xtrm-tools 0.5.10 → 0.5.13
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 +4 -1
- package/README.md +28 -30
- package/cli/dist/index.cjs +1509 -2722
- package/cli/dist/index.cjs.map +1 -1
- package/cli/package.json +1 -1
- package/config/instructions/agents-top.md +87 -23
- package/config/instructions/claude-top.md +101 -23
- package/config/pi/extensions/beads/index.ts +3 -1
- package/config/pi/extensions/session-flow/index.ts +26 -90
- package/config/pi/extensions/xtrm-loader/index.ts +39 -2
- package/hooks/README.md +0 -14
- package/hooks/beads-gate-messages.mjs +8 -22
- package/hooks/gitnexus/gitnexus-hook.cjs +1 -1
- package/hooks/hooks.json +25 -27
- package/hooks/quality-check-env.mjs +79 -0
- package/hooks/quality-check.cjs +6 -6
- package/hooks/statusline.mjs +115 -0
- package/hooks/using-xtrm-reminder.mjs +35 -0
- package/package.json +1 -1
- package/skills/sync-docs-workspace/iteration-1/benchmark.json +293 -0
- package/skills/sync-docs-workspace/iteration-1/benchmark.md +13 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/with_skill/outputs/result.md +210 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/with_skill/run-1/grading.json +28 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/with_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/without_skill/outputs/result.md +101 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/without_skill/run-1/grading.json +28 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/without_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/without_skill/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/with_skill/outputs/result.md +198 -0
- package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/with_skill/run-1/grading.json +28 -0
- package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/with_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/without_skill/outputs/result.md +94 -0
- package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/without_skill/run-1/grading.json +28 -0
- package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/without_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/with_skill/outputs/result.md +237 -0
- package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/with_skill/run-1/grading.json +28 -0
- package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/with_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/without_skill/outputs/result.md +134 -0
- package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/without_skill/run-1/grading.json +28 -0
- package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/without_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-2/benchmark.json +297 -0
- package/skills/sync-docs-workspace/iteration-2/benchmark.md +13 -0
- package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/with_skill/outputs/result.md +137 -0
- package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/with_skill/run-1/grading.json +92 -0
- package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/with_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/without_skill/outputs/result.md +134 -0
- package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/without_skill/run-1/grading.json +86 -0
- package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/without_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/with_skill/outputs/result.md +193 -0
- package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/with_skill/run-1/grading.json +72 -0
- package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/with_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/without_skill/outputs/result.md +211 -0
- package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/without_skill/run-1/grading.json +91 -0
- package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/without_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/with_skill/outputs/result.md +182 -0
- package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/with_skill/run-1/grading.json +95 -0
- package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/with_skill/run-1/timing.json +1 -0
- package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/without_skill/outputs/result.md +222 -0
- package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/without_skill/run-1/grading.json +88 -0
- package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/without_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-3/benchmark.json +298 -0
- package/skills/sync-docs-workspace/iteration-3/benchmark.md +13 -0
- package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/with_skill/outputs/result.md +125 -0
- package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/with_skill/run-1/grading.json +97 -0
- package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/with_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/without_skill/outputs/result.md +144 -0
- package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/without_skill/run-1/grading.json +78 -0
- package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/without_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/with_skill/outputs/result.md +104 -0
- package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/with_skill/run-1/grading.json +91 -0
- package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/with_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/without_skill/outputs/result.md +79 -0
- package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/without_skill/run-1/grading.json +82 -0
- package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/without_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/eval_metadata.json +27 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/phase1_context.json +302 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/phase2_drift.txt +33 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/phase3_analysis.json +114 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/phase4_fix.txt +118 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/phase5_validate.txt +38 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/result.md +158 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/run-1/grading.json +95 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/run-1/timing.json +5 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/without_skill/outputs/result.md +71 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/without_skill/run-1/grading.json +90 -0
- package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/without_skill/run-1/timing.json +5 -0
- package/skills/using-xtrm/SKILL.md +84 -205
- package/config/pi/extensions/bg-process/index.ts +0 -230
- package/config/pi/extensions/bg-process/package.json +0 -16
- package/config/pi/extensions/minimal-mode/index.ts +0 -201
- package/config/pi/extensions/minimal-mode/package.json +0 -16
- package/config/pi/extensions/todo/index.ts +0 -299
- package/config/pi/extensions/todo/package.json +0 -16
- package/hooks/agent_context.py +0 -105
- package/hooks/branch-state.mjs +0 -39
- package/hooks/guard-rules.mjs +0 -118
- package/hooks/main-guard-post-push.mjs +0 -71
- package/hooks/main-guard.mjs +0 -119
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@xtrm/pi-bg-process",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "xtrm Pi extension: bg-process",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": "./index.ts"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"pi",
|
|
11
|
-
"extension",
|
|
12
|
-
"xtrm"
|
|
13
|
-
],
|
|
14
|
-
"author": "xtrm",
|
|
15
|
-
"license": "MIT"
|
|
16
|
-
}
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
2
|
-
import {
|
|
3
|
-
createBashTool,
|
|
4
|
-
createEditTool,
|
|
5
|
-
createFindTool,
|
|
6
|
-
createGrepTool,
|
|
7
|
-
createLsTool,
|
|
8
|
-
createReadTool,
|
|
9
|
-
createWriteTool,
|
|
10
|
-
} from "@mariozechner/pi-coding-agent";
|
|
11
|
-
import { Text } from "@mariozechner/pi-tui";
|
|
12
|
-
|
|
13
|
-
function getTextContent(result: any): string {
|
|
14
|
-
if (!result?.content || !Array.isArray(result.content)) return "";
|
|
15
|
-
return result.content
|
|
16
|
-
.filter((c: any) => c?.type === "text" && typeof c.text === "string")
|
|
17
|
-
.map((c: any) => c.text)
|
|
18
|
-
.join("\n")
|
|
19
|
-
.trim();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function oneLine(s: string): string {
|
|
23
|
-
return (s || "").replace(/\s+/g, " ").trim();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function summarize(result: any): { text: string; isError: boolean } {
|
|
27
|
-
const raw = getTextContent(result);
|
|
28
|
-
if (!raw) return { text: "done", isError: false };
|
|
29
|
-
const line = oneLine(raw.split("\n").find((l) => l.trim()) || "");
|
|
30
|
-
const lower = line.toLowerCase();
|
|
31
|
-
const isError = lower.includes("error") || lower.includes("failed") || lower.includes("exception");
|
|
32
|
-
return { text: line.slice(0, 140) || "done", isError };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const toolCache = new Map<string, ReturnType<typeof createBuiltInTools>>();
|
|
36
|
-
function createBuiltInTools(cwd: string) {
|
|
37
|
-
return {
|
|
38
|
-
read: createReadTool(cwd),
|
|
39
|
-
bash: createBashTool(cwd),
|
|
40
|
-
edit: createEditTool(cwd),
|
|
41
|
-
write: createWriteTool(cwd),
|
|
42
|
-
find: createFindTool(cwd),
|
|
43
|
-
grep: createGrepTool(cwd),
|
|
44
|
-
ls: createLsTool(cwd),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
function getBuiltInTools(cwd: string) {
|
|
48
|
-
let tools = toolCache.get(cwd);
|
|
49
|
-
if (!tools) {
|
|
50
|
-
tools = createBuiltInTools(cwd);
|
|
51
|
-
toolCache.set(cwd, tools);
|
|
52
|
-
}
|
|
53
|
-
return tools;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export default function (pi: ExtensionAPI) {
|
|
57
|
-
let minimalEnabled = true;
|
|
58
|
-
let thinkingStatusEnabled = true;
|
|
59
|
-
let spinnerTimer: NodeJS.Timeout | null = null;
|
|
60
|
-
let spinnerIndex = 0;
|
|
61
|
-
const frames = ["thinking ", "thinking. ", "thinking.. ", "thinking..."];
|
|
62
|
-
|
|
63
|
-
const clearSpinner = (ctx: any) => {
|
|
64
|
-
if (spinnerTimer) {
|
|
65
|
-
clearInterval(spinnerTimer);
|
|
66
|
-
spinnerTimer = null;
|
|
67
|
-
}
|
|
68
|
-
if (ctx?.hasUI) {
|
|
69
|
-
ctx.ui.setStatus("thinking", undefined);
|
|
70
|
-
ctx.ui.setHeader(undefined);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const mountThinkingHeader = (ctx: any) => {
|
|
75
|
-
if (!ctx?.hasUI) return;
|
|
76
|
-
ctx.ui.setHeader((_tui: any, theme: any) => ({
|
|
77
|
-
invalidate() {},
|
|
78
|
-
render(width: number): string[] {
|
|
79
|
-
const text = frames[spinnerIndex];
|
|
80
|
-
return [oneLine(theme.fg("accent", text)).slice(0, width)];
|
|
81
|
-
},
|
|
82
|
-
}));
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const startSpinner = (ctx: any) => {
|
|
86
|
-
if (!thinkingStatusEnabled || !ctx?.hasUI) return;
|
|
87
|
-
clearSpinner(ctx);
|
|
88
|
-
spinnerIndex = 0;
|
|
89
|
-
ctx.ui.setStatus("thinking", frames[spinnerIndex]);
|
|
90
|
-
mountThinkingHeader(ctx);
|
|
91
|
-
spinnerTimer = setInterval(() => {
|
|
92
|
-
spinnerIndex = (spinnerIndex + 1) % frames.length;
|
|
93
|
-
ctx.ui.setStatus("thinking", frames[spinnerIndex]);
|
|
94
|
-
mountThinkingHeader(ctx);
|
|
95
|
-
}, 220);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const renderCollapsedResult = (result: any, theme: any) => {
|
|
99
|
-
const s = summarize(result);
|
|
100
|
-
const icon = s.isError ? theme.fg("error", "✗") : theme.fg("success", "✓");
|
|
101
|
-
const text = s.isError ? theme.fg("error", s.text) : theme.fg("muted", s.text);
|
|
102
|
-
if (minimalEnabled) return new Text(` ${icon} ${text}`, 0, 0);
|
|
103
|
-
return new Text(theme.fg("muted", ` → ${s.text}`), 0, 0);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const renderExpandedResult = (result: any, theme: any) => {
|
|
107
|
-
const text = getTextContent(result);
|
|
108
|
-
if (!text) return new Text("", 0, 0);
|
|
109
|
-
const output = text.split("\n").map((line) => theme.fg("toolOutput", line)).join("\n");
|
|
110
|
-
return new Text(`\n${output}`, 0, 0);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
pi.registerTool({
|
|
114
|
-
name: "bash",
|
|
115
|
-
label: "bash",
|
|
116
|
-
description: getBuiltInTools(process.cwd()).bash.description,
|
|
117
|
-
parameters: getBuiltInTools(process.cwd()).bash.parameters,
|
|
118
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
119
|
-
return getBuiltInTools(ctx.cwd).bash.execute(toolCallId, params, signal, onUpdate);
|
|
120
|
-
},
|
|
121
|
-
renderCall(args, theme) {
|
|
122
|
-
const cmd = oneLine(args.command || "");
|
|
123
|
-
return new Text(`${theme.fg("toolTitle", theme.bold("bash"))}(${theme.fg("accent", cmd || "...")})`, 0, 0);
|
|
124
|
-
},
|
|
125
|
-
renderResult(result, { expanded }, theme) {
|
|
126
|
-
return expanded ? renderExpandedResult(result, theme) : renderCollapsedResult(result, theme);
|
|
127
|
-
},
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
for (const name of ["read", "write", "edit", "find", "grep", "ls"] as const) {
|
|
131
|
-
pi.registerTool({
|
|
132
|
-
name,
|
|
133
|
-
label: name,
|
|
134
|
-
description: (getBuiltInTools(process.cwd()) as any)[name].description,
|
|
135
|
-
parameters: (getBuiltInTools(process.cwd()) as any)[name].parameters,
|
|
136
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
137
|
-
return (getBuiltInTools(ctx.cwd) as any)[name].execute(toolCallId, params, signal, onUpdate);
|
|
138
|
-
},
|
|
139
|
-
renderCall(args, theme) {
|
|
140
|
-
const suffix = oneLine(args.path || args.pattern || "");
|
|
141
|
-
return new Text(`${theme.fg("toolTitle", theme.bold(name))}${suffix ? `(${theme.fg("accent", suffix)})` : ""}`, 0, 0);
|
|
142
|
-
},
|
|
143
|
-
renderResult(result, { expanded }, theme) {
|
|
144
|
-
return expanded ? renderExpandedResult(result, theme) : renderCollapsedResult(result, theme);
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
pi.registerCommand("minimal-on", {
|
|
150
|
-
description: "Enable minimal collapsed tool output",
|
|
151
|
-
handler: async (_args, ctx) => {
|
|
152
|
-
minimalEnabled = true;
|
|
153
|
-
ctx.ui.notify("Minimal mode enabled", "info");
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
pi.registerCommand("minimal-off", {
|
|
158
|
-
description: "Disable minimal collapsed tool output",
|
|
159
|
-
handler: async (_args, ctx) => {
|
|
160
|
-
minimalEnabled = false;
|
|
161
|
-
ctx.ui.notify("Minimal mode disabled", "info");
|
|
162
|
-
},
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
pi.registerCommand("minimal-toggle", {
|
|
166
|
-
description: "Toggle minimal collapsed tool output",
|
|
167
|
-
handler: async (_args, ctx) => {
|
|
168
|
-
minimalEnabled = !minimalEnabled;
|
|
169
|
-
ctx.ui.notify(`Minimal mode ${minimalEnabled ? "enabled" : "disabled"}`, "info");
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
pi.registerCommand("thinking-status-toggle", {
|
|
174
|
-
description: "Toggle flashing thinking status indicator",
|
|
175
|
-
handler: async (_args, ctx) => {
|
|
176
|
-
thinkingStatusEnabled = !thinkingStatusEnabled;
|
|
177
|
-
if (!thinkingStatusEnabled) clearSpinner(ctx);
|
|
178
|
-
ctx.ui.notify(`Thinking status ${thinkingStatusEnabled ? "enabled" : "disabled"}`, "info");
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
pi.on("turn_start", async (_event, ctx) => {
|
|
183
|
-
startSpinner(ctx);
|
|
184
|
-
return undefined;
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
pi.on("turn_end", async (_event, ctx) => {
|
|
188
|
-
clearSpinner(ctx);
|
|
189
|
-
return undefined;
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
pi.on("agent_end", async (_event, ctx) => {
|
|
193
|
-
clearSpinner(ctx);
|
|
194
|
-
return undefined;
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
pi.on("session_shutdown", async (_event, ctx) => {
|
|
198
|
-
clearSpinner(ctx);
|
|
199
|
-
return undefined;
|
|
200
|
-
});
|
|
201
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@xtrm/pi-minimal-mode",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "xtrm Pi extension: minimal-mode",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": "./index.ts"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"pi",
|
|
11
|
-
"extension",
|
|
12
|
-
"xtrm"
|
|
13
|
-
],
|
|
14
|
-
"author": "xtrm",
|
|
15
|
-
"license": "MIT"
|
|
16
|
-
}
|
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Todo Extension - Demonstrates state management via session entries
|
|
3
|
-
*
|
|
4
|
-
* This extension:
|
|
5
|
-
* - Registers a `todo` tool for the LLM to manage todos
|
|
6
|
-
* - Registers a `/todos` command for users to view the list
|
|
7
|
-
*
|
|
8
|
-
* State is stored in tool result details (not external files), which allows
|
|
9
|
-
* proper branching - when you branch, the todo state is automatically
|
|
10
|
-
* correct for that point in history.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { StringEnum } from "@mariozechner/pi-ai";
|
|
14
|
-
import type { ExtensionAPI, ExtensionContext, Theme } from "@mariozechner/pi-coding-agent";
|
|
15
|
-
import { matchesKey, Text, truncateToWidth } from "@mariozechner/pi-tui";
|
|
16
|
-
import { Type } from "@sinclair/typebox";
|
|
17
|
-
|
|
18
|
-
interface Todo {
|
|
19
|
-
id: number;
|
|
20
|
-
text: string;
|
|
21
|
-
done: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface TodoDetails {
|
|
25
|
-
action: "list" | "add" | "toggle" | "clear";
|
|
26
|
-
todos: Todo[];
|
|
27
|
-
nextId: number;
|
|
28
|
-
error?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const TodoParams = Type.Object({
|
|
32
|
-
action: StringEnum(["list", "add", "toggle", "clear"] as const),
|
|
33
|
-
text: Type.Optional(Type.String({ description: "Todo text (for add)" })),
|
|
34
|
-
id: Type.Optional(Type.Number({ description: "Todo ID (for toggle)" })),
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* UI component for the /todos command
|
|
39
|
-
*/
|
|
40
|
-
class TodoListComponent {
|
|
41
|
-
private todos: Todo[];
|
|
42
|
-
private theme: Theme;
|
|
43
|
-
private onClose: () => void;
|
|
44
|
-
private cachedWidth?: number;
|
|
45
|
-
private cachedLines?: string[];
|
|
46
|
-
|
|
47
|
-
constructor(todos: Todo[], theme: Theme, onClose: () => void) {
|
|
48
|
-
this.todos = todos;
|
|
49
|
-
this.theme = theme;
|
|
50
|
-
this.onClose = onClose;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
handleInput(data: string): void {
|
|
54
|
-
if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
|
|
55
|
-
this.onClose();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
render(width: number): string[] {
|
|
60
|
-
if (this.cachedLines && this.cachedWidth === width) {
|
|
61
|
-
return this.cachedLines;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const lines: string[] = [];
|
|
65
|
-
const th = this.theme;
|
|
66
|
-
|
|
67
|
-
lines.push("");
|
|
68
|
-
const title = th.fg("accent", " Todos ");
|
|
69
|
-
const headerLine =
|
|
70
|
-
th.fg("borderMuted", "─".repeat(3)) + title + th.fg("borderMuted", "─".repeat(Math.max(0, width - 10)));
|
|
71
|
-
lines.push(truncateToWidth(headerLine, width));
|
|
72
|
-
lines.push("");
|
|
73
|
-
|
|
74
|
-
if (this.todos.length === 0) {
|
|
75
|
-
lines.push(truncateToWidth(` ${th.fg("dim", "No todos yet. Ask the agent to add some!")}`, width));
|
|
76
|
-
} else {
|
|
77
|
-
const done = this.todos.filter((t) => t.done).length;
|
|
78
|
-
const total = this.todos.length;
|
|
79
|
-
lines.push(truncateToWidth(` ${th.fg("muted", `${done}/${total} completed`)}`, width));
|
|
80
|
-
lines.push("");
|
|
81
|
-
|
|
82
|
-
for (const todo of this.todos) {
|
|
83
|
-
const check = todo.done ? th.fg("success", "✓") : th.fg("dim", "○");
|
|
84
|
-
const id = th.fg("accent", `#${todo.id}`);
|
|
85
|
-
const text = todo.done ? th.fg("dim", todo.text) : th.fg("text", todo.text);
|
|
86
|
-
lines.push(truncateToWidth(` ${check} ${id} ${text}`, width));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
lines.push("");
|
|
91
|
-
lines.push(truncateToWidth(` ${th.fg("dim", "Press Escape to close")}`, width));
|
|
92
|
-
lines.push("");
|
|
93
|
-
|
|
94
|
-
this.cachedWidth = width;
|
|
95
|
-
this.cachedLines = lines;
|
|
96
|
-
return lines;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
invalidate(): void {
|
|
100
|
-
this.cachedWidth = undefined;
|
|
101
|
-
this.cachedLines = undefined;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export default function (pi: ExtensionAPI) {
|
|
106
|
-
// In-memory state (reconstructed from session on load)
|
|
107
|
-
let todos: Todo[] = [];
|
|
108
|
-
let nextId = 1;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Reconstruct state from session entries.
|
|
112
|
-
* Scans tool results for this tool and applies them in order.
|
|
113
|
-
*/
|
|
114
|
-
const reconstructState = (ctx: ExtensionContext) => {
|
|
115
|
-
todos = [];
|
|
116
|
-
nextId = 1;
|
|
117
|
-
|
|
118
|
-
for (const entry of ctx.sessionManager.getBranch()) {
|
|
119
|
-
if (entry.type !== "message") continue;
|
|
120
|
-
const msg = entry.message;
|
|
121
|
-
if (msg.role !== "toolResult" || msg.toolName !== "todo") continue;
|
|
122
|
-
|
|
123
|
-
const details = msg.details as TodoDetails | undefined;
|
|
124
|
-
if (details) {
|
|
125
|
-
todos = details.todos;
|
|
126
|
-
nextId = details.nextId;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// Reconstruct state on session events
|
|
132
|
-
pi.on("session_start", async (_event, ctx) => reconstructState(ctx));
|
|
133
|
-
pi.on("session_switch", async (_event, ctx) => reconstructState(ctx));
|
|
134
|
-
pi.on("session_fork", async (_event, ctx) => reconstructState(ctx));
|
|
135
|
-
pi.on("session_tree", async (_event, ctx) => reconstructState(ctx));
|
|
136
|
-
|
|
137
|
-
// Register the todo tool for the LLM
|
|
138
|
-
pi.registerTool({
|
|
139
|
-
name: "todo",
|
|
140
|
-
label: "Todo",
|
|
141
|
-
description: "Manage a todo list. Actions: list, add (text), toggle (id), clear",
|
|
142
|
-
parameters: TodoParams,
|
|
143
|
-
|
|
144
|
-
async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
|
|
145
|
-
switch (params.action) {
|
|
146
|
-
case "list":
|
|
147
|
-
return {
|
|
148
|
-
content: [
|
|
149
|
-
{
|
|
150
|
-
type: "text",
|
|
151
|
-
text: todos.length
|
|
152
|
-
? todos.map((t) => `[${t.done ? "x" : " "}] #${t.id}: ${t.text}`).join("\n")
|
|
153
|
-
: "No todos",
|
|
154
|
-
},
|
|
155
|
-
],
|
|
156
|
-
details: { action: "list", todos: [...todos], nextId } as TodoDetails,
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
case "add": {
|
|
160
|
-
if (!params.text) {
|
|
161
|
-
return {
|
|
162
|
-
content: [{ type: "text", text: "Error: text required for add" }],
|
|
163
|
-
details: { action: "add", todos: [...todos], nextId, error: "text required" } as TodoDetails,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
const newTodo: Todo = { id: nextId++, text: params.text, done: false };
|
|
167
|
-
todos.push(newTodo);
|
|
168
|
-
return {
|
|
169
|
-
content: [{ type: "text", text: `Added todo #${newTodo.id}: ${newTodo.text}` }],
|
|
170
|
-
details: { action: "add", todos: [...todos], nextId } as TodoDetails,
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
case "toggle": {
|
|
175
|
-
if (params.id === undefined) {
|
|
176
|
-
return {
|
|
177
|
-
content: [{ type: "text", text: "Error: id required for toggle" }],
|
|
178
|
-
details: { action: "toggle", todos: [...todos], nextId, error: "id required" } as TodoDetails,
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
const todo = todos.find((t) => t.id === params.id);
|
|
182
|
-
if (!todo) {
|
|
183
|
-
return {
|
|
184
|
-
content: [{ type: "text", text: `Todo #${params.id} not found` }],
|
|
185
|
-
details: {
|
|
186
|
-
action: "toggle",
|
|
187
|
-
todos: [...todos],
|
|
188
|
-
nextId,
|
|
189
|
-
error: `#${params.id} not found`,
|
|
190
|
-
} as TodoDetails,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
todo.done = !todo.done;
|
|
194
|
-
return {
|
|
195
|
-
content: [{ type: "text", text: `Todo #${todo.id} ${todo.done ? "completed" : "uncompleted"}` }],
|
|
196
|
-
details: { action: "toggle", todos: [...todos], nextId } as TodoDetails,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
case "clear": {
|
|
201
|
-
const count = todos.length;
|
|
202
|
-
todos = [];
|
|
203
|
-
nextId = 1;
|
|
204
|
-
return {
|
|
205
|
-
content: [{ type: "text", text: `Cleared ${count} todos` }],
|
|
206
|
-
details: { action: "clear", todos: [], nextId: 1 } as TodoDetails,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
default:
|
|
211
|
-
return {
|
|
212
|
-
content: [{ type: "text", text: `Unknown action: ${params.action}` }],
|
|
213
|
-
details: {
|
|
214
|
-
action: "list",
|
|
215
|
-
todos: [...todos],
|
|
216
|
-
nextId,
|
|
217
|
-
error: `unknown action: ${params.action}`,
|
|
218
|
-
} as TodoDetails,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
|
|
223
|
-
renderCall(args, theme) {
|
|
224
|
-
let text = theme.fg("toolTitle", theme.bold("todo ")) + theme.fg("muted", args.action);
|
|
225
|
-
if (args.text) text += ` ${theme.fg("dim", `"${args.text}"`)}`;
|
|
226
|
-
if (args.id !== undefined) text += ` ${theme.fg("accent", `#${args.id}`)}`;
|
|
227
|
-
return new Text(text, 0, 0);
|
|
228
|
-
},
|
|
229
|
-
|
|
230
|
-
renderResult(result, { expanded }, theme) {
|
|
231
|
-
const details = result.details as TodoDetails | undefined;
|
|
232
|
-
if (!details) {
|
|
233
|
-
const text = result.content[0];
|
|
234
|
-
return new Text(text?.type === "text" ? text.text : "", 0, 0);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
if (details.error) {
|
|
238
|
-
return new Text(theme.fg("error", `Error: ${details.error}`), 0, 0);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const todoList = details.todos;
|
|
242
|
-
|
|
243
|
-
switch (details.action) {
|
|
244
|
-
case "list": {
|
|
245
|
-
if (todoList.length === 0) {
|
|
246
|
-
return new Text(theme.fg("dim", "No todos"), 0, 0);
|
|
247
|
-
}
|
|
248
|
-
let listText = theme.fg("muted", `${todoList.length} todo(s):`);
|
|
249
|
-
const display = expanded ? todoList : todoList.slice(0, 5);
|
|
250
|
-
for (const t of display) {
|
|
251
|
-
const check = t.done ? theme.fg("success", "✓") : theme.fg("dim", "○");
|
|
252
|
-
const itemText = t.done ? theme.fg("dim", t.text) : theme.fg("muted", t.text);
|
|
253
|
-
listText += `\n${check} ${theme.fg("accent", `#${t.id}`)} ${itemText}`;
|
|
254
|
-
}
|
|
255
|
-
if (!expanded && todoList.length > 5) {
|
|
256
|
-
listText += `\n${theme.fg("dim", `... ${todoList.length - 5} more`)}`;
|
|
257
|
-
}
|
|
258
|
-
return new Text(listText, 0, 0);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
case "add": {
|
|
262
|
-
const added = todoList[todoList.length - 1];
|
|
263
|
-
return new Text(
|
|
264
|
-
theme.fg("success", "✓ Added ") +
|
|
265
|
-
theme.fg("accent", `#${added.id}`) +
|
|
266
|
-
" " +
|
|
267
|
-
theme.fg("muted", added.text),
|
|
268
|
-
0,
|
|
269
|
-
0,
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
case "toggle": {
|
|
274
|
-
const text = result.content[0];
|
|
275
|
-
const msg = text?.type === "text" ? text.text : "";
|
|
276
|
-
return new Text(theme.fg("success", "✓ ") + theme.fg("muted", msg), 0, 0);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
case "clear":
|
|
280
|
-
return new Text(theme.fg("success", "✓ ") + theme.fg("muted", "Cleared all todos"), 0, 0);
|
|
281
|
-
}
|
|
282
|
-
},
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
// Register the /todos command for users
|
|
286
|
-
pi.registerCommand("todos", {
|
|
287
|
-
description: "Show all todos on the current branch",
|
|
288
|
-
handler: async (_args, ctx) => {
|
|
289
|
-
if (!ctx.hasUI) {
|
|
290
|
-
ctx.ui.notify("/todos requires interactive mode", "error");
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
await ctx.ui.custom<void>((_tui, theme, _kb, done) => {
|
|
295
|
-
return new TodoListComponent(todos, theme, () => done());
|
|
296
|
-
});
|
|
297
|
-
},
|
|
298
|
-
});
|
|
299
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@xtrm/pi-todo",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "xtrm Pi extension: todo",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": "./index.ts"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"pi",
|
|
11
|
-
"extension",
|
|
12
|
-
"xtrm"
|
|
13
|
-
],
|
|
14
|
-
"author": "xtrm",
|
|
15
|
-
"license": "MIT"
|
|
16
|
-
}
|
package/hooks/agent_context.py
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
import json
|
|
3
|
-
import sys
|
|
4
|
-
import os
|
|
5
|
-
|
|
6
|
-
class AgentContext:
|
|
7
|
-
def __init__(self):
|
|
8
|
-
try:
|
|
9
|
-
# Read JSON from stdin once
|
|
10
|
-
self.data = json.load(sys.stdin)
|
|
11
|
-
except Exception:
|
|
12
|
-
self.data = {}
|
|
13
|
-
|
|
14
|
-
self.tool_name = self.data.get('tool_name')
|
|
15
|
-
self.tool_input = self.data.get('tool_input', {})
|
|
16
|
-
self.event = self.data.get('hook_event_name')
|
|
17
|
-
self.prompt = self.data.get('prompt', '')
|
|
18
|
-
|
|
19
|
-
# Determine Agent Type
|
|
20
|
-
if self.tool_name in ['run_shell_command', 'read_file', 'write_file', 'replace']:
|
|
21
|
-
self.agent_type = 'gemini'
|
|
22
|
-
elif self.tool_name in ['Bash', 'Read', 'Write', 'Edit', 'Glob', 'Grep']:
|
|
23
|
-
self.agent_type = 'claude'
|
|
24
|
-
else:
|
|
25
|
-
# Fallback based on env vars
|
|
26
|
-
if os.environ.get('GEMINI_PROJECT_DIR'):
|
|
27
|
-
self.agent_type = 'gemini'
|
|
28
|
-
else:
|
|
29
|
-
self.agent_type = 'claude'
|
|
30
|
-
|
|
31
|
-
def is_shell_tool(self):
|
|
32
|
-
return self.tool_name in ['Bash', 'run_shell_command']
|
|
33
|
-
|
|
34
|
-
def is_write_tool(self):
|
|
35
|
-
return self.tool_name in ['Write', 'write_file']
|
|
36
|
-
|
|
37
|
-
def is_edit_tool(self):
|
|
38
|
-
return self.tool_name in ['Edit', 'replace']
|
|
39
|
-
|
|
40
|
-
def get_command(self):
|
|
41
|
-
return self.tool_input.get('command', '')
|
|
42
|
-
|
|
43
|
-
def get_file_path(self):
|
|
44
|
-
return self.tool_input.get('file_path', '')
|
|
45
|
-
|
|
46
|
-
def block(self, reason, system_message=None):
|
|
47
|
-
"""Unified block response.
|
|
48
|
-
|
|
49
|
-
Only PreToolUse hooks support permissionDecision: deny.
|
|
50
|
-
For other hooks, use continue: false to block execution.
|
|
51
|
-
"""
|
|
52
|
-
output = {}
|
|
53
|
-
|
|
54
|
-
if system_message:
|
|
55
|
-
output["systemMessage"] = system_message
|
|
56
|
-
|
|
57
|
-
# Only PreToolUse hooks support permissionDecision
|
|
58
|
-
if self.event == "PreToolUse":
|
|
59
|
-
output["hookSpecificOutput"] = {
|
|
60
|
-
"hookEventName": self.event,
|
|
61
|
-
"permissionDecision": "deny",
|
|
62
|
-
"permissionDecisionReason": reason
|
|
63
|
-
}
|
|
64
|
-
else:
|
|
65
|
-
# For non-PreToolUse hooks, use continue: false to block
|
|
66
|
-
output["continue"] = False
|
|
67
|
-
output["stopReason"] = reason
|
|
68
|
-
|
|
69
|
-
print(json.dumps(output))
|
|
70
|
-
sys.exit(0)
|
|
71
|
-
|
|
72
|
-
def allow(self, system_message=None, additional_context=None):
|
|
73
|
-
"""Unified allow response.
|
|
74
|
-
|
|
75
|
-
For PreToolUse hooks: outputs permissionDecision in hookSpecificOutput
|
|
76
|
-
For other hooks (UserPromptSubmit, SessionStart, PostToolUse):
|
|
77
|
-
only systemMessage and/or additionalContext are valid
|
|
78
|
-
"""
|
|
79
|
-
output = {}
|
|
80
|
-
|
|
81
|
-
if system_message:
|
|
82
|
-
output["systemMessage"] = system_message
|
|
83
|
-
|
|
84
|
-
# Build hookSpecificOutput if we have PreToolUse or additionalContext
|
|
85
|
-
if self.event == "PreToolUse" or additional_context:
|
|
86
|
-
hook_output = {"hookEventName": self.event}
|
|
87
|
-
|
|
88
|
-
# Only PreToolUse supports permissionDecision
|
|
89
|
-
if self.event == "PreToolUse":
|
|
90
|
-
hook_output["permissionDecision"] = "allow"
|
|
91
|
-
|
|
92
|
-
if additional_context:
|
|
93
|
-
hook_output["additionalContext"] = additional_context
|
|
94
|
-
|
|
95
|
-
output["hookSpecificOutput"] = hook_output
|
|
96
|
-
|
|
97
|
-
# Only print output if we have something to say
|
|
98
|
-
if output:
|
|
99
|
-
print(json.dumps(output))
|
|
100
|
-
|
|
101
|
-
sys.exit(0)
|
|
102
|
-
|
|
103
|
-
def fail_open(self):
|
|
104
|
-
"""Standard fail-open behavior"""
|
|
105
|
-
sys.exit(0)
|
package/hooks/branch-state.mjs
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// branch-state.mjs — UserPromptSubmit hook
|
|
3
|
-
// Re-injects current git branch and active beads claim at each prompt.
|
|
4
|
-
// Keeps the agent oriented after /compact or long sessions.
|
|
5
|
-
// Output: { hookSpecificOutput: { additionalSystemPrompt } }
|
|
6
|
-
|
|
7
|
-
import { execSync } from 'node:child_process';
|
|
8
|
-
import { readFileSync } from 'node:fs';
|
|
9
|
-
|
|
10
|
-
function readInput() {
|
|
11
|
-
try { return JSON.parse(readFileSync(0, 'utf-8')); } catch { return null; }
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function getBranch(cwd) {
|
|
15
|
-
try {
|
|
16
|
-
return execSync('git branch --show-current', {
|
|
17
|
-
encoding: 'utf8', cwd,
|
|
18
|
-
stdio: ['pipe', 'pipe', 'pipe'], timeout: 2000,
|
|
19
|
-
}).trim() || null;
|
|
20
|
-
} catch { return null; }
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
const input = readInput();
|
|
25
|
-
if (!input) process.exit(0);
|
|
26
|
-
|
|
27
|
-
const cwd = input.cwd || process.cwd();
|
|
28
|
-
const branch = getBranch(cwd);
|
|
29
|
-
|
|
30
|
-
if (!branch) process.exit(0);
|
|
31
|
-
|
|
32
|
-
process.stdout.write(JSON.stringify({
|
|
33
|
-
hookSpecificOutput: { additionalSystemPrompt: `[Context: branch=${branch}]` },
|
|
34
|
-
}));
|
|
35
|
-
process.stdout.write('\n');
|
|
36
|
-
process.exit(0);
|
|
37
|
-
} catch {
|
|
38
|
-
process.exit(0);
|
|
39
|
-
}
|