@acepaste/ingress 0.9.1 → 0.9.21
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/LICENSE +1 -1
- package/dist/src/adapters.d.ts +9 -0
- package/dist/src/adapters.js +76 -6
- package/dist/src/agent-hooks.d.ts +112 -0
- package/dist/src/agent-hooks.js +533 -0
- package/dist/src/approvers.d.ts +16 -0
- package/dist/src/approvers.js +50 -0
- package/dist/src/audio.d.ts +70 -0
- package/dist/src/audio.js +224 -0
- package/dist/src/audit-changes.d.ts +46 -0
- package/dist/src/audit-changes.js +110 -0
- package/dist/src/audit-local.d.ts +57 -0
- package/dist/src/audit-local.js +231 -0
- package/dist/src/audit-parsers.d.ts +1 -1
- package/dist/src/audit.js +48 -0
- package/dist/src/broker.d.ts +92 -1
- package/dist/src/broker.js +222 -3
- package/dist/src/calendar.d.ts +36 -0
- package/dist/src/calendar.js +227 -0
- package/dist/src/captions.d.ts +44 -0
- package/dist/src/captions.js +209 -0
- package/dist/src/changes.d.ts +105 -0
- package/dist/src/changes.js +174 -0
- package/dist/src/character.js +19 -3
- package/dist/src/classifier-model.d.ts +53 -0
- package/dist/src/classifier-model.js +3 -0
- package/dist/src/classifier.d.ts +41 -0
- package/dist/src/classifier.js +213 -0
- package/dist/src/cli.js +501 -1
- package/dist/src/codepass.d.ts +8 -0
- package/dist/src/codepass.js +39 -1
- package/dist/src/egress.d.ts +71 -0
- package/dist/src/egress.js +242 -0
- package/dist/src/email.d.ts +42 -0
- package/dist/src/email.js +424 -0
- package/dist/src/engine.d.ts +35 -12
- package/dist/src/engine.js +172 -45
- package/dist/src/image-meta.d.ts +33 -0
- package/dist/src/image-meta.js +433 -0
- package/dist/src/image.d.ts +104 -0
- package/dist/src/image.js +347 -0
- package/dist/src/index.d.ts +50 -5
- package/dist/src/index.js +28 -3
- package/dist/src/localguard.d.ts +33 -0
- package/dist/src/localguard.js +61 -0
- package/dist/src/meaning.d.ts +2 -0
- package/dist/src/meaning.js +348 -25
- package/dist/src/messages.d.ts +79 -0
- package/dist/src/messages.js +431 -0
- package/dist/src/multilingual.d.ts +3 -0
- package/dist/src/multilingual.js +117 -5
- package/dist/src/nearby.d.ts +52 -0
- package/dist/src/nearby.js +186 -0
- package/dist/src/netpolicy.js +50 -19
- package/dist/src/normalize.d.ts +36 -1
- package/dist/src/normalize.js +186 -4
- package/dist/src/provenance.d.ts +56 -0
- package/dist/src/provenance.js +114 -0
- package/dist/src/qr.d.ts +25 -0
- package/dist/src/qr.js +113 -0
- package/dist/src/safeguards.d.ts +61 -0
- package/dist/src/safeguards.js +199 -0
- package/dist/src/served.d.ts +20 -0
- package/dist/src/served.js +53 -0
- package/dist/src/shell-commands.d.ts +39 -0
- package/dist/src/shell-commands.js +291 -0
- package/dist/src/shortcuts.d.ts +45 -0
- package/dist/src/shortcuts.js +220 -0
- package/dist/src/stream.d.ts +88 -0
- package/dist/src/stream.js +119 -0
- package/dist/src/terminal.d.ts +29 -0
- package/dist/src/terminal.js +313 -0
- package/dist/src/tooldefs.d.ts +84 -0
- package/dist/src/tooldefs.js +122 -0
- package/dist/src/types.d.ts +50 -6
- package/dist/src/types.js +15 -2
- package/dist/src/visibility.d.ts +23 -3
- package/dist/src/visibility.js +285 -78
- package/native/ingress-presence.swift +48 -0
- package/native/ingress-vision.swift +417 -0
- package/package.json +4 -2
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provenance marks: what an agent wrote after reading outside content.
|
|
3
|
+
*
|
|
4
|
+
* A run that has read a web page, an email or a tool result may have been steered by it. What that run
|
|
5
|
+
* writes to disk is the way one steered moment reaches a later, clean session: a note, a script, a config.
|
|
6
|
+
* So each file written in such a run is marked: which session, when, and what it had read. When a later
|
|
7
|
+
* session reads the file, the mark says its content is at best "written by an agent earlier" (trust level 3
|
|
8
|
+
* only if the run that wrote it was clean; this one was not).
|
|
9
|
+
*
|
|
10
|
+
* A mark labels; it does not block. The files are the person's own project, and withholding them would stop
|
|
11
|
+
* work. The reader is told, the file is scanned as outside content, and the reading session counts as having
|
|
12
|
+
* read outside content.
|
|
13
|
+
*
|
|
14
|
+
* Marks are kept by path with the file's hash, so a mark also says whether the file changed since.
|
|
15
|
+
* A person clears a mark (`ingress provenance clear <path>`); an agent cannot.
|
|
16
|
+
*/
|
|
17
|
+
import { createHash } from "node:crypto";
|
|
18
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
19
|
+
import { execFileSync } from "node:child_process";
|
|
20
|
+
import { join, resolve } from "node:path";
|
|
21
|
+
import { stateDir } from "./changes.js";
|
|
22
|
+
const MAX_MARKS = 5000;
|
|
23
|
+
const MAX_HASH_BYTES = 20_000_000;
|
|
24
|
+
function hashFile(path) {
|
|
25
|
+
try {
|
|
26
|
+
if (statSync(path).size > MAX_HASH_BYTES)
|
|
27
|
+
return undefined;
|
|
28
|
+
return createHash("sha256").update(readFileSync(path)).digest("hex");
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class ProvenanceLedger {
|
|
35
|
+
file;
|
|
36
|
+
constructor(dir = stateDir()) { this.file = join(dir, "provenance.json"); }
|
|
37
|
+
read() {
|
|
38
|
+
try {
|
|
39
|
+
const v = JSON.parse(readFileSync(this.file, "utf8"));
|
|
40
|
+
return v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
write(marks) {
|
|
47
|
+
let entries = Object.entries(marks);
|
|
48
|
+
if (entries.length > MAX_MARKS)
|
|
49
|
+
entries = entries.sort((a, b) => a[1].at.localeCompare(b[1].at)).slice(-MAX_MARKS);
|
|
50
|
+
mkdirSync(join(this.file, ".."), { recursive: true, mode: 0o700 });
|
|
51
|
+
writeFileSync(`${this.file}.${process.pid}.tmp`, JSON.stringify(Object.fromEntries(entries)), { mode: 0o600 });
|
|
52
|
+
renameSync(`${this.file}.${process.pid}.tmp`, this.file);
|
|
53
|
+
}
|
|
54
|
+
/** Mark a file as written by a session that had read outside content. */
|
|
55
|
+
mark(path, by) {
|
|
56
|
+
const p = resolve(path);
|
|
57
|
+
const mark = { path: p, sha256: hashFile(p), at: by.at ?? new Date().toISOString(), session: by.session, sources: by.sources.slice(-5).map((s) => s.slice(0, 200)) };
|
|
58
|
+
const marks = this.read();
|
|
59
|
+
marks[p] = mark;
|
|
60
|
+
this.write(marks);
|
|
61
|
+
return mark;
|
|
62
|
+
}
|
|
63
|
+
/** The mark on a file, and whether the file is still what was written then. */
|
|
64
|
+
lookup(path) {
|
|
65
|
+
const p = resolve(path);
|
|
66
|
+
const mark = this.read()[p];
|
|
67
|
+
if (!mark || typeof mark.path !== "string")
|
|
68
|
+
return undefined;
|
|
69
|
+
return { mark, unchanged: mark.sha256 !== undefined && mark.sha256 === hashFile(p) };
|
|
70
|
+
}
|
|
71
|
+
/** Remove a mark: a person has looked at the file. Returns whether there was one. */
|
|
72
|
+
clear(path) {
|
|
73
|
+
const p = resolve(path);
|
|
74
|
+
const marks = this.read();
|
|
75
|
+
if (!(p in marks))
|
|
76
|
+
return false;
|
|
77
|
+
delete marks[p];
|
|
78
|
+
this.write(marks);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
list() { return Object.values(this.read()).sort((a, b) => b.at.localeCompare(a.at)); }
|
|
82
|
+
}
|
|
83
|
+
/** One sentence for whoever reads a marked file. */
|
|
84
|
+
export function describeMark(m, unchanged) {
|
|
85
|
+
const from = m.sources.length ? ` (it had read: ${m.sources.slice(-3).join(", ")})` : "";
|
|
86
|
+
return `this file was written on ${m.at.slice(0, 10)} by an agent session that had read outside content${from}${unchanged ? "" : "; it has been changed since"}`;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Where the operating system says a file came from: macOS marks downloads (and what is unpacked from them)
|
|
90
|
+
* with a quarantine attribute naming the app that fetched them, and often the address. Undefined when the
|
|
91
|
+
* file has no such mark, or on a system without it.
|
|
92
|
+
*/
|
|
93
|
+
export function downloadOrigin(path) {
|
|
94
|
+
if (process.platform !== "darwin" || !existsSync(path))
|
|
95
|
+
return undefined;
|
|
96
|
+
let q;
|
|
97
|
+
try {
|
|
98
|
+
q = execFileSync("/usr/bin/xattr", ["-p", "com.apple.quarantine", path], { encoding: "utf8", timeout: 2000, stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
if (!q)
|
|
104
|
+
return undefined;
|
|
105
|
+
// flags;timestamp;agent name;event id
|
|
106
|
+
const agent = q.split(";")[2] || undefined;
|
|
107
|
+
let from;
|
|
108
|
+
try {
|
|
109
|
+
const where = execFileSync("/usr/bin/mdls", ["-raw", "-name", "kMDItemWhereFroms", path], { encoding: "utf8", timeout: 2000, stdio: ["ignore", "pipe", "ignore"] });
|
|
110
|
+
from = where.match(/https?:\/\/[^\s",)]+/)?.[0];
|
|
111
|
+
}
|
|
112
|
+
catch { /* the attribute alone is enough */ }
|
|
113
|
+
return { agent, from };
|
|
114
|
+
}
|
package/dist/src/qr.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a QR code (or any barcode with a text payload) would do if it were followed.
|
|
3
|
+
*
|
|
4
|
+
* A person cannot read a QR code. They see a square and whatever caption sits beside it; the payload is
|
|
5
|
+
* for the machine. So the payload is judged for what it is: a link, or an action (join this Wi-Fi network,
|
|
6
|
+
* add this one-time-code secret, send this text message, pay this account, open this app), or plain text.
|
|
7
|
+
* Nothing here opens, fetches or performs anything.
|
|
8
|
+
*/
|
|
9
|
+
export type QrKind = "link" | "wifi" | "otp-secret" | "sms" | "phone" | "email" | "payment" | "contact" | "event" | "location" | "app-link" | "text";
|
|
10
|
+
export interface QrVerdict {
|
|
11
|
+
kind: QrKind;
|
|
12
|
+
/** one sentence a person can act on */
|
|
13
|
+
summary: string;
|
|
14
|
+
/** following it does something, rather than showing something */
|
|
15
|
+
action: boolean;
|
|
16
|
+
/** 0 to 1: how much care it needs */
|
|
17
|
+
risk: number;
|
|
18
|
+
/** for links: the host, to be fetched only through the gate */
|
|
19
|
+
host?: string;
|
|
20
|
+
url?: string;
|
|
21
|
+
/** free text carried by the payload (the whole payload for "text"; a message body for sms and email), to be scanned as content */
|
|
22
|
+
text?: string;
|
|
23
|
+
notes: string[];
|
|
24
|
+
}
|
|
25
|
+
export declare function judgeQrPayload(payload: string): QrVerdict;
|
package/dist/src/qr.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a QR code (or any barcode with a text payload) would do if it were followed.
|
|
3
|
+
*
|
|
4
|
+
* A person cannot read a QR code. They see a square and whatever caption sits beside it; the payload is
|
|
5
|
+
* for the machine. So the payload is judged for what it is: a link, or an action (join this Wi-Fi network,
|
|
6
|
+
* add this one-time-code secret, send this text message, pay this account, open this app), or plain text.
|
|
7
|
+
* Nothing here opens, fetches or performs anything.
|
|
8
|
+
*/
|
|
9
|
+
const PAY_SCHEMES = /^(?:bitcoin|bitcoincash|ethereum|litecoin|dogecoin|monero|solana|lightning|upi|paypal|venmo|cashapp|swish|bezahlcode|pix|alipays?|weixin|wxp)$/i;
|
|
10
|
+
const WEB = /^https?$/i;
|
|
11
|
+
function hostNotes(u) {
|
|
12
|
+
const n = [];
|
|
13
|
+
if (u.username || u.password)
|
|
14
|
+
n.push("the address carries a user name or password before the host, which hides where it really goes");
|
|
15
|
+
if (/^xn--|\.xn--/.test(u.hostname))
|
|
16
|
+
n.push("the host is an international name that may imitate another");
|
|
17
|
+
if (/^\d{1,3}(?:\.\d{1,3}){3}$|^\[/.test(u.hostname))
|
|
18
|
+
n.push("the host is a bare network address, not a name");
|
|
19
|
+
if (u.protocol === "http:")
|
|
20
|
+
n.push("the link is not encrypted");
|
|
21
|
+
if (/^(?:bit\.ly|t\.co|tinyurl\.com|goo\.gl|is\.gd|ow\.ly|buff\.ly|rebrand\.ly|cutt\.ly|qrco\.de|qr\.link|l\.ead\.me|s\.id|shorturl\.at|rb\.gy|t\.ly)$/i.test(u.hostname))
|
|
22
|
+
n.push("the link is a shortener: where it ends up is not visible here");
|
|
23
|
+
if (u.search.length > 200)
|
|
24
|
+
n.push(`the link carries ${u.search.length} characters of query data`);
|
|
25
|
+
return n;
|
|
26
|
+
}
|
|
27
|
+
export function judgeQrPayload(payload) {
|
|
28
|
+
const p = payload.trim();
|
|
29
|
+
const notes = [];
|
|
30
|
+
// Wi-Fi: WIFI:T:WPA;S:name;P:password;H:true;;
|
|
31
|
+
if (/^WIFI:/i.test(p)) {
|
|
32
|
+
const f = Object.fromEntries([...p.slice(5).matchAll(/([A-Z]):((?:\\.|[^;\\])*)/gi)].map((m) => [m[1].toUpperCase(), m[2].replace(/\\(.)/g, "$1")]));
|
|
33
|
+
if (!f.T || /^nopass$/i.test(f.T))
|
|
34
|
+
notes.push("the network has no password: anyone nearby can read its traffic");
|
|
35
|
+
if (/^true$/i.test(f.H ?? ""))
|
|
36
|
+
notes.push("the network is hidden");
|
|
37
|
+
return { kind: "wifi", action: true, risk: 0.6, summary: `joins the Wi-Fi network "${(f.S ?? "").slice(0, 64)}". A device that joins a network sends its traffic through whoever runs it`, notes };
|
|
38
|
+
}
|
|
39
|
+
// one-time-code secrets: scanning adds an authenticator entry; reading it gives away the secret
|
|
40
|
+
if (/^otpauth(?:-migration)?:\/\//i.test(p)) {
|
|
41
|
+
let label = "";
|
|
42
|
+
try {
|
|
43
|
+
label = decodeURIComponent(new URL(p).pathname.replace(/^\/+/, "")).slice(0, 80);
|
|
44
|
+
}
|
|
45
|
+
catch { /* shown without a label */ }
|
|
46
|
+
return { kind: "otp-secret", action: true, risk: 0.9, summary: `carries a one-time-code secret${label ? ` for "${label}"` : ""}. Whoever reads it can generate that account's sign-in codes: it must never be copied anywhere`, notes };
|
|
47
|
+
}
|
|
48
|
+
if (/^(?:smsto|sms|mms|mmsto):/i.test(p)) {
|
|
49
|
+
const m = p.match(/^(?:smsto|sms|mms|mmsto):\/{0,2}([^:?]*)[:?]?(?:body=)?([\s\S]*)$/i);
|
|
50
|
+
let body = m?.[2] ?? "";
|
|
51
|
+
try {
|
|
52
|
+
body = decodeURIComponent(body);
|
|
53
|
+
}
|
|
54
|
+
catch { /* as written */ }
|
|
55
|
+
if (/^\d{3,6}$/.test((m?.[1] ?? "").replace(/\D/g, "")))
|
|
56
|
+
notes.push("the number is a short code: messages to short codes can subscribe to paid services");
|
|
57
|
+
return { kind: "sms", action: true, risk: 0.6, summary: `writes a text message to ${(m?.[1] ?? "a number").slice(0, 40)}${body ? " with the words already filled in" : ""}`, text: body || undefined, notes };
|
|
58
|
+
}
|
|
59
|
+
if (/^tel:/i.test(p)) {
|
|
60
|
+
const num = p.slice(4);
|
|
61
|
+
if (/[*#]/.test(num))
|
|
62
|
+
notes.push("the number contains * or #: such codes can change phone settings such as call forwarding");
|
|
63
|
+
return { kind: "phone", action: true, risk: /[*#]/.test(num) ? 0.7 : 0.4, summary: `dials ${num.slice(0, 40)}`, notes };
|
|
64
|
+
}
|
|
65
|
+
if (/^(?:mailto:|MATMSG:)/i.test(p)) {
|
|
66
|
+
let body = "";
|
|
67
|
+
try {
|
|
68
|
+
const u = new URL(p.replace(/^MATMSG:/i, "mailto:"));
|
|
69
|
+
body = [u.searchParams.get("subject"), u.searchParams.get("body")].filter(Boolean).join("\n");
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
body = p.match(/BODY:([^;]*)/i)?.[1] ?? "";
|
|
73
|
+
}
|
|
74
|
+
return { kind: "email", action: true, risk: 0.4, summary: `writes an email${body ? " with the words already filled in" : ""}`, text: body || undefined, notes };
|
|
75
|
+
}
|
|
76
|
+
if (/^BEGIN:VCARD/i.test(p) || /^MECARD:/i.test(p))
|
|
77
|
+
return { kind: "contact", action: true, risk: 0.3, summary: "adds a contact to the address book", text: p.slice(0, 2000), notes };
|
|
78
|
+
if (/^BEGIN:VEVENT|^BEGIN:VCALENDAR/i.test(p))
|
|
79
|
+
return { kind: "event", action: true, risk: 0.4, summary: "adds an event to the calendar", text: p.slice(0, 4000), notes };
|
|
80
|
+
if (/^geo:/i.test(p))
|
|
81
|
+
return { kind: "location", action: false, risk: 0.1, summary: "opens a place on a map", notes };
|
|
82
|
+
// European bank transfer codes: "BCD" on the first line
|
|
83
|
+
if (/^BCD\r?\n\d{3}\r?\n/.test(p))
|
|
84
|
+
return { kind: "payment", action: true, risk: 0.8, summary: "starts a bank transfer with the recipient and amount already filled in", notes };
|
|
85
|
+
const scheme = p.match(/^([a-z][a-z0-9+.-]{1,31}):/i)?.[1];
|
|
86
|
+
if (scheme && WEB.test(scheme)) {
|
|
87
|
+
try {
|
|
88
|
+
const u = new URL(p);
|
|
89
|
+
notes.push(...hostNotes(u));
|
|
90
|
+
return { kind: "link", action: false, risk: Math.min(0.7, 0.15 + notes.length * 0.2), summary: `links to ${u.hostname}`, host: u.hostname.toLowerCase(), url: u.toString(), notes };
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return { kind: "link", action: false, risk: 0.5, summary: "holds a web address that does not parse", notes: ["an address that parsers read differently is a common way to disguise a destination"] };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (scheme && PAY_SCHEMES.test(scheme))
|
|
97
|
+
return { kind: "payment", action: true, risk: 0.8, summary: `starts a payment (${scheme.toLowerCase()}) with the recipient already filled in`, notes };
|
|
98
|
+
if (scheme && !/^(?:urn|data|javascript|file|about|blob)$/i.test(scheme) && /^[a-z][a-z0-9+.-]*:\/\//i.test(p)) {
|
|
99
|
+
return { kind: "app-link", action: true, risk: 0.5, summary: `opens an app through the "${scheme.toLowerCase()}:" scheme, with instructions for that app in the link`, text: p.slice(0, 2000), notes };
|
|
100
|
+
}
|
|
101
|
+
if (scheme && /^(?:javascript|data|file)$/i.test(scheme))
|
|
102
|
+
return { kind: "app-link", action: true, risk: 0.9, summary: `holds a "${scheme.toLowerCase()}:" address, which runs or opens content directly`, text: p.slice(0, 2000), notes };
|
|
103
|
+
// a bare domain is still a link once a scanner helps
|
|
104
|
+
if (/^(?:www\.)?[a-z0-9-]+(?:\.[a-z0-9-]+)+(?:\/\S*)?$/i.test(p) && !/\s/.test(p)) {
|
|
105
|
+
try {
|
|
106
|
+
const u = new URL(`https://${p}`);
|
|
107
|
+
notes.push(...hostNotes(u));
|
|
108
|
+
return { kind: "link", action: false, risk: 0.2 + notes.length * 0.2, summary: `links to ${u.hostname}`, host: u.hostname.toLowerCase(), url: u.toString(), notes };
|
|
109
|
+
}
|
|
110
|
+
catch { /* plain text */ }
|
|
111
|
+
}
|
|
112
|
+
return { kind: "text", action: false, risk: 0.1, summary: `holds ${p.length} characters of text`, text: p.slice(0, 8000), notes };
|
|
113
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safeguards the broker applies to every proposed action, whatever the run has read.
|
|
3
|
+
*
|
|
4
|
+
* These exist for the agent as much as for the person: an agent that has been steered by something it
|
|
5
|
+
* read cannot tell from the inside. Each check here is something the agent would want between itself and
|
|
6
|
+
* the world.
|
|
7
|
+
*
|
|
8
|
+
* persistence An action that creates something which acts later (a scheduled job, an automation, a
|
|
9
|
+
* mail rule, a login item, a hook, an edit to the agent's own instructions or memory)
|
|
10
|
+
* turns one bad moment into a standing one. It always needs a person.
|
|
11
|
+
* canary A marker placed in the run's context that has no reason to leave it. If it shows up in
|
|
12
|
+
* an outbound argument, the context itself is being sent somewhere: refuse.
|
|
13
|
+
* burst Many side effects in a short time, or the same one over and over, is a loop or a
|
|
14
|
+
* mass-send. Hold it for a person.
|
|
15
|
+
* stop One file a person can create to make every action wait until they remove it.
|
|
16
|
+
*/
|
|
17
|
+
export interface PersistenceHit {
|
|
18
|
+
/** what kind of standing change this is */
|
|
19
|
+
kind: "scheduled-job" | "startup-item" | "automation" | "mail-rule" | "hook" | "agent-instructions" | "agent-config" | "remote-access" | "webhook";
|
|
20
|
+
/** short explanation for the person */
|
|
21
|
+
why: string;
|
|
22
|
+
}
|
|
23
|
+
/** Does this action create or change something that acts later? `strings` are the argument strings and keys. */
|
|
24
|
+
export declare function persistenceShapes(tool: string, strings: readonly string[]): PersistenceHit[];
|
|
25
|
+
/** A marker with no meaning anywhere else: 96 random bits, so it never appears by accident. */
|
|
26
|
+
export declare function newCanary(): string;
|
|
27
|
+
/** The sentence placed in the agent's context with the marker. */
|
|
28
|
+
export declare function canaryNotice(canary: string): string;
|
|
29
|
+
/** True when any argument string carries the marker, plainly or through a common encoding. */
|
|
30
|
+
export declare function carriesCanary(strings: readonly string[], canaries: readonly string[]): boolean;
|
|
31
|
+
export interface BurstPolicy {
|
|
32
|
+
/** side effects a run may perform per minute before the next one needs a person */
|
|
33
|
+
perMinute: number;
|
|
34
|
+
/** times the very same action (tool and arguments) may run in ten minutes before the next one needs a person */
|
|
35
|
+
sameAction: number;
|
|
36
|
+
}
|
|
37
|
+
export declare const DEFAULT_BURST: BurstPolicy;
|
|
38
|
+
export declare class BurstCounter {
|
|
39
|
+
private at;
|
|
40
|
+
private same;
|
|
41
|
+
/** record one side effect that ran */
|
|
42
|
+
record(digestKey: string, now: number): void;
|
|
43
|
+
/** reasons the next action should wait for a person; empty when it is within limits */
|
|
44
|
+
check(digestKey: string, now: number, p: BurstPolicy): string[];
|
|
45
|
+
export(): {
|
|
46
|
+
at: number[];
|
|
47
|
+
same: Array<[string, number[]]>;
|
|
48
|
+
};
|
|
49
|
+
import(d: {
|
|
50
|
+
at?: unknown;
|
|
51
|
+
same?: unknown;
|
|
52
|
+
} | undefined): void;
|
|
53
|
+
private trim;
|
|
54
|
+
}
|
|
55
|
+
/** the same action whatever run it is in: tool and canonical arguments */
|
|
56
|
+
export declare const actionKey: (tool: string, canonicalArgs: string) => string;
|
|
57
|
+
/** Why everything is stopped, or undefined when it is not. Any readable file there counts, even an empty one. */
|
|
58
|
+
export declare function stopReason(dir?: string): string | undefined;
|
|
59
|
+
/** Stop every action routed through any broker on this machine that uses this state folder. */
|
|
60
|
+
export declare function engageStop(reason: string, dir?: string, now?: Date): string;
|
|
61
|
+
export declare function clearStop(dir?: string): boolean;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safeguards the broker applies to every proposed action, whatever the run has read.
|
|
3
|
+
*
|
|
4
|
+
* These exist for the agent as much as for the person: an agent that has been steered by something it
|
|
5
|
+
* read cannot tell from the inside. Each check here is something the agent would want between itself and
|
|
6
|
+
* the world.
|
|
7
|
+
*
|
|
8
|
+
* persistence An action that creates something which acts later (a scheduled job, an automation, a
|
|
9
|
+
* mail rule, a login item, a hook, an edit to the agent's own instructions or memory)
|
|
10
|
+
* turns one bad moment into a standing one. It always needs a person.
|
|
11
|
+
* canary A marker placed in the run's context that has no reason to leave it. If it shows up in
|
|
12
|
+
* an outbound argument, the context itself is being sent somewhere: refuse.
|
|
13
|
+
* burst Many side effects in a short time, or the same one over and over, is a loop or a
|
|
14
|
+
* mass-send. Hold it for a person.
|
|
15
|
+
* stop One file a person can create to make every action wait until they remove it.
|
|
16
|
+
*/
|
|
17
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
18
|
+
import { existsSync, readFileSync, rmSync, writeFileSync, mkdirSync } from "node:fs";
|
|
19
|
+
import { dirname, join } from "node:path";
|
|
20
|
+
import { stateDir } from "./changes.js";
|
|
21
|
+
/** words in a tool's own name that mean it creates or changes something that acts later */
|
|
22
|
+
const PERSISTENCE_TOOL_WORDS = [
|
|
23
|
+
[/\b(cron|crontab|schedule[drs]?|scheduler|timer|recurring|launchd|launch ?agent|systemd)\b/, "scheduled-job", "it schedules something to run later"],
|
|
24
|
+
[/\b(automation|automations|workflow|workflows|zap|zaps|scenario|recipe|applet|blueprint|shortcut|shortcuts|trigger|triggers)\b/, "automation", "it creates or changes an automation"],
|
|
25
|
+
[/\b(filter|filters|forward|forwarding|auto ?forward|redirect|inbox ?rule|mail ?rule|rule|rules|vacation|auto ?reply|autoresponder|delegate|delegation)\b/, "mail-rule", "it creates or changes a rule that handles messages without you"],
|
|
26
|
+
[/\b(webhook|webhooks|subscription|subscriptions|callback ?url)\b/, "webhook", "it registers an address that will be called later"],
|
|
27
|
+
[/\b(login ?item|startup|autostart|boot)\b/, "startup-item", "it sets something to start automatically"],
|
|
28
|
+
[/\b(hook|hooks)\b/, "hook", "it installs a hook that runs on later events"],
|
|
29
|
+
[/\b(memory|memories|instruction|instructions|system ?prompt|rules ?file|persona)\b/, "agent-instructions", "it writes to what an agent will read as its own instructions or memory"],
|
|
30
|
+
];
|
|
31
|
+
/** only tools that write count: reading a schedule or listing rules is not persistence */
|
|
32
|
+
const WRITE_WORDS = /\b(create|add|new|set|update|edit|write|save|put|insert|enable|install|register|upsert|modify|change|patch|append|schedule|import|make|configure)\b/;
|
|
33
|
+
/** paths whose contents run, or steer an agent, later */
|
|
34
|
+
const PERSISTENCE_PATHS = [
|
|
35
|
+
[/(?:^|[/\\])Library[/\\]Launch(?:Agents|Daemons)[/\\]|[/\\]etc[/\\]systemd[/\\]|[/\\]\.config[/\\]systemd[/\\]|[/\\]etc[/\\]init\.d[/\\]|\.(?:timer|service)\b(?=["'\s]|$)/i, "scheduled-job", "a launch agent, daemon or systemd unit"],
|
|
36
|
+
[/[/\\]etc[/\\]cron|[/\\]var[/\\]spool[/\\]cron|[/\\]etc[/\\]crontab\b|[/\\]etc[/\\]periodic[/\\]/i, "scheduled-job", "a cron table"],
|
|
37
|
+
[/(?:^|[/\\])\.(?:bashrc|bash_profile|bash_login|profile|zshrc|zshenv|zprofile|zlogin|config[/\\]fish[/\\]config\.fish)\b|[/\\]etc[/\\](?:profile|zshrc|bashrc|paths)\b/i, "startup-item", "a shell startup file, which runs in every new terminal"],
|
|
38
|
+
[/[/\\](?:Startup|StartupItems|LoginItems|autostart)[/\\]|com\.apple\.loginitems|backgrounditems\.btm/i, "startup-item", "a login or startup item"],
|
|
39
|
+
[/(?:^|[/\\])\.git[/\\]hooks[/\\]|(?:^|[/\\])\.husky[/\\]|(?:^|[/\\])\.claude[/\\]settings(?:\.local)?\.json|(?:^|[/\\])\.claude[/\\]hooks[/\\]/i, "hook", "a hook that runs on later events"],
|
|
40
|
+
[/(?:^|[/\\])(?:CLAUDE|AGENTS|GEMINI|COPILOT)\.md\b|(?:^|[/\\])\.cursorrules\b|(?:^|[/\\])\.cursor[/\\]rules[/\\]|(?:^|[/\\])\.github[/\\]copilot-instructions\.md|(?:^|[/\\])\.claude[/\\](?:commands|agents|skills)[/\\]|[/\\]memory[/\\][^/\\]+\.md\b|(?:^|[/\\])MEMORY\.md\b|global_rules\.md\b/i, "agent-instructions", "a file agents read as their own instructions or memory"],
|
|
41
|
+
[/(?:^|[/\\])\.mcp\.json\b|claude_desktop_config\.json|(?:^|[/\\])\.claude\.json\b|[/\\]\.cursor[/\\]mcp\.json|mcp_config\.json/i, "agent-config", "an agent's list of tool servers"],
|
|
42
|
+
[/(?:^|[/\\])\.ssh[/\\]authorized_keys|(?:^|[/\\])\.ssh[/\\]config\b|[/\\]etc[/\\]sudoers|[/\\]etc[/\\]ssh[/\\]sshd_config/i, "remote-access", "a file that decides who can log in or act as an administrator"],
|
|
43
|
+
[/[/\\]Library[/\\](?:Shortcuts|Services|Workflows)[/\\]|\.shortcut\b|[/\\]Folder Action Scripts[/\\]/i, "automation", "a shortcut, service or folder action"],
|
|
44
|
+
];
|
|
45
|
+
/** shell commands that create something which runs later */
|
|
46
|
+
const PERSISTENCE_COMMANDS = [
|
|
47
|
+
[/\bcrontab\s+(?!-l\b)\S|\bat\s+(?:now|\d|midnight|noon|tomorrow)\b|\bschtasks\b[^\n]*\/create\b|\bsystemctl\s+(?:--user\s+)?(?:enable|link)\b|\bsystemd-run\b[^\n]*--on-/i, "scheduled-job", "a command that schedules something to run later"],
|
|
48
|
+
[/\blaunchctl\s+(?:load|bootstrap|enable|submit)\b/i, "scheduled-job", "a command that loads a launch agent or daemon"],
|
|
49
|
+
[/\bosascript\b[^\n]*login item|\bsfltool\b|\bdefaults\s+write\b[^\n]*(?:loginwindow|LoginHook|AutoLaunchedApplicationDictionary)/i, "startup-item", "a command that adds a login item"],
|
|
50
|
+
[/\bgit\s+config\b[^\n]*core\.hooksPath\b|\bshortcuts\s+(?:import|sign)\b/i, "hook", "a command that installs a hook or shortcut"],
|
|
51
|
+
[/\bssh-copy-id\b|>>?\s*~?[^\s]*authorized_keys\b/i, "remote-access", "a command that lets a key log in later"],
|
|
52
|
+
];
|
|
53
|
+
const ownName = (tool) => { const i = tool.indexOf("__"); return i >= 0 ? tool.slice(i + 2) : tool; };
|
|
54
|
+
const words = (s) => s.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_\-.:/]+/g, " ").toLowerCase();
|
|
55
|
+
/** Does this action create or change something that acts later? `strings` are the argument strings and keys. */
|
|
56
|
+
export function persistenceShapes(tool, strings) {
|
|
57
|
+
const hits = new Map();
|
|
58
|
+
const add = (kind, why) => { if (!hits.has(kind))
|
|
59
|
+
hits.set(kind, { kind, why }); };
|
|
60
|
+
const name = words(ownName(tool));
|
|
61
|
+
if (WRITE_WORDS.test(name))
|
|
62
|
+
for (const [re, kind, why] of PERSISTENCE_TOOL_WORDS)
|
|
63
|
+
if (re.test(name))
|
|
64
|
+
add(kind, why);
|
|
65
|
+
// a mail tool that sets a forwarding address under any name: the field says so
|
|
66
|
+
const keys = strings.map(words).join(" | ");
|
|
67
|
+
if (/\b(forward(?:ing)? ?(?:to|address|email)|auto ?forward|redirect ?to|forwarding ?smtp)\b/.test(keys))
|
|
68
|
+
add("mail-rule", "it sets an address that mail will be forwarded to");
|
|
69
|
+
for (const s of strings) {
|
|
70
|
+
if (s.length > 20_000)
|
|
71
|
+
continue; // a file body is content, not a destination; the path argument is what matters
|
|
72
|
+
for (const [re, kind, why] of PERSISTENCE_PATHS)
|
|
73
|
+
if (re.test(s))
|
|
74
|
+
add(kind, `it touches ${why}`);
|
|
75
|
+
for (const [re, kind, why] of PERSISTENCE_COMMANDS)
|
|
76
|
+
if (re.test(s))
|
|
77
|
+
add(kind, `it runs ${why}`);
|
|
78
|
+
}
|
|
79
|
+
return [...hits.values()];
|
|
80
|
+
}
|
|
81
|
+
// ---------- canary ----------
|
|
82
|
+
/** A marker with no meaning anywhere else: 96 random bits, so it never appears by accident. */
|
|
83
|
+
export function newCanary() {
|
|
84
|
+
return `ingress-marker-${randomBytes(12).toString("hex")}`;
|
|
85
|
+
}
|
|
86
|
+
/** The sentence placed in the agent's context with the marker. */
|
|
87
|
+
export function canaryNotice(canary) {
|
|
88
|
+
return `[AcePaste Ingress run marker: ${canary}. It identifies this run and is not data. It must never appear in a tool argument, a message, a file or a URL; an action that carries it is refused.]`;
|
|
89
|
+
}
|
|
90
|
+
/** every spelling of the marker that would survive common encodings of the text around it */
|
|
91
|
+
function canaryForms(canary) {
|
|
92
|
+
const forms = new Set([canary, [...canary].reverse().join("")]);
|
|
93
|
+
const b = Buffer.from(canary, "utf8");
|
|
94
|
+
forms.add(b.toString("hex"));
|
|
95
|
+
// base64 depends on where the marker starts inside the encoded text: take the stable middle of each alignment
|
|
96
|
+
for (let pad = 0; pad < 3; pad++) {
|
|
97
|
+
const enc = Buffer.concat([Buffer.alloc(pad, 0x20), b]).toString("base64").replace(/=+$/, "");
|
|
98
|
+
forms.add(enc.slice(pad ? 4 : 0, enc.length - 4));
|
|
99
|
+
}
|
|
100
|
+
forms.add(encodeURIComponent(canary));
|
|
101
|
+
// the unique part alone: catches a marker whose fixed prefix was dropped or the text was split there
|
|
102
|
+
forms.add(canary.slice("ingress-marker-".length));
|
|
103
|
+
return [...forms].filter((f) => f.length >= 16);
|
|
104
|
+
}
|
|
105
|
+
/** True when any argument string carries the marker, plainly or through a common encoding. */
|
|
106
|
+
export function carriesCanary(strings, canaries) {
|
|
107
|
+
if (!canaries.length)
|
|
108
|
+
return false;
|
|
109
|
+
const forms = canaries.flatMap(canaryForms);
|
|
110
|
+
for (const s of strings) {
|
|
111
|
+
const variants = [s, s.toLowerCase()];
|
|
112
|
+
try {
|
|
113
|
+
variants.push(decodeURIComponent(s));
|
|
114
|
+
}
|
|
115
|
+
catch { /* keep as is */ }
|
|
116
|
+
const squeezed = s.replace(/[\s\-_.:,;|/\\]+/g, ""); // a marker broken up with separators
|
|
117
|
+
variants.push(squeezed, squeezed.toLowerCase());
|
|
118
|
+
for (const v of variants)
|
|
119
|
+
for (const f of forms)
|
|
120
|
+
if (v.includes(f) || v.includes(f.replace(/-/g, "")))
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
export const DEFAULT_BURST = { perMinute: 20, sameAction: 3 };
|
|
126
|
+
export class BurstCounter {
|
|
127
|
+
at = [];
|
|
128
|
+
same = new Map();
|
|
129
|
+
/** record one side effect that ran */
|
|
130
|
+
record(digestKey, now) {
|
|
131
|
+
this.at.push(now);
|
|
132
|
+
const s = this.same.get(digestKey) ?? [];
|
|
133
|
+
s.push(now);
|
|
134
|
+
this.same.set(digestKey, s);
|
|
135
|
+
this.trim(now);
|
|
136
|
+
}
|
|
137
|
+
/** reasons the next action should wait for a person; empty when it is within limits */
|
|
138
|
+
check(digestKey, now, p) {
|
|
139
|
+
this.trim(now);
|
|
140
|
+
const why = [];
|
|
141
|
+
const lastMinute = this.at.filter((t) => now - t < 60_000).length;
|
|
142
|
+
if (lastMinute >= p.perMinute)
|
|
143
|
+
why.push(`this run has already performed ${lastMinute} actions in the last minute`);
|
|
144
|
+
const repeats = (this.same.get(digestKey) ?? []).length;
|
|
145
|
+
if (repeats >= p.sameAction)
|
|
146
|
+
why.push(`this exact action has already run ${repeats} times in the last ten minutes`);
|
|
147
|
+
return why;
|
|
148
|
+
}
|
|
149
|
+
export() { return { at: this.at.slice(-200), same: [...this.same].slice(-200) }; }
|
|
150
|
+
import(d) {
|
|
151
|
+
if (!d || typeof d !== "object")
|
|
152
|
+
return;
|
|
153
|
+
if (Array.isArray(d.at))
|
|
154
|
+
this.at.push(...d.at.filter((x) => typeof x === "number"));
|
|
155
|
+
for (const e of Array.isArray(d.same) ? d.same : [])
|
|
156
|
+
if (Array.isArray(e) && typeof e[0] === "string" && Array.isArray(e[1]))
|
|
157
|
+
this.same.set(e[0], e[1].filter((x) => typeof x === "number"));
|
|
158
|
+
}
|
|
159
|
+
trim(now) {
|
|
160
|
+
this.at = this.at.filter((t) => now - t < 600_000);
|
|
161
|
+
for (const [k, v] of this.same) {
|
|
162
|
+
const kept = v.filter((t) => now - t < 600_000);
|
|
163
|
+
if (kept.length)
|
|
164
|
+
this.same.set(k, kept);
|
|
165
|
+
else
|
|
166
|
+
this.same.delete(k);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** the same action whatever run it is in: tool and canonical arguments */
|
|
171
|
+
export const actionKey = (tool, canonicalArgs) => createHash("sha256").update(`${tool}\n${canonicalArgs}`, "utf8").digest("hex");
|
|
172
|
+
// ---------- stop switch ----------
|
|
173
|
+
const stopPath = (dir) => join(dir ?? stateDir(), "STOP");
|
|
174
|
+
/** Why everything is stopped, or undefined when it is not. Any readable file there counts, even an empty one. */
|
|
175
|
+
export function stopReason(dir) {
|
|
176
|
+
const p = stopPath(dir);
|
|
177
|
+
if (!existsSync(p))
|
|
178
|
+
return undefined;
|
|
179
|
+
try {
|
|
180
|
+
return readFileSync(p, "utf8").trim().slice(0, 300) || "stopped by a person";
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return "stopped (the stop file exists but could not be read)";
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/** Stop every action routed through any broker on this machine that uses this state folder. */
|
|
187
|
+
export function engageStop(reason, dir, now = new Date()) {
|
|
188
|
+
const p = stopPath(dir);
|
|
189
|
+
mkdirSync(dirname(p), { recursive: true, mode: 0o700 });
|
|
190
|
+
writeFileSync(p, `${reason.trim() || "stopped by a person"} (since ${now.toISOString()})\n`, { mode: 0o600 });
|
|
191
|
+
return p;
|
|
192
|
+
}
|
|
193
|
+
export function clearStop(dir) {
|
|
194
|
+
const p = stopPath(dir);
|
|
195
|
+
if (!existsSync(p))
|
|
196
|
+
return false;
|
|
197
|
+
rmSync(p);
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comparing two copies of "the same" content by their words: the page served to an AI fetcher and to a
|
|
3
|
+
* browser, an email's plain part and its HTML part, a video's captions and its speech.
|
|
4
|
+
* The question is always whether one reader was told something the other was not.
|
|
5
|
+
*/
|
|
6
|
+
/** words of served text with markup, link targets and bare URLs removed, so Markdown and HTML of the same page compare equal */
|
|
7
|
+
export declare function servedWords(text: string): string[];
|
|
8
|
+
/** how much of what the agent received is absent from what the browser received (word occurrences, not distinct words) */
|
|
9
|
+
export declare function compareServed(agentText: string, humanText: string): {
|
|
10
|
+
agentWords: number;
|
|
11
|
+
agentOnlyWords: number;
|
|
12
|
+
agentOnlyShare: number;
|
|
13
|
+
longestAgentOnlyRun: number;
|
|
14
|
+
sample: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The passages of `text` that `reference` does not contain: runs of at least `minRun` words in a row that
|
|
18
|
+
* appear nowhere in the reference. Returned as the original text of each run, for scanning.
|
|
19
|
+
*/
|
|
20
|
+
export declare function passagesOnlyIn(text: string, reference: string, minRun?: number): string[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comparing two copies of "the same" content by their words: the page served to an AI fetcher and to a
|
|
3
|
+
* browser, an email's plain part and its HTML part, a video's captions and its speech.
|
|
4
|
+
* The question is always whether one reader was told something the other was not.
|
|
5
|
+
*/
|
|
6
|
+
/** words of served text with markup, link targets and bare URLs removed, so Markdown and HTML of the same page compare equal */
|
|
7
|
+
export function servedWords(text) {
|
|
8
|
+
const t = text
|
|
9
|
+
.replace(/!?\[([^\]]*)\]\([^)]*\)/g, " $1 ") // [label](target) and  -> label
|
|
10
|
+
.replace(/<\/?[a-z][^>]*>/gi, " ") // stray tags
|
|
11
|
+
.replace(/\b(?:https?:\/\/|www\.)\S+/gi, " ") // bare URLs
|
|
12
|
+
.replace(/[#>*_`~|\-]{1,}/g, " "); // markdown syntax
|
|
13
|
+
return t.toLowerCase().split(/[^\p{L}\p{N}']+/u).filter((w) => w.length > 2);
|
|
14
|
+
}
|
|
15
|
+
/** how much of what the agent received is absent from what the browser received (word occurrences, not distinct words) */
|
|
16
|
+
export function compareServed(agentText, humanText) {
|
|
17
|
+
const A = servedWords(agentText);
|
|
18
|
+
const H = new Set(servedWords(humanText));
|
|
19
|
+
const only = A.filter((w) => !H.has(w));
|
|
20
|
+
let run = 0, longestAgentOnlyRun = 0;
|
|
21
|
+
for (const w of A) {
|
|
22
|
+
run = H.has(w) ? 0 : run + 1;
|
|
23
|
+
if (run > longestAgentOnlyRun)
|
|
24
|
+
longestAgentOnlyRun = run;
|
|
25
|
+
}
|
|
26
|
+
const sampleSeen = new Set();
|
|
27
|
+
const sample = only.filter((w) => (sampleSeen.has(w) ? false : (sampleSeen.add(w), true))).slice(0, 30).join(" ");
|
|
28
|
+
return { agentWords: A.length, agentOnlyWords: only.length, agentOnlyShare: A.length ? only.length / A.length : 0, longestAgentOnlyRun, sample };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The passages of `text` that `reference` does not contain: runs of at least `minRun` words in a row that
|
|
32
|
+
* appear nowhere in the reference. Returned as the original text of each run, for scanning.
|
|
33
|
+
*/
|
|
34
|
+
export function passagesOnlyIn(text, reference, minRun = 8) {
|
|
35
|
+
const H = new Set(servedWords(reference));
|
|
36
|
+
const out = [];
|
|
37
|
+
// walk the original text sentence by sentence so the passages read as written
|
|
38
|
+
for (const sentence of text.split(/(?<=[.!?])\s+|\n{2,}/)) {
|
|
39
|
+
const words = servedWords(sentence);
|
|
40
|
+
if (words.length < minRun)
|
|
41
|
+
continue;
|
|
42
|
+
let run = 0, longest = 0;
|
|
43
|
+
for (const w of words) {
|
|
44
|
+
run = H.has(w) ? 0 : run + 1;
|
|
45
|
+
if (run > longest)
|
|
46
|
+
longest = run;
|
|
47
|
+
}
|
|
48
|
+
const missing = words.filter((w) => !H.has(w)).length;
|
|
49
|
+
if (longest >= minRun || (missing >= minRun && missing / words.length >= 0.7))
|
|
50
|
+
out.push(sentence.trim());
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which shell commands bring outside content into an agent's context?
|
|
3
|
+
*
|
|
4
|
+
* A PostToolUse hook sees a command and its output. Output that came from the network (curl, wget, gh, a
|
|
5
|
+
* script that calls fetch) or from a background task's output file is outside content and must be gated;
|
|
6
|
+
* the output of `ls` or `npm test` is not. This module answers that question from the command text.
|
|
7
|
+
*
|
|
8
|
+
* It errs toward gating: a command it cannot parse is gated if a network program appears in it at all.
|
|
9
|
+
*/
|
|
10
|
+
/** Split a command line into words and operators. Throws on an unterminated quote. */
|
|
11
|
+
export declare function shellTokens(command: string): string[];
|
|
12
|
+
/** Each simple command in command position: its program name (without a path) and its arguments. */
|
|
13
|
+
export declare function shellInvocations(command: string): Array<{
|
|
14
|
+
program: string;
|
|
15
|
+
args: string[];
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* The parts of a command line that can change something: every simple command except those that only read.
|
|
19
|
+
* `cat ~/.zshrc | grep PATH` changes nothing; `echo x >> ~/.zshrc` does. Used so that looking at a startup
|
|
20
|
+
* file or an agent's settings is not mistaken for editing it. A command that cannot be parsed is returned whole.
|
|
21
|
+
*/
|
|
22
|
+
export declare function shellWrites(command: string): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Ways a command line sends data to another machine, in plain words; empty when it only asks for something.
|
|
25
|
+
* `curl https://x/page` asks. `curl -d @notes.txt https://x`, `cat key | nc host 9000`, `scp a host:b`,
|
|
26
|
+
* a request built from another command's output: those send.
|
|
27
|
+
*/
|
|
28
|
+
export declare function shellUploads(command: string): string[];
|
|
29
|
+
export interface ShellGateOptions {
|
|
30
|
+
cwd?: string;
|
|
31
|
+
/** a loopback port whose responses are already gated (the Ingress service itself); requests only to it are not gated again */
|
|
32
|
+
ownPort?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A label for where this command's output came from if it must be gated, else undefined.
|
|
36
|
+
* Loopback is not exempt: a dev server, a local model server and a tunnel all serve content someone else
|
|
37
|
+
* wrote. Only requests addressed solely to `ownPort` are skipped.
|
|
38
|
+
*/
|
|
39
|
+
export declare function shellOutputSource(command: string, opts?: ShellGateOptions): string | undefined;
|