dispach 0.1.1 → 0.1.2
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/README.md +72 -13
- package/dist/{App-5a35bjkt.js → App-b1yrwrcq.js} +6 -6
- package/dist/{App-5a35bjkt.js.map → App-b1yrwrcq.js.map} +1 -1
- package/dist/{ConfigEditor-7nnc2ke6.js → ConfigEditor-n8hdw6r7.js} +2 -2
- package/dist/{KeyProbe-kbz0j6sm.js → KeyProbe-9jjeze5r.js} +2 -2
- package/dist/{Picker-2zjjt17a.js → Picker-hfeh1g6m.js} +3 -3
- package/dist/{Picker-2zjjt17a.js.map → Picker-hfeh1g6m.js.map} +1 -1
- package/dist/{SessionPicker-fyyvxy40.js → SessionPicker-zyqkg4dn.js} +3 -3
- package/dist/{SessionPicker-fyyvxy40.js.map → SessionPicker-zyqkg4dn.js.map} +1 -1
- package/dist/{SkillBrowser-x7r51zy0.js → SkillBrowser-3qdp8080.js} +3 -3
- package/dist/{SkillBrowser-x7r51zy0.js.map → SkillBrowser-3qdp8080.js.map} +1 -1
- package/dist/{WizardApp-v0dghsyw.js → WizardApp-vzpbydy3.js} +3 -3
- package/dist/{WizardApp-v0dghsyw.js.map → WizardApp-vzpbydy3.js.map} +1 -1
- package/dist/client.js +10 -10
- package/dist/client.js.map +4 -4
- package/dist/{config-9cv76yrk.js → config-g7za9x13.js} +5 -5
- package/dist/{config-9cv76yrk.js.map → config-g7za9x13.js.map} +1 -1
- package/dist/credential-npr6z8c8.js +19 -0
- package/dist/{credential-yxqj8x1f.js.map → credential-npr6z8c8.js.map} +2 -2
- package/dist/{index-zked16y4.js → index-02dn6m2j.js} +2 -2
- package/dist/{index-a4xqgdrm.js → index-0d93hyfc.js} +2 -2
- package/dist/{index-5t6wahx8.js → index-1c5113t4.js} +26 -26
- package/dist/index-1c5113t4.js.map +12 -0
- package/dist/{index-zxh0ntgf.js → index-258d8bzg.js} +2 -2
- package/dist/{index-nvm5hwe4.js → index-6p999cx4.js} +5 -5
- package/dist/{index-nvm5hwe4.js.map → index-6p999cx4.js.map} +1 -1
- package/dist/{index-73jfw4jp.js → index-6q4wf8e3.js} +2 -2
- package/dist/{index-r3wwvqzb.js → index-fecm8xe7.js} +16 -16
- package/dist/{index-r3wwvqzb.js.map → index-fecm8xe7.js.map} +2 -2
- package/dist/{index-83bqtze0.js → index-ff514z3y.js} +5 -5
- package/dist/{index-83bqtze0.js.map → index-ff514z3y.js.map} +1 -1
- package/dist/{index-17an0jqq.js → index-h9mw7b9d.js} +2 -2
- package/dist/{index-5x4dn0gg.js → index-hwpvhaza.js} +2 -2
- package/dist/{index-e0j1jafd.js → index-j55s3ehk.js} +5 -5
- package/dist/{index-e0j1jafd.js.map → index-j55s3ehk.js.map} +1 -1
- package/dist/{index-000rxxy3.js → index-mtn0g9vc.js} +4 -4
- package/dist/{index-000rxxy3.js.map → index-mtn0g9vc.js.map} +1 -1
- package/dist/{index-dwyr2kdm.js → index-qdbq8crg.js} +4 -4
- package/dist/{index-dwyr2kdm.js.map → index-qdbq8crg.js.map} +1 -1
- package/dist/{index-ez2mb28y.js → index-s9mbq7h6.js} +4 -4
- package/dist/{index-ez2mb28y.js.map → index-s9mbq7h6.js.map} +1 -1
- package/dist/{index-0b1hdwnm.js → index-tf71ap9v.js} +2 -2
- package/dist/index-ttwyrdjs.js +427 -0
- package/dist/index-ttwyrdjs.js.map +11 -0
- package/dist/{index-7z4sw2dm.js → index-tv4yv7d2.js} +162 -162
- package/dist/{index-7z4sw2dm.js.map → index-tv4yv7d2.js.map} +8 -8
- package/dist/{index-d69d6pkm.js → index-ty24n0jh.js} +35 -35
- package/dist/{index-d69d6pkm.js.map → index-ty24n0jh.js.map} +1 -1
- package/dist/{index-2wmsmcbr.js → index-vgc3y3rm.js} +4 -4
- package/dist/{index-2wmsmcbr.js.map → index-vgc3y3rm.js.map} +1 -1
- package/dist/index-whaw4b18.js +6 -0
- package/dist/index-whaw4b18.js.map +10 -0
- package/dist/index.js +50 -50
- package/dist/index.js.map +3 -3
- package/dist/lib/commands.d.ts.map +1 -1
- package/dist/lib/init-flow.d.ts +17 -4
- package/dist/lib/init-flow.d.ts.map +1 -1
- package/dist/lib/provision.d.ts.map +1 -1
- package/dist/{web-x77y8w3v.js → web-vkb16r62.js} +4 -4
- package/dist/{web-x77y8w3v.js.map → web-vkb16r62.js.map} +1 -1
- package/dist/wire.js +10 -10
- package/dist/wire.js.map +4 -4
- package/package.json +1 -1
- package/dist/credential-yxqj8x1f.js +0 -19
- package/dist/index-5t6wahx8.js.map +0 -12
- package/dist/index-9bkd0fdj.js +0 -427
- package/dist/index-9bkd0fdj.js.map +0 -11
- package/dist/index-xf178c4m.js +0 -6
- package/dist/index-xf178c4m.js.map +0 -10
- /package/dist/{ConfigEditor-7nnc2ke6.js.map → ConfigEditor-n8hdw6r7.js.map} +0 -0
- /package/dist/{KeyProbe-kbz0j6sm.js.map → KeyProbe-9jjeze5r.js.map} +0 -0
- /package/dist/{index-zked16y4.js.map → index-02dn6m2j.js.map} +0 -0
- /package/dist/{index-a4xqgdrm.js.map → index-0d93hyfc.js.map} +0 -0
- /package/dist/{index-zxh0ntgf.js.map → index-258d8bzg.js.map} +0 -0
- /package/dist/{index-73jfw4jp.js.map → index-6q4wf8e3.js.map} +0 -0
- /package/dist/{index-17an0jqq.js.map → index-h9mw7b9d.js.map} +0 -0
- /package/dist/{index-5x4dn0gg.js.map → index-hwpvhaza.js.map} +0 -0
- /package/dist/{index-0b1hdwnm.js.map → index-tf71ap9v.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Mt,e,E,tr,t,
|
|
2
|
+
import{Mt,e,E,tr,t,_e,fn,Ie,mt,je,H,hn,kr,Sr,ye,xr,ze,we,mn,pt,T,x,R,yt,He,wt,gn,We,_,M,$r,L,yn,Rr,Ir,m,Co}from"./index-tv4yv7d2.js";import{Me,Fn,Un,jn}from"./index-1c5113t4.js";import{A,O,Y,N,X,C,fr,et,hr,Ht,G,Kr,Hr,Wr,Mn,ce,tt,ke,Ln,Se,nt,qr,Gr}from"./index-ty24n0jh.js";import{Ko}from"./index-d4x6yvqh.js";import{Et}from"./index-gme2egyq.js";import{ct,ut,cn,Nt,un,ft,Qn,Ct,Pt,Fe,Te,ht,er}from"./index-ttwyrdjs.js";import{Rt,le,Ot}from"./index-whaw4b18.js";import{on,sn,$t,Xn,lt,bo,ko,So}from"./index-258d8bzg.js";import"./index-cqqb6gaq.js";import{cr,Lr,Xe,Dr,Fr,Ur}from"./index-fecm8xe7.js";import{Ye,Pr}from"./index-ammv5st7.js";import{jr}from"./index-hwpvhaza.js";import{zr,Pn,Br,Ce,Pe,St,xt,Je,Qe,Kt}from"./index-qdbq8crg.js";import{Wt,pe,Zr,b,Vr,J,ue,Dn,Yr,Z,ie}from"./index-6p999cx4.js";import{Ee,ee,B,w,Xt,Jt,ao,K,te}from"./index-mtn0g9vc.js";import{Hn}from"./index-4cf6v9nb.js";import{_o,$o}from"./index-tf71ap9v.js";import{Ro}from"./index-s9mbq7h6.js";import{q}from"./index-h9mw7b9d.js";import{l,p,d,c,bt,or,vt,qe}from"./index-j7gyr5nx.js";import{jo,Bo}from"./index-3g3ny01d.js";import{_n,Jo,ve,j,An,Cn,n,s,Bt,us}from"./index-vgc3y3rm.js";async function Gt(r){let o=await L.create({agents:[...r.manifestPaths],toolProviders:A,builtInPlugins:C,scriptRunner:O(),channels:N,env:m(r.manifestPaths),store:w(),lease:!1});b(()=>o.stop("cli-exit"));let a=o.list().map((f)=>f.describe()),u=new Map;for(let f of await o.store.leases.all()){if(f.runtimeId===o.runtimeId||!_(f.pid))continue;let h=Date.now()-Date.parse(f.startedAt);u.set(f.agentId,`serving · ${f.mode} · pid ${f.pid}${Number.isFinite(h)?` · up ${or(h)}`:""}`)}if(r.json===!0)return process.stdout.write(`${JSON.stringify({agents:a.map((f)=>({...f,serving:u.get(f.id)??null}))},null,2)}
|
|
3
3
|
`),n;let i=a.map((f)=>({label:f.id,value:`${f.model} ${String(f.window).padStart(7)} window`,note:u.get(f.id)??f.name}));return process.stdout.write(`${l(i)}
|
|
4
4
|
`),n}import{closeSync as Wo,existsSync as Tr,mkdirSync as Go,openSync as qo,readFileSync as Vo,readSync as Xo,statSync as Ar}from"node:fs";import{homedir as Yn}from"node:os";import{dirname as kn,join as Or,resolve as zo}from"node:path";function qt(r){let o=[];if(r.problem!==void 0)o.push({code:"daemon_agent_unreadable",severity:"warn",message:`Agent "${r.agentId}" could not be read: ${r.problem}`,hint:"The host skips an agent whose manifest will not load and serves the rest, so this is a warning rather than a refusal — `validate` on that agent says exactly what is wrong with it."});if(r.envFileMode!==void 0&&(r.envFileMode&63)!==0)o.push({code:"daemon_env_world_readable",severity:"warn",message:`${r.agentId}'s .env is mode ${(r.envFileMode&511).toString(8)} and holds its only secrets.`,hint:`Under a service manager that file is the *only* path credentials arrive by — a unit carries none on purpose, because its manager echoes the environment in plaintext. \`chmod 600 ${r.agentDir}/.env\`.`});return o}function Eo(r){let o=[];if(r.gitRoot!==void 0)o.push({code:"daemon_binary_in_checkout",severity:"warn",message:`The binary resolves to ${r.scriptPath}, inside a git checkout at ${r.gitRoot}.`,hint:"A rebuild, a branch switch or a `git clean` changes or breaks what the service runs, and the failure arrives with no obvious connection to the change. Fine for testing; install a released build for a service you intend to leave running."});if(/[/.](nvm|fnm|volta|asdf)\//.test(r.execPath))o.push({code:"daemon_versioned_runtime",severity:"warn",message:`The interpreter is a version-managed install: ${r.execPath}`,hint:"The absolute path is baked into the service definition, so removing that runtime version later kills the service with a message only the log file sees. A system or Homebrew install is more durable."});return o}function Vt(r){let o=[];for(let a of r.retiring)o.push({code:"daemon_per_agent_retired",severity:"warn",message:`Retiring ${a} — one service hosts every agent now.`,hint:"It is unloaded, re-enabled and its definition removed. The re-enable is not cosmetic: a `disable` row persists across boots and no verb deletes it, so a label left disabled makes any future job with that name install cleanly and silently never start. Per-agent on/off is `stop <agent>`, which persists in the store instead."});if(r.servedElsewhere.length>0){let a=r.servedElsewhere[0];o.push({code:"daemon_agents_held_elsewhere",severity:"warn",message:`${r.servedElsewhere.length} agent(s) are held by other live processes — ${a?.agentId} by pid ${a?.pid} (${a?.mode}).`,hint:"The service will start and serve everything else, and report those as served elsewhere rather than fighting for them — one listener per bot token is the whole reason the lease exists. `stop` with no agent ends the other processes."})}return o.push(...Eo(r.binary)),o}function Io(r,o="serving on"){let a=r.lastIndexOf(o);return a===-1?r:r.slice(a)}function zt(r){let o=Io(r),a=[],u=new Set;for(let i of o.matchAll(/denied — Sender "([^"]+)" is not in channel "([^"]+)"/g))if(i[1]!==void 0)u.add(`${i[1]}|${i[2]??""}`);for(let i of u){let[f,h]=i.split("|");a.push({code:"inbound_denied",summary:`messages from ${f} are being refused — they are not on channel "${h}"'s allowFrom list`,fix:`add ${f} to allowFrom in agent.yaml, then restart. An allowlist that is empty, or that has a typo in it, refuses silently from the sender's side: they see nothing at all.`})}if(/channel_telegram_unauthorized|telegram_token_missing/.test(o))a.push({code:"channel_unauthorized",summary:"the channel rejected its token",fix:"check the token in the .env beside the manifest, then restart."});return a}var To=3;function Yt(r,o){let a=Ao(o),u=[];if(o.pid!==void 0)u.push({label:"state",value:`running · pid ${o.pid}`,...o.uptimeMs===void 0?{}:{note:`up ${or(o.uptimeMs)}`}});else if(o.leasePid!==void 0)u.push({label:"state",value:`running in a terminal · pid ${o.leasePid}`,note:"not installed as a service"});if(o.runs!==void 0&&o.runs>1)u.push({label:"starts",value:String(o.runs),...a==="restart-loop"?{note:`launchd has restarted this ${o.runs} times`}:{note:"since the service was installed"}});if(a!=="running"&&o.lastExitCode!==void 0&&o.lastExitCode!==0)u.push({label:"last exit",value:`code ${o.lastExitCode}`});if(o.stderrPath!==void 0)u.push({label:"logs",value:o.stderrPath,...o.stderrBytes===void 0?{}:{note:`(${bt(o.stderrBytes)})`}});return{verdict:a,healthy:a==="running",headline:a==="restart-loop"?`${r} — RESTART LOOP`:`${r} — ${Oo(a)}`,rows:u,wantsStderrTail:a==="restart-loop"||a==="failed"||a==="installed-idle"}}function Ao(r){if(!r.installed)return r.leasePid===void 0?"absent":"running";if(r.pid!==void 0)return"running";if(r.disabled)return"stopped";if((r.runs??0)>=To&&(r.lastExitCode??0)!==0)return"restart-loop";if((r.lastExitCode??0)!==0)return"failed";return"installed-idle"}function Oo(r){switch(r){case"running":return"running";case"failed":return"STOPPED AFTER A FAILURE";case"restart-loop":return"exited · nothing is running";case"stopped":return"stopped by you";case"installed-idle":return"installed · not running";case"absent":return"not installed"}}function Qt(r){return`${r.headline}
|
|
5
|
-
${l(r.rows)}`}function dn(r){return["HOME","PATH","TMPDIR",`${r}SERVICE`,`${r}HOME`]}class Wn extends Error{code="daemon_secret_in_service";hint;constructor(r,o,a){super(`The service definition would carry an environment variable named ${r}.`);this.hint=`A ${a} unit is readable and its manager echoes every environment value in plaintext to any process running as this user — so a credential here is a credential published. The agent reads its own secrets from the .env beside its manifest, which is what the service is pointed at. Only these may appear: ${o.join(", ")}.`}}function ln(r,o,a){let u=dn(o);for(let i of Object.keys(r))if(!u.includes(i))throw new Wn(i,u,a)}var No={Crashed:!0},Be=30,Ge=30;function pn(r,o){return`${r}.agent.${o}`}function Ke(r){return`${r}.server`}function
|
|
6
|
-
`),u=Object.entries(r.environment).map(([f,h])=>` <key>${
|
|
7
|
-
<string>${
|
|
5
|
+
${l(r.rows)}`}function dn(r){return["HOME","PATH","TMPDIR",`${r}SERVICE`,`${r}HOME`]}class Wn extends Error{code="daemon_secret_in_service";hint;constructor(r,o,a){super(`The service definition would carry an environment variable named ${r}.`);this.hint=`A ${a} unit is readable and its manager echoes every environment value in plaintext to any process running as this user — so a credential here is a credential published. The agent reads its own secrets from the .env beside its manifest, which is what the service is pointed at. Only these may appear: ${o.join(", ")}.`}}function ln(r,o,a){let u=dn(o);for(let i of Object.keys(r))if(!u.includes(i))throw new Wn(i,u,a)}var No={Crashed:!0},Be=30,Ge=30;function pn(r,o){return`${r}.agent.${o}`}function Ke(r){return`${r}.server`}function Re(r){return r.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")}function wn(r,o){ln(r.environment,o,"launchd");let a=r.programArguments.map((f)=>` <string>${Re(f)}</string>`).join(`
|
|
6
|
+
`),u=Object.entries(r.environment).map(([f,h])=>` <key>${Re(f)}</key>
|
|
7
|
+
<string>${Re(h)}</string>`).join(`
|
|
8
8
|
`);return`<?xml version="1.0" encoding="UTF-8"?>
|
|
9
9
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
10
10
|
<!--
|
|
11
|
-
${r.provenance.map((f)=>` ${
|
|
11
|
+
${r.provenance.map((f)=>` ${Re(f)}`).join(`
|
|
12
12
|
`)}
|
|
13
13
|
-->
|
|
14
14
|
<plist version="1.0">
|
|
15
15
|
<dict>
|
|
16
16
|
<key>Label</key>
|
|
17
|
-
<string>${
|
|
17
|
+
<string>${Re(r.label)}</string>
|
|
18
18
|
<key>ProgramArguments</key>
|
|
19
19
|
<array>
|
|
20
20
|
${a}
|
|
@@ -33,11 +33,11 @@ ${a}
|
|
|
33
33
|
<key>ProcessType</key>
|
|
34
34
|
<string>Adaptive</string>
|
|
35
35
|
<key>WorkingDirectory</key>
|
|
36
|
-
<string>${
|
|
36
|
+
<string>${Re(r.workingDirectory)}</string>
|
|
37
37
|
<key>StandardOutPath</key>
|
|
38
|
-
<string>${
|
|
38
|
+
<string>${Re(r.stdoutPath)}</string>
|
|
39
39
|
<key>StandardErrorPath</key>
|
|
40
|
-
<string>${
|
|
40
|
+
<string>${Re(r.stderrPath)}</string>
|
|
41
41
|
<key>EnvironmentVariables</key>
|
|
42
42
|
<dict>
|
|
43
43
|
${u}
|
|
@@ -123,9 +123,9 @@ ${c(v.tail,4)}
|
|
|
123
123
|
`:`${i}
|
|
124
124
|
`),r.follow!==!0)return n;return await sr([{path:u.err,label:"stderr"},{path:u.out,label:"stdout"}],li(),{offsets:{[u.err]:$n(u.err)??0,[u.out]:$n(u.out)??0},intervalMs:us}),n}function li(){let r=!1,o,a=()=>{r=!0,o?.()};return process.on("SIGINT",a),b(()=>{process.off("SIGINT",a)}),{sizeOf:(u)=>$n(u),read:(u,i,f)=>{try{let h=qo(u,"r");try{let g=Buffer.alloc(f-i),v=Xo(h,g,0,g.length,i);return g.subarray(0,v).toString("utf8")}finally{Wo(h)}}catch{return""}},write:(u)=>void process.stdout.write(u),wait:(u)=>new Promise((i)=>{if(r){i();return}let f=setTimeout(i,u);o=()=>{clearTimeout(f),i()}}),stopped:()=>r}}function _r(r){let o=T(r);if(o.id===void 0||o.id==="")throw new t({code:"cli_daemon_agent_id_missing",message:`${r} declares no id, so there is no stable name to install a service under.`,hint:"A service label is derived from the manifest id and has to survive a rename of the directory. Add `id: <name>` to the manifest."});return o.id}function Ve(r){return vt(zo(r),Yn())}function $n(r){try{return Ar(r).size}catch{return}}function zn(r,o){try{let a=Vo(r,"utf8").trimEnd();if(a==="")return"";return a.split(`
|
|
125
125
|
`).slice(-o).join(`
|
|
126
|
-
`)}catch{return""}}var ll=dn(e.envPrefix);import{basename as Si,dirname as xi,join as
|
|
126
|
+
`)}catch{return""}}var ll=dn(e.envPrefix);import{basename as Si,dirname as xi,join as xe,resolve as Pi}from"node:path";import{rmSync as ci}from"node:fs";import{isAbsolute as Cr,join as ui,resolve as Nr}from"node:path";var fi=3;async function Mr(r){if(r.answers.skills!=="find")return;let o=r.answers.skillsSearch?.trim()??"";if(o===""){process.stdout.write("\nno words to search for, so no skill was installed — `sources search <words>` when you know what you want\n");return}let a=G(r.env);if(a.length===0){process.stdout.write("\nno skill sources are configured, so there was nothing to search\n\n `sources add <url>` adds one, then `skills install <agent> <source>/<skill>`.\n");return}process.stdout.write(`
|
|
127
127
|
searching ${a.length} skill source(s) for ${JSON.stringify(o)}
|
|
128
|
-
`);let u=[],i=[];for(let y of a){if(!ce(y.name,r.env))try{await tt(y,{...r.env===void 0?{}:{env:r.env},...r.git===void 0?{}:{git:r.git}})}catch(S){i.push(`${y.name} — ${S instanceof t?S.message:String(S)}`);continue}u.push(...
|
|
128
|
+
`);let u=[],i=[];for(let y of a){if(!ce(y.name,r.env))try{await tt(y,{...r.env===void 0?{}:{env:r.env},...r.git===void 0?{}:{git:r.git}})}catch(S){i.push(`${y.name} — ${S instanceof t?S.message:String(S)}`);continue}u.push(...ke(y,r.env))}for(let y of i)process.stdout.write(c(`could not fetch ${y}
|
|
129
129
|
`));if(u.length===0){process.stdout.write(`${c("no source could be read, so no skill was installed — the directory is there and empty")}
|
|
130
130
|
${c("`sources update` reports why; `sources search <words>` when it works",4)}
|
|
131
131
|
`);return}let f=mi(o,u);if(f.length===0){process.stdout.write(`${c(`nothing in ${u.length} skills matches those words, so none was installed`)}
|
|
@@ -133,18 +133,18 @@ ${c("the ranking is lexical: try the words a skill's own description would use,
|
|
|
133
133
|
`);return}let h=f[0],g=`${h.source}/${h.skill}`;if(process.stdout.write(`${c(`best of ${u.length}: ${g}`)}
|
|
134
134
|
`),f.length>1)process.stdout.write(`${c(`also matched: ${f.slice(1,1+fi).map((y)=>`${y.source}/${y.skill}`).join(", ")}`,4)}
|
|
135
135
|
`);if(process.stdout.write(`
|
|
136
|
-
`),
|
|
136
|
+
`),Se({action:"install",manifestPath:r.manifestPath,name:g,...r.env===void 0?{}:{sandboxEnv:r.env},...r.envOverlay===void 0?{}:{envOverlay:r.envOverlay}})!==n)return;let k=pi(r.manifestPath,r.envOverlay);if(k!==void 0)hi(r.manifestPath,h.skill,r.envOverlay),process.stdout.write(`
|
|
137
137
|
${d(`${g} was removed again: it does not load on this machine`)}
|
|
138
138
|
${c(k,4)}
|
|
139
139
|
${c("everything else is fine; `sources search` for one that needs no extra runtime",4)}
|
|
140
|
-
`)}function mi(r,o){let a=new Map,u=o.filter((i)=>i.problem===void 0).map((i)=>{let f=`${i.source}/${i.skill}`;return a.set(f,i),{name:f,dir:i.dir,tokens:i.tokens,scripts:[],ignoredScripts:[],frontmatter:{name:f,description:i.description,metadata:{}}}});return wt(r,u).filter((i)=>i.score>0).map((i)=>a.get(i.skill.name)).filter((i)=>i!==void 0)}function pi(r,o){try{let a=x(r,{knownProviders:Y,knownChannels:X,...o===void 0?{}:{env:{...process.env,...o}}}),u=a.manifest.skills;if(u===void 0)return;let i=H(a.manifest.model.main.id,a.manifest.model.main.capabilities);He({dir:Cr(u.dir)?u.dir:Nr(a.dir,u.dir),maxActive:u.maxActive,threshold:u.threshold,style:i.promptStyle,agentDir:a.dir,runner:O()});return}catch(a){return a instanceof t?a.message:String(a)}}function hi(r,o,a){try{let u=x(r,{knownProviders:Y,knownChannels:X,...a===void 0?{}:{env:{...process.env,...a}}}),i=u.manifest.skills;if(i===void 0)return;let f=Cr(i.dir)?i.dir:Nr(u.dir,i.dir);ci(ui(f,o),{recursive:!0,force:!0}),Ln(f,o)}catch{}}import{existsSync as gi,mkdirSync as yi,writeFileSync as wi}from"node:fs";import{dirname as bi,join as Zn,resolve as vi}from"node:path";var Sn={user:"--user",name:"--name",purpose:"--purpose",preset:"--preset",model:"--model",baseUrl:"--base-url",apiKeyEnv:"--api-key-env",apiKey:"(asked at the prompt only)",system:"--system",web:"--web",webBackend:"--web-backend",webKey:"(asked at the prompt only)",composio:"--composio",composioKey:"(asked at the prompt only)",telegram:"--telegram",telegramAllow:"--telegram-allow",telegramToken:"(asked at the prompt only)",schedules:"--schedules",server:"--server",skills:"--skills",skillsSearch:"--skills",skillsPick:"--skills",daemon:"--daemon",serverToken:"(generated)",dirChoice:"--dir",dir:"--dir"};function rt(r,o,a){let u=[];for(;;){let i=Fe(r,a);if(i===void 0)break;if(i.optional===!0){r[i.step]="";continue}if(i.fallback===""){u.push(i.step),r[i.step]="(missing)";continue}let f=
|
|
140
|
+
`)}function mi(r,o){let a=new Map,u=o.filter((i)=>i.problem===void 0).map((i)=>{let f=`${i.source}/${i.skill}`;return a.set(f,i),{name:f,dir:i.dir,tokens:i.tokens,scripts:[],ignoredScripts:[],frontmatter:{name:f,description:i.description,metadata:{}}}});return wt(r,u).filter((i)=>i.score>0).map((i)=>a.get(i.skill.name)).filter((i)=>i!==void 0)}function pi(r,o){try{let a=x(r,{knownProviders:Y,knownChannels:X,...o===void 0?{}:{env:{...process.env,...o}}}),u=a.manifest.skills;if(u===void 0)return;let i=H(a.manifest.model.main.id,a.manifest.model.main.capabilities);He({dir:Cr(u.dir)?u.dir:Nr(a.dir,u.dir),maxActive:u.maxActive,threshold:u.threshold,style:i.promptStyle,agentDir:a.dir,runner:O()});return}catch(a){return a instanceof t?a.message:String(a)}}function hi(r,o,a){try{let u=x(r,{knownProviders:Y,knownChannels:X,...a===void 0?{}:{env:{...process.env,...a}}}),i=u.manifest.skills;if(i===void 0)return;let f=Cr(i.dir)?i.dir:Nr(u.dir,i.dir);ci(ui(f,o),{recursive:!0,force:!0}),Ln(f,o)}catch{}}import{existsSync as gi,mkdirSync as yi,writeFileSync as wi}from"node:fs";import{dirname as bi,join as Zn,resolve as vi}from"node:path";var Sn={user:"--user",name:"--name",purpose:"--purpose",preset:"--preset",model:"--model",baseUrl:"--base-url",apiKeyEnv:"--api-key-env",apiKey:"(asked at the prompt only)",system:"--system",web:"--web",webBackend:"--web-backend",webKey:"(asked at the prompt only)",composio:"--composio",composioKey:"(asked at the prompt only)",telegram:"--telegram",telegramAllow:"--telegram-allow",telegramToken:"(asked at the prompt only)",schedules:"--schedules",server:"--server",skills:"--skills",skillsSearch:"--skills",skillsPick:"--skills",daemon:"--daemon",serverToken:"(generated)",dirChoice:"--dir",dir:"--dir"};function rt(r,o,a){let u=[];for(;;){let i=Fe(r,a);if(i===void 0)break;if(i.optional===!0){r[i.step]="";continue}if(i.fallback===""){u.push(i.step),r[i.step]="(missing)";continue}let f=Te(i.step,i.fallback);if(f.ok)r[i.step]=f.value}if(u.length>0){let i=u.map((f)=>Sn[f]).join(", ");throw new t({code:"cli_init_missing_answers",message:`Not interactive (${o}), and ${u.join(", ")} ${u.length===1?"has":"have"} no default.`,hint:`Pass ${i} — an agent's name is not something to guess — or run the command at a terminal to be asked. Everything with a sensible default (purpose, preset, endpoint, directory) already took it.`})}}function st(r,o){let a=r,u=ct(a.preset),i=a.apiKeyEnv??u?.apiKeyEnv,f=a.server??"local",h=a.dir??ut(a.dirChoice,a.name,o);if(h===void 0)throw new t({code:"cli_init_no_directory",message:`The directory answer was ${JSON.stringify(a.dirChoice)}, which resolves to no path.`,hint:"This is a bug in the CLI: every dirChoice except `custom` must derive a path in `dirFor`, and `custom` must have asked the dir question. Pass --dir <path> to get past it."});return{user:a.user,name:a.name,purpose:a.purpose,preset:a.preset,model:a.model,baseUrl:a.baseUrl,system:a.system,web:a.web,...a.webBackend===void 0?{}:{webBackend:a.webBackend},...a.webKey===void 0||a.webKey===""?{}:{webKey:a.webKey},composio:a.composio,...a.composioKey===void 0||a.composioKey===""?{}:{composioKey:a.composioKey},telegram:a.telegram,...a.telegramToken===void 0||a.telegramToken===""?{}:{telegramToken:a.telegramToken},...a.telegramAllow===void 0||a.telegramAllow===""?{}:{telegramAllow:a.telegramAllow},schedules:a.schedules??"none",server:f,skills:a.skills,...a.skillsSearch===void 0||a.skillsSearch===""?{}:{skillsSearch:a.skillsSearch},...a.skillsPick===void 0||a.skillsPick===""?{}:{skillsPick:a.skillsPick},daemon:a.daemon,...f==="local"?{serverToken:$i()}:{},...i===void 0?{}:{apiKeyEnv:i},...a.apiKey===void 0||a.apiKey===""?{}:{apiKey:a.apiKey},...a.dirChoice===void 0?{}:{dirChoice:a.dirChoice},dir:h}}function $i(){let r=new Uint8Array(32);return crypto.getRandomValues(r),[...r].map((o)=>o.toString(16).padStart(2,"0")).join("")}function ot(r,o){let a=o.map((u)=>Zn(r,u.relPath)).filter((u)=>gi(u));if(a.length>0)throw new t({code:"cli_init_target_exists",message:`${a.length} of the files init would write already exist: ${a.join(", ")}`,hint:"Nothing is overwritten and there is no --force — replacing a personalised workspace is exactly the loss this command exists to prevent. Point init at a fresh directory, or delete the files first if they really are disposable."});for(let u of o){let i=Zn(r,u.relPath);yi(bi(i),{recursive:!0}),wi(i,u.contents,{encoding:"utf8",...u.relPath===".env"?{mode:384}:{}})}}var Jr=new Map([["dir",{code:"provision_directory_refused",hint:"A provisioned agent lands in this host's sandbox, because where an agent lives on disk is the operator's decision rather than a caller's. Use `init --dir` at a terminal to put one somewhere else."}],["dirChoice",{code:"provision_directory_refused",hint:"A provisioned agent lands in this host's sandbox, because where an agent lives on disk is the operator's decision rather than a caller's. Use `init --dir` at a terminal to put one somewhere else."}],["daemon",{code:"provision_daemon_refused",hint:"This server is already hosting the agent you are creating — that is what `adopted` in the response means. Installing a service unit is `daemon install` at a terminal, and a route that writes one would be a web page installing a background process."}]]),it=new Map([["skills",new Map([["find",{code:"provision_skills_search_refused",hint:"Searching the catalogues is an interactive picker, not an answer — over the wire it would write no skills and report success. Send `starter` or `none`, then `skills search` and `skills install` once the agent exists."}]])]]);function Qr(r){let o=Te(r.step,r.fallback);return o.ok?o.value:r.fallback}function ki(r,o){let a=it.get(r.step);return{step:r.step,prompt:r.prompt,fallback:Qr(r),optional:r.optional===!0,secret:Ct.has(r.step),...o===void 0?{}:{requires:o},...r.options===void 0?{}:{choices:r.options.filter((u)=>a?.has(u.value)!==!0).map((u)=>({value:u.value,label:u.label,...u.hint===void 0?{}:{hint:u.hint}}))}}}var Xr=64;function es(r){let o=new Map,a=new Set,u=(f,h)=>{let g={...f},v=[];for(let k=0;k<Xr;k+=1){let y=Fe(g,r);if(y===void 0)break;let S=Qr(y);if(!Jr.has(y.step)&&!o.has(y.step))o.set(y.step,ki(y,h));for(let P of y.options??[]){if(P.value===S)continue;if(it.get(y.step)?.has(P.value)===!0)continue;v.push({seed:{...g,[y.step]:P.value},opened:{step:y.step,value:P.value}})}g[y.step]=S}return v},i=[...u({})];for(let f=0;f<Xr&&i.length>0;f+=1){let h=i.splice(0,i.length);for(let g of h){let v=`${g.opened.step}=${g.opened.value}`;if(a.has(v))continue;a.add(v),i.push(...u(g.seed,g.opened))}}return[...o.values()].sort((f,h)=>Qn.indexOf(f.step)-Qn.indexOf(h.step))}function ns(r){let o={};for(let[g,v]of Object.entries(r.answers)){let k=g;if(!(k in Sn))throw new t({code:"provision_unknown_answer",message:`"${g}" is not a question this runtime asks.`,hint:"GET /v1/provision lists every step with its prompt, default and choices. It is generated from the same walk the terminal wizard uses, so it cannot be stale.",field:g});let y=Jr.get(k);if(y!==void 0)throw new t({code:y.code,message:`"${g}" cannot be set over the API.`,hint:y.hint,field:g});let S=it.get(k)?.get(v.trim().toLowerCase());if(S!==void 0)throw new t({code:S.code,message:`${g} is ${JSON.stringify(v)}, which this runtime cannot do over the API.`,hint:S.hint,field:g});let P=Te(k,v);if(!P.ok)throw new t({code:"provision_answer_invalid",message:`${g} is ${JSON.stringify(v)}, which ${P.reason}`,hint:"GET /v1/provision lists every step with its prompt, its default and its choices, generated from the same walk the terminal wizard uses.",field:g});o[k]=P.value}rt(o,"this is the provisioning API",r.defaults);let a=st(o,r.defaults),u=Pt(a.name),i=ut("sandbox",a.name,r.defaults);if(i===void 0)throw new t({code:"provision_dir_unresolved",message:`No directory could be derived for ${JSON.stringify(a.name)}.`,hint:'This is a bug in the CLI: `dirFor("sandbox", …)` must always resolve a path. It returns undefined only when the name is missing, which `complete()` has already refused.',field:"name"});let f=vi(i),h=er({...a,dir:f});return ot(f,h),{agentId:u,dir:f,manifestPath:Zn(f,"agent.yaml"),files:h.map((g)=>g.relPath)}}function Ei(r){if(r.web!=="search")return;return cn(r.webBackend??"tavily")?.apiKeyEnv}async function ts(r){let o=await rs(r);if(o.kind==="aborted")return process.stdout.write(`nothing written
|
|
141
141
|
`),n;return o.kind==="failed"?o.code:n}async function at(r){return rs(r)}async function rs(r){let o=Ii(r),a=ie({json:!1,plain:r.plain===!0,oneShot:!1}),u=a.mode==="rich"&&r.yes!==!0,i={agentDirBase:B()};if(u){let F=await Ti(o,i);if(F===void 0)return{kind:"aborted"};Object.assign(o,F)}else rt(o,r.yes===!0?"--yes was passed":a.because,i);let f=st(o,i),h=Pi(process.cwd(),f.dir),g=ao(h);if(g!==void 0)process.stderr.write(`${g}
|
|
142
|
-
`);let v=
|
|
142
|
+
`);let v=xe(h,"agent.yaml"),k=er(f);ot(h,k);let y=f.apiKeyEnv,S=y!==void 0&&f.apiKey===void 0&&(process.env[y]===void 0||process.env[y]===""),P=S&&y!==void 0?{[y]:"(pending)"}:void 0,U=!1;try{let F=x(xe(h,"agent.yaml"),{knownProviders:Y,knownChannels:X,...S?{env:{...process.env,[y]:"(pending)"}}:{}}),I=H(F.manifest.model.main.id,F.manifest.model.main.capabilities),{workspace:de,warnings:oe}=We(F,I.promptStyle),ge=Ie(de,F.manifest.context.rules);if(ge!==void 0&&F.manifest.context.rules.onExceed==="fail")throw ge;U=oe.some((z)=>z.code==="soul_distilled")}catch(F){if(F instanceof t)return process.stderr.write(`init wrote ${k.length} files to ${h}, but the result does not load:
|
|
143
143
|
${F.format()}
|
|
144
144
|
`),{kind:"failed",code:s};throw F}if(process.stdout.write(`wrote ${k.length} files to ${h} — validated ok
|
|
145
145
|
`),f.skills==="find"){let F=(f.skillsPick??"").split(",").map((I)=>I.trim()).filter((I)=>I!=="");if(F.length>0)qr(F,v,{...P===void 0?{}:{envOverlay:P}});else if(!u)await Mr({answers:f,manifestPath:v,...P===void 0?{}:{envOverlay:P}})}let W=!1;if(f.daemon==="service"){process.stdout.write(`
|
|
146
146
|
`);try{W=await Ze({action:"install",manifestPath:v})===n}catch(F){process.stderr.write(`the background service was not installed: ${F instanceof t?F.message:String(F)}
|
|
147
|
-
`)}}return process.stdout.write(Ai(f,h,U,W)),{kind:"ok",manifestPath:
|
|
147
|
+
`)}}return process.stdout.write(Ai(f,h,U,W)),{kind:"ok",manifestPath:xe(h,"agent.yaml")}}function Ri(r){if(r===void 0)return[];if(ft.some((o)=>o.value===r))return[["skills",r]];return[["skills","find"],["skillsSearch",r]]}function Ii(r){let o={},a=[["user",r.user],["name",r.name],["purpose",r.purpose],["preset",r.preset],["model",r.model],["baseUrl",r.baseUrl],["apiKeyEnv",r.apiKeyEnv],["system",r.system],["web",r.web],["webBackend",r.webBackend],["composio",r.composio],["telegram",r.telegram],["telegramAllow",r.telegramAllow],["server",r.server],["schedules",r.schedules],...Ri(r.skills),["daemon",r.daemon],["dir",r.dir]];for(let[u,i]of a){if(i===void 0)continue;let f=Te(u,i);if(!f.ok)throw new t({code:"cli_init_flag_invalid",message:`${Sn[u]} is ${JSON.stringify(i)}, which ${f.reason}`,hint:"The flags take the same values the interactive questions do; run the command at a terminal without flags to be walked through them."});o[u]=f.value}return o}async function Ti(r,o){let[{render:a},{createElement:u},{WizardApp:i}]=await Promise.all([import("ink"),import("react"),import("./WizardApp-vzpbydy3.js")]),f;Wt();let h=a(u(i,{title:`${e.name} ${R}`,given:r,defaults:o,onDone:(g)=>{f=g}}),{exitOnCtrlC:!1,...Z()});return b(()=>h.unmount()),await h.waitUntilExit(),h.unmount(),f}function Ai(r,o,a,u=!1){let f=xi(o)===B()?Si(o):xe(o,"agent.yaml"),h=xe(o,"agent.yaml"),g=[];if(r.apiKeyEnv!==void 0&&r.apiKey===void 0)g.push(`Add your key: edit ${xe(o,".env")} and set ${r.apiKeyEnv}=`);let v=Ei(r);if(v!==void 0&&r.webKey===void 0)g.push(`Add your search key: edit ${xe(o,".env")} and set ${v}= — web_fetch works without it, web_search does not`);if(ht(r)&&r.composioKey===void 0)g.push(`Add your Composio key: edit ${xe(o,".env")} and set ${Nt}=`);if(r.telegram==="connected"&&r.telegramToken===void 0)g.push(`Add your bot token: message @BotFather with /newbot, then edit ${xe(o,".env")} and set ${un}=`);let k=r.telegram==="connected"||r.server==="local",y=r.telegram==="connected"&&r.server==="local"?"the Telegram bot and the HTTP API":r.telegram==="connected"?"the Telegram bot":"the HTTP API";if(k&&u)g.push(`${e.slug} run ${f} — talks to it right here. It starts no channel and binds `+`no port; ${y} belongs to the service, which is already up.`);else g.push(`${e.slug} run ${f}`);if(k){if(!u)g.push(`${e.slug} serve ${f} — starts ${y}; \`run\` starts neither`);if(r.daemon==="service"&&!u)g.push(`${e.slug} daemon install ${f} — the same thing, supervised: starts at `+"login and survives a reboot. Do this once the key and token above are in .env; the install checks them and refuses without them, on purpose.")}if(r.telegram==="connected"&&r.telegramAllow===void 0)g.push("Message the bot. Nobody is on its allowFrom yet, so it will refuse you — and print "+"the exact line to paste into agent.yaml.");if(ht(r))g.push('Ask it for an app — "connect my Gmail" — and it finds the tools, gives you the '+"sign-in link, and pins what you need. New tools go live on the next restart.");g.push(r.skills==="find"?`Add more skills: \`${e.slug} sources search <what it should do>\` ranks every skill in the catalogues, then \`${e.slug} skills install ${f} <source>/<skill>\`.`:r.skills==="starter"?`Fill in workspace-level skills/starter/SKILL.md, or take a real one — \`${e.slug} sources search <what it should do>\` searches 440+ from two catalogues.`:`Skills are off but the directory is there — \`${e.slug} sources search <what it should do>\` finds one, \`${e.slug} skills new ${f} <name>\` writes one.`),g.push("Make workspace/SOUL.md yours, then re-derive SOUL.compact.md to match — "+`\`${e.slug} workspace ${h}\` shows exactly what still reads as a template.`);let S=u?`
|
|
148
148
|
it is running in the background now — \`${e.slug} daemon status ${f}\` at any time,
|
|
149
149
|
and \`${e.slug} stop\` turns everything off.
|
|
150
150
|
`:"";return`${a?`
|
|
@@ -160,7 +160,7 @@ ${a}
|
|
|
160
160
|
]
|
|
161
161
|
`;let i=u.indexOf("[");if(i===-1)return;let h=u.slice(i+1).trimStart().startsWith("]")?"":",";return`${u.slice(0,i+1)}
|
|
162
162
|
${a}${h}
|
|
163
|
-
${u.slice(i+1)}`}async function ds(r={}){let o=ie({plain:!1,json:!1,oneShot:!1});if(o.mode!=="rich")throw new t({code:"cli_keys_needs_terminal",message:"The key probe needs a terminal — it has nothing to read on a pipe.",hint:`Not one here (${o.because}). Run it in the terminal whose keys you want to inspect; there is no scripted form, because the answer is a property of that terminal.`});let a=Z(r.noEnhancedKeys),u=a.kittyKeyboard!==void 0,i=Rn(process.env),f=In(i)?.name??i,[{render:h},{createElement:g},{KeyProbe:v}]=await Promise.all([import("ink"),import("react"),import("./KeyProbe-
|
|
163
|
+
${u.slice(i+1)}`}async function ds(r={}){let o=ie({plain:!1,json:!1,oneShot:!1});if(o.mode!=="rich")throw new t({code:"cli_keys_needs_terminal",message:"The key probe needs a terminal — it has nothing to read on a pipe.",hint:`Not one here (${o.because}). Run it in the terminal whose keys you want to inspect; there is no scripted form, because the answer is a property of that terminal.`});let a=Z(r.noEnhancedKeys),u=a.kittyKeyboard!==void 0,i=Rn(process.env),f=In(i)?.name??i,[{render:h},{createElement:g},{KeyProbe:v}]=await Promise.all([import("ink"),import("react"),import("./KeyProbe-9jjeze5r.js")]),k=()=>{},y=new Promise((U)=>{k=U}),S=En();b(()=>{S.close()}),pe(),process.stdout.write(ve);let P=h(g(v,{columns:q(process.stdout.columns,j),asked:u,terminal:f,takeRaw:S.takeRaw,correctKeys:S.correct,onDone:k}),{exitOnCtrlC:!1,...a});return b(()=>P.unmount()),await y,P.unmount(),S.close(),J(),await ue(),n}import{existsSync as Oi}from"node:fs";function dt(r=process.env){return Oi("/.dockerenv")||r.container!==void 0}function _i(r){let o=r.env??process.env;if(!r.needsServer)return"command-needs-no-server";if(r.disabled===!0)return"disabled-by-flag";if(o[`${e.envPrefix}SERVICE`]!==void 0)return"is-the-service";if(o[`${e.envPrefix}NO_BOOTSTRAP`]!==void 0)return"disabled-by-env";if(dt(o))return"in-container";if(o.CI!==void 0)return"in-ci";return}async function ls(r){let o=_i(r);if(o!==void 0)return{kind:"skipped",reason:o};if((await St(r.store)).length>0)return{kind:"already"};let u=r.platform??process.platform;if(!yr(u))return{kind:"manual",lines:[`${e.slug} daemon install`]};let i=r.install;if(i===void 0)return{kind:"failed",message:"no installer was supplied",hint:"This is a wiring mistake rather than a configuration one: `ensureServer` is called with an `install` callback by `index.ts`."};try{return await i()}catch(f){return{kind:"failed",message:f instanceof Error?f.message:String(f),hint:`The command ran anyway. \`${e.slug} daemon install\` reports the same failure with more detail — on macOS over SSH it is usually that a LaunchAgent needs a logged-in desktop session.`}}}function cs(r){switch(r.kind){case"started":return`started the background server · \`${e.slug} daemon uninstall\` to undo
|
|
164
164
|
`;case"manual":return`no server is running · ${r.lines.join(", then ")}
|
|
165
165
|
`;case"failed":return`could not start a background server: ${r.message}
|
|
166
166
|
hint: ${r.hint}
|
|
@@ -177,18 +177,18 @@ Read: ${[...v.indexed,...v.sessions].join(", ")}
|
|
|
177
177
|
`),n;if(process.stdout.write(l([{label:"corpus",value:`${i.corpus} passage${i.corpus===1?"":"s"}`},{label:"threshold",value:i.threshold.toFixed(2)},{label:"above it",value:String(f.length)}])),i.corpus===0)return process.stdout.write("\nNothing indexed. `memory_write` fills the carried file, and eviction moves older notes into the memory directory.\n"),n;if(h.length===0)return process.stdout.write(`
|
|
178
178
|
Nothing ${r.all===!0?"matched":`scored above ${i.threshold.toFixed(2)}`}. Try --all, or fewer words: a term present in more than half the corpus is dropped as uninformative.
|
|
179
179
|
`),n;let g=Math.max(6,...h.map((v)=>ys(v,i.carried).length));process.stdout.write(`
|
|
180
|
-
${
|
|
181
|
-
`);for(let v of h){let k=v.score>=i.threshold?" ":"·";process.stdout.write(`${
|
|
180
|
+
${$e("SCORE",6)} ${$e("LEXICAL",7)} ${$e("COVER",5)} ${$e("SOURCE",g)} ${$e("LEARNED",10)} PASSAGE
|
|
181
|
+
`);for(let v of h){let k=v.score>=i.threshold?" ":"·";process.stdout.write(`${$e(v.score.toFixed(3),6)} ${$e(v.lexical.toFixed(3),7)} ${$e(v.coverage.toFixed(2),5)} ${$e(ys(v,i.carried),g)} ${$e(v.passage.at.slice(0,10),10)} ${k}${Ki(v.passage.text)}
|
|
182
182
|
`)}if(r.all===!0&&f.length<h.length)process.stdout.write(`
|
|
183
183
|
${h.length-f.length} shown below the threshold; a turn would not inject those.
|
|
184
184
|
`);if(i.carried!==void 0&&h.some((v)=>v.passage.source===i.carried))process.stdout.write(`
|
|
185
185
|
${i.carried} is carried in every prompt already, so it is searchable here and deliberately absent from the retrieved block.
|
|
186
|
-
`);return n}finally{await o.stop("cli-exit")}}function Ki(r){let o=r.replace(/\s+/g," ").trim();return o.length<=gs?o:`${o.slice(0,gs-1)}…`}function
|
|
186
|
+
`);return n}finally{await o.stop("cli-exit")}}function Ki(r){let o=r.replace(/\s+/g," ").trim();return o.length<=gs?o:`${o.slice(0,gs-1)}…`}function $e(r,o){return r.length>=o?r:r+" ".repeat(o-r.length)}function ys(r,o){return r.passage.source===o?`${r.passage.source} *`:r.passage.source}var Ui=["context_length","context_window","max_context_length","max_model_len"],Di=[["prompt_cache_hit_tokens",(r)=>r.prompt_cache_hit_tokens],["prompt_tokens_details.cached_tokens",(r)=>{let o=r.prompt_tokens_details;return Tn(o)?o.cached_tokens:void 0}],["cache_read_input_tokens",(r)=>r.cache_read_input_tokens]];function Tn(r){return typeof r==="object"&&r!==null&&!Array.isArray(r)}function Tt(r){if(typeof r!=="number"||!Number.isFinite(r))return;if(!Number.isInteger(r)||r<=0)return;return r}function bs(r,o){let a=Tn(r)?r.data:void 0,u=Array.isArray(a)?a:Array.isArray(r)?r:void 0;if(u===void 0)return;let i=o.toLowerCase();for(let f of u){if(!Tn(f))continue;let h=typeof f.id==="string"?f.id.toLowerCase():void 0;if(h===void 0)continue;if(!(h===i||h.endsWith(`/${i}`)||i.endsWith(`/${h}`)))continue;for(let v of Ui){let k=Tt(f[v]);if(k!==void 0)return{technique:"metadata",tokens:k,bound:"ceiling",detail:`GET /models published ${v}: ${k}`}}return}return}function At(r){let o=[/(?:max_?tokens|context[\s_]?(?:length|window))[^[\]]{0,40}\[\s*\d[\d_,]*\s*,\s*(\d[\d_,]*)\s*\]/i,/maximum context length is (\d[\d_,]*)/i,/max_?tokens[^.\d]{0,40}?(\d[\d_,]*)/i,/context (?:length|window)(?: of)? (?:is )?(\d[\d_,]*)/i,/maximum (?:sequence|model) length (?:is )?(\d[\d_,]*)/i],a=[];for(let u of o){let i=u.exec(r);if(i?.[1]===void 0)continue;let f=Tt(Number(i[1].replaceAll(/[,_]/g,"")));if(f!==void 0)a.push(f)}if(a.length===0)return;return Math.max(...a)}function vs(r){if(!Tn(r))return;let o=Tt(r.prompt_tokens)??0;for(let[a,u]of Di){let i=u(r);if(typeof i==="number"&&Number.isFinite(i))return{cached:i,promptTokens:o,field:a}}return{cached:void 0,promptTokens:o,field:void 0}}function $s(r,o,a){if(r===void 0||o===void 0)return{supported:void 0,detail:"no usage came back, so the question was not answered"};if(o.field===void 0)return{supported:void 0,detail:"the endpoint reported usage with no cache field in it — unknown, not absent"};let u=o.cached??0;if(u>0)return{supported:!0,detail:`the second identical call reported ${u} cached of ${o.promptTokens} prompt tokens, via ${o.field}`};return{supported:!1,detail:`${o.field} came back 0 on an identical repeat of a ${a}-token prefix — evidence of no caching, not proof: a longer prefix may still hit`}}function en(r){let o=r.filter((u)=>u.bound==="ceiling");return(o.length>0?o:r).reduce((u,i)=>u===void 0||i.tokens>u.tokens?i:u,void 0)}function ks(r,o,a){return[" {",` pattern: "${`${r.split(":")[0]}*`}",`," capabilities: {",` contextWindow: ${o.toLocaleString("en-US").replaceAll(",","_")},`,...a===void 0?[]:[` maxOutput: ${a.toLocaleString("en-US").replaceAll(",","_")},`]," // the other fields are unchanged — this row reports only what was measured"," },"," },"].join(`
|
|
187
187
|
`)}function Ss(r,o,a){return`measured ${o} against ${r} — ${a}`}function xs(r,o){let a=Math.max(1,r),u=0,i=0;while(a<o)u+=a,i+=1,a*=2;return u+=o,i+=1,{requests:i,tokens:u}}var Hi=2000000000,Ps=1024,Rs=8192,Is=2097152;function Ts(r){return"context ".repeat(Math.max(1,r))}async function nn(r){let o=await r.text();try{return{text:o,json:JSON.parse(o)}}catch{return{text:o,json:void 0}}}function As(r,o){if(typeof r==="object"&&r!==null){let a=r,u=a.error;if(typeof u==="string")return u;if(typeof u==="object"&&u!==null){let i=u.message;if(typeof i==="string")return i}if(typeof a.message==="string")return a.message}return o}async function Bi(r,o,a){try{let u=await o(r.models,{headers:r.headers});if(!u.ok){a.push(`GET /models answered ${u.status}`);return}let{json:i}=await nn(u),f=bs(i,r.modelId);if(f===void 0)a.push("GET /models published no context length");return f}catch(u){a.push(`GET /models failed: ${u instanceof Error?u.message:String(u)}`);return}}async function Wi(r,o,a){try{let u=await o(r.chat,{method:"POST",headers:{"content-type":"application/json",...r.headers},body:JSON.stringify({model:r.modelId,messages:[{role:"user",content:"hi"}],max_tokens:Hi})}),{text:i,json:f}=await nn(u);if(u.ok)return a.push("the endpoint accepted an impossible max_tokens rather than refusing it — it clamps silently, so this technique cannot measure it"),{window:void 0,outputCeiling:void 0};let h=As(f,i.slice(0,400)),g=At(h);if(g===void 0)return a.push(`the refusal named no number: ${h.slice(0,160)}`),{window:void 0,outputCeiling:void 0};let v=/max_?tokens/i.test(h);return{window:v?void 0:{technique:"refusal",tokens:g,bound:"ceiling",detail:`refused an over-range request naming ${g}`},outputCeiling:v?g:void 0}}catch(u){return a.push(`the over-range request failed: ${u instanceof Error?u.message:String(u)}`),{window:void 0,outputCeiling:void 0}}}async function Es(r,o,a){let u=await o(r.chat,{method:"POST",headers:{"content-type":"application/json",...r.headers},body:JSON.stringify({model:r.modelId,messages:[{role:"user",content:a}],max_tokens:1})});if(!u.ok)return;let{json:i}=await nn(u),f=typeof i==="object"&&i!==null?i.usage:void 0;return vs(f)}async function Gi(r,o,a){let u=`${Ts(Ps)}
|
|
188
188
|
Reply with the single character x.`;try{let i=await Es(r,o,u),f=await Es(r,o,u);return $s(i,f,Ps)}catch(i){return a.push(`the caching probe failed: ${i instanceof Error?i.message:String(i)}`),{supported:void 0,detail:"the probe did not complete"}}}async function qi(r,o,a){let u=Rs,i=0;while(u<=Is){let f;try{f=await o(r.chat,{method:"POST",headers:{"content-type":"application/json",...r.headers},body:JSON.stringify({model:r.modelId,messages:[{role:"user",content:Ts(u)}],max_tokens:1})})}catch(k){a.push(`the search stopped at ${u}: ${k instanceof Error?k.message:String(k)}`);break}if(f.ok){let{json:k}=await nn(f),y=typeof k==="object"&&k!==null?k.usage:void 0,S=typeof y==="object"&&y!==null?y.prompt_tokens:void 0;i=typeof S==="number"&&Number.isFinite(S)?S:i,u*=2;continue}let{text:h,json:g}=await nn(f),v=At(As(g,h.slice(0,400)));if(v!==void 0)return{technique:"search",tokens:v,bound:"ceiling",detail:`refused a ${u}-token prompt and named ${v}`};break}if(i===0)return;return{technique:"search",tokens:i,bound:"floor",detail:`accepted a prompt the endpoint counted at ${i} tokens; nothing above it named a number`}}function Vi(r,o){let a=en(r.findings),u=a===void 0?"nothing measured — every technique came back empty":`${a.tokens} (${a.bound}) · ${a.detail}`,i=a===void 0?"":a.tokens===r.declared?"matches what is configured":a.bound==="ceiling"&&a.tokens>r.declared?`configured value is ${r.declared}, which is ${(a.tokens-r.declared).toLocaleString("en-US")} tokens short`:`configured value is ${r.declared}`,f=r.cache.supported===void 0?`unknown — ${r.cache.detail}`:r.cache.supported?`yes — ${r.cache.detail}`:`no — ${r.cache.detail}`;return[p(` ${r.role} · ${r.modelId}`),l([{label:"endpoint",value:r.baseUrl},{label:"configured",value:`${r.declared} (${r.declaredSource})`},{label:"measured",value:u},{label:"agreement",value:i},{label:"output cap",value:r.outputCeiling===void 0?"":String(r.outputCeiling)},{label:"prompt cache",value:f},...o===void 0?[]:[{label:"price",value:`$${o}/Mtok input, as given`}]]),...r.failures.length===0?[]:[" what did not answer:",...r.failures.map((h)=>` · ${h}`)],...a===void 0||a.bound!=="ceiling"?[]:[""," registry row, if this model should ship with it:",ks(r.modelId,a.tokens,r.outputCeiling).split(`
|
|
189
189
|
`).map((h)=>` ${h}`).join(`
|
|
190
190
|
`)]].join(`
|
|
191
|
-
`)}async function Os(r){let o=r.fetch??globalThis.fetch;try{let a=x(r.manifestPath,{knownProviders:Y,knownChannels:X,env:m([r.manifestPath])}),{manifest:u}=a,i=
|
|
191
|
+
`)}async function Os(r){let o=r.fetch??globalThis.fetch;try{let a=x(r.manifestPath,{knownProviders:Y,knownChannels:X,env:m([r.manifestPath])}),{manifest:u}=a,i=ye(u).filter((v)=>v.role===v.configuredAs),f=!1;if(r.window){let v=xs(Rs,Is),k=v.tokens*i.length,y=r.price===void 0?"":` ≈ $${(k/1e6*r.price).toFixed(2)}`;process.stdout.write(`--window will send up to ${v.requests} requests per role, about ${k.toLocaleString("en-US")} input tokens in total${y}.
|
|
192
192
|
That is an upper bound: the search stops at the first refusal, and the refused request generates nothing.
|
|
193
193
|
Tokens rather than dollars unless --price says otherwise: a price table in this repo would be wrong within a quarter.
|
|
194
194
|
`),f=r.yes||await Ye("spend it?"),process.stdout.write(f?`
|
|
@@ -211,9 +211,9 @@ Add a \`plugins:\` block to agent.yaml naming the ones you want.
|
|
|
211
211
|
Declared access — advisory in v1, recorded and not enforced:
|
|
212
212
|
`);for(let f of i)for(let h of f.permissions){let g=h.kind==="network"?h.hosts.join(", "):h.kind==="env"?h.vars.join(", "):h.kind==="fs"?`${h.paths.join(", ")} (${h.mode})`:h.kind==="exec"?h.commands.join(", "):h.tables.join(", ");process.stdout.write(` ${f.name} ${h.kind} ${g}
|
|
213
213
|
`)}}return n}import{existsSync as sa,readdirSync as Ms,rmSync as _t,statSync as Ks}from"node:fs";import{homedir as oa}from"node:os";import{join as Us}from"node:path";function Cs(r){if(r.filesOnly||r.sharesIdWith.length===0)return[];let o=r.sharesIdWith.join(", ");return[{code:"cli_agent_id_shared",message:`"${r.ref}" has the manifest id "${r.agentId}", which is also used by ${o} — removing its data would take that agent's sessions and memory too.`,hint:`Change one manifest's id and run \`memory rebuild\` for it, or pass --files-only to delete just the ${r.ref} directory and leave the store alone.`}]}function Ns(r){let o=[];if(r.running!==void 0)o.push({kind:"stop",detail:`stop pid ${r.running.pid} (${r.running.mode}) — gracefully, so anything it left running in the background is reaped`});if(!r.filesOnly&&r.service!==void 0)o.push({kind:"service",detail:`disable and unload ${r.service}`});if(!r.filesOnly){let a=r.footprint;if(o.push({kind:"store",detail:`delete ${ae(a.sessions,"conversation")}, ${ae(a.messages,"message")}, ${ae(a.passages,"memory passage")}`}),r.logs.length>0)o.push({kind:"logs",detail:`delete ${ae(r.logs.length,"log file")}`})}return o.push({kind:"directory",detail:`delete ${r.dir}`}),o}function Fs(r){let o=r.footprint,a=[{label:"directory",value:`${r.dir}`,note:`${ae(r.files.count,"file")}, ${bt(r.files.bytes)}`}];if(r.agentId!==r.ref)a.push({label:"manifest id",value:r.agentId,note:"keys the store, logs and service"});if(r.filesOnly)a.push({label:"keeping",value:`${ae(o.sessions,"conversation")}, ${ae(o.passages,"memory passage")}, and the logs`,note:"--files-only"});else a.push({label:"sessions",value:`${ae(o.sessions,"conversation")}, ${ae(o.messages,"message")}, ${ae(o.turns,"turn")}`},{label:"memory",value:`${ae(o.passages,"passage")} from ${ae(o.memorySources,"source")}`},{label:"outbox",value:o.outbox===0?"nothing queued":`${ae(o.outbox,"delivery")}${o.outboxPending===0?"":`, ${o.outboxPending} not yet sent`}`,...o.outboxPending===0?{}:{note:"abandoned"}},{label:"schedules",value:o.schedules===0?"none":ae(o.schedules,"schedule"),...o.schedules===0?{}:{note:"stops firing"}},{label:"logs",value:r.logs.length===0?"none":`${ae(r.logs.length,"file")}, ${bt(r.logs.reduce((u,i)=>u+i.bytes,0))}`},{label:"service",value:r.service??"not installed"});return a.push({label:"running",value:r.running===void 0?"no":`pid ${r.running.pid} (${r.running.mode})`}),l(a)}function Ls(r){if(r.length===0)return"";return r.map((o)=>{let a=o.footprint,u=[];if(a.sessions>0)u.push(`${ae(a.sessions,"conversation")}, ${ae(a.messages,"message")}`);if(a.passages>0)u.push(`${ae(a.passages,"memory passage")}`);if(a.outbox>0)u.push(`${ae(a.outbox,"queued delivery")}`);if(a.schedules>0)u.push(`${ae(a.schedules,"schedule")}`);if(a.lease)u.push("a stale lease");if(o.logs.length>0)u.push(`${ae(o.logs.length,"log file")}, ${bt(o.logs.reduce((i,f)=>i+f.bytes,0))}`);return` ${o.agentId} ${u.length===0?"rows with no detail":u.join(" · ")}`}).join(`
|
|
214
|
-
`)}function ae(r,o){return`${r} ${o}${r===1?"":"s"}`}import{homedir as zi}from"node:os";var js=12000,Yi=250;async function Nn(r){if(r.manifestPath!==void 0)return await Qi(r,r.manifestPath);return await Zi(r)}async function Qi(r,o){let a=ra(o),u=[];if(r.dryRun===!0){let g=await
|
|
214
|
+
`)}function ae(r,o){return`${r} ${o}${r===1?"":"s"}`}import{homedir as zi}from"node:os";var js=12000,Yi=250;async function Nn(r){if(r.manifestPath!==void 0)return await Qi(r,r.manifestPath);return await Zi(r)}async function Qi(r,o){let a=ra(o),u=[];if(r.dryRun===!0){let g=await Ce(a,r.store);return process.stdout.write(`would stop 1 agent:
|
|
215
215
|
${d(`${a} — ${g===void 0?"not running; would be switched off for the next start":g.baseUrl===void 0?`pid ${g.pid} (${g.mode}), which serves no HTTP — would be signalled`:`pid ${g.pid} (${g.mode}) at ${g.baseUrl}, which would drop it and keep serving`}`)}
|
|
216
|
-
`),n}await Pn(a,!1,r.reason,r.store),u.push("switched off for the next start");let i=await
|
|
216
|
+
`),n}await Pn(a,!1,r.reason,r.store),u.push("switched off for the next start");let i=await Ce(a,r.store),f=!0;if(i===void 0)u.push("nothing was running");else if(i.baseUrl===void 0){let g=await On(i.pid,"SIGTERM");f=g||await On(i.pid,"SIGKILL",!0),u.push(g?`pid ${i.pid} stopped cleanly`:f?`pid ${i.pid} had to be killed`:`pid ${i.pid} would not stop — check it by hand`)}else{let g=await Qe(i,`/v1/agents/${encodeURIComponent(a)}/stop`,r.reason===void 0?{}:{reason:r.reason},o);if(g.ok)u.push(`pid ${i.pid} dropped it and kept serving`);else if(g.status===409)f=!1,u.push(g.detail??"a turn is running");else if(g.status===401)f=!1,u.push(`pid ${i.pid} refused the request — set ${e.envPrefix}API_TOKEN to the server's token`);else f=!1,u.push(`pid ${i.pid} at ${i.baseUrl} could not be reached${g.detail===void 0?"":`: ${g.detail}`}`)}let h={agentId:a,service:!1,...i===void 0?{}:{pid:i.pid,mode:i.mode},stopped:f,note:u.join(" · ")};if(r.json===!0)process.stdout.write(`${JSON.stringify({stopped:[h]},null,2)}
|
|
217
217
|
`);else process.stdout.write(`${l([{label:a,value:f?"stopped":"NOT FULLY STOPPED",note:h.note}])}
|
|
218
218
|
`),process.stdout.write(`
|
|
219
219
|
Stays off across restarts. \`${e.slug} start ${a}\` switches it back on.
|
|
@@ -270,24 +270,24 @@ Nothing was deleted.
|
|
|
270
270
|
`:`
|
|
271
271
|
pruned ${i.length} agent id(s).
|
|
272
272
|
${l(f)}
|
|
273
|
-
`),n}async function Bs(r,o,a){if(r.includes("/")||r.endsWith(".yaml")||r.endsWith(".yml"))throw new t({code:"cli_remove_takes_a_name",message:`remove takes a sandbox agent's name, and "${r}" is a path.`,hint:`An agent outside ${B()} is a directory you created and yours to delete — \`rm -rf\` it. This command only removes agents \`${e.slug} init\` made, because it also has to clear their sessions, memory, logs and service.`});let u=K(),i=u.find((P)=>P.ref===r);if(i===void 0){let P=u.map((U)=>U.ref);throw new t({code:"cli_agent_unknown",message:`No agent named "${r}" in the sandbox${P.length===0?", which is empty":""}.`,hint:P.length===0?`Nothing to remove. \`${e.slug} init\` creates one.`:`Known agents: ${P.join(", ")}. \`--prune\` clears data left by an agent whose directory is already gone.`})}let f=i.id;if(f===void 0)try{f=T(i.manifestPath).id}catch{}let h=o.filesOnly===!0||f===void 0,g=f??r,v=await a.agentFootprint(g),k=v.lease?await a.leases.get(g):void 0,y=Ws(o),S=pn(e.slug,g);return{ref:r,agentId:g,manifestPath:i.manifestPath,dir:i.dir,files:la(i.dir),footprint:v,logs:Gs(g),sharesIdWith:u.filter((P)=>P.ref!==r&&(P.id??"")===g).map((P)=>P.ref),...k!==void 0&&_(k.pid)?{running:{pid:k.pid,mode:k.mode}}:{},...y?.state(S).installed===!0?{service:S}:{},filesOnly:h}}function Ws(r){let o=r.platform??process.platform;if(o!=="darwin")return;return Ue(o,{home:oa(),uid:process.getuid?.()??0,envPrefix:e.envPrefix,...r.exec===void 0?{}:{exec:r.exec}})}function la(r){let o=0,a=0,u=(i)=>{let f;try{f=Ms(i)}catch{return}for(let h of f){let g=Us(i,h);try{let v=Ks(g);if(v.isDirectory()){u(g);continue}o+=1,a+=v.size}catch{}}};return u(r),{count:o,bytes:a}}function Gs(r){let o=Jt(r),a=[];for(let u of[o.out,o.err])try{if(!sa(u))continue;a.push({path:u,bytes:Ks(u).size})}catch{}return a}function ca(){let r;try{r=Ms(Us(ee(),"logs"))}catch{return[]}let o=new Set;for(let a of r)for(let u of[".out.log",".err.log"])if(a.endsWith(u))o.add(a.slice(0,-u.length));return[...o]}async function Ft(r,o,a){if(r.yes===!0)return!0;let u=r.confirm;if(u===void 0)return!1;return await u(a,o)}import{randomBytes as jt}from"node:crypto";import{existsSync as wa}from"node:fs";import{createInterface as Zs}from"node:readline";class
|
|
274
|
-
hint: ${r.hint}`);if(this.name="DispachError",this.code=r.code,this.hint=r.hint??"",this.field=r.field,this.status=o.status,this.request=o.method===void 0||o.path===void 0?void 0:{method:o.method,path:o.path},o.cause!==void 0)this.cause=o.cause}}function ua(r,o){let a=r instanceof Error?r.message:String(r);return new
|
|
273
|
+
`),n}async function Bs(r,o,a){if(r.includes("/")||r.endsWith(".yaml")||r.endsWith(".yml"))throw new t({code:"cli_remove_takes_a_name",message:`remove takes a sandbox agent's name, and "${r}" is a path.`,hint:`An agent outside ${B()} is a directory you created and yours to delete — \`rm -rf\` it. This command only removes agents \`${e.slug} init\` made, because it also has to clear their sessions, memory, logs and service.`});let u=K(),i=u.find((P)=>P.ref===r);if(i===void 0){let P=u.map((U)=>U.ref);throw new t({code:"cli_agent_unknown",message:`No agent named "${r}" in the sandbox${P.length===0?", which is empty":""}.`,hint:P.length===0?`Nothing to remove. \`${e.slug} init\` creates one.`:`Known agents: ${P.join(", ")}. \`--prune\` clears data left by an agent whose directory is already gone.`})}let f=i.id;if(f===void 0)try{f=T(i.manifestPath).id}catch{}let h=o.filesOnly===!0||f===void 0,g=f??r,v=await a.agentFootprint(g),k=v.lease?await a.leases.get(g):void 0,y=Ws(o),S=pn(e.slug,g);return{ref:r,agentId:g,manifestPath:i.manifestPath,dir:i.dir,files:la(i.dir),footprint:v,logs:Gs(g),sharesIdWith:u.filter((P)=>P.ref!==r&&(P.id??"")===g).map((P)=>P.ref),...k!==void 0&&_(k.pid)?{running:{pid:k.pid,mode:k.mode}}:{},...y?.state(S).installed===!0?{service:S}:{},filesOnly:h}}function Ws(r){let o=r.platform??process.platform;if(o!=="darwin")return;return Ue(o,{home:oa(),uid:process.getuid?.()??0,envPrefix:e.envPrefix,...r.exec===void 0?{}:{exec:r.exec}})}function la(r){let o=0,a=0,u=(i)=>{let f;try{f=Ms(i)}catch{return}for(let h of f){let g=Us(i,h);try{let v=Ks(g);if(v.isDirectory()){u(g);continue}o+=1,a+=v.size}catch{}}};return u(r),{count:o,bytes:a}}function Gs(r){let o=Jt(r),a=[];for(let u of[o.out,o.err])try{if(!sa(u))continue;a.push({path:u,bytes:Ks(u).size})}catch{}return a}function ca(){let r;try{r=Ms(Us(ee(),"logs"))}catch{return[]}let o=new Set;for(let a of r)for(let u of[".out.log",".err.log"])if(a.endsWith(u))o.add(a.slice(0,-u.length));return[...o]}async function Ft(r,o,a){if(r.yes===!0)return!0;let u=r.confirm;if(u===void 0)return!1;return await u(a,o)}import{randomBytes as jt}from"node:crypto";import{existsSync as wa}from"node:fs";import{createInterface as Zs}from"node:readline";class Oe extends Error{code;hint;field;status;request;constructor(r,o={}){super(r.hint===void 0?r.message:`${r.message}
|
|
274
|
+
hint: ${r.hint}`);if(this.name="DispachError",this.code=r.code,this.hint=r.hint??"",this.field=r.field,this.status=o.status,this.request=o.method===void 0||o.path===void 0?void 0:{method:o.method,path:o.path},o.cause!==void 0)this.cause=o.cause}}function ua(r,o){let a=r instanceof Error?r.message:String(r);return new Oe({code:"transport_failed",message:`${o.method} ${o.path} did not reach ${o.baseUrl}: ${a}`,hint:"Check the base URL, that the server is running, and that nothing between you and it is refusing the connection. `GET /v1/health` needs no token and is the cheapest probe."},{...o,cause:r})}async function fa(r,o){let a;try{let u=await r.json();if(typeof u.error?.code==="string"&&typeof u.error.message==="string")a={code:u.error.code,message:u.error.message,...u.error.hint===void 0?{}:{hint:u.error.hint},...u.error.field===void 0?{}:{field:u.error.field}}}catch{}return new Oe(a??{code:`http_${r.status}`,message:`${o.method} ${o.path} returned ${r.status} with no error body.`,hint:"This is not a response this server produces, so something between you and it answered — a proxy, a gateway, or a load balancer. Check the URL and what is in front of it."},{status:r.status,...o})}var qs=new Set(Me);async function*Vs(r){for await(let o of Fn(ma(r))){if(o.event===void 0||o.data==="")continue;let a;try{a=JSON.parse(o.data)}catch{continue}yield{name:o.event,data:a}}}async function*ma(r){let o=r.getReader();try{while(!0){let{done:a,value:u}=await o.read();if(a)return;if(u!==void 0)yield u}}finally{o.releaseLock()}}async function*pa(r){for await(let{name:o,data:a}of Vs(r)){if(qs.has(o)){yield{kind:"event",event:a};continue}let u=a??{};switch(o){case"turn.accepted":yield{kind:"accepted",turnId:String(u.turnId??""),sessionKey:String(u.sessionKey??"")};break;case"stream.replay":yield{kind:"replay",report:{state:u.state==="ended"?"ended":"running",events:Number(u.events??0),truncated:u.truncated===!0,dropped:Number(u.dropped??0),chunks:u.chunks==="start"||u.chunks==="partial"?u.chunks:"none"}};break;case"stream.ended":yield{kind:"ended",turnId:String(u.turnId??""),status:String(u.status??"unknown"),steps:typeof u.steps==="number"?u.steps:void 0,errorCode:typeof u.errorCode==="string"?u.errorCode:void 0};break;case"stream.unavailable":yield{kind:"unavailable",turnId:String(u.turnId??""),reason:String(u.reason??"not observable from this process")};break;default:break}}}async function*ha(r){for await(let{name:o,data:a}of Vs(r)){if(qs.has(o)){yield{kind:"event",event:a};continue}if(o==="stream.subscribed"){let u=a??{};yield{kind:"subscribed",report:{agentId:typeof u.agentId==="string"?u.agentId:null,types:Array.isArray(u.types)?u.types:null,chunks:u.chunks===!0,implied:typeof u.implied==="string"?u.implied:void 0}}}}}async function*ga(r,o={}){for await(let a of r){if(a.kind==="replay"&&a.report.truncated&&o.allowTruncated!==!0)throw new Oe({code:"replay_truncated",message:`This turn's replay is missing its oldest ${a.report.dropped} event(s), so the text reconstructed from it would be incomplete.`,hint:"Read the finished text from GET /v1/agents/:id/turns/:turnId, or pass { allowTruncated: true } to accept a fragment. Streaming from the start of a turn is never truncated — this only happens when reattaching to one that has already produced more events than the buffer holds."});if(a.kind==="unavailable")throw new Oe({code:"turn_not_observable",message:`Turn ${a.turnId} is recorded as running but is not observable here: ${a.reason}.`,hint:"Its events are buffered in whichever process is executing it. Poll GET /v1/agents/:id/turns/:turnId for the outcome."});if(a.kind!=="event")continue;if(a.event.type!=="model.chunk")continue;let u=a.event.data;if(u.kind==="reasoning")continue;if(typeof u.delta==="string")yield u.delta}}function Xs(r){let o=r.baseUrl.replace(/\/+$/,""),a=r.fetch??fetch,u=(k={})=>({...r.token===void 0?{}:{authorization:`Bearer ${r.token}`},...k});async function i(k,y,S={}){let P;try{P=await a(`${o}${y}`,{method:k,headers:u({...S.body===void 0?{}:{"content-type":"application/json"},...S.accept===void 0?{}:{accept:S.accept},...S.headers}),...S.body===void 0?{}:{body:JSON.stringify(S.body)},...S.signal===void 0?{}:{signal:S.signal}})}catch(U){throw ua(U,{method:k,path:y,baseUrl:o})}if(!P.ok)throw await fa(P,{method:k,path:y});return P}async function f(k,y,S){return await(await i(k,y,S??{})).json()}async function h(k,y){let S=await i("GET",k,{accept:"text/event-stream",...y===void 0?{}:{signal:y}});if(S.body===null)throw new Oe({code:"no_response_body",message:`GET ${k} returned ${S.status} with no body to read.`,hint:"An SSE route always has a body. A missing one means something between you and the server buffered the response — commonly a proxy without streaming enabled."},{status:S.status,method:"GET",path:k});return S.body}function g(k,y,S,P={}){let U=(F)=>F?.chunks===!0?"?chunks=true":"",W={turnId:y,sessionKey:S,replayed:P.replayed===!0,async*stream(F){let I=await h(`/v1/agents/${encodeURIComponent(k)}/turns/${encodeURIComponent(y)}/stream${U(F)}`,F?.signal);yield*pa(I)},async*tokens(F){yield*ga(W.stream({chunks:!0,...F}),{...F?.allowTruncated===void 0?{}:{allowTruncated:F.allowTruncated}})},async text(){for await(let F of W.stream()){if(F.kind==="ended")break;if(F.kind==="unavailable")break;if(F.kind==="event"&&F.event.type==="turn.end")break}return(await W.get()).text},get:()=>f("GET",`/v1/agents/${encodeURIComponent(k)}/turns/${encodeURIComponent(y)}`),async stop(){await i("POST",`/v1/agents/${encodeURIComponent(k)}/turns/${encodeURIComponent(y)}/stop`)}};return W}function v(k){let y=(S)=>`/v1/agents/${encodeURIComponent(k)}${S}`;return{id:k,async send(S,P){let U=await f("POST",y("/messages"),{body:{text:S,...P?.sessionKey===void 0?{}:{sessionKey:P.sessionKey},...P?.deliver===void 0?{}:{deliver:P.deliver},...P?.from===void 0?{}:{from:P.from}},...P?.idempotencyKey===void 0?{}:{headers:{"idempotency-key":P.idempotencyKey}},...P?.signal===void 0?{}:{signal:P.signal}});return g(k,U.turnId,U.sessionKey,{replayed:U.replayed===!0})},turn:(S)=>g(k,S,""),describe:()=>f("GET",y("")),tools:()=>f("GET",y("/tools")),skills:()=>f("GET",y("/skills")),sessions:()=>f("GET",y("/sessions")),messages:(S,P)=>{let U=new URLSearchParams;if(P?.before!==void 0)U.set("before",String(P.before));if(P?.limit!==void 0)U.set("limit",String(P.limit));let W=U.size===0?"":`?${U.toString()}`;return f("GET",y(`/sessions/${encodeURIComponent(S)}/messages${W}`))},clearSession:(S)=>f("DELETE",y(`/sessions/${encodeURIComponent(S)}`)),reload:()=>f("POST",y("/reload"),{body:{}}),schedules:async()=>(await f("GET",y("/schedules"))).schedules,approvals:async()=>(await f("GET",y("/approvals"))).approvals,createSchedule:(S)=>f("POST",y("/schedules"),{body:S}),updateSchedule:(S,P)=>f("PATCH",y(`/schedules/${encodeURIComponent(S)}`),{body:P}),deleteSchedule:async(S)=>{await f("DELETE",y(`/schedules/${encodeURIComponent(S)}`))},runSchedule:(S)=>f("POST",y(`/schedules/${encodeURIComponent(S)}/run`),{body:{}}),config:()=>f("GET",y("/config")),setConfig:(S,P,U)=>f("PATCH",y("/config"),{body:{path:S,value:P,...U?.confirm===void 0?{}:{confirm:U.confirm}}}),session:(S)=>f("GET",y(`/sessions/${encodeURIComponent(S)}`)),setPhase:(S,P)=>f("POST",y(`/sessions/${encodeURIComponent(S)}/phase`),{body:{phase:P}}),approve:async(S,P)=>{await f("POST",y(`/approvals/${encodeURIComponent(S)}`),{body:{granted:P}})},stop:(S)=>f("POST",y("/stop"),{body:S===void 0?{}:{reason:S}}),start:()=>f("POST",y("/start"),{body:{}}),context:(S)=>{let P=new URLSearchParams;if(S?.sessionKey!==void 0)P.set("sessionKey",S.sessionKey);if(S?.input!==void 0)P.set("input",S.input);let U=P.size===0?"":`?${P.toString()}`;return f("GET",y(`/context${U}`))}}}return{agent:v,agents:()=>f("GET","/v1/agents"),health:()=>f("GET","/v1/health"),async ready(){try{return await i("GET","/v1/ready"),!0}catch(k){if(k instanceof Oe&&k.status===503)return!1;throw k}},provision:()=>f("GET","/v1/provision"),keys:()=>f("GET","/v1/keys"),createKey:(k)=>f("POST","/v1/keys",{body:k}),revokeKey:(k)=>f("DELETE",`/v1/keys/${encodeURIComponent(k)}`),createAgent:(k)=>f("POST","/v1/agents",{body:{answers:k}}),async*events(k){let y=new URLSearchParams;if(k?.agentId!==void 0)y.set("agentId",k.agentId);if(k?.types!==void 0&&k.types.length>0)y.set("types",k.types.join(","));if(k?.chunks===!0)y.set("chunks","true");let S=y.size===0?"":`?${y.toString()}`,P=await h(`/v1/events${S}`,k?.signal);yield*ha(P)}}}function tn(r,o){let a=[];for(let u of r){if(u.origin!==void 0&&u.origin!=="call")continue;if(u.role!=="user"&&u.role!=="assistant")continue;let i=Rr(u,o);if(i==="")continue;a.push({role:u.role,text:i})}return a}function Js(r){let o=r.ref??"<your agent>",a=`${e.slug} run ${o} --session ${r.sessionKey}`;return`
|
|
275
275
|
${Jo}Resume this session with:
|
|
276
276
|
${a}${_n}
|
|
277
277
|
`}function Lt(r,o){switch(r){case"first":return;case"restart":return"restarted — the configuration on disk is now the one in force; the conversation continues from the store.";case"switch":return"switched conversation — the one you left is still in the store, under its own key.";case"new":return o===void 0?"new conversation — the one you left is still in the store, under its own key.":`new conversation — the one you left is ${o}, still in the store. /sessions goes back to it.`}}function ya(r){return r==="nlt"?jn():Un()}function zs(r){return{kind:"embedded",agentId:r.agent.id,describe:()=>r.description,subscribe:(o)=>r.bus.on("*",o,{chunks:!0}),send:(o,a)=>r.send(o,{...a,source:"repl"}),streamFilter:r.streamFilter,history:r.history,sessions:r.sessions,clearSession:r.clearSession,tools:async()=>Xn(r.agent),context:r.context,close:async()=>{}}}function Ys(r){let o=r.client.agent(r.agentId),a=new Set,u=new AbortController,i,f=()=>{if(i!==void 0)return;i=(async()=>{for await(let h of r.client.events({agentId:r.agentId,chunks:!0,signal:u.signal})){if(h.kind!=="event"||h.event===void 0)continue;for(let g of a)g(h.event)}})().catch(()=>{})};return{kind:"attached",agentId:r.agentId,host:r.host,describe:()=>r.description,subscribe:(h)=>(a.add(h),f(),()=>a.delete(h)),send:async(h,g)=>{let v=!1,k,y=()=>{if(v=!0,k!==void 0)o.turn(k).stop().catch(()=>{})};g.signal.addEventListener("abort",y,{once:!0});let S,P=new Promise((U)=>{let W=(F)=>{if(k!==void 0&&F.turnId!==void 0&&F.turnId!==k)return;if(F.type==="error"){S=F.data;return}if(F.type!=="turn.end")return;a.delete(W),U({text:"",reason:F.data.reason,steps:F.data.steps,durationMs:F.data.durationMs,tokens:F.data.tokens,...S===void 0?{}:{error:S}})};a.add(W),f()});try{if(k=(await o.send(h,{sessionKey:g.sessionKey})).turnId,v)o.turn(k).stop().catch(()=>{});return await P}finally{g.signal.removeEventListener("abort",y)}},streamFilter:()=>ya(r.description.dialect),history:async(h)=>{let g=await o.messages(h);return tn([...g.messages].reverse().map((v)=>({role:v.role,content:v.content,...v.origin===void 0?{}:{origin:v.origin}})),r.description.dialect)},sessions:()=>o.sessions(),clearSession:async(h)=>{await o.clearSession(h)},tools:async()=>{let h=await o.tools();return{dialect:r.description.dialect,catalogueTokens:r.description.catalogueTokens,tools:h.map((g)=>({slug:g.slug,mutating:g.mutating,trust:g.trust,...g.trustReason===void 0?{}:{trustReason:g.trustReason},summary:g.summary}))}},context:async(h)=>{let g=await o.context({sessionKey:h});return{...g,windowSource:"as the host resolved it",...g.lastCompaction===void 0&&g.compactions!==void 0?{lastCompaction:g.compactions===0?void 0:`${g.compactions} stage${g.compactions===1?"":"s"} run this session`}:{}}},reload:async()=>(await o.reload()).adopted,close:async()=>{u.abort(),a.clear()}}}function Qs(r){if(r?.baseUrl===void 0||r.baseUrl==="")return;return{baseUrl:r.baseUrl,pid:r.pid}}async function ba(r,o,a,u,i,f=[],h){let g=r.describe(),[v,k]=await Promise.all([r.turns(o,1),r.store.messages.count(r.id,o)]),y=[`${e.name} ${R} · ${g.id} · ${g.model}`,`session ${o} · ${k} message(s) · window ${g.window} · store ${a}`,`ready in ${u.toFixed(0)} ms · /help for commands and keys · /exit to leave`],S=Lt(i,h);if(S!==void 0)y.push(S);if(v[0]?.errorCode==="turn_abandoned")y.push("note: the previous turn in this session did not finish — the process exited while it was generating.");for(let P of[...r.warnings,...r.tools.warnings])y.push(`note: ${P.message}
|
|
278
278
|
${P.hint}`);if(f.length>0)y.push(`note: ${f.join(", ")} in the .env here ${f.length===1?"was":"were"} ignored — this agent's own .env sets ${f.length===1?"it":"them"}.
|
|
279
279
|
A .env in the directory you launched from configures that project, not an agent living somewhere else. Export the variable to override the agent's own file.`);return y}async function Ut(r){let o=r.once!==void 0,a=ie({json:!1,plain:r.plain===!0,oneShot:o}),{mode:u}=a;if(r.manifestPath===void 0){let F=await $a(u,a.because,r);if(typeof F==="number")return F;return Ut({...r,manifestPath:F})}let i=$r();if(r.store===void 0&&r.ephemeral!==!0&&wa(i))process.stdout.write(`note: a session store exists at ${i} from an earlier version — pass --store ${i} to keep using it; the default is now ${w()}
|
|
280
|
-
`);let f;b(()=>f?.stop("cli-exit"));let h={current:void 0},g={current:""},v={current:r.sessionKey},k={current:!1},y={current:void 0},S=r.quiet===!0,P="first",U={current:void 0},W=r.ephemeral===!0?void 0:Qs(await
|
|
280
|
+
`);let f;b(()=>f?.stop("cli-exit"));let h={current:void 0},g={current:""},v={current:r.sessionKey},k={current:!1},y={current:void 0},S=r.quiet===!0,P="first",U={current:void 0},W=r.ephemeral===!0?void 0:Qs(await Ce(xt(r.manifestPath),r.store));if(W!==void 0)return await Pa({...r,host:W,mode:u==="rich"?"rich":"plain",quiet:S,oneShot:o,reader:h,draft:g,session:v,random:jt});for(;;){let F=await L.create({agents:[r.manifestPath],toolProviders:A,builtInPlugins:C,scriptRunner:O(),channels:N,env:m([r.manifestPath]),store:r.ephemeral===!0?":memory:":r.store??w()});f=F;let I=F.list()[0];if(I===void 0)throw Error("The manifest produced no agent.");if(v.current===void 0||v.current===""){let fe=await eo({list:()=>Q.sessions(),mode:u,asked:v.current,wantsContinue:r.continueSession===!0,random:jt});if(typeof fe==="number")return await F.stop("cli-exit"),fe;v.current=fe.sessionKey,k.current=fe.fresh}let de=v.current,oe=I.roles.main.capabilities.thinking!=="none",ge=r.noReasoning===!0?!1:oe,z=S||o?[]:await ba(I,de,F.store.location,P==="first"?F.boot.processMs:F.boot.bootMs,P,Co([r.manifestPath]),y.current),V=u==="rich"&&!S&&!o?tn(await I.history(de),I.describe().dialect):[],Q=zs({agent:I,bus:F.bus,send:(fe,Ae)=>I.send(fe,Ae),history:async(fe)=>tn(await I.history(fe),I.describe().dialect),sessions:async()=>await I.store.sessions.list(I.id),clearSession:async(fe)=>{await I.clearSession(fe)},context:async(fe)=>Ea(I,fe),streamFilter:()=>I.streamFilter(),description:{agentId:I.id,name:I.describe().name,model:I.describe().model,dialect:I.describe().dialect,window:I.describe().window,catalogueTokens:I.describe().catalogueTokens,thinking:I.roles.main.capabilities.thinking,warnings:[...I.warnings,...I.tools.warnings]}}),re={...r,source:Q,embedded:{agent:I,runtime:F},sessionKey:de,banner:z,prior:V,quiet:S,reader:h,draft:g,showReasoning:ge,freshSession:k.current,switchTo:U,random:jt},he=u==="rich"?await no(re):await to(re);if(await F.stop(he===Ne?"restart":"cli-exit"),he!==Ne)return he;if(U.current===void 0)P="restart";else P=U.current.reason,y.current=de,v.current=U.current.key,U.current=void 0;k.current=!1}}function va(r,o){let a=[];for(let u of r)Se({action:"install",manifestPath:o,name:`${u.source}/${u.skill}`,quiet:!0,collect:a});return a}var Ne=Symbol("restart");async function $a(r,o,a){let u=K();if(u.length===0){if(r==="rich"){let y=await at({plain:a.plain===!0});if(y.kind==="aborted")return process.stdout.write(`nothing to run
|
|
281
281
|
`),n;if(y.kind==="failed")return y.code;return y.manifestPath}throw new t({code:"cli_sandbox_empty",message:"No agent named, and the sandbox is empty.",hint:`Create one with \`${e.slug} init\`, or pass a path to an agent.yaml.`})}if(u.length===1&&u[0]!==void 0)return process.stdout.write(`running ${u[0].ref} — the only agent in the sandbox
|
|
282
282
|
`),u[0].manifestPath;if(r!=="rich"){for(let y of u)process.stdout.write(`${y.ref} ${y.problem??y.modelId??"?"} ${y.dir}
|
|
283
283
|
`);return process.stderr.write(`pass an agent name or a manifest path — the picker needs a terminal (${o})
|
|
284
|
-
`),s}let[{render:i},{createElement:f},{Picker:h}]=await Promise.all([import("ink"),import("react"),import("./Picker-
|
|
284
|
+
`),s}let[{render:i},{createElement:f},{Picker:h}]=await Promise.all([import("ink"),import("react"),import("./Picker-hfeh1g6m.js")]),g={kind:"quit"};Wt();let v=i(f(h,{title:`${e.name} ${R}`,agents:u,onDone:(y)=>{g=y}}),{exitOnCtrlC:!1,...Z(a.noEnhancedKeys)});b(()=>v.unmount()),await v.waitUntilExit(),v.unmount();let k=g;if(k.kind==="quit")return process.stdout.write(`nothing run
|
|
285
285
|
`),n;if(k.kind==="create"){let y=await at({plain:a.plain===!0});if(y.kind==="aborted")return process.stdout.write(`nothing to run
|
|
286
286
|
`),n;if(y.kind==="failed")return y.code;return y.manifestPath}return k.manifestPath}async function eo(r){let o=()=>({sessionKey:Hn(r.random),fresh:!0});if(r.wantsContinue&&r.asked==="")throw new t({code:"cli_session_ambiguous",message:"--continue and a bare --session ask for different things.",hint:"--continue takes the most recent conversation without asking; --session on its own opens the list. Pass one."});if(r.wantsContinue){let a=await r.list(),u=ka(a);if(u===void 0)return process.stdout.write(`no stored conversation with this agent yet — starting a new one
|
|
287
287
|
`),o();return{sessionKey:u.sessionKey,fresh:!1}}if(r.asked===""){let a=await r.list();if(a.length===0)return process.stdout.write(`no stored conversation with this agent yet — starting a new one
|
|
288
288
|
`),o();if(r.mode!=="rich"){for(let i of[...a].sort(Kn))process.stdout.write(`${i.sessionKey} ${i.messages} ${i.turns} ${i.lastActivityAt}
|
|
289
289
|
`);return process.stderr.write(`pass --session <key> — the picker needs a terminal, and --continue takes the most recent without one
|
|
290
|
-
`),s}let u=await Sa([...a].sort(Kn));return u===void 0?o():{sessionKey:u,fresh:!1}}return r.asked===void 0?o():{sessionKey:r.asked,fresh:!1}}function Kn(r,o){return Date.parse(o.lastActivityAt)-Date.parse(r.lastActivityAt)}function ka(r){return[...r].sort(Kn)[0]}async function Sa(r){let[{render:o},{createElement:a},{SessionPicker:u}]=await Promise.all([import("ink"),import("react"),import("./SessionPicker-
|
|
290
|
+
`),s}let u=await Sa([...a].sort(Kn));return u===void 0?o():{sessionKey:u,fresh:!1}}return r.asked===void 0?o():{sessionKey:r.asked,fresh:!1}}function Kn(r,o){return Date.parse(o.lastActivityAt)-Date.parse(r.lastActivityAt)}function ka(r){return[...r].sort(Kn)[0]}async function Sa(r){let[{render:o},{createElement:a},{SessionPicker:u}]=await Promise.all([import("ink"),import("react"),import("./SessionPicker-zyqkg4dn.js")]),i;Wt();let f=o(a(u,{sessions:r.map((h)=>({sessionKey:h.sessionKey,messages:h.messages,turns:h.turns,lastActivityAt:h.lastActivityAt,phase:h.phase})),now:Date.now(),columns:q(process.stdout.columns,j),maxRows:Bt,onDone:(h)=>{i=h,f.unmount()}}),{exitOnCtrlC:!1,...Z()});return b(()=>f.unmount()),await f.waitUntilExit(),i}function xa(r,o,a,u,i){let f=r.describe(),h=[`${e.name} ${R} · ${f.agentId} · ${f.model}`,`session ${o} · window ${f.window} · attached to ${a.baseUrl} (pid ${a.pid})`,"a view — the agent keeps running when you leave · /help for commands · /exit to detach"],g=Lt(u,i);if(g!==void 0)h.push(g);for(let v of f.warnings)h.push(`warning: ${v.message}`);return h}async function Pa(r){let o=r.manifestPath??"",a=xt(o),u=Je(o),i=Xs({baseUrl:r.host.baseUrl,...u===void 0?{}:{token:u}}),f=await i.agent(a).describe(),h=Ys({client:i,agentId:a,host:r.host,description:{agentId:a,name:f.name,model:f.model??"unknown",dialect:f.dialect??"nlt",window:f.window??0,catalogueTokens:f.catalogueTokens??0,thinking:"unknown",warnings:f.warnings??[]}}),g={current:void 0},v="first",k={current:void 0},y={current:!1};for(;;){if(r.session.current===void 0||r.session.current===""){let I=await eo({list:()=>h.sessions(),mode:r.mode,asked:r.session.current,wantsContinue:r.continueSession===!0,random:r.random});if(typeof I==="number")return I;r.session.current=I.sessionKey,y.current=I.fresh}let S=r.session.current??"",P=r.quiet||r.oneShot?[]:xa(h,S,r.host,v,k.current),U=r.mode==="rich"&&!r.quiet&&!r.oneShot?await h.history(S):[],W={...r,source:h,sessionKey:S,banner:P,prior:U,quiet:r.quiet,reader:r.reader,draft:r.draft,showReasoning:r.noReasoning!==!0,freshSession:y.current,switchTo:g,random:r.random},F=r.mode==="rich"?await no(W):await to(W);if(F!==Ne)return await h.close(),F;if(g.current===void 0)v="restart";else v=g.current.reason,k.current=S,r.session.current=g.current.key,g.current=void 0;y.current=!1}}async function no(r){let[{render:o},{createElement:a},{App:u}]=await Promise.all([import("ink"),import("react"),import("./App-b1yrwrcq.js")]),i=En();b(()=>{i.close()}),pe(),Zr(),process.stdout.write(`${ve}${Ko}`);let f=!1,h=o(a(u,{source:r.source,onSwitch:(g,v)=>{f=!0,r.switchTo.current={key:g,reason:"switch"},r.draft.current=v},onNew:(g)=>{f=!0,r.switchTo.current={key:Hn(r.random),reason:"new"},r.draft.current=g},sessions:async()=>[...await r.source.sessions()].sort(Kn).map((v)=>({sessionKey:v.sessionKey,messages:v.messages,turns:v.turns,lastActivityAt:v.lastActivityAt,phase:v.phase})),onRestart:(g)=>{f=!0,r.draft.current=g},sessionKey:r.sessionKey,model:r.source.describe().model,agentName:r.source.describe().agentId,freshSession:r.freshSession,warnings:r.source.describe().warnings.map((g)=>g.message),initial:So(ko(r.banner.slice(1)),r.prior),correctKeys:i.correct,showReasoning:r.showReasoning,quiet:r.quiet,...r.manifestPath===void 0?{}:{manifestPath:r.manifestPath},catalogue:{load:(g)=>nt({onStatus:g}),install:async(g,v)=>Et(va(g,v))},status:()=>r.embedded===void 0?so(r.source):ro(r.embedded),contextView:()=>oo(r,r.sessionKey),...r.draft.current===""?{}:{initialDraft:r.draft.current}}),{exitOnCtrlC:!1,...Z(r.noEnhancedKeys)});if(b(()=>h.unmount()),await h.waitUntilExit(),J(),!f)process.stdout.write(Js({ref:r.source.describe().agentId,sessionKey:r.sessionKey}));return f?Ne:n}async function to(r){let{source:o,sessionKey:a,quiet:u}=r,i=!0,f=(z)=>{if(z==="")return;process.stdout.write(z),i=z.endsWith(`
|
|
291
291
|
`)},h=(z)=>{if(!i)f(`
|
|
292
292
|
`);f(`${z}
|
|
293
293
|
`)};if(r.banner.length>0)f(`${r.banner.join(`
|
|
@@ -308,16 +308,16 @@ ${V.error.code}: ${V.error.message}
|
|
|
308
308
|
hint: ${V.error.hint}
|
|
309
309
|
`);if(xr(V.reason))I=s;if(!u&&V.reason==="final")f(` ${V.tokens.prompt} prompt · ${V.tokens.output} output · ${V.durationMs} ms
|
|
310
310
|
|
|
311
|
-
`);await ue()},
|
|
312
|
-
`);for(let f of r)process.stdout.write(`${
|
|
311
|
+
`);await ue()},ge=()=>de();process.on("SIGINT",ge);try{if(r.once!==void 0)return await oe(r.once),I;if(process.stdin.isTTY!==!0){let V=r.reader.current??Zs({input:process.stdin});r.reader.current=V;for await(let Q of V){let re=Q.trim();if(re==="")continue;let he=await U(re);if(he==="exit")break;if(he==="restart"){I=Ne;break}if(he==="handled")continue;await oe(re)}return I}let z=r.reader.current??Zs({input:process.stdin,output:process.stdout,prompt:An,terminal:!1});r.reader.current=z,z.prompt();for await(let V of z){let Q=V.trim();if(Q===""){z.prompt();continue}let re=await U(Q);if(re==="exit")break;if(re==="restart"){I=Ne;break}if(re==="handled"){z.prompt();continue}await oe(Q),z.prompt()}if(I!==Ne)z.close(),r.reader.current=void 0;return I}finally{process.off("SIGINT",ge),P()}}async function ro(r){let{agent:o,runtime:a}=r,u=o.describe(),i=o.manifest,f=i.channels.filter((y)=>y.enabled).map((y)=>`${y.id} (${y.type})`).join(", "),h=f===""?"none — reached through this session and the HTTP API only":a.channels.started?`${f} — connected in this session`:`${f} — configured, NOT running here; \`serve\` starts channels, \`run\` does not`,g=!i.server.enabled?"off":`enabled on ${i.server.host}:${i.server.port}, NOT bound here — \`serve\` binds it`,v=ye(i),k=v.filter((y)=>y.role!=="main"&&y.role===y.configuredAs);return l([{label:"agent",value:`${u.id} (${u.name})`},{label:"model",value:`${u.model} · ${i.tools.dialect} · ${u.window} token window (${je(v[0]?.window)})`},...k.map((y)=>({label:y.role,value:`${y.modelId} · ${y.window.contextWindow} token window (${je(y.window)})`})),{label:"channels",value:h},{label:"http api",value:g},{label:"store",value:a.store.location},{label:"background",value:await Ra(a,u.id)}])}async function so(r){let o=r.describe(),a=r.host,[u,i]=await Promise.all([r.tools(),r.sessions()]);return l([{label:"agent",value:`${o.agentId} (${o.name})`},{label:"attached to",value:a===void 0?"a host":`${a.baseUrl} · pid ${a.pid}`},{label:"this session",value:"a view — the agent runs in the host, and stays running when this exits"},{label:"model",value:`${o.model} · ${o.window} token window`},{label:"dialect",value:o.dialect},{label:"tools",value:`${u.tools.length} pinned · ${u.catalogueTokens} catalogue tokens per turn`},{label:"conversations",value:`${i.length} on this agent`},{label:"warnings",value:o.warnings.length===0?"none":o.warnings.map((f)=>f.message).join("; ")}])}async function Ea(r,o){let a=await r.previewContext({sessionKey:o}),[u]=ye(r.manifest);return{slots:a.slots,history:a.history,cache:a.cache,total:a.total,window:a.window,windowSource:je(u?.window),wireTokens:a.wireTokens,reserveOutput:a.reserveOutput,calibration:a.calibration,lastCompaction:a.compactions===0?void 0:`${a.compactions} stage${a.compactions===1?"":"s"} run this session`}}async function oo(r,o){return bo(await r.source.context(o))}async function Ra(r,o){if(r.owned.includes(o))return"this session is serving this agent";let a=await r.store.leases.get(o);if(a!==void 0&&_(a.pid))return a.mode==="daemon"?`running as a background service · pid ${a.pid} · \`${e.slug} daemon status ${o}\``:`served by another session · pid ${a.pid} (${a.mode})`;return`not supervised — \`${e.slug} daemon install ${o}\` keeps it running without a terminal`}function be(r,o){return r.length>=o?r:r+" ".repeat(o-r.length)}function Ia(r,o){if(!r.enabled)return"off";if(r.nextRunAt===void 0)return"done";let a=Date.parse(r.nextRunAt)-o;if(a<=0)return"due";let u=Math.round(a/60000);if(u<60)return`in ${u}m`;let i=Math.round(a/3600000);return i<48?`in ${i}h`:`in ${Math.round(i/24)}d`}function Ta(r,o){if(r.lastFiredAt===void 0)return"never run";let a=qe(r.lastFiredAt,o);if(r.lastStatus==="error")return`FAILED ${a}`;return`ok ${a}`}function Aa(r,o){if(r.length===0){process.stdout.write("no schedules — add a `schedules:` block to the manifest\n");return}let a=Math.max(8,...r.map((f)=>f.id.length)),u=Math.max(4,...r.map((f)=>`${f.kind} ${f.expr}`.length));process.stdout.write(`${be("SCHEDULE",a)} ${be("WHEN",u)} ${be("NEXT",7)} LAST
|
|
312
|
+
`);for(let f of r)process.stdout.write(`${be(f.id,a)} ${be(`${f.kind} ${f.expr}`,u)} ${be(Ia(f,o),7)} ${Ta(f,o)}
|
|
313
313
|
`);let i=r.filter((f)=>f.lastStatus==="error");if(i.length>0)process.stdout.write(`
|
|
314
314
|
${i.length} failing — \`schedules --id ${i[0]?.id}\` for the error
|
|
315
315
|
`)}function Oa(r){let o=[["kind",`${r.kind} ${r.expr}`],["timezone",r.timezone??"(host)"],["task",r.task],["deliver",r.deliverChannel===void 0?"none — the reply reaches the event stream only":`${r.deliverChannel} → ${r.deliverTo}`],["session",r.sessionMode],["model role",r.role??"main"],["enabled",r.enabled?"yes":"no"],["declared in",r.origin==="manifest"?"agent.yaml":"the API"],["next run",r.nextRunAt??"(never again)"],["runs",String(r.runs)],["last run",r.lastFiredAt??"never"],["last status",r.lastStatus??"-"]];if(r.lastError!==void 0)o.push(["last error",r.lastError]);let a=Math.max(...o.map(([u])=>u.length));process.stdout.write(`${r.id}
|
|
316
|
-
`);for(let[u,i]of o)process.stdout.write(` ${
|
|
316
|
+
`);for(let[u,i]of o)process.stdout.write(` ${be(u,a)} ${i}
|
|
317
317
|
`)}function _a(r,o){let a=new Set(o),u=new Map;for(let i of r){if(!a.has(i.channel))continue;let f=`${i.channel}\x00${i.peerId}`,h=u.get(f);if(h!==void 0&&h.lastSeen>=i.lastActivityAt)continue;u.set(f,{channelId:i.channel,address:i.peerId,lastSeen:i.lastActivityAt})}return[...u.values()].sort((i,f)=>i.channelId===f.channelId?f.lastSeen.localeCompare(i.lastSeen):i.channelId.localeCompare(f.channelId))}function Ca(r,o){if(r.length===0){process.stdout.write(`no addresses yet — this agent has had no conversation on a declared channel.
|
|
318
318
|
`+` An address appears here once a first message arrives on one.
|
|
319
|
-
`);return}let a=Math.max(7,...r.map((i)=>i.channelId.length)),u=Math.max(7,...r.map((i)=>i.address.length));process.stdout.write(`${
|
|
320
|
-
`);for(let i of r)process.stdout.write(`${
|
|
319
|
+
`);return}let a=Math.max(7,...r.map((i)=>i.channelId.length)),u=Math.max(7,...r.map((i)=>i.address.length));process.stdout.write(`${be("CHANNEL",a)} ${be("ADDRESS",u)} LAST SEEN
|
|
320
|
+
`);for(let i of r)process.stdout.write(`${be(i.channelId,a)} ${be(i.address,u)} ${qe(i.lastSeen,o)}
|
|
321
321
|
`);process.stdout.write(`
|
|
322
322
|
Use an ADDRESS in deliver.to. On Telegram an @name addresses a channel and
|
|
323
323
|
`+`never a person — a private chat is reached by the numeric id above.
|
|
@@ -334,14 +334,14 @@ Use an ADDRESS in deliver.to. On Telegram an @name addresses a channel and
|
|
|
334
334
|
`)}if(r.recipients===!0){let f=_a(await a.store.sessions.list(a.id),a.manifest.channels.map((h)=>h.id));if(r.json===!0)return process.stdout.write(`${JSON.stringify({recipients:f},null,2)}
|
|
335
335
|
`),n;return Ca(f,u),n}let i=await a.store.schedules.list(a.id);if(r.json)return process.stdout.write(`${JSON.stringify({schedules:i},null,2)}
|
|
336
336
|
`),n;if(r.id!==void 0){let f=i.find((h)=>h.id===r.id);if(f===void 0)return process.stderr.write(`no schedule "${r.id}" on ${a.id}
|
|
337
|
-
`),s;return Oa(f),n}if(r.enable===void 0&&r.disable===void 0)Aa(i,u);return n}import{dirname as lo,resolve as Dt}from"node:path";function Na(){return mt.shape.server.parse({})}async function co(r){let o=m(r.manifestPaths),a=r.store??w(),u=await zr(r.manifestPaths,o,a),i=u.filter((D)=>!D.enabled),f=u.filter((D)=>D.enabled),h=r.manifestPaths.length===0,g=[],v=[];for(let D of f)try{let ne=T(D.manifestPath),se=await yt({refs:ne.plugins??[],agentId:ne.id??D.manifestPath,paths:{workspace:lo(Dt(D.manifestPath)),state:lo(Dt(D.manifestPath)),manifest:Dt(D.manifestPath)},env:o,bus:new
|
|
337
|
+
`),s;return Oa(f),n}if(r.enable===void 0&&r.disable===void 0)Aa(i,u);return n}import{dirname as lo,resolve as Dt}from"node:path";function Na(){return mt.shape.server.parse({})}async function co(r){let o=m(r.manifestPaths),a=r.store??w(),u=await zr(r.manifestPaths,o,a),i=u.filter((D)=>!D.enabled),f=u.filter((D)=>D.enabled),h=r.manifestPaths.length===0,g=[],v=[];for(let D of f)try{let ne=T(D.manifestPath),se=await yt({refs:ne.plugins??[],agentId:ne.id??D.manifestPath,paths:{workspace:lo(Dt(D.manifestPath)),state:lo(Dt(D.manifestPath)),manifest:Dt(D.manifestPath)},env:o,bus:new _e({runtimeId:"serve-preload"}),builtIn:C,base:{toolProviders:A,channels:N}});g.push({path:D.manifestPath,loaded:x(D.manifestPath,{knownProviders:Object.keys(se.toolProviders),knownChannels:Object.keys(se.channels),env:o})})}catch(ne){if(!h)throw ne;v.push({path:D.manifestPath,detail:tr(ne)?ne.message:String(ne),...tr(ne)&&ne.hint!==void 0?{hint:ne.hint}:{}})}let k=g[0],y=k?.loaded,S=y?.manifest.server??Na();for(let D of g.slice(1)){let ne=D.loaded.manifest.server;for(let[se,De,rn,Le]of[["server.port",S.port,ne.port,r.port!==void 0],["server.host",S.host,ne.host,r.host!==void 0],["server.tokenEnv",S.tokenEnv,ne.tokenEnv,!1]]){if(Le||De===rn)continue;throw new t({code:"serve_bind_conflict",message:`${k?.path??"the first manifest"} sets ${se} to ${String(De)} and ${D.path} sets it to ${String(rn)}.`,hint:"One process binds one socket with one token, so these have to agree. Make them match, or run the disagreeing agent in its own process — a second `serve` on its own port.",field:se})}}let P=r.port??S.port,U=r.host??S.host,W=y===void 0?o[S.tokenEnv]:y.env[S.tokenEnv],F=o[`${e.envPrefix}SERVICE`]!==void 0,I=new _e({runtimeId:`rt_${Date.now().toString(36)}`});if(r.json!==!0)I.on("agent.channel.status",(D)=>{let ne=D.data,se=ne.input===void 0?"":` (${ne.input.kind}${ne.input.expiresAt===void 0?"":`, expires ${ne.input.expiresAt}`} — GET /v1/agents/${D.agentId??""} carries it)`;process.stdout.write(` ${ne.channelId}: ${ne.status}${ne.detail===void 0?"":` — ${ne.detail}`}${se}
|
|
338
338
|
`)}),I.on("agent.channel.error",(D)=>{let ne=D.data;process.stderr.write(` ${ne.channelId}: ${ne.message}
|
|
339
339
|
hint: ${ne.hint}
|
|
340
340
|
`)}),I.on("agent.channel.rejected",(D)=>{let ne=D.data;process.stdout.write(` ${ne.channelId}: ${ne.reason} — ${ne.detail}
|
|
341
|
-
`)});let de=cr(),oe=await L.create({agents:g.map((D)=>D.path),approve:de.approver,env:o,bus:I,toolProviders:A,builtInPlugins:C,scriptRunner:O(),channels:N,startChannels:!0,startSchedules:!0,store:a,mode:F?"daemon":"terminal"});Vr();let
|
|
341
|
+
`)});let de=cr(),oe=await L.create({agents:g.map((D)=>D.path),approve:de.approver,env:o,bus:I,toolProviders:A,builtInPlugins:C,scriptRunner:O(),channels:N,startChannels:!0,startSchedules:!0,store:a,mode:F?"daemon":"terminal"});Vr();let ge=Fa(),z=await oe.store.operatorKeys.liveCount(),V=z===0||r.claim===!0?Lr():void 0,Q;try{Q=await Ur({runtime:oe,host:U,port:P,approvals:de,allowedOrigins:S.allowedOrigins,allowedHosts:S.allowedHosts,resolveAgent:(D)=>Kt(D,o),provision:{steps:()=>es({agentDirBase:B(o)}),create:(D)=>ns({answers:D,defaults:{agentDirBase:B(o)}})},...V===void 0?{}:{claim:V},...W===void 0||W===""?{}:{token:W}})}catch(D){if(await oe.stop("server failed to bind"),D instanceof t)throw D;throw new t({code:"server_bind_failed",message:`Could not bind ${U}:${P}: ${D instanceof Error?D.message:String(D)}`,hint:"Another process is probably on that port. Pass --port, or set server.port in the manifest.",cause:D})}await oe.publishAddress(Q.url);let re=oe.list(),he=re[0];if(he!==void 0)process.title=re.length===1?`${e.slug} ${he.id}`:`${e.slug} ${re.length} agents`;for(let D of re)D.reportRuntimeState({serverListening:!0});if(r.json===!0)process.stdout.write(`${JSON.stringify({url:Q.url,websocket:Q.websocket,authenticated:W!==void 0&&W!=="",keys:z,...V===void 0?{}:{claim:V.token},agents:re.map((D)=>({id:D.id,channels:oe.channels.statusOf(D.id)})),declined:oe.declined.map((D)=>({agentId:D.agentId,pid:D.pid,mode:D.mode,since:D.startedAt})),disabled:i.map((D)=>({agentId:D.agentId,...D.reason===void 0?{}:{reason:D.reason}})),broken:v.map((D)=>({path:D.path,detail:D.detail,...D.hint===void 0?{}:{hint:D.hint}}))})}
|
|
342
342
|
`);else{let D=`http://${Xe(U)}:${Q.port}`,ne=D===Q.url?"":` (bound ${U} — every interface)`;process.stdout.write(`${e.name} serving on ${D}${ne}
|
|
343
343
|
`),process.stdout.write(` web UI ${D}/ · API reference ${D}/docs
|
|
344
|
-
`);for(let se of re){let De=oe.channels.statusOf(se.id),rn=De.length===0?"no channels":De.map((an)=>`${an.id} (${an.type})`).join(", "),
|
|
344
|
+
`);for(let se of re){let De=oe.channels.statusOf(se.id),rn=De.length===0?"no channels":De.map((an)=>`${an.id} (${an.type})`).join(", "),Le=se.manifest.schedules.filter((an)=>an.enabled),Po=se.manifest.schedules.length===0?"":`, ${Le.length} schedule${Le.length===1?"":"s"}${se.manifest.schedules.length>Le.length?` (+${se.manifest.schedules.length-Le.length} disabled)`:""}`;process.stdout.write(` ${se.id} — ${rn}${Po}
|
|
345
345
|
`)}for(let se of i)process.stdout.write(` ${se.agentId} — stopped${se.reason===void 0?"":` (${se.reason})`}, \`${e.slug} start ${se.agentId}\`
|
|
346
346
|
`);for(let se of v)if(process.stdout.write(` ${se.path} — NOT served: ${se.detail}
|
|
347
347
|
`),se.hint!==void 0)process.stdout.write(` hint: ${se.hint}
|
|
@@ -356,17 +356,17 @@ Use an ADDRESS in deliver.to. On Telegram an @name addresses a channel and
|
|
|
356
356
|
`);if(F)process.stdout.write(` running as a background service · ${e.slug} daemon status ${re[0]?.id??""}
|
|
357
357
|
`);else if(dt())process.stdout.write(` supervised by the container runtime — it stops with the container, and SIGTERM finishes the delivery in flight.
|
|
358
358
|
`);else process.stdout.write(` ctrl-c to stop — this ends when the terminal does. \`${e.slug} daemon install${re[0]?.id===void 0?"":` ${re[0].id}`}\` keeps it running.
|
|
359
|
-
`)}let fe=!1,
|
|
360
|
-
`),await
|
|
361
|
-
`);return}let o=La(r),a=Math.max(7,...o.map((u)=>u.sessionKey.length));process.stdout.write(`${
|
|
362
|
-
`);for(let u of o){let i=u.runs===void 0?"":` (${u.runs} run${u.runs===1?"":"s"})`;process.stdout.write(`${
|
|
359
|
+
`)}let fe=!1,Ae=async()=>{if(fe)return;fe=!0,await Q.stop(),await oe.stop("interrupted")};return b(Ae),await ge,process.stdout.write(`stopping
|
|
360
|
+
`),await Ae(),n}function Fa(){return new Promise((r)=>{let o=()=>{process.off("SIGINT",o),process.off("SIGTERM",o),r()};process.once("SIGINT",o),process.once("SIGTERM",o)})}function me(r,o){return r.length>=o?r:r+" ".repeat(o-r.length)}function La(r){let o=new Map,a=[];for(let u of r){let i=u.sessionKey.split(":"),f={sessionKey:u.sessionKey,phase:u.phase,messages:u.messages,turns:u.turns,lastActivityAt:u.lastActivityAt};if(i.length!==3||i[0]!=="schedule"){a.push(f);continue}let h=`schedule:${i[1]}`,g=o.get(h);if(g===void 0){let v={...f,sessionKey:`${h}:*`,runs:1};o.set(h,v),a.push(v);continue}if(g.runs=(g.runs??1)+1,g.messages+=u.messages,g.turns+=u.turns,u.lastActivityAt>g.lastActivityAt)g.lastActivityAt=u.lastActivityAt}return a}function ja(r){if(r.length===0){process.stdout.write(`no sessions yet
|
|
361
|
+
`);return}let o=La(r),a=Math.max(7,...o.map((u)=>u.sessionKey.length));process.stdout.write(`${me("SESSION",a)} ${me("MSGS",5)} ${me("TURNS",5)} ${me("PHASE",8)} LAST
|
|
362
|
+
`);for(let u of o){let i=u.runs===void 0?"":` (${u.runs} run${u.runs===1?"":"s"})`;process.stdout.write(`${me(u.sessionKey,a)} ${me(String(u.messages),5)} ${me(String(u.turns),5)} ${me(u.phase??"-",8)} ${qe(u.lastActivityAt,Date.now())}${i}
|
|
363
363
|
`)}}async function Ma(r,o,a){let u=await r.store.messages.page(r.id,o,{limit:a});if(u.messages.length===0){process.stdout.write(`no messages in ${o}
|
|
364
364
|
`);return}for(let i of[...u.messages].reverse())process.stdout.write(`${i.role}: ${i.content}
|
|
365
365
|
`);if(u.nextBefore!==void 0)process.stdout.write(`
|
|
366
366
|
… older messages exist; raise --limit
|
|
367
367
|
`)}async function Ka(r,o,a){let u=await r.turns(o,a);if(u.length===0){process.stdout.write(`no turns in ${o}
|
|
368
|
-
`);return}process.stdout.write(`${
|
|
369
|
-
`);for(let i of u)if(process.stdout.write(`${
|
|
368
|
+
`);return}process.stdout.write(`${me("TURN",22)} ${me("STATUS",9)} ${me("STEPS",5)} ${me("TOKENS",13)} ${me("MS",6)} SOURCE
|
|
369
|
+
`);for(let i of u)if(process.stdout.write(`${me(i.turnId,22)} ${me(i.status,9)} ${me(String(i.steps),5)} ${me(`${i.promptTokens}/${i.outputTokens}`,13)} ${me(String(i.durationMs??"-"),6)} ${i.source}
|
|
370
370
|
`),i.errorCode!==void 0){if(process.stdout.write(` ${i.errorCode}: ${i.errorMessage}
|
|
371
371
|
`),i.errorHint!==void 0)process.stdout.write(` hint: ${i.errorHint}
|
|
372
372
|
`)}}async function uo(r){let o=await L.create({agents:[r.manifestPath],store:r.store??w(),toolProviders:A,builtInPlugins:C,scriptRunner:O(),channels:N,env:m([r.manifestPath])});b(()=>o.stop("cli-exit"));let a=o.list()[0];if(a===void 0)throw Error("The manifest produced no agent.");let u=r.limit??Cn;if(r.clear===!0){if(r.sessionKey===void 0)throw Error("--clear needs a session. hint: pass --session <key>; there is deliberately no way to clear every session at once.");let f=await a.store.messages.count(a.id,r.sessionKey);return await a.clearSession(r.sessionKey),process.stdout.write(`cleared ${r.sessionKey}: ${f} message(s) removed, memory files untouched
|
|
@@ -421,7 +421,7 @@ ${c(h.hint,4)}
|
|
|
421
421
|
`),s;let u=a.filter((g)=>!ce(g.name,r.env));for(let g of u){if(r.json!==!0)process.stdout.write(`fetching ${g.name} for the first time … `);try{let v=await tt(g,{...r.env===void 0?{}:{env:r.env},...r.git===void 0?{}:{git:r.git}});if(r.json!==!0)process.stdout.write(`${v.skills} skills
|
|
422
422
|
`)}catch(v){if(r.json!==!0){if(process.stdout.write(`failed
|
|
423
423
|
`),v instanceof t)process.stdout.write(`${c(v.message)}
|
|
424
|
-
`)}}}let i=a.flatMap((g)=>
|
|
424
|
+
`)}}}let i=a.flatMap((g)=>ke(g,r.env));if(i.length===0)return process.stdout.write(`
|
|
425
425
|
nothing to search — no source has been fetched successfully
|
|
426
426
|
|
|
427
427
|
\`sources update\` reports why.
|
|
@@ -439,7 +439,7 @@ ${c(`… and ${f.length-h.length} more; narrow the query or use --json`)}
|
|
|
439
439
|
`);return process.stdout.write(`
|
|
440
440
|
${p("install")}
|
|
441
441
|
${c(`skills install <agent> ${h[0]?.source}/${h[0]?.skill}`)}
|
|
442
|
-
`),n}function od(r,o){let a=new Map,u=o.map((i)=>{let f=`${i.source}/${i.skill}`;return a.set(f,i),{name:f,dir:i.dir,tokens:i.tokens,scripts:[],ignoredScripts:[],frontmatter:{name:f,description:i.description,metadata:{}}}});return wt(r,u).filter((i)=>i.score>0).map((i)=>a.get(i.skill.name)).filter((i)=>i!==void 0)}async function po(r){let o=id(r.manifestPath),a=await Br(o,r.store),u=[];if(a?.enabled===!0)u.push("was already switched on");await Pn(o,!0,void 0,r.store);let i=await
|
|
442
|
+
`),n}function od(r,o){let a=new Map,u=o.map((i)=>{let f=`${i.source}/${i.skill}`;return a.set(f,i),{name:f,dir:i.dir,tokens:i.tokens,scripts:[],ignoredScripts:[],frontmatter:{name:f,description:i.description,metadata:{}}}});return wt(r,u).filter((i)=>i.score>0).map((i)=>a.get(i.skill.name)).filter((i)=>i!==void 0)}async function po(r){let o=id(r.manifestPath),a=await Br(o,r.store),u=[];if(a?.enabled===!0)u.push("was already switched on");await Pn(o,!0,void 0,r.store);let i=await Pe(r.store),f=!1;if(i===void 0)u.push("nothing is serving yet — it will be hosted at the next start");else if(i.baseUrl===void 0)u.push(`pid ${i.pid} is a ${i.mode} session, which serves no HTTP to adopt into`);else{let h=await Qe(i,`/v1/agents/${encodeURIComponent(o)}/start`,{},r.manifestPath);if(h.ok)f=!0,u.push(`adopted by pid ${i.pid}, live now`);else if(h.status===501)u.push(`pid ${i.pid} cannot look up manifests — restart it to pick this up`);else if(h.status===401)u.push(`pid ${i.pid} refused the request — set ${e.envPrefix}API_TOKEN to the server's token`);else u.push(`pid ${i.pid} could not adopt it${h.detail===void 0?"":`: ${h.detail}`}`)}if(r.json===!0)process.stdout.write(`${JSON.stringify({started:[{agentId:o,enabled:!0,running:f,...i===void 0?{}:{pid:i.pid,mode:i.mode},note:u.join(" · ")}]},null,2)}
|
|
443
443
|
`);else if(process.stdout.write(`${l([{label:o,value:f?"running":"switched on",note:u.join(" · ")}])}
|
|
444
444
|
`),!f&&i!==void 0&&i.baseUrl!==void 0)process.stdout.write(`
|
|
445
445
|
Switched on but not yet running. \`${e.slug} daemon restart\` picks it up.
|
|
@@ -476,7 +476,7 @@ ${d("nothing was written")}
|
|
|
476
476
|
${p("done")}
|
|
477
477
|
${u===""?"":`${c(`a copy of the old file is at ${vt(`${a}.${e.slug}-backup`,o.home)}`)}
|
|
478
478
|
`}${d("restart the terminal, then press shift+⏎ in a session to check it")}
|
|
479
|
-
`),n}async function yo(r){return r.warm===!0?await pd(r):await hd(r)}async function pd(r){let o=x(r.manifestPath,{knownProviders:Y,knownChannels:X,env:m([r.manifestPath])}),a=
|
|
479
|
+
`),n}async function yo(r){return r.warm===!0?await pd(r):await hd(r)}async function pd(r){let o=x(r.manifestPath,{knownProviders:Y,knownChannels:X,env:m([r.manifestPath])}),a=we(o.manifest.tools).selections,u=o.manifest.tools.pinned;if(a.length===0)return process.stdout.write(`nothing to warm — this manifest configures no tools.providers, so every tool it pins resolves locally.
|
|
480
480
|
`),n;if(u.length===0)return process.stdout.write(`nothing to warm — ${a.map((g)=>g.id).join(", ")} configured but tools.pinned is empty, so there are no schemas to fetch.
|
|
481
481
|
`),n;let i=[],f=new Set;for(let g of a){let v=A[g.id];if(v===void 0)return s;let k=v({dir:o.dir,env:o.env,config:g.config,agentId:o.manifest.id});if(k.refresh===void 0){for(let S of await k.resolve(u))f.add(S.spec.slug);if(r.json!==!0)process.stdout.write(`${g.id}: nothing to warm — it resolves without a cache.
|
|
482
482
|
`);continue}let y=await k.refresh(u);for(let S of u)if(!y.missing.includes(S))f.add(S);i.push({provider:g.id,fetched:y.fetched,changed:[...y.changed],missing:[...y.missing],cachePath:"cachePath"in y&&typeof y.cachePath==="string"?y.cachePath:""})}if(r.json===!0)process.stdout.write(`${JSON.stringify(i,null,2)}
|
|
@@ -486,8 +486,8 @@ ${u===""?"":`${c(`a copy of the old file is at ${vt(`${a}.${e.slug}-backup`,o.ho
|
|
|
486
486
|
`)}let h=u.filter((g)=>!f.has(g));for(let g of h)process.stdout.write(` missing: ${g} — no configured provider has a tool with that slug
|
|
487
487
|
`);return h.length>0?s:n}async function hd(r){let o=await L.create({agents:[r.manifestPath],toolProviders:A,builtInPlugins:C,scriptRunner:O(),channels:N,env:m([r.manifestPath])});try{let a=o.list()[0];if(a===void 0)throw Error("The manifest produced no agent.");let u=Xn(a);return process.stdout.write(r.json===!0?`${JSON.stringify(u,null,2)}
|
|
488
488
|
`:`${lt(u)}
|
|
489
|
-
`),n}finally{await o.stop("cli-exit")}}import{dirname as wo,isAbsolute as gd,resolve as Bn}from"node:path";async function vo(r){try{let o=T(r.manifestPath),a=await yt({refs:o.plugins??[],agentId:o.id??r.manifestPath,paths:{workspace:wo(Bn(r.manifestPath)),state:wo(Bn(r.manifestPath)),manifest:Bn(r.manifestPath)},env:m([r.manifestPath]),bus:new
|
|
490
|
-
`),n;let P=
|
|
489
|
+
`),n}finally{await o.stop("cli-exit")}}import{dirname as wo,isAbsolute as gd,resolve as Bn}from"node:path";async function vo(r){try{let o=T(r.manifestPath),a=await yt({refs:o.plugins??[],agentId:o.id??r.manifestPath,paths:{workspace:wo(Bn(r.manifestPath)),state:wo(Bn(r.manifestPath)),manifest:Bn(r.manifestPath)},env:m([r.manifestPath]),bus:new _e({runtimeId:"validate"}),builtIn:C,base:{toolProviders:A,channels:N}}),u=x(r.manifestPath,{knownProviders:Object.keys(a.toolProviders),knownChannels:Object.keys(a.channels),env:m([r.manifestPath])}),{manifest:i}=u,f=H(i.model.main.id,i.model.main.capabilities),{workspace:h,warnings:g}=We(u,f.promptStyle);yn(u,{channels:a.channels});let v=Ie(h,i.context.rules);if(v!==void 0&&i.context.rules.onExceed==="fail")throw v;let k=[...g,...mn(i),...v===void 0?[]:[v.toDetail()]],y=i.knowledge===void 0?void 0:gn({dir:gd(i.knowledge.dir)?i.knowledge.dir:Bn(u.dir,i.knowledge.dir),maxActive:i.knowledge.maxActive,budget:i.knowledge.budget,style:f.promptStyle}),S=["static","volatile","reminder"].map((I)=>{let de=h.files.filter((oe)=>oe.tier===I).map((oe)=>oe.name);if(de.length===0)return;return`${I}=${de.join(",")} (${h.tokens[I]}/${i.context.budgets[I]})`}).filter((I)=>I!==void 0).join(" ");if(r.json===!0)return process.stdout.write(`${JSON.stringify({ok:!0,path:u.path,id:i.id,model:i.model.main.id,window:u.window,capabilities:f,workspace:{files:h.files.map((I)=>({name:I.name,tier:I.tier,editable:I.editable,tokens:I.tokens,budget:I.budget})),tokens:h.tokens},knowledge:y===void 0?[]:y.entries.map((I)=>({name:I.name,keywords:I.keywords,tokens:I.tokens})),warnings:k},null,2)}
|
|
490
|
+
`),n;let P=ye(i),U=P.map((I)=>I.role===I.configuredAs?`${I.role}=${I.modelId}`:`${I.role}=→main`).join(" "),W=P.filter((I)=>I.role===I.configuredAs),F=$o({manifestPath:r.manifestPath,rawModelId:o.modelId,apiKeyEnv:i.model.main.apiKeyEnv}).flatMap((I)=>{let de=_o(I.origin);return de===void 0?[]:[` env ${I.variable} — ${de}
|
|
491
491
|
`]}).join("");return process.stdout.write(`ok ${u.path}
|
|
492
492
|
id ${i.id}${i.name===void 0?"":` (${i.name})`}
|
|
493
493
|
models ${U}
|
|
@@ -507,7 +507,7 @@ ${u===""?"":`${c(`a copy of the old file is at ${vt(`${a}.${e.slug}-backup`,o.ho
|
|
|
507
507
|
`+` caching at all, so no request field reaches it. Caching lives on the native
|
|
508
508
|
Messages API, which this runtime does not speak.
|
|
509
509
|
`:` promptCache none — this runtime sends no cache directives. Many endpoints cache
|
|
510
|
-
`+" a stable prefix anyway; `/context` reports what was actually charged.\n"}function xo(r){try{let o=x(r.manifestPath,{knownProviders:Y,knownChannels:X,env:m([r.manifestPath])}),{manifest:a}=o,u=H(a.model.main.id,a.model.main.capabilities),{workspace:i,warnings:f}=We(o,u.promptStyle),h=[...f,...Ir(i.files.map((k)=>({name:k.name,authored:k.authored,tier:k.tier,field:k.field})))],g=
|
|
510
|
+
`+" a stable prefix anyway; `/context` reports what was actually charged.\n"}function xo(r){try{let o=x(r.manifestPath,{knownProviders:Y,knownChannels:X,env:m([r.manifestPath])}),{manifest:a}=o,u=H(a.model.main.id,a.model.main.capabilities),{workspace:i,warnings:f}=We(o,u.promptStyle),h=[...f,...Ir(i.files.map((k)=>({name:k.name,authored:k.authored,tier:k.tier,field:k.field})))],g=Ie(i,a.context.rules);if(g!==void 0)h.push(g.toDetail());if(r.json===!0)return process.stdout.write(`${JSON.stringify({ok:h.length===0,path:o.path,promptStyle:u.promptStyle,files:i.files.map((k)=>({name:k.name,tier:k.tier,editable:k.editable,tokens:k.tokens,budget:k.budget})),tokens:i.tokens,findings:h},null,2)}
|
|
511
511
|
`),r.strict===!0&&h.length>0?s:n;let v=u.promptStyle;process.stdout.write(`${o.path}
|
|
512
512
|
rendering delimiters=${v.delimiters} intensity=${v.intensity} examplesIn=${v.examplesIn}
|
|
513
513
|
total ${i.tokens.total} tokens (static ${i.tokens.static}, volatile ${i.tokens.volatile}, reminder ${i.tokens.reminder})
|
|
@@ -522,10 +522,10 @@ ${h.length} finding(s)
|
|
|
522
522
|
`),r.strict===!0?s:n}catch(o){if(r.json===!0&&o instanceof t)return process.stdout.write(`${JSON.stringify({ok:!1,error:o.toDetail(),details:o.details},null,2)}
|
|
523
523
|
`),s;throw o}}function wd(r){if(r instanceof t)process.stderr.write(`${r.format()}
|
|
524
524
|
`);else if(r instanceof Error){if(process.stderr.write(`${r.message}
|
|
525
|
-
`),
|
|
525
|
+
`),Ee().debug&&r.stack!==void 0)process.stderr.write(`${r.stack}
|
|
526
526
|
`)}else process.stderr.write(`${String(r)}
|
|
527
527
|
`);return s}async function bd(){let r=process.stdout.write.bind(process.stdout);process.stdout.write=()=>!0;try{let o=await Ze({action:"install"});if(o!==n)return{kind:"failed",message:`daemon install exited ${o}`,hint:`Run \`${e.slug} daemon install\` to see what it said.`};return{kind:"started",label:`${e.slug}.server`}}finally{process.stdout.write=r}}async function vd(r){let o=jr(r);switch(o.kind){case"version":return process.stdout.write(`${R}
|
|
528
|
-
`),n;case"help":return process.stdout.write(It(o.command)),n;case"usage":return process.stdout.write(It()),s;case"command":break}let{command:a,positionals:u,flags:i}=o.parsed,f=u[0],h=()=>te(f),g=a.flags.some((y)=>y.name==="store")?i.str("store"):void 0,v=await ls({needsServer:a.needsServer,disabled:i.bool("no-bootstrap"),install:()=>bd(),...g===void 0?{}:{store:g}}),k=cs(v);if(k!==void 0)process.stderr.write(k);switch(a.name){case"init":{let y=i.str("dir"),S=i.str("user"),P=i.str("name"),U=i.str("purpose"),W=i.str("preset"),F=i.str("model"),I=i.str("base-url"),de=i.str("api-key-env"),oe=i.str("system"),
|
|
528
|
+
`),n;case"help":return process.stdout.write(It(o.command)),n;case"usage":return process.stdout.write(It()),s;case"command":break}let{command:a,positionals:u,flags:i}=o.parsed,f=u[0],h=()=>te(f),g=a.flags.some((y)=>y.name==="store")?i.str("store"):void 0,v=await ls({needsServer:a.needsServer,disabled:i.bool("no-bootstrap"),install:()=>bd(),...g===void 0?{}:{store:g}}),k=cs(v);if(k!==void 0)process.stderr.write(k);switch(a.name){case"init":{let y=i.str("dir"),S=i.str("user"),P=i.str("name"),U=i.str("purpose"),W=i.str("preset"),F=i.str("model"),I=i.str("base-url"),de=i.str("api-key-env"),oe=i.str("system"),ge=i.str("web"),z=i.str("web-backend"),V=i.str("composio"),Q=i.str("telegram"),re=i.str("telegram-allow"),he=i.str("server"),fe=i.str("schedules"),Ae=i.str("skills"),D=i.str("daemon");return await ts({...y===void 0?{}:{dir:y},...S===void 0?{}:{user:S},...P===void 0?{}:{name:P},...U===void 0?{}:{purpose:U},...W===void 0?{}:{preset:W},...F===void 0?{}:{model:F},...I===void 0?{}:{baseUrl:I},...de===void 0?{}:{apiKeyEnv:de},...oe===void 0?{}:{system:oe},...ge===void 0?{}:{web:ge},...z===void 0?{}:{webBackend:z},...V===void 0?{}:{composio:V},...Q===void 0?{}:{telegram:Q},...fe===void 0?{}:{schedules:fe},...re===void 0?{}:{telegramAllow:re},...he===void 0?{}:{server:he},...Ae===void 0?{}:{skills:Ae},...D===void 0?{}:{daemon:D},yes:i.bool("yes"),plain:i.bool("plain")})}case"run":{let y=i.str("session"),S=i.str("input"),P=i.str("store");return await Ut({...u[0]===void 0?{}:{manifestPath:h()},...y===void 0?{}:{sessionKey:y},continueSession:i.bool("continue"),...S===void 0?{}:{once:S},...P===void 0?{}:{store:P},ephemeral:i.bool("ephemeral"),quiet:i.bool("quiet"),showReasoning:i.bool("show-reasoning"),noReasoning:i.bool("no-reasoning"),...i.bool("no-enhanced-keys")?{noEnhancedKeys:!0}:{},plain:i.bool("plain")})}case"schedules":{let y=i.str("store"),S=i.str("id"),P=i.str("enable"),U=i.str("disable");return await io({manifestPath:h(),...y===void 0?{}:{store:y},...S===void 0?{}:{id:S},...P===void 0?{}:{enable:P},...U===void 0?{}:{disable:U},recipients:i.bool("recipients"),json:i.bool("json")})}case"sessions":{let y=i.str("session"),S=i.str("store"),P=i.num("limit");return await uo({manifestPath:h(),...y===void 0?{}:{sessionKey:y},...S===void 0?{}:{store:S},...P===void 0?{}:{limit:P},json:i.bool("json"),clear:i.bool("clear"),turns:i.bool("turns")})}case"memory":{let y=i.num("limit"),S=i.str("store");return await ws({action:f,manifestPath:te(u[1]??""),...u[2]===void 0?{}:{query:u[2]},...y===void 0?{}:{limit:y},...S===void 0?{}:{store:S},all:i.bool("all"),json:i.bool("json")})}case"config":{let{configCommand:y,readAction:S}=await import("./config-g7za9x13.js"),P=S(f,u[1]);return await y({action:P.action,...P.ref===void 0?{}:{ref:P.ref},...u[2]===void 0?{}:{name:u[2]},...u[3]===void 0?{}:{value:u[3]},...i.str("channel")===void 0?{}:{channel:i.str("channel")},remove:i.bool("remove"),yes:i.bool("yes"),...i.str("store")===void 0?{}:{store:i.str("store")}})}case"validate":return await vo({manifestPath:h(),json:i.bool("json")});case"workspace":return xo({manifestPath:h(),json:i.bool("json"),strict:i.bool("strict")});case"soul":{let y=i.str("out");return fo({action:f,file:u[1],...y===void 0?{}:{out:y}})}case"skills":{if(u.length===0)return await Gr({plain:i.bool("plain"),json:i.bool("json")});let y=u[2];return Se({action:f,manifestPath:te(u[1]??""),...y===void 0?{}:{name:y},json:i.bool("json"),strict:i.bool("strict")})}case"sources":{let y=i.str("path"),S=i.str("ref");return await mo({action:f,rest:u.slice(1),...y===void 0?{}:{path:y},...S===void 0?{}:{ref:S},json:i.bool("json")})}case"plugins":return await _s({manifestPath:te(u[0]??""),json:i.bool("json")});case"agents":return await Gt({manifestPaths:u.map((y)=>te(y)),json:i.bool("json")});case"serve":{let y=i.num("port"),S=i.str("host"),P=i.str("store");return await co({manifestPaths:u.map((U)=>te(U)),...y===void 0?{}:{port:y},...S===void 0?{}:{host:S},...P===void 0?{}:{store:P},claim:i.bool("claim"),json:i.bool("json")})}case"keys":return await ds({noEnhancedKeys:i.bool("no-enhanced-keys")});case"terminal-setup":return await go({dryRun:i.bool("dry-run"),yes:i.bool("yes"),json:i.bool("json"),confirm:Ye});case"remove":return await Ds({...f===void 0?{}:{ref:f},dryRun:i.bool("dry-run"),filesOnly:i.bool("files-only"),prune:i.bool("prune"),all:i.bool("all"),yes:i.bool("yes"),json:i.bool("json"),...i.str("store")===void 0?{}:{store:i.str("store")},confirm:Pr});case"stop":{let y=i.str("reason");return await Nn({...f===void 0?{}:{manifestPath:h()},dryRun:i.bool("dry-run"),...y===void 0?{}:{reason:y},...i.str("store")===void 0?{}:{store:i.str("store")},json:i.bool("json")})}case"start":return await po({manifestPath:h(),...i.str("store")===void 0?{}:{store:i.str("store")},json:i.bool("json")});case"web":{let{webCommand:y}=await import("./web-vkb16r62.js");return await y({action:f,...u[1]===void 0?{}:{manifestPath:te(u[1])},noOpen:i.bool("no-open"),...i.str("store")===void 0?{}:{store:i.str("store")},json:i.bool("json")})}case"credential":{let{credentialCommand:y}=await import("./credential-npr6z8c8.js");return await y({action:f??"",...u[1]===void 0?{}:{keyId:u[1]},...i.str("label")===void 0?{}:{label:i.str("label")},...i.str("agents")===void 0?{}:{agents:i.str("agents")},...i.str("sessions")===void 0?{}:{sessions:i.str("sessions")},...i.str("can")===void 0?{}:{can:i.str("can")},...i.str("expires")===void 0?{}:{expires:i.str("expires")},...i.str("store")===void 0?{}:{store:i.str("store")},json:i.bool("json")})}case"daemon":{let y=i.num("lines");return await Ze({action:f,...u[1]===void 0?{}:{manifestPath:te(u[1])},...y===void 0?{}:{lines:y},follow:i.bool("follow"),truncate:i.bool("truncate"),dryRun:i.bool("dry-run"),...i.str("store")===void 0?{}:{store:i.str("store")},json:i.bool("json")})}case"model":{let y=i.num("price");return await Os({manifestPath:te(u[1]),window:i.bool("window"),...y===void 0?{}:{price:y},write:i.bool("write"),yes:i.bool("yes"),json:i.bool("json")})}case"tools":return await yo({manifestPath:h(),warm:i.bool("warm"),json:i.bool("json")});default:throw new t({code:"cli_command_unwired",message:`Command "${a.name}" is declared but not wired up.`,hint:"Add a case for it in src/index.ts."})}}hs();Yr();await vd(process.argv.slice(2)).catch(wd).then((r)=>Dn(r));
|
|
529
529
|
|
|
530
|
-
//# debugId=
|
|
530
|
+
//# debugId=92EA07B9DCA0055664756E2164756E21
|
|
531
531
|
//# sourceMappingURL=index.js.map
|