dispach 0.2.0 → 0.2.1

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 (167) hide show
  1. package/README.md +58 -18
  2. package/dist/APEv2Parser-9wqew3zv.js +5 -0
  3. package/dist/{APEv2Parser-jdp5yp24.js.map → APEv2Parser-9wqew3zv.js.map} +1 -1
  4. package/dist/{AiffParser-n65syezh.js → AiffParser-tbx3xkmk.js} +3 -3
  5. package/dist/{AiffParser-n65syezh.js.map → AiffParser-tbx3xkmk.js.map} +1 -1
  6. package/dist/App-hjn867nc.js +11 -0
  7. package/dist/{App-pmqmzsb3.js.map → App-hjn867nc.js.map} +1 -1
  8. package/dist/{AsfParser-da1fqvxz.js → AsfParser-d784ak3y.js} +3 -3
  9. package/dist/{AsfParser-da1fqvxz.js.map → AsfParser-d784ak3y.js.map} +1 -1
  10. package/dist/{ConfigEditor-4nqbeejh.js → ConfigEditor-g7eb2wsm.js} +3 -3
  11. package/dist/{ConfigEditor-4nqbeejh.js.map → ConfigEditor-g7eb2wsm.js.map} +1 -1
  12. package/dist/{DsdiffParser-gk95sj7t.js → DsdiffParser-vxnfx80c.js} +2 -2
  13. package/dist/{DsfParser-b0enevjw.js → DsfParser-0xsh0zzk.js} +3 -3
  14. package/dist/{DsfParser-b0enevjw.js.map → DsfParser-0xsh0zzk.js.map} +1 -1
  15. package/dist/FlacParser-bf8y3e0w.js +5 -0
  16. package/dist/{KeyProbe-rspsxpsr.js → KeyProbe-w8c37s9q.js} +3 -3
  17. package/dist/{KeyProbe-rspsxpsr.js.map → KeyProbe-w8c37s9q.js.map} +1 -1
  18. package/dist/{MP4Parser-ph7rv2fn.js → MP4Parser-tq7r7wd4.js} +3 -3
  19. package/dist/{MP4Parser-ph7rv2fn.js.map → MP4Parser-tq7r7wd4.js.map} +1 -1
  20. package/dist/{MatroskaParser-fjk1mpct.js → MatroskaParser-a79gsmzb.js} +3 -3
  21. package/dist/{MatroskaParser-fjk1mpct.js.map → MatroskaParser-a79gsmzb.js.map} +1 -1
  22. package/dist/{MpegParser-vp7cj8ts.js → MpegParser-zs61b3wq.js} +3 -3
  23. package/dist/{MpegParser-vp7cj8ts.js.map → MpegParser-zs61b3wq.js.map} +1 -1
  24. package/dist/{MusepackParser-v22gft1f.js → MusepackParser-bp8dm6nz.js} +3 -3
  25. package/dist/{MusepackParser-v22gft1f.js.map → MusepackParser-bp8dm6nz.js.map} +1 -1
  26. package/dist/{OggParser-as1m8xsa.js → OggParser-7pxr1sn9.js} +3 -3
  27. package/dist/{OggParser-as1m8xsa.js.map → OggParser-7pxr1sn9.js.map} +1 -1
  28. package/dist/{Picker-jkmd5xnx.js → Picker-b09hr4tk.js} +3 -3
  29. package/dist/{Picker-jkmd5xnx.js.map → Picker-b09hr4tk.js.map} +1 -1
  30. package/dist/{SessionPicker-3712ke3k.js → SessionPicker-wtfxwdxg.js} +3 -3
  31. package/dist/{SessionPicker-3712ke3k.js.map → SessionPicker-wtfxwdxg.js.map} +1 -1
  32. package/dist/{SkillBrowser-qhsyszt4.js → SkillBrowser-p9ht63c7.js} +3 -3
  33. package/dist/{SkillBrowser-qhsyszt4.js.map → SkillBrowser-p9ht63c7.js.map} +1 -1
  34. package/dist/{WavPackParser-b4qqavzg.js → WavPackParser-gpf3r92t.js} +3 -3
  35. package/dist/{WavPackParser-b4qqavzg.js.map → WavPackParser-gpf3r92t.js.map} +1 -1
  36. package/dist/{WaveParser-fqs1h38f.js → WaveParser-3kcak550.js} +3 -3
  37. package/dist/{WaveParser-fqs1h38f.js.map → WaveParser-3kcak550.js.map} +1 -1
  38. package/dist/WizardApp-494018sk.js +5 -0
  39. package/dist/{WizardApp-qrq36nv8.js.map → WizardApp-494018sk.js.map} +1 -1
  40. package/dist/{channels-gf31stv7.js → channels-yhdvxxrb.js} +14 -14
  41. package/dist/{channels-gf31stv7.js.map → channels-yhdvxxrb.js.map} +1 -1
  42. package/dist/config-g0ybmm4t.js +24 -0
  43. package/dist/{config-z2cd0c5f.js.map → config-g0ybmm4t.js.map} +1 -1
  44. package/dist/credential-pkme1sfe.js +19 -0
  45. package/dist/{credential-h0wmsjsw.js.map → credential-pkme1sfe.js.map} +1 -1
  46. package/dist/{index-dwxmy0kx.js → index-0mz7wpbw.js} +6 -6
  47. package/dist/{index-dwxmy0kx.js.map → index-0mz7wpbw.js.map} +1 -1
  48. package/dist/{index-fcqy46mh.js → index-0pddq849.js} +25 -25
  49. package/dist/{index-fcqy46mh.js.map → index-0pddq849.js.map} +1 -1
  50. package/dist/{index-2yj11ykt.js → index-1f1erzfx.js} +4 -4
  51. package/dist/{index-2yj11ykt.js.map → index-1f1erzfx.js.map} +1 -1
  52. package/dist/{index-1h9pqnec.js → index-26ejkp8q.js} +189 -189
  53. package/dist/{index-1h9pqnec.js.map → index-26ejkp8q.js.map} +7 -7
  54. package/dist/{index-ccpq4k6r.js → index-307qmvb0.js} +25 -25
  55. package/dist/{index-ccpq4k6r.js.map → index-307qmvb0.js.map} +1 -1
  56. package/dist/index-3b3h8kyh.js +5 -0
  57. package/dist/{index-3mvenfbg.js.map → index-3b3h8kyh.js.map} +1 -1
  58. package/dist/{index-0p9p6fvc.js → index-3fgq1acj.js} +10 -10
  59. package/dist/{index-0p9p6fvc.js.map → index-3fgq1acj.js.map} +3 -3
  60. package/dist/{index-dh2g58s1.js → index-4emtktc0.js} +3 -3
  61. package/dist/{index-dh2g58s1.js.map → index-4emtktc0.js.map} +1 -1
  62. package/dist/{index-026q0y3a.js → index-4t3p7vm9.js} +4 -4
  63. package/dist/{index-026q0y3a.js.map → index-4t3p7vm9.js.map} +1 -1
  64. package/dist/{index-t5d8ey5t.js → index-5m9wydxb.js} +4 -4
  65. package/dist/{index-t5d8ey5t.js.map → index-5m9wydxb.js.map} +1 -1
  66. package/dist/{index-g1d06ct5.js → index-633eqxry.js} +7 -7
  67. package/dist/{index-g1d06ct5.js.map → index-633eqxry.js.map} +1 -1
  68. package/dist/index-6r9h7ftn.js +308 -0
  69. package/dist/index-6r9h7ftn.js.map +21 -0
  70. package/dist/{index-kktaw552.js → index-7gsbzvnc.js} +2 -2
  71. package/dist/{index-z88f35vs.js → index-94k4mh6s.js} +13 -13
  72. package/dist/{index-z88f35vs.js.map → index-94k4mh6s.js.map} +3 -3
  73. package/dist/index-9dmgk6d3.js +5 -0
  74. package/dist/{index-tny7c703.js.map → index-9dmgk6d3.js.map} +1 -1
  75. package/dist/index-9qv87rq7.js +9 -0
  76. package/dist/{index-s4a28ctb.js.map → index-9qv87rq7.js.map} +1 -1
  77. package/dist/{index-k2q76dhw.js → index-a6mtqkth.js} +6 -6
  78. package/dist/{index-k2q76dhw.js.map → index-a6mtqkth.js.map} +1 -1
  79. package/dist/{index-0m0x1454.js → index-ac2wzspd.js} +4 -4
  80. package/dist/{index-0m0x1454.js.map → index-ac2wzspd.js.map} +1 -1
  81. package/dist/{index-wxmqyv4c.js → index-ad5c9t83.js} +4 -4
  82. package/dist/{index-wxmqyv4c.js.map → index-ad5c9t83.js.map} +1 -1
  83. package/dist/{index-b7qc21s7.js → index-akv6e7ge.js} +6 -6
  84. package/dist/{index-b7qc21s7.js.map → index-akv6e7ge.js.map} +1 -1
  85. package/dist/{index-v271gbaz.js → index-ec101x93.js} +4 -4
  86. package/dist/{index-v271gbaz.js.map → index-ec101x93.js.map} +1 -1
  87. package/dist/{index-rhv6gqpt.js → index-f056wkb4.js} +4 -4
  88. package/dist/{index-rhv6gqpt.js.map → index-f056wkb4.js.map} +1 -1
  89. package/dist/{index-c2qjdz4q.js → index-gqaa06yh.js} +8 -8
  90. package/dist/{index-c2qjdz4q.js.map → index-gqaa06yh.js.map} +1 -1
  91. package/dist/{index-rfa0ztab.js → index-j20k6k0m.js} +4 -4
  92. package/dist/{index-rfa0ztab.js.map → index-j20k6k0m.js.map} +1 -1
  93. package/dist/{index-2pzgta33.js → index-jh2az41t.js} +4 -4
  94. package/dist/{index-2pzgta33.js.map → index-jh2az41t.js.map} +1 -1
  95. package/dist/{index-gace5ac7.js → index-mn34kj95.js} +4 -4
  96. package/dist/{index-gace5ac7.js.map → index-mn34kj95.js.map} +1 -1
  97. package/dist/{index-rvq7t636.js → index-myg5enf5.js} +2 -2
  98. package/dist/{index-s78sq9g1.js → index-pdsey1ab.js} +45 -45
  99. package/dist/{index-s78sq9g1.js.map → index-pdsey1ab.js.map} +1 -1
  100. package/dist/{index-jmnjcw61.js → index-psk6q25h.js} +4 -4
  101. package/dist/{index-jmnjcw61.js.map → index-psk6q25h.js.map} +1 -1
  102. package/dist/{index-3s2q0m64.js → index-q8b1fc3k.js} +4 -4
  103. package/dist/{index-3s2q0m64.js.map → index-q8b1fc3k.js.map} +1 -1
  104. package/dist/{index-g8n8rhtr.js → index-qh82wtpa.js} +3 -3
  105. package/dist/{index-g8n8rhtr.js.map → index-qh82wtpa.js.map} +1 -1
  106. package/dist/{index-gqbny9gy.js → index-s2tzq27a.js} +6 -6
  107. package/dist/{index-gqbny9gy.js.map → index-s2tzq27a.js.map} +1 -1
  108. package/dist/{index-1wxw30j1.js → index-s57ztjhq.js} +35 -35
  109. package/dist/index-s57ztjhq.js.map +13 -0
  110. package/dist/{index-jv7egrh2.js → index-skkddg44.js} +4 -4
  111. package/dist/{index-jv7egrh2.js.map → index-skkddg44.js.map} +1 -1
  112. package/dist/{index-9m6b14b4.js → index-thmq816c.js} +4 -4
  113. package/dist/{index-9m6b14b4.js.map → index-thmq816c.js.map} +1 -1
  114. package/dist/{index-es4bgkbh.js → index-trx9xb59.js} +6 -6
  115. package/dist/{index-es4bgkbh.js.map → index-trx9xb59.js.map} +1 -1
  116. package/dist/{index-60jxyzbe.js → index-twcgf73h.js} +4 -4
  117. package/dist/{index-60jxyzbe.js.map → index-twcgf73h.js.map} +1 -1
  118. package/dist/index-vw2hf4d8.js +6 -0
  119. package/dist/{index-v6taf4vn.js.map → index-vw2hf4d8.js.map} +1 -1
  120. package/dist/{index-m5rmhcez.js → index-w97gprre.js} +4 -4
  121. package/dist/{index-m5rmhcez.js.map → index-w97gprre.js.map} +1 -1
  122. package/dist/index-wk6andxq.js +5 -0
  123. package/dist/{index-ak304afj.js.map → index-wk6andxq.js.map} +1 -1
  124. package/dist/index-x9z2xnct.js +11 -0
  125. package/dist/{index-5nprb9px.js.map → index-x9z2xnct.js.map} +1 -1
  126. package/dist/index-xa9crtzq.js +6 -0
  127. package/dist/{index-qe3ybzh6.js.map → index-xa9crtzq.js.map} +1 -1
  128. package/dist/{index-0v2gw4mk.js → index-y34s71qe.js} +3 -3
  129. package/dist/{index-0v2gw4mk.js.map → index-y34s71qe.js.map} +1 -1
  130. package/dist/{index-y6r1k2yd.js → index-ye2yb3xf.js} +7 -7
  131. package/dist/{index-y6r1k2yd.js.map → index-ye2yb3xf.js.map} +1 -1
  132. package/dist/{index-y605a1rj.js → index-z0dgxd7d.js} +10 -10
  133. package/dist/{index-y605a1rj.js.map → index-z0dgxd7d.js.map} +2 -2
  134. package/dist/{index-m01mb74d.js → index-zg89tq04.js} +4 -4
  135. package/dist/{index-m01mb74d.js.map → index-zg89tq04.js.map} +1 -1
  136. package/dist/{index-dgrwpzz9.js → index-zjphh8ch.js} +4 -4
  137. package/dist/{index-dgrwpzz9.js.map → index-zjphh8ch.js.map} +1 -1
  138. package/dist/index.js +172 -172
  139. package/dist/index.js.map +4 -4
  140. package/dist/transcript.d.ts.map +1 -1
  141. package/dist/web-f6869dy2.js +14 -0
  142. package/dist/{web-stkkwyka.js.map → web-f6869dy2.js.map} +1 -1
  143. package/dist/wrapper-52c0vacs.js +5 -0
  144. package/dist/{wrapper-bwxbqa53.js.map → wrapper-52c0vacs.js.map} +1 -1
  145. package/package.json +2 -2
  146. package/dist/APEv2Parser-jdp5yp24.js +0 -5
  147. package/dist/App-pmqmzsb3.js +0 -11
  148. package/dist/FlacParser-6jwner07.js +0 -5
  149. package/dist/WizardApp-qrq36nv8.js +0 -5
  150. package/dist/config-z2cd0c5f.js +0 -24
  151. package/dist/credential-h0wmsjsw.js +0 -19
  152. package/dist/index-1wxw30j1.js.map +0 -13
  153. package/dist/index-358nsn9t.js +0 -65
  154. package/dist/index-358nsn9t.js.map +0 -21
  155. package/dist/index-3mvenfbg.js +0 -5
  156. package/dist/index-5nprb9px.js +0 -11
  157. package/dist/index-ak304afj.js +0 -5
  158. package/dist/index-qe3ybzh6.js +0 -6
  159. package/dist/index-s4a28ctb.js +0 -9
  160. package/dist/index-tny7c703.js +0 -5
  161. package/dist/index-v6taf4vn.js +0 -6
  162. package/dist/web-stkkwyka.js +0 -14
  163. package/dist/wrapper-bwxbqa53.js +0 -5
  164. /package/dist/{DsdiffParser-gk95sj7t.js.map → DsdiffParser-vxnfx80c.js.map} +0 -0
  165. /package/dist/{FlacParser-6jwner07.js.map → FlacParser-bf8y3e0w.js.map} +0 -0
  166. /package/dist/{index-kktaw552.js.map → index-7gsbzvnc.js.map} +0 -0
  167. /package/dist/{index-rvq7t636.js.map → index-myg5enf5.js.map} +0 -0
@@ -5,6 +5,6 @@
5
5
  "/**\n * `channels` — what an agent is reachable on, and the four things a person does to one.\n *\n * ## Why a command rather than more `config`\n *\n * Every one of these was possible already and reachable from nowhere obvious. Disconnecting meant\n * `config set <agent> channels '[{…the whole list again…}]'`; changing a token meant knowing that\n * `tokenEnv` names a variable and that `config env` writes it; relinking WhatsApp meant finding a\n * directory and deleting it. That is the standing rule about `init` — a capability reachable only by\n * somebody who already knows the field names is one the surface is hiding — applied to the thing a\n * person touches most after creating an agent.\n *\n * `lib/channel-actions.ts` holds the implementation, because the browser does the same four things\n * through HTTP and two implementations of \"disconnect a channel\" is how two surfaces come to\n * disagree about what it means.\n *\n * ## `status` is a different question from `list`\n *\n * This reads the **manifest**: what is configured, and whether its credential is filled in. Whether\n * a channel is *connected right now* is a fact about a running process, which only a host can\n * answer — `GET /v1/agents/:id` carries it and the `serve` banner prints it. Reporting a manifest\n * flag as a connection is decision 5.17's failure, so the output says which it is showing.\n */\n\nimport { dirname } from \"node:path\"\nimport { BRAND, HarnessError } from \"@dispach/core\"\nimport { announce } from \"#lib/bootstrap\"\nimport {\n type ChannelEntry,\n channelsOf,\n setChannelCredential,\n setChannelEnabled,\n unpairChannel,\n} from \"#lib/channel-actions\"\nimport { askSecret } from \"#lib/confirm\"\nimport { EXIT_FAILURE, EXIT_OK } from \"#lib/const\"\nimport {\n adoptOnHost,\n ensureHost,\n liveChannels,\n reloadOnHost,\n waitForPairing,\n} from \"#lib/host-actions\"\nimport { pairWhatsApp } from \"#lib/init-whatsapp\"\nimport { agentIdFor } from \"#lib/lifecycle\"\nimport { keyValue, type Row } from \"#lib/render\"\nimport type { ChannelsOptions } from \"#lib/schema\"\nimport { webUrl } from \"#lib/web-url\"\n\nexport async function channelsCommand(options: ChannelsOptions): Promise<number> {\n switch (options.action) {\n case \"list\":\n case undefined:\n return await list(options)\n case \"connect\":\n return await flip(options, true)\n case \"disconnect\":\n return await flip(options, false)\n case \"credential\":\n return await credential(options)\n case \"pair\":\n return await pair(options)\n case \"unpair\":\n return unpair(options)\n default:\n throw new HarnessError({\n code: \"cli_channels_action_unknown\",\n message: `channels: ${JSON.stringify(options.action)} is not an action`,\n hint: `Actions are list, connect, disconnect, credential and unpair — \\`${BRAND.slug} channels list <agent>\\`.`,\n })\n }\n}\n\nasync function list(options: ChannelsOptions): Promise<number> {\n const channels = channelsOf(options.manifestPath)\n if (options.json === true) {\n process.stdout.write(`${JSON.stringify({ channels }, null, 2)}\\n`)\n return EXIT_OK\n }\n if (channels.length === 0) {\n process.stdout.write(\n `No channels. This agent is reached through the CLI and the HTTP API only.\\nAdd one with \\`${BRAND.slug} config set <agent> channels\\`, or answer the channel questions in \\`${BRAND.slug} init\\`.\\n`,\n )\n return EXIT_OK\n }\n\n /**\n * **This column never says \"connected\", and that is a correction rather than a wording tweak.**\n *\n * It used to read `channel.enabled ? \"connected\" : \"disconnected\"` — so a WhatsApp channel that\n * had never been paired in its life printed `wa whatsapp connected`, and the footer explaining\n * that this is only the manifest did not undo the word in the table. Reported exactly that way:\n * a number was added, the listing said connected, and nothing anywhere offered a code. A\n * disclaimer under a claim does not cancel the claim.\n *\n * `enabled` and `disabled` are what the file actually says, and the live half now comes from\n * the host below instead of being disclaimed away.\n */\n const live = await liveChannels(options.manifestPath)\n const rows: Row[] = channels.map((channel) => {\n const now = live?.get(channel.id)\n return {\n label: channel.id,\n value: channel.type,\n note: [\n channel.enabled ? \"enabled\" : \"disabled\",\n ...(now === undefined ? [] : [`now ${now.status}`]),\n channel.credentialEnv === undefined\n ? // Said rather than omitted: an absent credential row reads as \"this one needs\n // no setting up\", which for WhatsApp is the opposite of the truth.\n channel.type === \"whatsapp\"\n ? pairingNote(channel)\n : \"no credential in the .env\"\n : `${channel.credentialEnv} ${channel.credentialSet ? \"set\" : \"NOT SET\"}`,\n // The paired account is always admitted, so an empty list no longer means nobody\n // for a channel with a `pairWith` — saying so is what stops the owner editing a\n // field they do not need to.\n channel.allowFrom.length === 0\n ? channel.pairWith === undefined\n ? \"allowFrom empty — permits nobody\"\n : `allows you (${channel.pairWith}) — allowFrom names anyone else`\n : `allows ${channel.allowFrom.join(\", \")}${channel.pairWith === undefined ? \"\" : \" and you\"}`,\n ].join(\" · \"),\n }\n })\n process.stdout.write(`${keyValue(rows)}\\n`)\n\n /**\n * The pending code or QR, from the host that is holding it.\n *\n * This is the half that was missing entirely: `needs_input` reached the `serve` banner and the\n * agent resource and **no command**, so the only way to pair was to watch a log at the moment\n * it scrolled past. A person who ran `channels list` — the command named after the question\n * they had — was told the channel was connected and given nothing to act on.\n */\n for (const [id, state] of live ?? []) {\n if (state.input === undefined) continue\n process.stdout.write(\n `\\n${id} is waiting to be paired — ${state.detail ?? \"enter this\"}:\\n\\n ${state.input.payload}\\n`,\n )\n if (state.input.expiresAt !== undefined)\n process.stdout.write(`\\n expires ${state.input.expiresAt}\\n`)\n }\n\n if (live === undefined)\n // The distinction 5.17 exists for. With no host there is genuinely nothing live to report,\n // and saying so beats printing a status column that is really a config flag.\n process.stdout.write(\n `\\nNothing is hosting this agent, so nothing above is a live status — it is what the\\nmanifest says. Start it with \\`${BRAND.slug} serve\\` to see what each channel is doing.\\n`,\n )\n return EXIT_OK\n}\n\n/** How this WhatsApp entry pairs, and whether it already has. */\nfunction pairingNote(channel: ChannelEntry): string {\n // `pairWith` turns pairing into a code typed into the phone; without it, a QR. The old string\n // said \"paired by QR\" unconditionally — wrong about the method once `pairWith` existed, and\n // wrong about the tense always, since it printed for a channel that had never been paired.\n const how =\n channel.pairWith === undefined ? \"pairs by QR\" : `pairs by code to ${channel.pairWith}`\n return channel.paired === true\n ? `${how}; linked — \\`channels unpair\\` forgets it`\n : `${how}; not linked yet`\n}\n\n/**\n * Connect a channel the way that channel needs.\n *\n * One verb for two mechanisms, because from the person's seat it is one action: \"make this\n * channel work\". WhatsApp pairs by a code typed into the phone; Telegram wants a bot token in the\n * `.env`. Making somebody know which of `credential` and `unpair`-then-`serve` applies is\n * remembering the implementation, and `channels pair <agent> wa` was the first thing typed when\n * the code did not appear — it answered *\"No agent named \\\"pair\\\"\"*, because `pair` was not an\n * action and so was read as the agent.\n *\n * WhatsApp has two cases. If a host is already serving this agent, the code it is offering is\n * shown and the command waits for the phone. If nothing is running, this pairs on its own — the\n * same interlude `init` uses — and the result is on disk for the next `serve`.\n */\nasync function pair(options: ChannelsOptions): Promise<number> {\n const channelId = channelIdOf(options)\n const channel = channelsOf(options.manifestPath).find((entry) => entry.id === channelId)\n if (channel === undefined)\n throw new HarnessError({\n code: \"cli_channel_unknown\",\n message: `No channel \"${channelId}\" in ${options.manifestPath}.`,\n hint: `\\`${BRAND.slug} channels list <agent>\\` names them.`,\n })\n\n if (channel.type === \"telegram\") {\n // A token is the pairing. Prompted and not echoed, then switched on — and the host holding\n // the agent reloads it, or the manifest says \"connected\" while the process runs the old one.\n const code = await credential(options)\n if (code !== EXIT_OK) return code\n const flipped = await flip(options, true)\n process.stdout.write(`${await reloadNote(options.manifestPath)}\\n`)\n return flipped\n }\n\n if (channel.type !== \"whatsapp\")\n throw new HarnessError({\n code: \"cli_channel_no_pairing\",\n message: `Channel \"${channelId}\" is a ${channel.type}, which has no pairing step.`,\n hint: `Use \\`${BRAND.slug} channels connect\\` to switch it on, or \\`credential\\` if it takes a token.`,\n })\n\n if (channel.pairWith === undefined)\n throw new HarnessError({\n code: \"cli_channel_no_number\",\n message: `Channel \"${channelId}\" has no pairWith, so there is no number to pair to.`,\n hint: \"Set pairWith on the channel to the account's own number, digits with the country code. Without it pairing is a QR, which `serve` offers.\",\n })\n\n if (channel.paired === true) {\n process.stdout.write(\n `${channelId} is already paired to ${channel.pairWith}. \\`${BRAND.slug} channels unpair\\` forgets it first.\\n`,\n )\n return EXIT_OK\n }\n\n /**\n * A host does the pairing when one can exist. It holds the socket, so when the phone accepts\n * the session is already in the process that will answer — nothing to reload, nothing to start.\n * The bootstrap puts one up first if none is; a container, CI or a caller with no installer\n * gets `undefined` here and the standalone path below, which pairs in this process and names\n * what to run next.\n */\n const agentId = agentIdFor(options.manifestPath)\n const { outcome, host } = await ensureHost({\n ...(options.installServer === undefined ? {} : { install: options.installServer }),\n })\n const note = announce(outcome)\n if (note !== undefined) process.stderr.write(note)\n if (host?.baseUrl !== undefined) {\n const adopted = await adoptOnHost(host, options.manifestPath)\n if (!adopted.ok) {\n process.stderr.write(\n `pid ${host.pid} did not adopt ${agentId}${adopted.detail === undefined ? \"\" : `: ${adopted.detail}`}\\n`,\n )\n } else {\n const result = await waitForPairing({ manifestPath: options.manifestPath, channelId })\n if (result === \"paired\") {\n process.stdout.write(\n `${channelId} is linked to ${channel.pairWith}, and pid ${host.pid} is serving it.\\n chat: ${webUrl(host.baseUrl, agentId)} — or \\`${BRAND.slug} run ${agentId}\\`\\n`,\n )\n return EXIT_OK\n }\n process.stdout.write(\n result === \"no-code\"\n ? `No code arrived from pid ${host.pid} — \\`${BRAND.slug} status\\` shows what the channel is doing; run this again once it offers one.\\n`\n : `Not paired yet — the host keeps offering codes; run this again.\\n`,\n )\n return EXIT_FAILURE\n }\n }\n\n const paired = await pairWhatsApp({\n manifestPath: options.manifestPath,\n dir: dirname(options.manifestPath),\n number: channel.pairWith,\n channelId,\n ...(channel.authDir === undefined ? {} : { authDir: channel.authDir }),\n })\n if (paired !== \"paired\") return EXIT_FAILURE\n // On disk and read by nothing yet. Said here, because a pairing that lands in a session file\n // and a process that never opens it is the exact dead end this verb exists to close.\n process.stdout.write(\n `Nothing is serving ${agentId} yet. \\`${BRAND.slug} serve ${agentId}\\` runs it here; \\`${BRAND.slug} daemon install\\` keeps a server running for every agent.\\n`,\n )\n return EXIT_OK\n}\n\n/** One line on whether the host holding this agent picked the change up. */\nasync function reloadNote(manifestPath: string): Promise<string> {\n const reloaded = await reloadOnHost(manifestPath)\n switch (reloaded.kind) {\n case \"reloaded\":\n return `pid ${reloaded.pid} reloaded it — the change is live.`\n case \"pending\":\n return `pid ${reloaded.pid} applies it when its ${reloaded.running} running turn(s) finish.`\n case \"busy\":\n return `pid ${reloaded.pid} has a turn in flight; \\`${BRAND.slug} restart ${agentIdFor(manifestPath)}\\` once it finishes.`\n case \"failed\":\n return `pid ${reloaded.pid} did not reload it${reloaded.detail === undefined ? \"\" : `: ${reloaded.detail}`} — \\`${BRAND.slug} restart ${agentIdFor(manifestPath)}\\` to retry.`\n case \"no-host\":\n return `Nothing is hosting it right now; it takes effect at the next start.`\n }\n}\n\nasync function flip(options: ChannelsOptions, enabled: boolean): Promise<number> {\n const result = await setChannelEnabled(options.manifestPath, channelIdOf(options), enabled)\n process.stdout.write(`${result.note}\\n`)\n return EXIT_OK\n}\n\nasync function credential(options: ChannelsOptions): Promise<number> {\n const channelId = channelIdOf(options)\n // **Prompted, never taken from an argument.** An argument lands in shell history *and* in `ps`,\n // readable by every local process for the call's lifetime — the same rule `config env` follows\n // and the reason `renderPlist` throws rather than writing one into a service definition.\n const value = await askSecret(`Credential for channel \"${channelId}\"`)\n // `undefined` covers both \"not a terminal\" and \"cancelled\", and both mean the same thing here:\n // nothing was read, so nothing is written. CI is told rather than having a secret arrive\n // unaudited from a pipe.\n if (value === undefined || value === \"\") {\n process.stdout.write(\n \"Nothing was read, so nothing was written. A secret is never taken from an argument or a pipe —\\nrun this at a terminal, or put the variable in the .env beside the manifest yourself.\\n\",\n )\n return EXIT_OK\n }\n const result = setChannelCredential(options.manifestPath, channelId, value)\n process.stdout.write(`${result.note}\\n`)\n return EXIT_OK\n}\n\n/**\n * Forget a stored pairing.\n *\n * Done on disk rather than through the transport, because the useful moment is usually with the\n * agent **not** running — `ChannelHub.reset` is the live path and the HTTP route uses it. Both end\n * in the same state, which is the state a first start produces.\n */\nfunction unpair(options: ChannelsOptions): number {\n const result = unpairChannel(options.manifestPath, channelIdOf(options))\n process.stdout.write(`${result.note}\\n`)\n return EXIT_OK\n}\n\nfunction channelIdOf(options: ChannelsOptions): string {\n const given = options.channelId\n if (given !== undefined && given !== \"\") return given\n const declared = channelsOf(options.manifestPath)\n // One channel is unambiguous, and making somebody name it would be ceremony. Two is a choice\n // nothing here can make for them.\n const only = declared[0]\n if (declared.length === 1 && only !== undefined) return only.id\n throw new HarnessError({\n code: \"cli_channels_needs_id\",\n message: \"Which channel?\",\n hint:\n declared.length === 0\n ? \"This agent declares none. `channels list <agent>` says so too.\"\n : `Name one: ${declared.map((channel) => channel.id).join(\", \")}.`,\n field: \"channelId\",\n })\n}\n"
6
6
  ],
7
7
  "mappings": ";+dAwBA,kBAAS,kBAyBF,eAAe,CAAe,CAAC,EAA2C,CAC7E,OAAQ,EAAQ,QACZ,IAAK,OACL,IAAK,QACD,OAAO,MAAM,EAAK,CAAO,EAC7B,IAAK,UACD,OAAO,MAAM,EAAK,EAAS,EAAI,EACnC,IAAK,aACD,OAAO,MAAM,EAAK,EAAS,EAAK,EACpC,IAAK,aACD,OAAO,MAAM,EAAW,CAAO,EACnC,IAAK,OACD,OAAO,MAAM,EAAK,CAAO,EAC7B,IAAK,SACD,OAAO,EAAO,CAAO,EACzB,QACI,MAAM,IAAI,EAAa,CACnB,KAAM,8BACN,QAAS,aAAa,KAAK,UAAU,EAA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xd7d.js";import"./index-s57ztjhq.js";import"./index-6r9h7ftn.js";import"./index-j20k6k0m.js";import{qA,Ni,Mi,Ti,Ri,_i,VA,jo,Jo,pA,Dn}from"./index-9qv87rq7.js";import{Gt}from"./index-ac2wzspd.js";import{bA,Wn}from"./index-ec101x93.js";import{zn,Zn,Ye,Ur}from"./index-x9z2xnct.js";import{Pe,ot}from"./index-ad5c9t83.js";import{St,U,qe,Et}from"./index-akv6e7ge.js";import{d,Q}from"./index-a6mtqkth.js";import{F,Fe}from"./index-0mz7wpbw.js";import{ke}from"./index-qh82wtpa.js";import{Rt,be,dA,o}from"./index-vw2hf4d8.js";import{readFileSync as p}from"node:fs";var v=["list","get","set","env","allow","edit"];function Y(e,t,i=(n)=>process.stderr.write(n)){let n=(e??"").trim();if(n==="")return{action:"edit",ref:void 0};if(!v.includes(n))return{action:"edit",ref:n};if(t!==void 0&&v.includes(t))i(`note: reading "${n}" as the action and "${t}" as the agent
3
+ `);if(t===void 0&&n!=="list")return{action:n,ref:void 0};return{action:n,ref:t}}async function Z(e){let t=e.out??((r)=>process.stdout.write(r)),i=e.action??"";if(!v.includes(i)){let r=j(i,[...v]);throw new A({code:"cli_config_action_unknown",message:`"${i}" is not something config does.`,hint:`One of: ${v.join(", ")}.${r===void 0?"":` Did you mean ${r}?`}`})}let n=Fe(e.ref??"",e.sandboxEnv);switch(i){case"list":{t(`${Ni(Jo(n),n)}
4
+ `);let r=jo(VA(gA(p(n,"utf8"))),Gt(n));for(let a of r)t(`
5
+ ${Q(`${a.name} is not set — ${a.why}`)}
6
+ `),t(`${Q(`\`config env <agent> ${a.name}\` fills it in`)}
7
+ `);return o}case"get":return C(n,e,t);case"set":return await E(n,e,t);case"env":return await S(n,e,t);case"edit":return await k(n,e,t);default:return await O(n,e,t)}}function C(e,t,i){let n=(t.name??"").trim(),r=b(n),a=Jo(e).find((s)=>s.setting.path===r.path);return i(`${Mi(r,a?.value)}
8
+ `),o}function b(e){let t=Qo(e)??ri(e);if(t!==void 0)return t;let i=j(e,[..._i()]);throw new A({code:"cli_config_path_unknown",message:`"${e}" is not a setting.`,hint:`\`config list <agent>\` shows every one with its current value.${i===void 0?"":` Did you mean ${i}?`}`,field:"path"})}async function E(e,t,i){let n=(t.name??"").trim(),r=b(n);if(r.via!==void 0)throw new A({code:"cli_config_needs_action",message:`${r.path} is not set by a dotted path.`,hint:`Use \`${r.via}\` — it lives inside a list entry, and it gets its value checked against the service that issues it rather than written verbatim.`,field:"path"});if(t.value===void 0)throw new A({code:"cli_config_value_missing",message:`No value given for ${n}.`,hint:`A bare word, a number, a list as ["a", "b"], or a map as {k: v}. \`config get <agent> ${n}\` shows what it is now.`,field:"value"});let a=fn(t.value),s=Ti(r,a);if(s!==void 0&&t.yes!==!0){if(i(`${Q(s)}
9
+ `),!await(t.confirm??bA)(`Change ${r.path} anyway?`))return i(`${d([{label:"unchanged",value:r.path}])}
10
+ `),o}let h=Gt(e),l=jo(VA(gA(p(e,"utf8"))),h).map((c)=>c.name),f=await zn(e,n,t.value),g=jo(VA(gA(p(e,"utf8"))),h).filter((c)=>!l.includes(c.name)),m=await _(e,t);return i(`${Ri({path:n,before:f.before,after:a,file:e,reflowed:f.reflowed,...m===void 0?{}:{running:m},pending:g,restartHint:y(m?.mode)})}
11
+ `),o}function y(e){if(e==="daemon")return"`daemon restart <agent>`";if(e==="embedded")return"`/restart` in this session";if(e==="terminal")return"that process being started again";return"it is started again"}async function _(e,t){let i;try{i=G(e).id}catch{return}if(i===void 0)return;try{let n=await fe.open({path:t.store??F(t.sandboxEnv)});try{for(let r of await n.leases.all()){if(r.agentId!==i)continue;if(!z(r.pid))continue;return{pid:r.pid,mode:r.mode}}}finally{await n.close()}}catch{return}return}async function S(e,t,i){let n=(t.name??"").trim();if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(n))throw new A({code:"cli_config_env_name_invalid",message:`"${n}" is not an environment variable name.`,hint:"Letters, digits and underscores, not starting with a digit — MODEL_API_KEY, TELEGRAM_BOT_TOKEN. `config list <agent>` shows which ones this agent names.",field:"name"});let a=await(t.secret??Wn)(`value for ${n} (not echoed):`);if(a===void 0)throw new A({code:"cli_config_env_no_value",message:`Nothing was written for ${n}.`,hint:"A secret is read from a prompt, never from an argument or a pipe — an argument is visible in `ps` and in shell history. Run this at a terminal, or edit the .env beside the manifest yourself."});if(a==="")throw new A({code:"cli_config_env_empty",message:`An empty value for ${n} would not start the agent.`,hint:"A variable set to nothing fails the load exactly as a missing one does. Nothing was written."});let s=Ye(e,n,a);return i(`${d([{label:"set",value:s.note}])}
12
+ `),i(`${Q("takes effect the next time the agent starts")}
13
+ `),o}async function O(e,t,i){let n=st(p(e,"utf8"),["channels"]);if(!Array.isArray(n)||n.length===0)throw new A({code:"cli_config_no_channels",message:"This agent has no channels, so there is nobody to allow.",hint:"`config set <agent> channels '[{type: telegram, id: tg, tokenEnv: TELEGRAM_BOT_TOKEN, mode: longpoll}]'` declares one first."});let r=n.filter((u)=>typeof u==="object"&&u!==null&&!Array.isArray(u)),a=r.map((u)=>String(u.id??"")).filter((u)=>u!==""),s=t.channel?.trim();if(s===void 0&&r.length>1)throw new A({code:"cli_config_channel_ambiguous",message:`This agent has ${r.length} channels, so --channel says which.`,hint:`One of: ${a.join(", ")}.`,field:"channel"});let h=s===void 0?0:r.findIndex((u)=>String(u.id??"")===s);if(h===-1)throw new A({code:"cli_config_channel_unknown",message:`No channel with id "${s}".`,hint:`Declared: ${a.join(", ")}.${j(s??"",a)===void 0?"":` Did you mean ${j(s??"",a)}?`}`,field:"channel"});let l=r[h],f=Ur(t.name??"",String(l.type??"")),g=Array.isArray(l.allowFrom)?l.allowFrom.map(String):[],m=t.remove===!0?g.filter((u)=>u!==f):g.includes(f)?g:[...g,f];if(m.length===g.length&&t.remove===!0)return i(`${d([{label:"unchanged",value:`${f} was not on ${String(l.id)}`}])}
14
+ `),o;if(m.length===g.length)return i(`${d([{label:"already allowed",value:`${f} on ${String(l.id)}`}])}
15
+ `),o;let c=await Zn(e,String(l.id??""),m),w=await _(e,t);if(i(`${d([{label:t.remove===!0?"removed":"allowed",value:f},{label:"channel",value:String(l.id)},{label:"now",value:qA(m)},{label:"file",value:e}])}
16
+ `),c.reflowed)i(`${Q("the file was re-serialised — it is valid, and comments may have moved")}
17
+ `);if(w!==void 0)i(`${Q(`this agent is running (pid ${w.pid}, ${w.mode}) and holds its settings for its lifetime — the change applies after ${y(w.mode)}`)}
18
+ `);return o}async function k(e,t,i){let n=ot({plain:!1,json:!1,oneShot:!1});if(n.mode!=="rich")throw new A({code:"cli_config_edit_needs_terminal",message:"The settings editor needs a terminal.",hint:`Not one here (${n.because}). \`config list\` reads them and \`config set\` changes one, both of which work on a pipe.`});let[{render:r},{createElement:a},{ConfigEditor:s}]=await Promise.all([import("ink"),import("react"),import("./ConfigEditor-g7eb2wsm.js")]),h=!1,l=()=>{},f=new Promise((c)=>{l=c});St(),process.stdout.write(Rt);let g=r(a(s,{rows:pA(e),apply:(c,w)=>Dn(e,c,w),reload:()=>pA(e),columns:ke(process.stdout.columns,be),window:dA,onDone:(c)=>{h=c,l()}}),{exitOnCtrlC:!1,...Pe()});U(()=>g.unmount()),await f,g.unmount(),qe(),await Et();let m=await _(e,t);if(!h)return i(`${d([{label:"unchanged",value:e}])}
19
+ `),o;return i(`${d([{label:"changed",value:e}])}
20
+ `),i(`${Q(`takes effect after ${y(m?.mode)}`)}
21
+ `),o}export{Z as configCommand,Y as readAction};
22
+
23
+ //# debugId=F6F673540A8E070764756E2164756E21
24
+ //# sourceMappingURL=config-g0ybmm4t.js.map
@@ -5,6 +5,6 @@
5
5
  "/**\n * `config` — a person changing an agent's settings without hand-editing YAML.\n *\n * ## Why this exists\n *\n * `config_read`/`config_set` shipped in Phase 3.6 and are the *agent's*. There was no equivalent for a\n * person, so the routes were editing `agent.yaml` by hand, re-running `init` into a fresh directory, or\n * asking the agent (which needs `config_set` pinned, a matching allow rule, and a restart).\n *\n * The inversion is the argument for the command. Decision 11.29 reserves `allowFrom`, `server.host`,\n * `server.tokenEnv` and `writeRoots` **for the person**, floored so the agent cannot widen its own\n * reach — and that is right. But the only editor ever built was the agent's, so the fields designated\n * as the person's had the worst ergonomics in the system: unvalidated YAML that fails at the next boot.\n * It compounds with `.env` being protected *precisely* so the agent cannot supply its own secrets,\n * which left the one actor who can fill in `MODEL_API_KEY` with no tool for doing it.\n *\n * ## What this does not own\n *\n * The write. `editManifest` places, validates against the real schema, checks that the providers still\n * resolve, and only then writes — one writer for every surface, because the three that existed made\n * the guarantee depend on which caller you happened to be.\n *\n * ## Why nothing here is floored\n *\n * The agent's floor exists because an agent that could widen its own inbound gate could be *talked\n * into* it by the message it is reading. A person at a terminal is not that threat. Two edits are\n * confirmed rather than refused — `tools.policy.deny` and `onMutate: allow` — and `lib/config-view.ts`\n * decides which, so \"what needs a confirmation\" is assertable without performing one.\n */\n\nimport { readFileSync } from \"node:fs\"\nimport {\n HarnessError,\n manifestDocument,\n manifestValueAt,\n nearest,\n parseSettingValue,\n personSetting,\n processAlive,\n readManifestHeader,\n type Setting,\n SqliteStore,\n settingByPath,\n} from \"@dispach/core\"\nimport { applyAllow, applySecret, applySet, checkedHandle } from \"#lib/config-apply\"\nimport type { EditorRow } from \"#lib/config-editor\"\nimport { agentEnv } from \"#lib/config-env\"\nimport { applyEditorRow, currentValues, editorRowsFor } from \"#lib/config-rows\"\nimport {\n confirmationFor,\n envNeeds,\n renderChange,\n renderOne,\n renderSettings,\n settablePaths,\n showValue,\n unmet,\n} from \"#lib/config-view\"\nimport { askSecret, askYesNo } from \"#lib/confirm\"\nimport {\n ENTER_ALT_SCREEN,\n EXIT_FAILURE,\n EXIT_OK,\n FALLBACK_COLUMNS,\n MAX_SCREEN_ROWS,\n} from \"#lib/const\"\nimport { flushOutput, markAltScreen, onExit, restoreTerminal } from \"#lib/exit\"\nimport { negotiateKeyboard } from \"#lib/keyboard\"\nimport { resolveModeFromProcess } from \"#lib/output\"\nimport { bullet, keyValue } from \"#lib/render\"\nimport { resolveAgentRef, storePath } from \"#lib/sandbox\"\nimport { screenColumns } from \"#lib/screen\"\n\nexport interface ConfigCommandOptions {\n /** `list` | `get` | `set` | `env` | `allow`. */\n readonly action?: string\n /** A path or a sandbox agent name. */\n readonly ref?: string\n /** A setting path, an env variable name, or a handle, depending on the action. */\n readonly name?: string\n readonly value?: string\n readonly channel?: string\n readonly remove?: boolean\n readonly yes?: boolean\n readonly store?: string\n /** Injected by tests. */\n readonly confirm?: (question: string) => Promise<boolean>\n readonly secret?: (question: string) => Promise<string | undefined>\n /**\n * The `<ENVPREFIX>HOME` override that relocates the whole sandbox. **Not** the manifest\n * environment: that one is `ambientEnv`, computed from the resolved path, and answers \"is this\n * variable set\". Two env concepts in one options object want two names — conflating them has\n * already cost a round, where `skills install` consulted a different registry from `init`.\n */\n readonly sandboxEnv?: Readonly<Record<string, string | undefined>>\n readonly out?: (text: string) => void\n}\n\nconst ACTIONS = [\"list\", \"get\", \"set\", \"env\", \"allow\", \"edit\"] as const\n\n/**\n * Read the action and the agent out of the positionals, allowing `config <agent>` with no action.\n *\n * The editor is what most people want from this command, so typing its name and an agent has to work.\n * Disambiguated the way this repo already does it twice over: a slash command takes arguments only\n * after a token that is *exactly* a known command, and `resolveAgentRef` lets the filesystem win with a\n * note on genuine ambiguity. Here the six action words win, and anything else is an agent.\n *\n * The collision is an agent literally named after an action, and it gets the note rather than silence —\n * running the wrong thing quietly is the failure worth avoiding, and it does not look wrong in output.\n */\nexport function readAction(\n first: string | undefined,\n second: string | undefined,\n warn: (line: string) => void = (line) => process.stderr.write(line),\n): { readonly action: string; readonly ref: string | undefined } {\n const given = (first ?? \"\").trim()\n if (given === \"\") return { action: \"edit\", ref: undefined }\n if (!ACTIONS.includes(given as (typeof ACTIONS)[number])) {\n return { action: \"edit\", ref: given }\n }\n if (second !== undefined && ACTIONS.includes(second as (typeof ACTIONS)[number])) {\n // Both words are action names, so one of them is an agent and only the order says which. The\n // first wins, and the note is what stops a silently-wrong run — the same choice\n // `resolveAgentRef` makes for a bare name shadowed by a directory.\n warn(`note: reading \"${given}\" as the action and \"${second}\" as the agent\\n`)\n }\n if (second === undefined && given !== \"list\") {\n // A known action word with nothing after it. `config edit` alone is the editor with no agent,\n // which fails later with the usual missing-manifest error; anything else is ambiguous only if an\n // agent has that name, and `resolveAgentRef` is what finds out.\n return { action: given, ref: undefined }\n }\n return { action: given, ref: second }\n}\n\nexport async function configCommand(options: ConfigCommandOptions): Promise<number> {\n const out = options.out ?? ((text: string) => process.stdout.write(text))\n const action = options.action ?? \"\"\n if (!ACTIONS.includes(action as (typeof ACTIONS)[number])) {\n const suggestion = nearest(action, [...ACTIONS])\n throw new HarnessError({\n code: \"cli_config_action_unknown\",\n message: `\"${action}\" is not something config does.`,\n hint: `One of: ${ACTIONS.join(\", \")}.${\n suggestion === undefined ? \"\" : ` Did you mean ${suggestion}?`\n }`,\n })\n }\n\n const manifestPath = resolveAgentRef(options.ref ?? \"\", options.sandboxEnv)\n\n switch (action) {\n case \"list\": {\n out(`${renderSettings(currentValues(manifestPath), manifestPath)}\\n`)\n // What is currently missing belongs here rather than on every `set`: this is the command\n // whose job is the overview, and a note repeated on unrelated edits is one nobody reads.\n const missing = unmet(\n envNeeds(manifestDocument(readFileSync(manifestPath, \"utf8\"))),\n agentEnv(manifestPath),\n )\n for (const need of missing) {\n out(`\\n${bullet(`${need.name} is not set — ${need.why}`)}\\n`)\n out(`${bullet(`\\`config env <agent> ${need.name}\\` fills it in`)}\\n`)\n }\n return EXIT_OK\n }\n case \"get\":\n return get(manifestPath, options, out)\n case \"set\":\n return await set(manifestPath, options, out)\n case \"env\":\n return await env(manifestPath, options, out)\n case \"edit\":\n return await edit(manifestPath, options, out)\n default:\n return await allow(manifestPath, options, out)\n }\n}\n\nfunction get(\n manifestPath: string,\n options: ConfigCommandOptions,\n out: (text: string) => void,\n): number {\n const path = (options.name ?? \"\").trim()\n const setting = requireSetting(path)\n const row = currentValues(manifestPath).find((entry) => entry.setting.path === setting.path)\n out(`${renderOne(setting, row?.value)}\\n`)\n return EXIT_OK\n}\n\nfunction requireSetting(path: string): Setting {\n // `model.fast` is the `model.<role>` row, the one placeholder a person fills in themselves.\n const found = settingByPath(path) ?? personSetting(path)\n if (found !== undefined) return found\n const suggestion = nearest(path, [...settablePaths()])\n throw new HarnessError({\n code: \"cli_config_path_unknown\",\n message: `\"${path}\" is not a setting.`,\n hint: `\\`config list <agent>\\` shows every one with its current value.${\n suggestion === undefined ? \"\" : ` Did you mean ${suggestion}?`\n }`,\n field: \"path\",\n })\n}\n\nasync function set(\n manifestPath: string,\n options: ConfigCommandOptions,\n out: (text: string) => void,\n): Promise<number> {\n const path = (options.name ?? \"\").trim()\n const setting = requireSetting(path)\n\n if (setting.via !== undefined) {\n throw new HarnessError({\n code: \"cli_config_needs_action\",\n message: `${setting.path} is not set by a dotted path.`,\n hint: `Use \\`${setting.via}\\` — it lives inside a list entry, and it gets its value checked against the service that issues it rather than written verbatim.`,\n field: \"path\",\n })\n }\n if (options.value === undefined) {\n throw new HarnessError({\n code: \"cli_config_value_missing\",\n message: `No value given for ${path}.`,\n hint: `A bare word, a number, a list as [\"a\", \"b\"], or a map as {k: v}. \\`config get <agent> ${path}\\` shows what it is now.`,\n field: \"value\",\n })\n }\n\n const value = parseSettingValue(options.value)\n\n // The confirmation, before anything is read or written. It is not a floor — these edits are the\n // person's to make — but both of them stop a check from running, and an edit whose whole effect is\n // invisible until something exploits it is worth one sentence and a keypress.\n const warning = confirmationFor(setting, value)\n if (warning !== undefined && options.yes !== true) {\n out(`${bullet(warning)}\\n`)\n const ask = options.confirm ?? askYesNo\n if (!(await ask(`Change ${setting.path} anyway?`))) {\n out(`${keyValue([{ label: \"unchanged\", value: setting.path }])}\\n`)\n return EXIT_OK\n }\n }\n\n // The agent's own layered environment, not this process's. `ambientEnv` alone does not do it: it\n // demotes a colliding cwd variable and never adds the agent's own file, so a token sitting beside\n // the manifest read as unset.\n const ambient = agentEnv(manifestPath)\n const before = unmet(\n envNeeds(manifestDocument(readFileSync(manifestPath, \"utf8\"))),\n ambient,\n ).map((need) => need.name)\n\n // `applySet` owns the write, so the editor and this command cannot validate a value differently.\n const result = await applySet(manifestPath, path, options.value)\n\n // Newly required only. Computed either side of the edit rather than guessed from the value, so\n // `server.enabled true` reports the token it has just made load-bearing and `limits.maxSteps 9`\n // reports nothing — which a live run got wrong in the other direction, warning that an agent with\n // a disabled server \"will refuse to start\".\n const pending = unmet(\n envNeeds(manifestDocument(readFileSync(manifestPath, \"utf8\"))),\n ambient,\n ).filter((need) => !before.includes(need.name))\n\n const held = await running(manifestPath, options)\n out(\n `${renderChange({\n path,\n before: result.before,\n after: value,\n file: manifestPath,\n reflowed: result.reflowed,\n ...(held === undefined ? {} : { running: held }),\n pending,\n restartHint: restartHint(held?.mode),\n })}\\n`,\n )\n return EXIT_OK\n}\n\n/**\n * How this agent comes back, phrased for how it is currently held.\n *\n * All three `RuntimeMode` values, because the generic sentence is useless for two of them. `embedded` is\n * the case that matters most and is easiest to miss: it is *this* session, so the answer is one word the\n * person can type — and a live run reported `pid 90050, embedded` under \"it is started again\", which is\n * true and gives them nothing.\n */\nfunction restartHint(mode: string | undefined): string {\n if (mode === \"daemon\") return \"`daemon restart <agent>`\"\n if (mode === \"embedded\") return \"`/restart` in this session\"\n if (mode === \"terminal\") return \"that process being started again\"\n return \"it is started again\"\n}\n\n/**\n * A live process holding this agent, or `undefined`.\n *\n * Never a refusal, only a note. Fixing a misconfiguration *while it is running and broken* is the main\n * thing this command is for, so refusing in that state would block the case it exists to serve.\n *\n * Liveness is re-checked rather than trusted: a lease row is a claim, and a boot that failed after\n * claiming leaves a row seconds old with no process under it — which once blocked every retry for\n * ninety seconds while naming a pid that no longer existed.\n */\nasync function running(\n manifestPath: string,\n options: ConfigCommandOptions,\n): Promise<{ readonly pid: number; readonly mode: string } | undefined> {\n let agentId: string | undefined\n try {\n agentId = readManifestHeader(manifestPath).id\n } catch {\n return undefined\n }\n if (agentId === undefined) return undefined\n\n try {\n const store = await SqliteStore.open({\n path: options.store ?? storePath(options.sandboxEnv),\n })\n try {\n for (const lease of await store.leases.all()) {\n if (lease.agentId !== agentId) continue\n if (!processAlive(lease.pid)) continue\n return { pid: lease.pid, mode: lease.mode }\n }\n } finally {\n await store.close()\n }\n } catch {\n // A missing or unreadable store is not a reason to refuse a manifest edit. The note is a\n // courtesy; the write is the command.\n return undefined\n }\n return undefined\n}\n\n/**\n * Put a secret in the `.env` beside the manifest.\n *\n * The value is prompted and never taken from an argument: an argument lands in shell history and in\n * `ps`, readable by every local process for the lifetime of the call. Not a TTY refuses rather than\n * reading a pipe, so a CI run is told nothing was written instead of a secret arriving from a source\n * the caller did not audit.\n *\n * Written 0600 whichever way the file arrived. Under a service manager this file is the *only* path\n * credentials take — launchd hands a job almost no environment and a plist carries none on purpose —\n * so tightening it is right even when this command did not create it.\n */\nasync function env(\n manifestPath: string,\n options: ConfigCommandOptions,\n out: (text: string) => void,\n): Promise<number> {\n const name = (options.name ?? \"\").trim()\n if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) {\n throw new HarnessError({\n code: \"cli_config_env_name_invalid\",\n message: `\"${name}\" is not an environment variable name.`,\n hint: \"Letters, digits and underscores, not starting with a digit — MODEL_API_KEY, TELEGRAM_BOT_TOKEN. `config list <agent>` shows which ones this agent names.\",\n field: \"name\",\n })\n }\n\n // Statically imported, not `await import`. A module reached both ways makes `bun build\n // --splitting` emit its exports twice and the binary refuses to parse — and `bun test` sails\n // through it, because tests import source and the failure is in the bundle. `confirm.ts` pulls in\n // only `node:readline`, so there is nothing to defer.\n const ask = options.secret ?? askSecret\n const value = await ask(`value for ${name} (not echoed):`)\n if (value === undefined) {\n throw new HarnessError({\n code: \"cli_config_env_no_value\",\n message: `Nothing was written for ${name}.`,\n hint: \"A secret is read from a prompt, never from an argument or a pipe — an argument is visible in `ps` and in shell history. Run this at a terminal, or edit the .env beside the manifest yourself.\",\n })\n }\n if (value === \"\") {\n throw new HarnessError({\n code: \"cli_config_env_empty\",\n message: `An empty value for ${name} would not start the agent.`,\n hint: \"A variable set to nothing fails the load exactly as a missing one does. Nothing was written.\",\n })\n }\n\n // The write itself is `applySecret`, which the editor calls too — two callers deciding separately\n // whether to tighten the file's mode is the same class of split as two manifest writers.\n const applied = applySecret(manifestPath, name, value)\n out(`${keyValue([{ label: \"set\", value: applied.note }])}\\n`)\n out(`${bullet(\"takes effect the next time the agent starts\")}\\n`)\n return EXIT_OK\n}\n\n/**\n * Add or remove a handle on a channel's `allowFrom`.\n *\n * Its own action rather than a `config set` path for two reasons. The source editor matches `key:` at\n * an indent and cannot index a sequence, so the field is not addressable — and rewriting the whole\n * `channels` list to change one handle is the dead end this command exists to remove. The second is\n * better: a handle can be *checked against the service that issues it*, and an impossible one is\n * otherwise a bot that is connected, healthy and silently refusing the one person it was set up for.\n */\nasync function allow(\n manifestPath: string,\n options: ConfigCommandOptions,\n out: (text: string) => void,\n): Promise<number> {\n const channels = manifestValueAt(readFileSync(manifestPath, \"utf8\"), [\"channels\"])\n if (!Array.isArray(channels) || channels.length === 0) {\n throw new HarnessError({\n code: \"cli_config_no_channels\",\n message: \"This agent has no channels, so there is nobody to allow.\",\n hint: \"`config set <agent> channels '[{type: telegram, id: tg, tokenEnv: TELEGRAM_BOT_TOKEN, mode: longpoll}]'` declares one first.\",\n })\n }\n\n const entries = channels.filter(\n (entry): entry is Record<string, unknown> =>\n typeof entry === \"object\" && entry !== null && !Array.isArray(entry),\n )\n const ids = entries.map((entry) => String(entry.id ?? \"\")).filter((id) => id !== \"\")\n const wanted = options.channel?.trim()\n if (wanted === undefined && entries.length > 1) {\n throw new HarnessError({\n code: \"cli_config_channel_ambiguous\",\n message: `This agent has ${entries.length} channels, so --channel says which.`,\n hint: `One of: ${ids.join(\", \")}.`,\n field: \"channel\",\n })\n }\n const at =\n wanted === undefined ? 0 : entries.findIndex((entry) => String(entry.id ?? \"\") === wanted)\n if (at === -1) {\n throw new HarnessError({\n code: \"cli_config_channel_unknown\",\n message: `No channel with id \"${wanted}\".`,\n hint: `Declared: ${ids.join(\", \")}.${\n nearest(wanted ?? \"\", ids) === undefined\n ? \"\"\n : ` Did you mean ${nearest(wanted ?? \"\", ids)}?`\n }`,\n field: \"channel\",\n })\n }\n\n const target = entries[at] as Record<string, unknown>\n const handle = checkedHandle(options.name ?? \"\", String(target.type ?? \"\"))\n const current = Array.isArray(target.allowFrom) ? target.allowFrom.map(String) : []\n\n const next =\n options.remove === true\n ? current.filter((entry) => entry !== handle)\n : current.includes(handle)\n ? current\n : [...current, handle]\n\n if (next.length === current.length && options.remove === true) {\n out(\n `${keyValue([\n { label: \"unchanged\", value: `${handle} was not on ${String(target.id)}` },\n ])}\\n`,\n )\n return EXIT_OK\n }\n if (next.length === current.length) {\n // Idempotent on purpose: running it twice is what somebody does when they are not sure it\n // took, and reporting a second write they did not make would be a small lie.\n out(\n `${keyValue([{ label: \"already allowed\", value: `${handle} on ${String(target.id)}` }])}\\n`,\n )\n return EXIT_OK\n }\n\n // `applyAllow` owns the write and the handle check, so the editor cannot validate a handle\n // differently from this command. It takes the whole list, because the whole list is what gets\n // written: one entry's key is not addressable by the source editor.\n const result = await applyAllow(manifestPath, String(target.id ?? \"\"), next)\n const held = await running(manifestPath, options)\n\n out(\n `${keyValue([\n { label: options.remove === true ? \"removed\" : \"allowed\", value: handle },\n { label: \"channel\", value: String(target.id) },\n { label: \"now\", value: showValue(next) },\n { label: \"file\", value: manifestPath },\n ])}\\n`,\n )\n if (result.reflowed) {\n out(`${bullet(\"the file was re-serialised — it is valid, and comments may have moved\")}\\n`)\n }\n if (held !== undefined) {\n out(\n `${bullet(\n `this agent is running (pid ${held.pid}, ${held.mode}) and holds its settings for its lifetime — the change applies after ${restartHint(held.mode)}`,\n )}\\n`,\n )\n }\n return EXIT_OK\n}\n\nexport const CONFIG_EXIT_FAILURE = EXIT_FAILURE\n\n/**\n * The editor, standalone.\n *\n * Alternate screen, because it waits for keys: it takes the terminal and gives it back. A changed flag\n * comes back through `onDone` so the one line printed afterwards can say a restart is needed — printed\n * on the real screen after the restore, because hard rule 8 does not stop applying when a screen closes.\n */\nasync function edit(\n manifestPath: string,\n options: ConfigCommandOptions,\n out: (text: string) => void,\n): Promise<number> {\n // Refused rather than attempted without a terminal. Two things went wrong otherwise, and the second\n // is the serious one: the alternate-screen sequence was written into a *pipe*, and Ink's own \"raw\n // mode is not supported\" error left the command exiting **0** — a failure that reported success,\n // which hard rule 8 exists to prevent. `browse` and `init` already ask this question the same way.\n const decision = resolveModeFromProcess({ plain: false, json: false, oneShot: false })\n if (decision.mode !== \"rich\") {\n throw new HarnessError({\n code: \"cli_config_edit_needs_terminal\",\n message: \"The settings editor needs a terminal.\",\n hint: `Not one here (${decision.because}). \\`config list\\` reads them and \\`config set\\` changes one, both of which work on a pipe.`,\n })\n }\n\n const [{ render }, { createElement }, { ConfigEditor }] = await Promise.all([\n import(\"ink\"),\n import(\"react\"),\n import(\"#components/ConfigEditor\"),\n ])\n\n let changed = false\n let finish: () => void = () => {}\n const closed = new Promise<void>((resolve) => {\n finish = resolve\n })\n\n markAltScreen()\n process.stdout.write(ENTER_ALT_SCREEN)\n\n // No wrapper component: the editor is a *view*, so it owns its own state and its single `useInput`,\n // exactly as `SkillBrowser` and `SessionPicker` do. Holding it here needed `useState` in this file,\n // which is a shared command path — and a static React import there costs ~170-210 ms on every\n // command including `validate --json`, which a boundaries test refuses outright.\n const instance = render(\n createElement(ConfigEditor, {\n rows: editorRowsFor(manifestPath),\n apply: (row: EditorRow, raw: string) => applyEditorRow(manifestPath, row, raw),\n reload: () => editorRowsFor(manifestPath),\n // A pty can report `columns === 0`, which `?? fallback` does not cover — measured, and it\n // once laid a picker's rows out for half the terminal, uniformly, on every row.\n columns: screenColumns(process.stdout.columns, FALLBACK_COLUMNS),\n window: MAX_SCREEN_ROWS,\n onDone: (didChange: boolean) => {\n changed = didChange\n finish()\n },\n }),\n { exitOnCtrlC: false, ...negotiateKeyboard() },\n )\n onExit(() => instance.unmount())\n await closed\n instance.unmount()\n restoreTerminal()\n await flushOutput()\n\n const held = await running(manifestPath, options)\n if (!changed) {\n out(`${keyValue([{ label: \"unchanged\", value: manifestPath }])}\\n`)\n return EXIT_OK\n }\n out(`${keyValue([{ label: \"changed\", value: manifestPath }])}\\n`)\n out(`${bullet(`takes effect after ${restartHint(held?.mode)}`)}\\n`)\n return EXIT_OK\n}\n"
6
6
  ],
7
7
  "mappings": ";mlBA8BA,uBAAS,gBAoET,IAAM,EAAU,CAAC,OAAQ,MAAO,MAAO,MAAO,QAAS,MAAM,EAatD,SAAS,CAAU,CACtB,EACA,EACA,EAA+B,CAAC,IAAS,QAAQ,OAAO,MAAM,CAAI,EACL,CAC7D,IAAM,GAAS,GAAS,IAAI,KAAK,EACjC,GAAI,IAAU,GAAI,MAAO,CAAE,OAAQ,OAAQ,IAAK,MAAU,EAC1D,GAAI,CAAC,EAAQ,SAAS,CAAiC,EACnD,MAAO,CAAE,OAAQ,OAAQ,IAAK,CAAM,EAExC,GAAI,IAAW,QAAa,EAAQ,SAAS,CAAkC,EAI3E,EAAK,kBAAkB,yBAA6B;AAAA,CAAwB,EAEhF,GAAI,IAAW,QAAa,IAAU,OAIlC,MAAO,CAAE,OAAQ,EAAO,IAAK,MAAU,EAE3C,MAAO,CAAE,OAAQ,EAAO,IAAK,CAAO,EAGjC,eAAe,CAAa,CAAC,EAAgD,CAChF,IAAM,EAAM,EAAQ,MAAQ,CAAC,IAAiB,QAAQ,OAAO,MAAM,CAAI,GACjE,EAAS,EAAQ,QAAU,GACjC,GAAI,CAAC,EAAQ,SAAS,CAAkC,EAAG,CACvD,IAAM,EAAa,EAAQ,EAAQ,CAAC,GAAG,CAAO,CAAC,EAC/C,MAAM,IAAI,EAAa,CACnB,KAAM,4BACN,QAAS,IAAI,mCACb,KAAM,WAAW,EAAQ,KAAK,IAAI,KAC9B,IAAe,OAAY,GAAK,iBAAiB,MAEzD,CAAC,EAGL,IAAM,EAAe,GAAgB,EAAQ,KAAO,GAAI,EAAQ,UAAU,E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V,EAAqB,IAAM,GACzB,EAAS,IAAI,QAAc,CAAC,IAAY,CAC1C,EAAS,EACZ,EAED,GAAc,EACd,QAAQ,OAAO,MAAM,EAAgB,EAMrC,IAAM,EAAW,EACb,EAAc,EAAc,CACxB,KAAM,GAAc,CAAY,EAChC,MAAO,CAAC,EAAgB,IAAgB,GAAe,EAAc,EAAK,CAAG,EAC7E,OAAQ,IAAM,GAAc,CAAY,EAGxC,QAAS,GAAc,QAAQ,OAAO,QAAS,EAAgB,EAC/D,OAAQ,GACR,OAAQ,CAAC,IAAuB,CAC5B,EAAU,EACV,EAAO,EAEf,CAAC,EACD,CAAE,YAAa,MAAU,GAAkB,CAAE,CACjD,EACA,EAAO,IAAM,EAAS,QAAQ,CAAC,EAC/B,MAAM,EACN,EAAS,QAAQ,EACjB,GAAgB,EAChB,MAAM,GAAY,EAElB,IAAM,EAAO,MAAM,EAAQ,EAAc,CAAO,EAChD,GAAI,CAAC,EAED,OADA,EAAI,GAAG,EAAS,CAAC,CAAE,MAAO,YAAa,MAAO,CAAa,CAAC,CAAC;AAAA,CAAK,EAC3D,EAIX,OAFA,EAAI,GAAG,EAAS,CAAC,CAAE,MAAO,UAAW,MAAO,CAAa,CAAC,CAAC;AAAA,CAAK,EAChE,EAAI,GAAG,EAAO,sBAAsB,EAAY,GAAM,IAAI,GAAG;AAAA,CAAK,EAC3D",
8
- "debugId": "0F7D8BAF905549FC64756E2164756E21",
8
+ "debugId": "F6F673540A8E070764756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ import{t,Dr}from"./index-26ejkp8q.js";import"./index-z0dgxd7d.js";import"./index-4t3p7vm9.js";import{At}from"./index-twcgf73h.js";import{Je,ut,gn,Xn}from"./index-xa9crtzq.js";import"./index-0mz7wpbw.js";function g(e){let n=/^(\d+)\s*(s|m|h|d)?$/.exec(e.trim());if(n===null)throw new At({code:"credential_usage",message:`--expires ${JSON.stringify(e)} is not a duration.`,hint:"Write it as 30s, 15m, 2h or 7d — or as a plain number of seconds."});let i=Number(n[1]);if(i===0)throw new At({code:"credential_usage",message:"--expires 0 would mint a credential that has already expired.",hint:"Leave the flag off for a key that never expires, or give it a real duration like 1h."});let s={s:1,m:60,h:3600,d:86400}[n[2]??"s"]??1;return i*s}function y(e){let n=e.split(",").map((s)=>s.trim().toLowerCase()).filter((s)=>s!==""),i=n.filter((s)=>!Dr.includes(s));if(i.length>0)throw new At({code:"credential_usage",message:`--can names ${i.map((s)=>JSON.stringify(s)).join(", ")}, which is not a capability.`,hint:`They are: ${Dr.join(", ")}. read is every GET; chat sends a message, answers an approval and stops a turn; write covers schedules, phase and clearing a session; admin covers credentials, provisioning and start/stop; peer reaches only a plugin route that asks for it (an A2A endpoint).`});return n}function f(e){return e.split(",").map((n)=>n.trim()).filter((n)=>n!=="")}function l(e){let n=[];if(n.push(e.scope?.agents===void 0?"every agent":e.scope.agents.join(", ")),e.scope?.sessions!==void 0)n.push(`sessions ${e.scope.sessions}`);if(n.push(e.scope?.can===void 0?"all capabilities":e.scope.can.join("+")),e.expiresAt!==void 0)n.push(`until ${e.expiresAt}`);return n.join(" · ")}async function d(e){let n=await Je(e);if(n===void 0)throw new At({code:"credential_usage",message:"No server is running, so there is nothing to mint a credential on.",hint:`A credential belongs to a server rather than to a file, so this command is an API client. Start one with \`${t.slug} serve\`, or use POST /v1/keys directly against a server you can already reach.`});return{lease:n,manifest:Xn(n.agentId)}}async function v(e){if(e.action==="create")return await h(e);if(e.action==="list")return await p(e);if(e.action==="revoke")return await m(e);throw new At({code:"credential_usage",message:`Unknown action ${JSON.stringify(e.action)}.`,hint:"The actions are create, list and revoke."})}async function h(e){let n=e.label?.trim();if(n===void 0||n==="")throw new At({code:"credential_usage",message:"--label is required.",hint:'A label is the only thing distinguishing two credentials in a listing, and "key 2" is a name nobody can act on when deciding which to revoke.'});let i={...e.agents===void 0?{}:{agents:f(e.agents)},...e.sessions===void 0?{}:{sessions:e.sessions},...e.can===void 0?{}:{can:y(e.can)},...e.expires===void 0?{}:{expiresIn:g(e.expires)}},{lease:s,manifest:o}=await d(e.store),a=await ut(s,"/v1/keys",{label:n,...Object.keys(i).length===0?{}:{scope:i}},o);if(!a.ok)return c(a,"mint a credential");let r=a.body;if(e.json===!0)return process.stdout.write(`${JSON.stringify(r,null,2)}
3
+ `),0;return process.stdout.write(`${r.secret}
4
+ `),process.stderr.write(` ${r.label} · ${r.keyId}
5
+ `),process.stderr.write(` reaches ${l(r)}
6
+ `),process.stderr.write(` This is the only time the secret is shown. It is stored as a fingerprint and no route returns it.
7
+ `),0}async function p(e){let{lease:n,manifest:i}=await d(e.store),s=await gn(n,"GET","/v1/keys",i);if(!s.ok)return c(s,"list credentials");let o=s.body,a=o.keys??[];if(e.json===!0)return process.stdout.write(`${JSON.stringify(o,null,2)}
8
+ `),0;if(a.length===0)return process.stdout.write(`No credentials. The server token is the only way in.
9
+ `),0;for(let r of a){let u=r.revokedAt===void 0?"live":"revoked";process.stdout.write(`${r.keyId} ${u.padEnd(7)} ${r.label}
10
+ `),process.stdout.write(` reaches ${l(r)}
11
+ `),process.stdout.write(` created ${r.createdAt}${r.lastUsedAt===void 0?" · never used":` · last used ${r.lastUsedAt}`}
12
+ `)}return 0}async function m(e){let n=e.keyId?.trim();if(n===void 0||n==="")throw new At({code:"credential_usage",message:"Which credential?",hint:`\`${t.slug} credential list\` prints the ids. Revoking is permanent — a revoked secret can never be re-presented.`});let{lease:i,manifest:s}=await d(e.store),o=await gn(i,"DELETE",`/v1/keys/${encodeURIComponent(n)}`,s);if(!o.ok)return c(o,"revoke that credential");let a=o.body;if(e.json===!0)return process.stdout.write(`${JSON.stringify(a,null,2)}
13
+ `),0;return process.stdout.write(`revoked ${a.keyId} · ${a.label}
14
+ `),0}function c(e,n){if(process.stderr.write(`Could not ${n}${e.status===0?"":` (${e.status})`}: ${e.detail??"the host did not answer"}
15
+ `),e.hint!==void 0)process.stderr.write(` hint: ${e.hint}
16
+ `);return 1}export{v as credentialCommand};
17
+
18
+ //# debugId=1935DBB32E768DA664756E2164756E21
19
+ //# sourceMappingURL=credential-pkme1sfe.js.map
@@ -5,6 +5,6 @@
5
5
  "/**\n * Operator credentials from a terminal: mint one, list them, revoke one.\n *\n * ## Why this is not called `keys`\n *\n * The `keys` command already exists and prints the bytes a terminal sends for a chord — a keyboard\n * diagnostic, nothing to do with credentials. Two unrelated meanings under one verb is the kind of\n * collision that costs somebody a confused minute every time they reach for either, so the new\n * surface takes the word the code and the spec already use for the thing: a **credential**.\n * `token` was the other candidate and loses to `server.tokenEnv`, which is a different credential\n * this command cannot mint or revoke.\n *\n * ## Why it talks to a running server rather than the store\n *\n * A key is a fingerprint in the shared store, so writing one directly would work — and would\n * bypass every check `POST /v1/keys` performs: the label rule, the scope validation, and the\n * refusal of a scope naming an agent that does not exist. That is the *\"a check only one surface\n * performs is a check the two disagree about\"* shape, on the surface where disagreeing means a\n * credential that the API would never have issued. So this is an HTTP client, and it says so when\n * there is no server to talk to.\n */\n\nimport { BRAND, CAPABILITIES, type Capability } from \"@dispach/core\"\nimport { UsageError } from \"#lib/args\"\nimport { anyLiveHost, callHost, manifestForId, postToHost } from \"#lib/lifecycle\"\n\nexport interface CredentialOptions {\n readonly action: string\n readonly keyId?: string\n readonly label?: string\n readonly agents?: string\n readonly sessions?: string\n readonly can?: string\n readonly expires?: string\n readonly json?: boolean\n readonly store?: string\n}\n\n/**\n * `1h`, `30m`, `7d`, `90s`, or plain seconds — into whole seconds.\n *\n * A suffix because \"how long should this credential live\" is a question people answer in hours and\n * days, and `3600` is a number somebody has to compute and can get wrong by a factor of sixty. Bare\n * digits stay accepted, since that is what the wire takes and a script already has the number.\n */\nexport function parseDuration(raw: string): number {\n const match = /^(\\d+)\\s*(s|m|h|d)?$/.exec(raw.trim())\n if (match === null) {\n throw new UsageError({\n code: \"credential_usage\",\n message: `--expires ${JSON.stringify(raw)} is not a duration.`,\n hint: \"Write it as 30s, 15m, 2h or 7d — or as a plain number of seconds.\",\n })\n }\n const value = Number(match[1])\n if (value === 0) {\n throw new UsageError({\n code: \"credential_usage\",\n message: \"--expires 0 would mint a credential that has already expired.\",\n hint: \"Leave the flag off for a key that never expires, or give it a real duration like 1h.\",\n })\n }\n const unit = { s: 1, m: 60, h: 3600, d: 86_400 }[match[2] ?? \"s\"] ?? 1\n return value * unit\n}\n\n/** `chat,read` → the capabilities, refusing anything that is not one rather than dropping it. */\nexport function parseCapabilities(raw: string): readonly Capability[] {\n const names = raw\n .split(\",\")\n .map((entry) => entry.trim().toLowerCase())\n .filter((entry) => entry !== \"\")\n const unknown = names.filter((name) => !(CAPABILITIES as readonly string[]).includes(name))\n if (unknown.length > 0) {\n throw new UsageError({\n code: \"credential_usage\",\n message: `--can names ${unknown.map((name) => JSON.stringify(name)).join(\", \")}, which is not a capability.`,\n hint: `They are: ${CAPABILITIES.join(\", \")}. read is every GET; chat sends a message, answers an approval and stops a turn; write covers schedules, phase and clearing a session; admin covers credentials, provisioning and start/stop; peer reaches only a plugin route that asks for it (an A2A endpoint).`,\n })\n }\n // An empty list is *not* silently promoted to \"everything\": `--can \"\"` is a key that may do\n // nothing, which is a coherent thing to ask for and a confusing thing to be given instead.\n return names as readonly Capability[]\n}\n\n/** A comma list into ids, with the empty entries dropped rather than sent as `\"\"`. */\nfunction parseList(raw: string): readonly string[] {\n return raw\n .split(\",\")\n .map((entry) => entry.trim())\n .filter((entry) => entry !== \"\")\n}\n\ninterface KeyLike {\n readonly keyId: string\n readonly label: string\n readonly createdAt: string\n readonly lastUsedAt?: string\n readonly revokedAt?: string\n readonly expiresAt?: string\n readonly scope?: {\n readonly agents?: readonly string[]\n readonly sessions?: string\n readonly can?: readonly string[]\n }\n}\n\n/**\n * One line describing what a key reaches, for a listing.\n *\n * **Printed back after minting too**, which is the half that matters: a prefix is not a namespace —\n * `team_4` also matches `team_42:x` — so showing what the scope *says* at the moment it is created\n * is the only cheap place to notice that it says something other than what was meant. The same\n * argument `telegramHandle` makes about a username that cannot exist.\n */\nexport function describeScope(key: KeyLike): string {\n const parts: string[] = []\n parts.push(key.scope?.agents === undefined ? \"every agent\" : key.scope.agents.join(\", \"))\n if (key.scope?.sessions !== undefined) parts.push(`sessions ${key.scope.sessions}`)\n parts.push(key.scope?.can === undefined ? \"all capabilities\" : key.scope.can.join(\"+\"))\n if (key.expiresAt !== undefined) parts.push(`until ${key.expiresAt}`)\n return parts.join(\" · \")\n}\n\n/** The host to ask, or a refusal naming why there is none. */\nasync function host(store?: string) {\n const lease = await anyLiveHost(store)\n if (lease === undefined) {\n throw new UsageError({\n code: \"credential_usage\",\n message: \"No server is running, so there is nothing to mint a credential on.\",\n hint: `A credential belongs to a server rather than to a file, so this command is an API client. Start one with \\`${BRAND.slug} serve\\`, or use POST /v1/keys directly against a server you can already reach.`,\n })\n }\n return { lease, manifest: manifestForId(lease.agentId) }\n}\n\nexport async function credentialCommand(options: CredentialOptions): Promise<number> {\n if (options.action === \"create\") return await create(options)\n if (options.action === \"list\") return await list(options)\n if (options.action === \"revoke\") return await revoke(options)\n throw new UsageError({\n code: \"credential_usage\",\n message: `Unknown action ${JSON.stringify(options.action)}.`,\n hint: \"The actions are create, list and revoke.\",\n })\n}\n\nasync function create(options: CredentialOptions): Promise<number> {\n const label = options.label?.trim()\n if (label === undefined || label === \"\") {\n throw new UsageError({\n code: \"credential_usage\",\n message: \"--label is required.\",\n hint: 'A label is the only thing distinguishing two credentials in a listing, and \"key 2\" is a name nobody can act on when deciding which to revoke.',\n })\n }\n const scope = {\n ...(options.agents === undefined ? {} : { agents: parseList(options.agents) }),\n ...(options.sessions === undefined ? {} : { sessions: options.sessions }),\n ...(options.can === undefined ? {} : { can: parseCapabilities(options.can) }),\n ...(options.expires === undefined ? {} : { expiresIn: parseDuration(options.expires) }),\n }\n\n const { lease, manifest } = await host(options.store)\n const reply = await postToHost(\n lease,\n \"/v1/keys\",\n { label, ...(Object.keys(scope).length === 0 ? {} : { scope }) },\n manifest,\n )\n if (!reply.ok) return refused(reply, \"mint a credential\")\n\n const key = reply.body as KeyLike & { readonly secret: string }\n if (options.json === true) {\n process.stdout.write(`${JSON.stringify(key, null, 2)}\\n`)\n return 0\n }\n /**\n * The secret, on its own line, **once**.\n *\n * It is not stored anywhere in a readable form and no route returns it again, so this is the\n * only moment it exists outside the caller's memory. Printed bare rather than inside a sentence\n * so that copying the line copies the credential and nothing else.\n */\n process.stdout.write(`${key.secret}\\n`)\n process.stderr.write(` ${key.label} · ${key.keyId}\\n`)\n process.stderr.write(` reaches ${describeScope(key)}\\n`)\n process.stderr.write(\n \" This is the only time the secret is shown. It is stored as a fingerprint and no route returns it.\\n\",\n )\n return 0\n}\n\nasync function list(options: CredentialOptions): Promise<number> {\n const { lease, manifest } = await host(options.store)\n const reply = await callHost(lease, \"GET\", \"/v1/keys\", manifest)\n if (!reply.ok) return refused(reply, \"list credentials\")\n\n const body = reply.body as { readonly keys?: readonly KeyLike[]; readonly scope?: string }\n const keys = body.keys ?? []\n if (options.json === true) {\n process.stdout.write(`${JSON.stringify(body, null, 2)}\\n`)\n return 0\n }\n if (keys.length === 0) {\n process.stdout.write(\"No credentials. The server token is the only way in.\\n\")\n return 0\n }\n for (const key of keys) {\n // Revoked ones are shown rather than hidden, the same as the API's listing: the row is the\n // only record a credential ever existed, and hiding it makes a revocation unverifiable.\n const state = key.revokedAt === undefined ? \"live\" : \"revoked\"\n process.stdout.write(`${key.keyId} ${state.padEnd(7)} ${key.label}\\n`)\n process.stdout.write(` reaches ${describeScope(key)}\\n`)\n process.stdout.write(\n ` created ${key.createdAt}${key.lastUsedAt === undefined ? \" · never used\" : ` · last used ${key.lastUsedAt}`}\\n`,\n )\n }\n return 0\n}\n\nasync function revoke(options: CredentialOptions): Promise<number> {\n const keyId = options.keyId?.trim()\n if (keyId === undefined || keyId === \"\") {\n throw new UsageError({\n code: \"credential_usage\",\n message: \"Which credential?\",\n hint: `\\`${BRAND.slug} credential list\\` prints the ids. Revoking is permanent — a revoked secret can never be re-presented.`,\n })\n }\n const { lease, manifest } = await host(options.store)\n const reply = await callHost(lease, \"DELETE\", `/v1/keys/${encodeURIComponent(keyId)}`, manifest)\n if (!reply.ok) return refused(reply, \"revoke that credential\")\n const key = reply.body as KeyLike\n if (options.json === true) {\n process.stdout.write(`${JSON.stringify(key, null, 2)}\\n`)\n return 0\n }\n process.stdout.write(`revoked ${key.keyId} · ${key.label}\\n`)\n return 0\n}\n\n/** The server's own words, not a paraphrase — it knows why far better than this command does. */\nfunction refused(reply: { status: number; detail?: string; hint?: string }, what: string): number {\n process.stderr.write(\n `Could not ${what}${reply.status === 0 ? \"\" : ` (${reply.status})`}: ${reply.detail ?? \"the host did not answer\"}\\n`,\n )\n if (reply.hint !== undefined) process.stderr.write(` hint: ${reply.hint}\\n`)\n return 1\n}\n"
6
6
  ],
7
7
  "mappings": ";2MA6CO,SAAS,CAAa,CAAC,EAAqB,CAC/C,IAAM,EAAQ,uBAAuB,KAAK,EAAI,KAAK,CAAC,EACpD,GAAI,IAAU,KACV,MAAM,IAAI,GAAW,CACjB,KAAM,mBACN,QAAS,aAAa,KAAK,UAAU,CAAG,uBACxC,KAAM,mEACV,CAAC,EAEL,IAAM,EAAQ,OAAO,EAAM,EAAE,EAC7B,GAAI,IAAU,EACV,MAAM,IAAI,GAAW,CACjB,KAAM,mBACN,QAAS,gEACT,KAAM,sFACV,CAAC,EAEL,IAAM,EAAO,CAAE,EAAG,EAAG,EAAG,GAAI,EAAG,KAAM,EAAG,KAAO,EAAE,EAAM,IAAM,MAAQ,EACrE,OAAO,EAAQ,EAIZ,SAAS,CAAiB,CAAC,EAAoC,CAClE,IAAM,EAAQ,EACT,MAAM,GAAG,EACT,IAAI,CAAC,IAAU,EAAM,KAAK,EAAE,YAAY,CAAC,EACzC,OAAO,CAAC,IAAU,IAAU,EAAE,EAC7B,EAAU,EAAM,OAAO,CAAC,IAAS,CAAE,GAAmC,SAAS,CAAI,CAAC,EAC1F,GAAI,EAAQ,OAAS,EACjB,MAAM,IAAI,GAAW,CAC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Aa,IAAO,EAAM,SAAW,EAAI,GAAK,KAAK,EAAM,cAAc,EAAM,QAAU;AAAA,CAC3F,EACI,EAAM,OAAS,OAAW,QAAQ,OAAO,MAAM,WAAW,EAAM;AAAA,CAAQ,EAC5E,MAAO",
8
- "debugId": "383B792CF43C9ED864756E2164756E21",
8
+ "debugId": "1935DBB32E768DA664756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import{A,j,t,G,Bn}from"./index-1h9pqnec.js";import{existsSync as l,mkdirSync as R,readdirSync as y,readFileSync as w,statSync as p,writeFileSync as S}from"node:fs";import{homedir as P}from"node:os";import{isAbsolute as k,join as i,resolve as m,sep as x}from"node:path";function f(n){return n!==void 0&&n!==""}function WA(n=process.env){return{noColor:f(n.NO_COLOR),dumbTerminal:n.TERM==="dumb",ci:f(n.CI)&&n.CI!=="false",debug:f(n.DEBUG),sandboxHome:f(n[`${A.envPrefix}HOME`])?n[`${A.envPrefix}HOME`]:void 0,noEnhancedKeys:f(n[`${A.envPrefix}NO_CSI_U`])}}function we(n=process.env){return WA(n).sandboxHome??i(P(),A.stateDir)}function ie(n){return i(we(n),"agents")}function mr(n){return i(we(n),"templates")}function F(n){return i(we(n),"store.db")}function se(n){return i(we(n),"plugins")}function Sr(n,e){return i(se(e),n)}function uo(n){let e=i(we(n),"logs","server");return{out:i(e,"out.log"),err:i(e,"err.log")}}function un(n,e){let o=i(we(e),"logs");return{out:i(o,`${n}.out.log`),err:i(o,`${n}.err.log`)}}function b(n){return i(n,".api-token")}function En(n){try{let e=w(b(n),"utf8").trim();return e===""?void 0:e}catch{return}}function $r(n,e){R(n,{recursive:!0}),S(b(n),`${e}
3
- `,{encoding:"utf8",mode:384})}function ks(n,e){let o=En(n);if(o!==void 0)return o;let s=[];try{s=y(n).sort()}catch{}let g=s.map((r)=>Bn(i(n,r))[`${A.envPrefix}API_TOKEN`]).find((r)=>r!==void 0&&r!=="")??e();return $r(n,g),g}function Ft(n,e){let o=m(ie(e)),s=m(n);return s===o||s.startsWith(o+x)}function Ls(n,e){if(Ft(n,e))return;return`note: ${m(n)} is outside the sandbox (${ie(e)}) — this agent has no bare name, so every later command needs its path. Omit --dir to put it in the sandbox.`}function Ae(n){let e=ie(n),o;try{o=y(e)}catch{return[]}let s=[];for(let r of o.sort()){let c=i(e,r),a=i(c,"agent.yaml");try{if(!p(c).isDirectory())continue}catch{continue}if(!l(a))continue;let h=0;try{h=p(a).mtimeMs}catch{}try{let u=G(a);s.push({ref:r,dir:c,manifestPath:a,mtimeMs:h,...u.id===void 0?{}:{id:u.id},...u.name===void 0?{}:{name:u.name},...u.modelId===void 0?{}:{modelId:u.modelId}})}catch(u){s.push({ref:r,dir:c,manifestPath:a,mtimeMs:h,problem:u instanceof Error?u.message:String(u)})}}let d=new Map;for(let r of s){if(r.id===void 0)continue;d.set(r.id,[...d.get(r.id)??[],r])}let g=s.map((r)=>{if(r.id===void 0||(d.get(r.id)?.length??0)<2)return r;return{...r,problem:`manifest id "${r.id}" is shared with another sandbox agent — their sessions share one history`}});return[...g.filter((r)=>r.problem===void 0),...g.filter((r)=>r.problem!==void 0)]}function Fe(n,e,o=process.cwd()){let s=n.includes(x)||n.includes("/")||n.endsWith(".yaml")||n.endsWith(".yml"),d=k(n)?n:m(o,n);if(!s&&l(d)&&l(i(ie(e),n)))process.stderr.write(`note: using ./${n} from the current directory; a sandbox agent "${n}" also exists — run it from elsewhere, or as ${i(ie(e),n)}
4
- `);if(s||l(d)){if(l(d)){if(p(d).isDirectory()){let a=i(d,"agent.yaml");if(l(a))return a;throw new t({code:"cli_agent_dir_without_manifest",message:`${n} is a directory with no agent.yaml inside.`,hint:"Point at the manifest itself, or at a directory that holds one. Sandbox agents are run by bare name, with no path separators."})}return d}throw new t({code:"cli_agent_path_missing",message:`${n} looks like a path, and nothing is there.`,hint:`Paths resolve against the current directory. For an agent in the sandbox, use its bare name — \`${A.slug} run <name>\` — which resolves under ${ie(e)}.`})}let g=i(ie(e),n,"agent.yaml");if(l(g))return g;let r=Ae(e).map((a)=>a.ref),c=j(n,r);throw new t({code:"cli_agent_unknown",message:`No agent named "${n}" in the sandbox${r.length===0?", which is empty":""}.`,hint:r.length===0?`Create one with \`${A.slug} init\`, or pass a path to an agent.yaml.`:`Known agents: ${r.join(", ")}.${c===void 0?"":` Did you mean ${c}?`} A path (./dir or file.yaml) is also accepted.`})}
5
- export{WA,we,ie,mr,F,se,Sr,uo,un,En,$r,ks,Ft,Ls,Ae,Fe};
2
+ import{t,j,A,G,hn}from"./index-26ejkp8q.js";import{existsSync as l,mkdirSync as R,readdirSync as y,readFileSync as w,statSync as p,writeFileSync as S}from"node:fs";import{homedir as P}from"node:os";import{isAbsolute as k,join as i,resolve as m,sep as x}from"node:path";function f(n){return n!==void 0&&n!==""}function Wt(n=process.env){return{noColor:f(n.NO_COLOR),dumbTerminal:n.TERM==="dumb",ci:f(n.CI)&&n.CI!=="false",debug:f(n.DEBUG),sandboxHome:f(n[`${t.envPrefix}HOME`])?n[`${t.envPrefix}HOME`]:void 0,noEnhancedKeys:f(n[`${t.envPrefix}NO_CSI_U`])}}function we(n=process.env){return Wt(n).sandboxHome??i(P(),t.stateDir)}function ie(n){return i(we(n),"agents")}function mr(n){return i(we(n),"templates")}function F(n){return i(we(n),"store.db")}function se(n){return i(we(n),"plugins")}function Sr(n,e){return i(se(e),n)}function uo(n){let e=i(we(n),"logs","server");return{out:i(e,"out.log"),err:i(e,"err.log")}}function dn(n,e){let o=i(we(e),"logs");return{out:i(o,`${n}.out.log`),err:i(o,`${n}.err.log`)}}function b(n){return i(n,".api-token")}function En(n){try{let e=w(b(n),"utf8").trim();return e===""?void 0:e}catch{return}}function $r(n,e){R(n,{recursive:!0}),S(b(n),`${e}
3
+ `,{encoding:"utf8",mode:384})}function ks(n,e){let o=En(n);if(o!==void 0)return o;let s=[];try{s=y(n).sort()}catch{}let g=s.map((r)=>hn(i(n,r))[`${t.envPrefix}API_TOKEN`]).find((r)=>r!==void 0&&r!=="")??e();return $r(n,g),g}function FA(n,e){let o=m(ie(e)),s=m(n);return s===o||s.startsWith(o+x)}function Ls(n,e){if(FA(n,e))return;return`note: ${m(n)} is outside the sandbox (${ie(e)}) — this agent has no bare name, so every later command needs its path. Omit --dir to put it in the sandbox.`}function te(n){let e=ie(n),o;try{o=y(e)}catch{return[]}let s=[];for(let r of o.sort()){let c=i(e,r),a=i(c,"agent.yaml");try{if(!p(c).isDirectory())continue}catch{continue}if(!l(a))continue;let h=0;try{h=p(a).mtimeMs}catch{}try{let u=G(a);s.push({ref:r,dir:c,manifestPath:a,mtimeMs:h,...u.id===void 0?{}:{id:u.id},...u.name===void 0?{}:{name:u.name},...u.modelId===void 0?{}:{modelId:u.modelId}})}catch(u){s.push({ref:r,dir:c,manifestPath:a,mtimeMs:h,problem:u instanceof Error?u.message:String(u)})}}let d=new Map;for(let r of s){if(r.id===void 0)continue;d.set(r.id,[...d.get(r.id)??[],r])}let g=s.map((r)=>{if(r.id===void 0||(d.get(r.id)?.length??0)<2)return r;return{...r,problem:`manifest id "${r.id}" is shared with another sandbox agent — their sessions share one history`}});return[...g.filter((r)=>r.problem===void 0),...g.filter((r)=>r.problem!==void 0)]}function Fe(n,e,o=process.cwd()){let s=n.includes(x)||n.includes("/")||n.endsWith(".yaml")||n.endsWith(".yml"),d=k(n)?n:m(o,n);if(!s&&l(d)&&l(i(ie(e),n)))process.stderr.write(`note: using ./${n} from the current directory; a sandbox agent "${n}" also exists — run it from elsewhere, or as ${i(ie(e),n)}
4
+ `);if(s||l(d)){if(l(d)){if(p(d).isDirectory()){let a=i(d,"agent.yaml");if(l(a))return a;throw new A({code:"cli_agent_dir_without_manifest",message:`${n} is a directory with no agent.yaml inside.`,hint:"Point at the manifest itself, or at a directory that holds one. Sandbox agents are run by bare name, with no path separators."})}return d}throw new A({code:"cli_agent_path_missing",message:`${n} looks like a path, and nothing is there.`,hint:`Paths resolve against the current directory. For an agent in the sandbox, use its bare name — \`${t.slug} run <name>\` — which resolves under ${ie(e)}.`})}let g=i(ie(e),n,"agent.yaml");if(l(g))return g;let r=te(e).map((a)=>a.ref),c=j(n,r);throw new A({code:"cli_agent_unknown",message:`No agent named "${n}" in the sandbox${r.length===0?", which is empty":""}.`,hint:r.length===0?`Create one with \`${t.slug} init\`, or pass a path to an agent.yaml.`:`Known agents: ${r.join(", ")}.${c===void 0?"":` Did you mean ${c}?`} A path (./dir or file.yaml) is also accepted.`})}
5
+ export{Wt,we,ie,mr,F,se,Sr,uo,dn,En,$r,ks,FA,Ls,te,Fe};
6
6
 
7
- //# debugId=5DED1E57C009FB3664756E2164756E21
8
- //# sourceMappingURL=index-dwxmy0kx.js.map
7
+ //# debugId=E4534B796AA6A8D964756E2164756E21
8
+ //# sourceMappingURL=index-0mz7wpbw.js.map
@@ -6,6 +6,6 @@
6
6
  "/**\n * Every environment read the CLI makes.\n *\n * Centralised for the same reason termheat centralises it: an environment variable consulted deep\n * inside a component is untestable and invisible. Everything downstream takes an `EnvFacts` value,\n * so the interesting logic — `resolveMode` especially — is a pure function of its inputs.\n */\n\nimport { BRAND } from \"@dispach/core\"\nimport type { EnvFacts } from \"#lib/types\"\n\n/**\n * `NO_COLOR` is honoured when present and non-empty, per no-color.org. An exported-but-empty\n * variable is a container passing through something unset, not a stated preference.\n */\nfunction isSet(value: string | undefined): boolean {\n return value !== undefined && value !== \"\"\n}\n\nexport function readEnv(env: Readonly<Record<string, string | undefined>> = process.env): EnvFacts {\n return {\n noColor: isSet(env.NO_COLOR),\n dumbTerminal: env.TERM === \"dumb\",\n // `CI=false` is set by tooling that wants to say \"not CI\", and taking it literally would\n // strip interactivity from a terminal that has it.\n ci: isSet(env.CI) && env.CI !== \"false\",\n debug: isSet(env.DEBUG),\n // The sandbox root override, `<ENVPREFIX>HOME`. Brand-derived so a rename moves it.\n sandboxHome: isSet(env[`${BRAND.envPrefix}HOME`])\n ? env[`${BRAND.envPrefix}HOME`]\n : undefined,\n // Brand-derived like the sandbox root above, so a rename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