repoburg 1.3.319 → 1.3.321

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 (195) hide show
  1. package/agent-pane/backend/dist/index.js +510 -159
  2. package/agent-pane/backend/dist/server.js +510 -159
  3. package/agent-pane/frontend/dist/assets/{TerminalView-D5Hg3Fzf.js → TerminalView-Z7ZJ436H.js} +1 -1
  4. package/agent-pane/frontend/dist/assets/{index-Cckb2tlY.js → index-CjwvHfxy.js} +12 -2
  5. package/agent-pane/frontend/dist/index.html +1 -1
  6. package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.d.ts +2 -1
  7. package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.js +10 -0
  8. package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.js.map +1 -1
  9. package/backend/dist/src/agent-runtime/agent-runtime.types.d.ts +12 -1
  10. package/backend/dist/src/ai-actions/ai-action-batch.service.js +6 -3
  11. package/backend/dist/src/ai-actions/ai-action-batch.service.js.map +1 -1
  12. package/backend/dist/src/app.module.js +2 -9
  13. package/backend/dist/src/app.module.js.map +1 -1
  14. package/backend/dist/src/application-state/application-state.service.d.ts +3 -4
  15. package/backend/dist/src/application-state/application-state.service.js +21 -25
  16. package/backend/dist/src/application-state/application-state.service.js.map +1 -1
  17. package/backend/dist/src/context-generation/context-generation.service.js +3 -0
  18. package/backend/dist/src/context-generation/context-generation.service.js.map +1 -1
  19. package/backend/dist/src/context-generation/project-guidance.d.ts +12 -0
  20. package/backend/dist/src/context-generation/project-guidance.js +103 -0
  21. package/backend/dist/src/context-generation/project-guidance.js.map +1 -0
  22. package/backend/dist/src/core-entities/mcp-config.entity.d.ts +3 -1
  23. package/backend/dist/src/core-entities/mcp-config.entity.js +17 -1
  24. package/backend/dist/src/core-entities/mcp-config.entity.js.map +1 -1
  25. package/backend/dist/src/global-config/dto/update-global-config.dto.d.ts +2 -0
  26. package/backend/dist/src/global-config/dto/update-global-config.dto.js +12 -0
  27. package/backend/dist/src/global-config/dto/update-global-config.dto.js.map +1 -1
  28. package/backend/dist/src/global-config/global-config.service.d.ts +2 -0
  29. package/backend/dist/src/global-config/global-config.service.js.map +1 -1
  30. package/backend/dist/src/interactive-chat/auto-compact.service.d.ts +34 -0
  31. package/backend/dist/src/interactive-chat/auto-compact.service.js +259 -0
  32. package/backend/dist/src/interactive-chat/auto-compact.service.js.map +1 -0
  33. package/backend/dist/src/interactive-chat/chat.module.js +2 -5
  34. package/backend/dist/src/interactive-chat/chat.module.js.map +1 -1
  35. package/backend/dist/src/interactive-chat/chat.service.d.ts +12 -4
  36. package/backend/dist/src/interactive-chat/chat.service.js +102 -39
  37. package/backend/dist/src/interactive-chat/chat.service.js.map +1 -1
  38. package/backend/dist/src/llm-orchestration/action-handlers/execute-code.handler.d.ts +1 -1
  39. package/backend/dist/src/llm-orchestration/action-handlers/execute-code.handler.js +8 -2
  40. package/backend/dist/src/llm-orchestration/action-handlers/execute-code.handler.js.map +1 -1
  41. package/backend/dist/src/llm-orchestration/action-handlers/mcp-tool-action.handler.d.ts +5 -2
  42. package/backend/dist/src/llm-orchestration/action-handlers/mcp-tool-action.handler.js +50 -17
  43. package/backend/dist/src/llm-orchestration/action-handlers/mcp-tool-action.handler.js.map +1 -1
  44. package/backend/dist/src/llm-orchestration/action-handlers/run-command.handler.js +9 -1
  45. package/backend/dist/src/llm-orchestration/action-handlers/run-command.handler.js.map +1 -1
  46. package/backend/dist/src/llm-orchestration/hooks/follow-up-post-execution.hook.js +8 -0
  47. package/backend/dist/src/llm-orchestration/hooks/follow-up-post-execution.hook.js.map +1 -1
  48. package/backend/dist/src/llm-orchestration/hooks/yolo-mode-post-execution.hook.js +2 -1
  49. package/backend/dist/src/llm-orchestration/hooks/yolo-mode-post-execution.hook.js.map +1 -1
  50. package/backend/dist/src/llm-orchestration/llm-orchestration.interfaces.d.ts +2 -0
  51. package/backend/dist/src/llm-orchestration/llm-orchestration.interfaces.js.map +1 -1
  52. package/backend/dist/src/llm-orchestration/llm-orchestration.module.js +0 -2
  53. package/backend/dist/src/llm-orchestration/llm-orchestration.module.js.map +1 -1
  54. package/backend/dist/src/llm-orchestration/llm-turn-processor.service.d.ts +8 -1
  55. package/backend/dist/src/llm-orchestration/llm-turn-processor.service.js +237 -194
  56. package/backend/dist/src/llm-orchestration/llm-turn-processor.service.js.map +1 -1
  57. package/backend/dist/src/llm-orchestration/turn-execution-plan.d.ts +18 -0
  58. package/backend/dist/src/llm-orchestration/turn-execution-plan.js +53 -0
  59. package/backend/dist/src/llm-orchestration/turn-execution-plan.js.map +1 -0
  60. package/backend/dist/src/llm-provider/ollama-llm.provider.d.ts +1 -0
  61. package/backend/dist/src/llm-provider/ollama-llm.provider.js +21 -5
  62. package/backend/dist/src/llm-provider/ollama-llm.provider.js.map +1 -1
  63. package/backend/dist/src/llm-provider/openrouter-llm.provider.d.ts +3 -0
  64. package/backend/dist/src/llm-provider/openrouter-llm.provider.js +8 -0
  65. package/backend/dist/src/llm-provider/openrouter-llm.provider.js.map +1 -1
  66. package/backend/dist/src/llm-responses/llm-responses.module.js +0 -4
  67. package/backend/dist/src/llm-responses/llm-responses.module.js.map +1 -1
  68. package/backend/dist/src/llm-responses/llm-responses.service.d.ts +12 -4
  69. package/backend/dist/src/llm-responses/llm-responses.service.js +4 -45
  70. package/backend/dist/src/llm-responses/llm-responses.service.js.map +1 -1
  71. package/backend/dist/src/main.js +4 -0
  72. package/backend/dist/src/main.js.map +1 -1
  73. package/backend/dist/src/mcp/marketplace/dto/initiate-connect.dto.d.ts +3 -1
  74. package/backend/dist/src/mcp/marketplace/dto/initiate-connect.dto.js +19 -0
  75. package/backend/dist/src/mcp/marketplace/dto/initiate-connect.dto.js.map +1 -1
  76. package/backend/dist/src/mcp/marketplace/marketplace.controller.js +7 -0
  77. package/backend/dist/src/mcp/marketplace/marketplace.controller.js.map +1 -1
  78. package/backend/dist/src/mcp/marketplace/marketplace.service.d.ts +9 -0
  79. package/backend/dist/src/mcp/marketplace/marketplace.service.js +68 -13
  80. package/backend/dist/src/mcp/marketplace/marketplace.service.js.map +1 -1
  81. package/backend/dist/src/mcp/marketplace/oauth-provider.d.ts +3 -0
  82. package/backend/dist/src/mcp/marketplace/oauth-provider.js.map +1 -1
  83. package/backend/dist/src/mcp/mcp-result.d.ts +12 -0
  84. package/backend/dist/src/mcp/mcp-result.js +125 -0
  85. package/backend/dist/src/mcp/mcp-result.js.map +1 -0
  86. package/backend/dist/src/mcp/mcp.service.d.ts +33 -1
  87. package/backend/dist/src/mcp/mcp.service.js +364 -79
  88. package/backend/dist/src/mcp/mcp.service.js.map +1 -1
  89. package/backend/dist/src/metadata-store/schemas/metadata-schemas.d.ts +3 -1
  90. package/backend/dist/src/metadata-store/schemas/metadata-schemas.js +11 -1
  91. package/backend/dist/src/metadata-store/schemas/metadata-schemas.js.map +1 -1
  92. package/backend/dist/src/seeding/data/shared/project-guidance-section.d.ts +1 -0
  93. package/backend/dist/src/seeding/data/shared/project-guidance-section.js +22 -0
  94. package/backend/dist/src/seeding/data/shared/project-guidance-section.js.map +1 -0
  95. package/backend/dist/src/seeding/data/system-prompts/default_native_tool_agent.d.ts +1 -1
  96. package/backend/dist/src/seeding/data/system-prompts/default_native_tool_agent.js +10 -38
  97. package/backend/dist/src/seeding/data/system-prompts/default_native_tool_agent.js.map +1 -1
  98. package/backend/dist/src/seeding/data/system-prompts/explore-codebase-agent.d.ts +1 -1
  99. package/backend/dist/src/seeding/data/system-prompts/explore-codebase-agent.js +3 -1
  100. package/backend/dist/src/seeding/data/system-prompts/explore-codebase-agent.js.map +1 -1
  101. package/backend/dist/src/seeding/data/system-prompts/general-purpose-agent.d.ts +1 -1
  102. package/backend/dist/src/seeding/data/system-prompts/general-purpose-agent.js +3 -1
  103. package/backend/dist/src/seeding/data/system-prompts/general-purpose-agent.js.map +1 -1
  104. package/backend/dist/src/session-cancellation/session-cancellation.module.d.ts +2 -0
  105. package/backend/dist/src/{message-bus/message-bus.module.js → session-cancellation/session-cancellation.module.js} +10 -11
  106. package/backend/dist/src/session-cancellation/session-cancellation.module.js.map +1 -0
  107. package/backend/dist/src/session-cancellation/session-cancellation.service.d.ts +13 -0
  108. package/backend/dist/src/session-cancellation/session-cancellation.service.js +75 -0
  109. package/backend/dist/src/session-cancellation/session-cancellation.service.js.map +1 -0
  110. package/backend/dist/src/session-inputs/session-inputs.service.js +3 -1
  111. package/backend/dist/src/session-inputs/session-inputs.service.js.map +1 -1
  112. package/backend/dist/src/sessions/sessions.module.js +0 -2
  113. package/backend/dist/src/sessions/sessions.module.js.map +1 -1
  114. package/backend/dist/src/sessions/sessions.service.d.ts +1 -3
  115. package/backend/dist/src/sessions/sessions.service.js +1 -5
  116. package/backend/dist/src/sessions/sessions.service.js.map +1 -1
  117. package/backend/dist/src/tool-hooks/hook-runtime.d.ts +1 -1
  118. package/backend/dist/src/tool-hooks/hook-runtime.js +17 -16
  119. package/backend/dist/src/tool-hooks/hook-runtime.js.map +1 -1
  120. package/backend/dist/src/utils/spawn-with-kill.d.ts +2 -0
  121. package/backend/dist/src/utils/spawn-with-kill.js +18 -3
  122. package/backend/dist/src/utils/spawn-with-kill.js.map +1 -1
  123. package/backend/dist/tsconfig.build.tsbuildinfo +1 -1
  124. package/daemon/dist/index.js +1 -17
  125. package/package.json +2 -8
  126. package/platform-cli.js +0 -316
  127. package/tabtape/extension/dist/build-info.json +3 -3
  128. package/tabtape/extension/dist/manifest.json +1 -1
  129. package/tabtape/ui/dist/build-info.json +3 -3
  130. package/backend/dist/src/llm-responses/dto/submit-llm-response.dto.d.ts +0 -9
  131. package/backend/dist/src/llm-responses/dto/submit-llm-response.dto.js +0 -80
  132. package/backend/dist/src/llm-responses/dto/submit-llm-response.dto.js.map +0 -1
  133. package/backend/dist/src/llm-responses/llm-responses.controller.d.ts +0 -8
  134. package/backend/dist/src/llm-responses/llm-responses.controller.js +0 -51
  135. package/backend/dist/src/llm-responses/llm-responses.controller.js.map +0 -1
  136. package/backend/dist/src/mcp-server/mcp-internal.controller.d.ts +0 -12
  137. package/backend/dist/src/mcp-server/mcp-internal.controller.js +0 -50
  138. package/backend/dist/src/mcp-server/mcp-internal.controller.js.map +0 -1
  139. package/backend/dist/src/mcp-server/mcp-server.bootstrap.d.ts +0 -2
  140. package/backend/dist/src/mcp-server/mcp-server.bootstrap.js +0 -166
  141. package/backend/dist/src/mcp-server/mcp-server.bootstrap.js.map +0 -1
  142. package/backend/dist/src/mcp-server/mcp-server.constants.d.ts +0 -8
  143. package/backend/dist/src/mcp-server/mcp-server.constants.js +0 -12
  144. package/backend/dist/src/mcp-server/mcp-server.constants.js.map +0 -1
  145. package/backend/dist/src/mcp-server/mcp-server.controller.d.ts +0 -19
  146. package/backend/dist/src/mcp-server/mcp-server.controller.js +0 -72
  147. package/backend/dist/src/mcp-server/mcp-server.controller.js.map +0 -1
  148. package/backend/dist/src/mcp-server/mcp-server.module.d.ts +0 -2
  149. package/backend/dist/src/mcp-server/mcp-server.module.js +0 -29
  150. package/backend/dist/src/mcp-server/mcp-server.module.js.map +0 -1
  151. package/backend/dist/src/mcp-server/mcp-server.process.service.d.ts +0 -23
  152. package/backend/dist/src/mcp-server/mcp-server.process.service.js +0 -130
  153. package/backend/dist/src/mcp-server/mcp-server.process.service.js.map +0 -1
  154. package/backend/dist/src/mcp-server/mcp-server.service.d.ts +0 -34
  155. package/backend/dist/src/mcp-server/mcp-server.service.js +0 -260
  156. package/backend/dist/src/mcp-server/mcp-server.service.js.map +0 -1
  157. package/backend/dist/src/message-bus/dto/submit-message.dto.d.ts +0 -4
  158. package/backend/dist/src/message-bus/dto/submit-message.dto.js +0 -22
  159. package/backend/dist/src/message-bus/dto/submit-message.dto.js.map +0 -1
  160. package/backend/dist/src/message-bus/message-bus.controller.d.ts +0 -13
  161. package/backend/dist/src/message-bus/message-bus.controller.js +0 -50
  162. package/backend/dist/src/message-bus/message-bus.controller.js.map +0 -1
  163. package/backend/dist/src/message-bus/message-bus.module.d.ts +0 -2
  164. package/backend/dist/src/message-bus/message-bus.module.js.map +0 -1
  165. package/backend/dist/src/message-bus/message-bus.service.d.ts +0 -7
  166. package/backend/dist/src/message-bus/message-bus.service.js +0 -32
  167. package/backend/dist/src/message-bus/message-bus.service.js.map +0 -1
  168. package/backend/dist/src/visual-editor/visual-editor.controller.d.ts +0 -14
  169. package/backend/dist/src/visual-editor/visual-editor.controller.js +0 -101
  170. package/backend/dist/src/visual-editor/visual-editor.controller.js.map +0 -1
  171. package/backend/dist/src/visual-editor/visual-editor.dto.d.ts +0 -5
  172. package/backend/dist/src/visual-editor/visual-editor.dto.js +0 -32
  173. package/backend/dist/src/visual-editor/visual-editor.dto.js.map +0 -1
  174. package/backend/dist/src/visual-editor/visual-editor.module.d.ts +0 -2
  175. package/backend/dist/src/visual-editor/visual-editor.module.js +0 -24
  176. package/backend/dist/src/visual-editor/visual-editor.module.js.map +0 -1
  177. package/daemon/dist/mcp-gateway.js +0 -401
  178. package/daemon/dist/mcp-gateway.spec.js +0 -295
  179. package/visual-editor-proxy/client/dist/main.js +0 -89
  180. package/visual-editor-proxy/client/tsconfig.json +0 -14
  181. package/visual-editor-proxy/dist/client/src/inspector.d.ts +0 -9
  182. package/visual-editor-proxy/dist/client/src/inspector.js +0 -96
  183. package/visual-editor-proxy/dist/client/src/inspector.js.map +0 -1
  184. package/visual-editor-proxy/dist/client/src/main.d.ts +0 -6
  185. package/visual-editor-proxy/dist/client/src/main.js +0 -108
  186. package/visual-editor-proxy/dist/client/src/main.js.map +0 -1
  187. package/visual-editor-proxy/dist/client/src/ui.d.ts +0 -6
  188. package/visual-editor-proxy/dist/client/src/ui.js +0 -153
  189. package/visual-editor-proxy/dist/client/src/ui.js.map +0 -1
  190. package/visual-editor-proxy/dist/src/main.d.ts +0 -1
  191. package/visual-editor-proxy/dist/src/main.js +0 -61
  192. package/visual-editor-proxy/dist/src/main.js.map +0 -1
  193. package/visual-editor-proxy/dist/tsconfig.tsbuildinfo +0 -1
  194. package/visual-editor-proxy/package.json +0 -21
  195. package/visual-editor-proxy/tsconfig.json +0 -21
@@ -761,7 +761,7 @@ var require_plugin = __commonJS({
761
761
  const name = this.name;
762
762
  let completed = false;
763
763
  this.options = typeof this.options === "function" ? this.options(this.server) : this.options;
764
- let timer2 = null;
764
+ let timer3 = null;
765
765
  const done = (execErr) => {
766
766
  if (completed) {
767
767
  debug("loading complete", name);
@@ -774,16 +774,16 @@ var require_plugin = __commonJS({
774
774
  debug("exec completed", name);
775
775
  }
776
776
  completed = true;
777
- if (timer2) {
778
- clearTimeout(timer2);
777
+ if (timer3) {
778
+ clearTimeout(timer3);
779
779
  }
780
780
  callback(execErr);
781
781
  };
782
782
  if (this.timeout > 0) {
783
783
  debug("setting up timeout", name, this.timeout);
784
- timer2 = setTimeout(function() {
784
+ timer3 = setTimeout(function() {
785
785
  debug("timed out", name);
786
- timer2 = null;
786
+ timer3 = null;
787
787
  const readyTimeoutErr = new AVV_ERR_PLUGIN_EXEC_TIMEOUT(name);
788
788
  readyTimeoutErr.fn = func;
789
789
  done(readyTimeoutErr);
@@ -1370,9 +1370,9 @@ var require_avvio = __commonJS({
1370
1370
  function timeoutCall(func, rootErr, context, cb) {
1371
1371
  const name = func.unwrappedName ?? func.name;
1372
1372
  debug("setting up ready timeout", name, this._opts.timeout);
1373
- let timer2 = setTimeout(() => {
1373
+ let timer3 = setTimeout(() => {
1374
1374
  debug("timed out", name);
1375
- timer2 = null;
1375
+ timer3 = null;
1376
1376
  const toutErr = new AVV_ERR_READY_TIMEOUT(name);
1377
1377
  toutErr.fn = func;
1378
1378
  this._error = toutErr;
@@ -1384,9 +1384,9 @@ var require_avvio = __commonJS({
1384
1384
  func(rootErr, context, timeoutCb.bind(this));
1385
1385
  }
1386
1386
  function timeoutCb(err) {
1387
- if (timer2) {
1388
- clearTimeout(timer2);
1389
- timer2 = null;
1387
+ if (timer3) {
1388
+ clearTimeout(timer3);
1389
+ timer3 = null;
1390
1390
  this._error = err;
1391
1391
  process.nextTick(cb, this._error);
1392
1392
  } else {
@@ -41106,6 +41106,19 @@ function createTables(database) {
41106
41106
  UNIQUE(app_id, workspace_path)
41107
41107
  );
41108
41108
 
41109
+ -- Mini-app alarms (apps/app-alarms.ts): one row per (app, instance, name),
41110
+ -- deleted when it fires. fire_at is epoch ms. They outlive a pane restart:
41111
+ -- a due alarm fires right after startup.
41112
+ CREATE TABLE IF NOT EXISTS app_alarms (
41113
+ app_id TEXT NOT NULL,
41114
+ workspace_path TEXT NOT NULL DEFAULT '',
41115
+ name TEXT NOT NULL,
41116
+ fire_at INTEGER NOT NULL,
41117
+ data TEXT,
41118
+ created_at TEXT NOT NULL,
41119
+ PRIMARY KEY (app_id, workspace_path, name)
41120
+ );
41121
+
41109
41122
  CREATE TABLE IF NOT EXISTS cli_processes (
41110
41123
  pid INTEGER PRIMARY KEY,
41111
41124
  session_id TEXT NOT NULL,
@@ -44094,14 +44107,14 @@ var AppServerClient = class {
44094
44107
  }
44095
44108
  const id = this.nextId++;
44096
44109
  const message = JSON.stringify({ id, method, params }) + "\n";
44097
- const timer2 = setTimeout(() => {
44110
+ const timer3 = setTimeout(() => {
44098
44111
  this.pending.delete(id);
44099
44112
  reject(new Error(`Request '${method}' (id=${id}) timed out after ${REQUEST_TIMEOUT_MS}ms`));
44100
44113
  }, REQUEST_TIMEOUT_MS);
44101
44114
  this.pending.set(id, {
44102
44115
  resolve,
44103
44116
  reject,
44104
- timer: timer2
44117
+ timer: timer3
44105
44118
  });
44106
44119
  this.write(message);
44107
44120
  });
@@ -44176,14 +44189,14 @@ var AppServerClient = class {
44176
44189
  if (this.gone) return Promise.resolve(true);
44177
44190
  return new Promise((resolve) => {
44178
44191
  const onExit = () => {
44179
- clearTimeout(timer2);
44192
+ clearTimeout(timer3);
44180
44193
  resolve(true);
44181
44194
  };
44182
- const timer2 = setTimeout(() => {
44195
+ const timer3 = setTimeout(() => {
44183
44196
  this.proc.removeListener("exit", onExit);
44184
44197
  resolve(false);
44185
44198
  }, ms);
44186
- timer2.unref?.();
44199
+ timer3.unref?.();
44187
44200
  this.proc.once("exit", onExit);
44188
44201
  });
44189
44202
  }
@@ -44908,14 +44921,14 @@ var VscodeWebManager = class {
44908
44921
  waitForReady(inst) {
44909
44922
  const deadline = this.deps.now() + STARTUP_TIMEOUT_MS;
44910
44923
  return new Promise((resolve) => {
44911
- const timer2 = setInterval(async () => {
44924
+ const timer3 = setInterval(async () => {
44912
44925
  if (inst.state !== "starting") {
44913
- clearInterval(timer2);
44926
+ clearInterval(timer3);
44914
44927
  resolve();
44915
44928
  return;
44916
44929
  }
44917
44930
  if (this.deps.now() > deadline) {
44918
- clearInterval(timer2);
44931
+ clearInterval(timer3);
44919
44932
  inst.state = "error";
44920
44933
  inst.error = `serve-web did not become ready within ${STARTUP_TIMEOUT_MS / 1e3}s`;
44921
44934
  inst.stopping = true;
@@ -44927,7 +44940,7 @@ var VscodeWebManager = class {
44927
44940
  }
44928
44941
  try {
44929
44942
  await this.deps.probe(inst.port, inst.token, inst.id);
44930
- clearInterval(timer2);
44943
+ clearInterval(timer3);
44931
44944
  if (inst.state === "starting") {
44932
44945
  inst.state = "running";
44933
44946
  this.markAccessed(inst.id);
@@ -99413,7 +99426,8 @@ Each subdirectory of this folder is one mini app:
99413
99426
  <app-id>/
99414
99427
  manifest.json - { "title": string, "description"?: string, "icon"?: string,
99415
99428
  "tools"?: [{ "name", "description", "inputSchema" }],
99416
- "headlessSessions"?: boolean }
99429
+ "headlessSessions"?: boolean,
99430
+ "sessionActivity"?: boolean }
99417
99431
  "icon" is the app logo: a Lucide icon name (see
99418
99432
  "Icons and logos" below)
99419
99433
  index.html - markup only (full HTML document); do NOT reference app.js
@@ -99609,6 +99623,46 @@ runtime and events go to the open tab only.
99609
99623
  - events are not replayed. Keep the session ids in the state, and when the
99610
99624
  runtime loads ask getSession(id) what happened while the pane was down
99611
99625
 
99626
+ ## Other sessions' turns (manifest "sessionActivity")
99627
+
99628
+ Set "sessionActivity": true in manifest.json to hear when a turn starts or
99629
+ ends in a session the app did NOT open (the user's sessions, other apps'):
99630
+
99631
+ AgentPane.onSessionActivity(({ event, sessionId, turnId, origin, originName, cancelled }) => ...)
99632
+
99633
+ - event is 'turn:started', 'turn:completed' or 'turn:failed' (cancelled: true
99634
+ when the user stopped it); turns of discussion threads are left out
99635
+ - origin is 'peer' when a message from another Claude session (SendMessage)
99636
+ started the turn, with originName the sender's name; null otherwise
99637
+ - turn:started can come again for the same turnId (a background task's
99638
+ follow-up reopens the turn): dedupe by turnId
99639
+ - read the session with getSessionInfo(sessionId) (cwd, runtime_type,
99640
+ transcript_path); the prompt itself is in the transcript
99641
+ - fires in the headless runtime only, with or without a tab: in the global
99642
+ instance, and in every workspace instance that has state and sees the
99643
+ session. Register the listener synchronously at startup
99644
+ - the app's own sessions are not reported here: they have onTurnCompleted
99645
+
99646
+ ## Alarms
99647
+
99648
+ The headless runtime's setTimeout dies with it (pane restart, hot reload).
99649
+ For a wake-up that must happen, use an alarm; the pane keeps it in its
99650
+ database and fires it into the instance that set it, loading it if needed:
99651
+
99652
+ await AgentPane.setAlarm('checkin:' + id, 15 * 60_000, { id }); // { name, fireAt, data }
99653
+ AgentPane.onAlarm(({ name, data, fireAt }) => ...);
99654
+ await AgentPane.clearAlarm(name); // { cleared }
99655
+ await AgentPane.listAlarms(); // soonest first
99656
+
99657
+ - headless only: in the tab these reject (use callTool to reach the headless
99658
+ runtime) and onAlarm never fires there
99659
+ - names are per instance; setting a name again moves that alarm. An alarm
99660
+ fires once, then it is gone. delayMs is at most 30 days, data at most 64 KB
99661
+ of JSON, at most 200 alarms per instance
99662
+ - an alarm that came due while the pane was down fires right after startup;
99663
+ check the state before acting on it
99664
+ - register onAlarm synchronously at startup. Deleting the app drops its alarms
99665
+
99612
99666
  ## Result contract
99613
99667
 
99614
99668
  To give the app a structured result, put this requirement in the job prompt:
@@ -99629,12 +99683,20 @@ function readManifestIn(dir) {
99629
99683
  description: typeof parsed.description === "string" ? parsed.description : void 0,
99630
99684
  icon: typeof parsed.icon === "string" ? parsed.icon : void 0,
99631
99685
  tools: Array.isArray(parsed.tools) ? parsed.tools.filter((t) => t && typeof t.name === "string" && typeof t.description === "string") : void 0,
99632
- headlessSessions: parsed.headlessSessions === true ? true : void 0
99686
+ headlessSessions: parsed.headlessSessions === true ? true : void 0,
99687
+ sessionActivity: parsed.sessionActivity === true ? true : void 0
99633
99688
  };
99634
99689
  } catch {
99635
99690
  return null;
99636
99691
  }
99637
99692
  }
99693
+ function listAppIds() {
99694
+ try {
99695
+ return fs2.readdirSync(appsRoot(), { withFileTypes: true }).filter((entry) => entry.isDirectory() && APP_ID_RE.test(entry.name)).map((entry) => entry.name);
99696
+ } catch {
99697
+ return [];
99698
+ }
99699
+ }
99638
99700
  function readManifest(id) {
99639
99701
  return readManifestIn(appDir(id));
99640
99702
  }
@@ -99678,8 +99740,8 @@ function startAppsWatch(onAppChange) {
99678
99740
  const file2 = segs[segs.length - 1];
99679
99741
  if (!appId || appId === path5.basename(root) || !APP_ID_RE.test(appId) || file2 === "state.json") return;
99680
99742
  if (segs.length === 1 && isRegularFile(path5.join(root, appId))) return;
99681
- const timer2 = pendingChanges.get(appId);
99682
- if (timer2) clearTimeout(timer2);
99743
+ const timer3 = pendingChanges.get(appId);
99744
+ if (timer3) clearTimeout(timer3);
99683
99745
  pendingChanges.set(
99684
99746
  appId,
99685
99747
  setTimeout(() => {
@@ -99697,7 +99759,7 @@ function stopAppsWatch() {
99697
99759
  watcher.close();
99698
99760
  watcher = null;
99699
99761
  }
99700
- for (const timer2 of pendingChanges.values()) clearTimeout(timer2);
99762
+ for (const timer3 of pendingChanges.values()) clearTimeout(timer3);
99701
99763
  pendingChanges.clear();
99702
99764
  }
99703
99765
 
@@ -100214,6 +100276,13 @@ function appSessionSummary(appId, workspace, sessionId) {
100214
100276
  if (!session || !sessionVisibleTo(session, appId, workspace)) return null;
100215
100277
  return sessionSummary(session, appId);
100216
100278
  }
100279
+ function activityInstances(appId, sessionId) {
100280
+ const db2 = getDb();
100281
+ const session = db2.prepare("SELECT * FROM sessions WHERE id = ?").get(sessionId);
100282
+ if (!session || openedByApp(session, appId)) return [];
100283
+ const rows = db2.prepare("SELECT workspace_path FROM app_instances WHERE app_id = ? AND workspace_path != '' ORDER BY workspace_path").all(appId);
100284
+ return ["", ...rows.map((r) => r.workspace_path).filter((w) => sessionVisibleTo(session, appId, w))];
100285
+ }
100217
100286
  function ownSession(appId, sessionId, api) {
100218
100287
  const session = getDb().prepare("SELECT * FROM sessions WHERE id = ?").get(String(sessionId));
100219
100288
  if (!session || !openedByApp(session, appId)) {
@@ -100256,6 +100325,124 @@ function toolCaller(appId, sessionId) {
100256
100325
  // src/apps/headless-runtime.ts
100257
100326
  import vm2 from "node:vm";
100258
100327
 
100328
+ // src/apps/app-alarms.ts
100329
+ var MAX_ALARM_DELAY_MS = 30 * 24 * 60 * 60 * 1e3;
100330
+ var MAX_ALARMS_PER_INSTANCE = 200;
100331
+ var MAX_NAME_LENGTH = 200;
100332
+ var MAX_DATA_BYTES = 64 * 1024;
100333
+ var MAX_TIMER_WAIT_MS = 60 * 60 * 1e3;
100334
+ function parseData(raw) {
100335
+ if (raw == null) return null;
100336
+ try {
100337
+ return JSON.parse(raw);
100338
+ } catch {
100339
+ return null;
100340
+ }
100341
+ }
100342
+ function toAlarm(row) {
100343
+ return { name: row.name, fireAt: row.fire_at, data: parseData(row.data) };
100344
+ }
100345
+ function setAppAlarm(appId, workspace, name, delayMs, data) {
100346
+ if (typeof name !== "string" || !name.trim() || name.length > MAX_NAME_LENGTH) {
100347
+ throw new Error(`setAlarm: name must be a non-empty string of at most ${MAX_NAME_LENGTH} characters`);
100348
+ }
100349
+ if (typeof delayMs !== "number" || !Number.isFinite(delayMs) || delayMs < 0) {
100350
+ throw new Error("setAlarm: delayMs must be a number of milliseconds, 0 or more");
100351
+ }
100352
+ if (delayMs > MAX_ALARM_DELAY_MS) {
100353
+ throw new Error(`setAlarm: delayMs is at most ${MAX_ALARM_DELAY_MS} (30 days)`);
100354
+ }
100355
+ let json2 = null;
100356
+ if (data !== void 0) {
100357
+ try {
100358
+ json2 = JSON.stringify(data) ?? null;
100359
+ } catch {
100360
+ throw new Error("setAlarm: data must be JSON");
100361
+ }
100362
+ if (json2 && Buffer.byteLength(json2) > MAX_DATA_BYTES) {
100363
+ throw new Error(`setAlarm: data is at most ${MAX_DATA_BYTES} bytes of JSON`);
100364
+ }
100365
+ }
100366
+ const db2 = getDb();
100367
+ const exists2 = db2.prepare("SELECT 1 FROM app_alarms WHERE app_id = ? AND workspace_path = ? AND name = ?").get(appId, workspace, name);
100368
+ if (!exists2) {
100369
+ const { n } = db2.prepare("SELECT COUNT(*) AS n FROM app_alarms WHERE app_id = ? AND workspace_path = ?").get(appId, workspace);
100370
+ if (n >= MAX_ALARMS_PER_INSTANCE) {
100371
+ throw new Error(`setAlarm: an instance holds at most ${MAX_ALARMS_PER_INSTANCE} alarms; clear one first`);
100372
+ }
100373
+ }
100374
+ const fireAt = Date.now() + Math.round(delayMs);
100375
+ db2.prepare(
100376
+ `INSERT INTO app_alarms (app_id, workspace_path, name, fire_at, data, created_at)
100377
+ VALUES (?, ?, ?, ?, ?, ?)
100378
+ ON CONFLICT(app_id, workspace_path, name) DO UPDATE SET
100379
+ fire_at = excluded.fire_at, data = excluded.data, created_at = excluded.created_at`
100380
+ ).run(appId, workspace, name, fireAt, json2, (/* @__PURE__ */ new Date()).toISOString());
100381
+ schedule();
100382
+ return { name, fireAt, data: parseData(json2) };
100383
+ }
100384
+ function clearAppAlarm(appId, workspace, name) {
100385
+ if (typeof name !== "string") throw new Error("clearAlarm: name must be a string");
100386
+ const { changes } = getDb().prepare("DELETE FROM app_alarms WHERE app_id = ? AND workspace_path = ? AND name = ?").run(appId, workspace, name);
100387
+ schedule();
100388
+ return { cleared: changes > 0 };
100389
+ }
100390
+ function listAppAlarms(appId, workspace) {
100391
+ const rows = getDb().prepare("SELECT * FROM app_alarms WHERE app_id = ? AND workspace_path = ? ORDER BY fire_at, name").all(appId, workspace);
100392
+ return rows.map(toAlarm);
100393
+ }
100394
+ function deleteAppAlarms(appId) {
100395
+ getDb().prepare("DELETE FROM app_alarms WHERE app_id = ?").run(appId);
100396
+ schedule();
100397
+ }
100398
+ var deliver = null;
100399
+ var timer2 = null;
100400
+ function fireDueAlarms(now = Date.now()) {
100401
+ const db2 = getDb();
100402
+ const due = db2.transaction(() => {
100403
+ const rows = db2.prepare("SELECT * FROM app_alarms WHERE fire_at <= ? ORDER BY fire_at, name").all(now);
100404
+ const drop = db2.prepare("DELETE FROM app_alarms WHERE app_id = ? AND workspace_path = ? AND name = ?");
100405
+ for (const row of rows) drop.run(row.app_id, row.workspace_path, row.name);
100406
+ return rows;
100407
+ }).immediate().map((row) => ({ appId: row.app_id, workspace: row.workspace_path, ...toAlarm(row) }));
100408
+ for (const alarm of due) {
100409
+ try {
100410
+ deliver?.(alarm);
100411
+ } catch (err) {
100412
+ console.error(`[alarms] ${alarm.appId} alarm ${alarm.name} failed:`, err);
100413
+ }
100414
+ }
100415
+ return due;
100416
+ }
100417
+ function schedule() {
100418
+ if (!deliver) return;
100419
+ if (timer2) clearTimeout(timer2);
100420
+ timer2 = null;
100421
+ const next = getDb().prepare("SELECT MIN(fire_at) AS at FROM app_alarms").get();
100422
+ if (next.at == null) return;
100423
+ const wait = Math.min(Math.max(next.at - Date.now(), 0), MAX_TIMER_WAIT_MS);
100424
+ timer2 = setTimeout(() => {
100425
+ timer2 = null;
100426
+ try {
100427
+ fireDueAlarms();
100428
+ } catch (err) {
100429
+ console.error("[alarms] firing failed:", err);
100430
+ }
100431
+ schedule();
100432
+ }, wait);
100433
+ timer2.unref?.();
100434
+ }
100435
+ function startAppAlarms(onDue) {
100436
+ stopAppAlarms();
100437
+ deliver = onDue;
100438
+ schedule();
100439
+ }
100440
+ function stopAppAlarms() {
100441
+ if (timer2) clearTimeout(timer2);
100442
+ timer2 = null;
100443
+ deliver = null;
100444
+ }
100445
+
100259
100446
  // src/apps/app-compile.ts
100260
100447
  import vm from "node:vm";
100261
100448
  import path9 from "node:path";
@@ -100464,6 +100651,23 @@ interface AgentPaneFileData { name?: string; type?: string; data: string }
100464
100651
  type AgentPaneFileRef = string | { id?: string; url?: string };
100465
100652
  /** A submitTurn attachment: a stored file, or inline bytes sent with that turn only. */
100466
100653
  type AgentPaneAttachment = AgentPaneFileRef | Blob | AgentPaneFileData;
100654
+ /** onSessionActivity: a turn started or ended in a session this app did not
100655
+ * open. Read the session with getSessionInfo (cwd, runtime_type,
100656
+ * transcript_path). */
100657
+ interface AgentPaneSessionActivity {
100658
+ event: 'turn:started' | 'turn:completed' | 'turn:failed';
100659
+ sessionId: string;
100660
+ turnId: string;
100661
+ /** 'peer': a message from another Claude session (SendMessage) started the
100662
+ * turn; null: the user, or an app. */
100663
+ origin: 'peer' | null;
100664
+ /** The sending session's name for a peer turn, else null. */
100665
+ originName: string | null;
100666
+ /** turn:failed of a turn the user stopped. */
100667
+ cancelled?: boolean;
100668
+ }
100669
+ /** An alarm of this instance (setAlarm). fireAt is epoch ms. */
100670
+ interface AgentPaneAlarm { name: string; fireAt: number; data: unknown }
100467
100671
  interface AgentPaneSubmitTurnOptions {
100468
100672
  /** Files the agent receives with the prompt (images are shown to the model). */
100469
100673
  attachments?: AgentPaneAttachment[];
@@ -100515,6 +100719,21 @@ declare const AgentPane: {
100515
100719
  /** Fires when the live background-task set of one of the app's sessions
100516
100720
  * changes (also empty sets, when the last task ends). */
100517
100721
  onBackgroundTasks(cb: (payload: AgentPaneBackgroundTasksPayload | null) => void): void;
100722
+ /** Headless only, with "sessionActivity": true in the manifest: a turn
100723
+ * started or ended in a session this app did not open (the user's), in
100724
+ * this instance's sight. turn:started can come again for the same turnId
100725
+ * when a background task's follow-up reopens the turn. */
100726
+ onSessionActivity(cb: (payload: AgentPaneSessionActivity) => void): void;
100727
+ /** Headless only: wake this instance in delayMs (at most 30 days), also
100728
+ * after a pane restart. Setting a name again moves that alarm. data (JSON)
100729
+ * comes back with it. Rejects in the tab. */
100730
+ setAlarm(name: string, delayMs: number, data?: unknown): Promise<AgentPaneAlarm>;
100731
+ /** Headless only: drop an alarm; cleared is false when none had the name. */
100732
+ clearAlarm(name: string): Promise<{ cleared: boolean }>;
100733
+ /** Headless only: this instance's alarms, soonest first. */
100734
+ listAlarms(): Promise<AgentPaneAlarm[]>;
100735
+ /** Headless only: an alarm of this instance came due. It fires once. */
100736
+ onAlarm(cb: (alarm: AgentPaneAlarm) => void): void;
100518
100737
  resolveToolCall(callId: string, result?: unknown): Promise<{ ok: boolean }>;
100519
100738
  /** Show a session in the pane (switches the view to its conversation).
100520
100739
  * Only works while the app is on screen: call it from a click handler. */
@@ -100808,7 +101027,13 @@ function loadRuntime(appId, workspace) {
100808
101027
  if (headlessSessions) return;
100809
101028
  throw new Error(`${api} is not available in the headless runtime without "headlessSessions": true in manifest.json`);
100810
101029
  };
100811
- const entry = { handler: null, turnListeners: [], taskListeners: [] };
101030
+ const entry = {
101031
+ handler: null,
101032
+ turnListeners: [],
101033
+ taskListeners: [],
101034
+ activityListeners: [],
101035
+ alarmListeners: []
101036
+ };
100812
101037
  const bridge = {
100813
101038
  getApp: () => answer(() => ({ id: appId, title: manifest?.title ?? appId, workspace })),
100814
101039
  // State is scoped to the calling session's workspace instance; '' = global
@@ -100884,9 +101109,23 @@ function loadRuntime(appId, workspace) {
100884
101109
  onBackgroundTasks: (cb) => {
100885
101110
  if (typeof cb === "function") entry.taskListeners.push(cb);
100886
101111
  },
100887
- // Live streaming is for a screen; nothing here renders.
101112
+ // Heard only with "sessionActivity" in the manifest (deliverSessionActivity).
101113
+ onSessionActivity: (cb) => {
101114
+ if (typeof cb === "function") entry.activityListeners.push(cb);
101115
+ },
101116
+ setAlarm: (name, delayMs, data) => answer(() => setAppAlarm(appId, workspace, name, delayMs, data)),
101117
+ clearAlarm: (name) => answer(() => clearAppAlarm(appId, workspace, name)),
101118
+ listAlarms: () => answer(() => listAppAlarms(appId, workspace)),
101119
+ onAlarm: (cb) => {
101120
+ if (typeof cb === "function") entry.alarmListeners.push(cb);
101121
+ },
101122
+ // Live streaming is for a screen; nothing here renders. The same goes for
101123
+ // state changes: the tab re-renders on them, and an app.ts shared by tab
101124
+ // and runtime registers that at startup — which must not fail the load.
100888
101125
  onTurnDelta: () => {
100889
101126
  },
101127
+ onStateChanged: () => {
101128
+ },
100890
101129
  // UI actions are intentionally unavailable headless.
100891
101130
  openSession: () => answer(() => {
100892
101131
  throw new Error("openSession is not available in the headless runtime");
@@ -100915,7 +101154,8 @@ function loadRuntime(appId, workspace) {
100915
101154
  console.warn(`[headless:${appId}] app.js load failed: ${err.message}`);
100916
101155
  return null;
100917
101156
  }
100918
- if (!entry.handler && !entry.turnListeners.length && !entry.taskListeners.length) return null;
101157
+ const listens = entry.turnListeners.length || entry.taskListeners.length || entry.activityListeners.length || entry.alarmListeners.length;
101158
+ if (!entry.handler && !listens) return null;
100919
101159
  runtimes.set(key, entry);
100920
101160
  return entry;
100921
101161
  }
@@ -100925,7 +101165,7 @@ function getHeadlessToolHandler(appId, workspace = "") {
100925
101165
  function dispatchHeadlessToolCall(handler, tool2, args, caller = null) {
100926
101166
  const callId = v4_default();
100927
101167
  const result = new Promise((resolve, reject) => {
100928
- const timer2 = setTimeout(() => {
101168
+ const timer3 = setTimeout(() => {
100929
101169
  pendingCalls.delete(callId);
100930
101170
  reject(
100931
101171
  new Error(
@@ -100933,7 +101173,7 @@ function dispatchHeadlessToolCall(handler, tool2, args, caller = null) {
100933
101173
  )
100934
101174
  );
100935
101175
  }, HEADLESS_TOOL_TIMEOUT_MS);
100936
- pendingCalls.set(callId, { resolve, reject, timer: timer2 });
101176
+ pendingCalls.set(callId, { resolve, reject, timer: timer3 });
100937
101177
  });
100938
101178
  const crashed = (err) => {
100939
101179
  const pending = pendingCalls.get(callId);
@@ -100985,6 +101225,49 @@ function deliverSessionEvent(event, data) {
100985
101225
  for (const listener of runtime.turnListeners) runAppCode(appId, () => listener(name, payload));
100986
101226
  }
100987
101227
  var SESSION_EVENTS = /* @__PURE__ */ new Set(["turn:completed", "turn:failed", "turn:cancelled", "background_tasks"]);
101228
+ var ACTIVITY_EVENTS = /* @__PURE__ */ new Set(["turn:started", "turn:completed", "turn:failed", "turn:cancelled"]);
101229
+ var activityApps = null;
101230
+ function sessionActivityApps() {
101231
+ activityApps ??= listAppIds().filter((id) => readManifest(id)?.sessionActivity === true);
101232
+ return activityApps;
101233
+ }
101234
+ function activityPayload(event, data) {
101235
+ const sessionId = String(data.sessionId);
101236
+ const turnId = String(data.turnId);
101237
+ const turn = getTurnOrigin(turnId);
101238
+ if (!turn || turn.thread_id || turn.session_id !== sessionId) return null;
101239
+ const peer = turn.origin === "peer";
101240
+ const base = { sessionId, turnId, origin: peer ? "peer" : null, originName: peer ? turn.origin_name : null };
101241
+ if (event === "turn:started") return { event, ...base };
101242
+ const [name, payload] = turnEvent(event, data);
101243
+ return { event: name, ...base, ...payload.cancelled ? { cancelled: true } : {} };
101244
+ }
101245
+ function getTurnOrigin(turnId) {
101246
+ const row = getDb().prepare("SELECT session_id, thread_id, origin, origin_name FROM turns WHERE id = ?").get(turnId);
101247
+ return row ?? null;
101248
+ }
101249
+ function deliverSessionActivity(event, data) {
101250
+ const apps = sessionActivityApps();
101251
+ if (!apps.length) return;
101252
+ const payload = activityPayload(event, data);
101253
+ if (!payload) return;
101254
+ for (const appId of apps) {
101255
+ for (const workspace of activityInstances(appId, String(payload.sessionId))) {
101256
+ const runtime = loadRuntime(appId, workspace);
101257
+ if (!runtime) continue;
101258
+ for (const listener of runtime.activityListeners) runAppCode(appId, () => listener({ ...payload }));
101259
+ }
101260
+ }
101261
+ }
101262
+ function deliverAlarm(alarm) {
101263
+ const runtime = loadRuntime(alarm.appId, alarm.workspace);
101264
+ if (!runtime?.alarmListeners.length) {
101265
+ console.warn(`[headless:${alarm.appId}] alarm ${alarm.name} dropped: the app has no onAlarm listener headless`);
101266
+ return;
101267
+ }
101268
+ const payload = { name: alarm.name, data: alarm.data, fireAt: alarm.fireAt };
101269
+ for (const listener of runtime.alarmListeners) runAppCode(alarm.appId, () => listener({ ...payload }));
101270
+ }
100988
101271
  function handleUnhandledRejection(reason, promise2) {
100989
101272
  if (promise2 instanceof Promise) throw reason;
100990
101273
  console.error("[headless] unhandled rejection in app code:", reason);
@@ -100993,18 +101276,28 @@ var stopSessionEvents = null;
100993
101276
  function startHeadlessEvents() {
100994
101277
  stopHeadlessEvents();
100995
101278
  const untap2 = tapBroadcast((event, data) => {
100996
- if (!SESSION_EVENTS.has(event)) return;
101279
+ const session = SESSION_EVENTS.has(event);
101280
+ const activity = ACTIVITY_EVENTS.has(event);
101281
+ if (!session && !activity) return;
100997
101282
  setImmediate(() => {
100998
- try {
100999
- deliverSessionEvent(event, data);
101000
- } catch (err) {
101001
- console.error(`[headless] ${event} delivery failed:`, err);
101283
+ for (const [wanted, deliver2] of [
101284
+ [session, deliverSessionEvent],
101285
+ [activity, deliverSessionActivity]
101286
+ ]) {
101287
+ if (!wanted) continue;
101288
+ try {
101289
+ deliver2(event, data);
101290
+ } catch (err) {
101291
+ console.error(`[headless] ${event} delivery failed:`, err);
101292
+ }
101002
101293
  }
101003
101294
  });
101004
101295
  });
101005
101296
  process.on("unhandledRejection", handleUnhandledRejection);
101297
+ startAppAlarms(deliverAlarm);
101006
101298
  stopSessionEvents = () => {
101007
101299
  untap2();
101300
+ stopAppAlarms();
101008
101301
  process.off("unhandledRejection", handleUnhandledRejection);
101009
101302
  };
101010
101303
  }
@@ -101014,6 +101307,7 @@ function stopHeadlessEvents() {
101014
101307
  }
101015
101308
  function invalidateHeadlessRuntime(appId) {
101016
101309
  invalidateCompiledApp(appId);
101310
+ activityApps = null;
101017
101311
  if (!appId) {
101018
101312
  runtimes.clear();
101019
101313
  return;
@@ -101134,7 +101428,7 @@ function dispatchAppTool(toolName, args, workspace = "", callerSessionId) {
101134
101428
  }
101135
101429
  const callId = v4_default();
101136
101430
  const result = new Promise((resolve, reject) => {
101137
- const timer2 = setTimeout(() => {
101431
+ const timer3 = setTimeout(() => {
101138
101432
  pendingCalls2.delete(callId);
101139
101433
  reject(
101140
101434
  new Error(
@@ -101142,7 +101436,7 @@ function dispatchAppTool(toolName, args, workspace = "", callerSessionId) {
101142
101436
  )
101143
101437
  );
101144
101438
  }, TOOL_CALL_TIMEOUT_MS);
101145
- pendingCalls2.set(callId, { resolve, reject, timer: timer2, appId });
101439
+ pendingCalls2.set(callId, { resolve, reject, timer: timer3, appId });
101146
101440
  broadcast("app:tool_call", { appId, callId, tool: localName, args: args ?? {}, workspace, caller });
101147
101441
  });
101148
101442
  return { callId, result };
@@ -101888,6 +102182,7 @@ async function registerAppRoutes(fastify, opts) {
101888
102182
  fs7.rmSync(appDir(id), { recursive: true, force: true });
101889
102183
  deleteAppFiles(id);
101890
102184
  deleteAppInstances(id);
102185
+ deleteAppAlarms(id);
101891
102186
  invalidateHeadlessRuntime(id);
101892
102187
  return { ok: true };
101893
102188
  });
@@ -102142,7 +102437,7 @@ function runCcusage(args) {
102142
102437
  failure ??= reason;
102143
102438
  child.kill("SIGTERM");
102144
102439
  };
102145
- const timer2 = setTimeout(() => stop(`ccusage did not finish in ${RUN_TIMEOUT_MS / 1e3}s`), RUN_TIMEOUT_MS);
102440
+ const timer3 = setTimeout(() => stop(`ccusage did not finish in ${RUN_TIMEOUT_MS / 1e3}s`), RUN_TIMEOUT_MS);
102146
102441
  child.stdout.on("data", (chunk) => {
102147
102442
  size2 += chunk.length;
102148
102443
  if (size2 > MAX_OUTPUT_BYTES) stop("ccusage output is too large");
@@ -102152,11 +102447,11 @@ function runCcusage(args) {
102152
102447
  if (stderr.length < 16384) stderr += chunk.toString("utf8");
102153
102448
  });
102154
102449
  child.on("error", (err) => {
102155
- clearTimeout(timer2);
102450
+ clearTimeout(timer3);
102156
102451
  reject(new Error(`ccusage could not start: ${err.message}`));
102157
102452
  });
102158
102453
  child.on("close", (code, signal) => {
102159
- clearTimeout(timer2);
102454
+ clearTimeout(timer3);
102160
102455
  if (failure) return reject(new Error(failure));
102161
102456
  if (code !== 0) {
102162
102457
  const detail = stderr.trim().split("\n").slice(-3).join(" ").slice(0, 500);
@@ -118568,11 +118863,11 @@ function requestHost(dir, body, timeoutMs = 2e3) {
118568
118863
  const sock = net2.connect(hostSocketPath(dir));
118569
118864
  let buf = "";
118570
118865
  let settled = false;
118571
- const timer2 = setTimeout(() => finish(Object.assign(new Error("session host timed out"), { code: "ETIMEDOUT" })), timeoutMs);
118866
+ const timer3 = setTimeout(() => finish(Object.assign(new Error("session host timed out"), { code: "ETIMEDOUT" })), timeoutMs);
118572
118867
  const finish = (err, value) => {
118573
118868
  if (settled) return;
118574
118869
  settled = true;
118575
- clearTimeout(timer2);
118870
+ clearTimeout(timer3);
118576
118871
  sock.destroy();
118577
118872
  if (err) reject(err);
118578
118873
  else resolve(value);
@@ -118627,11 +118922,11 @@ function attachHost(dir, after, timeoutMs = 5e3) {
118627
118922
  const sock = net2.connect(hostSocketPath(dir));
118628
118923
  let head = Buffer.alloc(0);
118629
118924
  let settled = false;
118630
- const timer2 = setTimeout(() => fail(Object.assign(new Error("session host attach timed out"), { code: "ETIMEDOUT" })), timeoutMs);
118925
+ const timer3 = setTimeout(() => fail(Object.assign(new Error("session host attach timed out"), { code: "ETIMEDOUT" })), timeoutMs);
118631
118926
  const fail = (err) => {
118632
118927
  if (settled) return;
118633
118928
  settled = true;
118634
- clearTimeout(timer2);
118929
+ clearTimeout(timer3);
118635
118930
  sock.destroy();
118636
118931
  reject(err);
118637
118932
  };
@@ -118656,7 +118951,7 @@ function attachHost(dir, after, timeoutMs = 5e3) {
118656
118951
  return;
118657
118952
  }
118658
118953
  settled = true;
118659
- clearTimeout(timer2);
118954
+ clearTimeout(timer3);
118660
118955
  sock.off("error", fail);
118661
118956
  sock.off("close", onEarlyClose);
118662
118957
  const attachment = new HostAttachment(header, sock);
@@ -119827,6 +120122,21 @@ function reapOrphanCliProcesses(db2, deps = defaultDeps) {
119827
120122
  return reapOrphanProcesses(db2, "claude", deps);
119828
120123
  }
119829
120124
 
120125
+ // src/providers/thread-summary.ts
120126
+ function buildThreadSummaryPrompt(transcript, directives) {
120127
+ const directiveLine = directives.trim() ? `
120128
+
120129
+ The user has given these summarization directives \u2014 follow them exactly:
120130
+ "${directives.trim()}"` : "";
120131
+ return `You are summarizing a side discussion thread that forked from a main agent session. The discussion begins at the FIRST message of the transcript below \u2014 summarize ONLY the discussion itself, from its beginning up to now.${directiveLine}
120132
+
120133
+ The discussion transcript (from the discussion's beginning):
120134
+
120135
+ ${transcript}
120136
+
120137
+ Produce a concise summary of the discussion that preserves: concrete findings, file paths, decisions, and any unresolved questions. Reply with only the summary text, nothing else.`;
120138
+ }
120139
+
119830
120140
  // src/codex/codex-provider.ts
119831
120141
  var TERMINAL_TASK_TYPE = "background_terminal";
119832
120142
  function taskPollMs() {
@@ -120158,7 +120468,9 @@ function completeTurn(db2, sessionId, turnId, usage) {
120158
120468
  const response = turnResponse(db2, turnId);
120159
120469
  const result = usage !== void 0 ? db2.prepare(
120160
120470
  "UPDATE turns SET status = 'completed', token_usage = ?, updated_at = ? WHERE id = ? AND status IN ('pending', 'running')"
120161
- ).run(JSON.stringify(usage), now, turnId) : db2.prepare("UPDATE turns SET status = 'completed', updated_at = ? WHERE id = ? AND status IN ('pending', 'running')").run(now, turnId);
120471
+ ).run(JSON.stringify(usage), now, turnId) : db2.prepare(
120472
+ "UPDATE turns SET status = 'completed', updated_at = ? WHERE id = ? AND status IN ('pending', 'running')"
120473
+ ).run(now, turnId);
120162
120474
  if (result.changes === 0) return;
120163
120475
  broadcast("turn:completed", {
120164
120476
  sessionId,
@@ -120595,15 +120907,15 @@ function handleItemEvent(params, sessionId, turnId, status, broadcastEvent, extr
120595
120907
  }
120596
120908
  function within(promise2, ms) {
120597
120909
  return new Promise((resolve) => {
120598
- const timer2 = setTimeout(() => resolve(null), ms);
120599
- timer2.unref?.();
120910
+ const timer3 = setTimeout(() => resolve(null), ms);
120911
+ timer3.unref?.();
120600
120912
  promise2.then(
120601
120913
  (value) => {
120602
- clearTimeout(timer2);
120914
+ clearTimeout(timer3);
120603
120915
  resolve(value);
120604
120916
  },
120605
120917
  () => {
120606
- clearTimeout(timer2);
120918
+ clearTimeout(timer3);
120607
120919
  resolve(null);
120608
120920
  }
120609
120921
  );
@@ -120810,17 +121122,7 @@ async function summarizeCodexThread(session, _thread, transcript, directives) {
120810
121122
  ephemeral: true
120811
121123
  });
120812
121124
  const threadId = initResult.thread.id;
120813
- const directiveLine = directives.trim() ? `
120814
-
120815
- The user has given these summarization directives \u2014 follow them exactly:
120816
- "${directives.trim()}"` : "";
120817
- const summaryPrompt = `You are summarizing a side discussion thread that forked from a main agent session. The discussion begins at the FIRST message of the transcript below \u2014 summarize ONLY the discussion itself, from its beginning up to now.${directiveLine}
120818
-
120819
- The discussion transcript (from the discussion's beginning):
120820
-
120821
- ${transcript}
120822
-
120823
- Produce a concise summary of the discussion that preserves: concrete findings, file paths, decisions, and any unresolved questions. Reply with only the summary text, nothing else.`;
121125
+ const summaryPrompt = buildThreadSummaryPrompt(transcript, directives);
120824
121126
  let summaryResolve;
120825
121127
  let summaryReject;
120826
121128
  const summaryPromise = new Promise((resolve, reject) => {
@@ -120926,7 +121228,10 @@ async function forkSession(session, targetTurn) {
120926
121228
  try {
120927
121229
  result = await fork({ lastTurnId });
120928
121230
  } catch (err) {
120929
- const range = await client.request("thread/read", { threadId, includeTurns: true }).then(({ thread }) => forkThroughReview(thread.turns ?? [], lastTurnId), () => void 0);
121231
+ const range = await client.request("thread/read", { threadId, includeTurns: true }).then(
121232
+ ({ thread }) => forkThroughReview(thread.turns ?? [], lastTurnId),
121233
+ () => void 0
121234
+ );
120930
121235
  if (!range) throw err;
120931
121236
  result = await fork(range);
120932
121237
  }
@@ -121167,7 +121472,9 @@ function hostFor(sessionId, cwd, options, onDirect) {
121167
121472
  const { command, args } = appServerCommand(options);
121168
121473
  return startCodexHost(getDb(), { sessionId, cwd, command, args, env: { ...process.env }, onDirect });
121169
121474
  } catch (err) {
121170
- console.error(`[codex] no session host for ${sessionId} (${err.message}); running the app-server directly`);
121475
+ console.error(
121476
+ `[codex] no session host for ${sessionId} (${err.message}); running the app-server directly`
121477
+ );
121171
121478
  return null;
121172
121479
  }
121173
121480
  }
@@ -121221,7 +121528,9 @@ function settleHostTurn(entry) {
121221
121528
  function maybeRetire(entry) {
121222
121529
  const why = entry.retireWhenIdle;
121223
121530
  if (!why || entry.replaying || entry.turns.length > 0 || !isCurrent(entry)) return;
121224
- console.log(`[codex] closing the idle app-server of session ${entry.sessionId} (${why}); the next prompt starts a new one`);
121531
+ console.log(
121532
+ `[codex] closing the idle app-server of session ${entry.sessionId} (${why}); the next prompt starts a new one`
121533
+ );
121225
121534
  void retireEntry(entry, "keep");
121226
121535
  }
121227
121536
  function detachEntry(entry) {
@@ -121302,16 +121611,16 @@ function replayDone(client, what) {
121302
121611
  if (!client.replaying || client.isClosed()) return Promise.resolve();
121303
121612
  return new Promise((resolve) => {
121304
121613
  const done = () => {
121305
- clearTimeout(timer2);
121614
+ clearTimeout(timer3);
121306
121615
  client.events.off("replayDone", done);
121307
121616
  client.events.off("closed", done);
121308
121617
  resolve();
121309
121618
  };
121310
- const timer2 = setTimeout(() => {
121619
+ const timer3 = setTimeout(() => {
121311
121620
  console.error(`[codex] the replay of ${what} takes long; startup goes on`);
121312
121621
  done();
121313
121622
  }, REPLAY_WAIT_MS);
121314
- timer2.unref?.();
121623
+ timer3.unref?.();
121315
121624
  client.events.once("replayDone", done);
121316
121625
  client.events.once("closed", done);
121317
121626
  });
@@ -121383,7 +121692,9 @@ var codexHostAdopter = {
121383
121692
  if (!session || session.runtime_type !== "codex") return;
121384
121693
  const detail = describeExit(exit);
121385
121694
  const threadId = row.external_id ?? session.external_thread_id;
121386
- console.log(`[codex] the app-server of session ${session.id} ended with no daemon attached (${detail}); replaying its log`);
121695
+ console.log(
121696
+ `[codex] the app-server of session ${session.id} ended with no daemon attached (${detail}); replaying its log`
121697
+ );
121387
121698
  if (log && log.length > 0 && threadId) {
121388
121699
  const logged = new LoggedAppServer();
121389
121700
  const client = new AppServerClient({ cwd: session.cwd ?? process.cwd(), process: logged, replaying: true });
@@ -123414,7 +123725,7 @@ Agent responded: "${truncatedResponse}"`;
123414
123725
  }
123415
123726
  }
123416
123727
  }
123417
- function buildThreadSummaryPrompt(transcript, directives, hasNativeContext) {
123728
+ function buildThreadSummaryPrompt2(transcript, directives, hasNativeContext) {
123418
123729
  const directiveLine = directives.trim() ? `
123419
123730
 
123420
123731
  The user has given these summarization directives \u2014 follow them exactly:
@@ -123442,7 +123753,7 @@ async function summarizeClaudeThread(session, thread, transcript, directives) {
123442
123753
  console.error("[claude] summarizeThread fork failed \u2014 falling back to embedded transcript:", err);
123443
123754
  }
123444
123755
  }
123445
- const prompt = buildThreadSummaryPrompt(transcript, directives, !!resumeId);
123756
+ const prompt = buildThreadSummaryPrompt2(transcript, directives, !!resumeId);
123446
123757
  q = query({
123447
123758
  prompt,
123448
123759
  options: {
@@ -123676,18 +123987,18 @@ var claudeHostAdopter = {
123676
123987
  retire
123677
123988
  });
123678
123989
  refreshHostLimit2(entry, running);
123679
- let timer2 = null;
123990
+ let timer3 = null;
123680
123991
  await Promise.race([
123681
123992
  entry.replayDone,
123682
123993
  new Promise((resolve) => {
123683
- timer2 = setTimeout(() => {
123994
+ timer3 = setTimeout(() => {
123684
123995
  console.error(`[claude] the replay of ${row.entry_key} takes long; startup goes on`);
123685
123996
  resolve();
123686
123997
  }, REPLAY_WAIT_MS2);
123687
- timer2.unref?.();
123998
+ timer3.unref?.();
123688
123999
  })
123689
124000
  ]);
123690
- if (timer2) clearTimeout(timer2);
124001
+ if (timer3) clearTimeout(timer3);
123691
124002
  console.log(
123692
124003
  `[claude] adopted the CLI of ${row.entry_key} (pid ${proc.pid ?? "?"})${running ? `, turn ${row.turn_id} goes on` : ""}${retire ? `; it closes once idle: ${retire}` : ""}`
123693
124004
  );
@@ -123885,12 +124196,12 @@ var HttpError = class extends Error {
123885
124196
  };
123886
124197
  async function fetchJson(url2, init, timeoutMs = 5e3) {
123887
124198
  const controller = new AbortController();
123888
- const timer2 = setTimeout(() => controller.abort(), timeoutMs);
124199
+ const timer3 = setTimeout(() => controller.abort(), timeoutMs);
123889
124200
  let response;
123890
124201
  try {
123891
124202
  response = await fetch(url2, { ...init, signal: controller.signal });
123892
124203
  } finally {
123893
- clearTimeout(timer2);
124204
+ clearTimeout(timer3);
123894
124205
  }
123895
124206
  const text2 = await response.text();
123896
124207
  if (!response.ok) {
@@ -124056,7 +124367,7 @@ function parseSelectionGroups(raw) {
124056
124367
  }).filter((g) => g !== null);
124057
124368
  }
124058
124369
  function mapActionToItem(action) {
124059
- const failed = action.status === "EXECUTION_FAILED";
124370
+ const failed = String(action.status ?? "").toLowerCase() === "execution_failed";
124060
124371
  const status = failed ? "failed" : "completed";
124061
124372
  const log = action.executionLogs?.[0];
124062
124373
  const output = log?.output ?? "";
@@ -124279,11 +124590,7 @@ async function streamAgentRuntimeMessages(baseUrl, sessionId, onMessage, opts =
124279
124590
  await reconnectDelay(delayMs, opts.signal);
124280
124591
  continue;
124281
124592
  }
124282
- const reason = await readBody(
124283
- response.body,
124284
- onMessage,
124285
- opts
124286
- );
124593
+ const reason = await readBody(response.body, onMessage, opts);
124287
124594
  if (reason !== null) {
124288
124595
  await response.body.cancel().catch(() => {
124289
124596
  });
@@ -124346,11 +124653,11 @@ async function getAgentRuntimeState(baseUrl, sessionId, timeoutMs = 5e3) {
124346
124653
  function reconnectDelay(delayMs, signal) {
124347
124654
  return new Promise((resolve) => {
124348
124655
  if (signal?.aborted) return resolve();
124349
- const timer2 = setTimeout(resolve, delayMs);
124656
+ const timer3 = setTimeout(resolve, delayMs);
124350
124657
  signal?.addEventListener(
124351
124658
  "abort",
124352
124659
  () => {
124353
- clearTimeout(timer2);
124660
+ clearTimeout(timer3);
124354
124661
  resolve();
124355
124662
  },
124356
124663
  { once: true }
@@ -124358,6 +124665,50 @@ function reconnectDelay(delayMs, signal) {
124358
124665
  });
124359
124666
  }
124360
124667
 
124668
+ // src/repoburg/throwaway-run.ts
124669
+ async function runThrowawayPrompt(client, options) {
124670
+ let throwawayId = null;
124671
+ try {
124672
+ const created = await client.createSession(options.model ? { model_id: options.model } : {});
124673
+ throwawayId = created.id;
124674
+ const controller = new AbortController();
124675
+ const timer3 = setTimeout(() => controller.abort(), options.timeoutMs);
124676
+ try {
124677
+ await client.createInput(throwawayId, {
124678
+ user_prompt: options.prompt,
124679
+ execution_strategy: "auto_apply"
124680
+ });
124681
+ let reply = "";
124682
+ let failed = false;
124683
+ const consume = (message) => {
124684
+ if (message.type === "assistant") {
124685
+ reply += message.content.filter((b) => b.type === "text").map((b) => b.text).join("");
124686
+ } else if (message.type === "result") {
124687
+ if (message.is_error) failed = true;
124688
+ else if (message.result) reply = message.result;
124689
+ }
124690
+ };
124691
+ const reason = await streamAgentRuntimeMessages(client.baseUrl, throwawayId, consume, {
124692
+ signal: controller.signal,
124693
+ deltas: false
124694
+ });
124695
+ if (reason === "aborted") {
124696
+ void client.cancel(throwawayId).catch(() => {
124697
+ });
124698
+ return null;
124699
+ }
124700
+ return failed ? null : reply;
124701
+ } finally {
124702
+ clearTimeout(timer3);
124703
+ }
124704
+ } catch {
124705
+ return null;
124706
+ } finally {
124707
+ if (throwawayId) void client.deleteSession(throwawayId).catch(() => {
124708
+ });
124709
+ }
124710
+ }
124711
+
124361
124712
  // src/repoburg/turn-projector.ts
124362
124713
  var RESULT_TIMEOUT_MS = 15 * 6e4;
124363
124714
  var MAX_RESULT_EXTENSIONS = 3;
@@ -124392,8 +124743,8 @@ var TurnProjector = class {
124392
124743
  }
124393
124744
  switch (message.type) {
124394
124745
  case "system":
124746
+ if (message.subtype === "compact_boundary") this.handleCompactBoundary(message);
124395
124747
  break;
124396
- // init — connection marker only; gaps go to recoverGap
124397
124748
  case "stream_event":
124398
124749
  this.handleStreamEvent(message);
124399
124750
  break;
@@ -124510,10 +124861,7 @@ var TurnProjector = class {
124510
124861
  }
124511
124862
  if (ids.includes(inputId)) return;
124512
124863
  ids.push(inputId);
124513
- db2.prepare("UPDATE turns SET runtime_input_ids = ? WHERE id = ?").run(
124514
- JSON.stringify(ids),
124515
- this.deps.turnId
124516
- );
124864
+ db2.prepare("UPDATE turns SET runtime_input_ids = ? WHERE id = ?").run(JSON.stringify(ids), this.deps.turnId);
124517
124865
  } catch {
124518
124866
  }
124519
124867
  }
@@ -124588,7 +124936,14 @@ var TurnProjector = class {
124588
124936
  else info.reasoningItemId = existing.id;
124589
124937
  const data = existing.data ? JSON.parse(existing.data) : {};
124590
124938
  if (existing.status !== "completed" || data.text !== text2) {
124591
- completeItem(db2, this.deps.agentPaneSessionId, this.deps.turnId, { ...existing, data }, { text: text2 }, "completed");
124939
+ completeItem(
124940
+ db2,
124941
+ this.deps.agentPaneSessionId,
124942
+ this.deps.turnId,
124943
+ { ...existing, data },
124944
+ { text: text2 },
124945
+ "completed"
124946
+ );
124592
124947
  }
124593
124948
  return;
124594
124949
  }
@@ -124605,6 +124960,28 @@ var TurnProjector = class {
124605
124960
  if (kind === "message") info.messageItemId = item.id;
124606
124961
  else info.reasoningItemId = item.id;
124607
124962
  }
124963
+ /** The backend compacted the context: a "Context compacted" row (the
124964
+ * item Claude sessions show), and the context counter drops to the fill
124965
+ * after it. */
124966
+ handleCompactBoundary(msg) {
124967
+ const meta3 = msg.compact_metadata;
124968
+ const externalId = `compact-${msg.seq ?? Date.now()}`;
124969
+ if (this.existingItemId(externalId)) return;
124970
+ insertItem(
124971
+ getDb(),
124972
+ this.deps.agentPaneSessionId,
124973
+ this.deps.turnId,
124974
+ externalId,
124975
+ "context_compaction",
124976
+ { trigger: meta3.trigger, pre_tokens: meta3.pre_tokens, post_tokens: meta3.post_tokens },
124977
+ "completed",
124978
+ "item:completed"
124979
+ );
124980
+ if (meta3.post_tokens > 0) {
124981
+ this.lastContextTokens = meta3.post_tokens;
124982
+ this.emitContextUsage();
124983
+ }
124984
+ }
124608
124985
  existingItemId(externalId) {
124609
124986
  const row = getDb().prepare("SELECT id FROM items WHERE turn_id = ? AND external_item_id = ?").get(this.deps.turnId, externalId);
124610
124987
  return row?.id ?? null;
@@ -124724,9 +125101,13 @@ var TurnProjector = class {
124724
125101
  output: msg.usage.output_tokens
124725
125102
  }) : null;
124726
125103
  this.closeOpenItems("completed");
124727
- db2.prepare(
124728
- "UPDATE turns SET status = ?, agent_response = ?, token_usage = ?, updated_at = ? WHERE id = ?"
124729
- ).run("completed", responseText || null, usage ? JSON.stringify(usage) : null, now, this.deps.turnId);
125104
+ db2.prepare("UPDATE turns SET status = ?, agent_response = ?, token_usage = ?, updated_at = ? WHERE id = ?").run(
125105
+ "completed",
125106
+ responseText || null,
125107
+ usage ? JSON.stringify(usage) : null,
125108
+ now,
125109
+ this.deps.turnId
125110
+ );
124730
125111
  recomputeSessionRunning(db2, this.deps.agentPaneSessionId, "active", true);
124731
125112
  broadcast("turn:completed", {
124732
125113
  sessionId: this.deps.agentPaneSessionId,
@@ -124770,9 +125151,7 @@ var TurnProjector = class {
124770
125151
  async syncTitle() {
124771
125152
  try {
124772
125153
  const db2 = getDb();
124773
- const session = db2.prepare("SELECT title FROM sessions WHERE id = ?").get(
124774
- this.deps.agentPaneSessionId
124775
- );
125154
+ const session = db2.prepare("SELECT title FROM sessions WHERE id = ?").get(this.deps.agentPaneSessionId);
124776
125155
  if (!session || session.title) return;
124777
125156
  const runtimeSession = await this.deps.client.getSession(this.deps.repoburgSessionId);
124778
125157
  const title = (runtimeSession.session_title || "").trim();
@@ -124803,54 +125182,19 @@ var TurnProjector = class {
124803
125182
  const sessionId = this.deps.agentPaneSessionId;
124804
125183
  if (titleGenerating3.has(sessionId)) return;
124805
125184
  const db2 = getDb();
124806
- const firstTurn = db2.prepare(
124807
- "SELECT user_prompt, agent_response FROM turns WHERE session_id = ? ORDER BY created_at ASC LIMIT 1"
124808
- ).get(sessionId);
125185
+ const firstTurn = db2.prepare("SELECT user_prompt, agent_response FROM turns WHERE session_id = ? ORDER BY created_at ASC LIMIT 1").get(sessionId);
124809
125186
  if (!firstTurn) return;
124810
125187
  titleGenerating3.add(sessionId);
124811
- let throwawayId = null;
124812
125188
  try {
124813
125189
  const pane = db2.prepare("SELECT model FROM sessions WHERE id = ?").get(sessionId);
124814
- const created = await this.deps.client.createSession(
124815
- pane?.model ? { model_id: pane.model } : {}
124816
- );
124817
- throwawayId = created.id;
124818
- const controller = new AbortController();
124819
- const timer2 = setTimeout(() => controller.abort(), TITLE_TIMEOUT_MS);
124820
- try {
124821
- await this.deps.client.createInput(throwawayId, {
124822
- user_prompt: buildTitlePrompt(firstTurn.user_prompt, firstTurn.agent_response),
124823
- execution_strategy: "auto_apply"
124824
- });
124825
- let reply = "";
124826
- const consume = (message) => {
124827
- if (message.type === "assistant") {
124828
- reply += message.content.filter((b) => b.type === "text").map((b) => b.text).join("");
124829
- } else if (message.type === "result" && !message.is_error && message.result) {
124830
- reply = message.result;
124831
- }
124832
- };
124833
- const reason = await streamAgentRuntimeMessages(
124834
- this.deps.client.baseUrl,
124835
- throwawayId,
124836
- consume,
124837
- { signal: controller.signal, deltas: false }
124838
- );
124839
- if (reason === "aborted") {
124840
- void this.deps.client.cancel(throwawayId).catch(() => {
124841
- });
124842
- }
124843
- const title = cleanTitle(reply);
124844
- if (title) this.applyTitle(title);
124845
- } finally {
124846
- clearTimeout(timer2);
124847
- }
124848
- } catch {
125190
+ const reply = await runThrowawayPrompt(this.deps.client, {
125191
+ model: pane?.model,
125192
+ prompt: buildTitlePrompt(firstTurn.user_prompt, firstTurn.agent_response),
125193
+ timeoutMs: TITLE_TIMEOUT_MS
125194
+ });
125195
+ const title = cleanTitle(reply ?? "");
125196
+ if (title) this.applyTitle(title);
124849
125197
  } finally {
124850
- if (throwawayId) {
124851
- void this.deps.client.deleteSession(throwawayId).catch(() => {
124852
- });
124853
- }
124854
125198
  titleGenerating3.delete(sessionId);
124855
125199
  }
124856
125200
  }
@@ -124876,11 +125220,7 @@ var TurnProjector = class {
124876
125220
  const db2 = getDb();
124877
125221
  const now = (/* @__PURE__ */ new Date()).toISOString();
124878
125222
  this.closeOpenItems("completed");
124879
- db2.prepare("UPDATE turns SET status = ?, updated_at = ? WHERE id = ?").run(
124880
- "aborted",
124881
- now,
124882
- this.deps.turnId
124883
- );
125223
+ db2.prepare("UPDATE turns SET status = ?, updated_at = ? WHERE id = ?").run("aborted", now, this.deps.turnId);
124884
125224
  recomputeSessionRunning(db2, this.deps.agentPaneSessionId);
124885
125225
  broadcast("turn:cancelled", {
124886
125226
  sessionId: this.deps.agentPaneSessionId,
@@ -124947,9 +125287,13 @@ var TurnProjector = class {
124947
125287
  const db2 = getDb();
124948
125288
  const now = (/* @__PURE__ */ new Date()).toISOString();
124949
125289
  this.closeOpenItems("completed");
124950
- db2.prepare(
124951
- "UPDATE turns SET status = ?, agent_response = ?, token_usage = ?, updated_at = ? WHERE id = ?"
124952
- ).run("completed", responseText || null, usage ? JSON.stringify(usage) : null, now, this.deps.turnId);
125290
+ db2.prepare("UPDATE turns SET status = ?, agent_response = ?, token_usage = ?, updated_at = ? WHERE id = ?").run(
125291
+ "completed",
125292
+ responseText || null,
125293
+ usage ? JSON.stringify(usage) : null,
125294
+ now,
125295
+ this.deps.turnId
125296
+ );
124953
125297
  recomputeSessionRunning(db2, this.deps.agentPaneSessionId, "active", true);
124954
125298
  broadcast("turn:completed", {
124955
125299
  sessionId: this.deps.agentPaneSessionId,
@@ -125018,9 +125362,7 @@ var TurnProjector = class {
125018
125362
  }
125019
125363
  };
125020
125364
  function extractFinalPlain(input) {
125021
- const action = input?.aiActions?.find(
125022
- (a) => a.action_type === "final" || a.action_type === "html_final"
125023
- );
125365
+ const action = input?.aiActions?.find((a) => a.action_type === "final" || a.action_type === "html_final");
125024
125366
  return action?.plain ?? null;
125025
125367
  }
125026
125368
  function buildTitlePrompt(userPrompt, agentResponse) {
@@ -125066,9 +125408,7 @@ var BACKEND_RESTARTED_ERROR = "The Repoburg backend restarted while this turn ra
125066
125408
  var BACKEND_UNREACHABLE_ERROR = `The Repoburg backend was unreachable for ${BACKEND_LOST_MS / 1e3} s while this turn ran, so the turn was lost. Send the prompt again.`;
125067
125409
  function isConnectionError(err) {
125068
125410
  const message = String(err?.message ?? "");
125069
- return /fetch failed|ECONNREFUSED|ENOTFOUND|ECONNRESET|ETIMEDOUT|EHOSTUNREACH|socket hang up/i.test(
125070
- message
125071
- );
125411
+ return /fetch failed|ECONNREFUSED|ENOTFOUND|ECONNRESET|ETIMEDOUT|EHOSTUNREACH|socket hang up/i.test(message);
125072
125412
  }
125073
125413
  async function ensureSession(session, client, baseUrl) {
125074
125414
  const existing = sessionMap3.get(session.id);
@@ -125178,12 +125518,7 @@ async function ensureContextWindow(entry) {
125178
125518
  }
125179
125519
  function failTurnBeforeStart(db2, sessionId, turnId, error51) {
125180
125520
  const now = (/* @__PURE__ */ new Date()).toISOString();
125181
- db2.prepare("UPDATE turns SET status = ?, error = ?, updated_at = ? WHERE id = ?").run(
125182
- "failed",
125183
- error51,
125184
- now,
125185
- turnId
125186
- );
125521
+ db2.prepare("UPDATE turns SET status = ?, error = ?, updated_at = ? WHERE id = ?").run("failed", error51, now, turnId);
125187
125522
  recomputeSessionRunning(db2, sessionId, "failed");
125188
125523
  broadcast("turn:failed", { sessionId, turnId, error: error51 });
125189
125524
  }
@@ -125238,7 +125573,7 @@ async function runStreamLoop(entry, projector) {
125238
125573
  });
125239
125574
  return;
125240
125575
  }
125241
- if (message.type === "system") {
125576
+ if (message.type === "system" && message.subtype === "init") {
125242
125577
  clearLostTimer();
125243
125578
  const bootId = message.bootId ?? null;
125244
125579
  if (active.bootId === void 0) active.bootId = bootId;
@@ -125600,6 +125935,21 @@ async function forkSession2(session, targetTurn) {
125600
125935
  const forked = await client.forkSession(session.external_thread_id, anchor);
125601
125936
  return forked.id;
125602
125937
  }
125938
+ var THREAD_SUMMARY_TIMEOUT_MS = 12e4;
125939
+ async function summarizeThread(session, _thread, transcript, directives) {
125940
+ try {
125941
+ const client = await resolveClient(session);
125942
+ const reply = await runThrowawayPrompt(client, {
125943
+ model: session.model,
125944
+ prompt: buildThreadSummaryPrompt(transcript, directives),
125945
+ timeoutMs: THREAD_SUMMARY_TIMEOUT_MS
125946
+ });
125947
+ return reply?.trim() || null;
125948
+ } catch (err) {
125949
+ console.error("[repoburg] summarizeThread failed:", err);
125950
+ return null;
125951
+ }
125952
+ }
125603
125953
  function clearAllThreads3() {
125604
125954
  for (const entry of sessionMap3.values()) {
125605
125955
  if (entry.activeTurn) {
@@ -125712,6 +126062,7 @@ var repoburgProvider = {
125712
126062
  getCommands: getCommands3,
125713
126063
  rewindRuntime,
125714
126064
  forkSession: forkSession2,
126065
+ summarizeThread,
125715
126066
  shutdown: shutdown3
125716
126067
  };
125717
126068