gsd-pi 2.29.0-dev.2ccf3fb → 2.29.0-dev.6a38b5d

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.
Files changed (50) hide show
  1. package/dist/resources/extensions/gsd/prompts/guided-discuss-milestone.md +1 -1
  2. package/package.json +1 -1
  3. package/packages/native/dist/native.d.ts +0 -2
  4. package/packages/native/dist/native.js +5 -19
  5. package/packages/native/src/native.ts +9 -23
  6. package/src/resources/extensions/gsd/prompts/guided-discuss-milestone.md +1 -1
  7. package/dist/resources/skills/create-gsd-extension/SKILL.md +0 -87
  8. package/dist/resources/skills/create-gsd-extension/references/compaction-session-control.md +0 -77
  9. package/dist/resources/skills/create-gsd-extension/references/custom-commands.md +0 -139
  10. package/dist/resources/skills/create-gsd-extension/references/custom-rendering.md +0 -108
  11. package/dist/resources/skills/create-gsd-extension/references/custom-tools.md +0 -183
  12. package/dist/resources/skills/create-gsd-extension/references/custom-ui.md +0 -490
  13. package/dist/resources/skills/create-gsd-extension/references/events-reference.md +0 -126
  14. package/dist/resources/skills/create-gsd-extension/references/extension-lifecycle.md +0 -64
  15. package/dist/resources/skills/create-gsd-extension/references/extensionapi-reference.md +0 -75
  16. package/dist/resources/skills/create-gsd-extension/references/extensioncontext-reference.md +0 -53
  17. package/dist/resources/skills/create-gsd-extension/references/key-rules-gotchas.md +0 -36
  18. package/dist/resources/skills/create-gsd-extension/references/mode-behavior.md +0 -32
  19. package/dist/resources/skills/create-gsd-extension/references/model-provider-management.md +0 -89
  20. package/dist/resources/skills/create-gsd-extension/references/packaging-distribution.md +0 -55
  21. package/dist/resources/skills/create-gsd-extension/references/remote-execution-overrides.md +0 -90
  22. package/dist/resources/skills/create-gsd-extension/references/state-management.md +0 -70
  23. package/dist/resources/skills/create-gsd-extension/references/system-prompt-modification.md +0 -52
  24. package/dist/resources/skills/create-gsd-extension/templates/extension-skeleton.ts +0 -51
  25. package/dist/resources/skills/create-gsd-extension/templates/stateful-tool-skeleton.ts +0 -143
  26. package/dist/resources/skills/create-gsd-extension/workflows/add-capability.md +0 -57
  27. package/dist/resources/skills/create-gsd-extension/workflows/create-extension.md +0 -156
  28. package/dist/resources/skills/create-gsd-extension/workflows/debug-extension.md +0 -74
  29. package/src/resources/skills/create-gsd-extension/SKILL.md +0 -87
  30. package/src/resources/skills/create-gsd-extension/references/compaction-session-control.md +0 -77
  31. package/src/resources/skills/create-gsd-extension/references/custom-commands.md +0 -139
  32. package/src/resources/skills/create-gsd-extension/references/custom-rendering.md +0 -108
  33. package/src/resources/skills/create-gsd-extension/references/custom-tools.md +0 -183
  34. package/src/resources/skills/create-gsd-extension/references/custom-ui.md +0 -490
  35. package/src/resources/skills/create-gsd-extension/references/events-reference.md +0 -126
  36. package/src/resources/skills/create-gsd-extension/references/extension-lifecycle.md +0 -64
  37. package/src/resources/skills/create-gsd-extension/references/extensionapi-reference.md +0 -75
  38. package/src/resources/skills/create-gsd-extension/references/extensioncontext-reference.md +0 -53
  39. package/src/resources/skills/create-gsd-extension/references/key-rules-gotchas.md +0 -36
  40. package/src/resources/skills/create-gsd-extension/references/mode-behavior.md +0 -32
  41. package/src/resources/skills/create-gsd-extension/references/model-provider-management.md +0 -89
  42. package/src/resources/skills/create-gsd-extension/references/packaging-distribution.md +0 -55
  43. package/src/resources/skills/create-gsd-extension/references/remote-execution-overrides.md +0 -90
  44. package/src/resources/skills/create-gsd-extension/references/state-management.md +0 -70
  45. package/src/resources/skills/create-gsd-extension/references/system-prompt-modification.md +0 -52
  46. package/src/resources/skills/create-gsd-extension/templates/extension-skeleton.ts +0 -51
  47. package/src/resources/skills/create-gsd-extension/templates/stateful-tool-skeleton.ts +0 -143
  48. package/src/resources/skills/create-gsd-extension/workflows/add-capability.md +0 -57
  49. package/src/resources/skills/create-gsd-extension/workflows/create-extension.md +0 -156
  50. package/src/resources/skills/create-gsd-extension/workflows/debug-extension.md +0 -74
@@ -91,7 +91,7 @@ Before moving to the wrap-up gate, verify you have covered:
91
91
  - options: "Yes, you got it (Recommended)", "Not quite — let me clarify"
92
92
  - **The question ID must contain `depth_verification`** (e.g. `depth_verification_confirm`) — this enables the write-gate downstream.
93
93
 
94
- **If `{{structuredQuestionsAvailable}}` is `false`:** ask in plain text: "Did I capture that correctly? If not, tell me what I missed." Wait for confirmation before proceeding.
94
+ **If `{{structuredQuestionsAvailable}}` is `false`:** ask in plain text: "Did I capture that correctly? Anything I missed?" Wait for confirmation before proceeding.
95
95
 
96
96
  If they clarify, absorb the correction and re-verify.
97
97
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gsd-pi",
3
- "version": "2.29.0-dev.2ccf3fb",
3
+ "version": "2.29.0-dev.6a38b5d",
4
4
  "description": "GSD — Get Shit Done coding agent",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -55,5 +55,3 @@ export declare const native: {
55
55
  parseStreamingJson: (text: string) => unknown;
56
56
  xxHash32: (input: string, seed: number) => number;
57
57
  };
58
- /** True when the native addon loaded successfully. False on unsupported platforms. */
59
- export declare const nativeAvailable = false;
@@ -22,14 +22,12 @@ const platformPackageMap = {
22
22
  "linux-arm64": "linux-arm64-gnu",
23
23
  "win32-x64": "win32-x64-msvc",
24
24
  };
25
- let _loadedSuccessfully = false;
26
25
  function loadNative() {
27
26
  const errors = [];
28
27
  // 1. Try the platform-specific npm optional dependency
29
28
  const packageSuffix = platformPackageMap[platformTag];
30
29
  if (packageSuffix) {
31
30
  try {
32
- _loadedSuccessfully = true;
33
31
  return require(`@gsd-build/engine-${packageSuffix}`);
34
32
  }
35
33
  catch (err) {
@@ -40,7 +38,6 @@ function loadNative() {
40
38
  // 2. Try local release build (native/addon/gsd_engine.{platform}.node)
41
39
  const releasePath = path.join(addonDir, `gsd_engine.${platformTag}.node`);
42
40
  try {
43
- _loadedSuccessfully = true;
44
41
  return require(releasePath);
45
42
  }
46
43
  catch (err) {
@@ -50,7 +47,6 @@ function loadNative() {
50
47
  // 3. Try local dev build (native/addon/gsd_engine.dev.node)
51
48
  const devPath = path.join(addonDir, "gsd_engine.dev.node");
52
49
  try {
53
- _loadedSuccessfully = true;
54
50
  return require(devPath);
55
51
  }
56
52
  catch (err) {
@@ -59,20 +55,10 @@ function loadNative() {
59
55
  }
60
56
  const details = errors.map((e) => ` - ${e}`).join("\n");
61
57
  const supportedPlatforms = Object.keys(platformPackageMap);
62
- // Graceful fallback: on unsupported platforms (e.g., win32-arm64), return a
63
- // proxy that throws on individual function calls rather than crashing the
64
- // entire import chain at startup (#1223). Consumers with JS fallbacks
65
- // (parseRoadmap, parsePlan, fuzzyFind, etc.) catch these and degrade gracefully.
66
- process.stderr.write(`[gsd] Native addon not available for ${platformTag}. Falling back to JS implementations (slower).\n` +
67
- ` Supported native platforms: ${supportedPlatforms.join(", ")}\n`);
68
- return new Proxy({}, {
69
- get(_target, prop) {
70
- return (..._args) => {
71
- throw new Error(`Native function '${String(prop)}' is not available on ${platformTag}`);
72
- };
73
- },
74
- });
58
+ throw new Error(`Failed to load gsd_engine native addon for ${platformTag}.\n\n` +
59
+ `Tried:\n${details}\n\n` +
60
+ `Supported platforms: ${supportedPlatforms.join(", ")}\n` +
61
+ `If your platform is listed, try reinstalling: npm i -g gsd-pi\n` +
62
+ `Otherwise, please open an issue: https://github.com/gsd-build/gsd-2/issues`);
75
63
  }
76
64
  export const native = loadNative();
77
- /** True when the native addon loaded successfully. False on unsupported platforms. */
78
- export const nativeAvailable = _loadedSuccessfully;
@@ -27,8 +27,6 @@ const platformPackageMap: Record<string, string> = {
27
27
  "win32-x64": "win32-x64-msvc",
28
28
  };
29
29
 
30
- let _loadedSuccessfully = false;
31
-
32
30
  function loadNative(): Record<string, unknown> {
33
31
  const errors: string[] = [];
34
32
 
@@ -36,7 +34,7 @@ function loadNative(): Record<string, unknown> {
36
34
  const packageSuffix = platformPackageMap[platformTag];
37
35
  if (packageSuffix) {
38
36
  try {
39
- _loadedSuccessfully = true; return require(`@gsd-build/engine-${packageSuffix}`) as Record<string, unknown>;
37
+ return require(`@gsd-build/engine-${packageSuffix}`) as Record<string, unknown>;
40
38
  } catch (err) {
41
39
  const message = err instanceof Error ? err.message : String(err);
42
40
  errors.push(`@gsd-build/engine-${packageSuffix}: ${message}`);
@@ -46,7 +44,7 @@ function loadNative(): Record<string, unknown> {
46
44
  // 2. Try local release build (native/addon/gsd_engine.{platform}.node)
47
45
  const releasePath = path.join(addonDir, `gsd_engine.${platformTag}.node`);
48
46
  try {
49
- _loadedSuccessfully = true; return require(releasePath) as Record<string, unknown>;
47
+ return require(releasePath) as Record<string, unknown>;
50
48
  } catch (err) {
51
49
  const message = err instanceof Error ? err.message : String(err);
52
50
  errors.push(`${releasePath}: ${message}`);
@@ -55,7 +53,7 @@ function loadNative(): Record<string, unknown> {
55
53
  // 3. Try local dev build (native/addon/gsd_engine.dev.node)
56
54
  const devPath = path.join(addonDir, "gsd_engine.dev.node");
57
55
  try {
58
- _loadedSuccessfully = true; return require(devPath) as Record<string, unknown>;
56
+ return require(devPath) as Record<string, unknown>;
59
57
  } catch (err) {
60
58
  const message = err instanceof Error ? err.message : String(err);
61
59
  errors.push(`${devPath}: ${message}`);
@@ -63,22 +61,13 @@ function loadNative(): Record<string, unknown> {
63
61
 
64
62
  const details = errors.map((e) => ` - ${e}`).join("\n");
65
63
  const supportedPlatforms = Object.keys(platformPackageMap);
66
-
67
- // Graceful fallback: on unsupported platforms (e.g., win32-arm64), return a
68
- // proxy that throws on individual function calls rather than crashing the
69
- // entire import chain at startup (#1223). Consumers with JS fallbacks
70
- // (parseRoadmap, parsePlan, fuzzyFind, etc.) catch these and degrade gracefully.
71
- process.stderr.write(
72
- `[gsd] Native addon not available for ${platformTag}. Falling back to JS implementations (slower).\n` +
73
- ` Supported native platforms: ${supportedPlatforms.join(", ")}\n`,
64
+ throw new Error(
65
+ `Failed to load gsd_engine native addon for ${platformTag}.\n\n` +
66
+ `Tried:\n${details}\n\n` +
67
+ `Supported platforms: ${supportedPlatforms.join(", ")}\n` +
68
+ `If your platform is listed, try reinstalling: npm i -g gsd-pi\n` +
69
+ `Otherwise, please open an issue: https://github.com/gsd-build/gsd-2/issues`,
74
70
  );
75
- return new Proxy({} as Record<string, unknown>, {
76
- get(_target, prop) {
77
- return (..._args: unknown[]) => {
78
- throw new Error(`Native function '${String(prop)}' is not available on ${platformTag}`);
79
- };
80
- },
81
- });
82
71
  }
83
72
 
84
73
  export const native = loadNative() as {
@@ -151,6 +140,3 @@ export const native = loadNative() as {
151
140
  parseStreamingJson: (text: string) => unknown;
152
141
  xxHash32: (input: string, seed: number) => number;
153
142
  };
154
-
155
- /** True when the native addon loaded successfully. False on unsupported platforms. */
156
- export const nativeAvailable = _loadedSuccessfully;
@@ -91,7 +91,7 @@ Before moving to the wrap-up gate, verify you have covered:
91
91
  - options: "Yes, you got it (Recommended)", "Not quite — let me clarify"
92
92
  - **The question ID must contain `depth_verification`** (e.g. `depth_verification_confirm`) — this enables the write-gate downstream.
93
93
 
94
- **If `{{structuredQuestionsAvailable}}` is `false`:** ask in plain text: "Did I capture that correctly? If not, tell me what I missed." Wait for confirmation before proceeding.
94
+ **If `{{structuredQuestionsAvailable}}` is `false`:** ask in plain text: "Did I capture that correctly? Anything I missed?" Wait for confirmation before proceeding.
95
95
 
96
96
  If they clarify, absorb the correction and re-verify.
97
97
 
@@ -1,87 +0,0 @@
1
- ---
2
- name: create-gsd-extension
3
- description: Create, debug, and iterate on GSD extensions (TypeScript modules that add tools, commands, event hooks, custom UI, and providers to GSD). Use when asked to build an extension, add a tool the LLM can call, register a slash command, hook into GSD events, create custom TUI components, or modify GSD behavior. Triggers on "create extension", "build extension", "add a tool", "register command", "hook into gsd", "custom tool", "gsd plugin", "gsd extension".
4
- ---
5
-
6
- <essential_principles>
7
-
8
- **Extensions are TypeScript modules** that hook into GSD's runtime (built on pi). They export a default function receiving `ExtensionAPI` and use it to subscribe to events, register tools/commands/shortcuts, and interact with the session.
9
-
10
- **GSD extension paths:**
11
- - Global extensions: `~/.gsd/agent/extensions/*.ts` or `~/.gsd/agent/extensions/*/index.ts`
12
- - Project-local extensions: `.gsd/extensions/*.ts` or `.gsd/extensions/*/index.ts`
13
-
14
- **The three primitives:**
15
- 1. **Events** — Listen and react (`pi.on("event", handler)`). Can block tool calls, modify messages, inject context.
16
- 2. **Tools** — Give the LLM new abilities (`pi.registerTool()`). LLM calls them autonomously.
17
- 3. **Commands** — Give users slash commands (`pi.registerCommand()`). Users type `/mycommand`.
18
-
19
- **Non-negotiable rules:**
20
- - Use `StringEnum` from `@mariozechner/pi-ai` for string enum params (NOT `Type.Union`/`Type.Literal` — breaks Google's API)
21
- - Truncate tool output to 50KB / 2000 lines max (use `truncateHead`/`truncateTail` from `@mariozechner/pi-coding-agent`)
22
- - Store stateful tool state in `details` for branching support
23
- - Check `signal?.aborted` in long-running tool executions
24
- - Use `pi.exec()` not `child_process` for shell commands
25
- - Check `ctx.hasUI` before dialog methods (non-interactive modes exist)
26
- - Session control methods (`waitForIdle`, `newSession`, `fork`, `navigateTree`, `reload`) are ONLY available in command handlers — they deadlock in event handlers
27
- - Lines from `render()` must not exceed `width` — use `truncateToWidth()`
28
- - Use theme from callback params, never import directly
29
- - Strip leading `@` from path params in custom tools (some models add it)
30
-
31
- **Available imports:**
32
-
33
- | Package | Purpose |
34
- |---------|---------|
35
- | `@mariozechner/pi-coding-agent` | `ExtensionAPI`, `ExtensionContext`, `Theme`, event types, tool utilities, `DynamicBorder`, `BorderedLoader`, `CustomEditor`, `highlightCode` |
36
- | `@sinclair/typebox` | `Type.Object`, `Type.String`, `Type.Number`, `Type.Optional`, `Type.Boolean`, `Type.Array` |
37
- | `@mariozechner/pi-ai` | `StringEnum` (required for string enums), `Type` re-export |
38
- | `@mariozechner/pi-tui` | `Text`, `Box`, `Container`, `Spacer`, `Markdown`, `SelectList`, `Input`, `matchesKey`, `Key`, `truncateToWidth`, `visibleWidth` |
39
- | Node.js built-ins | `node:fs`, `node:path`, `node:child_process`, etc. |
40
-
41
- </essential_principles>
42
-
43
- <routing>
44
- Based on user intent, route to the appropriate workflow:
45
-
46
- **Building a new extension:**
47
- - "Create an extension", "build a tool", "I want to add a command" → `workflows/create-extension.md`
48
-
49
- **Adding capabilities to an existing extension:**
50
- - "Add a tool to my extension", "add event hook", "add custom rendering" → `workflows/add-capability.md`
51
-
52
- **Debugging an extension:**
53
- - "My extension doesn't work", "tool not showing up", "event not firing" → `workflows/debug-extension.md`
54
-
55
- **If user intent is clear from context, skip the question and go directly to the workflow.**
56
- </routing>
57
-
58
- <reference_index>
59
- All domain knowledge in `references/`:
60
-
61
- **Core architecture:** extension-lifecycle.md, events-reference.md
62
- **API surface:** extensionapi-reference.md, extensioncontext-reference.md
63
- **Capabilities:** custom-tools.md, custom-commands.md, custom-ui.md, custom-rendering.md
64
- **Patterns:** state-management.md, system-prompt-modification.md, compaction-session-control.md
65
- **Infrastructure:** model-provider-management.md, remote-execution-overrides.md, packaging-distribution.md, mode-behavior.md
66
- **Gotchas:** key-rules-gotchas.md
67
- </reference_index>
68
-
69
- <workflows_index>
70
- | Workflow | Purpose |
71
- |----------|---------|
72
- | create-extension.md | Build a new extension from scratch |
73
- | add-capability.md | Add tools, commands, hooks, UI to an existing extension |
74
- | debug-extension.md | Diagnose and fix extension issues |
75
- </workflows_index>
76
-
77
- <success_criteria>
78
- Extension is complete when:
79
- - TypeScript compiles without errors (jiti handles this at runtime)
80
- - Extension loads on GSD startup or `/reload` without errors
81
- - Tools appear in the LLM's system prompt and are callable
82
- - Commands respond to `/command` input
83
- - Event hooks fire at the expected lifecycle points
84
- - Custom UI renders correctly within terminal width
85
- - State persists correctly across session restarts (if stateful)
86
- - Output is truncated to safe limits (if tools produce variable output)
87
- </success_criteria>
@@ -1,77 +0,0 @@
1
- <overview>
2
- Custom compaction hooks, triggering compaction, and session control methods available only in command handlers.
3
- </overview>
4
-
5
- <custom_compaction>
6
- Override default compaction behavior:
7
-
8
- ```typescript
9
- pi.on("session_before_compact", async (event, ctx) => {
10
- const { preparation, branchEntries, customInstructions, signal } = event;
11
-
12
- // Option 1: Cancel
13
- return { cancel: true };
14
-
15
- // Option 2: Custom summary
16
- return {
17
- compaction: {
18
- summary: "Custom summary of conversation so far...",
19
- firstKeptEntryId: preparation.firstKeptEntryId,
20
- tokensBefore: preparation.tokensBefore,
21
- }
22
- };
23
- });
24
- ```
25
- </custom_compaction>
26
-
27
- <trigger_compaction>
28
- Trigger compaction programmatically from any handler:
29
-
30
- ```typescript
31
- ctx.compact({
32
- customInstructions: "Focus on the authentication changes",
33
- onComplete: (result) => ctx.ui.notify("Compacted!", "info"),
34
- onError: (error) => ctx.ui.notify(`Failed: ${error.message}`, "error"),
35
- });
36
- ```
37
- </trigger_compaction>
38
-
39
- <session_control>
40
- **Only available in command handlers** (deadlocks in event handlers):
41
-
42
- ```typescript
43
- pi.registerCommand("handoff", {
44
- handler: async (args, ctx) => {
45
- await ctx.waitForIdle();
46
-
47
- // Create new session with initial context
48
- const result = await ctx.newSession({
49
- parentSession: ctx.sessionManager.getSessionFile(),
50
- setup: async (sm) => {
51
- sm.appendMessage({
52
- role: "user",
53
- content: [{ type: "text", text: `Context: ${args}` }],
54
- timestamp: Date.now(),
55
- });
56
- },
57
- });
58
-
59
- if (result.cancelled) { /* extension cancelled via session_before_switch */ }
60
- },
61
- });
62
- ```
63
-
64
- | Method | Purpose |
65
- |--------|---------|
66
- | `ctx.waitForIdle()` | Wait for agent to finish streaming |
67
- | `ctx.newSession(options?)` | Create a new session |
68
- | `ctx.fork(entryId)` | Fork from a specific entry |
69
- | `ctx.navigateTree(targetId, options?)` | Navigate session tree (with optional summary) |
70
- | `ctx.reload()` | Hot-reload everything (treat as terminal — code after runs pre-reload version) |
71
-
72
- `navigateTree` options:
73
- - `summarize: boolean` — generate summary of abandoned branch
74
- - `customInstructions: string` — instructions for summarizer
75
- - `replaceInstructions: boolean` — replace default prompt entirely
76
- - `label: string` — label to attach to branch summary
77
- </session_control>
@@ -1,139 +0,0 @@
1
- <overview>
2
- Custom slash commands — registration, argument completions, subcommand patterns, and the extended command context.
3
- </overview>
4
-
5
- <basic_registration>
6
- ```typescript
7
- pi.registerCommand("deploy", {
8
- description: "Deploy to an environment",
9
- handler: async (args, ctx) => {
10
- // args = everything after "/deploy "
11
- // ctx = ExtensionCommandContext (has session control methods)
12
- ctx.ui.notify(`Deploying to ${args || "production"}`, "info");
13
- },
14
- });
15
- ```
16
- </basic_registration>
17
-
18
- <argument_completions>
19
- Add tab-completion for command arguments:
20
-
21
- ```typescript
22
- import type { AutocompleteItem } from "@mariozechner/pi-tui";
23
-
24
- pi.registerCommand("deploy", {
25
- description: "Deploy to an environment",
26
- getArgumentCompletions: (prefix: string): AutocompleteItem[] | null => {
27
- const envs = ["dev", "staging", "prod"];
28
- const items = envs.map(e => ({ value: e, label: e }));
29
- const filtered = items.filter(i => i.value.startsWith(prefix));
30
- return filtered.length > 0 ? filtered : null;
31
- },
32
- handler: async (args, ctx) => {
33
- ctx.ui.notify(`Deploying to ${args}`, "info");
34
- },
35
- });
36
- ```
37
- </argument_completions>
38
-
39
- <subcommand_pattern>
40
- Fake nested commands via first-argument parsing. Used by `/wt new|ls|switch|merge|rm`.
41
-
42
- ```typescript
43
- pi.registerCommand("foo", {
44
- description: "Manage foo items: /foo new|list|delete [name]",
45
-
46
- getArgumentCompletions: (prefix: string) => {
47
- const parts = prefix.trim().split(/\s+/);
48
-
49
- // First arg: subcommand
50
- if (parts.length <= 1) {
51
- return ["new", "list", "delete"]
52
- .filter(cmd => cmd.startsWith(parts[0] ?? ""))
53
- .map(cmd => ({ value: cmd, label: cmd }));
54
- }
55
-
56
- // Second arg: depends on subcommand
57
- if (parts[0] === "delete") {
58
- const items = getItemsSomehow();
59
- return items
60
- .filter(name => name.startsWith(parts[1] ?? ""))
61
- .map(name => ({ value: `delete ${name}`, label: name }));
62
- }
63
-
64
- return [];
65
- },
66
-
67
- handler: async (args, ctx) => {
68
- const parts = args.trim().split(/\s+/);
69
- const sub = parts[0];
70
-
71
- switch (sub) {
72
- case "new": /* ... */ return;
73
- case "list": /* ... */ return;
74
- case "delete": /* handle parts[1] */ return;
75
- default:
76
- ctx.ui.notify("Usage: /foo <new|list|delete> [name]", "info");
77
- }
78
- },
79
- });
80
- ```
81
-
82
- **Gotcha:** `"".trim().split(/\s+/)` produces `['']`, not `[]`. That's why `parts.length <= 1` handles both empty and partial first arg.
83
- </subcommand_pattern>
84
-
85
- <command_context>
86
- Command handlers get `ExtensionCommandContext` which extends `ExtensionContext` with session control methods:
87
-
88
- | Method | Purpose |
89
- |--------|---------|
90
- | `ctx.waitForIdle()` | Wait for agent to finish streaming |
91
- | `ctx.newSession(options?)` | Create a new session |
92
- | `ctx.fork(entryId)` | Fork from an entry |
93
- | `ctx.navigateTree(targetId, options?)` | Navigate session tree |
94
- | `ctx.reload()` | Hot-reload everything |
95
-
96
- **⚠️ These methods are ONLY available in command handlers.** Calling them from event handlers causes deadlocks.
97
-
98
- ```typescript
99
- pi.registerCommand("handoff", {
100
- handler: async (args, ctx) => {
101
- await ctx.waitForIdle();
102
- await ctx.newSession({
103
- setup: async (sm) => {
104
- sm.appendMessage({
105
- role: "user",
106
- content: [{ type: "text", text: `Context: ${args}` }],
107
- timestamp: Date.now(),
108
- });
109
- },
110
- });
111
- },
112
- });
113
- ```
114
- </command_context>
115
-
116
- <reload_pattern>
117
- Expose reload as both a command and a tool the LLM can call:
118
-
119
- ```typescript
120
- pi.registerCommand("reload-runtime", {
121
- description: "Reload extensions, skills, prompts, and themes",
122
- handler: async (_args, ctx) => {
123
- await ctx.reload();
124
- return; // Treat reload as terminal
125
- },
126
- });
127
-
128
- pi.registerTool({
129
- name: "reload_runtime",
130
- label: "Reload Runtime",
131
- description: "Reload extensions, skills, prompts, and themes",
132
- parameters: Type.Object({}),
133
- async execute() {
134
- pi.sendUserMessage("/reload-runtime", { deliverAs: "followUp" });
135
- return { content: [{ type: "text", text: "Queued /reload-runtime as follow-up." }] };
136
- },
137
- });
138
- ```
139
- </reload_pattern>
@@ -1,108 +0,0 @@
1
- <overview>
2
- Custom rendering for tools and messages — control how they appear in the TUI.
3
- </overview>
4
-
5
- <tool_rendering>
6
- Tools can provide `renderCall` (how the call looks) and `renderResult` (how the result looks):
7
-
8
- ```typescript
9
- import { Text } from "@mariozechner/pi-tui";
10
- import { keyHint } from "@mariozechner/pi-coding-agent";
11
-
12
- pi.registerTool({
13
- name: "my_tool",
14
- // ...
15
-
16
- renderCall(args, theme) {
17
- let text = theme.fg("toolTitle", theme.bold("my_tool "));
18
- text += theme.fg("muted", args.action);
19
- if (args.text) text += " " + theme.fg("dim", `"${args.text}"`);
20
- return new Text(text, 0, 0); // 0,0 padding — Box handles it
21
- },
22
-
23
- renderResult(result, { expanded, isPartial }, theme) {
24
- // isPartial = true during streaming (onUpdate was called)
25
- if (isPartial) {
26
- return new Text(theme.fg("warning", "Processing..."), 0, 0);
27
- }
28
-
29
- // expanded = user toggled expand (Ctrl+O)
30
- if (result.details?.error) {
31
- return new Text(theme.fg("error", `Error: ${result.details.error}`), 0, 0);
32
- }
33
-
34
- let text = theme.fg("success", "✓ Done");
35
- if (!expanded) {
36
- text += ` (${keyHint("expandTools", "to expand")})`;
37
- }
38
- if (expanded && result.details?.items) {
39
- for (const item of result.details.items) {
40
- text += "\n " + theme.fg("dim", item);
41
- }
42
- }
43
- return new Text(text, 0, 0);
44
- },
45
- });
46
- ```
47
-
48
- If you omit `renderCall`/`renderResult`, the built-in renderer is used. Useful for tool overrides where you just wrap logic without reimplementing UI.
49
-
50
- **Fallback:** If render methods throw, `renderCall` shows tool name, `renderResult` shows raw `content` text.
51
- </tool_rendering>
52
-
53
- <key_hints>
54
- Key hint helpers for showing keybinding info in render output:
55
-
56
- ```typescript
57
- import { keyHint, appKeyHint, editorKey, rawKeyHint } from "@mariozechner/pi-coding-agent";
58
-
59
- // Editor action hint (respects user keybinding config)
60
- keyHint("expandTools", "to expand") // e.g., "Ctrl+O to expand"
61
- keyHint("selectConfirm", "to select")
62
-
63
- // Raw key hint (always shows literal key)
64
- rawKeyHint("Ctrl+O", "to expand")
65
- ```
66
- </key_hints>
67
-
68
- <message_rendering>
69
- Register a renderer for custom message types:
70
-
71
- ```typescript
72
- import { Text } from "@mariozechner/pi-tui";
73
-
74
- pi.registerMessageRenderer("my-extension", (message, options, theme) => {
75
- const { expanded } = options;
76
- let text = theme.fg("accent", `[${message.customType}] `) + message.content;
77
- if (expanded && message.details) {
78
- text += "\n" + theme.fg("dim", JSON.stringify(message.details, null, 2));
79
- }
80
- return new Text(text, 0, 0);
81
- });
82
-
83
- // Send messages that use this renderer:
84
- pi.sendMessage({
85
- customType: "my-extension", // Matches renderer name
86
- content: "Status update",
87
- display: true,
88
- details: { foo: "bar" },
89
- });
90
- ```
91
- </message_rendering>
92
-
93
- <syntax_highlighting>
94
- ```typescript
95
- import { highlightCode, getLanguageFromPath } from "@mariozechner/pi-coding-agent";
96
-
97
- const lang = getLanguageFromPath("/path/to/file.rs"); // "rust"
98
- const highlighted = highlightCode(code, lang, theme);
99
- ```
100
- </syntax_highlighting>
101
-
102
- <best_practices>
103
- - Return `Text` with padding `(0, 0)` — the wrapping `Box` handles padding
104
- - Support `expanded` for detail on demand
105
- - Handle `isPartial` for streaming progress
106
- - Keep collapsed view compact
107
- - Use `\n` for multi-line content within a single `Text`
108
- </best_practices>