@wrenautomation/birdwatch 0.0.0-stage → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +61 -0
- package/README.md +337 -2
- package/dist/app/cli.d.ts +4 -0
- package/dist/app/cli.js +149 -0
- package/dist/app/cli.js.map +1 -0
- package/dist/app/engine-cli.d.ts +50 -0
- package/dist/app/engine-cli.js +738 -0
- package/dist/app/engine-cli.js.map +1 -0
- package/dist/app/index.d.ts +6 -0
- package/dist/app/index.js +7 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/serve.d.ts +14 -0
- package/dist/app/serve.js +102 -0
- package/dist/app/serve.js.map +1 -0
- package/dist/document/body.d.ts +6 -0
- package/dist/document/body.js +18 -0
- package/dist/document/body.js.map +1 -0
- package/dist/document/check.d.ts +35 -0
- package/dist/document/check.js +68 -0
- package/dist/document/check.js.map +1 -0
- package/dist/document/extract.d.ts +81 -0
- package/dist/document/extract.js +226 -0
- package/dist/document/extract.js.map +1 -0
- package/dist/document/index.d.ts +11 -0
- package/dist/document/index.js +12 -0
- package/dist/document/index.js.map +1 -0
- package/dist/document/model.d.ts +10 -0
- package/dist/document/model.js +2 -0
- package/dist/document/model.js.map +1 -0
- package/dist/document/readers.d.ts +24 -0
- package/dist/document/readers.js +87 -0
- package/dist/document/readers.js.map +1 -0
- package/dist/document/types.d.ts +99 -0
- package/dist/document/types.js +93 -0
- package/dist/document/types.js.map +1 -0
- package/dist/engine/agent.d.ts +473 -0
- package/dist/engine/agent.js +989 -0
- package/dist/engine/agent.js.map +1 -0
- package/dist/engine/canonical.d.ts +4 -0
- package/dist/engine/canonical.js +55 -0
- package/dist/engine/canonical.js.map +1 -0
- package/dist/engine/cost.d.ts +13 -0
- package/dist/engine/cost.js +31 -0
- package/dist/engine/cost.js.map +1 -0
- package/dist/engine/index.d.ts +16 -0
- package/dist/engine/index.js +17 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/judge.d.ts +158 -0
- package/dist/engine/judge.js +323 -0
- package/dist/engine/judge.js.map +1 -0
- package/dist/engine/people.d.ts +34 -0
- package/dist/engine/people.js +125 -0
- package/dist/engine/people.js.map +1 -0
- package/dist/engine/plan.d.ts +6 -0
- package/dist/engine/plan.js +7 -0
- package/dist/engine/plan.js.map +1 -0
- package/dist/engine/ports.d.ts +124 -0
- package/dist/engine/ports.js +28 -0
- package/dist/engine/ports.js.map +1 -0
- package/dist/engine/recall.d.ts +42 -0
- package/dist/engine/recall.js +71 -0
- package/dist/engine/recall.js.map +1 -0
- package/dist/engine/runner.d.ts +30 -0
- package/dist/engine/runner.js +209 -0
- package/dist/engine/runner.js.map +1 -0
- package/dist/engine/state.d.ts +99 -0
- package/dist/engine/state.js +186 -0
- package/dist/engine/state.js.map +1 -0
- package/dist/engine/steps.d.ts +98 -0
- package/dist/engine/steps.js +560 -0
- package/dist/engine/steps.js.map +1 -0
- package/dist/engine/tree.d.ts +76 -0
- package/dist/engine/tree.js +148 -0
- package/dist/engine/tree.js.map +1 -0
- package/dist/engine/view.d.ts +138 -0
- package/dist/engine/view.js +188 -0
- package/dist/engine/view.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/ledger/files.d.ts +39 -0
- package/dist/ledger/files.js +113 -0
- package/dist/ledger/files.js.map +1 -0
- package/dist/ledger/ids.d.ts +4 -0
- package/dist/ledger/ids.js +9 -0
- package/dist/ledger/ids.js.map +1 -0
- package/dist/ledger/index.d.ts +11 -0
- package/dist/ledger/index.js +12 -0
- package/dist/ledger/index.js.map +1 -0
- package/dist/ledger/ledger.d.ts +46 -0
- package/dist/ledger/ledger.js +105 -0
- package/dist/ledger/ledger.js.map +1 -0
- package/dist/ledger/memory.d.ts +19 -0
- package/dist/ledger/memory.js +19 -0
- package/dist/ledger/memory.js.map +1 -0
- package/dist/ledger/records.d.ts +1424 -0
- package/dist/ledger/records.js +292 -0
- package/dist/ledger/records.js.map +1 -0
- package/dist/plan/index.d.ts +7 -0
- package/dist/plan/index.js +8 -0
- package/dist/plan/index.js.map +1 -0
- package/dist/plan/model.d.ts +6 -0
- package/dist/plan/model.js +7 -0
- package/dist/plan/model.js.map +1 -0
- package/dist/plan/plan.d.ts +31 -0
- package/dist/plan/plan.js +87 -0
- package/dist/plan/plan.js.map +1 -0
- package/dist/plan/plans/index.d.ts +17 -0
- package/dist/plan/plans/index.js +236 -0
- package/dist/plan/plans/index.js.map +1 -0
- package/dist/plan/render.d.ts +41 -0
- package/dist/plan/render.js +75 -0
- package/dist/plan/render.js.map +1 -0
- package/dist/plan/review.d.ts +11 -0
- package/dist/plan/review.js +39 -0
- package/dist/plan/review.js.map +1 -0
- package/dist/plan/triage.d.ts +18 -0
- package/dist/plan/triage.js +65 -0
- package/dist/plan/triage.js.map +1 -0
- package/dist/plan/types.d.ts +401 -0
- package/dist/plan/types.js +223 -0
- package/dist/plan/types.js.map +1 -0
- package/dist/sources/arxiv.d.ts +105 -0
- package/dist/sources/arxiv.js +321 -0
- package/dist/sources/arxiv.js.map +1 -0
- package/dist/sources/exa.d.ts +19 -0
- package/dist/sources/exa.js +59 -0
- package/dist/sources/exa.js.map +1 -0
- package/dist/sources/fetcher.d.ts +35 -0
- package/dist/sources/fetcher.js +67 -0
- package/dist/sources/fetcher.js.map +1 -0
- package/dist/sources/google.d.ts +16 -0
- package/dist/sources/google.js +64 -0
- package/dist/sources/google.js.map +1 -0
- package/dist/sources/index.d.ts +17 -0
- package/dist/sources/index.js +18 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/junk.d.ts +10 -0
- package/dist/sources/junk.js +16 -0
- package/dist/sources/junk.js.map +1 -0
- package/dist/sources/ladder.d.ts +47 -0
- package/dist/sources/ladder.js +158 -0
- package/dist/sources/ladder.js.map +1 -0
- package/dist/sources/ledger.d.ts +7 -0
- package/dist/sources/ledger.js +35 -0
- package/dist/sources/ledger.js.map +1 -0
- package/dist/sources/paste.d.ts +8 -0
- package/dist/sources/paste.js +22 -0
- package/dist/sources/paste.js.map +1 -0
- package/dist/sources/searxng.d.ts +11 -0
- package/dist/sources/searxng.js +38 -0
- package/dist/sources/searxng.js.map +1 -0
- package/dist/sources/sites.d.ts +53 -0
- package/dist/sources/sites.js +285 -0
- package/dist/sources/sites.js.map +1 -0
- package/dist/sources/ytdlp.d.ts +43 -0
- package/dist/sources/ytdlp.js +117 -0
- package/dist/sources/ytdlp.js.map +1 -0
- package/package.json +65 -3
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The files backend: a folder in any repo. `runs/<run>/<writer>.jsonl`, one file per run per
|
|
3
|
+
* writer, so two sessions on one run never touch the same file and git merges clean. A trace is
|
|
4
|
+
* the union of a run's files in time order. Plan files sit beside the runs,
|
|
5
|
+
* `plans/<kind>.json`. DuckDB reads the JSONL as it is.
|
|
6
|
+
*/
|
|
7
|
+
import { appendFile, mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { PlanFile } from "../plan/index.js";
|
|
10
|
+
import { matches, yieldRows } from "./ledger.js";
|
|
11
|
+
import { byTime, LedgerRecord } from "./records.js";
|
|
12
|
+
const safe = (name) => name.replace(/[^A-Za-z0-9._-]+/g, "-");
|
|
13
|
+
const exists = async (dir) => {
|
|
14
|
+
try {
|
|
15
|
+
return await readdir(dir);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
if (err.code === "ENOENT")
|
|
19
|
+
return [];
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export class FilesLedger {
|
|
24
|
+
root;
|
|
25
|
+
writer;
|
|
26
|
+
/** Lines skipped on read, since this ledger was made. Report them; never throw on them. */
|
|
27
|
+
problems = [];
|
|
28
|
+
/** `writer` names this session's file: a person's name, a session id. `by` on a record stays data. */
|
|
29
|
+
constructor(root, writer) {
|
|
30
|
+
this.root = root;
|
|
31
|
+
this.writer = writer;
|
|
32
|
+
}
|
|
33
|
+
runDir(run) {
|
|
34
|
+
return join(this.root, "runs", safe(run));
|
|
35
|
+
}
|
|
36
|
+
file(run) {
|
|
37
|
+
return join(this.runDir(run), `${safe(this.writer)}.jsonl`);
|
|
38
|
+
}
|
|
39
|
+
async append(record) {
|
|
40
|
+
await mkdir(this.runDir(record.run), { recursive: true });
|
|
41
|
+
await appendFile(this.file(record.run), `${JSON.stringify(record)}\n`, "utf8");
|
|
42
|
+
}
|
|
43
|
+
/** The runs on disk, by name. */
|
|
44
|
+
async runs() {
|
|
45
|
+
return (await exists(join(this.root, "runs"))).sort();
|
|
46
|
+
}
|
|
47
|
+
async readFile(path) {
|
|
48
|
+
const out = [];
|
|
49
|
+
const text = await readFile(path, "utf8");
|
|
50
|
+
const lines = text.split("\n");
|
|
51
|
+
const complete = text.endsWith("\n") ? lines.length - 1 : lines.length - 1;
|
|
52
|
+
lines.forEach((line, i) => {
|
|
53
|
+
if (!line.trim())
|
|
54
|
+
return;
|
|
55
|
+
if (i >= complete) {
|
|
56
|
+
this.problems.push({ file: path, line: i + 1, why: "partial last line" });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
let parsed;
|
|
60
|
+
try {
|
|
61
|
+
parsed = JSON.parse(line);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
this.problems.push({ file: path, line: i + 1, why: "not JSON" });
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const r = LedgerRecord.safeParse(parsed);
|
|
68
|
+
if (r.success)
|
|
69
|
+
out.push(r.data);
|
|
70
|
+
else
|
|
71
|
+
this.problems.push({ file: path, line: i + 1, why: r.error.issues[0]?.message ?? "bad" });
|
|
72
|
+
});
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
async trace(run) {
|
|
76
|
+
const dir = this.runDir(run);
|
|
77
|
+
const files = (await exists(dir)).filter((f) => f.endsWith(".jsonl")).sort();
|
|
78
|
+
const parts = await Promise.all(files.map((f) => this.readFile(join(dir, f))));
|
|
79
|
+
return parts.flat().sort(byTime);
|
|
80
|
+
}
|
|
81
|
+
async scan(filter = {}) {
|
|
82
|
+
const runs = filter.run !== undefined ? [filter.run] : await this.runs();
|
|
83
|
+
const parts = await Promise.all(runs.map((r) => this.trace(r)));
|
|
84
|
+
return parts
|
|
85
|
+
.flat()
|
|
86
|
+
.filter((r) => matches(r, filter))
|
|
87
|
+
.sort(byTime);
|
|
88
|
+
}
|
|
89
|
+
async yield(filter = {}) {
|
|
90
|
+
return yieldRows(await this.scan(), filter);
|
|
91
|
+
}
|
|
92
|
+
planPath(kind) {
|
|
93
|
+
return join(this.root, "plans", `${kind}.json`);
|
|
94
|
+
}
|
|
95
|
+
/** The tuned plan file for a kind, or null when the ledger has none (the stock plan file applies). */
|
|
96
|
+
async readPlan(kind) {
|
|
97
|
+
try {
|
|
98
|
+
return PlanFile.parse(JSON.parse(await readFile(this.planPath(kind), "utf8")));
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
if (err.code === "ENOENT")
|
|
102
|
+
return null;
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async writePlan(planFile) {
|
|
107
|
+
const path = this.planPath(planFile.kind);
|
|
108
|
+
await mkdir(join(this.root, "plans"), { recursive: true });
|
|
109
|
+
await writeFile(path, `${JSON.stringify(planFile, null, 2)}\n`, "utf8");
|
|
110
|
+
return path;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/ledger/files.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC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AE,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3D,MAAM,SAAS,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACxE,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Record ids: ULIDs, time-ordered and unique per writer. A test passes a counter instead. */
|
|
2
|
+
import { monotonicFactory } from "ulid";
|
|
3
|
+
export const ulids = () => monotonicFactory();
|
|
4
|
+
/** `a-000001`, `a-000002`, ...: readable ids for tests. */
|
|
5
|
+
export const countingIds = (prefix = "r") => {
|
|
6
|
+
let n = 0;
|
|
7
|
+
return () => `${prefix}-${String(++n).padStart(6, "0")}`;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../../src/ledger/ids.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,OAAO,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAIxC,MAAM,CAAC,MAAM,KAAK,GAAG,GAAQ,EAAE,CAAC,gBAAgB,EAAE,CAAC;AAEnD,2DAA2D;AAC3D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAM,GAAG,GAAG,EAAO,EAAE;IAC/C,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,GAAG,EAAE,CAAC,GAAG,MAAM,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;AAC3D,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ledger: the research engine's append-only store. The contract (`Ledger`: append, trace,
|
|
3
|
+
* scan, yield), the record shapes (one envelope, then the plan's and the document's fields), the files
|
|
4
|
+
* backend (JSONL per run per writer, plan files beside it) and a memory backend for tests.
|
|
5
|
+
* wren's Postgres answers the same four calls.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./files.js";
|
|
8
|
+
export * from "./ids.js";
|
|
9
|
+
export * from "./ledger.js";
|
|
10
|
+
export * from "./memory.js";
|
|
11
|
+
export * from "./records.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ledger: the research engine's append-only store. The contract (`Ledger`: append, trace,
|
|
3
|
+
* scan, yield), the record shapes (one envelope, then the plan's and the document's fields), the files
|
|
4
|
+
* backend (JSONL per run per writer, plan files beside it) and a memory backend for tests.
|
|
5
|
+
* wren's Postgres answers the same four calls.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./files.js";
|
|
8
|
+
export * from "./ids.js";
|
|
9
|
+
export * from "./ledger.js";
|
|
10
|
+
export * from "./memory.js";
|
|
11
|
+
export * from "./records.js";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ledger/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ledger contract: four calls every backend answers. `append` one record; `trace` one run's
|
|
3
|
+
* records in time order; `scan` records across runs by a filter; `yield` what sources, proposers,
|
|
4
|
+
* channels and ask kinds yielded, as the planner's rows. The yield is a fold over records, shared here
|
|
5
|
+
* so the files backend and a database compute the same rows (a database may do it in SQL).
|
|
6
|
+
*/
|
|
7
|
+
import type { AskKind, PlanFile, YieldRow } from "../plan/index.js";
|
|
8
|
+
import { type From, type LedgerRecord, type RecordOf, type RecordType, type Step } from "./records.js";
|
|
9
|
+
export interface Filter {
|
|
10
|
+
run?: string;
|
|
11
|
+
type?: RecordType | readonly RecordType[];
|
|
12
|
+
from?: From;
|
|
13
|
+
by?: string;
|
|
14
|
+
step?: Step;
|
|
15
|
+
round?: number;
|
|
16
|
+
/** ISO time: records at or after it. */
|
|
17
|
+
since?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface YieldFilter {
|
|
20
|
+
source?: string;
|
|
21
|
+
by?: string;
|
|
22
|
+
channel?: string;
|
|
23
|
+
kind?: YieldRow["kind"];
|
|
24
|
+
}
|
|
25
|
+
export interface Ledger {
|
|
26
|
+
append(record: LedgerRecord): Promise<void>;
|
|
27
|
+
/** One run's records, by time then id. */
|
|
28
|
+
trace(run: string): Promise<LedgerRecord[]>;
|
|
29
|
+
/** Records across runs, by time then id. */
|
|
30
|
+
scan(filter?: Filter): Promise<LedgerRecord[]>;
|
|
31
|
+
yield(filter?: YieldFilter): Promise<YieldRow[]>;
|
|
32
|
+
/** The tuned plan file of a kind, when the ledger keeps plan files (the files backend does). */
|
|
33
|
+
readPlan?(kind: AskKind): Promise<PlanFile | null>;
|
|
34
|
+
writePlan?(planFile: PlanFile): Promise<string>;
|
|
35
|
+
}
|
|
36
|
+
export declare function matches(r: LedgerRecord, f: Filter): boolean;
|
|
37
|
+
export declare const ofType: <T extends RecordType>(records: readonly LedgerRecord[], type: T) => RecordOf<T>[];
|
|
38
|
+
/** The latest call on each record: keep or drop. Records must be in time order. */
|
|
39
|
+
export declare function latestCalls(records: readonly LedgerRecord[]): Map<string, "keep" | "drop">;
|
|
40
|
+
/**
|
|
41
|
+
* Rows per source, per proposer (`by` of the queries), per channel and per ask kind: hits seen,
|
|
42
|
+
* documents read, findings proposed, findings kept by the latest call. The chain is
|
|
43
|
+
* query → hit → document → finding, so a finding counts for every source that returned its hit.
|
|
44
|
+
* A finding is kept unless its latest call is a drop: the gate kept it; a review or a person drops.
|
|
45
|
+
*/
|
|
46
|
+
export declare function yieldRows(records: readonly LedgerRecord[], filter?: YieldFilter): YieldRow[];
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { byTime, } from "./records.js";
|
|
2
|
+
export function matches(r, f) {
|
|
3
|
+
if (f.run !== undefined && r.run !== f.run)
|
|
4
|
+
return false;
|
|
5
|
+
if (f.type !== undefined && !(Array.isArray(f.type) ? f.type : [f.type]).includes(r.type))
|
|
6
|
+
return false;
|
|
7
|
+
if (f.from !== undefined && r.from !== f.from)
|
|
8
|
+
return false;
|
|
9
|
+
if (f.by !== undefined && r.by !== f.by)
|
|
10
|
+
return false;
|
|
11
|
+
if (f.step !== undefined && r.step !== f.step)
|
|
12
|
+
return false;
|
|
13
|
+
if (f.round !== undefined && r.round !== f.round)
|
|
14
|
+
return false;
|
|
15
|
+
if (f.since !== undefined && r.at < f.since)
|
|
16
|
+
return false;
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
export const ofType = (records, type) => records.filter((r) => r.type === type);
|
|
20
|
+
/** The latest call on each record: keep or drop. Records must be in time order. */
|
|
21
|
+
export function latestCalls(records) {
|
|
22
|
+
const out = new Map();
|
|
23
|
+
for (const c of ofType(records, "call"))
|
|
24
|
+
out.set(c.on, c.verdict);
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Rows per source, per proposer (`by` of the queries), per channel and per ask kind: hits seen,
|
|
29
|
+
* documents read, findings proposed, findings kept by the latest call. The chain is
|
|
30
|
+
* query → hit → document → finding, so a finding counts for every source that returned its hit.
|
|
31
|
+
* A finding is kept unless its latest call is a drop: the gate kept it; a review or a person drops.
|
|
32
|
+
*/
|
|
33
|
+
export function yieldRows(records, filter = {}) {
|
|
34
|
+
const sorted = [...records].sort(byTime);
|
|
35
|
+
const queries = new Map(ofType(sorted, "query").map((q) => [q.id, q]));
|
|
36
|
+
const hits = new Map(ofType(sorted, "hit").map((h) => [h.id, h]));
|
|
37
|
+
const documents = new Map(ofType(sorted, "document").map((d) => [d.id, d]));
|
|
38
|
+
const kept = latestCalls(sorted);
|
|
39
|
+
const tallies = new Map();
|
|
40
|
+
const tally = (grain, value) => {
|
|
41
|
+
const k = `${grain}\u0000${value}`;
|
|
42
|
+
let t = tallies.get(k);
|
|
43
|
+
if (!t) {
|
|
44
|
+
t = { grain, value, hits: new Set(), reads: new Set(), proposed: new Set(), kept: new Set() };
|
|
45
|
+
tallies.set(k, t);
|
|
46
|
+
}
|
|
47
|
+
return t;
|
|
48
|
+
};
|
|
49
|
+
/** Every row a hit counts toward. */
|
|
50
|
+
const grainsOf = (hit) => {
|
|
51
|
+
const out = hit.sources.map((s) => tally("source", s));
|
|
52
|
+
if (hit.channel)
|
|
53
|
+
out.push(tally("channel", hit.channel));
|
|
54
|
+
const bys = new Set();
|
|
55
|
+
const kinds = new Set();
|
|
56
|
+
for (const id of hit.queries) {
|
|
57
|
+
const q = queries.get(id);
|
|
58
|
+
if (!q)
|
|
59
|
+
continue;
|
|
60
|
+
bys.add(q.by);
|
|
61
|
+
kinds.add(q.kind);
|
|
62
|
+
}
|
|
63
|
+
for (const b of bys)
|
|
64
|
+
out.push(tally("by", b));
|
|
65
|
+
for (const k of kinds)
|
|
66
|
+
out.push(tally("kind", k));
|
|
67
|
+
return out;
|
|
68
|
+
};
|
|
69
|
+
for (const h of hits.values())
|
|
70
|
+
for (const t of grainsOf(h))
|
|
71
|
+
t.hits.add(h.key);
|
|
72
|
+
for (const d of documents.values()) {
|
|
73
|
+
const h = hits.get(d.hit);
|
|
74
|
+
if (h)
|
|
75
|
+
for (const t of grainsOf(h))
|
|
76
|
+
t.reads.add(d.url);
|
|
77
|
+
}
|
|
78
|
+
for (const f of ofType(sorted, "finding")) {
|
|
79
|
+
const d = documents.get(f.document);
|
|
80
|
+
const h = d && hits.get(d.hit);
|
|
81
|
+
if (!h)
|
|
82
|
+
continue;
|
|
83
|
+
for (const t of grainsOf(h)) {
|
|
84
|
+
t.proposed.add(f.id);
|
|
85
|
+
if (kept.get(f.id) !== "drop")
|
|
86
|
+
t.kept.add(f.id);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const want = (t) => {
|
|
90
|
+
const asked = ["source", "by", "channel", "kind"].filter((g) => filter[g]);
|
|
91
|
+
if (!asked.length)
|
|
92
|
+
return true;
|
|
93
|
+
return asked.some((g) => g === t.grain && filter[g] === t.value);
|
|
94
|
+
};
|
|
95
|
+
return [...tallies.values()].filter(want).map((t) => ({
|
|
96
|
+
...(t.grain === "kind"
|
|
97
|
+
? { kind: t.value }
|
|
98
|
+
: { [t.grain]: t.value }),
|
|
99
|
+
hits: t.hits.size,
|
|
100
|
+
reads: t.reads.size,
|
|
101
|
+
proposed: t.proposed.size,
|
|
102
|
+
kept: t.kept.size,
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=ledger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../src/ledger/ledger.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,MAAM,GAMP,MAAM,cAAc,CAAC;AAgCtB,MAAM,UAAU,OAAO,CAAC,CAAe,EAAE,CAAS;IAChD,IAAI,CAAC,CAAC,GAAG,KAAK,SAAS,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG;QAAE,OAAO,KAAK,CAAC;IACzD,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;QACvF,OAAO,KAAK,CAAC;IACf,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC;IAC5D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G,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACpD,GAAG,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM;YACpB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,KAAyB,EAAE;YACvC,CAAC,CAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,EAAkD,CAAC;QAC5E,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI;QACjB,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI;QACnB,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI;QACzB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI;KAClB,CAAC,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** A ledger in memory: tests and dry runs. */
|
|
2
|
+
import { type Filter, type Ledger, type YieldFilter } from "./ledger.js";
|
|
3
|
+
import { type LedgerRecord } from "./records.js";
|
|
4
|
+
export declare class MemoryLedger implements Ledger {
|
|
5
|
+
readonly records: LedgerRecord[];
|
|
6
|
+
append(record: LedgerRecord): Promise<void>;
|
|
7
|
+
trace(run: string): Promise<LedgerRecord[]>;
|
|
8
|
+
scan(filter?: Filter): Promise<LedgerRecord[]>;
|
|
9
|
+
yield(filter?: YieldFilter): Promise<{
|
|
10
|
+
hits: number;
|
|
11
|
+
reads: number;
|
|
12
|
+
proposed: number;
|
|
13
|
+
kept: number;
|
|
14
|
+
by?: string | undefined;
|
|
15
|
+
source?: string | undefined;
|
|
16
|
+
channel?: string | undefined;
|
|
17
|
+
kind?: "video" | "channel" | "web" | "person" | "site" | undefined;
|
|
18
|
+
}[]>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** A ledger in memory: tests and dry runs. */
|
|
2
|
+
import { matches, yieldRows } from "./ledger.js";
|
|
3
|
+
import { byTime } from "./records.js";
|
|
4
|
+
export class MemoryLedger {
|
|
5
|
+
records = [];
|
|
6
|
+
async append(record) {
|
|
7
|
+
this.records.push(record);
|
|
8
|
+
}
|
|
9
|
+
async trace(run) {
|
|
10
|
+
return this.scan({ run });
|
|
11
|
+
}
|
|
12
|
+
async scan(filter = {}) {
|
|
13
|
+
return this.records.filter((r) => matches(r, filter)).sort(byTime);
|
|
14
|
+
}
|
|
15
|
+
async yield(filter = {}) {
|
|
16
|
+
return yieldRows(this.records, filter);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/ledger/memory.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,OAAO,EAA4B,OAAO,EAAoB,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7F,OAAO,EAAE,MAAM,EAAqB,MAAM,cAAc,CAAC;AAEzD,MAAM,OAAO,YAAY;IACd,OAAO,GAAmB,EAAE,CAAC;IACtC,KAAK,CAAC,MAAM,CAAC,MAAoB;QAC/B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,GAAW;QACrB,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IAC5B,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE;QAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrE,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,SAAsB,EAAE;QAClC,OAAO,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACzC,CAAC;CACF"}
|