@north-light/cli 0.3.782 → 0.3.784
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/api/contract.d.ts +1 -1
- package/dist/api/contract.js +1 -1
- package/dist/api/dto/charges.d.ts +3 -3
- package/dist/api/dto/charges.js +1 -1
- package/dist/builtin-memory/crouter-sdk/release-notes.md +6 -0
- package/dist/builtin-memory/internal/marketplaces.md +1 -1
- package/dist/builtin-memory/internal/storage-tiers.md +1 -1
- package/dist/builtin-pi-packages/pi-crtr-extensions/README.md +3 -3
- package/dist/cli.js +2 -8
- package/dist/clients/attach/viewer.js +1 -1
- package/dist/commands/pkg/account-installs.d.ts +10 -0
- package/dist/commands/pkg/account-installs.js +1 -0
- package/dist/commands/pkg/plugin-manage.d.ts +4 -0
- package/dist/commands/pkg/plugin-manage.js +1 -1
- package/dist/commands/sys/doctor.js +1 -1
- package/dist/commands/sys/provider-login.js +5 -5
- package/dist/commands/sys/setup-core.d.ts +1 -52
- package/dist/commands/sys/setup-core.js +6 -6
- package/dist/commands/sys/setup-wizard.d.ts +4 -9
- package/dist/commands/sys/setup-wizard.js +3 -1
- package/dist/commands/sys/setup.js +1 -1
- package/dist/commands/sys/signin.js +7 -3
- package/dist/core/grants/shadow.js +1 -1
- package/dist/core/grants/sync.js +1 -1
- package/dist/core/ledger/check.d.ts +6 -2
- package/dist/core/ledger/check.js +1 -1
- package/dist/core/llm/run.js +2 -2
- package/dist/core/runtime/first-run-offer.d.ts +2 -6
- package/dist/core/runtime/first-run-offer.js +2 -10
- package/dist/core/runtime/front-door.js +8 -9
- package/dist/core/runtime/package-health.d.ts +1 -1
- package/dist/core/runtime/package-health.js +5 -4
- package/dist/core/runtime/provider-credential-gate.d.ts +1 -1
- package/dist/core/runtime/provider-credential-gate.js +1 -1
- package/dist/core/runtime/runner/machine/executor.d.ts +3 -0
- package/dist/core/runtime/runner/machine/executor.js +2 -1
- package/dist/core/runtime/start-refusal-notice.d.ts +5 -0
- package/dist/core/runtime/start-refusal-notice.js +1 -0
- package/dist/core/scoped-state/seed-terminal-defaults.d.ts +2 -0
- package/dist/core/scoped-state/seed-terminal-defaults.js +1 -0
- package/dist/daemon/cron-run.js +2 -2
- package/dist/daemon/fleet.js +5 -5
- package/dist/daemon/machine-daemon.js +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/freeze-lane.js +1 -1
- package/docs/cli/first-session.md +2 -2
- package/docs/cli/official-marketplace.md +1 -1
- package/docs/sdk/release-notes.md +6 -0
- package/package.json +3 -3
- package/packages/crouter-api/dist/api/contract.js +1 -1
- package/packages/crouter-api/dist/api/dto/charges.js +1 -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/commands/sys/panels/plugin-env-panel.d.ts +0 -19
- package/dist/commands/sys/panels/plugin-env-panel.js +0 -2
- package/dist/commands/sys/panels/plugins-panel.d.ts +0 -16
- package/dist/commands/sys/panels/plugins-panel.js +0 -1
- package/dist/core/runtime/front-door-login.d.ts +0 -2
- package/dist/core/runtime/front-door-login.js +0 -1
|
@@ -1 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var g=Object.defineProperty;var c=(n,r)=>g(n,"name",{value:r,configurable:!0});import{spawn as j}from"node:child_process";import{closeSync as J,existsSync as m,mkdirSync as v,openSync as K,readFileSync as V,statSync as X}from"node:fs";import{rm as W}from"node:fs/promises";import{basename as D,dirname as y,join as h}from"node:path";import{fileURLToPath as Y}from"node:url";import{emitEvent as q}from"../../../events/emit.js";import{contextDir as z,jobDir as Q,nodeRunDir as M,crtrHome as L,viewSocketPath as Z}from"../../../canvas/paths.js";import{captureTeardownSnapshot as ee,isAnyPidAlive as ne,killProcessTreePids as A,listProcessTableAsync as oe}from"../../../canvas/pid.js";import{scopesFilePath as G}from"../../../canvas/paths.js";import{writeFileBeneath as b}from"../../../spaces/open-beneath.js";import{FRONT_DOOR_ENV as te}from"../../front-door-env.js";import{brokerCommandDeclaresCanvasHome as re}from"../../broker-ownership.js";import{isShippedCanvasExtension as ie}from"../../../canvas/extensions.js";import{CANVAS_EXTENSIONS as ce,mergeCanvasExtensions as se}from"../../canvas-extensions.js";import{layoutRoot as ae,runtimeRoot as de}from"../../../layout.js";import{composeAppProcessEnv as ue,overlayBrokerEnv as fe}from"../../spawn-env.js";const R=c(()=>h(y(Y(import.meta.url)),"..","..","broker-cli.js"),"brokerEntry");function le(n){const r=n===void 0?{}:JSON.parse(n),t=h(y(R()),"..","..","builtin-pi-packages","pi-crtr-extensions"),e=(r.packages??[]).filter(o=>!/pi-crtr-extensions/.test(typeof o=="string"?o:String(o.source)));return`${JSON.stringify({...r,packages:[t,...e]},null,2)}
|
|
2
|
+
`}c(le,"withBundledExtensions");const H=c(n=>{if(n!==void 0)try{process.kill(-n,"SIGKILL")}catch{}},"killGroup"),pe=c(n=>new Promise(r=>setTimeout(r,n)),"sleep");async function U(){const n=[],r=await oe();if(r===null)throw new Error("the process table could not be read, so which brokers are running is unknown");for(const{pid:t,command:e}of r){const o=/broker-cli\.js .*--epoch (\S+) (\S+)\s*$/.exec(e);o!==null&&n.push({pid:t,execution:o[1],node:o[2],command:e})}return n}c(U,"findBrokers");const me=["CRTR_HOME","CRTR_RUNTIME_HOME"];function F(n,r){const t={...n};for(const e of me)delete t[e];return t.CRTR_CONTEXT_DIR!==void 0&&(t.CRTR_CONTEXT_DIR=z(r.id,t.CRTR_GRANTEE??r.app)),t.CRTR_SCOPES_FILE!==void 0&&(t.CRTR_SCOPES_FILE=G(r.id)),t}c(F,"localLaunchEnv");function he(n){const r=c(i=>D(i).replace(/\.[jt]s$/,""),"stem"),t=new Set(ce.map(r)),e=c(i=>ie(i)||D(y(i))==="pi-extensions"&&(t.has(r(i))||r(i).startsWith("canvas-")&&!m(i)),"shipped"),o=[],s=[];for(let i=0;i<n.length;i++)if(n[i]==="-e"&&n[i+1]!==void 0){const d=n[++i];if(e(d))continue;if(!m(d))throw new Error(`extension ${d} does not exist on this machine`);s.push(d)}else o.push(n[i]);return[...se(s).flatMap(i=>["-e",i]),...o]}c(he,"localExtensionArgv");function we(n,r,t){const e=JSON.parse(n);return JSON.stringify({...e,argv:he(e.argv),env:F(e.env??{},r),...t===void 0?{}:{start:t}})}c(we,"machineLaunchRecipe");function Ee(n,r,t){const e=n.launch,o=fe({argv:[],env:F(e.env??{},n.node)},ue(n.node.cwd,null,n.node.app,n.machine_env??{},{}));return Object.assign(o,{CRTR_HOME:ae(),CRTR_RUNTIME_HOME:process.env.CRTR_RUNTIME_HOME??de(),CRTR_API_URL:r.apiUrl,CRTR_EXECUTION_ID:t,CRTR_ENVIRONMENT_ID:r.environmentId,CRTR_VIEW_WSS:"0",[te]:"1"})}c(Ee,"machineBrokerEnv");async function $(n,r,t){const{tree:e,identities:o}=ee(n,null,t);if(o===null)return{confirmed:!1,error:`the process tree of broker ${n} could not be read, so shutdown cannot be confirmed`};const s=c(async(i,d)=>{for(let l=0;ne(i);l+=100){if(l>=d)return!1;await pe(100)}return!0},"waitUntilDead");try{process.kill(n,"SIGTERM")}catch{}return await s([n],r),A(e,"SIGTERM",o),await s(e,2e3)?{confirmed:!0}:(A(e,"SIGKILL",o),await s(e,5e3)?{confirmed:!0}:{confirmed:!1,error:`broker process tree of ${n} survived SIGKILL`})}c($,"stopBroker");async function Ae(n=1e4){const t=(await Promise.all((await U()).filter(e=>re(e.command,L())).map(e=>$(e.pid,n)))).filter(e=>!e.confirmed);if(t.length>0)throw new Error(t.map(e=>e.error??"a broker did not stop").join("; "))}c(Ae,"stopAllBrokers");function Ge(n){const r=(n.stopGraceS??10)*1e3,t=c(async e=>(await U()).find(o=>o.execution===e),"brokerOf");return{async start(e,o){const s={};let i=performance.now();const d=c(a=>{const u=performance.now();s[a]=Math.round((u-i)*10)/10,i=u},"stepDone"),l=await t(e.executionId);if(d("process_lookup"),l!==void 0)return{pid:l.pid,timings:s};if(o?.throwIfAborted(),!m(e.cwd)||!X(e.cwd).isDirectory())throw new Error(`the node's cwd ${e.cwd} is not a directory on this machine`);if(!m(R()))throw new Error(`the broker entry ${R()} does not exist`);if(e.bundle===void 0)throw new Error("the control plane carried no start bundle: it runs an older release than this Mac");const{bundle:_}=e,C=_.launch,w=M(e.nodeId);v(w,{recursive:!0}),b(w,h(w,"broker-launch.json"),we(e.launchJson,_.node,e.start),{atomic:!0,mode:384}),C.env?.CRTR_SCOPES_FILE!==void 0&&b(w,G(e.nodeId),JSON.stringify(C.scopes??[]),{atomic:!0});const O=Q(e.nodeId);v(O,{recursive:!0});const I=K(h(O,"broker.log"),"a"),k=Ee(_,n,e.executionId),S=k.PI_CODING_AGENT_DIR,x=h(S,"settings.json");v(S,{recursive:!0}),b(S,x,le(m(x)?V(x,"utf8"):void 0),{atomic:!0}),delete k.CRTR_NODE_TOKEN,d("file_writes");try{o?.throwIfAborted();const a=j(process.execPath,[R(),"--canvas-home",L(),"--epoch",e.executionId,e.nodeId],{cwd:e.cwd,detached:!0,stdio:["ignore",I,I,"pipe"],env:k});let u,N=!1;const P=c(()=>{u!==void 0&&n.onExit?.({execution:e.executionId,node:e.nodeId,...u})},"report");a.once("exit",(T,f)=>{u={code:T,signal:f},N&&P()});const p=a.stdio[3];if(p==null||!("end"in p))throw H(a.pid),new Error("broker token pipe did not open");const B=await new Promise((T,f)=>{a.once("error",f),a.once("spawn",()=>{a.off("error",f),p.once("error",E=>{H(a.pid),f(E)}),p.end(e.nodeToken,E=>{E?f(E):T(a.pid)})})});return N=!0,P(),a.unref(),d("spawn_and_token_pipe"),q({level:"info",event:"machine.start.timing",node_id:e.nodeId,fields:{execution:e.executionId,...s}}),{pid:B,timings:s}}finally{J(I)}},async wake({execution:e}){const o=await t(e.executionId);if(o===void 0)return"no_broker";try{return process.kill(o.pid,"SIGUSR1"),"signalled"}catch(s){if(s.code==="ESRCH")return"no_broker";throw s}},async stop({execution:e,options:o}){const s=await t(e.executionId);return s===void 0?{confirmed:!0}:await $(s.pid,r,o.excludePid)},async status({execution:e}){const o=await t(e.executionId);return o===void 0?{state:"gone"}:{state:"running",pid:o.pid}},async delete({nodeId:e}){return await W(M(e),{recursive:!0,force:!0}),null},async viewer({execution:e}){return{kind:"unix",path:Z(e.nodeId)}}}}c(Ge,"createMachineExecutor");export{Ge as createMachineExecutor,U as findBrokers,he as localExtensionArgv,Ee as machineBrokerEnv,we as machineLaunchRecipe,Ae as stopAllBrokers,le as withBundledExtensions};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Refusal } from '../ledger/index.js';
|
|
2
|
+
/** Report a refused start of `user:<id>` by an app limit or an operator stop; any other refusal is not reported. Never throws. */
|
|
3
|
+
export declare function noticeStartRefusal(refusal: Refusal): Promise<void>;
|
|
4
|
+
/** The same report from the `402 cap_exhausted` a refused revive or respawn threw; any other error is ignored. */
|
|
5
|
+
export declare function noticeStartRefusalError(error: unknown): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var l=Object.defineProperty;var n=(e,t)=>l(e,"name",{value:t,configurable:!0});import{directoryIssuer as f}from"../directory/issuer.js";import{emitEvent as c}from"../events/emit.js";import{describeOutboundFailure as p,outboundFetch as _}from"../events/outbound.js";import{mintDirectoryToken as y}from"../grants/sync.js";import{usageMonth as m}from"../ledger/months.js";import{RunError as g}from"../runs/operations.js";const a=new Set;async function E(e){await u(e.limit)}n(E,"noticeStartRefusal");async function x(e){if(!(e instanceof g)||e.code!=="cap_exhausted")return;const t=e.details?.limit;t!==void 0&&await u({id:t.id,payer:t.payer,source:t.source,grantee:t.filters.grantee})}n(x,"noticeStartRefusalError");async function u(e){const t=f();if(t===null||!e.payer?.startsWith("user:")||e.source!=="grant_sync"&&e.source!=="operator")return;const i=m(),o=`${e.id}|${i}`;if(a.has(o))return;a.add(o);const d=`${t}/v1/runtime/limit-refusals`;try{const r=await y(t),s=await _("limit_refusal_notice",d,{method:"POST",headers:{Authorization:`Bearer ${r.access_token}`,"Content-Type":"application/json"},body:JSON.stringify({user_id:e.payer.slice(5),limit_id:e.id,month:i,reason:e.source==="grant_sync"?"app_limit":"operator_stop",app_id:e.source==="grant_sync"&&e.grantee?.startsWith("app:")?e.grantee.slice(4):null}),signal:AbortSignal.timeout(1e4)});if(s.status===400){c({level:"warn",event:"ledger.start_refusal.notice_rejected",fields:{limit_id:e.id}});return}if(!s.ok)throw new Error(`directory answered the limit refusal notice: ${s.status}`)}catch(r){a.delete(o),c({level:"warn",event:"ledger.start_refusal.notice_failed",error:r,fields:{limit_id:e.id,...p(r)}})}}n(u,"notice");export{E as noticeStartRefusal,x as noticeStartRefusalError};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var d=Object.defineProperty;var s=(a,t)=>d(a,"name",{value:t,configurable:!0});import{withCanvasWrite as l}from"../canvas/db.js";import{applyOpsToRows as w,readSnapshotFromRows as O}from"./person-rows.js";import{emitEvent as E}from"../events/emit.js";import{appRevisionOf as g}from"./person-store.js";import{TERMINAL_APP as c}from"./imported-mac-installs.js";const o={name:"crouter-official-marketplace",url:"https://github.com/crouton-labs/crouter-official-marketplace.git"},S=["capture"],m=s(a=>`terminal_defaults_seeded:${a}`,"seededKey");async function R(){const a=(await l(async e=>await e.prepare("SELECT DISTINCT sub FROM grants WHERE grantee = 'app:terminal' AND status = 'active'").all())).map(e=>e.sub),t=[];for(const e of a)try{await l(async r=>{if(await r.prepare("SELECT 1 FROM canvas_meta WHERE key = ?").get(m(e))!==void 0)return!1;const n=(await O(r,e)).apps[c],p=n===void 0||Object.keys(n.plugins).length===0&&Object.keys(n.marketplaces).length===0;if(p){const u=Object.fromEntries(S.map(f=>[f,{enabled:!0,source_marketplace:o.name}]));await w(r,e,[{op:"app-plugins.replace",app:c,plugins:u,marketplaces:{[o.name]:{url:o.url,ref:"main",installed_at:new Date().toISOString()}},ifRevision:g(n)}])}return await r.prepare("INSERT INTO canvas_meta (key, value) VALUES (?, ?) ON CONFLICT (key) DO NOTHING").run(m(e),new Date().toISOString()),p})&&t.push(e)}catch(i){E({level:"warn",event:"daemon.settings.terminal_defaults_failed",fields:{person:e},error:i})}return t}s(R,"seedTerminalDefaults");export{R as seedTerminalDefaults,m as seededKey};
|
package/dist/daemon/cron-run.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var Y=Object.defineProperty;var i=(e,c)=>Y(e,"name",{value:c,configurable:!0});import{randomUUID as X}from"node:crypto";import{CRON_OUTPUT_HEAD_BYTES as A,formatCronOutputHead as S}from"./cron/capture.js";import{clearLiveRun as
|
|
2
|
-
${q}`.trim().slice(0,A)},lease:"release"}).then(t,a);return}
|
|
1
|
+
var Y=Object.defineProperty;var i=(e,c)=>Y(e,"name",{value:c,configurable:!0});import{randomUUID as X}from"node:crypto";import{CRON_OUTPUT_HEAD_BYTES as A,formatCronOutputHead as S}from"./cron/capture.js";import{clearLiveRun as w,cronDaemonInstanceId as M,ensureCronOwnerLease as z,registerLiveRun as G}from"./cron/live-runs.js";import{closeCronExecution as J,openCronExecution as K}from"./cron/run-socket.js";import{appProcessSandboxed as Q}from"../core/spaces/process.js";import{nodeAgentDir as V}from"../core/canvas/paths.js";import{uidForApp as W}from"../core/spaces/users.js";import{buildArmedRunContext as Z}from"./cron/armed-context.js";import{asPerson as j}from"./reconcilers/node-lifecycle/node-person.js";import{isProfilePaused as ee}from"../core/profiles/manifest.js";import{ensureCronFolder as ne}from"./cron/folders.js";import{cronEnvironment as re,fireInSandbox as te,fireOnMachine as oe,machineLinkLive as ae}from"./cron/machine-fire.js";import{advanceRecurrence as U}from"./cron/recurrence.js";import{checkCronFire as ie,cronPrincipalOf as se}from"./cron/authority.js";import{refusalError as de}from"../core/ledger/index.js";import{noticeStartRefusal as le}from"../core/runtime/start-refusal-notice.js";import{startRefusal as ue}from"../core/runtime/start-check.js";import{settleClosedRun as fe,settleUnspawnedRun as v}from"./cron/closed.js";import{settleRun as B}from"./cron/settle.js";import{applyOverlapPolicies as me,expireDueCrons as ce}from"./cron/passes.js";import{dueClockCrons as pe,acquireCronRunLease as he,releaseCronRunLease as we,attachCronRunPid as _e,HOSTED_CRON_MAX_FIRES as Ce}from"../core/canvas/crons.js";import{emitEvent as $}from"../core/events/emit.js";import{deliverDueDeadline as ge}from"../core/feed/messages.js";import{runAppCommand as xe}from"../core/runtime/run-command.js";import{CRON_OUTPUT_HEAD_BYTES as We}from"./cron/capture.js";import{cronDaemonInstanceId as je,markSelfCanceledCronRun as en}from"./cron/live-runs.js";import{recoverStaleCronLeases as rn}from"./cron/lease-recovery.js";function Je(e,c){return F(e,c).settled}i(Je,"executeCron");function F(e,c){const{outOfBand:s}=c;let l=i(()=>{},"admit");const u=new Promise(t=>{l=t}),_=new Promise((t,a)=>{let p=!1;const r=X();let I=i(()=>{},"undo");const R=i(d=>{if(I(),!p){a(d);return}p=!1,we(e.cron_id,r).then(()=>a(d),f=>{$({level:"error",event:"cron.lease.release_failed",error:f,fields:{cron_id:e.cron_id}}),a(d)})},"fail");(async()=>{const d=Date.now(),f=new Date(d).toISOString(),C={runId:r,outOfBand:s,startedAtIso:f,startedAtMs:d},D=await re(e),b=D?.kind==="machine"?D.id:null;if(b!==null&&!s&&!await ae(b)){t(null);return}if(await z(),!await he(e.cron_id,M,f,s,r,D?.kind==="blaxel"?Ce:null)){t(null);return}p=!0;let m=await ie(se(e));if(m.allowed){e={...e,scopes:m.scopes};const n=await ue({grantee:e.grantee,sub:e.sub,grant_id:e.grant_id});n!==null&&(m={allowed:!1,reason:"limit_reached",message:de(n).message},await le(n))}if(!m.allowed){try{if(!s&&e.recur!=null){const h=await U(e,d);if(h!==null)throw h}}catch(h){v(e,C,"run could not be armed",h).then(t,a);return}const n=Date.now();B(e,{outOfBand:s,outcome:{kind:"refused",reason:m.reason,message:m.message},record:{runId:r,startedAtIso:f,finishedAtMs:n,durationMs:n-d,exitCode:null,stdoutHead:null,stderrHead:`${m.reason}: ${m.message}`.slice(0,A)},lease:"release"}).then(t,a);return}if(D?.kind==="blaxel"){te(e,C,l).then(t,R);return}if(b!==null){oe(e,{environmentId:b,runId:r,outOfBand:s,startedAtIso:f,startedAtMs:d},l).then(t,R);return}let H;try{if(e.isolated&&ne(e.grantee,e.cron_id),{env:H}=await Z(e,r),!s&&e.recur!=null){const n=await U(e,d);if(n!==null)throw n}}catch(n){v(e,C,"run could not be armed",n).then(t,a);return}let k=null,y=!1;const O={runId:r,replaced:!1,selfCanceled:!1,kill:i(()=>{k!==null?k():y=!0},"kill")};G(e.cron_id,O),I=i(()=>w(e.cron_id,r),"undo"),l();const g=Q()?{executionId:r,kind:"cron",cronId:e.cron_id,fromExec:e.armed_from_exec,grantee:e.grantee,sub:e.sub,grantId:e.grant_id,scopes:e.scopes,originRunId:e.origin_run_id,isolated:e.isolated,anchor:e.anchor_node,uid:await W(e.grantee),rebuilt:!1,refusal:null}:null,x=i(()=>{g!==null&&J(r)},"closeExecution");I=i(()=>{w(e.cron_id,r),x()},"undo"),i(async()=>(g!==null&&await K(g,e.cwd,e.profile),xe({command:e.command,cwd:e.cwd,env:H,app:e.grantee,isolated:e.isolated,principal:{sub:e.sub,grantId:e.grant_id,scopes:e.scopes},...e.isolated?{folder:e.cwd}:{},...g!==null?{cron:{executionId:r,...e.anchor_node===null||e.isolated?{}:{anchorDir:V(e.anchor_node,e.grantee)}}}:e.anchor_node===null||e.isolated?{}:{nodeId:e.anchor_node},timeoutMs:e.run_timeout_s*1e3,headBytes:A})),"launch")().then(async n=>{if(n.pid===null){w(e.cron_id,r),x(),n.completion.then(o=>{v(e,C,"run failed to spawn",o.processError??new Error("bash did not provide a process id")).then(t,a)},a);return}I=i(()=>{w(e.cron_id,r),x(),n.terminate()},"undo");let h=!1;const P=i(()=>{n.completion.then(o=>{const T=O.replaced,N=O.selfCanceled,E=g?.refusal??null;if(w(e.cron_id,r),x(),h){t(null);return}if(E!==null&&!T){const L=Date.now(),q=S(o.stderr,o.stderrTruncated);B(e,{outOfBand:s,outcome:{kind:"refused",reason:E.reason,message:E.message},record:{runId:r,startedAtIso:f,finishedAtMs:L,durationMs:L-d,exitCode:o.exitCode,stdoutHead:S(o.stdout,o.stdoutTruncated)||null,stderrHead:`${E.reason}: ${E.message}
|
|
2
|
+
${q}`.trim().slice(0,A)},lease:"release"}).then(t,a);return}fe(e,{runId:r,outOfBand:s,startedAtIso:f,startedAtMs:d,finishedAtMs:Date.now(),code:o.exitCode,timedOut:o.timedOut,processError:o.processError,stdoutHead:S(o.stdout,o.stdoutTruncated),stderrHead:S(o.stderr,o.stderrTruncated),stdoutSha256:o.stdoutSha256,wasReplaced:T,wasSelfCanceled:N}).then(t,a)},a)},"settleCommand");if(!await _e(e.cron_id,M,f,n.pid)&&!O.selfCanceled){h=!0,n.terminate(),P();return}k=n.terminate,y&&n.terminate(),P()},n=>{w(e.cron_id,r),x(),v(e,C,"run failed to spawn",n).then(t,a)}).catch(R)})().catch(R)});return _.then(l,l),{admitted:u,settled:_}}i(F,"startCron");async function Ke(e,c){const s=new Date(e).toISOString();await ce(s),await me(e,s);const l=[];for(const u of await pe(s)){const _=await j(u.sub,async()=>ee(u.profile)?null:u.deadline_body!==null?await ge(u).then(()=>null):F(u,{outOfBand:!1})).catch(r=>($({level:"error",event:"cron.fire_failed",error:r,fields:{cron_id:u.cron_id}}),null));if(_===null)continue;const{admitted:t,settled:a}=_,p=a.then(()=>{});p.catch(()=>{}),await t,l.push(p),c.register?.(p)}for(const u of l)u.catch(()=>{});return l}i(Ke,"runDueCrons");export{We as CRON_OUTPUT_HEAD_BYTES,je as cronDaemonInstanceId,Je as executeCron,en as markSelfCanceledCronRun,rn as recoverStaleCronLeases,Ke as runDueCrons,F as startCron};
|
package/dist/daemon/fleet.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var P=Object.defineProperty;var
|
|
1
|
+
var P=Object.defineProperty;var c=(i,e)=>P(i,"name",{value:e,configurable:!0});import{getNode as w,getRow as R,recordRespawnAttempt as T}from"../core/canvas/index.js";import{revokeExitedNodeToken as N}from"../core/canvas/node-tokens.js";import{PROFILE_PAUSE_STOP_REASON as _,absorbProfilePauseStop as S,endExecution as y,hasLaunchingExecution as F,hasProfilePauseStop as C,hasRunningRemoteExecution as b,liveExecutionForNode as g,liveExecutionNodeIds as O,markProfilePauseStop as k,recordExecutionExit as A,takeObservedExit as M}from"../core/canvas/executions.js";import{isProfilePaused as z}from"../core/profiles/manifest.js";import{fullName as p}from"../core/canvas/labels.js";import{isSafeNodeId as o}from"../core/canvas/paths.js";import{hasIdleReleaseIntent as B,transition as v}from"../core/runtime/lifecycle.js";import{publishNotice as L}from"../core/runtime/close.js";import{hasAdmittedTurn as D,readFault as W,readInterruptedTurn as q,readTransportPoisonVerdict as G}from"../core/canvas/recovery.js";import{hasPendingWake as H}from"./reconcilers/live-obligation.js";import{clearRespawnPolicy as h,deferRespawnWhileOffline as Y,MAX_RESPAWN_ATTEMPTS as U,OFFLINE_RESPAWN_RETRY_MS as V,recordRespawnPolicy as j,respawnBackoffMs as K}from"./reconcilers/node-lifecycle/respawn-policy.js";import{probeOnline as X}from"../core/runtime/connectivity.js";import{runnerForExecution as J}from"../core/runtime/runner/index.js";import{reviveNode as Q}from"../core/runtime/revive.js";import{noticeStartRefusalError as Z}from"../core/runtime/start-refusal-notice.js";import{isStartRefusal as I}from"../core/runtime/start-check.js";import{MachineOfflineError as ee}from"../core/runtime/runner/machine/ops.js";import{pushUrgent as m}from"../core/feed/feed.js";import{emitEvent as f}from"../core/events/emit.js";import{brokerThresholdsForDaemon as te}from"../core/runtime/fleet.js";import{isRecoveryHeld as re}from"../core/runtime/recovery-hold.js";async function E(i,e){const r=await W(i.node_id),t=r===null?"":`The broker reported a ${r.kind} fault on ${r.link} (${r.op}) before it exited: ${r.message}
|
|
2
2
|
|
|
3
3
|
`,s=e===void 0?"The daemon did not observe an exit status.":`The observed exit status was code ${e.code??"null"}, signal ${e.signal??"null"}.`;return`\u26A0 Spawn failed \u2014 \`${i.name}\` (${i.kind}) never started.
|
|
4
4
|
|
|
@@ -6,16 +6,16 @@ Its pi vehicle exited before the session came up (no pi_session_id was ever reco
|
|
|
6
6
|
|
|
7
7
|
`+t+`Inspect canonical event diagnostics with \`crtr sys logs --node ${i.node_id}\`.
|
|
8
8
|
|
|
9
|
-
If the work still needs doing, re-spawn it.`}
|
|
9
|
+
If the work still needs doing, re-spawn it.`}c(E,"bootFailureBody");async function $(i,e){await m(i.node_id,await E(i,e),{from:i.node_id})}c($,"surfaceBootFailure");function x(i){return`\u26A0 Out of memory \u2014 \`${i.name}\` (${i.kind}) was killed because its app's processes together passed the app's memory limit.
|
|
10
10
|
|
|
11
|
-
Every process of the run was stopped. The daemon does not restart it, because it would reach the same limit. Reduce what the run holds in memory, or ask the person to raise the app's limit (\`crtr sys limits set --app ${i.grantee??"app:terminal"} --memory <size>\`), then revive the node.`}
|
|
11
|
+
Every process of the run was stopped. The daemon does not restart it, because it would reach the same limit. Reduce what the run holds in memory, or ask the person to raise the app's limit (\`crtr sys limits set --app ${i.grantee??"app:terminal"} --memory <size>\`), then revive the node.`}c(x,"outOfMemoryBody");async function ie(i){const e=await G(i.node_id),r=e===null?"":`
|
|
12
12
|
|
|
13
13
|
Provider rotation observed ${e.consecutivePasses} consecutive route-queue passes with no HTTP response (tried ${e.routes.join(", ")}). Check network and provider transport before reviving.`,t=`\u26A0 Crash loop \u2014 \`${i.name}\` (${i.kind}) kept dying without settling a turn.
|
|
14
14
|
|
|
15
15
|
Its session started successfully, but six consecutive relaunches made no progress, so the daemon stopped retrying.`+r+`
|
|
16
16
|
|
|
17
|
-
Fix the crash cause, then revive the node if the work still needs doing.`;await m(i.node_id,t,{from:i.node_id})}
|
|
17
|
+
Fix the crash cause, then revive the node if the work still needs doing.`;await m(i.node_id,t,{from:i.node_id})}c(ie,"surfaceCrashLoop");async function se(i,e){const r=e instanceof Error?e.message:String(e),t=`\u26A0 Recovery failed \u2014 \`${i.name}\` (${i.kind}) could not be relaunched.
|
|
18
18
|
|
|
19
19
|
The daemon refused this recovery before starting a broker: ${r}
|
|
20
20
|
|
|
21
|
-
The node is now dead. Fix the recorded launch configuration, then revive it if the work still needs doing.`;await m(i.node_id,t,{from:i.node_id})}
|
|
21
|
+
The node is now dead. Fix the recorded launch configuration, then revive it if the work still needs doing.`;await m(i.node_id,t,{from:i.node_id})}c(se,"surfaceRecoveryFailure");function ae(i,e,r=!0,t=!1){return i===null||i.status==="done"||i.status==="canceled"||i.status==="dead"?"forget":i.intent==="refresh"||i.cycle_pending===!0?"respawn-fresh":B(i)?"dormant":i.lifecycle==="resident"&&!e&&!r&&(i.pi_session_id!=null||t)?"release-idle":i.pi_session_id!=null?"respawn-resume":e||t||i.fork_from!=null?"respawn-fresh":"boot-failure"}c(ae,"classifyDeadNode");const ne=3e4;class Ne{static{c(this,"DaemonFleet")}#a;#n;#r;#o;#e=new Map;#t=new Set;#l=Number.NEGATIVE_INFINITY;constructor(e){this.#a=e.epoch,this.#n=e.enqueue,this.#r=e.now??Date.now,this.#o=e.probeOnline??(()=>X())}epoch(){return this.#a}register(e,r){if(this.#e.has(e))throw new Error(`fleet: ${e} already has a live broker entry \u2014 refusing a second launch (programming error)`);if(r.pid===null)throw new Error(`fleet: refusing to register ${e} with no pid`);this.#t.delete(e),this.#e.set(e,{pid:r.pid,handle:r})}async has(e){return this.#e.has(e)||await b(e)}async isClaimed(e){return this.#e.has(e)||this.#t.has(e)||await b(e)||await F(e,this.#a)}get(e){return this.#e.get(e)}size(){return this.#e.size}async#c(){const e=await O();for(const r of this.#e.keys())e.add(r);for(const r of this.#t)e.add(r);return e}async occupancy(){return(await this.#c()).size}async reserveSlot(e){if(this.#t.has(e)||this.#e.has(e))return!0;const{automaticReviveCap:r}=te(),t=await this.#c();if(this.#t.has(e)||this.#e.has(e))return!0;if(t.delete(e),t.size<r)return this.#t.has(e)||this.#t.add(e),!0;const s=this.#r();return s-this.#l>=ne&&(this.#l=s,f({level:"warn",event:"broker.capacity.revive_deferred",fields:{live_count:t.size,hard_cap:r}})),!1}releaseReservation(e){this.#t.delete(e)}entries(){return this.#e.entries()}async interruptForProfilePause(e,r=this.#e.get(e)?.pid){if(r===void 0){const t=await g(e);if(t===null||t.runner==="process"||t.state!=="running")return;await k(e),(await J(t.runner).stop(t,{reason:_})).confirmed&&await y(t.executionId,{reason:_});return}await k(e);try{process.kill(r,"SIGTERM")}catch{}}async hasProfilePauseInterruption(e){return await C(e)}forget(e){this.#e.delete(e),this.#t.delete(e)}#i=new Set;async exitsSettled(){for(;this.#i.size>0;)await Promise.allSettled([...this.#i])}async onChildExit(e,r,t){const s=this.#u(e,r,t);this.#i.add(s);try{await s}finally{this.#i.delete(s)}}async#u(e,r,t){const s=t??(await g(e))?.executionId;t&&await N(t),this.#e.delete(e),s!==void 0&&(await A(s,r),await y(s,{reason:"exited"})),this.#n(async()=>{const a=await w(e),n=a?.launched_at==null?Number.NaN:Date.parse(a.launched_at),d=Number.isFinite(n)?Math.max(0,this.#r()-n):null,u=a?.respawn_failures??0;this.#f(e,r,d,u)})}async deliverExit(e,r){await this.onChildExit(e,r)}async applyDeadRowPolicy(e){await this.#h(e,await M(e))}async terminalizeIfStillNonTerminal(e,r,t,s,a){const n=await w(e);return n===null||n.status==="done"||n.status==="canceled"||n.status==="dead"?!1:(await this.#s(e,n,{event:r,reason:s,detail:a,wake:`Child crashed \u2014 ${p(n)} (${e}) could not be relaunched and is now dead. It stays dead until you revive it \u2014 \`crtr node lifecycle revive ${e}\`.`,surface:c(()=>se(n,t),"surface")}),!0)}dispose(){}#f(e,r,t,s){f({level:"info",event:"broker.exit.observed",...o(e)?{node_id:e}:{},fields:{...o(e)?{}:{affected_node_id:e},code:r.code,signal:r.signal,uptime_ms:t,consecutive_failures:s}})}async#h(e,r){return this.#d(e,r)}async#d(e,r){const t=await w(e);if(t!==null&&z(t.profile_id))return await h(e),"forget";if(await S(e))return await h(e),"forget";if(await re(e))return"dormant";const s=(await q(e))?.interrupted===!0;if(r?.oomKilled===!0&&t!==null&&t.status!=="done"&&t.status!=="canceled"&&t.status!=="dead")return await h(e),await this.#s(e,t,{event:"broker.out_of_memory",reason:"out_of_memory",detail:{schema:"crtr.node-outcome-detail/v1",message:x(t)},wake:`Child out of memory \u2014 ${p(t)} (${e}) used more memory than its app is allowed and is now dead. It is not restarted automatically. Revive it with \`crtr node lifecycle revive ${e}\` once the work needs less memory or the cap is raised (\`crtr sys limits set\`).`,surface:c(async()=>{await m(e,x(t),{from:e})},"surface")}),"forget";const a=ae(t,s,await H(e),await D(e));switch(a){case"forget":await h(e);break;case"dormant":await h(e);break;case"release-idle":await h(e),await v(e,"release"),f({level:"info",event:"broker.recovery.released",...o(e)?{node_id:e}:{},fields:{...o(e)?{}:{affected_node_id:e}}});break;case"boot-failure":await this.#s(e,t,{event:"broker.boot.failed",reason:"boot_failed",detail:{schema:"crtr.node-outcome-detail/v1",message:await E(t,r)},wake:`Child crashed \u2014 ${p(t)} (${e}) exited before its session ever came up and is now dead. It stays dead until you revive it \u2014 \`crtr node lifecycle revive ${e}\`.`,surface:c(()=>$(t,r),"surface")});break;case"respawn-fresh":case"respawn-resume":await this.#p(e,t,a,s);break}return a}async#p(e,r,t,s){const a=await R(e);if(a===null)return;const n=a.respawn_failures??0;if(!await this.#o()){await Y(e,n,this.#r()),f({level:"info",event:"broker.respawn.offline_deferred",...o(e)?{node_id:e}:{},fields:{...o(e)?{}:{affected_node_id:e},action:t,retry_in_ms:V,consecutive_failures:n}});return}const d=a.respawn_not_before==null,u=d?await j(a,this.#r()):{failures:n,notBefore:a.respawn_not_before,exhausted:n>=U};if(u.exhausted){await T(e,{failures:u.failures,notBefore:null});const l=`Child crashed \u2014 ${p(r)} (${e}) kept dying without settling a turn (${u.failures} consecutive launches) and is now dead. It stays dead until you revive it \u2014 \`crtr node lifecycle revive ${e}\`.`;await this.#s(e,r,{event:"broker.respawn.exhausted",reason:"crash_looped",detail:{schema:"crtr.node-outcome-detail/v1",message:l,respawn_failures:u.failures},wake:l,...r.pi_session_id!=null?{surface:c(()=>ie(r),"surface")}:{}});return}if(d&&u.notBefore!==null){f({level:"info",event:"broker.respawn.deferred",...o(e)?{node_id:e}:{},fields:{...o(e)?{}:{affected_node_id:e},action:t,backoff_ms:K(u.failures),consecutive_failures:u.failures}});return}f({level:"info",event:"broker.respawn.started",...o(e)?{node_id:e}:{},fields:{...o(e)?{}:{affected_node_id:e},action:t,consecutive_failures:u.failures}});try{await Q(e,{capacity:"freeze",resume:t==="respawn-resume",wakeReason:t==="respawn-resume"&&s?"runtime-restart-abort":void 0,recovery:!0})}catch(l){if(I(l)||l instanceof ee){await h(e),await v(e,"release"),f({level:"warn",event:"node.start.refused",node_id:e,error:l,fields:{enact:"respawn"}}),await Z(l);return}f({level:"error",event:"broker.respawn.failed",...o(e)?{node_id:e}:{},error:l,fields:{...o(e)?{}:{affected_node_id:e},action:t}}),await this.terminalizeIfStillNonTerminal(e,"broker.respawn.refused",l,"launch_failed",{schema:"crtr.node-outcome-detail/v1",message:l instanceof Error?l.message:String(l)})}}async#s(e,r,t){f({level:"error",event:t.event,...o(e)?{node_id:e}:{fields:{affected_node_id:e}}}),await v(e,"crash",{reason:t.reason,outcome:{detail:t.detail}});try{await(t.surface??(()=>$(r)))()}catch(s){f({level:"error",event:"broker.boot_failure_surface.failed",...o(e)?{node_id:e}:{fields:{affected_node_id:e}},error:s})}await L(e,"notice.crash",t.wake,{reason:"child-crashed",child:e})}}export{Ne as DaemonFleet,ae as classifyDeadNode,$ as surfaceBootFailure};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var H=Object.defineProperty;var o=(t,r)=>H(t,"name",{value:r,configurable:!0});import{chmodSync as U,closeSync as G,existsSync as L,mkdirSync as b,openSync as N,unlinkSync as J,writeFileSync as Y,rmSync as M}from"node:fs";import{createServer as K}from"node:http";import{dirname as X,join as z}from"node:path";import{spawn as F}from"node:child_process";import{SELF_UPDATE_SCRIPT as V}from"../core/self-update.js";import{apiSocketPath as W,crtrHome as P}from"../core/canvas/paths.js";import{bindDaemonEventSource as $}from"../core/events/source.js";import{emitEvent as a}from"../core/events/emit.js";import{brokerCommandDeclaresCanvasHome as Q}from"../core/runtime/broker-ownership.js";import{createMachineExecutor as Z,findBrokers as q,stopAllBrokers as ee}from"../core/runtime/runner/machine/executor.js";import{machineCheckoutHandlers as ne}from"../core/checkout-identities.js";import{machineWorktreeHandlers as te}from"../core/worktree-machine.js";import{readPersonCredential as oe}from"../core/directory/person-credential.js";import{socketDir as re}from"../core/layout.js";import{isDaemonRunning as ie,pidfilePath as y,readPidfile as ae}from"./pidfile.js";import{spawnDaemon as se}from"./manage.js";import{processGeneration as ce}from"../commands/sys/shared.js";import{cancelMachineCron as de,runMachineCron as le,stopOrphanedMachineCrons as me}from"./cron/machine-exec.js";import{startMachineLink as fe}from"./machine-link/client.js";import{readMachineConfig as pe,readMachineCredential as C}from"./machine-link/config.js";import{jobExitReporting as ue,stopMachineJob as he}from"./machine-link/job-sweep.js";import{machineSupervision as ve,SUPERVISION_TICK_MS as we}from"./machine-supervision.js";import{startBrokerMemoryCap as _e}from"./broker-memory-cap.js";const D=10*6e4,Se=3e4,ye=75;let g=0;function ge(t,r){if(Date.now()-g<D||!/^\d+\.\d+\.\d+$/.test(t))return;g=Date.now(),a({level:"warn",event:"daemon.machine.updating",fields:{release:t}});const s=N(z(P(),"crtrd.err"),"a"),i=F(process.execPath,[V,"--version",t],{stdio:["ignore",s,s]});G(s),i.on("error",c=>a({level:"error",event:"daemon.machine.update_failed",fields:{release:t},error:c})),i.on("exit",c=>{if(c===ye){g=Date.now()-D+Se;return}if(c!==0){a({level:"error",event:"daemon.machine.update_failed",fields:{release:t,exit_code:c}});return}r()})}o(ge,"updateToRelease");const R=1024;function Ie(t,r){return{ok:!0,daemon_up:!0,store_accessible:!1,brokers_reconciled:!1,link_connected:t,signed_in:r,generation_id:ce()?.id??null,startup_phase:t?"ready":"recovering"}}o(Ie,"machineHealth");async function Ve(){const t=pe();if(t===void 0)throw new Error("crtrd --role machine needs runtime/machine.json: this install has not been imported as a machine");const r=oe()!==void 0;if(r&&C(),ie())throw new Error("a crtrd is already running for this home");$(),r||(await ee(),await me(),a({level:"info",event:"daemon.machine.signed_out",fields:{environment:t.environmentId}})),b(re(),{recursive:!0,mode:493});const s=W();L(s)&&J(s);let i;const c=ue(()=>i),f=K((e,n)=>{const d=(e.url??"").split("?")[0];if(e.method==="POST"&&(d==="/job-exit"||d==="/job-activity")){const k=[];let S=0;e.on("data",l=>{S+=l.length,S<=R&&k.push(l)}),e.on("end",()=>{if(S>R){n.writeHead(413),n.end();return}let l={};try{l=JSON.parse(Buffer.concat(k).toString("utf8"))}catch{}const T=typeof l.node=="string"&&typeof l.job=="string";n.writeHead(T?202:400,{"content-type":"application/json; charset=utf-8"}),n.end("{}"),T&&(d==="/job-exit"?c.notice:c.activity)(l.node,l.job)});return}const x=(e.method??"GET")==="GET"&&(e.url??"/").split("?")[0]==="/healthz";n.writeHead(x?200:404,{"content-type":"application/json; charset=utf-8"}),n.end(JSON.stringify(x?Ie(i?.connected()===!0,r):{error:{code:"not_found",message:"a machine-role crtrd serves only /healthz",origin:"runtime"}}))});await new Promise((e,n)=>{f.once("error",n),f.listen(s,()=>{f.off("error",n),U(s,384),e()})}),b(X(y()),{recursive:!0}),Y(y(),String(process.pid),"utf8");let I;const u=new Set,h=new Set;let v=!1;const m=Z({apiUrl:t.apiUrl,environmentId:t.environmentId,onExit:o(e=>i?.reportExit(e),"onExit")}),O=o(async(e,n)=>{u.add(e.executionId);for(const d of h)d.add(e.executionId);try{return await m.start(e,n)}finally{u.delete(e.executionId)}},"start");i=r?fe({apiUrl:t.apiUrl,environmentId:t.environmentId,credential:C,onOpen:o(()=>{c.onOpen(),v=!0},"onOpen"),onBehind:o(e=>ge(e,B),"onBehind"),handlers:{start:O,wake:m.wake,stop:m.stop,status:m.status,delete:m.delete,viewer:m.viewer,"cron.run":le,"cron.cancel":de,"job.stop":o(e=>he(e),"job.stop"),...te,...ne}}):void 0;const E=i===void 0?void 0:ve({link:i,brokers:o(async()=>{const e=new Set(u);h.add(e);const n=await q().finally(()=>h.delete(e));return v&&(v=!1,i?.reportRunning([...new Set([...e,...n.filter(d=>Q(d.command,P())).map(d=>d.execution)])])),n},"brokers"),stop:o((e,n)=>m.stop({execution:{executionId:e,nodeId:n,attempt:0},options:{reason:"yield_stall"}}),"stop")});let w=!1;const j=E===void 0?void 0:setInterval(()=>{w||(w=!0,E(Date.now()).catch(e=>a({level:"error",event:"daemon.machine.supervision_failed",error:e})).finally(()=>{w=!1}))},we),A=_e();a({level:"info",event:"daemon.machine.started",fields:{environment:t.environmentId}}),r&&(async()=>{await(await import("../commands/person-settings.js")).loadPersonSettingsViaApi();const{installed:e,failed:n}=await(await import("../commands/pkg/account-installs.js")).installAccountPlugins();a({level:n.length>0?"warn":"info",event:"daemon.machine.account_plugins",fields:{installed:e,failed:n}})})().catch(e=>a({level:"warn",event:"daemon.machine.account_plugins_failed",error:e}));const _=o(()=>I??=(async()=>{i?.stop(),clearInterval(j),A(),await new Promise(e=>{f.close(()=>e()),f.closeAllConnections()}),ae()===process.pid&&(M(s,{force:!0}),M(y(),{force:!0})),process.off("SIGINT",p),process.off("SIGTERM",p)})(),"teardown"),B=o(async()=>{if(I===void 0){await _();try{const e=await se();a({level:"info",event:"daemon.machine.replaced",fields:{successor_pid:e.pid??e.existing_pid??null}}),process.exit(0)}catch(e){a({level:"error",event:"daemon.machine.successor_failed",error:e}),process.exit(1)}}},"replaceSelf"),p=o(()=>{_().then(()=>process.exit(0),()=>process.exit(1))},"onSignal");return process.on("SIGINT",p),process.on("SIGTERM",p),_}o(Ve,"runMachineDaemon");export{Ie as machineHealth,Ve as runMachineDaemon};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var N=Object.defineProperty;var s=(i,t)=>N(i,"name",{value:t,configurable:!0});import{clearFrozen as w,getNode as y,getRow as D}from"../../../core/canvas/index.js";import{openDb as _}from"../../../core/canvas/db.js";import{fullName as T}from"../../../core/canvas/labels.js";import{isSafeNodeId as l}from"../../../core/canvas/paths.js";import{emitEvent as u}from"../../../core/events/emit.js";import{operationIdContext as z}from"../../../core/events/operation-id.js";import{acknowledgedNodeMailCount as C}from"../../../core/canvas/deliveries.js";import{publishNotice as L}from"../../../core/runtime/close.js";import{transition as p}from"../../../core/runtime/lifecycle.js";import{isStartRefusal as h}from"../../../core/runtime/start-check.js";import{EnvironmentImagePending as A}from"./remote-wake.js";import{asNodePerson as
|
|
1
|
+
var N=Object.defineProperty;var s=(i,t)=>N(i,"name",{value:t,configurable:!0});import{clearFrozen as w,getNode as y,getRow as D}from"../../../core/canvas/index.js";import{openDb as _}from"../../../core/canvas/db.js";import{fullName as T}from"../../../core/canvas/labels.js";import{isSafeNodeId as l}from"../../../core/canvas/paths.js";import{emitEvent as u}from"../../../core/events/emit.js";import{operationIdContext as z}from"../../../core/events/operation-id.js";import{acknowledgedNodeMailCount as C}from"../../../core/canvas/deliveries.js";import{publishNotice as L}from"../../../core/runtime/close.js";import{transition as p}from"../../../core/runtime/lifecycle.js";import{noticeStartRefusalError as M}from"../../../core/runtime/start-refusal-notice.js";import{isStartRefusal as h}from"../../../core/runtime/start-check.js";import{EnvironmentImagePending as A}from"./remote-wake.js";import{asNodePerson as b}from"./node-person.js";import{MachineOfflineError as m}from"../../../core/runtime/runner/machine/ops.js";import{commitReopenResident as I}from"../../../core/runtime/reopen.js";import{reviveNode as E}from"../../../core/runtime/revive.js";import{hasPendingWake as k}from"../live-obligation.js";import{readInterruptedTurn as O}from"../../../core/canvas/recovery.js";import{mapAsync as P}from"../../../core/async-array.js";const R=6,U=10*6e4,x=2e4;async function H(i){const t=await(await _()).prepare("SELECT idle_release_attempts, idle_release_last_attempt_at, idle_release_acked_count FROM nodes WHERE node_id = ?").get(i);return{attempts:Number(t?.idle_release_attempts??0),acknowledgedCount:Number(t?.idle_release_acked_count??0),lastAttempt:t?.idle_release_last_attempt_at==null?void 0:Date.parse(t.idle_release_last_attempt_at)}}s(H,"readEpisode");async function F(i,t,a,e,r){const o=await(await _()).prepare("UPDATE nodes SET idle_release_attempts = ?, idle_release_last_attempt_at = ?, idle_release_acked_count = ? WHERE node_id = ? AND idle_release_attempts = ?").run(a,new Date(r).toISOString(),e,i,t);return Number(o.changes)===1}s(F,"claimAttempt");async function W(i,t){await(await _()).prepare("UPDATE nodes SET idle_release_attempts = ?, idle_release_last_attempt_at = ?, idle_release_acked_count = ? WHERE node_id = ?").run(t.attempts,t.lastAttempt===void 0?null:new Date(t.lastAttempt).toISOString(),t.acknowledgedCount,i)}s(W,"writeEpisode");function $(i,t){if(t)return 2;const a=i.launched_at;if(a==null)return 1;const e=i.last_settled_at;return e==null?2:Date.parse(e)>Date.parse(a)?1:2}s($,"thawTier");function B(i,t){const a=i.row.frozen_at,e=t.row.frozen_at;return a==null?e==null?0:1:e==null?-1:Date.parse(a)-Date.parse(e)}s(B,"compareThaw");const X=16;class _e{static{s(this,"FreezeLaneReconciler")}async endEpisode(t){await(await _()).prepare("UPDATE nodes SET idle_release_attempts = 0, idle_release_last_attempt_at = NULL, idle_release_acked_count = 0 WHERE node_id = ? AND (idle_release_attempts <> 0 OR idle_release_last_attempt_at IS NOT NULL OR idle_release_acked_count <> 0)").run(t)}async run(t,a){const e=await P(a.candidates,async n=>({...n,tier:$(n.row,await k(n.row.node_id))}));e.sort(B);const r={stalled:0,waitingOnMail:0};let o=0;const d=s(async()=>{for(;o<e.length;){const n=e[o++];await z.fresh(()=>b(n.row,()=>this.enact(t,n,a.fleet)))==="frozen"&&(n.tier===1?r.stalled+=1:r.waitingOnMail+=1)}},"worker");return await Promise.all(Array.from({length:Math.min(X,e.length)},d)),r}async enact(t,a,e){const r=a.row.node_id;try{return a.enact==="thaw"?await this.enactThaw(a.row):a.enact==="reopen"?await this.enactReopen(a.row):a.enact==="idle-release"?await this.enactIdleRelease(t,a.row):(await e.applyDeadRowPolicy(r),await e.has(r)?"launched":(await D(r))?.frozen_at!=null?"frozen":"skipped")}catch(o){return u({level:"error",event:"node.lifecycle.enact_failed",...l(r)?{node_id:r}:{},error:o,fields:{...l(r)?{}:{affected_node_id:r},enact:a.enact}}),"skipped"}}async enactReopen(t){await I(t.node_id);try{return(await E(t.node_id,{resume:!0,capacity:"freeze"})).outcome==="frozen"?"frozen":"launched"}catch(a){if(h(a)||a instanceof A||a instanceof m)return await this.settleRefusedStart(t.node_id,a,"reopen");throw a}}async settleRefusedStart(t,a,e){return a instanceof m&&a.sent||await p(t,"release"),await w(t),u({level:"warn",event:"node.start.refused",node_id:t,error:a,fields:{enact:e}}),await M(a),"skipped"}async enactThaw(t){const a=(await O(t.node_id))?.interrupted===!0;if(!a&&t.lifecycle==="resident"&&(await y(t.node_id))?.pi_session_id!=null&&!await k(t.node_id))return await p(t.node_id,"release"),await w(t.node_id),"skipped";try{return(await E(t.node_id,{resume:!0,capacity:"freeze",recovery:!0,...a?{wakeReason:"runtime-restart-abort"}:{}})).outcome==="frozen"?"frozen":"launched"}catch(e){if(h(e)||e instanceof A||e instanceof m)return await this.settleRefusedStart(t.node_id,e,"thaw");const r=await y(t.node_id);throw r!==null&&(r.status==="active"||r.status==="idle")&&(await p(t.node_id,"crash",{reason:"launch_failed",outcome:{detail:{schema:"crtr.node-outcome-detail/v1",message:e instanceof Error?e.message:String(e)}}}),await w(t.node_id)),e}}async enactIdleRelease(t,a){const e=a.node_id,r=await C(e),o=await H(e),d=o.attempts===0||o.acknowledgedCount!==r,n=d?0:o.attempts;if(n>=R)return await this.endEpisode(e),u({level:"warn",event:"broker.idle_release.exhausted",...l(e)?{node_id:e}:{},fields:{...l(e)?{}:{affected_node_id:e},attempts:n,max_attempts:R}}),await p(e,"crash",{reason:"launch_failed",outcome:{detail:{schema:"crtr.node-outcome-detail/v1",respawn_failures:n}}}),await L(e,"notice.crash",`Child crashed \u2014 ${T(a)} (${e}) failed to relaunch after ${n} attempts while trying to deliver a pending inbox message (no delivery progress across any attempt), and is now dead. It stays dead until you revive it \u2014 \`crtr node lifecycle revive ${e}\`.`,{reason:"child-crashed",child:e}),"skipped";const f=d?void 0:o.lastAttempt,S=Math.min(x*2**n,U);if(f!==void 0&&t-f<S||!await F(e,o.attempts,n+1,r,t))return"skipped";const g=s(()=>W(e,{attempts:d?0:n,lastAttempt:d?void 0:o.lastAttempt,acknowledgedCount:r}),"giveBack");let v;try{v=await E(e,{resume:!0,capacity:"freeze"})}catch(c){if(!(c instanceof m||h(c)))throw c;return await g(),await this.settleRefusedStart(e,c,"idle-release")}return v.outcome==="frozen"?(await g(),"frozen"):(u({level:"info",event:"broker.revive.idle_release",...l(e)?{node_id:e}:{},attempt:n+1,fields:{...l(e)?{}:{affected_node_id:e},attempts:n+1,max_attempts:R}}),"launched")}}export{_e as FreezeLaneReconciler,B as compareThaw,$ as thawTier};
|
|
@@ -16,11 +16,11 @@ npm install -g @north-light/cli
|
|
|
16
16
|
crtr
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
The first time you run `crtr` on a machine, it opens the setup installer. Sign in to your Northlight account first (`crtr sys signin`, see [Sign in a machine to your Northlight account](/docs/cli/join-northlight)).
|
|
19
|
+
The first time you run `crtr` on a machine, it opens the setup installer. Sign in to your Northlight account first (`crtr sys signin`, see [Sign in a machine to your Northlight account](/docs/cli/join-northlight)). Signing in installs the plugins your account lists (a new account lists the official plugin marketplace and `capture`). The installer then offers system dependencies such as tmux. On a Mac, a last step explains how to make Option act as Alt in your terminal (crouter's menu is Alt+C), and can write the setting for you in Ghostty or VS Code after you confirm; until it is set, `/menu` opens the same menu. Next it asks which profile this directory belongs to, then opens a conversation with an agent in the same terminal. That first agent offers a short tour; say yes to learn the viewer, the inbox and document review, or just tell it what you're working on.
|
|
20
20
|
|
|
21
21
|
The conversation viewer is a tmux pane. If you ran `crtr` outside tmux, it starts tmux for you: after setup, the profile choice and sign-in, it opens a tmux session named `crouter` (or adds a window to it, if it already exists) and runs your same command there. Your other tmux sessions are left alone. If tmux is not installed, `crtr` tells you how to install it. The first conversation in a session that `crtr` started shows how to leave and come back: `Ctrl+B d` leaves tmux while the agent keeps running, and `Ctrl+B n` / `Ctrl+B p` switch windows. Run without a terminal (piped or in a script), `crtr` never starts tmux.
|
|
22
22
|
|
|
23
|
-
To reopen the installer later, for example to
|
|
23
|
+
To reopen the installer later, for example to install a missing dependency, run `crtr sys setup`. To add a plugin, run `crtr pkg plugin install <marketplace>/<plugin>`.
|
|
24
24
|
|
|
25
25
|
## Start a conversation
|
|
26
26
|
|
|
@@ -9,7 +9,7 @@ The official marketplace is a git repository, [`crouton-labs/crouter-official-ma
|
|
|
9
9
|
|
|
10
10
|
## Add the marketplace
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
A new Northlight account lists the official marketplace and the `capture` plugin, and a signed-in Mac installs whatever its account lists (after `crtr sys signin`, and when its daemon starts). To add the marketplace by hand:
|
|
13
13
|
|
|
14
14
|
```sh
|
|
15
15
|
crtr pkg market add https://github.com/crouton-labs/crouter-official-marketplace.git
|
|
@@ -7,6 +7,12 @@ description: Behavior changes in @north-light/sdk that an app must act on, newes
|
|
|
7
7
|
|
|
8
8
|
Changes to `@north-light/sdk` that can change what an existing app sees. Newest first.
|
|
9
9
|
|
|
10
|
+
## 0.3.783
|
|
11
|
+
|
|
12
|
+
### Every limit refusal carries `details.payment`
|
|
13
|
+
|
|
14
|
+
A `402 cap_exhausted` now always has `details.payment = { reason, message, pay_url, reset_at }`, whatever limit refused: `app_limit` (link to the app's page on the account site), `card_limit` (billing limit), `card_required`, `operator_stop`, and the new `person_limit` (a limit set with `crtr sys spend`; no link). `message` is the sentence to show the person and is also the error's top-level message. `PAYMENT_REFUSAL_REASONS` gains `operator_stop` and `person_limit`; treat an unknown reason as a sentence with no button. The `nothing_left` link is now `<directory>/account/pay`.
|
|
15
|
+
|
|
10
16
|
## 0.3.781
|
|
11
17
|
|
|
12
18
|
`sourcing.read` and `SOURCING_RUN_RULE`. Additive: no request or response an existing app sends or reads changes.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.784",
|
|
4
4
|
"description": "crtr — agent runtime with memory, plugins, and marketplaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -157,8 +157,8 @@
|
|
|
157
157
|
},
|
|
158
158
|
"license": "UNLICENSED",
|
|
159
159
|
"dependencies": {
|
|
160
|
-
"@north-light/identity": "0.3.
|
|
161
|
-
"@north-light/plugin": "0.3.
|
|
160
|
+
"@north-light/identity": "0.3.784",
|
|
161
|
+
"@north-light/plugin": "0.3.784",
|
|
162
162
|
"@earendil-works/chord": "1.5.2",
|
|
163
163
|
"@earendil-works/pi-agent-core": "1.5.2",
|
|
164
164
|
"@earendil-works/pi-ai": "1.5.2",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
//
|
|
13
13
|
// PURITY (spec §3.1): Node built-ins + `src/api/*` only.
|
|
14
14
|
/** The contract level this build serves and requires. Written by `scripts/contract.mjs release`; never edit by hand. */
|
|
15
|
-
export const CONTRACT_LEVEL = '1.
|
|
15
|
+
export const CONTRACT_LEVEL = '1.86';
|
|
16
16
|
/** Request header naming the one contract level the caller needs, e.g. `1.3`. Optional: absent means no check. */
|
|
17
17
|
export const REQUIRED_CONTRACT_HEADER = 'Crouter-Required-Contract';
|
|
18
18
|
/** Response header listing the contract levels the server serves, comma-separated, one per major, e.g. `1.3`. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// The money ledger's read and limit surfaces: `charges.list`, `spend_limits.list`, `spend_limits.set`, `spend_limits.remove`.
|
|
2
2
|
// (`limits.*` and `/v1/limits` are the per-app memory and disk caps; these are dollar limits.)
|
|
3
3
|
/** Why a call was refused for payment. `reason` is what an app branches on; never the message text. */
|
|
4
|
-
export const PAYMENT_REFUSAL_REASONS = ['trial_ended', 'card_required', 'card_limit', 'nothing_left', 'app_limit', 'team_limit', 'app_unpaid', 'account_held'];
|
|
4
|
+
export const PAYMENT_REFUSAL_REASONS = ['trial_ended', 'card_required', 'card_limit', 'nothing_left', 'app_limit', 'team_limit', 'app_unpaid', 'account_held', 'operator_stop', 'person_limit'];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.784",
|
|
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.784",
|
|
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.784",
|
|
31
|
+
"@north-light/identity": "0.3.784"
|
|
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.784",
|
|
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.784",
|
|
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.784",
|
|
32
|
+
"@north-light/plugin": "0.3.784",
|
|
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.784",
|
|
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.784",
|
|
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.784",
|
|
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.784",
|
|
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.784",
|
|
11927
|
+
"@north-light/identity": "0.3.784"
|
|
11928
11928
|
}
|
|
11929
11929
|
},
|
|
11930
11930
|
"packages/crouter-sdk": {
|
|
11931
11931
|
"name": "@north-light/sdk",
|
|
11932
|
-
"version": "0.3.
|
|
11932
|
+
"version": "0.3.784",
|
|
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.784",
|
|
11936
|
+
"@north-light/identity": "0.3.784",
|
|
11937
|
+
"@north-light/plugin": "0.3.784",
|
|
11938
11938
|
"jose": "^6.2.1"
|
|
11939
11939
|
},
|
|
11940
11940
|
"bin": {
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type SetupPanel } from '../../../core/tui/panel.js';
|
|
2
|
-
import type { SetupPluginEnvField } from '../setup-core.js';
|
|
3
|
-
/** Transient wizard input; only masked glyphs are rendered, and values go to the
|
|
4
|
-
* daemon app store after the wizard closes, before package installation. */
|
|
5
|
-
export declare class PluginEnvPanel implements SetupPanel {
|
|
6
|
-
private readonly existing;
|
|
7
|
-
private readonly onChange;
|
|
8
|
-
private fields;
|
|
9
|
-
private index;
|
|
10
|
-
private buffer;
|
|
11
|
-
private readonly entered;
|
|
12
|
-
constructor(existing: Set<string>, onChange: () => void);
|
|
13
|
-
setFields(fields: SetupPluginEnvField[]): void;
|
|
14
|
-
get values(): ReadonlyMap<string, string>;
|
|
15
|
-
badge(): string;
|
|
16
|
-
get complete(): boolean;
|
|
17
|
-
handleInput(data: string): boolean;
|
|
18
|
-
render(width: number): string[];
|
|
19
|
-
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var d=Object.defineProperty;var f=(h,e)=>d(h,"name",{value:e,configurable:!0});import{truncateToWidth as r}from"@earendil-works/pi-tui";import{theme as l,wrapText as a}from"../../../core/tui/panel.js";class x{static{f(this,"PluginEnvPanel")}existing;onChange;fields=[];index=0;buffer="";entered=new Map;constructor(e,t){this.existing=e,this.onChange=t}setFields(e){const t=e.filter(({name:s})=>!this.existing.has(s));if(!(this.fields.length===t.length&&this.fields.every((s,i)=>s.name===t[i]?.name))){const s=new Set(t.map(({name:i})=>i));for(const i of this.entered.keys())s.has(i)||this.entered.delete(i);this.index=0,this.buffer=""}this.fields=t,this.onChange()}get values(){return this.entered}badge(){return`${this.fields.length} keys`}get complete(){return this.index>=this.fields.length}handleInput(e){if(!this.fields.length||this.complete)return!1;if(e==="\r"||e===`
|
|
2
|
-
`)this.buffer&&this.entered.set(this.fields[this.index].name,this.buffer),this.buffer="",this.index=Math.min(this.index+1,this.fields.length);else if(e==="\x7F"||e==="\b")this.buffer=this.buffer.slice(0,-1);else{if(e===""||e==="\x1B")return!1;if(e.length>0&&!/[\x00-\x1f]/.test(e))this.buffer+=e;else return!1}return this.onChange(),!0}render(e){const t=[r(l.fg("accent",l.bold("Plugin credentials")),e)];if(!this.fields.length)return[...t,"No selected plugins need a new key."];t.push("Enter to save or skip each key. Values are never displayed.");for(const[n,s]of this.fields.entries()){const i=n===this.index?"\u25B6":" ",u=this.entered.has(s.name)?"\u2713 saved on finish":n<this.index?"skipped":"";if(t.push(r(`${i} ${s.name} (${s.plugin}) ${u}`,e)),n===this.index){for(const o of a(`${s.declaration.description}${s.declaration.url?` ${s.declaration.url}`:""}`,Math.max(1,e-4)))t.push(r(` ${o}`,e));t.push(r(s.declaration.secret===!1?` ${this.buffer}`:` ${"\u2022".repeat([...this.buffer].length)}`,e))}}return t}}export{x as PluginEnvPanel};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { SetupPackageId, SetupPackageManifestEntry } from '../setup-core.js';
|
|
2
|
-
import { type SetupPanel } from '../../../core/tui/panel.js';
|
|
3
|
-
export declare class PluginsPanel implements SetupPanel {
|
|
4
|
-
private readonly manifest;
|
|
5
|
-
private readonly installedPackageIds;
|
|
6
|
-
private readonly onChange;
|
|
7
|
-
private readonly selectedPackageIds;
|
|
8
|
-
private index;
|
|
9
|
-
private expandedId;
|
|
10
|
-
constructor(manifest: SetupPackageManifestEntry[], installedPackageIds: Set<SetupPackageId>, onChange: () => void);
|
|
11
|
-
badge(): string;
|
|
12
|
-
get selected(): readonly SetupPackageManifestEntry[];
|
|
13
|
-
private current;
|
|
14
|
-
handleInput(data: string, matches?: (id: string, input: string) => boolean): boolean;
|
|
15
|
-
render(width: number): string[];
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var p=Object.defineProperty;var c=(a,e)=>p(a,"name",{value:e,configurable:!0});import{truncateToWidth as d}from"@earendil-works/pi-tui";import{theme as t,wrapText as I}from"../../../core/tui/panel.js";const l="crtr-extensions";class ${static{c(this,"PluginsPanel")}manifest;installedPackageIds;onChange;selectedPackageIds=new Set;index=0;expandedId=null;constructor(e,s,n){this.manifest=e,this.installedPackageIds=s,this.onChange=n;for(const i of e)this.selectedPackageIds.add(i.id)}badge(){const e=this.manifest.filter(s=>!this.installedPackageIds.has(s.id)).length;return e===0?`${this.manifest.length} \u2713`:`${e} pending`}get selected(){return this.manifest.filter(e=>this.selectedPackageIds.has(e.id))}current(){return this.manifest[this.index]}handleInput(e,s){if(s===void 0)return!1;if(s("crtr.setup.list-down",e))this.index=this.manifest.length===0?0:(this.index+1)%this.manifest.length;else if(s("crtr.setup.list-up",e))this.index=this.manifest.length===0?0:(this.index-1+this.manifest.length)%this.manifest.length;else if(s("crtr.setup.toggle",e)){const n=this.current();n&&n.id!==l&&(this.selectedPackageIds.has(n.id)?this.selectedPackageIds.delete(n.id):this.selectedPackageIds.add(n.id))}else if(s("crtr.setup.details",e)){const n=this.current();n&&(this.expandedId=this.expandedId===n.id?null:n.id)}else return!1;return this.onChange(),!0}render(e){const s=[d(t.fg("accent",t.bold("Plugins")),e),d(t.fg("muted","Everything is checked by default. Leave it all on unless you have a specific reason not to."),e)];for(const[n,i]of this.manifest.entries()){const r=n===this.index,h=this.selectedPackageIds.has(i.id)?t.fg("success","[x]"):t.fg("dim","[ ]"),f=r?t.fg("accent","\u25B6"):t.fg("dim"," "),o=r?t.fg("accent",i.name):i.name,g=i.id===l?` ${t.fg("dim","required")}`:"",u=this.installedPackageIds.has(i.id)?t.fg("success","\u2713 installed"):t.fg("warning","not installed");if(s.push(d(`${f} ${h} ${o}${g} ${t.fg("dim","\u2014")} ${t.fg("muted",i.shortDescription)} ${u}`,e)),this.expandedId===i.id)for(const m of I(i.longDescription,Math.max(1,e-4)))s.push(d(t.fg("dim",` ${m}`),e))}return s}}export{$ as PluginsPanel};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var u=Object.defineProperty;var r=(a,t)=>u(a,"name",{value:t,configurable:!0});import{CredentialSynchronizationError as l,LoginDialogComponent as d,OAuthSelectorComponent as p}from"@earendil-works/pi-coding-agent";import{execFile as f}from"node:child_process";import{dialogAuthInteraction as g}from"../auth-interaction.js";import{isManagedProvider as w}from"../managed-providers.js";import{daemonManagedLogin as y}from"../model-auth/daemon-login.js";import{cliClient as h}from"../../commands/api-client.js";import{runSetupSettingsProcess as C}from"../../commands/sys/setup-settings-runner.js";import{buildProviderCatalog as b}from"../../commands/sys/panels/provider-panel.js";function I(a){const t=process.platform==="darwin"?"open":process.platform==="win32"?"cmd":"xdg-open",e=process.platform==="win32"?["/c","start","",a]:[a];f(t,e,{timeout:5e3},()=>{})}r(I,"openBrowser");class L{static{r(this,"FrontDoorLogin")}tui;runtime;agentDir;finish;component;dialog;settled=!1;constructor(t,e,s,o,n){this.tui=t,this.runtime=e,this.agentDir=s,this.finish=n,this.component=new p("login",o,i=>this.startLogin(o.find(c=>c.id===i)),()=>this.complete(!1))}get focused(){return this.component.focused}set focused(t){this.component.focused=t}handleInput(t){this.component.handleInput?.(t)}invalidate(){this.tui.requestRender()}render(t){return this.component.render(t)}dispose(){this.settled||this.dialog?.handleInput("\x1B")}complete(t){this.settled||(this.settled=!0,this.finish(t))}startLogin(t){if(!t){this.complete(!1);return}const e=new d(this.tui,t.id,i=>this.complete(i),t.name);this.dialog=e,this.component=e,this.tui.setFocus(this),this.tui.requestRender();const s=g(e,{openBrowser:I,onChange:r(()=>this.tui.requestRender(),"onChange"),isActive:r(()=>!this.settled&&!e.signal.aborted,"isActive")}),o=r(()=>{e.signal.aborted||this.complete(!1)},"fail");if(t.authType==="api_key"){e.showPrompt(`Enter API key for ${t.name}:`,"sk-...").then(async i=>{if(!i.trim()||this.settled){this.complete(!1);return}await h().installCredential(t.id,{kind:"api_key",api_key:i.trim()}),this.complete(!0)}).catch(o);return}const n=t.id;if(w(n)){y(h(),n,s).then(()=>{this.settled||e.signal.aborted||this.complete(!0)}).catch(o);return}if(!this.runtime.getProvider(n)?.auth.oauth){this.complete(!1);return}this.runtime.login(n,"oauth",s).then(()=>this.complete(!0)).catch(i=>{if(i instanceof l){this.complete(!0);return}o()})}}async function R(){return await C(({tui:t,agentDir:e,runtime:s,registry:o},n)=>new L(t,s,e,b(s,o).map(({providerId:i,name:c,authType:m})=>({id:i,name:c,authType:m})),n.submit))===!0}r(R,"runFrontDoorLogin");export{R as runFrontDoorLogin};
|