spacecode 2.14.3 → 2.14.4

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
@@ -6375,9 +6375,9 @@ var init_trust = __esm({
6375
6375
  });
6376
6376
 
6377
6377
  // ../agent/src/import/source-changes.ts
6378
- function fingerprintSources(files, hash) {
6378
+ function fingerprintSources(files, hash2) {
6379
6379
  const fingerprint = {};
6380
- for (const [path13, content] of Object.entries(files)) fingerprint[path13] = hash(content);
6380
+ for (const [path13, content] of Object.entries(files)) fingerprint[path13] = hash2(content);
6381
6381
  return fingerprint;
6382
6382
  }
6383
6383
  function diffSources(before, after) {
@@ -6397,8 +6397,8 @@ var init_source_changes = __esm({
6397
6397
  });
6398
6398
 
6399
6399
  // ../agent/src/import/mcp-tool-cache.ts
6400
- function serverCacheKey(def, hash) {
6401
- return hash(JSON.stringify([def.name, def.command, def.args, [...def.envNames].sort()]));
6400
+ function serverCacheKey(def, hash2) {
6401
+ return hash2(JSON.stringify([def.name, def.command, def.args, [...def.envNames].sort()]));
6402
6402
  }
6403
6403
  function cleanTool(raw) {
6404
6404
  if (!isPlainObject(raw) || typeof raw.name !== "string" || raw.name === "" || typeof raw.description !== "string" || !isPlainObject(raw.inputSchema)) return null;
@@ -7817,9 +7817,9 @@ function formatAdaptReport(r, before, replaced) {
7817
7817
  }
7818
7818
  async function adaptInstructions(deps, original) {
7819
7819
  const { client, log } = deps;
7820
- const hash = await sha12(original);
7820
+ const hash2 = await sha12(original);
7821
7821
  const current = await client.get("instructions", "global");
7822
- const marker = adaptedMarker(hash);
7822
+ const marker = adaptedMarker(hash2);
7823
7823
  const existingOrig = await client.get("instructions", "global.orig");
7824
7824
  if (current && existingOrig && existingOrig.content === original && current.description === marker) {
7825
7825
  log(" unchanged instructions/global (already adapted from this source)");
@@ -7886,7 +7886,7 @@ var init_import_adapt = __esm({
7886
7886
  "use strict";
7887
7887
  init_src();
7888
7888
  EXCERPT_CHARS = 1e3;
7889
- adaptedMarker = (hash) => `adapted-from:${hash}`;
7889
+ adaptedMarker = (hash2) => `adapted-from:${hash2}`;
7890
7890
  }
7891
7891
  });
7892
7892
 
@@ -104991,14 +104991,15 @@ async function must(shell, cmd, what) {
104991
104991
  if (r.exitCode !== 0) throw new Error(`${what} failed: ${r.stderr.trim() || `exit ${r.exitCode}`}`);
104992
104992
  return r.stdout.trim();
104993
104993
  }
104994
- async function createTaskWorktree(shell, cwd2, runId, taskId, attempt) {
104994
+ async function createTaskWorktree(shell, cwd2, base, runId, taskId, attempt, warn = () => {
104995
+ }) {
104995
104996
  const top = await must(shell, `cd ${q2(cwd2)} && git rev-parse --show-toplevel`, "finding the repository root");
104996
- const gitDir = await must(shell, `cd ${q2(cwd2)} && git rev-parse --absolute-git-dir`, "finding the git directory");
104997
- const base = await must(shell, `cd ${q2(top)} && git stash create`, "snapshotting the working tree") || "HEAD";
104998
- const root = `${gitDir}/spacecode-core`;
104999
- await shell(`find ${q2(root)} -mindepth 2 -maxdepth 2 -type d -name 'wt-*' -mmin +1440 2>/dev/null | while read -r w; do git -C ${q2(top)} worktree remove --force "$w" >/dev/null 2>&1; done; git -C ${q2(top)} worktree prune`);
104997
+ const commit = await must(shell, `cd ${q2(top)} && git stash create`, "snapshotting the working tree") || "HEAD";
104998
+ const root = `${base}/${safe(top.slice(top.lastIndexOf("/") + 1))}-${hash(top)}`;
104999
+ const sweep = await shell(`find ${q2(root)} -mindepth 2 -maxdepth 2 -type d -name 'wt-*' -mmin +1440 2>/dev/null | while read -r w; do git -C ${q2(top)} worktree remove --force "$w" >/dev/null 2>&1; done; git -C ${q2(top)} worktree prune`);
105000
+ if (sweep.exitCode !== 0) warn(`stale worktree sweep failed: ${sweep.stderr.trim().slice(0, 200) || `exit ${sweep.exitCode}`}`);
105000
105001
  const dir = `${root}/${safe(runId)}/wt-${safe(taskId)}-${attempt}`;
105001
- await must(shell, `git -C ${q2(top)} worktree add --detach ${q2(dir)} ${q2(base)}`, "creating the task worktree");
105002
+ await must(shell, `git -C ${q2(top)} worktree add --detach ${q2(dir)} ${q2(commit)}`, "creating the task worktree");
105002
105003
  const found = await must(shell, `cd ${q2(top)} && find . -maxdepth 4 -name node_modules -type d -prune -not -path './.git/*'`, "listing dependency folders");
105003
105004
  for (const line of found.split("\n")) {
105004
105005
  const rel = line.trim().replace(/^\.\//, "");
@@ -105016,12 +105017,17 @@ async function removeTaskWorktree(shell, top, dir) {
105016
105017
  return err instanceof Error ? err.message : String(err);
105017
105018
  }
105018
105019
  }
105019
- var q2, safe;
105020
+ var q2, safe, hash;
105020
105021
  var init_worktree = __esm({
105021
105022
  "src/core/worktree.ts"() {
105022
105023
  "use strict";
105023
105024
  q2 = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
105024
105025
  safe = (s) => s.replace(/[^A-Za-z0-9_.-]/g, "_");
105026
+ hash = (s) => {
105027
+ let h = 5381;
105028
+ for (let i = 0; i < s.length; i++) h = (h << 5) + h + s.charCodeAt(i) >>> 0;
105029
+ return h.toString(16);
105030
+ };
105025
105031
  }
105026
105032
  });
105027
105033
 
@@ -105034,7 +105040,7 @@ function localPipelineDeps(d, job) {
105034
105040
  const deps = {
105035
105041
  sandbox: { exec: shell, writeFile: (path13, content) => d.writeFile(path13, content) },
105036
105042
  setup: async () => {
105037
- const wt = await createTaskWorktree(shell, d.cwd, d.runId, job.taskId, job.attempt);
105043
+ const wt = await createTaskWorktree(shell, d.cwd, d.worktreeBase, d.runId, job.taskId, job.attempt, (message) => d.log(message, { runId: d.runId, taskId: job.taskId }));
105038
105044
  created = wt;
105039
105045
  return wt.dir;
105040
105046
  },
@@ -105228,6 +105234,7 @@ var init_core_turn = __esm({
105228
105234
  import { execFile as execFile4 } from "node:child_process";
105229
105235
  import { mkdir as mkdir6, writeFile as writeFile6 } from "node:fs/promises";
105230
105236
  import { join as join15 } from "node:path";
105237
+ import { tmpdir } from "node:os";
105231
105238
  async function repoIsPublic(url, fetchFn = fetch) {
105232
105239
  const hit = visibility.get(url);
105233
105240
  if (hit !== void 0) return hit;
@@ -105305,6 +105312,7 @@ async function runCoreForRepl(o) {
105305
105312
  const { deps, cleanup } = localPipelineDeps(
105306
105313
  {
105307
105314
  cwd: o.cwd,
105315
+ worktreeBase: join15(tmpdir(), "spacecode-core"),
105308
105316
  runId,
105309
105317
  backendUrl: backendUrl(o.env),
105310
105318
  apiKey: o.apiKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spacecode",
3
- "version": "2.14.3",
3
+ "version": "2.14.4",
4
4
  "description": "SpaceCode - launch cloud dev environments with AI coding agents",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",