qlogicagent 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/dist/agent.js +1 -0
  2. package/dist/cli.js +9 -0
  3. package/dist/contracts.js +1 -0
  4. package/dist/index.js +5 -15
  5. package/dist/orchestration.js +118 -0
  6. package/package.json +56 -42
  7. package/dist/agent/agent.js +0 -113
  8. package/dist/agent/tool-loop.js +0 -575
  9. package/dist/agent/types.js +0 -14
  10. package/dist/cli/main.js +0 -23
  11. package/dist/cli/stdio-server.js +0 -463
  12. package/dist/config/config.js +0 -21
  13. package/dist/contracts/hooks.js +0 -7
  14. package/dist/contracts/index.js +0 -10
  15. package/dist/contracts/planner.js +0 -2
  16. package/dist/contracts/skill-candidate.js +0 -195
  17. package/dist/contracts/todo.js +0 -9
  18. package/dist/llm/builtin-providers.js +0 -531
  19. package/dist/llm/index.js +0 -14
  20. package/dist/llm/llm-client.js +0 -67
  21. package/dist/llm/model-catalog.js +0 -191
  22. package/dist/llm/provider-def.js +0 -12
  23. package/dist/llm/provider-registry.js +0 -147
  24. package/dist/llm/transport.js +0 -27
  25. package/dist/llm/transports/anthropic-messages.js +0 -293
  26. package/dist/llm/transports/openai-chat.js +0 -165
  27. package/dist/orchestration/agent-registry.js +0 -116
  28. package/dist/orchestration/approval-aware-tool-plan.js +0 -87
  29. package/dist/orchestration/context-compression.js +0 -583
  30. package/dist/orchestration/conversation-repair.js +0 -429
  31. package/dist/orchestration/curator-scheduler.js +0 -135
  32. package/dist/orchestration/embedded-failover-policy.js +0 -168
  33. package/dist/orchestration/error-classification.js +0 -77
  34. package/dist/orchestration/failover-classification.js +0 -381
  35. package/dist/orchestration/failover-error.js +0 -198
  36. package/dist/orchestration/fork-subagent.js +0 -98
  37. package/dist/orchestration/index.js +0 -267
  38. package/dist/orchestration/memory-flush-policy.js +0 -85
  39. package/dist/orchestration/memory-provider.js +0 -2
  40. package/dist/orchestration/parallel-tool-calls.js +0 -59
  41. package/dist/orchestration/prompt-cache-strategy.js +0 -228
  42. package/dist/orchestration/reactive-compact.js +0 -78
  43. package/dist/orchestration/retry-loop.js +0 -24
  44. package/dist/orchestration/skill-candidate.js +0 -141
  45. package/dist/orchestration/skill-consolidation.js +0 -220
  46. package/dist/orchestration/skill-improvement.js +0 -66
  47. package/dist/orchestration/skill-similarity.js +0 -131
  48. package/dist/orchestration/streaming-tool-executor.js +0 -96
  49. package/dist/orchestration/team-orchestration.js +0 -369
  50. package/dist/orchestration/team-tool-loop-wiring.js +0 -147
  51. package/dist/orchestration/tool-choice-policy.js +0 -164
  52. package/dist/orchestration/tool-loop-state.js +0 -133
  53. package/dist/orchestration/tool-schema.js +0 -297
  54. package/dist/orchestration/transcript-repair.js +0 -426
  55. package/dist/orchestration/turn-loop-guard.js +0 -92
  56. package/dist/orchestration/web-browser-policy.js +0 -39
  57. package/dist/runtime/context-compression.js +0 -274
  58. package/dist/runtime/hook-registry.js +0 -53
  59. package/dist/runtime/memory-hooks.js +0 -65
  60. package/dist/runtime/tool-eligibility.js +0 -111
  61. package/dist/skills/index.js +0 -82
  62. package/dist/skills/memory-extractor.js +0 -173
  63. package/dist/skills/memory-query-tool.js +0 -127
  64. package/dist/skills/memory-store.js +0 -228
  65. package/dist/skills/memory-tool.js +0 -192
  66. package/dist/skills/portable-tool.js +0 -14
  67. package/dist/skills/qmemory-adapter.js +0 -165
  68. package/dist/skills/skill-frontmatter.js +0 -344
  69. package/dist/skills/skill-guard.js +0 -229
  70. package/dist/skills/skill-loader.js +0 -303
  71. package/dist/skills/skill-source.js +0 -126
  72. package/dist/skills/skill-types.js +0 -6
  73. package/dist/skills/think-tool.js +0 -59
  74. package/dist/skills/todo-tool.js +0 -114
  75. package/dist/skills/tools/agent-tool.js +0 -142
  76. package/dist/skills/tools/apply-patch-tool.js +0 -184
  77. package/dist/skills/tools/ask-user-tool.js +0 -121
  78. package/dist/skills/tools/brief-tool.js +0 -95
  79. package/dist/skills/tools/browser-tool.js +0 -155
  80. package/dist/skills/tools/checkpoint-tool.js +0 -102
  81. package/dist/skills/tools/config-tool.js +0 -143
  82. package/dist/skills/tools/cron-tool.js +0 -175
  83. package/dist/skills/tools/edit-tool.js +0 -70
  84. package/dist/skills/tools/exec-tool.js +0 -133
  85. package/dist/skills/tools/image-generate-tool.js +0 -67
  86. package/dist/skills/tools/instructions-tool.js +0 -187
  87. package/dist/skills/tools/lsp-tool.js +0 -227
  88. package/dist/skills/tools/mcp-client-types.js +0 -53
  89. package/dist/skills/tools/mcp-tool.js +0 -503
  90. package/dist/skills/tools/memory-tool.js +0 -88
  91. package/dist/skills/tools/monitor-tool.js +0 -131
  92. package/dist/skills/tools/music-generate-tool.js +0 -62
  93. package/dist/skills/tools/notify-tool.js +0 -62
  94. package/dist/skills/tools/patch-tool.js +0 -505
  95. package/dist/skills/tools/pdf-tool.js +0 -88
  96. package/dist/skills/tools/plan-mode-tool.js +0 -122
  97. package/dist/skills/tools/read-tool.js +0 -84
  98. package/dist/skills/tools/repl-tool.js +0 -69
  99. package/dist/skills/tools/search-tool.js +0 -225
  100. package/dist/skills/tools/send-message-tool.js +0 -76
  101. package/dist/skills/tools/skill-list-tool.js +0 -54
  102. package/dist/skills/tools/skill-manage-tool.js +0 -153
  103. package/dist/skills/tools/skill-view-tool.js +0 -72
  104. package/dist/skills/tools/sleep-tool.js +0 -81
  105. package/dist/skills/tools/structured-output-tool.js +0 -176
  106. package/dist/skills/tools/task-tool.js +0 -161
  107. package/dist/skills/tools/team-tool.js +0 -105
  108. package/dist/skills/tools/tool-search-tool.js +0 -110
  109. package/dist/skills/tools/tts-tool.js +0 -45
  110. package/dist/skills/tools/video-edit-tool.js +0 -74
  111. package/dist/skills/tools/video-generate-tool.js +0 -66
  112. package/dist/skills/tools/video-merge-tool.js +0 -92
  113. package/dist/skills/tools/video-upscale-tool.js +0 -52
  114. package/dist/skills/tools/web-fetch-tool.js +0 -92
  115. package/dist/skills/tools/web-search-tool.js +0 -86
  116. package/dist/skills/tools/worktree-tool.js +0 -147
  117. package/dist/skills/tools/write-tool.js +0 -81
  118. /package/dist/{agent → types/agent}/agent.d.ts +0 -0
  119. /package/dist/{agent → types/agent}/tool-loop.d.ts +0 -0
  120. /package/dist/{agent → types/agent}/types.d.ts +0 -0
  121. /package/dist/{cli → types/cli}/main.d.ts +0 -0
  122. /package/dist/{cli → types/cli}/stdio-server.d.ts +0 -0
  123. /package/dist/{config → types/config}/config.d.ts +0 -0
  124. /package/dist/{contracts → types/contracts}/hooks.d.ts +0 -0
  125. /package/dist/{contracts → types/contracts}/index.d.ts +0 -0
  126. /package/dist/{contracts → types/contracts}/planner.d.ts +0 -0
  127. /package/dist/{contracts → types/contracts}/skill-candidate.d.ts +0 -0
  128. /package/dist/{contracts → types/contracts}/todo.d.ts +0 -0
  129. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
  130. /package/dist/{llm → types/llm}/builtin-providers.d.ts +0 -0
  131. /package/dist/{llm → types/llm}/index.d.ts +0 -0
  132. /package/dist/{llm → types/llm}/llm-client.d.ts +0 -0
  133. /package/dist/{llm → types/llm}/model-catalog.d.ts +0 -0
  134. /package/dist/{llm → types/llm}/provider-def.d.ts +0 -0
  135. /package/dist/{llm → types/llm}/provider-registry.d.ts +0 -0
  136. /package/dist/{llm → types/llm}/transport.d.ts +0 -0
  137. /package/dist/{llm → types/llm}/transports/anthropic-messages.d.ts +0 -0
  138. /package/dist/{llm → types/llm}/transports/openai-chat.d.ts +0 -0
  139. /package/dist/{orchestration → types/orchestration}/agent-registry.d.ts +0 -0
  140. /package/dist/{orchestration → types/orchestration}/approval-aware-tool-plan.d.ts +0 -0
  141. /package/dist/{orchestration → types/orchestration}/context-compression.d.ts +0 -0
  142. /package/dist/{orchestration → types/orchestration}/conversation-repair.d.ts +0 -0
  143. /package/dist/{orchestration → types/orchestration}/curator-scheduler.d.ts +0 -0
  144. /package/dist/{orchestration → types/orchestration}/embedded-failover-policy.d.ts +0 -0
  145. /package/dist/{orchestration → types/orchestration}/error-classification.d.ts +0 -0
  146. /package/dist/{orchestration → types/orchestration}/failover-classification.d.ts +0 -0
  147. /package/dist/{orchestration → types/orchestration}/failover-error.d.ts +0 -0
  148. /package/dist/{orchestration → types/orchestration}/fork-subagent.d.ts +0 -0
  149. /package/dist/{orchestration → types/orchestration}/index.d.ts +0 -0
  150. /package/dist/{orchestration → types/orchestration}/memory-flush-policy.d.ts +0 -0
  151. /package/dist/{orchestration → types/orchestration}/memory-provider.d.ts +0 -0
  152. /package/dist/{orchestration → types/orchestration}/parallel-tool-calls.d.ts +0 -0
  153. /package/dist/{orchestration → types/orchestration}/prompt-cache-strategy.d.ts +0 -0
  154. /package/dist/{orchestration → types/orchestration}/reactive-compact.d.ts +0 -0
  155. /package/dist/{orchestration → types/orchestration}/retry-loop.d.ts +0 -0
  156. /package/dist/{orchestration → types/orchestration}/skill-candidate.d.ts +0 -0
  157. /package/dist/{orchestration → types/orchestration}/skill-consolidation.d.ts +0 -0
  158. /package/dist/{orchestration → types/orchestration}/skill-improvement.d.ts +0 -0
  159. /package/dist/{orchestration → types/orchestration}/skill-similarity.d.ts +0 -0
  160. /package/dist/{orchestration → types/orchestration}/streaming-tool-executor.d.ts +0 -0
  161. /package/dist/{orchestration → types/orchestration}/team-orchestration.d.ts +0 -0
  162. /package/dist/{orchestration → types/orchestration}/team-tool-loop-wiring.d.ts +0 -0
  163. /package/dist/{orchestration → types/orchestration}/tool-choice-policy.d.ts +0 -0
  164. /package/dist/{orchestration → types/orchestration}/tool-loop-state.d.ts +0 -0
  165. /package/dist/{orchestration → types/orchestration}/tool-schema.d.ts +0 -0
  166. /package/dist/{orchestration → types/orchestration}/transcript-repair.d.ts +0 -0
  167. /package/dist/{orchestration → types/orchestration}/turn-loop-guard.d.ts +0 -0
  168. /package/dist/{orchestration → types/orchestration}/web-browser-policy.d.ts +0 -0
  169. /package/dist/{runtime → types/runtime}/context-compression.d.ts +0 -0
  170. /package/dist/{runtime → types/runtime}/hook-registry.d.ts +0 -0
  171. /package/dist/{runtime → types/runtime}/memory-hooks.d.ts +0 -0
  172. /package/dist/{runtime → types/runtime}/tool-eligibility.d.ts +0 -0
  173. /package/dist/{skills → types/skills}/index.d.ts +0 -0
  174. /package/dist/{skills → types/skills}/memory-extractor.d.ts +0 -0
  175. /package/dist/{skills → types/skills}/memory-query-tool.d.ts +0 -0
  176. /package/dist/{skills → types/skills}/memory-store.d.ts +0 -0
  177. /package/dist/{skills → types/skills}/memory-tool.d.ts +0 -0
  178. /package/dist/{skills → types/skills}/portable-tool.d.ts +0 -0
  179. /package/dist/{skills → types/skills}/qmemory-adapter.d.ts +0 -0
  180. /package/dist/{skills → types/skills}/skill-frontmatter.d.ts +0 -0
  181. /package/dist/{skills → types/skills}/skill-guard.d.ts +0 -0
  182. /package/dist/{skills → types/skills}/skill-loader.d.ts +0 -0
  183. /package/dist/{skills → types/skills}/skill-source.d.ts +0 -0
  184. /package/dist/{skills → types/skills}/skill-types.d.ts +0 -0
  185. /package/dist/{skills → types/skills}/think-tool.d.ts +0 -0
  186. /package/dist/{skills → types/skills}/todo-tool.d.ts +0 -0
  187. /package/dist/{skills → types/skills}/tools/agent-tool.d.ts +0 -0
  188. /package/dist/{skills → types/skills}/tools/apply-patch-tool.d.ts +0 -0
  189. /package/dist/{skills → types/skills}/tools/ask-user-tool.d.ts +0 -0
  190. /package/dist/{skills → types/skills}/tools/brief-tool.d.ts +0 -0
  191. /package/dist/{skills → types/skills}/tools/browser-tool.d.ts +0 -0
  192. /package/dist/{skills → types/skills}/tools/checkpoint-tool.d.ts +0 -0
  193. /package/dist/{skills → types/skills}/tools/config-tool.d.ts +0 -0
  194. /package/dist/{skills → types/skills}/tools/cron-tool.d.ts +0 -0
  195. /package/dist/{skills → types/skills}/tools/edit-tool.d.ts +0 -0
  196. /package/dist/{skills → types/skills}/tools/exec-tool.d.ts +0 -0
  197. /package/dist/{skills → types/skills}/tools/image-generate-tool.d.ts +0 -0
  198. /package/dist/{skills → types/skills}/tools/instructions-tool.d.ts +0 -0
  199. /package/dist/{skills → types/skills}/tools/lsp-tool.d.ts +0 -0
  200. /package/dist/{skills → types/skills}/tools/mcp-client-types.d.ts +0 -0
  201. /package/dist/{skills → types/skills}/tools/mcp-tool.d.ts +0 -0
  202. /package/dist/{skills → types/skills}/tools/memory-tool.d.ts +0 -0
  203. /package/dist/{skills → types/skills}/tools/monitor-tool.d.ts +0 -0
  204. /package/dist/{skills → types/skills}/tools/music-generate-tool.d.ts +0 -0
  205. /package/dist/{skills → types/skills}/tools/notify-tool.d.ts +0 -0
  206. /package/dist/{skills → types/skills}/tools/patch-tool.d.ts +0 -0
  207. /package/dist/{skills → types/skills}/tools/pdf-tool.d.ts +0 -0
  208. /package/dist/{skills → types/skills}/tools/plan-mode-tool.d.ts +0 -0
  209. /package/dist/{skills → types/skills}/tools/read-tool.d.ts +0 -0
  210. /package/dist/{skills → types/skills}/tools/repl-tool.d.ts +0 -0
  211. /package/dist/{skills → types/skills}/tools/search-tool.d.ts +0 -0
  212. /package/dist/{skills → types/skills}/tools/send-message-tool.d.ts +0 -0
  213. /package/dist/{skills → types/skills}/tools/skill-list-tool.d.ts +0 -0
  214. /package/dist/{skills → types/skills}/tools/skill-manage-tool.d.ts +0 -0
  215. /package/dist/{skills → types/skills}/tools/skill-view-tool.d.ts +0 -0
  216. /package/dist/{skills → types/skills}/tools/sleep-tool.d.ts +0 -0
  217. /package/dist/{skills → types/skills}/tools/structured-output-tool.d.ts +0 -0
  218. /package/dist/{skills → types/skills}/tools/task-tool.d.ts +0 -0
  219. /package/dist/{skills → types/skills}/tools/team-tool.d.ts +0 -0
  220. /package/dist/{skills → types/skills}/tools/tool-search-tool.d.ts +0 -0
  221. /package/dist/{skills → types/skills}/tools/tts-tool.d.ts +0 -0
  222. /package/dist/{skills → types/skills}/tools/video-edit-tool.d.ts +0 -0
  223. /package/dist/{skills → types/skills}/tools/video-generate-tool.d.ts +0 -0
  224. /package/dist/{skills → types/skills}/tools/video-merge-tool.d.ts +0 -0
  225. /package/dist/{skills → types/skills}/tools/video-upscale-tool.d.ts +0 -0
  226. /package/dist/{skills → types/skills}/tools/web-fetch-tool.d.ts +0 -0
  227. /package/dist/{skills → types/skills}/tools/web-search-tool.d.ts +0 -0
  228. /package/dist/{skills → types/skills}/tools/worktree-tool.d.ts +0 -0
  229. /package/dist/{skills → types/skills}/tools/write-tool.d.ts +0 -0
@@ -1,165 +0,0 @@
1
- /**
2
- * OpenAI Chat Completions Transport — SSE streaming implementation.
3
- *
4
- * Covers all OpenAI-compatible providers:
5
- * DeepSeek, Qwen, 硅基, Minimax, Moonshot, Groq, Together, OpenRouter, etc.
6
- *
7
- * POST {baseUrl}/v1/chat/completions with stream: true
8
- * Auth: Authorization: Bearer {apiKey}
9
- *
10
- * SSE format: lines prefixed with "data: ", JSON parsing per event.
11
- *
12
- * Adapted from admin-infer-proxy-client.ts SSE logic + Hermes openai_chat.py transport.
13
- */
14
- export class OpenAIChatTransport {
15
- baseUrl;
16
- extraHeaders;
17
- timeoutMs;
18
- supportsStreamOptions;
19
- omitZeroTemperature;
20
- constructor(config) {
21
- // Strip trailing slash
22
- this.baseUrl = config.baseUrl.replace(/\/+$/, "");
23
- this.extraHeaders = config.extraHeaders ?? {};
24
- this.timeoutMs = config.timeoutMs ?? 180_000;
25
- this.supportsStreamOptions = config.supportsStreamOptions ?? true;
26
- this.omitZeroTemperature = config.omitZeroTemperature ?? false;
27
- }
28
- async *stream(request, apiKey, signal) {
29
- const url = `${this.baseUrl}/v1/chat/completions`;
30
- const body = {
31
- model: request.model,
32
- messages: request.messages,
33
- stream: true,
34
- };
35
- // stream_options: supported by most providers, but some reject it
36
- if (this.supportsStreamOptions) {
37
- body.stream_options = { include_usage: true };
38
- }
39
- if (request.tools && request.tools.length > 0) {
40
- body.tools = request.tools;
41
- if (request.toolChoice)
42
- body.tool_choice = request.toolChoice;
43
- }
44
- if (request.temperature !== undefined) {
45
- // Some providers (e.g. Moonshot/Kimi) reject temperature=0
46
- if (!(this.omitZeroTemperature && request.temperature === 0)) {
47
- body.temperature = request.temperature;
48
- }
49
- }
50
- if (request.maxTokens !== undefined)
51
- body.max_tokens = request.maxTokens;
52
- if (request.reasoning) {
53
- // DeepSeek-R1 / o1 style reasoning
54
- body.reasoning = request.reasoning;
55
- }
56
- const timeoutSignal = AbortSignal.timeout(this.timeoutMs);
57
- const combinedSignal = signal
58
- ? AbortSignal.any([signal, timeoutSignal])
59
- : timeoutSignal;
60
- const response = await fetch(url, {
61
- method: "POST",
62
- headers: {
63
- "Content-Type": "application/json",
64
- Authorization: `Bearer ${apiKey}`,
65
- ...this.extraHeaders,
66
- },
67
- body: JSON.stringify(body),
68
- signal: combinedSignal,
69
- });
70
- if (!response.ok) {
71
- const errorBody = await response.text().catch(() => "");
72
- throw new Error(`LLM API error ${response.status}: ${errorBody.slice(0, 500)}`);
73
- }
74
- if (!response.body) {
75
- throw new Error("LLM API returned no response body");
76
- }
77
- yield* this.parseSSEStream(response.body);
78
- }
79
- async *parseSSEStream(body) {
80
- const decoder = new TextDecoder();
81
- let buffer = "";
82
- for await (const raw of body) {
83
- buffer += decoder.decode(raw, { stream: true });
84
- // Process complete lines
85
- let newlineIdx;
86
- while ((newlineIdx = buffer.indexOf("\n")) !== -1) {
87
- const line = buffer.slice(0, newlineIdx).trim();
88
- buffer = buffer.slice(newlineIdx + 1);
89
- if (!line)
90
- continue;
91
- if (line.startsWith(":"))
92
- continue; // SSE comment
93
- if (!line.startsWith("data: "))
94
- continue;
95
- const data = line.slice(6);
96
- if (data === "[DONE]") {
97
- return;
98
- }
99
- let parsed;
100
- try {
101
- parsed = JSON.parse(data);
102
- }
103
- catch {
104
- continue; // Skip malformed JSON
105
- }
106
- yield* this.mapChunk(parsed);
107
- }
108
- }
109
- // Flush remaining buffer
110
- if (buffer.trim()) {
111
- const line = buffer.trim();
112
- if (line.startsWith("data: ") && line.slice(6) !== "[DONE]") {
113
- try {
114
- const parsed = JSON.parse(line.slice(6));
115
- yield* this.mapChunk(parsed);
116
- }
117
- catch {
118
- // ignore
119
- }
120
- }
121
- }
122
- }
123
- *mapChunk(chunk) {
124
- // Usage chunk (often sent at the end with stream_options)
125
- if (chunk.usage) {
126
- yield {
127
- type: "usage",
128
- promptTokens: chunk.usage.prompt_tokens ?? 0,
129
- completionTokens: chunk.usage.completion_tokens ?? 0,
130
- reasoningTokens: chunk.usage.completion_tokens_details?.reasoning_tokens,
131
- };
132
- }
133
- if (!chunk.choices || chunk.choices.length === 0)
134
- return;
135
- for (const choice of chunk.choices) {
136
- const delta = choice.delta;
137
- if (!delta)
138
- continue;
139
- // Reasoning content (DeepSeek-R1 style)
140
- if (delta.reasoning_content) {
141
- yield { type: "reasoning_delta", text: delta.reasoning_content };
142
- }
143
- // Text content
144
- if (delta.content) {
145
- yield { type: "delta", text: delta.content };
146
- }
147
- // Tool call deltas
148
- if (delta.tool_calls) {
149
- for (const tc of delta.tool_calls) {
150
- yield {
151
- type: "tool_call_delta",
152
- index: tc.index,
153
- id: tc.id,
154
- name: tc.function?.name,
155
- arguments: tc.function?.arguments ?? "",
156
- };
157
- }
158
- }
159
- // Finish reason
160
- if (choice.finish_reason) {
161
- yield { type: "done", finishReason: choice.finish_reason };
162
- }
163
- }
164
- }
165
- }
@@ -1,116 +0,0 @@
1
- /**
2
- * Built-in Agent Registry — CC-aligned agent definitions for fork/subagent.
3
- *
4
- * Each built-in agent defines a role with constrained tools, system prompt,
5
- * and execution budget. The LLM can invoke these via the AgentTool.
6
- */
7
- /** General-purpose sub-agent for delegated tasks. */
8
- const GENERAL_PURPOSE_AGENT = {
9
- name: "general",
10
- label: "General Purpose",
11
- description: "A general-purpose sub-agent that can perform any task with full tool access.",
12
- maxTurns: 200,
13
- toolAccessMode: "full",
14
- canFork: false,
15
- };
16
- /** Explore agent — read-only exploration (code search, file reading, analysis). */
17
- const EXPLORE_AGENT = {
18
- name: "explore",
19
- label: "Explore",
20
- description: "Fast read-only codebase exploration. Search files, read code, analyze structure. Cannot write or execute.",
21
- maxTurns: 50,
22
- toolAccessMode: "read-only",
23
- allowedTools: ["read_file", "search", "web_search", "web_fetch", "think", "memory_query", "tool_search"],
24
- canFork: false,
25
- };
26
- /** Plan agent — read-only planning mode (explore + propose, no execution). */
27
- const PLAN_AGENT = {
28
- name: "plan",
29
- label: "Plan",
30
- description: "Planning mode. Explore, analyze, and produce a structured plan. Cannot write files or execute commands.",
31
- maxTurns: 80,
32
- toolAccessMode: "read-only",
33
- allowedTools: ["read_file", "search", "web_search", "web_fetch", "think", "memory_query", "todo", "tool_search"],
34
- canFork: false,
35
- };
36
- /** Code agent — full execution capability for code tasks. */
37
- const CODE_AGENT = {
38
- name: "code",
39
- label: "Code",
40
- description: "A coding sub-agent with full tool access for implementation tasks.",
41
- maxTurns: 200,
42
- toolAccessMode: "full",
43
- canFork: true,
44
- };
45
- /** Research agent — web research and information gathering. */
46
- const RESEARCH_AGENT = {
47
- name: "research",
48
- label: "Research",
49
- description: "Web research and information gathering. Searches the web, fetches pages, and synthesizes findings.",
50
- maxTurns: 30,
51
- toolAccessMode: "read-only",
52
- allowedTools: ["web_search", "web_fetch", "read_file", "search", "think", "memory_query"],
53
- canFork: false,
54
- };
55
- /** Verification agent — runs tests and validates changes. */
56
- const VERIFY_AGENT = {
57
- name: "verify",
58
- label: "Verify",
59
- description: "Verification agent. Runs tests, checks build output, validates changes are correct.",
60
- maxTurns: 40,
61
- toolAccessMode: "full",
62
- allowedTools: ["exec", "read_file", "search", "think"],
63
- canFork: false,
64
- };
65
- const BUILT_IN_AGENTS = [
66
- GENERAL_PURPOSE_AGENT,
67
- EXPLORE_AGENT,
68
- PLAN_AGENT,
69
- CODE_AGENT,
70
- RESEARCH_AGENT,
71
- VERIFY_AGENT,
72
- ];
73
- /**
74
- * Get the full list of built-in agent definitions.
75
- */
76
- export function getBuiltInAgents() {
77
- return [...BUILT_IN_AGENTS];
78
- }
79
- /**
80
- * Look up a built-in agent by name.
81
- */
82
- export function getBuiltInAgent(name) {
83
- return BUILT_IN_AGENTS.find((a) => a.name === name);
84
- }
85
- /**
86
- * Check if a given agent name is a built-in agent.
87
- */
88
- export function isBuiltInAgent(name) {
89
- return BUILT_IN_AGENTS.some((a) => a.name === name);
90
- }
91
- /**
92
- * Resolve tool access for an agent definition.
93
- * Returns the set of tool names the agent is allowed to use.
94
- */
95
- export function resolveAgentToolSet(agent, availableTools) {
96
- if (agent.allowedTools && agent.allowedTools.length > 0) {
97
- const allowed = new Set(agent.allowedTools);
98
- return availableTools.filter((t) => allowed.has(t));
99
- }
100
- if (agent.toolAccessMode === "none")
101
- return [];
102
- if (agent.toolAccessMode === "read-only") {
103
- const writeTools = new Set([
104
- "file_edit", "create_file", "write_file", "replace_string_in_file",
105
- "multi_replace_string_in_file", "create_directory", "delete_file",
106
- "rename_file", "move_file", "exec", "run_in_terminal", "run_command",
107
- "git_commit", "git_push", "patch",
108
- ]);
109
- return availableTools.filter((t) => !writeTools.has(t));
110
- }
111
- // "full" — all tools except agent_tool itself (no recursive fork for non-canFork)
112
- if (!agent.canFork) {
113
- return availableTools.filter((t) => t !== "agent_tool" && t !== "team_create");
114
- }
115
- return [...availableTools];
116
- }
@@ -1,87 +0,0 @@
1
- function formatToolList(toolNames) {
2
- if (toolNames.length === 0) {
3
- return "no tools";
4
- }
5
- if (toolNames.length === 1) {
6
- return toolNames[0];
7
- }
8
- if (toolNames.length === 2) {
9
- return `${toolNames[0]} and ${toolNames[1]}`;
10
- }
11
- return `${toolNames.slice(0, -1).join(", ")}, and ${toolNames.at(-1)}`;
12
- }
13
- function requiresInteractiveApproval(capability) {
14
- if (!capability) {
15
- return false;
16
- }
17
- return capability.requiresApproval === true || capability.approvalMode === "user-confirm";
18
- }
19
- function buildEligibilityMap(eligibility) {
20
- return new Map((eligibility ?? []).map((entry) => [entry.toolName, entry]));
21
- }
22
- function requiresApprovalForTool(params) {
23
- const eligibility = params.eligibilityMap.get(params.toolName);
24
- if (eligibility?.approvalRequired !== undefined) {
25
- return eligibility.approvalRequired;
26
- }
27
- return requiresInteractiveApproval(params.capabilityMap.get(params.toolName));
28
- }
29
- export function summarizeApprovalAwareToolPlan(params) {
30
- const capabilityMap = new Map(params.toolCapabilities.map((capability) => [capability.name, capability]));
31
- const eligibilityMap = buildEligibilityMap(params.eligibility);
32
- const stepCount = params.batches.length;
33
- return params.batches.map((batch, index) => {
34
- const toolNames = batch.calls.map((call) => call.function.name);
35
- const approvalToolNames = batch.calls
36
- .map((call) => requiresApprovalForTool({
37
- toolName: call.function.name,
38
- capabilityMap,
39
- eligibilityMap,
40
- }) ? call.function.name : null)
41
- .filter((toolName) => Boolean(toolName));
42
- const approvalRequired = approvalToolNames.length > 0;
43
- const headline = batch.mode === "parallel"
44
- ? `Step ${index + 1}/${stepCount}: run ${toolNames.length} tools in parallel: ${formatToolList(toolNames)}.`
45
- : approvalRequired
46
- ? `Step ${index + 1}/${stepCount}: approval-gated execution for ${formatToolList(approvalToolNames)}.`
47
- : `Step ${index + 1}/${stepCount}: run ${formatToolList(toolNames)} serially.`;
48
- const detail = approvalRequired
49
- ? stepCount > index + 1
50
- ? "This step must be approved before later steps continue."
51
- : "This is the final planned step and requires approval before execution."
52
- : batch.mode === "parallel"
53
- ? "Parallel-safe tools are grouped to avoid unnecessary waiting."
54
- : "This step stays serial because the tool is not parallel-safe.";
55
- return {
56
- stepIndex: index + 1,
57
- stepCount,
58
- mode: batch.mode,
59
- callIds: batch.calls.map((call) => call.id),
60
- toolNames,
61
- approvalRequired,
62
- approvalToolNames,
63
- summary: `${headline} ${detail}`,
64
- };
65
- });
66
- }
67
- export function buildApprovalAwareReason(params) {
68
- if (!params.step) {
69
- return `semantic turn requested local tool: ${params.toolName}`;
70
- }
71
- const suffix = params.step.approvalRequired
72
- ? params.step.approvalToolNames.length > 1
73
- ? ` Approval is currently blocking ${formatToolList(params.step.approvalToolNames)}.`
74
- : " Approval is required before this step can continue."
75
- : "";
76
- return `${params.step.summary}${suffix}`;
77
- }
78
- export function buildApprovalStepContext(step) {
79
- if (!step) {
80
- return {};
81
- }
82
- return {
83
- stepIndex: step.stepIndex,
84
- stepTotal: step.stepCount,
85
- stepSummary: step.summary,
86
- };
87
- }