@draht/coding-agent 2026.4.5 → 2026.4.25-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/CHANGELOG.md +804 -625
  2. package/README.md +24 -15
  3. package/dist/cli/args.d.ts +7 -10
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +44 -46
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +1 -0
  9. package/dist/cli.js.map +1 -1
  10. package/dist/config.d.ts +9 -0
  11. package/dist/config.d.ts.map +1 -1
  12. package/dist/config.js +18 -0
  13. package/dist/config.js.map +1 -1
  14. package/dist/core/agent-session-runtime.d.ts +53 -106
  15. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  16. package/dist/core/agent-session-runtime.js +116 -147
  17. package/dist/core/agent-session-runtime.js.map +1 -1
  18. package/dist/core/agent-session-services.d.ts +86 -0
  19. package/dist/core/agent-session-services.d.ts.map +1 -0
  20. package/dist/core/agent-session-services.js +116 -0
  21. package/dist/core/agent-session-services.js.map +1 -0
  22. package/dist/core/agent-session.d.ts +8 -12
  23. package/dist/core/agent-session.d.ts.map +1 -1
  24. package/dist/core/agent-session.js +134 -45
  25. package/dist/core/agent-session.js.map +1 -1
  26. package/dist/core/bash-executor.d.ts.map +1 -1
  27. package/dist/core/bash-executor.js +19 -7
  28. package/dist/core/bash-executor.js.map +1 -1
  29. package/dist/core/compaction/compaction.d.ts +1 -1
  30. package/dist/core/compaction/compaction.d.ts.map +1 -1
  31. package/dist/core/compaction/compaction.js +18 -17
  32. package/dist/core/compaction/compaction.js.map +1 -1
  33. package/dist/core/extensions/index.d.ts +1 -1
  34. package/dist/core/extensions/index.d.ts.map +1 -1
  35. package/dist/core/extensions/index.js.map +1 -1
  36. package/dist/core/extensions/loader.d.ts.map +1 -1
  37. package/dist/core/extensions/loader.js +7 -7
  38. package/dist/core/extensions/loader.js.map +1 -1
  39. package/dist/core/extensions/runner.d.ts +1 -0
  40. package/dist/core/extensions/runner.d.ts.map +1 -1
  41. package/dist/core/extensions/runner.js +4 -0
  42. package/dist/core/extensions/runner.js.map +1 -1
  43. package/dist/core/extensions/types.d.ts +15 -14
  44. package/dist/core/extensions/types.d.ts.map +1 -1
  45. package/dist/core/extensions/types.js.map +1 -1
  46. package/dist/core/index.d.ts +2 -1
  47. package/dist/core/index.d.ts.map +1 -1
  48. package/dist/core/index.js +2 -1
  49. package/dist/core/index.js.map +1 -1
  50. package/dist/core/keybindings.d.ts +14 -1
  51. package/dist/core/keybindings.d.ts.map +1 -1
  52. package/dist/core/keybindings.js +13 -14
  53. package/dist/core/keybindings.js.map +1 -1
  54. package/dist/core/model-registry.d.ts.map +1 -1
  55. package/dist/core/model-registry.js +31 -1
  56. package/dist/core/model-registry.js.map +1 -1
  57. package/dist/core/package-manager.d.ts +21 -1
  58. package/dist/core/package-manager.d.ts.map +1 -1
  59. package/dist/core/package-manager.js +108 -43
  60. package/dist/core/package-manager.js.map +1 -1
  61. package/dist/core/prompt-templates.d.ts.map +1 -1
  62. package/dist/core/prompt-templates.js +22 -21
  63. package/dist/core/prompt-templates.js.map +1 -1
  64. package/dist/core/resource-loader.d.ts +0 -2
  65. package/dist/core/resource-loader.d.ts.map +1 -1
  66. package/dist/core/resource-loader.js +26 -8
  67. package/dist/core/resource-loader.js.map +1 -1
  68. package/dist/core/sdk.d.ts +2 -2
  69. package/dist/core/sdk.d.ts.map +1 -1
  70. package/dist/core/sdk.js +2 -2
  71. package/dist/core/sdk.js.map +1 -1
  72. package/dist/core/session-cwd.d.ts +19 -0
  73. package/dist/core/session-cwd.d.ts.map +1 -0
  74. package/dist/core/session-cwd.js +38 -0
  75. package/dist/core/session-cwd.js.map +1 -0
  76. package/dist/core/session-manager.d.ts +5 -1
  77. package/dist/core/session-manager.d.ts.map +1 -1
  78. package/dist/core/session-manager.js +16 -8
  79. package/dist/core/session-manager.js.map +1 -1
  80. package/dist/core/settings-manager.d.ts +6 -4
  81. package/dist/core/settings-manager.d.ts.map +1 -1
  82. package/dist/core/settings-manager.js +5 -1
  83. package/dist/core/settings-manager.js.map +1 -1
  84. package/dist/core/skills.d.ts +1 -1
  85. package/dist/core/skills.d.ts.map +1 -1
  86. package/dist/core/skills.js +3 -3
  87. package/dist/core/skills.js.map +1 -1
  88. package/dist/core/system-prompt.d.ts.map +1 -1
  89. package/dist/core/system-prompt.js +6 -6
  90. package/dist/core/system-prompt.js.map +1 -1
  91. package/dist/core/timings.d.ts +1 -0
  92. package/dist/core/timings.d.ts.map +1 -1
  93. package/dist/core/timings.js +6 -0
  94. package/dist/core/timings.js.map +1 -1
  95. package/dist/core/tools/bash.d.ts.map +1 -1
  96. package/dist/core/tools/bash.js +19 -9
  97. package/dist/core/tools/bash.js.map +1 -1
  98. package/dist/core/tools/edit-diff.d.ts +23 -1
  99. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  100. package/dist/core/tools/edit-diff.js +150 -57
  101. package/dist/core/tools/edit-diff.js.map +1 -1
  102. package/dist/core/tools/edit.d.ts +13 -11
  103. package/dist/core/tools/edit.d.ts.map +1 -1
  104. package/dist/core/tools/edit.js +55 -77
  105. package/dist/core/tools/edit.js.map +1 -1
  106. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  107. package/dist/core/tools/file-mutation-queue.js +4 -4
  108. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  109. package/dist/core/tools/index.d.ts +9 -6
  110. package/dist/core/tools/index.d.ts.map +1 -1
  111. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  112. package/dist/core/tools/tool-definition-wrapper.js +2 -0
  113. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  114. package/dist/index.d.ts +4 -4
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +4 -5
  117. package/dist/index.js.map +1 -1
  118. package/dist/main.d.ts.map +1 -1
  119. package/dist/main.js +252 -451
  120. package/dist/main.js.map +1 -1
  121. package/dist/migrations.d.ts +3 -3
  122. package/dist/migrations.d.ts.map +1 -1
  123. package/dist/migrations.js +25 -5
  124. package/dist/migrations.js.map +1 -1
  125. package/dist/modes/interactive/components/assistant-message.d.ts +3 -1
  126. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  127. package/dist/modes/interactive/components/assistant-message.js +14 -3
  128. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  129. package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
  130. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
  131. package/dist/modes/interactive/components/earendil-announcement.js +40 -0
  132. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
  133. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  134. package/dist/modes/interactive/components/settings-selector.js +1 -0
  135. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  136. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  137. package/dist/modes/interactive/components/thinking-selector.js +1 -0
  138. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  139. package/dist/modes/interactive/components/tool-execution.d.ts +0 -1
  140. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  141. package/dist/modes/interactive/components/tool-execution.js +2 -7
  142. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  143. package/dist/modes/interactive/components/tree-selector.d.ts +4 -2
  144. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  145. package/dist/modes/interactive/components/tree-selector.js +48 -15
  146. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  147. package/dist/modes/interactive/interactive-mode.d.ts +12 -3
  148. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  149. package/dist/modes/interactive/interactive-mode.js +237 -125
  150. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  151. package/dist/modes/interactive/theme/dark.json +8 -5
  152. package/dist/modes/interactive/theme/light.json +8 -5
  153. package/dist/modes/interactive/theme/theme-schema.json +6 -1
  154. package/dist/modes/interactive/theme/theme.d.ts +2 -2
  155. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  156. package/dist/modes/interactive/theme/theme.js +13 -1
  157. package/dist/modes/interactive/theme/theme.js.map +1 -1
  158. package/dist/modes/print-mode.d.ts +4 -4
  159. package/dist/modes/print-mode.d.ts.map +1 -1
  160. package/dist/modes/print-mode.js +6 -2
  161. package/dist/modes/print-mode.js.map +1 -1
  162. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  163. package/dist/modes/rpc/rpc-client.js +1 -0
  164. package/dist/modes/rpc/rpc-client.js.map +1 -1
  165. package/dist/modes/rpc/rpc-mode.d.ts +2 -2
  166. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  167. package/dist/modes/rpc/rpc-mode.js +26 -15
  168. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  169. package/dist/package-manager-cli.d.ts +4 -0
  170. package/dist/package-manager-cli.d.ts.map +1 -0
  171. package/dist/package-manager-cli.js +234 -0
  172. package/dist/package-manager-cli.js.map +1 -0
  173. package/dist/prompts/commands/atomic-commit.md +17 -0
  174. package/dist/prompts/commands/discuss-phase.md +15 -0
  175. package/dist/prompts/commands/execute-phase.md +14 -0
  176. package/dist/prompts/commands/fix.md +14 -0
  177. package/dist/prompts/commands/init-project.md +16 -0
  178. package/dist/prompts/commands/map-codebase.md +16 -0
  179. package/dist/prompts/commands/new-project.md +16 -0
  180. package/dist/prompts/commands/next-milestone.md +16 -0
  181. package/dist/prompts/commands/orchestrate.md +57 -0
  182. package/dist/prompts/commands/pause-work.md +13 -0
  183. package/dist/prompts/commands/plan-phase.md +15 -0
  184. package/dist/prompts/commands/progress.md +13 -0
  185. package/dist/prompts/commands/quick.md +14 -0
  186. package/dist/prompts/commands/resume-work.md +13 -0
  187. package/dist/prompts/commands/review.md +15 -0
  188. package/dist/prompts/commands/verify-work.md +15 -0
  189. package/dist/utils/paths.d.ts +7 -0
  190. package/dist/utils/paths.d.ts.map +1 -0
  191. package/dist/utils/paths.js +19 -0
  192. package/dist/utils/paths.js.map +1 -0
  193. package/docs/compaction.md +5 -3
  194. package/docs/custom-provider.md +1 -1
  195. package/docs/development.md +3 -1
  196. package/docs/extensions.md +150 -54
  197. package/docs/json.md +5 -2
  198. package/docs/keybindings.md +2 -0
  199. package/docs/models.md +55 -4
  200. package/docs/rpc.md +21 -7
  201. package/docs/sdk.md +116 -48
  202. package/docs/session.md +3 -3
  203. package/docs/settings.md +12 -0
  204. package/docs/skills.md +3 -2
  205. package/docs/tree.md +5 -2
  206. package/examples/README.md +1 -1
  207. package/examples/extensions/README.md +1 -0
  208. package/examples/extensions/antigravity-image-gen.ts +1 -1
  209. package/examples/extensions/custom-provider-gitlab-duo/index.ts +1 -1
  210. package/examples/extensions/doom-overlay/doom/build.sh +2 -2
  211. package/examples/extensions/hidden-thinking-label.ts +53 -0
  212. package/examples/extensions/overlay-qa-tests.ts +2 -2
  213. package/examples/extensions/sandbox/index.ts +8 -4
  214. package/examples/extensions/subagent/index.ts +5 -5
  215. package/examples/extensions/trigger-compact.ts +11 -1
  216. package/examples/sdk/13-session-runtime.ts +30 -12
  217. package/examples/sdk/README.md +4 -2
  218. package/package.json +7 -8
  219. package/prompts/commands/atomic-commit.md +17 -0
  220. package/prompts/commands/discuss-phase.md +15 -0
  221. package/prompts/commands/execute-phase.md +14 -0
  222. package/prompts/commands/fix.md +14 -0
  223. package/prompts/commands/init-project.md +16 -0
  224. package/prompts/commands/map-codebase.md +16 -0
  225. package/prompts/commands/new-project.md +16 -0
  226. package/prompts/commands/next-milestone.md +16 -0
  227. package/prompts/commands/orchestrate.md +57 -0
  228. package/prompts/commands/pause-work.md +13 -0
  229. package/prompts/commands/plan-phase.md +15 -0
  230. package/prompts/commands/progress.md +13 -0
  231. package/prompts/commands/quick.md +14 -0
  232. package/prompts/commands/resume-work.md +13 -0
  233. package/prompts/commands/review.md +15 -0
  234. package/prompts/commands/verify-work.md +15 -0
package/docs/sdk.md CHANGED
@@ -1,8 +1,8 @@
1
- > draht can help you use the SDK. Ask it to build an integration for your use case.
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 draht's agent capabilities. Use it to embed draht in other applications, build custom interfaces, or integrate with automated workflows.
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 `AgentSessionRuntimeHost`, not on `AgentSession`.
118
+ Session replacement APIs such as new-session, resume, fork, and import live on `AgentSessionRuntime`, not on `AgentSession`.
119
119
 
120
- ### createAgentSessionRuntime() and AgentSessionRuntimeHost
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
- AgentSessionRuntimeHost,
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 bootstrap = {
133
- // Optional: authStorage, model, thinkingLevel, tools, customTools, resourceLoader
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(bootstrap, {
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
- `createAgentSessionRuntime()` returns an internal runtime bundle. `AgentSessionRuntimeHost` owns replacement of that bundle across:
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
- - `runtimeHost.session` changes after those operations
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 `runtimeHost.session.bindExtensions(...)` again for the new session
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 = runtimeHost.session;
173
+ let session = runtime.session;
159
174
  let unsubscribe = session.subscribe(() => {});
160
175
 
161
- await runtimeHost.newSession();
176
+ await runtime.newSession();
162
177
 
163
178
  unsubscribe();
164
- session = runtimeHost.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-core`) handles the core LLM interaction. Access it via `session.agent`.
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: Tool[] - available 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 messages (useful for branching, restoration)
218
- session.agent.replaceMessages(messages);
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 (auto-compaction, retry)
277
- case "auto_compaction_start":
278
- case "auto_compaction_end":
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`, draht automatically creates them with the correct `cwd`
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
- AgentSessionRuntimeHost,
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 bootstrap = {};
676
- const runtime = await createAgentSessionRuntime(bootstrap, {
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 runtimeHost.newSession();
721
+ await runtime.newSession();
684
722
 
685
723
  // Replace the active session with another saved session
686
- await runtimeHost.switchSession("/path/to/session.jsonl");
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 runtimeHost.fork("entry-id");
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
- AgentSessionRuntimeHost,
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 bootstrap = {};
918
- const runtime = await createAgentSessionRuntime(bootstrap, {
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(runtimeHost, {
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
- AgentSessionRuntimeHost,
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 bootstrap = {};
948
- const runtime = await createAgentSessionRuntime(bootstrap, {
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(runtimeHost, {
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
- AgentSessionRuntimeHost,
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 bootstrap = {};
975
- const runtime = await createAgentSessionRuntime(bootstrap, {
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(runtimeHost);
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
- draht --mode rpc --no-session
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
- AgentSessionRuntimeHost
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 ([pi-mono](https://github.com/draht-dev/draht)):
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 pi-ai)
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 pi-coding-agent)
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
- - Direct `.md` files in the skills directory root
38
- - Recursive `SKILL.md` files under subdirectories
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
- - Children sorted by timestamp (oldest first)
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.replaceMessages(sessionManager.buildSessionContext().messages)`
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
@@ -1,6 +1,6 @@
1
1
  # Examples
2
2
 
3
- Example code for pi-coding-agent SDK and extensions.
3
+ Example code for draht coding agent SDK and extensions.
4
4
 
5
5
  ## Directories
6
6
 
@@ -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.18.3";
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 pi-ai's built-in Anthropic and OpenAI streaming implementations.
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
@@ -60,8 +60,8 @@ emcc -O2 \
60
60
  -s FORCE_FILESYSTEM=1 \
61
61
  -s EXIT_RUNTIME=0 \
62
62
  -s NO_EXIT_RUNTIME=1 \
63
- -DDOOMGENERIC_RESX=$RESX \
64
- -DDOOMGENERIC_RESY=$RESY \
63
+ -DDOOMGENERIC_RESX="$RESX" \
64
+ -DDOOMGENERIC_RESY="$RESY" \
65
65
  -I. \
66
66
  am_map.c \
67
67
  d_event.c \
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Hidden Thinking Label Extension
3
+ *
4
+ * Demonstrates `ctx.ui.setHiddenThinkingLabel()` for customizing the label shown
5
+ * when thinking blocks are hidden.
6
+ *
7
+ * Usage:
8
+ * pi --extension examples/extensions/hidden-thinking-label.ts
9
+ *
10
+ * Test:
11
+ * 1. Load this extension
12
+ * 2. Hide thinking blocks with Ctrl+T
13
+ * 3. Ask for something that produces reasoning output
14
+ * 4. The collapsed thinking block label will show the custom text
15
+ *
16
+ * Commands:
17
+ * /thinking-label <text> Set a custom hidden thinking label
18
+ * /thinking-label Reset to the default label
19
+ */
20
+
21
+ import type { ExtensionAPI, ExtensionContext } from "@draht/coding-agent";
22
+
23
+ const DEFAULT_LABEL = "Pondering...";
24
+
25
+ export default function (pi: ExtensionAPI) {
26
+ let label = DEFAULT_LABEL;
27
+
28
+ const applyLabel = (ctx: ExtensionContext) => {
29
+ ctx.ui.setHiddenThinkingLabel(label);
30
+ };
31
+
32
+ pi.on("session_start", async (_event, ctx) => {
33
+ applyLabel(ctx);
34
+ });
35
+
36
+ pi.registerCommand("thinking-label", {
37
+ description: "Set the hidden thinking label. Use without args to reset.",
38
+ handler: async (args, ctx) => {
39
+ const nextLabel = args.trim();
40
+
41
+ if (!nextLabel) {
42
+ label = DEFAULT_LABEL;
43
+ ctx.ui.setHiddenThinkingLabel();
44
+ ctx.ui.notify(`Hidden thinking label reset to: ${DEFAULT_LABEL}`);
45
+ return;
46
+ }
47
+
48
+ label = nextLabel;
49
+ ctx.ui.setHiddenThinkingLabel(label);
50
+ ctx.ui.notify(`Hidden thinking label set to: ${label}`);
51
+ },
52
+ });
53
+ }
@@ -473,13 +473,13 @@ class StreamingOverflowComponent extends BaseOverlay {
473
473
  echo ""
474
474
  for i in $(seq 1 100); do
475
475
  # Simulate long file paths with OSC 8 hyperlinks (clickable) - tests width overflow
476
- DIR="/Users/nicobailon/Documents/development/pi-mono/packages/coding-agent/src/modes/interactive"
476
+ DIR="/Users/nicobailon/Documents/development/draht-mono/packages/coding-agent/src/modes/interactive"
477
477
  FILE="\${DIR}/components/very-long-component-name-that-exceeds-width-\${i}.ts"
478
478
  echo -e "\\033]8;;file://\${FILE}\\007▶ read: \${FILE}\\033]8;;\\007"
479
479
 
480
480
  # Add some colored status messages with long text
481
481
  if [ $((i % 5)) -eq 0 ]; then
482
- echo -e " \\033[32m✓ Successfully processed \${i} files in /Users/nicobailon/Documents/development/pi-mono\\033[0m"
482
+ echo -e " \\033[32m✓ Successfully processed \${i} files in /Users/nicobailon/Documents/development/draht-mono\\033[0m"
483
483
  fi
484
484
  if [ $((i % 7)) -eq 0 ]; then
485
485
  echo -e " \\033[33m⚠ Warning: potential issue detected at line \${i} in very-long-component-name-that-exceeds-width.ts\\033[0m"
@@ -5,9 +5,13 @@
5
5
  * restrictions on bash commands at the OS level (sandbox-exec on macOS,
6
6
  * bubblewrap on Linux).
7
7
  *
8
+ * Note: this example intentionally overrides the built-in `bash` tool to show
9
+ * how built-in tools can be replaced. Alternatively, you could sandbox `bash`
10
+ * via `tool_call` input mutation without replacing the tool.
11
+ *
8
12
  * Config files (merged, project takes precedence):
9
- * - ~/.pi/agent/sandbox.json (global)
10
- * - <cwd>/.pi/sandbox.json (project-local)
13
+ * - ~/.draht/agent/extensions/sandbox.json (global)
14
+ * - <cwd>/.draht/sandbox.json (project-local)
11
15
  *
12
16
  * Example .pi/sandbox.json:
13
17
  * ```json
@@ -31,8 +35,8 @@
31
35
  * - `/sandbox` - show current sandbox configuration
32
36
  *
33
37
  * Setup:
34
- * 1. Copy sandbox/ directory to ~/.pi/agent/extensions/
35
- * 2. Run `npm install` in ~/.pi/agent/extensions/sandbox/
38
+ * 1. Copy sandbox/ directory to ~/.draht/agent/extensions/
39
+ * 2. Run `npm install` in ~/.draht/agent/extensions/sandbox/
36
40
  *
37
41
  * Linux also requires: bubblewrap, socat, ripgrep
38
42
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Subagent Tool - Delegate tasks to specialized agents
3
3
  *
4
- * Spawns a separate `pi` process for each subagent invocation,
4
+ * Spawns a separate `draht` process for each subagent invocation,
5
5
  * giving it an isolated context window.
6
6
  *
7
7
  * Supports three modes:
@@ -16,7 +16,7 @@ import { spawn } from "node:child_process";
16
16
  import * as fs from "node:fs";
17
17
  import * as os from "node:os";
18
18
  import * as path from "node:path";
19
- import type { AgentToolResult } from "@draht/agent-core";
19
+ import type { AgentToolResult } from "@draht/agent";
20
20
  import type { Message } from "@draht/ai";
21
21
  import { StringEnum } from "@draht/ai";
22
22
  import { type ExtensionAPI, getMarkdownTheme, withFileMutationQueue } from "@draht/coding-agent";
@@ -208,7 +208,7 @@ async function mapWithConcurrencyLimit<TIn, TOut>(
208
208
  }
209
209
 
210
210
  async function writePromptToTempFile(agentName: string, prompt: string): Promise<{ dir: string; filePath: string }> {
211
- const tmpDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "pi-subagent-"));
211
+ const tmpDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "draht-subagent-"));
212
212
  const safeName = agentName.replace(/[^\w.-]+/g, "_");
213
213
  const filePath = path.join(tmpDir, `prompt-${safeName}.md`);
214
214
  await withFileMutationQueue(filePath, async () => {
@@ -434,8 +434,8 @@ export default function (pi: ExtensionAPI) {
434
434
  description: [
435
435
  "Delegate tasks to specialized subagents with isolated context.",
436
436
  "Modes: single (agent + task), parallel (tasks array), chain (sequential with {previous} placeholder).",
437
- 'Default agent scope is "user" (from ~/.pi/agent/agents).',
438
- 'To enable project-local agents in .pi/agents, set agentScope: "both" (or "project").',
437
+ 'Default agent scope is "user" (from ~/.draht/agent/agents).',
438
+ 'To enable project-local agents in .draht/agents, set agentScope: "both" (or "project").',
439
439
  ].join(" "),
440
440
  parameters: SubagentParams,
441
441
 
@@ -3,6 +3,8 @@ import type { ExtensionAPI, ExtensionContext } from "@draht/coding-agent";
3
3
  const COMPACT_THRESHOLD_TOKENS = 100_000;
4
4
 
5
5
  export default function (pi: ExtensionAPI) {
6
+ let previousTokens: number | null | undefined;
7
+
6
8
  const triggerCompaction = (ctx: ExtensionContext, customInstructions?: string) => {
7
9
  if (ctx.hasUI) {
8
10
  ctx.ui.notify("Compaction started", "info");
@@ -24,7 +26,15 @@ export default function (pi: ExtensionAPI) {
24
26
 
25
27
  pi.on("turn_end", (_event, ctx) => {
26
28
  const usage = ctx.getContextUsage();
27
- if (!usage || usage.tokens === null || usage.tokens <= COMPACT_THRESHOLD_TOKENS) {
29
+ const currentTokens = usage?.tokens ?? null;
30
+ if (currentTokens === null) {
31
+ return;
32
+ }
33
+
34
+ const crossedThreshold =
35
+ previousTokens !== undefined && previousTokens !== null && previousTokens <= COMPACT_THRESHOLD_TOKENS;
36
+ previousTokens = currentTokens;
37
+ if (!crossedThreshold || currentTokens <= COMPACT_THRESHOLD_TOKENS) {
28
38
  return;
29
39
  }
30
40
  triggerCompaction(ctx);