@draht/coding-agent 2026.4.5 → 2026.4.23
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 +790 -625
- package/README.md +105 -96
- package/dist/cli/args.d.ts +7 -10
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +42 -44
- package/dist/cli/args.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1 -0
- package/dist/cli.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-runtime.d.ts +53 -106
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +116 -147
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +86 -0
- package/dist/core/agent-session-services.d.ts.map +1 -0
- package/dist/core/agent-session-services.js +116 -0
- package/dist/core/agent-session-services.js.map +1 -0
- package/dist/core/agent-session.d.ts +4 -12
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +122 -43
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +19 -7
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +1 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +18 -17
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +7 -7
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +4 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +15 -14
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybindings.d.ts +14 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +13 -14
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +30 -1
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/package-manager.d.ts +21 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +108 -43
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +1 -22
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/resource-loader.d.ts +0 -2
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +26 -8
- package/dist/core/resource-loader.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 +2 -2
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-cwd.d.ts +19 -0
- package/dist/core/session-cwd.d.ts.map +1 -0
- package/dist/core/session-cwd.js +38 -0
- package/dist/core/session-cwd.js.map +1 -0
- package/dist/core/session-manager.d.ts +5 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +16 -8
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +3 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +5 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +3 -3
- package/dist/core/skills.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +6 -6
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/timings.d.ts +1 -0
- package/dist/core/timings.d.ts.map +1 -1
- package/dist/core/timings.js +6 -0
- package/dist/core/timings.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +19 -9
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +23 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +150 -57
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts +13 -11
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +55 -77
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +4 -4
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/index.d.ts +9 -6
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +2 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +248 -450
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts +3 -3
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +25 -5
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +3 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +14 -3
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
- package/dist/modes/interactive/components/earendil-announcement.js +40 -0
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +0 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +2 -7
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +4 -2
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +48 -15
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +12 -3
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +220 -124
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +9 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts +4 -4
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +6 -2
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +1 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +2 -2
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +26 -15
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts +4 -0
- package/dist/package-manager-cli.d.ts.map +1 -0
- package/dist/package-manager-cli.js +234 -0
- package/dist/package-manager-cli.js.map +1 -0
- package/dist/prompts/commands/atomic-commit.md +17 -0
- package/dist/prompts/commands/discuss-phase.md +15 -0
- package/dist/prompts/commands/execute-phase.md +14 -0
- package/dist/prompts/commands/fix.md +14 -0
- package/dist/prompts/commands/init-project.md +16 -0
- package/dist/prompts/commands/map-codebase.md +16 -0
- package/dist/prompts/commands/new-project.md +16 -0
- package/dist/prompts/commands/next-milestone.md +16 -0
- package/dist/prompts/commands/pause-work.md +13 -0
- package/dist/prompts/commands/plan-phase.md +15 -0
- package/dist/prompts/commands/progress.md +13 -0
- package/dist/prompts/commands/quick.md +14 -0
- package/dist/prompts/commands/resume-work.md +13 -0
- package/dist/prompts/commands/review.md +15 -0
- package/dist/prompts/commands/verify-work.md +15 -0
- package/dist/utils/paths.d.ts +7 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +19 -0
- package/dist/utils/paths.js.map +1 -0
- package/docs/compaction.md +5 -3
- package/docs/custom-provider.md +1 -1
- package/docs/development.md +3 -1
- package/docs/extensions.md +150 -54
- package/docs/json.md +5 -2
- package/docs/keybindings.md +2 -0
- package/docs/models.md +55 -4
- package/docs/rpc.md +21 -7
- package/docs/sdk.md +116 -48
- package/docs/session.md +3 -3
- package/docs/settings.md +12 -0
- package/docs/skills.md +3 -2
- package/docs/tree.md +5 -2
- package/examples/README.md +1 -1
- package/examples/extensions/README.md +1 -0
- package/examples/extensions/antigravity-image-gen.ts +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +1 -1
- package/examples/extensions/doom-overlay/doom/build.sh +2 -2
- package/examples/extensions/hidden-thinking-label.ts +53 -0
- package/examples/extensions/overlay-qa-tests.ts +2 -2
- package/examples/extensions/sandbox/index.ts +8 -4
- package/examples/extensions/subagent/index.ts +5 -5
- package/examples/extensions/trigger-compact.ts +11 -1
- package/examples/sdk/13-session-runtime.ts +30 -12
- package/examples/sdk/README.md +4 -2
- package/package.json +7 -8
- package/prompts/commands/atomic-commit.md +17 -0
- package/prompts/commands/discuss-phase.md +15 -0
- package/prompts/commands/execute-phase.md +14 -0
- package/prompts/commands/fix.md +14 -0
- package/prompts/commands/init-project.md +16 -0
- package/prompts/commands/map-codebase.md +16 -0
- package/prompts/commands/new-project.md +16 -0
- package/prompts/commands/next-milestone.md +16 -0
- package/prompts/commands/pause-work.md +13 -0
- package/prompts/commands/plan-phase.md +15 -0
- package/prompts/commands/progress.md +13 -0
- package/prompts/commands/quick.md +14 -0
- package/prompts/commands/resume-work.md +13 -0
- package/prompts/commands/review.md +15 -0
- package/prompts/commands/verify-work.md +15 -0
package/docs/json.md
CHANGED
|
@@ -13,12 +13,15 @@ Events are defined in [`AgentSessionEvent`](https://github.com/draht-dev/draht/b
|
|
|
13
13
|
```typescript
|
|
14
14
|
type AgentSessionEvent =
|
|
15
15
|
| AgentEvent
|
|
16
|
-
| { type: "
|
|
17
|
-
| { type: "
|
|
16
|
+
| { type: "queue_update"; steering: readonly string[]; followUp: readonly string[] }
|
|
17
|
+
| { type: "compaction_start"; reason: "manual" | "threshold" | "overflow" }
|
|
18
|
+
| { type: "compaction_end"; reason: "manual" | "threshold" | "overflow"; result: CompactionResult | undefined; aborted: boolean; willRetry: boolean; errorMessage?: string }
|
|
18
19
|
| { type: "auto_retry_start"; attempt: number; maxAttempts: number; delayMs: number; errorMessage: string }
|
|
19
20
|
| { type: "auto_retry_end"; success: boolean; attempt: number; finalError?: string };
|
|
20
21
|
```
|
|
21
22
|
|
|
23
|
+
`queue_update` emits the full pending steering and follow-up queues whenever they change. `compaction_start` and `compaction_end` cover both manual and automatic compaction.
|
|
24
|
+
|
|
22
25
|
Base events from [`AgentEvent`](https://github.com/draht-dev/draht/blob/main/packages/agent/src/types.ts#L179):
|
|
23
26
|
|
|
24
27
|
```typescript
|
package/docs/keybindings.md
CHANGED
|
@@ -128,6 +128,8 @@ Modifier combinations: `ctrl+shift+x`, `alt+ctrl+x`, `ctrl+shift+alt+x`, `ctrl+1
|
|
|
128
128
|
|--------|---------|-------------|
|
|
129
129
|
| `app.tree.foldOrUp` | `ctrl+left`, `alt+left` | Fold current branch segment, or jump to the previous segment start |
|
|
130
130
|
| `app.tree.unfoldOrDown` | `ctrl+right`, `alt+right` | Unfold current branch segment, or jump to the next segment start or branch end |
|
|
131
|
+
| `app.tree.editLabel` | `shift+l` | Edit the label on the selected tree node |
|
|
132
|
+
| `app.tree.toggleLabelTimestamp` | `shift+t` | Toggle label timestamps in the tree |
|
|
131
133
|
|
|
132
134
|
## Custom Configuration
|
|
133
135
|
|
package/docs/models.md
CHANGED
|
@@ -90,6 +90,33 @@ Override defaults when you need specific values:
|
|
|
90
90
|
|
|
91
91
|
The file reloads each time you open `/model`. Edit during session; no restart needed.
|
|
92
92
|
|
|
93
|
+
## Google AI Studio Example
|
|
94
|
+
|
|
95
|
+
Use `google-generative-ai` with a `baseUrl` to add models from Google AI Studio, including custom Gemma 4 entries:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"providers": {
|
|
100
|
+
"my-google": {
|
|
101
|
+
"baseUrl": "https://generativelanguage.googleapis.com/v1beta",
|
|
102
|
+
"api": "google-generative-ai",
|
|
103
|
+
"apiKey": "GEMINI_API_KEY",
|
|
104
|
+
"models": [
|
|
105
|
+
{
|
|
106
|
+
"id": "gemma-4-31b-it",
|
|
107
|
+
"name": "Gemma 4 31B",
|
|
108
|
+
"input": ["text", "image"],
|
|
109
|
+
"contextWindow": 262144,
|
|
110
|
+
"reasoning": true
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The `baseUrl` is required when adding custom models to the `google-generative-ai` API type.
|
|
119
|
+
|
|
93
120
|
## Supported APIs
|
|
94
121
|
|
|
95
122
|
| API | Description |
|
|
@@ -131,7 +158,7 @@ The `apiKey` and `headers` fields support three formats:
|
|
|
131
158
|
"apiKey": "sk-..."
|
|
132
159
|
```
|
|
133
160
|
|
|
134
|
-
For `models.json`, shell commands are resolved at request time.
|
|
161
|
+
For `models.json`, shell commands are resolved at request time. pi intentionally does not apply built-in TTL, stale reuse, or recovery logic for arbitrary commands. Different commands need different caching and failure strategies, and pi cannot infer the right one.
|
|
135
162
|
|
|
136
163
|
If your command is slow, expensive, rate-limited, or should keep using a previous value on transient failures, wrap it in your own script or command that implements the caching or TTL behavior you want.
|
|
137
164
|
|
|
@@ -278,7 +305,7 @@ For providers with partial OpenAI compatibility, use the `compat` field.
|
|
|
278
305
|
| `requiresThinkingAsText` | Convert thinking blocks to plain text |
|
|
279
306
|
| `thinkingFormat` | Use `reasoning_effort`, `zai`, `qwen`, or `qwen-chat-template` thinking parameters |
|
|
280
307
|
| `supportsStrictMode` | Include the `strict` field in tool definitions |
|
|
281
|
-
| `openRouterRouting` | OpenRouter routing
|
|
308
|
+
| `openRouterRouting` | OpenRouter provider routing preferences. This object is sent as-is in the `provider` field of the [OpenRouter API request](https://openrouter.ai/docs/guides/routing/provider-selection). |
|
|
282
309
|
| `vercelGatewayRouting` | Vercel AI Gateway routing config for provider selection (`only`, `order`) |
|
|
283
310
|
|
|
284
311
|
`qwen` uses top-level `enable_thinking`. Use `qwen-chat-template` for local Qwen-compatible servers that require `chat_template_kwargs.enable_thinking`.
|
|
@@ -298,8 +325,32 @@ Example:
|
|
|
298
325
|
"name": "OpenRouter Claude 3.5 Sonnet",
|
|
299
326
|
"compat": {
|
|
300
327
|
"openRouterRouting": {
|
|
301
|
-
"
|
|
302
|
-
"
|
|
328
|
+
"allow_fallbacks": true,
|
|
329
|
+
"require_parameters": false,
|
|
330
|
+
"data_collection": "deny",
|
|
331
|
+
"zdr": true,
|
|
332
|
+
"enforce_distillable_text": false,
|
|
333
|
+
"order": ["anthropic", "amazon-bedrock", "google-vertex"],
|
|
334
|
+
"only": ["anthropic", "amazon-bedrock"],
|
|
335
|
+
"ignore": ["gmicloud", "friendli"],
|
|
336
|
+
"quantizations": ["fp16", "bf16"],
|
|
337
|
+
"sort": {
|
|
338
|
+
"by": "price",
|
|
339
|
+
"partition": "model"
|
|
340
|
+
},
|
|
341
|
+
"max_price": {
|
|
342
|
+
"prompt": 10,
|
|
343
|
+
"completion": 20
|
|
344
|
+
},
|
|
345
|
+
"preferred_min_throughput": {
|
|
346
|
+
"p50": 100,
|
|
347
|
+
"p90": 50
|
|
348
|
+
},
|
|
349
|
+
"preferred_max_latency": {
|
|
350
|
+
"p50": 1,
|
|
351
|
+
"p90": 3,
|
|
352
|
+
"p99": 5
|
|
353
|
+
}
|
|
303
354
|
}
|
|
304
355
|
}
|
|
305
356
|
}
|
package/docs/rpc.md
CHANGED
|
@@ -725,8 +725,9 @@ Events are streamed to stdout as JSON lines during agent operation. Events do NO
|
|
|
725
725
|
| `tool_execution_start` | Tool begins execution |
|
|
726
726
|
| `tool_execution_update` | Tool execution progress (streaming output) |
|
|
727
727
|
| `tool_execution_end` | Tool completes |
|
|
728
|
-
| `
|
|
729
|
-
| `
|
|
728
|
+
| `queue_update` | Pending steering/follow-up queue changed |
|
|
729
|
+
| `compaction_start` | Compaction begins |
|
|
730
|
+
| `compaction_end` | Compaction completes |
|
|
730
731
|
| `auto_retry_start` | Auto-retry begins (after transient error) |
|
|
731
732
|
| `auto_retry_end` | Auto-retry completes (success or final failure) |
|
|
732
733
|
| `extension_error` | Extension threw an error |
|
|
@@ -862,19 +863,32 @@ When complete:
|
|
|
862
863
|
|
|
863
864
|
Use `toolCallId` to correlate events. The `partialResult` in `tool_execution_update` contains the accumulated output so far (not just the delta), allowing clients to simply replace their display on each update.
|
|
864
865
|
|
|
865
|
-
###
|
|
866
|
+
### queue_update
|
|
866
867
|
|
|
867
|
-
Emitted
|
|
868
|
+
Emitted whenever the pending steering or follow-up queue changes.
|
|
868
869
|
|
|
869
870
|
```json
|
|
870
|
-
{
|
|
871
|
+
{
|
|
872
|
+
"type": "queue_update",
|
|
873
|
+
"steering": ["Focus on error handling"],
|
|
874
|
+
"followUp": ["After that, summarize the result"]
|
|
875
|
+
}
|
|
876
|
+
```
|
|
877
|
+
|
|
878
|
+
### compaction_start / compaction_end
|
|
879
|
+
|
|
880
|
+
Emitted when compaction runs, whether manual or automatic.
|
|
881
|
+
|
|
882
|
+
```json
|
|
883
|
+
{"type": "compaction_start", "reason": "threshold"}
|
|
871
884
|
```
|
|
872
885
|
|
|
873
|
-
The `reason` field is `"threshold"
|
|
886
|
+
The `reason` field is `"manual"`, `"threshold"`, or `"overflow"`.
|
|
874
887
|
|
|
875
888
|
```json
|
|
876
889
|
{
|
|
877
|
-
"type": "
|
|
890
|
+
"type": "compaction_end",
|
|
891
|
+
"reason": "threshold",
|
|
878
892
|
"result": {
|
|
879
893
|
"summary": "Summary of conversation...",
|
|
880
894
|
"firstKeptEntryId": "abc123",
|
package/docs/sdk.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
>
|
|
1
|
+
> pi can help you use the SDK. Ask it to build an integration for your use case.
|
|
2
2
|
|
|
3
3
|
# SDK
|
|
4
4
|
|
|
5
|
-
The SDK provides programmatic access to
|
|
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.
|
|
6
6
|
|
|
7
7
|
**Example use cases:**
|
|
8
8
|
- Build a custom UI (web, desktop, mobile)
|
|
@@ -115,33 +115,46 @@ interface AgentSession {
|
|
|
115
115
|
}
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
-
Session replacement APIs such as new-session, resume, fork, and import live on `
|
|
118
|
+
Session replacement APIs such as new-session, resume, fork, and import live on `AgentSessionRuntime`, not on `AgentSession`.
|
|
119
119
|
|
|
120
|
-
### createAgentSessionRuntime() and
|
|
120
|
+
### createAgentSessionRuntime() and AgentSessionRuntime
|
|
121
121
|
|
|
122
122
|
Use the runtime API when you need to replace the active session and rebuild cwd-bound runtime state.
|
|
123
123
|
This is the same layer used by the built-in interactive, print, and RPC modes.
|
|
124
124
|
|
|
125
|
+
`createAgentSessionRuntime()` takes a runtime factory plus the initial cwd/session target. The factory closes over process-global fixed inputs, recreates cwd-bound services for the effective cwd, resolves session options against those services, and returns a full runtime result.
|
|
126
|
+
|
|
125
127
|
```typescript
|
|
126
128
|
import {
|
|
127
|
-
|
|
129
|
+
type CreateAgentSessionRuntimeFactory,
|
|
130
|
+
createAgentSessionFromServices,
|
|
128
131
|
createAgentSessionRuntime,
|
|
132
|
+
createAgentSessionServices,
|
|
133
|
+
getAgentDir,
|
|
129
134
|
SessionManager,
|
|
130
135
|
} from "@draht/coding-agent";
|
|
131
136
|
|
|
132
|
-
const
|
|
133
|
-
|
|
137
|
+
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
138
|
+
const services = await createAgentSessionServices({ cwd });
|
|
139
|
+
return {
|
|
140
|
+
...(await createAgentSessionFromServices({
|
|
141
|
+
services,
|
|
142
|
+
sessionManager,
|
|
143
|
+
sessionStartEvent,
|
|
144
|
+
})),
|
|
145
|
+
services,
|
|
146
|
+
diagnostics: services.diagnostics,
|
|
147
|
+
};
|
|
134
148
|
};
|
|
135
149
|
|
|
136
|
-
const runtime = await createAgentSessionRuntime(
|
|
150
|
+
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
137
151
|
cwd: process.cwd(),
|
|
152
|
+
agentDir: getAgentDir(),
|
|
138
153
|
sessionManager: SessionManager.create(process.cwd()),
|
|
139
154
|
});
|
|
140
|
-
|
|
141
|
-
const runtimeHost = new AgentSessionRuntimeHost(bootstrap, runtime);
|
|
142
155
|
```
|
|
143
156
|
|
|
144
|
-
`
|
|
157
|
+
`AgentSessionRuntime` owns replacement of the active runtime across:
|
|
145
158
|
|
|
146
159
|
- `newSession()`
|
|
147
160
|
- `switchSession()`
|
|
@@ -150,18 +163,20 @@ const runtimeHost = new AgentSessionRuntimeHost(bootstrap, runtime);
|
|
|
150
163
|
|
|
151
164
|
Important behavior:
|
|
152
165
|
|
|
153
|
-
- `
|
|
166
|
+
- `runtime.session` changes after those operations
|
|
154
167
|
- event subscriptions are attached to a specific `AgentSession`, so re-subscribe after replacement
|
|
155
|
-
- if you use extensions, call `
|
|
168
|
+
- if you use extensions, call `runtime.session.bindExtensions(...)` again for the new session
|
|
169
|
+
- creation returns diagnostics on `runtime.diagnostics`
|
|
170
|
+
- if runtime creation or replacement fails, the method throws and the caller decides how to handle it
|
|
156
171
|
|
|
157
172
|
```typescript
|
|
158
|
-
let session =
|
|
173
|
+
let session = runtime.session;
|
|
159
174
|
let unsubscribe = session.subscribe(() => {});
|
|
160
175
|
|
|
161
|
-
await
|
|
176
|
+
await runtime.newSession();
|
|
162
177
|
|
|
163
178
|
unsubscribe();
|
|
164
|
-
session =
|
|
179
|
+
session = runtime.session;
|
|
165
180
|
unsubscribe = session.subscribe(() => {});
|
|
166
181
|
```
|
|
167
182
|
|
|
@@ -202,7 +217,7 @@ Both `steer()` and `followUp()` expand file-based prompt templates but error on
|
|
|
202
217
|
|
|
203
218
|
### Agent and AgentState
|
|
204
219
|
|
|
205
|
-
The `Agent` class (from `@draht/agent-core
|
|
220
|
+
The `Agent` class (from `@draht/agent-core`) handles the core LLM interaction. Access it via `session.agent`.
|
|
206
221
|
|
|
207
222
|
```typescript
|
|
208
223
|
// Access current state
|
|
@@ -212,10 +227,15 @@ const state = session.agent.state;
|
|
|
212
227
|
// state.model: Model - current model
|
|
213
228
|
// state.thinkingLevel: ThinkingLevel - current thinking level
|
|
214
229
|
// state.systemPrompt: string - system prompt
|
|
215
|
-
// state.tools:
|
|
230
|
+
// state.tools: AgentTool[] - available tools
|
|
231
|
+
// state.streamingMessage?: AgentMessage - current partial assistant message
|
|
232
|
+
// state.errorMessage?: string - latest assistant error
|
|
233
|
+
|
|
234
|
+
// Replace messages (useful for branching or restoration)
|
|
235
|
+
session.agent.state.messages = messages; // copies the top-level array
|
|
216
236
|
|
|
217
|
-
// Replace
|
|
218
|
-
session.agent.
|
|
237
|
+
// Replace tools
|
|
238
|
+
session.agent.state.tools = tools; // copies the top-level array
|
|
219
239
|
|
|
220
240
|
// Wait for agent to finish processing
|
|
221
241
|
await session.agent.waitForIdle();
|
|
@@ -273,9 +293,12 @@ session.subscribe((event) => {
|
|
|
273
293
|
// event.toolResults: tool results from this turn
|
|
274
294
|
break;
|
|
275
295
|
|
|
276
|
-
// Session events (
|
|
277
|
-
case "
|
|
278
|
-
|
|
296
|
+
// Session events (queue, compaction, retry)
|
|
297
|
+
case "queue_update":
|
|
298
|
+
console.log(event.steering, event.followUp);
|
|
299
|
+
break;
|
|
300
|
+
case "compaction_start":
|
|
301
|
+
case "compaction_end":
|
|
279
302
|
case "auto_retry_start":
|
|
280
303
|
case "auto_retry_end":
|
|
281
304
|
break;
|
|
@@ -473,7 +496,7 @@ const { session } = await createAgentSession({
|
|
|
473
496
|
```
|
|
474
497
|
|
|
475
498
|
**When you don't need factories:**
|
|
476
|
-
- If you omit `tools`,
|
|
499
|
+
- If you omit `tools`, pi automatically creates them with the correct `cwd`
|
|
477
500
|
- If you use `process.cwd()` as your `cwd`, the pre-built instances work fine
|
|
478
501
|
|
|
479
502
|
**When you must use factories:**
|
|
@@ -638,9 +661,12 @@ Sessions use a tree structure with `id`/`parentId` linking, enabling in-place br
|
|
|
638
661
|
|
|
639
662
|
```typescript
|
|
640
663
|
import {
|
|
641
|
-
|
|
664
|
+
type CreateAgentSessionRuntimeFactory,
|
|
642
665
|
createAgentSession,
|
|
666
|
+
createAgentSessionFromServices,
|
|
643
667
|
createAgentSessionRuntime,
|
|
668
|
+
createAgentSessionServices,
|
|
669
|
+
getAgentDir,
|
|
644
670
|
SessionManager,
|
|
645
671
|
} from "@draht/coding-agent";
|
|
646
672
|
|
|
@@ -672,21 +698,33 @@ const currentProjectSessions = await SessionManager.list(process.cwd());
|
|
|
672
698
|
const allSessions = await SessionManager.listAll(process.cwd());
|
|
673
699
|
|
|
674
700
|
// Session replacement API for /new, /resume, /fork, and import flows.
|
|
675
|
-
const
|
|
676
|
-
const
|
|
701
|
+
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
702
|
+
const services = await createAgentSessionServices({ cwd });
|
|
703
|
+
return {
|
|
704
|
+
...(await createAgentSessionFromServices({
|
|
705
|
+
services,
|
|
706
|
+
sessionManager,
|
|
707
|
+
sessionStartEvent,
|
|
708
|
+
})),
|
|
709
|
+
services,
|
|
710
|
+
diagnostics: services.diagnostics,
|
|
711
|
+
};
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
677
715
|
cwd: process.cwd(),
|
|
716
|
+
agentDir: getAgentDir(),
|
|
678
717
|
sessionManager: SessionManager.create(process.cwd()),
|
|
679
718
|
});
|
|
680
|
-
const runtimeHost = new AgentSessionRuntimeHost(bootstrap, runtime);
|
|
681
719
|
|
|
682
720
|
// Replace the active session with a fresh one
|
|
683
|
-
await
|
|
721
|
+
await runtime.newSession();
|
|
684
722
|
|
|
685
723
|
// Replace the active session with another saved session
|
|
686
|
-
await
|
|
724
|
+
await runtime.switchSession("/path/to/session.jsonl");
|
|
687
725
|
|
|
688
726
|
// Replace the active session with a fork from a specific entry
|
|
689
|
-
await
|
|
727
|
+
await runtime.fork("entry-id");
|
|
690
728
|
```
|
|
691
729
|
|
|
692
730
|
**SessionManager tree API:**
|
|
@@ -908,20 +946,30 @@ Full TUI interactive mode with editor, chat history, and all built-in commands:
|
|
|
908
946
|
|
|
909
947
|
```typescript
|
|
910
948
|
import {
|
|
911
|
-
|
|
949
|
+
type CreateAgentSessionRuntimeFactory,
|
|
950
|
+
createAgentSessionFromServices,
|
|
912
951
|
createAgentSessionRuntime,
|
|
952
|
+
createAgentSessionServices,
|
|
953
|
+
getAgentDir,
|
|
913
954
|
InteractiveMode,
|
|
914
955
|
SessionManager,
|
|
915
956
|
} from "@draht/coding-agent";
|
|
916
957
|
|
|
917
|
-
const
|
|
918
|
-
const
|
|
958
|
+
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
959
|
+
const services = await createAgentSessionServices({ cwd });
|
|
960
|
+
return {
|
|
961
|
+
...(await createAgentSessionFromServices({ services, sessionManager, sessionStartEvent })),
|
|
962
|
+
services,
|
|
963
|
+
diagnostics: services.diagnostics,
|
|
964
|
+
};
|
|
965
|
+
};
|
|
966
|
+
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
919
967
|
cwd: process.cwd(),
|
|
968
|
+
agentDir: getAgentDir(),
|
|
920
969
|
sessionManager: SessionManager.create(process.cwd()),
|
|
921
970
|
});
|
|
922
|
-
const runtimeHost = new AgentSessionRuntimeHost(bootstrap, runtime);
|
|
923
971
|
|
|
924
|
-
const mode = new InteractiveMode(
|
|
972
|
+
const mode = new InteractiveMode(runtime, {
|
|
925
973
|
migratedProviders: [],
|
|
926
974
|
modelFallbackMessage: undefined,
|
|
927
975
|
initialMessage: "Hello",
|
|
@@ -938,20 +986,30 @@ Single-shot mode: send prompts, output result, exit:
|
|
|
938
986
|
|
|
939
987
|
```typescript
|
|
940
988
|
import {
|
|
941
|
-
|
|
989
|
+
type CreateAgentSessionRuntimeFactory,
|
|
990
|
+
createAgentSessionFromServices,
|
|
942
991
|
createAgentSessionRuntime,
|
|
992
|
+
createAgentSessionServices,
|
|
993
|
+
getAgentDir,
|
|
943
994
|
runPrintMode,
|
|
944
995
|
SessionManager,
|
|
945
996
|
} from "@draht/coding-agent";
|
|
946
997
|
|
|
947
|
-
const
|
|
948
|
-
const
|
|
998
|
+
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
999
|
+
const services = await createAgentSessionServices({ cwd });
|
|
1000
|
+
return {
|
|
1001
|
+
...(await createAgentSessionFromServices({ services, sessionManager, sessionStartEvent })),
|
|
1002
|
+
services,
|
|
1003
|
+
diagnostics: services.diagnostics,
|
|
1004
|
+
};
|
|
1005
|
+
};
|
|
1006
|
+
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
949
1007
|
cwd: process.cwd(),
|
|
1008
|
+
agentDir: getAgentDir(),
|
|
950
1009
|
sessionManager: SessionManager.create(process.cwd()),
|
|
951
1010
|
});
|
|
952
|
-
const runtimeHost = new AgentSessionRuntimeHost(bootstrap, runtime);
|
|
953
1011
|
|
|
954
|
-
await runPrintMode(
|
|
1012
|
+
await runPrintMode(runtime, {
|
|
955
1013
|
mode: "text",
|
|
956
1014
|
initialMessage: "Hello",
|
|
957
1015
|
initialImages: [],
|
|
@@ -965,20 +1023,30 @@ JSON-RPC mode for subprocess integration:
|
|
|
965
1023
|
|
|
966
1024
|
```typescript
|
|
967
1025
|
import {
|
|
968
|
-
|
|
1026
|
+
type CreateAgentSessionRuntimeFactory,
|
|
1027
|
+
createAgentSessionFromServices,
|
|
969
1028
|
createAgentSessionRuntime,
|
|
1029
|
+
createAgentSessionServices,
|
|
1030
|
+
getAgentDir,
|
|
970
1031
|
runRpcMode,
|
|
971
1032
|
SessionManager,
|
|
972
1033
|
} from "@draht/coding-agent";
|
|
973
1034
|
|
|
974
|
-
const
|
|
975
|
-
const
|
|
1035
|
+
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
1036
|
+
const services = await createAgentSessionServices({ cwd });
|
|
1037
|
+
return {
|
|
1038
|
+
...(await createAgentSessionFromServices({ services, sessionManager, sessionStartEvent })),
|
|
1039
|
+
services,
|
|
1040
|
+
diagnostics: services.diagnostics,
|
|
1041
|
+
};
|
|
1042
|
+
};
|
|
1043
|
+
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
976
1044
|
cwd: process.cwd(),
|
|
1045
|
+
agentDir: getAgentDir(),
|
|
977
1046
|
sessionManager: SessionManager.create(process.cwd()),
|
|
978
1047
|
});
|
|
979
|
-
const runtimeHost = new AgentSessionRuntimeHost(bootstrap, runtime);
|
|
980
1048
|
|
|
981
|
-
await runRpcMode(
|
|
1049
|
+
await runRpcMode(runtime);
|
|
982
1050
|
```
|
|
983
1051
|
|
|
984
1052
|
See [RPC documentation](rpc.md) for the JSON protocol.
|
|
@@ -988,7 +1056,7 @@ See [RPC documentation](rpc.md) for the JSON protocol.
|
|
|
988
1056
|
For subprocess-based integration without building with the SDK, use the CLI directly:
|
|
989
1057
|
|
|
990
1058
|
```bash
|
|
991
|
-
|
|
1059
|
+
pi --mode rpc --no-session
|
|
992
1060
|
```
|
|
993
1061
|
|
|
994
1062
|
See [RPC documentation](rpc.md) for the JSON protocol.
|
|
@@ -1012,7 +1080,7 @@ The main entry point exports:
|
|
|
1012
1080
|
// Factory
|
|
1013
1081
|
createAgentSession
|
|
1014
1082
|
createAgentSessionRuntime
|
|
1015
|
-
|
|
1083
|
+
AgentSessionRuntime
|
|
1016
1084
|
|
|
1017
1085
|
// Auth and Models
|
|
1018
1086
|
AuthStorage
|
package/docs/session.md
CHANGED
|
@@ -28,7 +28,7 @@ Existing sessions are automatically migrated to the current version (v3) when lo
|
|
|
28
28
|
|
|
29
29
|
## Source Files
|
|
30
30
|
|
|
31
|
-
Source on GitHub ([
|
|
31
|
+
Source on GitHub ([draht-mono](https://github.com/draht-dev/draht)):
|
|
32
32
|
- [`packages/coding-agent/src/core/session-manager.ts`](https://github.com/draht-dev/draht/blob/main/packages/coding-agent/src/core/session-manager.ts) - Session entry types and SessionManager
|
|
33
33
|
- [`packages/coding-agent/src/core/messages.ts`](https://github.com/draht-dev/draht/blob/main/packages/coding-agent/src/core/messages.ts) - Extended message types (BashExecutionMessage, CustomMessage, etc.)
|
|
34
34
|
- [`packages/ai/src/types.ts`](https://github.com/draht-dev/draht/blob/main/packages/ai/src/types.ts) - Base message types (UserMessage, AssistantMessage, ToolResultMessage)
|
|
@@ -69,7 +69,7 @@ interface ToolCall {
|
|
|
69
69
|
}
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
### Base Message Types (from
|
|
72
|
+
### Base Message Types (from draht-ai)
|
|
73
73
|
|
|
74
74
|
```typescript
|
|
75
75
|
interface UserMessage {
|
|
@@ -116,7 +116,7 @@ interface Usage {
|
|
|
116
116
|
}
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
### Extended Message Types (from
|
|
119
|
+
### Extended Message Types (from draht coding agent)
|
|
120
120
|
|
|
121
121
|
```typescript
|
|
122
122
|
interface BashExecutionMessage {
|
package/docs/settings.md
CHANGED
|
@@ -127,6 +127,18 @@ When a provider requests a retry delay longer than `maxDelayMs` (e.g., Google's
|
|
|
127
127
|
|
|
128
128
|
`npmCommand` is used for all npm package-manager operations, including `npm root -g`, installs, uninstalls, and `npm install` inside git packages. Use argv-style entries exactly as the process should be launched.
|
|
129
129
|
|
|
130
|
+
### Sessions
|
|
131
|
+
|
|
132
|
+
| Setting | Type | Default | Description |
|
|
133
|
+
|---------|------|---------|-------------|
|
|
134
|
+
| `sessionDir` | string | - | Directory where session files are stored. Accepts absolute or relative paths. |
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{ "sessionDir": ".pi/sessions" }
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
When multiple sources specify a session directory, `--session-dir` CLI flag takes precedence over `sessionDir` in settings.json.
|
|
141
|
+
|
|
130
142
|
### Model Cycling
|
|
131
143
|
|
|
132
144
|
| Setting | Type | Default | Description |
|
package/docs/skills.md
CHANGED
|
@@ -34,8 +34,9 @@ Pi loads skills from:
|
|
|
34
34
|
- CLI: `--skill <path>` (repeatable, additive even with `--no-skills`)
|
|
35
35
|
|
|
36
36
|
Discovery rules:
|
|
37
|
-
-
|
|
38
|
-
-
|
|
37
|
+
- In `~/.pi/agent/skills/` and `.pi/skills/`, direct root `.md` files are discovered as individual skills
|
|
38
|
+
- In all skill locations, directories containing `SKILL.md` are discovered recursively
|
|
39
|
+
- In `~/.agents/skills/` and project `.agents/skills/`, root `.md` files are ignored
|
|
39
40
|
|
|
40
41
|
Disable discovery with `--no-skills` (explicit `--skill` paths still load).
|
|
41
42
|
|
package/docs/tree.md
CHANGED
|
@@ -35,6 +35,8 @@ Sessions are stored as trees where each entry has an `id` and `parentId`. The "l
|
|
|
35
35
|
| ↑/↓ | Navigate (depth-first order) |
|
|
36
36
|
| ←/→ | Page up/down |
|
|
37
37
|
| Ctrl+←/Ctrl+→ or Alt+←/Alt+→ | Fold/unfold and jump between branch segments |
|
|
38
|
+
| Shift+L | Set or clear a label on the selected node |
|
|
39
|
+
| Shift+T | Toggle label timestamps |
|
|
38
40
|
| Enter | Select node |
|
|
39
41
|
| Escape/Ctrl+C | Cancel |
|
|
40
42
|
| Ctrl+U | Toggle: user messages only |
|
|
@@ -49,11 +51,12 @@ Sessions are stored as trees where each entry has an `id` and `parentId`. The "l
|
|
|
49
51
|
- Height: half terminal height
|
|
50
52
|
- Current leaf marked with `← active`
|
|
51
53
|
- Labels shown inline: `[label-name]`
|
|
54
|
+
- `Shift+T` shows the latest label-change timestamp next to labeled nodes
|
|
52
55
|
- Foldable branch starts show `⊟` in the connector. Folded branches show `⊞`
|
|
53
56
|
- Active path marker `•` appears after the fold indicator when applicable
|
|
54
57
|
- Search and filter changes reset all folds
|
|
55
58
|
- Default filter hides `label` and `custom` entries (shown in Ctrl+O mode)
|
|
56
|
-
-
|
|
59
|
+
- At each branch point, the active subtree is shown first; other sibling branches are sorted by timestamp (oldest first)
|
|
57
60
|
|
|
58
61
|
## Selection Behavior
|
|
59
62
|
|
|
@@ -141,7 +144,7 @@ Flow:
|
|
|
141
144
|
4. Fire `session_before_tree` event (hook can cancel or provide summary)
|
|
142
145
|
5. Run default summarizer if needed
|
|
143
146
|
6. Switch leaf via `branch()` or `branchWithSummary()`
|
|
144
|
-
7. Update agent: `agent.
|
|
147
|
+
7. Update agent: `agent.state.messages = sessionManager.buildSessionContext().messages`
|
|
145
148
|
8. Fire `session_tree` event
|
|
146
149
|
9. Notify custom tools via session event
|
|
147
150
|
10. Return result with `editorText` if user message was selected
|
package/examples/README.md
CHANGED
|
@@ -52,6 +52,7 @@ cp permission-gate.ts ~/.draht/agent/extensions/
|
|
|
52
52
|
| `qna.ts` | Extracts questions from last response into editor via `ctx.ui.setEditorText()` |
|
|
53
53
|
| `status-line.ts` | Shows turn progress in footer via `ctx.ui.setStatus()` with themed colors |
|
|
54
54
|
| `widget-placement.ts` | Shows widgets above and below the editor via `ctx.ui.setWidget()` placement |
|
|
55
|
+
| `hidden-thinking-label.ts` | Customizes the collapsed thinking label via `ctx.ui.setHiddenThinkingLabel()` |
|
|
55
56
|
| `model-status.ts` | Shows model changes in status bar via `model_select` hook |
|
|
56
57
|
| `snake.ts` | Snake game with custom UI, keyboard handling, and session persistence |
|
|
57
58
|
| `send-user-message.ts` | Demonstrates `pi.sendUserMessage()` for sending user messages from extensions |
|
|
@@ -48,7 +48,7 @@ type SaveMode = (typeof SAVE_MODES)[number];
|
|
|
48
48
|
|
|
49
49
|
const ANTIGRAVITY_ENDPOINT = "https://daily-cloudcode-pa.sandbox.googleapis.com";
|
|
50
50
|
|
|
51
|
-
const DEFAULT_ANTIGRAVITY_VERSION = "1.
|
|
51
|
+
const DEFAULT_ANTIGRAVITY_VERSION = "1.21.9";
|
|
52
52
|
|
|
53
53
|
const ANTIGRAVITY_HEADERS = {
|
|
54
54
|
"User-Agent": `antigravity/${process.env.PI_AI_ANTIGRAVITY_VERSION || DEFAULT_ANTIGRAVITY_VERSION} darwin/arm64`,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* GitLab Duo Provider Extension
|
|
3
3
|
*
|
|
4
4
|
* Provides access to GitLab Duo AI models (Claude and GPT) through GitLab's AI Gateway.
|
|
5
|
-
* Delegates to
|
|
5
|
+
* Delegates to @draht/ai's built-in Anthropic and OpenAI streaming implementations.
|
|
6
6
|
*
|
|
7
7
|
* Usage:
|
|
8
8
|
* pi -e ./packages/coding-agent/examples/extensions/custom-provider-gitlab-duo
|