mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-06-10 12:10:53 +00:00
9a9744077e
Major refactoring of the team system with multiple improvements:
## Removed legacy delegation tools
- Delete `delegate.go`, `delegate_async.go`, `delegate_sync.go`, `delegate_events.go`,
`delegate_policy.go`, `delegate_prep.go`, `delegate_state.go`, `delegate_search_tool.go`
- Delete `evaluate_loop_tool.go`, `handoff_tool.go`
- Remove all references and registrations from tool manager and policy
- Clean up TEAM_PLAYBOOK_IDEAS.md and TEAM_SYSTEM.md (moved to docs)
## Rename await_reply → ask_user
- Rename action `await_reply` → `ask_user`, `clear_followup` → `clear_ask_user`
- Rename functions `executeAwaitReply` → `executeAskUser`, `executeClearFollowup` → `executeClearAskUser`
- Update system prompt with stronger wording to prevent model misuse
- Model was confusing "await_reply" with general waiting; "ask_user" is unambiguous
## Fix auto-followup false positives
- Add `HasActiveMemberTasks(ctx, teamID, excludeAgentID)` store method
- Guard `autoSetFollowup()` in consumer: skip when lead has active member tasks
- Prevents auto-followup when lead is orchestrating teammates (not waiting for user)
## Task identifier zero-padding
- Change format from `T-1-xxxx` → `T-001-xxxx` (3-digit minimum)
## Refactor workspace WS handlers to filesystem-only
- Rewrite `teams.workspace.list/read/delete` to use pure filesystem (os.ReadDir/ReadFile/Remove)
- Remove DB dependency from workspace WS handlers
- Consistent with storage handler and workspace tools
- Simplify TeamWorkspaceFile type and frontend hook
## Add team events listing API
- New WS method `teams.events.list` with team_id, limit, offset params
- New HTTP endpoint `GET /v1/teams/{id}/events` with bearer auth
- New `ListTeamEvents(ctx, teamID, limit, offset)` store method
- JOIN with team_tasks for team-wide event filtering
## Extract team access policy
- New `team_access_policy.go` — centralized team tool access control
## Migration 000019: team_id columns
- Add team_id foreign key columns to relevant tables
## Other improvements
- Add team_id propagation through agent loop, tracing, sessions
- Update i18n locale files (en/vi/zh) for new tool labels
- Update frontend builtin-tools page and require-setup component
- Bump RequiredSchemaVersion for migration 000019
111 lines
3.6 KiB
Go
111 lines
3.6 KiB
Go
package tracing
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type contextKey string
|
|
|
|
const (
|
|
traceIDKey contextKey = "goclaw_trace_id"
|
|
parentSpanKey contextKey = "goclaw_parent_span_id"
|
|
collectorKey contextKey = "goclaw_trace_collector"
|
|
announceParentKey contextKey = "goclaw_announce_parent_span_id"
|
|
delegateParentTraceKey contextKey = "goclaw_delegate_parent_trace_id"
|
|
traceTeamIDKey contextKey = "goclaw_trace_team_id"
|
|
)
|
|
|
|
// WithTraceID returns a context with the given trace ID.
|
|
func WithTraceID(ctx context.Context, id uuid.UUID) context.Context {
|
|
return context.WithValue(ctx, traceIDKey, id)
|
|
}
|
|
|
|
// TraceIDFromContext extracts the trace ID from context. Returns uuid.Nil if not set.
|
|
func TraceIDFromContext(ctx context.Context) uuid.UUID {
|
|
if v, ok := ctx.Value(traceIDKey).(uuid.UUID); ok {
|
|
return v
|
|
}
|
|
return uuid.Nil
|
|
}
|
|
|
|
// WithParentSpanID returns a context with the given parent span ID.
|
|
func WithParentSpanID(ctx context.Context, id uuid.UUID) context.Context {
|
|
return context.WithValue(ctx, parentSpanKey, id)
|
|
}
|
|
|
|
// ParentSpanIDFromContext extracts the parent span ID. Returns uuid.Nil if not set.
|
|
func ParentSpanIDFromContext(ctx context.Context) uuid.UUID {
|
|
if v, ok := ctx.Value(parentSpanKey).(uuid.UUID); ok {
|
|
return v
|
|
}
|
|
return uuid.Nil
|
|
}
|
|
|
|
// WithCollector returns a context with the given Collector.
|
|
func WithCollector(ctx context.Context, c *Collector) context.Context {
|
|
return context.WithValue(ctx, collectorKey, c)
|
|
}
|
|
|
|
// CollectorFromContext extracts the Collector from context. Returns nil if not set.
|
|
func CollectorFromContext(ctx context.Context) *Collector {
|
|
if v, ok := ctx.Value(collectorKey).(*Collector); ok {
|
|
return v
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// WithAnnounceParentSpanID returns a context indicating this run's agent span
|
|
// should be nested under the given parent span (used for announce runs).
|
|
func WithAnnounceParentSpanID(ctx context.Context, id uuid.UUID) context.Context {
|
|
return context.WithValue(ctx, announceParentKey, id)
|
|
}
|
|
|
|
// AnnounceParentSpanIDFromContext extracts the announce parent span ID.
|
|
// Returns uuid.Nil if not set (i.e., this is a normal run, not an announce).
|
|
func AnnounceParentSpanIDFromContext(ctx context.Context) uuid.UUID {
|
|
if v, ok := ctx.Value(announceParentKey).(uuid.UUID); ok {
|
|
return v
|
|
}
|
|
return uuid.Nil
|
|
}
|
|
|
|
// WithDelegateParentTraceID sets the parent trace ID for delegation linking.
|
|
// Unlike ParentTraceID on RunRequest (which reuses the parent trace for announces),
|
|
// this creates a NEW trace that links back to the parent via parent_trace_id.
|
|
func WithDelegateParentTraceID(ctx context.Context, id uuid.UUID) context.Context {
|
|
return context.WithValue(ctx, delegateParentTraceKey, id)
|
|
}
|
|
|
|
// DelegateParentTraceIDFromContext extracts the delegation parent trace ID.
|
|
func DelegateParentTraceIDFromContext(ctx context.Context) uuid.UUID {
|
|
if v, ok := ctx.Value(delegateParentTraceKey).(uuid.UUID); ok {
|
|
return v
|
|
}
|
|
return uuid.Nil
|
|
}
|
|
|
|
// WithTraceTeamID sets the team ID for trace/span scoping.
|
|
func WithTraceTeamID(ctx context.Context, id uuid.UUID) context.Context {
|
|
return context.WithValue(ctx, traceTeamIDKey, id)
|
|
}
|
|
|
|
// TraceTeamIDFromContext extracts the team ID for trace/span scoping.
|
|
// Returns uuid.Nil if not set (non-team run).
|
|
func TraceTeamIDFromContext(ctx context.Context) uuid.UUID {
|
|
if v, ok := ctx.Value(traceTeamIDKey).(uuid.UUID); ok {
|
|
return v
|
|
}
|
|
return uuid.Nil
|
|
}
|
|
|
|
// TraceTeamIDPtrFromContext returns *uuid.UUID for setting on SpanData.TeamID.
|
|
// Returns nil if not set (non-team run).
|
|
func TraceTeamIDPtrFromContext(ctx context.Context) *uuid.UUID {
|
|
if v, ok := ctx.Value(traceTeamIDKey).(uuid.UUID); ok && v != uuid.Nil {
|
|
return &v
|
|
}
|
|
return nil
|
|
}
|