indusagi-coding-agent 0.1.28 → 0.1.30

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 (147) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE.md +22 -0
  3. package/README.md +2 -0
  4. package/dist/core/messages.d.ts +1 -76
  5. package/dist/core/messages.d.ts.map +1 -1
  6. package/dist/core/messages.js +1 -122
  7. package/dist/core/messages.js.map +1 -1
  8. package/dist/core/session-manager.d.ts +1 -447
  9. package/dist/core/session-manager.d.ts.map +1 -1
  10. package/dist/core/session-manager.js +1 -1203
  11. package/dist/core/session-manager.js.map +1 -1
  12. package/package.json +2 -2
  13. package/docs/COMPLETE-GUIDE.md +0 -300
  14. package/docs/COMPREHENSIVE-CLI-SUMMARY.md +0 -900
  15. package/docs/MODES-ARCHITECTURE.md +0 -565
  16. package/docs/PRINT-MODE-GUIDE.md +0 -456
  17. package/docs/README.md +0 -78
  18. package/docs/RPC-GUIDE.md +0 -705
  19. package/docs/UTILS-IMPLEMENTATION-SUMMARY.md +0 -647
  20. package/docs/UTILS-MODULE-OVERVIEW.md +0 -1480
  21. package/docs/UTILS-QA-CHECKLIST.md +0 -1061
  22. package/docs/UTILS-USAGE-GUIDE.md +0 -1419
  23. package/docs/compaction.md +0 -390
  24. package/docs/custom-provider.md +0 -538
  25. package/docs/development.md +0 -69
  26. package/docs/extensions.md +0 -1733
  27. package/docs/hooks.md +0 -378
  28. package/docs/images/doom-extension.png +0 -0
  29. package/docs/images/interactive-mode.png +0 -0
  30. package/docs/images/tree-view.png +0 -0
  31. package/docs/json.md +0 -79
  32. package/docs/keybindings.md +0 -162
  33. package/docs/models.md +0 -193
  34. package/docs/packages.md +0 -163
  35. package/docs/prompt-templates.md +0 -67
  36. package/docs/providers.md +0 -147
  37. package/docs/rpc.md +0 -1048
  38. package/docs/sdk.md +0 -969
  39. package/docs/session.md +0 -412
  40. package/docs/settings.md +0 -219
  41. package/docs/shell-aliases.md +0 -13
  42. package/docs/skills.md +0 -226
  43. package/docs/subagents.md +0 -225
  44. package/docs/terminal-setup.md +0 -65
  45. package/docs/themes.md +0 -295
  46. package/docs/tree.md +0 -219
  47. package/docs/tui.md +0 -887
  48. package/docs/web-tools.md +0 -304
  49. package/docs/windows.md +0 -17
  50. package/examples/README.md +0 -25
  51. package/examples/extensions/README.md +0 -192
  52. package/examples/extensions/antigravity-image-gen.ts +0 -414
  53. package/examples/extensions/auto-commit-on-exit.ts +0 -49
  54. package/examples/extensions/bookmark.ts +0 -50
  55. package/examples/extensions/claude-rules.ts +0 -86
  56. package/examples/extensions/confirm-destructive.ts +0 -59
  57. package/examples/extensions/custom-compaction.ts +0 -115
  58. package/examples/extensions/custom-footer.ts +0 -65
  59. package/examples/extensions/custom-header.ts +0 -73
  60. package/examples/extensions/custom-provider-anthropic/index.ts +0 -605
  61. package/examples/extensions/custom-provider-anthropic/package-lock.json +0 -24
  62. package/examples/extensions/custom-provider-anthropic/package.json +0 -19
  63. package/examples/extensions/custom-provider-gitlab-duo/index.ts +0 -350
  64. package/examples/extensions/custom-provider-gitlab-duo/package.json +0 -16
  65. package/examples/extensions/custom-provider-gitlab-duo/test.ts +0 -83
  66. package/examples/extensions/dirty-repo-guard.ts +0 -56
  67. package/examples/extensions/doom-overlay/README.md +0 -46
  68. package/examples/extensions/doom-overlay/doom/build/doom.js +0 -21
  69. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  70. package/examples/extensions/doom-overlay/doom/build.sh +0 -152
  71. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +0 -72
  72. package/examples/extensions/doom-overlay/doom-component.ts +0 -133
  73. package/examples/extensions/doom-overlay/doom-engine.ts +0 -173
  74. package/examples/extensions/doom-overlay/doom-keys.ts +0 -105
  75. package/examples/extensions/doom-overlay/index.ts +0 -74
  76. package/examples/extensions/doom-overlay/wad-finder.ts +0 -51
  77. package/examples/extensions/event-bus.ts +0 -43
  78. package/examples/extensions/file-trigger.ts +0 -41
  79. package/examples/extensions/git-checkpoint.ts +0 -53
  80. package/examples/extensions/handoff.ts +0 -151
  81. package/examples/extensions/hello.ts +0 -25
  82. package/examples/extensions/inline-bash.ts +0 -94
  83. package/examples/extensions/input-transform.ts +0 -43
  84. package/examples/extensions/interactive-shell.ts +0 -196
  85. package/examples/extensions/mac-system-theme.ts +0 -47
  86. package/examples/extensions/message-renderer.ts +0 -60
  87. package/examples/extensions/modal-editor.ts +0 -86
  88. package/examples/extensions/model-status.ts +0 -31
  89. package/examples/extensions/notify.ts +0 -25
  90. package/examples/extensions/overlay-qa-tests.ts +0 -882
  91. package/examples/extensions/overlay-test.ts +0 -151
  92. package/examples/extensions/permission-gate.ts +0 -34
  93. package/examples/extensions/pirate.ts +0 -47
  94. package/examples/extensions/plan-mode/README.md +0 -65
  95. package/examples/extensions/plan-mode/index.ts +0 -341
  96. package/examples/extensions/plan-mode/utils.ts +0 -168
  97. package/examples/extensions/preset.ts +0 -399
  98. package/examples/extensions/protected-paths.ts +0 -30
  99. package/examples/extensions/qna.ts +0 -120
  100. package/examples/extensions/question.ts +0 -265
  101. package/examples/extensions/questionnaire.ts +0 -428
  102. package/examples/extensions/rainbow-editor.ts +0 -88
  103. package/examples/extensions/sandbox/index.ts +0 -318
  104. package/examples/extensions/sandbox/package-lock.json +0 -92
  105. package/examples/extensions/sandbox/package.json +0 -19
  106. package/examples/extensions/send-user-message.ts +0 -97
  107. package/examples/extensions/session-name.ts +0 -27
  108. package/examples/extensions/shutdown-command.ts +0 -63
  109. package/examples/extensions/snake.ts +0 -344
  110. package/examples/extensions/space-invaders.ts +0 -561
  111. package/examples/extensions/ssh.ts +0 -220
  112. package/examples/extensions/status-line.ts +0 -40
  113. package/examples/extensions/subagent/README.md +0 -172
  114. package/examples/extensions/subagent/agents/planner.md +0 -37
  115. package/examples/extensions/subagent/agents/reviewer.md +0 -35
  116. package/examples/extensions/subagent/agents/scout.md +0 -50
  117. package/examples/extensions/subagent/agents/worker.md +0 -24
  118. package/examples/extensions/subagent/agents.ts +0 -127
  119. package/examples/extensions/subagent/index.ts +0 -964
  120. package/examples/extensions/subagent/prompts/implement-and-review.md +0 -10
  121. package/examples/extensions/subagent/prompts/implement.md +0 -10
  122. package/examples/extensions/subagent/prompts/scout-and-plan.md +0 -9
  123. package/examples/extensions/summarize.ts +0 -196
  124. package/examples/extensions/timed-confirm.ts +0 -70
  125. package/examples/extensions/todo.ts +0 -300
  126. package/examples/extensions/tool-override.ts +0 -144
  127. package/examples/extensions/tools.ts +0 -147
  128. package/examples/extensions/trigger-compact.ts +0 -40
  129. package/examples/extensions/truncated-tool.ts +0 -193
  130. package/examples/extensions/widget-placement.ts +0 -17
  131. package/examples/extensions/with-deps/index.ts +0 -36
  132. package/examples/extensions/with-deps/package-lock.json +0 -31
  133. package/examples/extensions/with-deps/package.json +0 -22
  134. package/examples/sdk/01-minimal.ts +0 -22
  135. package/examples/sdk/02-custom-model.ts +0 -50
  136. package/examples/sdk/03-custom-prompt.ts +0 -55
  137. package/examples/sdk/04-skills.ts +0 -46
  138. package/examples/sdk/05-tools.ts +0 -56
  139. package/examples/sdk/06-extensions.ts +0 -88
  140. package/examples/sdk/07-context-files.ts +0 -40
  141. package/examples/sdk/08-prompt-templates.ts +0 -47
  142. package/examples/sdk/09-api-keys-and-oauth.ts +0 -48
  143. package/examples/sdk/10-settings.ts +0 -38
  144. package/examples/sdk/11-sessions.ts +0 -48
  145. package/examples/sdk/12-full-control.ts +0 -82
  146. package/examples/sdk/13-codex-oauth.ts +0 -37
  147. package/examples/sdk/README.md +0 -144
package/docs/themes.md DELETED
@@ -1,295 +0,0 @@
1
- > indusagi can create themes. Ask it to build one for your setup.
2
-
3
- # Themes
4
-
5
- Themes are JSON files that define colors for the TUI.
6
-
7
- ## Table of Contents
8
-
9
- - [Locations](#locations)
10
- - [Selecting a Theme](#selecting-a-theme)
11
- - [Creating a Custom Theme](#creating-a-custom-theme)
12
- - [Theme Format](#theme-format)
13
- - [Color Tokens](#color-tokens)
14
- - [Color Values](#color-values)
15
- - [Tips](#tips)
16
-
17
- ## Locations
18
-
19
- Indusagi loads themes from:
20
-
21
- - Built-in: `dark`, `light`
22
- - Global: `~/.indusagi/agent/themes/*.json`
23
- - Project: `.indusagi/themes/*.json`
24
- - Packages: `themes/` directories or `indusagi.themes` entries in `package.json`
25
- - Settings: `themes` array with files or directories
26
- - CLI: `--theme <path>` (repeatable)
27
-
28
- Disable discovery with `--no-themes`.
29
-
30
- ## Selecting a Theme
31
-
32
- Select a theme via `/settings` or in `settings.json`:
33
-
34
- ```json
35
- {
36
- "theme": "my-theme"
37
- }
38
- ```
39
-
40
- On first run, indusagi detects your terminal background and defaults to `dark` or `light`.
41
-
42
- ## Creating a Custom Theme
43
-
44
- 1. Create a theme file:
45
-
46
- ```bash
47
- mkdir -p ~/.indusagi/agent/themes
48
- vim ~/.indusagi/agent/themes/my-theme.json
49
- ```
50
-
51
- 2. Define the theme with all required colors (see [Color Tokens](#color-tokens)):
52
-
53
- ```json
54
- {
55
- "$schema": "https://raw.githubusercontent.com/badlogic/indusagi-mono/main/packages/coding-agent/src/modes/interactive/theme/theme-schema.json",
56
- "name": "my-theme",
57
- "vars": {
58
- "primary": "#00aaff",
59
- "secondary": 242
60
- },
61
- "colors": {
62
- "accent": "primary",
63
- "border": "primary",
64
- "borderAccent": "#00ffff",
65
- "borderMuted": "secondary",
66
- "success": "#00ff00",
67
- "error": "#ff0000",
68
- "warning": "#ffff00",
69
- "muted": "secondary",
70
- "dim": 240,
71
- "text": "",
72
- "thinkingText": "secondary",
73
- "selectedBg": "#2d2d30",
74
- "userMessageBg": "#2d2d30",
75
- "userMessageText": "",
76
- "customMessageBg": "#2d2d30",
77
- "customMessageText": "",
78
- "customMessageLabel": "primary",
79
- "toolPendingBg": "#1e1e2e",
80
- "toolSuccessBg": "#1e2e1e",
81
- "toolErrorBg": "#2e1e1e",
82
- "toolTitle": "primary",
83
- "toolOutput": "",
84
- "mdHeading": "#ffaa00",
85
- "mdLink": "primary",
86
- "mdLinkUrl": "secondary",
87
- "mdCode": "#00ffff",
88
- "mdCodeBlock": "",
89
- "mdCodeBlockBorder": "secondary",
90
- "mdQuote": "secondary",
91
- "mdQuoteBorder": "secondary",
92
- "mdHr": "secondary",
93
- "mdListBullet": "#00ffff",
94
- "toolDiffAdded": "#00ff00",
95
- "toolDiffRemoved": "#ff0000",
96
- "toolDiffContext": "secondary",
97
- "syntaxComment": "secondary",
98
- "syntaxKeyword": "primary",
99
- "syntaxFunction": "#00aaff",
100
- "syntaxVariable": "#ffaa00",
101
- "syntaxString": "#00ff00",
102
- "syntaxNumber": "#ff00ff",
103
- "syntaxType": "#00aaff",
104
- "syntaxOperator": "primary",
105
- "syntaxPunctuation": "secondary",
106
- "thinkingOff": "secondary",
107
- "thinkingMinimal": "primary",
108
- "thinkingLow": "#00aaff",
109
- "thinkingMedium": "#00ffff",
110
- "thinkingHigh": "#ff00ff",
111
- "thinkingXhigh": "#ff0000",
112
- "bashMode": "#ffaa00"
113
- }
114
- }
115
- ```
116
-
117
- 3. Select the theme via `/settings`.
118
-
119
- **Hot reload:** When you edit the currently active custom theme file, indusagi reloads it automatically for immediate visual feedback.
120
-
121
- ## Theme Format
122
-
123
- ```json
124
- {
125
- "$schema": "https://raw.githubusercontent.com/badlogic/indusagi-mono/main/packages/coding-agent/src/modes/interactive/theme/theme-schema.json",
126
- "name": "my-theme",
127
- "vars": {
128
- "blue": "#0066cc",
129
- "gray": 242
130
- },
131
- "colors": {
132
- "accent": "blue",
133
- "muted": "gray",
134
- "text": "",
135
- ...
136
- }
137
- }
138
- ```
139
-
140
- - `name` is required and must be unique.
141
- - `vars` is optional. Define reusable colors here, then reference them in `colors`.
142
- - `colors` must define all 51 required tokens.
143
-
144
- The `$schema` field enables editor auto-completion and validation.
145
-
146
- ## Color Tokens
147
-
148
- Every theme must define all 51 color tokens. There are no optional colors.
149
-
150
- ### Core UI (11 colors)
151
-
152
- | Token | Purpose |
153
- |-------|---------|
154
- | `accent` | Primary accent (logo, selected items, cursor) |
155
- | `border` | Normal borders |
156
- | `borderAccent` | Highlighted borders |
157
- | `borderMuted` | Subtle borders (editor) |
158
- | `success` | Success states |
159
- | `error` | Error states |
160
- | `warning` | Warning states |
161
- | `muted` | Secondary text |
162
- | `dim` | Tertiary text |
163
- | `text` | Default text (usually `""`) |
164
- | `thinkingText` | Thinking block text |
165
-
166
- ### Backgrounds & Content (11 colors)
167
-
168
- | Token | Purpose |
169
- |-------|---------|
170
- | `selectedBg` | Selected line background |
171
- | `userMessageBg` | User message background |
172
- | `userMessageText` | User message text |
173
- | `customMessageBg` | Extension message background |
174
- | `customMessageText` | Extension message text |
175
- | `customMessageLabel` | Extension message label |
176
- | `toolPendingBg` | Tool box (pending) |
177
- | `toolSuccessBg` | Tool box (success) |
178
- | `toolErrorBg` | Tool box (error) |
179
- | `toolTitle` | Tool title |
180
- | `toolOutput` | Tool output text |
181
-
182
- ### Markdown (10 colors)
183
-
184
- | Token | Purpose |
185
- |-------|---------|
186
- | `mdHeading` | Headings |
187
- | `mdLink` | Link text |
188
- | `mdLinkUrl` | Link URL |
189
- | `mdCode` | Inline code |
190
- | `mdCodeBlock` | Code block content |
191
- | `mdCodeBlockBorder` | Code block fences |
192
- | `mdQuote` | Blockquote text |
193
- | `mdQuoteBorder` | Blockquote border |
194
- | `mdHr` | Horizontal rule |
195
- | `mdListBullet` | List bullets |
196
-
197
- ### Tool Diffs (3 colors)
198
-
199
- | Token | Purpose |
200
- |-------|---------|
201
- | `toolDiffAdded` | Added lines |
202
- | `toolDiffRemoved` | Removed lines |
203
- | `toolDiffContext` | Context lines |
204
-
205
- ### Syntax Highlighting (9 colors)
206
-
207
- | Token | Purpose |
208
- |-------|---------|
209
- | `syntaxComment` | Comments |
210
- | `syntaxKeyword` | Keywords |
211
- | `syntaxFunction` | Function names |
212
- | `syntaxVariable` | Variables |
213
- | `syntaxString` | Strings |
214
- | `syntaxNumber` | Numbers |
215
- | `syntaxType` | Types |
216
- | `syntaxOperator` | Operators |
217
- | `syntaxPunctuation` | Punctuation |
218
-
219
- ### Thinking Level Borders (6 colors)
220
-
221
- Editor border colors indicating thinking level (visual hierarchy from subtle to prominent):
222
-
223
- | Token | Purpose |
224
- |-------|---------|
225
- | `thinkingOff` | Thinking off |
226
- | `thinkingMinimal` | Minimal thinking |
227
- | `thinkingLow` | Low thinking |
228
- | `thinkingMedium` | Medium thinking |
229
- | `thinkingHigh` | High thinking |
230
- | `thinkingXhigh` | Extra high thinking |
231
-
232
- ### Bash Mode (1 color)
233
-
234
- | Token | Purpose |
235
- |-------|---------|
236
- | `bashMode` | Editor border in bash mode (`!` prefix) |
237
-
238
- ### HTML Export (optional)
239
-
240
- The `export` section controls colors for `/export` HTML output. If omitted, colors are derived from `userMessageBg`.
241
-
242
- ```json
243
- {
244
- "export": {
245
- "pageBg": "#18181e",
246
- "cardBg": "#1e1e24",
247
- "infoBg": "#3c3728"
248
- }
249
- }
250
- ```
251
-
252
- ## Color Values
253
-
254
- Four formats are supported:
255
-
256
- | Format | Example | Description |
257
- |--------|---------|-------------|
258
- | Hex | `"#ff0000"` | 6-digit hex RGB |
259
- | 256-color | `39` | xterm 256-color palette index (0-255) |
260
- | Variable | `"primary"` | Reference to a `vars` entry |
261
- | Default | `""` | Terminal's default color |
262
-
263
- ### 256-Color Palette
264
-
265
- - `0-15`: Basic ANSI colors (terminal-dependent)
266
- - `16-231`: 6×6×6 RGB cube (`16 + 36×R + 6×G + B` where R,G,B are 0-5)
267
- - `232-255`: Grayscale ramp
268
-
269
- ### Terminal Compatibility
270
-
271
- Indusagi uses 24-bit RGB colors. Most modern terminals support this (iTerm2, Kitty, WezTerm, Windows Terminal, VS Code). For older terminals with only 256-color support, indusagi falls back to the nearest approximation.
272
-
273
- Check truecolor support:
274
-
275
- ```bash
276
- echo $COLORTERM # Should output "truecolor" or "24bit"
277
- ```
278
-
279
- ## Tips
280
-
281
- **Dark terminals:** Use bright, saturated colors with higher contrast.
282
-
283
- **Light terminals:** Use darker, muted colors with lower contrast.
284
-
285
- **Color harmony:** Start with a base palette (Nord, Gruvbox, Tokyo Night), define it in `vars`, and reference consistently.
286
-
287
- **Testing:** Check your theme with different message types, tool states, markdown content, and long wrapped text.
288
-
289
- **VS Code:** Set `terminal.integrated.minimumContrastRatio` to `1` for accurate colors.
290
-
291
- ## Examples
292
-
293
- See the built-in themes:
294
- - [dark.json](../src/modes/interactive/theme/dark.json)
295
- - [light.json](../src/modes/interactive/theme/light.json)
package/docs/tree.md DELETED
@@ -1,219 +0,0 @@
1
- # Session Tree Navigation
2
-
3
- The `/tree` command provides tree-based navigation of the session history.
4
-
5
- ## Overview
6
-
7
- Sessions are stored as trees where each entry has an `id` and `parentId`. The "leaf" pointer tracks the current position. `/tree` lets you navigate to any point and optionally summarize the branch you're leaving.
8
-
9
- ### Comparison with `/fork`
10
-
11
- | Feature | `/fork` | `/tree` |
12
- |---------|---------|---------|
13
- | View | Flat list of user messages | Full tree structure |
14
- | Action | Extracts path to **new session file** | Changes leaf in **same session** |
15
- | Summary | Never | Optional (user prompted) |
16
- | Events | `session_before_fork` / `session_fork` | `session_before_tree` / `session_tree` |
17
-
18
- ## Tree UI
19
-
20
- ```
21
- ├─ user: "Hello, can you help..."
22
- │ └─ assistant: "Of course! I can..."
23
- │ ├─ user: "Let's try approach A..."
24
- │ │ └─ assistant: "For approach A..."
25
- │ │ └─ [compaction: 12k tokens]
26
- │ │ └─ user: "That worked..." ← active
27
- │ └─ user: "Actually, approach B..."
28
- │ └─ assistant: "For approach B..."
29
- ```
30
-
31
- ### Controls
32
-
33
- | Key | Action |
34
- |-----|--------|
35
- | ↑/↓ | Navigate (depth-first order) |
36
- | Enter | Select node |
37
- | Escape/Ctrl+C | Cancel |
38
- | Ctrl+U | Toggle: user messages only |
39
- | Ctrl+O | Toggle: show all (including custom/label entries) |
40
-
41
- ### Display
42
-
43
- - Height: half terminal height
44
- - Current leaf marked with `← active`
45
- - Labels shown inline: `[label-name]`
46
- - Default filter hides `label` and `custom` entries (shown in Ctrl+O mode)
47
- - Children sorted by timestamp (oldest first)
48
-
49
- ## Selection Behavior
50
-
51
- ### User Message or Custom Message
52
- 1. Leaf set to **parent** of selected node (or `null` if root)
53
- 2. Message text placed in **editor** for re-submission
54
- 3. User edits and submits, creating a new branch
55
-
56
- ### Non-User Message (assistant, compaction, etc.)
57
- 1. Leaf set to **selected node**
58
- 2. Editor stays empty
59
- 3. User continues from that point
60
-
61
- ### Selecting Root User Message
62
- If user selects the very first message (has no parent):
63
- 1. Leaf reset to `null` (empty conversation)
64
- 2. Message text placed in editor
65
- 3. User effectively restarts from scratch
66
-
67
- ## Branch Summarization
68
-
69
- When switching branches, user is presented with three options:
70
-
71
- 1. **No summary** - Switch immediately without summarizing
72
- 2. **Summarize** - Generate a summary using the default prompt
73
- 3. **Summarize with custom prompt** - Opens an editor to enter additional focus instructions that are appended to the default summarization prompt
74
-
75
- ### What Gets Summarized
76
-
77
- Path from old leaf back to common ancestor with target:
78
-
79
- ```
80
- A → B → C → D → E → F ← old leaf
81
- ↘ G → H ← target
82
- ```
83
-
84
- Abandoned path: D → E → F (summarized)
85
-
86
- Summarization stops at:
87
- 1. Common ancestor (always)
88
- 2. Compaction node (if encountered first)
89
-
90
- ### Summary Storage
91
-
92
- Stored as `BranchSummaryEntry`:
93
-
94
- ```typescript
95
- interface BranchSummaryEntry {
96
- type: "branch_summary";
97
- id: string;
98
- parentId: string; // New leaf position
99
- timestamp: string;
100
- fromId: string; // Old leaf we abandoned
101
- summary: string; // LLM-generated summary
102
- details?: unknown; // Optional hook data
103
- }
104
- ```
105
-
106
- ## Implementation
107
-
108
- ### AgentSession.navigateTree()
109
-
110
- ```typescript
111
- async navigateTree(
112
- targetId: string,
113
- options?: {
114
- summarize?: boolean;
115
- customInstructions?: string;
116
- replaceInstructions?: boolean;
117
- label?: string;
118
- }
119
- ): Promise<{ editorText?: string; cancelled: boolean }>
120
- ```
121
-
122
- Options:
123
- - `summarize`: Whether to generate a summary of the abandoned branch
124
- - `customInstructions`: Custom instructions for the summarizer
125
- - `replaceInstructions`: If true, `customInstructions` replaces the default prompt instead of being appended
126
- - `label`: Label to attach to the branch summary entry (or target entry if not summarizing)
127
-
128
- Flow:
129
- 1. Validate target, check no-op (target === current leaf)
130
- 2. Find common ancestor between old leaf and target
131
- 3. Collect entries to summarize (if requested)
132
- 4. Fire `session_before_tree` event (hook can cancel or provide summary)
133
- 5. Run default summarizer if needed
134
- 6. Switch leaf via `branch()` or `branchWithSummary()`
135
- 7. Update agent: `agent.replaceMessages(sessionManager.buildSessionContext().messages)`
136
- 8. Fire `session_tree` event
137
- 9. Notify custom tools via session event
138
- 10. Return result with `editorText` if user message was selected
139
-
140
- ### SessionManager
141
-
142
- - `getLeafUuid(): string | null` - Current leaf (null if empty)
143
- - `resetLeaf(): void` - Set leaf to null (for root user message navigation)
144
- - `getTree(): SessionTreeNode[]` - Full tree with children sorted by timestamp
145
- - `branch(id)` - Change leaf pointer
146
- - `branchWithSummary(id, summary)` - Change leaf and create summary entry
147
-
148
- ### InteractiveMode
149
-
150
- `/tree` command shows `TreeSelectorComponent`, then:
151
- 1. Prompt for summarization
152
- 2. Call `session.navigateTree()`
153
- 3. Clear and re-render chat
154
- 4. Set editor text if applicable
155
-
156
- ## Hook Events
157
-
158
- ### `session_before_tree`
159
-
160
- ```typescript
161
- interface TreePreparation {
162
- targetId: string;
163
- oldLeafId: string | null;
164
- commonAncestorId: string | null;
165
- entriesToSummarize: SessionEntry[];
166
- userWantsSummary: boolean;
167
- customInstructions?: string;
168
- replaceInstructions?: boolean;
169
- label?: string;
170
- }
171
-
172
- interface SessionBeforeTreeEvent {
173
- type: "session_before_tree";
174
- preparation: TreePreparation;
175
- signal: AbortSignal;
176
- }
177
-
178
- interface SessionBeforeTreeResult {
179
- cancel?: boolean;
180
- summary?: { summary: string; details?: unknown };
181
- customInstructions?: string; // Override custom instructions
182
- replaceInstructions?: boolean; // Override replace mode
183
- label?: string; // Override label
184
- }
185
- ```
186
-
187
- Extensions can override `customInstructions`, `replaceInstructions`, and `label` by returning them from the `session_before_tree` handler.
188
-
189
- ### `session_tree`
190
-
191
- ```typescript
192
- interface SessionTreeEvent {
193
- type: "session_tree";
194
- newLeafId: string | null;
195
- oldLeafId: string | null;
196
- summaryEntry?: BranchSummaryEntry;
197
- fromHook?: boolean;
198
- }
199
- ```
200
-
201
- ### Example: Custom Summarizer
202
-
203
- ```typescript
204
- export default function(indusagi: HookAPI) {
205
- indusagi.on("session_before_tree", async (event, ctx) => {
206
- if (!event.preparation.userWantsSummary) return;
207
- if (event.preparation.entriesToSummarize.length === 0) return;
208
-
209
- const summary = await myCustomSummarizer(event.preparation.entriesToSummarize);
210
- return { summary: { summary, details: { custom: true } } };
211
- });
212
- }
213
- ```
214
-
215
- ## Error Handling
216
-
217
- - Summarization failure: cancels navigation, shows error
218
- - User abort (Escape): cancels navigation
219
- - Hook returns `cancel: true`: cancels navigation silently