buildWorkspaceBlocks builds Block 3 of the agent system prompt: the workspace/retrieval context plus the separately-cached dynamic (wall-clock) context. Returns empty strings when no context builder is configured.
(ctx context.Context, query string)
| 998 | // workspace/retrieval context plus the separately-cached dynamic (wall-clock) |
| 999 | // context. Returns empty strings when no context builder is configured. |
| 1000 | func (a *AgentMode) buildWorkspaceBlocks(ctx context.Context, query string) (string, string) { |
| 1001 | if a.cli.contextBuilder == nil { |
| 1002 | return "", "" |
| 1003 | } |
| 1004 | var hints []string |
| 1005 | hintWindow := 3 |
| 1006 | if len(a.cli.history) < hintWindow { |
| 1007 | hintWindow = len(a.cli.history) |
| 1008 | } |
| 1009 | if hintWindow > 0 { |
| 1010 | var recentTexts []string |
| 1011 | for _, msg := range a.cli.history[len(a.cli.history)-hintWindow:] { |
| 1012 | recentTexts = append(recentTexts, msg.Content) |
| 1013 | } |
| 1014 | hints = memory.ExtractKeywords(recentTexts) |
| 1015 | } |
| 1016 | // Memory injection mode: "index" (pull) keeps the per-turn payload |
| 1017 | // bounded — a small stable digest plus the recall directive — while |
| 1018 | // "full" (push) injects the whole hint-driven retrieval. Agent/coder |
| 1019 | // can pull, so they honor the configured mode directly. |
| 1020 | mode := loadMemoryMode() |
| 1021 | aug := a.cli.hydeAugmenterFor(a.qualityConfig) |
| 1022 | recallHint := "" |
| 1023 | if mode == memModeIndex { |
| 1024 | recallHint = memoryRecallHint |
| 1025 | } |
| 1026 | workspaceText := a.cli.contextBuilder.BuildWorkspaceContextMode(ctx, query, hints, aug, mode, recallHint) |
| 1027 | |
| 1028 | // Append the knowledge-graph map-of-content card next to the memory index. |
| 1029 | // It is tiny and deterministic (so prompt-cache friendly), and agent/coder |
| 1030 | // can pull a subject's neighborhood on demand via @graph. |
| 1031 | if mode != memModeOff { |
| 1032 | if gb := a.cli.graphIndexBlock(); gb != "" { |
| 1033 | if strings.TrimSpace(workspaceText) == "" { |
| 1034 | workspaceText = gb |
| 1035 | } else { |
| 1036 | workspaceText = strings.TrimRight(workspaceText, "\n") + "\n\n" + gb |
| 1037 | } |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | dynamicText := a.cli.contextBuilder.BuildDynamicContext() |
| 1042 | return workspaceText, dynamicText |
| 1043 | } |
| 1044 | |
| 1045 | // RunCoderOnce executa o modo coder de forma não-interativa (one-shot), |
| 1046 | // mas mantendo o loop ReAct do AgentMode (com tool_calls/plugins). |
no test coverage detected