@north-light/cli 0.3.759 → 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 (81) hide show
  1. package/dist/api/contract.d.ts +1 -1
  2. package/dist/api/contract.js +1 -1
  3. package/dist/api/error-codes.d.ts +5 -0
  4. package/dist/api/error-codes.js +1 -1
  5. package/dist/builtin-memory/crouter-sdk/release-notes.md +4 -0
  6. package/dist/builtin-memory/internal/nodes-and-canvas.md +1 -1
  7. package/dist/builtin-memory/internal/storage-tiers.md +1 -1
  8. package/dist/cli.js +5 -5
  9. package/dist/clients/attach/config.js +1 -1
  10. package/dist/clients/attach/viewer.js +467 -467
  11. package/dist/commands/api-client.d.ts +0 -5
  12. package/dist/commands/api-client.js +3 -3
  13. package/dist/commands/daemon-generation.js +1 -1
  14. package/dist/commands/sys/import/move.d.ts +1 -34
  15. package/dist/commands/sys/import/move.js +5 -9
  16. package/dist/commands/sys/import/start.d.ts +0 -3
  17. package/dist/commands/sys/import/start.js +1 -1
  18. package/dist/commands/sys/signin.js +2 -2
  19. package/dist/core/canvas/managed-worktree-sweep-candidates.d.ts +2 -0
  20. package/dist/core/canvas/managed-worktree-sweep-candidates.js +6 -4
  21. package/dist/core/command-plugins/caller-header.d.ts +3 -1
  22. package/dist/core/command-plugins/caller-header.js +1 -1
  23. package/dist/core/command.d.ts +1 -1
  24. package/dist/core/grants/owner.d.ts +2 -0
  25. package/dist/core/grants/owner.js +1 -1
  26. package/dist/core/graph/reader.d.ts +5 -0
  27. package/dist/core/graph/reader.js +3 -3
  28. package/dist/core/graph/types.d.ts +2 -0
  29. package/dist/core/permissions/evaluator.js +2 -2
  30. package/dist/core/providers/call.js +1 -1
  31. package/dist/core/providers/errors.js +1 -1
  32. package/dist/core/providers/mint.d.ts +19 -0
  33. package/dist/core/providers/mint.js +1 -1
  34. package/dist/core/runtime/front-door.js +9 -10
  35. package/dist/core/user-settings.d.ts +2 -2
  36. package/dist/core/worktree-mutation-async.js +5 -5
  37. package/dist/core/worktree-scripts.d.ts +13 -0
  38. package/dist/core/worktree-scripts.js +5 -0
  39. package/dist/core/worktree-sweep.js +4 -4
  40. package/dist/daemon/api/handlers/daemon.js +1 -1
  41. package/dist/daemon/api/handlers/memory.js +5 -5
  42. package/dist/daemon/api/handlers/plugin-app-token.js +1 -1
  43. package/dist/daemon/api/reader.d.ts +1 -1
  44. package/dist/daemon/api/reader.js +1 -1
  45. package/dist/daemon/crtrd.js +11 -11
  46. package/dist/daemon/import-dump-run.js +4 -4
  47. package/dist/daemon/machine-daemon.js +1 -1
  48. package/dist/daemon/machine-link/config.d.ts +0 -24
  49. package/dist/daemon/machine-link/config.js +4 -4
  50. package/dist/daemon/manage.d.ts +1 -1
  51. package/docs/sdk/release-notes.md +4 -0
  52. package/package.json +3 -3
  53. package/packages/crouter-api/dist/api/contract.js +1 -1
  54. package/packages/crouter-api/dist/api/error-codes.js +2 -0
  55. package/packages/crouter-api/dist/clients/attach/config.js +2 -1
  56. package/packages/crouter-api/dist/commands/api-client.js +1 -12
  57. package/packages/crouter-api/dist/commands/sys/import/move.js +5 -205
  58. package/packages/crouter-api/dist/commands/sys/import/start.js +15 -51
  59. package/packages/crouter-api/dist/commands/sys/signin.js +13 -54
  60. package/packages/crouter-api/dist/core/command-plugins/caller-header.js +2 -2
  61. package/packages/crouter-api/dist/core/grants/owner.js +6 -0
  62. package/packages/crouter-api/dist/core/graph/reader.js +15 -1
  63. package/packages/crouter-api/dist/core/permissions/evaluator.js +2 -0
  64. package/packages/crouter-api/dist/core/providers/call.js +11 -5
  65. package/packages/crouter-api/dist/core/providers/errors.js +1 -0
  66. package/packages/crouter-api/dist/core/providers/mint.js +58 -29
  67. package/packages/crouter-api/dist/core/worktree-mutation-async.js +11 -3
  68. package/packages/crouter-api/dist/core/worktree-scripts.js +72 -0
  69. package/packages/crouter-api/dist/core/worktree-sweep.js +10 -1
  70. package/packages/crouter-api/dist/daemon/api/reader.js +10 -2
  71. package/packages/crouter-api/dist/daemon/machine-link/config.js +1 -27
  72. package/packages/crouter-api/package.json +1 -1
  73. package/packages/crouter-identity/package.json +1 -1
  74. package/packages/crouter-plugin/package.json +3 -3
  75. package/runtime.lock.json +14 -14
  76. package/dist/commands/sys/import/retry.d.ts +0 -1
  77. package/dist/commands/sys/import/retry.js +0 -1
  78. package/dist/daemon/machine-link/move-notify.d.ts +0 -4
  79. package/dist/daemon/machine-link/move-notify.js +0 -1
  80. package/packages/crouter-api/dist/commands/sys/import/retry.js +0 -38
  81. package/packages/crouter-api/dist/daemon/machine-link/move-notify.js +0 -15
@@ -1,5 +1,5 @@
1
1
  /** The contract level this build serves and requires. Written by `scripts/contract.mjs release`; never edit by hand. */
2
- export declare const CONTRACT_LEVEL = "1.80";
2
+ export declare const CONTRACT_LEVEL = "1.81";
3
3
  /** Request header naming the one contract level the caller needs, e.g. `1.3`. Optional: absent means no check. */
4
4
  export declare const REQUIRED_CONTRACT_HEADER = "Crouter-Required-Contract";
5
5
  /** Response header listing the contract levels the server serves, comma-separated, one per major, e.g. `1.3`. */
@@ -1 +1 @@
1
- var c=Object.defineProperty;var e=(r,t)=>c(r,"name",{value:t,configurable:!0});const f="1.80",i="Crouter-Required-Contract",p="Crouter-Contract";function l(r){const t=/^(\d+)\.(\d+)$/.exec(r.trim());return t===null?null:{major:Number(t[1]),minor:Number(t[2])}}e(l,"parseContractLevel");function a(r){return r==null?[]:r.split(",").map(t=>l(t)).filter(t=>t!==null)}e(a,"parseServedContracts");function s(r,t){const n=l(r);return n===null?!1:(typeof t=="string"||t===null||t===void 0?a(t):t).some(u=>u.major===n.major&&u.minor>=n.minor)}e(s,"contractSatisfies");function C(r,t,n={}){if(r===void 0)return null;if(l(r)===null)return{status:400,code:"invalid_request",param:i,message:`${i} must be a contract level like 1.0.`};if(s(r,t))return null;const o=r.trim();return{status:426,code:"runtime_version_unsupported",message:t===null||a(t).length===0?`The runtime did not name its contract level; the caller requires contract ${o} or later. Roll the runtime forward.`:`The runtime serves contract ${t}; the caller requires contract ${o} or later within the same major. Roll the runtime forward, or pin an SDK whose crouterContract the runtime serves.`,details:{sdk_version:(n.legacyMinimum??"").trim(),runtime_version:n.runtimeVersion??null,required_contract:o,runtime_contract:t}}}e(C,"contractRefusal");export{p as CONTRACT_HEADER,f as CONTRACT_LEVEL,i as REQUIRED_CONTRACT_HEADER,C as contractRefusal,s as contractSatisfies,l as parseContractLevel,a as parseServedContracts};
1
+ var c=Object.defineProperty;var e=(r,t)=>c(r,"name",{value:t,configurable:!0});const f="1.81",i="Crouter-Required-Contract",p="Crouter-Contract";function l(r){const t=/^(\d+)\.(\d+)$/.exec(r.trim());return t===null?null:{major:Number(t[1]),minor:Number(t[2])}}e(l,"parseContractLevel");function a(r){return r==null?[]:r.split(",").map(t=>l(t)).filter(t=>t!==null)}e(a,"parseServedContracts");function s(r,t){const n=l(r);return n===null?!1:(typeof t=="string"||t===null||t===void 0?a(t):t).some(u=>u.major===n.major&&u.minor>=n.minor)}e(s,"contractSatisfies");function C(r,t,n={}){if(r===void 0)return null;if(l(r)===null)return{status:400,code:"invalid_request",param:i,message:`${i} must be a contract level like 1.0.`};if(s(r,t))return null;const o=r.trim();return{status:426,code:"runtime_version_unsupported",message:t===null||a(t).length===0?`The runtime did not name its contract level; the caller requires contract ${o} or later. Roll the runtime forward.`:`The runtime serves contract ${t}; the caller requires contract ${o} or later within the same major. Roll the runtime forward, or pin an SDK whose crouterContract the runtime serves.`,details:{sdk_version:(n.legacyMinimum??"").trim(),runtime_version:n.runtimeVersion??null,required_contract:o,runtime_contract:t}}}e(C,"contractRefusal");export{p as CONTRACT_HEADER,f as CONTRACT_LEVEL,i as REQUIRED_CONTRACT_HEADER,C as contractRefusal,s as contractSatisfies,l as parseContractLevel,a as parseServedContracts};
@@ -39,6 +39,11 @@ export declare const errorCodes: {
39
39
  readonly status: 403;
40
40
  readonly retryable: false;
41
41
  };
42
+ readonly not_granted: {
43
+ readonly type: "permission_error";
44
+ readonly status: 403;
45
+ readonly retryable: false;
46
+ };
42
47
  readonly owner_only: {
43
48
  readonly type: "permission_error";
44
49
  readonly status: 403;
@@ -1 +1 @@
1
- const e={unauthorized:{type:"authentication_error",status:401,retryable:!1},machine_revoked:{type:"authentication_error",status:401,retryable:!1},grant_revoked:{type:"authentication_error",status:401,retryable:!1},grant_removed:{type:"authentication_error",status:401,retryable:!1},grant_suspended:{type:"authentication_error",status:401,retryable:!1},refresh_token_expired:{type:"authentication_error",status:401,retryable:!1},refresh_token_reused:{type:"authentication_error",status:401,retryable:!1},scope_missing:{type:"permission_error",status:403,retryable:!1},owner_only:{type:"permission_error",status:403,retryable:!1},other_app_run:{type:"permission_error",status:403,retryable:!1},payer_not_app:{type:"permission_error",status:403,retryable:!1},approval_pending:{type:"permission_error",status:403,retryable:!1},user_denied:{type:"permission_error",status:403,retryable:!1},provider_refused:{type:"permission_error",status:403,retryable:!1},provider_not_connected:{type:"permission_error",status:403,retryable:!1},provider_setup_pending:{type:"permission_error",status:403,retryable:!1},question_pages_off:{type:"permission_error",status:403,retryable:!1},unsandboxed_machine:{type:"permission_error",status:403,retryable:!1},app_not_granted:{type:"permission_error",status:403,retryable:!1},isolated_run:{type:"permission_error",status:403,retryable:!1},provider_version_retired:{type:"permission_error",status:403,retryable:!1},invalid_scope:{type:"invalid_request_error",status:400,retryable:!1},invalid_request:{type:"invalid_request_error",status:400,retryable:!1},range_not_satisfiable:{type:"invalid_request_error",status:416,retryable:!1},not_here:{type:"invalid_request_error",status:404,retryable:!1},peer_version_too_old:{type:"invalid_request_error",status:426,retryable:!1},conflict:{type:"invalid_request_error",status:409,retryable:!1},model_sign_in_required:{type:"invalid_request_error",status:409,retryable:!1},invalid_argument:{type:"invalid_request_error",status:400,retryable:!1},machine_required:{type:"invalid_request_error",status:409,retryable:!1},device_offline:{type:"server_error",status:503,retryable:!0},device_timeout:{type:"server_error",status:504,retryable:!0},device_disconnected:{type:"server_error",status:503,retryable:!1},not_found:{type:"invalid_request_error",status:404,retryable:!1},model_unavailable:{type:"invalid_request_error",status:404,retryable:!1},upstream_model_unavailable:{type:"server_error",status:503,retryable:!0},substitution_refused:{type:"invalid_request_error",status:400,retryable:!1},idempotency_conflict:{type:"invalid_request_error",status:409,retryable:!1},run_settled:{type:"invalid_request_error",status:409,retryable:!1},cap_exhausted:{type:"rate_limit_error",status:402,retryable:!1},payment_refused:{type:"invalid_request_error",status:402,retryable:!1},concurrency_limit:{type:"rate_limit_error",status:429,retryable:!0},all_routes_exhausted:{type:"rate_limit_error",status:429,retryable:!0},provider_rate_limited:{type:"rate_limit_error",status:429,retryable:!0},rate_limited:{type:"rate_limit_error",status:429,retryable:!0},busy:{type:"rate_limit_error",status:429,retryable:!0},northlight_unreachable:{type:"server_error",status:503,retryable:!0},runtime_unreachable:{type:"server_error",status:503,retryable:!0},isolated_unavailable:{type:"server_error",status:503,retryable:!0},sandbox_unavailable:{type:"server_error",status:503,retryable:!1},runtime_starting:{type:"server_error",status:503,retryable:!0},runtime_provisioning:{type:"server_error",status:503,retryable:!0},provider_unavailable:{type:"server_error",status:503,retryable:!0},upstream_refused:{type:"server_error",status:502,retryable:!1},provider_bad_response:{type:"server_error",status:502,retryable:!1},service_unavailable:{type:"server_error",status:503,retryable:!0},not_implemented:{type:"server_error",status:501,retryable:!1},permission_error:{type:"permission_error",status:403,retryable:!1},storage_unavailable:{type:"server_error",status:503,retryable:!0},server_error:{type:"server_error",status:500,retryable:!0},server_failure:{type:"server_error",status:500,retryable:!1},wake_timeout:{type:"server_error",status:504,retryable:!0}};export{e as errorCodes};
1
+ const e={unauthorized:{type:"authentication_error",status:401,retryable:!1},machine_revoked:{type:"authentication_error",status:401,retryable:!1},grant_revoked:{type:"authentication_error",status:401,retryable:!1},grant_removed:{type:"authentication_error",status:401,retryable:!1},grant_suspended:{type:"authentication_error",status:401,retryable:!1},refresh_token_expired:{type:"authentication_error",status:401,retryable:!1},refresh_token_reused:{type:"authentication_error",status:401,retryable:!1},scope_missing:{type:"permission_error",status:403,retryable:!1},not_granted:{type:"permission_error",status:403,retryable:!1},owner_only:{type:"permission_error",status:403,retryable:!1},other_app_run:{type:"permission_error",status:403,retryable:!1},payer_not_app:{type:"permission_error",status:403,retryable:!1},approval_pending:{type:"permission_error",status:403,retryable:!1},user_denied:{type:"permission_error",status:403,retryable:!1},provider_refused:{type:"permission_error",status:403,retryable:!1},provider_not_connected:{type:"permission_error",status:403,retryable:!1},provider_setup_pending:{type:"permission_error",status:403,retryable:!1},question_pages_off:{type:"permission_error",status:403,retryable:!1},unsandboxed_machine:{type:"permission_error",status:403,retryable:!1},app_not_granted:{type:"permission_error",status:403,retryable:!1},isolated_run:{type:"permission_error",status:403,retryable:!1},provider_version_retired:{type:"permission_error",status:403,retryable:!1},invalid_scope:{type:"invalid_request_error",status:400,retryable:!1},invalid_request:{type:"invalid_request_error",status:400,retryable:!1},range_not_satisfiable:{type:"invalid_request_error",status:416,retryable:!1},not_here:{type:"invalid_request_error",status:404,retryable:!1},peer_version_too_old:{type:"invalid_request_error",status:426,retryable:!1},conflict:{type:"invalid_request_error",status:409,retryable:!1},model_sign_in_required:{type:"invalid_request_error",status:409,retryable:!1},invalid_argument:{type:"invalid_request_error",status:400,retryable:!1},machine_required:{type:"invalid_request_error",status:409,retryable:!1},device_offline:{type:"server_error",status:503,retryable:!0},device_timeout:{type:"server_error",status:504,retryable:!0},device_disconnected:{type:"server_error",status:503,retryable:!1},not_found:{type:"invalid_request_error",status:404,retryable:!1},model_unavailable:{type:"invalid_request_error",status:404,retryable:!1},upstream_model_unavailable:{type:"server_error",status:503,retryable:!0},substitution_refused:{type:"invalid_request_error",status:400,retryable:!1},idempotency_conflict:{type:"invalid_request_error",status:409,retryable:!1},run_settled:{type:"invalid_request_error",status:409,retryable:!1},cap_exhausted:{type:"rate_limit_error",status:402,retryable:!1},payment_refused:{type:"invalid_request_error",status:402,retryable:!1},concurrency_limit:{type:"rate_limit_error",status:429,retryable:!0},all_routes_exhausted:{type:"rate_limit_error",status:429,retryable:!0},provider_rate_limited:{type:"rate_limit_error",status:429,retryable:!0},rate_limited:{type:"rate_limit_error",status:429,retryable:!0},busy:{type:"rate_limit_error",status:429,retryable:!0},northlight_unreachable:{type:"server_error",status:503,retryable:!0},runtime_unreachable:{type:"server_error",status:503,retryable:!0},isolated_unavailable:{type:"server_error",status:503,retryable:!0},sandbox_unavailable:{type:"server_error",status:503,retryable:!1},runtime_starting:{type:"server_error",status:503,retryable:!0},runtime_provisioning:{type:"server_error",status:503,retryable:!0},provider_unavailable:{type:"server_error",status:503,retryable:!0},upstream_refused:{type:"server_error",status:502,retryable:!1},provider_bad_response:{type:"server_error",status:502,retryable:!1},service_unavailable:{type:"server_error",status:503,retryable:!0},not_implemented:{type:"server_error",status:501,retryable:!1},permission_error:{type:"permission_error",status:403,retryable:!1},storage_unavailable:{type:"server_error",status:503,retryable:!0},server_error:{type:"server_error",status:500,retryable:!0},server_failure:{type:"server_error",status:500,retryable:!1},wake_timeout:{type:"server_error",status:504,retryable:!0}};export{e as errorCodes};
@@ -15,6 +15,10 @@ Changes to `@north-light/sdk` that can change what an existing app sees. Newest
15
15
 
16
16
  `grant.get().resolved_scopes` may contain `<provider>:*` (for example `integrations:*`) in place of one entry per group. It means every group of that provider the grant may hold. Check a scope with the new `holds(resolved_scopes, scope)` export instead of comparing strings, because `integrations:gmail` is held while only `integrations:*` is listed. The directory sends this form only to a runtime that understands it.
17
17
 
18
+ ### `--as` acts for another principal
19
+
20
+ A node's provider call, plugin call and memory or object read can name `as`. From a node whose app namespace differs from `as`, crtrd exchanges the node's call token at the directory; the call runs with subject `as`, the node's app as grantee and actor. Reads cover only what the grant from `as` holds. A refusal is 403 `not_granted` (no grant from `as`) or `scope_missing`. `as` inside the node's own namespace needs no grant.
21
+
18
22
  ## 0.3.755
19
23
 
20
24
  ### An app can start runs in its own environment with no person
@@ -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};