@criogaid/pi-hashline-edit 0.1.0
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/LICENSE +21 -0
- package/README.md +279 -0
- package/package.json +50 -0
- package/src/core/apply.test.ts +327 -0
- package/src/core/apply.ts +264 -0
- package/src/core/hash.test.ts +54 -0
- package/src/core/hash.ts +68 -0
- package/src/core/index.ts +13 -0
- package/src/core/lines.test.ts +33 -0
- package/src/core/lines.ts +52 -0
- package/src/core/types.ts +87 -0
- package/src/index.ts +44 -0
- package/src/integration/grep-rg.test.ts +390 -0
- package/src/pi/action-fusion.test.ts +244 -0
- package/src/pi/action-fusion.ts +284 -0
- package/src/pi/config.test.ts +22 -0
- package/src/pi/config.ts +56 -0
- package/src/pi/edit-tool.ts +367 -0
- package/src/pi/execute.test.ts +521 -0
- package/src/pi/failure-context.test.ts +88 -0
- package/src/pi/failure-context.ts +98 -0
- package/src/pi/failure-path.test.ts +60 -0
- package/src/pi/file-commit.test.ts +200 -0
- package/src/pi/file-commit.ts +185 -0
- package/src/pi/fusion-card.test.ts +69 -0
- package/src/pi/fusion-card.ts +78 -0
- package/src/pi/grep-tool.ts +795 -0
- package/src/pi/grep.test.ts +515 -0
- package/src/pi/pi.test.ts +19 -0
- package/src/pi/read-tool.ts +178 -0
- package/src/pi/registration.test.ts +41 -0
- package/src/pi/render.ts +103 -0
- package/src/pi/replace-tool.ts +303 -0
- package/src/pi/replace.test.ts +287 -0
- package/src/pi/rg-line-filter.test.ts +79 -0
- package/src/pi/rg-line-filter.ts +358 -0
- package/src/pi/rg-line-ranges.test.ts +30 -0
- package/src/pi/rg-line-ranges.ts +106 -0
- package/src/pi/state.ts +27 -0
- package/src/pi/write-tool.ts +83 -0
- package/src/pi/write.test.ts +126 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { createBashToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { Box, Text, type Component } from "@earendil-works/pi-tui";
|
|
4
|
+
import type { ActionFusionProgress } from "./action-fusion.ts";
|
|
5
|
+
|
|
6
|
+
const CARD_TYPE = "hashline-then-run";
|
|
7
|
+
const RESULT_TYPE = "hashline-then-run-result";
|
|
8
|
+
|
|
9
|
+
/** Render one durable transcript card per fused command without adding model context. */
|
|
10
|
+
export function registerFusionCards(pi: ExtensionAPI) {
|
|
11
|
+
const bash = createBashToolDefinition(process.cwd());
|
|
12
|
+
const states = new Map<string, ActionFusionProgress>();
|
|
13
|
+
const active = new Set<string>();
|
|
14
|
+
|
|
15
|
+
const restore = (ctx: ExtensionContext) => {
|
|
16
|
+
states.clear();
|
|
17
|
+
active.clear();
|
|
18
|
+
for (const entry of ctx.sessionManager.getBranch()) {
|
|
19
|
+
if (entry.type !== "custom" || (entry.customType !== CARD_TYPE && entry.customType !== RESULT_TYPE)) continue;
|
|
20
|
+
const data = entry.data as ActionFusionProgress | undefined;
|
|
21
|
+
if (data && typeof data.toolCallId === "string" && typeof data.commandText === "string" && typeof data.output === "string") {
|
|
22
|
+
states.set(data.toolCallId, data);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
pi.on("session_start", (_event, ctx) => restore(ctx));
|
|
27
|
+
pi.on("session_tree", (_event, ctx) => restore(ctx));
|
|
28
|
+
|
|
29
|
+
pi.registerEntryRenderer<ActionFusionProgress>(CARD_TYPE, (entry, { expanded }, theme) => {
|
|
30
|
+
const initial = entry.data;
|
|
31
|
+
if (!initial) return undefined;
|
|
32
|
+
const statusText = new Text("", 0, 0);
|
|
33
|
+
const box = new Box(1, 1);
|
|
34
|
+
let call: Component | undefined;
|
|
35
|
+
let result: Component | undefined;
|
|
36
|
+
const rendererState = { startedAt: undefined, endedAt: undefined, interval: undefined };
|
|
37
|
+
return {
|
|
38
|
+
invalidate: () => box.invalidate(),
|
|
39
|
+
render(width) {
|
|
40
|
+
// Read live state during rendering; native tool updates schedule the repaint.
|
|
41
|
+
const current = states.get(initial.toolCallId) ?? initial;
|
|
42
|
+
const pending = current.command === "waiting" || current.command === "running";
|
|
43
|
+
const status = pending && !active.has(current.toolCallId) ? "interrupted (final status unknown)" : current.command;
|
|
44
|
+
const color = pending ? "warning" : current.command === "succeeded" ? "success" : "error";
|
|
45
|
+
const background = pending ? "toolPendingBg" : current.command === "succeeded" ? "toolSuccessBg" : "toolErrorBg";
|
|
46
|
+
box.setBgFn((line) => theme.bg(background, line));
|
|
47
|
+
const stale = current.freshness === "changed" || current.freshness === "missing" ? `\nAnchors are stale: target ${current.freshness}.` : "";
|
|
48
|
+
statusText.setText(`${theme.fg("toolTitle", theme.bold("then_run"))} · ${theme.fg(color, status)}\n${current.path}\npublication=${current.publication} freshness=${current.freshness}${stale}`);
|
|
49
|
+
const context = {
|
|
50
|
+
args: { command: current.commandText }, toolCallId: current.toolCallId, cwd: process.cwd(),
|
|
51
|
+
state: rendererState, invalidate: () => box.invalidate(),
|
|
52
|
+
// Parent tool updates drive entry rendering; leave the native elapsed-time timer off.
|
|
53
|
+
executionStarted: false, argsComplete: true, isPartial: pending, expanded, showImages: false,
|
|
54
|
+
isError: !pending && current.command !== "succeeded",
|
|
55
|
+
};
|
|
56
|
+
call = bash.renderCall!(context.args, theme, { ...context, lastComponent: call });
|
|
57
|
+
result = bash.renderResult!({ content: [{ type: "text", text: current.output }], details: undefined },
|
|
58
|
+
{ expanded, isPartial: pending }, theme, { ...context, lastComponent: result });
|
|
59
|
+
box.clear();
|
|
60
|
+
box.addChild(statusText);
|
|
61
|
+
box.addChild(call);
|
|
62
|
+
box.addChild(result);
|
|
63
|
+
return box.render(width);
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return (progress: ActionFusionProgress) => {
|
|
69
|
+
const first = !states.has(progress.toolCallId);
|
|
70
|
+
states.set(progress.toolCallId, progress);
|
|
71
|
+
const pending = progress.command === "waiting" || progress.command === "running";
|
|
72
|
+
if (pending) active.add(progress.toolCallId);
|
|
73
|
+
else active.delete(progress.toolCallId);
|
|
74
|
+
// Only endpoints are persisted; streaming snapshots reuse Bash's bounded output.
|
|
75
|
+
if (first) pi.appendEntry(CARD_TYPE, progress);
|
|
76
|
+
if (!pending) pi.appendEntry(RESULT_TYPE, progress);
|
|
77
|
+
};
|
|
78
|
+
}
|