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 = `
@@ -41958,8 +41958,8 @@ function forkPoint(db2, sessionId, target) {
41958
41958
  return row?.external_turn_id ?? null;
41959
41959
  }
41960
41960
  function snapshotTurnIds(db2, sessionId) {
41961
- const rows = db2.prepare("SELECT id, external_turn_id FROM turns WHERE session_id = ? AND thread_id IS NULL").all(sessionId);
41962
- return JSON.stringify(Object.fromEntries(rows.map((r) => [r.id, r.external_turn_id])));
41961
+ const rows = db2.prepare("SELECT id, external_turn_id, runtime_input_ids FROM turns WHERE session_id = ? AND thread_id IS NULL").all(sessionId);
41962
+ return JSON.stringify(Object.fromEntries(rows.map((r) => [r.id, [r.external_turn_id, r.runtime_input_ids]])));
41963
41963
  }
41964
41964
  function restoreTurnIds(db2, sessionId, snapshot) {
41965
41965
  if (!snapshot) return;
@@ -41969,19 +41969,40 @@ function restoreTurnIds(db2, sessionId, snapshot) {
41969
41969
  } catch {
41970
41970
  return;
41971
41971
  }
41972
- const update = db2.prepare("UPDATE turns SET external_turn_id = ? WHERE id = ? AND session_id = ?");
41973
- for (const [turnId, externalId] of Object.entries(ids)) update.run(externalId, turnId, sessionId);
41972
+ const updateExternal = db2.prepare("UPDATE turns SET external_turn_id = ? WHERE id = ? AND session_id = ?");
41973
+ const updateBoth = db2.prepare(
41974
+ "UPDATE turns SET external_turn_id = ?, runtime_input_ids = ? WHERE id = ? AND session_id = ?"
41975
+ );
41976
+ for (const [turnId, value] of Object.entries(ids)) {
41977
+ if (Array.isArray(value)) updateBoth.run(value[0] ?? null, value[1] ?? null, turnId, sessionId);
41978
+ else updateExternal.run(value, turnId, sessionId);
41979
+ }
41980
+ }
41981
+ function forkedRuntimeInputIds(raw, map2) {
41982
+ if (!raw) return raw;
41983
+ let ids;
41984
+ try {
41985
+ ids = JSON.parse(raw);
41986
+ } catch {
41987
+ return raw;
41988
+ }
41989
+ if (!Array.isArray(ids)) return raw;
41990
+ return JSON.stringify(ids.map((id) => typeof id === "string" ? map2.get(id) ?? id : id));
41974
41991
  }
41975
41992
  function applyTurnIdMap(db2, sessionId, map2, upToCreatedAt = null) {
41976
41993
  if (map2.size === 0) return;
41977
41994
  const rows = db2.prepare(
41978
- `SELECT id, external_turn_id FROM turns
41979
- WHERE session_id = ? AND thread_id IS NULL AND external_turn_id IS NOT NULL` + (upToCreatedAt ? " AND created_at <= ?" : "")
41995
+ `SELECT id, external_turn_id, runtime_input_ids FROM turns
41996
+ WHERE session_id = ? AND thread_id IS NULL
41997
+ AND (external_turn_id IS NOT NULL OR runtime_input_ids IS NOT NULL)` + (upToCreatedAt ? " AND created_at <= ?" : "")
41980
41998
  ).all(...upToCreatedAt ? [sessionId, upToCreatedAt] : [sessionId]);
41981
- const update = db2.prepare("UPDATE turns SET external_turn_id = ? WHERE id = ?");
41999
+ const update = db2.prepare("UPDATE turns SET external_turn_id = ?, runtime_input_ids = ? WHERE id = ?");
41982
42000
  for (const row of rows) {
41983
- const mapped = map2.get(row.external_turn_id);
41984
- if (mapped) update.run(mapped, row.id);
42001
+ const externalId = (row.external_turn_id && map2.get(row.external_turn_id)) ?? row.external_turn_id;
42002
+ const inputIds = forkedRuntimeInputIds(row.runtime_input_ids, map2);
42003
+ if (externalId !== row.external_turn_id || inputIds !== row.runtime_input_ids) {
42004
+ update.run(externalId, inputIds, row.id);
42005
+ }
41985
42006
  }
41986
42007
  }
41987
42008
  function dropRewoundTurns(db2, sessionId) {
@@ -42560,8 +42581,8 @@ async function registerSessionRoutes(fastify) {
42560
42581
  for (const turn of turnRows) {
42561
42582
  const newTurnId = v4_default();
42562
42583
  db2.prepare(
42563
- `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)
42564
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
42584
+ `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)
42585
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
42565
42586
  ).run(
42566
42587
  newTurnId,
42567
42588
  newSessionId,
@@ -42570,6 +42591,7 @@ async function registerSessionRoutes(fastify) {
42570
42591
  turn.thoughts,
42571
42592
  turn.token_usage,
42572
42593
  (turn.external_turn_id && turnIds.get(turn.external_turn_id)) ?? turn.external_turn_id,
42594
+ forkedRuntimeInputIds(turn.runtime_input_ids, turnIds),
42573
42595
  turn.status,
42574
42596
  turn.error,
42575
42597
  turn.attachments,
@@ -42804,7 +42826,7 @@ function recoverInterruptedTurns(db2, opts) {
42804
42826
  WHERE i.status = 'in_progress'`
42805
42827
  ).all();
42806
42828
  const orphaned = open.filter((i) => !skip.entries.has(runtimeEntryKey(i.session_id, i.thread_id)));
42807
- const stopTask3 = db2.prepare(
42829
+ const stopTask4 = db2.prepare(
42808
42830
  `UPDATE items SET data = json_set(COALESCE(data, '{}'), '$.status', 'stopped')
42809
42831
  WHERE id = ? AND json_valid(COALESCE(data, '{}'))`
42810
42832
  );
@@ -42812,7 +42834,7 @@ function recoverInterruptedTurns(db2, opts) {
42812
42834
  const items = { changes: 0 };
42813
42835
  db2.transaction(() => {
42814
42836
  for (const item of orphaned) {
42815
- if (item.type === "background_task") stopTask3.run(item.id);
42837
+ if (item.type === "background_task") stopTask4.run(item.id);
42816
42838
  items.changes += failItem.run(now, item.id).changes;
42817
42839
  }
42818
42840
  })();
@@ -43967,6 +43989,165 @@ async function registerProviderRoutes(fastify) {
43967
43989
  var InferenceCredentialsError = class extends Error {
43968
43990
  };
43969
43991
 
43992
+ // src/repoburg/backend-resolver.ts
43993
+ import path4 from "node:path";
43994
+ var RepoburgSignInRequiredError = class extends Error {
43995
+ constructor(projectPath) {
43996
+ super(
43997
+ `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'.`
43998
+ );
43999
+ this.projectPath = projectPath;
44000
+ this.name = "RepoburgSignInRequiredError";
44001
+ }
44002
+ code = "repoburg_sign_in_required";
44003
+ };
44004
+ var HEALTH_POLL_INTERVAL_MS = 1e3;
44005
+ var HEALTH_TIMEOUT_MS = 3e4;
44006
+ function daemonBaseUrl() {
44007
+ return (process.env.REPOBURG_DAEMON_URL || "http://localhost:9998").replace(/\/+$/, "");
44008
+ }
44009
+ var HttpError = class extends Error {
44010
+ constructor(status, body, url2) {
44011
+ super(`${url2} failed: ${status} ${body}`);
44012
+ this.status = status;
44013
+ this.body = body;
44014
+ this.url = url2;
44015
+ }
44016
+ };
44017
+ async function fetchJson(url2, init, timeoutMs = 5e3) {
44018
+ const controller = new AbortController();
44019
+ const timer3 = setTimeout(() => controller.abort(), timeoutMs);
44020
+ let response;
44021
+ try {
44022
+ response = await fetch(url2, { ...init, signal: controller.signal });
44023
+ } finally {
44024
+ clearTimeout(timer3);
44025
+ }
44026
+ const text2 = await response.text();
44027
+ if (!response.ok) {
44028
+ throw new HttpError(response.status, text2, url2);
44029
+ }
44030
+ try {
44031
+ return JSON.parse(text2);
44032
+ } catch {
44033
+ throw new Error(`Unexpected non-JSON response from ${url2}`);
44034
+ }
44035
+ }
44036
+ function daemonErrorMessage(err) {
44037
+ if (err instanceof HttpError) {
44038
+ try {
44039
+ const parsed = JSON.parse(err.body);
44040
+ return parsed.message || parsed.error || err.body;
44041
+ } catch {
44042
+ return err.body;
44043
+ }
44044
+ }
44045
+ return err.message;
44046
+ }
44047
+ var resolvedCache = /* @__PURE__ */ new Map();
44048
+ function invalidateBackend(baseUrl) {
44049
+ for (const [key, value] of resolvedCache) {
44050
+ if (value.baseUrl === baseUrl) resolvedCache.delete(key);
44051
+ }
44052
+ }
44053
+ async function backendHealthy(baseUrl, expectedPath) {
44054
+ try {
44055
+ const health = await fetchJson(`${baseUrl}/health`, void 0, 2e3);
44056
+ if (health.status !== "ok") return false;
44057
+ if (expectedPath && health.projectPath) {
44058
+ return path4.resolve(health.projectPath) === path4.resolve(expectedPath);
44059
+ }
44060
+ return true;
44061
+ } catch {
44062
+ return false;
44063
+ }
44064
+ }
44065
+ async function waitForHealthy(baseUrl, name, expectedPath) {
44066
+ const deadline = Date.now() + HEALTH_TIMEOUT_MS;
44067
+ while (Date.now() < deadline) {
44068
+ if (await backendHealthy(baseUrl, expectedPath)) return;
44069
+ await new Promise((resolve) => setTimeout(resolve, HEALTH_POLL_INTERVAL_MS));
44070
+ }
44071
+ throw new Error(
44072
+ `Backend '${name}' on ${baseUrl} did not become healthy within ${HEALTH_TIMEOUT_MS / 1e3}s. Check daemon logs: repoburg logs ${name}`
44073
+ );
44074
+ }
44075
+ function serviceBaseUrl(service) {
44076
+ return `http://localhost:${service.port}`;
44077
+ }
44078
+ function coveringService(services, absPath) {
44079
+ return services.filter((s) => absPath === s.path || absPath.startsWith(s.path + path4.sep)).sort((a, b) => b.path.length - a.path.length)[0];
44080
+ }
44081
+ async function restartService(daemon, name) {
44082
+ try {
44083
+ await fetchJson(`${daemon}/services/${name}/restart`, { method: "POST" });
44084
+ } catch (err) {
44085
+ throw new Error(`Daemon failed to restart backend '${name}': ${daemonErrorMessage(err)}`);
44086
+ }
44087
+ }
44088
+ async function startService(daemon, projectPath) {
44089
+ try {
44090
+ return await fetchJson(`${daemon}/services/start`, {
44091
+ method: "POST",
44092
+ headers: { "Content-Type": "application/json" },
44093
+ body: JSON.stringify({ path: projectPath })
44094
+ });
44095
+ } catch (err) {
44096
+ if (err instanceof HttpError && err.status === 401) throw new RepoburgSignInRequiredError(projectPath);
44097
+ throw new Error(`Daemon failed to start backend for ${projectPath}: ${daemonErrorMessage(err)}`);
44098
+ }
44099
+ }
44100
+ function cache(absPath, service) {
44101
+ const resolved = {
44102
+ baseUrl: serviceBaseUrl(service),
44103
+ port: service.port,
44104
+ name: service.name,
44105
+ servesPath: service.path
44106
+ };
44107
+ resolvedCache.set(absPath, resolved);
44108
+ return resolved;
44109
+ }
44110
+ async function resolveBackendUrl(projectPath, opts = {}) {
44111
+ const autoStart = opts.autoStart !== false;
44112
+ const envUrl = process.env.REPOBURG_BACKEND_URL;
44113
+ if (envUrl) {
44114
+ return { baseUrl: envUrl.replace(/\/+$/, ""), port: 0, name: "REPOBURG_BACKEND_URL" };
44115
+ }
44116
+ const absPath = path4.resolve(projectPath);
44117
+ const daemon = daemonBaseUrl();
44118
+ const cached3 = resolvedCache.get(absPath);
44119
+ if (cached3 && await backendHealthy(cached3.baseUrl, cached3.servesPath ?? absPath)) {
44120
+ return cached3;
44121
+ }
44122
+ try {
44123
+ await fetchJson(`${daemon}/health`, void 0, 3e3);
44124
+ } catch {
44125
+ throw new Error(
44126
+ `Repoburg daemon not reachable at ${daemon}. Start it with 'repoburg-daemon', or set REPOBURG_BACKEND_URL to a running backend.`
44127
+ );
44128
+ }
44129
+ const services = await fetchJson(`${daemon}/services`);
44130
+ const match = coveringService(services, absPath);
44131
+ if (match && match.status === "running") {
44132
+ if (await backendHealthy(serviceBaseUrl(match), match.path)) {
44133
+ return cache(absPath, match);
44134
+ }
44135
+ if (!autoStart) return null;
44136
+ await restartService(daemon, match.name);
44137
+ await waitForHealthy(serviceBaseUrl(match), match.name, match.path);
44138
+ return cache(absPath, match);
44139
+ }
44140
+ if (!autoStart) return null;
44141
+ if (match) {
44142
+ await restartService(daemon, match.name);
44143
+ await waitForHealthy(serviceBaseUrl(match), match.name, match.path);
44144
+ return cache(absPath, match);
44145
+ }
44146
+ const service = await startService(daemon, absPath);
44147
+ await waitForHealthy(serviceBaseUrl(service), service.name, absPath);
44148
+ return cache(absPath, service);
44149
+ }
44150
+
43970
44151
  // src/routes/models.ts
43971
44152
  function inferenceRuntime(id, reply) {
43972
44153
  const provider = hasProvider(id) ? getProvider(id) : void 0;
@@ -43980,6 +44161,9 @@ function sendInferenceError(reply, error51) {
43980
44161
  if (error51 instanceof InferenceCredentialsError) {
43981
44162
  return reply.code(400).send({ error: error51.message });
43982
44163
  }
44164
+ if (error51 instanceof RepoburgSignInRequiredError) {
44165
+ return reply.code(403).send({ error: error51.message, code: error51.code });
44166
+ }
43983
44167
  const message = error51 instanceof Error ? error51.message : String(error51);
43984
44168
  return reply.code(503).send({ error: message });
43985
44169
  }
@@ -44616,23 +44800,23 @@ import http from "node:http";
44616
44800
  import net from "node:net";
44617
44801
  import crypto from "node:crypto";
44618
44802
  import os3 from "node:os";
44619
- import path4 from "node:path";
44803
+ import path5 from "node:path";
44620
44804
  import { mkdir, readdir as readdir2, symlink, lstat, access, readFile, writeFile, unlink } from "node:fs/promises";
44621
- var VSCODE_WEB_DATA_DIR = path4.join(os3.homedir(), ".repoburg", "vscode-web");
44805
+ var VSCODE_WEB_DATA_DIR = path5.join(os3.homedir(), ".repoburg", "vscode-web");
44622
44806
  function resolveDesktopUserDir() {
44623
44807
  if (process.platform === "darwin") {
44624
- return path4.join(os3.homedir(), "Library", "Application Support", "Code", "User");
44808
+ return path5.join(os3.homedir(), "Library", "Application Support", "Code", "User");
44625
44809
  }
44626
44810
  if (process.platform === "win32" && process.env.APPDATA) {
44627
- return path4.join(process.env.APPDATA, "Code", "User");
44811
+ return path5.join(process.env.APPDATA, "Code", "User");
44628
44812
  }
44629
44813
  if (process.platform === "linux") {
44630
- return path4.join(os3.homedir(), ".config", "Code", "User");
44814
+ return path5.join(os3.homedir(), ".config", "Code", "User");
44631
44815
  }
44632
44816
  return null;
44633
44817
  }
44634
44818
  async function linkUnlessExists(src, dst) {
44635
- await mkdir(path4.dirname(dst), { recursive: true });
44819
+ await mkdir(path5.dirname(dst), { recursive: true });
44636
44820
  try {
44637
44821
  await lstat(dst);
44638
44822
  return false;
@@ -44647,19 +44831,19 @@ function fileRegistryUri(dir) {
44647
44831
  }
44648
44832
  async function syncProfile(dataDir = VSCODE_WEB_DATA_DIR) {
44649
44833
  try {
44650
- const desktopExt = path4.join(os3.homedir(), ".vscode", "extensions");
44834
+ const desktopExt = path5.join(os3.homedir(), ".vscode", "extensions");
44651
44835
  let entries;
44652
44836
  try {
44653
44837
  entries = await readdir2(desktopExt, { withFileTypes: true });
44654
44838
  } catch {
44655
44839
  return;
44656
44840
  }
44657
- const serverExt = path4.join(dataDir, "extensions");
44841
+ const serverExt = path5.join(dataDir, "extensions");
44658
44842
  const linkedFolders = [];
44659
44843
  for (const entry of entries) {
44660
44844
  if (!entry.isDirectory()) continue;
44661
- const target = path4.join(serverExt, entry.name);
44662
- await linkUnlessExists(path4.join(desktopExt, entry.name), target);
44845
+ const target = path5.join(serverExt, entry.name);
44846
+ await linkUnlessExists(path5.join(desktopExt, entry.name), target);
44663
44847
  const st = await lstat(target).catch(() => null);
44664
44848
  if (st?.isSymbolicLink()) linkedFolders.push(entry.name);
44665
44849
  }
@@ -44667,15 +44851,15 @@ async function syncProfile(dataDir = VSCODE_WEB_DATA_DIR) {
44667
44851
  await pruneObsolete(serverExt, linkedFolders);
44668
44852
  const desktopUser = resolveDesktopUserDir();
44669
44853
  if (!desktopUser) return;
44670
- const serverUser = path4.join(dataDir, "data", "User");
44854
+ const serverUser = path5.join(dataDir, "data", "User");
44671
44855
  for (const item of ["settings.json", "keybindings.json", "snippets"]) {
44672
- const src = path4.join(desktopUser, item);
44856
+ const src = path5.join(desktopUser, item);
44673
44857
  try {
44674
44858
  await access(src);
44675
44859
  } catch {
44676
44860
  continue;
44677
44861
  }
44678
- await linkUnlessExists(src, path4.join(serverUser, item));
44862
+ await linkUnlessExists(src, path5.join(serverUser, item));
44679
44863
  }
44680
44864
  } catch {
44681
44865
  }
@@ -44683,13 +44867,13 @@ async function syncProfile(dataDir = VSCODE_WEB_DATA_DIR) {
44683
44867
  async function mergeExtensionRegistry(desktopExt, serverExt, linkedFolders) {
44684
44868
  let desktopEntries = [];
44685
44869
  try {
44686
- desktopEntries = JSON.parse(await readFile(path4.join(desktopExt, "extensions.json"), "utf8"));
44870
+ desktopEntries = JSON.parse(await readFile(path5.join(desktopExt, "extensions.json"), "utf8"));
44687
44871
  } catch {
44688
44872
  return;
44689
44873
  }
44690
44874
  const linked = new Set(linkedFolders);
44691
44875
  const toAdd = desktopEntries.filter((e) => e.identifier?.id && linked.has(e.relativeLocation));
44692
- const serverRegistryPath = path4.join(serverExt, "extensions.json");
44876
+ const serverRegistryPath = path5.join(serverExt, "extensions.json");
44693
44877
  let serverEntries = [];
44694
44878
  try {
44695
44879
  serverEntries = JSON.parse(await readFile(serverRegistryPath, "utf8"));
@@ -44699,13 +44883,13 @@ async function mergeExtensionRegistry(desktopExt, serverExt, linkedFolders) {
44699
44883
  const additions = toAdd.filter((e) => !known.has(`${e.identifier.id.toLowerCase()}@${e.version}`));
44700
44884
  if (additions.length === 0) return;
44701
44885
  for (const entry of additions) {
44702
- const dir = path4.join(serverExt, entry.relativeLocation);
44886
+ const dir = path5.join(serverExt, entry.relativeLocation);
44703
44887
  serverEntries.push({ ...entry, location: fileRegistryUri(dir) });
44704
44888
  }
44705
44889
  await writeFile(serverRegistryPath, JSON.stringify(serverEntries));
44706
44890
  }
44707
44891
  async function pruneObsolete(serverExt, linkedFolders) {
44708
- const obsoletePath = path4.join(serverExt, ".obsolete");
44892
+ const obsoletePath = path5.join(serverExt, ".obsolete");
44709
44893
  let obsolete;
44710
44894
  try {
44711
44895
  obsolete = JSON.parse(await readFile(obsoletePath, "utf8"));
@@ -45164,15 +45348,15 @@ function proxyHandler(request, reply) {
45164
45348
 
45165
45349
  // src/routes/apps.ts
45166
45350
  import fs7 from "node:fs";
45167
- import path11 from "node:path";
45351
+ import path12 from "node:path";
45168
45352
 
45169
45353
  // src/apps/instances.ts
45170
45354
  import fs3 from "node:fs";
45171
- import path6 from "node:path";
45355
+ import path7 from "node:path";
45172
45356
 
45173
45357
  // src/apps/apps-registry.ts
45174
45358
  import fs2 from "node:fs";
45175
- import path5 from "node:path";
45359
+ import path6 from "node:path";
45176
45360
  import os4 from "node:os";
45177
45361
  import { fileURLToPath } from "node:url";
45178
45362
 
@@ -99397,10 +99581,10 @@ function setAppsRootOverride(root) {
99397
99581
  rootOverride = root;
99398
99582
  }
99399
99583
  function appsRoot() {
99400
- return rootOverride ?? process.env.AGENT_PANE_APPS_DIR ?? path5.join(os4.homedir(), ".repoburg", "agent-pane", "apps");
99584
+ return rootOverride ?? process.env.AGENT_PANE_APPS_DIR ?? path6.join(os4.homedir(), ".repoburg", "agent-pane", "apps");
99401
99585
  }
99402
99586
  function appDir(id) {
99403
- return path5.join(appsRoot(), id);
99587
+ return path6.join(appsRoot(), id);
99404
99588
  }
99405
99589
  var examplesRootOverride = null;
99406
99590
  function setExamplesRootOverride(root) {
@@ -99409,16 +99593,16 @@ function setExamplesRootOverride(root) {
99409
99593
  function examplesRoot() {
99410
99594
  if (examplesRootOverride) return examplesRootOverride;
99411
99595
  if (process.env.AGENT_PANE_EXAMPLES_DIR) return process.env.AGENT_PANE_EXAMPLES_DIR;
99412
- const here = path5.dirname(fileURLToPath(import.meta.url));
99413
- for (const candidate of [path5.resolve(here, "../../examples"), path5.resolve(here, "../../../examples")]) {
99596
+ const here = path6.dirname(fileURLToPath(import.meta.url));
99597
+ for (const candidate of [path6.resolve(here, "../../examples"), path6.resolve(here, "../../../examples")]) {
99414
99598
  if (fs2.existsSync(candidate)) return candidate;
99415
99599
  }
99416
99600
  return null;
99417
99601
  }
99418
99602
  function isInAppFolder(cwd) {
99419
99603
  if (!cwd) return false;
99420
- const rel = path5.relative(path5.resolve(appsRoot()), path5.resolve(cwd));
99421
- return rel !== "" && !path5.isAbsolute(rel) && rel.split(path5.sep)[0] !== "..";
99604
+ const rel = path6.relative(path6.resolve(appsRoot()), path6.resolve(cwd));
99605
+ return rel !== "" && !path6.isAbsolute(rel) && rel.split(path6.sep)[0] !== "..";
99422
99606
  }
99423
99607
  function appsConventions() {
99424
99608
  return APPS_MD_SKELETON;
@@ -99427,7 +99611,7 @@ function ensureAppsRoot() {
99427
99611
  const root = appsRoot();
99428
99612
  fs2.mkdirSync(root, { recursive: true });
99429
99613
  for (const name of ["CLAUDE.md", "AGENTS.md"]) {
99430
- const file2 = path5.join(root, name);
99614
+ const file2 = path6.join(root, name);
99431
99615
  try {
99432
99616
  if (fs2.existsSync(file2) && fs2.readFileSync(file2, "utf-8") === APPS_MD_FILE) continue;
99433
99617
  fs2.writeFileSync(file2, APPS_MD_FILE);
@@ -99692,7 +99876,7 @@ folder's own CLAUDE.md / AGENTS.md. -->
99692
99876
  ${APPS_MD_SKELETON}`;
99693
99877
  function readManifestIn(dir) {
99694
99878
  try {
99695
- const raw = fs2.readFileSync(path5.join(dir, "manifest.json"), "utf-8");
99879
+ const raw = fs2.readFileSync(path6.join(dir, "manifest.json"), "utf-8");
99696
99880
  const parsed = JSON.parse(raw);
99697
99881
  if (!parsed || typeof parsed.title !== "string") return null;
99698
99882
  return {
@@ -99719,7 +99903,7 @@ function readManifest(id) {
99719
99903
  }
99720
99904
  function readAppFile(id, name) {
99721
99905
  try {
99722
- return fs2.readFileSync(path5.join(appDir(id), name), "utf-8");
99906
+ return fs2.readFileSync(path6.join(appDir(id), name), "utf-8");
99723
99907
  } catch {
99724
99908
  return "";
99725
99909
  }
@@ -99752,11 +99936,11 @@ function startAppsWatch(onAppChange) {
99752
99936
  try {
99753
99937
  watcher = fs2.watch(root, { recursive: true }, (_event, filename) => {
99754
99938
  const rel = String(filename ?? "");
99755
- const segs = rel.split(path5.sep);
99939
+ const segs = rel.split(path6.sep);
99756
99940
  const appId = segs[0];
99757
99941
  const file2 = segs[segs.length - 1];
99758
- if (!appId || appId === path5.basename(root) || !APP_ID_RE.test(appId) || file2 === "state.json") return;
99759
- if (segs.length === 1 && isRegularFile(path5.join(root, appId))) return;
99942
+ if (!appId || appId === path6.basename(root) || !APP_ID_RE.test(appId) || file2 === "state.json") return;
99943
+ if (segs.length === 1 && isRegularFile(path6.join(root, appId))) return;
99760
99944
  const timer3 = pendingChanges.get(appId);
99761
99945
  if (timer3) clearTimeout(timer3);
99762
99946
  pendingChanges.set(
@@ -99827,7 +100011,7 @@ function getInstanceState(appId, workspace = "") {
99827
100011
  const stored = readRow(appId, workspace);
99828
100012
  if (stored) return stored;
99829
100013
  if (workspace === "") {
99830
- const legacyFile = path6.join(appDir(appId), "state.json");
100014
+ const legacyFile = path7.join(appDir(appId), "state.json");
99831
100015
  if (fs3.existsSync(legacyFile)) {
99832
100016
  const legacy = readState(appId);
99833
100017
  const imported = { pinned: legacy.pinned, data: legacy.data, version: 1 };
@@ -99860,9 +100044,9 @@ function resolveToolWorkspace(workspace) {
99860
100044
  const rows = getDb().prepare("SELECT path, deleted FROM workspaces").all();
99861
100045
  const active = rows.filter((w) => !w.deleted).map((w) => w.path);
99862
100046
  if (active.includes(workspace)) return workspace;
99863
- const cwd = path6.isAbsolute(workspace) ? path6.resolve(workspace) : "";
100047
+ const cwd = path7.isAbsolute(workspace) ? path7.resolve(workspace) : "";
99864
100048
  if (isInAppFolder(cwd)) return "";
99865
- const covering = rows.filter((w) => cwd === w.path || cwd.startsWith(w.path + path6.sep)).sort((a, b) => b.path.length - a.path.length)[0];
100049
+ const covering = rows.filter((w) => cwd === w.path || cwd.startsWith(w.path + path7.sep)).sort((a, b) => b.path.length - a.path.length)[0];
99866
100050
  if (covering && !covering.deleted) return covering.path;
99867
100051
  throw new Error(`Unknown workspace: ${workspace}. Known workspaces: ${active.join(", ") || "none"}`);
99868
100052
  }
@@ -99889,7 +100073,7 @@ function importAppInstances(appId, instances) {
99889
100073
  import fs5 from "node:fs";
99890
100074
 
99891
100075
  // src/apps/app-sessions.ts
99892
- import path8 from "node:path";
100076
+ import path9 from "node:path";
99893
100077
 
99894
100078
  // src/sidecar/transcript-locator.ts
99895
100079
  import { existsSync as existsSync2, readdirSync } from "node:fs";
@@ -99975,7 +100159,7 @@ function locateTranscriptCached(session) {
99975
100159
  import crypto2 from "node:crypto";
99976
100160
  import fs4 from "node:fs";
99977
100161
  import os5 from "node:os";
99978
- import path7 from "node:path";
100162
+ import path8 from "node:path";
99979
100163
  var APP_FILE_MAX_BYTES = 5 * 1024 * 1024;
99980
100164
  var APP_FILE_TYPES = {
99981
100165
  "image/png": "png",
@@ -100000,11 +100184,11 @@ function setAppFilesRootOverride(root) {
100000
100184
  rootOverride2 = root;
100001
100185
  }
100002
100186
  function appFilesRoot() {
100003
- return rootOverride2 ?? process.env.AGENT_PANE_APP_FILES_DIR ?? path7.join(os5.homedir(), ".repoburg", "agent-pane", "app-files");
100187
+ return rootOverride2 ?? process.env.AGENT_PANE_APP_FILES_DIR ?? path8.join(os5.homedir(), ".repoburg", "agent-pane", "app-files");
100004
100188
  }
100005
100189
  function appFilesDir(appId) {
100006
100190
  if (!APP_ID_RE.test(appId)) throw new AppFileError("Invalid app id", 400);
100007
- return path7.join(appFilesRoot(), appId);
100191
+ return path8.join(appFilesRoot(), appId);
100008
100192
  }
100009
100193
  function appFileUrl(appId, fileId) {
100010
100194
  return `/api/apps/${appId}/files/${fileId}`;
@@ -100065,7 +100249,7 @@ function saveAppFile(appId, upload) {
100065
100249
  const type = sniffImageType(bytes);
100066
100250
  if (!type) throw new AppFileError(`The file is not a ${ACCEPTED} image`, 400);
100067
100251
  const fileId = `${crypto2.createHash("sha256").update(bytes).digest("hex")}.${APP_FILE_TYPES[type]}`;
100068
- const file2 = path7.join(dir, fileId);
100252
+ const file2 = path8.join(dir, fileId);
100069
100253
  if (!fs4.existsSync(file2)) {
100070
100254
  fs4.mkdirSync(dir, { recursive: true });
100071
100255
  const tmp = `${file2}.${process.pid}.${crypto2.randomBytes(4).toString("hex")}.tmp`;
@@ -100097,7 +100281,7 @@ function getAppFile(appId, ref) {
100097
100281
  if (!APP_ID_RE.test(appId)) return null;
100098
100282
  const fileId = appFileRefId(appId, ref);
100099
100283
  if (!fileId) return null;
100100
- const file2 = path7.join(appFilesDir(appId), fileId);
100284
+ const file2 = path8.join(appFilesDir(appId), fileId);
100101
100285
  try {
100102
100286
  const stat2 = fs4.statSync(file2);
100103
100287
  if (!stat2.isFile()) return null;
@@ -100109,7 +100293,7 @@ function getAppFile(appId, ref) {
100109
100293
  function readAppFileData(appId, fileId) {
100110
100294
  if (!APP_ID_RE.test(appId) || !APP_FILE_ID_RE.test(fileId)) return null;
100111
100295
  try {
100112
- return { bytes: fs4.readFileSync(path7.join(appFilesDir(appId), fileId)), type: fileType(fileId) };
100296
+ return { bytes: fs4.readFileSync(path8.join(appFilesDir(appId), fileId)), type: fileType(fileId) };
100113
100297
  } catch {
100114
100298
  return null;
100115
100299
  }
@@ -100137,7 +100321,7 @@ function writeImportedAppFiles(appId, files) {
100137
100321
  const dir = appFilesDir(appId);
100138
100322
  fs4.mkdirSync(dir, { recursive: true });
100139
100323
  for (const [fileId, bytes] of files) {
100140
- const file2 = path7.join(dir, fileId);
100324
+ const file2 = path8.join(dir, fileId);
100141
100325
  if (!fs4.existsSync(file2)) fs4.writeFileSync(file2, bytes);
100142
100326
  }
100143
100327
  }
@@ -100242,7 +100426,7 @@ function appSessionInfo(appId, sessionId) {
100242
100426
  function sessionVisibleTo(session, appId, workspace) {
100243
100427
  if (!workspace) return true;
100244
100428
  const cwd = session.cwd;
100245
- if (cwd && (cwd === workspace || cwd.startsWith(workspace.endsWith(path8.sep) ? workspace : workspace + path8.sep))) {
100429
+ if (cwd && (cwd === workspace || cwd.startsWith(workspace.endsWith(path9.sep) ? workspace : workspace + path9.sep))) {
100246
100430
  return true;
100247
100431
  }
100248
100432
  return session.origin_app_workspace === workspace && openedByApp(session, appId);
@@ -100462,7 +100646,7 @@ function stopAppAlarms() {
100462
100646
 
100463
100647
  // src/apps/app-compile.ts
100464
100648
  import vm from "node:vm";
100465
- import path9 from "node:path";
100649
+ import path10 from "node:path";
100466
100650
  import ts from "typescript";
100467
100651
 
100468
100652
  // src/apps/app-lint.ts
@@ -100768,10 +100952,10 @@ declare const AgentPane: {
100768
100952
  fileUrl(ref: AgentPaneFileRef): string;
100769
100953
  };
100770
100954
  `;
100771
- var cache = /* @__PURE__ */ new Map();
100955
+ var cache2 = /* @__PURE__ */ new Map();
100772
100956
  function invalidateCompiledApp(appId) {
100773
- if (!appId) cache.clear();
100774
- else cache.delete(appId);
100957
+ if (!appId) cache2.clear();
100958
+ else cache2.delete(appId);
100775
100959
  }
100776
100960
  function tsDiagnosticToFile(file2, d) {
100777
100961
  if (!d.file) return null;
@@ -100891,15 +101075,15 @@ function typeCheckModules(appId, modules) {
100891
101075
  };
100892
101076
  const host = ts.createCompilerHost(options);
100893
101077
  const origReadFile = host.readFile.bind(host);
100894
- host.readFile = (fname) => path9.basename(fname) === BRIDGE_DTS_FILE ? BRIDGE_DTS : origReadFile(fname);
101078
+ host.readFile = (fname) => path10.basename(fname) === BRIDGE_DTS_FILE ? BRIDGE_DTS : origReadFile(fname);
100895
101079
  host.writeFile = () => {
100896
101080
  };
100897
- const bridgePath = path9.join(dir, BRIDGE_DTS_FILE);
100898
- const rootNames = [...modules.map((m) => path9.join(dir, m.file)), bridgePath];
101081
+ const bridgePath = path10.join(dir, BRIDGE_DTS_FILE);
101082
+ const rootNames = [...modules.map((m) => path10.join(dir, m.file)), bridgePath];
100899
101083
  const program = ts.createProgram(rootNames, options, host);
100900
101084
  const out = [];
100901
101085
  for (const mod of modules) {
100902
- const sf = program.getSourceFile(path9.join(dir, mod.file));
101086
+ const sf = program.getSourceFile(path10.join(dir, mod.file));
100903
101087
  if (!sf) continue;
100904
101088
  out.push(
100905
101089
  ...[...program.getSyntacticDiagnostics(sf), ...program.getSemanticDiagnostics(sf)].map((d) => tsDiagnosticToFile(mod.file, d)).filter((d) => d !== null)
@@ -100926,7 +101110,7 @@ function checkJsSyntax(js) {
100926
101110
  }
100927
101111
  }
100928
101112
  function compileAppJs(appId) {
100929
- const cached3 = cache.get(appId);
101113
+ const cached3 = cache2.get(appId);
100930
101114
  if (cached3) return cached3;
100931
101115
  const tsSource = readAppFile(appId, APP_TS);
100932
101116
  let result;
@@ -100974,7 +101158,7 @@ function compileAppJs(appId) {
100974
101158
  readManifest(appId)?.icon
100975
101159
  )
100976
101160
  );
100977
- cache.set(appId, result);
101161
+ cache2.set(appId, result);
100978
101162
  return result;
100979
101163
  }
100980
101164
 
@@ -101476,7 +101660,7 @@ function anyAppHasTools() {
101476
101660
 
101477
101661
  // src/apps/app-zip.ts
101478
101662
  import fs6 from "node:fs";
101479
- import path10 from "node:path";
101663
+ import path11 from "node:path";
101480
101664
 
101481
101665
  // src/apps/zip.ts
101482
101666
  import zlib from "node:zlib";
@@ -101648,7 +101832,7 @@ function collectAppFiles(id) {
101648
101832
  if (isSkipped(entry.name)) continue;
101649
101833
  const relPath = rel ? `${rel}/${entry.name}` : entry.name;
101650
101834
  if (!rel && entry.name === "state.json") continue;
101651
- const full = path10.join(dir, entry.name);
101835
+ const full = path11.join(dir, entry.name);
101652
101836
  if (entry.isDirectory()) walk(full, relPath);
101653
101837
  else if (entry.isFile()) out.push({ name: `${id}/${relPath}`, data: fs6.readFileSync(full) });
101654
101838
  }
@@ -101664,7 +101848,7 @@ function collectAppData(id) {
101664
101848
  for (const fileId of listAppFileIds(id)) {
101665
101849
  out.push({
101666
101850
  name: `${id}/${APP_DATA_DIR}/files/${fileId}`,
101667
- data: fs6.readFileSync(path10.join(appFilesDir(id), fileId))
101851
+ data: fs6.readFileSync(path11.join(appFilesDir(id), fileId))
101668
101852
  });
101669
101853
  }
101670
101854
  return out;
@@ -101691,7 +101875,7 @@ function parseAppData(entries) {
101691
101875
  const instances = doc.instances.map((item) => {
101692
101876
  const inst = item;
101693
101877
  const workspace = inst && typeof inst.workspace === "string" ? inst.workspace : null;
101694
- const valid = workspace !== null && (workspace === "" || path10.isAbsolute(workspace)) && !seen.has(workspace) && (inst.data === null || typeof inst.data === "object" && !Array.isArray(inst.data));
101878
+ const valid = workspace !== null && (workspace === "" || path11.isAbsolute(workspace)) && !seen.has(workspace) && (inst.data === null || typeof inst.data === "object" && !Array.isArray(inst.data));
101695
101879
  if (!valid) throw new AppZipError(`${APP_DATA_DIR}/data.json has an invalid instance`, 400);
101696
101880
  seen.add(workspace);
101697
101881
  return { workspace, pinned: inst.pinned === true, data: inst.data };
@@ -101780,7 +101964,7 @@ function rehomeInstances(data, id) {
101780
101964
  const newDir = appFilesDir(id);
101781
101965
  const oldDir = data.filesDir?.replace(/[\\/]+$/, "");
101782
101966
  if (oldDir && oldDir !== newDir) {
101783
- swaps.push([`${oldDir}/`, `${newDir}${path10.sep}`], [`${oldDir}\\`, `${newDir}${path10.sep}`]);
101967
+ swaps.push([`${oldDir}/`, `${newDir}${path11.sep}`], [`${oldDir}\\`, `${newDir}${path11.sep}`]);
101784
101968
  }
101785
101969
  if (swaps.length === 0) return data.instances;
101786
101970
  const replace = (s) => swaps.reduce((out, [from, to]) => out.split(from).join(to), s);
@@ -101794,15 +101978,15 @@ function importAppZip(id, buf, opts = {}) {
101794
101978
  if (readManifest(id) || fs6.existsSync(appDir(id))) throw new AppZipError("App already exists", 409);
101795
101979
  const withData = opts.data ? data : null;
101796
101980
  ensureAppsRoot();
101797
- const tmp = path10.join(appsRoot(), `.import-${v4_default()}`);
101981
+ const tmp = path11.join(appsRoot(), `.import-${v4_default()}`);
101798
101982
  try {
101799
101983
  for (const [rel, bytes] of files) {
101800
- const file2 = path10.join(tmp, ...rel.split("/"));
101801
- fs6.mkdirSync(path10.dirname(file2), { recursive: true });
101984
+ const file2 = path11.join(tmp, ...rel.split("/"));
101985
+ fs6.mkdirSync(path11.dirname(file2), { recursive: true });
101802
101986
  fs6.writeFileSync(file2, bytes);
101803
101987
  }
101804
101988
  if (!files.has("manifest.json")) {
101805
- fs6.writeFileSync(path10.join(tmp, "manifest.json"), JSON.stringify({ title: id }, null, 2));
101989
+ fs6.writeFileSync(path11.join(tmp, "manifest.json"), JSON.stringify({ title: id }, null, 2));
101806
101990
  } else if (!readManifestIn(tmp)) {
101807
101991
  throw new AppZipError('manifest.json is invalid (it needs at least a "title" string)', 400);
101808
101992
  }
@@ -101914,7 +102098,7 @@ async function registerAppRoutes(fastify, opts) {
101914
102098
  try {
101915
102099
  for (const entry of fs7.readdirSync(exRoot, { withFileTypes: true })) {
101916
102100
  if (!entry.isDirectory() || !APP_ID_RE.test(entry.name)) continue;
101917
- const manifest = readManifestIn(path11.join(exRoot, entry.name));
102101
+ const manifest = readManifestIn(path12.join(exRoot, entry.name));
101918
102102
  if (!manifest) continue;
101919
102103
  out.push({
101920
102104
  id: entry.name,
@@ -101935,7 +102119,7 @@ async function registerAppRoutes(fastify, opts) {
101935
102119
  if (!APP_ID_RE.test(id)) return reply.code(400).send({ error: "Invalid app id" });
101936
102120
  const exRoot = examplesRoot();
101937
102121
  if (!exRoot) return reply.code(404).send({ error: "Examples catalog not available" });
101938
- const src = path11.join(exRoot, id);
102122
+ const src = path12.join(exRoot, id);
101939
102123
  if (!readManifestIn(src)) return reply.code(404).send({ error: "Example not found" });
101940
102124
  if (readManifest(id)) return reply.code(409).send({ error: "App already installed" });
101941
102125
  ensureAppsRoot();
@@ -101974,7 +102158,7 @@ async function registerAppRoutes(fastify, opts) {
101974
102158
  fs7.mkdirSync(dir, { recursive: true });
101975
102159
  const cleanTitle2 = title.trim();
101976
102160
  fs7.writeFileSync(
101977
- path11.join(dir, "manifest.json"),
102161
+ path12.join(dir, "manifest.json"),
101978
102162
  JSON.stringify(
101979
102163
  {
101980
102164
  title: cleanTitle2,
@@ -101985,8 +102169,8 @@ async function registerAppRoutes(fastify, opts) {
101985
102169
  2
101986
102170
  )
101987
102171
  );
101988
- fs7.writeFileSync(path11.join(dir, "index.html"), SKELETON_HTML.replaceAll("__TITLE__", cleanTitle2));
101989
- fs7.writeFileSync(path11.join(dir, "app.ts"), SKELETON_TS);
102172
+ fs7.writeFileSync(path12.join(dir, "index.html"), SKELETON_HTML.replaceAll("__TITLE__", cleanTitle2));
102173
+ fs7.writeFileSync(path12.join(dir, "app.ts"), SKELETON_TS);
101990
102174
  return { ok: true, id };
101991
102175
  }
101992
102176
  );
@@ -102550,16 +102734,16 @@ async function loadFresh(timezone) {
102550
102734
  ]);
102551
102735
  return { data: parseCcusageJson(stdout), generatedAt: Date.now() };
102552
102736
  }
102553
- var cache2 = /* @__PURE__ */ new Map();
102737
+ var cache3 = /* @__PURE__ */ new Map();
102554
102738
  var inflight = /* @__PURE__ */ new Map();
102555
102739
  function loadCcusage(timezone, fresh) {
102556
- const cached3 = cache2.get(timezone);
102740
+ const cached3 = cache3.get(timezone);
102557
102741
  if (cached3 && !fresh) return Promise.resolve(cached3);
102558
102742
  let run = inflight.get(timezone);
102559
102743
  if (!run) {
102560
102744
  run = loadFresh(timezone).then((result) => {
102561
- if (cache2.size >= 4) cache2.clear();
102562
- cache2.set(timezone, result);
102745
+ if (cache3.size >= 4) cache3.clear();
102746
+ cache3.set(timezone, result);
102563
102747
  return result;
102564
102748
  }).finally(() => inflight.delete(timezone));
102565
102749
  inflight.set(timezone, run);
@@ -102964,7 +103148,7 @@ async function registerUsageRoutes(fastify) {
102964
103148
 
102965
103149
  // src/claude/session-import.ts
102966
103150
  import { readFile as readFile2, realpath } from "node:fs/promises";
102967
- import path12 from "node:path";
103151
+ import path13 from "node:path";
102968
103152
  import { getSessionInfo, listSessions } from "@anthropic-ai/claude-agent-sdk";
102969
103153
 
102970
103154
  // src/claude/widget-tool.ts
@@ -118009,7 +118193,7 @@ async function realDir(dir) {
118009
118193
  }
118010
118194
  }
118011
118195
  async function sameDir(a, realB) {
118012
- const realA = await realDir(a) ?? path12.resolve(a);
118196
+ const realA = await realDir(a) ?? path13.resolve(a);
118013
118197
  return realA === realB;
118014
118198
  }
118015
118199
  function knownClaudeSessionIds(db2) {
@@ -118179,22 +118363,22 @@ async function registerClaudeSessionRoutes(fastify) {
118179
118363
 
118180
118364
  // src/codex/session-import.ts
118181
118365
  import { realpath as realpath2 } from "node:fs/promises";
118182
- import path14 from "node:path";
118366
+ import path15 from "node:path";
118183
118367
 
118184
118368
  // src/apps/register-mcp.ts
118185
118369
  import fs8 from "node:fs";
118186
- import path13 from "node:path";
118370
+ import path14 from "node:path";
118187
118371
  import { fileURLToPath as fileURLToPath2 } from "node:url";
118188
118372
  var MCP_SERVER_NAME = "agentpane-miniapps";
118189
118373
  function panePublicUrl() {
118190
118374
  return (process.env.AGENT_PANE_PUBLIC_URL || process.env.REPOBURG_DAEMON_URL || "http://localhost:9998").replace(/\/+$/, "");
118191
118375
  }
118192
118376
  function stdioScriptPath() {
118193
- const here = path13.dirname(fileURLToPath2(import.meta.url));
118377
+ const here = path14.dirname(fileURLToPath2(import.meta.url));
118194
118378
  const candidates = [
118195
- path13.resolve(here, "../../scripts/miniapp-mcp-stdio.mjs"),
118379
+ path14.resolve(here, "../../scripts/miniapp-mcp-stdio.mjs"),
118196
118380
  // src/apps/ → backend/scripts
118197
- path13.resolve(here, "../scripts/miniapp-mcp-stdio.mjs")
118381
+ path14.resolve(here, "../scripts/miniapp-mcp-stdio.mjs")
118198
118382
  // dist bundle → backend/scripts
118199
118383
  ];
118200
118384
  for (const candidate of candidates) {
@@ -118453,7 +118637,7 @@ async function realDir2(dir) {
118453
118637
  async function workspaceDirs(workspacePath) {
118454
118638
  const real = await realDir2(workspacePath);
118455
118639
  if (!real) return null;
118456
- const given = path14.resolve(workspacePath);
118640
+ const given = path15.resolve(workspacePath);
118457
118641
  return given === real ? [real] : [given, real];
118458
118642
  }
118459
118643
  function titleOf2(thread) {
@@ -118693,7 +118877,7 @@ async function registerCodexSessionRoutes(fastify) {
118693
118877
 
118694
118878
  // src/session-host/flags.ts
118695
118879
  import fs9 from "node:fs";
118696
- import path15 from "node:path";
118880
+ import path16 from "node:path";
118697
118881
  var DEFAULT_FLAGS = {
118698
118882
  claude: true,
118699
118883
  codex: true,
@@ -118712,13 +118896,13 @@ function setPaneDataDir(dir) {
118712
118896
  }
118713
118897
  function sessionHostsRoot() {
118714
118898
  const override = process.env.AGENT_PANE_SESSION_HOSTS_DIR;
118715
- if (override) return path15.resolve(override);
118716
- return paneDataDir ? path15.join(paneDataDir, "session-hosts") : null;
118899
+ if (override) return path16.resolve(override);
118900
+ return paneDataDir ? path16.join(paneDataDir, "session-hosts") : null;
118717
118901
  }
118718
118902
  function flagsFilePath() {
118719
118903
  const root = sessionHostsRoot();
118720
- if (process.env.AGENT_PANE_SESSION_HOSTS_DIR) return path15.join(path15.dirname(root), "session-hosts.json");
118721
- return paneDataDir ? path15.join(paneDataDir, "session-hosts.json") : null;
118904
+ if (process.env.AGENT_PANE_SESSION_HOSTS_DIR) return path16.join(path16.dirname(root), "session-hosts.json");
118905
+ return paneDataDir ? path16.join(paneDataDir, "session-hosts.json") : null;
118722
118906
  }
118723
118907
  function readFlagFile(file2) {
118724
118908
  if (!file2) return {};
@@ -118790,7 +118974,7 @@ var LOG_HEADER_LEN = LOG_HEADER_PREFIX.length + LOG_HEADER_DIGITS + 1;
118790
118974
  // src/session-host/registry.ts
118791
118975
  import { randomBytes, randomUUID as randomUUID2 } from "node:crypto";
118792
118976
  import fs11 from "node:fs";
118793
- import path17 from "node:path";
118977
+ import path18 from "node:path";
118794
118978
  import { fileURLToPath as fileURLToPath4 } from "node:url";
118795
118979
 
118796
118980
  // src/session-host/client.ts
@@ -118798,7 +118982,7 @@ import { execFile as execFile3, spawn as spawn4 } from "node:child_process";
118798
118982
  import { EventEmitter as EventEmitter2 } from "node:events";
118799
118983
  import fs10 from "node:fs";
118800
118984
  import net2 from "node:net";
118801
- import path16 from "node:path";
118985
+ import path17 from "node:path";
118802
118986
  import { fileURLToPath as fileURLToPath3 } from "node:url";
118803
118987
  var HostRequestError = class extends Error {
118804
118988
  reply;
@@ -118810,11 +118994,11 @@ var HostRequestError = class extends Error {
118810
118994
  function hostScriptPath() {
118811
118995
  const override = process.env.AGENT_PANE_SESSION_HOST_SCRIPT;
118812
118996
  if (override) return override;
118813
- const here = path16.dirname(fileURLToPath3(import.meta.url));
118997
+ const here = path17.dirname(fileURLToPath3(import.meta.url));
118814
118998
  const candidates = [
118815
- path16.resolve(here, "../../scripts/session-host.mjs"),
118999
+ path17.resolve(here, "../../scripts/session-host.mjs"),
118816
119000
  // src/session-host/ → backend/scripts
118817
- path16.resolve(here, "../scripts/session-host.mjs")
119001
+ path17.resolve(here, "../scripts/session-host.mjs")
118818
119002
  // dist bundle → backend/scripts
118819
119003
  ];
118820
119004
  for (const candidate of candidates) {
@@ -118823,10 +119007,10 @@ function hostScriptPath() {
118823
119007
  return null;
118824
119008
  }
118825
119009
  function hostSocketPath(dir) {
118826
- const direct = path16.join(dir, "sock");
119010
+ const direct = path17.join(dir, "sock");
118827
119011
  if (Buffer.byteLength(direct) < 100) return direct;
118828
119012
  const uid = typeof process.getuid === "function" ? process.getuid() : 0;
118829
- return path16.join("/tmp", `rbsh-${uid}`, path16.basename(dir), "sock");
119013
+ return path17.join("/tmp", `rbsh-${uid}`, path17.basename(dir), "sock");
118830
119014
  }
118831
119015
  function readJson(file2) {
118832
119016
  try {
@@ -118836,10 +119020,10 @@ function readJson(file2) {
118836
119020
  }
118837
119021
  }
118838
119022
  function readHostExit(dir) {
118839
- return readJson(path16.join(dir, "exit.json"));
119023
+ return readJson(path17.join(dir, "exit.json"));
118840
119024
  }
118841
119025
  function readHostChild(dir) {
118842
- return readJson(path16.join(dir, "child.json"));
119026
+ return readJson(path17.join(dir, "child.json"));
118843
119027
  }
118844
119028
  function isPidAlive(pid) {
118845
119029
  if (!pid || pid <= 0) return false;
@@ -119029,7 +119213,7 @@ async function waitForHost(dir, timeoutMs = 1e4) {
119029
119213
  function readLogOldest(dir) {
119030
119214
  let fd = null;
119031
119215
  try {
119032
- fd = fs10.openSync(path16.join(dir, "out.log"), "r");
119216
+ fd = fs10.openSync(path17.join(dir, "out.log"), "r");
119033
119217
  const buf = Buffer.alloc(LOG_HEADER_LEN);
119034
119218
  const n = fs10.readSync(fd, buf, 0, LOG_HEADER_LEN, 0);
119035
119219
  const text2 = buf.subarray(0, n).toString("utf8");
@@ -119046,7 +119230,7 @@ function readHostLog(dir, after) {
119046
119230
  const oldest = readLogOldest(dir);
119047
119231
  if (oldest === null || after < oldest) return null;
119048
119232
  try {
119049
- const all = fs10.readFileSync(path16.join(dir, "out.log"));
119233
+ const all = fs10.readFileSync(path17.join(dir, "out.log"));
119050
119234
  const start = LOG_HEADER_LEN + (after - oldest);
119051
119235
  if (start > all.length) return null;
119052
119236
  return all.subarray(start);
@@ -119060,7 +119244,7 @@ function removeHostDir(dir) {
119060
119244
  } catch (err) {
119061
119245
  console.error(`[session-host] could not remove ${dir}:`, err.message);
119062
119246
  }
119063
- const alias = path16.dirname(hostSocketPath(dir));
119247
+ const alias = path17.dirname(hostSocketPath(dir));
119064
119248
  if (alias !== dir) {
119065
119249
  try {
119066
119250
  fs10.unlinkSync(alias);
@@ -119123,16 +119307,16 @@ function newHostDir() {
119123
119307
  const root = sessionHostsRoot();
119124
119308
  if (!root) throw new Error("session hosts have no directory");
119125
119309
  const id = randomBytes(8).toString("hex");
119126
- return { id, dir: path17.join(root, id) };
119310
+ return { id, dir: path18.join(root, id) };
119127
119311
  }
119128
119312
  var cachedVersion;
119129
119313
  function runtimeVersion() {
119130
119314
  if (cachedVersion !== void 0) return cachedVersion;
119131
119315
  cachedVersion = null;
119132
- const here = path17.dirname(fileURLToPath4(import.meta.url));
119316
+ const here = path18.dirname(fileURLToPath4(import.meta.url));
119133
119317
  for (const rel of ["../../../../package.json", "../../../package.json"]) {
119134
119318
  try {
119135
- const pkg = JSON.parse(fs11.readFileSync(path17.resolve(here, rel), "utf8"));
119319
+ const pkg = JSON.parse(fs11.readFileSync(path18.resolve(here, rel), "utf8"));
119136
119320
  if (pkg.name === "repoburg" && pkg.version) {
119137
119321
  cachedVersion = pkg.version;
119138
119322
  break;
@@ -119145,13 +119329,13 @@ function runtimeVersion() {
119145
119329
  function writeHostMeta(dir, meta3) {
119146
119330
  fs11.mkdirSync(dir, { recursive: true, mode: 448 });
119147
119331
  fs11.chmodSync(dir, 448);
119148
- const tmp = path17.join(dir, "meta.json.tmp");
119332
+ const tmp = path18.join(dir, "meta.json.tmp");
119149
119333
  fs11.writeFileSync(tmp, JSON.stringify(meta3, null, 2) + "\n", { mode: 384 });
119150
- fs11.renameSync(tmp, path17.join(dir, "meta.json"));
119334
+ fs11.renameSync(tmp, path18.join(dir, "meta.json"));
119151
119335
  }
119152
119336
  function readHostMeta(dir) {
119153
119337
  try {
119154
- return JSON.parse(fs11.readFileSync(path17.join(dir, "meta.json"), "utf8"));
119338
+ return JSON.parse(fs11.readFileSync(path18.join(dir, "meta.json"), "utf8"));
119155
119339
  } catch {
119156
119340
  return null;
119157
119341
  }
@@ -119296,7 +119480,7 @@ async function adoptHosts(db2, root, adoption, result) {
119296
119480
  const seen = /* @__PURE__ */ new Set();
119297
119481
  const queue = [];
119298
119482
  for (const id of entries) {
119299
- const dir = path17.join(root, id);
119483
+ const dir = path18.join(root, id);
119300
119484
  try {
119301
119485
  if (!fs11.statSync(dir).isDirectory()) continue;
119302
119486
  } catch {
@@ -119864,7 +120048,7 @@ function mapTokenUsage(data) {
119864
120048
  import { spawn as spawn6 } from "node:child_process";
119865
120049
  import fs12 from "node:fs";
119866
120050
  import os6 from "node:os";
119867
- import path18 from "node:path";
120051
+ import path19 from "node:path";
119868
120052
  import { fileURLToPath as fileURLToPath5 } from "node:url";
119869
120053
  var TABTAPE_MCP_NAME = "tabtape";
119870
120054
  var PLAYWRIGHT_MCP_NAME = "playwright";
@@ -119878,15 +120062,15 @@ function disabled() {
119878
120062
  function tabtapeBaseUrl() {
119879
120063
  return (process.env.AGENT_PANE_TABTAPE_URL || `${sessionHostDaemonUrl()}/tabtape`).replace(/\/+$/, "");
119880
120064
  }
119881
- function playwrightMcpScript(from = path18.dirname(fileURLToPath5(import.meta.url))) {
120065
+ function playwrightMcpScript(from = path19.dirname(fileURLToPath5(import.meta.url))) {
119882
120066
  if (scriptOverride !== void 0) return scriptOverride;
119883
120067
  let dir = from;
119884
120068
  for (let i = 0; i < 6; i++) {
119885
- const script = path18.join(dir, "tabtape", "playwright", "mcp.mjs");
119886
- if (fs12.existsSync(script) && fs12.existsSync(path18.join(dir, "tabtape", "extension", "dist", "manifest.json"))) {
120069
+ const script = path19.join(dir, "tabtape", "playwright", "mcp.mjs");
120070
+ if (fs12.existsSync(script) && fs12.existsSync(path19.join(dir, "tabtape", "extension", "dist", "manifest.json"))) {
119887
120071
  return script;
119888
120072
  }
119889
- const parent = path18.dirname(dir);
120073
+ const parent = path19.dirname(dir);
119890
120074
  if (parent === dir) break;
119891
120075
  dir = parent;
119892
120076
  }
@@ -119928,14 +120112,17 @@ function jsonServerNames(file2, pick2) {
119928
120112
  }
119929
120113
  function claudeConfigFile() {
119930
120114
  if (process.env.AGENT_PANE_CLAUDE_CONFIG_FILE) return process.env.AGENT_PANE_CLAUDE_CONFIG_FILE;
119931
- return path18.join(process.env.CLAUDE_CONFIG_DIR || os6.homedir(), ".claude.json");
120115
+ return path19.join(process.env.CLAUDE_CONFIG_DIR || os6.homedir(), ".claude.json");
119932
120116
  }
119933
120117
  function claudeUserMcpNames(cwd) {
119934
120118
  const file2 = claudeConfigFile();
119935
120119
  return /* @__PURE__ */ new Set([
119936
120120
  ...jsonServerNames(file2, (json2) => json2.mcpServers),
119937
- ...jsonServerNames(file2, (json2) => json2.projects?.[cwd]?.mcpServers),
119938
- ...jsonServerNames(path18.join(cwd, ".mcp.json"), (json2) => json2.mcpServers)
120121
+ ...jsonServerNames(
120122
+ file2,
120123
+ (json2) => json2.projects?.[cwd]?.mcpServers
120124
+ ),
120125
+ ...jsonServerNames(path19.join(cwd, ".mcp.json"), (json2) => json2.mcpServers)
119939
120126
  ]);
119940
120127
  }
119941
120128
  async function claudeBrowserMcpServers(cwd) {
@@ -119958,8 +120145,11 @@ function tomlServerNames(file2) {
119958
120145
  return names;
119959
120146
  }
119960
120147
  function codexUserMcpNames(cwd) {
119961
- const home = process.env.CODEX_HOME || path18.join(os6.homedir(), ".codex");
119962
- return /* @__PURE__ */ new Set([...tomlServerNames(path18.join(home, "config.toml")), ...tomlServerNames(path18.join(cwd, ".codex", "config.toml"))]);
120148
+ const home = process.env.CODEX_HOME || path19.join(os6.homedir(), ".codex");
120149
+ return /* @__PURE__ */ new Set([
120150
+ ...tomlServerNames(path19.join(home, "config.toml")),
120151
+ ...tomlServerNames(path19.join(cwd, ".codex", "config.toml"))
120152
+ ]);
119963
120153
  }
119964
120154
  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.`;
119965
120155
  async function codexBrowserMcp(cwd) {
@@ -119984,15 +120174,29 @@ async function codexBrowserMcp(cwd) {
119984
120174
  }
119985
120175
  return { args, instructions: mcp.tabtape ? CODEX_BROWSER_CHECK_INSTRUCTIONS : null };
119986
120176
  }
120177
+ async function repoburgBrowserMcpServers(_cwd) {
120178
+ const mcp = await browserMcp(/* @__PURE__ */ new Set());
120179
+ const servers = [];
120180
+ if (mcp.tabtape) {
120181
+ servers.push({
120182
+ name: TABTAPE_MCP_NAME,
120183
+ type: "http",
120184
+ url: mcp.tabtape,
120185
+ instructions: CODEX_BROWSER_CHECK_INSTRUCTIONS
120186
+ });
120187
+ }
120188
+ if (mcp.playwright) servers.push({ name: PLAYWRIGHT_MCP_NAME, type: "stdio", ...mcp.playwright });
120189
+ return servers;
120190
+ }
119987
120191
  var prepared = false;
119988
120192
  function chromiumDownloadCommand(execPath = process.execPath) {
119989
- const bin = path18.dirname(execPath);
119990
- const npx = path18.join(bin, process.platform === "win32" ? "npx.cmd" : "npx");
120193
+ const bin = path19.dirname(execPath);
120194
+ const npx = path19.join(bin, process.platform === "win32" ? "npx.cmd" : "npx");
119991
120195
  if (!fs12.existsSync(npx)) return null;
119992
120196
  return {
119993
120197
  command: npx,
119994
120198
  args: ["-y", "@playwright/mcp@latest", "install-browser", "chromium"],
119995
- env: { ...process.env, PATH: [bin, process.env.PATH].filter(Boolean).join(path18.delimiter) }
120199
+ env: { ...process.env, PATH: [bin, process.env.PATH].filter(Boolean).join(path19.delimiter) }
119996
120200
  };
119997
120201
  }
119998
120202
  function prepareBrowserMcp() {
@@ -123364,25 +123568,25 @@ function upsertItem(db2, desc, sessionId, turnId, status, broadcastEvent) {
123364
123568
  }
123365
123569
  async function interruptTurn2(sessionId, threadId) {
123366
123570
  let entry;
123367
- let entryKey = null;
123571
+ let entryKey2 = null;
123368
123572
  if (threadId) {
123369
- entryKey = `${sessionId}:thread:${threadId}`;
123370
- entry = sessionMap2.get(entryKey);
123573
+ entryKey2 = `${sessionId}:thread:${threadId}`;
123574
+ entry = sessionMap2.get(entryKey2);
123371
123575
  } else {
123372
123576
  entry = sessionMap2.get(sessionId);
123373
- entryKey = sessionId;
123577
+ entryKey2 = sessionId;
123374
123578
  if (!entry || !entry.turnId) {
123375
- entryKey = null;
123579
+ entryKey2 = null;
123376
123580
  for (const [key, threadEntry] of sessionMap2) {
123377
123581
  if (key.startsWith(`${sessionId}:thread:`) && threadEntry.turnId) {
123378
123582
  entry = threadEntry;
123379
- entryKey = key;
123583
+ entryKey2 = key;
123380
123584
  break;
123381
123585
  }
123382
123586
  }
123383
123587
  }
123384
123588
  }
123385
- if (entry && entry.turnId && entryKey) {
123589
+ if (entry && entry.turnId && entryKey2) {
123386
123590
  const turnId = entry.turnId;
123387
123591
  try {
123388
123592
  await entry.query.interrupt();
@@ -123405,7 +123609,7 @@ async function interruptTurn2(sessionId, threadId) {
123405
123609
  entry.promptQueue.close();
123406
123610
  entry.query.close();
123407
123611
  streamingMessageIds.delete(turnId);
123408
- sessionMap2.delete(entryKey);
123612
+ sessionMap2.delete(entryKey2);
123409
123613
  dropBackgroundTasks(sessionId, entry);
123410
123614
  }
123411
123615
  }
@@ -124100,7 +124304,7 @@ var RepoburgHttpClient = class {
124100
124304
  return this.request("POST", "/sessions", dto);
124101
124305
  }
124102
124306
  async patchSession(id, dto) {
124103
- return this.request("PATCH", `/sessions/${id}`, dto);
124307
+ return this.request("PUT", `/sessions/${id}`, dto);
124104
124308
  }
124105
124309
  async getSession(id) {
124106
124310
  return this.request("GET", `/sessions/${id}`);
@@ -124109,19 +124313,13 @@ var RepoburgHttpClient = class {
124109
124313
  return this.request("POST", `/sessions/${sessionId}/inputs`, dto);
124110
124314
  }
124111
124315
  async getInputWithActions(sessionId, inputId) {
124112
- return this.request(
124113
- "GET",
124114
- `/sessions/${sessionId}/inputs/${inputId}/actions-with-logs`
124115
- );
124316
+ return this.request("GET", `/sessions/${sessionId}/inputs/${inputId}/actions-with-logs`);
124116
124317
  }
124117
124318
  async getSessionInputs(sessionId) {
124118
124319
  return this.request("GET", `/sessions/${sessionId}/inputs`);
124119
124320
  }
124120
124321
  async deleteInputsUntilHere(sessionId, anchorInputId) {
124121
- await this.request(
124122
- "DELETE",
124123
- `/sessions/${sessionId}/inputs/${anchorInputId}/until-here`
124124
- );
124322
+ await this.request("DELETE", `/sessions/${sessionId}/inputs/${anchorInputId}/until-here`);
124125
124323
  }
124126
124324
  async deleteSession(id) {
124127
124325
  await this.request("DELETE", `/sessions/${id}`);
@@ -124132,11 +124330,24 @@ var RepoburgHttpClient = class {
124132
124330
  });
124133
124331
  }
124134
124332
  async cancel(sessionId) {
124333
+ return this.request("POST", `/streaming/${sessionId}/cancel`);
124334
+ }
124335
+ async listBackgroundTasks(sessionId) {
124336
+ const result = await this.request(
124337
+ "GET",
124338
+ `/sessions/${sessionId}/background-tasks`
124339
+ );
124340
+ return result.tasks ?? [];
124341
+ }
124342
+ async stopBackgroundTask(sessionId, taskId) {
124135
124343
  return this.request(
124136
124344
  "POST",
124137
- `/streaming/${sessionId}/cancel`
124345
+ `/sessions/${sessionId}/background-tasks/${encodeURIComponent(taskId)}/stop`
124138
124346
  );
124139
124347
  }
124348
+ async setSessionMcpServers(sessionId, servers) {
124349
+ await this.request("PUT", `/sessions/${sessionId}/mcp-servers`, { servers });
124350
+ }
124140
124351
  async getModels() {
124141
124352
  const result = await this.request("GET", "/llm-provider/models");
124142
124353
  return result.models ?? [];
@@ -124166,154 +124377,6 @@ var RepoburgHttpClient = class {
124166
124377
  }
124167
124378
  };
124168
124379
 
124169
- // src/repoburg/backend-resolver.ts
124170
- import path19 from "node:path";
124171
- var HEALTH_POLL_INTERVAL_MS = 1e3;
124172
- var HEALTH_TIMEOUT_MS = 3e4;
124173
- function daemonBaseUrl() {
124174
- return (process.env.REPOBURG_DAEMON_URL || "http://localhost:9998").replace(/\/+$/, "");
124175
- }
124176
- var HttpError = class extends Error {
124177
- constructor(status, body, url2) {
124178
- super(`${url2} failed: ${status} ${body}`);
124179
- this.status = status;
124180
- this.body = body;
124181
- this.url = url2;
124182
- }
124183
- };
124184
- async function fetchJson(url2, init, timeoutMs = 5e3) {
124185
- const controller = new AbortController();
124186
- const timer3 = setTimeout(() => controller.abort(), timeoutMs);
124187
- let response;
124188
- try {
124189
- response = await fetch(url2, { ...init, signal: controller.signal });
124190
- } finally {
124191
- clearTimeout(timer3);
124192
- }
124193
- const text2 = await response.text();
124194
- if (!response.ok) {
124195
- throw new HttpError(response.status, text2, url2);
124196
- }
124197
- try {
124198
- return JSON.parse(text2);
124199
- } catch {
124200
- throw new Error(`Unexpected non-JSON response from ${url2}`);
124201
- }
124202
- }
124203
- function daemonErrorMessage(err) {
124204
- if (err instanceof HttpError) {
124205
- try {
124206
- const parsed = JSON.parse(err.body);
124207
- return parsed.message || parsed.error || err.body;
124208
- } catch {
124209
- return err.body;
124210
- }
124211
- }
124212
- return err.message;
124213
- }
124214
- var resolvedCache = /* @__PURE__ */ new Map();
124215
- function invalidateBackend(baseUrl) {
124216
- for (const [key, value] of resolvedCache) {
124217
- if (value.baseUrl === baseUrl) resolvedCache.delete(key);
124218
- }
124219
- }
124220
- async function backendHealthy(baseUrl, expectedPath) {
124221
- try {
124222
- const health = await fetchJson(`${baseUrl}/health`, void 0, 2e3);
124223
- if (health.status !== "ok") return false;
124224
- if (expectedPath && health.projectPath) {
124225
- return path19.resolve(health.projectPath) === path19.resolve(expectedPath);
124226
- }
124227
- return true;
124228
- } catch {
124229
- return false;
124230
- }
124231
- }
124232
- async function waitForHealthy(baseUrl, name, expectedPath) {
124233
- const deadline = Date.now() + HEALTH_TIMEOUT_MS;
124234
- while (Date.now() < deadline) {
124235
- if (await backendHealthy(baseUrl, expectedPath)) return;
124236
- await new Promise((resolve) => setTimeout(resolve, HEALTH_POLL_INTERVAL_MS));
124237
- }
124238
- throw new Error(
124239
- `Backend '${name}' on ${baseUrl} did not become healthy within ${HEALTH_TIMEOUT_MS / 1e3}s. Check daemon logs: repoburg logs ${name}`
124240
- );
124241
- }
124242
- function serviceBaseUrl(service) {
124243
- return `http://localhost:${service.port}`;
124244
- }
124245
- function coveringService(services, absPath) {
124246
- return services.filter((s) => absPath === s.path || absPath.startsWith(s.path + path19.sep)).sort((a, b) => b.path.length - a.path.length)[0];
124247
- }
124248
- async function restartService(daemon, name) {
124249
- try {
124250
- await fetchJson(`${daemon}/services/${name}/restart`, { method: "POST" });
124251
- } catch (err) {
124252
- throw new Error(`Daemon failed to restart backend '${name}': ${daemonErrorMessage(err)}`);
124253
- }
124254
- }
124255
- async function startService(daemon, projectPath) {
124256
- try {
124257
- return await fetchJson(`${daemon}/services/start`, {
124258
- method: "POST",
124259
- headers: { "Content-Type": "application/json" },
124260
- body: JSON.stringify({ path: projectPath })
124261
- });
124262
- } catch (err) {
124263
- throw new Error(`Daemon failed to start backend for ${projectPath}: ${daemonErrorMessage(err)}`);
124264
- }
124265
- }
124266
- function cache3(absPath, service) {
124267
- const resolved = {
124268
- baseUrl: serviceBaseUrl(service),
124269
- port: service.port,
124270
- name: service.name,
124271
- servesPath: service.path
124272
- };
124273
- resolvedCache.set(absPath, resolved);
124274
- return resolved;
124275
- }
124276
- async function resolveBackendUrl(projectPath, opts = {}) {
124277
- const autoStart = opts.autoStart !== false;
124278
- const envUrl = process.env.REPOBURG_BACKEND_URL;
124279
- if (envUrl) {
124280
- return { baseUrl: envUrl.replace(/\/+$/, ""), port: 0, name: "REPOBURG_BACKEND_URL" };
124281
- }
124282
- const absPath = path19.resolve(projectPath);
124283
- const daemon = daemonBaseUrl();
124284
- const cached3 = resolvedCache.get(absPath);
124285
- if (cached3 && await backendHealthy(cached3.baseUrl, cached3.servesPath ?? absPath)) {
124286
- return cached3;
124287
- }
124288
- try {
124289
- await fetchJson(`${daemon}/health`, void 0, 3e3);
124290
- } catch {
124291
- throw new Error(
124292
- `Repoburg daemon not reachable at ${daemon}. Start it with 'repoburg-daemon', or set REPOBURG_BACKEND_URL to a running backend.`
124293
- );
124294
- }
124295
- const services = await fetchJson(`${daemon}/services`);
124296
- const match = coveringService(services, absPath);
124297
- if (match && match.status === "running") {
124298
- if (await backendHealthy(serviceBaseUrl(match), match.path)) {
124299
- return cache3(absPath, match);
124300
- }
124301
- if (!autoStart) return null;
124302
- await restartService(daemon, match.name);
124303
- await waitForHealthy(serviceBaseUrl(match), match.name, match.path);
124304
- return cache3(absPath, match);
124305
- }
124306
- if (!autoStart) return null;
124307
- if (match) {
124308
- await restartService(daemon, match.name);
124309
- await waitForHealthy(serviceBaseUrl(match), match.name, match.path);
124310
- return cache3(absPath, match);
124311
- }
124312
- const service = await startService(daemon, absPath);
124313
- await waitForHealthy(serviceBaseUrl(service), service.name, absPath);
124314
- return cache3(absPath, service);
124315
- }
124316
-
124317
124380
  // src/repoburg/action-mapping.ts
124318
124381
  function parseJsonArgs(raw) {
124319
124382
  if (!raw) return null;
@@ -124696,6 +124759,96 @@ async function runThrowawayPrompt(client, options) {
124696
124759
  }
124697
124760
  }
124698
124761
 
124762
+ // src/repoburg/repoburg-tasks.ts
124763
+ import { readFileSync as readFileSync5 } from "node:fs";
124764
+ import { isAbsolute, join as join6 } from "node:path";
124765
+ var TASK_OUTPUT_MAX2 = 2e4;
124766
+ var REPOBURG_TASK_TYPE = "background_terminal";
124767
+ var NOT_BACKGROUND_COMMAND = `NOT (type = 'background_task' AND json_valid(COALESCE(data, '{}'))
124768
+ AND json_extract(data, '$.task_type') = '${REPOBURG_TASK_TYPE}')`;
124769
+ function taskItemExternalId(taskId) {
124770
+ return `task-${taskId}`;
124771
+ }
124772
+ function taskOutputPath(outputFile, cwd) {
124773
+ if (!outputFile) return null;
124774
+ if (isAbsolute(outputFile)) return outputFile;
124775
+ return cwd ? join6(cwd, outputFile) : null;
124776
+ }
124777
+ function readTaskOutput(path21) {
124778
+ if (!path21) return "";
124779
+ try {
124780
+ const text2 = readFileSync5(path21, "utf-8");
124781
+ return text2.length > TASK_OUTPUT_MAX2 ? text2.slice(-TASK_OUTPUT_MAX2) : text2;
124782
+ } catch {
124783
+ return "";
124784
+ }
124785
+ }
124786
+ function findTaskItem2(db2, sessionId, taskId) {
124787
+ return db2.prepare(
124788
+ `SELECT i.* FROM items i JOIN turns t ON t.id = i.turn_id
124789
+ WHERE t.session_id = ? AND i.external_item_id = ? AND i.type = 'background_task'
124790
+ ORDER BY i.created_at DESC LIMIT 1`
124791
+ ).get(sessionId, taskItemExternalId(taskId));
124792
+ }
124793
+ function openTaskItem2(db2, sessionId, turnId, task) {
124794
+ if (findTaskItem2(db2, sessionId, task.task_id)) return;
124795
+ insertItem(
124796
+ db2,
124797
+ sessionId,
124798
+ turnId,
124799
+ taskItemExternalId(task.task_id),
124800
+ "background_task",
124801
+ {
124802
+ task_id: task.task_id,
124803
+ description: task.description,
124804
+ task_type: REPOBURG_TASK_TYPE,
124805
+ subagent_type: null,
124806
+ prompt: task.command,
124807
+ status: "running",
124808
+ summary: null,
124809
+ output_file: task.output_file,
124810
+ output: "",
124811
+ token_count: null,
124812
+ last_tool_name: null
124813
+ },
124814
+ "in_progress",
124815
+ "item:started"
124816
+ );
124817
+ }
124818
+ function updateTaskItem(db2, sessionId, taskId, update) {
124819
+ const row = findTaskItem2(db2, sessionId, taskId);
124820
+ if (!row) return false;
124821
+ if (row.status !== "in_progress") return true;
124822
+ const prev = row.data ? JSON.parse(row.data) : {};
124823
+ const output = readTaskOutput(prev.output_file ?? null) || String(prev.output ?? "");
124824
+ const ended = update.status !== "running";
124825
+ if (!ended && output === prev.output) return true;
124826
+ const data = {
124827
+ ...prev,
124828
+ status: update.status,
124829
+ output,
124830
+ ...update.summary !== void 0 ? { summary: update.summary } : {},
124831
+ ...update.exit_code !== void 0 ? { exit_code: update.exit_code } : {}
124832
+ };
124833
+ const status = !ended ? "in_progress" : update.status === "failed" ? "failed" : "completed";
124834
+ const item = { ...row, data: prev };
124835
+ updateItem(db2, sessionId, row.turn_id, item, data, status);
124836
+ return true;
124837
+ }
124838
+ function taskSummary(task) {
124839
+ const name = `Background command "${task.description}"`;
124840
+ switch (task.status) {
124841
+ case "completed":
124842
+ return `${name} completed (exit code 0)`;
124843
+ case "stopped":
124844
+ return `${name} was stopped`;
124845
+ case "failed":
124846
+ return task.exit_code === null ? `${name} was killed` : `${name} failed with exit code ${task.exit_code}`;
124847
+ default:
124848
+ return `${name} is running`;
124849
+ }
124850
+ }
124851
+
124699
124852
  // src/repoburg/turn-projector.ts
124700
124853
  var RESULT_TIMEOUT_MS = 15 * 6e4;
124701
124854
  var MAX_RESULT_EXTENSIONS = 3;
@@ -124731,6 +124884,8 @@ var TurnProjector = class {
124731
124884
  switch (message.type) {
124732
124885
  case "system":
124733
124886
  if (message.subtype === "compact_boundary") this.handleCompactBoundary(message);
124887
+ else if (message.subtype === "task_started") this.handleTaskStarted(message);
124888
+ else if (message.subtype === "task_notification") this.handleTaskNotification(message);
124734
124889
  break;
124735
124890
  case "stream_event":
124736
124891
  this.handleStreamEvent(message);
@@ -125060,6 +125215,27 @@ var TurnProjector = class {
125060
125215
  }
125061
125216
  this.touch();
125062
125217
  }
125218
+ /** A background task started in this turn → its background_task item. */
125219
+ handleTaskStarted(msg) {
125220
+ openTaskItem2(getDb(), this.deps.agentPaneSessionId, this.deps.turnId, {
125221
+ task_id: msg.task_id,
125222
+ description: msg.description,
125223
+ command: msg.command,
125224
+ output_file: taskOutputPath(msg.output_file, this.deps.cwd)
125225
+ });
125226
+ this.deps.onTaskEvent?.(msg);
125227
+ this.touch();
125228
+ }
125229
+ /** A background task ended — maybe one an earlier turn started. */
125230
+ handleTaskNotification(msg) {
125231
+ updateTaskItem(getDb(), this.deps.agentPaneSessionId, msg.task_id, {
125232
+ status: msg.status,
125233
+ summary: msg.summary,
125234
+ exit_code: msg.exit_code
125235
+ });
125236
+ this.deps.onTaskEvent?.(msg);
125237
+ this.touch();
125238
+ }
125063
125239
  handleResult(msg) {
125064
125240
  switch (msg.subtype) {
125065
125241
  case "success":
@@ -125224,12 +125400,9 @@ var TurnProjector = class {
125224
125400
  closeOpenItems(status) {
125225
125401
  const db2 = getDb();
125226
125402
  const now = (/* @__PURE__ */ new Date()).toISOString();
125227
- db2.prepare("UPDATE items SET status = ?, updated_at = ? WHERE turn_id = ? AND status = ?").run(
125228
- status,
125229
- now,
125230
- this.deps.turnId,
125231
- "in_progress"
125232
- );
125403
+ db2.prepare(
125404
+ `UPDATE items SET status = ?, updated_at = ? WHERE turn_id = ? AND status = ? AND ${NOT_BACKGROUND_COMMAND}`
125405
+ ).run(status, now, this.deps.turnId, "in_progress");
125233
125406
  }
125234
125407
  // -------------------------------------------------------------------------
125235
125408
  // Watch-dog + snapshot reconcile
@@ -125406,9 +125579,10 @@ async function ensureSession(session, client, baseUrl) {
125406
125579
  repoburgSessionId: session.external_thread_id,
125407
125580
  client,
125408
125581
  baseUrl,
125409
- modelId: session.model || null,
125410
- // undefined forces a re-push on the next turn — heals sessions created
125582
+ // undefined forces a re-push of model and effort on the next turn —
125583
+ // heals switches made while the pane was down, and sessions created
125411
125584
  // before unsafe effort values (e.g. ollama xhigh) were clamped.
125585
+ modelId: void 0,
125412
125586
  reasoningEffort: void 0,
125413
125587
  threadId: null,
125414
125588
  contextWindow: null,
@@ -125453,6 +125627,7 @@ async function ensureThreadSession(session, turn, client, baseUrl) {
125453
125627
  const db2 = getDb();
125454
125628
  const thread = db2.prepare("SELECT external_thread_id FROM discussion_threads WHERE id = ?").get(turn.thread_id);
125455
125629
  let runtimeId = thread?.external_thread_id ?? null;
125630
+ const forked = !!runtimeId;
125456
125631
  if (!runtimeId) {
125457
125632
  const created = await client.createSession({
125458
125633
  session_title: session.title ? `Discussion: ${session.title}` : "Discussion",
@@ -125472,7 +125647,7 @@ async function ensureThreadSession(session, turn, client, baseUrl) {
125472
125647
  repoburgSessionId: runtimeId,
125473
125648
  client,
125474
125649
  baseUrl,
125475
- modelId: session.model || null,
125650
+ modelId: forked ? void 0 : session.model || null,
125476
125651
  reasoningEffort: void 0,
125477
125652
  // re-pushed on the first thread turn
125478
125653
  threadId: turn.thread_id,
@@ -125523,12 +125698,9 @@ function failTurn3(entry, error51) {
125523
125698
  now,
125524
125699
  active.turnId
125525
125700
  );
125526
- db2.prepare("UPDATE items SET status = ?, updated_at = ? WHERE turn_id = ? AND status = ?").run(
125527
- "failed",
125528
- now,
125529
- active.turnId,
125530
- "in_progress"
125531
- );
125701
+ db2.prepare(
125702
+ `UPDATE items SET status = ?, updated_at = ? WHERE turn_id = ? AND status = ? AND ${NOT_BACKGROUND_COMMAND}`
125703
+ ).run("failed", now, active.turnId, "in_progress");
125532
125704
  recomputeSessionRunning(db2, entry.agentPaneSessionId, "failed");
125533
125705
  broadcast("turn:failed", { sessionId: entry.agentPaneSessionId, turnId: active.turnId, error: error51 });
125534
125706
  }
@@ -125657,6 +125829,16 @@ async function startTurn4(session, turn) {
125657
125829
  entry.baseUrl = baseUrl;
125658
125830
  entry.client = client;
125659
125831
  }
125832
+ startingEntries.add(entry);
125833
+ try {
125834
+ await runTurn2(session, turn, entry, firstInput);
125835
+ } finally {
125836
+ startingEntries.delete(entry);
125837
+ }
125838
+ }
125839
+ async function runTurn2(session, turn, entry, firstInput) {
125840
+ const db2 = getDb();
125841
+ await syncSessionMcp(entry, session.cwd ?? process.cwd());
125660
125842
  const wantedModel = session.model || null;
125661
125843
  const wantedEffort = mapReasoningEffort(session.model_reasoning_effort);
125662
125844
  if (wantedModel !== entry.modelId || wantedEffort !== entry.reasoningEffort) {
@@ -125676,7 +125858,11 @@ async function startTurn4(session, turn) {
125676
125858
  db2.prepare("UPDATE turns SET status = ?, updated_at = ? WHERE id = ?").run("running", now, turn.id);
125677
125859
  setSessionStatus3(db2, session.id, 1, "running", now);
125678
125860
  broadcast("turn:started", { sessionId: session.id, turnId: turn.id });
125679
- const state = await getAgentRuntimeState(entry.baseUrl, entry.repoburgSessionId).catch(() => null);
125861
+ let state = await getAgentRuntimeState(entry.baseUrl, entry.repoburgSessionId).catch(() => null);
125862
+ if (state?.turnInFlight && !(entry.activeTurn && !entry.activeTurn.projector.isDone)) {
125863
+ await entry.client.cancel(entry.repoburgSessionId).catch(() => void 0);
125864
+ state = await waitForRunEnd(entry, RUN_END_WAIT_MS) ?? state;
125865
+ }
125680
125866
  if (state) {
125681
125867
  const cursor = {
125682
125868
  bootId: state.bootId,
@@ -125694,7 +125880,10 @@ async function startTurn4(session, turn) {
125694
125880
  // Late-bound — the window resolves from the runtime catalog while the
125695
125881
  // turn streams and is read at turn completion.
125696
125882
  getContextWindow: () => entry.contextWindow,
125697
- ...state ? { firstSeq: state.lastSeq + 1 } : {}
125883
+ ...state ? { firstSeq: state.lastSeq + 1 } : {},
125884
+ cwd: session.cwd ?? null,
125885
+ onTaskEvent: (message) => onTaskEvent(entry, message),
125886
+ onFinished: () => onTurnFinished(entry)
125698
125887
  });
125699
125888
  entry.activeTurn = {
125700
125889
  turnId: turn.id,
@@ -125723,6 +125912,245 @@ async function startTurn4(session, turn) {
125723
125912
  failTurn3(entry, err.message);
125724
125913
  }
125725
125914
  }
125915
+ var TASK_POLL_MS = 2e3;
125916
+ var WAKE_WATCH_MS = 2e4;
125917
+ var RUN_END_WAIT_MS = 1e4;
125918
+ var taskStates = /* @__PURE__ */ new WeakMap();
125919
+ var startingEntries = /* @__PURE__ */ new Set();
125920
+ var publishedTasks = /* @__PURE__ */ new Map();
125921
+ function taskStateOf(entry) {
125922
+ let state = taskStates.get(entry);
125923
+ if (!state) {
125924
+ state = { running: /* @__PURE__ */ new Map(), timer: null, polling: false, watchUntil: 0 };
125925
+ taskStates.set(entry, state);
125926
+ }
125927
+ return state;
125928
+ }
125929
+ function taskPollMs2() {
125930
+ const fromEnv = Number(process.env.AGENT_PANE_REPOBURG_TASK_POLL_MS);
125931
+ return Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : TASK_POLL_MS;
125932
+ }
125933
+ function sessionCwd(sessionId) {
125934
+ try {
125935
+ const row = getDb().prepare("SELECT cwd FROM sessions WHERE id = ?").get(sessionId);
125936
+ return row?.cwd ?? null;
125937
+ } catch {
125938
+ return null;
125939
+ }
125940
+ }
125941
+ function entryKey(entry) {
125942
+ return entry.threadId ? `${entry.agentPaneSessionId}:thread:${entry.threadId}` : entry.agentPaneSessionId;
125943
+ }
125944
+ function onTaskEvent(entry, message) {
125945
+ const state = taskStateOf(entry);
125946
+ if (message.subtype === "task_started") {
125947
+ state.running.set(message.task_id, {
125948
+ task_id: message.task_id,
125949
+ task_type: REPOBURG_TASK_TYPE,
125950
+ description: message.description
125951
+ });
125952
+ } else {
125953
+ state.running.delete(message.task_id);
125954
+ state.watchUntil = Date.now() + WAKE_WATCH_MS;
125955
+ }
125956
+ publishTasks2(entry.agentPaneSessionId);
125957
+ ensureTaskPolling(entry);
125958
+ }
125959
+ function onTurnFinished(entry) {
125960
+ const state = taskStates.get(entry);
125961
+ if (!state) return;
125962
+ state.watchUntil = Math.max(state.watchUntil, Date.now() + WAKE_WATCH_MS);
125963
+ ensureTaskPolling(entry);
125964
+ }
125965
+ function sessionTasks(sessionId) {
125966
+ const tasks = [];
125967
+ for (const [key, entry] of sessionMap3) {
125968
+ if (key !== sessionId && !key.startsWith(`${sessionId}:thread:`)) continue;
125969
+ const state = taskStates.get(entry);
125970
+ if (state) tasks.push(...state.running.values());
125971
+ }
125972
+ return tasks;
125973
+ }
125974
+ function publishTasks2(sessionId) {
125975
+ const tasks = sessionTasks(sessionId);
125976
+ const json2 = JSON.stringify(tasks);
125977
+ if ((publishedTasks.get(sessionId) ?? "[]") === json2) return;
125978
+ if (tasks.length > 0) publishedTasks.set(sessionId, json2);
125979
+ else publishedTasks.delete(sessionId);
125980
+ broadcast("background_tasks", { sessionId, tasks });
125981
+ }
125982
+ function ensureTaskPolling(entry) {
125983
+ const state = taskStateOf(entry);
125984
+ if (state.timer || !entry.client.listBackgroundTasks) return;
125985
+ if (state.running.size === 0 && Date.now() >= state.watchUntil) return;
125986
+ state.timer = setInterval(() => void pollTasks(entry), taskPollMs2());
125987
+ state.timer.unref?.();
125988
+ }
125989
+ function stopTaskPolling2(entry) {
125990
+ const state = taskStates.get(entry);
125991
+ if (!state?.timer) return;
125992
+ clearInterval(state.timer);
125993
+ state.timer = null;
125994
+ }
125995
+ async function pollTasks(entry) {
125996
+ const state = taskStateOf(entry);
125997
+ if (state.polling) return;
125998
+ if (sessionMap3.get(entryKey(entry)) !== entry) {
125999
+ stopTaskPolling2(entry);
126000
+ return;
126001
+ }
126002
+ state.polling = true;
126003
+ try {
126004
+ const tasks = await entry.client.listBackgroundTasks(entry.repoburgSessionId);
126005
+ const db2 = getDb();
126006
+ const listed = new Set(tasks.map((task) => task.task_id));
126007
+ for (const task of tasks) {
126008
+ if (task.status === "running") {
126009
+ state.running.set(task.task_id, {
126010
+ task_id: task.task_id,
126011
+ task_type: REPOBURG_TASK_TYPE,
126012
+ description: task.description
126013
+ });
126014
+ updateTaskItem(db2, entry.agentPaneSessionId, task.task_id, { status: "running" });
126015
+ } else if (state.running.delete(task.task_id)) {
126016
+ state.watchUntil = Date.now() + WAKE_WATCH_MS;
126017
+ updateTaskItem(db2, entry.agentPaneSessionId, task.task_id, {
126018
+ status: task.status,
126019
+ summary: taskSummary(task),
126020
+ exit_code: task.exit_code
126021
+ });
126022
+ }
126023
+ }
126024
+ for (const taskId of [...state.running.keys()]) {
126025
+ if (listed.has(taskId)) continue;
126026
+ state.running.delete(taskId);
126027
+ updateTaskItem(db2, entry.agentPaneSessionId, taskId, {
126028
+ status: "stopped",
126029
+ summary: "The Repoburg backend stopped running this task.",
126030
+ exit_code: null
126031
+ });
126032
+ }
126033
+ publishTasks2(entry.agentPaneSessionId);
126034
+ await attachWakeRun(entry);
126035
+ } catch (err) {
126036
+ if (httpStatus(err) === 404) {
126037
+ state.running.clear();
126038
+ state.watchUntil = 0;
126039
+ publishTasks2(entry.agentPaneSessionId);
126040
+ } else if (isConnectionError(err)) {
126041
+ invalidateBackend(entry.baseUrl);
126042
+ }
126043
+ } finally {
126044
+ state.polling = false;
126045
+ if (state.running.size === 0 && Date.now() >= state.watchUntil) stopTaskPolling2(entry);
126046
+ }
126047
+ }
126048
+ function entryBusy(entry) {
126049
+ return startingEntries.has(entry) || !!entry.activeTurn && !entry.activeTurn.projector.isDone;
126050
+ }
126051
+ async function attachWakeRun(entry) {
126052
+ if (entryBusy(entry)) return;
126053
+ const state = await getAgentRuntimeState(entry.baseUrl, entry.repoburgSessionId).catch(() => null);
126054
+ if (!state || entryBusy(entry)) return;
126055
+ const previous = entry.activeTurn;
126056
+ const handled = previous && previous.bootId === state.bootId && previous.lastSeq !== null ? previous.lastSeq : null;
126057
+ const missedRun = handled !== null && !previous?.cancelled && state.lastResult !== null && (state.lastResult.seq ?? 0) > handled;
126058
+ if (!state.turnInFlight && !missedRun) return;
126059
+ const db2 = getDb();
126060
+ 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);
126061
+ if (!turn || turn.status === "running" || turn.status === "pending") return;
126062
+ const fromSeq = handled ?? state.lastResult?.seq ?? 0;
126063
+ const now = (/* @__PURE__ */ new Date()).toISOString();
126064
+ const cursor = {
126065
+ bootId: state.bootId,
126066
+ firstSeq: fromSeq + 1,
126067
+ baseUrl: entry.baseUrl,
126068
+ runtimeSessionId: entry.repoburgSessionId
126069
+ };
126070
+ db2.prepare("UPDATE turns SET status = 'running', error = NULL, stream_cursor = ?, updated_at = ? WHERE id = ?").run(
126071
+ JSON.stringify(cursor),
126072
+ now,
126073
+ turn.id
126074
+ );
126075
+ setSessionStatus3(db2, entry.agentPaneSessionId, 1, "running", now);
126076
+ broadcast("turn:started", { sessionId: entry.agentPaneSessionId, turnId: turn.id });
126077
+ const projector = new TurnProjector({
126078
+ agentPaneSessionId: entry.agentPaneSessionId,
126079
+ turnId: turn.id,
126080
+ repoburgSessionId: entry.repoburgSessionId,
126081
+ client: entry.client,
126082
+ getContextWindow: () => entry.contextWindow,
126083
+ firstSeq: fromSeq + 1,
126084
+ cwd: sessionCwd(entry.agentPaneSessionId),
126085
+ onTaskEvent: (message) => onTaskEvent(entry, message),
126086
+ onFinished: () => onTurnFinished(entry)
126087
+ });
126088
+ entry.activeTurn = {
126089
+ turnId: turn.id,
126090
+ projector,
126091
+ sseAbort: new AbortController(),
126092
+ cancelled: false,
126093
+ bootId: state.bootId,
126094
+ lastSeq: fromSeq
126095
+ };
126096
+ console.log(`[repoburg] session ${entry.agentPaneSessionId}: a background task ended, turn ${turn.id} runs again`);
126097
+ runStreamLoop(entry, projector).catch((err) => {
126098
+ console.error("[repoburg] stream loop crashed:", err);
126099
+ failTurn3(entry, `Stream loop failed: ${err.message}`);
126100
+ });
126101
+ }
126102
+ async function waitForRunEnd(entry, timeoutMs) {
126103
+ const end = Date.now() + timeoutMs;
126104
+ for (; ; ) {
126105
+ const state = await getAgentRuntimeState(entry.baseUrl, entry.repoburgSessionId).catch(() => null);
126106
+ if (!state || !state.turnInFlight || Date.now() >= end) return state;
126107
+ await new Promise((resolve) => setTimeout(resolve, 200));
126108
+ }
126109
+ }
126110
+ async function stopTask3(sessionId, taskId) {
126111
+ for (const [key, entry] of sessionMap3) {
126112
+ if (key !== sessionId && !key.startsWith(`${sessionId}:thread:`)) continue;
126113
+ const state = taskStates.get(entry);
126114
+ if (!state?.running.has(taskId) || !entry.client.stopBackgroundTask) continue;
126115
+ const task = await entry.client.stopBackgroundTask(entry.repoburgSessionId, taskId);
126116
+ state.running.delete(taskId);
126117
+ updateTaskItem(getDb(), sessionId, taskId, {
126118
+ status: task.status === "running" ? "stopped" : task.status,
126119
+ summary: taskSummary(task),
126120
+ exit_code: task.exit_code
126121
+ });
126122
+ publishTasks2(sessionId);
126123
+ return;
126124
+ }
126125
+ throw new Error(`No running background task ${taskId} in this session`);
126126
+ }
126127
+ function listBackgroundTasks3() {
126128
+ const bySession = {};
126129
+ for (const entry of sessionMap3.values()) {
126130
+ const tasks = sessionTasks(entry.agentPaneSessionId);
126131
+ if (tasks.length > 0) bySession[entry.agentPaneSessionId] = tasks;
126132
+ }
126133
+ return bySession;
126134
+ }
126135
+ var pushedMcp = /* @__PURE__ */ new Map();
126136
+ var noSessionMcp = /* @__PURE__ */ new Set();
126137
+ async function syncSessionMcp(entry, cwd) {
126138
+ if (!entry.client.setSessionMcpServers || noSessionMcp.has(entry.baseUrl)) return;
126139
+ try {
126140
+ const servers = await repoburgBrowserMcpServers(cwd);
126141
+ const json2 = JSON.stringify(servers);
126142
+ const key = `${entry.baseUrl} ${entry.repoburgSessionId}`;
126143
+ if (pushedMcp.get(key) === json2) return;
126144
+ await entry.client.setSessionMcpServers(entry.repoburgSessionId, servers);
126145
+ pushedMcp.set(key, json2);
126146
+ } catch (err) {
126147
+ if (httpStatus(err) === 404 || httpStatus(err) === 400) {
126148
+ noSessionMcp.add(entry.baseUrl);
126149
+ return;
126150
+ }
126151
+ console.warn("[repoburg] could not set the session MCP servers:", err.message);
126152
+ }
126153
+ }
125726
126154
  function parseCursor(raw) {
125727
126155
  if (!raw) return null;
125728
126156
  try {
@@ -125781,9 +126209,9 @@ async function adoptRepoburgTurns(db2, result) {
125781
126209
  repoburgSessionId: cursor.runtimeSessionId,
125782
126210
  client: new RepoburgHttpClient(cursor.baseUrl),
125783
126211
  baseUrl: cursor.baseUrl,
125784
- modelId: row.model,
126212
+ modelId: void 0,
126213
+ // model and effort re-pushed on the next turn
125785
126214
  reasoningEffort: void 0,
125786
- // re-pushed on the next turn
125787
126215
  threadId: row.thread_id,
125788
126216
  contextWindow: null,
125789
126217
  modelsResolved: false,
@@ -125796,7 +126224,10 @@ async function adoptRepoburgTurns(db2, result) {
125796
126224
  repoburgSessionId: cursor.runtimeSessionId,
125797
126225
  client: entry.client,
125798
126226
  getContextWindow: () => entry.contextWindow,
125799
- firstSeq: cursor.firstSeq
126227
+ firstSeq: cursor.firstSeq,
126228
+ cwd: sessionCwd(row.session_id),
126229
+ onTaskEvent: (message) => onTaskEvent(entry, message),
126230
+ onFinished: () => onTurnFinished(entry)
125800
126231
  });
125801
126232
  entry.activeTurn = {
125802
126233
  turnId: row.id,
@@ -125839,12 +126270,9 @@ async function interruptTurn3(sessionId, threadId) {
125839
126270
  const db2 = getDb();
125840
126271
  const now = (/* @__PURE__ */ new Date()).toISOString();
125841
126272
  db2.prepare("UPDATE turns SET status = ?, updated_at = ? WHERE id = ?").run("aborted", now, active.turnId);
125842
- db2.prepare("UPDATE items SET status = ?, updated_at = ? WHERE turn_id = ? AND status = ?").run(
125843
- "completed",
125844
- now,
125845
- active.turnId,
125846
- "in_progress"
125847
- );
126273
+ db2.prepare(
126274
+ `UPDATE items SET status = ?, updated_at = ? WHERE turn_id = ? AND status = ? AND ${NOT_BACKGROUND_COMMAND}`
126275
+ ).run("completed", now, active.turnId, "in_progress");
125848
126276
  recomputeSessionRunning(db2, sessionId);
125849
126277
  broadcast("turn:cancelled", { sessionId, turnId: active.turnId });
125850
126278
  return true;
@@ -125858,6 +126286,7 @@ function clearThread3(sessionId) {
125858
126286
  active.projector.close();
125859
126287
  active.sseAbort.abort();
125860
126288
  }
126289
+ stopTaskPolling2(entry);
125861
126290
  sessionMap3.delete(key);
125862
126291
  }
125863
126292
  }
@@ -125871,6 +126300,7 @@ function clearThreadBranch3(sessionId, threadId) {
125871
126300
  active.projector.close();
125872
126301
  active.sseAbort.abort();
125873
126302
  }
126303
+ stopTaskPolling2(entry);
125874
126304
  sessionMap3.delete(key);
125875
126305
  }
125876
126306
  }
@@ -125920,8 +126350,15 @@ async function forkSession2(session, targetTurn) {
125920
126350
  }
125921
126351
  const client = await resolveClient(session);
125922
126352
  const forked = await client.forkSession(session.external_thread_id, anchor);
126353
+ forkInputIds.set(forked.id, new Map(Object.entries(forked.input_id_map ?? {})));
125923
126354
  return forked.id;
125924
126355
  }
126356
+ var forkInputIds = /* @__PURE__ */ new Map();
126357
+ async function forkedTurnIds2(_session, forkedId) {
126358
+ const ids = forkInputIds.get(forkedId) ?? /* @__PURE__ */ new Map();
126359
+ forkInputIds.delete(forkedId);
126360
+ return ids;
126361
+ }
125925
126362
  var THREAD_SUMMARY_TIMEOUT_MS = 12e4;
125926
126363
  async function summarizeThread(session, _thread, transcript, directives) {
125927
126364
  try {
@@ -125945,8 +126382,12 @@ function clearAllThreads3() {
125945
126382
  active.projector.close();
125946
126383
  active.sseAbort.abort();
125947
126384
  }
126385
+ stopTaskPolling2(entry);
125948
126386
  }
125949
126387
  sessionMap3.clear();
126388
+ publishedTasks.clear();
126389
+ pushedMcp.clear();
126390
+ noSessionMcp.clear();
125950
126391
  }
125951
126392
  async function getModels3(cwd) {
125952
126393
  try {
@@ -126049,7 +126490,10 @@ var repoburgProvider = {
126049
126490
  getCommands: getCommands3,
126050
126491
  rewindRuntime,
126051
126492
  forkSession: forkSession2,
126493
+ forkedTurnIds: forkedTurnIds2,
126052
126494
  summarizeThread,
126495
+ stopTask: stopTask3,
126496
+ listBackgroundTasks: listBackgroundTasks3,
126053
126497
  shutdown: shutdown3
126054
126498
  };
126055
126499