@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,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audio: what a listener hears, and what is in the recording only for a machine.
|
|
3
|
+
*
|
|
4
|
+
* A person hears a recording once, through speakers, at the level it was mixed. A transcriber gets the
|
|
5
|
+
* samples. So the recording is transcribed several ways and the transcripts are compared:
|
|
6
|
+
*
|
|
7
|
+
* as heard the recording as it is
|
|
8
|
+
* quiet parts raised after strong level compression: speech mixed too low for a person to make out
|
|
9
|
+
* (under music, under another voice) becomes plain to a transcriber
|
|
10
|
+
* re-encoded limited to telephone bandwidth, squeezed through an 8-bit telephone codec, played
|
|
11
|
+
* slightly faster. Speech survives all three; a listener would understand every one.
|
|
12
|
+
* Audio crafted so that a transcriber hears words that are not there (an adversarial
|
|
13
|
+
* example) is fragile, and what is "heard" changes
|
|
14
|
+
*
|
|
15
|
+
* Words found only after the quiet parts are raised are concealed text. A transcript that changes when the
|
|
16
|
+
* audio is re-encoded is reported. The file's tags (title, comment, lyrics) are text nobody hears.
|
|
17
|
+
*
|
|
18
|
+
* Transcription is not built in. The engine calls a transcriber you choose, on this machine:
|
|
19
|
+
* INGRESS_AUDIO_TRANSCRIBER is a command that takes a file path and prints the report as JSON
|
|
20
|
+
* (tools/audio/transcribe.py is one, using an open Whisper model). Without it the tags are still read and the
|
|
21
|
+
* result says the recording was not transcribed.
|
|
22
|
+
*
|
|
23
|
+
* Limits: a voice cannot be told from a clone of it. Nothing above the range of the file (ultrasound played
|
|
24
|
+
* to a microphone) is in the file to find. And a voice is never an approval: what a recording says is content.
|
|
25
|
+
*/
|
|
26
|
+
import type { Finding, TextSegment } from "./types.js";
|
|
27
|
+
export type AudioFormat = "wav" | "mp3" | "m4a" | "flac" | "ogg" | "aiff" | "unknown";
|
|
28
|
+
export interface AudioReport {
|
|
29
|
+
/** seconds */
|
|
30
|
+
duration: number;
|
|
31
|
+
/** false when the recording could not be decoded */
|
|
32
|
+
decoded?: boolean;
|
|
33
|
+
variants: Array<{
|
|
34
|
+
name: string;
|
|
35
|
+
kind: "heard" | "quiet" | "reencoded";
|
|
36
|
+
text: string;
|
|
37
|
+
}>;
|
|
38
|
+
notes?: string[];
|
|
39
|
+
}
|
|
40
|
+
export type AudioRunner = (path: string) => Promise<AudioReport>;
|
|
41
|
+
export interface AudioCoverage {
|
|
42
|
+
format: string;
|
|
43
|
+
transcribed: boolean;
|
|
44
|
+
reason?: string;
|
|
45
|
+
seconds?: number;
|
|
46
|
+
notes: string[];
|
|
47
|
+
}
|
|
48
|
+
export interface AudioInspection {
|
|
49
|
+
format: AudioFormat;
|
|
50
|
+
texts: Array<{
|
|
51
|
+
field: string;
|
|
52
|
+
text: string;
|
|
53
|
+
}>;
|
|
54
|
+
report: string;
|
|
55
|
+
transcript?: AudioReport;
|
|
56
|
+
segments: TextSegment[];
|
|
57
|
+
findings: Finding[];
|
|
58
|
+
coverage: AudioCoverage;
|
|
59
|
+
}
|
|
60
|
+
export declare function detectAudioFormat(b: Uint8Array): AudioFormat;
|
|
61
|
+
/** Text in a recording's tags: ID3v2 frames (MP3, AIFF, WAV), RIFF INFO chunks, Vorbis comments (FLAC, Ogg). */
|
|
62
|
+
export declare function readAudioTags(b: Uint8Array): Array<{
|
|
63
|
+
field: string;
|
|
64
|
+
text: string;
|
|
65
|
+
}>;
|
|
66
|
+
/** The transcriber named by INGRESS_AUDIO_TRANSCRIBER: a command line; the file path is added as its last argument. */
|
|
67
|
+
export declare function commandRunner(command?: string, timeoutMs?: number): AudioRunner | undefined;
|
|
68
|
+
export declare function inspectAudio(bytes: Uint8Array, opts?: {
|
|
69
|
+
transcriber?: AudioRunner | false;
|
|
70
|
+
}): Promise<AudioInspection>;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audio: what a listener hears, and what is in the recording only for a machine.
|
|
3
|
+
*
|
|
4
|
+
* A person hears a recording once, through speakers, at the level it was mixed. A transcriber gets the
|
|
5
|
+
* samples. So the recording is transcribed several ways and the transcripts are compared:
|
|
6
|
+
*
|
|
7
|
+
* as heard the recording as it is
|
|
8
|
+
* quiet parts raised after strong level compression: speech mixed too low for a person to make out
|
|
9
|
+
* (under music, under another voice) becomes plain to a transcriber
|
|
10
|
+
* re-encoded limited to telephone bandwidth, squeezed through an 8-bit telephone codec, played
|
|
11
|
+
* slightly faster. Speech survives all three; a listener would understand every one.
|
|
12
|
+
* Audio crafted so that a transcriber hears words that are not there (an adversarial
|
|
13
|
+
* example) is fragile, and what is "heard" changes
|
|
14
|
+
*
|
|
15
|
+
* Words found only after the quiet parts are raised are concealed text. A transcript that changes when the
|
|
16
|
+
* audio is re-encoded is reported. The file's tags (title, comment, lyrics) are text nobody hears.
|
|
17
|
+
*
|
|
18
|
+
* Transcription is not built in. The engine calls a transcriber you choose, on this machine:
|
|
19
|
+
* INGRESS_AUDIO_TRANSCRIBER is a command that takes a file path and prints the report as JSON
|
|
20
|
+
* (tools/audio/transcribe.py is one, using an open Whisper model). Without it the tags are still read and the
|
|
21
|
+
* result says the recording was not transcribed.
|
|
22
|
+
*
|
|
23
|
+
* Limits: a voice cannot be told from a clone of it. Nothing above the range of the file (ultrasound played
|
|
24
|
+
* to a microphone) is in the file to find. And a voice is never an approval: what a recording says is content.
|
|
25
|
+
*/
|
|
26
|
+
import { execFile } from "node:child_process";
|
|
27
|
+
import { createHash } from "node:crypto";
|
|
28
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
29
|
+
import { tmpdir } from "node:os";
|
|
30
|
+
import { join } from "node:path";
|
|
31
|
+
import { passagesOnlyIn, servedWords } from "./served.js";
|
|
32
|
+
const ascii = (b, from, to) => { let s = ""; for (let i = from; i < to && i < b.length; i++)
|
|
33
|
+
s += String.fromCharCode(b[i]); return s; };
|
|
34
|
+
export function detectAudioFormat(b) {
|
|
35
|
+
if (ascii(b, 0, 4) === "RIFF" && ascii(b, 8, 12) === "WAVE")
|
|
36
|
+
return "wav";
|
|
37
|
+
if (ascii(b, 0, 3) === "ID3" || (b.length > 2 && b[0] === 0xff && (b[1] & 0xe0) === 0xe0))
|
|
38
|
+
return "mp3";
|
|
39
|
+
if (ascii(b, 4, 8) === "ftyp" && /M4A|M4B|mp4|isom|qt /.test(ascii(b, 8, 12)))
|
|
40
|
+
return "m4a";
|
|
41
|
+
if (ascii(b, 0, 4) === "fLaC")
|
|
42
|
+
return "flac";
|
|
43
|
+
if (ascii(b, 0, 4) === "OggS")
|
|
44
|
+
return "ogg";
|
|
45
|
+
if (ascii(b, 0, 4) === "FORM" && /AIF[FC]/.test(ascii(b, 8, 12)))
|
|
46
|
+
return "aiff";
|
|
47
|
+
return "unknown";
|
|
48
|
+
}
|
|
49
|
+
const TEXT_FRAMES = { TIT1: "grouping", TIT2: "title", TIT3: "subtitle", TALB: "album", TPE1: "artist", COMM: "comment", USLT: "lyrics", TXXX: "custom", TCOM: "composer", TENC: "encoded-by", TCOP: "copyright", WXXX: "link" };
|
|
50
|
+
/** Text in a recording's tags: ID3v2 frames (MP3, AIFF, WAV), RIFF INFO chunks, Vorbis comments (FLAC, Ogg). */
|
|
51
|
+
export function readAudioTags(b) {
|
|
52
|
+
const out = [];
|
|
53
|
+
const push = (field, text) => { const t = text.replace(/\0+/g, " ").replace(/[\x01-\x08\x0b\x0c\x0e-\x1f]/g, " ").trim().slice(0, 20_000); if (t.length >= 3)
|
|
54
|
+
out.push({ field, text: t }); };
|
|
55
|
+
const decode = (enc, bytes) => new TextDecoder(enc === 1 ? "utf-16" : enc === 2 ? "utf-16be" : enc === 3 ? "utf-8" : "latin1", { fatal: false }).decode(bytes);
|
|
56
|
+
const id3 = (at) => {
|
|
57
|
+
if (ascii(b, at, at + 3) !== "ID3" || at + 10 > b.length)
|
|
58
|
+
return;
|
|
59
|
+
const major = b[at + 3];
|
|
60
|
+
const size = ((b[at + 6] & 0x7f) << 21) | ((b[at + 7] & 0x7f) << 14) | ((b[at + 8] & 0x7f) << 7) | (b[at + 9] & 0x7f);
|
|
61
|
+
let o = at + 10;
|
|
62
|
+
const end = Math.min(b.length, at + 10 + size);
|
|
63
|
+
let guard = 0;
|
|
64
|
+
while (o + 10 <= end && guard++ < 2000) {
|
|
65
|
+
const id = ascii(b, o, o + 4);
|
|
66
|
+
if (!/^[A-Z0-9]{4}$/.test(id))
|
|
67
|
+
break;
|
|
68
|
+
const raw = [b[o + 4], b[o + 5], b[o + 6], b[o + 7]];
|
|
69
|
+
const len = major >= 4 ? ((raw[0] & 0x7f) << 21) | ((raw[1] & 0x7f) << 14) | ((raw[2] & 0x7f) << 7) | (raw[3] & 0x7f) : ((raw[0] << 24) | (raw[1] << 16) | (raw[2] << 8) | raw[3]) >>> 0;
|
|
70
|
+
const data = b.subarray(o + 10, Math.min(end, o + 10 + len));
|
|
71
|
+
const name = TEXT_FRAMES[id];
|
|
72
|
+
if (name && data.length > 1) {
|
|
73
|
+
// COMM and USLT: encoding, 3-letter language, a short description, then the text
|
|
74
|
+
const body = id === "COMM" || id === "USLT" ? data.subarray(4) : data.subarray(1);
|
|
75
|
+
push(`id3:${name}`, decode(data[0], body));
|
|
76
|
+
}
|
|
77
|
+
if (len <= 0)
|
|
78
|
+
break;
|
|
79
|
+
o += 10 + len;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
id3(0);
|
|
83
|
+
const fmt = detectAudioFormat(b);
|
|
84
|
+
if (fmt === "wav" || fmt === "aiff") {
|
|
85
|
+
const le = fmt === "wav";
|
|
86
|
+
const dv = new DataView(b.buffer, b.byteOffset, b.byteLength);
|
|
87
|
+
let o = 12, guard = 0;
|
|
88
|
+
while (o + 8 <= b.length && guard++ < 10_000) {
|
|
89
|
+
const id = ascii(b, o, o + 4), len = dv.getUint32(o + 4, le);
|
|
90
|
+
if (id === "LIST" && ascii(b, o + 8, o + 12) === "INFO") {
|
|
91
|
+
let p = o + 12;
|
|
92
|
+
while (p + 8 <= Math.min(b.length, o + 8 + len)) {
|
|
93
|
+
const k = ascii(b, p, p + 4), n = dv.getUint32(p + 4, true);
|
|
94
|
+
push(`info:${k}`, new TextDecoder("utf-8", { fatal: false }).decode(b.subarray(p + 8, Math.min(b.length, p + 8 + n))));
|
|
95
|
+
p += 8 + n + (n & 1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else if (id === "id3 " || id === "ID3 ")
|
|
99
|
+
id3(o + 8);
|
|
100
|
+
else if (["NAME", "AUTH", "ANNO", "(c) "].includes(id))
|
|
101
|
+
push(`aiff:${id.trim()}`, new TextDecoder("latin1").decode(b.subarray(o + 8, Math.min(b.length, o + 8 + len))));
|
|
102
|
+
o += 8 + len + (len & 1);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (fmt === "flac" || fmt === "ogg") {
|
|
106
|
+
// Vorbis comments are "KEY=value" strings preceded by a 4-byte length; find them by the vendor block's marker
|
|
107
|
+
const text = new TextDecoder("utf-8", { fatal: false }).decode(b.subarray(0, Math.min(b.length, 1_000_000)));
|
|
108
|
+
for (const m of text.matchAll(/\b(TITLE|DESCRIPTION|COMMENT|LYRICS|ARTIST|ALBUM|UNSYNCEDLYRICS)=([^\0\x01-\x08]{3,4000})/gi))
|
|
109
|
+
push(`vorbis:${m[1].toLowerCase()}`, m[2].replace(/[\x0e-\x1f][\s\S]*$/, ""));
|
|
110
|
+
}
|
|
111
|
+
const seen = new Set();
|
|
112
|
+
return out.filter((t) => !seen.has(t.text) && seen.add(t.text)).slice(0, 60);
|
|
113
|
+
}
|
|
114
|
+
/** The transcriber named by INGRESS_AUDIO_TRANSCRIBER: a command line; the file path is added as its last argument. */
|
|
115
|
+
export function commandRunner(command = process.env.INGRESS_AUDIO_TRANSCRIBER ?? "", timeoutMs = 600_000) {
|
|
116
|
+
const parts = command.match(/"[^"]*"|'[^']*'|\S+/g)?.map((p) => p.replace(/^(["'])(.*)\1$/, "$2"));
|
|
117
|
+
if (!parts?.length)
|
|
118
|
+
return undefined;
|
|
119
|
+
return (path) => new Promise((resolve, reject) => {
|
|
120
|
+
execFile(parts[0], [...parts.slice(1), path], { timeout: timeoutMs, maxBuffer: 64 * 1024 * 1024, encoding: "utf8" }, (err, stdout) => {
|
|
121
|
+
if (err)
|
|
122
|
+
return reject(new Error(`the transcriber failed (${String(err.message).slice(0, 160)})`));
|
|
123
|
+
try {
|
|
124
|
+
const r = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
125
|
+
if (!Array.isArray(r.variants))
|
|
126
|
+
throw new Error("no variants in its report");
|
|
127
|
+
resolve(r);
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
reject(new Error(`the transcriber's report could not be read (${e.message})`));
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const EXT = { wav: "wav", mp3: "mp3", m4a: "m4a", flac: "flac", ogg: "ogg", aiff: "aiff", unknown: "bin" };
|
|
136
|
+
const wordSet = (t) => new Set(servedWords(t));
|
|
137
|
+
/** share of a's words that b also has */
|
|
138
|
+
function overlap(a, b) {
|
|
139
|
+
const A = servedWords(a), B = wordSet(b);
|
|
140
|
+
return A.length ? A.filter((w) => B.has(w)).length / A.length : 1;
|
|
141
|
+
}
|
|
142
|
+
export async function inspectAudio(bytes, opts = {}) {
|
|
143
|
+
const format = detectAudioFormat(bytes);
|
|
144
|
+
const texts = readAudioTags(bytes);
|
|
145
|
+
const segments = [];
|
|
146
|
+
const findings = [];
|
|
147
|
+
const coverage = { format, transcribed: false, notes: [] };
|
|
148
|
+
const add = (f) => findings.push({ pass: "channel", action: "none", ...f });
|
|
149
|
+
const routine = /^(?:id3:(?:title|album|artist|composer|encoded-by|copyright|grouping)|info:(?:INAM|IART|IPRD|ISFT|ICRD|IGNR|ICOP)|vorbis:(?:title|artist|album)|aiff:(?:NAME|AUTH))$/;
|
|
150
|
+
for (const t of texts)
|
|
151
|
+
if (!routine.test(t.field) || t.text.split(/\s+/).length >= 12)
|
|
152
|
+
segments.push({ text: t.text, visibility: "concealed", path: `audio/metadata:${t.field}` });
|
|
153
|
+
if (segments.length)
|
|
154
|
+
add({ kind: "audio.metadata_text", confidence: 0.1, severity: 0.2, message: `the file's tags hold text nobody hears (${segments.slice(0, 4).map((s) => s.path.replace("audio/metadata:", "")).join(", ")})`, inHidden: true });
|
|
155
|
+
let transcript;
|
|
156
|
+
const runner = opts.transcriber === false ? undefined : opts.transcriber ?? commandRunner();
|
|
157
|
+
if (format === "unknown")
|
|
158
|
+
coverage.reason = "not a recognised audio format";
|
|
159
|
+
else if (opts.transcriber === false)
|
|
160
|
+
coverage.reason = "transcription was turned off";
|
|
161
|
+
else if (!runner)
|
|
162
|
+
coverage.reason = "no transcriber is configured (set INGRESS_AUDIO_TRANSCRIBER; see tools/audio)";
|
|
163
|
+
else {
|
|
164
|
+
const dir = mkdtempSync(join(tmpdir(), "ingress-audio-"));
|
|
165
|
+
const file = join(dir, `audio.${EXT[format]}`);
|
|
166
|
+
try {
|
|
167
|
+
writeFileSync(file, bytes, { mode: 0o600 });
|
|
168
|
+
const got = await runner(file);
|
|
169
|
+
coverage.notes.push(...(got.notes ?? []));
|
|
170
|
+
if (got.decoded === false)
|
|
171
|
+
coverage.reason = got.notes?.[0] ?? "the recording could not be decoded";
|
|
172
|
+
else {
|
|
173
|
+
transcript = got;
|
|
174
|
+
coverage.transcribed = true;
|
|
175
|
+
coverage.seconds = got.duration;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
coverage.reason = e.message;
|
|
180
|
+
}
|
|
181
|
+
finally {
|
|
182
|
+
try {
|
|
183
|
+
rmSync(dir, { recursive: true, force: true });
|
|
184
|
+
}
|
|
185
|
+
catch { /* temp folder */ }
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (transcript) {
|
|
189
|
+
const heard = transcript.variants.find((v) => v.kind === "heard")?.text.trim() ?? "";
|
|
190
|
+
if (heard)
|
|
191
|
+
segments.unshift({ text: heard, visibility: "visible", path: "audio/speech" });
|
|
192
|
+
// speech a listener cannot make out
|
|
193
|
+
const re = transcript.variants.filter((v) => v.kind === "reencoded");
|
|
194
|
+
const everythingHeard = [heard, ...re.map((v) => v.text)].join(" ");
|
|
195
|
+
for (const q of transcript.variants.filter((v) => v.kind === "quiet")) {
|
|
196
|
+
const only = passagesOnlyIn(q.text, everythingHeard, 5);
|
|
197
|
+
if (!only.length)
|
|
198
|
+
continue;
|
|
199
|
+
only.forEach((t, i) => segments.push({ text: t, visibility: "concealed", path: `audio/quiet-speech[${i}]` }));
|
|
200
|
+
add({ kind: "audio.quiet_speech", confidence: 0.4, severity: 0.6, message: `${only.join(" ").split(/\s+/).length} words are spoken too quietly to make out and become plain once the quiet parts are raised (${q.name})`, excerpt: only[0].slice(0, 160), inHidden: true });
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
// what is heard should not depend on an encoding a listener would not notice
|
|
204
|
+
const words = servedWords(heard).length;
|
|
205
|
+
if (words >= 6 && re.length >= 2) {
|
|
206
|
+
const kept = re.map((v) => ({ name: v.name, share: overlap(heard, v.text) }));
|
|
207
|
+
const lost = kept.filter((k) => k.share < 0.4);
|
|
208
|
+
// the re-encodings agreeing with each other while disagreeing with the original is the mark of crafted audio
|
|
209
|
+
const agree = re.length >= 2 ? overlap(re[0].text, re[1].text) : 0;
|
|
210
|
+
if (lost.length >= 2 || (lost.length >= 1 && lost.length === re.length)) {
|
|
211
|
+
add({ kind: "audio.transcript_unstable", confidence: agree >= 0.6 ? 0.5 : 0.35, severity: 0.65, message: `what a transcriber hears changes when the recording is re-encoded in ways a listener would not notice (${lost.map((k) => `${k.name}: ${(k.share * 100).toFixed(0)}% of the words survive`).join("; ")}). Speech does not do that; audio crafted to be mis-heard does` });
|
|
212
|
+
const stable = re.reduce((a, v) => (v.text.length > a.length ? v.text : a), "");
|
|
213
|
+
if (stable.trim())
|
|
214
|
+
segments.push({ text: stable, visibility: "visible", path: "audio/speech~after-re-encoding" });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
add({ kind: "audio.not_transcribed", confidence: 0.1, severity: 0.2, message: `the recording was not transcribed: ${coverage.reason}. What is said in it was not checked` });
|
|
220
|
+
segments.push({ text: `[audio, ${format}: not transcribed (${coverage.reason})]`, visibility: "visible", path: "audio/note" });
|
|
221
|
+
}
|
|
222
|
+
const report = JSON.stringify({ sha256: createHash("sha256").update(bytes).digest("hex"), format, transcribed: coverage.transcribed, seconds: transcript?.duration, segments: segments.map((s) => ({ path: s.path, visibility: s.visibility, text: s.text })) });
|
|
223
|
+
return { format, texts, report, transcript, segments, findings, coverage };
|
|
224
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The environment audit, compared with the last one and with what a person confirmed.
|
|
3
|
+
* Identity rules follow Kith & Revere: what an item is, not its notes or counts.
|
|
4
|
+
*/
|
|
5
|
+
import type { AuditReport } from "./audit.js";
|
|
6
|
+
import type { AuditArea, AuditFinding } from "./audit-parsers.js";
|
|
7
|
+
import { type ConfirmState, type Snapshot, type SnapshotDiff, type TrackedItem } from "./changes.js";
|
|
8
|
+
/** Areas whose results depend on the network the machine is on right now; they would drown real changes. */
|
|
9
|
+
export declare const AUDIT_VOLATILE: readonly AuditArea[];
|
|
10
|
+
/**
|
|
11
|
+
* Areas a person should confirm once: things that can change what agents receive or do.
|
|
12
|
+
* Until confirmed (and whenever they change) they need attention.
|
|
13
|
+
*/
|
|
14
|
+
export declare const AUDIT_NEEDS_CONFIRMATION: readonly AuditArea[];
|
|
15
|
+
/** Stable identity of one audit finding, or undefined when the finding is not worth tracking. */
|
|
16
|
+
export declare function auditItemKey(f: AuditFinding): string | undefined;
|
|
17
|
+
export declare function auditSnapshot(r: AuditReport): Snapshot;
|
|
18
|
+
export interface AuditAttention {
|
|
19
|
+
area: string;
|
|
20
|
+
state: ConfirmState;
|
|
21
|
+
items: TrackedItem[];
|
|
22
|
+
}
|
|
23
|
+
export interface AuditChanges {
|
|
24
|
+
/** undefined on the first audit: there is nothing to compare with */
|
|
25
|
+
diff?: SnapshotDiff;
|
|
26
|
+
/** areas waiting for a person: never confirmed, or changed since they were */
|
|
27
|
+
needsAttention: AuditAttention[];
|
|
28
|
+
confirmed: string[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Save this audit's snapshot and report what changed since the previous one, and which areas a person
|
|
32
|
+
* still needs to confirm. `dir` defaults to Ingress's state folder.
|
|
33
|
+
*/
|
|
34
|
+
export declare function trackAudit(r: AuditReport, opts?: {
|
|
35
|
+
dir?: string;
|
|
36
|
+
save?: boolean;
|
|
37
|
+
}): AuditChanges;
|
|
38
|
+
/** A person confirms the current items of one audit area as expected. */
|
|
39
|
+
export declare function confirmAuditArea(r: AuditReport, area: AuditArea, opts?: {
|
|
40
|
+
dir?: string;
|
|
41
|
+
now?: Date;
|
|
42
|
+
}): {
|
|
43
|
+
area: string;
|
|
44
|
+
items: number;
|
|
45
|
+
};
|
|
46
|
+
export declare function formatAuditChanges(c: AuditChanges): string;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The environment audit, compared with the last one and with what a person confirmed.
|
|
3
|
+
* Identity rules follow Kith & Revere: what an item is, not its notes or counts.
|
|
4
|
+
*/
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { BaselineStore, SnapshotStore, diffSnapshots, fingerprint, formatDiff, stateDir } from "./changes.js";
|
|
7
|
+
import { ENGINE_VERSION } from "./types.js";
|
|
8
|
+
/** Areas whose results depend on the network the machine is on right now; they would drown real changes. */
|
|
9
|
+
export const AUDIT_VOLATILE = ["resolution"];
|
|
10
|
+
/**
|
|
11
|
+
* Areas a person should confirm once: things that can change what agents receive or do.
|
|
12
|
+
* Until confirmed (and whenever they change) they need attention.
|
|
13
|
+
*/
|
|
14
|
+
export const AUDIT_NEEDS_CONFIRMATION = [
|
|
15
|
+
"agent-config", "agent-instructions", "certificates", "network-extension", "proxy", "browser-policy", "browser-extension", "browser-search", "hosts", "dns",
|
|
16
|
+
"input-devices", "listening", "tunnels", "printers", "network-interfaces",
|
|
17
|
+
];
|
|
18
|
+
/** Stable identity of one audit finding, or undefined when the finding is not worth tracking. */
|
|
19
|
+
export function auditItemKey(f) {
|
|
20
|
+
// the DNS servers in use change with every network a laptop joins
|
|
21
|
+
if (f.area === "dns" && f.title.startsWith("DNS servers:"))
|
|
22
|
+
return undefined;
|
|
23
|
+
// local-only listeners come and go with every dev server; the ones the network can reach are what a person confirms
|
|
24
|
+
if (f.area === "listening" && f.title.endsWith("listens on this machine only"))
|
|
25
|
+
return undefined;
|
|
26
|
+
const where = f.where ?? "";
|
|
27
|
+
// content matters here: an edited instruction file or hook is a change even though its path is the same
|
|
28
|
+
if (f.area === "agent-instructions") {
|
|
29
|
+
const sha = f.detail.match(/fingerprint ([0-9a-f]{12})/)?.[1] ?? "flagged";
|
|
30
|
+
return `${where} @ ${sha}`;
|
|
31
|
+
}
|
|
32
|
+
if (f.area === "agent-config" && /agent hook command/.test(f.title))
|
|
33
|
+
return `${where} | agent hooks @ ${fingerprint(f.detail).slice(0, 12)}`;
|
|
34
|
+
// blocklist sizes change whenever the list updates; the fact that a blocklist is there does not
|
|
35
|
+
const title = /\b(blocked|blocks|cloaks)\b/.test(f.title) ? f.title.replace(/\d+/g, "N") : f.title;
|
|
36
|
+
return `${where} | ${title}`;
|
|
37
|
+
}
|
|
38
|
+
export function auditSnapshot(r) {
|
|
39
|
+
const groups = {};
|
|
40
|
+
// every area that was looked at gets a group, so "nothing there" is a state that can change
|
|
41
|
+
for (const c of r.checked)
|
|
42
|
+
if (c.status === "checked")
|
|
43
|
+
groups[c.area] ??= [];
|
|
44
|
+
for (const f of r.findings) {
|
|
45
|
+
const key = auditItemKey(f);
|
|
46
|
+
if (key === undefined)
|
|
47
|
+
continue;
|
|
48
|
+
(groups[f.area] ??= []).push({ key, label: f.title, detail: f.where });
|
|
49
|
+
}
|
|
50
|
+
return { at: r.at, version: ENGINE_VERSION, groups };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Save this audit's snapshot and report what changed since the previous one, and which areas a person
|
|
54
|
+
* still needs to confirm. `dir` defaults to Ingress's state folder.
|
|
55
|
+
*/
|
|
56
|
+
export function trackAudit(r, opts = {}) {
|
|
57
|
+
const dir = opts.dir ?? stateDir();
|
|
58
|
+
const snaps = new SnapshotStore(join(dir, "audit-snapshots"), "audit");
|
|
59
|
+
const baselines = new BaselineStore(join(dir, "baselines.json"));
|
|
60
|
+
const current = auditSnapshot(r);
|
|
61
|
+
const previous = snaps.latest(current.at);
|
|
62
|
+
const diff = previous ? diffSnapshots(previous, current, { volatile: AUDIT_VOLATILE }) : undefined;
|
|
63
|
+
if (opts.save !== false)
|
|
64
|
+
snaps.save(current);
|
|
65
|
+
const needsAttention = [];
|
|
66
|
+
const confirmed = [];
|
|
67
|
+
for (const area of AUDIT_NEEDS_CONFIRMATION) {
|
|
68
|
+
const items = current.groups[area];
|
|
69
|
+
if (items === undefined)
|
|
70
|
+
continue; // not checked on this platform
|
|
71
|
+
const state = baselines.state(`audit:${area}`, items);
|
|
72
|
+
if (state.state === "confirmed")
|
|
73
|
+
confirmed.push(area);
|
|
74
|
+
// an area with nothing in it and nothing ever confirmed needs no one's attention
|
|
75
|
+
else if (state.state === "changed" || items.length)
|
|
76
|
+
needsAttention.push({ area, state, items });
|
|
77
|
+
}
|
|
78
|
+
return { diff, needsAttention, confirmed };
|
|
79
|
+
}
|
|
80
|
+
/** A person confirms the current items of one audit area as expected. */
|
|
81
|
+
export function confirmAuditArea(r, area, opts = {}) {
|
|
82
|
+
const baselines = new BaselineStore(join(opts.dir ?? stateDir(), "baselines.json"));
|
|
83
|
+
const items = auditSnapshot(r).groups[area] ?? [];
|
|
84
|
+
baselines.confirm(`audit:${area}`, items, opts.now);
|
|
85
|
+
return { area, items: items.length };
|
|
86
|
+
}
|
|
87
|
+
export function formatAuditChanges(c) {
|
|
88
|
+
const lines = [];
|
|
89
|
+
lines.push(c.diff ? formatDiff(c.diff, "audit") : "First audit on this machine: nothing to compare with yet.");
|
|
90
|
+
if (c.diff?.newGroups.length)
|
|
91
|
+
lines.push(` (newly checked in this version, not a change on the machine: ${c.diff.newGroups.join(", ")})`);
|
|
92
|
+
if (c.needsAttention.length) {
|
|
93
|
+
lines.push("", "Needs your confirmation (things that can change what agents receive or do):");
|
|
94
|
+
for (const a of c.needsAttention) {
|
|
95
|
+
if (a.state.state === "changed") {
|
|
96
|
+
lines.push(` ${a.area}: changed since you confirmed it on ${a.state.since}`);
|
|
97
|
+
for (const x of a.state.added)
|
|
98
|
+
lines.push(` + ${x.label}`);
|
|
99
|
+
for (const x of a.state.removed)
|
|
100
|
+
lines.push(` - ${x}`);
|
|
101
|
+
}
|
|
102
|
+
else
|
|
103
|
+
lines.push(` ${a.area}: ${a.items.length} item(s), never confirmed`);
|
|
104
|
+
}
|
|
105
|
+
lines.push(" Confirm an area once it looks right: ingress audit confirm <area>");
|
|
106
|
+
}
|
|
107
|
+
if (c.confirmed.length)
|
|
108
|
+
lines.push("", `Confirmed and unchanged: ${c.confirmed.join(", ")}`);
|
|
109
|
+
return lines.join("\n");
|
|
110
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment audit, local side: what is attached to this machine and what it exposes.
|
|
3
|
+
* Pure parsers and classifiers (no file, process or network access here). Collectors are in audit.ts.
|
|
4
|
+
*
|
|
5
|
+
* input devices A device that presents itself as a keyboard types as the person. In an agent's terminal
|
|
6
|
+
* keystrokes are the user, so no content check ever sees them (BadUSB, "rubber ducky"
|
|
7
|
+
* cables, an unauthenticated Bluetooth keyboard). The audit cannot watch typing; it can say
|
|
8
|
+
* which keyboards exist, so a new one is noticed.
|
|
9
|
+
* listening What accepts connections, and whether from this machine only or from the network.
|
|
10
|
+
* Identity is the program and its exposure, not the port (ports change on every restart).
|
|
11
|
+
* tunnels A tunnel or reverse forward turns a local port into an internet address: "localhost"
|
|
12
|
+
* stops being local.
|
|
13
|
+
* printers A printer's name and address are set by whoever is on the network; a print job sends a
|
|
14
|
+
* document there.
|
|
15
|
+
* interfaces A new network adapter (a USB Ethernet dongle) can take over routing and DNS.
|
|
16
|
+
*/
|
|
17
|
+
import type { AuditFinding } from "./audit-parsers.js";
|
|
18
|
+
export interface HidDevice {
|
|
19
|
+
vendorId: string;
|
|
20
|
+
productId: string;
|
|
21
|
+
transport: string;
|
|
22
|
+
product: string;
|
|
23
|
+
usagePage: number;
|
|
24
|
+
usage: number;
|
|
25
|
+
builtIn: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** Parse `hidutil list`. Columns are fixed-width; the header gives their positions. */
|
|
28
|
+
export declare function parseHidutilList(text: string): HidDevice[];
|
|
29
|
+
export declare function classifyInputDevices(devices: readonly HidDevice[]): AuditFinding[];
|
|
30
|
+
export interface Listener {
|
|
31
|
+
command: string;
|
|
32
|
+
pid: number;
|
|
33
|
+
user: string;
|
|
34
|
+
address: string;
|
|
35
|
+
port: number;
|
|
36
|
+
exposed: boolean;
|
|
37
|
+
}
|
|
38
|
+
export declare function parseLsofListen(text: string): Listener[];
|
|
39
|
+
export declare function classifyListeners(listeners: readonly Listener[]): AuditFinding[];
|
|
40
|
+
export interface Tunnel {
|
|
41
|
+
tool: string;
|
|
42
|
+
detail: string;
|
|
43
|
+
}
|
|
44
|
+
export declare function findTunnels(psOutput: string): Tunnel[];
|
|
45
|
+
export declare function classifyTunnels(tunnels: readonly Tunnel[]): AuditFinding[];
|
|
46
|
+
export interface Printer {
|
|
47
|
+
name: string;
|
|
48
|
+
uri: string;
|
|
49
|
+
}
|
|
50
|
+
export declare function parseLpstatDevices(text: string): Printer[];
|
|
51
|
+
export declare function classifyPrinters(printers: readonly Printer[]): AuditFinding[];
|
|
52
|
+
export interface HardwarePort {
|
|
53
|
+
port: string;
|
|
54
|
+
device: string;
|
|
55
|
+
}
|
|
56
|
+
export declare function parseHardwarePorts(text: string): HardwarePort[];
|
|
57
|
+
export declare function classifyHardwarePorts(ports: readonly HardwarePort[]): AuditFinding[];
|