@tokenoftrust/cli 1.4.0-rc.2 → 1.4.0-rc.20

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
@@ -5,11 +5,12 @@ One command to go from a Token of Trust invite to a running store.
5
5
  ```sh
6
6
  npm i -g @tokenoftrust/cli
7
7
 
8
- tot checkout # list the stores you can build on
9
- tot checkout <tenant> --clone ./my-store
8
+ tot clone # list the stores you can build on
9
+ tot clone <tenant> my-store # mirrors `git clone`; dir defaults to <tenant>
10
10
  cd my-store
11
11
  tot dev # run it locally with save→reload — no Docker needed
12
- tot submit # (coming) submit it for preview
12
+ tot preview # bundle your edits into a compliance-reviewed preview
13
+ tot ship # promote a reconciled preview live (diff + one confirm)
13
14
  ```
14
15
 
15
16
  **Prerequisites: Node.js and an invite. Nothing else.** `tot dev` downloads the
@@ -22,10 +23,12 @@ be fetched.)
22
23
 
23
24
  | Command | Status | What it does |
24
25
  | --- | --- | --- |
25
- | `tot checkout [<tenant>]` | **built** | Clone a store you're entitled to build on, with an authenticated remote configured. No arg → list your stores. |
26
- | `tot validate` | next | Lint your store before you submit. |
26
+ | `tot clone [<tenant>] [<dir>]` | **built** | Clone a store you're entitled to build on (mirrors `git clone`), with an authenticated remote configured. Dir defaults to `<tenant>`. No arg → list your stores. |
27
+ | `tot validate` | next | Lint your store before you preview. |
27
28
  | `tot dev` | **built** | Run your store locally with save→reload — NATIVELY (no Docker; falls back to it with `--docker` or automatically if the native artifact isn't available). |
28
- | `tot submit` | next | Submit your store for preview (pushes the preview ref, reports the reconcile/compliance verdict + preview URL). |
29
+ | `tot preview` | **built** | Bundle your edits into a compliance-reviewed preview (validates, auto-commits the known content trees, pushes the preview ref, opens/updates a candidate PR, reports the reconcile/compliance verdict + preview URL). `tot submit` / `tot deploy` still work as teaching aliases for this same flow. |
30
+ | `tot ship` | **built** | Promote a reconciled preview live: always shows a diff-vs-live and asks for one `[y/N]` confirm (no `--yes`, refuses outside a terminal); records an approval request if you're not authorised to ship yourself. |
31
+ | `tot pr [list\|view\|close]` | **built** | See and manage the candidate PRs `tot preview` opens (`gh pr`-shaped). |
29
32
  | `tot doctor` | built | Check this machine is ready and show which context `tot` detected. |
30
33
 
31
34
  ## Context-aware
@@ -34,7 +37,7 @@ The same `tot` does the right thing wherever you run it (walks up like `git`):
34
37
 
35
38
  - **storefront monorepo** — a full platform checkout;
36
39
  - **tenant checkout** — a standalone `content/ public/ theme.json .tot/config.json` clone (tenant read from `.tot/config.json`);
37
- - **loose** — anywhere else; `tot checkout <tenant> --clone <dir>` gets you a checkout.
40
+ - **loose** — anywhere else; `tot clone <tenant>` gets you a checkout.
38
41
 
39
42
  `tot doctor` prints the detected context.
40
43
 
@@ -42,8 +45,8 @@ The same `tot` does the right thing wherever you run it (walks up like `git`):
42
45
 
43
46
  `tot` talks to the Token of Trust MCP (default `https://mcp.tokenoftrust.com`, override with `--mcp` or `MCP_BASE_URL`). It is **single-plane**: the only identity is **you**, signed in against the MCP over OAuth.
44
47
 
45
- - Run `tot login` once — it opens your browser (or falls back to a device code on a headless box), you sign in as yourself, and the session is cached at `~/.tot/credentials.json` and refreshed silently. Every later command (`tot checkout`, `tot start`, `tot submit`, …) runs as you, with no re-auth. Entitlement is derived server-side from your ToT memberships.
46
- - Not signed in? On a terminal, `tot start` / `tot checkout` **offer to sign you in right there** and continue in-flow — no "run `tot login`, then re-run".
48
+ - Run `tot login` once — it opens your browser (or falls back to a device code on a headless box), you sign in as yourself, and the session is cached at `~/.tot/credentials.json` and refreshed silently. Every later command (`tot clone`, `tot start`, `tot preview`, `tot ship`, …) runs as you, with no re-auth. Entitlement is derived server-side from your ToT memberships.
49
+ - Not signed in? On a terminal, `tot start` / `tot clone` **offer to sign you in right there** and continue in-flow — no "run `tot login`, then re-run".
47
50
  - The old operator env-triple (`TOT_API_KEY` / `TOT_SECRET_KEY` / `TOT_APP_DOMAIN`) **no longer signs the CLI in** — tot-mcp went OAuth-first on 2026-07-23. If those vars are set, `tot` prints a one-line advisory and uses your `tot login` session anyway; it never reads them for auth.
48
51
 
49
52
  ### Optional: multiple identities at once (`TOT_PROFILE`)
package/bin/tot.mjs CHANGED
@@ -8,11 +8,19 @@
8
8
  * tot login sign in to Token of Trust (OAuth) ← built (MCP OAuth PKCE loopback; caches ~/.tot/credentials.json)
9
9
  * tot logout sign out (clear the cached session) ← built (deletes ~/.tot/credentials.json; local-only, no server revoke)
10
10
  * tot whoami who you're signed in as ← built
11
+ * tot link link your identity to the ToT broker (resolve store scope) ← built
11
12
  * tot grants capability/tier/expiry per store you can act on ← built (introspection diagnostics)
12
- * tot checkout [<tenant>] clone a store you can build on ← built
13
+ * tot clone [<tenant>] clone a store you can build on ← built
13
14
  * tot validate lint your store before you submit ← built
14
15
  * tot dev run your store locally with save→reload ← built (monorepo: host astro; standalone: runs the published runner image)
15
- * tot submit submit your store for preview ← built (validate + push preview ref; MCP preview_status read-back)
16
+ * tot preview push your store to a reviewable preview ← built (validate + push preview ref; MCP preview_status read-back). `submit`/`deploy` are teaching aliases.
17
+ * tot ship publish the current green aggregate live ← built (GET/POST /api/changes/ship → b09 orchestrator; exact plan + y/N confirm; waits for VERIFIED live truth)
18
+ * tot accept / tot merge queue a PR into the preview aggregate ← built (b08: plan + y/N confirm → POST /api/changes/integrate = b07 queue enqueue; NO merge-to-main, NO go-live; refuses non-TTY without --yes)
19
+ * tot sync fetch `preview` + merge it into your branch ← built (b16: the common accept-conflict recovery path; local-only, stops safely on conflict)
20
+ * tot rollback [<version>] instant re-point to a prior live version ← built (u3 promotion_status/promotion_rollback seam; diff + y/N confirm; refuses non-TTY / ineligible)
21
+ * tot pr list / view / close your candidate PRs ← built (candidate_status/candidate_close; gh-pr-shaped)
22
+ * tot branches full branch-cleanup report (every branch, not just open PRs) ← built (b14: candidate_list)
23
+ * tot cleanup owner-confirmed branch GC (deletes terminal branches only) ← built (b14: candidate_list + candidate_delete; --dry-run classifies only)
16
24
  * tot doctor check this machine is ready
17
25
  * tot ideas copy-paste AI prompts that reliably wow
18
26
  * tot feedback send a note to ToT + your recent CLI activity ← built (activity-log.mjs → feedback_submit MCP tool)
@@ -24,7 +32,7 @@
24
32
  * from anywhere else. Every command receives the detected context.
25
33
  *
26
34
  * This package is `@tokenoftrust/cli` (bin `tot`). Its heaviest command, `tot dev`,
27
- * fetches the published storefront runner; `tot checkout/validate/submit` are
35
+ * fetches the published storefront runner; `tot clone/validate/submit` are
28
36
  * pure Node. Dependency-free by design so `npm i -g @tokenoftrust/cli` stays light.
29
37
  */
30
38
  import "../src/ensure-node.mjs"; // hard Node-version gate — must stay first (see the module doc)
@@ -32,9 +40,10 @@ import { readFileSync } from "node:fs";
32
40
  import { detectContext } from "../src/context.mjs";
33
41
  import { printError } from "../src/errors.mjs";
34
42
  import { recordActivity, redactArgs } from "../src/activity-log.mjs";
43
+ import { emitActivity, capRendered } from "../src/activity.mjs";
35
44
  import { maybeNotifyUpdate } from "../src/update-check.mjs";
36
45
 
37
- const BUILD_ORDER = ["checkout", "validate", "dev", "submit"];
46
+ const BUILD_ORDER = ["clone", "validate", "dev", "preview"];
38
47
 
39
48
  // CLI version (stamped into the activity log). Read from our own package.json; best-effort.
40
49
  const VERSION = (() => {
@@ -53,11 +62,23 @@ tot — Token of Trust developer CLI
53
62
  tot login sign in to Token of Trust
54
63
  tot logout sign out (clear the cached session)
55
64
  tot whoami show who you're signed in as
65
+ tot link link your identity so your stores resolve
56
66
  tot grants capability/tier/expiry per store you can act on
57
- tot checkout [<tenant>] clone a store you can build on
67
+ tot clone [<tenant>] clone a store you can build on
58
68
  tot validate lint your store before you submit
59
69
  tot dev run your store locally with save→reload
60
- tot submit submit your store for preview
70
+ tot preview push your store to a reviewable preview
71
+ tot ship publish the tenant's current green aggregate live (plan → confirm → ship)
72
+ tot accept / tot merge queue a PR into the preview aggregate — operator verb, no go-live (plan → confirm → integrate)
73
+ tot sync fetch \`preview\` and merge it into your local branch (accept-conflict recovery)
74
+ tot rollback [<version>] instant re-point to a prior live version (list → confirm → rollback)
75
+ tot revert --preview <PR|sha> remove already-integrated content from the preview aggregate via a new revert commit — no force-reset (plan → confirm → revert)
76
+ tot hotfix --pr <N> OWNER-ONLY exception: release an urgent fix from main to live, bypassing unshipped preview work (plan → confirm → release → auto forward-integrate)
77
+ tot retire evict a candidate PR's preview to reclaim space — operator verb, rebuildable (plan → confirm → evict)
78
+ tot go-live cut the apex domain over to the storefront (readiness → confirm → cutover)
79
+ tot pr list / view / close your candidate PRs
80
+ tot branches full branch-cleanup report — every branch, any PR state, cleanup eligibility
81
+ tot cleanup owner-confirmed branch GC (--dry-run to classify only; deletes terminal branches only)
61
82
  tot doctor check this machine is ready
62
83
  tot ideas copy-paste AI prompts that reliably wow
63
84
  tot feedback "<msg>" send feedback to Token of Trust (attaches recent activity)
@@ -109,6 +130,11 @@ async function dispatch(cmd, rest, ctx) {
109
130
  return run(rest, ctx);
110
131
  }
111
132
 
133
+ if (cmd === "link") {
134
+ const { run } = await import("../src/commands/link.mjs");
135
+ return run(rest, ctx);
136
+ }
137
+
112
138
  if (cmd === "doctor") {
113
139
  const { run } = await import("../src/commands/doctor.mjs");
114
140
  return run(rest, ctx);
@@ -124,8 +150,8 @@ async function dispatch(cmd, rest, ctx) {
124
150
  return run(rest, ctx);
125
151
  }
126
152
 
127
- if (cmd === "checkout") {
128
- const { run } = await import("../src/commands/checkout.mjs");
153
+ if (cmd === "clone") {
154
+ const { run } = await import("../src/commands/clone.mjs");
129
155
  return run(rest, ctx);
130
156
  }
131
157
 
@@ -139,8 +165,103 @@ async function dispatch(cmd, rest, ctx) {
139
165
  return run(rest, ctx);
140
166
  }
141
167
 
142
- if (cmd === "submit") {
143
- const { run } = await import("../src/commands/submit.mjs");
168
+ // dev preview → ship. `preview` is the first-class verb; `submit`/`deploy`
169
+ // reach the SAME preview flow as teaching aliases (preview.mjs prints a one-line
170
+ // hint nudging the developer onto `tot preview` / `tot ship`).
171
+ if (cmd === "preview") {
172
+ const { run } = await import("../src/commands/preview.mjs");
173
+ return run(rest, ctx);
174
+ }
175
+
176
+ if (cmd === "submit" || cmd === "deploy") {
177
+ const { run } = await import("../src/commands/preview.mjs");
178
+ return run(rest, ctx, { alias: cmd });
179
+ }
180
+
181
+ if (cmd === "ship") {
182
+ const { run } = await import("../src/commands/ship.mjs");
183
+ return run(rest, ctx);
184
+ }
185
+
186
+ // `accept` queue-integrates a PR into the protected `preview` aggregate (b08) —
187
+ // NO merge-to-main, NO go-live; going live is `tot ship`, which publishes the
188
+ // whole current GREEN AGGREGATE (b10). Backed by POST /api/changes/integrate
189
+ // (b07's TenantIntegrationQueue.enqueue); see accept.mjs's header. `merge` is a
190
+ // first-class alias, not a teaching nudge: both dispatch straight to the same command.
191
+ if (cmd === "accept" || cmd === "merge") {
192
+ const { run } = await import("../src/commands/accept.mjs");
193
+ return run(rest, ctx);
194
+ }
195
+
196
+ // `sync` is the common accept-conflict recovery path (P1 item 12): fetches the
197
+ // protected `preview` branch and merges it into the developer's local branch so
198
+ // they can resolve locally, then re-`tot preview`. Purely local — no push, no
199
+ // MCP call, never touches the shared `preview`/`main` refs themselves. See
200
+ // sync.mjs's header for the full contract.
201
+ if (cmd === "sync") {
202
+ const { run } = await import("../src/commands/sync.mjs");
203
+ return run(rest, ctx);
204
+ }
205
+
206
+ if (cmd === "rollback") {
207
+ const { run } = await import("../src/commands/rollback.mjs");
208
+ return run(rest, ctx);
209
+ }
210
+
211
+ // `revert --preview <PR|integration-sha>` removes already-integrated content from
212
+ // the protected `preview` aggregate via a NEW auditable revert commit (b21) — NO
213
+ // force-reset, NO touch to main/live. Backed by POST /api/changes/revert (b07's
214
+ // TenantIntegrationQueue.enqueueRevert). To undo something already LIVE, that's
215
+ // `tot rollback`, not this. See revert.mjs's header.
216
+ if (cmd === "revert") {
217
+ const { run } = await import("../src/commands/revert.mjs");
218
+ return run(rest, ctx);
219
+ }
220
+
221
+ // `hotfix --pr <N>` is the OWNER-ONLY EXCEPTION lane (b22): release an urgent fix
222
+ // from `main` to live while `preview` still holds other unshipped work, EXCLUDING
223
+ // that unshipped preview head, then automatically forward-integrate main → preview
224
+ // and re-validate. It is DELIBERATELY a distinct verb — never a `--base main` flag
225
+ // on `tot ship` (which publishes the whole green preview aggregate). Backed by
226
+ // GET/POST /api/changes/hotfix → b22's HotfixOrchestrator. See hotfix.mjs's header.
227
+ if (cmd === "hotfix") {
228
+ const { run } = await import("../src/commands/hotfix.mjs");
229
+ return run(rest, ctx);
230
+ }
231
+
232
+ // `retire` evicts a candidate PR's hosted preview to reclaim space (unit U7) —
233
+ // a DISTINCT operator verb from `accept`/reject: retire touches no change
234
+ // lifecycle and is reversible-by-rebuild (`tot preview build`). See retire.mjs.
235
+ if (cmd === "retire") {
236
+ const { run } = await import("../src/commands/retire.mjs");
237
+ return run(rest, ctx);
238
+ }
239
+
240
+ if (cmd === "go-live") {
241
+ const { run } = await import("../src/commands/go-live.mjs");
242
+ return run(rest, ctx);
243
+ }
244
+
245
+ if (cmd === "pr") {
246
+ const { run } = await import("../src/commands/pr.mjs");
247
+ return run(rest, ctx);
248
+ }
249
+
250
+ // `branches` is the FULL branch-cleanup report (every branch, any PR state) —
251
+ // distinct from `tot pr list`, which only shows OPEN PRs (P1 item 9). Read-only;
252
+ // always safe to run, and the report `tot cleanup` reuses before deleting anything.
253
+ if (cmd === "branches") {
254
+ const { run } = await import("../src/commands/branches.mjs");
255
+ return run(rest, ctx);
256
+ }
257
+
258
+ // `cleanup` is owner-confirmed BRANCH GC (P1 items 9/10) — an irreversible git-ref
259
+ // delete, distinct from `tot retire`'s hosted-preview eviction (rebuildable, no
260
+ // branch touched). `--dry-run` classifies and prints; it never deletes. Age alone
261
+ // never makes a branch eligible; main/preview are always kept; orphans are
262
+ // quarantined, never auto-deleted. See cleanup.mjs's header.
263
+ if (cmd === "cleanup") {
264
+ const { run } = await import("../src/commands/cleanup.mjs");
144
265
  return run(rest, ctx);
145
266
  }
146
267
 
@@ -149,10 +270,21 @@ async function dispatch(cmd, rest, ctx) {
149
270
  return run(rest, ctx);
150
271
  }
151
272
 
273
+ // `checkout` was deliberately freed up: it's no longer a tot verb precisely so it
274
+ // can mean what it means in git. Point both ways rather than a bare "unknown".
275
+ if (cmd === "checkout") {
276
+ console.error(
277
+ "`tot checkout` isn't a tot command — `checkout` now means what it does in git.\n\n" +
278
+ " • switch branches / restore files in your store: git checkout <ref>\n" +
279
+ " • clone a store you can build on: tot clone <tenant>\n",
280
+ );
281
+ return 2;
282
+ }
283
+
152
284
  if (BUILD_ORDER.includes(cmd)) {
153
285
  console.error(
154
286
  `\`tot ${cmd}\` isn't built yet.\n\n` +
155
- `Build order: ${BUILD_ORDER.map((c) => (c === "checkout" ? `${c}✓` : c)).join(" → ")}.\n` +
287
+ `Build order: ${BUILD_ORDER.map((c) => (c === "clone" ? `${c}✓` : c)).join(" → ")}.\n` +
156
288
  `Inside a storefront checkout you can use the in-repo scripts today ` +
157
289
  `(e.g. \`pnpm tot ${cmd}\`).`,
158
290
  );
@@ -164,12 +296,39 @@ async function dispatch(cmd, rest, ctx) {
164
296
  return 2;
165
297
  }
166
298
 
299
+ /**
300
+ * The safe `subcommand` value for a command's activity event. Only the fixed
301
+ * sub-dispatcher verbs (e.g. `app scaffold` / `app dev`) are surfaced — an
302
+ * arbitrary positional (a tenant name, a path, a code) is NEVER used, so the
303
+ * activity `subcommand` field can't carry PII even before redaction. Returns
304
+ * undefined for every command without a fixed subcommand vocabulary.
305
+ */
306
+ function safeSubcommand(cmd, rest) {
307
+ if (cmd === "app") {
308
+ const sub = rest.find((t) => t && !t.startsWith("-"));
309
+ if (sub === "scaffold" || sub === "dev") return sub;
310
+ }
311
+ return undefined;
312
+ }
313
+
167
314
  async function main() {
168
315
  const [cmd, ...rest] = process.argv.slice(2);
169
316
  const ctx = detectContext();
170
317
  const startedAt = Date.now();
318
+ const command = cmd || "(none)";
319
+ const subcommand = safeSubcommand(cmd, rest);
171
320
  let code = 0;
172
321
  let errMsg = null;
322
+
323
+ // D3: emit `cli.command.invoked` on start — best-effort, a SILENT no-op without a
324
+ // hosted-bridge credential (never a network call / never blocks). Fired without
325
+ // await so it adds no latency to the command; settled alongside the result below.
326
+ const invokedEmit = emitActivity({
327
+ action: "cli.command.invoked",
328
+ outcome: { status: "invoked" },
329
+ payload: { args: { command, ...(subcommand ? { subcommand } : {}), cliVersion: VERSION, node: process.version } },
330
+ });
331
+
173
332
  try {
174
333
  code = await dispatch(cmd, rest, ctx);
175
334
  return code;
@@ -177,17 +336,35 @@ async function main() {
177
336
  errMsg = e?.message || String(e);
178
337
  throw e;
179
338
  } finally {
339
+ const exitCode = errMsg ? 1 : (code ?? 0);
340
+ const durationMs = Date.now() - startedAt;
180
341
  // Best-effort activity breadcrumb (never throws, never blocks). `feedback`'s own
181
342
  // free-text message is omitted — it's user-typed and belongs only in the report.
182
343
  recordActivity({
183
344
  ts: new Date().toISOString(),
184
345
  v: VERSION,
185
- cmd: cmd || "(none)",
346
+ cmd: command,
186
347
  args: cmd === "feedback" ? ["«omitted»"] : redactArgs(rest),
187
- code: errMsg ? 1 : (code ?? 0),
188
- ms: Date.now() - startedAt,
348
+ code: exitCode,
349
+ ms: durationMs,
189
350
  ...(errMsg ? { err: String(errMsg).slice(0, 200) } : {}),
190
351
  });
352
+ // D3: emit `cli.command.result` (exit code + duration + a bounded/redacted
353
+ // rendered field). The house-style error text is capped + run through the JS
354
+ // redaction mirror; per the D0 catalog the `cli.*` rendered lane is empty-
355
+ // allowlisted, so it's DROPPED by design (the safe default for a high-volume
356
+ // action) — the emit path still exercises the mirror. Bounded-await here (with
357
+ // the invoked emit) so a live bridge flushes before the process exits; a no-op
358
+ // when there's no credential.
359
+ const resultEmit = emitActivity({
360
+ action: "cli.command.result",
361
+ outcome: { status: errMsg ? "failed" : "succeeded", durationMs },
362
+ payload: {
363
+ args: { command, ...(subcommand ? { subcommand } : {}), cliVersion: VERSION, exitCode, durationMs },
364
+ ...(errMsg ? { rendered: { output: capRendered(errMsg) } } : {}),
365
+ },
366
+ });
367
+ await Promise.allSettled([invokedEmit, resultEmit]);
191
368
  // Nudge if a newer/unsupported version exists (drawn from cache — instant),
192
369
  // and kick a detached registry refresh if stale. Never throws, never blocks.
193
370
  maybeNotifyUpdate(VERSION);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tokenoftrust/cli",
3
- "version": "1.4.0-rc.2",
4
- "description": "Token of Trust developer CLI — check out a tenant store, run it locally with save→reload, and submit it for preview. Installs the `tot` command.",
3
+ "version": "1.4.0-rc.20",
4
+ "description": "Token of Trust developer CLI — clone a tenant store, run it locally with save→reload, and submit it for preview. Installs the `tot` command.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Token of Trust",
7
7
  "homepage": "https://www.tokenoftrust.com",