qlogicagent 0.2.1 → 0.4.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 (226) hide show
  1. package/README.md +45 -45
  2. package/package.json +56 -42
  3. package/dist/agent/agent.d.ts +0 -43
  4. package/dist/agent/agent.js +0 -113
  5. package/dist/agent/tool-loop.d.ts +0 -64
  6. package/dist/agent/tool-loop.js +0 -575
  7. package/dist/agent/types.d.ts +0 -175
  8. package/dist/agent/types.js +0 -14
  9. package/dist/cli/main.d.ts +0 -11
  10. package/dist/cli/main.js +0 -23
  11. package/dist/cli/stdio-server.d.ts +0 -45
  12. package/dist/cli/stdio-server.js +0 -463
  13. package/dist/config/config.d.ts +0 -17
  14. package/dist/config/config.js +0 -21
  15. package/dist/contracts/hooks.d.ts +0 -120
  16. package/dist/contracts/hooks.js +0 -7
  17. package/dist/contracts/index.d.ts +0 -10
  18. package/dist/contracts/index.js +0 -10
  19. package/dist/contracts/planner.d.ts +0 -35
  20. package/dist/contracts/planner.js +0 -2
  21. package/dist/contracts/skill-candidate.d.ts +0 -63
  22. package/dist/contracts/skill-candidate.js +0 -195
  23. package/dist/contracts/todo.d.ts +0 -14
  24. package/dist/contracts/todo.js +0 -9
  25. package/dist/index.d.ts +0 -13
  26. package/dist/index.js +0 -15
  27. package/dist/llm/builtin-providers.d.ts +0 -10
  28. package/dist/llm/builtin-providers.js +0 -531
  29. package/dist/llm/index.d.ts +0 -15
  30. package/dist/llm/index.js +0 -14
  31. package/dist/llm/llm-client.d.ts +0 -43
  32. package/dist/llm/llm-client.js +0 -67
  33. package/dist/llm/model-catalog.d.ts +0 -53
  34. package/dist/llm/model-catalog.js +0 -191
  35. package/dist/llm/provider-def.d.ts +0 -59
  36. package/dist/llm/provider-def.js +0 -12
  37. package/dist/llm/provider-registry.d.ts +0 -54
  38. package/dist/llm/provider-registry.js +0 -147
  39. package/dist/llm/transport.d.ts +0 -62
  40. package/dist/llm/transport.js +0 -27
  41. package/dist/llm/transports/anthropic-messages.d.ts +0 -31
  42. package/dist/llm/transports/anthropic-messages.js +0 -293
  43. package/dist/llm/transports/openai-chat.d.ts +0 -36
  44. package/dist/llm/transports/openai-chat.js +0 -165
  45. package/dist/orchestration/agent-registry.d.ts +0 -41
  46. package/dist/orchestration/agent-registry.js +0 -116
  47. package/dist/orchestration/approval-aware-tool-plan.d.ts +0 -32
  48. package/dist/orchestration/approval-aware-tool-plan.js +0 -87
  49. package/dist/orchestration/context-compression.d.ts +0 -220
  50. package/dist/orchestration/context-compression.js +0 -583
  51. package/dist/orchestration/conversation-repair.d.ts +0 -61
  52. package/dist/orchestration/conversation-repair.js +0 -429
  53. package/dist/orchestration/curator-scheduler.d.ts +0 -119
  54. package/dist/orchestration/curator-scheduler.js +0 -135
  55. package/dist/orchestration/embedded-failover-policy.d.ts +0 -110
  56. package/dist/orchestration/embedded-failover-policy.js +0 -168
  57. package/dist/orchestration/error-classification.d.ts +0 -12
  58. package/dist/orchestration/error-classification.js +0 -77
  59. package/dist/orchestration/failover-classification.d.ts +0 -8
  60. package/dist/orchestration/failover-classification.js +0 -381
  61. package/dist/orchestration/failover-error.d.ts +0 -33
  62. package/dist/orchestration/failover-error.js +0 -198
  63. package/dist/orchestration/fork-subagent.d.ts +0 -100
  64. package/dist/orchestration/fork-subagent.js +0 -98
  65. package/dist/orchestration/index.d.ts +0 -120
  66. package/dist/orchestration/index.js +0 -267
  67. package/dist/orchestration/memory-flush-policy.d.ts +0 -57
  68. package/dist/orchestration/memory-flush-policy.js +0 -85
  69. package/dist/orchestration/memory-provider.d.ts +0 -14
  70. package/dist/orchestration/memory-provider.js +0 -2
  71. package/dist/orchestration/parallel-tool-calls.d.ts +0 -41
  72. package/dist/orchestration/parallel-tool-calls.js +0 -59
  73. package/dist/orchestration/prompt-cache-strategy.d.ts +0 -126
  74. package/dist/orchestration/prompt-cache-strategy.js +0 -228
  75. package/dist/orchestration/reactive-compact.d.ts +0 -73
  76. package/dist/orchestration/reactive-compact.js +0 -78
  77. package/dist/orchestration/retry-loop.d.ts +0 -22
  78. package/dist/orchestration/retry-loop.js +0 -24
  79. package/dist/orchestration/skill-candidate.d.ts +0 -52
  80. package/dist/orchestration/skill-candidate.js +0 -141
  81. package/dist/orchestration/skill-consolidation.d.ts +0 -123
  82. package/dist/orchestration/skill-consolidation.js +0 -220
  83. package/dist/orchestration/skill-improvement.d.ts +0 -59
  84. package/dist/orchestration/skill-improvement.js +0 -66
  85. package/dist/orchestration/skill-similarity.d.ts +0 -98
  86. package/dist/orchestration/skill-similarity.js +0 -131
  87. package/dist/orchestration/streaming-tool-executor.d.ts +0 -73
  88. package/dist/orchestration/streaming-tool-executor.js +0 -96
  89. package/dist/orchestration/team-orchestration.d.ts +0 -195
  90. package/dist/orchestration/team-orchestration.js +0 -369
  91. package/dist/orchestration/team-tool-loop-wiring.d.ts +0 -92
  92. package/dist/orchestration/team-tool-loop-wiring.js +0 -147
  93. package/dist/orchestration/tool-choice-policy.d.ts +0 -54
  94. package/dist/orchestration/tool-choice-policy.js +0 -164
  95. package/dist/orchestration/tool-loop-state.d.ts +0 -50
  96. package/dist/orchestration/tool-loop-state.js +0 -133
  97. package/dist/orchestration/tool-schema.d.ts +0 -39
  98. package/dist/orchestration/tool-schema.js +0 -297
  99. package/dist/orchestration/transcript-repair.d.ts +0 -42
  100. package/dist/orchestration/transcript-repair.js +0 -426
  101. package/dist/orchestration/turn-loop-guard.d.ts +0 -86
  102. package/dist/orchestration/turn-loop-guard.js +0 -92
  103. package/dist/orchestration/web-browser-policy.d.ts +0 -17
  104. package/dist/orchestration/web-browser-policy.js +0 -39
  105. package/dist/runtime/context-compression.d.ts +0 -61
  106. package/dist/runtime/context-compression.js +0 -274
  107. package/dist/runtime/hook-registry.d.ts +0 -12
  108. package/dist/runtime/hook-registry.js +0 -53
  109. package/dist/runtime/memory-hooks.d.ts +0 -23
  110. package/dist/runtime/memory-hooks.js +0 -65
  111. package/dist/runtime/tool-eligibility.d.ts +0 -59
  112. package/dist/runtime/tool-eligibility.js +0 -111
  113. package/dist/skills/index.d.ts +0 -108
  114. package/dist/skills/index.js +0 -82
  115. package/dist/skills/memory-extractor.d.ts +0 -64
  116. package/dist/skills/memory-extractor.js +0 -173
  117. package/dist/skills/memory-query-tool.d.ts +0 -43
  118. package/dist/skills/memory-query-tool.js +0 -127
  119. package/dist/skills/memory-store.d.ts +0 -66
  120. package/dist/skills/memory-store.js +0 -228
  121. package/dist/skills/memory-tool.d.ts +0 -67
  122. package/dist/skills/memory-tool.js +0 -192
  123. package/dist/skills/portable-tool.d.ts +0 -71
  124. package/dist/skills/portable-tool.js +0 -14
  125. package/dist/skills/qmemory-adapter.d.ts +0 -52
  126. package/dist/skills/qmemory-adapter.js +0 -165
  127. package/dist/skills/skill-frontmatter.d.ts +0 -19
  128. package/dist/skills/skill-frontmatter.js +0 -344
  129. package/dist/skills/skill-guard.d.ts +0 -23
  130. package/dist/skills/skill-guard.js +0 -229
  131. package/dist/skills/skill-loader.d.ts +0 -16
  132. package/dist/skills/skill-loader.js +0 -303
  133. package/dist/skills/skill-source.d.ts +0 -119
  134. package/dist/skills/skill-source.js +0 -126
  135. package/dist/skills/skill-types.d.ts +0 -199
  136. package/dist/skills/skill-types.js +0 -6
  137. package/dist/skills/think-tool.d.ts +0 -16
  138. package/dist/skills/think-tool.js +0 -59
  139. package/dist/skills/todo-tool.d.ts +0 -63
  140. package/dist/skills/todo-tool.js +0 -114
  141. package/dist/skills/tools/agent-tool.d.ts +0 -91
  142. package/dist/skills/tools/agent-tool.js +0 -142
  143. package/dist/skills/tools/apply-patch-tool.d.ts +0 -29
  144. package/dist/skills/tools/apply-patch-tool.js +0 -184
  145. package/dist/skills/tools/ask-user-tool.d.ts +0 -80
  146. package/dist/skills/tools/ask-user-tool.js +0 -121
  147. package/dist/skills/tools/brief-tool.d.ts +0 -74
  148. package/dist/skills/tools/brief-tool.js +0 -95
  149. package/dist/skills/tools/browser-tool.d.ts +0 -114
  150. package/dist/skills/tools/browser-tool.js +0 -155
  151. package/dist/skills/tools/checkpoint-tool.d.ts +0 -66
  152. package/dist/skills/tools/checkpoint-tool.js +0 -102
  153. package/dist/skills/tools/config-tool.d.ts +0 -63
  154. package/dist/skills/tools/config-tool.js +0 -143
  155. package/dist/skills/tools/cron-tool.d.ts +0 -116
  156. package/dist/skills/tools/cron-tool.js +0 -175
  157. package/dist/skills/tools/edit-tool.d.ts +0 -43
  158. package/dist/skills/tools/edit-tool.js +0 -70
  159. package/dist/skills/tools/exec-tool.d.ts +0 -102
  160. package/dist/skills/tools/exec-tool.js +0 -133
  161. package/dist/skills/tools/image-generate-tool.d.ts +0 -62
  162. package/dist/skills/tools/image-generate-tool.js +0 -67
  163. package/dist/skills/tools/instructions-tool.d.ts +0 -103
  164. package/dist/skills/tools/instructions-tool.js +0 -187
  165. package/dist/skills/tools/lsp-tool.d.ts +0 -153
  166. package/dist/skills/tools/lsp-tool.js +0 -227
  167. package/dist/skills/tools/mcp-client-types.d.ts +0 -269
  168. package/dist/skills/tools/mcp-client-types.js +0 -53
  169. package/dist/skills/tools/mcp-tool.d.ts +0 -249
  170. package/dist/skills/tools/mcp-tool.js +0 -503
  171. package/dist/skills/tools/memory-tool.d.ts +0 -74
  172. package/dist/skills/tools/memory-tool.js +0 -88
  173. package/dist/skills/tools/monitor-tool.d.ts +0 -113
  174. package/dist/skills/tools/monitor-tool.js +0 -131
  175. package/dist/skills/tools/music-generate-tool.d.ts +0 -55
  176. package/dist/skills/tools/music-generate-tool.js +0 -62
  177. package/dist/skills/tools/notify-tool.d.ts +0 -53
  178. package/dist/skills/tools/notify-tool.js +0 -62
  179. package/dist/skills/tools/patch-tool.d.ts +0 -45
  180. package/dist/skills/tools/patch-tool.js +0 -505
  181. package/dist/skills/tools/pdf-tool.d.ts +0 -66
  182. package/dist/skills/tools/pdf-tool.js +0 -88
  183. package/dist/skills/tools/plan-mode-tool.d.ts +0 -59
  184. package/dist/skills/tools/plan-mode-tool.js +0 -122
  185. package/dist/skills/tools/read-tool.d.ts +0 -51
  186. package/dist/skills/tools/read-tool.js +0 -84
  187. package/dist/skills/tools/repl-tool.d.ts +0 -70
  188. package/dist/skills/tools/repl-tool.js +0 -69
  189. package/dist/skills/tools/search-tool.d.ts +0 -112
  190. package/dist/skills/tools/search-tool.js +0 -225
  191. package/dist/skills/tools/send-message-tool.d.ts +0 -51
  192. package/dist/skills/tools/send-message-tool.js +0 -76
  193. package/dist/skills/tools/skill-list-tool.d.ts +0 -33
  194. package/dist/skills/tools/skill-list-tool.js +0 -54
  195. package/dist/skills/tools/skill-manage-tool.d.ts +0 -73
  196. package/dist/skills/tools/skill-manage-tool.js +0 -153
  197. package/dist/skills/tools/skill-view-tool.d.ts +0 -37
  198. package/dist/skills/tools/skill-view-tool.js +0 -72
  199. package/dist/skills/tools/sleep-tool.d.ts +0 -49
  200. package/dist/skills/tools/sleep-tool.js +0 -81
  201. package/dist/skills/tools/structured-output-tool.d.ts +0 -116
  202. package/dist/skills/tools/structured-output-tool.js +0 -176
  203. package/dist/skills/tools/task-tool.d.ts +0 -104
  204. package/dist/skills/tools/task-tool.js +0 -161
  205. package/dist/skills/tools/team-tool.d.ts +0 -89
  206. package/dist/skills/tools/team-tool.js +0 -105
  207. package/dist/skills/tools/tool-search-tool.d.ts +0 -51
  208. package/dist/skills/tools/tool-search-tool.js +0 -110
  209. package/dist/skills/tools/tts-tool.d.ts +0 -38
  210. package/dist/skills/tools/tts-tool.js +0 -45
  211. package/dist/skills/tools/video-edit-tool.d.ts +0 -69
  212. package/dist/skills/tools/video-edit-tool.js +0 -74
  213. package/dist/skills/tools/video-generate-tool.d.ts +0 -62
  214. package/dist/skills/tools/video-generate-tool.js +0 -66
  215. package/dist/skills/tools/video-merge-tool.d.ts +0 -105
  216. package/dist/skills/tools/video-merge-tool.js +0 -92
  217. package/dist/skills/tools/video-upscale-tool.d.ts +0 -45
  218. package/dist/skills/tools/video-upscale-tool.js +0 -52
  219. package/dist/skills/tools/web-fetch-tool.d.ts +0 -78
  220. package/dist/skills/tools/web-fetch-tool.js +0 -92
  221. package/dist/skills/tools/web-search-tool.d.ts +0 -57
  222. package/dist/skills/tools/web-search-tool.js +0 -86
  223. package/dist/skills/tools/worktree-tool.d.ts +0 -69
  224. package/dist/skills/tools/worktree-tool.js +0 -147
  225. package/dist/skills/tools/write-tool.d.ts +0 -45
  226. package/dist/skills/tools/write-tool.js +0 -81
@@ -1,142 +0,0 @@
1
- // ============================================================
2
- // Agent Tool — CC-aligned fork sub-agent with built-in registry.
3
- // Reference: claude-code-haha/src/tools/AgentTool/AgentTool.tsx
4
- // claude-code-haha/src/tools/AgentTool/runAgent.ts
5
- // claude-code-haha/src/tools/AgentTool/forkSubagent.ts
6
- // claude-code-haha/src/tools/AgentTool/builtInAgents.ts
7
- // Category: system
8
- // ============================================================
9
- export const AGENT_TOOL_NAME = "agent";
10
- export const BUILT_IN_AGENT_TYPES = [
11
- "general", "explore", "plan", "code", "research", "verify",
12
- ];
13
- export const AGENT_TOOL_SCHEMA = {
14
- type: "object",
15
- properties: {
16
- agent: {
17
- type: "string",
18
- enum: ["general", "explore", "plan", "code", "research", "verify"],
19
- description: "Sub-agent type to fork:\n" +
20
- "- general: Full tool access, any task\n" +
21
- "- explore: Read-only codebase exploration (search, read, analyze)\n" +
22
- "- plan: Planning mode (explore + produce plan, no writes)\n" +
23
- "- code: Coding agent with full tool access\n" +
24
- "- research: Web research and information gathering\n" +
25
- "- verify: Run tests, check builds, validate changes",
26
- },
27
- prompt: {
28
- type: "string",
29
- description: "Detailed task for the sub-agent. The sub-agent shares your conversation " +
30
- "history as context (prompt cache shared). Be specific about what " +
31
- "information to return in the final response.",
32
- },
33
- description: {
34
- type: "string",
35
- description: "Short description (3-7 words) for status tracking.",
36
- },
37
- maxTurns: {
38
- type: "number",
39
- description: "Max turns for the sub-agent. Defaults: general=200, explore=50, plan=80, code=200, research=30, verify=40.",
40
- },
41
- background: {
42
- type: "boolean",
43
- description: "If true, runs in background and returns a task_id. Poll with task tool. Default: false.",
44
- },
45
- },
46
- required: ["agent", "prompt"],
47
- additionalProperties: false,
48
- };
49
- /** Maximum fork depth for in-memory agents. */
50
- export const MAX_FORK_DEPTH = 4;
51
- export function createAgentTool(deps) {
52
- return {
53
- name: AGENT_TOOL_NAME,
54
- label: "Sub-Agent",
55
- description: "Fork a sub-agent to handle complex tasks autonomously. " +
56
- "Sub-agents share your conversation context (prompt cache) and " +
57
- "have isolated tool state. Use for: parallel research, code exploration, " +
58
- "testing, delegating large tasks to specialized agents.",
59
- parameters: AGENT_TOOL_SCHEMA,
60
- searchHint: "fork subagent delegate spawn child parallel worker",
61
- isConcurrencySafe: true,
62
- execute: async (_toolCallId, params) => {
63
- // Validate prompt
64
- if (!params.prompt || params.prompt.trim().length < 10) {
65
- return {
66
- content: [{ type: "text", text: "Error: prompt must be at least 10 characters." }],
67
- details: { type: "agent", error: "prompt_too_short" },
68
- };
69
- }
70
- // Validate agent type
71
- if (!BUILT_IN_AGENT_TYPES.includes(params.agent)) {
72
- return {
73
- content: [{
74
- type: "text",
75
- text: `Error: unknown agent "${params.agent}". Available: ${BUILT_IN_AGENT_TYPES.join(", ")}`,
76
- }],
77
- details: { type: "agent", error: "invalid_agent_type" },
78
- };
79
- }
80
- // Fork depth guard
81
- const depth = deps.currentForkDepth ?? 0;
82
- if (depth >= MAX_FORK_DEPTH) {
83
- return {
84
- content: [{
85
- type: "text",
86
- text: `Error: maximum fork depth (${MAX_FORK_DEPTH}) reached. Cannot spawn more sub-agents. Complete current work instead.`,
87
- }],
88
- details: { type: "agent", error: "max_depth_reached", depth },
89
- };
90
- }
91
- try {
92
- const result = await deps.forkAgent({
93
- agent: params.agent,
94
- prompt: params.prompt.trim(),
95
- description: params.description,
96
- maxTurns: params.maxTurns,
97
- background: params.background,
98
- abortSignal: deps.abortSignal,
99
- });
100
- // Background mode — return task reference
101
- if (params.background && result.status === "running") {
102
- return {
103
- content: [{
104
- type: "text",
105
- text: `Sub-agent "${params.agent}" started in background.\nAgent ID: ${result.agentId}\nUse task tool with this ID to check status and get output.`,
106
- }],
107
- details: { type: "agent", agentId: result.agentId, status: "running", background: true },
108
- };
109
- }
110
- // Failed
111
- if (result.status === "failed") {
112
- return {
113
- content: [{ type: "text", text: `Sub-agent failed: ${result.error || "unknown error"}` }],
114
- details: { type: "agent", agentId: result.agentId, status: "failed", error: result.error },
115
- };
116
- }
117
- // Completed — return output with metadata
118
- const output = result.output || "(sub-agent returned no output)";
119
- const suffix = result.maxTurnsReached
120
- ? "\n\n[Note: Sub-agent reached turn limit. Output may be incomplete.]"
121
- : "";
122
- return {
123
- content: [{ type: "text", text: output + suffix }],
124
- details: {
125
- type: "agent",
126
- agentId: result.agentId,
127
- status: "completed",
128
- tokensUsed: result.tokensUsed,
129
- maxTurnsReached: result.maxTurnsReached,
130
- },
131
- };
132
- }
133
- catch (err) {
134
- const msg = err instanceof Error ? err.message : String(err);
135
- return {
136
- content: [{ type: "text", text: `Sub-agent execution failed: ${msg}` }],
137
- details: { type: "agent", error: "execution_error", message: msg },
138
- };
139
- }
140
- },
141
- };
142
- }
@@ -1,29 +0,0 @@
1
- import type { PortableTool } from "../portable-tool.js";
2
- export declare const APPLY_PATCH_TOOL_NAME: "apply_patch";
3
- export interface ApplyPatchToolParams {
4
- input: string;
5
- }
6
- export declare const APPLY_PATCH_TOOL_SCHEMA: {
7
- readonly type: "object";
8
- readonly properties: {
9
- readonly input: {
10
- readonly type: "string";
11
- readonly description: "Patch content using the *** Begin Patch / *** End Patch format.";
12
- };
13
- };
14
- readonly required: readonly ["input"];
15
- };
16
- export interface ApplyPatchSummary {
17
- added: string[];
18
- modified: string[];
19
- deleted: string[];
20
- }
21
- /** Deps injected by the host runtime for file patching. */
22
- export interface ApplyPatchToolDeps {
23
- readFile(path: string): Promise<string>;
24
- writeFile(path: string, content: string): Promise<void>;
25
- deleteFile(path: string): Promise<void>;
26
- fileExists(path: string): Promise<boolean>;
27
- resolvePath(input: string): string;
28
- }
29
- export declare function createApplyPatchTool(deps: ApplyPatchToolDeps): PortableTool<ApplyPatchToolParams>;
@@ -1,184 +0,0 @@
1
- // ============================================================
2
- // Apply Patch Tool — apply unified diff patches to files.
3
- // Category: coding
4
- // ============================================================
5
- export const APPLY_PATCH_TOOL_NAME = "apply_patch";
6
- export const APPLY_PATCH_TOOL_SCHEMA = {
7
- type: "object",
8
- properties: {
9
- input: {
10
- type: "string",
11
- description: "Patch content using the *** Begin Patch / *** End Patch format.",
12
- },
13
- },
14
- required: ["input"],
15
- };
16
- function parsePatch(input) {
17
- const lines = input.split("\n");
18
- const ops = [];
19
- let current = null;
20
- let currentHunk = null;
21
- let inPatch = false;
22
- for (const line of lines) {
23
- if (line.startsWith("*** Begin Patch")) {
24
- inPatch = true;
25
- continue;
26
- }
27
- if (line.startsWith("*** End Patch")) {
28
- break;
29
- }
30
- if (!inPatch)
31
- continue;
32
- if (line.startsWith("*** Add File: ")) {
33
- if (current)
34
- ops.push(current);
35
- current = { type: "add", path: line.slice("*** Add File: ".length).trim(), hunks: [] };
36
- currentHunk = { contextBefore: [], removals: [], additions: [], contextAfter: [] };
37
- current.hunks.push(currentHunk);
38
- }
39
- else if (line.startsWith("*** Update File: ")) {
40
- if (current)
41
- ops.push(current);
42
- current = { type: "update", path: line.slice("*** Update File: ".length).trim(), hunks: [] };
43
- currentHunk = null;
44
- }
45
- else if (line.startsWith("*** Delete File: ")) {
46
- if (current)
47
- ops.push(current);
48
- current = { type: "delete", path: line.slice("*** Delete File: ".length).trim(), hunks: [] };
49
- currentHunk = null;
50
- }
51
- else if (line.startsWith("*** Move to: ") && current) {
52
- current.moveTo = line.slice("*** Move to: ".length).trim();
53
- }
54
- else if (line.startsWith("@@ ") && current) {
55
- currentHunk = { contextBefore: [], removals: [], additions: [], contextAfter: [] };
56
- current.hunks.push(currentHunk);
57
- }
58
- else if (currentHunk) {
59
- if (line.startsWith("+")) {
60
- currentHunk.additions.push(line.slice(1));
61
- }
62
- else if (line.startsWith("-")) {
63
- currentHunk.removals.push(line.slice(1));
64
- }
65
- else {
66
- // context line (space prefix or bare)
67
- const ctx = line.startsWith(" ") ? line.slice(1) : line;
68
- if (currentHunk.additions.length === 0 && currentHunk.removals.length === 0) {
69
- currentHunk.contextBefore.push(ctx);
70
- }
71
- else {
72
- currentHunk.contextAfter.push(ctx);
73
- }
74
- }
75
- }
76
- }
77
- if (current)
78
- ops.push(current);
79
- return ops;
80
- }
81
- function applyHunksToContent(content, hunks) {
82
- const lines = content.split("\n");
83
- let result = [...lines];
84
- for (const hunk of hunks) {
85
- // Find context match position
86
- let matchStart = -1;
87
- if (hunk.contextBefore.length > 0) {
88
- for (let i = 0; i <= result.length - hunk.contextBefore.length; i++) {
89
- let matches = true;
90
- for (let j = 0; j < hunk.contextBefore.length; j++) {
91
- if (result[i + j] !== hunk.contextBefore[j]) {
92
- matches = false;
93
- break;
94
- }
95
- }
96
- if (matches) {
97
- matchStart = i + hunk.contextBefore.length;
98
- break;
99
- }
100
- }
101
- }
102
- else {
103
- matchStart = 0;
104
- }
105
- if (matchStart === -1)
106
- continue;
107
- // Remove old lines
108
- if (hunk.removals.length > 0) {
109
- result.splice(matchStart, hunk.removals.length, ...hunk.additions);
110
- }
111
- else {
112
- result.splice(matchStart, 0, ...hunk.additions);
113
- }
114
- }
115
- return result.join("\n");
116
- }
117
- export function createApplyPatchTool(deps) {
118
- return {
119
- name: APPLY_PATCH_TOOL_NAME,
120
- label: "Apply Patch",
121
- description: "Apply a patch to one or more files using the *** Begin Patch / *** End Patch format. " +
122
- "Supports Add File, Update File, Delete File, and Move To operations.",
123
- parameters: APPLY_PATCH_TOOL_SCHEMA,
124
- execute: async (_toolCallId, params) => {
125
- const ops = parsePatch(params.input);
126
- if (ops.length === 0) {
127
- return {
128
- content: [{ type: "text", text: "Error: No valid patch operations found. Ensure *** Begin Patch / *** End Patch markers are present." }],
129
- };
130
- }
131
- const summary = { added: [], modified: [], deleted: [] };
132
- const errors = [];
133
- for (const op of ops) {
134
- const resolved = deps.resolvePath(op.path);
135
- try {
136
- switch (op.type) {
137
- case "add": {
138
- const newContent = op.hunks.flatMap((h) => [...h.additions]).join("\n");
139
- await deps.writeFile(resolved, newContent);
140
- summary.added.push(op.path);
141
- break;
142
- }
143
- case "update": {
144
- const existing = await deps.readFile(resolved);
145
- const patched = applyHunksToContent(existing, op.hunks);
146
- if (op.moveTo) {
147
- const dest = deps.resolvePath(op.moveTo);
148
- await deps.writeFile(dest, patched);
149
- await deps.deleteFile(resolved);
150
- summary.modified.push(`${op.path} → ${op.moveTo}`);
151
- }
152
- else {
153
- await deps.writeFile(resolved, patched);
154
- summary.modified.push(op.path);
155
- }
156
- break;
157
- }
158
- case "delete": {
159
- await deps.deleteFile(resolved);
160
- summary.deleted.push(op.path);
161
- break;
162
- }
163
- }
164
- }
165
- catch (err) {
166
- errors.push(`${op.type} ${op.path}: ${err instanceof Error ? err.message : String(err)}`);
167
- }
168
- }
169
- const parts = [];
170
- if (summary.added.length)
171
- parts.push(`Added: ${summary.added.join(", ")}`);
172
- if (summary.modified.length)
173
- parts.push(`Modified: ${summary.modified.join(", ")}`);
174
- if (summary.deleted.length)
175
- parts.push(`Deleted: ${summary.deleted.join(", ")}`);
176
- if (errors.length)
177
- parts.push(`Errors: ${errors.join("; ")}`);
178
- return {
179
- content: [{ type: "text", text: parts.join("\n") || "No changes applied." }],
180
- details: { type: "apply_patch", summary, errors },
181
- };
182
- },
183
- };
184
- }
@@ -1,80 +0,0 @@
1
- import type { PortableTool } from "../portable-tool.js";
2
- export declare const ASK_USER_TOOL_NAME: "ask_user";
3
- export interface AskUserOption {
4
- label: string;
5
- description?: string;
6
- }
7
- export interface AskUserQuestion {
8
- question: string;
9
- header: string;
10
- options?: AskUserOption[];
11
- multiSelect?: boolean;
12
- }
13
- export interface AskUserToolParams {
14
- questions: AskUserQuestion[];
15
- }
16
- export declare const ASK_USER_TOOL_SCHEMA: {
17
- readonly type: "object";
18
- readonly properties: {
19
- readonly questions: {
20
- readonly type: "array";
21
- readonly minItems: 1;
22
- readonly maxItems: 4;
23
- readonly description: "1-4 clarifying questions to ask the user.";
24
- readonly items: {
25
- readonly type: "object";
26
- readonly properties: {
27
- readonly question: {
28
- readonly type: "string";
29
- readonly description: "The question text. Should end with '?'.";
30
- };
31
- readonly header: {
32
- readonly type: "string";
33
- readonly description: "Short identifier/tag for this question (max 50 chars).";
34
- };
35
- readonly options: {
36
- readonly type: "array";
37
- readonly description: "2-4 options for the user to choose from. Omit for free text.";
38
- readonly items: {
39
- readonly type: "object";
40
- readonly properties: {
41
- readonly label: {
42
- readonly type: "string";
43
- readonly description: "Display label (1-5 words).";
44
- };
45
- readonly description: {
46
- readonly type: "string";
47
- readonly description: "Brief explanation of this option.";
48
- };
49
- };
50
- readonly required: readonly ["label"];
51
- };
52
- };
53
- readonly multiSelect: {
54
- readonly type: "boolean";
55
- readonly description: "Allow selecting multiple options (default: false).";
56
- };
57
- };
58
- readonly required: readonly ["question", "header"];
59
- };
60
- };
61
- };
62
- readonly required: readonly ["questions"];
63
- };
64
- export interface AskUserAnswer {
65
- question: string;
66
- answer: string;
67
- }
68
- /**
69
- * Host-provided user interaction backend.
70
- * The host renders the questions in the UI and collects answers.
71
- */
72
- export interface AskUserToolDeps {
73
- /**
74
- * Present questions to the user and collect answers.
75
- * Returns a map of question text → answer text.
76
- * If the user declines, returns null.
77
- */
78
- askUser(questions: AskUserQuestion[]): Promise<Record<string, string> | null>;
79
- }
80
- export declare function createAskUserTool(deps: AskUserToolDeps): PortableTool<AskUserToolParams>;
@@ -1,121 +0,0 @@
1
- // ============================================================
2
- // Ask User Tool — ask the user clarifying questions.
3
- // Reference: claude-code-haha/src/tools/AskUserQuestionTool/AskUserQuestionTool.tsx
4
- // Category: interaction
5
- // ============================================================
6
- export const ASK_USER_TOOL_NAME = "ask_user";
7
- export const ASK_USER_TOOL_SCHEMA = {
8
- type: "object",
9
- properties: {
10
- questions: {
11
- type: "array",
12
- minItems: 1,
13
- maxItems: 4,
14
- description: "1-4 clarifying questions to ask the user.",
15
- items: {
16
- type: "object",
17
- properties: {
18
- question: {
19
- type: "string",
20
- description: "The question text. Should end with '?'.",
21
- },
22
- header: {
23
- type: "string",
24
- description: "Short identifier/tag for this question (max 50 chars).",
25
- },
26
- options: {
27
- type: "array",
28
- description: "2-4 options for the user to choose from. Omit for free text.",
29
- items: {
30
- type: "object",
31
- properties: {
32
- label: {
33
- type: "string",
34
- description: "Display label (1-5 words).",
35
- },
36
- description: {
37
- type: "string",
38
- description: "Brief explanation of this option.",
39
- },
40
- },
41
- required: ["label"],
42
- },
43
- },
44
- multiSelect: {
45
- type: "boolean",
46
- description: "Allow selecting multiple options (default: false).",
47
- },
48
- },
49
- required: ["question", "header"],
50
- },
51
- },
52
- },
53
- required: ["questions"],
54
- };
55
- export function createAskUserTool(deps) {
56
- return {
57
- name: ASK_USER_TOOL_NAME,
58
- label: "Ask User",
59
- description: "Ask the user clarifying questions when you need more information to proceed. " +
60
- "Supports free text questions and multiple-choice options. " +
61
- "Use this when the user's intent is ambiguous or you need confirmation.",
62
- parameters: ASK_USER_TOOL_SCHEMA,
63
- execute: async (_toolCallId, params) => {
64
- // Validate questions count
65
- if (!params.questions || params.questions.length === 0) {
66
- return {
67
- content: [{ type: "text", text: "Error: at least one question is required." }],
68
- details: { type: "ask_user", error: "no_questions" },
69
- };
70
- }
71
- if (params.questions.length > 4) {
72
- return {
73
- content: [{ type: "text", text: "Error: maximum 4 questions allowed." }],
74
- details: { type: "ask_user", error: "too_many_questions" },
75
- };
76
- }
77
- // Validate unique question texts
78
- const questionTexts = params.questions.map((q) => q.question);
79
- if (new Set(questionTexts).size !== questionTexts.length) {
80
- return {
81
- content: [{ type: "text", text: "Error: all questions must have unique text." }],
82
- details: { type: "ask_user", error: "duplicate_questions" },
83
- };
84
- }
85
- // Validate options count and label uniqueness per question
86
- for (const q of params.questions) {
87
- if (q.options && (q.options.length < 2 || q.options.length > 4)) {
88
- return {
89
- content: [{ type: "text", text: `Error: question "${q.header}" must have 2-4 options (got ${q.options.length}).` }],
90
- details: { type: "ask_user", error: "invalid_option_count" },
91
- };
92
- }
93
- if (q.options) {
94
- const labels = q.options.map((o) => o.label);
95
- if (new Set(labels).size !== labels.length) {
96
- return {
97
- content: [{ type: "text", text: `Error: question "${q.header}" has duplicate option labels.` }],
98
- details: { type: "ask_user", error: "duplicate_option_labels" },
99
- };
100
- }
101
- }
102
- }
103
- const answers = await deps.askUser(params.questions);
104
- if (answers === null) {
105
- return {
106
- content: [{ type: "text", text: "User declined to answer questions." }],
107
- details: { type: "ask_user", declined: true },
108
- };
109
- }
110
- const lines = ["User answered:"];
111
- for (const q of params.questions) {
112
- const answer = answers[q.question] ?? "(no answer)";
113
- lines.push(`- ${q.header}: ${answer}`);
114
- }
115
- return {
116
- content: [{ type: "text", text: lines.join("\n") }],
117
- details: { type: "ask_user", answers, questionCount: params.questions.length },
118
- };
119
- },
120
- };
121
- }
@@ -1,74 +0,0 @@
1
- import type { PortableTool } from "../portable-tool.js";
2
- export declare const BRIEF_TOOL_NAME: "send_user_message";
3
- export type BriefMessageStatus = "normal" | "proactive";
4
- export interface BriefAttachment {
5
- /** Absolute or workspace-relative path */
6
- path: string;
7
- /** Size in bytes (filled by host) */
8
- size?: number;
9
- /** Whether the file is an image */
10
- isImage?: boolean;
11
- /** Upload UUID (host may upload for web preview) */
12
- fileUuid?: string;
13
- }
14
- export interface BriefToolParams {
15
- /** Markdown-formatted message to display to the user */
16
- message: string;
17
- /** File attachments to include with the message */
18
- attachments?: string[];
19
- /** Message status — 'proactive' for unsolicited updates */
20
- status?: BriefMessageStatus;
21
- }
22
- export declare const BRIEF_TOOL_SCHEMA: {
23
- readonly type: "object";
24
- readonly properties: {
25
- readonly message: {
26
- readonly type: "string";
27
- readonly description: string;
28
- readonly minLength: 1;
29
- };
30
- readonly attachments: {
31
- readonly type: "array";
32
- readonly description: "Optional file paths to attach (images, documents, etc.).";
33
- readonly items: {
34
- readonly type: "string";
35
- };
36
- readonly maxItems: 10;
37
- };
38
- readonly status: {
39
- readonly type: "string";
40
- readonly enum: readonly ["normal", "proactive"];
41
- readonly description: string;
42
- };
43
- };
44
- readonly required: readonly ["message"];
45
- };
46
- export interface BriefDeliveryResult {
47
- delivered: boolean;
48
- attachments?: BriefAttachment[];
49
- sentAt?: string;
50
- error?: string;
51
- }
52
- /**
53
- * Host-provided message delivery backend.
54
- */
55
- export interface BriefToolDeps {
56
- /** Deliver the message to the user's UI */
57
- deliverMessage(params: {
58
- message: string;
59
- attachments?: string[];
60
- status: BriefMessageStatus;
61
- }): Promise<BriefDeliveryResult>;
62
- /** Validate and resolve attachment paths. Returns resolved attachments or error. */
63
- resolveAttachments?(paths: string[]): Promise<BriefAttachment[] | {
64
- error: string;
65
- }>;
66
- }
67
- /** Check if brief mode is active (host determines this) */
68
- export interface BriefModeConfig {
69
- /** Whether the agent is in brief/chat mode */
70
- isBriefMode: boolean;
71
- /** Whether the user opted in via UI/CLI */
72
- userOptIn?: boolean;
73
- }
74
- export declare function createBriefTool(deps: BriefToolDeps): PortableTool<BriefToolParams>;