@caupulican/pi-adaptative 0.86.14 → 0.86.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/core/extensions/types.d.ts +3 -1
  3. package/dist/core/extensions/types.d.ts.map +1 -1
  4. package/dist/core/extensions/types.js.map +1 -1
  5. package/dist/core/tools/edit.d.ts +4 -1
  6. package/dist/core/tools/edit.d.ts.map +1 -1
  7. package/dist/core/tools/edit.js +31 -0
  8. package/dist/core/tools/edit.js.map +1 -1
  9. package/dist/core/tools/file-failure-recovery.d.ts +17 -0
  10. package/dist/core/tools/file-failure-recovery.d.ts.map +1 -0
  11. package/dist/core/tools/file-failure-recovery.js +43 -0
  12. package/dist/core/tools/file-failure-recovery.js.map +1 -0
  13. package/dist/core/tools/index.d.ts +1 -0
  14. package/dist/core/tools/index.d.ts.map +1 -1
  15. package/dist/core/tools/index.js +1 -0
  16. package/dist/core/tools/index.js.map +1 -1
  17. package/dist/core/tools/ls.d.ts +3 -0
  18. package/dist/core/tools/ls.d.ts.map +1 -1
  19. package/dist/core/tools/ls.js +14 -0
  20. package/dist/core/tools/ls.js.map +1 -1
  21. package/dist/core/tools/read.d.ts +3 -0
  22. package/dist/core/tools/read.d.ts.map +1 -1
  23. package/dist/core/tools/read.js +17 -0
  24. package/dist/core/tools/read.js.map +1 -1
  25. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  26. package/dist/core/tools/tool-definition-wrapper.js +2 -0
  27. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  28. package/dist/core/tools/write.d.ts +4 -1
  29. package/dist/core/tools/write.d.ts.map +1 -1
  30. package/dist/core/tools/write.js +36 -0
  31. package/dist/core/tools/write.js.map +1 -1
  32. package/dist/index.d.ts +1 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +1 -1
  35. package/dist/index.js.map +1 -1
  36. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  37. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  38. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  39. package/examples/extensions/sandbox/package-lock.json +2 -2
  40. package/examples/extensions/sandbox/package.json +1 -1
  41. package/examples/extensions/with-deps/package-lock.json +2 -2
  42. package/examples/extensions/with-deps/package.json +1 -1
  43. package/npm-shrinkwrap.json +12 -12
  44. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,GAAG,EAA2B,MAAM,oBAAoB,CAAC;AAElE,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAON,KAAK,aAAa,EAClB,KAAK,cAAc,EAOnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACN,4BAA4B,EAG5B,MAAM,2BAA2B,CAAC;AAMnC,KAAK,WAAW,GAAG,cAAc,GAAG,aAAa,CAAC;AAElD,KAAK,eAAe,GAAG;IACtB,aAAa,CAAC,EAAE,uBAAuB,CAAC;CACxC,CAAC;AAoBF,QAAA,MAAM,UAAU;;;;;;;;;;;;;IAiBd,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAStD,MAAM,WAAW,eAAe;IAC/B,KAAK,EAAE,QAAQ,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,wFA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,EAAE,WAAW,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAwMF,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,EAAE,eAAe,CAAC,CAqOjF;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG"}
@@ -1,9 +1,11 @@
1
+ import { createAgentToolFailureRecoveryAuthority } from "@caupulican/pi-agent-core";
1
2
  import { Box, Container, Spacer, Text } from "@caupulican/pi-tui";
2
3
  import { readFile as fsReadFile, writeFile as fsWriteFile } from "fs/promises";
3
4
  import { Type } from "typebox";
4
5
  import { renderDiff } from "../../modes/interactive/components/diff.js";
5
6
  import { applyEditMatchPlan, applyEditsToNormalizedContent, computeEditsPlannedDiff, detectLineEnding, digestNormalizedEditSource, generateDiffString, generateUnifiedPatch, normalizeToLF, restoreLineEndings, stripBom, } from "./edit-diff.js";
6
7
  import { isValidUTF8 } from "./file-encoding-policy.js";
8
+ import { EDIT_RETARGET_RECOVERY_TARGET_KIND, FILE_CURRENT_TEXT_RECOVERY_TARGET_KIND, fileRecoveryTarget, selectFileFailureRecoveryAuthority, } from "./file-failure-recovery.js";
7
9
  import { FileMutationIntentController, FileMutationPreflightError, } from "./file-mutation-intent.js";
8
10
  import { withFileMutationQueue } from "./file-mutation-queue.js";
9
11
  import { resolveToCwd } from "./path-utils.js";
@@ -208,10 +210,12 @@ function setEditPreview(component, preview) {
208
210
  }
209
211
  export function createEditToolDefinition(cwd, options) {
210
212
  const ops = options?.operations ?? defaultEditOperations;
213
+ const failureRecoveryAuthority = selectFileFailureRecoveryAuthority(options?.operations !== undefined, options?.failureRecoveryAuthority);
211
214
  if (options?.operations && !options.intentController) {
212
215
  throw new Error("Custom edit operations require a matching file mutation intent controller.");
213
216
  }
214
217
  const intentController = options?.intentController ?? new FileMutationIntentController();
218
+ const retargetRecoveryAuthority = createAgentToolFailureRecoveryAuthority();
215
219
  let cachedMatchPlan;
216
220
  return {
217
221
  name: "edit",
@@ -226,6 +230,33 @@ export function createEditToolDefinition(cwd, options) {
226
230
  parameters: editSchema,
227
231
  renderShell: "self",
228
232
  prepareArguments: prepareEditArguments,
233
+ failureRecovery: {
234
+ getFailureTargets: (params, failure) => {
235
+ if (failure.failureCode === "mutation_retarget_required") {
236
+ return [
237
+ {
238
+ authority: retargetRecoveryAuthority,
239
+ kind: EDIT_RETARGET_RECOVERY_TARGET_KIND,
240
+ scope: resolveToCwd(params.path, cwd),
241
+ },
242
+ ];
243
+ }
244
+ if (failure.failureCode === "edit_old_text_not_found" && failureRecoveryAuthority) {
245
+ return [
246
+ fileRecoveryTarget(failureRecoveryAuthority, FILE_CURRENT_TEXT_RECOVERY_TARGET_KIND, params.path, cwd),
247
+ ];
248
+ }
249
+ return [];
250
+ },
251
+ actions: [
252
+ {
253
+ kind: "correct",
254
+ authority: retargetRecoveryAuthority,
255
+ targetKind: EDIT_RETARGET_RECOVERY_TARGET_KIND,
256
+ instruction: "Use edit with the retained payloadRef and a corrected path naming the intended existing file.",
257
+ },
258
+ ],
259
+ },
229
260
  async execute(_toolCallId, input, signal, _onUpdate, _ctx) {
230
261
  const validated = validateEditInput(input);
231
262
  const { path } = validated;
@@ -1 +1 @@
1
- {"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAe,IA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CAAC,OAAO,EAAE,gBAAgB;yBACvD,CAAC,IAAI,OAAO,CAAC;gBAChB,CAAC;gBACD,IAAI,aAAa,CAAC,YAAY,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC;oBACpD,aAAa,CAAC,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;oBAC7C,OAAO,GAAG,IAAI,CAAC;gBAChB,CAAC;gBACD,IAAI,OAAO,EAAE,CAAC;oBACb,sBAAsB,CACrB,aAAa,EACb,OAAO,CAAC,IAAsC,EAC9C,KAAK,EACL,OAAO,CAAC,GAAG,CACX,CAAC;gBACH,CAAC;YACF,CAAC;YAED,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;YAC3G,MAAM,SAAS,GAAI,OAAO,CAAC,aAAuC,IAAI,IAAI,SAAS,EAAE,CAAC;YACtF,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,IAAI,CAAC,MAAM,EAAE,CAAC;gBACb,OAAO,SAAS,CAAC;YAClB,CAAC;YACD,SAAS,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAClC,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC3C,OAAO,SAAS,CAAC;QAClB,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB;IACpE,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport { Box, Container, Spacer, Text } from \"@caupulican/pi-tui\";\nimport { readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { renderDiff } from \"../../modes/interactive/components/diff.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\tapplyEditMatchPlan,\n\tapplyEditsToNormalizedContent,\n\tcomputeEditsPlannedDiff,\n\tdetectLineEnding,\n\tdigestNormalizedEditSource,\n\ttype Edit,\n\ttype EditDiffError,\n\ttype EditDiffResult,\n\ttype EditMatchPlan,\n\tgenerateDiffString,\n\tgenerateUnifiedPatch,\n\tnormalizeToLF,\n\trestoreLineEndings,\n\tstripBom,\n} from \"./edit-diff.ts\";\nimport { isValidUTF8 } from \"./file-encoding-policy.ts\";\nimport {\n\tFileMutationIntentController,\n\ttype FileMutationLease,\n\tFileMutationPreflightError,\n} from \"./file-mutation-intent.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { renderToolPath, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\ntype EditPreview = EditDiffResult | EditDiffError;\n\ntype EditRenderState = {\n\tcallComponent?: EditCallRenderComponent;\n};\n\nconst replaceEditSchema = Type.Object(\n\t{\n\t\toldText: Type.String({ minLength: 1 }),\n\t\tnewText: Type.String(),\n\t\trange: Type.Optional(\n\t\t\tType.Object(\n\t\t\t\t{\n\t\t\t\t\tstartLine: Type.Integer({ minimum: 1 }),\n\t\t\t\t\tendLine: Type.Integer({ minimum: 1 }),\n\t\t\t\t},\n\t\t\t\t{ additionalProperties: false },\n\t\t\t),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nconst editPathSchema = Type.String({ minLength: 1 });\nconst editSchema = Type.Union([\n\tType.Object(\n\t\t{\n\t\t\tpath: editPathSchema,\n\t\t\tedits: Type.Array(replaceEditSchema, {\n\t\t\t\tminItems: 1,\n\t\t\t}),\n\t\t},\n\t\t{ additionalProperties: false },\n\t),\n\tType.Object(\n\t\t{\n\t\t\tpath: editPathSchema,\n\t\t\tpayloadRef: Type.String({ minLength: 1 }),\n\t\t},\n\t\t{ additionalProperties: false },\n\t),\n]);\n\nexport type EditToolInput = Static<typeof editSchema>;\ntype LegacyEditToolInput = {\n\tpath?: unknown;\n\tedits?: unknown;\n\tpayloadRef?: unknown;\n\toldText?: unknown;\n\tnewText?: unknown;\n};\n\nexport interface EditToolDetails {\n\tphase: \"edited\";\n\tcontentRef?: string;\n\t/** Display-oriented diff of the changes made */\n\tdiff?: string;\n\t/** Standard unified patch of the changes made */\n\tpatch?: string;\n\t/** Line number of the first change in the new file (for editor navigation) */\n\tfirstChangedLine?: number;\n\t/** True when execution reused the match plan already validated for the call preview. */\n\tmatchPlanReused?: boolean;\n}\n\n/**\n * Pluggable operations for the edit tool.\n * Override these to delegate file editing to remote systems (for example SSH).\n */\nexport interface EditOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n}\n\nconst defaultEditOperations: EditOperations = {\n\treadFile: (path) => fsReadFile(path),\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n};\n\nexport interface EditToolOptions {\n\t/** Custom operations for file editing. Default: local filesystem */\n\toperations?: EditOperations;\n\t/** Session-owned harness preflight and exact-content-reference authority. */\n\tintentController?: FileMutationIntentController;\n}\n\nfunction prepareEditArguments(input: unknown): EditToolInput {\n\tif (!input || typeof input !== \"object\" || Array.isArray(input)) {\n\t\treturn input as EditToolInput;\n\t}\n\n\tlet args = input as Record<string, unknown>;\n\n\tconst legacy = args as LegacyEditToolInput;\n\tif (typeof legacy.oldText === \"string\" && typeof legacy.newText === \"string\") {\n\t\tconst edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];\n\t\tedits.push({ oldText: legacy.oldText, newText: legacy.newText });\n\t\tconst { oldText: _oldText, newText: _newText, ...rest } = legacy;\n\t\targs = { ...rest, edits };\n\t}\n\n\treturn args as EditToolInput;\n}\n\nfunction validateEdits(edits: unknown): Edit[] {\n\tif (!Array.isArray(edits) || edits.length === 0) {\n\t\tthrow new Error(\"Edit tool input is invalid. edits must contain at least one replacement.\");\n\t}\n\tfor (const edit of edits) {\n\t\tif (\n\t\t\ttypeof edit !== \"object\" ||\n\t\t\tedit === null ||\n\t\t\ttypeof edit.oldText !== \"string\" ||\n\t\t\ttypeof edit.newText !== \"string\"\n\t\t) {\n\t\t\tthrow new Error(\"Edit tool input is invalid. Every edit requires string oldText and newText fields.\");\n\t\t}\n\t}\n\treturn edits as Edit[];\n}\n\nfunction validateEditInput(\n\tinput: EditToolInput,\n): { path: string; edits: Edit[]; payloadRef?: undefined } | { path: string; edits?: undefined; payloadRef: string } {\n\tif (\"payloadRef\" in input) return { path: input.path, payloadRef: input.payloadRef };\n\treturn { path: input.path, edits: validateEdits(input.edits) };\n}\n\ntype RenderableEditArgs = {\n\tpath?: string;\n\tfile_path?: string;\n\tedits?: Edit[];\n\tpayloadRef?: string;\n\toldText?: string;\n\tnewText?: string;\n};\n\ntype EditToolResultLike = {\n\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\tdetails?: EditToolDetails;\n};\n\ntype EditCallRenderComponent = Box & {\n\tpreview?: EditPreview;\n\tpreviewRequestId: number;\n\tpreviewPending?: boolean;\n\tsettledError?: boolean;\n};\n\nfunction createEditCallRenderComponent(): EditCallRenderComponent {\n\treturn Object.assign(new Box(1, 1, (text: string) => text), {\n\t\tpreview: undefined as EditPreview | undefined,\n\t\tpreviewRequestId: 0,\n\t\tpreviewPending: false,\n\t\tsettledError: false,\n\t});\n}\n\nfunction getEditCallRenderComponent(state: EditRenderState, lastComponent: unknown): EditCallRenderComponent {\n\tif (lastComponent instanceof Box) {\n\t\tconst component = lastComponent as EditCallRenderComponent;\n\t\tstate.callComponent = component;\n\t\treturn component;\n\t}\n\tif (state.callComponent) {\n\t\treturn state.callComponent;\n\t}\n\tconst component = createEditCallRenderComponent();\n\tstate.callComponent = component;\n\treturn component;\n}\n\nfunction getRenderablePreviewInput(args: RenderableEditArgs | undefined): { path: string; edits: Edit[] } | null {\n\tif (!args) {\n\t\treturn null;\n\t}\n\n\tconst path = typeof args.path === \"string\" ? args.path : typeof args.file_path === \"string\" ? args.file_path : null;\n\tif (!path) {\n\t\treturn null;\n\t}\n\n\tif (\n\t\tArray.isArray(args.edits) &&\n\t\targs.edits.length > 0 &&\n\t\targs.edits.every((edit) => typeof edit?.oldText === \"string\" && typeof edit?.newText === \"string\")\n\t) {\n\t\treturn { path, edits: args.edits };\n\t}\n\n\tif (typeof args.oldText === \"string\" && typeof args.newText === \"string\") {\n\t\treturn { path, edits: [{ oldText: args.oldText, newText: args.newText }] };\n\t}\n\n\treturn null;\n}\n\ninterface CachedEditMatchPlan {\n\tabsolutePath: string;\n\tedits: Edit[];\n\tplan: EditMatchPlan;\n\tsourceDigest: string;\n\tdiff: string;\n\tfirstChangedLine: number | undefined;\n}\n\nfunction snapshotEdits(edits: Edit[]): Edit[] {\n\treturn edits.map((edit) => ({\n\t\toldText: edit.oldText,\n\t\tnewText: edit.newText,\n\t\t...(edit.range ? { range: { startLine: edit.range.startLine, endLine: edit.range.endLine } } : {}),\n\t}));\n}\n\nfunction editsMatch(left: Edit[], right: Edit[]): boolean {\n\tif (left.length !== right.length) return false;\n\tfor (let index = 0; index < left.length; index++) {\n\t\tconst leftEdit = left[index];\n\t\tconst rightEdit = right[index];\n\t\tif (\n\t\t\tleftEdit.oldText !== rightEdit.oldText ||\n\t\t\tleftEdit.newText !== rightEdit.newText ||\n\t\t\tleftEdit.range?.startLine !== rightEdit.range?.startLine ||\n\t\t\tleftEdit.range?.endLine !== rightEdit.range?.endLine\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction formatEditCall(args: RenderableEditArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nfunction formatEditResult(\n\targs: RenderableEditArgs | undefined,\n\tpreview: EditPreview | undefined,\n\tresult: EditToolResultLike,\n\ttheme: Theme,\n\tisError: boolean,\n): string | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst previewDiff = preview && !(\"error\" in preview) ? preview.diff : undefined;\n\tconst previewError = preview && \"error\" in preview ? preview.error : undefined;\n\tif (isError) {\n\t\tconst errorText = result.content\n\t\t\t.filter((c) => c.type === \"text\")\n\t\t\t.map((c) => c.text || \"\")\n\t\t\t.join(\"\\n\");\n\t\tif (!errorText || errorText === previewError) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn theme.fg(\"error\", errorText);\n\t}\n\n\tconst resultDiff = result.details?.diff;\n\tif (resultDiff && resultDiff !== previewDiff) {\n\t\treturn renderDiff(resultDiff, { filePath: rawPath ?? undefined });\n\t}\n\n\treturn undefined;\n}\n\nasync function editPathFailureWithRetainedPayload(\n\terror: FileMutationPreflightError,\n\tvalidated:\n\t\t| { path: string; edits: Edit[]; payloadRef?: undefined }\n\t\t| { path: string; edits?: undefined; payloadRef: string },\n\tintentController: FileMutationIntentController,\n\tsignal?: AbortSignal,\n): Promise<Error> {\n\tconst failureIdentity = error.reason === \"edit_missing\" ? \"edit_missing (ENOENT)\" : \"edit_not_file\";\n\tif (validated.payloadRef) {\n\t\tawait intentController.assertMutationPayload(validated.payloadRef, \"edit\", signal);\n\t\treturn new Error(\n\t\t\t`PI_FILE_MUTATION_RETARGET ${failureIdentity}: payloadRef ${validated.payloadRef}. Choose only a corrected path naming an existing file; the exact valid edit payload is retained for full revalidation.`,\n\t\t);\n\t}\n\n\ttry {\n\t\tconst retained = await intentController.retainMutationPayload(\"edit\", JSON.stringify(validated.edits));\n\t\tif (retained) {\n\t\t\treturn new Error(\n\t\t\t\t`PI_FILE_MUTATION_RETARGET ${failureIdentity}: payloadRef ${retained.payloadRef}. Choose only a corrected path naming an existing file; the exact valid edit payload is retained for full revalidation.`,\n\t\t\t);\n\t\t}\n\t} catch {\n\t\t// The path failure remains authoritative when the bounded retry cache is unavailable.\n\t}\n\treturn new Error(`${error.message} The edit payload could not be retained within the secure retry-cache bound.`);\n}\n\nfunction getEditHeaderBg(\n\tpreview: EditPreview | undefined,\n\tsettledError: boolean | undefined,\n\ttheme: Theme,\n): (text: string) => string {\n\tif (preview) {\n\t\tif (\"error\" in preview) {\n\t\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t\t}\n\t\treturn (text: string) => theme.bg(\"toolSuccessBg\", text);\n\t}\n\tif (settledError) {\n\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t}\n\treturn (text: string) => theme.bg(\"toolPendingBg\", text);\n}\n\nfunction buildEditCallComponent(\n\tcomponent: EditCallRenderComponent,\n\targs: RenderableEditArgs | undefined,\n\ttheme: Theme,\n\tcwd: string,\n): EditCallRenderComponent {\n\tcomponent.setBgFn(getEditHeaderBg(component.preview, component.settledError, theme));\n\tcomponent.clear();\n\tcomponent.addChild(new Text(formatEditCall(args, theme, cwd), 0, 0));\n\n\tif (!component.preview) {\n\t\treturn component;\n\t}\n\n\tconst body =\n\t\t\"error\" in component.preview ? theme.fg(\"error\", component.preview.error) : renderDiff(component.preview.diff);\n\tcomponent.addChild(new Spacer(1));\n\tcomponent.addChild(new Text(body, 0, 0));\n\treturn component;\n}\n\nfunction setEditPreview(component: EditCallRenderComponent, preview: EditPreview): boolean {\n\tconst current = component.preview;\n\tconst changed =\n\t\tcurrent === undefined ||\n\t\t(\"error\" in current && \"error\" in preview\n\t\t\t? current.error !== preview.error\n\t\t\t: \"error\" in current !== \"error\" in preview) ||\n\t\t(!(\"error\" in current) &&\n\t\t\t!(\"error\" in preview) &&\n\t\t\t(current.diff !== preview.diff || current.firstChangedLine !== preview.firstChangedLine));\n\tcomponent.preview = preview;\n\tcomponent.previewPending = false;\n\treturn changed;\n}\n\nexport function createEditToolDefinition(\n\tcwd: string,\n\toptions?: EditToolOptions,\n): ToolDefinition<typeof editSchema, EditToolDetails | undefined, EditRenderState> {\n\tconst ops = options?.operations ?? defaultEditOperations;\n\tif (options?.operations && !options.intentController) {\n\t\tthrow new Error(\"Custom edit operations require a matching file mutation intent controller.\");\n\t}\n\tconst intentController = options?.intentController ?? new FileMutationIntentController();\n\tlet cachedMatchPlan: CachedEditMatchPlan | undefined;\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit existing UTF-8 text in one call. Send path and all edits; after a path-only failure, reuse the returned payloadRef with only the corrected path. The harness preflights, revalidates, and stale-checks every exact replacement.\",\n\t\tpromptSnippet: \"Preflight existing files; apply exact, stale-safe edits\",\n\t\tpromptGuidelines: [\n\t\t\t\"Call edit once with path and all replacements; preparation and stale-target checks are harness-owned.\",\n\t\t\t\"If a path failure returns payloadRef, choose the correct existing path and reuse that reference instead of regenerating edits.\",\n\t\t\t\"oldText is exact, unique, minimal, and original-file based; pass the inclusive line range from the supplying read when known, batch separate edits, and merge overlaps.\",\n\t\t],\n\t\tparameters: editSchema,\n\t\trenderShell: \"self\",\n\t\tprepareArguments: prepareEditArguments,\n\t\tasync execute(_toolCallId, input: EditToolInput, signal?: AbortSignal, _onUpdate?, _ctx?) {\n\t\t\tconst validated = validateEditInput(input);\n\t\t\tconst { path } = validated;\n\t\t\tconst absolutePath = resolveToCwd(path, cwd);\n\t\t\tlet lease: FileMutationLease;\n\t\t\ttry {\n\t\t\t\tlease = await intentController.prepare(\"edit\", absolutePath, signal, path);\n\t\t\t} catch (error) {\n\t\t\t\tif (\n\t\t\t\t\terror instanceof FileMutationPreflightError &&\n\t\t\t\t\t(error.reason === \"edit_missing\" || error.reason === \"edit_not_file\")\n\t\t\t\t) {\n\t\t\t\t\tthrow await editPathFailureWithRetainedPayload(error, validated, intentController, signal);\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\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\tlet payloadRef: string | undefined;\n\t\t\t\tlet edits: Edit[];\n\t\t\t\tif (validated.edits !== undefined) {\n\t\t\t\t\tedits = validated.edits;\n\t\t\t\t} else {\n\t\t\t\t\tpayloadRef = validated.payloadRef;\n\t\t\t\t\tedits = validateEdits(\n\t\t\t\t\t\tJSON.parse(await intentController.readMutationPayload(payloadRef, \"edit\", signal)),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tawait intentController.assertCurrent(lease, signal);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Read the file.\n\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\tif (!isValidUTF8(buffer)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`PI_FILE_ENCODING_CORRUPTION: ${path} is not valid UTF-8 text; exact text replacement is unsafe and could corrupt its bytes.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst rawContent = buffer.toString(\"utf-8\");\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Strip BOM before matching. The model will not include an invisible BOM in oldText.\n\t\t\t\tconst { bom, text: content } = stripBom(rawContent);\n\t\t\t\tconst originalEnding = detectLineEnding(content);\n\t\t\t\tconst normalizedContent = normalizeToLF(content);\n\t\t\t\tconst cachedForInput =\n\t\t\t\t\tcachedMatchPlan?.absolutePath === absolutePath && editsMatch(cachedMatchPlan.edits, edits)\n\t\t\t\t\t\t? cachedMatchPlan\n\t\t\t\t\t\t: undefined;\n\t\t\t\tif (cachedForInput) cachedMatchPlan = undefined;\n\t\t\t\tconst matchPlanReused =\n\t\t\t\t\tcachedForInput !== undefined &&\n\t\t\t\t\tcachedForInput.sourceDigest === digestNormalizedEditSource(normalizedContent);\n\t\t\t\tconst { baseContent, newContent } = matchPlanReused\n\t\t\t\t\t? applyEditMatchPlan(normalizedContent, cachedForInput.plan, path)\n\t\t\t\t\t: applyEditsToNormalizedContent(normalizedContent, edits, path);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst finalContent = bom + restoreLineEndings(newContent, originalEnding);\n\t\t\t\tawait intentController.assertCurrent(lease, signal);\n\t\t\t\tthrowIfAborted();\n\t\t\t\tawait ops.writeFile(absolutePath, finalContent);\n\t\t\t\tthrowIfAborted();\n\t\t\t\tconst contentReference = intentController.rememberContent(absolutePath, finalContent);\n\t\t\t\tif (payloadRef) await intentController.discardMutationPayload(payloadRef);\n\n\t\t\t\tconst diffResult = matchPlanReused\n\t\t\t\t\t? { diff: cachedForInput.diff, firstChangedLine: cachedForInput.firstChangedLine }\n\t\t\t\t\t: generateDiffString(baseContent, newContent);\n\t\t\t\tconst patch = generateUnifiedPatch(path, baseContent, newContent);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `Successfully replaced ${edits.length} block(s) in ${path}; this edit is complete, so do not call edit again for this path. To copy these exact bytes to a different new path, call write once for that path with contentRef ${contentReference.contentRef}.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tphase: \"edited\" as const,\n\t\t\t\t\t\tcontentRef: contentReference.contentRef,\n\t\t\t\t\t\tdiff: diffResult.diff,\n\t\t\t\t\t\tpatch,\n\t\t\t\t\t\tfirstChangedLine: diffResult.firstChangedLine,\n\t\t\t\t\t\tmatchPlanReused,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst component = getEditCallRenderComponent(context.state, context.lastComponent);\n\t\t\tconst previewInput = getRenderablePreviewInput(args as RenderableEditArgs | undefined);\n\n\t\t\tif ((!context.argsComplete || !previewInput) && (component.preview || component.previewPending)) {\n\t\t\t\tcomponent.preview = undefined;\n\t\t\t\tcomponent.previewPending = false;\n\t\t\t\tcomponent.settledError = false;\n\t\t\t\tcomponent.previewRequestId++;\n\t\t\t}\n\n\t\t\tif (context.argsComplete && previewInput && !component.preview && !component.previewPending) {\n\t\t\t\tcomponent.previewPending = true;\n\t\t\t\tconst requestId = ++component.previewRequestId;\n\t\t\t\tvoid computeEditsPlannedDiff(previewInput.path, previewInput.edits, context.cwd).then((preview) => {\n\t\t\t\t\tif (component.previewRequestId === requestId) {\n\t\t\t\t\t\tif (!(\"error\" in preview) && !options?.operations) {\n\t\t\t\t\t\t\tcachedMatchPlan = {\n\t\t\t\t\t\t\t\tabsolutePath: resolveToCwd(previewInput.path, context.cwd),\n\t\t\t\t\t\t\t\tedits: snapshotEdits(previewInput.edits),\n\t\t\t\t\t\t\t\tplan: preview.plan,\n\t\t\t\t\t\t\t\tsourceDigest: preview.sourceDigest,\n\t\t\t\t\t\t\t\tdiff: preview.diff,\n\t\t\t\t\t\t\t\tfirstChangedLine: preview.firstChangedLine,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsetEditPreview(component, preview);\n\t\t\t\t\t\tcontext.invalidate();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn buildEditCallComponent(component, args, theme, context.cwd);\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst callComponent = context.state.callComponent;\n\t\t\tconst typedResult = result as EditToolResultLike;\n\t\t\tconst resultDiff = !context.isError ? typedResult.details?.diff : undefined;\n\t\t\tlet changed = false;\n\t\t\tif (callComponent) {\n\t\t\t\tcallComponent.previewRequestId++;\n\t\t\t\tif (typeof resultDiff === \"string\") {\n\t\t\t\t\tchanged =\n\t\t\t\t\t\tsetEditPreview(callComponent, {\n\t\t\t\t\t\t\tdiff: resultDiff,\n\t\t\t\t\t\t\tfirstChangedLine: typedResult.details?.firstChangedLine,\n\t\t\t\t\t\t}) || changed;\n\t\t\t\t}\n\t\t\t\tif (callComponent.settledError !== context.isError) {\n\t\t\t\t\tcallComponent.settledError = context.isError;\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t\tif (changed) {\n\t\t\t\t\tbuildEditCallComponent(\n\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\tcontext.args as RenderableEditArgs | undefined,\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t\tcontext.cwd,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst output = formatEditResult(context.args, callComponent?.preview, typedResult, theme, context.isError);\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\tif (!output) {\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(output, 1, 0));\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema> {\n\treturn wrapToolDefinition(createEditToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,uCAAuC,EAAE,MAAM,2BAA2B,CAAC;AACpG,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAGxE,OAAO,EACN,kBAAk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GAAG,gBAAgB,CAAC,OAAO,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;YAC3G,MAAM,SAAS,GAAI,OAAO,CAAC,aAAuC,IAAI,IAAI,SAAS,EAAE,CAAC;YACtF,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,IAAI,CAAC,MAAM,EAAE,CAAC;gBACb,OAAO,SAAS,CAAC;YAClB,CAAC;YACD,SAAS,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAClC,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC3C,OAAO,SAAS,CAAC;QAClB,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB;IACpE,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { type AgentTool, createAgentToolFailureRecoveryAuthority } from \"@caupulican/pi-agent-core\";\nimport { Box, Container, Spacer, Text } from \"@caupulican/pi-tui\";\nimport { readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { renderDiff } from \"../../modes/interactive/components/diff.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\tapplyEditMatchPlan,\n\tapplyEditsToNormalizedContent,\n\tcomputeEditsPlannedDiff,\n\tdetectLineEnding,\n\tdigestNormalizedEditSource,\n\ttype Edit,\n\ttype EditDiffError,\n\ttype EditDiffResult,\n\ttype EditMatchPlan,\n\tgenerateDiffString,\n\tgenerateUnifiedPatch,\n\tnormalizeToLF,\n\trestoreLineEndings,\n\tstripBom,\n} from \"./edit-diff.ts\";\nimport { isValidUTF8 } from \"./file-encoding-policy.ts\";\nimport {\n\tEDIT_RETARGET_RECOVERY_TARGET_KIND,\n\tFILE_CURRENT_TEXT_RECOVERY_TARGET_KIND,\n\ttype FileFailureRecoveryAuthority,\n\tfileRecoveryTarget,\n\tselectFileFailureRecoveryAuthority,\n} from \"./file-failure-recovery.ts\";\nimport {\n\tFileMutationIntentController,\n\ttype FileMutationLease,\n\tFileMutationPreflightError,\n} from \"./file-mutation-intent.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { renderToolPath, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\ntype EditPreview = EditDiffResult | EditDiffError;\n\ntype EditRenderState = {\n\tcallComponent?: EditCallRenderComponent;\n};\n\nconst replaceEditSchema = Type.Object(\n\t{\n\t\toldText: Type.String({ minLength: 1 }),\n\t\tnewText: Type.String(),\n\t\trange: Type.Optional(\n\t\t\tType.Object(\n\t\t\t\t{\n\t\t\t\t\tstartLine: Type.Integer({ minimum: 1 }),\n\t\t\t\t\tendLine: Type.Integer({ minimum: 1 }),\n\t\t\t\t},\n\t\t\t\t{ additionalProperties: false },\n\t\t\t),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nconst editPathSchema = Type.String({ minLength: 1 });\nconst editSchema = Type.Union([\n\tType.Object(\n\t\t{\n\t\t\tpath: editPathSchema,\n\t\t\tedits: Type.Array(replaceEditSchema, {\n\t\t\t\tminItems: 1,\n\t\t\t}),\n\t\t},\n\t\t{ additionalProperties: false },\n\t),\n\tType.Object(\n\t\t{\n\t\t\tpath: editPathSchema,\n\t\t\tpayloadRef: Type.String({ minLength: 1 }),\n\t\t},\n\t\t{ additionalProperties: false },\n\t),\n]);\n\nexport type EditToolInput = Static<typeof editSchema>;\ntype LegacyEditToolInput = {\n\tpath?: unknown;\n\tedits?: unknown;\n\tpayloadRef?: unknown;\n\toldText?: unknown;\n\tnewText?: unknown;\n};\n\nexport interface EditToolDetails {\n\tphase: \"edited\";\n\tcontentRef?: string;\n\t/** Display-oriented diff of the changes made */\n\tdiff?: string;\n\t/** Standard unified patch of the changes made */\n\tpatch?: string;\n\t/** Line number of the first change in the new file (for editor navigation) */\n\tfirstChangedLine?: number;\n\t/** True when execution reused the match plan already validated for the call preview. */\n\tmatchPlanReused?: boolean;\n}\n\n/**\n * Pluggable operations for the edit tool.\n * Override these to delegate file editing to remote systems (for example SSH).\n */\nexport interface EditOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n}\n\nconst defaultEditOperations: EditOperations = {\n\treadFile: (path) => fsReadFile(path),\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n};\n\nexport interface EditToolOptions {\n\t/** Custom operations for file editing. Default: local filesystem */\n\toperations?: EditOperations;\n\t/** Shared backend identity for exact cross-tool recovery with custom operations. */\n\tfailureRecoveryAuthority?: FileFailureRecoveryAuthority;\n\t/** Session-owned harness preflight and exact-content-reference authority. */\n\tintentController?: FileMutationIntentController;\n}\n\nfunction prepareEditArguments(input: unknown): EditToolInput {\n\tif (!input || typeof input !== \"object\" || Array.isArray(input)) {\n\t\treturn input as EditToolInput;\n\t}\n\n\tlet args = input as Record<string, unknown>;\n\n\tconst legacy = args as LegacyEditToolInput;\n\tif (typeof legacy.oldText === \"string\" && typeof legacy.newText === \"string\") {\n\t\tconst edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];\n\t\tedits.push({ oldText: legacy.oldText, newText: legacy.newText });\n\t\tconst { oldText: _oldText, newText: _newText, ...rest } = legacy;\n\t\targs = { ...rest, edits };\n\t}\n\n\treturn args as EditToolInput;\n}\n\nfunction validateEdits(edits: unknown): Edit[] {\n\tif (!Array.isArray(edits) || edits.length === 0) {\n\t\tthrow new Error(\"Edit tool input is invalid. edits must contain at least one replacement.\");\n\t}\n\tfor (const edit of edits) {\n\t\tif (\n\t\t\ttypeof edit !== \"object\" ||\n\t\t\tedit === null ||\n\t\t\ttypeof edit.oldText !== \"string\" ||\n\t\t\ttypeof edit.newText !== \"string\"\n\t\t) {\n\t\t\tthrow new Error(\"Edit tool input is invalid. Every edit requires string oldText and newText fields.\");\n\t\t}\n\t}\n\treturn edits as Edit[];\n}\n\nfunction validateEditInput(\n\tinput: EditToolInput,\n): { path: string; edits: Edit[]; payloadRef?: undefined } | { path: string; edits?: undefined; payloadRef: string } {\n\tif (\"payloadRef\" in input) return { path: input.path, payloadRef: input.payloadRef };\n\treturn { path: input.path, edits: validateEdits(input.edits) };\n}\n\ntype RenderableEditArgs = {\n\tpath?: string;\n\tfile_path?: string;\n\tedits?: Edit[];\n\tpayloadRef?: string;\n\toldText?: string;\n\tnewText?: string;\n};\n\ntype EditToolResultLike = {\n\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\tdetails?: EditToolDetails;\n};\n\ntype EditCallRenderComponent = Box & {\n\tpreview?: EditPreview;\n\tpreviewRequestId: number;\n\tpreviewPending?: boolean;\n\tsettledError?: boolean;\n};\n\nfunction createEditCallRenderComponent(): EditCallRenderComponent {\n\treturn Object.assign(new Box(1, 1, (text: string) => text), {\n\t\tpreview: undefined as EditPreview | undefined,\n\t\tpreviewRequestId: 0,\n\t\tpreviewPending: false,\n\t\tsettledError: false,\n\t});\n}\n\nfunction getEditCallRenderComponent(state: EditRenderState, lastComponent: unknown): EditCallRenderComponent {\n\tif (lastComponent instanceof Box) {\n\t\tconst component = lastComponent as EditCallRenderComponent;\n\t\tstate.callComponent = component;\n\t\treturn component;\n\t}\n\tif (state.callComponent) {\n\t\treturn state.callComponent;\n\t}\n\tconst component = createEditCallRenderComponent();\n\tstate.callComponent = component;\n\treturn component;\n}\n\nfunction getRenderablePreviewInput(args: RenderableEditArgs | undefined): { path: string; edits: Edit[] } | null {\n\tif (!args) {\n\t\treturn null;\n\t}\n\n\tconst path = typeof args.path === \"string\" ? args.path : typeof args.file_path === \"string\" ? args.file_path : null;\n\tif (!path) {\n\t\treturn null;\n\t}\n\n\tif (\n\t\tArray.isArray(args.edits) &&\n\t\targs.edits.length > 0 &&\n\t\targs.edits.every((edit) => typeof edit?.oldText === \"string\" && typeof edit?.newText === \"string\")\n\t) {\n\t\treturn { path, edits: args.edits };\n\t}\n\n\tif (typeof args.oldText === \"string\" && typeof args.newText === \"string\") {\n\t\treturn { path, edits: [{ oldText: args.oldText, newText: args.newText }] };\n\t}\n\n\treturn null;\n}\n\ninterface CachedEditMatchPlan {\n\tabsolutePath: string;\n\tedits: Edit[];\n\tplan: EditMatchPlan;\n\tsourceDigest: string;\n\tdiff: string;\n\tfirstChangedLine: number | undefined;\n}\n\nfunction snapshotEdits(edits: Edit[]): Edit[] {\n\treturn edits.map((edit) => ({\n\t\toldText: edit.oldText,\n\t\tnewText: edit.newText,\n\t\t...(edit.range ? { range: { startLine: edit.range.startLine, endLine: edit.range.endLine } } : {}),\n\t}));\n}\n\nfunction editsMatch(left: Edit[], right: Edit[]): boolean {\n\tif (left.length !== right.length) return false;\n\tfor (let index = 0; index < left.length; index++) {\n\t\tconst leftEdit = left[index];\n\t\tconst rightEdit = right[index];\n\t\tif (\n\t\t\tleftEdit.oldText !== rightEdit.oldText ||\n\t\t\tleftEdit.newText !== rightEdit.newText ||\n\t\t\tleftEdit.range?.startLine !== rightEdit.range?.startLine ||\n\t\t\tleftEdit.range?.endLine !== rightEdit.range?.endLine\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction formatEditCall(args: RenderableEditArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nfunction formatEditResult(\n\targs: RenderableEditArgs | undefined,\n\tpreview: EditPreview | undefined,\n\tresult: EditToolResultLike,\n\ttheme: Theme,\n\tisError: boolean,\n): string | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst previewDiff = preview && !(\"error\" in preview) ? preview.diff : undefined;\n\tconst previewError = preview && \"error\" in preview ? preview.error : undefined;\n\tif (isError) {\n\t\tconst errorText = result.content\n\t\t\t.filter((c) => c.type === \"text\")\n\t\t\t.map((c) => c.text || \"\")\n\t\t\t.join(\"\\n\");\n\t\tif (!errorText || errorText === previewError) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn theme.fg(\"error\", errorText);\n\t}\n\n\tconst resultDiff = result.details?.diff;\n\tif (resultDiff && resultDiff !== previewDiff) {\n\t\treturn renderDiff(resultDiff, { filePath: rawPath ?? undefined });\n\t}\n\n\treturn undefined;\n}\n\nasync function editPathFailureWithRetainedPayload(\n\terror: FileMutationPreflightError,\n\tvalidated:\n\t\t| { path: string; edits: Edit[]; payloadRef?: undefined }\n\t\t| { path: string; edits?: undefined; payloadRef: string },\n\tintentController: FileMutationIntentController,\n\tsignal?: AbortSignal,\n): Promise<Error> {\n\tconst failureIdentity = error.reason === \"edit_missing\" ? \"edit_missing (ENOENT)\" : \"edit_not_file\";\n\tif (validated.payloadRef) {\n\t\tawait intentController.assertMutationPayload(validated.payloadRef, \"edit\", signal);\n\t\treturn new Error(\n\t\t\t`PI_FILE_MUTATION_RETARGET ${failureIdentity}: payloadRef ${validated.payloadRef}. Choose only a corrected path naming an existing file; the exact valid edit payload is retained for full revalidation.`,\n\t\t);\n\t}\n\n\ttry {\n\t\tconst retained = await intentController.retainMutationPayload(\"edit\", JSON.stringify(validated.edits));\n\t\tif (retained) {\n\t\t\treturn new Error(\n\t\t\t\t`PI_FILE_MUTATION_RETARGET ${failureIdentity}: payloadRef ${retained.payloadRef}. Choose only a corrected path naming an existing file; the exact valid edit payload is retained for full revalidation.`,\n\t\t\t);\n\t\t}\n\t} catch {\n\t\t// The path failure remains authoritative when the bounded retry cache is unavailable.\n\t}\n\treturn new Error(`${error.message} The edit payload could not be retained within the secure retry-cache bound.`);\n}\n\nfunction getEditHeaderBg(\n\tpreview: EditPreview | undefined,\n\tsettledError: boolean | undefined,\n\ttheme: Theme,\n): (text: string) => string {\n\tif (preview) {\n\t\tif (\"error\" in preview) {\n\t\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t\t}\n\t\treturn (text: string) => theme.bg(\"toolSuccessBg\", text);\n\t}\n\tif (settledError) {\n\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t}\n\treturn (text: string) => theme.bg(\"toolPendingBg\", text);\n}\n\nfunction buildEditCallComponent(\n\tcomponent: EditCallRenderComponent,\n\targs: RenderableEditArgs | undefined,\n\ttheme: Theme,\n\tcwd: string,\n): EditCallRenderComponent {\n\tcomponent.setBgFn(getEditHeaderBg(component.preview, component.settledError, theme));\n\tcomponent.clear();\n\tcomponent.addChild(new Text(formatEditCall(args, theme, cwd), 0, 0));\n\n\tif (!component.preview) {\n\t\treturn component;\n\t}\n\n\tconst body =\n\t\t\"error\" in component.preview ? theme.fg(\"error\", component.preview.error) : renderDiff(component.preview.diff);\n\tcomponent.addChild(new Spacer(1));\n\tcomponent.addChild(new Text(body, 0, 0));\n\treturn component;\n}\n\nfunction setEditPreview(component: EditCallRenderComponent, preview: EditPreview): boolean {\n\tconst current = component.preview;\n\tconst changed =\n\t\tcurrent === undefined ||\n\t\t(\"error\" in current && \"error\" in preview\n\t\t\t? current.error !== preview.error\n\t\t\t: \"error\" in current !== \"error\" in preview) ||\n\t\t(!(\"error\" in current) &&\n\t\t\t!(\"error\" in preview) &&\n\t\t\t(current.diff !== preview.diff || current.firstChangedLine !== preview.firstChangedLine));\n\tcomponent.preview = preview;\n\tcomponent.previewPending = false;\n\treturn changed;\n}\n\nexport function createEditToolDefinition(\n\tcwd: string,\n\toptions?: EditToolOptions,\n): ToolDefinition<typeof editSchema, EditToolDetails | undefined, EditRenderState> {\n\tconst ops = options?.operations ?? defaultEditOperations;\n\tconst failureRecoveryAuthority = selectFileFailureRecoveryAuthority(\n\t\toptions?.operations !== undefined,\n\t\toptions?.failureRecoveryAuthority,\n\t);\n\tif (options?.operations && !options.intentController) {\n\t\tthrow new Error(\"Custom edit operations require a matching file mutation intent controller.\");\n\t}\n\tconst intentController = options?.intentController ?? new FileMutationIntentController();\n\tconst retargetRecoveryAuthority = createAgentToolFailureRecoveryAuthority();\n\tlet cachedMatchPlan: CachedEditMatchPlan | undefined;\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit existing UTF-8 text in one call. Send path and all edits; after a path-only failure, reuse the returned payloadRef with only the corrected path. The harness preflights, revalidates, and stale-checks every exact replacement.\",\n\t\tpromptSnippet: \"Preflight existing files; apply exact, stale-safe edits\",\n\t\tpromptGuidelines: [\n\t\t\t\"Call edit once with path and all replacements; preparation and stale-target checks are harness-owned.\",\n\t\t\t\"If a path failure returns payloadRef, choose the correct existing path and reuse that reference instead of regenerating edits.\",\n\t\t\t\"oldText is exact, unique, minimal, and original-file based; pass the inclusive line range from the supplying read when known, batch separate edits, and merge overlaps.\",\n\t\t],\n\t\tparameters: editSchema,\n\t\trenderShell: \"self\",\n\t\tprepareArguments: prepareEditArguments,\n\t\tfailureRecovery: {\n\t\t\tgetFailureTargets: (params, failure) => {\n\t\t\t\tif (failure.failureCode === \"mutation_retarget_required\") {\n\t\t\t\t\treturn [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tauthority: retargetRecoveryAuthority,\n\t\t\t\t\t\t\tkind: EDIT_RETARGET_RECOVERY_TARGET_KIND,\n\t\t\t\t\t\t\tscope: resolveToCwd(params.path, cwd),\n\t\t\t\t\t\t},\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\tif (failure.failureCode === \"edit_old_text_not_found\" && failureRecoveryAuthority) {\n\t\t\t\t\treturn [\n\t\t\t\t\t\tfileRecoveryTarget(\n\t\t\t\t\t\t\tfailureRecoveryAuthority,\n\t\t\t\t\t\t\tFILE_CURRENT_TEXT_RECOVERY_TARGET_KIND,\n\t\t\t\t\t\t\tparams.path,\n\t\t\t\t\t\t\tcwd,\n\t\t\t\t\t\t),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\treturn [];\n\t\t\t},\n\t\t\tactions: [\n\t\t\t\t{\n\t\t\t\t\tkind: \"correct\",\n\t\t\t\t\tauthority: retargetRecoveryAuthority,\n\t\t\t\t\ttargetKind: EDIT_RETARGET_RECOVERY_TARGET_KIND,\n\t\t\t\t\tinstruction:\n\t\t\t\t\t\t\"Use edit with the retained payloadRef and a corrected path naming the intended existing file.\",\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\tasync execute(_toolCallId, input: EditToolInput, signal?: AbortSignal, _onUpdate?, _ctx?) {\n\t\t\tconst validated = validateEditInput(input);\n\t\t\tconst { path } = validated;\n\t\t\tconst absolutePath = resolveToCwd(path, cwd);\n\t\t\tlet lease: FileMutationLease;\n\t\t\ttry {\n\t\t\t\tlease = await intentController.prepare(\"edit\", absolutePath, signal, path);\n\t\t\t} catch (error) {\n\t\t\t\tif (\n\t\t\t\t\terror instanceof FileMutationPreflightError &&\n\t\t\t\t\t(error.reason === \"edit_missing\" || error.reason === \"edit_not_file\")\n\t\t\t\t) {\n\t\t\t\t\tthrow await editPathFailureWithRetainedPayload(error, validated, intentController, signal);\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\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\tlet payloadRef: string | undefined;\n\t\t\t\tlet edits: Edit[];\n\t\t\t\tif (validated.edits !== undefined) {\n\t\t\t\t\tedits = validated.edits;\n\t\t\t\t} else {\n\t\t\t\t\tpayloadRef = validated.payloadRef;\n\t\t\t\t\tedits = validateEdits(\n\t\t\t\t\t\tJSON.parse(await intentController.readMutationPayload(payloadRef, \"edit\", signal)),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tawait intentController.assertCurrent(lease, signal);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Read the file.\n\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\tif (!isValidUTF8(buffer)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`PI_FILE_ENCODING_CORRUPTION: ${path} is not valid UTF-8 text; exact text replacement is unsafe and could corrupt its bytes.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst rawContent = buffer.toString(\"utf-8\");\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Strip BOM before matching. The model will not include an invisible BOM in oldText.\n\t\t\t\tconst { bom, text: content } = stripBom(rawContent);\n\t\t\t\tconst originalEnding = detectLineEnding(content);\n\t\t\t\tconst normalizedContent = normalizeToLF(content);\n\t\t\t\tconst cachedForInput =\n\t\t\t\t\tcachedMatchPlan?.absolutePath === absolutePath && editsMatch(cachedMatchPlan.edits, edits)\n\t\t\t\t\t\t? cachedMatchPlan\n\t\t\t\t\t\t: undefined;\n\t\t\t\tif (cachedForInput) cachedMatchPlan = undefined;\n\t\t\t\tconst matchPlanReused =\n\t\t\t\t\tcachedForInput !== undefined &&\n\t\t\t\t\tcachedForInput.sourceDigest === digestNormalizedEditSource(normalizedContent);\n\t\t\t\tconst { baseContent, newContent } = matchPlanReused\n\t\t\t\t\t? applyEditMatchPlan(normalizedContent, cachedForInput.plan, path)\n\t\t\t\t\t: applyEditsToNormalizedContent(normalizedContent, edits, path);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst finalContent = bom + restoreLineEndings(newContent, originalEnding);\n\t\t\t\tawait intentController.assertCurrent(lease, signal);\n\t\t\t\tthrowIfAborted();\n\t\t\t\tawait ops.writeFile(absolutePath, finalContent);\n\t\t\t\tthrowIfAborted();\n\t\t\t\tconst contentReference = intentController.rememberContent(absolutePath, finalContent);\n\t\t\t\tif (payloadRef) await intentController.discardMutationPayload(payloadRef);\n\n\t\t\t\tconst diffResult = matchPlanReused\n\t\t\t\t\t? { diff: cachedForInput.diff, firstChangedLine: cachedForInput.firstChangedLine }\n\t\t\t\t\t: generateDiffString(baseContent, newContent);\n\t\t\t\tconst patch = generateUnifiedPatch(path, baseContent, newContent);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `Successfully replaced ${edits.length} block(s) in ${path}; this edit is complete, so do not call edit again for this path. To copy these exact bytes to a different new path, call write once for that path with contentRef ${contentReference.contentRef}.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tphase: \"edited\" as const,\n\t\t\t\t\t\tcontentRef: contentReference.contentRef,\n\t\t\t\t\t\tdiff: diffResult.diff,\n\t\t\t\t\t\tpatch,\n\t\t\t\t\t\tfirstChangedLine: diffResult.firstChangedLine,\n\t\t\t\t\t\tmatchPlanReused,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst component = getEditCallRenderComponent(context.state, context.lastComponent);\n\t\t\tconst previewInput = getRenderablePreviewInput(args as RenderableEditArgs | undefined);\n\n\t\t\tif ((!context.argsComplete || !previewInput) && (component.preview || component.previewPending)) {\n\t\t\t\tcomponent.preview = undefined;\n\t\t\t\tcomponent.previewPending = false;\n\t\t\t\tcomponent.settledError = false;\n\t\t\t\tcomponent.previewRequestId++;\n\t\t\t}\n\n\t\t\tif (context.argsComplete && previewInput && !component.preview && !component.previewPending) {\n\t\t\t\tcomponent.previewPending = true;\n\t\t\t\tconst requestId = ++component.previewRequestId;\n\t\t\t\tvoid computeEditsPlannedDiff(previewInput.path, previewInput.edits, context.cwd).then((preview) => {\n\t\t\t\t\tif (component.previewRequestId === requestId) {\n\t\t\t\t\t\tif (!(\"error\" in preview) && !options?.operations) {\n\t\t\t\t\t\t\tcachedMatchPlan = {\n\t\t\t\t\t\t\t\tabsolutePath: resolveToCwd(previewInput.path, context.cwd),\n\t\t\t\t\t\t\t\tedits: snapshotEdits(previewInput.edits),\n\t\t\t\t\t\t\t\tplan: preview.plan,\n\t\t\t\t\t\t\t\tsourceDigest: preview.sourceDigest,\n\t\t\t\t\t\t\t\tdiff: preview.diff,\n\t\t\t\t\t\t\t\tfirstChangedLine: preview.firstChangedLine,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsetEditPreview(component, preview);\n\t\t\t\t\t\tcontext.invalidate();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn buildEditCallComponent(component, args, theme, context.cwd);\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst callComponent = context.state.callComponent;\n\t\t\tconst typedResult = result as EditToolResultLike;\n\t\t\tconst resultDiff = !context.isError ? typedResult.details?.diff : undefined;\n\t\t\tlet changed = false;\n\t\t\tif (callComponent) {\n\t\t\t\tcallComponent.previewRequestId++;\n\t\t\t\tif (typeof resultDiff === \"string\") {\n\t\t\t\t\tchanged =\n\t\t\t\t\t\tsetEditPreview(callComponent, {\n\t\t\t\t\t\t\tdiff: resultDiff,\n\t\t\t\t\t\t\tfirstChangedLine: typedResult.details?.firstChangedLine,\n\t\t\t\t\t\t}) || changed;\n\t\t\t\t}\n\t\t\t\tif (callComponent.settledError !== context.isError) {\n\t\t\t\t\tcallComponent.settledError = context.isError;\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t\tif (changed) {\n\t\t\t\t\tbuildEditCallComponent(\n\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\tcontext.args as RenderableEditArgs | undefined,\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t\tcontext.cwd,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst output = formatEditResult(context.args, callComponent?.preview, typedResult, theme, context.isError);\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\tif (!output) {\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(output, 1, 0));\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema> {\n\treturn wrapToolDefinition(createEditToolDefinition(cwd, options));\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import { type AgentToolFailureRecoveryAuthority, type AgentToolFailureRecoveryTarget } from "@caupulican/pi-agent-core";
2
+ export declare const FILE_EXISTS_RECOVERY_TARGET_KIND = "filesystem.file.exists";
3
+ export declare const FILE_CURRENT_TEXT_RECOVERY_TARGET_KIND = "filesystem.file.current-text";
4
+ export declare const WRITE_RETARGET_RECOVERY_TARGET_KIND = "filesystem.write.retarget";
5
+ export declare const EDIT_RETARGET_RECOVERY_TARGET_KIND = "filesystem.edit.retarget";
6
+ export interface FileFailureRecoveryAuthority {
7
+ /** Exact backend identity shared by cooperating tool contracts. */
8
+ readonly contractAuthority: AgentToolFailureRecoveryAuthority;
9
+ /** Pure canonical identity for a path already resolved against the tool cwd. */
10
+ getScope: (absolutePath: string) => string;
11
+ }
12
+ /** Create one backend authority and pass the same instance to every cooperating custom file tool. */
13
+ export declare function createFileFailureRecoveryAuthority(getScope: (absolutePath: string) => string): FileFailureRecoveryAuthority;
14
+ export declare function selectFileFailureRecoveryAuthority(usesCustomOperations: boolean, explicitAuthority: FileFailureRecoveryAuthority | undefined): FileFailureRecoveryAuthority | undefined;
15
+ export declare function fileRecoveryScope(authority: FileFailureRecoveryAuthority, path: string, cwd: string): string;
16
+ export declare function fileRecoveryTarget(authority: FileFailureRecoveryAuthority, kind: string, path: string, cwd: string): AgentToolFailureRecoveryTarget;
17
+ //# sourceMappingURL=file-failure-recovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-failure-recovery.d.ts","sourceRoot":"","sources":["../../../src/core/tools/file-failure-recovery.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,KAAK,iCAAiC,EACtC,KAAK,8BAA8B,EAEnC,MAAM,2BAA2B,CAAC;AAGnC,eAAO,MAAM,gCAAgC,2BAA2B,CAAC;AACzE,eAAO,MAAM,sCAAsC,iCAAiC,CAAC;AACrF,eAAO,MAAM,mCAAmC,8BAA8B,CAAC;AAC/E,eAAO,MAAM,kCAAkC,6BAA6B,CAAC;AAE7E,MAAM,WAAW,4BAA4B;IAC5C,mEAAmE;IACnE,QAAQ,CAAC,iBAAiB,EAAE,iCAAiC,CAAC;IAC9D,gFAAgF;IAChF,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C;AAED,qGAAqG;AACrG,wBAAgB,kCAAkC,CACjD,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,GACxC,4BAA4B,CAE9B;AAmBD,wBAAgB,kCAAkC,CACjD,oBAAoB,EAAE,OAAO,EAC7B,iBAAiB,EAAE,4BAA4B,GAAG,SAAS,GACzD,4BAA4B,GAAG,SAAS,CAE1C;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,4BAA4B,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAE5G;AAED,wBAAgB,kBAAkB,CACjC,SAAS,EAAE,4BAA4B,EACvC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,GACT,8BAA8B,CAMhC"}
@@ -0,0 +1,43 @@
1
+ import { realpathSync } from "node:fs";
2
+ import { basename, dirname, resolve } from "node:path";
3
+ import { createAgentToolFailureRecoveryAuthority, } from "@caupulican/pi-agent-core";
4
+ import { resolveToCwd } from "./path-utils.js";
5
+ export const FILE_EXISTS_RECOVERY_TARGET_KIND = "filesystem.file.exists";
6
+ export const FILE_CURRENT_TEXT_RECOVERY_TARGET_KIND = "filesystem.file.current-text";
7
+ export const WRITE_RETARGET_RECOVERY_TARGET_KIND = "filesystem.write.retarget";
8
+ export const EDIT_RETARGET_RECOVERY_TARGET_KIND = "filesystem.edit.retarget";
9
+ /** Create one backend authority and pass the same instance to every cooperating custom file tool. */
10
+ export function createFileFailureRecoveryAuthority(getScope) {
11
+ return Object.freeze({ contractAuthority: createAgentToolFailureRecoveryAuthority(), getScope });
12
+ }
13
+ function canonicalizeLocalPath(absolutePath) {
14
+ let existingAncestor = absolutePath;
15
+ const missingSegments = [];
16
+ while (true) {
17
+ try {
18
+ return resolve(realpathSync.native(existingAncestor), ...missingSegments.reverse());
19
+ }
20
+ catch {
21
+ const parent = dirname(existingAncestor);
22
+ if (parent === existingAncestor)
23
+ return absolutePath;
24
+ missingSegments.push(basename(existingAncestor));
25
+ existingAncestor = parent;
26
+ }
27
+ }
28
+ }
29
+ const LOCAL_FILE_FAILURE_RECOVERY_AUTHORITY = createFileFailureRecoveryAuthority(canonicalizeLocalPath);
30
+ export function selectFileFailureRecoveryAuthority(usesCustomOperations, explicitAuthority) {
31
+ return explicitAuthority ?? (usesCustomOperations ? undefined : LOCAL_FILE_FAILURE_RECOVERY_AUTHORITY);
32
+ }
33
+ export function fileRecoveryScope(authority, path, cwd) {
34
+ return authority.getScope(resolveToCwd(path, cwd));
35
+ }
36
+ export function fileRecoveryTarget(authority, kind, path, cwd) {
37
+ return {
38
+ authority: authority.contractAuthority,
39
+ kind,
40
+ scope: fileRecoveryScope(authority, path, cwd),
41
+ };
42
+ }
43
+ //# sourceMappingURL=file-failure-recovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-failure-recovery.js","sourceRoot":"","sources":["../../../src/core/tools/file-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AC,CAAC;AAExG,MAAM,UAAU,kCAAkC,CACjD,oBAA6B,EAC7B,iBAA2D;IAE3D,OAAO,iBAAiB,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,qCAAqC,CAAC,CAAC;AACxG,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,SAAuC,EAAE,IAAY,EAAE,GAAW;IACnG,OAAO,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,kBAAkB,CACjC,SAAuC,EACvC,IAAY,EACZ,IAAY,EACZ,GAAW;IAEX,OAAO;QACN,SAAS,EAAE,SAAS,CAAC,iBAAiB;QACtC,IAAI;QACJ,KAAK,EAAE,iBAAiB,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC;KAC9C,CAAC;AACH,CAAC","sourcesContent":["import { realpathSync } from \"node:fs\";\nimport { basename, dirname, resolve } from \"node:path\";\nimport {\n\ttype AgentToolFailureRecoveryAuthority,\n\ttype AgentToolFailureRecoveryTarget,\n\tcreateAgentToolFailureRecoveryAuthority,\n} from \"@caupulican/pi-agent-core\";\nimport { resolveToCwd } from \"./path-utils.ts\";\n\nexport const FILE_EXISTS_RECOVERY_TARGET_KIND = \"filesystem.file.exists\";\nexport const FILE_CURRENT_TEXT_RECOVERY_TARGET_KIND = \"filesystem.file.current-text\";\nexport const WRITE_RETARGET_RECOVERY_TARGET_KIND = \"filesystem.write.retarget\";\nexport const EDIT_RETARGET_RECOVERY_TARGET_KIND = \"filesystem.edit.retarget\";\n\nexport interface FileFailureRecoveryAuthority {\n\t/** Exact backend identity shared by cooperating tool contracts. */\n\treadonly contractAuthority: AgentToolFailureRecoveryAuthority;\n\t/** Pure canonical identity for a path already resolved against the tool cwd. */\n\tgetScope: (absolutePath: string) => string;\n}\n\n/** Create one backend authority and pass the same instance to every cooperating custom file tool. */\nexport function createFileFailureRecoveryAuthority(\n\tgetScope: (absolutePath: string) => string,\n): FileFailureRecoveryAuthority {\n\treturn Object.freeze({ contractAuthority: createAgentToolFailureRecoveryAuthority(), getScope });\n}\n\nfunction canonicalizeLocalPath(absolutePath: string): string {\n\tlet existingAncestor = absolutePath;\n\tconst missingSegments: string[] = [];\n\twhile (true) {\n\t\ttry {\n\t\t\treturn resolve(realpathSync.native(existingAncestor), ...missingSegments.reverse());\n\t\t} catch {\n\t\t\tconst parent = dirname(existingAncestor);\n\t\t\tif (parent === existingAncestor) return absolutePath;\n\t\t\tmissingSegments.push(basename(existingAncestor));\n\t\t\texistingAncestor = parent;\n\t\t}\n\t}\n}\n\nconst LOCAL_FILE_FAILURE_RECOVERY_AUTHORITY = createFileFailureRecoveryAuthority(canonicalizeLocalPath);\n\nexport function selectFileFailureRecoveryAuthority(\n\tusesCustomOperations: boolean,\n\texplicitAuthority: FileFailureRecoveryAuthority | undefined,\n): FileFailureRecoveryAuthority | undefined {\n\treturn explicitAuthority ?? (usesCustomOperations ? undefined : LOCAL_FILE_FAILURE_RECOVERY_AUTHORITY);\n}\n\nexport function fileRecoveryScope(authority: FileFailureRecoveryAuthority, path: string, cwd: string): string {\n\treturn authority.getScope(resolveToCwd(path, cwd));\n}\n\nexport function fileRecoveryTarget(\n\tauthority: FileFailureRecoveryAuthority,\n\tkind: string,\n\tpath: string,\n\tcwd: string,\n): AgentToolFailureRecoveryTarget {\n\treturn {\n\t\tauthority: authority.contractAuthority,\n\t\tkind,\n\t\tscope: fileRecoveryScope(authority, path, cwd),\n\t};\n}\n"]}
@@ -4,6 +4,7 @@ export { type BashOperations, type BashSpawnContext, type BashSpawnHook, type Ba
4
4
  export { CONTEXT_SCOUT_GUIDANCE, type ContextScoutToolDependencies, type ContextScoutToolDetails, type ContextScoutToolInput, createContextScoutToolDefinition, formatScoutResult, } from "./context-scout.ts";
5
5
  export { createEditTool, createEditToolDefinition, type EditOperations, type EditToolDetails, type EditToolInput, type EditToolOptions, } from "./edit.ts";
6
6
  export { createExtensionifyTool, createExtensionifyToolDefinition, type ExtensionifyInput, type ExtensionifyReport, type ExtensionifyToolDetails, type ExtensionifyToolOptions, } from "./extensionify.ts";
7
+ export { createFileFailureRecoveryAuthority, type FileFailureRecoveryAuthority, } from "./file-failure-recovery.ts";
7
8
  export { type FileContentReference, FileMutationIntentController, type FileMutationIntentControllerOptions, type FileMutationIntentOperations, type FileMutationKind, type FileMutationLease, type FileMutationPayloadReference, FileMutationPreflightError, type FileMutationPreflightFailureReason, type FilePathIdentity, type FilePathInspection, localFileMutationIntentOperations, } from "./file-mutation-intent.ts";
8
9
  export { withFileMutationQueue } from "./file-mutation-queue.ts";
9
10
  export { createFindTool, createFindToolDefinition, type FindOperations, type FindToolDetails, type FindToolInput, type FindToolOptions, } from "./find.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,YAAY,EACZ,YAAY,EACZ,YAAY,GACZ,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACN,KAAK,2BAA2B,EAChC,KAAK,yBAAyB,EAC9B,KAAK,2BAA2B,EAChC,0BAA0B,EAC1B,oCAAoC,GACpC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,cAAc,EACd,wBAAwB,EACxB,yBAAyB,EACzB,kCAAkC,EAClC,+BAA+B,GAC/B,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,sBAAsB,EACtB,KAAK,4BAA4B,EACjC,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,gCAAgC,EAChC,iBAAiB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAA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,wBAAgB,cAAc,CAC7B,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,YAAY,EACtB,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC1C,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAiBjC"}
@@ -4,6 +4,7 @@ export { createBashTool, createBashToolDefinition, createLocalBashOperations, cr
4
4
  export { CONTEXT_SCOUT_GUIDANCE, createContextScoutToolDefinition, formatScoutResult, } from "./context-scout.js";
5
5
  export { createEditTool, createEditToolDefinition, } from "./edit.js";
6
6
  export { createExtensionifyTool, createExtensionifyToolDefinition, } from "./extensionify.js";
7
+ export { createFileFailureRecoveryAuthority, } from "./file-failure-recovery.js";
7
8
  export { FileMutationIntentController, FileMutationPreflightError, localFileMutationIntentOperations, } from "./file-mutation-intent.js";
8
9
  export { withFileMutationQueue } from "./file-mutation-queue.js";
9
10
  export { createFindTool, createFindToolDefinition, } from "./find.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EAGV,YAAY,EACZ,YAAY,EACZ,YAAY,GACZ,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAIN,0BAA0B,EAC1B,oCAAoC,GACpC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAON,cAAc,EACd,wBAAwB,EACxB,yBAAyB,EACzB,kCAAkC,EAClC,+BAA+B,GAC/B,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,sBAAsB,EAItB,gCAAgC,EAChC,iBAAiB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,sBAAsB,EACtB,gCAAgC,GAKhC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEN,4BAA4B,EAM5B,0BAA0B,EAI1B,iCAAi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,CAAC;QACxC,EAAE,EAAE,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC;QAClC,WAAW,EAAE,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,WAAW,CAAC;QAC5D,QAAQ,EAAE,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC;QACpD,YAAY,EAAE,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,YAAY,CAAC;QAChE,iBAAiB,EAAE,0BAA0B,CAAC,GAAG,EAAE,OAAO,EAAE,iBAAiB,CAAC;KAC9E,CAAC;AACH,CAAC","sourcesContent":["export {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n} from \"@caupulican/pi-agent-core/node\";\nexport {\n\ttype ArtifactRetrieveToolDetails,\n\ttype ArtifactRetrieveToolInput,\n\ttype ArtifactRetrieveToolOptions,\n\tcreateArtifactRetrieveTool,\n\tcreateArtifactRetrieveToolDefinition,\n} from \"./artifact-retrieve.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\tcreateLocalPlatformShellOperations,\n\tcreateLocalPowerShellOperations,\n} from \"./bash.ts\";\nexport {\n\tCONTEXT_SCOUT_GUIDANCE,\n\ttype ContextScoutToolDependencies,\n\ttype ContextScoutToolDetails,\n\ttype ContextScoutToolInput,\n\tcreateContextScoutToolDefinition,\n\tformatScoutResult,\n} from \"./context-scout.ts\";\nexport {\n\tcreateEditTool,\n\tcreateEditToolDefinition,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n} from \"./edit.ts\";\nexport {\n\tcreateExtensionifyTool,\n\tcreateExtensionifyToolDefinition,\n\ttype ExtensionifyInput,\n\ttype ExtensionifyReport,\n\ttype ExtensionifyToolDetails,\n\ttype ExtensionifyToolOptions,\n} from \"./extensionify.ts\";\nexport {\n\ttype FileContentReference,\n\tFileMutationIntentController,\n\ttype FileMutationIntentControllerOptions,\n\ttype FileMutationIntentOperations,\n\ttype FileMutationKind,\n\ttype FileMutationLease,\n\ttype FileMutationPayloadReference,\n\tFileMutationPreflightError,\n\ttype FileMutationPreflightFailureReason,\n\ttype FilePathIdentity,\n\ttype FilePathInspection,\n\tlocalFileMutationIntentOperations,\n} from \"./file-mutation-intent.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\tcreateProfileWriterToolDefinition,\n\ttype ProfileWriterToolDetails,\n\ttype ProfileWriterToolInput,\n} from \"./profile-writer.ts\";\nexport {\n\tcreatePythonTool,\n\tcreatePythonToolDefinition,\n\tDEFAULT_PYTHON_TIMEOUT_SECONDS,\n\tMAX_PYTHON_OUTPUT_BYTES,\n\tMAX_PYTHON_TIMEOUT_SECONDS,\n\ttype PythonExecutionRequest,\n\ttype PythonExecutionResult,\n\ttype PythonOperations,\n\ttype PythonToolDetails,\n\ttype PythonToolInput,\n\ttype PythonToolOptions,\n\tresolvePythonToolPath,\n} from \"./python.ts\";\nexport {\n\tcreateReadTool,\n\tcreateReadToolDefinition,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n} from \"./read.ts\";\nexport {\n\tcreateSecretStoreToolDefinition,\n\ttype SecretStoreStatus,\n\ttype SecretStoreToolDetails,\n\ttype SecretStoreToolInput,\n\ttype SecretStoreToolOptions,\n} from \"./secret-store.ts\";\nexport {\n\tcreateSkillAuditTool,\n\tcreateSkillAuditToolDefinition,\n\tjaccard,\n\ttype SkillAuditInput,\n\ttype SkillAuditReport,\n\ttype SkillAuditToolDetails,\n\ttype SkillAuditToolOptions,\n\ttokenize,\n} from \"./skill-audit.ts\";\nexport {\n\tcreateSkillifyTool,\n\tcreateSkillifyToolDefinition,\n\ttype SkillifyInput,\n\ttype SkillifyReport,\n\ttype SkillifyToolDetails,\n\ttype SkillifyToolOptions,\n} from \"./skillify.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 \"@caupulican/pi-agent-core\";\nimport {\n\ttype ArtifactRetrieveToolOptions,\n\tcreateArtifactRetrieveTool,\n\tcreateArtifactRetrieveToolDefinition,\n} from \"./artifact-retrieve.ts\";\nimport { type BashToolOptions, createBashTool, createBashToolDefinition } from \"./bash.ts\";\nimport { createEditTool, createEditToolDefinition, type EditToolOptions } from \"./edit.ts\";\nimport {\n\tcreateDefaultExtensionifyRuntimeOptions,\n\tcreateExtensionifyTool,\n\tcreateExtensionifyToolDefinition,\n\ttype ExtensionifyToolOptions,\n} from \"./extensionify.ts\";\nimport { FileMutationIntentController } from \"./file-mutation-intent.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 { createPythonTool, createPythonToolDefinition, type PythonToolOptions } from \"./python.ts\";\nimport { createReadTool, createReadToolDefinition, type ReadToolOptions } from \"./read.ts\";\nimport { createSkillAuditTool, createSkillAuditToolDefinition, type SkillAuditToolOptions } from \"./skill-audit.ts\";\nimport { createSkillifyTool, createSkillifyToolDefinition, type SkillifyToolOptions } from \"./skillify.ts\";\nimport { createToolDefinitionWithRuntime, type ToolDef, type ToolName } from \"./tool-definition-factory.ts\";\nimport { createWriteTool, createWriteToolDefinition, type WriteToolOptions } from \"./write.ts\";\n\nexport { allToolNames, type ToolDef, type ToolName } from \"./tool-definition-factory.ts\";\n\nexport type Tool = AgentTool<any>;\n\nexport interface ToolsOptions {\n\tread?: ReadToolOptions;\n\tbash?: BashToolOptions;\n\tpython?: PythonToolOptions;\n\twrite?: WriteToolOptions;\n\tedit?: EditToolOptions;\n\tgrep?: GrepToolOptions;\n\tfind?: FindToolOptions;\n\tls?: LsToolOptions;\n\tskill_audit?: SkillAuditToolOptions;\n\tskillify?: SkillifyToolOptions;\n\textensionify?: ExtensionifyToolOptions;\n\tartifact_retrieve?: ArtifactRetrieveToolOptions;\n}\n\nfunction withSharedFileMutationIntents(options?: ToolsOptions): ToolsOptions {\n\tconst writeController = options?.write?.intentController;\n\tconst editController = options?.edit?.intentController;\n\tif ((options?.write?.operations || options?.edit?.operations) && !writeController && !editController) {\n\t\tthrow new Error(\"Custom file operations require an explicit shared file mutation intent controller.\");\n\t}\n\tif (writeController && editController && writeController !== editController) {\n\t\tthrow new Error(\"Write and edit tools in one surface must share one file mutation intent controller.\");\n\t}\n\tconst intentController = writeController ?? editController ?? new FileMutationIntentController();\n\treturn {\n\t\t...options,\n\t\twrite: { ...options?.write, intentController },\n\t\tedit: { ...options?.edit, intentController },\n\t};\n}\n\nexport function createToolDefinition(toolName: ToolName, cwd: string, options?: ToolsOptions): ToolDef {\n\treturn createToolDefinitionWithRuntime(toolName, cwd, {\n\t\t...options,\n\t\textensionify: createDefaultExtensionifyRuntimeOptions(options?.extensionify),\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 \"python\":\n\t\t\treturn createPythonTool(cwd, options?.python);\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 \"skill_audit\":\n\t\t\treturn createSkillAuditTool(cwd, options?.skill_audit);\n\t\tcase \"skillify\":\n\t\t\treturn createSkillifyTool(cwd, options?.skillify);\n\t\tcase \"extensionify\":\n\t\t\treturn createExtensionifyTool(cwd, options?.extensionify);\n\t\tcase \"artifact_retrieve\":\n\t\t\treturn createArtifactRetrieveTool(cwd, options?.artifact_retrieve);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createCodingToolDefinitions(\n\tcwd: string,\n\toptions?: ToolsOptions,\n\tplatform: NodeJS.Platform = process.platform,\n): ToolDef[] {\n\tconst sharedOptions = withSharedFileMutationIntents(options);\n\tconst bashOptions: BashToolOptions = { ...options?.bash, platform };\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateBashToolDefinition(cwd, bashOptions),\n\t\tcreatePythonToolDefinition(cwd, options?.python),\n\t\tcreateEditToolDefinition(cwd, sharedOptions.edit),\n\t\tcreateWriteToolDefinition(cwd, sharedOptions.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\nexport function createAllToolDefinitions(\n\tcwd: string,\n\toptions?: ToolsOptions,\n\tplatform: NodeJS.Platform = process.platform,\n): Partial<Record<ToolName, ToolDef>> {\n\tconst sharedOptions = withSharedFileMutationIntents(options);\n\tconst bashOptions: BashToolOptions = { ...options?.bash, platform };\n\treturn {\n\t\tread: createReadToolDefinition(cwd, options?.read),\n\t\tbash: createBashToolDefinition(cwd, bashOptions),\n\t\tpython: createPythonToolDefinition(cwd, options?.python),\n\t\tedit: createEditToolDefinition(cwd, sharedOptions.edit),\n\t\twrite: createWriteToolDefinition(cwd, sharedOptions.write),\n\t\tgrep: createGrepToolDefinition(cwd, options?.grep),\n\t\tfind: createFindToolDefinition(cwd, options?.find),\n\t\tls: createLsToolDefinition(cwd, options?.ls),\n\t\tskill_audit: createSkillAuditToolDefinition(cwd, options?.skill_audit),\n\t\tskillify: createSkillifyToolDefinition(cwd, options?.skillify),\n\t\textensionify: createExtensionifyToolDefinition(cwd, options?.extensionify),\n\t\tartifact_retrieve: createArtifactRetrieveToolDefinition(cwd, options?.artifact_retrieve),\n\t};\n}\n\nexport function createCodingTools(\n\tcwd: string,\n\toptions?: ToolsOptions,\n\tplatform: NodeJS.Platform = process.platform,\n): Tool[] {\n\tconst sharedOptions = withSharedFileMutationIntents(options);\n\tconst bashOptions: BashToolOptions = { ...options?.bash, platform };\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateBashTool(cwd, bashOptions),\n\t\tcreatePythonTool(cwd, options?.python),\n\t\tcreateEditTool(cwd, sharedOptions.edit),\n\t\tcreateWriteTool(cwd, sharedOptions.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(\n\tcwd: string,\n\toptions?: ToolsOptions,\n\tplatform: NodeJS.Platform = process.platform,\n): Partial<Record<ToolName, Tool>> {\n\tconst sharedOptions = withSharedFileMutationIntents(options);\n\tconst bashOptions: BashToolOptions = { ...options?.bash, platform };\n\treturn {\n\t\tread: createReadTool(cwd, options?.read),\n\t\tbash: createBashTool(cwd, bashOptions),\n\t\tpython: createPythonTool(cwd, options?.python),\n\t\tedit: createEditTool(cwd, sharedOptions.edit),\n\t\twrite: createWriteTool(cwd, sharedOptions.write),\n\t\tgrep: createGrepTool(cwd, options?.grep),\n\t\tfind: createFindTool(cwd, options?.find),\n\t\tls: createLsTool(cwd, options?.ls),\n\t\tskill_audit: createSkillAuditTool(cwd, options?.skill_audit),\n\t\tskillify: createSkillifyTool(cwd, options?.skillify),\n\t\textensionify: createExtensionifyTool(cwd, options?.extensionify),\n\t\tartifact_retrieve: createArtifactRetrieveTool(cwd, options?.artifact_retrieve),\n\t};\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EAGV,YAAY,EACZ,YAAY,EACZ,YAAY,GACZ,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAIN,0BAA0B,EAC1B,oCAAoC,GACpC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAON,cAAc,EACd,wBAAwB,EACxB,yBAAyB,EACzB,kCAAkC,EAClC,+BAA+B,GAC/B,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,sBAAsB,EAItB,gCAAgC,EAChC,iBAAiB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,sBAAsB,EACtB,gCAAgC,GAKhC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,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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,GAAG,EAAE,OAAO,EAAE,WAAW,CAAC;QAC5D,QAAQ,EAAE,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC;QACpD,YAAY,EAAE,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,YAAY,CAAC;QAChE,iBAAiB,EAAE,0BAA0B,CAAC,GAAG,EAAE,OAAO,EAAE,iBAAiB,CAAC;KAC9E,CAAC;AACH,CAAC","sourcesContent":["export {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n} from \"@caupulican/pi-agent-core/node\";\nexport {\n\ttype ArtifactRetrieveToolDetails,\n\ttype ArtifactRetrieveToolInput,\n\ttype ArtifactRetrieveToolOptions,\n\tcreateArtifactRetrieveTool,\n\tcreateArtifactRetrieveToolDefinition,\n} from \"./artifact-retrieve.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\tcreateLocalPlatformShellOperations,\n\tcreateLocalPowerShellOperations,\n} from \"./bash.ts\";\nexport {\n\tCONTEXT_SCOUT_GUIDANCE,\n\ttype ContextScoutToolDependencies,\n\ttype ContextScoutToolDetails,\n\ttype ContextScoutToolInput,\n\tcreateContextScoutToolDefinition,\n\tformatScoutResult,\n} from \"./context-scout.ts\";\nexport {\n\tcreateEditTool,\n\tcreateEditToolDefinition,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n} from \"./edit.ts\";\nexport {\n\tcreateExtensionifyTool,\n\tcreateExtensionifyToolDefinition,\n\ttype ExtensionifyInput,\n\ttype ExtensionifyReport,\n\ttype ExtensionifyToolDetails,\n\ttype ExtensionifyToolOptions,\n} from \"./extensionify.ts\";\nexport {\n\tcreateFileFailureRecoveryAuthority,\n\ttype FileFailureRecoveryAuthority,\n} from \"./file-failure-recovery.ts\";\nexport {\n\ttype FileContentReference,\n\tFileMutationIntentController,\n\ttype FileMutationIntentControllerOptions,\n\ttype FileMutationIntentOperations,\n\ttype FileMutationKind,\n\ttype FileMutationLease,\n\ttype FileMutationPayloadReference,\n\tFileMutationPreflightError,\n\ttype FileMutationPreflightFailureReason,\n\ttype FilePathIdentity,\n\ttype FilePathInspection,\n\tlocalFileMutationIntentOperations,\n} from \"./file-mutation-intent.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\tcreateProfileWriterToolDefinition,\n\ttype ProfileWriterToolDetails,\n\ttype ProfileWriterToolInput,\n} from \"./profile-writer.ts\";\nexport {\n\tcreatePythonTool,\n\tcreatePythonToolDefinition,\n\tDEFAULT_PYTHON_TIMEOUT_SECONDS,\n\tMAX_PYTHON_OUTPUT_BYTES,\n\tMAX_PYTHON_TIMEOUT_SECONDS,\n\ttype PythonExecutionRequest,\n\ttype PythonExecutionResult,\n\ttype PythonOperations,\n\ttype PythonToolDetails,\n\ttype PythonToolInput,\n\ttype PythonToolOptions,\n\tresolvePythonToolPath,\n} from \"./python.ts\";\nexport {\n\tcreateReadTool,\n\tcreateReadToolDefinition,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n} from \"./read.ts\";\nexport {\n\tcreateSecretStoreToolDefinition,\n\ttype SecretStoreStatus,\n\ttype SecretStoreToolDetails,\n\ttype SecretStoreToolInput,\n\ttype SecretStoreToolOptions,\n} from \"./secret-store.ts\";\nexport {\n\tcreateSkillAuditTool,\n\tcreateSkillAuditToolDefinition,\n\tjaccard,\n\ttype SkillAuditInput,\n\ttype SkillAuditReport,\n\ttype SkillAuditToolDetails,\n\ttype SkillAuditToolOptions,\n\ttokenize,\n} from \"./skill-audit.ts\";\nexport {\n\tcreateSkillifyTool,\n\tcreateSkillifyToolDefinition,\n\ttype SkillifyInput,\n\ttype SkillifyReport,\n\ttype SkillifyToolDetails,\n\ttype SkillifyToolOptions,\n} from \"./skillify.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 \"@caupulican/pi-agent-core\";\nimport {\n\ttype ArtifactRetrieveToolOptions,\n\tcreateArtifactRetrieveTool,\n\tcreateArtifactRetrieveToolDefinition,\n} from \"./artifact-retrieve.ts\";\nimport { type BashToolOptions, createBashTool, createBashToolDefinition } from \"./bash.ts\";\nimport { createEditTool, createEditToolDefinition, type EditToolOptions } from \"./edit.ts\";\nimport {\n\tcreateDefaultExtensionifyRuntimeOptions,\n\tcreateExtensionifyTool,\n\tcreateExtensionifyToolDefinition,\n\ttype ExtensionifyToolOptions,\n} from \"./extensionify.ts\";\nimport { FileMutationIntentController } from \"./file-mutation-intent.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 { createPythonTool, createPythonToolDefinition, type PythonToolOptions } from \"./python.ts\";\nimport { createReadTool, createReadToolDefinition, type ReadToolOptions } from \"./read.ts\";\nimport { createSkillAuditTool, createSkillAuditToolDefinition, type SkillAuditToolOptions } from \"./skill-audit.ts\";\nimport { createSkillifyTool, createSkillifyToolDefinition, type SkillifyToolOptions } from \"./skillify.ts\";\nimport { createToolDefinitionWithRuntime, type ToolDef, type ToolName } from \"./tool-definition-factory.ts\";\nimport { createWriteTool, createWriteToolDefinition, type WriteToolOptions } from \"./write.ts\";\n\nexport { allToolNames, type ToolDef, type ToolName } from \"./tool-definition-factory.ts\";\n\nexport type Tool = AgentTool<any>;\n\nexport interface ToolsOptions {\n\tread?: ReadToolOptions;\n\tbash?: BashToolOptions;\n\tpython?: PythonToolOptions;\n\twrite?: WriteToolOptions;\n\tedit?: EditToolOptions;\n\tgrep?: GrepToolOptions;\n\tfind?: FindToolOptions;\n\tls?: LsToolOptions;\n\tskill_audit?: SkillAuditToolOptions;\n\tskillify?: SkillifyToolOptions;\n\textensionify?: ExtensionifyToolOptions;\n\tartifact_retrieve?: ArtifactRetrieveToolOptions;\n}\n\nfunction withSharedFileMutationIntents(options?: ToolsOptions): ToolsOptions {\n\tconst writeController = options?.write?.intentController;\n\tconst editController = options?.edit?.intentController;\n\tif ((options?.write?.operations || options?.edit?.operations) && !writeController && !editController) {\n\t\tthrow new Error(\"Custom file operations require an explicit shared file mutation intent controller.\");\n\t}\n\tif (writeController && editController && writeController !== editController) {\n\t\tthrow new Error(\"Write and edit tools in one surface must share one file mutation intent controller.\");\n\t}\n\tconst intentController = writeController ?? editController ?? new FileMutationIntentController();\n\treturn {\n\t\t...options,\n\t\twrite: { ...options?.write, intentController },\n\t\tedit: { ...options?.edit, intentController },\n\t};\n}\n\nexport function createToolDefinition(toolName: ToolName, cwd: string, options?: ToolsOptions): ToolDef {\n\treturn createToolDefinitionWithRuntime(toolName, cwd, {\n\t\t...options,\n\t\textensionify: createDefaultExtensionifyRuntimeOptions(options?.extensionify),\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 \"python\":\n\t\t\treturn createPythonTool(cwd, options?.python);\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 \"skill_audit\":\n\t\t\treturn createSkillAuditTool(cwd, options?.skill_audit);\n\t\tcase \"skillify\":\n\t\t\treturn createSkillifyTool(cwd, options?.skillify);\n\t\tcase \"extensionify\":\n\t\t\treturn createExtensionifyTool(cwd, options?.extensionify);\n\t\tcase \"artifact_retrieve\":\n\t\t\treturn createArtifactRetrieveTool(cwd, options?.artifact_retrieve);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createCodingToolDefinitions(\n\tcwd: string,\n\toptions?: ToolsOptions,\n\tplatform: NodeJS.Platform = process.platform,\n): ToolDef[] {\n\tconst sharedOptions = withSharedFileMutationIntents(options);\n\tconst bashOptions: BashToolOptions = { ...options?.bash, platform };\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateBashToolDefinition(cwd, bashOptions),\n\t\tcreatePythonToolDefinition(cwd, options?.python),\n\t\tcreateEditToolDefinition(cwd, sharedOptions.edit),\n\t\tcreateWriteToolDefinition(cwd, sharedOptions.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\nexport function createAllToolDefinitions(\n\tcwd: string,\n\toptions?: ToolsOptions,\n\tplatform: NodeJS.Platform = process.platform,\n): Partial<Record<ToolName, ToolDef>> {\n\tconst sharedOptions = withSharedFileMutationIntents(options);\n\tconst bashOptions: BashToolOptions = { ...options?.bash, platform };\n\treturn {\n\t\tread: createReadToolDefinition(cwd, options?.read),\n\t\tbash: createBashToolDefinition(cwd, bashOptions),\n\t\tpython: createPythonToolDefinition(cwd, options?.python),\n\t\tedit: createEditToolDefinition(cwd, sharedOptions.edit),\n\t\twrite: createWriteToolDefinition(cwd, sharedOptions.write),\n\t\tgrep: createGrepToolDefinition(cwd, options?.grep),\n\t\tfind: createFindToolDefinition(cwd, options?.find),\n\t\tls: createLsToolDefinition(cwd, options?.ls),\n\t\tskill_audit: createSkillAuditToolDefinition(cwd, options?.skill_audit),\n\t\tskillify: createSkillifyToolDefinition(cwd, options?.skillify),\n\t\textensionify: createExtensionifyToolDefinition(cwd, options?.extensionify),\n\t\tartifact_retrieve: createArtifactRetrieveToolDefinition(cwd, options?.artifact_retrieve),\n\t};\n}\n\nexport function createCodingTools(\n\tcwd: string,\n\toptions?: ToolsOptions,\n\tplatform: NodeJS.Platform = process.platform,\n): Tool[] {\n\tconst sharedOptions = withSharedFileMutationIntents(options);\n\tconst bashOptions: BashToolOptions = { ...options?.bash, platform };\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateBashTool(cwd, bashOptions),\n\t\tcreatePythonTool(cwd, options?.python),\n\t\tcreateEditTool(cwd, sharedOptions.edit),\n\t\tcreateWriteTool(cwd, sharedOptions.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(\n\tcwd: string,\n\toptions?: ToolsOptions,\n\tplatform: NodeJS.Platform = process.platform,\n): Partial<Record<ToolName, Tool>> {\n\tconst sharedOptions = withSharedFileMutationIntents(options);\n\tconst bashOptions: BashToolOptions = { ...options?.bash, platform };\n\treturn {\n\t\tread: createReadTool(cwd, options?.read),\n\t\tbash: createBashTool(cwd, bashOptions),\n\t\tpython: createPythonTool(cwd, options?.python),\n\t\tedit: createEditTool(cwd, sharedOptions.edit),\n\t\twrite: createWriteTool(cwd, sharedOptions.write),\n\t\tgrep: createGrepTool(cwd, options?.grep),\n\t\tfind: createFindTool(cwd, options?.find),\n\t\tls: createLsTool(cwd, options?.ls),\n\t\tskill_audit: createSkillAuditTool(cwd, options?.skill_audit),\n\t\tskillify: createSkillifyTool(cwd, options?.skillify),\n\t\textensionify: createExtensionifyTool(cwd, options?.extensionify),\n\t\tartifact_retrieve: createArtifactRetrieveTool(cwd, options?.artifact_retrieve),\n\t};\n}\n"]}
@@ -2,6 +2,7 @@ import type { AgentTool } from "@caupulican/pi-agent-core";
2
2
  import { type TruncationResult } from "@caupulican/pi-agent-core/truncate";
3
3
  import { type Static, Type } from "typebox";
4
4
  import type { ToolDefinition } from "../extensions/types.ts";
5
+ import { type FileFailureRecoveryAuthority } from "./file-failure-recovery.ts";
5
6
  declare const lsSchema: Type.TObject<{
6
7
  path: Type.TOptional<Type.TString>;
7
8
  limit: Type.TOptional<Type.TNumber>;
@@ -32,6 +33,8 @@ export interface LsOperations {
32
33
  export interface LsToolOptions {
33
34
  /** Custom operations for directory listing. Default: local filesystem */
34
35
  operations?: LsOperations;
36
+ /** Shared backend identity for exact cross-tool recovery with custom operations. */
37
+ failureRecoveryAuthority?: FileFailureRecoveryAuthority;
35
38
  }
36
39
  export declare function createLsToolDefinition(cwd: string, options?: LsToolOptions): ToolDefinition<typeof lsSchema, LsToolDetails | undefined>;
37
40
  export declare function createLsTool(cwd: string, options?: LsToolOptions): AgentTool<typeof lsSchema>;
@@ -1 +1 @@
1
- {"version":3,"file":"ls.d.ts","sourceRoot":"","sources":["../../../src/core/tools/ls.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAiC,KAAK,gBAAgB,EAAgB,MAAM,oCAAoC,CAAC;AAExH,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAWtF,QAAA,MAAM,QAAQ;;;;EAIZ,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,QAAQ,CAAC,CAAC;AAIlD,MAAM,WAAW,aAAa;IAC7B,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC5B,WAAW,EAAE,MAAM,OAAO,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC5B,2BAA2B;IAC3B,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IAC7D,wDAAwD;IACxD,IAAI,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC;IACrE,6BAA6B;IAC7B,OAAO,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MA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AK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IAC7D,wDAAwD;IACxD,IAAI,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC;IACrE,6BAA6B;IAC7B,OAAO,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC;CAChE;AAQD,MAAM,WAAW,aAAa;IAC7B,yEAAyE;IACzE,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,oFAAoF;IACpF,wBAAwB,CAAC,EAAE,4BAA4B,CAAC;CACxD;AA+CD,wBAAgB,sBAAsB,CACrC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,aAAa,GACrB,cAAc,CAAC,OAAO,QAAQ,EAAE,aAAa,GAAG,SAAS,CAAC,CAgK5D;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC,OAAO,QAAQ,CAAC,CAE7F"}
@@ -2,6 +2,7 @@ import { readdir as fsReaddir, stat as fsStat } from "node:fs/promises";
2
2
  import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "@caupulican/pi-agent-core/truncate";
3
3
  import nodePath from "path";
4
4
  import { Type } from "typebox";
5
+ import { FILE_EXISTS_RECOVERY_TARGET_KIND, selectFileFailureRecoveryAuthority, } from "./file-failure-recovery.js";
5
6
  import { pathExists, resolveToCwd } from "./path-utils.js";
6
7
  import { formatCollapsibleToolResult, renderTextComponent, renderToolPath, str, toolTextResult, } from "./render-utils.js";
7
8
  import { wrapToolDefinition } from "./tool-definition-wrapper.js";
@@ -53,12 +54,25 @@ function getPermissionString(mode, isDirectory) {
53
54
  }
54
55
  export function createLsToolDefinition(cwd, options) {
55
56
  const ops = options?.operations ?? defaultLsOperations;
57
+ const failureRecoveryAuthority = selectFileFailureRecoveryAuthority(options?.operations !== undefined, options?.failureRecoveryAuthority);
56
58
  return {
57
59
  name: "ls",
58
60
  label: "ls",
59
61
  description: `List directory contents. Returns entries sorted alphabetically, with '/' suffix for directories. Includes dotfiles. Output is truncated to ${DEFAULT_LIMIT} entries or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first).`,
60
62
  promptSnippet: "List directory contents",
61
63
  parameters: lsSchema,
64
+ failureRecovery: {
65
+ actions: failureRecoveryAuthority
66
+ ? [
67
+ {
68
+ kind: "correct",
69
+ authority: failureRecoveryAuthority.contractAuthority,
70
+ targetKind: FILE_EXISTS_RECOVERY_TARGET_KIND,
71
+ instruction: "Use ls on the parent directory to find the actual entry, then submit a changed path.",
72
+ },
73
+ ]
74
+ : [],
75
+ },
62
76
  toolGroup: "explore",
63
77
  async execute(_toolCallId, { path, limit, metadata }, signal, _onUpdate, _ctx) {
64
78
  return new Promise((resolve, reject) => {