repoburg 1.3.322 → 1.3.324

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 (198) hide show
  1. package/agent-pane/backend/dist/index.js +795 -351
  2. package/agent-pane/backend/dist/server.js +796 -352
  3. package/agent-pane/frontend/dist/assets/{TerminalView-Z7ZJ436H.js → TerminalView-DQaRNqT-.js} +1 -1
  4. package/agent-pane/frontend/dist/assets/index-CUuZmtId.css +1 -0
  5. package/agent-pane/frontend/dist/assets/index-kBNaARow.js +862 -0
  6. package/agent-pane/frontend/dist/index.html +2 -2
  7. package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.d.ts +6 -1
  8. package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.js +31 -0
  9. package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.js.map +1 -1
  10. package/backend/dist/src/agent-runtime/agent-runtime.types.d.ts +22 -2
  11. package/backend/dist/src/ai-actions/ai-action-batch.service.d.ts +3 -1
  12. package/backend/dist/src/ai-actions/ai-action-batch.service.js +20 -6
  13. package/backend/dist/src/ai-actions/ai-action-batch.service.js.map +1 -1
  14. package/backend/dist/src/app.module.js +6 -0
  15. package/backend/dist/src/app.module.js.map +1 -1
  16. package/backend/dist/src/application-state/application-state.controller.d.ts +0 -6
  17. package/backend/dist/src/application-state/application-state.controller.js +0 -29
  18. package/backend/dist/src/application-state/application-state.controller.js.map +1 -1
  19. package/backend/dist/src/application-state/application-state.service.d.ts +1 -3
  20. package/backend/dist/src/application-state/application-state.service.js +8 -15
  21. package/backend/dist/src/application-state/application-state.service.js.map +1 -1
  22. package/backend/dist/src/background-tasks/background-tasks.controller.d.ts +9 -0
  23. package/backend/dist/src/background-tasks/background-tasks.controller.js +59 -0
  24. package/backend/dist/src/background-tasks/background-tasks.controller.js.map +1 -0
  25. package/backend/dist/src/background-tasks/background-tasks.module.d.ts +2 -0
  26. package/backend/dist/src/background-tasks/background-tasks.module.js +32 -0
  27. package/backend/dist/src/background-tasks/background-tasks.module.js.map +1 -0
  28. package/backend/dist/src/background-tasks/background-tasks.service.d.ts +62 -0
  29. package/backend/dist/src/background-tasks/background-tasks.service.js +415 -0
  30. package/backend/dist/src/background-tasks/background-tasks.service.js.map +1 -0
  31. package/backend/dist/src/command-hooks/command-hooks.module.d.ts +2 -0
  32. package/backend/dist/src/command-hooks/command-hooks.module.js +24 -0
  33. package/backend/dist/src/command-hooks/command-hooks.module.js.map +1 -0
  34. package/backend/dist/src/command-hooks/command-hooks.service.d.ts +39 -0
  35. package/backend/dist/src/command-hooks/command-hooks.service.js +367 -0
  36. package/backend/dist/src/command-hooks/command-hooks.service.js.map +1 -0
  37. package/backend/dist/src/context-generation/context-generation.service.d.ts +3 -0
  38. package/backend/dist/src/context-generation/context-generation.service.js +7 -1
  39. package/backend/dist/src/context-generation/context-generation.service.js.map +1 -1
  40. package/backend/dist/src/core-entities/session.entity.d.ts +1 -0
  41. package/backend/dist/src/core-entities/session.entity.js +7 -0
  42. package/backend/dist/src/core-entities/session.entity.js.map +1 -1
  43. package/backend/dist/src/file-read-registry/file-read-registry.module.d.ts +2 -0
  44. package/backend/dist/src/file-read-registry/file-read-registry.module.js +26 -0
  45. package/backend/dist/src/file-read-registry/file-read-registry.module.js.map +1 -0
  46. package/backend/dist/src/file-read-registry/file-read-registry.service.d.ts +28 -0
  47. package/backend/dist/src/file-read-registry/file-read-registry.service.js +199 -0
  48. package/backend/dist/src/file-read-registry/file-read-registry.service.js.map +1 -0
  49. package/backend/dist/src/global-config/dto/update-global-config.dto.d.ts +1 -1
  50. package/backend/dist/src/global-config/dto/update-global-config.dto.js +7 -5
  51. package/backend/dist/src/global-config/dto/update-global-config.dto.js.map +1 -1
  52. package/backend/dist/src/global-config/global-config.service.d.ts +1 -1
  53. package/backend/dist/src/global-config/global-config.service.js.map +1 -1
  54. package/backend/dist/src/interactive-chat/auto-compact.service.d.ts +3 -1
  55. package/backend/dist/src/interactive-chat/auto-compact.service.js +8 -2
  56. package/backend/dist/src/interactive-chat/auto-compact.service.js.map +1 -1
  57. package/backend/dist/src/interactive-chat/chat.service.d.ts +7 -1
  58. package/backend/dist/src/interactive-chat/chat.service.js +82 -2
  59. package/backend/dist/src/interactive-chat/chat.service.js.map +1 -1
  60. package/backend/dist/src/llm-orchestration/action-handlers/action-handler.interface.d.ts +1 -0
  61. package/backend/dist/src/llm-orchestration/action-handlers/dto/run-command.args.dto.d.ts +2 -0
  62. package/backend/dist/src/llm-orchestration/action-handlers/dto/run-command.args.dto.js +10 -0
  63. package/backend/dist/src/llm-orchestration/action-handlers/dto/run-command.args.dto.js.map +1 -1
  64. package/backend/dist/src/llm-orchestration/action-handlers/list-mcp-resources.handler.d.ts +11 -0
  65. package/backend/dist/src/llm-orchestration/action-handlers/list-mcp-resources.handler.js +100 -0
  66. package/backend/dist/src/llm-orchestration/action-handlers/list-mcp-resources.handler.js.map +1 -0
  67. package/backend/dist/src/llm-orchestration/action-handlers/list-mcp.handler.d.ts +4 -2
  68. package/backend/dist/src/llm-orchestration/action-handlers/list-mcp.handler.js +15 -4
  69. package/backend/dist/src/llm-orchestration/action-handlers/list-mcp.handler.js.map +1 -1
  70. package/backend/dist/src/llm-orchestration/action-handlers/list-tools.handler.d.ts +4 -2
  71. package/backend/dist/src/llm-orchestration/action-handlers/list-tools.handler.js +15 -4
  72. package/backend/dist/src/llm-orchestration/action-handlers/list-tools.handler.js.map +1 -1
  73. package/backend/dist/src/llm-orchestration/action-handlers/load-tool.handler.d.ts +3 -1
  74. package/backend/dist/src/llm-orchestration/action-handlers/load-tool.handler.js +11 -3
  75. package/backend/dist/src/llm-orchestration/action-handlers/load-tool.handler.js.map +1 -1
  76. package/backend/dist/src/llm-orchestration/action-handlers/mcp-tool-action.handler.d.ts +1 -1
  77. package/backend/dist/src/llm-orchestration/action-handlers/mcp-tool-action.handler.js.map +1 -1
  78. package/backend/dist/src/llm-orchestration/action-handlers/read-mcp-resource.handler.d.ts +11 -0
  79. package/backend/dist/src/llm-orchestration/action-handlers/read-mcp-resource.handler.js +94 -0
  80. package/backend/dist/src/llm-orchestration/action-handlers/read-mcp-resource.handler.js.map +1 -0
  81. package/backend/dist/src/llm-orchestration/action-handlers/request-context.handler.d.ts +18 -1
  82. package/backend/dist/src/llm-orchestration/action-handlers/request-context.handler.js +266 -25
  83. package/backend/dist/src/llm-orchestration/action-handlers/request-context.handler.js.map +1 -1
  84. package/backend/dist/src/llm-orchestration/action-handlers/run-command.handler.d.ts +4 -1
  85. package/backend/dist/src/llm-orchestration/action-handlers/run-command.handler.js +79 -2
  86. package/backend/dist/src/llm-orchestration/action-handlers/run-command.handler.js.map +1 -1
  87. package/backend/dist/src/llm-orchestration/action-handlers/task-output.handler.d.ts +16 -0
  88. package/backend/dist/src/llm-orchestration/action-handlers/task-output.handler.js +135 -0
  89. package/backend/dist/src/llm-orchestration/action-handlers/task-output.handler.js.map +1 -0
  90. package/backend/dist/src/llm-orchestration/action-handlers/task-stop.handler.d.ts +12 -0
  91. package/backend/dist/src/llm-orchestration/action-handlers/task-stop.handler.js +78 -0
  92. package/backend/dist/src/llm-orchestration/action-handlers/task-stop.handler.js.map +1 -0
  93. package/backend/dist/src/llm-orchestration/action-handlers/utils/local-web-fetch.d.ts +28 -0
  94. package/backend/dist/src/llm-orchestration/action-handlers/utils/local-web-fetch.js +208 -0
  95. package/backend/dist/src/llm-orchestration/action-handlers/utils/local-web-fetch.js.map +1 -0
  96. package/backend/dist/src/llm-orchestration/action-handlers/web-fetch.handler.d.ts +2 -0
  97. package/backend/dist/src/llm-orchestration/action-handlers/web-fetch.handler.js +85 -60
  98. package/backend/dist/src/llm-orchestration/action-handlers/web-fetch.handler.js.map +1 -1
  99. package/backend/dist/src/llm-orchestration/action-handlers/web-search.handler.d.ts +1 -0
  100. package/backend/dist/src/llm-orchestration/action-handlers/web-search.handler.js +3 -0
  101. package/backend/dist/src/llm-orchestration/action-handlers/web-search.handler.js.map +1 -1
  102. package/backend/dist/src/llm-orchestration/hooks/frontend-notification.hook.js +13 -5
  103. package/backend/dist/src/llm-orchestration/hooks/frontend-notification.hook.js.map +1 -1
  104. package/backend/dist/src/llm-orchestration/hooks/invalid-tool-feedback.hook.js +2 -0
  105. package/backend/dist/src/llm-orchestration/hooks/invalid-tool-feedback.hook.js.map +1 -1
  106. package/backend/dist/src/llm-orchestration/hooks/max-turns-post-execution.hook.d.ts +12 -0
  107. package/backend/dist/src/llm-orchestration/hooks/max-turns-post-execution.hook.js +52 -0
  108. package/backend/dist/src/llm-orchestration/hooks/max-turns-post-execution.hook.js.map +1 -0
  109. package/backend/dist/src/llm-orchestration/hooks/stop-command-hooks.post-execution.hook.d.ts +16 -0
  110. package/backend/dist/src/llm-orchestration/hooks/stop-command-hooks.post-execution.hook.js +79 -0
  111. package/backend/dist/src/llm-orchestration/hooks/stop-command-hooks.post-execution.hook.js.map +1 -0
  112. package/backend/dist/src/llm-orchestration/llm-orchestration.interfaces.d.ts +1 -0
  113. package/backend/dist/src/llm-orchestration/llm-orchestration.interfaces.js.map +1 -1
  114. package/backend/dist/src/llm-orchestration/llm-orchestration.module.js +49 -88
  115. package/backend/dist/src/llm-orchestration/llm-orchestration.module.js.map +1 -1
  116. package/backend/dist/src/llm-orchestration/llm-turn-processor.service.d.ts +9 -1
  117. package/backend/dist/src/llm-orchestration/llm-turn-processor.service.js +143 -5
  118. package/backend/dist/src/llm-orchestration/llm-turn-processor.service.js.map +1 -1
  119. package/backend/dist/src/llm-orchestration/tool-schema.service.d.ts +6 -1
  120. package/backend/dist/src/llm-orchestration/tool-schema.service.js +47 -8
  121. package/backend/dist/src/llm-orchestration/tool-schema.service.js.map +1 -1
  122. package/backend/dist/src/mcp/mcp.module.js +8 -4
  123. package/backend/dist/src/mcp/mcp.module.js.map +1 -1
  124. package/backend/dist/src/mcp/mcp.service.d.ts +3 -0
  125. package/backend/dist/src/mcp/mcp.service.js +9 -0
  126. package/backend/dist/src/mcp/mcp.service.js.map +1 -1
  127. package/backend/dist/src/mcp/session-mcp.controller.d.ts +11 -0
  128. package/backend/dist/src/mcp/session-mcp.controller.js +54 -0
  129. package/backend/dist/src/mcp/session-mcp.controller.js.map +1 -0
  130. package/backend/dist/src/mcp/session-mcp.service.d.ts +67 -0
  131. package/backend/dist/src/mcp/session-mcp.service.js +421 -0
  132. package/backend/dist/src/mcp/session-mcp.service.js.map +1 -0
  133. package/backend/dist/src/seeding/data/sub-agents/control-repoburg.js +4 -0
  134. package/backend/dist/src/seeding/data/sub-agents/control-repoburg.js.map +1 -1
  135. package/backend/dist/src/seeding/data/sub-agents/explore-codebase.js +4 -0
  136. package/backend/dist/src/seeding/data/sub-agents/explore-codebase.js.map +1 -1
  137. package/backend/dist/src/seeding/data/sub-agents/general-purpose.js +4 -0
  138. package/backend/dist/src/seeding/data/sub-agents/general-purpose.js.map +1 -1
  139. package/backend/dist/src/seeding/data/system-prompts/control-repoburg-agent.js +4 -0
  140. package/backend/dist/src/seeding/data/system-prompts/control-repoburg-agent.js.map +1 -1
  141. package/backend/dist/src/seeding/data/system-prompts/default_native_tool_agent.d.ts +1 -1
  142. package/backend/dist/src/seeding/data/system-prompts/default_native_tool_agent.js +8 -0
  143. package/backend/dist/src/seeding/data/system-prompts/default_native_tool_agent.js.map +1 -1
  144. package/backend/dist/src/seeding/data/system-prompts/explore-codebase-agent.d.ts +1 -1
  145. package/backend/dist/src/seeding/data/system-prompts/explore-codebase-agent.js +5 -1
  146. package/backend/dist/src/seeding/data/system-prompts/explore-codebase-agent.js.map +1 -1
  147. package/backend/dist/src/seeding/data/system-prompts/general-purpose-agent.d.ts +1 -1
  148. package/backend/dist/src/seeding/data/system-prompts/general-purpose-agent.js +7 -2
  149. package/backend/dist/src/seeding/data/system-prompts/general-purpose-agent.js.map +1 -1
  150. package/backend/dist/src/session-cancellation/session-cancellation.service.d.ts +5 -0
  151. package/backend/dist/src/session-cancellation/session-cancellation.service.js +20 -0
  152. package/backend/dist/src/session-cancellation/session-cancellation.service.js.map +1 -1
  153. package/backend/dist/src/session-event-logs/session-event-logs.service.d.ts +1 -0
  154. package/backend/dist/src/session-event-logs/session-event-logs.service.js +4 -0
  155. package/backend/dist/src/session-event-logs/session-event-logs.service.js.map +1 -1
  156. package/backend/dist/src/session-inputs/dto/session-input.dto.d.ts +1 -0
  157. package/backend/dist/src/session-inputs/dto/session-input.dto.js +10 -0
  158. package/backend/dist/src/session-inputs/dto/session-input.dto.js.map +1 -1
  159. package/backend/dist/src/session-inputs/session-input-context.service.d.ts +5 -2
  160. package/backend/dist/src/session-inputs/session-input-context.service.js +20 -4
  161. package/backend/dist/src/session-inputs/session-input-context.service.js.map +1 -1
  162. package/backend/dist/src/session-inputs/session-inputs.controller.js +3 -1
  163. package/backend/dist/src/session-inputs/session-inputs.controller.js.map +1 -1
  164. package/backend/dist/src/session-inputs/session-inputs.service.d.ts +8 -2
  165. package/backend/dist/src/session-inputs/session-inputs.service.js +43 -8
  166. package/backend/dist/src/session-inputs/session-inputs.service.js.map +1 -1
  167. package/backend/dist/src/sessions/sessions.controller.d.ts +2 -2
  168. package/backend/dist/src/sessions/sessions.controller.js.map +1 -1
  169. package/backend/dist/src/sessions/sessions.service.d.ts +4 -1
  170. package/backend/dist/src/sessions/sessions.service.js +5 -1
  171. package/backend/dist/src/sessions/sessions.service.js.map +1 -1
  172. package/backend/dist/src/slash-commands/slash-commands.controller.d.ts +1 -1
  173. package/backend/dist/src/slash-commands/slash-commands.controller.js +7 -3
  174. package/backend/dist/src/slash-commands/slash-commands.controller.js.map +1 -1
  175. package/backend/dist/src/slash-commands/slash-commands.module.js +2 -0
  176. package/backend/dist/src/slash-commands/slash-commands.module.js.map +1 -1
  177. package/backend/dist/src/slash-commands/slash-commands.service.d.ts +12 -4
  178. package/backend/dist/src/slash-commands/slash-commands.service.js +279 -65
  179. package/backend/dist/src/slash-commands/slash-commands.service.js.map +1 -1
  180. package/backend/dist/src/system-prompts/system-prompts.service.js +4 -0
  181. package/backend/dist/src/system-prompts/system-prompts.service.js.map +1 -1
  182. package/backend/dist/src/utils/pdf-text.d.ts +16 -0
  183. package/backend/dist/src/utils/pdf-text.js +27 -0
  184. package/backend/dist/src/utils/pdf-text.js.map +1 -0
  185. package/backend/dist/src/utils/tool-images.d.ts +10 -0
  186. package/backend/dist/src/utils/tool-images.js +55 -0
  187. package/backend/dist/src/utils/tool-images.js.map +1 -0
  188. package/backend/dist/tsconfig.build.tsbuildinfo +1 -1
  189. package/backend/package.json +1 -0
  190. package/package.json +3 -1
  191. package/tabtape/extension/dist/build-info.json +3 -3
  192. package/tabtape/extension/dist/manifest.json +1 -1
  193. package/tabtape/ui/dist/build-info.json +3 -3
  194. package/agent-pane/frontend/dist/assets/index-C1m0abtH.css +0 -1
  195. package/agent-pane/frontend/dist/assets/index-CjwvHfxy.js +0 -862
  196. package/backend/dist/src/application-state/dto/set-websocket-enabled.dto.d.ts +0 -3
  197. package/backend/dist/src/application-state/dto/set-websocket-enabled.dto.js +0 -23
  198. package/backend/dist/src/application-state/dto/set-websocket-enabled.dto.js.map +0 -1
@@ -7854,7 +7854,7 @@ var require_thread_stream = __commonJS({
7854
7854
  var { version: version2 } = require_package();
7855
7855
  var { EventEmitter: EventEmitter5 } = __require("events");
7856
7856
  var { Worker } = __require("worker_threads");
7857
- var { join: join6 } = __require("path");
7857
+ var { join: join7 } = __require("path");
7858
7858
  var { pathToFileURL } = __require("url");
7859
7859
  var { wait } = require_wait();
7860
7860
  var {
@@ -7905,7 +7905,7 @@ var require_thread_stream = __commonJS({
7905
7905
  function createWorker(stream, opts) {
7906
7906
  const { filename, workerData } = opts;
7907
7907
  const bundlerOverrides = "__bundlerPathsOverrides" in globalThis ? globalThis.__bundlerPathsOverrides : {};
7908
- const toExecute = bundlerOverrides["thread-stream-worker"] || join6(__dirname, "lib", "worker.js");
7908
+ const toExecute = bundlerOverrides["thread-stream-worker"] || join7(__dirname, "lib", "worker.js");
7909
7909
  const worker = new Worker(toExecute, {
7910
7910
  ...opts.workerOpts,
7911
7911
  name: opts.workerOpts?.name || "thread-stream",
@@ -8373,7 +8373,7 @@ var require_transport = __commonJS({
8373
8373
  var { createRequire } = __require("module");
8374
8374
  var { existsSync: existsSync3 } = __require("node:fs");
8375
8375
  var getCallers = require_caller();
8376
- var { join: join6, isAbsolute, sep } = __require("node:path");
8376
+ var { join: join7, isAbsolute: isAbsolute2, sep } = __require("node:path");
8377
8377
  var { fileURLToPath: fileURLToPath6 } = __require("node:url");
8378
8378
  var sleep2 = require_atomic_sleep();
8379
8379
  var onExit = require_on_exit_leak_free();
@@ -8445,7 +8445,7 @@ var require_transport = __commonJS({
8445
8445
  return false;
8446
8446
  }
8447
8447
  }
8448
- return isAbsolute(path21) && !existsSync3(path21);
8448
+ return isAbsolute2(path21) && !existsSync3(path21);
8449
8449
  }
8450
8450
  function stripQuotes(value) {
8451
8451
  const first = value[0];
@@ -8526,7 +8526,7 @@ var require_transport = __commonJS({
8526
8526
  throw new Error("only one of target or targets can be specified");
8527
8527
  }
8528
8528
  if (targets) {
8529
- target = bundlerOverrides["pino-worker"] || join6(__dirname, "worker.js");
8529
+ target = bundlerOverrides["pino-worker"] || join7(__dirname, "worker.js");
8530
8530
  options.targets = targets.filter((dest) => dest.target).map((dest) => {
8531
8531
  return {
8532
8532
  ...dest,
@@ -8544,7 +8544,7 @@ var require_transport = __commonJS({
8544
8544
  });
8545
8545
  });
8546
8546
  } else if (pipeline) {
8547
- target = bundlerOverrides["pino-worker"] || join6(__dirname, "worker.js");
8547
+ target = bundlerOverrides["pino-worker"] || join7(__dirname, "worker.js");
8548
8548
  options.pipelines = [pipeline.map((dest) => {
8549
8549
  return {
8550
8550
  ...dest,
@@ -8563,11 +8563,11 @@ var require_transport = __commonJS({
8563
8563
  return buildStream(fixTarget(target), options, worker, sync, name);
8564
8564
  function fixTarget(origin) {
8565
8565
  origin = bundlerOverrides[origin] || origin;
8566
- if (isAbsolute(origin) || origin.indexOf("file://") === 0) {
8566
+ if (isAbsolute2(origin) || origin.indexOf("file://") === 0) {
8567
8567
  return origin;
8568
8568
  }
8569
8569
  if (origin === "pino/file") {
8570
- return join6(__dirname, "..", "file.js");
8570
+ return join7(__dirname, "..", "file.js");
8571
8571
  }
8572
8572
  let fixTarget2;
8573
8573
  for (const filePath of callers) {
@@ -9547,7 +9547,7 @@ var require_safe_stable_stringify = __commonJS({
9547
9547
  return circularValue;
9548
9548
  }
9549
9549
  let res = "";
9550
- let join6 = ",";
9550
+ let join7 = ",";
9551
9551
  const originalIndentation = indentation;
9552
9552
  if (Array.isArray(value)) {
9553
9553
  if (value.length === 0) {
@@ -9561,7 +9561,7 @@ var require_safe_stable_stringify = __commonJS({
9561
9561
  indentation += spacer;
9562
9562
  res += `
9563
9563
  ${indentation}`;
9564
- join6 = `,
9564
+ join7 = `,
9565
9565
  ${indentation}`;
9566
9566
  }
9567
9567
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -9569,13 +9569,13 @@ ${indentation}`;
9569
9569
  for (; i < maximumValuesToStringify - 1; i++) {
9570
9570
  const tmp2 = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
9571
9571
  res += tmp2 !== void 0 ? tmp2 : "null";
9572
- res += join6;
9572
+ res += join7;
9573
9573
  }
9574
9574
  const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
9575
9575
  res += tmp !== void 0 ? tmp : "null";
9576
9576
  if (value.length - 1 > maximumBreadth) {
9577
9577
  const removedKeys = value.length - maximumBreadth - 1;
9578
- res += `${join6}"... ${getItemCount(removedKeys)} not stringified"`;
9578
+ res += `${join7}"... ${getItemCount(removedKeys)} not stringified"`;
9579
9579
  }
9580
9580
  if (spacer !== "") {
9581
9581
  res += `
@@ -9596,7 +9596,7 @@ ${originalIndentation}`;
9596
9596
  let separator = "";
9597
9597
  if (spacer !== "") {
9598
9598
  indentation += spacer;
9599
- join6 = `,
9599
+ join7 = `,
9600
9600
  ${indentation}`;
9601
9601
  whitespace = " ";
9602
9602
  }
@@ -9610,13 +9610,13 @@ ${indentation}`;
9610
9610
  const tmp = stringifyFnReplacer(key2, value, stack, replacer, spacer, indentation);
9611
9611
  if (tmp !== void 0) {
9612
9612
  res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
9613
- separator = join6;
9613
+ separator = join7;
9614
9614
  }
9615
9615
  }
9616
9616
  if (keyLength > maximumBreadth) {
9617
9617
  const removedKeys = keyLength - maximumBreadth;
9618
9618
  res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
9619
- separator = join6;
9619
+ separator = join7;
9620
9620
  }
9621
9621
  if (spacer !== "" && separator.length > 1) {
9622
9622
  res = `
@@ -9657,7 +9657,7 @@ ${originalIndentation}`;
9657
9657
  }
9658
9658
  const originalIndentation = indentation;
9659
9659
  let res = "";
9660
- let join6 = ",";
9660
+ let join7 = ",";
9661
9661
  if (Array.isArray(value)) {
9662
9662
  if (value.length === 0) {
9663
9663
  return "[]";
@@ -9670,7 +9670,7 @@ ${originalIndentation}`;
9670
9670
  indentation += spacer;
9671
9671
  res += `
9672
9672
  ${indentation}`;
9673
- join6 = `,
9673
+ join7 = `,
9674
9674
  ${indentation}`;
9675
9675
  }
9676
9676
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -9678,13 +9678,13 @@ ${indentation}`;
9678
9678
  for (; i < maximumValuesToStringify - 1; i++) {
9679
9679
  const tmp2 = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
9680
9680
  res += tmp2 !== void 0 ? tmp2 : "null";
9681
- res += join6;
9681
+ res += join7;
9682
9682
  }
9683
9683
  const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
9684
9684
  res += tmp !== void 0 ? tmp : "null";
9685
9685
  if (value.length - 1 > maximumBreadth) {
9686
9686
  const removedKeys = value.length - maximumBreadth - 1;
9687
- res += `${join6}"... ${getItemCount(removedKeys)} not stringified"`;
9687
+ res += `${join7}"... ${getItemCount(removedKeys)} not stringified"`;
9688
9688
  }
9689
9689
  if (spacer !== "") {
9690
9690
  res += `
@@ -9697,7 +9697,7 @@ ${originalIndentation}`;
9697
9697
  let whitespace = "";
9698
9698
  if (spacer !== "") {
9699
9699
  indentation += spacer;
9700
- join6 = `,
9700
+ join7 = `,
9701
9701
  ${indentation}`;
9702
9702
  whitespace = " ";
9703
9703
  }
@@ -9706,7 +9706,7 @@ ${indentation}`;
9706
9706
  const tmp = stringifyArrayReplacer(key2, value[key2], stack, replacer, spacer, indentation);
9707
9707
  if (tmp !== void 0) {
9708
9708
  res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
9709
- separator = join6;
9709
+ separator = join7;
9710
9710
  }
9711
9711
  }
9712
9712
  if (spacer !== "" && separator.length > 1) {
@@ -9764,20 +9764,20 @@ ${originalIndentation}`;
9764
9764
  indentation += spacer;
9765
9765
  let res2 = `
9766
9766
  ${indentation}`;
9767
- const join7 = `,
9767
+ const join8 = `,
9768
9768
  ${indentation}`;
9769
9769
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
9770
9770
  let i = 0;
9771
9771
  for (; i < maximumValuesToStringify - 1; i++) {
9772
9772
  const tmp2 = stringifyIndent(String(i), value[i], stack, spacer, indentation);
9773
9773
  res2 += tmp2 !== void 0 ? tmp2 : "null";
9774
- res2 += join7;
9774
+ res2 += join8;
9775
9775
  }
9776
9776
  const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
9777
9777
  res2 += tmp !== void 0 ? tmp : "null";
9778
9778
  if (value.length - 1 > maximumBreadth) {
9779
9779
  const removedKeys = value.length - maximumBreadth - 1;
9780
- res2 += `${join7}"... ${getItemCount(removedKeys)} not stringified"`;
9780
+ res2 += `${join8}"... ${getItemCount(removedKeys)} not stringified"`;
9781
9781
  }
9782
9782
  res2 += `
9783
9783
  ${originalIndentation}`;
@@ -9793,16 +9793,16 @@ ${originalIndentation}`;
9793
9793
  return '"[Object]"';
9794
9794
  }
9795
9795
  indentation += spacer;
9796
- const join6 = `,
9796
+ const join7 = `,
9797
9797
  ${indentation}`;
9798
9798
  let res = "";
9799
9799
  let separator = "";
9800
9800
  let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
9801
9801
  if (isTypedArrayWithEntries(value)) {
9802
- res += stringifyTypedArray(value, join6, maximumBreadth);
9802
+ res += stringifyTypedArray(value, join7, maximumBreadth);
9803
9803
  keys = keys.slice(value.length);
9804
9804
  maximumPropertiesToStringify -= value.length;
9805
- separator = join6;
9805
+ separator = join7;
9806
9806
  }
9807
9807
  if (deterministic) {
9808
9808
  keys = sort(keys, comparator);
@@ -9813,13 +9813,13 @@ ${indentation}`;
9813
9813
  const tmp = stringifyIndent(key2, value[key2], stack, spacer, indentation);
9814
9814
  if (tmp !== void 0) {
9815
9815
  res += `${separator}${strEscape(key2)}: ${tmp}`;
9816
- separator = join6;
9816
+ separator = join7;
9817
9817
  }
9818
9818
  }
9819
9819
  if (keyLength > maximumBreadth) {
9820
9820
  const removedKeys = keyLength - maximumBreadth;
9821
9821
  res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
9822
- separator = join6;
9822
+ separator = join7;
9823
9823
  }
9824
9824
  if (separator !== "") {
9825
9825
  res = `
@@ -41941,8 +41941,8 @@ function forkPoint(db2, sessionId, target) {
41941
41941
  return row?.external_turn_id ?? null;
41942
41942
  }
41943
41943
  function snapshotTurnIds(db2, sessionId) {
41944
- const rows = db2.prepare("SELECT id, external_turn_id FROM turns WHERE session_id = ? AND thread_id IS NULL").all(sessionId);
41945
- return JSON.stringify(Object.fromEntries(rows.map((r) => [r.id, r.external_turn_id])));
41944
+ const rows = db2.prepare("SELECT id, external_turn_id, runtime_input_ids FROM turns WHERE session_id = ? AND thread_id IS NULL").all(sessionId);
41945
+ return JSON.stringify(Object.fromEntries(rows.map((r) => [r.id, [r.external_turn_id, r.runtime_input_ids]])));
41946
41946
  }
41947
41947
  function restoreTurnIds(db2, sessionId, snapshot) {
41948
41948
  if (!snapshot) return;
@@ -41952,19 +41952,40 @@ function restoreTurnIds(db2, sessionId, snapshot) {
41952
41952
  } catch {
41953
41953
  return;
41954
41954
  }
41955
- const update = db2.prepare("UPDATE turns SET external_turn_id = ? WHERE id = ? AND session_id = ?");
41956
- for (const [turnId, externalId] of Object.entries(ids)) update.run(externalId, turnId, sessionId);
41955
+ const updateExternal = db2.prepare("UPDATE turns SET external_turn_id = ? WHERE id = ? AND session_id = ?");
41956
+ const updateBoth = db2.prepare(
41957
+ "UPDATE turns SET external_turn_id = ?, runtime_input_ids = ? WHERE id = ? AND session_id = ?"
41958
+ );
41959
+ for (const [turnId, value] of Object.entries(ids)) {
41960
+ if (Array.isArray(value)) updateBoth.run(value[0] ?? null, value[1] ?? null, turnId, sessionId);
41961
+ else updateExternal.run(value, turnId, sessionId);
41962
+ }
41963
+ }
41964
+ function forkedRuntimeInputIds(raw, map2) {
41965
+ if (!raw) return raw;
41966
+ let ids;
41967
+ try {
41968
+ ids = JSON.parse(raw);
41969
+ } catch {
41970
+ return raw;
41971
+ }
41972
+ if (!Array.isArray(ids)) return raw;
41973
+ return JSON.stringify(ids.map((id) => typeof id === "string" ? map2.get(id) ?? id : id));
41957
41974
  }
41958
41975
  function applyTurnIdMap(db2, sessionId, map2, upToCreatedAt = null) {
41959
41976
  if (map2.size === 0) return;
41960
41977
  const rows = db2.prepare(
41961
- `SELECT id, external_turn_id FROM turns
41962
- WHERE session_id = ? AND thread_id IS NULL AND external_turn_id IS NOT NULL` + (upToCreatedAt ? " AND created_at <= ?" : "")
41978
+ `SELECT id, external_turn_id, runtime_input_ids FROM turns
41979
+ WHERE session_id = ? AND thread_id IS NULL
41980
+ AND (external_turn_id IS NOT NULL OR runtime_input_ids IS NOT NULL)` + (upToCreatedAt ? " AND created_at <= ?" : "")
41963
41981
  ).all(...upToCreatedAt ? [sessionId, upToCreatedAt] : [sessionId]);
41964
- const update = db2.prepare("UPDATE turns SET external_turn_id = ? WHERE id = ?");
41982
+ const update = db2.prepare("UPDATE turns SET external_turn_id = ?, runtime_input_ids = ? WHERE id = ?");
41965
41983
  for (const row of rows) {
41966
- const mapped = map2.get(row.external_turn_id);
41967
- if (mapped) update.run(mapped, row.id);
41984
+ const externalId = (row.external_turn_id && map2.get(row.external_turn_id)) ?? row.external_turn_id;
41985
+ const inputIds = forkedRuntimeInputIds(row.runtime_input_ids, map2);
41986
+ if (externalId !== row.external_turn_id || inputIds !== row.runtime_input_ids) {
41987
+ update.run(externalId, inputIds, row.id);
41988
+ }
41968
41989
  }
41969
41990
  }
41970
41991
  function dropRewoundTurns(db2, sessionId) {
@@ -42543,8 +42564,8 @@ async function registerSessionRoutes(fastify) {
42543
42564
  for (const turn of turnRows) {
42544
42565
  const newTurnId = v4_default();
42545
42566
  db2.prepare(
42546
- `INSERT INTO turns (id, session_id, user_prompt, agent_response, thoughts, token_usage, external_turn_id, status, error, attachments, origin, origin_name, created_at, updated_at)
42547
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
42567
+ `INSERT INTO turns (id, session_id, user_prompt, agent_response, thoughts, token_usage, external_turn_id, runtime_input_ids, status, error, attachments, origin, origin_name, created_at, updated_at)
42568
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
42548
42569
  ).run(
42549
42570
  newTurnId,
42550
42571
  newSessionId,
@@ -42553,6 +42574,7 @@ async function registerSessionRoutes(fastify) {
42553
42574
  turn.thoughts,
42554
42575
  turn.token_usage,
42555
42576
  (turn.external_turn_id && turnIds.get(turn.external_turn_id)) ?? turn.external_turn_id,
42577
+ forkedRuntimeInputIds(turn.runtime_input_ids, turnIds),
42556
42578
  turn.status,
42557
42579
  turn.error,
42558
42580
  turn.attachments,
@@ -42787,7 +42809,7 @@ function recoverInterruptedTurns(db2, opts) {
42787
42809
  WHERE i.status = 'in_progress'`
42788
42810
  ).all();
42789
42811
  const orphaned = open.filter((i) => !skip.entries.has(runtimeEntryKey(i.session_id, i.thread_id)));
42790
- const stopTask3 = db2.prepare(
42812
+ const stopTask4 = db2.prepare(
42791
42813
  `UPDATE items SET data = json_set(COALESCE(data, '{}'), '$.status', 'stopped')
42792
42814
  WHERE id = ? AND json_valid(COALESCE(data, '{}'))`
42793
42815
  );
@@ -42795,7 +42817,7 @@ function recoverInterruptedTurns(db2, opts) {
42795
42817
  const items = { changes: 0 };
42796
42818
  db2.transaction(() => {
42797
42819
  for (const item of orphaned) {
42798
- if (item.type === "background_task") stopTask3.run(item.id);
42820
+ if (item.type === "background_task") stopTask4.run(item.id);
42799
42821
  items.changes += failItem.run(now, item.id).changes;
42800
42822
  }
42801
42823
  })();
@@ -43950,6 +43972,165 @@ async function registerProviderRoutes(fastify) {
43950
43972
  var InferenceCredentialsError = class extends Error {
43951
43973
  };
43952
43974
 
43975
+ // src/repoburg/backend-resolver.ts
43976
+ import path4 from "node:path";
43977
+ var RepoburgSignInRequiredError = class extends Error {
43978
+ constructor(projectPath) {
43979
+ super(
43980
+ `This machine is not signed in to Repoburg, so Repoburg cannot start in ${projectPath}. Sign in from the model picker (Repoburg), or run 'repoburg login'.`
43981
+ );
43982
+ this.projectPath = projectPath;
43983
+ this.name = "RepoburgSignInRequiredError";
43984
+ }
43985
+ code = "repoburg_sign_in_required";
43986
+ };
43987
+ var HEALTH_POLL_INTERVAL_MS = 1e3;
43988
+ var HEALTH_TIMEOUT_MS = 3e4;
43989
+ function daemonBaseUrl() {
43990
+ return (process.env.REPOBURG_DAEMON_URL || "http://localhost:9998").replace(/\/+$/, "");
43991
+ }
43992
+ var HttpError = class extends Error {
43993
+ constructor(status, body, url2) {
43994
+ super(`${url2} failed: ${status} ${body}`);
43995
+ this.status = status;
43996
+ this.body = body;
43997
+ this.url = url2;
43998
+ }
43999
+ };
44000
+ async function fetchJson(url2, init, timeoutMs = 5e3) {
44001
+ const controller = new AbortController();
44002
+ const timer3 = setTimeout(() => controller.abort(), timeoutMs);
44003
+ let response;
44004
+ try {
44005
+ response = await fetch(url2, { ...init, signal: controller.signal });
44006
+ } finally {
44007
+ clearTimeout(timer3);
44008
+ }
44009
+ const text2 = await response.text();
44010
+ if (!response.ok) {
44011
+ throw new HttpError(response.status, text2, url2);
44012
+ }
44013
+ try {
44014
+ return JSON.parse(text2);
44015
+ } catch {
44016
+ throw new Error(`Unexpected non-JSON response from ${url2}`);
44017
+ }
44018
+ }
44019
+ function daemonErrorMessage(err) {
44020
+ if (err instanceof HttpError) {
44021
+ try {
44022
+ const parsed = JSON.parse(err.body);
44023
+ return parsed.message || parsed.error || err.body;
44024
+ } catch {
44025
+ return err.body;
44026
+ }
44027
+ }
44028
+ return err.message;
44029
+ }
44030
+ var resolvedCache = /* @__PURE__ */ new Map();
44031
+ function invalidateBackend(baseUrl) {
44032
+ for (const [key, value] of resolvedCache) {
44033
+ if (value.baseUrl === baseUrl) resolvedCache.delete(key);
44034
+ }
44035
+ }
44036
+ async function backendHealthy(baseUrl, expectedPath) {
44037
+ try {
44038
+ const health = await fetchJson(`${baseUrl}/health`, void 0, 2e3);
44039
+ if (health.status !== "ok") return false;
44040
+ if (expectedPath && health.projectPath) {
44041
+ return path4.resolve(health.projectPath) === path4.resolve(expectedPath);
44042
+ }
44043
+ return true;
44044
+ } catch {
44045
+ return false;
44046
+ }
44047
+ }
44048
+ async function waitForHealthy(baseUrl, name, expectedPath) {
44049
+ const deadline = Date.now() + HEALTH_TIMEOUT_MS;
44050
+ while (Date.now() < deadline) {
44051
+ if (await backendHealthy(baseUrl, expectedPath)) return;
44052
+ await new Promise((resolve) => setTimeout(resolve, HEALTH_POLL_INTERVAL_MS));
44053
+ }
44054
+ throw new Error(
44055
+ `Backend '${name}' on ${baseUrl} did not become healthy within ${HEALTH_TIMEOUT_MS / 1e3}s. Check daemon logs: repoburg logs ${name}`
44056
+ );
44057
+ }
44058
+ function serviceBaseUrl(service) {
44059
+ return `http://localhost:${service.port}`;
44060
+ }
44061
+ function coveringService(services, absPath) {
44062
+ return services.filter((s) => absPath === s.path || absPath.startsWith(s.path + path4.sep)).sort((a, b) => b.path.length - a.path.length)[0];
44063
+ }
44064
+ async function restartService(daemon, name) {
44065
+ try {
44066
+ await fetchJson(`${daemon}/services/${name}/restart`, { method: "POST" });
44067
+ } catch (err) {
44068
+ throw new Error(`Daemon failed to restart backend '${name}': ${daemonErrorMessage(err)}`);
44069
+ }
44070
+ }
44071
+ async function startService(daemon, projectPath) {
44072
+ try {
44073
+ return await fetchJson(`${daemon}/services/start`, {
44074
+ method: "POST",
44075
+ headers: { "Content-Type": "application/json" },
44076
+ body: JSON.stringify({ path: projectPath })
44077
+ });
44078
+ } catch (err) {
44079
+ if (err instanceof HttpError && err.status === 401) throw new RepoburgSignInRequiredError(projectPath);
44080
+ throw new Error(`Daemon failed to start backend for ${projectPath}: ${daemonErrorMessage(err)}`);
44081
+ }
44082
+ }
44083
+ function cache(absPath, service) {
44084
+ const resolved = {
44085
+ baseUrl: serviceBaseUrl(service),
44086
+ port: service.port,
44087
+ name: service.name,
44088
+ servesPath: service.path
44089
+ };
44090
+ resolvedCache.set(absPath, resolved);
44091
+ return resolved;
44092
+ }
44093
+ async function resolveBackendUrl(projectPath, opts = {}) {
44094
+ const autoStart = opts.autoStart !== false;
44095
+ const envUrl = process.env.REPOBURG_BACKEND_URL;
44096
+ if (envUrl) {
44097
+ return { baseUrl: envUrl.replace(/\/+$/, ""), port: 0, name: "REPOBURG_BACKEND_URL" };
44098
+ }
44099
+ const absPath = path4.resolve(projectPath);
44100
+ const daemon = daemonBaseUrl();
44101
+ const cached3 = resolvedCache.get(absPath);
44102
+ if (cached3 && await backendHealthy(cached3.baseUrl, cached3.servesPath ?? absPath)) {
44103
+ return cached3;
44104
+ }
44105
+ try {
44106
+ await fetchJson(`${daemon}/health`, void 0, 3e3);
44107
+ } catch {
44108
+ throw new Error(
44109
+ `Repoburg daemon not reachable at ${daemon}. Start it with 'repoburg-daemon', or set REPOBURG_BACKEND_URL to a running backend.`
44110
+ );
44111
+ }
44112
+ const services = await fetchJson(`${daemon}/services`);
44113
+ const match = coveringService(services, absPath);
44114
+ if (match && match.status === "running") {
44115
+ if (await backendHealthy(serviceBaseUrl(match), match.path)) {
44116
+ return cache(absPath, match);
44117
+ }
44118
+ if (!autoStart) return null;
44119
+ await restartService(daemon, match.name);
44120
+ await waitForHealthy(serviceBaseUrl(match), match.name, match.path);
44121
+ return cache(absPath, match);
44122
+ }
44123
+ if (!autoStart) return null;
44124
+ if (match) {
44125
+ await restartService(daemon, match.name);
44126
+ await waitForHealthy(serviceBaseUrl(match), match.name, match.path);
44127
+ return cache(absPath, match);
44128
+ }
44129
+ const service = await startService(daemon, absPath);
44130
+ await waitForHealthy(serviceBaseUrl(service), service.name, absPath);
44131
+ return cache(absPath, service);
44132
+ }
44133
+
43953
44134
  // src/routes/models.ts
43954
44135
  function inferenceRuntime(id, reply) {
43955
44136
  const provider = hasProvider(id) ? getProvider(id) : void 0;
@@ -43963,6 +44144,9 @@ function sendInferenceError(reply, error51) {
43963
44144
  if (error51 instanceof InferenceCredentialsError) {
43964
44145
  return reply.code(400).send({ error: error51.message });
43965
44146
  }
44147
+ if (error51 instanceof RepoburgSignInRequiredError) {
44148
+ return reply.code(403).send({ error: error51.message, code: error51.code });
44149
+ }
43966
44150
  const message = error51 instanceof Error ? error51.message : String(error51);
43967
44151
  return reply.code(503).send({ error: message });
43968
44152
  }
@@ -44599,23 +44783,23 @@ import http from "node:http";
44599
44783
  import net from "node:net";
44600
44784
  import crypto from "node:crypto";
44601
44785
  import os3 from "node:os";
44602
- import path4 from "node:path";
44786
+ import path5 from "node:path";
44603
44787
  import { mkdir, readdir as readdir2, symlink, lstat, access, readFile, writeFile, unlink } from "node:fs/promises";
44604
- var VSCODE_WEB_DATA_DIR = path4.join(os3.homedir(), ".repoburg", "vscode-web");
44788
+ var VSCODE_WEB_DATA_DIR = path5.join(os3.homedir(), ".repoburg", "vscode-web");
44605
44789
  function resolveDesktopUserDir() {
44606
44790
  if (process.platform === "darwin") {
44607
- return path4.join(os3.homedir(), "Library", "Application Support", "Code", "User");
44791
+ return path5.join(os3.homedir(), "Library", "Application Support", "Code", "User");
44608
44792
  }
44609
44793
  if (process.platform === "win32" && process.env.APPDATA) {
44610
- return path4.join(process.env.APPDATA, "Code", "User");
44794
+ return path5.join(process.env.APPDATA, "Code", "User");
44611
44795
  }
44612
44796
  if (process.platform === "linux") {
44613
- return path4.join(os3.homedir(), ".config", "Code", "User");
44797
+ return path5.join(os3.homedir(), ".config", "Code", "User");
44614
44798
  }
44615
44799
  return null;
44616
44800
  }
44617
44801
  async function linkUnlessExists(src, dst) {
44618
- await mkdir(path4.dirname(dst), { recursive: true });
44802
+ await mkdir(path5.dirname(dst), { recursive: true });
44619
44803
  try {
44620
44804
  await lstat(dst);
44621
44805
  return false;
@@ -44630,19 +44814,19 @@ function fileRegistryUri(dir) {
44630
44814
  }
44631
44815
  async function syncProfile(dataDir = VSCODE_WEB_DATA_DIR) {
44632
44816
  try {
44633
- const desktopExt = path4.join(os3.homedir(), ".vscode", "extensions");
44817
+ const desktopExt = path5.join(os3.homedir(), ".vscode", "extensions");
44634
44818
  let entries;
44635
44819
  try {
44636
44820
  entries = await readdir2(desktopExt, { withFileTypes: true });
44637
44821
  } catch {
44638
44822
  return;
44639
44823
  }
44640
- const serverExt = path4.join(dataDir, "extensions");
44824
+ const serverExt = path5.join(dataDir, "extensions");
44641
44825
  const linkedFolders = [];
44642
44826
  for (const entry of entries) {
44643
44827
  if (!entry.isDirectory()) continue;
44644
- const target = path4.join(serverExt, entry.name);
44645
- await linkUnlessExists(path4.join(desktopExt, entry.name), target);
44828
+ const target = path5.join(serverExt, entry.name);
44829
+ await linkUnlessExists(path5.join(desktopExt, entry.name), target);
44646
44830
  const st = await lstat(target).catch(() => null);
44647
44831
  if (st?.isSymbolicLink()) linkedFolders.push(entry.name);
44648
44832
  }
@@ -44650,15 +44834,15 @@ async function syncProfile(dataDir = VSCODE_WEB_DATA_DIR) {
44650
44834
  await pruneObsolete(serverExt, linkedFolders);
44651
44835
  const desktopUser = resolveDesktopUserDir();
44652
44836
  if (!desktopUser) return;
44653
- const serverUser = path4.join(dataDir, "data", "User");
44837
+ const serverUser = path5.join(dataDir, "data", "User");
44654
44838
  for (const item of ["settings.json", "keybindings.json", "snippets"]) {
44655
- const src = path4.join(desktopUser, item);
44839
+ const src = path5.join(desktopUser, item);
44656
44840
  try {
44657
44841
  await access(src);
44658
44842
  } catch {
44659
44843
  continue;
44660
44844
  }
44661
- await linkUnlessExists(src, path4.join(serverUser, item));
44845
+ await linkUnlessExists(src, path5.join(serverUser, item));
44662
44846
  }
44663
44847
  } catch {
44664
44848
  }
@@ -44666,13 +44850,13 @@ async function syncProfile(dataDir = VSCODE_WEB_DATA_DIR) {
44666
44850
  async function mergeExtensionRegistry(desktopExt, serverExt, linkedFolders) {
44667
44851
  let desktopEntries = [];
44668
44852
  try {
44669
- desktopEntries = JSON.parse(await readFile(path4.join(desktopExt, "extensions.json"), "utf8"));
44853
+ desktopEntries = JSON.parse(await readFile(path5.join(desktopExt, "extensions.json"), "utf8"));
44670
44854
  } catch {
44671
44855
  return;
44672
44856
  }
44673
44857
  const linked = new Set(linkedFolders);
44674
44858
  const toAdd = desktopEntries.filter((e) => e.identifier?.id && linked.has(e.relativeLocation));
44675
- const serverRegistryPath = path4.join(serverExt, "extensions.json");
44859
+ const serverRegistryPath = path5.join(serverExt, "extensions.json");
44676
44860
  let serverEntries = [];
44677
44861
  try {
44678
44862
  serverEntries = JSON.parse(await readFile(serverRegistryPath, "utf8"));
@@ -44682,13 +44866,13 @@ async function mergeExtensionRegistry(desktopExt, serverExt, linkedFolders) {
44682
44866
  const additions = toAdd.filter((e) => !known.has(`${e.identifier.id.toLowerCase()}@${e.version}`));
44683
44867
  if (additions.length === 0) return;
44684
44868
  for (const entry of additions) {
44685
- const dir = path4.join(serverExt, entry.relativeLocation);
44869
+ const dir = path5.join(serverExt, entry.relativeLocation);
44686
44870
  serverEntries.push({ ...entry, location: fileRegistryUri(dir) });
44687
44871
  }
44688
44872
  await writeFile(serverRegistryPath, JSON.stringify(serverEntries));
44689
44873
  }
44690
44874
  async function pruneObsolete(serverExt, linkedFolders) {
44691
- const obsoletePath = path4.join(serverExt, ".obsolete");
44875
+ const obsoletePath = path5.join(serverExt, ".obsolete");
44692
44876
  let obsolete;
44693
44877
  try {
44694
44878
  obsolete = JSON.parse(await readFile(obsoletePath, "utf8"));
@@ -45147,15 +45331,15 @@ function proxyHandler(request, reply) {
45147
45331
 
45148
45332
  // src/routes/apps.ts
45149
45333
  import fs7 from "node:fs";
45150
- import path11 from "node:path";
45334
+ import path12 from "node:path";
45151
45335
 
45152
45336
  // src/apps/instances.ts
45153
45337
  import fs3 from "node:fs";
45154
- import path6 from "node:path";
45338
+ import path7 from "node:path";
45155
45339
 
45156
45340
  // src/apps/apps-registry.ts
45157
45341
  import fs2 from "node:fs";
45158
- import path5 from "node:path";
45342
+ import path6 from "node:path";
45159
45343
  import os4 from "node:os";
45160
45344
  import { fileURLToPath } from "node:url";
45161
45345
 
@@ -99380,10 +99564,10 @@ function setAppsRootOverride(root) {
99380
99564
  rootOverride = root;
99381
99565
  }
99382
99566
  function appsRoot() {
99383
- return rootOverride ?? process.env.AGENT_PANE_APPS_DIR ?? path5.join(os4.homedir(), ".repoburg", "agent-pane", "apps");
99567
+ return rootOverride ?? process.env.AGENT_PANE_APPS_DIR ?? path6.join(os4.homedir(), ".repoburg", "agent-pane", "apps");
99384
99568
  }
99385
99569
  function appDir(id) {
99386
- return path5.join(appsRoot(), id);
99570
+ return path6.join(appsRoot(), id);
99387
99571
  }
99388
99572
  var examplesRootOverride = null;
99389
99573
  function setExamplesRootOverride(root) {
@@ -99392,16 +99576,16 @@ function setExamplesRootOverride(root) {
99392
99576
  function examplesRoot() {
99393
99577
  if (examplesRootOverride) return examplesRootOverride;
99394
99578
  if (process.env.AGENT_PANE_EXAMPLES_DIR) return process.env.AGENT_PANE_EXAMPLES_DIR;
99395
- const here = path5.dirname(fileURLToPath(import.meta.url));
99396
- for (const candidate of [path5.resolve(here, "../../examples"), path5.resolve(here, "../../../examples")]) {
99579
+ const here = path6.dirname(fileURLToPath(import.meta.url));
99580
+ for (const candidate of [path6.resolve(here, "../../examples"), path6.resolve(here, "../../../examples")]) {
99397
99581
  if (fs2.existsSync(candidate)) return candidate;
99398
99582
  }
99399
99583
  return null;
99400
99584
  }
99401
99585
  function isInAppFolder(cwd) {
99402
99586
  if (!cwd) return false;
99403
- const rel = path5.relative(path5.resolve(appsRoot()), path5.resolve(cwd));
99404
- return rel !== "" && !path5.isAbsolute(rel) && rel.split(path5.sep)[0] !== "..";
99587
+ const rel = path6.relative(path6.resolve(appsRoot()), path6.resolve(cwd));
99588
+ return rel !== "" && !path6.isAbsolute(rel) && rel.split(path6.sep)[0] !== "..";
99405
99589
  }
99406
99590
  function appsConventions() {
99407
99591
  return APPS_MD_SKELETON;
@@ -99410,7 +99594,7 @@ function ensureAppsRoot() {
99410
99594
  const root = appsRoot();
99411
99595
  fs2.mkdirSync(root, { recursive: true });
99412
99596
  for (const name of ["CLAUDE.md", "AGENTS.md"]) {
99413
- const file2 = path5.join(root, name);
99597
+ const file2 = path6.join(root, name);
99414
99598
  try {
99415
99599
  if (fs2.existsSync(file2) && fs2.readFileSync(file2, "utf-8") === APPS_MD_FILE) continue;
99416
99600
  fs2.writeFileSync(file2, APPS_MD_FILE);
@@ -99675,7 +99859,7 @@ folder's own CLAUDE.md / AGENTS.md. -->
99675
99859
  ${APPS_MD_SKELETON}`;
99676
99860
  function readManifestIn(dir) {
99677
99861
  try {
99678
- const raw = fs2.readFileSync(path5.join(dir, "manifest.json"), "utf-8");
99862
+ const raw = fs2.readFileSync(path6.join(dir, "manifest.json"), "utf-8");
99679
99863
  const parsed = JSON.parse(raw);
99680
99864
  if (!parsed || typeof parsed.title !== "string") return null;
99681
99865
  return {
@@ -99702,7 +99886,7 @@ function readManifest(id) {
99702
99886
  }
99703
99887
  function readAppFile(id, name) {
99704
99888
  try {
99705
- return fs2.readFileSync(path5.join(appDir(id), name), "utf-8");
99889
+ return fs2.readFileSync(path6.join(appDir(id), name), "utf-8");
99706
99890
  } catch {
99707
99891
  return "";
99708
99892
  }
@@ -99735,11 +99919,11 @@ function startAppsWatch(onAppChange) {
99735
99919
  try {
99736
99920
  watcher = fs2.watch(root, { recursive: true }, (_event, filename) => {
99737
99921
  const rel = String(filename ?? "");
99738
- const segs = rel.split(path5.sep);
99922
+ const segs = rel.split(path6.sep);
99739
99923
  const appId = segs[0];
99740
99924
  const file2 = segs[segs.length - 1];
99741
- if (!appId || appId === path5.basename(root) || !APP_ID_RE.test(appId) || file2 === "state.json") return;
99742
- if (segs.length === 1 && isRegularFile(path5.join(root, appId))) return;
99925
+ if (!appId || appId === path6.basename(root) || !APP_ID_RE.test(appId) || file2 === "state.json") return;
99926
+ if (segs.length === 1 && isRegularFile(path6.join(root, appId))) return;
99743
99927
  const timer3 = pendingChanges.get(appId);
99744
99928
  if (timer3) clearTimeout(timer3);
99745
99929
  pendingChanges.set(
@@ -99810,7 +99994,7 @@ function getInstanceState(appId, workspace = "") {
99810
99994
  const stored = readRow(appId, workspace);
99811
99995
  if (stored) return stored;
99812
99996
  if (workspace === "") {
99813
- const legacyFile = path6.join(appDir(appId), "state.json");
99997
+ const legacyFile = path7.join(appDir(appId), "state.json");
99814
99998
  if (fs3.existsSync(legacyFile)) {
99815
99999
  const legacy = readState(appId);
99816
100000
  const imported = { pinned: legacy.pinned, data: legacy.data, version: 1 };
@@ -99843,9 +100027,9 @@ function resolveToolWorkspace(workspace) {
99843
100027
  const rows = getDb().prepare("SELECT path, deleted FROM workspaces").all();
99844
100028
  const active = rows.filter((w) => !w.deleted).map((w) => w.path);
99845
100029
  if (active.includes(workspace)) return workspace;
99846
- const cwd = path6.isAbsolute(workspace) ? path6.resolve(workspace) : "";
100030
+ const cwd = path7.isAbsolute(workspace) ? path7.resolve(workspace) : "";
99847
100031
  if (isInAppFolder(cwd)) return "";
99848
- const covering = rows.filter((w) => cwd === w.path || cwd.startsWith(w.path + path6.sep)).sort((a, b) => b.path.length - a.path.length)[0];
100032
+ const covering = rows.filter((w) => cwd === w.path || cwd.startsWith(w.path + path7.sep)).sort((a, b) => b.path.length - a.path.length)[0];
99849
100033
  if (covering && !covering.deleted) return covering.path;
99850
100034
  throw new Error(`Unknown workspace: ${workspace}. Known workspaces: ${active.join(", ") || "none"}`);
99851
100035
  }
@@ -99872,7 +100056,7 @@ function importAppInstances(appId, instances) {
99872
100056
  import fs5 from "node:fs";
99873
100057
 
99874
100058
  // src/apps/app-sessions.ts
99875
- import path8 from "node:path";
100059
+ import path9 from "node:path";
99876
100060
 
99877
100061
  // src/sidecar/transcript-locator.ts
99878
100062
  import { existsSync as existsSync2, readdirSync } from "node:fs";
@@ -99958,7 +100142,7 @@ function locateTranscriptCached(session) {
99958
100142
  import crypto2 from "node:crypto";
99959
100143
  import fs4 from "node:fs";
99960
100144
  import os5 from "node:os";
99961
- import path7 from "node:path";
100145
+ import path8 from "node:path";
99962
100146
  var APP_FILE_MAX_BYTES = 5 * 1024 * 1024;
99963
100147
  var APP_FILE_TYPES = {
99964
100148
  "image/png": "png",
@@ -99983,11 +100167,11 @@ function setAppFilesRootOverride(root) {
99983
100167
  rootOverride2 = root;
99984
100168
  }
99985
100169
  function appFilesRoot() {
99986
- return rootOverride2 ?? process.env.AGENT_PANE_APP_FILES_DIR ?? path7.join(os5.homedir(), ".repoburg", "agent-pane", "app-files");
100170
+ return rootOverride2 ?? process.env.AGENT_PANE_APP_FILES_DIR ?? path8.join(os5.homedir(), ".repoburg", "agent-pane", "app-files");
99987
100171
  }
99988
100172
  function appFilesDir(appId) {
99989
100173
  if (!APP_ID_RE.test(appId)) throw new AppFileError("Invalid app id", 400);
99990
- return path7.join(appFilesRoot(), appId);
100174
+ return path8.join(appFilesRoot(), appId);
99991
100175
  }
99992
100176
  function appFileUrl(appId, fileId) {
99993
100177
  return `/api/apps/${appId}/files/${fileId}`;
@@ -100048,7 +100232,7 @@ function saveAppFile(appId, upload) {
100048
100232
  const type = sniffImageType(bytes);
100049
100233
  if (!type) throw new AppFileError(`The file is not a ${ACCEPTED} image`, 400);
100050
100234
  const fileId = `${crypto2.createHash("sha256").update(bytes).digest("hex")}.${APP_FILE_TYPES[type]}`;
100051
- const file2 = path7.join(dir, fileId);
100235
+ const file2 = path8.join(dir, fileId);
100052
100236
  if (!fs4.existsSync(file2)) {
100053
100237
  fs4.mkdirSync(dir, { recursive: true });
100054
100238
  const tmp = `${file2}.${process.pid}.${crypto2.randomBytes(4).toString("hex")}.tmp`;
@@ -100080,7 +100264,7 @@ function getAppFile(appId, ref) {
100080
100264
  if (!APP_ID_RE.test(appId)) return null;
100081
100265
  const fileId = appFileRefId(appId, ref);
100082
100266
  if (!fileId) return null;
100083
- const file2 = path7.join(appFilesDir(appId), fileId);
100267
+ const file2 = path8.join(appFilesDir(appId), fileId);
100084
100268
  try {
100085
100269
  const stat2 = fs4.statSync(file2);
100086
100270
  if (!stat2.isFile()) return null;
@@ -100092,7 +100276,7 @@ function getAppFile(appId, ref) {
100092
100276
  function readAppFileData(appId, fileId) {
100093
100277
  if (!APP_ID_RE.test(appId) || !APP_FILE_ID_RE.test(fileId)) return null;
100094
100278
  try {
100095
- return { bytes: fs4.readFileSync(path7.join(appFilesDir(appId), fileId)), type: fileType(fileId) };
100279
+ return { bytes: fs4.readFileSync(path8.join(appFilesDir(appId), fileId)), type: fileType(fileId) };
100096
100280
  } catch {
100097
100281
  return null;
100098
100282
  }
@@ -100120,7 +100304,7 @@ function writeImportedAppFiles(appId, files) {
100120
100304
  const dir = appFilesDir(appId);
100121
100305
  fs4.mkdirSync(dir, { recursive: true });
100122
100306
  for (const [fileId, bytes] of files) {
100123
- const file2 = path7.join(dir, fileId);
100307
+ const file2 = path8.join(dir, fileId);
100124
100308
  if (!fs4.existsSync(file2)) fs4.writeFileSync(file2, bytes);
100125
100309
  }
100126
100310
  }
@@ -100225,7 +100409,7 @@ function appSessionInfo(appId, sessionId) {
100225
100409
  function sessionVisibleTo(session, appId, workspace) {
100226
100410
  if (!workspace) return true;
100227
100411
  const cwd = session.cwd;
100228
- if (cwd && (cwd === workspace || cwd.startsWith(workspace.endsWith(path8.sep) ? workspace : workspace + path8.sep))) {
100412
+ if (cwd && (cwd === workspace || cwd.startsWith(workspace.endsWith(path9.sep) ? workspace : workspace + path9.sep))) {
100229
100413
  return true;
100230
100414
  }
100231
100415
  return session.origin_app_workspace === workspace && openedByApp(session, appId);
@@ -100445,7 +100629,7 @@ function stopAppAlarms() {
100445
100629
 
100446
100630
  // src/apps/app-compile.ts
100447
100631
  import vm from "node:vm";
100448
- import path9 from "node:path";
100632
+ import path10 from "node:path";
100449
100633
  import ts from "typescript";
100450
100634
 
100451
100635
  // src/apps/app-lint.ts
@@ -100751,10 +100935,10 @@ declare const AgentPane: {
100751
100935
  fileUrl(ref: AgentPaneFileRef): string;
100752
100936
  };
100753
100937
  `;
100754
- var cache = /* @__PURE__ */ new Map();
100938
+ var cache2 = /* @__PURE__ */ new Map();
100755
100939
  function invalidateCompiledApp(appId) {
100756
- if (!appId) cache.clear();
100757
- else cache.delete(appId);
100940
+ if (!appId) cache2.clear();
100941
+ else cache2.delete(appId);
100758
100942
  }
100759
100943
  function tsDiagnosticToFile(file2, d) {
100760
100944
  if (!d.file) return null;
@@ -100874,15 +101058,15 @@ function typeCheckModules(appId, modules) {
100874
101058
  };
100875
101059
  const host = ts.createCompilerHost(options);
100876
101060
  const origReadFile = host.readFile.bind(host);
100877
- host.readFile = (fname) => path9.basename(fname) === BRIDGE_DTS_FILE ? BRIDGE_DTS : origReadFile(fname);
101061
+ host.readFile = (fname) => path10.basename(fname) === BRIDGE_DTS_FILE ? BRIDGE_DTS : origReadFile(fname);
100878
101062
  host.writeFile = () => {
100879
101063
  };
100880
- const bridgePath = path9.join(dir, BRIDGE_DTS_FILE);
100881
- const rootNames = [...modules.map((m) => path9.join(dir, m.file)), bridgePath];
101064
+ const bridgePath = path10.join(dir, BRIDGE_DTS_FILE);
101065
+ const rootNames = [...modules.map((m) => path10.join(dir, m.file)), bridgePath];
100882
101066
  const program = ts.createProgram(rootNames, options, host);
100883
101067
  const out = [];
100884
101068
  for (const mod of modules) {
100885
- const sf = program.getSourceFile(path9.join(dir, mod.file));
101069
+ const sf = program.getSourceFile(path10.join(dir, mod.file));
100886
101070
  if (!sf) continue;
100887
101071
  out.push(
100888
101072
  ...[...program.getSyntacticDiagnostics(sf), ...program.getSemanticDiagnostics(sf)].map((d) => tsDiagnosticToFile(mod.file, d)).filter((d) => d !== null)
@@ -100909,7 +101093,7 @@ function checkJsSyntax(js) {
100909
101093
  }
100910
101094
  }
100911
101095
  function compileAppJs(appId) {
100912
- const cached3 = cache.get(appId);
101096
+ const cached3 = cache2.get(appId);
100913
101097
  if (cached3) return cached3;
100914
101098
  const tsSource = readAppFile(appId, APP_TS);
100915
101099
  let result;
@@ -100957,7 +101141,7 @@ function compileAppJs(appId) {
100957
101141
  readManifest(appId)?.icon
100958
101142
  )
100959
101143
  );
100960
- cache.set(appId, result);
101144
+ cache2.set(appId, result);
100961
101145
  return result;
100962
101146
  }
100963
101147
 
@@ -101459,7 +101643,7 @@ function anyAppHasTools() {
101459
101643
 
101460
101644
  // src/apps/app-zip.ts
101461
101645
  import fs6 from "node:fs";
101462
- import path10 from "node:path";
101646
+ import path11 from "node:path";
101463
101647
 
101464
101648
  // src/apps/zip.ts
101465
101649
  import zlib from "node:zlib";
@@ -101631,7 +101815,7 @@ function collectAppFiles(id) {
101631
101815
  if (isSkipped(entry.name)) continue;
101632
101816
  const relPath = rel ? `${rel}/${entry.name}` : entry.name;
101633
101817
  if (!rel && entry.name === "state.json") continue;
101634
- const full = path10.join(dir, entry.name);
101818
+ const full = path11.join(dir, entry.name);
101635
101819
  if (entry.isDirectory()) walk(full, relPath);
101636
101820
  else if (entry.isFile()) out.push({ name: `${id}/${relPath}`, data: fs6.readFileSync(full) });
101637
101821
  }
@@ -101647,7 +101831,7 @@ function collectAppData(id) {
101647
101831
  for (const fileId of listAppFileIds(id)) {
101648
101832
  out.push({
101649
101833
  name: `${id}/${APP_DATA_DIR}/files/${fileId}`,
101650
- data: fs6.readFileSync(path10.join(appFilesDir(id), fileId))
101834
+ data: fs6.readFileSync(path11.join(appFilesDir(id), fileId))
101651
101835
  });
101652
101836
  }
101653
101837
  return out;
@@ -101674,7 +101858,7 @@ function parseAppData(entries) {
101674
101858
  const instances = doc.instances.map((item) => {
101675
101859
  const inst = item;
101676
101860
  const workspace = inst && typeof inst.workspace === "string" ? inst.workspace : null;
101677
- const valid = workspace !== null && (workspace === "" || path10.isAbsolute(workspace)) && !seen.has(workspace) && (inst.data === null || typeof inst.data === "object" && !Array.isArray(inst.data));
101861
+ const valid = workspace !== null && (workspace === "" || path11.isAbsolute(workspace)) && !seen.has(workspace) && (inst.data === null || typeof inst.data === "object" && !Array.isArray(inst.data));
101678
101862
  if (!valid) throw new AppZipError(`${APP_DATA_DIR}/data.json has an invalid instance`, 400);
101679
101863
  seen.add(workspace);
101680
101864
  return { workspace, pinned: inst.pinned === true, data: inst.data };
@@ -101763,7 +101947,7 @@ function rehomeInstances(data, id) {
101763
101947
  const newDir = appFilesDir(id);
101764
101948
  const oldDir = data.filesDir?.replace(/[\\/]+$/, "");
101765
101949
  if (oldDir && oldDir !== newDir) {
101766
- swaps.push([`${oldDir}/`, `${newDir}${path10.sep}`], [`${oldDir}\\`, `${newDir}${path10.sep}`]);
101950
+ swaps.push([`${oldDir}/`, `${newDir}${path11.sep}`], [`${oldDir}\\`, `${newDir}${path11.sep}`]);
101767
101951
  }
101768
101952
  if (swaps.length === 0) return data.instances;
101769
101953
  const replace = (s) => swaps.reduce((out, [from, to]) => out.split(from).join(to), s);
@@ -101777,15 +101961,15 @@ function importAppZip(id, buf, opts = {}) {
101777
101961
  if (readManifest(id) || fs6.existsSync(appDir(id))) throw new AppZipError("App already exists", 409);
101778
101962
  const withData = opts.data ? data : null;
101779
101963
  ensureAppsRoot();
101780
- const tmp = path10.join(appsRoot(), `.import-${v4_default()}`);
101964
+ const tmp = path11.join(appsRoot(), `.import-${v4_default()}`);
101781
101965
  try {
101782
101966
  for (const [rel, bytes] of files) {
101783
- const file2 = path10.join(tmp, ...rel.split("/"));
101784
- fs6.mkdirSync(path10.dirname(file2), { recursive: true });
101967
+ const file2 = path11.join(tmp, ...rel.split("/"));
101968
+ fs6.mkdirSync(path11.dirname(file2), { recursive: true });
101785
101969
  fs6.writeFileSync(file2, bytes);
101786
101970
  }
101787
101971
  if (!files.has("manifest.json")) {
101788
- fs6.writeFileSync(path10.join(tmp, "manifest.json"), JSON.stringify({ title: id }, null, 2));
101972
+ fs6.writeFileSync(path11.join(tmp, "manifest.json"), JSON.stringify({ title: id }, null, 2));
101789
101973
  } else if (!readManifestIn(tmp)) {
101790
101974
  throw new AppZipError('manifest.json is invalid (it needs at least a "title" string)', 400);
101791
101975
  }
@@ -101897,7 +102081,7 @@ async function registerAppRoutes(fastify, opts) {
101897
102081
  try {
101898
102082
  for (const entry of fs7.readdirSync(exRoot, { withFileTypes: true })) {
101899
102083
  if (!entry.isDirectory() || !APP_ID_RE.test(entry.name)) continue;
101900
- const manifest = readManifestIn(path11.join(exRoot, entry.name));
102084
+ const manifest = readManifestIn(path12.join(exRoot, entry.name));
101901
102085
  if (!manifest) continue;
101902
102086
  out.push({
101903
102087
  id: entry.name,
@@ -101918,7 +102102,7 @@ async function registerAppRoutes(fastify, opts) {
101918
102102
  if (!APP_ID_RE.test(id)) return reply.code(400).send({ error: "Invalid app id" });
101919
102103
  const exRoot = examplesRoot();
101920
102104
  if (!exRoot) return reply.code(404).send({ error: "Examples catalog not available" });
101921
- const src = path11.join(exRoot, id);
102105
+ const src = path12.join(exRoot, id);
101922
102106
  if (!readManifestIn(src)) return reply.code(404).send({ error: "Example not found" });
101923
102107
  if (readManifest(id)) return reply.code(409).send({ error: "App already installed" });
101924
102108
  ensureAppsRoot();
@@ -101957,7 +102141,7 @@ async function registerAppRoutes(fastify, opts) {
101957
102141
  fs7.mkdirSync(dir, { recursive: true });
101958
102142
  const cleanTitle2 = title.trim();
101959
102143
  fs7.writeFileSync(
101960
- path11.join(dir, "manifest.json"),
102144
+ path12.join(dir, "manifest.json"),
101961
102145
  JSON.stringify(
101962
102146
  {
101963
102147
  title: cleanTitle2,
@@ -101968,8 +102152,8 @@ async function registerAppRoutes(fastify, opts) {
101968
102152
  2
101969
102153
  )
101970
102154
  );
101971
- fs7.writeFileSync(path11.join(dir, "index.html"), SKELETON_HTML.replaceAll("__TITLE__", cleanTitle2));
101972
- fs7.writeFileSync(path11.join(dir, "app.ts"), SKELETON_TS);
102155
+ fs7.writeFileSync(path12.join(dir, "index.html"), SKELETON_HTML.replaceAll("__TITLE__", cleanTitle2));
102156
+ fs7.writeFileSync(path12.join(dir, "app.ts"), SKELETON_TS);
101973
102157
  return { ok: true, id };
101974
102158
  }
101975
102159
  );
@@ -102533,16 +102717,16 @@ async function loadFresh(timezone) {
102533
102717
  ]);
102534
102718
  return { data: parseCcusageJson(stdout), generatedAt: Date.now() };
102535
102719
  }
102536
- var cache2 = /* @__PURE__ */ new Map();
102720
+ var cache3 = /* @__PURE__ */ new Map();
102537
102721
  var inflight = /* @__PURE__ */ new Map();
102538
102722
  function loadCcusage(timezone, fresh) {
102539
- const cached3 = cache2.get(timezone);
102723
+ const cached3 = cache3.get(timezone);
102540
102724
  if (cached3 && !fresh) return Promise.resolve(cached3);
102541
102725
  let run = inflight.get(timezone);
102542
102726
  if (!run) {
102543
102727
  run = loadFresh(timezone).then((result) => {
102544
- if (cache2.size >= 4) cache2.clear();
102545
- cache2.set(timezone, result);
102728
+ if (cache3.size >= 4) cache3.clear();
102729
+ cache3.set(timezone, result);
102546
102730
  return result;
102547
102731
  }).finally(() => inflight.delete(timezone));
102548
102732
  inflight.set(timezone, run);
@@ -102947,7 +103131,7 @@ async function registerUsageRoutes(fastify) {
102947
103131
 
102948
103132
  // src/claude/session-import.ts
102949
103133
  import { readFile as readFile2, realpath } from "node:fs/promises";
102950
- import path12 from "node:path";
103134
+ import path13 from "node:path";
102951
103135
  import { getSessionInfo, listSessions } from "@anthropic-ai/claude-agent-sdk";
102952
103136
 
102953
103137
  // src/claude/widget-tool.ts
@@ -117992,7 +118176,7 @@ async function realDir(dir) {
117992
118176
  }
117993
118177
  }
117994
118178
  async function sameDir(a, realB) {
117995
- const realA = await realDir(a) ?? path12.resolve(a);
118179
+ const realA = await realDir(a) ?? path13.resolve(a);
117996
118180
  return realA === realB;
117997
118181
  }
117998
118182
  function knownClaudeSessionIds(db2) {
@@ -118162,22 +118346,22 @@ async function registerClaudeSessionRoutes(fastify) {
118162
118346
 
118163
118347
  // src/codex/session-import.ts
118164
118348
  import { realpath as realpath2 } from "node:fs/promises";
118165
- import path14 from "node:path";
118349
+ import path15 from "node:path";
118166
118350
 
118167
118351
  // src/apps/register-mcp.ts
118168
118352
  import fs8 from "node:fs";
118169
- import path13 from "node:path";
118353
+ import path14 from "node:path";
118170
118354
  import { fileURLToPath as fileURLToPath2 } from "node:url";
118171
118355
  var MCP_SERVER_NAME = "agentpane-miniapps";
118172
118356
  function panePublicUrl() {
118173
118357
  return (process.env.AGENT_PANE_PUBLIC_URL || process.env.REPOBURG_DAEMON_URL || "http://localhost:9998").replace(/\/+$/, "");
118174
118358
  }
118175
118359
  function stdioScriptPath() {
118176
- const here = path13.dirname(fileURLToPath2(import.meta.url));
118360
+ const here = path14.dirname(fileURLToPath2(import.meta.url));
118177
118361
  const candidates = [
118178
- path13.resolve(here, "../../scripts/miniapp-mcp-stdio.mjs"),
118362
+ path14.resolve(here, "../../scripts/miniapp-mcp-stdio.mjs"),
118179
118363
  // src/apps/ → backend/scripts
118180
- path13.resolve(here, "../scripts/miniapp-mcp-stdio.mjs")
118364
+ path14.resolve(here, "../scripts/miniapp-mcp-stdio.mjs")
118181
118365
  // dist bundle → backend/scripts
118182
118366
  ];
118183
118367
  for (const candidate of candidates) {
@@ -118436,7 +118620,7 @@ async function realDir2(dir) {
118436
118620
  async function workspaceDirs(workspacePath) {
118437
118621
  const real = await realDir2(workspacePath);
118438
118622
  if (!real) return null;
118439
- const given = path14.resolve(workspacePath);
118623
+ const given = path15.resolve(workspacePath);
118440
118624
  return given === real ? [real] : [given, real];
118441
118625
  }
118442
118626
  function titleOf2(thread) {
@@ -118676,7 +118860,7 @@ async function registerCodexSessionRoutes(fastify) {
118676
118860
 
118677
118861
  // src/session-host/flags.ts
118678
118862
  import fs9 from "node:fs";
118679
- import path15 from "node:path";
118863
+ import path16 from "node:path";
118680
118864
  var DEFAULT_FLAGS = {
118681
118865
  claude: true,
118682
118866
  codex: true,
@@ -118695,13 +118879,13 @@ function setPaneDataDir(dir) {
118695
118879
  }
118696
118880
  function sessionHostsRoot() {
118697
118881
  const override = process.env.AGENT_PANE_SESSION_HOSTS_DIR;
118698
- if (override) return path15.resolve(override);
118699
- return paneDataDir ? path15.join(paneDataDir, "session-hosts") : null;
118882
+ if (override) return path16.resolve(override);
118883
+ return paneDataDir ? path16.join(paneDataDir, "session-hosts") : null;
118700
118884
  }
118701
118885
  function flagsFilePath() {
118702
118886
  const root = sessionHostsRoot();
118703
- if (process.env.AGENT_PANE_SESSION_HOSTS_DIR) return path15.join(path15.dirname(root), "session-hosts.json");
118704
- return paneDataDir ? path15.join(paneDataDir, "session-hosts.json") : null;
118887
+ if (process.env.AGENT_PANE_SESSION_HOSTS_DIR) return path16.join(path16.dirname(root), "session-hosts.json");
118888
+ return paneDataDir ? path16.join(paneDataDir, "session-hosts.json") : null;
118705
118889
  }
118706
118890
  function readFlagFile(file2) {
118707
118891
  if (!file2) return {};
@@ -118773,7 +118957,7 @@ var LOG_HEADER_LEN = LOG_HEADER_PREFIX.length + LOG_HEADER_DIGITS + 1;
118773
118957
  // src/session-host/registry.ts
118774
118958
  import { randomBytes, randomUUID as randomUUID2 } from "node:crypto";
118775
118959
  import fs11 from "node:fs";
118776
- import path17 from "node:path";
118960
+ import path18 from "node:path";
118777
118961
  import { fileURLToPath as fileURLToPath4 } from "node:url";
118778
118962
 
118779
118963
  // src/session-host/client.ts
@@ -118781,7 +118965,7 @@ import { execFile as execFile3, spawn as spawn4 } from "node:child_process";
118781
118965
  import { EventEmitter as EventEmitter2 } from "node:events";
118782
118966
  import fs10 from "node:fs";
118783
118967
  import net2 from "node:net";
118784
- import path16 from "node:path";
118968
+ import path17 from "node:path";
118785
118969
  import { fileURLToPath as fileURLToPath3 } from "node:url";
118786
118970
  var HostRequestError = class extends Error {
118787
118971
  reply;
@@ -118793,11 +118977,11 @@ var HostRequestError = class extends Error {
118793
118977
  function hostScriptPath() {
118794
118978
  const override = process.env.AGENT_PANE_SESSION_HOST_SCRIPT;
118795
118979
  if (override) return override;
118796
- const here = path16.dirname(fileURLToPath3(import.meta.url));
118980
+ const here = path17.dirname(fileURLToPath3(import.meta.url));
118797
118981
  const candidates = [
118798
- path16.resolve(here, "../../scripts/session-host.mjs"),
118982
+ path17.resolve(here, "../../scripts/session-host.mjs"),
118799
118983
  // src/session-host/ → backend/scripts
118800
- path16.resolve(here, "../scripts/session-host.mjs")
118984
+ path17.resolve(here, "../scripts/session-host.mjs")
118801
118985
  // dist bundle → backend/scripts
118802
118986
  ];
118803
118987
  for (const candidate of candidates) {
@@ -118806,10 +118990,10 @@ function hostScriptPath() {
118806
118990
  return null;
118807
118991
  }
118808
118992
  function hostSocketPath(dir) {
118809
- const direct = path16.join(dir, "sock");
118993
+ const direct = path17.join(dir, "sock");
118810
118994
  if (Buffer.byteLength(direct) < 100) return direct;
118811
118995
  const uid = typeof process.getuid === "function" ? process.getuid() : 0;
118812
- return path16.join("/tmp", `rbsh-${uid}`, path16.basename(dir), "sock");
118996
+ return path17.join("/tmp", `rbsh-${uid}`, path17.basename(dir), "sock");
118813
118997
  }
118814
118998
  function readJson(file2) {
118815
118999
  try {
@@ -118819,10 +119003,10 @@ function readJson(file2) {
118819
119003
  }
118820
119004
  }
118821
119005
  function readHostExit(dir) {
118822
- return readJson(path16.join(dir, "exit.json"));
119006
+ return readJson(path17.join(dir, "exit.json"));
118823
119007
  }
118824
119008
  function readHostChild(dir) {
118825
- return readJson(path16.join(dir, "child.json"));
119009
+ return readJson(path17.join(dir, "child.json"));
118826
119010
  }
118827
119011
  function isPidAlive(pid) {
118828
119012
  if (!pid || pid <= 0) return false;
@@ -119012,7 +119196,7 @@ async function waitForHost(dir, timeoutMs = 1e4) {
119012
119196
  function readLogOldest(dir) {
119013
119197
  let fd = null;
119014
119198
  try {
119015
- fd = fs10.openSync(path16.join(dir, "out.log"), "r");
119199
+ fd = fs10.openSync(path17.join(dir, "out.log"), "r");
119016
119200
  const buf = Buffer.alloc(LOG_HEADER_LEN);
119017
119201
  const n = fs10.readSync(fd, buf, 0, LOG_HEADER_LEN, 0);
119018
119202
  const text2 = buf.subarray(0, n).toString("utf8");
@@ -119029,7 +119213,7 @@ function readHostLog(dir, after) {
119029
119213
  const oldest = readLogOldest(dir);
119030
119214
  if (oldest === null || after < oldest) return null;
119031
119215
  try {
119032
- const all = fs10.readFileSync(path16.join(dir, "out.log"));
119216
+ const all = fs10.readFileSync(path17.join(dir, "out.log"));
119033
119217
  const start = LOG_HEADER_LEN + (after - oldest);
119034
119218
  if (start > all.length) return null;
119035
119219
  return all.subarray(start);
@@ -119043,7 +119227,7 @@ function removeHostDir(dir) {
119043
119227
  } catch (err) {
119044
119228
  console.error(`[session-host] could not remove ${dir}:`, err.message);
119045
119229
  }
119046
- const alias = path16.dirname(hostSocketPath(dir));
119230
+ const alias = path17.dirname(hostSocketPath(dir));
119047
119231
  if (alias !== dir) {
119048
119232
  try {
119049
119233
  fs10.unlinkSync(alias);
@@ -119106,16 +119290,16 @@ function newHostDir() {
119106
119290
  const root = sessionHostsRoot();
119107
119291
  if (!root) throw new Error("session hosts have no directory");
119108
119292
  const id = randomBytes(8).toString("hex");
119109
- return { id, dir: path17.join(root, id) };
119293
+ return { id, dir: path18.join(root, id) };
119110
119294
  }
119111
119295
  var cachedVersion;
119112
119296
  function runtimeVersion() {
119113
119297
  if (cachedVersion !== void 0) return cachedVersion;
119114
119298
  cachedVersion = null;
119115
- const here = path17.dirname(fileURLToPath4(import.meta.url));
119299
+ const here = path18.dirname(fileURLToPath4(import.meta.url));
119116
119300
  for (const rel of ["../../../../package.json", "../../../package.json"]) {
119117
119301
  try {
119118
- const pkg = JSON.parse(fs11.readFileSync(path17.resolve(here, rel), "utf8"));
119302
+ const pkg = JSON.parse(fs11.readFileSync(path18.resolve(here, rel), "utf8"));
119119
119303
  if (pkg.name === "repoburg" && pkg.version) {
119120
119304
  cachedVersion = pkg.version;
119121
119305
  break;
@@ -119128,13 +119312,13 @@ function runtimeVersion() {
119128
119312
  function writeHostMeta(dir, meta3) {
119129
119313
  fs11.mkdirSync(dir, { recursive: true, mode: 448 });
119130
119314
  fs11.chmodSync(dir, 448);
119131
- const tmp = path17.join(dir, "meta.json.tmp");
119315
+ const tmp = path18.join(dir, "meta.json.tmp");
119132
119316
  fs11.writeFileSync(tmp, JSON.stringify(meta3, null, 2) + "\n", { mode: 384 });
119133
- fs11.renameSync(tmp, path17.join(dir, "meta.json"));
119317
+ fs11.renameSync(tmp, path18.join(dir, "meta.json"));
119134
119318
  }
119135
119319
  function readHostMeta(dir) {
119136
119320
  try {
119137
- return JSON.parse(fs11.readFileSync(path17.join(dir, "meta.json"), "utf8"));
119321
+ return JSON.parse(fs11.readFileSync(path18.join(dir, "meta.json"), "utf8"));
119138
119322
  } catch {
119139
119323
  return null;
119140
119324
  }
@@ -119279,7 +119463,7 @@ async function adoptHosts(db2, root, adoption, result) {
119279
119463
  const seen = /* @__PURE__ */ new Set();
119280
119464
  const queue = [];
119281
119465
  for (const id of entries) {
119282
- const dir = path17.join(root, id);
119466
+ const dir = path18.join(root, id);
119283
119467
  try {
119284
119468
  if (!fs11.statSync(dir).isDirectory()) continue;
119285
119469
  } catch {
@@ -119406,7 +119590,7 @@ async function shutDownAllHosts() {
119406
119590
  }
119407
119591
  await Promise.all(
119408
119592
  entries.map(async (id) => {
119409
- const dir = path17.join(root, id);
119593
+ const dir = path18.join(root, id);
119410
119594
  const row = db2 ? getHostRow(db2, id) : void 0;
119411
119595
  try {
119412
119596
  await shutDownHost(dir, { eof: row?.runtime === "codex" });
@@ -119877,7 +120061,7 @@ function mapTokenUsage(data) {
119877
120061
  import { spawn as spawn6 } from "node:child_process";
119878
120062
  import fs12 from "node:fs";
119879
120063
  import os6 from "node:os";
119880
- import path18 from "node:path";
120064
+ import path19 from "node:path";
119881
120065
  import { fileURLToPath as fileURLToPath5 } from "node:url";
119882
120066
  var TABTAPE_MCP_NAME = "tabtape";
119883
120067
  var PLAYWRIGHT_MCP_NAME = "playwright";
@@ -119891,15 +120075,15 @@ function disabled() {
119891
120075
  function tabtapeBaseUrl() {
119892
120076
  return (process.env.AGENT_PANE_TABTAPE_URL || `${sessionHostDaemonUrl()}/tabtape`).replace(/\/+$/, "");
119893
120077
  }
119894
- function playwrightMcpScript(from = path18.dirname(fileURLToPath5(import.meta.url))) {
120078
+ function playwrightMcpScript(from = path19.dirname(fileURLToPath5(import.meta.url))) {
119895
120079
  if (scriptOverride !== void 0) return scriptOverride;
119896
120080
  let dir = from;
119897
120081
  for (let i = 0; i < 6; i++) {
119898
- const script = path18.join(dir, "tabtape", "playwright", "mcp.mjs");
119899
- if (fs12.existsSync(script) && fs12.existsSync(path18.join(dir, "tabtape", "extension", "dist", "manifest.json"))) {
120082
+ const script = path19.join(dir, "tabtape", "playwright", "mcp.mjs");
120083
+ if (fs12.existsSync(script) && fs12.existsSync(path19.join(dir, "tabtape", "extension", "dist", "manifest.json"))) {
119900
120084
  return script;
119901
120085
  }
119902
- const parent = path18.dirname(dir);
120086
+ const parent = path19.dirname(dir);
119903
120087
  if (parent === dir) break;
119904
120088
  dir = parent;
119905
120089
  }
@@ -119941,14 +120125,17 @@ function jsonServerNames(file2, pick2) {
119941
120125
  }
119942
120126
  function claudeConfigFile() {
119943
120127
  if (process.env.AGENT_PANE_CLAUDE_CONFIG_FILE) return process.env.AGENT_PANE_CLAUDE_CONFIG_FILE;
119944
- return path18.join(process.env.CLAUDE_CONFIG_DIR || os6.homedir(), ".claude.json");
120128
+ return path19.join(process.env.CLAUDE_CONFIG_DIR || os6.homedir(), ".claude.json");
119945
120129
  }
119946
120130
  function claudeUserMcpNames(cwd) {
119947
120131
  const file2 = claudeConfigFile();
119948
120132
  return /* @__PURE__ */ new Set([
119949
120133
  ...jsonServerNames(file2, (json2) => json2.mcpServers),
119950
- ...jsonServerNames(file2, (json2) => json2.projects?.[cwd]?.mcpServers),
119951
- ...jsonServerNames(path18.join(cwd, ".mcp.json"), (json2) => json2.mcpServers)
120134
+ ...jsonServerNames(
120135
+ file2,
120136
+ (json2) => json2.projects?.[cwd]?.mcpServers
120137
+ ),
120138
+ ...jsonServerNames(path19.join(cwd, ".mcp.json"), (json2) => json2.mcpServers)
119952
120139
  ]);
119953
120140
  }
119954
120141
  async function claudeBrowserMcpServers(cwd) {
@@ -119971,8 +120158,11 @@ function tomlServerNames(file2) {
119971
120158
  return names;
119972
120159
  }
119973
120160
  function codexUserMcpNames(cwd) {
119974
- const home = process.env.CODEX_HOME || path18.join(os6.homedir(), ".codex");
119975
- return /* @__PURE__ */ new Set([...tomlServerNames(path18.join(home, "config.toml")), ...tomlServerNames(path18.join(cwd, ".codex", "config.toml"))]);
120161
+ const home = process.env.CODEX_HOME || path19.join(os6.homedir(), ".codex");
120162
+ return /* @__PURE__ */ new Set([
120163
+ ...tomlServerNames(path19.join(home, "config.toml")),
120164
+ ...tomlServerNames(path19.join(cwd, ".codex", "config.toml"))
120165
+ ]);
119976
120166
  }
119977
120167
  var CODEX_BROWSER_CHECK_INSTRUCTIONS = `Browser checks: when you check a change end-to-end in a browser, use the playwright MCP tools (a Chromium with the tabtape recorder) and record the check. Call the tabtape tool get_record_link (name: what you check, url: the first page), open its start link with browser_navigate, do the check, then open its stop link: that page shows the replay link, which you give the user. When a check fails, look into the recording with the tabtape tools before guessing. If recording does not work (the start page says "Nothing happened", or tabtape cannot be reached), carry on with the check and tell the user the recording failed.`;
119978
120168
  async function codexBrowserMcp(cwd) {
@@ -119997,15 +120187,29 @@ async function codexBrowserMcp(cwd) {
119997
120187
  }
119998
120188
  return { args, instructions: mcp.tabtape ? CODEX_BROWSER_CHECK_INSTRUCTIONS : null };
119999
120189
  }
120190
+ async function repoburgBrowserMcpServers(_cwd) {
120191
+ const mcp = await browserMcp(/* @__PURE__ */ new Set());
120192
+ const servers = [];
120193
+ if (mcp.tabtape) {
120194
+ servers.push({
120195
+ name: TABTAPE_MCP_NAME,
120196
+ type: "http",
120197
+ url: mcp.tabtape,
120198
+ instructions: CODEX_BROWSER_CHECK_INSTRUCTIONS
120199
+ });
120200
+ }
120201
+ if (mcp.playwright) servers.push({ name: PLAYWRIGHT_MCP_NAME, type: "stdio", ...mcp.playwright });
120202
+ return servers;
120203
+ }
120000
120204
  var prepared = false;
120001
120205
  function chromiumDownloadCommand(execPath = process.execPath) {
120002
- const bin = path18.dirname(execPath);
120003
- const npx = path18.join(bin, process.platform === "win32" ? "npx.cmd" : "npx");
120206
+ const bin = path19.dirname(execPath);
120207
+ const npx = path19.join(bin, process.platform === "win32" ? "npx.cmd" : "npx");
120004
120208
  if (!fs12.existsSync(npx)) return null;
120005
120209
  return {
120006
120210
  command: npx,
120007
120211
  args: ["-y", "@playwright/mcp@latest", "install-browser", "chromium"],
120008
- env: { ...process.env, PATH: [bin, process.env.PATH].filter(Boolean).join(path18.delimiter) }
120212
+ env: { ...process.env, PATH: [bin, process.env.PATH].filter(Boolean).join(path19.delimiter) }
120009
120213
  };
120010
120214
  }
120011
120215
  function prepareBrowserMcp() {
@@ -123377,25 +123581,25 @@ function upsertItem(db2, desc, sessionId, turnId, status, broadcastEvent) {
123377
123581
  }
123378
123582
  async function interruptTurn2(sessionId, threadId) {
123379
123583
  let entry;
123380
- let entryKey = null;
123584
+ let entryKey2 = null;
123381
123585
  if (threadId) {
123382
- entryKey = `${sessionId}:thread:${threadId}`;
123383
- entry = sessionMap2.get(entryKey);
123586
+ entryKey2 = `${sessionId}:thread:${threadId}`;
123587
+ entry = sessionMap2.get(entryKey2);
123384
123588
  } else {
123385
123589
  entry = sessionMap2.get(sessionId);
123386
- entryKey = sessionId;
123590
+ entryKey2 = sessionId;
123387
123591
  if (!entry || !entry.turnId) {
123388
- entryKey = null;
123592
+ entryKey2 = null;
123389
123593
  for (const [key, threadEntry] of sessionMap2) {
123390
123594
  if (key.startsWith(`${sessionId}:thread:`) && threadEntry.turnId) {
123391
123595
  entry = threadEntry;
123392
- entryKey = key;
123596
+ entryKey2 = key;
123393
123597
  break;
123394
123598
  }
123395
123599
  }
123396
123600
  }
123397
123601
  }
123398
- if (entry && entry.turnId && entryKey) {
123602
+ if (entry && entry.turnId && entryKey2) {
123399
123603
  const turnId = entry.turnId;
123400
123604
  try {
123401
123605
  await entry.query.interrupt();
@@ -123418,7 +123622,7 @@ async function interruptTurn2(sessionId, threadId) {
123418
123622
  entry.promptQueue.close();
123419
123623
  entry.query.close();
123420
123624
  streamingMessageIds.delete(turnId);
123421
- sessionMap2.delete(entryKey);
123625
+ sessionMap2.delete(entryKey2);
123422
123626
  dropBackgroundTasks(sessionId, entry);
123423
123627
  }
123424
123628
  }
@@ -124113,7 +124317,7 @@ var RepoburgHttpClient = class {
124113
124317
  return this.request("POST", "/sessions", dto);
124114
124318
  }
124115
124319
  async patchSession(id, dto) {
124116
- return this.request("PATCH", `/sessions/${id}`, dto);
124320
+ return this.request("PUT", `/sessions/${id}`, dto);
124117
124321
  }
124118
124322
  async getSession(id) {
124119
124323
  return this.request("GET", `/sessions/${id}`);
@@ -124122,19 +124326,13 @@ var RepoburgHttpClient = class {
124122
124326
  return this.request("POST", `/sessions/${sessionId}/inputs`, dto);
124123
124327
  }
124124
124328
  async getInputWithActions(sessionId, inputId) {
124125
- return this.request(
124126
- "GET",
124127
- `/sessions/${sessionId}/inputs/${inputId}/actions-with-logs`
124128
- );
124329
+ return this.request("GET", `/sessions/${sessionId}/inputs/${inputId}/actions-with-logs`);
124129
124330
  }
124130
124331
  async getSessionInputs(sessionId) {
124131
124332
  return this.request("GET", `/sessions/${sessionId}/inputs`);
124132
124333
  }
124133
124334
  async deleteInputsUntilHere(sessionId, anchorInputId) {
124134
- await this.request(
124135
- "DELETE",
124136
- `/sessions/${sessionId}/inputs/${anchorInputId}/until-here`
124137
- );
124335
+ await this.request("DELETE", `/sessions/${sessionId}/inputs/${anchorInputId}/until-here`);
124138
124336
  }
124139
124337
  async deleteSession(id) {
124140
124338
  await this.request("DELETE", `/sessions/${id}`);
@@ -124145,11 +124343,24 @@ var RepoburgHttpClient = class {
124145
124343
  });
124146
124344
  }
124147
124345
  async cancel(sessionId) {
124346
+ return this.request("POST", `/streaming/${sessionId}/cancel`);
124347
+ }
124348
+ async listBackgroundTasks(sessionId) {
124349
+ const result = await this.request(
124350
+ "GET",
124351
+ `/sessions/${sessionId}/background-tasks`
124352
+ );
124353
+ return result.tasks ?? [];
124354
+ }
124355
+ async stopBackgroundTask(sessionId, taskId) {
124148
124356
  return this.request(
124149
124357
  "POST",
124150
- `/streaming/${sessionId}/cancel`
124358
+ `/sessions/${sessionId}/background-tasks/${encodeURIComponent(taskId)}/stop`
124151
124359
  );
124152
124360
  }
124361
+ async setSessionMcpServers(sessionId, servers) {
124362
+ await this.request("PUT", `/sessions/${sessionId}/mcp-servers`, { servers });
124363
+ }
124153
124364
  async getModels() {
124154
124365
  const result = await this.request("GET", "/llm-provider/models");
124155
124366
  return result.models ?? [];
@@ -124179,154 +124390,6 @@ var RepoburgHttpClient = class {
124179
124390
  }
124180
124391
  };
124181
124392
 
124182
- // src/repoburg/backend-resolver.ts
124183
- import path19 from "node:path";
124184
- var HEALTH_POLL_INTERVAL_MS = 1e3;
124185
- var HEALTH_TIMEOUT_MS = 3e4;
124186
- function daemonBaseUrl() {
124187
- return (process.env.REPOBURG_DAEMON_URL || "http://localhost:9998").replace(/\/+$/, "");
124188
- }
124189
- var HttpError = class extends Error {
124190
- constructor(status, body, url2) {
124191
- super(`${url2} failed: ${status} ${body}`);
124192
- this.status = status;
124193
- this.body = body;
124194
- this.url = url2;
124195
- }
124196
- };
124197
- async function fetchJson(url2, init, timeoutMs = 5e3) {
124198
- const controller = new AbortController();
124199
- const timer3 = setTimeout(() => controller.abort(), timeoutMs);
124200
- let response;
124201
- try {
124202
- response = await fetch(url2, { ...init, signal: controller.signal });
124203
- } finally {
124204
- clearTimeout(timer3);
124205
- }
124206
- const text2 = await response.text();
124207
- if (!response.ok) {
124208
- throw new HttpError(response.status, text2, url2);
124209
- }
124210
- try {
124211
- return JSON.parse(text2);
124212
- } catch {
124213
- throw new Error(`Unexpected non-JSON response from ${url2}`);
124214
- }
124215
- }
124216
- function daemonErrorMessage(err) {
124217
- if (err instanceof HttpError) {
124218
- try {
124219
- const parsed = JSON.parse(err.body);
124220
- return parsed.message || parsed.error || err.body;
124221
- } catch {
124222
- return err.body;
124223
- }
124224
- }
124225
- return err.message;
124226
- }
124227
- var resolvedCache = /* @__PURE__ */ new Map();
124228
- function invalidateBackend(baseUrl) {
124229
- for (const [key, value] of resolvedCache) {
124230
- if (value.baseUrl === baseUrl) resolvedCache.delete(key);
124231
- }
124232
- }
124233
- async function backendHealthy(baseUrl, expectedPath) {
124234
- try {
124235
- const health = await fetchJson(`${baseUrl}/health`, void 0, 2e3);
124236
- if (health.status !== "ok") return false;
124237
- if (expectedPath && health.projectPath) {
124238
- return path19.resolve(health.projectPath) === path19.resolve(expectedPath);
124239
- }
124240
- return true;
124241
- } catch {
124242
- return false;
124243
- }
124244
- }
124245
- async function waitForHealthy(baseUrl, name, expectedPath) {
124246
- const deadline = Date.now() + HEALTH_TIMEOUT_MS;
124247
- while (Date.now() < deadline) {
124248
- if (await backendHealthy(baseUrl, expectedPath)) return;
124249
- await new Promise((resolve) => setTimeout(resolve, HEALTH_POLL_INTERVAL_MS));
124250
- }
124251
- throw new Error(
124252
- `Backend '${name}' on ${baseUrl} did not become healthy within ${HEALTH_TIMEOUT_MS / 1e3}s. Check daemon logs: repoburg logs ${name}`
124253
- );
124254
- }
124255
- function serviceBaseUrl(service) {
124256
- return `http://localhost:${service.port}`;
124257
- }
124258
- function coveringService(services, absPath) {
124259
- return services.filter((s) => absPath === s.path || absPath.startsWith(s.path + path19.sep)).sort((a, b) => b.path.length - a.path.length)[0];
124260
- }
124261
- async function restartService(daemon, name) {
124262
- try {
124263
- await fetchJson(`${daemon}/services/${name}/restart`, { method: "POST" });
124264
- } catch (err) {
124265
- throw new Error(`Daemon failed to restart backend '${name}': ${daemonErrorMessage(err)}`);
124266
- }
124267
- }
124268
- async function startService(daemon, projectPath) {
124269
- try {
124270
- return await fetchJson(`${daemon}/services/start`, {
124271
- method: "POST",
124272
- headers: { "Content-Type": "application/json" },
124273
- body: JSON.stringify({ path: projectPath })
124274
- });
124275
- } catch (err) {
124276
- throw new Error(`Daemon failed to start backend for ${projectPath}: ${daemonErrorMessage(err)}`);
124277
- }
124278
- }
124279
- function cache3(absPath, service) {
124280
- const resolved = {
124281
- baseUrl: serviceBaseUrl(service),
124282
- port: service.port,
124283
- name: service.name,
124284
- servesPath: service.path
124285
- };
124286
- resolvedCache.set(absPath, resolved);
124287
- return resolved;
124288
- }
124289
- async function resolveBackendUrl(projectPath, opts = {}) {
124290
- const autoStart = opts.autoStart !== false;
124291
- const envUrl = process.env.REPOBURG_BACKEND_URL;
124292
- if (envUrl) {
124293
- return { baseUrl: envUrl.replace(/\/+$/, ""), port: 0, name: "REPOBURG_BACKEND_URL" };
124294
- }
124295
- const absPath = path19.resolve(projectPath);
124296
- const daemon = daemonBaseUrl();
124297
- const cached3 = resolvedCache.get(absPath);
124298
- if (cached3 && await backendHealthy(cached3.baseUrl, cached3.servesPath ?? absPath)) {
124299
- return cached3;
124300
- }
124301
- try {
124302
- await fetchJson(`${daemon}/health`, void 0, 3e3);
124303
- } catch {
124304
- throw new Error(
124305
- `Repoburg daemon not reachable at ${daemon}. Start it with 'repoburg-daemon', or set REPOBURG_BACKEND_URL to a running backend.`
124306
- );
124307
- }
124308
- const services = await fetchJson(`${daemon}/services`);
124309
- const match = coveringService(services, absPath);
124310
- if (match && match.status === "running") {
124311
- if (await backendHealthy(serviceBaseUrl(match), match.path)) {
124312
- return cache3(absPath, match);
124313
- }
124314
- if (!autoStart) return null;
124315
- await restartService(daemon, match.name);
124316
- await waitForHealthy(serviceBaseUrl(match), match.name, match.path);
124317
- return cache3(absPath, match);
124318
- }
124319
- if (!autoStart) return null;
124320
- if (match) {
124321
- await restartService(daemon, match.name);
124322
- await waitForHealthy(serviceBaseUrl(match), match.name, match.path);
124323
- return cache3(absPath, match);
124324
- }
124325
- const service = await startService(daemon, absPath);
124326
- await waitForHealthy(serviceBaseUrl(service), service.name, absPath);
124327
- return cache3(absPath, service);
124328
- }
124329
-
124330
124393
  // src/repoburg/action-mapping.ts
124331
124394
  function parseJsonArgs(raw) {
124332
124395
  if (!raw) return null;
@@ -124709,6 +124772,96 @@ async function runThrowawayPrompt(client, options) {
124709
124772
  }
124710
124773
  }
124711
124774
 
124775
+ // src/repoburg/repoburg-tasks.ts
124776
+ import { readFileSync as readFileSync5 } from "node:fs";
124777
+ import { isAbsolute, join as join6 } from "node:path";
124778
+ var TASK_OUTPUT_MAX2 = 2e4;
124779
+ var REPOBURG_TASK_TYPE = "background_terminal";
124780
+ var NOT_BACKGROUND_COMMAND = `NOT (type = 'background_task' AND json_valid(COALESCE(data, '{}'))
124781
+ AND json_extract(data, '$.task_type') = '${REPOBURG_TASK_TYPE}')`;
124782
+ function taskItemExternalId(taskId) {
124783
+ return `task-${taskId}`;
124784
+ }
124785
+ function taskOutputPath(outputFile, cwd) {
124786
+ if (!outputFile) return null;
124787
+ if (isAbsolute(outputFile)) return outputFile;
124788
+ return cwd ? join6(cwd, outputFile) : null;
124789
+ }
124790
+ function readTaskOutput(path21) {
124791
+ if (!path21) return "";
124792
+ try {
124793
+ const text2 = readFileSync5(path21, "utf-8");
124794
+ return text2.length > TASK_OUTPUT_MAX2 ? text2.slice(-TASK_OUTPUT_MAX2) : text2;
124795
+ } catch {
124796
+ return "";
124797
+ }
124798
+ }
124799
+ function findTaskItem2(db2, sessionId, taskId) {
124800
+ return db2.prepare(
124801
+ `SELECT i.* FROM items i JOIN turns t ON t.id = i.turn_id
124802
+ WHERE t.session_id = ? AND i.external_item_id = ? AND i.type = 'background_task'
124803
+ ORDER BY i.created_at DESC LIMIT 1`
124804
+ ).get(sessionId, taskItemExternalId(taskId));
124805
+ }
124806
+ function openTaskItem2(db2, sessionId, turnId, task) {
124807
+ if (findTaskItem2(db2, sessionId, task.task_id)) return;
124808
+ insertItem(
124809
+ db2,
124810
+ sessionId,
124811
+ turnId,
124812
+ taskItemExternalId(task.task_id),
124813
+ "background_task",
124814
+ {
124815
+ task_id: task.task_id,
124816
+ description: task.description,
124817
+ task_type: REPOBURG_TASK_TYPE,
124818
+ subagent_type: null,
124819
+ prompt: task.command,
124820
+ status: "running",
124821
+ summary: null,
124822
+ output_file: task.output_file,
124823
+ output: "",
124824
+ token_count: null,
124825
+ last_tool_name: null
124826
+ },
124827
+ "in_progress",
124828
+ "item:started"
124829
+ );
124830
+ }
124831
+ function updateTaskItem(db2, sessionId, taskId, update) {
124832
+ const row = findTaskItem2(db2, sessionId, taskId);
124833
+ if (!row) return false;
124834
+ if (row.status !== "in_progress") return true;
124835
+ const prev = row.data ? JSON.parse(row.data) : {};
124836
+ const output = readTaskOutput(prev.output_file ?? null) || String(prev.output ?? "");
124837
+ const ended = update.status !== "running";
124838
+ if (!ended && output === prev.output) return true;
124839
+ const data = {
124840
+ ...prev,
124841
+ status: update.status,
124842
+ output,
124843
+ ...update.summary !== void 0 ? { summary: update.summary } : {},
124844
+ ...update.exit_code !== void 0 ? { exit_code: update.exit_code } : {}
124845
+ };
124846
+ const status = !ended ? "in_progress" : update.status === "failed" ? "failed" : "completed";
124847
+ const item = { ...row, data: prev };
124848
+ updateItem(db2, sessionId, row.turn_id, item, data, status);
124849
+ return true;
124850
+ }
124851
+ function taskSummary(task) {
124852
+ const name = `Background command "${task.description}"`;
124853
+ switch (task.status) {
124854
+ case "completed":
124855
+ return `${name} completed (exit code 0)`;
124856
+ case "stopped":
124857
+ return `${name} was stopped`;
124858
+ case "failed":
124859
+ return task.exit_code === null ? `${name} was killed` : `${name} failed with exit code ${task.exit_code}`;
124860
+ default:
124861
+ return `${name} is running`;
124862
+ }
124863
+ }
124864
+
124712
124865
  // src/repoburg/turn-projector.ts
124713
124866
  var RESULT_TIMEOUT_MS = 15 * 6e4;
124714
124867
  var MAX_RESULT_EXTENSIONS = 3;
@@ -124744,6 +124897,8 @@ var TurnProjector = class {
124744
124897
  switch (message.type) {
124745
124898
  case "system":
124746
124899
  if (message.subtype === "compact_boundary") this.handleCompactBoundary(message);
124900
+ else if (message.subtype === "task_started") this.handleTaskStarted(message);
124901
+ else if (message.subtype === "task_notification") this.handleTaskNotification(message);
124747
124902
  break;
124748
124903
  case "stream_event":
124749
124904
  this.handleStreamEvent(message);
@@ -125073,6 +125228,27 @@ var TurnProjector = class {
125073
125228
  }
125074
125229
  this.touch();
125075
125230
  }
125231
+ /** A background task started in this turn → its background_task item. */
125232
+ handleTaskStarted(msg) {
125233
+ openTaskItem2(getDb(), this.deps.agentPaneSessionId, this.deps.turnId, {
125234
+ task_id: msg.task_id,
125235
+ description: msg.description,
125236
+ command: msg.command,
125237
+ output_file: taskOutputPath(msg.output_file, this.deps.cwd)
125238
+ });
125239
+ this.deps.onTaskEvent?.(msg);
125240
+ this.touch();
125241
+ }
125242
+ /** A background task ended — maybe one an earlier turn started. */
125243
+ handleTaskNotification(msg) {
125244
+ updateTaskItem(getDb(), this.deps.agentPaneSessionId, msg.task_id, {
125245
+ status: msg.status,
125246
+ summary: msg.summary,
125247
+ exit_code: msg.exit_code
125248
+ });
125249
+ this.deps.onTaskEvent?.(msg);
125250
+ this.touch();
125251
+ }
125076
125252
  handleResult(msg) {
125077
125253
  switch (msg.subtype) {
125078
125254
  case "success":
@@ -125237,12 +125413,9 @@ var TurnProjector = class {
125237
125413
  closeOpenItems(status) {
125238
125414
  const db2 = getDb();
125239
125415
  const now = (/* @__PURE__ */ new Date()).toISOString();
125240
- db2.prepare("UPDATE items SET status = ?, updated_at = ? WHERE turn_id = ? AND status = ?").run(
125241
- status,
125242
- now,
125243
- this.deps.turnId,
125244
- "in_progress"
125245
- );
125416
+ db2.prepare(
125417
+ `UPDATE items SET status = ?, updated_at = ? WHERE turn_id = ? AND status = ? AND ${NOT_BACKGROUND_COMMAND}`
125418
+ ).run(status, now, this.deps.turnId, "in_progress");
125246
125419
  }
125247
125420
  // -------------------------------------------------------------------------
125248
125421
  // Watch-dog + snapshot reconcile
@@ -125419,9 +125592,10 @@ async function ensureSession(session, client, baseUrl) {
125419
125592
  repoburgSessionId: session.external_thread_id,
125420
125593
  client,
125421
125594
  baseUrl,
125422
- modelId: session.model || null,
125423
- // undefined forces a re-push on the next turn — heals sessions created
125595
+ // undefined forces a re-push of model and effort on the next turn —
125596
+ // heals switches made while the pane was down, and sessions created
125424
125597
  // before unsafe effort values (e.g. ollama xhigh) were clamped.
125598
+ modelId: void 0,
125425
125599
  reasoningEffort: void 0,
125426
125600
  threadId: null,
125427
125601
  contextWindow: null,
@@ -125466,6 +125640,7 @@ async function ensureThreadSession(session, turn, client, baseUrl) {
125466
125640
  const db2 = getDb();
125467
125641
  const thread = db2.prepare("SELECT external_thread_id FROM discussion_threads WHERE id = ?").get(turn.thread_id);
125468
125642
  let runtimeId = thread?.external_thread_id ?? null;
125643
+ const forked = !!runtimeId;
125469
125644
  if (!runtimeId) {
125470
125645
  const created = await client.createSession({
125471
125646
  session_title: session.title ? `Discussion: ${session.title}` : "Discussion",
@@ -125485,7 +125660,7 @@ async function ensureThreadSession(session, turn, client, baseUrl) {
125485
125660
  repoburgSessionId: runtimeId,
125486
125661
  client,
125487
125662
  baseUrl,
125488
- modelId: session.model || null,
125663
+ modelId: forked ? void 0 : session.model || null,
125489
125664
  reasoningEffort: void 0,
125490
125665
  // re-pushed on the first thread turn
125491
125666
  threadId: turn.thread_id,
@@ -125536,12 +125711,9 @@ function failTurn3(entry, error51) {
125536
125711
  now,
125537
125712
  active.turnId
125538
125713
  );
125539
- db2.prepare("UPDATE items SET status = ?, updated_at = ? WHERE turn_id = ? AND status = ?").run(
125540
- "failed",
125541
- now,
125542
- active.turnId,
125543
- "in_progress"
125544
- );
125714
+ db2.prepare(
125715
+ `UPDATE items SET status = ?, updated_at = ? WHERE turn_id = ? AND status = ? AND ${NOT_BACKGROUND_COMMAND}`
125716
+ ).run("failed", now, active.turnId, "in_progress");
125545
125717
  recomputeSessionRunning(db2, entry.agentPaneSessionId, "failed");
125546
125718
  broadcast("turn:failed", { sessionId: entry.agentPaneSessionId, turnId: active.turnId, error: error51 });
125547
125719
  }
@@ -125670,6 +125842,16 @@ async function startTurn4(session, turn) {
125670
125842
  entry.baseUrl = baseUrl;
125671
125843
  entry.client = client;
125672
125844
  }
125845
+ startingEntries.add(entry);
125846
+ try {
125847
+ await runTurn2(session, turn, entry, firstInput);
125848
+ } finally {
125849
+ startingEntries.delete(entry);
125850
+ }
125851
+ }
125852
+ async function runTurn2(session, turn, entry, firstInput) {
125853
+ const db2 = getDb();
125854
+ await syncSessionMcp(entry, session.cwd ?? process.cwd());
125673
125855
  const wantedModel = session.model || null;
125674
125856
  const wantedEffort = mapReasoningEffort(session.model_reasoning_effort);
125675
125857
  if (wantedModel !== entry.modelId || wantedEffort !== entry.reasoningEffort) {
@@ -125689,7 +125871,11 @@ async function startTurn4(session, turn) {
125689
125871
  db2.prepare("UPDATE turns SET status = ?, updated_at = ? WHERE id = ?").run("running", now, turn.id);
125690
125872
  setSessionStatus3(db2, session.id, 1, "running", now);
125691
125873
  broadcast("turn:started", { sessionId: session.id, turnId: turn.id });
125692
- const state = await getAgentRuntimeState(entry.baseUrl, entry.repoburgSessionId).catch(() => null);
125874
+ let state = await getAgentRuntimeState(entry.baseUrl, entry.repoburgSessionId).catch(() => null);
125875
+ if (state?.turnInFlight && !(entry.activeTurn && !entry.activeTurn.projector.isDone)) {
125876
+ await entry.client.cancel(entry.repoburgSessionId).catch(() => void 0);
125877
+ state = await waitForRunEnd(entry, RUN_END_WAIT_MS) ?? state;
125878
+ }
125693
125879
  if (state) {
125694
125880
  const cursor = {
125695
125881
  bootId: state.bootId,
@@ -125707,7 +125893,10 @@ async function startTurn4(session, turn) {
125707
125893
  // Late-bound — the window resolves from the runtime catalog while the
125708
125894
  // turn streams and is read at turn completion.
125709
125895
  getContextWindow: () => entry.contextWindow,
125710
- ...state ? { firstSeq: state.lastSeq + 1 } : {}
125896
+ ...state ? { firstSeq: state.lastSeq + 1 } : {},
125897
+ cwd: session.cwd ?? null,
125898
+ onTaskEvent: (message) => onTaskEvent(entry, message),
125899
+ onFinished: () => onTurnFinished(entry)
125711
125900
  });
125712
125901
  entry.activeTurn = {
125713
125902
  turnId: turn.id,
@@ -125736,6 +125925,245 @@ async function startTurn4(session, turn) {
125736
125925
  failTurn3(entry, err.message);
125737
125926
  }
125738
125927
  }
125928
+ var TASK_POLL_MS = 2e3;
125929
+ var WAKE_WATCH_MS = 2e4;
125930
+ var RUN_END_WAIT_MS = 1e4;
125931
+ var taskStates = /* @__PURE__ */ new WeakMap();
125932
+ var startingEntries = /* @__PURE__ */ new Set();
125933
+ var publishedTasks = /* @__PURE__ */ new Map();
125934
+ function taskStateOf(entry) {
125935
+ let state = taskStates.get(entry);
125936
+ if (!state) {
125937
+ state = { running: /* @__PURE__ */ new Map(), timer: null, polling: false, watchUntil: 0 };
125938
+ taskStates.set(entry, state);
125939
+ }
125940
+ return state;
125941
+ }
125942
+ function taskPollMs2() {
125943
+ const fromEnv = Number(process.env.AGENT_PANE_REPOBURG_TASK_POLL_MS);
125944
+ return Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : TASK_POLL_MS;
125945
+ }
125946
+ function sessionCwd(sessionId) {
125947
+ try {
125948
+ const row = getDb().prepare("SELECT cwd FROM sessions WHERE id = ?").get(sessionId);
125949
+ return row?.cwd ?? null;
125950
+ } catch {
125951
+ return null;
125952
+ }
125953
+ }
125954
+ function entryKey(entry) {
125955
+ return entry.threadId ? `${entry.agentPaneSessionId}:thread:${entry.threadId}` : entry.agentPaneSessionId;
125956
+ }
125957
+ function onTaskEvent(entry, message) {
125958
+ const state = taskStateOf(entry);
125959
+ if (message.subtype === "task_started") {
125960
+ state.running.set(message.task_id, {
125961
+ task_id: message.task_id,
125962
+ task_type: REPOBURG_TASK_TYPE,
125963
+ description: message.description
125964
+ });
125965
+ } else {
125966
+ state.running.delete(message.task_id);
125967
+ state.watchUntil = Date.now() + WAKE_WATCH_MS;
125968
+ }
125969
+ publishTasks2(entry.agentPaneSessionId);
125970
+ ensureTaskPolling(entry);
125971
+ }
125972
+ function onTurnFinished(entry) {
125973
+ const state = taskStates.get(entry);
125974
+ if (!state) return;
125975
+ state.watchUntil = Math.max(state.watchUntil, Date.now() + WAKE_WATCH_MS);
125976
+ ensureTaskPolling(entry);
125977
+ }
125978
+ function sessionTasks(sessionId) {
125979
+ const tasks = [];
125980
+ for (const [key, entry] of sessionMap3) {
125981
+ if (key !== sessionId && !key.startsWith(`${sessionId}:thread:`)) continue;
125982
+ const state = taskStates.get(entry);
125983
+ if (state) tasks.push(...state.running.values());
125984
+ }
125985
+ return tasks;
125986
+ }
125987
+ function publishTasks2(sessionId) {
125988
+ const tasks = sessionTasks(sessionId);
125989
+ const json2 = JSON.stringify(tasks);
125990
+ if ((publishedTasks.get(sessionId) ?? "[]") === json2) return;
125991
+ if (tasks.length > 0) publishedTasks.set(sessionId, json2);
125992
+ else publishedTasks.delete(sessionId);
125993
+ broadcast("background_tasks", { sessionId, tasks });
125994
+ }
125995
+ function ensureTaskPolling(entry) {
125996
+ const state = taskStateOf(entry);
125997
+ if (state.timer || !entry.client.listBackgroundTasks) return;
125998
+ if (state.running.size === 0 && Date.now() >= state.watchUntil) return;
125999
+ state.timer = setInterval(() => void pollTasks(entry), taskPollMs2());
126000
+ state.timer.unref?.();
126001
+ }
126002
+ function stopTaskPolling2(entry) {
126003
+ const state = taskStates.get(entry);
126004
+ if (!state?.timer) return;
126005
+ clearInterval(state.timer);
126006
+ state.timer = null;
126007
+ }
126008
+ async function pollTasks(entry) {
126009
+ const state = taskStateOf(entry);
126010
+ if (state.polling) return;
126011
+ if (sessionMap3.get(entryKey(entry)) !== entry) {
126012
+ stopTaskPolling2(entry);
126013
+ return;
126014
+ }
126015
+ state.polling = true;
126016
+ try {
126017
+ const tasks = await entry.client.listBackgroundTasks(entry.repoburgSessionId);
126018
+ const db2 = getDb();
126019
+ const listed = new Set(tasks.map((task) => task.task_id));
126020
+ for (const task of tasks) {
126021
+ if (task.status === "running") {
126022
+ state.running.set(task.task_id, {
126023
+ task_id: task.task_id,
126024
+ task_type: REPOBURG_TASK_TYPE,
126025
+ description: task.description
126026
+ });
126027
+ updateTaskItem(db2, entry.agentPaneSessionId, task.task_id, { status: "running" });
126028
+ } else if (state.running.delete(task.task_id)) {
126029
+ state.watchUntil = Date.now() + WAKE_WATCH_MS;
126030
+ updateTaskItem(db2, entry.agentPaneSessionId, task.task_id, {
126031
+ status: task.status,
126032
+ summary: taskSummary(task),
126033
+ exit_code: task.exit_code
126034
+ });
126035
+ }
126036
+ }
126037
+ for (const taskId of [...state.running.keys()]) {
126038
+ if (listed.has(taskId)) continue;
126039
+ state.running.delete(taskId);
126040
+ updateTaskItem(db2, entry.agentPaneSessionId, taskId, {
126041
+ status: "stopped",
126042
+ summary: "The Repoburg backend stopped running this task.",
126043
+ exit_code: null
126044
+ });
126045
+ }
126046
+ publishTasks2(entry.agentPaneSessionId);
126047
+ await attachWakeRun(entry);
126048
+ } catch (err) {
126049
+ if (httpStatus(err) === 404) {
126050
+ state.running.clear();
126051
+ state.watchUntil = 0;
126052
+ publishTasks2(entry.agentPaneSessionId);
126053
+ } else if (isConnectionError(err)) {
126054
+ invalidateBackend(entry.baseUrl);
126055
+ }
126056
+ } finally {
126057
+ state.polling = false;
126058
+ if (state.running.size === 0 && Date.now() >= state.watchUntil) stopTaskPolling2(entry);
126059
+ }
126060
+ }
126061
+ function entryBusy(entry) {
126062
+ return startingEntries.has(entry) || !!entry.activeTurn && !entry.activeTurn.projector.isDone;
126063
+ }
126064
+ async function attachWakeRun(entry) {
126065
+ if (entryBusy(entry)) return;
126066
+ const state = await getAgentRuntimeState(entry.baseUrl, entry.repoburgSessionId).catch(() => null);
126067
+ if (!state || entryBusy(entry)) return;
126068
+ const previous = entry.activeTurn;
126069
+ const handled = previous && previous.bootId === state.bootId && previous.lastSeq !== null ? previous.lastSeq : null;
126070
+ const missedRun = handled !== null && !previous?.cancelled && state.lastResult !== null && (state.lastResult.seq ?? 0) > handled;
126071
+ if (!state.turnInFlight && !missedRun) return;
126072
+ const db2 = getDb();
126073
+ const turn = db2.prepare("SELECT id, status FROM turns WHERE session_id = ? AND thread_id IS ? ORDER BY created_at DESC LIMIT 1").get(entry.agentPaneSessionId, entry.threadId);
126074
+ if (!turn || turn.status === "running" || turn.status === "pending") return;
126075
+ const fromSeq = handled ?? state.lastResult?.seq ?? 0;
126076
+ const now = (/* @__PURE__ */ new Date()).toISOString();
126077
+ const cursor = {
126078
+ bootId: state.bootId,
126079
+ firstSeq: fromSeq + 1,
126080
+ baseUrl: entry.baseUrl,
126081
+ runtimeSessionId: entry.repoburgSessionId
126082
+ };
126083
+ db2.prepare("UPDATE turns SET status = 'running', error = NULL, stream_cursor = ?, updated_at = ? WHERE id = ?").run(
126084
+ JSON.stringify(cursor),
126085
+ now,
126086
+ turn.id
126087
+ );
126088
+ setSessionStatus3(db2, entry.agentPaneSessionId, 1, "running", now);
126089
+ broadcast("turn:started", { sessionId: entry.agentPaneSessionId, turnId: turn.id });
126090
+ const projector = new TurnProjector({
126091
+ agentPaneSessionId: entry.agentPaneSessionId,
126092
+ turnId: turn.id,
126093
+ repoburgSessionId: entry.repoburgSessionId,
126094
+ client: entry.client,
126095
+ getContextWindow: () => entry.contextWindow,
126096
+ firstSeq: fromSeq + 1,
126097
+ cwd: sessionCwd(entry.agentPaneSessionId),
126098
+ onTaskEvent: (message) => onTaskEvent(entry, message),
126099
+ onFinished: () => onTurnFinished(entry)
126100
+ });
126101
+ entry.activeTurn = {
126102
+ turnId: turn.id,
126103
+ projector,
126104
+ sseAbort: new AbortController(),
126105
+ cancelled: false,
126106
+ bootId: state.bootId,
126107
+ lastSeq: fromSeq
126108
+ };
126109
+ console.log(`[repoburg] session ${entry.agentPaneSessionId}: a background task ended, turn ${turn.id} runs again`);
126110
+ runStreamLoop(entry, projector).catch((err) => {
126111
+ console.error("[repoburg] stream loop crashed:", err);
126112
+ failTurn3(entry, `Stream loop failed: ${err.message}`);
126113
+ });
126114
+ }
126115
+ async function waitForRunEnd(entry, timeoutMs) {
126116
+ const end = Date.now() + timeoutMs;
126117
+ for (; ; ) {
126118
+ const state = await getAgentRuntimeState(entry.baseUrl, entry.repoburgSessionId).catch(() => null);
126119
+ if (!state || !state.turnInFlight || Date.now() >= end) return state;
126120
+ await new Promise((resolve) => setTimeout(resolve, 200));
126121
+ }
126122
+ }
126123
+ async function stopTask3(sessionId, taskId) {
126124
+ for (const [key, entry] of sessionMap3) {
126125
+ if (key !== sessionId && !key.startsWith(`${sessionId}:thread:`)) continue;
126126
+ const state = taskStates.get(entry);
126127
+ if (!state?.running.has(taskId) || !entry.client.stopBackgroundTask) continue;
126128
+ const task = await entry.client.stopBackgroundTask(entry.repoburgSessionId, taskId);
126129
+ state.running.delete(taskId);
126130
+ updateTaskItem(getDb(), sessionId, taskId, {
126131
+ status: task.status === "running" ? "stopped" : task.status,
126132
+ summary: taskSummary(task),
126133
+ exit_code: task.exit_code
126134
+ });
126135
+ publishTasks2(sessionId);
126136
+ return;
126137
+ }
126138
+ throw new Error(`No running background task ${taskId} in this session`);
126139
+ }
126140
+ function listBackgroundTasks3() {
126141
+ const bySession = {};
126142
+ for (const entry of sessionMap3.values()) {
126143
+ const tasks = sessionTasks(entry.agentPaneSessionId);
126144
+ if (tasks.length > 0) bySession[entry.agentPaneSessionId] = tasks;
126145
+ }
126146
+ return bySession;
126147
+ }
126148
+ var pushedMcp = /* @__PURE__ */ new Map();
126149
+ var noSessionMcp = /* @__PURE__ */ new Set();
126150
+ async function syncSessionMcp(entry, cwd) {
126151
+ if (!entry.client.setSessionMcpServers || noSessionMcp.has(entry.baseUrl)) return;
126152
+ try {
126153
+ const servers = await repoburgBrowserMcpServers(cwd);
126154
+ const json2 = JSON.stringify(servers);
126155
+ const key = `${entry.baseUrl} ${entry.repoburgSessionId}`;
126156
+ if (pushedMcp.get(key) === json2) return;
126157
+ await entry.client.setSessionMcpServers(entry.repoburgSessionId, servers);
126158
+ pushedMcp.set(key, json2);
126159
+ } catch (err) {
126160
+ if (httpStatus(err) === 404 || httpStatus(err) === 400) {
126161
+ noSessionMcp.add(entry.baseUrl);
126162
+ return;
126163
+ }
126164
+ console.warn("[repoburg] could not set the session MCP servers:", err.message);
126165
+ }
126166
+ }
125739
126167
  function parseCursor(raw) {
125740
126168
  if (!raw) return null;
125741
126169
  try {
@@ -125794,9 +126222,9 @@ async function adoptRepoburgTurns(db2, result) {
125794
126222
  repoburgSessionId: cursor.runtimeSessionId,
125795
126223
  client: new RepoburgHttpClient(cursor.baseUrl),
125796
126224
  baseUrl: cursor.baseUrl,
125797
- modelId: row.model,
126225
+ modelId: void 0,
126226
+ // model and effort re-pushed on the next turn
125798
126227
  reasoningEffort: void 0,
125799
- // re-pushed on the next turn
125800
126228
  threadId: row.thread_id,
125801
126229
  contextWindow: null,
125802
126230
  modelsResolved: false,
@@ -125809,7 +126237,10 @@ async function adoptRepoburgTurns(db2, result) {
125809
126237
  repoburgSessionId: cursor.runtimeSessionId,
125810
126238
  client: entry.client,
125811
126239
  getContextWindow: () => entry.contextWindow,
125812
- firstSeq: cursor.firstSeq
126240
+ firstSeq: cursor.firstSeq,
126241
+ cwd: sessionCwd(row.session_id),
126242
+ onTaskEvent: (message) => onTaskEvent(entry, message),
126243
+ onFinished: () => onTurnFinished(entry)
125813
126244
  });
125814
126245
  entry.activeTurn = {
125815
126246
  turnId: row.id,
@@ -125852,12 +126283,9 @@ async function interruptTurn3(sessionId, threadId) {
125852
126283
  const db2 = getDb();
125853
126284
  const now = (/* @__PURE__ */ new Date()).toISOString();
125854
126285
  db2.prepare("UPDATE turns SET status = ?, updated_at = ? WHERE id = ?").run("aborted", now, active.turnId);
125855
- db2.prepare("UPDATE items SET status = ?, updated_at = ? WHERE turn_id = ? AND status = ?").run(
125856
- "completed",
125857
- now,
125858
- active.turnId,
125859
- "in_progress"
125860
- );
126286
+ db2.prepare(
126287
+ `UPDATE items SET status = ?, updated_at = ? WHERE turn_id = ? AND status = ? AND ${NOT_BACKGROUND_COMMAND}`
126288
+ ).run("completed", now, active.turnId, "in_progress");
125861
126289
  recomputeSessionRunning(db2, sessionId);
125862
126290
  broadcast("turn:cancelled", { sessionId, turnId: active.turnId });
125863
126291
  return true;
@@ -125871,6 +126299,7 @@ function clearThread3(sessionId) {
125871
126299
  active.projector.close();
125872
126300
  active.sseAbort.abort();
125873
126301
  }
126302
+ stopTaskPolling2(entry);
125874
126303
  sessionMap3.delete(key);
125875
126304
  }
125876
126305
  }
@@ -125884,6 +126313,7 @@ function clearThreadBranch3(sessionId, threadId) {
125884
126313
  active.projector.close();
125885
126314
  active.sseAbort.abort();
125886
126315
  }
126316
+ stopTaskPolling2(entry);
125887
126317
  sessionMap3.delete(key);
125888
126318
  }
125889
126319
  }
@@ -125933,8 +126363,15 @@ async function forkSession2(session, targetTurn) {
125933
126363
  }
125934
126364
  const client = await resolveClient(session);
125935
126365
  const forked = await client.forkSession(session.external_thread_id, anchor);
126366
+ forkInputIds.set(forked.id, new Map(Object.entries(forked.input_id_map ?? {})));
125936
126367
  return forked.id;
125937
126368
  }
126369
+ var forkInputIds = /* @__PURE__ */ new Map();
126370
+ async function forkedTurnIds2(_session, forkedId) {
126371
+ const ids = forkInputIds.get(forkedId) ?? /* @__PURE__ */ new Map();
126372
+ forkInputIds.delete(forkedId);
126373
+ return ids;
126374
+ }
125938
126375
  var THREAD_SUMMARY_TIMEOUT_MS = 12e4;
125939
126376
  async function summarizeThread(session, _thread, transcript, directives) {
125940
126377
  try {
@@ -125958,8 +126395,12 @@ function clearAllThreads3() {
125958
126395
  active.projector.close();
125959
126396
  active.sseAbort.abort();
125960
126397
  }
126398
+ stopTaskPolling2(entry);
125961
126399
  }
125962
126400
  sessionMap3.clear();
126401
+ publishedTasks.clear();
126402
+ pushedMcp.clear();
126403
+ noSessionMcp.clear();
125963
126404
  }
125964
126405
  async function getModels3(cwd) {
125965
126406
  try {
@@ -126062,7 +126503,10 @@ var repoburgProvider = {
126062
126503
  getCommands: getCommands3,
126063
126504
  rewindRuntime,
126064
126505
  forkSession: forkSession2,
126506
+ forkedTurnIds: forkedTurnIds2,
126065
126507
  summarizeThread,
126508
+ stopTask: stopTask3,
126509
+ listBackgroundTasks: listBackgroundTasks3,
126066
126510
  shutdown: shutdown3
126067
126511
  };
126068
126512