@north-light/cli 0.3.737 → 0.3.739
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 +9 -9
- package/dist/clients/attach/viewer.js +546 -546
- package/dist/commands/sys/doctor.js +1 -1
- package/dist/commands/sys/old-package.d.ts +9 -0
- package/dist/commands/sys/old-package.js +1 -0
- package/dist/commands/sys/setup-core.js +3 -3
- package/dist/commands/sys/signin.js +3 -2
- package/dist/core/import/export/cloud.d.ts +3 -0
- package/dist/core/import/export/cloud.js +1 -1
- package/dist/core/profiles/manifest.js +1 -1
- package/dist/core/runtime/front-door.js +7 -7
- package/dist/daemon/machine-link/config.d.ts +2 -0
- package/dist/daemon/machine-link/config.js +4 -4
- package/dist/daemon/manage.js +3 -3
- package/package.json +3 -3
- package/packages/crouter-api/dist/commands/sys/doctor.js +9 -0
- package/packages/crouter-api/dist/commands/sys/old-package.js +20 -0
- package/packages/crouter-api/dist/commands/sys/setup-core.js +2 -2
- package/packages/crouter-api/dist/commands/sys/signin.js +8 -0
- package/packages/crouter-api/dist/core/import/export/cloud.js +10 -0
- package/packages/crouter-api/dist/core/profiles/manifest.js +5 -2
- package/packages/crouter-api/dist/daemon/machine-link/config.js +3 -0
- package/packages/crouter-api/dist/daemon/manage.js +4 -1
- 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
package/dist/daemon/manage.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var V=Object.defineProperty;var o=(e,t)=>V(e,"name",{value:t,configurable:!0});import{spawn as U,execFileSync as J}from"node:child_process";import{createRequire as Q}from"node:module";import{dirname as M,join as D}from"node:path";import{fileURLToPath as Z,pathToFileURL as O}from"node:url";import{existsSync as W,lstatSync as ee,mkdirSync as te,openSync as H,closeSync as K,fstatSync as G,readSync as re}from"node:fs";import{crtrHome as g}from"../core/canvas/paths.js";import{listProcessTable as ne}from"../core/canvas/pid.js";import{bindDaemonEventSource as oe,eventSource as ae}from"../core/events/source.js";import{hostExecPath as k}from"../core/runtime/branded-host.js";import{isDaemonRunning as ie,readPidfile as x,isPidAlive as m}from"./pidfile.js";import{DAEMON_STARTUP_WINDOW_MS as j}from"./startup-policy.js";import{readMachineConfig as
|
|
2
|
-
`).at(-1)??"";return JSON.parse(u)}o(R,"runDaemonEntry");function
|
|
3
|
-
${r}`),this.name="DaemonExitedBeforeReadyError",this.stderrTail=r}}class X extends Error{static{o(this,"DaemonLaunchError")}constructor(t){super(t instanceof Error?t.message:String(t),{cause:t}),this.name="DaemonLaunchError"}}class v extends Error{static{o(this,"DaemonStartupBlockedError")}constructor(t,r){super(`daemon ${t} is running but normal startup is blocked: ${r}`),this.name="DaemonStartupBlockedError"}}class F extends Error{static{o(this,"DaemonNotPreparedError")}constructor(t,r){super(r===void 0?`daemon ${t} is serving but did not report the prepared startup phase`:`daemon ${t} reported startup phase ${r}, not prepared`),this.name="DaemonNotPreparedError"}}async function
|
|
1
|
+
var V=Object.defineProperty;var o=(e,t)=>V(e,"name",{value:t,configurable:!0});import{spawn as U,execFileSync as J}from"node:child_process";import{createRequire as Q}from"node:module";import{dirname as M,join as D}from"node:path";import{fileURLToPath as Z,pathToFileURL as O}from"node:url";import{existsSync as W,lstatSync as ee,mkdirSync as te,openSync as H,closeSync as K,fstatSync as G,readSync as re}from"node:fs";import{crtrHome as g}from"../core/canvas/paths.js";import{listProcessTable as ne}from"../core/canvas/pid.js";import{bindDaemonEventSource as oe,eventSource as ae}from"../core/events/source.js";import{hostExecPath as k}from"../core/runtime/branded-host.js";import{isDaemonRunning as ie,readPidfile as x,isPidAlive as m}from"./pidfile.js";import{DAEMON_STARTUP_WINDOW_MS as j}from"./startup-policy.js";import{computerIsUnset as se,readMachineConfig as ce}from"./machine-link/config.js";import{exclusiveLockOwnerPid as ue}from"../core/exclusive-lock.js";import{onDiskMigrationLockPath as le}from"../core/canvas/paths.js";import{envNoDaemonAutostart as de}from"../shared/env.js";import{waitForDaemonAvailability as pe}from"../api/index.js";import{localClient as fe}from"../api/node-transport.js";const me=["CRTR_NODE_ID","CRTR_KIND","CRTR_MODE","CRTR_LIFECYCLE","CRTR_NODE_CWD","CRTR_CONTEXT_DIR","CRTR_CYCLES","CRTR_PROFILE_ID","CRTR_PARENT_NODE_ID","CRTR_FRONT_DOOR","TMUX","TMUX_PANE","CRTR_BROKER_ENGINE","CRTR_PI_BINARY","NODE_OPTIONS"];function A(){const e={...process.env};for(const t of me)delete e[t];return e}o(A,"sanitizedDaemonEnv");function he(){for(let e=M(Z(import.meta.url));;e=M(e)){if(W(D(e,"bin","runtime-generation-manifest.mjs")))return e;if(M(e)===e)throw new Error(`cannot locate the crouter generation root from ${import.meta.url}`)}}o(he,"generationRoot");async function I(){const e=he(),t=O(D(e,"bin","runtime-generation-manifest.mjs")).href,{runtimeHome:r}=await import(t);try{ee(D(r(),"selected"))}catch(u){if(u.code!=="ENOENT")throw u;return["--conditions","crtr-src","--import",O(Q(import.meta.url).resolve("tsx/esm")).href,D(e,"src","daemon","crtrd-cli.ts")]}const n=O(D(e,"bin","runtime-selector.mjs")).href,{tryResolveRuntime:a}=await import(n),s=a("daemon");if(!s.ok)throw new Error(`cannot resolve the selected runtime generation's daemon entry: ${s.error}`);return[s.runtime.entryPath]}o(I,"resolveDaemonLaunch");function we(e,t){return e.includes(` --canvas-home ${t} `)||e.endsWith(` --canvas-home ${t}`)}o(we,"daemonCommandDeclaresCanvasHome");function _e(){const e=ne();if(e===null)return[];const t=g(),r=[];for(const{pid:n,command:a}of e)a.includes("daemon/crtrd")&&we(a,t)&&n!==process.pid&&r.push(n);return r}o(_e,"findDaemonPids");function Ee(e){const t=_e().filter(n=>n!==e);for(const n of t)try{process.kill(n,"SIGTERM")}catch{}if(t.length===0)return t;const r=Date.now()+2e3;for(;Date.now()<r&&t.some(n=>m(n));)J("sleep",["0.1"]);for(const n of t)if(m(n))try{process.kill(n,"SIGKILL")}catch{}return t}o(Ee,"sweepStrayDaemons");async function qe(){const e=process.execve;if(e===void 0)throw new Error(`this Node.js ${process.version} runtime cannot replace PID 1 with the successor daemon`);const t=k(),r=await I();return e(t,[t,...r,"--canvas-home",g()],A())}o(qe,"execDaemon");async function R(e){const t=await I(),r=U(k(),[...t,...e],{stdio:["ignore","pipe","pipe"],env:A()});let n="",a="";r.stdout.setEncoding("utf8").on("data",c=>{n+=c}),r.stderr.setEncoding("utf8").on("data",c=>{a+=c});const s=await new Promise((c,p)=>{r.once("error",p),r.once("close",h=>c(h))});if(s!==0)throw new Error(a.trim()||`the ${e[0]} process exited with code ${s}`);const u=n.trim().split(`
|
|
2
|
+
`).at(-1)??"";return JSON.parse(u)}o(R,"runDaemonEntry");function Ve(){return R(["export-sqlite"])}o(Ve,"runDaemonExportSqlite");function Je(e,t){return R(["import-dump",e,t])}o(Je,"runDaemonImportDump");function Qe(e){return R(["import-dump",e,"bodies"])}o(Qe,"runDaemonBodiesDump");function Ze(){return R(["import-dump","","install-id"])}o(Ze,"runDaemonInstallId");const z=2e4,N=10,P=1e3;async function L(e=P){const t=Math.min(e,P);return fe({autostart:!1,timeoutMs:t}).probeHealthz(t)}o(L,"probeDaemonHealth");function De(e){const t=e instanceof Error?e.message:String(e);if(typeof e!="object"||e===null)return t;const r=e.code,n=e.cause,a=typeof r=="string"?r:n?.code;return typeof a=="string"&&!t.includes(a)?`${t}: ${a}`:t}o(De,"probeErrorMessage");async function Y(e=P){const t=await L(e);if(t.startup_phase==="blocked"){const r=x()??process.pid;throw new v(r,t.startup_blocked??"daemon startup is blocked")}if(!t.ok)throw new Error(t.startup_blocked??"crtrd health check reported not ready")}o(Y,"probeDaemonServing");async function et(){try{return await Y(),!0}catch{return!1}}o(et,"isDaemonServing");function $(e){return new Promise(t=>{setTimeout(t,e)})}o($,"sleepMs");class C extends Error{static{o(this,"DaemonExitedBeforeReadyError")}stderrTail;constructor(t,r){super(r===""?t:`${t}
|
|
3
|
+
${r}`),this.name="DaemonExitedBeforeReadyError",this.stderrTail=r}}class X extends Error{static{o(this,"DaemonLaunchError")}constructor(t){super(t instanceof Error?t.message:String(t),{cause:t}),this.name="DaemonLaunchError"}}class v extends Error{static{o(this,"DaemonStartupBlockedError")}constructor(t,r){super(`daemon ${t} is running but normal startup is blocked: ${r}`),this.name="DaemonStartupBlockedError"}}class F extends Error{static{o(this,"DaemonNotPreparedError")}constructor(t,r){super(r===void 0?`daemon ${t} is serving but did not report the prepared startup phase`:`daemon ${t} reported startup phase ${r}, not prepared`),this.name="DaemonNotPreparedError"}}async function xe(e,t=j,r={},n="ready"){const a=r.readPidfile??x,s=r.isPidAlive??m,u=r.childExited,c=r.isDaemonServing,p=r.probeDaemonServing??(async _=>{if(c!==void 0){if(await c())return;throw new Error("crtrd health check reported not ready")}await Y(_)}),h=r.probeDaemonHealth??L,y=r.sleepMs??$,i=r.now??Date.now;let f=null,l=null;return await pe({windowMs:t,pollIntervalMs:N,now:i,sleep:y,retry:o(_=>_!==l,"retry"),probe:o(async _=>{const w=a();if(w===null||!s(w)){const d=u?.();throw d!=null&&(d.signal!==null?l=new C(`daemon ${e} exited before becoming ready (by ${d.signal})`,r.childStderrTail?.()??""):d.code!==0&&(l=new C(`daemon ${e} exited before becoming ready (with exit code ${d.code??"?"})`,r.childStderrTail?.()??"")),l!==null)?l:new Error(`daemon ${e} has no live pidfile owner`)}if(n==="ready"){try{await p(_)}catch(d){throw d instanceof v&&(l=d),d}f=w;return}const E=await h(_);if(E.startup_phase==="prepared"){f=w;return}throw E.startup_phase==="blocked"?(l=new v(w,E.startup_blocked??"on-disk migration is blocked"),l):E.startup_phase==="ready"?(l=new F(w,E.startup_phase),l):new Error(`daemon ${w} is ${E.startup_phase??"not reporting a startup phase"}; waiting for prepared`)},"probe")}),f===e?null:f}o(xe,"verifyDaemonStartup");async function ye(e,t=z,r={}){const n=r.readPidfile??x,a=r.isPidAlive??m,s=r.sleepMs??$,u=r.now??Date.now,c=u()+t;for(;u()<=c;){if(!a(e)&&n()!==e)return;await s(N)}throw new Error(`daemon ${e} did not exit and release its pidfile within ${t}ms`)}o(ye,"waitForDaemonExit");const ge=2e3,Se=5e3;async function q(e,t=z,r={}){const n=r.isPidAlive??m,a=r.sleepMs??$,s=r.now??Date.now;try{process.kill(e,"SIGTERM")}catch{}try{return await ye(e,t,r),"terminated"}catch{}try{process.kill(e,"SIGKILL")}catch{}const u=s()+ge;for(;s()<=u;){if(!n(e))return"killed";await a(N)}throw new Error(`daemon ${e} survived both SIGTERM and SIGKILL`)}o(q,"stopDaemonProcess");async function tt(){const e=x(),t=e!==null&&m(e),r=t&&await q(e)==="killed",n=Ee(null);return{stopped:t||n.length>0,...t?{pid:e}:{},strays_killed:n,force_killed:r}}o(tt,"stopAllDaemons");function Re(e,t,r=2048){let n;try{n=H(e,"r");const{size:a}=G(n),s=Math.max(t,a-r),u=a-s;if(u<=0)return"";const c=Buffer.alloc(u);return re(n,c,0,u,s),c.toString("utf8").trim()}catch{return""}finally{if(n!==void 0)try{K(n)}catch{}}}o(Re,"readLogTailFrom");async function ve(e={}){if(process.platform==="linux"&&W("/run/crtr/launcher.sock")&&!m(x()??-1)&&ce()===void 0)throw new Error("crtrd is managed by the root launcher; it cannot self-daemonize");const t=e.targetPhase??"ready",r=x();if(r!==null&&m(r))try{const i=await L();if(t==="prepared"){if(i.startup_phase==="prepared")return{started:!1,existing_pid:r,startup_phase:i.startup_phase};throw new F(r,i.startup_phase)}return i.ok?{started:!1,existing_pid:r,...i.startup_phase===void 0?{}:{startup_phase:i.startup_phase}}:{started:!1,existing_pid:r,running:!0,serving:!1,probe_error:i.startup_blocked??"crtrd health check reported not ready",...i.startup_phase===void 0?{}:{startup_phase:i.startup_phase}}}catch(i){if(i instanceof F)throw i;return{started:!1,existing_pid:r,running:!0,serving:!1,probe_error:De(i)}}te(g(),{recursive:!0});const n=await I().catch(i=>{throw new X(i)}),a=D(g(),"crtrd.err"),s=H(a,"a"),u=(()=>{try{return G(s).size}catch{return 0}})();ae()===void 0&&oe();const c=U(k(),[...n,"--canvas-home",g(),...t==="prepared"?["--prepare"]:[]],{detached:!0,stdio:["ignore",s,s],env:A()});K(s);const p=c.pid;if(p===void 0)throw new Error("daemon spawn did not return a pid");let h=null;c.once("exit",(i,f)=>{h={code:i,signal:f}}),c.unref();let y;try{y=await xe(p,j,{childExited:o(()=>h,"childExited"),childStderrTail:o(()=>Re(a,u),"childStderrTail")},t)}catch(i){const f=ue(le())===p;if(h===null&&!f&&!(i instanceof v))try{await q(p,Se)}catch{}throw i}return y!==null?{started:!1,existing_pid:y,startup_phase:t}:{started:!0,pid:p,startup_phase:t}}o(ve,"spawnDaemon");function Te(){return de()||process.argv.includes("--no-autostart")}o(Te,"autostartDisabled");const be=5e3,Me=6e4;let B=!1,S,T=0,b=0;function Oe(e){return Math.min(be*2**(e-1),Me)}o(Oe,"autostartBackoffMs");function ke(){S=void 0,T=0,b=0}o(ke,"resetDaemonAutostart");function rt(){return S}o(rt,"daemonAutostartStartupFailure");function nt(e={}){const t=e.isDaemonRunning??ie,r=e.spawnDaemon??ve,n=e.now??Date.now;if(!Te()&&!(!e.spawnDaemon&&se())&&!B&&!(n()<b)){if(t()){ke();return}S=void 0,B=!0,r().then(()=>{S=void 0,T=0,b=0},a=>{(a instanceof C||a instanceof X)&&(S=a.message),T+=1,b=n()+Oe(T)}).finally(()=>{B=!1})}}o(nt,"ensureDaemon");export{me as DAEMON_ENV_STRIP_KEYS,C as DaemonExitedBeforeReadyError,X as DaemonLaunchError,F as DaemonNotPreparedError,v as DaemonStartupBlockedError,Te as autostartDisabled,rt as daemonAutostartStartupFailure,we as daemonCommandDeclaresCanvasHome,nt as ensureDaemon,qe as execDaemon,_e as findDaemonPids,et as isDaemonServing,L as probeDaemonHealth,Y as probeDaemonServing,De as probeErrorMessage,ke as resetDaemonAutostart,Qe as runDaemonBodiesDump,Ve as runDaemonExportSqlite,Je as runDaemonImportDump,Ze as runDaemonInstallId,A as sanitizedDaemonEnv,ve as spawnDaemon,tt as stopAllDaemons,q as stopDaemonProcess,Ee as sweepStrayDaemons,xe as verifyDaemonStartup,ye as waitForDaemonExit};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.739",
|
|
4
4
|
"description": "crtr — agent runtime with memory, plugins, and marketplaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -158,8 +158,8 @@
|
|
|
158
158
|
},
|
|
159
159
|
"license": "UNLICENSED",
|
|
160
160
|
"dependencies": {
|
|
161
|
-
"@north-light/identity": "0.3.
|
|
162
|
-
"@north-light/plugin": "0.3.
|
|
161
|
+
"@north-light/identity": "0.3.739",
|
|
162
|
+
"@north-light/plugin": "0.3.739",
|
|
163
163
|
"@earendil-works/chord": "1.5.2",
|
|
164
164
|
"@earendil-works/pi-agent-core": "1.5.2",
|
|
165
165
|
"@earendil-works/pi-ai": "1.5.2",
|
|
@@ -12,6 +12,7 @@ import { pathExists, listDirs, removePath } from '../../core/fs-utils.js';
|
|
|
12
12
|
import { lsRemote } from '../../core/git.js';
|
|
13
13
|
import { cliClient } from '../api-client.js';
|
|
14
14
|
import { detectNerdFont, nerdFontInstallCommand, NERD_FONT_SELECT_HINT } from '../../core/runtime/nerd-font.js';
|
|
15
|
+
import { oldPackageInstalled } from './old-package.js';
|
|
15
16
|
import { detectPackageManager } from './setup-core.js';
|
|
16
17
|
import { validateEffectiveCommandPlugins } from '../../core/command-plugins/discovery.js';
|
|
17
18
|
import { adaptPluginContributions } from '../../core/command-plugins/compose.js';
|
|
@@ -386,6 +387,13 @@ function runNerdFontCheck() {
|
|
|
386
387
|
...(plan.command ? { command: plan.command } : {}),
|
|
387
388
|
});
|
|
388
389
|
}
|
|
390
|
+
/** `@crouton-kit/crouter` installed beside this package fights it for the `crtr` bin, and npm refuses to install over it; only uninstalling it first works. */
|
|
391
|
+
function oldPackageCheck() {
|
|
392
|
+
const old = oldPackageInstalled();
|
|
393
|
+
if (old === undefined)
|
|
394
|
+
return pass('canvas', 'package:old-crouter', 'the old @crouton-kit/crouter package is not installed');
|
|
395
|
+
return failCheck('canvas', 'package:old-crouter', old.message, { kind: 'human_action', description: 'Remove the old package, then reinstall this one', command: `${old.uninstall} && npm i -g @north-light/cli@latest` });
|
|
396
|
+
}
|
|
389
397
|
/** Where the generation was installed from (`<id>.source.json` beside it, written by install-runtime). */
|
|
390
398
|
function installSourceCheck(label, generation) {
|
|
391
399
|
const name = `runtime:${label}:source`;
|
|
@@ -630,6 +638,7 @@ export const sysDoctorLeaf = defineLeaf({
|
|
|
630
638
|
allResults.push(...runBinContributionChecks(scopes));
|
|
631
639
|
allResults.push(...runHumanActionChecks(scopes));
|
|
632
640
|
allResults.push(...await runRequiresChecks(scopes));
|
|
641
|
+
allResults.push(oldPackageCheck());
|
|
633
642
|
allResults.push(...await runFaultChecks());
|
|
634
643
|
const processLocation = processGeneration();
|
|
635
644
|
allResults.push(...await generationChecks('selected', selectedGeneration(), processLocation === null));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// The old `@crouton-kit/crouter` package declares the same `crtr` bin as `@north-light/cli`. npm checks bin ownership before any install script runs,
|
|
2
|
+
// so `npm i -g @north-light/cli` over it fails with EEXIST and no script of ours can prevent that; the old package has to be uninstalled first.
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import { dirname, join, sep } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
export const OLD_PACKAGE = '@crouton-kit/crouter';
|
|
7
|
+
export const OLD_PACKAGE_UNINSTALL = `npm uninstall -g ${OLD_PACKAGE}`;
|
|
8
|
+
/** Where a global install of this package sits beside the old one: `<lib>/node_modules/@north-light/cli` → `<lib>/node_modules/@crouton-kit/crouter`. */
|
|
9
|
+
export function oldPackageDir(packageRoot) {
|
|
10
|
+
const marker = `${sep}node_modules${sep}@north-light${sep}cli`;
|
|
11
|
+
const at = packageRoot.lastIndexOf(marker);
|
|
12
|
+
return at < 0 ? undefined : join(packageRoot.slice(0, at), 'node_modules', OLD_PACKAGE);
|
|
13
|
+
}
|
|
14
|
+
/** The old package installed next to this one, with the message that names the command that removes it; undefined when it is absent. */
|
|
15
|
+
export function oldPackageInstalled(packageRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..', '..')) {
|
|
16
|
+
const dir = oldPackageDir(packageRoot);
|
|
17
|
+
if (dir === undefined || !existsSync(join(dir, 'package.json')))
|
|
18
|
+
return undefined;
|
|
19
|
+
return { uninstall: OLD_PACKAGE_UNINSTALL, message: `The old ${OLD_PACKAGE} package is still installed at ${dir} and owns the \`crtr\` command. Run \`${OLD_PACKAGE_UNINSTALL}\`, then \`npm i -g @north-light/cli@latest\`.` };
|
|
20
|
+
}
|
|
@@ -5,7 +5,7 @@ import { piAgentDir } from '../../core/runtime/package-health.js';
|
|
|
5
5
|
import { basename, dirname, join, relative, resolve } from 'node:path';
|
|
6
6
|
import { isDeepStrictEqual } from 'node:util';
|
|
7
7
|
import { BINDING_CATALOG, normalizeGesture, splitGestureExpression, inboxShortcut, resolveKeybindings, } from '../../core/keybindings/index.js';
|
|
8
|
-
import {
|
|
8
|
+
import { builtinPiPackageDir } from '../../core/scope.js';
|
|
9
9
|
import { atomicWriteJson, readJsonIfExists, readJsonOrNull } from '../../core/fs-utils.js';
|
|
10
10
|
import { resolveBundledPiCliPath } from '../../core/runtime/pi-cli.js';
|
|
11
11
|
import { crtrVersion } from '../../shared/crtr-version.js';
|
|
@@ -272,7 +272,7 @@ const LOCAL_PACKAGE_NAME_ALIASES = {
|
|
|
272
272
|
'dev-plugin': [],
|
|
273
273
|
};
|
|
274
274
|
function selectedPiPackageDir(name) {
|
|
275
|
-
return
|
|
275
|
+
return builtinPiPackageDir(name);
|
|
276
276
|
}
|
|
277
277
|
export function buildSetupManifest(resolveBuiltinPackageDir = selectedPiPackageDir) {
|
|
278
278
|
// Order matters at execution: the marketplace source registers before the
|
|
@@ -13,6 +13,7 @@ import { envNodeId } from '../../shared/env.js';
|
|
|
13
13
|
import { ExitCode } from '../../types.js';
|
|
14
14
|
import { insideBroker } from './join.js';
|
|
15
15
|
import { defaultDirectoryUrl, finishMove, registerThisMac, runMove, settleEarlierMove } from './import/move.js';
|
|
16
|
+
import { oldPackageInstalled } from './old-package.js';
|
|
16
17
|
import { WAIT_FOR_PID_ENV } from './import/start.js';
|
|
17
18
|
/** Open the confirm page in the person's browser; a failure to open it is harmless because the code and address are printed too. */
|
|
18
19
|
function openBrowser(url) {
|
|
@@ -114,6 +115,7 @@ export const sysSigninLeaf = defineLeaf({
|
|
|
114
115
|
outputKind: 'object',
|
|
115
116
|
effects: [
|
|
116
117
|
'Calls the directory (`POST /v1/developer/logins`, then polls `/v1/developer/logins/poll`) and, once approved, writes `runtime/secrets/person-credential` (0600) and replaces the cached bearer. A declined, abandoned or refused sign-in writes nothing and leaves an existing sign-in as it was.',
|
|
118
|
+
'Starts the local daemon first when it is not running, and waits until it serves.',
|
|
117
119
|
'On a computer whose records are local: the move of `crtr sys import start --kind machine` (drains the daemon, uploads, restarts it in machine role); a move confirmed failed before the account holds the records ends the drain and signs this computer out again. If the account\'s result is unknown, the move record and drain remain for recovery. From inside a node it runs as a detached process logging to `runtime/import/move.log`.',
|
|
118
120
|
'On a computer with no local records: registers it with `POST /v1/machines`, writes `runtime/machine.json` and `runtime/secrets/machine-credential`, and starts the machine daemon. Run again after `northlight_unreachable`, it resumes at registration with the stored sign-in.',
|
|
119
121
|
'On a moved computer: restarts the daemon so it reconnects to Northlight.',
|
|
@@ -121,6 +123,12 @@ export const sysSigninLeaf = defineLeaf({
|
|
|
121
123
|
],
|
|
122
124
|
},
|
|
123
125
|
run: async (input) => {
|
|
126
|
+
// A computer with local records needs its daemon (the move reads the canvas through it) and a machine's daemon is the machine role; a fresh computer starts none until it is registered.
|
|
127
|
+
if (readMachineConfig() !== undefined || hasLocalCanvas())
|
|
128
|
+
await spawnDaemon();
|
|
129
|
+
const oldPackage = oldPackageInstalled();
|
|
130
|
+
if (oldPackage !== undefined)
|
|
131
|
+
process.stderr.write(`${oldPackage.message}\n`);
|
|
124
132
|
const directoryUrl = input.directoryUrl === undefined ? defaultDirectoryUrl() : String(input.directoryUrl);
|
|
125
133
|
const unfinished = await settleEarlierMove(showSignIn);
|
|
126
134
|
if (unfinished !== undefined) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// The exporter's HTTP side: `/v1/imports` on the control plane with the person's (or the operator's) bearer token, and signed R2 PUTs.
|
|
2
2
|
// Imports Node built-ins only, so a CLI leaf can use it.
|
|
3
3
|
import { CrtrError, general } from '../../errors.js';
|
|
4
|
+
import { ExitCode } from '../../../types.js';
|
|
5
|
+
import { crtrVersion } from '../../../shared/crtr-version.js';
|
|
4
6
|
import { NORTHLIGHT_UNREACHABLE } from '../../directory/reach.js';
|
|
5
7
|
/** The dump directory's file holding the opened file stores, and the order they are uploaded in. */
|
|
6
8
|
export const STORE_FILE = 'stores.json';
|
|
@@ -17,6 +19,11 @@ function failureText(error) {
|
|
|
17
19
|
const cause = error.cause;
|
|
18
20
|
return `failed: ${error instanceof Error ? error.message : String(error)}${typeof cause?.code === 'string' ? ` (${cause.code})` : ''}`;
|
|
19
21
|
}
|
|
22
|
+
/** The control plane refuses a source that runs another release than its own: name the release it accepts and the command that installs it. */
|
|
23
|
+
export function releaseMismatch(accepted, status) {
|
|
24
|
+
const command = `npm i -g @north-light/cli@${accepted}`;
|
|
25
|
+
return new CrtrError('release_mismatch', `Northlight accepts only crtr ${accepted} for this step, and this computer runs ${crtrVersion()}. Install it with \`${command}\`, then run \`crtr sys signin\` again.`, ExitCode.GENERAL, { status, code: 'release_mismatch', accepted, next: `Run \`${command}\`, then \`crtr sys signin\`.` });
|
|
26
|
+
}
|
|
20
27
|
export class ImportCloud {
|
|
21
28
|
apiUrl;
|
|
22
29
|
token;
|
|
@@ -83,6 +90,9 @@ export class ImportCloud {
|
|
|
83
90
|
catch {
|
|
84
91
|
code = undefined;
|
|
85
92
|
}
|
|
93
|
+
const accepted = code === 'release_mismatch' ? /control plane accepts (\S+)/.exec(text)?.[1]?.replace(/[^0-9A-Za-z.+-]+$/, '') : undefined;
|
|
94
|
+
if (accepted !== undefined)
|
|
95
|
+
throw releaseMismatch(accepted, response.status);
|
|
86
96
|
throw general(`${method} ${path} answered ${response.status}: ${text.slice(0, 500)}`, { status: response.status, ...(typeof code === 'string' ? { code } : {}) });
|
|
87
97
|
}
|
|
88
98
|
return (text === '' ? undefined : JSON.parse(text));
|
|
@@ -237,9 +237,12 @@ export async function ensureRootProfile() {
|
|
|
237
237
|
}
|
|
238
238
|
return await createProfile(ROOT_PROFILE_NAME, [], { grantee: 'app:terminal' });
|
|
239
239
|
}
|
|
240
|
-
|
|
240
|
+
// A computer signed in to an account that already has a root profile (made on another computer, so with another id) uses that one.
|
|
241
|
+
const existing = getStoredProfile(ROOT_PROFILE_ID)
|
|
242
|
+
?? listProfiles().find((p) => p.manifest.name === ROOT_PROFILE_NAME && profileApp(p.manifest) === 'app:terminal')
|
|
243
|
+
?? null;
|
|
241
244
|
if (existing !== null) {
|
|
242
|
-
scaffoldProfile(
|
|
245
|
+
scaffoldProfile(existing.profileId, existing.manifest);
|
|
243
246
|
return existing;
|
|
244
247
|
}
|
|
245
248
|
const next = {
|
|
@@ -7,6 +7,7 @@ import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync }
|
|
|
7
7
|
import { randomBytes } from 'node:crypto';
|
|
8
8
|
import { dirname, join } from 'node:path';
|
|
9
9
|
import { runtimeRoot, secretsDir } from '../../core/layout.js';
|
|
10
|
+
import { joinedIssuer } from '../../core/directory/join.js';
|
|
10
11
|
import { CrtrError } from '../../core/errors.js';
|
|
11
12
|
import { atomicWriteJson } from '../../core/fs-utils.js';
|
|
12
13
|
import { ExitCode } from '../../types.js';
|
|
@@ -75,3 +76,5 @@ export function readOrCreateInstallId() {
|
|
|
75
76
|
}
|
|
76
77
|
/** Whether this computer still holds a local canvas from before crtr was fleet-only (a supervised Postgres or a SQLite file). */
|
|
77
78
|
export const hasLocalCanvas = () => ['pg', 'canvas.db', 'canvas.db.imported'].some((name) => existsSync(join(runtimeRoot(), name)));
|
|
79
|
+
/** A computer with no `machine.json`, no local records and no join registration has not been set up: it has no control plane to reach until `crtr sys signin`. */
|
|
80
|
+
export const computerIsUnset = () => readMachineConfig() === undefined && !hasLocalCanvas() && joinedIssuer() === null;
|
|
@@ -16,7 +16,7 @@ import { hostExecPath } from '../core/runtime/branded-host.js';
|
|
|
16
16
|
// reaches openDb) so the CLI daemon front door stays canvas.db-free (plan B-0).
|
|
17
17
|
import { isDaemonRunning, readPidfile, isPidAlive } from './pidfile.js';
|
|
18
18
|
import { DAEMON_STARTUP_WINDOW_MS } from './startup-policy.js';
|
|
19
|
-
import { readMachineConfig } from './machine-link/config.js';
|
|
19
|
+
import { computerIsUnset, readMachineConfig } from './machine-link/config.js';
|
|
20
20
|
import { exclusiveLockOwnerPid } from '../core/exclusive-lock.js';
|
|
21
21
|
import { onDiskMigrationLockPath } from '../core/canvas/paths.js';
|
|
22
22
|
import { envNoDaemonAutostart } from '../shared/env.js';
|
|
@@ -694,6 +694,9 @@ export function ensureDaemon(deps = {}) {
|
|
|
694
694
|
const now = deps.now ?? Date.now;
|
|
695
695
|
if (autostartDisabled())
|
|
696
696
|
return;
|
|
697
|
+
// A computer with no `machine.json` and no local records is not set up: no command starts a local control plane there (`crtr sys signin` comes first).
|
|
698
|
+
if (!deps.spawnDaemon && computerIsUnset())
|
|
699
|
+
return;
|
|
697
700
|
if (autostartInFlight)
|
|
698
701
|
return;
|
|
699
702
|
if (now() < autostartNextAttemptAt)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.739",
|
|
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.739",
|
|
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.739",
|
|
31
|
+
"@north-light/identity": "0.3.739"
|
|
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.739",
|
|
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.739",
|
|
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.739",
|
|
32
|
+
"@north-light/plugin": "0.3.739",
|
|
33
33
|
"cron-parser": "^5.6.0",
|
|
34
34
|
"esbuild": "0.28.2",
|
|
35
35
|
"jose": "^6.2.12",
|
|
@@ -11902,17 +11902,17 @@
|
|
|
11902
11902
|
},
|
|
11903
11903
|
"packages/crouter-api": {
|
|
11904
11904
|
"name": "@north-light/api",
|
|
11905
|
-
"version": "0.3.
|
|
11905
|
+
"version": "0.3.739",
|
|
11906
11906
|
"license": "UNLICENSED"
|
|
11907
11907
|
},
|
|
11908
11908
|
"packages/crouter-env-docker": {
|
|
11909
11909
|
"name": "@north-light/env-docker",
|
|
11910
|
-
"version": "0.3.
|
|
11910
|
+
"version": "0.3.739",
|
|
11911
11911
|
"license": "UNLICENSED"
|
|
11912
11912
|
},
|
|
11913
11913
|
"packages/crouter-identity": {
|
|
11914
11914
|
"name": "@north-light/identity",
|
|
11915
|
-
"version": "0.3.
|
|
11915
|
+
"version": "0.3.739",
|
|
11916
11916
|
"license": "UNLICENSED",
|
|
11917
11917
|
"dependencies": {
|
|
11918
11918
|
"jose": "^6.2.1"
|
|
@@ -11920,21 +11920,21 @@
|
|
|
11920
11920
|
},
|
|
11921
11921
|
"packages/crouter-plugin": {
|
|
11922
11922
|
"name": "@north-light/plugin",
|
|
11923
|
-
"version": "0.3.
|
|
11923
|
+
"version": "0.3.739",
|
|
11924
11924
|
"license": "UNLICENSED",
|
|
11925
11925
|
"dependencies": {
|
|
11926
|
-
"@north-light/api": "0.3.
|
|
11927
|
-
"@north-light/identity": "0.3.
|
|
11926
|
+
"@north-light/api": "0.3.739",
|
|
11927
|
+
"@north-light/identity": "0.3.739"
|
|
11928
11928
|
}
|
|
11929
11929
|
},
|
|
11930
11930
|
"packages/crouter-sdk": {
|
|
11931
11931
|
"name": "@north-light/sdk",
|
|
11932
|
-
"version": "0.3.
|
|
11932
|
+
"version": "0.3.739",
|
|
11933
11933
|
"license": "UNLICENSED",
|
|
11934
11934
|
"dependencies": {
|
|
11935
|
-
"@north-light/api": "0.3.
|
|
11936
|
-
"@north-light/identity": "0.3.
|
|
11937
|
-
"@north-light/plugin": "0.3.
|
|
11935
|
+
"@north-light/api": "0.3.739",
|
|
11936
|
+
"@north-light/identity": "0.3.739",
|
|
11937
|
+
"@north-light/plugin": "0.3.739",
|
|
11938
11938
|
"jose": "^6.2.1"
|
|
11939
11939
|
},
|
|
11940
11940
|
"bin": {
|