@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/src/pi/state.ts CHANGED
@@ -8,10 +8,9 @@
8
8
  * @module pi-hashline-edit/pi
9
9
  */
10
10
 
11
- import type { HashlineEditConfig } from "./config.ts";
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
  }
@@ -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: { path: mutationParams.path, revision: result.revision, created: result.created, publication: result.publication },
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 finalizeMutation(await mutate(), true);
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
  };
@@ -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, /mutation revision may not describe the final file/i);
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
+ }));