@north-light/cli 0.3.683 → 0.3.684
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/runtime/runner/blaxel/image-build.d.ts +2 -0
- package/dist/core/runtime/runner/blaxel/image-build.js +6 -6
- package/package.json +3 -3
- package/packages/crouter-api/dist/core/runtime/runner/blaxel/image-build.js +5 -2
- package/packages/crouter-api/package.json +1 -1
- package/packages/crouter-identity/package.json +1 -1
- package/packages/crouter-plugin/package.json +3 -3
- package/runtime.lock.json +14 -14
|
@@ -83,6 +83,8 @@ interface ImageDoc {
|
|
|
83
83
|
export declare function getImage(config: BlaxelConfig, name: string): Promise<ImageDoc | null>;
|
|
84
84
|
/** Deleting an absent image is not an error; an image a sandbox still uses is refused by Blaxel. */
|
|
85
85
|
export declare function deleteImage(config: BlaxelConfig, name: string): Promise<void>;
|
|
86
|
+
/** How long a build may stay BUILDING: the crouter-cloud image takes ~30-33 min on Blaxel. */
|
|
87
|
+
export declare const BUILD_TIMEOUT_MS: number;
|
|
86
88
|
/** Uploads `dir` (Dockerfile and context) as a build of sandbox image `name` and waits for it. A failed build throws with Blaxel's last event message. */
|
|
87
89
|
export declare function buildImage(config: BlaxelConfig, name: string, dir: string, options?: BuildImageOptions): Promise<BuiltImage>;
|
|
88
90
|
/** The image name of an environment: every revision is a new tag of it. */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
1
|
+
var K=Object.defineProperty;var c=(t,r)=>K(t,"name",{value:r,configurable:!0});import{spawn as j}from"node:child_process";import{constants as A,lstatSync as q,mkdirSync as z,readFileSync as H,readdirSync as J,readlinkSync as W,rmSync as X,writeFileSync as b}from"node:fs";import{join as E,relative as V}from"node:path";import{crc32 as Z,deflateRawSync as Q}from"node:zlib";import{BlaxelApiError as tt}from"./client.js";const et="public.ecr.aws/docker/library/node:24-alpine",rt="ghcr.io/blaxel-ai/sandbox:latest",f="crtr",D="/var/lib/crtr/recipe-pi-agent",nt="blaxel.toml",st=`[build]
|
|
2
2
|
slim = false
|
|
3
|
-
`,
|
|
4
|
-
`).map(r=>r.trim()).filter(r=>r!==""),"lines"),I=c((t,r)=>`RUN { ${r}; } >> ${
|
|
5
|
-
`)}c(
|
|
6
|
-
`,{mode:384}),t.recipe.setup_script!==null&&t.recipe.setup_script.trim()!==""&&b(E(t.dir,
|
|
3
|
+
`,ot="1.1.0",U="recipe-setup.sh",L="repos",B="/work/.crtr/setup.log",P="/work/.crtr/setup-failed",C=c(t=>`'${t.replace(/'/g,"'\\''")}'`,"shellQuote"),it=c(t=>(t??"").split(`
|
|
4
|
+
`).map(r=>r.trim()).filter(r=>r!==""),"lines"),I=c((t,r)=>`RUN { ${r}; } >> ${B} 2>&1 || echo ${C(t)} "exited $?" >> ${P}`,"guarded");function at(t,r,i=!1){const o=it(t.pi_packages),a=t.setup_script!==null&&t.setup_script.trim()!=="",n=[`FROM ${et}`,"RUN apk add --no-cache bash git curl ripgrep",`COPY --from=${rt} /sandbox-api /usr/local/bin/sandbox-api`,`RUN adduser -D -h /home/${f} -s /bin/sh ${f} && mkdir -p /work/.crtr ${D} && chown -R ${f} /work /var/lib/crtr`],e=[`${n[0]} AS build`,...i?["ARG NODE_AUTH_TOKEN"]:[],...n.slice(1),`RUN rm -f ${P} ${B}`,I("npm install -g pnpm","npm install -g pnpm && mkdir -p /var/lib/postgresql")];t.repositories.length>0&&e.push(`COPY --chown=${f} ${L}/ /work/`),o.length>0&&e.push(I("npm install pi",`npm install -g @earendil-works/pi-coding-agent@${ot}`)),a&&e.push(`COPY ${U} /tmp/${U}`),e.push("WORKDIR /work");for(const s of o)e.push(I(`pi install ${s}`,`HOME=/var/lib/crtr PI_CODING_AGENT_DIR=${D} pi install ${C(s)}`));a&&e.push(I("setup script",`bash /tmp/${U}`)),e.push(I("finalize",`echo ${Math.trunc(r)} > /work/.crtr/recipe-revision && chown -R ${f} /work /home/${f} /var/lib/crtr`)),e.push("",...n);for(const s of["/work",`/home/${f}`,"/var/lib/crtr"])e.push(`COPY --from=build --chown=${f}:${f} ${s} ${s}`);for(const s of["/usr/local","/usr","/etc","/lib"])e.push(`COPY --from=build ${s} ${s}`);return e.push("COPY --from=build /var/lib/postgresql /var/lib/postgresql"),e.push("RUN if getent passwd postgres >/dev/null; then chown -R postgres:postgres /var/lib/postgresql; fi"),i&&e.push(`RUN rm -f /work/.npmrc /home/${f}/.npmrc`),e.push(`USER ${f}`,"WORKDIR /work",'ENTRYPOINT ["/usr/local/bin/sandbox-api"]',""),e.join(`
|
|
5
|
+
`)}c(at,"recipeDockerfile");const ct=c((t,r,i)=>new Promise((o,a)=>{const n=j("git",t,{cwd:i,env:{...process.env,...r,GIT_TERMINAL_PROMPT:"0"},stdio:["ignore","ignore","pipe"]});let e="";n.stderr.on("data",s=>{e+=s.toString()}),n.on("error",a),n.on("close",s=>{s===0?o():a(new Error(`git ${t[0]} failed (${s}): ${e.slice(0,300)}`))})}),"runGit");async function Et(t){const r=t.git??ct,i=t.packagesToken??null,o=t.cloneUrl??(n=>`https://github.com/${n}.git`);z(E(t.dir,L),{recursive:!0});const a=t.token===null?{}:{GIT_CONFIG_COUNT:"1",GIT_CONFIG_KEY_0:"http.https://github.com/.extraheader",GIT_CONFIG_VALUE_0:`AUTHORIZATION: basic ${Buffer.from(`x-access-token:${t.token}`).toString("base64")}`};for(const n of t.recipe.repositories){if(!/^[A-Za-z0-9._-]+$/.test(n.name)||n.name==="."||n.name==="..")throw new Error(`repository name ${JSON.stringify(n.name)} is not a plain directory name`);await r(["clone","--quiet","--branch",n.default_branch,o(n.github_full_name),E(L,n.name)],a,t.dir)}b(E(t.dir,nt),st),b(E(t.dir,"Dockerfile"),at(t.recipe,t.revision,i!==null)),i!==null&&b(E(t.dir,".env.build"),`NODE_AUTH_TOKEN=${i}
|
|
6
|
+
`,{mode:384}),t.recipe.setup_script!==null&&t.recipe.setup_script.trim()!==""&&b(E(t.dir,U),t.recipe.setup_script.endsWith(`
|
|
7
7
|
`)?t.recipe.setup_script:`${t.recipe.setup_script}
|
|
8
|
-
`)}c(
|
|
8
|
+
`)}c(Et,"prepareBuildDir");function G(t,r,i){for(const o of J(r).sort()){const a=E(r,o),n=q(a),e=V(t,a).split("\\").join("/");n.isDirectory()?G(t,a,i):n.isSymbolicLink()?i.push({name:e,data:Buffer.from(W(a)),mode:A.S_IFLNK|511}):n.isFile()&&i.push({name:e,data:H(a),mode:A.S_IFREG|n.mode&511})}}c(G,"walk");function lt(t){const r=[];G(t,t,r);const i=[],o=[];let a=0;for(const s of r){const d=Buffer.from(s.name),g=Q(s.data),$=Z(s.data),p=Buffer.alloc(30);p.writeUInt32LE(67324752,0),p.writeUInt16LE(20,4),p.writeUInt16LE(2048,6),p.writeUInt16LE(8,8),p.writeUInt32LE(33,12),p.writeUInt32LE($,14),p.writeUInt32LE(g.length,18),p.writeUInt32LE(s.data.length,22),p.writeUInt16LE(d.length,26),i.push(p,d,g);const l=Buffer.alloc(46);l.writeUInt32LE(33639248,0),l.writeUInt16LE(788,4),l.writeUInt16LE(20,6),l.writeUInt16LE(2048,8),l.writeUInt16LE(8,10),l.writeUInt32LE(33,14),l.writeUInt32LE($,16),l.writeUInt32LE(g.length,20),l.writeUInt32LE(s.data.length,24),l.writeUInt16LE(d.length,28),l.writeUInt32LE(s.mode<<16>>>0,38),l.writeUInt32LE(a,42),o.push(l,d),a+=p.length+d.length+g.length}const n=Buffer.concat(o),e=Buffer.alloc(22);return e.writeUInt32LE(101010256,0),e.writeUInt16LE(r.length,8),e.writeUInt16LE(r.length,10),e.writeUInt32LE(n.length,12),e.writeUInt32LE(a,16),Buffer.concat([...i,n,e])}c(lt,"zipDirectory");async function O(t,r,i,o,a=[]){const n=`${t.controlUrl??"https://api.blaxel.ai/v0"}${i}`,e=await(t.fetch??fetch)(n,{method:r,headers:{authorization:`Bearer ${t.apiKey}`,"x-blaxel-workspace":t.workspace,"content-type":"application/json"},...o===void 0?{}:{body:JSON.stringify(o)}}),s=await e.text();let d=null;if(s!=="")try{d=JSON.parse(s)}catch{d={raw:s}}if(!e.ok&&!a.includes(e.status))throw new tt(e.status,null,`Blaxel ${r} ${n} failed (${e.status}): ${s.slice(0,300)}`);return{status:e.status,headers:e.headers,json:d}}c(O,"api");async function M(t,r){const{status:i,json:o}=await O(t,"GET",`/images/sandbox/${encodeURIComponent(r)}`,void 0,[404]);return i===404?null:o}c(M,"getImage");async function It(t,r){await O(t,"DELETE",`/images/sandbox/${encodeURIComponent(r)}`,void 0,[404])}c(It,"deleteImage");const pt=60*6e4;async function $t(t,r,i,o={}){const a=o.sleep??(h=>new Promise(u=>setTimeout(u,h))),n=o.now??Date.now,e=n(),s=await M(t,r),d=new Set((s?.spec?.tags??[]).map(h=>h.name)),g=c(h=>(h?.metadata?.events??[]).map(u=>Date.parse(u.time??"")).filter(u=>!Number.isNaN(u)),"eventTimes"),$=Math.max(-1/0,...g(s)),l=(await O(t,"POST","/images",{resourceType:"sandbox",name:r})).headers.get("x-blaxel-upload-url");if(l===null)throw new Error(`Blaxel gave no upload URL for image ${r}`);const x=await(t.fetch??fetch)(l,{method:"PUT",headers:{"content-type":"application/zip"},body:new Uint8Array(lt(i))});if(!x.ok)throw new Error(`uploading the build context of image ${r} failed (${x.status}): ${(await x.text()).slice(0,300)}`);const T=o.timeoutMs??pt,F=e+T;let R=null;for(;;){const h=await M(t,r),u=h?.metadata?.status,N=g(h).filter(m=>m>$).sort((m,_)=>m-_);if(u==="BUILT"&&N.length>=2){R??=n();const m=(h?.spec?.tags??[]).filter(w=>w.name!==void 0),_=N[0],k=c(w=>Date.parse(w??"")>=_,"touchedSince"),S=m.filter(w=>!d.has(w.name)||k(w.createdAt)||k(w.updatedAt)),y=n()-R>=(o.tagGraceMs??6e4),v=(S.length>0?S:y?m:[]).sort((w,Y)=>(Y.updatedAt??"").localeCompare(w.updatedAt??""))[0]?.name;if(v!==void 0)return{ref:`sandbox/${r}:${v}`,buildMs:n()-e};if(y)throw new Error(`Blaxel built image ${r} but no tag appeared`)}if(u==="FAILED"||u==="TERMINATED"){const m=h?.metadata?.events??[];throw new Error(`building image ${r} ${u.toLowerCase()}: ${m[m.length-1]?.message??"no message"}`)}if(n()>F)throw new Error(`building image ${r} did not finish within ${T} ms (last status ${u??"none"})`);await a(o.pollMs??3e3)}}c($t,"buildImage");const bt=c(t=>`env-${t}`,"environmentImageName");function Ut(t){X(t,{recursive:!0,force:!0})}c(Ut,"removeBuildDir");export{st as BLAXEL_TOML,nt as BLAXEL_TOML_FILE,pt as BUILD_TIMEOUT_MS,et as NODE_BASE_IMAGE,D as RECIPE_PI_AGENT_DIR,L as REPOS_DIR,f as RUN_USER,rt as SANDBOX_API_IMAGE,P as SETUP_FAILED_FILE,B as SETUP_LOG_FILE,U as SETUP_SCRIPT_FILE,$t as buildImage,It as deleteImage,bt as environmentImageName,M as getImage,Et as prepareBuildDir,at as recipeDockerfile,Ut as removeBuildDir,lt as zipDirectory};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.684",
|
|
4
4
|
"description": "crtr — agent runtime with memory, plugins, and marketplaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -156,8 +156,8 @@
|
|
|
156
156
|
},
|
|
157
157
|
"license": "UNLICENSED",
|
|
158
158
|
"dependencies": {
|
|
159
|
-
"@north-light/identity": "0.3.
|
|
160
|
-
"@north-light/plugin": "0.3.
|
|
159
|
+
"@north-light/identity": "0.3.684",
|
|
160
|
+
"@north-light/plugin": "0.3.684",
|
|
161
161
|
"@earendil-works/chord": "1.5.2",
|
|
162
162
|
"@earendil-works/pi-agent-core": "1.5.2",
|
|
163
163
|
"@earendil-works/pi-ai": "1.5.2",
|
|
@@ -197,6 +197,8 @@ export async function getImage(config, name) {
|
|
|
197
197
|
export async function deleteImage(config, name) {
|
|
198
198
|
await api(config, 'DELETE', `/images/sandbox/${encodeURIComponent(name)}`, undefined, [404]);
|
|
199
199
|
}
|
|
200
|
+
/** How long a build may stay BUILDING: the crouter-cloud image takes ~30-33 min on Blaxel. */
|
|
201
|
+
export const BUILD_TIMEOUT_MS = 60 * 60_000;
|
|
200
202
|
/** Uploads `dir` (Dockerfile and context) as a build of sandbox image `name` and waits for it. A failed build throws with Blaxel's last event message. */
|
|
201
203
|
export async function buildImage(config, name, dir, options = {}) {
|
|
202
204
|
const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
@@ -214,7 +216,8 @@ export async function buildImage(config, name, dir, options = {}) {
|
|
|
214
216
|
const put = await (config.fetch ?? fetch)(uploadUrl, { method: 'PUT', headers: { 'content-type': 'application/zip' }, body: new Uint8Array(zipDirectory(dir)) });
|
|
215
217
|
if (!put.ok)
|
|
216
218
|
throw new Error(`uploading the build context of image ${name} failed (${put.status}): ${(await put.text()).slice(0, 300)}`);
|
|
217
|
-
const
|
|
219
|
+
const timeoutMs = options.timeoutMs ?? BUILD_TIMEOUT_MS;
|
|
220
|
+
const deadline = started + timeoutMs;
|
|
218
221
|
let builtAt = null;
|
|
219
222
|
for (;;) {
|
|
220
223
|
const image = await getImage(config, name);
|
|
@@ -244,7 +247,7 @@ export async function buildImage(config, name, dir, options = {}) {
|
|
|
244
247
|
throw new Error(`building image ${name} ${status.toLowerCase()}: ${events[events.length - 1]?.message ?? 'no message'}`);
|
|
245
248
|
}
|
|
246
249
|
if (now() > deadline)
|
|
247
|
-
throw new Error(`building image ${name} did not finish within ${
|
|
250
|
+
throw new Error(`building image ${name} did not finish within ${timeoutMs} ms (last status ${status ?? 'none'})`);
|
|
248
251
|
await sleep(options.pollMs ?? 3000);
|
|
249
252
|
}
|
|
250
253
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.684",
|
|
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",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.684",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"postpack": "node ../../scripts/pack-minify.mjs postpack packages/crouter-plugin"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@north-light/api": "0.3.
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
30
|
+
"@north-light/api": "0.3.684",
|
|
31
|
+
"@north-light/identity": "0.3.684"
|
|
32
32
|
},
|
|
33
33
|
"license": "UNLICENSED",
|
|
34
34
|
"publishConfig": {
|
package/runtime.lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.684",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@north-light/cli",
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.684",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "UNLICENSED",
|
|
12
12
|
"workspaces": [
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"@milkdown/preset-gfm": "^7.22.3",
|
|
29
29
|
"@milkdown/prose": "^7.22.3",
|
|
30
30
|
"@milkdown/utils": "^7.22.3",
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
32
|
-
"@north-light/plugin": "0.3.
|
|
31
|
+
"@north-light/identity": "0.3.684",
|
|
32
|
+
"@north-light/plugin": "0.3.684",
|
|
33
33
|
"cron-parser": "^5.6.0",
|
|
34
34
|
"esbuild": "0.28.2",
|
|
35
35
|
"jose": "^6.2.12",
|
|
@@ -10667,17 +10667,17 @@
|
|
|
10667
10667
|
},
|
|
10668
10668
|
"packages/crouter-api": {
|
|
10669
10669
|
"name": "@north-light/api",
|
|
10670
|
-
"version": "0.3.
|
|
10670
|
+
"version": "0.3.684",
|
|
10671
10671
|
"license": "UNLICENSED"
|
|
10672
10672
|
},
|
|
10673
10673
|
"packages/crouter-env-docker": {
|
|
10674
10674
|
"name": "@north-light/env-docker",
|
|
10675
|
-
"version": "0.3.
|
|
10675
|
+
"version": "0.3.684",
|
|
10676
10676
|
"license": "UNLICENSED"
|
|
10677
10677
|
},
|
|
10678
10678
|
"packages/crouter-identity": {
|
|
10679
10679
|
"name": "@north-light/identity",
|
|
10680
|
-
"version": "0.3.
|
|
10680
|
+
"version": "0.3.684",
|
|
10681
10681
|
"license": "UNLICENSED",
|
|
10682
10682
|
"dependencies": {
|
|
10683
10683
|
"jose": "^6.2.1"
|
|
@@ -10685,21 +10685,21 @@
|
|
|
10685
10685
|
},
|
|
10686
10686
|
"packages/crouter-plugin": {
|
|
10687
10687
|
"name": "@north-light/plugin",
|
|
10688
|
-
"version": "0.3.
|
|
10688
|
+
"version": "0.3.684",
|
|
10689
10689
|
"license": "UNLICENSED",
|
|
10690
10690
|
"dependencies": {
|
|
10691
|
-
"@north-light/api": "0.3.
|
|
10692
|
-
"@north-light/identity": "0.3.
|
|
10691
|
+
"@north-light/api": "0.3.684",
|
|
10692
|
+
"@north-light/identity": "0.3.684"
|
|
10693
10693
|
}
|
|
10694
10694
|
},
|
|
10695
10695
|
"packages/crouter-sdk": {
|
|
10696
10696
|
"name": "@north-light/sdk",
|
|
10697
|
-
"version": "0.3.
|
|
10697
|
+
"version": "0.3.684",
|
|
10698
10698
|
"license": "UNLICENSED",
|
|
10699
10699
|
"dependencies": {
|
|
10700
|
-
"@north-light/api": "0.3.
|
|
10701
|
-
"@north-light/identity": "0.3.
|
|
10702
|
-
"@north-light/plugin": "0.3.
|
|
10700
|
+
"@north-light/api": "0.3.684",
|
|
10701
|
+
"@north-light/identity": "0.3.684",
|
|
10702
|
+
"@north-light/plugin": "0.3.684",
|
|
10703
10703
|
"jose": "^6.2.1"
|
|
10704
10704
|
},
|
|
10705
10705
|
"bin": {
|