@north-light/cli 0.3.778 → 0.3.780

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.
@@ -3,11 +3,11 @@ kind: preference
3
3
  when-and-why-to-read: When a node runs in base mode on any kind but explore, this preference should be read so orientation noise lands in a scout's window and comes back as a clean map instead of silting the context this node's real work runs in.
4
4
  gate: {mode: base, not: {kind: explore}}
5
5
  rationale: >-
6
- Split from 04-base-worker: gated {mode: base} alone, this section told an explore base node to spawn an explore scout for its own assignment — circular, and in tension with kinds/explore/base's narrower promote-only rule. The section itself exists because the kernel's "understand before you delegate" line is orchestrator-gated, so base workers had no counterweight to mapping unfamiliar code in their own window: they spent their context on read-only exploration and yielded before the real work. The operative mechanism is context, not model-tier economics (Silas, 2026-08-30): exploration residue — dead ends, half-relevant files — degrades the window it lands in, so the scout's job is to absorb that noise and return a distilled map every later node, the spawner included, loads clean. The body avoids "weigh/consider/decide" verbs deliberately: an instruction to perform a cognitive act gets narrated ("I considered a scout and…"), so the always-consider behavior is carried structurally — spawn is the unmarked default, skip is gated behind an exception test models apply silently. The exception was widened and the scout's cost stated on 2026-11-11 (Silas), following the Fable 5.2 prompting guidance that standing instructions to delegate make that model start more subagents than the task needs; the unsupported claim that a scout does a more thorough job was removed with it.
6
+ Split from 04-base-worker: gated {mode: base} alone, this section told an explore base node to spawn an explore scout for its own assignment — circular, and in tension with kinds/explore/base's narrower promote-only rule. The section itself exists because the kernel's "understand before you delegate" line is orchestrator-gated, so base workers had no counterweight to mapping unfamiliar code in their own window: they spent their context on read-only exploration and yielded before the real work. The operative mechanism is context, not model-tier economics (Silas, 2026-08-30): exploration residue — dead ends, half-relevant files — degrades the window it lands in, so the scout's job is to absorb that noise and return a distilled map every later node, the spawner included, loads clean. The body avoids "weigh/consider/decide" verbs deliberately: an instruction to perform a cognitive act gets narrated ("I considered a scout and…"), so the always-consider behavior is carried structurally — spawn is the unmarked default, skip is gated behind an exception test models apply silently.
7
7
  surfaces:
8
8
  - on: boot
9
9
  at: content
10
10
  ---
11
11
 
12
12
  ## Exploring
13
- Fresh work on a surface you do not yet understand and cannot read in a few files — a codebase, a system, a domain — starts with an `explore` node to chart it (`crtr node -h`), with `--mode orchestrate` when the surface is large or there are multiple questions. The dead ends and half-relevant files of exploration stay in the window that read them; a scout keeps them in its own window and hands back a distilled map or answer. A scout costs a full window of tokens and a wait for its report, so read the surface yourself when you already know it, when you can name the files to open, or when the answer sits in a handful of files.
13
+ Fresh work on a surface you do not yet understand — a codebase, a system, a domain — starts with an `explore` node to chart it (`crtr node -h`), with `--mode orchestrate` when the surface is large or there are multiple questions. Charting it yourself bloats your context window; a scout spends its own window and hands back a distilled map or answer, and it will do a more thorough job. Skip the scout only when you already know the surface or it is small enough to read directly — waiting on one for a two-file change costs more than it saves.
@@ -1 +1 @@
1
- var pe=Object.defineProperty;var m=(e,t)=>pe(e,"name",{value:t,configurable:!0});import{validateDeclaredResult as K}from"../../api/command-manifest/result.js";import{callerAllows as ce,requireGroup as fe}from"../../daemon/api/handlers/providers.js";import{callerTerminalGrant as me}from"../grants/terminal.js";import{environmentPayerOfNode as ve,findRefusal as ge,payerOf as he,refusalError as we,refusedMark as ye,writeCharge as be}from"../ledger/index.js";import{listInstalledPlugins as _e}from"../resolver.js";import{emitEvent as je}from"../events/emit.js";import{ProviderError as l,scopeMissing as ke}from"./errors.js";import{parseProviderPayment as Ae}from"../provider-failure.js";import{resolveProviderRef as Pe}from"./roots.js";import{providerToolPath as $e}from"../plugin-objects-manifest.js";import{ensureProviderBundle as Ee,refreshProviderBundle as Z,resolveProviderBundle as S,unavailableProviderError as qe}from"./bundles.js";import{prepareFileCall as Ce,resignForRetry as ee,resolveFileResult as re}from"./files.js";import{consumeApproval as Re,requireProviderApproval as Te}from"./approval.js";import{actingToken as Me,outboundToken as Oe}from"./mint.js";import{discardFile as Ie}from"./token-cache.js";import{registerProviderCall as Ne}from"./inflight.js";import{buildRequestPlan as Be,paramKey as Se}from"../command-plugins/transport/http-plan.js";import{newTraceId as Fe}from"../../shared/traceparent.js";import{sendProviderRequest as De,ProviderTransportError as Ue}from"./request.js";import{acceptProviderReceipt as Le}from"./receipts.js";import{writeProviderAudit as xe}from"./audit.js";import{selectDevice as Je,sendDeviceCall as He,deviceFailure as Ge,deviceUnreachable as te,DEFAULT_DEVICE_REQUEST_MS as ze}from"./device.js";import{isLibsSearch as oe,wantsBundling as Ke,callLibsSearch as Qe,bundleExec as Ve,mapLibOutcome as We,reportLibCalls as Xe}from"./device-libs.js";import{ownMachineId as Ye}from"../peer/directory.js";import{directoryIssuer as Ze}from"../directory/issuer.js";import{isCloudRole as er}from"../canvas/person-state.js";import{formatCrtrCaller as ne}from"../command-plugins/caller-header.js";import{getNode as rr}from"../canvas/canvas.js";import{envelopeForProviderCaller as tr,EnvelopeError as or}from"../peer/envelope.js";const nr="app:terminal";function ie(e){const t=[],i=m((p,r,n)=>{const c=[...r,p.name],d=n||p.tier==="hidden";if(p.kind==="branch"){for(const b of p.children)i(b,c,d);return}const h=$e(e.roots.length,c);t.push({tool:h,leaf:p,hidden:d})},"walk");for(const p of e.roots)i(p,[],!1);return t}m(ie,"providerLeaves");function ae(e){if(e.kind!=="branch")return null;const t=[];for(const v of e.children)if(v.kind==="branch"){const _=ae(v);_&&t.push(_)}else if("group"in v&&v.group){const{kind:_,name:s,description:j,whenToUse:w,tier:y,summary:A,params:P,output:o,effects:u,group:k}=v;t.push({kind:_,name:s,description:j,whenToUse:w,...y===void 0?{}:{tier:y},summary:A,params:P,output:o,effects:u,group:k})}if(t.length===0)return null;const{kind:i,name:p,description:r,whenToUse:n,tier:c,summary:d,model:h,rootEntry:b}=e;return{kind:i,name:p,description:r,whenToUse:n,...c===void 0?{}:{tier:c},summary:d,...h===void 0?{}:{model:h},...b===void 0?{}:{rootEntry:b},children:t}}m(ae,"providerHelpBranch");async function xr(e,t){const i=await S(t),p=ie(i.commands),r=_e("user").find(n=>n.name===t)?.manifest.description??t;return{provider:t,status:"available",major:i.major,display_name:r,transport:i.transport.kind,groups:i.provider.groups.filter(n=>ce(e,`${t}:${n.group}`)).map(n=>({group:n.group,leaves:p.filter(({leaf:c,hidden:d})=>!d&&c.group===n.group).map(({tool:c,leaf:d})=>({tool:c,description:d.description,summary:d.summary,params:d.params,output:d.output}))})),commands:i.commands.roots.flatMap(n=>{const c=ae(n);return c?[c]:[]})}}m(xr,"providerTools");async function ir(e){return await Le(e.headers["crtr-receipt"],e)}m(ir,"onProviderResponse");async function ar(e){if(e.class==="person"){const t=(await me())?.sub;if(!t)throw new l("grant_revoked","This machine has no active Northlight grant for your terminal. Run `crtr sys signin` again.");return{sub:t,grantee:t}}if(!e.sub||!e.grantee)throw new l("grant_revoked","the caller has no active grant");return{sub:e.sub,grantee:e.grantee}}m(ar,"identity");function se(e,t){return[`${e.id}:${t.group}`]}m(se,"callScope");function sr(e,t){const i=ie(e.commands).find(p=>p.tool===t);if(!i)throw new l("not_found",`tool "${t}" is not in provider "${e.id}"`,{param:"tool"});if(!i.leaf.group)throw new l("not_found",`tool "${t}" has no group`,{param:"tool"});return i.leaf}m(sr,"leafFor");function Q(e){if(!e||typeof e!="object"||Array.isArray(e))return{};const t=e.error;return!t||typeof t!="object"||Array.isArray(t)?{}:t}m(Q,"errorBody");function dr(e){const t=Array.isArray(e)?e[0]:e;if(!t)return;const i=Number(t);if(Number.isFinite(i)&&i>=0)return i;const p=Date.parse(t);return Number.isFinite(p)?Math.max(0,Math.ceil((p-Date.now())/1e3)):void 0}m(dr,"retryAfter");function F(e,t,i,p=!1){const r=Q(t),n=typeof r.code=="string"?r.code:void 0,c=typeof r.message=="string"?r.message:`provider answered HTTP ${e}`,d=typeof r.field=="string"?r.field:void 0,h=r.details&&typeof r.details=="object"?r.details:{},b=Ae(h.payment),v=typeof r.next=="string"?r.next:typeof h.next=="string"?h.next:void 0,s={origin:"provider",details:{code:n??null,message:c,...d?{field:d}:{},...v!==void 0?{next:v}:{},...r.received!==void 0?{received:r.received}:{},...b===void 0?{}:{payment:b},status:e},...d?{param:d}:{}};return e===429?new l("provider_rate_limited",c,{...s,retry_after_s:dr(i["retry-after"])}):e===401||e>=500?new l("provider_unavailable",c,s):e===403&&n==="provider_refused"?new l("provider_refused",c,s):e===403&&n==="approval_required"?new l("provider_error",p?"provider asked for approval again":"provider approval question is invalid",{...s,status:e}):new l("provider_error",c,{...s,status:e})}m(F,"mapProviderResponse");function de(e,t){return JSON.stringify({major:e.major,endpoint:e.transport.kind==="http"?e.transport.endpoint:null,baseUrl:e.commands.baseUrl??null,rest:t.rest,params:t.params,output:t.output})}m(de,"approvalShape");async function ur(e){const t=e.origin!==void 0?ne({node:e.origin.node??void 0,run:e.origin.run??void 0,machine:e.origin.machine}):ne({node:e.node_id??void 0,run:e.run_id??void 0,profile:e.node_id?(await rr(e.node_id))?.profile_id??void 0:void 0,machine:Ze()!==null?Ye():void 0});return t===""?{}:{"Crtr-Caller":t}}m(ur,"crtrCallerHeader");async function Jr(e,t,i){const p=Pe(t.provider);if(p===null)throw new l("not_found",`provider "${t.provider}" is not available`,{param:"provider"});const r={...t,provider:p},n=new AbortController,c=m(()=>n.abort(i.signal.reason),"abort");i.signal.aborted?c():i.signal.addEventListener("abort",c,{once:!0});let d=i.requestId;const h=i.traceId??Fe(),b=Ne({request_id:d,run_id:e.run_id,node_id:e.node_id,controller:n});let v,_,s,j,w,y,A,P="allowed";try{if(er()&&e.class==="person"&&e.resolved!==null&&!e.resolved.some(g=>g.startsWith(`${r.provider}:`)))throw ke(`${r.provider}:*`);try{await Ee(r.provider)}catch{throw qe(r.provider)}let o=await S(r.provider,r.version),u=!1,k=!1,$,D,q,V=!1,W=!1,U,X=0;for(;;){const g=sr(o,r.tool);if(s=`${o.id}:${g.group}`,fe(e,o.id,g.group),o.transport.kind!=="machine"&&r.machine!==void 0)throw new l("invalid_argument",`provider "${o.id}" is not served by a device, so it takes no machine`,{param:"machine"});o.transport.kind==="machine"&&U===void 0&&(U=await Je(r.machine,void 0,{newest:oe(o.major,r.tool)}),X=Date.now()+(o.commands.timeouts?.requestMs??ze));let L=null;if(r.approval&&!V){const a=await Re(e,r,de(o,g));q=a.option,L=a.prepared,A=r.approval,d=a.requestId,V=!0}const N={params:g.params.filter(a=>"type"in a&&a.type==="file").map(a=>a.name),output:g.output.find(a=>a.type==="file")?.name??null},Y=JSON.stringify(N);if(D!==void 0&&D!==Y)throw new l("provider_bad_response","the refreshed manifest changed the tool file contract",{origin:"provider",details:{status:409,message:"manifest_stale changed the tool file contract"}});D=Y,L&&($=await ee(e,N,r.arguments,L,{signal:n.signal})),$??=await Ce(e,N,r.arguments,{signal:n.signal});const x=await ar(e),{grantee:T}=x,M=r.as??x.sub;if(o.transport.kind==="machine"){if(r.as!==void 0)throw new l("not_granted","`--as` is not available on a provider served by a device",{param:"as"});const a=await pr(e,o,r,g,$,{sub:M,requestId:d,deadlineAt:X,signal:n.signal,machine:U});return y=a.responder,v=a.cleanup,{status:200,body:a.result}}const J=o.transport.endpoint;let C;try{C=r.as===void 0?await Oe({audience:J,sub:M,grantee:T,initiating_app:T,scope:se(o,g)},{signal:n.signal}):await Me(x,r.as,{audience:J,scope:se(o,g)},{signal:n.signal})}catch(a){if(!(a instanceof l)||a.details?.directory_error!=="invalid_target"||k)throw a;k=!0,await Z(o.id,{conditional:!1,...r.version===void 0?{}:{version:r.version}});const E=await S(o.id,r.version);if(E.transport.kind==="machine"||E.transport.endpoint===J)throw a;o=E;continue}j=C.jti;const H=e.class==="person"?nr:T,O=he({call:"tool",tokenPayer:C.payer,sub:M,environmentPayer:await ve(e.node_id)}),G=await ge({scope:"call",payer:O.payer,funding:O.funding,sub:M,grantee:H,provider:`app:${o.id}`});if(G!==null)throw await be({request:d,kind:"tool",what:`${o.id}:${r.tool}`,usd:0,payer:O.payer,funding:O.funding,sub:M,actor:e.actor??(r.as===void 0?null:T),grantee:H,node:e.node_id,run:e.run_id,provider:`app:${o.id}`,causedBy:i.causedBy??null,refused:ye(G)}),we(G);const ue={registration:{name:o.id,endpoint:o.transport.endpoint},...o.commands.baseUrl?{baseUrl:o.commands.baseUrl}:{},...o.commands.timeouts?{timeouts:o.commands.timeouts}:{},params:g.params,rest:g.rest,output:g.output,commandPath:[o.id,...r.tool.split(" ")]},le=Be(ue,$.arguments,void 0,{authorization:`Bearer ${C.access_token}`,requestId:d,traceId:h,fileMode:"pass-through",extraHeaders:{...i.causedBy?{"Crtr-Caused-By":i.causedBy}:{},...e.run_id?{"Crtr-Run-Id":e.run_id}:{},...await ur(e),...q?{"Crtr-Approval":q}:{},...$.headers}});_??=Date.now()+(o.commands.timeouts?.requestMs??3e4);let f;try{if(f=await De(le,{connectMs:o.commands.timeouts?.connectMs,requestMs:o.commands.timeouts?.requestMs,deadlineAt:_,signal:n.signal}),n.signal.aborted)throw n.signal.reason??new Error("provider call aborted")}catch(a){throw n.signal.aborted?n.signal.reason??a:a instanceof Ue?new l("provider_unavailable",a.message,{origin:"provider",details:{status:null,code:a.kind}}):a}if(w??=await ir({provider:o.id,tool:r.tool,request_id:d,run_id:e.run_id,sub:M,grantee:T,payer:C.payer,ledger_grantee:H,funding:O.funding,node_id:e.node_id,actor:e.actor??(r.as===void 0?null:T),caused_by:i.causedBy??null,jti:C.jti,status:f.status,headers:f.headers}),y=f.headers["crtr-responder"],f.status===401&&Ie(C.key),f.status>=200&&f.status<300){const a=f.body;if(!a||typeof a!="object"||Array.isArray(a))throw new l("provider_bad_response","provider result is not a JSON object",{origin:"provider",details:{status:f.status,message:"provider result is not a JSON object"}});let E;try{E=await re(e,$,a,{signal:n.signal})}catch(I){throw I instanceof l&&I.code==="provider_error"?new l("provider_bad_response",I.message,{origin:"provider",details:{status:f.status,message:I.message}}):I}v=E.cleanup;const B=K(g.output,E.result);if(B)throw new l("provider_bad_response",`provider result has an invalid output field "${B.field}"`,{origin:"provider",param:B.field,details:{status:f.status,...B}});if(n.signal.aborted)throw n.signal.reason??new Error("provider call aborted");return{status:200,body:E.result}}const R=Q(f.body);if(f.status===403&&R.code==="approval_required"&&!q&&!W){W=!0;const a=await Te(e,r,d,R.question,n.signal,de(o,g),$);if(A=a.questionId,q=a.option,$=await ee(e,N,r.arguments,$,{signal:n.signal}),_=void 0,n.signal.aborted)throw new l("user_denied","the approval wait was canceled");continue}if(f.status===403&&R.code==="approval_required"&&q)throw F(f.status,f.body,f.headers,!0);const z=f.status===410&&R.code==="unsupported_major"&&r.version===void 0;if(f.status!==401&&(R.manifest_stale===!0||z)&&!u){u=!0;const a=o.major;await Z(o.id,{conditional:!1,...r.version===void 0?{}:{version:r.version}}),o=await S(o.id,r.version),je({level:"info",event:"daemon.providers.call_retried",fields:{provider:o.id,tool:r.tool,reason:z?"unsupported_major":"manifest_stale",major_before:a,major_after:o.major,...z&&typeof R.received=="number"?{received:R.received}:{}}});continue}throw F(f.status,f.body,f.headers,!!q)}}catch(o){throw o instanceof l&&o.question_id&&(A=o.question_id),y===void 0&&o instanceof l&&typeof o.responder=="string"&&(y=o.responder),P=`refused:${o instanceof l?o.code:"server_error"}`,await v?.(),o}finally{try{await xe({request_id:d,caller:e,provider:r.provider,tool:r.tool,scope_checked:s,outcome:P,jti:j,receipt_id:w,responder:y,question_id:A})}finally{b()}i.signal.removeEventListener("abort",c)}}m(Jr,"callProvider");function lr(e,t){const i={...t};for(const{name:p}of e.params){const r=Se(p);r===p||!Object.hasOwn(i,r)||(i[p]=i[r],delete i[r])}return i}m(lr,"declaredNames");async function pr(e,t,i,p,r,n){const{machine:c}=n;let d;try{d=await tr(e,n.sub)}catch(u){throw u instanceof or?new l("invalid_request",u.message,{origin:"runtime"}):u}const h={machine:c,envelope:d,signal:n.signal,deadlineAt:n.deadlineAt,mapFailure:F};if(oe(t.major,i.tool)){const u=await Qe(h,r.arguments,t.major),k=K(p.output,u);if(k)throw new l("provider_bad_response",`the libraries result has an invalid output field "${k.field}"`,{origin:"provider",param:k.field,details:{status:200,...k}});return{result:u,responder:void 0,cleanup:void 0}}let b=r.arguments,v=null,_="";if(Ke(t.major,i.tool,r.arguments)){const u=await Ve(h,r.arguments,t.major);if(n.deadlineAt-Date.now()<=0)throw te(c,"timeout","");u!==null&&(b=u.arguments,v=u.services,_=u.release)}const s=await He(c,{tool:i.tool,arguments:lr(p,b),version:t.major,requestId:n.requestId,runId:e.run_id,deadlineAt:n.deadlineAt,upload:r.upload===null?null:{id:r.upload.upload_id,link:r.upload.upload_link}},d,n.signal);if(n.signal.aborted)throw n.signal.reason??new Error("provider call aborted");if("unreachable"in s)throw te(c,s.unreachable.reason,s.unreachable.message);const j=s.headers["crtr-responder"],w=Q(s.body);if(s.status<200||s.status>=300){const u=Ge(c,s.status,typeof w.code=="string"?w.code:void 0,typeof w.message=="string"?w.message:void 0,s.body),k=u===null&&s.status>=500&&typeof w.code=="string"?new l("provider_error",typeof w.message=="string"?w.message:`the device answered HTTP ${s.status}`,{origin:"runtime",status:s.status,details:{code:w.code,status:s.status}}):null;throw Object.assign(u??k??F(s.status,s.body,s.headers),{responder:j})}const y=s.body&&typeof s.body=="object"&&!Array.isArray(s.body)?s.body.result:void 0;if(!y||typeof y!="object"||Array.isArray(y))throw Object.assign(new l("provider_bad_response","the device result is not a JSON object",{origin:"provider",details:{status:s.status,message:"the device result is not a JSON object"}}),{responder:j});let A=y;if(v!==null){const u=We(A,v);if(Xe(c,d,_,u.calls),"error"in u)throw Object.assign(u.error,{responder:j});A=u.result}let P;try{P=await re(e,r,A,{signal:n.signal})}catch(u){throw u instanceof l&&u.code==="provider_error"?Object.assign(new l("provider_bad_response",u.message,{origin:"provider",details:{status:s.status,message:u.message}}),{responder:j}):u}const o=K(p.output,P.result);if(o)throw await P.cleanup?.(),Object.assign(new l("provider_bad_response",`the device result has an invalid output field "${o.field}"`,{origin:"provider",param:o.field,details:{status:s.status,...o}}),{responder:j});return{result:P.result,responder:j,cleanup:P.cleanup}}m(pr,"callDevice");export{Jr as callProvider,ur as crtrCallerHeader,ar as identity,F as mapProviderResponse,ir as onProviderResponse,ie as providerLeaves,xr as providerTools};
1
+ var pe=Object.defineProperty;var m=(e,o)=>pe(e,"name",{value:o,configurable:!0});import{validateDeclaredResult as z}from"../../api/command-manifest/result.js";import{callerAllows as ce,requireGroup as fe}from"../../daemon/api/handlers/providers.js";import{callerTerminalGrant as me}from"../grants/terminal.js";import{environmentPayerOfNode as ve,findRefusal as ge,payerOf as he,refusalError as we,refusedMark as ye,writeCharge as be}from"../ledger/index.js";import{listInstalledPlugins as _e}from"../resolver.js";import{emitEvent as je}from"../events/emit.js";import{ProviderError as l,scopeMissing as ke}from"./errors.js";import{parseProviderPayment as Ae}from"../provider-failure.js";import{resolveProviderRef as Pe}from"./roots.js";import{providerToolPath as Ee}from"../plugin-objects-manifest.js";import{ensureProviderBundle as $e,refreshProviderBundle as Z,resolveProviderBundle as S,unavailableProviderError as Re}from"./bundles.js";import{prepareFileCall as qe,resignForRetry as ee,resolveFileResult as re}from"./files.js";import{consumeApproval as Ce,requireProviderApproval as Ie}from"./approval.js";import{actingToken as Te,outboundToken as Me}from"./mint.js";import{discardFile as Oe}from"./token-cache.js";import{registerProviderCall as Ne}from"./inflight.js";import{buildRequestPlan as Be,paramKey as Se}from"../command-plugins/transport/http-plan.js";import{newTraceId as De}from"../../shared/traceparent.js";import{sendProviderRequest as Fe,ProviderTransportError as Ue}from"./request.js";import{acceptProviderReceipt as Le}from"./receipts.js";import{writeProviderAudit as xe}from"./audit.js";import{selectDevice as Je,sendDeviceCall as He,deviceFailure as Ge,deviceUnreachable as te,DEFAULT_DEVICE_REQUEST_MS as Ve}from"./device.js";import{isLibsSearch as oe,wantsBundling as ze,callLibsSearch as Ke,bundleExec as Qe,mapLibOutcome as We,reportLibCalls as Xe}from"./device-libs.js";import{ownMachineId as Ye}from"../peer/directory.js";import{directoryIssuer as Ze}from"../directory/issuer.js";import{isCloudRole as er}from"../canvas/person-state.js";import{formatCrtrCaller as ne}from"../command-plugins/caller-header.js";import{getNode as rr}from"../canvas/canvas.js";import{envelopeForProviderCaller as tr,EnvelopeError as or}from"../peer/envelope.js";const nr="app:terminal",ir="sms";function ie(e){const o=[],i=m((p,r,n)=>{const c=[...r,p.name],d=n||p.tier==="hidden";if(p.kind==="branch"){for(const b of p.children)i(b,c,d);return}const h=Ee(e.roots.length,c);o.push({tool:h,leaf:p,hidden:d})},"walk");for(const p of e.roots)i(p,[],!1);return o}m(ie,"providerLeaves");function ae(e){if(e.kind!=="branch")return null;const o=[];for(const v of e.children)if(v.kind==="branch"){const _=ae(v);_&&o.push(_)}else if("group"in v&&v.group){const{kind:_,name:s,description:j,whenToUse:w,tier:y,summary:A,params:P,output:t,effects:u,group:k}=v;o.push({kind:_,name:s,description:j,whenToUse:w,...y===void 0?{}:{tier:y},summary:A,params:P,output:t,effects:u,group:k})}if(o.length===0)return null;const{kind:i,name:p,description:r,whenToUse:n,tier:c,summary:d,model:h,rootEntry:b}=e;return{kind:i,name:p,description:r,whenToUse:n,...c===void 0?{}:{tier:c},summary:d,...h===void 0?{}:{model:h},...b===void 0?{}:{rootEntry:b},children:o}}m(ae,"providerHelpBranch");async function Jr(e,o){const i=await S(o),p=ie(i.commands),r=_e("user").find(n=>n.name===o)?.manifest.description??o;return{provider:o,status:"available",major:i.major,display_name:r,transport:i.transport.kind,groups:i.provider.groups.filter(n=>ce(e,`${o}:${n.group}`)).map(n=>({group:n.group,leaves:p.filter(({leaf:c,hidden:d})=>!d&&c.group===n.group).map(({tool:c,leaf:d})=>({tool:c,description:d.description,summary:d.summary,params:d.params,output:d.output}))})),commands:i.commands.roots.flatMap(n=>{const c=ae(n);return c?[c]:[]})}}m(Jr,"providerTools");async function ar(e){return await Le(e.headers["crtr-receipt"],e)}m(ar,"onProviderResponse");async function sr(e){if(e.class==="person"){const o=(await me())?.sub;if(!o)throw new l("grant_revoked","This machine has no active Northlight grant for your terminal. Run `crtr sys signin` again.");return{sub:o,grantee:o}}if(!e.sub||!e.grantee)throw new l("grant_revoked","the caller has no active grant");return{sub:e.sub,grantee:e.grantee}}m(sr,"identity");function se(e,o){return[`${e.id}:${o.group}`]}m(se,"callScope");function dr(e,o){const i=ie(e.commands).find(p=>p.tool===o);if(!i)throw new l("not_found",`tool "${o}" is not in provider "${e.id}"`,{param:"tool"});if(!i.leaf.group)throw new l("not_found",`tool "${o}" has no group`,{param:"tool"});return i.leaf}m(dr,"leafFor");function K(e){if(!e||typeof e!="object"||Array.isArray(e))return{};const o=e.error;return!o||typeof o!="object"||Array.isArray(o)?{}:o}m(K,"errorBody");function ur(e){const o=Array.isArray(e)?e[0]:e;if(!o)return;const i=Number(o);if(Number.isFinite(i)&&i>=0)return i;const p=Date.parse(o);return Number.isFinite(p)?Math.max(0,Math.ceil((p-Date.now())/1e3)):void 0}m(ur,"retryAfter");function D(e,o,i,p=!1){const r=K(o),n=typeof r.code=="string"?r.code:void 0,c=typeof r.message=="string"?r.message:`provider answered HTTP ${e}`,d=typeof r.field=="string"?r.field:void 0,h=r.details&&typeof r.details=="object"?r.details:{},b=Ae(h.payment),v=typeof r.next=="string"?r.next:typeof h.next=="string"?h.next:void 0,s={origin:"provider",details:{code:n??null,message:c,...d?{field:d}:{},...v!==void 0?{next:v}:{},...r.received!==void 0?{received:r.received}:{},...b===void 0?{}:{payment:b},status:e},...d?{param:d}:{}};return e===429?new l("provider_rate_limited",c,{...s,retry_after_s:ur(i["retry-after"])}):e===401||e>=500?new l("provider_unavailable",c,s):e===403&&n==="provider_refused"?new l("provider_refused",c,s):e===403&&n==="approval_required"?new l("provider_error",p?"provider asked for approval again":"provider approval question is invalid",{...s,status:e}):new l("provider_error",c,{...s,status:e})}m(D,"mapProviderResponse");function de(e,o){return JSON.stringify({major:e.major,endpoint:e.transport.kind==="http"?e.transport.endpoint:null,baseUrl:e.commands.baseUrl??null,rest:o.rest,params:o.params,output:o.output})}m(de,"approvalShape");async function lr(e){const o=e.origin!==void 0?ne({node:e.origin.node??void 0,run:e.origin.run??void 0,machine:e.origin.machine}):ne({node:e.node_id??void 0,run:e.run_id??void 0,profile:e.node_id?(await rr(e.node_id))?.profile_id??void 0:void 0,machine:Ze()!==null?Ye():void 0});return o===""?{}:{"Crtr-Caller":o}}m(lr,"crtrCallerHeader");async function Hr(e,o,i){const p=Pe(o.provider);if(p===null)throw new l("not_found",`provider "${o.provider}" is not available`,{param:"provider"});const r={...o,provider:p},n=new AbortController,c=m(()=>n.abort(i.signal.reason),"abort");i.signal.aborted?c():i.signal.addEventListener("abort",c,{once:!0});let d=i.requestId;const h=i.traceId??De(),b=Ne({request_id:d,run_id:e.run_id,node_id:e.node_id,controller:n});let v,_,s,j,w,y,A,P="allowed";try{if(er()&&e.class==="person"&&e.resolved!==null&&!e.resolved.some(g=>g.startsWith(`${r.provider}:`)))throw ke(`${r.provider}:*`);try{await $e(r.provider)}catch{throw Re(r.provider)}let t=await S(r.provider,r.version),u=!1,k=!1,E,F,R,Q=!1,W=!1,U,X=0;for(;;){const g=dr(t,r.tool);if(s=`${t.id}:${g.group}`,fe(e,t.id,g.group),t.transport.kind!=="machine"&&r.machine!==void 0)throw new l("invalid_argument",`provider "${t.id}" is not served by a device, so it takes no machine`,{param:"machine"});t.transport.kind==="machine"&&U===void 0&&(U=await Je(r.machine,void 0,{newest:oe(t.major,r.tool)}),X=Date.now()+(t.commands.timeouts?.requestMs??Ve));let L=null;if(r.approval&&!Q){const a=await Ce(e,r,de(t,g));R=a.option,L=a.prepared,A=r.approval,d=a.requestId,Q=!0}const N={params:g.params.filter(a=>"type"in a&&a.type==="file").map(a=>a.name),output:g.output.find(a=>a.type==="file")?.name??null},Y=JSON.stringify(N);if(F!==void 0&&F!==Y)throw new l("provider_bad_response","the refreshed manifest changed the tool file contract",{origin:"provider",details:{status:409,message:"manifest_stale changed the tool file contract"}});F=Y,L&&(E=await ee(e,N,r.arguments,L,{signal:n.signal})),E??=await qe(e,N,r.arguments,{signal:n.signal});const x=await sr(e),{grantee:I}=x,T=r.as??x.sub;if(t.transport.kind==="machine"){if(r.as!==void 0)throw new l("not_granted","`--as` is not available on a provider served by a device",{param:"as"});const a=await cr(e,t,r,g,E,{sub:T,requestId:d,deadlineAt:X,signal:n.signal,machine:U});return y=a.responder,v=a.cleanup,{status:200,body:a.result}}const J=t.transport.endpoint;let q;try{q=r.as===void 0?await Me({audience:J,sub:T,grantee:I,initiating_app:I,scope:se(t,g)},{signal:n.signal}):await Te(x,r.as,{audience:J,scope:se(t,g)},{signal:n.signal})}catch(a){if(!(a instanceof l)||a.details?.directory_error!=="invalid_target"||k)throw a;k=!0,await Z(t.id,{conditional:!1,...r.version===void 0?{}:{version:r.version}});const $=await S(t.id,r.version);if($.transport.kind==="machine"||$.transport.endpoint===J)throw a;t=$;continue}j=q.jti;const H=e.class==="person"?nr:I,M=he({call:"tool",tokenPayer:q.payer,sub:T,environmentPayer:await ve(e.node_id)}),G=t.id===ir?null:await ge({scope:"call",payer:M.payer,funding:M.funding,sub:T,grantee:H,provider:`app:${t.id}`});if(G!==null)throw await be({request:d,kind:"tool",what:`${t.id}:${r.tool}`,usd:0,payer:M.payer,funding:M.funding,sub:T,actor:e.actor??(r.as===void 0?null:I),grantee:H,node:e.node_id,run:e.run_id,provider:`app:${t.id}`,causedBy:i.causedBy??null,refused:ye(G)}),we(G);const ue={registration:{name:t.id,endpoint:t.transport.endpoint},...t.commands.baseUrl?{baseUrl:t.commands.baseUrl}:{},...t.commands.timeouts?{timeouts:t.commands.timeouts}:{},params:g.params,rest:g.rest,output:g.output,commandPath:[t.id,...r.tool.split(" ")]},le=Be(ue,E.arguments,void 0,{authorization:`Bearer ${q.access_token}`,requestId:d,traceId:h,fileMode:"pass-through",extraHeaders:{...i.causedBy?{"Crtr-Caused-By":i.causedBy}:{},...e.run_id?{"Crtr-Run-Id":e.run_id}:{},...await lr(e),...R?{"Crtr-Approval":R}:{},...E.headers}});_??=Date.now()+(t.commands.timeouts?.requestMs??3e4);let f;try{if(f=await Fe(le,{connectMs:t.commands.timeouts?.connectMs,requestMs:t.commands.timeouts?.requestMs,deadlineAt:_,signal:n.signal}),n.signal.aborted)throw n.signal.reason??new Error("provider call aborted")}catch(a){throw n.signal.aborted?n.signal.reason??a:a instanceof Ue?new l("provider_unavailable",a.message,{origin:"provider",details:{status:null,code:a.kind}}):a}if(w??=await ar({provider:t.id,tool:r.tool,request_id:d,run_id:e.run_id,sub:T,grantee:I,payer:q.payer,ledger_grantee:H,funding:M.funding,node_id:e.node_id,actor:e.actor??(r.as===void 0?null:I),caused_by:i.causedBy??null,jti:q.jti,status:f.status,headers:f.headers}),y=f.headers["crtr-responder"],f.status===401&&Oe(q.key),f.status>=200&&f.status<300){const a=f.body;if(!a||typeof a!="object"||Array.isArray(a))throw new l("provider_bad_response","provider result is not a JSON object",{origin:"provider",details:{status:f.status,message:"provider result is not a JSON object"}});let $;try{$=await re(e,E,a,{signal:n.signal})}catch(O){throw O instanceof l&&O.code==="provider_error"?new l("provider_bad_response",O.message,{origin:"provider",details:{status:f.status,message:O.message}}):O}v=$.cleanup;const B=z(g.output,$.result);if(B)throw new l("provider_bad_response",`provider result has an invalid output field "${B.field}"`,{origin:"provider",param:B.field,details:{status:f.status,...B}});if(n.signal.aborted)throw n.signal.reason??new Error("provider call aborted");return{status:200,body:$.result}}const C=K(f.body);if(f.status===403&&C.code==="approval_required"&&!R&&!W){W=!0;const a=await Ie(e,r,d,C.question,n.signal,de(t,g),E);if(A=a.questionId,R=a.option,E=await ee(e,N,r.arguments,E,{signal:n.signal}),_=void 0,n.signal.aborted)throw new l("user_denied","the approval wait was canceled");continue}if(f.status===403&&C.code==="approval_required"&&R)throw D(f.status,f.body,f.headers,!0);const V=f.status===410&&C.code==="unsupported_major"&&r.version===void 0;if(f.status!==401&&(C.manifest_stale===!0||V)&&!u){u=!0;const a=t.major;await Z(t.id,{conditional:!1,...r.version===void 0?{}:{version:r.version}}),t=await S(t.id,r.version),je({level:"info",event:"daemon.providers.call_retried",fields:{provider:t.id,tool:r.tool,reason:V?"unsupported_major":"manifest_stale",major_before:a,major_after:t.major,...V&&typeof C.received=="number"?{received:C.received}:{}}});continue}throw D(f.status,f.body,f.headers,!!R)}}catch(t){throw t instanceof l&&t.question_id&&(A=t.question_id),y===void 0&&t instanceof l&&typeof t.responder=="string"&&(y=t.responder),P=`refused:${t instanceof l?t.code:"server_error"}`,await v?.(),t}finally{try{await xe({request_id:d,caller:e,provider:r.provider,tool:r.tool,scope_checked:s,outcome:P,jti:j,receipt_id:w,responder:y,question_id:A})}finally{b()}i.signal.removeEventListener("abort",c)}}m(Hr,"callProvider");function pr(e,o){const i={...o};for(const{name:p}of e.params){const r=Se(p);r===p||!Object.hasOwn(i,r)||(i[p]=i[r],delete i[r])}return i}m(pr,"declaredNames");async function cr(e,o,i,p,r,n){const{machine:c}=n;let d;try{d=await tr(e,n.sub)}catch(u){throw u instanceof or?new l("invalid_request",u.message,{origin:"runtime"}):u}const h={machine:c,envelope:d,signal:n.signal,deadlineAt:n.deadlineAt,mapFailure:D};if(oe(o.major,i.tool)){const u=await Ke(h,r.arguments,o.major),k=z(p.output,u);if(k)throw new l("provider_bad_response",`the libraries result has an invalid output field "${k.field}"`,{origin:"provider",param:k.field,details:{status:200,...k}});return{result:u,responder:void 0,cleanup:void 0}}let b=r.arguments,v=null,_="";if(ze(o.major,i.tool,r.arguments)){const u=await Qe(h,r.arguments,o.major);if(n.deadlineAt-Date.now()<=0)throw te(c,"timeout","");u!==null&&(b=u.arguments,v=u.services,_=u.release)}const s=await He(c,{tool:i.tool,arguments:pr(p,b),version:o.major,requestId:n.requestId,runId:e.run_id,deadlineAt:n.deadlineAt,upload:r.upload===null?null:{id:r.upload.upload_id,link:r.upload.upload_link}},d,n.signal);if(n.signal.aborted)throw n.signal.reason??new Error("provider call aborted");if("unreachable"in s)throw te(c,s.unreachable.reason,s.unreachable.message);const j=s.headers["crtr-responder"],w=K(s.body);if(s.status<200||s.status>=300){const u=Ge(c,s.status,typeof w.code=="string"?w.code:void 0,typeof w.message=="string"?w.message:void 0,s.body),k=u===null&&s.status>=500&&typeof w.code=="string"?new l("provider_error",typeof w.message=="string"?w.message:`the device answered HTTP ${s.status}`,{origin:"runtime",status:s.status,details:{code:w.code,status:s.status}}):null;throw Object.assign(u??k??D(s.status,s.body,s.headers),{responder:j})}const y=s.body&&typeof s.body=="object"&&!Array.isArray(s.body)?s.body.result:void 0;if(!y||typeof y!="object"||Array.isArray(y))throw Object.assign(new l("provider_bad_response","the device result is not a JSON object",{origin:"provider",details:{status:s.status,message:"the device result is not a JSON object"}}),{responder:j});let A=y;if(v!==null){const u=We(A,v);if(Xe(c,d,_,u.calls),"error"in u)throw Object.assign(u.error,{responder:j});A=u.result}let P;try{P=await re(e,r,A,{signal:n.signal})}catch(u){throw u instanceof l&&u.code==="provider_error"?Object.assign(new l("provider_bad_response",u.message,{origin:"provider",details:{status:s.status,message:u.message}}),{responder:j}):u}const t=z(p.output,P.result);if(t)throw await P.cleanup?.(),Object.assign(new l("provider_bad_response",`the device result has an invalid output field "${t.field}"`,{origin:"provider",param:t.field,details:{status:s.status,...t}}),{responder:j});return{result:P.result,responder:j,cleanup:P.cleanup}}m(cr,"callDevice");export{Hr as callProvider,lr as crtrCallerHeader,sr as identity,D as mapProviderResponse,ar as onProviderResponse,ie as providerLeaves,Jr as providerTools};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.778",
3
+ "version": "0.3.780",
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.778",
161
- "@north-light/plugin": "0.3.778",
160
+ "@north-light/identity": "0.3.780",
161
+ "@north-light/plugin": "0.3.780",
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",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/api",
3
- "version": "0.3.778",
3
+ "version": "0.3.780",
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/identity",
3
- "version": "0.3.778",
3
+ "version": "0.3.780",
4
4
  "description": "Northlight access-token verification and scope rules",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/plugin",
3
- "version": "0.3.778",
3
+ "version": "0.3.780",
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.778",
31
- "@north-light/identity": "0.3.778"
30
+ "@north-light/api": "0.3.780",
31
+ "@north-light/identity": "0.3.780"
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.778",
3
+ "version": "0.3.780",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@north-light/cli",
9
- "version": "0.3.778",
9
+ "version": "0.3.780",
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.778",
32
- "@north-light/plugin": "0.3.778",
31
+ "@north-light/identity": "0.3.780",
32
+ "@north-light/plugin": "0.3.780",
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.778",
11905
+ "version": "0.3.780",
11906
11906
  "license": "UNLICENSED"
11907
11907
  },
11908
11908
  "packages/crouter-env-docker": {
11909
11909
  "name": "@north-light/env-docker",
11910
- "version": "0.3.778",
11910
+ "version": "0.3.780",
11911
11911
  "license": "UNLICENSED"
11912
11912
  },
11913
11913
  "packages/crouter-identity": {
11914
11914
  "name": "@north-light/identity",
11915
- "version": "0.3.778",
11915
+ "version": "0.3.780",
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.778",
11923
+ "version": "0.3.780",
11924
11924
  "license": "UNLICENSED",
11925
11925
  "dependencies": {
11926
- "@north-light/api": "0.3.778",
11927
- "@north-light/identity": "0.3.778"
11926
+ "@north-light/api": "0.3.780",
11927
+ "@north-light/identity": "0.3.780"
11928
11928
  }
11929
11929
  },
11930
11930
  "packages/crouter-sdk": {
11931
11931
  "name": "@north-light/sdk",
11932
- "version": "0.3.778",
11932
+ "version": "0.3.780",
11933
11933
  "license": "UNLICENSED",
11934
11934
  "dependencies": {
11935
- "@north-light/api": "0.3.778",
11936
- "@north-light/identity": "0.3.778",
11937
- "@north-light/plugin": "0.3.778",
11935
+ "@north-light/api": "0.3.780",
11936
+ "@north-light/identity": "0.3.780",
11937
+ "@north-light/plugin": "0.3.780",
11938
11938
  "jose": "^6.2.1"
11939
11939
  },
11940
11940
  "bin": {