apex-code 0.0.1-alpha.4 → 0.0.1-alpha.5
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.
- package/CHANGELOG.md +49 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +2 -2
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +20 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +91 -1
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +17 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +10 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/lsp/client.d.ts +76 -0
- package/dist/core/lsp/client.d.ts.map +1 -0
- package/dist/core/lsp/client.js +469 -0
- package/dist/core/lsp/client.js.map +1 -0
- package/dist/core/lsp/diagnostics.d.ts +47 -0
- package/dist/core/lsp/diagnostics.d.ts.map +1 -0
- package/dist/core/lsp/diagnostics.js +224 -0
- package/dist/core/lsp/diagnostics.js.map +1 -0
- package/dist/core/lsp/pool.d.ts +48 -0
- package/dist/core/lsp/pool.d.ts.map +1 -0
- package/dist/core/lsp/pool.js +150 -0
- package/dist/core/lsp/pool.js.map +1 -0
- package/dist/core/lsp/registry.d.ts +49 -0
- package/dist/core/lsp/registry.d.ts.map +1 -0
- package/dist/core/lsp/registry.js +215 -0
- package/dist/core/lsp/registry.js.map +1 -0
- package/dist/core/lsp/status.d.ts +23 -0
- package/dist/core/lsp/status.d.ts.map +1 -0
- package/dist/core/lsp/status.js +35 -0
- package/dist/core/lsp/status.js.map +1 -0
- package/dist/core/lsp/sync.d.ts +13 -0
- package/dist/core/lsp/sync.d.ts.map +1 -0
- package/dist/core/lsp/sync.js +71 -0
- package/dist/core/lsp/sync.js.map +1 -0
- package/dist/core/project-trust.d.ts.map +1 -1
- package/dist/core/project-trust.js +1 -1
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/sdk.d.ts +4 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +10 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +3 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +3 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tools/contract.d.ts +29 -2
- package/dist/core/tools/contract.d.ts.map +1 -1
- package/dist/core/tools/contract.js.map +1 -1
- package/dist/core/tools/diagnostics.d.ts +39 -0
- package/dist/core/tools/diagnostics.d.ts.map +1 -0
- package/dist/core/tools/diagnostics.js +62 -0
- package/dist/core/tools/diagnostics.js.map +1 -0
- package/dist/core/tools/edit.d.ts +10 -0
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +17 -8
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/index.d.ts +15 -2
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +6 -0
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/lsp.d.ts +62 -0
- package/dist/core/tools/lsp.d.ts.map +1 -0
- package/dist/core/tools/lsp.js +216 -0
- package/dist/core/tools/lsp.js.map +1 -0
- package/dist/core/tools/write.d.ts +10 -0
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +16 -3
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +49 -1
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +235 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.js +2 -1
- package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +1 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +1 -0
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/splash-header.d.ts +41 -0
- package/dist/modes/interactive/components/splash-header.d.ts.map +1 -0
- package/dist/modes/interactive/components/splash-header.js +145 -0
- package/dist/modes/interactive/components/splash-header.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +17 -14
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/apex.json +94 -0
- package/dist/modes/interactive/theme/light.json +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +6 -1
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/themes/apex-logo.d.ts +21 -0
- package/dist/themes/apex-logo.d.ts.map +1 -0
- package/dist/themes/apex-logo.js +31 -0
- package/dist/themes/apex-logo.js.map +1 -0
- package/dist/utils/changelog.d.ts +7 -2
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js +82 -13
- package/dist/utils/changelog.js.map +1 -1
- package/npm-shrinkwrap.json +5 -5
- package/package.json +2 -2
package/dist/core/tools/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { withFileMutationQueue } from "./file-mutation-queue.js";
|
|
|
6
6
|
export { createFindTool, createFindToolDefinition, } from "./find.js";
|
|
7
7
|
export { createGrepTool, createGrepToolDefinition, } from "./grep.js";
|
|
8
8
|
export { createLsTool, createLsToolDefinition, } from "./ls.js";
|
|
9
|
+
export { createLspTool, createLspToolDefinition, } from "./lsp.js";
|
|
9
10
|
export { createPlanPresentTool, createPlanPresentToolDefinition, } from "./plan-present.js";
|
|
10
11
|
export { createReadTool, createReadToolDefinition, } from "./read.js";
|
|
11
12
|
export { createTestPermissionSpec, createTestTool, createTestToolDefinition, } from "./test.js";
|
|
@@ -21,6 +22,7 @@ import { createEditTool, createEditToolDefinition } from "./edit.js";
|
|
|
21
22
|
import { createFindTool, createFindToolDefinition } from "./find.js";
|
|
22
23
|
import { createGrepTool, createGrepToolDefinition } from "./grep.js";
|
|
23
24
|
import { createLsTool, createLsToolDefinition } from "./ls.js";
|
|
25
|
+
import { createLspTool, createLspToolDefinition } from "./lsp.js";
|
|
24
26
|
import { createPlanPresentTool, createPlanPresentToolDefinition } from "./plan-present.js";
|
|
25
27
|
import { createReadTool, createReadToolDefinition } from "./read.js";
|
|
26
28
|
import { createTestTool, createTestToolDefinition } from "./test.js";
|
|
@@ -183,6 +185,9 @@ export function createAllToolDefinitions(cwd, options) {
|
|
|
183
185
|
plan_present: createPlanPresentToolDefinition(),
|
|
184
186
|
delegate: createDelegateToolDefinition(options?.delegate?.runtime ?? noopDelegationRuntime),
|
|
185
187
|
test: createTestToolDefinition(cwd, options?.test),
|
|
188
|
+
// Registered only when configured (LSP.5): an unconfigured session's registry,
|
|
189
|
+
// and therefore its static prompt prefix, is unaffected by this subsystem.
|
|
190
|
+
...(options?.lsp ? { lsp: createLspToolDefinition(cwd, options.lsp) } : {}),
|
|
186
191
|
};
|
|
187
192
|
}
|
|
188
193
|
export function createCodingTools(cwd, options) {
|
|
@@ -223,6 +228,7 @@ export function createAllTools(cwd, options) {
|
|
|
223
228
|
plan_present: createPlanPresentTool(),
|
|
224
229
|
delegate: createDelegateTool(options?.delegate?.runtime ?? noopDelegationRuntime),
|
|
225
230
|
test: createTestTool(cwd, options?.test),
|
|
231
|
+
...(options?.lsp ? { lsp: createLspTool(cwd, options.lsp) } : {}),
|
|
226
232
|
};
|
|
227
233
|
}
|
|
228
234
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0C,iBAAiB,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC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AAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,KAAK,EAAE,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC;QAC3C,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,EAAE,EAAE,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC;QAClC,WAAW,EAAE,oBAAoB,CAAC,QAAQ,CAAC;QAC3C,UAAU,EAAE,mBAAmB,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,kBAAkB,CAAC;QACjF,UAAU,EAAE,mBAAmB,CAAC,OAAO,EAAE,UAAU,CAAC;QACpD,SAAS,EAAE,kBAAkB,CAAC,OAAO,EAAE,SAAS,CAAC;QACjD,QAAQ,EAAE,iBAAiB,EAAE;QAC7B,YAAY,EAAE,qBAAqB,EAAE;QACrC,QAAQ,EAAE,kBAAkB,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,IAAI,qBAAqB,CAAC;QACjF,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;KACxC,CAAC;AAAA,CACF","sourcesContent":["export { type AskUserDetails, type AskUserInput, createAskUserTool, createAskUserToolDefinition } from \"./ask-user.ts\";\nexport {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\tcreateBashTool,\n\tcreateBashToolDefinition,\n\tcreateLocalBashOperations,\n} from \"./bash.ts\";\nexport {\n\tcreateDelegateTool,\n\tcreateDelegateToolDefinition,\n\ttype DelegateDetails,\n\ttype DelegateInput,\n} from \"./delegate.ts\";\nexport {\n\tcreateEditTool,\n\tcreateEditToolDefinition,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n} from \"./edit.ts\";\nexport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nexport {\n\tcreateFindTool,\n\tcreateFindToolDefinition,\n\ttype FindOperations,\n\ttype FindToolDetails,\n\ttype FindToolInput,\n\ttype FindToolOptions,\n} from \"./find.ts\";\nexport {\n\tcreateGrepTool,\n\tcreateGrepToolDefinition,\n\ttype GrepOperations,\n\ttype GrepToolDetails,\n\ttype GrepToolInput,\n\ttype GrepToolOptions,\n} from \"./grep.ts\";\nexport {\n\tcreateLsTool,\n\tcreateLsToolDefinition,\n\ttype LsOperations,\n\ttype LsToolDetails,\n\ttype LsToolInput,\n\ttype LsToolOptions,\n} from \"./ls.ts\";\nexport {\n\tcreatePlanPresentTool,\n\tcreatePlanPresentToolDefinition,\n\ttype PlanPresentDetails,\n\ttype PlanPresentInput,\n} from \"./plan-present.ts\";\nexport {\n\tcreateReadTool,\n\tcreateReadToolDefinition,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n} from \"./read.ts\";\nexport {\n\tcreateTestPermissionSpec,\n\tcreateTestTool,\n\tcreateTestToolDefinition,\n\ttype TestOperationResult,\n\ttype TestOperations,\n\ttype TestRunDetails,\n\ttype TestToolInput,\n\ttype TestToolOptions,\n} from \"./test.ts\";\nexport {\n\tcreateTodoWriteTool,\n\tcreateTodoWriteToolDefinition,\n\ttype TodoItem,\n\ttype TodoWriteDetails,\n\ttype TodoWriteInput,\n\ttype TodoWriteStore,\n} from \"./todo-write.ts\";\nexport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n} from \"./truncate.ts\";\nexport {\n\tcreateWebFetchTool,\n\tcreateWebFetchToolDefinition,\n\ttype WebFetchDetails,\n\ttype WebFetchInput,\n\ttype WebFetchOperations,\n\ttype WebFetchToolOptions,\n} from \"./web-fetch.ts\";\nexport {\n\tcreateWebSearchTool,\n\tcreateWebSearchToolDefinition,\n\ttype WebSearchDetails,\n\ttype WebSearchInput,\n\ttype WebSearchOperations,\n\ttype WebSearchResult,\n\ttype WebSearchToolOptions,\n} from \"./web-search.ts\";\nexport {\n\tcreateWriteTool,\n\tcreateWriteToolDefinition,\n\ttype WriteOperations,\n\ttype WriteToolDetails,\n\ttype WriteToolInput,\n\ttype WriteToolOptions,\n} from \"./write.ts\";\n\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport type { DelegationRuntimeOptions } from \"../delegation/runtime.ts\";\nimport { createAskUserTool, createAskUserToolDefinition } from \"./ask-user.ts\";\nimport { type BashToolOptions, createBashTool, createBashToolDefinition } from \"./bash.ts\";\nimport type { ApexToolDefinition } from \"./contract.ts\";\nimport { createDelegateTool, createDelegateToolDefinition } from \"./delegate.ts\";\nimport { createEditTool, createEditToolDefinition, type EditToolOptions } from \"./edit.ts\";\nimport { createFindTool, createFindToolDefinition, type FindToolOptions } from \"./find.ts\";\nimport { createGrepTool, createGrepToolDefinition, type GrepToolOptions } from \"./grep.ts\";\nimport { createLsTool, createLsToolDefinition, type LsToolOptions } from \"./ls.ts\";\nimport { createPlanPresentTool, createPlanPresentToolDefinition } from \"./plan-present.ts\";\nimport { createReadTool, createReadToolDefinition, type ReadToolOptions } from \"./read.ts\";\nimport { createTestTool, createTestToolDefinition, type TestToolOptions } from \"./test.ts\";\nimport { createTodoWriteTool, createTodoWriteToolDefinition, type TodoWriteStore } from \"./todo-write.ts\";\nimport { createToolSchemaTool, createToolSchemaToolDefinition, type ToolSchemaResolver } from \"./tool-schema.ts\";\nimport { createWebFetchTool, createWebFetchToolDefinition, type WebFetchToolOptions } from \"./web-fetch.ts\";\nimport { createWebSearchTool, createWebSearchToolDefinition, type WebSearchToolOptions } from \"./web-search.ts\";\nimport { createWriteTool, createWriteToolDefinition, type WriteToolOptions } from \"./write.ts\";\n\nexport type Tool = AgentTool<any>;\nexport type ToolDef = ApexToolDefinition<any, any>;\nexport type ToolName =\n\t| \"read\"\n\t| \"bash\"\n\t| \"edit\"\n\t| \"write\"\n\t| \"grep\"\n\t| \"find\"\n\t| \"ls\"\n\t| \"tool_schema\"\n\t| \"todo_write\"\n\t| \"web_search\"\n\t| \"web_fetch\"\n\t| \"ask_user\"\n\t| \"plan_present\"\n\t| \"delegate\"\n\t| \"test\";\nexport const allToolNames: Set<ToolName> = new Set([\n\t\"read\",\n\t\"bash\",\n\t\"edit\",\n\t\"write\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n\t\"tool_schema\",\n\t\"todo_write\",\n\t\"web_search\",\n\t\"web_fetch\",\n\t\"ask_user\",\n\t\"plan_present\",\n\t\"delegate\",\n\t\"test\",\n]);\n\nexport interface ToolsOptions {\n\tread?: ReadToolOptions;\n\tbash?: BashToolOptions;\n\twrite?: WriteToolOptions;\n\tedit?: EditToolOptions;\n\tgrep?: GrepToolOptions;\n\tfind?: FindToolOptions;\n\tls?: LsToolOptions;\n\ttool_schema?: { resolver?: ToolSchemaResolver };\n\ttodo_write?: { store?: TodoWriteStore };\n\tweb_search?: WebSearchToolOptions;\n\tweb_fetch?: WebFetchToolOptions;\n\tdelegate?: { runtime?: DelegationRuntimeOptions };\n\ttest?: TestToolOptions;\n}\n\n/** Default store when no session/workspace context supplies one (mirrors emptyToolSchemaResolver below). */\nconst noopTodoWriteStore: TodoWriteStore = { write: () => {} };\n\n/**\n * Default runtime when no session supplies one (mirrors noopTodoWriteStore/\n * emptyToolSchemaResolver above): every agent type is unresolvable, so `delegate`\n * stays inert -- callable, but every call fails loudly with \"unknown agent type\"\n * rather than silently spawning a child with no real authority derivation behind\n * it. Real production wiring (a resolved parent capability set, a derived\n * permission store, and a `buildChildSession` that calls `createAgentSession`) is\n * supplied by `sdk.ts`'s `createAgentSession({ delegation })` option.\n */\nconst noopDelegationRuntime: DelegationRuntimeOptions = {\n\tresolveAgent: () => undefined,\n\tgetParentCapabilities: () => new Set(),\n\tgetToolCapabilities: () => undefined,\n\tgetDelegationDepth: () => 0,\n\tmaxDelegationDepth: 2,\n\tbuildChildSession: async () => {\n\t\tthrow new Error(\"delegate has no runtime configured in this context -- no agent types are resolvable.\");\n\t},\n};\n\nexport function createToolDefinition(toolName: ToolName, cwd: string, options?: ToolsOptions): ToolDef {\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadToolDefinition(cwd, options?.read);\n\t\tcase \"bash\":\n\t\t\treturn createBashToolDefinition(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditToolDefinition(cwd, options?.edit);\n\t\tcase \"write\":\n\t\t\treturn createWriteToolDefinition(cwd, options?.write);\n\t\tcase \"grep\":\n\t\t\treturn createGrepToolDefinition(cwd, options?.grep);\n\t\tcase \"find\":\n\t\t\treturn createFindToolDefinition(cwd, options?.find);\n\t\tcase \"ls\":\n\t\t\treturn createLsToolDefinition(cwd, options?.ls);\n\t\tcase \"tool_schema\":\n\t\t\treturn createToolSchemaToolDefinition(options?.tool_schema?.resolver ?? emptyToolSchemaResolver);\n\t\tcase \"todo_write\":\n\t\t\treturn createTodoWriteToolDefinition(options?.todo_write?.store ?? noopTodoWriteStore);\n\t\tcase \"web_search\":\n\t\t\treturn createWebSearchToolDefinition(options?.web_search);\n\t\tcase \"web_fetch\":\n\t\t\treturn createWebFetchToolDefinition(options?.web_fetch);\n\t\tcase \"ask_user\":\n\t\t\treturn createAskUserToolDefinition();\n\t\tcase \"plan_present\":\n\t\t\treturn createPlanPresentToolDefinition();\n\t\tcase \"delegate\":\n\t\t\treturn createDelegateToolDefinition(options?.delegate?.runtime ?? noopDelegationRuntime);\n\t\tcase \"test\":\n\t\t\treturn createTestToolDefinition(cwd, options?.test);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createTool(toolName: ToolName, cwd: string, options?: ToolsOptions): Tool {\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadTool(cwd, options?.read);\n\t\tcase \"bash\":\n\t\t\treturn createBashTool(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditTool(cwd, options?.edit);\n\t\tcase \"write\":\n\t\t\treturn createWriteTool(cwd, options?.write);\n\t\tcase \"grep\":\n\t\t\treturn createGrepTool(cwd, options?.grep);\n\t\tcase \"find\":\n\t\t\treturn createFindTool(cwd, options?.find);\n\t\tcase \"ls\":\n\t\t\treturn createLsTool(cwd, options?.ls);\n\t\tcase \"tool_schema\":\n\t\t\treturn createToolSchemaTool(options?.tool_schema?.resolver ?? emptyToolSchemaResolver);\n\t\tcase \"todo_write\":\n\t\t\treturn createTodoWriteTool(options?.todo_write?.store ?? noopTodoWriteStore);\n\t\tcase \"web_search\":\n\t\t\treturn createWebSearchTool(options?.web_search);\n\t\tcase \"web_fetch\":\n\t\t\treturn createWebFetchTool(options?.web_fetch);\n\t\tcase \"ask_user\":\n\t\t\treturn createAskUserTool();\n\t\tcase \"plan_present\":\n\t\t\treturn createPlanPresentTool();\n\t\tcase \"delegate\":\n\t\t\treturn createDelegateTool(options?.delegate?.runtime ?? noopDelegationRuntime);\n\t\tcase \"test\":\n\t\t\treturn createTestTool(cwd, options?.test);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createCodingToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateBashToolDefinition(cwd, options?.bash),\n\t\tcreateEditToolDefinition(cwd, options?.edit),\n\t\tcreateWriteToolDefinition(cwd, options?.write),\n\t];\n}\n\nexport function createReadOnlyToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateGrepToolDefinition(cwd, options?.grep),\n\t\tcreateFindToolDefinition(cwd, options?.find),\n\t\tcreateLsToolDefinition(cwd, options?.ls),\n\t];\n}\n\nconst emptyToolSchemaResolver: ToolSchemaResolver = {\n\tgetTool: () => undefined,\n\tmarkLoaded: () => {},\n};\n\nexport function createAllToolDefinitions(cwd: string, options?: ToolsOptions): Record<ToolName, ToolDef> {\n\tconst definitions = {\n\t\tread: createReadToolDefinition(cwd, options?.read),\n\t\tbash: createBashToolDefinition(cwd, options?.bash),\n\t\tedit: createEditToolDefinition(cwd, options?.edit),\n\t\twrite: createWriteToolDefinition(cwd, options?.write),\n\t\tgrep: createGrepToolDefinition(cwd, options?.grep),\n\t\tfind: createFindToolDefinition(cwd, options?.find),\n\t\tls: createLsToolDefinition(cwd, options?.ls),\n\t};\n\tconst resolver = options?.tool_schema?.resolver ?? {\n\t\tgetTool: (name: string) => definitions[name as keyof typeof definitions],\n\t\tmarkLoaded: () => {},\n\t};\n\treturn {\n\t\t...definitions,\n\t\ttool_schema: createToolSchemaToolDefinition(resolver),\n\t\ttodo_write: createTodoWriteToolDefinition(options?.todo_write?.store ?? noopTodoWriteStore),\n\t\tweb_search: createWebSearchToolDefinition(options?.web_search),\n\t\tweb_fetch: createWebFetchToolDefinition(options?.web_fetch),\n\t\task_user: createAskUserToolDefinition(),\n\t\tplan_present: createPlanPresentToolDefinition(),\n\t\tdelegate: createDelegateToolDefinition(options?.delegate?.runtime ?? noopDelegationRuntime),\n\t\ttest: createTestToolDefinition(cwd, options?.test),\n\t};\n}\n\nexport function createCodingTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateBashTool(cwd, options?.bash),\n\t\tcreateEditTool(cwd, options?.edit),\n\t\tcreateWriteTool(cwd, options?.write),\n\t];\n}\n\nexport function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateGrepTool(cwd, options?.grep),\n\t\tcreateFindTool(cwd, options?.find),\n\t\tcreateLsTool(cwd, options?.ls),\n\t];\n}\n\nexport function createAllTools(cwd: string, options?: ToolsOptions): Record<ToolName, Tool> {\n\tconst definitions = createAllToolDefinitions(cwd, options);\n\tconst resolver = options?.tool_schema?.resolver ?? {\n\t\tgetTool: (name: string) => definitions[name as ToolName],\n\t\tmarkLoaded: () => {},\n\t};\n\treturn {\n\t\tread: createReadTool(cwd, options?.read),\n\t\tbash: createBashTool(cwd, options?.bash),\n\t\tedit: createEditTool(cwd, options?.edit),\n\t\twrite: createWriteTool(cwd, options?.write),\n\t\tgrep: createGrepTool(cwd, options?.grep),\n\t\tfind: createFindTool(cwd, options?.find),\n\t\tls: createLsTool(cwd, options?.ls),\n\t\ttool_schema: createToolSchemaTool(resolver),\n\t\ttodo_write: createTodoWriteTool(options?.todo_write?.store ?? noopTodoWriteStore),\n\t\tweb_search: createWebSearchTool(options?.web_search),\n\t\tweb_fetch: createWebFetchTool(options?.web_fetch),\n\t\task_user: createAskUserTool(),\n\t\tplan_present: createPlanPresentTool(),\n\t\tdelegate: createDelegateTool(options?.delegate?.runtime ?? noopDelegationRuntime),\n\t\ttest: createTestTool(cwd, options?.test),\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0C,iBAAiB,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AACvH,OAAO,EAON,cAAc,EACd,wBAAwB,EACxB,yBAAyB,GACzB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,kBAAkB,EAClB,4BAA4B,GAG5B,MAAM,eAAe,CAAC;AAWvB,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAC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AAC,CAAC;KACpB,CAAC;IACF,OAAO;QACN,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,KAAK,EAAE,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC;QAC3C,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,EAAE,EAAE,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC;QAClC,WAAW,EAAE,oBAAoB,CAAC,QAAQ,CAAC;QAC3C,UAAU,EAAE,mBAAmB,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,kBAAkB,CAAC;QACjF,UAAU,EAAE,mBAAmB,CAAC,OAAO,EAAE,UAAU,CAAC;QACpD,SAAS,EAAE,kBAAkB,CAAC,OAAO,EAAE,SAAS,CAAC;QACjD,QAAQ,EAAE,iBAAiB,EAAE;QAC7B,YAAY,EAAE,qBAAqB,EAAE;QACrC,QAAQ,EAAE,kBAAkB,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,IAAI,qBAAqB,CAAC;QACjF,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACjE,CAAC;AAAA,CACF","sourcesContent":["export { type AskUserDetails, type AskUserInput, createAskUserTool, createAskUserToolDefinition } from \"./ask-user.ts\";\nexport {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\tcreateBashTool,\n\tcreateBashToolDefinition,\n\tcreateLocalBashOperations,\n} from \"./bash.ts\";\nexport {\n\tcreateDelegateTool,\n\tcreateDelegateToolDefinition,\n\ttype DelegateDetails,\n\ttype DelegateInput,\n} from \"./delegate.ts\";\nexport type {\n\tDiagnostic,\n\tDiagnosticEvidenceRecord,\n\tDiagnosticPosition,\n\tDiagnosticRange,\n\tDiagnosticSeverityCounts,\n\tDiagnosticsOperations,\n\tDiagnosticsOutcome,\n\tDiagnosticUnavailableKind,\n} from \"./diagnostics.ts\";\nexport {\n\tcreateEditTool,\n\tcreateEditToolDefinition,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n} from \"./edit.ts\";\nexport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nexport {\n\tcreateFindTool,\n\tcreateFindToolDefinition,\n\ttype FindOperations,\n\ttype FindToolDetails,\n\ttype FindToolInput,\n\ttype FindToolOptions,\n} from \"./find.ts\";\nexport {\n\tcreateGrepTool,\n\tcreateGrepToolDefinition,\n\ttype GrepOperations,\n\ttype GrepToolDetails,\n\ttype GrepToolInput,\n\ttype GrepToolOptions,\n} from \"./grep.ts\";\nexport {\n\tcreateLsTool,\n\tcreateLsToolDefinition,\n\ttype LsOperations,\n\ttype LsToolDetails,\n\ttype LsToolInput,\n\ttype LsToolOptions,\n} from \"./ls.ts\";\nexport {\n\tcreateLspTool,\n\tcreateLspToolDefinition,\n\ttype LspLocation,\n\ttype LspOperations,\n\ttype LspSymbol,\n\ttype LspToolDetails,\n\ttype LspToolInput,\n\ttype LspToolOptions,\n} from \"./lsp.ts\";\nexport {\n\tcreatePlanPresentTool,\n\tcreatePlanPresentToolDefinition,\n\ttype PlanPresentDetails,\n\ttype PlanPresentInput,\n} from \"./plan-present.ts\";\nexport {\n\tcreateReadTool,\n\tcreateReadToolDefinition,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n} from \"./read.ts\";\nexport {\n\tcreateTestPermissionSpec,\n\tcreateTestTool,\n\tcreateTestToolDefinition,\n\ttype TestOperationResult,\n\ttype TestOperations,\n\ttype TestRunDetails,\n\ttype TestToolInput,\n\ttype TestToolOptions,\n} from \"./test.ts\";\nexport {\n\tcreateTodoWriteTool,\n\tcreateTodoWriteToolDefinition,\n\ttype TodoItem,\n\ttype TodoWriteDetails,\n\ttype TodoWriteInput,\n\ttype TodoWriteStore,\n} from \"./todo-write.ts\";\nexport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n} from \"./truncate.ts\";\nexport {\n\tcreateWebFetchTool,\n\tcreateWebFetchToolDefinition,\n\ttype WebFetchDetails,\n\ttype WebFetchInput,\n\ttype WebFetchOperations,\n\ttype WebFetchToolOptions,\n} from \"./web-fetch.ts\";\nexport {\n\tcreateWebSearchTool,\n\tcreateWebSearchToolDefinition,\n\ttype WebSearchDetails,\n\ttype WebSearchInput,\n\ttype WebSearchOperations,\n\ttype WebSearchResult,\n\ttype WebSearchToolOptions,\n} from \"./web-search.ts\";\nexport {\n\tcreateWriteTool,\n\tcreateWriteToolDefinition,\n\ttype WriteOperations,\n\ttype WriteToolDetails,\n\ttype WriteToolInput,\n\ttype WriteToolOptions,\n} from \"./write.ts\";\n\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport type { DelegationRuntimeOptions } from \"../delegation/runtime.ts\";\nimport { createAskUserTool, createAskUserToolDefinition } from \"./ask-user.ts\";\nimport { type BashToolOptions, createBashTool, createBashToolDefinition } from \"./bash.ts\";\nimport type { ApexToolDefinition } from \"./contract.ts\";\nimport { createDelegateTool, createDelegateToolDefinition } from \"./delegate.ts\";\nimport { createEditTool, createEditToolDefinition, type EditToolOptions } from \"./edit.ts\";\nimport { createFindTool, createFindToolDefinition, type FindToolOptions } from \"./find.ts\";\nimport { createGrepTool, createGrepToolDefinition, type GrepToolOptions } from \"./grep.ts\";\nimport { createLsTool, createLsToolDefinition, type LsToolOptions } from \"./ls.ts\";\nimport { createLspTool, createLspToolDefinition, type LspToolOptions } from \"./lsp.ts\";\nimport { createPlanPresentTool, createPlanPresentToolDefinition } from \"./plan-present.ts\";\nimport { createReadTool, createReadToolDefinition, type ReadToolOptions } from \"./read.ts\";\nimport { createTestTool, createTestToolDefinition, type TestToolOptions } from \"./test.ts\";\nimport { createTodoWriteTool, createTodoWriteToolDefinition, type TodoWriteStore } from \"./todo-write.ts\";\nimport { createToolSchemaTool, createToolSchemaToolDefinition, type ToolSchemaResolver } from \"./tool-schema.ts\";\nimport { createWebFetchTool, createWebFetchToolDefinition, type WebFetchToolOptions } from \"./web-fetch.ts\";\nimport { createWebSearchTool, createWebSearchToolDefinition, type WebSearchToolOptions } from \"./web-search.ts\";\nimport { createWriteTool, createWriteToolDefinition, type WriteToolOptions } from \"./write.ts\";\n\nexport type Tool = AgentTool<any>;\nexport type ToolDef = ApexToolDefinition<any, any>;\nexport type ToolName =\n\t| \"read\"\n\t| \"bash\"\n\t| \"edit\"\n\t| \"write\"\n\t| \"grep\"\n\t| \"find\"\n\t| \"ls\"\n\t| \"tool_schema\"\n\t| \"todo_write\"\n\t| \"web_search\"\n\t| \"web_fetch\"\n\t| \"ask_user\"\n\t| \"plan_present\"\n\t| \"delegate\"\n\t| \"test\";\nexport const allToolNames: Set<ToolName> = new Set([\n\t\"read\",\n\t\"bash\",\n\t\"edit\",\n\t\"write\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n\t\"tool_schema\",\n\t\"todo_write\",\n\t\"web_search\",\n\t\"web_fetch\",\n\t\"ask_user\",\n\t\"plan_present\",\n\t\"delegate\",\n\t\"test\",\n]);\n\nexport interface ToolsOptions {\n\tread?: ReadToolOptions;\n\tbash?: BashToolOptions;\n\twrite?: WriteToolOptions;\n\tedit?: EditToolOptions;\n\tgrep?: GrepToolOptions;\n\tfind?: FindToolOptions;\n\tls?: LsToolOptions;\n\ttool_schema?: { resolver?: ToolSchemaResolver };\n\ttodo_write?: { store?: TodoWriteStore };\n\tweb_search?: WebSearchToolOptions;\n\tweb_fetch?: WebFetchToolOptions;\n\tdelegate?: { runtime?: DelegationRuntimeOptions };\n\ttest?: TestToolOptions;\n\t/**\n\t * The `lsp` navigation tool (LSP.5). Undefined by default -- the registry-building\n\t * functions below include the `lsp` key only when this is provided, which is what\n\t * keeps an unconfigured session's tool set (and static prompt prefix) unaffected.\n\t */\n\tlsp?: LspToolOptions;\n}\n\n/** Default store when no session/workspace context supplies one (mirrors emptyToolSchemaResolver below). */\nconst noopTodoWriteStore: TodoWriteStore = { write: () => {} };\n\n/**\n * Default runtime when no session supplies one (mirrors noopTodoWriteStore/\n * emptyToolSchemaResolver above): every agent type is unresolvable, so `delegate`\n * stays inert -- callable, but every call fails loudly with \"unknown agent type\"\n * rather than silently spawning a child with no real authority derivation behind\n * it. Real production wiring (a resolved parent capability set, a derived\n * permission store, and a `buildChildSession` that calls `createAgentSession`) is\n * supplied by `sdk.ts`'s `createAgentSession({ delegation })` option.\n */\nconst noopDelegationRuntime: DelegationRuntimeOptions = {\n\tresolveAgent: () => undefined,\n\tgetParentCapabilities: () => new Set(),\n\tgetToolCapabilities: () => undefined,\n\tgetDelegationDepth: () => 0,\n\tmaxDelegationDepth: 2,\n\tbuildChildSession: async () => {\n\t\tthrow new Error(\"delegate has no runtime configured in this context -- no agent types are resolvable.\");\n\t},\n};\n\nexport function createToolDefinition(toolName: ToolName, cwd: string, options?: ToolsOptions): ToolDef {\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadToolDefinition(cwd, options?.read);\n\t\tcase \"bash\":\n\t\t\treturn createBashToolDefinition(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditToolDefinition(cwd, options?.edit);\n\t\tcase \"write\":\n\t\t\treturn createWriteToolDefinition(cwd, options?.write);\n\t\tcase \"grep\":\n\t\t\treturn createGrepToolDefinition(cwd, options?.grep);\n\t\tcase \"find\":\n\t\t\treturn createFindToolDefinition(cwd, options?.find);\n\t\tcase \"ls\":\n\t\t\treturn createLsToolDefinition(cwd, options?.ls);\n\t\tcase \"tool_schema\":\n\t\t\treturn createToolSchemaToolDefinition(options?.tool_schema?.resolver ?? emptyToolSchemaResolver);\n\t\tcase \"todo_write\":\n\t\t\treturn createTodoWriteToolDefinition(options?.todo_write?.store ?? noopTodoWriteStore);\n\t\tcase \"web_search\":\n\t\t\treturn createWebSearchToolDefinition(options?.web_search);\n\t\tcase \"web_fetch\":\n\t\t\treturn createWebFetchToolDefinition(options?.web_fetch);\n\t\tcase \"ask_user\":\n\t\t\treturn createAskUserToolDefinition();\n\t\tcase \"plan_present\":\n\t\t\treturn createPlanPresentToolDefinition();\n\t\tcase \"delegate\":\n\t\t\treturn createDelegateToolDefinition(options?.delegate?.runtime ?? noopDelegationRuntime);\n\t\tcase \"test\":\n\t\t\treturn createTestToolDefinition(cwd, options?.test);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createTool(toolName: ToolName, cwd: string, options?: ToolsOptions): Tool {\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadTool(cwd, options?.read);\n\t\tcase \"bash\":\n\t\t\treturn createBashTool(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditTool(cwd, options?.edit);\n\t\tcase \"write\":\n\t\t\treturn createWriteTool(cwd, options?.write);\n\t\tcase \"grep\":\n\t\t\treturn createGrepTool(cwd, options?.grep);\n\t\tcase \"find\":\n\t\t\treturn createFindTool(cwd, options?.find);\n\t\tcase \"ls\":\n\t\t\treturn createLsTool(cwd, options?.ls);\n\t\tcase \"tool_schema\":\n\t\t\treturn createToolSchemaTool(options?.tool_schema?.resolver ?? emptyToolSchemaResolver);\n\t\tcase \"todo_write\":\n\t\t\treturn createTodoWriteTool(options?.todo_write?.store ?? noopTodoWriteStore);\n\t\tcase \"web_search\":\n\t\t\treturn createWebSearchTool(options?.web_search);\n\t\tcase \"web_fetch\":\n\t\t\treturn createWebFetchTool(options?.web_fetch);\n\t\tcase \"ask_user\":\n\t\t\treturn createAskUserTool();\n\t\tcase \"plan_present\":\n\t\t\treturn createPlanPresentTool();\n\t\tcase \"delegate\":\n\t\t\treturn createDelegateTool(options?.delegate?.runtime ?? noopDelegationRuntime);\n\t\tcase \"test\":\n\t\t\treturn createTestTool(cwd, options?.test);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createCodingToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateBashToolDefinition(cwd, options?.bash),\n\t\tcreateEditToolDefinition(cwd, options?.edit),\n\t\tcreateWriteToolDefinition(cwd, options?.write),\n\t];\n}\n\nexport function createReadOnlyToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateGrepToolDefinition(cwd, options?.grep),\n\t\tcreateFindToolDefinition(cwd, options?.find),\n\t\tcreateLsToolDefinition(cwd, options?.ls),\n\t];\n}\n\nconst emptyToolSchemaResolver: ToolSchemaResolver = {\n\tgetTool: () => undefined,\n\tmarkLoaded: () => {},\n};\n\nexport function createAllToolDefinitions(\n\tcwd: string,\n\toptions?: ToolsOptions,\n): Record<ToolName, ToolDef> & { lsp?: ToolDef } {\n\tconst definitions = {\n\t\tread: createReadToolDefinition(cwd, options?.read),\n\t\tbash: createBashToolDefinition(cwd, options?.bash),\n\t\tedit: createEditToolDefinition(cwd, options?.edit),\n\t\twrite: createWriteToolDefinition(cwd, options?.write),\n\t\tgrep: createGrepToolDefinition(cwd, options?.grep),\n\t\tfind: createFindToolDefinition(cwd, options?.find),\n\t\tls: createLsToolDefinition(cwd, options?.ls),\n\t};\n\tconst resolver = options?.tool_schema?.resolver ?? {\n\t\tgetTool: (name: string) => definitions[name as keyof typeof definitions],\n\t\tmarkLoaded: () => {},\n\t};\n\treturn {\n\t\t...definitions,\n\t\ttool_schema: createToolSchemaToolDefinition(resolver),\n\t\ttodo_write: createTodoWriteToolDefinition(options?.todo_write?.store ?? noopTodoWriteStore),\n\t\tweb_search: createWebSearchToolDefinition(options?.web_search),\n\t\tweb_fetch: createWebFetchToolDefinition(options?.web_fetch),\n\t\task_user: createAskUserToolDefinition(),\n\t\tplan_present: createPlanPresentToolDefinition(),\n\t\tdelegate: createDelegateToolDefinition(options?.delegate?.runtime ?? noopDelegationRuntime),\n\t\ttest: createTestToolDefinition(cwd, options?.test),\n\t\t// Registered only when configured (LSP.5): an unconfigured session's registry,\n\t\t// and therefore its static prompt prefix, is unaffected by this subsystem.\n\t\t...(options?.lsp ? { lsp: createLspToolDefinition(cwd, options.lsp) } : {}),\n\t};\n}\n\nexport function createCodingTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateBashTool(cwd, options?.bash),\n\t\tcreateEditTool(cwd, options?.edit),\n\t\tcreateWriteTool(cwd, options?.write),\n\t];\n}\n\nexport function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateGrepTool(cwd, options?.grep),\n\t\tcreateFindTool(cwd, options?.find),\n\t\tcreateLsTool(cwd, options?.ls),\n\t];\n}\n\nexport function createAllTools(cwd: string, options?: ToolsOptions): Record<ToolName, Tool> & { lsp?: Tool } {\n\tconst definitions = createAllToolDefinitions(cwd, options);\n\tconst resolver = options?.tool_schema?.resolver ?? {\n\t\tgetTool: (name: string) => definitions[name as ToolName],\n\t\tmarkLoaded: () => {},\n\t};\n\treturn {\n\t\tread: createReadTool(cwd, options?.read),\n\t\tbash: createBashTool(cwd, options?.bash),\n\t\tedit: createEditTool(cwd, options?.edit),\n\t\twrite: createWriteTool(cwd, options?.write),\n\t\tgrep: createGrepTool(cwd, options?.grep),\n\t\tfind: createFindTool(cwd, options?.find),\n\t\tls: createLsTool(cwd, options?.ls),\n\t\ttool_schema: createToolSchemaTool(resolver),\n\t\ttodo_write: createTodoWriteTool(options?.todo_write?.store ?? noopTodoWriteStore),\n\t\tweb_search: createWebSearchTool(options?.web_search),\n\t\tweb_fetch: createWebFetchTool(options?.web_fetch),\n\t\task_user: createAskUserTool(),\n\t\tplan_present: createPlanPresentTool(),\n\t\tdelegate: createDelegateTool(options?.delegate?.runtime ?? noopDelegationRuntime),\n\t\ttest: createTestTool(cwd, options?.test),\n\t\t...(options?.lsp ? { lsp: createLspTool(cwd, options.lsp) } : {}),\n\t};\n}\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { AgentTool } from "apex-code-agent-core";
|
|
2
|
+
import { type Static, Type } from "typebox";
|
|
3
|
+
import type { ApexToolDefinition } from "./contract.ts";
|
|
4
|
+
declare const lspSchema: Type.TUnion<[Type.TObject<{
|
|
5
|
+
operation: Type.TUnion<[Type.TLiteral<"definition">, Type.TLiteral<"references">]>;
|
|
6
|
+
path: Type.TString;
|
|
7
|
+
line: Type.TNumber;
|
|
8
|
+
character: Type.TNumber;
|
|
9
|
+
}>, Type.TObject<{
|
|
10
|
+
operation: Type.TLiteral<"document_symbols">;
|
|
11
|
+
path: Type.TString;
|
|
12
|
+
}>]>;
|
|
13
|
+
export type LspToolInput = Static<typeof lspSchema>;
|
|
14
|
+
export interface LspPosition {
|
|
15
|
+
readonly line: number;
|
|
16
|
+
readonly character: number;
|
|
17
|
+
}
|
|
18
|
+
export interface LspRange {
|
|
19
|
+
readonly start: LspPosition;
|
|
20
|
+
readonly end: LspPosition;
|
|
21
|
+
}
|
|
22
|
+
/** A navigation result normalized to a workspace-relative path and one-based range. */
|
|
23
|
+
export interface LspLocation {
|
|
24
|
+
readonly path: string;
|
|
25
|
+
readonly range: LspRange;
|
|
26
|
+
}
|
|
27
|
+
/** A flattened document symbol normalized to a workspace-relative path and one-based ranges. */
|
|
28
|
+
export interface LspSymbol {
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly kind: number;
|
|
31
|
+
readonly path: string;
|
|
32
|
+
readonly range: LspRange;
|
|
33
|
+
readonly selectionRange: LspRange;
|
|
34
|
+
readonly detail?: string;
|
|
35
|
+
}
|
|
36
|
+
export type LspToolDetails = {
|
|
37
|
+
operation: "definition" | "references";
|
|
38
|
+
locations: LspLocation[];
|
|
39
|
+
omitted: number;
|
|
40
|
+
truncated: number;
|
|
41
|
+
} | {
|
|
42
|
+
operation: "document_symbols";
|
|
43
|
+
symbols: LspSymbol[];
|
|
44
|
+
omitted: number;
|
|
45
|
+
truncated: number;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Pluggable transport for the `lsp` tool. The executable, its arguments, and the
|
|
49
|
+
* closed JSON-RPC method set are all fixed by configuration the tool never chooses
|
|
50
|
+
* itself -- see contract.capabilities below for why that keeps this `{fs.read}`
|
|
51
|
+
* rather than `{exec}`.
|
|
52
|
+
*/
|
|
53
|
+
export interface LspOperations {
|
|
54
|
+
request(absolutePath: string, method: string, params: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
55
|
+
}
|
|
56
|
+
export interface LspToolOptions {
|
|
57
|
+
operations: LspOperations;
|
|
58
|
+
}
|
|
59
|
+
export declare function createLspToolDefinition(cwd: string, options: LspToolOptions): ApexToolDefinition<typeof lspSchema, LspToolDetails>;
|
|
60
|
+
export declare function createLspTool(cwd: string, options: LspToolOptions): AgentTool<typeof lspSchema>;
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=lsp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lsp.d.ts","sourceRoot":"","sources":["../../../src/core/tools/lsp.ts"],"names":[],"mappings":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,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/F;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC7B,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACvG;AAED,MAAM,WAAW,cAAc;IAC9B,UAAU,EAAE,aAAa,CAAC;CAC1B;AAwJD,wBAAgB,uBAAuB,CACtC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,cAAc,GACrB,kBAAkB,CAAC,OAAO,SAAS,EAAE,cAAc,CAAC,CAwDtD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,SAAS,CAAC,OAAO,SAAS,CAAC,CAE/F","sourcesContent":["import { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport type { ApexToolDefinition } from \"./contract.ts\";\nimport { createPathPermissionSpec } from \"./path-permission.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst MAX_LOCATIONS = 1_000;\nconst MAX_SYMBOLS = 2_000;\n\nconst lspNavigationSchema = Type.Object({\n\toperation: Type.Union([Type.Literal(\"definition\"), Type.Literal(\"references\")], {\n\t\tdescription: \"Which navigation query to run.\",\n\t}),\n\tpath: Type.String({ description: \"Path to the file (relative or absolute).\" }),\n\tline: Type.Number({ description: \"One-based line number.\" }),\n\tcharacter: Type.Number({ description: \"One-based UTF-16 character offset within the line.\" }),\n});\n\nconst lspDocumentSymbolsSchema = Type.Object({\n\toperation: Type.Literal(\"document_symbols\", { description: \"List the symbols declared in a file.\" }),\n\tpath: Type.String({ description: \"Path to the file (relative or absolute).\" }),\n});\n\nconst lspSchema = Type.Union([lspNavigationSchema, lspDocumentSymbolsSchema]);\n\nexport type LspToolInput = Static<typeof lspSchema>;\n\nexport interface LspPosition {\n\treadonly line: number;\n\treadonly character: number;\n}\n\nexport interface LspRange {\n\treadonly start: LspPosition;\n\treadonly end: LspPosition;\n}\n\n/** A navigation result normalized to a workspace-relative path and one-based range. */\nexport interface LspLocation {\n\treadonly path: string;\n\treadonly range: LspRange;\n}\n\n/** A flattened document symbol normalized to a workspace-relative path and one-based ranges. */\nexport interface LspSymbol {\n\treadonly name: string;\n\treadonly kind: number;\n\treadonly path: string;\n\treadonly range: LspRange;\n\treadonly selectionRange: LspRange;\n\treadonly detail?: string;\n}\n\nexport type LspToolDetails =\n\t| { operation: \"definition\" | \"references\"; locations: LspLocation[]; omitted: number; truncated: number }\n\t| { operation: \"document_symbols\"; symbols: LspSymbol[]; omitted: number; truncated: number };\n\n/**\n * Pluggable transport for the `lsp` tool. The executable, its arguments, and the\n * closed JSON-RPC method set are all fixed by configuration the tool never chooses\n * itself -- see contract.capabilities below for why that keeps this `{fs.read}`\n * rather than `{exec}`.\n */\nexport interface LspOperations {\n\trequest(absolutePath: string, method: string, params: unknown, signal?: AbortSignal): Promise<unknown>;\n}\n\nexport interface LspToolOptions {\n\toperations: LspOperations;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isPosition(value: unknown): value is LspPosition {\n\treturn isRecord(value) && typeof value.line === \"number\" && typeof value.character === \"number\";\n}\n\nfunction isRange(value: unknown): value is LspRange {\n\treturn isRecord(value) && isPosition(value.start) && isPosition(value.end);\n}\n\nfunction toOneBasedPosition(position: LspPosition): LspPosition {\n\treturn { line: position.line + 1, character: position.character + 1 };\n}\n\nfunction toOneBasedRange(range: LspRange): LspRange {\n\treturn { start: toOneBasedPosition(range.start), end: toOneBasedPosition(range.end) };\n}\n\nfunction fileUriToAbsolutePath(uri: string): string | undefined {\n\tif (!uri.startsWith(\"file:\")) return undefined;\n\ttry {\n\t\treturn fileURLToPath(uri);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction rawLocationUriAndRange(value: unknown): { uri: string; range: LspRange } | undefined {\n\tif (!isRecord(value)) return undefined;\n\tif (typeof value.uri === \"string\" && isRange(value.range)) return { uri: value.uri, range: value.range };\n\tif (typeof value.targetUri === \"string\" && isRange(value.targetRange)) {\n\t\treturn { uri: value.targetUri, range: value.targetRange };\n\t}\n\treturn undefined;\n}\n\nfunction normalizeLocations(raw: unknown, cwd: string): { locations: LspLocation[]; omitted: number } {\n\tconst items = Array.isArray(raw) ? raw : raw === undefined || raw === null ? [] : [raw];\n\tconst locations: LspLocation[] = [];\n\tlet omitted = 0;\n\tfor (const item of items) {\n\t\tconst parsed = rawLocationUriAndRange(item);\n\t\tconst absolutePath = parsed ? fileUriToAbsolutePath(parsed.uri) : undefined;\n\t\tif (!parsed || !absolutePath) {\n\t\t\tomitted++;\n\t\t\tcontinue;\n\t\t}\n\t\tlocations.push({\n\t\t\tpath: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd),\n\t\t\trange: toOneBasedRange(parsed.range),\n\t\t});\n\t}\n\treturn { locations, omitted };\n}\n\nfunction compareLocations(a: LspLocation, b: LspLocation): number {\n\tif (a.path !== b.path) return a.path < b.path ? -1 : 1;\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\tif (a.range.end.line !== b.range.end.line) return a.range.end.line - b.range.end.line;\n\treturn a.range.end.character - b.range.end.character;\n}\n\nfunction dedupeSortAndCap(locations: LspLocation[], max: number): { locations: LspLocation[]; truncated: number } {\n\tconst seen = new Set<string>();\n\tconst unique: LspLocation[] = [];\n\tfor (const location of locations) {\n\t\tconst key = JSON.stringify(location);\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tunique.push(location);\n\t}\n\tunique.sort(compareLocations);\n\tconst capped = unique.slice(0, max);\n\treturn { locations: capped, truncated: unique.length - capped.length };\n}\n\nfunction isRawDocumentSymbol(value: unknown): value is Record<string, unknown> {\n\treturn isRecord(value) && typeof value.name === \"string\" && isRange(value.range) && isRange(value.selectionRange);\n}\n\nfunction flattenSymbols(raw: unknown, path: string): { symbols: LspSymbol[]; omitted: number } {\n\tconst symbols: LspSymbol[] = [];\n\tlet omitted = 0;\n\tconst visit = (value: unknown): void => {\n\t\tif (!Array.isArray(value)) return;\n\t\tfor (const item of value) {\n\t\t\tif (!isRawDocumentSymbol(item)) {\n\t\t\t\tomitted++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tsymbols.push({\n\t\t\t\tname: item.name as string,\n\t\t\t\tkind: typeof item.kind === \"number\" ? item.kind : 0,\n\t\t\t\tpath,\n\t\t\t\trange: toOneBasedRange(item.range as LspRange),\n\t\t\t\tselectionRange: toOneBasedRange(item.selectionRange as LspRange),\n\t\t\t\t...(typeof item.detail === \"string\" ? { detail: item.detail } : {}),\n\t\t\t});\n\t\t\tif (Array.isArray(item.children)) visit(item.children);\n\t\t}\n\t};\n\tvisit(Array.isArray(raw) ? raw : []);\n\treturn { symbols, omitted };\n}\n\nfunction compareSymbols(a: LspSymbol, b: LspSymbol): number {\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\treturn a.name === b.name ? 0 : a.name < b.name ? -1 : 1;\n}\n\nfunction capSymbols(symbols: LspSymbol[], max: number): { symbols: LspSymbol[]; truncated: number } {\n\tconst sorted = [...symbols].sort(compareSymbols);\n\tconst capped = sorted.slice(0, max);\n\treturn { symbols: capped, truncated: sorted.length - capped.length };\n}\n\nfunction formatNotices(omitted: number, truncated: number): string {\n\tconst notices: string[] = [];\n\tif (omitted > 0) notices.push(`${omitted} non-file result(s) omitted`);\n\tif (truncated > 0) notices.push(`${truncated} result(s) truncated`);\n\treturn notices.length > 0 ? `\\n\\n[${notices.join(\", \")}]` : \"\";\n}\n\nfunction formatLocationsText(\n\toperation: \"definition\" | \"references\",\n\tlocations: LspLocation[],\n\tomitted: number,\n\ttruncated: number,\n): string {\n\tif (locations.length === 0) {\n\t\treturn operation === \"definition\" ? \"No definition found.\" : \"No references found.\";\n\t}\n\tconst lines = locations.map(\n\t\t(location) => `${location.path}:${location.range.start.line}:${location.range.start.character}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nfunction formatSymbolsText(symbols: LspSymbol[], omitted: number, truncated: number): string {\n\tif (symbols.length === 0) return \"No symbols found.\";\n\tconst lines = symbols.map(\n\t\t(symbol) => `${symbol.path}:${symbol.range.start.line}:${symbol.range.start.character} ${symbol.name}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nexport function createLspToolDefinition(\n\tcwd: string,\n\toptions: LspToolOptions,\n): ApexToolDefinition<typeof lspSchema, LspToolDetails> {\n\tconst { operations } = options;\n\treturn {\n\t\tname: \"lsp\",\n\t\tlabel: \"lsp\",\n\t\tdescription: \"Query the configured language server for definitions, references, or symbols.\",\n\t\tparameters: lspSchema,\n\t\tcontract: {\n\t\t\t// `grep` spawns `rg` and declares {fs.read}, not {exec}, because the caller\n\t\t\t// never chooses what runs -- the executable, args, and closed JSON-RPC\n\t\t\t// method set all come from settings.json / this tool's own code. Same\n\t\t\t// reasoning here: {exec} would silently widen a delegation ceiling for no\n\t\t\t// capability the model can actually reach through this tool.\n\t\t\tcapabilities: new Set([\"fs.read\"]),\n\t\t\tpermission: createPathPermissionSpec({\n\t\t\t\tcwd,\n\t\t\t\tdefaultBehavior: \"allow\",\n\t\t\t\tverb: \"Query\",\n\t\t\t\tgetPath: (params) => params.path,\n\t\t\t}),\n\t\t\tcontext: { resultRecoverable: true, deferSchema: true },\n\t\t\tevidence: { emits: new Set(), capture: () => [] },\n\t\t},\n\t\tasync execute(_toolCallId, input: LspToolInput, signal?: AbortSignal) {\n\t\t\tconst absolutePath = resolveToCwd(input.path, cwd);\n\t\t\tconst uri = pathToFileURL(absolutePath).href;\n\n\t\t\tif (input.operation === \"document_symbols\") {\n\t\t\t\tconst raw = await operations.request(\n\t\t\t\t\tabsolutePath,\n\t\t\t\t\t\"textDocument/documentSymbol\",\n\t\t\t\t\t{ textDocument: { uri } },\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\t\t\t\tconst relativePath = formatPathRelativeToCwdOrAbsolute(absolutePath, cwd);\n\t\t\t\tconst { symbols, omitted } = flattenSymbols(raw, relativePath);\n\t\t\t\tconst { symbols: capped, truncated } = capSymbols(symbols, MAX_SYMBOLS);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: formatSymbolsText(capped, omitted, truncated) }],\n\t\t\t\t\tdetails: { operation: \"document_symbols\", symbols: capped, omitted, truncated },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst position = { line: input.line - 1, character: input.character - 1 };\n\t\t\tconst method = input.operation === \"definition\" ? \"textDocument/definition\" : \"textDocument/references\";\n\t\t\tconst params: Record<string, unknown> = { textDocument: { uri }, position };\n\t\t\tif (input.operation === \"references\") params.context = { includeDeclaration: true };\n\t\t\tconst raw = await operations.request(absolutePath, method, params, signal);\n\t\t\tconst { locations, omitted } = normalizeLocations(raw, cwd);\n\t\t\tconst { locations: capped, truncated } = dedupeSortAndCap(locations, MAX_LOCATIONS);\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: formatLocationsText(input.operation, capped, omitted, truncated) }],\n\t\t\t\tdetails: { operation: input.operation, locations: capped, omitted, truncated },\n\t\t\t};\n\t\t},\n\t};\n}\n\nexport function createLspTool(cwd: string, options: LspToolOptions): AgentTool<typeof lspSchema> {\n\treturn wrapToolDefinition(createLspToolDefinition(cwd, options));\n}\n"]}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import { formatPathRelativeToCwdOrAbsolute } from "../../utils/paths.js";
|
|
4
|
+
import { createPathPermissionSpec } from "./path-permission.js";
|
|
5
|
+
import { resolveToCwd } from "./path-utils.js";
|
|
6
|
+
import { wrapToolDefinition } from "./tool-definition-wrapper.js";
|
|
7
|
+
const MAX_LOCATIONS = 1_000;
|
|
8
|
+
const MAX_SYMBOLS = 2_000;
|
|
9
|
+
const lspNavigationSchema = Type.Object({
|
|
10
|
+
operation: Type.Union([Type.Literal("definition"), Type.Literal("references")], {
|
|
11
|
+
description: "Which navigation query to run.",
|
|
12
|
+
}),
|
|
13
|
+
path: Type.String({ description: "Path to the file (relative or absolute)." }),
|
|
14
|
+
line: Type.Number({ description: "One-based line number." }),
|
|
15
|
+
character: Type.Number({ description: "One-based UTF-16 character offset within the line." }),
|
|
16
|
+
});
|
|
17
|
+
const lspDocumentSymbolsSchema = Type.Object({
|
|
18
|
+
operation: Type.Literal("document_symbols", { description: "List the symbols declared in a file." }),
|
|
19
|
+
path: Type.String({ description: "Path to the file (relative or absolute)." }),
|
|
20
|
+
});
|
|
21
|
+
const lspSchema = Type.Union([lspNavigationSchema, lspDocumentSymbolsSchema]);
|
|
22
|
+
function isRecord(value) {
|
|
23
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
function isPosition(value) {
|
|
26
|
+
return isRecord(value) && typeof value.line === "number" && typeof value.character === "number";
|
|
27
|
+
}
|
|
28
|
+
function isRange(value) {
|
|
29
|
+
return isRecord(value) && isPosition(value.start) && isPosition(value.end);
|
|
30
|
+
}
|
|
31
|
+
function toOneBasedPosition(position) {
|
|
32
|
+
return { line: position.line + 1, character: position.character + 1 };
|
|
33
|
+
}
|
|
34
|
+
function toOneBasedRange(range) {
|
|
35
|
+
return { start: toOneBasedPosition(range.start), end: toOneBasedPosition(range.end) };
|
|
36
|
+
}
|
|
37
|
+
function fileUriToAbsolutePath(uri) {
|
|
38
|
+
if (!uri.startsWith("file:"))
|
|
39
|
+
return undefined;
|
|
40
|
+
try {
|
|
41
|
+
return fileURLToPath(uri);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function rawLocationUriAndRange(value) {
|
|
48
|
+
if (!isRecord(value))
|
|
49
|
+
return undefined;
|
|
50
|
+
if (typeof value.uri === "string" && isRange(value.range))
|
|
51
|
+
return { uri: value.uri, range: value.range };
|
|
52
|
+
if (typeof value.targetUri === "string" && isRange(value.targetRange)) {
|
|
53
|
+
return { uri: value.targetUri, range: value.targetRange };
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
function normalizeLocations(raw, cwd) {
|
|
58
|
+
const items = Array.isArray(raw) ? raw : raw === undefined || raw === null ? [] : [raw];
|
|
59
|
+
const locations = [];
|
|
60
|
+
let omitted = 0;
|
|
61
|
+
for (const item of items) {
|
|
62
|
+
const parsed = rawLocationUriAndRange(item);
|
|
63
|
+
const absolutePath = parsed ? fileUriToAbsolutePath(parsed.uri) : undefined;
|
|
64
|
+
if (!parsed || !absolutePath) {
|
|
65
|
+
omitted++;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
locations.push({
|
|
69
|
+
path: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd),
|
|
70
|
+
range: toOneBasedRange(parsed.range),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return { locations, omitted };
|
|
74
|
+
}
|
|
75
|
+
function compareLocations(a, b) {
|
|
76
|
+
if (a.path !== b.path)
|
|
77
|
+
return a.path < b.path ? -1 : 1;
|
|
78
|
+
if (a.range.start.line !== b.range.start.line)
|
|
79
|
+
return a.range.start.line - b.range.start.line;
|
|
80
|
+
if (a.range.start.character !== b.range.start.character)
|
|
81
|
+
return a.range.start.character - b.range.start.character;
|
|
82
|
+
if (a.range.end.line !== b.range.end.line)
|
|
83
|
+
return a.range.end.line - b.range.end.line;
|
|
84
|
+
return a.range.end.character - b.range.end.character;
|
|
85
|
+
}
|
|
86
|
+
function dedupeSortAndCap(locations, max) {
|
|
87
|
+
const seen = new Set();
|
|
88
|
+
const unique = [];
|
|
89
|
+
for (const location of locations) {
|
|
90
|
+
const key = JSON.stringify(location);
|
|
91
|
+
if (seen.has(key))
|
|
92
|
+
continue;
|
|
93
|
+
seen.add(key);
|
|
94
|
+
unique.push(location);
|
|
95
|
+
}
|
|
96
|
+
unique.sort(compareLocations);
|
|
97
|
+
const capped = unique.slice(0, max);
|
|
98
|
+
return { locations: capped, truncated: unique.length - capped.length };
|
|
99
|
+
}
|
|
100
|
+
function isRawDocumentSymbol(value) {
|
|
101
|
+
return isRecord(value) && typeof value.name === "string" && isRange(value.range) && isRange(value.selectionRange);
|
|
102
|
+
}
|
|
103
|
+
function flattenSymbols(raw, path) {
|
|
104
|
+
const symbols = [];
|
|
105
|
+
let omitted = 0;
|
|
106
|
+
const visit = (value) => {
|
|
107
|
+
if (!Array.isArray(value))
|
|
108
|
+
return;
|
|
109
|
+
for (const item of value) {
|
|
110
|
+
if (!isRawDocumentSymbol(item)) {
|
|
111
|
+
omitted++;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
symbols.push({
|
|
115
|
+
name: item.name,
|
|
116
|
+
kind: typeof item.kind === "number" ? item.kind : 0,
|
|
117
|
+
path,
|
|
118
|
+
range: toOneBasedRange(item.range),
|
|
119
|
+
selectionRange: toOneBasedRange(item.selectionRange),
|
|
120
|
+
...(typeof item.detail === "string" ? { detail: item.detail } : {}),
|
|
121
|
+
});
|
|
122
|
+
if (Array.isArray(item.children))
|
|
123
|
+
visit(item.children);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
visit(Array.isArray(raw) ? raw : []);
|
|
127
|
+
return { symbols, omitted };
|
|
128
|
+
}
|
|
129
|
+
function compareSymbols(a, b) {
|
|
130
|
+
if (a.range.start.line !== b.range.start.line)
|
|
131
|
+
return a.range.start.line - b.range.start.line;
|
|
132
|
+
if (a.range.start.character !== b.range.start.character)
|
|
133
|
+
return a.range.start.character - b.range.start.character;
|
|
134
|
+
return a.name === b.name ? 0 : a.name < b.name ? -1 : 1;
|
|
135
|
+
}
|
|
136
|
+
function capSymbols(symbols, max) {
|
|
137
|
+
const sorted = [...symbols].sort(compareSymbols);
|
|
138
|
+
const capped = sorted.slice(0, max);
|
|
139
|
+
return { symbols: capped, truncated: sorted.length - capped.length };
|
|
140
|
+
}
|
|
141
|
+
function formatNotices(omitted, truncated) {
|
|
142
|
+
const notices = [];
|
|
143
|
+
if (omitted > 0)
|
|
144
|
+
notices.push(`${omitted} non-file result(s) omitted`);
|
|
145
|
+
if (truncated > 0)
|
|
146
|
+
notices.push(`${truncated} result(s) truncated`);
|
|
147
|
+
return notices.length > 0 ? `\n\n[${notices.join(", ")}]` : "";
|
|
148
|
+
}
|
|
149
|
+
function formatLocationsText(operation, locations, omitted, truncated) {
|
|
150
|
+
if (locations.length === 0) {
|
|
151
|
+
return operation === "definition" ? "No definition found." : "No references found.";
|
|
152
|
+
}
|
|
153
|
+
const lines = locations.map((location) => `${location.path}:${location.range.start.line}:${location.range.start.character}`);
|
|
154
|
+
return `${lines.join("\n")}${formatNotices(omitted, truncated)}`;
|
|
155
|
+
}
|
|
156
|
+
function formatSymbolsText(symbols, omitted, truncated) {
|
|
157
|
+
if (symbols.length === 0)
|
|
158
|
+
return "No symbols found.";
|
|
159
|
+
const lines = symbols.map((symbol) => `${symbol.path}:${symbol.range.start.line}:${symbol.range.start.character} ${symbol.name}`);
|
|
160
|
+
return `${lines.join("\n")}${formatNotices(omitted, truncated)}`;
|
|
161
|
+
}
|
|
162
|
+
export function createLspToolDefinition(cwd, options) {
|
|
163
|
+
const { operations } = options;
|
|
164
|
+
return {
|
|
165
|
+
name: "lsp",
|
|
166
|
+
label: "lsp",
|
|
167
|
+
description: "Query the configured language server for definitions, references, or symbols.",
|
|
168
|
+
parameters: lspSchema,
|
|
169
|
+
contract: {
|
|
170
|
+
// `grep` spawns `rg` and declares {fs.read}, not {exec}, because the caller
|
|
171
|
+
// never chooses what runs -- the executable, args, and closed JSON-RPC
|
|
172
|
+
// method set all come from settings.json / this tool's own code. Same
|
|
173
|
+
// reasoning here: {exec} would silently widen a delegation ceiling for no
|
|
174
|
+
// capability the model can actually reach through this tool.
|
|
175
|
+
capabilities: new Set(["fs.read"]),
|
|
176
|
+
permission: createPathPermissionSpec({
|
|
177
|
+
cwd,
|
|
178
|
+
defaultBehavior: "allow",
|
|
179
|
+
verb: "Query",
|
|
180
|
+
getPath: (params) => params.path,
|
|
181
|
+
}),
|
|
182
|
+
context: { resultRecoverable: true, deferSchema: true },
|
|
183
|
+
evidence: { emits: new Set(), capture: () => [] },
|
|
184
|
+
},
|
|
185
|
+
async execute(_toolCallId, input, signal) {
|
|
186
|
+
const absolutePath = resolveToCwd(input.path, cwd);
|
|
187
|
+
const uri = pathToFileURL(absolutePath).href;
|
|
188
|
+
if (input.operation === "document_symbols") {
|
|
189
|
+
const raw = await operations.request(absolutePath, "textDocument/documentSymbol", { textDocument: { uri } }, signal);
|
|
190
|
+
const relativePath = formatPathRelativeToCwdOrAbsolute(absolutePath, cwd);
|
|
191
|
+
const { symbols, omitted } = flattenSymbols(raw, relativePath);
|
|
192
|
+
const { symbols: capped, truncated } = capSymbols(symbols, MAX_SYMBOLS);
|
|
193
|
+
return {
|
|
194
|
+
content: [{ type: "text", text: formatSymbolsText(capped, omitted, truncated) }],
|
|
195
|
+
details: { operation: "document_symbols", symbols: capped, omitted, truncated },
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const position = { line: input.line - 1, character: input.character - 1 };
|
|
199
|
+
const method = input.operation === "definition" ? "textDocument/definition" : "textDocument/references";
|
|
200
|
+
const params = { textDocument: { uri }, position };
|
|
201
|
+
if (input.operation === "references")
|
|
202
|
+
params.context = { includeDeclaration: true };
|
|
203
|
+
const raw = await operations.request(absolutePath, method, params, signal);
|
|
204
|
+
const { locations, omitted } = normalizeLocations(raw, cwd);
|
|
205
|
+
const { locations: capped, truncated } = dedupeSortAndCap(locations, MAX_LOCATIONS);
|
|
206
|
+
return {
|
|
207
|
+
content: [{ type: "text", text: formatLocationsText(input.operation, capped, omitted, truncated) }],
|
|
208
|
+
details: { operation: input.operation, locations: capped, omitted, truncated },
|
|
209
|
+
};
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
export function createLspTool(cwd, options) {
|
|
214
|
+
return wrapToolDefinition(createLspToolDefinition(cwd, options));
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=lsp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lsp.js","sourceRoot":"","sources":["../../../src/core/tools/lsp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAExD,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,iCAAiC,EAAE,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,aAAa,GAAG,KAAK,CAAC;AAC5B,MAAM,WAAW,GAAG,KAAK,CAAC;AAE1B,MAAM,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC;IACvC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE;QAC/E,WAAW,EAAE,gCAAgC;KAC7C,CAAC;IACF,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAA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,aAAa,CAAC,CAAC;YACpF,OAAO;gBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC;gBACnG,OAAO,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE;aAC9E,CAAC;QAAA,CACF;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,OAAuB,EAA+B;IAChG,OAAO,kBAAkB,CAAC,uBAAuB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CACjE","sourcesContent":["import { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport type { ApexToolDefinition } from \"./contract.ts\";\nimport { createPathPermissionSpec } from \"./path-permission.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst MAX_LOCATIONS = 1_000;\nconst MAX_SYMBOLS = 2_000;\n\nconst lspNavigationSchema = Type.Object({\n\toperation: Type.Union([Type.Literal(\"definition\"), Type.Literal(\"references\")], {\n\t\tdescription: \"Which navigation query to run.\",\n\t}),\n\tpath: Type.String({ description: \"Path to the file (relative or absolute).\" }),\n\tline: Type.Number({ description: \"One-based line number.\" }),\n\tcharacter: Type.Number({ description: \"One-based UTF-16 character offset within the line.\" }),\n});\n\nconst lspDocumentSymbolsSchema = Type.Object({\n\toperation: Type.Literal(\"document_symbols\", { description: \"List the symbols declared in a file.\" }),\n\tpath: Type.String({ description: \"Path to the file (relative or absolute).\" }),\n});\n\nconst lspSchema = Type.Union([lspNavigationSchema, lspDocumentSymbolsSchema]);\n\nexport type LspToolInput = Static<typeof lspSchema>;\n\nexport interface LspPosition {\n\treadonly line: number;\n\treadonly character: number;\n}\n\nexport interface LspRange {\n\treadonly start: LspPosition;\n\treadonly end: LspPosition;\n}\n\n/** A navigation result normalized to a workspace-relative path and one-based range. */\nexport interface LspLocation {\n\treadonly path: string;\n\treadonly range: LspRange;\n}\n\n/** A flattened document symbol normalized to a workspace-relative path and one-based ranges. */\nexport interface LspSymbol {\n\treadonly name: string;\n\treadonly kind: number;\n\treadonly path: string;\n\treadonly range: LspRange;\n\treadonly selectionRange: LspRange;\n\treadonly detail?: string;\n}\n\nexport type LspToolDetails =\n\t| { operation: \"definition\" | \"references\"; locations: LspLocation[]; omitted: number; truncated: number }\n\t| { operation: \"document_symbols\"; symbols: LspSymbol[]; omitted: number; truncated: number };\n\n/**\n * Pluggable transport for the `lsp` tool. The executable, its arguments, and the\n * closed JSON-RPC method set are all fixed by configuration the tool never chooses\n * itself -- see contract.capabilities below for why that keeps this `{fs.read}`\n * rather than `{exec}`.\n */\nexport interface LspOperations {\n\trequest(absolutePath: string, method: string, params: unknown, signal?: AbortSignal): Promise<unknown>;\n}\n\nexport interface LspToolOptions {\n\toperations: LspOperations;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isPosition(value: unknown): value is LspPosition {\n\treturn isRecord(value) && typeof value.line === \"number\" && typeof value.character === \"number\";\n}\n\nfunction isRange(value: unknown): value is LspRange {\n\treturn isRecord(value) && isPosition(value.start) && isPosition(value.end);\n}\n\nfunction toOneBasedPosition(position: LspPosition): LspPosition {\n\treturn { line: position.line + 1, character: position.character + 1 };\n}\n\nfunction toOneBasedRange(range: LspRange): LspRange {\n\treturn { start: toOneBasedPosition(range.start), end: toOneBasedPosition(range.end) };\n}\n\nfunction fileUriToAbsolutePath(uri: string): string | undefined {\n\tif (!uri.startsWith(\"file:\")) return undefined;\n\ttry {\n\t\treturn fileURLToPath(uri);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction rawLocationUriAndRange(value: unknown): { uri: string; range: LspRange } | undefined {\n\tif (!isRecord(value)) return undefined;\n\tif (typeof value.uri === \"string\" && isRange(value.range)) return { uri: value.uri, range: value.range };\n\tif (typeof value.targetUri === \"string\" && isRange(value.targetRange)) {\n\t\treturn { uri: value.targetUri, range: value.targetRange };\n\t}\n\treturn undefined;\n}\n\nfunction normalizeLocations(raw: unknown, cwd: string): { locations: LspLocation[]; omitted: number } {\n\tconst items = Array.isArray(raw) ? raw : raw === undefined || raw === null ? [] : [raw];\n\tconst locations: LspLocation[] = [];\n\tlet omitted = 0;\n\tfor (const item of items) {\n\t\tconst parsed = rawLocationUriAndRange(item);\n\t\tconst absolutePath = parsed ? fileUriToAbsolutePath(parsed.uri) : undefined;\n\t\tif (!parsed || !absolutePath) {\n\t\t\tomitted++;\n\t\t\tcontinue;\n\t\t}\n\t\tlocations.push({\n\t\t\tpath: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd),\n\t\t\trange: toOneBasedRange(parsed.range),\n\t\t});\n\t}\n\treturn { locations, omitted };\n}\n\nfunction compareLocations(a: LspLocation, b: LspLocation): number {\n\tif (a.path !== b.path) return a.path < b.path ? -1 : 1;\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\tif (a.range.end.line !== b.range.end.line) return a.range.end.line - b.range.end.line;\n\treturn a.range.end.character - b.range.end.character;\n}\n\nfunction dedupeSortAndCap(locations: LspLocation[], max: number): { locations: LspLocation[]; truncated: number } {\n\tconst seen = new Set<string>();\n\tconst unique: LspLocation[] = [];\n\tfor (const location of locations) {\n\t\tconst key = JSON.stringify(location);\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tunique.push(location);\n\t}\n\tunique.sort(compareLocations);\n\tconst capped = unique.slice(0, max);\n\treturn { locations: capped, truncated: unique.length - capped.length };\n}\n\nfunction isRawDocumentSymbol(value: unknown): value is Record<string, unknown> {\n\treturn isRecord(value) && typeof value.name === \"string\" && isRange(value.range) && isRange(value.selectionRange);\n}\n\nfunction flattenSymbols(raw: unknown, path: string): { symbols: LspSymbol[]; omitted: number } {\n\tconst symbols: LspSymbol[] = [];\n\tlet omitted = 0;\n\tconst visit = (value: unknown): void => {\n\t\tif (!Array.isArray(value)) return;\n\t\tfor (const item of value) {\n\t\t\tif (!isRawDocumentSymbol(item)) {\n\t\t\t\tomitted++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tsymbols.push({\n\t\t\t\tname: item.name as string,\n\t\t\t\tkind: typeof item.kind === \"number\" ? item.kind : 0,\n\t\t\t\tpath,\n\t\t\t\trange: toOneBasedRange(item.range as LspRange),\n\t\t\t\tselectionRange: toOneBasedRange(item.selectionRange as LspRange),\n\t\t\t\t...(typeof item.detail === \"string\" ? { detail: item.detail } : {}),\n\t\t\t});\n\t\t\tif (Array.isArray(item.children)) visit(item.children);\n\t\t}\n\t};\n\tvisit(Array.isArray(raw) ? raw : []);\n\treturn { symbols, omitted };\n}\n\nfunction compareSymbols(a: LspSymbol, b: LspSymbol): number {\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\treturn a.name === b.name ? 0 : a.name < b.name ? -1 : 1;\n}\n\nfunction capSymbols(symbols: LspSymbol[], max: number): { symbols: LspSymbol[]; truncated: number } {\n\tconst sorted = [...symbols].sort(compareSymbols);\n\tconst capped = sorted.slice(0, max);\n\treturn { symbols: capped, truncated: sorted.length - capped.length };\n}\n\nfunction formatNotices(omitted: number, truncated: number): string {\n\tconst notices: string[] = [];\n\tif (omitted > 0) notices.push(`${omitted} non-file result(s) omitted`);\n\tif (truncated > 0) notices.push(`${truncated} result(s) truncated`);\n\treturn notices.length > 0 ? `\\n\\n[${notices.join(\", \")}]` : \"\";\n}\n\nfunction formatLocationsText(\n\toperation: \"definition\" | \"references\",\n\tlocations: LspLocation[],\n\tomitted: number,\n\ttruncated: number,\n): string {\n\tif (locations.length === 0) {\n\t\treturn operation === \"definition\" ? \"No definition found.\" : \"No references found.\";\n\t}\n\tconst lines = locations.map(\n\t\t(location) => `${location.path}:${location.range.start.line}:${location.range.start.character}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nfunction formatSymbolsText(symbols: LspSymbol[], omitted: number, truncated: number): string {\n\tif (symbols.length === 0) return \"No symbols found.\";\n\tconst lines = symbols.map(\n\t\t(symbol) => `${symbol.path}:${symbol.range.start.line}:${symbol.range.start.character} ${symbol.name}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nexport function createLspToolDefinition(\n\tcwd: string,\n\toptions: LspToolOptions,\n): ApexToolDefinition<typeof lspSchema, LspToolDetails> {\n\tconst { operations } = options;\n\treturn {\n\t\tname: \"lsp\",\n\t\tlabel: \"lsp\",\n\t\tdescription: \"Query the configured language server for definitions, references, or symbols.\",\n\t\tparameters: lspSchema,\n\t\tcontract: {\n\t\t\t// `grep` spawns `rg` and declares {fs.read}, not {exec}, because the caller\n\t\t\t// never chooses what runs -- the executable, args, and closed JSON-RPC\n\t\t\t// method set all come from settings.json / this tool's own code. Same\n\t\t\t// reasoning here: {exec} would silently widen a delegation ceiling for no\n\t\t\t// capability the model can actually reach through this tool.\n\t\t\tcapabilities: new Set([\"fs.read\"]),\n\t\t\tpermission: createPathPermissionSpec({\n\t\t\t\tcwd,\n\t\t\t\tdefaultBehavior: \"allow\",\n\t\t\t\tverb: \"Query\",\n\t\t\t\tgetPath: (params) => params.path,\n\t\t\t}),\n\t\t\tcontext: { resultRecoverable: true, deferSchema: true },\n\t\t\tevidence: { emits: new Set(), capture: () => [] },\n\t\t},\n\t\tasync execute(_toolCallId, input: LspToolInput, signal?: AbortSignal) {\n\t\t\tconst absolutePath = resolveToCwd(input.path, cwd);\n\t\t\tconst uri = pathToFileURL(absolutePath).href;\n\n\t\t\tif (input.operation === \"document_symbols\") {\n\t\t\t\tconst raw = await operations.request(\n\t\t\t\t\tabsolutePath,\n\t\t\t\t\t\"textDocument/documentSymbol\",\n\t\t\t\t\t{ textDocument: { uri } },\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\t\t\t\tconst relativePath = formatPathRelativeToCwdOrAbsolute(absolutePath, cwd);\n\t\t\t\tconst { symbols, omitted } = flattenSymbols(raw, relativePath);\n\t\t\t\tconst { symbols: capped, truncated } = capSymbols(symbols, MAX_SYMBOLS);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: formatSymbolsText(capped, omitted, truncated) }],\n\t\t\t\t\tdetails: { operation: \"document_symbols\", symbols: capped, omitted, truncated },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst position = { line: input.line - 1, character: input.character - 1 };\n\t\t\tconst method = input.operation === \"definition\" ? \"textDocument/definition\" : \"textDocument/references\";\n\t\t\tconst params: Record<string, unknown> = { textDocument: { uri }, position };\n\t\t\tif (input.operation === \"references\") params.context = { includeDeclaration: true };\n\t\t\tconst raw = await operations.request(absolutePath, method, params, signal);\n\t\t\tconst { locations, omitted } = normalizeLocations(raw, cwd);\n\t\t\tconst { locations: capped, truncated } = dedupeSortAndCap(locations, MAX_LOCATIONS);\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: formatLocationsText(input.operation, capped, omitted, truncated) }],\n\t\t\t\tdetails: { operation: input.operation, locations: capped, omitted, truncated },\n\t\t\t};\n\t\t},\n\t};\n}\n\nexport function createLspTool(cwd: string, options: LspToolOptions): AgentTool<typeof lspSchema> {\n\treturn wrapToolDefinition(createLspToolDefinition(cwd, options));\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AgentTool } from "apex-code-agent-core";
|
|
2
2
|
import { type Static, Type } from "typebox";
|
|
3
3
|
import type { ApexToolDefinition } from "./contract.ts";
|
|
4
|
+
import type { DiagnosticsOperations, DiagnosticsOutcome } from "./diagnostics.ts";
|
|
4
5
|
declare const writeSchema: Type.TObject<{
|
|
5
6
|
path: Type.TString;
|
|
6
7
|
content: Type.TString;
|
|
@@ -13,6 +14,8 @@ export type WriteToolInput = Static<typeof writeSchema>;
|
|
|
13
14
|
export interface WriteToolDetails {
|
|
14
15
|
byteCount: number;
|
|
15
16
|
contentHash: string;
|
|
17
|
+
/** Present only when `WriteToolOptions.diagnosticsOperations` is configured (LSP.4). */
|
|
18
|
+
diagnostics?: DiagnosticsOutcome;
|
|
16
19
|
}
|
|
17
20
|
/**
|
|
18
21
|
* Pluggable operations for the write tool.
|
|
@@ -27,6 +30,13 @@ export interface WriteOperations {
|
|
|
27
30
|
export interface WriteToolOptions {
|
|
28
31
|
/** Custom operations for file writing. Default: local filesystem */
|
|
29
32
|
operations?: WriteOperations;
|
|
33
|
+
/**
|
|
34
|
+
* Optional post-mutation diagnostics (LSP.4). Absent by default -- byte-identical
|
|
35
|
+
* existing behavior. When present, called inside `withFileMutationQueue` after the
|
|
36
|
+
* write succeeds and before the queue releases, matching `TestOperations`/
|
|
37
|
+
* `GrepOperations`' injection pattern (`test.ts:28`, `grep.ts:58`).
|
|
38
|
+
*/
|
|
39
|
+
diagnosticsOperations?: DiagnosticsOperations;
|
|
30
40
|
}
|
|
31
41
|
export declare function createWriteToolDefinition(cwd: string, options?: WriteToolOptions): ApexToolDefinition<typeof writeSchema, WriteToolDetails>;
|
|
32
42
|
export declare function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAOxD,QAAA,MAAM,WAAW;;;EAGf,CAAC;AAEH,eAAO,MAAM,iCAAiC;;;CAGpC,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAExD,MAAM,WAAW,gBAAgB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACpB;AAMD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,8BAA8B;IAC9B,SAAS,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,mCAAmC;IACnC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAOD,MAAM,WAAW,gBAAgB;IAChC,oEAAoE;IACpE,UAAU,CAAC,EAAE,eAAe,CAAC;CAC7B;AA6ID,wBAAgB,yBAAyB,CACxC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,gBAAgB,GACxB,kBAAkB,CAAC,OAAO,WAAW,EAAE,gBAAgB,CAAC,CAyG1D;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC,OAAO,WAAW,CAAC,CAEtG","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { Container, Text } from \"@earendil-works/pi-tui\";\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport { mkdir as fsMkdir, writeFile as fsWriteFile } from \"fs/promises\";\nimport { dirname } from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport type { ApexToolDefinition } from \"./contract.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { createPathPermissionSpec } from \"./path-permission.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { normalizeDisplayText, renderToolPath, replaceTabs, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst writeSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to write (relative or absolute)\" }),\n\tcontent: Type.String({ description: \"Content to write to the file\" }),\n});\n\nexport const writeToolSystemPromptContribution = {\n\tsnippet: \"Create or overwrite files\",\n\tguidelines: [\"Use write only for new files or complete rewrites.\"],\n} as const;\n\nexport type WriteToolInput = Static<typeof writeSchema>;\n\nexport interface WriteToolDetails {\n\tbyteCount: number;\n\tcontentHash: string;\n}\n\nfunction sha256(value: string): string {\n\treturn createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\n/**\n * Pluggable operations for the write tool.\n * Override these to delegate file writing to remote systems (for example SSH).\n */\nexport interface WriteOperations {\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Create directory recursively */\n\tmkdir: (dir: string) => Promise<void>;\n}\n\nconst defaultWriteOperations: WriteOperations = {\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\tmkdir: (dir) => fsMkdir(dir, { recursive: true }).then(() => {}),\n};\n\nexport interface WriteToolOptions {\n\t/** Custom operations for file writing. Default: local filesystem */\n\toperations?: WriteOperations;\n}\n\ntype WriteHighlightCache = {\n\trawPath: string | null;\n\tlang: string;\n\trawContent: string;\n\tnormalizedLines: string[];\n\thighlightedLines: string[];\n};\n\nclass WriteCallRenderComponent extends Text {\n\tcache?: WriteHighlightCache;\n\n\tconstructor() {\n\t\tsuper(\"\", 0, 0);\n\t}\n}\n\nconst WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;\n\nfunction highlightSingleLine(line: string, lang: string): string {\n\tconst highlighted = highlightCode(line, lang);\n\treturn highlighted[0] ?? \"\";\n}\n\nfunction refreshWriteHighlightPrefix(cache: WriteHighlightCache): void {\n\tconst prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\tif (prefixCount === 0) return;\n\tconst prefixSource = cache.normalizedLines.slice(0, prefixCount).join(\"\\n\");\n\tconst prefixHighlighted = highlightCode(prefixSource, cache.lang);\n\tfor (let i = 0; i < prefixCount; i++) {\n\t\tcache.highlightedLines[i] =\n\t\t\tprefixHighlighted[i] ?? highlightSingleLine(cache.normalizedLines[i] ?? \"\", cache.lang);\n\t}\n}\n\nfunction rebuildWriteHighlightCacheFull(rawPath: string | null, fileContent: string): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tconst displayContent = normalizeDisplayText(fileContent);\n\tconst normalized = replaceTabs(displayContent);\n\treturn {\n\t\trawPath,\n\t\tlang,\n\t\trawContent: fileContent,\n\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\thighlightedLines: highlightCode(normalized, lang),\n\t};\n}\n\nfunction updateWriteHighlightCacheIncremental(\n\tcache: WriteHighlightCache | undefined,\n\trawPath: string | null,\n\tfileContent: string,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tif (!cache) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (cache.lang !== lang || cache.rawPath !== rawPath) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (!fileContent.startsWith(cache.rawContent)) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (fileContent.length === cache.rawContent.length) return cache;\n\n\tconst deltaRaw = fileContent.slice(cache.rawContent.length);\n\tconst deltaDisplay = normalizeDisplayText(deltaRaw);\n\tconst deltaNormalized = replaceTabs(deltaDisplay);\n\tcache.rawContent = fileContent;\n\tif (cache.normalizedLines.length === 0) {\n\t\tcache.normalizedLines.push(\"\");\n\t\tcache.highlightedLines.push(\"\");\n\t}\n\n\tconst segments = deltaNormalized.split(\"\\n\");\n\tconst lastIndex = cache.normalizedLines.length - 1;\n\tcache.normalizedLines[lastIndex] += segments[0];\n\tcache.highlightedLines[lastIndex] = highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);\n\tfor (let i = 1; i < segments.length; i++) {\n\t\tcache.normalizedLines.push(segments[i]);\n\t\tcache.highlightedLines.push(highlightSingleLine(segments[i], cache.lang));\n\t}\n\trefreshWriteHighlightPrefix(cache);\n\treturn cache;\n}\n\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\n\nfunction formatWriteCall(\n\targs: { path?: string; file_path?: string; content?: string } | undefined,\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tcache: WriteHighlightCache | undefined,\n\tcwd: string,\n): string {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst fileContent = str(args?.content);\n\tconst pathDisplay = renderToolPath(rawPath, theme, cwd);\n\tlet text = `${theme.fg(\"toolTitle\", theme.bold(\"write\"))} ${pathDisplay}`;\n\n\tif (fileContent === null) {\n\t\ttext += `\\n\\n${theme.fg(\"error\", \"[invalid content arg - expected string]\")}`;\n\t} else if (fileContent) {\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tconst renderedLines = lang\n\t\t\t? (cache?.highlightedLines ?? highlightCode(replaceTabs(normalizeDisplayText(fileContent)), lang))\n\t\t\t: normalizeDisplayText(fileContent).split(\"\\n\");\n\t\tconst lines = trimTrailingEmptyLines(renderedLines);\n\t\tconst totalLines = lines.length;\n\t\tconst maxLines = options.expanded ? lines.length : 10;\n\t\tconst displayLines = lines.slice(0, maxLines);\n\t\tconst remaining = lines.length - maxLines;\n\t\ttext += `\\n\\n${displayLines.map((line) => (lang ? line : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines, ${totalLines} total,`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t}\n\t}\n\n\treturn text;\n}\n\nfunction formatWriteResult(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>; isError?: boolean },\n\ttheme: Theme,\n): string | undefined {\n\tif (!result.isError) {\n\t\treturn undefined;\n\t}\n\tconst output = result.content\n\t\t.filter((c) => c.type === \"text\")\n\t\t.map((c) => c.text || \"\")\n\t\t.join(\"\\n\");\n\tif (!output) {\n\t\treturn undefined;\n\t}\n\treturn `\\n${theme.fg(\"error\", output)}`;\n}\n\nexport function createWriteToolDefinition(\n\tcwd: string,\n\toptions?: WriteToolOptions,\n): ApexToolDefinition<typeof writeSchema, WriteToolDetails> {\n\tconst ops = options?.operations ?? defaultWriteOperations;\n\treturn {\n\t\tname: \"write\",\n\t\tlabel: \"write\",\n\t\tdescription:\n\t\t\t\"Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.\",\n\t\tpromptSnippet: writeToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...writeToolSystemPromptContribution.guidelines],\n\t\tparameters: writeSchema,\n\t\tcontract: {\n\t\t\tcapabilities: new Set([\"fs.write\"]),\n\t\t\tpermission: createPathPermissionSpec({\n\t\t\t\tcwd,\n\t\t\t\tdefaultBehavior: \"ask\",\n\t\t\t\tverb: \"Write\",\n\t\t\t\tgetPath: (params) => params.path,\n\t\t\t}),\n\t\t\tcontext: { resultRecoverable: true, deferSchema: false },\n\t\t\tevidence: {\n\t\t\t\temits: new Set([\"diff\"]),\n\t\t\t\tcapture: (params, result) => {\n\t\t\t\t\tconst details = result.details;\n\t\t\t\t\treturn details\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tkind: \"diff\",\n\t\t\t\t\t\t\t\t\tpath: params.path,\n\t\t\t\t\t\t\t\t\tbyteCount: details.byteCount,\n\t\t\t\t\t\t\t\t\tcontentHash: details.contentHash,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: [{ kind: \"diff\", path: params.path }];\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, content }: { path: string; content: string },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\tconst absolutePath = resolveToCwd(path, cwd);\n\t\t\tconst dir = dirname(absolutePath);\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\t\t\t\t// Create parent directories if needed.\n\t\t\t\tawait ops.mkdir(dir);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Write the file contents.\n\t\t\t\tawait ops.writeFile(absolutePath, content);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: `Successfully wrote ${content.length} bytes to ${path}` }],\n\t\t\t\t\tdetails: { byteCount: Buffer.byteLength(content), contentHash: sha256(content) },\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst renderArgs = args as { path?: string; file_path?: string; content?: string } | undefined;\n\t\t\tconst rawPath = str(renderArgs?.file_path ?? renderArgs?.path);\n\t\t\tconst fileContent = str(renderArgs?.content);\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as WriteCallRenderComponent | undefined) ?? new WriteCallRenderComponent();\n\t\t\tif (fileContent !== null) {\n\t\t\t\tcomponent.cache = context.argsComplete\n\t\t\t\t\t? rebuildWriteHighlightCacheFull(rawPath, fileContent)\n\t\t\t\t\t: updateWriteHighlightCacheIncremental(component.cache, rawPath, fileContent);\n\t\t\t} else {\n\t\t\t\tcomponent.cache = undefined;\n\t\t\t}\n\t\t\tcomponent.setText(\n\t\t\t\tformatWriteCall(\n\t\t\t\t\trenderArgs,\n\t\t\t\t\t{ expanded: context.expanded, isPartial: context.isPartial },\n\t\t\t\t\ttheme,\n\t\t\t\t\tcomponent.cache,\n\t\t\t\t\tcontext.cwd,\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn component;\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst output = formatWriteResult({ ...result, isError: context.isError }, theme);\n\t\t\tif (!output) {\n\t\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\t\tcomponent.clear();\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(output);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema> {\n\treturn wrapToolDefinition(createWriteToolDefinition(cwd, options));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,eAAe,CAAC;AACxE,OAAO,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAQlF,QAAA,MAAM,WAAW;;;EAGf,CAAC;AAEH,eAAO,MAAM,iCAAiC;;;CAGpC,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAExD,MAAM,WAAW,gBAAgB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,wFAAwF;IACxF,WAAW,CAAC,EAAE,kBAAkB,CAAC;CACjC;AAMD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,8BAA8B;IAC9B,SAAS,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,mCAAmC;IACnC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAOD,MAAM,WAAW,gBAAgB;IAChC,oEAAoE;IACpE,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;CAC9C;AA6ID,wBAAgB,yBAAyB,CACxC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,gBAAgB,GACxB,kBAAkB,CAAC,OAAO,WAAW,EAAE,gBAAgB,CAAC,CAsH1D;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC,OAAO,WAAW,CAAC,CAEtG","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { Container, Text } from \"@earendil-works/pi-tui\";\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport { mkdir as fsMkdir, writeFile as fsWriteFile } from \"fs/promises\";\nimport { dirname } from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport type { ApexToolDefinition, EvidenceRecord } from \"./contract.ts\";\nimport type { DiagnosticsOperations, DiagnosticsOutcome } from \"./diagnostics.ts\";\nimport { diagnosticEvidenceForPath, formatDiagnosticsOutcome } from \"./diagnostics.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { createPathPermissionSpec } from \"./path-permission.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { normalizeDisplayText, renderToolPath, replaceTabs, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst writeSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to write (relative or absolute)\" }),\n\tcontent: Type.String({ description: \"Content to write to the file\" }),\n});\n\nexport const writeToolSystemPromptContribution = {\n\tsnippet: \"Create or overwrite files\",\n\tguidelines: [\"Use write only for new files or complete rewrites.\"],\n} as const;\n\nexport type WriteToolInput = Static<typeof writeSchema>;\n\nexport interface WriteToolDetails {\n\tbyteCount: number;\n\tcontentHash: string;\n\t/** Present only when `WriteToolOptions.diagnosticsOperations` is configured (LSP.4). */\n\tdiagnostics?: DiagnosticsOutcome;\n}\n\nfunction sha256(value: string): string {\n\treturn createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\n/**\n * Pluggable operations for the write tool.\n * Override these to delegate file writing to remote systems (for example SSH).\n */\nexport interface WriteOperations {\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Create directory recursively */\n\tmkdir: (dir: string) => Promise<void>;\n}\n\nconst defaultWriteOperations: WriteOperations = {\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\tmkdir: (dir) => fsMkdir(dir, { recursive: true }).then(() => {}),\n};\n\nexport interface WriteToolOptions {\n\t/** Custom operations for file writing. Default: local filesystem */\n\toperations?: WriteOperations;\n\t/**\n\t * Optional post-mutation diagnostics (LSP.4). Absent by default -- byte-identical\n\t * existing behavior. When present, called inside `withFileMutationQueue` after the\n\t * write succeeds and before the queue releases, matching `TestOperations`/\n\t * `GrepOperations`' injection pattern (`test.ts:28`, `grep.ts:58`).\n\t */\n\tdiagnosticsOperations?: DiagnosticsOperations;\n}\n\ntype WriteHighlightCache = {\n\trawPath: string | null;\n\tlang: string;\n\trawContent: string;\n\tnormalizedLines: string[];\n\thighlightedLines: string[];\n};\n\nclass WriteCallRenderComponent extends Text {\n\tcache?: WriteHighlightCache;\n\n\tconstructor() {\n\t\tsuper(\"\", 0, 0);\n\t}\n}\n\nconst WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;\n\nfunction highlightSingleLine(line: string, lang: string): string {\n\tconst highlighted = highlightCode(line, lang);\n\treturn highlighted[0] ?? \"\";\n}\n\nfunction refreshWriteHighlightPrefix(cache: WriteHighlightCache): void {\n\tconst prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\tif (prefixCount === 0) return;\n\tconst prefixSource = cache.normalizedLines.slice(0, prefixCount).join(\"\\n\");\n\tconst prefixHighlighted = highlightCode(prefixSource, cache.lang);\n\tfor (let i = 0; i < prefixCount; i++) {\n\t\tcache.highlightedLines[i] =\n\t\t\tprefixHighlighted[i] ?? highlightSingleLine(cache.normalizedLines[i] ?? \"\", cache.lang);\n\t}\n}\n\nfunction rebuildWriteHighlightCacheFull(rawPath: string | null, fileContent: string): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tconst displayContent = normalizeDisplayText(fileContent);\n\tconst normalized = replaceTabs(displayContent);\n\treturn {\n\t\trawPath,\n\t\tlang,\n\t\trawContent: fileContent,\n\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\thighlightedLines: highlightCode(normalized, lang),\n\t};\n}\n\nfunction updateWriteHighlightCacheIncremental(\n\tcache: WriteHighlightCache | undefined,\n\trawPath: string | null,\n\tfileContent: string,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tif (!cache) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (cache.lang !== lang || cache.rawPath !== rawPath) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (!fileContent.startsWith(cache.rawContent)) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (fileContent.length === cache.rawContent.length) return cache;\n\n\tconst deltaRaw = fileContent.slice(cache.rawContent.length);\n\tconst deltaDisplay = normalizeDisplayText(deltaRaw);\n\tconst deltaNormalized = replaceTabs(deltaDisplay);\n\tcache.rawContent = fileContent;\n\tif (cache.normalizedLines.length === 0) {\n\t\tcache.normalizedLines.push(\"\");\n\t\tcache.highlightedLines.push(\"\");\n\t}\n\n\tconst segments = deltaNormalized.split(\"\\n\");\n\tconst lastIndex = cache.normalizedLines.length - 1;\n\tcache.normalizedLines[lastIndex] += segments[0];\n\tcache.highlightedLines[lastIndex] = highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);\n\tfor (let i = 1; i < segments.length; i++) {\n\t\tcache.normalizedLines.push(segments[i]);\n\t\tcache.highlightedLines.push(highlightSingleLine(segments[i], cache.lang));\n\t}\n\trefreshWriteHighlightPrefix(cache);\n\treturn cache;\n}\n\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\n\nfunction formatWriteCall(\n\targs: { path?: string; file_path?: string; content?: string } | undefined,\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tcache: WriteHighlightCache | undefined,\n\tcwd: string,\n): string {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst fileContent = str(args?.content);\n\tconst pathDisplay = renderToolPath(rawPath, theme, cwd);\n\tlet text = `${theme.fg(\"toolTitle\", theme.bold(\"write\"))} ${pathDisplay}`;\n\n\tif (fileContent === null) {\n\t\ttext += `\\n\\n${theme.fg(\"error\", \"[invalid content arg - expected string]\")}`;\n\t} else if (fileContent) {\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tconst renderedLines = lang\n\t\t\t? (cache?.highlightedLines ?? highlightCode(replaceTabs(normalizeDisplayText(fileContent)), lang))\n\t\t\t: normalizeDisplayText(fileContent).split(\"\\n\");\n\t\tconst lines = trimTrailingEmptyLines(renderedLines);\n\t\tconst totalLines = lines.length;\n\t\tconst maxLines = options.expanded ? lines.length : 10;\n\t\tconst displayLines = lines.slice(0, maxLines);\n\t\tconst remaining = lines.length - maxLines;\n\t\ttext += `\\n\\n${displayLines.map((line) => (lang ? line : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines, ${totalLines} total,`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t}\n\t}\n\n\treturn text;\n}\n\nfunction formatWriteResult(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>; isError?: boolean },\n\ttheme: Theme,\n): string | undefined {\n\tif (!result.isError) {\n\t\treturn undefined;\n\t}\n\tconst output = result.content\n\t\t.filter((c) => c.type === \"text\")\n\t\t.map((c) => c.text || \"\")\n\t\t.join(\"\\n\");\n\tif (!output) {\n\t\treturn undefined;\n\t}\n\treturn `\\n${theme.fg(\"error\", output)}`;\n}\n\nexport function createWriteToolDefinition(\n\tcwd: string,\n\toptions?: WriteToolOptions,\n): ApexToolDefinition<typeof writeSchema, WriteToolDetails> {\n\tconst ops = options?.operations ?? defaultWriteOperations;\n\tconst diagnosticsOperations = options?.diagnosticsOperations;\n\treturn {\n\t\tname: \"write\",\n\t\tlabel: \"write\",\n\t\tdescription:\n\t\t\t\"Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.\",\n\t\tpromptSnippet: writeToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...writeToolSystemPromptContribution.guidelines],\n\t\tparameters: writeSchema,\n\t\tcontract: {\n\t\t\tcapabilities: new Set([\"fs.write\"]),\n\t\t\tpermission: createPathPermissionSpec({\n\t\t\t\tcwd,\n\t\t\t\tdefaultBehavior: \"ask\",\n\t\t\t\tverb: \"Write\",\n\t\t\t\tgetPath: (params) => params.path,\n\t\t\t}),\n\t\t\tcontext: { resultRecoverable: true, deferSchema: false },\n\t\t\tevidence: {\n\t\t\t\temits: new Set(diagnosticsOperations ? [\"diff\", \"diagnostic\"] : [\"diff\"]),\n\t\t\t\tcapture: (params, result) => {\n\t\t\t\t\tconst details = result.details;\n\t\t\t\t\tconst records: EvidenceRecord[] = details\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tkind: \"diff\",\n\t\t\t\t\t\t\t\t\tpath: params.path,\n\t\t\t\t\t\t\t\t\tbyteCount: details.byteCount,\n\t\t\t\t\t\t\t\t\tcontentHash: details.contentHash,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: [{ kind: \"diff\", path: params.path }];\n\t\t\t\t\tif (details?.diagnostics) records.push(diagnosticEvidenceForPath(params.path, details.diagnostics));\n\t\t\t\t\treturn records;\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, content }: { path: string; content: string },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\tconst absolutePath = resolveToCwd(path, cwd);\n\t\t\tconst dir = dirname(absolutePath);\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\t\t\t\t// Create parent directories if needed.\n\t\t\t\tawait ops.mkdir(dir);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Write the file contents.\n\t\t\t\tawait ops.writeFile(absolutePath, content);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst successText = `Successfully wrote ${content.length} bytes to ${path}`;\n\n\t\t\t\tif (diagnosticsOperations) {\n\t\t\t\t\tconst diagnostics = await diagnosticsOperations.afterMutation(absolutePath, signal);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: `${successText}\\n\\n${formatDiagnosticsOutcome(diagnostics)}` }],\n\t\t\t\t\t\tdetails: { byteCount: Buffer.byteLength(content), contentHash: sha256(content), diagnostics },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: successText }],\n\t\t\t\t\tdetails: { byteCount: Buffer.byteLength(content), contentHash: sha256(content) },\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst renderArgs = args as { path?: string; file_path?: string; content?: string } | undefined;\n\t\t\tconst rawPath = str(renderArgs?.file_path ?? renderArgs?.path);\n\t\t\tconst fileContent = str(renderArgs?.content);\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as WriteCallRenderComponent | undefined) ?? new WriteCallRenderComponent();\n\t\t\tif (fileContent !== null) {\n\t\t\t\tcomponent.cache = context.argsComplete\n\t\t\t\t\t? rebuildWriteHighlightCacheFull(rawPath, fileContent)\n\t\t\t\t\t: updateWriteHighlightCacheIncremental(component.cache, rawPath, fileContent);\n\t\t\t} else {\n\t\t\t\tcomponent.cache = undefined;\n\t\t\t}\n\t\t\tcomponent.setText(\n\t\t\t\tformatWriteCall(\n\t\t\t\t\trenderArgs,\n\t\t\t\t\t{ expanded: context.expanded, isPartial: context.isPartial },\n\t\t\t\t\ttheme,\n\t\t\t\t\tcomponent.cache,\n\t\t\t\t\tcontext.cwd,\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn component;\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst output = formatWriteResult({ ...result, isError: context.isError }, theme);\n\t\t\tif (!output) {\n\t\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\t\tcomponent.clear();\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(output);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema> {\n\treturn wrapToolDefinition(createWriteToolDefinition(cwd, options));\n}\n"]}
|