@north-light/cli 0.3.709 → 0.3.710
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clients/attach/input/capabilities.js +1 -1
- package/dist/clients/attach/session/layout-record.d.ts +13 -0
- package/dist/clients/attach/session/layout-record.js +1 -0
- package/dist/clients/attach/session/teardown.d.ts +2 -0
- package/dist/clients/attach/session/teardown.js +3 -3
- package/dist/clients/attach/slash/dispatch.js +2 -2
- package/dist/clients/attach/slash/recover.d.ts +10 -0
- package/dist/clients/attach/slash/recover.js +2 -0
- package/dist/clients/attach/viewer.js +504 -501
- package/dist/core/canvas/managed-worktree-sweep-candidates.d.ts +2 -2
- package/dist/core/canvas/managed-worktree-sweep-candidates.js +5 -3
- package/dist/core/canvas/schema-pg/028-machine-calls-worktree-sweep.sql +6 -0
- package/dist/core/canvas/schema-version.d.ts +1 -1
- package/dist/core/canvas/schema-version.js +1 -1
- package/dist/core/runtime/broker-request.d.ts +2 -0
- package/dist/core/runtime/broker-request.js +1 -1
- package/dist/core/runtime/broker.js +1 -1
- package/dist/core/runtime/model-swap.d.ts +2 -1
- package/dist/core/runtime/model-swap.js +1 -1
- package/dist/core/runtime/placement-tmux.d.ts +1 -1
- package/dist/core/runtime/placement-tmux.js +1 -1
- package/dist/core/runtime/runner/machine/call.js +2 -2
- package/dist/core/runtime/runner/machine/ops.d.ts +11 -1
- package/dist/core/runtime/runner/machine/ops.js +1 -1
- package/dist/core/runtime/tmux-driver.d.ts +7 -0
- package/dist/core/runtime/tmux-driver.js +6 -6
- package/dist/core/worktree-machine.d.ts +4 -1
- package/dist/core/worktree-machine.js +1 -1
- package/dist/core/worktree-sweep.d.ts +14 -3
- package/dist/core/worktree-sweep.js +4 -4
- package/dist/daemon/api/handlers/nodes.js +1 -1
- package/dist/daemon/fleet.d.ts +1 -1
- package/dist/daemon/fleet.js +4 -4
- package/dist/daemon/reconcilers/managed-worktree-sweep.js +1 -1
- package/dist/daemon/runs/observer.d.ts +4 -0
- package/dist/daemon/runs/observer.js +1 -1
- package/dist/pi-extensions/canvas-inbox-watcher.js +1 -1
- package/package.json +3 -3
- package/packages/crouter-api/dist/clients/attach/input/capabilities.js +1 -0
- package/packages/crouter-api/dist/clients/attach/session/layout-record.js +52 -0
- package/packages/crouter-api/dist/clients/attach/session/teardown.js +2 -0
- package/packages/crouter-api/dist/clients/attach/slash/dispatch.js +12 -0
- package/packages/crouter-api/dist/clients/attach/slash/recover.js +111 -0
- package/packages/crouter-api/dist/clients/attach/viewer.js +9 -1
- package/packages/crouter-api/dist/core/canvas/schema-version.js +1 -1
- package/packages/crouter-api/dist/core/runtime/broker-ownership.js +6 -0
- package/packages/crouter-api/dist/core/runtime/broker-request.js +1 -1
- package/packages/crouter-api/dist/core/runtime/model-swap.js +2 -1
- package/packages/crouter-api/dist/core/runtime/placement-tmux.js +1 -1
- package/packages/crouter-api/dist/core/runtime/runner/machine/call.js +1 -1
- package/packages/crouter-api/dist/core/runtime/runner/machine/executor.js +235 -0
- package/packages/crouter-api/dist/core/runtime/runner/machine/ops.js +1 -1
- package/packages/crouter-api/dist/core/runtime/tmux-driver.js +11 -0
- package/packages/crouter-api/dist/core/worktree-machine.js +20 -0
- package/packages/crouter-api/dist/core/worktree-sweep.js +439 -0
- package/packages/crouter-api/dist/daemon/runs/observer.js +1 -1
- package/packages/crouter-api/package.json +1 -1
- package/packages/crouter-identity/package.json +1 -1
- package/packages/crouter-plugin/package.json +3 -3
- package/runtime.lock.json +14 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
var o=Object.defineProperty;var
|
|
1
|
+
var o=Object.defineProperty;var n=(e,s)=>o(e,"name",{value:s,configurable:!0});function l(e){const s=e.remote,t=e.role,a=new Set;return s||(a.add("local-canvas-inspect"),a.add("canvas-inbox")),t==="controller"&&(a.add("engine-drive"),a.add("dequeue")),t==="controller"&&!s&&(a.add("wake-dormant"),a.add("auth"),a.add("canvas-resume"),a.add("local-host")),{role:t,remote:s,get nodeId(){return e.nodeId},profileId:e.profileId,permittedOperations:a,permits:n(r=>a.has(r),"permits"),refusal:n((r,i)=>{const c=i===void 0?"":`/${i} `;if(e.isBrokerOffline?.()===!0&&(r==="engine-drive"||r==="dequeue"||r==="auth"))return`${c}needs a live broker; this node is parked \u2014 submit a message to wake it`;if(!a.has(r))return s&&(r==="canvas-resume"||r==="local-canvas-inspect"||r==="canvas-inbox")?`${c}Not available with --canvas because it acts on this machine's local canvas`:s&&t==="controller"?`${c}Not available with --canvas because it acts on this machine, not the remote node`:`${c}is not available to a read-only observer attach (--observer) \u2014 it would drive this node`},"refusal")}}n(l,"createViewerCapabilities");function u(e){switch(e.type){case"prompt":case"steer":case"follow_up":case"abort":case"bash":case"set_model":case"cycle_model":case"cycle_ladder":case"cycle_thinking":case"set_thinking_level":case"set_auto_retry":case"set_auto_compaction":case"compact":case"new_session":case"switch_session":case"fork":case"set_session_name":case"navigate_tree":case"reload":case"export":case"clone":case"share":case"reload_auth":return"engine-drive";default:return}}n(u,"viewerOperationForFrame");function f(e,s,t){if(t)switch(e){case"resume":return"canvas-resume";case"context":case"node-metadata":return"local-canvas-inspect";case"plugins":return;case"inbox":return"canvas-inbox";case"clear":case"resume-session":case"tutorial":return"engine-drive";case"recover":case"promote":case"rename":case"mcp":return"local-host";default:return}if(s)switch(e){case"copy":case"session":case"changelog":case"hotkeys":case"quit":return;case"login":case"logout":return"auth";default:return"engine-drive"}}n(f,"viewerOperationForSlash");export{l as createViewerCapabilities,u as viewerOperationForFrame,f as viewerOperationForSlash};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface LayoutRecord {
|
|
2
|
+
nodeId: string;
|
|
3
|
+
session: string;
|
|
4
|
+
windowIndex: number;
|
|
5
|
+
windowName: string;
|
|
6
|
+
paneIndex: number;
|
|
7
|
+
cwd: string;
|
|
8
|
+
pane: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function writeLayoutRecord(nodeId: string, pane: string | undefined, cwd: string): void;
|
|
11
|
+
/** Delete this node's record unless another viewer pane has since claimed it. */
|
|
12
|
+
export declare function removeLayoutRecord(nodeId: string, pane: string | undefined): void;
|
|
13
|
+
export declare function readLayoutRecords(): LayoutRecord[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var f=Object.defineProperty;var t=(r,e)=>f(r,"name",{value:e,configurable:!0});import{mkdirSync as a,readdirSync as m,readFileSync as s,rmSync as y,writeFileSync as w}from"node:fs";import{join as c}from"node:path";import{runtimeRoot as p}from"../../../core/layout.js";import{paneCoordinates as h}from"../../../core/runtime/placement-tmux.js";function i(){return c(p(),"viewer-panes")}t(i,"recordsDir");function u(r){return c(i(),`${r}.json`)}t(u,"recordPath");function j(r,e,n){if(e===void 0||e==="")return;const o=h(e);if(o===null)return;const d={nodeId:r,session:o.session,windowIndex:o.windowIndex,windowName:o.windowName,paneIndex:o.paneIndex,cwd:n,pane:e};try{a(i(),{recursive:!0}),w(u(r),JSON.stringify(d))}catch{}}t(j,"writeLayoutRecord");function v(r,e){try{const n=JSON.parse(s(u(r),"utf8"));(e===void 0||n.pane===e)&&y(u(r),{force:!0})}catch{}}t(v,"removeLayoutRecord");function J(){let r;try{r=m(i())}catch{return[]}const e=[];for(const n of r)if(n.endsWith(".json"))try{e.push(JSON.parse(s(c(i(),n),"utf8")))}catch{}return e}t(J,"readLayoutRecords");export{J as readLayoutRecords,v as removeLayoutRecord,j as writeLayoutRecord};
|
|
@@ -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
|
+
/** Drop this viewer's tmux layout record. Called only when the person detached or the node finished, never on a signal or a lost broker. */
|
|
21
|
+
forgetLayout: () => void;
|
|
20
22
|
/** 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
23
|
undelivered: () => string[];
|
|
22
24
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var m=Object.defineProperty;var t=(r,n)=>m(r,"name",{value:n,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 v(r,n){const{tui:
|
|
1
|
+
var m=Object.defineProperty;var t=(r,n)=>m(r,"name",{value:n,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 v(r,n){const{tui:p,socket:i,remote:u}=r;let c=!1;const d=t(()=>{if(!c){c=!0;try{process.stdout.write(I),p.stop()}catch{}}},"restore");process.once("exit",d);let s=!1,a;const g=new Promise(e=>{a=e}),l=t(e=>{if(s)return;if(s=!0,n.stopLocal(),e==="detach"&&i.send({type:"bye"}),i.close(),(e==="detach"||e==="node-done")&&n.forgetLayout(),d(),e==="broker-gone"){const o=n.lastSocketError()??`broker gone \u2014 node ${r.nodeId} is no longer running its engine.`;process.stderr.write(`
|
|
2
2
|
${o}
|
|
3
3
|
Reattach with: ${n.reattachCommand()}
|
|
4
4
|
`)}e==="create-failed"&&process.stderr.write(`
|
|
5
5
|
${n.lastSocketError()??"creating the node failed"}
|
|
6
|
-
`);const
|
|
6
|
+
`);const f=n.undelivered();if(f.length>0&&process.stderr.write(`
|
|
7
7
|
Not delivered:
|
|
8
|
-
${
|
|
8
|
+
${f.join(`
|
|
9
9
|
---
|
|
10
10
|
`)}
|
|
11
11
|
`),e==="node-done"){process.stderr.write(`
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var L=Object.defineProperty;var i=(t,e)=>L(t,"name",{value:e,configurable:!0});import{execFile as d}from"node:child_process";import{BUILTIN_SLASH_COMMANDS as h}from"../../../core/runtime/pi-vendored.js";import{surfaceTmuxStyleArgs as U}from"../../../core/runtime/surface-bg.js";import{crouterMenuTmuxArgs as E}from"../../../core/runtime/tmux-bindings.js";import{viewerOperationForSlash as $}from"../input/capabilities.js";import{shellQuote as y}from"../../../shared/shell-quote.js";const g=[{name:"tutorial",description:"The guided crouter tutorial \u2014 your agent teaches it, one lesson at a time"},{name:"menu",description:"Open the crouter action menu \u2014 the same menu as Alt+C, for when Option/Alt does not work in your terminal"},{name:"clear",description:"Clear the conversation and free context \u2014 a fresh, empty session (like /new)"},{name:"graph",description:"Toggle the canvas GRAPH view (your local subscription tree)"},{name:"inbox",description:"Toggle the human inbox \u2014 pending asks and reviews for you"},{name:"promote",description:"Promote this node to an orchestrator \u2014 /promote, or /promote <kind> to specialize"},{name:"resume",description:"Open the canvas navigator and swap THIS pane onto the chosen node; parked residents wake only on submitted input"},{name:"resume-session",description:"Switch this node onto one of its saved pi sessions \u2014 picker, or /resume-session <session-path>"},{name:"context",description:"Browse the files in this node\u2019s and its subscriptions\u2019 context dirs in a read-only nvim popup"},{name:"plugins",description:"Open the interactive plugin browser for this machine"},{name:"node-metadata",description:"Inspect this node \u2014 identity, lifecycle, runtime, graph, output, paths, and agent surfaces"},{name:"mcp",description:"MCP servers \u2014 status from the adapter\u2019s config/cache; Enter (or /mcp <server>) connects, reconnects, or re-auths"},{name:"rename",description:"Rename this node everywhere \u2014 node row, viewer window, session chip, tmux pane: /rename <name>"},{name:"color",description:"Color this node \u2014 tmux pane outline + name chip: /color <color> (red, blue, #rrggbb, \u2026) or /color none"},{name:"mouse",description:"Toggle mouse wheel scrolling and drag-select \u2014 off restores tmux drag-select and copy-mode mouse"},{name:"copy-message",description:"Copy the newest message visible in the transcript viewport"},{name:"copy-tool",description:"Copy the newest tool call output"},{name:"copy-transcript",description:"Copy every copyable transcript block"},{name:"more-detail",description:"Show the transcript one verbosity level more open, in this viewer only (Ctrl+O)"},{name:"less-detail",description:"Show the transcript one verbosity level more collapsed, in this viewer only (Ctrl+Shift+O)"}],_=new Map([["resume-node","resume"]]),w=new Set([...g.map(t=>t.name),..._.keys()]),X=new Set(["black","red","green","yellow","blue","magenta","cyan","white","brightred","brightgreen","brightyellow","brightblue","brightmagenta","brightcyan","orange","grey","gray","default"]),M=new Set(["trust"]),T=new Set(Object.keys({off:!0,minimal:!0,low:!0,medium:!0,high:!0,xhigh:!0,max:!0})),v=new Set(h.map(t=>t.name));function b(t){return t.capabilities.nodeId}i(b,"nodeIdFor");function j(t){return t.capabilities.profileId}i(j,"profileIdFor");function N(t,e){const n=$(t,v.has(t),w.has(t));return n===void 0?void 0:e.capabilities.refusal(n,t)}i(N,"readOnlyRefusal");function ie(){return new Set([...v,...w,...M])}i(ie,"locallyConsumedCommandNames");function D(t){const e=/^\/(\S+)\s*([\s\S]*)$/.exec(t.trim());return e===null?void 0:{name:e[1],arg:e[2].trim()}}i(D,"parseSlashCommand");function se(t){return t.trimStart().startsWith("/")}i(se,"isSlashCommand");function ae(t,e){const n=D(t);if(n===void 0)return!1;const{arg:o}=n,r=_.get(n.name)??n.name;if(M.has(r))return e.notify(`/${r} is not supported in attach (Phase 4)`),!0;if(w.has(r)){const s=N(r,e);return s!==void 0?(e.notify(s),!0):H(r,o,e)}if(!v.has(r))return!1;const u=N(r,e);if(u!==void 0)return e.notify(u),!0;switch(r){case"new":return e.send({type:"new_session"}),!0;case"reload":return e.send({type:"reload"}),!0;case"compact":return e.send({type:"compact",instructions:o||void 0}),!0;case"quit":return e.onQuit?(e.onQuit(),!0):(e.send({type:"bye"}),e.notify("Detaching \u2014 the engine keeps running"),!0);case"name":return o?(e.send({type:"set_session_name",name:o}),!0):m(e,"/name <display name>");case"export":{const{path:s,format:a}=K(o,e.cwd??process.cwd());return e.send({type:"export",path:s,format:a}),e.notify(`Exporting session \u2192 ${s}`),!0}case"import":return o?(e.send({type:"switch_session",path:o}),!0):m(e,"/import <path-to-session.jsonl>");case"model":return o?(e.send({type:"set_model",model:o}),!0):f(e.openModelPicker,e,"model","/model <provider/id>");case"fork":return o?(e.send({type:"fork",entryId:o}),!0):f(e.openForkPicker,e,"fork point","/fork <entryId>");case"tree":return o?(e.send({type:"navigate_tree",targetId:o}),!0):f(e.openTreePicker,e,"tree","/tree <entryId>");case"scoped-models":return e.openScopedModelsPicker?(e.openScopedModelsPicker(),!0):(e.notify("The scoped-models view needs the read-op channel, which this viewer has not wired"),!0);case"settings":return Y(o,e);case"session":return e.notify(z(e.state)),!0;case"copy":return e.onCopy?(e.onCopy(),!0):(e.notify("/copy is not available in this viewer"),!0);case"login":return e.openLoginPicker?(e.openLoginPicker(),!0):(e.notify("/login is not available in this viewer"),!0);case"logout":return e.openLogoutPicker?(e.openLogoutPicker(),!0):(e.notify("/logout is not available in this viewer"),!0);case"share":return e.send({type:"share"}),e.notify("Sharing session\u2026"),!0;case"clone":return e.send({type:"clone"}),e.notify("Cloning session\u2026"),!0;case"changelog":return e.notify("/changelog: see https://github.com/earendil-works/pi for release notes (no bundled changelog in this build)"),!0;case"hotkeys":return e.onHelp?(e.onHelp(),!0):(e.notify("/hotkeys is not available in this viewer"),!0);default:return e.notify(`/${r} is not available in attach (Phase 4)`),!0}}i(ae,"dispatchSlashCommand");function P(t,e){const n=i(a=>{const l=$(a,!1,!0);return l===void 0||e.permits(l)},"permitted"),o=g.filter(a=>n(a.name)),r=new Map(g.map(a=>[a.name,a])),u=t.flatMap(a=>{const l=r.get(a.name);return l===void 0?[a]:n(a.name)?[l]:[]}),s=new Set(t.map(a=>a.name));return[...u,...o.filter(a=>!s.has(a.name))]}i(P,"withCanvasCommands");function ue(t,e){return P(t??h,e).map(n=>({name:n.name,description:n.description}))}i(ue,"slashCommandList");function le(t,e){return P(t??h,e).map(n=>({value:`/${n.name}`,label:`/${n.name}`,description:n.description}))}i(le,"commandAutocompleteItems");function H(t,e,n){switch(t){case"clear":return n.send({type:"new_session"}),!0;case"graph":return n.onGraph?n.onGraph():n.notify("The GRAPH overlay is not wired into the viewer yet"),!0;case"inbox":return n.onInbox?n.onInbox():n.notify("The inbox surface is not wired into the viewer yet"),!0;case"menu":return q(n);case"tutorial":return n.send({type:"prompt",text:"The user asked for the crouter tutorial. Run `crtr sys tutorial -h`, pick the track that matches what they want to learn, and teach it one lesson per invocation \u2014 in your own words, letting them try each thing before you move on."}),!0;case"promote":return B(e,n),!0;case"resume":return e?m(n,"/resume \u2014 no argument; use /resume-session <path> to switch pi sessions"):G(n);case"resume-session":return e?(n.send({type:"switch_session",path:e}),!0):f(n.openSessionPicker,n,"session","/resume-session <session-path>");case"mcp":return n.openMcpPicker?n.openMcpPicker(e||void 0):n.notify("The MCP panel is not wired into this viewer"),!0;case"context":return J(n);case"plugins":return Q(n);case"node-metadata":return n.onNodeMetadata?n.onNodeMetadata():n.notify("Node metadata is not wired into this viewer"),!0;case"rename":return R(e,n),!0;case"color":return F(e,n);case"more-detail":return n.onMoreDetail?n.onMoreDetail():n.notify("Verbosity is not wired into this viewer"),!0;case"less-detail":return n.onLessDetail?n.onLessDetail():n.notify("Verbosity is not wired into this viewer"),!0;case"mouse":return n.onToggleMouse?n.onToggleMouse():n.notify("Mouse reporting is not wired into this viewer"),!0;case"copy-message":return n.onCopyTarget?n.onCopyTarget("message"):n.notify("/copy-message is not available in this viewer"),!0;case"copy-tool":return n.onCopyTarget?n.onCopyTarget("tool"):n.notify("/copy-tool is not available in this viewer"),!0;case"copy-transcript":return n.onCopyTarget?n.onCopyTarget("transcript"):n.notify("/copy-transcript is not available in this viewer"),!0;default:return n.notify(`/${t} is not available in attach`),!0}}i(H,"dispatchCanvasCommand");function B(t,e){const n=b(e).trim();if(n===""){e.notify("/promote: no node to promote (viewer has no node id)");return}const o=t.trim().toLowerCase();e.notify(o?`Promoting \u2192 ${o}\u2026`:"Promoting\u2026");const r=["node","promote","--node",n,"--json"];o!==""&&r.push("--kind",o),d("crtr",r,{timeout:15e3,maxBuffer:4*1024*1024},(s,a)=>{let l=null,p=null;try{l=JSON.parse(a)}catch{l=null}if(s&&l===null){const O=typeof s.stdout=="string"?s.stdout:"";try{const C=JSON.parse(O);p=typeof C.message=="string"?C.message:null}catch{p=null}p===null&&(p=s.message)}if(l===null){e.notify(`promote failed: ${p??"unknown error"}`);return}const S=(l.roadmap_ref??"").trim();e.notify(`Promoted to ${l.kind??"orchestrator"} orchestrator \u2014 authoring roadmap${S!==""?` (${S})`:""}.`),e.send({type:"prompt",text:"You have just been promoted to an orchestrator. Your new-role guidance is arriving \u2014 read it, author your roadmap, and start delegating."})}).stdin?.end()}i(B,"promoteNode");function R(t,e){const n=b(e).trim();if(n===""){e.notify("/rename: no node to rename (viewer has no node id)");return}if(t===""){e.notify("Usage: /rename <name>");return}e.send({type:"set_session_name",name:t});const o=process.env.TMUX_PANE;process.env.TMUX!==void 0&&o!==void 0&&o!==""&&d("tmux",["select-pane","-t",o,"-T",t],()=>{}),d("crtr",["node","config","--node",n,"--name",t,"--json"],{timeout:15e3,maxBuffer:4*1024*1024},(r,u)=>{if(r){let s=null;try{const a=JSON.parse(u);s=typeof a.message=="string"?a.message:null}catch{s=null}e.notify(`rename failed: ${s??r.message}`);return}e.notify(`Renamed node \u2192 ${t}`)})}i(R,"renameNode");function c(t){return new Promise(e=>{d("tmux",t,{timeout:5e3},(n,o)=>e(n?"":o))})}i(c,"tmuxCall");async function V(t,e,n){if(n){await c(["set-option","-p","-u","-t",t,"@crtr_color"]);return}await c(["set-option","-p","-t",t,"@crtr_color",e]);for(const o of["pane-border-style","pane-active-border-style"]){const r=(await c(["show-options","-wqv","-t",t,o])).trim();if(r.includes("@crtr_color"))continue;let u=r!==""?r:(await c(["show-options","-gqv",o])).trim();u===""&&(u=o==="pane-active-border-style"?"fg=green":"default");const s=`#{?#{!=:#{@crtr_color},},fg=#{@crtr_color},${u.replace(/,/g,"#,")}}`;await c(["set-option","-w","-t",t,o,s])}}i(V,"paintPaneBorder");function F(t,e){const n=t.trim().toLowerCase();if(n==="")return e.notify("Usage: /color <color> \u2014 a name (red, blue, orange\u2026), colourN, or #rrggbb; /color none to clear"),!0;const o=n==="none"||n==="clear";if(!(o||X.has(n)||/^colour\d{1,3}$/.test(n)||/^#[0-9a-f]{6}$/.test(n)))return e.notify(`Invalid color "${n}" \u2014 use a tmux colour name (${["red","green","yellow","blue","magenta","cyan","orange"].join(", ")}, \u2026), colourN, or #rrggbb`),!0;const u=process.env.TMUX_PANE,s=process.env.TMUX!==void 0&&u!==void 0&&u!=="";return s&&V(u,n,o),e.onColor?.(o?null:n),e.notify(o?"Node color cleared":`Node colored ${n}${s?"":" (chip only \u2014 no tmux pane)"}`),!0}i(F,"colorNode");function G(t){const e=process.env.TMUX_PANE;if(process.env.TMUX===void 0||e===void 0||e==="")return t.notify("/resume needs tmux"),!0;const n=y(t.cwd??process.cwd()),o=j(t),r=o===void 0||o===""?"":` --profile-id ${y(o)}`,u=`crtr canvas browse --return-pane ${e} --cwd ${n}${r}`;return k(u,{w:"97%",h:"95%"}),!0}i(G,"resumeNode");function q(t){const e=process.env.TMUX_PANE;if(process.env.TMUX===void 0||e===void 0||e==="")return t.notify("/menu needs tmux \u2014 the crouter action menu is a tmux menu"),!0;try{d("tmux",["display-menu","-t",e,...E().slice(1)],n=>{n&&t.notify(`/menu failed: ${n.message.split(`
|
|
2
|
-
`)[0]}`)})}catch(n){t.notify(`/menu failed: ${n.message}`)}return!0}i(
|
|
1
|
+
var L=Object.defineProperty;var i=(t,e)=>L(t,"name",{value:e,configurable:!0});import{execFile as l}from"node:child_process";import{BUILTIN_SLASH_COMMANDS as h}from"../../../core/runtime/pi-vendored.js";import{surfaceTmuxStyleArgs as U}from"../../../core/runtime/surface-bg.js";import{crouterMenuTmuxArgs as E}from"../../../core/runtime/tmux-bindings.js";import{viewerOperationForSlash as C}from"../input/capabilities.js";import{formatReport as X,recover as j}from"./recover.js";import{shellQuote as y}from"../../../shared/shell-quote.js";const g=[{name:"tutorial",description:"The guided crouter tutorial \u2014 your agent teaches it, one lesson at a time"},{name:"menu",description:"Open the crouter action menu \u2014 the same menu as Alt+C, for when Option/Alt does not work in your terminal"},{name:"clear",description:"Clear the conversation and free context \u2014 a fresh, empty session (like /new)"},{name:"graph",description:"Toggle the canvas GRAPH view (your local subscription tree)"},{name:"inbox",description:"Toggle the human inbox \u2014 pending asks and reviews for you"},{name:"promote",description:"Promote this node to an orchestrator \u2014 /promote, or /promote <kind> to specialize"},{name:"resume",description:"Open the canvas navigator and swap THIS pane onto the chosen node; parked residents wake only on submitted input"},{name:"resume-session",description:"Switch this node onto one of its saved pi sessions \u2014 picker, or /resume-session <session-path>"},{name:"context",description:"Browse the files in this node\u2019s and its subscriptions\u2019 context dirs in a read-only nvim popup"},{name:"plugins",description:"Open the interactive plugin browser for this machine"},{name:"node-metadata",description:"Inspect this node \u2014 identity, lifecycle, runtime, graph, output, paths, and agent surfaces"},{name:"mcp",description:"MCP servers \u2014 status from the adapter\u2019s config/cache; Enter (or /mcp <server>) connects, reconnects, or re-auths"},{name:"rename",description:"Rename this node everywhere \u2014 node row, viewer window, session chip, tmux pane: /rename <name>"},{name:"color",description:"Color this node \u2014 tmux pane outline + name chip: /color <color> (red, blue, #rrggbb, \u2026) or /color none"},{name:"recover",description:"After a crash or reboot: revive every disconnected node and rebuild the tmux viewer panes that were open"},{name:"mouse",description:"Toggle mouse wheel scrolling and drag-select \u2014 off restores tmux drag-select and copy-mode mouse"},{name:"copy-message",description:"Copy the newest message visible in the transcript viewport"},{name:"copy-tool",description:"Copy the newest tool call output"},{name:"copy-transcript",description:"Copy every copyable transcript block"},{name:"more-detail",description:"Show the transcript one verbosity level more open, in this viewer only (Ctrl+O)"},{name:"less-detail",description:"Show the transcript one verbosity level more collapsed, in this viewer only (Ctrl+Shift+O)"}],_=new Map([["resume-node","resume"]]),w=new Set([...g.map(t=>t.name),..._.keys()]),D=new Set(["black","red","green","yellow","blue","magenta","cyan","white","brightred","brightgreen","brightyellow","brightblue","brightmagenta","brightcyan","orange","grey","gray","default"]),M=new Set(["trust"]),T=new Set(Object.keys({off:!0,minimal:!0,low:!0,medium:!0,high:!0,xhigh:!0,max:!0})),v=new Set(h.map(t=>t.name));function b(t){return t.capabilities.nodeId}i(b,"nodeIdFor");function H(t){return t.capabilities.profileId}i(H,"profileIdFor");function N(t,e){const n=C(t,v.has(t),w.has(t));return n===void 0?void 0:e.capabilities.refusal(n,t)}i(N,"readOnlyRefusal");function ue(){return new Set([...v,...w,...M])}i(ue,"locallyConsumedCommandNames");function R(t){const e=/^\/(\S+)\s*([\s\S]*)$/.exec(t.trim());return e===null?void 0:{name:e[1],arg:e[2].trim()}}i(R,"parseSlashCommand");function de(t){return t.trimStart().startsWith("/")}i(de,"isSlashCommand");function le(t,e){const n=R(t);if(n===void 0)return!1;const{arg:r}=n,o=_.get(n.name)??n.name;if(M.has(o))return e.notify(`/${o} is not supported in attach (Phase 4)`),!0;if(w.has(o)){const s=N(o,e);return s!==void 0?(e.notify(s),!0):B(o,r,e)}if(!v.has(o))return!1;const u=N(o,e);if(u!==void 0)return e.notify(u),!0;switch(o){case"new":return e.send({type:"new_session"}),!0;case"reload":return e.send({type:"reload"}),!0;case"compact":return e.send({type:"compact",instructions:r||void 0}),!0;case"quit":return e.onQuit?(e.onQuit(),!0):(e.send({type:"bye"}),e.notify("Detaching \u2014 the engine keeps running"),!0);case"name":return r?(e.send({type:"set_session_name",name:r}),!0):m(e,"/name <display name>");case"export":{const{path:s,format:a}=Z(r,e.cwd??process.cwd());return e.send({type:"export",path:s,format:a}),e.notify(`Exporting session \u2192 ${s}`),!0}case"import":return r?(e.send({type:"switch_session",path:r}),!0):m(e,"/import <path-to-session.jsonl>");case"model":return r?(e.send({type:"set_model",model:r}),!0):f(e.openModelPicker,e,"model","/model <provider/id>");case"fork":return r?(e.send({type:"fork",entryId:r}),!0):f(e.openForkPicker,e,"fork point","/fork <entryId>");case"tree":return r?(e.send({type:"navigate_tree",targetId:r}),!0):f(e.openTreePicker,e,"tree","/tree <entryId>");case"scoped-models":return e.openScopedModelsPicker?(e.openScopedModelsPicker(),!0):(e.notify("The scoped-models view needs the read-op channel, which this viewer has not wired"),!0);case"settings":return z(r,e);case"session":return e.notify(x(e.state)),!0;case"copy":return e.onCopy?(e.onCopy(),!0):(e.notify("/copy is not available in this viewer"),!0);case"login":return e.openLoginPicker?(e.openLoginPicker(),!0):(e.notify("/login is not available in this viewer"),!0);case"logout":return e.openLogoutPicker?(e.openLogoutPicker(),!0):(e.notify("/logout is not available in this viewer"),!0);case"share":return e.send({type:"share"}),e.notify("Sharing session\u2026"),!0;case"clone":return e.send({type:"clone"}),e.notify("Cloning session\u2026"),!0;case"changelog":return e.notify("/changelog: see https://github.com/earendil-works/pi for release notes (no bundled changelog in this build)"),!0;case"hotkeys":return e.onHelp?(e.onHelp(),!0):(e.notify("/hotkeys is not available in this viewer"),!0);default:return e.notify(`/${o} is not available in attach (Phase 4)`),!0}}i(le,"dispatchSlashCommand");function P(t,e){const n=i(a=>{const d=C(a,!1,!0);return d===void 0||e.permits(d)},"permitted"),r=g.filter(a=>n(a.name)),o=new Map(g.map(a=>[a.name,a])),u=t.flatMap(a=>{const d=o.get(a.name);return d===void 0?[a]:n(a.name)?[d]:[]}),s=new Set(t.map(a=>a.name));return[...u,...r.filter(a=>!s.has(a.name))]}i(P,"withCanvasCommands");function pe(t,e){return P(t??h,e).map(n=>({name:n.name,description:n.description}))}i(pe,"slashCommandList");function ce(t,e){return P(t??h,e).map(n=>({value:`/${n.name}`,label:`/${n.name}`,description:n.description}))}i(ce,"commandAutocompleteItems");function B(t,e,n){switch(t){case"clear":return n.send({type:"new_session"}),!0;case"graph":return n.onGraph?n.onGraph():n.notify("The GRAPH overlay is not wired into the viewer yet"),!0;case"inbox":return n.onInbox?n.onInbox():n.notify("The inbox surface is not wired into the viewer yet"),!0;case"menu":return Q(n);case"tutorial":return n.send({type:"prompt",text:"The user asked for the crouter tutorial. Run `crtr sys tutorial -h`, pick the track that matches what they want to learn, and teach it one lesson per invocation \u2014 in your own words, letting them try each thing before you move on."}),!0;case"promote":return V(e,n),!0;case"resume":return e?m(n,"/resume \u2014 no argument; use /resume-session <path> to switch pi sessions"):J(n);case"resume-session":return e?(n.send({type:"switch_session",path:e}),!0):f(n.openSessionPicker,n,"session","/resume-session <session-path>");case"mcp":return n.openMcpPicker?n.openMcpPicker(e||void 0):n.notify("The MCP panel is not wired into this viewer"),!0;case"context":return W(n);case"plugins":return Y(n);case"node-metadata":return n.onNodeMetadata?n.onNodeMetadata():n.notify("Node metadata is not wired into this viewer"),!0;case"rename":return F(e,n),!0;case"color":return q(e,n);case"more-detail":return n.onMoreDetail?n.onMoreDetail():n.notify("Verbosity is not wired into this viewer"),!0;case"less-detail":return n.onLessDetail?n.onLessDetail():n.notify("Verbosity is not wired into this viewer"),!0;case"recover":return e?m(n,"/recover \u2014 no argument"):process.env.TMUX===void 0?(n.notify("/recover needs tmux"),!0):(n.notify("Recovering \u2014 reviving nodes and rebuilding panes\u2026"),j().then(r=>n.notify(X(r)),r=>n.notify(`recover failed: ${r instanceof Error?r.message:String(r)}`)),!0);case"mouse":return n.onToggleMouse?n.onToggleMouse():n.notify("Mouse reporting is not wired into this viewer"),!0;case"copy-message":return n.onCopyTarget?n.onCopyTarget("message"):n.notify("/copy-message is not available in this viewer"),!0;case"copy-tool":return n.onCopyTarget?n.onCopyTarget("tool"):n.notify("/copy-tool is not available in this viewer"),!0;case"copy-transcript":return n.onCopyTarget?n.onCopyTarget("transcript"):n.notify("/copy-transcript is not available in this viewer"),!0;default:return n.notify(`/${t} is not available in attach`),!0}}i(B,"dispatchCanvasCommand");function V(t,e){const n=b(e).trim();if(n===""){e.notify("/promote: no node to promote (viewer has no node id)");return}const r=t.trim().toLowerCase();e.notify(r?`Promoting \u2192 ${r}\u2026`:"Promoting\u2026");const o=["node","promote","--node",n,"--json"];r!==""&&o.push("--kind",r),l("crtr",o,{timeout:15e3,maxBuffer:4*1024*1024},(s,a)=>{let d=null,p=null;try{d=JSON.parse(a)}catch{d=null}if(s&&d===null){const O=typeof s.stdout=="string"?s.stdout:"";try{const $=JSON.parse(O);p=typeof $.message=="string"?$.message:null}catch{p=null}p===null&&(p=s.message)}if(d===null){e.notify(`promote failed: ${p??"unknown error"}`);return}const S=(d.roadmap_ref??"").trim();e.notify(`Promoted to ${d.kind??"orchestrator"} orchestrator \u2014 authoring roadmap${S!==""?` (${S})`:""}.`),e.send({type:"prompt",text:"You have just been promoted to an orchestrator. Your new-role guidance is arriving \u2014 read it, author your roadmap, and start delegating."})}).stdin?.end()}i(V,"promoteNode");function F(t,e){const n=b(e).trim();if(n===""){e.notify("/rename: no node to rename (viewer has no node id)");return}if(t===""){e.notify("Usage: /rename <name>");return}e.send({type:"set_session_name",name:t});const r=process.env.TMUX_PANE;process.env.TMUX!==void 0&&r!==void 0&&r!==""&&l("tmux",["select-pane","-t",r,"-T",t],()=>{}),l("crtr",["node","config","--node",n,"--name",t,"--json"],{timeout:15e3,maxBuffer:4*1024*1024},(o,u)=>{if(o){let s=null;try{const a=JSON.parse(u);s=typeof a.message=="string"?a.message:null}catch{s=null}e.notify(`rename failed: ${s??o.message}`);return}e.notify(`Renamed node \u2192 ${t}`)})}i(F,"renameNode");function c(t){return new Promise(e=>{l("tmux",t,{timeout:5e3},(n,r)=>e(n?"":r))})}i(c,"tmuxCall");async function G(t,e,n){if(n){await c(["set-option","-p","-u","-t",t,"@crtr_color"]);return}await c(["set-option","-p","-t",t,"@crtr_color",e]);for(const r of["pane-border-style","pane-active-border-style"]){const o=(await c(["show-options","-wqv","-t",t,r])).trim();if(o.includes("@crtr_color"))continue;let u=o!==""?o:(await c(["show-options","-gqv",r])).trim();u===""&&(u=r==="pane-active-border-style"?"fg=green":"default");const s=`#{?#{!=:#{@crtr_color},},fg=#{@crtr_color},${u.replace(/,/g,"#,")}}`;await c(["set-option","-w","-t",t,r,s])}}i(G,"paintPaneBorder");function q(t,e){const n=t.trim().toLowerCase();if(n==="")return e.notify("Usage: /color <color> \u2014 a name (red, blue, orange\u2026), colourN, or #rrggbb; /color none to clear"),!0;const r=n==="none"||n==="clear";if(!(r||D.has(n)||/^colour\d{1,3}$/.test(n)||/^#[0-9a-f]{6}$/.test(n)))return e.notify(`Invalid color "${n}" \u2014 use a tmux colour name (${["red","green","yellow","blue","magenta","cyan","orange"].join(", ")}, \u2026), colourN, or #rrggbb`),!0;const u=process.env.TMUX_PANE,s=process.env.TMUX!==void 0&&u!==void 0&&u!=="";return s&&G(u,n,r),e.onColor?.(r?null:n),e.notify(r?"Node color cleared":`Node colored ${n}${s?"":" (chip only \u2014 no tmux pane)"}`),!0}i(q,"colorNode");function J(t){const e=process.env.TMUX_PANE;if(process.env.TMUX===void 0||e===void 0||e==="")return t.notify("/resume needs tmux"),!0;const n=y(t.cwd??process.cwd()),r=H(t),o=r===void 0||r===""?"":` --profile-id ${y(r)}`,u=`crtr canvas browse --return-pane ${e} --cwd ${n}${o}`;return k(u,{w:"97%",h:"95%"}),!0}i(J,"resumeNode");function Q(t){const e=process.env.TMUX_PANE;if(process.env.TMUX===void 0||e===void 0||e==="")return t.notify("/menu needs tmux \u2014 the crouter action menu is a tmux menu"),!0;try{l("tmux",["display-menu","-t",e,...E().slice(1)],n=>{n&&t.notify(`/menu failed: ${n.message.split(`
|
|
2
|
+
`)[0]}`)})}catch(n){t.notify(`/menu failed: ${n.message}`)}return!0}i(Q,"openActionMenu");function W(t){if(process.env.TMUX===void 0)return t.notify("/context needs tmux"),!0;const e=b(t).trim();return e===""?(t.notify("/context: no node to root on (viewer has no node id)"),!0):(k(`crtr node inspect context --node ${y(e)}`),!0)}i(W,"openContext");function Y(t){return process.env.TMUX===void 0?(t.notify("/plugins needs tmux"),!0):(k("crtr pkg browse"),!0)}i(Y,"openPlugins");function k(t,e={w:"90%",h:"85%"}){try{l("tmux",["display-popup","-E","-w",e.w,"-h",e.h,...U(),t],()=>{})}catch{}}i(k,"popup");function m(t,e){return t.notify(`Usage: ${e}`),!0}i(m,"usage");function K(t,e,n){return t.notify(`Interactive ${e} picker isn't available over view.sock yet \u2014 use ${n}`),!0}i(K,"pickerHint");function f(t,e,n,r){return t?(t(),!0):K(e,n,r)}i(f,"openOrHint");function z(t,e){const[n,...r]=t.split(/\s+/),o=r.join(" ").trim();switch(n){case"thinking":return o?T.has(o)?(e.send({type:"set_thinking_level",level:o}),!0):(e.notify(`Invalid thinking level "${o}" \u2014 choose one of: ${[...T].join(", ")}`),!0):m(e,"/settings thinking <level>");case"auto-retry":return e.send({type:"set_auto_retry",enabled:I(o)}),!0;case"auto-compaction":return e.send({type:"set_auto_compaction",enabled:I(o)}),!0;case"":return e.openSettingsPicker?(e.openSettingsPicker(),!0):A(e);default:return A(e)}}i(z,"handleSettings");function A(t){return t.notify("Settings: /settings thinking <level> | auto-retry on|off | auto-compaction on|off"),!0}i(A,"settingsSummary");function I(t){return/^(on|true|yes|1|enabled?)$/i.test(t.trim())}i(I,"parseBool");function Z(t,e){const n=t||`${e}/pi-export-${Date.now()}.html`,r=n.endsWith(".jsonl")?"jsonl":"html";return{path:n,format:r}}i(Z,"parseExport");function x(t){return t?`Session ${t.sessionName?`"${t.sessionName}" `:""}${t.sessionId} \xB7 model ${t.model?.id??"unknown"} \xB7 thinking ${t.thinkingLevel}`:"Session info unavailable"}i(x,"describeSession");export{g as CANVAS_SLASH_COMMANDS,ce as commandAutocompleteItems,le as dispatchSlashCommand,de as isSlashCommand,ue as locallyConsumedCommandNames,pe as slashCommandList};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface RecoverReport {
|
|
2
|
+
revived: number;
|
|
3
|
+
failed: string[];
|
|
4
|
+
frozen: number;
|
|
5
|
+
panes: number;
|
|
6
|
+
skipped: number;
|
|
7
|
+
source: 'snapshot' | 'recent views' | 'none';
|
|
8
|
+
}
|
|
9
|
+
export declare function recover(now?: number): Promise<RecoverReport>;
|
|
10
|
+
export declare function formatReport(r: RecoverReport): string;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var u=Object.defineProperty;var w=(n,t)=>u(n,"name",{value:t,configurable:!0});import{existsSync as m,statSync as h,openSync as v,readSync as I,closeSync as g}from"node:fs";import{join as _}from"node:path";import{routes as y}from"../../../api/index.js";import{cliClient as $}from"../../../commands/api-client.js";import{runtimeRoot as x}from"../../../core/layout.js";import{liveViewerPanes as S}from"../../../core/runtime/tmux-driver.js";import{openViewerPane as k,selectLayout as N}from"../../../core/runtime/placement-tmux.js";import{readLayoutRecords as z}from"../session/layout-record.js";const L=8*1024*1024,B=60*6e4;function O(n){const t=_(x(),"crtrd.log");if(!m(t))return[];const r=h(t).size,l=Math.max(0,r-L),i=Buffer.alloc(r-l),s=v(t,"r");try{I(s,i,0,i.length,l)}finally{g(s)}const f=[];for(const a of i.toString("utf8").split(`
|
|
2
|
+
`))if(a.includes("daemon.timing.view_open_received"))try{const d=JSON.parse(a);d.event==="daemon.timing.view_open_received"&&d.node_id!==void 0&&n-Date.parse(d.ts)<=B&&!f.includes(d.node_id)&&f.push(d.node_id)}catch{}return f}w(O,"recentViewOpens");async function V(n=Date.now()){const t=$(),r=await t.request("POST",y.reviveAll()),l=new Set(r.failed.map(e=>e.node_id)),i={revived:r.revived.length,failed:r.failed.map(e=>`${e.node_id}: ${e.error}`),frozen:r.frozen.length,panes:0,skipped:0,source:"none"};let s=z();if(s.length>0)i.source="snapshot";else{const e=O(n);e.length>0&&(i.source="recent views"),s=[];for(const o of e)s.push({nodeId:o,session:"",windowIndex:s.length,windowName:"",paneIndex:0,cwd:"",pane:""})}const f=new Set(S().map(e=>e.nodeId)),a=[];for(const e of s){if(f.has(e.nodeId)||l.has(e.nodeId)){i.skipped++;continue}try{const o=await t.getNode(e.nodeId);if(o.status==="done"||o.status==="canceled"||o.final_report!=null){i.skipped++;continue}const c=e.cwd===""?o.cwd:e.cwd,p=e.session===""?c.split("/").filter(Boolean).pop()??"crtr":e.session;a.push({...e,cwd:c,session:p,windowName:e.windowName===""?o.name:e.windowName})}catch{i.skipped++}}a.sort((e,o)=>e.session.localeCompare(o.session)||e.windowIndex-o.windowIndex||e.paneIndex-o.paneIndex);const d=new Map;for(const e of a){const o=`${e.session} ${e.windowIndex}`,c=d.get(o),p=k(e.nodeId,e.session,{name:e.windowName,cwd:e.cwd,waitForBroker:!0,...c===void 0?{}:{besidePane:c}});if(p===null){i.failed.push(`${e.nodeId}: tmux refused to open a pane`);continue}c===void 0?d.set(o,p.pane):p.window!==null&&N(p.window,"even-horizontal"),i.panes++}return i}w(V,"recover");function F(n){const t=[`revived ${n.revived}`,`${n.panes} pane${n.panes===1?"":"s"} recreated (${n.source})`];return n.frozen>0&&t.push(`${n.frozen} waiting for broker slots`),n.skipped>0&&t.push(`${n.skipped} skipped (already viewed, finished, or not revivable)`),n.failed.length>0&&t.push(`${n.failed.length} failed: ${n.failed.join("; ")}`),`Recovered \u2014 ${t.join(", ")}`}w(F,"formatReport");export{F as formatReport,V as recover};
|