@mariozechner/pi-coding-agent 0.34.2 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/CHANGELOG.md +210 -0
  2. package/README.md +246 -107
  3. package/dist/cli/args.d.ts +3 -4
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +13 -18
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/config.d.ts +2 -2
  8. package/dist/config.d.ts.map +1 -1
  9. package/dist/config.js +3 -3
  10. package/dist/config.js.map +1 -1
  11. package/dist/core/agent-session.d.ts +39 -50
  12. package/dist/core/agent-session.d.ts.map +1 -1
  13. package/dist/core/agent-session.js +166 -197
  14. package/dist/core/agent-session.js.map +1 -1
  15. package/dist/core/auth-storage.d.ts.map +1 -1
  16. package/dist/core/auth-storage.js +4 -1
  17. package/dist/core/auth-storage.js.map +1 -1
  18. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  19. package/dist/core/compaction/branch-summarization.js +3 -3
  20. package/dist/core/compaction/branch-summarization.js.map +1 -1
  21. package/dist/core/compaction/compaction.d.ts +1 -1
  22. package/dist/core/compaction/compaction.d.ts.map +1 -1
  23. package/dist/core/compaction/compaction.js +6 -5
  24. package/dist/core/compaction/compaction.js.map +1 -1
  25. package/dist/core/event-bus.d.ts +9 -0
  26. package/dist/core/event-bus.d.ts.map +1 -0
  27. package/dist/core/event-bus.js +25 -0
  28. package/dist/core/event-bus.js.map +1 -0
  29. package/dist/core/exec.d.ts +1 -1
  30. package/dist/core/exec.d.ts.map +1 -1
  31. package/dist/core/exec.js +1 -1
  32. package/dist/core/exec.js.map +1 -1
  33. package/dist/core/extensions/index.d.ts +10 -0
  34. package/dist/core/extensions/index.d.ts.map +1 -0
  35. package/dist/core/extensions/index.js +9 -0
  36. package/dist/core/extensions/index.js.map +1 -0
  37. package/dist/core/extensions/loader.d.ts +21 -0
  38. package/dist/core/extensions/loader.d.ts.map +1 -0
  39. package/dist/core/extensions/loader.js +400 -0
  40. package/dist/core/extensions/loader.js.map +1 -0
  41. package/dist/core/extensions/runner.d.ts +88 -0
  42. package/dist/core/extensions/runner.d.ts.map +1 -0
  43. package/dist/core/{hooks → extensions}/runner.js +52 -141
  44. package/dist/core/extensions/runner.js.map +1 -0
  45. package/dist/core/extensions/types.d.ts +461 -0
  46. package/dist/core/extensions/types.d.ts.map +1 -0
  47. package/dist/core/{hooks → extensions}/types.js +7 -4
  48. package/dist/core/extensions/types.js.map +1 -0
  49. package/dist/core/extensions/wrapper.d.ts +25 -0
  50. package/dist/core/extensions/wrapper.d.ts.map +1 -0
  51. package/dist/core/{hooks/tool-wrapper.js → extensions/wrapper.js} +39 -24
  52. package/dist/core/extensions/wrapper.js.map +1 -0
  53. package/dist/core/index.d.ts +2 -2
  54. package/dist/core/index.d.ts.map +1 -1
  55. package/dist/core/index.js +3 -2
  56. package/dist/core/index.js.map +1 -1
  57. package/dist/core/messages.d.ts +7 -7
  58. package/dist/core/messages.d.ts.map +1 -1
  59. package/dist/core/messages.js +4 -4
  60. package/dist/core/messages.js.map +1 -1
  61. package/dist/core/model-registry.d.ts.map +1 -1
  62. package/dist/core/model-registry.js +2 -0
  63. package/dist/core/model-registry.js.map +1 -1
  64. package/dist/core/model-resolver.d.ts.map +1 -1
  65. package/dist/core/model-resolver.js +1 -0
  66. package/dist/core/model-resolver.js.map +1 -1
  67. package/dist/core/prompt-templates.d.ts +40 -0
  68. package/dist/core/prompt-templates.d.ts.map +1 -0
  69. package/dist/core/{slash-commands.js → prompt-templates.js} +31 -31
  70. package/dist/core/prompt-templates.js.map +1 -0
  71. package/dist/core/sdk.d.ts +29 -52
  72. package/dist/core/sdk.d.ts.map +1 -1
  73. package/dist/core/sdk.js +111 -211
  74. package/dist/core/sdk.js.map +1 -1
  75. package/dist/core/session-manager.d.ts +17 -17
  76. package/dist/core/session-manager.d.ts.map +1 -1
  77. package/dist/core/session-manager.js +25 -10
  78. package/dist/core/session-manager.js.map +1 -1
  79. package/dist/core/settings-manager.d.ts +3 -6
  80. package/dist/core/settings-manager.d.ts.map +1 -1
  81. package/dist/core/settings-manager.js +4 -11
  82. package/dist/core/settings-manager.js.map +1 -1
  83. package/dist/core/system-prompt.d.ts.map +1 -1
  84. package/dist/core/system-prompt.js +4 -2
  85. package/dist/core/system-prompt.js.map +1 -1
  86. package/dist/index.d.ts +4 -5
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +5 -6
  89. package/dist/index.js.map +1 -1
  90. package/dist/main.d.ts.map +1 -1
  91. package/dist/main.js +36 -33
  92. package/dist/main.js.map +1 -1
  93. package/dist/migrations.d.ts +7 -2
  94. package/dist/migrations.d.ts.map +1 -1
  95. package/dist/migrations.js +93 -4
  96. package/dist/migrations.js.map +1 -1
  97. package/dist/modes/interactive/components/bordered-loader.d.ts +1 -1
  98. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  99. package/dist/modes/interactive/components/bordered-loader.js +1 -1
  100. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  101. package/dist/modes/interactive/components/branch-summary-message.d.ts +1 -1
  102. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  103. package/dist/modes/interactive/components/branch-summary-message.js +1 -1
  104. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  105. package/dist/modes/interactive/components/compaction-summary-message.d.ts +1 -1
  106. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  107. package/dist/modes/interactive/components/compaction-summary-message.js +1 -1
  108. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  109. package/dist/modes/interactive/components/custom-editor.d.ts +2 -2
  110. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  111. package/dist/modes/interactive/components/custom-editor.js +4 -4
  112. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  113. package/dist/modes/interactive/components/custom-message.d.ts +18 -0
  114. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
  115. package/dist/modes/interactive/components/{hook-message.js → custom-message.js} +3 -3
  116. package/dist/modes/interactive/components/custom-message.js.map +1 -0
  117. package/dist/modes/interactive/components/dynamic-border.d.ts +2 -2
  118. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  119. package/dist/modes/interactive/components/dynamic-border.js +2 -2
  120. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  121. package/dist/modes/interactive/components/{hook-editor.d.ts → extension-editor.d.ts} +3 -3
  122. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
  123. package/dist/modes/interactive/components/{hook-editor.js → extension-editor.js} +4 -4
  124. package/dist/modes/interactive/components/extension-editor.js.map +1 -0
  125. package/dist/modes/interactive/components/{hook-input.d.ts → extension-input.d.ts} +3 -3
  126. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
  127. package/dist/modes/interactive/components/{hook-input.js → extension-input.js} +3 -3
  128. package/dist/modes/interactive/components/extension-input.js.map +1 -0
  129. package/dist/modes/interactive/components/{hook-selector.d.ts → extension-selector.d.ts} +3 -3
  130. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
  131. package/dist/modes/interactive/components/{hook-selector.js → extension-selector.js} +3 -3
  132. package/dist/modes/interactive/components/extension-selector.js.map +1 -0
  133. package/dist/modes/interactive/components/footer.d.ts +3 -3
  134. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  135. package/dist/modes/interactive/components/footer.js +8 -8
  136. package/dist/modes/interactive/components/footer.js.map +1 -1
  137. package/dist/modes/interactive/components/tool-execution.d.ts +3 -3
  138. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  139. package/dist/modes/interactive/components/tool-execution.js +9 -9
  140. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  141. package/dist/modes/interactive/interactive-mode.d.ts +37 -44
  142. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  143. package/dist/modes/interactive/interactive-mode.js +143 -189
  144. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  145. package/dist/modes/print-mode.d.ts.map +1 -1
  146. package/dist/modes/print-mode.js +10 -33
  147. package/dist/modes/print-mode.js.map +1 -1
  148. package/dist/modes/rpc/rpc-client.d.ts +3 -3
  149. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  150. package/dist/modes/rpc/rpc-client.js +3 -3
  151. package/dist/modes/rpc/rpc-client.js.map +1 -1
  152. package/dist/modes/rpc/rpc-mode.d.ts +2 -2
  153. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  154. package/dist/modes/rpc/rpc-mode.js +33 -57
  155. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  156. package/dist/modes/rpc/rpc-types.d.ts +16 -16
  157. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  158. package/dist/modes/rpc/rpc-types.js.map +1 -1
  159. package/docs/extensions.md +1053 -0
  160. package/docs/rpc.md +4 -4
  161. package/docs/sdk.md +62 -93
  162. package/docs/session.md +22 -19
  163. package/docs/skills.md +1 -1
  164. package/docs/tui.md +1 -1
  165. package/examples/README.md +9 -15
  166. package/examples/extensions/README.md +141 -0
  167. package/examples/{hooks → extensions}/auto-commit-on-exit.ts +3 -3
  168. package/examples/extensions/chalk-logger.ts +26 -0
  169. package/examples/{hooks → extensions}/confirm-destructive.ts +3 -3
  170. package/examples/{hooks → extensions}/custom-compaction.ts +6 -6
  171. package/examples/{hooks → extensions}/dirty-repo-guard.ts +8 -4
  172. package/examples/{hooks → extensions}/file-trigger.ts +3 -3
  173. package/examples/{hooks → extensions}/git-checkpoint.ts +3 -3
  174. package/examples/{hooks → extensions}/handoff.ts +3 -3
  175. package/examples/extensions/hello.ts +25 -0
  176. package/examples/{hooks → extensions}/permission-gate.ts +3 -3
  177. package/examples/{hooks → extensions}/pirate.ts +5 -5
  178. package/examples/{hooks → extensions}/plan-mode.ts +6 -6
  179. package/examples/{hooks → extensions}/protected-paths.ts +3 -3
  180. package/examples/{hooks → extensions}/qna.ts +3 -3
  181. package/examples/{custom-tools/question/index.ts → extensions/question.ts} +13 -17
  182. package/examples/{hooks → extensions}/snake.ts +3 -3
  183. package/examples/{hooks → extensions}/status-line.ts +3 -3
  184. package/examples/{custom-tools → extensions}/subagent/README.md +15 -15
  185. package/examples/{custom-tools → extensions}/subagent/index.ts +22 -43
  186. package/examples/{custom-tools/todo/index.ts → extensions/todo.ts} +122 -39
  187. package/examples/{hooks → extensions}/tools.ts +5 -5
  188. package/examples/extensions/with-deps/index.ts +36 -0
  189. package/examples/extensions/with-deps/package-lock.json +31 -0
  190. package/examples/extensions/with-deps/package.json +16 -0
  191. package/examples/sdk/01-minimal.ts +1 -1
  192. package/examples/sdk/05-tools.ts +7 -41
  193. package/examples/sdk/06-extensions.ts +81 -0
  194. package/examples/sdk/08-prompt-templates.ts +42 -0
  195. package/examples/sdk/12-full-control.ts +10 -29
  196. package/examples/sdk/README.md +5 -5
  197. package/package.json +4 -4
  198. package/dist/core/custom-tools/index.d.ts +0 -7
  199. package/dist/core/custom-tools/index.d.ts.map +0 -1
  200. package/dist/core/custom-tools/index.js +0 -6
  201. package/dist/core/custom-tools/index.js.map +0 -1
  202. package/dist/core/custom-tools/loader.d.ts +0 -30
  203. package/dist/core/custom-tools/loader.d.ts.map +0 -1
  204. package/dist/core/custom-tools/loader.js +0 -276
  205. package/dist/core/custom-tools/loader.js.map +0 -1
  206. package/dist/core/custom-tools/types.d.ts +0 -144
  207. package/dist/core/custom-tools/types.d.ts.map +0 -1
  208. package/dist/core/custom-tools/types.js +0 -8
  209. package/dist/core/custom-tools/types.js.map +0 -1
  210. package/dist/core/custom-tools/wrapper.d.ts +0 -15
  211. package/dist/core/custom-tools/wrapper.d.ts.map +0 -1
  212. package/dist/core/custom-tools/wrapper.js +0 -23
  213. package/dist/core/custom-tools/wrapper.js.map +0 -1
  214. package/dist/core/hooks/index.d.ts +0 -6
  215. package/dist/core/hooks/index.d.ts.map +0 -1
  216. package/dist/core/hooks/index.js +0 -6
  217. package/dist/core/hooks/index.js.map +0 -1
  218. package/dist/core/hooks/loader.d.ts +0 -146
  219. package/dist/core/hooks/loader.d.ts.map +0 -1
  220. package/dist/core/hooks/loader.js +0 -275
  221. package/dist/core/hooks/loader.js.map +0 -1
  222. package/dist/core/hooks/runner.d.ts +0 -173
  223. package/dist/core/hooks/runner.d.ts.map +0 -1
  224. package/dist/core/hooks/runner.js.map +0 -1
  225. package/dist/core/hooks/tool-wrapper.d.ts +0 -17
  226. package/dist/core/hooks/tool-wrapper.d.ts.map +0 -1
  227. package/dist/core/hooks/tool-wrapper.js.map +0 -1
  228. package/dist/core/hooks/types.d.ts +0 -767
  229. package/dist/core/hooks/types.d.ts.map +0 -1
  230. package/dist/core/hooks/types.js.map +0 -1
  231. package/dist/core/slash-commands.d.ts +0 -40
  232. package/dist/core/slash-commands.d.ts.map +0 -1
  233. package/dist/core/slash-commands.js.map +0 -1
  234. package/dist/modes/interactive/components/hook-editor.d.ts.map +0 -1
  235. package/dist/modes/interactive/components/hook-editor.js.map +0 -1
  236. package/dist/modes/interactive/components/hook-input.d.ts.map +0 -1
  237. package/dist/modes/interactive/components/hook-input.js.map +0 -1
  238. package/dist/modes/interactive/components/hook-message.d.ts +0 -18
  239. package/dist/modes/interactive/components/hook-message.d.ts.map +0 -1
  240. package/dist/modes/interactive/components/hook-message.js.map +0 -1
  241. package/dist/modes/interactive/components/hook-selector.d.ts.map +0 -1
  242. package/dist/modes/interactive/components/hook-selector.js.map +0 -1
  243. package/docs/custom-tools.md +0 -514
  244. package/docs/extension-loading.md +0 -1004
  245. package/docs/hooks.md +0 -979
  246. package/docs/session-tree-plan.md +0 -441
  247. package/examples/custom-tools/README.md +0 -114
  248. package/examples/custom-tools/hello/index.ts +0 -21
  249. package/examples/hooks/README.md +0 -60
  250. package/examples/hooks/todo/index.ts +0 -134
  251. package/examples/sdk/06-hooks.ts +0 -61
  252. package/examples/sdk/08-slash-commands.ts +0 -42
  253. /package/examples/{custom-tools → extensions}/subagent/agents/planner.md +0 -0
  254. /package/examples/{custom-tools → extensions}/subagent/agents/reviewer.md +0 -0
  255. /package/examples/{custom-tools → extensions}/subagent/agents/scout.md +0 -0
  256. /package/examples/{custom-tools → extensions}/subagent/agents/worker.md +0 -0
  257. /package/examples/{custom-tools → extensions}/subagent/agents.ts +0 -0
  258. /package/examples/{custom-tools/subagent/commands → extensions/subagent/prompts}/implement-and-review.md +0 -0
  259. /package/examples/{custom-tools/subagent/commands → extensions/subagent/prompts}/implement.md +0 -0
  260. /package/examples/{custom-tools/subagent/commands → extensions/subagent/prompts}/scout-and-plan.md +0 -0
@@ -1,134 +0,0 @@
1
- /**
2
- * Todo Hook - Companion to the todo custom tool
3
- *
4
- * Registers a /todos command that displays all todos on the current branch
5
- * with a nice custom UI.
6
- */
7
-
8
- import type { HookAPI, Theme } from "@mariozechner/pi-coding-agent";
9
- import { matchesKey, truncateToWidth } from "@mariozechner/pi-tui";
10
-
11
- interface Todo {
12
- id: number;
13
- text: string;
14
- done: boolean;
15
- }
16
-
17
- interface TodoDetails {
18
- action: "list" | "add" | "toggle" | "clear";
19
- todos: Todo[];
20
- nextId: number;
21
- error?: string;
22
- }
23
-
24
- class TodoListComponent {
25
- private todos: Todo[];
26
- private theme: Theme;
27
- private onClose: () => void;
28
- private cachedWidth?: number;
29
- private cachedLines?: string[];
30
-
31
- constructor(todos: Todo[], theme: Theme, onClose: () => void) {
32
- this.todos = todos;
33
- this.theme = theme;
34
- this.onClose = onClose;
35
- }
36
-
37
- handleInput(data: string): void {
38
- if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
39
- this.onClose();
40
- }
41
- }
42
-
43
- render(width: number): string[] {
44
- if (this.cachedLines && this.cachedWidth === width) {
45
- return this.cachedLines;
46
- }
47
-
48
- const lines: string[] = [];
49
- const th = this.theme;
50
-
51
- // Header
52
- lines.push("");
53
- const title = th.fg("accent", " Todos ");
54
- const headerLine =
55
- th.fg("borderMuted", "─".repeat(3)) + title + th.fg("borderMuted", "─".repeat(Math.max(0, width - 10)));
56
- lines.push(truncateToWidth(headerLine, width));
57
- lines.push("");
58
-
59
- if (this.todos.length === 0) {
60
- lines.push(truncateToWidth(` ${th.fg("dim", "No todos yet. Ask the agent to add some!")}`, width));
61
- } else {
62
- // Stats
63
- const done = this.todos.filter((t) => t.done).length;
64
- const total = this.todos.length;
65
- const statsText = ` ${th.fg("muted", `${done}/${total} completed`)}`;
66
- lines.push(truncateToWidth(statsText, width));
67
- lines.push("");
68
-
69
- // Todo items
70
- for (const todo of this.todos) {
71
- const check = todo.done ? th.fg("success", "✓") : th.fg("dim", "○");
72
- const id = th.fg("accent", `#${todo.id}`);
73
- const text = todo.done ? th.fg("dim", todo.text) : th.fg("text", todo.text);
74
- const line = ` ${check} ${id} ${text}`;
75
- lines.push(truncateToWidth(line, width));
76
- }
77
- }
78
-
79
- lines.push("");
80
- lines.push(truncateToWidth(` ${th.fg("dim", "Press Escape to close")}`, width));
81
- lines.push("");
82
-
83
- this.cachedWidth = width;
84
- this.cachedLines = lines;
85
- return lines;
86
- }
87
-
88
- invalidate(): void {
89
- this.cachedWidth = undefined;
90
- this.cachedLines = undefined;
91
- }
92
- }
93
-
94
- export default function (pi: HookAPI) {
95
- /**
96
- * Reconstruct todos from session entries on the current branch.
97
- */
98
- function getTodos(ctx: {
99
- sessionManager: {
100
- getBranch: () => Array<{ type: string; message?: { role?: string; toolName?: string; details?: unknown } }>;
101
- };
102
- }): Todo[] {
103
- let todos: Todo[] = [];
104
-
105
- for (const entry of ctx.sessionManager.getBranch()) {
106
- if (entry.type !== "message") continue;
107
- const msg = entry.message;
108
- if (!msg || msg.role !== "toolResult" || msg.toolName !== "todo") continue;
109
-
110
- const details = msg.details as TodoDetails | undefined;
111
- if (details) {
112
- todos = details.todos;
113
- }
114
- }
115
-
116
- return todos;
117
- }
118
-
119
- pi.registerCommand("todos", {
120
- description: "Show all todos on the current branch",
121
- handler: async (_args, ctx) => {
122
- if (!ctx.hasUI) {
123
- ctx.ui.notify("/todos requires interactive mode", "error");
124
- return;
125
- }
126
-
127
- const todos = getTodos(ctx);
128
-
129
- await ctx.ui.custom<void>((_tui, theme, done) => {
130
- return new TodoListComponent(todos, theme, () => done());
131
- });
132
- },
133
- });
134
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * Hooks Configuration
3
- *
4
- * Hooks intercept agent events for logging, blocking, or modification.
5
- */
6
-
7
- import { createAgentSession, type HookFactory, SessionManager } from "@mariozechner/pi-coding-agent";
8
-
9
- // Logging hook
10
- const loggingHook: HookFactory = (api) => {
11
- api.on("agent_start", async () => {
12
- console.log("[Hook] Agent starting");
13
- });
14
-
15
- api.on("tool_call", async (event) => {
16
- console.log(`[Hook] Tool: ${event.toolName}`);
17
- return undefined; // Don't block
18
- });
19
-
20
- api.on("agent_end", async (event) => {
21
- console.log(`[Hook] Done, ${event.messages.length} messages`);
22
- });
23
- };
24
-
25
- // Blocking hook (returns { block: true, reason: "..." })
26
- const safetyHook: HookFactory = (api) => {
27
- api.on("tool_call", async (event) => {
28
- if (event.toolName === "bash") {
29
- const cmd = (event.input as { command?: string }).command ?? "";
30
- if (cmd.includes("rm -rf")) {
31
- return { block: true, reason: "Dangerous command blocked" };
32
- }
33
- }
34
- return undefined;
35
- });
36
- };
37
-
38
- // Use inline hooks
39
- const { session } = await createAgentSession({
40
- hooks: [{ factory: loggingHook }, { factory: safetyHook }],
41
- sessionManager: SessionManager.inMemory(),
42
- });
43
-
44
- session.subscribe((event) => {
45
- if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
46
- process.stdout.write(event.assistantMessageEvent.delta);
47
- }
48
- });
49
-
50
- await session.prompt("List files in the current directory.");
51
- console.log();
52
-
53
- // Disable all hooks:
54
- // hooks: []
55
-
56
- // Merge with discovered hooks:
57
- // const discovered = await discoverHooks();
58
- // hooks: [...discovered, { factory: myHook }]
59
-
60
- // Add paths without replacing discovery:
61
- // additionalHookPaths: ["/extra/hooks"]
@@ -1,42 +0,0 @@
1
- /**
2
- * Slash Commands
3
- *
4
- * File-based commands that inject content when invoked with /commandname.
5
- */
6
-
7
- import {
8
- createAgentSession,
9
- discoverSlashCommands,
10
- type FileSlashCommand,
11
- SessionManager,
12
- } from "@mariozechner/pi-coding-agent";
13
-
14
- // Discover commands from cwd/.pi/commands/ and ~/.pi/agent/commands/
15
- const discovered = discoverSlashCommands();
16
- console.log("Discovered slash commands:");
17
- for (const cmd of discovered) {
18
- console.log(` /${cmd.name}: ${cmd.description}`);
19
- }
20
-
21
- // Define custom commands
22
- const deployCommand: FileSlashCommand = {
23
- name: "deploy",
24
- description: "Deploy the application",
25
- source: "(custom)",
26
- content: `# Deploy Instructions
27
-
28
- 1. Build: npm run build
29
- 2. Test: npm test
30
- 3. Deploy: npm run deploy`,
31
- };
32
-
33
- // Use discovered + custom commands
34
- await createAgentSession({
35
- slashCommands: [...discovered, deployCommand],
36
- sessionManager: SessionManager.inMemory(),
37
- });
38
-
39
- console.log(`Session created with ${discovered.length + 1} slash commands`);
40
-
41
- // Disable slash commands:
42
- // slashCommands: []