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
@@ -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>
@@ -1,183 +0,0 @@
1
- <overview>
2
- Complete custom tools reference — registration, parameters, execution, output truncation, overrides, rendering, and dynamic registration.
3
- </overview>
4
-
5
- <registration>
6
- ```typescript
7
- import { Type } from "@sinclair/typebox";
8
- import { StringEnum } from "@mariozechner/pi-ai";
9
-
10
- pi.registerTool({
11
- name: "my_tool", // Unique identifier (snake_case)
12
- label: "My Tool", // Display name in TUI
13
- description: "What this does", // Full description shown to LLM
14
-
15
- // Optional: one-liner for system prompt "Available tools" section
16
- promptSnippet: "Manage project todo items",
17
-
18
- // Optional: bullets added to system prompt "Guidelines" when tool is active
19
- promptGuidelines: [
20
- "Use my_tool for task management instead of file edits."
21
- ],
22
-
23
- // Parameter schema (MUST use TypeBox)
24
- parameters: Type.Object({
25
- action: StringEnum(["list", "add", "remove"] as const),
26
- text: Type.Optional(Type.String({ description: "Item text" })),
27
- id: Type.Optional(Type.Number({ description: "Item ID" })),
28
- }),
29
-
30
- async execute(toolCallId, params, signal, onUpdate, ctx) {
31
- // 1. Check cancellation
32
- if (signal?.aborted) {
33
- return { content: [{ type: "text", text: "Cancelled" }] };
34
- }
35
-
36
- // 2. Stream progress (optional)
37
- onUpdate?.({
38
- content: [{ type: "text", text: "Working..." }],
39
- details: { progress: 50 },
40
- });
41
-
42
- // 3. Do the work
43
- const result = await doWork(params);
44
-
45
- // 4. Return result
46
- return {
47
- content: [{ type: "text", text: "Result text for LLM" }], // Sent to LLM context
48
- details: { data: result }, // For rendering & state
49
- };
50
- },
51
-
52
- // Optional: custom TUI rendering
53
- renderCall(args, theme) { ... },
54
- renderResult(result, { expanded, isPartial }, theme) { ... },
55
- });
56
- ```
57
- </registration>
58
-
59
- <critical_stringenum>
60
- **⚠️ MUST use `StringEnum` for string enum parameters:**
61
-
62
- ```typescript
63
- import { StringEnum } from "@mariozechner/pi-ai";
64
-
65
- // ✅ Correct — works with all providers including Google
66
- action: StringEnum(["list", "add", "remove"] as const)
67
-
68
- // ❌ BROKEN with Google's API
69
- action: Type.Union([Type.Literal("list"), Type.Literal("add")])
70
- ```
71
- </critical_stringenum>
72
-
73
- <output_truncation>
74
- Tools MUST truncate output to avoid context overflow. Built-in limit: 50KB / 2000 lines.
75
-
76
- ```typescript
77
- import {
78
- truncateHead, truncateTail, formatSize,
79
- DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES,
80
- } from "@mariozechner/pi-coding-agent";
81
-
82
- async execute(toolCallId, params, signal, onUpdate, ctx) {
83
- const output = await runCommand();
84
- const truncation = truncateHead(output, {
85
- maxLines: DEFAULT_MAX_LINES,
86
- maxBytes: DEFAULT_MAX_BYTES,
87
- });
88
-
89
- let result = truncation.content;
90
- if (truncation.truncated) {
91
- const tempFile = writeTempFile(output);
92
- result += `\n\n[Output truncated: ${truncation.outputLines}/${truncation.totalLines} lines`;
93
- result += ` (${formatSize(truncation.outputBytes)}/${formatSize(truncation.totalBytes)}).`;
94
- result += ` Full output: ${tempFile}]`;
95
- }
96
- return { content: [{ type: "text", text: result }] };
97
- }
98
- ```
99
-
100
- Use `truncateHead` when beginning matters (search results, file reads). Use `truncateTail` when end matters (logs, command output).
101
- </output_truncation>
102
-
103
- <signaling_errors>
104
- Throw to signal an error (sets `isError: true`). Returning a value never sets error flag.
105
-
106
- ```typescript
107
- async execute(toolCallId, params) {
108
- if (!isValid(params.input)) {
109
- throw new Error(`Invalid input: ${params.input}`);
110
- }
111
- return { content: [{ type: "text", text: "OK" }], details: {} };
112
- }
113
- ```
114
- </signaling_errors>
115
-
116
- <dynamic_registration>
117
- Tools can be registered at any time — during load, in `session_start`, in command handlers. Available immediately without `/reload`.
118
-
119
- ```typescript
120
- pi.on("session_start", async (_event, ctx) => {
121
- pi.registerTool({ name: "dynamic_tool", ... });
122
- });
123
- ```
124
-
125
- Use `pi.setActiveTools(names)` to enable/disable tools at runtime.
126
- </dynamic_registration>
127
-
128
- <overriding_builtins>
129
- Register a tool with the same name as a built-in (`read`, `bash`, `edit`, `write`, `grep`, `find`, `ls`) to override it. **Must match exact result shape including `details` type.**
130
-
131
- ```typescript
132
- import { createReadTool } from "@mariozechner/pi-coding-agent";
133
-
134
- pi.registerTool({
135
- name: "read",
136
- label: "Read (Logged)",
137
- description: "Read file contents with logging",
138
- parameters: Type.Object({
139
- path: Type.String(),
140
- offset: Type.Optional(Type.Number()),
141
- limit: Type.Optional(Type.Number()),
142
- }),
143
- async execute(toolCallId, params, signal, onUpdate, ctx) {
144
- console.log(`[AUDIT] Reading: ${params.path}`);
145
- const builtIn = createReadTool(ctx.cwd);
146
- return builtIn.execute(toolCallId, params, signal, onUpdate);
147
- },
148
- // Omit renderCall/renderResult to use built-in renderer
149
- });
150
- ```
151
-
152
- Start with no built-in tools: `gsd --no-tools -e ./my-extension.ts`
153
- </overriding_builtins>
154
-
155
- <multiple_tools>
156
- One extension can register multiple tools with shared state:
157
-
158
- ```typescript
159
- export default function (pi: ExtensionAPI) {
160
- let connection = null;
161
-
162
- pi.registerTool({ name: "db_connect", ... });
163
- pi.registerTool({ name: "db_query", ... });
164
- pi.registerTool({ name: "db_close", ... });
165
-
166
- pi.on("session_shutdown", async () => {
167
- connection?.close();
168
- });
169
- }
170
- ```
171
- </multiple_tools>
172
-
173
- <path_normalization>
174
- Some models add `@` prefix to path arguments. Strip it:
175
-
176
- ```typescript
177
- async execute(toolCallId, params, signal, onUpdate, ctx) {
178
- let path = params.path;
179
- if (path.startsWith("@")) path = path.slice(1);
180
- // ...
181
- }
182
- ```
183
- </path_normalization>