@tduyng/pi-edit-path 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tduyng/pi-edit-path",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Two halves of one edit path: fuse the validation command into the edit that needs it, and name the region on disk a failed edit meant so the retry lands without a re-read.",
5
5
  "keywords": [
6
6
  "pi",
@@ -62,7 +62,7 @@ export function coerceThenRun(value: ThenRun | string | undefined): ThenRun | un
62
62
  function commandFrom(literal: string): ThenRun {
63
63
  const trimmed = literal.trim()
64
64
  if (trimmed === '') throw new Error(NO_COMMAND)
65
- if (!/^[{[]?\s*"?[A-Za-z_]\w*"?\s*:/.test(trimmed)) return { command: trimmed }
65
+ if (!/^[{[]/.test(trimmed)) return { command: trimmed }
66
66
  const command = literalCommand(trimmed)
67
67
  if (command === undefined) throw new Error(NO_COMMAND)
68
68
  const ran: ThenRun = { command }
@@ -79,11 +79,13 @@ function literalCommand(literal: string): string | undefined {
79
79
  parsed = undefined
80
80
  }
81
81
  if (isCommandObject(parsed)) return parsed.command.trim()
82
- const match = /"?command"?\s*:\s*(?:"([^"]*)"|'([^']*)'|([^,:}]+))/.exec(literal)
82
+ const match = /"?command"?\s*:\s*(?:"([^"]*)"|'([^']*)'|([^,}]*))/.exec(literal)
83
83
  const command = (match?.[1] ?? match?.[2] ?? match?.[3] ?? '').trim()
84
84
  return command === '' ? undefined : command
85
85
  }
86
86
 
87
+ const MAX_OUTPUT_CHARS = 12_000
88
+
87
89
  type JsonValue = null | boolean | number | string | JsonValue[] | JsonObject
88
90
 
89
91
  interface JsonObject {
@@ -124,7 +126,11 @@ export function resultText(result: AgentToolResult<unknown>): string {
124
126
  }
125
127
 
126
128
  export function fuseResults<T>(mutation: AgentToolResult<T>, ran: AgentToolResult<unknown>): AgentToolResult<T> {
127
- const output = resultText(ran)
129
+ const raw = resultText(ran)
130
+ const output =
131
+ raw.length > MAX_OUTPUT_CHARS
132
+ ? `${raw.slice(-MAX_OUTPUT_CHARS)}\n[then_run output truncated to the last ${MAX_OUTPUT_CHARS} characters]`
133
+ : raw
128
134
  return {
129
135
  ...mutation,
130
136
  content: [...mutation.content, { type: 'text' as const, text: output ? `${SUCCEEDED}\n${output}` : SUCCEEDED }]
@@ -183,7 +189,10 @@ export default function actionFusionExtension(pi: ExtensionAPI): void {
183
189
  edits: t.array(t.object({ oldText: t.string(), newText: t.string() })),
184
190
  then_run: thenRunSchema
185
191
  }),
186
- prepareArguments: (input) => (isJsonObject(input) ? normalizeEditInput(input) : input) as EditArgs,
192
+ prepareArguments: (input) => {
193
+ const prepared = editBuiltin.prepareArguments?.(input) ?? input
194
+ return (isJsonObject(prepared) ? normalizeEditInput(prepared) : prepared) as EditArgs
195
+ },
187
196
  async execute(toolCallId, input: EditArgs, signal, onUpdate, ctx) {
188
197
  const { then_run, ...mutation } = input as typeof input & { then_run?: ThenRun }
189
198
  const result = await editFor(ctx.cwd).execute(toolCallId, mutation, signal, onUpdate, ctx)