@north-light/api 0.3.727 → 0.3.729
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/core/environment-starter-script.d.ts +1 -1
- package/dist/core/environment-starter-script.js +3 -3
- package/dist/core/runtime/reopen.js +5 -0
- package/dist/core/runtime/revive.d.ts +2 -1
- package/dist/core/runtime/revive.js +21 -1
- package/dist/core/runtime/runner/blaxel/image-build.js +2 -7
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const STARTER_SETUP_SCRIPT = "#!/usr/bin/env bash\n# Setup script for a crtr cloud environment.\n#\n# How it runs\n# - Once per image build, as root, in /work, on Alpine Linux (use apk, not apt). Every sandbox of the profile starts from the result.\n# - Your repositories are already checked out at /work/<repo name> before this runs.\n# - The sandbox user is \"crtr\" (home /home/crtr). Files you create for it must be chowned to it.\n# - Already done for you: git, gh, curl, ripgrep, Node 24, pnpm.
|
|
1
|
+
export declare const STARTER_SETUP_SCRIPT = "#!/usr/bin/env bash\n# Setup script for a crtr cloud environment.\n#\n# How it runs\n# - Once per image build, as root, in /work, on Alpine Linux (use apk, not apt). Every sandbox of the profile starts from the result.\n# - Your repositories are already checked out at /work/<repo name> before this runs.\n# - The sandbox user is \"crtr\" (home /home/crtr). Files you create for it must be chowned to it.\n# - Already done for you: git, gh, curl, ripgrep, Node 24, pnpm. Packages are not pre-installed: run `pnpm install` in a sandbox,\n# or install at build time below.\n# - Output goes to /work/.crtr/setup.log in the image. If this script exits non-zero, sandboxes refuse to start and point at that log.\n# - The image keeps /work, /home/crtr, /usr, /etc and /lib. Anything written to /root or /tmp is lost.\n#\n# Secrets (API keys, database URLs) do not belong here: anything written by this script is baked into the image. Store them on the profile\n# instead and every sandbox gets them as environment variables:\n# printf '%s' \"<value>\" | crtr profile env set <profile> --name OPENAI_API_KEY\n#\n# Apply this file with:\n# crtr profile environment set --profile <profile> --setup-script-file ./setup.sh\n# then watch the build with `crtr profile environment show --profile <profile>` (ready when image_revision equals recipe_revision).\n#\n# Uncomment the sections you need. Delete the rest.\n\nset -euo pipefail\n\n# \u2500\u2500 1. System packages \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n# Alpine package names: https://pkgs.alpinelinux.org/packages\n# apk add --no-cache build-base python3 # native npm modules (node-gyp)\n# apk add --no-cache jq sqlite # command-line tools your agents use\n# apk add --no-cache chromium # headless browser tests\n\n# \u2500\u2500 2. A local Postgres \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n# Creates a database cluster owned by crtr. Section 5 starts it on the agent's first shell command.\n# apk add --no-cache postgresql postgresql-contrib\n# mkdir -p /run/postgresql && chown crtr /run/postgresql\n# su crtr -c 'initdb -D /home/crtr/pg -U postgres --auth=trust'\n\n# \u2500\u2500 3. App dependencies \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n# To install a repository's packages at build time:\n# (cd /work/<repo name> && npm ci)\n# (cd /work/<repo name> && pnpm install --frozen-lockfile)\n# Each full install can take 0.5-1.5 GB of the sandbox disk. Install only the repositories agents work in most.\n\n# \u2500\u2500 4. Global CLIs \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n# npm install -g typescript tsx\n# curl -fsSL https://example.com/install.sh | sh\n\n# \u2500\u2500 5. Start services on the agent's first command \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n# The agent's shell is non-interactive bash, which runs the file named by $BASH_ENV before each command. Write a start script here, then\n# set BASH_ENV on the profile: printf '%s' /home/crtr/.services-up.sh | crtr profile env set <profile> --name BASH_ENV\n# cat > /home/crtr/.services-up.sh <<'UP'\n# pg_ctl -D /home/crtr/pg status >/dev/null 2>&1 || pg_ctl -D /home/crtr/pg -o \"-k /tmp -h localhost\" -l /tmp/pg.log -w start >/dev/null 2>&1 || true\n# UP\n# chown crtr /home/crtr/.services-up.sh\n\n# \u2500\u2500 6. Seed files and config \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n# cp /work/<repo name>/.env.example /work/<repo name>/.env # placeholders only; real values come from `crtr profile env`\n# chown -R crtr /work/<repo name>\n";
|
|
@@ -8,8 +8,8 @@ export const STARTER_SETUP_SCRIPT = `#!/usr/bin/env bash
|
|
|
8
8
|
# - Once per image build, as root, in /work, on Alpine Linux (use apk, not apt). Every sandbox of the profile starts from the result.
|
|
9
9
|
# - Your repositories are already checked out at /work/<repo name> before this runs.
|
|
10
10
|
# - The sandbox user is "crtr" (home /home/crtr). Files you create for it must be chowned to it.
|
|
11
|
-
# - Already done for you: git, gh, curl, ripgrep, Node 24, pnpm.
|
|
12
|
-
#
|
|
11
|
+
# - Already done for you: git, gh, curl, ripgrep, Node 24, pnpm. Packages are not pre-installed: run \`pnpm install\` in a sandbox,
|
|
12
|
+
# or install at build time below.
|
|
13
13
|
# - Output goes to /work/.crtr/setup.log in the image. If this script exits non-zero, sandboxes refuse to start and point at that log.
|
|
14
14
|
# - The image keeps /work, /home/crtr, /usr, /etc and /lib. Anything written to /root or /tmp is lost.
|
|
15
15
|
#
|
|
@@ -38,7 +38,7 @@ set -euo pipefail
|
|
|
38
38
|
# su crtr -c 'initdb -D /home/crtr/pg -U postgres --auth=trust'
|
|
39
39
|
|
|
40
40
|
# ── 3. App dependencies ──────────────────────────────────────────────────────────────────────────────
|
|
41
|
-
#
|
|
41
|
+
# To install a repository's packages at build time:
|
|
42
42
|
# (cd /work/<repo name> && npm ci)
|
|
43
43
|
# (cd /work/<repo name> && pnpm install --frozen-lockfile)
|
|
44
44
|
# Each full install can take 0.5-1.5 GB of the sandbox disk. Install only the repositories agents work in most.
|
|
@@ -41,6 +41,7 @@ import { clearFinalReportIfMatches, getFinalReport, getNode, updateNode } from '
|
|
|
41
41
|
import { subscribersOf } from '../canvas/tree.js';
|
|
42
42
|
import { InputError } from '../io.js';
|
|
43
43
|
import { transition } from './lifecycle.js';
|
|
44
|
+
import { assertCheckoutNotRemoved } from './revive.js';
|
|
44
45
|
import { noticeChangedWhileDone } from './ledger.js';
|
|
45
46
|
async function currentFinalReport(nodeId) {
|
|
46
47
|
return await getFinalReport(nodeId);
|
|
@@ -123,6 +124,10 @@ async function isManagerOf(callerNodeId, nodeId) {
|
|
|
123
124
|
* Writing lifecycle first leaves a failed latch CAS with the canonical-final
|
|
124
125
|
* pointer intact. Both writes finish before either delivery channel begins. */
|
|
125
126
|
export async function commitReopenResident(nodeId, expectedFinalReport, callerNodeId) {
|
|
127
|
+
// A node whose managed checkout was removed can never run again: refuse before any reopen write.
|
|
128
|
+
const before = await getNode(nodeId);
|
|
129
|
+
if (before !== null)
|
|
130
|
+
assertCheckoutNotRemoved(nodeId, before);
|
|
126
131
|
const finalReport = await currentFinalReport(nodeId);
|
|
127
132
|
if (!(await isManagerOf(callerNodeId, nodeId)))
|
|
128
133
|
await updateNode(nodeId, { lifecycle: 'resident' });
|
|
@@ -111,7 +111,8 @@ export declare function assertRecordedCwdExists(nodeId: string, meta: NodeMeta):
|
|
|
111
111
|
blaxelEnvironment: string | null;
|
|
112
112
|
remoteMachine: boolean;
|
|
113
113
|
}>;
|
|
114
|
-
/** Cleanup deleted this node's managed checkout and its branch, and nothing rebuilds them
|
|
114
|
+
/** Cleanup deleted this node's managed checkout and its branch, and nothing rebuilds them; its cwd now names the shared repository
|
|
115
|
+
* root, so a launch would edit the base checkout. Refuse on any host, before a caller changes state. */
|
|
115
116
|
export declare function assertCheckoutNotRemoved(nodeId: string, meta: NodeMeta): void;
|
|
116
117
|
/** The `node:start` lifecycle hooks for a node coming up: a launch, or a cycle started in a running process. */
|
|
117
118
|
export declare function runNodeStartHooks(nodeId: string, meta: NodeMeta, isBirth: boolean): Promise<void>;
|
|
@@ -228,6 +228,10 @@ async function decideReviveAsCaller(nodeId, opts, wakeParked) {
|
|
|
228
228
|
if (meta.final_report !== null) {
|
|
229
229
|
throw new Error(`reviveNode: refusing to revive ${nodeId} — its finalization latch is set (final_report=${meta.final_report}). A final landed between the caller's reopen-gate check and this revive; re-run with --reopen if this retask is still wanted.`);
|
|
230
230
|
}
|
|
231
|
+
// A removed managed checkout refuses every start, before the start checks so its reason is the one recorded. An attach that only
|
|
232
|
+
// looks at a parked node starts nothing; cleanup completes only after the engine exits, so no live broker is refused.
|
|
233
|
+
if (wakeParked || !(meta.lifecycle === 'resident' && isParked(meta)))
|
|
234
|
+
await refuseRemovedCheckout(nodeId, meta);
|
|
231
235
|
assertProfileActive(meta.profile_id);
|
|
232
236
|
// An unsandboxed machine runs terminal agents only: refuse before any lifecycle hook or other prelaunch executable runs as the app.
|
|
233
237
|
assertGranteeRunsHere(meta.grantee);
|
|
@@ -368,7 +372,8 @@ export async function assertRecordedCwdExists(nodeId, meta) {
|
|
|
368
372
|
}
|
|
369
373
|
return { blaxelEnvironment, remoteMachine };
|
|
370
374
|
}
|
|
371
|
-
/** Cleanup deleted this node's managed checkout and its branch, and nothing rebuilds them
|
|
375
|
+
/** Cleanup deleted this node's managed checkout and its branch, and nothing rebuilds them; its cwd now names the shared repository
|
|
376
|
+
* root, so a launch would edit the base checkout. Refuse on any host, before a caller changes state. */
|
|
372
377
|
export function assertCheckoutNotRemoved(nodeId, meta) {
|
|
373
378
|
const worktree = meta.managed_worktree;
|
|
374
379
|
if (worktree?.state !== 'closed' || worktree.cleanup !== 'complete')
|
|
@@ -379,6 +384,21 @@ export function assertCheckoutNotRemoved(nodeId, meta) {
|
|
|
379
384
|
next: `Start a new node in ${worktree.repo_root}.`,
|
|
380
385
|
});
|
|
381
386
|
}
|
|
387
|
+
/** Every start path goes through reviveNode, so this is where a removed checkout is refused. A wake that has no caller to report
|
|
388
|
+
* to (a tick reopen of a parked resident, a stranded or idle-released launch) leaves the row live; it is settled dead with the
|
|
389
|
+
* reason as its outcome, which `crtr node inspect show` prints, so the tick does not select it again. */
|
|
390
|
+
async function refuseRemovedCheckout(nodeId, meta) {
|
|
391
|
+
try {
|
|
392
|
+
assertCheckoutNotRemoved(nodeId, meta);
|
|
393
|
+
}
|
|
394
|
+
catch (error) {
|
|
395
|
+
if (meta.status === 'active' || meta.status === 'idle') {
|
|
396
|
+
await transition(nodeId, 'crash', { reason: 'launch_failed', outcome: { detail: { schema: 'crtr.node-outcome-detail/v1', message: error.message } } });
|
|
397
|
+
await clearFrozen(nodeId);
|
|
398
|
+
}
|
|
399
|
+
throw error;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
382
402
|
/** The `node:start` lifecycle hooks for a node coming up: a launch, or a cycle started in a running process. */
|
|
383
403
|
export async function runNodeStartHooks(nodeId, meta, isBirth) {
|
|
384
404
|
const lifecycleHooks = discoverLifecycleHookRegistry(meta.cwd, meta.profile_id).plans.get('node:start') ?? [];
|
|
@@ -72,13 +72,8 @@ export function recipeDockerfile(recipe, revision, packagesToken = false) {
|
|
|
72
72
|
out.push(`COPY ${SETUP_SCRIPT_FILE} /tmp/${SETUP_SCRIPT_FILE}`);
|
|
73
73
|
out.push('WORKDIR /work');
|
|
74
74
|
out.push(`RUN ${writeRunUserNpmrc()}`);
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
// setup script's `su crtr -c 'pnpm install'` can write them. No step here may `chown -R` the trees: each one rewrites every file into a new layer, and the
|
|
78
|
-
// doubled multi-GB image kept Blaxel's build at BUILDING past the timeout. The final stage's `COPY --chown` sets ownership once.
|
|
79
|
-
for (const repo of recipe.repositories) {
|
|
80
|
-
out.push(`RUN if [ -f /work/${repo.name}/pnpm-lock.yaml ]; then su ${RUN_USER} -c 'cd /work/${repo.name} && HOME=/home/${RUN_USER} pnpm fetch' >> ${SETUP_LOG_FILE} 2>&1 || echo 'pnpm fetch ${repo.name} failed' >> ${SETUP_LOG_FILE}; fi`);
|
|
81
|
-
}
|
|
75
|
+
// No step pre-downloads pnpm packages: a multi-GB store (nine repositories) kept Blaxel's build at BUILDING past the timeout, so `pnpm install` in a sandbox downloads.
|
|
76
|
+
// No step here may `chown -R` the trees either: each one rewrites every file into a new layer. The final stage's `COPY --chown` sets ownership once.
|
|
82
77
|
for (const source of packages)
|
|
83
78
|
out.push(guarded(`pi install ${source}`, `HOME=/var/lib/crtr PI_CODING_AGENT_DIR=${RECIPE_PI_AGENT_DIR} pi install ${shellQuote(source)}`));
|
|
84
79
|
// Blaxel never reports a failed Docker step: the image stays BUILDING until the timeout, and its build log is not readable. So a failing script must not fail
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.729",
|
|
4
4
|
"description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/api/index.js",
|