@oneie/cli 5.1.0 → 5.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.
package/README.md CHANGED
@@ -70,12 +70,26 @@ one tasks brief --workspace one --tree # one screen: counts, ready, b
70
70
  one tasks board --workspace one --tree --all # every row; --kind work|approval|all (default work)
71
71
  one tasks plan <goal-tid|tag> --tree # waves + critical path in hops; cycles, outside waits, ownerless
72
72
  one tasks plan <goal> --emit dispatch --out w.json # hand-off: tid/assignee/model/effort/touches/accept per wave
73
+ one tasks plan <goal> --draw # the plan DRAWN; in a terminal it is live: select, act, see what changed
74
+ one tasks plan <goal> --draw --print # the same picture once, for an agent or a pipe (default with no TTY)
73
75
  one tasks sequence <tid> <tid> <tid> --apply # chain in order (one tasks:bulk call); preview without --apply
74
76
  one tasks depend <tid> <blockedBy> # one edge; undepend removes it
75
77
  one tasks set --where-tag t --set-status done # filter-driven edit; preview unless --apply
76
78
  one tasks bulk --file plan.json # creates/edits from a file, chunked at 25
77
79
  ```
78
80
 
81
+ **`--draw`: see the plan, act on a row, see what happened.** Waves are columns and the critical
82
+ path (the chain that decides when the plan finishes) is drawn as arrows along the top. Every other
83
+ dependency is written in words ("waits Build it"). A parent with open subtasks is never shown ready,
84
+ because `tasks:claim` would refuse it. In a terminal: arrows select a row, then `c` claim · `d` done ·
85
+ `o` reopen · `m` comment · enter notes · `r` re-read · `q` quit.
86
+ After each action the bottom line shows the receipt, and what just became ready and whether the
87
+ critical path moved are highlighted. The change is applied from the action's receipt at once. The
88
+ board snapshot is a ≤60s memo, and forcing a rebuild (`fresh`) re-reads every row in the group, which
89
+ has crashed the worker, so the view never forces one; it says the snapshot is catching up. A refusal
90
+ reads `✗ … refused: <reason> (nothing changed)`. `--save <name>` also writes the drawing for
91
+ `one draw <name>`.
92
+
79
93
  Rows tagged `approval` are parked workflow runs: excluded by default, counted, and never closed by
80
94
  status (`set --apply` refuses them unless `--kind all`). Every read states `total`, `truncated` and
81
95
  `asOf`; a partial read says it is partial.
@@ -95,6 +109,18 @@ one login --key <key> # or paste a key directly
95
109
 
96
110
  Workspace operations use a Bearer token `<slug>:<key>`. Override the API base per command with `--api` (default `https://api.one.ie`, the gateway).
97
111
 
112
+ ## Join an existing group
113
+
114
+ ```bash
115
+ one login # become someone — no new group
116
+ one request acme --reason "I run your newsletter" # ask the owner; prints the requestId
117
+ one requests # your asks
118
+ one requests --group acme --status pending # an owner's queue
119
+ one approve <requestId> # owner answers (--reject to refuse)
120
+ ```
121
+
122
+ Bare `one` prints this door beside the new-group one and never prompts. `approve` needs `manage_members`, so an owner answers with a `one login` key — an agent-class key is refused. Every verb takes `--json` and `--api`; with no key it exits 1 pointing at `one login`.
123
+
98
124
  ## Wallets
99
125
 
100
126
  Every actor — human or agent — gets real, self-custodied multi-chain wallets. The CLI reads and writes the same `wallet:*` receivers `/w` uses:
@@ -192,6 +218,24 @@ JSON body, so the raw door is no worse than a wrapper:
192
218
  one ask media:generate --data '{"prompt":"a red bicycle"}'
193
219
  ```
194
220
 
221
+ ## Draw — ASCII diagrams, onto the board
222
+
223
+ ```bash
224
+ one draw [name|path] # open lazydraw (the TUI) on a drawing
225
+ one draw list # saved drawings
226
+ one draw export <name> [--basic] [--fenced] [-o out.txt]
227
+ one draw attach <name> --task <tid> [--workspace S] # post it to the task's thread
228
+ ```
229
+
230
+ `one draw` runs [lazydraw](https://github.com/mpospirit/lazydraw) (MIT, Çağrı
231
+ Gökpunar). It is a Bun app, so it is spawned rather than bundled: `lazydraw` if
232
+ it is on your PATH, else `bun x lazydraw@0.1.1`. Without Bun you get one line
233
+ telling you how to install it. Everything except `attach` is passed straight
234
+ through. `attach` exports plain ASCII in a Markdown fence and posts it through
235
+ `tasks:comment`, so the sketch sits on the row it explains. A diagram over the
236
+ door's 4000-byte comment cap is **refused** with both numbers, never cut, and a
237
+ comment the door trimmed is reported as `truncated`.
238
+
195
239
  ## Chat — fan in · fan out
196
240
 
197
241
  Send to a space, broadcast to all, or stream incoming messages:
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "5.1.0",
3
+ "version": "5.2.1",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "commander": "^12.0.0",
23
- "@oneie/sdk": "^0.16.0"
23
+ "@oneie/sdk": "^0.16.2"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@oneie/evals": "^0.2.0",
@@ -0,0 +1,18 @@
1
+ import { Command } from 'commander';
2
+ /** Pinned so `bun x` cannot quietly run a different release. ONE_LAZYDRAW overrides. */
3
+ export declare const LAZYDRAW_PKG = "lazydraw@0.1.1";
4
+ /** tasks:comment's MAX_COMMENT_BYTES (one.ie/web/src/lib/resolvers/tasks.ts). */
5
+ export declare const COMMENT_MAX_BYTES = 4000;
6
+ /** The argv that runs lazydraw on this machine, or null when neither lazydraw nor bun is reachable. */
7
+ export declare function resolveRunner(has?: (bin: string) => boolean): string[] | null;
8
+ /** The comment body `attach` posts, or a refusal naming the budget that bit. */
9
+ export declare function attachBody(name: string, diagram: string): {
10
+ ok: true;
11
+ body: string;
12
+ bytes: number;
13
+ } | {
14
+ ok: false;
15
+ error: string;
16
+ bytes: number;
17
+ };
18
+ export declare function drawCmd(): Command;
@@ -0,0 +1,156 @@
1
+ import { Command } from 'commander';
2
+ import { spawnSync } from 'node:child_process';
3
+ import { accessSync, constants } from 'node:fs';
4
+ import { delimiter, join } from 'node:path';
5
+ import { authHeaders, resolveBase } from './lib/client.js';
6
+ import { askPath } from './lib/api-path.js';
7
+ // `one draw` — ASCII diagrams in the terminal, via lazydraw
8
+ // (github.com/mpospirit/lazydraw, MIT, © Çağrı Gökpunar).
9
+ //
10
+ // NOT A DEPENDENCY, on purpose. The CLI's runtime deps are exactly commander +
11
+ // @oneie/sdk, and lazydraw is a Bun TUI (its bin is `src/cli.ts`, Bun >= 1.3)
12
+ // while `one` runs on node. So we spawn it: `lazydraw` if it is on PATH, else
13
+ // `bun x lazydraw@<pinned>`. Without Bun there is no editor to open, and the
14
+ // command says so in one line instead of a stack trace.
15
+ //
16
+ // What earns a verb here:
17
+ // draw [args…] PASSTHROUGH — `one draw`, `one draw <name>`, `one draw list`,
18
+ // `one draw export <name> --basic --fenced -o f` are lazydraw's own.
19
+ // attach EARNS IT — exports a drawing and posts it to a task's thread
20
+ // through tasks:comment, so a sketch lands on the board row it
21
+ // explains. The door caps a comment at 4000 bytes; a bigger
22
+ // diagram is REFUSED here with both numbers, never cut mid-line.
23
+ /** Pinned so `bun x` cannot quietly run a different release. ONE_LAZYDRAW overrides. */
24
+ export const LAZYDRAW_PKG = 'lazydraw@0.1.1';
25
+ /** tasks:comment's MAX_COMMENT_BYTES (one.ie/web/src/lib/resolvers/tasks.ts). */
26
+ export const COMMENT_MAX_BYTES = 4000;
27
+ const DEFAULT_API = 'https://api.one.ie';
28
+ function onPath(bin, path = process.env.PATH ?? '') {
29
+ for (const dir of path.split(delimiter)) {
30
+ if (!dir)
31
+ continue;
32
+ try {
33
+ accessSync(join(dir, bin), constants.X_OK);
34
+ return true;
35
+ }
36
+ catch {
37
+ /* next dir */
38
+ }
39
+ }
40
+ return false;
41
+ }
42
+ /** The argv that runs lazydraw on this machine, or null when neither lazydraw nor bun is reachable. */
43
+ export function resolveRunner(has = (b) => onPath(b)) {
44
+ if (has('lazydraw'))
45
+ return ['lazydraw'];
46
+ if (has('bun'))
47
+ return ['bun', 'x', process.env.ONE_LAZYDRAW || LAZYDRAW_PKG];
48
+ return null;
49
+ }
50
+ const NO_BUN = 'one draw needs Bun >= 1.3 (lazydraw is a Bun app): curl -fsSL https://bun.sh/install | bash — or `bun install -g lazydraw`';
51
+ /** The comment body `attach` posts, or a refusal naming the budget that bit. */
52
+ export function attachBody(name, diagram) {
53
+ const body = `Diagram \`${name}\` (one draw):\n\n${diagram.trim()}`;
54
+ const bytes = Buffer.byteLength(body, 'utf8');
55
+ if (!diagram.trim())
56
+ return { ok: false, error: `drawing "${name}" exported empty`, bytes };
57
+ if (bytes > COMMENT_MAX_BYTES) {
58
+ return {
59
+ ok: false,
60
+ error: `drawing "${name}" is ${bytes} bytes as a comment; tasks:comment keeps ${COMMENT_MAX_BYTES} — not posted (crop it, or export -o and attach the file)`,
61
+ bytes,
62
+ };
63
+ }
64
+ return { ok: true, body, bytes };
65
+ }
66
+ function fail(msg) {
67
+ process.stderr.write(`error ${msg}\n`);
68
+ process.exitCode = 1;
69
+ }
70
+ async function askComment(api, data) {
71
+ const res = await fetch(askPath(resolveBase({ api }, DEFAULT_API), 'tasks:comment'), {
72
+ method: 'POST',
73
+ headers: authHeaders(),
74
+ body: JSON.stringify({ data }),
75
+ });
76
+ const text = await res.text();
77
+ let o;
78
+ try {
79
+ o = JSON.parse(text);
80
+ }
81
+ catch {
82
+ throw new Error(`tasks:comment → ${res.status} ${text.slice(0, 200)}`);
83
+ }
84
+ if (o.outcome && o.outcome !== 'result') {
85
+ const inner = (o.result ?? {});
86
+ // ok:false LAST — an inner body's own `ok` must never overwrite a failed outcome.
87
+ return { ...inner, ok: false, error: inner.error ?? String(o.outcome) };
88
+ }
89
+ if (!res.ok)
90
+ throw new Error(`tasks:comment → ${res.status} ${text.slice(0, 200)}`);
91
+ return (o.result ?? o) ?? {};
92
+ }
93
+ export function drawCmd() {
94
+ const cmd = new Command('draw')
95
+ .description('ASCII diagrams in the terminal (lazydraw) — `one draw [name]`, `list`, `export`, `attach`')
96
+ .argument('[args...]', 'passed to lazydraw: <name|path> · list · export <name> [--basic] [--comment s] [--fenced] [-o f] · --import f')
97
+ .allowUnknownOption()
98
+ .helpOption('-h, --help', 'show this help (lazydraw’s own: one draw -- --help)')
99
+ .action((args) => {
100
+ const runner = resolveRunner();
101
+ if (!runner)
102
+ return fail(NO_BUN);
103
+ const [bin, ...pre] = runner;
104
+ const r = spawnSync(bin, [...pre, ...args], { stdio: 'inherit' });
105
+ if (r.error)
106
+ return fail(`${bin}: ${r.error.message}`);
107
+ process.exitCode = r.status ?? 1;
108
+ });
109
+ cmd
110
+ .command('attach <name>')
111
+ .description('Export a drawing and post it to a task thread (tasks:comment); refuses over the 4000-byte comment cap')
112
+ .requiredOption('--task <tid>', 'Task id, e.g. task:01a0…')
113
+ .option('--workspace <slug>', 'Workspace the task lives in (one you control)')
114
+ .option('--extended', 'Box-drawing characters instead of plain ASCII (+ - |)')
115
+ .option('--api <url>', 'API base URL', DEFAULT_API)
116
+ .option('--json', 'Print the receipt as JSON')
117
+ .action(async (name, opts) => {
118
+ const runner = resolveRunner();
119
+ if (!runner)
120
+ return fail(NO_BUN);
121
+ const [bin, ...pre] = runner;
122
+ const exportArgs = ['export', name, '--fenced', ...(opts.extended ? [] : ['--basic'])];
123
+ const r = spawnSync(bin, [...pre, ...exportArgs], { encoding: 'utf8' });
124
+ if (r.error)
125
+ return fail(`${bin}: ${r.error.message}`);
126
+ if (r.status !== 0)
127
+ return fail((r.stderr || `lazydraw export exited ${r.status}`).trim());
128
+ const built = attachBody(name, r.stdout);
129
+ if (!built.ok)
130
+ return fail(built.error);
131
+ const res = await askComment(opts.api, {
132
+ tid: opts.task,
133
+ body: built.body,
134
+ ...(opts.workspace ? { workspace: opts.workspace } : {}),
135
+ });
136
+ // The door's own receipt decides "cut", never our byte count: it trims before
137
+ // it measures, so comparing against what we sent reads a newline as a loss.
138
+ const submitted = typeof res.submittedBytes === 'number' ? res.submittedBytes : undefined;
139
+ const stored = typeof res.storedBytes === 'number' ? res.storedBytes : undefined;
140
+ const cut = res.truncated === true || (submitted !== undefined && stored !== undefined && stored < submitted);
141
+ const json = opts.json || process.argv.includes('--json');
142
+ const failed = res.ok === false || typeof res.error === 'string';
143
+ const receipt = { ok: !failed && !cut, tid: opts.task, drawing: name, submittedBytes: submitted, storedBytes: stored, ...(cut ? { truncated: true } : {}), ...(res.error ? { error: res.error } : {}) };
144
+ if (json)
145
+ process.stdout.write(JSON.stringify(receipt, null, 2) + '\n');
146
+ if (failed) {
147
+ const landed = typeof res.durability === 'string' ? ` (${res.durability})` : '';
148
+ return fail(`tasks:comment refused: ${String(res.error)}${landed}${res.retryable ? ' — retryable, run it again' : ''}`);
149
+ }
150
+ if (cut)
151
+ return fail(`posted but CUT: ${submitted} bytes submitted, ${stored} stored`);
152
+ if (!json)
153
+ process.stdout.write(`✓ ${name} → ${opts.task} (${built.bytes} bytes)\n`);
154
+ });
155
+ return cmd;
156
+ }
package/dist/src/group.js CHANGED
@@ -2,6 +2,7 @@ import { Command } from 'commander';
2
2
  import { createReadStream, existsSync } from 'node:fs';
3
3
  import { createInterface } from 'node:readline';
4
4
  import { out, resolveBase, resolveKey } from './lib/client.js';
5
+ import { watchCommands } from './join.js';
5
6
  const DEFAULT_API = resolveBase({}, 'https://one.ie');
6
7
  function readApiKey() {
7
8
  const key = resolveKey();
@@ -111,5 +112,6 @@ export function groupCmd() {
111
112
  dry_run: opts.dryRun ?? false,
112
113
  });
113
114
  });
115
+ watchCommands(cmd);
114
116
  return cmd;
115
117
  }
package/dist/src/index.js CHANGED
@@ -19,6 +19,7 @@ import { evalCmd } from './eval.js';
19
19
  import { setupCmd } from './setup.js';
20
20
  import { clientCmd } from './client.js';
21
21
  import { walletCmd } from './wallet.js';
22
+ import { keyCmd } from './key.js';
22
23
  import { pushCmd } from './push.js';
23
24
  import { deployCmd } from './deploy.js';
24
25
  import { statusCmd } from './status.js';
@@ -35,8 +36,10 @@ import { pluginCmd } from './plugin.js';
35
36
  import { workflowCmd } from './workflow.js';
36
37
  import { tasksCmd } from './tasks.js';
37
38
  import { mediaCmd } from './media.js';
39
+ import { drawCmd } from './draw.js';
38
40
  import { endpointCmd } from './endpoint.js';
39
41
  import { shopCmd } from './shop.js';
42
+ import { bareDoors, joinCommands } from './join.js';
40
43
  import { readFileSync } from 'node:fs';
41
44
  import { fileURLToPath } from 'node:url';
42
45
  import { resolve, dirname } from 'node:path';
@@ -67,6 +70,7 @@ program.addCommand(doctorCmd());
67
70
  program.addCommand(whoamiCmd());
68
71
  program.addCommand(buildLoginCommand());
69
72
  program.addCommand(walletCmd());
73
+ program.addCommand(keyCmd());
70
74
  program.addCommand(pushCmd());
71
75
  program.addCommand(deployCmd());
72
76
  program.addCommand(statusCmd());
@@ -84,22 +88,21 @@ program.addCommand(pluginCmd());
84
88
  program.addCommand(workflowCmd());
85
89
  program.addCommand(tasksCmd());
86
90
  program.addCommand(mediaCmd());
91
+ program.addCommand(drawCmd());
87
92
  program.addCommand(endpointCmd());
88
93
  program.addCommand(shopCmd());
94
+ joinCommands(program);
89
95
  // Bare `oneie` (no args, no --help/--version): route the audience to its
90
96
  // journey instead of commander's default help dump. Never an interactive
91
97
  // prompt — agent env and human TTY both get a printed block (contract #10).
92
98
  if (process.argv.length === 2) {
93
99
  if (isAgentEnvironment()) {
94
- process.stdout.write('oneie — no workspace yet.\n' +
95
- ' oneie init --write-env # provision a workspace, no account required\n' +
96
- ' oneie onboard # provision + walk the lifecycle stages\n' +
97
- ' oneie --help # full command reference\n');
100
+ // Two doors, new group and existing group (text/join-existing-plan.md § W2).
101
+ process.stdout.write('oneie — no workspace yet.\n' + bareDoors(true));
98
102
  }
99
103
  else {
100
104
  displayBanner();
101
- process.stdout.write(' npx oneie create <name> # scaffold a new workspace\n' +
102
- ' oneie --help # full command reference\n');
105
+ process.stdout.write(bareDoors(false));
103
106
  }
104
107
  process.exit(0);
105
108
  }
@@ -0,0 +1,11 @@
1
+ import type { Command } from 'commander';
2
+ export declare const JOIN_VERBS: readonly ["request", "requests", "approve"];
3
+ /** The door block bare `oneie` prints — contract #10: printed, never prompted. */
4
+ export declare function bareDoors(agent: boolean): string;
5
+ export declare function joinCommands(program: Command): void;
6
+ /**
7
+ * `oneie group follow|unfollow <group>` — watch a PUBLIC group
8
+ * (text/join-existing-plan.md W3 D2). Mounted on the existing `group` command
9
+ * by group.ts, because a top-level `follow` is taken.
10
+ */
11
+ export declare function watchCommands(group: Command): void;
@@ -0,0 +1,292 @@
1
+ import { jsonMode, resolveBase, resolveKey } from './lib/client.js';
2
+ import { askPath } from './lib/api-path.js';
3
+ // The existing-group door (text/join-existing-plan.md § W2). A newcomer — person
4
+ // or agent — becomes someone (`oneie login`), asks a group's owner to let them
5
+ // in, and the owner answers. Each verb is one receiver through the ask door; the
6
+ // receiver owns authority, validation and the owner notice.
7
+ //
8
+ // `follow <group>` is NOT a top-level verb: `oneie follow <type>` is already the
9
+ // path-selection verb (substrate.ts), and commander 12 throws on a duplicate
10
+ // name at registration — before index.ts reaches the bare-argv check — so a
11
+ // second `follow` would crash every invocation, bare `oneie` included. Watching
12
+ // a group is `oneie group follow <group>` (watchCommands, mounted by group.ts).
13
+ const DEFAULT_API = 'https://one.ie';
14
+ const ROLES = ['viewer', 'member', 'admin'];
15
+ const STATUSES = ['pending', 'approved', 'rejected'];
16
+ export const JOIN_VERBS = ['request', 'requests', 'approve'];
17
+ /** The door block bare `oneie` prints — contract #10: printed, never prompted. */
18
+ export function bareDoors(agent) {
19
+ const newGroup = agent
20
+ ? ' oneie init --write-env # provision a group, no account required\n' +
21
+ ' oneie onboard # provision + walk the lifecycle stages\n'
22
+ : ' npx oneie create <name> # scaffold a new group\n';
23
+ return ('new group:\n' +
24
+ newGroup +
25
+ 'existing group:\n' +
26
+ ' oneie login # become someone — no new group\n' +
27
+ " oneie request <group> [--reason] # ask the owner to let you in\n" +
28
+ " oneie requests [--group <g>] # your asks, or an owner's queue\n" +
29
+ ' oneie approve <requestId> [--reject]\n' +
30
+ ' oneie group follow <group> # watch a public group\n' +
31
+ ' oneie --help # full command reference\n');
32
+ }
33
+ const NO_KEY = 'no API key — run `oneie login` (or set ONE_API_KEY)';
34
+ function fail(cmd, error) {
35
+ if (jsonMode(cmd))
36
+ process.stdout.write(JSON.stringify({ ok: false, error }) + '\n');
37
+ else
38
+ process.stderr.write(`error ${error}\n`);
39
+ process.exitCode = 1;
40
+ }
41
+ /** One receiver through the ask door. Throws with the receiver's own reason on any refusal. */
42
+ async function ask(api, key, receiver, data) {
43
+ const base = resolveBase({ api }, DEFAULT_API);
44
+ const res = await fetch(askPath(base, receiver), {
45
+ method: 'POST',
46
+ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
47
+ body: JSON.stringify({ data }),
48
+ });
49
+ const text = await res.text();
50
+ let body;
51
+ try {
52
+ body = text ? JSON.parse(text) : undefined;
53
+ }
54
+ catch {
55
+ throw new Error(`${receiver} → ${res.status} ${text.slice(0, 200)}`);
56
+ }
57
+ if (!body || !('outcome' in body)) {
58
+ if (!res.ok)
59
+ throw new Error(`${receiver} → ${res.status} ${text.slice(0, 200)}`);
60
+ return body ?? {};
61
+ }
62
+ if (body.outcome === 'result') {
63
+ const r = (body.result ?? {});
64
+ if (r.ok === false)
65
+ throw new Error(String(r.error ?? `${receiver} refused`));
66
+ return r;
67
+ }
68
+ // A dissolve answers 200 — the signal reached nobody. Name it, never read it as ok.
69
+ if (body.outcome === 'dissolved') {
70
+ throw new Error(`${receiver} is not live on ${base} yet (dissolved: ${String(body.reason ?? 'no handler')})`);
71
+ }
72
+ const inner = body.result;
73
+ throw new Error(String(inner?.error ?? body.error ?? `${receiver}: ${String(body.outcome)}`));
74
+ }
75
+ // An unregistered `world:<name>` is not a dissolve on the web door: it is read as
76
+ // `world:<tag-expr>` and routed (measured on prod 2026-09-26 — world:list-requests
77
+ // answered outcome "result" {routed:"learned", actor:"ceo"}). So an answer missing
78
+ // the field the verb exists to return is refused, never printed as empty.
79
+ function notLive(receiver, missing, r) {
80
+ const routed = r.routed ? ` — routed as a world tag (routed=${String(r.routed)}, actor=${String(r.actor ?? '?')})` : '';
81
+ return `${receiver} is not live here yet: answer carried ${missing}${routed}`;
82
+ }
83
+ /** Resolve the key or refuse; every verb here acts as someone. */
84
+ function keyOrFail(cmd) {
85
+ const key = resolveKey();
86
+ if (!key)
87
+ fail(cmd, NO_KEY);
88
+ return key || undefined;
89
+ }
90
+ function cell(v) {
91
+ if (v === undefined || v === null || v === '')
92
+ return '-';
93
+ // A cell is receiver data, and a reason is a stranger's text: no control
94
+ // character (ESC, BEL, CR) reaches the terminal.
95
+ return String(v).replace(/\p{Cc}+/gu, ' ').replace(/\s+/g, ' ').slice(0, 40);
96
+ }
97
+ export function joinCommands(program) {
98
+ program
99
+ .command('request <group>')
100
+ .description("Ask a group's owner to let you in — always pends, never auto-grants")
101
+ .option('--role <role>', 'Role to ask for: viewer | member | admin')
102
+ .option('--reason <text>', 'Why — shown to the owner')
103
+ .option('--api <url>', 'API base URL', DEFAULT_API)
104
+ .action(async (group, opts, cmd) => {
105
+ if (opts.role && !ROLES.includes(opts.role)) {
106
+ return fail(cmd, `--role must be one of ${ROLES.join(' | ')} (got "${opts.role}")`);
107
+ }
108
+ const key = keyOrFail(cmd);
109
+ if (!key)
110
+ return;
111
+ const data = { group };
112
+ if (opts.role)
113
+ data.role = opts.role;
114
+ if (opts.reason)
115
+ data.reason = opts.reason;
116
+ let r;
117
+ try {
118
+ r = await ask(opts.api, key, 'world:request-access', data);
119
+ }
120
+ catch (e) {
121
+ return fail(cmd, e.message);
122
+ }
123
+ if (typeof r.requestId !== 'string')
124
+ return fail(cmd, notLive('world:request-access', 'no requestId', r));
125
+ if (jsonMode(cmd)) {
126
+ process.stdout.write(JSON.stringify({ ok: true, ...r, group }) + '\n');
127
+ return;
128
+ }
129
+ process.stdout.write(`ok requestId=${JSON.stringify(r.requestId)} group=${JSON.stringify(group)}\n`);
130
+ if (r.existing === true)
131
+ process.stdout.write(`an ask to ${group} was already pending — no new notice sent; check with: oneie requests\n`);
132
+ else if (r.notified === true)
133
+ process.stdout.write(`the owner of ${group} has been notified — follow the answer with: oneie requests\n`);
134
+ else if (r.notified === false)
135
+ process.stdout.write(`the owner of ${group} was NOT notified — send them the requestId\n`);
136
+ else
137
+ process.stdout.write(`pending — the owner answers from their queue; check with: oneie requests\n`);
138
+ });
139
+ program
140
+ .command('requests')
141
+ .description("List access requests — your own asks, or an owner's queue for a group")
142
+ .option('--group <g>', "Group whose queue to list (owner/admin)")
143
+ .option('--status <s>', 'pending | approved | rejected')
144
+ .option('--api <url>', 'API base URL', DEFAULT_API)
145
+ .action(async (opts, cmd) => {
146
+ if (opts.status && !STATUSES.includes(opts.status)) {
147
+ return fail(cmd, `--status must be one of ${STATUSES.join(' | ')} (got "${opts.status}")`);
148
+ }
149
+ const key = keyOrFail(cmd);
150
+ if (!key)
151
+ return;
152
+ const data = {};
153
+ if (opts.group)
154
+ data.group = opts.group;
155
+ if (opts.status)
156
+ data.status = opts.status;
157
+ let r;
158
+ try {
159
+ r = await ask(opts.api, key, 'world:list-requests', data);
160
+ }
161
+ catch (e) {
162
+ return fail(cmd, e.message);
163
+ }
164
+ const list = r.requests ?? r.rows;
165
+ if (!Array.isArray(list))
166
+ return fail(cmd, notLive('world:list-requests', 'no request list', r));
167
+ if (jsonMode(cmd)) {
168
+ process.stdout.write(JSON.stringify({ ok: true, ...r }) + '\n');
169
+ return;
170
+ }
171
+ const rows = list;
172
+ const total = typeof r.total === 'number' ? r.total : rows.length;
173
+ if (rows.length === 0)
174
+ process.stdout.write('no requests\n');
175
+ else {
176
+ const head = ['requestId', 'group', 'role', 'status', 'requester', 'reason'];
177
+ const body = rows.map((x) => [
178
+ cell(x.requestId ?? x.id),
179
+ cell(x.group ?? x.gid),
180
+ cell(x.role),
181
+ cell(x.status),
182
+ cell(x.requester ?? x.actor ?? x.aid ?? x.uid),
183
+ cell(x.reason),
184
+ ]);
185
+ const w = head.map((h, i) => Math.max(h.length, ...body.map((b) => b[i].length)));
186
+ for (const line of [head, ...body])
187
+ process.stdout.write(line.map((c, i) => c.padEnd(w[i])).join(' ').trimEnd() + '\n');
188
+ }
189
+ // Absent is not false: only a present `truncated` makes total a floor.
190
+ if (r.truncated !== undefined && r.truncated !== false) {
191
+ process.stdout.write(`total=${total} truncated — at least ${total}; ${JSON.stringify(r.truncated)}\n`);
192
+ }
193
+ else {
194
+ process.stdout.write(`total=${total}\n`);
195
+ }
196
+ });
197
+ program
198
+ .command('approve <requestId>')
199
+ .description('Answer an access request — approve by default, --reject to refuse')
200
+ .option('--reject', 'Reject instead of approve')
201
+ .option('--api <url>', 'API base URL', DEFAULT_API)
202
+ .action(async (requestId, opts, cmd) => {
203
+ const key = keyOrFail(cmd);
204
+ if (!key)
205
+ return;
206
+ const decision = opts.reject ? 'rejected' : 'approved';
207
+ let r;
208
+ try {
209
+ r = await ask(opts.api, key, 'world:approve-request', { requestId, decision });
210
+ }
211
+ catch (e) {
212
+ return fail(cmd, e.message);
213
+ }
214
+ // W1 answers `membership` = setMembership's verdict. `failed` (the write
215
+ // did not land) or `refused` (the owner guard said no) means the D1
216
+ // decision is recorded while the requester still holds no role — the one
217
+ // outcome an "ok" line would turn into a lie.
218
+ const membership = typeof r.membership === 'string' ? r.membership : undefined;
219
+ if (membership === 'failed' || membership === 'refused') {
220
+ const error = `approval recorded, but membership was not written (membership=${membership}) — the requester cannot act in the group yet; re-run \`oneie approve ${requestId}\``;
221
+ process.exitCode = 1;
222
+ if (jsonMode(cmd)) {
223
+ process.stdout.write(JSON.stringify({ ...r, ok: false, requestId, decision, error }) + '\n');
224
+ }
225
+ else {
226
+ process.stderr.write(`error ${error}\n`);
227
+ }
228
+ return;
229
+ }
230
+ if (jsonMode(cmd)) {
231
+ process.stdout.write(JSON.stringify({ ...r, ok: true, requestId, decision }) + '\n');
232
+ return;
233
+ }
234
+ const verdict = membership ? ` membership=${membership}` : '';
235
+ process.stdout.write(`ok requestId=${JSON.stringify(requestId)} decision=${JSON.stringify(decision)}${verdict}\n`);
236
+ });
237
+ }
238
+ /**
239
+ * `oneie group follow|unfollow <group>` — watch a PUBLIC group
240
+ * (text/join-existing-plan.md W3 D2). Mounted on the existing `group` command
241
+ * by group.ts, because a top-level `follow` is taken.
242
+ */
243
+ export function watchCommands(group) {
244
+ group
245
+ .command('follow <group>')
246
+ .description("Watch a public group — its announces reach your inbox (no membership, no role)")
247
+ .option('--api <url>', 'API base URL', DEFAULT_API)
248
+ .action(async (target, opts, cmd) => {
249
+ const key = keyOrFail(cmd);
250
+ if (!key)
251
+ return;
252
+ let r;
253
+ try {
254
+ r = await ask(opts.api, key, 'groups:follow', { group: target });
255
+ }
256
+ catch (e) {
257
+ return fail(cmd, e.message);
258
+ }
259
+ if (r.following !== true)
260
+ return fail(cmd, notLive('groups:follow', 'no following:true', r));
261
+ const slug = typeof r.group === 'string' ? r.group : target;
262
+ if (jsonMode(cmd)) {
263
+ process.stdout.write(JSON.stringify({ ok: true, ...r, group: slug }) + '\n');
264
+ return;
265
+ }
266
+ process.stdout.write(`ok following ${JSON.stringify(slug)} — its announces now reach your inbox; stop with: oneie group unfollow ${slug}\n`);
267
+ });
268
+ group
269
+ .command('unfollow <group>')
270
+ .description('Stop watching a group (a declared subscription on it is left alone)')
271
+ .option('--api <url>', 'API base URL', DEFAULT_API)
272
+ .action(async (target, opts, cmd) => {
273
+ const key = keyOrFail(cmd);
274
+ if (!key)
275
+ return;
276
+ let r;
277
+ try {
278
+ r = await ask(opts.api, key, 'groups:unfollow', { group: target });
279
+ }
280
+ catch (e) {
281
+ return fail(cmd, e.message);
282
+ }
283
+ if (r.following !== false)
284
+ return fail(cmd, notLive('groups:unfollow', 'no following:false', r));
285
+ const slug = typeof r.group === 'string' ? r.group : target;
286
+ if (jsonMode(cmd)) {
287
+ process.stdout.write(JSON.stringify({ ok: true, ...r, group: slug }) + '\n');
288
+ return;
289
+ }
290
+ process.stdout.write(`ok not following ${JSON.stringify(slug)}\n`);
291
+ });
292
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * key.ts — `one key new | recover | public | verify`, the text/key.md door on a terminal.
3
+ *
4
+ * A VERB OVER WALLET KEYGEN, NOT A SECOND DERIVATION. Every address comes from
5
+ * `@oneie/sdk/wallet` — the same core `one wallet keygen`, packages/recover and
6
+ * the browser (by parity test) derive with. The public identity is the SDK's
7
+ * `@oneie/sdk/key-identity`, byte-identical to one.ie/web's `deriveUserIdPub`.
8
+ *
9
+ * THE KEY NEVER LEAVES THIS MACHINE.
10
+ * • new · recover · public make no network call at all.
11
+ * • verify makes one kind of call — `fetchReferences(base, apiKey)` — and it is
12
+ * structurally unable to send the key: its only inputs are a URL and the API
13
+ * key. It reads the public identities the server holds and the comparison
14
+ * happens HERE, so not even the public identity is transmitted.
15
+ * • The words never come from argv (shell history, `ps`): env or stdin, or a
16
+ * hidden prompt on a terminal. An argv token is never echoed — it may BE the
17
+ * phrase.
18
+ * • Under --json the words never reach stdout (an agent's stdout is a model
19
+ * context and a session log). They reach disk only behind keygen's own
20
+ * --yes-i-accept-plaintext-file, at 0600.
21
+ */
22
+ import { Command } from 'commander';
23
+ export declare function keyCmd(): Command;