replicas-engine 0.1.1642 → 0.1.1644

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.
package/dist/src/index.js CHANGED
@@ -91,7 +91,7 @@ import {
91
91
  evaluateCommandProtection,
92
92
  extractToolCommand,
93
93
  reportCommandProtectionBlock
94
- } from "./chunk-ANS535QZ.js";
94
+ } from "./chunk-RH6UDT73.js";
95
95
  import {
96
96
  ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
97
97
  AGENT_MESSAGE_DELTA_METHOD,
@@ -129,10 +129,10 @@ import {
129
129
  spawnMuseMsp,
130
130
  startMuseSession,
131
131
  uuidV7
132
- } from "./chunk-XP4DII7G.js";
132
+ } from "./chunk-EQM5UQI7.js";
133
133
  import {
134
134
  publishedPullRequestUrls
135
- } from "./chunk-VWCK47IH.js";
135
+ } from "./chunk-A23NCSWD.js";
136
136
  import {
137
137
  ACCOUNT_RATE_LIMITS_READ_METHOD,
138
138
  AsyncLock,
@@ -212,7 +212,7 @@ import {
212
212
  transcriptSecrets,
213
213
  upsertCredentialFileLines,
214
214
  writeSecureCredentialFile
215
- } from "./chunk-34O6XJV7.js";
215
+ } from "./chunk-ZLOQ4MPK.js";
216
216
  import {
217
217
  ENGINE_ENV,
218
218
  UNQUOTED_PATHS_CONFIG,
@@ -223,16 +223,16 @@ import {
223
223
  resolveDiffBase,
224
224
  setAgentCredentialSnapshot,
225
225
  setLinearSessionId
226
- } from "./chunk-B32DFOG7.js";
226
+ } from "./chunk-AMGR5JV4.js";
227
227
  import {
228
228
  buildCodexAgentEnv,
229
229
  getCodexModelProvider
230
- } from "./chunk-YJQUT7IV.js";
230
+ } from "./chunk-CGADOFRJ.js";
231
231
  import {
232
232
  SUBPROCESS_MAX_BUFFER,
233
233
  execAsync,
234
234
  execFileAsync
235
- } from "./chunk-R3XF43SW.js";
235
+ } from "./chunk-I6CD7YY5.js";
236
236
  import {
237
237
  isRecord as isRecord2
238
238
  } from "./chunk-UZSNFLDQ.js";
@@ -337,7 +337,6 @@ import {
337
337
  REPLICAS_MCP_SERVER_NAME,
338
338
  REPLICAS_MCP_TOOLS,
339
339
  REPLICAS_RUNTIME_ENV_ALIASES,
340
- SANDBOX_SKILL_DIRS,
341
340
  SUBAGENT_MCP_HARNESSES,
342
341
  SUBAGENT_MCP_SERVER_NAME,
343
342
  SUBAGENT_MCP_TOOLS,
@@ -529,7 +528,7 @@ import {
529
528
  workspaceTokenRequestSchema,
530
529
  workspaceTokenResponseSchema,
531
530
  wrapInTag
532
- } from "./chunk-TMJ2JDXT.js";
531
+ } from "./chunk-R6FS7GDP.js";
533
532
  import {
534
533
  __commonJS,
535
534
  __export,
@@ -3974,7 +3973,7 @@ var require_compile2 = __commonJS({
3974
3973
  const schOrFunc = root.refs[ref];
3975
3974
  if (schOrFunc)
3976
3975
  return schOrFunc;
3977
- let _sch = resolve8.call(this, root, ref);
3976
+ let _sch = resolve9.call(this, root, ref);
3978
3977
  if (_sch === void 0) {
3979
3978
  const schema = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref];
3980
3979
  const { schemaId } = this.opts;
@@ -4001,7 +4000,7 @@ var require_compile2 = __commonJS({
4001
4000
  function sameSchemaEnv(s1, s2) {
4002
4001
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
4003
4002
  }
4004
- function resolve8(root, ref) {
4003
+ function resolve9(root, ref) {
4005
4004
  let sch;
4006
4005
  while (typeof (sch = this.refs[ref]) == "string")
4007
4006
  ref = sch;
@@ -4865,7 +4864,7 @@ var require_fast_uri2 = __commonJS({
4865
4864
  }
4866
4865
  return uri;
4867
4866
  }
4868
- function resolve8(baseURI, relativeURI, options) {
4867
+ function resolve9(baseURI, relativeURI, options) {
4869
4868
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
4870
4869
  const {
4871
4870
  parsed: baseParsed,
@@ -5256,7 +5255,7 @@ var require_fast_uri2 = __commonJS({
5256
5255
  var fastUri = {
5257
5256
  SCHEMES,
5258
5257
  normalize,
5259
- resolve: resolve8,
5258
+ resolve: resolve9,
5260
5259
  resolveComponent,
5261
5260
  equal,
5262
5261
  serialize,
@@ -9571,16 +9570,16 @@ function resolveMcpOAuthRoute(requestUrl) {
9571
9570
  }
9572
9571
  var MAX_MCP_OAUTH_BODY_BYTES = 10 * 1024 * 1024;
9573
9572
  function readBody(request, maxBytes) {
9574
- return new Promise((resolve8) => {
9573
+ return new Promise((resolve9) => {
9575
9574
  const chunks = [];
9576
9575
  let size = 0;
9577
9576
  request.on("data", (chunk) => {
9578
9577
  size += chunk.length;
9579
- if (size > maxBytes) resolve8("too_large");
9578
+ if (size > maxBytes) resolve9("too_large");
9580
9579
  else chunks.push(chunk);
9581
9580
  });
9582
- request.on("end", () => resolve8(Buffer.concat(chunks)));
9583
- request.on("error", () => resolve8(null));
9581
+ request.on("end", () => resolve9(Buffer.concat(chunks)));
9582
+ request.on("error", () => resolve9(null));
9584
9583
  });
9585
9584
  }
9586
9585
  function forward(request, response, target, token, onResponse = (incoming) => pipeResponse(incoming, response)) {
@@ -9750,11 +9749,11 @@ var EngineLifecycle = class {
9750
9749
  }
9751
9750
  waitForActive(timeoutMs) {
9752
9751
  if (this.active) return Promise.resolve();
9753
- return new Promise((resolve8) => {
9754
- const timer = setTimeout(resolve8, timeoutMs);
9752
+ return new Promise((resolve9) => {
9753
+ const timer = setTimeout(resolve9, timeoutMs);
9755
9754
  this.activeWaiters.push(() => {
9756
9755
  clearTimeout(timer);
9757
- resolve8();
9756
+ resolve9();
9758
9757
  });
9759
9758
  });
9760
9759
  }
@@ -9805,9 +9804,9 @@ var StreamWriter = class {
9805
9804
  return true;
9806
9805
  }
9807
9806
  flush(signal) {
9808
- return new Promise((resolve8, reject) => {
9807
+ return new Promise((resolve9, reject) => {
9809
9808
  if (!this.stream) {
9810
- resolve8();
9809
+ resolve9();
9811
9810
  return;
9812
9811
  }
9813
9812
  if (this.flushTimer) {
@@ -9824,7 +9823,7 @@ var StreamWriter = class {
9824
9823
  s.write("", (error) => {
9825
9824
  signal?.removeEventListener("abort", onAbort);
9826
9825
  if (error) reject(error);
9827
- else resolve8();
9826
+ else resolve9();
9828
9827
  });
9829
9828
  });
9830
9829
  }
@@ -10381,7 +10380,7 @@ var ReplicasConfigService = class {
10381
10380
  });
10382
10381
  if (signal("SIGTERM").length === 0) return;
10383
10382
  const deadline = Date.now() + 5e3;
10384
- while (signal(0).length > 0 && Date.now() < deadline) await new Promise((resolve8) => setTimeout(resolve8, 25));
10383
+ while (signal(0).length > 0 && Date.now() < deadline) await new Promise((resolve9) => setTimeout(resolve9, 25));
10385
10384
  signal("SIGKILL");
10386
10385
  }
10387
10386
  /**
@@ -10457,7 +10456,7 @@ var ReplicasConfigService = class {
10457
10456
  await this.logToFile(`[${params.repoName}] --- Running: ${params.label} ---`);
10458
10457
  emit(`$ ${params.label}
10459
10458
  `);
10460
- return new Promise((resolve8) => {
10459
+ return new Promise((resolve9) => {
10461
10460
  const proc = spawn("bash", ["-lc", params.command], {
10462
10461
  cwd: params.cwd,
10463
10462
  env: process.env,
@@ -10470,7 +10469,7 @@ var ReplicasConfigService = class {
10470
10469
  const finish = (result) => {
10471
10470
  if (settled) return;
10472
10471
  settled = true;
10473
- resolve8(result);
10472
+ resolve9(result);
10474
10473
  };
10475
10474
  const timer = setTimeout(() => {
10476
10475
  timedOut = true;
@@ -11025,7 +11024,7 @@ async function startDeviceRelays(names, paths, signal) {
11025
11024
  await rm2(paths.socket(name), { force: true });
11026
11025
  const relay = { server: createServer((local) => attach(relay, local)), knownHostsPath: paths.knownHosts(name), waiting: [], pending: [] };
11027
11026
  relays.set(name, relay);
11028
- await new Promise((resolve8, reject) => relay.server.once("error", reject).listen(paths.socket(name), resolve8));
11027
+ await new Promise((resolve9, reject) => relay.server.once("error", reject).listen(paths.socket(name), resolve9));
11029
11028
  }));
11030
11029
  }
11031
11030
 
@@ -13216,8 +13215,8 @@ var PromptStream = class {
13216
13215
  if (this.closed) {
13217
13216
  return Promise.resolve({ value: void 0, done: true });
13218
13217
  }
13219
- return new Promise((resolve8) => {
13220
- this.waiters.push(resolve8);
13218
+ return new Promise((resolve9) => {
13219
+ this.waiters.push(resolve9);
13221
13220
  });
13222
13221
  }
13223
13222
  };
@@ -13589,7 +13588,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13589
13588
  // Claude Code starts a command for another chat's SendMessage without streaming its text, and can start it a moment before writing it.
13590
13589
  async recordPeerMessage(uuid, query2) {
13591
13590
  for (const delayMs of [0, 100, 300, 600, 1e3]) {
13592
- if (delayMs) await new Promise((resolve8) => setTimeout(resolve8, delayMs));
13591
+ if (delayMs) await new Promise((resolve9) => setTimeout(resolve9, delayMs));
13593
13592
  if (this.activeQuery !== query2 || !this.sessionId) return;
13594
13593
  const entry = (await getSessionMessages(this.sessionId, { dir: this.workingDirectory })).findLast((message) => message.uuid === uuid);
13595
13594
  if (!entry) continue;
@@ -13774,14 +13773,14 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13774
13773
  const requestId = randomUUID3();
13775
13774
  const toolUseId = options.toolUseID;
13776
13775
  const { options: requestOptions, questions: requestQuestions } = handler.getRequest(input);
13777
- const result = await new Promise((resolve8) => {
13776
+ const result = await new Promise((resolve9) => {
13778
13777
  this.pendingToolInputs.set(requestId, {
13779
13778
  requestId,
13780
13779
  toolUseId,
13781
13780
  toolName,
13782
13781
  input,
13783
13782
  handler,
13784
- resolve: resolve8
13783
+ resolve: resolve9
13785
13784
  });
13786
13785
  const onAbort = () => {
13787
13786
  const pending = this.pendingToolInputs.get(requestId);
@@ -14036,7 +14035,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
14036
14035
  error
14037
14036
  );
14038
14037
  await this.tearDownSession();
14039
- await new Promise((resolve8) => setTimeout(resolve8, delayMs));
14038
+ await new Promise((resolve9) => setTimeout(resolve9, delayMs));
14040
14039
  currentRequest = { ...request, message: CLAUDE_MIDTURN_CONTINUE_PROMPT, images: [], goalMode: false };
14041
14040
  attempt++;
14042
14041
  continue;
@@ -14049,7 +14048,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
14049
14048
  error
14050
14049
  );
14051
14050
  await this.tearDownSession();
14052
- await new Promise((resolve8) => setTimeout(resolve8, delayMs));
14051
+ await new Promise((resolve9) => setTimeout(resolve9, delayMs));
14053
14052
  attempt++;
14054
14053
  continue;
14055
14054
  }
@@ -14200,10 +14199,10 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
14200
14199
  this.endedReplies.clear();
14201
14200
  this.cutSentAt = null;
14202
14201
  try {
14203
- await new Promise((resolve8, reject) => {
14202
+ await new Promise((resolve9, reject) => {
14204
14203
  const steers = options.steers ?? /* @__PURE__ */ new Map();
14205
14204
  this.pendingTurn = {
14206
- resolve: resolve8,
14205
+ resolve: resolve9,
14207
14206
  reject,
14208
14207
  sawActivity: false,
14209
14208
  steers,
@@ -15847,8 +15846,8 @@ ${text.slice(-24e3)}`
15847
15846
  });
15848
15847
  };
15849
15848
  let resolveCompleted;
15850
- const completed = new Promise((resolve8) => {
15851
- resolveCompleted = resolve8;
15849
+ const completed = new Promise((resolve9) => {
15850
+ resolveCompleted = resolve9;
15852
15851
  });
15853
15852
  let rejectDisposed = () => {
15854
15853
  };
@@ -16479,8 +16478,8 @@ var CodexHistoryFile = class {
16479
16478
  this.nextOffset += bytes.length;
16480
16479
  const synced = Promise.withResolvers();
16481
16480
  this.taken = synced.promise;
16482
- const written = new Promise((resolve8, reject) => {
16483
- this.queued.push({ bytes, stream: this.isStream(event), resolve: resolve8, reject, synced: synced.resolve });
16481
+ const written = new Promise((resolve9, reject) => {
16482
+ this.queued.push({ bytes, stream: this.isStream(event), resolve: resolve9, reject, synced: synced.resolve });
16484
16483
  });
16485
16484
  written.catch(() => {
16486
16485
  });
@@ -16562,7 +16561,7 @@ var CodexHistoryFile = class {
16562
16561
  } catch (error) {
16563
16562
  const delay2 = WRITE_RETRY_DELAYS_MS[attempt];
16564
16563
  if (delay2 === void 0) throw error;
16565
- await new Promise((resolve8) => setTimeout(resolve8, delay2));
16564
+ await new Promise((resolve9) => setTimeout(resolve9, delay2));
16566
16565
  }
16567
16566
  }
16568
16567
  }
@@ -17079,8 +17078,8 @@ var CursorManager = class extends CodingAgentManager {
17079
17078
  let agent = null;
17080
17079
  let sawCursorActivity = false;
17081
17080
  let reconnectNoticeTimer = null;
17082
- const aborted = new Promise((resolve8) => {
17083
- this.abortActiveTurn = () => resolve8(TURN_ABORTED);
17081
+ const aborted = new Promise((resolve9) => {
17082
+ this.abortActiveTurn = () => resolve9(TURN_ABORTED);
17084
17083
  });
17085
17084
  const linearForwarder = new LinearEventForwarder(() => this.linearSessionId);
17086
17085
  const clearReconnectNoticeTimer = () => {
@@ -17572,8 +17571,8 @@ ${typeof pending.subject.command === "string" ? pending.subject.command : JSON.s
17572
17571
  userMessageRecorded = true;
17573
17572
  }
17574
17573
  if (/^\/compact$/i.test(request.message.trim())) {
17575
- const completed2 = new Promise((resolve8) => {
17576
- this.compactionComplete = { resolve: resolve8 };
17574
+ const completed2 = new Promise((resolve9) => {
17575
+ this.compactionComplete = { resolve: resolve9 };
17577
17576
  });
17578
17577
  const result2 = await this.request("session/compact", {
17579
17578
  commandId: uuidV7(),
@@ -17605,8 +17604,8 @@ ${pending}
17605
17604
  ` : ""}${request.planMode ? "Plan the requested work without modifying files or running mutating commands.\n\n" : ""}${request.message}`;
17606
17605
  if (signal.aborted) return;
17607
17606
  this.turnError = null;
17608
- const completed = new Promise((resolve8) => {
17609
- this.turnComplete = { resolve: resolve8 };
17607
+ const completed = new Promise((resolve9) => {
17608
+ this.turnComplete = { resolve: resolve9 };
17610
17609
  });
17611
17610
  const result = await this.request("turn/start", {
17612
17611
  ...museTurnStartParams(this.sessionId, this.createTurnInput(text, request.images), request.thinkingLevel),
@@ -18030,8 +18029,8 @@ var OpencodeManager = class extends CodingAgentManager {
18030
18029
  const previousUpdate = this.clientUpdate;
18031
18030
  let finishUpdate = () => {
18032
18031
  };
18033
- this.clientUpdate = new Promise((resolve8) => {
18034
- finishUpdate = resolve8;
18032
+ this.clientUpdate = new Promise((resolve9) => {
18033
+ finishUpdate = resolve9;
18035
18034
  });
18036
18035
  await previousUpdate;
18037
18036
  try {
@@ -18112,8 +18111,8 @@ var OpencodeManager = class extends CodingAgentManager {
18112
18111
  this.configuredModels = new Set(providerModels);
18113
18112
  const eventController = new AbortController();
18114
18113
  this.eventAbortController = eventController;
18115
- this.eventSubscriptionReady = new Promise((resolve8) => {
18116
- this.resolveEventSubscriptionReady = resolve8;
18114
+ this.eventSubscriptionReady = new Promise((resolve9) => {
18115
+ this.resolveEventSubscriptionReady = resolve9;
18117
18116
  });
18118
18117
  this.subscribeToEvents(client, eventController).catch((error) => {
18119
18118
  this.resolveEventSubscriptionReady?.();
@@ -18123,7 +18122,7 @@ var OpencodeManager = class extends CodingAgentManager {
18123
18122
  });
18124
18123
  await Promise.race([
18125
18124
  this.eventSubscriptionReady,
18126
- new Promise((resolve8) => setTimeout(resolve8, 2e3))
18125
+ new Promise((resolve9) => setTimeout(resolve9, 2e3))
18127
18126
  ]);
18128
18127
  return client;
18129
18128
  } finally {
@@ -27849,14 +27848,14 @@ function inputRequiredRoundsExceededMessage(method, maxRounds) {
27849
27848
  return `Multi-round-trip request '${method}' still required input after ${maxRounds} rounds (inputRequired.maxRounds)`;
27850
27849
  }
27851
27850
  function sleep2(ms, signal) {
27852
- return new Promise((resolve8, reject) => {
27851
+ return new Promise((resolve9, reject) => {
27853
27852
  if (signal?.aborted) {
27854
27853
  reject(signal.reason instanceof SdkError ? signal.reason : new SdkError(SdkErrorCode.RequestTimeout, String(signal.reason)));
27855
27854
  return;
27856
27855
  }
27857
27856
  const timer = setTimeout(() => {
27858
27857
  signal?.removeEventListener("abort", onAbort);
27859
- resolve8();
27858
+ resolve9();
27860
27859
  }, ms);
27861
27860
  const onAbort = () => {
27862
27861
  clearTimeout(timer);
@@ -28700,7 +28699,7 @@ var Protocol = class {
28700
28699
  const flowStartedAt = Date.now();
28701
28700
  let onAbort;
28702
28701
  let cleanupMessageId;
28703
- return new Promise((resolve8, reject) => {
28702
+ return new Promise((resolve9, reject) => {
28704
28703
  const earlyReject = (error) => {
28705
28704
  reject(error);
28706
28705
  };
@@ -28769,7 +28768,7 @@ var Protocol = class {
28769
28768
  }
28770
28769
  if (decoded.kind === "invalid") return reject(decoded.error);
28771
28770
  if (decoded.kind === "input_required") {
28772
- if (options?.allowInputRequired === true) return resolve8(manualInputRequiredValue(decoded));
28771
+ if (options?.allowInputRequired === true) return resolve9(manualInputRequiredValue(decoded));
28773
28772
  const flow = {
28774
28773
  codec,
28775
28774
  request,
@@ -28781,11 +28780,11 @@ var Protocol = class {
28781
28780
  params
28782
28781
  }, resultSchema, legOptions)
28783
28782
  };
28784
- return resolve8(this._resolveNonCompleteResult(decoded, flow));
28783
+ return resolve9(this._resolveNonCompleteResult(decoded, flow));
28785
28784
  }
28786
28785
  const result = decoded.result;
28787
28786
  validateStandardSchema(resultSchema, result).then((parseResult) => {
28788
- if (parseResult.success) resolve8(parseResult.data);
28787
+ if (parseResult.success) resolve9(parseResult.data);
28789
28788
  else reject(new SdkError(SdkErrorCode.InvalidResult, `Invalid result for ${request.method}: ${parseResult.error}`));
28790
28789
  }, reject);
28791
28790
  });
@@ -31802,7 +31801,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin(((exports) => {
31802
31801
  ref = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, ref);
31803
31802
  const schOrFunc = root.refs[ref];
31804
31803
  if (schOrFunc) return schOrFunc;
31805
- let _sch = resolve8.call(this, root, ref);
31804
+ let _sch = resolve9.call(this, root, ref);
31806
31805
  if (_sch === void 0) {
31807
31806
  const schema = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref];
31808
31807
  const { schemaId } = this.opts;
@@ -31828,7 +31827,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin(((exports) => {
31828
31827
  function sameSchemaEnv(s1, s2) {
31829
31828
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
31830
31829
  }
31831
- function resolve8(root, ref) {
31830
+ function resolve9(root, ref) {
31832
31831
  let sch;
31833
31832
  while (typeof (sch = this.refs[ref]) == "string") ref = sch;
31834
31833
  return sch || this.schemas[ref] || resolveSchema.call(this, root, ref);
@@ -32278,7 +32277,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
32278
32277
  else if (typeof uri === "object") uri = parse3(serialize(uri, options), options);
32279
32278
  return uri;
32280
32279
  }
32281
- function resolve8(baseURI, relativeURI, options) {
32280
+ function resolve9(baseURI, relativeURI, options) {
32282
32281
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
32283
32282
  const resolved = resolveComponent(parse3(baseURI, schemelessOptions), parse3(relativeURI, schemelessOptions), schemelessOptions, true);
32284
32283
  schemelessOptions.skipEscape = true;
@@ -32452,7 +32451,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
32452
32451
  const fastUri = {
32453
32452
  SCHEMES,
32454
32453
  normalize,
32455
- resolve: resolve8,
32454
+ resolve: resolve9,
32456
32455
  resolveComponent,
32457
32456
  equal,
32458
32457
  serialize,
@@ -38317,14 +38316,14 @@ var ProbeWindow = class ProbeWindow2 {
38317
38316
  */
38318
38317
  async exchange(buildRequest, timeoutMs) {
38319
38318
  const id = `server-discover-probe-${++this._probeCounter}`;
38320
- return new Promise((resolve8) => {
38319
+ return new Promise((resolve9) => {
38321
38320
  let settled = false;
38322
38321
  const settle = (reply) => {
38323
38322
  if (settled) return;
38324
38323
  settled = true;
38325
38324
  clearTimeout(timer);
38326
38325
  if (this._pending?.id === id) this._pending = void 0;
38327
- resolve8(reply);
38326
+ resolve9(reply);
38328
38327
  };
38329
38328
  const timer = setTimeout(() => settle({ kind: "timeout" }), timeoutMs);
38330
38329
  this._pending = {
@@ -39538,13 +39537,13 @@ var Client = class extends Protocol {
39538
39537
  let onCallerAbort;
39539
39538
  let resolveOpening;
39540
39539
  let rejectOpening;
39541
- const opening = new Promise((resolve8, reject) => {
39542
- resolveOpening = resolve8;
39540
+ const opening = new Promise((resolve9, reject) => {
39541
+ resolveOpening = resolve9;
39543
39542
  rejectOpening = reject;
39544
39543
  });
39545
39544
  let resolveClosed;
39546
- const closed = new Promise((resolve8) => {
39547
- resolveClosed = resolve8;
39545
+ const closed = new Promise((resolve9) => {
39546
+ resolveClosed = resolve9;
39548
39547
  });
39549
39548
  const settle = (outcome) => {
39550
39549
  if (state === "closed") return;
@@ -40100,7 +40099,7 @@ var SSEClientTransport = class {
40100
40099
  const eventSourceFetch = this._eventSourceInit?.fetch;
40101
40100
  const fetchImpl = this._redirects(eventSourceFetch ? this._dpop?.(eventSourceFetch) ?? eventSourceFetch : this._fetch ?? fetch);
40102
40101
  let redirect;
40103
- return new Promise((resolve8, reject) => {
40102
+ return new Promise((resolve9, reject) => {
40104
40103
  this._eventSource = new EventSource(this._url.href, {
40105
40104
  ...this._eventSourceInit,
40106
40105
  fetch: async (url3, init) => {
@@ -40134,7 +40133,7 @@ var SSEClientTransport = class {
40134
40133
  response,
40135
40134
  serverUrl: this._url,
40136
40135
  fetchFn: this._fetchWithInit
40137
- }).then(() => this._startOrAuth().then(resolve8, reject), (error$2) => {
40136
+ }).then(() => this._startOrAuth().then(resolve9, reject), (error$2) => {
40138
40137
  this._connectAuthRetried = false;
40139
40138
  markAuthSeamEscape(error$2);
40140
40139
  this.onerror?.(error$2);
@@ -40172,7 +40171,7 @@ var SSEClientTransport = class {
40172
40171
  this.close();
40173
40172
  return;
40174
40173
  }
40175
- resolve8();
40174
+ resolve9();
40176
40175
  });
40177
40176
  this._eventSource.onmessage = (event) => {
40178
40177
  const messageEvent = event;
@@ -40921,7 +40920,7 @@ var StdioClientTransport = class {
40921
40920
  */
40922
40921
  async start() {
40923
40922
  if (this._process) throw new Error("StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.");
40924
- return new Promise((resolve8, reject) => {
40923
+ return new Promise((resolve9, reject) => {
40925
40924
  this._process = (0, import_cross_spawn.default)(this._serverParams.command, this._serverParams.args ?? [], {
40926
40925
  env: {
40927
40926
  ...getDefaultEnvironment(),
@@ -40941,7 +40940,7 @@ var StdioClientTransport = class {
40941
40940
  this.onerror?.(error);
40942
40941
  });
40943
40942
  this._process.on("spawn", () => {
40944
- resolve8();
40943
+ resolve9();
40945
40944
  });
40946
40945
  this._process.on("close", (_code) => {
40947
40946
  this._process = void 0;
@@ -41006,7 +41005,7 @@ var StdioClientTransport = class {
41006
41005
  const proc = this._process;
41007
41006
  this._process = void 0;
41008
41007
  if (proc && proc.exitCode === null && proc.signalCode === null) {
41009
- const exited = new Promise((resolve8) => proc.once("exit", () => resolve8()));
41008
+ const exited = new Promise((resolve9) => proc.once("exit", () => resolve9()));
41010
41009
  try {
41011
41010
  proc.stdin?.end();
41012
41011
  } catch {
@@ -41015,7 +41014,7 @@ var StdioClientTransport = class {
41015
41014
  proc.kill("SIGTERM");
41016
41015
  } catch {
41017
41016
  }
41018
- await Promise.race([exited, new Promise((resolve8) => setTimeout(resolve8, 1e3).unref())]);
41017
+ await Promise.race([exited, new Promise((resolve9) => setTimeout(resolve9, 1e3).unref())]);
41019
41018
  if (proc.exitCode === null && proc.signalCode === null) try {
41020
41019
  proc.kill("SIGKILL");
41021
41020
  } catch {
@@ -41040,22 +41039,22 @@ var StdioClientTransport = class {
41040
41039
  if (this._process) {
41041
41040
  const processToClose = this._process;
41042
41041
  this._process = void 0;
41043
- const closePromise = new Promise((resolve8) => {
41042
+ const closePromise = new Promise((resolve9) => {
41044
41043
  processToClose.once("close", () => {
41045
- resolve8();
41044
+ resolve9();
41046
41045
  });
41047
41046
  });
41048
41047
  try {
41049
41048
  processToClose.stdin?.end();
41050
41049
  } catch {
41051
41050
  }
41052
- await Promise.race([closePromise, new Promise((resolve8) => setTimeout(resolve8, 2e3).unref())]);
41051
+ await Promise.race([closePromise, new Promise((resolve9) => setTimeout(resolve9, 2e3).unref())]);
41053
41052
  if (processToClose.exitCode === null) {
41054
41053
  try {
41055
41054
  processToClose.kill("SIGTERM");
41056
41055
  } catch {
41057
41056
  }
41058
- await Promise.race([closePromise, new Promise((resolve8) => setTimeout(resolve8, 2e3).unref())]);
41057
+ await Promise.race([closePromise, new Promise((resolve9) => setTimeout(resolve9, 2e3).unref())]);
41059
41058
  }
41060
41059
  if (processToClose.exitCode === null) try {
41061
41060
  processToClose.kill("SIGKILL");
@@ -41065,11 +41064,11 @@ var StdioClientTransport = class {
41065
41064
  this._readBuffer.clear();
41066
41065
  }
41067
41066
  send(message) {
41068
- return new Promise((resolve8) => {
41067
+ return new Promise((resolve9) => {
41069
41068
  if (!this._process?.stdin) throw new SdkError(SdkErrorCode.NotConnected, "Not connected");
41070
41069
  const json = serializeMessage(message);
41071
- if (this._process.stdin.write(json)) resolve8();
41072
- else this._process.stdin.once("drain", resolve8);
41070
+ if (this._process.stdin.write(json)) resolve9();
41071
+ else this._process.stdin.once("drain", resolve9);
41073
41072
  });
41074
41073
  }
41075
41074
  };
@@ -41090,13 +41089,13 @@ var UnixSocketClientTransport = class {
41090
41089
  if (this.socket) {
41091
41090
  throw new Error("UnixSocketClientTransport already started");
41092
41091
  }
41093
- await new Promise((resolve8, reject) => {
41092
+ await new Promise((resolve9, reject) => {
41094
41093
  const socket = createConnection(this.socketPath);
41095
41094
  this.socket = socket;
41096
41095
  let connected = false;
41097
41096
  socket.once("connect", () => {
41098
41097
  connected = true;
41099
- resolve8();
41098
+ resolve9();
41100
41099
  });
41101
41100
  socket.on("data", (chunk) => {
41102
41101
  try {
@@ -41128,12 +41127,12 @@ var UnixSocketClientTransport = class {
41128
41127
  this.socket = void 0;
41129
41128
  this.readBuffer.clear();
41130
41129
  if (!socket || socket.destroyed) return;
41131
- await new Promise((resolve8) => {
41130
+ await new Promise((resolve9) => {
41132
41131
  const timeout = setTimeout(() => socket.destroy(), 2e3);
41133
41132
  timeout.unref();
41134
41133
  socket.once("close", () => {
41135
41134
  clearTimeout(timeout);
41136
- resolve8();
41135
+ resolve9();
41137
41136
  });
41138
41137
  socket.end();
41139
41138
  });
@@ -41141,10 +41140,10 @@ var UnixSocketClientTransport = class {
41141
41140
  async send(message) {
41142
41141
  const socket = this.socket;
41143
41142
  if (!socket || socket.destroyed) throw new Error("Unix socket is not connected");
41144
- await new Promise((resolve8, reject) => {
41143
+ await new Promise((resolve9, reject) => {
41145
41144
  socket.write(serializeMessage(message), (error) => {
41146
41145
  if (error) reject(error);
41147
- else resolve8();
41146
+ else resolve9();
41148
41147
  });
41149
41148
  });
41150
41149
  }
@@ -41309,7 +41308,7 @@ function throwIfAborted(signal) {
41309
41308
  async function abortable(promise, signal) {
41310
41309
  if (!signal) return promise;
41311
41310
  throwIfAborted(signal);
41312
- return await new Promise((resolve8, reject) => {
41311
+ return await new Promise((resolve9, reject) => {
41313
41312
  let settled = false;
41314
41313
  const cleanup = () => signal.removeEventListener("abort", onAbort);
41315
41314
  const onAbort = () => {
@@ -41324,7 +41323,7 @@ async function abortable(promise, signal) {
41324
41323
  if (settled) return;
41325
41324
  settled = true;
41326
41325
  cleanup();
41327
- resolve8(value);
41326
+ resolve9(value);
41328
41327
  },
41329
41328
  (error) => {
41330
41329
  if (settled) return;
@@ -41508,7 +41507,7 @@ var FORCE_CACHE_TIMEOUT_MS = 3e4;
41508
41507
  async function forceNpxCache(packageSpec, signal) {
41509
41508
  throwIfAborted(signal);
41510
41509
  try {
41511
- await new Promise((resolve8, reject) => {
41510
+ await new Promise((resolve9, reject) => {
41512
41511
  const proc = (0, import_cross_spawn2.default)(
41513
41512
  "npm",
41514
41513
  ["exec", "--yes", "--package", packageSpec, "--", "node", "-e", "1"],
@@ -41527,7 +41526,7 @@ async function forceNpxCache(packageSpec, signal) {
41527
41526
  proc.on("close", () => {
41528
41527
  clearTimeout(timer);
41529
41528
  signal?.removeEventListener("abort", abort);
41530
- resolve8();
41529
+ resolve9();
41531
41530
  });
41532
41531
  proc.on("error", (err) => {
41533
41532
  clearTimeout(timer);
@@ -43440,14 +43439,14 @@ var baseOpen = async (options) => {
43440
43439
  }
43441
43440
  const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
43442
43441
  if (options.wait) {
43443
- return new Promise((resolve8, reject) => {
43442
+ return new Promise((resolve9, reject) => {
43444
43443
  subprocess.once("error", reject);
43445
43444
  subprocess.once("close", (exitCode) => {
43446
43445
  if (!options.allowNonzeroExitCode && exitCode > 0) {
43447
43446
  reject(new Error(`Exited with code ${exitCode}`));
43448
43447
  return;
43449
43448
  }
43450
- resolve8(subprocess);
43449
+ resolve9(subprocess);
43451
43450
  });
43452
43451
  });
43453
43452
  }
@@ -43775,12 +43774,12 @@ async function ensureCallbackServerLocked(options = {}) {
43775
43774
  const candidateServer = createServer2(handleRequest);
43776
43775
  const listenPort = strictPort ? requiredPort : 0;
43777
43776
  try {
43778
- await new Promise((resolve8, reject) => {
43777
+ await new Promise((resolve9, reject) => {
43779
43778
  candidateServer.once("error", (err) => {
43780
43779
  reject(err);
43781
43780
  });
43782
43781
  candidateServer.listen(listenPort, requestedHost, () => {
43783
- resolve8();
43782
+ resolve9();
43784
43783
  });
43785
43784
  });
43786
43785
  if (strictPort) {
@@ -43793,8 +43792,8 @@ async function ensureCallbackServerLocked(options = {}) {
43793
43792
  setOAuthCallbackPort(address.port);
43794
43793
  }
43795
43794
  if (previousServer && (needsStrictRebind || needsHostSwitch)) {
43796
- await new Promise((resolve8) => {
43797
- previousServer.close(() => resolve8());
43795
+ await new Promise((resolve9) => {
43796
+ previousServer.close(() => resolve9());
43798
43797
  });
43799
43798
  }
43800
43799
  callbackServerHost = requestedHost;
@@ -43810,8 +43809,8 @@ async function ensureCallbackServerLocked(options = {}) {
43810
43809
  reservedAuthStates.delete(reservedState);
43811
43810
  }
43812
43811
  const nodeError = error;
43813
- await new Promise((resolve8) => {
43814
- candidateServer.close(() => resolve8());
43812
+ await new Promise((resolve9) => {
43813
+ candidateServer.close(() => resolve9());
43815
43814
  });
43816
43815
  if (strictPort && nodeError.code === "EADDRINUSE") {
43817
43816
  throw new Error(
@@ -43827,14 +43826,14 @@ function releaseCallbackServer(oauthState) {
43827
43826
  }
43828
43827
  function waitForCallback(oauthState) {
43829
43828
  reservedAuthStates.delete(oauthState);
43830
- return new Promise((resolve8, reject) => {
43829
+ return new Promise((resolve9, reject) => {
43831
43830
  const timeout = setTimeout(() => {
43832
43831
  if (pendingAuths.has(oauthState)) {
43833
43832
  pendingAuths.delete(oauthState);
43834
43833
  reject(new Error("OAuth callback timeout - authorization took too long"));
43835
43834
  }
43836
43835
  }, CALLBACK_TIMEOUT_MS);
43837
- pendingAuths.set(oauthState, { resolve: resolve8, reject, timeout });
43836
+ pendingAuths.set(oauthState, { resolve: resolve9, reject, timeout });
43838
43837
  });
43839
43838
  }
43840
43839
  function cancelPendingCallback(oauthState) {
@@ -43859,9 +43858,9 @@ function stopCallbackServer() {
43859
43858
  });
43860
43859
  }
43861
43860
  if (server) {
43862
- await new Promise((resolve8) => {
43861
+ await new Promise((resolve9) => {
43863
43862
  server.close(() => {
43864
- resolve8();
43863
+ resolve9();
43865
43864
  });
43866
43865
  });
43867
43866
  server = void 0;
@@ -45750,7 +45749,7 @@ function resolvedCommand(config) {
45750
45749
  async function invokeRequestHeadersCommand(config, envelope, signal) {
45751
45750
  const resolved = resolvedCommand(config);
45752
45751
  if (USE_PROCESS_GROUP) assertPosixProcessDiscoveryAvailable();
45753
- return new Promise((resolve8, reject) => {
45752
+ return new Promise((resolve9, reject) => {
45754
45753
  let stdout = Buffer.alloc(0);
45755
45754
  let settled = false;
45756
45755
  const cleanupToken = randomUUID4();
@@ -45779,7 +45778,7 @@ async function invokeRequestHeadersCommand(config, envelope, signal) {
45779
45778
  if (descendantTracker) clearInterval(descendantTracker);
45780
45779
  signal.removeEventListener("abort", abort);
45781
45780
  if (result.status === "error") reject(result.error);
45782
- else resolve8(result.headers);
45781
+ else resolve9(result.headers);
45783
45782
  };
45784
45783
  const finishAfterKill = (result) => {
45785
45784
  try {
@@ -49071,12 +49070,12 @@ async function openMcpSetup(state, pi, ctx, configOverridePath, mode = "setup",
49071
49070
  markSetupCompleted(discovery.fingerprint);
49072
49071
  }
49073
49072
  };
49074
- return new Promise((resolve8) => {
49073
+ return new Promise((resolve9) => {
49075
49074
  ctx.ui.custom(
49076
49075
  (tui, _theme, keybindings, done) => {
49077
49076
  return createMcpSetupPanel(discovery, callbacks, { mode, onboardingState, keybindings }, tui, () => {
49078
49077
  done(void 0);
49079
- resolve8({ configChanged });
49078
+ resolve9({ configChanged });
49080
49079
  });
49081
49080
  },
49082
49081
  { overlay: true, overlayOptions: { anchor: "center", width: 92 } }
@@ -49158,7 +49157,7 @@ async function openMcpPanel(state, pi, ctx, configOverridePath, onDirectToolsCon
49158
49157
  const callbacks = buildMcpPanelCallbacks(state, config, ctx, () => overlayHandle);
49159
49158
  const { createMcpPanel } = await import("./mcp-panel-KQREMMFT.js");
49160
49159
  let configChanged = false;
49161
- await new Promise((resolve8) => {
49160
+ await new Promise((resolve9) => {
49162
49161
  ctx.ui.custom(
49163
49162
  (tui, _theme, keybindings, done) => {
49164
49163
  return createMcpPanel(config, cache2, provenanceMap, callbacks, tui, (result) => {
@@ -49181,13 +49180,13 @@ async function openMcpPanel(state, pi, ctx, configOverridePath, onDirectToolsCon
49181
49180
  ctx.ui.notify("Direct tools updated for this session.", "info");
49182
49181
  }
49183
49182
  done(void 0);
49184
- resolve8();
49183
+ resolve9();
49185
49184
  })().catch((error) => {
49186
49185
  const message = error instanceof Error ? error.message : String(error);
49187
49186
  ctx.ui.notify(`Direct tools updated, but live refresh failed: ${message}`, "error");
49188
49187
  configChanged = true;
49189
49188
  done(void 0);
49190
- resolve8();
49189
+ resolve9();
49191
49190
  });
49192
49191
  }, { noticeLines, keybindings });
49193
49192
  },
@@ -49229,12 +49228,12 @@ async function openMcpAuthPanel(state, pi, ctx, configOverridePath) {
49229
49228
  let overlayHandle;
49230
49229
  const callbacks = buildMcpPanelCallbacks(state, config, ctx, () => overlayHandle);
49231
49230
  const { createMcpPanel } = await import("./mcp-panel-KQREMMFT.js");
49232
- await new Promise((resolve8) => {
49231
+ await new Promise((resolve9) => {
49233
49232
  ctx.ui.custom(
49234
49233
  (tui, _theme, keybindings, done) => {
49235
49234
  return createMcpPanel(config, cache2, provenanceMap, callbacks, tui, () => {
49236
49235
  done(void 0);
49237
- resolve8();
49236
+ resolve9();
49238
49237
  }, {
49239
49238
  authOnly: true,
49240
49239
  keybindings,
@@ -51181,7 +51180,7 @@ data: ${JSON.stringify(payload)}
51181
51180
  markCompleted("stale");
51182
51181
  }, WATCHDOG_INTERVAL_MS);
51183
51182
  watchdog.unref();
51184
- return new Promise((resolve8, reject) => {
51183
+ return new Promise((resolve9, reject) => {
51185
51184
  const candidates = resolvePortCandidates(options.port);
51186
51185
  let candidateIndex = 0;
51187
51186
  const startSandboxProxy = (parentOrigin) => {
@@ -51318,7 +51317,7 @@ data: ${JSON.stringify(payload)}
51318
51317
  getSessionMessages: () => ({ ...sessionMessages }),
51319
51318
  getStreamSummary: () => streamSummary ? { ...streamSummary, phases: [...streamSummary.phases] } : void 0
51320
51319
  };
51321
- resolve8(handle);
51320
+ resolve9(handle);
51322
51321
  }).catch((error) => {
51323
51322
  log.error("Failed to start sandbox proxy", error instanceof Error ? error : void 0);
51324
51323
  closeListeners();
@@ -51343,7 +51342,7 @@ async function parseBody(req, res) {
51343
51342
  }
51344
51343
  }
51345
51344
  function readBody2(req) {
51346
- return new Promise((resolve8, reject) => {
51345
+ return new Promise((resolve9, reject) => {
51347
51346
  let size = 0;
51348
51347
  const chunks = [];
51349
51348
  req.on("data", (chunk) => {
@@ -51357,7 +51356,7 @@ function readBody2(req) {
51357
51356
  });
51358
51357
  req.on("end", () => {
51359
51358
  try {
51360
- resolve8(JSON.parse(Buffer.concat(chunks).toString("utf-8")));
51359
+ resolve9(JSON.parse(Buffer.concat(chunks).toString("utf-8")));
51361
51360
  } catch (error) {
51362
51361
  reject(error);
51363
51362
  }
@@ -51538,22 +51537,22 @@ function isRemoteSession() {
51538
51537
  return Boolean(process.env.SSH_CONNECTION || process.env.SSH_TTY);
51539
51538
  }
51540
51539
  function hasActiveRemoteLogin() {
51541
- return new Promise((resolve8) => {
51540
+ return new Promise((resolve9) => {
51542
51541
  execFile6("who", { encoding: "utf8", timeout: 2e3 }, (error, out) => {
51543
51542
  if (error) {
51544
- resolve8(false);
51543
+ resolve9(false);
51545
51544
  return;
51546
51545
  }
51547
- resolve8(/\(.+\)\s*$/m.test(out));
51546
+ resolve9(/\(.+\)\s*$/m.test(out));
51548
51547
  });
51549
51548
  });
51550
51549
  }
51551
51550
  function probeMoshiGateway() {
51552
- return new Promise((resolve8) => {
51551
+ return new Promise((resolve9) => {
51553
51552
  const socket = net.connect({ host: "127.0.0.1", port: 24543 });
51554
51553
  const done = (ok) => {
51555
51554
  socket.destroy();
51556
- resolve8(ok);
51555
+ resolve9(ok);
51557
51556
  };
51558
51557
  socket.setTimeout(300);
51559
51558
  socket.once("connect", () => done(true));
@@ -57973,7 +57972,7 @@ async function runMcpScript(state, code, timeoutMs = DEFAULT_MCP_SCRIPT_TIMEOUT_
57973
57972
  trackUnmanagedFds: false
57974
57973
  });
57975
57974
  const activeWorker = worker;
57976
- const execution = new Promise((resolve8, reject) => {
57975
+ const execution = new Promise((resolve9, reject) => {
57977
57976
  let completed = false;
57978
57977
  activeWorker.on("message", (value) => {
57979
57978
  const message = parseWorkerMessage(value);
@@ -57985,7 +57984,7 @@ async function runMcpScript(state, code, timeoutMs = DEFAULT_MCP_SCRIPT_TIMEOUT_
57985
57984
  if (message.type === "done") {
57986
57985
  completed = true;
57987
57986
  if ("returnBlock" in message) output.push(toContentBlock(message.returnBlock));
57988
- resolve8();
57987
+ resolve9();
57989
57988
  return;
57990
57989
  }
57991
57990
  if (message.type === "error") {
@@ -58264,8 +58263,8 @@ async function awaitWithTimeout(promise, timeoutMs) {
58264
58263
  try {
58265
58264
  return await Promise.race([
58266
58265
  promise,
58267
- new Promise((resolve8) => {
58268
- timer = setTimeout(() => resolve8(INIT_WAIT_TIMED_OUT), timeoutMs);
58266
+ new Promise((resolve9) => {
58267
+ timer = setTimeout(() => resolve9(INIT_WAIT_TIMED_OUT), timeoutMs);
58269
58268
  timer.unref?.();
58270
58269
  })
58271
58270
  ]);
@@ -60661,15 +60660,15 @@ var GLOBAL_CANVAS_DIRECTORIES = [
60661
60660
  join25(process.env.XDG_DATA_HOME ?? join25(homedir7(), ".local", "share"), "opencode", "plans"),
60662
60661
  join25(homedir7(), ".replicas", "canvas")
60663
60662
  ];
60664
- async function canvasDirectories() {
60665
- const repositories = await gitService.listRepositories().catch(() => []);
60663
+ async function canvasDirectories(repositories) {
60664
+ repositories ??= await gitService.listRepositories().catch(() => []);
60666
60665
  return [
60667
60666
  ...GLOBAL_CANVAS_DIRECTORIES,
60668
60667
  ...repositories.map((repository) => join25(repository.path, ".opencode", "plans"))
60669
60668
  ];
60670
60669
  }
60671
60670
  var CanvasService = class {
60672
- constructor(directories = canvasDirectories) {
60671
+ constructor(directories = () => canvasDirectories()) {
60673
60672
  this.directories = directories;
60674
60673
  }
60675
60674
  directories;
@@ -60899,7 +60898,7 @@ function parseChatMessageSendersJsonl(content) {
60899
60898
  import { request as httpRequest } from "http";
60900
60899
  import { request as httpsRequest } from "https";
60901
60900
  async function putPresignedFile(urlValue, body, size, contentType) {
60902
- await new Promise((resolve8, reject) => {
60901
+ await new Promise((resolve9, reject) => {
60903
60902
  const url3 = new URL(urlValue);
60904
60903
  const request = (url3.protocol === "https:" ? httpsRequest : httpRequest)(url3, {
60905
60904
  method: "PUT",
@@ -60915,7 +60914,7 @@ async function putPresignedFile(urlValue, body, size, contentType) {
60915
60914
  });
60916
60915
  response.on("end", () => {
60917
60916
  const status = response.statusCode ?? 0;
60918
- if (status >= 200 && status < 300) resolve8();
60917
+ if (status >= 200 && status < 300) resolve9();
60919
60918
  else reject(new Error(`upload failed: ${status} ${body2}`));
60920
60919
  });
60921
60920
  response.on("error", reject);
@@ -61220,13 +61219,13 @@ function runBeforeDeadline(operation, deadline) {
61220
61219
  const timeoutMs = deadline - Date.now();
61221
61220
  if (timeoutMs <= 0) return Promise.reject(new DOMException("engine log flush deadline exceeded", "TimeoutError"));
61222
61221
  const signal = AbortSignal.timeout(timeoutMs);
61223
- return new Promise((resolve8, reject) => {
61222
+ return new Promise((resolve9, reject) => {
61224
61223
  const onAbort = () => reject(signal.reason);
61225
61224
  signal.addEventListener("abort", onAbort, { once: true });
61226
61225
  operation(signal).then(
61227
61226
  (value) => {
61228
61227
  signal.removeEventListener("abort", onAbort);
61229
- resolve8(value);
61228
+ resolve9(value);
61230
61229
  },
61231
61230
  (error) => {
61232
61231
  signal.removeEventListener("abort", onAbort);
@@ -61838,8 +61837,8 @@ var ChatService = class {
61838
61837
  }
61839
61838
  const remainingMs = timeoutMs === null ? null : timeoutMs - (Date.now() - startedAt);
61840
61839
  if (remainingMs !== null && remainingMs <= 0) return { ...result, timedOut: true };
61841
- await new Promise((resolve8) => setTimeout(
61842
- resolve8,
61840
+ await new Promise((resolve9) => setTimeout(
61841
+ resolve9,
61843
61842
  remainingMs === null ? SUBAGENT_POLL_INTERVAL_MS : Math.min(SUBAGENT_POLL_INTERVAL_MS, remainingMs)
61844
61843
  ));
61845
61844
  }
@@ -63570,9 +63569,10 @@ ${note}`;
63570
63569
 
63571
63570
  // src/services/repo-file-service.ts
63572
63571
  import { execFile as execFile7 } from "child_process";
63573
- import { readFile as readFile19 } from "fs/promises";
63572
+ import { createReadStream as createReadStream2 } from "fs";
63573
+ import { readFile as readFile19, realpath as realpath2, stat as stat5 } from "fs/promises";
63574
63574
  import { homedir as homedir9 } from "os";
63575
- import { extname as extname3, join as join32 } from "path";
63575
+ import { extname as extname3, isAbsolute as isAbsolute3, join as join32, resolve as resolve5 } from "path";
63576
63576
 
63577
63577
  // src/services/language-server-service.ts
63578
63578
  import { spawn as spawn4 } from "child_process";
@@ -63772,8 +63772,14 @@ function isBinaryExtension(filePath) {
63772
63772
  ]);
63773
63773
  return classifyCanvasFilename(filePath).kind === "image" || binaryExts.has(ext);
63774
63774
  }
63775
+ async function readUpTo(path8, maxBytes) {
63776
+ const chunks = [];
63777
+ for await (const chunk of createReadStream2(path8, { end: maxBytes })) chunks.push(chunk);
63778
+ const bytes = Buffer.concat(chunks);
63779
+ return bytes.length > maxBytes ? null : bytes;
63780
+ }
63775
63781
  function execGitAsync(args, cwd, timeoutMs) {
63776
- return new Promise((resolve8, reject) => {
63782
+ return new Promise((resolve9, reject) => {
63777
63783
  const child = execFile7("git", [...UNQUOTED_PATHS_CONFIG, ...args], {
63778
63784
  cwd,
63779
63785
  encoding: "utf-8",
@@ -63783,7 +63789,7 @@ function execGitAsync(args, cwd, timeoutMs) {
63783
63789
  if (error) {
63784
63790
  reject(error);
63785
63791
  } else {
63786
- resolve8(stdout);
63792
+ resolve9(stdout);
63787
63793
  }
63788
63794
  });
63789
63795
  child.stdin?.end();
@@ -63847,10 +63853,22 @@ var RepoFileService = class {
63847
63853
  const file = await this.readResolvedFile(repoName, filePath, resolved);
63848
63854
  return typeof file?.content === "string" ? { ...file, revision: fileRevision(file.content) } : file;
63849
63855
  }
63850
- /** Read-only: skill files carry no revision, so the viewer never offers to edit them. */
63851
- async readSkillFile(filePath) {
63852
- const resolved = await this.resolveSkillFile(filePath);
63853
- return resolved ? await this.readResolvedFile("", filePath, resolved) : null;
63856
+ /** Read-only: files outside the repos carry no revision, so the viewer never offers to edit them. */
63857
+ async readWorkspaceFile(filePath) {
63858
+ const repos = await this.gitService.listRepositories();
63859
+ const roots = [
63860
+ ...isAbsolute3(filePath) ? ["/"] : [],
63861
+ ...repos.map((repo) => repo.path),
63862
+ ...await canvasDirectories(repos),
63863
+ join32(this.homeDir, "workspaces"),
63864
+ this.homeDir
63865
+ ];
63866
+ for (const root of roots) {
63867
+ const path8 = resolve5(root, filePath.replace(/^\/+/, ""));
63868
+ const file = await realpath2(path8).then(async (fullPath) => ({ fullPath, stats: await stat5(fullPath) })).catch(() => null);
63869
+ if (file?.stats.isFile()) return await this.readResolvedFile("", path8, { fullPath: file.fullPath, sizeBytes: file.stats.size });
63870
+ }
63871
+ return null;
63854
63872
  }
63855
63873
  async readResolvedFile(repoName, filePath, { fullPath, sizeBytes }) {
63856
63874
  try {
@@ -63858,18 +63876,7 @@ var RepoFileService = class {
63858
63876
  const { kind, mimeType } = classifyCanvasFilename(filePath);
63859
63877
  if (kind === "image" || kind === "pdf" || kind === "docx") {
63860
63878
  const maxPreviewBytes = kind === "image" ? MAX_CANVAS_FILE_BYTES : MAX_CANVAS_PREVIEW_BYTES;
63861
- if (sizeBytes > maxPreviewBytes) {
63862
- return {
63863
- repoName,
63864
- path: filePath,
63865
- content: null,
63866
- language: null,
63867
- sizeBytes,
63868
- binary: true,
63869
- tooLarge: true,
63870
- mimeType
63871
- };
63872
- }
63879
+ const bytes2 = sizeBytes > maxPreviewBytes ? null : await readUpTo(fullPath, maxPreviewBytes);
63873
63880
  return {
63874
63881
  repoName,
63875
63882
  path: filePath,
@@ -63877,9 +63884,9 @@ var RepoFileService = class {
63877
63884
  language: null,
63878
63885
  sizeBytes,
63879
63886
  binary: true,
63880
- tooLarge: false,
63881
- base64: (await readFile19(fullPath)).toString("base64"),
63882
- mimeType
63887
+ tooLarge: !bytes2,
63888
+ mimeType,
63889
+ ...bytes2 && { base64: bytes2.toString("base64") }
63883
63890
  };
63884
63891
  }
63885
63892
  return {
@@ -63892,7 +63899,8 @@ var RepoFileService = class {
63892
63899
  tooLarge: false
63893
63900
  };
63894
63901
  }
63895
- if (sizeBytes > MAX_REPO_FILE_CONTENT_BYTES) {
63902
+ const bytes = sizeBytes > MAX_REPO_FILE_CONTENT_BYTES ? null : await readUpTo(fullPath, MAX_REPO_FILE_CONTENT_BYTES);
63903
+ if (!bytes) {
63896
63904
  return {
63897
63905
  repoName,
63898
63906
  path: filePath,
@@ -63903,11 +63911,21 @@ var RepoFileService = class {
63903
63911
  tooLarge: true
63904
63912
  };
63905
63913
  }
63906
- const content = await readFile19(fullPath, "utf-8");
63914
+ if (bytes.includes(0)) {
63915
+ return {
63916
+ repoName,
63917
+ path: filePath,
63918
+ content: null,
63919
+ language: null,
63920
+ sizeBytes,
63921
+ binary: true,
63922
+ tooLarge: false
63923
+ };
63924
+ }
63907
63925
  return {
63908
63926
  repoName,
63909
63927
  path: filePath,
63910
- content,
63928
+ content: bytes.toString("utf-8"),
63911
63929
  language: detectLanguageByPath(filePath),
63912
63930
  sizeBytes,
63913
63931
  binary: false,
@@ -63983,16 +64001,6 @@ var RepoFileService = class {
63983
64001
  if (!repo) return null;
63984
64002
  return await resolveContainedFile(repo.path, filePath);
63985
64003
  }
63986
- async resolveSkillFile(filePath) {
63987
- const skillRoots = SANDBOX_SKILL_DIRS.map((dir) => join32(this.homeDir, dir));
63988
- if (!skillRoots.some((root) => filePath.startsWith(`${root}/`))) return null;
63989
- const repos = await this.gitService.listRepositories();
63990
- for (const root of [...skillRoots, ...repos.map((repo) => repo.path)]) {
63991
- const resolved = await resolveContainedFile(root, filePath);
63992
- if (resolved) return resolved.fullPath.split("/").includes(".git") ? null : resolved;
63993
- }
63994
- return null;
63995
- }
63996
64004
  async indexAll(refresh) {
63997
64005
  const repos = await this.gitService.listRepositories();
63998
64006
  for (const repo of repos) {
@@ -64057,9 +64065,9 @@ var RepoFileService = class {
64057
64065
  // src/v1-routes.ts
64058
64066
  import { Hono } from "hono";
64059
64067
  import { z as z6 } from "zod";
64060
- import { readdir as readdir11, stat as stat5, readFile as readFile22 } from "fs/promises";
64068
+ import { readdir as readdir11, stat as stat6, readFile as readFile22 } from "fs/promises";
64061
64069
  import { openAsBlob } from "fs";
64062
- import { join as join35, resolve as resolve5 } from "path";
64070
+ import { join as join35, resolve as resolve6 } from "path";
64063
64071
 
64064
64072
  // src/services/warm-hooks-service.ts
64065
64073
  import { spawn as spawn5 } from "child_process";
@@ -64223,7 +64231,7 @@ async function executeHookScriptStreaming(params) {
64223
64231
  let bufferExceeded = false;
64224
64232
  params.onChunk(`$ ${params.label}
64225
64233
  `);
64226
- return new Promise((resolve8) => {
64234
+ return new Promise((resolve9) => {
64227
64235
  const proc = spawn5("bash", ["-lc", params.content], {
64228
64236
  cwd: params.cwd,
64229
64237
  env: process.env,
@@ -64256,7 +64264,7 @@ async function executeHookScriptStreaming(params) {
64256
64264
  proc.on("close", (code) => {
64257
64265
  clearTimeout(timer);
64258
64266
  const output = [`$ ${params.label}`, ...outputParts].join("");
64259
- resolve8({
64267
+ resolve9({
64260
64268
  exitCode: bufferExceeded ? 1 : code ?? 1,
64261
64269
  output,
64262
64270
  timedOut: killed && !bufferExceeded
@@ -64266,7 +64274,7 @@ async function executeHookScriptStreaming(params) {
64266
64274
  clearTimeout(timer);
64267
64275
  const output = [`$ ${params.label}
64268
64276
  `, ...outputParts, err.message].join("");
64269
- resolve8({
64277
+ resolve9({
64270
64278
  exitCode: 1,
64271
64279
  output,
64272
64280
  timedOut: false
@@ -65117,10 +65125,10 @@ function createV1Routes(deps) {
65117
65125
  }
65118
65126
  return c.json(result);
65119
65127
  });
65120
- app2.get("/skill-files/content", async (c) => {
65128
+ app2.get("/files/content", async (c) => {
65121
65129
  const path8 = c.req.query("path");
65122
65130
  if (!path8) return c.json(jsonError("path is required"), 400);
65123
- const result = await deps.repoFileService.readSkillFile(path8);
65131
+ const result = await deps.repoFileService.readWorkspaceFile(path8);
65124
65132
  if (!result) return c.json(jsonError("File not found"), 404);
65125
65133
  return c.json(result);
65126
65134
  });
@@ -65548,7 +65556,7 @@ data: ${JSON.stringify("Terminal session not found")}
65548
65556
  const sessions = await Promise.all(
65549
65557
  logFiles.map(async (filename) => {
65550
65558
  const filePath = join35(LOG_DIR, filename);
65551
- const fileStat = await stat5(filePath);
65559
+ const fileStat = await stat6(filePath);
65552
65560
  const sessionId = filename.replace(/\.log$/, "");
65553
65561
  return {
65554
65562
  sessionId,
@@ -65576,8 +65584,8 @@ data: ${JSON.stringify("Terminal session not found")}
65576
65584
  if (!isValidEngineLogSessionId(sessionId)) {
65577
65585
  return c.json(jsonError("Invalid session ID"), 400);
65578
65586
  }
65579
- const filePath = resolve5(LOG_DIR, `${sessionId}.log`);
65580
- if (!filePath.startsWith(resolve5(LOG_DIR))) {
65587
+ const filePath = resolve6(LOG_DIR, `${sessionId}.log`);
65588
+ if (!filePath.startsWith(resolve6(LOG_DIR))) {
65581
65589
  return c.json(jsonError("Invalid session ID"), 400);
65582
65590
  }
65583
65591
  let content;
@@ -65604,9 +65612,9 @@ data: ${JSON.stringify("Terminal session not found")}
65604
65612
 
65605
65613
  // src/services/exec/exec-socket.ts
65606
65614
  import { randomUUID as randomUUID12 } from "crypto";
65607
- import { mkdir as mkdir17, open as open3, stat as stat6, writeFile as writeFile10 } from "fs/promises";
65615
+ import { mkdir as mkdir17, open as open3, stat as stat7, writeFile as writeFile10 } from "fs/promises";
65608
65616
  import { arch as arch2, platform as platform3 } from "os";
65609
- import { dirname as dirname14, join as join36, resolve as resolve6 } from "path";
65617
+ import { dirname as dirname14, join as join36, resolve as resolve7 } from "path";
65610
65618
  import { z as z7 } from "zod";
65611
65619
 
65612
65620
  // src/services/exec/process-registry.ts
@@ -65733,8 +65741,8 @@ var ProcessRegistry = class {
65733
65741
  child.stdin.on("error", () => {
65734
65742
  });
65735
65743
  if (!options.stdin) child.stdin.end();
65736
- return new Promise((resolve8) => {
65737
- child.once("error", (error) => resolve8(createErrorResult({ code: "spawn_error", message: error.message })));
65744
+ return new Promise((resolve9) => {
65745
+ child.once("error", (error) => resolve9(createErrorResult({ code: "spawn_error", message: error.message })));
65738
65746
  child.once("spawn", () => {
65739
65747
  const managed = new ManagedProcess(options, child, () => this.processes.delete(managed.id));
65740
65748
  this.processes.set(managed.id, managed);
@@ -65751,7 +65759,7 @@ var ProcessRegistry = class {
65751
65759
  drain = setTimeout(settle, EXIT_DRAIN_MS);
65752
65760
  });
65753
65761
  child.once("close", settle);
65754
- resolve8(createSuccessResult(managed));
65762
+ resolve9(createSuccessResult(managed));
65755
65763
  });
65756
65764
  });
65757
65765
  }
@@ -65803,7 +65811,7 @@ function parse(schema, json) {
65803
65811
  }
65804
65812
  function resolvePath(target) {
65805
65813
  if (target === "~" || target.startsWith("~/")) return join36(ENGINE_ENV.HOME_DIR, target.slice(1));
65806
- return resolve6(ENGINE_ENV.WORKSPACE_ROOT, target);
65814
+ return resolve7(ENGINE_ENV.WORKSPACE_ROOT, target);
65807
65815
  }
65808
65816
  async function mcpServerProcess(name) {
65809
65817
  const entry = (await getManagedPiMcpServers())[name];
@@ -65891,7 +65899,7 @@ function attachExecSocket(socket) {
65891
65899
  };
65892
65900
  },
65893
65901
  stat: async (_id, json) => {
65894
- const info = await stat6(resolvePath(parse(schemas.stat, json).path));
65902
+ const info = await stat7(resolvePath(parse(schemas.stat, json).path));
65895
65903
  const kind = info.isFile() ? "file" : info.isDirectory() ? "directory" : "other";
65896
65904
  return { kind, size: info.size, mtimeMs: info.mtimeMs };
65897
65905
  },
@@ -65918,7 +65926,7 @@ function attachExecSocket(socket) {
65918
65926
  exec: async (id, json) => {
65919
65927
  const request = parse(schemas.exec, json);
65920
65928
  const cwd = resolvePath(request.cwd ?? ".");
65921
- if (!(await stat6(cwd).catch(() => null))?.isDirectory()) throw new ExecError("ENOENT", `Working directory not found: ${cwd}`, cwd);
65929
+ if (!(await stat7(cwd).catch(() => null))?.isDirectory()) throw new ExecError("ENOENT", `Working directory not found: ${cwd}`, cwd);
65922
65930
  const [file, ...args] = request.argv ?? ["/bin/bash", request.login === false ? "-c" : "-lc", request.command ?? ""];
65923
65931
  const target = request.mcpServer ? { ...await mcpServerProcess(request.mcpServer), command: `mcp ${request.mcpServer}` } : { file, args, command: request.command ?? args.join(" ") };
65924
65932
  const spawned = await processRegistry.spawn({ ...request, ...target, cwd });
@@ -66145,7 +66153,7 @@ var ResourceMonitor = class {
66145
66153
  if (this.sampling) return;
66146
66154
  this.sampling = true;
66147
66155
  try {
66148
- const [stat7, meminfo, cpuPressure, memoryPressure, ioPressure] = await Promise.all([
66156
+ const [stat8, meminfo, cpuPressure, memoryPressure, ioPressure] = await Promise.all([
66149
66157
  readWithin("/proc/stat"),
66150
66158
  readWithin("/proc/meminfo"),
66151
66159
  readOptional("/proc/pressure/cpu"),
@@ -66153,7 +66161,7 @@ var ResourceMonitor = class {
66153
66161
  readOptional("/proc/pressure/io")
66154
66162
  ]);
66155
66163
  if (!this.timer) return;
66156
- const lines = stat7.split("\n");
66164
+ const lines = stat8.split("\n");
66157
66165
  const jiffies = lines[0].trim().split(/\s+/).slice(1, 9).map(Number);
66158
66166
  const total = jiffies.reduce((sum, value) => sum + value, 0);
66159
66167
  const cpu = { busy: total - jiffies[3] - jiffies[4], total };
@@ -66312,12 +66320,12 @@ var heartbeatService = new HeartbeatService();
66312
66320
 
66313
66321
  // src/services/workspace-sdk-service.ts
66314
66322
  import { cp, mkdir as mkdir18 } from "fs/promises";
66315
- import { dirname as dirname15, resolve as resolve7 } from "path";
66323
+ import { dirname as dirname15, resolve as resolve8 } from "path";
66316
66324
  import { fileURLToPath as fileURLToPath6 } from "url";
66317
66325
  async function installWorkspaceSdk() {
66318
- const source = resolve7(dirname15(fileURLToPath6(import.meta.url)), "../../workspace-sdk");
66326
+ const source = resolve8(dirname15(fileURLToPath6(import.meta.url)), "../../workspace-sdk");
66319
66327
  const targets = [
66320
- resolve7(ENGINE_ENV.HOME_DIR, "node_modules/@replicas/sdk"),
66328
+ resolve8(ENGINE_ENV.HOME_DIR, "node_modules/@replicas/sdk"),
66321
66329
  "/tmp/node_modules/@replicas/sdk"
66322
66330
  ];
66323
66331
  await Promise.all(targets.map(async (target) => {
@@ -66383,12 +66391,12 @@ async function listen() {
66383
66391
  }).catch((error) => console.error("[GitPushTracker] Failed to track pushed repository:", error));
66384
66392
  });
66385
66393
  });
66386
- await new Promise((resolve8, reject) => {
66394
+ await new Promise((resolve9, reject) => {
66387
66395
  server3.once("error", reject);
66388
66396
  server3.listen(SOCKET_PATH, () => {
66389
66397
  server3.off("error", reject);
66390
66398
  server3.on("error", (error) => console.error("[GitPushTracker] Socket error:", error));
66391
- resolve8();
66399
+ resolve9();
66392
66400
  });
66393
66401
  });
66394
66402
  process.env.GIT_TRACE2_EVENT = `af_unix:stream:${SOCKET_PATH}`;
@@ -66439,11 +66447,11 @@ async function checkActiveSSHSessions() {
66439
66447
  }
66440
66448
  }
66441
66449
  function checkDesktopReady() {
66442
- return new Promise((resolve8) => {
66450
+ return new Promise((resolve9) => {
66443
66451
  const socket = connect({ host: "127.0.0.1", port: DESKTOP_STREAM_PORT });
66444
66452
  const done = (ready) => {
66445
66453
  socket.destroy();
66446
- resolve8(ready);
66454
+ resolve9(ready);
66447
66455
  };
66448
66456
  socket.once("connect", () => done(true));
66449
66457
  socket.once("error", () => done(false));