pi-agent-ide 0.7.0 → 0.7.1

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 (218) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/chunk-2TRHFMCZ.js +11 -0
  3. package/dist/{chunk-FXNKMNSJ.js → chunk-4GCWGE2C.js} +1 -1
  4. package/dist/chunk-4XMY4H4V.js +1 -0
  5. package/dist/{chunk-3HYXQ4YA.js → chunk-76ZK5ODR.js} +2 -2
  6. package/dist/{chunk-6CZO43OH.js → chunk-BU7IZLKB.js} +1 -1
  7. package/dist/chunk-CWD4O5PM.js +3 -0
  8. package/dist/chunk-D3WTDA6V.js +2 -0
  9. package/dist/chunk-GXEGY7GV.js +1 -0
  10. package/dist/{chunk-GBLKIB6O.js → chunk-HZEY4GT4.js} +1 -1
  11. package/dist/{chunk-S5LXX32D.js → chunk-LEEQIQ7D.js} +6 -6
  12. package/dist/chunk-NRZO5KJT.js +9 -0
  13. package/dist/chunk-OMVRLWMX.js +5 -0
  14. package/dist/{chunk-KR36BT5E.js → chunk-PGIVHICI.js} +1 -1
  15. package/dist/{chunk-YRF7OATP.js → chunk-PKKDDIWW.js} +1 -1
  16. package/dist/{chunk-EDURPQAV.js → chunk-QRJLIV6P.js} +6 -6
  17. package/dist/{chunk-OBNING2A.js → chunk-S5PL5DFQ.js} +1 -1
  18. package/dist/chunk-VMTR74FF.js +2 -0
  19. package/dist/{chunk-PYPPV2F5.js → chunk-WMO6RNE2.js} +1 -1
  20. package/dist/{chunk-3JO7QFIL.js → chunk-WU6ZK6YD.js} +1 -1
  21. package/dist/{chunk-F5YZG77W.js → chunk-XH5WN5XA.js} +1 -1
  22. package/dist/{chunk-AJRIASPQ.js → chunk-YP46DVVP.js} +1 -1
  23. package/dist/entry-11.js +1 -1
  24. package/dist/entry-13.js +1 -1
  25. package/dist/entry-14.js +1 -1
  26. package/dist/entry-15.js +1 -1
  27. package/dist/entry-17.js +1 -1
  28. package/dist/entry-25.js +2 -2
  29. package/dist/entry-26.js +1 -1
  30. package/dist/entry-27.js +2 -2
  31. package/dist/entry-28.js +1 -1
  32. package/dist/entry-29.js +1 -1
  33. package/dist/entry-31.js +13 -12
  34. package/dist/entry-33.js +1 -1
  35. package/dist/entry-37.js +6 -6
  36. package/dist/entry-41.js +1 -1
  37. package/dist/entry-43.js +1 -1
  38. package/dist/entry-44.js +1 -1
  39. package/dist/entry-45.js +13 -14
  40. package/dist/entry-46.js +1 -1
  41. package/dist/entry-49.js +1 -1
  42. package/dist/entry-50.js +1 -1
  43. package/dist/entry-51.js +2 -2
  44. package/dist/entry-53.js +1 -1
  45. package/dist/entry-54.js +1 -1
  46. package/dist/entry-56.js +1 -1
  47. package/dist/entry-57.js +1 -1
  48. package/dist/entry-58.js +1 -1
  49. package/dist/entry-60.js +1 -1
  50. package/dist/entry-62.js +1 -1
  51. package/dist/entry-65.js +1 -1
  52. package/dist/entry-68.js +1 -1
  53. package/dist/entry-70.js +1 -1
  54. package/dist/entry-75.js +1 -1
  55. package/dist/entry-77.js +33 -34
  56. package/dist/entry-78.js +1 -1
  57. package/dist/entry-79.js +1 -1
  58. package/dist/entry-80.js +1 -1
  59. package/dist/entry-82.js +2 -2
  60. package/dist/entry-83.js +1 -1
  61. package/dist/entry-84.js +1 -1
  62. package/dist/entry-85.js +1 -1
  63. package/dist/entry-86.js +1 -1
  64. package/dist/pi-agent-ide.js +14 -9
  65. package/docs/agent-guides/editing.md +35 -46
  66. package/docs/agent-guides/read-resources.md +5 -9
  67. package/docs/agent-guides/search-code.md +12 -17
  68. package/docs/agent-guides/select-code.md +61 -140
  69. package/docs/structured-results.md +27 -62
  70. package/docs/tools.md +6 -10
  71. package/node_modules/pi-agent-doctor/package.json +1 -1
  72. package/node_modules/pi-agent-documentation/package.json +1 -1
  73. package/node_modules/pi-agent-filesystem/index.ts +7 -6
  74. package/node_modules/pi-agent-filesystem/package.json +7 -7
  75. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  76. package/node_modules/pi-agent-filesystem-jq/index.ts +4 -3
  77. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  78. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  79. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  80. package/node_modules/pi-agent-ide-ast/package.json +13 -13
  81. package/node_modules/pi-agent-ide-ast/src/extension.ts +7 -4
  82. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +35 -6
  83. package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +1 -1
  84. package/node_modules/pi-agent-ide-ast/src/select-schema.ts +2 -2
  85. package/node_modules/pi-agent-ide-ast/src/tool-select.ts +18 -1
  86. package/node_modules/pi-agent-ide-changes/index.ts +4 -3
  87. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  88. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  89. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  90. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  91. package/node_modules/pi-agent-ide-lsp/index.ts +3 -3
  92. package/node_modules/pi-agent-ide-lsp/package.json +9 -9
  93. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +5 -1
  94. package/node_modules/pi-agent-image/package.json +2 -2
  95. package/node_modules/pi-agent-invariant/package.json +1 -1
  96. package/node_modules/pi-agent-pdf/package.json +2 -2
  97. package/node_modules/pi-agent-read/package.json +7 -7
  98. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  99. package/node_modules/pi-agent-read/src/api/read-parameters.ts +38 -1
  100. package/node_modules/pi-agent-read/src/api/tools/read.ts +7 -1
  101. package/node_modules/pi-agent-read/src/core/extension.ts +7 -1
  102. package/node_modules/pi-agent-read/src/core/read-core.ts +50 -35
  103. package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +3 -3
  104. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +9 -2
  105. package/node_modules/pi-agent-resource/package.json +1 -1
  106. package/node_modules/pi-agent-resource/src/result-targets.ts +183 -9
  107. package/node_modules/pi-agent-resource/src/tool-result.ts +13 -1
  108. package/node_modules/pi-agent-search/package.json +5 -5
  109. package/node_modules/pi-agent-search/src/api/search-parameters.ts +1 -1
  110. package/node_modules/pi-agent-search-text/index.ts +1 -1
  111. package/node_modules/pi-agent-search-text/package.json +7 -7
  112. package/node_modules/pi-agent-text/package.json +2 -2
  113. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  114. package/node_modules/pi-agent-text-anchor-exact/index.ts +65 -4
  115. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  116. package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  117. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +4 -3
  118. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  119. package/node_modules/pi-agent-text-editor/package.json +9 -9
  120. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
  121. package/node_modules/pi-agent-text-editor/src/core/extension.ts +10 -3
  122. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +3 -13
  123. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +18 -11
  124. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +43 -209
  125. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +37 -31
  126. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  127. package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +2 -7
  128. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +1 -1
  129. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +2 -2
  130. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
  131. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +1 -1
  132. package/node_modules/pi-agent-text-editor-renderer/package.json +5 -5
  133. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +4 -4
  134. package/node_modules/pi-agent-tool-call-interception/package.json +2 -2
  135. package/node_modules/pi-agent-tool-call-interception/src/index.ts +3 -0
  136. package/node_modules/pi-agent-tool-ui/package.json +1 -1
  137. package/node_modules/pi-agent-web/index.ts +4 -3
  138. package/node_modules/pi-agent-web/package.json +7 -7
  139. package/node_modules/pi-agent-web-html/package.json +2 -2
  140. package/node_modules/pi-agent-web-image/package.json +3 -3
  141. package/node_modules/pi-agent-web-pdf/package.json +3 -3
  142. package/node_modules/pi-agent-web-text/package.json +3 -3
  143. package/package.json +35 -35
  144. package/src/composite/text-results.ts +221 -0
  145. package/src/documentation/extension.ts +11 -9
  146. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +7 -6
  147. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  148. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  149. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/index.ts +4 -3
  150. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  151. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  152. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  153. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +4 -3
  154. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  155. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +2 -2
  156. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +3 -3
  157. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +3 -3
  158. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +3 -3
  159. package/src/extensions/pi-agent-read/package.json +7 -7
  160. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  161. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +38 -1
  162. package/src/extensions/pi-agent-read/src/api/tools/read.ts +7 -1
  163. package/src/extensions/pi-agent-read/src/core/extension.ts +7 -1
  164. package/src/extensions/pi-agent-read/src/core/read-core.ts +50 -35
  165. package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +3 -3
  166. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +9 -2
  167. package/src/extensions/pi-agent-search/package.json +5 -5
  168. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +1 -1
  169. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -7
  170. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +1 -1
  171. package/src/extensions/pi-agent-text-editor/package.json +9 -9
  172. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  173. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +65 -4
  174. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  175. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  176. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +4 -3
  177. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  178. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +5 -5
  179. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +4 -4
  180. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
  181. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +10 -3
  182. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +3 -13
  183. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +18 -11
  184. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +43 -209
  185. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +37 -31
  186. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  187. package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +2 -7
  188. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +1 -1
  189. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +2 -2
  190. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
  191. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +1 -1
  192. package/src/pi-agent-ide.ts +4 -1
  193. package/src/plugins/pi-agent-ide-ast/package.json +13 -13
  194. package/src/plugins/pi-agent-ide-ast/src/extension.ts +7 -4
  195. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +35 -6
  196. package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +1 -1
  197. package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +2 -2
  198. package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +18 -1
  199. package/src/plugins/pi-agent-ide-changes/index.ts +4 -3
  200. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  201. package/src/plugins/pi-agent-ide-debugger/index.ts +5 -3
  202. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +5 -3
  203. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  204. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  205. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  206. package/src/plugins/pi-agent-ide-lsp/index.ts +3 -3
  207. package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
  208. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +5 -1
  209. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +8 -6
  210. package/src/plugins/pi-agent-ide-vision/index.ts +12 -4
  211. package/dist/chunk-4NIFBFFR.js +0 -11
  212. package/dist/chunk-7LZKOHH2.js +0 -1
  213. package/dist/chunk-FK42RSF4.js +0 -1
  214. package/dist/chunk-KBP3QUDT.js +0 -2
  215. package/dist/chunk-OE7QVAI2.js +0 -5
  216. package/dist/chunk-SILJ3OL4.js +0 -9
  217. package/dist/chunk-SQKAXYIR.js +0 -2
  218. package/dist/chunk-VCGNVTXQ.js +0 -1
@@ -19,11 +19,6 @@ export const transferFileParameters = Type.Object(
19
19
  {
20
20
  path: filePath,
21
21
  target: filePath,
22
- overwrite: Type.Optional(
23
- Type.Boolean({
24
- description: "Allow replacing an existing regular target file. Defaults to false.",
25
- }),
26
- ),
27
22
  },
28
23
  { additionalProperties: false },
29
24
  );
@@ -76,7 +71,7 @@ export async function executeFileOperation(
76
71
  throw Object.assign(new Error("Invalid file operation arguments"), {
77
72
  code: "INVALID_ARGUMENTS",
78
73
  });
79
- const args = input as { path: string; target?: string; overwrite?: boolean };
74
+ const args = input as { path: string; target?: string };
80
75
  source = path.resolve(cwd, args.path);
81
76
  target = args.target === undefined ? undefined : path.resolve(cwd, args.target);
82
77
  signal?.throwIfAborted();
@@ -95,19 +90,14 @@ export async function executeFileOperation(
95
90
  throw Object.assign(new Error("Source and target are the same file"), {
96
91
  code: "SAME_FILE",
97
92
  });
98
- if (args.overwrite !== true)
99
- throw Object.assign(new Error("Target exists; use overwrite: true to replace it"), {
100
- code: "EEXIST",
101
- });
102
93
  }
103
94
  }
104
95
  signal?.throwIfAborted();
105
96
  started = true;
106
97
  if (operation === "delete") await unlink(source);
107
98
  else if (target !== undefined) {
108
- if (operation === "copy")
109
- await fs.copy(source, target, { overwrite: args.overwrite === true, errorOnExist: true });
110
- else await fs.move(source, target, { overwrite: args.overwrite === true });
99
+ if (operation === "copy") await fs.copy(source, target, { overwrite: true });
100
+ else await fs.move(source, target, { overwrite: true });
111
101
  }
112
102
  return {
113
103
  kind: "file-operation",
@@ -42,10 +42,11 @@ import {
42
42
  type NativeEditBatchEvent,
43
43
  } from "#src/api/native-edit-batch-event.js";
44
44
  import {
45
- mutationDataSchema,
46
- mutationOutputSchema,
45
+ flushDataSchema,
46
+ flushOutputSchema,
47
47
  mutationOutcome,
48
48
  type MutationData,
49
+ type FlushData,
49
50
  } from "./structured-result.js";
50
51
 
51
52
  interface PendingBatch {
@@ -62,7 +63,7 @@ interface BatchSummary {
62
63
  }
63
64
 
64
65
  interface ScriptBatch {
65
- readonly reports: StructuredResult<MutationData>[];
66
+ readonly reports: StructuredResult<FlushData>[];
66
67
  reportCursor: number;
67
68
  readonly id: string;
68
69
  readonly context: ExtensionContext;
@@ -103,10 +104,7 @@ function receiptEffect(files: MutationData["files"]): MutationData["effect"] {
103
104
  : "not-applied";
104
105
  }
105
106
 
106
- function receiptStatus(
107
- errors: readonly unknown[],
108
- operations: NonNullable<MutationData["operations"]>,
109
- ) {
107
+ function receiptStatus(errors: readonly unknown[], operations: FlushData["operations"]) {
110
108
  return errors.length === 0
111
109
  ? ("success" as const)
112
110
  : operations.some(
@@ -192,7 +190,7 @@ class NativeTextEditBatchCoordinator {
192
190
  "Use flush to commit pending native Codemode text edits and return their observed effects. Await tools.flush({}) before depending on a completed write. A failed flush retains applied effects and does not replay edits. Call it only inside native Codemode.",
193
191
  promptSnippet: "Commit pending native editor changes and inspect their effects",
194
192
  parameters: Type.Object({}, { additionalProperties: false }),
195
- outputSchema: mutationOutputSchema,
193
+ outputSchema: flushOutputSchema,
196
194
  execute: async (id) => {
197
195
  const script = this.invocations.get(id);
198
196
  if (!script) throw new Error("Flush requires an active native Codemode script");
@@ -209,15 +207,24 @@ class NativeTextEditBatchCoordinator {
209
207
  content: [
210
208
  {
211
209
  type: "text",
212
- text:
210
+ text: [
213
211
  errors.length === 0
214
212
  ? `Flushed ${operations.length} editor operations; ${effect}.`
215
- : `Editor flush failed; ${effect}.\n${errors.map((error) => error.message).join("\n")}`,
213
+ : `Editor flush failed; ${effect}.`,
214
+ ...files.map(
215
+ (file) =>
216
+ `${file.source}: ${file.effect}${file.state ? ` (${file.state})` : ""}`,
217
+ ),
218
+ ...operations.map(
219
+ (operation) =>
220
+ `${operation.operation}: ${operation.effect}${operation.errors.length ? ` — ${operation.errors.map((error) => error.message).join("; ")}` : ""}`,
221
+ ),
222
+ ].join("\n"),
216
223
  },
217
224
  ],
218
225
  details: { results: [] },
219
226
  },
220
- mutationDataSchema,
227
+ flushDataSchema,
221
228
  {
222
229
  status: receiptStatus(errors, operations),
223
230
  data: { operation: "flush", effect, files, operations },
@@ -1,7 +1,5 @@
1
1
  import { Type, type Static } from "typebox";
2
- import { Value } from "typebox/value";
3
2
  import {
4
- MAX_STRUCTURED_BYTES,
5
3
  resultError,
6
4
  resultErrorSchema,
7
5
  structuredResultSchema,
@@ -23,142 +21,55 @@ const file = Type.Object(
23
21
  {
24
22
  source: Type.String(),
25
23
  effect,
26
- action: Type.Optional(Type.String()),
27
24
  state: Type.Optional(
28
25
  Type.Union([Type.Literal("present"), Type.Literal("absent"), Type.Literal("unknown")]),
29
26
  ),
30
27
  },
31
28
  { additionalProperties: false },
32
29
  );
33
- const operation = Type.Object(
34
- {
35
- id: Type.String(),
36
- operation: Type.String(),
37
- effect,
38
- errors: Type.Array(resultErrorSchema),
39
- status: Type.Optional(
40
- Type.Union([
41
- Type.Literal("success"),
42
- Type.Literal("error"),
43
- Type.Literal("warning"),
44
- Type.Literal("unknown"),
45
- ]),
46
- ),
47
- sources: Type.Optional(Type.Array(Type.String())),
48
- warnings: Type.Optional(Type.Array(resultErrorSchema)),
49
- },
30
+ const receipt = { effect, files: Type.Array(file) };
31
+
32
+ /** Validate one file tool's result. Recovery, rendering and resource actions stay in details. */
33
+ export function mutationDataSchema(operation: string) {
34
+ return Type.Object(
35
+ {
36
+ operation: Type.Literal(operation),
37
+ ...receipt,
38
+ operationId: Type.Optional(Type.String()),
39
+ ...(operation === "delete" || operation === "flush"
40
+ ? {}
41
+ : {
42
+ target: Type.Optional(Type.String()),
43
+ targetUnavailable: Type.Optional(Type.String()),
44
+ }),
45
+ },
46
+ { additionalProperties: false },
47
+ );
48
+ }
49
+ /** Internal validation schema for a single tool, not an agent-facing return declaration. */
50
+ export function mutationResultSchema(operation: string) {
51
+ return structuredResultSchema(mutationDataSchema(operation));
52
+ }
53
+ const batchOperation = Type.Object(
54
+ { id: Type.String(), operation: Type.String(), effect, errors: Type.Array(resultErrorSchema) },
50
55
  { additionalProperties: false },
51
56
  );
52
- export const mutationDataSchema = Type.Object(
53
- {
54
- operation: Type.String(),
55
- effect,
56
- operationId: Type.Optional(Type.String()),
57
- target: Type.Optional(
58
- Type.String({
59
- description:
60
- "Backend-owned resulting-text scope: replace/insert text, write's whole file, copy/move destinations, or undo's whole restored files. Delete never supplies a live target. Pending handles require a confirmed commit.",
61
- }),
62
- ),
63
- targetUnavailable: Type.Optional(
64
- Type.String({
65
- description:
66
- "Why a completed mutation could not provide a safe resulting-text target. The write effect is reported separately.",
67
- }),
68
- ),
69
- files: Type.Array(file),
70
- changes: Type.Optional(
71
- Type.Array(
72
- Type.Object(
73
- {
74
- source: Type.String(),
75
- from: Type.Integer({
76
- description:
77
- "Inclusive zero-based UTF-16 offset in the pre-edit snapshot; not a live selector.",
78
- }),
79
- to: Type.Integer({
80
- description:
81
- "Exclusive zero-based UTF-16 offset in the pre-edit snapshot; not a live selector.",
82
- }),
83
- removedText: Type.String(),
84
- insertedText: Type.String(),
85
- },
86
- { additionalProperties: false },
87
- ),
88
- ),
89
- ),
90
- changesUnavailable: Type.Optional(
91
- Type.String({
92
- description: "Why the exact change record is omitted; applied effects remain reported.",
93
- }),
94
- ),
95
- operations: Type.Optional(Type.Array(operation)),
96
- parentToolCallId: Type.Optional(Type.String()),
97
- recovery: Type.Optional(
98
- Type.Array(
99
- Type.Object({
100
- source: Type.String(),
101
- field: Type.String(),
102
- anchor: Type.String(),
103
- total: Type.Integer(),
104
- candidates: Type.Array(
105
- Type.Object({
106
- rank: Type.Integer(),
107
- range: Type.Object({
108
- start: Type.Object({ lineNumber: Type.Integer(), column: Type.Integer() }),
109
- end: Type.Object({ lineNumber: Type.Integer(), column: Type.Integer() }),
110
- }),
111
- }),
112
- ),
113
- }),
114
- ),
115
- ),
116
- action: Type.Optional(
117
- Type.Object(
118
- {
119
- source: Type.String(),
120
- kind: Type.Optional(Type.String()),
121
- status: Type.Optional(Type.String()),
122
- command: Type.Optional(Type.String()),
123
- deleted: Type.Optional(Type.Boolean()),
124
- session: Type.Optional(Type.String()),
125
- file: Type.Optional(Type.String()),
126
- line: Type.Optional(Type.Integer()),
127
- verified: Type.Optional(Type.Boolean()),
128
- evaluation: Type.Optional(
129
- Type.Object(
130
- {
131
- expression: Type.String(),
132
- result: Type.String(),
133
- type: Type.Optional(Type.String()),
134
- variablesReference: Type.Integer(),
135
- },
136
- { additionalProperties: false },
137
- ),
138
- ),
139
- breakpoints: Type.Optional(
140
- Type.Array(
141
- Type.Object(
142
- {
143
- source: Type.String(),
144
- file: Type.String(),
145
- line: Type.Integer(),
146
- verified: Type.Boolean(),
147
- },
148
- { additionalProperties: false },
149
- ),
150
- ),
151
- ),
152
- },
153
- { additionalProperties: false },
154
- ),
155
- ),
156
- },
57
+ /** Flush owns the batch journal; individual file tools do not carry it. */
58
+ export const flushDataSchema = Type.Object(
59
+ { operation: Type.Literal("flush"), ...receipt, operations: Type.Array(batchOperation) },
157
60
  { additionalProperties: false },
158
61
  );
159
- export const mutationOutputSchema = structuredResultSchema(mutationDataSchema);
160
- /** Public receipt fields are defined by the native output schema. */
161
- export type MutationData = Static<typeof mutationDataSchema>;
62
+ export const flushOutputSchema = structuredResultSchema(flushDataSchema);
63
+ export type FlushData = Static<typeof flushDataSchema>;
64
+ /** Small internal receipt used to collect observed file effects. */
65
+ export interface MutationData {
66
+ operation: string;
67
+ effect: Static<typeof effect>;
68
+ files: Static<typeof file>[];
69
+ operationId?: string;
70
+ target?: string;
71
+ targetUnavailable?: string;
72
+ }
162
73
  type MutationFile = MutationData["files"][number];
163
74
  function record(value: unknown): value is Record<string, unknown> {
164
75
  return typeof value === "object" && value !== null;
@@ -180,16 +91,13 @@ export function mutationOutcome(
180
91
  data: {
181
92
  operation,
182
93
  effect: "pending",
183
- ...(typeof details.metadata?.resultTarget === "string"
94
+ ...(operation !== "delete" && typeof details.metadata?.resultTarget === "string"
184
95
  ? { target: details.metadata.resultTarget }
185
96
  : {}),
186
97
  files:
187
98
  typeof detailRecord.source === "string"
188
99
  ? [{ source: detailRecord.source, effect: "pending" }]
189
100
  : [],
190
- ...(typeof native.parentToolCallId === "string"
191
- ? { parentToolCallId: native.parentToolCallId }
192
- : {}),
193
101
  },
194
102
  };
195
103
  const observed = new Set(completions.map((completion) => completion.resourceSource));
@@ -286,20 +194,6 @@ export function mutationOutcome(
286
194
  const file = unique.find((file) => file.source === state.source);
287
195
  if (file && (state.state === "present" || state.state === "absent")) file.state = state.state;
288
196
  }
289
- const changes = (results ?? [])
290
- .filter((item) => item.data.ok)
291
- .flatMap((item) => {
292
- const source = item.data.path;
293
- if (source === undefined) return [];
294
- return (item.data.rawChanges ?? []).map((change) => ({
295
- source,
296
- from: change.fromA,
297
- to: change.toA,
298
- removedText: change.removedText,
299
- insertedText: change.insertedText,
300
- }));
301
- });
302
- const changesFit = Buffer.byteLength(JSON.stringify(changes)) <= MAX_STRUCTURED_BYTES / 2;
303
197
  const known = unique.some((file) => file.effect === "applied");
304
198
  if (result.isError && errors.length === 0)
305
199
  errors.push({ code: "MUTATION_FAILED", message: "Mutation failed" });
@@ -318,46 +212,6 @@ export function mutationOutcome(
318
212
  : known
319
213
  ? "applied"
320
214
  : "not-applied";
321
- const action =
322
- semantic && typeof semantic.source === "string"
323
- ? {
324
- source: semantic.source,
325
- ...(typeof semantic.kind === "string" ? { kind: semantic.kind } : {}),
326
- ...(typeof semantic.status === "string" ? { status: semantic.status } : {}),
327
- ...(typeof semantic.command === "string" ? { command: semantic.command } : {}),
328
- ...(typeof semantic.deleted === "boolean" ? { deleted: semantic.deleted } : {}),
329
- ...(typeof semantic.session === "string" ? { session: semantic.session } : {}),
330
- ...(typeof semantic.file === "string" ? { file: semantic.file } : {}),
331
- ...(typeof semantic.line === "number" ? { line: semantic.line } : {}),
332
- ...(typeof semantic.verified === "boolean" ? { verified: semantic.verified } : {}),
333
- ...(record(semantic.evaluation)
334
- ? {
335
- evaluation: {
336
- expression: semantic.evaluation.expression,
337
- result: semantic.evaluation.result,
338
- variablesReference: semantic.evaluation.variablesReference,
339
- ...(typeof semantic.evaluation.type === "string"
340
- ? { type: semantic.evaluation.type }
341
- : {}),
342
- },
343
- }
344
- : {}),
345
- ...(Array.isArray(semantic.breakpoints)
346
- ? {
347
- breakpoints: semantic.breakpoints.filter(record).map((breakpoint) => ({
348
- source: breakpoint.source,
349
- file: breakpoint.file,
350
- line: breakpoint.line,
351
- verified: breakpoint.verified,
352
- })),
353
- }
354
- : {}),
355
- }
356
- : undefined;
357
- const checkedAction =
358
- action && Value.Check(mutationDataSchema.properties.action, action) ? action : undefined;
359
- if (action && !checkedAction)
360
- errors.push(resultError("Action adapter returned invalid fields", "INVALID_STRUCTURED_RESULT"));
361
215
  return {
362
216
  status:
363
217
  errors.length === 0
@@ -369,32 +223,12 @@ export function mutationOutcome(
369
223
  operation,
370
224
  effect,
371
225
  files: unique,
372
- ...(changes.length === 0
373
- ? {}
374
- : changesFit
375
- ? { changes }
376
- : {
377
- changesUnavailable:
378
- "Exact change record exceeds the 512 KiB receipt budget; it was not clipped.",
379
- }),
380
- ...(typeof details.metadata?.resultTarget === "string"
226
+ ...(operation !== "delete" && typeof details.metadata?.resultTarget === "string"
381
227
  ? { target: details.metadata.resultTarget }
382
228
  : {}),
383
- ...(typeof details.metadata?.targetUnavailable === "string"
229
+ ...(operation !== "delete" && typeof details.metadata?.targetUnavailable === "string"
384
230
  ? { targetUnavailable: details.metadata.targetUnavailable }
385
231
  : {}),
386
- ...(details.anchorRecoveries === undefined
387
- ? {}
388
- : {
389
- recovery: details.anchorRecoveries.map((item) => ({
390
- source: item.path,
391
- field: item.field,
392
- anchor: item.anchor,
393
- total: item.total,
394
- candidates: [...item.candidates],
395
- })),
396
- }),
397
- ...(checkedAction ? { action: checkedAction } : {}),
398
232
  },
399
233
  errors,
400
234
  };
@@ -408,5 +242,5 @@ export function structuredMutation(
408
242
  ) {
409
243
  const outcome = mutationOutcome(result, operation, completions);
410
244
  if (outcome.data && operationId !== undefined) outcome.data.operationId = operationId;
411
- return withStructuredResult(result, mutationDataSchema, outcome);
245
+ return withStructuredResult(result, mutationDataSchema(operation), outcome);
412
246
  }
@@ -84,7 +84,7 @@ import type { ToolCallAnchorRenderState } from "pi-agent-tool-call-interception"
84
84
  import type { Static, TSchema } from "typebox";
85
85
  import { executeWholeFileTool, isWholeFileInvocation } from "#src/core/file-operation-tools.js";
86
86
  import { EDITING_GUIDELINES } from "#src/core/editing-guidelines.js";
87
- import { mutationOutputSchema, structuredMutation } from "./structured-result.js";
87
+ import { mutationResultSchema, structuredMutation } from "./structured-result.js";
88
88
  import type { ResultTargetStore } from "pi-agent-resource";
89
89
 
90
90
  export function createTextTool<TParameters extends TSchema>(
@@ -118,7 +118,7 @@ export function createTextTool<TParameters extends TSchema>(
118
118
  promptGuidelines: [...EDITING_GUIDELINES, ...(definition.promptGuidelines ?? [])],
119
119
  description: definition.description,
120
120
  parameters: definition.parameters,
121
- outputSchema: mutationOutputSchema,
121
+ outputSchema: mutationResultSchema(definition.name),
122
122
  prepareArguments: (arguments_) =>
123
123
  // oxlint-disable-next-line typescript/no-unsafe-return -- TypeBox resolves only concrete tool schemas.
124
124
  prepareGuardedArguments(
@@ -348,19 +348,17 @@ export function createTextTool<TParameters extends TSchema>(
348
348
  (
349
349
  {
350
350
  replace:
351
- "Local data.target selects this call's resulting text; empty replacement selects the resulting position, not the removed text.",
352
- insert:
353
- "Local data.target selects this call's inserted text, including supplied line separators.",
354
- write: "Local data.target selects the whole written file, not only its changed span.",
355
- copy: "Local data.target selects only the destination text; a whole-file copy selects the whole destination. The source is unchanged.",
356
- move: "Local data.target selects only the destination text; a whole-file move selects the whole destination. Source removals never become output targets.",
357
- delete:
358
- "Deletion returns a change record and file state, never a live target or an empty-position target.",
359
- undo: "Local data.target selects whole restored text files, not only reversed spans. Restored absence is reported in files[].state without a live target.",
351
+ "This result selects the resulting text; empty replacement selects the resulting position, not the removed text.",
352
+ insert: "This result selects the inserted text, including supplied line separators.",
353
+ write: "This result selects the whole written file, not only its changed span.",
354
+ copy: "This result selects only destination text; a whole-file copy selects the whole destination. The source is unchanged.",
355
+ move: "This result selects only destination text; a whole-file move selects the whole destination. Source removals never become output targets.",
356
+ delete: "Deletion reports file effects but provides no reusable text selection.",
357
+ undo: "This result selects whole restored text files, not only reversed spans. Deleted files provide no text selection.",
360
358
  } as Record<string, string>
361
359
  )[definition.name] ?? "",
362
360
  ["replace", "insert", "write", "copy", "move", "undo"].includes(definition.name)
363
- ? "A pending data.target requires confirmed writing. Successful changes without a verified text mapping expose data.targetUnavailable; inspect effects separately."
361
+ ? "Pass this unchanged result to another source tool for dependent work. Pending edits commit before the next tool consumes them. If the result reports no verified text selection, inspect the file instead."
364
362
  : "",
365
363
  definition.source.inherited
366
364
  ? definition.wholeFileOperation === undefined
@@ -1406,12 +1404,18 @@ async function anchorFailureToolResult(
1406
1404
  const results: FileMutationResult[] = [];
1407
1405
  const anchorRecoveries: NonNullable<FileMutationBatchResult["anchorRecoveries"]>[number][] = [];
1408
1406
  const messages: string[] = [];
1407
+ const exactTextFailures: string[] = [];
1409
1408
  for (const item of recovered) {
1410
1409
  if (item === undefined) {
1411
1410
  continue;
1412
1411
  }
1413
1412
  results.push(...(item.details.results ?? []));
1414
1413
  anchorRecoveries.push(...(item.details.anchorRecoveries ?? []));
1414
+ const failed = item.details.metadata?.exactTextFailures;
1415
+ if (Array.isArray(failed))
1416
+ exactTextFailures.push(
1417
+ ...failed.filter((source): source is string => typeof source === "string"),
1418
+ );
1415
1419
  for (const block of item.content) {
1416
1420
  if (block.type === "text") {
1417
1421
  messages.push(block.text);
@@ -1423,7 +1427,12 @@ async function anchorFailureToolResult(
1423
1427
  }
1424
1428
  return {
1425
1429
  content: [{ type: "text", text: messages.join("\n\n") }],
1426
- details: { results, anchorRecoveries, effect: "not-applied" },
1430
+ details: {
1431
+ results,
1432
+ anchorRecoveries,
1433
+ effect: "not-applied",
1434
+ metadata: { exactTextFailures },
1435
+ },
1427
1436
  };
1428
1437
  }
1429
1438
  if (!(failure.cause instanceof TextMutationAnchorResolutionError)) {
@@ -1432,15 +1441,10 @@ async function anchorFailureToolResult(
1432
1441
 
1433
1442
  const contextual = failure.cause;
1434
1443
  const resolution = contextual.resolution;
1435
- const recovery = await resolveAnchorRecovery(contextual);
1436
- if (recovery?.kind === "timed-out") {
1437
- return failureToolResult(
1438
- contextual.source,
1439
- failure.code,
1440
- `${failure.message}; recovery timed out`,
1441
- "not-applied",
1442
- );
1443
- }
1444
+ const recovery = await resolveAnchorRecovery(contextual).catch(() => {
1445
+ context.signal?.throwIfAborted();
1446
+ return undefined;
1447
+ });
1444
1448
 
1445
1449
  const windows =
1446
1450
  recovery?.kind === "candidates"
@@ -1451,9 +1455,7 @@ async function anchorFailureToolResult(
1451
1455
  : resolution.rejection?.contextRange === undefined
1452
1456
  ? []
1453
1457
  : [resolution.rejection.contextRange];
1454
- if (windows.length === 0) {
1455
- return undefined;
1456
- }
1458
+ if (windows.length === 0) windows.push({ offset: 1, limit: 40 });
1457
1459
 
1458
1460
  const reads = await Promise.all(
1459
1461
  windows.map((range) =>
@@ -1464,14 +1466,15 @@ async function anchorFailureToolResult(
1464
1466
  cwd: context.cwd,
1465
1467
  ...(context.signal !== undefined && { signal: context.signal }),
1466
1468
  },
1467
- ),
1469
+ )?.catch(() => {
1470
+ context.signal?.throwIfAborted();
1471
+ return undefined;
1472
+ }),
1468
1473
  ),
1469
1474
  );
1470
1475
  const recoveryTexts: string[] = [];
1471
1476
  for (const read of reads) {
1472
- if (read === undefined || read.isError === true) {
1473
- return undefined;
1474
- }
1477
+ if (read === undefined || read.isError === true) continue;
1475
1478
  recoveryTexts.push(
1476
1479
  ...read.content.filter((block) => block.type === "text").map((block) => block.text),
1477
1480
  );
@@ -1512,6 +1515,9 @@ async function anchorFailureToolResult(
1512
1515
  results: [result],
1513
1516
  effect: "not-applied",
1514
1517
  anchorRecovery: true,
1518
+ ...(resolution.resolverId === "exact-text" && {
1519
+ metadata: { exactTextFailures: [contextual.source] },
1520
+ }),
1515
1521
  ...(recovery?.kind === "candidates" && {
1516
1522
  anchorRecoveries: [
1517
1523
  {
@@ -1542,8 +1548,8 @@ function formatRejectedAnchorMessage(
1542
1548
  ? "is invalid"
1543
1549
  : "could not be resolved";
1544
1550
  const guidance =
1545
- code === "ambiguous"
1546
- ? "Use a unique text span or one of the candidate anchors below."
1551
+ failure.resolution.resolverId === "exact-text"
1552
+ ? "Exact-text editing is now blocked for this file until an anchor-based edit succeeds. Find the intended location among the current anchors below, or use Read/Search for another section, and use its anchor. After that edit, exact text is available again."
1547
1553
  : "If the intended text is represented below, use its candidate anchor. Otherwise, reread the relevant section and choose a current anchor.";
1548
1554
  const context = recoveryContext.length === 0 ? "" : `\n\n${recoveryContext}`;
1549
1555
  return `[SYSTEM] ${failure.toolName} blocked: ${failure.field} anchor "${failure.anchor}" ${state}. ${guidance} (${reason})${context}`;
@@ -303,7 +303,7 @@ class InterceptorImpl implements ToolCallInterceptor {
303
303
  content: guardResult.content,
304
304
  details,
305
305
  },
306
- mutationDataSchema,
306
+ mutationDataSchema(event.toolName),
307
307
  {
308
308
  status: "error",
309
309
  errors: [resultError(message, "INTERCEPTED")],
@@ -33,12 +33,12 @@ export function sourceRangeProperties() {
33
33
  export function targetProperties() {
34
34
  return {
35
35
  target: resultSourceProperty(
36
- "Destination file path or source result. A structured result replaces its exact ranges (zero-width ranges insert); omit targetStart/targetEnd. Source and destination selections pair in declared order with equal counts. A string target keeps its existing anchor semantics.",
36
+ "Destination file path, unchanged source result or its UUID. A result replaces its exact ranges (zero-width ranges insert); omit targetStart/targetEnd. Source and destination selections pair in declared order with equal counts. A file path keeps its existing anchor semantics. Whole-file transfers replace an existing regular destination file.",
37
37
  ),
38
38
  targetStart: Type.Optional(
39
39
  Type.String({
40
40
  description:
41
- "Registered anchor or unique exact text in the destination. Required for text transfers with a string target; omit for whole-file transfers or a structured target. Without targetEnd, inserts after the last containing line, keeping the selected text. With targetEnd, replacement starts at the first containing line. SEARCH :match also uses these line boundaries.",
41
+ "Registered anchor or unique exact text in the destination. Required for text transfers to a file path; omit for whole-file transfers or a result destination. Without targetEnd, inserts after the last containing line, keeping the selected text. With targetEnd, replacement starts at the first containing line. SEARCH :match also uses these line boundaries.",
42
42
  }),
43
43
  ),
44
44
  targetEnd: Type.Optional(
@@ -47,10 +47,5 @@ export function targetProperties() {
47
47
  "Optional inclusive destination end. Replaces whole lines through the last line containing this anchor, including SEARCH :match. May differ in type from targetStart; both must resolve uniquely in the target file and in forward order. Omit to insert after targetStart instead.",
48
48
  }),
49
49
  ),
50
- overwrite: Type.Optional(
51
- Type.Boolean({
52
- description: "Allow replacing an existing regular target file. Defaults to false.",
53
- }),
54
- ),
55
50
  };
56
51
  }
@@ -18,7 +18,7 @@ import type { TextMutationToolRegistration } from "#src/api/mutation-tool.js";
18
18
  export const copySchema = Type.Object(
19
19
  {
20
20
  path: resultSourceProperty(
21
- "Source file path or structured source selection; omit start/end for structured inputs. Use one whole-file result when target is a string without text selectors. Structured source/destination selections pair in declared order, with equal counts and duplicate ranges removed.",
21
+ "Source file path, unchanged source result or its UUID; omit start/end for result inputs. Use one whole-file result when the destination is a file path without text selectors. Source/destination selections pair in declared order, with equal counts and duplicate ranges removed.",
22
22
  ),
23
23
  ...sourceRangeProperties(),
24
24
  ...targetProperties(),
@@ -18,7 +18,7 @@ import type { TextMutationToolRegistration } from "#src/api/mutation-tool.js";
18
18
  export const deleteSchema = Type.Object(
19
19
  {
20
20
  path: resultSourceProperty(
21
- "File path or structured source selection. A structured input deletes only its exact text ranges, even if it selects a whole file; omit start/end.",
21
+ "File path, unchanged source result or its UUID. A result input deletes only its selected text and keeps the file, even for a whole-file selection; omit start/end.",
22
22
  ),
23
23
  ...sourceRangeProperties(),
24
24
  },
@@ -34,7 +34,7 @@ export const deleteMutationTool: TextMutationToolRegistration<typeof deleteSchem
34
34
  name: "delete",
35
35
  wholeFileOperation: "delete",
36
36
  description:
37
- "Use delete to permanently delete one regular file when an ordinary string path is supplied without text selectors, or to remove selected text. Structured path removes only its text ranges and keeps the file, even for a whole-file selection. Whole-file deletion rejects directories and symlinks.",
37
+ "Use delete to permanently delete one regular file when an ordinary string path is supplied without text selectors, or to remove selected text. A result input removes only its text ranges and keeps the file, even for a whole-file selection. Whole-file deletion rejects directories and symlinks.",
38
38
 
39
39
  promptSnippet: "Delete regular files, or delete selected text using exact matches or anchors",
40
40
  parameters: deleteSchema,
@@ -20,7 +20,7 @@ import type { TextChange } from "#src/core/text-change-engine.js";
20
20
  export const moveSchema = Type.Object(
21
21
  {
22
22
  path: resultSourceProperty(
23
- "Source file path or structured source selection; omit start/end for structured inputs. Use one whole-file result when target is a string without text selectors. Structured source/destination selections pair in declared order, with equal counts and duplicate ranges removed. Destinations must not overlap or touch source ranges.",
23
+ "Source file path, unchanged source result or its UUID; omit start/end for result inputs. Use one whole-file result when the destination is a file path without text selectors. Source/destination selections pair in declared order, with equal counts and duplicate ranges removed. Destinations must not overlap or touch source ranges.",
24
24
  ),
25
25
  ...sourceRangeProperties(),
26
26
  ...targetProperties(),