@north-light/cli 0.3.580 → 0.3.582

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 (237) hide show
  1. package/dist/api/client.d.ts +6 -1
  2. package/dist/api/client.js +3 -3
  3. package/dist/api/contract.d.ts +1 -1
  4. package/dist/api/contract.js +1 -1
  5. package/dist/api/dto/execution-start.d.ts +14 -0
  6. package/dist/api/dto/health.d.ts +22 -0
  7. package/dist/api/dto/imports.d.ts +142 -0
  8. package/dist/api/dto/imports.js +0 -0
  9. package/dist/api/error-codes.d.ts +5 -0
  10. package/dist/api/error-codes.js +1 -1
  11. package/dist/api/errors.js +1 -1
  12. package/dist/api/index.d.ts +1 -0
  13. package/dist/api/index.js +1 -1
  14. package/dist/api/routes.d.ts +2 -0
  15. package/dist/api/routes.js +1 -1
  16. package/dist/build-root.d.ts +11 -4
  17. package/dist/build-root.js +1 -1
  18. package/dist/cli.js +7 -7
  19. package/dist/clients/attach/session/connection.d.ts +3 -1
  20. package/dist/clients/attach/session/connection.js +1 -1
  21. package/dist/clients/attach/viewer.js +529 -529
  22. package/dist/commands/api-client.d.ts +12 -4
  23. package/dist/commands/api-client.js +3 -3
  24. package/dist/commands/sys/daemon.js +1 -1
  25. package/dist/commands/sys/desktop.d.ts +5 -0
  26. package/dist/commands/sys/desktop.js +1 -0
  27. package/dist/commands/sys/import/move.d.ts +55 -0
  28. package/dist/commands/sys/import/move.js +8 -0
  29. package/dist/commands/sys/import/resume.d.ts +1 -0
  30. package/dist/commands/sys/import/resume.js +1 -0
  31. package/dist/commands/sys/import/start.d.ts +4 -0
  32. package/dist/commands/sys/import/start.js +1 -0
  33. package/dist/commands/sys/join.d.ts +2 -0
  34. package/dist/commands/sys/join.js +1 -1
  35. package/dist/commands/sys/machine/rotate.d.ts +1 -0
  36. package/dist/commands/sys/machine/rotate.js +1 -0
  37. package/dist/commands/sys/signin.d.ts +7 -0
  38. package/dist/commands/sys/signin.js +2 -0
  39. package/dist/commands/sys.js +1 -1
  40. package/dist/core/blobs/r2.d.ts +4 -0
  41. package/dist/core/blobs/r2.js +7 -4
  42. package/dist/core/canvas/daemon-owner.d.ts +1 -1
  43. package/dist/core/canvas/executions.d.ts +1 -1
  44. package/dist/core/canvas/node-tokens.d.ts +2 -0
  45. package/dist/core/canvas/node-tokens.js +3 -3
  46. package/dist/core/canvas/pid.d.ts +6 -0
  47. package/dist/core/canvas/pid.js +5 -5
  48. package/dist/core/command-plugins/compose.js +1 -1
  49. package/dist/core/command.d.ts +17 -8
  50. package/dist/core/command.js +9 -9
  51. package/dist/core/directory/issuer.d.ts +3 -0
  52. package/dist/core/directory/issuer.js +1 -1
  53. package/dist/core/directory/person-credential.d.ts +61 -0
  54. package/dist/core/directory/person-credential.js +1 -0
  55. package/dist/core/directory/reach.d.ts +3 -0
  56. package/dist/core/directory/reach.js +1 -0
  57. package/dist/core/grants/mirror.d.ts +3 -0
  58. package/dist/core/grants/mirror.js +2 -2
  59. package/dist/core/graph/bodies-boot-copy.d.ts +16 -2
  60. package/dist/core/graph/bodies-boot-copy.js +1 -1
  61. package/dist/core/graph/bodies.d.ts +13 -4
  62. package/dist/core/graph/bodies.js +1 -1
  63. package/dist/core/graph/deletion.d.ts +4 -1
  64. package/dist/core/graph/deletion.js +3 -3
  65. package/dist/core/graph/documents.d.ts +4 -0
  66. package/dist/core/graph/documents.js +9 -9
  67. package/dist/core/graph/reader.js +2 -2
  68. package/dist/core/graph/repo-sync/exchange.js +2 -2
  69. package/dist/core/graph/repo-sync/ref-format.d.ts +7 -2
  70. package/dist/core/graph/repo-sync/ref-format.js +2 -2
  71. package/dist/core/import/bundle/blob-keys.d.ts +10 -0
  72. package/dist/core/import/bundle/blob-keys.js +1 -0
  73. package/dist/core/import/bundle/layout.d.ts +90 -0
  74. package/dist/core/import/bundle/layout.js +5 -0
  75. package/dist/core/import/export/archive.d.ts +11 -0
  76. package/dist/core/import/export/archive.js +1 -0
  77. package/dist/core/import/export/cloud.d.ts +23 -0
  78. package/dist/core/import/export/cloud.js +1 -0
  79. package/dist/core/import/export/dump.d.ts +34 -0
  80. package/dist/core/import/export/dump.js +3 -0
  81. package/dist/core/import/export/files.d.ts +22 -0
  82. package/dist/core/import/export/files.js +1 -0
  83. package/dist/core/import/export/inline.d.ts +3 -0
  84. package/dist/core/import/export/inline.js +1 -0
  85. package/dist/core/import/export/source.d.ts +2 -0
  86. package/dist/core/import/export/source.js +1 -0
  87. package/dist/core/import/export/stores.d.ts +9 -0
  88. package/dist/core/import/export/stores.js +1 -0
  89. package/dist/core/import/load/bind.d.ts +19 -0
  90. package/dist/core/import/load/bind.js +15 -0
  91. package/dist/core/import/load/blobs.d.ts +10 -0
  92. package/dist/core/import/load/blobs.js +1 -0
  93. package/dist/core/import/load/catalog.d.ts +32 -0
  94. package/dist/core/import/load/catalog.js +9 -0
  95. package/dist/core/import/load/copy.d.ts +26 -0
  96. package/dist/core/import/load/copy.js +6 -0
  97. package/dist/core/import/load/path-map.d.ts +7 -0
  98. package/dist/core/import/load/path-map.js +1 -0
  99. package/dist/core/import/load/prepare.d.ts +37 -0
  100. package/dist/core/import/load/prepare.js +10 -0
  101. package/dist/core/import/load/rewrite.d.ts +39 -0
  102. package/dist/core/import/load/rewrite.js +13 -0
  103. package/dist/core/import/load/rollback.d.ts +3 -0
  104. package/dist/core/import/load/rollback.js +6 -0
  105. package/dist/core/import/load/run.d.ts +22 -0
  106. package/dist/core/import/load/run.js +3 -0
  107. package/dist/core/import/load/stage.d.ts +15 -0
  108. package/dist/core/import/load/stage.js +1 -0
  109. package/dist/core/import/load/stores.d.ts +24 -0
  110. package/dist/core/import/load/stores.js +2 -0
  111. package/dist/core/import/load/verify.d.ts +4 -0
  112. package/dist/core/import/load/verify.js +12 -0
  113. package/dist/core/io.js +4 -4
  114. package/dist/core/northlight/previews.d.ts +22 -0
  115. package/dist/core/northlight/previews.js +1 -0
  116. package/dist/core/providers/call.js +1 -1
  117. package/dist/core/providers/device.js +1 -1
  118. package/dist/core/providers/files.d.ts +2 -1
  119. package/dist/core/providers/files.js +1 -1
  120. package/dist/core/runtime/broker/cli-relay.js +1 -1
  121. package/dist/core/runtime/broker/model-adapter.js +3 -3
  122. package/dist/core/runtime/broker-ownership.d.ts +1 -0
  123. package/dist/core/runtime/broker-ownership.js +1 -0
  124. package/dist/core/runtime/broker.js +1 -1
  125. package/dist/core/runtime/first-run-offer.d.ts +7 -2
  126. package/dist/core/runtime/first-run-offer.js +10 -2
  127. package/dist/core/runtime/front-door.js +4 -4
  128. package/dist/core/runtime/revive.d.ts +5 -2
  129. package/dist/core/runtime/revive.js +2 -2
  130. package/dist/core/runtime/runner/blaxel/runner.js +3 -3
  131. package/dist/core/runtime/runner/index.d.ts +1 -0
  132. package/dist/core/runtime/runner/index.js +1 -1
  133. package/dist/core/runtime/runner/machine/call.d.ts +8 -0
  134. package/dist/core/runtime/runner/machine/call.js +3 -0
  135. package/dist/core/runtime/runner/machine/environment.d.ts +1 -0
  136. package/dist/core/runtime/runner/machine/environment.js +1 -0
  137. package/dist/core/runtime/runner/machine/executor.d.ts +29 -0
  138. package/dist/core/runtime/runner/machine/executor.js +1 -0
  139. package/dist/core/runtime/runner/machine/machine-executor.test.d.ts +1 -0
  140. package/dist/core/runtime/runner/machine/machine-executor.test.js +4 -0
  141. package/dist/core/runtime/runner/machine/ops.d.ts +127 -0
  142. package/dist/core/runtime/runner/machine/ops.js +1 -0
  143. package/dist/core/runtime/runner/machine/runner.d.ts +12 -0
  144. package/dist/core/runtime/runner/machine/runner.js +1 -0
  145. package/dist/core/runtime/runner/types.d.ts +7 -1
  146. package/dist/core/runtime/warm-pool.d.ts +2 -0
  147. package/dist/core/runtime/warm-pool.js +1 -1
  148. package/dist/core/secrets/env-rows.d.ts +1 -0
  149. package/dist/core/secrets/env-rows.js +1 -1
  150. package/dist/core/storage/purge.d.ts +6 -0
  151. package/dist/core/storage/purge.js +4 -0
  152. package/dist/core/subscription-state.d.ts +1 -0
  153. package/dist/core/subscription-state.js +1 -1
  154. package/dist/daemon/api/bridge.js +3 -3
  155. package/dist/daemon/api/handlers/attach.js +1 -1
  156. package/dist/daemon/api/handlers/crons.js +1 -1
  157. package/dist/daemon/api/handlers/daemon.js +1 -1
  158. package/dist/daemon/api/handlers/execution-start.js +2 -2
  159. package/dist/daemon/api/handlers/files.js +1 -1
  160. package/dist/daemon/api/handlers/imports.d.ts +2 -0
  161. package/dist/daemon/api/handlers/imports.js +1 -0
  162. package/dist/daemon/api/handlers/machine-credential.d.ts +2 -0
  163. package/dist/daemon/api/handlers/machine-credential.js +1 -0
  164. package/dist/daemon/api/handlers/profiles.js +1 -1
  165. package/dist/daemon/api/handlers/providers.js +1 -1
  166. package/dist/daemon/api/handlers/runs.js +1 -1
  167. package/dist/daemon/api/import-auth.d.ts +6 -0
  168. package/dist/daemon/api/import-auth.js +1 -0
  169. package/dist/daemon/api/operations.d.ts +2 -2
  170. package/dist/daemon/api/operations.js +1 -1
  171. package/dist/daemon/api/router.d.ts +7 -1
  172. package/dist/daemon/api/router.js +1 -1
  173. package/dist/daemon/api/server.js +1 -1
  174. package/dist/daemon/boot-migrations.js +1 -1
  175. package/dist/daemon/broker-signals/bus.d.ts +3 -2
  176. package/dist/daemon/broker-signals/bus.js +1 -1
  177. package/dist/daemon/cron/armed-context.d.ts +1 -0
  178. package/dist/daemon/cron/armed-context.js +1 -1
  179. package/dist/daemon/cron/closed.d.ts +31 -0
  180. package/dist/daemon/cron/closed.js +1 -0
  181. package/dist/daemon/cron/ended.js +2 -2
  182. package/dist/daemon/cron/lease-recovery.js +1 -1
  183. package/dist/daemon/cron/machine-exec.d.ts +11 -0
  184. package/dist/daemon/cron/machine-exec.js +1 -0
  185. package/dist/daemon/cron/machine-fire.d.ts +26 -0
  186. package/dist/daemon/cron/machine-fire.js +1 -0
  187. package/dist/daemon/cron/recurrence.d.ts +14 -0
  188. package/dist/daemon/cron/recurrence.js +1 -0
  189. package/dist/daemon/cron/run-token.d.ts +7 -0
  190. package/dist/daemon/cron/run-token.js +1 -0
  191. package/dist/daemon/cron-run.js +2 -2
  192. package/dist/daemon/crtrd-cli.js +1 -1
  193. package/dist/daemon/crtrd.d.ts +3 -3
  194. package/dist/daemon/crtrd.js +14 -14
  195. package/dist/daemon/drain.d.ts +25 -0
  196. package/dist/daemon/drain.js +9 -0
  197. package/dist/daemon/due-sources.d.ts +1 -1
  198. package/dist/daemon/due-sources.js +1 -1
  199. package/dist/daemon/due.js +8 -8
  200. package/dist/daemon/fleet.js +5 -5
  201. package/dist/daemon/import-dump-run.d.ts +1 -0
  202. package/dist/daemon/import-dump-run.js +5 -0
  203. package/dist/daemon/machine-daemon.d.ts +10 -0
  204. package/dist/daemon/machine-daemon.js +1 -0
  205. package/dist/daemon/machine-link/client.d.ts +29 -0
  206. package/dist/daemon/machine-link/client.js +1 -0
  207. package/dist/daemon/machine-link/config.d.ts +45 -0
  208. package/dist/daemon/machine-link/config.js +3 -0
  209. package/dist/daemon/machine-link/credential.d.ts +7 -0
  210. package/dist/daemon/machine-link/credential.js +2 -0
  211. package/dist/daemon/machine-link/forward.d.ts +16 -0
  212. package/dist/daemon/machine-link/forward.js +1 -0
  213. package/dist/daemon/machine-link/frames.d.ts +49 -0
  214. package/dist/daemon/machine-link/frames.js +1 -0
  215. package/dist/daemon/machine-link/holder.d.ts +73 -0
  216. package/dist/daemon/machine-link/holder.js +9 -0
  217. package/dist/daemon/machine-link/move-notify.d.ts +4 -0
  218. package/dist/daemon/machine-link/move-notify.js +1 -0
  219. package/dist/daemon/manage.d.ts +19 -3
  220. package/dist/daemon/manage.js +3 -3
  221. package/dist/daemon/reconcilers/cron-lane.js +1 -1
  222. package/dist/daemon/reconcilers/delivery-lane.js +2 -2
  223. package/dist/daemon/reconcilers/import-lane.d.ts +9 -0
  224. package/dist/daemon/reconcilers/import-lane.js +1 -0
  225. package/dist/daemon/reconcilers/node-lifecycle/freeze-lane.js +1 -1
  226. package/dist/daemon/reconcilers/node-lifecycle/remote-wake.d.ts +3 -0
  227. package/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +1 -1
  228. package/dist/daemon/reconcilers/node-lifecycle/tick.js +1 -1
  229. package/dist/daemon/reconcilers/purge-due-work.d.ts +13 -0
  230. package/dist/daemon/reconcilers/purge-due-work.js +1 -0
  231. package/dist/daemon/reconcilers/row-claim.d.ts +1 -0
  232. package/dist/daemon/reconcilers/row-claim.js +2 -2
  233. package/dist/daemon/runs/observer.js +3 -3
  234. package/package.json +2 -2
  235. package/packages/crouter-identity/package.json +1 -1
  236. package/runtime.lock.json +13 -13
  237. package/scripts/sandbox-start.mjs +185 -2
@@ -22,6 +22,8 @@ export declare function declaredExtensibleCoreBranches(): Promise<ReadonlySet<st
22
22
  export declare function personOnlyInvocation(argv: readonly string[]): string | null;
23
23
  /** Select a smaller canonical tree; `runCli` still parses, renders help, and reports errors. */
24
24
  export declare function isDaemonControlInvocation(argv: readonly string[]): boolean;
25
+ /** `sys signin` and `sys signout` run when the stored sign-in is gone or a move is unfinished, the states in which the settings load would refuse. */
26
+ export declare function isSignInInvocation(argv: readonly string[]): boolean;
25
27
  export declare function isJoinInvocation(argv: readonly string[]): boolean;
26
28
  export declare function isLayoutMigrationInvocation(argv: readonly string[]): boolean;
27
29
  /** Assemble the canonical daemon-control definitions without loading settings or plugin discovery. This path exists so `crtr sys daemon restart` can start the new generation that converts pre-SQL user state. */
@@ -52,8 +54,13 @@ export declare function resolveCoreRoot(first: string): Promise<RootDef | null>;
52
54
  *
53
55
  * Order is deterministic: core subtrees in declared order first, then accepted
54
56
  * external branches sorted by contributor name (from the unified snapshot).
55
- * Composition is invocation-local and reads only stored manifest bytes — no
56
- * cache, no persistence, ZERO network — so a plugin enable/update/remove or an
57
- * HTTP-transport plugin manifest replacement takes effect on the next invocation
58
- * automatically. Composition performs no network I/O. */
57
+ * Composition is invocation-local — no cache, no persistence — and reads only
58
+ * stored manifest bytes, so a plugin enable/update/remove or an HTTP-transport
59
+ * plugin manifest replacement takes effect on the next invocation automatically.
60
+ * The one network read is the granted provider catalog (`GET /v1/providers/tools`)
61
+ * that a sandboxed node, a fleet node and a moved computer ask their control plane
62
+ * or daemon for. On a moved computer a failed read does not abort the tree: the
63
+ * tree is built from what is known locally and the failure rides on the root
64
+ * (`providerCatalogFailure`), which the dispatcher raises in place of
65
+ * `unknown_path` when the person types a top-level name the tree lacks. */
59
66
  export declare function buildRoot(): Promise<RootDef>;
@@ -1 +1 @@
1
- var I=Object.defineProperty;var n=(e,t)=>I(e,"name",{value:t,configurable:!0});import{defineBranch as D,defineRoot as y,GLOBAL_TOKENS as R}from"./core/command.js";import{createCoreHookCatalog as x}from"./core/command-hooks/catalog.js";import{composeCoreHooks as B}from"./core/command-hooks/compose.js";import{mark as p}from"./core/timing.js";import{envNodeId as G,envScopes as U,isSandboxedNode as E,providerProjectionOverBrokerRelay as q,scopeAllowed as z}from"./shared/env.js";const S="crtr: agentic runtime.",b=[{name:"--json",desc:"stdout as the leaf's declared outputs in raw JSON instead of prose \u2014 for scripts (a cron's bash, external tooling) that must branch on canvas state; prose stays the contract for what you read yourself."}],k=Object.assign(Object.create(null),{doc:n(async()=>(await import("./commands/doc.js")).registerDoc(),"doc"),"custom-object":n(async()=>(await import("./commands/custom-object.js")).registerCustomObject(),"custom-object"),profile:n(async()=>(await import("./commands/profile.js")).registerProfile(),"profile"),pkg:n(async()=>(await import("./commands/pkg.js")).registerPkg(),"pkg"),human:n(async()=>(await import("./commands/human.js")).registerHuman(),"human"),sys:n(async()=>(await import("./commands/sys.js")).registerSys(),"sys"),node:n(async()=>(await import("./commands/node.js")).registerNode(),"node"),push:n(async()=>(await import("./commands/push.js")).registerPush(),"push"),cron:n(async()=>(await import("./commands/cron.js")).registerCron(),"cron"),canvas:n(async()=>(await import("./commands/canvas.js")).registerCanvas(),"canvas"),surface:n(async()=>(await import("./commands/surface.js")).registerSurface(),"surface")}),m=Object.freeze(Object.keys(k)),J={human:["crtr:act"],cron:["crtr:schedule"],doc:["crtr:memory:read:user","crtr:memory:rw:user"]};function j(e){const t=U();return t===null?e:e.filter(r=>{const o=J[r.name];return o===void 0||o.some(s=>z(t,s))||r.name==="doc"&&process.env.CRTR_GRANTEE?.startsWith("app:")===!0})}n(j,"allowedSubtrees");const N=new Map;function L(e){let t=N.get(e);return t===void 0&&(t=k[e](),N.set(e,t)),t}n(L,"loadSubtree");function v(e){return Promise.all(m.filter(t=>e.has(t)).map(L))}n(v,"loadCoreSubtreesNamed");function C(){return v(new Set(m))}n(C,"loadCoreSubtrees");function P(e){const t=new Set;for(const r of e){const o=r.split(" ")[0];m.includes(o)&&t.add(o)}return t}n(P,"subtreesNamedBy");let T;function se(){return p("cli.hooks.catalog"),T??=C().then(x),T}n(se,"coreHookCatalog");function _(){let e;return()=>(e??=(async()=>{const{compileHookRegistry:t,declaredCommandHookTargets:r,effectiveHookPlugins:o}=await import("./core/command-hooks/discovery.js"),s=o(),a=E()&&G()!==void 0?await(await import("./core/command-hooks/transport/plan.js")).remoteHookPlan(process.cwd()):[];if(p("cli.hooks.effective_plugins",{count:s.length+a.length}),s.length===0&&a.length===0)return p("cli.hooks.empty_registry"),t(x([]),[]);const c=E()?s.filter(l=>l.scope==="project"):s,i=P([...r(c),...a.map(l=>l.target)]);return p("cli.hooks.catalog",{subtrees:[...i].join(",")}),t(x(await v(i)),c,a)})(),e)}n(_,"hookRegistryLoader");function g(e){const t=new Set,r=n((o,s)=>{if(!(o.kind==="branch"&&o.passthrough!==void 0)&&(t.add(s),o.kind==="branch"))for(const a of o.children)r(a,`${s} ${a.name}`)},"visit");for(const o of e)r(o,o.name);return t}n(g,"commandPathsFor");async function ae(){return g(await C())}n(ae,"coreCommandPaths");async function ie(e){return g(await v(P(e)))}n(ie,"coreCommandPathsCovering");function W(e){const t=[],r=n((o,s)=>{o.extensible===!0&&t.push(s);for(const a of o.children)a.kind==="branch"&&r(a,[...s,a.name])},"visit");for(const o of e)r(o,[o.name]);return t}n(W,"extensibleBranchPaths");const $=Object.freeze(["human","sys tutorial"]);async function A(){return new Set($)}n(A,"extensibleCoreBranches");async function ce(){return new Set(W(await C()).map(e=>e.join(" ")))}n(ce,"declaredExtensibleCoreBranches");function F(e,t){const{listing:r,...o}=e.help;return D({name:e.name,description:e.description,whenToUse:e.whenToUse,tier:e.tier,help:o,rootEntry:e.rootEntry,extensible:e.extensible,plugin:e.plugin,slash:e.slash,passthrough:e.passthrough,children:t})}n(F,"rebuildBranch");async function M(e,t,r){if(t.size===0)return e;const[{buildExternalCommandSnapshot:o},{composeCoreBranchMounts:s}]=await Promise.all([import("./core/command-plugins/discovery.js"),import("./core/command-plugins/compose.js")]),a=o(new Set(m),void 0,void 0,r,t),c=n((i,l)=>{let h=!1;const w=i.children.map(d=>{if(d.kind!=="branch")return d;const u=c(d,[...l,d.name]);return u!==d&&(h=!0),u}),f=i.extensible===!0?s(a.coreMounts,l):[];return h||f.length>0?F(i,[...w,...f]):i},"composeBranch");return e.map(i=>c(i,[i.name]))}n(M,"composeCorePluginMounts");async function K(e,t){const{validateEffectiveCommandPlugins:r}=await import("./core/command-plugins/discovery.js"),s=r(new Set(m),void 0,void 0,void 0,t).flatMap(c=>c.manifest===void 0?[]:[c.manifest]).filter(c=>c.coreMounts.some(i=>i.parent[0]===e));if(s.length===0)return null;const a=P(s.flatMap(c=>[...c.coreMounts.map(i=>i.parent.join(" ")),...Object.keys(c.helpAddenda??{})]));return a.add(e),g(await v(a))}n(K,"dispatchCommandPaths");function O(e,t){const r=e.slice(2).filter(o=>!R.has(o));return r[0]==="sys"&&r[1]===t}n(O,"isSysInvocation");const X=[["surface"],["sys"],["pkg"],["profile","default"],["canvas","chord"],["canvas","config"],["canvas","use"],["canvas","browse"],["canvas","issue"]],Y=[["sys","feedback"]];function H(e,t){return t.every((r,o)=>e[o]===r)}n(H,"startsWithPath");function ue(e){const t=e.slice(2).filter(o=>!R.has(o));if(Y.some(o=>H(t,o)))return null;const r=X.find(o=>H(t,o));return r===void 0?null:r.join(" ")}n(ue,"personOnlyInvocation");function le(e){return O(e,"daemon")}n(le,"isDaemonControlInvocation");function de(e){return O(e,"join")}n(de,"isJoinInvocation");function me(e){return O(e,"migrate")}n(me,"isLayoutMigrationInvocation");async function pe(){const{registerDaemonControlSys:e}=await import("./commands/sys/daemon.js");return y({tagline:S,globals:b,subtrees:[e()]})}n(pe,"resolveDaemonControlRoot");async function fe(){const[{defineSysBranch:e},{sysMigrateLeaf:t}]=await Promise.all([import("./commands/sys/branch.js"),import("./commands/sys/migrate.js")]);return y({tagline:S,globals:b,subtrees:[e([t])]})}n(fe,"resolveLayoutMigrationRoot");async function ge(e){return(e!==void 0?await Q(e):null)??V()}n(ge,"resolveRoot");async function Q(e){if(k[e]===void 0)return null;const t=await L(e),r=await A(),o=[...r].some(a=>a.split(" ")[0]===e)?await K(e,r):null,s=j(o===null?[t]:await M([t],r,o));return s.length>0?y({tagline:S,globals:b,subtrees:B(s,_())}):null}n(Q,"resolveCoreRoot");async function V(){const e=await C(),[{buildExternalCommandSnapshot:t},{composeExternalSubtrees:r,composeSandboxProviderSubtrees:o},{qualifiedTopLevelCommandName:s}]=await Promise.all([import("./core/command-plugins/discovery.js"),import("./core/command-plugins/compose.js"),import("./core/command-manifests/registry.js")]),a=await A(),c=await M(e,a,g(e)),i=t(new Set(m),void 0,void 0,g(e),a);let l=r(i);if(E()||q()){const{cliClient:h}=await import("./commands/api-client.js");p("cli.providers.request");const{providers:w}=await h().request("GET","/v1/providers/tools");p("cli.providers.fetched",{providers:w.length});const f=o(w,new Set(m)),d=new Set(f.map(u=>u.name));l=[...f,...r({...i,contributions:i.contributions.map(u=>d.has(u.node.name)?{...u,node:{...u.node,name:s(u.contributor,u.node.name)}}:u)})]}return y({tagline:S,globals:b,subtrees:[...B(j(c),_()),...l]})}n(V,"buildRoot");export{$ as EXTENSIBLE_CORE_BRANCHES,m as SUBTREE_NAMES,V as buildRoot,ae as coreCommandPaths,ie as coreCommandPathsCovering,se as coreHookCatalog,ce as declaredExtensibleCoreBranches,A as extensibleCoreBranches,le as isDaemonControlInvocation,de as isJoinInvocation,me as isLayoutMigrationInvocation,ue as personOnlyInvocation,Q as resolveCoreRoot,pe as resolveDaemonControlRoot,fe as resolveLayoutMigrationRoot,ge as resolveRoot};
1
+ var U=Object.defineProperty;var n=(e,t)=>U(e,"name",{value:t,configurable:!0});import{defineBranch as q,defineRoot as S,GLOBAL_TOKENS as j}from"./core/command.js";import{createCoreHookCatalog as k}from"./core/command-hooks/catalog.js";import{composeCoreHooks as N}from"./core/command-hooks/compose.js";import{mark as g}from"./core/timing.js";import{ApiError as z}from"./api/errors.js";import{CrtrError as F}from"./core/errors.js";import{envNodeId as J,envScopes as W,isSandboxedNode as P,providerProjectionOverBrokerRelay as $,scopeAllowed as K}from"./shared/env.js";const b="crtr: agentic runtime.",C=[{name:"--json",desc:"stdout as the leaf's declared outputs in raw JSON instead of prose \u2014 for scripts (a cron's bash, external tooling) that must branch on canvas state; prose stays the contract for what you read yourself."}],B=Object.assign(Object.create(null),{doc:n(async()=>(await import("./commands/doc.js")).registerDoc(),"doc"),"custom-object":n(async()=>(await import("./commands/custom-object.js")).registerCustomObject(),"custom-object"),profile:n(async()=>(await import("./commands/profile.js")).registerProfile(),"profile"),pkg:n(async()=>(await import("./commands/pkg.js")).registerPkg(),"pkg"),human:n(async()=>(await import("./commands/human.js")).registerHuman(),"human"),sys:n(async()=>(await import("./commands/sys.js")).registerSys(),"sys"),node:n(async()=>(await import("./commands/node.js")).registerNode(),"node"),push:n(async()=>(await import("./commands/push.js")).registerPush(),"push"),cron:n(async()=>(await import("./commands/cron.js")).registerCron(),"cron"),canvas:n(async()=>(await import("./commands/canvas.js")).registerCanvas(),"canvas"),surface:n(async()=>(await import("./commands/surface.js")).registerSurface(),"surface")}),m=Object.freeze(Object.keys(B)),X={human:["crtr:act"],cron:["crtr:schedule"],doc:["crtr:memory:read:user","crtr:memory:rw:user"]};function L(e){const t=W();return t===null?e:e.filter(r=>{const o=X[r.name];return o===void 0||o.some(s=>K(t,s))||r.name==="doc"&&process.env.CRTR_GRANTEE?.startsWith("app:")===!0})}n(L,"allowedSubtrees");const T=new Map;function A(e){let t=T.get(e);return t===void 0&&(t=B[e](),T.set(e,t)),t}n(A,"loadSubtree");function x(e){return Promise.all(m.filter(t=>e.has(t)).map(A))}n(x,"loadCoreSubtreesNamed");function E(){return x(new Set(m))}n(E,"loadCoreSubtrees");function O(e){const t=new Set;for(const r of e){const o=r.split(" ")[0];m.includes(o)&&t.add(o)}return t}n(O,"subtreesNamedBy");let _;function pe(){return g("cli.hooks.catalog"),_??=E().then(k),_}n(pe,"coreHookCatalog");function M(){let e;return()=>(e??=(async()=>{const{compileHookRegistry:t,declaredCommandHookTargets:r,effectiveHookPlugins:o}=await import("./core/command-hooks/discovery.js"),s=o(),a=P()&&J()!==void 0?await(await import("./core/command-hooks/transport/plan.js")).remoteHookPlan(process.cwd()):[];if(g("cli.hooks.effective_plugins",{count:s.length+a.length}),s.length===0&&a.length===0)return g("cli.hooks.empty_registry"),t(k([]),[]);const c=P()?s.filter(l=>l.scope==="project"):s,i=O([...r(c),...a.map(l=>l.target)]);return g("cli.hooks.catalog",{subtrees:[...i].join(",")}),t(k(await x(i)),c,a)})(),e)}n(M,"hookRegistryLoader");function y(e){const t=new Set,r=n((o,s)=>{if(!(o.kind==="branch"&&o.passthrough!==void 0)&&(t.add(s),o.kind==="branch"))for(const a of o.children)r(a,`${s} ${a.name}`)},"visit");for(const o of e)r(o,o.name);return t}n(y,"commandPathsFor");async function me(){return y(await E())}n(me,"coreCommandPaths");async function fe(e){return y(await x(O(e)))}n(fe,"coreCommandPathsCovering");function Y(e){const t=[],r=n((o,s)=>{o.extensible===!0&&t.push(s);for(const a of o.children)a.kind==="branch"&&r(a,[...s,a.name])},"visit");for(const o of e)r(o,[o.name]);return t}n(Y,"extensibleBranchPaths");const Q=Object.freeze(["human","sys tutorial"]);async function H(){return new Set(Q)}n(H,"extensibleCoreBranches");async function ge(){return new Set(Y(await E()).map(e=>e.join(" ")))}n(ge,"declaredExtensibleCoreBranches");function V(e,t){const{listing:r,...o}=e.help;return q({name:e.name,description:e.description,whenToUse:e.whenToUse,tier:e.tier,help:o,rootEntry:e.rootEntry,extensible:e.extensible,plugin:e.plugin,slash:e.slash,passthrough:e.passthrough,children:t})}n(V,"rebuildBranch");async function I(e,t,r){if(t.size===0)return e;const[{buildExternalCommandSnapshot:o},{composeCoreBranchMounts:s}]=await Promise.all([import("./core/command-plugins/discovery.js"),import("./core/command-plugins/compose.js")]),a=o(new Set(m),void 0,void 0,r,t),c=n((i,l)=>{let f=!1;const h=i.children.map(d=>{if(d.kind!=="branch")return d;const p=c(d,[...l,d.name]);return p!==d&&(f=!0),p}),w=i.extensible===!0?s(a.coreMounts,l):[];return f||w.length>0?V(i,[...h,...w]):i},"composeBranch");return e.map(i=>c(i,[i.name]))}n(I,"composeCorePluginMounts");async function Z(e,t){const{validateEffectiveCommandPlugins:r}=await import("./core/command-plugins/discovery.js"),s=r(new Set(m),void 0,void 0,void 0,t).flatMap(c=>c.manifest===void 0?[]:[c.manifest]).filter(c=>c.coreMounts.some(i=>i.parent[0]===e));if(s.length===0)return null;const a=O(s.flatMap(c=>[...c.coreMounts.map(i=>i.parent.join(" ")),...Object.keys(c.helpAddenda??{})]));return a.add(e),y(await x(a))}n(Z,"dispatchCommandPaths");function v(e,t){const r=e.slice(2).filter(o=>!j.has(o));return r[0]==="sys"&&r[1]===t}n(v,"isSysInvocation");const ee=[["surface"],["sys"],["pkg"],["profile","default"],["canvas","chord"],["canvas","config"],["canvas","use"],["canvas","browse"],["canvas","issue"]],te=[["sys","feedback"]];function D(e,t){return t.every((r,o)=>e[o]===r)}n(D,"startsWithPath");function he(e){const t=e.slice(2).filter(o=>!j.has(o));if(te.some(o=>D(t,o)))return null;const r=ee.find(o=>D(t,o));return r===void 0?null:r.join(" ")}n(he,"personOnlyInvocation");function we(e){return v(e,"daemon")}n(we,"isDaemonControlInvocation");function ye(e){return v(e,"signin")||v(e,"signout")}n(ye,"isSignInInvocation");function ve(e){return v(e,"join")}n(ve,"isJoinInvocation");function Se(e){return v(e,"migrate")}n(Se,"isLayoutMigrationInvocation");async function be(){const{registerDaemonControlSys:e}=await import("./commands/sys/daemon.js");return S({tagline:b,globals:C,subtrees:[e()]})}n(be,"resolveDaemonControlRoot");async function Ce(){const[{defineSysBranch:e},{sysMigrateLeaf:t}]=await Promise.all([import("./commands/sys/branch.js"),import("./commands/sys/migrate.js")]);return S({tagline:b,globals:C,subtrees:[e([t])]})}n(Ce,"resolveLayoutMigrationRoot");async function xe(e){return(e!==void 0?await ne(e):null)??oe()}n(xe,"resolveRoot");async function ne(e){if(B[e]===void 0)return null;const t=await A(e),r=await H(),o=[...r].some(a=>a.split(" ")[0]===e)?await Z(e,r):null,s=L(o===null?[t]:await I([t],r,o));return s.length>0?S({tagline:b,globals:C,subtrees:N(s,M())}):null}n(ne,"resolveCoreRoot");async function oe(){const e=await E(),[{buildExternalCommandSnapshot:t},{composeExternalSubtrees:r,composeSandboxProviderSubtrees:o},{qualifiedTopLevelCommandName:s}]=await Promise.all([import("./core/command-plugins/discovery.js"),import("./core/command-plugins/compose.js"),import("./core/command-manifests/registry.js")]),a=await H(),c=await I(e,a,y(e)),i=t(new Set(m),void 0,void 0,y(e),a);let l=r(i);const f=(await import("./daemon/machine-link/config.js")).readMachineConfig()!==void 0;let h;if(P()||$()||f){const{cliClient:d}=await import("./commands/api-client.js");g("cli.providers.request");let p=[];try{p=(await d().request("GET","/v1/providers/tools")).providers}catch(u){if(!f||!(u instanceof z||u instanceof F))throw u;h=u}g("cli.providers.fetched",{providers:p.length});const R=o(p,new Set(m)),G=new Set(R.map(u=>u.name));l=[...R,...r({...i,contributions:i.contributions.map(u=>G.has(u.node.name)?{...u,node:{...u.node,name:s(u.contributor,u.node.name)}}:u)})]}if(!f){const{previewBranches:d}=await import("./core/northlight/previews.js");l=[...l,...d(process.platform,new Set(l.map(p=>p.name)))]}const w=S({tagline:b,globals:C,subtrees:[...N(L(c),M()),...l]});return h===void 0?w:{...w,providerCatalogFailure:h}}n(oe,"buildRoot");export{Q as EXTENSIBLE_CORE_BRANCHES,m as SUBTREE_NAMES,oe as buildRoot,me as coreCommandPaths,fe as coreCommandPathsCovering,pe as coreHookCatalog,ge as declaredExtensibleCoreBranches,H as extensibleCoreBranches,we as isDaemonControlInvocation,ve as isJoinInvocation,Se as isLayoutMigrationInvocation,ye as isSignInInvocation,he as personOnlyInvocation,ne as resolveCoreRoot,be as resolveDaemonControlRoot,Ce as resolveLayoutMigrationRoot,xe as resolveRoot};
package/dist/cli.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- var R=Object.defineProperty;var s=(r,o)=>R(r,"name",{value:o,configurable:!0});import"./suppress-experimental-warnings.js";import{mkdirSync as S,openSync as _,readFileSync as E,renameSync as b,rmSync as C,statSync as u,writeFileSync as I}from"node:fs";import{dirname as g,join as a}from"node:path";import{enableCompileCache as A}from"node:module";import{fileURLToPath as h}from"node:url";import{isDaemonControlInvocation as m,isJoinInvocation as N,isLayoutMigrationInvocation as O,personOnlyInvocation as x,resolveDaemonControlRoot as $,resolveLayoutMigrationRoot as k,resolveRoot as T}from"./build-root.js";import{maybeBootRoot as P}from"./core/runtime/front-door.js";import{maybeAutoUpdate as F}from"./core/auto-update.js";import{ensureProjectScope as M}from"./core/bootstrap.js";import{provisionExports as D,pruneLegacyExports as L}from"./core/host-exports/export.js";import{revalidateBundlePlugins as j}from"./core/command-plugins/revalidate.js";import{renderNode as K,runCli as y,walk as U}from"./core/command.js";import{dispatchWithStaleRecovery as B}from"./core/manifest-recovery.js";import{installStdoutErrorPolicy as J}from"./core/stdout-errors.js";import{handle as V}from"./core/io.js";import{CrtrError as w,ownerOnly as W}from"./core/errors.js";import{ExitCode as q}from"./types.js";import{layoutNeedsMigration as G,runtimeRoot as z}from"./core/layout.js";import{ApiError as v}from"./api/index.js";import{mark as i}from"./core/timing.js";import{launchSnapshotFile as H,sandboxCliNodeId as Q}from"./shared/env.js";import{nodeRunDir as f}from"./core/canvas/paths.js";import{installBrokerConfigSnapshot as X}from"./core/config.js";_(h(import.meta.url),"r"),J(),i("cli.entry",{cmd:process.argv[2]??"(bare)"});try{A()}catch{}i("cli.compile_cache");const Y=a(g(h(import.meta.url)),".."),l=a(z(),"first-run.json");function c(r){return(r instanceof Error?r.message:String(r)).split(/\r?\n/,1)[0]??""}s(c,"errorMessage");function Z(r){const o=g(l);S(o,{recursive:!0});const t=`${l}.${process.pid}.${Date.now()}.tmp`;try{I(t,JSON.stringify({packageVersion:r,completedAt:new Date().toISOString()})+`
3
- `,"utf8"),b(t,l)}finally{C(t,{force:!0})}}s(Z,"writeFirstRunMarker");async function rr(){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: ${c(o)}
4
- `);return}try{if(u(a(Y,".git"),{throwIfNoEntry:!1})!==void 0)return}catch(o){process.stderr.write(`crtr: first-run reconcile source check failed: ${c(o)}
2
+ var R=Object.defineProperty;var s=(r,o)=>R(r,"name",{value:o,configurable:!0});import"./suppress-experimental-warnings.js";import{mkdirSync as _,openSync as b,readFileSync as E,renameSync as I,rmSync as C,statSync as g,writeFileSync as A}from"node:fs";import{dirname as h,join as a}from"node:path";import{enableCompileCache as N}from"node:module";import{fileURLToPath as y}from"node:url";import{isDaemonControlInvocation as f,isJoinInvocation as O,isLayoutMigrationInvocation as x,isSignInInvocation as $,personOnlyInvocation as k,resolveDaemonControlRoot as T,resolveLayoutMigrationRoot as P,resolveRoot as F}from"./build-root.js";import{maybeBootRoot as M}from"./core/runtime/front-door.js";import{maybeAutoUpdate as D}from"./core/auto-update.js";import{ensureProjectScope as L}from"./core/bootstrap.js";import{provisionExports as U,pruneLegacyExports as j}from"./core/host-exports/export.js";import{revalidateBundlePlugins as K}from"./core/command-plugins/revalidate.js";import{renderNode as B,runCli as w,walk as J}from"./core/command.js";import{dispatchWithStaleRecovery as V}from"./core/manifest-recovery.js";import{installStdoutErrorPolicy as W}from"./core/stdout-errors.js";import{handle as q}from"./core/io.js";import{CrtrError as m,ownerOnly as G}from"./core/errors.js";import{ExitCode as z}from"./types.js";import{layoutNeedsMigration as H,runtimeRoot as Q}from"./core/layout.js";import{ApiError as v}from"./api/index.js";import{mark as i}from"./core/timing.js";import{launchSnapshotFile as X,sandboxCliNodeId as Y}from"./shared/env.js";import{nodeRunDir as d}from"./core/canvas/paths.js";import{installBrokerConfigSnapshot as Z}from"./core/config.js";b(y(import.meta.url),"r"),W(),i("cli.entry",{cmd:process.argv[2]??"(bare)"});try{N()}catch{}i("cli.compile_cache");const rr=a(h(y(import.meta.url)),".."),l=a(Q(),"first-run.json");function c(r){return(r instanceof Error?r.message:String(r)).split(/\r?\n/,1)[0]??""}s(c,"errorMessage");function or(r){const o=h(l);_(o,{recursive:!0});const t=`${l}.${process.pid}.${Date.now()}.tmp`;try{A(t,JSON.stringify({packageVersion:r,completedAt:new Date().toISOString()})+`
3
+ `,"utf8"),I(t,l)}finally{C(t,{force:!0})}}s(or,"writeFirstRunMarker");async function er(){if(process.env.CRTR_NO_AUTO_INIT==="1")return;try{if(g(l,{throwIfNoEntry:!1})!==void 0)return}catch(o){process.stderr.write(`crtr: first-run reconcile marker check failed: ${c(o)}
4
+ `);return}try{if(g(a(rr,".git"),{throwIfNoEntry:!1})!==void 0)return}catch(o){process.stderr.write(`crtr: first-run reconcile source check failed: ${c(o)}
5
5
  `);return}let r;try{const{reconcileFirstRun:o}=await import("./commands/sys/setup-core.js");r=await o((t,p)=>{process.stderr.write(`crtr: first-run reconcile ${t} failed: ${c(p)}
6
6
  `)})}catch(o){process.stderr.write(`crtr: first-run reconcile failed: ${c(o)}
7
- `)}finally{if(r!==void 0)try{Z(r)}catch(o){process.stderr.write(`crtr: first-run reconcile marker failed: ${c(o)}
8
- `)}}}s(rr,"maybeReconcileFirstRun");async function or(){const r=O(process.argv),o=Q(),t=o!==void 0;if(o!==void 0){process.env.CRTR_API_SOCKET=a(f(o),"cli.sock");const e=x(process.argv);if(e!==null)throw W(`crtr ${e} is not available to an app's node`,"Run this command from the person's terminal.");const n=JSON.parse(E(H(f(o))??a(f(o),"broker-launch.json"),"utf8"));if(!n.configSnapshot)throw new Error("node launch is missing its config snapshot");X(n.configSnapshot)}if(!t&&G()&&!m(process.argv)&&!r)throw new w("layout_migration_required","run crtr sys migrate while the runtime is offline",q.NETWORK,{next:"Run `crtr sys migrate` while the runtime is offline, then restart it."});if(r){const e=await k();if(process.argv.slice(4).some(n=>n==="-h"||n==="--help")){process.stdout.write(K(U(e,["sys","migrate"]).node)+`
9
- `);return}await y(e,process.argv);return}if(!t&&!m(process.argv)&&!N(process.argv)){try{await(await import("./commands/person-settings.js")).loadPersonSettingsViaApi()}catch(e){if(!(process.argv.slice(2).some(d=>d==="-h"||d==="--help")&&e instanceof v&&e.code==="daemon_unavailable"))throw e;(await import("./core/scoped-state/person-store.js")).installPreludeSnapshot({profiles:[],defaults:{},settings:{},state:{}})}i("cli.settings_loaded")}if(t||(L(process.argv),await rr()),await P(process.argv),i("cli.front_door_passed"),m(process.argv)){await y(await $(),process.argv);return}t||await j(process.argv),i("cli.plugins_revalidated");const p=await T(process.argv[2]);i("cli.root_resolved"),t||(D(p,process.argv),await M(process.argv),await F(process.argv)),i("cli.dispatch_start"),await B(p,process.argv),i("cli.dispatch_done")}s(or,"main"),or().catch(r=>{(r instanceof Error&&r.name==="AbortError"||r instanceof Error&&/operation was aborted/i.test(r.message))&&(process.stderr.write(`crtr: Interrupted
10
- `),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}
7
+ `)}finally{if(r!==void 0)try{or(r)}catch(o){process.stderr.write(`crtr: first-run reconcile marker failed: ${c(o)}
8
+ `)}}}s(er,"maybeReconcileFirstRun");async function tr(){const r=x(process.argv),o=Y(),t=o!==void 0;if(o!==void 0){process.env.CRTR_API_SOCKET=a(d(o),"cli.sock");const e=k(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 n=JSON.parse(E(X(d(o))??a(d(o),"broker-launch.json"),"utf8"));if(!n.configSnapshot)throw new Error("node launch is missing its config snapshot");Z(n.configSnapshot)}if(!t&&H()&&!f(process.argv)&&!r)throw new m("layout_migration_required","run crtr sys migrate while the runtime is offline",z.NETWORK,{next:"Run `crtr sys migrate` while the runtime is offline, then restart it."});if(r){const e=await P();if(process.argv.slice(4).some(n=>n==="-h"||n==="--help")){process.stdout.write(B(J(e,["sys","migrate"]).node)+`
9
+ `);return}await w(e,process.argv);return}if(!t&&!f(process.argv)&&!O(process.argv)&&!$(process.argv)){try{await(await import("./commands/person-settings.js")).loadPersonSettingsViaApi()}catch(e){const n=process.argv.slice(2).some(u=>u==="-h"||u==="--help"),S=e instanceof v&&(e.code==="daemon_unavailable"||e.code==="northlight_unreachable")||e instanceof m&&(e.code==="not_signed_in"||e.code==="move_unfinished"||e.code==="northlight_unreachable");if(!(n&&S))throw e;(await import("./core/scoped-state/person-store.js")).installPreludeSnapshot({profiles:[],defaults:{},settings:{},state:{}})}i("cli.settings_loaded")}if(t||(j(process.argv),await er()),await M(process.argv),i("cli.front_door_passed"),f(process.argv)){await w(await T(),process.argv);return}t||await K(process.argv),i("cli.plugins_revalidated");const p=await F(process.argv[2]);i("cli.root_resolved"),t||(U(p,process.argv),await L(process.argv),await D(process.argv)),i("cli.dispatch_start"),await V(p,process.argv),i("cli.dispatch_done")}s(tr,"main"),tr().catch(r=>{(r instanceof Error&&r.name==="AbortError"||r instanceof Error&&/operation was aborted/i.test(r.message))&&(process.stderr.write(`crtr: Interrupted
10
+ `),process.exit(130)),(r instanceof v||r instanceof m)&&(q(r),process.exit(typeof process.exitCode=="number"?process.exitCode:1));const t=r instanceof Error?r.message:String(r);process.stderr.write(`crtr: ${t}
11
11
  `),process.exit(1)});
@@ -1,7 +1,9 @@
1
1
  import type { BrokerSnapshot, ClientRole } from '../../../core/runtime/broker-protocol.js';
2
2
  import type { CanvasSource } from '../../../core/canvas/source.js';
3
3
  import type { NodeMeta } from '../../../core/canvas/types.js';
4
- import { BrokerClient } from '../../../core/broker-client/index.js';
4
+ import { BrokerClient, type RelayTarget } from '../../../core/broker-client/index.js';
5
+ /** A relay target for an imported Mac: the cloud control plane, with the signed-in person's bearer. `relayToken` is read at each dial. */
6
+ export declare function machineRelayTarget(apiUrl: string, directoryUrl: string): Promise<RelayTarget>;
5
7
  /** The hello handshake's initial role. A REMOTE attach (`--canvas`) is a
6
8
  * strictly VIEW-ONLY surface — it must claim observer regardless of
7
9
  * `--observer`, never controller. Local attach claims controller unless
@@ -1 +1 @@
1
- var T=Object.defineProperty;var o=(e,r)=>T(e,"name",{value:r,configurable:!0});import{createConnection as y}from"node:net";import{apiSocketPath as A,viewSocketPath as P}from"../../../core/canvas/paths.js";import{BrokerClient as x,BrokerUnavailableError as E,RelayTransport as g}from"../../../core/broker-client/index.js";import{resolveRemoteCanvasTarget as _}from"../../../core/remote-canvas-target.js";import{ApiCanvasSource as R,cliCanvasSource as F,cliClient as S,rethrowAsCliError as M}from"../../../commands/api-client.js";import{InputError as p}from"../../../core/io.js";function U(e,r){return e||r?"observer":"controller"}o(U,"resolveHelloRole");async function $(e){const r=Number(process.env.CRTR_ATTACH_WAIT_MS??"");if(!Number.isFinite(r)||r<=0)return;const w=P(e),l=Date.now()+r;for(;Date.now()<l;){if(await new Promise(a=>{const s=y(w),c=o(n=>{s.destroy(),a(n)},"settle");s.once("connect",()=>c(!0)),s.once("error",()=>c(!1))}))return;await new Promise(a=>setTimeout(a,100))}}o($,"preWaitForViewSocket");async function V(e,r,w=!0){const l=r!==void 0,h=l?F({canvasName:r}):new R;let a,s,c,n,d;if(l)a={cwd:process.cwd()},c=new g(e,_(r));else{const t=await h.getNode(e);if(t===null)throw new p({error:"not_found",message:`no node: ${e}`,received:e,next:"List nodes with `crtr node inspect list`."});a=t,s=t;try{if((await S().ensureAttach(e,{resume:!0,revive:!0,wakeParked:w})).parked){const u=await S().getSnapshot(e);n=u.snapshot,d=u.commands}}catch(m){M(m,"The node may be finalized or otherwise not attachable.")}n===void 0&&await $(e),c=new g(e,{socketPath:A()})}const i=new x(e,{transport:c}),k=o(t=>t instanceof E?new p({error:"no_broker",message:t.message,received:e,next:"Focus or revive the node first \u2014 attach needs a running headless broker."}):new p({error:"socket_error",message:`could not attach to node ${e}: ${String(t?.message??t)}`,received:e,next:"Check the node has a running headless broker."}),"toAttachError");let f;return i.on("error",t=>{f===void 0&&(f=t)}),n===void 0&&await new Promise(async(t,m)=>{const u=o(()=>{C(),t()},"onConnect"),v=o(b=>{C(),m(b)},"onErr"),C=o(()=>{i.off("connect",u),i.off("error",v)},"cleanup");i.on("connect",u),i.on("error",v),i.connect()}).catch(t=>{throw k(t)}),{remote:l,canvasSource:h,meta:a,nodeIdentity:s,socket:i,...n===void 0?{}:{initialSnapshot:n,initialCommands:d},assertConnected:o(()=>{if(n===void 0&&f!==void 0)throw k(f)},"assertConnected")}}o(V,"connectToNode");export{V as connectToNode,$ as preWaitForViewSocket,U as resolveHelloRole};
1
+ var T=Object.defineProperty;var n=(e,t)=>T(e,"name",{value:t,configurable:!0});import{createConnection as R}from"node:net";import{apiSocketPath as _,viewSocketPath as A}from"../../../core/canvas/paths.js";import{BrokerClient as x,BrokerUnavailableError as P,RelayTransport as d}from"../../../core/broker-client/index.js";import{resolveRemoteCanvasTarget as M}from"../../../core/remote-canvas-target.js";import{ApiCanvasSource as B,cliCanvasSource as F,cliClient as b,rethrowAsCliError as H}from"../../../commands/api-client.js";import{InputError as k}from"../../../core/io.js";import{readMachineConfig as $}from"../../../daemon/machine-link/config.js";import{personBearer as y}from"../../../core/directory/person-credential.js";const D=15e3;async function U(e,t){let a=await y(t);return setInterval(()=>{y(t).then(s=>{a=s},()=>{})},D).unref(),{previewEndpoint:e,get relayToken(){return a}}}n(U,"machineRelayTarget");function O(e,t){return e||t?"observer":"controller"}n(O,"resolveHelloRole");async function W(e){const t=Number(process.env.CRTR_ATTACH_WAIT_MS??"");if(!Number.isFinite(t)||t<=0)return;const a=A(e),u=Date.now()+t;for(;Date.now()<u;){if(await new Promise(c=>{const o=R(a),m=n(l=>{o.destroy(),c(l)},"settle");o.once("connect",()=>m(!0)),o.once("error",()=>m(!1))}))return;await new Promise(c=>setTimeout(c,100))}}n(W,"preWaitForViewSocket");async function Q(e,t,a=!0){const u=t!==void 0,s=u?void 0:$(),c=t!==void 0?F({canvasName:t}):new B;let o,m,l,f,v;if(t!==void 0)o={cwd:process.cwd()},l=new d(e,M(t));else{const r=await c.getNode(e);if(r===null)throw new k({error:"not_found",message:`no node: ${e}`,received:e,next:"List nodes with `crtr node inspect list`."});o=r,m=r;try{if((await b().ensureAttach(e,{resume:!0,revive:!0,wakeParked:a})).parked){const w=await b().getSnapshot(e);f=w.snapshot,v=w.commands}}catch(p){H(p,"The node may be finalized or otherwise not attachable.")}s!==void 0?l=new d(e,await U(s.apiUrl,s.directoryUrl)):(f===void 0&&await W(e),l=new d(e,{socketPath:_()}))}const i=new x(e,{transport:l}),g=n(r=>r instanceof P?new k({error:"no_broker",message:r.message,received:e,next:"Focus or revive the node first \u2014 attach needs a running headless broker."}):new k({error:"socket_error",message:`could not attach to node ${e}: ${String(r?.message??r)}`,received:e,next:"Check the node has a running headless broker."}),"toAttachError");let h;return i.on("error",r=>{h===void 0&&(h=r)}),f===void 0&&await new Promise(async(r,p)=>{const w=n(()=>{S(),r()},"onConnect"),C=n(E=>{S(),p(E)},"onErr"),S=n(()=>{i.off("connect",w),i.off("error",C)},"cleanup");i.on("connect",w),i.on("error",C),i.connect()}).catch(r=>{throw g(r)}),{remote:u,canvasSource:c,meta:o,nodeIdentity:m,socket:i,...f===void 0?{}:{initialSnapshot:f,initialCommands:v},assertConnected:n(()=>{if(f===void 0&&h!==void 0)throw g(h)},"assertConnected")}}n(Q,"connectToNode");export{Q as connectToNode,U as machineRelayTarget,W as preWaitForViewSocket,O as resolveHelloRole};