@tokenoftrust/cli 6.13.0 → 6.14.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.
package/bin/tot.mjs CHANGED
@@ -22,6 +22,7 @@ import { printError } from "../src/errors.mjs";
22
22
  import { recordActivity, redactArgs } from "../src/activity-log.mjs";
23
23
  import { emitActivity, capRendered } from "../src/activity.mjs";
24
24
  import { maybeNotifyUpdate } from "../src/update-check.mjs";
25
+ import { printMailLine } from "../src/inbox-indicator.mjs";
25
26
  import {
26
27
  currentInvocationDiagnostics,
27
28
  currentInvocationSession,
@@ -74,6 +75,7 @@ const COMMANDS = [
74
75
  { invocation: "doctor", blurb: "check this machine is ready" },
75
76
  { invocation: "ideas", blurb: "copy-paste AI prompts that reliably wow" },
76
77
  { invocation: 'feedback "<msg>"', blurb: "send feedback to Token of Trust (attaches recent activity)" },
78
+ { invocation: "inbox [list|read|ack|done|snooze|reply|threshold]", blurb: "your Token of Trust inbox — replies to your feedback and other news" },
77
79
  { invocation: "app scaffold <name>", blurb: "scaffold a Storefront Private App" },
78
80
  { invocation: "app dev ...", blurb: "local, offline Private App webhook/manifest/JWT harness" },
79
81
  { invocation: "app install", blurb: "install your Private App on your store (env defaults to test); prints the client secret once" },
@@ -161,6 +163,11 @@ async function dispatch(cmd, rest, ctx) {
161
163
  return /** @type {any} */ (run)(rest, ctx);
162
164
  }
163
165
 
166
+ if (cmd === "inbox") {
167
+ const { run } = await import("../src/commands/inbox.mjs");
168
+ return run(rest);
169
+ }
170
+
164
171
  if (cmd === "whoami") {
165
172
  const { run } = await import("../src/commands/whoami.mjs");
166
173
  return run(rest, ctx);
@@ -456,6 +463,8 @@ async function main() {
456
463
  },
457
464
  });
458
465
  await Promise.allSettled([invokedEmit, resultEmit]);
466
+ // At most one mailbox line, from what this command's own calls already saw — no request here.
467
+ try { printMailLine(cmd, rest); } catch { /* the indicator never changes a command's outcome */ }
459
468
  // Nudge if a newer/unsupported version exists (drawn from cache — instant),
460
469
  // and kick a detached registry refresh if stale. Never throws, never blocks.
461
470
  maybeNotifyUpdate(VERSION);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/cli",
3
- "version": "6.13.0",
3
+ "version": "6.14.0",
4
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",
@@ -0,0 +1,284 @@
1
+ /**
2
+ * `tot inbox` — your Token of Trust inbox, through the signed-in MCP session.
3
+ *
4
+ * tot inbox [list] [--all] [--state <s>] [--min <level>] [--limit <n>] [--cursor <c>] [--json]
5
+ * tot inbox read <item> [--json]
6
+ * tot inbox ack|done <item> [--json]
7
+ * tot inbox snooze <item> --until <ISO-8601 | 30m | 2h | 1d> [--json]
8
+ * tot inbox reply <item> [--request-id <id>] [--json] (reply text on stdin)
9
+ * tot inbox threshold [fyi|update|action_required] [--json]
10
+ *
11
+ * Every verb is one MCP tool call on the existing client. `reply` takes the action from the
12
+ * item's own descriptor and only ever calls `feedback_reply`; anything else the server names is
13
+ * refused. The inbox commands never print the waiting-mail line (bin/tot.mjs suppresses it).
14
+ */
15
+ import { randomUUID } from "node:crypto";
16
+ import { readSessionCredentials } from "../token-store.mjs";
17
+ import { establishSession, AuthUnavailableError } from "../auth.mjs";
18
+ import { createMcpClient } from "../mcp.mjs";
19
+ import { fail } from "../errors.mjs";
20
+ import { recordDiagnostic } from "../diagnostics.mjs";
21
+ import { INBOX_ATTENTIONS } from "../inbox-indicator.mjs";
22
+
23
+ const DEFAULT_MCP_URL = "https://mcp.tokenoftrust.com";
24
+ const STATES = ["waiting", "read", "acked", "snoozed", "done"];
25
+ const ITEM_ID = /^[A-Za-z0-9][A-Za-z0-9:._-]{2,199}$/;
26
+ const REQUEST_ID = /^[A-Za-z0-9._-]{8,96}$/;
27
+ const MAX_REPLY = 4000;
28
+ const MAX_STDIN_BYTES = 64 * 1024;
29
+ const REPLY_TOOL = "feedback_reply";
30
+
31
+ const USAGE = `tot inbox — your Token of Trust inbox
32
+
33
+ tot inbox what is waiting for you (list)
34
+ tot inbox list [--all] [--state <waiting|read|acked|snoozed|done>]
35
+ [--min <fyi|update|action_required>] [--limit <1-100>] [--cursor <c>]
36
+ tot inbox read <item> one item and its conversation
37
+ tot inbox ack <item> seen it — stops counting as waiting
38
+ tot inbox done <item> finished with it
39
+ tot inbox snooze <item> --until <ISO-8601 | 30m | 2h | 1d>
40
+ tot inbox reply <item> reply on the item's feedback report; the text comes from stdin
41
+ tot inbox threshold [level] show or set what is announced (fyi | update | action_required)
42
+
43
+ --json machine-readable output
44
+ --mcp <url> MCP base URL`;
45
+
46
+ /** Strip terminal control characters from server text. */
47
+ function clean(value) {
48
+ return String(value ?? "").replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g, "");
49
+ }
50
+
51
+ function parseArgs(argv) {
52
+ /** @type {{ positional: string[], json: boolean, help: boolean, all: boolean, state: any, min: any,
53
+ * limit: any, cursor: any, until: any, requestId: any, mcp: any, missing?: string, unknown?: string }} */
54
+ const a = {
55
+ positional: [], json: false, help: false, all: false, state: null, min: null,
56
+ limit: null, cursor: null, until: null, requestId: null, mcp: null,
57
+ };
58
+ const valued = {
59
+ "--state": "state", "--min": "min", "--limit": "limit", "--cursor": "cursor",
60
+ "--until": "until", "--request-id": "requestId", "--mcp": "mcp",
61
+ };
62
+ for (let i = 0; i < argv.length; i++) {
63
+ const t = argv[i];
64
+ if (t === "--json") a.json = true;
65
+ else if (t === "--help" || t === "-h") a.help = true;
66
+ else if (t === "--all") a.all = true;
67
+ else if (t.startsWith("--") && t.includes("=") && valued[t.slice(0, t.indexOf("="))]) {
68
+ a[valued[t.slice(0, t.indexOf("="))]] = t.slice(t.indexOf("=") + 1);
69
+ } else if (valued[t]) {
70
+ const v = argv[i + 1];
71
+ if (v === undefined || v.startsWith("--")) a.missing = t;
72
+ else { a[valued[t]] = v; i++; }
73
+ } else if (t.startsWith("-") && t !== "-") a.unknown = t;
74
+ else a.positional.push(t);
75
+ }
76
+ return a;
77
+ }
78
+
79
+ /**
80
+ * `until` as an ISO instant. Accepts an ISO-8601 timestamp or a relative 30m / 2h / 1d.
81
+ * @param {string} value @param {number} [now]
82
+ * @returns {string|null}
83
+ */
84
+ export function resolveSnoozeUntil(value, now = Date.now()) {
85
+ const rel = /^(\d{1,4})([mhd])$/.exec(String(value));
86
+ if (rel) {
87
+ const unit = { m: 60_000, h: 3_600_000, d: 86_400_000 }[rel[2]];
88
+ return new Date(now + Number(rel[1]) * unit).toISOString();
89
+ }
90
+ if (!/^\d{4}-\d{2}-\d{2}T/.test(String(value))) return null;
91
+ const ms = Date.parse(value);
92
+ return Number.isNaN(ms) ? null : new Date(ms).toISOString();
93
+ }
94
+
95
+ /** @param {NodeJS.ReadableStream} stream */
96
+ async function readStdin(stream) {
97
+ /** @type {Buffer[]} */
98
+ const chunks = [];
99
+ let size = 0;
100
+ for await (const chunk of stream) {
101
+ const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
102
+ size += buf.length;
103
+ if (size > MAX_STDIN_BYTES) return null;
104
+ chunks.push(buf);
105
+ }
106
+ return Buffer.concat(chunks).toString("utf8");
107
+ }
108
+
109
+ function itemLine(item) {
110
+ const attention = item.attention === "action_required" ? "action required" : item.attention;
111
+ return `${clean(item.itemId)} ${clean(attention)} ${clean(item.state)} ${clean(item.updatedAt)} ${clean(item.summary)}`;
112
+ }
113
+
114
+ function printItem(item) {
115
+ console.log(`${itemLine(item)}${item.snoozedUntil ? ` (snoozed until ${clean(item.snoozedUntil)})` : ""}`);
116
+ }
117
+
118
+ function usageError(message, next) {
119
+ console.error(fail(message, next));
120
+ return 2;
121
+ }
122
+
123
+ function needItem(args) {
124
+ const id = args.positional[1];
125
+ if (!id) return { error: usageError("an inbox item id is required.", "e.g. tot inbox read fb:fb-123") };
126
+ if (!ITEM_ID.test(id)) return { error: usageError("that is not an inbox item id.", "copy one from `tot inbox`.") };
127
+ return { id };
128
+ }
129
+
130
+ /**
131
+ * @param {string[]} argv
132
+ * @param {{ createClient?: typeof createMcpClient, establishSession?: typeof establishSession,
133
+ * stdin?: NodeJS.ReadableStream, now?: number }} [deps] Test seam; production passes only argv.
134
+ */
135
+ export async function run(argv, deps = {}) {
136
+ const args = parseArgs(argv);
137
+ if (args.help) {
138
+ console.log(USAGE);
139
+ return 0;
140
+ }
141
+ if (args.missing) return usageError(`${args.missing} needs a value.`);
142
+ if (args.unknown) return usageError(`unknown option ${args.unknown}.`, "see `tot inbox --help`.");
143
+
144
+ const verb = args.positional[0] ?? "list";
145
+ if (!["list", "read", "ack", "done", "snooze", "reply", "threshold"].includes(verb)) {
146
+ return usageError(`unknown inbox command "${clean(verb).slice(0, 40)}".`, "see `tot inbox --help`.");
147
+ }
148
+
149
+ // Validate everything that needs no server before any request or sign-in.
150
+ /** @type {string|undefined} */
151
+ let id;
152
+ if (verb === "read" || verb === "ack" || verb === "done" || verb === "snooze" || verb === "reply") {
153
+ const need = needItem(args);
154
+ if (need.error !== undefined) return need.error;
155
+ id = need.id;
156
+ }
157
+ const listArgs = {};
158
+ if (verb === "list") {
159
+ if (args.state) {
160
+ if (!STATES.includes(args.state)) return usageError(`--state must be one of: ${STATES.join(", ")}.`);
161
+ listArgs.state = args.state;
162
+ }
163
+ if (args.min) {
164
+ if (!INBOX_ATTENTIONS.includes(args.min)) return usageError(`--min must be one of: ${INBOX_ATTENTIONS.join(", ")}.`);
165
+ listArgs.minAttention = args.min;
166
+ }
167
+ if (args.limit !== null) {
168
+ const n = Number(args.limit);
169
+ if (!Number.isInteger(n) || n < 1 || n > 100) return usageError("--limit must be a whole number from 1 to 100.");
170
+ listArgs.limit = n;
171
+ }
172
+ if (args.cursor) listArgs.cursor = args.cursor;
173
+ if (args.all) listArgs.includeSuppressed = true;
174
+ }
175
+ let until;
176
+ if (verb === "snooze") {
177
+ if (!args.until) return usageError("--until is required.", "e.g. tot inbox snooze fb:fb-123 --until 2h");
178
+ until = resolveSnoozeUntil(args.until, deps.now);
179
+ if (!until) return usageError("--until must be an ISO-8601 time or 30m / 2h / 1d.");
180
+ if (Date.parse(until) <= (deps.now ?? Date.now())) return usageError("--until must be in the future.");
181
+ }
182
+ let threshold;
183
+ if (verb === "threshold" && args.positional[1] !== undefined) {
184
+ threshold = args.positional[1];
185
+ if (!INBOX_ATTENTIONS.includes(threshold)) {
186
+ return usageError(`threshold must be one of: ${INBOX_ATTENTIONS.join(", ")}.`);
187
+ }
188
+ }
189
+ let body;
190
+ let requestId;
191
+ if (verb === "reply") {
192
+ requestId = args.requestId || randomUUID();
193
+ if (!REQUEST_ID.test(requestId)) return usageError("--request-id must be 8-96 letters, digits, . _ or -.");
194
+ const stdin = deps.stdin ?? process.stdin;
195
+ if (!deps.stdin && process.stdin.isTTY) {
196
+ return usageError("the reply text comes from stdin.", 'e.g. echo "thanks" | tot inbox reply fb:fb-123');
197
+ }
198
+ const text = await readStdin(stdin);
199
+ if (text === null) return usageError("the reply is too large.", `keep it under ${MAX_REPLY} characters.`);
200
+ body = text.replace(/\r\n/g, "\n").replace(/\n+$/, "");
201
+ if (!body.trim()) return usageError("the reply is empty.", "pipe the text in on stdin.");
202
+ if (body.length > MAX_REPLY) return usageError(`the reply is ${body.length} characters.`, `keep it under ${MAX_REPLY}.`);
203
+ }
204
+
205
+ const env = process.env;
206
+ const creds = readSessionCredentials(env);
207
+ const mcpUrl = args.mcp || creds?.mcpUrl || env.MCP_BASE_URL || env.TOT_MCP_URL || DEFAULT_MCP_URL;
208
+ const client = (deps.createClient || createMcpClient)(mcpUrl);
209
+
210
+ try {
211
+ await (deps.establishSession || establishSession)(client, { env });
212
+ } catch (e) {
213
+ if (e instanceof AuthUnavailableError) {
214
+ console.error(fail(`can't open your inbox: ${e.message}`, e.hint || "run `tot login` first."));
215
+ return 1;
216
+ }
217
+ throw e;
218
+ }
219
+
220
+ const print = (value) => console.log(JSON.stringify(value, null, 2));
221
+ try {
222
+ if (verb === "list") {
223
+ const r = await client.callTool("inbox_list", listArgs);
224
+ if (args.json) { print(r); return 0; }
225
+ const items = Array.isArray(r?.items) ? r.items : [];
226
+ if (!items.length) console.log("No mail.");
227
+ for (const item of items) printItem(item);
228
+ if (r?.nextCursor) console.log(`more: tot inbox list --cursor ${clean(r.nextCursor)}`);
229
+ return 0;
230
+ }
231
+ if (verb === "read") {
232
+ const r = await client.callTool("inbox_get", { itemId: id });
233
+ if (args.json) { print(r); return 0; }
234
+ printItem(r.item ?? {});
235
+ for (const m of Array.isArray(r.thread) ? r.thread : []) {
236
+ console.log(`\n[${clean(m.createdAt)}] ${clean(m.authorRole)}:\n${clean(m.body)}`);
237
+ }
238
+ if (Array.isArray(r.actions) && r.actions.some((x) => x?.tool === REPLY_TOOL)) {
239
+ console.log(`\nreply: echo "<text>" | tot inbox reply ${id}`);
240
+ }
241
+ return 0;
242
+ }
243
+ if (verb === "ack" || verb === "done" || verb === "snooze") {
244
+ const r = verb === "ack" ? await client.callTool("inbox_ack", { itemId: id })
245
+ : verb === "done" ? await client.callTool("inbox_done", { itemId: id })
246
+ : await client.callTool("inbox_snooze", { itemId: id, until });
247
+ if (args.json) { print(r); return 0; }
248
+ console.log(`+ ${verb === "ack" ? "acknowledged" : verb === "done" ? "done" : "snoozed"}`);
249
+ if (r?.item) printItem(r.item);
250
+ return 0;
251
+ }
252
+ if (verb === "reply") {
253
+ const got = await client.callTool("inbox_get", { itemId: id });
254
+ const action = Array.isArray(got?.actions) ? got.actions.find((x) => x?.tool === REPLY_TOOL) : null;
255
+ const feedbackId = action?.arguments?.feedbackId;
256
+ if (!action || typeof feedbackId !== "string" || !feedbackId) {
257
+ console.error(fail("this item does not take a reply.", "`tot inbox read` shows what you can do with it."));
258
+ return 1;
259
+ }
260
+ const r = await client.callTool("feedback_reply", { feedbackId, requestId, body });
261
+ if (args.json) { print(r); return 0; }
262
+ console.log(r?.status === "duplicate" ? "+ already sent" : "+ sent");
263
+ return 0;
264
+ }
265
+ // threshold
266
+ const r = threshold === undefined
267
+ ? await client.callTool("inbox_preference_get", {})
268
+ : await client.callTool("inbox_preference_set", { threshold });
269
+ if (args.json) { print(r); return 0; }
270
+ console.log(`threshold: ${clean(r?.threshold)}`);
271
+ return 0;
272
+ } catch (e) {
273
+ recordDiagnostic(e, { command: "inbox", operation: `inbox ${verb}`, required: true }, env);
274
+ const status = e?.diagnostic?.serverStatus;
275
+ if (status === "not_found") {
276
+ console.error(fail("no such inbox item.", "list yours with `tot inbox`."));
277
+ } else if (status === "unauthenticated") {
278
+ console.error(fail("you are not signed in.", "run `tot login`."));
279
+ } else {
280
+ console.error(fail(`inbox ${verb} failed: ${clean(e?.message || e)}`));
281
+ }
282
+ return 1;
283
+ }
284
+ }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * The inbox indicator — the one bounded block the MCP appends to an ordinary
3
+ * successful tool result when the signed-in person has mail waiting:
4
+ *
5
+ * { type: "text", text: '{"inbox":{"waiting":2,"highest":"update","hint":"inbox_list"}}' }
6
+ *
7
+ * `mcp.mjs` removes it from every result BEFORE the result is parsed, so no caller
8
+ * ever sees it, and records only the count and the highest attention here. The
9
+ * top-level `finally` in bin/tot.mjs prints at most one mailbox line from that
10
+ * record. It never makes a request, and the line carries no title, body or
11
+ * identity — only a count and an attention level.
12
+ */
13
+
14
+ export const INBOX_ATTENTIONS = ["fyi", "update", "action_required"];
15
+ const MAX_WAITING = 99;
16
+
17
+ /** @type {{ waiting: number, atLeast: boolean, highest: string } | null} */
18
+ let signal = null;
19
+
20
+ /**
21
+ * The parsed indicator when `block` is the synthetic inbox block, else null.
22
+ * @param {any} block
23
+ * @returns {{ waiting: number, atLeast: boolean, highest: string } | null}
24
+ */
25
+ export function parseIndicatorBlock(block) {
26
+ if (block?.type !== "text" || typeof block.text !== "string" || !block.text.startsWith('{"inbox":')) {
27
+ return null;
28
+ }
29
+ let inbox;
30
+ try {
31
+ inbox = JSON.parse(block.text)?.inbox;
32
+ } catch (err) {
33
+ if (err instanceof SyntaxError) return null;
34
+ throw err;
35
+ }
36
+ if (inbox?.hint !== "inbox_list") return null;
37
+ const waiting = inbox.waiting;
38
+ if (!Number.isInteger(waiting) || waiting < 1 || waiting > MAX_WAITING) return null;
39
+ if (!INBOX_ATTENTIONS.includes(inbox.highest)) return null;
40
+ return { waiting, atLeast: inbox.atLeast === true, highest: inbox.highest };
41
+ }
42
+
43
+ /**
44
+ * Split the indicator out of a tool result's `content`. Returns the result to
45
+ * parse (a shallow copy without the block, or the original when it has none) and
46
+ * the indicator found. The original object is never mutated.
47
+ * @param {any} result
48
+ * @returns {{ result: any, indicator: ReturnType<typeof parseIndicatorBlock> }}
49
+ */
50
+ export function stripIndicator(result) {
51
+ if (!result || typeof result !== "object" || !Array.isArray(result.content)) {
52
+ return { result, indicator: null };
53
+ }
54
+ let indicator = null;
55
+ const content = result.content.filter((block) => {
56
+ const parsed = parseIndicatorBlock(block);
57
+ if (!parsed) return true;
58
+ indicator ??= parsed;
59
+ return false;
60
+ });
61
+ if (content.length === result.content.length) return { result, indicator: null };
62
+ return { result: { ...result, content }, indicator };
63
+ }
64
+
65
+ /**
66
+ * Keep the highest attention seen this command; among equals, the newest signal.
67
+ * @param {NonNullable<ReturnType<typeof parseIndicatorBlock>>} next
68
+ */
69
+ export function noteIndicator(next) {
70
+ if (!signal || INBOX_ATTENTIONS.indexOf(next.highest) >= INBOX_ATTENTIONS.indexOf(signal.highest)) {
71
+ signal = { ...next };
72
+ }
73
+ }
74
+
75
+ export function currentIndicator() {
76
+ return signal ? { ...signal } : null;
77
+ }
78
+
79
+ export function resetIndicator() {
80
+ signal = null;
81
+ }
82
+
83
+ /**
84
+ * The one Unix-mailbox-style line. Count and attention only.
85
+ * @param {NonNullable<ReturnType<typeof currentIndicator>>} s
86
+ */
87
+ export function formatMailLine(s) {
88
+ const count = `${s.waiting}${s.atLeast ? "+" : ""}`;
89
+ const level = s.highest === "action_required" ? "action required" : s.highest;
90
+ return `You have mail (${count} waiting, ${level}) — run \`tot inbox\``;
91
+ }
92
+
93
+ const MACHINE_FLAGS = new Set(["--json", "--machine", "--porcelain", "--quiet", "-q"]);
94
+
95
+ /**
96
+ * Whether the mailbox line may print for this invocation: never on an inbox
97
+ * command, never in a machine or JSON mode, and never when TOT_NO_MAIL_LINE is set.
98
+ * @param {string|undefined} cmd @param {string[]} rest @param {NodeJS.ProcessEnv} [env]
99
+ */
100
+ export function mailLineAllowed(cmd, rest, env = process.env) {
101
+ if (cmd === "inbox") return false;
102
+ if (env.TOT_NO_MAIL_LINE) return false;
103
+ return !rest.some(
104
+ (t) => MACHINE_FLAGS.has(t) || /^--(?:format|output)(?:=|$)/.test(t) && /json/i.test(t.split("=")[1] ?? rest[rest.indexOf(t) + 1] ?? ""),
105
+ );
106
+ }
107
+
108
+ /**
109
+ * Print the line to stderr once, if there is mail and printing is allowed.
110
+ * @param {string|undefined} cmd @param {string[]} rest
111
+ * @param {{ env?: NodeJS.ProcessEnv, write?: (s: string) => void }} [opts]
112
+ */
113
+ export function printMailLine(cmd, rest, { env = process.env, write = (s) => process.stderr.write(s) } = {}) {
114
+ const s = currentIndicator();
115
+ if (!s || !mailLineAllowed(cmd, rest, env)) return false;
116
+ write(`${formatMailLine(s)}\n`);
117
+ return true;
118
+ }
package/src/mcp.mjs CHANGED
@@ -11,6 +11,7 @@ import { readFileSync } from "node:fs";
11
11
  import { randomUUID } from "node:crypto";
12
12
  import os from "node:os";
13
13
  import { CliDiagnosticError, recordDiagnostic, sanitizeDiagnosticText } from "./diagnostics.mjs";
14
+ import { noteIndicator, stripIndicator } from "./inbox-indicator.mjs";
14
15
 
15
16
  // A server's refusal is written for the person reading it and usually ends with what to do,
16
17
  // so it is shown whole. The cap only bounds a runaway body; sanitizing still applies.
@@ -309,6 +310,13 @@ export function createMcpClient(baseUrl, opts = {}) {
309
310
  if (error?.diagnostic) error.diagnostic.operation = name;
310
311
  throw error;
311
312
  }
313
+ // The server appends one bounded inbox block to ordinary successful results. Take it out
314
+ // before anything parses the result, and keep only its count and attention for the mailbox line.
315
+ if (!r?.isError) {
316
+ const split = stripIndicator(r);
317
+ if (split.indicator) noteIndicator(split.indicator);
318
+ r = split.result;
319
+ }
312
320
  if (r?.isError) {
313
321
  const tb = Array.isArray(r?.content)
314
322
  ? r.content.find((c) => c?.type === "text")
@@ -71,6 +71,14 @@ export const TENANT_NEUTRAL_TOOLS = Object.freeze(new Set([
71
71
  "dev_renderer_artifact",
72
72
  "dev_image_pull_token",
73
73
  "feedback_submit",
74
+ "feedback_reply",
75
+ "inbox_list",
76
+ "inbox_get",
77
+ "inbox_ack",
78
+ "inbox_done",
79
+ "inbox_snooze",
80
+ "inbox_preference_get",
81
+ "inbox_preference_set",
74
82
  "repo_read_credential",
75
83
  ]));
76
84
 
@@ -125,6 +125,21 @@ the preview stage without waiting on the store owner:
125
125
  RFC-reserved recipient fixtures. Preview tokens and webhooks are isolated by the stage wall
126
126
  (`403 stage_mismatch` if used against live publication hosts).
127
127
 
128
+ ### Calling the API in test
129
+
130
+ A `test` install calls its store's preview stage at `https://storefront.tokenoftrust.store/<tenant>`.
131
+ No preview token is needed: your app's own credential selects the test stage, and it acts only on
132
+ preview data. No `Origin` header is needed; server-to-server is fine. Production installs call the
133
+ store's own live domain, never the shared host. A request with no credential gets 401
134
+ `store-not-public`.
135
+
136
+ ```bash
137
+ curl -s -X POST https://storefront.tokenoftrust.store/<tenant>/api/apps/oauth/token \
138
+ -d grant_type=client_credentials -d client_id=<clientId> -d client_secret=<clientSecret>
139
+ curl -s https://storefront.tokenoftrust.store/<tenant>/api/apps/v1/<path> \
140
+ -H "Authorization: Bearer <access_token>"
141
+ ```
142
+
128
143
  ## Going live (`private_key_jwt` candidate staging & 1-click Owner approval)
129
144
 
130
145
  1. Point `webhooks.endpoint` at your real, publicly reachable HTTPS receiver and swap the dev-only