@north-light/cli 0.3.654 → 0.3.656
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/api/contract.d.ts +1 -1
- package/dist/api/contract.js +1 -1
- package/dist/api/dto/docs.d.ts +6 -3
- package/dist/clients/attach/config.js +1 -1
- package/dist/clients/attach/input/controller.d.ts +2 -3
- package/dist/clients/attach/input/controller.js +3 -3
- package/dist/clients/attach/render/chat-view.d.ts +41 -37
- package/dist/clients/attach/render/chat-view.js +3 -3
- package/dist/clients/attach/session/bindings.d.ts +1 -1
- package/dist/clients/attach/session/bindings.js +1 -1
- package/dist/clients/attach/session/document-links.d.ts +3 -2
- package/dist/clients/attach/session/document-links.js +1 -1
- package/dist/clients/attach/session/input-wiring.d.ts +9 -9
- package/dist/clients/attach/session/input-wiring.js +1 -1
- package/dist/clients/attach/slash/dispatch.d.ts +6 -8
- package/dist/clients/attach/slash/dispatch.js +2 -2
- package/dist/clients/attach/viewer.js +514 -514
- package/dist/commands/node/create.js +1 -1
- package/dist/commands/sys/panels/prefs-panel.js +1 -1
- package/dist/core/config.js +1 -1
- package/dist/core/graph/documents.js +13 -11
- package/dist/core/graph/edges.js +4 -3
- package/dist/core/graph/events.d.ts +1 -1
- package/dist/core/graph/events.js +8 -8
- package/dist/core/graph/exposures.js +7 -4
- package/dist/core/graph/kinds/document.js +4 -4
- package/dist/core/graph/kinds/dto.d.ts +2 -0
- package/dist/core/graph/kinds/dto.js +1 -1
- package/dist/core/graph/names.d.ts +4 -0
- package/dist/core/graph/names.js +9 -8
- package/dist/core/graph/rules.d.ts +2 -0
- package/dist/core/graph/rules.js +3 -3
- package/dist/core/keybindings/catalog.d.ts +3 -3
- package/dist/core/keybindings/catalog.js +1 -1
- package/dist/core/runtime/broker/tool-groups.js +1 -1
- package/dist/core/runtime/broker/turn-replies.d.ts +1 -4
- package/dist/core/runtime/broker/turn-replies.js +1 -1
- package/dist/core/runtime/broker-protocol.d.ts +2 -2
- package/dist/core/runtime/tmux-bindings.js +3 -3
- package/dist/core/substrate/delivery/corpus.d.ts +3 -0
- package/dist/core/substrate/delivery/corpus.js +2 -3
- package/dist/core/substrate/delivery/render-event.js +4 -4
- package/dist/core/user-settings.d.ts +13 -35
- package/dist/core/user-settings.js +1 -1
- package/dist/daemon/api/canvas-host.d.ts +9 -0
- package/dist/daemon/api/canvas-host.js +1 -0
- package/dist/daemon/api/document-listener.js +1 -11
- package/dist/daemon/api/document-page.d.ts +18 -0
- package/dist/daemon/api/document-page.js +11 -0
- package/dist/daemon/api/handlers/document-access.js +1 -1
- package/dist/daemon/api/server.js +1 -1
- package/dist/daemon/broker-signals/bus.d.ts +3 -2
- package/dist/daemon/broker-signals/bus.js +1 -1
- package/dist/doc-editor/editor.js +24 -24
- package/dist/types.d.ts +13 -15
- package/dist/types.js +1 -1
- package/docs/cli/the-viewer.md +16 -2
- package/package.json +2 -2
- package/packages/crouter-identity/package.json +1 -1
- package/runtime.lock.json +13 -13
|
@@ -75,7 +75,7 @@ export interface BrokerSnapshot {
|
|
|
75
75
|
* Structured objects with bullets and filesDeleted.
|
|
76
76
|
* Optional so snapshots from an older live runtime remain readable. */
|
|
77
77
|
toolGroupSummaries?: Record<string, ToolGroupSummary>;
|
|
78
|
-
/** Consolidated replies (`
|
|
78
|
+
/** Consolidated replies (the viewer's `replies` verbosity), keyed by the
|
|
79
79
|
* turn's opening user-message timestamp (or `start`). Optional: absent from
|
|
80
80
|
* older runtimes and when no turn has been rewritten. */
|
|
81
81
|
turnReplies?: Record<string, TurnReply>;
|
|
@@ -643,7 +643,7 @@ export interface ToolGroupSummaryFrame {
|
|
|
643
643
|
key: string;
|
|
644
644
|
summary: ToolGroupSummary;
|
|
645
645
|
}
|
|
646
|
-
/** A completed consolidated-reply rewrite for one turn (`
|
|
646
|
+
/** A completed consolidated-reply rewrite for one turn (the viewer's `replies` verbosity). */
|
|
647
647
|
export interface TurnReplyFrame {
|
|
648
648
|
type: 'turn_reply';
|
|
649
649
|
key: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Q=Object.defineProperty;var u=(e,n)=>Q(e,"name",{value:n,configurable:!0});import{mkdtempSync as Y,rmSync as Z,writeFileSync as V}from"node:fs";import{tmpdir as O}from"node:os";import{join as M}from"node:path";import{ATTACH_CONTROL_BINDINGS as U,BINDING_CATALOG as _,BINDING_IDS as ee,encodeAttachControlInput as ne,formatGesture as te,isAttachPaneBinding as re,resolveUserKeybindingSettings as q}from"../keybindings/index.js";import{normalizeTmuxPassthrough as ie}from"../config.js";import{withExclusiveDirectoryLock as oe}from"../exclusive-lock.js";import{surfaceTmuxStyleArgs as se}from"./surface-bg.js";import{runTmux as f,shellQuote as k}from"./tmux-driver.js";const A="@crtr_keybindings_manifest",p="root",ue={"crtr.tmux.menu.promote":{description:"promote to orchestrator",action:{kind:"keys",keys:"/promote"}},"crtr.tmux.menu.resume":{description:"find node",action:{kind:"keys",keys:"/resume"}},"crtr.tmux.menu.dashboard":{description:"dashboard",action:{kind:"direct",run:"surface dashboard --pane {pane}"}},"crtr.tmux.menu.fork":{description:"fork into idle root",action:{kind:"direct",run:"node fork --pane {pane}"}},"crtr.tmux.menu.demote-mode":{description:"demote to base node",action:{kind:"direct",run:"node config --mode base --pane {pane}"}},"crtr.tmux.menu.demote":{description:"demote to terminal (finish when done)",action:{kind:"direct",run:"node lifecycle demote --pane {pane}"}},"crtr.tmux.menu.make-resident":{description:"make resident (interactable)",action:{kind:"direct",run:"node config --lifecycle resident --pane {pane}"}},"crtr.tmux.menu.detach":{description:"demote + close viewer",action:{kind:"direct",run:"node lifecycle demote --pane {pane} --detach"}},"crtr.tmux.menu.close-subtree":{description:"close agent + subtree",action:{kind:"direct",run:"node lifecycle close --pane {pane}"}},"crtr.tmux.menu.background-bash":{description:"background running bash",action:{kind:"direct",run:"node bash background --pane {pane}"}},"crtr.tmux.menu.file-review":{description:"review a file",action:{kind:"raw-keys",keys:"M-S-r"}},"crtr.tmux.menu.metadata":{description:"metadata",action:{kind:"keys",keys:"/node-metadata"}},"crtr.tmux.menu.fold-tools":{description:"fold finished tool calls",action:{kind:"keys",keys:"/fold-tools"}},"crtr.tmux.menu.show-working":{description:"show/hide working",action:{kind:"keys",keys:"/show-working"}},"crtr.tmux.menu.context":{description:"context + reports",action:{kind:"keys",keys:"/context"}},"crtr.tmux.menu.providers":{description:"settings",action:{kind:"popup",run:"sys settings",size:{w:"90%",h:"85%"}}},"crtr.tmux.menu.provider-options":{description:"provider options",action:{kind:"popup",run:"sys settings --page provider-options",size:{w:"90%",h:"85%"}}},"crtr.tmux.menu.plugins":{description:"plugins",action:{kind:"popup",run:"pkg browse",size:{w:"90%",h:"85%"}}},"crtr.tmux.menu.analytics":{description:"analytics",action:{kind:"popup",run:"canvas analytics --pane {pane}",size:{w:"90%",h:"85%"}}},"crtr.tmux.menu.context-admin":{description:"context surface",action:{kind:"popup",run:"sys context admin",size:{w:"98%",h:"96%"}}},"crtr.tmux.menu.graph":{description:"canvas graph",action:{kind:"keys",keys:"/graph"}},"crtr.tmux.menu.focus-manager":{description:"go to manager",action:{kind:"command",run:"surface node focus {manager}"}},"crtr.tmux.menu.copy-id":{description:"copy node id",action:{kind:"direct",run:"surface node id --pane {pane}"}},"crtr.tmux.menu.reload-viewer":{description:"reload viewer",action:{kind:"direct",run:"surface reload --pane {pane}"}},"crtr.tmux.menu.recap":{description:"generate recap",action:{kind:"keys",keys:"/recap"}},"crtr.tmux.menu.pin":{description:"pin conversation",action:{kind:"direct",run:"surface node pin --pane {pane}"}},"crtr.tmux.menu.issue.idea":{description:"idea",action:{kind:"popup",run:"canvas issue new --type idea"}},"crtr.tmux.menu.issue.bug":{description:"bug",action:{kind:"popup",run:"canvas issue new --type bug"}}};function b(e){return e.replace(/#/g,"##")}u(b,"escapeTmuxFormats");function ce(e){return e.map(k).join(" ")}u(ce,"tmuxCommand");const ae={w:"60%",h:"50%"};function G(e,n=!1,t=ae){const r=`crtr canvas chord --pane '#{pane_id}' --run ${k(b(e))}${n?" --interactive":""}`;return n?{argv:["display-popup","-E","-w",t.w,"-h",t.h,"-d","#{pane_current_path}",r],menu:`display-popup -E -w ${t.w} -h ${t.h} -d "#{pane_current_path}" ${k(r)}`}:{argv:["run-shell",`${r} >/dev/null 2>&1`],menu:`run-shell ${k(`${r} >/dev/null 2>&1`)}`}}u(G,"chordCommand");function de(e){const t=`crtr ${b(e).replace("{pane}","#{pane_id}")} >/dev/null 2>&1`;return{argv:["run-shell","-b",t],menu:`run-shell -b ${k(t)}`}}u(de,"directCommand");function j(e){switch(e.kind){case"disabled":return null;case"separator":return null;case"dismiss":return{argv:["refresh-client"],menu:"refresh-client"};case"keys":{const n=b(e.keys);return{argv:["send-keys",n,"Enter"],menu:`send-keys -t '#{pane_id}' ${k(n)} Enter`}}case"raw-keys":{const n=b(e.keys);return{argv:["send-keys",n],menu:`send-keys -t '#{pane_id}' ${k(n)}`}}case"literal-input":{const n=b(e.input);return{argv:["send-keys","-l",n],menu:`send-keys -l -t '#{pane_id}' ${k(n)}`}}case"command":return G(e.run);case"direct":return de(e.run);case"popup":return G(e.run,!0,e.size);case"submenu":{const n=N(e.title,e.items);return{argv:n,menu:ce(n)}}}}u(j,"menuActionCommand");function me(e){return j(e)?.menu??""}u(me,"renderMenuAction");function pe(e){return e.replace(/#\[[^\]]*\]/g,"").length}u(pe,"menuItemWidth");function N(e,n){const t=b(e),r=n.reduce((o,c)=>Math.max(o,pe(c.description)),0),s=["display-menu","-T",`#[align=centre]${t}`,...se()];s.push("-x",`#{e|-:#{pane_right},${Math.max(t.length,r)+7}}`,"-y","#{e|+:#{pane_top},3}","--");for(const o of n){if(o.action.kind==="separator"){s.push("");continue}const c=o.action.kind==="disabled"?o.description:b(o.description);s.push(c,o.selector,me(o.action))}return s.push("","-esc / q to close","",""),s}u(N,"buildMenuArgs");const le={enter:"Enter",escape:"Escape",tab:"Tab",backspace:"BSpace",delete:"DC",space:"Space",up:"Up",down:"Down",left:"Left",right:"Right",pageup:"PPage",pagedown:"NPage",home:"Home",end:"End"};function z(e){if(e==="+")return{key:"+",modifiers:[]};if(e.endsWith("++"))return{key:"+",modifiers:e.slice(0,-2).split("+")};const n=e.split("+");return{key:n.pop(),modifiers:n}}u(z,"normalizedStrokeParts");function fe(e){return v(e)[0]}u(fe,"tmuxKey");function v(e){let{key:n,modifiers:t}=z(e);const r=new Set(t),s=u((o,c)=>[r.has("ctrl")?"C-":"",r.has("alt")?"M-":"",c?"S-":"",le[o]??o].join(""),"name");if(r.has("shift")&&n.length===1&&/[a-z]/.test(n)){const o=n.toUpperCase();return!r.has("ctrl")&&!r.has("alt")?[s(o,!1)]:[s(o,!0),s(o,!1),s(n,!0)]}return[s(n,r.has("shift"))]}u(v,"tmuxKeyNames");function ge(e){const{key:n,modifiers:t}=z(e);return t.includes("shift")&&/[a-z]/.test(n)?n.toUpperCase():n==="space"?" ":n}u(ge,"menuSelector");function T(e,n,t){const r=[];for(const s of e){const o=n.get(s);if(o!==void 0)for(const c of t.gestures(s))r.push({description:o.description,selector:ge(c),action:o.action})}return r}u(T,"boundMenuItems");function F(e){const n=new Map;for(const[c,l]of Object.entries(ue))l!==void 0&&n.set(c,l);for(const{menuId:c,actionId:l}of U){const x=_.find(w=>w.id===l);if(x===void 0)throw new Error(`missing attach binding definition ${l}`);n.set(c,{description:x.name.toLowerCase(),action:{kind:"literal-input",input:ne(l)}})}const t=T(U.map(({menuId:c})=>c),n,e);t.length>0&&n.set("crtr.tmux.menu.attach",{description:"attach viewer \u203A",action:{kind:"submenu",title:" attach viewer ",items:t}});const r=T(["crtr.tmux.menu.metadata","crtr.tmux.menu.context"],n,e);n.set("crtr.tmux.menu.show",{description:"inspect \u203A",action:{kind:"submenu",title:" inspect node ",items:r}});const s=T(["crtr.tmux.menu.fold-tools","crtr.tmux.menu.show-working"],n,e);n.set("crtr.tmux.menu.view-settings",{description:"display \u203A",action:{kind:"submenu",title:" display ",items:s}});const o=T(["crtr.tmux.menu.issue.idea","crtr.tmux.menu.issue.bug"],n,e);return n.set("crtr.tmux.menu.issues",{description:"create \u203A",action:{kind:"submenu",title:" create ",items:o}}),n}u(F,"resolvedMenuActions");function K(e,n){const t=u(c=>T(c,n,e),"boundItems"),r=[],s=u((c,l)=>{l.length!==0&&(r.length>0&&r.push({description:"",selector:"",action:{kind:"separator"}}),r.push({description:`-#[bold]${c}`,selector:"",action:{kind:"disabled"}},...l))},"addGroup");s("Explore",t(["crtr.tmux.menu.dashboard","crtr.tmux.menu.resume","crtr.tmux.menu.graph","crtr.tmux.menu.focus-manager","crtr.tmux.menu.show","crtr.tmux.menu.view-settings"])),s("Current node",t(["crtr.tmux.menu.attach","crtr.tmux.menu.background-bash","crtr.tmux.menu.file-review","crtr.tmux.menu.pin","crtr.tmux.menu.copy-id","crtr.tmux.menu.reload-viewer","crtr.tmux.menu.recap"])),s("Lifecycle",t(["crtr.tmux.menu.fork","crtr.tmux.menu.promote","crtr.tmux.menu.demote-mode","crtr.tmux.menu.demote","crtr.tmux.menu.make-resident","crtr.tmux.menu.detach","crtr.tmux.menu.close-subtree"])),s("System",t(["crtr.tmux.menu.providers","crtr.tmux.menu.provider-options","crtr.tmux.menu.plugins","crtr.tmux.menu.analytics","crtr.tmux.menu.context-admin","crtr.tmux.menu.issues"]));const o=e.gestures("crtr.tmux.menu.open");if(o.length>0&&r.length>0){r.push({description:"",selector:"",action:{kind:"separator"}});for(const c of o)r.push({description:`${te(c)} to close`,selector:fe(c),action:{kind:"dismiss"}})}return r}u(K,"menuItems");function Pe(e){const n=e??q().bindings;return N(" crtr ",K(n,F(n)))}u(Pe,"crouterMenuTmuxArgs");function S(e,n){let t=n;for(;t<e.length&&/\s/.test(e[t]);)t+=1;if(t>=e.length)return null;let r=null,s="";for(;t<e.length;){const o=e[t];if(r===null&&/\s/.test(o))break;if(r===null&&(o==="'"||o==='"')){r=o,t+=1;continue}if(r===o){r=null,t+=1;continue}if(o==="\\"&&r!=="'"&&t+1<e.length){s+=e[t+1],t+=2;continue}s+=o,t+=1}return{value:s,end:t}}u(S,"readTmuxToken");function B(e){const n=S(e,0);if(n?.value!=="bind-key")return null;let t=n.end,r=!1;for(;;){const s=S(e,t);if(s===null)return null;if(t=s.end,s.value==="-r"){r=!0;continue}if(s.value!=="-T")continue;const o=S(e,t);if(o===null)return null;const c=S(e,o.end);return c===null?null:{table:o.value,key:c.value,command:e.slice(c.end).trimStart(),repeat:r}}}u(B,"parseTmuxBinding");function $(e,n){const t=f(["list-keys","-T",e]);return t.ok?t.stdout.split(`
|
|
1
|
+
var Q=Object.defineProperty;var u=(e,n)=>Q(e,"name",{value:n,configurable:!0});import{mkdtempSync as Y,rmSync as Z,writeFileSync as V}from"node:fs";import{tmpdir as O}from"node:os";import{join as M}from"node:path";import{ATTACH_CONTROL_BINDINGS as U,BINDING_CATALOG as _,BINDING_IDS as ee,encodeAttachControlInput as ne,formatGesture as te,isAttachPaneBinding as re,resolveUserKeybindingSettings as q}from"../keybindings/index.js";import{normalizeTmuxPassthrough as ie}from"../config.js";import{withExclusiveDirectoryLock as oe}from"../exclusive-lock.js";import{surfaceTmuxStyleArgs as se}from"./surface-bg.js";import{runTmux as f,shellQuote as x}from"./tmux-driver.js";const A="@crtr_keybindings_manifest",p="root",ue={"crtr.tmux.menu.promote":{description:"promote to orchestrator",action:{kind:"keys",keys:"/promote"}},"crtr.tmux.menu.resume":{description:"find node",action:{kind:"keys",keys:"/resume"}},"crtr.tmux.menu.dashboard":{description:"dashboard",action:{kind:"direct",run:"surface dashboard --pane {pane}"}},"crtr.tmux.menu.fork":{description:"fork into idle root",action:{kind:"direct",run:"node fork --pane {pane}"}},"crtr.tmux.menu.demote-mode":{description:"demote to base node",action:{kind:"direct",run:"node config --mode base --pane {pane}"}},"crtr.tmux.menu.demote":{description:"demote to terminal (finish when done)",action:{kind:"direct",run:"node lifecycle demote --pane {pane}"}},"crtr.tmux.menu.make-resident":{description:"make resident (interactable)",action:{kind:"direct",run:"node config --lifecycle resident --pane {pane}"}},"crtr.tmux.menu.detach":{description:"demote + close viewer",action:{kind:"direct",run:"node lifecycle demote --pane {pane} --detach"}},"crtr.tmux.menu.close-subtree":{description:"close agent + subtree",action:{kind:"direct",run:"node lifecycle close --pane {pane}"}},"crtr.tmux.menu.background-bash":{description:"background running bash",action:{kind:"direct",run:"node bash background --pane {pane}"}},"crtr.tmux.menu.file-review":{description:"review a file",action:{kind:"raw-keys",keys:"M-S-r"}},"crtr.tmux.menu.metadata":{description:"metadata",action:{kind:"keys",keys:"/node-metadata"}},"crtr.tmux.menu.more-detail":{description:"more detail",action:{kind:"keys",keys:"/more-detail"}},"crtr.tmux.menu.less-detail":{description:"less detail",action:{kind:"keys",keys:"/less-detail"}},"crtr.tmux.menu.context":{description:"context + reports",action:{kind:"keys",keys:"/context"}},"crtr.tmux.menu.providers":{description:"settings",action:{kind:"popup",run:"sys settings",size:{w:"90%",h:"85%"}}},"crtr.tmux.menu.provider-options":{description:"provider options",action:{kind:"popup",run:"sys settings --page provider-options",size:{w:"90%",h:"85%"}}},"crtr.tmux.menu.plugins":{description:"plugins",action:{kind:"popup",run:"pkg browse",size:{w:"90%",h:"85%"}}},"crtr.tmux.menu.analytics":{description:"analytics",action:{kind:"popup",run:"canvas analytics --pane {pane}",size:{w:"90%",h:"85%"}}},"crtr.tmux.menu.context-admin":{description:"context surface",action:{kind:"popup",run:"sys context admin",size:{w:"98%",h:"96%"}}},"crtr.tmux.menu.graph":{description:"canvas graph",action:{kind:"keys",keys:"/graph"}},"crtr.tmux.menu.focus-manager":{description:"go to manager",action:{kind:"command",run:"surface node focus {manager}"}},"crtr.tmux.menu.copy-id":{description:"copy node id",action:{kind:"direct",run:"surface node id --pane {pane}"}},"crtr.tmux.menu.reload-viewer":{description:"reload viewer",action:{kind:"direct",run:"surface reload --pane {pane}"}},"crtr.tmux.menu.recap":{description:"generate recap",action:{kind:"keys",keys:"/recap"}},"crtr.tmux.menu.pin":{description:"pin conversation",action:{kind:"direct",run:"surface node pin --pane {pane}"}},"crtr.tmux.menu.issue.idea":{description:"idea",action:{kind:"popup",run:"canvas issue new --type idea"}},"crtr.tmux.menu.issue.bug":{description:"bug",action:{kind:"popup",run:"canvas issue new --type bug"}}};function b(e){return e.replace(/#/g,"##")}u(b,"escapeTmuxFormats");function ce(e){return e.map(x).join(" ")}u(ce,"tmuxCommand");const ae={w:"60%",h:"50%"};function G(e,n=!1,t=ae){const r=`crtr canvas chord --pane '#{pane_id}' --run ${x(b(e))}${n?" --interactive":""}`;return n?{argv:["display-popup","-E","-w",t.w,"-h",t.h,"-d","#{pane_current_path}",r],menu:`display-popup -E -w ${t.w} -h ${t.h} -d "#{pane_current_path}" ${x(r)}`}:{argv:["run-shell",`${r} >/dev/null 2>&1`],menu:`run-shell ${x(`${r} >/dev/null 2>&1`)}`}}u(G,"chordCommand");function de(e){const t=`crtr ${b(e).replace("{pane}","#{pane_id}")} >/dev/null 2>&1`;return{argv:["run-shell","-b",t],menu:`run-shell -b ${x(t)}`}}u(de,"directCommand");function j(e){switch(e.kind){case"disabled":return null;case"separator":return null;case"dismiss":return{argv:["refresh-client"],menu:"refresh-client"};case"keys":{const n=b(e.keys);return{argv:["send-keys",n,"Enter"],menu:`send-keys -t '#{pane_id}' ${x(n)} Enter`}}case"raw-keys":{const n=b(e.keys);return{argv:["send-keys",n],menu:`send-keys -t '#{pane_id}' ${x(n)}`}}case"literal-input":{const n=b(e.input);return{argv:["send-keys","-l",n],menu:`send-keys -l -t '#{pane_id}' ${x(n)}`}}case"command":return G(e.run);case"direct":return de(e.run);case"popup":return G(e.run,!0,e.size);case"submenu":{const n=N(e.title,e.items);return{argv:n,menu:ce(n)}}}}u(j,"menuActionCommand");function me(e){return j(e)?.menu??""}u(me,"renderMenuAction");function pe(e){return e.replace(/#\[[^\]]*\]/g,"").length}u(pe,"menuItemWidth");function N(e,n){const t=b(e),r=n.reduce((o,c)=>Math.max(o,pe(c.description)),0),s=["display-menu","-T",`#[align=centre]${t}`,...se()];s.push("-x",`#{e|-:#{pane_right},${Math.max(t.length,r)+7}}`,"-y","#{e|+:#{pane_top},3}","--");for(const o of n){if(o.action.kind==="separator"){s.push("");continue}const c=o.action.kind==="disabled"?o.description:b(o.description);s.push(c,o.selector,me(o.action))}return s.push("","-esc / q to close","",""),s}u(N,"buildMenuArgs");const le={enter:"Enter",escape:"Escape",tab:"Tab",backspace:"BSpace",delete:"DC",space:"Space",up:"Up",down:"Down",left:"Left",right:"Right",pageup:"PPage",pagedown:"NPage",home:"Home",end:"End"};function z(e){if(e==="+")return{key:"+",modifiers:[]};if(e.endsWith("++"))return{key:"+",modifiers:e.slice(0,-2).split("+")};const n=e.split("+");return{key:n.pop(),modifiers:n}}u(z,"normalizedStrokeParts");function fe(e){return v(e)[0]}u(fe,"tmuxKey");function v(e){let{key:n,modifiers:t}=z(e);const r=new Set(t),s=u((o,c)=>[r.has("ctrl")?"C-":"",r.has("alt")?"M-":"",c?"S-":"",le[o]??o].join(""),"name");if(r.has("shift")&&n.length===1&&/[a-z]/.test(n)){const o=n.toUpperCase();return!r.has("ctrl")&&!r.has("alt")?[s(o,!1)]:[s(o,!0),s(o,!1),s(n,!0)]}return[s(n,r.has("shift"))]}u(v,"tmuxKeyNames");function ge(e){const{key:n,modifiers:t}=z(e);return t.includes("shift")&&/[a-z]/.test(n)?n.toUpperCase():n==="space"?" ":n}u(ge,"menuSelector");function T(e,n,t){const r=[];for(const s of e){const o=n.get(s);if(o!==void 0)for(const c of t.gestures(s))r.push({description:o.description,selector:ge(c),action:o.action})}return r}u(T,"boundMenuItems");function F(e){const n=new Map;for(const[c,l]of Object.entries(ue))l!==void 0&&n.set(c,l);for(const{menuId:c,actionId:l}of U){const h=_.find(w=>w.id===l);if(h===void 0)throw new Error(`missing attach binding definition ${l}`);n.set(c,{description:h.name.toLowerCase(),action:{kind:"literal-input",input:ne(l)}})}const t=T(U.map(({menuId:c})=>c),n,e);t.length>0&&n.set("crtr.tmux.menu.attach",{description:"attach viewer \u203A",action:{kind:"submenu",title:" attach viewer ",items:t}});const r=T(["crtr.tmux.menu.metadata","crtr.tmux.menu.context"],n,e);n.set("crtr.tmux.menu.show",{description:"inspect \u203A",action:{kind:"submenu",title:" inspect node ",items:r}});const s=T(["crtr.tmux.menu.more-detail","crtr.tmux.menu.less-detail"],n,e);n.set("crtr.tmux.menu.view-settings",{description:"display \u203A",action:{kind:"submenu",title:" display ",items:s}});const o=T(["crtr.tmux.menu.issue.idea","crtr.tmux.menu.issue.bug"],n,e);return n.set("crtr.tmux.menu.issues",{description:"create \u203A",action:{kind:"submenu",title:" create ",items:o}}),n}u(F,"resolvedMenuActions");function K(e,n){const t=u(c=>T(c,n,e),"boundItems"),r=[],s=u((c,l)=>{l.length!==0&&(r.length>0&&r.push({description:"",selector:"",action:{kind:"separator"}}),r.push({description:`-#[bold]${c}`,selector:"",action:{kind:"disabled"}},...l))},"addGroup");s("Explore",t(["crtr.tmux.menu.dashboard","crtr.tmux.menu.resume","crtr.tmux.menu.graph","crtr.tmux.menu.focus-manager","crtr.tmux.menu.show","crtr.tmux.menu.view-settings"])),s("Current node",t(["crtr.tmux.menu.attach","crtr.tmux.menu.background-bash","crtr.tmux.menu.file-review","crtr.tmux.menu.pin","crtr.tmux.menu.copy-id","crtr.tmux.menu.reload-viewer","crtr.tmux.menu.recap"])),s("Lifecycle",t(["crtr.tmux.menu.fork","crtr.tmux.menu.promote","crtr.tmux.menu.demote-mode","crtr.tmux.menu.demote","crtr.tmux.menu.make-resident","crtr.tmux.menu.detach","crtr.tmux.menu.close-subtree"])),s("System",t(["crtr.tmux.menu.providers","crtr.tmux.menu.provider-options","crtr.tmux.menu.plugins","crtr.tmux.menu.analytics","crtr.tmux.menu.context-admin","crtr.tmux.menu.issues"]));const o=e.gestures("crtr.tmux.menu.open");if(o.length>0&&r.length>0){r.push({description:"",selector:"",action:{kind:"separator"}});for(const c of o)r.push({description:`${te(c)} to close`,selector:fe(c),action:{kind:"dismiss"}})}return r}u(K,"menuItems");function Pe(e){const n=e??q().bindings;return N(" crtr ",K(n,F(n)))}u(Pe,"crouterMenuTmuxArgs");function S(e,n){let t=n;for(;t<e.length&&/\s/.test(e[t]);)t+=1;if(t>=e.length)return null;let r=null,s="";for(;t<e.length;){const o=e[t];if(r===null&&/\s/.test(o))break;if(r===null&&(o==="'"||o==='"')){r=o,t+=1;continue}if(r===o){r=null,t+=1;continue}if(o==="\\"&&r!=="'"&&t+1<e.length){s+=e[t+1],t+=2;continue}s+=o,t+=1}return{value:s,end:t}}u(S,"readTmuxToken");function B(e){const n=S(e,0);if(n?.value!=="bind-key")return null;let t=n.end,r=!1;for(;;){const s=S(e,t);if(s===null)return null;if(t=s.end,s.value==="-r"){r=!0;continue}if(s.value!=="-T")continue;const o=S(e,t);if(o===null)return null;const c=S(e,o.end);return c===null?null:{table:o.value,key:c.value,command:e.slice(c.end).trimStart(),repeat:r}}}u(B,"parseTmuxBinding");function $(e,n){const t=f(["list-keys","-T",e]);return t.ok?t.stdout.split(`
|
|
2
2
|
`).find(r=>{const s=B(r);return s?.table===e&&s.key===n})??null:null}u($,"bindingAt");function Le(e){const n=f(["list-keys","-T",p]);if(!n.ok)return[];const t=new Set(n.stdout.split(`
|
|
3
|
-
`).flatMap(r=>{const s=B(r);return s?.table===p?[s.key]:[]}));return e.filter(r=>!r.includes(" > ")&&v(r).some(s=>t.has(s)))}u(Le,"occupiedTmuxRootGestures");function R(e){return typeof e=="object"&&e!==null&&typeof e.table=="string"&&typeof e.key=="string"}u(R,"isInstalledPair");function
|
|
4
|
-
`,"utf8"),f(["source-file",t])}finally{Z(n,{recursive:!0,force:!0})}}u(be,"sourceBindingLine");function X(e){return e.original===null?f(["unbind-key","-T",p,C(e.key)]):be(e.original)}u(X,"restoreWrappedBinding");function we(){return["run-shell","-b",'crtr surface inbox --quiet --tmux-socket "#{socket_path}" --tmux-client "#{client_name}" --target-pane "#{pane_id}"']}u(we,"inboxToggleTmuxCommand");function ve(e){switch(e){case"crtr.tmux.node.next":return["run-shell","crtr surface node cycle --dir next --pane '#{pane_id}' >/dev/null 2>&1"];case"crtr.tmux.node.previous":return["run-shell","crtr surface node cycle --dir prev --pane '#{pane_id}' >/dev/null 2>&1"];case"crtr.tmux.inbox.toggle":return we();default:throw new Error(`no tmux command for ${e}`)}}u(ve,"actionCommand");function $e(){const e=process.env.TMUX?.split(",")[0]?.trim();if(e!==void 0&&e!=="")return`${e}.crtr-keybindings.lock`;const n=f(["display-message","-p","#{socket_path}"]);if(n.ok&&n.stdout!=="")return`${n.stdout}.crtr-keybindings.lock`;const t=typeof process.getuid=="function"?process.getuid():"user";return M(O(),`crtr-tmux-keybindings-${t}.lock`)}u($e,"tmuxBindingLockPath");function De(e,n=[]){return oe($e(),()=>Ie(e,n))}u(De,"installTmuxBindings");function Ie(e,n=[]){const t=e===void 0?q():void 0,r=e??t.bindings,s=e===void 0?t.tmuxPassthrough:ie(n),o=[],c=[],l=
|
|
3
|
+
`).flatMap(r=>{const s=B(r);return s?.table===p?[s.key]:[]}));return e.filter(r=>!r.includes(" > ")&&v(r).some(s=>t.has(s)))}u(Le,"occupiedTmuxRootGestures");function R(e){return typeof e=="object"&&e!==null&&typeof e.table=="string"&&typeof e.key=="string"}u(R,"isInstalledPair");function ke(e){if(typeof e!="object"||e===null)return!1;const n=e;return typeof n.bindingId=="string"&&ee.has(n.bindingId)&&typeof n.gesture=="string"&&typeof n.key=="string"&&(typeof n.original=="string"||n.original===null)&&typeof n.wrapper=="string"&&(n.state==="owned"||n.state==="relinquished")}u(ke,"isWrappedRootBinding");function xe(){const e=f(["show-options","-s","-q",A]);if(!e.ok)return null;if(e.stdout==="")return{pairs:[],wrappers:[]};const n=f(["show-options","-s","-qv",A]);if(!n.ok)return null;try{const t=JSON.parse(n.stdout);if(Array.isArray(t))return t.every(R)?{pairs:t,wrappers:[]}:null;if(typeof t!="object"||t===null)return null;const r=t;return!Array.isArray(r.pairs)||!r.pairs.every(R)||!Array.isArray(r.wrappers)||!r.wrappers.every(ke)?null:{pairs:r.pairs,wrappers:r.wrappers}}catch{return null}}u(xe,"readManifest");function W(e){return f(["set-option","-s",A,JSON.stringify(e)])}u(W,"writeManifest");function C(e){return e.replace(/\\/g,"\\\\").replace(/;/g,"\\;")}u(C,"tmuxKeyArgument");function he(e){return`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/;/g,"\\;")}"`}u(he,"tmuxCommandToken");function ye(e){let n=null,t="";for(let r=0;r<e.length;r+=1){const s=e[r];if(n===null&&(s==="'"||s==='"')){n=s,t+=s;continue}if(n===s){n=null,t+=s;continue}if(s==="\\"&&r+1<e.length){const o=e[r+1];n===null&&o===";"?t+=";":t+=s+o,r+=1;continue}t+=s}return t}u(ye,"bindingCommandForBranch");function be(e){const n=Y(M(O(),"crtr-tmux-binding-")),t=M(n,"binding.conf");try{return V(t,`${e}
|
|
4
|
+
`,"utf8"),f(["source-file",t])}finally{Z(n,{recursive:!0,force:!0})}}u(be,"sourceBindingLine");function X(e){return e.original===null?f(["unbind-key","-T",p,C(e.key)]):be(e.original)}u(X,"restoreWrappedBinding");function we(){return["run-shell","-b",'crtr surface inbox --quiet --tmux-socket "#{socket_path}" --tmux-client "#{client_name}" --target-pane "#{pane_id}"']}u(we,"inboxToggleTmuxCommand");function ve(e){switch(e){case"crtr.tmux.node.next":return["run-shell","crtr surface node cycle --dir next --pane '#{pane_id}' >/dev/null 2>&1"];case"crtr.tmux.node.previous":return["run-shell","crtr surface node cycle --dir prev --pane '#{pane_id}' >/dev/null 2>&1"];case"crtr.tmux.inbox.toggle":return we();default:throw new Error(`no tmux command for ${e}`)}}u(ve,"actionCommand");function $e(){const e=process.env.TMUX?.split(",")[0]?.trim();if(e!==void 0&&e!=="")return`${e}.crtr-keybindings.lock`;const n=f(["display-message","-p","#{socket_path}"]);if(n.ok&&n.stdout!=="")return`${n.stdout}.crtr-keybindings.lock`;const t=typeof process.getuid=="function"?process.getuid():"user";return M(O(),`crtr-tmux-keybindings-${t}.lock`)}u($e,"tmuxBindingLockPath");function De(e,n=[]){return oe($e(),()=>Ie(e,n))}u(De,"installTmuxBindings");function Ie(e,n=[]){const t=e===void 0?q():void 0,r=e??t.bindings,s=e===void 0?t.tmuxPassthrough:ie(n),o=[],c=[],l=xe();if(l===null)return o.push({code:"tmux-error",message:`tmux is unavailable or ${A} is malformed`}),{ok:!1,installed:c,diagnostics:o};const h=new Map;for(const i of s){const a=_.find(d=>d.id===i);if(!(a===void 0||!re(a))){for(const d of r.gestures(i))if(!d.includes(" > "))for(const m of v(d))h.has(m)||h.set(m,{bindingId:i,gesture:d})}}const w=new Set,I=[];for(const i of l.wrappers){const a=h.get(i.key),d=$(p,i.key);if(d!==null&&d===i.original)continue;if(i.state==="relinquished"||d!==i.wrapper){w.add(i.key),a!==void 0&&I.push({...i,...a,state:"relinquished"});continue}const m=X(i);m.ok||(w.add(i.key),I.push(i),o.push({code:"tmux-error",bindingId:i.bindingId,gesture:i.gesture,message:`could not restore tmux binding ${p}:${i.key}: ${m.stderr}`}))}for(const i of l.pairs){if(i.table===p&&w.has(i.key))continue;const a=f(["unbind-key","-T",i.table,C(i.key)]);!a.ok&&$(i.table,i.key)!==null&&o.push({code:"tmux-error",message:`could not remove crouter binding ${i.table}:${i.key}: ${a.stderr}`})}if(o.some(i=>i.code==="tmux-error")){const i=W({pairs:l.pairs,wrappers:I});return i.ok||o.push({code:"tmux-error",message:`could not save crouter tmux ownership manifest: ${i.stderr}`}),{ok:!1,installed:c,diagnostics:o}}const E=u((i,a,d,m,k)=>{if($(i,a)!==null)return o.push({code:"occupied",bindingId:m,gesture:k,message:`${i}:${a} is already bound by tmux; ${m} was not installed`}),!1;const g=f(["bind-key","-T",i,C(a),...d]);return g.ok?(c.push({table:i,key:a}),!0):(o.push({code:"tmux-error",bindingId:m,gesture:k,message:`could not install ${m}: ${g.stderr}`}),!1)},"install"),P=F(r),H=N(" crtr ",K(r,P));for(const i of r.gestures("crtr.tmux.menu.open"))for(const a of v(i))E(p,a,H,"crtr.tmux.menu.open",i);for(const i of _){if(i.pair?.field!=="menu")continue;const a=_.find(y=>y.id===i.pair?.pairedId);if(a?.pair?.field!=="global")continue;const d=i.id,m=a.id,k=P.get(d),g=k===void 0?null:j(k.action);if(g===null)throw new Error(`no direct tmux action for paired menu binding ${d}`);for(const y of r.gestures(m))for(const J of v(y))E(p,J,g.argv,m,y)}for(const i of["crtr.tmux.node.next","crtr.tmux.node.previous","crtr.tmux.inbox.toggle"])for(const a of r.gestures(i))for(const d of v(a))E(p,d,ve(i),i,a);const L=[];for(const[i,a]of h){if(w.has(i))continue;const d=$(p,i);if(d===null)continue;const m=B(d);if(m===null||m.command===""){o.push({code:"tmux-error",bindingId:a.bindingId,gesture:a.gesture,message:`could not parse occupied tmux binding ${p}:${i}`});continue}const k=f(["bind-key",...m.repeat?["-r"]:[],"-T",p,C(i),"if-shell","-F","#{!=:#{@crtr_attach},}",`send-keys ${he(i)}`,ye(m.command)]);if(!k.ok){o.push({code:"tmux-error",bindingId:a.bindingId,gesture:a.gesture,message:`could not wrap ${p}:${i}: ${k.stderr}`});continue}const g=$(p,i);if(g===null||!g.includes("@crtr_attach")){o.push({code:"tmux-error",bindingId:a.bindingId,gesture:a.gesture,message:`could not fingerprint wrapped tmux binding ${p}:${i}`});continue}const y={...a,key:i,original:d,wrapper:g,state:"owned"};I.push(y),L.push(y)}const D=W({pairs:c,wrappers:I});if(!D.ok){o.push({code:"tmux-error",message:`could not save crouter tmux ownership manifest: ${D.stderr}`});for(const i of L)$(p,i.key)===i.wrapper&&X(i)}return{ok:o.every(i=>i.code!=="tmux-error"),installed:c,diagnostics:o}}u(Ie,"reconcileTmuxBindings");export{Pe as crouterMenuTmuxArgs,we as inboxToggleTmuxCommand,De as installTmuxBindings,Le as occupiedTmuxRootGestures};
|
|
@@ -18,6 +18,9 @@ export declare function primeBodies(db: CanvasDb, docs: readonly DeliveryDoc[]):
|
|
|
18
18
|
/** Documents with a rule on one of `on` whose owner is in the reader's view and that the reader may read, in view order. At `boot` a node's
|
|
19
19
|
* own documents come in even without a boot rule. */
|
|
20
20
|
export declare function loadCorpus(db: CanvasDb, reader: Reader, on: RuleOn[]): Promise<DeliveryDoc[]>;
|
|
21
|
+
/** Documents as delivery documents for `reader`, each with all its rules, in the order given (explicit reads and link targets). Every one
|
|
22
|
+
* must be a live document the reader may read. */
|
|
23
|
+
export declare function deliveryDocsOf(db: CanvasDb, reader: Reader, docs: readonly ObjectRow[]): Promise<DeliveryDoc[]>;
|
|
21
24
|
/** One document as a delivery document for `reader`, with all its rules (an explicit read). */
|
|
22
25
|
export declare function deliveryDocOf(db: CanvasDb, reader: Reader, doc: ObjectRow): Promise<DeliveryDoc>;
|
|
23
26
|
/** Every listed document of one owner the reader can read, for prefix listings. */
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
var S=Object.defineProperty;var
|
|
2
|
-
WHERE o.type = 'document' AND o.deleted_at IS NULL AND ${
|
|
3
|
-
ORDER BY number DESC LIMIT 1`).get(t.id,...o);if(!i)throw new Error(`document ${t.id} has no head revision ${t.heads_key}`);return i.body_hash}s(b,"headBodyHash");async function $(e,t,o){return{view:o,ev:await L(e,t)}}s($,"resolveContext");async function x(e,t,o,i,n,l,c){const{view:r}=o,w=r.findIndex(H=>H.id===n.owner),d=w>=0?r[w]:await e.prepare("SELECT * FROM objects WHERE id = ?").get(n.owner),p=N(d),u=c?.get(n.name),y=u===void 0?await I(e,t,n.name,o):u===null?{missing:!0}:{object:{id:u}},f=await b(e,n),{heads_key:E,unlisted:a,source_path:m,...M}=n,g={object:M,owner:d,ownerHandle:p,viewRank:w>=0?w:r.length,ownNode:t.class==="node"&&n.owner===t.node.id,shipped:m!==null,kind:n.kind==="preference"?"preference":"knowledge",name:n.name,displayName:"object"in y&&y.object.id===n.id?n.name:`${p}/${n.name}`,preview:n.preview,unlisted:a!==0,headsKey:E,bodyHash:f,body:s(async()=>v.get(g)??U(g,await A(e,f)),"body"),rules:l,limit:W(i,d,t)};return g}s(x,"toDeliveryDoc");const v=new WeakMap;function U(e,t){return v.set(e,t),t}s(U,"remember");async function X(e,t){const o=t.filter(n=>!v.has(n)),i=await C(e,o.map(n=>n.bodyHash));for(const n of o)v.set(n,i.get(n.bodyHash))}s(X,"primeBodies");async function Z(e,t,o){const i=await j(e,t),n=await $(e,t,i),l=await R(e,t),c=new Map;if(i.length===0)return[];const r=await k(e,n.ev,"read","o"),w={sql:`${r.sql} AND o.owner IN (${i.map(()=>"?").join(",")})`,params:[...r.params,...i.map(a=>a.id)]};for(const a of await B(e,o,w))c.set(a.object,[...c.get(a.object)??[],a]);const d=t.class==="node"&&o.includes("boot")?await h(e,n.ev,"o.owner = ?",[t.node.id]):[],p=[...new Set([...c.keys(),...d.map(a=>a.id)])],u=p.length===0?[]:await h(e,n.ev,`o.id IN (${p.map(()=>"?").join(",")})`,p),y=new Map(i.map((a,m)=>[a.id,m])),f=s(a=>y.get(a.owner)??i.length,"rankOf"),E=await D(e,n,u.map(a=>a.name));return await O(u.sort((a,m)=>f(a)-f(m)||a.seq-m.seq),async a=>await x(e,t,n,l,a,c.get(a.id)??[],E))}s(Z,"loadCorpus");async function ee(e,t,o){const i=await $(e,t,await j(e,t)),n=(await h(e,i.ev,"o.id = ?",[o.id]))[0];if(!n)throw new Error(`document ${o.id} has no documents row or is not readable`);return await x(e,t,i,await R(e,t),n,await _(e,n))}s(ee,"deliveryDocOf");async function te(e,t,o){const i=await $(e,t,await j(e,t)),n=await R(e,t),l=await h(e,i.ev,"o.owner = ? AND d.unlisted = 0",[o.id]),c=await D(e,i,l.map(r=>r.name));return await O(l,async r=>await x(e,t,i,n,r,await _(e,r),c))}s(te,"listingCorpus");async function ne(e,t){if(t.class!=="node")throw new Error(`nodeSubject needs a node reader, got ${t.class}`);const o=await F(t.node.id,[...t.repos,...t.projectRepos]);if(o===null)throw new Error(`no node ${t.node.id}`);return o}s(ne,"nodeSubject");export{ee as deliveryDocOf,W as deliveryLimitFor,te as listingCorpus,Z as loadCorpus,ne as nodeSubject,N as ownerHandle,X as primeBodies,T as typedLimitKey};
|
|
1
|
+
var S=Object.defineProperty;var r=(e,t)=>S(e,"name",{value:t,configurable:!0});import{permits as A,resolveReader as H}from"../../permissions/evaluator.js";import{get as L,getMany as q}from"../../graph/bodies.js";import{resolveName as B,viewOf as C,viewResolutions as F}from"../../graph/names.js";import{rulesOn as W,rulesOfMany as Y}from"../../graph/rules.js";import{loadExactProfileManifest as I}from"../../profiles/manifest.js";import{assembleNodeSubject as T}from"../subject.js";import{mapAsync as K}from"../../async-array.js";function b(e){return e.type==="node"?e.id:e.name}r(b,"ownerHandle");function U(e){return`${e.type}:${b(e)}`}r(U,"typedLimitKey");function J(e,t,n){if(n?.class==="node"&&n.profile!==null&&n.profile.id===t.id)return"content";const i=e?.delivery_limits;return i?i[U(t)]??i[b(t)]??"content":"content"}r(J,"deliveryLimitFor");async function P(e,t){if(t.class!=="node"||t.profile===null)return null;const n=await e.prepare("SELECT external_id FROM identities WHERE object = ? AND scheme = 'profile'").get(t.profile.id);if(!n)throw new Error(`profile object ${t.profile.id} has no profile identity`);return I(n.external_id).manifest}r(P,"readerManifest");async function N(e,t){const n=await C(e,t),i=await H(e,t);return{reader:t,context:{view:n,ev:i},read:await A(e,i,"read","o"),manifest:await P(e,t)}}r(N,"corpusScope");async function y(e,t,n,i){return await e.prepareUncached(`SELECT o.*, d.heads_key, d.unlisted, d.source_path FROM objects o JOIN documents d ON d.object = o.id
|
|
2
|
+
WHERE o.type = 'document' AND o.deleted_at IS NULL AND ${n} AND ${t.read.sql} ORDER BY o.seq`).all(...i,...t.read.params)}r(y,"documentRows");async function z(e,t){const n=[...new Set(t.flatMap(a=>a.heads_key.split(",")))],i=n.length===0?[]:await e.prepare("SELECT rev_id, document, number, body_hash FROM revisions WHERE rev_id = ANY(?::text[])").all(n),s=new Map(i.map(a=>[a.rev_id,a])),l=new Map;for(const a of t){let d;for(const p of a.heads_key.split(",")){const u=s.get(p);if(u===void 0||u.document!==a.id)continue;const f=Number(u.number);(d===void 0||f>d.number)&&(d={number:f,body_hash:u.body_hash})}if(d===void 0)throw new Error(`document ${a.id} has no head revision ${a.heads_key}`);l.set(a.id,d.body_hash)}return l}r(z,"headBodyHashes");async function x(e,t,n,i){if(n.length===0)return[];const{reader:s,context:l,manifest:a}=t,{view:d}=l,p=new Map(d.map((o,w)=>[o.id,w])),u=[...new Set(n.map(o=>o.owner).filter(o=>!p.has(o)))],f=new Map(d.map(o=>[o.id,o]));if(u.length>0)for(const o of await e.prepare("SELECT * FROM objects WHERE id = ANY(?::text[])").all(u))f.set(o.id,o);const h=i??await Y(e,n.map(o=>o.id)),c=await z(e,n),m=await F(e,l,n.map(o=>o.name));return await K(n,async o=>{const w=f.get(o.owner);if(w===void 0)throw new Error(`document ${o.id} has no owner row ${o.owner}`);const R=p.get(w.id)??d.length,_=b(w),v=m.get(o.name),j=v===void 0?await B(e,s,o.name,l):v===null?{missing:!0}:{object:{id:v}},M=c.get(o.id),{heads_key:$,unlisted:k,source_path:O,...D}=o,E={object:D,owner:w,ownerHandle:_,viewRank:R,ownNode:s.class==="node"&&o.owner===s.node.id,shipped:O!==null,kind:o.kind==="preference"?"preference":"knowledge",name:o.name,displayName:"object"in j&&j.object.id===o.id?o.name:`${_}/${o.name}`,preview:o.preview,unlisted:k!==0,headsKey:$,bodyHash:M,body:r(async()=>g.get(E)??G(E,await L(e,M)),"body"),rules:h.get(o.id)??[],limit:J(a,w,s)};return E})}r(x,"toDeliveryDocs");const g=new WeakMap;function G(e,t){return g.set(e,t),t}r(G,"remember");async function se(e,t){const n=t.filter(s=>!g.has(s)),i=await q(e,n.map(s=>s.bodyHash));for(const s of n)g.set(s,i.get(s.bodyHash))}r(se,"primeBodies");async function ae(e,t,n){const i=await N(e,t),{view:s}=i.context,l=new Map;if(s.length===0)return[];const a={sql:`${i.read.sql} AND o.owner IN (${s.map(()=>"?").join(",")})`,params:[...i.read.params,...s.map(c=>c.id)]};for(const c of await W(e,n,a))l.set(c.object,[...l.get(c.object)??[],c]);const d=t.class==="node"&&n.includes("boot")?await y(e,i,"o.owner = ?",[t.node.id]):[],p=[...new Set([...l.keys(),...d.map(c=>c.id)])],u=p.length===0?[]:await y(e,i,"o.id = ANY(?::text[])",[p]),f=new Map(s.map((c,m)=>[c.id,m])),h=r(c=>f.get(c.owner)??s.length,"rankOf");return await x(e,i,u.sort((c,m)=>h(c)-h(m)||c.seq-m.seq),l)}r(ae,"loadCorpus");async function Q(e,t,n){if(n.length===0)return[];const i=await N(e,t),s=n.map(a=>a.id),l=new Map((await y(e,i,"o.id = ANY(?::text[])",[s])).map(a=>[a.id,a]));return await x(e,i,s.map(a=>{const d=l.get(a);if(!d)throw new Error(`document ${a} has no documents row or is not readable`);return d}))}r(Q,"deliveryDocsOf");async function re(e,t,n){return(await Q(e,t,[n]))[0]}r(re,"deliveryDocOf");async function ce(e,t,n){const i=await N(e,t);return await x(e,i,await y(e,i,"o.owner = ? AND d.unlisted = 0",[n.id]))}r(ce,"listingCorpus");async function de(e,t){if(t.class!=="node")throw new Error(`nodeSubject needs a node reader, got ${t.class}`);const n=await T(t.node.id,[...t.repos,...t.projectRepos]);if(n===null)throw new Error(`no node ${t.node.id}`);return n}r(de,"nodeSubject");export{re as deliveryDocOf,Q as deliveryDocsOf,J as deliveryLimitFor,ce as listingCorpus,ae as loadCorpus,de as nodeSubject,b as ownerHandle,se as primeBodies,U as typedLimitKey};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
1
|
+
var A=Object.defineProperty;var d=(e,n)=>A(e,"name",{value:n,configurable:!0});import{permits as D,resolveReader as H}from"../../permissions/evaluator.js";import{heldAtOrAbove as v,hold as b,holdListing as K,listedAtOrAbove as E}from"../../graph/exposures.js";import{deliveryDocsOf as O,listingCorpus as R,loadCorpus as g,primeBodies as L}from"./corpus.js";import{listingBlock as C,ownSetBlock as B,listingKey as P,listingLabel as x,listingPrefixes as k,renderListing as M}from"./listings.js";import{planDelivery as S}from"./plan.js";function w(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}d(w,"attr");async function W(e,n){let t=`kind="${w(e.kind)}" name="${w(e.displayName)}"`;if(n==="content"){const i=(await e.body()).trim();if(i!=="")return`<memory ${t}>
|
|
2
2
|
${i}
|
|
3
|
-
</memory>`}else n==="preview"&&e.preview.trim()!==""&&(t+=` readWhen="${w(e.preview.trim())}"`);return`<memory ${t} />`}
|
|
3
|
+
</memory>`}else n==="preview"&&e.preview.trim()!==""&&(t+=` readWhen="${w(e.preview.trim())}"`);return`<memory ${t} />`}d(W,"renderEnvelope");function j(e){return e.length===0?"":`<auto-loaded-context>
|
|
4
4
|
${e.join(`
|
|
5
5
|
`)}
|
|
6
|
-
</auto-loaded-context>`}
|
|
6
|
+
</auto-loaded-context>`}d(j,"wrapAutoLoaded");async function q(e,n){let t=e.members.get(n.owner.id);return t===void 0&&(t=await R(e.ctx.db,e.ctx.reader,n.owner),e.members.set(n.owner.id,t)),t}d(q,"membersOf");async function I(e,n,t){const i=await D(e,await H(e,n),"read","o"),o=await e.prepareUncached(`SELECT o.* FROM edges e JOIN objects o ON o.id = e.dst
|
|
7
7
|
WHERE e.type = 'links-to' AND e.src = ? AND o.type = 'document' AND o.deleted_at IS NULL AND o.id <> ? AND ${i.sql}
|
|
8
|
-
ORDER BY e.written_as`).all(t.object.id,t.object.id,...i.params);return await
|
|
8
|
+
ORDER BY e.written_as`).all(t.object.id,t.object.id,...i.params);return await O(e,n,o)}d(I,"linkedDocs");function U(e,n){return n.owner.id===e.owner.id&&n.name.startsWith(`${e.name}/`)&&!n.name.slice(e.name.length+1).includes("/")}d(U,"underOwnPrefix");async function _(e,n){const{ledger:t,channel:i}=e.ctx,o=[],c=[];for(const r of await I(e.ctx.db,e.ctx.reader,n)){if(U(n,r)&&!r.unlisted)continue;const p={object:r.object.id,headsKey:r.headsKey,contentHash:r.bodyHash};if(v(t,p,"preview"))continue;b(t,i,p,"preview"),e.delivered.push({doc:r,level:"preview",cause:"link preview attached to content delivery"}),c.push(r);const a=r.preview.trim();o.push(a===""?`[[${r.displayName}]]`:`[[${r.displayName}]]: ${a}`)}return{lines:o,linked:c}}d(_,"linkPreviews");async function $(e,n,t){const{ledger:i,channel:o}=e.ctx,c=await q(e,n),r=[];let p,a=[];for(const m of k(c,n.name)){const f=m===n.name,s=P(n,m);if(!(f&&t)&&E(i,s,"preview"))continue;const{lines:l,previewed:u}=M(c,m,i,o,!(f&&t));for(const y of u)e.delivered.push({doc:y,level:"preview",cause:"directory listing attached to content delivery"});l.length!==0&&(K(i,o,s,"preview"),f?a=l:r.push(C(x(n,m),l)))}const h=await _(e,n);return t?a.length>0&&(p=a):a.length+h.lines.length>0&&r.unshift(B(x(n,n.name),a,h.lines)),e.chainCorpus??=await g(e.ctx.db,e.ctx.reader,["document-read"]),r.push(...await N(e,e.chainCorpus,"document-read",{doc:n},"memory-read companion of content delivery")),{blocks:r,...p===void 0?{}:{listing:p},linked:h.linked}}d($,"attachments");async function N(e,n,t,i,o){const{db:c,reader:r,subject:p,ledger:a,channel:h}=e.ctx,m=await S(c,p,r,n,t,i),f=[];await L(c,m.docs.filter(s=>s.winner&&s.finalRung==="content"&&!v(a,{object:s.doc.object.id,headsKey:s.doc.headsKey,contentHash:s.doc.bodyHash},"content")).map(s=>s.doc));for(const s of m.docs){const l=s.finalRung;if(!s.winner||l==="none")continue;const{doc:u}=s,y={object:u.object.id,headsKey:u.headsKey,contentHash:u.bodyHash};v(a,y,l)||(b(a,h,y,l),e.delivered.push({doc:u,level:l,...o===void 0?{}:{cause:o}}),l==="content"&&f.push(...(await $(e,u,!1)).blocks),f.push(await W(u,l)))}return f}d(N,"renderPlan");async function Q(e,n,t,i){i??=await g(e.db,e.reader,[n]);const o={ctx:e,delivered:[],members:new Map};return{content:j(await N(o,i,n,t)),delivered:o.delivered}}d(Q,"renderEvent");async function V(e,n,t=!1){const i={ctx:e,delivered:[],members:new Map};b(e.ledger,e.channel,{object:n.object.id,headsKey:n.headsKey,contentHash:n.bodyHash},"content");const{blocks:o,listing:c,linked:r}=await $(i,n,!t);return{attachments:j(o),...c===void 0?{}:{listing:c},linked:r,delivered:i.delivered}}d(V,"renderExplicitRead");export{I as linkedDocs,W as renderEnvelope,Q as renderEvent,V as renderExplicitRead,j as wrapAutoLoaded};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ScopeConfig } from '../types.js';
|
|
1
|
+
import type { Verbosity, ScopeConfig } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Which settings destination owns a preference row. Every settings-surface row
|
|
4
4
|
* must name one, so a new preference cannot be added without deciding where a
|
|
@@ -14,10 +14,17 @@ export interface UserSettingDefinition<Key extends string = string> {
|
|
|
14
14
|
group: UserSettingGroup;
|
|
15
15
|
order: number;
|
|
16
16
|
format: (config: ScopeConfig) => string;
|
|
17
|
+
/** How the settings panel draws the value, when it differs from `format`. */
|
|
18
|
+
display?: (config: ScopeConfig) => string;
|
|
17
19
|
cycle: (config: ScopeConfig, delta: number) => void;
|
|
18
20
|
/** Mutate `config` from a CLI string, returning a user-facing validation error on failure. */
|
|
19
21
|
setFromString: (config: ScopeConfig, raw: string) => string | null;
|
|
20
22
|
}
|
|
23
|
+
/** Display names for each verbosity level, least detail first. */
|
|
24
|
+
export declare const VERBOSITY_LABELS: Record<Verbosity, string>;
|
|
25
|
+
/** The verbosity level drawn as a track: one stop per level, the current one
|
|
26
|
+
* filled, then its name — e.g. `less ━━━━●────○────○ more Tool calls`. */
|
|
27
|
+
export declare function verbositySpectrum(level: Verbosity): string;
|
|
21
28
|
/**
|
|
22
29
|
* Exhaustive settings-surface coverage for ScopeConfig. Primitive preferences
|
|
23
30
|
* are required by the type to define a Settings row; structured registries must
|
|
@@ -245,33 +252,19 @@ export declare const CONFIG_SETTINGS_COVERAGE: {
|
|
|
245
252
|
setFromString: (config: ScopeConfig, raw: string) => string | null;
|
|
246
253
|
};
|
|
247
254
|
};
|
|
248
|
-
|
|
255
|
+
verbosity: {
|
|
249
256
|
surface: "settings";
|
|
250
257
|
setting: {
|
|
251
|
-
key: "
|
|
258
|
+
key: "verbosity";
|
|
252
259
|
label: string;
|
|
253
260
|
description: string;
|
|
254
261
|
valueConstraint: string;
|
|
255
262
|
applies: string;
|
|
256
263
|
group: "display";
|
|
257
264
|
order: number;
|
|
258
|
-
format: (config: ScopeConfig) => "
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
};
|
|
262
|
-
};
|
|
263
|
-
summarize_tool_calls: {
|
|
264
|
-
surface: "settings";
|
|
265
|
-
setting: {
|
|
266
|
-
key: "summarize_tool_calls";
|
|
267
|
-
label: string;
|
|
268
|
-
description: string;
|
|
269
|
-
valueConstraint: string;
|
|
270
|
-
applies: string;
|
|
271
|
-
group: "display";
|
|
272
|
-
order: number;
|
|
273
|
-
format: (config: ScopeConfig) => "on" | "off";
|
|
274
|
-
cycle: (config: ScopeConfig) => void;
|
|
265
|
+
format: (config: ScopeConfig) => "replies" | "summaries" | "tools" | "previews" | "full";
|
|
266
|
+
display: (config: ScopeConfig) => string;
|
|
267
|
+
cycle: (config: ScopeConfig, delta: number) => void;
|
|
275
268
|
setFromString: (config: ScopeConfig, raw: string) => string | null;
|
|
276
269
|
};
|
|
277
270
|
};
|
|
@@ -305,21 +298,6 @@ export declare const CONFIG_SETTINGS_COVERAGE: {
|
|
|
305
298
|
setFromString: (config: ScopeConfig, raw: string) => string | null;
|
|
306
299
|
};
|
|
307
300
|
};
|
|
308
|
-
consolidate_replies: {
|
|
309
|
-
surface: "settings";
|
|
310
|
-
setting: {
|
|
311
|
-
key: "consolidate_replies";
|
|
312
|
-
label: string;
|
|
313
|
-
description: string;
|
|
314
|
-
valueConstraint: string;
|
|
315
|
-
applies: string;
|
|
316
|
-
group: "display";
|
|
317
|
-
order: number;
|
|
318
|
-
format: (config: ScopeConfig) => "on" | "off";
|
|
319
|
-
cycle: (config: ScopeConfig) => void;
|
|
320
|
-
setFromString: (config: ScopeConfig, raw: string) => string | null;
|
|
321
|
-
};
|
|
322
|
-
};
|
|
323
301
|
keybindings: {
|
|
324
302
|
surface: "specialized";
|
|
325
303
|
owner: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var v=Object.defineProperty;var n=(e,t)=>v(e,"name",{value:t,configurable:!0});import{CONDENSED_HISTORY_MODES as u,MOUSE_MODE_DEFAULTS as p,WHIP_MESSAGE_MODES as d}from"../types.js";function i(e,t,o){const s=e.indexOf(t),a=s>=0?s:0;return e[(a+o+e.length)%e.length]}n(i,"cycleChoice");function c(e,t,o){const s=e.indexOf(t);return s>=0?e[(s+o+e.length)%e.length]:o>=0?e.find(a=>a>t)??e[0]:[...e].reverse().find(a=>a<t)??e[e.length-1]}n(c,"cycleNumber");function r(e,t){return e==="true"?!0:e==="false"?!1:`${t} must be true or false`}n(r,"booleanFromString");function f(e,t){if(!/^\d+$/.test(e))return`${t} must be an integer >= 0`;const o=Number(e);return Number.isSafeInteger(o)?o:`${t} must be an integer >= 0`}n(f,"nonNegativeIntegerFromString");function _(e,t){const o=f(e,t);return typeof o=="string"||o<1?`${t} must be an integer >= 1`:o}n(_,"positiveIntegerFromString");const m=[!1,"notify","apply"],w=[0,1,6,12,24,48,72,168],b=[1,2,3,4,5,6,8,10,12],l="openai-codex";function g(e,t){const o=e.providerOptions[t];if(o!==void 0)return o;const s={};return e.providerOptions[t]=s,s}n(g,"providerOptionsFor");const x=[1,2,3,4,5,6],h={schema_version:{surface:"specialized",owner:"internal schema migration"},marketplaces:{surface:"specialized",owner:"Plugins and pkg market commands"},plugins:{surface:"specialized",owner:"Plugins tab and pkg plugin commands"},auto_update:{surface:"settings",settings:{crtr:{key:"auto_update.crtr",label:"crouter updates",description:"Notify about crouter releases, install them automatically, or turn checks off.",valueConstraint:"true|false|notify|apply; true stores notify",applies:"Applies on the next crouter command.",group:"updates",order:70,format:n(e=>e.auto_update.crtr===!1?"off":e.auto_update.crtr,"format"),cycle:n((e,t)=>{e.auto_update.crtr=i(m,e.auto_update.crtr,t)},"cycle"),setFromString:n((e,t)=>{const o=t==="true"?"notify":t;return o!=="notify"&&o!=="apply"&&o!=="false"?"auto_update.crtr must be notify, apply, or false":(e.auto_update.crtr=o==="false"?!1:o,null)},"setFromString")},content:{key:"auto_update.content",label:"Content updates",description:"Notify about plugin and marketplace updates, apply them automatically, or turn checks off.",valueConstraint:"false|notify|apply",applies:"Applies on the next crouter command.",group:"updates",order:80,format:n(e=>e.auto_update.content===!1?"off":e.auto_update.content,"format"),cycle:n((e,t)=>{e.auto_update.content=i(m,e.auto_update.content,t)},"cycle"),setFromString:n((e,t)=>t!=="notify"&&t!=="apply"&&t!=="false"?"auto_update.content must be notify, apply, or false":(e.auto_update.content=t==="false"?!1:t,null),"setFromString")},interval_hours:{key:"auto_update.interval_hours",label:"Update interval",description:"Minimum hours between automatic update checks. Zero checks on every command.",valueConstraint:"integer >= 0",applies:"Applies on the next crouter command.",group:"updates",order:90,format:n(e=>`${e.auto_update.interval_hours}h`,"format"),cycle:n((e,t)=>{e.auto_update.interval_hours=c(w,e.auto_update.interval_hours,t)},"cycle"),setFromString:n((e,t)=>{const o=f(t,"auto_update.interval_hours");return typeof o=="string"?o:(e.auto_update.interval_hours=o,null)},"setFromString")}}},max_panes_per_window:{surface:"settings",setting:{key:"max_panes_per_window",label:"Maximum panes",description:"Maximum human-review panes placed in one tmux window before using another window.",valueConstraint:"integer >= 1",applies:"Applies to the next pane placement.",group:"panes",order:20,format:n(e=>String(e.max_panes_per_window),"format"),cycle:n((e,t)=>{e.max_panes_per_window=c(b,e.max_panes_per_window,t)},"cycle"),setFromString:n((e,t)=>{const o=_(t,"max_panes_per_window");return typeof o=="string"?o:(e.max_panes_per_window=o,null)},"setFromString")}},auto_open_child_viewers:{surface:"settings",setting:{key:"auto_open_child_viewers",label:"Open child panes",description:"Open each managed child beside its watched parent. Off keeps new children running in the background.",valueConstraint:"true|false",applies:"Applies to the next managed child created; independent roots still open their attended viewer.",group:"panes",order:10,format:n(e=>e.auto_open_child_viewers?"on":"off","format"),cycle:n(e=>{e.auto_open_child_viewers=!e.auto_open_child_viewers},"cycle"),setFromString:n((e,t)=>{const o=r(t,"auto_open_child_viewers");return typeof o=="string"?o:(e.auto_open_child_viewers=o,null)},"setFromString")}},brokerThresholds:{surface:"specialized",owner:"Broker limits tab"},lifecycle:{surface:"specialized",owner:"sys config set lifecycle.unattendedParkMs"},completion_bell:{surface:"settings",setting:{key:"completion_bell",label:"Completion bell",description:"Ring a short sound when the node in an attached viewer finishes a turn.",valueConstraint:"true|false",applies:"Applies on the next turn end.",group:"display",order:41,format:n(e=>e.completion_bell?"on":"off","format"),cycle:n(e=>{e.completion_bell=!e.completion_bell},"cycle"),setFromString:n((e,t)=>{const o=r(t,"completion_bell");return typeof o=="string"?o:(e.completion_bell=o,null)},"setFromString")}},working_gerunds:{surface:"specialized",owner:"sys config set working_gerunds"},whip_mode:{surface:"settings",setting:{key:"whip_mode",label:"Whip mode",description:"Play the whip animation when you send a prompt and when a viewer opens for an agent with an initial prompt.",valueConstraint:"true|false",applies:"Applies on the next attach.",group:"display",order:39,format:n(e=>e.whip_mode?"on":"off","format"),cycle:n(e=>{e.whip_mode=!e.whip_mode},"cycle"),setFromString:n((e,t)=>{const o=r(t,"whip_mode");return typeof o=="string"?o:(e.whip_mode=o,null)},"setFromString")}},page_surface:{surface:"settings",setting:{key:"page_surface",label:"Page human surface",description:"This host reads pages in a browser rather than a terminal. Agents are told the page module runs as written, HTML pages are offered, and document review and live display leave the command tree.",valueConstraint:"true|false",applies:"Applies when human command help is assembled.",group:"display",order:37,format:n(e=>e.page_surface?"on":"off","format"),cycle:n(e=>{e.page_surface=!e.page_surface},"cycle"),setFromString:n((e,t)=>{const o=r(t,"page_surface");return typeof o=="string"?o:(e.page_surface=o,null)},"setFromString")}},whip_messages:{surface:"specialized",owner:"sys config set whip_messages"},whip_message_mode:{surface:"settings",setting:{key:"whip_message_mode",label:"Whip message",description:"What the whip action sends: a random line from whip_messages, or the fixed \u201CGo faster\u201D.",valueConstraint:d.join("|"),applies:"Applies on the next attach.",group:"display",order:40,format:n(e=>e.whip_message_mode==="go-faster"?"go faster":"random","format"),cycle:n((e,t)=>{e.whip_message_mode=i(d,e.whip_message_mode,t)},"cycle"),setFromString:n((e,t)=>d.includes(t)?(e.whip_message_mode=t,null):`whip_message_mode must be one of: ${d.join("|")}`,"setFromString")}},mouse_mode_default:{surface:"settings",setting:{key:"mouse_mode_default",label:"Default mouse mode",description:"Initial mouse wheel scrolling for each attached viewer.",valueConstraint:p.join("|"),applies:"Applies on the next attach.",group:"display",order:38,format:n(e=>e.mouse_mode_default==="tmux"?"follow tmux":e.mouse_mode_default,"format"),cycle:n((e,t)=>{e.mouse_mode_default=i(p,e.mouse_mode_default,t)},"cycle"),setFromString:n((e,t)=>p.includes(t)?(e.mouse_mode_default=t,null):`mouse_mode_default must be one of: ${p.join("|")}`,"setFromString")}},live_cycles:{surface:"settings",setting:{key:"live_cycles",label:"Live cycles",description:"Trailing refresh cycles rendered at full fidelity; older cycles condense to text.",valueConstraint:"integer >= 1",applies:"Applies on the next attach.",group:"display",order:50,format:n(e=>String(e.live_cycles),"format"),cycle:n((e,t)=>{e.live_cycles=c(x,e.live_cycles,t)},"cycle"),setFromString:n((e,t)=>{const o=_(t,"live_cycles");return typeof o=="string"?o:(e.live_cycles=o,null)},"setFromString")}},condensed_history:{surface:"settings",setting:{key:"condensed_history",label:"Condensed history",description:"Messages retained from condensed cycles. Tool calls are never kept.",valueConstraint:u.join("|"),applies:"Applies on the next attach.",group:"display",order:60,format:n(e=>e.condensed_history,"format"),cycle:n((e,t)=>{e.condensed_history=i(u,e.condensed_history,t)},"cycle"),setFromString:n((e,t)=>u.includes(t)?(e.condensed_history=t,null):`condensed_history must be one of: ${u.join("|")}`,"setFromString")}},bash_tool_purpose:{surface:"settings",setting:{key:"bash_tool_purpose",label:"Bash purpose field",description:"Expose the optional purpose label to agents in the bash tool schema. Off removes the field without disabling the bash valve.",valueConstraint:"true|false",applies:"Applies on the next node session.",group:"display",order:25,format:n(e=>e.bash_tool_purpose?"on":"off","format"),cycle:n(e=>{e.bash_tool_purpose=!e.bash_tool_purpose},"cycle"),setFromString:n((e,t)=>{const o=r(t,"bash_tool_purpose");return typeof o=="string"?o:(e.bash_tool_purpose=o,null)},"setFromString")}},fold_finished_tools:{surface:"settings",setting:{key:"fold_finished_tools",label:"Fold finished tools",description:"Fold every settled tool call to its call line. Toggle live with /fold-tools.",valueConstraint:"true|false",applies:"Applies on the next attach.",group:"display",order:30,format:n(e=>e.fold_finished_tools?"on":"off","format"),cycle:n(e=>{e.fold_finished_tools=!e.fold_finished_tools},"cycle"),setFromString:n((e,t)=>{const o=r(t,"fold_finished_tools");return typeof o=="string"?o:(e.fold_finished_tools=o,null)},"setFromString")}},summarize_tool_calls:{surface:"settings",setting:{key:"summarize_tool_calls",label:"Summarize tool calls",description:"Replace completed folded tool-call groups with a one-line broker summary when available.",valueConstraint:"true|false",applies:"Applies when the next visible message closes a tool-call group.",group:"display",order:35,format:n(e=>e.summarize_tool_calls?"on":"off","format"),cycle:n(e=>{e.summarize_tool_calls=!e.summarize_tool_calls},"cycle"),setFromString:n((e,t)=>{const o=r(t,"summarize_tool_calls");return typeof o=="string"?o:(e.summarize_tool_calls=o,null)},"setFromString")}},document_port:{surface:"settings",setting:{key:"document_port",label:"Document browser port",description:"Fixed localhost port where crtrd serves editable document pages.",valueConstraint:"1-65535",applies:"Applies after daemon handover and on the next attach.",group:"display",order:37.5,format:n(e=>String(e.document_port),"format"),cycle:n((e,t)=>{e.document_port=Math.max(1,Math.min(65535,e.document_port+t))},"cycle"),setFromString:n((e,t)=>{const o=Number(t);return!/^\d+$/.test(t)||!Number.isInteger(o)||o<1||o>65535?"document_port must be an integer from 1 to 65535":(e.document_port=o,null)},"setFromString")}},detailed_tool_recaps:{surface:"settings",setting:{key:"detailed_tool_recaps",label:"Detailed tool recaps",description:"Show each document read and edited file in folded tool recaps. Off shows a compact count line instead.",valueConstraint:"true|false",applies:"Applies on the next attach.",group:"display",order:36,format:n(e=>e.detailed_tool_recaps?"on":"off","format"),cycle:n(e=>{e.detailed_tool_recaps=!e.detailed_tool_recaps},"cycle"),setFromString:n((e,t)=>{const o=r(t,"detailed_tool_recaps");return typeof o=="string"?o:(e.detailed_tool_recaps=o,null)},"setFromString")}},consolidate_replies:{surface:"settings",setting:{key:"consolidate_replies",label:"Consolidate replies",description:"Experiment: show one rewritten agent reply per message you type, with the working folded behind it (/show-working).",valueConstraint:"true|false",applies:"Applies on the next attach; the broker reads it per turn.",group:"display",order:36.5,format:n(e=>e.consolidate_replies?"on":"off","format"),cycle:n(e=>{e.consolidate_replies=!e.consolidate_replies},"cycle"),setFromString:n((e,t)=>{const o=r(t,"consolidate_replies");return typeof o=="string"?o:(e.consolidate_replies=o,null)},"setFromString")}},keybindings:{surface:"specialized",owner:"Keybindings tab"},tmux_passthrough:{surface:"specialized",owner:"Keybindings tab"},providerOptions:{surface:"settings",settings:{"openai-codex.fastMode":{key:`providerOptions.${l}.fastMode`,label:"Codex fast mode",description:"Serve Codex turns at the ChatGPT priority tier: about 1.5x faster generation for about 2x the credits. Displayed cost does not reflect the premium.",valueConstraint:"true|false",applies:"Applies on each node's next turn.",group:"providers",order:40,format:n(e=>e.providerOptions[l]?.fastMode?"on":"off","format"),cycle:n(e=>{const t=g(e,l);t.fastMode=!t.fastMode},"cycle"),setFromString:n((e,t)=>{const o=r(t,`providerOptions.${l}.fastMode`);return typeof o=="string"?o:(g(e,l).fastMode=o,null)},"setFromString")}}},modelLadders:{surface:"specialized",owner:"Models tab"},modelRoutes:{surface:"specialized",owner:"Models route declarations"},modelRouting:{surface:"specialized",owner:"Models route declarations"},kinds:{surface:"specialized",owner:"Models tab and kind registry"},page_components:{surface:"specialized",owner:"Page component catalog: product-registered page component kinds"},remoteCanvas:{surface:"specialized",owner:"canvas config commands"},api:{surface:"specialized",owner:"sys connect"},paths:{surface:"specialized",owner:"runtime layout"},store:{surface:"specialized",owner:"daemon conversation store"},runtime:{surface:"specialized",owner:"app-facing listener"},spawnEnv:{surface:"specialized",owner:"spawn environment allow-list"},bin:{surface:"specialized",owner:"bare-binary contributions on every node PATH"},humanActions:{surface:"specialized",owner:"scope-configured human completion actions"}},O=Object.keys(h);function S(){const e=[];for(const t of Object.values(h))t.surface==="settings"&&("setting"in t?e.push(t.setting):e.push(...Object.values(t.settings)));return e.sort((t,o)=>t.order-o.order)}n(S,"collectUserSettings");const y=S();function A(e){return y.find(t=>t.key===e)}n(A,"findUserSetting");function z(e){return y.filter(t=>t.group===e)}n(z,"userSettingsInGroup");export{h as CONFIG_SETTINGS_COVERAGE,O as SCOPE_CONFIG_KEYS,y as USER_SETTINGS,A as findUserSetting,z as userSettingsInGroup};
|
|
1
|
+
var b=Object.defineProperty;var n=(e,t)=>b(e,"name",{value:t,configurable:!0});import{CONDENSED_HISTORY_MODES as p,MOUSE_MODE_DEFAULTS as d,VERBOSITY_LEVELS as a,WHIP_MESSAGE_MODES as c}from"../types.js";const w={replies:"Replies only",summaries:"Messages + summaries",tools:"Tool calls",previews:"Previews",full:"Full"};function x(e){const t=a.indexOf(e);return`less ${a.map((o,s)=>s===t?"\u25CF":"\u25CB").map((o,s)=>s===0?o:`${s<=t?"\u2501\u2501\u2501\u2501":"\u2500\u2500\u2500\u2500"}${o}`).join("")} more ${w[e]}`}n(x,"verbositySpectrum");function l(e,t,r){const o=e.indexOf(t),s=o>=0?o:0;return e[(s+r+e.length)%e.length]}n(l,"cycleChoice");function f(e,t,r){const o=e.indexOf(t);return o>=0?e[(o+r+e.length)%e.length]:r>=0?e.find(s=>s>t)??e[0]:[...e].reverse().find(s=>s<t)??e[e.length-1]}n(f,"cycleNumber");function i(e,t){return e==="true"?!0:e==="false"?!1:`${t} must be true or false`}n(i,"booleanFromString");function m(e,t){if(!/^\d+$/.test(e))return`${t} must be an integer >= 0`;const r=Number(e);return Number.isSafeInteger(r)?r:`${t} must be an integer >= 0`}n(m,"nonNegativeIntegerFromString");function _(e,t){const r=m(e,t);return typeof r=="string"||r<1?`${t} must be an integer >= 1`:r}n(_,"positiveIntegerFromString");const g=[!1,"notify","apply"],S=[0,1,6,12,24,48,72,168],k=[1,2,3,4,5,6,8,10,12],u="openai-codex";function h(e,t){const r=e.providerOptions[t];if(r!==void 0)return r;const o={};return e.providerOptions[t]=o,o}n(h,"providerOptionsFor");const O=[1,2,3,4,5,6],y={schema_version:{surface:"specialized",owner:"internal schema migration"},marketplaces:{surface:"specialized",owner:"Plugins and pkg market commands"},plugins:{surface:"specialized",owner:"Plugins tab and pkg plugin commands"},auto_update:{surface:"settings",settings:{crtr:{key:"auto_update.crtr",label:"crouter updates",description:"Notify about crouter releases, install them automatically, or turn checks off.",valueConstraint:"true|false|notify|apply; true stores notify",applies:"Applies on the next crouter command.",group:"updates",order:70,format:n(e=>e.auto_update.crtr===!1?"off":e.auto_update.crtr,"format"),cycle:n((e,t)=>{e.auto_update.crtr=l(g,e.auto_update.crtr,t)},"cycle"),setFromString:n((e,t)=>{const r=t==="true"?"notify":t;return r!=="notify"&&r!=="apply"&&r!=="false"?"auto_update.crtr must be notify, apply, or false":(e.auto_update.crtr=r==="false"?!1:r,null)},"setFromString")},content:{key:"auto_update.content",label:"Content updates",description:"Notify about plugin and marketplace updates, apply them automatically, or turn checks off.",valueConstraint:"false|notify|apply",applies:"Applies on the next crouter command.",group:"updates",order:80,format:n(e=>e.auto_update.content===!1?"off":e.auto_update.content,"format"),cycle:n((e,t)=>{e.auto_update.content=l(g,e.auto_update.content,t)},"cycle"),setFromString:n((e,t)=>t!=="notify"&&t!=="apply"&&t!=="false"?"auto_update.content must be notify, apply, or false":(e.auto_update.content=t==="false"?!1:t,null),"setFromString")},interval_hours:{key:"auto_update.interval_hours",label:"Update interval",description:"Minimum hours between automatic update checks. Zero checks on every command.",valueConstraint:"integer >= 0",applies:"Applies on the next crouter command.",group:"updates",order:90,format:n(e=>`${e.auto_update.interval_hours}h`,"format"),cycle:n((e,t)=>{e.auto_update.interval_hours=f(S,e.auto_update.interval_hours,t)},"cycle"),setFromString:n((e,t)=>{const r=m(t,"auto_update.interval_hours");return typeof r=="string"?r:(e.auto_update.interval_hours=r,null)},"setFromString")}}},max_panes_per_window:{surface:"settings",setting:{key:"max_panes_per_window",label:"Maximum panes",description:"Maximum human-review panes placed in one tmux window before using another window.",valueConstraint:"integer >= 1",applies:"Applies to the next pane placement.",group:"panes",order:20,format:n(e=>String(e.max_panes_per_window),"format"),cycle:n((e,t)=>{e.max_panes_per_window=f(k,e.max_panes_per_window,t)},"cycle"),setFromString:n((e,t)=>{const r=_(t,"max_panes_per_window");return typeof r=="string"?r:(e.max_panes_per_window=r,null)},"setFromString")}},auto_open_child_viewers:{surface:"settings",setting:{key:"auto_open_child_viewers",label:"Open child panes",description:"Open each managed child beside its watched parent. Off keeps new children running in the background.",valueConstraint:"true|false",applies:"Applies to the next managed child created; independent roots still open their attended viewer.",group:"panes",order:10,format:n(e=>e.auto_open_child_viewers?"on":"off","format"),cycle:n(e=>{e.auto_open_child_viewers=!e.auto_open_child_viewers},"cycle"),setFromString:n((e,t)=>{const r=i(t,"auto_open_child_viewers");return typeof r=="string"?r:(e.auto_open_child_viewers=r,null)},"setFromString")}},brokerThresholds:{surface:"specialized",owner:"Broker limits tab"},lifecycle:{surface:"specialized",owner:"sys config set lifecycle.unattendedParkMs"},completion_bell:{surface:"settings",setting:{key:"completion_bell",label:"Completion bell",description:"Ring a short sound when the node in an attached viewer finishes a turn.",valueConstraint:"true|false",applies:"Applies on the next turn end.",group:"display",order:41,format:n(e=>e.completion_bell?"on":"off","format"),cycle:n(e=>{e.completion_bell=!e.completion_bell},"cycle"),setFromString:n((e,t)=>{const r=i(t,"completion_bell");return typeof r=="string"?r:(e.completion_bell=r,null)},"setFromString")}},working_gerunds:{surface:"specialized",owner:"sys config set working_gerunds"},whip_mode:{surface:"settings",setting:{key:"whip_mode",label:"Whip mode",description:"Play the whip animation when you send a prompt and when a viewer opens for an agent with an initial prompt.",valueConstraint:"true|false",applies:"Applies on the next attach.",group:"display",order:39,format:n(e=>e.whip_mode?"on":"off","format"),cycle:n(e=>{e.whip_mode=!e.whip_mode},"cycle"),setFromString:n((e,t)=>{const r=i(t,"whip_mode");return typeof r=="string"?r:(e.whip_mode=r,null)},"setFromString")}},page_surface:{surface:"settings",setting:{key:"page_surface",label:"Page human surface",description:"This host reads pages in a browser rather than a terminal. Agents are told the page module runs as written, HTML pages are offered, and document review and live display leave the command tree.",valueConstraint:"true|false",applies:"Applies when human command help is assembled.",group:"display",order:37,format:n(e=>e.page_surface?"on":"off","format"),cycle:n(e=>{e.page_surface=!e.page_surface},"cycle"),setFromString:n((e,t)=>{const r=i(t,"page_surface");return typeof r=="string"?r:(e.page_surface=r,null)},"setFromString")}},whip_messages:{surface:"specialized",owner:"sys config set whip_messages"},whip_message_mode:{surface:"settings",setting:{key:"whip_message_mode",label:"Whip message",description:"What the whip action sends: a random line from whip_messages, or the fixed \u201CGo faster\u201D.",valueConstraint:c.join("|"),applies:"Applies on the next attach.",group:"display",order:40,format:n(e=>e.whip_message_mode==="go-faster"?"go faster":"random","format"),cycle:n((e,t)=>{e.whip_message_mode=l(c,e.whip_message_mode,t)},"cycle"),setFromString:n((e,t)=>c.includes(t)?(e.whip_message_mode=t,null):`whip_message_mode must be one of: ${c.join("|")}`,"setFromString")}},mouse_mode_default:{surface:"settings",setting:{key:"mouse_mode_default",label:"Default mouse mode",description:"Initial mouse wheel scrolling for each attached viewer.",valueConstraint:d.join("|"),applies:"Applies on the next attach.",group:"display",order:38,format:n(e=>e.mouse_mode_default==="tmux"?"follow tmux":e.mouse_mode_default,"format"),cycle:n((e,t)=>{e.mouse_mode_default=l(d,e.mouse_mode_default,t)},"cycle"),setFromString:n((e,t)=>d.includes(t)?(e.mouse_mode_default=t,null):`mouse_mode_default must be one of: ${d.join("|")}`,"setFromString")}},live_cycles:{surface:"settings",setting:{key:"live_cycles",label:"Live cycles",description:"Trailing refresh cycles rendered at full fidelity; older cycles condense to text.",valueConstraint:"integer >= 1",applies:"Applies on the next attach.",group:"display",order:50,format:n(e=>String(e.live_cycles),"format"),cycle:n((e,t)=>{e.live_cycles=f(O,e.live_cycles,t)},"cycle"),setFromString:n((e,t)=>{const r=_(t,"live_cycles");return typeof r=="string"?r:(e.live_cycles=r,null)},"setFromString")}},condensed_history:{surface:"settings",setting:{key:"condensed_history",label:"Condensed history",description:"Messages retained from condensed cycles. Tool calls are never kept.",valueConstraint:p.join("|"),applies:"Applies on the next attach.",group:"display",order:60,format:n(e=>e.condensed_history,"format"),cycle:n((e,t)=>{e.condensed_history=l(p,e.condensed_history,t)},"cycle"),setFromString:n((e,t)=>p.includes(t)?(e.condensed_history=t,null):`condensed_history must be one of: ${p.join("|")}`,"setFromString")}},bash_tool_purpose:{surface:"settings",setting:{key:"bash_tool_purpose",label:"Bash purpose field",description:"Expose the optional purpose label to agents in the bash tool schema. Off removes the field without disabling the bash valve.",valueConstraint:"true|false",applies:"Applies on the next node session.",group:"display",order:25,format:n(e=>e.bash_tool_purpose?"on":"off","format"),cycle:n(e=>{e.bash_tool_purpose=!e.bash_tool_purpose},"cycle"),setFromString:n((e,t)=>{const r=i(t,"bash_tool_purpose");return typeof r=="string"?r:(e.bash_tool_purpose=r,null)},"setFromString")}},verbosity:{surface:"settings",setting:{key:"verbosity",label:"Verbosity",description:"How much of a transcript the viewer shows, from one rewritten reply per message to every tool call untruncated. Ctrl+O shows more and Ctrl+Shift+O less in the open viewer only; this sets where every viewer starts.",valueConstraint:a.join("|"),applies:"Applies on the next attach.",group:"display",order:30,format:n(e=>e.verbosity,"format"),display:n(e=>x(e.verbosity),"display"),cycle:n((e,t)=>{const r=a.indexOf(e.verbosity)+t;e.verbosity=a[Math.max(0,Math.min(a.length-1,r))]},"cycle"),setFromString:n((e,t)=>a.includes(t)?(e.verbosity=t,null):`verbosity must be one of: ${a.join("|")}`,"setFromString")}},document_port:{surface:"settings",setting:{key:"document_port",label:"Document browser port",description:"Fixed localhost port where crtrd serves editable document pages.",valueConstraint:"1-65535",applies:"Applies after daemon handover and on the next attach.",group:"display",order:37.5,format:n(e=>String(e.document_port),"format"),cycle:n((e,t)=>{e.document_port=Math.max(1,Math.min(65535,e.document_port+t))},"cycle"),setFromString:n((e,t)=>{const r=Number(t);return!/^\d+$/.test(t)||!Number.isInteger(r)||r<1||r>65535?"document_port must be an integer from 1 to 65535":(e.document_port=r,null)},"setFromString")}},detailed_tool_recaps:{surface:"settings",setting:{key:"detailed_tool_recaps",label:"Detailed tool recaps",description:"Show each document read and edited file in folded tool recaps. Off shows a compact count line instead.",valueConstraint:"true|false",applies:"Applies on the next attach.",group:"display",order:36,format:n(e=>e.detailed_tool_recaps?"on":"off","format"),cycle:n(e=>{e.detailed_tool_recaps=!e.detailed_tool_recaps},"cycle"),setFromString:n((e,t)=>{const r=i(t,"detailed_tool_recaps");return typeof r=="string"?r:(e.detailed_tool_recaps=r,null)},"setFromString")}},keybindings:{surface:"specialized",owner:"Keybindings tab"},tmux_passthrough:{surface:"specialized",owner:"Keybindings tab"},providerOptions:{surface:"settings",settings:{"openai-codex.fastMode":{key:`providerOptions.${u}.fastMode`,label:"Codex fast mode",description:"Serve Codex turns at the ChatGPT priority tier: about 1.5x faster generation for about 2x the credits. Displayed cost does not reflect the premium.",valueConstraint:"true|false",applies:"Applies on each node's next turn.",group:"providers",order:40,format:n(e=>e.providerOptions[u]?.fastMode?"on":"off","format"),cycle:n(e=>{const t=h(e,u);t.fastMode=!t.fastMode},"cycle"),setFromString:n((e,t)=>{const r=i(t,`providerOptions.${u}.fastMode`);return typeof r=="string"?r:(h(e,u).fastMode=r,null)},"setFromString")}}},modelLadders:{surface:"specialized",owner:"Models tab"},modelRoutes:{surface:"specialized",owner:"Models route declarations"},modelRouting:{surface:"specialized",owner:"Models route declarations"},kinds:{surface:"specialized",owner:"Models tab and kind registry"},page_components:{surface:"specialized",owner:"Page component catalog: product-registered page component kinds"},remoteCanvas:{surface:"specialized",owner:"canvas config commands"},api:{surface:"specialized",owner:"sys connect"},paths:{surface:"specialized",owner:"runtime layout"},store:{surface:"specialized",owner:"daemon conversation store"},runtime:{surface:"specialized",owner:"app-facing listener"},spawnEnv:{surface:"specialized",owner:"spawn environment allow-list"},bin:{surface:"specialized",owner:"bare-binary contributions on every node PATH"},humanActions:{surface:"specialized",owner:"scope-configured human completion actions"}},M=Object.keys(y);function C(){const e=[];for(const t of Object.values(y))t.surface==="settings"&&("setting"in t?e.push(t.setting):e.push(...Object.values(t.settings)));return e.sort((t,r)=>t.order-r.order)}n(C,"collectUserSettings");const v=C();function F(e){return v.find(t=>t.key===e)}n(F,"findUserSetting");function z(e){return v.filter(t=>t.group===e)}n(z,"userSettingsInGroup");export{y as CONFIG_SETTINGS_COVERAGE,M as SCOPE_CONFIG_KEYS,v as USER_SETTINGS,w as VERBOSITY_LABELS,F as findUserSetting,z as userSettingsInGroup,x as verbositySpectrum};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
export declare const CANVAS_CALLBACK_PATH = "/auth/callback";
|
|
3
|
+
/** The configured canvas origin, from `CRTR_CANVAS_URL` alone, on a cloud role; undefined otherwise. Never reads the key, so a
|
|
4
|
+
* half-configured canvas cannot fail requests for any other host. */
|
|
5
|
+
export declare function canvasOrigin(): string | undefined;
|
|
6
|
+
/** Whether `req` is for the canvas host: a cloud role whose `CRTR_CANVAS_URL` host equals the request's Host. */
|
|
7
|
+
export declare function isCanvasRequest(req: IncomingMessage): boolean;
|
|
8
|
+
/** Serve one request on the canvas host. The caller checked `isCanvasRequest`. */
|
|
9
|
+
export declare function serveCanvas(req: IncomingMessage, res: ServerResponse): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var U=Object.defineProperty;var a=(e,n)=>U(e,"name",{value:n,configurable:!0});import{createHash as v,createHmac as C,createPrivateKey as x,hkdfSync as j,randomBytes as _,randomUUID as J,sign as D,timingSafeEqual as H}from"node:crypto";import{readFileSync as V}from"node:fs";import{JwksCache as W,verifyIdToken as B}from"@north-light/identity";import{isCloudRole as M,runAsPerson as z}from"../../core/canvas/person.js";import{directoryIssuer as F}from"../../core/directory/issuer.js";import{emitEvent as R}from"../../core/events/emit.js";import{ApiError as K}from"../../api/errors.js";import{boundDaemonControl as G}from"../control.js";import{loadPersonSettings as Y}from"../../core/scoped-state/person-rows.js";import{personHasSnapshot as Z}from"../../core/scoped-state/person-store.js";import{escapeHtml as T}from"./vendor-signin.js";import{cookieValue as A,documentNotFound as Q,documentShell as X,error as m,messagePage as p,resolveDocument as q,serveDocumentApi as ee,setPageHeaders as ne}from"./document-page.js";const w="/auth/callback",E=12*36e5,L=10*6e4,te=1e4;let g,$,y;function oe(){if(g!==void 0)return g;const e=process.env.CRTR_CANVAS_URL;if(!e)return g=null;const n=new URL(e),t=process.env.CRTR_CANVAS_CLIENT_ID,o=process.env.CRTR_CANVAS_JWK_FILE,r=F();if(!t||!o||r===null)throw new Error("CRTR_CANVAS_URL needs CRTR_CANVAS_CLIENT_ID, CRTR_CANVAS_JWK_FILE and CRTR_DIRECTORY_URL");const i=JSON.parse(V(o,"utf8"));if(i.kty!=="EC"||i.crv!=="P-256"||!i.d)throw new Error("CRTR_CANVAS_JWK_FILE must hold a private P-256 JWK");const s=Buffer.from(j("sha256",i.d,"crtr-canvas","canvas-session-cookies",32));return g={origin:n.origin,host:n.host,secure:n.protocol==="https:",clientId:t,jwk:i,issuer:r,key:s}}a(oe,"canvasConfig");function re(){const e=process.env.CRTR_CANVAS_URL;if(!(!M()||!e))try{return new URL(e).origin}catch{return}}a(re,"canvasOrigin");function ve(e){const n=re();return n!==void 0&&e.headers.host===new URL(n).host}a(ve,"isCanvasRequest");const f=a(e=>e.toString("base64url"),"b64");function I(e,n,t,o){const r=f(Buffer.from(JSON.stringify({...t,purpose:n,exp:Date.now()+o})));return`${r}.${f(C("sha256",e.key).update(r).digest())}`}a(I,"seal");function N(e,n,t){if(!t)return null;const[o,r,i]=t.split(".");if(!o||!r||i!==void 0)return null;const s=a(c=>v("sha256").update(c).digest(),"digest");if(!H(s(r),s(f(C("sha256",e.key).update(o).digest()))))return null;try{const c=JSON.parse(Buffer.from(o,"base64url").toString("utf8"));return c.purpose===n&&typeof c.exp=="number"&&c.exp>Date.now()?c:null}catch{return null}}a(N,"open");const S=a((e,n)=>e.secure?`__Host-${n}`:n,"cookieName");function k(e,n,t,o){return`${S(e,n)}=${t}; Path=/; HttpOnly; SameSite=Lax; Max-Age=${Math.floor(o/1e3)}${e.secure?"; Secure":""}`}a(k,"cookie");async function O(e,n){const t=await fetch(e,{...n,signal:AbortSignal.timeout(te)}),o=await t.json().catch(()=>({}));if(!t.ok)throw new Error(`directory ${new URL(e).pathname} answered ${t.status}: ${String(o.error_description??o.error??"")}`);return o}a(O,"directoryJson");function P(e){return y??=O(`${e.issuer}/.well-known/openid-configuration`).then(n=>{if(typeof n.authorization_endpoint!="string"||typeof n.token_endpoint!="string")throw new Error("directory discovery has no authorization or token endpoint");return n},n=>{throw y=void 0,n}),y}a(P,"discover");function ie(e,n){const t=Math.floor(Date.now()/1e3),o=f(Buffer.from(JSON.stringify({alg:"ES256",typ:"JWT",...e.jwk.kid?{kid:e.jwk.kid}:{}}))),r=f(Buffer.from(JSON.stringify({iss:e.clientId,sub:e.clientId,aud:n,iat:t,exp:t+60,jti:J()}))),i=D("sha256",Buffer.from(`${o}.${r}`),{key:x({key:e.jwk,format:"jwk"}),dsaEncoding:"ieee-p1363"});return`${o}.${r}.${f(i)}`}a(ie,"clientAssertion");async function b(e,n,t){return await O(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({...t,client_id:e.clientId,client_assertion_type:"urn:ietf:params:oauth:client-assertion-type:jwt-bearer",client_assertion:ie(e,n)})})}a(b,"directoryPost");async function ae(e,n,t){const o=await P(e),r={state:f(_(16)),verifier:f(_(32)),nonce:f(_(32)),next:t},i=new URL(o.authorization_endpoint);i.search=new URLSearchParams({response_type:"code",client_id:e.clientId,redirect_uri:`${e.origin}${w}`,scope:"openid",state:r.state,nonce:r.nonce,code_challenge:f(v("sha256").update(r.verifier).digest()),code_challenge_method:"S256"}).toString(),n.writeHead(303,{Location:i.href,"Set-Cookie":k(e,`crtr_canvas_login_${r.state}`,I(e,"login",r,L),L),"Cache-Control":"no-store"}),n.end()}a(ae,"startSignIn");async function se(e,n,t,o){const r=o.searchParams.get("state"),i=r!==null&&/^[A-Za-z0-9_-]{22}$/.test(r)?`crtr_canvas_login_${r}`:void 0,s=i===void 0?null:N(e,"login",A(n.headers.cookie,S(e,i))),c=o.searchParams.get("code");if(o.searchParams.get("error")!==null)return p(t,400,"Sign-in did not finish",`Northlight answered <code>${T(o.searchParams.get("error").slice(0,100))}</code>. Open the document link again to retry.`);if(s===null||c===null||r!==s.state)return p(t,400,"Sign-in did not finish","This sign-in started in another browser or expired. Open the document link again.");const d=await P(e),u=await b(e,d.token_endpoint,{grant_type:"authorization_code",code:c,redirect_uri:`${e.origin}${w}`,code_verifier:s.verifier});if(typeof u.refresh_token=="string"&&d.revocation_endpoint!==void 0&&await b(e,d.revocation_endpoint,{token:u.refresh_token,token_type_hint:"refresh_token"}).catch(h=>R({level:"warn",event:"api.canvas.revoke_failed",error:h instanceof Error?h:new Error(String(h))})),typeof u.id_token!="string")throw new Error("the directory token response has no id_token");$??=new W(e.issuer);const l=await B({token:u.id_token,jwks:$,issuer:e.issuer,audience:e.clientId});if(l.nonce!==s.nonce)return p(t,400,"Sign-in did not finish","The sign-in answer does not match this browser. Open the document link again.");t.writeHead(303,{Location:s.next,"Set-Cookie":[k(e,"crtr_canvas_session",I(e,"session",{sub:l.sub},E),E),k(e,i,"",0)],"Cache-Control":"no-store"}),t.end()}a(se,"finishSignIn");async function Ce(e,n){try{await ce(e,n)}catch(t){R({level:"error",event:"api.canvas.failed",error:t instanceof Error?t:new Error(String(t)),fields:{method:e.method,path:e.url?.split("?")[0]}}),n.headersSent?n.destroy():p(n,500,"Something went wrong","The document could not be opened. Try again in a moment.")}}a(Ce,"serveCanvas");async function ce(e,n){const t=oe();if(t===null)throw new Error("CRTR_CANVAS_URL is unset");if(ne(n),G()?.startupBlock()!=null)return p(n,503,"Starting up","The canvas is starting. Try again in a moment.");const o=new URL(e.url??"/",t.origin);if(e.method==="POST"){if(e.headers.origin!==t.origin)return m(n,403,"forbidden","invalid Origin");if(e.headers["content-type"]!=="application/json")return m(n,415,"unsupported_media_type","Content-Type must be application/json")}if(e.method==="GET"&&o.pathname===w)return await se(t,e,n,o);const r=e.method==="GET"&&(o.pathname.startsWith("/r/")||o.pathname.startsWith("/document/")),i=o.pathname.startsWith("/assets/")?null:N(t,"session",A(e.headers.cookie,S(t,"crtr_canvas_session")));if(i===null&&!o.pathname.startsWith("/assets/"))return r?await ae(t,n,`${o.pathname}${o.search}`):m(n,401,"unauthorized","your sign-in expired: reload the page to sign in again");const s=i?.sub,c=a(d=>s===void 0?d():z(s,async()=>(Z()||await Y(s),await d())),"asPerson");await c(async()=>{if(r){const d=o.pathname.startsWith("/r/")?"/r/":"/document/";let u;try{u=decodeURIComponent(o.pathname.slice(d.length))}catch{return m(n,400,"invalid_request","the address is not valid percent-encoding")}let l;try{l=u===""?null:await q(u)}catch(h){if(h instanceof K&&h.code==="ambiguous_name")return p(n,409,"More than one document has this name",T(h.message));throw h}if(l===null||d==="/document/"&&l.id!==u)return Q(n,u);if(d==="/r/"){n.writeHead(303,{Location:`/document/${encodeURIComponent(l.id)}`,"Cache-Control":"no-store"}),n.end();return}return X(n,l.id,l)}if(!await ee(e,n,o,c))return e.method==="GET"&&o.pathname==="/"?p(n,404,"Northlight canvas","Open a document from its link in the viewer."):m(n,404,"not_found","route not found")})}a(ce,"canvasRequest");export{w as CANVAS_CALLBACK_PATH,re as canvasOrigin,ve as isCanvasRequest,Ce as serveCanvas};
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
`);const s=h(async _=>{if(_==="deleted"){e.write(`event: deleted
|
|
4
|
-
data: {}
|
|
5
|
-
|
|
6
|
-
`),e.end();return}const f=await p(o),g=f&&await D(f);g&&e.write(`event: edited
|
|
7
|
-
data: ${JSON.stringify({revision:g.revision,heads_key:g.heads_key})}
|
|
8
|
-
|
|
9
|
-
`)},"notify"),d=await M(o,_=>{s(_).catch(f=>{V({level:"error",event:"daemon.document_events.notify_failed",error:f}),e.end()})}),w=setInterval(()=>e.write(`: keepalive
|
|
10
|
-
|
|
11
|
-
`),3e4);e.on("close",()=>{clearInterval(w),d()});return}if(i.method==="GET"&&c.pathname.startsWith(`/assets/${y}/`)){const o=c.pathname.slice(`/assets/${y}/`.length);if(!/^[a-zA-Z0-9_.-]+$/.test(o))return m(e,404,"not_found","asset not found");const s=o==="mermaid.js"?E(j,"clients/attach/assets/mermaid.min.js"):E(j,"doc-editor",o);try{const d=B(s);return e.writeHead(200,{"Content-Type":z(o)===".css"?"text/css; charset=utf-8":"text/javascript; charset=utf-8","Cache-Control":"public, max-age=31536000, immutable"}),e.end(d)}catch(d){if(d.code==="ENOENT")return m(e,404,"not_found","asset not found");throw d}}return m(e,404,"not_found","route not found")})().catch(u=>{e.headersSent?e.destroy():m(e,500,"server_failure",u instanceof Error?u.message:String(u))})});return{ready:new Promise((i,e)=>{r.once("error",u=>{v=`the document listener could not bind 127.0.0.1:${n}: ${u.message}`,e(u)}),r.listen(n,"127.0.0.1",()=>{r.removeAllListeners("error"),v=void 0,i()})}),close:h(()=>new Promise(i=>{v="the document listener is closed",r.closeAllConnections(),r.close(()=>i())}),"close")}}h(Ee,"createDocumentListener");export{Ee as createDocumentListener,Te as documentListenerUnavailable};
|
|
1
|
+
var f=Object.defineProperty;var c=(n,r)=>f(n,"name",{value:r,configurable:!0});import{createHash as p,timingSafeEqual as v}from"node:crypto";import{createServer as g}from"node:http";import{cookieValue as S,documentNotFound as $,documentShell as y,error as d,messagePage as w,resolveDocument as P,serveDocumentApi as k,setPageHeaders as _}from"./document-page.js";function m(n,r){const l=c(s=>p("sha256").update(s).digest(),"digest");return v(l(n),l(r))}c(m,"sameSecret");const b=c(n=>n(),"inProcess");let h="the document listener has not started";function T(){return h}c(T,"documentListenerUnavailable");function W(n,r){const l=`crtr_doc_${n}`,s=g((t,e)=>{(async()=>{_(e);const a=[`127.0.0.1:${n}`,`localhost:${n}`];if(typeof t.headers.host!="string"||!a.includes(t.headers.host))return d(e,403,"forbidden","invalid Host");if(t.method==="POST"){if(!a.some(i=>t.headers.origin===`http://${i}`))return d(e,403,"forbidden","invalid Origin");if(t.headers["content-type"]!=="application/json")return d(e,415,"unsupported_media_type","Content-Type must be application/json")}const o=new URL(t.url??"/",`http://127.0.0.1:${n}`);if(!o.pathname.startsWith("/assets/")){const i=t.method==="GET"&&o.pathname.startsWith("/r/")?o.searchParams.get("t"):null;if(i!==null&&m(i,r))return o.searchParams.delete("t"),e.writeHead(303,{Location:`${o.pathname}${o.search}`,"Set-Cookie":`${l}=${r}; HttpOnly; SameSite=Strict; Path=/`,"Cache-Control":"no-store"}),e.end();const u=S(t.headers.cookie,l);if(i!==null||u===void 0||!m(u,r))return o.pathname.startsWith("/r/")?w(e,401,"Not authorized","Open this document from its link in the attach viewer."):d(e,401,"unauthorized","open the document link from the attach viewer")}if(t.method==="GET"&&o.pathname.startsWith("/r/")){let i;try{i=decodeURIComponent(o.pathname.slice(3))}catch{return d(e,400,"invalid_request","ref is not valid percent-encoding")}const u=await P(i);return u?y(e,i,u):$(e,i)}if(!await k(t,e,o,b))return d(e,404,"not_found","route not found")})().catch(a=>{e.headersSent?e.destroy():d(e,500,"server_failure",a instanceof Error?a.message:String(a))})});return{ready:new Promise((t,e)=>{s.once("error",a=>{h=`the document listener could not bind 127.0.0.1:${n}: ${a.message}`,e(a)}),s.listen(n,"127.0.0.1",()=>{s.removeAllListeners("error"),h=void 0,t()})}),close:c(()=>new Promise(t=>{h="the document listener is closed",s.closeAllConnections(),s.close(()=>t())}),"close")}}c(W,"createDocumentListener");export{W as createDocumentListener,T as documentListenerUnavailable};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import type { ObjectRow } from '../../core/graph/types.js';
|
|
3
|
+
/** Runs a callback as the request's person. The canvas host wraps it in `runAsPerson`; a live-update notification fires outside the
|
|
4
|
+
* request's async context, so it re-enters the person through this. */
|
|
5
|
+
export type AsPerson = <T>(fn: () => Promise<T>) => Promise<T>;
|
|
6
|
+
export declare function setPageHeaders(res: ServerResponse): void;
|
|
7
|
+
export declare function error(res: ServerResponse, status: number, code: string, message: string): void;
|
|
8
|
+
export declare function cookieValue(header: string | undefined, name: string): string | undefined;
|
|
9
|
+
/** A small HTML page with a heading and one paragraph of already-escaped HTML. */
|
|
10
|
+
export declare function messagePage(res: ServerResponse, status: number, title: string, html: string): void;
|
|
11
|
+
export declare function documentNotFound(res: ServerResponse, ref: string): void;
|
|
12
|
+
/** The editor's HTML shell; the editor reads `ref` from `#app[data-ref]` and calls the `/api/*` routes with it. */
|
|
13
|
+
export declare function documentShell(res: ServerResponse, ref: string, doc: ObjectRow): void;
|
|
14
|
+
/** The live document `ref` names that the request's person can read, or null. */
|
|
15
|
+
export declare function resolveDocument(ref: string): Promise<ObjectRow | null>;
|
|
16
|
+
/** Serve `/api/doc`, `/api/save`, `/api/events` and `/assets/<version>/…`. Answers false for any other route. The caller has already
|
|
17
|
+
* checked its gate, and for a POST the Origin and Content-Type. */
|
|
18
|
+
export declare function serveDocumentApi(req: IncomingMessage, res: ServerResponse, url: URL, asPerson: AsPerson): Promise<boolean>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var j=Object.defineProperty;var s=(n,e)=>j(n,"name",{value:e,configurable:!0});import{readFileSync as D}from"node:fs";import{join as x,extname as O}from"node:path";import{fileURLToPath as P}from"node:url";import{withCanvasWrite as p}from"../../core/canvas/db.js";import{ApiError as R}from"../../api/errors.js";import{get as v}from"../../core/graph/bodies.js";import{canChange as E,isShipped as A}from"../../core/graph/access.js";import{documentRecord as T,editDocument as B,heads as $,withCurrentNames as _}from"../../core/graph/documents.js";import{getById as g}from"../../core/graph/objects.js";import{subscribeDocumentEvents as F}from"../../core/graph/events.js";import{emitEvent as I}from"../../core/events/emit.js";import{checkoutsForCwd as J}from"../../core/graph/repo-sync/repos.js";import{canonicalName as L,repoChange as U,syncChanged as W}from"./handlers/docs.js";import{escapeHtml as h}from"./vendor-signin.js";import{readerFor as b,resolveRef as G,warmDocumentWatchers as z}from"./reader.js";import{mergeDocumentLines as M}from"./document-merge.js";import{crtrVersion as V}from"../../shared/crtr-version.js";const X="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'none'; frame-ancestors 'none'",C={class:"person"},w=encodeURIComponent(V()),S=P(new URL("../../../dist/",import.meta.url));function we(n){n.setHeader("Content-Security-Policy",X),n.setHeader("X-Content-Type-Options","nosniff")}s(we,"setPageHeaders");function u(n,e,t,o){n.writeHead(e,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),n.end(JSON.stringify({error:{code:t,message:o}}))}s(u,"error");function ve(n,e){for(const t of(n??"").split(";")){const o=t.indexOf("=");if(o!==-1&&t.slice(0,o).trim()===e)return t.slice(o+1).trim()}}s(ve,"cookieValue");function H(n,e,t){n.writeHead(e,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),n.end(JSON.stringify(t))}s(H,"json");function Z(n,e,t,o){n.writeHead(e,{"Content-Type":"text/html; charset=utf-8","Cache-Control":"no-store"}),n.end(`<!doctype html><html><head><meta charset="utf-8"><title>${h(t)}</title><link rel="icon" href="data:,"></head><body style="font-family:system-ui,sans-serif;max-width:40rem;margin:4rem auto;padding:0 1rem"><h1>${h(t)}</h1><p>${o}</p></body></html>`)}s(Z,"messagePage");function _e(n,e){Z(n,404,"Document not found",`No document you can read is named <code>${h(e)}</code>.`)}s(_e,"documentNotFound");function ge(n,e,t){n.writeHead(200,{"Content-Type":"text/html; charset=utf-8","Cache-Control":"no-store"}),n.end(`<!doctype html><html><head><meta charset="utf-8"><title>${h(t.name)}</title><link rel="icon" href="data:,"><link rel="stylesheet" href="/assets/${w}/editor.css"></head><body><div id="app" data-ref="${h(e)}"></div><script type="module" src="/assets/${w}/editor.js"><\/script></body></html>`)}s(ge,"documentShell");async function N(n){return await p(async e=>{const t=await g(e,n.id);if(!t||t.deleted_at||t.type!=="document")return null;const o=await b(e,{principal:C}),a=await T(e,t),r=await $(e,t),i=await L(e,t),c=r.length===1&&await E(e,o,t);return{id:t.id,name:i,revision:a.revision,heads_key:a.heads_key,body:r.length===1?await _(e,t,await v(e,r[0].body_hash)):"",editable:c,...c?{}:{readonly_reason:r.length!==1?`has ${r.length} heads and needs a merge`:await A(e,t)?"shipped by a plugin":"you cannot change this document"}}})}s(N,"snapshot");async function k(n){return await p(async e=>{const t=await b(e,{principal:C});try{const o=await G(e,t,n);return"deleted"in o||"remote"in o||o.type!=="document"?null:o}catch(o){if(o instanceof R&&o.code==="not_found")return null;throw o}})}s(k,"resolveDocument");async function q(n){return await p(async e=>{const t=await g(e,n);return!t||t.type!=="document"||t.deleted_at!==null})}s(q,"isDeleted");async function K(n){const e=[];let t=0;for await(const o of n){if(t+=o.length,t>2e6)throw new Error("request body exceeds 2 MB");e.push(o)}return JSON.parse(Buffer.concat(e).toString("utf8"))}s(K,"requestBody");async function Q(n){await z(n.id);const e=await p(async t=>{const o=await b(t,{principal:C}),a=await g(t,n.id);if(!a||a.type!=="document"||a.deleted_at)return{status:404,value:{error:{code:"not_found",message:"document not found"}}};const r=await T(t,a),i=await $(t,a);if(i.length!==1||!await E(t,o,a))return{status:403,value:{error:{code:"forbidden",message:"document is read-only"}}};const c=await _(t,a,await v(t,i[0].body_hash)),f=await t.prepareUncached("SELECT body_hash FROM revisions WHERE document = ? AND rev_id = ?").get(a.id,n.base_heads_key);if(!f||await _(t,a,await v(t,f.body_hash))!==n.base_body)return{status:409,value:{saved:!1,conflict:{revision:r.revision,heads_key:r.heads_key,current_body:c,your_body:n.body}}};const y=n.base_heads_key!==r.heads_key,l=y?M(n.base_body,n.body,c):n.body;if(l===null)return{status:409,value:{saved:!1,conflict:{revision:r.revision,heads_key:r.heads_key,current_body:c,your_body:n.body}}};const d=await B(t,o,a,{body:l},n.rationale?.trim()||"edited by the person in the browser",r.heads_key,{},async m=>await J(t,m));return"stale"in d?{status:409,value:{saved:!1,conflict:{revision:d.stale.revision,heads_key:d.stale.heads_key,current_body:c,your_body:n.body}}}:{status:200,value:{saved:!0,revision:d.revision,heads_key:d.heads_key,body:l,merged:y},change:await U(t,o,[a])}});return e.change&&await W(e.change),e}s(Q,"save");async function be(n,e,t,o){if(n.method==="GET"&&t.pathname==="/api/doc"){const a=t.searchParams.get("ref"),r=a?await k(a):null,i=r&&await N(r);return i?H(e,200,{...i,ref:a}):u(e,404,"not_found","document not found"),!0}if(n.method==="POST"&&t.pathname==="/api/save"){const a=await K(n);if(!a||typeof a!="object"||Array.isArray(a))return u(e,400,"invalid_request","invalid save body"),!0;const r=a;if(typeof r.id!="string"||typeof r.base_heads_key!="string"||typeof r.base_body!="string"||typeof r.body!="string"||r.rationale!==void 0&&typeof r.rationale!="string")return u(e,400,"invalid_request","invalid save body"),!0;const i=await Q(r);return H(e,i.status,i.value),!0}if(n.method==="GET"&&t.pathname==="/api/events"){const a=t.searchParams.get("id");if(!a||!await k(a))return u(e,404,"not_found","document not found"),!0;e.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-store",Connection:"keep-alive","X-Accel-Buffering":"no"}),e.write(`: connected
|
|
2
|
+
|
|
3
|
+
`);const r=s(async()=>{const d=await k(a),m=d&&await N(d);if(!e.writableEnded){if(m){e.write(`event: edited
|
|
4
|
+
data: ${JSON.stringify({revision:m.revision,heads_key:m.heads_key})}
|
|
5
|
+
|
|
6
|
+
`);return}await q(a)&&e.write(`event: deleted
|
|
7
|
+
data: {}
|
|
8
|
+
|
|
9
|
+
`),e.end()}},"notify");let i=!1,c=!1;const f=s(()=>{if(i){c=!0;return}i=!0,o(r).catch(d=>{I({level:"error",event:"daemon.document_events.notify_failed",error:d}),e.end()}).finally(()=>{i=!1,c&&!e.writableEnded&&(c=!1,f())})},"wake"),y=await F(a,f),l=setInterval(()=>{e.writableEnded||e.write(`: keepalive
|
|
10
|
+
|
|
11
|
+
`)},3e4);return e.on("close",()=>{clearInterval(l),y()}),!0}if(n.method==="GET"&&t.pathname.startsWith(`/assets/${w}/`)){const a=t.pathname.slice(`/assets/${w}/`.length);if(!/^[a-zA-Z0-9_.-]+$/.test(a))return u(e,404,"not_found","asset not found"),!0;const r=a==="mermaid.js"?x(S,"clients/attach/assets/mermaid.min.js"):x(S,"doc-editor",a);try{const i=D(r);e.writeHead(200,{"Content-Type":O(a)===".css"?"text/css; charset=utf-8":"text/javascript; charset=utf-8","Cache-Control":"public, max-age=31536000, immutable"}),e.end(i)}catch(i){if(i.code==="ENOENT")u(e,404,"not_found","asset not found");else throw i}return!0}return!1}s(be,"serveDocumentApi");export{ve as cookieValue,_e as documentNotFound,ge as documentShell,u as error,Z as messagePage,k as resolveDocument,be as serveDocumentApi,we as setPageHeaders};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var n=Object.defineProperty;var o=(e,t)=>n(e,"name",{value:t,configurable:!0});import{ApiError as r}from"../../../api/errors.js";import{isCloudRole as s}from"../../../core/canvas/person.js";import{canvasOrigin as i}from"../canvas-host.js";import{documentListenerUnavailable as a}from"../document-listener.js";import{documentSecret as u}from"../document-secret.js";const v=[{method:"GET",pattern:"/v1/documents/browser-access",handler:o(()=>{if(s()){const t=i();if(t===void 0)throw new r(503,"document_listener_unavailable","this API serves no document page (CRTR_CANVAS_URL is unset)");return{status:200,body:{canvas_url:t}}}const e=a();if(e!==void 0)throw new r(503,"document_listener_unavailable",e);return{status:200,body:{secret:u()}}},"handler")}];export{v as documentAccessRoutes};
|