@oneie/cli 5.5.2 → 5.7.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 (43) hide show
  1. package/README.md +29 -0
  2. package/dist/package.json +2 -2
  3. package/dist/src/index.js +15 -15
  4. package/dist/src/init.d.ts +10 -1
  5. package/dist/src/init.js +26 -11
  6. package/dist/src/join.d.ts +1 -1
  7. package/dist/src/join.js +2 -1
  8. package/dist/src/key-publish.d.ts +40 -0
  9. package/dist/src/key-publish.js +232 -0
  10. package/dist/src/key-seal.d.ts +21 -0
  11. package/dist/src/key-seal.js +142 -0
  12. package/dist/src/key.js +22 -5
  13. package/dist/src/lib/age-plugin.d.ts +51 -0
  14. package/dist/src/lib/age-plugin.js +130 -0
  15. package/dist/src/lib/env-sealed.d.ts +53 -0
  16. package/dist/src/lib/env-sealed.js +184 -0
  17. package/dist/src/lib/journey.d.ts +137 -0
  18. package/dist/src/lib/journey.js +232 -0
  19. package/dist/src/lib/key-receipt.d.ts +48 -0
  20. package/dist/src/lib/key-receipt.js +116 -0
  21. package/dist/src/lib/lock-lookup.d.ts +40 -0
  22. package/dist/src/lib/lock-lookup.js +92 -0
  23. package/dist/src/lib/message-seal.d.ts +63 -0
  24. package/dist/src/lib/message-seal.js +150 -0
  25. package/dist/src/lib/shop-init.js +2 -2
  26. package/dist/src/lib/vault-read.d.ts +24 -0
  27. package/dist/src/lib/vault-read.js +77 -0
  28. package/dist/src/media.d.ts +27 -0
  29. package/dist/src/media.js +249 -18
  30. package/dist/src/secrets-device.d.ts +32 -0
  31. package/dist/src/secrets-device.js +127 -0
  32. package/dist/src/secrets-give.d.ts +125 -0
  33. package/dist/src/secrets-give.js +236 -0
  34. package/dist/src/secrets-run.d.ts +31 -0
  35. package/dist/src/secrets-run.js +182 -0
  36. package/dist/src/secrets.d.ts +32 -0
  37. package/dist/src/secrets.js +197 -0
  38. package/dist/src/social.js +27 -8
  39. package/dist/src/start.d.ts +15 -0
  40. package/dist/src/start.js +200 -0
  41. package/dist/src/write.d.ts +43 -0
  42. package/dist/src/write.js +174 -0
  43. package/package.json +2 -2
@@ -0,0 +1,174 @@
1
+ /**
2
+ * write.ts — `one write <slug> --to age1… [file|-]`: seal a note HERE, on this machine,
3
+ * and drop the ciphertext in a holder's inbox through the door already live on one.ie.
4
+ *
5
+ * POST <web base>/api/write { ws, sealed, from? }
6
+ *
7
+ * THE PLAINTEXT NEVER LEAVES THIS PROCESS. The note is sealed to the `--to` lock(s)
8
+ * before any request is built, and the request body is built from the armored block and
9
+ * the slug alone — `sealNote` takes the plaintext, `postSealed` takes only what is
10
+ * already sealed, and a test pins that the posted body does not contain the note.
11
+ * The door itself refuses anything that is not one armored age block.
12
+ *
13
+ * `/api/write` is a WEB route (one.ie), not a gateway receiver, so this does not go
14
+ * through `askPath`. An env base that points at the gateway (api.one.ie) would 404, so
15
+ * unless `--api` names a host explicitly, that base is replaced with https://one.ie.
16
+ *
17
+ * `--to` is the literal `age1…` the holder gave you, used as given — no lookup, no check.
18
+ * Leave `--to` off and the name's PUBLISHED lock is looked up and verified here first
19
+ * (lib/lock-lookup.ts: GET /api/lock/<slug>, the Sui signature re-checked locally). An
20
+ * unpublished name, a lookup that is not live or unreachable, or a lock that does not
21
+ * verify stops the note before anything is sealed or posted — it never falls back to a
22
+ * lock nobody checked.
23
+ */
24
+ import { Command } from 'commander';
25
+ import { jsonMode } from './lib/client.js';
26
+ import { exitFor, lookupLock } from './lib/lock-lookup.js';
27
+ import { ageModule, readNote } from './lib/message-seal.js';
28
+ /** The door's own limits (one.ie/web pages/api/write.ts + lib/key/sealed-post.ts). */
29
+ export const SEALED_MAX_CHARS = 8000;
30
+ const SLUG_RE = /^[a-z0-9][a-z0-9-]{0,62}$/;
31
+ const AGENT_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
32
+ const FROM_MAX = 60;
33
+ const DEADLINE_MS = 15_000;
34
+ const WEB = 'https://one.ie';
35
+ export function writeBase(explicit, env = process.env) {
36
+ const pick = explicit ?? env.ONE_API_URL ?? env.ONEIE_BASE_URL ?? WEB;
37
+ const base = pick.replace(/\/$/, '');
38
+ if (!explicit) {
39
+ try {
40
+ if (new URL(base).hostname === 'api.one.ie')
41
+ return WEB;
42
+ }
43
+ catch {
44
+ /* an unparseable env base falls through and fails at fetch with a plain sentence */
45
+ }
46
+ }
47
+ return base;
48
+ }
49
+ const collect = (v, prev = []) => [...prev, v];
50
+ /** Plaintext in, armored block out — or a plain refusal. Nothing here touches the network. */
51
+ export async function sealNote(note, locks) {
52
+ if (locks.length === 0)
53
+ return { ok: false, error: 'seal it to someone — pass --to age1…', code: 'no_recipient' };
54
+ const age = await ageModule();
55
+ for (const l of locks) {
56
+ try {
57
+ age.decodeRecipient(l);
58
+ }
59
+ catch {
60
+ return { ok: false, error: `${l} is not an age lock — it starts age1…`, code: 'bad_key' };
61
+ }
62
+ }
63
+ return { ok: true, sealed: age.armor(age.encrypt(note, [...new Set(locks.map((l) => l.trim()))])) };
64
+ }
65
+ /** Post an ALREADY SEALED block. Its inputs carry no plaintext, by signature. */
66
+ export async function postSealed(base, ws, sealed, from, fetchImpl = fetch) {
67
+ const body = { ws, sealed };
68
+ if (from)
69
+ body.from = from;
70
+ const ctl = new AbortController();
71
+ const timer = setTimeout(() => ctl.abort(), DEADLINE_MS);
72
+ let res;
73
+ try {
74
+ res = await fetchImpl(`${base}/api/write`, {
75
+ method: 'POST',
76
+ headers: { 'content-type': 'application/json' },
77
+ body: JSON.stringify(body),
78
+ signal: ctl.signal,
79
+ });
80
+ }
81
+ catch {
82
+ return { ok: false, error: `could not reach ${base} — the note was sealed but not sent`, code: 'unreachable' };
83
+ }
84
+ finally {
85
+ clearTimeout(timer);
86
+ }
87
+ let j = {};
88
+ try {
89
+ j = (await res.json());
90
+ }
91
+ catch {
92
+ /* a non-JSON body is reported by status below */
93
+ }
94
+ if (res.status === 429)
95
+ return { ok: false, error: 'too many notes from this address — the door takes ten a minute; wait and try again', code: 'rate_limited' };
96
+ if (res.ok && j.ok)
97
+ return { ok: true, workspace: ws, threadId: j.threadId ?? null, messageId: j.messageId ?? null, sealedChars: sealed.length };
98
+ switch (j.error) {
99
+ case 'bad_workspace':
100
+ return { ok: false, error: `"${ws}" is not a workspace name`, code: 'bad_workspace' };
101
+ case 'unknown_workspace':
102
+ return { ok: false, error: `there is no workspace called "${ws}" on ${base}`, code: 'unknown_workspace' };
103
+ case 'not_sealed':
104
+ return { ok: false, error: 'the door refused it — it is not one armored age block', code: 'not_sealed' };
105
+ default:
106
+ return { ok: false, error: `the door answered ${res.status}${j.error ? ` (${j.error})` : ''} — nothing was delivered`, code: j.error ?? 'failed' };
107
+ }
108
+ }
109
+ export function writeCmd() {
110
+ return new Command('write')
111
+ .description("Seal a note on this machine to someone's age1… lock and drop it in their inbox on one.ie (/api/write). Plaintext never leaves")
112
+ .argument('<slug>', "The holder's workspace name, or <workspace>/<agent-id> for an agent's own lock (the note still lands in the workspace's sealed notes)")
113
+ .argument('[file]', 'The note to send; omit or "-" to read stdin')
114
+ .option('--to <lock>', 'The holder\'s age1… lock (repeat to seal to several). Omit it to use the lock <slug> has PUBLISHED, checked here first', collect)
115
+ .option('--from <name>', `A display name for you, up to ${FROM_MAX} characters — a label, never proof of who you are`)
116
+ .option('--api <url>', 'Web base (default https://one.ie; /api/write is a web route, not on the gateway)')
117
+ .action(async (nameArg, file, o, c) => {
118
+ const refuse = (f) => {
119
+ if (jsonMode(c))
120
+ process.stdout.write(JSON.stringify(f) + '\n');
121
+ else
122
+ process.stderr.write(`error ${f.error}\n`);
123
+ process.exitCode = 1;
124
+ };
125
+ // `sam` or `sam/scout`: the workspace half is where the note lands; the whole name
126
+ // is what gets looked up, so an agent's lock is checked against ITS name, never sam's.
127
+ const name = nameArg.trim();
128
+ const ws = name.split('/')[0].toLowerCase();
129
+ if (!SLUG_RE.test(ws))
130
+ return refuse({ ok: false, error: `"${nameArg}" is not a workspace name — lowercase letters, digits and dashes`, code: 'bad_workspace' });
131
+ const agentPart = name.includes('/') ? name.slice(name.indexOf('/') + 1) : undefined;
132
+ if (agentPart !== undefined && !AGENT_NAME_RE.test(agentPart)) {
133
+ return refuse({ ok: false, error: `"${nameArg}" is not an agent name — <workspace>/<agent-id>`, code: 'bad_agent' });
134
+ }
135
+ const from = o.from?.trim();
136
+ if (from && from.length > FROM_MAX)
137
+ return refuse({ ok: false, error: `--from is ${from.length} characters; the door keeps ${FROM_MAX}`, code: 'from_too_long' });
138
+ // No --to: seal to the name's published lock, but only one that verifies HERE.
139
+ let locks = o.to ?? [];
140
+ let checked;
141
+ if (locks.length === 0) {
142
+ const found = await lookupLock(writeBase(o.api), agentPart === undefined ? ws : `${ws}/${agentPart}`);
143
+ if (!found.ok) {
144
+ refuse(found);
145
+ process.exitCode = exitFor(found.code);
146
+ return;
147
+ }
148
+ checked = found;
149
+ locks = [found.lock];
150
+ }
151
+ const note = await readNote(file);
152
+ if ('ok' in note)
153
+ return refuse(note);
154
+ const sealed = await sealNote(note, locks);
155
+ if (!sealed.ok)
156
+ return refuse(sealed);
157
+ if (sealed.sealed.length > SEALED_MAX_CHARS) {
158
+ return refuse({
159
+ ok: false,
160
+ error: `sealed, this note is ${sealed.sealed.length} characters and the door takes ${SEALED_MAX_CHARS} — send a shorter note, or fewer locks. Nothing was sent`,
161
+ code: 'too_long',
162
+ });
163
+ }
164
+ const r = await postSealed(writeBase(o.api), ws, sealed.sealed, from);
165
+ if (!r.ok)
166
+ return refuse(r);
167
+ if (jsonMode(c))
168
+ process.stdout.write(JSON.stringify(checked ? { ...r, name: checked.name, lock: checked.lock, suiAddress: checked.suiAddress, lockChecked: true } : r) + '\n');
169
+ else if (checked)
170
+ process.stdout.write(`sent sealed to ${checked.name}'s published lock (signature checked, signed by Sui address ${checked.suiAddress}), ${r.sealedChars} characters, into ${ws}'s sealed notes\n`);
171
+ else
172
+ process.stdout.write(`sent sealed to ${new Set(o.to).size} lock(s), ${r.sealedChars} characters, into ${ws}'s sealed notes\n`);
173
+ });
174
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "5.5.2",
3
+ "version": "5.7.0",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -15,7 +15,7 @@
15
15
  "build": "tsc && cp package.json dist/ && chmod +x dist/src/index.js",
16
16
  "dev": "tsx src/index.ts",
17
17
  "typecheck": "tsc --noEmit",
18
- "test": "bash ../../.claude/scripts/gate-run.sh test-cli -- vitest run",
18
+ "test": "bash ../../.claude/scripts/gate-run.sh test-cli -- ./node_modules/.bin/vitest run",
19
19
  "prepublishOnly": "bun run build"
20
20
  },
21
21
  "dependencies": {