@north-light/cli 0.3.760 → 0.3.761

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.
Files changed (49) hide show
  1. package/dist/builtin-memory/internal/nodes-and-canvas.md +1 -1
  2. package/dist/builtin-memory/internal/storage-tiers.md +1 -1
  3. package/dist/cli.js +5 -5
  4. package/dist/clients/attach/config.js +1 -1
  5. package/dist/clients/attach/viewer.js +467 -467
  6. package/dist/commands/api-client.d.ts +0 -5
  7. package/dist/commands/api-client.js +3 -3
  8. package/dist/commands/daemon-generation.js +1 -1
  9. package/dist/commands/sys/import/move.d.ts +1 -34
  10. package/dist/commands/sys/import/move.js +5 -9
  11. package/dist/commands/sys/import/start.d.ts +0 -3
  12. package/dist/commands/sys/import/start.js +1 -1
  13. package/dist/commands/sys/signin.js +2 -2
  14. package/dist/core/canvas/managed-worktree-sweep-candidates.d.ts +2 -0
  15. package/dist/core/canvas/managed-worktree-sweep-candidates.js +6 -4
  16. package/dist/core/command.d.ts +1 -1
  17. package/dist/core/runtime/front-door.js +9 -10
  18. package/dist/core/user-settings.d.ts +2 -2
  19. package/dist/core/worktree-mutation-async.js +5 -5
  20. package/dist/core/worktree-scripts.d.ts +13 -0
  21. package/dist/core/worktree-scripts.js +5 -0
  22. package/dist/core/worktree-sweep.js +4 -4
  23. package/dist/daemon/api/handlers/daemon.js +1 -1
  24. package/dist/daemon/crtrd.js +11 -11
  25. package/dist/daemon/import-dump-run.js +4 -4
  26. package/dist/daemon/machine-daemon.js +1 -1
  27. package/dist/daemon/machine-link/config.d.ts +0 -24
  28. package/dist/daemon/machine-link/config.js +4 -4
  29. package/dist/daemon/manage.d.ts +1 -1
  30. package/package.json +3 -3
  31. package/packages/crouter-api/dist/clients/attach/config.js +2 -1
  32. package/packages/crouter-api/dist/commands/api-client.js +1 -12
  33. package/packages/crouter-api/dist/commands/sys/import/move.js +5 -205
  34. package/packages/crouter-api/dist/commands/sys/import/start.js +15 -51
  35. package/packages/crouter-api/dist/commands/sys/signin.js +13 -54
  36. package/packages/crouter-api/dist/core/worktree-mutation-async.js +11 -3
  37. package/packages/crouter-api/dist/core/worktree-scripts.js +72 -0
  38. package/packages/crouter-api/dist/core/worktree-sweep.js +10 -1
  39. package/packages/crouter-api/dist/daemon/machine-link/config.js +1 -27
  40. package/packages/crouter-api/package.json +1 -1
  41. package/packages/crouter-identity/package.json +1 -1
  42. package/packages/crouter-plugin/package.json +3 -3
  43. package/runtime.lock.json +14 -14
  44. package/dist/commands/sys/import/retry.d.ts +0 -1
  45. package/dist/commands/sys/import/retry.js +0 -1
  46. package/dist/daemon/machine-link/move-notify.d.ts +0 -4
  47. package/dist/daemon/machine-link/move-notify.js +0 -1
  48. package/packages/crouter-api/dist/commands/sys/import/retry.js +0 -38
  49. package/packages/crouter-api/dist/daemon/machine-link/move-notify.js +0 -15
@@ -24,7 +24,7 @@ crtrd runs in one of four roles:
24
24
  | `--role reconcile` | the cloud control plane | runs the reconcilers and boot sweeps; serves only a health check |
25
25
  | `--role machine` | a Mac imported into an account (`runtime/machine.json` present) | opens no database and serves no API; holds an outbound link to the cloud and runs the processes of nodes whose environment is this machine |
26
26
 
27
- A node runs in an **environment**. A `blaxel` environment runs its broker, shell and files in a Blaxel sandbox the cloud roles start and wake. A `machine` environment runs them on a Mac: directly under that Mac's own crtrd when it is not imported, or through the machine link when the cloud roles own it. `crtr sys import` moves a Mac or a hosted runtime into an account; `crtr sys machine rotate` replaces an imported Mac's machine credential.
27
+ A node runs in an **environment**. A `blaxel` environment runs its broker, shell and files in a Blaxel sandbox the cloud roles start and wake. A `machine` environment runs them on a Mac: directly under that Mac's own crtrd when it is not imported, or through the machine link when the cloud roles own it. `crtr sys import` moves a hosted runtime into an account; `crtr sys machine rotate` replaces an imported Mac's machine credential.
28
28
 
29
29
  ## Spawn & delegate
30
30
 
@@ -15,7 +15,7 @@ Everything on the canvas — documents, nodes, jobs, owners, custom objects —
15
15
 
16
16
  ## 1. Where the database and blobs are
17
17
 
18
- - **On a Mac not yet moved to the cloud**, the no-role crtrd supervises its own Postgres 18 cluster under `<runtime>/pg/`; this is the database `crtr sys import --kind machine` reads when moving the Mac to the cloud. `CRTR_DATABASE_URL` points it at any other Postgres instead. Blobs are files under `<runtime>/blobs/`.
18
+ - **On a Mac not yet moved to the cloud**, the no-role crtrd supervises its own Postgres 18 cluster under `<runtime>/pg/`; a Mac with a local canvas cannot sign in (`local_canvas_unsupported`). `CRTR_DATABASE_URL` points it at any other Postgres instead. Blobs are files under `<runtime>/blobs/`.
19
19
  - **In the cloud**, the `api` and `reconcile` crtrd roles share one RDS Postgres with the directory (crouter's tables are in schema `crtr`), and blobs are in R2 (`CRTR_R2_BUCKET` plus the other `CRTR_R2_*` variables). The API processes share no disk, so anything they must both see is a row or a blob.
20
20
  - **An imported Mac** runs crtrd as the `machine` role: it opens no database and serves no API. It holds an outbound link to the cloud and runs that account's processes for nodes whose environment is this machine.
21
21
 
package/dist/cli.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- var _=Object.defineProperty;var n=(r,o)=>_(r,"name",{value:o,configurable:!0});import"./suppress-experimental-warnings.js";import{mkdirSync as R,openSync as b,readFileSync as I,renameSync as E,rmSync as C,statSync as u,writeFileSync as k}from"node:fs";import{dirname as g,join as s}from"node:path";import{enableCompileCache as O}from"node:module";import{fileURLToPath as h}from"node:url";import{isDaemonControlInvocation as m,isJoinInvocation as A,isPkgInstallInvocation as $,isSignInInvocation as P,personOnlyInvocation as x,resolveDaemonControlRoot as N,resolveRoot as T}from"./build-root.js";import{maybeBootRoot as F}from"./core/runtime/front-door.js";import{maybeAutoUpdate as D}from"./core/auto-update.js";import{ensureProjectScope as U}from"./core/bootstrap.js";import{provisionExports as j,pruneLegacyExports as B}from"./core/host-exports/export.js";import{revalidateBundlePlugins as L}from"./core/command-plugins/revalidate.js";import{runCli as M}from"./core/command.js";import{dispatchWithStaleRecovery as J}from"./core/manifest-recovery.js";import{installStdoutErrorPolicy as K}from"./core/stdout-errors.js";import{handle as V}from"./core/io.js";import{CrtrError as w,ownerOnly as G}from"./core/errors.js";import{runtimeRoot as W}from"./core/layout.js";import{ApiError as v}from"./api/index.js";import{mark as i}from"./core/timing.js";import{launchSnapshotFile as q,providerProjectionOverBrokerRelay as y,sandboxCliNodeId as z}from"./shared/env.js";import{nodeRunDir as f}from"./core/canvas/paths.js";import{installBrokerConfigSnapshot as H}from"./core/config.js";b(h(import.meta.url),"r"),K(),i("cli.entry",{cmd:process.argv[2]??"(bare)"});try{O()}catch{}i("cli.compile_cache");const Q=s(g(h(import.meta.url)),".."),l=s(W(),"first-run.json");function a(r){return(r instanceof Error?r.message:String(r)).split(/\r?\n/,1)[0]??""}n(a,"errorMessage");function X(r){const o=g(l);R(o,{recursive:!0});const e=`${l}.${process.pid}.${Date.now()}.tmp`;try{k(e,JSON.stringify({packageVersion:r,completedAt:new Date().toISOString()})+`
3
- `,"utf8"),E(e,l)}finally{C(e,{force:!0})}}n(X,"writeFirstRunMarker");async function Y(){if(process.env.CRTR_NO_AUTO_INIT==="1")return;try{if(u(l,{throwIfNoEntry:!1})!==void 0)return}catch(o){process.stderr.write(`crtr: first-run reconcile marker check failed: ${a(o)}
2
+ var R=Object.defineProperty;var n=(r,o)=>R(r,"name",{value:o,configurable:!0});import"./suppress-experimental-warnings.js";import{mkdirSync as _,openSync as b,readFileSync as I,renameSync as E,rmSync as C,statSync as u,writeFileSync as k}from"node:fs";import{dirname as g,join as s}from"node:path";import{enableCompileCache as O}from"node:module";import{fileURLToPath as h}from"node:url";import{isDaemonControlInvocation as m,isJoinInvocation as A,isPkgInstallInvocation as $,isSignInInvocation as P,personOnlyInvocation as x,resolveDaemonControlRoot as N,resolveRoot as T}from"./build-root.js";import{maybeBootRoot as F}from"./core/runtime/front-door.js";import{maybeAutoUpdate as D}from"./core/auto-update.js";import{ensureProjectScope as U}from"./core/bootstrap.js";import{provisionExports as j,pruneLegacyExports as B}from"./core/host-exports/export.js";import{revalidateBundlePlugins as L}from"./core/command-plugins/revalidate.js";import{runCli as M}from"./core/command.js";import{dispatchWithStaleRecovery as J}from"./core/manifest-recovery.js";import{installStdoutErrorPolicy as K}from"./core/stdout-errors.js";import{handle as V}from"./core/io.js";import{CrtrError as w,ownerOnly as G}from"./core/errors.js";import{runtimeRoot as W}from"./core/layout.js";import{ApiError as v}from"./api/index.js";import{mark as i}from"./core/timing.js";import{launchSnapshotFile as q,providerProjectionOverBrokerRelay as y,sandboxCliNodeId as z}from"./shared/env.js";import{nodeRunDir as f}from"./core/canvas/paths.js";import{installBrokerConfigSnapshot as H}from"./core/config.js";b(h(import.meta.url),"r"),K(),i("cli.entry",{cmd:process.argv[2]??"(bare)"});try{O()}catch{}i("cli.compile_cache");const Q=s(g(h(import.meta.url)),".."),l=s(W(),"first-run.json");function a(r){return(r instanceof Error?r.message:String(r)).split(/\r?\n/,1)[0]??""}n(a,"errorMessage");function X(r){const o=g(l);_(o,{recursive:!0});const t=`${l}.${process.pid}.${Date.now()}.tmp`;try{k(t,JSON.stringify({packageVersion:r,completedAt:new Date().toISOString()})+`
3
+ `,"utf8"),E(t,l)}finally{C(t,{force:!0})}}n(X,"writeFirstRunMarker");async function Y(){if(process.env.CRTR_NO_AUTO_INIT==="1")return;try{if(u(l,{throwIfNoEntry:!1})!==void 0)return}catch(o){process.stderr.write(`crtr: first-run reconcile marker check failed: ${a(o)}
4
4
  `);return}try{if(u(s(Q,".git"),{throwIfNoEntry:!1})!==void 0)return}catch(o){process.stderr.write(`crtr: first-run reconcile source check failed: ${a(o)}
5
- `);return}let r;try{const{reconcileFirstRun:o}=await import("./commands/sys/setup-core.js");r=await o((e,c)=>{process.stderr.write(`crtr: first-run reconcile ${e} failed: ${a(c)}
5
+ `);return}let r;try{const{reconcileFirstRun:o}=await import("./commands/sys/setup-core.js");r=await o((t,c)=>{process.stderr.write(`crtr: first-run reconcile ${t} failed: ${a(c)}
6
6
  `)})}catch(o){process.stderr.write(`crtr: first-run reconcile failed: ${a(o)}
7
7
  `)}finally{if(r!==void 0)try{X(r)}catch(o){process.stderr.write(`crtr: first-run reconcile marker failed: ${a(o)}
8
- `)}}}n(Y,"maybeReconcileFirstRun");async function Z(){const r=z(),o=r!==void 0;if(r!==void 0){process.env.CRTR_API_SOCKET=s(f(r),"cli.sock");const t=x(process.argv);if(t!==null)throw G(`crtr ${t} is not available to an app's node`,"Run this command from the person's terminal.");const p=JSON.parse(I(q(f(r))??s(f(r),"broker-launch.json"),"utf8"));if(!p.configSnapshot)throw new Error("node launch is missing its config snapshot");H(p.configSnapshot)}const e=n(async()=>(await import("./core/scoped-state/person-store.js")).installPreludeSnapshot({profiles:[],defaults:{},settings:{},state:{},apps:{}}),"installEmptySettings");if(!o&&(await import("./commands/api-client.js")).usesRunToken())await e();else if(!o&&!y()&&(await import("./daemon/machine-link/config.js")).computerIsUnset()&&!m(process.argv))await e();else if((!o||$(process.argv))&&!m(process.argv)&&!A(process.argv)&&!P(process.argv)){try{o||await(await import("./commands/daemon-generation.js")).assertLocalDaemonMatchesCli(),await(await import("./commands/person-settings.js")).loadPersonSettingsViaApi(),o||await(await import("./core/scoped-state/imported-mac-installs.js")).migrateLegacyInstallsOnce()}catch(t){const p=process.argv.slice(2).some(d=>d==="-h"||d==="--help"),S=t instanceof v&&(t.code==="daemon_unavailable"||t.code==="northlight_unreachable")||t instanceof w&&(t.code==="daemon_generation_mismatch"||t.code==="not_signed_in"||t.code==="move_unfinished"||t.code==="northlight_unreachable");if(!(p&&S))throw t;await e()}i("cli.settings_loaded")}if(o||(B(process.argv),y()||await Y()),await F(process.argv),i("cli.front_door_passed"),m(process.argv)){await M(await N(),process.argv);return}o||await L(process.argv),i("cli.plugins_revalidated");const c=await T(process.argv[2]);i("cli.root_resolved"),o||(j(c,process.argv),await U(process.argv),await D(process.argv)),i("cli.dispatch_start"),await J(c,process.argv),i("cli.dispatch_done")}n(Z,"main"),Z().catch(r=>{(r instanceof Error&&r.name==="AbortError"||r instanceof Error&&/operation was aborted/i.test(r.message))&&(process.stderr.write(`crtr: Interrupted
9
- `),process.exit(130)),(r instanceof v||r instanceof w)&&(V(r),process.exit(typeof process.exitCode=="number"?process.exitCode:1));const e=r instanceof Error?r.message:String(r);process.stderr.write(`crtr: ${e}
8
+ `)}}}n(Y,"maybeReconcileFirstRun");async function Z(){const r=z(),o=r!==void 0;if(r!==void 0){process.env.CRTR_API_SOCKET=s(f(r),"cli.sock");const e=x(process.argv);if(e!==null)throw G(`crtr ${e} is not available to an app's node`,"Run this command from the person's terminal.");const p=JSON.parse(I(q(f(r))??s(f(r),"broker-launch.json"),"utf8"));if(!p.configSnapshot)throw new Error("node launch is missing its config snapshot");H(p.configSnapshot)}const t=n(async()=>(await import("./core/scoped-state/person-store.js")).installPreludeSnapshot({profiles:[],defaults:{},settings:{},state:{},apps:{}}),"installEmptySettings");if(!o&&(await import("./commands/api-client.js")).usesRunToken())await t();else if(!o&&!y()&&(await import("./daemon/machine-link/config.js")).computerIsUnset()&&!m(process.argv))await t();else if((!o||$(process.argv))&&!m(process.argv)&&!A(process.argv)&&!P(process.argv)){try{o||await(await import("./commands/daemon-generation.js")).assertLocalDaemonMatchesCli(),await(await import("./commands/person-settings.js")).loadPersonSettingsViaApi(),o||await(await import("./core/scoped-state/imported-mac-installs.js")).migrateLegacyInstallsOnce()}catch(e){const p=process.argv.slice(2).some(d=>d==="-h"||d==="--help"),S=e instanceof v&&(e.code==="daemon_unavailable"||e.code==="northlight_unreachable")||e instanceof w&&(e.code==="daemon_generation_mismatch"||e.code==="not_signed_in"||e.code==="northlight_unreachable");if(!(p&&S))throw e;await t()}i("cli.settings_loaded")}if(o||(B(process.argv),y()||await Y()),await F(process.argv),i("cli.front_door_passed"),m(process.argv)){await M(await N(),process.argv);return}o||await L(process.argv),i("cli.plugins_revalidated");const c=await T(process.argv[2]);i("cli.root_resolved"),o||(j(c,process.argv),await U(process.argv),await D(process.argv)),i("cli.dispatch_start"),await J(c,process.argv),i("cli.dispatch_done")}n(Z,"main"),Z().catch(r=>{(r instanceof Error&&r.name==="AbortError"||r instanceof Error&&/operation was aborted/i.test(r.message))&&(process.stderr.write(`crtr: Interrupted
9
+ `),process.exit(130)),(r instanceof v||r instanceof w)&&(V(r),process.exit(typeof process.exitCode=="number"?process.exitCode:1));const t=r instanceof Error?r.message:String(r);process.stderr.write(`crtr: ${t}
10
10
  `),process.exit(1)});
@@ -1 +1 @@
1
- var y=Object.defineProperty;var t=(e,o)=>y(e,"name",{value:o,configurable:!0});import{readFileSync as l}from"node:fs";import{createRequire as b}from"node:module";import{piAgentDir as h}from"../../core/runtime/package-health.js";import{join as s}from"node:path";import{pathToFileURL as K}from"node:url";import{KeybindingsManager as x,TUI_KEYBINDINGS as w,setKeybindings as k}from"@earendil-works/pi-tui";import{getMarkdownTheme as p,getSelectListTheme as T}from"@earendil-works/pi-coding-agent";import{initCrtrTheme as E}from"../../core/runtime/crtr-theme.js";import{surfaceBgAnsi as B}from"../../core/runtime/surface-bg.js";function i(){return h()}t(i,"defaultAgentDir");const D={"app.interrupt":{defaultKeys:"escape",description:"Cancel or abort"},"app.clear":{defaultKeys:"ctrl+c",description:"Clear editor"},"app.exit":{defaultKeys:[],description:"Exit when editor is empty"},"app.suspend":{defaultKeys:"ctrl+z",description:"Suspend to background"},"app.thinking.cycle":{defaultKeys:"shift+tab",description:"Cycle thinking level"},"app.model.cycleForward":{defaultKeys:"ctrl+p",description:"Cycle to next model"},"app.model.cycleBackward":{defaultKeys:"shift+ctrl+p",description:"Cycle to previous model"},"app.model.select":{defaultKeys:"ctrl+l",description:"Open model selector"},"app.tools.expand":{defaultKeys:"ctrl+o",description:"Show more detail (verbosity level)"},"app.thinking.toggle":{defaultKeys:"ctrl+t",description:"Toggle thinking blocks"},"app.editor.external":{defaultKeys:"ctrl+alt+g",description:"Open external editor"},"app.message.followUp":{defaultKeys:[],description:"Queue follow-up message"},"app.message.dequeue":{defaultKeys:"alt+up",description:"Restore queued messages"},"app.clipboard.pasteImage":{defaultKeys:["alt+v","ctrl+v"],description:"Paste image from clipboard"},"app.session.new":{defaultKeys:[],description:"Start a new session"},"app.session.tree":{defaultKeys:[],description:"Open session tree"},"app.session.fork":{defaultKeys:[],description:"Fork current session"},"app.session.resume":{defaultKeys:[],description:"Resume a session"}};function I(e=i()){try{const o=JSON.parse(l(s(e,"keybindings.json"),"utf8")),r=o&&typeof o=="object"&&"keybindings"in o?o.keybindings:o;return!r||typeof r!="object"?void 0:r}catch{return}}t(I,"loadUserKeybindings");const C={"tui.input.newLine":{defaultKeys:["shift+enter","alt+enter"],description:"Insert new line"},"tui.editor.deleteToLineStart":{defaultKeys:[],description:"Delete to line start"},"tui.editor.deleteToLineEnd":{defaultKeys:[],description:"Delete to line end"},"tui.editor.deleteCharForward":{defaultKeys:["delete"],description:"Delete character forward"}};function H(e=i()){const o={...w,...D,...C},r=new x(o,I(e));return k(r),r}t(H,"createKeybindingsManager");let a;function u(){return a||(a=(async()=>{try{const e=import.meta.resolve("@earendil-works/pi-coding-agent"),o=b(e).resolve("@earendil-works/pi-tui");return await import(K(o).href)}catch{return}})()),a}t(u,"editorPiTui");async function J(e){(await u())?.setKeybindings(e)}t(J,"mirrorKeybindingsToEditor");async function V(e){(await u())?.setKittyProtocolActive(e)}t(V,"mirrorKittyProtocolToEditor");let c;function z(){return c||(c=(async()=>{try{const e=import.meta.resolve("@earendil-works/pi-coding-agent");return await(await import(new URL("./utils/tools-manager.js",e).href)).ensureTool("fd",!0)??null}catch{return null}})()),c}t(z,"resolveFdPath");function R(e){const o=[s(e?.cwd??process.cwd(),".pi","settings.json"),s(e?.agentDir??i(),"settings.json")];for(const r of o)try{const n=JSON.parse(l(r,"utf8"));if(n&&typeof n=="object"&&typeof n.theme=="string")return n.theme}catch{}}t(R,"loadThemeName");function Q(e){E(R(e),e?.agentDir??i())}t(Q,"applyTheme");const $=t(e=>`\x1B[2m${e}\x1B[22m`,"FAINT"),v=t(e=>`\x1B[31m${e}\x1B[39m`,"RED"),N=t(e=>`\x1B[33m${e}\x1B[39m`,"YELLOW"),f=t(e=>`\x1B[32m${e}\x1B[39m`,"GREEN"),P=t(e=>`\x1B[92m${e}\x1B[39m`,"BRIGHT_GREEN"),O=t(e=>`\x1B[91m${e}\x1B[39m`,"DIFF_REMOVED"),d="\x1B[48;2;36;36;36m";function S(e,o){return`${d}${e(o).replace(/\x1b\[0m/g,`\x1B[0m${d}`)}`}t(S,"codeSurfaceFragment");function W(){const e=p(),o=t((r,n)=>S(r,n),"paint");return{...e,codeBlockIndent:`${d}${e.codeBlockIndent??" "}`,codeBlock:t(r=>o(e.codeBlock,r),"codeBlock"),codeBlockBorder:t(r=>o(e.codeBlockBorder,r),"codeBlockBorder"),highlightCode:e.highlightCode?(r,n)=>e.highlightCode(r,n).map(m=>o(g=>g,m)):void 0}}t(W,"attachMarkdownTheme");function X(){const e=p(),o=T(),r=B();return{accent:e.heading,active:e.code,info:e.link,muted:o.description,faint:$,border:e.hr,bold:e.bold,error:v,warning:N,diffAdded:f,diffRemoved:O,bashMode:f,bashModeAlt:P,surface:t(n=>`${r}${n.replace(/\x1b\[0m/g,`\x1B[0m${r}`)}\x1B[49m`,"surface")}}t(X,"attachPalette");export{Q as applyTheme,W as attachMarkdownTheme,X as attachPalette,H as createKeybindingsManager,i as defaultAgentDir,R as loadThemeName,I as loadUserKeybindings,J as mirrorKeybindingsToEditor,V as mirrorKittyProtocolToEditor,z as resolveFdPath};
1
+ var y=Object.defineProperty;var t=(e,o)=>y(e,"name",{value:o,configurable:!0});import{readFileSync as l}from"node:fs";import{createRequire as b}from"node:module";import{piAgentDir as h}from"../../core/runtime/package-health.js";import{join as s}from"node:path";import{pathToFileURL as K}from"node:url";import{KeybindingsManager as x,TUI_KEYBINDINGS as w,setKeybindings as k}from"@earendil-works/pi-tui";import{getMarkdownTheme as p,getSelectListTheme as T}from"@earendil-works/pi-coding-agent";import{initCrtrTheme as E}from"../../core/runtime/crtr-theme.js";import{surfaceBgAnsi as B}from"../../core/runtime/surface-bg.js";function i(){return h()}t(i,"defaultAgentDir");const D={"app.interrupt":{defaultKeys:"escape",description:"Cancel or abort"},"app.clear":{defaultKeys:"ctrl+c",description:"Clear editor"},"app.exit":{defaultKeys:[],description:"Exit when editor is empty"},"app.suspend":{defaultKeys:"ctrl+z",description:"Suspend to background"},"app.thinking.cycle":{defaultKeys:"shift+tab",description:"Cycle thinking level"},"app.model.cycleForward":{defaultKeys:"ctrl+p",description:"Cycle to next model"},"app.model.cycleBackward":{defaultKeys:"shift+ctrl+p",description:"Cycle to previous model"},"app.model.select":{defaultKeys:"ctrl+l",description:"Open model selector"},"app.tools.expand":{defaultKeys:"ctrl+o",description:"Show more detail (verbosity level)"},"app.thinking.toggle":{defaultKeys:"ctrl+t",description:"Toggle thinking blocks"},"app.editor.external":{defaultKeys:"ctrl+alt+g",description:"Open external editor"},"app.message.followUp":{defaultKeys:[],description:"Queue follow-up message"},"app.message.dequeue":{defaultKeys:"alt+up",description:"Restore queued messages"},"app.clipboard.pasteImage":{defaultKeys:["alt+v","ctrl+v"],description:"Paste image from clipboard"},"app.session.new":{defaultKeys:[],description:"Start a new session"},"app.session.tree":{defaultKeys:[],description:"Open session tree"},"app.session.fork":{defaultKeys:[],description:"Fork current session"},"app.session.resume":{defaultKeys:[],description:"Resume a session"}};function I(e=i()){try{const o=JSON.parse(l(s(e,"keybindings.json"),"utf8")),r=o&&typeof o=="object"&&"keybindings"in o?o.keybindings:o;return!r||typeof r!="object"?void 0:r}catch{return}}t(I,"loadUserKeybindings");const C={"tui.input.newLine":{defaultKeys:["shift+enter","alt+enter"],description:"Insert new line"},"tui.editor.deleteToLineStart":{defaultKeys:["super+backspace"],description:"Delete to line start"},"tui.editor.deleteToLineEnd":{defaultKeys:[],description:"Delete to line end"},"tui.editor.deleteCharForward":{defaultKeys:["delete"],description:"Delete character forward"}};function H(e=i()){const o={...w,...D,...C},r=new x(o,I(e));return k(r),r}t(H,"createKeybindingsManager");let a;function u(){return a||(a=(async()=>{try{const e=import.meta.resolve("@earendil-works/pi-coding-agent"),o=b(e).resolve("@earendil-works/pi-tui");return await import(K(o).href)}catch{return}})()),a}t(u,"editorPiTui");async function J(e){(await u())?.setKeybindings(e)}t(J,"mirrorKeybindingsToEditor");async function V(e){(await u())?.setKittyProtocolActive(e)}t(V,"mirrorKittyProtocolToEditor");let c;function z(){return c||(c=(async()=>{try{const e=import.meta.resolve("@earendil-works/pi-coding-agent");return await(await import(new URL("./utils/tools-manager.js",e).href)).ensureTool("fd",!0)??null}catch{return null}})()),c}t(z,"resolveFdPath");function R(e){const o=[s(e?.cwd??process.cwd(),".pi","settings.json"),s(e?.agentDir??i(),"settings.json")];for(const r of o)try{const n=JSON.parse(l(r,"utf8"));if(n&&typeof n=="object"&&typeof n.theme=="string")return n.theme}catch{}}t(R,"loadThemeName");function Q(e){E(R(e),e?.agentDir??i())}t(Q,"applyTheme");const $=t(e=>`\x1B[2m${e}\x1B[22m`,"FAINT"),v=t(e=>`\x1B[31m${e}\x1B[39m`,"RED"),N=t(e=>`\x1B[33m${e}\x1B[39m`,"YELLOW"),f=t(e=>`\x1B[32m${e}\x1B[39m`,"GREEN"),P=t(e=>`\x1B[92m${e}\x1B[39m`,"BRIGHT_GREEN"),O=t(e=>`\x1B[91m${e}\x1B[39m`,"DIFF_REMOVED"),d="\x1B[48;2;36;36;36m";function S(e,o){return`${d}${e(o).replace(/\x1b\[0m/g,`\x1B[0m${d}`)}`}t(S,"codeSurfaceFragment");function W(){const e=p(),o=t((r,n)=>S(r,n),"paint");return{...e,codeBlockIndent:`${d}${e.codeBlockIndent??" "}`,codeBlock:t(r=>o(e.codeBlock,r),"codeBlock"),codeBlockBorder:t(r=>o(e.codeBlockBorder,r),"codeBlockBorder"),highlightCode:e.highlightCode?(r,n)=>e.highlightCode(r,n).map(m=>o(g=>g,m)):void 0}}t(W,"attachMarkdownTheme");function X(){const e=p(),o=T(),r=B();return{accent:e.heading,active:e.code,info:e.link,muted:o.description,faint:$,border:e.hr,bold:e.bold,error:v,warning:N,diffAdded:f,diffRemoved:O,bashMode:f,bashModeAlt:P,surface:t(n=>`${r}${n.replace(/\x1b\[0m/g,`\x1B[0m${r}`)}\x1B[49m`,"surface")}}t(X,"attachPalette");export{Q as applyTheme,W as attachMarkdownTheme,X as attachPalette,H as createKeybindingsManager,i as defaultAgentDir,R as loadThemeName,I as loadUserKeybindings,J as mirrorKeybindingsToEditor,V as mirrorKittyProtocolToEditor,z as resolveFdPath};