oneie 5.8.0 → 5.9.0

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 (270) hide show
  1. package/README.md +114 -6
  2. package/dist/package.json +37 -11
  3. package/dist/src/age-1k8hs4ec.js +1 -0
  4. package/dist/src/client-n6fpnd9f.js +1 -0
  5. package/dist/src/evm-tx-cqhm9rtt.js +1 -0
  6. package/dist/src/hl-run-0pv1e0p2.js +1 -0
  7. package/dist/src/index-f5vhzspa.js +12 -0
  8. package/dist/src/index-h3nrt8bx.js +4 -0
  9. package/dist/src/index-st6k9vhc.js +2062 -0
  10. package/dist/src/index.js +1122 -134
  11. package/dist/src/message-key-yczrxszr.js +1 -0
  12. package/dist/src/message-lock-thr851d5.js +5 -0
  13. package/dist/src/sweep-order-jrq2hkye.js +1 -0
  14. package/dist/src/sweep-runner-jftw9em7.js +1 -0
  15. package/package.json +37 -11
  16. package/dist/src/agent.d.ts +0 -75
  17. package/dist/src/agent.js +0 -1334
  18. package/dist/src/agentverse.d.ts +0 -26
  19. package/dist/src/agentverse.js +0 -171
  20. package/dist/src/args.d.ts +0 -9
  21. package/dist/src/args.js +0 -61
  22. package/dist/src/auth.d.ts +0 -6
  23. package/dist/src/auth.js +0 -121
  24. package/dist/src/balances.d.ts +0 -89
  25. package/dist/src/balances.js +0 -202
  26. package/dist/src/banner.d.ts +0 -1
  27. package/dist/src/banner.js +0 -17
  28. package/dist/src/broadcast.d.ts +0 -8
  29. package/dist/src/broadcast.js +0 -175
  30. package/dist/src/catalog.d.ts +0 -12
  31. package/dist/src/catalog.js +0 -76
  32. package/dist/src/ceiling.d.ts +0 -36
  33. package/dist/src/ceiling.js +0 -189
  34. package/dist/src/chat.d.ts +0 -2
  35. package/dist/src/chat.js +0 -92
  36. package/dist/src/check.d.ts +0 -11
  37. package/dist/src/check.js +0 -53
  38. package/dist/src/client.d.ts +0 -5
  39. package/dist/src/client.js +0 -157
  40. package/dist/src/compiler.d.ts +0 -36
  41. package/dist/src/compiler.js +0 -366
  42. package/dist/src/config.d.ts +0 -24
  43. package/dist/src/config.js +0 -70
  44. package/dist/src/connect.d.ts +0 -2
  45. package/dist/src/connect.js +0 -64
  46. package/dist/src/coordinate.d.ts +0 -3
  47. package/dist/src/coordinate.js +0 -58
  48. package/dist/src/create.d.ts +0 -2
  49. package/dist/src/create.js +0 -113
  50. package/dist/src/credits.d.ts +0 -29
  51. package/dist/src/credits.js +0 -88
  52. package/dist/src/deploy.d.ts +0 -2
  53. package/dist/src/deploy.js +0 -19
  54. package/dist/src/dev.d.ts +0 -2
  55. package/dist/src/dev.js +0 -75
  56. package/dist/src/device-flow.d.ts +0 -57
  57. package/dist/src/device-flow.js +0 -173
  58. package/dist/src/doctor.d.ts +0 -26
  59. package/dist/src/doctor.js +0 -146
  60. package/dist/src/draw.d.ts +0 -18
  61. package/dist/src/draw.js +0 -156
  62. package/dist/src/endpoint.d.ts +0 -2
  63. package/dist/src/endpoint.js +0 -250
  64. package/dist/src/env.d.ts +0 -3
  65. package/dist/src/env.js +0 -37
  66. package/dist/src/eval.d.ts +0 -2
  67. package/dist/src/eval.js +0 -43
  68. package/dist/src/fn.d.ts +0 -2
  69. package/dist/src/fn.js +0 -70
  70. package/dist/src/group.d.ts +0 -2
  71. package/dist/src/group.js +0 -117
  72. package/dist/src/hl-run.d.ts +0 -119
  73. package/dist/src/hl-run.js +0 -480
  74. package/dist/src/hl.d.ts +0 -17
  75. package/dist/src/hl.js +0 -148
  76. package/dist/src/index.d.ts +0 -2
  77. package/dist/src/init.d.ts +0 -76
  78. package/dist/src/init.js +0 -278
  79. package/dist/src/join.d.ts +0 -11
  80. package/dist/src/join.js +0 -297
  81. package/dist/src/key-publish.d.ts +0 -40
  82. package/dist/src/key-publish.js +0 -232
  83. package/dist/src/key-seal.d.ts +0 -21
  84. package/dist/src/key-seal.js +0 -142
  85. package/dist/src/key-sweep.d.ts +0 -93
  86. package/dist/src/key-sweep.js +0 -270
  87. package/dist/src/key.d.ts +0 -26
  88. package/dist/src/key.js +0 -338
  89. package/dist/src/lib/age-plugin.d.ts +0 -51
  90. package/dist/src/lib/age-plugin.js +0 -130
  91. package/dist/src/lib/agent-env.d.ts +0 -12
  92. package/dist/src/lib/agent-env.js +0 -48
  93. package/dist/src/lib/api-path.d.ts +0 -2
  94. package/dist/src/lib/api-path.js +0 -40
  95. package/dist/src/lib/asker.d.ts +0 -34
  96. package/dist/src/lib/asker.js +0 -126
  97. package/dist/src/lib/check-words.d.ts +0 -57
  98. package/dist/src/lib/check-words.js +0 -144
  99. package/dist/src/lib/client.d.ts +0 -20
  100. package/dist/src/lib/client.js +0 -71
  101. package/dist/src/lib/env-sealed.d.ts +0 -53
  102. package/dist/src/lib/env-sealed.js +0 -184
  103. package/dist/src/lib/flow-tag.d.ts +0 -86
  104. package/dist/src/lib/flow-tag.js +0 -230
  105. package/dist/src/lib/hl-core/actions.d.ts +0 -99
  106. package/dist/src/lib/hl-core/actions.js +0 -69
  107. package/dist/src/lib/hl-core/eip712.d.ts +0 -33
  108. package/dist/src/lib/hl-core/eip712.js +0 -107
  109. package/dist/src/lib/hl-core/errors.d.ts +0 -10
  110. package/dist/src/lib/hl-core/errors.js +0 -15
  111. package/dist/src/lib/hl-core/exchange.d.ts +0 -24
  112. package/dist/src/lib/hl-core/exchange.js +0 -47
  113. package/dist/src/lib/hl-core/index.d.ts +0 -13
  114. package/dist/src/lib/hl-core/index.js +0 -14
  115. package/dist/src/lib/hl-core/meta.d.ts +0 -57
  116. package/dist/src/lib/hl-core/meta.js +0 -110
  117. package/dist/src/lib/hl-core/msgpack.d.ts +0 -18
  118. package/dist/src/lib/hl-core/msgpack.js +0 -136
  119. package/dist/src/lib/hl-core/net.d.ts +0 -2
  120. package/dist/src/lib/hl-core/net.js +0 -7
  121. package/dist/src/lib/hl-core/signing.d.ts +0 -103
  122. package/dist/src/lib/hl-core/signing.js +0 -295
  123. package/dist/src/lib/hl-core/wire.d.ts +0 -34
  124. package/dist/src/lib/hl-core/wire.js +0 -81
  125. package/dist/src/lib/invoked-as.d.ts +0 -2
  126. package/dist/src/lib/invoked-as.js +0 -24
  127. package/dist/src/lib/journey-words.d.ts +0 -84
  128. package/dist/src/lib/journey-words.js +0 -363
  129. package/dist/src/lib/journey.d.ts +0 -150
  130. package/dist/src/lib/journey.js +0 -264
  131. package/dist/src/lib/key-receipt.d.ts +0 -48
  132. package/dist/src/lib/key-receipt.js +0 -116
  133. package/dist/src/lib/key-source.d.ts +0 -9
  134. package/dist/src/lib/key-source.js +0 -33
  135. package/dist/src/lib/keyfile.d.ts +0 -136
  136. package/dist/src/lib/keyfile.js +0 -397
  137. package/dist/src/lib/launch-claude.d.ts +0 -5
  138. package/dist/src/lib/launch-claude.js +0 -45
  139. package/dist/src/lib/lock-lookup.d.ts +0 -40
  140. package/dist/src/lib/lock-lookup.js +0 -92
  141. package/dist/src/lib/message-seal.d.ts +0 -63
  142. package/dist/src/lib/message-seal.js +0 -150
  143. package/dist/src/lib/net-choice.d.ts +0 -28
  144. package/dist/src/lib/net-choice.js +0 -72
  145. package/dist/src/lib/network.d.ts +0 -22
  146. package/dist/src/lib/network.js +0 -50
  147. package/dist/src/lib/next-words.d.ts +0 -105
  148. package/dist/src/lib/next-words.js +0 -298
  149. package/dist/src/lib/paths.d.ts +0 -41
  150. package/dist/src/lib/paths.js +0 -91
  151. package/dist/src/lib/plan-draw.d.ts +0 -56
  152. package/dist/src/lib/plan-draw.js +0 -219
  153. package/dist/src/lib/plan-live.d.ts +0 -20
  154. package/dist/src/lib/plan-live.js +0 -192
  155. package/dist/src/lib/qr.d.ts +0 -21
  156. package/dist/src/lib/qr.js +0 -402
  157. package/dist/src/lib/roster.d.ts +0 -20
  158. package/dist/src/lib/roster.js +0 -79
  159. package/dist/src/lib/sale-card.d.ts +0 -117
  160. package/dist/src/lib/sale-card.js +0 -261
  161. package/dist/src/lib/shop-init.d.ts +0 -62
  162. package/dist/src/lib/shop-init.js +0 -63
  163. package/dist/src/lib/sui-grpc-send.d.ts +0 -90
  164. package/dist/src/lib/sui-grpc-send.js +0 -128
  165. package/dist/src/lib/swap-core.d.ts +0 -163
  166. package/dist/src/lib/swap-core.js +0 -405
  167. package/dist/src/lib/tasks-digest.d.ts +0 -66
  168. package/dist/src/lib/tasks-digest.js +0 -200
  169. package/dist/src/lib/tasks-graph.d.ts +0 -79
  170. package/dist/src/lib/tasks-graph.js +0 -463
  171. package/dist/src/lib/tasks-lens.d.ts +0 -31
  172. package/dist/src/lib/tasks-lens.js +0 -47
  173. package/dist/src/lib/tasks-next.d.ts +0 -25
  174. package/dist/src/lib/tasks-next.js +0 -103
  175. package/dist/src/lib/tasks-prove.d.ts +0 -15
  176. package/dist/src/lib/tasks-prove.js +0 -68
  177. package/dist/src/lib/tasks-route.d.ts +0 -29
  178. package/dist/src/lib/tasks-route.js +0 -151
  179. package/dist/src/lib/tasks-score.d.ts +0 -36
  180. package/dist/src/lib/tasks-score.js +0 -152
  181. package/dist/src/lib/tasks-workspace.d.ts +0 -18
  182. package/dist/src/lib/tasks-workspace.js +0 -73
  183. package/dist/src/lib/timed-fetch.d.ts +0 -33
  184. package/dist/src/lib/timed-fetch.js +0 -59
  185. package/dist/src/lib/vault-read.d.ts +0 -24
  186. package/dist/src/lib/vault-read.js +0 -77
  187. package/dist/src/lib/vaultfile.d.ts +0 -103
  188. package/dist/src/lib/vaultfile.js +0 -249
  189. package/dist/src/lib/wallet-money.d.ts +0 -222
  190. package/dist/src/lib/wallet-money.js +0 -578
  191. package/dist/src/lib/wallet-request.d.ts +0 -50
  192. package/dist/src/lib/wallet-request.js +0 -86
  193. package/dist/src/links.d.ts +0 -5
  194. package/dist/src/links.js +0 -45
  195. package/dist/src/media.d.ts +0 -29
  196. package/dist/src/media.js +0 -487
  197. package/dist/src/message-receipt.d.ts +0 -25
  198. package/dist/src/message-receipt.js +0 -71
  199. package/dist/src/message.d.ts +0 -13
  200. package/dist/src/message.js +0 -92
  201. package/dist/src/move.d.ts +0 -36
  202. package/dist/src/move.js +0 -152
  203. package/dist/src/network-cmd.d.ts +0 -17
  204. package/dist/src/network-cmd.js +0 -74
  205. package/dist/src/next.d.ts +0 -12
  206. package/dist/src/next.js +0 -67
  207. package/dist/src/onboard.d.ts +0 -16
  208. package/dist/src/onboard.js +0 -149
  209. package/dist/src/plugin.d.ts +0 -2
  210. package/dist/src/plugin.js +0 -193
  211. package/dist/src/push.d.ts +0 -2
  212. package/dist/src/push.js +0 -115
  213. package/dist/src/render.d.ts +0 -21
  214. package/dist/src/render.js +0 -32
  215. package/dist/src/secrets-device.d.ts +0 -32
  216. package/dist/src/secrets-device.js +0 -127
  217. package/dist/src/secrets-give.d.ts +0 -125
  218. package/dist/src/secrets-give.js +0 -236
  219. package/dist/src/secrets-list.d.ts +0 -27
  220. package/dist/src/secrets-list.js +0 -84
  221. package/dist/src/secrets-run.d.ts +0 -31
  222. package/dist/src/secrets-run.js +0 -182
  223. package/dist/src/secrets.d.ts +0 -33
  224. package/dist/src/secrets.js +0 -200
  225. package/dist/src/setup.d.ts +0 -6
  226. package/dist/src/setup.js +0 -127
  227. package/dist/src/ship.d.ts +0 -2
  228. package/dist/src/ship.js +0 -18
  229. package/dist/src/shop-buy.d.ts +0 -16
  230. package/dist/src/shop-buy.js +0 -101
  231. package/dist/src/shop.d.ts +0 -10
  232. package/dist/src/shop.js +0 -112
  233. package/dist/src/skill-parser.d.ts +0 -14
  234. package/dist/src/skill-parser.js +0 -113
  235. package/dist/src/skill.d.ts +0 -2
  236. package/dist/src/skill.js +0 -493
  237. package/dist/src/slug.d.ts +0 -2
  238. package/dist/src/slug.js +0 -6
  239. package/dist/src/social.d.ts +0 -2
  240. package/dist/src/social.js +0 -106
  241. package/dist/src/staff.d.ts +0 -2
  242. package/dist/src/staff.js +0 -104
  243. package/dist/src/start.d.ts +0 -27
  244. package/dist/src/start.js +0 -225
  245. package/dist/src/status.d.ts +0 -2
  246. package/dist/src/status.js +0 -52
  247. package/dist/src/substrate.d.ts +0 -2
  248. package/dist/src/substrate.js +0 -258
  249. package/dist/src/swap.d.ts +0 -93
  250. package/dist/src/swap.js +0 -622
  251. package/dist/src/tasks.d.ts +0 -2
  252. package/dist/src/tasks.js +0 -743
  253. package/dist/src/templates.d.ts +0 -1
  254. package/dist/src/templates.js +0 -213
  255. package/dist/src/thread.d.ts +0 -2
  256. package/dist/src/thread.js +0 -52
  257. package/dist/src/trade.d.ts +0 -2
  258. package/dist/src/trade.js +0 -91
  259. package/dist/src/trail.d.ts +0 -2
  260. package/dist/src/trail.js +0 -41
  261. package/dist/src/validate.d.ts +0 -13
  262. package/dist/src/validate.js +0 -35
  263. package/dist/src/wallet-money.d.ts +0 -158
  264. package/dist/src/wallet-money.js +0 -664
  265. package/dist/src/wallet.d.ts +0 -169
  266. package/dist/src/wallet.js +0 -973
  267. package/dist/src/workflow.d.ts +0 -2
  268. package/dist/src/workflow.js +0 -169
  269. package/dist/src/write.d.ts +0 -43
  270. package/dist/src/write.js +0 -180
package/dist/src/staff.js DELETED
@@ -1,104 +0,0 @@
1
- import { Command } from 'commander';
2
- import { authHeaders, out, resolveBase, resolveKey } from './lib/client.js';
3
- import { askPath } from './lib/api-path.js';
4
- const DEFAULT_API = resolveBase({}, 'https://one.ie');
5
- const VALID_ROLES = ['owner', 'admin', 'member', 'viewer'];
6
- export function staffCmd() {
7
- const cmd = new Command('staff').description('Workspace staff management');
8
- cmd
9
- .command('invite [email]')
10
- .description('Invite a human to your workspace; omit email to get an invite URL without sending mail')
11
- .option('--role <role>', `Role to assign: ${VALID_ROLES.join('|')}`, 'admin')
12
- .option('--workspace <slug>', 'Workspace slug (defaults to authenticated workspace)')
13
- .option('--dry-run', 'Print plan without sending invite')
14
- .option('--api <url>', 'API base URL', DEFAULT_API)
15
- .action(async (email, opts) => {
16
- const role = opts.role;
17
- if (!VALID_ROLES.includes(role)) {
18
- out(cmd, { ok: false, error: `--role must be one of: ${VALID_ROLES.join(', ')}` });
19
- return;
20
- }
21
- if (opts.dryRun) {
22
- out(cmd, { ok: true, dry_run: true, email: email ?? '(url-only)', role, workspace: opts.workspace ?? '(authenticated)' });
23
- return;
24
- }
25
- const key = resolveKey();
26
- if (!key) {
27
- out(cmd, { ok: false, error: 'no API key — set ONEIE_API_KEY or run: oneie auth login' });
28
- return;
29
- }
30
- const base = opts.api.replace(/\/$/, '');
31
- const body = { role };
32
- if (email)
33
- body.email = email;
34
- if (opts.workspace)
35
- body.workspace = opts.workspace;
36
- const res = await fetch(askPath(base, 'world:invite-member'), {
37
- method: 'POST',
38
- headers: authHeaders({ key }),
39
- body: JSON.stringify({ data: body }),
40
- });
41
- if (!res.ok) {
42
- const text = await res.text().catch(() => '');
43
- out(cmd, { ok: false, error: `${res.status}: ${text}` });
44
- return;
45
- }
46
- const json = (await res.json());
47
- if (json.error) {
48
- out(cmd, { ok: false, error: json.error });
49
- return;
50
- }
51
- const inviteUrl = json.inviteUrl ?? (json.token ? `${base}/join?token=${encodeURIComponent(json.token)}` : undefined);
52
- out(cmd, { ok: true, email: email ?? '(url-only)', role, invite_url: inviteUrl ?? '(sent)' });
53
- });
54
- cmd
55
- .command('add-agent <name>')
56
- .description('Create an agent in your workspace and print its key once')
57
- .option('--role <role>', `Role to assign: ${VALID_ROLES.join('|')}`, 'member')
58
- .option('--workspace <slug>', 'Workspace slug (defaults to authenticated workspace)')
59
- .option('--api <url>', 'API base URL', DEFAULT_API)
60
- .action(async (name, opts) => {
61
- const role = opts.role;
62
- if (!VALID_ROLES.includes(role)) {
63
- out(cmd, { ok: false, error: `--role must be one of: ${VALID_ROLES.join(', ')}` });
64
- return;
65
- }
66
- const key = resolveKey();
67
- if (!key) {
68
- out(cmd, { ok: false, error: 'no API key — set ONEIE_API_KEY or run: oneie auth login' });
69
- return;
70
- }
71
- const base = opts.api.replace(/\/$/, '');
72
- const body = { name, role };
73
- if (opts.workspace)
74
- body.workspace = opts.workspace;
75
- const res = await fetch(askPath(base, 'world:invite-agent'), {
76
- method: 'POST',
77
- headers: authHeaders({ key }),
78
- body: JSON.stringify({ data: body }),
79
- });
80
- if (!res.ok) {
81
- const text = await res.text().catch(() => '');
82
- out(cmd, { ok: false, error: `${res.status}: ${text}` });
83
- return;
84
- }
85
- const json = (await res.json());
86
- if (json.error) {
87
- out(cmd, { ok: false, error: json.error });
88
- return;
89
- }
90
- const result = json.result ?? json;
91
- // The ask door answers a refusal INSIDE result (`{outcome:"failure", result:{error,reason}}`)
92
- // with HTTP 200 — read it, or a forbidden prints `aid=undefined key=undefined` as ok.
93
- if (result.error) {
94
- out(cmd, { ok: false, error: result.reason ?? result.error });
95
- return;
96
- }
97
- if (!result.aid || !result.key) {
98
- out(cmd, { ok: false, error: 'door answered without aid/key' });
99
- return;
100
- }
101
- out(cmd, { ok: true, name, role, aid: result.aid, key: result.key });
102
- });
103
- return cmd;
104
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * `oneie start`, and bare `npx oneie`: the whole journey in the current folder —
3
- * key → products → test sale → handover link. The logic is `lib/journey.ts`;
4
- * this file is the wiring: disk, network, Keychain, and the printed receipt.
5
- *
6
- * The journey's key lives in THIS folder (`.one/agent.key`, 0600, git-ignored
7
- * before it is written) and never in ~/.config/one/key — a stray run must not
8
- * replace the machine key someone already logs in with.
9
- */
10
- import { Command } from 'commander';
11
- import { type JourneyDeps } from './lib/journey.js';
12
- /** The flags bare `npx oneie --email …` hands to `start` — the journey's own, nothing else. */
13
- export declare const START_FLAGS: Set<string>;
14
- /** Bare `oneie`, or `oneie` led by a journey flag, runs `start`. Everything else is untouched. */
15
- export declare function startArgv(argv: string[]): string[];
16
- /** A progress line for a person (stderr, so `--json` stdout stays one object). Silent in JSON mode. */
17
- export type Say = (line: string) => void;
18
- /**
19
- * The journey's wiring. Exported, with `f` and `limits` injectable, so a test can
20
- * drive these exact round trips against a server that never answers
21
- * (`tests/journey-no-answer.test.ts`).
22
- */
23
- export declare function journeyDeps(dir: string, api: string, say: Say, f?: typeof fetch, limits?: {
24
- askMs: number;
25
- provisionMs: number;
26
- }): JourneyDeps;
27
- export declare function startCmd(): Command;
package/dist/src/start.js DELETED
@@ -1,225 +0,0 @@
1
- /**
2
- * `oneie start`, and bare `npx oneie`: the whole journey in the current folder —
3
- * key → products → test sale → handover link. The logic is `lib/journey.ts`;
4
- * this file is the wiring: disk, network, Keychain, and the printed receipt.
5
- *
6
- * The journey's key lives in THIS folder (`.one/agent.key`, 0600, git-ignored
7
- * before it is written) and never in ~/.config/one/key — a stray run must not
8
- * replace the machine key someone already logs in with.
9
- */
10
- import { Command } from 'commander';
11
- import { chmodSync, existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
12
- import { join } from 'node:path';
13
- import { askPath } from './lib/api-path.js';
14
- import { jsonMode } from './lib/client.js';
15
- import { KEY_DIR_NAME, KEY_FILE_NAME, LEGACY_KEY_DIR_NAME, META_FILE_NAME, readKeyFolder, writeKeyFolder } from './lib/keyfile.js';
16
- import { keychainAvailable, readVaultFolder, vaultPath } from './lib/vaultfile.js';
17
- import { cliPrefix } from './lib/invoked-as.js';
18
- import { agentType } from './lib/agent-env.js';
19
- import { provisionLocalWallet } from './init.js';
20
- import { promptSecret, registerSealedWallet } from './wallet.js';
21
- import { parseProductSpec, runJourney, } from './lib/journey.js';
22
- import { asciiOf, haveNow, journeyIntro, journeyResume, journeyWords } from './lib/journey-words.js';
23
- import { learnNetwork } from './lib/network.js';
24
- import { ASK_TIMEOUT_MS, NoAnswerError, PROVISION_TIMEOUT_MS, fetchJson } from './lib/timed-fetch.js';
25
- const DEFAULT_API = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
26
- /** The flags bare `npx oneie --email …` hands to `start` — the journey's own, nothing else. */
27
- export const START_FLAGS = new Set(['--name', '--email', '--product', '--currency', '--wait', '--api']);
28
- /** Bare `oneie`, or `oneie` led by a journey flag, runs `start`. Everything else is untouched. */
29
- export function startArgv(argv) {
30
- // `--json` is the program's own flag, so it stays in front of the subcommand:
31
- // `npx oneie --json` runs the journey in JSON instead of printing Usage.
32
- const lead = argv[2] === '--json' ? 3 : 2;
33
- const head = argv.slice(0, lead);
34
- if (argv.length === lead)
35
- return [...head, 'start'];
36
- const first = argv[lead]?.split('=')[0] ?? '';
37
- if (START_FLAGS.has(first))
38
- return [...head, 'start', ...argv.slice(lead)];
39
- return argv;
40
- }
41
- const statePath = (dir) => join(dir, KEY_DIR_NAME, 'journey.json');
42
- function loadState(dir) {
43
- const p = statePath(dir);
44
- if (!existsSync(p))
45
- return null;
46
- try {
47
- const s = JSON.parse(readFileSync(p, 'utf8'));
48
- return s && s.v === 1 && typeof s.workspace === 'string' ? s : null;
49
- }
50
- catch {
51
- return null;
52
- }
53
- }
54
- /** 0600 and atomic: the state carries the owner link, which is a bearer credential. */
55
- function saveState(dir, s) {
56
- const p = statePath(dir);
57
- const tmp = `${p}.${process.pid}.tmp`;
58
- writeFileSync(tmp, JSON.stringify(s, null, 2) + '\n', { mode: 0o600 });
59
- chmodSync(tmp, 0o600);
60
- renameSync(tmp, p);
61
- }
62
- /**
63
- * Keychain where there is one (Touch ID opens it, nothing is typed); a
64
- * passphrase only at a real terminal. An agent shell elsewhere is refused by
65
- * name — never downgraded to a plaintext file.
66
- */
67
- async function walletStore(dir) {
68
- if (keychainAvailable())
69
- return { kind: 'keychain', dir };
70
- if (!process.stdin.isTTY) {
71
- return { error: 'no Apple Keychain here and no terminal to type a passphrase into — run `npx oneie wallet new` in your own terminal, then `npx oneie wallet register --kind agent`' };
72
- }
73
- const passphrase = await promptSecret('Choose a passphrase to lock your agent\'s wallet (8 characters or more): ');
74
- if (passphrase !== (await promptSecret('Type it again: ')))
75
- return { error: 'the two passphrases did not match, so no wallet was made. Run it again and type the same one twice' };
76
- if (passphrase.length < 8)
77
- return { error: 'that passphrase is shorter than 8 characters, so no wallet was made. Run it again with a longer one' };
78
- return { kind: 'vault', dir, passphrase };
79
- }
80
- /**
81
- * The journey's wiring. Exported, with `f` and `limits` injectable, so a test can
82
- * drive these exact round trips against a server that never answers
83
- * (`tests/journey-no-answer.test.ts`).
84
- */
85
- export function journeyDeps(dir, api, say, f = fetch, limits = { askMs: ASK_TIMEOUT_MS, provisionMs: PROVISION_TIMEOUT_MS }) {
86
- return {
87
- say,
88
- load: () => loadState(dir),
89
- save: (s) => saveState(dir, s),
90
- key: () => {
91
- const f = readKeyFolder(dir);
92
- if (!f)
93
- return null;
94
- const reg = f.meta.regKey;
95
- return typeof reg === 'string' && reg ? reg : f.apiKey;
96
- },
97
- existingKey: () => {
98
- for (const d of [KEY_DIR_NAME, LEGACY_KEY_DIR_NAME]) {
99
- if (!existsSync(join(dir, d, KEY_FILE_NAME)))
100
- continue;
101
- try {
102
- const meta = JSON.parse(readFileSync(join(dir, d, META_FILE_NAME), 'utf8'));
103
- return typeof meta.workspace === 'string' ? meta.workspace : '';
104
- }
105
- catch {
106
- return '';
107
- }
108
- }
109
- return null;
110
- },
111
- provision: async (body) => {
112
- say('Making your agent\'s key and its own group on one.ie…');
113
- // A write, so a silent server is reported and never retried: a second call would make a second group.
114
- try {
115
- return await fetchJson(f, `${api}/api/provision/agent`, {
116
- method: 'POST',
117
- headers: { 'Content-Type': 'application/json' },
118
- body: JSON.stringify(body),
119
- }, limits.provisionMs, `${api}/api/provision/agent`);
120
- }
121
- catch (e) {
122
- if (!(e instanceof NoAnswerError))
123
- throw e;
124
- return { ok: false, status: 0, json: { error: `${e.message}. Nothing was saved in this folder, so run \`npx oneie\` again` } };
125
- }
126
- },
127
- saveKey: (p) => writeKeyFolder({ dir, api, ...p }),
128
- wallet: async ({ key, workspace }) => {
129
- // A wallet sealed on an earlier run whose registration did not land: open it
130
- // (Touch ID for a Keychain seal) and register THAT one — minting again would
131
- // be refused, and would leave the first wallet's addresses orphaned.
132
- if (existsSync(vaultPath(dir))) {
133
- say('Opening the wallet made on an earlier run. Touch ID may ask you to confirm…');
134
- const r = await registerSealedWallet({ base: api, key, workspace, actor: workspace, dir });
135
- return r.ok
136
- ? { ok: true, file: vaultPath(dir), keychain: readVaultFolder(dir)?.wrap === 'keychain', addresses: (r.addresses ?? {}) }
137
- : { ok: false, file: vaultPath(dir), error: `${String(r.error ?? 'wallet:create refused')} — the sealed wallet is kept; run \`npx oneie\` again to retry` };
138
- }
139
- const store = await walletStore(dir);
140
- if ('error' in store)
141
- return { ok: false, error: store.error };
142
- say(store.kind === 'keychain'
143
- ? 'Locking your agent\'s wallet in your Apple Keychain. Touch ID may ask you to confirm…'
144
- : 'Locking your agent\'s wallet with your passphrase…');
145
- return provisionLocalWallet({ api, key, workspace, store });
146
- },
147
- ask: async (key, receiver, data) => {
148
- let res;
149
- try {
150
- res = await fetchJson(f, askPath(api, receiver), {
151
- method: 'POST',
152
- headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
153
- body: JSON.stringify({ data }),
154
- }, limits.askMs, receiver);
155
- }
156
- catch (e) {
157
- // A silent server is its own outcome, so the journey can name it instead of hanging.
158
- if (e instanceof NoAnswerError)
159
- return { outcome: 'no_answer', error: e.message };
160
- throw e;
161
- }
162
- const body = res.json;
163
- // A transport-level refusal is its own outcome — never read as an empty success.
164
- if (!res.ok)
165
- return { outcome: `http_${res.status}`, error: String(body.error ?? body.detail ?? '') };
166
- return body;
167
- },
168
- sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
169
- now: () => Date.now(),
170
- };
171
- }
172
- export function startCmd() {
173
- const cmd = new Command('start')
174
- .description('Walk the whole path in this folder: your key, a product, a test sale, then one link that hands it over. Bare `npx oneie` runs it; run it again to pick up where you left off')
175
- .option('--name <name>', 'Group / agent display name', 'My Shop')
176
- .option('--email <email>', "The new owner's email — the handover link is sent there as well as printed")
177
- .option('--product <name=price>', 'A product in major units, e.g. "Mug=12.50" (repeatable; default one Test product at 1.00)', (v, acc) => [...acc, v], [])
178
- .option('--currency <iso>', 'ISO 4217 for --product prices', 'usd')
179
- .option('--wait <seconds>', 'Keep reading back the test sale this long before stopping at pending (default: a re-run waits 20 s, a first run reads once)')
180
- .option('--api <url>', 'API base URL', DEFAULT_API)
181
- .action(async (opts, sub) => {
182
- const products = [];
183
- for (const raw of opts.product) {
184
- const p = parseProductSpec(raw, opts.currency);
185
- if (!p.ok) {
186
- if (jsonMode(sub))
187
- process.stdout.write(JSON.stringify({ ok: false, error: p.error }) + '\n');
188
- else
189
- process.stderr.write(`✗ ${p.error}\n`);
190
- process.exitCode = 1;
191
- return;
192
- }
193
- products.push(p.product);
194
- }
195
- const api = opts.api.replace(/\/$/, '');
196
- const json = jsonMode(sub);
197
- const cli = cliPrefix();
198
- // A pipe, a log or NO_COLOR gets plain ASCII: the same words, no box or glyph it cannot draw.
199
- const plain = !process.stdout.isTTY || 'NO_COLOR' in process.env;
200
- const fmt = (text) => (plain ? asciiOf(text) : text);
201
- if (!json) {
202
- const earlier = loadState(process.cwd());
203
- process.stdout.write(fmt(earlier ? journeyResume(earlier.workspace) : journeyIntro(cli)));
204
- }
205
- // The network shapes the words and `have.network`; asked now, in parallel with the walk, never blocking it.
206
- const netP = learnNetwork(api);
207
- const say = json ? () => { } : (line) => process.stderr.write(` ${fmt(line)}\n`);
208
- const report = await runJourney(journeyDeps(process.cwd(), api, say), {
209
- api,
210
- name: opts.name,
211
- ...(opts.email ? { email: opts.email } : {}),
212
- products,
213
- ...(opts.wait !== undefined ? { waitSeconds: Math.max(0, Number(opts.wait) || 0) } : {}),
214
- });
215
- const net = await netP;
216
- // `have` is additive: every fact the panel prints, in full, beside the report's own keys.
217
- if (json)
218
- process.stdout.write(JSON.stringify({ ...report, have: haveNow(report, cli, { net }) }) + '\n');
219
- else
220
- process.stdout.write(fmt('\n' + journeyWords(report, cli, { agent: agentType(), net })));
221
- if (!report.ok)
222
- process.exitCode = 1;
223
- });
224
- return cmd;
225
- }
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare function statusCmd(): Command;
@@ -1,52 +0,0 @@
1
- import { Command } from 'commander';
2
- import { mergeEnv } from './env.js';
3
- import { renderStatus } from './render.js';
4
- import { askPath } from './lib/api-path.js';
5
- const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://one.ie';
6
- export function statusCmd() {
7
- return new Command('status')
8
- .description('Agency P&L dashboard (pool, margin, per-client burns)')
9
- .option('--api <url>', 'API base URL', DEFAULT_API)
10
- .option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
11
- .option('--json', 'Output raw JSON')
12
- .action(async (opts) => {
13
- const dir = process.cwd();
14
- const env = mergeEnv(dir);
15
- const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? '';
16
- if (!key || !env.AGENCY_SLUG) {
17
- process.stderr.write('not set up — run `one setup` first\n');
18
- process.exit(1);
19
- }
20
- const base = opts.api.replace(/\/$/, '');
21
- // slug is required for staff/owner keys — without it the receiver resolves
22
- // the key's personal workspace and returns an empty portfolio.
23
- const res = await fetch(askPath(base, 'billing:clients'), {
24
- method: 'POST',
25
- headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
26
- body: JSON.stringify({ data: { slug: env.AGENCY_SLUG } }),
27
- });
28
- if (!res.ok) {
29
- process.stderr.write(`billing:clients → ${res.status}\n`);
30
- process.exit(1);
31
- }
32
- const json = await res.json();
33
- if (json.outcome === 'failure') {
34
- const result = (json.result ?? {});
35
- const details = Object.entries(result)
36
- .map(([k, v]) => `${k}=${typeof v === 'string' ? v : JSON.stringify(v)}`)
37
- .join(' ');
38
- process.stderr.write(`billing:clients → forbidden: ${details}\n`);
39
- process.exit(1);
40
- }
41
- if (opts.json) {
42
- process.stdout.write(JSON.stringify(json, null, 2) + '\n');
43
- return;
44
- }
45
- // Receiver replies in the four-outcome envelope: { outcome, result: { agency, clients } }.
46
- // Unwrap it (keep the bare-shape fallback for older hosts).
47
- const payload = (json.result ?? json);
48
- const agency = (payload.agency ?? { slug: env.AGENCY_SLUG, name: env.AGENCY_NAME ?? null, markup_pct: 0, pool: 0, plan: 'free' });
49
- const clients = (payload.clients ?? []);
50
- process.stdout.write(renderStatus(agency, clients) + '\n');
51
- });
52
- }
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare function substrateCommands(program: Command): void;