@mariozechner/pi-coding-agent 0.30.2 → 0.31.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 +244 -1
- package/README.md +105 -84
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +5 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/file-processor.d.ts +3 -3
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +7 -10
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +18 -0
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +73 -34
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +464 -210
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +2 -2
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +2 -2
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bash-executor.d.ts +2 -2
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +2 -2
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +84 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/core/compaction/branch-summarization.js +233 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -0
- package/dist/core/{compaction.d.ts → compaction/compaction.d.ts} +38 -19
- package/dist/core/compaction/compaction.d.ts.map +1 -0
- package/dist/core/compaction/compaction.js +558 -0
- package/dist/core/compaction/compaction.js.map +1 -0
- package/dist/core/compaction/index.d.ts +7 -0
- package/dist/core/compaction/index.d.ts.map +1 -0
- package/dist/core/compaction/index.js +7 -0
- package/dist/core/compaction/index.js.map +1 -0
- package/dist/core/compaction/utils.d.ts +35 -0
- package/dist/core/compaction/utils.d.ts.map +1 -0
- package/dist/core/compaction/utils.js +138 -0
- package/dist/core/compaction/utils.js.map +1 -0
- package/dist/core/custom-tools/index.d.ts +2 -1
- package/dist/core/custom-tools/index.d.ts.map +1 -1
- package/dist/core/custom-tools/index.js +1 -0
- package/dist/core/custom-tools/index.js.map +1 -1
- package/dist/core/custom-tools/loader.d.ts.map +1 -1
- package/dist/core/custom-tools/loader.js +13 -80
- package/dist/core/custom-tools/loader.js.map +1 -1
- package/dist/core/custom-tools/types.d.ts +84 -59
- package/dist/core/custom-tools/types.d.ts.map +1 -1
- package/dist/core/custom-tools/types.js.map +1 -1
- package/dist/core/custom-tools/wrapper.d.ts +15 -0
- package/dist/core/custom-tools/wrapper.d.ts.map +1 -0
- package/dist/core/custom-tools/wrapper.js +23 -0
- package/dist/core/custom-tools/wrapper.js.map +1 -0
- package/dist/core/exec.d.ts +29 -0
- package/dist/core/exec.d.ts.map +1 -0
- package/dist/core/exec.js +71 -0
- package/dist/core/exec.js.map +1 -0
- package/dist/core/export-html/index.d.ts +17 -0
- package/dist/core/export-html/index.d.ts.map +1 -0
- package/dist/core/export-html/index.js +171 -0
- package/dist/core/export-html/index.js.map +1 -0
- package/dist/core/export-html/template.css +781 -0
- package/dist/core/export-html/template.html +54 -0
- package/dist/core/export-html/template.js +1185 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked.min.js +6 -0
- package/dist/core/hooks/index.d.ts +4 -4
- package/dist/core/hooks/index.d.ts.map +1 -1
- package/dist/core/hooks/index.js +3 -3
- package/dist/core/hooks/index.js.map +1 -1
- package/dist/core/hooks/loader.d.ts +40 -5
- package/dist/core/hooks/loader.d.ts.map +1 -1
- package/dist/core/hooks/loader.js +43 -10
- package/dist/core/hooks/loader.js.map +1 -1
- package/dist/core/hooks/runner.d.ts +94 -18
- package/dist/core/hooks/runner.d.ts.map +1 -1
- package/dist/core/hooks/runner.js +199 -120
- package/dist/core/hooks/runner.js.map +1 -1
- package/dist/core/hooks/tool-wrapper.d.ts +1 -1
- package/dist/core/hooks/tool-wrapper.d.ts.map +1 -1
- package/dist/core/hooks/tool-wrapper.js +36 -19
- package/dist/core/hooks/tool-wrapper.js.map +1 -1
- package/dist/core/hooks/types.d.ts +407 -96
- package/dist/core/hooks/types.d.ts.map +1 -1
- package/dist/core/hooks/types.js.map +1 -1
- package/dist/core/index.d.ts +4 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/messages.d.ts +44 -12
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +82 -34
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-registry.d.ts +5 -5
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +7 -7
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +7 -7
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +45 -14
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/sdk.d.ts +7 -10
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +88 -32
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +202 -36
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +565 -133
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +9 -3
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +13 -12
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +6 -3
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +33 -0
- package/dist/core/tools/edit-diff.d.ts.map +1 -0
- package/dist/core/tools/edit-diff.js +171 -0
- package/dist/core/tools/edit-diff.js.map +1 -0
- 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 +20 -95
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +1 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/write.d.ts +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +22 -21
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +3 -4
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +6 -2
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.d.ts +12 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.js +30 -0
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +14 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.js +35 -0
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +14 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +36 -0
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +5 -1
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.js +5 -1
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +12 -6
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +57 -25
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/hook-editor.d.ts +15 -0
- package/dist/modes/interactive/components/hook-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/hook-editor.js +95 -0
- package/dist/modes/interactive/components/hook-editor.js.map +1 -0
- package/dist/modes/interactive/components/hook-message.d.ts +18 -0
- package/dist/modes/interactive/components/hook-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/hook-message.js +80 -0
- package/dist/modes/interactive/components/hook-message.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +3 -3
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +1 -1
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +15 -2
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +70 -21
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +52 -0
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector.js +745 -0
- package/dist/modes/interactive/components/tree-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +3 -3
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.js +1 -1
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +1 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +2 -5
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +29 -12
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +589 -208
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +13 -1
- package/dist/modes/interactive/theme/light.json +13 -1
- package/dist/modes/interactive/theme/theme-schema.json +34 -0
- package/dist/modes/interactive/theme/theme.d.ts +20 -2
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +135 -2
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts +3 -3
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +26 -20
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +13 -10
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +11 -10
- 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 +88 -35
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +30 -11
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/shell.d.ts +4 -2
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +36 -7
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/tools-manager.d.ts +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +2 -2
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/compaction.md +388 -0
- package/docs/custom-tools.md +146 -43
- package/docs/extension-loading.md +1004 -0
- package/docs/hooks.md +562 -596
- package/docs/rpc.md +33 -19
- package/docs/sdk.md +93 -21
- package/docs/session-tree-plan.md +441 -0
- package/docs/session.md +172 -21
- package/docs/skills.md +2 -0
- package/docs/theme.md +31 -2
- package/docs/tree.md +197 -0
- package/docs/tui.md +343 -0
- package/examples/README.md +1 -9
- package/examples/custom-tools/hello/index.ts +4 -3
- package/examples/custom-tools/question/index.ts +4 -4
- package/examples/custom-tools/subagent/index.ts +7 -6
- package/examples/custom-tools/todo/index.ts +11 -5
- package/examples/hooks/README.md +29 -71
- package/examples/hooks/auto-commit-on-exit.ts +8 -9
- package/examples/hooks/confirm-destructive.ts +29 -30
- package/examples/hooks/custom-compaction.ts +20 -21
- package/examples/hooks/dirty-repo-guard.ts +41 -40
- package/examples/hooks/file-trigger.ts +10 -5
- package/examples/hooks/git-checkpoint.ts +16 -12
- package/examples/hooks/handoff.ts +150 -0
- package/examples/hooks/permission-gate.ts +1 -1
- package/examples/hooks/protected-paths.ts +1 -1
- package/examples/hooks/qna.ts +119 -0
- package/examples/hooks/snake.ts +343 -0
- package/examples/hooks/status-line.ts +40 -0
- package/examples/sdk/01-minimal.ts +1 -1
- package/examples/sdk/02-custom-model.ts +1 -1
- package/examples/sdk/03-custom-prompt.ts +1 -1
- package/examples/sdk/04-skills.ts +1 -1
- package/examples/sdk/05-tools.ts +4 -4
- package/examples/sdk/06-hooks.ts +1 -1
- package/examples/sdk/07-context-files.ts +1 -1
- package/examples/sdk/08-slash-commands.ts +6 -1
- package/examples/sdk/09-api-keys-and-oauth.ts +1 -1
- package/examples/sdk/10-settings.ts +1 -1
- package/examples/sdk/11-sessions.ts +1 -1
- package/examples/sdk/12-full-control.ts +4 -7
- package/package.json +6 -6
- package/dist/core/compaction.d.ts.map +0 -1
- package/dist/core/compaction.js +0 -412
- package/dist/core/compaction.js.map +0 -1
- package/dist/core/export-html.d.ts +0 -23
- package/dist/core/export-html.d.ts.map +0 -1
- package/dist/core/export-html.js +0 -1185
- package/dist/core/export-html.js.map +0 -1
- package/dist/modes/interactive/components/compaction.d.ts +0 -15
- package/dist/modes/interactive/components/compaction.d.ts.map +0 -1
- package/dist/modes/interactive/components/compaction.js +0 -41
- package/dist/modes/interactive/components/compaction.js.map +0 -1
- package/docs/hooks-v2.md +0 -385
- package/docs/session-tree.md +0 -452
package/docs/rpc.md
CHANGED
|
@@ -36,9 +36,9 @@ Send a user prompt to the agent. Returns immediately; events stream asynchronous
|
|
|
36
36
|
{"id": "req-1", "type": "prompt", "message": "Hello, world!"}
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
With
|
|
39
|
+
With images:
|
|
40
40
|
```json
|
|
41
|
-
{"type": "prompt", "message": "What's in this image?", "
|
|
41
|
+
{"type": "prompt", "message": "What's in this image?", "images": [{"type": "image", "source": {"type": "base64", "mediaType": "image/png", "data": "..."}}]}
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
Response:
|
|
@@ -46,7 +46,7 @@ Response:
|
|
|
46
46
|
{"id": "req-1", "type": "response", "command": "prompt", "success": true}
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
The `
|
|
49
|
+
The `images` field is optional. Each image uses `ImageContent` format with base64 or URL source.
|
|
50
50
|
|
|
51
51
|
#### queue_message
|
|
52
52
|
|
|
@@ -76,22 +76,27 @@ Response:
|
|
|
76
76
|
{"type": "response", "command": "abort", "success": true}
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
####
|
|
79
|
+
#### new_session
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
Start a fresh session. Can be cancelled by a `session_before_switch` hook.
|
|
82
82
|
|
|
83
83
|
```json
|
|
84
|
-
{"type": "
|
|
84
|
+
{"type": "new_session"}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
With optional parent session tracking:
|
|
88
|
+
```json
|
|
89
|
+
{"type": "new_session", "parentSession": "/path/to/parent-session.jsonl"}
|
|
85
90
|
```
|
|
86
91
|
|
|
87
92
|
Response:
|
|
88
93
|
```json
|
|
89
|
-
{"type": "response", "command": "
|
|
94
|
+
{"type": "response", "command": "new_session", "success": true, "data": {"cancelled": false}}
|
|
90
95
|
```
|
|
91
96
|
|
|
92
|
-
If a hook cancelled
|
|
97
|
+
If a hook cancelled:
|
|
93
98
|
```json
|
|
94
|
-
{"type": "response", "command": "
|
|
99
|
+
{"type": "response", "command": "new_session", "success": true, "data": {"cancelled": true}}
|
|
95
100
|
```
|
|
96
101
|
|
|
97
102
|
### State
|
|
@@ -145,7 +150,7 @@ Response:
|
|
|
145
150
|
}
|
|
146
151
|
```
|
|
147
152
|
|
|
148
|
-
Messages are `
|
|
153
|
+
Messages are `AgentMessage` objects (see [Message Types](#message-types)).
|
|
149
154
|
|
|
150
155
|
### Model
|
|
151
156
|
|
|
@@ -289,8 +294,10 @@ Response:
|
|
|
289
294
|
"command": "compact",
|
|
290
295
|
"success": true,
|
|
291
296
|
"data": {
|
|
297
|
+
"summary": "Summary of conversation...",
|
|
298
|
+
"firstKeptEntryId": "abc123",
|
|
292
299
|
"tokensBefore": 150000,
|
|
293
|
-
"
|
|
300
|
+
"details": {}
|
|
294
301
|
}
|
|
295
302
|
}
|
|
296
303
|
```
|
|
@@ -491,7 +498,7 @@ If a hook cancelled the switch:
|
|
|
491
498
|
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.
|
|
492
499
|
|
|
493
500
|
```json
|
|
494
|
-
{"type": "branch", "
|
|
501
|
+
{"type": "branch", "entryId": "abc123"}
|
|
495
502
|
```
|
|
496
503
|
|
|
497
504
|
Response:
|
|
@@ -530,8 +537,8 @@ Response:
|
|
|
530
537
|
"success": true,
|
|
531
538
|
"data": {
|
|
532
539
|
"messages": [
|
|
533
|
-
{"
|
|
534
|
-
{"
|
|
540
|
+
{"entryId": "abc123", "text": "First prompt..."},
|
|
541
|
+
{"entryId": "def456", "text": "Second prompt..."}
|
|
535
542
|
]
|
|
536
543
|
}
|
|
537
544
|
}
|
|
@@ -618,7 +625,7 @@ A turn consists of one assistant response plus any resulting tool calls and resu
|
|
|
618
625
|
|
|
619
626
|
### message_start / message_end
|
|
620
627
|
|
|
621
|
-
Emitted when a message begins and completes. The `message` field contains an `
|
|
628
|
+
Emitted when a message begins and completes. The `message` field contains an `AgentMessage`.
|
|
622
629
|
|
|
623
630
|
```json
|
|
624
631
|
{"type": "message_start", "message": {...}}
|
|
@@ -717,20 +724,27 @@ Use `toolCallId` to correlate events. The `partialResult` in `tool_execution_upd
|
|
|
717
724
|
Emitted when automatic compaction runs (when context is nearly full).
|
|
718
725
|
|
|
719
726
|
```json
|
|
720
|
-
{"type": "auto_compaction_start"}
|
|
727
|
+
{"type": "auto_compaction_start", "reason": "threshold"}
|
|
721
728
|
```
|
|
722
729
|
|
|
730
|
+
The `reason` field is `"threshold"` (context getting large) or `"overflow"` (context exceeded limit).
|
|
731
|
+
|
|
723
732
|
```json
|
|
724
733
|
{
|
|
725
734
|
"type": "auto_compaction_end",
|
|
726
735
|
"result": {
|
|
736
|
+
"summary": "Summary of conversation...",
|
|
737
|
+
"firstKeptEntryId": "abc123",
|
|
727
738
|
"tokensBefore": 150000,
|
|
728
|
-
"
|
|
739
|
+
"details": {}
|
|
729
740
|
},
|
|
730
|
-
"aborted": false
|
|
741
|
+
"aborted": false,
|
|
742
|
+
"willRetry": false
|
|
731
743
|
}
|
|
732
744
|
```
|
|
733
745
|
|
|
746
|
+
If `reason` was `"overflow"` and compaction succeeds, `willRetry` is `true` and the agent will automatically retry the prompt.
|
|
747
|
+
|
|
734
748
|
If compaction was aborted, `result` is `null` and `aborted` is `true`.
|
|
735
749
|
|
|
736
750
|
### auto_retry_start / auto_retry_end
|
|
@@ -806,7 +820,7 @@ Parse errors:
|
|
|
806
820
|
|
|
807
821
|
Source files:
|
|
808
822
|
- [`packages/ai/src/types.ts`](../../ai/src/types.ts) - `Model`, `UserMessage`, `AssistantMessage`, `ToolResultMessage`
|
|
809
|
-
- [`packages/agent/src/types.ts`](../../agent/src/types.ts) - `
|
|
823
|
+
- [`packages/agent/src/types.ts`](../../agent/src/types.ts) - `AgentMessage`, `AgentEvent`
|
|
810
824
|
- [`src/core/messages.ts`](../src/core/messages.ts) - `BashExecutionMessage`
|
|
811
825
|
- [`src/modes/rpc/rpc-types.ts`](../src/modes/rpc/rpc-types.ts) - RPC command/response types
|
|
812
826
|
|
package/docs/sdk.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> pi can help you use the SDK. Ask it to build an integration for your use case.
|
|
2
|
+
|
|
1
3
|
# SDK
|
|
2
4
|
|
|
3
5
|
The SDK provides programmatic access to pi's agent capabilities. Use it to embed pi in other applications, build custom interfaces, or integrate with automated workflows.
|
|
@@ -81,26 +83,32 @@ interface AgentSession {
|
|
|
81
83
|
subscribe(listener: (event: AgentSessionEvent) => void): () => void;
|
|
82
84
|
|
|
83
85
|
// Session info
|
|
84
|
-
sessionFile: string |
|
|
86
|
+
sessionFile: string | undefined; // undefined for in-memory
|
|
85
87
|
sessionId: string;
|
|
86
88
|
|
|
87
89
|
// Model control
|
|
88
90
|
setModel(model: Model): Promise<void>;
|
|
89
91
|
setThinkingLevel(level: ThinkingLevel): void;
|
|
90
|
-
cycleModel(): Promise<ModelCycleResult |
|
|
91
|
-
cycleThinkingLevel(): ThinkingLevel |
|
|
92
|
+
cycleModel(): Promise<ModelCycleResult | undefined>;
|
|
93
|
+
cycleThinkingLevel(): ThinkingLevel | undefined;
|
|
92
94
|
|
|
93
95
|
// State access
|
|
94
96
|
agent: Agent;
|
|
95
|
-
model: Model |
|
|
97
|
+
model: Model | undefined;
|
|
96
98
|
thinkingLevel: ThinkingLevel;
|
|
97
|
-
messages:
|
|
99
|
+
messages: AgentMessage[];
|
|
98
100
|
isStreaming: boolean;
|
|
99
101
|
|
|
100
102
|
// Session management
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
newSession(options?: { parentSession?: string }): Promise<boolean>; // Returns false if cancelled by hook
|
|
104
|
+
switchSession(sessionPath: string): Promise<boolean>;
|
|
105
|
+
|
|
106
|
+
// Branching
|
|
107
|
+
branch(entryId: string): Promise<{ selectedText: string; cancelled: boolean }>; // Creates new session file
|
|
108
|
+
navigateTree(targetId: string, options?: { summarize?: boolean }): Promise<{ editorText?: string; cancelled: boolean }>; // In-place navigation
|
|
109
|
+
|
|
110
|
+
// Hook message injection
|
|
111
|
+
sendHookMessage(message: HookMessage, triggerTurn?: boolean): Promise<void>;
|
|
104
112
|
|
|
105
113
|
// Compaction
|
|
106
114
|
compact(customInstructions?: string): Promise<CompactionResult>;
|
|
@@ -122,7 +130,7 @@ The `Agent` class (from `@mariozechner/pi-agent-core`) handles the core LLM inte
|
|
|
122
130
|
// Access current state
|
|
123
131
|
const state = session.agent.state;
|
|
124
132
|
|
|
125
|
-
// state.messages:
|
|
133
|
+
// state.messages: AgentMessage[] - conversation history
|
|
126
134
|
// state.model: Model - current model
|
|
127
135
|
// state.thinkingLevel: ThinkingLevel - current thinking level
|
|
128
136
|
// state.systemPrompt: string - system prompt
|
|
@@ -394,10 +402,10 @@ const { session } = await createAgentSession({
|
|
|
394
402
|
|
|
395
403
|
```typescript
|
|
396
404
|
import { Type } from "@sinclair/typebox";
|
|
397
|
-
import { createAgentSession, discoverCustomTools, type
|
|
405
|
+
import { createAgentSession, discoverCustomTools, type CustomTool } from "@mariozechner/pi-coding-agent";
|
|
398
406
|
|
|
399
407
|
// Inline custom tool
|
|
400
|
-
const myTool:
|
|
408
|
+
const myTool: CustomTool = {
|
|
401
409
|
name: "my_tool",
|
|
402
410
|
label: "My Tool",
|
|
403
411
|
description: "Does something useful",
|
|
@@ -436,18 +444,38 @@ import { createAgentSession, discoverHooks, type HookFactory } from "@mariozechn
|
|
|
436
444
|
|
|
437
445
|
// Inline hook
|
|
438
446
|
const loggingHook: HookFactory = (api) => {
|
|
447
|
+
// Log tool calls
|
|
439
448
|
api.on("tool_call", async (event) => {
|
|
440
449
|
console.log(`Tool: ${event.toolName}`);
|
|
441
450
|
return undefined; // Don't block
|
|
442
451
|
});
|
|
443
452
|
|
|
453
|
+
// Block dangerous commands
|
|
444
454
|
api.on("tool_call", async (event) => {
|
|
445
|
-
// Block dangerous commands
|
|
446
455
|
if (event.toolName === "bash" && event.input.command?.includes("rm -rf")) {
|
|
447
456
|
return { block: true, reason: "Dangerous command" };
|
|
448
457
|
}
|
|
449
458
|
return undefined;
|
|
450
459
|
});
|
|
460
|
+
|
|
461
|
+
// Register custom slash command
|
|
462
|
+
api.registerCommand("stats", {
|
|
463
|
+
description: "Show session stats",
|
|
464
|
+
handler: async (ctx) => {
|
|
465
|
+
const entries = ctx.sessionManager.getEntries();
|
|
466
|
+
ctx.ui.notify(`${entries.length} entries`, "info");
|
|
467
|
+
},
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
// Inject messages
|
|
471
|
+
api.sendMessage({
|
|
472
|
+
customType: "my-hook",
|
|
473
|
+
content: "Hook initialized",
|
|
474
|
+
display: false, // Hidden from TUI
|
|
475
|
+
}, false); // Don't trigger agent turn
|
|
476
|
+
|
|
477
|
+
// Persist hook state
|
|
478
|
+
api.appendEntry("my-hook", { initialized: true });
|
|
451
479
|
};
|
|
452
480
|
|
|
453
481
|
// Replace discovery
|
|
@@ -472,7 +500,15 @@ const { session } = await createAgentSession({
|
|
|
472
500
|
});
|
|
473
501
|
```
|
|
474
502
|
|
|
475
|
-
|
|
503
|
+
Hook API methods:
|
|
504
|
+
- `api.on(event, handler)` - Subscribe to events
|
|
505
|
+
- `api.sendMessage(message, triggerTurn?)` - Inject message (creates `CustomMessageEntry`)
|
|
506
|
+
- `api.appendEntry(customType, data?)` - Persist hook state (not in LLM context)
|
|
507
|
+
- `api.registerCommand(name, options)` - Register custom slash command
|
|
508
|
+
- `api.registerMessageRenderer(customType, renderer)` - Custom TUI rendering
|
|
509
|
+
- `api.exec(command, args, options?)` - Execute shell commands
|
|
510
|
+
|
|
511
|
+
> See [examples/sdk/06-hooks.ts](../examples/sdk/06-hooks.ts) and [docs/hooks.md](hooks.md)
|
|
476
512
|
|
|
477
513
|
### Skills
|
|
478
514
|
|
|
@@ -560,6 +596,8 @@ const { session } = await createAgentSession({
|
|
|
560
596
|
|
|
561
597
|
### Session Management
|
|
562
598
|
|
|
599
|
+
Sessions use a tree structure with `id`/`parentId` linking, enabling in-place branching.
|
|
600
|
+
|
|
563
601
|
```typescript
|
|
564
602
|
import { createAgentSession, SessionManager } from "@mariozechner/pi-coding-agent";
|
|
565
603
|
|
|
@@ -597,12 +635,32 @@ const customDir = "/path/to/my-sessions";
|
|
|
597
635
|
const { session } = await createAgentSession({
|
|
598
636
|
sessionManager: SessionManager.create(process.cwd(), customDir),
|
|
599
637
|
});
|
|
600
|
-
// Also works with list and continueRecent:
|
|
601
|
-
// SessionManager.list(process.cwd(), customDir);
|
|
602
|
-
// SessionManager.continueRecent(process.cwd(), customDir);
|
|
603
638
|
```
|
|
604
639
|
|
|
605
|
-
|
|
640
|
+
**SessionManager tree API:**
|
|
641
|
+
|
|
642
|
+
```typescript
|
|
643
|
+
const sm = SessionManager.open("/path/to/session.jsonl");
|
|
644
|
+
|
|
645
|
+
// Tree traversal
|
|
646
|
+
const entries = sm.getEntries(); // All entries (excludes header)
|
|
647
|
+
const tree = sm.getTree(); // Full tree structure
|
|
648
|
+
const path = sm.getPath(); // Path from root to current leaf
|
|
649
|
+
const leaf = sm.getLeafEntry(); // Current leaf entry
|
|
650
|
+
const entry = sm.getEntry(id); // Get entry by ID
|
|
651
|
+
const children = sm.getChildren(id); // Direct children of entry
|
|
652
|
+
|
|
653
|
+
// Labels
|
|
654
|
+
const label = sm.getLabel(id); // Get label for entry
|
|
655
|
+
sm.appendLabelChange(id, "checkpoint"); // Set label
|
|
656
|
+
|
|
657
|
+
// Branching
|
|
658
|
+
sm.branch(entryId); // Move leaf to earlier entry
|
|
659
|
+
sm.branchWithSummary(id, "Summary..."); // Branch with context summary
|
|
660
|
+
sm.createBranchedSession(leafId); // Extract path to new file
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
> See [examples/sdk/11-sessions.ts](../examples/sdk/11-sessions.ts) and [docs/session.md](session.md)
|
|
606
664
|
|
|
607
665
|
### Settings Management
|
|
608
666
|
|
|
@@ -737,7 +795,7 @@ import {
|
|
|
737
795
|
readTool,
|
|
738
796
|
bashTool,
|
|
739
797
|
type HookFactory,
|
|
740
|
-
type
|
|
798
|
+
type CustomTool,
|
|
741
799
|
} from "@mariozechner/pi-coding-agent";
|
|
742
800
|
|
|
743
801
|
// Set up auth storage (custom location)
|
|
@@ -760,7 +818,7 @@ const auditHook: HookFactory = (api) => {
|
|
|
760
818
|
};
|
|
761
819
|
|
|
762
820
|
// Inline tool
|
|
763
|
-
const statusTool:
|
|
821
|
+
const statusTool: CustomTool = {
|
|
764
822
|
name: "status",
|
|
765
823
|
label: "Status",
|
|
766
824
|
description: "Get system status",
|
|
@@ -876,7 +934,7 @@ createGrepTool, createFindTool, createLsTool
|
|
|
876
934
|
// Types
|
|
877
935
|
type CreateAgentSessionOptions
|
|
878
936
|
type CreateAgentSessionResult
|
|
879
|
-
type
|
|
937
|
+
type CustomTool
|
|
880
938
|
type HookFactory
|
|
881
939
|
type Skill
|
|
882
940
|
type FileSlashCommand
|
|
@@ -888,7 +946,21 @@ type Tool
|
|
|
888
946
|
For hook types, import from the hooks subpath:
|
|
889
947
|
|
|
890
948
|
```typescript
|
|
891
|
-
import type {
|
|
949
|
+
import type {
|
|
950
|
+
HookAPI,
|
|
951
|
+
HookMessage,
|
|
952
|
+
HookFactory,
|
|
953
|
+
HookEventContext,
|
|
954
|
+
HookCommandContext,
|
|
955
|
+
ToolCallEvent,
|
|
956
|
+
ToolResultEvent,
|
|
957
|
+
} from "@mariozechner/pi-coding-agent/hooks";
|
|
958
|
+
```
|
|
959
|
+
|
|
960
|
+
For message utilities:
|
|
961
|
+
|
|
962
|
+
```typescript
|
|
963
|
+
import { isHookMessage, createHookMessage } from "@mariozechner/pi-coding-agent";
|
|
892
964
|
```
|
|
893
965
|
|
|
894
966
|
For config utilities:
|