@apholdings/jensen-code 0.0.3 → 0.0.5
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/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +6 -6
- package/dist/cli/args.js.map +1 -1
- package/dist/config.d.ts +6 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +32 -25
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +25 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +1 -1
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts +4 -1
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +25 -11
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +5 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +0 -2
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +8 -146
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/header.d.ts +9 -3
- package/dist/modes/interactive/components/header.d.ts.map +1 -1
- package/dist/modes/interactive/components/header.js +125 -196
- package/dist/modes/interactive/components/header.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +1 -2
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +23 -4
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +657 -243
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +2 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js +8 -4
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +2 -2
- package/dist/utils/tools-manager.js.map +1 -1
- package/examples/extensions/osgrep.ts +643 -0
- package/examples/extensions/subagent/agents.ts +150 -38
- package/examples/extensions/subagent/index.ts +634 -514
- package/package.json +4 -3
- package/examples/README.md +0 -25
- package/examples/extensions/README.md +0 -206
- package/examples/extensions/antigravity-image-gen.ts +0 -416
- package/examples/extensions/auto-commit-on-exit.ts +0 -50
- package/examples/extensions/bash-spawn-hook.ts +0 -31
- package/examples/extensions/bookmark.ts +0 -51
- package/examples/extensions/built-in-tool-renderer.ts +0 -247
- package/examples/extensions/claude-rules.ts +0 -87
- package/examples/extensions/commands.ts +0 -73
- package/examples/extensions/confirm-destructive.ts +0 -60
- package/examples/extensions/custom-compaction.ts +0 -115
- package/examples/extensions/custom-footer.ts +0 -65
- package/examples/extensions/custom-header.ts +0 -74
- package/examples/extensions/custom-provider-anthropic/index.ts +0 -605
- package/examples/extensions/custom-provider-anthropic/package-lock.json +0 -24
- package/examples/extensions/custom-provider-anthropic/package.json +0 -19
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +0 -350
- package/examples/extensions/custom-provider-gitlab-duo/package.json +0 -16
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +0 -82
- package/examples/extensions/custom-provider-qwen-cli/index.ts +0 -346
- package/examples/extensions/custom-provider-qwen-cli/package.json +0 -16
- package/examples/extensions/dirty-repo-guard.ts +0 -57
- package/examples/extensions/doom-overlay/README.md +0 -46
- package/examples/extensions/doom-overlay/doom/build/doom.js +0 -21
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +0 -152
- package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +0 -72
- package/examples/extensions/doom-overlay/doom-component.ts +0 -132
- package/examples/extensions/doom-overlay/doom-engine.ts +0 -173
- package/examples/extensions/doom-overlay/doom-keys.ts +0 -104
- package/examples/extensions/doom-overlay/index.ts +0 -75
- package/examples/extensions/doom-overlay/wad-finder.ts +0 -51
- package/examples/extensions/dynamic-resources/SKILL.md +0 -8
- package/examples/extensions/dynamic-resources/dynamic.json +0 -79
- package/examples/extensions/dynamic-resources/dynamic.md +0 -5
- package/examples/extensions/dynamic-resources/index.ts +0 -16
- package/examples/extensions/dynamic-tools.ts +0 -75
- package/examples/extensions/event-bus.ts +0 -44
- package/examples/extensions/file-trigger.ts +0 -42
- package/examples/extensions/git-checkpoint.ts +0 -54
- package/examples/extensions/handoff.ts +0 -151
- package/examples/extensions/hello.ts +0 -26
- package/examples/extensions/inline-bash.ts +0 -95
- package/examples/extensions/input-transform.ts +0 -44
- package/examples/extensions/interactive-shell.ts +0 -197
- package/examples/extensions/mac-system-theme.ts +0 -48
- package/examples/extensions/message-renderer.ts +0 -60
- package/examples/extensions/minimal-mode.ts +0 -427
- package/examples/extensions/modal-editor.ts +0 -86
- package/examples/extensions/model-status.ts +0 -32
- package/examples/extensions/notify.ts +0 -56
- package/examples/extensions/overlay-qa-tests.ts +0 -1349
- package/examples/extensions/overlay-test.ts +0 -151
- package/examples/extensions/permission-gate.ts +0 -35
- package/examples/extensions/pirate.ts +0 -48
- package/examples/extensions/plan-mode/README.md +0 -65
- package/examples/extensions/plan-mode/index.ts +0 -341
- package/examples/extensions/plan-mode/utils.ts +0 -168
- package/examples/extensions/preset.ts +0 -399
- package/examples/extensions/protected-paths.ts +0 -31
- package/examples/extensions/provider-payload.ts +0 -15
- package/examples/extensions/qna.ts +0 -120
- package/examples/extensions/question.ts +0 -265
- package/examples/extensions/questionnaire.ts +0 -428
- package/examples/extensions/rainbow-editor.ts +0 -89
- package/examples/extensions/reload-runtime.ts +0 -38
- package/examples/extensions/rpc-demo.ts +0 -125
- package/examples/extensions/sandbox/index.ts +0 -319
- package/examples/extensions/sandbox/package-lock.json +0 -92
- package/examples/extensions/sandbox/package.json +0 -19
- package/examples/extensions/send-user-message.ts +0 -98
- package/examples/extensions/session-name.ts +0 -28
- package/examples/extensions/shutdown-command.ts +0 -64
- package/examples/extensions/snake.ts +0 -344
- package/examples/extensions/space-invaders.ts +0 -561
- package/examples/extensions/ssh.ts +0 -221
- package/examples/extensions/status-line.ts +0 -41
- package/examples/extensions/subagent/README.md +0 -172
- package/examples/extensions/subagent/agents/planner.md +0 -37
- package/examples/extensions/subagent/agents/reviewer.md +0 -35
- package/examples/extensions/subagent/agents/scout.md +0 -50
- package/examples/extensions/subagent/agents/worker.md +0 -24
- package/examples/extensions/subagent/prompts/implement-and-review.md +0 -10
- package/examples/extensions/subagent/prompts/implement.md +0 -10
- package/examples/extensions/subagent/prompts/scout-and-plan.md +0 -9
- package/examples/extensions/summarize.ts +0 -196
- package/examples/extensions/system-prompt-header.ts +0 -18
- package/examples/extensions/timed-confirm.ts +0 -71
- package/examples/extensions/titlebar-spinner.ts +0 -59
- package/examples/extensions/todo.ts +0 -300
- package/examples/extensions/tool-override.ts +0 -144
- package/examples/extensions/tools.ts +0 -147
- package/examples/extensions/trigger-compact.ts +0 -41
- package/examples/extensions/truncated-tool.ts +0 -193
- package/examples/extensions/widget-placement.ts +0 -18
- package/examples/extensions/with-deps/index.ts +0 -33
- package/examples/extensions/with-deps/package-lock.json +0 -31
- package/examples/extensions/with-deps/package.json +0 -22
- package/examples/rpc-extension-ui.ts +0 -632
- package/examples/sdk/01-minimal.ts +0 -23
- package/examples/sdk/02-custom-model.ts +0 -50
- package/examples/sdk/03-custom-prompt.ts +0 -56
- package/examples/sdk/04-skills.ts +0 -47
- package/examples/sdk/05-tools.ts +0 -57
- package/examples/sdk/06-extensions.ts +0 -89
- package/examples/sdk/07-context-files.ts +0 -41
- package/examples/sdk/08-prompt-templates.ts +0 -48
- package/examples/sdk/09-api-keys-and-oauth.ts +0 -49
- package/examples/sdk/10-settings.ts +0 -52
- package/examples/sdk/11-sessions.ts +0 -49
- package/examples/sdk/12-full-control.ts +0 -83
- package/examples/sdk/README.md +0 -145
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Minimal Mode Example - Demonstrates a "minimal" tool display mode
|
|
3
|
-
*
|
|
4
|
-
* This extension overrides built-in tools to provide custom rendering:
|
|
5
|
-
* - Collapsed mode: Only shows the tool call (command/path), no output
|
|
6
|
-
* - Expanded mode: Shows full output like the built-in renderers
|
|
7
|
-
*
|
|
8
|
-
* This demonstrates how a "minimal mode" could work, where ctrl+o cycles through:
|
|
9
|
-
* - Standard: Shows truncated output (current default)
|
|
10
|
-
* - Expanded: Shows full output (current expanded)
|
|
11
|
-
* - Minimal: Shows only tool call, no output (this extension's collapsed mode)
|
|
12
|
-
*
|
|
13
|
-
* Usage:
|
|
14
|
-
* pi -e ./minimal-mode.ts
|
|
15
|
-
*
|
|
16
|
-
* Then use ctrl+o to toggle between minimal (collapsed) and full (expanded) views.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import type { ExtensionAPI } from "@apholdings/jensen-code";
|
|
20
|
-
import {
|
|
21
|
-
createBashTool,
|
|
22
|
-
createEditTool,
|
|
23
|
-
createFindTool,
|
|
24
|
-
createGrepTool,
|
|
25
|
-
createLsTool,
|
|
26
|
-
createReadTool,
|
|
27
|
-
createWriteTool,
|
|
28
|
-
} from "@apholdings/jensen-code";
|
|
29
|
-
import { Text } from "@apholdings/jensen-tui";
|
|
30
|
-
import { homedir } from "os";
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Shorten a path by replacing home directory with ~
|
|
34
|
-
*/
|
|
35
|
-
function shortenPath(path: string): string {
|
|
36
|
-
const home = homedir();
|
|
37
|
-
if (path.startsWith(home)) {
|
|
38
|
-
return `~${path.slice(home.length)}`;
|
|
39
|
-
}
|
|
40
|
-
return path;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Cache for built-in tools by cwd
|
|
44
|
-
const toolCache = new Map<string, ReturnType<typeof createBuiltInTools>>();
|
|
45
|
-
|
|
46
|
-
function createBuiltInTools(cwd: string) {
|
|
47
|
-
return {
|
|
48
|
-
read: createReadTool(cwd),
|
|
49
|
-
bash: createBashTool(cwd),
|
|
50
|
-
edit: createEditTool(cwd),
|
|
51
|
-
write: createWriteTool(cwd),
|
|
52
|
-
find: createFindTool(cwd),
|
|
53
|
-
grep: createGrepTool(cwd),
|
|
54
|
-
ls: createLsTool(cwd),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function getBuiltInTools(cwd: string) {
|
|
59
|
-
let tools = toolCache.get(cwd);
|
|
60
|
-
if (!tools) {
|
|
61
|
-
tools = createBuiltInTools(cwd);
|
|
62
|
-
toolCache.set(cwd, tools);
|
|
63
|
-
}
|
|
64
|
-
return tools;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export default function (pi: ExtensionAPI) {
|
|
68
|
-
// =========================================================================
|
|
69
|
-
// Read Tool
|
|
70
|
-
// =========================================================================
|
|
71
|
-
pi.registerTool({
|
|
72
|
-
name: "read",
|
|
73
|
-
label: "read",
|
|
74
|
-
description:
|
|
75
|
-
"Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to 2000 lines or 50KB (whichever is hit first). Use offset/limit for large files.",
|
|
76
|
-
parameters: getBuiltInTools(process.cwd()).read.parameters,
|
|
77
|
-
|
|
78
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
79
|
-
const tools = getBuiltInTools(ctx.cwd);
|
|
80
|
-
return tools.read.execute(toolCallId, params, signal, onUpdate);
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
renderCall(args, theme) {
|
|
84
|
-
const path = shortenPath(args.path || "");
|
|
85
|
-
let pathDisplay = path ? theme.fg("accent", path) : theme.fg("toolOutput", "...");
|
|
86
|
-
|
|
87
|
-
// Show line range if specified
|
|
88
|
-
if (args.offset !== undefined || args.limit !== undefined) {
|
|
89
|
-
const startLine = args.offset ?? 1;
|
|
90
|
-
const endLine = args.limit !== undefined ? startLine + args.limit - 1 : "";
|
|
91
|
-
pathDisplay += theme.fg("warning", `:${startLine}${endLine ? `-${endLine}` : ""}`);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return new Text(`${theme.fg("toolTitle", theme.bold("read"))} ${pathDisplay}`, 0, 0);
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
renderResult(result, { expanded }, theme) {
|
|
98
|
-
// Minimal mode: show nothing in collapsed state
|
|
99
|
-
if (!expanded) {
|
|
100
|
-
return new Text("", 0, 0);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Expanded mode: show full output
|
|
104
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
105
|
-
if (!textContent || textContent.type !== "text") {
|
|
106
|
-
return new Text("", 0, 0);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const lines = textContent.text.split("\n");
|
|
110
|
-
const output = lines.map((line) => theme.fg("toolOutput", line)).join("\n");
|
|
111
|
-
return new Text(`\n${output}`, 0, 0);
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// =========================================================================
|
|
116
|
-
// Bash Tool
|
|
117
|
-
// =========================================================================
|
|
118
|
-
pi.registerTool({
|
|
119
|
-
name: "bash",
|
|
120
|
-
label: "bash",
|
|
121
|
-
description:
|
|
122
|
-
"Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last 2000 lines or 50KB (whichever is hit first).",
|
|
123
|
-
parameters: getBuiltInTools(process.cwd()).bash.parameters,
|
|
124
|
-
|
|
125
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
126
|
-
const tools = getBuiltInTools(ctx.cwd);
|
|
127
|
-
return tools.bash.execute(toolCallId, params, signal, onUpdate);
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
renderCall(args, theme) {
|
|
131
|
-
const command = args.command || "...";
|
|
132
|
-
const timeout = args.timeout as number | undefined;
|
|
133
|
-
const timeoutSuffix = timeout ? theme.fg("muted", ` (timeout ${timeout}s)`) : "";
|
|
134
|
-
|
|
135
|
-
return new Text(theme.fg("toolTitle", theme.bold(`$ ${command}`)) + timeoutSuffix, 0, 0);
|
|
136
|
-
},
|
|
137
|
-
|
|
138
|
-
renderResult(result, { expanded }, theme) {
|
|
139
|
-
// Minimal mode: show nothing in collapsed state
|
|
140
|
-
if (!expanded) {
|
|
141
|
-
return new Text("", 0, 0);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Expanded mode: show full output
|
|
145
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
146
|
-
if (!textContent || textContent.type !== "text") {
|
|
147
|
-
return new Text("", 0, 0);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const output = textContent.text
|
|
151
|
-
.trim()
|
|
152
|
-
.split("\n")
|
|
153
|
-
.map((line) => theme.fg("toolOutput", line))
|
|
154
|
-
.join("\n");
|
|
155
|
-
|
|
156
|
-
if (!output) {
|
|
157
|
-
return new Text("", 0, 0);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return new Text(`\n${output}`, 0, 0);
|
|
161
|
-
},
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
// =========================================================================
|
|
165
|
-
// Write Tool
|
|
166
|
-
// =========================================================================
|
|
167
|
-
pi.registerTool({
|
|
168
|
-
name: "write",
|
|
169
|
-
label: "write",
|
|
170
|
-
description:
|
|
171
|
-
"Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.",
|
|
172
|
-
parameters: getBuiltInTools(process.cwd()).write.parameters,
|
|
173
|
-
|
|
174
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
175
|
-
const tools = getBuiltInTools(ctx.cwd);
|
|
176
|
-
return tools.write.execute(toolCallId, params, signal, onUpdate);
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
renderCall(args, theme) {
|
|
180
|
-
const path = shortenPath(args.path || "");
|
|
181
|
-
const pathDisplay = path ? theme.fg("accent", path) : theme.fg("toolOutput", "...");
|
|
182
|
-
const lineCount = args.content ? args.content.split("\n").length : 0;
|
|
183
|
-
const lineInfo = lineCount > 0 ? theme.fg("muted", ` (${lineCount} lines)`) : "";
|
|
184
|
-
|
|
185
|
-
return new Text(`${theme.fg("toolTitle", theme.bold("write"))} ${pathDisplay}${lineInfo}`, 0, 0);
|
|
186
|
-
},
|
|
187
|
-
|
|
188
|
-
renderResult(result, { expanded }, theme) {
|
|
189
|
-
// Minimal mode: show nothing (file was written)
|
|
190
|
-
if (!expanded) {
|
|
191
|
-
return new Text("", 0, 0);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Expanded mode: show error if any
|
|
195
|
-
if (result.content.some((c) => c.type === "text" && c.text)) {
|
|
196
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
197
|
-
if (textContent?.type === "text" && textContent.text) {
|
|
198
|
-
return new Text(`\n${theme.fg("error", textContent.text)}`, 0, 0);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return new Text("", 0, 0);
|
|
203
|
-
},
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// =========================================================================
|
|
207
|
-
// Edit Tool
|
|
208
|
-
// =========================================================================
|
|
209
|
-
pi.registerTool({
|
|
210
|
-
name: "edit",
|
|
211
|
-
label: "edit",
|
|
212
|
-
description:
|
|
213
|
-
"Edit a file by replacing exact text. The oldText must match exactly (including whitespace). Use this for precise, surgical edits.",
|
|
214
|
-
parameters: getBuiltInTools(process.cwd()).edit.parameters,
|
|
215
|
-
|
|
216
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
217
|
-
const tools = getBuiltInTools(ctx.cwd);
|
|
218
|
-
return tools.edit.execute(toolCallId, params, signal, onUpdate);
|
|
219
|
-
},
|
|
220
|
-
|
|
221
|
-
renderCall(args, theme) {
|
|
222
|
-
const path = shortenPath(args.path || "");
|
|
223
|
-
const pathDisplay = path ? theme.fg("accent", path) : theme.fg("toolOutput", "...");
|
|
224
|
-
|
|
225
|
-
return new Text(`${theme.fg("toolTitle", theme.bold("edit"))} ${pathDisplay}`, 0, 0);
|
|
226
|
-
},
|
|
227
|
-
|
|
228
|
-
renderResult(result, { expanded }, theme) {
|
|
229
|
-
// Minimal mode: show nothing in collapsed state
|
|
230
|
-
if (!expanded) {
|
|
231
|
-
return new Text("", 0, 0);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Expanded mode: show diff or error
|
|
235
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
236
|
-
if (!textContent || textContent.type !== "text") {
|
|
237
|
-
return new Text("", 0, 0);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// For errors, show the error message
|
|
241
|
-
const text = textContent.text;
|
|
242
|
-
if (text.includes("Error") || text.includes("error")) {
|
|
243
|
-
return new Text(`\n${theme.fg("error", text)}`, 0, 0);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// Otherwise show the text (would be nice to show actual diff here)
|
|
247
|
-
return new Text(`\n${theme.fg("toolOutput", text)}`, 0, 0);
|
|
248
|
-
},
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
// =========================================================================
|
|
252
|
-
// Find Tool
|
|
253
|
-
// =========================================================================
|
|
254
|
-
pi.registerTool({
|
|
255
|
-
name: "find",
|
|
256
|
-
label: "find",
|
|
257
|
-
description:
|
|
258
|
-
"Find files by name pattern (glob). Searches recursively from the specified path. Output limited to 200 results.",
|
|
259
|
-
parameters: getBuiltInTools(process.cwd()).find.parameters,
|
|
260
|
-
|
|
261
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
262
|
-
const tools = getBuiltInTools(ctx.cwd);
|
|
263
|
-
return tools.find.execute(toolCallId, params, signal, onUpdate);
|
|
264
|
-
},
|
|
265
|
-
|
|
266
|
-
renderCall(args, theme) {
|
|
267
|
-
const pattern = args.pattern || "";
|
|
268
|
-
const path = shortenPath(args.path || ".");
|
|
269
|
-
const limit = args.limit;
|
|
270
|
-
|
|
271
|
-
let text = `${theme.fg("toolTitle", theme.bold("find"))} ${theme.fg("accent", pattern)}`;
|
|
272
|
-
text += theme.fg("toolOutput", ` in ${path}`);
|
|
273
|
-
if (limit !== undefined) {
|
|
274
|
-
text += theme.fg("toolOutput", ` (limit ${limit})`);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return new Text(text, 0, 0);
|
|
278
|
-
},
|
|
279
|
-
|
|
280
|
-
renderResult(result, { expanded }, theme) {
|
|
281
|
-
if (!expanded) {
|
|
282
|
-
// Minimal: just show count
|
|
283
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
284
|
-
if (textContent?.type === "text") {
|
|
285
|
-
const count = textContent.text.trim().split("\n").filter(Boolean).length;
|
|
286
|
-
if (count > 0) {
|
|
287
|
-
return new Text(theme.fg("muted", ` → ${count} files`), 0, 0);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
return new Text("", 0, 0);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// Expanded: show full results
|
|
294
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
295
|
-
if (!textContent || textContent.type !== "text") {
|
|
296
|
-
return new Text("", 0, 0);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
const output = textContent.text
|
|
300
|
-
.trim()
|
|
301
|
-
.split("\n")
|
|
302
|
-
.map((line) => theme.fg("toolOutput", line))
|
|
303
|
-
.join("\n");
|
|
304
|
-
|
|
305
|
-
return new Text(`\n${output}`, 0, 0);
|
|
306
|
-
},
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
// =========================================================================
|
|
310
|
-
// Grep Tool
|
|
311
|
-
// =========================================================================
|
|
312
|
-
pi.registerTool({
|
|
313
|
-
name: "grep",
|
|
314
|
-
label: "grep",
|
|
315
|
-
description:
|
|
316
|
-
"Search file contents by regex pattern. Uses ripgrep for fast searching. Output limited to 200 matches.",
|
|
317
|
-
parameters: getBuiltInTools(process.cwd()).grep.parameters,
|
|
318
|
-
|
|
319
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
320
|
-
const tools = getBuiltInTools(ctx.cwd);
|
|
321
|
-
return tools.grep.execute(toolCallId, params, signal, onUpdate);
|
|
322
|
-
},
|
|
323
|
-
|
|
324
|
-
renderCall(args, theme) {
|
|
325
|
-
const pattern = args.pattern || "";
|
|
326
|
-
const path = shortenPath(args.path || ".");
|
|
327
|
-
const glob = args.glob;
|
|
328
|
-
const limit = args.limit;
|
|
329
|
-
|
|
330
|
-
let text = `${theme.fg("toolTitle", theme.bold("grep"))} ${theme.fg("accent", `/${pattern}/`)}`;
|
|
331
|
-
text += theme.fg("toolOutput", ` in ${path}`);
|
|
332
|
-
if (glob) {
|
|
333
|
-
text += theme.fg("toolOutput", ` (${glob})`);
|
|
334
|
-
}
|
|
335
|
-
if (limit !== undefined) {
|
|
336
|
-
text += theme.fg("toolOutput", ` limit ${limit}`);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
return new Text(text, 0, 0);
|
|
340
|
-
},
|
|
341
|
-
|
|
342
|
-
renderResult(result, { expanded }, theme) {
|
|
343
|
-
if (!expanded) {
|
|
344
|
-
// Minimal: just show match count
|
|
345
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
346
|
-
if (textContent?.type === "text") {
|
|
347
|
-
const count = textContent.text.trim().split("\n").filter(Boolean).length;
|
|
348
|
-
if (count > 0) {
|
|
349
|
-
return new Text(theme.fg("muted", ` → ${count} matches`), 0, 0);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return new Text("", 0, 0);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// Expanded: show full results
|
|
356
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
357
|
-
if (!textContent || textContent.type !== "text") {
|
|
358
|
-
return new Text("", 0, 0);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
const output = textContent.text
|
|
362
|
-
.trim()
|
|
363
|
-
.split("\n")
|
|
364
|
-
.map((line) => theme.fg("toolOutput", line))
|
|
365
|
-
.join("\n");
|
|
366
|
-
|
|
367
|
-
return new Text(`\n${output}`, 0, 0);
|
|
368
|
-
},
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
// =========================================================================
|
|
372
|
-
// Ls Tool
|
|
373
|
-
// =========================================================================
|
|
374
|
-
pi.registerTool({
|
|
375
|
-
name: "ls",
|
|
376
|
-
label: "ls",
|
|
377
|
-
description:
|
|
378
|
-
"List directory contents with file sizes. Shows files and directories with their sizes. Output limited to 500 entries.",
|
|
379
|
-
parameters: getBuiltInTools(process.cwd()).ls.parameters,
|
|
380
|
-
|
|
381
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
382
|
-
const tools = getBuiltInTools(ctx.cwd);
|
|
383
|
-
return tools.ls.execute(toolCallId, params, signal, onUpdate);
|
|
384
|
-
},
|
|
385
|
-
|
|
386
|
-
renderCall(args, theme) {
|
|
387
|
-
const path = shortenPath(args.path || ".");
|
|
388
|
-
const limit = args.limit;
|
|
389
|
-
|
|
390
|
-
let text = `${theme.fg("toolTitle", theme.bold("ls"))} ${theme.fg("accent", path)}`;
|
|
391
|
-
if (limit !== undefined) {
|
|
392
|
-
text += theme.fg("toolOutput", ` (limit ${limit})`);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
return new Text(text, 0, 0);
|
|
396
|
-
},
|
|
397
|
-
|
|
398
|
-
renderResult(result, { expanded }, theme) {
|
|
399
|
-
if (!expanded) {
|
|
400
|
-
// Minimal: just show entry count
|
|
401
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
402
|
-
if (textContent?.type === "text") {
|
|
403
|
-
const count = textContent.text.trim().split("\n").filter(Boolean).length;
|
|
404
|
-
if (count > 0) {
|
|
405
|
-
return new Text(theme.fg("muted", ` → ${count} entries`), 0, 0);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
return new Text("", 0, 0);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// Expanded: show full listing
|
|
412
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
413
|
-
if (!textContent || textContent.type !== "text") {
|
|
414
|
-
return new Text("", 0, 0);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
const output = textContent.text
|
|
418
|
-
.trim()
|
|
419
|
-
.split("\n")
|
|
420
|
-
.map((line) => theme.fg("toolOutput", line))
|
|
421
|
-
.join("\n");
|
|
422
|
-
|
|
423
|
-
return new Text(`\n${output}`, 0, 0);
|
|
424
|
-
},
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Modal Editor - vim-like modal editing example
|
|
3
|
-
*
|
|
4
|
-
* Usage: pi --extension ./examples/extensions/modal-editor.ts
|
|
5
|
-
*
|
|
6
|
-
* - Escape: insert → normal mode (in normal mode, aborts agent)
|
|
7
|
-
* - i: normal → insert mode
|
|
8
|
-
* - hjkl: navigation in normal mode
|
|
9
|
-
* - ctrl+c, ctrl+d, etc. work in both modes
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { CustomEditor, type ExtensionAPI } from "@apholdings/jensen-code";
|
|
13
|
-
import { matchesKey, truncateToWidth, visibleWidth } from "@apholdings/jensen-tui";
|
|
14
|
-
|
|
15
|
-
// Normal mode key mappings: key -> escape sequence (or null for mode switch)
|
|
16
|
-
const NORMAL_KEYS: Record<string, string | null> = {
|
|
17
|
-
h: "\x1b[D", // left
|
|
18
|
-
j: "\x1b[B", // down
|
|
19
|
-
k: "\x1b[A", // up
|
|
20
|
-
l: "\x1b[C", // right
|
|
21
|
-
"0": "\x01", // line start
|
|
22
|
-
$: "\x05", // line end
|
|
23
|
-
x: "\x1b[3~", // delete char
|
|
24
|
-
i: null, // insert mode
|
|
25
|
-
a: null, // append (insert + right)
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
class ModalEditor extends CustomEditor {
|
|
29
|
-
private mode: "normal" | "insert" = "insert";
|
|
30
|
-
|
|
31
|
-
handleInput(data: string): void {
|
|
32
|
-
// Escape toggles to normal mode, or passes through for app handling
|
|
33
|
-
if (matchesKey(data, "escape")) {
|
|
34
|
-
if (this.mode === "insert") {
|
|
35
|
-
this.mode = "normal";
|
|
36
|
-
} else {
|
|
37
|
-
super.handleInput(data); // abort agent, etc.
|
|
38
|
-
}
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Insert mode: pass everything through
|
|
43
|
-
if (this.mode === "insert") {
|
|
44
|
-
super.handleInput(data);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Normal mode: check mapped keys
|
|
49
|
-
if (data in NORMAL_KEYS) {
|
|
50
|
-
const seq = NORMAL_KEYS[data];
|
|
51
|
-
if (data === "i") {
|
|
52
|
-
this.mode = "insert";
|
|
53
|
-
} else if (data === "a") {
|
|
54
|
-
this.mode = "insert";
|
|
55
|
-
super.handleInput("\x1b[C"); // move right first
|
|
56
|
-
} else if (seq) {
|
|
57
|
-
super.handleInput(seq);
|
|
58
|
-
}
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Pass control sequences (ctrl+c, etc.) to super, ignore printable chars
|
|
63
|
-
if (data.length === 1 && data.charCodeAt(0) >= 32) return;
|
|
64
|
-
super.handleInput(data);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
render(width: number): string[] {
|
|
68
|
-
const lines = super.render(width);
|
|
69
|
-
if (lines.length === 0) return lines;
|
|
70
|
-
|
|
71
|
-
// Add mode indicator to bottom border
|
|
72
|
-
const label = this.mode === "normal" ? " NORMAL " : " INSERT ";
|
|
73
|
-
const last = lines.length - 1;
|
|
74
|
-
if (visibleWidth(lines[last]!) >= label.length) {
|
|
75
|
-
lines[last] = truncateToWidth(lines[last]!, width - label.length, "") + label;
|
|
76
|
-
}
|
|
77
|
-
return lines;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export default function (pi: ExtensionAPI) {
|
|
82
|
-
pi.on("session_start", (_event, ctx) => {
|
|
83
|
-
ctx.ui.setEditorComponent((tui, theme, kb) => new ModalEditor(tui, theme, kb));
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Model status extension - shows model changes in the status bar.
|
|
3
|
-
*
|
|
4
|
-
* Demonstrates the `model_select` hook which fires when the model changes
|
|
5
|
-
* via /model command, Ctrl+P cycling, or session restore.
|
|
6
|
-
*
|
|
7
|
-
* Usage: pi -e ./model-status.ts
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { ExtensionAPI } from "@apholdings/jensen-code";
|
|
11
|
-
|
|
12
|
-
export default function (pi: ExtensionAPI) {
|
|
13
|
-
pi.on("model_select", async (event, ctx) => {
|
|
14
|
-
const { model, previousModel, source } = event;
|
|
15
|
-
|
|
16
|
-
// Format model identifiers
|
|
17
|
-
const next = `${model.provider}/${model.id}`;
|
|
18
|
-
const prev = previousModel ? `${previousModel.provider}/${previousModel.id}` : "none";
|
|
19
|
-
|
|
20
|
-
// Show notification on change
|
|
21
|
-
if (source !== "restore") {
|
|
22
|
-
ctx.ui.notify(`Model: ${next}`, "info");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Update status bar with current model
|
|
26
|
-
ctx.ui.setStatus("model", `🤖 ${model.id}`);
|
|
27
|
-
|
|
28
|
-
// Log change details (visible in debug output)
|
|
29
|
-
console.log(`[model_select] ${prev} → ${next} (${source})`);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pi Notify Extension
|
|
3
|
-
*
|
|
4
|
-
* Sends a native terminal notification when Pi agent is done and waiting for input.
|
|
5
|
-
* Supports multiple terminal protocols:
|
|
6
|
-
* - OSC 777: Ghostty, iTerm2, WezTerm, rxvt-unicode
|
|
7
|
-
* - OSC 99: Kitty
|
|
8
|
-
* - Windows toast: Windows Terminal (WSL)
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type { ExtensionAPI } from "@apholdings/jensen-code";
|
|
12
|
-
|
|
13
|
-
function windowsToastScript(title: string, body: string): string {
|
|
14
|
-
const type = "Windows.UI.Notifications";
|
|
15
|
-
const mgr = `[${type}.ToastNotificationManager, ${type}, ContentType = WindowsRuntime]`;
|
|
16
|
-
const template = `[${type}.ToastTemplateType]::ToastText01`;
|
|
17
|
-
const toast = `[${type}.ToastNotification]::new($xml)`;
|
|
18
|
-
return [
|
|
19
|
-
`${mgr} > $null`,
|
|
20
|
-
`$xml = [${type}.ToastNotificationManager]::GetTemplateContent(${template})`,
|
|
21
|
-
`$xml.GetElementsByTagName('text')[0].AppendChild($xml.CreateTextNode('${body}')) > $null`,
|
|
22
|
-
`[${type}.ToastNotificationManager]::CreateToastNotifier('${title}').Show(${toast})`,
|
|
23
|
-
].join("; ");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function notifyOSC777(title: string, body: string): void {
|
|
27
|
-
process.stdout.write(`\x1b]777;notify;${title};${body}\x07`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function notifyOSC99(title: string, body: string): void {
|
|
31
|
-
// Kitty OSC 99: i=notification id, d=0 means not done yet, p=body for second part
|
|
32
|
-
process.stdout.write(`\x1b]99;i=1:d=0;${title}\x1b\\`);
|
|
33
|
-
process.stdout.write(`\x1b]99;i=1:p=body;${body}\x1b\\`);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function notifyWindows(title: string, body: string): void {
|
|
37
|
-
const { execFile } = require("child_process");
|
|
38
|
-
execFile("powershell.exe", ["-NoProfile", "-Command", windowsToastScript(title, body)]);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function notify(title: string, body: string): void {
|
|
42
|
-
if (process.env.WT_SESSION) {
|
|
43
|
-
notifyWindows(title, body);
|
|
44
|
-
} else if (process.env.KITTY_WINDOW_ID) {
|
|
45
|
-
notifyOSC99(title, body);
|
|
46
|
-
} else {
|
|
47
|
-
notifyOSC777(title, body);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export default function (pi: ExtensionAPI) {
|
|
52
|
-
pi.on("agent_end", async () => {
|
|
53
|
-
notify("Pi", "Ready for input");
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|