@bastani/atomic 0.9.19-alpha.5 → 0.9.19-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/README.md +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +6 -0
- package/dist/builtin/intercom/broker/client.ts +19 -1
- package/dist/builtin/intercom/index.bundle.mjs +8 -1
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +6 -0
- package/dist/builtin/subagents/README.md +3 -1
- package/dist/builtin/subagents/agents/codebase-online-researcher.md +7 -7
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/subagent/SKILL.md +3 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +2 -1
- package/dist/builtin/web-access/CHANGELOG.md +13 -0
- package/dist/builtin/web-access/README.md +31 -24
- package/dist/builtin/web-access/index.bundle.mjs +16121 -80
- package/dist/builtin/web-access/package.json +2 -1
- package/dist/builtin/workflows/CHANGELOG.md +15 -0
- package/dist/builtin/workflows/README.md +1 -1
- package/dist/builtin/workflows/builtin/adversarial-verification.js +2 -2
- package/dist/builtin/workflows/builtin/{chunk-vhmnzdj9.js → chunk-1jth021m.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-p8jjwfg6.js → chunk-2377r57g.js} +4 -2
- package/dist/builtin/workflows/builtin/{chunk-hbnwv56f.js → chunk-31j2gs7h.js} +2 -2
- package/dist/builtin/workflows/builtin/{chunk-n8zysf1t.js → chunk-ngkqkzej.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-1nbq96fh.js → chunk-nkrafh9s.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-1kx4aggw.js → chunk-wf741bv3.js} +2 -2
- package/dist/builtin/workflows/builtin/{chunk-t6x2d78s.js → chunk-z29qbehr.js} +1 -1
- package/dist/builtin/workflows/builtin/generate-and-filter.js +2 -2
- package/dist/builtin/workflows/builtin/goal.js +3 -3
- package/dist/builtin/workflows/builtin/index.js +7 -7
- package/dist/builtin/workflows/builtin/ralph.js +3 -3
- package/dist/builtin/workflows/builtin/tournament.js +2 -2
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +339 -31
- package/dist/builtin/workflows/src/index.js +67 -19
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +2 -0
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +10 -0
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/tools/bash.d.ts +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +3 -2
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts +3 -0
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +91 -12
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-coordinator.d.ts +255 -0
- package/dist/core/tools/file-mutation-coordinator.d.ts.map +1 -0
- package/dist/core/tools/file-mutation-coordinator.js +300 -0
- package/dist/core/tools/file-mutation-coordinator.js.map +1 -0
- package/dist/core/tools/file-mutation-queue.d.ts +14 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +15 -3
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/hashline.d.ts +9 -0
- package/dist/core/tools/hashline.d.ts.map +1 -1
- package/dist/core/tools/hashline.js +12 -1
- package/dist/core/tools/hashline.js.map +1 -1
- package/dist/core/tools/index.d.ts +9 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +67 -12
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/non-minting-snapshot-store.d.ts +49 -0
- package/dist/core/tools/non-minting-snapshot-store.d.ts.map +1 -0
- package/dist/core/tools/non-minting-snapshot-store.js +64 -0
- package/dist/core/tools/non-minting-snapshot-store.js.map +1 -0
- package/dist/core/tools/powershell.d.ts +2 -2
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/core/tools/powershell.js +2 -5
- package/dist/core/tools/powershell.js.map +1 -1
- package/dist/core/tools/read-document-extract.js.map +1 -1
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/write.d.ts +30 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +97 -8
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/task-live-transcript.d.ts +1 -1
- package/dist/modes/interactive/components/task-live-transcript.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-live-transcript.js +19 -11
- package/dist/modes/interactive/components/task-live-transcript.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.js +3 -1
- package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.js +28 -4
- package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +3 -0
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/modes/interactive-engine/activity-watchdog.d.ts +2 -2
- package/dist/modes/interactive-engine/activity-watchdog.d.ts.map +1 -1
- package/dist/modes/interactive-engine/activity-watchdog.js.map +1 -1
- package/dist/modes/interactive-engine/engine-diagnostic-view.d.ts +3 -1
- package/dist/modes/interactive-engine/engine-diagnostic-view.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-diagnostic-view.js +11 -0
- package/dist/modes/interactive-engine/engine-diagnostic-view.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +2 -1
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/rpc/rpc-client-process.d.ts +2 -0
- package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-process.js +23 -1
- package/dist/modes/rpc/rpc-client-process.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +20 -3
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/utils/markit.d.ts +2 -0
- package/dist/utils/markit.d.ts.map +1 -1
- package/dist/utils/markit.js +65 -5
- package/dist/utils/markit.js.map +1 -1
- package/docs/background-tasks.md +15 -11
- package/docs/build.md +51 -0
- package/docs/changelog.mdx +8 -8
- package/docs/compaction/reference.md +267 -0
- package/docs/compaction.md +36 -219
- package/docs/computer-use.md +35 -0
- package/docs/containerization.md +9 -5
- package/docs/custom-provider/api-reference.md +145 -0
- package/docs/custom-provider/oauth.md +131 -0
- package/docs/custom-provider/override.md +34 -0
- package/docs/custom-provider/registration.md +163 -0
- package/docs/custom-provider/streaming.md +214 -0
- package/docs/custom-provider.md +43 -607
- package/docs/development.md +87 -0
- package/docs/docs.json +199 -76
- package/docs/environment-variables.md +1 -1
- package/docs/extensions/api-reference.md +1001 -0
- package/docs/extensions/authoring.md +676 -0
- package/docs/extensions/events.md +793 -0
- package/docs/extensions/examples.md +94 -0
- package/docs/extensions/ui.md +470 -0
- package/docs/extensions.md +270 -2768
- package/docs/getting-started/authentication.md +55 -0
- package/docs/getting-started/first-session.md +172 -0
- package/docs/getting-started/installation.md +154 -0
- package/docs/getting-started/project-instructions.md +43 -0
- package/docs/guides/configuration.md +65 -0
- package/docs/guides/intercom.md +24 -0
- package/docs/guides/non-interactive.md +33 -0
- package/docs/guides/subagents.md +24 -0
- package/docs/guides/workflows.md +27 -0
- package/docs/guides.md +41 -0
- package/docs/index.md +13 -45
- package/docs/intercom/operations.md +178 -0
- package/docs/intercom/reference.md +146 -0
- package/docs/intercom.md +54 -259
- package/docs/json.md +17 -0
- package/docs/llama-cpp.md +5 -0
- package/docs/models/artificial-analysis-index.md +89 -0
- package/docs/models/evals.md +2 -2
- package/docs/models/model-selection.md +3 -3
- package/docs/models/pareto-efficiency.md +2 -2
- package/docs/models/reference.md +601 -0
- package/docs/models.md +45 -550
- package/docs/packages/authoring.md +88 -0
- package/docs/packages/reference.md +43 -0
- package/docs/packages.md +28 -107
- package/docs/programmatic.md +29 -0
- package/docs/prompt-templates.md +11 -0
- package/docs/providers/reference.md +23 -0
- package/docs/providers.md +10 -15
- package/docs/quickstart.md +44 -238
- package/docs/reference/cli.md +252 -0
- package/docs/reference.md +52 -0
- package/docs/rpc/examples.md +64 -0
- package/docs/rpc/extension-ui.md +198 -0
- package/docs/rpc/protocol.md +1341 -0
- package/docs/rpc.md +109 -1346
- package/docs/sdk/reference.md +1090 -0
- package/docs/sdk.md +56 -1002
- package/docs/session-format.md +2 -0
- package/docs/sessions.md +6 -10
- package/docs/settings.md +6 -45
- package/docs/skills/authoring.md +95 -0
- package/docs/skills/reference.md +60 -0
- package/docs/skills.md +20 -122
- package/docs/subagents/authoring.md +37 -0
- package/docs/subagents/reference.md +60 -0
- package/docs/subagents.md +42 -96
- package/docs/terminal-setup.md +1 -1
- package/docs/themes/reference.md +176 -0
- package/docs/themes.md +21 -135
- package/docs/tmux.md +5 -0
- package/docs/tools/edit.md +5 -0
- package/docs/tools.md +31 -0
- package/docs/tui/reference.md +343 -0
- package/docs/tui.md +23 -286
- package/docs/usage.md +26 -209
- package/docs/web-access.md +40 -0
- package/docs/windows.md +2 -1
- package/docs/workflows/api-reference.md +11 -4
- package/docs/workflows/authoring.md +4 -2
- package/docs/workflows/builtins.md +2 -2
- package/docs/workflows/operations.md +11 -7
- package/docs/workflows/reliable-design.md +21 -3
- package/docs/workflows/verification.md +8 -0
- package/examples/extensions/gondolin/index.ts +116 -148
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/ssh.ts +56 -34
- package/npm-shrinkwrap.json +33 -33
- package/package.json +4 -4
package/dist/core/tools/edit.js
CHANGED
|
@@ -6,9 +6,11 @@ import { renderDiff } from "../../modes/interactive/components/diff.js";
|
|
|
6
6
|
import { nativeBlockResolver } from "./block-resolver.js";
|
|
7
7
|
import { EditBatchCoordinator, parallelEditBatchWarning } from "./edit-batch.js";
|
|
8
8
|
import { generateDiffString, generateUnifiedPatch, normalizeToLF, stripBom } from "./edit-diff.js";
|
|
9
|
-
import {
|
|
9
|
+
import { assertLiveMatchesPrepared, computeLiveState, FileMutationConflict, filesystemErrorCode, isMissingTargetError, } from "./file-mutation-coordinator.js";
|
|
10
|
+
import { canonicalMutationKey, withFileMutationQueue } from "./file-mutation-queue.js";
|
|
10
11
|
import { createHashlineSnapshotStore, formatCompactHashlineEditResult, recordHashlineSnapshot, } from "./hashline.js";
|
|
11
|
-
import { Filesystem, missingSnapshotTagMessage, Patch, Patcher, } from "./hashline-engine/index.js";
|
|
12
|
+
import { Filesystem, MismatchError, missingSnapshotTagMessage, Patch, Patcher, } from "./hashline-engine/index.js";
|
|
13
|
+
import { NonMintingSnapshotStore } from "./non-minting-snapshot-store.js";
|
|
12
14
|
import { isNotebookPath, readEditableNotebookText, serializeEditedNotebookText } from "./notebook.js";
|
|
13
15
|
import { resolveReadPath } from "./path-utils.js";
|
|
14
16
|
import { renderToolPath } from "./render-utils.js";
|
|
@@ -231,9 +233,15 @@ function formatEditResult(result, theme, isError) {
|
|
|
231
233
|
}
|
|
232
234
|
async function withFileMutationQueues(filePaths, fn) {
|
|
233
235
|
const sorted = [...new Set(filePaths)].sort();
|
|
236
|
+
const canonicalKeys = new Map();
|
|
234
237
|
const run = (index) => {
|
|
235
238
|
const filePath = sorted[index];
|
|
236
|
-
return filePath
|
|
239
|
+
return filePath
|
|
240
|
+
? withFileMutationQueue(filePath, (canonicalKey) => {
|
|
241
|
+
canonicalKeys.set(filePath, canonicalKey);
|
|
242
|
+
return run(index + 1);
|
|
243
|
+
})
|
|
244
|
+
: fn(canonicalKeys);
|
|
237
245
|
};
|
|
238
246
|
return run(0);
|
|
239
247
|
}
|
|
@@ -264,17 +272,49 @@ function assertUniquePreparedPaths(prepared) {
|
|
|
264
272
|
}
|
|
265
273
|
function createEditCwdScope(cwd, ops, hashlineStore) {
|
|
266
274
|
const fs = new EditFilesystem(cwd, ops);
|
|
267
|
-
|
|
275
|
+
// Reads delegate to the session store; records are computed and dropped, so a rejection
|
|
276
|
+
// cannot mint the tag that would validate an identical retry. `recordHashlineSnapshot`
|
|
277
|
+
// below stays the single writer of provenance.
|
|
278
|
+
const patcher = new Patcher({
|
|
279
|
+
fs,
|
|
280
|
+
snapshots: new NonMintingSnapshotStore(hashlineStore.snapshots),
|
|
281
|
+
blockResolver: nativeBlockResolver,
|
|
282
|
+
});
|
|
268
283
|
const noopCounts = new Map();
|
|
269
284
|
const batcher = new EditBatchCoordinator();
|
|
270
|
-
|
|
285
|
+
/**
|
|
286
|
+
* `requester` is the identity of the call that reached the lock first. #2496 merges
|
|
287
|
+
* compatible siblings into one planned mutation, and a conflict rejects that mutation as a
|
|
288
|
+
* unit, so naming the batch's holder is accurate. Identity is diagnostic regardless: it
|
|
289
|
+
* never decides whether a sibling is admitted.
|
|
290
|
+
*/
|
|
291
|
+
async function applySiblingEdits(siblings, canonicalKeys, applySignal, requester) {
|
|
271
292
|
const merged = siblings.length === 1
|
|
272
293
|
? Patch.parse(siblings[0].input, { cwd })
|
|
273
294
|
: Patch.parse(siblings.map((sibling) => sibling.input).join("\n"), { cwd });
|
|
274
295
|
const prepared = [];
|
|
275
296
|
for (const section of merged.sections) {
|
|
276
297
|
throwIfAborted(applySignal);
|
|
277
|
-
|
|
298
|
+
try {
|
|
299
|
+
prepared.push(await patcher.prepare(section));
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
// `hashRecognized` is the engine's own answer to "have I ever recorded this tag
|
|
303
|
+
// for this path", so the foreign case is read off a typed field rather than
|
|
304
|
+
// matched out of a message in vendored code. Everything else the engine raises
|
|
305
|
+
// is left alone: recovery successes and the head/tail drift warning never reach
|
|
306
|
+
// here, and a stale-but-known tag keeps the engine's own wording.
|
|
307
|
+
if (!(error instanceof MismatchError) || error.hashRecognized)
|
|
308
|
+
throw error;
|
|
309
|
+
throw new FileMutationConflict({
|
|
310
|
+
reason: "foreign_snapshot",
|
|
311
|
+
path: section.path,
|
|
312
|
+
canonicalKey: await canonicalMutationKey(fs.canonicalPath(section.path)),
|
|
313
|
+
presentedTag: error.expectedFileHash,
|
|
314
|
+
liveState: computeLiveState(error.fileLines.join("\n")),
|
|
315
|
+
...(requester ? { requester } : {}),
|
|
316
|
+
});
|
|
317
|
+
}
|
|
278
318
|
}
|
|
279
319
|
assertUniquePreparedPaths(prepared);
|
|
280
320
|
const noops = prepared.filter((item) => item.isNoop);
|
|
@@ -293,8 +333,43 @@ function createEditCwdScope(cwd, ops, hashlineStore) {
|
|
|
293
333
|
}
|
|
294
334
|
for (const item of prepared) {
|
|
295
335
|
throwIfAborted(applySignal);
|
|
296
|
-
|
|
297
|
-
|
|
336
|
+
let live;
|
|
337
|
+
try {
|
|
338
|
+
live = normalizeToLF(stripBom(await fs.readText(item.section.path)).text);
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
// `prepare` already read this file, so a read failing now means the target changed
|
|
342
|
+
// state under the patch: deleted, replaced by a directory, locked, or rewritten as
|
|
343
|
+
// something this reader cannot parse. Those are all race outcomes rather than tool
|
|
344
|
+
// errors, and letting them escape as raw filesystem errors would hide that from
|
|
345
|
+
// every consumer that tells conflicts apart from ordinary tool failures.
|
|
346
|
+
const missing = isMissingTargetError(error);
|
|
347
|
+
const causeCode = filesystemErrorCode(error);
|
|
348
|
+
throw new FileMutationConflict({
|
|
349
|
+
reason: missing ? "target_missing" : "target_unreadable",
|
|
350
|
+
path: item.section.path,
|
|
351
|
+
// Queue registration resolved this before preparation. A new lookup may fail
|
|
352
|
+
// for the same reason as the read and mask the typed conflict.
|
|
353
|
+
canonicalKey: canonicalKeys.get(item.canonicalPath),
|
|
354
|
+
// Only the missing case can describe the target. Once a read fails for any
|
|
355
|
+
// other cause, its size and tag are unknowable and claiming either is invention.
|
|
356
|
+
...(missing ? { liveState: computeLiveState(undefined) } : {}),
|
|
357
|
+
...(causeCode ? { causeCode } : {}),
|
|
358
|
+
...(requester ? { requester } : {}),
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
// Compared before calling the guard so the happy path skips the extra `realpath`
|
|
362
|
+
// that naming the target canonically costs. The guard still owns the rejection.
|
|
363
|
+
if (live !== item.normalized) {
|
|
364
|
+
assertLiveMatchesPrepared({
|
|
365
|
+
canonicalKey: await canonicalMutationKey(item.canonicalPath),
|
|
366
|
+
path: item.section.path,
|
|
367
|
+
prepared: item.normalized,
|
|
368
|
+
live,
|
|
369
|
+
...(requester ? { requester } : {}),
|
|
370
|
+
...(item.section.fileHash ? { presentedTag: item.section.fileHash } : {}),
|
|
371
|
+
});
|
|
372
|
+
}
|
|
298
373
|
}
|
|
299
374
|
const outputs = [];
|
|
300
375
|
let combinedDiff = "", combinedPatch = "";
|
|
@@ -315,9 +390,13 @@ function createEditCwdScope(cwd, ops, hashlineStore) {
|
|
|
315
390
|
(written.length > 0 ? ` Sections already written: ${written.join(", ")}.` : "") +
|
|
316
391
|
(notWritten.length > 0 ? ` Sections not written: ${notWritten.join(", ")}.` : ""), { cause: error });
|
|
317
392
|
}
|
|
318
|
-
throwIfAborted(applySignal);
|
|
319
393
|
invalidateNativeSearchCache(result.canonicalPath);
|
|
394
|
+
// Recorded before the abort check, not after. `commit` has already written, and since
|
|
395
|
+
// the patcher was made non-minting this call is the only writer of provenance, so
|
|
396
|
+
// aborting first would leave the session's own bytes on disk with nothing recorded
|
|
397
|
+
// for them. The next overwrite would then read as another agent's file.
|
|
320
398
|
const snapshot = recordHashlineSnapshot(result.canonicalPath, cwd, result.after, hashlineStore);
|
|
399
|
+
throwIfAborted(applySignal);
|
|
321
400
|
const diffResult = generateDiffString(result.before, result.after);
|
|
322
401
|
combinedDiff += `${combinedDiff ? "\n" : ""}${diffResult.diff}`;
|
|
323
402
|
combinedPatch += `${combinedPatch ? "\n" : ""}${generateUnifiedPatch(result.path, result.before, result.after)}`;
|
|
@@ -357,7 +436,7 @@ export function createEditToolDefinition(cwd, options) {
|
|
|
357
436
|
promptGuidelines: [...editToolSystemPromptContribution.guidelines],
|
|
358
437
|
constrainedSampling: { type: "json_schema", strict: "prefer" },
|
|
359
438
|
parameters: editSchema,
|
|
360
|
-
async execute(
|
|
439
|
+
async execute(toolCallId, input, signal, _onUpdate, ctx) {
|
|
361
440
|
if (typeof input.input !== "string" || input.input.trim() === "")
|
|
362
441
|
throw new Error("edit input must be a non-empty hashline script with [PATH#TAG] sections.");
|
|
363
442
|
const executionCwd = ctx?.cwd || cwd;
|
|
@@ -371,13 +450,13 @@ export function createEditToolDefinition(cwd, options) {
|
|
|
371
450
|
}
|
|
372
451
|
const entry = batcher.announce(input.input, paths, signal);
|
|
373
452
|
try {
|
|
374
|
-
return await withFileMutationQueues([...paths.keys()].map((sectionPath) => fs.canonicalPath(sectionPath)), async () => {
|
|
453
|
+
return await withFileMutationQueues([...paths.keys()].map((sectionPath) => fs.canonicalPath(sectionPath)), async (canonicalKeys) => {
|
|
375
454
|
if (entry.settled)
|
|
376
455
|
return await entry.promise;
|
|
377
456
|
throwIfAborted(signal);
|
|
378
457
|
const siblings = batcher.takeCompatible(entry);
|
|
379
458
|
try {
|
|
380
|
-
const result = await applySiblingEdits(siblings, signal);
|
|
459
|
+
const result = await applySiblingEdits(siblings, canonicalKeys, signal, options?.resolveMutationRequester?.(toolCallId));
|
|
381
460
|
for (const sibling of siblings)
|
|
382
461
|
sibling.resolve(result);
|
|
383
462
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,QAAQ,IAAI,UAAU,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAGxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACnG,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACN,2BAA2B,EAC3B,+BAA+B,EAE/B,sBAAsB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,UAAU,EACV,yBAAyB,EACzB,KAAK,EACL,OAAO,GAIP,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AACtG,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,UAAU,GAAG,IAA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AAE,OAAO,SAAS,CAAC;YAC9B,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 \"@earendil-works/pi-agent-core\";\nimport { Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, 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.js\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { nativeBlockResolver } from \"./block-resolver.ts\";\nimport { EditBatchCoordinator, parallelEditBatchWarning } from \"./edit-batch.ts\";\nimport { generateDiffString, generateUnifiedPatch, normalizeToLF, stripBom } from \"./edit-diff.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport {\n\tcreateHashlineSnapshotStore,\n\tformatCompactHashlineEditResult,\n\ttype HashlineSnapshotStore,\n\trecordHashlineSnapshot,\n} from \"./hashline.ts\";\nimport {\n\tFilesystem,\n\tmissingSnapshotTagMessage,\n\tPatch,\n\tPatcher,\n\ttype PatchSectionResult,\n\ttype PreparedSection,\n\ttype WriteResult,\n} from \"./hashline-engine/index.ts\";\nimport { isNotebookPath, readEditableNotebookText, serializeEditedNotebookText } from \"./notebook.ts\";\nimport { resolveReadPath } from \"./path-utils.ts\";\nimport { renderToolPath } from \"./render-utils.ts\";\nimport { invalidateNativeSearchCache } from \"./search-native.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst editSchema = Type.Object(\n\t{\n\t\tinput: Type.String({\n\t\t\tdescription:\n\t\t\t\t\"One or more hashline file sections. Must start with [PATH#TAG]; tag comes from the latest read, search, write, or successful edit output.\",\n\t\t}),\n\t},\n\t{ additionalProperties: false },\n);\n// Hashline prompt origin: can1357/oh-my-pi packages/hashline/src/prompt.md @ 15b5c1397fc (MIT).\n// This file carries Atomic-maintained local modifications; see ./hashline-engine/PROVENANCE.md and ./hashline-engine/LICENSE.upstream.\nexport const editToolSystemPromptContribution = Object.freeze({\n\tsnippet: \"Apply source edits with hashline patch input\",\n\tguidelines: Object.freeze([\n\t\t\"hashline edit format: a header ending in ':' is followed by '+TEXT' body rows; 'delete' has no body. Every section starts with [PATH#TAG]; TAG is REQUIRED (the 4-hex snapshot tag from your latest read/search) — there is no hashless form. Use the write tool to create new files.\",\n\t\t\"Ops: 'replace N..M:' replaces original lines N..M (INCLUSIVE — line M is consumed); 'delete N..M' / 'delete block N' delete (no body); 'insert before N:' / 'insert after N:' insert relative to a line; 'insert head:' / 'insert tail:' insert at file start/end. Block ops ('replace block N:', 'delete block N', 'insert after block N:') resolve the exact syntactic node BEGINNING on N through the native Rust tree-sitter `blockRangeAt` primitive in `@bastani/atomic-natives`; the brace/indent heuristic is the fallback only when the native binding is unavailable. Single line: 'replace N..N:' / 'delete N'. The range is the ORIGINAL lines you touch; body length is irrelevant.\",\n\t\t\"Body rows appear only under a ':' header and start on the NEXT line. Every row is '+TEXT' (adds a literal line, leading whitespace kept; '+' alone adds a blank line). There is NO other body row kind — never write '-old' or a bare/context line. To keep a line, leave it out of every range. For a literal line starting with '-' or '+', prefix it: '+-x', '++x'.\",\n\t\t\"Block anchors: 'replace block N' resolves the outermost node BEGINNING on N. Where a language folds a decorator/annotation into its construct (Python folds `@dec` and `def` into one node; TypeScript/Java annotations also fold), anchoring at the first decorator sweeps both. Rust `#[attr]` and doc- or line-comments resolve alone; replacing there with a construct body duplicates the construct, so use explicit 'replace N..M:' to take both. Confirm the result echo: 'replace block N → resolved lines A-B (K lines)'. 'insert after block N:' takes the opener, never the closer; insert-after echoes '; body lands after line B'. Resolution fails for an unsupported language, blank/closer line, no node beginning on N, or an unparsable block; use 'replace N..M:' or 'insert after M:' instead.\",\n\t\t\"Numbers refer to the ORIGINAL file and do not shift as hunks apply; they die with the call — every applied edit mints a fresh #TAG and renumbers, so anchor the next edit on the edit response or a fresh read. Parallel edit calls that share a [path#TAG] are applied as one snapshot batch. Ranges are TIGHT: cover ONLY lines whose content changes; a stale wide range shreds everything it spans. Pure additions use 'insert', never a widened 'replace'. Whole construct → 'replace block N'; lines inside it → 'replace N..M'.\",\n\t\t\"On a stale-tag rejection or any surprising result: STOP and re-read before further edits. Never start or end a range mid-expression/mid-block, and never span a hunk across an elided ('…') region — read it first. Never use edit to reformat/restyle code; run the project formatter instead.\",\n\t\t[\n\t\t\t\"Worked examples. Original (the exact shape `read` returns):\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"1:@cache\",\n\t\t\t\"2:def greet(name):\",\n\t\t\t'3: msg = \"Hello, \" + name',\n\t\t\t\"4: print(msg)\",\n\t\t\t'5:greet(\"world\")',\n\t\t\t\"```\",\n\t\t\t\"Replace one original line with one line:\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"replace 3..3:\",\n\t\t\t'+ msg = f\"Hi, {name}\"',\n\t\t\t\"```\",\n\t\t\t\"Replace the decorated Python block (Python folds `@cache` and `def` into one node; anchoring at line 2 would keep/orphan line 1). For a Rust attribute or doc- or line-comment, use explicit `replace N..M:` to take both it and the construct:\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"replace block 1:\",\n\t\t\t\"+@cache\",\n\t\t\t\"+def greet(name):\",\n\t\t\t'+ print(f\"Hello, {name}\")',\n\t\t\t\"```\",\n\t\t\t\"Delete one line (no colon/body):\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"delete 4\",\n\t\t\t\"```\",\n\t\t\t\"Delete a range (no colon/body):\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"delete 3..4\",\n\t\t\t\"```\",\n\t\t\t\"Delete a whole block (no colon/body):\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"delete block 2\",\n\t\t\t\"```\",\n\t\t\t\"Insert before a line:\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"insert before 5:\",\n\t\t\t\"+log()\",\n\t\t\t\"```\",\n\t\t\t\"Insert after a line:\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"insert after 3:\",\n\t\t\t\"+ print(msg)\",\n\t\t\t\"```\",\n\t\t\t\"Insert after the block whose opener is line 2:\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"insert after block 2:\",\n\t\t\t\"+audit()\",\n\t\t\t\"```\",\n\t\t\t\"Insert at both file ends:\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"insert head:\",\n\t\t\t\"+# generated\",\n\t\t\t\"insert tail:\",\n\t\t\t'+greet(\"everyone\")',\n\t\t\t\"```\",\n\t\t\t\"Multi-file input:\",\n\t\t\t\"```text\",\n\t\t\t\"[src/a.ts#0A3B]\",\n\t\t\t\"replace 1..1:\",\n\t\t\t\"+export const enabled = true;\",\n\t\t\t\"[src/b.ts#1F7C]\",\n\t\t\t\"delete 20\",\n\t\t\t\"```\",\n\t\t].join(\"\\n\"),\n\t\t[\n\t\t\t\"Anti-patterns:\",\n\t\t\t\"```text\",\n\t\t\t\"# WRONG — `-` rows are rejected; bare context rows are auto-prefixed and inserted as literal content: `-` rows are not valid; the range already names the lines being changed. For a literal `-` line, write `+-…`.\",\n\t\t\t\"replace 3..3:\",\n\t\t\t' msg = \"Hello\"',\n\t\t\t\"- print(msg)\",\n\t\t\t\"+ return msg\",\n\t\t\t\"# RIGHT\",\n\t\t\t\"replace 3..3:\",\n\t\t\t\"+ return msg\",\n\t\t\t\"\",\n\t\t\t\"# WRONG — body glued to its header: payload line has no preceding hunk header; body starts on the NEXT line.\",\n\t\t\t\"replace block 238:+export const value = 1;\",\n\t\t\t\"# RIGHT\",\n\t\t\t\"replace block 238:\",\n\t\t\t\"+export const value = 1;\",\n\t\t\t\"\",\n\t\t\t\"# WRONG — `delete N..M` has no colon and no body.\",\n\t\t\t\"delete 2..3:\",\n\t\t\t\"+replacement\",\n\t\t\t\"# RIGHT: delete 2..3\",\n\t\t\t\"\",\n\t\t\t\"# WRONG — empty `insert` / `replace`: `insert` needs at least one `+TEXT` body row. A bodyless concrete `replace` silently deletes the range.\",\n\t\t\t\"insert after 2:\",\n\t\t\t\"replace 4..4:\",\n\t\t\t\"# RIGHT — give `replace` a body; if deletion is intended, write `delete 4`.\",\n\t\t\t\"\",\n\t\t\t\"# WRONG — widened replace for a pure insertion can drop retyped keepers.\",\n\t\t\t\"replace 2..4:\",\n\t\t\t\"+kept()\",\n\t\t\t\"+added()\",\n\t\t\t\"# RIGHT: insert after 2:\",\n\t\t\t\"+added()\",\n\t\t\t\"\",\n\t\t\t\"# WRONG — block anchor is a closer/last visible line.\",\n\t\t\t\"insert after block 3:\",\n\t\t\t\"+after()\",\n\t\t\t\"# RIGHT: insert after 3:\",\n\t\t\t\"+after()\",\n\t\t\t\"```\",\n\t\t].join(\"\\n\"),\n\t\t[\n\t\t\t\"If you remember nothing else:\",\n\t\t\t\"1. RE-GROUND AFTER EVERY EDIT. Every apply mints a fresh #TAG and renumbers; use the edit response or a fresh read. Stale tag or surprise? STOP and re-read.\",\n\t\t\t\"2. RANGES ARE TIGHT. Cover only lines that change; a stale wide range shreds everything it spans. Whole construct → replace block N.\",\n\t\t\t\"3. THE BODY IS THE FINAL CONTENT. Only +TEXT rows; never -old/context lines. The range does the deleting.\",\n\t\t].join(\"\\n\"),\n\t] as const),\n} as const);\n\nexport type EditToolInput = Static<typeof editSchema>;\n\nexport interface EditToolDetails {\n\tdiff: string;\n\tpatch: string;\n\tfirstChangedLine?: number;\n}\n\nexport interface EditOperations {\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\taccess: (absolutePath: string) => Promise<void>;\n}\n\nconst defaultEditOperations: EditOperations = {\n\treadFile: (path) => fsReadFile(path),\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\taccess: (path) => fsAccess(path, constants.R_OK | constants.W_OK),\n};\n\nexport interface EditToolOptions {\n\toperations?: EditOperations;\n\thashlineStore?: HashlineSnapshotStore;\n}\n\ntype EditToolResultLike = {\n\tcontent: Array<{ type: \"text\"; text: string }>;\n\tdetails: EditToolDetails | undefined;\n};\n\nclass EditFilesystem extends Filesystem {\n\tprivate readonly cwd: string;\n\tprivate readonly operations: EditOperations;\n\tconstructor(cwd: string, operations: EditOperations) {\n\t\tsuper();\n\t\tthis.cwd = cwd;\n\t\tthis.operations = operations;\n\t}\n\n\tcanonicalPath(path: string): string {\n\t\treturn resolveReadPath(path, this.cwd);\n\t}\n\n\tasync preflightWrite(path: string): Promise<void> {\n\t\tconst absolutePath = this.canonicalPath(path);\n\t\ttry {\n\t\t\tawait this.operations.access(absolutePath);\n\t\t} catch (error: unknown) {\n\t\t\tconst message = error instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\tthrow new Error(`Could not edit file: ${path}. ${message}.`);\n\t\t}\n\t}\n\n\tasync readText(path: string): Promise<string> {\n\t\tconst absolutePath = this.canonicalPath(path);\n\t\treturn isNotebookPath(absolutePath)\n\t\t\t? readEditableNotebookText(absolutePath, path)\n\t\t\t: (await this.operations.readFile(absolutePath)).toString(\"utf-8\");\n\t}\n\n\tasync writeText(path: string, content: string): Promise<WriteResult> {\n\t\tconst absolutePath = this.canonicalPath(path);\n\t\tconst persisted = isNotebookPath(absolutePath)\n\t\t\t? serializeEditedNotebookText(absolutePath, path, normalizeToLF(stripBom(content).text))\n\t\t\t: content;\n\t\tawait this.operations.writeFile(absolutePath, persisted);\n\t\treturn { text: persisted };\n\t}\n}\n\nfunction isFourDigitHexTag(value: string): boolean {\n\treturn (\n\t\tvalue.length === 4 &&\n\t\t[...value].every(\n\t\t\t(char) => (char >= \"0\" && char <= \"9\") || (char >= \"a\" && char <= \"f\") || (char >= \"A\" && char <= \"F\"),\n\t\t)\n\t);\n}\n\nfunction extractFirstHeaderPath(input: string | undefined): string | undefined {\n\tif (!input) return undefined;\n\tfor (const line of input.split(\"\\n\")) {\n\t\tconst trimmed = line.trimStart();\n\t\tif (!trimmed.startsWith(\"[\")) continue;\n\t\tconst hashIndex = trimmed.indexOf(\"#\", 1);\n\t\tconst closeIndex = hashIndex >= 0 ? trimmed.indexOf(\"]\", hashIndex + 1) : -1;\n\t\tif (hashIndex <= 1 || closeIndex !== hashIndex + 5) continue;\n\t\tconst tag = trimmed.slice(hashIndex + 1, closeIndex);\n\t\tif (isFourDigitHexTag(tag)) return trimmed.slice(1, hashIndex);\n\t}\n\treturn undefined;\n}\n\nfunction formatEditCall(args: unknown, theme: Theme, cwd: string): string {\n\tconst input = args && typeof args === \"object\" && \"input\" in args ? (args as { input?: unknown }).input : undefined;\n\tconst pathDisplay = renderToolPath(\n\t\textractFirstHeaderPath(typeof input === \"string\" ? input : undefined) ?? null,\n\t\ttheme,\n\t\tcwd,\n\t);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nfunction formatEditResult(result: EditToolResultLike, theme: Theme, isError: boolean): string | 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\treturn errorText ? theme.fg(\"error\", errorText) : undefined;\n\t}\n\treturn result.details?.diff ? renderDiff(result.details.diff) : undefined;\n}\n\nasync function withFileMutationQueues<T>(filePaths: readonly string[], fn: () => Promise<T>): Promise<T> {\n\tconst sorted = [...new Set(filePaths)].sort();\n\tconst run = (index: number): Promise<T> => {\n\t\tconst filePath = sorted[index];\n\t\treturn filePath ? withFileMutationQueue(filePath, () => run(index + 1)) : fn();\n\t};\n\treturn run(0);\n}\n\nfunction throwIfAborted(signal?: AbortSignal): void {\n\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n}\n\nfunction formatNoopMessage(path: string, count: number): string {\n\treturn `Edits to ${path} parsed and applied cleanly, but produced no change: your body row(s) are byte-identical to the file at the targeted lines. The bug is somewhere else — re-read the file before issuing another edit. Do NOT widen the payload or add lines; verify the anchor first.${count > 1 ? `\\nNo-op count for this identical payload: ${count}.` : \"\"}`;\n}\n\nfunction blockMessages(item: PreparedSection | PatchSectionResult): string[] {\n\tconst warnings =\n\t\t\"parseWarnings\" in item ? [...item.parseWarnings, ...(item.applyResult.warnings ?? [])] : item.warnings;\n\tconst resolutions =\n\t\t(\"applyResult\" in item ? item.applyResult.blockResolutions : item.blockResolutions)?.map((resolution) => {\n\t\t\tconst verb = resolution.op === \"insert_after\" ? \"insert after block\" : `${resolution.op} block`;\n\t\t\tconst lands = resolution.op === \"insert_after\" ? `; body lands after line ${resolution.end}` : \"\";\n\t\t\treturn `${verb} ${resolution.anchorLine} → resolved lines ${resolution.start}-${resolution.end} (${resolution.end - resolution.start + 1} lines)${lands}`;\n\t\t}) ?? [];\n\treturn [...warnings, ...resolutions];\n}\n\nfunction assertUniquePreparedPaths(prepared: readonly PreparedSection[]): void {\n\tconst seen = new Map<string, string>();\n\tfor (const entry of prepared) {\n\t\tconst previous = seen.get(entry.canonicalPath);\n\t\tif (previous)\n\t\t\tthrow new Error(\n\t\t\t\t`Multiple hashline sections resolve to the same file (${previous} and ${entry.section.path}). Merge their ops under one header before applying.`,\n\t\t\t);\n\t\tseen.set(entry.canonicalPath, entry.section.path);\n\t}\n}\n\ninterface EditCwdScope {\n\treadonly fs: EditFilesystem;\n\treadonly batcher: EditBatchCoordinator<EditToolResultLike>;\n\tapplySiblingEdits(siblings: readonly { input: string }[], applySignal?: AbortSignal): Promise<EditToolResultLike>;\n}\n\nfunction createEditCwdScope(cwd: string, ops: EditOperations, hashlineStore: HashlineSnapshotStore): EditCwdScope {\n\tconst fs = new EditFilesystem(cwd, ops);\n\tconst patcher = new Patcher({ fs, snapshots: hashlineStore.snapshots, blockResolver: nativeBlockResolver });\n\tconst noopCounts = new Map<string, number>();\n\tconst batcher = new EditBatchCoordinator<EditToolResultLike>();\n\tasync function applySiblingEdits(\n\t\tsiblings: readonly { input: string }[],\n\t\tapplySignal?: AbortSignal,\n\t): Promise<EditToolResultLike> {\n\t\tconst merged =\n\t\t\tsiblings.length === 1\n\t\t\t\t? Patch.parse(siblings[0]!.input, { cwd })\n\t\t\t\t: Patch.parse(siblings.map((sibling) => sibling.input).join(\"\\n\"), { cwd });\n\t\tconst prepared: PreparedSection[] = [];\n\t\tfor (const section of merged.sections) {\n\t\t\tthrowIfAborted(applySignal);\n\t\t\tprepared.push(await patcher.prepare(section));\n\t\t}\n\t\tassertUniquePreparedPaths(prepared);\n\t\tconst noops = prepared.filter((item) => item.isNoop);\n\t\tif (noops.length > 0) {\n\t\t\tif (noops.length !== prepared.length)\n\t\t\t\tthrow new Error(`Hashline edit for ${noops[0]!.section.path} did not change the file.`);\n\t\t\tconst key = prepared.map((item) => `${item.canonicalPath}\\0${item.applyResult.text}`).join(\"\\0\\0\");\n\t\t\tconst count = (noopCounts.get(key) ?? 0) + 1;\n\t\t\tnoopCounts.set(key, count);\n\t\t\tif (count >= 3) throw new Error(`STOP. ${formatNoopMessage(prepared[0]!.section.path, count)}`);\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: formatNoopMessage(prepared[0]!.section.path, count) }],\n\t\t\t\tdetails: { diff: \"\", patch: \"\" },\n\t\t\t};\n\t\t}\n\t\tfor (const item of prepared) {\n\t\t\tthrowIfAborted(applySignal);\n\t\t\tif (normalizeToLF(stripBom(await fs.readText(item.section.path)).text) !== item.normalized)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Stale hashline tag for ${item.section.path}: file content changed before write. Re-read before editing.`,\n\t\t\t\t);\n\t\t}\n\t\tconst outputs: string[] = [];\n\t\tlet combinedDiff = \"\",\n\t\t\tcombinedPatch = \"\";\n\t\tlet firstChangedLine: number | undefined;\n\t\tconst batchNote = siblings.length > 1 ? [parallelEditBatchWarning(siblings.length)] : [];\n\t\tfor (let index = 0; index < prepared.length; index++) {\n\t\t\tconst item = prepared[index]!;\n\t\t\tthrowIfAborted(applySignal);\n\t\t\tlet result: PatchSectionResult;\n\t\t\ttry {\n\t\t\t\tresult = await patcher.commit(item);\n\t\t\t} catch (error) {\n\t\t\t\tconst written = prepared.slice(0, index).map((entry) => entry.section.path);\n\t\t\t\tconst notWritten = prepared.slice(index + 1).map((entry) => entry.section.path);\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to write ${item.section.path}: ${message}` +\n\t\t\t\t\t\t(written.length > 0 ? ` Sections already written: ${written.join(\", \")}.` : \"\") +\n\t\t\t\t\t\t(notWritten.length > 0 ? ` Sections not written: ${notWritten.join(\", \")}.` : \"\"),\n\t\t\t\t\t{ cause: error },\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrowIfAborted(applySignal);\n\t\t\tinvalidateNativeSearchCache(result.canonicalPath);\n\t\t\tconst snapshot = recordHashlineSnapshot(result.canonicalPath, cwd, result.after, hashlineStore);\n\t\t\tconst diffResult = generateDiffString(result.before, result.after);\n\t\t\tcombinedDiff += `${combinedDiff ? \"\\n\" : \"\"}${diffResult.diff}`;\n\t\t\tcombinedPatch += `${combinedPatch ? \"\\n\" : \"\"}${generateUnifiedPatch(result.path, result.before, result.after)}`;\n\t\t\tfirstChangedLine ??= diffResult.firstChangedLine;\n\t\t\toutputs.push(formatCompactHashlineEditResult(snapshot, diffResult, [...batchNote, ...blockMessages(result)]));\n\t\t}\n\t\treturn {\n\t\t\tcontent: [{ type: \"text\", text: outputs.join(\"\\n\\n\") }],\n\t\t\tdetails: { diff: combinedDiff, patch: combinedPatch, firstChangedLine },\n\t\t};\n\t}\n\treturn { fs, batcher, applySiblingEdits };\n}\n\nexport function createEditToolDefinition(\n\tcwd: string,\n\toptions?: EditToolOptions,\n): ToolDefinition<typeof editSchema, EditToolDetails | undefined> {\n\tconst ops = options?.operations ?? defaultEditOperations;\n\tconst hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();\n\t// Atomic adaptation of upstream #8627 (\"use ctx.cwd for cwd-sensitive tools\"). Upstream's edit\n\t// tool is a stateless text replacer, so it could resolve `ctx?.cwd || cwd` inline. Atomic's\n\t// hashline patcher instead carries per-tool state — the `EditFilesystem`, the `Patcher`, the\n\t// repeated-no-op counters, and the parallel-edit batcher — that is all keyed to one cwd.\n\t// Mutating a shared cwd field would corrupt concurrent tool calls, so each distinct execution\n\t// cwd gets its own scope. Callers that pass no ctx keep the factory cwd's scope unchanged.\n\tconst scopes = new Map<string, EditCwdScope>();\n\tconst scopeFor = (executionCwd: string): EditCwdScope => {\n\t\tconst existing = scopes.get(executionCwd);\n\t\tif (existing) return existing;\n\t\tconst scope = createEditCwdScope(executionCwd, ops, hashlineStore);\n\t\tscopes.set(executionCwd, scope);\n\t\treturn scope;\n\t};\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit existing files with the hashline patch language: each section starts with [PATH#TAG] (TAG is the 4-hex snapshot tag from your latest read/search), then hunk headers (replace N..M:, replace block N:, delete N..M, delete block N, insert before|after N:, insert after block N:, insert head:, insert tail:) followed by +TEXT body rows. Numbers refer to the original file. Use the write tool to create new files.\",\n\t\tpromptSnippet: editToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...editToolSystemPromptContribution.guidelines],\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tparameters: editSchema,\n\t\tasync execute(_toolCallId, input: EditToolInput, signal?: AbortSignal, _onUpdate?, ctx?: ExtensionContext) {\n\t\t\tif (typeof input.input !== \"string\" || input.input.trim() === \"\")\n\t\t\t\tthrow new Error(\"edit input must be a non-empty hashline script with [PATH#TAG] sections.\");\n\t\t\tconst executionCwd = ctx?.cwd || cwd;\n\t\t\tconst { fs, batcher, applySiblingEdits } = scopeFor(executionCwd);\n\t\t\tconst patch = Patch.parse(input.input, { cwd: executionCwd });\n\t\t\tconst paths = new Map<string, string>();\n\t\t\tfor (const section of patch.sections) {\n\t\t\t\tif (section.fileHash === undefined) throw new Error(missingSnapshotTagMessage(section.path));\n\t\t\t\tpaths.set(section.path, section.fileHash);\n\t\t\t}\n\t\t\tconst entry = batcher.announce(input.input, paths, signal);\n\t\t\ttry {\n\t\t\t\treturn await withFileMutationQueues(\n\t\t\t\t\t[...paths.keys()].map((sectionPath) => fs.canonicalPath(sectionPath)),\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tif (entry.settled) return await entry.promise;\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tconst siblings = batcher.takeCompatible(entry);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst result = await applySiblingEdits(siblings, signal);\n\t\t\t\t\t\t\tfor (const sibling of siblings) sibling.resolve(result);\n\t\t\t\t\t\t\treturn result;\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tfor (const sibling of siblings) sibling.reject(error);\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tif (entry.settled) return await entry.promise;\n\t\t\t\tentry.reject(error);\n\t\t\t\tthrow error;\n\t\t\t} finally {\n\t\t\t\tbatcher.drop(entry);\n\t\t\t}\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatEditCall(args, theme, context.cwd));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst output = formatEditResult(result as EditToolResultLike, 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) return component;\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":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,QAAQ,IAAI,UAAU,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAGxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACnG,OAAO,EACN,yBAAyB,EACzB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,GAGpB,MAAM,gCAAgC,CAAC;AACx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F,CAAC;QACD,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO;YAC9B,MAAM,IAAI,GAAI,OAAO,CAAC,aAAkC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/E,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;YACvD,OAAO,IAAI,CAAC;QACb,CAAC;QACD,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO;YAC5C,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAA4B,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;YACtF,MAAM,SAAS,GAAI,OAAO,CAAC,aAAuC,IAAI,IAAI,SAAS,EAAE,CAAC;YACtF,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,IAAI,CAAC,MAAM;gBAAE,OAAO,SAAS,CAAC;YAC9B,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 \"@earendil-works/pi-agent-core\";\nimport { Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, 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.js\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { nativeBlockResolver } from \"./block-resolver.ts\";\nimport { EditBatchCoordinator, parallelEditBatchWarning } from \"./edit-batch.ts\";\nimport { generateDiffString, generateUnifiedPatch, normalizeToLF, stripBom } from \"./edit-diff.ts\";\nimport {\n\tassertLiveMatchesPrepared,\n\tcomputeLiveState,\n\tFileMutationConflict,\n\tfilesystemErrorCode,\n\tisMissingTargetError,\n\ttype MutationRequester,\n\ttype MutationRequesterResolver,\n} from \"./file-mutation-coordinator.ts\";\nimport { canonicalMutationKey, withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport {\n\tcreateHashlineSnapshotStore,\n\tformatCompactHashlineEditResult,\n\ttype HashlineSnapshotStore,\n\trecordHashlineSnapshot,\n} from \"./hashline.ts\";\nimport {\n\tFilesystem,\n\tMismatchError,\n\tmissingSnapshotTagMessage,\n\tPatch,\n\tPatcher,\n\ttype PatchSectionResult,\n\ttype PreparedSection,\n\ttype WriteResult,\n} from \"./hashline-engine/index.ts\";\nimport { NonMintingSnapshotStore } from \"./non-minting-snapshot-store.ts\";\nimport { isNotebookPath, readEditableNotebookText, serializeEditedNotebookText } from \"./notebook.ts\";\nimport { resolveReadPath } from \"./path-utils.ts\";\nimport { renderToolPath } from \"./render-utils.ts\";\nimport { invalidateNativeSearchCache } from \"./search-native.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst editSchema = Type.Object(\n\t{\n\t\tinput: Type.String({\n\t\t\tdescription:\n\t\t\t\t\"One or more hashline file sections. Must start with [PATH#TAG]; tag comes from the latest read, search, write, or successful edit output.\",\n\t\t}),\n\t},\n\t{ additionalProperties: false },\n);\n// Hashline prompt origin: can1357/oh-my-pi packages/hashline/src/prompt.md @ 15b5c1397fc (MIT).\n// This file carries Atomic-maintained local modifications; see ./hashline-engine/PROVENANCE.md and ./hashline-engine/LICENSE.upstream.\nexport const editToolSystemPromptContribution = Object.freeze({\n\tsnippet: \"Apply source edits with hashline patch input\",\n\tguidelines: Object.freeze([\n\t\t\"hashline edit format: a header ending in ':' is followed by '+TEXT' body rows; 'delete' has no body. Every section starts with [PATH#TAG]; TAG is REQUIRED (the 4-hex snapshot tag from your latest read/search) — there is no hashless form. Use the write tool to create new files.\",\n\t\t\"Ops: 'replace N..M:' replaces original lines N..M (INCLUSIVE — line M is consumed); 'delete N..M' / 'delete block N' delete (no body); 'insert before N:' / 'insert after N:' insert relative to a line; 'insert head:' / 'insert tail:' insert at file start/end. Block ops ('replace block N:', 'delete block N', 'insert after block N:') resolve the exact syntactic node BEGINNING on N through the native Rust tree-sitter `blockRangeAt` primitive in `@bastani/atomic-natives`; the brace/indent heuristic is the fallback only when the native binding is unavailable. Single line: 'replace N..N:' / 'delete N'. The range is the ORIGINAL lines you touch; body length is irrelevant.\",\n\t\t\"Body rows appear only under a ':' header and start on the NEXT line. Every row is '+TEXT' (adds a literal line, leading whitespace kept; '+' alone adds a blank line). There is NO other body row kind — never write '-old' or a bare/context line. To keep a line, leave it out of every range. For a literal line starting with '-' or '+', prefix it: '+-x', '++x'.\",\n\t\t\"Block anchors: 'replace block N' resolves the outermost node BEGINNING on N. Where a language folds a decorator/annotation into its construct (Python folds `@dec` and `def` into one node; TypeScript/Java annotations also fold), anchoring at the first decorator sweeps both. Rust `#[attr]` and doc- or line-comments resolve alone; replacing there with a construct body duplicates the construct, so use explicit 'replace N..M:' to take both. Confirm the result echo: 'replace block N → resolved lines A-B (K lines)'. 'insert after block N:' takes the opener, never the closer; insert-after echoes '; body lands after line B'. Resolution fails for an unsupported language, blank/closer line, no node beginning on N, or an unparsable block; use 'replace N..M:' or 'insert after M:' instead.\",\n\t\t\"Numbers refer to the ORIGINAL file and do not shift as hunks apply; they die with the call — every applied edit mints a fresh #TAG and renumbers, so anchor the next edit on the edit response or a fresh read. Parallel edit calls that share a [path#TAG] are applied as one snapshot batch. Ranges are TIGHT: cover ONLY lines whose content changes; a stale wide range shreds everything it spans. Pure additions use 'insert', never a widened 'replace'. Whole construct → 'replace block N'; lines inside it → 'replace N..M'.\",\n\t\t\"On a stale-tag rejection or any surprising result: STOP and re-read before further edits. Never start or end a range mid-expression/mid-block, and never span a hunk across an elided ('…') region — read it first. Never use edit to reformat/restyle code; run the project formatter instead.\",\n\t\t[\n\t\t\t\"Worked examples. Original (the exact shape `read` returns):\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"1:@cache\",\n\t\t\t\"2:def greet(name):\",\n\t\t\t'3: msg = \"Hello, \" + name',\n\t\t\t\"4: print(msg)\",\n\t\t\t'5:greet(\"world\")',\n\t\t\t\"```\",\n\t\t\t\"Replace one original line with one line:\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"replace 3..3:\",\n\t\t\t'+ msg = f\"Hi, {name}\"',\n\t\t\t\"```\",\n\t\t\t\"Replace the decorated Python block (Python folds `@cache` and `def` into one node; anchoring at line 2 would keep/orphan line 1). For a Rust attribute or doc- or line-comment, use explicit `replace N..M:` to take both it and the construct:\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"replace block 1:\",\n\t\t\t\"+@cache\",\n\t\t\t\"+def greet(name):\",\n\t\t\t'+ print(f\"Hello, {name}\")',\n\t\t\t\"```\",\n\t\t\t\"Delete one line (no colon/body):\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"delete 4\",\n\t\t\t\"```\",\n\t\t\t\"Delete a range (no colon/body):\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"delete 3..4\",\n\t\t\t\"```\",\n\t\t\t\"Delete a whole block (no colon/body):\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"delete block 2\",\n\t\t\t\"```\",\n\t\t\t\"Insert before a line:\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"insert before 5:\",\n\t\t\t\"+log()\",\n\t\t\t\"```\",\n\t\t\t\"Insert after a line:\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"insert after 3:\",\n\t\t\t\"+ print(msg)\",\n\t\t\t\"```\",\n\t\t\t\"Insert after the block whose opener is line 2:\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"insert after block 2:\",\n\t\t\t\"+audit()\",\n\t\t\t\"```\",\n\t\t\t\"Insert at both file ends:\",\n\t\t\t\"```text\",\n\t\t\t\"[greet.py#A1B2]\",\n\t\t\t\"insert head:\",\n\t\t\t\"+# generated\",\n\t\t\t\"insert tail:\",\n\t\t\t'+greet(\"everyone\")',\n\t\t\t\"```\",\n\t\t\t\"Multi-file input:\",\n\t\t\t\"```text\",\n\t\t\t\"[src/a.ts#0A3B]\",\n\t\t\t\"replace 1..1:\",\n\t\t\t\"+export const enabled = true;\",\n\t\t\t\"[src/b.ts#1F7C]\",\n\t\t\t\"delete 20\",\n\t\t\t\"```\",\n\t\t].join(\"\\n\"),\n\t\t[\n\t\t\t\"Anti-patterns:\",\n\t\t\t\"```text\",\n\t\t\t\"# WRONG — `-` rows are rejected; bare context rows are auto-prefixed and inserted as literal content: `-` rows are not valid; the range already names the lines being changed. For a literal `-` line, write `+-…`.\",\n\t\t\t\"replace 3..3:\",\n\t\t\t' msg = \"Hello\"',\n\t\t\t\"- print(msg)\",\n\t\t\t\"+ return msg\",\n\t\t\t\"# RIGHT\",\n\t\t\t\"replace 3..3:\",\n\t\t\t\"+ return msg\",\n\t\t\t\"\",\n\t\t\t\"# WRONG — body glued to its header: payload line has no preceding hunk header; body starts on the NEXT line.\",\n\t\t\t\"replace block 238:+export const value = 1;\",\n\t\t\t\"# RIGHT\",\n\t\t\t\"replace block 238:\",\n\t\t\t\"+export const value = 1;\",\n\t\t\t\"\",\n\t\t\t\"# WRONG — `delete N..M` has no colon and no body.\",\n\t\t\t\"delete 2..3:\",\n\t\t\t\"+replacement\",\n\t\t\t\"# RIGHT: delete 2..3\",\n\t\t\t\"\",\n\t\t\t\"# WRONG — empty `insert` / `replace`: `insert` needs at least one `+TEXT` body row. A bodyless concrete `replace` silently deletes the range.\",\n\t\t\t\"insert after 2:\",\n\t\t\t\"replace 4..4:\",\n\t\t\t\"# RIGHT — give `replace` a body; if deletion is intended, write `delete 4`.\",\n\t\t\t\"\",\n\t\t\t\"# WRONG — widened replace for a pure insertion can drop retyped keepers.\",\n\t\t\t\"replace 2..4:\",\n\t\t\t\"+kept()\",\n\t\t\t\"+added()\",\n\t\t\t\"# RIGHT: insert after 2:\",\n\t\t\t\"+added()\",\n\t\t\t\"\",\n\t\t\t\"# WRONG — block anchor is a closer/last visible line.\",\n\t\t\t\"insert after block 3:\",\n\t\t\t\"+after()\",\n\t\t\t\"# RIGHT: insert after 3:\",\n\t\t\t\"+after()\",\n\t\t\t\"```\",\n\t\t].join(\"\\n\"),\n\t\t[\n\t\t\t\"If you remember nothing else:\",\n\t\t\t\"1. RE-GROUND AFTER EVERY EDIT. Every apply mints a fresh #TAG and renumbers; use the edit response or a fresh read. Stale tag or surprise? STOP and re-read.\",\n\t\t\t\"2. RANGES ARE TIGHT. Cover only lines that change; a stale wide range shreds everything it spans. Whole construct → replace block N.\",\n\t\t\t\"3. THE BODY IS THE FINAL CONTENT. Only +TEXT rows; never -old/context lines. The range does the deleting.\",\n\t\t].join(\"\\n\"),\n\t] as const),\n} as const);\n\nexport type EditToolInput = Static<typeof editSchema>;\n\nexport interface EditToolDetails {\n\tdiff: string;\n\tpatch: string;\n\tfirstChangedLine?: number;\n}\n\nexport interface EditOperations {\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\taccess: (absolutePath: string) => Promise<void>;\n}\n\nconst defaultEditOperations: EditOperations = {\n\treadFile: (path) => fsReadFile(path),\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\taccess: (path) => fsAccess(path, constants.R_OK | constants.W_OK),\n};\n\nexport interface EditToolOptions {\n\toperations?: EditOperations;\n\thashlineStore?: HashlineSnapshotStore;\n\t/** Resolves who is being rejected when a mutation conflicts. Diagnostic only. */\n\tresolveMutationRequester?: MutationRequesterResolver;\n}\n\ntype EditToolResultLike = {\n\tcontent: Array<{ type: \"text\"; text: string }>;\n\tdetails: EditToolDetails | undefined;\n};\n\nclass EditFilesystem extends Filesystem {\n\tprivate readonly cwd: string;\n\tprivate readonly operations: EditOperations;\n\tconstructor(cwd: string, operations: EditOperations) {\n\t\tsuper();\n\t\tthis.cwd = cwd;\n\t\tthis.operations = operations;\n\t}\n\n\tcanonicalPath(path: string): string {\n\t\treturn resolveReadPath(path, this.cwd);\n\t}\n\n\tasync preflightWrite(path: string): Promise<void> {\n\t\tconst absolutePath = this.canonicalPath(path);\n\t\ttry {\n\t\t\tawait this.operations.access(absolutePath);\n\t\t} catch (error: unknown) {\n\t\t\tconst message = error instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\tthrow new Error(`Could not edit file: ${path}. ${message}.`);\n\t\t}\n\t}\n\n\tasync readText(path: string): Promise<string> {\n\t\tconst absolutePath = this.canonicalPath(path);\n\t\treturn isNotebookPath(absolutePath)\n\t\t\t? readEditableNotebookText(absolutePath, path)\n\t\t\t: (await this.operations.readFile(absolutePath)).toString(\"utf-8\");\n\t}\n\n\tasync writeText(path: string, content: string): Promise<WriteResult> {\n\t\tconst absolutePath = this.canonicalPath(path);\n\t\tconst persisted = isNotebookPath(absolutePath)\n\t\t\t? serializeEditedNotebookText(absolutePath, path, normalizeToLF(stripBom(content).text))\n\t\t\t: content;\n\t\tawait this.operations.writeFile(absolutePath, persisted);\n\t\treturn { text: persisted };\n\t}\n}\n\nfunction isFourDigitHexTag(value: string): boolean {\n\treturn (\n\t\tvalue.length === 4 &&\n\t\t[...value].every(\n\t\t\t(char) => (char >= \"0\" && char <= \"9\") || (char >= \"a\" && char <= \"f\") || (char >= \"A\" && char <= \"F\"),\n\t\t)\n\t);\n}\n\nfunction extractFirstHeaderPath(input: string | undefined): string | undefined {\n\tif (!input) return undefined;\n\tfor (const line of input.split(\"\\n\")) {\n\t\tconst trimmed = line.trimStart();\n\t\tif (!trimmed.startsWith(\"[\")) continue;\n\t\tconst hashIndex = trimmed.indexOf(\"#\", 1);\n\t\tconst closeIndex = hashIndex >= 0 ? trimmed.indexOf(\"]\", hashIndex + 1) : -1;\n\t\tif (hashIndex <= 1 || closeIndex !== hashIndex + 5) continue;\n\t\tconst tag = trimmed.slice(hashIndex + 1, closeIndex);\n\t\tif (isFourDigitHexTag(tag)) return trimmed.slice(1, hashIndex);\n\t}\n\treturn undefined;\n}\n\nfunction formatEditCall(args: unknown, theme: Theme, cwd: string): string {\n\tconst input = args && typeof args === \"object\" && \"input\" in args ? (args as { input?: unknown }).input : undefined;\n\tconst pathDisplay = renderToolPath(\n\t\textractFirstHeaderPath(typeof input === \"string\" ? input : undefined) ?? null,\n\t\ttheme,\n\t\tcwd,\n\t);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nfunction formatEditResult(result: EditToolResultLike, theme: Theme, isError: boolean): string | 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\treturn errorText ? theme.fg(\"error\", errorText) : undefined;\n\t}\n\treturn result.details?.diff ? renderDiff(result.details.diff) : undefined;\n}\n\nasync function withFileMutationQueues<T>(\n\tfilePaths: readonly string[],\n\tfn: (canonicalKeys: ReadonlyMap<string, string>) => Promise<T>,\n): Promise<T> {\n\tconst sorted = [...new Set(filePaths)].sort();\n\tconst canonicalKeys = new Map<string, string>();\n\tconst run = (index: number): Promise<T> => {\n\t\tconst filePath = sorted[index];\n\t\treturn filePath\n\t\t\t? withFileMutationQueue(filePath, (canonicalKey) => {\n\t\t\t\t\tcanonicalKeys.set(filePath, canonicalKey);\n\t\t\t\t\treturn run(index + 1);\n\t\t\t\t})\n\t\t\t: fn(canonicalKeys);\n\t};\n\treturn run(0);\n}\n\nfunction throwIfAborted(signal?: AbortSignal): void {\n\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n}\n\nfunction formatNoopMessage(path: string, count: number): string {\n\treturn `Edits to ${path} parsed and applied cleanly, but produced no change: your body row(s) are byte-identical to the file at the targeted lines. The bug is somewhere else — re-read the file before issuing another edit. Do NOT widen the payload or add lines; verify the anchor first.${count > 1 ? `\\nNo-op count for this identical payload: ${count}.` : \"\"}`;\n}\n\nfunction blockMessages(item: PreparedSection | PatchSectionResult): string[] {\n\tconst warnings =\n\t\t\"parseWarnings\" in item ? [...item.parseWarnings, ...(item.applyResult.warnings ?? [])] : item.warnings;\n\tconst resolutions =\n\t\t(\"applyResult\" in item ? item.applyResult.blockResolutions : item.blockResolutions)?.map((resolution) => {\n\t\t\tconst verb = resolution.op === \"insert_after\" ? \"insert after block\" : `${resolution.op} block`;\n\t\t\tconst lands = resolution.op === \"insert_after\" ? `; body lands after line ${resolution.end}` : \"\";\n\t\t\treturn `${verb} ${resolution.anchorLine} → resolved lines ${resolution.start}-${resolution.end} (${resolution.end - resolution.start + 1} lines)${lands}`;\n\t\t}) ?? [];\n\treturn [...warnings, ...resolutions];\n}\n\nfunction assertUniquePreparedPaths(prepared: readonly PreparedSection[]): void {\n\tconst seen = new Map<string, string>();\n\tfor (const entry of prepared) {\n\t\tconst previous = seen.get(entry.canonicalPath);\n\t\tif (previous)\n\t\t\tthrow new Error(\n\t\t\t\t`Multiple hashline sections resolve to the same file (${previous} and ${entry.section.path}). Merge their ops under one header before applying.`,\n\t\t\t);\n\t\tseen.set(entry.canonicalPath, entry.section.path);\n\t}\n}\n\ninterface EditCwdScope {\n\treadonly fs: EditFilesystem;\n\treadonly batcher: EditBatchCoordinator<EditToolResultLike>;\n\tapplySiblingEdits(\n\t\tsiblings: readonly { input: string }[],\n\t\tcanonicalKeys: ReadonlyMap<string, string>,\n\t\tapplySignal?: AbortSignal,\n\t\trequester?: MutationRequester,\n\t): Promise<EditToolResultLike>;\n}\n\nfunction createEditCwdScope(cwd: string, ops: EditOperations, hashlineStore: HashlineSnapshotStore): EditCwdScope {\n\tconst fs = new EditFilesystem(cwd, ops);\n\t// Reads delegate to the session store; records are computed and dropped, so a rejection\n\t// cannot mint the tag that would validate an identical retry. `recordHashlineSnapshot`\n\t// below stays the single writer of provenance.\n\tconst patcher = new Patcher({\n\t\tfs,\n\t\tsnapshots: new NonMintingSnapshotStore(hashlineStore.snapshots),\n\t\tblockResolver: nativeBlockResolver,\n\t});\n\tconst noopCounts = new Map<string, number>();\n\tconst batcher = new EditBatchCoordinator<EditToolResultLike>();\n\t/**\n\t * `requester` is the identity of the call that reached the lock first. #2496 merges\n\t * compatible siblings into one planned mutation, and a conflict rejects that mutation as a\n\t * unit, so naming the batch's holder is accurate. Identity is diagnostic regardless: it\n\t * never decides whether a sibling is admitted.\n\t */\n\tasync function applySiblingEdits(\n\t\tsiblings: readonly { input: string }[],\n\t\tcanonicalKeys: ReadonlyMap<string, string>,\n\t\tapplySignal?: AbortSignal,\n\t\trequester?: MutationRequester,\n\t): Promise<EditToolResultLike> {\n\t\tconst merged =\n\t\t\tsiblings.length === 1\n\t\t\t\t? Patch.parse(siblings[0]!.input, { cwd })\n\t\t\t\t: Patch.parse(siblings.map((sibling) => sibling.input).join(\"\\n\"), { cwd });\n\t\tconst prepared: PreparedSection[] = [];\n\t\tfor (const section of merged.sections) {\n\t\t\tthrowIfAborted(applySignal);\n\t\t\ttry {\n\t\t\t\tprepared.push(await patcher.prepare(section));\n\t\t\t} catch (error) {\n\t\t\t\t// `hashRecognized` is the engine's own answer to \"have I ever recorded this tag\n\t\t\t\t// for this path\", so the foreign case is read off a typed field rather than\n\t\t\t\t// matched out of a message in vendored code. Everything else the engine raises\n\t\t\t\t// is left alone: recovery successes and the head/tail drift warning never reach\n\t\t\t\t// here, and a stale-but-known tag keeps the engine's own wording.\n\t\t\t\tif (!(error instanceof MismatchError) || error.hashRecognized) throw error;\n\t\t\t\tthrow new FileMutationConflict({\n\t\t\t\t\treason: \"foreign_snapshot\",\n\t\t\t\t\tpath: section.path,\n\t\t\t\t\tcanonicalKey: await canonicalMutationKey(fs.canonicalPath(section.path)),\n\t\t\t\t\tpresentedTag: error.expectedFileHash,\n\t\t\t\t\tliveState: computeLiveState(error.fileLines.join(\"\\n\")),\n\t\t\t\t\t...(requester ? { requester } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tassertUniquePreparedPaths(prepared);\n\t\tconst noops = prepared.filter((item) => item.isNoop);\n\t\tif (noops.length > 0) {\n\t\t\tif (noops.length !== prepared.length)\n\t\t\t\tthrow new Error(`Hashline edit for ${noops[0]!.section.path} did not change the file.`);\n\t\t\tconst key = prepared.map((item) => `${item.canonicalPath}\\0${item.applyResult.text}`).join(\"\\0\\0\");\n\t\t\tconst count = (noopCounts.get(key) ?? 0) + 1;\n\t\t\tnoopCounts.set(key, count);\n\t\t\tif (count >= 3) throw new Error(`STOP. ${formatNoopMessage(prepared[0]!.section.path, count)}`);\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: formatNoopMessage(prepared[0]!.section.path, count) }],\n\t\t\t\tdetails: { diff: \"\", patch: \"\" },\n\t\t\t};\n\t\t}\n\t\tfor (const item of prepared) {\n\t\t\tthrowIfAborted(applySignal);\n\t\t\tlet live: string;\n\t\t\ttry {\n\t\t\t\tlive = normalizeToLF(stripBom(await fs.readText(item.section.path)).text);\n\t\t\t} catch (error) {\n\t\t\t\t// `prepare` already read this file, so a read failing now means the target changed\n\t\t\t\t// state under the patch: deleted, replaced by a directory, locked, or rewritten as\n\t\t\t\t// something this reader cannot parse. Those are all race outcomes rather than tool\n\t\t\t\t// errors, and letting them escape as raw filesystem errors would hide that from\n\t\t\t\t// every consumer that tells conflicts apart from ordinary tool failures.\n\t\t\t\tconst missing = isMissingTargetError(error);\n\t\t\t\tconst causeCode = filesystemErrorCode(error);\n\t\t\t\tthrow new FileMutationConflict({\n\t\t\t\t\treason: missing ? \"target_missing\" : \"target_unreadable\",\n\t\t\t\t\tpath: item.section.path,\n\t\t\t\t\t// Queue registration resolved this before preparation. A new lookup may fail\n\t\t\t\t\t// for the same reason as the read and mask the typed conflict.\n\t\t\t\t\tcanonicalKey: canonicalKeys.get(item.canonicalPath)!,\n\t\t\t\t\t// Only the missing case can describe the target. Once a read fails for any\n\t\t\t\t\t// other cause, its size and tag are unknowable and claiming either is invention.\n\t\t\t\t\t...(missing ? { liveState: computeLiveState(undefined) } : {}),\n\t\t\t\t\t...(causeCode ? { causeCode } : {}),\n\t\t\t\t\t...(requester ? { requester } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t\t// Compared before calling the guard so the happy path skips the extra `realpath`\n\t\t\t// that naming the target canonically costs. The guard still owns the rejection.\n\t\t\tif (live !== item.normalized) {\n\t\t\t\tassertLiveMatchesPrepared({\n\t\t\t\t\tcanonicalKey: await canonicalMutationKey(item.canonicalPath),\n\t\t\t\t\tpath: item.section.path,\n\t\t\t\t\tprepared: item.normalized,\n\t\t\t\t\tlive,\n\t\t\t\t\t...(requester ? { requester } : {}),\n\t\t\t\t\t...(item.section.fileHash ? { presentedTag: item.section.fileHash } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tconst outputs: string[] = [];\n\t\tlet combinedDiff = \"\",\n\t\t\tcombinedPatch = \"\";\n\t\tlet firstChangedLine: number | undefined;\n\t\tconst batchNote = siblings.length > 1 ? [parallelEditBatchWarning(siblings.length)] : [];\n\t\tfor (let index = 0; index < prepared.length; index++) {\n\t\t\tconst item = prepared[index]!;\n\t\t\tthrowIfAborted(applySignal);\n\t\t\tlet result: PatchSectionResult;\n\t\t\ttry {\n\t\t\t\tresult = await patcher.commit(item);\n\t\t\t} catch (error) {\n\t\t\t\tconst written = prepared.slice(0, index).map((entry) => entry.section.path);\n\t\t\t\tconst notWritten = prepared.slice(index + 1).map((entry) => entry.section.path);\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to write ${item.section.path}: ${message}` +\n\t\t\t\t\t\t(written.length > 0 ? ` Sections already written: ${written.join(\", \")}.` : \"\") +\n\t\t\t\t\t\t(notWritten.length > 0 ? ` Sections not written: ${notWritten.join(\", \")}.` : \"\"),\n\t\t\t\t\t{ cause: error },\n\t\t\t\t);\n\t\t\t}\n\t\t\tinvalidateNativeSearchCache(result.canonicalPath);\n\t\t\t// Recorded before the abort check, not after. `commit` has already written, and since\n\t\t\t// the patcher was made non-minting this call is the only writer of provenance, so\n\t\t\t// aborting first would leave the session's own bytes on disk with nothing recorded\n\t\t\t// for them. The next overwrite would then read as another agent's file.\n\t\t\tconst snapshot = recordHashlineSnapshot(result.canonicalPath, cwd, result.after, hashlineStore);\n\t\t\tthrowIfAborted(applySignal);\n\t\t\tconst diffResult = generateDiffString(result.before, result.after);\n\t\t\tcombinedDiff += `${combinedDiff ? \"\\n\" : \"\"}${diffResult.diff}`;\n\t\t\tcombinedPatch += `${combinedPatch ? \"\\n\" : \"\"}${generateUnifiedPatch(result.path, result.before, result.after)}`;\n\t\t\tfirstChangedLine ??= diffResult.firstChangedLine;\n\t\t\toutputs.push(formatCompactHashlineEditResult(snapshot, diffResult, [...batchNote, ...blockMessages(result)]));\n\t\t}\n\t\treturn {\n\t\t\tcontent: [{ type: \"text\", text: outputs.join(\"\\n\\n\") }],\n\t\t\tdetails: { diff: combinedDiff, patch: combinedPatch, firstChangedLine },\n\t\t};\n\t}\n\treturn { fs, batcher, applySiblingEdits };\n}\n\nexport function createEditToolDefinition(\n\tcwd: string,\n\toptions?: EditToolOptions,\n): ToolDefinition<typeof editSchema, EditToolDetails | undefined> {\n\tconst ops = options?.operations ?? defaultEditOperations;\n\tconst hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();\n\t// Atomic adaptation of upstream #8627 (\"use ctx.cwd for cwd-sensitive tools\"). Upstream's edit\n\t// tool is a stateless text replacer, so it could resolve `ctx?.cwd || cwd` inline. Atomic's\n\t// hashline patcher instead carries per-tool state — the `EditFilesystem`, the `Patcher`, the\n\t// repeated-no-op counters, and the parallel-edit batcher — that is all keyed to one cwd.\n\t// Mutating a shared cwd field would corrupt concurrent tool calls, so each distinct execution\n\t// cwd gets its own scope. Callers that pass no ctx keep the factory cwd's scope unchanged.\n\tconst scopes = new Map<string, EditCwdScope>();\n\tconst scopeFor = (executionCwd: string): EditCwdScope => {\n\t\tconst existing = scopes.get(executionCwd);\n\t\tif (existing) return existing;\n\t\tconst scope = createEditCwdScope(executionCwd, ops, hashlineStore);\n\t\tscopes.set(executionCwd, scope);\n\t\treturn scope;\n\t};\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit existing files with the hashline patch language: each section starts with [PATH#TAG] (TAG is the 4-hex snapshot tag from your latest read/search), then hunk headers (replace N..M:, replace block N:, delete N..M, delete block N, insert before|after N:, insert after block N:, insert head:, insert tail:) followed by +TEXT body rows. Numbers refer to the original file. Use the write tool to create new files.\",\n\t\tpromptSnippet: editToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...editToolSystemPromptContribution.guidelines],\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tparameters: editSchema,\n\t\tasync execute(toolCallId, input: EditToolInput, signal?: AbortSignal, _onUpdate?, ctx?: ExtensionContext) {\n\t\t\tif (typeof input.input !== \"string\" || input.input.trim() === \"\")\n\t\t\t\tthrow new Error(\"edit input must be a non-empty hashline script with [PATH#TAG] sections.\");\n\t\t\tconst executionCwd = ctx?.cwd || cwd;\n\t\t\tconst { fs, batcher, applySiblingEdits } = scopeFor(executionCwd);\n\t\t\tconst patch = Patch.parse(input.input, { cwd: executionCwd });\n\t\t\tconst paths = new Map<string, string>();\n\t\t\tfor (const section of patch.sections) {\n\t\t\t\tif (section.fileHash === undefined) throw new Error(missingSnapshotTagMessage(section.path));\n\t\t\t\tpaths.set(section.path, section.fileHash);\n\t\t\t}\n\t\t\tconst entry = batcher.announce(input.input, paths, signal);\n\t\t\ttry {\n\t\t\t\treturn await withFileMutationQueues(\n\t\t\t\t\t[...paths.keys()].map((sectionPath) => fs.canonicalPath(sectionPath)),\n\t\t\t\t\tasync (canonicalKeys) => {\n\t\t\t\t\t\tif (entry.settled) return await entry.promise;\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tconst siblings = batcher.takeCompatible(entry);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst result = await applySiblingEdits(\n\t\t\t\t\t\t\t\tsiblings,\n\t\t\t\t\t\t\t\tcanonicalKeys,\n\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\toptions?.resolveMutationRequester?.(toolCallId),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tfor (const sibling of siblings) sibling.resolve(result);\n\t\t\t\t\t\t\treturn result;\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tfor (const sibling of siblings) sibling.reject(error);\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tif (entry.settled) return await entry.promise;\n\t\t\t\tentry.reject(error);\n\t\t\t\tthrow error;\n\t\t\t} finally {\n\t\t\t\tbatcher.drop(entry);\n\t\t\t}\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatEditCall(args, theme, context.cwd));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst output = formatEditResult(result as EditToolResultLike, 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) return component;\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"]}
|