@kabmo-labs/kabmo 0.24.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +579 -510
  3. package/dist/client/static/js/index-bc9aa4mx.css +1 -0
  4. package/dist/client/static/js/{index-jcr5twtp.js → index-ga8cbpt4.js} +1072 -1174
  5. package/package.json +2 -4
  6. package/src/cli/lib/args.js +24 -1
  7. package/src/cli/lib/args.test.js +16 -0
  8. package/src/cli/lib/commands/session.js +233 -0
  9. package/src/cli/lib/commands/session.test.js +103 -0
  10. package/src/cli/main.js +1 -1
  11. package/src/client/components/common/ComposerPicker.tsx +3 -0
  12. package/src/client/components/common/code-surface/shiki.test.ts +82 -0
  13. package/src/client/components/common/code-surface/shiki.ts +28 -7
  14. package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +113 -0
  15. package/src/client/components/common/session-actions-menu/index.tsx +33 -2
  16. package/src/client/components/common/session-row/StatusSlot.tsx +4 -4
  17. package/src/client/components/common/session-row/index.tsx +27 -1
  18. package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
  19. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +25 -12
  20. package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +66 -0
  21. package/src/client/components/layout/session-sidebar/SessionItem.tsx +28 -3
  22. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +36 -5
  23. package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +94 -0
  24. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
  25. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +120 -0
  26. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +47 -0
  27. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +28 -35
  28. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +18 -5
  29. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +21 -4
  30. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +27 -5
  31. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
  32. package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
  33. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +135 -118
  34. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
  35. package/src/client/components/workspace/chat-timeline/MessageList.tsx +4 -0
  36. package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
  37. package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
  38. package/src/client/components/workspace/chat-timeline/index.tsx +3 -1
  39. package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
  40. package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
  41. package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
  42. package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
  43. package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
  44. package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
  45. package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
  46. package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
  47. package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
  48. package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
  49. package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
  50. package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
  51. package/src/client/data/settings/omp-schema.json +1 -1
  52. package/src/client/data/theme/terminal.test.ts +25 -0
  53. package/src/client/data/theme/terminal.ts +96 -79
  54. package/src/client/hooks/chat/composer/items.test.ts +12 -26
  55. package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
  56. package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
  57. package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
  58. package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
  59. package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
  60. package/src/client/hooks/chat/timeline/send-execute.test.ts +39 -0
  61. package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
  62. package/src/client/hooks/chat/timeline/send-steer.test.ts +3 -1
  63. package/src/client/hooks/chat/timeline/send.test-util.ts +7 -1
  64. package/src/client/hooks/chat/timeline/send.test.ts +3 -1
  65. package/src/client/hooks/chat/timeline/send.ts +51 -50
  66. package/src/client/hooks/chat/timeline/use-fork-session.ts +49 -0
  67. package/src/client/hooks/models/use-harness-update.test.ts +193 -0
  68. package/src/client/hooks/models/use-harness-update.ts +202 -0
  69. package/src/client/hooks/workspace/child-expansion.ts +33 -0
  70. package/src/client/hooks/workspace/terminal/index.ts +17 -3
  71. package/src/client/hooks/workspace/terminal/socket.ts +9 -4
  72. package/src/client/lib/session-tree.test.ts +50 -0
  73. package/src/client/lib/session-tree.ts +59 -0
  74. package/src/client/tailwind.css +17 -11
  75. package/src/server/index.ts +2 -0
  76. package/src/server/lib/auth/guard.ts +10 -0
  77. package/src/server/lib/btw/session-copy.server.ts +6 -44
  78. package/src/server/lib/btw/session-copy.test.ts +2 -1
  79. package/src/server/lib/db/schema.ts +4 -0
  80. package/src/server/lib/db/seed-terminal.test.ts +1 -1
  81. package/src/server/lib/db/seed.test.ts +1 -1
  82. package/src/server/lib/harness/acp/background-work.test.ts +262 -0
  83. package/src/server/lib/harness/acp/background-work.ts +320 -0
  84. package/src/server/lib/harness/acp/client.ts +2 -2
  85. package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
  86. package/src/server/lib/harness/acp/gateway-env.ts +70 -0
  87. package/src/server/lib/harness/acp/prompt.test.ts +20 -0
  88. package/src/server/lib/harness/acp/prompt.ts +19 -3
  89. package/src/server/lib/harness/acp/session-background.test.ts +129 -0
  90. package/src/server/lib/harness/acp/session-exit.ts +31 -0
  91. package/src/server/lib/harness/acp/session-handshake.test.ts +108 -0
  92. package/src/server/lib/harness/acp/session-handshake.ts +27 -1
  93. package/src/server/lib/harness/acp/session-listeners.ts +31 -0
  94. package/src/server/lib/harness/acp/session-requests.ts +47 -0
  95. package/src/server/lib/harness/acp/session-turns.ts +20 -5
  96. package/src/server/lib/harness/acp/session.test-util.ts +23 -1
  97. package/src/server/lib/harness/acp/session.ts +59 -59
  98. package/src/server/lib/harness/acp/turn.test.ts +81 -0
  99. package/src/server/lib/harness/acp/turn.ts +26 -9
  100. package/src/server/lib/harness/acp/verbs.ts +12 -2
  101. package/src/server/lib/harness/launch.ts +3 -1
  102. package/src/server/lib/harness/spawn.server.ts +15 -2
  103. package/src/server/lib/harness/update-job-store.test.ts +126 -0
  104. package/src/server/lib/harness/update-job-store.ts +109 -0
  105. package/src/server/lib/harness/update-job.server.ts +203 -0
  106. package/src/server/lib/harness/update-worker.test.ts +153 -0
  107. package/src/server/lib/harness/update-worker.ts +197 -0
  108. package/src/server/lib/lifecycle/paths.ts +23 -0
  109. package/src/server/lib/omp/rpc/manager.ts +5 -5
  110. package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
  111. package/src/server/lib/omp/rpc/session-registry.ts +14 -2
  112. package/src/server/lib/omp/rpc/terminal-settle.ts +53 -5
  113. package/src/server/lib/omp/session/delete-flow.server.ts +47 -0
  114. package/src/server/lib/omp/session/delete.server.ts +5 -0
  115. package/src/server/lib/omp/session/rewind-file.ts +39 -21
  116. package/src/server/lib/omp/session/sidebar-data.server.ts +6 -6
  117. package/src/server/lib/omp/session/transcript-copy.ts +123 -0
  118. package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
  119. package/src/server/lib/sessions/agent-token.server.ts +134 -0
  120. package/src/server/lib/sessions/answers.server.test.ts +33 -0
  121. package/src/server/lib/sessions/answers.server.ts +37 -0
  122. package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
  123. package/src/server/lib/sessions/dispatch.server.ts +128 -0
  124. package/src/server/lib/sessions/fork.server.test.ts +209 -0
  125. package/src/server/lib/sessions/fork.server.ts +304 -0
  126. package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
  127. package/src/server/lib/sessions/lifecycle.server.ts +71 -0
  128. package/src/server/lib/sessions/notify.server.test.ts +112 -0
  129. package/src/server/lib/sessions/notify.server.ts +212 -0
  130. package/src/server/lib/sessions/relation-types.ts +76 -0
  131. package/src/server/lib/sessions/relations.server.test.ts +207 -0
  132. package/src/server/lib/sessions/relations.server.ts +337 -0
  133. package/src/server/lib/sessions/resolve.server.ts +106 -0
  134. package/src/server/lib/sessions/schema.server.ts +82 -0
  135. package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
  136. package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
  137. package/src/server/lib/sessions/spawn.server.test.ts +196 -0
  138. package/src/server/lib/sessions/spawn.server.ts +310 -0
  139. package/src/server/lib/terminal/attach-replay.test.ts +2 -2
  140. package/src/server/lib/terminal/output.test.ts +2 -2
  141. package/src/server/lib/terminal/output.ts +1 -1
  142. package/src/server/lib/terminal/resize.test.ts +99 -0
  143. package/src/server/lib/terminal/runtime.server.ts +26 -6
  144. package/src/server/lib/terminal/send-result.test.ts +18 -1
  145. package/src/server/lib/terminal/send-result.ts +26 -2
  146. package/src/server/lib/terminal/session.server.ts +6 -6
  147. package/src/server/lib/usage/new-api.test.ts +92 -0
  148. package/src/server/lib/usage/new-api.ts +131 -0
  149. package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
  150. package/src/server/lib/usage/provider-key.ts +33 -0
  151. package/src/server/lib/usage/providers.server.ts +10 -3
  152. package/src/server/lib/usage/vendor-balance.server.ts +4 -53
  153. package/src/server/lib/usage/vendor-http.ts +41 -0
  154. package/src/server/lib/usage/window.ts +55 -0
  155. package/src/server/routes/agent/command.ts +14 -1
  156. package/src/server/routes/agent/harness-command.ts +6 -0
  157. package/src/server/routes/agent/new.ts +15 -0
  158. package/src/server/routes/harness/add-provider.test.ts +9 -1
  159. package/src/server/routes/harness/import-action.ts +4 -0
  160. package/src/server/routes/harness/import.test.ts +1 -1
  161. package/src/server/routes/harness/index.ts +5 -1
  162. package/src/server/routes/harness/update-status.ts +26 -0
  163. package/src/server/routes/harness/update.test.ts +119 -0
  164. package/src/server/routes/harness/update.ts +59 -147
  165. package/src/server/routes/sessions/answer.ts +24 -0
  166. package/src/server/routes/sessions/batch-delete.ts +11 -5
  167. package/src/server/routes/sessions/delete.ts +4 -2
  168. package/src/server/routes/sessions/fork.ts +74 -0
  169. package/src/server/routes/sessions/index.ts +14 -0
  170. package/src/server/routes/sessions/relations.ts +85 -0
  171. package/src/server/routes/sessions/session.ts +4 -0
  172. package/src/server/routes/sessions/spawn.ts +134 -0
  173. package/src/server/routes/terminal/ws.ts +3 -3
  174. package/src/shared/lib/chat/composer/client.ts +31 -2
  175. package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
  176. package/src/shared/lib/chat/composer/delegation.ts +206 -0
  177. package/src/shared/lib/chat/notice-text.ts +1 -1
  178. package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
  179. package/src/shared/lib/code/ansi.ts +1 -1
  180. package/src/shared/lib/fonts/nerd-symbols.css +4 -3
  181. package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
  182. package/src/shared/lib/harness/provider-facts.test.ts +27 -0
  183. package/src/shared/lib/harness/providers.ts +35 -1
  184. package/src/shared/lib/harness/update-job.ts +33 -0
  185. package/src/shared/lib/harness/update-plan.test.ts +21 -6
  186. package/src/shared/lib/harness/update-plan.ts +12 -4
  187. package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
  188. package/src/shared/lib/omp/session/wait-idle.ts +12 -2
  189. package/src/shared/lib/theme/catalog.test.ts +13 -9
  190. package/src/shared/lib/theme/color.test.ts +2 -2
  191. package/src/shared/lib/theme/color.ts +4 -4
  192. package/src/shared/lib/theme/theme.test.ts +1 -1
  193. package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
  194. package/src/shared/lib/workspace/terminal/input.ts +33 -0
  195. package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
  196. package/src/shared/lib/workspace/terminal/keys.ts +7 -7
  197. package/src/shared/types/chat.ts +1 -1
  198. package/src/shared/types/harness-update.ts +65 -0
  199. package/src/shared/types/omp/agent.ts +19 -2
  200. package/src/shared/types/workspace.ts +4 -0
  201. package/src/test-support/fake-omp-fork.ts +16 -2
  202. package/src/test-support/harness-table.test-util.ts +15 -1
  203. package/dist/client/static/js/index-z3w7n85q.css +0 -1
  204. package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
  205. package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  /**
7
- * Updating ONE harness — and refusing where Kabmo must not act.
7
+ * Updating ONE harness — as a BACKGROUND job, and refusing where Kabmo must not act.
8
8
  *
9
9
  * Three mechanisms, and the refusal is as much of the feature as the button:
10
10
  *
@@ -21,103 +21,64 @@
21
21
  * **An adapter is TWO installs.** `claude` is `@agentclientprotocol/claude-agent-acp`
22
22
  * (the number the probe reports) on top of the `claude` CLI, and they move
23
23
  * independently — measured here: adapter 0.100.0 under CLI 2.1.318. So one press
24
- * moves EVERY part that is behind and none that is current:
24
+ * moves EVERY part that is behind and none that is current. The decision itself
25
+ * is pure (`planHarnessUpdate`); this route only resolves the facts it needs and
26
+ * hands the argv to the worker.
25
27
  *
26
- * - both behind → `npm i -g <adapter>@<latest>` then `claude update`;
27
- * - only the CLI → `claude update`, with no adapter install at all;
28
- * - only the adapter → the npm install alone.
29
- *
30
- * Running both unconditionally was the first shape, and it reinstalled an adapter
31
- * that was already current while reporting "updated to 0.101.0" about a version
32
- * that never moved.
33
- *
34
- * Every run is a POST that answers plain JSON, not an SSE stream: an npm install
35
- * of one package, or one `upgrade` subcommand, is seconds rather than the minutes
36
- * `omp update` and the Kabmo self-update take. If one of these grows long enough
37
- * to need streaming, it should reuse `updates/apply.ts` rather than grow a second
38
- * progress protocol here.
28
+ * **The route does not run the installs.** They used to run here, inside the POST:
29
+ * the request stayed open for minutes, a reload forgot the run, and a five-minute
30
+ * child timeout could kill `npm install -g` halfway through writing a package
31
+ * tree — the corruption this design removes. The run is a detached worker
32
+ * (`update-worker.ts`) that writes progress to `harness-update.json`; this route
33
+ * answers `202` in milliseconds and `GET /api/harness/update/status` reports the
34
+ * outcome. A second press while one runs is a `409`, read from that same record,
35
+ * so a reloaded page cannot start a competing install.
39
36
  */
40
37
 
41
- import { json } from '@/server/lib/remix-compat';
38
+ import { json, NO_STORE_HEADERS } from '@/server/lib/remix-compat';
42
39
  import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
43
40
  import { methodNotAllowed } from '@/server/lib/route-adapter';
44
41
  import { HARNESS_IDS, harnessDescriptor, type HarnessId } from '@/shared/lib/harness/catalog';
45
- import { harnessUpdateFacts, latestSourceFor, type HarnessUpdateFacts } from '@/shared/lib/harness/updates';
46
- import { forgetProbe, loadProbes } from '@/server/lib/harness/probe-cache.server';
47
- import { forgetCliVersion, harnessVersionState } from '@/server/lib/harness/update-state.server';
48
- import { planHarnessUpdate, repointAdapterLaunch, type HarnessUpdateStep } from '@/shared/lib/harness/update-plan';
49
- import { loadHarnessConfig, saveHarnessConfig } from '@/server/lib/harness/config.server';
42
+ import { harnessUpdateFacts, latestSourceFor } from '@/shared/lib/harness/updates';
43
+ import { loadProbes } from '@/server/lib/harness/probe-cache.server';
44
+ import { harnessVersionState, type HarnessVersionState } from '@/server/lib/harness/update-state.server';
45
+ import { planHarnessUpdate, type HarnessUpdateStep } from '@/shared/lib/harness/update-plan';
50
46
  import { resolveOmpBin } from '@/server/lib/omp/core/cli';
51
- import { harnessVersionRows } from '@/server/routes/harness/versions';
52
-
53
- /** Longest one update may run before it is killed and reported as a timeout. */
54
- const UPDATE_TIMEOUT_MS = 5 * 60_000;
47
+ import {
48
+ runningUpdateJob,
49
+ startHarnessUpdateJob,
50
+ } from '@/server/lib/harness/update-job.server';
55
51
 
56
- /** The result the UI reports, in the agent's own terms. */
52
+ /** The answer to a press that has nothing to move, still plain JSON. */
57
53
  interface HarnessUpdateOutcome {
58
54
  success: boolean;
59
55
  id: string;
60
56
  message: string;
61
- /** The commands that ran, so the reader can repeat them themselves. */
62
- command?: string;
63
- /** The tail of their output — what actually failed, when it failed. */
64
- output?: string;
65
- }
66
-
67
- /** Run a command, capturing its combined output for the report. */
68
- async function run(command: string[], cwd?: string): Promise<{ code: number | null; output: string }> {
69
- const proc = Bun.spawn({
70
- cmd: command,
71
- stdin: 'ignore',
72
- stdout: 'pipe',
73
- stderr: 'pipe',
74
- timeout: UPDATE_TIMEOUT_MS,
75
- env: { ...Bun.env, PAGER: 'cat', FORCE_COLOR: '0' },
76
- ...(cwd ? { cwd } : {}),
77
- });
78
- const [stdout, stderr] = await Promise.all([
79
- new Response(proc.stdout).text(),
80
- new Response(proc.stderr).text(),
81
- ]);
82
- const code = await proc.exited;
83
- return { code, output: [stdout, stderr].filter(Boolean).join('\n').trim() };
84
57
  }
85
58
 
86
- /** The last few lines of a run, which is where a failure explains itself. */
87
- function tail(output: string, lines = 12): string {
88
- const all = output.split('\n');
89
- return all.slice(Math.max(0, all.length - lines)).join('\n').trim();
59
+ /** A readable description of the numbers currently on disk, for "already current". */
60
+ function currentParts(state: HarnessVersionState, cliName: string | undefined): string {
61
+ return [
62
+ state.agent.version && `adapter ${state.agent.version}`,
63
+ state.cli?.version && `${cliName ?? 'CLI'} ${state.cli.version}`,
64
+ ].filter(Boolean).join(', ');
90
65
  }
91
66
 
92
67
  /**
93
- * Make an adapter install the one the next spawn runs.
68
+ * The argv for a `self` harness: the vendor's own updater, resolved by name.
94
69
  *
95
- * The launch table starts an npm adapter through a PINNED `npx -y pkg@x.y.z`
96
- * (measured versions), while the update installs the package GLOBALLY. Those are
97
- * two different resolvers: `npm i -g` writes a binary onto PATH that `npx` never
98
- * consults, so the press reported success while every new session still started
99
- * the old pinned build — measured on `claude` (global 0.101.0, launch requested
100
- * 0.100.0) and reproduced for codex/pi/zcode by construction.
101
- *
102
- * Once the install succeeded AND the binary is on PATH, the harness's launch
103
- * line is pointed at it. A user's own configured command is never replaced: it
104
- * is an explicit choice about how this machine launches the harness.
70
+ * `omp` has its own resolver (`KABMO_OMP_BIN`, then PATH): a custom install is
71
+ * launchable and already reported as installed, so checking PATH alone refused
72
+ * the one updater the harness actually has.
105
73
  */
106
- async function pointAtInstalledAdapter(
107
- harness: HarnessId,
108
- facts: HarnessUpdateFacts,
109
- steps: HarnessUpdateStep[],
110
- ): Promise<string | null> {
111
- const config = await loadHarnessConfig(harness);
112
- const bin = repointAdapterLaunch(
113
- facts,
114
- steps,
115
- config.command,
116
- facts.agentBin ? Boolean(Bun.which(facts.agentBin)) : false,
117
- );
118
- if (!bin) return null;
119
- await saveHarnessConfig(harness, { ...config, command: bin });
120
- return bin;
74
+ function selfSteps(harness: HarnessId, label: string, command: string): { steps: HarnessUpdateStep[]; error?: string } {
75
+ const argv = command.split(' ');
76
+ const binary = argv[0];
77
+ const resolved = harness === 'omp-acp' ? resolveOmpBin() : binary ? Bun.which(binary) : null;
78
+ if (!binary || !resolved) {
79
+ return { steps: [], error: `${label}: \`${binary || 'the updater'}\` is not on PATH` };
80
+ }
81
+ return { steps: [{ part: label, command, argv: [resolved, ...argv.slice(1)] }] };
121
82
  }
122
83
 
123
84
  export async function action({ request, params }: ActionFunctionArgs) {
@@ -150,26 +111,23 @@ export async function action({ request, params }: ActionFunctionArgs) {
150
111
  }, { status: 400 });
151
112
  }
152
113
 
114
+ // Read BEFORE planning: the answer to a press while an install runs must not
115
+ // depend on what this press would have planned, and planning reads the npm
116
+ // registry.
117
+ const running = await runningUpdateJob();
118
+ if (running) {
119
+ return json({
120
+ error: `${running.label} update is already running — it continues in the background`,
121
+ job: running,
122
+ }, { status: 409, headers: NO_STORE_HEADERS });
123
+ }
124
+
153
125
  if (facts.kind === 'self') {
154
- const command = facts.command?.split(' ') ?? [];
155
- const binary = command[0];
156
- // `omp` has its own resolver (`KABMO_OMP_BIN`, then PATH): a custom install
157
- // is launchable and already reported as installed by `commandAvailable`, so
158
- // checking PATH alone refused the one updater the harness actually has.
159
- const resolved = harness === 'omp-acp' ? resolveOmpBin() : binary ? Bun.which(binary) : null;
160
- if (!binary || !resolved) {
161
- return json({ error: `${label}: \`${binary ?? 'the updater'}\` is not on PATH` }, { status: 400 });
162
- }
163
- const result = await run([resolved, ...command.slice(1)]);
164
- const ok = result.code === 0;
165
- const outcome: HarnessUpdateOutcome = {
166
- success: ok,
167
- id: harness,
168
- message: ok ? `${label} updated` : `${label} update failed (exit ${result.code ?? 'killed'})`,
169
- command: facts.command,
170
- ...(result.output ? { output: tail(result.output) } : {}),
171
- };
172
- return json(outcome);
126
+ if (!facts.command) return json({ error: `${label} names no updater command` }, { status: 400 });
127
+ const { steps, error } = selfSteps(harness, label, facts.command);
128
+ if (error) return json({ error }, { status: 400 });
129
+ const job = await startHarnessUpdateJob(harness, label, steps);
130
+ return json({ started: true, job }, { status: 202, headers: NO_STORE_HEADERS });
173
131
  }
174
132
 
175
133
  // `npm`: install the package at the version the registry reports NOW, so the
@@ -191,17 +149,12 @@ export async function action({ request, params }: ActionFunctionArgs) {
191
149
  return json({ error: `${label} is not installed on this machine` }, { status: 400 });
192
150
  }
193
151
 
194
- // `harnessVersionState` was read with `force`, so both latest numbers are what
195
- // the registry serves NOW rather than what the dialog remembered.
196
-
197
152
  const steps = planHarnessUpdate(label, facts, state, agentVersion);
198
153
 
199
154
  if (steps.length === 0) {
200
155
  // Nothing to install. Reported as a success the UI can state plainly, rather
201
156
  // than running an install that would change nothing.
202
- const current = [state.agent.version && `adapter ${state.agent.version}`, state.cli?.version && `${facts.cli?.name} ${state.cli.version}`]
203
- .filter(Boolean)
204
- .join(', ');
157
+ const current = currentParts(state, facts.cli?.name);
205
158
  return json({
206
159
  success: true,
207
160
  id: harness,
@@ -213,47 +166,6 @@ export async function action({ request, params }: ActionFunctionArgs) {
213
166
  } satisfies HarnessUpdateOutcome);
214
167
  }
215
168
 
216
- /** Did every step that ran succeed, and what did each print? */
217
- const outputs: string[] = [];
218
- let ok = true;
219
- for (const step of steps) {
220
- const result = await run(step.argv);
221
- if (result.output) outputs.push(result.output);
222
- if (result.code !== 0) {
223
- ok = false;
224
- // The first failure ends the run: installing the CLI on top of a failed
225
- // adapter install would report two outcomes for one broken state.
226
- break;
227
- }
228
- }
229
-
230
- if (ok) {
231
- // The cached probe describes the binary that WAS installed. Keeping it would
232
- // report the old version until the TTL (30 min) or a manual re-probe — and
233
- // measured after a real `npm install`: the row still read 0.100.0 while npm
234
- // had 0.101.0 on disk, because the running adapter was the previous process.
235
- await forgetProbe(harness);
236
- // The CLI's `--version` read has the same problem: it is cached for ten
237
- // minutes, so the row would keep claiming the old number after it moved.
238
- if (facts.cli) forgetCliVersion(facts.cli.bin);
239
- }
240
- // Only after the install succeeded: the launch line is repointed at the binary
241
- // that install wrote, or the next session would start the pinned one forever.
242
- const repointed = ok ? await pointAtInstalledAdapter(harness, facts, steps) : null;
243
-
244
- const moved = steps.map((step) => step.part);
245
- return json({
246
- success: ok,
247
- id: harness,
248
- message: ok
249
- ? `${label} updated (${moved.join(' + ')})${repointed ? ` — launches now run \`${repointed}\`` : ''} — check its status to read the new version`
250
- : `${label} update failed`,
251
- command: steps.map((step) => step.command).join(' && '),
252
- ...(outputs.length > 0 ? { output: tail(outputs.join('\n')) } : {}),
253
- } satisfies HarnessUpdateOutcome);
254
- }
255
-
256
- /** GET answers the same rows the versions route does, so a mistake reads plainly. */
257
- export async function loader() {
258
- return json({ harnesses: await harnessVersionRows() });
169
+ const job = await startHarnessUpdateJob(harness, label, steps);
170
+ return json({ started: true, job }, { status: 202, headers: NO_STORE_HEADERS });
259
171
  }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * GET /api/sessions/:sessionId/answer — the last assistant text a turn closed.
8
+ *
9
+ * ACP has no transcript for `/api/chat/:id` to read after the process dies, so
10
+ * `kabmo session output` needs this row. A null answer is a real state (the
11
+ * session has not answered yet), not an error.
12
+ */
13
+
14
+ import { json } from '@/server/lib/remix-compat';
15
+ import type { LoaderFunctionArgs } from '@/server/lib/remix-compat';
16
+ import { methodNotAllowed } from '@/server/lib/route-adapter';
17
+ import { loadSessionAnswer } from '@/server/lib/sessions/answers.server';
18
+
19
+ export async function getSessionAnswer({ request, params }: LoaderFunctionArgs) {
20
+ if (request.method !== 'GET') return methodNotAllowed({ request, params });
21
+ const sessionId = params.sessionId;
22
+ if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
23
+ return json({ sessionId, answer: await loadSessionAnswer(sessionId) });
24
+ }
@@ -20,7 +20,7 @@
20
20
  import { json } from '@/server/lib/remix-compat';
21
21
  import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
22
22
  import { methodNotAllowed, parseJsonBody } from '@/server/lib/route-adapter';
23
- import { removeSession } from '@/server/lib/omp/session/delete-flow.server';
23
+ import { removeSessionTree } from '@/server/lib/omp/session/delete-flow.server';
24
24
 
25
25
  /** One request cannot carry an unbounded selection. */
26
26
  const MAX_BATCH = 500;
@@ -44,6 +44,7 @@ export async function batchDeleteSessions({ request }: ActionFunctionArgs) {
44
44
  }
45
45
 
46
46
  const removed: string[] = [];
47
+ const removedDependents: string[] = [];
47
48
  const refused: { id: string; error: string; code?: string }[] = [];
48
49
 
49
50
  // Sequential, deliberately: every removal may have to destroy an omp child
@@ -51,10 +52,15 @@ export async function batchDeleteSessions({ request }: ActionFunctionArgs) {
51
52
  // transcript writer per session at once for no gain — the work is dominated
52
53
  // by process teardown, not by the filesystem.
53
54
  for (const id of ids) {
54
- const result = await removeSession(id);
55
- if (result.ok) removed.push(id);
56
- else refused.push({ id, error: result.error ?? 'Could not delete the session.', code: result.code });
55
+ const tree = await removeSessionTree(id);
56
+ const result = tree.result;
57
+ if (result.ok) {
58
+ removed.push(id);
59
+ removedDependents.push(...tree.removedDependents);
60
+ } else {
61
+ refused.push({ id, error: result.error ?? 'Could not delete the session.', code: result.code });
62
+ }
57
63
  }
58
64
 
59
- return json({ success: refused.length === 0, removed, refused });
65
+ return json({ success: refused.length === 0, removed, removedDependents, refused });
60
66
  }
@@ -17,7 +17,7 @@
17
17
  import { json } from '@/server/lib/remix-compat';
18
18
  import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
19
19
  import { methodNotAllowed } from '@/server/lib/route-adapter';
20
- import { removeSession } from '@/server/lib/omp/session/delete-flow.server';
20
+ import { removeSessionTree } from '@/server/lib/omp/session/delete-flow.server';
21
21
 
22
22
  export async function deleteSession({ request, params }: ActionFunctionArgs) {
23
23
  if (request.method !== 'DELETE') {
@@ -27,7 +27,8 @@ export async function deleteSession({ request, params }: ActionFunctionArgs) {
27
27
  const sessionId = params.sessionId;
28
28
  if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
29
29
 
30
- const result = await removeSession(sessionId);
30
+ const tree = await removeSessionTree(sessionId);
31
+ const result = tree.result;
31
32
  if (!result.ok) {
32
33
  return json(
33
34
  { error: result.error, code: result.code },
@@ -38,6 +39,7 @@ export async function deleteSession({ request, params }: ActionFunctionArgs) {
38
39
  return json({
39
40
  success: true,
40
41
  sessionId,
42
+ removedDependents: tree.removedDependents,
41
43
  fileRemoved: result.fileRemoved,
42
44
  artifactsRemoved: result.artifactsRemoved,
43
45
  btwTopicsRemoved: result.btwTopicsRemoved,
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * POST /api/sessions/:sessionId/fork — branch a session at an anchor.
8
+ *
9
+ * Mounted under the same `:sessionId` position as the folder loader, so the
10
+ * parameter keeps that name; the suffix is what makes the route distinct.
11
+ */
12
+
13
+ import { json } from '@/server/lib/remix-compat';
14
+ import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
15
+ import { methodNotAllowed, parseJsonBody } from '@/server/lib/route-adapter';
16
+ import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
17
+ import {
18
+ SessionForkError,
19
+ forkSession,
20
+ } from '@/server/lib/sessions/fork.server';
21
+
22
+ interface ForkBody {
23
+ anchorEntryId?: unknown;
24
+ prompt?: unknown;
25
+ title?: unknown;
26
+ cwd?: unknown;
27
+ visibility?: unknown;
28
+ lifecycleOwnerSessionId?: unknown;
29
+ }
30
+
31
+ function readString(value: unknown): string | null {
32
+ return typeof value === 'string' && value.trim() ? value.trim() : null;
33
+ }
34
+
35
+ export async function forkSessionRoute({ request, params }: ActionFunctionArgs) {
36
+ if (request.method !== 'POST') return methodNotAllowed({ request, params });
37
+ const sourceSessionId = params.sessionId;
38
+ if (!sourceSessionId) return json({ error: 'Missing session id' }, { status: 400 });
39
+
40
+ const parsed = await parseJsonBody<ForkBody>(request);
41
+ if (!parsed.ok) return json({ error: 'Invalid JSON body' }, { status: 400 });
42
+ const visibility = parsed.body.visibility;
43
+ if (visibility !== undefined && visibility !== 'visible' && visibility !== 'hidden') {
44
+ return json({ error: 'visibility must be "visible" or "hidden"' }, { status: 400 });
45
+ }
46
+
47
+ try {
48
+ const result = await forkSession({
49
+ sourceSessionId,
50
+ anchorEntryId: readString(parsed.body.anchorEntryId),
51
+ prompt: readString(parsed.body.prompt),
52
+ title: readString(parsed.body.title),
53
+ cwd: readString(parsed.body.cwd),
54
+ ...(visibility ? { visibility: visibility as 'visible' | 'hidden' } : {}),
55
+ lifecycleOwnerSessionId: readString(parsed.body.lifecycleOwnerSessionId),
56
+ });
57
+ emitRealtimeSignal('sidebar-structure');
58
+ return json(result, { status: 201 });
59
+ } catch (error) {
60
+ if (error instanceof SessionForkError) {
61
+ const status =
62
+ error.code === 'source_not_found'
63
+ ? 404
64
+ : error.code === 'source_archived' || error.code === 'fork_requires_checkpoint'
65
+ ? 409
66
+ : 400;
67
+ return json({ error: error.message, code: error.code }, { status });
68
+ }
69
+ return json(
70
+ { error: error instanceof Error ? error.message : 'Could not fork the session' },
71
+ { status: 500 },
72
+ );
73
+ }
74
+ }
@@ -16,9 +16,16 @@ import { cancelSubagent, steerSubagent } from '@/server/routes/sessions/subagent
16
16
  import { deleteSession } from '@/server/routes/sessions/delete';
17
17
  import { batchDeleteSessions } from '@/server/routes/sessions/batch-delete';
18
18
  import { batchArchiveSessions } from '@/server/routes/sessions/batch-archive';
19
+ import { spawnSession } from '@/server/routes/sessions/spawn';
20
+ import { getSessionRelations, updateSessionParent } from '@/server/routes/sessions/relations';
21
+ import { forkSessionRoute } from '@/server/routes/sessions/fork';
22
+ import { getSessionAnswer } from '@/server/routes/sessions/answer';
19
23
 
20
24
  export const sessionsBindings: HandlerBinding[] = [
21
25
  ...bindingsFor(sessionsList, '/api/sessions/list'),
26
+ // Static before the `:sessionId` routes, for the same reason batch-delete is:
27
+ // a parameter route winning the match answers 405.
28
+ { method: 'POST', path: '/api/sessions/spawn', handler: spawnSession },
22
29
  // Registered BEFORE the `:sessionId` routes: the segment is static, and the
23
30
  // batch route is POST while `:sessionId` answers DELETE, so an id route
24
31
  // winning the match would turn every batch into a 405.
@@ -27,6 +34,13 @@ export const sessionsBindings: HandlerBinding[] = [
27
34
  // `:sessionId` routes for the same reason as batch-delete.
28
35
  { method: 'POST', path: '/api/sessions/batch-archive', handler: batchArchiveSessions },
29
36
  ...bindingsFor(sessionsFolder, '/api/sessions/:sessionId'),
37
+ // The tree around one session. Both are static suffixes under the same
38
+ // `:sessionId` position, whose name must stay `sessionId` — Elysia requires
39
+ // one parameter name per position across every `/api/sessions/*` route.
40
+ { method: 'GET', path: '/api/sessions/:sessionId/relations', handler: getSessionRelations },
41
+ { method: 'POST', path: '/api/sessions/:sessionId/parent', handler: updateSessionParent },
42
+ { method: 'POST', path: '/api/sessions/:sessionId/fork', handler: forkSessionRoute },
43
+ { method: 'GET', path: '/api/sessions/:sessionId/answer', handler: getSessionAnswer },
30
44
  // DELETE-only on the same path the folder loader answers GET on: mounting it
31
45
  // through `actionBindings` would register a 405 GET fallback that Elysia
32
46
  // applies after the loader, replacing the workspace listing with it.
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The tree around one session: its parent, children, forks and cleanup owner.
8
+ *
9
+ * A fork is deliberately NOT in `children`: it is a source-derived session and
10
+ * stays silent, so listing it under the parent edge would promise a
11
+ * notification that never comes. The info panel draws it from `forks`.
12
+ */
13
+
14
+ import { json } from '@/server/lib/remix-compat';
15
+ import type { ActionFunctionArgs, LoaderFunctionArgs } from '@/server/lib/remix-compat';
16
+ import { methodNotAllowed, parseJsonBody } from '@/server/lib/route-adapter';
17
+ import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
18
+ import { SessionRelationError } from '@/server/lib/sessions/relation-types';
19
+ import {
20
+ getSessionRelation,
21
+ listChildRelations,
22
+ listForkRelations,
23
+ listOwnedRelations,
24
+ setSessionParent,
25
+ } from '@/server/lib/sessions/relations.server';
26
+
27
+ export async function getSessionRelations({ request, params }: LoaderFunctionArgs) {
28
+ if (request.method !== 'GET') return methodNotAllowed({ request, params });
29
+ const sessionId = params.sessionId;
30
+ if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
31
+
32
+ const [relation, children, forks, owned] = await Promise.all([
33
+ getSessionRelation(sessionId),
34
+ listChildRelations(sessionId),
35
+ listForkRelations(sessionId),
36
+ listOwnedRelations(sessionId),
37
+ ]);
38
+ return json({
39
+ sessionId,
40
+ parent: relation?.parentSessionId ? { sessionId: relation.parentSessionId } : null,
41
+ parentNotifications: relation?.parentNotifications ?? 'auto',
42
+ visibility: relation?.visibility ?? 'visible',
43
+ origin: relation?.originKind
44
+ ? { kind: relation.originKind, sourceSessionId: relation.sourceSessionId }
45
+ : null,
46
+ children: children.map((row) => ({
47
+ sessionId: row.sessionId,
48
+ visibility: row.visibility,
49
+ parentNotifications: row.parentNotifications,
50
+ depth: row.depth,
51
+ })),
52
+ forks: forks.map((row) => ({ sessionId: row.sessionId, visibility: row.visibility })),
53
+ lifecycleOwner: relation?.lifecycleOwnerSessionId
54
+ ? { sessionId: relation.lifecycleOwnerSessionId }
55
+ : null,
56
+ owned: owned.map((row) => ({ sessionId: row.sessionId })),
57
+ });
58
+ }
59
+
60
+ export async function updateSessionParent({ request, params }: ActionFunctionArgs) {
61
+ if (request.method !== 'POST') return methodNotAllowed({ request, params });
62
+ const sessionId = params.sessionId;
63
+ if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
64
+
65
+ const parsed = await parseJsonBody<{ parentSessionId?: unknown }>(request);
66
+ if (!parsed.ok) return json({ error: 'Invalid JSON body' }, { status: 400 });
67
+ const raw = parsed.body.parentSessionId;
68
+ if (raw !== null && typeof raw !== 'string') {
69
+ return json({ error: 'parentSessionId must be a string or null' }, { status: 400 });
70
+ }
71
+
72
+ try {
73
+ const relation = await setSessionParent(sessionId, raw);
74
+ emitRealtimeSignal('sidebar-structure');
75
+ return json({ ok: true, parentSessionId: relation.parentSessionId, depth: relation.depth });
76
+ } catch (error) {
77
+ if (error instanceof SessionRelationError) {
78
+ return json({ error: error.message, code: error.code }, { status: 409 });
79
+ }
80
+ return json(
81
+ { error: error instanceof Error ? error.message : 'Could not reparent the session' },
82
+ { status: 500 },
83
+ );
84
+ }
85
+ }
@@ -19,6 +19,7 @@ import { loadAcpGoalState } from '@/server/lib/harness/acp/acp-goal-state.server
19
19
  import { asHarnessSession } from '@/server/lib/harness/registry';
20
20
  import { applyHarnessMode } from '@/server/routes/agent/harness-command';
21
21
  import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
22
+ import { archiveDependents } from '@/server/lib/sessions/lifecycle.server';
22
23
 
23
24
  /**
24
25
  * GET /api/sessions/:sessionId/modes — the plan/goal mode selection.
@@ -125,6 +126,9 @@ export async function archiveSession({ request, params }: ActionFunctionArgs) {
125
126
  'INSERT OR IGNORE INTO archived_sessions (session_id) VALUES (?)',
126
127
  [sessionId],
127
128
  );
129
+ // An owner takes its tree with it: sidebar children and cleanup dependents
130
+ // are archived and stopped; unarchiving this row does not bring them back.
131
+ await archiveDependents(sessionId);
128
132
  } else {
129
133
  await db.run('DELETE FROM archived_sessions WHERE session_id = ?', [sessionId]);
130
134
  }