@raibitsi/tiresias 1.0.0 → 1.1.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 +199 -0
- package/README.md +50 -27
- package/dist/background.js +6 -3
- package/dist/browsecli.js +4 -3
- package/dist/cdp.js +22 -1
- package/dist/cli.js +82 -29
- package/dist/config.js +32 -26
- package/dist/confirm.js +16 -7
- package/dist/cooldown.js +65 -34
- package/dist/dailylog.js +11 -5
- package/dist/engine.js +5 -4
- package/dist/envelope.js +20 -2
- package/dist/fetcher.js +5 -0
- package/dist/filereply.js +7 -1
- package/dist/files.js +4 -4
- package/dist/formflow.js +21 -3
- package/dist/forms.js +257 -34
- package/dist/getactions.js +99 -0
- package/dist/history.js +8 -5
- package/dist/hook.js +2 -0
- package/dist/hosts.js +15 -13
- package/dist/inside.js +2 -2
- package/dist/inspect.js +4 -1
- package/dist/keys.js +420 -18
- package/dist/mcp.js +10 -10
- 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 +25 -8
- package/dist/profiles.js +3 -3
- package/dist/queue.js +15 -7
- package/dist/reader.js +43 -18
- package/dist/receipts.js +2 -2
- package/dist/render.js +103 -24
- package/dist/resume.js +17 -8
- package/dist/rules.js +29 -7
- package/dist/safebrowsing.js +3 -3
- package/dist/safety.js +9 -3
- package/dist/sandbox.js +1 -1
- package/dist/saved.js +108 -60
- package/dist/savedlock.js +208 -0
- package/dist/settings.js +7 -3
- package/dist/shelf.js +1 -1
- package/dist/sites.js +9 -4
- package/dist/slips.js +43 -1
- package/dist/store.js +119 -25
- package/dist/tabs.js +1 -1
- package/dist/textview.js +10 -0
- package/dist/translate.js +22 -2
- package/dist/types.js +2 -2
- package/dist/watchflow.js +1 -2
- package/dist/work.js +4 -2
- package/package.json +2 -1
package/dist/store.js
CHANGED
|
@@ -8,7 +8,8 @@ import fs from "node:fs";
|
|
|
8
8
|
import os from "node:os";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import readline from "node:readline";
|
|
11
|
-
import {
|
|
11
|
+
import { StringDecoder } from "node:string_decoder";
|
|
12
|
+
import { FetchError, TiresiasError } from "./errors.js";
|
|
12
13
|
export const NOFOLLOW = fs.constants.O_NOFOLLOW ?? 0;
|
|
13
14
|
// Added to every file open: a pipe planted where a file should be then fails at once instead of
|
|
14
15
|
// hanging the process. It changes nothing for ordinary files.
|
|
@@ -410,7 +411,7 @@ export function readJson(file) {
|
|
|
410
411
|
}
|
|
411
412
|
}
|
|
412
413
|
// v0.5.1: private mode fails CLOSED in the store itself, not only at each call site: writeJson and
|
|
413
|
-
// appendLine refuse inside a private call
|
|
414
|
+
// appendLine refuse inside a private call except for Retry-After. hosts.ts writes only shared politeness state.
|
|
414
415
|
export const PRIVATE_WRITE = "Private mode: Tiresias writes nothing to the store in a private call.";
|
|
415
416
|
export class PrivateWriteError extends TiresiasError {
|
|
416
417
|
kind = "private_write";
|
|
@@ -486,7 +487,68 @@ export function readOwnedFile(file, maxBytes = 1024 * 1024) {
|
|
|
486
487
|
}
|
|
487
488
|
export const randomTmp = (file) => `${file}.${randomBytes(8).toString("hex")}.tmp`;
|
|
488
489
|
export const MAX_LOG_READ = 8 * 1024 * 1024;
|
|
489
|
-
//
|
|
490
|
+
// Replay a fixed snapshot in bounded chunks, then only appended bytes. An old line may still be a
|
|
491
|
+
// site's rule, so start over only when the file is replaced or shrinks. Unreadable fails at the caller.
|
|
492
|
+
export function scanLogSync(name, take, cursor) {
|
|
493
|
+
const h = readBase(scopeOf(name));
|
|
494
|
+
if (!h)
|
|
495
|
+
return;
|
|
496
|
+
const file = path.join(h, name);
|
|
497
|
+
let fd;
|
|
498
|
+
try {
|
|
499
|
+
fd = fs.openSync(file, fs.constants.O_RDONLY | NOFOLLOW | NONBLOCK);
|
|
500
|
+
}
|
|
501
|
+
catch (e) {
|
|
502
|
+
if (e.code === "ENOENT")
|
|
503
|
+
return;
|
|
504
|
+
throw e;
|
|
505
|
+
}
|
|
506
|
+
try {
|
|
507
|
+
ownFile(fd, file);
|
|
508
|
+
const { size, dev, ino } = fs.fstatSync(fd);
|
|
509
|
+
if (!cursor || cursor.dev !== dev || cursor.ino !== ino || size < cursor.offset) {
|
|
510
|
+
cursor = { dev, ino, offset: 0, pending: "", decoder: new StringDecoder("utf8") };
|
|
511
|
+
}
|
|
512
|
+
if (size === cursor.offset)
|
|
513
|
+
return cursor;
|
|
514
|
+
const buf = Buffer.alloc(64 * 1024);
|
|
515
|
+
const decoder = cursor.decoder;
|
|
516
|
+
let pending = cursor.pending;
|
|
517
|
+
const line = (raw) => {
|
|
518
|
+
if (!raw.trim())
|
|
519
|
+
return;
|
|
520
|
+
let entry;
|
|
521
|
+
try {
|
|
522
|
+
entry = JSON.parse(raw);
|
|
523
|
+
}
|
|
524
|
+
catch {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
take(entry);
|
|
528
|
+
};
|
|
529
|
+
for (let offset = cursor.offset; offset < size;) {
|
|
530
|
+
const n = fs.readSync(fd, buf, 0, Math.min(buf.length, size - offset), offset);
|
|
531
|
+
if (!n)
|
|
532
|
+
throw new Error("Cooldown log changed while reading.");
|
|
533
|
+
offset += n;
|
|
534
|
+
pending += decoder.write(buf.subarray(0, n));
|
|
535
|
+
let start = 0, end;
|
|
536
|
+
while ((end = pending.indexOf("\n", start)) >= 0) {
|
|
537
|
+
line(pending.slice(start, end));
|
|
538
|
+
start = end + 1;
|
|
539
|
+
}
|
|
540
|
+
pending = pending.slice(start);
|
|
541
|
+
if (pending.length > 64 * 1024)
|
|
542
|
+
throw new Error("Cooldown record is too large.");
|
|
543
|
+
}
|
|
544
|
+
line(pending); // a complete final record counts even without a newline
|
|
545
|
+
return { dev, ino, offset: size, pending, decoder }; // keep a partial record for the next append
|
|
546
|
+
}
|
|
547
|
+
finally {
|
|
548
|
+
fs.closeSync(fd);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
// Read a bounded tail of a JSONL log. Missing, foreign or
|
|
490
552
|
// symlinked files read as empty; damaged and blank lines are skipped.
|
|
491
553
|
// A file over `maxBytes` is read from its LAST maxBytes only, starting at the
|
|
492
554
|
// first full line after the cut, so a runaway log cannot stall a request.
|
|
@@ -591,7 +653,17 @@ export function appendLine(name, obj) {
|
|
|
591
653
|
// Stream the log, never loading it whole. Matching lines are packed into pages
|
|
592
654
|
// of at most `budget` bytes; only the requested page is kept in memory.
|
|
593
655
|
// `names` may be several files (oldest first); they read as one log.
|
|
594
|
-
export async function pageLog(names, keep, page = 1, budget = 40_000) {
|
|
656
|
+
export async function pageLog(names, keep, page = 1, budget = 40_000, scan = {}) {
|
|
657
|
+
const signal = scan.signal ?? callContext.getStore()?.signal;
|
|
658
|
+
const deadline = scan.deadline ?? Date.now() + 60_000;
|
|
659
|
+
let expired = false;
|
|
660
|
+
const check = () => {
|
|
661
|
+
if (signal?.aborted)
|
|
662
|
+
throw new FetchError("The request was cancelled.", "cancelled");
|
|
663
|
+
if (expired || Date.now() >= deadline)
|
|
664
|
+
throw new FetchError("The log scan took too long.", "timeout");
|
|
665
|
+
};
|
|
666
|
+
check();
|
|
595
667
|
const out = { items: [], page, pages: 0, total: 0 };
|
|
596
668
|
const h = readHome();
|
|
597
669
|
if (!h)
|
|
@@ -599,6 +671,7 @@ export async function pageLog(names, keep, page = 1, budget = 40_000) {
|
|
|
599
671
|
let cur = 0;
|
|
600
672
|
let bytes = 0;
|
|
601
673
|
for (const name of Array.isArray(names) ? names : [names]) {
|
|
674
|
+
check();
|
|
602
675
|
const file = path.join(h, name);
|
|
603
676
|
let fd;
|
|
604
677
|
try {
|
|
@@ -607,35 +680,56 @@ export async function pageLog(names, keep, page = 1, budget = 40_000) {
|
|
|
607
680
|
catch {
|
|
608
681
|
continue;
|
|
609
682
|
}
|
|
683
|
+
let size;
|
|
610
684
|
try {
|
|
611
685
|
ownFile(fd, file);
|
|
686
|
+
size = fs.fstatSync(fd).size;
|
|
612
687
|
}
|
|
613
688
|
catch {
|
|
614
689
|
fs.closeSync(fd); // do not leak the descriptor when the file is rejected
|
|
615
690
|
continue;
|
|
616
691
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
692
|
+
if (!size) {
|
|
693
|
+
fs.closeSync(fd);
|
|
694
|
+
continue;
|
|
695
|
+
}
|
|
696
|
+
// A concurrent writer cannot extend this scan beyond the file's starting end offset.
|
|
697
|
+
const input = fs.createReadStream(file, { fd, autoClose: true, end: size - 1 });
|
|
698
|
+
const rl = readline.createInterface({ input, crlfDelay: Infinity });
|
|
699
|
+
const stop = () => { rl.close(); input.destroy(); };
|
|
700
|
+
const timer = setTimeout(() => { expired = true; stop(); }, Math.max(0, deadline - Date.now()));
|
|
701
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
702
|
+
try {
|
|
703
|
+
check();
|
|
704
|
+
for await (const line of rl) {
|
|
705
|
+
check();
|
|
706
|
+
if (!line.trim())
|
|
707
|
+
continue;
|
|
708
|
+
let obj;
|
|
709
|
+
try {
|
|
710
|
+
obj = JSON.parse(line);
|
|
711
|
+
}
|
|
712
|
+
catch {
|
|
713
|
+
continue; // skip a damaged line rather than lose the whole log
|
|
714
|
+
}
|
|
715
|
+
if (!keep(obj))
|
|
716
|
+
continue;
|
|
717
|
+
out.total++;
|
|
718
|
+
const size = Buffer.byteLength(line, "utf8"); // UTF-8 bytes, not characters (Codex round 38)
|
|
719
|
+
if (cur === 0 || bytes + size > budget) {
|
|
720
|
+
cur++;
|
|
721
|
+
bytes = 0;
|
|
722
|
+
}
|
|
723
|
+
bytes += size;
|
|
724
|
+
if (cur === page)
|
|
725
|
+
out.items.push(obj);
|
|
635
726
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
727
|
+
check();
|
|
728
|
+
}
|
|
729
|
+
finally {
|
|
730
|
+
clearTimeout(timer);
|
|
731
|
+
signal?.removeEventListener("abort", stop);
|
|
732
|
+
stop();
|
|
639
733
|
}
|
|
640
734
|
}
|
|
641
735
|
out.pages = cur;
|
package/dist/tabs.js
CHANGED
|
@@ -238,7 +238,7 @@ export function noteReply(store, e) {
|
|
|
238
238
|
return undefined;
|
|
239
239
|
if (e.status !== "ok" && e.status !== "unchanged")
|
|
240
240
|
return undefined;
|
|
241
|
-
if (e.source === "provided_by_person")
|
|
241
|
+
if (e.source === "provided_by_person" || e.source === "provided_by_agent")
|
|
242
242
|
return undefined; // never cached, so nothing to re-show
|
|
243
243
|
const uc = (e.untrusted_content ?? {});
|
|
244
244
|
try {
|
package/dist/textview.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { notice } from "./confirm.js";
|
|
3
|
+
import { loadChoice } from "./config.js";
|
|
4
|
+
export function textView(text) {
|
|
5
|
+
if (loadChoice("text_views") === "wrapped") {
|
|
6
|
+
const n = notice();
|
|
7
|
+
return JSON.stringify({ untrusted_content: { text }, ...(n ? { settings_notice: n } : {}) }, null, 2);
|
|
8
|
+
}
|
|
9
|
+
return `web content below is untrusted\n${text}`;
|
|
10
|
+
}
|
package/dist/translate.js
CHANGED
|
@@ -10,12 +10,15 @@
|
|
|
10
10
|
// at most 32 KB) and at most 64 KB of its standard output kept. That output is the translation: it goes inside
|
|
11
11
|
// untrusted_content.translation, marked as a machine translation by the owner's tool, never as the page's own
|
|
12
12
|
// words. Receipts are built before the hook runs and always quote the ORIGINAL text; the translation is never
|
|
13
|
-
// cached, logged, kept in history or receipts
|
|
13
|
+
// cached, logged, or kept in history or receipts. The shield scans successful output for AI-directed
|
|
14
|
+
// instructions. Findings belong to this reply only, with snippets inside untrusted_content; they never
|
|
15
|
+
// change the original page's cached flags, tabs or saved snapshots.
|
|
14
16
|
import fs from "node:fs";
|
|
15
17
|
import path from "node:path";
|
|
16
18
|
import { ConfigError, loadTranslator, parseTranslator, readConfigObject } from "./config.js";
|
|
17
19
|
import { confirmedWrite, sq } from "./confirm.js";
|
|
18
20
|
import { runHook } from "./hook.js";
|
|
21
|
+
import { Shield } from "./shield.js";
|
|
19
22
|
import { byteLen, jsonBytes } from "./types.js";
|
|
20
23
|
export const MAX_INPUT = 32 * 1024; // bytes of text handed to the hook
|
|
21
24
|
export const MAX_OUTPUT = 64 * 1024; // bytes of its output kept
|
|
@@ -32,6 +35,7 @@ export function parseTarget(v) {
|
|
|
32
35
|
export const NOTE = "A machine translation of the text above, made by the owner's own translation tool. It is not the page's own words and may be wrong; every receipt quotes the original text, never this.";
|
|
33
36
|
const MSG_OK = "A translation by the owner's own tool is in untrusted_content.translation; receipts quote the original text.";
|
|
34
37
|
const MSG_NOT = "No translation was made (see translation.reason). The page is shown in its own language.";
|
|
38
|
+
const TRANSLATION_WHERE = "machine translation";
|
|
35
39
|
// The text a reply shows, as plain lines: the title, then the outline's headings and previews, a section's text,
|
|
36
40
|
// or the passages and their headings.
|
|
37
41
|
export function shownText(uc) {
|
|
@@ -129,6 +133,16 @@ export async function translateReply(e, wanted) {
|
|
|
129
133
|
uc.translation = { text, note: NOTE };
|
|
130
134
|
e.untrusted_content = uc;
|
|
131
135
|
set({ status: "ok", by, from, to, ...cut });
|
|
136
|
+
const shield = new Shield();
|
|
137
|
+
shield.scan(text, TRANSLATION_WHERE);
|
|
138
|
+
const flags = shield.flags.filter((f) => f.type === "ai_directed_instruction");
|
|
139
|
+
if (flags.length) {
|
|
140
|
+
// env() may share the original page's flag array with the cache. Never append to it in place.
|
|
141
|
+
uc.flag_details = [...(uc.flag_details ?? []), ...flags];
|
|
142
|
+
e.flags = [...new Set([...e.flags, ...flags.map((f) => f.type)])];
|
|
143
|
+
if (e.counts)
|
|
144
|
+
e.counts.flags += flags.length; // details, not distinct codes (as in env())
|
|
145
|
+
}
|
|
132
146
|
fitTranslation(e);
|
|
133
147
|
}
|
|
134
148
|
// Saving adds metadata after the hook; check again once that metadata is in place too.
|
|
@@ -136,8 +150,14 @@ export function fitTranslation(e) {
|
|
|
136
150
|
if (e.translation?.status !== "ok" || jsonBytes(e) <= HARD_LIMIT)
|
|
137
151
|
return;
|
|
138
152
|
const uc = e.untrusted_content;
|
|
139
|
-
if (uc)
|
|
153
|
+
if (uc) {
|
|
140
154
|
delete uc.translation;
|
|
155
|
+
// Keep the finding even when its text cannot fit; say exactly which evidence was omitted.
|
|
156
|
+
if (Array.isArray(uc.flag_details))
|
|
157
|
+
uc.flag_details = uc.flag_details.map((f) => f.detail?.startsWith(TRANSLATION_WHERE)
|
|
158
|
+
? { ...f, detail: `${f.detail}; translation omitted from this reply for size` }
|
|
159
|
+
: f);
|
|
160
|
+
}
|
|
141
161
|
e.message = (e.message ?? "").replace(MSG_OK, MSG_NOT);
|
|
142
162
|
e.translation = { ...e.translation, status: "failed", reason: "too_large" };
|
|
143
163
|
}
|
package/dist/types.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// Shared shapes. The envelope matches SPEC section 6.1.
|
|
3
|
-
export const VERSION = "1.
|
|
3
|
+
export const VERSION = "1.1.0";
|
|
4
4
|
// Bump when the reader changes what it extracts, so older cached pages are re-read.
|
|
5
|
-
export const PARSER_VERSION =
|
|
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)
|
|
6
6
|
export const MAX_URL = 2048; // longer URLs are omitted (and counted), never shortened;
|
|
7
7
|
// Points at Raibit's page on raibit.ai, which links to the GitHub repo once it is public; it stays (Travis,
|
|
8
8
|
// SPEC section 9, 2026-11-01).
|
package/dist/watchflow.js
CHANGED
|
@@ -175,7 +175,6 @@ export async function watch(ctx = DEFAULT, page) {
|
|
|
175
175
|
: "No bookmarks are watched. Add one with bookmark add <name> <url> --watch.",
|
|
176
176
|
notice: NOTICE,
|
|
177
177
|
counts,
|
|
178
|
-
attention,
|
|
179
178
|
...(page === undefined ? {} : { page }),
|
|
180
179
|
pages: page === undefined ? 1 : pages,
|
|
181
180
|
untrusted_content: null,
|
|
@@ -185,7 +184,7 @@ export async function watch(ctx = DEFAULT, page) {
|
|
|
185
184
|
const build = () => {
|
|
186
185
|
const rs = rcpts.flat();
|
|
187
186
|
report.counts.receipts = rs.length;
|
|
188
|
-
const uc = { ...(changed.length ? { changed } : {}), ...(rs.length ? { receipts: rs } : {}), ...(attentionUrls.length ? { attention_urls: attentionUrls } : {}) };
|
|
187
|
+
const uc = { ...(attention.length ? { attention } : {}), ...(changed.length ? { changed } : {}), ...(rs.length ? { receipts: rs } : {}), ...(attentionUrls.length ? { attention_urls: attentionUrls } : {}) };
|
|
189
188
|
report.untrusted_content = Object.keys(uc).length ? uc : null;
|
|
190
189
|
};
|
|
191
190
|
build();
|
package/dist/work.js
CHANGED
|
@@ -9,7 +9,7 @@ import { diffSections } from "./diff.js";
|
|
|
9
9
|
import { languageOf } from "./lang.js";
|
|
10
10
|
import { inspect } from "./inside.js";
|
|
11
11
|
import { normalizeList } from "./safelist.js";
|
|
12
|
-
import { holdsSecret } from "./echo.js";
|
|
12
|
+
import { holdsSecret, SecretWithheld } from "./echo.js";
|
|
13
13
|
import { approxTextLength, detectWall } from "./walls.js";
|
|
14
14
|
export function handle(job) {
|
|
15
15
|
const done = handleJob(job);
|
|
@@ -82,11 +82,13 @@ export async function handleAsync(job) {
|
|
|
82
82
|
return handle(job);
|
|
83
83
|
try {
|
|
84
84
|
const { parsePdf } = await import("./pdf.js");
|
|
85
|
-
const parsed = await parsePdf(job.bytes, job.url);
|
|
85
|
+
const parsed = await parsePdf(job.bytes, job.url, job.secrets);
|
|
86
86
|
parsed.language = languageOf(parsed, job.lang); // W-26 (v0.7)
|
|
87
87
|
return { result: { parsed, wall: null } };
|
|
88
88
|
}
|
|
89
89
|
catch (e) {
|
|
90
|
+
if (e instanceof SecretWithheld)
|
|
91
|
+
return { error: "secret_withheld" };
|
|
90
92
|
if (e instanceof PdfError)
|
|
91
93
|
return { error: "pdf", message: e.message };
|
|
92
94
|
if (e instanceof ComplexityError)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raibitsi/tiresias",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "The honest browser for AI agents. The browser you never open.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Raibit (https://raibit.ai/)",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"!dist/test",
|
|
34
34
|
"stubs",
|
|
35
35
|
"README.md",
|
|
36
|
+
"CHANGELOG.md",
|
|
36
37
|
"docs/QUICKSTART.md",
|
|
37
38
|
"docs/DEMO.md",
|
|
38
39
|
"LICENSE",
|