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,
@@ -44111,14 +44124,14 @@ var AppServerClient = class {
44111
44124
  }
44112
44125
  const id = this.nextId++;
44113
44126
  const message = JSON.stringify({ id, method, params }) + "\n";
44114
- const timer2 = setTimeout(() => {
44127
+ const timer3 = setTimeout(() => {
44115
44128
  this.pending.delete(id);
44116
44129
  reject(new Error(`Request '${method}' (id=${id}) timed out after ${REQUEST_TIMEOUT_MS}ms`));
44117
44130
  }, REQUEST_TIMEOUT_MS);
44118
44131
  this.pending.set(id, {
44119
44132
  resolve,
44120
44133
  reject,
44121
- timer: timer2
44134
+ timer: timer3
44122
44135
  });
44123
44136
  this.write(message);
44124
44137
  });
@@ -44193,14 +44206,14 @@ var AppServerClient = class {
44193
44206
  if (this.gone) return Promise.resolve(true);
44194
44207
  return new Promise((resolve) => {
44195
44208
  const onExit = () => {
44196
- clearTimeout(timer2);
44209
+ clearTimeout(timer3);
44197
44210
  resolve(true);
44198
44211
  };
44199
- const timer2 = setTimeout(() => {
44212
+ const timer3 = setTimeout(() => {
44200
44213
  this.proc.removeListener("exit", onExit);
44201
44214
  resolve(false);
44202
44215
  }, ms);
44203
- timer2.unref?.();
44216
+ timer3.unref?.();
44204
44217
  this.proc.once("exit", onExit);
44205
44218
  });
44206
44219
  }
@@ -44925,14 +44938,14 @@ var VscodeWebManager = class {
44925
44938
  waitForReady(inst) {
44926
44939
  const deadline = this.deps.now() + STARTUP_TIMEOUT_MS;
44927
44940
  return new Promise((resolve) => {
44928
- const timer2 = setInterval(async () => {
44941
+ const timer3 = setInterval(async () => {
44929
44942
  if (inst.state !== "starting") {
44930
- clearInterval(timer2);
44943
+ clearInterval(timer3);
44931
44944
  resolve();
44932
44945
  return;
44933
44946
  }
44934
44947
  if (this.deps.now() > deadline) {
44935
- clearInterval(timer2);
44948
+ clearInterval(timer3);
44936
44949
  inst.state = "error";
44937
44950
  inst.error = `serve-web did not become ready within ${STARTUP_TIMEOUT_MS / 1e3}s`;
44938
44951
  inst.stopping = true;
@@ -44944,7 +44957,7 @@ var VscodeWebManager = class {
44944
44957
  }
44945
44958
  try {
44946
44959
  await this.deps.probe(inst.port, inst.token, inst.id);
44947
- clearInterval(timer2);
44960
+ clearInterval(timer3);
44948
44961
  if (inst.state === "starting") {
44949
44962
  inst.state = "running";
44950
44963
  this.markAccessed(inst.id);
@@ -99430,7 +99443,8 @@ Each subdirectory of this folder is one mini app:
99430
99443
  <app-id>/
99431
99444
  manifest.json - { "title": string, "description"?: string, "icon"?: string,
99432
99445
  "tools"?: [{ "name", "description", "inputSchema" }],
99433
- "headlessSessions"?: boolean }
99446
+ "headlessSessions"?: boolean,
99447
+ "sessionActivity"?: boolean }
99434
99448
  "icon" is the app logo: a Lucide icon name (see
99435
99449
  "Icons and logos" below)
99436
99450
  index.html - markup only (full HTML document); do NOT reference app.js
@@ -99626,6 +99640,46 @@ runtime and events go to the open tab only.
99626
99640
  - events are not replayed. Keep the session ids in the state, and when the
99627
99641
  runtime loads ask getSession(id) what happened while the pane was down
99628
99642
 
99643
+ ## Other sessions' turns (manifest "sessionActivity")
99644
+
99645
+ Set "sessionActivity": true in manifest.json to hear when a turn starts or
99646
+ ends in a session the app did NOT open (the user's sessions, other apps'):
99647
+
99648
+ AgentPane.onSessionActivity(({ event, sessionId, turnId, origin, originName, cancelled }) => ...)
99649
+
99650
+ - event is 'turn:started', 'turn:completed' or 'turn:failed' (cancelled: true
99651
+ when the user stopped it); turns of discussion threads are left out
99652
+ - origin is 'peer' when a message from another Claude session (SendMessage)
99653
+ started the turn, with originName the sender's name; null otherwise
99654
+ - turn:started can come again for the same turnId (a background task's
99655
+ follow-up reopens the turn): dedupe by turnId
99656
+ - read the session with getSessionInfo(sessionId) (cwd, runtime_type,
99657
+ transcript_path); the prompt itself is in the transcript
99658
+ - fires in the headless runtime only, with or without a tab: in the global
99659
+ instance, and in every workspace instance that has state and sees the
99660
+ session. Register the listener synchronously at startup
99661
+ - the app's own sessions are not reported here: they have onTurnCompleted
99662
+
99663
+ ## Alarms
99664
+
99665
+ The headless runtime's setTimeout dies with it (pane restart, hot reload).
99666
+ For a wake-up that must happen, use an alarm; the pane keeps it in its
99667
+ database and fires it into the instance that set it, loading it if needed:
99668
+
99669
+ await AgentPane.setAlarm('checkin:' + id, 15 * 60_000, { id }); // { name, fireAt, data }
99670
+ AgentPane.onAlarm(({ name, data, fireAt }) => ...);
99671
+ await AgentPane.clearAlarm(name); // { cleared }
99672
+ await AgentPane.listAlarms(); // soonest first
99673
+
99674
+ - headless only: in the tab these reject (use callTool to reach the headless
99675
+ runtime) and onAlarm never fires there
99676
+ - names are per instance; setting a name again moves that alarm. An alarm
99677
+ fires once, then it is gone. delayMs is at most 30 days, data at most 64 KB
99678
+ of JSON, at most 200 alarms per instance
99679
+ - an alarm that came due while the pane was down fires right after startup;
99680
+ check the state before acting on it
99681
+ - register onAlarm synchronously at startup. Deleting the app drops its alarms
99682
+
99629
99683
  ## Result contract
99630
99684
 
99631
99685
  To give the app a structured result, put this requirement in the job prompt:
@@ -99646,12 +99700,20 @@ function readManifestIn(dir) {
99646
99700
  description: typeof parsed.description === "string" ? parsed.description : void 0,
99647
99701
  icon: typeof parsed.icon === "string" ? parsed.icon : void 0,
99648
99702
  tools: Array.isArray(parsed.tools) ? parsed.tools.filter((t) => t && typeof t.name === "string" && typeof t.description === "string") : void 0,
99649
- headlessSessions: parsed.headlessSessions === true ? true : void 0
99703
+ headlessSessions: parsed.headlessSessions === true ? true : void 0,
99704
+ sessionActivity: parsed.sessionActivity === true ? true : void 0
99650
99705
  };
99651
99706
  } catch {
99652
99707
  return null;
99653
99708
  }
99654
99709
  }
99710
+ function listAppIds() {
99711
+ try {
99712
+ return fs2.readdirSync(appsRoot(), { withFileTypes: true }).filter((entry) => entry.isDirectory() && APP_ID_RE.test(entry.name)).map((entry) => entry.name);
99713
+ } catch {
99714
+ return [];
99715
+ }
99716
+ }
99655
99717
  function readManifest(id) {
99656
99718
  return readManifestIn(appDir(id));
99657
99719
  }
@@ -99695,8 +99757,8 @@ function startAppsWatch(onAppChange) {
99695
99757
  const file2 = segs[segs.length - 1];
99696
99758
  if (!appId || appId === path5.basename(root) || !APP_ID_RE.test(appId) || file2 === "state.json") return;
99697
99759
  if (segs.length === 1 && isRegularFile(path5.join(root, appId))) return;
99698
- const timer2 = pendingChanges.get(appId);
99699
- if (timer2) clearTimeout(timer2);
99760
+ const timer3 = pendingChanges.get(appId);
99761
+ if (timer3) clearTimeout(timer3);
99700
99762
  pendingChanges.set(
99701
99763
  appId,
99702
99764
  setTimeout(() => {
@@ -99714,7 +99776,7 @@ function stopAppsWatch() {
99714
99776
  watcher.close();
99715
99777
  watcher = null;
99716
99778
  }
99717
- for (const timer2 of pendingChanges.values()) clearTimeout(timer2);
99779
+ for (const timer3 of pendingChanges.values()) clearTimeout(timer3);
99718
99780
  pendingChanges.clear();
99719
99781
  }
99720
99782
 
@@ -100231,6 +100293,13 @@ function appSessionSummary(appId, workspace, sessionId) {
100231
100293
  if (!session || !sessionVisibleTo(session, appId, workspace)) return null;
100232
100294
  return sessionSummary(session, appId);
100233
100295
  }
100296
+ function activityInstances(appId, sessionId) {
100297
+ const db2 = getDb();
100298
+ const session = db2.prepare("SELECT * FROM sessions WHERE id = ?").get(sessionId);
100299
+ if (!session || openedByApp(session, appId)) return [];
100300
+ const rows = db2.prepare("SELECT workspace_path FROM app_instances WHERE app_id = ? AND workspace_path != '' ORDER BY workspace_path").all(appId);
100301
+ return ["", ...rows.map((r) => r.workspace_path).filter((w) => sessionVisibleTo(session, appId, w))];
100302
+ }
100234
100303
  function ownSession(appId, sessionId, api) {
100235
100304
  const session = getDb().prepare("SELECT * FROM sessions WHERE id = ?").get(String(sessionId));
100236
100305
  if (!session || !openedByApp(session, appId)) {
@@ -100273,6 +100342,124 @@ function toolCaller(appId, sessionId) {
100273
100342
  // src/apps/headless-runtime.ts
100274
100343
  import vm2 from "node:vm";
100275
100344
 
100345
+ // src/apps/app-alarms.ts
100346
+ var MAX_ALARM_DELAY_MS = 30 * 24 * 60 * 60 * 1e3;
100347
+ var MAX_ALARMS_PER_INSTANCE = 200;
100348
+ var MAX_NAME_LENGTH = 200;
100349
+ var MAX_DATA_BYTES = 64 * 1024;
100350
+ var MAX_TIMER_WAIT_MS = 60 * 60 * 1e3;
100351
+ function parseData(raw) {
100352
+ if (raw == null) return null;
100353
+ try {
100354
+ return JSON.parse(raw);
100355
+ } catch {
100356
+ return null;
100357
+ }
100358
+ }
100359
+ function toAlarm(row) {
100360
+ return { name: row.name, fireAt: row.fire_at, data: parseData(row.data) };
100361
+ }
100362
+ function setAppAlarm(appId, workspace, name, delayMs, data) {
100363
+ if (typeof name !== "string" || !name.trim() || name.length > MAX_NAME_LENGTH) {
100364
+ throw new Error(`setAlarm: name must be a non-empty string of at most ${MAX_NAME_LENGTH} characters`);
100365
+ }
100366
+ if (typeof delayMs !== "number" || !Number.isFinite(delayMs) || delayMs < 0) {
100367
+ throw new Error("setAlarm: delayMs must be a number of milliseconds, 0 or more");
100368
+ }
100369
+ if (delayMs > MAX_ALARM_DELAY_MS) {
100370
+ throw new Error(`setAlarm: delayMs is at most ${MAX_ALARM_DELAY_MS} (30 days)`);
100371
+ }
100372
+ let json2 = null;
100373
+ if (data !== void 0) {
100374
+ try {
100375
+ json2 = JSON.stringify(data) ?? null;
100376
+ } catch {
100377
+ throw new Error("setAlarm: data must be JSON");
100378
+ }
100379
+ if (json2 && Buffer.byteLength(json2) > MAX_DATA_BYTES) {
100380
+ throw new Error(`setAlarm: data is at most ${MAX_DATA_BYTES} bytes of JSON`);
100381
+ }
100382
+ }
100383
+ const db2 = getDb();
100384
+ const exists2 = db2.prepare("SELECT 1 FROM app_alarms WHERE app_id = ? AND workspace_path = ? AND name = ?").get(appId, workspace, name);
100385
+ if (!exists2) {
100386
+ const { n } = db2.prepare("SELECT COUNT(*) AS n FROM app_alarms WHERE app_id = ? AND workspace_path = ?").get(appId, workspace);
100387
+ if (n >= MAX_ALARMS_PER_INSTANCE) {
100388
+ throw new Error(`setAlarm: an instance holds at most ${MAX_ALARMS_PER_INSTANCE} alarms; clear one first`);
100389
+ }
100390
+ }
100391
+ const fireAt = Date.now() + Math.round(delayMs);
100392
+ db2.prepare(
100393
+ `INSERT INTO app_alarms (app_id, workspace_path, name, fire_at, data, created_at)
100394
+ VALUES (?, ?, ?, ?, ?, ?)
100395
+ ON CONFLICT(app_id, workspace_path, name) DO UPDATE SET
100396
+ fire_at = excluded.fire_at, data = excluded.data, created_at = excluded.created_at`
100397
+ ).run(appId, workspace, name, fireAt, json2, (/* @__PURE__ */ new Date()).toISOString());
100398
+ schedule();
100399
+ return { name, fireAt, data: parseData(json2) };
100400
+ }
100401
+ function clearAppAlarm(appId, workspace, name) {
100402
+ if (typeof name !== "string") throw new Error("clearAlarm: name must be a string");
100403
+ const { changes } = getDb().prepare("DELETE FROM app_alarms WHERE app_id = ? AND workspace_path = ? AND name = ?").run(appId, workspace, name);
100404
+ schedule();
100405
+ return { cleared: changes > 0 };
100406
+ }
100407
+ function listAppAlarms(appId, workspace) {
100408
+ const rows = getDb().prepare("SELECT * FROM app_alarms WHERE app_id = ? AND workspace_path = ? ORDER BY fire_at, name").all(appId, workspace);
100409
+ return rows.map(toAlarm);
100410
+ }
100411
+ function deleteAppAlarms(appId) {
100412
+ getDb().prepare("DELETE FROM app_alarms WHERE app_id = ?").run(appId);
100413
+ schedule();
100414
+ }
100415
+ var deliver = null;
100416
+ var timer2 = null;
100417
+ function fireDueAlarms(now = Date.now()) {
100418
+ const db2 = getDb();
100419
+ const due = db2.transaction(() => {
100420
+ const rows = db2.prepare("SELECT * FROM app_alarms WHERE fire_at <= ? ORDER BY fire_at, name").all(now);
100421
+ const drop = db2.prepare("DELETE FROM app_alarms WHERE app_id = ? AND workspace_path = ? AND name = ?");
100422
+ for (const row of rows) drop.run(row.app_id, row.workspace_path, row.name);
100423
+ return rows;
100424
+ }).immediate().map((row) => ({ appId: row.app_id, workspace: row.workspace_path, ...toAlarm(row) }));
100425
+ for (const alarm of due) {
100426
+ try {
100427
+ deliver?.(alarm);
100428
+ } catch (err) {
100429
+ console.error(`[alarms] ${alarm.appId} alarm ${alarm.name} failed:`, err);
100430
+ }
100431
+ }
100432
+ return due;
100433
+ }
100434
+ function schedule() {
100435
+ if (!deliver) return;
100436
+ if (timer2) clearTimeout(timer2);
100437
+ timer2 = null;
100438
+ const next = getDb().prepare("SELECT MIN(fire_at) AS at FROM app_alarms").get();
100439
+ if (next.at == null) return;
100440
+ const wait = Math.min(Math.max(next.at - Date.now(), 0), MAX_TIMER_WAIT_MS);
100441
+ timer2 = setTimeout(() => {
100442
+ timer2 = null;
100443
+ try {
100444
+ fireDueAlarms();
100445
+ } catch (err) {
100446
+ console.error("[alarms] firing failed:", err);
100447
+ }
100448
+ schedule();
100449
+ }, wait);
100450
+ timer2.unref?.();
100451
+ }
100452
+ function startAppAlarms(onDue) {
100453
+ stopAppAlarms();
100454
+ deliver = onDue;
100455
+ schedule();
100456
+ }
100457
+ function stopAppAlarms() {
100458
+ if (timer2) clearTimeout(timer2);
100459
+ timer2 = null;
100460
+ deliver = null;
100461
+ }
100462
+
100276
100463
  // src/apps/app-compile.ts
100277
100464
  import vm from "node:vm";
100278
100465
  import path9 from "node:path";
@@ -100481,6 +100668,23 @@ interface AgentPaneFileData { name?: string; type?: string; data: string }
100481
100668
  type AgentPaneFileRef = string | { id?: string; url?: string };
100482
100669
  /** A submitTurn attachment: a stored file, or inline bytes sent with that turn only. */
100483
100670
  type AgentPaneAttachment = AgentPaneFileRef | Blob | AgentPaneFileData;
100671
+ /** onSessionActivity: a turn started or ended in a session this app did not
100672
+ * open. Read the session with getSessionInfo (cwd, runtime_type,
100673
+ * transcript_path). */
100674
+ interface AgentPaneSessionActivity {
100675
+ event: 'turn:started' | 'turn:completed' | 'turn:failed';
100676
+ sessionId: string;
100677
+ turnId: string;
100678
+ /** 'peer': a message from another Claude session (SendMessage) started the
100679
+ * turn; null: the user, or an app. */
100680
+ origin: 'peer' | null;
100681
+ /** The sending session's name for a peer turn, else null. */
100682
+ originName: string | null;
100683
+ /** turn:failed of a turn the user stopped. */
100684
+ cancelled?: boolean;
100685
+ }
100686
+ /** An alarm of this instance (setAlarm). fireAt is epoch ms. */
100687
+ interface AgentPaneAlarm { name: string; fireAt: number; data: unknown }
100484
100688
  interface AgentPaneSubmitTurnOptions {
100485
100689
  /** Files the agent receives with the prompt (images are shown to the model). */
100486
100690
  attachments?: AgentPaneAttachment[];
@@ -100532,6 +100736,21 @@ declare const AgentPane: {
100532
100736
  /** Fires when the live background-task set of one of the app's sessions
100533
100737
  * changes (also empty sets, when the last task ends). */
100534
100738
  onBackgroundTasks(cb: (payload: AgentPaneBackgroundTasksPayload | null) => void): void;
100739
+ /** Headless only, with "sessionActivity": true in the manifest: a turn
100740
+ * started or ended in a session this app did not open (the user's), in
100741
+ * this instance's sight. turn:started can come again for the same turnId
100742
+ * when a background task's follow-up reopens the turn. */
100743
+ onSessionActivity(cb: (payload: AgentPaneSessionActivity) => void): void;
100744
+ /** Headless only: wake this instance in delayMs (at most 30 days), also
100745
+ * after a pane restart. Setting a name again moves that alarm. data (JSON)
100746
+ * comes back with it. Rejects in the tab. */
100747
+ setAlarm(name: string, delayMs: number, data?: unknown): Promise<AgentPaneAlarm>;
100748
+ /** Headless only: drop an alarm; cleared is false when none had the name. */
100749
+ clearAlarm(name: string): Promise<{ cleared: boolean }>;
100750
+ /** Headless only: this instance's alarms, soonest first. */
100751
+ listAlarms(): Promise<AgentPaneAlarm[]>;
100752
+ /** Headless only: an alarm of this instance came due. It fires once. */
100753
+ onAlarm(cb: (alarm: AgentPaneAlarm) => void): void;
100535
100754
  resolveToolCall(callId: string, result?: unknown): Promise<{ ok: boolean }>;
100536
100755
  /** Show a session in the pane (switches the view to its conversation).
100537
100756
  * Only works while the app is on screen: call it from a click handler. */
@@ -100825,7 +101044,13 @@ function loadRuntime(appId, workspace) {
100825
101044
  if (headlessSessions) return;
100826
101045
  throw new Error(`${api} is not available in the headless runtime without "headlessSessions": true in manifest.json`);
100827
101046
  };
100828
- const entry = { handler: null, turnListeners: [], taskListeners: [] };
101047
+ const entry = {
101048
+ handler: null,
101049
+ turnListeners: [],
101050
+ taskListeners: [],
101051
+ activityListeners: [],
101052
+ alarmListeners: []
101053
+ };
100829
101054
  const bridge = {
100830
101055
  getApp: () => answer(() => ({ id: appId, title: manifest?.title ?? appId, workspace })),
100831
101056
  // State is scoped to the calling session's workspace instance; '' = global
@@ -100901,9 +101126,23 @@ function loadRuntime(appId, workspace) {
100901
101126
  onBackgroundTasks: (cb) => {
100902
101127
  if (typeof cb === "function") entry.taskListeners.push(cb);
100903
101128
  },
100904
- // Live streaming is for a screen; nothing here renders.
101129
+ // Heard only with "sessionActivity" in the manifest (deliverSessionActivity).
101130
+ onSessionActivity: (cb) => {
101131
+ if (typeof cb === "function") entry.activityListeners.push(cb);
101132
+ },
101133
+ setAlarm: (name, delayMs, data) => answer(() => setAppAlarm(appId, workspace, name, delayMs, data)),
101134
+ clearAlarm: (name) => answer(() => clearAppAlarm(appId, workspace, name)),
101135
+ listAlarms: () => answer(() => listAppAlarms(appId, workspace)),
101136
+ onAlarm: (cb) => {
101137
+ if (typeof cb === "function") entry.alarmListeners.push(cb);
101138
+ },
101139
+ // Live streaming is for a screen; nothing here renders. The same goes for
101140
+ // state changes: the tab re-renders on them, and an app.ts shared by tab
101141
+ // and runtime registers that at startup — which must not fail the load.
100905
101142
  onTurnDelta: () => {
100906
101143
  },
101144
+ onStateChanged: () => {
101145
+ },
100907
101146
  // UI actions are intentionally unavailable headless.
100908
101147
  openSession: () => answer(() => {
100909
101148
  throw new Error("openSession is not available in the headless runtime");
@@ -100932,7 +101171,8 @@ function loadRuntime(appId, workspace) {
100932
101171
  console.warn(`[headless:${appId}] app.js load failed: ${err.message}`);
100933
101172
  return null;
100934
101173
  }
100935
- if (!entry.handler && !entry.turnListeners.length && !entry.taskListeners.length) return null;
101174
+ const listens = entry.turnListeners.length || entry.taskListeners.length || entry.activityListeners.length || entry.alarmListeners.length;
101175
+ if (!entry.handler && !listens) return null;
100936
101176
  runtimes.set(key, entry);
100937
101177
  return entry;
100938
101178
  }
@@ -100942,7 +101182,7 @@ function getHeadlessToolHandler(appId, workspace = "") {
100942
101182
  function dispatchHeadlessToolCall(handler, tool2, args, caller = null) {
100943
101183
  const callId = v4_default();
100944
101184
  const result = new Promise((resolve, reject) => {
100945
- const timer2 = setTimeout(() => {
101185
+ const timer3 = setTimeout(() => {
100946
101186
  pendingCalls.delete(callId);
100947
101187
  reject(
100948
101188
  new Error(
@@ -100950,7 +101190,7 @@ function dispatchHeadlessToolCall(handler, tool2, args, caller = null) {
100950
101190
  )
100951
101191
  );
100952
101192
  }, HEADLESS_TOOL_TIMEOUT_MS);
100953
- pendingCalls.set(callId, { resolve, reject, timer: timer2 });
101193
+ pendingCalls.set(callId, { resolve, reject, timer: timer3 });
100954
101194
  });
100955
101195
  const crashed = (err) => {
100956
101196
  const pending = pendingCalls.get(callId);
@@ -101002,6 +101242,49 @@ function deliverSessionEvent(event, data) {
101002
101242
  for (const listener of runtime.turnListeners) runAppCode(appId, () => listener(name, payload));
101003
101243
  }
101004
101244
  var SESSION_EVENTS = /* @__PURE__ */ new Set(["turn:completed", "turn:failed", "turn:cancelled", "background_tasks"]);
101245
+ var ACTIVITY_EVENTS = /* @__PURE__ */ new Set(["turn:started", "turn:completed", "turn:failed", "turn:cancelled"]);
101246
+ var activityApps = null;
101247
+ function sessionActivityApps() {
101248
+ activityApps ??= listAppIds().filter((id) => readManifest(id)?.sessionActivity === true);
101249
+ return activityApps;
101250
+ }
101251
+ function activityPayload(event, data) {
101252
+ const sessionId = String(data.sessionId);
101253
+ const turnId = String(data.turnId);
101254
+ const turn = getTurnOrigin(turnId);
101255
+ if (!turn || turn.thread_id || turn.session_id !== sessionId) return null;
101256
+ const peer = turn.origin === "peer";
101257
+ const base = { sessionId, turnId, origin: peer ? "peer" : null, originName: peer ? turn.origin_name : null };
101258
+ if (event === "turn:started") return { event, ...base };
101259
+ const [name, payload] = turnEvent(event, data);
101260
+ return { event: name, ...base, ...payload.cancelled ? { cancelled: true } : {} };
101261
+ }
101262
+ function getTurnOrigin(turnId) {
101263
+ const row = getDb().prepare("SELECT session_id, thread_id, origin, origin_name FROM turns WHERE id = ?").get(turnId);
101264
+ return row ?? null;
101265
+ }
101266
+ function deliverSessionActivity(event, data) {
101267
+ const apps = sessionActivityApps();
101268
+ if (!apps.length) return;
101269
+ const payload = activityPayload(event, data);
101270
+ if (!payload) return;
101271
+ for (const appId of apps) {
101272
+ for (const workspace of activityInstances(appId, String(payload.sessionId))) {
101273
+ const runtime = loadRuntime(appId, workspace);
101274
+ if (!runtime) continue;
101275
+ for (const listener of runtime.activityListeners) runAppCode(appId, () => listener({ ...payload }));
101276
+ }
101277
+ }
101278
+ }
101279
+ function deliverAlarm(alarm) {
101280
+ const runtime = loadRuntime(alarm.appId, alarm.workspace);
101281
+ if (!runtime?.alarmListeners.length) {
101282
+ console.warn(`[headless:${alarm.appId}] alarm ${alarm.name} dropped: the app has no onAlarm listener headless`);
101283
+ return;
101284
+ }
101285
+ const payload = { name: alarm.name, data: alarm.data, fireAt: alarm.fireAt };
101286
+ for (const listener of runtime.alarmListeners) runAppCode(alarm.appId, () => listener({ ...payload }));
101287
+ }
101005
101288
  function handleUnhandledRejection(reason, promise2) {
101006
101289
  if (promise2 instanceof Promise) throw reason;
101007
101290
  console.error("[headless] unhandled rejection in app code:", reason);
@@ -101010,18 +101293,28 @@ var stopSessionEvents = null;
101010
101293
  function startHeadlessEvents() {
101011
101294
  stopHeadlessEvents();
101012
101295
  const untap2 = tapBroadcast((event, data) => {
101013
- if (!SESSION_EVENTS.has(event)) return;
101296
+ const session = SESSION_EVENTS.has(event);
101297
+ const activity = ACTIVITY_EVENTS.has(event);
101298
+ if (!session && !activity) return;
101014
101299
  setImmediate(() => {
101015
- try {
101016
- deliverSessionEvent(event, data);
101017
- } catch (err) {
101018
- console.error(`[headless] ${event} delivery failed:`, err);
101300
+ for (const [wanted, deliver2] of [
101301
+ [session, deliverSessionEvent],
101302
+ [activity, deliverSessionActivity]
101303
+ ]) {
101304
+ if (!wanted) continue;
101305
+ try {
101306
+ deliver2(event, data);
101307
+ } catch (err) {
101308
+ console.error(`[headless] ${event} delivery failed:`, err);
101309
+ }
101019
101310
  }
101020
101311
  });
101021
101312
  });
101022
101313
  process.on("unhandledRejection", handleUnhandledRejection);
101314
+ startAppAlarms(deliverAlarm);
101023
101315
  stopSessionEvents = () => {
101024
101316
  untap2();
101317
+ stopAppAlarms();
101025
101318
  process.off("unhandledRejection", handleUnhandledRejection);
101026
101319
  };
101027
101320
  }
@@ -101031,6 +101324,7 @@ function stopHeadlessEvents() {
101031
101324
  }
101032
101325
  function invalidateHeadlessRuntime(appId) {
101033
101326
  invalidateCompiledApp(appId);
101327
+ activityApps = null;
101034
101328
  if (!appId) {
101035
101329
  runtimes.clear();
101036
101330
  return;
@@ -101151,7 +101445,7 @@ function dispatchAppTool(toolName, args, workspace = "", callerSessionId) {
101151
101445
  }
101152
101446
  const callId = v4_default();
101153
101447
  const result = new Promise((resolve, reject) => {
101154
- const timer2 = setTimeout(() => {
101448
+ const timer3 = setTimeout(() => {
101155
101449
  pendingCalls2.delete(callId);
101156
101450
  reject(
101157
101451
  new Error(
@@ -101159,7 +101453,7 @@ function dispatchAppTool(toolName, args, workspace = "", callerSessionId) {
101159
101453
  )
101160
101454
  );
101161
101455
  }, TOOL_CALL_TIMEOUT_MS);
101162
- pendingCalls2.set(callId, { resolve, reject, timer: timer2, appId });
101456
+ pendingCalls2.set(callId, { resolve, reject, timer: timer3, appId });
101163
101457
  broadcast("app:tool_call", { appId, callId, tool: localName, args: args ?? {}, workspace, caller });
101164
101458
  });
101165
101459
  return { callId, result };
@@ -101905,6 +102199,7 @@ async function registerAppRoutes(fastify, opts) {
101905
102199
  fs7.rmSync(appDir(id), { recursive: true, force: true });
101906
102200
  deleteAppFiles(id);
101907
102201
  deleteAppInstances(id);
102202
+ deleteAppAlarms(id);
101908
102203
  invalidateHeadlessRuntime(id);
101909
102204
  return { ok: true };
101910
102205
  });
@@ -102159,7 +102454,7 @@ function runCcusage(args) {
102159
102454
  failure ??= reason;
102160
102455
  child.kill("SIGTERM");
102161
102456
  };
102162
- const timer2 = setTimeout(() => stop(`ccusage did not finish in ${RUN_TIMEOUT_MS / 1e3}s`), RUN_TIMEOUT_MS);
102457
+ const timer3 = setTimeout(() => stop(`ccusage did not finish in ${RUN_TIMEOUT_MS / 1e3}s`), RUN_TIMEOUT_MS);
102163
102458
  child.stdout.on("data", (chunk) => {
102164
102459
  size2 += chunk.length;
102165
102460
  if (size2 > MAX_OUTPUT_BYTES) stop("ccusage output is too large");
@@ -102169,11 +102464,11 @@ function runCcusage(args) {
102169
102464
  if (stderr.length < 16384) stderr += chunk.toString("utf8");
102170
102465
  });
102171
102466
  child.on("error", (err) => {
102172
- clearTimeout(timer2);
102467
+ clearTimeout(timer3);
102173
102468
  reject(new Error(`ccusage could not start: ${err.message}`));
102174
102469
  });
102175
102470
  child.on("close", (code, signal) => {
102176
- clearTimeout(timer2);
102471
+ clearTimeout(timer3);
102177
102472
  if (failure) return reject(new Error(failure));
102178
102473
  if (code !== 0) {
102179
102474
  const detail = stderr.trim().split("\n").slice(-3).join(" ").slice(0, 500);
@@ -118585,11 +118880,11 @@ function requestHost(dir, body, timeoutMs = 2e3) {
118585
118880
  const sock = net2.connect(hostSocketPath(dir));
118586
118881
  let buf = "";
118587
118882
  let settled = false;
118588
- const timer2 = setTimeout(() => finish(Object.assign(new Error("session host timed out"), { code: "ETIMEDOUT" })), timeoutMs);
118883
+ const timer3 = setTimeout(() => finish(Object.assign(new Error("session host timed out"), { code: "ETIMEDOUT" })), timeoutMs);
118589
118884
  const finish = (err, value) => {
118590
118885
  if (settled) return;
118591
118886
  settled = true;
118592
- clearTimeout(timer2);
118887
+ clearTimeout(timer3);
118593
118888
  sock.destroy();
118594
118889
  if (err) reject(err);
118595
118890
  else resolve(value);
@@ -118644,11 +118939,11 @@ function attachHost(dir, after, timeoutMs = 5e3) {
118644
118939
  const sock = net2.connect(hostSocketPath(dir));
118645
118940
  let head = Buffer.alloc(0);
118646
118941
  let settled = false;
118647
- const timer2 = setTimeout(() => fail(Object.assign(new Error("session host attach timed out"), { code: "ETIMEDOUT" })), timeoutMs);
118942
+ const timer3 = setTimeout(() => fail(Object.assign(new Error("session host attach timed out"), { code: "ETIMEDOUT" })), timeoutMs);
118648
118943
  const fail = (err) => {
118649
118944
  if (settled) return;
118650
118945
  settled = true;
118651
- clearTimeout(timer2);
118946
+ clearTimeout(timer3);
118652
118947
  sock.destroy();
118653
118948
  reject(err);
118654
118949
  };
@@ -118673,7 +118968,7 @@ function attachHost(dir, after, timeoutMs = 5e3) {
118673
118968
  return;
118674
118969
  }
118675
118970
  settled = true;
118676
- clearTimeout(timer2);
118971
+ clearTimeout(timer3);
118677
118972
  sock.off("error", fail);
118678
118973
  sock.off("close", onEarlyClose);
118679
118974
  const attachment = new HostAttachment(header, sock);
@@ -119814,6 +120109,21 @@ function reapOrphanCliProcesses(db2, deps = defaultDeps) {
119814
120109
  return reapOrphanProcesses(db2, "claude", deps);
119815
120110
  }
119816
120111
 
120112
+ // src/providers/thread-summary.ts
120113
+ function buildThreadSummaryPrompt(transcript, directives) {
120114
+ const directiveLine = directives.trim() ? `
120115
+
120116
+ The user has given these summarization directives \u2014 follow them exactly:
120117
+ "${directives.trim()}"` : "";
120118
+ 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}
120119
+
120120
+ The discussion transcript (from the discussion's beginning):
120121
+
120122
+ ${transcript}
120123
+
120124
+ 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.`;
120125
+ }
120126
+
119817
120127
  // src/codex/codex-provider.ts
119818
120128
  var TERMINAL_TASK_TYPE = "background_terminal";
119819
120129
  function taskPollMs() {
@@ -120145,7 +120455,9 @@ function completeTurn(db2, sessionId, turnId, usage) {
120145
120455
  const response = turnResponse(db2, turnId);
120146
120456
  const result = usage !== void 0 ? db2.prepare(
120147
120457
  "UPDATE turns SET status = 'completed', token_usage = ?, updated_at = ? WHERE id = ? AND status IN ('pending', 'running')"
120148
- ).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);
120458
+ ).run(JSON.stringify(usage), now, turnId) : db2.prepare(
120459
+ "UPDATE turns SET status = 'completed', updated_at = ? WHERE id = ? AND status IN ('pending', 'running')"
120460
+ ).run(now, turnId);
120149
120461
  if (result.changes === 0) return;
120150
120462
  broadcast("turn:completed", {
120151
120463
  sessionId,
@@ -120582,15 +120894,15 @@ function handleItemEvent(params, sessionId, turnId, status, broadcastEvent, extr
120582
120894
  }
120583
120895
  function within(promise2, ms) {
120584
120896
  return new Promise((resolve) => {
120585
- const timer2 = setTimeout(() => resolve(null), ms);
120586
- timer2.unref?.();
120897
+ const timer3 = setTimeout(() => resolve(null), ms);
120898
+ timer3.unref?.();
120587
120899
  promise2.then(
120588
120900
  (value) => {
120589
- clearTimeout(timer2);
120901
+ clearTimeout(timer3);
120590
120902
  resolve(value);
120591
120903
  },
120592
120904
  () => {
120593
- clearTimeout(timer2);
120905
+ clearTimeout(timer3);
120594
120906
  resolve(null);
120595
120907
  }
120596
120908
  );
@@ -120797,17 +121109,7 @@ async function summarizeCodexThread(session, _thread, transcript, directives) {
120797
121109
  ephemeral: true
120798
121110
  });
120799
121111
  const threadId = initResult.thread.id;
120800
- const directiveLine = directives.trim() ? `
120801
-
120802
- The user has given these summarization directives \u2014 follow them exactly:
120803
- "${directives.trim()}"` : "";
120804
- 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}
120805
-
120806
- The discussion transcript (from the discussion's beginning):
120807
-
120808
- ${transcript}
120809
-
120810
- 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.`;
121112
+ const summaryPrompt = buildThreadSummaryPrompt(transcript, directives);
120811
121113
  let summaryResolve;
120812
121114
  let summaryReject;
120813
121115
  const summaryPromise = new Promise((resolve, reject) => {
@@ -120913,7 +121215,10 @@ async function forkSession(session, targetTurn) {
120913
121215
  try {
120914
121216
  result = await fork({ lastTurnId });
120915
121217
  } catch (err) {
120916
- const range = await client.request("thread/read", { threadId, includeTurns: true }).then(({ thread }) => forkThroughReview(thread.turns ?? [], lastTurnId), () => void 0);
121218
+ const range = await client.request("thread/read", { threadId, includeTurns: true }).then(
121219
+ ({ thread }) => forkThroughReview(thread.turns ?? [], lastTurnId),
121220
+ () => void 0
121221
+ );
120917
121222
  if (!range) throw err;
120918
121223
  result = await fork(range);
120919
121224
  }
@@ -121154,7 +121459,9 @@ function hostFor(sessionId, cwd, options, onDirect) {
121154
121459
  const { command, args } = appServerCommand(options);
121155
121460
  return startCodexHost(getDb(), { sessionId, cwd, command, args, env: { ...process.env }, onDirect });
121156
121461
  } catch (err) {
121157
- console.error(`[codex] no session host for ${sessionId} (${err.message}); running the app-server directly`);
121462
+ console.error(
121463
+ `[codex] no session host for ${sessionId} (${err.message}); running the app-server directly`
121464
+ );
121158
121465
  return null;
121159
121466
  }
121160
121467
  }
@@ -121208,7 +121515,9 @@ function settleHostTurn(entry) {
121208
121515
  function maybeRetire(entry) {
121209
121516
  const why = entry.retireWhenIdle;
121210
121517
  if (!why || entry.replaying || entry.turns.length > 0 || !isCurrent(entry)) return;
121211
- console.log(`[codex] closing the idle app-server of session ${entry.sessionId} (${why}); the next prompt starts a new one`);
121518
+ console.log(
121519
+ `[codex] closing the idle app-server of session ${entry.sessionId} (${why}); the next prompt starts a new one`
121520
+ );
121212
121521
  void retireEntry(entry, "keep");
121213
121522
  }
121214
121523
  function detachEntry(entry) {
@@ -121289,16 +121598,16 @@ function replayDone(client, what) {
121289
121598
  if (!client.replaying || client.isClosed()) return Promise.resolve();
121290
121599
  return new Promise((resolve) => {
121291
121600
  const done = () => {
121292
- clearTimeout(timer2);
121601
+ clearTimeout(timer3);
121293
121602
  client.events.off("replayDone", done);
121294
121603
  client.events.off("closed", done);
121295
121604
  resolve();
121296
121605
  };
121297
- const timer2 = setTimeout(() => {
121606
+ const timer3 = setTimeout(() => {
121298
121607
  console.error(`[codex] the replay of ${what} takes long; startup goes on`);
121299
121608
  done();
121300
121609
  }, REPLAY_WAIT_MS);
121301
- timer2.unref?.();
121610
+ timer3.unref?.();
121302
121611
  client.events.once("replayDone", done);
121303
121612
  client.events.once("closed", done);
121304
121613
  });
@@ -121370,7 +121679,9 @@ var codexHostAdopter = {
121370
121679
  if (!session || session.runtime_type !== "codex") return;
121371
121680
  const detail = describeExit(exit);
121372
121681
  const threadId = row.external_id ?? session.external_thread_id;
121373
- console.log(`[codex] the app-server of session ${session.id} ended with no daemon attached (${detail}); replaying its log`);
121682
+ console.log(
121683
+ `[codex] the app-server of session ${session.id} ended with no daemon attached (${detail}); replaying its log`
121684
+ );
121374
121685
  if (log && log.length > 0 && threadId) {
121375
121686
  const logged = new LoggedAppServer();
121376
121687
  const client = new AppServerClient({ cwd: session.cwd ?? process.cwd(), process: logged, replaying: true });
@@ -123401,7 +123712,7 @@ Agent responded: "${truncatedResponse}"`;
123401
123712
  }
123402
123713
  }
123403
123714
  }
123404
- function buildThreadSummaryPrompt(transcript, directives, hasNativeContext) {
123715
+ function buildThreadSummaryPrompt2(transcript, directives, hasNativeContext) {
123405
123716
  const directiveLine = directives.trim() ? `
123406
123717
 
123407
123718
  The user has given these summarization directives \u2014 follow them exactly:
@@ -123429,7 +123740,7 @@ async function summarizeClaudeThread(session, thread, transcript, directives) {
123429
123740
  console.error("[claude] summarizeThread fork failed \u2014 falling back to embedded transcript:", err);
123430
123741
  }
123431
123742
  }
123432
- const prompt = buildThreadSummaryPrompt(transcript, directives, !!resumeId);
123743
+ const prompt = buildThreadSummaryPrompt2(transcript, directives, !!resumeId);
123433
123744
  q = query({
123434
123745
  prompt,
123435
123746
  options: {
@@ -123663,18 +123974,18 @@ var claudeHostAdopter = {
123663
123974
  retire
123664
123975
  });
123665
123976
  refreshHostLimit2(entry, running);
123666
- let timer2 = null;
123977
+ let timer3 = null;
123667
123978
  await Promise.race([
123668
123979
  entry.replayDone,
123669
123980
  new Promise((resolve) => {
123670
- timer2 = setTimeout(() => {
123981
+ timer3 = setTimeout(() => {
123671
123982
  console.error(`[claude] the replay of ${row.entry_key} takes long; startup goes on`);
123672
123983
  resolve();
123673
123984
  }, REPLAY_WAIT_MS2);
123674
- timer2.unref?.();
123985
+ timer3.unref?.();
123675
123986
  })
123676
123987
  ]);
123677
- if (timer2) clearTimeout(timer2);
123988
+ if (timer3) clearTimeout(timer3);
123678
123989
  console.log(
123679
123990
  `[claude] adopted the CLI of ${row.entry_key} (pid ${proc.pid ?? "?"})${running ? `, turn ${row.turn_id} goes on` : ""}${retire ? `; it closes once idle: ${retire}` : ""}`
123680
123991
  );
@@ -123872,12 +124183,12 @@ var HttpError = class extends Error {
123872
124183
  };
123873
124184
  async function fetchJson(url2, init, timeoutMs = 5e3) {
123874
124185
  const controller = new AbortController();
123875
- const timer2 = setTimeout(() => controller.abort(), timeoutMs);
124186
+ const timer3 = setTimeout(() => controller.abort(), timeoutMs);
123876
124187
  let response;
123877
124188
  try {
123878
124189
  response = await fetch(url2, { ...init, signal: controller.signal });
123879
124190
  } finally {
123880
- clearTimeout(timer2);
124191
+ clearTimeout(timer3);
123881
124192
  }
123882
124193
  const text2 = await response.text();
123883
124194
  if (!response.ok) {
@@ -124043,7 +124354,7 @@ function parseSelectionGroups(raw) {
124043
124354
  }).filter((g) => g !== null);
124044
124355
  }
124045
124356
  function mapActionToItem(action) {
124046
- const failed = action.status === "EXECUTION_FAILED";
124357
+ const failed = String(action.status ?? "").toLowerCase() === "execution_failed";
124047
124358
  const status = failed ? "failed" : "completed";
124048
124359
  const log = action.executionLogs?.[0];
124049
124360
  const output = log?.output ?? "";
@@ -124266,11 +124577,7 @@ async function streamAgentRuntimeMessages(baseUrl, sessionId, onMessage, opts =
124266
124577
  await reconnectDelay(delayMs, opts.signal);
124267
124578
  continue;
124268
124579
  }
124269
- const reason = await readBody(
124270
- response.body,
124271
- onMessage,
124272
- opts
124273
- );
124580
+ const reason = await readBody(response.body, onMessage, opts);
124274
124581
  if (reason !== null) {
124275
124582
  await response.body.cancel().catch(() => {
124276
124583
  });
@@ -124333,11 +124640,11 @@ async function getAgentRuntimeState(baseUrl, sessionId, timeoutMs = 5e3) {
124333
124640
  function reconnectDelay(delayMs, signal) {
124334
124641
  return new Promise((resolve) => {
124335
124642
  if (signal?.aborted) return resolve();
124336
- const timer2 = setTimeout(resolve, delayMs);
124643
+ const timer3 = setTimeout(resolve, delayMs);
124337
124644
  signal?.addEventListener(
124338
124645
  "abort",
124339
124646
  () => {
124340
- clearTimeout(timer2);
124647
+ clearTimeout(timer3);
124341
124648
  resolve();
124342
124649
  },
124343
124650
  { once: true }
@@ -124345,6 +124652,50 @@ function reconnectDelay(delayMs, signal) {
124345
124652
  });
124346
124653
  }
124347
124654
 
124655
+ // src/repoburg/throwaway-run.ts
124656
+ async function runThrowawayPrompt(client, options) {
124657
+ let throwawayId = null;
124658
+ try {
124659
+ const created = await client.createSession(options.model ? { model_id: options.model } : {});
124660
+ throwawayId = created.id;
124661
+ const controller = new AbortController();
124662
+ const timer3 = setTimeout(() => controller.abort(), options.timeoutMs);
124663
+ try {
124664
+ await client.createInput(throwawayId, {
124665
+ user_prompt: options.prompt,
124666
+ execution_strategy: "auto_apply"
124667
+ });
124668
+ let reply = "";
124669
+ let failed = false;
124670
+ const consume = (message) => {
124671
+ if (message.type === "assistant") {
124672
+ reply += message.content.filter((b) => b.type === "text").map((b) => b.text).join("");
124673
+ } else if (message.type === "result") {
124674
+ if (message.is_error) failed = true;
124675
+ else if (message.result) reply = message.result;
124676
+ }
124677
+ };
124678
+ const reason = await streamAgentRuntimeMessages(client.baseUrl, throwawayId, consume, {
124679
+ signal: controller.signal,
124680
+ deltas: false
124681
+ });
124682
+ if (reason === "aborted") {
124683
+ void client.cancel(throwawayId).catch(() => {
124684
+ });
124685
+ return null;
124686
+ }
124687
+ return failed ? null : reply;
124688
+ } finally {
124689
+ clearTimeout(timer3);
124690
+ }
124691
+ } catch {
124692
+ return null;
124693
+ } finally {
124694
+ if (throwawayId) void client.deleteSession(throwawayId).catch(() => {
124695
+ });
124696
+ }
124697
+ }
124698
+
124348
124699
  // src/repoburg/turn-projector.ts
124349
124700
  var RESULT_TIMEOUT_MS = 15 * 6e4;
124350
124701
  var MAX_RESULT_EXTENSIONS = 3;
@@ -124379,8 +124730,8 @@ var TurnProjector = class {
124379
124730
  }
124380
124731
  switch (message.type) {
124381
124732
  case "system":
124733
+ if (message.subtype === "compact_boundary") this.handleCompactBoundary(message);
124382
124734
  break;
124383
- // init — connection marker only; gaps go to recoverGap
124384
124735
  case "stream_event":
124385
124736
  this.handleStreamEvent(message);
124386
124737
  break;
@@ -124497,10 +124848,7 @@ var TurnProjector = class {
124497
124848
  }
124498
124849
  if (ids.includes(inputId)) return;
124499
124850
  ids.push(inputId);
124500
- db2.prepare("UPDATE turns SET runtime_input_ids = ? WHERE id = ?").run(
124501
- JSON.stringify(ids),
124502
- this.deps.turnId
124503
- );
124851
+ db2.prepare("UPDATE turns SET runtime_input_ids = ? WHERE id = ?").run(JSON.stringify(ids), this.deps.turnId);
124504
124852
  } catch {
124505
124853
  }
124506
124854
  }
@@ -124575,7 +124923,14 @@ var TurnProjector = class {
124575
124923
  else info.reasoningItemId = existing.id;
124576
124924
  const data = existing.data ? JSON.parse(existing.data) : {};
124577
124925
  if (existing.status !== "completed" || data.text !== text2) {
124578
- completeItem(db2, this.deps.agentPaneSessionId, this.deps.turnId, { ...existing, data }, { text: text2 }, "completed");
124926
+ completeItem(
124927
+ db2,
124928
+ this.deps.agentPaneSessionId,
124929
+ this.deps.turnId,
124930
+ { ...existing, data },
124931
+ { text: text2 },
124932
+ "completed"
124933
+ );
124579
124934
  }
124580
124935
  return;
124581
124936
  }
@@ -124592,6 +124947,28 @@ var TurnProjector = class {
124592
124947
  if (kind === "message") info.messageItemId = item.id;
124593
124948
  else info.reasoningItemId = item.id;
124594
124949
  }
124950
+ /** The backend compacted the context: a "Context compacted" row (the
124951
+ * item Claude sessions show), and the context counter drops to the fill
124952
+ * after it. */
124953
+ handleCompactBoundary(msg) {
124954
+ const meta3 = msg.compact_metadata;
124955
+ const externalId = `compact-${msg.seq ?? Date.now()}`;
124956
+ if (this.existingItemId(externalId)) return;
124957
+ insertItem(
124958
+ getDb(),
124959
+ this.deps.agentPaneSessionId,
124960
+ this.deps.turnId,
124961
+ externalId,
124962
+ "context_compaction",
124963
+ { trigger: meta3.trigger, pre_tokens: meta3.pre_tokens, post_tokens: meta3.post_tokens },
124964
+ "completed",
124965
+ "item:completed"
124966
+ );
124967
+ if (meta3.post_tokens > 0) {
124968
+ this.lastContextTokens = meta3.post_tokens;
124969
+ this.emitContextUsage();
124970
+ }
124971
+ }
124595
124972
  existingItemId(externalId) {
124596
124973
  const row = getDb().prepare("SELECT id FROM items WHERE turn_id = ? AND external_item_id = ?").get(this.deps.turnId, externalId);
124597
124974
  return row?.id ?? null;
@@ -124711,9 +125088,13 @@ var TurnProjector = class {
124711
125088
  output: msg.usage.output_tokens
124712
125089
  }) : null;
124713
125090
  this.closeOpenItems("completed");
124714
- db2.prepare(
124715
- "UPDATE turns SET status = ?, agent_response = ?, token_usage = ?, updated_at = ? WHERE id = ?"
124716
- ).run("completed", responseText || null, usage ? JSON.stringify(usage) : null, now, this.deps.turnId);
125091
+ db2.prepare("UPDATE turns SET status = ?, agent_response = ?, token_usage = ?, updated_at = ? WHERE id = ?").run(
125092
+ "completed",
125093
+ responseText || null,
125094
+ usage ? JSON.stringify(usage) : null,
125095
+ now,
125096
+ this.deps.turnId
125097
+ );
124717
125098
  recomputeSessionRunning(db2, this.deps.agentPaneSessionId, "active", true);
124718
125099
  broadcast("turn:completed", {
124719
125100
  sessionId: this.deps.agentPaneSessionId,
@@ -124757,9 +125138,7 @@ var TurnProjector = class {
124757
125138
  async syncTitle() {
124758
125139
  try {
124759
125140
  const db2 = getDb();
124760
- const session = db2.prepare("SELECT title FROM sessions WHERE id = ?").get(
124761
- this.deps.agentPaneSessionId
124762
- );
125141
+ const session = db2.prepare("SELECT title FROM sessions WHERE id = ?").get(this.deps.agentPaneSessionId);
124763
125142
  if (!session || session.title) return;
124764
125143
  const runtimeSession = await this.deps.client.getSession(this.deps.repoburgSessionId);
124765
125144
  const title = (runtimeSession.session_title || "").trim();
@@ -124790,54 +125169,19 @@ var TurnProjector = class {
124790
125169
  const sessionId = this.deps.agentPaneSessionId;
124791
125170
  if (titleGenerating3.has(sessionId)) return;
124792
125171
  const db2 = getDb();
124793
- const firstTurn = db2.prepare(
124794
- "SELECT user_prompt, agent_response FROM turns WHERE session_id = ? ORDER BY created_at ASC LIMIT 1"
124795
- ).get(sessionId);
125172
+ const firstTurn = db2.prepare("SELECT user_prompt, agent_response FROM turns WHERE session_id = ? ORDER BY created_at ASC LIMIT 1").get(sessionId);
124796
125173
  if (!firstTurn) return;
124797
125174
  titleGenerating3.add(sessionId);
124798
- let throwawayId = null;
124799
125175
  try {
124800
125176
  const pane = db2.prepare("SELECT model FROM sessions WHERE id = ?").get(sessionId);
124801
- const created = await this.deps.client.createSession(
124802
- pane?.model ? { model_id: pane.model } : {}
124803
- );
124804
- throwawayId = created.id;
124805
- const controller = new AbortController();
124806
- const timer2 = setTimeout(() => controller.abort(), TITLE_TIMEOUT_MS);
124807
- try {
124808
- await this.deps.client.createInput(throwawayId, {
124809
- user_prompt: buildTitlePrompt(firstTurn.user_prompt, firstTurn.agent_response),
124810
- execution_strategy: "auto_apply"
124811
- });
124812
- let reply = "";
124813
- const consume = (message) => {
124814
- if (message.type === "assistant") {
124815
- reply += message.content.filter((b) => b.type === "text").map((b) => b.text).join("");
124816
- } else if (message.type === "result" && !message.is_error && message.result) {
124817
- reply = message.result;
124818
- }
124819
- };
124820
- const reason = await streamAgentRuntimeMessages(
124821
- this.deps.client.baseUrl,
124822
- throwawayId,
124823
- consume,
124824
- { signal: controller.signal, deltas: false }
124825
- );
124826
- if (reason === "aborted") {
124827
- void this.deps.client.cancel(throwawayId).catch(() => {
124828
- });
124829
- }
124830
- const title = cleanTitle(reply);
124831
- if (title) this.applyTitle(title);
124832
- } finally {
124833
- clearTimeout(timer2);
124834
- }
124835
- } catch {
125177
+ const reply = await runThrowawayPrompt(this.deps.client, {
125178
+ model: pane?.model,
125179
+ prompt: buildTitlePrompt(firstTurn.user_prompt, firstTurn.agent_response),
125180
+ timeoutMs: TITLE_TIMEOUT_MS
125181
+ });
125182
+ const title = cleanTitle(reply ?? "");
125183
+ if (title) this.applyTitle(title);
124836
125184
  } finally {
124837
- if (throwawayId) {
124838
- void this.deps.client.deleteSession(throwawayId).catch(() => {
124839
- });
124840
- }
124841
125185
  titleGenerating3.delete(sessionId);
124842
125186
  }
124843
125187
  }
@@ -124863,11 +125207,7 @@ var TurnProjector = class {
124863
125207
  const db2 = getDb();
124864
125208
  const now = (/* @__PURE__ */ new Date()).toISOString();
124865
125209
  this.closeOpenItems("completed");
124866
- db2.prepare("UPDATE turns SET status = ?, updated_at = ? WHERE id = ?").run(
124867
- "aborted",
124868
- now,
124869
- this.deps.turnId
124870
- );
125210
+ db2.prepare("UPDATE turns SET status = ?, updated_at = ? WHERE id = ?").run("aborted", now, this.deps.turnId);
124871
125211
  recomputeSessionRunning(db2, this.deps.agentPaneSessionId);
124872
125212
  broadcast("turn:cancelled", {
124873
125213
  sessionId: this.deps.agentPaneSessionId,
@@ -124934,9 +125274,13 @@ var TurnProjector = class {
124934
125274
  const db2 = getDb();
124935
125275
  const now = (/* @__PURE__ */ new Date()).toISOString();
124936
125276
  this.closeOpenItems("completed");
124937
- db2.prepare(
124938
- "UPDATE turns SET status = ?, agent_response = ?, token_usage = ?, updated_at = ? WHERE id = ?"
124939
- ).run("completed", responseText || null, usage ? JSON.stringify(usage) : null, now, this.deps.turnId);
125277
+ db2.prepare("UPDATE turns SET status = ?, agent_response = ?, token_usage = ?, updated_at = ? WHERE id = ?").run(
125278
+ "completed",
125279
+ responseText || null,
125280
+ usage ? JSON.stringify(usage) : null,
125281
+ now,
125282
+ this.deps.turnId
125283
+ );
124940
125284
  recomputeSessionRunning(db2, this.deps.agentPaneSessionId, "active", true);
124941
125285
  broadcast("turn:completed", {
124942
125286
  sessionId: this.deps.agentPaneSessionId,
@@ -125005,9 +125349,7 @@ var TurnProjector = class {
125005
125349
  }
125006
125350
  };
125007
125351
  function extractFinalPlain(input) {
125008
- const action = input?.aiActions?.find(
125009
- (a) => a.action_type === "final" || a.action_type === "html_final"
125010
- );
125352
+ const action = input?.aiActions?.find((a) => a.action_type === "final" || a.action_type === "html_final");
125011
125353
  return action?.plain ?? null;
125012
125354
  }
125013
125355
  function buildTitlePrompt(userPrompt, agentResponse) {
@@ -125053,9 +125395,7 @@ var BACKEND_RESTARTED_ERROR = "The Repoburg backend restarted while this turn ra
125053
125395
  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.`;
125054
125396
  function isConnectionError(err) {
125055
125397
  const message = String(err?.message ?? "");
125056
- return /fetch failed|ECONNREFUSED|ENOTFOUND|ECONNRESET|ETIMEDOUT|EHOSTUNREACH|socket hang up/i.test(
125057
- message
125058
- );
125398
+ return /fetch failed|ECONNREFUSED|ENOTFOUND|ECONNRESET|ETIMEDOUT|EHOSTUNREACH|socket hang up/i.test(message);
125059
125399
  }
125060
125400
  async function ensureSession(session, client, baseUrl) {
125061
125401
  const existing = sessionMap3.get(session.id);
@@ -125165,12 +125505,7 @@ async function ensureContextWindow(entry) {
125165
125505
  }
125166
125506
  function failTurnBeforeStart(db2, sessionId, turnId, error51) {
125167
125507
  const now = (/* @__PURE__ */ new Date()).toISOString();
125168
- db2.prepare("UPDATE turns SET status = ?, error = ?, updated_at = ? WHERE id = ?").run(
125169
- "failed",
125170
- error51,
125171
- now,
125172
- turnId
125173
- );
125508
+ db2.prepare("UPDATE turns SET status = ?, error = ?, updated_at = ? WHERE id = ?").run("failed", error51, now, turnId);
125174
125509
  recomputeSessionRunning(db2, sessionId, "failed");
125175
125510
  broadcast("turn:failed", { sessionId, turnId, error: error51 });
125176
125511
  }
@@ -125225,7 +125560,7 @@ async function runStreamLoop(entry, projector) {
125225
125560
  });
125226
125561
  return;
125227
125562
  }
125228
- if (message.type === "system") {
125563
+ if (message.type === "system" && message.subtype === "init") {
125229
125564
  clearLostTimer();
125230
125565
  const bootId = message.bootId ?? null;
125231
125566
  if (active.bootId === void 0) active.bootId = bootId;
@@ -125587,6 +125922,21 @@ async function forkSession2(session, targetTurn) {
125587
125922
  const forked = await client.forkSession(session.external_thread_id, anchor);
125588
125923
  return forked.id;
125589
125924
  }
125925
+ var THREAD_SUMMARY_TIMEOUT_MS = 12e4;
125926
+ async function summarizeThread(session, _thread, transcript, directives) {
125927
+ try {
125928
+ const client = await resolveClient(session);
125929
+ const reply = await runThrowawayPrompt(client, {
125930
+ model: session.model,
125931
+ prompt: buildThreadSummaryPrompt(transcript, directives),
125932
+ timeoutMs: THREAD_SUMMARY_TIMEOUT_MS
125933
+ });
125934
+ return reply?.trim() || null;
125935
+ } catch (err) {
125936
+ console.error("[repoburg] summarizeThread failed:", err);
125937
+ return null;
125938
+ }
125939
+ }
125590
125940
  function clearAllThreads3() {
125591
125941
  for (const entry of sessionMap3.values()) {
125592
125942
  if (entry.activeTurn) {
@@ -125699,6 +126049,7 @@ var repoburgProvider = {
125699
126049
  getCommands: getCommands3,
125700
126050
  rewindRuntime,
125701
126051
  forkSession: forkSession2,
126052
+ summarizeThread,
125702
126053
  shutdown: shutdown3
125703
126054
  };
125704
126055