@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.
Files changed (67) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/README.md +72 -33
  3. package/data/README.md +33 -0
  4. package/data/guard-ordinary-urls.txt +102 -0
  5. package/data/guard-starter.jsonl +424 -0
  6. package/dist/aimed.js +23 -0
  7. package/dist/anchor.js +26 -13
  8. package/dist/browsecli.js +17 -13
  9. package/dist/cdp.js +22 -1
  10. package/dist/cleanup.js +3 -1
  11. package/dist/cli.js +216 -68
  12. package/dist/config.js +75 -1
  13. package/dist/confirm.js +20 -5
  14. package/dist/cooldown.js +57 -32
  15. package/dist/dailylog.js +11 -5
  16. package/dist/dom.js +13 -8
  17. package/dist/doors.js +1 -1
  18. package/dist/engine.js +9 -4
  19. package/dist/envelope.js +10 -1
  20. package/dist/fetcher.js +29 -2
  21. package/dist/filereply.js +7 -1
  22. package/dist/formflow.js +21 -3
  23. package/dist/forms.js +337 -42
  24. package/dist/getactions.js +119 -0
  25. package/dist/guard.js +1240 -0
  26. package/dist/guardclient.js +245 -0
  27. package/dist/guardnetwork.js +22 -0
  28. package/dist/history.js +11 -5
  29. package/dist/hook.js +2 -0
  30. package/dist/hosts.js +34 -27
  31. package/dist/keys.js +420 -18
  32. package/dist/local.js +537 -0
  33. package/dist/mcp.js +56 -25
  34. package/dist/needs.js +9 -5
  35. package/dist/parentwatch.js +6 -16
  36. package/dist/pdf.js +4 -1
  37. package/dist/pdfchild.js +0 -2
  38. package/dist/pdfproc.js +26 -11
  39. package/dist/pdfwatch.js +14 -0
  40. package/dist/pipeline.js +117 -26
  41. package/dist/preformatted.js +12 -0
  42. package/dist/profiles.js +3 -3
  43. package/dist/queue.js +24 -20
  44. package/dist/reader.js +441 -87
  45. package/dist/receipts.js +7 -2
  46. package/dist/render.js +156 -27
  47. package/dist/renderactions.js +69 -0
  48. package/dist/resume.js +8 -6
  49. package/dist/rules.js +24 -5
  50. package/dist/safebrowsing.js +3 -3
  51. package/dist/safety.js +15 -7
  52. package/dist/sandbox.js +1 -1
  53. package/dist/saved.js +24 -9
  54. package/dist/savedlock.js +99 -5
  55. package/dist/settings.js +10 -3
  56. package/dist/shelf.js +1 -1
  57. package/dist/shield.js +15 -0
  58. package/dist/slips.js +43 -1
  59. package/dist/store.js +119 -25
  60. package/dist/tabs.js +1 -1
  61. package/dist/textview.js +16 -0
  62. package/dist/translate.js +22 -2
  63. package/dist/types.js +9 -2
  64. package/dist/watchflow.js +1 -2
  65. package/dist/work.js +10 -2
  66. package/docs/LOCAL-MODELS.md +271 -0
  67. package/package.json +5 -2
package/dist/safety.js CHANGED
@@ -8,6 +8,7 @@
8
8
  // The connection's own `lookup` hook resolves the name, validates every
9
9
  // answer, and hands that same answer to the socket. TLS still verifies the
10
10
  // hostname because we connect by name, not by IP.
11
+ import { guardGetAction } from "./getactions.js";
11
12
  import { createHash } from "node:crypto";
12
13
  import dns from "node:dns/promises";
13
14
  import fs from "node:fs";
@@ -413,10 +414,12 @@ export function decoderFor(encoding) {
413
414
  // only the first bytes are kept until the decision, then nothing but the running hash (and the last 512
414
415
  // bytes, for a disk image's trailer). With no `files` option (or a status that is not a success) the body
415
416
  // is kept as a page whatever it is, as before v0.5.
416
- async function readBody(msg, max, truncate, signal, d, files) {
417
+ // v1.2: `noBody` is a 204 or a 304. Neither has a body, so there is nothing to decompress, whatever
418
+ // Content-Encoding the headers repeat (Wikipedia's 304 says gzip, and gunzipping nothing failed every revisit).
419
+ async function readBody(msg, max, truncate, signal, d, files, noBody = false) {
417
420
  let chosen;
418
421
  try {
419
- chosen = decoderFor(msg.headers["content-encoding"]);
422
+ chosen = noBody ? null : decoderFor(msg.headers["content-encoding"]);
420
423
  }
421
424
  catch (e) {
422
425
  msg.destroy();
@@ -684,13 +687,15 @@ export class Wire {
684
687
  }
685
688
  }
686
689
  }
687
- // v0.7: one plain GET, no redirects, no lookup pinning, capped by its connection's bytes (Wire). For API calls to a
690
+ // v0.7: one plain GET, no redirects, guarded lookup, capped by its connection's bytes (Wire). For API calls to a
688
691
  // fixed endpoint (Google Web Risk), never for a site. The body is read up to `bodyMax`; past it, null.
689
692
  export function boundedGet(url, headers, bodyMax, wire, signal) {
690
693
  return new Promise((resolve, reject) => {
691
- const u = new URL(url);
694
+ const u = parseSafeUrl(url);
695
+ assertLiteral(u);
696
+ assertPort(u);
692
697
  const mod = u.protocol === "https:" ? https : http;
693
- const req = mod.request({ hostname: u.hostname.replace(/^\[|\]$/g, ""), port: u.port || undefined, path: u.pathname + u.search, method: "GET", headers, agent: false, signal }, (res) => {
698
+ const req = mod.request({ hostname: u.hostname.replace(/^\[|\]$/g, ""), port: u.port || undefined, path: u.pathname + u.search, method: "GET", headers, lookup: guardedLookup, agent: false, signal }, (res) => {
694
699
  if (res.statusCode !== 200) {
695
700
  res.destroy();
696
701
  return resolve({ status: res.statusCode ?? 0, body: null });
@@ -840,6 +845,9 @@ export async function safeFetch(rawUrl, opts = {}) {
840
845
  if (sent)
841
846
  (sent.requests++, signed && sent.signed++);
842
847
  };
848
+ if (!opts.submit && (hop > 0 || method === "GET"))
849
+ guardGetAction(u);
850
+ opts.beforeSend?.(u);
843
851
  let msg;
844
852
  try {
845
853
  msg = await abortable(requestOnce(u, headers, ctl.signal, onSent, hop === 0 ? method : "GET", hop === 0 ? body : undefined, wire));
@@ -915,7 +923,7 @@ export async function safeFetch(rawUrl, opts = {}) {
915
923
  }
916
924
  let read;
917
925
  try {
918
- read = await readBody(msg, max, !!opts.truncate, ctl.signal, declared, files);
926
+ read = await readBody(msg, max, !!opts.truncate, ctl.signal, declared, files, status === 204 || status === 304);
919
927
  }
920
928
  catch (e) {
921
929
  if (e instanceof FetchError && e.code === "too_large" && mimeOf(ct) === "application/pdf") {
@@ -927,7 +935,7 @@ export async function safeFetch(rawUrl, opts = {}) {
927
935
  if ("file" in read) {
928
936
  if (Number.isFinite(cl))
929
937
  read.file.declared_size = String(cl);
930
- return { status, headers: toHeaders(msg.headers), body: "", url: u.href, redirected, truncated: false, file: read.file };
938
+ return { status, headers: toHeaders(msg.headers), body: "", url: u.href, redirected, truncated: read.file.stopped !== undefined, file: read.file };
931
939
  }
932
940
  const { page: buf, truncated, verdict } = read;
933
941
  const common = { status, headers: toHeaders(msg.headers), url: u.href, redirected, truncated, size: wire.total, ...("read" in verdict ? { read: verdict.read } : {}), fileFlags: verdict.flags };
package/dist/sandbox.js CHANGED
@@ -81,7 +81,7 @@ export async function runUntrusted(job, size) {
81
81
  // decoder buffers are not counted by a worker's heap limit.
82
82
  if (job.op === "pdf")
83
83
  return (await import("./pdfproc.js")).runPdfChild(job);
84
- if (size <= INLINE_MAX)
84
+ if (size <= INLINE_MAX && !(job.op === "parse" && job.kind === "plain" && job.mode === "calendar"))
85
85
  return unwrap(handle(job));
86
86
  const sig = currentSignal();
87
87
  let release;
package/dist/saved.js CHANGED
@@ -15,7 +15,7 @@
15
15
  import fs from "node:fs";
16
16
  import path from "node:path";
17
17
  import { randomBytes, sign as edSign, verify as edVerify } from "node:crypto";
18
- import { ensureSlipKey, readSlipKey } from "./keys.js";
18
+ import { ensureSlipKey, readSlipKey, retiredSlipKeys } from "./keys.js";
19
19
  import { releaseLock, stillOwned, takeLock } from "./savedlock.js";
20
20
  import { bound as boundReceipt } from "./receipts.js";
21
21
  import { DEFAULT_LIMITS, loadLimits, loadSavingMode } from "./config.js";
@@ -485,18 +485,32 @@ export async function verify(idOrPrefix) {
485
485
  return { id, ok: false, manifest: "damaged", message: "The manifest is damaged or not one of Tiresias's: this snapshot cannot be trusted." };
486
486
  const idMatches = m.id === id && snapshotId(m) === id;
487
487
  let signature = "bad";
488
+ let retiredAt;
489
+ const sig = Buffer.from(m.sig, "base64url");
490
+ const sigOk = sig.length === 64 && sig.toString("base64url") === m.sig;
488
491
  try {
489
492
  const keys = readSlipKey();
490
493
  if (!keys)
491
494
  signature = "no_key";
492
- else {
493
- const sig = Buffer.from(m.sig, "base64url");
494
- signature = sig.length === 64 && sig.toString("base64url") === m.sig && edVerify(null, signedBytes(m), keys.pub, sig) ? "ok" : "bad";
495
- }
495
+ else
496
+ signature = sigOk && edVerify(null, signedBytes(m), keys.pub, sig) ? "ok" : "bad";
496
497
  }
497
498
  catch {
498
499
  signature = "no_key";
499
500
  }
501
+ // v1.1: a snapshot signed before `keys rotate --slips` is checked against the retired public halves.
502
+ if (signature !== "ok" && sigOk) {
503
+ try {
504
+ const hit = retiredSlipKeys().find((k) => edVerify(null, signedBytes(m), k.pub, sig));
505
+ if (hit) {
506
+ signature = "retired_key";
507
+ retiredAt = hit.retired_at;
508
+ }
509
+ }
510
+ catch {
511
+ // the retired list cannot be read: the result stays as it was
512
+ }
513
+ }
500
514
  const parts = new Map();
501
515
  const files = m.files.map((f) => {
502
516
  const b = readFileChecked(path.join(dir, f.name), MAX_PART);
@@ -518,7 +532,7 @@ export async function verify(idOrPrefix) {
518
532
  // (Codex v0.8 round 1: a planted manifest must not choose work for the reader).
519
533
  let texts = null;
520
534
  let why;
521
- if (m.receipts.length && (!idMatches || signature !== "ok" || !filesOk))
535
+ if (m.receipts.length && (!idMatches || !(signature === "ok" || signature === "retired_key") || !filesOk))
522
536
  why = "not_authentic";
523
537
  else if (m.receipts.length && m.files.length) {
524
538
  try {
@@ -540,7 +554,8 @@ export async function verify(idOrPrefix) {
540
554
  quote: (texts ? (texts.some((t) => r.quote.length <= t.length && t.includes(r.quote)) ? "found" : "not_found") : "not_checked"),
541
555
  }));
542
556
  const quotesOk = receipts.every((r) => r.snapshot_matches && r.quote === "found");
543
- const ok = idMatches && signature === "ok" && filesOk && !unreadable && extra === 0 && quotesOk;
557
+ const signed = signature === "ok" || signature === "retired_key";
558
+ const ok = idMatches && signed && filesOk && !unreadable && extra === 0 && quotesOk;
544
559
  const reader = m.parser === PARSER_VERSION ? "same" : "different";
545
560
  const problems = [
546
561
  !idMatches && "the id does not match the manifest",
@@ -554,9 +569,9 @@ export async function verify(idOrPrefix) {
554
569
  receipts.some((r) => r.quote === "not_checked") && "some quotes could not be checked",
555
570
  ].filter((x) => !!x);
556
571
  return {
557
- id, ok, manifest: "ok", id_matches: idMatches, signature, files, ...(extra ? { extra_files: extra } : {}), ...(unreadable ? { folder: "unreadable" } : {}), receipts, reader, ...(why ? { quotes_unchecked_reason: why } : {}),
572
+ id, ok, manifest: "ok", id_matches: idMatches, signature, ...(retiredAt ? { retired_key_at: retiredAt } : {}), files, ...(extra ? { extra_files: extra } : {}), ...(unreadable ? { folder: "unreadable" } : {}), receipts, reader, ...(why ? { quotes_unchecked_reason: why } : {}),
558
573
  message: ok
559
- ? `Verified: the signature, the id and every saved file match, and all ${receipts.length} quotes are in the saved bytes.`
574
+ ? `Verified: the signature, the id and every saved file match, and all ${receipts.length} quotes are in the saved bytes.${retiredAt ? ` The signature is by this profile's earlier slip key, retired on ${retiredAt} (tiresias keys rotate --slips); if that key had leaked, someone holding it could also have made this snapshot.` : ""}`
560
575
  : `Not verified: ${problems.join("; ")}.`,
561
576
  };
562
577
  }
package/dist/savedlock.js CHANGED
@@ -1,26 +1,101 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // Saves run in killable MCP servers. Publish a nonempty lock directory atomically, so even a kill during
3
- // acquisition leaves a named owner. Only ESRCH permits recovery; a live owner is never timed out.
3
+ // acquisition leaves a named owner. Recovery needs proof the owner is gone: ESRCH, or (v1.1, Codex K.9) the pid now
4
+ // belongs to a different process than the one whose start stamp the lock recorded. A live owner is never timed out.
4
5
  // Recovery removes the dead owner's unique entry, then rmdir: a delayed recoverer cannot remove a new,
5
6
  // nonempty lock. Config commands keep ownedlock.ts's deliberately manual recovery policy.
7
+ import { execFileSync } from "node:child_process";
6
8
  import { randomBytes } from "node:crypto";
7
9
  import fs from "node:fs";
10
+ import os from "node:os";
8
11
  import path from "node:path";
9
12
  import { NOFOLLOW, NONBLOCK } from "./store.js";
10
13
  const TRY_MS = 1_000;
11
14
  const OWNER_RE = /^[1-9][0-9]*-[0-9a-f]{24}$/;
12
15
  const sleepSync = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
13
- function dead(pid) {
16
+ // A process's start stamp, as the kernel recorded it, or null. Format: "<scope>|<value>".
17
+ // - Linux: scope = boot id + pid namespace + time namespace (ours), value = start time in clock ticks since boot
18
+ // (/proc/<pid>/stat field 22).
19
+ // - Elsewhere: scope = "ps" + host name, value = ps's lstart, printed with TZ=UTC and LC_ALL=C so every reader
20
+ // prints it the same way (Codex r4: time zone and locale change the text).
21
+ // The value stays the same for the life of a process whatever the wall clock does, and differs for a later
22
+ // process given the same pid.
23
+ function scope() {
24
+ try {
25
+ if (process.platform === "linux") {
26
+ // Codex r5: stat's start time includes the READER's time-namespace offset, so the time namespace is part of
27
+ // the scope too. Kernels without time namespaces have no such link: one shared clock.
28
+ let timeNs = "no-time-ns";
29
+ try {
30
+ timeNs = fs.readlinkSync("/proc/self/ns/time");
31
+ }
32
+ catch {
33
+ // kept as one shared clock
34
+ }
35
+ return `linux:${fs.readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim()}:${fs.readlinkSync("/proc/self/ns/pid")}:${timeNs}`;
36
+ }
37
+ return `ps:${os.hostname()}`;
38
+ }
39
+ catch {
40
+ return null;
41
+ }
42
+ }
43
+ function startStamp(pid) {
44
+ const sc = scope();
45
+ if (!sc)
46
+ return null;
47
+ try {
48
+ if (process.platform === "linux") {
49
+ // Only meaningful when this /proc numbers pids the way we do (Codex r6: a procfs mounted for another pid
50
+ // namespace can map our number to someone else) and that pid lives in OUR pid namespace.
51
+ if (fs.readlinkSync("/proc/self") !== String(process.pid))
52
+ return null;
53
+ if (fs.readlinkSync(`/proc/${pid}/ns/pid`) !== fs.readlinkSync("/proc/self/ns/pid"))
54
+ return null;
55
+ const stat = fs.readFileSync(`/proc/${pid}/stat`, "utf8");
56
+ const ticks = stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
57
+ return ticks && /^\d+$/.test(ticks) ? `${sc}|${ticks}` : null;
58
+ }
59
+ const env = { PATH: process.env.PATH ?? "/usr/bin:/bin", TZ: "UTC", LC_ALL: "C" };
60
+ const t = execFileSync("ps", ["-o", "lstart=", "-p", String(pid)], { encoding: "utf8", timeout: 2_000, env, stdio: ["ignore", "pipe", "ignore"] }).trim();
61
+ return t ? `${sc}|${t}` : null;
62
+ }
63
+ catch {
64
+ return null;
65
+ }
66
+ }
67
+ let ownStamp;
68
+ const myStamp = () => (ownStamp === undefined ? (ownStamp = startStamp(process.pid)) : ownStamp);
69
+ // The owner is gone if its pid no longer exists (ESRCH). Codex K.9: a pid can be reused, so when the pid is alive
70
+ // and the lock recorded its owner's start stamp, a different stamp on that pid now means a different process,
71
+ // but only when the lock was taken in the same scope (same machine and boot, same pid namespace) as ours; a lock
72
+ // from another container or host is never judged this way. The wall clock is never used (Codex r3). Anything
73
+ // unclear, including an old lock with no stamp or a stamp that cannot be read, counts as alive.
74
+ export function dead(pid, recordedStamp) {
14
75
  if (!Number.isSafeInteger(pid) || pid <= 0)
15
76
  return false;
16
77
  try {
17
78
  process.kill(pid, 0);
18
- return false;
19
79
  }
20
80
  catch (e) {
21
81
  return e.code === "ESRCH";
22
82
  }
83
+ if (!recordedStamp)
84
+ return false;
85
+ const sep = recordedStamp.lastIndexOf("|");
86
+ if (sep < 0)
87
+ return false;
88
+ const now = startStamp(pid);
89
+ if (now === null)
90
+ return false;
91
+ const nowSep = now.lastIndexOf("|");
92
+ // Both stamps must come from the same scope, checked on the stamp just read (Codex r6: a host name change
93
+ // between two samples must not turn a scope change into a "different process").
94
+ if (now.slice(0, nowSep) !== recordedStamp.slice(0, sep))
95
+ return false;
96
+ return now.slice(nowSep + 1) !== recordedStamp.slice(sep + 1);
23
97
  }
98
+ export const _startStamp = startStamp; // tests
24
99
  function recover(file) {
25
100
  const l = file + ".lock";
26
101
  try {
@@ -36,7 +111,18 @@ function recover(file) {
36
111
  finally {
37
112
  d.closeSync();
38
113
  }
39
- if (!owner || !dead(Number(owner.split("-")[0])))
114
+ if (!owner)
115
+ return;
116
+ let stamp;
117
+ try {
118
+ const st = fs.lstatSync(path.join(l, owner));
119
+ if (st.size > 0 && st.size <= 256)
120
+ stamp = fs.readFileSync(path.join(l, owner), "utf8").trim() || undefined;
121
+ }
122
+ catch {
123
+ return;
124
+ }
125
+ if (!dead(Number(owner.split("-")[0]), stamp))
40
126
  return;
41
127
  releaseLock(file, owner);
42
128
  }
@@ -66,7 +152,15 @@ export function takeLock(file, tryMs = TRY_MS) {
66
152
  const until = Date.now() + tryMs;
67
153
  try {
68
154
  fs.mkdirSync(tmp, { mode: 0o700 });
69
- fs.closeSync(fs.openSync(path.join(tmp, token), fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | NOFOLLOW, 0o600));
155
+ const ofd = fs.openSync(path.join(tmp, token), fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | NOFOLLOW, 0o600);
156
+ try {
157
+ const stamp = myStamp(); // K.9: who holds this pid, so a later process given the same pid is told apart
158
+ if (stamp)
159
+ fs.writeSync(ofd, stamp + "\n");
160
+ }
161
+ finally {
162
+ fs.closeSync(ofd);
163
+ }
70
164
  for (;;) {
71
165
  try {
72
166
  fs.renameSync(tmp, l); // replaces an empty recovered directory, never a live nonempty one
package/dist/settings.js CHANGED
@@ -10,7 +10,7 @@
10
10
  // Risk key is shown only as set or not set.
11
11
  import os from "node:os";
12
12
  import path from "node:path";
13
- import { ConfigError, DEFAULT_ANCHORING, DEFAULT_CALENDARS, DEFAULT_DOORS, DEFAULT_LIMITS, DEFAULT_SAVING, parseAnchoring, parseCalendars, KNOWN_KEYS, parseAgentStyle, parseDoors, parseKeyFile, parseSafeBrowsing, parseSaving, parseScanner, parseSignatureAgent, parseTranslator, readConfigObject, } from "./config.js";
13
+ import { parseChoice, ConfigError, DEFAULT_ANCHORING, DEFAULT_CALENDARS, DEFAULT_DOORS, DEFAULT_LIMITS, DEFAULT_SAVING, parseAnchoring, parseCalendars, KNOWN_KEYS, parseAgentStyle, parseDoors, parseGuard, parseKeyFile, parseSafeBrowsing, parseSaving, parseScanner, parseSignatureAgent, parseTranslator, readConfigObject, } from "./config.js";
14
14
  import { defaultKeyFile } from "./safebrowsing.js";
15
15
  import { DEFAULT_RENDER, parseRender } from "./render.js";
16
16
  import { MAX_SPACING_S, MIN_SPACING_S, candidates, loadSites, normalizeSite, parsePortList, parseSiteRule, parseSites } from "./sites.js";
@@ -35,6 +35,10 @@ const onOff = (name) => (s) => {
35
35
  throw new ConfigError(`"${name}" takes on or off.`);
36
36
  };
37
37
  export const DEFS = [
38
+ { name: "get_form_actions", default: "read", description: 'Reading a URL matching a GET form action seen on its source page: "read" reads it normally; "slip" requires a submit_form slip. Rendered scripts may never request the GET form actions on that page.', check: (v) => parseChoice("get_form_actions", v), fromText: (v) => parseChoice("get_form_actions", v) },
39
+ { name: "private_spacing", default: "shared", description: 'Private calls and form previews: "shared" writes origin and times only to share spacing across processes; "none" writes nothing and separate processes do not space these calls against each other.', check: (v) => parseChoice("private_spacing", v), fromText: (v) => parseChoice("private_spacing", v) },
40
+ { name: "hook_secrets", default: "hidden", description: 'Scanner and translator environment: "hidden" removes Tiresias secret variables; "inherit" passes the full owner environment, including those secrets.', check: (v) => parseChoice("hook_secrets", v), fromText: (v) => parseChoice("hook_secrets", v) },
41
+ { name: "text_views", default: "marked", description: 'Text views: "marked" keeps them readable with a marker before web content; "wrapped" wraps the text inside untrusted_content, like JSON. Agents should use JSON output.', check: (v) => parseChoice("text_views", v), fromText: (v) => parseChoice("text_views", v) },
38
42
  { name: "doors", default: DEFAULT_DOORS, description: 'How a first read of a site treats its door checks (llms.txt, MCP, API): "background" returns the page at once and checks them afterwards; "wait" checks them first (slower).', check: parseDoors, fromText: parseDoors },
39
43
  { name: "rendering", default: DEFAULT_RENDER, description: 'Running a page\'s JavaScript (W-10), in the installed Google Chrome, sandboxed and throwaway, with every request it makes going through Tiresias\'s rules: "off" never; "ask" when a read asks for it; "auto" also when a plain read is an empty JavaScript shell. TIRESIAS_RENDERING overrides it.', check: parseRender, fromText: parseRender },
40
44
  { name: "saving", default: DEFAULT_SAVING, description: 'Keeping a signed snapshot of a page a read asks to save (W-28): "off" never; "ask" when a read asks for it (read --save, or save on the MCP read). Snapshots are kept in this profile\'s saved/ folder; see tiresias saved.', check: parseSaving, fromText: parseSaving },
@@ -52,6 +56,8 @@ export const DEFS = [
52
56
  { name: "safe_browsing", default: true, description: "Check every URL against the Phishing.Database list (and Google Web Risk, with a key) before requesting it.", check: parseSafeBrowsing, fromText: onOff("safe_browsing") },
53
57
  { name: "web_risk_key_file", default: null, description: "The file holding WEB_RISK_API_KEY= (a full path). Default for the default profile: ~/.config/tiresias/secrets.env.", check: parseKeyFile, fromText: parseKeyFile },
54
58
  { name: "scanner", default: null, description: "Your own virus checker, run on every high-risk file warning (none is included).", check: parseScanner, howToSet: "Set it with: tiresias scanner set [--timeout 10] [--send-file] -- /full/path/to/program [args...]" },
59
+ { name: "guard", default: null, description: "The meaning check for local model mode (W-38): your own embedding model, reached at an OpenAI-compatible address, compares each passage with a library of known planted instructions (none is included and nothing is sent anywhere until you set it up).", check: (v) => parseGuard(v), howToSet: "Set it with: tiresias guard setup --url http://localhost:1234/v1 --model <embedding model id> (see tiresias guard --help); remove it with: tiresias guard off" },
60
+ { name: "written_by", default: "on", description: 'Local model mode\'s label for who wrote each passage (W-39): "on" gives every passage of a page that carries visitor text (comments, reviews, forum posts, as the page\'s own markup marks them) a written_by saying whether the site or a visitor wrote it; "off" leaves it out. It is a fact about the page, not a warning, and nothing is withheld because of it.', check: (v) => parseChoice("written_by", v), fromText: (v) => parseChoice("written_by", v) },
55
61
  { name: "translator", default: null, description: "Your own translation program, run only when an agent asks a read for a translation; it gets the page's text on standard input and the source and target languages as its last two arguments (none is included).", check: parseTranslator, howToSet: "Set it with: tiresias translator set [--timeout 20] -- /full/path/to/program [args...]" },
56
62
  ];
57
63
  const DEF = new Map(DEFS.map((d) => [d.name, d]));
@@ -84,7 +90,7 @@ const SITE_DEF = new Map(SITE_DEFS.map((d) => [d.name, d]));
84
90
  const ENV = [
85
91
  { name: "TIRESIAS_HOME", default: "~/.tiresias", description: "The store folder (shared by every agent pointed at it)." },
86
92
  { name: "TIRESIAS_PROFILE", default: "default", description: "The profile to use when --profile is not given." },
87
- { name: "TIRESIAS_PRIVATE", default: "off", description: "1 makes the whole session private: nothing about any visit is saved." },
93
+ { name: "TIRESIAS_PRIVATE", default: "off", description: "1 makes the whole session private: no page records are saved; minimal politeness state still applies." },
88
94
  { name: "TIRESIAS_SAFE_BROWSING", default: "on", description: "0 turns the Safe Browsing check off for the session." },
89
95
  { name: "TIRESIAS_ALLOW_PORTS", default: "none", description: 'More ports to allow on every site, like "8080,9000-9100".' },
90
96
  { name: "TIRESIAS_MAX_BYTES", default: String(5 * 1024 * 1024), description: "The most bytes of a page that are read." },
@@ -96,6 +102,7 @@ const ENV = [
96
102
  { name: "TIRESIAS_RENDERING", default: "not set", description: 'off, ask or auto: overrides the "rendering" setting for the session.' },
97
103
  { name: "TIRESIAS_CHROME", default: "not set", description: "The full path of the Chrome program used to render pages, when it is not in the usual place. Tiresias never downloads a browser." },
98
104
  { name: "TIRESIAS_WEB_RISK_KEY", default: "not set", description: "A Google Web Risk key (shown here only as set or not set).", secret: true },
105
+ { name: "TIRESIAS_GUARD_KEY", default: "not set", description: "A key for the meaning check's embedding endpoint, sent as a Bearer token, read when a call is made and never stored (shown here only as set or not set).", secret: true },
99
106
  ];
100
107
  export const configFile = () => path.join(homeDir(), "config.json");
101
108
  const tilde = (p) => (p.startsWith(os.homedir() + path.sep) ? "~" + p.slice(os.homedir().length) : p);
@@ -353,7 +360,7 @@ export function confirmNow(name, rest, priv, confirm) {
353
360
  if (priv)
354
361
  throw new ConfigError(PRIVATE);
355
362
  if (!name || !isRisky(name))
356
- throw new ConfigError("Usage: tiresias settings confirm <risky setting> [<site>] --confirm \"...\". Risky settings: saving, rendering, translator, scanner, anchoring, anchor_calendars, safe_browsing, and the site settings ports, spacing_seconds, never_visit, hand_off.");
363
+ throw new ConfigError("Usage: tiresias settings confirm <risky setting> [<site>] --confirm \"...\". Risky settings: private_spacing, hook_secrets, saving, rendering, translator, scanner, anchoring, anchor_calendars, safe_browsing, guard, and the site settings ports, spacing_seconds, never_visit, hand_off.");
357
364
  const site = SITE_DEF.has(name) ? siteArgs(name, rest, false).site : undefined;
358
365
  if (!site && rest.length)
359
366
  throw new ConfigError(`Usage: tiresias settings confirm ${name} --confirm "..."`);
package/dist/shelf.js CHANGED
@@ -130,7 +130,7 @@ export function clean(x) {
130
130
  url: c(o.url, MAX_URL_LOG), final_url: c(o.final_url, MAX_URL_LOG),
131
131
  ...str("declared_type", 200), ...str("declared_name", 255),
132
132
  agent: typeof o.agent === "string" ? c(o.agent, 200) : "unknown",
133
- ...(o.source === "provided_by_person" ? { source: "provided_by_person" } : {}),
133
+ ...(o.source === "provided_by_person" || o.source === "provided_by_agent" ? { source: o.source } : {}),
134
134
  };
135
135
  if (cut)
136
136
  r.cut = true;
package/dist/shield.js CHANGED
@@ -1,3 +1,11 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // N-02: injection shield.
3
+ // Web pages can carry text meant for the AI that reads them, not for people:
4
+ // white-on-white text, display:none blocks, comments, "ignore previous
5
+ // instructions". We do three things: keep page content inside
6
+ // untrusted_content, leave hidden text OUT of the readable text, and report
7
+ // what we found in `flags` so the agent and its human can see the attempt.
8
+ import { AIMED } from "./aimed.js";
1
9
  import { EN, otherMatches } from "./shieldphrases.js";
2
10
  import { hiddenText } from "./inspect.js";
3
11
  // v0.7 (W-26): the English list moved to shieldphrases.ts with the twelve other languages.
@@ -54,6 +62,13 @@ export class Shield {
54
62
  // text contains (shieldphrases.ts).
55
63
  for (const o of otherMatches(norm))
56
64
  this.add({ type: "ai_directed_instruction", snippet: snippet(o.text, o.index), detail: `${where}; phrase in ${o.lang}` });
65
+ // v1.2: local mode's wider check, on the same bounded normalized text. add() keeps the cap and
66
+ // drops duplicate snippets when a phrase and a pattern point to the same passage.
67
+ for (const [name, { re }] of Object.entries(AIMED)) {
68
+ const m = re.exec(norm);
69
+ if (m)
70
+ this.add({ type: "ai_directed_instruction", snippet: snippet(norm, m.index), detail: `${where}; pattern ${name}` });
71
+ }
57
72
  }
58
73
  hidden(reason, text) {
59
74
  this.add({ type: "hidden_text", snippet: snippet(text), detail: reason });
package/dist/slips.js CHANGED
@@ -36,7 +36,7 @@ import { SlipError } from "./errors.js";
36
36
  import { PATH_RE, pathAllowed } from "./forms.js";
37
37
  import { readItem, writeItem } from "./itemfiles.js";
38
38
  import * as history from "./history.js";
39
- import { ensureSlipKey, readSlipKey } from "./keys.js";
39
+ import { SLIP_KEY_FILE, ensureSlipKey, readSlipKey, replaceSlipKey } from "./keys.js";
40
40
  import { NOFOLLOW, NONBLOCK, cliSafeId, isPrivate, ownFile, profileName, rmRegular, subDir } from "./store.js";
41
41
  export { SlipError };
42
42
  // The fixed allow-list of actions. v0.4 has exactly one.
@@ -491,6 +491,35 @@ export function revokeAll(priv = false) {
491
491
  removeLooseUse(d, f);
492
492
  return n;
493
493
  }
494
+ // ---- v1.1 workstream 4: rotating the slip key ----
495
+ // A new slip key makes every existing slip fail its signature check, so the rotation revokes them all, cleanly and
496
+ // on the record (revoked.jsonl), before the key is replaced, and once more after it (a slip granted meanwhile was
497
+ // signed by the old key). Saved pages are not touched: the old key's public half is kept for `saved verify`.
498
+ // Receipts never reference the slip key (a receipt names a snapshot by its SHA-256 id). An irreversible action, so
499
+ // it always needs its phrase, even with confirmations for risky settings turned off; the CLI also asks a person at
500
+ // a terminal to type "rotate slip key", like `slip revoke --all`. Written to history (tool "keys").
501
+ export const ROTATE_SLIP_PHRASE = "YES, ROTATE THE SLIP KEY";
502
+ export function checkRotatePhrase(confirm) {
503
+ if (confirm !== ROTATE_SLIP_PHRASE)
504
+ throw new SlipError(`Rotating the slip key revokes every permission slip of this profile, and saved pages signed before it are then checked against the old key's public half. It needs the exact confirmation ${JSON.stringify(ROTATE_SLIP_PHRASE)}. Run it again with: tiresias keys rotate --slips --confirm '${ROTATE_SLIP_PHRASE}' (type it exactly, in capitals; it is recorded in history). Nothing was changed.`);
505
+ }
506
+ export function rotateSlipKey(confirm, priv = false, now = Date.now()) {
507
+ if (priv || isPrivate())
508
+ throw new SlipError("Private mode: nothing is written, so the slip key is not rotated.");
509
+ checkRotatePhrase(confirm);
510
+ const d = subDir("keys", false);
511
+ if (!d || !fs.lstatSync(path.join(d, SLIP_KEY_FILE), { throwIfNoEntry: false }))
512
+ throw new SlipError("There is no slip key yet, so there is nothing to rotate. One is made by the first slip grant or saved page.");
513
+ // The slips are revoked inside replaceSlipKey, after every refusal (synced folder, another rotation, a full retired
514
+ // list), so a refused rotation never destroys them (Codex K.4).
515
+ let revoked = 0;
516
+ const r = replaceSlipKey(now, () => {
517
+ revoked = revokeAll(priv);
518
+ });
519
+ revoked += revokeAll(priv);
520
+ history.record({ time: new Date(now).toISOString(), tool: "keys", url: "", agent: "cli", status: "ok", door: "none", event: "slip_key_rotated", revoked, by: process.stdin.isTTY === true ? "terminal" : "not_terminal" });
521
+ return { revoked, retired: r.retired };
522
+ }
494
523
  // A use file is deleted on its own only when its slip file is confirmed gone at that moment. A slip
495
524
  // granted (and claimed) after any listing was made still has its <id>.json, so its uses are never
496
525
  // touched (Codex round 49: a final sweep deleted a new slip's use and gave the use back). Uses only
@@ -687,3 +716,16 @@ export function claimSlip(action, url, label, opts = {}) {
687
716
  }
688
717
  return no("no_slip");
689
718
  }
719
+ // A claimed use stays spent, but may leave the queue only while its slip still permits this target.
720
+ export function claimedStillValid(claim, action, url) {
721
+ const t = target(url);
722
+ const d = subDir("slips", false);
723
+ if (!d || !t || !pathAllowed(url) || !PATH_RE.test(t.pathname))
724
+ return false;
725
+ const keys = readSlipKey();
726
+ const profile = profileName();
727
+ const s = readOne(d, claim.slip_id, keys, profile);
728
+ return !!s && s !== "damaged" && s.action === action && s.site === t.origin && pathCovers(s.path, t.pathname)
729
+ && Date.parse(s.expires_at) > Date.now() && claim.use >= 1 && claim.use <= s.uses
730
+ && useVerifies(d, s.id, claim.use, keys, profile);
731
+ }