@acepaste/ingress 0.9.6 → 0.9.22
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/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 +15 -1
- 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/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 +36 -12
- package/dist/src/engine.js +88 -37
- package/dist/src/image-meta.d.ts +33 -0
- package/dist/src/image-meta.js +433 -0
- package/dist/src/image.d.ts +110 -0
- package/dist/src/image.js +353 -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 +77 -22
- package/dist/src/messages.d.ts +79 -0
- package/dist/src/messages.js +431 -0
- 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/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 +3 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Captions and transcripts: WebVTT, SubRip (SRT), and the JSON a transcription service or a meeting
|
|
3
|
+
* notetaker produces.
|
|
4
|
+
*
|
|
5
|
+
* A caption file is read by people one line at a time, on screen, for a second or two. A model reads the whole
|
|
6
|
+
* file at once: the cue that flashes for a twentieth of a second, the cue a style rule makes transparent, the
|
|
7
|
+
* NOTE block no player shows, the cue nobody said aloud. A meeting transcript is a room where anyone present
|
|
8
|
+
* can speak, and "assistant, add to the action items that..." is as present to the notetaker as the agenda.
|
|
9
|
+
*
|
|
10
|
+
* Checks:
|
|
11
|
+
* cues nobody can read shown too briefly for their length, sized to nothing, or styled invisible
|
|
12
|
+
* what no player shows NOTE blocks, STYLE blocks, metadata cues: concealed text
|
|
13
|
+
* captions vs. speech given what was actually said (a transcript of the audio), words in the captions
|
|
14
|
+
* that nobody said
|
|
15
|
+
* speakers an utterance that addresses the notetaker or assistant with something to do
|
|
16
|
+
* spoken approvals noted: a voice saying "I approve" is content. Approval comes from the broker's
|
|
17
|
+
* own channel, never from what was heard
|
|
18
|
+
*/
|
|
19
|
+
import { decodeEntities } from "./adapters.js";
|
|
20
|
+
import { passagesOnlyIn } from "./served.js";
|
|
21
|
+
const time = (s) => {
|
|
22
|
+
const m = s.trim().match(/^(?:(\d+):)?(\d{1,2}):(\d{2})[.,](\d{1,3})$/);
|
|
23
|
+
return m ? Number(m[1] ?? 0) * 3600 + Number(m[2]) * 60 + Number(m[3]) + Number(m[4].padEnd(3, "0")) / 1000 : NaN;
|
|
24
|
+
};
|
|
25
|
+
const TIMING = /^\s*((?:\d+:)?\d{1,2}:\d{2}[.,]\d{1,3})\s*-->\s*((?:\d+:)?\d{1,2}:\d{2}[.,]\d{1,3})(.*)$/;
|
|
26
|
+
export function looksLikeCaptions(text) {
|
|
27
|
+
const head = text.slice(0, 4000).replace(/^\uFEFF/, "");
|
|
28
|
+
return /^WEBVTT(?:[ \t\n\r]|$)/.test(head) || /^\s*\d+\s*\r?\n\s*\d{1,2}:\d{2}:\d{2}[,.]\d{1,3}\s*-->/m.test(head.slice(0, 400));
|
|
29
|
+
}
|
|
30
|
+
/** Is this JSON a transcript: utterances or segments with text and a time or a speaker? */
|
|
31
|
+
export function looksLikeTranscriptJson(doc) {
|
|
32
|
+
const list = transcriptList(doc);
|
|
33
|
+
if (!list || !list.length)
|
|
34
|
+
return false;
|
|
35
|
+
return list.slice(0, 30).every((u) => {
|
|
36
|
+
if (!u || typeof u !== "object")
|
|
37
|
+
return false;
|
|
38
|
+
const o = u;
|
|
39
|
+
const hasText = typeof o.text === "string" || typeof o.transcript === "string" || typeof o.sentence === "string";
|
|
40
|
+
const hasTime = ["start", "end", "start_time", "startTime", "offset", "timestamp", "start_ms"].some((k) => typeof o[k] === "number" || (typeof o[k] === "string" && /\d:\d\d/.test(o[k])));
|
|
41
|
+
const hasSpeaker = ["speaker", "speaker_name", "speakerName", "participant"].some((k) => typeof o[k] === "string" || typeof o[k] === "number");
|
|
42
|
+
return hasText && hasTime && (hasSpeaker || "end" in o || "duration" in o || "end_time" in o || "endTime" in o) && !("subject" in o) && !("is_from_me" in o);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function transcriptList(doc) {
|
|
46
|
+
if (Array.isArray(doc))
|
|
47
|
+
return doc;
|
|
48
|
+
if (doc && typeof doc === "object") {
|
|
49
|
+
const d = doc;
|
|
50
|
+
for (const k of ["utterances", "segments", "sentences", "transcript", "results", "monologues", "entries", "captions"])
|
|
51
|
+
if (Array.isArray(d[k]))
|
|
52
|
+
return d[k];
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
/** class names a STYLE block makes invisible; "*" when every cue is */
|
|
57
|
+
function hiddenClasses(style) {
|
|
58
|
+
const out = new Set();
|
|
59
|
+
for (const m of style.matchAll(/::cue(?:\(([^)]*)\))?\s*\{([^}]*)\}/g)) {
|
|
60
|
+
const body = m[2].toLowerCase().replace(/\s+/g, "");
|
|
61
|
+
const hides = /opacity:0(?:\.0+)?(?:;|$)|visibility:hidden|display:none|font-size:0(?:px|em|%|pt)?(?:;|$)|(?:^|;)color:(?:transparent|rgba\([^)]*,0(?:\.0+)?\)|#[0-9a-f]{6}00|#[0-9a-f]{3}0)(?:;|$)/.test(body);
|
|
62
|
+
if (!hides)
|
|
63
|
+
continue;
|
|
64
|
+
const sel = (m[1] ?? "").trim();
|
|
65
|
+
if (!sel)
|
|
66
|
+
out.add("*");
|
|
67
|
+
for (const c of sel.matchAll(/\.([\w-]+)/g))
|
|
68
|
+
out.add(c[1]);
|
|
69
|
+
for (const v of sel.matchAll(/v\[voice=["']?([^"'\]]+)/g))
|
|
70
|
+
out.add(`voice:${v[1]}`);
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
const untag = (t) => decodeEntities(t.replace(/<\d{1,2}:\d{2}(?::\d{2})?\.\d{3}>/g, "").replace(/<\/?[a-zA-Z][^>]*>/g, "").replace(/\{\\[^}]*\}/g, "")).text.replace(/[ \t]+/g, " ").trim();
|
|
75
|
+
export function parseCaptions(raw) {
|
|
76
|
+
const text = raw.replace(/^\uFEFF/, "").replace(/\r\n?/g, "\n");
|
|
77
|
+
const format = /^WEBVTT/.test(text) ? "vtt" : "srt";
|
|
78
|
+
const cues = [], notes = [], styles = [];
|
|
79
|
+
for (const block of text.split(/\n{2,}/).slice(0, 50_000)) {
|
|
80
|
+
const lines = block.split("\n");
|
|
81
|
+
if (/^WEBVTT/.test(lines[0])) {
|
|
82
|
+
if (lines.length > 1)
|
|
83
|
+
notes.push(lines.slice(1).join("\n"));
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (/^NOTE(?:\s|$)/.test(lines[0])) {
|
|
87
|
+
notes.push(block.replace(/^NOTE\s*/, ""));
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (/^STYLE\s*$/.test(lines[0])) {
|
|
91
|
+
styles.push(lines.slice(1).join("\n"));
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (/^REGION\s*$/.test(lines[0]))
|
|
95
|
+
continue;
|
|
96
|
+
const at = lines.findIndex((l) => TIMING.test(l));
|
|
97
|
+
if (at < 0) {
|
|
98
|
+
if (block.trim() && format === "vtt")
|
|
99
|
+
notes.push(block);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const m = lines[at].match(TIMING);
|
|
103
|
+
const body = lines.slice(at + 1).join("\n");
|
|
104
|
+
const speaker = body.match(/<v(?:\.[\w.-]+)?\s+([^>]+)>/)?.[1]?.trim() // (a plain "Word:" is as often the start of a sentence as a speaker: only ">> Name:" and "NAME:" count)
|
|
105
|
+
?? body.match(/^\s*>>\s*([A-Z][\w .'-]{1,30}):\s/)?.[1] ?? body.match(/^\s*([A-Z][A-Z .'-]{1,30}):\s/)?.[1];
|
|
106
|
+
cues.push({ start: time(m[1]), end: time(m[2]), text: untag(body), speaker, settings: m[3].trim() || undefined, classes: [...body.matchAll(/<c((?:\.[\w-]+)+)>/g)].flatMap((c) => c[1].split(".").filter(Boolean)), id: at > 0 ? lines[at - 1].trim() : undefined });
|
|
107
|
+
}
|
|
108
|
+
return { cues, notes, styles, format };
|
|
109
|
+
}
|
|
110
|
+
const NOTETAKER = /\b(?:note ?taker|notetaking (?:bot|assistant)|meeting (?:assistant|bot)|ai assistant|assistant|copilot|the (?:ai|bot|agent|model)|otter|fireflies|fathom|gemini|claude|chatgpt)\b[^.?!\n]{0,60}\b(?:add|record|write|put|include|insert|send|email|forward|share|schedule|create|delete|remove|ignore|disregard|forget|remember|note that|make sure|summari[sz]e (?:this|it) as|mark|assign|approve|grant)\b/i;
|
|
111
|
+
const SPOKEN_APPROVAL = /\b(?:i (?:hereby )?(?:approve|authori[sz]e|consent|give (?:my )?(?:approval|permission|consent))|you (?:have|'ve got) my (?:approval|permission|authori[sz]ation|consent)|(?:approved|permission granted|go ahead and (?:send|pay|delete|transfer|wire)))\b/i;
|
|
112
|
+
export function adaptCaptions(raw, hints = {}) {
|
|
113
|
+
const segments = [];
|
|
114
|
+
const findings = [];
|
|
115
|
+
const add = (f) => findings.push({ pass: "channel", action: "none", ...f });
|
|
116
|
+
let cues = [];
|
|
117
|
+
let label = "captions";
|
|
118
|
+
let doc;
|
|
119
|
+
const head = raw.trimStart()[0];
|
|
120
|
+
if (head === "{" || head === "[") {
|
|
121
|
+
try {
|
|
122
|
+
doc = JSON.parse(raw);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
doc = undefined;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const list = doc !== undefined ? transcriptList(doc) : undefined;
|
|
129
|
+
if (list) {
|
|
130
|
+
label = "transcript";
|
|
131
|
+
const sec = (v, ms = false) => (typeof v === "number" ? (ms || v > 100_000 ? v / 1000 : v) : typeof v === "string" ? (Number.isNaN(time(v.includes(".") || v.includes(",") ? v : `${v}.000`)) ? Number(v) || NaN : time(v.includes(".") || v.includes(",") ? v : `${v}.000`)) : NaN);
|
|
132
|
+
for (const u of list.slice(0, 50_000)) {
|
|
133
|
+
if (!u || typeof u !== "object")
|
|
134
|
+
continue;
|
|
135
|
+
const o = u;
|
|
136
|
+
const text = String(o.text ?? o.transcript ?? o.sentence ?? "").trim();
|
|
137
|
+
if (!text)
|
|
138
|
+
continue;
|
|
139
|
+
const start = sec(o.start ?? o.start_time ?? o.startTime ?? o.offset ?? o.timestamp ?? o.start_ms, "start_ms" in o);
|
|
140
|
+
const end = "duration" in o && typeof o.duration === "number" ? start + (o.duration > 1000 ? o.duration / 1000 : o.duration) : sec(o.end ?? o.end_time ?? o.endTime, false);
|
|
141
|
+
const sp = o.speaker ?? o.speaker_name ?? o.speakerName ?? o.participant;
|
|
142
|
+
cues.push({ start, end, text, speaker: sp === undefined ? undefined : typeof sp === "number" ? `Speaker ${sp}` : String(sp), classes: [] });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
const p = parseCaptions(raw);
|
|
147
|
+
cues = p.cues;
|
|
148
|
+
// what no player shows
|
|
149
|
+
p.notes.forEach((n, i) => { if (n.trim())
|
|
150
|
+
segments.push({ text: n.trim(), visibility: "comment", path: `captions/note[${i}]` }); });
|
|
151
|
+
const hidden = hiddenClasses(p.styles.join("\n"));
|
|
152
|
+
p.styles.forEach((s, i) => { const said = [...s.matchAll(/content\s*:\s*["']([^"']{8,})["']/g)].map((m) => m[1]); if (said.length)
|
|
153
|
+
segments.push({ text: said.join("\n"), visibility: "css_hidden", path: `captions/style[${i}]` }); });
|
|
154
|
+
if (hidden.size) {
|
|
155
|
+
const styled = cues.filter((c) => hidden.has("*") || c.classes.some((k) => hidden.has(k)) || (c.speaker && hidden.has(`voice:${c.speaker}`)));
|
|
156
|
+
if (styled.length) {
|
|
157
|
+
add({ kind: "captions.hidden_cue", confidence: 0.5, severity: 0.7, message: `${styled.length} cue(s) are styled invisible (transparent, zero size or hidden) by the file's own STYLE block: a player shows nothing, a program reading the file gets the words`, inHidden: true });
|
|
158
|
+
for (const c of styled) {
|
|
159
|
+
segments.push({ text: c.text, visibility: "css_hidden", path: `captions/cue@${fmt(c.start)}~styled-hidden` });
|
|
160
|
+
c.text = "";
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// cues nobody can read: shown too briefly for their length, or sized to nothing
|
|
166
|
+
const flashed = [];
|
|
167
|
+
for (const c of cues) {
|
|
168
|
+
if (!c.text)
|
|
169
|
+
continue;
|
|
170
|
+
const dur = c.end - c.start, chars = c.text.replace(/\s+/g, "").length, words = c.text.split(/\s+/).length;
|
|
171
|
+
const tiny = /(?:^|\s)size:[0-2]%/.test(c.settings ?? "");
|
|
172
|
+
const tooFast = Number.isFinite(dur) && words >= 4 && (dur <= 0.2 || chars / Math.max(dur, 0.001) > 60);
|
|
173
|
+
if (tiny || (label === "captions" && tooFast)) {
|
|
174
|
+
flashed.push(c);
|
|
175
|
+
segments.push({ text: c.text, visibility: "concealed", path: `captions/cue@${fmt(c.start)}~unreadable` });
|
|
176
|
+
c.text = "";
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (flashed.length)
|
|
180
|
+
add({ kind: "captions.unreadable_cue", confidence: 0.4, severity: 0.65, message: `${flashed.length} cue(s) are on screen too briefly to read, or sized to nothing (the first at ${fmt(flashed[0].start)}): a viewer cannot read them, a program reading the file does`, inHidden: true });
|
|
181
|
+
// the words, in order, with speakers
|
|
182
|
+
const outside = new Set((hints.outsideSpeakers ?? []).map((s) => s.toLowerCase()));
|
|
183
|
+
let last = "";
|
|
184
|
+
const shownParts = [];
|
|
185
|
+
cues.forEach((c, i) => {
|
|
186
|
+
if (!c.text)
|
|
187
|
+
return;
|
|
188
|
+
if (c.speaker && c.speaker !== last) {
|
|
189
|
+
segments.push({ text: c.speaker, visibility: "visible", path: `${label}[${i}]/speaker` });
|
|
190
|
+
last = c.speaker;
|
|
191
|
+
}
|
|
192
|
+
segments.push({ text: c.text, visibility: "visible", path: `${label}[${i}]/text` });
|
|
193
|
+
shownParts.push(c.text);
|
|
194
|
+
if (NOTETAKER.test(c.text))
|
|
195
|
+
add({ kind: "captions.addressed_to_notetaker", confidence: c.speaker && outside.has(c.speaker.toLowerCase()) ? 0.55 : 0.4, severity: 0.65, message: `${c.speaker ? `${c.speaker.slice(0, 40)} ` : "someone "}speaks to the notetaker or assistant with something to do (at ${fmt(c.start)})${c.speaker && outside.has(c.speaker.toLowerCase()) ? ", and is from outside the organisation" : ""}: what is said in a meeting is content, not an instruction to the one taking notes`, excerpt: c.text.slice(0, 160), location: `${label}[${i}]/text` });
|
|
196
|
+
else if (SPOKEN_APPROVAL.test(c.text))
|
|
197
|
+
add({ kind: "captions.spoken_approval", confidence: 0.05, severity: 0.2, message: `a spoken approval at ${fmt(c.start)}: a voice is never an approval. Actions are approved through the broker's own channel`, location: `${label}[${i}]/text` });
|
|
198
|
+
});
|
|
199
|
+
// captions that nobody said
|
|
200
|
+
if (hints.spoken && hints.spoken.trim().split(/\s+/).length >= 20) {
|
|
201
|
+
const only = passagesOnlyIn(shownParts.join(" "), hints.spoken, 8);
|
|
202
|
+
if (only.length) {
|
|
203
|
+
add({ kind: "captions.not_spoken", confidence: 0.4, severity: 0.6, message: `the captions say ${only.length} thing(s) that were not said aloud`, excerpt: only[0].slice(0, 160), inHidden: true });
|
|
204
|
+
only.forEach((t, i) => segments.push({ text: t, visibility: "concealed", path: `captions/not-spoken[${i}]` }));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return { segments, findings };
|
|
208
|
+
}
|
|
209
|
+
const fmt = (s) => (Number.isFinite(s) ? `${String(Math.floor(s / 60)).padStart(2, "0")}:${(s % 60).toFixed(1).padStart(4, "0")}` : "?");
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Change tracking (Kith & Revere lineage: Baselines.swift and Changes.swift, ported 2026-11-18).
|
|
3
|
+
*
|
|
4
|
+
* Two questions, asked the same way everywhere in Ingress:
|
|
5
|
+
* 1. What changed since last time? (diffSnapshots)
|
|
6
|
+
* 2. Did a person say this set is expected, and is it still that set? (BaselineStore)
|
|
7
|
+
*
|
|
8
|
+
* The rules that make the answers useful are Kith & Revere's:
|
|
9
|
+
* - An item is identified by what it is (a path, a label, a program), never by notes, sizes or dates,
|
|
10
|
+
* so routine churn does not count as a change.
|
|
11
|
+
* - A group that is new in this version of the software is not a change on the machine.
|
|
12
|
+
* - Groups whose lists churn on their own are left out of comparisons.
|
|
13
|
+
* - A confirmed set stays confirmed only while it is exactly that set. Any addition or removal sends it
|
|
14
|
+
* back to review and shows exactly what changed.
|
|
15
|
+
* - Where an item's content matters (an instruction file, a tool description), its fingerprint is part of
|
|
16
|
+
* its identity, so an edit is a change.
|
|
17
|
+
*/
|
|
18
|
+
export interface TrackedItem {
|
|
19
|
+
/** stable identity: what the item is */
|
|
20
|
+
key: string;
|
|
21
|
+
/** what to show a person */
|
|
22
|
+
label: string;
|
|
23
|
+
/** free text for display only; never part of the identity */
|
|
24
|
+
detail?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface Snapshot {
|
|
27
|
+
at: string;
|
|
28
|
+
/** software version that took it, for the "new group in this version" rule */
|
|
29
|
+
version: string;
|
|
30
|
+
groups: Record<string, TrackedItem[]>;
|
|
31
|
+
}
|
|
32
|
+
export interface GroupChange {
|
|
33
|
+
group: string;
|
|
34
|
+
added: TrackedItem[];
|
|
35
|
+
/** keys that were present before and are gone now */
|
|
36
|
+
removed: string[];
|
|
37
|
+
}
|
|
38
|
+
export interface SnapshotDiff {
|
|
39
|
+
previousAt: string;
|
|
40
|
+
changes: GroupChange[];
|
|
41
|
+
/** groups this snapshot has and the previous one did not: new checks, not changes on the machine */
|
|
42
|
+
newGroups: string[];
|
|
43
|
+
addedCount: number;
|
|
44
|
+
removedCount: number;
|
|
45
|
+
isEmpty: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** What changed between two snapshots, group by group. */
|
|
48
|
+
export declare function diffSnapshots(previous: Snapshot, current: Snapshot, opts?: {
|
|
49
|
+
volatile?: readonly string[];
|
|
50
|
+
}): SnapshotDiff;
|
|
51
|
+
export interface Baseline {
|
|
52
|
+
confirmedAt: string;
|
|
53
|
+
/** who or what confirmed: "person" (an explicit confirmation) or "first-seen" (recorded on first sight, not yet confirmed) */
|
|
54
|
+
by: "person" | "first-seen";
|
|
55
|
+
keys: string[];
|
|
56
|
+
}
|
|
57
|
+
export type ConfirmState = {
|
|
58
|
+
state: "none";
|
|
59
|
+
} | {
|
|
60
|
+
state: "first-seen";
|
|
61
|
+
since: string;
|
|
62
|
+
} | {
|
|
63
|
+
state: "confirmed";
|
|
64
|
+
at: string;
|
|
65
|
+
} | {
|
|
66
|
+
state: "changed";
|
|
67
|
+
since: string;
|
|
68
|
+
added: TrackedItem[];
|
|
69
|
+
removed: string[];
|
|
70
|
+
};
|
|
71
|
+
/** Compare the current items of a group with its baseline. */
|
|
72
|
+
export declare function confirmState(items: readonly TrackedItem[], baseline: Baseline | undefined): ConfirmState;
|
|
73
|
+
/** Where Ingress keeps its own state: INGRESS_STATE_DIR, else ~/.acepaste-ingress/state. */
|
|
74
|
+
export declare function stateDir(env?: NodeJS.ProcessEnv): string;
|
|
75
|
+
/**
|
|
76
|
+
* Confirmed sets, kept in one JSON file readable only by its owner. Only identities are stored.
|
|
77
|
+
* The store never confirms anything on its own: `confirm` is for a person's explicit action, and
|
|
78
|
+
* `recordFirstSeen` only remembers what was there, so a later change can be noticed.
|
|
79
|
+
*/
|
|
80
|
+
export declare class BaselineStore {
|
|
81
|
+
private readonly path;
|
|
82
|
+
private data;
|
|
83
|
+
constructor(path?: string);
|
|
84
|
+
get(group: string): Baseline | undefined;
|
|
85
|
+
state(group: string, items: readonly TrackedItem[]): ConfirmState;
|
|
86
|
+
/** A person says the current set is expected. */
|
|
87
|
+
confirm(group: string, items: readonly TrackedItem[], now?: Date): Baseline;
|
|
88
|
+
/** Remember a set the first time it is seen. Does nothing when a baseline already exists. */
|
|
89
|
+
recordFirstSeen(group: string, items: readonly TrackedItem[], now?: Date): ConfirmState;
|
|
90
|
+
revoke(group: string): void;
|
|
91
|
+
groups(): string[];
|
|
92
|
+
private save;
|
|
93
|
+
}
|
|
94
|
+
/** Snapshots on disk: one JSON file per run, named so they sort by time. */
|
|
95
|
+
export declare class SnapshotStore {
|
|
96
|
+
private readonly dir;
|
|
97
|
+
private readonly prefix;
|
|
98
|
+
constructor(dir: string, prefix: string);
|
|
99
|
+
save(s: Snapshot): string;
|
|
100
|
+
/** The most recent snapshot saved before `before` (default: the newest of all). */
|
|
101
|
+
latest(before?: string): Snapshot | undefined;
|
|
102
|
+
}
|
|
103
|
+
/** Fingerprint of a definition whose content matters: canonical JSON, sorted keys, sha256. */
|
|
104
|
+
export declare function fingerprint(value: unknown): string;
|
|
105
|
+
export declare function formatDiff(d: SnapshotDiff, what?: string): string;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Change tracking (Kith & Revere lineage: Baselines.swift and Changes.swift, ported 2026-11-18).
|
|
3
|
+
*
|
|
4
|
+
* Two questions, asked the same way everywhere in Ingress:
|
|
5
|
+
* 1. What changed since last time? (diffSnapshots)
|
|
6
|
+
* 2. Did a person say this set is expected, and is it still that set? (BaselineStore)
|
|
7
|
+
*
|
|
8
|
+
* The rules that make the answers useful are Kith & Revere's:
|
|
9
|
+
* - An item is identified by what it is (a path, a label, a program), never by notes, sizes or dates,
|
|
10
|
+
* so routine churn does not count as a change.
|
|
11
|
+
* - A group that is new in this version of the software is not a change on the machine.
|
|
12
|
+
* - Groups whose lists churn on their own are left out of comparisons.
|
|
13
|
+
* - A confirmed set stays confirmed only while it is exactly that set. Any addition or removal sends it
|
|
14
|
+
* back to review and shows exactly what changed.
|
|
15
|
+
* - Where an item's content matters (an instruction file, a tool description), its fingerprint is part of
|
|
16
|
+
* its identity, so an edit is a change.
|
|
17
|
+
*/
|
|
18
|
+
import { createHash } from "node:crypto";
|
|
19
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from "node:fs";
|
|
20
|
+
import { dirname, join } from "node:path";
|
|
21
|
+
import { homedir } from "node:os";
|
|
22
|
+
const uniqueByKey = (items) => [...new Map(items.map((i) => [i.key, i])).values()];
|
|
23
|
+
/** What changed between two snapshots, group by group. */
|
|
24
|
+
export function diffSnapshots(previous, current, opts = {}) {
|
|
25
|
+
const volatile = new Set(opts.volatile ?? []);
|
|
26
|
+
const changes = [];
|
|
27
|
+
const newGroups = [];
|
|
28
|
+
for (const group of Object.keys(current.groups).sort()) {
|
|
29
|
+
if (volatile.has(group))
|
|
30
|
+
continue;
|
|
31
|
+
if (!(group in previous.groups)) {
|
|
32
|
+
newGroups.push(group);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const before = new Set(previous.groups[group].map((i) => i.key));
|
|
36
|
+
const cur = uniqueByKey(current.groups[group]);
|
|
37
|
+
const now = new Set(cur.map((i) => i.key));
|
|
38
|
+
const added = cur.filter((i) => !before.has(i.key));
|
|
39
|
+
const removed = [...before].filter((k) => !now.has(k)).sort();
|
|
40
|
+
if (added.length || removed.length)
|
|
41
|
+
changes.push({ group, added, removed });
|
|
42
|
+
}
|
|
43
|
+
// a group that existed before and is entirely gone now: everything in it was removed
|
|
44
|
+
for (const group of Object.keys(previous.groups).sort()) {
|
|
45
|
+
if (volatile.has(group) || group in current.groups)
|
|
46
|
+
continue;
|
|
47
|
+
const removed = [...new Set(previous.groups[group].map((i) => i.key))].sort();
|
|
48
|
+
if (removed.length)
|
|
49
|
+
changes.push({ group, added: [], removed });
|
|
50
|
+
}
|
|
51
|
+
const addedCount = changes.reduce((n, c) => n + c.added.length, 0);
|
|
52
|
+
const removedCount = changes.reduce((n, c) => n + c.removed.length, 0);
|
|
53
|
+
return { previousAt: previous.at, changes, newGroups, addedCount, removedCount, isEmpty: !changes.length };
|
|
54
|
+
}
|
|
55
|
+
/** Compare the current items of a group with its baseline. */
|
|
56
|
+
export function confirmState(items, baseline) {
|
|
57
|
+
if (!baseline)
|
|
58
|
+
return { state: "none" };
|
|
59
|
+
const cur = uniqueByKey(items);
|
|
60
|
+
const before = new Set(baseline.keys);
|
|
61
|
+
const now = new Set(cur.map((i) => i.key));
|
|
62
|
+
const added = cur.filter((i) => !before.has(i.key));
|
|
63
|
+
const removed = baseline.keys.filter((k) => !now.has(k)).sort();
|
|
64
|
+
if (added.length || removed.length)
|
|
65
|
+
return { state: "changed", since: baseline.confirmedAt, added, removed };
|
|
66
|
+
return baseline.by === "person" ? { state: "confirmed", at: baseline.confirmedAt } : { state: "first-seen", since: baseline.confirmedAt };
|
|
67
|
+
}
|
|
68
|
+
/** Where Ingress keeps its own state: INGRESS_STATE_DIR, else ~/.acepaste-ingress/state. */
|
|
69
|
+
export function stateDir(env = process.env) {
|
|
70
|
+
return env.INGRESS_STATE_DIR || join(homedir(), ".acepaste-ingress", "state");
|
|
71
|
+
}
|
|
72
|
+
function writePrivate(path, text) {
|
|
73
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
74
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
75
|
+
writeFileSync(tmp, text, { mode: 0o600 });
|
|
76
|
+
renameSync(tmp, path); // a reader sees the old file or the new one, never half of either
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Confirmed sets, kept in one JSON file readable only by its owner. Only identities are stored.
|
|
80
|
+
* The store never confirms anything on its own: `confirm` is for a person's explicit action, and
|
|
81
|
+
* `recordFirstSeen` only remembers what was there, so a later change can be noticed.
|
|
82
|
+
*/
|
|
83
|
+
export class BaselineStore {
|
|
84
|
+
path;
|
|
85
|
+
data = {};
|
|
86
|
+
constructor(path = join(stateDir(), "baselines.json")) {
|
|
87
|
+
this.path = path;
|
|
88
|
+
try {
|
|
89
|
+
if (existsSync(path))
|
|
90
|
+
this.data = JSON.parse(readFileSync(path, "utf8"));
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
this.data = {};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
get(group) { return this.data[group]; }
|
|
97
|
+
state(group, items) { return confirmState(items, this.data[group]); }
|
|
98
|
+
/** A person says the current set is expected. */
|
|
99
|
+
confirm(group, items, now = new Date()) {
|
|
100
|
+
const b = { confirmedAt: now.toISOString(), by: "person", keys: [...new Set(items.map((i) => i.key))].sort() };
|
|
101
|
+
this.data[group] = b;
|
|
102
|
+
this.save();
|
|
103
|
+
return b;
|
|
104
|
+
}
|
|
105
|
+
/** Remember a set the first time it is seen. Does nothing when a baseline already exists. */
|
|
106
|
+
recordFirstSeen(group, items, now = new Date()) {
|
|
107
|
+
if (!this.data[group]) {
|
|
108
|
+
this.data[group] = { confirmedAt: now.toISOString(), by: "first-seen", keys: [...new Set(items.map((i) => i.key))].sort() };
|
|
109
|
+
this.save();
|
|
110
|
+
}
|
|
111
|
+
return this.state(group, items);
|
|
112
|
+
}
|
|
113
|
+
revoke(group) { delete this.data[group]; this.save(); }
|
|
114
|
+
groups() { return Object.keys(this.data).sort(); }
|
|
115
|
+
save() { writePrivate(this.path, JSON.stringify(this.data, null, 1)); }
|
|
116
|
+
}
|
|
117
|
+
/** Snapshots on disk: one JSON file per run, named so they sort by time. */
|
|
118
|
+
export class SnapshotStore {
|
|
119
|
+
dir;
|
|
120
|
+
prefix;
|
|
121
|
+
constructor(dir, prefix) {
|
|
122
|
+
this.dir = dir;
|
|
123
|
+
this.prefix = prefix;
|
|
124
|
+
}
|
|
125
|
+
save(s) {
|
|
126
|
+
const name = `${this.prefix}-${s.at.replace(/[:.]/g, "-")}.json`;
|
|
127
|
+
const path = join(this.dir, name);
|
|
128
|
+
writePrivate(path, JSON.stringify(s));
|
|
129
|
+
return path;
|
|
130
|
+
}
|
|
131
|
+
/** The most recent snapshot saved before `before` (default: the newest of all). */
|
|
132
|
+
latest(before) {
|
|
133
|
+
let names;
|
|
134
|
+
try {
|
|
135
|
+
names = readdirSync(this.dir).filter((n) => n.startsWith(`${this.prefix}-`) && n.endsWith(".json")).sort();
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
const cut = before ? `${this.prefix}-${before.replace(/[:.]/g, "-")}.json` : undefined;
|
|
141
|
+
const eligible = cut ? names.filter((n) => n < cut) : names;
|
|
142
|
+
for (let i = eligible.length - 1; i >= 0; i--) {
|
|
143
|
+
try {
|
|
144
|
+
return JSON.parse(readFileSync(join(this.dir, eligible[i]), "utf8"));
|
|
145
|
+
}
|
|
146
|
+
catch { /* a torn file: try the one before */ }
|
|
147
|
+
}
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** Fingerprint of a definition whose content matters: canonical JSON, sorted keys, sha256. */
|
|
152
|
+
export function fingerprint(value) {
|
|
153
|
+
const canon = (v) => {
|
|
154
|
+
if (Array.isArray(v))
|
|
155
|
+
return v.map(canon);
|
|
156
|
+
if (v && typeof v === "object")
|
|
157
|
+
return Object.fromEntries(Object.keys(v).sort().map((k) => [k, canon(v[k])]));
|
|
158
|
+
return v;
|
|
159
|
+
};
|
|
160
|
+
return createHash("sha256").update(JSON.stringify(canon(value)) ?? "null", "utf8").digest("hex");
|
|
161
|
+
}
|
|
162
|
+
export function formatDiff(d, what = "run") {
|
|
163
|
+
if (d.isEmpty)
|
|
164
|
+
return `Nothing changed since the last ${what} (${d.previousAt}).`;
|
|
165
|
+
const lines = [`Changed since the last ${what} (${d.previousAt}): ${d.addedCount} added, ${d.removedCount} removed`];
|
|
166
|
+
for (const c of d.changes) {
|
|
167
|
+
lines.push(` ${c.group}`);
|
|
168
|
+
for (const a of c.added)
|
|
169
|
+
lines.push(` + ${a.label}${a.detail ? ` (${a.detail})` : ""}`);
|
|
170
|
+
for (const r of c.removed)
|
|
171
|
+
lines.push(` - ${r}`);
|
|
172
|
+
}
|
|
173
|
+
return lines.join("\n");
|
|
174
|
+
}
|
package/dist/src/character.js
CHANGED
|
@@ -104,7 +104,18 @@ export function scanCharacters(text) {
|
|
|
104
104
|
cleaned = cleaned.slice(0, m.index) + cleaned.slice(m.index + 1);
|
|
105
105
|
}
|
|
106
106
|
// 3. Zero-width characters, script-aware.
|
|
107
|
-
|
|
107
|
+
// What counts is a zero-width character doing something to the text: splitting a word ("ig<ZWSP>nore") or
|
|
108
|
+
// standing in a run (a bit channel). One standing alone, or beside punctuation or space, is layout: a break
|
|
109
|
+
// hint in a long path, or the whole text of a heading anchor (VitePress writes one into every heading, and ten
|
|
110
|
+
// of them rated vuejs.org hostile). Layout ones are still removed from the cleaned text; they are not evidence.
|
|
111
|
+
const allZw = [...cleaned.matchAll(ZERO_WIDTH)];
|
|
112
|
+
const zwOne = new RegExp(`^(?:${ZERO_WIDTH.source})$`, ZERO_WIDTH.flags.replace("g", ""));
|
|
113
|
+
const isZw = (c) => c !== undefined && zwOne.test(c);
|
|
114
|
+
const isWordChar = (c) => c !== undefined && /[\p{L}\p{N}]/u.test(c);
|
|
115
|
+
const zw = allZw.filter((m) => {
|
|
116
|
+
const prev = cleaned[m.index - 1], next = cleaned[m.index + m[0].length];
|
|
117
|
+
return isZw(prev) || isZw(next) || (isWordChar(prev) && isWordChar(next));
|
|
118
|
+
});
|
|
108
119
|
const joinerStray = [];
|
|
109
120
|
for (let i = 0; i < cleaned.length; i++) {
|
|
110
121
|
const ch = cleaned[i];
|
|
@@ -143,6 +154,9 @@ export function scanCharacters(text) {
|
|
|
143
154
|
decodedPayloads.push(out);
|
|
144
155
|
}
|
|
145
156
|
}
|
|
157
|
+
}
|
|
158
|
+
// every zero-width character is removed from the cleaned text, whether or not it counted as evidence
|
|
159
|
+
if (allZw.length || joinerStray.length) {
|
|
146
160
|
// single pass removal: indices in joinerStray refer to the string before any removal
|
|
147
161
|
const drop = new Set(joinerStray);
|
|
148
162
|
let out = "";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare const CLASSIFIER_MODEL: {
|
|
2
|
+
format: string;
|
|
3
|
+
trainedAt: string;
|
|
4
|
+
nFeatures: number;
|
|
5
|
+
maxChars: number;
|
|
6
|
+
word: {
|
|
7
|
+
ngram: number[];
|
|
8
|
+
scale: number;
|
|
9
|
+
int8: string;
|
|
10
|
+
};
|
|
11
|
+
char: {
|
|
12
|
+
ngram: number[];
|
|
13
|
+
scale: number;
|
|
14
|
+
int8: string;
|
|
15
|
+
};
|
|
16
|
+
bias: number;
|
|
17
|
+
threshold: number;
|
|
18
|
+
validation: {
|
|
19
|
+
fprTarget: number;
|
|
20
|
+
rows: number;
|
|
21
|
+
};
|
|
22
|
+
trainedOn: {
|
|
23
|
+
"enron (benign)": number;
|
|
24
|
+
"generated hard negatives (nl) (benign)": number;
|
|
25
|
+
"oasst1 (explanatory prose) (benign)": number;
|
|
26
|
+
"SPML (benign)": number;
|
|
27
|
+
"oasst1 (what people ask) (benign)": number;
|
|
28
|
+
"SPML (attack)": number;
|
|
29
|
+
"multilingual (train) (benign)": number;
|
|
30
|
+
"dolly (instructions) (benign)": number;
|
|
31
|
+
"dolly (reference passages) (benign)": number;
|
|
32
|
+
"generated ordinary email (en) (benign)": number;
|
|
33
|
+
"llmail-inject Phase1 (attack)": number;
|
|
34
|
+
"generated hard negatives (pt) (benign)": number;
|
|
35
|
+
"generated hard negatives (en) (benign)": number;
|
|
36
|
+
"generated hard negatives (it) (benign)": number;
|
|
37
|
+
"generated hard negatives (tr) (benign)": number;
|
|
38
|
+
"generated hard negatives (fr) (benign)": number;
|
|
39
|
+
"generated hard negatives (de) (benign)": number;
|
|
40
|
+
"multilingual (train) (attack)": number;
|
|
41
|
+
"generated hard negatives (es) (benign)": number;
|
|
42
|
+
"llmail-inject Phase2 (attack)": number;
|
|
43
|
+
"gandalf (train) (attack)": number;
|
|
44
|
+
"jailbreak-classification (train) (attack)": number;
|
|
45
|
+
"deepset (train) (benign)": number;
|
|
46
|
+
"jailbreak-classification (train) (benign)": number;
|
|
47
|
+
"deepset (train) (attack)": number;
|
|
48
|
+
};
|
|
49
|
+
parity: {
|
|
50
|
+
text: string;
|
|
51
|
+
p: number;
|
|
52
|
+
}[];
|
|
53
|
+
};
|