@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/dist/receipts.js CHANGED
@@ -23,13 +23,18 @@ export function bound(r) {
23
23
  // sent) or "file" (a file warning). Older lines have neither: a line with `sent: "form"` is a form, one with
24
24
  // `file: "warning"` a file (whose `kind` field there was the FILE's kind), anything else a quote.
25
25
  export const RECORD_VERSION = 1;
26
+ // Returns how many of the logged copies were cut (0: the log holds every receipt whole).
26
27
  export function record(receipts) {
27
28
  const now = Date.now();
28
29
  const recorded_at = new Date(now).toISOString();
30
+ let cut = 0;
29
31
  for (const r of receipts) {
30
32
  const row = bound({ v: RECORD_VERSION, kind: "quote", ...r, recorded_at });
33
+ if (row.cut)
34
+ cut++;
31
35
  appendLine(`receipts/${utcDay(now)}.jsonl`, row);
32
36
  }
37
+ return cut;
33
38
  }
34
39
  export async function query(f, scan = {}) {
35
40
  const since = parseSince(f.since);
package/dist/render.js CHANGED
@@ -29,11 +29,13 @@ import { callContext } from "./context.js";
29
29
  import { Busy, Slots } from "./slots.js";
30
30
  import { ConfigError, TiresiasError } from "./errors.js";
31
31
  import { runUntrusted } from "./sandbox.js";
32
+ import { MAX_FORM_ACTIONS, MAX_FORM_ACTION_CHARS, MAX_LIVE_ACTION, RenderActionCache } from "./renderactions.js";
32
33
  import { politeFetch } from "./fetcher.js";
33
34
  import { shutdownSignal } from "./lifetime.js";
34
35
  import { READ_SLACK, fetchCap } from "./safety.js";
35
36
  import { envMayLoosen, inForceConfig } from "./confirm.js";
36
37
  import { LIMITS as INSPECT, VIEWPORT, checkInspection, inspectScript, newMark, wallVerdict } from "./inspect.js";
38
+ import { STRUCTURED_HEADING } from "./reader.js";
37
39
  export const RENDER_MODES = ["off", "ask", "auto"];
38
40
  export const DEFAULT_RENDER = "off";
39
41
  export function parseRender(v) {
@@ -121,9 +123,9 @@ export function findChrome() {
121
123
  return (CHROME_PATHS[process.platform] ?? []).find(runnable) ?? null;
122
124
  }
123
125
  // ---- the empty JavaScript shell test (auto mode) ----
124
- // A page read as HTML whose text is almost nothing and that carries scripts.
125
- export function looksLikeShell(textChars, body) {
126
- return textChars < 200 && /<script\b/i.test(body);
126
+ // v1.2: short link menus can be shells; a substantial unlinked block or a useful list of links is content.
127
+ export function looksLikeShell(parsed, hasScript) {
128
+ return hasScript && parsed.text_chars < 200 && parsed.links.length < 20 && !parsed.sections.some(s => !(s.generated && s.heading === STRUCTURED_HEADING) && s.blocks.some(b => b.text.length >= 80 && b.marks.length === 0));
127
129
  }
128
130
  // ---- process lifetime ----
129
131
  const live = new Map(); // every running Chrome's killer, by process id
@@ -412,8 +414,9 @@ async function renderNow(pageUrl, body, fn) {
412
414
  const chrome = findChrome();
413
415
  if (!chrome)
414
416
  throw new RenderUnavailable();
415
- const forms = await runUntrusted({ op: "forms", body, url: pageUrl }, body.length);
416
- const actions = forms.forms.filter((f) => f.method === "GET" && f.action).map((f) => getActionTarget(new URL(f.action)));
417
+ const forms = await runUntrusted({ op: "form_actions", body, url: pageUrl }, body.length);
418
+ const actionCache = new RenderActionCache();
419
+ const actions = forms.incomplete ? null : actionCache.scan(forms.actions);
417
420
  hookExit();
418
421
  sweepProfiles();
419
422
  const started = Date.now();
@@ -534,7 +537,7 @@ async function renderNow(pageUrl, body, fn) {
534
537
  return await fail("not_get");
535
538
  const target = new URL(url);
536
539
  const actionTarget = getActionTarget(target);
537
- if (forms.omitted || actions.some((a) => getActionTargetsMatch(a, actionTarget)))
540
+ if (actions === null || actions.some((a) => getActionTargetsMatch(a, actionTarget)))
538
541
  return await fail("form_action");
539
542
  if (!TYPES_FETCHED.has(type))
540
543
  return await fail("not_needed");
@@ -544,19 +547,66 @@ async function renderNow(pageUrl, body, fn) {
544
547
  const r = await cmd("Runtime.evaluate", {
545
548
  contextId: world.executionContextId, returnByValue: true, timeout: 1000,
546
549
  expression: `(() => { /* get_form_actions */
547
- const forms = Object.getOwnPropertyDescriptor(Document.prototype, 'forms').get.call(document);
548
- if (forms.length > 20) return null;
549
- const method = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, 'method').get;
550
- const action = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, 'action').get;
550
+ const getter = (proto, name) => Object.getOwnPropertyDescriptor(proto, name).get;
551
+ const forms = getter(Document.prototype, 'forms').call(document);
552
+ const formCount = getter(HTMLCollection.prototype, 'length').call(forms);
553
+ const formAt = HTMLCollection.prototype.item;
554
+ // Native selectors and indexed access avoid named form properties and page wrappers.
555
+ // Include attributes on every element, even controls outside their form and non-controls.
556
+ const nodes = Document.prototype.querySelectorAll.call(document, '[formaction], [formmethod]');
557
+ const nodeCount = getter(NodeList.prototype, 'length').call(nodes);
558
+ if (formCount > ${MAX_FORM_ACTIONS} || nodeCount > ${LIMITS.elements}) return null;
559
+ const nodeAt = NodeList.prototype.item;
560
+ const attr = Element.prototype.getAttribute;
561
+ const localName = getter(Element.prototype, 'localName');
562
+ const namespace = getter(Element.prototype, 'namespaceURI');
563
+ const base = getter(Node.prototype, 'baseURI');
564
+ const page = getter(Document.prototype, 'URL').call(document);
565
+ const method = getter(HTMLFormElement.prototype, 'method');
566
+ const action = getter(HTMLFormElement.prototype, 'action');
567
+ const buttonAction = getter(HTMLButtonElement.prototype, 'formAction');
568
+ const buttonMethod = getter(HTMLButtonElement.prototype, 'formMethod');
569
+ const inputAction = getter(HTMLInputElement.prototype, 'formAction');
570
+ const inputMethod = getter(HTMLInputElement.prototype, 'formMethod');
551
571
  const out = [];
552
- for (let i = 0; i < forms.length; i++) if (method.call(forms[i]).toLowerCase() === 'get') out.push(action.call(forms[i]));
572
+ let total = 0, count = formCount, getOverride = false;
573
+ const add = a => {
574
+ if (typeof a !== 'string' || a.length > ${MAX_LIVE_ACTION} || a.includes('\\0')) throw new Error('Unreadable action');
575
+ total += a.length;
576
+ if (total > ${MAX_FORM_ACTION_CHARS}) throw new Error('Action budget');
577
+ out.push(a);
578
+ };
579
+ for (let i = 0; i < nodeCount; i++) {
580
+ const n = nodeAt.call(nodes, i);
581
+ const name = namespace.call(n) === 'http://www.w3.org/1999/xhtml' ? localName.call(n) : '';
582
+ const actionGetter = name === 'button' ? buttonAction : name === 'input' ? inputAction : null;
583
+ const methodGetter = name === 'button' ? buttonMethod : name === 'input' ? inputMethod : null;
584
+ const fm = attr.call(n, 'formmethod');
585
+ if (fm !== null) {
586
+ const m = methodGetter ? methodGetter.call(n) : fm;
587
+ if (typeof m !== 'string') return null;
588
+ if (m.toLowerCase() !== 'post' && m.toLowerCase() !== 'dialog') getOverride = true;
589
+ }
590
+ const fa = attr.call(n, 'formaction');
591
+ if (fa !== null) {
592
+ if (++count > ${MAX_FORM_ACTIONS} || typeof fa !== 'string' || fa.length > ${MAX_LIVE_ACTION} || fa.includes('\\0')) return null;
593
+ // Non-controls have no formAction getter; apply the same URL rule ourselves.
594
+ const a = actionGetter ? actionGetter.call(n) : fa === '' ? page : new URL(fa, base.call(n)).href;
595
+ add(a);
596
+ }
597
+ }
598
+ for (let i = 0; i < formCount; i++) {
599
+ const f = formAt.call(forms, i);
600
+ const m = method.call(f);
601
+ if (typeof m !== 'string') return null;
602
+ if (!getOverride && (m.toLowerCase() === 'post' || m.toLowerCase() === 'dialog')) continue;
603
+ add(action.call(f));
604
+ }
553
605
  return out;
554
606
  })()`,
555
607
  }, pageSession);
556
- const live = r.result?.value;
557
- if (!Array.isArray(live) || live.length > 20 || live.some((a) => typeof a !== "string" || a.length > 8192))
558
- return await fail("form_action");
559
- if (live.some((a) => { const u = new URL(a, pageUrl); return getActionTargetsMatch(getActionTarget(u), actionTarget); }))
608
+ const live = actionCache.scan(r.result?.value);
609
+ if (live === null || live.some((a) => getActionTargetsMatch(a, actionTarget)))
560
610
  return await fail("form_action");
561
611
  }
562
612
  catch {
@@ -0,0 +1,69 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { getActionTarget } from "./getactions.js";
3
+ import { MAX_FORM_ACTIONS, MAX_FORM_ACTION_CHARS, MAX_FORM_BASES } from "./types.js";
4
+ // The limits live in types.ts so the page reader (forms.ts, run in the worker) does not load this
5
+ // module and, through it, the whole request path.
6
+ export { MAX_FORM_ACTIONS, MAX_FORM_ACTION_CHARS, MAX_FORM_BASES };
7
+ // Collectors cap source actions. The static union can emit one target per source
8
+ // for the page URL and each web base; deduplication can only reduce this bound.
9
+ export const MAX_FORM_ACTION_TARGETS = MAX_FORM_ACTIONS * (MAX_FORM_BASES + 1);
10
+ export const MAX_LIVE_ACTION = 8192;
11
+ // null means a valid non-network action. Invalid, credentialed and oversized actions
12
+ // throw instead, including on non-web schemes, so callers fail closed.
13
+ export function networkFormAction(raw, base, max) {
14
+ if (raw.length > max)
15
+ throw new Error("Oversized form action");
16
+ const u = new URL(raw, base);
17
+ if (u.href.length > max || u.username || u.password)
18
+ throw new Error("Unsafe form action");
19
+ return u.protocol === "http:" || u.protocol === "https:" ? u : null;
20
+ }
21
+ // Owned by one render, shared by its static scan and all live scans. FIFO eviction
22
+ // bounds both keys and values by entry count and source characters. A complete scan
23
+ // of live actions fits in the cache. Larger static scans may evict entries, but
24
+ // retain every target in the scan's separate result set. Later scans reuse
25
+ // retained entries and safely recompute evicted ones.
26
+ export class RenderActionCache {
27
+ entries = new Map();
28
+ chars = 0;
29
+ scan(input) {
30
+ if (!Array.isArray(input) || input.length > MAX_FORM_ACTION_TARGETS)
31
+ return null;
32
+ let total = 0;
33
+ // Static input is already deduplicated, web-only and fragment-free: its
34
+ // resolved lengths cannot exceed the collector's max(raw, resolved) charges.
35
+ for (const a of input) {
36
+ if (typeof a !== "string" || a.length > MAX_LIVE_ACTION)
37
+ return null;
38
+ total += a.length;
39
+ if (total > MAX_FORM_ACTION_CHARS)
40
+ return null;
41
+ }
42
+ const targets = new Set();
43
+ try {
44
+ for (const a of new Set(input)) {
45
+ let target = this.entries.get(a);
46
+ if (target === undefined) {
47
+ // Both the static resolver and the native live getter return absolute
48
+ // URLs. A relative getter value signals failed resolution (for example
49
+ // under an opaque base); do not silently resolve it against the page.
50
+ const u = networkFormAction(a, undefined, MAX_LIVE_ACTION);
51
+ target = u ? getActionTarget(u) : null;
52
+ while (this.entries.size >= MAX_FORM_ACTIONS || this.chars + a.length > MAX_FORM_ACTION_CHARS) {
53
+ const first = this.entries.keys().next().value;
54
+ this.entries.delete(first);
55
+ this.chars -= first.length;
56
+ }
57
+ this.entries.set(a, target);
58
+ this.chars += a.length;
59
+ }
60
+ if (target !== null)
61
+ targets.add(target);
62
+ }
63
+ return [...targets];
64
+ }
65
+ catch {
66
+ return null;
67
+ }
68
+ }
69
+ }
package/dist/rules.js CHANGED
@@ -253,6 +253,10 @@ async function fetchRobots(origin) {
253
253
  let reserved = budget ? ROBOTS_COST : 0;
254
254
  let charged = reserved; // a failure is charged in full (bytes may have arrived)
255
255
  const turns = new Turns(); // robots.txt holds its site's turn until read AND parsed, its delay noted (rounds 74, 86)
256
+ const holder = callContext.getStore()?.robotsPasses;
257
+ // Per FETCH, not per call: redirects and a 304 retry invalidate this fetch's pass; another site's
258
+ // fresh robots fetch in the same call can still pair. Only this fetching async context owns it.
259
+ const visit = { requests: 0 };
256
260
  try {
257
261
  try {
258
262
  const fetchRobots = () => safeFetch(origin + "/robots.txt", {
@@ -281,8 +285,10 @@ async function fetchRobots(origin) {
281
285
  throw new Refused("robots.txt redirected to another site's path, so Tiresias assumes the site says no.");
282
286
  if (cooldownLeft(u.origin) > 0)
283
287
  throw new Refused("The site asked Tiresias to wait (Retry-After). Not calling it again yet.", undefined, cooldownLeft(u.origin), u.href);
288
+ visit.requests++;
289
+ visit.pass = undefined;
284
290
  turns.leaveOthers(u);
285
- await turns.take(u, spacingMs() / 1000, signal); // v0.5.1: robots.txt waits its turn too (v0.6: and a site's own spacing, in the queue)
291
+ await turns.take(u, spacingMs() / 1000, signal, { robots: visit }); // v0.5.1: robots.txt waits its turn too (v0.6: and a site's own spacing, in the queue)
286
292
  },
287
293
  });
288
294
  let res = await fetchRobots();
@@ -320,6 +326,8 @@ async function fetchRobots(origin) {
320
326
  robots = closed("robots.txt returned an unexpected HTTP 304, so Tiresias assumes the site says no.", 60_000);
321
327
  else if (res.status === 206)
322
328
  robots = closed("robots.txt came back partial (HTTP 206), so Tiresias assumes the site says no.", 60_000);
329
+ else if (res.status >= 200 && res.status < 300 && res.truncated)
330
+ robots = closed("robots.txt is larger than 512 KB, too large to apply faithfully, so Tiresias assumes the site says no.", ONE_HOUR);
323
331
  else if (res.status >= 200 && res.status < 300 && (res.bytes !== undefined || res.file !== undefined))
324
332
  // v0.9 hardening (Codex round 2b, HIGH): a robots.txt the fetcher took for a PDF or a file comes back with no
325
333
  // text, which would parse as "no rules". What Tiresias cannot read as text, it takes as "the site says no".
@@ -338,7 +346,9 @@ async function fetchRobots(origin) {
338
346
  // The cooldown itself was recorded when the headers arrived (onHeaders above).
339
347
  const ra = res.headers.get("retry-after") ?? undefined;
340
348
  const secs = res.status === 429 || res.status === 503 ? cooldownSeconds(res.status, ra ?? null) : undefined;
341
- robots = closed(`robots.txt returned HTTP ${res.status}, so Tiresias assumes the site says no.`, 60_000, { retryAfter: ra, retrySeconds: secs });
349
+ // A 429 or 503 is the site asking for a wait, and the reply says so: "assumes the site says no" read as a
350
+ // refusal for good, and a caller gave up on a page it could have read a minute later (field list, 2026-11-14).
351
+ robots = closed(secs !== undefined ? `robots.txt returned HTTP ${res.status}: the site asked Tiresias to wait, so nothing on it is read yet. This is a wait, not a no. Ask again in ${secs} seconds.` : `robots.txt returned HTTP ${res.status}, so Tiresias assumes the site says no.`, 60_000, { retryAfter: ra, retrySeconds: secs });
342
352
  }
343
353
  else
344
354
  robots = { mode: "missing", rules: [], crawlDelay: 0, sitemaps: [], expires: Date.now() + ONE_HOUR };
@@ -363,6 +373,8 @@ async function fetchRobots(origin) {
363
373
  }
364
374
  finally {
365
375
  turns.giveBack();
376
+ if (visit.requests === 1 && visit.pass)
377
+ holder?.pending.set(visit.pass.origin, visit.pass);
366
378
  if (budget && reserved)
367
379
  budget.release(reserved, charged);
368
380
  }
package/dist/safety.js CHANGED
@@ -414,10 +414,12 @@ export function decoderFor(encoding) {
414
414
  // only the first bytes are kept until the decision, then nothing but the running hash (and the last 512
415
415
  // bytes, for a disk image's trailer). With no `files` option (or a status that is not a success) the body
416
416
  // is kept as a page whatever it is, as before v0.5.
417
- 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) {
418
420
  let chosen;
419
421
  try {
420
- chosen = decoderFor(msg.headers["content-encoding"]);
422
+ chosen = noBody ? null : decoderFor(msg.headers["content-encoding"]);
421
423
  }
422
424
  catch (e) {
423
425
  msg.destroy();
@@ -921,7 +923,7 @@ export async function safeFetch(rawUrl, opts = {}) {
921
923
  }
922
924
  let read;
923
925
  try {
924
- 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);
925
927
  }
926
928
  catch (e) {
927
929
  if (e instanceof FetchError && e.code === "too_large" && mimeOf(ct) === "application/pdf") {
@@ -933,7 +935,7 @@ export async function safeFetch(rawUrl, opts = {}) {
933
935
  if ("file" in read) {
934
936
  if (Number.isFinite(cl))
935
937
  read.file.declared_size = String(cl);
936
- 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 };
937
939
  }
938
940
  const { page: buf, truncated, verdict } = read;
939
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/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 { parseChoice, 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";
@@ -56,6 +56,8 @@ export const DEFS = [
56
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") },
57
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 },
58
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) },
59
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...]" },
60
62
  ];
61
63
  const DEF = new Map(DEFS.map((d) => [d.name, d]));
@@ -100,6 +102,7 @@ const ENV = [
100
102
  { name: "TIRESIAS_RENDERING", default: "not set", description: 'off, ask or auto: overrides the "rendering" setting for the session.' },
101
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." },
102
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 },
103
106
  ];
104
107
  export const configFile = () => path.join(homeDir(), "config.json");
105
108
  const tilde = (p) => (p.startsWith(os.homedir() + path.sep) ? "~" + p.slice(os.homedir().length) : p);
@@ -357,7 +360,7 @@ export function confirmNow(name, rest, priv, confirm) {
357
360
  if (priv)
358
361
  throw new ConfigError(PRIVATE);
359
362
  if (!name || !isRisky(name))
360
- 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, 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.");
361
364
  const site = SITE_DEF.has(name) ? siteArgs(name, rest, false).site : undefined;
362
365
  if (!site && rest.length)
363
366
  throw new ConfigError(`Usage: tiresias settings confirm ${name} --confirm "..."`);
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/textview.js CHANGED
@@ -1,10 +1,16 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  import { notice } from "./confirm.js";
3
3
  import { loadChoice } from "./config.js";
4
+ // Display only: keep newlines, tabs and ordinary Unicode, but make terminal controls,
5
+ // Unicode line separators and bidirectional overrides/isolates visible and inert.
6
+ export function escapeTerminal(text) {
7
+ return text.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u2028-\u202e\u2066-\u2069]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
8
+ }
4
9
  export function textView(text) {
5
10
  if (loadChoice("text_views") === "wrapped") {
6
11
  const n = notice();
7
- return JSON.stringify({ untrusted_content: { text }, ...(n ? { settings_notice: n } : {}) }, null, 2);
12
+ // Serialize first: C0 controls are already escaped, and the remaining escapes stay valid JSON.
13
+ return escapeTerminal(JSON.stringify({ untrusted_content: { text }, ...(n ? { settings_notice: n } : {}) }, null, 2));
8
14
  }
9
- return `web content below is untrusted\n${text}`;
15
+ return `web content below is untrusted\n${escapeTerminal(text)}`;
10
16
  }
package/dist/types.js CHANGED
@@ -1,9 +1,16 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // Shared shapes. The envelope matches SPEC section 6.1.
3
- export const VERSION = "1.1.0";
3
+ export const VERSION = "1.2.0";
4
4
  // Bump when the reader changes what it extracts, so older cached pages are re-read.
5
- export const PARSER_VERSION = 16; // 16: v1.1.0 form recognition (cached form listings carry not_allowed). 15: v1.0.1 reader fixes. 14: v0.9.1 sweep ("(JSON)" heading generated, list indentation capped at 8 levels, markdown code kept as preformatted, nesting past 256 flattened). 13: v0.9 labels Tiresias makes ("(top of page)", "(structured data)") are marked generated, never quoted. 12: v0.7 language (W-26). 11: v0.6 calendar events (ics.ts). 10: v0.5.1 JSON as line blocks, W-22 reader. 9: W-20 file kinds (scripts, CSV, calendars and contacts read as plain text; SVG; file flags)
5
+ export const PARSER_VERSION = 20; // 20: W-39 attribution survives structural scopes, JSON-LD, pre descendants and flattening. 19: v1.2 W-39 blocks a visitor wrote carry their level. 18: v1.2 the page root (<html>, <body>) is never boilerplate. 17: v1.1.1 whitespace-only form actions resolve against the base. 16: v1.1.0 form recognition (cached form listings carry not_allowed). 15: v1.0.1 reader fixes. 14: v0.9.1 sweep ("(JSON)" heading generated, list indentation capped at 8 levels, markdown code kept as preformatted, nesting past 256 flattened). 13: v0.9 labels Tiresias makes ("(top of page)", "(structured data)") are marked generated, never quoted. 12: v0.7 language (W-26). 11: v0.6 calendar events (ics.ts). 10: v0.5.1 JSON as line blocks, W-22 reader. 9: W-20 file kinds (scripts, CSV, calendars and contacts read as plain text; SVG; file flags)
6
6
  export const MAX_URL = 2048; // longer URLs are omitted (and counted), never shortened;
7
+ // The render guard's scan of a page's form actions (forms.ts for the HTML, renderactions.ts for the live page).
8
+ export const MAX_FORM_ACTIONS = 1000;
9
+ export const MAX_FORM_BASES = 16; // distinct http(s) <base href> candidates in the static scan
10
+ // 1,000 short shop actions (for example https://shop.example/cart/add, 29 characters)
11
+ // fit comfortably. This is below the old live bound of 20 * 8,192 characters and
12
+ // close to the old static bound of 20 * 2,048. Count repeats before deduplicating.
13
+ export const MAX_FORM_ACTION_CHARS = 65_536;
7
14
  // Points at Raibit's page on raibit.ai, which links to the GitHub repo once it is public; it stays (Travis,
8
15
  // SPEC section 9, 2026-11-01).
9
16
  export const USER_AGENT = `Tiresias/${VERSION} (+https://raibit.ai/tiresias/)`;
package/dist/work.js CHANGED
@@ -3,6 +3,8 @@
3
3
  // a worker thread (worker.ts) when the input is big, so a hostile page that
4
4
  // makes one of them slow cannot stall the main thread: the main thread just
5
5
  // terminates the worker when the time budget runs out (sandbox.ts).
6
+ import { parseDocument } from "./dom.js";
7
+ import { extractFormActions } from "./forms.js";
6
8
  import { PdfError } from "./errors.js";
7
9
  import { ComplexityError, parseHtml, parseJsonText, parseMarkdown, parsePlain, parseSvg, topPassages } from "./reader.js";
8
10
  import { diffSections } from "./diff.js";
@@ -40,6 +42,10 @@ function handleJob(job) {
40
42
  : null;
41
43
  return { result: { parsed, wall } };
42
44
  }
45
+ case "form_actions": {
46
+ const tree = parseDocument(job.body);
47
+ return { result: tree.flattened ? { actions: [], incomplete: true } : extractFormActions(tree.doc, job.url) };
48
+ }
43
49
  case "forms": {
44
50
  const keep = {};
45
51
  const parsed = parseHtml(job.body, job.url, keep);