@criogaid/pi-hashline-edit 0.1.1 → 0.1.3
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/README.md +168 -197
- package/package.json +1 -1
- package/src/core/apply.test.ts +40 -1
- package/src/core/apply.ts +13 -3
- package/src/core/hash.test.ts +7 -3
- package/src/core/hash.ts +6 -10
- package/src/core/index.ts +1 -0
- package/src/core/text.test.ts +15 -0
- package/src/core/text.ts +18 -0
- package/src/core/types.ts +1 -2
- package/src/index.ts +4 -3
- package/src/integration/grep-rg.test.ts +20 -0
- package/src/pi/action-fusion.test.ts +8 -6
- package/src/pi/action-fusion.ts +39 -18
- package/src/pi/config.test.ts +28 -8
- package/src/pi/config.ts +9 -7
- package/src/pi/edit-tool.ts +44 -70
- package/src/pi/execute.test.ts +50 -1
- package/src/pi/failure-path.test.ts +10 -7
- package/src/pi/file-commit.test.ts +29 -1
- package/src/pi/file-commit.ts +39 -7
- package/src/pi/fusion-card.test.ts +1 -1
- package/src/pi/grep-tool.ts +20 -34
- package/src/pi/grep.test.ts +24 -6
- package/src/pi/mutation-result.ts +46 -0
- package/src/pi/read-tool.ts +4 -4
- package/src/pi/registration.test.ts +69 -9
- package/src/pi/render.ts +51 -1
- package/src/pi/replace-tool.ts +34 -44
- package/src/pi/result-safety.test.ts +169 -0
- package/src/pi/state.ts +2 -3
- package/src/pi/write-tool.ts +12 -2
- package/src/pi/write.test.ts +7 -1
package/src/pi/state.ts
CHANGED
|
@@ -8,10 +8,9 @@
|
|
|
8
8
|
* @module pi-hashline-edit/pi
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import type
|
|
11
|
+
import { DEFAULT_CONFIG, type HashlineEditConfig } from "./config.ts";
|
|
12
12
|
|
|
13
13
|
const GLOBAL_KEY = "__piHashlineEdit";
|
|
14
|
-
const DEFAULT_CONFIG: HashlineEditConfig = { enabled: true, actionFusion: false, hashLen: 4, shiftRadius: 15 };
|
|
15
14
|
|
|
16
15
|
export interface HashlineEditState {
|
|
17
16
|
config: HashlineEditConfig;
|
|
@@ -21,7 +20,7 @@ export function getState(): HashlineEditState {
|
|
|
21
20
|
const g = globalThis as Record<string, unknown>;
|
|
22
21
|
const existing = g[GLOBAL_KEY];
|
|
23
22
|
if (existing) return existing as HashlineEditState;
|
|
24
|
-
const state: HashlineEditState = { config: DEFAULT_CONFIG };
|
|
23
|
+
const state: HashlineEditState = { config: { ...DEFAULT_CONFIG } };
|
|
25
24
|
g[GLOBAL_KEY] = state;
|
|
26
25
|
return state;
|
|
27
26
|
}
|
package/src/pi/write-tool.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { ACTION_FUSION_GUIDELINES, createActionFusionExecutor, createThenRunSche
|
|
|
5
5
|
import { commitFile, FileMutationError, type CommitMode } from "./file-commit.ts";
|
|
6
6
|
import { canonicalPath } from "./read-tool.ts";
|
|
7
7
|
import { computeLineHash, splitLines } from "../core/index.ts";
|
|
8
|
+
import { finalizeMutationResult } from "./mutation-result.ts";
|
|
8
9
|
|
|
9
10
|
function createWriteSchema(actionFusion: boolean) {
|
|
10
11
|
return Type.Object({
|
|
@@ -45,6 +46,7 @@ export function makeWriteOverride(cwd: string, fusion?: ReturnType<typeof create
|
|
|
45
46
|
async execute(toolCallId: string, params: WriteParams, signal: AbortSignal | undefined, onUpdate: any, ctx: any) {
|
|
46
47
|
const { then_run, ...mutationParams } = params;
|
|
47
48
|
if (!fusion && then_run !== undefined) throw new Error("then_run is unavailable because hashlineEdit.actionFusion is disabled");
|
|
49
|
+
if (mutationParams.content.includes("\0")) throw new Error("UNSUPPORTED_TEXT: NUL bytes are not editable.");
|
|
48
50
|
const absolutePath = canonicalPath(cwd, mutationParams.path);
|
|
49
51
|
const hashLen = getState().config.hashLen;
|
|
50
52
|
let mutationAnchors = "";
|
|
@@ -59,7 +61,15 @@ export function makeWriteOverride(cwd: string, fusion?: ReturnType<typeof create
|
|
|
59
61
|
mutationAnchors = formatAnchors(mutationParams.content, hashLen);
|
|
60
62
|
return {
|
|
61
63
|
content: [{ type: "text" as const, text: `${result.created ? "Created" : "Wrote"} ${mutationParams.path}.\nRevision: ${result.revision}` }],
|
|
62
|
-
details: {
|
|
64
|
+
details: {
|
|
65
|
+
path: mutationParams.path,
|
|
66
|
+
revision: result.publishedRevision,
|
|
67
|
+
baseRevision: result.baseRevision,
|
|
68
|
+
publishedRevision: result.publishedRevision,
|
|
69
|
+
observedRevision: result.observedRevision,
|
|
70
|
+
created: result.created,
|
|
71
|
+
publication: result.publication,
|
|
72
|
+
},
|
|
63
73
|
};
|
|
64
74
|
} catch (error) {
|
|
65
75
|
throw new FileMutationError("post_process", "PUBLISHED", `file was published but write result generation failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
@@ -76,7 +86,7 @@ export function makeWriteOverride(cwd: string, fusion?: ReturnType<typeof create
|
|
|
76
86
|
}],
|
|
77
87
|
};
|
|
78
88
|
};
|
|
79
|
-
if (!fusion) return
|
|
89
|
+
if (!fusion) return finalizeMutationResult(await mutate(), finalizeMutation);
|
|
80
90
|
return fusion({ toolCallId, absolutePath, thenRun: then_run, mutate, finalizeMutation, signal, ctx, onUpdate });
|
|
81
91
|
},
|
|
82
92
|
};
|
package/src/pi/write.test.ts
CHANGED
|
@@ -98,7 +98,7 @@ test("write omits pre-command anchors when then_run changes the target", async (
|
|
|
98
98
|
const text = result.content.map((block: any) => block.text).join("\n");
|
|
99
99
|
assert.match(text, /Mutation revision:/);
|
|
100
100
|
assert.match(text, /Pre-command anchors are omitted/);
|
|
101
|
-
assert.match(text, /
|
|
101
|
+
assert.match(text, /published revision may not describe the final file/i);
|
|
102
102
|
assert.doesNotMatch(text, /Fresh anchors:|\b1#[0-9A-Z]+\b/);
|
|
103
103
|
assert.equal(result.details.actionFusion.freshness, "changed");
|
|
104
104
|
assert.deepEqual(write.renderResult(result, { isPartial: false }, {}, { isError: false }).render(100), []);
|
|
@@ -124,3 +124,9 @@ test("write omits anchors when a failed then_run changed the target", async () =
|
|
|
124
124
|
assert.match(text, /Pre-command anchors are omitted/);
|
|
125
125
|
assert.doesNotMatch(text, /Fresh anchors:/);
|
|
126
126
|
}));
|
|
127
|
+
|
|
128
|
+
test("write rejects NUL content", async () => withTemp(async (dir) => {
|
|
129
|
+
const write = makeWriteOverride(dir);
|
|
130
|
+
await assert.rejects(write.execute("nul", { path: "nul.txt", content: "a\0b" }, undefined, undefined, context(dir)), /UNSUPPORTED_TEXT/);
|
|
131
|
+
await assert.rejects(readFile(join(dir, "nul.txt")), /ENOENT/);
|
|
132
|
+
}));
|