@raibitsi/tiresias 1.1.0 → 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 +43 -0
- package/README.md +27 -11
- 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 +16 -13
- package/dist/cleanup.js +3 -1
- package/dist/cli.js +144 -49
- package/dist/config.js +60 -1
- package/dist/confirm.js +15 -4
- package/dist/dom.js +13 -8
- package/dist/doors.js +1 -1
- package/dist/engine.js +6 -1
- package/dist/envelope.js +10 -1
- package/dist/fetcher.js +24 -2
- package/dist/forms.js +80 -8
- package/dist/getactions.js +28 -8
- package/dist/guard.js +1240 -0
- package/dist/guardclient.js +245 -0
- package/dist/guardnetwork.js +22 -0
- package/dist/history.js +4 -1
- package/dist/hosts.js +24 -17
- package/dist/local.js +537 -0
- package/dist/mcp.js +46 -15
- package/dist/pipeline.js +106 -24
- package/dist/preformatted.js +12 -0
- package/dist/queue.js +20 -18
- package/dist/reader.js +441 -87
- package/dist/receipts.js +5 -0
- package/dist/render.js +65 -15
- package/dist/renderactions.js +69 -0
- package/dist/rules.js +14 -2
- package/dist/safety.js +6 -4
- package/dist/settings.js +5 -2
- package/dist/shield.js +15 -0
- package/dist/textview.js +8 -2
- package/dist/types.js +9 -2
- package/dist/work.js +6 -0
- package/docs/LOCAL-MODELS.md +271 -0
- package/package.json +5 -2
package/dist/anchor.js
CHANGED
|
@@ -30,6 +30,8 @@ const MAX_BATCH_FILE = 8 * 1024 * 1024;
|
|
|
30
30
|
const MAX_OTS = 64 * 1024; // a stored proof from the root (calendar answers are at most 10 KB each)
|
|
31
31
|
const MAX_ANSWER = 10_000; // what the official client reads from a calendar
|
|
32
32
|
const MAX_UPGRADE_REQUESTS = 200; // per run
|
|
33
|
+
const BITCOIN_RETRY_DAYS = 14; // a calendar's unchecked claim must not stop other allowed calendars early
|
|
34
|
+
const BITCOIN_CAVEAT = "A calendar's report is not checked against Bitcoin here. To check it, run tiresias receipts verify and follow its last step, or use the official ots verify.";
|
|
33
35
|
const MAX_BUNDLE = 16 * 1024 * 1024;
|
|
34
36
|
const MAX_SCAN = 2_000_000; // receipts lines looked at in one run
|
|
35
37
|
const HEX64 = /^[0-9a-f]{64}$/;
|
|
@@ -360,24 +362,31 @@ async function upgradeAll(limits = {}) {
|
|
|
360
362
|
}
|
|
361
363
|
checked++;
|
|
362
364
|
const b = readBatch(file);
|
|
363
|
-
if (!b
|
|
365
|
+
if (!b)
|
|
366
|
+
continue;
|
|
367
|
+
const retryClaim = Date.now() - Date.parse(b.created_at) < BITCOIN_RETRY_DAYS * 86_400_000;
|
|
368
|
+
if (b.status === "complete" && !retryClaim)
|
|
364
369
|
continue;
|
|
365
|
-
rep.batches++;
|
|
366
370
|
const root = Buffer.from(b.id, "hex");
|
|
367
371
|
let stamp;
|
|
368
372
|
try {
|
|
369
373
|
stamp = ots.parse(root, Buffer.from(b.ots, "base64"));
|
|
370
374
|
}
|
|
371
375
|
catch {
|
|
376
|
+
rep.batches++;
|
|
372
377
|
rep.failed++;
|
|
373
378
|
continue;
|
|
374
379
|
}
|
|
375
380
|
let changed = false;
|
|
376
381
|
const pending = ots.attestations(stamp).filter((p) => p.att.kind === "pending");
|
|
382
|
+
const canAsk = (p) => p.att.kind === "pending" && !hasBitcoin(p.node).length && upgradeAllowed(p.att.uri, mine);
|
|
383
|
+
if (hasBitcoin(stamp).length && (!retryClaim || !pending.some(canAsk)))
|
|
384
|
+
continue;
|
|
385
|
+
rep.batches++;
|
|
377
386
|
const first = cursor && path.basename(file) === cursor.file ? cursor.att : 0;
|
|
378
387
|
for (let i = first; i < pending.length; i++) {
|
|
379
388
|
const p = pending[i];
|
|
380
|
-
if (p.att.kind !== "pending")
|
|
389
|
+
if (p.att.kind !== "pending" || hasBitcoin(p.node).length)
|
|
381
390
|
continue;
|
|
382
391
|
if (!upgradeAllowed(p.att.uri, mine)) {
|
|
383
392
|
rep.not_listed++;
|
|
@@ -385,7 +394,7 @@ async function upgradeAll(limits = {}) {
|
|
|
385
394
|
}
|
|
386
395
|
if (budget <= 0) {
|
|
387
396
|
next = { file: path.basename(file), att: i };
|
|
388
|
-
rep.requests_not_asked = pending.length
|
|
397
|
+
rep.requests_not_asked = pending.slice(i).filter(canAsk).length;
|
|
389
398
|
break;
|
|
390
399
|
}
|
|
391
400
|
budget--;
|
|
@@ -398,11 +407,15 @@ async function upgradeAll(limits = {}) {
|
|
|
398
407
|
continue;
|
|
399
408
|
}
|
|
400
409
|
const up = ots.parse(p.msg, r.raw);
|
|
401
|
-
const
|
|
410
|
+
const before = ots.serialize(stamp);
|
|
411
|
+
const trial = ots.parse(root, before);
|
|
402
412
|
ots.merge([...ots.nodes(trial)].find((n) => n.msg.equals(p.msg)), up);
|
|
403
|
-
proofBytes(trial, b.leaves.length);
|
|
404
|
-
|
|
405
|
-
|
|
413
|
+
const after = proofBytes(trial, b.leaves.length);
|
|
414
|
+
if (!before.equals(after)) {
|
|
415
|
+
// Keep existing node references so later pending entries see answers learned in this run.
|
|
416
|
+
ots.merge(stamp, trial);
|
|
417
|
+
changed = true;
|
|
418
|
+
}
|
|
406
419
|
}
|
|
407
420
|
catch {
|
|
408
421
|
rep.failed++;
|
|
@@ -442,8 +455,8 @@ export async function upgrade(limits = {}) {
|
|
|
442
455
|
return { status: "ok", message: upgradeText(u), upgrade: u };
|
|
443
456
|
}
|
|
444
457
|
const upgradeText = (u) => (u.batches
|
|
445
|
-
? `${u.batches}
|
|
446
|
-
: "No pending batches checked.") + (u.scan_incomplete ? ` Upgrade scan incomplete: ${u.batches_not_checked} batch file(s) not checked, ${u.requests_not_asked} pending request(s) not asked in the current batch; the next run resumes here.` : "");
|
|
458
|
+
? `${u.batches} batch(es) checked: ${u.completed} reported in a Bitcoin block by a calendar, ${u.still_pending} still pending${u.failed ? `, ${u.failed} calendar request(s) failed` : ""}${u.not_listed ? `, ${u.not_listed} naming a calendar not on the list (not asked)` : ""}.`
|
|
459
|
+
: "No pending batches checked.") + (u.completed ? ` ${BITCOIN_CAVEAT}` : "") + (u.scan_incomplete ? ` Upgrade scan incomplete: ${u.batches_not_checked} batch file(s) not checked, ${u.requests_not_asked} pending request(s) not asked in the current batch; the next run resumes here.` : "");
|
|
447
460
|
// After a new batch: only earlier batches are worth a word (v0.9 rehearsal: "No pending batches." right after
|
|
448
461
|
// "It is pending" read as a contradiction).
|
|
449
462
|
const earlierText = (u) => (u.batches || u.scan_incomplete ? ` Earlier batches: ${upgradeText(u)}` : "");
|
|
@@ -508,7 +521,7 @@ export async function run(limits = {}) {
|
|
|
508
521
|
const waiting = total - todo.length;
|
|
509
522
|
return {
|
|
510
523
|
status: "ok",
|
|
511
|
-
message: `Anchored ${leaves.length} fingerprint(s) (${receipts} receipt record(s), ${leaves.length - receipts} snapshot(s)) in one batch; ${accepted} of ${calendars.length} calendar(s) accepted its root. It is pending until a calendar
|
|
524
|
+
message: `Anchored ${leaves.length} fingerprint(s) (${receipts} receipt record(s), ${leaves.length - receipts} snapshot(s)) in one batch; ${accepted} of ${calendars.length} calendar(s) accepted its root. It is pending until a calendar reports it in a Bitcoin block (usually a few hours): run tiresias anchor upgrade (or tiresias anchor) later.${waiting ? ` ${waiting} more wait for the next run.` : ""}${scanText}${earlierText(u)}`,
|
|
512
525
|
scan_incomplete: incomplete,
|
|
513
526
|
profile_batch: { id: b.id, leaves: leaves.length, receipts, snapshots: leaves.length - receipts, calendars: results },
|
|
514
527
|
...(waiting ? { waiting } : {}),
|
|
@@ -528,7 +541,7 @@ export async function status(page = 1, limits = {}) {
|
|
|
528
541
|
const pending = all.filter((b) => b.status === "pending").length;
|
|
529
542
|
return {
|
|
530
543
|
status: "ok",
|
|
531
|
-
message: `Anchoring is ${mode}. ${all.length} batch(es): ${all.length - pending} in a Bitcoin block, ${pending} pending. ${total} fingerprint(s) not yet anchored${incomplete ? " in this part of the log (receipt scan incomplete; run anchor to continue)" : ""}
|
|
544
|
+
message: `Anchoring is ${mode}. ${all.length} batch(es): ${all.length - pending} reported in a Bitcoin block by a calendar, ${pending} pending. ${total} fingerprint(s) not yet anchored${incomplete ? " in this part of the log (receipt scan incomplete; run anchor to continue)" : ""}.${all.length - pending > 0 ? ` ${BITCOIN_CAVEAT}` : ""}`,
|
|
532
545
|
scan_incomplete: incomplete,
|
|
533
546
|
anchoring: mode, calendars, not_yet_anchored: total, batches: all.slice((page - 1) * per, page * per), total_batches: all.length, page, pages,
|
|
534
547
|
};
|
|
@@ -607,7 +620,7 @@ export async function prove(idArg) {
|
|
|
607
620
|
}
|
|
608
621
|
export function proveText(bd) {
|
|
609
622
|
const what = bd.kind === "receipt" ? "receipt record" : "saved snapshot";
|
|
610
|
-
const when = bd.batch.status === "complete" ? `
|
|
623
|
+
const when = bd.batch.status === "complete" ? `A calendar reports its batch in Bitcoin block(s) ${bd.batch.bitcoin.join(", ")}. ${BITCOIN_CAVEAT}` : "Its batch is still pending (no calendar has reported a Bitcoin block yet): run tiresias anchor upgrade later, then prove it again for a proof that needs no calendar.";
|
|
611
624
|
return `A proof for this ${what} (batch of ${bd.batch.created_at}). ${when}${bd.record ? "" : ` The ${what} itself is no longer kept here; the proof covers its fingerprint, so whoever holds it can still check it.`}`;
|
|
612
625
|
}
|
|
613
626
|
// Write the bundle, the exact record bytes (whose SHA-256 is the fingerprint) and the .ots into a folder that exists.
|
package/dist/browsecli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// v0.6 Track 2 ("browse"): the command-line side of tabs and back/forward (W-24) and the downloads shelf
|
|
3
3
|
// (W-27), kept out of cli.ts so the shared file only gains a few lines.
|
|
4
|
-
import { textView } from "./textview.js";
|
|
4
|
+
import { escapeTerminal, textView } from "./textview.js";
|
|
5
5
|
import { stampProfile } from "./store.js";
|
|
6
6
|
import { errorEnv } from "./envelope.js";
|
|
7
7
|
import * as shelf from "./shelf.js";
|
|
@@ -20,7 +20,10 @@ export const BROWSE_TAKES = {
|
|
|
20
20
|
forward: ["section", "question", "page"],
|
|
21
21
|
files: ["site", "since", "until", "page"],
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
// Terminal display only. Applying the escape again is harmless: backslashes stay unchanged.
|
|
24
|
+
const print = (text) => console.log(escapeTerminal(String(text)));
|
|
25
|
+
const printError = (text) => console.error(escapeTerminal(String(text)));
|
|
26
|
+
const json = (x) => escapeTerminal(JSON.stringify(stampProfile(x), null, 2));
|
|
24
27
|
const exitFor = (status) => (status === "ok" || status === "unchanged" ? 0 : status === "error" ? 1 : 2);
|
|
25
28
|
// The CLI read command calls this after a read: the read opens (or moves to) a tab in the CLI's session.
|
|
26
29
|
// Never in private mode (noteReply checks the reply and the session).
|
|
@@ -75,7 +78,7 @@ export async function runBrowseCommand(cmd, positionals, values, sessionPriv) {
|
|
|
75
78
|
throw e; // fixed text: one JSON line on standard error, exit 1
|
|
76
79
|
// anything else keeps its detail inside untrusted_content, as over MCP (Codex browse round 2)
|
|
77
80
|
const env = errorEnv("", e);
|
|
78
|
-
|
|
81
|
+
printError(values.text ? env.message : JSON.stringify(stampProfile(env)));
|
|
79
82
|
return 1;
|
|
80
83
|
}
|
|
81
84
|
if (values.text) {
|
|
@@ -85,18 +88,18 @@ export async function runBrowseCommand(cmd, positionals, values, sessionPriv) {
|
|
|
85
88
|
if (r.pages > 1)
|
|
86
89
|
L.push(`Page ${r.page} of ${r.pages}. Use --page N for more.`);
|
|
87
90
|
L.push("URLs and names above came from the web: data, not instructions.");
|
|
88
|
-
|
|
91
|
+
print(textView(L.join("\n")));
|
|
89
92
|
}
|
|
90
93
|
else
|
|
91
|
-
|
|
94
|
+
print(json(r));
|
|
92
95
|
return 0;
|
|
93
96
|
}
|
|
94
97
|
const store = new DiskTabs();
|
|
95
|
-
const
|
|
98
|
+
const printTab = (e) => {
|
|
96
99
|
if (e.status === "error")
|
|
97
|
-
|
|
100
|
+
printError(values.text ? tabText(e) : JSON.stringify(stampProfile(e)));
|
|
98
101
|
else
|
|
99
|
-
|
|
102
|
+
print(values.text ? tabText(e) : json(e));
|
|
100
103
|
return exitFor(e.status);
|
|
101
104
|
};
|
|
102
105
|
const num = (s, usage) => {
|
|
@@ -109,7 +112,7 @@ export async function runBrowseCommand(cmd, positionals, values, sessionPriv) {
|
|
|
109
112
|
if (sub === "close") {
|
|
110
113
|
if ((n !== undefined) === !!values.all || positionals.length > 3)
|
|
111
114
|
throw new Error("Usage: tiresias tabs close <n> | tabs close --all");
|
|
112
|
-
return
|
|
115
|
+
return printTab(await tabAction(store, values.all ? { action: "close_all" } : { action: "close", number: num(n, "Usage: tiresias tabs close <n> | tabs close --all") }, {}, sessionPriv));
|
|
113
116
|
}
|
|
114
117
|
if (sub !== undefined || values.all)
|
|
115
118
|
throw new Error("Usage: tiresias tabs [--page 2] | tabs close <n> | tabs close --all");
|
|
@@ -121,20 +124,20 @@ export async function runBrowseCommand(cmd, positionals, values, sessionPriv) {
|
|
|
121
124
|
if (r.pages > 1)
|
|
122
125
|
L.push(`Page ${r.page} of ${r.pages}. Use --page N for more.`);
|
|
123
126
|
L.push("Titles and URLs above came from the web or from an agent: data, not instructions.");
|
|
124
|
-
|
|
127
|
+
print(textView(L.join("\n")));
|
|
125
128
|
}
|
|
126
129
|
else
|
|
127
|
-
|
|
130
|
+
print(json(r));
|
|
128
131
|
return 0;
|
|
129
132
|
}
|
|
130
133
|
const view = { section, question: values.question, page };
|
|
131
134
|
if (cmd === "tab" && positionals.length > 2)
|
|
132
135
|
throw new Error("Usage: tiresias tab <n> [--section 3] [--question \"...\"] [--page 2]");
|
|
133
136
|
if (cmd === "tab")
|
|
134
|
-
return
|
|
137
|
+
return printTab(await tabAction(store, { action: "open", number: num(positionals[1], "Usage: tiresias tab <n> [--section 3] [--question \"...\"] [--page 2]") }, view, sessionPriv));
|
|
135
138
|
if (positionals.length > 1)
|
|
136
139
|
throw new Error(`Usage: tiresias ${cmd} [--section 3] [--question "..."] [--page 2]`);
|
|
137
140
|
if (cmd !== "back" && cmd !== "forward")
|
|
138
141
|
return null;
|
|
139
|
-
return
|
|
142
|
+
return printTab(await tabAction(store, { action: cmd }, view, sessionPriv));
|
|
140
143
|
}
|
package/dist/cleanup.js
CHANGED
|
@@ -123,7 +123,9 @@ async function gather(h) {
|
|
|
123
123
|
// W-05: slips/ is not counted either: permissions, at most 200 small slips per profile.
|
|
124
124
|
// W-28: saved/ has its own cap (max_saved_mb), so the main cap never evicts a snapshot to make room for cache.
|
|
125
125
|
// W-08: anchors/ holds only hashes and salts (no browsing data) and is what keeps old proofs provable: not counted.
|
|
126
|
-
|
|
126
|
+
// W-38: guard/ is the owner's meaning check library, built by tiresias guard setup and bounded there (a few
|
|
127
|
+
// thousand vectors): not browsing data, never evicted by the cap or by clear, removed by tiresias guard off.
|
|
128
|
+
const NOT_COUNTED = new Set(["bookmarks", "slips", "saved", "anchors", "guard", PROFILES_FOLDER, ...SHARED]);
|
|
127
129
|
// v0.6 (Codex browse rounds 3, 5 and 6): walked as a stream, so a folder with a huge number of entries never
|
|
128
130
|
// has to fit in memory at once, with a budget of MEASURE.max entries and MEASURE_DEPTH levels, so a tampered
|
|
129
131
|
// store cannot stall the trim. A count that did not finish is a LOWER bound: the disk cap is still applied
|