@criogaid/pi-hashline-edit 0.1.2 → 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 +4 -4
- package/package.json +1 -1
- package/src/pi/action-fusion.test.ts +1 -1
- package/src/pi/config.test.ts +6 -9
- package/src/pi/config.ts +3 -3
- package/src/pi/registration.test.ts +15 -2
- package/src/pi/state.ts +2 -3
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Overrides `read`, `grep`, `edit`, and `write`, and adds `replace` for bulk trans
|
|
|
9
9
|
- **Search → edit:** `read` and `grep` return the same `LINE#HASH` anchors, so search results can feed directly into edits.
|
|
10
10
|
- **Batch and chain edits:** submit structured JSON operations together, then use the returned fresh anchors for the next change.
|
|
11
11
|
- **Recover from stale anchors:** rejected edits offer checksum-matching candidates or nearby current-file context for a verified retry. Recovery never applies automatically.
|
|
12
|
-
- **Edit → test:**
|
|
12
|
+
- **Edit → test:** Action Fusion lets a mutation include an optional follow-up command, with separate file and command outcomes and separate TUI cards.
|
|
13
13
|
|
|
14
14
|
[Quick start](#quick-start) · [Tools](#tools) · [Configuration](#configuration) · [Action Fusion](#action-fusion) · [Safety and design](#safety-and-design)
|
|
15
15
|
|
|
@@ -154,7 +154,7 @@ Add `hashlineEdit` to Pi's global settings (`~/.pi/agent/settings.json` by defau
|
|
|
154
154
|
{
|
|
155
155
|
"hashlineEdit": {
|
|
156
156
|
"enabled": true,
|
|
157
|
-
"actionFusion":
|
|
157
|
+
"actionFusion": true,
|
|
158
158
|
"hashLen": 4,
|
|
159
159
|
"shiftRadius": 15
|
|
160
160
|
}
|
|
@@ -164,7 +164,7 @@ Add `hashlineEdit` to Pi's global settings (`~/.pi/agent/settings.json` by defau
|
|
|
164
164
|
| Setting | Default | Meaning |
|
|
165
165
|
| --- | --- | --- |
|
|
166
166
|
| `enabled` | `true` | Enable all five tools as one unit. Set `false` to restore built-in tools. |
|
|
167
|
-
| `actionFusion` | `
|
|
167
|
+
| `actionFusion` | `true` | Expose `then_run` on mutation tools. Set `false` to disable command support. |
|
|
168
168
|
| `hashLen` | `4` | Integer checksum length, 2–8 characters. |
|
|
169
169
|
| `shiftRadius` | `15` | Integer recovery-search radius, 0–100 lines; `0` disables recovery. |
|
|
170
170
|
|
|
@@ -172,7 +172,7 @@ The project's `hashlineEdit` object replaces the global object as a whole; missi
|
|
|
172
172
|
|
|
173
173
|
## Action Fusion
|
|
174
174
|
|
|
175
|
-
|
|
175
|
+
Action Fusion is enabled by default. Set `"actionFusion": false` in `hashlineEdit` and reload Pi to disable it; an existing explicit `false` remains effective. Commands run only when a call supplies `then_run`:
|
|
176
176
|
|
|
177
177
|
```json
|
|
178
178
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@criogaid/pi-hashline-edit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Hashline-style file editing for pi — line-anchored edits verified by content hash, replacing oldText/newText matching",
|
|
6
6
|
"homepage": "https://github.com/Criogaid/pi-hashline-edit#readme",
|
|
@@ -17,7 +17,7 @@ async function tempDir(): Promise<string> {
|
|
|
17
17
|
|
|
18
18
|
const ctx = (cwd: string) => ({ cwd }) as any;
|
|
19
19
|
|
|
20
|
-
test("
|
|
20
|
+
test("mutation tools expose Fusion schemas and guidance when supplied an executor", () => {
|
|
21
21
|
const fusion = createActionFusionExecutor();
|
|
22
22
|
for (const makeTool of [makeEditOverride, makeReplaceTool, makeWriteOverride]) {
|
|
23
23
|
const disabled = makeTool("/tmp") as any;
|
package/src/pi/config.test.ts
CHANGED
|
@@ -5,17 +5,14 @@ import assert from "node:assert/strict";
|
|
|
5
5
|
import { test } from "node:test";
|
|
6
6
|
import { loadConfig } from "./config.ts";
|
|
7
7
|
|
|
8
|
-
test("actionFusion defaults
|
|
8
|
+
test("actionFusion defaults on and honors explicit disabling", async () => {
|
|
9
9
|
const root = await mkdtemp(join(tmpdir(), "hashline-config-"));
|
|
10
10
|
try {
|
|
11
11
|
await mkdir(join(root, ".pi"));
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
assert.equal(config.actionFusion, true);
|
|
17
|
-
assert.equal(config.hashLen, 4);
|
|
18
|
-
assert.equal(config.shiftRadius, 15);
|
|
12
|
+
for (const [actionFusion, expected] of [[undefined, true], [false, false], [true, true], [null, true], ["false", true], [0, true]]) {
|
|
13
|
+
await writeFile(join(root, ".pi", "settings.json"), JSON.stringify({ hashlineEdit: { actionFusion } }));
|
|
14
|
+
assert.deepEqual(loadConfig(root), { enabled: true, actionFusion: expected, hashLen: 4, shiftRadius: 15 });
|
|
15
|
+
}
|
|
19
16
|
} finally {
|
|
20
17
|
await rm(root, { recursive: true, force: true });
|
|
21
18
|
}
|
|
@@ -28,7 +25,7 @@ test("config rejects fractional values and tolerates malformed settings shapes",
|
|
|
28
25
|
const path = join(root, ".pi", "settings.json");
|
|
29
26
|
for (const value of [3.5, -1, "4", null]) {
|
|
30
27
|
await writeFile(path, JSON.stringify({ hashlineEdit: { hashLen: value, shiftRadius: value } }));
|
|
31
|
-
assert.deepEqual(loadConfig(root), { enabled: true, actionFusion:
|
|
28
|
+
assert.deepEqual(loadConfig(root), { enabled: true, actionFusion: true, hashLen: 4, shiftRadius: 15 });
|
|
32
29
|
}
|
|
33
30
|
for (const rootValue of [null, [], 42, "settings", { hashlineEdit: [] }, { hashlineEdit: "invalid" }]) {
|
|
34
31
|
await writeFile(path, JSON.stringify(rootValue));
|
package/src/pi/config.ts
CHANGED
|
@@ -13,7 +13,7 @@ import * as path from "node:path";
|
|
|
13
13
|
export interface HashlineEditConfig {
|
|
14
14
|
/** Master switch: when false the extension registers no tools — pi's built-ins remain. */
|
|
15
15
|
enabled: boolean;
|
|
16
|
-
/**
|
|
16
|
+
/** Expose optional commands after edit/replace/write. Enabled by default; false disables them. */
|
|
17
17
|
actionFusion: boolean;
|
|
18
18
|
/** Line hash length (default 4). */
|
|
19
19
|
hashLen: number;
|
|
@@ -21,7 +21,7 @@ export interface HashlineEditConfig {
|
|
|
21
21
|
shiftRadius: number;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const DEFAULT_CONFIG: HashlineEditConfig = { enabled: true, actionFusion:
|
|
24
|
+
export const DEFAULT_CONFIG: HashlineEditConfig = { enabled: true, actionFusion: true, hashLen: 4, shiftRadius: 15 };
|
|
25
25
|
|
|
26
26
|
/** Parse JSON directly without stripping comments (standard JSON forbids comments; on error fall back to default). */
|
|
27
27
|
function readSettings(filePath: string): Record<string, unknown> {
|
|
@@ -45,7 +45,7 @@ export function loadConfig(cwd?: string): HashlineEditConfig {
|
|
|
45
45
|
const raw = value !== null && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {};
|
|
46
46
|
return {
|
|
47
47
|
enabled: typeof raw.enabled === "boolean" ? raw.enabled : DEFAULT_CONFIG.enabled,
|
|
48
|
-
actionFusion: raw.actionFusion ===
|
|
48
|
+
actionFusion: typeof raw.actionFusion === "boolean" ? raw.actionFusion : DEFAULT_CONFIG.actionFusion,
|
|
49
49
|
hashLen:
|
|
50
50
|
typeof raw.hashLen === "number" && Number.isInteger(raw.hashLen) && raw.hashLen >= 2 && raw.hashLen <= 8
|
|
51
51
|
? raw.hashLen
|
|
@@ -9,14 +9,14 @@ import { initTheme } from "@earendil-works/pi-coding-agent";
|
|
|
9
9
|
import { ToolExecutionComponent } from "../../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/tool-execution.js";
|
|
10
10
|
import { theme } from "../../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js";
|
|
11
11
|
|
|
12
|
-
test("
|
|
12
|
+
test("mutation cards use Fusion by default and explicit false removes command support", async () => {
|
|
13
13
|
const dir = await mkdtemp(join(tmpdir(), "hashline-registration-"));
|
|
14
14
|
const previousCwd = process.cwd();
|
|
15
15
|
const state = getState();
|
|
16
16
|
const previousConfig = state.config;
|
|
17
17
|
try {
|
|
18
18
|
await mkdir(join(dir, ".pi"));
|
|
19
|
-
await writeFile(join(dir, ".pi", "settings.json"), JSON.stringify({ hashlineEdit: { enabled: true
|
|
19
|
+
await writeFile(join(dir, ".pi", "settings.json"), JSON.stringify({ hashlineEdit: { enabled: true } }));
|
|
20
20
|
process.chdir(dir);
|
|
21
21
|
const tools: any[] = [];
|
|
22
22
|
const entries: any[] = [];
|
|
@@ -80,6 +80,19 @@ test("registered mutation cards finish independently of fused command cards", as
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
assert.deepEqual(entries.map((entry) => entry.data.command), cases.flatMap(() => ["waiting", "failed", "waiting", "skipped"]));
|
|
83
|
+
await writeFile(join(dir, ".pi", "settings.json"), JSON.stringify({ hashlineEdit: { actionFusion: false } }));
|
|
84
|
+
const disabledTools: any[] = [];
|
|
85
|
+
registerHashline({
|
|
86
|
+
on() {},
|
|
87
|
+
registerEntryRenderer() {},
|
|
88
|
+
registerTool(tool: any) { disabledTools.push(tool); },
|
|
89
|
+
} as any);
|
|
90
|
+
assert.equal(disabledTools.length, 5);
|
|
91
|
+
for (const tool of disabledTools.filter((tool) => ["edit", "replace", "write"].includes(tool.name))) {
|
|
92
|
+
assert.equal(tool.parameters.properties.then_run, undefined);
|
|
93
|
+
assert.equal(tool.renderShell, "default");
|
|
94
|
+
await assert.rejects(tool.execute("disabled", { path: "published.txt", then_run: { command: "exit 0" } }, undefined, undefined, { cwd: dir }), /then_run is unavailable/);
|
|
95
|
+
}
|
|
83
96
|
} finally {
|
|
84
97
|
process.chdir(previousCwd);
|
|
85
98
|
state.config = previousConfig;
|
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
|
}
|