@north-light/crouter 0.3.202 → 0.3.203
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/ansi-cells.d.ts +5 -1
- package/dist/clients/attach/ansi-cells.js +16 -5
- package/dist/clients/attach/render/transcript-search.js +5 -6
- package/dist/clients/attach/viewer.js +1 -1
- package/dist/commands/human/shared.d.ts +1 -0
- package/dist/commands/human/shared.js +5 -0
- package/dist/commands/human.js +1 -0
- package/package.json +1 -1
- package/runtime.lock.json +2 -2
|
@@ -24,10 +24,14 @@ export declare function rowCells(line: string): number;
|
|
|
24
24
|
/** Plain text of cells `[from, to)` — every escape, link boundary, and cursor
|
|
25
25
|
* marker dropped, exactly what a terminal copies out of that span. */
|
|
26
26
|
export declare function sliceCells(line: string, from: number, to: number): string;
|
|
27
|
-
/** The SGR pair `styleCells` asserts over a span.
|
|
27
|
+
/** The SGR pair `styleCells` asserts over a span. A style that paints color
|
|
28
|
+
* sets `restore`, because its `off` cannot un-set one color without also
|
|
29
|
+
* discarding whatever color the row had underneath it — with `restore`, the
|
|
30
|
+
* span closes by resetting and replaying the SGRs the row had already asserted. */
|
|
28
31
|
export type CellStyle = {
|
|
29
32
|
on: string;
|
|
30
33
|
off: string;
|
|
34
|
+
restore?: boolean;
|
|
31
35
|
};
|
|
32
36
|
export declare const INVERSE_STYLE: CellStyle;
|
|
33
37
|
/** Style cells `[from, to)`, re-asserting `style.on` after any SGR inside the
|
|
@@ -89,19 +89,30 @@ export function styleCells(line, from, to, maxCells, style = INVERSE_STYLE) {
|
|
|
89
89
|
return line;
|
|
90
90
|
let out = '';
|
|
91
91
|
let inside = false;
|
|
92
|
+
// The SGRs in force at the current point, so a color span can hand the row
|
|
93
|
+
// back exactly as it found it. A full reset clears the list.
|
|
94
|
+
const active = [];
|
|
92
95
|
const open = () => { if (!inside) {
|
|
93
96
|
out += style.on;
|
|
94
97
|
inside = true;
|
|
95
98
|
} };
|
|
96
|
-
const close = () => {
|
|
97
|
-
|
|
99
|
+
const close = () => {
|
|
100
|
+
if (!inside)
|
|
101
|
+
return;
|
|
102
|
+
out += style.restore === true ? `\x1b[0m${active.join('')}` : style.off;
|
|
98
103
|
inside = false;
|
|
99
|
-
}
|
|
104
|
+
};
|
|
100
105
|
const cells = walkRow(line, {
|
|
101
106
|
onEscape: (escape) => {
|
|
102
107
|
out += escape;
|
|
108
|
+
if (!escape.endsWith('m'))
|
|
109
|
+
return;
|
|
110
|
+
if (escape === '\x1b[0m' || escape === '\x1b[m')
|
|
111
|
+
active.length = 0;
|
|
112
|
+
else
|
|
113
|
+
active.push(escape);
|
|
103
114
|
// An SGR inside the span may have reset every attribute, including ours.
|
|
104
|
-
if (inside
|
|
115
|
+
if (inside)
|
|
105
116
|
out += style.on;
|
|
106
117
|
},
|
|
107
118
|
onGlyph: (glyph) => {
|
|
@@ -116,7 +127,7 @@ export function styleCells(line, from, to, maxCells, style = INVERSE_STYLE) {
|
|
|
116
127
|
if (cells < end) {
|
|
117
128
|
const gap = Math.max(0, from - cells);
|
|
118
129
|
const styled = end - Math.max(from, cells);
|
|
119
|
-
out += ' '.repeat(gap) + style.on + ' '.repeat(styled) + style.off;
|
|
130
|
+
out += ' '.repeat(gap) + style.on + ' '.repeat(styled) + (style.restore === true ? '\x1b[0m' : style.off);
|
|
120
131
|
}
|
|
121
132
|
return out;
|
|
122
133
|
}
|
|
@@ -10,12 +10,11 @@
|
|
|
10
10
|
// what the viewport needs to scroll to one and what `highlightCells` needs to
|
|
11
11
|
// paint one.
|
|
12
12
|
import { styleCells, walkRow } from '../ansi-cells.js';
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const SELECTED_HIT_STYLE = { on: '\x1b[7m\x1b[4m', off: '\x1b[24m\x1b[27m' };
|
|
13
|
+
/** Hits are painted as backgrounds with black text, the way an editor marks
|
|
14
|
+
* find results: white for every hit, amber for the one you are standing on, so
|
|
15
|
+
* a screen full of hits still says which of them `n` will leave. */
|
|
16
|
+
const HIT_STYLE = { on: '\x1b[107m\x1b[30m', off: '', restore: true };
|
|
17
|
+
const SELECTED_HIT_STYLE = { on: '\x1b[48;5;214m\x1b[30m', off: '', restore: true };
|
|
19
18
|
function plainRow(line) {
|
|
20
19
|
let text = '';
|
|
21
20
|
const cells = [];
|
|
@@ -1913,7 +1913,7 @@ ${pis(t)}
|
|
|
1913
1913
|
|
|
1914
1914
|
`)}registerCopyBlock(t,r,i){let o=this.condensedCopyBlocks.get(this.appendTarget);if(o){let u=o.findIndex(p=>p.block===t);u===-1?o.push({block:t,kind:r,text:i}):o[u].text=i;return}let a=this.copyIndex.get(t);a===void 0?(this.copyIndex.set(t,this.copyBlockRecords.length),this.copyBlockRecords.push({block:t,kind:r,text:i})):this.copyBlockRecords[a].text=i}unregisterCopyBlock(t){let r=this.condensedCopyBlocks.get(this.appendTarget);if(r){let o=r.findIndex(a=>a.block===t);o!==-1&&r.splice(o,1);return}let i=this.copyIndex.get(t);if(i!==void 0){this.copyBlockRecords.splice(i,1),this.copyIndex.delete(t);for(let o=i;o<this.copyBlockRecords.length;o++)this.copyIndex.set(this.copyBlockRecords[o].block,o)}}appendCondensedBlock({component:t,copyBlocks:r}){this.append(t),this.registerCopyBlock(t,"condensed",r.map(i=>i.text).filter(i=>i.trim()!=="").join(`
|
|
1915
1915
|
|
|
1916
|
-
`))}toolResultText(t){if(typeof t=="string")return t;if(typeof t=="object"&&t!==null&&"content"in t){let r=t.content;if(typeof r=="string")return r;if(Array.isArray(r))return r.filter(i=>typeof i=="object"&&i!==null&&i.type==="text"&&typeof i.text=="string").map(i=>i.text).join("")}try{let r=JSON.stringify(t);return typeof r=="string"?r:""}catch{return""}}pushTranscriptText(t){let r=t.trim();if(r==="")return;let i=g9t([r],this.cwd);if(i.length===0)return;let o=[...i,...this.transcriptFilePaths.filter(a=>!i.includes(a))].slice(0,50);this.transcriptFilePaths.splice(0,this.transcriptFilePaths.length,...o)}pushTranscriptValue(t){try{let r=typeof t=="string"?t:JSON.stringify(t);typeof r=="string"&&this.pushTranscriptText(r)}catch{}}userMessageText(t){let r=t.content;return typeof r=="string"?r:Array.isArray(r)?r.filter(i=>typeof i=="object"&&i!==null&&i.type==="text").map(i=>i.text).join(""):""}};var fos="\x1B[2m\u2338 image \u2014 scroll to view\x1B[22m",S1e={first:-1,last:-1,lastFullyVisible:-1};function mos(e){return e.some(t=>t.includes("\x1B_G")||t.includes("\x1B]1337;File="))}function hos(e,t,r){let i=0,o=e.blockCount();for(;i<o;){let a=Math.floor((i+o)/2);e.blockStart(a,r)+e.blockHeight(a,r)>t?o=a:i=a+1}return i}function s7n(e,t){let r={follow:!0,anchor:void 0},i,o=0,a=S1e,u;function p(f,g,E){let v=Math.max(0,E-g);if(r.follow)return v;if(!r.anchor)return r.follow=!0,v;let T=e.anchorLine(r.anchor,f);return T===void 0?(r.follow=!0,r.anchor=void 0,v):Math.min(Math.max(0,T),v)}function m(f,g,E,v){let T=Math.min(E,v+g);if(v>=T)return{top:v,bottom:T,total:E,blocks:S1e};let C=e.blockCount(),w=hos(e,v,f),P=-1,k=-1,D=-1;for(;w<C;){let z=e.blockStart(w,f);if(z>=T)break;let Z=e.blockHeight(w,f),H=z+Z;H>v&&(P===-1&&(P=w),k=w,z>=v&&H<=T&&(D=w)),w++}return{top:v,bottom:T,total:E,blocks:P===-1?S1e:{first:P,last:k,lastFullyVisible:D}}}function _(){if(i===void 0||o<=0)return;let f=e.totalHeight(i),g=p(i,o,f);return m(i,o,f,g)}return{renderSlice(f,g){let E=Math.max(0,g);if(i=f,o=E,E===0)return a=S1e,u=e.revision(),[];let v=e.totalHeight(f),T=p(f,E,v),C=m(f,E,v,T),w=[];for(let k=C.blocks.first;k!==-1&&k<=C.blocks.last;k++){let D=e.blockStart(k,f),z=e.blockLines(k,f),Z=e.blockHeight(k,f),H=D+Z,J=Math.max(0,C.top-D),ne=Math.min(Z,C.bottom-D);if(J>=ne)continue;if((D<C.top||H>C.bottom)&&mos(z))w.push(...Array(ne-J).fill(fos));else if(t===void 0)w.push(...z.slice(J,ne));else for(let be=J;be<ne;be++)w.push(t(D+be,z[be],f))}let P=w.length>=E?w.slice(0,E):[...Array(E-w.length).fill(""),...w];return a=C.blocks,u=e.revision(),P},scrollBy(f){if(i===void 0||o<=0||f===0)return!1;let g=r.follow,E=r.anchor,v=e.totalHeight(i),T=p(i,o,v),C=Math.max(0,v-o),w=Math.min(Math.max(0,T+f),C);return w>=C?(r.follow=!0,r.anchor=void 0):(r.follow=!1,r.anchor=e.anchorAt(w,i),r.anchor||(r.follow=!0)),r.follow!==g||r.anchor!==E},pageRows(){return Math.max(0,o-1)},goLive(){r.follow=!0,r.anchor=void 0},scrollToLine(f){if(i===void 0||o<=0)return;let g=e.totalHeight(i),E=Math.max(0,g-o),v=Math.min(Math.max(0,f-Math.floor(o/3)),E);if(v>=E){r.follow=!0,r.anchor=void 0;return}r.follow=!1,r.anchor=e.anchorAt(v,i),r.anchor||(r.follow=!0)},topLine(){if(!(i===void 0||o<=0))return p(i,o,e.totalHeight(i))},isLive(){return r.follow},visibleBlocks(){let f=e.revision();return u===f||(a=_()?.blocks??S1e,u=f),a},invalidate(){e.invalidate()}}}var _os=new Intl.Segmenter(void 0,{granularity:"grapheme"}),gos="\x1B[7m",yos="\x1B[27m";function bos(e,t){let r=e[t+1];if(r!==void 0){if(r==="]"||r==="_"||r==="P"||r==="^"){let i=e.indexOf("\x07",t+2),o=e.indexOf("\x1B\\",t+2),a=i===-1?o:o===-1?i:Math.min(i,o);return a===-1?void 0:{text:e.slice(t,a+(a===i?1:2)),end:a+(a===i?1:2)}}if(r==="["){let i=t+2;for(;i<e.length&&(e.charCodeAt(i)<64||e.charCodeAt(i)>126);)i++;return i>=e.length?void 0:{text:e.slice(t,i+1),end:i+1}}return{text:e.slice(t,t+2),end:t+2}}}function zme(e,t){let r=0,i=0;for(;i<e.length;){if(e[i]==="\x1B"){let u=bos(e,i);if(u===void 0)break;t.onEscape?.(u.text),i=u.end;continue}let o=e.indexOf("\x1B",i),a=e.slice(i,o===-1?void 0:o);for(let u of _os.segment(a)){let p=OE(u.segment);t.onGlyph?.({text:u.segment,cell:r,width:p}),r+=p}i=o===-1?e.length:o}return r}function a7n(e,t,r){let i="";return zme(e,{onGlyph:o=>{o.cell>=t&&o.cell<r&&(i+=o.text)}}),i}var Eos={on:gos,off:yos};function J9t(e,t,r,i,o=Eos){let a=Math.min(r,i);if(a<=t||t<0)return e;let u="",p=!1,m=()=>{p||(u+=o.on,p=!0)},_=()=>{p&&(u+=o.off,p=!1)},f=zme(e,{onEscape:g=>{u+=g,p&&g.endsWith("m")&&(u+=o.on)},onGlyph:g=>{g.cell>=t&&g.cell<a?m():_(),u+=g.text}});if(_(),f<a){let g=Math.max(0,t-f),E=a-Math.max(t,f);u+=" ".repeat(g)+o.on+" ".repeat(E)+o.off}return u}function c7n(e,t,r,i){return J9t(e,t,r,i)}var Aos={on:"\x1B[7m",off:"\x1B[27m"},Sos={on:"\x1B[7m\x1B[4m",off:"\x1B[24m\x1B[27m"};function Tos(e){let t="",r=[],i=zme(e,{onGlyph:o=>{for(let a=0;a<o.text.length;a++)r.push(o.cell);t+=o.text}});return{text:t,cells:r,width:i}}function vos(e){return e!==e.toLowerCase()}function Cos(e,t,r,i,o){let a=r?e.text:e.text.toLowerCase(),u=r?t:t.toLowerCase(),p=a.indexOf(u);for(;p!==-1;){let m=p+u.length,_=e.cells[p]??0,f=m<e.cells.length?e.cells[m]:e.width;f>_&&o.push({line:i,from:_,to:f}),p=a.indexOf(u,p+Math.max(1,u.length))}}function l7n(e){let t="",r=0,i=[],o=new Map,a,u;function p(m){let _=`${m}:${e.revision()}:${t}`;if(a===_)return i;let f=[];if(t!==""){let E=vos(t),v=e.blockCount();for(let T=0;T<v;T++){let C=e.blockStart(T,m),w=e.blockLines(T,m);for(let P=0;P<w.length;P++){let k=w[P];k.toLowerCase().includes(t.toLowerCase())&&Cos(Tos(k),t,E,C+P,f)}}}let g=new Map;for(let E of f){let v=g.get(E.line);v?v.push(E):g.set(E.line,[E])}if(i=f,o=g,a=_,u!==void 0){let E=u;u=void 0;let v=f.findIndex(T=>T.line>=E);r=v===-1?Math.max(0,f.length-1):v}else r>=f.length&&(r=Math.max(0,f.length-1));return i}return{setQuery(m,_){m!==t&&(t=m,u=_,a=void 0)},query(){return t},matches(m){return p(m)},current(m){return p(m)[r]},status(m){let _=p(m);return{index:_.length===0?0:r+1,total:_.length}},step(m,_){let f=p(m);if(f.length!==0)return r=(r+_+f.length)%f.length,f[r]},selectNear(m,_){let f=p(m);if(f.length===0)return;let g=f.findIndex(E=>E.line>=_);return r=g===-1?f.length-1:g,f[r]},decorate(m,_,f){if(t==="")return _;let g=p(f),E=o.get(m);if(E===void 0)return _;let v=g[r],T=_;for(let C of E)T=J9t(T,C.from,C.to,f,C===v?Sos:Aos);return T}}}import{existsSync as A7n,readFileSync as S7n}from"node:fs";import{join as T7n}from"node:path";import{spawnSync as Ios}from"node:child_process";import{readFileSync as xos}from"node:fs";function u7n(){try{let e=xos("/proc/sys/kernel/random/boot_id","utf8").trim();return e.length>0?e:null}catch{return null}}function wos(e){try{let t=Ios("ps",["-o","stat=","-p",String(e)],{encoding:"utf8",timeout:2e3});if(t.error!=null||t.signal!=null||typeof t.stdout!="string"||typeof t.stderr=="string"&&t.stderr.trim()!=="")return"unknown";let r=t.stdout.trim();return r===""?"gone":r.charAt(0)==="Z"?"zombie":"live"}catch{return"unknown"}}function F9(e){if(e==null)return!1;try{process.kill(e,0)}catch(r){return r.code==="EPERM"}let t=wos(e);return t!=="zombie"&&t!=="gone"}var Ros=6e4;function kos(e,t=Date.now,r=Ros){let i=null,o=0;return()=>{if(i!==null)return i;let a=t();if(a<o)return null;let u=e();return u!==null?i=u:(o=a+r,null)}}var twu=kos(u7n);import{existsSync as Nos,writeFileSync as iwu,rmSync as owu,mkdirSync as swu,statSync as awu}from"node:fs";import{join as Pos}from"node:path";function Oos(e){return Pos(x4(e),"busy")}function p7n(e){return Nos(Oos(e))}import{existsSync as gwu,mkdirSync as $os,readFileSync as zos,rmSync as jos,writeFileSync as qos}from"node:fs";import{join as Gos}from"node:path";var Dos="crtr:managed-provider-cooling";function d7n(e){let t=e?.diagnostics;return Array.isArray(t)&&t.some(r=>r?.type===Dos)}function bet(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var Mos={"rate-limit":"rate_limit",overloaded:"overloaded",connection:"connection",auth:"auth",protocol:"protocol","context-overflow":"context_overflow",wedged:"wedged","model-not-found":"model_not_found",other:"unknown"};function K9t(e){return{class:Mos[e.kind],retry_disposition:e.retry.disposition}}function Y9t(e){return typeof e=="string"?e:""}function f7n(e){let t=e??"";return/rate.?limit|\b429\b|too many requests|quota/i.test(t)?"rate-limit":/\b413\b|payload too large|entity too large|request too large|entity\.too\.large|body exceeds/i.test(t)?"protocol":/invalid_grant|refresh token|unauthori[sz]ed|invalid.?api.?key|authentication failed|\b401\b|\b403\b/i.test(t)?"auth":/context overflow recovery failed/i.test(t)?"context-overflow":/websocket.*(?:closed.*\b(?:1002|1003|1007|1008|1009|1010)\b|protocol error|policy violation|unsupported data|invalid (?:frame|payload)|message too big|mandatory extension)/i.test(t)?"protocol":/overloaded|\b5\d\d\b|internal server error|api.?error|capacity|server.{0,3}busy|temporarily unavailable/i.test(t)?"overloaded":/connection|econnreset|etimedout|enotfound|econnrefused|network|fetch failed|socket hang|timed? out|timeout|\bterminated\b|other side closed|premature close|websocket\s+(?:was\s+)?closed|websocket stream closed before response\.completed|websocket\s+error|websocket.*interrupt/i.test(t)?"connection":"other"}function Los(e){let t=Y9t(e.code)||Y9t(e.errno);return t===""?null:/^(ECONNREFUSED|ECONNRESET|ETIMEDOUT|ENOENT|ENOTFOUND|EAI_AGAIN|EPIPE|EHOSTUNREACH|ENETUNREACH)$/i.test(t)?"connection":null}function Fos(e){let t=typeof e.status=="number"?e.status:null;return t===null?null:t===401||t===403?"auth":t===429?"rate-limit":t===503||t===529||t>=500&&t<=599?"overloaded":t>=400&&t<=499?"protocol":null}function Bos(e){let t=typeof e.code=="number"?e.code:null;if(t===null)return null;if(t===1008)return"protocol";if(t===1006)return"connection";if(t===1011){let r=Y9t(e.reason);return/no running broker/i.test(r)||f7n(r)==="connection"?"connection":"other"}return null}function Eet(e,t){return t==="auth"||t==="protocol"||t==="context-overflow"?"fatal":e==="pi\u2192provider"?t==="connection"||t==="rate-limit"||t==="overloaded"?"auto":"fatal":"manual"}function Uos(e){if(typeof e=="string")return e;if(!bet(e))return"";let t=[e.message,e.errorMessage,e.reason,e.body,e.statusText];for(let i of t)if(typeof i=="string"&&i!=="")return i;let r=e.error;if(bet(r)){let i=r.message;if(typeof i=="string"&&i!=="")return i;let o=r.reason;if(typeof o=="string"&&o!=="")return o}return""}function Aet(e,t){if(e==="pi\u2192provider"&&d7n(t))return{kind:"rate-limit",disposition:"auto"};if(bet(t)){let i=Los(t);if(i!==null)return{kind:i,disposition:Eet(e,i)};let o=Fos(t);if(o!==null)return{kind:o,disposition:Eet(e,o)};let a=Bos(t);if(a!==null)return{kind:a,disposition:Eet(e,a)}}let r=f7n(Uos(t));return{kind:r,disposition:Eet(e,r)}}var Vos=5*6e4,Wos=500;function X9t(e){return Gos(x4(e),"fault")}function Qos(e){return e.slice(0,Wos)}function m7n(e){return e.link==="pi\u2192provider"&&e.retry.disposition==="auto"&&e.retry.by==="daemon"?3:e.retry.disposition==="fatal"?2:1}var Hos=["pi\u2192provider","viewer\u2194broker","relay\u2194broker","viewer\u2194crtrd","daemon\u2192node","crtr\u2192pi"],Jos=["rate-limit","overloaded","connection","auth","protocol","context-overflow","other","wedged","model-not-found"];function Yos(e){try{let t=JSON.parse(e);if(!Hos.includes(t.link)||typeof t.op!="string"||t.op===""||!Jos.includes(t.kind)||typeof t.message!="string"||typeof t.since!="string")return null;let r=LY(t.operation_id),i=t.retry;return i===void 0||i.disposition!=="auto"&&i.disposition!=="manual"&&i.disposition!=="fatal"||i.by!==void 0&&i.by!=="sdk"&&i.by!=="daemon"&&i.by!=="client"||i.attempt!==void 0&&typeof i.attempt!="number"||i.max!==void 0&&typeof i.max!="number"||i.nextAt!==void 0&&typeof i.nextAt!="string"||t.anchorEntryId!==void 0&&(typeof t.anchorEntryId!="string"||t.anchorEntryId==="")?null:{link:t.link,op:t.op,kind:t.kind,retry:{disposition:i.disposition,...i.by===void 0?{}:{by:i.by},...i.attempt===void 0?{}:{attempt:i.attempt},...i.max===void 0?{}:{max:i.max},...i.nextAt===void 0?{}:{nextAt:i.nextAt}},message:t.message,since:t.since,operation_id:r,...t.anchorEntryId===void 0?{}:{anchorEntryId:t.anchorEntryId}}}catch{return null}}function Z9t(e){try{return Yos(zos(X9t(e),"utf8"))}catch{return null}}function Kos(e,t){try{$os(x4(e),{recursive:!0}),qos(X9t(e),JSON.stringify(t))}catch{}}function Xos(e,t){let r=Z9t(e);if(r!==null){if(r.link===t.link&&r.kind===t.kind){let i={...r.retry,...t.retry};t.retry.disposition==="fatal"&&!("nextAt"in t.retry)&&delete i.nextAt,t={...t,since:r.since,anchorEntryId:r.anchorEntryId??t.anchorEntryId,retry:i}}else if(m7n(r)>m7n(t))return}Kos(e,t)}function h7n(e){if(e!==void 0)return LY(e);let t=WSe.current();return t!==void 0?t:WSe.fresh(r=>r)}function _7n(e,t){let r=h7n(t.operation_id),i={link:t.link,op:t.op,kind:t.kind,retry:t.retry,message:Qos(t.message),since:t.since??new Date().toISOString(),operation_id:r,...typeof t.anchorEntryId=="string"&&t.anchorEntryId!==""?{anchorEntryId:t.anchorEntryId}:{}};$Y({level:i.retry.disposition==="fatal"?"error":"warn",event:"fault.recorded",operation_id:r,node_id:e,error_class:K9t(i),fields:{link:i.link,op:i.op,kind:i.kind,retry:i.retry,message:i.message,...i.anchorEntryId===void 0?{}:{anchor_entry_id:i.anchorEntryId}}}),Xos(e,i)}function Tet(e,t){try{let r=Z9t(e);if(r===null||t?.link!==void 0&&r.link!==t.link)return!1;jos(X9t(e));let i=h7n();return $Y({level:"info",event:"fault.cleared",operation_id:i,node_id:e,error_class:K9t(r),fields:{cleared_fault_operation_id:r.operation_id,link:r.link,op:r.op,kind:r.kind,retry:r.retry,message:r.message,since:r.since,...r.anchorEntryId===void 0?{}:{anchor_entry_id:r.anchorEntryId}}}),!0}catch{return!1}}function T1e(e){return Z9t(e)}function g7n(e,t,r=5e3){let i=/^[\x20-\x7e]+$/.test(t);return async function(a,u){if(!i)return{ok:!1,stdout:"",stderr:"remote source: invalid stored relay token"};let p={kind:"exec",bin:a,args:u},m=new AbortController,_=setTimeout(()=>m.abort(),r),f;try{f=await fetch(new URL("/__crtr/source",e),{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${t}`},body:JSON.stringify(p),signal:m.signal})}catch{return m.signal.aborted?{ok:!1,stdout:"",stderr:`remote source: timeout after ${r}ms`}:{ok:!1,stdout:"",stderr:"remote source: network error"}}finally{clearTimeout(_)}return f.ok?await f.json():{ok:!1,stdout:"",stderr:`remote source: HTTP ${f.status} ${f.statusText}`}}}var eQt=1e3;function Yz(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Zos(e){if(!Yz(e))return!1;let t=e.node;if(!Yz(t)||typeof t.node_id!="string"||!Array.isArray(e.reports)||!Array.isArray(e.managers))return!1;let r=e.artifacts;if(!Yz(r)||typeof r.report!="number"||typeof r.doc!="number"||typeof r.roadmap!="number"||typeof e.pending_crons!="number")return!1;let i=e.paths;return!(!Yz(i)||typeof i.context_dir!="string"||typeof i.reports_dir!="string"||"session_file"in i&&i.session_file!==null&&typeof i.session_file!="string"||typeof e.follow_up!="string")}function y7n(e){return Yz(e)&&typeof e.node_id=="string"&&typeof e.name=="string"&&typeof e.kind=="string"&&typeof e.status=="string"&&typeof e.active=="boolean"}function ess(e){return Yz(e)?typeof e.node_id=="string"&&typeof e.name=="string"&&typeof e.kind=="string"&&typeof e.mode=="string"&&typeof e.lifecycle=="string"&&typeof e.status=="string"&&typeof e.cwd=="string"&&typeof e.created=="string":!1}var Kz=class{constructor(t,r){this.previewEndpoint=t;this.relayToken=r;this.exec=g7n(t,r)}previewEndpoint;relayToken;exec;nodeCache=new Map;rosterCache=new Map;viewCache=new Map;async execJson(t){let r;try{r=await this.exec("crtr",["--json",...t])}catch{return null}if(!r.ok||r.exitCode!==void 0&&r.exitCode!==0)return null;try{return JSON.parse(r.stdout.trim())}catch{return null}}async fetchShow(t){let r=this.nodeCache.get(t);if(r&&Date.now()-r.at<eQt)return r.value;let i=await this.execJson(["node","inspect","show",t]),o=Zos(i)?{...i,reports:i.reports.filter(y7n),managers:i.managers.filter(y7n)}:null;return this.nodeCache.set(t,{value:o,at:Date.now()}),o}async rawShow(t){return this.fetchShow(t)}async getNode(t){return(await this.fetchShow(t))?.node??null}async getRow(t){let r=(await this.fetchShow(t))?.node;return r?{node_id:r.node_id,name:r.name,kind:r.kind,mode:r.mode,lifecycle:r.lifecycle,status:r.status,cwd:r.cwd,host_kind:r.host_kind??null,profile_id:r.profile_id??null,parent:r.parent??null,created:r.created,intent:r.intent??null,waiting_for:r.waiting_for??null,pi_pid:r.pi_pid??null,pi_pid_identity:r.pi_pid_identity??null,window:r.window??null,tmux_session:r.tmux_session??null,pane:r.pane??null}:null}async listNodes(t){let r=JSON.stringify(t?.status??null),i=this.rosterCache.get(r);if(i&&Date.now()-i.at<eQt)return i.value;let o=["node","inspect","list"];t?.status&&o.push("--status",(Array.isArray(t.status)?t.status:[t.status]).join(","));let a=await this.execJson(o),p=(Yz(a)&&Array.isArray(a.nodes)?a.nodes:[]).filter(ess);return this.rosterCache.set(r,{value:p,at:Date.now()}),p}async subscriptionsOf(t){return((await this.fetchShow(t))?.reports??[]).map(i=>({node_id:i.node_id,active:i.active,created:""}))}async subscribersOf(t){return((await this.fetchShow(t))?.managers??[]).map(i=>({node_id:i.node_id,active:i.active,created:""}))}async view(t){let r=this.viewCache.get(t);if(r&&Date.now()-r.at<eQt)return r.value;let i=new Set([t]),o=[],a=(await this.subscriptionsOf(t)).map(u=>u.node_id);for(;a.length>0;){let u=a.shift();if(!i.has(u)){i.add(u),o.push(u);for(let p of await this.subscriptionsOf(u))i.has(p.node_id)||a.push(p.node_id)}}return this.viewCache.set(t,{value:o,at:Date.now()}),o}async ticketCountsForView(t){let r=await this.execJson(["canvas","attention","map","--view",t]);return Yz(r)&&Yz(r.counts)?r.counts:{}}async hasActiveLiveSubscription(t){let r=(await this.subscriptionsOf(t)).filter(i=>i.active);for(let i of r){let o=await this.getRow(i.node_id);if(o&&(o.status==="active"||o.status==="idle"))return!0}return!1}};function tQt(e){return e==="orchestrator"?"\uF0E8":"\uF007"}function rQt(e){let t=(e.description??"").trim(),i=[e.name&&e.name!==e.kind?e.name:"",t].filter(o=>o!=="").join(" ");return i!==""?i:e.name}function b7n(e){return`${tQt(e.mode)} ${e.kind}`}var tss={active:"\u25CF",idle:"\u25CB",done:"\u2713",dead:"\u2717",canceled:"\u2298"},rss={active:32,idle:33,done:36,dead:31,canceled:90},nss="\u27F3",iss=92,oss="\u26A0",sss=33;function E7n(e){switch(e){case"rate-limit":return"rate-limited";case"overloaded":return"overloaded";case"connection":return"down";case"auth":return"auth";case"protocol":return"protocol";case"context-overflow":return"context-overflow";case"wedged":return"wedged";case"model-not-found":return"model-not-found";default:return"other"}}function nQt(e,t){return t.hanging!=null?{glyph:oss,color:sss,word:E7n(t.hanging.kind),bold:!0}:t.streaming===!0?{glyph:nss,color:iss,word:"live",bold:!0}:{glyph:tss[e]??"?",color:rss[e]}}function ass(e,t){let r=Date.parse(e);if(Number.isNaN(r))return"now";let i=r-t;return i<=0?"now":i>=6e4?`${Math.max(1,Math.round(i/6e4))}m`:`${Math.max(1,Math.ceil(i/1e3))}s`}function css(e){return e.retry.disposition!=="auto"}function lss(e,t=Date.now()){let r=e.retry;if(!css(e)){if(r.by==="client")return"redialing";let i=typeof r.attempt=="number"&&typeof r.max=="number"?`auto-retry ${r.attempt}/${r.max}`:"auto-retrying";return r.nextAt?`${i}, next ${ass(r.nextAt,t)}`:i}return"needs you"}function iQt(e,t=Date.now()){return`${e.link} ${E7n(e.kind)} \xB7 ${lss(e,t)}`}function vet(e,t){return t===null||t.link==="pi\u2192provider"&&t.retry.by==="daemon"&&t.retry.disposition==="auto"&&!F9(e.pi_pid)?null:t}var v7n=30,mB="\x1B[",Fg=`${mB}0m`,v1e=`${mB}1m`,sw=`${mB}2m`,Cet=`${mB}7m`,C7n=`${mB}48;5;22m`,xet=`${mB}32m`,Vwu=`${mB}31m`,C1e=`${mB}33m`,Wwu=`${mB}36m`,Qwu=`${mB}90m`;function uss(e){return vet(e,T1e(e.node_id))}function pss(e){return e.status!=="active"&&e.status!=="idle"||!F9(e.pi_pid)?!1:p7n(e.node_id)}function Iet(e,t=!1){if(e===null)return"?";let r=nQt(e.status,{streaming:t?!1:pss(e),hanging:t?null:uss(e)});return`${mB}${r.color}m${r.glyph}${Fg}`}var x7n=/\x1b\[[0-9;]*m/g;function I7n(e){return e.replace(x7n,"")}function EL(e){return e.replace(x7n,"").length}function x1e(e,t=Xz()){if(EL(e)<=t)return e;let r="",i=0,o=0;for(;o<e.length&&i<t-1;){if(e[o]==="\x1B"){let a=/^\x1b\[[0-9;]*m/.exec(e.slice(o));if(a){r+=a[0],o+=a[0].length;continue}}r+=e[o],i++,o++}return`${r}\u2026${Fg}`}function Xz(){return Math.max(20,Math.min((process.stdout.columns??80)-2,180))}function I1e(e,t,r){let i=x1e(e,t),o=i.replace(/\x1b\[0m/g,`${Fg}${r}`),a=Math.max(0,t-EL(i));return`${r}${o}${" ".repeat(a)}${Fg}`}var oQt=new Map;function w1e(){oQt.clear()}function w7n(e){let t=oQt.get(e);if(t!==void 0)return t;let r;try{let i=T7n(x4(e),"telemetry.json");r=A7n(i)?JSON.parse(S7n(i,"utf8")):{}}catch{r={}}return oQt.set(e,r),r}function dss(e){return e<1e3?`${e}`:`${Math.round(e/1e3)}k`}function wet(e,t=!1){return dss(t?0:w7n(e).context_tokens??0)}function Ret(e,t,r=!1){if(r||t?.status!=="active")return"";let i=(w7n(e).last_activity??"").trim();return i===""?"":` ${sw}\xB7 ${i}${Fg}`}function ket(e){let t=e?.cycles??0;return t>0?` ${sw}\u27F3${t}${Fg}`:""}function R1e(e,t){if(e===null)return Net(t);let r=e.name&&e.name!==e.kind?e.name:"";if(r!=="")return r;let i=(e.description??"").trim();return i!==""?i:e.name}function Net(e){return e.slice(0,8)}function fss(e,t,r=!1){if(r||t?.status!=="active")return!1;try{let i=T7n(x4(e),"attach.json");if(!A7n(i))return!1;let o=JSON.parse(S7n(i,"utf8"));return typeof o.viewers=="number"&&o.viewers>0}catch{return!1}}function R7n(e,t,r,i=!1){return i?!1:r.has(e)?!0:fss(e,t,i)}function Pet(e,t){let r=t[e]??0;return r>0?` ${C1e}\u2691${r}${Fg}`:""}var Hwu=`${sw}jk move \xB7 hl fold \xB7 \u21B5 focus \xB7 e expand \xB7 x kill \xB7 m mgr \xB7 esc${Fg}`;var mss=["crtr.attach.scroll.up","crtr.attach.scroll.down","crtr.attach.scroll.page-up","crtr.attach.scroll.page-down","crtr.attach.scroll.live","crtr.attach.mouse.toggle","crtr.attach.copy.message"];function ite(e,t,r){return qY(e,t,jY(r),(i,o)=>Kc(i,o))}function sQt(e,t){t[e]()}function k7n(e,t,r){for(let{actionId:i}of I4)if(ite(e,i,t))return sQt(i,r),!0;return!1}function N7n(e,t,r){for(let i of mss)if(ite(e,i,t))return r[i](),!0;return!1}function P7n(e){for(let t of["crtr.attach.clear-or-detach","crtr.attach.detach"])if(e.gestures(t).length>0)return FI(e,t)}function aQt(e,t,r,i){let o=e();if(t(o.bindings),r())try{i(o.bindings,o.tmuxPassthrough)}catch{}return o}function O7n(e){if(e!==""){for(let t of e){let r=t.codePointAt(0);if(r<32||r===127)return}return e}}function D7n(e,t,r,i,o){let a="closed",u=0,p="",m=()=>e.terminal.columns,_=w=>{w!==void 0&&r.scrollToLine(w.line),e.requestRender()},f=()=>{i.setQuery(p,u),_(i.current(m()))},g=()=>{a="closed",p="",i.setQuery("",void 0),e.requestRender()},E=()=>{a==="closed"&&(u=r.topLine()??0),a="editing",p=i.query(),e.requestRender()},v=w=>{let P=i.step(m(),w);if(P===void 0){o.setNotice(`No matches for \u201C${i.query()}\u201D`);return}_(P)};return{component:{render(w){if(a==="closed")return[];let{index:P,total:k}=i.status(w),D=a==="editing"?`${t.accent("\u2315")} ${p}${t.accent("\u258C")}`:`${t.accent("\u2315")} ${p}`,z=k===0?i.query()===""?t.faint("type to search what is on screen"):t.error("no matches"):t.info(`${P}/${k}`),Z=a==="editing"?t.faint("enter browse \xB7 esc cancel"):t.faint([`${FI(o.bindings(),"crtr.attach.search.next")} next`,`${FI(o.bindings(),"crtr.attach.search.previous")} prev`,`${FI(o.bindings(),"crtr.attach.search.edit")} edit`,`${FI(o.bindings(),"crtr.attach.search.close")} close`].join(" \xB7 ")),H=`${z} ${Z}`,J=w-EL(D)-EL(H)-2;return[J<1?_l(` ${D}`,w,"",!0):` ${D}${" ".repeat(J)}${H} `]},invalidate(){}},open:E,close:g,handleKey:w=>{if(a==="closed")return!1;let P=o.bindings();if(ite(P,"crtr.attach.search.close",w))return g(),!0;if(a==="editing"){if(w==="")return g(),!0;if(w==="\r"||w===`
|
|
1916
|
+
`))}toolResultText(t){if(typeof t=="string")return t;if(typeof t=="object"&&t!==null&&"content"in t){let r=t.content;if(typeof r=="string")return r;if(Array.isArray(r))return r.filter(i=>typeof i=="object"&&i!==null&&i.type==="text"&&typeof i.text=="string").map(i=>i.text).join("")}try{let r=JSON.stringify(t);return typeof r=="string"?r:""}catch{return""}}pushTranscriptText(t){let r=t.trim();if(r==="")return;let i=g9t([r],this.cwd);if(i.length===0)return;let o=[...i,...this.transcriptFilePaths.filter(a=>!i.includes(a))].slice(0,50);this.transcriptFilePaths.splice(0,this.transcriptFilePaths.length,...o)}pushTranscriptValue(t){try{let r=typeof t=="string"?t:JSON.stringify(t);typeof r=="string"&&this.pushTranscriptText(r)}catch{}}userMessageText(t){let r=t.content;return typeof r=="string"?r:Array.isArray(r)?r.filter(i=>typeof i=="object"&&i!==null&&i.type==="text").map(i=>i.text).join(""):""}};var fos="\x1B[2m\u2338 image \u2014 scroll to view\x1B[22m",S1e={first:-1,last:-1,lastFullyVisible:-1};function mos(e){return e.some(t=>t.includes("\x1B_G")||t.includes("\x1B]1337;File="))}function hos(e,t,r){let i=0,o=e.blockCount();for(;i<o;){let a=Math.floor((i+o)/2);e.blockStart(a,r)+e.blockHeight(a,r)>t?o=a:i=a+1}return i}function s7n(e,t){let r={follow:!0,anchor:void 0},i,o=0,a=S1e,u;function p(f,g,E){let v=Math.max(0,E-g);if(r.follow)return v;if(!r.anchor)return r.follow=!0,v;let T=e.anchorLine(r.anchor,f);return T===void 0?(r.follow=!0,r.anchor=void 0,v):Math.min(Math.max(0,T),v)}function m(f,g,E,v){let T=Math.min(E,v+g);if(v>=T)return{top:v,bottom:T,total:E,blocks:S1e};let C=e.blockCount(),w=hos(e,v,f),P=-1,k=-1,D=-1;for(;w<C;){let z=e.blockStart(w,f);if(z>=T)break;let Z=e.blockHeight(w,f),H=z+Z;H>v&&(P===-1&&(P=w),k=w,z>=v&&H<=T&&(D=w)),w++}return{top:v,bottom:T,total:E,blocks:P===-1?S1e:{first:P,last:k,lastFullyVisible:D}}}function _(){if(i===void 0||o<=0)return;let f=e.totalHeight(i),g=p(i,o,f);return m(i,o,f,g)}return{renderSlice(f,g){let E=Math.max(0,g);if(i=f,o=E,E===0)return a=S1e,u=e.revision(),[];let v=e.totalHeight(f),T=p(f,E,v),C=m(f,E,v,T),w=[];for(let k=C.blocks.first;k!==-1&&k<=C.blocks.last;k++){let D=e.blockStart(k,f),z=e.blockLines(k,f),Z=e.blockHeight(k,f),H=D+Z,J=Math.max(0,C.top-D),ne=Math.min(Z,C.bottom-D);if(J>=ne)continue;if((D<C.top||H>C.bottom)&&mos(z))w.push(...Array(ne-J).fill(fos));else if(t===void 0)w.push(...z.slice(J,ne));else for(let be=J;be<ne;be++)w.push(t(D+be,z[be],f))}let P=w.length>=E?w.slice(0,E):[...Array(E-w.length).fill(""),...w];return a=C.blocks,u=e.revision(),P},scrollBy(f){if(i===void 0||o<=0||f===0)return!1;let g=r.follow,E=r.anchor,v=e.totalHeight(i),T=p(i,o,v),C=Math.max(0,v-o),w=Math.min(Math.max(0,T+f),C);return w>=C?(r.follow=!0,r.anchor=void 0):(r.follow=!1,r.anchor=e.anchorAt(w,i),r.anchor||(r.follow=!0)),r.follow!==g||r.anchor!==E},pageRows(){return Math.max(0,o-1)},goLive(){r.follow=!0,r.anchor=void 0},scrollToLine(f){if(i===void 0||o<=0)return;let g=e.totalHeight(i),E=Math.max(0,g-o),v=Math.min(Math.max(0,f-Math.floor(o/3)),E);if(v>=E){r.follow=!0,r.anchor=void 0;return}r.follow=!1,r.anchor=e.anchorAt(v,i),r.anchor||(r.follow=!0)},topLine(){if(!(i===void 0||o<=0))return p(i,o,e.totalHeight(i))},isLive(){return r.follow},visibleBlocks(){let f=e.revision();return u===f||(a=_()?.blocks??S1e,u=f),a},invalidate(){e.invalidate()}}}var _os=new Intl.Segmenter(void 0,{granularity:"grapheme"}),gos="\x1B[7m",yos="\x1B[27m";function bos(e,t){let r=e[t+1];if(r!==void 0){if(r==="]"||r==="_"||r==="P"||r==="^"){let i=e.indexOf("\x07",t+2),o=e.indexOf("\x1B\\",t+2),a=i===-1?o:o===-1?i:Math.min(i,o);return a===-1?void 0:{text:e.slice(t,a+(a===i?1:2)),end:a+(a===i?1:2)}}if(r==="["){let i=t+2;for(;i<e.length&&(e.charCodeAt(i)<64||e.charCodeAt(i)>126);)i++;return i>=e.length?void 0:{text:e.slice(t,i+1),end:i+1}}return{text:e.slice(t,t+2),end:t+2}}}function zme(e,t){let r=0,i=0;for(;i<e.length;){if(e[i]==="\x1B"){let u=bos(e,i);if(u===void 0)break;t.onEscape?.(u.text),i=u.end;continue}let o=e.indexOf("\x1B",i),a=e.slice(i,o===-1?void 0:o);for(let u of _os.segment(a)){let p=OE(u.segment);t.onGlyph?.({text:u.segment,cell:r,width:p}),r+=p}i=o===-1?e.length:o}return r}function a7n(e,t,r){let i="";return zme(e,{onGlyph:o=>{o.cell>=t&&o.cell<r&&(i+=o.text)}}),i}var Eos={on:gos,off:yos};function J9t(e,t,r,i,o=Eos){let a=Math.min(r,i);if(a<=t||t<0)return e;let u="",p=!1,m=[],_=()=>{p||(u+=o.on,p=!0)},f=()=>{p&&(u+=o.restore===!0?`\x1B[0m${m.join("")}`:o.off,p=!1)},g=zme(e,{onEscape:E=>{u+=E,E.endsWith("m")&&(E==="\x1B[0m"||E==="\x1B[m"?m.length=0:m.push(E),p&&(u+=o.on))},onGlyph:E=>{E.cell>=t&&E.cell<a?_():f(),u+=E.text}});if(f(),g<a){let E=Math.max(0,t-g),v=a-Math.max(t,g);u+=" ".repeat(E)+o.on+" ".repeat(v)+(o.restore===!0?"\x1B[0m":o.off)}return u}function c7n(e,t,r,i){return J9t(e,t,r,i)}var Aos={on:"\x1B[107m\x1B[30m",off:"",restore:!0},Sos={on:"\x1B[48;5;214m\x1B[30m",off:"",restore:!0};function Tos(e){let t="",r=[],i=zme(e,{onGlyph:o=>{for(let a=0;a<o.text.length;a++)r.push(o.cell);t+=o.text}});return{text:t,cells:r,width:i}}function vos(e){return e!==e.toLowerCase()}function Cos(e,t,r,i,o){let a=r?e.text:e.text.toLowerCase(),u=r?t:t.toLowerCase(),p=a.indexOf(u);for(;p!==-1;){let m=p+u.length,_=e.cells[p]??0,f=m<e.cells.length?e.cells[m]:e.width;f>_&&o.push({line:i,from:_,to:f}),p=a.indexOf(u,p+Math.max(1,u.length))}}function l7n(e){let t="",r=0,i=[],o=new Map,a,u;function p(m){let _=`${m}:${e.revision()}:${t}`;if(a===_)return i;let f=[];if(t!==""){let E=vos(t),v=e.blockCount();for(let T=0;T<v;T++){let C=e.blockStart(T,m),w=e.blockLines(T,m);for(let P=0;P<w.length;P++){let k=w[P];k.toLowerCase().includes(t.toLowerCase())&&Cos(Tos(k),t,E,C+P,f)}}}let g=new Map;for(let E of f){let v=g.get(E.line);v?v.push(E):g.set(E.line,[E])}if(i=f,o=g,a=_,u!==void 0){let E=u;u=void 0;let v=f.findIndex(T=>T.line>=E);r=v===-1?Math.max(0,f.length-1):v}else r>=f.length&&(r=Math.max(0,f.length-1));return i}return{setQuery(m,_){m!==t&&(t=m,u=_,a=void 0)},query(){return t},matches(m){return p(m)},current(m){return p(m)[r]},status(m){let _=p(m);return{index:_.length===0?0:r+1,total:_.length}},step(m,_){let f=p(m);if(f.length!==0)return r=(r+_+f.length)%f.length,f[r]},selectNear(m,_){let f=p(m);if(f.length===0)return;let g=f.findIndex(E=>E.line>=_);return r=g===-1?f.length-1:g,f[r]},decorate(m,_,f){if(t==="")return _;let g=p(f),E=o.get(m);if(E===void 0)return _;let v=g[r],T=_;for(let C of E)T=J9t(T,C.from,C.to,f,C===v?Sos:Aos);return T}}}import{existsSync as A7n,readFileSync as S7n}from"node:fs";import{join as T7n}from"node:path";import{spawnSync as Ios}from"node:child_process";import{readFileSync as xos}from"node:fs";function u7n(){try{let e=xos("/proc/sys/kernel/random/boot_id","utf8").trim();return e.length>0?e:null}catch{return null}}function wos(e){try{let t=Ios("ps",["-o","stat=","-p",String(e)],{encoding:"utf8",timeout:2e3});if(t.error!=null||t.signal!=null||typeof t.stdout!="string"||typeof t.stderr=="string"&&t.stderr.trim()!=="")return"unknown";let r=t.stdout.trim();return r===""?"gone":r.charAt(0)==="Z"?"zombie":"live"}catch{return"unknown"}}function F9(e){if(e==null)return!1;try{process.kill(e,0)}catch(r){return r.code==="EPERM"}let t=wos(e);return t!=="zombie"&&t!=="gone"}var Ros=6e4;function kos(e,t=Date.now,r=Ros){let i=null,o=0;return()=>{if(i!==null)return i;let a=t();if(a<o)return null;let u=e();return u!==null?i=u:(o=a+r,null)}}var twu=kos(u7n);import{existsSync as Nos,writeFileSync as iwu,rmSync as owu,mkdirSync as swu,statSync as awu}from"node:fs";import{join as Pos}from"node:path";function Oos(e){return Pos(x4(e),"busy")}function p7n(e){return Nos(Oos(e))}import{existsSync as gwu,mkdirSync as $os,readFileSync as zos,rmSync as jos,writeFileSync as qos}from"node:fs";import{join as Gos}from"node:path";var Dos="crtr:managed-provider-cooling";function d7n(e){let t=e?.diagnostics;return Array.isArray(t)&&t.some(r=>r?.type===Dos)}function bet(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var Mos={"rate-limit":"rate_limit",overloaded:"overloaded",connection:"connection",auth:"auth",protocol:"protocol","context-overflow":"context_overflow",wedged:"wedged","model-not-found":"model_not_found",other:"unknown"};function K9t(e){return{class:Mos[e.kind],retry_disposition:e.retry.disposition}}function Y9t(e){return typeof e=="string"?e:""}function f7n(e){let t=e??"";return/rate.?limit|\b429\b|too many requests|quota/i.test(t)?"rate-limit":/\b413\b|payload too large|entity too large|request too large|entity\.too\.large|body exceeds/i.test(t)?"protocol":/invalid_grant|refresh token|unauthori[sz]ed|invalid.?api.?key|authentication failed|\b401\b|\b403\b/i.test(t)?"auth":/context overflow recovery failed/i.test(t)?"context-overflow":/websocket.*(?:closed.*\b(?:1002|1003|1007|1008|1009|1010)\b|protocol error|policy violation|unsupported data|invalid (?:frame|payload)|message too big|mandatory extension)/i.test(t)?"protocol":/overloaded|\b5\d\d\b|internal server error|api.?error|capacity|server.{0,3}busy|temporarily unavailable/i.test(t)?"overloaded":/connection|econnreset|etimedout|enotfound|econnrefused|network|fetch failed|socket hang|timed? out|timeout|\bterminated\b|other side closed|premature close|websocket\s+(?:was\s+)?closed|websocket stream closed before response\.completed|websocket\s+error|websocket.*interrupt/i.test(t)?"connection":"other"}function Los(e){let t=Y9t(e.code)||Y9t(e.errno);return t===""?null:/^(ECONNREFUSED|ECONNRESET|ETIMEDOUT|ENOENT|ENOTFOUND|EAI_AGAIN|EPIPE|EHOSTUNREACH|ENETUNREACH)$/i.test(t)?"connection":null}function Fos(e){let t=typeof e.status=="number"?e.status:null;return t===null?null:t===401||t===403?"auth":t===429?"rate-limit":t===503||t===529||t>=500&&t<=599?"overloaded":t>=400&&t<=499?"protocol":null}function Bos(e){let t=typeof e.code=="number"?e.code:null;if(t===null)return null;if(t===1008)return"protocol";if(t===1006)return"connection";if(t===1011){let r=Y9t(e.reason);return/no running broker/i.test(r)||f7n(r)==="connection"?"connection":"other"}return null}function Eet(e,t){return t==="auth"||t==="protocol"||t==="context-overflow"?"fatal":e==="pi\u2192provider"?t==="connection"||t==="rate-limit"||t==="overloaded"?"auto":"fatal":"manual"}function Uos(e){if(typeof e=="string")return e;if(!bet(e))return"";let t=[e.message,e.errorMessage,e.reason,e.body,e.statusText];for(let i of t)if(typeof i=="string"&&i!=="")return i;let r=e.error;if(bet(r)){let i=r.message;if(typeof i=="string"&&i!=="")return i;let o=r.reason;if(typeof o=="string"&&o!=="")return o}return""}function Aet(e,t){if(e==="pi\u2192provider"&&d7n(t))return{kind:"rate-limit",disposition:"auto"};if(bet(t)){let i=Los(t);if(i!==null)return{kind:i,disposition:Eet(e,i)};let o=Fos(t);if(o!==null)return{kind:o,disposition:Eet(e,o)};let a=Bos(t);if(a!==null)return{kind:a,disposition:Eet(e,a)}}let r=f7n(Uos(t));return{kind:r,disposition:Eet(e,r)}}var Vos=5*6e4,Wos=500;function X9t(e){return Gos(x4(e),"fault")}function Qos(e){return e.slice(0,Wos)}function m7n(e){return e.link==="pi\u2192provider"&&e.retry.disposition==="auto"&&e.retry.by==="daemon"?3:e.retry.disposition==="fatal"?2:1}var Hos=["pi\u2192provider","viewer\u2194broker","relay\u2194broker","viewer\u2194crtrd","daemon\u2192node","crtr\u2192pi"],Jos=["rate-limit","overloaded","connection","auth","protocol","context-overflow","other","wedged","model-not-found"];function Yos(e){try{let t=JSON.parse(e);if(!Hos.includes(t.link)||typeof t.op!="string"||t.op===""||!Jos.includes(t.kind)||typeof t.message!="string"||typeof t.since!="string")return null;let r=LY(t.operation_id),i=t.retry;return i===void 0||i.disposition!=="auto"&&i.disposition!=="manual"&&i.disposition!=="fatal"||i.by!==void 0&&i.by!=="sdk"&&i.by!=="daemon"&&i.by!=="client"||i.attempt!==void 0&&typeof i.attempt!="number"||i.max!==void 0&&typeof i.max!="number"||i.nextAt!==void 0&&typeof i.nextAt!="string"||t.anchorEntryId!==void 0&&(typeof t.anchorEntryId!="string"||t.anchorEntryId==="")?null:{link:t.link,op:t.op,kind:t.kind,retry:{disposition:i.disposition,...i.by===void 0?{}:{by:i.by},...i.attempt===void 0?{}:{attempt:i.attempt},...i.max===void 0?{}:{max:i.max},...i.nextAt===void 0?{}:{nextAt:i.nextAt}},message:t.message,since:t.since,operation_id:r,...t.anchorEntryId===void 0?{}:{anchorEntryId:t.anchorEntryId}}}catch{return null}}function Z9t(e){try{return Yos(zos(X9t(e),"utf8"))}catch{return null}}function Kos(e,t){try{$os(x4(e),{recursive:!0}),qos(X9t(e),JSON.stringify(t))}catch{}}function Xos(e,t){let r=Z9t(e);if(r!==null){if(r.link===t.link&&r.kind===t.kind){let i={...r.retry,...t.retry};t.retry.disposition==="fatal"&&!("nextAt"in t.retry)&&delete i.nextAt,t={...t,since:r.since,anchorEntryId:r.anchorEntryId??t.anchorEntryId,retry:i}}else if(m7n(r)>m7n(t))return}Kos(e,t)}function h7n(e){if(e!==void 0)return LY(e);let t=WSe.current();return t!==void 0?t:WSe.fresh(r=>r)}function _7n(e,t){let r=h7n(t.operation_id),i={link:t.link,op:t.op,kind:t.kind,retry:t.retry,message:Qos(t.message),since:t.since??new Date().toISOString(),operation_id:r,...typeof t.anchorEntryId=="string"&&t.anchorEntryId!==""?{anchorEntryId:t.anchorEntryId}:{}};$Y({level:i.retry.disposition==="fatal"?"error":"warn",event:"fault.recorded",operation_id:r,node_id:e,error_class:K9t(i),fields:{link:i.link,op:i.op,kind:i.kind,retry:i.retry,message:i.message,...i.anchorEntryId===void 0?{}:{anchor_entry_id:i.anchorEntryId}}}),Xos(e,i)}function Tet(e,t){try{let r=Z9t(e);if(r===null||t?.link!==void 0&&r.link!==t.link)return!1;jos(X9t(e));let i=h7n();return $Y({level:"info",event:"fault.cleared",operation_id:i,node_id:e,error_class:K9t(r),fields:{cleared_fault_operation_id:r.operation_id,link:r.link,op:r.op,kind:r.kind,retry:r.retry,message:r.message,since:r.since,...r.anchorEntryId===void 0?{}:{anchor_entry_id:r.anchorEntryId}}}),!0}catch{return!1}}function T1e(e){return Z9t(e)}function g7n(e,t,r=5e3){let i=/^[\x20-\x7e]+$/.test(t);return async function(a,u){if(!i)return{ok:!1,stdout:"",stderr:"remote source: invalid stored relay token"};let p={kind:"exec",bin:a,args:u},m=new AbortController,_=setTimeout(()=>m.abort(),r),f;try{f=await fetch(new URL("/__crtr/source",e),{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${t}`},body:JSON.stringify(p),signal:m.signal})}catch{return m.signal.aborted?{ok:!1,stdout:"",stderr:`remote source: timeout after ${r}ms`}:{ok:!1,stdout:"",stderr:"remote source: network error"}}finally{clearTimeout(_)}return f.ok?await f.json():{ok:!1,stdout:"",stderr:`remote source: HTTP ${f.status} ${f.statusText}`}}}var eQt=1e3;function Yz(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Zos(e){if(!Yz(e))return!1;let t=e.node;if(!Yz(t)||typeof t.node_id!="string"||!Array.isArray(e.reports)||!Array.isArray(e.managers))return!1;let r=e.artifacts;if(!Yz(r)||typeof r.report!="number"||typeof r.doc!="number"||typeof r.roadmap!="number"||typeof e.pending_crons!="number")return!1;let i=e.paths;return!(!Yz(i)||typeof i.context_dir!="string"||typeof i.reports_dir!="string"||"session_file"in i&&i.session_file!==null&&typeof i.session_file!="string"||typeof e.follow_up!="string")}function y7n(e){return Yz(e)&&typeof e.node_id=="string"&&typeof e.name=="string"&&typeof e.kind=="string"&&typeof e.status=="string"&&typeof e.active=="boolean"}function ess(e){return Yz(e)?typeof e.node_id=="string"&&typeof e.name=="string"&&typeof e.kind=="string"&&typeof e.mode=="string"&&typeof e.lifecycle=="string"&&typeof e.status=="string"&&typeof e.cwd=="string"&&typeof e.created=="string":!1}var Kz=class{constructor(t,r){this.previewEndpoint=t;this.relayToken=r;this.exec=g7n(t,r)}previewEndpoint;relayToken;exec;nodeCache=new Map;rosterCache=new Map;viewCache=new Map;async execJson(t){let r;try{r=await this.exec("crtr",["--json",...t])}catch{return null}if(!r.ok||r.exitCode!==void 0&&r.exitCode!==0)return null;try{return JSON.parse(r.stdout.trim())}catch{return null}}async fetchShow(t){let r=this.nodeCache.get(t);if(r&&Date.now()-r.at<eQt)return r.value;let i=await this.execJson(["node","inspect","show",t]),o=Zos(i)?{...i,reports:i.reports.filter(y7n),managers:i.managers.filter(y7n)}:null;return this.nodeCache.set(t,{value:o,at:Date.now()}),o}async rawShow(t){return this.fetchShow(t)}async getNode(t){return(await this.fetchShow(t))?.node??null}async getRow(t){let r=(await this.fetchShow(t))?.node;return r?{node_id:r.node_id,name:r.name,kind:r.kind,mode:r.mode,lifecycle:r.lifecycle,status:r.status,cwd:r.cwd,host_kind:r.host_kind??null,profile_id:r.profile_id??null,parent:r.parent??null,created:r.created,intent:r.intent??null,waiting_for:r.waiting_for??null,pi_pid:r.pi_pid??null,pi_pid_identity:r.pi_pid_identity??null,window:r.window??null,tmux_session:r.tmux_session??null,pane:r.pane??null}:null}async listNodes(t){let r=JSON.stringify(t?.status??null),i=this.rosterCache.get(r);if(i&&Date.now()-i.at<eQt)return i.value;let o=["node","inspect","list"];t?.status&&o.push("--status",(Array.isArray(t.status)?t.status:[t.status]).join(","));let a=await this.execJson(o),p=(Yz(a)&&Array.isArray(a.nodes)?a.nodes:[]).filter(ess);return this.rosterCache.set(r,{value:p,at:Date.now()}),p}async subscriptionsOf(t){return((await this.fetchShow(t))?.reports??[]).map(i=>({node_id:i.node_id,active:i.active,created:""}))}async subscribersOf(t){return((await this.fetchShow(t))?.managers??[]).map(i=>({node_id:i.node_id,active:i.active,created:""}))}async view(t){let r=this.viewCache.get(t);if(r&&Date.now()-r.at<eQt)return r.value;let i=new Set([t]),o=[],a=(await this.subscriptionsOf(t)).map(u=>u.node_id);for(;a.length>0;){let u=a.shift();if(!i.has(u)){i.add(u),o.push(u);for(let p of await this.subscriptionsOf(u))i.has(p.node_id)||a.push(p.node_id)}}return this.viewCache.set(t,{value:o,at:Date.now()}),o}async ticketCountsForView(t){let r=await this.execJson(["canvas","attention","map","--view",t]);return Yz(r)&&Yz(r.counts)?r.counts:{}}async hasActiveLiveSubscription(t){let r=(await this.subscriptionsOf(t)).filter(i=>i.active);for(let i of r){let o=await this.getRow(i.node_id);if(o&&(o.status==="active"||o.status==="idle"))return!0}return!1}};function tQt(e){return e==="orchestrator"?"\uF0E8":"\uF007"}function rQt(e){let t=(e.description??"").trim(),i=[e.name&&e.name!==e.kind?e.name:"",t].filter(o=>o!=="").join(" ");return i!==""?i:e.name}function b7n(e){return`${tQt(e.mode)} ${e.kind}`}var tss={active:"\u25CF",idle:"\u25CB",done:"\u2713",dead:"\u2717",canceled:"\u2298"},rss={active:32,idle:33,done:36,dead:31,canceled:90},nss="\u27F3",iss=92,oss="\u26A0",sss=33;function E7n(e){switch(e){case"rate-limit":return"rate-limited";case"overloaded":return"overloaded";case"connection":return"down";case"auth":return"auth";case"protocol":return"protocol";case"context-overflow":return"context-overflow";case"wedged":return"wedged";case"model-not-found":return"model-not-found";default:return"other"}}function nQt(e,t){return t.hanging!=null?{glyph:oss,color:sss,word:E7n(t.hanging.kind),bold:!0}:t.streaming===!0?{glyph:nss,color:iss,word:"live",bold:!0}:{glyph:tss[e]??"?",color:rss[e]}}function ass(e,t){let r=Date.parse(e);if(Number.isNaN(r))return"now";let i=r-t;return i<=0?"now":i>=6e4?`${Math.max(1,Math.round(i/6e4))}m`:`${Math.max(1,Math.ceil(i/1e3))}s`}function css(e){return e.retry.disposition!=="auto"}function lss(e,t=Date.now()){let r=e.retry;if(!css(e)){if(r.by==="client")return"redialing";let i=typeof r.attempt=="number"&&typeof r.max=="number"?`auto-retry ${r.attempt}/${r.max}`:"auto-retrying";return r.nextAt?`${i}, next ${ass(r.nextAt,t)}`:i}return"needs you"}function iQt(e,t=Date.now()){return`${e.link} ${E7n(e.kind)} \xB7 ${lss(e,t)}`}function vet(e,t){return t===null||t.link==="pi\u2192provider"&&t.retry.by==="daemon"&&t.retry.disposition==="auto"&&!F9(e.pi_pid)?null:t}var v7n=30,mB="\x1B[",Fg=`${mB}0m`,v1e=`${mB}1m`,sw=`${mB}2m`,Cet=`${mB}7m`,C7n=`${mB}48;5;22m`,xet=`${mB}32m`,Vwu=`${mB}31m`,C1e=`${mB}33m`,Wwu=`${mB}36m`,Qwu=`${mB}90m`;function uss(e){return vet(e,T1e(e.node_id))}function pss(e){return e.status!=="active"&&e.status!=="idle"||!F9(e.pi_pid)?!1:p7n(e.node_id)}function Iet(e,t=!1){if(e===null)return"?";let r=nQt(e.status,{streaming:t?!1:pss(e),hanging:t?null:uss(e)});return`${mB}${r.color}m${r.glyph}${Fg}`}var x7n=/\x1b\[[0-9;]*m/g;function I7n(e){return e.replace(x7n,"")}function EL(e){return e.replace(x7n,"").length}function x1e(e,t=Xz()){if(EL(e)<=t)return e;let r="",i=0,o=0;for(;o<e.length&&i<t-1;){if(e[o]==="\x1B"){let a=/^\x1b\[[0-9;]*m/.exec(e.slice(o));if(a){r+=a[0],o+=a[0].length;continue}}r+=e[o],i++,o++}return`${r}\u2026${Fg}`}function Xz(){return Math.max(20,Math.min((process.stdout.columns??80)-2,180))}function I1e(e,t,r){let i=x1e(e,t),o=i.replace(/\x1b\[0m/g,`${Fg}${r}`),a=Math.max(0,t-EL(i));return`${r}${o}${" ".repeat(a)}${Fg}`}var oQt=new Map;function w1e(){oQt.clear()}function w7n(e){let t=oQt.get(e);if(t!==void 0)return t;let r;try{let i=T7n(x4(e),"telemetry.json");r=A7n(i)?JSON.parse(S7n(i,"utf8")):{}}catch{r={}}return oQt.set(e,r),r}function dss(e){return e<1e3?`${e}`:`${Math.round(e/1e3)}k`}function wet(e,t=!1){return dss(t?0:w7n(e).context_tokens??0)}function Ret(e,t,r=!1){if(r||t?.status!=="active")return"";let i=(w7n(e).last_activity??"").trim();return i===""?"":` ${sw}\xB7 ${i}${Fg}`}function ket(e){let t=e?.cycles??0;return t>0?` ${sw}\u27F3${t}${Fg}`:""}function R1e(e,t){if(e===null)return Net(t);let r=e.name&&e.name!==e.kind?e.name:"";if(r!=="")return r;let i=(e.description??"").trim();return i!==""?i:e.name}function Net(e){return e.slice(0,8)}function fss(e,t,r=!1){if(r||t?.status!=="active")return!1;try{let i=T7n(x4(e),"attach.json");if(!A7n(i))return!1;let o=JSON.parse(S7n(i,"utf8"));return typeof o.viewers=="number"&&o.viewers>0}catch{return!1}}function R7n(e,t,r,i=!1){return i?!1:r.has(e)?!0:fss(e,t,i)}function Pet(e,t){let r=t[e]??0;return r>0?` ${C1e}\u2691${r}${Fg}`:""}var Hwu=`${sw}jk move \xB7 hl fold \xB7 \u21B5 focus \xB7 e expand \xB7 x kill \xB7 m mgr \xB7 esc${Fg}`;var mss=["crtr.attach.scroll.up","crtr.attach.scroll.down","crtr.attach.scroll.page-up","crtr.attach.scroll.page-down","crtr.attach.scroll.live","crtr.attach.mouse.toggle","crtr.attach.copy.message"];function ite(e,t,r){return qY(e,t,jY(r),(i,o)=>Kc(i,o))}function sQt(e,t){t[e]()}function k7n(e,t,r){for(let{actionId:i}of I4)if(ite(e,i,t))return sQt(i,r),!0;return!1}function N7n(e,t,r){for(let i of mss)if(ite(e,i,t))return r[i](),!0;return!1}function P7n(e){for(let t of["crtr.attach.clear-or-detach","crtr.attach.detach"])if(e.gestures(t).length>0)return FI(e,t)}function aQt(e,t,r,i){let o=e();if(t(o.bindings),r())try{i(o.bindings,o.tmuxPassthrough)}catch{}return o}function O7n(e){if(e!==""){for(let t of e){let r=t.codePointAt(0);if(r<32||r===127)return}return e}}function D7n(e,t,r,i,o){let a="closed",u=0,p="",m=()=>e.terminal.columns,_=w=>{w!==void 0&&r.scrollToLine(w.line),e.requestRender()},f=()=>{i.setQuery(p,u),_(i.current(m()))},g=()=>{a="closed",p="",i.setQuery("",void 0),e.requestRender()},E=()=>{a==="closed"&&(u=r.topLine()??0),a="editing",p=i.query(),e.requestRender()},v=w=>{let P=i.step(m(),w);if(P===void 0){o.setNotice(`No matches for \u201C${i.query()}\u201D`);return}_(P)};return{component:{render(w){if(a==="closed")return[];let{index:P,total:k}=i.status(w),D=a==="editing"?`${t.accent("\u2315")} ${p}${t.accent("\u258C")}`:`${t.accent("\u2315")} ${p}`,z=k===0?i.query()===""?t.faint("type to search what is on screen"):t.error("no matches"):t.info(`${P}/${k}`),Z=a==="editing"?t.faint("enter browse \xB7 esc cancel"):t.faint([`${FI(o.bindings(),"crtr.attach.search.next")} next`,`${FI(o.bindings(),"crtr.attach.search.previous")} prev`,`${FI(o.bindings(),"crtr.attach.search.edit")} edit`,`${FI(o.bindings(),"crtr.attach.search.close")} close`].join(" \xB7 ")),H=`${z} ${Z}`,J=w-EL(D)-EL(H)-2;return[J<1?_l(` ${D}`,w,"",!0):` ${D}${" ".repeat(J)}${H} `]},invalidate(){}},open:E,close:g,handleKey:w=>{if(a==="closed")return!1;let P=o.bindings();if(ite(P,"crtr.attach.search.close",w))return g(),!0;if(a==="editing"){if(w==="")return g(),!0;if(w==="\r"||w===`
|
|
1917
1917
|
`)return i.status(m()).total===0?(o.setNotice(p===""?"Type something to search for":`No matches for \u201C${p}\u201D`),!0):(a="browsing",e.requestRender(),!0);if(w==="\x7F"||w==="\b")return p=[...p].slice(0,-1).join(""),f(),!0;let k=O7n(w);return k===void 0?!1:(p+=k,f(),!0)}return ite(P,"crtr.attach.search.next",w)||w==="\r"||w===`
|
|
1918
1918
|
`?(v(1),!0):ite(P,"crtr.attach.search.previous",w)?(v(-1),!0):ite(P,"crtr.attach.search.edit",w)?(E(),!0):(O7n(w)!==void 0&&g(),!1)}}}import{performance as M7n}from"node:perf_hooks";var cQt=100,hss=25,_ss=.5,gss=.15;function yss(e){return 1-(1-e)*(1-e)}function L7n(e,t){let r,i=0,o=0,a=0,u=()=>{r!==void 0&&clearTimeout(r),r=void 0,o=0,a=0},p=_=>{let f=Math.max(0,i+cQt-_);r=setTimeout(()=>{r=void 0,m(M7n.now(),!0)},Math.min(hss,f))},m=(_,f)=>{let g=Math.min(1,(_-i)/cQt),E=Math.round(o*yss(g)),v=E-a;if(v!==0){if(!e.scrollBy(v))return u();a=E,t()}if(g===1)return u();f&&p(_)};return{page(_){let f=M7n.now();r!==void 0&&(clearTimeout(r),r=void 0,m(f,!1));let g=o-a,E=Math.max(1,Math.round(e.pageRows()*_ss)),v=(_==="up"?-1:1)*E;if(o=g+v,a=0,o===0)return u();i=f-cQt*gss,m(f,!0)},cancel:u}}import{spawnSync as F7n}from"node:child_process";var B7n=3e3;function bss(){if(process.platform==="darwin")return[["pbcopy",[]]];let e=!!process.env.WAYLAND_DISPLAY||process.env.XDG_SESSION_TYPE==="wayland",t=["xclip",["-selection","clipboard"]],r=["wl-copy",[]];return e?[r,t]:[t,r]}function lQt(e){for(let[t,r]of bss()){let i=F7n(t,r,{input:e,timeout:B7n,encoding:"utf-8"});if(i.error){if(i.error.code==="ENOENT")continue;continue}if(i.status===0)return!0}return!1}function Oet(e){let t=lQt(e),r=!1;if(process.env.TMUX!==void 0){let i=F7n("tmux",["load-buffer","-w","-"],{input:e,timeout:B7n,encoding:"utf-8"});r=!i.error&&i.status===0}return{system:t,tmux:r}}function jme(e){return e!==void 0&&e.trim()!==""}function Ess(e){return e.split(`
|
|
1919
1919
|
`).length}function Ass(e,t){if(e&&t)return"clipboard + tmux buffer";if(e)return"clipboard";if(t)return"tmux buffer"}function Sss(e,t,r){let{first:i,last:o,lastFullyVisible:a}=t.visibleBlocks(),u=p=>{let m=r.blockAt(p);return m?e.blockText(m):void 0};for(let p=Math.min(o,a);p>=i;p--){let m=u(p);if(jme(m))return m}for(let p=o;p>=i;p--){let m=u(p);if(jme(m))return m}}function U7n(e,t,r){return{copy(i){let o,a;switch(i){case"message":{let _=Sss(e,t,r);jme(_)&&(o={text:_,label:"message"}),a="Nothing to copy \u2014 no visible message";break}case"last-assistant":{let _=e.getLastAssistantText();jme(_)&&(o={text:_,label:"last assistant message"}),a="Nothing to copy \u2014 no assistant message yet";break}case"tool":{let _=e.getLastToolOutputText();jme(_)&&(o={text:_,label:"tool output"}),a="Nothing to copy \u2014 no tool output yet";break}case"transcript":{let _=e.getTranscriptPlainText();jme(_)&&(o={text:_,label:"transcript"}),a="Nothing to copy \u2014 transcript is empty";break}}if(!o)return a;let{system:u,tmux:p}=Oet(o.text),m=Ass(u,p);return m?`Copied ${o.label} (${Ess(o.text)} lines) \u2014 ${m}`:"Copy failed \u2014 no clipboard tool found"}}}var Det=class extends gl{render(t){let r=super.render(t);return r[0]===""?r.slice(1):r}};import{spawn as Ils}from"node:child_process";import{readFileSync as wls,unlinkSync as Rls,writeFileSync as kls}from"node:fs";import{tmpdir as Nls}from"node:os";import{join as Pls}from"node:path";import{StringDecoder as Tss}from"node:string_decoder";function Met(e){return JSON.stringify(e)+`
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { readConfig } from '../../core/config.js';
|
|
2
2
|
import { CORE_COMPONENT_SELECTION_LINES } from '../../core/human/component-docs.js';
|
|
3
|
+
// The reader's missing context is the gap syntax cannot close: an inbox page
|
|
4
|
+
// is opened away from the conversation that produced it, by someone who never
|
|
5
|
+
// followed the work.
|
|
6
|
+
const PAGE_BRIEF = 'Write the page for where it is read. A page projected to the inbox is opened away from this conversation by someone who has not followed the work, so it stands alone; an inline page can lean on what the conversation already said. Title names the topic; subtitle states the decision, your recommendation, and the stakes. Content carries only what is needed to decide, with the evidence behind it below the ask rather than ahead of it. Ask only what changes your next step, and offer only options you would actually take. A page that asks nothing states what happened and what it changes.';
|
|
3
7
|
const PAGE_AUTHORING = 'Write one `.tsx` module to `$CRTR_CONTEXT_DIR/pages/<name>.tsx` that default-exports a component whose root element is `<Page title="…" subtitle="…">`; a multi-step page puts its content in `<Step>` children. Or send a complete `.html` file with a nonempty `<title>`; HTML is delivered verbatim and collects no response. Delivery is chosen by `human send` flags, never a Page prop. Registry components and React are already in scope, so the module contains no `import` and no `require`. Full JS is yours: state, expressions, `.map` over your data, event handlers, plain elements with Tailwind classes. `usePageHost` is a reserved hook whose product-supplied members are opaque here. Never render submit or dismiss chrome — the host owns it. Display-only pages are first-class: a page with no questions may be sent without inbox or reply delivery. The module is compiled when you submit it and a compile error rejects the submit; there is no pre-check.';
|
|
4
8
|
const DISPLAY_SET_LINE = 'The shadcn display set — `Card`, `Badge`, `Button`, `Table`, `Tabs`, `Separator`, `Alert`, `Progress`, `Accordion` and their parts — is in scope too, for presentation only.';
|
|
5
9
|
/** The one page authoring model for `human -h`. */
|
|
6
10
|
export function pageHelpText(pageSurface = false) {
|
|
7
11
|
return {
|
|
12
|
+
brief: PAGE_BRIEF,
|
|
8
13
|
authoring: pageSurface
|
|
9
14
|
? `Use inline pages as the default way to put structured or interactive content in front of the user; the environment renders rich components, so a page is not a special occasion. ${PAGE_AUTHORING}`
|
|
10
15
|
: PAGE_AUTHORING,
|
package/dist/commands/human.js
CHANGED
package/package.json
CHANGED
package/runtime.lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/crouter",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.203",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@north-light/crouter",
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.203",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|