@north-light/cli 0.3.667 → 0.3.668
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/client.d.ts +2 -1
- package/dist/api/client.js +1 -1
- package/dist/api/dto/bash-jobs.d.ts +3 -0
- package/dist/api/dto/broker-ops.d.ts +37 -0
- package/dist/api/routes.d.ts +1 -0
- package/dist/api/routes.js +1 -1
- package/dist/clients/attach/render/card-presentation.js +2 -2
- package/dist/clients/attach/viewer.js +258 -258
- package/dist/commands/node/bash.js +4 -4
- package/dist/core/bash-job-supervisor.js +3 -3
- package/dist/core/bash-jobs.js +5 -5
- package/dist/core/canvas/memory-reads.js +2 -1
- package/dist/core/canvas/waits.d.ts +2 -0
- package/dist/core/canvas/waits.js +6 -6
- package/dist/core/feed/messages.d.ts +5 -2
- package/dist/core/feed/messages.js +10 -5
- package/dist/core/grants/mirror.d.ts +11 -3
- package/dist/core/grants/mirror.js +6 -4
- package/dist/core/grants/on-sync.js +1 -1
- package/dist/core/graph/events.d.ts +9 -0
- package/dist/core/graph/events.js +12 -12
- package/dist/core/graph/kinds/document.js +2 -2
- package/dist/core/graph/kinds/kind.d.ts +2 -1
- package/dist/core/graph/kinds/node.js +1 -1
- package/dist/core/graph/names.d.ts +4 -3
- package/dist/core/graph/names.js +10 -9
- package/dist/core/graph/watches.d.ts +11 -2
- package/dist/core/graph/watches.js +13 -9
- package/dist/core/human/requests.d.ts +18 -1
- package/dist/core/human/requests.js +20 -18
- package/dist/core/human/scan.d.ts +3 -2
- package/dist/core/human/scan.js +1 -1
- package/dist/core/runtime/broker/attachments-fetch.d.ts +2 -1
- package/dist/core/runtime/broker/attachments-fetch.js +1 -1
- package/dist/core/runtime/broker/bash-job-launch.js +1 -1
- package/dist/core/runtime/broker/boot-state.d.ts +5 -0
- package/dist/core/runtime/broker/boot-state.js +1 -1
- package/dist/core/runtime/broker/cycle-start.d.ts +50 -0
- package/dist/core/runtime/broker/cycle-start.js +2 -0
- package/dist/core/runtime/broker/fault-retry.js +1 -1
- package/dist/core/runtime/broker/frame-dispatch.d.ts +2 -0
- package/dist/core/runtime/broker/frame-dispatch.js +1 -1
- package/dist/core/runtime/broker/frame-memory-refs.d.ts +2 -0
- package/dist/core/runtime/broker/frame-memory-refs.js +1 -1
- package/dist/core/runtime/broker/job-reporter.d.ts +4 -2
- package/dist/core/runtime/broker/job-reporter.js +2 -2
- package/dist/core/runtime/broker/rebind.d.ts +3 -0
- package/dist/core/runtime/broker/rebind.js +1 -1
- package/dist/core/runtime/broker.js +1 -1
- package/dist/core/runtime/runner/blaxel/image-build.d.ts +3 -0
- package/dist/core/runtime/runner/blaxel/image-build.js +1 -1
- package/dist/core/runtime/runner/blaxel/release-image.d.ts +37 -0
- package/dist/core/runtime/runner/blaxel/release-image.js +3 -0
- package/dist/core/runtime/runner/blaxel/runner.d.ts +1 -1
- package/dist/core/runtime/spawn.js +2 -2
- package/dist/core/secrets/blaxel-launch.d.ts +8 -0
- package/dist/core/secrets/blaxel-launch.js +3 -3
- package/dist/core/substrate/delivery/corpus.d.ts +7 -2
- package/dist/core/substrate/delivery/corpus.js +2 -2
- package/dist/core/substrate/delivery/deliver.js +3 -3
- package/dist/core/substrate/delivery/render-boot.js +27 -27
- package/dist/core/substrate/delivery/render-event.d.ts +5 -4
- package/dist/core/substrate/delivery/render-event.js +6 -6
- package/dist/daemon/api/bridge.js +3 -3
- package/dist/daemon/api/environment-of.d.ts +4 -0
- package/dist/daemon/api/environment-of.js +3 -3
- package/dist/daemon/api/handlers/attach.js +1 -1
- package/dist/daemon/api/handlers/bash-jobs.d.ts +2 -0
- package/dist/daemon/api/handlers/bash-jobs.js +3 -3
- package/dist/daemon/api/handlers/broker-ops.js +1 -1
- package/dist/daemon/api/handlers/broker-recovery.d.ts +2 -0
- package/dist/daemon/api/handlers/broker-recovery.js +1 -1
- package/dist/daemon/api/handlers/canvas.js +6 -6
- package/dist/daemon/api/handlers/inbox.js +1 -1
- package/dist/daemon/api/handlers/node-records.d.ts +7 -0
- package/dist/daemon/api/handlers/node-records.js +1 -1
- package/dist/daemon/api/handlers/nodes.js +1 -1
- package/dist/daemon/api/map.js +2 -2
- package/dist/daemon/api/operations.js +1 -1
- package/dist/daemon/cron/authority.d.ts +3 -1
- package/dist/daemon/cron/authority.js +1 -1
- package/dist/daemon/cron/escalation.js +1 -1
- package/dist/daemon/cron/sinks.js +2 -2
- package/dist/daemon/cron-run.js +2 -2
- package/dist/daemon/crtrd.js +12 -12
- package/dist/daemon/machine-daemon.js +1 -1
- package/dist/daemon/machine-link/client.d.ts +8 -0
- package/dist/daemon/machine-link/client.js +1 -1
- package/dist/daemon/machine-link/frames.d.ts +18 -0
- package/dist/daemon/machine-link/frames.js +1 -1
- package/dist/daemon/machine-link/holder.d.ts +2 -0
- package/dist/daemon/machine-link/holder.js +5 -5
- package/dist/daemon/machine-link/job-sweep.d.ts +15 -0
- package/dist/daemon/machine-link/job-sweep.js +1 -0
- package/dist/daemon/reconcilers/action-lane.js +1 -1
- package/dist/daemon/reconcilers/bash-deadline.js +1 -1
- package/dist/pi-extensions/canvas-context-intro.js +2 -2
- package/dist/pi-extensions/canvas-doc-substrate.js +4 -4
- package/dist/pi-extensions/canvas-passive-context.d.ts +13 -10
- package/dist/pi-extensions/canvas-passive-context.js +9 -12
- package/dist/pi-extensions/canvas-recap.js +6 -6
- package/dist/pi-extensions/canvas-stophook.js +1 -1
- package/dist/pi-extensions/canvas-structured-output.js +6 -6
- package/package.json +2 -2
- package/packages/crouter-identity/package.json +1 -1
- package/runtime.lock.json +13 -13
- package/scripts/sandbox-bootstrap.sh +36 -7
- package/scripts/sandbox-start.mjs +41 -7
|
@@ -5,6 +5,8 @@ interface InputEventLike {
|
|
|
5
5
|
text: string;
|
|
6
6
|
images?: unknown[];
|
|
7
7
|
source: 'interactive' | 'rpc' | 'extension';
|
|
8
|
+
/** Set only while the agent is streaming: how this input will be queued. */
|
|
9
|
+
streamingBehavior?: 'steer' | 'followUp';
|
|
8
10
|
}
|
|
9
11
|
type InputEventResultLike = {
|
|
10
12
|
action: 'continue';
|
|
@@ -18,21 +20,22 @@ type InputEventResultLike = {
|
|
|
18
20
|
interface PiLike {
|
|
19
21
|
on(event: 'input', handler: (event: InputEventLike, ctx: any) => InputEventResultLike | void | Promise<InputEventResultLike | void>): void;
|
|
20
22
|
on(event: 'agent_settled' | 'session_shutdown', handler: (event: any, ctx: any) => void | Promise<void>): void;
|
|
23
|
+
sendMessage: (message: {
|
|
24
|
+
customType: string;
|
|
25
|
+
content: string;
|
|
26
|
+
display: boolean;
|
|
27
|
+
details?: unknown;
|
|
28
|
+
}, options?: {
|
|
29
|
+
deliverAs?: 'steer' | 'followUp' | 'nextTurn';
|
|
30
|
+
triggerTurn?: boolean;
|
|
31
|
+
}) => void;
|
|
21
32
|
}
|
|
22
33
|
/**
|
|
23
34
|
* Render drained passive entries (oldest first) into one XML pre-text block.
|
|
24
35
|
* Each accumulated message is its own timestamped `<update>` element.
|
|
25
36
|
*/
|
|
26
37
|
export declare function formatPassive(entries: BrokerPassiveEntry[], nodeId?: string): Promise<string>;
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
*
|
|
30
|
-
* A runtime card is a WHOLE-message envelope: it opens at byte 0 and closes at
|
|
31
|
-
* the last byte. The inbox watcher's own wake arrives through this same `input`
|
|
32
|
-
* event, so prepending to it would push the envelope off byte 0 and every
|
|
33
|
-
* reader would attribute the digest to the person. Inside the card, the backlog
|
|
34
|
-
* becomes the body's first child instead.
|
|
35
|
-
*/
|
|
36
|
-
export declare function placeBacklog(text: string, preText: string): string;
|
|
38
|
+
/** Runtime-card kind of the backlog message. */
|
|
39
|
+
export declare const PASSIVE_BACKLOG_CARD_KIND = "passive-backlog";
|
|
37
40
|
export declare function registerCanvasPassiveContext(pi: PiLike): void;
|
|
38
41
|
export default registerCanvasPassiveContext;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
var w=Object.defineProperty;var
|
|
2
|
-
`))return
|
|
1
|
+
var w=Object.defineProperty;var l=(r,e)=>w(r,"name",{value:e,configurable:!0});import{envNodeId as v}from"../shared/env.js";import{isAbsolute as b}from"node:path";import{acknowledgeBrokerMail as g,claimBrokerMail as $,readBrokerPassiveMessage as k}from"../core/runtime/broker/daemon-ops.js";import{ApiError as A}from"../api/errors.js";import{wasTurnRefused as C}from"../core/runtime/broker/extension-abort.js";import{emitEvent as T}from"../core/events/emit.js";import{SITUATIONAL_CONTEXT_CUSTOM_TYPE as x,formatCard as I}from"../shared/generated-context.js";const _=4e3;function M(r){if(!r.startsWith(`---
|
|
2
|
+
`))return r;const e=r.indexOf(`
|
|
3
3
|
---
|
|
4
|
-
`,4);return e===-1?
|
|
5
|
-
\u2026 (truncated; read the full report with \`crtr canvas read ${e.ref}\`)`:i}if(
|
|
6
|
-
\u2026 (truncated; full report at ${e.ref})`:
|
|
7
|
-
${await P(e,
|
|
4
|
+
`,4);return e===-1?r:r.slice(e+5)}l(M,"stripFrontmatter");async function P(r,e){if(e.ref!==void 0&&e.ref!==""){const t=e.data?.report_body;if(typeof t=="string"&&t.trim()!==""){const i=t.trim();return i.length>_?`${i.slice(0,_)}
|
|
5
|
+
\u2026 (truncated; read the full report with \`crtr canvas read ${e.ref}\`)`:i}if(b(e.ref))try{const{content:i}=await k(r,e.ref),c=M(i).trim();if(c!=="")return c.length>_?`${c.slice(0,_)}
|
|
6
|
+
\u2026 (truncated; full report at ${e.ref})`:c}catch(i){if(!(i instanceof A)||i.status!==404)throw i}}const u=e.data?.body;return typeof u=="string"&&u.trim()!==""?u.trim():e.label}l(P,"entryContent");function p(r){return r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}l(p,"attr");async function B(r,e=v()??""){const u=(await Promise.all(r.map(async t=>{const i=p(t.from??"system"),c=t.from_name!==void 0&&t.from_name!==""?` from_name="${p(t.from_name)}"`:"",m=t.ref!==void 0&&t.ref!==""?` ref="${p(t.ref)}"`:"";return`<update from="${i}"${c} kind="${p(t.kind)}" at="${p(t.ts)}"${m}>
|
|
7
|
+
${await P(e,t)}
|
|
8
8
|
</update>`}))).join(`
|
|
9
|
-
`);return`<passive-subscription-backlog count="${
|
|
10
|
-
${
|
|
11
|
-
</passive-subscription-backlog>`}
|
|
12
|
-
|
|
13
|
-
${t}`;const r=t.length-l.body.length-I.length;return`${t.slice(0,r)}${e}
|
|
14
|
-
${t.slice(r)}`}u(O,"placeBacklog");function R(t){const e=new Map,l=new Map;let r,i;function f(c){try{A({level:"error",event:"inbox.delivery.failed",outcome:"failed",error:c,fields:{channel:"passive"}})}catch{}}u(f,"reportFailure");async function m(c){if(i!==void 0)return i;if(r===void 0&&(r=[...e.values()].filter(o=>o.injected).map(({claim:o})=>({delivery_id:o.delivery_id,attempts:o.attempts,disposition:j()?"released":"acknowledged"}))),r.length===0)return r=void 0,!0;const a=r,d=(async()=>{try{const o=await h(c,a);if(o.action==="hold")return!1;for(const s of a){const n=o.results.find(y=>y.delivery_id===s.delivery_id);if(n?.outcome!==s.disposition&&n?.outcome!=="stale")throw new Error(`passive mail settlement has no terminal outcome: ${s.delivery_id}`)}for(const s of a)e.delete(s.delivery_id);return r=void 0,!0}catch(o){return f(o),!1}})().finally(()=>{i===d&&(i=void 0)});return i=d,d}u(m,"settle"),t.on("input",async c=>{const a=v();if(!(a===void 0||a.trim()===""))try{if(r!==void 0&&!await m(a))return;const d=await b(a,"passive",l);if(d.action==="hold")return;for(const n of d.deliveries)e.has(n.delivery_id)||e.set(n.delivery_id,{claim:n,injected:!1});const o=[...e.values()].filter(n=>!n.injected);if(o.length===0)return;const s=O(c.text,await E(o.map(({claim:n})=>n.entry),a));for(const n of o)n.injected=!0;return{action:"transform",text:s,images:c.images}}catch(d){f(d);const o=[...e.values()].filter(s=>!s.injected);if(o.length>0)try{const s=await h(a,o.map(({claim:n})=>({delivery_id:n.delivery_id,attempts:n.attempts,disposition:"released"})));if(s.action!=="hold")for(const n of o){const y=s.results.find(_=>_.delivery_id===n.claim.delivery_id)?.outcome;(y==="released"||y==="stale")&&e.delete(n.claim.delivery_id)}}catch(s){f(s)}return}}),t.on("agent_settled",async()=>{const c=v();c!==void 0&&c!==""&&await m(c)}),t.on("session_shutdown",async(c,a)=>{const d=v();d!==void 0&&d!==""&&a?.hasPendingMessages?.()!==!0&&await m(d)})}u(R,"registerCanvasPassiveContext");var Y=R;export{Y as default,E as formatPassive,O as placeBacklog,R as registerCanvasPassiveContext};
|
|
9
|
+
`);return`<passive-subscription-backlog count="${r.length}" note="Reports accumulated from nodes you passively subscribe to while you were not actively listening. Surfaced now because you were messaged. Oldest first.">
|
|
10
|
+
${u}
|
|
11
|
+
</passive-subscription-backlog>`}l(B,"formatPassive");const E="passive-backlog";function O(r){const e=new Map,u=new Map;let t,i;function c(f){try{T({level:"error",event:"inbox.delivery.failed",outcome:"failed",error:f,fields:{channel:"passive"}})}catch{}}l(c,"reportFailure");async function m(f){if(i!==void 0)return i;if(t===void 0&&(t=[...e.values()].filter(o=>o.injected).map(({claim:o})=>({delivery_id:o.delivery_id,attempts:o.attempts,disposition:C()?"released":"acknowledged"}))),t.length===0)return t=void 0,!0;const a=t,d=(async()=>{try{const o=await g(f,a);if(o.action==="hold")return!1;for(const s of a){const n=o.results.find(y=>y.delivery_id===s.delivery_id);if(n?.outcome!==s.disposition&&n?.outcome!=="stale")throw new Error(`passive mail settlement has no terminal outcome: ${s.delivery_id}`)}for(const s of a)e.delete(s.delivery_id);return t=void 0,!0}catch(o){return c(o),!1}})().finally(()=>{i===d&&(i=void 0)});return i=d,d}l(m,"settle"),r.on("input",async f=>{const a=v();if(!(a===void 0||a.trim()===""))try{if(t!==void 0&&!await m(a))return;const d=await $(a,"passive",u);if(d.action==="hold")return;for(const n of d.deliveries)e.has(n.delivery_id)||e.set(n.delivery_id,{claim:n,injected:!1});const o=[...e.values()].filter(n=>!n.injected);if(o.length===0)return;const s=I(E,{},await B(o.map(({claim:n})=>n.entry),a));r.sendMessage({customType:x,content:s,display:!0,details:{nodeId:a}},{deliverAs:f.streamingBehavior??"nextTurn"});for(const n of o)n.injected=!0;return}catch(d){c(d);const o=[...e.values()].filter(s=>!s.injected);if(o.length>0)try{const s=await g(a,o.map(({claim:n})=>({delivery_id:n.delivery_id,attempts:n.attempts,disposition:"released"})));if(s.action!=="hold")for(const n of o){const y=s.results.find(h=>h.delivery_id===n.claim.delivery_id)?.outcome;(y==="released"||y==="stale")&&e.delete(n.claim.delivery_id)}}catch(s){c(s)}return}}),r.on("agent_settled",async()=>{const f=v();f!==void 0&&f!==""&&await m(f)}),r.on("session_shutdown",async(f,a)=>{const d=v();d!==void 0&&d!==""&&a?.hasPendingMessages?.()!==!0&&await m(d)})}l(O,"registerCanvasPassiveContext");var U=O;export{E as PASSIVE_BACKLOG_CARD_KIND,U as default,B as formatPassive,O as registerCanvasPassiveContext};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
`).trim():""}c(
|
|
1
|
+
var W=Object.defineProperty;var c=(t,o)=>W(t,"name",{value:o,configurable:!0});import{envNodeId as U,envRecapIdleMs as V}from"../shared/env.js";import{bootExtensionState as q}from"../core/runtime/broker/boot-state.js";import{brokerExtensionState as F}from"../core/runtime/broker/daemon-ops.js";import{generateRecap as H}from"../core/runtime/recap.js";import{currentOrPendingCausedBy as $}from"../core/runtime/broker/turn-cause.js";import{putBrokerRecap as K}from"../core/runtime/broker/daemon-ops.js";import{isReviewBoundary as Y}from"../core/runtime/session-visibility.js";import{editorLabelForBrokerNode as z}from"../core/runtime/broker-extension-render.js";import{generateAndCommitRecapName as J,readRoadmap as Q}from"./broker-local.js";function X(){return V()}c(X,"idleMs");const Z=7e3,R=5,ee=1200,D="crtr-recap";let M;function te(t){const o=t.content;return typeof o=="string"?o.trim():Array.isArray(o)?o.filter(r=>r!==null&&typeof r=="object"&&r.type==="text"&&typeof r.text=="string").map(r=>(r.text??"").trim()).filter(r=>r!=="").join(`
|
|
2
|
+
`).trim():""}c(te,"messageText");function ne(t,o){let r;try{r=t.getEntries()}catch{return{entries:[],boundaryPresent:o===void 0}}if(o===void 0)return{entries:r,boundaryPresent:!0};const e=r.findIndex(a=>Y(a,o));return e===-1?{entries:[],boundaryPresent:!1}:{entries:r.slice(e+1),boundaryPresent:!0}}c(ne,"recapEntries");function j(t,o,r,e){const{entries:a,boundaryPresent:u}=ne(t,e),l=[],m=c(d=>{const p=d.role;if(p!=="user"&&p!=="assistant")return;let f=te(d);if(f==="")return;f.length>o&&(f=`${f.slice(0,o)} \u2026[truncated]`);const g=`${p==="user"?"User":"Agent"}: ${f}`;l.at(-1)!==g&&l.push(g)},"append");for(const d of a)d.type!=="message"||d.message===void 0||m(d.message);return u&&r?.role==="assistant"&&m(r),l}c(j,"conversationParts");function re(t,o,r){const e=j(t,ee,o,r);if(e.length===0)return"";if(e.length<=R*2)return e.join(`
|
|
3
3
|
|
|
4
|
-
`);const a=e.length-
|
|
4
|
+
`);const a=e.length-R*2;return[...e.slice(0,R),`[\u2026 ${a} message${a===1?"":"s"} omitted \u2026]`,...e.slice(e.length-R)].join(`
|
|
5
5
|
|
|
6
|
-
`)}c(
|
|
6
|
+
`)}c(re,"buildConversation");function ie(t,o,r){const e=j(t,600,o,r);if(e.length===0)return"";const a=48;return e.length<=a?e.join(`
|
|
7
7
|
|
|
8
8
|
`):Array.from({length:a},(l,m)=>{const d=Math.round(m*(e.length-1)/(a-1));return e[d]}).join(`
|
|
9
9
|
|
|
10
|
-
`)}c(
|
|
11
|
-
`).filter(n=>n.trim()!=="");if(s.length!==0)try{a.setWidget(
|
|
10
|
+
`)}c(ie,"buildNamingConversation");function se(t,o=H,r){const e=U();if(e===void 0||e.trim()==="")return;let a,u,l,m;const d=c(i=>{const s=i.model?.provider?.trim(),n=i.model?.id?.trim();s&&n&&(m=`${s}/${n}`)},"captureLiveModel");let p=Date.now(),f=0,g,_=!1,S=!1,E=!1,y=!1,I;const v=c(()=>a!==void 0&&typeof a.setWidget=="function","canPaint"),P=c(i=>{try{a?.notify?.(i,"info")}catch{}},"notify"),k=c(()=>{if(v())try{a.setWidget(D,void 0,{placement:"aboveEditor"})}catch{}},"clearRecap"),B=c(i=>{if(!v()||i==="")return;const s=i.split(`
|
|
11
|
+
`).filter(n=>n.trim()!=="");if(s.length!==0)try{a.setWidget(D,s,{placement:"aboveEditor"})}catch{}},"showRecap"),w=c(()=>{p=Date.now(),f+=1,E=!1,_&&(S=!0)},"onMessage"),T=c(i=>{if(t.getSessionName===void 0||t.setSessionName===void 0)return;if(r!==void 0){const n=t.getSessionName();if(n===void 0)return;r(e,i,()=>t.getSessionName?.()===n,h=>{try{t.setSessionName?.(h)}catch{}});return}const s=$()??null;F(e).then(({node:n})=>{if(n.name.trim()!==""&&n.name!==n.kind)return;const h=z(n);t.getSessionName?.()===h&&J(e,i,{name:n.name,description:n.description??"",title:n.title??"",icon:n.icon??"",kind:n.kind},()=>t.getSessionName?.()===h,s,x=>{try{t.setSessionName?.(x)}catch{}})}).catch(()=>{})},"refreshAutomaticName"),C=c(i=>{if(!v()||u===void 0||y)return;const s=g,n=l?.review_binding?.review_id??u.getEntries().map(A=>A.details?.reviewId).find(A=>typeof A=="string"),h=re(u,s,n);if(h===""){E=!0,_=!1,S=!1,k();return}E=!1;const x=i?ie(u,s,n):"",b=f;i||(I=b),y=!0,i&&(P("Generating recap\u2026"),T(x));const L=$()??null;Q(e).catch(()=>null).then(A=>o(h,G=>{!i&&f!==b||!v()||K(e,G).then(()=>{!i&&f!==b||!v()||(_=!0,S=f!==b,B(G),i&&P("Recap ready"))}).catch(O=>P(`Recap could not be saved: ${String(O)}`)).finally(()=>{y=!1})},m,A??void 0,L)),setTimeout(()=>{y=!1},3e4).unref?.()},"requestRecap");t.registerCommand?.("recap",{description:"Generate a Goal/State recap and refresh the original generated session title",handler:c((i,s)=>{a=s.ui,u=s.sessionManager,d(s),C(!0)},"handler")}),t.on("session_start",(i,s)=>{a=s.ui,u=s.sessionManager,d(s),l=void 0,q(e).then(n=>{l=n.node}).catch(()=>{}),p=Date.now(),f=0,g=void 0,_=!1,S=!1,E=!1,y=!1,I=void 0,k()}),t.on("input",(i,s)=>{w()}),t.on("message_update",(i,s)=>{const n=i?.message;n?.role==="assistant"&&(g=n),w()}),t.on("turn_end",(i,s)=>{g=void 0,d(s),w()}),M!==void 0&&clearInterval(M);const N=setInterval(()=>{try{if(!v()||u===void 0||E||_&&!S||y||I===f||Date.now()-p<X())return;C(!1)}catch{}},Z);typeof N.unref=="function"&&N.unref(),M=N,t.on("session_shutdown",()=>{clearInterval(N),M===N&&(M=void 0)})}c(se,"registerCanvasRecap");var he=se;export{he as default,se as registerCanvasRecap};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var K=Object.defineProperty;var l=(r,t)=>K(r,"name",{value:t,configurable:!0});import{brokerSignalClient as C}from"../core/runtime/broker/signal-stream.js";import{brokerExecutionId as Z}from"../core/runtime/broker/daemon-ops.js";import{envNodeId as ee}from"../shared/env.js";import{stripCdPrefix as te}from"../shared/strip-cd-prefix.js";import{brokerRecovery as ne,mutateBrokerFault as Y,recordBrokerTelemetry as re,recordBrokerTurn as A,clearBrokerPushedFinal as oe,consumeBrokerPushedFinal as se}from"../core/runtime/broker/daemon-ops.js";import{bindBrokerSession as ae,cachedBrokerNode as j,postBrokerIdle as ie,relaunchBrokerRoot as le,settleBroker as z,startBrokerCycle as ce}from"../core/runtime/broker/daemon-ops.js";import{emitEvent as F}from"../core/events/emit.js";import{brokerStartCycle as ue}from"../core/runtime/broker/held-deferred-inbox.js";import{CONTEXT_NUDGE_CUSTOM_TYPE as de,formatCard as fe}from"../shared/generated-context.js";import{isReviewBoundary as he}from"../core/runtime/session-visibility.js";import{clearRefusedTurn as ye,isRuntimeTeardownInProgress as me,refuseTurn as pe,runRefreshAbort as ge}from"../core/runtime/broker/extension-abort.js";import{announceMessageOrigin as G}from"../core/runtime/stamp/channel.js";const Q=80;function we(r,t){const i=t??{},s=l(w=>typeof w=="string"?w:"","pick"),c=te(s(i.command).trim())||s(i.path)||s(i.file_path)||s(i.pattern)||s(i.description)||s(i.prompt),f=(c!==""?`${r}: ${c}`:r).replace(/\s+/g," ").trim();return f.length>Q?f.slice(0,Q):f}l(we,"summarizeActivity");function _e(r){for(let t=r.length-1;t>=0;t--)if(r[t]?.role==="assistant")return r[t]}l(_e,"lastAssistantMessage");function ke(r){try{const t=r?.sessionManager?.getBranch();if(!Array.isArray(t))return[];const i=new Set;for(const s of t){if(!he(s))continue;const u=s.details?.reviewId;typeof u=="string"&&i.add(u)}return[...i]}catch{return[]}}l(ke,"currentReviewBoundaryIds");const V=1e4,x=[13e4,15e4,17e4,185e3,2e5];function be(r){const t=x[0],i=x[x.length-1];if(r<t)return null;if(r>=i)return i+Math.floor((r-i)/V)*V;let s=t;for(const u of x)r>=u&&(s=u);return s}l(be,"steerBand");function ve(r,t,i){const s=Math.round(r/1e3),u=r>=185e3,c="This is not a request to stop: keep going until your task is done.";if(i==="orchestrator")return r<15e4?`Context ~${s}k and growing. ${c} When you reach a good stopping point, consider updating your roadmap (\`crtr doc edit roadmap\`) and running \`crtr node yield\` to refresh against it \u2014 no rush yet.`:u?`Context ~${s}k \u2014 this is getting long. ${c} Bring your roadmap current, hand off anything outstanding, and \`crtr node yield\` immediately to refresh before this context overflows; the fresh window continues the work.`:`Context ~${s}k. ${c} Update your roadmap (\`crtr doc edit roadmap\`) so a fresh revive can continue, delegate any outstanding work, then \`crtr node yield\` to refresh.`;if(t==="resident"){const f="If substantial work remains, `crtr node yield` to continue fresh against your goal and your note. Add --promote only when worthwhile independent work can run in parallel and coordinating it should become your primary job; `crtr node yield -h` has the boundary.";return r<15e4?`Context ~${s}k and growing. ${c} ${f} Otherwise no rush.`:u?`Context ~${s}k \u2014 this is getting long. ${c} If little remains, finish the task now; if much remains, \`crtr node yield\` immediately, with a note saying where things stand, to continue fresh against your goal before this context overflows.`:`Context ~${s}k. ${c} ${f} If little remains, finish the task here; if much remains, \`crtr node yield\` rather than letting this context grow.`}return r<15e4?`Context ~${s}k and growing. ${c} If the task is done, finish with \`crtr push final\`. If real work remains, \`crtr node yield\` to continue in a fresh window against your goal and your note \u2014 no rush yet.`:u?`Context ~${s}k \u2014 this is getting long. ${c} \`crtr push final\` only if the task is done; otherwise \`crtr node yield\` immediately, with a note saying where things stand, to continue in a fresh window before this context overflows.`:`Context ~${s}k. ${c} If the task is done, finish with \`crtr push final\`; otherwise \`crtr node yield\` now to refresh into a clean window and keep going against your goal and your note.`}l(ve,"steerNote");function Te(r){const t=ee();if(t===void 0||t.trim()==="")return;let i=0,s=0,u="",c=null,f=null;const w=new Set;let k=!1,I=!1;const N=l(e=>{if(!I){I=!0;try{ge(()=>e?.abort?.())}catch{}}},"abortForRefresh");let v;const W=C().subscribe("node",()=>{const e=C();k&&e.state==="connected"&&e.latestNode?.intent==="refresh"&&N(v)}),d=l((e,n)=>{F({event:"broker.daemon.operation.failed",level:"error",node_id:t,error:n,fields:{operation:e}})},"emitDaemonOperationFailure"),X=l(async e=>{try{const n=ue();if(n===void 0)throw new Error("broker has no in-place cycle start");const o=await ce(t);if(o.action==="restart"){e?.shutdown?.();return}if(!await n(o))return}catch(n){d("cycle",n);try{e?.shutdown?.()}catch{}}},"startNextCycle"),D=l((e,n)=>{if(e.action==="new_cycle"){X(n);return}if(e.action==="reprompt"){G(e.prompt,{type:"runtime",kind:"stop-guard"}),r.sendUserMessage(e.prompt,{deliverAs:"followUp"});return}if(e.action==="stay_resident"){ie(t).then(()=>C().stop(),o=>d("idle",o));return}if(e.action==="shutdown")try{n?.shutdown?.()}catch{}},"enactSettleDirective"),J=3e3;let O=0,$=Promise.resolve(),h=null,U=null,q=-1/0,m=null,S=0;const B=l(()=>{if(h===null||h===U)return;const e=h;U=e,q=Date.now(),$=$.then(()=>re(t,e)).catch(n=>d("telemetry",n))},"queueTelemetry"),R=l((e,n)=>{if(h!==null&&h.tokens_in===i&&h.tokens_out===s&&h.model===u&&h.context_tokens===e&&h.last_activity===n)return;S=Math.max(Date.now(),S+1),h={tokens_in:i,tokens_out:s,model:u,context_tokens:e,last_activity:n,updated_at:new Date(S).toISOString()};const o=2e3-(Date.now()-q);o<=0?B():m===null&&(m=setTimeout(()=>{m=null,B()},o),m.unref?.())},"publishTelemetry"),E=l(()=>(m!==null&&clearTimeout(m),m=null,B(),$),"flushTelemetry");let P=Promise.resolve();const H=l(e=>(P=P.catch(()=>{}).then(async()=>{const n=await A(t,{event:"progress"});if(n.fault_link==="daemon\u2192node"&&(await ne(t)).fault?.op==="conversation_write_failed"){if(!e)return;await(await import("../core/conversation-store/index.js")).flushConversation(),await Y(t,{op:"clear",link:"daemon\u2192node"})}else(n.fault_link==="daemon\u2192node"||e&&n.fault_link==="pi\u2192provider")&&await Y(t,{op:"clear",link:n.fault_link})}),P),"reportProgress"),T=l(()=>{const e=Date.now();e-O<J||(O=e,H(!1).catch(n=>d("turn_progress",n)))},"heartbeat");r.on("session_start",async(e,n)=>{try{const o=n?.sessionManager?.getSessionId?.();if(typeof o!="string"||o==="")return;const p=n?.sessionManager?.getSessionFile?.(),g=typeof p=="string"&&p!==""?p:null,_=typeof e?.reason=="string"?e.reason:null;_==="new"&&(i=0,s=0,w.clear());const a=await ae(t,{piSessionId:o,sessionFile:g,pid:process.pid,reason:_,reviewBoundaryIds:ke(n)});if(a.action==="none"&&C().start(t,Z()),a.action==="shutdown"){try{n?.shutdown?.()}catch{}return}if(a.action==="relaunch_root"){le(t).catch(y=>{const b=y instanceof Error?y.message:String(y);n?.ui?.notify?.(`/new refused: ${b}`,"error"),F({event:"broker.daemon.operation.failed",level:"error",node_id:t,error:y,fields:{operation:"relaunch_root"}})});return}}catch(o){F({event:"broker.daemon.operation.failed",level:"error",node_id:t,error:o,fields:{operation:"session_bound"}})}}),r.on("agent_start",async(e,n)=>{k=!0,v=n;try{if(!(await A(t,{event:"started"})).applied)throw new Error("daemon refused turn open")}catch(o){d("turn_open",o),n?.ui?.notify?.("Turn refused: the broker no longer owns this node.","error"),pe(()=>n?.abort?.())}}),r.on("input",async()=>{k||(I=!1),ye();try{await oe(t)}catch(e){throw d("clear_pushed_final",e),e}}),r.on("tool_execution_start",e=>{try{f=we(String(e?.toolName??""),e?.args),R(c,f),T()}catch{}}),r.on("tool_execution_update",()=>{try{T()}catch{}}),r.on("message_update",()=>{try{T()}catch{}}),r.on("tool_execution_end",async(e,n)=>{try{T(),(await j(t)).intent==="refresh"&&N(n)}catch{}}),r.on("session_shutdown",async(e,n)=>{W(),k=!1,v=void 0,await E();try{await A(t,{event:"closed",end_reason:"teardown-aborted"})}catch(o){d("turn_close_teardown",o)}if(e?.reason==="quit")try{const o=await z(t,{stopReason:"quit",pushedFinal:!1,inPlaceCycle:!0});D(o,n)}catch(o){d("settle_quit",o)}});const L=l(e=>{e?.role!=="assistant"||e.usage==null||(i+=Number(e.usage.input??0)||0,s+=Number(e.usage.output??0)||0,typeof e.model=="string"&&e.model!==""&&(u=e.model))},"accumulate");r.on("turn_end",async(e,n)=>{L(e?.message);let o=null;try{const a=n.getContextUsage()?.tokens;typeof a=="number"&&(o=a)}catch{}o!==null&&(c=o),R(o,f),await E();try{const a=e?.message?.stopReason!=="error"&&e?.message?.stopReason!=="aborted";await H(a)}catch(a){d("turn_end_fault_clear",a)}const p=Array.isArray(e?.message?.content)?e.message.content:[],g=e?.message?.stopReason??"",_=g!=="error"&&g!=="aborted"&&p.some(a=>a?.type==="toolCall");try{const a=o!==null?be(o):null,y=a!==null&&!w.has(a)?await j(t):null;if(a!==null&&y!==null){w.add(a);const b=fe("context-nudge",{},ve(a,y.lifecycle,y.mode));_?(G(b,{type:"runtime",kind:"context-nudge"}),r.sendUserMessage(b,{deliverAs:"steer"})):r.sendMessage({customType:de,content:b,display:!0},{deliverAs:"nextTurn"})}}catch(a){d("turn_boundary",a)}});let M=null;r.on("agent_end",e=>{M=e;try{const n=Array.isArray(e?.messages)?e.messages:[];for(const o of n)L(o)}catch{}}),r.on("agent_settled",async(e,n)=>{k=!1,v=void 0,R(c,f),await E();const o=M;if(M=null,me())return;try{await A(t,{event:"closed",end_reason:"settled"})}catch(a){d("turn_close",a);return}const p=Array.isArray(o?.messages)?o.messages:[],g=_e(p),_=typeof g?.stopReason=="string"?g.stopReason:"";try{const a=o===null?{pushedFinal:!1}:await se(t),y=await z(t,{stopReason:_,pushedFinal:a.pushedFinal,inPlaceCycle:!0});D(y,n)}catch(a){d("settle",a)}})}l(Te,"registerCanvasStophook");var De=Te;export{De as default,Te as registerCanvasStophook,ve as steerNote};
|
|
1
|
+
var Z=Object.defineProperty;var l=(r,t)=>Z(r,"name",{value:t,configurable:!0});import{brokerSignalClient as C}from"../core/runtime/broker/signal-stream.js";import{brokerExecutionId as ee}from"../core/runtime/broker/daemon-ops.js";import{takeCycleBind as te}from"../core/runtime/broker/cycle-start.js";import{markSeededStateBound as ne}from"../core/runtime/broker/boot-state.js";import{envNodeId as re}from"../shared/env.js";import{stripCdPrefix as oe}from"../shared/strip-cd-prefix.js";import{brokerRecovery as se,mutateBrokerFault as Y,recordBrokerTelemetry as ae,recordBrokerTurn as A,clearBrokerPushedFinal as ie,consumeBrokerPushedFinal as le}from"../core/runtime/broker/daemon-ops.js";import{bindBrokerSession as ce,cachedBrokerNode as j,postBrokerIdle as ue,relaunchBrokerRoot as de,settleBroker as z,startBrokerCycle as fe}from"../core/runtime/broker/daemon-ops.js";import{emitEvent as F}from"../core/events/emit.js";import{brokerStartCycle as he}from"../core/runtime/broker/held-deferred-inbox.js";import{CONTEXT_NUDGE_CUSTOM_TYPE as me,formatCard as ye}from"../shared/generated-context.js";import{isReviewBoundary as pe}from"../core/runtime/session-visibility.js";import{clearRefusedTurn as ge,isRuntimeTeardownInProgress as we,refuseTurn as _e,runRefreshAbort as ke}from"../core/runtime/broker/extension-abort.js";import{announceMessageOrigin as G}from"../core/runtime/stamp/channel.js";const Q=80;function be(r,t){const i=t??{},s=l(_=>typeof _=="string"?_:"","pick"),c=oe(s(i.command).trim())||s(i.path)||s(i.file_path)||s(i.pattern)||s(i.description)||s(i.prompt),f=(c!==""?`${r}: ${c}`:r).replace(/\s+/g," ").trim();return f.length>Q?f.slice(0,Q):f}l(be,"summarizeActivity");function ve(r){for(let t=r.length-1;t>=0;t--)if(r[t]?.role==="assistant")return r[t]}l(ve,"lastAssistantMessage");function Te(r){try{const t=r?.sessionManager?.getBranch();if(!Array.isArray(t))return[];const i=new Set;for(const s of t){if(!pe(s))continue;const u=s.details?.reviewId;typeof u=="string"&&i.add(u)}return[...i]}catch{return[]}}l(Te,"currentReviewBoundaryIds");const V=1e4,S=[13e4,15e4,17e4,185e3,2e5];function Ce(r){const t=S[0],i=S[S.length-1];if(r<t)return null;if(r>=i)return i+Math.floor((r-i)/V)*V;let s=t;for(const u of S)r>=u&&(s=u);return s}l(Ce,"steerBand");function Ae(r,t,i){const s=Math.round(r/1e3),u=r>=185e3,c="This is not a request to stop: keep going until your task is done.";if(i==="orchestrator")return r<15e4?`Context ~${s}k and growing. ${c} When you reach a good stopping point, consider updating your roadmap (\`crtr doc edit roadmap\`) and running \`crtr node yield\` to refresh against it \u2014 no rush yet.`:u?`Context ~${s}k \u2014 this is getting long. ${c} Bring your roadmap current, hand off anything outstanding, and \`crtr node yield\` immediately to refresh before this context overflows; the fresh window continues the work.`:`Context ~${s}k. ${c} Update your roadmap (\`crtr doc edit roadmap\`) so a fresh revive can continue, delegate any outstanding work, then \`crtr node yield\` to refresh.`;if(t==="resident"){const f="If substantial work remains, `crtr node yield` to continue fresh against your goal and your note. Add --promote only when worthwhile independent work can run in parallel and coordinating it should become your primary job; `crtr node yield -h` has the boundary.";return r<15e4?`Context ~${s}k and growing. ${c} ${f} Otherwise no rush.`:u?`Context ~${s}k \u2014 this is getting long. ${c} If little remains, finish the task now; if much remains, \`crtr node yield\` immediately, with a note saying where things stand, to continue fresh against your goal before this context overflows.`:`Context ~${s}k. ${c} ${f} If little remains, finish the task here; if much remains, \`crtr node yield\` rather than letting this context grow.`}return r<15e4?`Context ~${s}k and growing. ${c} If the task is done, finish with \`crtr push final\`. If real work remains, \`crtr node yield\` to continue in a fresh window against your goal and your note \u2014 no rush yet.`:u?`Context ~${s}k \u2014 this is getting long. ${c} \`crtr push final\` only if the task is done; otherwise \`crtr node yield\` immediately, with a note saying where things stand, to continue in a fresh window before this context overflows.`:`Context ~${s}k. ${c} If the task is done, finish with \`crtr push final\`; otherwise \`crtr node yield\` now to refresh into a clean window and keep going against your goal and your note.`}l(Ae,"steerNote");function Se(r){const t=re();if(t===void 0||t.trim()==="")return;let i=0,s=0,u="",c=null,f=null;const _=new Set;let b=!1,x=!1;const N=l(e=>{if(!x){x=!0;try{ke(()=>e?.abort?.())}catch{}}},"abortForRefresh");let v;const W=C().subscribe("node",()=>{const e=C();b&&e.state==="connected"&&e.latestNode?.intent==="refresh"&&N(v)}),d=l((e,n)=>{F({event:"broker.daemon.operation.failed",level:"error",node_id:t,error:n,fields:{operation:e}})},"emitDaemonOperationFailure"),X=l(async e=>{try{const n=he();if(n===void 0)throw new Error("broker has no in-place cycle start");const o=await fe(t);if(o.action==="restart"){e?.shutdown?.();return}if(!await n(o))return}catch(n){d("cycle",n);try{e?.shutdown?.()}catch{}}},"startNextCycle"),D=l((e,n)=>{if(e.action==="new_cycle"){X(n);return}if(e.action==="reprompt"){G(e.prompt,{type:"runtime",kind:"stop-guard"}),r.sendUserMessage(e.prompt,{deliverAs:"followUp"});return}if(e.action==="stay_resident"){ue(t).then(()=>C().stop(),o=>d("idle",o));return}if(e.action==="shutdown")try{n?.shutdown?.()}catch{}},"enactSettleDirective"),J=3e3;let O=0,I=Promise.resolve(),h=null,U=null,q=-1/0,p=null,$=0;const B=l(()=>{if(h===null||h===U)return;const e=h;U=e,q=Date.now(),I=I.then(()=>ae(t,e)).catch(n=>d("telemetry",n))},"queueTelemetry"),R=l((e,n)=>{if(h!==null&&h.tokens_in===i&&h.tokens_out===s&&h.model===u&&h.context_tokens===e&&h.last_activity===n)return;$=Math.max(Date.now(),$+1),h={tokens_in:i,tokens_out:s,model:u,context_tokens:e,last_activity:n,updated_at:new Date($).toISOString()};const o=2e3-(Date.now()-q);o<=0?B():p===null&&(p=setTimeout(()=>{p=null,B()},o),p.unref?.())},"publishTelemetry"),P=l(()=>(p!==null&&clearTimeout(p),p=null,B(),I),"flushTelemetry");let E=Promise.resolve();const H=l(e=>(E=E.catch(()=>{}).then(async()=>{const n=await A(t,{event:"progress"});if(n.fault_link==="daemon\u2192node"&&(await se(t)).fault?.op==="conversation_write_failed"){if(!e)return;await(await import("../core/conversation-store/index.js")).flushConversation(),await Y(t,{op:"clear",link:"daemon\u2192node"})}else(n.fault_link==="daemon\u2192node"||e&&n.fault_link==="pi\u2192provider")&&await Y(t,{op:"clear",link:n.fault_link})}),E),"reportProgress"),T=l(()=>{const e=Date.now();e-O<J||(O=e,H(!1).catch(n=>d("turn_progress",n)))},"heartbeat");r.on("session_start",async(e,n)=>{try{const o=n?.sessionManager?.getSessionId?.();if(typeof o!="string"||o==="")return;const g=n?.sessionManager?.getSessionFile?.(),w=typeof g=="string"&&g!==""?g:null,k=typeof e?.reason=="string"?e.reason:null;k==="new"&&(i=0,s=0,_.clear());const a=te(t),m=a!==void 0&&!a.bindPending?{action:a.action}:await ce(t,{piSessionId:o,sessionFile:w,pid:process.pid,reason:k,reviewBoundaryIds:Te(n)});if(a?.bindPending===!0&&m.action==="none"&&ne(t),m.action==="none"&&C().start(t,ee()),m.action==="shutdown"){try{n?.shutdown?.()}catch{}return}if(m.action==="relaunch_root"){de(t).catch(y=>{const K=y instanceof Error?y.message:String(y);n?.ui?.notify?.(`/new refused: ${K}`,"error"),F({event:"broker.daemon.operation.failed",level:"error",node_id:t,error:y,fields:{operation:"relaunch_root"}})});return}}catch(o){F({event:"broker.daemon.operation.failed",level:"error",node_id:t,error:o,fields:{operation:"session_bound"}})}}),r.on("agent_start",async(e,n)=>{b=!0,v=n;try{if(!(await A(t,{event:"started"})).applied)throw new Error("daemon refused turn open")}catch(o){d("turn_open",o),n?.ui?.notify?.("Turn refused: the broker no longer owns this node.","error"),_e(()=>n?.abort?.())}}),r.on("input",async()=>{b||(x=!1),ge();try{await ie(t)}catch(e){throw d("clear_pushed_final",e),e}}),r.on("tool_execution_start",e=>{try{f=be(String(e?.toolName??""),e?.args),R(c,f),T()}catch{}}),r.on("tool_execution_update",()=>{try{T()}catch{}}),r.on("message_update",()=>{try{T()}catch{}}),r.on("tool_execution_end",async(e,n)=>{try{T(),(await j(t)).intent==="refresh"&&N(n)}catch{}}),r.on("session_shutdown",async(e,n)=>{W(),b=!1,v=void 0,await P();try{await A(t,{event:"closed",end_reason:"teardown-aborted"})}catch(o){d("turn_close_teardown",o)}if(e?.reason==="quit")try{const o=await z(t,{stopReason:"quit",pushedFinal:!1,inPlaceCycle:!0});D(o,n)}catch(o){d("settle_quit",o)}});const L=l(e=>{e?.role!=="assistant"||e.usage==null||(i+=Number(e.usage.input??0)||0,s+=Number(e.usage.output??0)||0,typeof e.model=="string"&&e.model!==""&&(u=e.model))},"accumulate");r.on("turn_end",async(e,n)=>{L(e?.message);let o=null;try{const a=n.getContextUsage()?.tokens;typeof a=="number"&&(o=a)}catch{}o!==null&&(c=o),R(o,f),await P();try{const a=e?.message?.stopReason!=="error"&&e?.message?.stopReason!=="aborted";await H(a)}catch(a){d("turn_end_fault_clear",a)}const g=Array.isArray(e?.message?.content)?e.message.content:[],w=e?.message?.stopReason??"",k=w!=="error"&&w!=="aborted"&&g.some(a=>a?.type==="toolCall");try{const a=o!==null?Ce(o):null,m=a!==null&&!_.has(a)?await j(t):null;if(a!==null&&m!==null){_.add(a);const y=ye("context-nudge",{},Ae(a,m.lifecycle,m.mode));k?(G(y,{type:"runtime",kind:"context-nudge"}),r.sendUserMessage(y,{deliverAs:"steer"})):r.sendMessage({customType:me,content:y,display:!0},{deliverAs:"nextTurn"})}}catch(a){d("turn_boundary",a)}});let M=null;r.on("agent_end",e=>{M=e;try{const n=Array.isArray(e?.messages)?e.messages:[];for(const o of n)L(o)}catch{}}),r.on("agent_settled",async(e,n)=>{b=!1,v=void 0,R(c,f),await P();const o=M;if(M=null,we())return;try{await A(t,{event:"closed",end_reason:"settled"})}catch(a){d("turn_close",a);return}const g=Array.isArray(o?.messages)?o.messages:[],w=ve(g),k=typeof w?.stopReason=="string"?w.stopReason:"";try{const a=o===null?{pushedFinal:!1}:await le(t),m=await z(t,{stopReason:k,pushedFinal:a.pushedFinal,inPlaceCycle:!0});D(m,n)}catch(a){d("settle",a)}})}l(Se,"registerCanvasStophook");var Le=Se;export{Le as default,Se as registerCanvasStophook,Ae as steerNote};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var g=Object.defineProperty;var
|
|
1
|
+
var g=Object.defineProperty;var d=(e,t)=>g(e,"name",{value:t,configurable:!0});import{Type as o}from"typebox";import{envNodeId as q}from"../shared/env.js";import{takeCycleStructuredRequest as w}from"../core/runtime/broker/cycle-start.js";import{localClient as p}from"../api/node-transport.js";import{ApiError as O}from"../api/index.js";import{SUBMIT_RESULT_TOOL as c}from"../core/runtime/structured-output.js";function $(e){const t=JSON.stringify(e.schema,null,2),r=`call the ${`\`${c}\` tool with \`request_id: "${e.request_id}"\``} and the JSON in \`result\``,n=`call \`${c}\` with \`decline: { reason, code }\` instead`;return`<structured-output-request>
|
|
2
2
|
${e.mode==="terminal"?`This node owes a terminal structured result. When the work is complete, submit it: ${r}. That records it and pushes your final report in one step, finishing this node. Do NOT call \`crtr push final\` yourself; it is blocked while this request is pending. If the schema cannot be honestly satisfied (blocked, unavailable, bad input), ${n} of inventing a value \u2014 that finishes the node with a declined outcome. You cannot stop or go dormant until the result is accepted or declined.`:`This node owes a one-off structured result. Submit it: ${r}. That records it and pushes an update report to your subscribers, then you continue working normally. If the schema cannot be honestly satisfied, ${n} of inventing a value. You cannot stop or go dormant until the result is accepted or declined.`}
|
|
3
3
|
|
|
4
4
|
The submitted JSON is validated against this schema; a mismatch rejects with field errors and records nothing, so fix it and call the tool again.
|
|
@@ -8,11 +8,11 @@ Required schema:
|
|
|
8
8
|
\`\`\`json
|
|
9
9
|
${t}
|
|
10
10
|
\`\`\`
|
|
11
|
-
</structured-output-request>`}
|
|
12
|
-
- code: ${t.code} (${t.retryable?"retryable":"not retryable"})`;return`${
|
|
11
|
+
</structured-output-request>`}d($,"structuredOutputPromptBlock");function S(e){const t=e.declined,i=e.mode==="terminal"?`${t?"Decline recorded":"Result recorded"} \u2014 node finished; its engine shuts down on next stop.`:`${t?"One-off request declined":"One-off result recorded"} and pushed \u2014 the structured-output gate is cleared; continue working normally.`,r=t===void 0?"":`
|
|
12
|
+
- code: ${t.code} (${t.retryable?"retryable":"not retryable"})`;return`${i}
|
|
13
13
|
|
|
14
|
-
- report: ${e.report}${r}`}
|
|
14
|
+
- report: ${e.report}${r}`}d(S,"submitResultText");async function f(e){return(await p({autostart:!1}).brokerStructuredRequest(e)).request}d(f,"readPendingRequest");function T(e,t){if(typeof t!="string")return t;const i=e?.schema.type;if(i!=="object"&&i!=="array")return t;try{return JSON.parse(t)}catch{return t}}d(T,"normalizeResult");function l(e){return{content:[{type:"text",text:e}],details:void 0,isError:!0}}d(l,"errorResult");function x(e,t=r=>p({autostart:!1}).submitResult(e,r),i=()=>f(e)){return{name:c,label:"Submit result",description:"Answer this node's pending structured-output request. Pass the request id from the structured-output instruction and either `result` (the JSON value matching the required schema) or `decline` when the schema cannot be honestly satisfied. The result is validated against the schema; a mismatch is rejected with field errors and nothing is recorded.",promptSnippet:"Submit the JSON result for a pending structured-output request (or decline it)",parameters:o.Object({request_id:o.String({description:"The request id named in the structured-output instruction."}),result:o.Optional(o.Unknown({description:"The JSON value matching the required schema. Omit when declining."})),decline:o.Optional(o.Object({reason:o.String({description:"One sentence on why the schema cannot be honestly satisfied."}),code:o.String({description:"A whitespace-free token naming the decline class, as the requester documented."}),retryable:o.Optional(o.Boolean({description:"Whether a retry could succeed. Default false."}))},{description:"Decline the request instead of submitting a result."}))}),defaultActive:!1,async execute(r,n){const s=typeof n.request_id=="string"?n.request_id.trim():"";if(s==="")return l("request_id is required: pass the request id named in the structured-output instruction.");const h=Object.hasOwn(n,"result")&&n.result!==void 0,a=n.decline;if(h&&a!==void 0)return l("Pass either `result` or `decline`, not both.");if(!h&&a===void 0)return l("Pass `result` (the JSON value matching the required schema), or `decline` when the schema cannot be honestly satisfied.");const y=a!==void 0?{request_id:s,decline:a.reason,code:a.code,retryable:a.retryable===!0}:{request_id:s,value:T(await i(),n.result)};try{const u=await t(y);return{content:[{type:"text",text:S(u)}],details:u,...u.mode==="terminal"?{terminate:!0}:{}}}catch(u){if(u instanceof O){const m=u.details,b=typeof m?.next=="string"?`
|
|
15
15
|
|
|
16
|
-
${m.next}`:"";return l(`${
|
|
16
|
+
${m.next}`:"";return l(`${u.code}: ${u.message}${b}`)}return l(`The result was not submitted: ${u.message}`)}}}}d(x,"createSubmitResultTool");function v(e){const t=q();if(t===void 0||t.trim()==="")return;e.registerTool(x(t));const i=d(r=>{const n=e.getActiveTools(),s=n.includes(c);r&&!s?e.setActiveTools([...n,c]):!r&&s&&e.setActiveTools(n.filter(h=>h!==c))},"syncTool");e.on("before_agent_start",async r=>{const n=w(t),s=n!==void 0?n.request:await f(t);if(i(s!==null),s!==null)return{systemPrompt:`${r.systemPrompt}
|
|
17
17
|
|
|
18
|
-
${
|
|
18
|
+
${$(s)}`}}),e.on("turn_end",async()=>{await f(t)!==null&&i(!0)})}d(v,"registerCanvasStructuredOutput");var P=v;export{c as SUBMIT_RESULT_TOOL,x as createSubmitResultTool,P as default,v as registerCanvasStructuredOutput,$ as structuredOutputPromptBlock,S as submitResultText};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.668",
|
|
4
4
|
"description": "crtr — agent runtime with memory, plugins, and marketplaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
},
|
|
150
150
|
"license": "UNLICENSED",
|
|
151
151
|
"dependencies": {
|
|
152
|
-
"@north-light/identity": "0.3.
|
|
152
|
+
"@north-light/identity": "0.3.668",
|
|
153
153
|
"@earendil-works/chord": "1.5.2",
|
|
154
154
|
"@earendil-works/pi-agent-core": "1.5.2",
|
|
155
155
|
"@earendil-works/pi-ai": "1.5.2",
|
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.668",
|
|
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.668",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "UNLICENSED",
|
|
12
12
|
"workspaces": [
|
|
@@ -28,7 +28,7 @@
|
|
|
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.
|
|
31
|
+
"@north-light/identity": "0.3.668",
|
|
32
32
|
"cron-parser": "^5.6.0",
|
|
33
33
|
"esbuild": "0.28.2",
|
|
34
34
|
"jose": "^6.2.12",
|
|
@@ -10666,17 +10666,17 @@
|
|
|
10666
10666
|
},
|
|
10667
10667
|
"packages/crouter-api": {
|
|
10668
10668
|
"name": "@north-light/api",
|
|
10669
|
-
"version": "0.3.
|
|
10669
|
+
"version": "0.3.668",
|
|
10670
10670
|
"license": "UNLICENSED"
|
|
10671
10671
|
},
|
|
10672
10672
|
"packages/crouter-env-docker": {
|
|
10673
10673
|
"name": "@north-light/env-docker",
|
|
10674
|
-
"version": "0.3.
|
|
10674
|
+
"version": "0.3.668",
|
|
10675
10675
|
"license": "UNLICENSED"
|
|
10676
10676
|
},
|
|
10677
10677
|
"packages/crouter-identity": {
|
|
10678
10678
|
"name": "@north-light/identity",
|
|
10679
|
-
"version": "0.3.
|
|
10679
|
+
"version": "0.3.668",
|
|
10680
10680
|
"license": "UNLICENSED",
|
|
10681
10681
|
"dependencies": {
|
|
10682
10682
|
"jose": "^6.2.1"
|
|
@@ -10684,21 +10684,21 @@
|
|
|
10684
10684
|
},
|
|
10685
10685
|
"packages/crouter-plugin": {
|
|
10686
10686
|
"name": "@north-light/plugin",
|
|
10687
|
-
"version": "0.3.
|
|
10687
|
+
"version": "0.3.668",
|
|
10688
10688
|
"license": "UNLICENSED",
|
|
10689
10689
|
"dependencies": {
|
|
10690
|
-
"@north-light/api": "0.3.
|
|
10691
|
-
"@north-light/identity": "0.3.
|
|
10690
|
+
"@north-light/api": "0.3.668",
|
|
10691
|
+
"@north-light/identity": "0.3.668"
|
|
10692
10692
|
}
|
|
10693
10693
|
},
|
|
10694
10694
|
"packages/crouter-sdk": {
|
|
10695
10695
|
"name": "@north-light/sdk",
|
|
10696
|
-
"version": "0.3.
|
|
10696
|
+
"version": "0.3.668",
|
|
10697
10697
|
"license": "UNLICENSED",
|
|
10698
10698
|
"dependencies": {
|
|
10699
|
-
"@north-light/api": "0.3.
|
|
10700
|
-
"@north-light/identity": "0.3.
|
|
10701
|
-
"@north-light/plugin": "0.3.
|
|
10699
|
+
"@north-light/api": "0.3.668",
|
|
10700
|
+
"@north-light/identity": "0.3.668",
|
|
10701
|
+
"@north-light/plugin": "0.3.668",
|
|
10702
10702
|
"jose": "^6.2.1"
|
|
10703
10703
|
},
|
|
10704
10704
|
"bin": {
|
|
@@ -3,8 +3,14 @@
|
|
|
3
3
|
#
|
|
4
4
|
# Runs as root in the sandbox's `broker-<execution id>` process. Environment: CRTR_NODE_TOKEN, CRTR_RELEASE,
|
|
5
5
|
# CRTR_RELEASE_URL, CRTR_RELEASE_SHA256 and the rest the runner set. Once per sandbox it creates the `crtr` user
|
|
6
|
-
# (`crtrd` refuses root) and its directories; it installs the release
|
|
7
|
-
#
|
|
6
|
+
# (`crtrd` refuses root) and its directories; it installs the release unless `$ROOT/releases/<release>` already holds
|
|
7
|
+
# it (complete, and unpacked from the tarball whose sha256 the wake names, recorded in its `.sha256`): that is the
|
|
8
|
+
# fast path, taken in a sandbox made from the release image (release-image.ts), which carries the release, `crtr`,
|
|
9
|
+
# `rg` and the directories, so nothing is installed or downloaded. Otherwise (the stock image, a release the image
|
|
10
|
+
# lacks, an image built from another tarball) it downloads, checks the sha256, unpacks into a temp dir and renames
|
|
11
|
+
# into place (replacing a release of the same name that fails the check), keeps three; then hands over to
|
|
12
|
+
# `crtr-sandbox-start` as `crtr`. Each phase prints `crtr-boot: <phase> up=<seconds>` (the VM's uptime, which the
|
|
13
|
+
# start script reads too, so it can report every phase of the boot together).
|
|
8
14
|
# The node token reaches the start script on stdin, never in its environment, so it is in no process's
|
|
9
15
|
# /proc/<pid>/environ. It is not hidden from user `crtr` otherwise: the broker holds it in memory, and the agent's
|
|
10
16
|
# shell runs as the same user (design-fleet D13/D78 scope the token to this execution's node, nothing more). The final `exec` chain forks nothing (busybox `nsenter -S/-G` execs, and the token goes in as a here-document, not a pipe, which would
|
|
@@ -13,6 +19,13 @@
|
|
|
13
19
|
# as its last line (the runner's `status` reports that reason).
|
|
14
20
|
set -eu
|
|
15
21
|
|
|
22
|
+
# /proc/uptime is read with a builtin: no fork. Empty when unreadable, which the start script reports as unknown.
|
|
23
|
+
uptime_now() { up=; read -r up _ < /proc/uptime 2>/dev/null || up=; }
|
|
24
|
+
phase() { uptime_now; echo "crtr-boot: $1 up=${up:-unknown}${2:+ $2}" >&2; }
|
|
25
|
+
uptime_now
|
|
26
|
+
CRTR_BOOT_START_UP=$up
|
|
27
|
+
phase bootstrap_start
|
|
28
|
+
|
|
16
29
|
fail() { echo "crtr-sandbox-start: failed $1${2:+ ($2)}" >&2; exit "${3:-1}"; }
|
|
17
30
|
|
|
18
31
|
: "${CRTR_RELEASE:?}" "${CRTR_RELEASE_URL:?}" "${CRTR_RELEASE_SHA256:?}" "${CRTR_NODE_TOKEN:?}"
|
|
@@ -28,10 +41,21 @@ if ! id "$RUN_USER" >/dev/null 2>&1; then
|
|
|
28
41
|
fi
|
|
29
42
|
mkdir -p /run/crtr /var/lib/crtr /work "$RELEASES"
|
|
30
43
|
chown "$RUN_USER" /run/crtr /var/lib/crtr /work
|
|
31
|
-
# pi's grep tool wants ripgrep; installing it once per sandbox avoids a GitHub download at the first grep.
|
|
32
|
-
|
|
44
|
+
# pi's grep tool wants ripgrep; the release image has it, and installing it once per sandbox avoids a GitHub download at the first grep.
|
|
45
|
+
rg=present
|
|
46
|
+
if ! command -v rg >/dev/null 2>&1; then
|
|
47
|
+
if apk add --no-cache ripgrep >/dev/null 2>&1; then rg=installed; else rg=missing; echo "crtr-sandbox-start: ripgrep not installed" >&2; fi
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
# The release is trusted only when it is complete and was unpacked from the tarball this wake names. A directory of the right name without that
|
|
51
|
+
# record (an install by an older bootstrap, an image built from another tarball of the same version) is replaced, never run unchecked.
|
|
52
|
+
release_current() { [ -f "$RELEASE_DIR/.complete" ] && [ "$(cat "$RELEASE_DIR/.sha256" 2>/dev/null)" = "$CRTR_RELEASE_SHA256" ]; }
|
|
33
53
|
|
|
34
|
-
if
|
|
54
|
+
if release_current; then
|
|
55
|
+
source=present
|
|
56
|
+
else
|
|
57
|
+
source=downloaded
|
|
58
|
+
[ ! -e "$RELEASE_DIR" ] || source=replaced
|
|
35
59
|
tmp=$(mktemp -d "$RELEASES/.tmp.XXXXXX")
|
|
36
60
|
trap 'rm -rf "$tmp"' EXIT
|
|
37
61
|
wget -q -O "$tmp/runtime.tar.gz" "$CRTR_RELEASE_URL" || fail release_download "$CRTR_RELEASE"
|
|
@@ -39,12 +63,17 @@ if [ ! -f "$RELEASE_DIR/.complete" ]; then
|
|
|
39
63
|
[ "$actual" = "$CRTR_RELEASE_SHA256" ] || fail release_checksum "expected $CRTR_RELEASE_SHA256, got $actual"
|
|
40
64
|
mkdir "$tmp/unpack"
|
|
41
65
|
tar -xzf "$tmp/runtime.tar.gz" -C "$tmp/unpack" || fail release_unpack
|
|
66
|
+
printf '%s\n' "$actual" > "$tmp/unpack/.sha256"
|
|
42
67
|
: > "$tmp/unpack/.complete"
|
|
43
|
-
# A
|
|
44
|
-
if ! mv "$
|
|
68
|
+
# A directory that fails the check is moved aside (removed with $tmp); one a concurrent start just installed from the same tarball is left, and wins.
|
|
69
|
+
if [ -e "$RELEASE_DIR" ] && ! release_current; then mv "$RELEASE_DIR" "$tmp/stale" 2>/dev/null || true; fi
|
|
70
|
+
if ! mv "$tmp/unpack" "$RELEASE_DIR" 2>/dev/null; then release_current || fail release_install; fi
|
|
45
71
|
rm -rf "$tmp"
|
|
46
72
|
trap - EXIT
|
|
47
73
|
fi
|
|
74
|
+
phase release_ready "source=$source rg=$rg"
|
|
75
|
+
uptime_now
|
|
76
|
+
export CRTR_BOOT_START_UP CRTR_BOOT_RELEASE_UP=$up CRTR_BOOT_RELEASE_SOURCE=$source CRTR_BOOT_RG=$rg
|
|
48
77
|
current_tmp="$ROOT/current.new.$$"
|
|
49
78
|
ln -sfn "$RELEASE_DIR" "$current_tmp" && mv -T "$current_tmp" "$ROOT/current"
|
|
50
79
|
# Keep the three newest releases (the current one among them).
|
|
@@ -10,7 +10,7 @@ import { spawn, spawnSync } from 'node:child_process';
|
|
|
10
10
|
import { createServer } from 'node:http';
|
|
11
11
|
import { randomBytes } from 'node:crypto';
|
|
12
12
|
import { chmodSync, closeSync, constants as fsConstants, createWriteStream, existsSync, fsyncSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, symlinkSync, unlinkSync, writeFileSync, writeSync } from 'node:fs';
|
|
13
|
-
import { tmpdir } from 'node:os';
|
|
13
|
+
import { tmpdir, uptime } from 'node:os';
|
|
14
14
|
import { basename, dirname, join, resolve, sep } from 'node:path';
|
|
15
15
|
import { fileURLToPath } from 'node:url';
|
|
16
16
|
import { Readable } from 'node:stream';
|
|
@@ -42,6 +42,29 @@ export function findBrokers(procRoot = '/proc') {
|
|
|
42
42
|
|
|
43
43
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
44
44
|
|
|
45
|
+
/** The boot's phase clock. `sandbox-bootstrap.sh` prints its own phases as VM uptime (`crtr-boot: <phase> up=<s>`) and exports the two it reached
|
|
46
|
+
* (`CRTR_BOOT_START_UP`, `CRTR_BOOT_RELEASE_UP`); this reads the same clock (`os.uptime()`), so every phase is an offset from the bootstrap's start. Each mark
|
|
47
|
+
* prints one stderr line (the process log, `bl logs`); `record()` is the one `sandbox.boot` node log record the start posts once the broker runs. With no
|
|
48
|
+
* bootstrap clock (a start run by hand) offsets count from the start script. */
|
|
49
|
+
export function bootClock(env, now = uptime, log = (line) => console.error(line)) {
|
|
50
|
+
const number = (value) => (value !== undefined && value !== '' && Number.isFinite(Number(value)) ? Number(value) : null);
|
|
51
|
+
const t0 = number(env.CRTR_BOOT_START_UP) ?? now();
|
|
52
|
+
const phases = { bootstrap_start: 0 };
|
|
53
|
+
const release = number(env.CRTR_BOOT_RELEASE_UP);
|
|
54
|
+
if (release !== null) phases.release_ready = Math.round((release - t0) * 1000);
|
|
55
|
+
const facts = { release_source: env.CRTR_BOOT_RELEASE_SOURCE || null, rg: env.CRTR_BOOT_RG || null };
|
|
56
|
+
return {
|
|
57
|
+
phases,
|
|
58
|
+
facts,
|
|
59
|
+
mark(phase, detail = {}) {
|
|
60
|
+
phases[phase] = Math.round((now() - t0) * 1000);
|
|
61
|
+
Object.assign(facts, detail);
|
|
62
|
+
log(`crtr-boot: ${phase} +${phases[phase]}ms${Object.keys(detail).length > 0 ? ` ${JSON.stringify(detail)}` : ''}`);
|
|
63
|
+
},
|
|
64
|
+
record: (extra) => ({ phases_ms: { ...phases }, ...facts, ...extra }),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
45
68
|
async function stopBroker(pid) {
|
|
46
69
|
try { process.kill(pid, 'SIGTERM'); } catch { return; }
|
|
47
70
|
for (let i = 0; i < 100; i++) {
|
|
@@ -303,6 +326,8 @@ function writeUnpackMarker(path) {
|
|
|
303
326
|
}
|
|
304
327
|
|
|
305
328
|
async function start(env) {
|
|
329
|
+
const boot = bootClock(env);
|
|
330
|
+
boot.mark('start_script_up');
|
|
306
331
|
const need = (name) => { const v = env[name]; if (!v) throw new StartFailure('bad_environment', `${name} is not set`); return v; };
|
|
307
332
|
const apiUrl = need('CRTR_API_URL');
|
|
308
333
|
const executionId = need('CRTR_EXECUTION_ID');
|
|
@@ -316,6 +341,7 @@ async function start(env) {
|
|
|
316
341
|
if (response.status === 401 || response.status === 403) throw new StartFailure('token_rejected', `the control plane answered ${response.status}`);
|
|
317
342
|
if (!response.ok) throw new StartFailure('bundle_failed', `the control plane answered ${response.status}`);
|
|
318
343
|
const bundle = await response.json();
|
|
344
|
+
boot.mark('bundle_fetched');
|
|
319
345
|
|
|
320
346
|
// 5.2 a broker of this execution is signalled; a broker of another execution is stopped.
|
|
321
347
|
const brokers = findBrokers(env.CRTR_PROC_ROOT ?? '/proc').filter((b) => b.node === bundle.node.id);
|
|
@@ -349,7 +375,9 @@ async function start(env) {
|
|
|
349
375
|
// with git alone; the release CLI would load the person's settings from a daemon this start cannot reach.
|
|
350
376
|
const marker = join(work, '.crtr', 'plugins-revision');
|
|
351
377
|
const have = existsSync(marker) ? readFileSync(marker, 'utf8').trim() : null;
|
|
378
|
+
const pluginFacts = { plugins: bundle.plugins.length, plugins_applied: false, marketplaces_cloned: 0 };
|
|
352
379
|
if (have !== String(bundle.plugins_revision)) {
|
|
380
|
+
pluginFacts.plugins_applied = true;
|
|
353
381
|
const pluginsDir = join(root, 'runtime', 'plugins');
|
|
354
382
|
const marketplacesDir = join(root, 'runtime', 'marketplaces');
|
|
355
383
|
const cloneEnv = { ...gitEnv, GIT_TERMINAL_PROMPT: '0' };
|
|
@@ -388,6 +416,7 @@ async function start(env) {
|
|
|
388
416
|
rmSync(dest, { recursive: true, force: true });
|
|
389
417
|
renameSync(staging, dest);
|
|
390
418
|
marketplaces.set(key, { dest, manifest });
|
|
419
|
+
pluginFacts.marketplaces_cloned = marketplaces.size;
|
|
391
420
|
}
|
|
392
421
|
const { dest: marketplaceDir, manifest } = marketplaces.get(key);
|
|
393
422
|
const entry = manifest.plugins.find((candidate) => candidate?.name === plugin.name);
|
|
@@ -412,6 +441,7 @@ async function start(env) {
|
|
|
412
441
|
}
|
|
413
442
|
}
|
|
414
443
|
if (have !== String(bundle.plugins_revision)) { mkdirSync(dirname(marker), { recursive: true }); writeFileSync(marker, String(bundle.plugins_revision)); }
|
|
444
|
+
boot.mark('plugins_ready', pluginFacts);
|
|
415
445
|
|
|
416
446
|
// 5.6 fetch only, never clone and never move a working tree; a failure is recorded and the start continues. The fetch reaches a private
|
|
417
447
|
// repository through the credential helper, over a relay of this process (see credentialRelay) because the broker's does not exist yet.
|
|
@@ -503,20 +533,24 @@ async function start(env) {
|
|
|
503
533
|
CRTR_FRONT_DOOR: '1', CRTR_EXECUTION_ID: executionId, CRTR_API_URL: apiUrl, CRTR_NO_AUTO_INIT: '1',
|
|
504
534
|
CRTR_PLUGINS_REVISION: String(bundle.plugins_revision), ...(environmentId ? { CRTR_ENVIRONMENT_ID: environmentId } : {}), ...(scopesFile ? { CRTR_SCOPES_FILE: scopesFile } : {}),
|
|
505
535
|
PATH: `${join(releaseDir, 'bin')}:${env.PATH ?? '/usr/local/bin:/usr/bin:/bin'}` };
|
|
506
|
-
for (const name of ['CRTR_NODE_TOKEN', 'CRTR_RELEASE_URL', 'CRTR_RELEASE_SHA256']) delete brokerEnv[name];
|
|
536
|
+
for (const name of ['CRTR_NODE_TOKEN', 'CRTR_RELEASE_URL', 'CRTR_RELEASE_SHA256', 'CRTR_BOOT_START_UP', 'CRTR_BOOT_RELEASE_UP', 'CRTR_BOOT_RELEASE_SOURCE', 'CRTR_BOOT_RG']) delete brokerEnv[name];
|
|
507
537
|
const child = spawn(process.execPath, [brokerEntry, '--canvas-home', join(root, 'runtime'), '--epoch', executionId, nodeId],
|
|
508
538
|
{ cwd, env: brokerEnv, stdio: ['ignore', 'inherit', 'inherit', 'pipe'] });
|
|
509
539
|
child.stdio[3].end(token);
|
|
540
|
+
boot.mark('broker_spawned');
|
|
510
541
|
const exited = new Promise((resolveExit) => child.on('exit', (code, signal) => resolveExit(code ?? (signal ? 128 : 1))));
|
|
511
542
|
for (const sig of ['SIGTERM', 'SIGINT']) process.on(sig, () => child.kill(sig));
|
|
512
|
-
//
|
|
513
|
-
|
|
514
|
-
|
|
543
|
+
// A failure, and the boot's phase timings, are node log records (`POST /v1/nodes/:id/records/log`, the route a broker's events use); a refused post goes to the process log (`bl logs`).
|
|
544
|
+
// The broker's own `broker.startup.*` events (cli_entry, module_loaded, session_built, extensions_bound) and its run events carry the phases after this one.
|
|
545
|
+
const postRecord = async (level, event, fields) => {
|
|
546
|
+
const record = JSON.stringify({ v: 1, ts: new Date().toISOString(), level, event, component: 'broker', operation_id: randomBytes(16).toString('hex'), node_id: nodeId, fields });
|
|
515
547
|
try {
|
|
516
548
|
const posted = await api(apiUrl, token, 'POST', `/v1/nodes/${nodeId}/records/log`, { record, expected_execution_id: executionId });
|
|
517
549
|
if (!posted.ok) throw new Error(`the control plane answered ${posted.status}`);
|
|
518
|
-
} catch (error) { console.error(
|
|
519
|
-
}
|
|
550
|
+
} catch (error) { console.error(`${event} ${record} (not recorded: ${error?.message ?? error})`); }
|
|
551
|
+
};
|
|
552
|
+
for (const failure of fetchFailures) await postRecord('warn', 'sandbox.fetch.failed', failure);
|
|
553
|
+
await postRecord('info', 'sandbox.boot', boot.record({ release: basename(releaseDir) }));
|
|
520
554
|
return await exited;
|
|
521
555
|
}
|
|
522
556
|
|