@north-light/cli 0.3.701 → 0.3.703

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.
@@ -1 +1 @@
1
- var c=Object.defineProperty;var n=(t,e)=>c(t,"name",{value:e,configurable:!0});import{defineBranch as h,defineLeaf as l}from"../../core/command.js";import{mark as a}from"../../core/timing.js";function v(t){return l({name:"to",description:"attach an interactive terminal viewer to a node (reviving it if dormant)",whenToUse:"you want to WATCH or DRIVE a headless node live in this pane \u2014 it connects over the node's unix socket to the broker hosting the engine and renders the same chat stream. Attaches are writable by default, remote ones included (a remote canvas admits a writer only with message permission on the node); use --observer for read-only. A DORMANT node is revived first: crtrd runs reviveNode server-side, then the viewer streams over the broker's socket. The configured detach shortcuts leave the engine running",help:{name:`${t} attach to`,summary:"attach a terminal viewer to a headless node's running broker (writable by default, --observer for read-only); configured detach shortcuts leave the engine running",params:[{kind:"positional",name:"node",required:!0,constraint:"Node id to attach to. A dormant node is revived (server-side) before the viewer connects."},{kind:"flag",name:"observer",type:"bool",required:!1,default:!1,constraint:"Attach READ-ONLY: request the observer role (needs only read permission). Default attaches, local or --canvas, request the writable controller role."},{kind:"flag",name:"canvas",type:"string",required:!1,constraint:"Attach against a remote canvas target configured via `crtr canvas config add` instead of the local canvas \u2014 connects over a relayed WebSocket to the target's preview endpoint using the relay token from the 0600 secrets store. A remote attach is writable by default and needs message permission on the node; with read permission only, the attach is refused and --observer is required. Omit for local (default): connects to the node's local unix socket, which must already exist in THIS machine's canvas.db. Does NOT honor `crtr canvas use` \u2014 this flag is the only way to attach remotely."}],output:[{name:"note",type:"string",required:!1,constraint:"Only set on the non-TTY/piped path (a static notice); the interactive path returns nothing."}],outputKind:"object",effects:["Takes over the current pane in raw mode and renders the node's live engine stream until you use a configured detach shortcut or the broker exits.","As a writable controller: sends prompts/steers/dialog answers to the engine over the socket. As observer: read-only. Multiple writable viewers may drive the same broker.","A dormant node is revived server-side (crtrd runs reviveNode) before the viewer connects; this LOCAL process NEVER spawns pi and NEVER writes the session \u2014 it holds only a socket to the broker.","Outside a TTY (piped): prints a short notice and exits 0 \u2014 attach is an interactive program, not a pipe stage."]},run:n(async e=>{const r=e.node,o=e.observer??!1,s=e.canvas,i=process.env.CRTR_ATTACH_WAKE_PARKED!=="0";if(delete process.env.CRTR_ATTACH_WAKE_PARKED,!process.stdout.isTTY)return{note:`crtr surface attach is an interactive terminal viewer \u2014 run it in a tmux pane (a TTY), not a pipe. Node: ${r}`};a("viewer.bundle_import_start");const{runAttach:d}=await import("./viewer.js");a("viewer.bundle_loaded"),await d(r,o,s,i),process.exit(0)},"run"),render:n(e=>e.note!==void 0?String(e.note):"","render")})}n(v,"attachToLeaf");function w(t,e){return h({name:"attach",description:"a terminal viewer for a headless node \u2014 connect over its socket and drive (or watch) the live engine",whenToUse:"you want to open a headless node live in this pane \u2014 watch its engine stream and drive it by typing, without the node ever running pi in your window. A dormant node is revived server-side (crtrd runs reviveNode) before the viewer connects over a unix socket; this local process never starts the engine itself. Configured detach shortcuts leave the engine running.",tier:e,rootEntry:{concept:"a terminal viewer for a headless node \u2014 connect over its socket and drive (or watch) the live engine",desc:"attach a terminal viewer to a headless node",useWhen:"you want to open a headless node live in this pane \u2014 watch its engine stream and drive it by typing, without the node ever running pi in your window. A dormant node is revived server-side (crtrd runs reviveNode) before the viewer connects over a unix socket; this local process never starts the engine itself. Configured detach shortcuts leave the engine running."},help:{name:`${t} attach`,summary:"attach a terminal viewer to a headless node's running broker",model:`The branch opens a viewer in the current pane. A TTY is required; piped invocation prints a notice and exits. Attaches request the writable controller role, local or --canvas; --observer is read-only. Multiple writable viewers may watch and drive one broker. Configured detach shortcuts detach cleanly and the engine runs on. A dormant node is revived server-side (crtrd runs reviveNode) before the viewer connects. If the broker exits, the viewer holds the pane and auto-reconnects \u2014 through a yield/refresh relaunch, and across dormancy until the node wakes again \u2014 reporting "broker gone" and exiting only when the node is terminal (done/dead/canceled) or deleted. This local process NEVER spawns pi or writes the session \u2014 it holds only a socket to the broker. --canvas <name> is the escape hatch for a node hosted on a different machine's canvas \u2014 see the leaf's own -h.`},children:[v(t)]})}n(w,"registerAttach");export{w as registerAttach};
1
+ var c=Object.defineProperty;var n=(t,e)=>c(t,"name",{value:e,configurable:!0});import{defineBranch as h,defineLeaf as l}from"../../core/command.js";import{mark as a}from"../../core/timing.js";function v(t){return l({name:"to",description:"attach an interactive terminal viewer to a node (reviving it if dormant)",whenToUse:"you want to WATCH or DRIVE a headless node live in this pane \u2014 it connects over the node's unix socket to the broker hosting the engine and renders the same chat stream. Attaches are writable by default, remote ones included (a remote canvas admits a writer only with message permission on the node); use --observer for read-only. A DORMANT node is revived first: crtrd runs reviveNode server-side, then the viewer streams over the broker's socket. The configured detach shortcuts leave the engine running",help:{name:`${t} attach to`,summary:"attach a terminal viewer to a headless node's running broker (writable by default, --observer for read-only); configured detach shortcuts leave the engine running",params:[{kind:"positional",name:"node",required:!0,constraint:"Node id to attach to. A dormant node is revived (server-side) before the viewer connects."},{kind:"flag",name:"observer",type:"bool",required:!1,default:!1,constraint:"Attach READ-ONLY: request the observer role (needs only read permission). Default attaches, local or --canvas, request the writable controller role."},{kind:"flag",name:"canvas",type:"string",required:!1,constraint:"Attach against a remote canvas target configured via `crtr canvas config add` instead of the local canvas \u2014 connects over a relayed WebSocket to the target's preview endpoint using the relay token from the 0600 secrets store. A remote attach is writable by default and needs message permission on the node; with read permission only, the attach is refused and --observer is required. Omit for local (default): connects to the node's local unix socket, which must already exist in THIS machine's canvas.db. Does NOT honor `crtr canvas use` \u2014 this flag is the only way to attach remotely."}],output:[{name:"note",type:"string",required:!1,constraint:"Only set on the non-TTY/piped path (a static notice); the interactive path returns nothing."}],outputKind:"object",effects:["Takes over the current pane in raw mode and renders the node's live engine stream until you use a configured detach shortcut or the broker exits.","As a writable controller: sends prompts/steers/dialog answers to the engine over the socket. As observer: read-only. Multiple writable viewers may drive the same broker.","A dormant node is revived server-side (crtrd runs reviveNode) before the viewer connects; this LOCAL process NEVER spawns pi and NEVER writes the session \u2014 it holds only a socket to the broker.","Outside a TTY (piped): prints a short notice and exits 0 \u2014 attach is an interactive program, not a pipe stage."]},run:n(async e=>{const r=e.node,o=e.observer??!1,s=e.canvas,i=process.env.CRTR_ATTACH_WAKE_PARKED!=="0";if(delete process.env.CRTR_ATTACH_WAKE_PARKED,!process.stdout.isTTY)return{note:`crtr surface attach is an interactive terminal viewer \u2014 run it in a tmux pane (a TTY), not a pipe. Node: ${r}`};a("viewer.bundle_import_start");const{runAttach:d}=await import("./viewer.js");a("viewer.bundle_loaded"),await d(r,o,s,i),process.exit(process.exitCode??0)},"run"),render:n(e=>e.note!==void 0?String(e.note):"","render")})}n(v,"attachToLeaf");function w(t,e){return h({name:"attach",description:"a terminal viewer for a headless node \u2014 connect over its socket and drive (or watch) the live engine",whenToUse:"you want to open a headless node live in this pane \u2014 watch its engine stream and drive it by typing, without the node ever running pi in your window. A dormant node is revived server-side (crtrd runs reviveNode) before the viewer connects over a unix socket; this local process never starts the engine itself. Configured detach shortcuts leave the engine running.",tier:e,rootEntry:{concept:"a terminal viewer for a headless node \u2014 connect over its socket and drive (or watch) the live engine",desc:"attach a terminal viewer to a headless node",useWhen:"you want to open a headless node live in this pane \u2014 watch its engine stream and drive it by typing, without the node ever running pi in your window. A dormant node is revived server-side (crtrd runs reviveNode) before the viewer connects over a unix socket; this local process never starts the engine itself. Configured detach shortcuts leave the engine running."},help:{name:`${t} attach`,summary:"attach a terminal viewer to a headless node's running broker",model:`The branch opens a viewer in the current pane. A TTY is required; piped invocation prints a notice and exits. Attaches request the writable controller role, local or --canvas; --observer is read-only. Multiple writable viewers may watch and drive one broker. Configured detach shortcuts detach cleanly and the engine runs on. A dormant node is revived server-side (crtrd runs reviveNode) before the viewer connects. If the broker exits, the viewer holds the pane and auto-reconnects \u2014 through a yield/refresh relaunch, and across dormancy until the node wakes again \u2014 reporting "broker gone" and exiting only when the node is terminal (done/dead/canceled) or deleted. This local process NEVER spawns pi or writes the session \u2014 it holds only a socket to the broker. --canvas <name> is the escape hatch for a node hosted on a different machine's canvas \u2014 see the leaf's own -h.`},children:[v(t)]})}n(w,"registerAttach");export{w as registerAttach};
@@ -1,4 +1,4 @@
1
- import type { BrokerSnapshot, BrokerToClient, ClientRole } from '../../../core/runtime/broker-protocol.js';
1
+ import type { BrokerSnapshot, ClientRole } from '../../../core/runtime/broker-protocol.js';
2
2
  import type { CanvasSource } from '../../../core/canvas/source.js';
3
3
  import type { NodeDetailDTO } from '../../../api/dto/nodes.js';
4
4
  import type { NodeMeta } from '../../../core/canvas/types.js';
@@ -33,32 +33,21 @@ export interface AttachConnection {
33
33
  /** The attached node's persona/lifecycle, when this canvas can tell us —
34
34
  * `undefined` for a remote attach until the viewer refetches it. */
35
35
  readonly nodeIdentity: Pick<NodeMeta, 'kind' | 'mode' | 'lifecycle' | 'icon'> | undefined;
36
- /** The one socket target for the node's headless broker. It is intentionally
37
- * disconnected only when focus opened an exact parked resident offline. */
36
+ /** The one socket to the node's headless broker. Not connected until `dial()` settles. */
38
37
  readonly socket: BrokerClient;
39
- /** Saved snapshot used to seed an offline parked viewer. Absent for direct
40
- * attach and for focus paths whose broker was live or legitimately woke. */
41
- readonly initialSnapshot?: BrokerSnapshot;
42
- /** Frames the broker sent from its `welcome` on, received before the viewer's handlers existed. Empty when no `hello` was sent during the connect. */
43
- readonly earlyFrames: BrokerToClient[];
44
- /** Stop collecting and hand over every frame collected so far, once. */
45
- takeEarlyFrames(): BrokerToClient[];
46
- readonly initialCommands?: ReadonlyArray<{
38
+ /** Revive the node if it is dormant (server-side) and connect `socket`, resolving once the transport is open. It does not send `hello`. Rejects with a plain `InputError`.
39
+ * Resolves with the node's saved snapshot when the node is parked and was deliberately not woken: no socket was opened, and the viewer shows that snapshot offline. */
40
+ dial(): Promise<ParkedSnapshot | undefined>;
41
+ }
42
+ /** A parked node's saved snapshot and command inventory, shown by an offline viewer. */
43
+ export interface ParkedSnapshot {
44
+ readonly snapshot: BrokerSnapshot;
45
+ readonly commands: ReadonlyArray<{
47
46
  name: string;
48
47
  description: string;
49
48
  source: string;
50
- }>;
51
- /** Re-throw a connect-adjacent failure that landed AFTER `connect` resolved.
52
- * Call once, synchronously, just before permanent socket wiring takes over;
53
- * a no-op if nothing failed. See the never-removed error listener below. */
54
- assertConnected(): void;
49
+ }> | undefined;
55
50
  }
56
- /** Resolve the target, revive the node if it is dormant (server-side), and dial
57
- * the broker. Rejects with a plain `InputError` — no terminal has been taken
58
- * over at this point, so a failure here is an ordinary non-zero CLI exit. */
59
- export declare function connectToNode(nodeId: string, canvasName?: string, wakeParked?: boolean, known?: NodeDetailDTO,
60
- /** The viewer's identity for the `hello` sent right after the connect. A live attach stays on the caller's screen until the broker's `welcome` answers it. */
61
- hello?: {
62
- role: 'controller' | 'observer';
63
- clientId: string;
64
- }): Promise<AttachConnection>;
51
+ /** Resolve the attach target and build the not-yet-connected socket. Rejects with
52
+ * a plain `InputError` for an unknown node — no terminal has been taken over yet. */
53
+ export declare function connectToNode(nodeId: string, canvasName?: string, wakeParked?: boolean, known?: NodeDetailDTO): Promise<AttachConnection>;
@@ -1 +1 @@
1
- var M=Object.defineProperty;var r=(e,s)=>M(e,"name",{value:s,configurable:!0});import{createConnection as B}from"node:net";import{apiSocketPath as $,viewSocketPath as z}from"../../../core/canvas/paths.js";import{BrokerClient as H,BrokerUnavailableError as F,RelayTransport as T}from"../../../core/broker-client/index.js";import{resolveRemoteCanvasTarget as D}from"../../../core/remote-canvas-target.js";import{ApiCanvasSource as U,cliCanvasSource as W,cliClient as _,rethrowAsCliError as x}from"../../../commands/api-client.js";import{InputError as R,apiErrorToCliError as L}from"../../../core/io.js";import{ApiError as V}from"../../../api/index.js";import{readMachineConfig as q}from"../../../daemon/machine-link/config.js";import{personBearer as P}from"../../../core/directory/person-credential.js";const G=15e3;async function J(e,s){let a=await P(s);return setInterval(()=>{P(s).then(l=>{a=l},()=>{})},G).unref(),{previewEndpoint:e,get relayToken(){return a}}}r(J,"machineRelayTarget");function re(e){return e?"observer":"controller"}r(re,"resolveHelloRole");async function K(e){const s=Number(process.env.CRTR_ATTACH_WAIT_MS??"");if(!Number.isFinite(s)||s<=0)return;const a=z(e),g=Date.now()+s;for(;Date.now()<g;){if(await new Promise(u=>{const c=B(a),d=r(h=>{c.destroy(),u(h)},"settle");c.once("connect",()=>d(!0)),c.once("error",()=>d(!1))}))return;await new Promise(u=>setTimeout(u,100))}}r(K,"preWaitForViewSocket");async function oe(e,s,a=!0,g,l){const u=s!==void 0,c=u?void 0:q(),d=s!==void 0?W({canvasName:s}):new U;let h,A,b,f,k;if(s!==void 0)h={cwd:process.cwd()},b=new T(e,D(s));else{const t=g??await d.getNode(e);if(t===null)throw new R({error:"not_found",message:`no node: ${e}`,received:e,next:"List nodes with `crtr node inspect list`."});if(h=t,A=t,c!==void 0)b=new T(e,await J(c.apiUrl,c.directoryUrl),a);else{try{if((await _().ensureAttach(e,{resume:!0,revive:!0,wakeParked:a})).parked){const i=await _().getSnapshot(e);f=i.snapshot,k=i.commands}}catch(n){x(n,"The node may be finalized or otherwise not attachable.")}f===void 0&&await K(e),b=new T(e,{socketPath:$()})}}const o=new H(e,{transport:b}),v=[];let C;const S=r(t=>{const n=t?.refusal;return n!==void 0?L(new V(n.status,n.code,n.message),"The node may be finalized or otherwise not attachable."):t instanceof F?new R({error:"no_broker",message:t.message,received:e,next:"Focus or revive the node first \u2014 attach needs a running headless broker."}):new R({error:"socket_error",message:`could not attach to node ${e}: ${String(t?.message??t)}`,received:e,next:"Check the node has a running headless broker."})},"toAttachError");let E;return o.on("error",t=>{E===void 0&&(E=t)}),f===void 0&&(await new Promise(async(t,n)=>{const i=r(()=>{p(),t()},"onConnect"),w=r(y=>{p(),n(y)},"onErr"),p=r(()=>{o.off("connect",i),o.off("error",w)},"cleanup");o.on("connect",i),o.on("error",w),o.connect()}).catch(async t=>{if(c!==void 0&&!a&&String(t?.message).includes("node_dormant")){const n=await _().getSnapshot(e).catch(i=>x(i,"The node may be finalized or otherwise not attachable."));f=n.snapshot,k=n.commands;return}throw S(t)}),l!==void 0&&await new Promise((t,n)=>{const i=r(m=>{v.push(m),m.type==="welcome"&&(y(),t())},"onFrame"),w=r(()=>{y(),n(new F(e,`the broker of node ${e} closed before its session was ready; it did not start`))},"onClose"),p=r(m=>{y(),n(m)},"onErr"),y=r(()=>{o.off("error",p),o.off("close",w),v.some(m=>m.type==="welcome")||o.off("frame",i)},"cleanup");C=i,o.on("frame",i),o.on("close",w),o.on("error",p),o.send({type:"hello",role:l.role,client_id:l.clientId,term:{cols:process.stdout.columns??80,rows:process.stdout.rows??24}})}).catch(t=>{throw S(t)})),{remote:u,canvasSource:d,meta:h,nodeIdentity:A,socket:o,...f===void 0?{}:{initialSnapshot:f,initialCommands:k},earlyFrames:v,takeEarlyFrames:r(()=>(C!==void 0&&o.off("frame",C),C=void 0,v.splice(0)),"takeEarlyFrames"),assertConnected:r(()=>{if(f===void 0&&E!==void 0)throw S(E)},"assertConnected")}}r(oe,"connectToNode");export{oe as connectToNode,J as machineRelayTarget,K as preWaitForViewSocket,re as resolveHelloRole};
1
+ var _=Object.defineProperty;var n=(e,r)=>_(e,"name",{value:r,configurable:!0});import{createConnection as R}from"node:net";import{apiSocketPath as A,viewSocketPath as x}from"../../../core/canvas/paths.js";import{BrokerClient as M,BrokerUnavailableError as P,RelayTransport as p}from"../../../core/broker-client/index.js";import{resolveRemoteCanvasTarget as B}from"../../../core/remote-canvas-target.js";import{ApiCanvasSource as F,cliCanvasSource as z,cliClient as k,rethrowAsCliError as y}from"../../../commands/api-client.js";import{InputError as w,apiErrorToCliError as H}from"../../../core/io.js";import{ApiError as $}from"../../../api/index.js";import{readMachineConfig as D}from"../../../daemon/machine-link/config.js";import{personBearer as T}from"../../../core/directory/person-credential.js";import{mark as U}from"../../../core/timing.js";const W=15e3;async function L(e,r){let a=await T(r);return setInterval(()=>{T(r).then(u=>{a=u},()=>{})},W).unref(),{previewEndpoint:e,get relayToken(){return a}}}n(L,"machineRelayTarget");function ee(e){return e?"observer":"controller"}n(ee,"resolveHelloRole");async function V(e){const r=Number(process.env.CRTR_ATTACH_WAIT_MS??"");if(!Number.isFinite(r)||r<=0)return;const a=x(e),f=Date.now()+r;for(;Date.now()<f;){if(await new Promise(o=>{const s=R(a),c=n(m=>{s.destroy(),o(m)},"settle");s.once("connect",()=>c(!0)),s.once("error",()=>c(!1))}))return;await new Promise(o=>setTimeout(o,100))}}n(V,"preWaitForViewSocket");async function te(e,r,a=!0,f){const u=r!==void 0,o=u?void 0:D(),s=r!==void 0?z({canvasName:r}):new F;let c,m,h;if(r!==void 0)c={cwd:process.cwd()},h=new p(e,B(r));else{const t=f??await s.getNode(e);if(t===null)throw new w({error:"not_found",message:`no node: ${e}`,received:e,next:"List nodes with `crtr node inspect list`."});c=t,m=t,o!==void 0?h=new p(e,await L(o.apiUrl,o.directoryUrl),a):h=new p(e,{socketPath:A()})}const l=new M(e,{transport:h}),C=r===void 0&&o===void 0,E=n(t=>{const i=t?.refusal;return i!==void 0?H(new $(i.status,i.code,i.message),"The node may be finalized or otherwise not attachable."):t instanceof P?new w({error:"no_broker",message:t.message,received:e,next:"Focus or revive the node first \u2014 attach needs a running headless broker."}):new w({error:"socket_error",message:`could not attach to node ${e}: ${String(t?.message??t)}`,received:e,next:"Check the node has a running headless broker."})},"toAttachError"),d=n(async()=>{const t=await k().getSnapshot(e);return{snapshot:t.snapshot,commands:t.commands}},"parkedSnapshot");return{remote:u,canvasSource:s,meta:c,nodeIdentity:m,socket:l,dial:n(async()=>{if(C){try{if((await k().ensureAttach(e,{resume:!0,revive:!0,wakeParked:a})).parked)return await d()}catch(t){y(t,"The node may be finalized or otherwise not attachable.")}await V(e)}try{await new Promise((t,i)=>{const g=n(()=>{b(),t()},"onConnect"),v=n(S=>{b(),i(S)},"onErr"),b=n(()=>{l.off("connect",g),l.off("error",v)},"cleanup");l.on("connect",g),l.on("error",v),l.connect()})}catch(t){if(o!==void 0&&!a&&String(t?.message).includes("node_dormant"))return await d().catch(i=>y(i,"The node may be finalized or otherwise not attachable."));throw E(t)}U("viewer.transport_open")},"dial")}}n(te,"connectToNode");export{te as connectToNode,L as machineRelayTarget,V as preWaitForViewSocket,ee as resolveHelloRole};
@@ -4,6 +4,7 @@ import { type ViewerCapabilities } from '../input/capabilities.js';
4
4
  import type { VerbosityChange } from '../render/chat-view.js';
5
5
  import type { KeybindingsManager } from '@earendil-works/pi-tui';
6
6
  import type { CopyTarget } from '../render/transcript-copy.js';
7
+ import type { ClientToBroker } from '../../../core/runtime/broker-protocol.js';
7
8
  import type { AttachSession } from './context.js';
8
9
  /** What the input layer needs from the rest of the session. Everything here is
9
10
  * a getter or a command — never a value — so nothing can go stale. */
@@ -42,6 +43,8 @@ export interface InputWiringHooks {
42
43
  onPromptSent: () => void;
43
44
  /** A new message left the editor; show it pending until echoed. */
44
45
  onMessageSent: (text: string) => void;
46
+ /** Send a frame to the broker; before the broker's first welcome the viewer holds it. */
47
+ send: (frame: ClientToBroker) => void;
45
48
  /** Per-user completion frecency store, shared with the editor inventory. */
46
49
  frecency: FrecencyStore;
47
50
  }
@@ -1 +1 @@
1
- var D=Object.defineProperty;var e=(n,a)=>D(n,"name",{value:a,configurable:!0});import{InputController as b}from"../input/controller.js";import{createViewerCapabilities as I}from"../input/capabilities.js";import{VERBOSITY_LABELS as C}from"../../../core/user-settings.js";import{VERBOSITY_LEVELS as m}from"../../../types.js";import{cliClient as M}from"../../../commands/api-client.js";import{buildLoginPicker as T,buildLogoutPicker as v}from"../overlays/auth.js";import{defaultAgentDir as w}from"../config.js";function q(n,a){return I({nodeId:n.nodeId,profileId:n.meta.profile_id??void 0,remote:n.remote,role:n.role,isBrokerOffline:a})}e(q,"createViewerCapabilitiesForInput");function u({level:n}){return`Verbosity: ${C[n]} (${m.indexOf(n)+1}/${m.length})`}e(u,"verbosityName");function S(n){return n.atEnd?`${u(n)} \u2014 Ctrl+O again goes back to ${C[m[0]]}`:`${u(n)} \u2014 Ctrl+O shows more`}e(S,"moreDetailNotice");function E(n){return n.atEnd?`${u(n)}, the most collapsed level \u2014 Ctrl+O shows more`:`${u(n)} \u2014 Ctrl+O shows more`}e(E,"lessDetailNotice");function A(n,a,d,t){const{nodeId:y,socket:s,tui:l,editor:p,containers:g}=n,{setNotice:i}=t,f=e(()=>s.send({type:"reload_auth"}),"reloadAuth"),P=d.permits("auth")?{openLoginPicker:e(()=>{const o=t.agentDir()??w();c.openAuthPicker(()=>T(l,o,f,r=>i(r)))},"openLoginPicker"),openLogoutPicker:e(()=>{const o=t.agentDir()??w();c.openAuthPicker(()=>v(o,f,r=>i(r)))},"openLogoutPicker")}:{},c=new b(l,p,a,{onCommand:e(o=>s.send(o),"onCommand"),onDialogResponse:e(o=>s.send(o),"onDialogResponse"),onNotice:e(o=>i(o),"onNotice"),onGraph:t.toggleGraph,onInbox:t.toggleInbox,onHelp:t.toggleHelp,onNodeMetadata:t.openNodeMetadata,onQuit:t.quit,onCopy:e(()=>t.copyTarget("last-assistant"),"onCopy"),onCopyTarget:t.copyTarget,onToggleMouse:e(()=>{const o=t.toggleMouse();i(o?"Mouse: wheel scrolling on, drag to select and copy":"Mouse: off \u2014 tmux drag-select and copy-mode restored")},"onToggleMouse"),onColor:t.setChipColor,onPromptSent:t.onPromptSent,onMessageSent:t.onMessageSent,frecency:t.frecency,knownRefNames:e(()=>p.getResolvedRefNames(),"knownRefNames"),onMoreDetail:e(()=>i(S(t.moreDetail())),"onMoreDetail"),onLessDetail:e(()=>i(E(t.lessDetail())),"onLessDetail"),onToggleThinking:e(()=>i(t.toggleThinking()?"Thinking blocks: hidden":"Thinking blocks: visible"),"onToggleThinking"),onRequest:e(o=>{const r=d.refusal("engine-drive");return r===void 0?s.request(o):Promise.reject(new Error(r))},"onRequest"),onMountPicker:e(o=>{g.pickerPanel.addChild(o),l.requestRender()},"onMountPicker"),onUnmountPicker:e(()=>{g.pickerPanel.clear(),l.requestRender()},"onUnmountPicker"),isDormant:t.isDormant,onDormantSubmit:d.permits("wake-dormant")?o=>{(async()=>{try{const r=await M().sendMessage(y,{body:o,from:"human"});i(r.revived?"\u21BB waking node\u2026":"\u2709 delivered \u2014 node reads on next wake")}catch(r){i(`Couldn't wake node: ${r instanceof Error?r.message:String(r)}`)}})()}:void 0,...P},d);return c}e(A,"createInputController");export{A as createInputController,q as createViewerCapabilitiesForInput,E as lessDetailNotice,S as moreDetailNotice};
1
+ var D=Object.defineProperty;var t=(n,a)=>D(n,"name",{value:a,configurable:!0});import{InputController as b}from"../input/controller.js";import{createViewerCapabilities as I}from"../input/capabilities.js";import{VERBOSITY_LABELS as f}from"../../../core/user-settings.js";import{VERBOSITY_LEVELS as c}from"../../../types.js";import{cliClient as M}from"../../../commands/api-client.js";import{buildLoginPicker as T,buildLogoutPicker as v}from"../overlays/auth.js";import{defaultAgentDir as C}from"../config.js";function A(n,a){return I({nodeId:n.nodeId,profileId:n.meta.profile_id??void 0,remote:n.remote,role:n.role,isBrokerOffline:a})}t(A,"createViewerCapabilitiesForInput");function s({level:n}){return`Verbosity: ${f[n]} (${c.indexOf(n)+1}/${c.length})`}t(s,"verbosityName");function S(n){return n.atEnd?`${s(n)} \u2014 Ctrl+O again goes back to ${f[c[0]]}`:`${s(n)} \u2014 Ctrl+O shows more`}t(S,"moreDetailNotice");function E(n){return n.atEnd?`${s(n)}, the most collapsed level \u2014 Ctrl+O shows more`:`${s(n)} \u2014 Ctrl+O shows more`}t(E,"lessDetailNotice");function _(n,a,d,e){const{nodeId:w,socket:y,tui:l,editor:m,containers:p}=n,{setNotice:i}=e,g=t(()=>e.send({type:"reload_auth"}),"reloadAuth"),P=d.permits("auth")?{openLoginPicker:t(()=>{const r=e.agentDir()??C();u.openAuthPicker(()=>T(l,r,g,o=>i(o)))},"openLoginPicker"),openLogoutPicker:t(()=>{const r=e.agentDir()??C();u.openAuthPicker(()=>v(r,g,o=>i(o)))},"openLogoutPicker")}:{},u=new b(l,m,a,{onCommand:e.send,onDialogResponse:e.send,onNotice:t(r=>i(r),"onNotice"),onGraph:e.toggleGraph,onInbox:e.toggleInbox,onHelp:e.toggleHelp,onNodeMetadata:e.openNodeMetadata,onQuit:e.quit,onCopy:t(()=>e.copyTarget("last-assistant"),"onCopy"),onCopyTarget:e.copyTarget,onToggleMouse:t(()=>{const r=e.toggleMouse();i(r?"Mouse: wheel scrolling on, drag to select and copy":"Mouse: off \u2014 tmux drag-select and copy-mode restored")},"onToggleMouse"),onColor:e.setChipColor,onPromptSent:e.onPromptSent,onMessageSent:e.onMessageSent,frecency:e.frecency,knownRefNames:t(()=>m.getResolvedRefNames(),"knownRefNames"),onMoreDetail:t(()=>i(S(e.moreDetail())),"onMoreDetail"),onLessDetail:t(()=>i(E(e.lessDetail())),"onLessDetail"),onToggleThinking:t(()=>i(e.toggleThinking()?"Thinking blocks: hidden":"Thinking blocks: visible"),"onToggleThinking"),onRequest:t(r=>{const o=d.refusal("engine-drive");return o===void 0?y.request(r):Promise.reject(new Error(o))},"onRequest"),onMountPicker:t(r=>{p.pickerPanel.addChild(r),l.requestRender()},"onMountPicker"),onUnmountPicker:t(()=>{p.pickerPanel.clear(),l.requestRender()},"onUnmountPicker"),isDormant:e.isDormant,onDormantSubmit:d.permits("wake-dormant")?r=>{(async()=>{try{const o=await M().sendMessage(w,{body:r,from:"human"});i(o.revived?"\u21BB waking node\u2026":"\u2709 delivered \u2014 node reads on next wake")}catch(o){i(`Couldn't wake node: ${o instanceof Error?o.message:String(o)}`)}})()}:void 0,...P},d);return u}t(_,"createInputController");export{_ as createInputController,A as createViewerCapabilitiesForInput,E as lessDetailNotice,S as moreDetailNotice};
@@ -18,9 +18,6 @@ export interface ReconnectHooks {
18
18
  /** End the session. `node-done` is a clean finalize (the node pushed its
19
19
  * final report) and closes the pane; `broker-gone` freezes the corpse. */
20
20
  teardown: (reason: 'node-done' | 'broker-gone') => void;
21
- /** The viewer was bootstrapped from a saved parked snapshot before any socket
22
- * connection. */
23
- initialDormant?: boolean;
24
21
  /** Called once each time the node is first seen as dormant. A stopped broker
25
22
  * will relay no final session event, so the viewer clears live-only display. */
26
23
  onEnterDormancy: () => void;
@@ -1 +1 @@
1
- var b=Object.defineProperty;var n=(f,e)=>b(f,"name",{value:e,configurable:!0});import{AttachRefusedError as A,reconnectShouldGiveUp as C}from"../../../core/broker-client/index.js";const P=1e3,I=3e3;function x(f,e){const{nodeId:p,socket:s,canvasSource:T}=f;let u,l=!1,c=e.initialDormant===!0,y=!1,o=!1,D=n(()=>{},"resolveStopped"),d,m;const R=new Promise(r=>{D=r}),_=n(r=>o?Promise.resolve(!1):new Promise(t=>{const i=n(a=>{d=void 0,m=void 0,t(a)},"settle");d=setTimeout(()=>i(!0),r),m=n(()=>{d!==void 0&&clearTimeout(d),i(!1)},"cancelRetry")}),"waitForRetry");let E=!1,w=!1;const g=n(()=>{w=!1,s.send({type:"hello",role:e.role,client_id:e.clientId,term:{cols:process.stdout.columns??80,rows:process.stdout.rows??24}})},"sendHello"),v=n(async()=>{l=!0,e.setNotice("\u21BB node refreshing \u2014 reconnecting\u2026",{sticky:!0});let r=200;try{for(;!o&&!e.isTornDown();){let t;try{t=await T.getRow(p)}catch{t=void 0}if(t!==void 0&&C(t)){y=t!==null;break}const i=t?.status==="dead"||t?.status==="canceled",a=t?.status==="idle"||t?.intent==="idle-release"||t?.status==="done",N=a&&!c;c=a,N&&e.onEnterDormancy(),e.setNotice(i?`node is ${t?.status} \u2014 waiting for a revive`:a?"":"\u21BB node refreshing \u2014 reconnecting\u2026",{sticky:!a});try{if(!await Promise.race([s.redial({brokerUnavailableIsExpected:a||i}).then(()=>!0),R.then(()=>!1)])||o||e.isTornDown())return;g(),c=!1,e.setNotice("");return}catch{if(!await _(a||i?I:Math.min(r,P)))return;r*=2}}}finally{l=!1}!o&&!e.isTornDown()&&e.teardown(y?"node-done":"broker-gone")},"attemptReconnect");return{sendHello:g,startDormant:n(()=>{l||o||e.isTornDown()||(e.onEnterDormancy(),v())},"startDormant"),isDormant:n(()=>c,"isDormant"),lastSocketError:n(()=>u,"lastSocketError"),install:n(async()=>{s.on("frame",r=>{r.type==="welcome"&&(E=!0),e.onFrame(r)}),s.on("error",r=>{u=r.message,r instanceof A&&(w=!0)}),s.on("close",()=>{if(!e.isTornDown()&&!l){if(e.remote&&e.role==="controller"&&w&&!E){u=`the remote canvas refused the attach to ${p}. A writable attach needs message permission on the node; with read permission only, attach with --observer.`,e.teardown("broker-gone");return}v()}})},"install"),stop:n(()=>{o||(o=!0,m?.(),D())},"stop")}}n(x,"createReconnect");export{x as createReconnect};
1
+ var C=Object.defineProperty;var n=(u,e)=>C(u,"name",{value:e,configurable:!0});import{AttachRefusedError as P,reconnectShouldGiveUp as I}from"../../../core/broker-client/index.js";const M=1e3,O=3e3;function L(u,e){const{nodeId:D,socket:s,canvasSource:_}=u;let m,d=!1,i=!1,E=!1,a=!1,g=n(()=>{},"resolveStopped"),f,w;const N=new Promise(r=>{g=r}),S=n(r=>a?Promise.resolve(!1):new Promise(l=>{const c=n(t=>{f=void 0,w=void 0,l(t)},"settle");f=setTimeout(()=>c(!0),r),w=n(()=>{f!==void 0&&clearTimeout(f),c(!1)},"cancelRetry")}),"waitForRetry");let v=!1,p=!1;const T=n(()=>{p=!1,s.send({type:"hello",role:e.role,client_id:e.clientId,term:{cols:process.stdout.columns??80,rows:process.stdout.rows??24}})},"sendHello"),R=n(async(r=!1)=>{d=!0;let l=!r;l&&e.setNotice("\u21BB node refreshing \u2014 reconnecting\u2026",{sticky:!0});let c=200;try{for(;!a&&!e.isTornDown();){let t;try{t=await _.getRow(D)}catch{t=void 0}if(t!==void 0&&I(t)){E=t!==null;break}const y=t?.status==="dead"||t?.status==="canceled",o=t?.status==="idle"||t?.intent==="idle-release"||t?.status==="done",b=o&&!i;i=o,b&&e.onEnterDormancy(),(l||!o)&&(e.setNotice(y?`node is ${t?.status} \u2014 waiting for a revive`:o?"":"\u21BB node refreshing \u2014 reconnecting\u2026",{sticky:!o}),l=!o);try{if(!await Promise.race([s.redial({brokerUnavailableIsExpected:o||y}).then(()=>!0),N.then(()=>!1)])||a||e.isTornDown())return;T(),i=!1,e.setNotice("");return}catch{if(!await S(o||y?O:Math.min(c,M)))return;c*=2}}}finally{d=!1}!a&&!e.isTornDown()&&e.teardown(E?"node-done":"broker-gone")},"attemptReconnect");return{sendHello:T,startDormant:n(()=>{d||a||e.isTornDown()||(i=!0,e.onEnterDormancy(),R(!0))},"startDormant"),isDormant:n(()=>i,"isDormant"),lastSocketError:n(()=>m,"lastSocketError"),install:n(async()=>{s.on("frame",r=>{r.type==="welcome"&&(v=!0),e.onFrame(r)}),s.on("error",r=>{m=r.message,r instanceof P&&(p=!0)}),s.on("close",()=>{if(!e.isTornDown()&&!d){if(e.remote&&e.role==="controller"&&p&&!v){m=`the remote canvas refused the attach to ${D}. A writable attach needs message permission on the node; with read permission only, attach with --observer.`,e.teardown("broker-gone");return}R()}})},"install"),stop:n(()=>{a||(a=!0,w?.(),g())},"stop")}}n(L,"createReconnect");export{L as createReconnect};
@@ -17,6 +17,8 @@ export interface TeardownHooks {
17
17
  /** This viewer's tmux pane, as self-tagged at startup. Used only by the
18
18
  * node-done path to close our own pane. */
19
19
  tagPane: () => string | undefined;
20
+ /** Text the person entered that the broker never received (held frames and the unsent draft before the first welcome); empty once delivered. Printed on every exit. */
21
+ undelivered: () => string[];
20
22
  }
21
23
  export interface AttachTeardown {
22
24
  /** Resolves when the session has ended — `runAttach` awaits this. */
@@ -1,6 +1,11 @@
1
- var g=Object.defineProperty;var n=(o,t)=>g(o,"name",{value:t,configurable:!0});import{closePane as w,currentTmux as S,inTmux as T}from"../../../core/runtime/placement-tmux.js";import{FOCUS_REPORTING_OFF as I}from"./focus-events.js";function G(o,t){const{tui:f,socket:c,nodeId:i,remote:u}=o;let a=!1;const d=n(()=>{if(!a){a=!0;try{process.stdout.write(I),f.stop()}catch{}}},"restore");process.once("exit",d);let s=!1,l;const m=new Promise(e=>{l=e}),p=n(e=>{if(!s){if(s=!0,t.stopLocal(),e==="detach"&&c.send({type:"bye"}),c.close(),d(),e==="broker-gone"){const r=t.lastSocketError()??`broker gone \u2014 node ${i} is no longer running its engine.`;process.stderr.write(`
1
+ var w=Object.defineProperty;var t=(o,n)=>w(o,"name",{value:n,configurable:!0});import{closePane as S,currentTmux as T,inTmux as I}from"../../../core/runtime/placement-tmux.js";import{FOCUS_REPORTING_OFF as P}from"./focus-events.js";function E(o,n){const{tui:f,socket:i,nodeId:c,remote:g}=o;let d=!1;const a=t(()=>{if(!d){d=!0;try{process.stdout.write(P),f.stop()}catch{}}},"restore");process.once("exit",a);let s=!1,l;const m=new Promise(e=>{l=e}),p=t(e=>{if(s)return;if(s=!0,n.stopLocal(),e==="detach"&&i.send({type:"bye"}),i.close(),a(),e==="broker-gone"){const r=n.lastSocketError()??`broker gone \u2014 node ${c} is no longer running its engine.`;process.stderr.write(`
2
2
  ${r}
3
- Reattach with: ${t.reattachCommand}
4
- `)}if(e==="node-done"){process.stderr.write(`
5
- \u2713 node ${i} finished \u2014 final report submitted.
6
- `);const r=t.tagPane()??process.env.TMUX_PANE??S()?.pane;!u&&r!==void 0&&T()&&w(r)}l()}},"teardown");return{done:m,teardown:p,isTornDown:n(()=>s,"isTornDown"),installSignalHandlers:n(()=>{const e=n(()=>p("signal"),"onSignal");process.once("SIGTERM",e),process.once("SIGHUP",e),process.once("SIGINT",e)},"installSignalHandlers")}}n(G,"createTeardown");export{G as createTeardown};
3
+ Reattach with: ${n.reattachCommand}
4
+ `)}const u=n.undelivered();if(u.length>0&&process.stderr.write(`
5
+ Not delivered:
6
+ ${u.join(`
7
+ ---
8
+ `)}
9
+ `),e==="node-done"){process.stderr.write(`
10
+ \u2713 node ${c} finished \u2014 final report submitted.
11
+ `);const r=n.tagPane()??process.env.TMUX_PANE??T()?.pane;!g&&r!==void 0&&I()&&S(r)}l()},"teardown");return{done:m,teardown:p,isTornDown:t(()=>s,"isTornDown"),installSignalHandlers:t(()=>{const e=t(()=>p("signal"),"onSignal");process.once("SIGTERM",e),process.once("SIGHUP",e),process.once("SIGINT",e)},"installSignalHandlers")}}t(E,"createTeardown");export{E as createTeardown};