@valni/cli-darwin-x64 0.1.2 → 0.1.3

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 (149) hide show
  1. package/LICENSE +1 -2
  2. package/package.json +1 -1
  3. package/runtime/LICENSE +1 -2
  4. package/runtime/examples/extensions/auto-commit-on-exit.ts +6 -6
  5. package/runtime/examples/extensions/bash-spawn-hook.ts +3 -3
  6. package/runtime/examples/extensions/bookmark.ts +5 -5
  7. package/runtime/examples/extensions/border-status-editor.ts +7 -7
  8. package/runtime/examples/extensions/built-in-tool-renderer.ts +6 -6
  9. package/runtime/examples/extensions/claude-rules.ts +4 -4
  10. package/runtime/examples/extensions/commands.ts +5 -5
  11. package/runtime/examples/extensions/confirm-destructive.ts +3 -3
  12. package/runtime/examples/extensions/custom-footer.ts +2 -2
  13. package/runtime/examples/extensions/custom-header.ts +5 -5
  14. package/runtime/examples/extensions/custom-provider-anthropic/index.ts +4 -4
  15. package/runtime/examples/extensions/custom-provider-anthropic/package-lock.json +4 -4
  16. package/runtime/examples/extensions/custom-provider-anthropic/package.json +3 -3
  17. package/runtime/examples/extensions/dirty-repo-guard.ts +7 -7
  18. package/runtime/examples/extensions/doom-overlay/doom/build.sh +4 -4
  19. package/runtime/examples/extensions/doom-overlay/doom/{doomgeneric_pi.c → doomgeneric_valni.c} +1 -1
  20. package/runtime/examples/extensions/doom-overlay/index.ts +3 -3
  21. package/runtime/examples/extensions/dynamic-resources/dynamic.json +0 -1
  22. package/runtime/examples/extensions/dynamic-resources/index.ts +2 -4
  23. package/runtime/examples/extensions/dynamic-tools.ts +4 -4
  24. package/runtime/examples/extensions/entry-renderer.ts +6 -6
  25. package/runtime/examples/extensions/event-bus.ts +8 -8
  26. package/runtime/examples/extensions/file-trigger.ts +3 -3
  27. package/runtime/examples/extensions/git-checkpoint.ts +7 -7
  28. package/runtime/examples/extensions/git-merge-and-resolve.ts +14 -14
  29. package/runtime/examples/extensions/github-issue-autocomplete.ts +6 -6
  30. package/runtime/examples/extensions/hello.ts +2 -2
  31. package/runtime/examples/extensions/hidden-thinking-label.ts +4 -4
  32. package/runtime/examples/extensions/inline-bash.ts +5 -5
  33. package/runtime/examples/extensions/input-transform-streaming.ts +5 -5
  34. package/runtime/examples/extensions/input-transform.ts +5 -5
  35. package/runtime/examples/extensions/interactive-shell.ts +3 -3
  36. package/runtime/examples/extensions/mac-system-theme.ts +5 -5
  37. package/runtime/examples/extensions/message-renderer.ts +4 -4
  38. package/runtime/examples/extensions/minimal-mode.ts +9 -9
  39. package/runtime/examples/extensions/modal-editor.ts +3 -3
  40. package/runtime/examples/extensions/model-status.ts +3 -3
  41. package/runtime/examples/extensions/notify.ts +5 -5
  42. package/runtime/examples/extensions/overlay-qa-tests.ts +20 -20
  43. package/runtime/examples/extensions/overlay-test.ts +3 -3
  44. package/runtime/examples/extensions/permission-gate.ts +2 -2
  45. package/runtime/examples/extensions/pirate.ts +4 -4
  46. package/runtime/examples/extensions/plan-mode/index.ts +21 -21
  47. package/runtime/examples/extensions/preset.ts +26 -26
  48. package/runtime/examples/extensions/project-trust.ts +7 -7
  49. package/runtime/examples/extensions/prompt-customizer.ts +3 -3
  50. package/runtime/examples/extensions/protected-paths.ts +2 -2
  51. package/runtime/examples/extensions/provider-payload.ts +3 -3
  52. package/runtime/examples/extensions/question.ts +2 -2
  53. package/runtime/examples/extensions/questionnaire.ts +2 -2
  54. package/runtime/examples/extensions/rainbow-editor.ts +3 -3
  55. package/runtime/examples/extensions/reload-runtime.ts +4 -4
  56. package/runtime/examples/extensions/rpc-demo.ts +10 -10
  57. package/runtime/examples/extensions/sandbox/index.ts +15 -15
  58. package/runtime/examples/extensions/sandbox/package-lock.json +4 -4
  59. package/runtime/examples/extensions/sandbox/package.json +3 -3
  60. package/runtime/examples/extensions/send-user-message.ts +13 -13
  61. package/runtime/examples/extensions/session-name.ts +4 -4
  62. package/runtime/examples/extensions/shutdown-command.ts +10 -10
  63. package/runtime/examples/extensions/snake.ts +3 -3
  64. package/runtime/examples/extensions/space-invaders.ts +3 -3
  65. package/runtime/examples/extensions/ssh.ts +12 -12
  66. package/runtime/examples/extensions/status-line.ts +4 -4
  67. package/runtime/examples/extensions/structured-output.ts +2 -2
  68. package/runtime/examples/extensions/subagent/index.ts +5 -5
  69. package/runtime/examples/extensions/system-prompt-header.ts +3 -3
  70. package/runtime/examples/extensions/tic-tac-toe.ts +15 -15
  71. package/runtime/examples/extensions/timed-confirm.ts +4 -4
  72. package/runtime/examples/extensions/titlebar-spinner.ts +11 -11
  73. package/runtime/examples/extensions/todo.ts +5 -5
  74. package/runtime/examples/extensions/tool-override.ts +5 -5
  75. package/runtime/examples/extensions/tools.ts +10 -10
  76. package/runtime/examples/extensions/trigger-compact.ts +3 -3
  77. package/runtime/examples/extensions/truncated-tool.ts +3 -3
  78. package/runtime/examples/extensions/widget-placement.ts +2 -2
  79. package/runtime/examples/extensions/with-deps/index.ts +2 -2
  80. package/runtime/examples/extensions/with-deps/package-lock.json +4 -4
  81. package/runtime/examples/extensions/with-deps/package.json +3 -3
  82. package/runtime/examples/extensions/working-indicator.ts +7 -7
  83. package/runtime/examples/extensions/working-message-test.ts +3 -3
  84. package/runtime/examples/sdk/01-minimal.ts +1 -1
  85. package/runtime/examples/sdk/03-custom-prompt.ts +1 -1
  86. package/runtime/examples/sdk/04-skills.ts +1 -1
  87. package/runtime/examples/sdk/05-tools.ts +1 -1
  88. package/runtime/examples/sdk/06-extensions.ts +11 -11
  89. package/runtime/examples/sdk/08-prompt-templates.ts +1 -1
  90. package/runtime/export-html/template.js +3 -3
  91. package/runtime/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
  92. package/runtime/package.json +8 -14
  93. package/runtime/theme/dark.json +0 -1
  94. package/runtime/theme/light.json +0 -1
  95. package/runtime/theme/theme-schema.json +2 -2
  96. package/runtime/valni +2 -2
  97. package/runtime/README.md +0 -674
  98. package/runtime/docs/extensions.md +0 -2910
  99. package/runtime/docs/json.md +0 -82
  100. package/runtime/docs/models.md +0 -540
  101. package/runtime/docs/packages.md +0 -228
  102. package/runtime/docs/rpc.md +0 -1480
  103. package/runtime/docs/sdk.md +0 -1183
  104. package/runtime/docs/session-format.md +0 -422
  105. package/runtime/docs/settings.md +0 -315
  106. package/runtime/docs/shell-aliases.md +0 -13
  107. package/runtime/docs/terminal-setup.md +0 -142
  108. package/runtime/docs/termux.md +0 -127
  109. package/runtime/docs/tmux.md +0 -63
  110. package/runtime/docs/tui.md +0 -927
  111. package/runtime/docs/windows.md +0 -17
  112. package/runtime/examples/README.md +0 -25
  113. package/runtime/examples/extensions/README.md +0 -212
  114. package/runtime/examples/extensions/doom-overlay/README.md +0 -46
  115. package/runtime/examples/extensions/dynamic-resources/SKILL.md +0 -8
  116. package/runtime/examples/extensions/dynamic-resources/dynamic.md +0 -5
  117. package/runtime/examples/extensions/gondolin/index.ts +0 -531
  118. package/runtime/examples/extensions/gondolin/package-lock.json +0 -185
  119. package/runtime/examples/extensions/gondolin/package.json +0 -19
  120. package/runtime/examples/extensions/plan-mode/README.md +0 -66
  121. package/runtime/examples/extensions/subagent/README.md +0 -175
  122. package/runtime/examples/extensions/subagent/agents/planner.md +0 -37
  123. package/runtime/examples/extensions/subagent/agents/reviewer.md +0 -35
  124. package/runtime/examples/extensions/subagent/agents/scout.md +0 -50
  125. package/runtime/examples/extensions/subagent/agents/worker.md +0 -24
  126. package/runtime/examples/extensions/subagent/prompts/implement-and-review.md +0 -10
  127. package/runtime/examples/extensions/subagent/prompts/implement.md +0 -10
  128. package/runtime/examples/extensions/subagent/prompts/scout-and-plan.md +0 -9
  129. package/runtime/examples/sdk/README.md +0 -140
  130. package/runtime/node_modules/@mariozechner/clipboard/.yarnrc.yml +0 -1
  131. package/runtime/node_modules/@mariozechner/clipboard/Cargo.toml +0 -45
  132. package/runtime/node_modules/@mariozechner/clipboard/README.md +0 -60
  133. package/runtime/node_modules/@mariozechner/clipboard/build.rs +0 -5
  134. package/runtime/node_modules/@mariozechner/clipboard/clipboard.darwin-x64.node +0 -0
  135. package/runtime/node_modules/@mariozechner/clipboard/exp.ts +0 -12
  136. package/runtime/node_modules/@mariozechner/clipboard/index.js +0 -606
  137. package/runtime/node_modules/@mariozechner/clipboard/package.json +0 -56
  138. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/common.rs +0 -307
  139. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/mod.rs +0 -93
  140. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/ios.rs +0 -313
  141. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/macos.rs +0 -471
  142. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/mod.rs +0 -252
  143. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/wayland.rs +0 -431
  144. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/win.rs +0 -712
  145. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/x11.rs +0 -916
  146. package/runtime/node_modules/@mariozechner/clipboard/src/lib.rs +0 -194
  147. package/runtime/node_modules/@mariozechner/clipboard-darwin-x64/README.md +0 -3
  148. package/runtime/node_modules/@mariozechner/clipboard-darwin-x64/clipboard.darwin-x64.node +0 -0
  149. package/runtime/node_modules/@mariozechner/clipboard-darwin-x64/package.json +0 -22
@@ -1,422 +0,0 @@
1
- # Session File Format
2
-
3
- Sessions are stored as JSONL (JSON Lines) files. Each line is a JSON object with a `type` field. Session entries form a tree structure via `id`/`parentId` fields, enabling in-place branching without creating new files.
4
-
5
- ## File Location
6
-
7
- ```
8
- ~/.valni/agent/sessions/--<path>--/<timestamp>_<uuid>.jsonl
9
- ```
10
-
11
- Where `<path>` is the working directory with `/` replaced by `-`.
12
-
13
- ## Deleting Sessions
14
-
15
- Sessions can be removed by deleting their `.jsonl` files under `~/.valni/agent/sessions/`.
16
-
17
- Pi also supports deleting sessions interactively from `/resume` (select a session and press `Ctrl+D`, then confirm). When available, valni uses the `trash` CLI to avoid permanent deletion.
18
-
19
- ## Session Version
20
-
21
- Sessions have a version field in the header:
22
-
23
- - **Version 1**: Linear entry sequence (legacy, auto-migrated on load)
24
- - **Version 2**: Tree structure with `id`/`parentId` linking
25
- - **Version 3**: Renamed `hookMessage` role to `custom` (extensions unification)
26
-
27
- Existing sessions are automatically migrated to the current version (v3) when loaded.
28
-
29
- ## Source Files
30
-
31
- Source on GitHub ([pi-mono](https://github.com/earendil-works/pi-mono)):
32
- - [`packages/coding-agent/src/core/session-manager.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/session-manager.ts) - Session entry types and SessionManager
33
- - [`packages/coding-agent/src/core/messages.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/messages.ts) - Extended message types (BashExecutionMessage, CustomMessage, etc.)
34
- - [`packages/ai/src/types.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/types.ts) - Base message types (UserMessage, AssistantMessage, ToolResultMessage)
35
- - [`packages/agent/src/types.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/agent/src/types.ts) - AgentMessage union type
36
-
37
- For TypeScript definitions in your project, inspect `node_modules/@valni/cli/dist/` and `node_modules/@valni/ai/dist/`.
38
-
39
- ## Message Types
40
-
41
- Session entries contain `AgentMessage` objects. Understanding these types is essential for parsing sessions and writing extensions.
42
-
43
- ### Content Blocks
44
-
45
- Messages contain arrays of typed content blocks:
46
-
47
- ```typescript
48
- interface TextContent {
49
- type: "text";
50
- text: string;
51
- }
52
-
53
- interface ImageContent {
54
- type: "image";
55
- data: string; // base64 encoded
56
- mimeType: string; // e.g., "image/jpeg", "image/png"
57
- }
58
-
59
- interface ThinkingContent {
60
- type: "thinking";
61
- thinking: string;
62
- }
63
-
64
- interface ToolCall {
65
- type: "toolCall";
66
- id: string;
67
- name: string;
68
- arguments: Record<string, any>;
69
- }
70
- ```
71
-
72
- ### Base Message Types (from pi-ai)
73
-
74
- ```typescript
75
- interface UserMessage {
76
- role: "user";
77
- content: string | (TextContent | ImageContent)[];
78
- timestamp: number; // Unix ms
79
- }
80
-
81
- interface AssistantMessage {
82
- role: "assistant";
83
- content: (TextContent | ThinkingContent | ToolCall)[];
84
- api: string;
85
- provider: string;
86
- model: string;
87
- usage: Usage;
88
- stopReason: "stop" | "length" | "toolUse" | "error" | "aborted";
89
- errorMessage?: string;
90
- timestamp: number;
91
- }
92
-
93
- interface ToolResultMessage {
94
- role: "toolResult";
95
- toolCallId: string;
96
- toolName: string;
97
- content: (TextContent | ImageContent)[];
98
- details?: any; // Tool-specific metadata
99
- isError: boolean;
100
- timestamp: number;
101
- }
102
-
103
- interface Usage {
104
- input: number;
105
- output: number;
106
- cacheRead: number;
107
- cacheWrite: number;
108
- totalTokens: number;
109
- cost: {
110
- input: number;
111
- output: number;
112
- cacheRead: number;
113
- cacheWrite: number;
114
- total: number;
115
- };
116
- }
117
- ```
118
-
119
- ### Extended Message Types (from pi-coding-agent)
120
-
121
- ```typescript
122
- interface BashExecutionMessage {
123
- role: "bashExecution";
124
- command: string;
125
- output: string;
126
- exitCode: number | undefined;
127
- cancelled: boolean;
128
- truncated: boolean;
129
- fullOutputPath?: string;
130
- excludeFromContext?: boolean; // true for !! prefix commands
131
- timestamp: number;
132
- }
133
-
134
- interface CustomMessage {
135
- role: "custom";
136
- customType: string; // Extension identifier
137
- content: string | (TextContent | ImageContent)[];
138
- display: boolean; // Show in TUI
139
- details?: any; // Extension-specific metadata
140
- timestamp: number;
141
- }
142
-
143
- interface BranchSummaryMessage {
144
- role: "branchSummary";
145
- summary: string;
146
- fromId: string; // Entry we branched from
147
- timestamp: number;
148
- }
149
-
150
- interface CompactionSummaryMessage {
151
- role: "compactionSummary";
152
- summary: string;
153
- tokensBefore: number;
154
- timestamp: number;
155
- }
156
- ```
157
-
158
- ### AgentMessage Union
159
-
160
- ```typescript
161
- type AgentMessage =
162
- | UserMessage
163
- | AssistantMessage
164
- | ToolResultMessage
165
- | BashExecutionMessage
166
- | CustomMessage
167
- | BranchSummaryMessage
168
- | CompactionSummaryMessage;
169
- ```
170
-
171
- ## Entry Base
172
-
173
- All entries (except `SessionHeader`) extend `SessionEntryBase`:
174
-
175
- ```typescript
176
- interface SessionEntryBase {
177
- type: string;
178
- id: string; // 8-char hex ID
179
- parentId: string | null; // Parent entry ID (null for first entry)
180
- timestamp: string; // ISO timestamp
181
- }
182
- ```
183
-
184
- ## Entry Types
185
-
186
- ### SessionHeader
187
-
188
- First line of the file. Metadata only, not part of the tree (no `id`/`parentId`).
189
-
190
- ```json
191
- {"type":"session","version":3,"id":"uuid","timestamp":"2024-12-03T14:00:00.000Z","cwd":"/path/to/project"}
192
- ```
193
-
194
- For sessions with a parent (created via `/fork`, `/clone`, or `newSession({ parentSession })`):
195
-
196
- ```json
197
- {"type":"session","version":3,"id":"uuid","timestamp":"2024-12-03T14:00:00.000Z","cwd":"/path/to/project","parentSession":"/path/to/original/session.jsonl"}
198
- ```
199
-
200
- ### SessionMessageEntry
201
-
202
- A message in the conversation. The `message` field contains an `AgentMessage`.
203
-
204
- ```json
205
- {"type":"message","id":"a1b2c3d4","parentId":"prev1234","timestamp":"2024-12-03T14:00:01.000Z","message":{"role":"user","content":"Hello"}}
206
- {"type":"message","id":"b2c3d4e5","parentId":"a1b2c3d4","timestamp":"2024-12-03T14:00:02.000Z","message":{"role":"assistant","content":[{"type":"text","text":"Hi!"}],"provider":"anthropic","model":"claude-sonnet-4-5","usage":{...},"stopReason":"stop"}}
207
- {"type":"message","id":"c3d4e5f6","parentId":"b2c3d4e5","timestamp":"2024-12-03T14:00:03.000Z","message":{"role":"toolResult","toolCallId":"call_123","toolName":"bash","content":[{"type":"text","text":"output"}],"isError":false}}
208
- ```
209
-
210
- ### ModelChangeEntry
211
-
212
- Emitted when the user switches models mid-session.
213
-
214
- ```json
215
- {"type":"model_change","id":"d4e5f6g7","parentId":"c3d4e5f6","timestamp":"2024-12-03T14:05:00.000Z","provider":"openai","modelId":"gpt-4o"}
216
- ```
217
-
218
- ### ThinkingLevelChangeEntry
219
-
220
- Emitted when the user changes the thinking/reasoning level.
221
-
222
- ```json
223
- {"type":"thinking_level_change","id":"e5f6g7h8","parentId":"d4e5f6g7","timestamp":"2024-12-03T14:06:00.000Z","thinkingLevel":"high"}
224
- ```
225
-
226
- ### CompactionEntry
227
-
228
- Created when context is compacted. Stores a summary of earlier messages.
229
-
230
- ```json
231
- {"type":"compaction","id":"f6g7h8i9","parentId":"e5f6g7h8","timestamp":"2024-12-03T14:10:00.000Z","summary":"User discussed X, Y, Z...","firstKeptEntryId":"c3d4e5f6","tokensBefore":50000}
232
- ```
233
-
234
- Optional fields:
235
- - `details`: Implementation-specific data (e.g., `{ readFiles: string[], modifiedFiles: string[] }` for default, or custom data for extensions)
236
- - `fromHook`: `true` if generated by an extension, `false`/`undefined` if pi-generated (legacy field name)
237
-
238
- ### BranchSummaryEntry
239
-
240
- Created when switching branches via `/tree` with an LLM generated summary of the left branch up to the common ancestor. Captures context from the abandoned path.
241
-
242
- ```json
243
- {"type":"branch_summary","id":"g7h8i9j0","parentId":"a1b2c3d4","timestamp":"2024-12-03T14:15:00.000Z","fromId":"f6g7h8i9","summary":"Branch explored approach A..."}
244
- ```
245
-
246
- Optional fields:
247
- - `details`: File tracking data (`{ readFiles: string[], modifiedFiles: string[] }`) for default, or custom data for extensions
248
- - `fromHook`: `true` if generated by an extension, `false`/`undefined` if pi-generated (legacy field name)
249
-
250
- ### CustomEntry
251
-
252
- Extension state persistence. Does NOT participate in LLM context.
253
-
254
- ```json
255
- {"type":"custom","id":"h8i9j0k1","parentId":"g7h8i9j0","timestamp":"2024-12-03T14:20:00.000Z","customType":"my-extension","data":{"count":42}}
256
- ```
257
-
258
- Use `customType` to identify your extension's entries on reload. Interactive mode can render custom entries via `pi.registerEntryRenderer(customType, renderer)`, but they still do not participate in LLM context.
259
-
260
- ### CustomMessageEntry
261
-
262
- Extension-injected messages that DO participate in LLM context.
263
-
264
- ```json
265
- {"type":"custom_message","id":"i9j0k1l2","parentId":"h8i9j0k1","timestamp":"2024-12-03T14:25:00.000Z","customType":"my-extension","content":"Injected context...","display":true}
266
- ```
267
-
268
- Fields:
269
- - `content`: String or `(TextContent | ImageContent)[]` (same as UserMessage)
270
- - `display`: `true` = show in TUI with distinct styling, `false` = hidden
271
- - `details`: Optional extension-specific metadata (not sent to LLM)
272
-
273
- ### LabelEntry
274
-
275
- User-defined bookmark/marker on an entry.
276
-
277
- ```json
278
- {"type":"label","id":"j0k1l2m3","parentId":"i9j0k1l2","timestamp":"2024-12-03T14:30:00.000Z","targetId":"a1b2c3d4","label":"checkpoint-1"}
279
- ```
280
-
281
- Set `label` to `undefined` to clear a label.
282
-
283
- ### SessionInfoEntry
284
-
285
- Session metadata (e.g., user-defined display name). Set via `/name`, `--name` / `-n`, or `pi.setSessionName()` in extensions.
286
-
287
- ```json
288
- {"type":"session_info","id":"k1l2m3n4","parentId":"j0k1l2m3","timestamp":"2024-12-03T14:35:00.000Z","name":"Refactor auth module"}
289
- ```
290
-
291
- The session name is displayed in the session selector (`/resume`) instead of the first message when set.
292
-
293
- ## Tree Structure
294
-
295
- Entries form a tree:
296
- - First entry has `parentId: null`
297
- - Each subsequent entry points to its parent via `parentId`
298
- - Branching creates new children from an earlier entry
299
- - The "leaf" is the current position in the tree
300
-
301
- ```
302
- [user msg] ─── [assistant] ─── [user msg] ─── [assistant] ─┬─ [user msg] ← current leaf
303
- │
304
- └─ [branch_summary] ─── [user msg] ← alternate branch
305
- ```
306
-
307
- ## Context Building
308
-
309
- `buildContextEntries()` walks from the current leaf to the root, producing the active entry list while honoring compaction:
310
-
311
- 1. Collects all entries on the path
312
- 2. If a `CompactionEntry` is on the path:
313
- - Includes the compaction entry first
314
- - Then entries from `firstKeptEntryId` to compaction
315
- - Then entries after compaction
316
- 3. Preserves non-message entries in the selected range so interactive mode can render them
317
-
318
- `buildSessionContext()` builds on that entry list to produce the message list for the LLM:
319
-
320
- 1. Extracts current model and thinking level settings from the full path
321
- 2. Converts selected entries to messages:
322
- - `message` -> stored `AgentMessage`
323
- - `compaction` -> `compactionSummary`
324
- - `branch_summary` -> `branchSummary`
325
- - `custom_message` -> `CustomMessage`
326
- - `custom` -> no context message
327
-
328
- ## Parsing Example
329
-
330
- ```typescript
331
- import { readFileSync } from "fs";
332
-
333
- const lines = readFileSync("session.jsonl", "utf8").trim().split("\n");
334
-
335
- for (const line of lines) {
336
- const entry = JSON.parse(line);
337
-
338
- switch (entry.type) {
339
- case "session":
340
- console.log(`Session v${entry.version ?? 1}: ${entry.id}`);
341
- break;
342
- case "message":
343
- console.log(`[${entry.id}] ${entry.message.role}: ${JSON.stringify(entry.message.content)}`);
344
- break;
345
- case "compaction":
346
- console.log(`[${entry.id}] Compaction: ${entry.tokensBefore} tokens summarized`);
347
- break;
348
- case "branch_summary":
349
- console.log(`[${entry.id}] Branch from ${entry.fromId}`);
350
- break;
351
- case "custom":
352
- console.log(`[${entry.id}] Custom (${entry.customType}): ${JSON.stringify(entry.data)}`);
353
- break;
354
- case "custom_message":
355
- console.log(`[${entry.id}] Extension message (${entry.customType}): ${entry.content}`);
356
- break;
357
- case "label":
358
- console.log(`[${entry.id}] Label "${entry.label}" on ${entry.targetId}`);
359
- break;
360
- case "model_change":
361
- console.log(`[${entry.id}] Model: ${entry.provider}/${entry.modelId}`);
362
- break;
363
- case "thinking_level_change":
364
- console.log(`[${entry.id}] Thinking: ${entry.thinkingLevel}`);
365
- break;
366
- }
367
- }
368
- ```
369
-
370
- ## SessionManager API
371
-
372
- Key methods for working with sessions programmatically.
373
-
374
- ### Static Creation Methods
375
- - `SessionManager.create(cwd, sessionDir?)` - New session
376
- - `SessionManager.open(path, sessionDir?)` - Open existing session file
377
- - `SessionManager.continueRecent(cwd, sessionDir?)` - Continue most recent or create new
378
- - `SessionManager.inMemory(cwd?)` - No file persistence
379
- - `SessionManager.forkFrom(sourcePath, targetCwd, sessionDir?)` - Fork session from another project
380
-
381
- ### Static Listing Methods
382
- - `SessionManager.list(cwd, sessionDir?, onProgress?)` - List sessions for a directory
383
- - `SessionManager.listAll(onProgress?)` - List all sessions across all projects
384
-
385
- ### Instance Methods - Session Management
386
- - `newSession(options?)` - Start a new session (options: `{ parentSession?: string }`)
387
- - `setSessionFile(path)` - Switch to a different session file
388
- - `createBranchedSession(leafId)` - Extract branch to new session file
389
-
390
- ### Instance Methods - Appending (all return entry ID)
391
- - `appendMessage(message)` - Add message
392
- - `appendThinkingLevelChange(level)` - Record thinking change
393
- - `appendModelChange(provider, modelId)` - Record model change
394
- - `appendCompaction(summary, firstKeptEntryId, tokensBefore, details?, fromHook?)` - Add compaction
395
- - `appendCustomEntry(customType, data?)` - Extension state (not in context)
396
- - `appendSessionInfo(name)` - Set session display name
397
- - `appendCustomMessageEntry(customType, content, display, details?)` - Extension message (in context)
398
- - `appendLabelChange(targetId, label)` - Set/clear label
399
-
400
- ### Instance Methods - Tree Navigation
401
- - `getLeafId()` - Current position
402
- - `getLeafEntry()` - Get current leaf entry
403
- - `getEntry(id)` - Get entry by ID
404
- - `getBranch(fromId?)` - Walk from entry to root
405
- - `getTree()` - Get full tree structure
406
- - `getChildren(parentId)` - Get direct children
407
- - `getLabel(id)` - Get label for entry
408
- - `branch(entryId)` - Move leaf to earlier entry
409
- - `resetLeaf()` - Reset leaf to null (before any entries)
410
- - `branchWithSummary(entryId, summary, details?, fromHook?)` - Branch with context summary
411
-
412
- ### Instance Methods - Context & Info
413
- - `buildContextEntries()` - Get active branch entries with compaction applied
414
- - `buildSessionContext()` - Get messages, thinkingLevel, and model for LLM
415
- - `getEntries()` - All entries (excluding header)
416
- - `getHeader()` - Session header metadata
417
- - `getSessionName()` - Get display name from latest session_info entry
418
- - `getCwd()` - Working directory
419
- - `getSessionDir()` - Session storage directory
420
- - `getSessionId()` - Session UUID
421
- - `getSessionFile()` - Session file path (undefined for in-memory)
422
- - `isPersisted()` - Whether session is saved to disk