spacecode 2.11.1 → 2.12.1

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/repl.mjs CHANGED
@@ -104418,15 +104418,30 @@ async function runCoreTurn(d, prompt) {
104418
104418
  ...body === void 0 ? {} : { body: JSON.stringify(body) },
104419
104419
  signal: d.signal
104420
104420
  });
104421
- if (!res.ok) throw new CoreTurnError(`core run request failed (${res.status}) ${method} ${path13.split("?")[0]}`);
104421
+ if (!res.ok) throw new CoreTurnError(`core run request failed (${res.status}) ${method} ${path13.split("?")[0]}`, res.status);
104422
104422
  return res.json();
104423
104423
  };
104424
+ const poll = async (path13) => {
104425
+ for (let attempt = 0; ; attempt++) {
104426
+ try {
104427
+ return await call("GET", path13);
104428
+ } catch (err) {
104429
+ const transient = err instanceof CoreTurnError && err.status !== void 0 && err.status >= 500;
104430
+ if (!transient || d.signal.aborted) throw err;
104431
+ if (attempt >= POLL_RETRIES) throw new CoreTurnError(`${err.message} (gave up after ${POLL_RETRIES} retries)`, err.status);
104432
+ d.emit({ type: "text", seq: ++seq, content: `(run service answered ${err.status}; retry ${attempt + 1}/${POLL_RETRIES})
104433
+
104434
+ ` });
104435
+ await d.sleep(Math.min(8e3, 1e3 * 2 ** attempt));
104436
+ }
104437
+ }
104438
+ };
104424
104439
  let runId = d.getRunId();
104425
104440
  if (!runId) {
104426
104441
  const created = await call("POST", "", {
104427
104442
  sessionId: d.sessionId,
104428
104443
  budgetTokens: d.budgetTokens ?? DEFAULT_BUDGET,
104429
- ...d.repo ? { repoUrl: d.repo.url, ...d.repo.branch ? { branch: d.repo.branch } : {} } : {}
104444
+ ...d.repo ? { repoUrl: d.repo.url, ...d.repo.branch ? { branch: d.repo.branch } : {}, ...d.ghToken ? { ghToken: d.ghToken } : {} } : {}
104430
104445
  });
104431
104446
  runId = created.runId;
104432
104447
  d.setRunId(runId);
@@ -104442,7 +104457,7 @@ async function runCoreTurn(d, prompt) {
104442
104457
  let state = null;
104443
104458
  for (; ; ) {
104444
104459
  if (d.signal.aborted) throw new CoreTurnError("aborted");
104445
- const events = (await call("GET", `/${runId}/events?after=${cur.after}&limit=200`)).events;
104460
+ const events = (await poll(`/${runId}/events?after=${cur.after}&limit=200`)).events;
104446
104461
  for (const e of events) {
104447
104462
  cur.after = Math.max(cur.after, e.seq);
104448
104463
  if (!e.applied) continue;
@@ -104454,7 +104469,7 @@ async function runCoreTurn(d, prompt) {
104454
104469
  }
104455
104470
  if (e.type === "verifier_result" && Array.isArray(p.problems) && p.problems.length > 0) say(`task ${String(p.taskId)}: verifier: ${p.problems.join("; ")}`);
104456
104471
  }
104457
- state = (await call("GET", `/${runId}`)).state;
104472
+ state = (await poll(`/${runId}`)).state;
104458
104473
  const now = {};
104459
104474
  for (const id of state.order) now[id] = state.tasks[id].status;
104460
104475
  const changed = state.order.filter((id) => now[id] !== cur.known[id]);
@@ -104485,7 +104500,7 @@ async function runCoreTurn(d, prompt) {
104485
104500
  cur.tokensBase = state.tokensUsed;
104486
104501
  return { success: (state.status === "done" || state.status === "needs_user") && patchFailures === 0, text: lastText, tokens };
104487
104502
  }
104488
- var newRunCursor, TERMINAL, DEFAULT_BUDGET, DEFAULT_MAX_WAIT_MS, CoreTurnError;
104503
+ var newRunCursor, TERMINAL, DEFAULT_BUDGET, DEFAULT_MAX_WAIT_MS, CoreTurnError, POLL_RETRIES;
104489
104504
  var init_core_turn = __esm({
104490
104505
  "src/core/core-turn.ts"() {
104491
104506
  "use strict";
@@ -104494,7 +104509,12 @@ var init_core_turn = __esm({
104494
104509
  DEFAULT_BUDGET = 5e5;
104495
104510
  DEFAULT_MAX_WAIT_MS = 30 * 6e4;
104496
104511
  CoreTurnError = class extends Error {
104512
+ constructor(message, status) {
104513
+ super(message);
104514
+ this.status = status;
104515
+ }
104497
104516
  };
104517
+ POLL_RETRIES = 5;
104498
104518
  }
104499
104519
  });
104500
104520
 
@@ -104519,6 +104539,11 @@ async function detectRepo(cwd2, env3) {
104519
104539
  const branch = env3.SPACECODE_CORE_BRANCH?.trim();
104520
104540
  return { url, ...branch ? { branch } : {} };
104521
104541
  }
104542
+ function shareableGithubToken(env3) {
104543
+ if (env3.SPACECODE_CORE_SHARE_GITHUB_TOKEN?.trim().toLowerCase() !== "on") return void 0;
104544
+ const t = (env3.GH_TOKEN ?? env3.GITHUB_TOKEN)?.trim();
104545
+ return t ? t : void 0;
104546
+ }
104522
104547
  function patchApplier(executor, cwd2, runId) {
104523
104548
  return async ({ taskId, patch }) => {
104524
104549
  const top = await gitOut(cwd2, ["rev-parse", "--show-toplevel"]) ?? cwd2;
@@ -104541,6 +104566,7 @@ async function runCoreForRepl(o) {
104541
104566
  apiKey: o.apiKey,
104542
104567
  sessionId: o.sessionId,
104543
104568
  repo,
104569
+ ...shareableGithubToken(o.env) ? { ghToken: shareableGithubToken(o.env) } : {},
104544
104570
  getRunId: () => o.runIdRef.current,
104545
104571
  setRunId: (id) => {
104546
104572
  o.runIdRef.current = id;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spacecode",
3
- "version": "2.11.1",
3
+ "version": "2.12.1",
4
4
  "description": "SpaceCode - launch cloud dev environments with AI coding agents",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",