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,86 +0,0 @@
1
- // ============================================================
2
- // Web Search Tool — search the web for information.
3
- // Reference: claude-code-haha/src/tools/WebSearchTool/WebSearchTool.ts
4
- // hermes-agent-2026.4.30/tools/web_tools.py
5
- // Category: web
6
- // ============================================================
7
- export const WEB_SEARCH_TOOL_NAME = "web_search";
8
- export const WEB_SEARCH_TOOL_SCHEMA = {
9
- type: "object",
10
- properties: {
11
- query: {
12
- type: "string",
13
- description: "Search query string. Be specific and concise for best results.",
14
- },
15
- allowedDomains: {
16
- type: "array",
17
- items: { type: "string" },
18
- description: "Only include results from these domains (e.g. ['docs.python.org', 'stackoverflow.com']). " +
19
- "Cannot be used together with blockedDomains.",
20
- },
21
- blockedDomains: {
22
- type: "array",
23
- items: { type: "string" },
24
- description: "Exclude results from these domains. Cannot be used together with allowedDomains.",
25
- },
26
- },
27
- required: ["query"],
28
- };
29
- const MAX_RESULTS = 10;
30
- export function createWebSearchTool(deps) {
31
- return {
32
- name: WEB_SEARCH_TOOL_NAME,
33
- label: "Web Search",
34
- description: "Search the web for current information. Returns top results with title, URL, and snippet. " +
35
- "Use this when you need up-to-date information that may not be in your training data. " +
36
- "You MUST include source URLs as markdown links when citing search results.",
37
- parameters: WEB_SEARCH_TOOL_SCHEMA,
38
- execute: async (_toolCallId, params) => {
39
- // Validate mutual exclusivity
40
- if (params.allowedDomains?.length && params.blockedDomains?.length) {
41
- return {
42
- content: [{ type: "text", text: "Error: allowedDomains and blockedDomains cannot both be specified." }],
43
- details: { type: "web_search", error: "mutual_exclusion" },
44
- };
45
- }
46
- // Validate query
47
- if (!params.query || params.query.trim().length < 2) {
48
- return {
49
- content: [{ type: "text", text: "Error: query must be at least 2 characters." }],
50
- details: { type: "web_search", error: "invalid_query" },
51
- };
52
- }
53
- const output = await deps.search(params.query.trim(), {
54
- allowedDomains: params.allowedDomains,
55
- blockedDomains: params.blockedDomains,
56
- maxResults: MAX_RESULTS,
57
- });
58
- if (output.results.length === 0) {
59
- return {
60
- content: [{ type: "text", text: `No results found for: "${params.query}"` }],
61
- details: { type: "web_search", query: params.query, resultCount: 0 },
62
- };
63
- }
64
- const lines = [
65
- `Web search results for: "${output.query}"`,
66
- "",
67
- "REMINDER: You MUST include source URLs as markdown links when referencing these results.",
68
- "",
69
- ];
70
- for (let i = 0; i < output.results.length; i++) {
71
- const r = output.results[i];
72
- lines.push(`${i + 1}. [${r.title}](${r.url})`);
73
- lines.push(` ${r.snippet}`);
74
- lines.push("");
75
- }
76
- return {
77
- content: [{ type: "text", text: lines.join("\n") }],
78
- details: {
79
- type: "web_search",
80
- query: output.query,
81
- resultCount: output.results.length,
82
- },
83
- };
84
- },
85
- };
86
- }
@@ -1,147 +0,0 @@
1
- // ============================================================
2
- // Worktree Tool — git worktree isolation for parallel development.
3
- // Reference: claude-code-haha/src/tools/EnterWorktreeTool/EnterWorktreeTool.ts
4
- // claude-code-haha/src/tools/ExitWorktreeTool/ExitWorktreeTool.ts
5
- // Category: system (git)
6
- // Dependency: #13 AgentTool
7
- // ============================================================
8
- export const WORKTREE_TOOL_NAME = "worktree";
9
- export const WORKTREE_TOOL_SCHEMA = {
10
- type: "object",
11
- properties: {
12
- action: {
13
- type: "string",
14
- enum: ["enter", "exit", "list"],
15
- description: "enter: Create and switch to an isolated git worktree branch.\n" +
16
- "exit: Leave worktree (keep or remove it).\n" +
17
- "list: Show all active worktrees.",
18
- },
19
- name: {
20
- type: "string",
21
- description: "Worktree/branch name (for enter). Must be kebab-case, max 64 characters. " +
22
- "If omitted, auto-generated from task context.",
23
- },
24
- exitAction: {
25
- type: "string",
26
- enum: ["keep", "remove"],
27
- description: "For exit: 'keep' retains the worktree for later use; 'remove' deletes it.",
28
- },
29
- discardChanges: {
30
- type: "boolean",
31
- description: "Required true to confirm discarding uncommitted changes when exitAction='remove'. " +
32
- "Safety mechanism to prevent data loss.",
33
- },
34
- },
35
- required: ["action"],
36
- };
37
- const NAME_PATTERN = /^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]?$/;
38
- export function createWorktreeTool(deps) {
39
- return {
40
- name: WORKTREE_TOOL_NAME,
41
- label: "Git Worktree",
42
- description: "Create isolated git worktree branches for parallel development. " +
43
- "Each worktree has its own working directory independent of the main branch. " +
44
- "Use for: parallel features, safe experimentation, sub-agent isolation. " +
45
- "Exit to keep or remove the worktree when done.",
46
- parameters: WORKTREE_TOOL_SCHEMA,
47
- execute: async (_toolCallId, params) => {
48
- switch (params.action) {
49
- case "enter": {
50
- if (deps.isInWorktree()) {
51
- return {
52
- content: [{ type: "text", text: "Error: already in a worktree. Exit first before entering another." }],
53
- details: { type: "worktree", error: "already_in_worktree" },
54
- };
55
- }
56
- if (params.name && !NAME_PATTERN.test(params.name)) {
57
- return {
58
- content: [{ type: "text", text: "Error: name must be kebab-case (a-z, 0-9, hyphens), 2-64 characters." }],
59
- details: { type: "worktree", error: "invalid_name" },
60
- };
61
- }
62
- const result = await deps.enterWorktree(params.name);
63
- if (!result.success) {
64
- return {
65
- content: [{ type: "text", text: `Error: ${result.error || "failed to create worktree"}` }],
66
- details: { type: "worktree", error: result.error },
67
- };
68
- }
69
- const wt = result.worktree;
70
- const lines = [
71
- `Entered worktree: ${wt.name}`,
72
- ` Branch: ${wt.branch}`,
73
- ` Path: ${wt.path}`,
74
- "",
75
- "Working in isolated branch. Changes here do not affect the main branch.",
76
- "Use action='exit' when done (keep or remove).",
77
- ];
78
- return {
79
- content: [{ type: "text", text: lines.join("\n") }],
80
- details: { type: "worktree", action: "enter", name: wt.name, branch: wt.branch, path: wt.path },
81
- };
82
- }
83
- case "exit": {
84
- if (!deps.isInWorktree()) {
85
- return {
86
- content: [{ type: "text", text: "Error: not in a worktree." }],
87
- details: { type: "worktree", error: "not_in_worktree" },
88
- };
89
- }
90
- const exitAction = params.exitAction || "keep";
91
- // Safety: require explicit discard confirmation for remove with changes
92
- if (exitAction === "remove") {
93
- const current = deps.currentWorktree?.();
94
- if (current && (current.hasChanges || current.unpushedCommits > 0) && !params.discardChanges) {
95
- const warnings = [];
96
- if (current.hasChanges)
97
- warnings.push("uncommitted changes");
98
- if (current.unpushedCommits > 0)
99
- warnings.push(`${current.unpushedCommits} unpushed commit(s)`);
100
- return {
101
- content: [{ type: "text", text: `Error: worktree has ${warnings.join(" and ")}. Set discardChanges=true to confirm removal, or use exitAction='keep'.` }],
102
- details: { type: "worktree", error: "has_changes", hasChanges: current.hasChanges, unpushedCommits: current.unpushedCommits },
103
- };
104
- }
105
- }
106
- const result = await deps.exitWorktree(exitAction, params.discardChanges);
107
- if (!result.success) {
108
- return {
109
- content: [{ type: "text", text: `Error: ${result.error || "failed to exit worktree"}` }],
110
- details: { type: "worktree", error: result.error },
111
- };
112
- }
113
- const action = exitAction === "keep" ? "Worktree kept for later use." : "Worktree removed.";
114
- return {
115
- content: [{ type: "text", text: `Exited worktree. ${action}\nRestored to: ${result.previousCwd || "main workspace"}` }],
116
- details: { type: "worktree", action: "exit", exitAction, previousCwd: result.previousCwd },
117
- };
118
- }
119
- case "list": {
120
- const result = await deps.listWorktrees();
121
- if (!result.worktrees || result.worktrees.length === 0) {
122
- return {
123
- content: [{ type: "text", text: "No worktrees (only the main working tree)." }],
124
- details: { type: "worktree", action: "list", count: 0 },
125
- };
126
- }
127
- const lines = [`Worktrees (${result.worktrees.length}):`, ""];
128
- for (const wt of result.worktrees) {
129
- const current = wt.isCurrent ? " ← current" : "";
130
- const status = wt.hasChanges ? " (has changes)" : "";
131
- lines.push(` ${wt.name} [${wt.branch}]${current}${status}`);
132
- lines.push(` path: ${wt.path}`);
133
- }
134
- return {
135
- content: [{ type: "text", text: lines.join("\n") }],
136
- details: { type: "worktree", action: "list", count: result.worktrees.length },
137
- };
138
- }
139
- default:
140
- return {
141
- content: [{ type: "text", text: `Error: unknown action "${params.action}".` }],
142
- details: { type: "worktree", error: "unknown_action" },
143
- };
144
- }
145
- },
146
- };
147
- }
@@ -1,81 +0,0 @@
1
- // ============================================================
2
- // File Write Tool — create/overwrite files.
3
- // Reference: claude-code-haha/src/tools/FileWriteTool/FileWriteTool.ts
4
- // Category: coding
5
- // ============================================================
6
- export const WRITE_TOOL_NAME = "write";
7
- export const WRITE_TOOL_SCHEMA = {
8
- type: "object",
9
- properties: {
10
- path: {
11
- type: "string",
12
- description: "Absolute path to the file to write.",
13
- },
14
- content: {
15
- type: "string",
16
- description: "Content to write to the file.",
17
- },
18
- },
19
- required: ["path", "content"],
20
- };
21
- const MAX_WRITE_SIZE = 500_000; // 500KB safety limit
22
- export function createWriteTool(deps) {
23
- return {
24
- name: WRITE_TOOL_NAME,
25
- label: "Write File",
26
- description: "Write content to a file. Creates the file if it doesn't exist, overwrites if it does. " +
27
- "Automatically creates parent directories. " +
28
- "Prefer edit/patch for modifying existing files (safer than full overwrite).",
29
- parameters: WRITE_TOOL_SCHEMA,
30
- execute: async (_toolCallId, params) => {
31
- const resolved = deps.resolvePath(params.path);
32
- // Validate path access
33
- if (deps.validatePath) {
34
- const blocked = deps.validatePath(resolved);
35
- if (blocked) {
36
- return {
37
- content: [{ type: "text", text: `Access denied: ${blocked}` }],
38
- details: { type: "write", path: resolved, error: "access_denied" },
39
- };
40
- }
41
- }
42
- // Large file protection
43
- if (params.content.length > MAX_WRITE_SIZE) {
44
- return {
45
- content: [{
46
- type: "text",
47
- text: `Content too large (${params.content.length} chars, max ${MAX_WRITE_SIZE}). ` +
48
- "Split into multiple writes or use a different approach.",
49
- }],
50
- details: { type: "write", path: resolved, error: "content_too_large" },
51
- };
52
- }
53
- // First-read-then-write protection
54
- if (deps.checkReadBeforeWrite) {
55
- const warning = deps.checkReadBeforeWrite(resolved);
56
- if (warning) {
57
- return {
58
- content: [{ type: "text", text: warning }],
59
- details: { type: "write", path: resolved, error: "not_read_first" },
60
- };
61
- }
62
- }
63
- // Concurrent modification detection
64
- if (deps.checkConcurrentModification) {
65
- const conflict = deps.checkConcurrentModification(resolved);
66
- if (conflict) {
67
- return {
68
- content: [{ type: "text", text: `Concurrent modification detected: ${conflict}. Re-read the file first.` }],
69
- details: { type: "write", path: resolved, error: "concurrent_modification" },
70
- };
71
- }
72
- }
73
- await deps.writeFile(resolved, params.content);
74
- const lineCount = params.content.split("\n").length;
75
- return {
76
- content: [{ type: "text", text: `Wrote ${lineCount} lines to ${resolved}` }],
77
- details: { type: "write", path: resolved, lineCount },
78
- };
79
- },
80
- };
81
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes