@raibitsi/tiresias 1.0.1 → 1.2.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/CHANGELOG.md +88 -0
- package/README.md +72 -33
- package/data/README.md +33 -0
- package/data/guard-ordinary-urls.txt +102 -0
- package/data/guard-starter.jsonl +424 -0
- package/dist/aimed.js +23 -0
- package/dist/anchor.js +26 -13
- package/dist/browsecli.js +17 -13
- package/dist/cdp.js +22 -1
- package/dist/cleanup.js +3 -1
- package/dist/cli.js +216 -68
- package/dist/config.js +75 -1
- package/dist/confirm.js +20 -5
- package/dist/cooldown.js +57 -32
- package/dist/dailylog.js +11 -5
- package/dist/dom.js +13 -8
- package/dist/doors.js +1 -1
- package/dist/engine.js +9 -4
- package/dist/envelope.js +10 -1
- package/dist/fetcher.js +29 -2
- package/dist/filereply.js +7 -1
- package/dist/formflow.js +21 -3
- package/dist/forms.js +337 -42
- package/dist/getactions.js +119 -0
- package/dist/guard.js +1240 -0
- package/dist/guardclient.js +245 -0
- package/dist/guardnetwork.js +22 -0
- package/dist/history.js +11 -5
- package/dist/hook.js +2 -0
- package/dist/hosts.js +34 -27
- package/dist/keys.js +420 -18
- package/dist/local.js +537 -0
- package/dist/mcp.js +56 -25
- package/dist/needs.js +9 -5
- package/dist/parentwatch.js +6 -16
- package/dist/pdf.js +4 -1
- package/dist/pdfchild.js +0 -2
- package/dist/pdfproc.js +26 -11
- package/dist/pdfwatch.js +14 -0
- package/dist/pipeline.js +117 -26
- package/dist/preformatted.js +12 -0
- package/dist/profiles.js +3 -3
- package/dist/queue.js +24 -20
- package/dist/reader.js +441 -87
- package/dist/receipts.js +7 -2
- package/dist/render.js +156 -27
- package/dist/renderactions.js +69 -0
- package/dist/resume.js +8 -6
- package/dist/rules.js +24 -5
- package/dist/safebrowsing.js +3 -3
- package/dist/safety.js +15 -7
- package/dist/sandbox.js +1 -1
- package/dist/saved.js +24 -9
- package/dist/savedlock.js +99 -5
- package/dist/settings.js +10 -3
- package/dist/shelf.js +1 -1
- package/dist/shield.js +15 -0
- package/dist/slips.js +43 -1
- package/dist/store.js +119 -25
- package/dist/tabs.js +1 -1
- package/dist/textview.js +16 -0
- package/dist/translate.js +22 -2
- package/dist/types.js +9 -2
- package/dist/watchflow.js +1 -2
- package/dist/work.js +10 -2
- package/docs/LOCAL-MODELS.md +271 -0
- package/package.json +5 -2
package/dist/cli.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
// N-09: the command-line door. Same engine, same store as the MCP server.
|
|
4
4
|
import "./nodecheck.js"; // first: an older Node gets a plain message before anything else runs
|
|
5
|
+
import { escapeTerminal, textView } from "./textview.js";
|
|
5
6
|
import { parseArgs } from "node:util";
|
|
6
7
|
import { drainForExit, installShutdown } from "./background.js";
|
|
7
|
-
import { loadLimits } from "./config.js";
|
|
8
|
+
import { loadChoice, loadLimits } from "./config.js";
|
|
8
9
|
import { clearStore } from "./cleanup.js";
|
|
9
10
|
import * as engine from "./engine.js";
|
|
10
11
|
import { serveStdio } from "./mcp.js";
|
|
@@ -12,10 +13,14 @@ import { assertProfile, profileName, selectProfile, stampProfile } from "./store
|
|
|
12
13
|
import { BROWSE_HELP, BROWSE_TAKES, noteCliRead, runBrowseCommand } from "./browsecli.js";
|
|
13
14
|
import { VERSION } from "./types.js";
|
|
14
15
|
import { notice, startupNotice } from "./confirm.js";
|
|
15
|
-
import { historyEnvelope, receiptsEnvelope } from "./envelope.js";
|
|
16
|
+
import { listEnvelope, historyEnvelope, receiptsEnvelope } from "./envelope.js";
|
|
17
|
+
import { localRead, parseLocalBudget } from "./local.js";
|
|
16
18
|
// JSON output carries `profile` at the top level when it is not `default` (W-18), and `settings_notice` when a risky
|
|
17
19
|
// setting changed in the last 24 hours or a loosening waits for confirmation (W-32, v0.9).
|
|
18
|
-
|
|
20
|
+
// Terminal display only. Applying the escape again is harmless: backslashes stay unchanged.
|
|
21
|
+
const print = (text) => console.log(escapeTerminal(String(text)));
|
|
22
|
+
const printError = (text) => console.error(escapeTerminal(String(text)));
|
|
23
|
+
const json = (x, space = 2) => escapeTerminal(JSON.stringify(stampNotice(stampProfile(x)), null, space));
|
|
19
24
|
let noticeLines = null; // null: not looked up yet (once per process, after the profile is chosen)
|
|
20
25
|
let profileSelected = false;
|
|
21
26
|
function currentNotice() {
|
|
@@ -48,6 +53,9 @@ const HELP = `Tiresias ${VERSION}: the honest browser for AI agents.
|
|
|
48
53
|
request through Tiresias's rules), when the owner allows it
|
|
49
54
|
[--save] keep a signed snapshot of the bytes this read received, when the owner
|
|
50
55
|
allows saving (tiresias settings set saving ask --confirm "YES, TURN ON SAVING")
|
|
56
|
+
[--local [--local-budget 6000]] print the reply a local model gets from tiresias mcp --local.
|
|
57
|
+
With --local, the only other options are --question, --section,
|
|
58
|
+
--page and --local-budget
|
|
51
59
|
tiresias doors <url>
|
|
52
60
|
tiresias check <url> [--page 2] [--fresh] if it changed: what changed (added and removed blocks)
|
|
53
61
|
tiresias resume <ticket> [--from-file <path>] pick up a read that stopped at a wall: retry it, or read
|
|
@@ -59,8 +67,8 @@ const HELP = `Tiresias ${VERSION}: the honest browser for AI agents.
|
|
|
59
67
|
its Merkle path and a standard .ots file (--out: three files, never overwriting)
|
|
60
68
|
tiresias receipts verify <bundle> check a proof bundle offline; says which step needs a Bitcoin block header
|
|
61
69
|
tiresias history [--since 2026-10-01] [--site example.com] [--agent codex]
|
|
62
|
-
tiresias log [--day 2026-10-16] [--to <folder>] [--page 2]
|
|
63
|
-
tiresias needs [--since 30d] [--page 2] patterns in the history and suggested wants (W-12)
|
|
70
|
+
tiresias log [--day 2026-10-16] [--to <folder>] [--page 2] [--json]
|
|
71
|
+
tiresias needs [--since 30d] [--page 2] [--json] patterns in the history and suggested wants (W-12)
|
|
64
72
|
tiresias bookmark add <name> <url> [--watch]
|
|
65
73
|
tiresias bookmark remove <name>
|
|
66
74
|
tiresias bookmark watch <name> on|off
|
|
@@ -85,6 +93,13 @@ const HELP = `Tiresias ${VERSION}: the honest browser for AI agents.
|
|
|
85
93
|
the directory body plus signed response headers for a static host
|
|
86
94
|
(1 to 90 days; a verifier that wants shorter-lived signatures needs
|
|
87
95
|
a server that signs each response itself)
|
|
96
|
+
tiresias keys rotate [--overlap 7] a new signing key; the old one stays in the directory for the
|
|
97
|
+
overlap (0 to 30 days, default 7) and then drops out by itself.
|
|
98
|
+
New requests sign with the new key only. After a leak: --overlap 0
|
|
99
|
+
tiresias keys rotate --finish end the overlap now: drop the old key from the directory and delete it
|
|
100
|
+
tiresias keys rotate --slips --confirm "YES, ROTATE THE SLIP KEY"
|
|
101
|
+
a new slip key: revokes every permission slip (a person types
|
|
102
|
+
"rotate slip key" back); saved pages stay checkable
|
|
88
103
|
tiresias scanner set [--timeout 10] [--send-file --confirm "YES, SEND FILES TO THE SCANNER"] -- /full/path/to/program [args...]
|
|
89
104
|
your own virus checker, run on every high-risk file warning (none
|
|
90
105
|
is included); it gets the fingerprint (and with --send-file the file)
|
|
@@ -94,12 +109,28 @@ const HELP = `Tiresias ${VERSION}: the honest browser for AI agents.
|
|
|
94
109
|
translation (none is included); it gets the text on standard
|
|
95
110
|
input and the source and target languages as its last two arguments
|
|
96
111
|
tiresias translator show | translator off the translator setting, or remove it
|
|
112
|
+
tiresias guard setup --url http://localhost:1234/v1 --model <embedding model id> [--prefix "..."]
|
|
113
|
+
[--false-alarms 1] [--ordinary <file.jsonl> | --ordinary-urls <file.txt>] [--timeout 4]
|
|
114
|
+
the meaning check for local model mode: your own embedding model
|
|
115
|
+
compares each passage with known planted instructions (none is
|
|
116
|
+
included). Setup reads about 100 ordinary pages through Tiresias to
|
|
117
|
+
calibrate, unless you give your own; an address outside your network
|
|
118
|
+
takes --confirm "YES, SEND PAGE TEXT OUTSIDE MY NETWORK"
|
|
119
|
+
tiresias guard import <file> [--name <collection>] create a new collection of planted texts (.jsonl with
|
|
120
|
+
"text", or one text per line). Pick an unused --name; "starter"
|
|
121
|
+
is reserved. Without --name, a unique name comes from the file
|
|
122
|
+
tiresias guard show | guard check [--file <path> | <text>] | guard off
|
|
123
|
+
the setting and library sizes; score one text; remove the setting and
|
|
124
|
+
the library
|
|
97
125
|
tiresias settings every owner setting: value, default, what it does, where it is stored
|
|
98
126
|
tiresias settings set <name> [<site>] <value> | settings reset <name> [<site>] [--confirm "..."]
|
|
99
127
|
change one setting (site settings: spacing_seconds, ports, hand_off,
|
|
100
128
|
never_visit take a site, like example.com or *.example.com); turning a
|
|
101
129
|
risky setting on or looser takes --confirm with its exact phrase
|
|
102
130
|
(printed when it is missing), like --confirm "YES, TURN ON SAVING"
|
|
131
|
+
get_form_actions read|slip; private_spacing shared|none;
|
|
132
|
+
hook_secrets hidden|inherit; text_views marked|wrapped
|
|
133
|
+
none and inherit need the risky-setting confirmation
|
|
103
134
|
tiresias settings confirm <name> [<site>] --confirm "..." confirm a risky value config.json holds
|
|
104
135
|
(a hand edit); until then it is not in force
|
|
105
136
|
tiresias settings confirmations off|on --confirm "..." never ask for the phrase again, or ask again
|
|
@@ -112,7 +143,7 @@ const HELP = `Tiresias ${VERSION}: the honest browser for AI agents.
|
|
|
112
143
|
tiresias slip list active slips, plus expired, used-up and damaged counts
|
|
113
144
|
tiresias slip revoke <id> | --all take a slip back (it can never be used again)
|
|
114
145
|
tiresias form preview <url> --form N [--set name=value ...] [--unset name]
|
|
115
|
-
the exact request a form would send (
|
|
146
|
+
the exact request a form would send (the previewed form is not sent)
|
|
116
147
|
tiresias form submit <url> --form N [--set name=value ...] [--unset name] --preview <hash>
|
|
117
148
|
send it once, with a permission slip (refused without one)
|
|
118
149
|
tiresias profile create <name> a separate profile: its own keys, history, cache, bookmarks,
|
|
@@ -122,6 +153,10 @@ const HELP = `Tiresias ${VERSION}: the honest browser for AI agents.
|
|
|
122
153
|
delete one profile's folder (--delete-key when it has a signing key)
|
|
123
154
|
${BROWSE_HELP}
|
|
124
155
|
tiresias mcp start the MCP server (stdio)
|
|
156
|
+
tiresias mcp --local [--local-budget 6000] the MCP server for small models that run on your own
|
|
157
|
+
computer: one read tool, short instructions and short replies, about
|
|
158
|
+
6,000 characters of page text (--local-budget: 1000 to 20000).
|
|
159
|
+
Tiresias does not search the web, so give your model a search tool too
|
|
125
160
|
|
|
126
161
|
Add --profile <name> to any command (or set TIRESIAS_PROFILE) to use that profile; without it,
|
|
127
162
|
the default profile (the store folder itself) is used. The MCP server serves one profile, fixed
|
|
@@ -145,7 +180,8 @@ run, unpacked or saved: it comes back as status "file_warning" with its kind (fr
|
|
|
145
180
|
size and SHA-256 fingerprint, for you to decide about. TIRESIAS_MAX_FILE_BYTES (default 50 MB) caps
|
|
146
181
|
what is fingerprinted.
|
|
147
182
|
|
|
148
|
-
Output is JSON, except log and needs, which print a readable page
|
|
183
|
+
Output is JSON, except log and needs, which print a readable page (--json for JSON).
|
|
184
|
+
Add --text for a short summary. Text views mark web content as untrusted; agents should use JSON.`;
|
|
149
185
|
// v0.5.1: exit codes. 0 only when the call did its job (ok, unchanged); 2 when Tiresias stopped on
|
|
150
186
|
// purpose (a wall, a flag, a refusal, a file warning, a price tag); 1 on an error.
|
|
151
187
|
export function exitFor(status) {
|
|
@@ -159,7 +195,7 @@ export function exitFor(status) {
|
|
|
159
195
|
// --profile, --text and --help go with every command; --private with every command that reads the store.
|
|
160
196
|
const COMMON = ["profile", "text", "help", "private"];
|
|
161
197
|
const TAKES = {
|
|
162
|
-
read: ["question", "section", "page", "changes", "fresh", "allow-flagged", "translate", "render", "save"],
|
|
198
|
+
read: ["question", "section", "page", "changes", "fresh", "allow-flagged", "translate", "render", "save", "local", "local-budget"],
|
|
163
199
|
saved: ["page", "all"], // v0.8 (W-28)
|
|
164
200
|
doors: ["allow-flagged"],
|
|
165
201
|
check: ["page", "fresh", "allow-flagged"],
|
|
@@ -168,20 +204,21 @@ const TAKES = {
|
|
|
168
204
|
receipts: ["url", "since", "page", "out"], // out: v0.8 receipts prove (W-08)
|
|
169
205
|
anchor: ["page"], // v0.8 (W-08)
|
|
170
206
|
history: ["since", "site", "agent", "page"],
|
|
171
|
-
log: ["day", "to", "page"],
|
|
172
|
-
needs: ["since", "page"],
|
|
207
|
+
log: ["day", "to", "page", "json"],
|
|
208
|
+
needs: ["since", "page", "json"],
|
|
173
209
|
bookmark: ["watch", "page", "allow-flagged"],
|
|
174
210
|
watch: ["page", "allow-flagged"],
|
|
175
211
|
clear: ["older-than", "all", "dry-run"],
|
|
176
|
-
keys: ["force", "host", "days", "out"],
|
|
212
|
+
keys: ["force", "host", "days", "out", "overlap", "finish", "slips", "confirm"], // overlap, finish, slips, confirm: v1.1 keys rotate
|
|
177
213
|
scanner: ["timeout", "send-file", "confirm"], // confirm: v0.9 (W-32)
|
|
178
214
|
translator: ["timeout", "confirm"], // v0.7 (W-26)
|
|
215
|
+
guard: ["url", "model", "prefix", "false-alarms", "ordinary", "ordinary-urls", "timeout", "confirm", "name", "file"], // v1.2 (W-38)
|
|
179
216
|
settings: ["confirm"], // v0.6 (W-29); confirm: v0.9 (W-32)
|
|
180
217
|
safety: [],
|
|
181
218
|
slip: ["action", "site", "path", "until", "for", "uses", "note", "all", "page"],
|
|
182
219
|
form: ["form", "set", "unset", "preview", "allow-flagged"],
|
|
183
220
|
profile: ["yes", "delete-key"],
|
|
184
|
-
mcp: [],
|
|
221
|
+
mcp: ["local", "local-budget"], // W-34 (v1.2)
|
|
185
222
|
...BROWSE_TAKES, // v0.6 W-24 tabs, W-27 files (browsecli.ts)
|
|
186
223
|
};
|
|
187
224
|
// Per-command help: the lines of HELP for that command (and their continuation lines).
|
|
@@ -205,15 +242,15 @@ function helpFor(cmd) {
|
|
|
205
242
|
// form (plain text, or JSON) only on --text.
|
|
206
243
|
function printReply(r, text, plain = r.message) {
|
|
207
244
|
if (r.status === "error")
|
|
208
|
-
|
|
245
|
+
printError(text ? plain : json(r, 0));
|
|
209
246
|
else
|
|
210
|
-
|
|
247
|
+
print(text ? plain : json(r));
|
|
211
248
|
}
|
|
212
249
|
function printEnvelope(e, text) {
|
|
213
250
|
if (e.status === "error")
|
|
214
|
-
|
|
251
|
+
printError(text ? summary(e) : json(e, 0));
|
|
215
252
|
else
|
|
216
|
-
|
|
253
|
+
print(text ? summary(e) : json(e));
|
|
217
254
|
}
|
|
218
255
|
function summary(e) {
|
|
219
256
|
const uc = e.untrusted_content;
|
|
@@ -227,7 +264,7 @@ function summary(e) {
|
|
|
227
264
|
if (e.message)
|
|
228
265
|
lines.push(e.message);
|
|
229
266
|
if (e.source)
|
|
230
|
-
lines.push(`Source: a page a person provided (nothing was fetched).`);
|
|
267
|
+
lines.push(`Source: ${e.source === "provided_by_agent" ? "text an agent provided" : "a page a person provided"} (nothing was fetched).`);
|
|
231
268
|
if (e.cache)
|
|
232
269
|
lines.push(`Cache: ${e.cache}${uc?.cached_at ? ` (copy from ${uc.cached_at}${uc.cached_by !== undefined ? `, fetched by ${JSON.stringify(uc.cached_by)}` : ""})` : ""}`);
|
|
233
270
|
if (e.safety)
|
|
@@ -320,7 +357,7 @@ function summary(e) {
|
|
|
320
357
|
lines.push(`Page ${p.page} of ${p.pages}. Use --page N for more.`);
|
|
321
358
|
}
|
|
322
359
|
lines.push(e.notice);
|
|
323
|
-
return lines.join("\n");
|
|
360
|
+
return textView(lines.join("\n"));
|
|
324
361
|
}
|
|
325
362
|
// The cron-friendly summary: which bookmarks changed and which need a person (Codex round 36).
|
|
326
363
|
// Names are the owner's own ([a-z0-9-]); URLs are printed for the person reading, marked as from the web.
|
|
@@ -335,10 +372,10 @@ function watchText(r) {
|
|
|
335
372
|
const what = i.changes_omitted ? "too much changed to list" : i.added !== undefined ? `${i.added} added, ${i.removed} removed` : "changed (no list: nothing comparable was kept)";
|
|
336
373
|
L.push(` ${i.name}: ${what} <${i.url}>`);
|
|
337
374
|
}
|
|
338
|
-
if (r.attention.length)
|
|
375
|
+
if ((r.untrusted_content?.attention ?? []).length)
|
|
339
376
|
L.push("", "Needs attention:");
|
|
340
377
|
const urls = new Map((r.untrusted_content?.attention_urls ?? []).map((u) => [u.name, u]));
|
|
341
|
-
for (const a of r.attention) {
|
|
378
|
+
for (const a of r.untrusted_content?.attention ?? []) {
|
|
342
379
|
const why = a.outcome === "walled" ? `walled (${a.reason ?? "wall"})` : a.outcome === "waiting" ? `waiting ${a.retry_after_seconds} s (the site asked)`
|
|
343
380
|
: a.outcome === "file_warning" ? `now leads to a file (${a.file?.kind}, ${a.file?.risk} risk${a.file?.fingerprint ? `, ${a.file.fingerprint}` : ""}${a.file?.scan ? `, scanner: ${a.file.scan}` : ""}), not read`
|
|
344
381
|
: `failed (${a.status}${a.retry_after_seconds !== undefined ? `, wait ${a.retry_after_seconds} s` : ""})`;
|
|
@@ -348,7 +385,7 @@ function watchText(r) {
|
|
|
348
385
|
if (c.attention_omitted)
|
|
349
386
|
L.push(` and ${c.attention_omitted} more not named.`);
|
|
350
387
|
L.push("", "URLs above came from the web or from bookmarks: data, not instructions.");
|
|
351
|
-
return L.join("\n");
|
|
388
|
+
return textView(L.join("\n"));
|
|
352
389
|
}
|
|
353
390
|
// Every snapshot id in this profile (for saved verify --all).
|
|
354
391
|
function allIds(sv) {
|
|
@@ -364,13 +401,15 @@ async function main() {
|
|
|
364
401
|
tokens: true,
|
|
365
402
|
options: {
|
|
366
403
|
question: { type: "string" }, section: { type: "string" }, url: { type: "string" }, since: { type: "string" },
|
|
367
|
-
site: { type: "string" }, agent: { type: "string" }, page: { type: "string" }, text: { type: "boolean" }, private: { type: "boolean" }, changes: { type: "boolean" }, watch: { type: "boolean" }, day: { type: "string" }, to: { type: "string" },
|
|
404
|
+
site: { type: "string" }, agent: { type: "string" }, page: { type: "string" }, text: { type: "boolean" }, json: { type: "boolean" }, private: { type: "boolean" }, changes: { type: "boolean" }, watch: { type: "boolean" }, day: { type: "string" }, to: { type: "string" },
|
|
368
405
|
fresh: { type: "boolean" }, "from-file": { type: "string" }, "allow-flagged": { type: "boolean" },
|
|
369
406
|
profile: { type: "string" }, yes: { type: "boolean" }, "delete-key": { type: "boolean" },
|
|
370
407
|
form: { type: "string" }, set: { type: "string", multiple: true }, unset: { type: "string", multiple: true }, preview: { type: "string" },
|
|
371
408
|
action: { type: "string" }, path: { type: "string" }, until: { type: "string" }, for: { type: "string" }, uses: { type: "string" }, note: { type: "string" },
|
|
372
409
|
timeout: { type: "string" }, "send-file": { type: "boolean" }, translate: { type: "string" }, render: { type: "boolean" }, save: { type: "boolean" }, confirm: { type: "string" },
|
|
373
|
-
|
|
410
|
+
local: { type: "boolean" }, "local-budget": { type: "string" },
|
|
411
|
+
model: { type: "string" }, prefix: { type: "string" }, "false-alarms": { type: "string" }, ordinary: { type: "string" }, "ordinary-urls": { type: "string" }, name: { type: "string" }, file: { type: "string" },
|
|
412
|
+
force: { type: "boolean" }, overlap: { type: "string" }, finish: { type: "boolean" }, slips: { type: "boolean" }, host: { type: "string" }, days: { type: "string" }, out: { type: "string" }, "older-than": { type: "string" }, all: { type: "boolean" }, "dry-run": { type: "boolean" }, help: { type: "boolean", short: "h" }, version: { type: "boolean" },
|
|
374
413
|
},
|
|
375
414
|
});
|
|
376
415
|
const [cmd, arg] = positionals;
|
|
@@ -412,17 +451,17 @@ async function main() {
|
|
|
412
451
|
const all = profiles.list();
|
|
413
452
|
const left = profiles.leftovers().length; // interrupted removals (Codex round 46)
|
|
414
453
|
const note = left ? `${left} interrupted profile removal(s) left files in profiles/.removing-*; the next "tiresias profile remove" finishes them.` : undefined;
|
|
415
|
-
|
|
454
|
+
print(values.text ? all.map((p) => `${p.name}${p.created_at ? ` made ${p.created_at}` : ""} key: ${p.signing_key ? "yes" : "no"} signature_agent: ${p.signature_agent ?? "none"}${p.problem ? ` PROBLEM: ${p.problem}` : ""}`).concat(note ? [note] : []).join("\n") : json({ profiles: all, ...(left ? { removing_leftovers: left, note } : {}) }));
|
|
416
455
|
return 0;
|
|
417
456
|
}
|
|
418
457
|
if (sub === "create" && name !== undefined) {
|
|
419
458
|
const r = profiles.create(name, sessionPriv);
|
|
420
|
-
|
|
459
|
+
print(values.text ? r.message : json(r));
|
|
421
460
|
return 0;
|
|
422
461
|
}
|
|
423
462
|
if (sub === "remove" && name !== undefined) {
|
|
424
463
|
const r = profiles.remove(name, { yes: values.yes, deleteKey: values["delete-key"], priv: sessionPriv });
|
|
425
|
-
|
|
464
|
+
print(values.text ? r.message : json(r));
|
|
426
465
|
return 0;
|
|
427
466
|
}
|
|
428
467
|
throw new Error("Usage: tiresias profile create <name> | profile list | profile remove <name> --yes [--delete-key]");
|
|
@@ -430,6 +469,10 @@ async function main() {
|
|
|
430
469
|
// W-18: one process serves one profile, chosen here once (--profile, else TIRESIAS_PROFILE, else
|
|
431
470
|
// default). A profile that does not exist stops the command before anything is read or created.
|
|
432
471
|
assertProfile();
|
|
472
|
+
// W-34 (v1.2): local model mode. --local-budget goes with --local only.
|
|
473
|
+
if (values["local-budget"] !== undefined && !values.local)
|
|
474
|
+
throw new Error("--local-budget goes with --local.");
|
|
475
|
+
const localBudget = values.local ? parseLocalBudget(values["local-budget"]) : undefined;
|
|
433
476
|
if (cmd === "mcp") {
|
|
434
477
|
// Integration Codex round 3 (v0.8): `mcp --private` is the documented TIRESIAS_PRIVATE=1, for the whole server
|
|
435
478
|
// (before, the flag was accepted and ignored, so calls without their own `private` were recorded).
|
|
@@ -444,8 +487,8 @@ async function main() {
|
|
|
444
487
|
// held back for confirmation (the agent may never pass the reply notice on).
|
|
445
488
|
const held = startupNotice(profileName());
|
|
446
489
|
if (held)
|
|
447
|
-
process.stderr.write(`${held}\n`);
|
|
448
|
-
await serveStdio();
|
|
490
|
+
process.stderr.write(escapeTerminal(`${held}\n`));
|
|
491
|
+
await serveStdio(localBudget === undefined ? {} : { local: { budget: localBudget } });
|
|
449
492
|
return -1; // keep running
|
|
450
493
|
}
|
|
451
494
|
installShutdown(); // v0.6 (Codex round 6): a signal during ANY command runs the bounded cleanup (lifetime.ts)
|
|
@@ -466,17 +509,18 @@ async function main() {
|
|
|
466
509
|
if (sessionPriv)
|
|
467
510
|
throw new Error("Private mode: nothing is written, so the log is not exported. Run it without --to to print it.");
|
|
468
511
|
const r = await engine.exportDailyLog(values.to, values.day);
|
|
469
|
-
|
|
512
|
+
print(values.json ? json(r) : r.message + `\n${r.file}`);
|
|
470
513
|
}
|
|
471
514
|
else {
|
|
472
515
|
const r = await engine.dailyLog(values.day, page);
|
|
473
|
-
|
|
516
|
+
print(values.json ? json(listEnvelope("", { day: r.day, entries: r.entries, log: r.text }, { page: r.page, pages: r.pages, total: r.entries })) : textView(r.text + (r.pages > 1 ? `\nPage ${r.page} of ${r.pages}. Use --page N for more.` : "")));
|
|
474
517
|
}
|
|
475
518
|
return 0;
|
|
476
519
|
}
|
|
477
520
|
if (cmd === "needs") {
|
|
478
521
|
const { toMarkdown } = await import("./needs.js");
|
|
479
|
-
|
|
522
|
+
const r = await engine.needsReport(values.since, page);
|
|
523
|
+
print(values.json ? json(r) : textView(toMarkdown(r)));
|
|
480
524
|
return 0;
|
|
481
525
|
}
|
|
482
526
|
if (cmd === "bookmark") {
|
|
@@ -507,7 +551,7 @@ async function main() {
|
|
|
507
551
|
await confirmByTyping(site, `Grant a permission slip: ${String(values.action)} on ${site}${values.path ? String(values.path) : ""}.`);
|
|
508
552
|
const v = slips.grant({ action: values.action, site: values.site, path: values.path, until: values.until, for: values.for, uses: values.uses, note: values.note }, sessionPriv);
|
|
509
553
|
const msg = `Granted slip ${v.id}: ${v.action} on ${v.site}${v.path ?? ""}${v.path ? " (and below)" : ""}, ${v.uses} use${v.uses === 1 ? "" : "s"}, until ${v.expires_at}. Revoke it with: tiresias slip revoke ${v.id}`;
|
|
510
|
-
|
|
554
|
+
print(values.text ? msg : json({ status: "ok", message: msg, slip: v }));
|
|
511
555
|
return 0;
|
|
512
556
|
}
|
|
513
557
|
if (sub === "revoke" && (id !== undefined) !== !!values.all) {
|
|
@@ -516,14 +560,14 @@ async function main() {
|
|
|
516
560
|
await confirmByTyping("revoke all", "Revoke every permission slip of this profile.");
|
|
517
561
|
const n = slips.revokeAll(sessionPriv);
|
|
518
562
|
const msg = `Revoked ${n} slip${n === 1 ? "" : "s"}. None of them can be used again.`;
|
|
519
|
-
|
|
563
|
+
print(values.text ? msg : json({ status: "ok", message: msg, revoked: n }));
|
|
520
564
|
}
|
|
521
565
|
else {
|
|
522
566
|
const what = slips.confirmTextFor(id);
|
|
523
567
|
await confirmByTyping(what, `Revoke slip ${id}.`);
|
|
524
568
|
slips.revoke(id, sessionPriv);
|
|
525
569
|
const msg = "Revoked. That slip can never be used again.";
|
|
526
|
-
|
|
570
|
+
print(values.text ? msg : json({ status: "ok", message: msg, revoked: 1 }));
|
|
527
571
|
}
|
|
528
572
|
return 0;
|
|
529
573
|
}
|
|
@@ -536,7 +580,7 @@ async function main() {
|
|
|
536
580
|
lines.push(` ${s.id} ${s.action} on ${s.site}${s.path ?? ""} ${s.uses_left} of ${s.uses} uses left until ${s.expires_at}${notes.has(s.id) ? ` note: ${JSON.stringify(notes.get(s.id))}` : ""}`);
|
|
537
581
|
if (r.pages > 1)
|
|
538
582
|
lines.push(`Page ${r.page} of ${r.pages}. Use --page N for more.`);
|
|
539
|
-
|
|
583
|
+
print(values.text ? lines.join("\n") : json(r));
|
|
540
584
|
return 0;
|
|
541
585
|
}
|
|
542
586
|
throw new Error("Usage: tiresias slip grant --action submit_form --site <origin> [--path /p] [--until <date> | --for 7d] [--uses N] [--note text] | slip list | slip revoke <id> | slip revoke --all");
|
|
@@ -581,7 +625,7 @@ async function main() {
|
|
|
581
625
|
}
|
|
582
626
|
if (cmd === "watch") {
|
|
583
627
|
const r = await engine.watch(ctx, page);
|
|
584
|
-
|
|
628
|
+
print(values.text ? watchText(r) : json(r));
|
|
585
629
|
return 0;
|
|
586
630
|
}
|
|
587
631
|
if (cmd === "scanner") {
|
|
@@ -596,23 +640,71 @@ async function main() {
|
|
|
596
640
|
throw new Error("Usage: tiresias scanner set [--timeout 10] [--send-file] -- /full/path/to/program [args...]");
|
|
597
641
|
const cfg = scanner.setScanner(command, { timeout: values.timeout, sendFile: values["send-file"], confirm: values.confirm }, sessionPriv);
|
|
598
642
|
const msg = `Scanner set: ${cfg.command[0]}${cfg.command.length > 1 ? ` with ${cfg.command.length - 1} argument(s)` : ""}, up to ${cfg.timeout_seconds} s per file, ${cfg.send_file ? "and it is handed the file itself (a quarantine copy, deleted after)" : "fingerprint only (not the file)"}. It runs on every high-risk file warning.`;
|
|
599
|
-
|
|
643
|
+
print(values.text ? msg : json({ status: "ok", message: msg, scanner: cfg }));
|
|
600
644
|
return 0;
|
|
601
645
|
}
|
|
602
646
|
if (arg === "show") {
|
|
603
647
|
const cfg = loadScanner();
|
|
604
648
|
const msg = cfg ? `Scanner: ${JSON.stringify(cfg.command)}, ${cfg.timeout_seconds} s, send_file ${cfg.send_file}.` : "No scanner is set. Tiresias includes none; set your own with: tiresias scanner set -- /full/path/to/program [args...]";
|
|
605
|
-
|
|
649
|
+
print(values.text ? msg : json({ status: "ok", message: msg, scanner: cfg }));
|
|
606
650
|
return 0;
|
|
607
651
|
}
|
|
608
652
|
if (arg === "off") {
|
|
609
653
|
const was = scanner.clearScanner(sessionPriv);
|
|
610
654
|
const msg = was ? "Scanner removed. File warnings are no longer checked by it." : "No scanner was set.";
|
|
611
|
-
|
|
655
|
+
print(values.text ? msg : json({ status: "ok", message: msg }));
|
|
612
656
|
return 0;
|
|
613
657
|
}
|
|
614
658
|
throw new Error("Usage: tiresias scanner set [--timeout 10] [--send-file] -- /full/path/to/program [args...] | scanner show | scanner off");
|
|
615
659
|
}
|
|
660
|
+
if (cmd === "guard") {
|
|
661
|
+
// W-38 (v1.2): the owner's meaning check. Only here, from the command line (or by editing config.json): nothing
|
|
662
|
+
// in either MCP server reads, sets, changes or triggers it. Replies name collections and counts, never a text.
|
|
663
|
+
const g = await import("./guard.js");
|
|
664
|
+
const print = (r) => console.log(values.text ? r.message : json(r));
|
|
665
|
+
if (arg === "setup") {
|
|
666
|
+
const r = await g.setup({ url: values.url, model: values.model, prefix: values.prefix, falseAlarms: values["false-alarms"], timeout: values.timeout, ordinary: values.ordinary, ordinaryUrls: values["ordinary-urls"], confirm: values.confirm }, sessionPriv);
|
|
667
|
+
print(r);
|
|
668
|
+
return 0;
|
|
669
|
+
}
|
|
670
|
+
if (arg === "import") {
|
|
671
|
+
const file = positionals[2];
|
|
672
|
+
if (!file || positionals.length > 3)
|
|
673
|
+
throw new Error("Usage: tiresias guard import <file> [--name <collection>]");
|
|
674
|
+
print(await g.importFile(file, values.name, sessionPriv));
|
|
675
|
+
return 0;
|
|
676
|
+
}
|
|
677
|
+
if (arg === "show" && positionals.length === 2) {
|
|
678
|
+
print(g.show());
|
|
679
|
+
return 0;
|
|
680
|
+
}
|
|
681
|
+
if (arg === "check") {
|
|
682
|
+
const words = positionals.slice(2).join(" ");
|
|
683
|
+
if ((values.file !== undefined) === (words !== ""))
|
|
684
|
+
throw new Error("Usage: tiresias guard check [--file <path> | <text>]");
|
|
685
|
+
let text = words;
|
|
686
|
+
if (values.file !== undefined) {
|
|
687
|
+
const fsm = await import("node:fs");
|
|
688
|
+
const fd = fsm.openSync(values.file, fsm.constants.O_RDONLY | (fsm.constants.O_NONBLOCK ?? 0));
|
|
689
|
+
try {
|
|
690
|
+
const st = fsm.fstatSync(fd);
|
|
691
|
+
if (!st.isFile() || st.size > 64 * 1024)
|
|
692
|
+
throw new Error("guard check --file takes a plain file of at most 64 KB.");
|
|
693
|
+
text = fsm.readFileSync(fd, "utf8");
|
|
694
|
+
}
|
|
695
|
+
finally {
|
|
696
|
+
fsm.closeSync(fd);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
print(await g.check(text));
|
|
700
|
+
return 0;
|
|
701
|
+
}
|
|
702
|
+
if (arg === "off" && positionals.length === 2) {
|
|
703
|
+
print(g.off(sessionPriv));
|
|
704
|
+
return 0;
|
|
705
|
+
}
|
|
706
|
+
throw new Error("Usage: tiresias guard setup --url <url> --model <id> [...] | guard import <file> [--name <collection>] | guard show | guard check [--file <path> | <text>] | guard off");
|
|
707
|
+
}
|
|
616
708
|
if (cmd === "saved") {
|
|
617
709
|
// W-28 (v0.8): saved snapshots. Owner's commands: nothing in the MCP server lists, verifies or deletes them.
|
|
618
710
|
const sv = await import("./saved.js");
|
|
@@ -622,12 +714,12 @@ async function main() {
|
|
|
622
714
|
const L = [r.message, ...r.saved.map((i) => ` ${i.id.slice(0, 16)} ${i.saved_at ?? "(damaged)"} ${i.fingerprint_only ? "fingerprint only" : `${i.bytes} bytes${i.rendered ? ", rendered" : ""}`}, ${i.receipts} receipts <${r.untrusted_content.urls.find((u) => u.id === i.id)?.final_url ?? ""}>`)];
|
|
623
715
|
if (r.pages > 1)
|
|
624
716
|
L.push(`Page ${r.page} of ${r.pages}. Use --page N for more.`);
|
|
625
|
-
|
|
717
|
+
print(values.text ? textView(L.join("\n")) : json(r));
|
|
626
718
|
return 0;
|
|
627
719
|
}
|
|
628
720
|
if (sub === "show" && id) {
|
|
629
721
|
const r = sv.show(id);
|
|
630
|
-
|
|
722
|
+
print(values.text ? textView(`${r.message}\nFolder: ${r.folder}${r.untrusted_content ? `\n${JSON.stringify(r.untrusted_content.manifest, null, 2)}` : ""}`) : json(r));
|
|
631
723
|
return 0;
|
|
632
724
|
}
|
|
633
725
|
if (sub === "verify" && (id || values.all)) {
|
|
@@ -645,7 +737,7 @@ async function main() {
|
|
|
645
737
|
if (sessionPriv)
|
|
646
738
|
throw new Error("Private mode: nothing in the store is changed, so no snapshot is deleted.");
|
|
647
739
|
const r = sv.remove(values.all ? "all" : id);
|
|
648
|
-
|
|
740
|
+
print(values.text ? r.message : json(r));
|
|
649
741
|
return 0;
|
|
650
742
|
}
|
|
651
743
|
throw new Error("Usage: tiresias saved [list] [--page N] | saved show <id> | saved verify <id> | --all | saved delete <id> | --all");
|
|
@@ -663,15 +755,15 @@ async function main() {
|
|
|
663
755
|
}
|
|
664
756
|
if (sub === "upgrade") {
|
|
665
757
|
const r = await an.upgrade();
|
|
666
|
-
|
|
758
|
+
print(values.text ? r.message : json(r));
|
|
667
759
|
return 0;
|
|
668
760
|
}
|
|
669
761
|
if (sub === "status") {
|
|
670
762
|
const r = await an.status(page);
|
|
671
|
-
const L = [r.message, `Calendars: ${r.calendars.join(", ")}`, ...r.batches.map((b) => ` ${b.id.slice(0, 16)} ${b.created_at} ${b.leaves} leaves ${b.status === "complete" ? `in Bitcoin block ${b.bitcoin.join(", ")}` : "pending"}`)];
|
|
763
|
+
const L = [r.message, `Calendars: ${r.calendars.join(", ")}`, ...r.batches.map((b) => ` ${b.id.slice(0, 16)} ${b.created_at} ${b.leaves} leaves ${b.status === "complete" ? `reported in Bitcoin block ${b.bitcoin.join(", ")}` : "pending"}`)];
|
|
672
764
|
if (r.pages > 1)
|
|
673
765
|
L.push(`Page ${r.page} of ${r.pages}. Use --page N for more.`);
|
|
674
|
-
|
|
766
|
+
print(values.text ? L.join("\n") : json(r));
|
|
675
767
|
return 0;
|
|
676
768
|
}
|
|
677
769
|
throw new Error("Usage: tiresias anchor | anchor status [--page N] | anchor upgrade");
|
|
@@ -687,10 +779,10 @@ async function main() {
|
|
|
687
779
|
const msg = an.proveText(bd);
|
|
688
780
|
if (values.out !== undefined) {
|
|
689
781
|
const files = an.writeBundle(bd, values.out, !!sessionPriv);
|
|
690
|
-
|
|
782
|
+
print(values.text ? `${msg}\nWritten:\n${files.map((f) => ` ${f}`).join("\n")}\nCheck it with: tiresias receipts verify ${files[0]}${bd.batch.status === "complete" ? ` (or the official tool: ots verify ${files[files.length - 1]})` : ""}` : json({ status: "ok", message: msg, files }));
|
|
691
783
|
}
|
|
692
784
|
else
|
|
693
|
-
|
|
785
|
+
print(values.text ? msg : json({ status: "ok", message: msg, notice: (await import("./types.js")).NOTICE, untrusted_content: { bundle: bd } }));
|
|
694
786
|
return 0;
|
|
695
787
|
}
|
|
696
788
|
const r = an.verifyBundle(target);
|
|
@@ -711,19 +803,19 @@ async function main() {
|
|
|
711
803
|
throw new Error("Usage: tiresias translator set [--timeout 20] -- /full/path/to/program [args...]");
|
|
712
804
|
const cfg = tr.setTranslator(command, { timeout: values.timeout, confirm: values.confirm }, sessionPriv);
|
|
713
805
|
const msg = `Translator set: ${cfg.command[0]}${cfg.command.length > 1 ? ` with ${cfg.command.length - 1} argument(s)` : ""}, up to ${cfg.timeout_seconds} s per read. It runs only when a read asks for a translation, with the text on standard input and the source and target languages as its last two arguments.`;
|
|
714
|
-
|
|
806
|
+
print(values.text ? msg : json({ status: "ok", message: msg, translator: cfg }));
|
|
715
807
|
return 0;
|
|
716
808
|
}
|
|
717
809
|
if (arg === "show") {
|
|
718
810
|
const cfg = loadTranslator();
|
|
719
811
|
const msg = cfg ? `Translator: ${JSON.stringify(cfg.command)}, ${cfg.timeout_seconds} s.` : "No translator is set. Tiresias includes none; set your own with: tiresias translator set -- /full/path/to/program [args...]";
|
|
720
|
-
|
|
812
|
+
print(values.text ? msg : json({ status: "ok", message: msg, translator: cfg }));
|
|
721
813
|
return 0;
|
|
722
814
|
}
|
|
723
815
|
if (arg === "off") {
|
|
724
816
|
const was = tr.clearTranslator(sessionPriv);
|
|
725
817
|
const msg = was ? "Translator removed. Reads no longer offer translations." : "No translator was set.";
|
|
726
|
-
|
|
818
|
+
print(values.text ? msg : json({ status: "ok", message: msg }));
|
|
727
819
|
return 0;
|
|
728
820
|
}
|
|
729
821
|
throw new Error("Usage: tiresias translator set [--timeout 20] -- /full/path/to/program [args...] | translator show | translator off");
|
|
@@ -733,15 +825,15 @@ async function main() {
|
|
|
733
825
|
const r = (await import("./settings.js")).command(positionals.slice(1), sessionPriv, { confirm: values.confirm });
|
|
734
826
|
noticeLines = null; // look again: this command may have just changed what the notice says
|
|
735
827
|
if (r.code)
|
|
736
|
-
|
|
828
|
+
printError(values.text ? r.text : json(r.reply, 0));
|
|
737
829
|
else
|
|
738
|
-
|
|
830
|
+
print(values.text ? r.text : json(r.reply));
|
|
739
831
|
return r.code;
|
|
740
832
|
}
|
|
741
833
|
if (cmd === "safety") {
|
|
742
834
|
if (arg === "status") {
|
|
743
835
|
const r = engine.safetyStatus();
|
|
744
|
-
|
|
836
|
+
print(values.text ? `${r.message}\nList: ${r.list.state}${r.list.entries !== undefined ? `, ${r.list.entries} domains, confirmed ${r.list.verified_at}` : ""}\nWeb Risk: ${r.web_risk.configured ? `set up (${r.web_risk.from})` : "not set up"}` : json(r));
|
|
745
837
|
return 0;
|
|
746
838
|
}
|
|
747
839
|
if (arg === "update") {
|
|
@@ -760,13 +852,10 @@ async function main() {
|
|
|
760
852
|
if (sessionPriv)
|
|
761
853
|
throw new Error("Private mode: nothing is written, so no key is made.");
|
|
762
854
|
const r = await keys.initKey(values.force);
|
|
763
|
-
|
|
855
|
+
print(json({ message: r.replaced ? "Replaced your signing key." : "Made your signing key.", private_key_file: r.file, keyid: r.keyid, public_jwk: r.public_jwk, directory: r.directory, next: 'Host "directory" at /.well-known/http-message-signatures-directory on your site, and set "signature_agent" in config.json. The private key was not printed.' }));
|
|
764
856
|
}
|
|
765
857
|
else if (sub === "show" || sub === "directory") {
|
|
766
|
-
const
|
|
767
|
-
if (!jwk)
|
|
768
|
-
throw new Error("No signing key yet. Run: tiresias keys init");
|
|
769
|
-
const info = await keys.publicInfo(jwk);
|
|
858
|
+
const { info, previous } = await keys.publishedKeys(); // v1.1: the previous key too, while its overlap window is open
|
|
770
859
|
if (sub === "directory")
|
|
771
860
|
console.log(JSON.stringify(info.directory, null, 2)); // the exact JSON to host: nothing added
|
|
772
861
|
else {
|
|
@@ -777,7 +866,8 @@ async function main() {
|
|
|
777
866
|
catch (e) {
|
|
778
867
|
agent = `(config.json problem: ${e.message})`;
|
|
779
868
|
}
|
|
780
|
-
|
|
869
|
+
const rotation = previous ? { previous_keyid: previous.keyid, rotated_at: previous.rotated_at, previous_leaves_directory_at: previous.until, note: "New requests are signed with the new key only. The previous key stays in the directory until then; run `tiresias keys rotate --finish` to drop it now." } : undefined;
|
|
870
|
+
print(json({ public_jwk: info.public_jwk, keyid: info.keyid, directory: info.directory, ...(rotation ? { rotation } : {}), signature_agent: agent, signing: agent && !agent.startsWith("(") ? "on" : "off (set signature_agent in config.json)" }));
|
|
781
871
|
}
|
|
782
872
|
}
|
|
783
873
|
else if (sub === "sign-directory") {
|
|
@@ -792,7 +882,9 @@ async function main() {
|
|
|
792
882
|
}
|
|
793
883
|
const days = values.days === undefined ? 30 : /^\d+$/.test(values.days) ? Number(values.days) : NaN;
|
|
794
884
|
const r = await keys.signDirectory({ host, days });
|
|
795
|
-
const reminder =
|
|
885
|
+
const reminder = r.capped_by_rotation
|
|
886
|
+
? `These signatures stop working on ${r.expires_at}, when your previous key leaves the directory (keys rotate). Run this command again right after that time, and re-upload, so the directory lists only the new key.`
|
|
887
|
+
: `These signatures stop working on ${r.expires_at}. Run this command again and re-upload before then.`;
|
|
796
888
|
if (values.out !== undefined) {
|
|
797
889
|
const fsm = await import("node:fs");
|
|
798
890
|
const pathm = await import("node:path");
|
|
@@ -809,13 +901,53 @@ async function main() {
|
|
|
809
901
|
fsm.writeFileSync(tmp, content, { flag: "wx", mode: 0o644 });
|
|
810
902
|
fsm.renameSync(tmp, target);
|
|
811
903
|
}
|
|
812
|
-
|
|
904
|
+
print(json({ host: r.host, serve_at: `https://${r.host}${r.path}`, files: Object.keys(files).map((n) => pathm.join(folder, n)), expires_at: r.expires_at, reminder }));
|
|
813
905
|
}
|
|
814
906
|
else
|
|
815
|
-
|
|
907
|
+
print(json({ host: r.host, serve_at: `https://${r.host}${r.path}`, created_at: r.created_at, expires_at: r.expires_at, body: JSON.parse(r.body), headers: r.headers, reminder }));
|
|
908
|
+
}
|
|
909
|
+
else if (sub === "rotate") {
|
|
910
|
+
// v1.1 workstream 4: rotate the signing key (overlap window) or, with --slips, the slip key.
|
|
911
|
+
if (sessionPriv)
|
|
912
|
+
throw new Error("Private mode: nothing is written, so no key is rotated.");
|
|
913
|
+
const history = await import("./history.js");
|
|
914
|
+
const by = process.stdin.isTTY === true ? "terminal" : "not_terminal";
|
|
915
|
+
if (values.slips) {
|
|
916
|
+
if (values.finish || values.overlap !== undefined)
|
|
917
|
+
throw new Error("keys rotate --slips takes only --confirm.");
|
|
918
|
+
const slips = await import("./slips.js");
|
|
919
|
+
slips.checkRotatePhrase(values.confirm); // before the prompt: a missing phrase never asks anything
|
|
920
|
+
const { confirmByTyping } = await import("./person.js");
|
|
921
|
+
await confirmByTyping("rotate slip key", "Rotate the slip key: every permission slip of this profile is revoked now and can never be used again. Saved pages stay checkable against the old key's public half.");
|
|
922
|
+
const r = slips.rotateSlipKey(values.confirm, sessionPriv);
|
|
923
|
+
const msg = `Rotated the slip key. Revoked ${r.revoked} slip${r.revoked === 1 ? "" : "s"}; grant new ones with tiresias slip grant. ${r.retired ? "Saved pages signed before now still verify (tiresias saved verify names the retired key)." : "The old key could not be read, so it was replaced without keeping its public half: saved pages it signed no longer verify."} Receipts do not use the slip key and are unchanged. The private key was not printed.`;
|
|
924
|
+
print(values.text ? msg : json({ status: "ok", message: msg, revoked: r.revoked, old_key_kept_for_saved_pages: r.retired }));
|
|
925
|
+
}
|
|
926
|
+
else if (values.finish) {
|
|
927
|
+
if (values.overlap !== undefined || values.confirm !== undefined)
|
|
928
|
+
throw new Error("keys rotate --finish takes no other option.");
|
|
929
|
+
const r = await keys.finishRotation();
|
|
930
|
+
if (r.finished)
|
|
931
|
+
history.record({ time: new Date().toISOString(), tool: "keys", url: "", agent: "cli", status: "ok", door: "none", event: "signing_key_rotation_finished", by });
|
|
932
|
+
const msg = r.finished
|
|
933
|
+
? `Finished the rotation: the previous key${r.previous_keyid ? ` (${r.previous_keyid})` : ""} is out of the directory and its private half is deleted. Publish the directory again (tiresias keys directory or keys sign-directory).`
|
|
934
|
+
: "No rotation is in its overlap window, so there was nothing to finish.";
|
|
935
|
+
print(values.text ? msg : json({ status: "ok", message: msg, finished: r.finished, ...(r.previous_keyid ? { previous_keyid: r.previous_keyid } : {}) }));
|
|
936
|
+
}
|
|
937
|
+
else {
|
|
938
|
+
if (values.confirm !== undefined)
|
|
939
|
+
throw new Error("keys rotate takes --confirm only with --slips.");
|
|
940
|
+
const r = await keys.rotateKey({ overlapDays: keys.parseOverlap(values.overlap) });
|
|
941
|
+
history.record({ time: r.rotated_at, tool: "keys", url: "", agent: "cli", status: "ok", door: "none", event: "signing_key_rotated", by });
|
|
942
|
+
const msg = r.overlap_until
|
|
943
|
+
? `Rotated your signing key. New requests are signed with the new key (${r.keyid}). The previous key (${r.previous_keyid}) stays in your directory until ${r.overlap_until}, then drops out by itself (tiresias keys rotate --finish drops it now).`
|
|
944
|
+
: `Rotated your signing key with no overlap. New requests are signed with the new key (${r.keyid}); the previous key (${r.previous_keyid}) is deleted and out of the directory now.`;
|
|
945
|
+
const next = 'Publish the new directory now: tiresias keys directory (or keys sign-directory for a static host) and upload it to /.well-known/http-message-signatures-directory. A server that signs your directory itself (such as a Cloudflare Worker holding a copy of the key) needs the new key too. The private key was not printed.';
|
|
946
|
+
print(values.text ? `${msg}\n${next}` : json({ status: "ok", message: msg, keyid: r.keyid, public_jwk: r.public_jwk, previous_keyid: r.previous_keyid, overlap_days: r.overlap_days, overlap_until: r.overlap_until, directory: r.directory, private_key_file: r.file, next }));
|
|
947
|
+
}
|
|
816
948
|
}
|
|
817
949
|
else
|
|
818
|
-
throw new Error("Usage: tiresias keys init [--force] | keys show | keys directory | keys sign-directory");
|
|
950
|
+
throw new Error("Usage: tiresias keys init [--force] | keys show | keys directory | keys sign-directory | keys rotate [--overlap 7] | keys rotate --finish | keys rotate --slips --confirm \"YES, ROTATE THE SLIP KEY\"");
|
|
819
951
|
return 0;
|
|
820
952
|
}
|
|
821
953
|
if (cmd === "clear") {
|
|
@@ -828,9 +960,25 @@ async function main() {
|
|
|
828
960
|
if (sessionPriv && !values["dry-run"])
|
|
829
961
|
throw new Error("Private mode: nothing in the store is changed, so nothing is cleared. Use --dry-run to see what clear would remove.");
|
|
830
962
|
const r = await clearStore({ limits: loadLimits(), olderThanMs, all: values.all, dryRun: values["dry-run"] });
|
|
831
|
-
|
|
963
|
+
print(values.text ? r.summary : json(r));
|
|
832
964
|
return r.not_removed ? 1 : 0; // v0.6: something clear meant to remove is still there
|
|
833
965
|
}
|
|
966
|
+
if (cmd === "read" && localBudget !== undefined) {
|
|
967
|
+
// What a local model gets: the read local mode makes, printed as JSON. A local model can pass only these
|
|
968
|
+
// options, and its reads are not tabs.
|
|
969
|
+
const extra = (tokens ?? []).find((t) => t.kind === "option" && !["local", "local-budget", "question", "section", "page", "private", "profile"].includes(t.name));
|
|
970
|
+
if (extra)
|
|
971
|
+
throw new Error(`--local takes only --question, --section, --page and --local-budget, not --${extra.name}.`);
|
|
972
|
+
const section = values.section === undefined ? undefined : Number(values.section);
|
|
973
|
+
if (section !== undefined && (!Number.isInteger(section) || section < 1))
|
|
974
|
+
throw new Error("--section must be a whole number, 1 or more");
|
|
975
|
+
const r = await localRead(need(), { question: values.question, section, page }, ctx, localBudget);
|
|
976
|
+
if (r.status === "error")
|
|
977
|
+
printError(json(r, 0));
|
|
978
|
+
else
|
|
979
|
+
print(json(r));
|
|
980
|
+
return exitFor(r.status);
|
|
981
|
+
}
|
|
834
982
|
let out;
|
|
835
983
|
if (cmd === "read") {
|
|
836
984
|
const section = values.section === undefined ? undefined : Number(values.section);
|
|
@@ -856,7 +1004,7 @@ async function main() {
|
|
|
856
1004
|
if (isEnv)
|
|
857
1005
|
printEnvelope(out, values.text);
|
|
858
1006
|
else
|
|
859
|
-
|
|
1007
|
+
print(json(out));
|
|
860
1008
|
return isEnv ? exitFor(out.status) : 0;
|
|
861
1009
|
}
|
|
862
1010
|
// W-30 (v0.6): the door checks a read started in the background finish (or end by their own deadline)
|
|
@@ -865,9 +1013,9 @@ main().then(async (code) => {
|
|
|
865
1013
|
if (code < 0)
|
|
866
1014
|
return;
|
|
867
1015
|
// W-32 (v0.9): a --text reply ends with the settings notice (a JSON reply carries it as settings_notice).
|
|
868
|
-
const n = process.argv.includes("--text") ? currentNotice() : undefined;
|
|
1016
|
+
const n = process.argv.includes("--text") && loadChoice("text_views") !== "wrapped" ? currentNotice() : undefined;
|
|
869
1017
|
if (n)
|
|
870
|
-
(code === 0 ?
|
|
1018
|
+
(code === 0 ? print : printError)(`\nSettings notice:\n${n.map((l) => ` ${l}`).join("\n")}`);
|
|
871
1019
|
await drainForExit();
|
|
872
1020
|
process.exit(code);
|
|
873
1021
|
}, async (e) => {
|
|
@@ -888,7 +1036,7 @@ main().then(async (code) => {
|
|
|
888
1036
|
const sub = process.argv[2] && /^[a-z]{1,20}$/.test(process.argv[2]) ? process.argv[2] : "<command>";
|
|
889
1037
|
const msg = opt !== undefined ? `Unknown option ${JSON.stringify(opt)}. Run tiresias ${sub} --help for the options it takes.` : e.message;
|
|
890
1038
|
const n = process.argv.includes("--text") ? currentNotice() : undefined;
|
|
891
|
-
|
|
1039
|
+
printError(process.argv.includes("--text") ? msg + (n ? `\n\nSettings notice:\n${n.map((l) => ` ${l}`).join("\n")}` : "") : json({ status: "error", message: msg }, 0));
|
|
892
1040
|
await drainForExit();
|
|
893
1041
|
process.exit(1);
|
|
894
1042
|
});
|