@mariozechner/pi-coding-agent 0.26.0 → 0.27.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.
- package/CHANGELOG.md +21 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +1 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/core/agent-session.d.ts +7 -5
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +49 -15
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/hooks/index.d.ts +1 -1
- package/dist/core/hooks/index.d.ts.map +1 -1
- package/dist/core/hooks/index.js.map +1 -1
- package/dist/core/hooks/runner.d.ts +3 -3
- package/dist/core/hooks/runner.d.ts.map +1 -1
- package/dist/core/hooks/runner.js +7 -3
- package/dist/core/hooks/runner.js.map +1 -1
- package/dist/core/hooks/types.d.ts +30 -24
- package/dist/core/hooks/types.d.ts.map +1 -1
- package/dist/core/hooks/types.js.map +1 -1
- package/dist/core/sdk.d.ts +2 -2
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +7 -3
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +1 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +6 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +149 -144
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts +7 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +105 -102
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +7 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +128 -124
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +11 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +198 -194
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +19 -7
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +43 -17
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts +6 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +90 -86
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/path-utils.d.ts +6 -1
- package/dist/core/tools/path-utils.d.ts.map +1 -1
- package/dist/core/tools/path-utils.js +17 -5
- package/dist/core/tools/path-utils.js.map +1 -1
- package/dist/core/tools/read.d.ts +7 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +118 -115
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/write.d.ts +6 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +63 -59
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +5 -5
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +8 -3
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +73 -47
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.js +33 -0
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +26 -9
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +10 -2
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +7 -2
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +5 -5
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +7 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/docs/hooks.md +42 -28
- package/docs/rpc.md +26 -6
- package/docs/sdk.md +47 -2
- package/examples/hooks/README.md +19 -3
- package/examples/hooks/auto-commit-on-exit.ts +50 -0
- package/examples/hooks/confirm-destructive.ts +62 -0
- package/examples/hooks/dirty-repo-guard.ts +59 -0
- package/examples/hooks/git-checkpoint.ts +6 -5
- package/examples/sdk/05-tools.ts +30 -4
- package/examples/sdk/12-full-control.ts +12 -4
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-types.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACzF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAClF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAM9D,MAAM,MAAM,UAAU,GAEnB;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,UAAU,EAAE,CAAA;CAAE,GAC5E;IAAE,EAAE,CAAC,EAAE,M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,MAAM,CAAA;CAAE,GAC1F;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7F;IACA,IAAI,EAAE,iBAAiB,CAAC;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,QAAQ,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;CACzC,CAAC;AAML,oCAAoC;AACpC,MAAM,MAAM,iBAAiB,GAC1B;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,GAC5D;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,IAAI,CAAA;CAAE,CAAC;AAM7D,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC","sourcesContent":["/**\n * RPC protocol types for headless operation.\n *\n * Commands are sent as JSON lines on stdin.\n * Responses and events are emitted as JSON lines on stdout.\n */\n\nimport type { AppMessage, Attachment, ThinkingLevel } from \"@mariozechner/pi-agent-core\";\nimport type { Model } from \"@mariozechner/pi-ai\";\nimport type { CompactionResult, SessionStats } from \"../../core/agent-session.js\";\nimport type { BashResult } from \"../../core/bash-executor.js\";\n\n// ============================================================================\n// RPC Commands (stdin)\n// ============================================================================\n\nexport type RpcCommand =\n\t// Prompting\n\t| { id?: string; type: \"prompt\"; message: string; attachments?: Attachment[] }\n\t| { id?: string; type: \"queue_message\"; message: string }\n\t| { id?: string; type: \"abort\" }\n\t| { id?: string; type: \"reset\" }\n\n\t// State\n\t| { id?: string; type: \"get_state\" }\n\n\t// Model\n\t| { id?: string; type: \"set_model\"; provider: string; modelId: string }\n\t| { id?: string; type: \"cycle_model\" }\n\t| { id?: string; type: \"get_available_models\" }\n\n\t// Thinking\n\t| { id?: string; type: \"set_thinking_level\"; level: ThinkingLevel }\n\t| { id?: string; type: \"cycle_thinking_level\" }\n\n\t// Queue mode\n\t| { id?: string; type: \"set_queue_mode\"; mode: \"all\" | \"one-at-a-time\" }\n\n\t// Compaction\n\t| { id?: string; type: \"compact\"; customInstructions?: string }\n\t| { id?: string; type: \"set_auto_compaction\"; enabled: boolean }\n\n\t// Retry\n\t| { id?: string; type: \"set_auto_retry\"; enabled: boolean }\n\t| { id?: string; type: \"abort_retry\" }\n\n\t// Bash\n\t| { id?: string; type: \"bash\"; command: string }\n\t| { id?: string; type: \"abort_bash\" }\n\n\t// Session\n\t| { id?: string; type: \"get_session_stats\" }\n\t| { id?: string; type: \"export_html\"; outputPath?: string }\n\t| { id?: string; type: \"switch_session\"; sessionPath: string }\n\t| { id?: string; type: \"branch\"; entryIndex: number }\n\t| { id?: string; type: \"get_branch_messages\" }\n\t| { id?: string; type: \"get_last_assistant_text\" }\n\n\t// Messages\n\t| { id?: string; type: \"get_messages\" };\n\n// ============================================================================\n// RPC State\n// ============================================================================\n\nexport interface RpcSessionState {\n\tmodel: Model<any> | null;\n\tthinkingLevel: ThinkingLevel;\n\tisStreaming: boolean;\n\tisCompacting: boolean;\n\tqueueMode: \"all\" | \"one-at-a-time\";\n\tsessionFile: string | null;\n\tsessionId: string;\n\tautoCompactionEnabled: boolean;\n\tmessageCount: number;\n\tqueuedMessageCount: number;\n}\n\n// ============================================================================\n// RPC Responses (stdout)\n// ============================================================================\n\n// Success responses with data\nexport type RpcResponse =\n\t// Prompting (async - events follow)\n\t| { id?: string; type: \"response\"; command: \"prompt\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"queue_message\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"reset\"; success: true }\n\n\t// State\n\t| { id?: string; type: \"response\"; command: \"get_state\"; success: true; data: RpcSessionState }\n\n\t// Model\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"set_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: Model<any>;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: { model: Model<any>; thinkingLevel: ThinkingLevel; isScoped: boolean } | null;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_available_models\";\n\t\t\tsuccess: true;\n\t\t\tdata: { models: Model<any>[] };\n\t }\n\n\t// Thinking\n\t| { id?: string; type: \"response\"; command: \"set_thinking_level\"; success: true }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_thinking_level\";\n\t\t\tsuccess: true;\n\t\t\tdata: { level: ThinkingLevel } | null;\n\t }\n\n\t// Queue mode\n\t| { id?: string; type: \"response\"; command: \"set_queue_mode\"; success: true }\n\n\t// Compaction\n\t| { id?: string; type: \"response\"; command: \"compact\"; success: true; data: CompactionResult }\n\t| { id?: string; type: \"response\"; command: \"set_auto_compaction\"; success: true }\n\n\t// Retry\n\t| { id?: string; type: \"response\"; command: \"set_auto_retry\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort_retry\"; success: true }\n\n\t// Bash\n\t| { id?: string; type: \"response\"; command: \"bash\"; success: true; data: BashResult }\n\t| { id?: string; type: \"response\"; command: \"abort_bash\"; success: true }\n\n\t// Session\n\t| { id?: string; type: \"response\"; command: \"get_session_stats\"; success: true; data: SessionStats }\n\t| { id?: string; type: \"response\"; command: \"export_html\"; success: true; data: { path: string } }\n\t| { id?: string; type: \"response\"; command: \"switch_session\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"branch\"; success: true; data: { text: string } }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_branch_messages\";\n\t\t\tsuccess: true;\n\t\t\tdata: { messages: Array<{ entryIndex: number; text: string }> };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_last_assistant_text\";\n\t\t\tsuccess: true;\n\t\t\tdata: { text: string | null };\n\t }\n\n\t// Messages\n\t| { id?: string; type: \"response\"; command: \"get_messages\"; success: true; data: { messages: AppMessage[] } }\n\n\t// Error response (any command can fail)\n\t| { id?: string; type: \"response\"; command: string; success: false; error: string };\n\n// ============================================================================\n// Hook UI Events (stdout)\n// ============================================================================\n\n/** Emitted when a hook needs user input */\nexport type RpcHookUIRequest =\n\t| { type: \"hook_ui_request\"; id: string; method: \"select\"; title: string; options: string[] }\n\t| { type: \"hook_ui_request\"; id: string; method: \"confirm\"; title: string; message: string }\n\t| { type: \"hook_ui_request\"; id: string; method: \"input\"; title: string; placeholder?: string }\n\t| {\n\t\t\ttype: \"hook_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"notify\";\n\t\t\tmessage: string;\n\t\t\tnotifyType?: \"info\" | \"warning\" | \"error\";\n\t };\n\n// ============================================================================\n// Hook UI Commands (stdin)\n// ============================================================================\n\n/** Response to a hook UI request */\nexport type RpcHookUIResponse =\n\t| { type: \"hook_ui_response\"; id: string; value: string }\n\t| { type: \"hook_ui_response\"; id: string; confirmed: boolean }\n\t| { type: \"hook_ui_response\"; id: string; cancelled: true };\n\n// ============================================================================\n// Helper type for extracting command types\n// ============================================================================\n\nexport type RpcCommandType = RpcCommand[\"type\"];\n"]}
|
|
1
|
+
{"version":3,"file":"rpc-types.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,aA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AI,EAAE,kBAAkB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,IAAI,CAAA;CAAE,CAAC;AAM7D,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC","sourcesContent":["/**\n * RPC protocol types for headless operation.\n *\n * Commands are sent as JSON lines on stdin.\n * Responses and events are emitted as JSON lines on stdout.\n */\n\nimport type { AppMessage, Attachment, ThinkingLevel } from \"@mariozechner/pi-agent-core\";\nimport type { Model } from \"@mariozechner/pi-ai\";\nimport type { CompactionResult, SessionStats } from \"../../core/agent-session.js\";\nimport type { BashResult } from \"../../core/bash-executor.js\";\n\n// ============================================================================\n// RPC Commands (stdin)\n// ============================================================================\n\nexport type RpcCommand =\n\t// Prompting\n\t| { id?: string; type: \"prompt\"; message: string; attachments?: Attachment[] }\n\t| { id?: string; type: \"queue_message\"; message: string }\n\t| { id?: string; type: \"abort\" }\n\t| { id?: string; type: \"reset\" }\n\n\t// State\n\t| { id?: string; type: \"get_state\" }\n\n\t// Model\n\t| { id?: string; type: \"set_model\"; provider: string; modelId: string }\n\t| { id?: string; type: \"cycle_model\" }\n\t| { id?: string; type: \"get_available_models\" }\n\n\t// Thinking\n\t| { id?: string; type: \"set_thinking_level\"; level: ThinkingLevel }\n\t| { id?: string; type: \"cycle_thinking_level\" }\n\n\t// Queue mode\n\t| { id?: string; type: \"set_queue_mode\"; mode: \"all\" | \"one-at-a-time\" }\n\n\t// Compaction\n\t| { id?: string; type: \"compact\"; customInstructions?: string }\n\t| { id?: string; type: \"set_auto_compaction\"; enabled: boolean }\n\n\t// Retry\n\t| { id?: string; type: \"set_auto_retry\"; enabled: boolean }\n\t| { id?: string; type: \"abort_retry\" }\n\n\t// Bash\n\t| { id?: string; type: \"bash\"; command: string }\n\t| { id?: string; type: \"abort_bash\" }\n\n\t// Session\n\t| { id?: string; type: \"get_session_stats\" }\n\t| { id?: string; type: \"export_html\"; outputPath?: string }\n\t| { id?: string; type: \"switch_session\"; sessionPath: string }\n\t| { id?: string; type: \"branch\"; entryIndex: number }\n\t| { id?: string; type: \"get_branch_messages\" }\n\t| { id?: string; type: \"get_last_assistant_text\" }\n\n\t// Messages\n\t| { id?: string; type: \"get_messages\" };\n\n// ============================================================================\n// RPC State\n// ============================================================================\n\nexport interface RpcSessionState {\n\tmodel: Model<any> | null;\n\tthinkingLevel: ThinkingLevel;\n\tisStreaming: boolean;\n\tisCompacting: boolean;\n\tqueueMode: \"all\" | \"one-at-a-time\";\n\tsessionFile: string | null;\n\tsessionId: string;\n\tautoCompactionEnabled: boolean;\n\tmessageCount: number;\n\tqueuedMessageCount: number;\n}\n\n// ============================================================================\n// RPC Responses (stdout)\n// ============================================================================\n\n// Success responses with data\nexport type RpcResponse =\n\t// Prompting (async - events follow)\n\t| { id?: string; type: \"response\"; command: \"prompt\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"queue_message\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"reset\"; success: true; data: { cancelled: boolean } }\n\n\t// State\n\t| { id?: string; type: \"response\"; command: \"get_state\"; success: true; data: RpcSessionState }\n\n\t// Model\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"set_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: Model<any>;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: { model: Model<any>; thinkingLevel: ThinkingLevel; isScoped: boolean } | null;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_available_models\";\n\t\t\tsuccess: true;\n\t\t\tdata: { models: Model<any>[] };\n\t }\n\n\t// Thinking\n\t| { id?: string; type: \"response\"; command: \"set_thinking_level\"; success: true }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_thinking_level\";\n\t\t\tsuccess: true;\n\t\t\tdata: { level: ThinkingLevel } | null;\n\t }\n\n\t// Queue mode\n\t| { id?: string; type: \"response\"; command: \"set_queue_mode\"; success: true }\n\n\t// Compaction\n\t| { id?: string; type: \"response\"; command: \"compact\"; success: true; data: CompactionResult }\n\t| { id?: string; type: \"response\"; command: \"set_auto_compaction\"; success: true }\n\n\t// Retry\n\t| { id?: string; type: \"response\"; command: \"set_auto_retry\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort_retry\"; success: true }\n\n\t// Bash\n\t| { id?: string; type: \"response\"; command: \"bash\"; success: true; data: BashResult }\n\t| { id?: string; type: \"response\"; command: \"abort_bash\"; success: true }\n\n\t// Session\n\t| { id?: string; type: \"response\"; command: \"get_session_stats\"; success: true; data: SessionStats }\n\t| { id?: string; type: \"response\"; command: \"export_html\"; success: true; data: { path: string } }\n\t| { id?: string; type: \"response\"; command: \"switch_session\"; success: true; data: { cancelled: boolean } }\n\t| { id?: string; type: \"response\"; command: \"branch\"; success: true; data: { text: string; cancelled: boolean } }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_branch_messages\";\n\t\t\tsuccess: true;\n\t\t\tdata: { messages: Array<{ entryIndex: number; text: string }> };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_last_assistant_text\";\n\t\t\tsuccess: true;\n\t\t\tdata: { text: string | null };\n\t }\n\n\t// Messages\n\t| { id?: string; type: \"response\"; command: \"get_messages\"; success: true; data: { messages: AppMessage[] } }\n\n\t// Error response (any command can fail)\n\t| { id?: string; type: \"response\"; command: string; success: false; error: string };\n\n// ============================================================================\n// Hook UI Events (stdout)\n// ============================================================================\n\n/** Emitted when a hook needs user input */\nexport type RpcHookUIRequest =\n\t| { type: \"hook_ui_request\"; id: string; method: \"select\"; title: string; options: string[] }\n\t| { type: \"hook_ui_request\"; id: string; method: \"confirm\"; title: string; message: string }\n\t| { type: \"hook_ui_request\"; id: string; method: \"input\"; title: string; placeholder?: string }\n\t| {\n\t\t\ttype: \"hook_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"notify\";\n\t\t\tmessage: string;\n\t\t\tnotifyType?: \"info\" | \"warning\" | \"error\";\n\t };\n\n// ============================================================================\n// Hook UI Commands (stdin)\n// ============================================================================\n\n/** Response to a hook UI request */\nexport type RpcHookUIResponse =\n\t| { type: \"hook_ui_response\"; id: string; value: string }\n\t| { type: \"hook_ui_response\"; id: string; confirmed: boolean }\n\t| { type: \"hook_ui_response\"; id: string; cancelled: true };\n\n// ============================================================================\n// Helper type for extracting command types\n// ============================================================================\n\nexport type RpcCommandType = RpcCommand[\"type\"];\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-types.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG","sourcesContent":["/**\n * RPC protocol types for headless operation.\n *\n * Commands are sent as JSON lines on stdin.\n * Responses and events are emitted as JSON lines on stdout.\n */\n\nimport type { AppMessage, Attachment, ThinkingLevel } from \"@mariozechner/pi-agent-core\";\nimport type { Model } from \"@mariozechner/pi-ai\";\nimport type { CompactionResult, SessionStats } from \"../../core/agent-session.js\";\nimport type { BashResult } from \"../../core/bash-executor.js\";\n\n// ============================================================================\n// RPC Commands (stdin)\n// ============================================================================\n\nexport type RpcCommand =\n\t// Prompting\n\t| { id?: string; type: \"prompt\"; message: string; attachments?: Attachment[] }\n\t| { id?: string; type: \"queue_message\"; message: string }\n\t| { id?: string; type: \"abort\" }\n\t| { id?: string; type: \"reset\" }\n\n\t// State\n\t| { id?: string; type: \"get_state\" }\n\n\t// Model\n\t| { id?: string; type: \"set_model\"; provider: string; modelId: string }\n\t| { id?: string; type: \"cycle_model\" }\n\t| { id?: string; type: \"get_available_models\" }\n\n\t// Thinking\n\t| { id?: string; type: \"set_thinking_level\"; level: ThinkingLevel }\n\t| { id?: string; type: \"cycle_thinking_level\" }\n\n\t// Queue mode\n\t| { id?: string; type: \"set_queue_mode\"; mode: \"all\" | \"one-at-a-time\" }\n\n\t// Compaction\n\t| { id?: string; type: \"compact\"; customInstructions?: string }\n\t| { id?: string; type: \"set_auto_compaction\"; enabled: boolean }\n\n\t// Retry\n\t| { id?: string; type: \"set_auto_retry\"; enabled: boolean }\n\t| { id?: string; type: \"abort_retry\" }\n\n\t// Bash\n\t| { id?: string; type: \"bash\"; command: string }\n\t| { id?: string; type: \"abort_bash\" }\n\n\t// Session\n\t| { id?: string; type: \"get_session_stats\" }\n\t| { id?: string; type: \"export_html\"; outputPath?: string }\n\t| { id?: string; type: \"switch_session\"; sessionPath: string }\n\t| { id?: string; type: \"branch\"; entryIndex: number }\n\t| { id?: string; type: \"get_branch_messages\" }\n\t| { id?: string; type: \"get_last_assistant_text\" }\n\n\t// Messages\n\t| { id?: string; type: \"get_messages\" };\n\n// ============================================================================\n// RPC State\n// ============================================================================\n\nexport interface RpcSessionState {\n\tmodel: Model<any> | null;\n\tthinkingLevel: ThinkingLevel;\n\tisStreaming: boolean;\n\tisCompacting: boolean;\n\tqueueMode: \"all\" | \"one-at-a-time\";\n\tsessionFile: string | null;\n\tsessionId: string;\n\tautoCompactionEnabled: boolean;\n\tmessageCount: number;\n\tqueuedMessageCount: number;\n}\n\n// ============================================================================\n// RPC Responses (stdout)\n// ============================================================================\n\n// Success responses with data\nexport type RpcResponse =\n\t// Prompting (async - events follow)\n\t| { id?: string; type: \"response\"; command: \"prompt\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"queue_message\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"reset\"; success: true }\n\n\t// State\n\t| { id?: string; type: \"response\"; command: \"get_state\"; success: true; data: RpcSessionState }\n\n\t// Model\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"set_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: Model<any>;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: { model: Model<any>; thinkingLevel: ThinkingLevel; isScoped: boolean } | null;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_available_models\";\n\t\t\tsuccess: true;\n\t\t\tdata: { models: Model<any>[] };\n\t }\n\n\t// Thinking\n\t| { id?: string; type: \"response\"; command: \"set_thinking_level\"; success: true }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_thinking_level\";\n\t\t\tsuccess: true;\n\t\t\tdata: { level: ThinkingLevel } | null;\n\t }\n\n\t// Queue mode\n\t| { id?: string; type: \"response\"; command: \"set_queue_mode\"; success: true }\n\n\t// Compaction\n\t| { id?: string; type: \"response\"; command: \"compact\"; success: true; data: CompactionResult }\n\t| { id?: string; type: \"response\"; command: \"set_auto_compaction\"; success: true }\n\n\t// Retry\n\t| { id?: string; type: \"response\"; command: \"set_auto_retry\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort_retry\"; success: true }\n\n\t// Bash\n\t| { id?: string; type: \"response\"; command: \"bash\"; success: true; data: BashResult }\n\t| { id?: string; type: \"response\"; command: \"abort_bash\"; success: true }\n\n\t// Session\n\t| { id?: string; type: \"response\"; command: \"get_session_stats\"; success: true; data: SessionStats }\n\t| { id?: string; type: \"response\"; command: \"export_html\"; success: true; data: { path: string } }\n\t| { id?: string; type: \"response\"; command: \"switch_session\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"branch\"; success: true; data: { text: string } }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_branch_messages\";\n\t\t\tsuccess: true;\n\t\t\tdata: { messages: Array<{ entryIndex: number; text: string }> };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_last_assistant_text\";\n\t\t\tsuccess: true;\n\t\t\tdata: { text: string | null };\n\t }\n\n\t// Messages\n\t| { id?: string; type: \"response\"; command: \"get_messages\"; success: true; data: { messages: AppMessage[] } }\n\n\t// Error response (any command can fail)\n\t| { id?: string; type: \"response\"; command: string; success: false; error: string };\n\n// ============================================================================\n// Hook UI Events (stdout)\n// ============================================================================\n\n/** Emitted when a hook needs user input */\nexport type RpcHookUIRequest =\n\t| { type: \"hook_ui_request\"; id: string; method: \"select\"; title: string; options: string[] }\n\t| { type: \"hook_ui_request\"; id: string; method: \"confirm\"; title: string; message: string }\n\t| { type: \"hook_ui_request\"; id: string; method: \"input\"; title: string; placeholder?: string }\n\t| {\n\t\t\ttype: \"hook_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"notify\";\n\t\t\tmessage: string;\n\t\t\tnotifyType?: \"info\" | \"warning\" | \"error\";\n\t };\n\n// ============================================================================\n// Hook UI Commands (stdin)\n// ============================================================================\n\n/** Response to a hook UI request */\nexport type RpcHookUIResponse =\n\t| { type: \"hook_ui_response\"; id: string; value: string }\n\t| { type: \"hook_ui_response\"; id: string; confirmed: boolean }\n\t| { type: \"hook_ui_response\"; id: string; cancelled: true };\n\n// ============================================================================\n// Helper type for extracting command types\n// ============================================================================\n\nexport type RpcCommandType = RpcCommand[\"type\"];\n"]}
|
|
1
|
+
{"version":3,"file":"rpc-types.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG","sourcesContent":["/**\n * RPC protocol types for headless operation.\n *\n * Commands are sent as JSON lines on stdin.\n * Responses and events are emitted as JSON lines on stdout.\n */\n\nimport type { AppMessage, Attachment, ThinkingLevel } from \"@mariozechner/pi-agent-core\";\nimport type { Model } from \"@mariozechner/pi-ai\";\nimport type { CompactionResult, SessionStats } from \"../../core/agent-session.js\";\nimport type { BashResult } from \"../../core/bash-executor.js\";\n\n// ============================================================================\n// RPC Commands (stdin)\n// ============================================================================\n\nexport type RpcCommand =\n\t// Prompting\n\t| { id?: string; type: \"prompt\"; message: string; attachments?: Attachment[] }\n\t| { id?: string; type: \"queue_message\"; message: string }\n\t| { id?: string; type: \"abort\" }\n\t| { id?: string; type: \"reset\" }\n\n\t// State\n\t| { id?: string; type: \"get_state\" }\n\n\t// Model\n\t| { id?: string; type: \"set_model\"; provider: string; modelId: string }\n\t| { id?: string; type: \"cycle_model\" }\n\t| { id?: string; type: \"get_available_models\" }\n\n\t// Thinking\n\t| { id?: string; type: \"set_thinking_level\"; level: ThinkingLevel }\n\t| { id?: string; type: \"cycle_thinking_level\" }\n\n\t// Queue mode\n\t| { id?: string; type: \"set_queue_mode\"; mode: \"all\" | \"one-at-a-time\" }\n\n\t// Compaction\n\t| { id?: string; type: \"compact\"; customInstructions?: string }\n\t| { id?: string; type: \"set_auto_compaction\"; enabled: boolean }\n\n\t// Retry\n\t| { id?: string; type: \"set_auto_retry\"; enabled: boolean }\n\t| { id?: string; type: \"abort_retry\" }\n\n\t// Bash\n\t| { id?: string; type: \"bash\"; command: string }\n\t| { id?: string; type: \"abort_bash\" }\n\n\t// Session\n\t| { id?: string; type: \"get_session_stats\" }\n\t| { id?: string; type: \"export_html\"; outputPath?: string }\n\t| { id?: string; type: \"switch_session\"; sessionPath: string }\n\t| { id?: string; type: \"branch\"; entryIndex: number }\n\t| { id?: string; type: \"get_branch_messages\" }\n\t| { id?: string; type: \"get_last_assistant_text\" }\n\n\t// Messages\n\t| { id?: string; type: \"get_messages\" };\n\n// ============================================================================\n// RPC State\n// ============================================================================\n\nexport interface RpcSessionState {\n\tmodel: Model<any> | null;\n\tthinkingLevel: ThinkingLevel;\n\tisStreaming: boolean;\n\tisCompacting: boolean;\n\tqueueMode: \"all\" | \"one-at-a-time\";\n\tsessionFile: string | null;\n\tsessionId: string;\n\tautoCompactionEnabled: boolean;\n\tmessageCount: number;\n\tqueuedMessageCount: number;\n}\n\n// ============================================================================\n// RPC Responses (stdout)\n// ============================================================================\n\n// Success responses with data\nexport type RpcResponse =\n\t// Prompting (async - events follow)\n\t| { id?: string; type: \"response\"; command: \"prompt\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"queue_message\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"reset\"; success: true; data: { cancelled: boolean } }\n\n\t// State\n\t| { id?: string; type: \"response\"; command: \"get_state\"; success: true; data: RpcSessionState }\n\n\t// Model\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"set_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: Model<any>;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: { model: Model<any>; thinkingLevel: ThinkingLevel; isScoped: boolean } | null;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_available_models\";\n\t\t\tsuccess: true;\n\t\t\tdata: { models: Model<any>[] };\n\t }\n\n\t// Thinking\n\t| { id?: string; type: \"response\"; command: \"set_thinking_level\"; success: true }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_thinking_level\";\n\t\t\tsuccess: true;\n\t\t\tdata: { level: ThinkingLevel } | null;\n\t }\n\n\t// Queue mode\n\t| { id?: string; type: \"response\"; command: \"set_queue_mode\"; success: true }\n\n\t// Compaction\n\t| { id?: string; type: \"response\"; command: \"compact\"; success: true; data: CompactionResult }\n\t| { id?: string; type: \"response\"; command: \"set_auto_compaction\"; success: true }\n\n\t// Retry\n\t| { id?: string; type: \"response\"; command: \"set_auto_retry\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort_retry\"; success: true }\n\n\t// Bash\n\t| { id?: string; type: \"response\"; command: \"bash\"; success: true; data: BashResult }\n\t| { id?: string; type: \"response\"; command: \"abort_bash\"; success: true }\n\n\t// Session\n\t| { id?: string; type: \"response\"; command: \"get_session_stats\"; success: true; data: SessionStats }\n\t| { id?: string; type: \"response\"; command: \"export_html\"; success: true; data: { path: string } }\n\t| { id?: string; type: \"response\"; command: \"switch_session\"; success: true; data: { cancelled: boolean } }\n\t| { id?: string; type: \"response\"; command: \"branch\"; success: true; data: { text: string; cancelled: boolean } }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_branch_messages\";\n\t\t\tsuccess: true;\n\t\t\tdata: { messages: Array<{ entryIndex: number; text: string }> };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_last_assistant_text\";\n\t\t\tsuccess: true;\n\t\t\tdata: { text: string | null };\n\t }\n\n\t// Messages\n\t| { id?: string; type: \"response\"; command: \"get_messages\"; success: true; data: { messages: AppMessage[] } }\n\n\t// Error response (any command can fail)\n\t| { id?: string; type: \"response\"; command: string; success: false; error: string };\n\n// ============================================================================\n// Hook UI Events (stdout)\n// ============================================================================\n\n/** Emitted when a hook needs user input */\nexport type RpcHookUIRequest =\n\t| { type: \"hook_ui_request\"; id: string; method: \"select\"; title: string; options: string[] }\n\t| { type: \"hook_ui_request\"; id: string; method: \"confirm\"; title: string; message: string }\n\t| { type: \"hook_ui_request\"; id: string; method: \"input\"; title: string; placeholder?: string }\n\t| {\n\t\t\ttype: \"hook_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"notify\";\n\t\t\tmessage: string;\n\t\t\tnotifyType?: \"info\" | \"warning\" | \"error\";\n\t };\n\n// ============================================================================\n// Hook UI Commands (stdin)\n// ============================================================================\n\n/** Response to a hook UI request */\nexport type RpcHookUIResponse =\n\t| { type: \"hook_ui_response\"; id: string; value: string }\n\t| { type: \"hook_ui_response\"; id: string; confirmed: boolean }\n\t| { type: \"hook_ui_response\"; id: string; cancelled: true };\n\n// ============================================================================\n// Helper type for extracting command types\n// ============================================================================\n\nexport type RpcCommandType = RpcCommand[\"type\"];\n"]}
|
package/docs/hooks.md
CHANGED
|
@@ -117,51 +117,55 @@ user sends another prompt ◄─────────────────
|
|
|
117
117
|
|
|
118
118
|
user branches (/branch)
|
|
119
119
|
│
|
|
120
|
-
├─►
|
|
121
|
-
└─► session (reason: "
|
|
120
|
+
├─► session (reason: "before_branch", can cancel)
|
|
121
|
+
└─► session (reason: "branch", AFTER branch)
|
|
122
122
|
|
|
123
123
|
user switches session (/session)
|
|
124
124
|
│
|
|
125
|
-
|
|
125
|
+
├─► session (reason: "before_switch", can cancel)
|
|
126
|
+
└─► session (reason: "switch", AFTER switch)
|
|
126
127
|
|
|
127
128
|
user clears session (/clear)
|
|
128
129
|
│
|
|
129
|
-
|
|
130
|
+
├─► session (reason: "before_clear", can cancel)
|
|
131
|
+
└─► session (reason: "clear", AFTER clear)
|
|
132
|
+
|
|
133
|
+
user exits (double Ctrl+C or Ctrl+D)
|
|
134
|
+
│
|
|
135
|
+
└─► session (reason: "shutdown")
|
|
130
136
|
```
|
|
131
137
|
|
|
132
138
|
A **turn** is one LLM response plus any tool calls. Complex tasks loop through multiple turns until the LLM responds without calling tools.
|
|
133
139
|
|
|
134
140
|
### session
|
|
135
141
|
|
|
136
|
-
Fired on
|
|
142
|
+
Fired on session lifecycle events. The `before_*` variants fire before the action and can be cancelled by returning `{ cancel: true }`.
|
|
137
143
|
|
|
138
144
|
```typescript
|
|
139
145
|
pi.on("session", async (event, ctx) => {
|
|
140
146
|
// event.entries: SessionEntry[] - all session entries
|
|
141
147
|
// event.sessionFile: string | null - current session file (null with --no-session)
|
|
142
148
|
// event.previousSessionFile: string | null - previous session file
|
|
143
|
-
// event.reason: "start" | "switch" | "clear"
|
|
149
|
+
// event.reason: "start" | "before_switch" | "switch" | "before_clear" | "clear" |
|
|
150
|
+
// "before_branch" | "branch" | "shutdown"
|
|
151
|
+
// event.targetTurnIndex: number - only for "before_branch" and "branch"
|
|
152
|
+
|
|
153
|
+
// Cancel a before_* action:
|
|
154
|
+
if (event.reason === "before_clear") {
|
|
155
|
+
return { cancel: true };
|
|
156
|
+
}
|
|
157
|
+
// No return needed if not cancelling
|
|
144
158
|
});
|
|
145
159
|
```
|
|
146
160
|
|
|
147
161
|
**Reasons:**
|
|
148
162
|
- `start`: Initial session load on startup
|
|
149
|
-
- `switch`: User switched sessions (`/session`)
|
|
150
|
-
- `clear`: User cleared the session (`/clear`)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
Fired BEFORE a branch happens. Can control branch behavior.
|
|
163
|
+
- `before_switch` / `switch`: User switched sessions (`/session`)
|
|
164
|
+
- `before_clear` / `clear`: User cleared the session (`/clear`)
|
|
165
|
+
- `before_branch` / `branch`: User branched the session (`/branch`)
|
|
166
|
+
- `shutdown`: Process is exiting (double Ctrl+C, Ctrl+D, or SIGTERM)
|
|
155
167
|
|
|
156
|
-
|
|
157
|
-
pi.on("branch", async (event, ctx) => {
|
|
158
|
-
// event.targetTurnIndex: number
|
|
159
|
-
// event.entries: SessionEntry[]
|
|
160
|
-
return { skipConversationRestore: true }; // or undefined
|
|
161
|
-
});
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
Note: After branch completes, a `session` event fires with `reason: "switch"`.
|
|
168
|
+
For `before_branch` and `branch` events, `event.targetTurnIndex` contains the entry index being branched from.
|
|
165
169
|
|
|
166
170
|
### agent_start / agent_end
|
|
167
171
|
|
|
@@ -544,9 +548,12 @@ export default function (pi: HookAPI) {
|
|
|
544
548
|
}
|
|
545
549
|
});
|
|
546
550
|
|
|
547
|
-
pi.on("
|
|
551
|
+
pi.on("session", async (event, ctx) => {
|
|
552
|
+
// Only handle before_branch events
|
|
553
|
+
if (event.reason !== "before_branch") return;
|
|
554
|
+
|
|
548
555
|
const ref = checkpoints.get(event.targetTurnIndex);
|
|
549
|
-
if (!ref) return
|
|
556
|
+
if (!ref) return;
|
|
550
557
|
|
|
551
558
|
const choice = await ctx.ui.select("Restore code state?", [
|
|
552
559
|
"Yes, restore code to that point",
|
|
@@ -557,8 +564,6 @@ export default function (pi: HookAPI) {
|
|
|
557
564
|
await ctx.exec("git", ["stash", "apply", ref]);
|
|
558
565
|
ctx.ui.notify("Code restored to checkpoint", "info");
|
|
559
566
|
}
|
|
560
|
-
|
|
561
|
-
return undefined;
|
|
562
567
|
});
|
|
563
568
|
|
|
564
569
|
pi.on("agent_end", async () => {
|
|
@@ -712,17 +717,26 @@ User sends prompt:
|
|
|
712
717
|
|
|
713
718
|
Branch:
|
|
714
719
|
-> AgentSession.branch()
|
|
715
|
-
-> hookRunner.emit({ type: "
|
|
716
|
-
-> [branch happens]
|
|
717
|
-
-> hookRunner.emit({ type: "session", reason: "
|
|
720
|
+
-> hookRunner.emit({ type: "session", reason: "before_branch", ... }) # can cancel
|
|
721
|
+
-> [if not cancelled: branch happens]
|
|
722
|
+
-> hookRunner.emit({ type: "session", reason: "branch", ... })
|
|
718
723
|
|
|
719
724
|
Session switch:
|
|
720
725
|
-> AgentSession.switchSession()
|
|
726
|
+
-> hookRunner.emit({ type: "session", reason: "before_switch", ... }) # can cancel
|
|
727
|
+
-> [if not cancelled: switch happens]
|
|
721
728
|
-> hookRunner.emit({ type: "session", reason: "switch", ... })
|
|
722
729
|
|
|
723
730
|
Clear:
|
|
724
731
|
-> AgentSession.reset()
|
|
732
|
+
-> hookRunner.emit({ type: "session", reason: "before_clear", ... }) # can cancel
|
|
733
|
+
-> [if not cancelled: clear happens]
|
|
725
734
|
-> hookRunner.emit({ type: "session", reason: "clear", ... })
|
|
735
|
+
|
|
736
|
+
Shutdown (interactive mode):
|
|
737
|
+
-> handleCtrlC() or handleCtrlD()
|
|
738
|
+
-> hookRunner.emit({ type: "session", reason: "shutdown", ... })
|
|
739
|
+
-> process.exit(0)
|
|
726
740
|
```
|
|
727
741
|
|
|
728
742
|
## UI Context by Mode
|
package/docs/rpc.md
CHANGED
|
@@ -78,7 +78,7 @@ Response:
|
|
|
78
78
|
|
|
79
79
|
#### reset
|
|
80
80
|
|
|
81
|
-
Clear context and start a fresh session.
|
|
81
|
+
Clear context and start a fresh session. Can be cancelled by a `before_clear` hook.
|
|
82
82
|
|
|
83
83
|
```json
|
|
84
84
|
{"type": "reset"}
|
|
@@ -86,7 +86,12 @@ Clear context and start a fresh session.
|
|
|
86
86
|
|
|
87
87
|
Response:
|
|
88
88
|
```json
|
|
89
|
-
{"type": "response", "command": "reset", "success": true}
|
|
89
|
+
{"type": "response", "command": "reset", "success": true, "data": {"cancelled": false}}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
If a hook cancelled the reset:
|
|
93
|
+
```json
|
|
94
|
+
{"type": "response", "command": "reset", "success": true, "data": {"cancelled": true}}
|
|
90
95
|
```
|
|
91
96
|
|
|
92
97
|
### State
|
|
@@ -465,7 +470,7 @@ Response:
|
|
|
465
470
|
|
|
466
471
|
#### switch_session
|
|
467
472
|
|
|
468
|
-
Load a different session file.
|
|
473
|
+
Load a different session file. Can be cancelled by a `before_switch` hook.
|
|
469
474
|
|
|
470
475
|
```json
|
|
471
476
|
{"type": "switch_session", "sessionPath": "/path/to/session.jsonl"}
|
|
@@ -473,12 +478,17 @@ Load a different session file.
|
|
|
473
478
|
|
|
474
479
|
Response:
|
|
475
480
|
```json
|
|
476
|
-
{"type": "response", "command": "switch_session", "success": true}
|
|
481
|
+
{"type": "response", "command": "switch_session", "success": true, "data": {"cancelled": false}}
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
If a hook cancelled the switch:
|
|
485
|
+
```json
|
|
486
|
+
{"type": "response", "command": "switch_session", "success": true, "data": {"cancelled": true}}
|
|
477
487
|
```
|
|
478
488
|
|
|
479
489
|
#### branch
|
|
480
490
|
|
|
481
|
-
Create a new branch from a previous user message. Returns the text of the message being branched from.
|
|
491
|
+
Create a new branch from a previous user message. Can be cancelled by a `before_branch` hook. Returns the text of the message being branched from.
|
|
482
492
|
|
|
483
493
|
```json
|
|
484
494
|
{"type": "branch", "entryIndex": 2}
|
|
@@ -490,7 +500,17 @@ Response:
|
|
|
490
500
|
"type": "response",
|
|
491
501
|
"command": "branch",
|
|
492
502
|
"success": true,
|
|
493
|
-
"data": {"text": "The original prompt text..."}
|
|
503
|
+
"data": {"text": "The original prompt text...", "cancelled": false}
|
|
504
|
+
}
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
If a hook cancelled the branch:
|
|
508
|
+
```json
|
|
509
|
+
{
|
|
510
|
+
"type": "response",
|
|
511
|
+
"command": "branch",
|
|
512
|
+
"success": true,
|
|
513
|
+
"data": {"text": "The original prompt text...", "cancelled": true}
|
|
494
514
|
}
|
|
495
515
|
```
|
|
496
516
|
|
package/docs/sdk.md
CHANGED
|
@@ -307,7 +307,7 @@ const { session } = await createAgentSession({
|
|
|
307
307
|
```typescript
|
|
308
308
|
import {
|
|
309
309
|
codingTools, // read, bash, edit, write (default)
|
|
310
|
-
readOnlyTools, // read,
|
|
310
|
+
readOnlyTools, // read, grep, find, ls
|
|
311
311
|
readTool, bashTool, editTool, writeTool,
|
|
312
312
|
grepTool, findTool, lsTool,
|
|
313
313
|
} from "@mariozechner/pi-coding-agent";
|
|
@@ -323,6 +323,45 @@ const { session } = await createAgentSession({
|
|
|
323
323
|
});
|
|
324
324
|
```
|
|
325
325
|
|
|
326
|
+
#### Tools with Custom cwd
|
|
327
|
+
|
|
328
|
+
**Important:** The pre-built tool instances (`readTool`, `bashTool`, etc.) use `process.cwd()` for path resolution. When you specify a custom `cwd` AND provide explicit `tools`, you must use the tool factory functions to ensure paths resolve correctly:
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
import {
|
|
332
|
+
createCodingTools, // Creates [read, bash, edit, write] for specific cwd
|
|
333
|
+
createReadOnlyTools, // Creates [read, grep, find, ls] for specific cwd
|
|
334
|
+
createReadTool,
|
|
335
|
+
createBashTool,
|
|
336
|
+
createEditTool,
|
|
337
|
+
createWriteTool,
|
|
338
|
+
createGrepTool,
|
|
339
|
+
createFindTool,
|
|
340
|
+
createLsTool,
|
|
341
|
+
} from "@mariozechner/pi-coding-agent";
|
|
342
|
+
|
|
343
|
+
const cwd = "/path/to/project";
|
|
344
|
+
|
|
345
|
+
// Use factory for tool sets
|
|
346
|
+
const { session } = await createAgentSession({
|
|
347
|
+
cwd,
|
|
348
|
+
tools: createCodingTools(cwd), // Tools resolve paths relative to cwd
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
// Or pick specific tools
|
|
352
|
+
const { session } = await createAgentSession({
|
|
353
|
+
cwd,
|
|
354
|
+
tools: [createReadTool(cwd), createBashTool(cwd), createGrepTool(cwd)],
|
|
355
|
+
});
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
**When you don't need factories:**
|
|
359
|
+
- If you omit `tools`, pi automatically creates them with the correct `cwd`
|
|
360
|
+
- If you use `process.cwd()` as your `cwd`, the pre-built instances work fine
|
|
361
|
+
|
|
362
|
+
**When you must use factories:**
|
|
363
|
+
- When you specify both `cwd` (different from `process.cwd()`) AND `tools`
|
|
364
|
+
|
|
326
365
|
> See [examples/sdk/05-tools.ts](../examples/sdk/05-tools.ts)
|
|
327
366
|
|
|
328
367
|
### Custom Tools
|
|
@@ -788,12 +827,18 @@ buildSystemPrompt
|
|
|
788
827
|
SessionManager
|
|
789
828
|
SettingsManager
|
|
790
829
|
|
|
791
|
-
// Built-in tools
|
|
830
|
+
// Built-in tools (use process.cwd())
|
|
792
831
|
codingTools
|
|
793
832
|
readOnlyTools
|
|
794
833
|
readTool, bashTool, editTool, writeTool
|
|
795
834
|
grepTool, findTool, lsTool
|
|
796
835
|
|
|
836
|
+
// Tool factories (for custom cwd)
|
|
837
|
+
createCodingTools
|
|
838
|
+
createReadOnlyTools
|
|
839
|
+
createReadTool, createBashTool, createEditTool, createWriteTool
|
|
840
|
+
createGrepTool, createFindTool, createLsTool
|
|
841
|
+
|
|
797
842
|
// Types
|
|
798
843
|
type CreateAgentSessionOptions
|
|
799
844
|
type CreateAgentSessionResult
|
package/examples/hooks/README.md
CHANGED
|
@@ -16,6 +16,15 @@ Blocks writes to protected paths (.env, .git/, node_modules/).
|
|
|
16
16
|
### file-trigger.ts
|
|
17
17
|
Watches a trigger file and injects its contents into the conversation. Useful for external systems (CI, file watchers, webhooks) to send messages to the agent.
|
|
18
18
|
|
|
19
|
+
### confirm-destructive.ts
|
|
20
|
+
Prompts for confirmation before destructive session actions (clear, switch, branch). Demonstrates how to cancel `before_*` session events.
|
|
21
|
+
|
|
22
|
+
### dirty-repo-guard.ts
|
|
23
|
+
Prevents session changes when there are uncommitted git changes. Blocks clear/switch/branch until you commit.
|
|
24
|
+
|
|
25
|
+
### auto-commit-on-exit.ts
|
|
26
|
+
Automatically commits changes when the agent exits (shutdown event). Uses the last assistant message to generate a commit message.
|
|
27
|
+
|
|
19
28
|
## Usage
|
|
20
29
|
|
|
21
30
|
```bash
|
|
@@ -38,8 +47,16 @@ import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
|
|
38
47
|
|
|
39
48
|
export default function (pi: HookAPI) {
|
|
40
49
|
pi.on("session", async (event, ctx) => {
|
|
41
|
-
// event.reason: "start" | "switch" | "clear"
|
|
50
|
+
// event.reason: "start" | "before_switch" | "switch" | "before_clear" | "clear" |
|
|
51
|
+
// "before_branch" | "branch" | "shutdown"
|
|
52
|
+
// event.targetTurnIndex: number (only for before_branch/branch)
|
|
42
53
|
// ctx.ui, ctx.exec, ctx.cwd, ctx.sessionFile, ctx.hasUI
|
|
54
|
+
|
|
55
|
+
// Cancel before_* actions:
|
|
56
|
+
if (event.reason === "before_clear") {
|
|
57
|
+
return { cancel: true };
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
43
60
|
});
|
|
44
61
|
|
|
45
62
|
pi.on("tool_call", async (event, ctx) => {
|
|
@@ -58,8 +75,7 @@ export default function (pi: HookAPI) {
|
|
|
58
75
|
```
|
|
59
76
|
|
|
60
77
|
**Available events:**
|
|
61
|
-
- `session` -
|
|
62
|
-
- `branch` - before branching (can skip conversation restore)
|
|
78
|
+
- `session` - lifecycle events with before/after variants (can cancel before_* actions)
|
|
63
79
|
- `agent_start` / `agent_end` - per user prompt
|
|
64
80
|
- `turn_start` / `turn_end` - per LLM turn
|
|
65
81
|
- `tool_call` - before tool execution (can block)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-Commit on Exit Hook
|
|
3
|
+
*
|
|
4
|
+
* Automatically commits changes when the agent exits.
|
|
5
|
+
* Uses the last assistant message to generate a commit message.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
|
9
|
+
|
|
10
|
+
export default function (pi: HookAPI) {
|
|
11
|
+
pi.on("session", async (event, ctx) => {
|
|
12
|
+
if (event.reason !== "shutdown") return;
|
|
13
|
+
|
|
14
|
+
// Check for uncommitted changes
|
|
15
|
+
const { stdout: status, code } = await ctx.exec("git", ["status", "--porcelain"]);
|
|
16
|
+
|
|
17
|
+
if (code !== 0 || status.trim().length === 0) {
|
|
18
|
+
// Not a git repo or no changes
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Find the last assistant message for commit context
|
|
23
|
+
let lastAssistantText = "";
|
|
24
|
+
for (let i = event.entries.length - 1; i >= 0; i--) {
|
|
25
|
+
const entry = event.entries[i];
|
|
26
|
+
if (entry.type === "message" && entry.message.role === "assistant") {
|
|
27
|
+
const content = entry.message.content;
|
|
28
|
+
if (Array.isArray(content)) {
|
|
29
|
+
lastAssistantText = content
|
|
30
|
+
.filter((c): c is { type: "text"; text: string } => c.type === "text")
|
|
31
|
+
.map((c) => c.text)
|
|
32
|
+
.join("\n");
|
|
33
|
+
}
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Generate a simple commit message
|
|
39
|
+
const firstLine = lastAssistantText.split("\n")[0] || "Work in progress";
|
|
40
|
+
const commitMessage = `[pi] ${firstLine.slice(0, 50)}${firstLine.length > 50 ? "..." : ""}`;
|
|
41
|
+
|
|
42
|
+
// Stage and commit
|
|
43
|
+
await ctx.exec("git", ["add", "-A"]);
|
|
44
|
+
const { code: commitCode } = await ctx.exec("git", ["commit", "-m", commitMessage]);
|
|
45
|
+
|
|
46
|
+
if (commitCode === 0 && ctx.hasUI) {
|
|
47
|
+
ctx.ui.notify(`Auto-committed: ${commitMessage}`, "info");
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Confirm Destructive Actions Hook
|
|
3
|
+
*
|
|
4
|
+
* Prompts for confirmation before destructive session actions (clear, switch, branch).
|
|
5
|
+
* Demonstrates how to cancel session events using the before_* variants.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
|
9
|
+
|
|
10
|
+
export default function (pi: HookAPI) {
|
|
11
|
+
pi.on("session", async (event, ctx) => {
|
|
12
|
+
// Only handle before_* events (the ones that can be cancelled)
|
|
13
|
+
if (event.reason === "before_clear") {
|
|
14
|
+
if (!ctx.hasUI) return;
|
|
15
|
+
|
|
16
|
+
const confirmed = await ctx.ui.confirm(
|
|
17
|
+
"Clear session?",
|
|
18
|
+
"This will delete all messages in the current session.",
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (!confirmed) {
|
|
22
|
+
ctx.ui.notify("Clear cancelled", "info");
|
|
23
|
+
return { cancel: true };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (event.reason === "before_switch") {
|
|
28
|
+
if (!ctx.hasUI) return;
|
|
29
|
+
|
|
30
|
+
// Check if there are unsaved changes (messages since last assistant response)
|
|
31
|
+
const hasUnsavedWork = event.entries.some(
|
|
32
|
+
(e) => e.type === "message" && e.message.role === "user",
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if (hasUnsavedWork) {
|
|
36
|
+
const confirmed = await ctx.ui.confirm(
|
|
37
|
+
"Switch session?",
|
|
38
|
+
"You have messages in the current session. Switch anyway?",
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if (!confirmed) {
|
|
42
|
+
ctx.ui.notify("Switch cancelled", "info");
|
|
43
|
+
return { cancel: true };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (event.reason === "before_branch") {
|
|
49
|
+
if (!ctx.hasUI) return;
|
|
50
|
+
|
|
51
|
+
const choice = await ctx.ui.select(
|
|
52
|
+
`Branch from turn ${event.targetTurnIndex}?`,
|
|
53
|
+
["Yes, create branch", "No, stay in current session"],
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
if (choice !== "Yes, create branch") {
|
|
57
|
+
ctx.ui.notify("Branch cancelled", "info");
|
|
58
|
+
return { cancel: true };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dirty Repo Guard Hook
|
|
3
|
+
*
|
|
4
|
+
* Prevents session changes when there are uncommitted git changes.
|
|
5
|
+
* Useful to ensure work is committed before switching context.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
|
9
|
+
|
|
10
|
+
export default function (pi: HookAPI) {
|
|
11
|
+
pi.on("session", async (event, ctx) => {
|
|
12
|
+
// Only guard destructive actions
|
|
13
|
+
if (
|
|
14
|
+
event.reason !== "before_clear" &&
|
|
15
|
+
event.reason !== "before_switch" &&
|
|
16
|
+
event.reason !== "before_branch"
|
|
17
|
+
) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Check for uncommitted changes
|
|
22
|
+
const { stdout, code } = await ctx.exec("git", ["status", "--porcelain"]);
|
|
23
|
+
|
|
24
|
+
if (code !== 0) {
|
|
25
|
+
// Not a git repo, allow the action
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const hasChanges = stdout.trim().length > 0;
|
|
30
|
+
if (!hasChanges) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!ctx.hasUI) {
|
|
35
|
+
// In non-interactive mode, block by default
|
|
36
|
+
return { cancel: true };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Count changed files
|
|
40
|
+
const changedFiles = stdout.trim().split("\n").filter(Boolean).length;
|
|
41
|
+
|
|
42
|
+
const action =
|
|
43
|
+
event.reason === "before_clear"
|
|
44
|
+
? "clear session"
|
|
45
|
+
: event.reason === "before_switch"
|
|
46
|
+
? "switch session"
|
|
47
|
+
: "branch";
|
|
48
|
+
|
|
49
|
+
const choice = await ctx.ui.select(
|
|
50
|
+
`You have ${changedFiles} uncommitted file(s). ${action} anyway?`,
|
|
51
|
+
["Yes, proceed anyway", "No, let me commit first"],
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
if (choice !== "Yes, proceed anyway") {
|
|
55
|
+
ctx.ui.notify("Commit your changes first", "warning");
|
|
56
|
+
return { cancel: true };
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -19,13 +19,16 @@ export default function (pi: HookAPI) {
|
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
pi.on("
|
|
22
|
+
pi.on("session", async (event, ctx) => {
|
|
23
|
+
// Only handle before_branch events
|
|
24
|
+
if (event.reason !== "before_branch") return;
|
|
25
|
+
|
|
23
26
|
const ref = checkpoints.get(event.targetTurnIndex);
|
|
24
|
-
if (!ref) return
|
|
27
|
+
if (!ref) return;
|
|
25
28
|
|
|
26
29
|
if (!ctx.hasUI) {
|
|
27
30
|
// In non-interactive mode, don't restore automatically
|
|
28
|
-
return
|
|
31
|
+
return;
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
const choice = await ctx.ui.select("Restore code state?", [
|
|
@@ -37,8 +40,6 @@ export default function (pi: HookAPI) {
|
|
|
37
40
|
await ctx.exec("git", ["stash", "apply", ref]);
|
|
38
41
|
ctx.ui.notify("Code restored to checkpoint", "info");
|
|
39
42
|
}
|
|
40
|
-
|
|
41
|
-
return undefined;
|
|
42
43
|
});
|
|
43
44
|
|
|
44
45
|
pi.on("agent_end", async () => {
|