@north-light/crouter 0.3.332 → 0.3.334
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/api/command-manifest/manifest.js +1 -1
- package/dist/build-root.js +1 -1
- package/dist/builtin-memory/crouter-concepts/INDEX.md +13 -0
- package/dist/builtin-memory/crouter-concepts/README.md +19 -0
- package/dist/builtin-memory/crouter-concepts/lifecycle-and-wakes.md +28 -0
- package/dist/builtin-memory/crouter-concepts/memory.md +36 -0
- package/dist/builtin-memory/crouter-concepts/nodes-and-the-canvas.md +30 -0
- package/dist/builtin-memory/crouter-concepts/profiles-kinds-and-modes.md +33 -0
- package/dist/builtin-memory/crouter-concepts/scopes-and-trust.md +34 -0
- package/dist/builtin-memory/crouter-concepts/why-a-daemon.md +31 -0
- package/dist/builtin-memory/crouter-sdk/guides/README.md +19 -0
- package/dist/builtin-memory/crouter-sdk/guides/app-memory.md +73 -0
- package/dist/builtin-memory/crouter-sdk/guides/event-driven-assistant.md +91 -0
- package/dist/builtin-memory/crouter-sdk/guides/fan-out-pipeline.md +57 -0
- package/dist/builtin-memory/crouter-sdk/guides/human-approval.md +79 -0
- package/dist/builtin-memory/crouter-sdk/guides/typed-extraction.md +53 -0
- package/dist/clients/attach/input/capabilities.js +1 -1
- package/dist/clients/attach/overlays/help.js +1 -1
- package/dist/clients/attach/slash/dispatch.js +1 -1
- package/dist/clients/attach/viewer.js +413 -413
- package/dist/commands/sys/branch.js +1 -1
- package/dist/commands/sys/setup-core.d.ts +1 -1
- package/dist/commands/sys/setup-core.js +4 -4
- package/dist/commands/sys/tutorial/branch.d.ts +1 -0
- package/dist/commands/sys/tutorial/branch.js +1 -0
- package/dist/commands/sys/tutorial/lessons.d.ts +6 -0
- package/dist/commands/sys/tutorial/lessons.js +12 -0
- package/dist/commands/sys/tutorial/scenario.d.ts +1 -0
- package/dist/commands/sys/tutorial/scenario.js +2 -0
- package/dist/commands/sys/tutorial/tracks.d.ts +2 -0
- package/dist/commands/sys/tutorial/tracks.js +4 -0
- package/dist/commands/sys.js +1 -1
- package/dist/core/runtime/boot-root.d.ts +7 -0
- package/dist/core/runtime/boot-root.js +4 -4
- package/dist/core/runtime/first-run-offer.d.ts +11 -0
- package/dist/core/runtime/first-run-offer.js +5 -0
- package/dist/core/runtime/front-door.js +3 -3
- package/dist/daemon/api/handlers/node-events.js +1 -1
- package/dist/types.js +1 -1
- package/docs/cli/README.md +16 -0
- package/docs/cli/canvas-and-dashboard.md +56 -0
- package/docs/cli/first-session.md +55 -0
- package/docs/cli/human-inbox.md +34 -0
- package/docs/cli/memory-and-preferences.md +50 -0
- package/docs/cli/the-viewer.md +79 -0
- package/docs/concepts/README.md +17 -0
- package/docs/concepts/lifecycle-and-wakes.md +26 -0
- package/docs/concepts/memory.md +34 -0
- package/docs/concepts/nodes-and-the-canvas.md +28 -0
- package/docs/concepts/profiles-kinds-and-modes.md +31 -0
- package/docs/concepts/scopes-and-trust.md +32 -0
- package/docs/concepts/why-a-daemon.md +29 -0
- package/docs/sdk/guides/README.md +18 -0
- package/docs/sdk/guides/app-memory.md +22 -0
- package/docs/sdk/guides/event-driven-assistant.md +24 -0
- package/docs/sdk/guides/fan-out-pipeline.md +24 -0
- package/docs/sdk/guides/human-approval.md +24 -0
- package/docs/sdk/guides/typed-extraction.md +22 -0
- package/package.json +8 -8
- package/runtime.lock.json +196 -196
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
---
|
|
2
|
+
kind: knowledge
|
|
3
|
+
when-and-why-to-read: When a person must approve or reject work before an agent
|
|
4
|
+
continues, read this because the SDK can create an inbox request whose answer
|
|
5
|
+
wakes the requesting node.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Human approval
|
|
9
|
+
|
|
10
|
+
Use this recipe when a decision belongs to a person, not a timeout or an agent guess. Run `npx tsx examples/guides/human-approval.ts /path/to/repo`; it prints an inbox ticket id. Answer the page in the crtr human inbox and the worker wakes with that answer before it reports its result.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import Crouter from '@north-light/crouter-sdk';
|
|
14
|
+
import { resolve } from 'node:path';
|
|
15
|
+
|
|
16
|
+
const client = new Crouter();
|
|
17
|
+
const cwd = resolve(process.argv[2] ?? process.cwd());
|
|
18
|
+
|
|
19
|
+
const worker = await client.nodes.create({
|
|
20
|
+
name: 'approval worker',
|
|
21
|
+
cwd,
|
|
22
|
+
root: true,
|
|
23
|
+
root_lifecycle: 'terminal',
|
|
24
|
+
no_kickoff: true,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const request = await client.human.requests.create({
|
|
28
|
+
creator_cwd: cwd,
|
|
29
|
+
requester_node_id: worker.node_id,
|
|
30
|
+
delivery: { placement: 'panel', inbox: true, reply: true },
|
|
31
|
+
page: {
|
|
32
|
+
dialect: 'jsx',
|
|
33
|
+
source: `export default function Approval() {
|
|
34
|
+
return (
|
|
35
|
+
<Page title="Approve the release?" subtitle="The worker will continue with your choice.">
|
|
36
|
+
<UserQuestion
|
|
37
|
+
id="approval"
|
|
38
|
+
label="Release action"
|
|
39
|
+
body="Approve to continue the release, or reject to stop it."
|
|
40
|
+
mode="single"
|
|
41
|
+
options={[
|
|
42
|
+
{ id: 'approve', label: 'Approve', recommended: true },
|
|
43
|
+
{ id: 'reject', label: 'Reject' },
|
|
44
|
+
]}
|
|
45
|
+
/>
|
|
46
|
+
</Page>
|
|
47
|
+
);
|
|
48
|
+
}`,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const ticket = await client.human.requests.retrieve(request.request_id);
|
|
53
|
+
if (ticket.inbox_ticket_id === null) throw new Error('the approval request was not added to the inbox');
|
|
54
|
+
|
|
55
|
+
await client.nodes.message(worker.node_id, {
|
|
56
|
+
body: `A human approval request is open. Wait for its reply. When it arrives, state whether the release was approved or rejected, then push a final report.`,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
console.log(`approval ticket: ${ticket.inbox_ticket_id}`);
|
|
60
|
+
console.log('Answer it in the crtr human inbox. The worker will wake with the response.');
|
|
61
|
+
|
|
62
|
+
const outcome = await client.nodes.waitForOutcome(worker.node_id);
|
|
63
|
+
console.log(`worker outcome: ${outcome.kind}`);
|
|
64
|
+
if (outcome.kind !== 'result') process.exitCode = 1;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The application creates the page through `client.human.requests.create()` and names the worker as `requester_node_id`. `delivery.reply: true` makes the settled answer travel back to that node. The page's `UserQuestion` supplies a known response shape, so the person sees an explicit approve or reject decision instead of an unstructured prompt.
|
|
68
|
+
|
|
69
|
+
The worker is terminal because this is a bounded approval run: it waits after setup, wakes when the person answers, then publishes its final result. The pending human request keeps that wait durable. The application does not poll the node or invent a fallback deadline; the human reply is a canvas event. `client.human.inbox` can list, inspect, and answer inbox tickets when your application provides its own human interface.
|
|
70
|
+
|
|
71
|
+
Observed against the local daemon after an approve response:
|
|
72
|
+
|
|
73
|
+
```text
|
|
74
|
+
approval ticket: a643479ca7a79758bf86f32d24bd8c9b22e16509cd60996c5e4fe0bc5f097d45
|
|
75
|
+
Answer it in the crtr human inbox. The worker will wake with the response.
|
|
76
|
+
worker outcome: result
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
See [[crouter-concepts/lifecycle-and-wakes]] for the wake model and [[crouter-concepts/scopes-and-trust]] for why the daemon, rather than the application, owns delivery of the answer.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
kind: knowledge
|
|
3
|
+
when-and-why-to-read: When an application needs one bounded structured answer
|
|
4
|
+
with no follow-up, read this because nodes.parse returns a typed outcome union
|
|
5
|
+
instead of hiding agent failures.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Typed extraction
|
|
9
|
+
|
|
10
|
+
Use this recipe to extract a small fact set from files in one working directory. Run it with `npx tsx examples/guides/typed-extraction.ts /path/to/repo`; it prints a package name and version or exits with an explicit agent outcome.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import Crouter from '@north-light/crouter-sdk';
|
|
14
|
+
import { resolve } from 'node:path';
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
|
|
17
|
+
const client = new Crouter();
|
|
18
|
+
const cwd = resolve(process.argv[2] ?? process.cwd());
|
|
19
|
+
|
|
20
|
+
const extraction = await client.nodes.parse({
|
|
21
|
+
prompt: 'Read package.json in this directory. Return its name and version.',
|
|
22
|
+
cwd,
|
|
23
|
+
root: true,
|
|
24
|
+
root_lifecycle: 'terminal',
|
|
25
|
+
deadline: '5m',
|
|
26
|
+
output_schema: z.object({
|
|
27
|
+
name: z.string(),
|
|
28
|
+
version: z.string(),
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (extraction.kind === 'result') {
|
|
33
|
+
console.log(`package ${extraction.output_parsed.name}@${extraction.output_parsed.version}`);
|
|
34
|
+
} else if (extraction.reason === 'declined') {
|
|
35
|
+
console.error(`agent declined: ${extraction.declined?.reason ?? 'no reason supplied'}`);
|
|
36
|
+
process.exitCode = 2;
|
|
37
|
+
} else {
|
|
38
|
+
console.error(`agent failed: ${extraction.reason}`, extraction.detail);
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`nodes.parse()` creates a terminal root, waits for it, and returns the structured result typed from the Zod schema. The schema belongs at the boundary where your application consumes the answer, not in a second parser after the run.
|
|
44
|
+
|
|
45
|
+
Observed against the local daemon in this checkout:
|
|
46
|
+
|
|
47
|
+
```text
|
|
48
|
+
package @north-light/crouter@0.3.332
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Handle every outcome arm. A result contains `output_parsed`; a decline says the agent could not honestly meet the schema; another failure carries its reason and detail. Transport and daemon failures still throw, so let those reach your normal application error handling.
|
|
52
|
+
|
|
53
|
+
This is the right shape for bounded work: one prompt, one answer, and no future message. If a user or external event must return to the same agent later, use a resident node instead. See [[crouter-concepts/nodes-and-the-canvas]] for why an SDK node has durable identity, and [[crouter-concepts/lifecycle-and-wakes]] for the terminal-versus-resident decision.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var o=Object.defineProperty;var r=(e,s)=>o(e,"name",{value:s,configurable:!0});function l(e){const s=e.remote,t=s?"observer":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"),a.add("wake-dormant"),a.add("auth"),a.add("canvas-resume")),{role:t,remote:s,nodeId:e.nodeId,profileId:e.profileId,permittedOperations:a,permits:r(n=>a.has(n),"permits"),refusal:r((n,i)=>{const c=i===void 0?"":`/${i} `;if(e.isBrokerOffline?.()===!0&&(n==="engine-drive"||n==="dequeue"||n==="auth"))return`${c}needs a live broker; this node is parked \u2014 submit a message to wake it`;if(!a.has(n))return s&&(n==="canvas-resume"||n==="local-canvas-inspect"||n==="canvas-inbox")?`${c}Read-only remote attach \u2014 not available with --canvas because it acts on this machine's local canvas`:s?`${c}Read-only remote attach \u2014 not available with --canvas (view-only)`:`${c}is not available to a read-only observer attach (--observer) \u2014 it would drive this node`},"refusal")}}r(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}}r(u,"viewerOperationForFrame");function v(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"promote":case"rename":case"resume-session":case"mcp":return"engine-drive";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"}}r(v,"viewerOperationForSlash");export{l as createViewerCapabilities,u as viewerOperationForFrame,v as viewerOperationForSlash};
|
|
1
|
+
var o=Object.defineProperty;var r=(e,s)=>o(e,"name",{value:s,configurable:!0});function l(e){const s=e.remote,t=s?"observer":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"),a.add("wake-dormant"),a.add("auth"),a.add("canvas-resume")),{role:t,remote:s,nodeId:e.nodeId,profileId:e.profileId,permittedOperations:a,permits:r(n=>a.has(n),"permits"),refusal:r((n,i)=>{const c=i===void 0?"":`/${i} `;if(e.isBrokerOffline?.()===!0&&(n==="engine-drive"||n==="dequeue"||n==="auth"))return`${c}needs a live broker; this node is parked \u2014 submit a message to wake it`;if(!a.has(n))return s&&(n==="canvas-resume"||n==="local-canvas-inspect"||n==="canvas-inbox")?`${c}Read-only remote attach \u2014 not available with --canvas because it acts on this machine's local canvas`:s?`${c}Read-only remote attach \u2014 not available with --canvas (view-only)`:`${c}is not available to a read-only observer attach (--observer) \u2014 it would drive this node`},"refusal")}}r(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}}r(u,"viewerOperationForFrame");function v(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"promote":case"rename":case"resume-session":case"tutorial":case"mcp":return"engine-drive";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"}}r(v,"viewerOperationForSlash");export{l as createViewerCapabilities,u as viewerOperationForFrame,v as viewerOperationForSlash};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var w=Object.defineProperty;var d=(g,t)=>w(g,"name",{value:t,configurable:!0});import{matchesKey as h,truncateToWidth as c,visibleWidth as m}from"@earendil-works/pi-tui";import{ATTACH_CONTROL_BINDINGS as x,BINDING_CATALOG as T,formatBinding as $,matchesPiTuiInput as M}from"../../../core/keybindings/index.js";const R=.72,v={anchor:"center",width:"72%",minWidth:48,maxHeight:"72%",margin:1};class C{static{d(this,"HelpOverlay")}tui;pal;handle;bindings;scrollTop=0;lastContentRows=1;constructor(t,e){this.tui=t,this.pal=e}setBindings(t){this.bindings=t,this.handle!==void 0&&this.tui.requestRender()}toggle(){this.handle===void 0?this.open():this.close()}close(){this.handle!==void 0&&(this.handle.hide(),this.handle=void 0,this.tui.requestRender())}isOpen(){return this.handle!==void 0}invalidate(){this.handle!==void 0&&this.tui.requestRender()}render(t){const e=Math.max(1,t);if(e<5)return this.renderNarrow(e);const i=e-4,s=this.body(i),o=Math.max(1,this.tui.terminal.rows),n=Math.max(3,Math.min(Math.floor(o*R),Math.max(3,o-2))),r=Math.max(1,n-2),l=s.length>r,u=l&&r>=3?r-2:1;this.lastContentRows=u,this.scrollTop=Math.max(0,Math.min(this.scrollTop,Math.max(0,s.length-u)));const p=Math.min(s.length,this.scrollTop+u),a=[];for(l&&r>=3&&a.push(this.scrollTop>0?this.pal.muted(`\u2191 ${this.scrollTop} more`):""),a.push(...s.slice(this.scrollTop,p)),l&&r>=3?a.push(p<s.length?this.pal.muted(`\u2193 ${s.length-p} more`):""):l&&r===2&&a.push(p<s.length?this.pal.muted(`\u2193 ${s.length-p} more`):"");a.length<r;)a.push("");const y=this.pal.bold(this.pal.accent("\u2328 attach help")),b=this.pal.muted("esc dismiss \xB7 \u2191\u2193 scroll");return[this.borderRow("\u256D","\u256E",y,e),...a.map(f=>this.boxRow(f,e)),this.borderRow("\u2570","\u256F",b,e)].map(this.pal.surface)}handleInput(t){return h(t,"escape")||h(t,"q")?(this.close(),!0):h(t,"up")||this.matchesBinding("crtr.attach.scroll.up",t)?this.scrollBy(-1):h(t,"down")||this.matchesBinding("crtr.attach.scroll.down",t)?this.scrollBy(1):h(t,"pageUp")||this.matchesBinding("crtr.attach.scroll.page-up",t)?this.scrollBy(-this.pageSize()):h(t,"pageDown")||this.matchesBinding("crtr.attach.scroll.page-down",t)?this.scrollBy(this.pageSize()):!0}open(){this.scrollTop=0,this.handle=this.tui.showOverlay(this,v)}matchesBinding(t,e){return this.bindings!==void 0&&M(this.bindings,t,e,(i,s)=>h(i,s))}scrollBy(t){const e=this.body(Math.max(1,this.tui.terminal.columns-4)).length,i=Math.max(0,e-this.lastContentRows),s=Math.max(0,Math.min(i,this.scrollTop+t));return s!==this.scrollTop&&(this.scrollTop=s,this.tui.requestRender()),!0}pageSize(){return Math.max(1,this.lastContentRows-1)}body(t){return this.lines().flatMap(e=>this.wrap(e.text,t).map(i=>this.style(i,e.style)))}lines(){const t=d((n,r)=>({text:`${this.binding(n)} ${r}`,style:"plain"}),"binding"),e=d(n=>({text:n,style:"heading"}),"heading"),i=d(n=>({text:n,style:"muted"}),"muted"),s={text:"",style:"plain"},o=x.map(({actionId:n})=>{const r=T.find(l=>l.id===n)?.name??n;return t(n,r)});return[e("Scrolling"),t("crtr.attach.scroll.up","scroll one line up"),t("crtr.attach.scroll.down","scroll one line down"),t("crtr.attach.scroll.page-up","scroll one page up"),t("crtr.attach.scroll.page-down","scroll one page down"),t("crtr.attach.scroll.live","return to the live bottom"),i("mouse wheel (when reporting is on)"),s,e("Searching the transcript"),{text:`${this.binding("crtr.attach.search")} search what the transcript is currently showing. Type to jump as you go, enter to browse the matches.`,style:"plain"},{text:`${this.binding("crtr.attach.search.next")} / ${this.binding("crtr.attach.search.previous")} next and previous match \xB7 ${this.binding("crtr.attach.search.edit")} edit the query \xB7 ${this.binding("crtr.attach.search.close")} close. Typing anything else closes search and returns to the editor.`,style:"plain"},{text:"A lowercase query ignores case; any uppercase letter makes it case-sensitive.",style:"plain"},{text:"Folded tool output is not on screen, so it is not searched \u2014 unfold it to include it.",style:"muted"},s,e("Selection and copy"),{text:"Drag with the mouse to select; releasing copies the selection to the clipboard (and the tmux buffer). Any key clears the highlight.",style:"plain"},{text:"prefix + [ tmux copy-mode selects and copies the visible screenful; it works even while mouse reporting is on.",style:"plain"},{text:"Option-drag (iTerm2, Terminal.app) or Shift-drag (Ghostty, Alacritty, xterm) makes a true terminal selection that bypasses mouse reporting.",style:"plain"},{text:"Block-copy commands copy transcript content and are not capped at one screenful.",style:"plain"},s,e("Copy commands"),{text:"/copy last assistant message.",style:"plain"},{text:`/copy-message (${this.binding("crtr.attach.copy.message")}) newest copyable block entirely visible in the viewport; otherwise the newest one that intersects it.`,style:"plain"},{text:"/copy-tool newest tool call's result text.",style:"plain"},{text:"/copy-transcript every copyable block's text, oldest to newest, joined by blank lines.",style:"plain"},s,e("Mouse"),{text:`/mouse or ${this.binding("crtr.attach.mouse.toggle")} toggle mouse reporting \u2014 wheel scrolling and viewer drag-select. Turning it off restores tmux drag-select and copy-mode mouse.`,style:"plain"},s,e("Other attach keys"),...o]}binding(t){return this.bindings===void 0?"Loading\u2026":$(this.bindings,t)}wrap(t,e){if(t==="")return[""];const i=Math.max(1,e),s=t.split(/\s+/),o=[];let n="";for(const r of s){const l=n===""?r:`${n} ${r}`;n!==""&&m(l)>i?(o.push(c(n,i,"",!0)),n=` ${r}`):n=l}return n!==""&&o.push(c(n,i,"",!0)),o}style(t,e){switch(e){case"heading":return this.pal.bold(this.pal.accent(t));case"muted":return this.pal.muted(t);case"plain":return t}}boxRow(t,e){const i=e-4,s=c(t,i,"",!0),o=" ".repeat(Math.max(0,i-m(s)));return`${this.pal.border("\u2502")} ${s}${o} ${this.pal.border("\u2502")}`}borderRow(t,e,i,s){if(s<6)return c(`${this.pal.border(t)}${i}${this.pal.border(e)}`,s,"",!0);const o=s-5,n=c(i,o,"\u2026"),r=Math.max(0,s-5-m(n));return`${this.pal.border(`${t}\u2500`)} ${n} ${this.pal.border("\u2500".repeat(r)+e)}`}renderNarrow(t){const e=c(this.pal.bold(this.pal.accent("help")),t,"",!0);return[this.pal.surface(e)]}}export{C as HelpOverlay};
|
|
1
|
+
var w=Object.defineProperty;var d=(g,t)=>w(g,"name",{value:t,configurable:!0});import{matchesKey as h,truncateToWidth as c,visibleWidth as m}from"@earendil-works/pi-tui";import{ATTACH_CONTROL_BINDINGS as x,BINDING_CATALOG as T,formatBinding as $,matchesPiTuiInput as M}from"../../../core/keybindings/index.js";const R=.72,v={anchor:"center",width:"72%",minWidth:48,maxHeight:"72%",margin:1};class C{static{d(this,"HelpOverlay")}tui;pal;handle;bindings;scrollTop=0;lastContentRows=1;constructor(t,e){this.tui=t,this.pal=e}setBindings(t){this.bindings=t,this.handle!==void 0&&this.tui.requestRender()}toggle(){this.handle===void 0?this.open():this.close()}close(){this.handle!==void 0&&(this.handle.hide(),this.handle=void 0,this.tui.requestRender())}isOpen(){return this.handle!==void 0}invalidate(){this.handle!==void 0&&this.tui.requestRender()}render(t){const e=Math.max(1,t);if(e<5)return this.renderNarrow(e);const i=e-4,s=this.body(i),o=Math.max(1,this.tui.terminal.rows),n=Math.max(3,Math.min(Math.floor(o*R),Math.max(3,o-2))),r=Math.max(1,n-2),l=s.length>r,u=l&&r>=3?r-2:1;this.lastContentRows=u,this.scrollTop=Math.max(0,Math.min(this.scrollTop,Math.max(0,s.length-u)));const p=Math.min(s.length,this.scrollTop+u),a=[];for(l&&r>=3&&a.push(this.scrollTop>0?this.pal.muted(`\u2191 ${this.scrollTop} more`):""),a.push(...s.slice(this.scrollTop,p)),l&&r>=3?a.push(p<s.length?this.pal.muted(`\u2193 ${s.length-p} more`):""):l&&r===2&&a.push(p<s.length?this.pal.muted(`\u2193 ${s.length-p} more`):"");a.length<r;)a.push("");const y=this.pal.bold(this.pal.accent("\u2328 attach help")),b=this.pal.muted("esc dismiss \xB7 \u2191\u2193 scroll");return[this.borderRow("\u256D","\u256E",y,e),...a.map(f=>this.boxRow(f,e)),this.borderRow("\u2570","\u256F",b,e)].map(this.pal.surface)}handleInput(t){return h(t,"escape")||h(t,"q")?(this.close(),!0):h(t,"up")||this.matchesBinding("crtr.attach.scroll.up",t)?this.scrollBy(-1):h(t,"down")||this.matchesBinding("crtr.attach.scroll.down",t)?this.scrollBy(1):h(t,"pageUp")||this.matchesBinding("crtr.attach.scroll.page-up",t)?this.scrollBy(-this.pageSize()):h(t,"pageDown")||this.matchesBinding("crtr.attach.scroll.page-down",t)?this.scrollBy(this.pageSize()):!0}open(){this.scrollTop=0,this.handle=this.tui.showOverlay(this,v)}matchesBinding(t,e){return this.bindings!==void 0&&M(this.bindings,t,e,(i,s)=>h(i,s))}scrollBy(t){const e=this.body(Math.max(1,this.tui.terminal.columns-4)).length,i=Math.max(0,e-this.lastContentRows),s=Math.max(0,Math.min(i,this.scrollTop+t));return s!==this.scrollTop&&(this.scrollTop=s,this.tui.requestRender()),!0}pageSize(){return Math.max(1,this.lastContentRows-1)}body(t){return this.lines().flatMap(e=>this.wrap(e.text,t).map(i=>this.style(i,e.style)))}lines(){const t=d((n,r)=>({text:`${this.binding(n)} ${r}`,style:"plain"}),"binding"),e=d(n=>({text:n,style:"heading"}),"heading"),i=d(n=>({text:n,style:"muted"}),"muted"),s={text:"",style:"plain"},o=x.map(({actionId:n})=>{const r=T.find(l=>l.id===n)?.name??n;return t(n,r)});return[e("Learning crouter"),{text:"/tutorial the guided crouter tutorial \u2014 your agent teaches it, one lesson at a time",style:"plain"},s,e("Scrolling"),t("crtr.attach.scroll.up","scroll one line up"),t("crtr.attach.scroll.down","scroll one line down"),t("crtr.attach.scroll.page-up","scroll one page up"),t("crtr.attach.scroll.page-down","scroll one page down"),t("crtr.attach.scroll.live","return to the live bottom"),i("mouse wheel (when reporting is on)"),s,e("Searching the transcript"),{text:`${this.binding("crtr.attach.search")} search what the transcript is currently showing. Type to jump as you go, enter to browse the matches.`,style:"plain"},{text:`${this.binding("crtr.attach.search.next")} / ${this.binding("crtr.attach.search.previous")} next and previous match \xB7 ${this.binding("crtr.attach.search.edit")} edit the query \xB7 ${this.binding("crtr.attach.search.close")} close. Typing anything else closes search and returns to the editor.`,style:"plain"},{text:"A lowercase query ignores case; any uppercase letter makes it case-sensitive.",style:"plain"},{text:"Folded tool output is not on screen, so it is not searched \u2014 unfold it to include it.",style:"muted"},s,e("Selection and copy"),{text:"Drag with the mouse to select; releasing copies the selection to the clipboard (and the tmux buffer). Any key clears the highlight.",style:"plain"},{text:"prefix + [ tmux copy-mode selects and copies the visible screenful; it works even while mouse reporting is on.",style:"plain"},{text:"Option-drag (iTerm2, Terminal.app) or Shift-drag (Ghostty, Alacritty, xterm) makes a true terminal selection that bypasses mouse reporting.",style:"plain"},{text:"Block-copy commands copy transcript content and are not capped at one screenful.",style:"plain"},s,e("Copy commands"),{text:"/copy last assistant message.",style:"plain"},{text:`/copy-message (${this.binding("crtr.attach.copy.message")}) newest copyable block entirely visible in the viewport; otherwise the newest one that intersects it.`,style:"plain"},{text:"/copy-tool newest tool call's result text.",style:"plain"},{text:"/copy-transcript every copyable block's text, oldest to newest, joined by blank lines.",style:"plain"},s,e("Mouse"),{text:`/mouse or ${this.binding("crtr.attach.mouse.toggle")} toggle mouse reporting \u2014 wheel scrolling and viewer drag-select. Turning it off restores tmux drag-select and copy-mode mouse.`,style:"plain"},s,e("Other attach keys"),...o]}binding(t){return this.bindings===void 0?"Loading\u2026":$(this.bindings,t)}wrap(t,e){if(t==="")return[""];const i=Math.max(1,e),s=t.split(/\s+/),o=[];let n="";for(const r of s){const l=n===""?r:`${n} ${r}`;n!==""&&m(l)>i?(o.push(c(n,i,"",!0)),n=` ${r}`):n=l}return n!==""&&o.push(c(n,i,"",!0)),o}style(t,e){switch(e){case"heading":return this.pal.bold(this.pal.accent(t));case"muted":return this.pal.muted(t);case"plain":return t}}boxRow(t,e){const i=e-4,s=c(t,i,"",!0),o=" ".repeat(Math.max(0,i-m(s)));return`${this.pal.border("\u2502")} ${s}${o} ${this.pal.border("\u2502")}`}borderRow(t,e,i,s){if(s<6)return c(`${this.pal.border(t)}${i}${this.pal.border(e)}`,s,"",!0);const o=s-5,n=c(i,o,"\u2026"),r=Math.max(0,s-5-m(n));return`${this.pal.border(`${t}\u2500`)} ${n} ${this.pal.border("\u2500".repeat(r)+e)}`}renderNarrow(t){const e=c(this.pal.bold(this.pal.accent("help")),t,"",!0);return[this.pal.surface(e)]}}export{C as HelpOverlay};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var E=Object.defineProperty;var i=(o,e)=>E(o,"name",{value:e,configurable:!0});import{execFile as p}from"node:child_process";import{BUILTIN_SLASH_COMMANDS as h}from"../../../core/runtime/pi-vendored.js";import{surfaceTmuxStyleArgs as O}from"../../../core/runtime/surface-bg.js";import{viewerOperationForSlash as _}from"../input/capabilities.js";import{shellQuote as y}from"../../../shared/shell-quote.js";const g=[{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 this node + 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, artifacts, 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:"fold-tools",description:"View setting \u2014 fold every FINISHED tool call to its single call line (Alt+C \u2192 z \u2192 f)"}],$=new Map([["resume-node","resume"]]),w=new Set([...g.map(o=>o.name),...$.keys()]),U=new Set(["black","red","green","yellow","blue","magenta","cyan","white","brightred","brightgreen","brightyellow","brightblue","brightmagenta","brightcyan","orange","grey","gray","default"]),T=new Set(["trust"]),N=new Set(Object.keys({off:!0,minimal:!0,low:!0,medium:!0,high:!0,xhigh:!0,max:!0})),v=new Set(h.map(o=>o.name));function b(o){return o.capabilities.nodeId}i(b,"nodeIdFor");function H(o){return o.capabilities.profileId}i(H,"profileIdFor");function P(o,e){const n=_(o,v.has(o),w.has(o));return n===void 0?void 0:e.capabilities.refusal(n,o)}i(P,"readOnlyRefusal");function oe(){return new Set([...v,...w,...T])}i(oe,"locallyConsumedCommandNames");function j(o){const e=/^\/(\S+)\s*([\s\S]*)$/.exec(o.trim());return e===null?void 0:{name:e[1],arg:e[2].trim()}}i(j,"parseSlashCommand");function te(o){return o.trimStart().startsWith("/")}i(te,"isSlashCommand");function re(o,e){const n=j(o);if(n===void 0)return!1;const{arg:t}=n,r=$.get(n.name)??n.name;if(T.has(r))return e.notify(`/${r} is not supported in attach (Phase 4)`),!0;if(w.has(r)){const s=P(r,e);return s!==void 0?(e.notify(s),!0):X(r,t,e)}if(!v.has(r))return!1;const u=P(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:t||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 t?(e.send({type:"set_session_name",name:t}),!0):f(e,"/name <display name>");case"export":{const{path:s,format:a}=W(t,e.cwd??process.cwd());return e.send({type:"export",path:s,format:a}),e.notify(`Exporting session \u2192 ${s}`),!0}case"import":return t?(e.send({type:"switch_session",path:t}),!0):f(e,"/import <path-to-session.jsonl>");case"model":return t?(e.send({type:"set_model",model:t}),!0):m(e.openModelPicker,e,"model","/model <provider/id>");case"fork":return t?(e.send({type:"fork",entryId:t}),!0):m(e.openForkPicker,e,"fork point","/fork <entryId>");case"tree":return t?(e.send({type:"navigate_tree",targetId:t}),!0):m(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 Q(t,e);case"session":return e.notify(Y(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(re,"dispatchSlashCommand");function M(o,e){const n=i(a=>{const l=_(a,!1,!0);return l===void 0||e.permits(l)},"permitted"),t=g.filter(a=>n(a.name)),r=new Map(g.map(a=>[a.name,a])),u=o.flatMap(a=>{const l=r.get(a.name);return l===void 0?[a]:n(a.name)?[l]:[]}),s=new Set(o.map(a=>a.name));return[...u,...t.filter(a=>!s.has(a.name))]}i(M,"withCanvasCommands");function ie(o,e){return M(o??h,e).map(n=>({name:n.name,description:n.description}))}i(ie,"slashCommandList");function se(o,e){return M(o??h,e).map(n=>({value:`/${n.name}`,label:`/${n.name}`,description:n.description}))}i(se,"commandAutocompleteItems");function X(o,e,n){switch(o){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"promote":return B(e,n),!0;case"resume":return e?f(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):m(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 V(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 F(e,n),!0;case"color":return R(e,n);case"fold-tools":return n.onFoldTools?n.onFoldTools():n.notify("The fold-tools view setting 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(`/${o} is not available in attach`),!0}}i(X,"dispatchCanvasCommand");function B(o,e){const n=b(e).trim();if(n===""){e.notify("/promote: no node to promote (viewer has no node id)");return}const t=o.trim().toLowerCase();e.notify(t?`Promoting \u2192 ${t}\u2026`:"Promoting\u2026");const r=["node","promote","--node",n,"--json"];t!==""&&r.push("--kind",t),p("crtr",r,{timeout:15e3,maxBuffer:4*1024*1024},(s,a)=>{let l=null,d=null;try{l=JSON.parse(a)}catch{l=null}if(s&&l===null){const L=typeof s.stdout=="string"?s.stdout:"";try{const C=JSON.parse(L);d=typeof C.message=="string"?C.message:null}catch{d=null}d===null&&(d=s.message)}if(l===null){e.notify(`promote failed: ${d??"unknown error"}`);return}const S=(l.roadmap_path??"").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 F(o,e){const n=b(e).trim();if(n===""){e.notify("/rename: no node to rename (viewer has no node id)");return}if(o===""){e.notify("Usage: /rename <name>");return}e.send({type:"set_session_name",name:o});const t=process.env.TMUX_PANE;process.env.TMUX!==void 0&&t!==void 0&&t!==""&&p("tmux",["select-pane","-t",t,"-T",o],()=>{}),p("crtr",["node","config","--node",n,"--name",o,"--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 ${o}`)})}i(F,"renameNode");function c(o){return new Promise(e=>{p("tmux",o,{timeout:5e3},(n,t)=>e(n?"":t))})}i(c,"tmuxCall");async function D(o,e,n){if(n){await c(["set-option","-p","-u","-t",o,"@crtr_color"]);return}await c(["set-option","-p","-t",o,"@crtr_color",e]);for(const t of["pane-border-style","pane-active-border-style"]){const r=(await c(["show-options","-wqv","-t",o,t])).trim();if(r.includes("@crtr_color"))continue;let u=r!==""?r:(await c(["show-options","-gqv",t])).trim();u===""&&(u=t==="pane-active-border-style"?"fg=green":"default");const s=`#{?#{!=:#{@crtr_color},},fg=#{@crtr_color},${u.replace(/,/g,"#,")}}`;await c(["set-option","-w","-t",o,t,s])}}i(D,"paintPaneBorder");function R(o,e){const n=o.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 t=n==="none"||n==="clear";if(!(t||U.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&&D(u,n,t),e.onColor?.(t?null:n),e.notify(t?"Node color cleared":`Node colored ${n}${s?"":" (chip only \u2014 no tmux pane)"}`),!0}i(R,"colorNode");function G(o){const e=process.env.TMUX_PANE;if(process.env.TMUX===void 0||e===void 0||e==="")return o.notify("/resume needs tmux"),!0;const n=y(o.cwd??process.cwd()),t=H(o),r=t===void 0||t===""?"":` --profile-id ${y(t)}`,u=`crtr canvas browse --return-pane ${e} --cwd ${n}${r}`;return k(u,{w:"97%",h:"95%"}),!0}i(G,"resumeNode");function V(o){if(process.env.TMUX===void 0)return o.notify("/context needs tmux"),!0;const e=b(o).trim();return e===""?(o.notify("/context: no node to root on (viewer has no node id)"),!0):(k(`crtr node inspect context --node ${y(e)}`),!0)}i(V,"openContext");function q(o){return process.env.TMUX===void 0?(o.notify("/plugins needs tmux"),!0):(k("crtr pkg browse"),!0)}i(q,"openPlugins");function k(o,e={w:"90%",h:"85%"}){try{p("tmux",["display-popup","-E","-w",e.w,"-h",e.h,...O(),o],()=>{})}catch{}}i(k,"popup");function f(o,e){return o.notify(`Usage: ${e}`),!0}i(f,"usage");function J(o,e,n){return o.notify(`Interactive ${e} picker isn't available over view.sock yet \u2014 use ${n}`),!0}i(J,"pickerHint");function m(o,e,n,t){return o?(o(),!0):J(e,n,t)}i(m,"openOrHint");function Q(o,e){const[n,...t]=o.split(/\s+/),r=t.join(" ").trim();switch(n){case"thinking":return r?N.has(r)?(e.send({type:"set_thinking_level",level:r}),!0):(e.notify(`Invalid thinking level "${r}" \u2014 choose one of: ${[...N].join(", ")}`),!0):f(e,"/settings thinking <level>");case"auto-retry":return e.send({type:"set_auto_retry",enabled:A(r)}),!0;case"auto-compaction":return e.send({type:"set_auto_compaction",enabled:A(r)}),!0;case"":return e.openSettingsPicker?(e.openSettingsPicker(),!0):I(e);default:return I(e)}}i(Q,"handleSettings");function I(o){return o.notify("Settings: /settings thinking <level> | auto-retry on|off | auto-compaction on|off"),!0}i(I,"settingsSummary");function A(o){return/^(on|true|yes|1|enabled?)$/i.test(o.trim())}i(A,"parseBool");function W(o,e){const n=o||`${e}/pi-export-${Date.now()}.html`,t=n.endsWith(".jsonl")?"jsonl":"html";return{path:n,format:t}}i(W,"parseExport");function Y(o){return o?`Session ${o.sessionName?`"${o.sessionName}" `:""}${o.sessionId} \xB7 model ${o.model?.id??"unknown"} \xB7 thinking ${o.thinkingLevel}`:"Session info unavailable"}i(Y,"describeSession");export{g as CANVAS_SLASH_COMMANDS,se as commandAutocompleteItems,re as dispatchSlashCommand,te as isSlashCommand,oe as locallyConsumedCommandNames,ie as slashCommandList};
|
|
1
|
+
var E=Object.defineProperty;var i=(t,e)=>E(t,"name",{value:e,configurable:!0});import{execFile as p}from"node:child_process";import{BUILTIN_SLASH_COMMANDS as h}from"../../../core/runtime/pi-vendored.js";import{surfaceTmuxStyleArgs as O}from"../../../core/runtime/surface-bg.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:"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 this node + 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, artifacts, 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:"fold-tools",description:"View setting \u2014 fold every FINISHED tool call to its single call line (Alt+C \u2192 z \u2192 f)"}],$=new Map([["resume-node","resume"]]),w=new Set([...g.map(t=>t.name),...$.keys()]),U=new Set(["black","red","green","yellow","blue","magenta","cyan","white","brightred","brightgreen","brightyellow","brightblue","brightmagenta","brightcyan","orange","grey","gray","default"]),T=new Set(["trust"]),N=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 P(t,e){const n=_(t,v.has(t),w.has(t));return n===void 0?void 0:e.capabilities.refusal(n,t)}i(P,"readOnlyRefusal");function te(){return new Set([...v,...w,...T])}i(te,"locallyConsumedCommandNames");function j(t){const e=/^\/(\S+)\s*([\s\S]*)$/.exec(t.trim());return e===null?void 0:{name:e[1],arg:e[2].trim()}}i(j,"parseSlashCommand");function oe(t){return t.trimStart().startsWith("/")}i(oe,"isSlashCommand");function re(t,e){const n=j(t);if(n===void 0)return!1;const{arg:o}=n,r=$.get(n.name)??n.name;if(T.has(r))return e.notify(`/${r} is not supported in attach (Phase 4)`),!0;if(w.has(r)){const s=P(r,e);return s!==void 0?(e.notify(s),!0):X(r,o,e)}if(!v.has(r))return!1;const u=P(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}=W(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 Q(o,e);case"session":return e.notify(Y(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(re,"dispatchSlashCommand");function M(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(M,"withCanvasCommands");function ie(t,e){return M(t??h,e).map(n=>({name:n.name,description:n.description}))}i(ie,"slashCommandList");function se(t,e){return M(t??h,e).map(n=>({value:`/${n.name}`,label:`/${n.name}`,description:n.description}))}i(se,"commandAutocompleteItems");function X(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"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 V(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 F(e,n),!0;case"color":return R(e,n);case"fold-tools":return n.onFoldTools?n.onFoldTools():n.notify("The fold-tools view setting 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(X,"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),p("crtr",r,{timeout:15e3,maxBuffer:4*1024*1024},(s,a)=>{let l=null,d=null;try{l=JSON.parse(a)}catch{l=null}if(s&&l===null){const L=typeof s.stdout=="string"?s.stdout:"";try{const C=JSON.parse(L);d=typeof C.message=="string"?C.message:null}catch{d=null}d===null&&(d=s.message)}if(l===null){e.notify(`promote failed: ${d??"unknown error"}`);return}const S=(l.roadmap_path??"").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 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 o=process.env.TMUX_PANE;process.env.TMUX!==void 0&&o!==void 0&&o!==""&&p("tmux",["select-pane","-t",o,"-T",t],()=>{}),p("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(F,"renameNode");function c(t){return new Promise(e=>{p("tmux",t,{timeout:5e3},(n,o)=>e(n?"":o))})}i(c,"tmuxCall");async function D(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(D,"paintPaneBorder");function R(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||U.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&&D(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(R,"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=H(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 V(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(V,"openContext");function q(t){return process.env.TMUX===void 0?(t.notify("/plugins needs tmux"),!0):(k("crtr pkg browse"),!0)}i(q,"openPlugins");function k(t,e={w:"90%",h:"85%"}){try{p("tmux",["display-popup","-E","-w",e.w,"-h",e.h,...O(),t],()=>{})}catch{}}i(k,"popup");function m(t,e){return t.notify(`Usage: ${e}`),!0}i(m,"usage");function J(t,e,n){return t.notify(`Interactive ${e} picker isn't available over view.sock yet \u2014 use ${n}`),!0}i(J,"pickerHint");function f(t,e,n,o){return t?(t(),!0):J(e,n,o)}i(f,"openOrHint");function Q(t,e){const[n,...o]=t.split(/\s+/),r=o.join(" ").trim();switch(n){case"thinking":return r?N.has(r)?(e.send({type:"set_thinking_level",level:r}),!0):(e.notify(`Invalid thinking level "${r}" \u2014 choose one of: ${[...N].join(", ")}`),!0):m(e,"/settings thinking <level>");case"auto-retry":return e.send({type:"set_auto_retry",enabled:A(r)}),!0;case"auto-compaction":return e.send({type:"set_auto_compaction",enabled:A(r)}),!0;case"":return e.openSettingsPicker?(e.openSettingsPicker(),!0):I(e);default:return I(e)}}i(Q,"handleSettings");function I(t){return t.notify("Settings: /settings thinking <level> | auto-retry on|off | auto-compaction on|off"),!0}i(I,"settingsSummary");function A(t){return/^(on|true|yes|1|enabled?)$/i.test(t.trim())}i(A,"parseBool");function W(t,e){const n=t||`${e}/pi-export-${Date.now()}.html`,o=n.endsWith(".jsonl")?"jsonl":"html";return{path:n,format:o}}i(W,"parseExport");function Y(t){return t?`Session ${t.sessionName?`"${t.sessionName}" `:""}${t.sessionId} \xB7 model ${t.model?.id??"unknown"} \xB7 thinking ${t.thinkingLevel}`:"Session info unavailable"}i(Y,"describeSession");export{g as CANVAS_SLASH_COMMANDS,se as commandAutocompleteItems,re as dispatchSlashCommand,oe as isSlashCommand,te as locallyConsumedCommandNames,ie as slashCommandList};
|