@tablation/crew 0.130.5 → 0.130.7
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/cli.js +1095 -1007
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4751,7 +4751,10 @@ The \`${f.hook}\` hook (\`${f.label}\`) printed, last lines:
|
|
|
4751
4751
|
${f.tail}
|
|
4752
4752
|
\`\`\``;
|
|
4753
4753
|
}
|
|
4754
|
-
function describeRelease(o, route2) {
|
|
4754
|
+
function describeRelease(o, route2, where) {
|
|
4755
|
+
const shipNote = where?.ship ? `
|
|
4756
|
+
|
|
4757
|
+
Failed on ship ${where.ship}${where.runner === "sandbox" ? " (sandbox runner, released on the host rather than from a release sandbox)" : ""}; other ships' releases of this repository are unaffected.` : "";
|
|
4755
4758
|
if (o.integrated) {
|
|
4756
4759
|
return {
|
|
4757
4760
|
level: "ok",
|
|
@@ -4787,7 +4790,7 @@ ${o.isolation}` : ""),
|
|
|
4787
4790
|
level: "fail",
|
|
4788
4791
|
headline: `${route2}: release blocked \u2014 setup failed`,
|
|
4789
4792
|
detail: withHookTail(
|
|
4790
|
-
|
|
4793
|
+
`the setup hook failed in the release checkout; the target stays on the previous release${shipNote}`,
|
|
4791
4794
|
o.hookFailure
|
|
4792
4795
|
)
|
|
4793
4796
|
};
|
|
@@ -5059,7 +5062,11 @@ ${userLine}ExecStart=${[...crewInvocation(crewHome), ...subcommandFor(job, "syst
|
|
|
5059
5062
|
WorkingDirectory=${crewHome}
|
|
5060
5063
|
${systemdEnvLines(ship)}
|
|
5061
5064
|
StandardOutput=append:${schedulerLog}
|
|
5062
|
-
StandardError=append:${schedulerLog}
|
|
5065
|
+
StandardError=append:${schedulerLog}${job === "passengers" ? `
|
|
5066
|
+
# CREW-2994: the sync spawns the relay tunnel (a detached ssh) and exits. The
|
|
5067
|
+
# default KillMode=control-group would kill that ssh with the rest of this
|
|
5068
|
+
# one-shot unit's cgroup, so no tunnel would ever survive to "connected".
|
|
5069
|
+
KillMode=process` : ""}
|
|
5063
5070
|
`;
|
|
5064
5071
|
const timer = `# Written by \`crew install\` \u2014 re-run it rather than hand-editing this file.
|
|
5065
5072
|
[Unit]
|
|
@@ -6405,7 +6412,10 @@ function repoFindings(o) {
|
|
|
6405
6412
|
if (o.base.failed) {
|
|
6406
6413
|
problems.push({ severity: "blocker", kind: "base_unsafe", ...at, message: `${o.repo}: ${o.base.message}` });
|
|
6407
6414
|
} else if (o.base.message) passed++;
|
|
6408
|
-
for (const
|
|
6415
|
+
for (const g of o.sandboxGaps ?? []) {
|
|
6416
|
+
problems.push({ severity: "attention", kind: "hook_missing", ...at, hook: g.hook, command: g.command, message: g.message, remedy: g.remedy });
|
|
6417
|
+
}
|
|
6418
|
+
for (const hook2 of o.sandboxGaps ? [] : HOOK_NAMES2) {
|
|
6409
6419
|
const script = o.hooks[hook2];
|
|
6410
6420
|
const command2 = script ? hookCommand(script) : null;
|
|
6411
6421
|
if (!command2) continue;
|
|
@@ -6466,18 +6476,9 @@ function attentionProblems(items, already) {
|
|
|
6466
6476
|
return items.filter((i) => !seen.has(i.key)).map((i) => ({ severity: "attention", kind: i.kind, message: i.message }));
|
|
6467
6477
|
}
|
|
6468
6478
|
|
|
6469
|
-
// src/sandbox-image.ts
|
|
6470
|
-
import { createHash as createHash7 } from "crypto";
|
|
6471
|
-
import { spawn as spawn5 } from "child_process";
|
|
6472
|
-
import { execFileSync as execFileSync9 } from "child_process";
|
|
6473
|
-
import { existsSync as existsSync29, mkdirSync as mkdirSync19, readFileSync as readFileSync28, renameSync as renameSync3, writeFileSync as writeFileSync20, rmSync as rmSync15 } from "fs";
|
|
6474
|
-
import { dirname as dirname15, join as join32 } from "path";
|
|
6475
|
-
import { fileURLToPath } from "url";
|
|
6476
|
-
import { tmpdir as tmpdir3 } from "os";
|
|
6477
|
-
|
|
6478
6479
|
// src/passenger-containers.ts
|
|
6479
|
-
import { execFileSync as
|
|
6480
|
-
import { createHash as
|
|
6480
|
+
import { execFileSync as execFileSync9 } from "child_process";
|
|
6481
|
+
import { createHash as createHash7 } from "crypto";
|
|
6481
6482
|
|
|
6482
6483
|
// src/sandbox-cache.ts
|
|
6483
6484
|
import { execFile as execFile2 } from "child_process";
|
|
@@ -6485,19 +6486,19 @@ import { promisify as promisify2 } from "util";
|
|
|
6485
6486
|
|
|
6486
6487
|
// src/deprovision-host.ts
|
|
6487
6488
|
import { spawnSync as spawnSync7 } from "child_process";
|
|
6488
|
-
import { existsSync as
|
|
6489
|
+
import { existsSync as existsSync29, readdirSync as readdirSync11 } from "fs";
|
|
6489
6490
|
|
|
6490
6491
|
// src/interrupted.ts
|
|
6491
|
-
import { existsSync as
|
|
6492
|
-
import { join as
|
|
6492
|
+
import { existsSync as existsSync27, readdirSync as readdirSync9, readFileSync as readFileSync28 } from "fs";
|
|
6493
|
+
import { join as join31 } from "path";
|
|
6493
6494
|
|
|
6494
6495
|
// src/agent.ts
|
|
6495
6496
|
import { spawnSync as spawnSync6 } from "child_process";
|
|
6496
|
-
import { readFileSync as
|
|
6497
|
+
import { readFileSync as readFileSync27, existsSync as existsSync26, statSync as statSync8, mkdirSync as mkdirSync19, writeFileSync as writeFileSync20, createWriteStream, openSync as openSync4, closeSync as closeSync4, readSync } from "fs";
|
|
6497
6498
|
import { StringDecoder } from "string_decoder";
|
|
6498
6499
|
import { finished } from "stream/promises";
|
|
6499
|
-
import { join as
|
|
6500
|
-
import { createHash as
|
|
6500
|
+
import { join as join30, dirname as dirname15, basename as basename9 } from "path";
|
|
6501
|
+
import { createHash as createHash6, randomUUID } from "crypto";
|
|
6501
6502
|
|
|
6502
6503
|
// src/state.ts
|
|
6503
6504
|
import { readFileSync as readFileSync19, writeFileSync as writeFileSync14, existsSync as existsSync18, mkdirSync as mkdirSync13, rmSync as rmSync10, statSync as statSync7, readdirSync as readdirSync5 } from "fs";
|
|
@@ -10818,291 +10819,623 @@ var HandoffTranscriptTracker = class {
|
|
|
10818
10819
|
}
|
|
10819
10820
|
};
|
|
10820
10821
|
|
|
10821
|
-
// src/
|
|
10822
|
-
|
|
10822
|
+
// src/sandbox-image.ts
|
|
10823
|
+
import { createHash as createHash4 } from "crypto";
|
|
10824
|
+
import { spawn as spawn3 } from "child_process";
|
|
10825
|
+
import { execFileSync as execFileSync7 } from "child_process";
|
|
10826
|
+
import { existsSync as existsSync23, mkdirSync as mkdirSync17, readFileSync as readFileSync24, renameSync as renameSync3, writeFileSync as writeFileSync18, rmSync as rmSync14 } from "fs";
|
|
10827
|
+
import { dirname as dirname13, join as join26 } from "path";
|
|
10828
|
+
import { fileURLToPath } from "url";
|
|
10829
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
10830
|
+
var SANDBOX_BASE_IMAGE = "nvcr.io/nvidia/base/ubuntu:24.04";
|
|
10831
|
+
var SANDBOX_OPENSHELL_VERSION = "0.1.6";
|
|
10832
|
+
var SANDBOX_CLAUDE_VERSION = "2.1.309";
|
|
10833
|
+
var SANDBOX_CLAUDE_DIST = "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases";
|
|
10834
|
+
var SANDBOX_CLAUDE_SHA256 = {
|
|
10835
|
+
x86_64: { platform: "linux-x64", sha256: "4d704a8aecbe038affa3000f498ae17c1b4f753add8facb8764120affc99b658" },
|
|
10836
|
+
aarch64: { platform: "linux-arm64", sha256: "9796dd26899337f687739a0b39a7353b639f062a3436a7b941fcf19a1b757a9b" }
|
|
10823
10837
|
};
|
|
10824
|
-
var
|
|
10825
|
-
var
|
|
10826
|
-
var
|
|
10827
|
-
function
|
|
10828
|
-
const
|
|
10829
|
-
for (const
|
|
10830
|
-
|
|
10831
|
-
if (name && !names.includes(name)) names.push(name);
|
|
10838
|
+
var SANDBOX_UID = 1e3;
|
|
10839
|
+
var CREW_PREFIX = "/opt/crew";
|
|
10840
|
+
var SANDBOX_BRIDGE_PATH = `${CREW_PREFIX}/bin/intel-bridge`;
|
|
10841
|
+
function readBridgeBundle() {
|
|
10842
|
+
const here = dirname13(fileURLToPath(import.meta.url));
|
|
10843
|
+
for (const p of [join26(here, "sandbox-intel-bridge.cjs"), join26(here, "..", "dist", "sandbox-intel-bridge.cjs")]) {
|
|
10844
|
+
if (existsSync23(p)) return readFileSync24(p, "utf8");
|
|
10832
10845
|
}
|
|
10833
|
-
return
|
|
10834
|
-
}
|
|
10835
|
-
function expandSkillMarkers(text2, lookup2, opts = {}) {
|
|
10836
|
-
const maxDepth = opts.maxDepth ?? MAX_INCLUDE_DEPTH;
|
|
10837
|
-
const maxBytes = opts.maxBytes ?? MAX_INCLUDED_BYTES;
|
|
10838
|
-
const warnings = [];
|
|
10839
|
-
let included = 0;
|
|
10840
|
-
const expand2 = (source, chain) => source.replace(MARKER, (literal, rawName) => {
|
|
10841
|
-
const name = rawName.trim();
|
|
10842
|
-
if (!name) return literal;
|
|
10843
|
-
if (chain.includes(name)) {
|
|
10844
|
-
warnings.push(`skill include "${name}" left literal: it includes itself (${[...chain, name].join(" \u2192 ")})`);
|
|
10845
|
-
return literal;
|
|
10846
|
-
}
|
|
10847
|
-
if (chain.length >= maxDepth) {
|
|
10848
|
-
warnings.push(`skill include "${name}" left literal: nested deeper than ${maxDepth} levels`);
|
|
10849
|
-
return literal;
|
|
10850
|
-
}
|
|
10851
|
-
const body = lookup2(name);
|
|
10852
|
-
if (body === void 0) throw new SkillIncludeError(`no skill named "${name}" for the include ${literal}`);
|
|
10853
|
-
const trimmed = body.replace(/^\n+/, "").replace(/\n+$/, "");
|
|
10854
|
-
const bytes = Buffer.byteLength(trimmed, "utf8");
|
|
10855
|
-
if (included + bytes > maxBytes) {
|
|
10856
|
-
warnings.push(`skill include "${name}" left literal: it would exceed the ${maxBytes}-byte include budget`);
|
|
10857
|
-
return literal;
|
|
10858
|
-
}
|
|
10859
|
-
included += bytes;
|
|
10860
|
-
return expand2(trimmed, [...chain, name]);
|
|
10861
|
-
});
|
|
10862
|
-
return { text: expand2(text2, []), warnings };
|
|
10863
|
-
}
|
|
10864
|
-
|
|
10865
|
-
// src/skills.ts
|
|
10866
|
-
import { readFileSync as readFileSync25, readdirSync as readdirSync8, existsSync as existsSync24 } from "fs";
|
|
10867
|
-
import { join as join27 } from "path";
|
|
10868
|
-
import { parse as parseYaml } from "yaml";
|
|
10869
|
-
import { TablationClient as TablationClient3, StaleWriteError as StaleWriteError3, TablationApiError as TablationApiError2 } from "@tablation/client";
|
|
10870
|
-
|
|
10871
|
-
// src/prompt-additions.ts
|
|
10872
|
-
var PROMPT_ADDITIONS_SEPARATOR = "---\n\nAdditional instructions from this workspace. Where they conflict with anything above, these take precedence.";
|
|
10873
|
-
function appendAdditions(text2, additions) {
|
|
10874
|
-
if (typeof additions !== "string" || additions.trim() === "") return text2;
|
|
10875
|
-
return `${text2}
|
|
10876
|
-
|
|
10877
|
-
${PROMPT_ADDITIONS_SEPARATOR}
|
|
10878
|
-
|
|
10879
|
-
${additions}`;
|
|
10846
|
+
return void 0;
|
|
10880
10847
|
}
|
|
10881
|
-
|
|
10882
|
-
|
|
10883
|
-
|
|
10884
|
-
|
|
10885
|
-
|
|
10886
|
-
var
|
|
10887
|
-
|
|
10888
|
-
|
|
10889
|
-
|
|
10890
|
-
|
|
10891
|
-
|
|
10892
|
-
}
|
|
10893
|
-
|
|
10894
|
-
|
|
10895
|
-
var
|
|
10848
|
+
var SANDBOX_UV_VERSION = "0.13.6";
|
|
10849
|
+
var SANDBOX_SERENA_VERSION = "2.1.0";
|
|
10850
|
+
var SERENA_IMAGE_HOME = `${CREW_PREFIX}/serena`;
|
|
10851
|
+
var SERENA_LANGUAGE_SERVERS_ENV = "CREW_SERENA_LANGUAGE_SERVERS";
|
|
10852
|
+
var SANDBOX_RETRY_AFTER_MS = 60 * 60 * 1e3;
|
|
10853
|
+
var KEEP_TAGS = 2;
|
|
10854
|
+
var CREDENTIAL_HELPER = `#!/bin/sh
|
|
10855
|
+
# git credential helper: answers from the environment the runner passes in, so
|
|
10856
|
+
# no token is ever written into an image layer.
|
|
10857
|
+
[ "$1" = get ] || exit 0
|
|
10858
|
+
[ -n "$CREW_FORGE_TOKEN" ] || exit 0
|
|
10859
|
+
echo "username=\${CREW_FORGE_USER:-x-access-token}"
|
|
10860
|
+
echo "password=$CREW_FORGE_TOKEN"
|
|
10861
|
+
`;
|
|
10862
|
+
var MCP_CONFIG = `${JSON.stringify({ mcpServers: {} }, null, 2)}
|
|
10863
|
+
`;
|
|
10864
|
+
var hash = (parts) => createHash4("sha256").update(JSON.stringify(parts)).digest("hex").slice(0, 12);
|
|
10865
|
+
var slug = (s) => s.toLowerCase().replace(/[^a-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "") || "repo";
|
|
10866
|
+
var run2 = (cmd) => `RUN ["/bin/bash", "-c", ${JSON.stringify(`set -euo pipefail; ${cmd}`)}]`;
|
|
10867
|
+
var CREW_ENV = {
|
|
10868
|
+
CREW_SANDBOX: "1",
|
|
10869
|
+
CREW_CACHE_DIR: `${CREW_PREFIX}/cache`,
|
|
10870
|
+
XDG_CACHE_HOME: `${CREW_PREFIX}/cache`,
|
|
10871
|
+
npm_config_cache: `${CREW_PREFIX}/cache/npm`,
|
|
10872
|
+
npm_config_store_dir: `${CREW_PREFIX}/pnpm-store`,
|
|
10873
|
+
// pnpm 11 ignores npm_config_store_dir and reads only this spelling (CREW-2973): without it `pnpm fetch`
|
|
10874
|
+
// at build time fills the builder's home store, and a run's offline install finds /opt/crew/pnpm-store empty.
|
|
10875
|
+
pnpm_config_store_dir: `${CREW_PREFIX}/pnpm-store`,
|
|
10876
|
+
PNPM_HOME: `${CREW_PREFIX}/pnpm`,
|
|
10877
|
+
// A run cannot reach the download host, so an in-run update attempt is only noise.
|
|
10878
|
+
DISABLE_AUTOUPDATER: "1"
|
|
10896
10879
|
};
|
|
10897
|
-
function
|
|
10898
|
-
const
|
|
10899
|
-
|
|
10900
|
-
|
|
10901
|
-
|
|
10902
|
-
|
|
10903
|
-
return
|
|
10880
|
+
function sandboxEnvExports() {
|
|
10881
|
+
const vars = {
|
|
10882
|
+
...CREW_ENV,
|
|
10883
|
+
[SERENA_LANGUAGE_SERVERS_ENV]: `${SERENA_IMAGE_HOME}/language_servers`,
|
|
10884
|
+
UV_PYTHON_INSTALL_DIR: `${CREW_PREFIX}/uv/python`
|
|
10885
|
+
};
|
|
10886
|
+
return Object.entries(vars).map(([k, v]) => `${k}=${v}; export ${k}; `).join("");
|
|
10904
10887
|
}
|
|
10905
|
-
|
|
10906
|
-
const
|
|
10907
|
-
|
|
10908
|
-
|
|
10909
|
-
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10914
|
-
|
|
10915
|
-
try {
|
|
10916
|
-
const row = await client2.records.get(route2.resolved.models.crew, seatId);
|
|
10917
|
-
return row.agent_id ?? void 0;
|
|
10918
|
-
} catch {
|
|
10919
|
-
return void 0;
|
|
10920
|
-
}
|
|
10888
|
+
function claudeInstallCommand() {
|
|
10889
|
+
const cases = Object.entries(SANDBOX_CLAUDE_SHA256).map(([arch, { platform: platform2, sha256: sha2562 }]) => `${arch}) p=${platform2}; sum=${sha2562};;`).join(" ");
|
|
10890
|
+
return [
|
|
10891
|
+
`case "$(uname -m)" in ${cases} *) echo "no pinned Claude Code binary for $(uname -m)" >&2; exit 1;; esac`,
|
|
10892
|
+
`mkdir -p ${CREW_PREFIX}/bin`,
|
|
10893
|
+
`curl -fsSL --retry 3 -o ${CREW_PREFIX}/bin/claude "${SANDBOX_CLAUDE_DIST}/${SANDBOX_CLAUDE_VERSION}/$p/claude"`,
|
|
10894
|
+
`echo "$sum ${CREW_PREFIX}/bin/claude" | sha256sum -c -`,
|
|
10895
|
+
`chmod 0755 ${CREW_PREFIX}/bin/claude`,
|
|
10896
|
+
`${CREW_PREFIX}/bin/claude --version | grep -F "${SANDBOX_CLAUDE_VERSION}"`
|
|
10897
|
+
].join("; ");
|
|
10921
10898
|
}
|
|
10922
|
-
|
|
10923
|
-
|
|
10924
|
-
|
|
10925
|
-
|
|
10926
|
-
|
|
10927
|
-
|
|
10928
|
-
|
|
10929
|
-
|
|
10930
|
-
let row;
|
|
10931
|
-
let agentsModelId;
|
|
10932
|
-
try {
|
|
10933
|
-
const agentsModel = await client2.dataModels.get("agents", route2.resolved.workspaceId);
|
|
10934
|
-
agentsModelId = agentsModel.id;
|
|
10935
|
-
row = await client2.records.get(agentsModelId, agentId);
|
|
10936
|
-
} catch {
|
|
10937
|
-
return {};
|
|
10938
|
-
}
|
|
10939
|
-
const additions = typeof row.prompt_additions === "string" && row.prompt_additions.trim() !== "" ? row.prompt_additions : void 0;
|
|
10940
|
-
const divergedPrompt = await divergedRowPrompt(route2, role, row, agentId, agentsModelId, opts);
|
|
10941
|
-
return { divergedPrompt, additions };
|
|
10899
|
+
function serenaInstallCommand() {
|
|
10900
|
+
return [
|
|
10901
|
+
`python3 -m venv ${CREW_PREFIX}/uv-venv`,
|
|
10902
|
+
`${CREW_PREFIX}/uv-venv/bin/pip install --no-cache-dir uv==${SANDBOX_UV_VERSION}`,
|
|
10903
|
+
`ln -sf ${CREW_PREFIX}/uv-venv/bin/uv ${CREW_PREFIX}/bin/uv`,
|
|
10904
|
+
`UV_TOOL_DIR=${CREW_PREFIX}/uv/tools UV_TOOL_BIN_DIR=${CREW_PREFIX}/bin UV_PYTHON_INSTALL_DIR=${CREW_PREFIX}/uv/python UV_CACHE_DIR=${CREW_PREFIX}/cache/uv ${CREW_PREFIX}/bin/uv tool install -p 3.13 serena-agent==${SANDBOX_SERENA_VERSION}`,
|
|
10905
|
+
`${CREW_PREFIX}/bin/serena --help >/dev/null`
|
|
10906
|
+
].join("; ");
|
|
10942
10907
|
}
|
|
10943
|
-
function
|
|
10944
|
-
return
|
|
10908
|
+
function serenaWarmCommand() {
|
|
10909
|
+
return [
|
|
10910
|
+
`mkdir -p ${SERENA_IMAGE_HOME}`,
|
|
10911
|
+
`SERENA_HOME=${SERENA_IMAGE_HOME} serena project index ${WARM_DIR}`
|
|
10912
|
+
].join("; ");
|
|
10945
10913
|
}
|
|
10946
|
-
|
|
10947
|
-
|
|
10948
|
-
|
|
10949
|
-
|
|
10950
|
-
|
|
10951
|
-
|
|
10952
|
-
|
|
10953
|
-
if (lastSynced !== void 0 && lastSynced === row.prompt) return void 0;
|
|
10954
|
-
}
|
|
10955
|
-
return row.prompt;
|
|
10914
|
+
function baseLayer() {
|
|
10915
|
+
const dockerfile = [
|
|
10916
|
+
`FROM ${SANDBOX_BASE_IMAGE}`,
|
|
10917
|
+
`LABEL io.crew.sandbox.layer="base" io.crew.sandbox.openshell="${SANDBOX_OPENSHELL_VERSION}"`,
|
|
10918
|
+
""
|
|
10919
|
+
].join("\n");
|
|
10920
|
+
return { name: "base", tag: `crew-sandbox-base:${hash({ SANDBOX_BASE_IMAGE, SANDBOX_OPENSHELL_VERSION })}`, dockerfile, files: {} };
|
|
10956
10921
|
}
|
|
10957
|
-
|
|
10958
|
-
|
|
10959
|
-
|
|
10960
|
-
|
|
10961
|
-
|
|
10962
|
-
|
|
10922
|
+
var APT_HTTPS_COMMAND = "sed -i -E 's#http://([a-z0-9.-]*\\.)?ubuntu\\.com#https://\\1ubuntu.com#g' /etc/apt/sources.list.d/ubuntu.sources 2>/dev/null || true";
|
|
10923
|
+
var CA_BUNDLE_FILE = "ca-certificates.crt";
|
|
10924
|
+
var HOST_CA_BUNDLES = ["/etc/ssl/certs/ca-certificates.crt", "/etc/pki/tls/certs/ca-bundle.crt", "/etc/ssl/cert.pem"];
|
|
10925
|
+
function readHostCaBundle(paths = HOST_CA_BUNDLES) {
|
|
10926
|
+
for (const path of paths) {
|
|
10927
|
+
try {
|
|
10928
|
+
return readFileSync24(path, "utf8");
|
|
10929
|
+
} catch {
|
|
10930
|
+
}
|
|
10963
10931
|
}
|
|
10932
|
+
return "";
|
|
10964
10933
|
}
|
|
10965
|
-
function
|
|
10966
|
-
const
|
|
10967
|
-
|
|
10934
|
+
function crewLayer(base, intel, bridge) {
|
|
10935
|
+
const files = { "credential-helper": CREDENTIAL_HELPER, "mcp.json": MCP_CONFIG, ...bridge ? { "intel-bridge": bridge } : {} };
|
|
10936
|
+
const env = Object.entries(CREW_ENV).map(([k, v]) => `${k}=${v}`).join(" ");
|
|
10937
|
+
const dockerfile = [
|
|
10938
|
+
`FROM ${base.tag}`,
|
|
10939
|
+
"USER root",
|
|
10940
|
+
`COPY ${CA_BUNDLE_FILE} /etc/ssl/certs/ca-certificates.crt`,
|
|
10941
|
+
run2(APT_HTTPS_COMMAND),
|
|
10942
|
+
run2(`apt-get update && apt-get install -y --no-install-recommends ca-certificates curl git${intel ? " python3 python3-venv nodejs" : ""} && rm -rf /var/lib/apt/lists/*`),
|
|
10943
|
+
`COPY credential-helper ${CREW_PREFIX}/bin/credential-helper`,
|
|
10944
|
+
`COPY mcp.json ${CREW_PREFIX}/mcp/mcp.json`,
|
|
10945
|
+
...bridge ? [`COPY intel-bridge ${SANDBOX_BRIDGE_PATH}`] : [],
|
|
10946
|
+
run2(claudeInstallCommand()),
|
|
10947
|
+
...intel ? [run2(`mkdir -p ${CREW_PREFIX}/cache && ${serenaInstallCommand()}`)] : [],
|
|
10948
|
+
run2(`chmod 0755 ${CREW_PREFIX}/bin/credential-helper && git config --system credential.helper ${CREW_PREFIX}/bin/credential-helper`),
|
|
10949
|
+
run2(`mkdir -p ${CREW_PREFIX}/cache ${CREW_PREFIX}/pnpm-store ${CREW_PREFIX}/pnpm /sandbox && chown -R ${SANDBOX_UID}:${SANDBOX_UID} ${CREW_PREFIX} /sandbox`),
|
|
10950
|
+
...intel ? [`ENV ${SERENA_LANGUAGE_SERVERS_ENV}=${SERENA_IMAGE_HOME}/language_servers UV_PYTHON_INSTALL_DIR=${CREW_PREFIX}/uv/python`] : [],
|
|
10951
|
+
`ENV ${env} PATH=${CREW_PREFIX}/pnpm:${CREW_PREFIX}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin`,
|
|
10952
|
+
`LABEL io.crew.sandbox.layer="crew" io.crew.sandbox.claude="${SANDBOX_CLAUDE_VERSION}"`,
|
|
10953
|
+
""
|
|
10954
|
+
].join("\n");
|
|
10955
|
+
return { name: "crew", tag: `crew-sandbox-crew:${hash({ base: base.tag, dockerfile, files })}`, dockerfile, files, caBundleFile: CA_BUNDLE_FILE };
|
|
10968
10956
|
}
|
|
10969
|
-
|
|
10970
|
-
|
|
10971
|
-
|
|
10972
|
-
|
|
10973
|
-
|
|
10974
|
-
|
|
10975
|
-
|
|
10976
|
-
|
|
10977
|
-
|
|
10978
|
-
|
|
10979
|
-
|
|
10980
|
-
const
|
|
10981
|
-
|
|
10982
|
-
|
|
10983
|
-
|
|
10984
|
-
...tier && TIERS.includes(tier) ? { tier } : {},
|
|
10985
|
-
...vendor ? { vendor } : {}
|
|
10986
|
-
};
|
|
10987
|
-
return Object.keys(persona).length > 0 ? persona : void 0;
|
|
10988
|
-
} catch {
|
|
10989
|
-
return void 0;
|
|
10957
|
+
var WARM_DIR = "/tmp/crew-warm";
|
|
10958
|
+
var WARM_MAX_BYTES = 64 * 1024 * 1024;
|
|
10959
|
+
var globToRegExp = (glob) => new RegExp(`^${glob.split("*").map((p) => p.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join("[^/]*")}$`);
|
|
10960
|
+
function readWarmFiles(dir, ref, patterns) {
|
|
10961
|
+
if (patterns.length === 0) return {};
|
|
10962
|
+
const git2 = (args) => execFileSync7("git", ["-C", dir, ...args], { encoding: "utf8", maxBuffer: WARM_MAX_BYTES, stdio: ["ignore", "pipe", "pipe"] });
|
|
10963
|
+
const all = git2(["ls-tree", "-r", "--name-only", ref]).split("\n").filter(Boolean);
|
|
10964
|
+
const res = patterns.map(globToRegExp);
|
|
10965
|
+
const out = {};
|
|
10966
|
+
let total = 0;
|
|
10967
|
+
for (const path of all.filter((f) => res.some((re) => re.test(f))).sort()) {
|
|
10968
|
+
const content = git2(["show", `${ref}:${path}`]);
|
|
10969
|
+
total += content.length;
|
|
10970
|
+
if (total > WARM_MAX_BYTES) throw new Error(`sandbox.warm files exceed ${WARM_MAX_BYTES} bytes`);
|
|
10971
|
+
out[path] = content;
|
|
10990
10972
|
}
|
|
10973
|
+
return out;
|
|
10991
10974
|
}
|
|
10992
|
-
|
|
10993
|
-
const
|
|
10994
|
-
|
|
10995
|
-
|
|
10996
|
-
|
|
10997
|
-
|
|
10998
|
-
|
|
10999
|
-
|
|
11000
|
-
|
|
11001
|
-
|
|
11002
|
-
|
|
11003
|
-
}
|
|
11004
|
-
|
|
11005
|
-
|
|
11006
|
-
|
|
11007
|
-
|
|
11008
|
-
|
|
11009
|
-
|
|
11010
|
-
|
|
11011
|
-
|
|
11012
|
-
|
|
10975
|
+
function repoLayer(repo, decl, crew, warm) {
|
|
10976
|
+
const env = Object.entries(CREW_ENV).map(([k, v]) => `${k}=${v}`).join(" ");
|
|
10977
|
+
const lines2 = [];
|
|
10978
|
+
if (decl.image) {
|
|
10979
|
+
lines2.push(
|
|
10980
|
+
`FROM ${crew.tag} AS crew`,
|
|
10981
|
+
`FROM ${decl.image}`,
|
|
10982
|
+
"USER root",
|
|
10983
|
+
`COPY --from=crew ${CREW_PREFIX} ${CREW_PREFIX}`,
|
|
10984
|
+
`ENV ${env} PATH=${CREW_PREFIX}/pnpm:${CREW_PREFIX}/bin:$PATH`
|
|
10985
|
+
);
|
|
10986
|
+
} else {
|
|
10987
|
+
lines2.push(`FROM ${crew.tag}`, "USER root");
|
|
10988
|
+
}
|
|
10989
|
+
if (decl.packages.length > 0) {
|
|
10990
|
+
lines2.push(run2(APT_HTTPS_COMMAND));
|
|
10991
|
+
lines2.push(run2(`apt-get update && apt-get install -y --no-install-recommends ${decl.packages.join(" ")} && rm -rf /var/lib/apt/lists/*`));
|
|
10992
|
+
}
|
|
10993
|
+
lines2.push(
|
|
10994
|
+
run2(`mkdir -p /sandbox && chown -R ${SANDBOX_UID}:${SANDBOX_UID} /sandbox ${CREW_PREFIX}`),
|
|
10995
|
+
`USER ${SANDBOX_UID}`,
|
|
10996
|
+
"WORKDIR /sandbox"
|
|
10997
|
+
);
|
|
10998
|
+
const files = {};
|
|
10999
|
+
const warming = Object.keys(warm).length > 0;
|
|
11000
|
+
if (warming) {
|
|
11001
|
+
for (const [path, content] of Object.entries(warm)) files[`warm/${path}`] = content;
|
|
11002
|
+
lines2.push(`COPY --chown=${SANDBOX_UID}:${SANDBOX_UID} warm/ ${WARM_DIR}/`, `WORKDIR ${WARM_DIR}`);
|
|
11013
11003
|
}
|
|
11004
|
+
for (const step of decl.setup) lines2.push(run2(step));
|
|
11005
|
+
if (warming && decl.intel) lines2.push(run2(serenaWarmCommand()));
|
|
11006
|
+
if (warming) lines2.push("WORKDIR /sandbox", run2(`rm -rf ${WARM_DIR}`));
|
|
11007
|
+
lines2.push(`LABEL io.crew.sandbox.layer="repo" io.crew.sandbox.repo=${JSON.stringify(repo)}`, "");
|
|
11008
|
+
const dockerfile = lines2.join("\n");
|
|
11009
|
+
return { name: "repo", tag: `crew-sandbox/${slug(repo)}:${hash({ crew: crew.tag, dockerfile, files })}`, dockerfile, files };
|
|
11014
11010
|
}
|
|
11015
|
-
function
|
|
11016
|
-
|
|
11011
|
+
function planSandbox(repo, decl, warm = {}, bridge) {
|
|
11012
|
+
const base = baseLayer();
|
|
11013
|
+
const crew = crewLayer(base, decl.intel, bridge);
|
|
11014
|
+
const layer = repoLayer(repo, decl, crew, warm);
|
|
11015
|
+
return { repo, tag: layer.tag, claude: SANDBOX_CLAUDE_VERSION, layers: [base, crew, layer] };
|
|
11017
11016
|
}
|
|
11018
|
-
|
|
11019
|
-
|
|
11017
|
+
var SHIP_SANDBOX_KEY = "@ship";
|
|
11018
|
+
var shipSandboxRef = () => ({ name: SHIP_SANDBOX_KEY, decl: { packages: [], setup: [] } });
|
|
11019
|
+
var sandboxStatePath = (stateDir) => join26(stateDir, "sandbox-images.json");
|
|
11020
|
+
function readSandboxState(stateDir) {
|
|
11020
11021
|
try {
|
|
11021
|
-
const
|
|
11022
|
-
|
|
11023
|
-
});
|
|
11024
|
-
if (!res.ok) return void 0;
|
|
11025
|
-
const me = await res.json();
|
|
11026
|
-
return typeof me.role === "string" ? me.role : void 0;
|
|
11022
|
+
const v = JSON.parse(readFileSync24(sandboxStatePath(stateDir), "utf8"));
|
|
11023
|
+
return v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
11027
11024
|
} catch {
|
|
11028
|
-
return
|
|
11025
|
+
return {};
|
|
11029
11026
|
}
|
|
11030
11027
|
}
|
|
11031
|
-
function
|
|
11032
|
-
|
|
11033
|
-
|
|
11034
|
-
|
|
11035
|
-
|
|
11028
|
+
function writeSandboxState(stateDir, state) {
|
|
11029
|
+
mkdirSync17(stateDir, { recursive: true });
|
|
11030
|
+
const file = sandboxStatePath(stateDir);
|
|
11031
|
+
writeFileSync18(`${file}.tmp`, `${JSON.stringify(state, null, 2)}
|
|
11032
|
+
`);
|
|
11033
|
+
renameSync3(`${file}.tmp`, file);
|
|
11036
11034
|
}
|
|
11037
|
-
function
|
|
11038
|
-
return
|
|
11035
|
+
function sandboxImageFor(state, repo) {
|
|
11036
|
+
return state[repo]?.tags[0]?.tag ?? null;
|
|
11039
11037
|
}
|
|
11040
|
-
function
|
|
11041
|
-
return
|
|
11038
|
+
function sandboxImageForRun(state, repo, declares) {
|
|
11039
|
+
return (declares && repo ? sandboxImageFor(state, repo) : null) ?? sandboxImageFor(state, SHIP_SANDBOX_KEY);
|
|
11042
11040
|
}
|
|
11043
|
-
function
|
|
11044
|
-
|
|
11041
|
+
function sandboxImageStatus(state, plan) {
|
|
11042
|
+
const s = state[plan.repo];
|
|
11043
|
+
const current = s?.tags[0];
|
|
11044
|
+
if (s?.failure && s.failure.tag === plan.tag) {
|
|
11045
|
+
return { status: "failed", detail: `last build of ${plan.tag} failed at ${s.failure.at}; log ${s.failure.logPath}${current ? `; running ${current.tag}` : ""}` };
|
|
11046
|
+
}
|
|
11047
|
+
if (!current) return { status: "missing", detail: `no image built yet (wants ${plan.tag}); run \`crew sandbox build\`` };
|
|
11048
|
+
if (current.tag !== plan.tag) return { status: "stale", detail: `running ${current.tag} (claude ${current.claude ?? "unknown"}), declaration now builds ${plan.tag} (claude ${plan.claude})` };
|
|
11049
|
+
return { status: "ok", detail: `${current.tag} built ${current.builtAt}, claude ${current.claude ?? "unknown"}` };
|
|
11045
11050
|
}
|
|
11046
|
-
var
|
|
11047
|
-
|
|
11048
|
-
|
|
11049
|
-
|
|
11050
|
-
|
|
11051
|
+
var spawnBuildRunner = (engine = "docker") => (args, logPath) => new Promise((resolve8) => {
|
|
11052
|
+
const child = spawn3(engine, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
11053
|
+
const chunks = [];
|
|
11054
|
+
child.stdout.on("data", (d) => chunks.push(d));
|
|
11055
|
+
child.stderr.on("data", (d) => chunks.push(d));
|
|
11056
|
+
const done = (code, extra = "") => {
|
|
11057
|
+
writeFileSync18(logPath, `$ ${engine} ${args.join(" ")}
|
|
11058
|
+
${Buffer.concat(chunks).toString("utf8")}${extra}`, { flag: "a" });
|
|
11059
|
+
resolve8(code);
|
|
11060
|
+
};
|
|
11061
|
+
child.on("error", (e) => done(127, `${e.message}
|
|
11062
|
+
`));
|
|
11063
|
+
child.on("close", (code) => done(code ?? 1));
|
|
11064
|
+
});
|
|
11065
|
+
var engineHasImage = (engine = "docker", exec = realExec) => (tag) => {
|
|
11066
|
+
try {
|
|
11067
|
+
exec(engine, ["image", "inspect", tag], { timeoutMs: 2e4 });
|
|
11068
|
+
return true;
|
|
11069
|
+
} catch {
|
|
11070
|
+
return false;
|
|
11051
11071
|
}
|
|
11052
|
-
|
|
11053
|
-
|
|
11054
|
-
baseUrl: `${route2.baseUrl}/api`,
|
|
11055
|
-
apiKey: resolveApiKey(route2),
|
|
11056
|
-
headers: { "User-Agent": opts.userAgent ?? "Mozilla/5.0 TablationCrewAgent/1.0" }
|
|
11057
|
-
});
|
|
11058
|
-
let agentsModel;
|
|
11072
|
+
};
|
|
11073
|
+
var engineRemoveImage = (engine = "docker", exec = realExec) => (tag) => {
|
|
11059
11074
|
try {
|
|
11060
|
-
|
|
11061
|
-
} catch
|
|
11062
|
-
if (e instanceof TablationApiError && e.status === 404) {
|
|
11063
|
-
throw new AgentsSyncError(
|
|
11064
|
-
`workspace ${workspaceId} has no Agents table yet \u2014 every workspace auto-provisions one (ISSUE-465); an older workspace may still need its one-time backfill`
|
|
11065
|
-
);
|
|
11066
|
-
}
|
|
11067
|
-
throw e;
|
|
11075
|
+
exec(engine, ["image", "rm", tag], { timeoutMs: 6e4 });
|
|
11076
|
+
} catch {
|
|
11068
11077
|
}
|
|
11069
|
-
|
|
11070
|
-
|
|
11071
|
-
|
|
11072
|
-
const
|
|
11073
|
-
|
|
11074
|
-
|
|
11075
|
-
|
|
11076
|
-
|
|
11077
|
-
|
|
11078
|
-
|
|
11079
|
-
|
|
11080
|
-
|
|
11078
|
+
};
|
|
11079
|
+
var sandboxLogDir = (stateDir) => join26(stateDir, "sandbox-logs");
|
|
11080
|
+
async function buildSandboxImage(plan, deps) {
|
|
11081
|
+
const now = deps.now ?? (() => /* @__PURE__ */ new Date());
|
|
11082
|
+
const state = readSandboxState(deps.stateDir);
|
|
11083
|
+
const entry = state[plan.repo] ?? { tags: [] };
|
|
11084
|
+
if (entry.tags[0]?.tag === plan.tag && deps.hasImage(plan.tag)) {
|
|
11085
|
+
return { kind: "reused", tag: plan.tag };
|
|
11086
|
+
}
|
|
11087
|
+
const logDir = sandboxLogDir(deps.stateDir);
|
|
11088
|
+
mkdirSync17(logDir, { recursive: true });
|
|
11089
|
+
const logPath = join26(logDir, `${slug(plan.repo)}-${now().toISOString().replace(/[:.]/g, "-")}.log`);
|
|
11090
|
+
const builtLayers = [];
|
|
11091
|
+
for (const layer of plan.layers) {
|
|
11092
|
+
if (deps.hasImage(layer.tag)) continue;
|
|
11093
|
+
const ctx = join26(tmpdir2(), `crew-sandbox-${hash([layer.tag, process.pid, Date.now()])}`);
|
|
11094
|
+
mkdirSync17(ctx, { recursive: true });
|
|
11095
|
+
try {
|
|
11096
|
+
writeFileSync18(join26(ctx, "Dockerfile"), layer.dockerfile);
|
|
11097
|
+
for (const [name, content] of Object.entries(layer.files)) {
|
|
11098
|
+
mkdirSync17(dirname13(join26(ctx, name)), { recursive: true });
|
|
11099
|
+
writeFileSync18(join26(ctx, name), content);
|
|
11081
11100
|
}
|
|
11082
|
-
|
|
11083
|
-
|
|
11084
|
-
|
|
11085
|
-
|
|
11086
|
-
|
|
11087
|
-
|
|
11088
|
-
if (opts.dryRun) {
|
|
11089
|
-
outcomes.push({ role, action: "created", agentId: "(dry run)" });
|
|
11090
|
-
continue;
|
|
11101
|
+
if (layer.caBundleFile) writeFileSync18(join26(ctx, layer.caBundleFile), (deps.caBundle ?? readHostCaBundle)());
|
|
11102
|
+
const code = await deps.run(["build", "--tag", layer.tag, "--file", join26(ctx, "Dockerfile"), ctx], logPath);
|
|
11103
|
+
if (code !== 0) {
|
|
11104
|
+
state[plan.repo] = { ...entry, failure: { tag: plan.tag, at: now().toISOString(), logPath } };
|
|
11105
|
+
writeSandboxState(deps.stateDir, state);
|
|
11106
|
+
return { kind: "failed", tag: plan.tag, logPath, layer: layer.name };
|
|
11091
11107
|
}
|
|
11092
|
-
|
|
11093
|
-
|
|
11094
|
-
|
|
11095
|
-
|
|
11108
|
+
builtLayers.push(layer.name);
|
|
11109
|
+
} finally {
|
|
11110
|
+
rmSync14(ctx, { recursive: true, force: true });
|
|
11111
|
+
}
|
|
11112
|
+
}
|
|
11113
|
+
const tags = [{ tag: plan.tag, builtAt: now().toISOString(), claude: plan.claude }, ...entry.tags.filter((t) => t.tag !== plan.tag)];
|
|
11114
|
+
const dropped = tags.slice(KEEP_TAGS);
|
|
11115
|
+
state[plan.repo] = { tags: tags.slice(0, KEEP_TAGS) };
|
|
11116
|
+
writeSandboxState(deps.stateDir, state);
|
|
11117
|
+
for (const t of dropped) deps.removeImage(t.tag);
|
|
11118
|
+
return { kind: "built", tag: plan.tag, builtLayers };
|
|
11119
|
+
}
|
|
11120
|
+
var sandboxFailedKey = (repo) => `sandbox_build_failed:${repo}`;
|
|
11121
|
+
function sandboxFailedItem(repo, tag, layer, logPath, nowIso = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
11122
|
+
return {
|
|
11123
|
+
kind: "sandbox_build_failed",
|
|
11124
|
+
key: sandboxFailedKey(repo),
|
|
11125
|
+
since: nowIso,
|
|
11126
|
+
message: `${repo}: sandbox image ${tag} failed to build at the ${layer} layer (log: ${logPath}); sandboxes keep running the previous image. Retries automatically after the declaration changes or in an hour; \`crew sandbox build\` forces it`
|
|
11127
|
+
};
|
|
11128
|
+
}
|
|
11129
|
+
async function sandboxBuildTick(repos, deps, force = false) {
|
|
11130
|
+
const nowMs = (deps.now ?? (() => /* @__PURE__ */ new Date()))().getTime();
|
|
11131
|
+
for (const r of repos) {
|
|
11132
|
+
const plan = planSandbox(r.name, r.decl, r.warm, r.bridge);
|
|
11133
|
+
const state = readSandboxState(deps.stateDir)[r.name];
|
|
11134
|
+
const upToDate = state?.tags[0]?.tag === plan.tag && deps.hasImage(plan.tag);
|
|
11135
|
+
if (upToDate) {
|
|
11136
|
+
deps.clear(sandboxFailedKey(r.name));
|
|
11096
11137
|
continue;
|
|
11097
11138
|
}
|
|
11098
|
-
if (
|
|
11099
|
-
|
|
11100
|
-
|
|
11101
|
-
|
|
11102
|
-
|
|
11103
|
-
|
|
11104
|
-
|
|
11105
|
-
|
|
11139
|
+
if (!force && state?.failure?.tag === plan.tag && nowMs - Date.parse(state.failure.at) < SANDBOX_RETRY_AFTER_MS) continue;
|
|
11140
|
+
deps.log(`sandbox image for ${r.name}: building ${plan.tag}`);
|
|
11141
|
+
const out = await buildSandboxImage(plan, deps);
|
|
11142
|
+
if (out.kind === "failed") {
|
|
11143
|
+
deps.raise(sandboxFailedItem(r.name, out.tag, out.layer, out.logPath));
|
|
11144
|
+
deps.log(`sandbox image for ${r.name}: build failed at the ${out.layer} layer, log ${out.logPath}`);
|
|
11145
|
+
} else {
|
|
11146
|
+
deps.clear(sandboxFailedKey(r.name));
|
|
11147
|
+
deps.log(`sandbox image for ${r.name}: ${out.kind === "built" ? `built ${out.tag}` : `${out.tag} already built`}`);
|
|
11148
|
+
}
|
|
11149
|
+
return r.name;
|
|
11150
|
+
}
|
|
11151
|
+
return null;
|
|
11152
|
+
}
|
|
11153
|
+
|
|
11154
|
+
// src/skill-include.ts
|
|
11155
|
+
var SkillIncludeError = class extends Error {
|
|
11156
|
+
};
|
|
11157
|
+
var MAX_INCLUDE_DEPTH = 3;
|
|
11158
|
+
var MAX_INCLUDED_BYTES = 2e5;
|
|
11159
|
+
var MARKER = /\{\{[ \t]*skill:[ \t]*([^{}\r\n]*?)[ \t]*\}\}/g;
|
|
11160
|
+
function skillMarkerNames(text2) {
|
|
11161
|
+
const names = [];
|
|
11162
|
+
for (const m of text2.matchAll(MARKER)) {
|
|
11163
|
+
const name = m[1].trim();
|
|
11164
|
+
if (name && !names.includes(name)) names.push(name);
|
|
11165
|
+
}
|
|
11166
|
+
return names;
|
|
11167
|
+
}
|
|
11168
|
+
function expandSkillMarkers(text2, lookup2, opts = {}) {
|
|
11169
|
+
const maxDepth = opts.maxDepth ?? MAX_INCLUDE_DEPTH;
|
|
11170
|
+
const maxBytes = opts.maxBytes ?? MAX_INCLUDED_BYTES;
|
|
11171
|
+
const warnings = [];
|
|
11172
|
+
let included = 0;
|
|
11173
|
+
const expand2 = (source, chain) => source.replace(MARKER, (literal, rawName) => {
|
|
11174
|
+
const name = rawName.trim();
|
|
11175
|
+
if (!name) return literal;
|
|
11176
|
+
if (chain.includes(name)) {
|
|
11177
|
+
warnings.push(`skill include "${name}" left literal: it includes itself (${[...chain, name].join(" \u2192 ")})`);
|
|
11178
|
+
return literal;
|
|
11179
|
+
}
|
|
11180
|
+
if (chain.length >= maxDepth) {
|
|
11181
|
+
warnings.push(`skill include "${name}" left literal: nested deeper than ${maxDepth} levels`);
|
|
11182
|
+
return literal;
|
|
11183
|
+
}
|
|
11184
|
+
const body = lookup2(name);
|
|
11185
|
+
if (body === void 0) throw new SkillIncludeError(`no skill named "${name}" for the include ${literal}`);
|
|
11186
|
+
const trimmed = body.replace(/^\n+/, "").replace(/\n+$/, "");
|
|
11187
|
+
const bytes = Buffer.byteLength(trimmed, "utf8");
|
|
11188
|
+
if (included + bytes > maxBytes) {
|
|
11189
|
+
warnings.push(`skill include "${name}" left literal: it would exceed the ${maxBytes}-byte include budget`);
|
|
11190
|
+
return literal;
|
|
11191
|
+
}
|
|
11192
|
+
included += bytes;
|
|
11193
|
+
return expand2(trimmed, [...chain, name]);
|
|
11194
|
+
});
|
|
11195
|
+
return { text: expand2(text2, []), warnings };
|
|
11196
|
+
}
|
|
11197
|
+
|
|
11198
|
+
// src/skills.ts
|
|
11199
|
+
import { readFileSync as readFileSync26, readdirSync as readdirSync8, existsSync as existsSync25 } from "fs";
|
|
11200
|
+
import { join as join28 } from "path";
|
|
11201
|
+
import { parse as parseYaml } from "yaml";
|
|
11202
|
+
import { TablationClient as TablationClient3, StaleWriteError as StaleWriteError3, TablationApiError as TablationApiError2 } from "@tablation/client";
|
|
11203
|
+
|
|
11204
|
+
// src/prompt-additions.ts
|
|
11205
|
+
var PROMPT_ADDITIONS_SEPARATOR = "---\n\nAdditional instructions from this workspace. Where they conflict with anything above, these take precedence.";
|
|
11206
|
+
function appendAdditions(text2, additions) {
|
|
11207
|
+
if (typeof additions !== "string" || additions.trim() === "") return text2;
|
|
11208
|
+
return `${text2}
|
|
11209
|
+
|
|
11210
|
+
${PROMPT_ADDITIONS_SEPARATOR}
|
|
11211
|
+
|
|
11212
|
+
${additions}`;
|
|
11213
|
+
}
|
|
11214
|
+
|
|
11215
|
+
// src/agents.ts
|
|
11216
|
+
import { readFileSync as readFileSync25, existsSync as existsSync24 } from "fs";
|
|
11217
|
+
import { join as join27 } from "path";
|
|
11218
|
+
import { TablationClient as TablationClient2, StaleWriteError as StaleWriteError2, TablationApiError } from "@tablation/client";
|
|
11219
|
+
var PERSONA_NAME = {
|
|
11220
|
+
dev: "Developer",
|
|
11221
|
+
design: "Design",
|
|
11222
|
+
qa: "QA",
|
|
11223
|
+
triage: "Triage",
|
|
11224
|
+
pair: "Pair"
|
|
11225
|
+
};
|
|
11226
|
+
var CREW_AGENT_FIELD_NAME = "Agent";
|
|
11227
|
+
var CREW_AGENT_COLUMN = "agent_id";
|
|
11228
|
+
var AgentsSyncError = class extends Error {
|
|
11229
|
+
};
|
|
11230
|
+
function personaDefaultPrompt(promptsDir, role) {
|
|
11231
|
+
const briefPath = join27(promptsDir, "personas", `lane-${role}.md`);
|
|
11232
|
+
if (!existsSync24(briefPath)) throw new AgentsSyncError(`no brief at ${briefPath}`);
|
|
11233
|
+
if (SELF_CONTAINED_ROLES.has(role)) return readFileSync25(briefPath, "utf8");
|
|
11234
|
+
const commonPath = join27(promptsDir, "personas", "common.md");
|
|
11235
|
+
if (!existsSync24(commonPath)) return readFileSync25(briefPath, "utf8");
|
|
11236
|
+
return `${readFileSync25(commonPath, "utf8")}${readFileSync25(briefPath, "utf8")}`;
|
|
11237
|
+
}
|
|
11238
|
+
async function resolveAgentId(route2, role, opts) {
|
|
11239
|
+
const cached = route2.resolved?.agentPersonas?.[role]?.agentId;
|
|
11240
|
+
if (cached) return cached;
|
|
11241
|
+
const seatId = route2.resolved?.seats?.[role];
|
|
11242
|
+
if (!seatId || !route2.resolved) return void 0;
|
|
11243
|
+
const client2 = new TablationClient2({
|
|
11244
|
+
baseUrl: `${route2.baseUrl}/api`,
|
|
11245
|
+
apiKey: resolveApiKey(route2),
|
|
11246
|
+
headers: { "User-Agent": opts.userAgent ?? "Mozilla/5.0 TablationCrewAgent/1.0" }
|
|
11247
|
+
});
|
|
11248
|
+
try {
|
|
11249
|
+
const row = await client2.records.get(route2.resolved.models.crew, seatId);
|
|
11250
|
+
return row.agent_id ?? void 0;
|
|
11251
|
+
} catch {
|
|
11252
|
+
return void 0;
|
|
11253
|
+
}
|
|
11254
|
+
}
|
|
11255
|
+
async function fetchPersonaPrompt(route2, role, opts) {
|
|
11256
|
+
const agentId = await resolveAgentId(route2, role, opts);
|
|
11257
|
+
if (!agentId || !route2.resolved) return {};
|
|
11258
|
+
const client2 = new TablationClient2({
|
|
11259
|
+
baseUrl: `${route2.baseUrl}/api`,
|
|
11260
|
+
apiKey: resolveApiKey(route2),
|
|
11261
|
+
headers: { "User-Agent": opts.userAgent ?? "Mozilla/5.0 TablationCrewAgent/1.0" }
|
|
11262
|
+
});
|
|
11263
|
+
let row;
|
|
11264
|
+
let agentsModelId;
|
|
11265
|
+
try {
|
|
11266
|
+
const agentsModel = await client2.dataModels.get("agents", route2.resolved.workspaceId);
|
|
11267
|
+
agentsModelId = agentsModel.id;
|
|
11268
|
+
row = await client2.records.get(agentsModelId, agentId);
|
|
11269
|
+
} catch {
|
|
11270
|
+
return {};
|
|
11271
|
+
}
|
|
11272
|
+
const additions = typeof row.prompt_additions === "string" && row.prompt_additions.trim() !== "" ? row.prompt_additions : void 0;
|
|
11273
|
+
const divergedPrompt = await divergedRowPrompt(route2, role, row, agentId, agentsModelId, opts);
|
|
11274
|
+
return { divergedPrompt, additions };
|
|
11275
|
+
}
|
|
11276
|
+
function personaPromptOptions(p) {
|
|
11277
|
+
return { divergedPrompt: p.divergedPrompt, personaAdditions: p.additions };
|
|
11278
|
+
}
|
|
11279
|
+
async function divergedRowPrompt(route2, role, row, agentId, agentsModelId, opts) {
|
|
11280
|
+
if (!route2.resolved) return void 0;
|
|
11281
|
+
const defaultPrompt = personaDefaultPrompt(route2.promptsDir, role);
|
|
11282
|
+
if (row.prompt === defaultPrompt) return void 0;
|
|
11283
|
+
const cached = route2.resolved.agentPersonas?.[role];
|
|
11284
|
+
if (cached?.agentId === agentId && cached.historyId) {
|
|
11285
|
+
const lastSynced = await fetchLastSyncedPrompt(route2, agentsModelId, agentId, cached.historyId, opts.userAgent);
|
|
11286
|
+
if (lastSynced !== void 0 && lastSynced === row.prompt) return void 0;
|
|
11287
|
+
}
|
|
11288
|
+
return row.prompt;
|
|
11289
|
+
}
|
|
11290
|
+
async function fetchLastSyncedPrompt(route2, agentsModelId, recordId, historyId, userAgent) {
|
|
11291
|
+
try {
|
|
11292
|
+
const entries = await fetchHistoryEntries(route2, agentsModelId, recordId, userAgent);
|
|
11293
|
+
return entries.find((e) => e.history_id === historyId)?.prompt;
|
|
11294
|
+
} catch {
|
|
11295
|
+
return void 0;
|
|
11296
|
+
}
|
|
11297
|
+
}
|
|
11298
|
+
function choiceValue(v) {
|
|
11299
|
+
const raw = typeof v === "string" ? v : v && typeof v === "object" ? v.value ?? v.key : void 0;
|
|
11300
|
+
return typeof raw === "string" && raw.trim() ? raw.trim().toLowerCase() : void 0;
|
|
11301
|
+
}
|
|
11302
|
+
async function fetchSeatPersona(route2, role, opts) {
|
|
11303
|
+
const agentId = await resolveAgentId(route2, role, opts);
|
|
11304
|
+
if (!agentId || !route2.resolved) return void 0;
|
|
11305
|
+
const client2 = new TablationClient2({
|
|
11306
|
+
baseUrl: `${route2.baseUrl}/api`,
|
|
11307
|
+
apiKey: resolveApiKey(route2),
|
|
11308
|
+
headers: { "User-Agent": opts.userAgent ?? "Mozilla/5.0 TablationCrewAgent/1.0" }
|
|
11309
|
+
});
|
|
11310
|
+
try {
|
|
11311
|
+
const agentsModel = await client2.dataModels.get("agents", route2.resolved.workspaceId);
|
|
11312
|
+
const row = await client2.records.get(agentsModel.id, agentId);
|
|
11313
|
+
const tier = choiceValue(row.tier);
|
|
11314
|
+
const vendor = choiceValue(row.vendor);
|
|
11315
|
+
const persona = {
|
|
11316
|
+
...row.model ? { model: row.model } : {},
|
|
11317
|
+
...tier && TIERS.includes(tier) ? { tier } : {},
|
|
11318
|
+
...vendor ? { vendor } : {}
|
|
11319
|
+
};
|
|
11320
|
+
return Object.keys(persona).length > 0 ? persona : void 0;
|
|
11321
|
+
} catch {
|
|
11322
|
+
return void 0;
|
|
11323
|
+
}
|
|
11324
|
+
}
|
|
11325
|
+
async function currentPersonaPrompt(route2, role, opts) {
|
|
11326
|
+
const { divergedPrompt, additions } = await fetchPersonaPrompt(route2, role, opts);
|
|
11327
|
+
return appendAdditions(divergedPrompt ?? personaDefaultPrompt(route2.promptsDir, role), additions);
|
|
11328
|
+
}
|
|
11329
|
+
async function fetchHistoryEntries(route2, agentsModelId, recordId, userAgent, limit = 50) {
|
|
11330
|
+
const url = `${route2.baseUrl.replace(/\/+$/, "")}/api/data-models/${agentsModelId}/records/${recordId}/history?limit=${limit}`;
|
|
11331
|
+
const res = await fetch(url, {
|
|
11332
|
+
headers: {
|
|
11333
|
+
Authorization: `Bearer ${resolveApiKey(route2)}`,
|
|
11334
|
+
"User-Agent": userAgent ?? "Mozilla/5.0 TablationCrewAgent/1.0"
|
|
11335
|
+
}
|
|
11336
|
+
});
|
|
11337
|
+
if (!res.ok) throw new AgentsSyncError(`history lookup for ${recordId}: ${res.status} ${res.statusText}`);
|
|
11338
|
+
return await res.json();
|
|
11339
|
+
}
|
|
11340
|
+
async function fetchLatestHistoryId(route2, agentsModelId, recordId, userAgent) {
|
|
11341
|
+
try {
|
|
11342
|
+
const entries = await fetchHistoryEntries(route2, agentsModelId, recordId, userAgent, 1);
|
|
11343
|
+
return entries[0]?.history_id;
|
|
11344
|
+
} catch {
|
|
11345
|
+
return void 0;
|
|
11346
|
+
}
|
|
11347
|
+
}
|
|
11348
|
+
function isAdminRole(role) {
|
|
11349
|
+
return role === void 0 || role === "WORKSPACE_ADMIN" || role === "PLATFORM_ADMIN";
|
|
11350
|
+
}
|
|
11351
|
+
async function fetchKeyRole(route2, userAgent) {
|
|
11352
|
+
if (!route2.resolved) return void 0;
|
|
11353
|
+
try {
|
|
11354
|
+
const res = await fetch(`${route2.baseUrl.replace(/\/+$/, "")}/api/auth/me?workspaceId=${route2.resolved.workspaceId}`, {
|
|
11355
|
+
headers: { Authorization: `Bearer ${resolveApiKey(route2)}`, "User-Agent": userAgent ?? "Mozilla/5.0 TablationCrewAgent/1.0" }
|
|
11356
|
+
});
|
|
11357
|
+
if (!res.ok) return void 0;
|
|
11358
|
+
const me = await res.json();
|
|
11359
|
+
return typeof me.role === "string" ? me.role : void 0;
|
|
11360
|
+
} catch {
|
|
11361
|
+
return void 0;
|
|
11362
|
+
}
|
|
11363
|
+
}
|
|
11364
|
+
function isForbidden(e) {
|
|
11365
|
+
return e instanceof TablationApiError && e.status === 403;
|
|
11366
|
+
}
|
|
11367
|
+
function promptSourceFields(model, prompt) {
|
|
11368
|
+
return model.fields?.some((f) => f.columnName === "prompt_baseline") ? { prompt_source: "crew", prompt_baseline: prompt } : {};
|
|
11369
|
+
}
|
|
11370
|
+
function hasPromptBaselineColumn(model) {
|
|
11371
|
+
return model.fields?.some((f) => f.columnName === "prompt_baseline") === true;
|
|
11372
|
+
}
|
|
11373
|
+
function needsBaselineBackfill(model, row) {
|
|
11374
|
+
return hasPromptBaselineColumn(model) && row.prompt_customized !== true && (typeof row.prompt_baseline !== "string" || !row.prompt_source);
|
|
11375
|
+
}
|
|
11376
|
+
function isPromptGateRejection(e) {
|
|
11377
|
+
return e instanceof TablationApiError && e.status === 422;
|
|
11378
|
+
}
|
|
11379
|
+
var RELEASE_AGENT_NAME = "Release agent";
|
|
11380
|
+
var RELEASE_AGENT_PROMPT = "Principal for the crew release phase (merge, deploy, release comments). It runs no model; this row only gives those tracker writes an agent identity.";
|
|
11381
|
+
async function syncPersonas(route2, opts) {
|
|
11382
|
+
if (!route2.resolved) {
|
|
11383
|
+
throw new AgentsSyncError(`route "${route2.route}" has no resolved ids \u2014 run \`crew connect\` first`);
|
|
11384
|
+
}
|
|
11385
|
+
const workspaceId = route2.resolved.workspaceId;
|
|
11386
|
+
const client2 = new TablationClient2({
|
|
11387
|
+
baseUrl: `${route2.baseUrl}/api`,
|
|
11388
|
+
apiKey: resolveApiKey(route2),
|
|
11389
|
+
headers: { "User-Agent": opts.userAgent ?? "Mozilla/5.0 TablationCrewAgent/1.0" }
|
|
11390
|
+
});
|
|
11391
|
+
let agentsModel;
|
|
11392
|
+
try {
|
|
11393
|
+
agentsModel = await client2.dataModels.get("agents", workspaceId);
|
|
11394
|
+
} catch (e) {
|
|
11395
|
+
if (e instanceof TablationApiError && e.status === 404) {
|
|
11396
|
+
throw new AgentsSyncError(
|
|
11397
|
+
`workspace ${workspaceId} has no Agents table yet \u2014 every workspace auto-provisions one (ISSUE-465); an older workspace may still need its one-time backfill`
|
|
11398
|
+
);
|
|
11399
|
+
}
|
|
11400
|
+
throw e;
|
|
11401
|
+
}
|
|
11402
|
+
const rows = await client2.records.list(agentsModel.id, { limit: 200 });
|
|
11403
|
+
const cache = route2.resolved.agentPersonas ?? {};
|
|
11404
|
+
const outcomes = [];
|
|
11405
|
+
const agentPersonas = { ...cache };
|
|
11406
|
+
for (const role of ROLE_NAMES) {
|
|
11407
|
+
const name = PERSONA_NAME[role];
|
|
11408
|
+
const defaultPrompt = personaDefaultPrompt(route2.promptsDir, role);
|
|
11409
|
+
const row = rows.find((r) => r.name === name);
|
|
11410
|
+
if (opts.readOnly) {
|
|
11411
|
+
if (!row) {
|
|
11412
|
+
outcomes.push({ role, action: "missing", agentId: "" });
|
|
11413
|
+
continue;
|
|
11414
|
+
}
|
|
11415
|
+
const prior = cache[role]?.agentId === row.id ? cache[role] : void 0;
|
|
11416
|
+
agentPersonas[role] = { agentId: row.id, lastSyncedUpdatedAt: prior?.lastSyncedUpdatedAt ?? row.updated_at, ...prior?.historyId ? { historyId: prior.historyId } : {} };
|
|
11417
|
+
outcomes.push({ role, action: "adopted", agentId: row.id });
|
|
11418
|
+
continue;
|
|
11419
|
+
}
|
|
11420
|
+
if (!row) {
|
|
11421
|
+
if (opts.dryRun) {
|
|
11422
|
+
outcomes.push({ role, action: "created", agentId: "(dry run)" });
|
|
11423
|
+
continue;
|
|
11424
|
+
}
|
|
11425
|
+
const created = await client2.records.create(agentsModel.id, { name, prompt: defaultPrompt, ...promptSourceFields(agentsModel, defaultPrompt) });
|
|
11426
|
+
const historyId = await fetchLatestHistoryId(route2, agentsModel.id, created.id, opts.userAgent);
|
|
11427
|
+
agentPersonas[role] = { agentId: created.id, lastSyncedUpdatedAt: created.updated_at, ...historyId ? { historyId } : {} };
|
|
11428
|
+
outcomes.push({ role, action: "created", agentId: created.id });
|
|
11429
|
+
continue;
|
|
11430
|
+
}
|
|
11431
|
+
if (row.prompt === defaultPrompt) {
|
|
11432
|
+
let anchoredAt = row.updated_at;
|
|
11433
|
+
if (!opts.dryRun && needsBaselineBackfill(agentsModel, row)) {
|
|
11434
|
+
try {
|
|
11435
|
+
anchoredAt = (await client2.records.update(agentsModel.id, row.id, promptSourceFields(agentsModel, defaultPrompt), row.updated_at)).updated_at;
|
|
11436
|
+
} catch (e) {
|
|
11437
|
+
if (!(e instanceof StaleWriteError2) && !isPromptGateRejection(e)) throw e;
|
|
11438
|
+
}
|
|
11106
11439
|
}
|
|
11107
11440
|
const historyId = await fetchLatestHistoryId(route2, agentsModel.id, row.id, opts.userAgent);
|
|
11108
11441
|
agentPersonas[role] = { agentId: row.id, lastSyncedUpdatedAt: anchoredAt, ...historyId ? { historyId } : {} };
|
|
@@ -11347,7 +11680,7 @@ function describeCrewLink(o) {
|
|
|
11347
11680
|
var SkillSyncError = class extends Error {
|
|
11348
11681
|
};
|
|
11349
11682
|
function parseSkillFile(path) {
|
|
11350
|
-
const text2 =
|
|
11683
|
+
const text2 = readFileSync26(path, "utf8");
|
|
11351
11684
|
const match = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/.exec(text2);
|
|
11352
11685
|
if (!match) throw new SkillSyncError(`${path}: missing YAML frontmatter (expected a leading --- block)`);
|
|
11353
11686
|
const frontmatter = match[1];
|
|
@@ -11360,9 +11693,9 @@ function parseSkillFile(path) {
|
|
|
11360
11693
|
return { name: meta.name, description: meta.description, prompt: body, file: path };
|
|
11361
11694
|
}
|
|
11362
11695
|
function listLocalSkills(promptsDir) {
|
|
11363
|
-
const dir =
|
|
11364
|
-
if (!
|
|
11365
|
-
return readdirSync8(dir).filter((f) => f.endsWith(".md")).map((f) => parseSkillFile(
|
|
11696
|
+
const dir = join28(promptsDir, "skills");
|
|
11697
|
+
if (!existsSync25(dir)) return [];
|
|
11698
|
+
return readdirSync8(dir).filter((f) => f.endsWith(".md")).map((f) => parseSkillFile(join28(dir, f)));
|
|
11366
11699
|
}
|
|
11367
11700
|
async function syncSkills(route2, opts) {
|
|
11368
11701
|
if (!route2.resolved) {
|
|
@@ -11546,11 +11879,11 @@ function skillMarkerWarnings(promptsDir, personaPrompts) {
|
|
|
11546
11879
|
}
|
|
11547
11880
|
|
|
11548
11881
|
// src/runner.ts
|
|
11549
|
-
import { spawn as
|
|
11550
|
-
import { mkdtempSync, mkdirSync as
|
|
11551
|
-
import { createHash as
|
|
11552
|
-
import { tmpdir as
|
|
11553
|
-
import { basename as basename8, dirname as
|
|
11882
|
+
import { spawn as spawn4, execFile, execFileSync as execFileSync8 } from "child_process";
|
|
11883
|
+
import { mkdtempSync, mkdirSync as mkdirSync18, writeFileSync as writeFileSync19, rmSync as rmSync15 } from "fs";
|
|
11884
|
+
import { createHash as createHash5 } from "crypto";
|
|
11885
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
11886
|
+
import { basename as basename8, dirname as dirname14, join as join29 } from "path";
|
|
11554
11887
|
import { promisify } from "util";
|
|
11555
11888
|
|
|
11556
11889
|
// src/run-limit.ts
|
|
@@ -11614,7 +11947,7 @@ var SANDBOX_PROMPT_PATH = "/sandbox/prompt.txt";
|
|
|
11614
11947
|
var HostRunner = class {
|
|
11615
11948
|
kind = "host";
|
|
11616
11949
|
start(plan, o) {
|
|
11617
|
-
const child =
|
|
11950
|
+
const child = spawn4(plan.bin, plan.args, {
|
|
11618
11951
|
cwd: plan.cwd,
|
|
11619
11952
|
env: o.env,
|
|
11620
11953
|
stdio: ["pipe", o.streamFd, "inherit"],
|
|
@@ -11644,7 +11977,7 @@ function shQuote2(s) {
|
|
|
11644
11977
|
return `'${s.replace(/'/g, `'\\''`)}'`;
|
|
11645
11978
|
}
|
|
11646
11979
|
function sandboxName(plan, now = Date.now()) {
|
|
11647
|
-
const h =
|
|
11980
|
+
const h = createHash5("sha256").update([plan.route, plan.role, plan.ticket ?? ""].join("\0")).digest();
|
|
11648
11981
|
const tag = (h.readUInt32BE(0) % 36 ** 6).toString(36).padStart(6, "0");
|
|
11649
11982
|
return `crew-${tag}${now.toString(36).slice(-8).padStart(8, "0")}`;
|
|
11650
11983
|
}
|
|
@@ -11685,8 +12018,8 @@ var SandboxRunner = class {
|
|
|
11685
12018
|
throw new Error(`cannot generate the sandbox policy: ${e.message}`);
|
|
11686
12019
|
}
|
|
11687
12020
|
policyFile = policyPathFor(plan.streamPath);
|
|
11688
|
-
|
|
11689
|
-
|
|
12021
|
+
mkdirSync18(dirname14(policyFile), { recursive: true });
|
|
12022
|
+
writeFileSync19(policyFile, generated.yaml, { mode: 384 });
|
|
11690
12023
|
}
|
|
11691
12024
|
const create2 = ["sandbox", "create", "--name", name, "--detach"];
|
|
11692
12025
|
if (policyFile) create2.push("--policy", policyFile);
|
|
@@ -11733,18 +12066,18 @@ var SandboxRunner = class {
|
|
|
11733
12066
|
const harness = cfg.agentBin ?? basename8(plan.bin);
|
|
11734
12067
|
const viaUpload = Buffer.byteLength(plan.prompt) > SANDBOX_STDIN_LIMIT;
|
|
11735
12068
|
if (viaUpload) {
|
|
11736
|
-
const tmp = mkdtempSync(
|
|
12069
|
+
const tmp = mkdtempSync(join29(tmpdir3(), "crew-prompt-"));
|
|
11737
12070
|
try {
|
|
11738
|
-
const file =
|
|
11739
|
-
|
|
12071
|
+
const file = join29(tmp, "prompt.txt");
|
|
12072
|
+
writeFileSync19(file, plan.prompt, { mode: 384 });
|
|
11740
12073
|
await this.os(["sandbox", "upload", name, file, SANDBOX_PROMPT_PATH]);
|
|
11741
12074
|
} finally {
|
|
11742
|
-
|
|
12075
|
+
rmSync15(tmp, { recursive: true, force: true });
|
|
11743
12076
|
}
|
|
11744
12077
|
}
|
|
11745
12078
|
const withStubs = `${sandboxEnvExports()}PATH=${shQuote2(SANDBOX_STUB_DIR)}:"$PATH"; export PATH; `;
|
|
11746
12079
|
const command2 = viaUpload ? ["sh", "-c", `${withStubs}exec ${[harness, ...plan.args].map(shQuote2).join(" ")} < ${SANDBOX_PROMPT_PATH}`] : ["sh", "-c", `${withStubs}exec "$@"`, "sh", harness, ...plan.args];
|
|
11747
|
-
const child =
|
|
12080
|
+
const child = spawn4(cfg.bin, ["sandbox", "exec", "-n", name, "--no-login-shell", "--workdir", cfg.workDir, "--", ...command2], {
|
|
11748
12081
|
env: process.env,
|
|
11749
12082
|
stdio: ["pipe", o.streamFd, "inherit"],
|
|
11750
12083
|
detached: true
|
|
@@ -11799,7 +12132,7 @@ var SandboxRunner = class {
|
|
|
11799
12132
|
var describeExecError = describe;
|
|
11800
12133
|
function gitOrigin(cwd) {
|
|
11801
12134
|
try {
|
|
11802
|
-
return
|
|
12135
|
+
return execFileSync8("git", ["-C", cwd, "remote", "get-url", "origin"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
11803
12136
|
} catch {
|
|
11804
12137
|
return null;
|
|
11805
12138
|
}
|
|
@@ -11811,7 +12144,7 @@ function runnerOfSidecar(sc) {
|
|
|
11811
12144
|
return sc.runner === "sandbox" ? new SandboxRunner(sc.sandboxBin ? { bin: sc.sandboxBin } : {}) : new HostRunner();
|
|
11812
12145
|
}
|
|
11813
12146
|
var PROBE_CREATE_TIMEOUT_MS = 12e4;
|
|
11814
|
-
function checkSandboxRunner(cfg = {}, run3 = (b, a, t) =>
|
|
12147
|
+
function checkSandboxRunner(cfg = {}, run3 = (b, a, t) => execFileSync8(b, a, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: t ?? 15e3 })) {
|
|
11815
12148
|
const bin = cfg.bin ?? DEFAULT_SANDBOX_CONFIG.bin;
|
|
11816
12149
|
let version;
|
|
11817
12150
|
try {
|
|
@@ -11927,7 +12260,7 @@ var ALLOWANCE_REFUSAL_MARKER = "AI_ALLOWANCE_EXCEEDED";
|
|
|
11927
12260
|
function streamShowsAllowanceRefusal(streamPath) {
|
|
11928
12261
|
let raw;
|
|
11929
12262
|
try {
|
|
11930
|
-
raw =
|
|
12263
|
+
raw = readFileSync27(streamPath, "utf8");
|
|
11931
12264
|
} catch {
|
|
11932
12265
|
return false;
|
|
11933
12266
|
}
|
|
@@ -11950,7 +12283,7 @@ function streamShowsAllowanceRefusal(streamPath) {
|
|
|
11950
12283
|
}
|
|
11951
12284
|
return false;
|
|
11952
12285
|
}
|
|
11953
|
-
var digestPathFor = (stateDir, routeLabel, role, runId) =>
|
|
12286
|
+
var digestPathFor = (stateDir, routeLabel, role, runId) => join30(stateDir, `digest-${routeLabel}-${role}${runId ? `-${runId}` : ""}.md`);
|
|
11954
12287
|
function codeBridgeFor(o, harness) {
|
|
11955
12288
|
if (!o.ticket) return void 0;
|
|
11956
12289
|
const number = /(\d+)$/.exec(o.ticket)?.[1];
|
|
@@ -11977,7 +12310,7 @@ function codeBridgeFor(o, harness) {
|
|
|
11977
12310
|
"--clone",
|
|
11978
12311
|
o.ship.sandbox?.workDir ?? DEFAULT_SANDBOX_WORKDIR,
|
|
11979
12312
|
"--state-dir",
|
|
11980
|
-
|
|
12313
|
+
dirname15(SANDBOX_INTEL_DIR),
|
|
11981
12314
|
"--ticket",
|
|
11982
12315
|
number,
|
|
11983
12316
|
...seed ? ["--seed-cache", seed] : []
|
|
@@ -11990,33 +12323,33 @@ function codeBridgeFor(o, harness) {
|
|
|
11990
12323
|
bridge.settingsFile = `${SANDBOX_INTEL_DIR}/gemini-settings.json`;
|
|
11991
12324
|
bridge.files = [{ path: bridge.settingsFile, content: text2 }];
|
|
11992
12325
|
} else {
|
|
11993
|
-
const file =
|
|
11994
|
-
|
|
11995
|
-
|
|
12326
|
+
const file = join30(intelDir(o.stateDir, o.route.route, number), "gemini-settings.json");
|
|
12327
|
+
mkdirSync19(dirname15(file), { recursive: true });
|
|
12328
|
+
writeFileSync20(file, text2);
|
|
11996
12329
|
bridge.settingsFile = file;
|
|
11997
12330
|
}
|
|
11998
12331
|
}
|
|
11999
12332
|
return bridge;
|
|
12000
12333
|
}
|
|
12001
12334
|
function planAgentRun(o) {
|
|
12002
|
-
const briefPath =
|
|
12003
|
-
if (!
|
|
12335
|
+
const briefPath = join30(o.route.promptsDir, "personas", `lane-${o.role}.md`);
|
|
12336
|
+
if (!existsSync26(briefPath)) {
|
|
12004
12337
|
throw new AgentError(`no brief at ${briefPath} \u2014 refusing to run an unscoped session`);
|
|
12005
12338
|
}
|
|
12006
|
-
const commonPath =
|
|
12007
|
-
const usesCommon = !SELF_CONTAINED_ROLES.has(o.role) &&
|
|
12339
|
+
const commonPath = join30(o.route.promptsDir, "personas", "common.md");
|
|
12340
|
+
const usesCommon = !SELF_CONTAINED_ROLES.has(o.role) && existsSync26(commonPath);
|
|
12008
12341
|
const now = o.now ?? (() => Date.now());
|
|
12009
12342
|
const routeLabel = routeSlug(o.route.route);
|
|
12010
12343
|
const ownDigest = o.runId ? digestPathFor(o.stateDir, routeLabel, o.role, o.runId) : void 0;
|
|
12011
|
-
const digestPath2 = ownDigest &&
|
|
12344
|
+
const digestPath2 = ownDigest && existsSync26(ownDigest) ? ownDigest : digestPathFor(o.stateDir, routeLabel, o.role);
|
|
12012
12345
|
let digest;
|
|
12013
12346
|
let ageSeconds;
|
|
12014
|
-
if (
|
|
12347
|
+
if (existsSync26(digestPath2)) {
|
|
12015
12348
|
ageSeconds = Math.floor((now() - statSync8(digestPath2).mtimeMs) / 1e3);
|
|
12016
|
-
if (ageSeconds <= DIGEST_MAX_AGE_SECONDS) digest =
|
|
12349
|
+
if (ageSeconds <= DIGEST_MAX_AGE_SECONDS) digest = readFileSync27(digestPath2, "utf8");
|
|
12017
12350
|
}
|
|
12018
|
-
const common = usesCommon ?
|
|
12019
|
-
const brief =
|
|
12351
|
+
const common = usesCommon ? readFileSync27(commonPath, "utf8") : "";
|
|
12352
|
+
const brief = readFileSync27(briefPath, "utf8");
|
|
12020
12353
|
const effectiveCommon = o.divergedPrompt ? "" : common;
|
|
12021
12354
|
const effectiveBrief = appendAdditions(o.divergedPrompt ?? brief, o.personaAdditions);
|
|
12022
12355
|
const localSkills = new Map(listLocalSkills(o.route.promptsDir).map((s) => [s.name, s.prompt]));
|
|
@@ -12038,8 +12371,8 @@ function planAgentRun(o) {
|
|
|
12038
12371
|
brief: expanded.text,
|
|
12039
12372
|
digest
|
|
12040
12373
|
});
|
|
12041
|
-
const promptSha =
|
|
12042
|
-
const streamsDir =
|
|
12374
|
+
const promptSha = createHash6("sha256").update(expanded.text).digest("hex");
|
|
12375
|
+
const streamsDir = join30(o.stateDir, "streams");
|
|
12043
12376
|
const base = `${routeLabel}-${o.role}-${o.cycle}${o.runId ? `-${o.runId}` : ""}`;
|
|
12044
12377
|
const seat = resolveSeat(o.ship, o.route, o.role, o.agentPersona ?? (o.agentModel ? { model: o.agentModel } : {}), o.repo);
|
|
12045
12378
|
const { model } = seat;
|
|
@@ -12142,8 +12475,8 @@ function planAgentRun(o) {
|
|
|
12142
12475
|
digestAttached: digest !== void 0,
|
|
12143
12476
|
digestAgeSeconds: ageSeconds,
|
|
12144
12477
|
model,
|
|
12145
|
-
streamPath:
|
|
12146
|
-
eventsPath:
|
|
12478
|
+
streamPath: join30(streamsDir, `${base}.jsonl`),
|
|
12479
|
+
eventsPath: join30(streamsDir, `${base}.events.jsonl`),
|
|
12147
12480
|
ticket: o.ticket,
|
|
12148
12481
|
ticketRecordId: o.ticketRecordId ?? null,
|
|
12149
12482
|
repo: o.repo ?? null,
|
|
@@ -12175,7 +12508,7 @@ function describePlan(p) {
|
|
|
12175
12508
|
var pidPathFor = (streamPath) => `${streamPath}.pid`;
|
|
12176
12509
|
function readRunSidecar(streamPath) {
|
|
12177
12510
|
try {
|
|
12178
|
-
const sc = JSON.parse(
|
|
12511
|
+
const sc = JSON.parse(readFileSync27(pidPathFor(streamPath), "utf8"));
|
|
12179
12512
|
return typeof sc.pid === "number" && typeof sc.spawnedAt === "string" && typeof sc.role === "string" ? sc : null;
|
|
12180
12513
|
} catch {
|
|
12181
12514
|
return null;
|
|
@@ -12223,7 +12556,7 @@ async function killForDeadline(kill, pid, emit, role, ticket, spawnedAt, limitMi
|
|
|
12223
12556
|
var withoutKey = ({ apiKey: _apiKey, ...rest }) => rest;
|
|
12224
12557
|
function openSink(path) {
|
|
12225
12558
|
try {
|
|
12226
|
-
|
|
12559
|
+
mkdirSync19(dirname15(path), { recursive: true });
|
|
12227
12560
|
return createWriteStream(path, { flags: "a" });
|
|
12228
12561
|
} catch {
|
|
12229
12562
|
return void 0;
|
|
@@ -12409,7 +12742,7 @@ var RunObserver = class {
|
|
|
12409
12742
|
};
|
|
12410
12743
|
function writeRunMeta(id, startedAt, liveTicket, extra) {
|
|
12411
12744
|
try {
|
|
12412
|
-
|
|
12745
|
+
writeFileSync20(`${id.streamPath}.meta.json`, JSON.stringify({
|
|
12413
12746
|
route: id.route,
|
|
12414
12747
|
role: id.role,
|
|
12415
12748
|
hint: id.ticket,
|
|
@@ -12600,7 +12933,7 @@ function spawnAgent(plan, emit, hintMoved) {
|
|
|
12600
12933
|
const id = identityOf(plan, adapter.harness);
|
|
12601
12934
|
let streamFd;
|
|
12602
12935
|
try {
|
|
12603
|
-
|
|
12936
|
+
mkdirSync19(dirname15(plan.streamPath), { recursive: true });
|
|
12604
12937
|
streamFd = openSync4(plan.streamPath, "a");
|
|
12605
12938
|
} catch (e) {
|
|
12606
12939
|
void endSink(eventsSink);
|
|
@@ -12659,7 +12992,7 @@ function spawnAgent(plan, emit, hintMoved) {
|
|
|
12659
12992
|
...plan.workspaceRunId ? { workspaceRunId: plan.workspaceRunId } : {}
|
|
12660
12993
|
};
|
|
12661
12994
|
try {
|
|
12662
|
-
|
|
12995
|
+
writeFileSync20(pidPathFor(plan.streamPath), JSON.stringify(sidecar));
|
|
12663
12996
|
} catch {
|
|
12664
12997
|
}
|
|
12665
12998
|
}
|
|
@@ -12773,21 +13106,21 @@ var pidAlive = (pid) => {
|
|
|
12773
13106
|
};
|
|
12774
13107
|
function runFinished(streamPath) {
|
|
12775
13108
|
const path = `${streamPath}.meta.json`;
|
|
12776
|
-
if (!
|
|
13109
|
+
if (!existsSync27(path)) return false;
|
|
12777
13110
|
try {
|
|
12778
|
-
return JSON.parse(
|
|
13111
|
+
return JSON.parse(readFileSync28(path, "utf8")).running !== true;
|
|
12779
13112
|
} catch {
|
|
12780
13113
|
return true;
|
|
12781
13114
|
}
|
|
12782
13115
|
}
|
|
12783
13116
|
function orphanedStreams(o) {
|
|
12784
|
-
const dir =
|
|
12785
|
-
if (!
|
|
13117
|
+
const dir = join31(o.stateDir, "streams");
|
|
13118
|
+
if (!existsSync27(dir)) return [];
|
|
12786
13119
|
const ownerAlive = o.isOwnerAlive ?? pidAlive;
|
|
12787
13120
|
const out = [];
|
|
12788
13121
|
for (const name of readdirSync9(dir)) {
|
|
12789
13122
|
if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
|
|
12790
|
-
const streamPath =
|
|
13123
|
+
const streamPath = join31(dir, name);
|
|
12791
13124
|
if (runFinished(streamPath)) continue;
|
|
12792
13125
|
const sidecar = readRunSidecar(streamPath);
|
|
12793
13126
|
if (!sidecar || sidecar.route !== o.routeLabel) continue;
|
|
@@ -12840,15 +13173,15 @@ async function reconcileRuns(o) {
|
|
|
12840
13173
|
}
|
|
12841
13174
|
|
|
12842
13175
|
// src/live-runs.ts
|
|
12843
|
-
import { existsSync as
|
|
12844
|
-
import { join as
|
|
13176
|
+
import { existsSync as existsSync28, readdirSync as readdirSync10, statSync as statSync9 } from "fs";
|
|
13177
|
+
import { join as join32 } from "path";
|
|
12845
13178
|
function liveRuns(stateDir, isAlive = runIsAlive) {
|
|
12846
|
-
const dir =
|
|
12847
|
-
if (!
|
|
13179
|
+
const dir = join32(stateDir, "streams");
|
|
13180
|
+
if (!existsSync28(dir)) return [];
|
|
12848
13181
|
const out = [];
|
|
12849
13182
|
for (const name of readdirSync10(dir)) {
|
|
12850
13183
|
if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
|
|
12851
|
-
const streamPath =
|
|
13184
|
+
const streamPath = join32(dir, name);
|
|
12852
13185
|
if (runFinished(streamPath)) continue;
|
|
12853
13186
|
const sidecar = readRunSidecar(streamPath);
|
|
12854
13187
|
if (!sidecar || !isAlive(sidecar)) continue;
|
|
@@ -12858,12 +13191,12 @@ function liveRuns(stateDir, isAlive = runIsAlive) {
|
|
|
12858
13191
|
}
|
|
12859
13192
|
function runActivity(stateDir, isAlive = runIsAlive) {
|
|
12860
13193
|
const activeRuns = liveRuns(stateDir, isAlive).length;
|
|
12861
|
-
const dir =
|
|
13194
|
+
const dir = join32(stateDir, "streams");
|
|
12862
13195
|
let newest = 0;
|
|
12863
|
-
if (
|
|
13196
|
+
if (existsSync28(dir)) {
|
|
12864
13197
|
for (const name of readdirSync10(dir)) {
|
|
12865
13198
|
if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
|
|
12866
|
-
const streamPath =
|
|
13199
|
+
const streamPath = join32(dir, name);
|
|
12867
13200
|
if (!runFinished(streamPath)) continue;
|
|
12868
13201
|
try {
|
|
12869
13202
|
newest = Math.max(newest, statSync9(`${streamPath}.meta.json`).mtimeMs);
|
|
@@ -12958,7 +13291,7 @@ function realDeprovisionDeps(cfg, emit, crewHome, getStore) {
|
|
|
12958
13291
|
if (host === "windows") return [];
|
|
12959
13292
|
const ctx = installContext();
|
|
12960
13293
|
const systemd = detectSystemd();
|
|
12961
|
-
return ["run", "release", "passengers"].flatMap((job) => planInstall(cfg.ship, crewHome, host, systemd, job, ctx).unitPaths).filter((p) =>
|
|
13294
|
+
return ["run", "release", "passengers"].flatMap((job) => planInstall(cfg.ship, crewHome, host, systemd, job, ctx).unitPaths).filter((p) => existsSync29(p));
|
|
12962
13295
|
};
|
|
12963
13296
|
return {
|
|
12964
13297
|
liveRuns: () => liveRuns(stateDir).map((r) => ({ role: r.role, route: r.route, pid: r.pid, ticketRecordId: r.ticketRecordId ?? void 0, streamPath: r.streamPath })),
|
|
@@ -13019,7 +13352,7 @@ function realDeprovisionDeps(cfg, emit, crewHome, getStore) {
|
|
|
13019
13352
|
},
|
|
13020
13353
|
remaining() {
|
|
13021
13354
|
const left = [];
|
|
13022
|
-
if (
|
|
13355
|
+
if (existsSync29(cfg.configFile)) left.push(`config ${cfg.configFile}`);
|
|
13023
13356
|
for (const h of forgeHosts()) if (hasForgeToken(cfg.ship.forges, h, stateDir)) left.push(`forge token for ${h}`);
|
|
13024
13357
|
try {
|
|
13025
13358
|
for (const k of readdirSync11(keysDir(stateDir))) left.push(`seat key ${k}`);
|
|
@@ -13042,7 +13375,7 @@ function realDeprovisionDeps(cfg, emit, crewHome, getStore) {
|
|
|
13042
13375
|
|
|
13043
13376
|
// src/sandbox-cache.ts
|
|
13044
13377
|
var execFileP2 = promisify2(execFile2);
|
|
13045
|
-
var
|
|
13378
|
+
var realExec2 = (bin, args, o) => execFileP2(bin, args, { env: o?.env ?? process.env, maxBuffer: 16 * 1024 * 1024 });
|
|
13046
13379
|
var OPENSHELL_ATTACHABLE_LABEL = "openshell.ai/sandbox-attachable=true";
|
|
13047
13380
|
var OPENSHELL_WORKSPACE_LABEL = "openshell.ai/sandbox-attachable-workspace";
|
|
13048
13381
|
var VOLUME_ROOT = "/cache";
|
|
@@ -13178,7 +13511,7 @@ git -C "$m" show "refs/heads/$base:$path"
|
|
|
13178
13511
|
var SandboxCache = class {
|
|
13179
13512
|
s;
|
|
13180
13513
|
exec;
|
|
13181
|
-
constructor(s, exec =
|
|
13514
|
+
constructor(s, exec = realExec2) {
|
|
13182
13515
|
this.s = s;
|
|
13183
13516
|
this.exec = exec;
|
|
13184
13517
|
}
|
|
@@ -13201,712 +13534,419 @@ var SandboxCache = class {
|
|
|
13201
13534
|
`${OPENSHELL_WORKSPACE_LABEL}=${this.s.workspace}`,
|
|
13202
13535
|
"--label",
|
|
13203
13536
|
DOCKER_LABEL_OWNER,
|
|
13204
|
-
"--label",
|
|
13205
|
-
DOCKER_LABEL_CACHE,
|
|
13206
|
-
this.s.volume
|
|
13207
|
-
]);
|
|
13208
|
-
return true;
|
|
13209
|
-
}
|
|
13210
|
-
/** The workspace label the existing volume carries, or null when the volume is absent or unlabeled. A volume's labels cannot be changed in place. */
|
|
13211
|
-
async volumeWorkspace() {
|
|
13212
|
-
try {
|
|
13213
|
-
const { stdout } = await this.engine(["volume", "inspect", "--format", `{{index .Labels "${OPENSHELL_WORKSPACE_LABEL}"}}`, this.s.volume]);
|
|
13214
|
-
const v = stdout.trim();
|
|
13215
|
-
return v && v !== "<no value>" ? v : null;
|
|
13216
|
-
} catch {
|
|
13217
|
-
return null;
|
|
13218
|
-
}
|
|
13219
|
-
}
|
|
13220
|
-
helper(image, script, args, env = {}, extra = []) {
|
|
13221
|
-
const flags = Object.keys(env).flatMap((k) => ["-e", k]);
|
|
13222
|
-
return this.engine(["run", "--rm", "--label", DOCKER_LABEL_OWNER, "-v", `${this.s.volume}:${VOLUME_ROOT}`, ...extra, ...flags, "--entrypoint", "sh", image, "-c", script, "sh", ...args], { ...process.env, ...env });
|
|
13223
|
-
}
|
|
13224
|
-
/**
|
|
13225
|
-
* Refreshes every mirror (and, where configured, its dependency tree). One
|
|
13226
|
-
* repository failing does not stop the others; the caller raises attention
|
|
13227
|
-
* for the failures and the runs keep using the previous mirror state.
|
|
13228
|
-
*/
|
|
13229
|
-
async refresh(repos) {
|
|
13230
|
-
await this.ensureVolume();
|
|
13231
|
-
const out = [];
|
|
13232
|
-
for (const r of repos) {
|
|
13233
|
-
const env = r.token ? { CREW_FORGE_TOKEN: r.token, CREW_FORGE_USER: r.username ?? DEFAULT_FORGE_USERNAME } : {};
|
|
13234
|
-
try {
|
|
13235
|
-
await this.helper(this.s.helperImage, REFRESH_SCRIPT, [mirrorRelPath(r), forgeDescriptorFor(r.host).httpsUrl(r.host, r.path)], env);
|
|
13236
|
-
} catch (e) {
|
|
13237
|
-
out.push({ repo: r, ok: false, detail: r.token ? describe(e) : `no readable forge token for ${r.host} (see \`crew forge list\`); ${describe(e)}` });
|
|
13238
|
-
continue;
|
|
13239
|
-
}
|
|
13240
|
-
if (this.s.depsCommand && this.s.depsImage) {
|
|
13241
|
-
try {
|
|
13242
|
-
await this.helper(this.s.depsImage, DEPS_SCRIPT, [mirrorRelPath(r), depsRelDir(r), this.s.depsLockfile], { CREW_DEPS_COMMAND: this.s.depsCommand });
|
|
13243
|
-
} catch (e) {
|
|
13244
|
-
out.push({ repo: r, ok: false, detail: `dependency tree: ${describe(e)}` });
|
|
13245
|
-
continue;
|
|
13246
|
-
}
|
|
13247
|
-
}
|
|
13248
|
-
if (r.intelImage) {
|
|
13249
|
-
try {
|
|
13250
|
-
await this.helper(r.intelImage, INTEL_SCRIPT, [mirrorRelPath(r), intelRelDir(r), serenaConfigYaml("@PROJECT@")]);
|
|
13251
|
-
} catch (e) {
|
|
13252
|
-
out.push({ repo: r, ok: false, detail: `intel index: ${describe(e)}` });
|
|
13253
|
-
continue;
|
|
13254
|
-
}
|
|
13255
|
-
}
|
|
13256
|
-
out.push({ repo: r, ok: true });
|
|
13257
|
-
}
|
|
13258
|
-
return out;
|
|
13259
|
-
}
|
|
13260
|
-
/**
|
|
13261
|
-
* Makes `<parentDir>/<name>` hold the tree at the tip of `base` in the
|
|
13262
|
-
* repository's mirror, owned by the host user so crew can remove it. Reads
|
|
13263
|
-
* the mirror only; the refresh that moves the tip is `refresh`.
|
|
13264
|
-
*/
|
|
13265
|
-
async materialize(repo, base, parentDir, name) {
|
|
13266
|
-
const uid = process.getuid?.();
|
|
13267
|
-
const gid = process.getgid?.();
|
|
13268
|
-
const extra = ["-v", `${parentDir}:/out`, ...uid === void 0 || gid === void 0 ? [] : ["--user", `${uid}:${gid}`, "-e", "HOME=/tmp"]];
|
|
13269
|
-
const { stdout } = await this.helper(this.s.helperImage, MATERIALIZE_SCRIPT, [mirrorRelPath(repo), name, base], {}, extra);
|
|
13270
|
-
const m = /^(updated|unchanged) (\S+)/m.exec(stdout);
|
|
13271
|
-
if (!m) throw new Error(`unexpected output materializing ${repo.host}/${repo.path}: ${stdout.trim().slice(0, 200)}`);
|
|
13272
|
-
return { tip: m[2], changed: m[1] === "updated" };
|
|
13273
|
-
}
|
|
13274
|
-
/**
|
|
13275
|
-
* The text of `path` at the tip of `base` in the repository's mirror, or
|
|
13276
|
-
* null when the mirror has no such file. Throws when the mirror or the
|
|
13277
|
-
* branch is missing, so the caller can tell "no contract" from "no mirror".
|
|
13278
|
-
*/
|
|
13279
|
-
async showFile(repo, base, path) {
|
|
13280
|
-
try {
|
|
13281
|
-
const { stdout } = await this.helper(this.s.helperImage, SHOW_SCRIPT, [mirrorRelPath(repo), base, path]);
|
|
13282
|
-
return stdout;
|
|
13283
|
-
} catch (e) {
|
|
13284
|
-
if (e.code === 4) return null;
|
|
13285
|
-
throw e;
|
|
13286
|
-
}
|
|
13287
|
-
}
|
|
13288
|
-
/** Mirrors in the volume with their last refresh; empty when the volume does not exist. */
|
|
13289
|
-
async list() {
|
|
13290
|
-
try {
|
|
13291
|
-
await this.engine(["volume", "inspect", this.s.volume]);
|
|
13292
|
-
} catch {
|
|
13293
|
-
return [];
|
|
13294
|
-
}
|
|
13295
|
-
const script = `cd ${VOLUME_ROOT}/mirrors 2>/dev/null || exit 0; find . -name '*.git' -type d -prune | while read -r d; do r="\${d#./}"; i=${VOLUME_ROOT}/intel/"\${r%.git}"; printf '%s\\t%s\\t%s\\t%s\\n' "$r" "$(cat "$d/crew-last-refresh" 2>/dev/null)" "$(cat "$i/indexed-commit" 2>/dev/null)" "$(stat -c %y "$i/indexed-commit" 2>/dev/null | cut -c1-19)"; done`;
|
|
13296
|
-
const { stdout } = await this.helper(this.s.helperImage, script, []);
|
|
13297
|
-
const rows = [];
|
|
13298
|
-
for (const line of stdout.split("\n").filter(Boolean)) {
|
|
13299
|
-
const [rel, when, commit, indexedAt] = line.split(" ");
|
|
13300
|
-
const m = /^([^/]+)\/(.+)\.git$/.exec(rel ?? "");
|
|
13301
|
-
if (m) rows.push({ repo: { host: m[1], path: m[2] }, lastRefresh: when?.trim() || null, ...commit?.trim() ? { intel: { commit: commit.trim(), indexedAt: indexedAt?.trim() || null } } : {} });
|
|
13302
|
-
}
|
|
13303
|
-
return rows;
|
|
13304
|
-
}
|
|
13305
|
-
/** Drops mirrors (and their dependency trees) for repositories not in `keep`. Returns what was dropped. */
|
|
13306
|
-
async prune(keep) {
|
|
13307
|
-
const have = new Set(keep.map((r) => `${r.host}/${r.path}`));
|
|
13308
|
-
const drop = (await this.list()).map((m) => m.repo).filter((r) => !have.has(`${r.host}/${r.path}`));
|
|
13309
|
-
for (const r of drop) {
|
|
13310
|
-
await this.helper(this.s.helperImage, `rm -rf ${VOLUME_ROOT}/${q(mirrorRelPath(r))} ${VOLUME_ROOT}/${q(depsRelDir(r))} ${VOLUME_ROOT}/${q(intelRelDir(r))}`, []);
|
|
13311
|
-
}
|
|
13312
|
-
return drop;
|
|
13313
|
-
}
|
|
13314
|
-
/** Recreates the volume empty; the next pass refreshes every mirror. */
|
|
13315
|
-
async reset() {
|
|
13316
|
-
try {
|
|
13317
|
-
await this.engine(["volume", "rm", "--force", this.s.volume]);
|
|
13318
|
-
} catch (e) {
|
|
13319
|
-
throw new Error(`could not remove volume ${this.s.volume}: ${describe(e)}`);
|
|
13320
|
-
}
|
|
13321
|
-
await this.ensureVolume();
|
|
13322
|
-
}
|
|
13323
|
-
};
|
|
13324
|
-
function describe(e) {
|
|
13325
|
-
const err3 = e;
|
|
13326
|
-
const lines2 = (err3.stderr?.trim() || err3.message || String(e)).split("\n");
|
|
13327
|
-
const tail3 = lines2.slice(-3);
|
|
13328
|
-
const first = lines2.find((l) => /^(fatal|error):/.test(l.trim()));
|
|
13329
|
-
return (first && !tail3.includes(first) ? [first, ...tail3] : tail3).join(" / ");
|
|
13330
|
-
}
|
|
13331
|
-
function cacheSettingsOf(cfg) {
|
|
13332
|
-
if (!cfg?.cacheVolume) return null;
|
|
13333
|
-
return {
|
|
13334
|
-
engine: cfg.engine ?? DEFAULT_CACHE_SETTINGS.engine,
|
|
13335
|
-
volume: cfg.cacheVolume,
|
|
13336
|
-
workspace: cfg.cacheWorkspace ?? DEFAULT_CACHE_SETTINGS.workspace,
|
|
13337
|
-
helperImage: cfg.cacheImage ?? DEFAULT_CACHE_SETTINGS.helperImage,
|
|
13338
|
-
depsImage: cfg.depsImage ?? cfg.image,
|
|
13339
|
-
depsCommand: cfg.depsCommand,
|
|
13340
|
-
depsLockfile: cfg.depsLockfile ?? DEFAULT_CACHE_SETTINGS.depsLockfile
|
|
13341
|
-
};
|
|
13342
|
-
}
|
|
13343
|
-
var sandboxCacheKey = (volume, r) => `sandbox_cache:${volume}:${r.host}/${r.path}`;
|
|
13344
|
-
function unmirroredRepos(served, mirrors) {
|
|
13345
|
-
const have = new Set(mirrors.map((m) => `${m.repo.host}/${m.repo.path}`));
|
|
13346
|
-
return served.map((r) => `${r.host}/${r.path}`).filter((k, i, a) => !have.has(k) && a.indexOf(k) === i);
|
|
13347
|
-
}
|
|
13348
|
-
var CACHE_REFRESH_INTERVAL_MS = 6e4;
|
|
13349
|
-
function makeCachePass(o) {
|
|
13350
|
-
const now = o.now ?? Date.now;
|
|
13351
|
-
let last = -Infinity;
|
|
13352
|
-
return async () => {
|
|
13353
|
-
if (now() - last < CACHE_REFRESH_INTERVAL_MS) return [];
|
|
13354
|
-
last = now();
|
|
13355
|
-
const all = [];
|
|
13356
|
-
for (const r of o.repos()) {
|
|
13357
|
-
let release;
|
|
13358
|
-
try {
|
|
13359
|
-
release = o.lock(r.dir);
|
|
13360
|
-
all.push(...await o.cache.refresh([r]));
|
|
13361
|
-
} catch (e) {
|
|
13362
|
-
all.push({ repo: r, ok: false, detail: describe(e) });
|
|
13363
|
-
} finally {
|
|
13364
|
-
release?.();
|
|
13365
|
-
}
|
|
13366
|
-
}
|
|
13367
|
-
for (const out of all) {
|
|
13368
|
-
const key = sandboxCacheKey(o.volume, out.repo);
|
|
13369
|
-
if (out.ok) o.ok(key);
|
|
13370
|
-
else await o.fail(key, `sandbox cache: ${out.repo.host}/${out.repo.path} did not refresh (${out.detail}); runs use the previous mirror. Resumes automatically when a later pass refreshes it`, new Date(now()).toISOString());
|
|
13371
|
-
}
|
|
13372
|
-
return all;
|
|
13373
|
-
};
|
|
13374
|
-
}
|
|
13375
|
-
|
|
13376
|
-
// src/passenger-containers.ts
|
|
13377
|
-
var realExec2 = (cmd, args, opts) => {
|
|
13378
|
-
try {
|
|
13379
|
-
return execFileSync8(cmd, args, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: opts?.timeoutMs });
|
|
13380
|
-
} catch (e) {
|
|
13381
|
-
const err3 = e;
|
|
13382
|
-
const why = [err3.stderr, err3.stdout].map((x) => (x ?? "").trim()).filter(Boolean).join(" / ");
|
|
13383
|
-
throw new Error(`${cmd} ${args.join(" ")}: ${why || err3.message.trim()}`);
|
|
13384
|
-
}
|
|
13385
|
-
};
|
|
13386
|
-
var DOCKER_INFO_TIMEOUT_MS = 1e4;
|
|
13387
|
-
function dockerAvailable(exec = realExec2) {
|
|
13388
|
-
try {
|
|
13389
|
-
exec("docker", ["info"], { timeoutMs: DOCKER_INFO_TIMEOUT_MS });
|
|
13390
|
-
return true;
|
|
13391
|
-
} catch {
|
|
13392
|
-
return false;
|
|
13393
|
-
}
|
|
13394
|
-
}
|
|
13395
|
-
var PASSENGER_IMAGE_REPO = "tablation/crew-passenger-mcp";
|
|
13396
|
-
function passengerImageRef(cfg) {
|
|
13397
|
-
return process.env.CREW_PASSENGER_IMAGE || cfg.ship.passengerImage || `${PASSENGER_IMAGE_REPO}:${crewVersion(cfg.crewHome)}`;
|
|
13398
|
-
}
|
|
13399
|
-
function imagePresent(image, exec = realExec2) {
|
|
13400
|
-
try {
|
|
13401
|
-
exec("docker", ["image", "inspect", image]);
|
|
13402
|
-
return true;
|
|
13403
|
-
} catch {
|
|
13404
|
-
return false;
|
|
13405
|
-
}
|
|
13406
|
-
}
|
|
13407
|
-
function ensureImage(image, exec = realExec2) {
|
|
13408
|
-
if (!imagePresent(image, exec)) exec("docker", ["pull", image]);
|
|
13409
|
-
}
|
|
13410
|
-
function containerNameFor(workspaceId) {
|
|
13411
|
-
return `crew-passenger-${workspaceId}`;
|
|
13412
|
-
}
|
|
13413
|
-
function portFor(workspaceId, base = 28765, span = 1e3) {
|
|
13414
|
-
const digest = createHash6("sha256").update(workspaceId).digest();
|
|
13415
|
-
return base + digest.readUInt32BE(0) % span;
|
|
13416
|
-
}
|
|
13417
|
-
function mountsDigest(mounts, image) {
|
|
13418
|
-
const sorted2 = [...mounts].sort((a, b) => a.containerPath.localeCompare(b.containerPath));
|
|
13419
|
-
return createHash6("sha256").update(JSON.stringify({ mounts: sorted2, image })).digest("hex").slice(0, 16);
|
|
13420
|
-
}
|
|
13421
|
-
function planContainers(cfg) {
|
|
13422
|
-
const byWorkspace = /* @__PURE__ */ new Map();
|
|
13423
|
-
const image = passengerImageRef(cfg);
|
|
13424
|
-
for (const route2 of cfg.routes) {
|
|
13425
|
-
if (!route2.enabled || !route2.hostPassengers || !route2.resolved?.workspaceId) continue;
|
|
13426
|
-
const workspaceId = route2.resolved.workspaceId;
|
|
13427
|
-
const mounts = byWorkspace.get(workspaceId) ?? /* @__PURE__ */ new Map();
|
|
13428
|
-
for (const target of passengerCheckoutTargets(route2, passengerMirrorArea(cfg.ship))) {
|
|
13429
|
-
mounts.set(target.name, { hostPath: target.dir, containerPath: `/workspace/${target.name}` });
|
|
13537
|
+
"--label",
|
|
13538
|
+
DOCKER_LABEL_CACHE,
|
|
13539
|
+
this.s.volume
|
|
13540
|
+
]);
|
|
13541
|
+
return true;
|
|
13542
|
+
}
|
|
13543
|
+
/** The workspace label the existing volume carries, or null when the volume is absent or unlabeled. A volume's labels cannot be changed in place. */
|
|
13544
|
+
async volumeWorkspace() {
|
|
13545
|
+
try {
|
|
13546
|
+
const { stdout } = await this.engine(["volume", "inspect", "--format", `{{index .Labels "${OPENSHELL_WORKSPACE_LABEL}"}}`, this.s.volume]);
|
|
13547
|
+
const v = stdout.trim();
|
|
13548
|
+
return v && v !== "<no value>" ? v : null;
|
|
13549
|
+
} catch {
|
|
13550
|
+
return null;
|
|
13430
13551
|
}
|
|
13431
|
-
byWorkspace.set(workspaceId, mounts);
|
|
13432
13552
|
}
|
|
13433
|
-
|
|
13434
|
-
const
|
|
13435
|
-
return {
|
|
13436
|
-
workspaceId,
|
|
13437
|
-
containerName: containerNameFor(workspaceId),
|
|
13438
|
-
port: portFor(workspaceId),
|
|
13439
|
-
image,
|
|
13440
|
-
mounts: mountList,
|
|
13441
|
-
mountsHash: mountsDigest(mountList, image)
|
|
13442
|
-
};
|
|
13443
|
-
});
|
|
13444
|
-
}
|
|
13445
|
-
function listPassengerContainers(exec = realExec2) {
|
|
13446
|
-
const out = exec("docker", ["ps", "-a", "--filter", "name=crew-passenger-", "--format", "{{.Names}} {{.State}}"]);
|
|
13447
|
-
return out.split("\n").map((l) => l.trim()).filter(Boolean).map((line) => {
|
|
13448
|
-
const [name, state] = line.split(" ");
|
|
13449
|
-
return { name, running: state === "running" };
|
|
13450
|
-
});
|
|
13451
|
-
}
|
|
13452
|
-
function currentMountsHash(name, exec) {
|
|
13453
|
-
try {
|
|
13454
|
-
const out = exec("docker", ["inspect", "--format", '{{ index .Config.Labels "crew.mounts.hash" }}', name]);
|
|
13455
|
-
const hash2 = out.trim();
|
|
13456
|
-
return hash2 || void 0;
|
|
13457
|
-
} catch {
|
|
13458
|
-
return void 0;
|
|
13553
|
+
helper(image, script, args, env = {}, extra = []) {
|
|
13554
|
+
const flags = Object.keys(env).flatMap((k) => ["-e", k]);
|
|
13555
|
+
return this.engine(["run", "--rm", "--label", DOCKER_LABEL_OWNER, "-v", `${this.s.volume}:${VOLUME_ROOT}`, ...extra, ...flags, "--entrypoint", "sh", image, "-c", script, "sh", ...args], { ...process.env, ...env });
|
|
13459
13556
|
}
|
|
13460
|
-
|
|
13461
|
-
|
|
13462
|
-
|
|
13463
|
-
|
|
13464
|
-
|
|
13557
|
+
/**
|
|
13558
|
+
* Refreshes every mirror (and, where configured, its dependency tree). One
|
|
13559
|
+
* repository failing does not stop the others; the caller raises attention
|
|
13560
|
+
* for the failures and the runs keep using the previous mirror state.
|
|
13561
|
+
*/
|
|
13562
|
+
async refresh(repos) {
|
|
13563
|
+
await this.ensureVolume();
|
|
13564
|
+
const out = [];
|
|
13565
|
+
for (const r of repos) {
|
|
13566
|
+
const env = r.token ? { CREW_FORGE_TOKEN: r.token, CREW_FORGE_USER: r.username ?? DEFAULT_FORGE_USERNAME } : {};
|
|
13567
|
+
try {
|
|
13568
|
+
await this.helper(this.s.helperImage, REFRESH_SCRIPT, [mirrorRelPath(r), forgeDescriptorFor(r.host).httpsUrl(r.host, r.path)], env);
|
|
13569
|
+
} catch (e) {
|
|
13570
|
+
out.push({ repo: r, ok: false, detail: r.token ? describe(e) : `no readable forge token for ${r.host} (see \`crew forge list\`); ${describe(e)}` });
|
|
13571
|
+
continue;
|
|
13572
|
+
}
|
|
13573
|
+
if (this.s.depsCommand && this.s.depsImage) {
|
|
13574
|
+
try {
|
|
13575
|
+
await this.helper(this.s.depsImage, DEPS_SCRIPT, [mirrorRelPath(r), depsRelDir(r), this.s.depsLockfile], { CREW_DEPS_COMMAND: this.s.depsCommand });
|
|
13576
|
+
} catch (e) {
|
|
13577
|
+
out.push({ repo: r, ok: false, detail: `dependency tree: ${describe(e)}` });
|
|
13578
|
+
continue;
|
|
13579
|
+
}
|
|
13580
|
+
}
|
|
13581
|
+
if (r.intelImage) {
|
|
13582
|
+
try {
|
|
13583
|
+
await this.helper(r.intelImage, INTEL_SCRIPT, [mirrorRelPath(r), intelRelDir(r), serenaConfigYaml("@PROJECT@")]);
|
|
13584
|
+
} catch (e) {
|
|
13585
|
+
out.push({ repo: r, ok: false, detail: `intel index: ${describe(e)}` });
|
|
13586
|
+
continue;
|
|
13587
|
+
}
|
|
13588
|
+
}
|
|
13589
|
+
out.push({ repo: r, ok: true });
|
|
13590
|
+
}
|
|
13591
|
+
return out;
|
|
13465
13592
|
}
|
|
13466
|
-
|
|
13467
|
-
|
|
13468
|
-
|
|
13469
|
-
|
|
13470
|
-
|
|
13471
|
-
|
|
13472
|
-
|
|
13473
|
-
|
|
13474
|
-
"
|
|
13475
|
-
|
|
13476
|
-
|
|
13477
|
-
|
|
13478
|
-
|
|
13479
|
-
"-e",
|
|
13480
|
-
`TABLATION_API_BASE_URL=${tablationApiBaseUrl}`,
|
|
13481
|
-
"--label",
|
|
13482
|
-
`crew.mounts.hash=${plan.mountsHash}`
|
|
13483
|
-
];
|
|
13484
|
-
if (sync) {
|
|
13485
|
-
args.push(
|
|
13486
|
-
"--add-host",
|
|
13487
|
-
"host.docker.internal:host-gateway",
|
|
13488
|
-
"-e",
|
|
13489
|
-
`PASSENGER_SYNC_URL=http://${sync.host}:${sync.port}/sync`,
|
|
13490
|
-
"-e",
|
|
13491
|
-
`PASSENGER_SYNC_SECRET=${sync.secret}`,
|
|
13492
|
-
"-e",
|
|
13493
|
-
`PASSENGER_MCP_SECRET=${sync.secret}`
|
|
13494
|
-
);
|
|
13593
|
+
/**
|
|
13594
|
+
* Makes `<parentDir>/<name>` hold the tree at the tip of `base` in the
|
|
13595
|
+
* repository's mirror, owned by the host user so crew can remove it. Reads
|
|
13596
|
+
* the mirror only; the refresh that moves the tip is `refresh`.
|
|
13597
|
+
*/
|
|
13598
|
+
async materialize(repo, base, parentDir, name) {
|
|
13599
|
+
const uid = process.getuid?.();
|
|
13600
|
+
const gid = process.getgid?.();
|
|
13601
|
+
const extra = ["-v", `${parentDir}:/out`, ...uid === void 0 || gid === void 0 ? [] : ["--user", `${uid}:${gid}`, "-e", "HOME=/tmp"]];
|
|
13602
|
+
const { stdout } = await this.helper(this.s.helperImage, MATERIALIZE_SCRIPT, [mirrorRelPath(repo), name, base], {}, extra);
|
|
13603
|
+
const m = /^(updated|unchanged) (\S+)/m.exec(stdout);
|
|
13604
|
+
if (!m) throw new Error(`unexpected output materializing ${repo.host}/${repo.path}: ${stdout.trim().slice(0, 200)}`);
|
|
13605
|
+
return { tip: m[2], changed: m[1] === "updated" };
|
|
13495
13606
|
}
|
|
13496
|
-
|
|
13497
|
-
|
|
13498
|
-
|
|
13499
|
-
|
|
13500
|
-
|
|
13501
|
-
|
|
13502
|
-
|
|
13503
|
-
|
|
13504
|
-
|
|
13505
|
-
|
|
13506
|
-
|
|
13507
|
-
|
|
13508
|
-
const ensured = /* @__PURE__ */ new Set();
|
|
13509
|
-
const start = (plan, sync) => {
|
|
13510
|
-
if (!ensured.has(plan.image)) {
|
|
13511
|
-
ensureImage(plan.image, exec);
|
|
13512
|
-
ensured.add(plan.image);
|
|
13513
|
-
}
|
|
13514
|
-
startContainer(plan, tablationApiBaseUrl, sync, exec);
|
|
13515
|
-
};
|
|
13516
|
-
for (const plan of plans) {
|
|
13517
|
-
const sync = syncEndpoints.get(plan.workspaceId);
|
|
13518
|
-
const current = existingByName.get(plan.containerName);
|
|
13519
|
-
if (!current) {
|
|
13520
|
-
start(plan, sync);
|
|
13521
|
-
started.push(plan.containerName);
|
|
13522
|
-
} else if (!current.running) {
|
|
13523
|
-
stopContainer(plan.containerName, exec);
|
|
13524
|
-
start(plan, sync);
|
|
13525
|
-
started.push(plan.containerName);
|
|
13526
|
-
} else if (currentMountsHash(plan.containerName, exec) !== plan.mountsHash) {
|
|
13527
|
-
stopContainer(plan.containerName, exec);
|
|
13528
|
-
start(plan, sync);
|
|
13529
|
-
recreated.push(plan.containerName);
|
|
13607
|
+
/**
|
|
13608
|
+
* The text of `path` at the tip of `base` in the repository's mirror, or
|
|
13609
|
+
* null when the mirror has no such file. Throws when the mirror or the
|
|
13610
|
+
* branch is missing, so the caller can tell "no contract" from "no mirror".
|
|
13611
|
+
*/
|
|
13612
|
+
async showFile(repo, base, path) {
|
|
13613
|
+
try {
|
|
13614
|
+
const { stdout } = await this.helper(this.s.helperImage, SHOW_SCRIPT, [mirrorRelPath(repo), base, path]);
|
|
13615
|
+
return stdout;
|
|
13616
|
+
} catch (e) {
|
|
13617
|
+
if (e.code === 4) return null;
|
|
13618
|
+
throw e;
|
|
13530
13619
|
}
|
|
13531
13620
|
}
|
|
13532
|
-
|
|
13533
|
-
|
|
13534
|
-
|
|
13535
|
-
|
|
13621
|
+
/** Mirrors in the volume with their last refresh; empty when the volume does not exist. */
|
|
13622
|
+
async list() {
|
|
13623
|
+
try {
|
|
13624
|
+
await this.engine(["volume", "inspect", this.s.volume]);
|
|
13625
|
+
} catch {
|
|
13626
|
+
return [];
|
|
13627
|
+
}
|
|
13628
|
+
const script = `cd ${VOLUME_ROOT}/mirrors 2>/dev/null || exit 0; find . -name '*.git' -type d -prune | while read -r d; do r="\${d#./}"; i=${VOLUME_ROOT}/intel/"\${r%.git}"; printf '%s\\t%s\\t%s\\t%s\\n' "$r" "$(cat "$d/crew-last-refresh" 2>/dev/null)" "$(cat "$i/indexed-commit" 2>/dev/null)" "$(stat -c %y "$i/indexed-commit" 2>/dev/null | cut -c1-19)"; done`;
|
|
13629
|
+
const { stdout } = await this.helper(this.s.helperImage, script, []);
|
|
13630
|
+
const rows = [];
|
|
13631
|
+
for (const line of stdout.split("\n").filter(Boolean)) {
|
|
13632
|
+
const [rel, when, commit, indexedAt] = line.split(" ");
|
|
13633
|
+
const m = /^([^/]+)\/(.+)\.git$/.exec(rel ?? "");
|
|
13634
|
+
if (m) rows.push({ repo: { host: m[1], path: m[2] }, lastRefresh: when?.trim() || null, ...commit?.trim() ? { intel: { commit: commit.trim(), indexedAt: indexedAt?.trim() || null } } : {} });
|
|
13536
13635
|
}
|
|
13636
|
+
return rows;
|
|
13537
13637
|
}
|
|
13538
|
-
|
|
13539
|
-
|
|
13540
|
-
|
|
13541
|
-
|
|
13542
|
-
|
|
13543
|
-
|
|
13544
|
-
if (workspaceId && route2.resolved.workspaceId !== workspaceId) continue;
|
|
13545
|
-
const routeWorkspaceId = route2.resolved.workspaceId;
|
|
13546
|
-
const mirrorArea = passengerMirrorArea(cfg.ship);
|
|
13547
|
-
const cache = mirrorArea ? cacheSettingsOf(cfg.ship.sandbox) : null;
|
|
13548
|
-
const ordinaryByName = new Map(reposOf(route2).map((t) => [t.name, t]));
|
|
13549
|
-
for (const target of passengerCheckoutTargets(route2, mirrorArea)) {
|
|
13550
|
-
const ordinary = ordinaryByName.get(target.name);
|
|
13551
|
-
const override = route2.repoOverrides[target.name];
|
|
13552
|
-
let refused = false;
|
|
13553
|
-
const declared = ordinary ? loadRepoConfigTolerant(ordinary.dir, (e) => {
|
|
13554
|
-
refused = true;
|
|
13555
|
-
onRefused?.(target.name, e);
|
|
13556
|
-
}) : null;
|
|
13557
|
-
if (refused) continue;
|
|
13558
|
-
const effective = resolveRepoConfig(
|
|
13559
|
-
declared,
|
|
13560
|
-
{ branch: { ...route2.branch, ...override?.branch } },
|
|
13561
|
-
ordinary?.dir ?? target.dir
|
|
13562
|
-
);
|
|
13563
|
-
specs.push({
|
|
13564
|
-
name: target.name,
|
|
13565
|
-
workspaceId: routeWorkspaceId,
|
|
13566
|
-
dir: target.dir,
|
|
13567
|
-
remote: target.remote,
|
|
13568
|
-
gitRemoteName: effective.branch.remote,
|
|
13569
|
-
base: effective.branch.base,
|
|
13570
|
-
originUrl: ordinary ? originUrlOf(ordinary.dir, effective.branch.remote) : null,
|
|
13571
|
-
cloneScheme: cfg.ship.cloneScheme,
|
|
13572
|
-
...target.forgeHost ? { forgeHost: target.forgeHost } : {},
|
|
13573
|
-
...cache ? { mirror: { cache } } : {}
|
|
13574
|
-
});
|
|
13638
|
+
/** Drops mirrors (and their dependency trees) for repositories not in `keep`. Returns what was dropped. */
|
|
13639
|
+
async prune(keep) {
|
|
13640
|
+
const have = new Set(keep.map((r) => `${r.host}/${r.path}`));
|
|
13641
|
+
const drop = (await this.list()).map((m) => m.repo).filter((r) => !have.has(`${r.host}/${r.path}`));
|
|
13642
|
+
for (const r of drop) {
|
|
13643
|
+
await this.helper(this.s.helperImage, `rm -rf ${VOLUME_ROOT}/${q(mirrorRelPath(r))} ${VOLUME_ROOT}/${q(depsRelDir(r))} ${VOLUME_ROOT}/${q(intelRelDir(r))}`, []);
|
|
13575
13644
|
}
|
|
13645
|
+
return drop;
|
|
13576
13646
|
}
|
|
13577
|
-
|
|
13578
|
-
|
|
13579
|
-
|
|
13580
|
-
|
|
13581
|
-
|
|
13582
|
-
|
|
13583
|
-
|
|
13584
|
-
|
|
13585
|
-
}
|
|
13586
|
-
|
|
13587
|
-
// src/sandbox-image.ts
|
|
13588
|
-
var SANDBOX_BASE_IMAGE = "nvcr.io/nvidia/base/ubuntu:24.04";
|
|
13589
|
-
var SANDBOX_OPENSHELL_VERSION = "0.1.6";
|
|
13590
|
-
var SANDBOX_CLAUDE_VERSION = "2.1.309";
|
|
13591
|
-
var SANDBOX_CLAUDE_DIST = "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases";
|
|
13592
|
-
var SANDBOX_CLAUDE_SHA256 = {
|
|
13593
|
-
x86_64: { platform: "linux-x64", sha256: "4d704a8aecbe038affa3000f498ae17c1b4f753add8facb8764120affc99b658" },
|
|
13594
|
-
aarch64: { platform: "linux-arm64", sha256: "9796dd26899337f687739a0b39a7353b639f062a3436a7b941fcf19a1b757a9b" }
|
|
13595
|
-
};
|
|
13596
|
-
var SANDBOX_UID = 1e3;
|
|
13597
|
-
var CREW_PREFIX = "/opt/crew";
|
|
13598
|
-
var SANDBOX_BRIDGE_PATH = `${CREW_PREFIX}/bin/intel-bridge`;
|
|
13599
|
-
function readBridgeBundle() {
|
|
13600
|
-
const here = dirname15(fileURLToPath(import.meta.url));
|
|
13601
|
-
for (const p of [join32(here, "sandbox-intel-bridge.cjs"), join32(here, "..", "dist", "sandbox-intel-bridge.cjs")]) {
|
|
13602
|
-
if (existsSync29(p)) return readFileSync28(p, "utf8");
|
|
13647
|
+
/** Recreates the volume empty; the next pass refreshes every mirror. */
|
|
13648
|
+
async reset() {
|
|
13649
|
+
try {
|
|
13650
|
+
await this.engine(["volume", "rm", "--force", this.s.volume]);
|
|
13651
|
+
} catch (e) {
|
|
13652
|
+
throw new Error(`could not remove volume ${this.s.volume}: ${describe(e)}`);
|
|
13653
|
+
}
|
|
13654
|
+
await this.ensureVolume();
|
|
13603
13655
|
}
|
|
13604
|
-
return void 0;
|
|
13605
|
-
}
|
|
13606
|
-
var SANDBOX_UV_VERSION = "0.13.6";
|
|
13607
|
-
var SANDBOX_SERENA_VERSION = "2.1.0";
|
|
13608
|
-
var SERENA_IMAGE_HOME = `${CREW_PREFIX}/serena`;
|
|
13609
|
-
var SERENA_LANGUAGE_SERVERS_ENV = "CREW_SERENA_LANGUAGE_SERVERS";
|
|
13610
|
-
var SANDBOX_RETRY_AFTER_MS = 60 * 60 * 1e3;
|
|
13611
|
-
var KEEP_TAGS = 2;
|
|
13612
|
-
var CREDENTIAL_HELPER = `#!/bin/sh
|
|
13613
|
-
# git credential helper: answers from the environment the runner passes in, so
|
|
13614
|
-
# no token is ever written into an image layer.
|
|
13615
|
-
[ "$1" = get ] || exit 0
|
|
13616
|
-
[ -n "$CREW_FORGE_TOKEN" ] || exit 0
|
|
13617
|
-
echo "username=\${CREW_FORGE_USER:-x-access-token}"
|
|
13618
|
-
echo "password=$CREW_FORGE_TOKEN"
|
|
13619
|
-
`;
|
|
13620
|
-
var MCP_CONFIG = `${JSON.stringify({ mcpServers: {} }, null, 2)}
|
|
13621
|
-
`;
|
|
13622
|
-
var hash = (parts) => createHash7("sha256").update(JSON.stringify(parts)).digest("hex").slice(0, 12);
|
|
13623
|
-
var slug = (s) => s.toLowerCase().replace(/[^a-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "") || "repo";
|
|
13624
|
-
var run2 = (cmd) => `RUN ["/bin/bash", "-c", ${JSON.stringify(`set -euo pipefail; ${cmd}`)}]`;
|
|
13625
|
-
var CREW_ENV = {
|
|
13626
|
-
CREW_SANDBOX: "1",
|
|
13627
|
-
CREW_CACHE_DIR: `${CREW_PREFIX}/cache`,
|
|
13628
|
-
XDG_CACHE_HOME: `${CREW_PREFIX}/cache`,
|
|
13629
|
-
npm_config_cache: `${CREW_PREFIX}/cache/npm`,
|
|
13630
|
-
npm_config_store_dir: `${CREW_PREFIX}/pnpm-store`,
|
|
13631
|
-
// pnpm 11 ignores npm_config_store_dir and reads only this spelling (CREW-2973): without it `pnpm fetch`
|
|
13632
|
-
// at build time fills the builder's home store, and a run's offline install finds /opt/crew/pnpm-store empty.
|
|
13633
|
-
pnpm_config_store_dir: `${CREW_PREFIX}/pnpm-store`,
|
|
13634
|
-
PNPM_HOME: `${CREW_PREFIX}/pnpm`,
|
|
13635
|
-
// A run cannot reach the download host, so an in-run update attempt is only noise.
|
|
13636
|
-
DISABLE_AUTOUPDATER: "1"
|
|
13637
13656
|
};
|
|
13638
|
-
function
|
|
13639
|
-
const
|
|
13640
|
-
|
|
13641
|
-
|
|
13642
|
-
|
|
13657
|
+
function describe(e) {
|
|
13658
|
+
const err3 = e;
|
|
13659
|
+
const lines2 = (err3.stderr?.trim() || err3.message || String(e)).split("\n");
|
|
13660
|
+
const tail3 = lines2.slice(-3);
|
|
13661
|
+
const first = lines2.find((l) => /^(fatal|error):/.test(l.trim()));
|
|
13662
|
+
return (first && !tail3.includes(first) ? [first, ...tail3] : tail3).join(" / ");
|
|
13663
|
+
}
|
|
13664
|
+
function cacheSettingsOf(cfg) {
|
|
13665
|
+
if (!cfg?.cacheVolume) return null;
|
|
13666
|
+
return {
|
|
13667
|
+
engine: cfg.engine ?? DEFAULT_CACHE_SETTINGS.engine,
|
|
13668
|
+
volume: cfg.cacheVolume,
|
|
13669
|
+
workspace: cfg.cacheWorkspace ?? DEFAULT_CACHE_SETTINGS.workspace,
|
|
13670
|
+
helperImage: cfg.cacheImage ?? DEFAULT_CACHE_SETTINGS.helperImage,
|
|
13671
|
+
depsImage: cfg.depsImage ?? cfg.image,
|
|
13672
|
+
depsCommand: cfg.depsCommand,
|
|
13673
|
+
depsLockfile: cfg.depsLockfile ?? DEFAULT_CACHE_SETTINGS.depsLockfile
|
|
13643
13674
|
};
|
|
13644
|
-
return Object.entries(vars).map(([k, v]) => `${k}=${v}; export ${k}; `).join("");
|
|
13645
13675
|
}
|
|
13646
|
-
|
|
13647
|
-
|
|
13648
|
-
|
|
13649
|
-
|
|
13650
|
-
`mkdir -p ${CREW_PREFIX}/bin`,
|
|
13651
|
-
`curl -fsSL --retry 3 -o ${CREW_PREFIX}/bin/claude "${SANDBOX_CLAUDE_DIST}/${SANDBOX_CLAUDE_VERSION}/$p/claude"`,
|
|
13652
|
-
`echo "$sum ${CREW_PREFIX}/bin/claude" | sha256sum -c -`,
|
|
13653
|
-
`chmod 0755 ${CREW_PREFIX}/bin/claude`,
|
|
13654
|
-
`${CREW_PREFIX}/bin/claude --version | grep -F "${SANDBOX_CLAUDE_VERSION}"`
|
|
13655
|
-
].join("; ");
|
|
13676
|
+
var sandboxCacheKey = (volume, r) => `sandbox_cache:${volume}:${r.host}/${r.path}`;
|
|
13677
|
+
function unmirroredRepos(served, mirrors) {
|
|
13678
|
+
const have = new Set(mirrors.map((m) => `${m.repo.host}/${m.repo.path}`));
|
|
13679
|
+
return served.map((r) => `${r.host}/${r.path}`).filter((k, i, a) => !have.has(k) && a.indexOf(k) === i);
|
|
13656
13680
|
}
|
|
13657
|
-
|
|
13658
|
-
|
|
13659
|
-
|
|
13660
|
-
|
|
13661
|
-
|
|
13662
|
-
|
|
13663
|
-
|
|
13664
|
-
|
|
13681
|
+
var CACHE_REFRESH_INTERVAL_MS = 6e4;
|
|
13682
|
+
function makeCachePass(o) {
|
|
13683
|
+
const now = o.now ?? Date.now;
|
|
13684
|
+
let last = -Infinity;
|
|
13685
|
+
return async () => {
|
|
13686
|
+
if (now() - last < CACHE_REFRESH_INTERVAL_MS) return [];
|
|
13687
|
+
last = now();
|
|
13688
|
+
const all = [];
|
|
13689
|
+
for (const r of o.repos()) {
|
|
13690
|
+
let release;
|
|
13691
|
+
try {
|
|
13692
|
+
release = o.lock(r.dir);
|
|
13693
|
+
all.push(...await o.cache.refresh([r]));
|
|
13694
|
+
} catch (e) {
|
|
13695
|
+
all.push({ repo: r, ok: false, detail: describe(e) });
|
|
13696
|
+
} finally {
|
|
13697
|
+
release?.();
|
|
13698
|
+
}
|
|
13699
|
+
}
|
|
13700
|
+
for (const out of all) {
|
|
13701
|
+
const key = sandboxCacheKey(o.volume, out.repo);
|
|
13702
|
+
if (out.ok) o.ok(key);
|
|
13703
|
+
else await o.fail(key, `sandbox cache: ${out.repo.host}/${out.repo.path} did not refresh (${out.detail}); runs use the previous mirror. Resumes automatically when a later pass refreshes it`, new Date(now()).toISOString());
|
|
13704
|
+
}
|
|
13705
|
+
return all;
|
|
13706
|
+
};
|
|
13665
13707
|
}
|
|
13666
|
-
|
|
13667
|
-
|
|
13668
|
-
|
|
13669
|
-
|
|
13670
|
-
|
|
13708
|
+
|
|
13709
|
+
// src/passenger-containers.ts
|
|
13710
|
+
var realExec = (cmd, args, opts) => {
|
|
13711
|
+
try {
|
|
13712
|
+
return execFileSync9(cmd, args, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: opts?.timeoutMs });
|
|
13713
|
+
} catch (e) {
|
|
13714
|
+
const err3 = e;
|
|
13715
|
+
const why = [err3.stderr, err3.stdout].map((x) => (x ?? "").trim()).filter(Boolean).join(" / ");
|
|
13716
|
+
throw new Error(`${cmd} ${args.join(" ")}: ${why || err3.message.trim()}`);
|
|
13717
|
+
}
|
|
13718
|
+
};
|
|
13719
|
+
var DOCKER_INFO_TIMEOUT_MS = 1e4;
|
|
13720
|
+
function dockerAvailable(exec = realExec) {
|
|
13721
|
+
try {
|
|
13722
|
+
exec("docker", ["info"], { timeoutMs: DOCKER_INFO_TIMEOUT_MS });
|
|
13723
|
+
return true;
|
|
13724
|
+
} catch {
|
|
13725
|
+
return false;
|
|
13726
|
+
}
|
|
13671
13727
|
}
|
|
13672
|
-
|
|
13673
|
-
|
|
13674
|
-
|
|
13675
|
-
`LABEL io.crew.sandbox.layer="base" io.crew.sandbox.openshell="${SANDBOX_OPENSHELL_VERSION}"`,
|
|
13676
|
-
""
|
|
13677
|
-
].join("\n");
|
|
13678
|
-
return { name: "base", tag: `crew-sandbox-base:${hash({ SANDBOX_BASE_IMAGE, SANDBOX_OPENSHELL_VERSION })}`, dockerfile, files: {} };
|
|
13728
|
+
var PASSENGER_IMAGE_REPO = "tablation/crew-passenger-mcp";
|
|
13729
|
+
function passengerImageRef(cfg) {
|
|
13730
|
+
return process.env.CREW_PASSENGER_IMAGE || cfg.ship.passengerImage || `${PASSENGER_IMAGE_REPO}:${crewVersion(cfg.crewHome)}`;
|
|
13679
13731
|
}
|
|
13680
|
-
|
|
13681
|
-
|
|
13682
|
-
|
|
13683
|
-
|
|
13684
|
-
|
|
13685
|
-
|
|
13686
|
-
return readFileSync28(path, "utf8");
|
|
13687
|
-
} catch {
|
|
13688
|
-
}
|
|
13732
|
+
function imagePresent(image, exec = realExec) {
|
|
13733
|
+
try {
|
|
13734
|
+
exec("docker", ["image", "inspect", image]);
|
|
13735
|
+
return true;
|
|
13736
|
+
} catch {
|
|
13737
|
+
return false;
|
|
13689
13738
|
}
|
|
13690
|
-
return "";
|
|
13691
13739
|
}
|
|
13692
|
-
function
|
|
13693
|
-
|
|
13694
|
-
const env = Object.entries(CREW_ENV).map(([k, v]) => `${k}=${v}`).join(" ");
|
|
13695
|
-
const dockerfile = [
|
|
13696
|
-
`FROM ${base.tag}`,
|
|
13697
|
-
"USER root",
|
|
13698
|
-
`COPY ${CA_BUNDLE_FILE} /etc/ssl/certs/ca-certificates.crt`,
|
|
13699
|
-
run2(APT_HTTPS_COMMAND),
|
|
13700
|
-
run2(`apt-get update && apt-get install -y --no-install-recommends ca-certificates curl git${intel ? " python3 python3-venv nodejs" : ""} && rm -rf /var/lib/apt/lists/*`),
|
|
13701
|
-
`COPY credential-helper ${CREW_PREFIX}/bin/credential-helper`,
|
|
13702
|
-
`COPY mcp.json ${CREW_PREFIX}/mcp/mcp.json`,
|
|
13703
|
-
...bridge ? [`COPY intel-bridge ${SANDBOX_BRIDGE_PATH}`] : [],
|
|
13704
|
-
run2(claudeInstallCommand()),
|
|
13705
|
-
...intel ? [run2(`mkdir -p ${CREW_PREFIX}/cache && ${serenaInstallCommand()}`)] : [],
|
|
13706
|
-
run2(`chmod 0755 ${CREW_PREFIX}/bin/credential-helper && git config --system credential.helper ${CREW_PREFIX}/bin/credential-helper`),
|
|
13707
|
-
run2(`mkdir -p ${CREW_PREFIX}/cache ${CREW_PREFIX}/pnpm-store ${CREW_PREFIX}/pnpm /sandbox && chown -R ${SANDBOX_UID}:${SANDBOX_UID} ${CREW_PREFIX} /sandbox`),
|
|
13708
|
-
...intel ? [`ENV ${SERENA_LANGUAGE_SERVERS_ENV}=${SERENA_IMAGE_HOME}/language_servers UV_PYTHON_INSTALL_DIR=${CREW_PREFIX}/uv/python`] : [],
|
|
13709
|
-
`ENV ${env} PATH=${CREW_PREFIX}/pnpm:${CREW_PREFIX}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin`,
|
|
13710
|
-
`LABEL io.crew.sandbox.layer="crew" io.crew.sandbox.claude="${SANDBOX_CLAUDE_VERSION}"`,
|
|
13711
|
-
""
|
|
13712
|
-
].join("\n");
|
|
13713
|
-
return { name: "crew", tag: `crew-sandbox-crew:${hash({ base: base.tag, dockerfile, files })}`, dockerfile, files, caBundleFile: CA_BUNDLE_FILE };
|
|
13740
|
+
function ensureImage(image, exec = realExec) {
|
|
13741
|
+
if (!imagePresent(image, exec)) exec("docker", ["pull", image]);
|
|
13714
13742
|
}
|
|
13715
|
-
|
|
13716
|
-
|
|
13717
|
-
var globToRegExp = (glob) => new RegExp(`^${glob.split("*").map((p) => p.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join("[^/]*")}$`);
|
|
13718
|
-
function readWarmFiles(dir, ref, patterns) {
|
|
13719
|
-
if (patterns.length === 0) return {};
|
|
13720
|
-
const git2 = (args) => execFileSync9("git", ["-C", dir, ...args], { encoding: "utf8", maxBuffer: WARM_MAX_BYTES, stdio: ["ignore", "pipe", "pipe"] });
|
|
13721
|
-
const all = git2(["ls-tree", "-r", "--name-only", ref]).split("\n").filter(Boolean);
|
|
13722
|
-
const res = patterns.map(globToRegExp);
|
|
13723
|
-
const out = {};
|
|
13724
|
-
let total = 0;
|
|
13725
|
-
for (const path of all.filter((f) => res.some((re) => re.test(f))).sort()) {
|
|
13726
|
-
const content = git2(["show", `${ref}:${path}`]);
|
|
13727
|
-
total += content.length;
|
|
13728
|
-
if (total > WARM_MAX_BYTES) throw new Error(`sandbox.warm files exceed ${WARM_MAX_BYTES} bytes`);
|
|
13729
|
-
out[path] = content;
|
|
13730
|
-
}
|
|
13731
|
-
return out;
|
|
13743
|
+
function containerNameFor(workspaceId) {
|
|
13744
|
+
return `crew-passenger-${workspaceId}`;
|
|
13732
13745
|
}
|
|
13733
|
-
function
|
|
13734
|
-
const
|
|
13735
|
-
|
|
13736
|
-
|
|
13737
|
-
|
|
13738
|
-
|
|
13739
|
-
|
|
13740
|
-
|
|
13741
|
-
|
|
13742
|
-
|
|
13743
|
-
|
|
13744
|
-
|
|
13745
|
-
|
|
13746
|
-
|
|
13747
|
-
|
|
13748
|
-
|
|
13749
|
-
|
|
13750
|
-
|
|
13751
|
-
|
|
13752
|
-
run2(`mkdir -p /sandbox && chown -R ${SANDBOX_UID}:${SANDBOX_UID} /sandbox ${CREW_PREFIX}`),
|
|
13753
|
-
`USER ${SANDBOX_UID}`,
|
|
13754
|
-
"WORKDIR /sandbox"
|
|
13755
|
-
);
|
|
13756
|
-
const files = {};
|
|
13757
|
-
const warming = Object.keys(warm).length > 0;
|
|
13758
|
-
if (warming) {
|
|
13759
|
-
for (const [path, content] of Object.entries(warm)) files[`warm/${path}`] = content;
|
|
13760
|
-
lines2.push(`COPY --chown=${SANDBOX_UID}:${SANDBOX_UID} warm/ ${WARM_DIR}/`, `WORKDIR ${WARM_DIR}`);
|
|
13746
|
+
function portFor(workspaceId, base = 28765, span = 1e3) {
|
|
13747
|
+
const digest = createHash7("sha256").update(workspaceId).digest();
|
|
13748
|
+
return base + digest.readUInt32BE(0) % span;
|
|
13749
|
+
}
|
|
13750
|
+
function mountsDigest(mounts, image) {
|
|
13751
|
+
const sorted2 = [...mounts].sort((a, b) => a.containerPath.localeCompare(b.containerPath));
|
|
13752
|
+
return createHash7("sha256").update(JSON.stringify({ mounts: sorted2, image })).digest("hex").slice(0, 16);
|
|
13753
|
+
}
|
|
13754
|
+
function planContainers(cfg) {
|
|
13755
|
+
const byWorkspace = /* @__PURE__ */ new Map();
|
|
13756
|
+
const image = passengerImageRef(cfg);
|
|
13757
|
+
for (const route2 of cfg.routes) {
|
|
13758
|
+
if (!route2.enabled || !route2.hostPassengers || !route2.resolved?.workspaceId) continue;
|
|
13759
|
+
const workspaceId = route2.resolved.workspaceId;
|
|
13760
|
+
const mounts = byWorkspace.get(workspaceId) ?? /* @__PURE__ */ new Map();
|
|
13761
|
+
for (const target of passengerCheckoutTargets(route2, passengerMirrorArea(cfg.ship))) {
|
|
13762
|
+
mounts.set(target.name, { hostPath: target.dir, containerPath: `/workspace/${target.name}` });
|
|
13763
|
+
}
|
|
13764
|
+
byWorkspace.set(workspaceId, mounts);
|
|
13761
13765
|
}
|
|
13762
|
-
|
|
13763
|
-
|
|
13764
|
-
|
|
13765
|
-
|
|
13766
|
-
|
|
13767
|
-
|
|
13766
|
+
return [...byWorkspace.entries()].filter(([, mounts]) => mounts.size > 0).map(([workspaceId, mounts]) => {
|
|
13767
|
+
const mountList = [...mounts.values()];
|
|
13768
|
+
return {
|
|
13769
|
+
workspaceId,
|
|
13770
|
+
containerName: containerNameFor(workspaceId),
|
|
13771
|
+
port: portFor(workspaceId),
|
|
13772
|
+
image,
|
|
13773
|
+
mounts: mountList,
|
|
13774
|
+
mountsHash: mountsDigest(mountList, image)
|
|
13775
|
+
};
|
|
13776
|
+
});
|
|
13768
13777
|
}
|
|
13769
|
-
function
|
|
13770
|
-
const
|
|
13771
|
-
|
|
13772
|
-
|
|
13773
|
-
|
|
13778
|
+
function listPassengerContainers(exec = realExec) {
|
|
13779
|
+
const out = exec("docker", ["ps", "-a", "--filter", "name=crew-passenger-", "--format", "{{.Names}} {{.State}}"]);
|
|
13780
|
+
return out.split("\n").map((l) => l.trim()).filter(Boolean).map((line) => {
|
|
13781
|
+
const [name, state] = line.split(" ");
|
|
13782
|
+
return { name, running: state === "running" };
|
|
13783
|
+
});
|
|
13774
13784
|
}
|
|
13775
|
-
|
|
13776
|
-
var shipSandboxRef = () => ({ name: SHIP_SANDBOX_KEY, decl: { packages: [], setup: [] } });
|
|
13777
|
-
var sandboxStatePath = (stateDir) => join32(stateDir, "sandbox-images.json");
|
|
13778
|
-
function readSandboxState(stateDir) {
|
|
13785
|
+
function currentMountsHash(name, exec) {
|
|
13779
13786
|
try {
|
|
13780
|
-
const
|
|
13781
|
-
|
|
13787
|
+
const out = exec("docker", ["inspect", "--format", '{{ index .Config.Labels "crew.mounts.hash" }}', name]);
|
|
13788
|
+
const hash2 = out.trim();
|
|
13789
|
+
return hash2 || void 0;
|
|
13782
13790
|
} catch {
|
|
13783
|
-
return
|
|
13791
|
+
return void 0;
|
|
13784
13792
|
}
|
|
13785
13793
|
}
|
|
13786
|
-
function
|
|
13787
|
-
|
|
13788
|
-
|
|
13789
|
-
|
|
13790
|
-
|
|
13791
|
-
renameSync3(`${file}.tmp`, file);
|
|
13794
|
+
function stopContainer(name, exec = realExec) {
|
|
13795
|
+
try {
|
|
13796
|
+
exec("docker", ["rm", "-f", name]);
|
|
13797
|
+
} catch {
|
|
13798
|
+
}
|
|
13792
13799
|
}
|
|
13793
|
-
function
|
|
13794
|
-
|
|
13800
|
+
function startContainer(plan, tablationApiBaseUrl, sync, exec = realExec) {
|
|
13801
|
+
const args = [
|
|
13802
|
+
"run",
|
|
13803
|
+
"-d",
|
|
13804
|
+
"--name",
|
|
13805
|
+
plan.containerName,
|
|
13806
|
+
"--restart",
|
|
13807
|
+
"unless-stopped",
|
|
13808
|
+
"-p",
|
|
13809
|
+
`${plan.port}:8765`,
|
|
13810
|
+
"-e",
|
|
13811
|
+
`PASSENGER_MCP_WORKSPACE_ID=${plan.workspaceId}`,
|
|
13812
|
+
"-e",
|
|
13813
|
+
`TABLATION_API_BASE_URL=${tablationApiBaseUrl}`,
|
|
13814
|
+
"--label",
|
|
13815
|
+
`crew.mounts.hash=${plan.mountsHash}`
|
|
13816
|
+
];
|
|
13817
|
+
if (sync) {
|
|
13818
|
+
args.push(
|
|
13819
|
+
"--add-host",
|
|
13820
|
+
"host.docker.internal:host-gateway",
|
|
13821
|
+
"-e",
|
|
13822
|
+
`PASSENGER_SYNC_URL=http://${sync.host}:${sync.port}/sync`,
|
|
13823
|
+
"-e",
|
|
13824
|
+
`PASSENGER_SYNC_SECRET=${sync.secret}`,
|
|
13825
|
+
"-e",
|
|
13826
|
+
`PASSENGER_MCP_SECRET=${sync.secret}`
|
|
13827
|
+
);
|
|
13828
|
+
}
|
|
13829
|
+
for (const m of plan.mounts) args.push("-v", `${m.hostPath}:${m.containerPath}:ro`);
|
|
13830
|
+
args.push(plan.image);
|
|
13831
|
+
exec("docker", args);
|
|
13795
13832
|
}
|
|
13796
|
-
function
|
|
13797
|
-
|
|
13833
|
+
function syncPassengerContainers(cfg, tablationApiBaseUrl, exec = realExec, syncEndpoints = /* @__PURE__ */ new Map()) {
|
|
13834
|
+
const plans = planContainers(cfg);
|
|
13835
|
+
const plannedByName = new Map(plans.map((p) => [p.containerName, p]));
|
|
13836
|
+
const existing = listPassengerContainers(exec);
|
|
13837
|
+
const existingByName = new Map(existing.map((c) => [c.name, c]));
|
|
13838
|
+
const started = [];
|
|
13839
|
+
const recreated = [];
|
|
13840
|
+
const stopped = [];
|
|
13841
|
+
const ensured = /* @__PURE__ */ new Set();
|
|
13842
|
+
const start = (plan, sync) => {
|
|
13843
|
+
if (!ensured.has(plan.image)) {
|
|
13844
|
+
ensureImage(plan.image, exec);
|
|
13845
|
+
ensured.add(plan.image);
|
|
13846
|
+
}
|
|
13847
|
+
startContainer(plan, tablationApiBaseUrl, sync, exec);
|
|
13848
|
+
};
|
|
13849
|
+
for (const plan of plans) {
|
|
13850
|
+
const sync = syncEndpoints.get(plan.workspaceId);
|
|
13851
|
+
const current = existingByName.get(plan.containerName);
|
|
13852
|
+
if (!current) {
|
|
13853
|
+
start(plan, sync);
|
|
13854
|
+
started.push(plan.containerName);
|
|
13855
|
+
} else if (!current.running) {
|
|
13856
|
+
stopContainer(plan.containerName, exec);
|
|
13857
|
+
start(plan, sync);
|
|
13858
|
+
started.push(plan.containerName);
|
|
13859
|
+
} else if (currentMountsHash(plan.containerName, exec) !== plan.mountsHash) {
|
|
13860
|
+
stopContainer(plan.containerName, exec);
|
|
13861
|
+
start(plan, sync);
|
|
13862
|
+
recreated.push(plan.containerName);
|
|
13863
|
+
}
|
|
13864
|
+
}
|
|
13865
|
+
for (const { name } of existing) {
|
|
13866
|
+
if (!plannedByName.has(name)) {
|
|
13867
|
+
stopContainer(name, exec);
|
|
13868
|
+
stopped.push(name);
|
|
13869
|
+
}
|
|
13870
|
+
}
|
|
13871
|
+
return { started, recreated, stopped };
|
|
13798
13872
|
}
|
|
13799
|
-
function
|
|
13800
|
-
const
|
|
13801
|
-
const
|
|
13802
|
-
|
|
13803
|
-
|
|
13873
|
+
function passengerCheckoutSyncSpecs(cfg, workspaceId, onRefused) {
|
|
13874
|
+
const specs = [];
|
|
13875
|
+
for (const route2 of cfg.routes) {
|
|
13876
|
+
if (!route2.enabled || !route2.hostPassengers || !route2.resolved?.workspaceId) continue;
|
|
13877
|
+
if (workspaceId && route2.resolved.workspaceId !== workspaceId) continue;
|
|
13878
|
+
const routeWorkspaceId = route2.resolved.workspaceId;
|
|
13879
|
+
const mirrorArea = passengerMirrorArea(cfg.ship);
|
|
13880
|
+
const cache = mirrorArea ? cacheSettingsOf(cfg.ship.sandbox) : null;
|
|
13881
|
+
const ordinaryByName = new Map(reposOf(route2).map((t) => [t.name, t]));
|
|
13882
|
+
for (const target of passengerCheckoutTargets(route2, mirrorArea)) {
|
|
13883
|
+
const ordinary = ordinaryByName.get(target.name);
|
|
13884
|
+
const override = route2.repoOverrides[target.name];
|
|
13885
|
+
let refused = false;
|
|
13886
|
+
const declared = ordinary ? loadRepoConfigTolerant(ordinary.dir, (e) => {
|
|
13887
|
+
refused = true;
|
|
13888
|
+
onRefused?.(target.name, e);
|
|
13889
|
+
}) : null;
|
|
13890
|
+
if (refused) continue;
|
|
13891
|
+
const effective = resolveRepoConfig(
|
|
13892
|
+
declared,
|
|
13893
|
+
{ branch: { ...route2.branch, ...override?.branch } },
|
|
13894
|
+
ordinary?.dir ?? target.dir
|
|
13895
|
+
);
|
|
13896
|
+
specs.push({
|
|
13897
|
+
name: target.name,
|
|
13898
|
+
workspaceId: routeWorkspaceId,
|
|
13899
|
+
dir: target.dir,
|
|
13900
|
+
remote: target.remote,
|
|
13901
|
+
gitRemoteName: effective.branch.remote,
|
|
13902
|
+
base: effective.branch.base,
|
|
13903
|
+
originUrl: ordinary ? originUrlOf(ordinary.dir, effective.branch.remote) : null,
|
|
13904
|
+
cloneScheme: cfg.ship.cloneScheme,
|
|
13905
|
+
...target.forgeHost ? { forgeHost: target.forgeHost } : {},
|
|
13906
|
+
...cache ? { mirror: { cache } } : {}
|
|
13907
|
+
});
|
|
13908
|
+
}
|
|
13804
13909
|
}
|
|
13805
|
-
|
|
13806
|
-
if (current.tag !== plan.tag) return { status: "stale", detail: `running ${current.tag} (claude ${current.claude ?? "unknown"}), declaration now builds ${plan.tag} (claude ${plan.claude})` };
|
|
13807
|
-
return { status: "ok", detail: `${current.tag} built ${current.builtAt}, claude ${current.claude ?? "unknown"}` };
|
|
13910
|
+
return specs;
|
|
13808
13911
|
}
|
|
13809
|
-
|
|
13810
|
-
|
|
13811
|
-
|
|
13812
|
-
|
|
13813
|
-
|
|
13814
|
-
|
|
13815
|
-
|
|
13816
|
-
|
|
13817
|
-
|
|
13818
|
-
|
|
13819
|
-
child.on("error", (e) => done(127, `${e.message}
|
|
13820
|
-
`));
|
|
13821
|
-
child.on("close", (code) => done(code ?? 1));
|
|
13822
|
-
});
|
|
13823
|
-
var engineHasImage = (engine = "docker", exec = realExec2) => (tag) => {
|
|
13912
|
+
function syncAllPassengerCheckouts(cfg, onRefused) {
|
|
13913
|
+
return passengerCheckoutSyncSpecs(cfg, void 0, onRefused).filter((spec) => !spec.mirror).map((spec) => ({
|
|
13914
|
+
name: spec.name,
|
|
13915
|
+
workspaceId: spec.workspaceId,
|
|
13916
|
+
outcome: syncPassengerCheckout(spec.dir, spec.remote, spec.gitRemoteName, spec.base, { originUrl: spec.originUrl, scheme: spec.cloneScheme, host: spec.forgeHost })
|
|
13917
|
+
}));
|
|
13918
|
+
}
|
|
13919
|
+
|
|
13920
|
+
// src/sandbox-hooks.ts
|
|
13921
|
+
var imageHasBinary = (engine = "docker", exec = realExec) => (image, bin) => {
|
|
13824
13922
|
try {
|
|
13825
|
-
exec(engine, ["
|
|
13923
|
+
exec(engine, ["run", "--rm", "--entrypoint", "sh", image, "-c", `command -v ${bin}`], { timeoutMs: 6e4 });
|
|
13826
13924
|
return true;
|
|
13827
13925
|
} catch {
|
|
13828
13926
|
return false;
|
|
13829
13927
|
}
|
|
13830
13928
|
};
|
|
13831
|
-
|
|
13832
|
-
|
|
13833
|
-
|
|
13834
|
-
|
|
13835
|
-
|
|
13836
|
-
|
|
13837
|
-
var sandboxLogDir = (stateDir) => join32(stateDir, "sandbox-logs");
|
|
13838
|
-
async function buildSandboxImage(plan, deps) {
|
|
13839
|
-
const now = deps.now ?? (() => /* @__PURE__ */ new Date());
|
|
13840
|
-
const state = readSandboxState(deps.stateDir);
|
|
13841
|
-
const entry = state[plan.repo] ?? { tags: [] };
|
|
13842
|
-
if (entry.tags[0]?.tag === plan.tag && deps.hasImage(plan.tag)) {
|
|
13843
|
-
return { kind: "reused", tag: plan.tag };
|
|
13844
|
-
}
|
|
13845
|
-
const logDir = sandboxLogDir(deps.stateDir);
|
|
13846
|
-
mkdirSync19(logDir, { recursive: true });
|
|
13847
|
-
const logPath = join32(logDir, `${slug(plan.repo)}-${now().toISOString().replace(/[:.]/g, "-")}.log`);
|
|
13848
|
-
const builtLayers = [];
|
|
13849
|
-
for (const layer of plan.layers) {
|
|
13850
|
-
if (deps.hasImage(layer.tag)) continue;
|
|
13851
|
-
const ctx = join32(tmpdir3(), `crew-sandbox-${hash([layer.tag, process.pid, Date.now()])}`);
|
|
13852
|
-
mkdirSync19(ctx, { recursive: true });
|
|
13853
|
-
try {
|
|
13854
|
-
writeFileSync20(join32(ctx, "Dockerfile"), layer.dockerfile);
|
|
13855
|
-
for (const [name, content] of Object.entries(layer.files)) {
|
|
13856
|
-
mkdirSync19(dirname15(join32(ctx, name)), { recursive: true });
|
|
13857
|
-
writeFileSync20(join32(ctx, name), content);
|
|
13858
|
-
}
|
|
13859
|
-
if (layer.caBundleFile) writeFileSync20(join32(ctx, layer.caBundleFile), (deps.caBundle ?? readHostCaBundle)());
|
|
13860
|
-
const code = await deps.run(["build", "--tag", layer.tag, "--file", join32(ctx, "Dockerfile"), ctx], logPath);
|
|
13861
|
-
if (code !== 0) {
|
|
13862
|
-
state[plan.repo] = { ...entry, failure: { tag: plan.tag, at: now().toISOString(), logPath } };
|
|
13863
|
-
writeSandboxState(deps.stateDir, state);
|
|
13864
|
-
return { kind: "failed", tag: plan.tag, logPath, layer: layer.name };
|
|
13865
|
-
}
|
|
13866
|
-
builtLayers.push(layer.name);
|
|
13867
|
-
} finally {
|
|
13868
|
-
rmSync15(ctx, { recursive: true, force: true });
|
|
13869
|
-
}
|
|
13870
|
-
}
|
|
13871
|
-
const tags = [{ tag: plan.tag, builtAt: now().toISOString(), claude: plan.claude }, ...entry.tags.filter((t) => t.tag !== plan.tag)];
|
|
13872
|
-
const dropped = tags.slice(KEEP_TAGS);
|
|
13873
|
-
state[plan.repo] = { tags: tags.slice(0, KEEP_TAGS) };
|
|
13874
|
-
writeSandboxState(deps.stateDir, state);
|
|
13875
|
-
for (const t of dropped) deps.removeImage(t.tag);
|
|
13876
|
-
return { kind: "built", tag: plan.tag, builtLayers };
|
|
13877
|
-
}
|
|
13878
|
-
var sandboxFailedKey = (repo) => `sandbox_build_failed:${repo}`;
|
|
13879
|
-
function sandboxFailedItem(repo, tag, layer, logPath, nowIso = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
13880
|
-
return {
|
|
13881
|
-
kind: "sandbox_build_failed",
|
|
13882
|
-
key: sandboxFailedKey(repo),
|
|
13883
|
-
since: nowIso,
|
|
13884
|
-
message: `${repo}: sandbox image ${tag} failed to build at the ${layer} layer (log: ${logPath}); sandboxes keep running the previous image. Retries automatically after the declaration changes or in an hour; \`crew sandbox build\` forces it`
|
|
13929
|
+
function sandboxHookGaps(o) {
|
|
13930
|
+
if (!o.image) return [];
|
|
13931
|
+
const seen = /* @__PURE__ */ new Map();
|
|
13932
|
+
const has = (bin) => {
|
|
13933
|
+
if (!seen.has(bin)) seen.set(bin, o.hasBinary(o.image, bin));
|
|
13934
|
+
return seen.get(bin);
|
|
13885
13935
|
};
|
|
13886
|
-
|
|
13887
|
-
|
|
13888
|
-
|
|
13889
|
-
|
|
13890
|
-
|
|
13891
|
-
const
|
|
13892
|
-
|
|
13893
|
-
|
|
13894
|
-
|
|
13895
|
-
|
|
13896
|
-
|
|
13897
|
-
|
|
13898
|
-
deps.log(`sandbox image for ${r.name}: building ${plan.tag}`);
|
|
13899
|
-
const out = await buildSandboxImage(plan, deps);
|
|
13900
|
-
if (out.kind === "failed") {
|
|
13901
|
-
deps.raise(sandboxFailedItem(r.name, out.tag, out.layer, out.logPath));
|
|
13902
|
-
deps.log(`sandbox image for ${r.name}: build failed at the ${out.layer} layer, log ${out.logPath}`);
|
|
13903
|
-
} else {
|
|
13904
|
-
deps.clear(sandboxFailedKey(r.name));
|
|
13905
|
-
deps.log(`sandbox image for ${r.name}: ${out.kind === "built" ? `built ${out.tag}` : `${out.tag} already built`}`);
|
|
13906
|
-
}
|
|
13907
|
-
return r.name;
|
|
13936
|
+
const gaps = [];
|
|
13937
|
+
for (const hook2 of ["setup", "test", "build", "deploy"]) {
|
|
13938
|
+
const script = o.hooks[hook2];
|
|
13939
|
+
const command2 = script ? hookCommand(script) : null;
|
|
13940
|
+
if (!command2 || has(command2)) continue;
|
|
13941
|
+
const remedy = o.declares ? `add the package that provides \`${command2}\` to sandbox.packages or sandbox.setup in ${o.repo}'s .crew.yaml, then \`crew sandbox build ${o.repo}\`` : `${o.repo} declares no sandbox: section, so it runs in the ship's crew image; add a sandbox: section to its .crew.yaml providing \`${command2}\``;
|
|
13942
|
+
gaps.push({
|
|
13943
|
+
hook: hook2,
|
|
13944
|
+
command: command2,
|
|
13945
|
+
remedy,
|
|
13946
|
+
message: `${o.route}/${o.repo}: the ${hook2} hook runs \`${command2}\`, which is not in its sandbox image ${o.image} \u2014 ${remedy}`
|
|
13947
|
+
});
|
|
13908
13948
|
}
|
|
13909
|
-
return
|
|
13949
|
+
return gaps;
|
|
13910
13950
|
}
|
|
13911
13951
|
|
|
13912
13952
|
// src/doctor-checks.ts
|
|
@@ -16106,7 +16146,7 @@ function readAllPersistedWorkspaceIds(stateDir) {
|
|
|
16106
16146
|
}
|
|
16107
16147
|
var TUNNEL_REJECTED_KEY = "tunnel_rejected";
|
|
16108
16148
|
function tunnelRejectedMessage(workspaceId, quickExits) {
|
|
16109
|
-
return `the relay tunnel for workspace ${workspaceId} exited before settling on ${quickExits} consecutive cycles, which is how a refused claim looks (the relay logs "slug already owned by another workspace/ssh key") \u2014 rotate the slug with \`crew rotate-passenger-url\` or check the relay journal
|
|
16149
|
+
return `the relay tunnel for workspace ${workspaceId} exited before settling on ${quickExits} consecutive cycles, which is how a refused claim looks (the relay logs "slug already owned by another workspace/ssh key") \u2014 rotate the slug with \`crew rotate-passenger-url\` or check the relay journal. If the relay logged no rejection, a Linux passengers unit without KillMode=process kills the tunnel when the sync exits (CREW-2994): run \`crew install\`, and see \`crew doctor\``;
|
|
16110
16150
|
}
|
|
16111
16151
|
function rejectedTunnels(stateDir) {
|
|
16112
16152
|
const out = [];
|
|
@@ -20015,6 +20055,9 @@ function mirrorOutcome(m) {
|
|
|
20015
20055
|
function lacksCheckout(ship, dir) {
|
|
20016
20056
|
return ship.runner === "sandbox" && !existsSync39(dir) && !remoteOf(dir);
|
|
20017
20057
|
}
|
|
20058
|
+
function skipsHostCheckout(ship) {
|
|
20059
|
+
return ship.runner === "sandbox";
|
|
20060
|
+
}
|
|
20018
20061
|
function mirrorRepoOfTarget(t) {
|
|
20019
20062
|
return mirrorRepoOf({ remote: t.remote, forgeHost: t.forgeHost });
|
|
20020
20063
|
}
|
|
@@ -24484,7 +24527,7 @@ async function runRoleAgentLocked(role, decision, ctx, hooks, held) {
|
|
|
24484
24527
|
const target = repoTargetFor(route2, result.ticket.repo_id);
|
|
24485
24528
|
ticketRepo = target?.name;
|
|
24486
24529
|
try {
|
|
24487
|
-
if (target && ensureRepoCheckout(target.dir, target.remote, { scheme: ship.cloneScheme, host: target.forgeHost })) {
|
|
24530
|
+
if (target && !skipsHostCheckout(ship) && ensureRepoCheckout(target.dir, target.remote, { scheme: ship.cloneScheme, host: target.forgeHost })) {
|
|
24488
24531
|
emit.emit(`cloned ${target.name} into ${target.dir}`, { step: "select", role });
|
|
24489
24532
|
}
|
|
24490
24533
|
} catch (e) {
|
|
@@ -26974,7 +27017,7 @@ ${changed2.map((c) => ` - ${c}
|
|
|
26974
27017
|
async function releasePhase(c, target, opts = {}) {
|
|
26975
27018
|
const scope = releaseLockScope(c.route, target.name);
|
|
26976
27019
|
const remit = emit.forRoute(c.route);
|
|
26977
|
-
if (
|
|
27020
|
+
if (cfg.ship.runner === "sandbox") {
|
|
26978
27021
|
let mode = null;
|
|
26979
27022
|
let contract = null;
|
|
26980
27023
|
const settings = cacheSettingsOf(cfg.ship.sandbox);
|
|
@@ -26990,9 +27033,11 @@ ${changed2.map((c) => ` - ${c}
|
|
|
26990
27033
|
if (releasesFromSandbox(mode) && settings && mirror && contract) {
|
|
26991
27034
|
return releaseFromSandbox(c, target, contract, mirror, opts);
|
|
26992
27035
|
}
|
|
26993
|
-
|
|
26994
|
-
|
|
26995
|
-
|
|
27036
|
+
if (lacksCheckout(cfg.ship, target.dir)) {
|
|
27037
|
+
const note = noCheckoutReleaseNote(target.name, mode);
|
|
27038
|
+
if (firstReport(`${scope0(c, target)}:release`)) remit.emit(note, { step: "release" });
|
|
27039
|
+
return { scope: releaseLockScope(c.route, target.name), tests: "skipped", outcome: "skipped", detail: note };
|
|
27040
|
+
}
|
|
26996
27041
|
}
|
|
26997
27042
|
const relLock = dryRun ? void 0 : state.acquire(`release-${scope}`);
|
|
26998
27043
|
if (relLock && !relLock.ok) {
|
|
@@ -27317,7 +27362,7 @@ ${changed2.map((c) => ` - ${c}
|
|
|
27317
27362
|
}
|
|
27318
27363
|
return placement;
|
|
27319
27364
|
};
|
|
27320
|
-
const news = describeRelease(outcome, scope);
|
|
27365
|
+
const news = describeRelease(outcome, scope, { ship: cfg.ship.name, runner: cfg.ship.runner });
|
|
27321
27366
|
if (news) {
|
|
27322
27367
|
const notified = await notify(c, cfg.ship, news, remit, dryRun);
|
|
27323
27368
|
if (!notified && news.level === "fail") {
|
|
@@ -27655,7 +27700,7 @@ ${cu.tail.trimEnd()}
|
|
|
27655
27700
|
const target = repoTargetFor(w.route, result.ticket.repo_id);
|
|
27656
27701
|
fleetTicketRepo = target?.name;
|
|
27657
27702
|
try {
|
|
27658
|
-
if (target && ensureRepoCheckout(target.dir, target.remote, { scheme: cfg.ship.cloneScheme, host: target.forgeHost })) {
|
|
27703
|
+
if (target && !skipsHostCheckout(cfg.ship) && ensureRepoCheckout(target.dir, target.remote, { scheme: cfg.ship.cloneScheme, host: target.forgeHost })) {
|
|
27659
27704
|
wemit.emit(`cloned ${target.name} into ${target.dir}`, { step: "select", role: w.role });
|
|
27660
27705
|
}
|
|
27661
27706
|
} catch (e) {
|
|
@@ -27873,7 +27918,7 @@ ${cu.tail.trimEnd()}
|
|
|
27873
27918
|
const target = repoTargetFor(route2, result.ticket.repo_id);
|
|
27874
27919
|
ticketRepo = target?.name;
|
|
27875
27920
|
try {
|
|
27876
|
-
if (target && ensureRepoCheckout(target.dir, target.remote, { scheme: cfg.ship.cloneScheme, host: target.forgeHost })) {
|
|
27921
|
+
if (target && !skipsHostCheckout(cfg.ship) && ensureRepoCheckout(target.dir, target.remote, { scheme: cfg.ship.cloneScheme, host: target.forgeHost })) {
|
|
27877
27922
|
emit.emit(`cloned ${target.name} into ${target.dir}`, { step: "select", role: current });
|
|
27878
27923
|
}
|
|
27879
27924
|
} catch (e) {
|
|
@@ -31306,6 +31351,15 @@ watermark: ${state.watermark()}
|
|
|
31306
31351
|
base: doctorBaseReport(r, r.config.branch.base, baseHealth),
|
|
31307
31352
|
hooks: r.config.hooks,
|
|
31308
31353
|
onPath: (cmd) => !!findOnPath(cmd, doctorSchedulerPath),
|
|
31354
|
+
// CREW-3007: on a sandbox ship the hooks run in the image, so the host PATH is not asked.
|
|
31355
|
+
sandboxGaps: cfg.ship.runner === "sandbox" ? sandboxHookGaps({
|
|
31356
|
+
route: c.route,
|
|
31357
|
+
repo: r.name,
|
|
31358
|
+
hooks: r.config.hooks,
|
|
31359
|
+
declares: Boolean(r.config.sandbox),
|
|
31360
|
+
image: sandboxImageForRun(readSandboxState(cfg.ship.stateDir), r.name, Boolean(r.config.sandbox)),
|
|
31361
|
+
hasBinary: imageHasBinary()
|
|
31362
|
+
}) : void 0,
|
|
31309
31363
|
mapFile: mapFilePath(r.config.hooks.map) ? inspectMapFile(r.dir, mapFilePath(r.config.hooks.map)) : void 0,
|
|
31310
31364
|
intelSyntax: r.config.hooks.intel && !intelFlavor(r.config.hooks.intel) ? checkHookSyntax(r.config.hooks.intel, r.config.shell) : void 0,
|
|
31311
31365
|
intelFlavor: intelFlavor(r.config.hooks.intel) ? { name: intelFlavor(r.config.hooks.intel), missing: [
|
|
@@ -31414,6 +31468,21 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
31414
31468
|
);
|
|
31415
31469
|
}
|
|
31416
31470
|
}
|
|
31471
|
+
if (host === "linux" && detectSystemd() && cfg.ship.relayHost) {
|
|
31472
|
+
const pPlan = planInstall(cfg.ship, CREW_HOME, host, true, "passengers", installContext());
|
|
31473
|
+
const keeps = unitAbandonsAgents(pPlan, (p) => {
|
|
31474
|
+
try {
|
|
31475
|
+
return readFileSync47(p, "utf8");
|
|
31476
|
+
} catch {
|
|
31477
|
+
return null;
|
|
31478
|
+
}
|
|
31479
|
+
});
|
|
31480
|
+
if (keeps === false) {
|
|
31481
|
+
process.stdout.write(
|
|
31482
|
+
"passengers unit: WARN the installed unit lacks KillMode=process, so systemd kills the relay tunnel each time the sync exits (tunnel never reaches connected); run `crew install`\n"
|
|
31483
|
+
);
|
|
31484
|
+
}
|
|
31485
|
+
}
|
|
31417
31486
|
if (host === "linux" && detectSystemd()) {
|
|
31418
31487
|
const ctl = planDaemonControl(CREW_HOME, host, true);
|
|
31419
31488
|
const unitPlan = planInstall(cfg.ship, CREW_HOME, host, true, "run", installContext());
|
|
@@ -31766,11 +31835,30 @@ crew manifest: ${seats2.length ? seats2.map((c) => c.name).join(", ") : "non
|
|
|
31766
31835
|
continue;
|
|
31767
31836
|
}
|
|
31768
31837
|
for (const r of repos) {
|
|
31838
|
+
const gaps = cfg.ship.runner === "sandbox" ? sandboxHookGaps({
|
|
31839
|
+
route: c.route,
|
|
31840
|
+
repo: r.name,
|
|
31841
|
+
hooks: r.config.hooks,
|
|
31842
|
+
declares: Boolean(r.config.sandbox),
|
|
31843
|
+
image: sandboxImageForRun(readSandboxState(cfg.ship.stateDir), r.name, Boolean(r.config.sandbox)),
|
|
31844
|
+
hasBinary: imageHasBinary()
|
|
31845
|
+
}) : [];
|
|
31769
31846
|
for (const name of ["setup", "test", "build", "deploy"]) {
|
|
31770
31847
|
const script = r.config.hooks[name];
|
|
31771
31848
|
const cmd = script ? hookCommand(script) : null;
|
|
31772
31849
|
if (!cmd) continue;
|
|
31773
31850
|
const key = `hook_missing:${c.route}/${r.name}/${name}`;
|
|
31851
|
+
if (cfg.ship.runner === "sandbox") {
|
|
31852
|
+
const gap = gaps.find((g) => g.hook === name);
|
|
31853
|
+
if (!gap) {
|
|
31854
|
+
clearShipAttention(state, key);
|
|
31855
|
+
continue;
|
|
31856
|
+
}
|
|
31857
|
+
process.stdout.write(`hook ${c.route}/${r.name} ${name}: \`${cmd}\` NOT FOUND in the sandbox image
|
|
31858
|
+
`);
|
|
31859
|
+
await raiseShipAttention({ state, emit, route: c, ship: cfg.ship }, { kind: "hook_missing", key, message: gap.message, since: (/* @__PURE__ */ new Date()).toISOString() });
|
|
31860
|
+
continue;
|
|
31861
|
+
}
|
|
31774
31862
|
if (findOnPath(cmd, schedulerPath)) {
|
|
31775
31863
|
clearShipAttention(state, key);
|
|
31776
31864
|
continue;
|