@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.
Files changed (159) hide show
  1. package/LICENSE.md +61 -0
  2. package/README.md +337 -2
  3. package/dist/app/cli.d.ts +4 -0
  4. package/dist/app/cli.js +149 -0
  5. package/dist/app/cli.js.map +1 -0
  6. package/dist/app/engine-cli.d.ts +50 -0
  7. package/dist/app/engine-cli.js +738 -0
  8. package/dist/app/engine-cli.js.map +1 -0
  9. package/dist/app/index.d.ts +6 -0
  10. package/dist/app/index.js +7 -0
  11. package/dist/app/index.js.map +1 -0
  12. package/dist/app/serve.d.ts +14 -0
  13. package/dist/app/serve.js +102 -0
  14. package/dist/app/serve.js.map +1 -0
  15. package/dist/document/body.d.ts +6 -0
  16. package/dist/document/body.js +18 -0
  17. package/dist/document/body.js.map +1 -0
  18. package/dist/document/check.d.ts +35 -0
  19. package/dist/document/check.js +68 -0
  20. package/dist/document/check.js.map +1 -0
  21. package/dist/document/extract.d.ts +81 -0
  22. package/dist/document/extract.js +226 -0
  23. package/dist/document/extract.js.map +1 -0
  24. package/dist/document/index.d.ts +11 -0
  25. package/dist/document/index.js +12 -0
  26. package/dist/document/index.js.map +1 -0
  27. package/dist/document/model.d.ts +10 -0
  28. package/dist/document/model.js +2 -0
  29. package/dist/document/model.js.map +1 -0
  30. package/dist/document/readers.d.ts +24 -0
  31. package/dist/document/readers.js +87 -0
  32. package/dist/document/readers.js.map +1 -0
  33. package/dist/document/types.d.ts +99 -0
  34. package/dist/document/types.js +93 -0
  35. package/dist/document/types.js.map +1 -0
  36. package/dist/engine/agent.d.ts +473 -0
  37. package/dist/engine/agent.js +989 -0
  38. package/dist/engine/agent.js.map +1 -0
  39. package/dist/engine/canonical.d.ts +4 -0
  40. package/dist/engine/canonical.js +55 -0
  41. package/dist/engine/canonical.js.map +1 -0
  42. package/dist/engine/cost.d.ts +13 -0
  43. package/dist/engine/cost.js +31 -0
  44. package/dist/engine/cost.js.map +1 -0
  45. package/dist/engine/index.d.ts +16 -0
  46. package/dist/engine/index.js +17 -0
  47. package/dist/engine/index.js.map +1 -0
  48. package/dist/engine/judge.d.ts +158 -0
  49. package/dist/engine/judge.js +323 -0
  50. package/dist/engine/judge.js.map +1 -0
  51. package/dist/engine/people.d.ts +34 -0
  52. package/dist/engine/people.js +125 -0
  53. package/dist/engine/people.js.map +1 -0
  54. package/dist/engine/plan.d.ts +6 -0
  55. package/dist/engine/plan.js +7 -0
  56. package/dist/engine/plan.js.map +1 -0
  57. package/dist/engine/ports.d.ts +124 -0
  58. package/dist/engine/ports.js +28 -0
  59. package/dist/engine/ports.js.map +1 -0
  60. package/dist/engine/recall.d.ts +42 -0
  61. package/dist/engine/recall.js +71 -0
  62. package/dist/engine/recall.js.map +1 -0
  63. package/dist/engine/runner.d.ts +30 -0
  64. package/dist/engine/runner.js +209 -0
  65. package/dist/engine/runner.js.map +1 -0
  66. package/dist/engine/state.d.ts +99 -0
  67. package/dist/engine/state.js +186 -0
  68. package/dist/engine/state.js.map +1 -0
  69. package/dist/engine/steps.d.ts +98 -0
  70. package/dist/engine/steps.js +560 -0
  71. package/dist/engine/steps.js.map +1 -0
  72. package/dist/engine/tree.d.ts +76 -0
  73. package/dist/engine/tree.js +148 -0
  74. package/dist/engine/tree.js.map +1 -0
  75. package/dist/engine/view.d.ts +138 -0
  76. package/dist/engine/view.js +188 -0
  77. package/dist/engine/view.js.map +1 -0
  78. package/dist/index.d.ts +15 -0
  79. package/dist/index.js +16 -0
  80. package/dist/index.js.map +1 -0
  81. package/dist/ledger/files.d.ts +39 -0
  82. package/dist/ledger/files.js +113 -0
  83. package/dist/ledger/files.js.map +1 -0
  84. package/dist/ledger/ids.d.ts +4 -0
  85. package/dist/ledger/ids.js +9 -0
  86. package/dist/ledger/ids.js.map +1 -0
  87. package/dist/ledger/index.d.ts +11 -0
  88. package/dist/ledger/index.js +12 -0
  89. package/dist/ledger/index.js.map +1 -0
  90. package/dist/ledger/ledger.d.ts +46 -0
  91. package/dist/ledger/ledger.js +105 -0
  92. package/dist/ledger/ledger.js.map +1 -0
  93. package/dist/ledger/memory.d.ts +19 -0
  94. package/dist/ledger/memory.js +19 -0
  95. package/dist/ledger/memory.js.map +1 -0
  96. package/dist/ledger/records.d.ts +1424 -0
  97. package/dist/ledger/records.js +292 -0
  98. package/dist/ledger/records.js.map +1 -0
  99. package/dist/plan/index.d.ts +7 -0
  100. package/dist/plan/index.js +8 -0
  101. package/dist/plan/index.js.map +1 -0
  102. package/dist/plan/model.d.ts +6 -0
  103. package/dist/plan/model.js +7 -0
  104. package/dist/plan/model.js.map +1 -0
  105. package/dist/plan/plan.d.ts +31 -0
  106. package/dist/plan/plan.js +87 -0
  107. package/dist/plan/plan.js.map +1 -0
  108. package/dist/plan/plans/index.d.ts +17 -0
  109. package/dist/plan/plans/index.js +236 -0
  110. package/dist/plan/plans/index.js.map +1 -0
  111. package/dist/plan/render.d.ts +41 -0
  112. package/dist/plan/render.js +75 -0
  113. package/dist/plan/render.js.map +1 -0
  114. package/dist/plan/review.d.ts +11 -0
  115. package/dist/plan/review.js +39 -0
  116. package/dist/plan/review.js.map +1 -0
  117. package/dist/plan/triage.d.ts +18 -0
  118. package/dist/plan/triage.js +65 -0
  119. package/dist/plan/triage.js.map +1 -0
  120. package/dist/plan/types.d.ts +401 -0
  121. package/dist/plan/types.js +223 -0
  122. package/dist/plan/types.js.map +1 -0
  123. package/dist/sources/arxiv.d.ts +105 -0
  124. package/dist/sources/arxiv.js +321 -0
  125. package/dist/sources/arxiv.js.map +1 -0
  126. package/dist/sources/exa.d.ts +19 -0
  127. package/dist/sources/exa.js +59 -0
  128. package/dist/sources/exa.js.map +1 -0
  129. package/dist/sources/fetcher.d.ts +35 -0
  130. package/dist/sources/fetcher.js +67 -0
  131. package/dist/sources/fetcher.js.map +1 -0
  132. package/dist/sources/google.d.ts +16 -0
  133. package/dist/sources/google.js +64 -0
  134. package/dist/sources/google.js.map +1 -0
  135. package/dist/sources/index.d.ts +17 -0
  136. package/dist/sources/index.js +18 -0
  137. package/dist/sources/index.js.map +1 -0
  138. package/dist/sources/junk.d.ts +10 -0
  139. package/dist/sources/junk.js +16 -0
  140. package/dist/sources/junk.js.map +1 -0
  141. package/dist/sources/ladder.d.ts +47 -0
  142. package/dist/sources/ladder.js +158 -0
  143. package/dist/sources/ladder.js.map +1 -0
  144. package/dist/sources/ledger.d.ts +7 -0
  145. package/dist/sources/ledger.js +35 -0
  146. package/dist/sources/ledger.js.map +1 -0
  147. package/dist/sources/paste.d.ts +8 -0
  148. package/dist/sources/paste.js +22 -0
  149. package/dist/sources/paste.js.map +1 -0
  150. package/dist/sources/searxng.d.ts +11 -0
  151. package/dist/sources/searxng.js +38 -0
  152. package/dist/sources/searxng.js.map +1 -0
  153. package/dist/sources/sites.d.ts +53 -0
  154. package/dist/sources/sites.js +285 -0
  155. package/dist/sources/sites.js.map +1 -0
  156. package/dist/sources/ytdlp.d.ts +43 -0
  157. package/dist/sources/ytdlp.js +117 -0
  158. package/dist/sources/ytdlp.js.map +1 -0
  159. package/package.json +65 -3
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The run tree: a child run names its parent on every snapshot. A wide run finds the niches;
3
+ * a child per niche goes deep; a stopped child's patterns and dead ends reach the parent's next
4
+ * plan. Each child keeps its own budget, stop and resume. A child's budget is never more than
5
+ * its parent's. The depth and the children per round are guard rails: past the depth a warning.
6
+ * The one hard stop is the pages the whole tree reads, pinned on the root's snapshot: depth costs
7
+ * nothing a sibling would not, so only the total is worth a wall.
8
+ */
9
+ import type { SnapshotRecord } from "../ledger/records.js";
10
+ import type { Budget, PlanFile } from "../plan/index.js";
11
+ import { costOf } from "./cost.js";
12
+ import type { Deps } from "./ports.js";
13
+ /** The caps when the plan file names none: the root and its children; six children per round. */
14
+ export declare const RUNS: {
15
+ depth: number;
16
+ children: number;
17
+ };
18
+ export type Parent = NonNullable<SnapshotRecord["parent"]>;
19
+ type Reads = Pick<Deps, "ledger">;
20
+ /** The runs that name this one as parent, each by its first snapshot, in the order they began. */
21
+ export declare function childrenOf(deps: Reads, run: string): Promise<SnapshotRecord[]>;
22
+ /** The pages a tree may read, for a root's snapshot: the plan file's, else from the root's budget. */
23
+ export declare const treeReadsOf: (planFile: PlanFile, budget: Budget) => number;
24
+ /** The run's ancestors, root first, each by its latest snapshot. */
25
+ export declare function lineageOf(deps: Reads, run: string): Promise<SnapshotRecord[]>;
26
+ /** What the tree the run sits in may still read; null for a tree with no cap (a run before 0.21). */
27
+ export declare function treeRoom(deps: Reads, run: string): Promise<{
28
+ root: string;
29
+ cap: number;
30
+ read: number;
31
+ left: number;
32
+ } | null>;
33
+ /** Per field, the smaller: a child never gets more than its parent. */
34
+ export declare const minBudget: (a: Budget, b: Budget) => Budget;
35
+ /** The plan file's budget, capped by the parent's on each round of a child. */
36
+ export declare function budgetUnder(deps: Reads, parent: Parent | undefined, budget: Budget): Promise<Budget>;
37
+ /**
38
+ * A new child's link, checked: the parent has a plan, its round has room for one more child, and
39
+ * the tree has pages left to read. Past the depth, a warning: the why says why deeper beats a
40
+ * sibling.
41
+ */
42
+ export declare function linkTo(deps: Reads, to: {
43
+ run: string;
44
+ why: string;
45
+ }, planFile: PlanFile): Promise<{
46
+ parent: Parent;
47
+ warnings: string[];
48
+ }>;
49
+ /**
50
+ * What a parent's next plan reads from its children. A stopped child gives known lines: its
51
+ * stop, its patterns with their sites per class, its dead ends (facets to skip). A child still
52
+ * going is open. The lines name the child run and the pattern: the ledger is their source.
53
+ */
54
+ export declare function fromChildren(deps: Reads, run: string): Promise<{
55
+ known: string[];
56
+ open: string[];
57
+ }>;
58
+ /** For a new child: what its parent and siblings already found that bears on its ask, with URLs. */
59
+ export declare function fromSiblings(deps: Reads, parent: string, ask: string, n?: number): Promise<string[]>;
60
+ export interface ChildView {
61
+ run: string;
62
+ ask: string;
63
+ why: string;
64
+ /** The parent's round it began in. */
65
+ round: number;
66
+ stopped: boolean;
67
+ patterns: number;
68
+ reads: number;
69
+ }
70
+ /** The run's children, and what the whole tree under it read and cost. */
71
+ export declare function runTree(deps: Reads, run: string): Promise<{
72
+ children: ChildView[];
73
+ reads: number;
74
+ cost: ReturnType<typeof costOf>;
75
+ }>;
76
+ export {};
@@ -0,0 +1,148 @@
1
+ /**
2
+ * The run tree: a child run names its parent on every snapshot. A wide run finds the niches;
3
+ * a child per niche goes deep; a stopped child's patterns and dead ends reach the parent's next
4
+ * plan. Each child keeps its own budget, stop and resume. A child's budget is never more than
5
+ * its parent's. The depth and the children per round are guard rails: past the depth a warning.
6
+ * The one hard stop is the pages the whole tree reads, pinned on the root's snapshot: depth costs
7
+ * nothing a sibling would not, so only the total is worth a wall.
8
+ */
9
+ import { costOf } from "./cost.js";
10
+ import { recall } from "./recall.js";
11
+ import { classesOf, fold } from "./state.js";
12
+ /** The caps when the plan file names none: the root and its children; six children per round. */
13
+ export const RUNS = { depth: 2, children: 6 };
14
+ const stateOf = async (deps, run) => fold(run, await deps.ledger.trace(run));
15
+ /** The runs that name this one as parent, each by its first snapshot, in the order they began. */
16
+ export async function childrenOf(deps, run) {
17
+ const out = new Map();
18
+ for (const r of await deps.ledger.scan({ type: ["snapshot"] }))
19
+ if (r.type === "snapshot" && r.parent?.run === run && !out.has(r.run))
20
+ out.set(r.run, r);
21
+ return [...out.values()];
22
+ }
23
+ /** The pages a tree may read, for a root's snapshot: the plan file's, else from the root's budget. */
24
+ export const treeReadsOf = (planFile, budget) => planFile.runs?.reads ??
25
+ budget.reads * budget.rounds * ((planFile.runs?.children ?? RUNS.children) + 1);
26
+ /** The run's ancestors, root first, each by its latest snapshot. */
27
+ export async function lineageOf(deps, run) {
28
+ const out = [];
29
+ for (let s = (await stateOf(deps, run)).snapshot; s?.parent;) {
30
+ s = (await stateOf(deps, s.parent.run)).snapshot;
31
+ if (s)
32
+ out.unshift(s);
33
+ }
34
+ return out;
35
+ }
36
+ /** What the tree the run sits in may still read; null for a tree with no cap (a run before 0.21). */
37
+ export async function treeRoom(deps, run) {
38
+ const root = (await lineageOf(deps, run))[0] ?? (await stateOf(deps, run)).snapshot;
39
+ if (!root?.treeReads)
40
+ return null;
41
+ const read = (await runTree(deps, root.run)).reads;
42
+ return { root: root.run, cap: root.treeReads, read, left: Math.max(0, root.treeReads - read) };
43
+ }
44
+ /** Per field, the smaller: a child never gets more than its parent. */
45
+ export const minBudget = (a, b) => ({
46
+ queries: Math.min(a.queries, b.queries),
47
+ reads: Math.min(a.reads, b.reads),
48
+ rounds: Math.min(a.rounds, b.rounds),
49
+ checks: Math.min(a.checks, b.checks),
50
+ });
51
+ /** The plan file's budget, capped by the parent's on each round of a child. */
52
+ export async function budgetUnder(deps, parent, budget) {
53
+ const up = parent && (await stateOf(deps, parent.run)).snapshot;
54
+ return up ? minBudget(budget, up.budget) : budget;
55
+ }
56
+ /**
57
+ * A new child's link, checked: the parent has a plan, its round has room for one more child, and
58
+ * the tree has pages left to read. Past the depth, a warning: the why says why deeper beats a
59
+ * sibling.
60
+ */
61
+ export async function linkTo(deps, to, planFile) {
62
+ if (!to.why.trim())
63
+ throw new Error("--parent: why this child?");
64
+ const up = (await stateOf(deps, to.run)).snapshot;
65
+ if (!up)
66
+ throw new Error(`parent ${to.run}: no plan yet`);
67
+ const caps = { ...RUNS, ...planFile.runs };
68
+ const level = (await lineageOf(deps, to.run)).length + 2;
69
+ const room = await treeRoom(deps, to.run);
70
+ if (room && !room.left)
71
+ throw new Error(`--parent: the tree under ${room.root} read ${room.read} pages, its cap ${room.cap} (plan file runs.reads on the root)`);
72
+ const siblings = (await childrenOf(deps, to.run)).filter((c) => c.parent?.round === up.round).length;
73
+ if (siblings >= caps.children)
74
+ throw new Error(`--parent: round ${up.round} of ${to.run} has ${siblings} children, the cap (plan file runs.children)`);
75
+ const warnings = [];
76
+ if (level > caps.depth)
77
+ warnings.push(`level ${level}, past runs.depth ${caps.depth}: a guard rail; the why says why a deeper run beats a sibling`);
78
+ const reads = (await runTree(deps, to.run)).reads;
79
+ const cap = up.budget.reads * up.budget.rounds;
80
+ if (reads >= cap)
81
+ warnings.push(`the tree under ${to.run} read ${reads} pages, past its budget of ${cap}: a guard rail, not a stop`);
82
+ return {
83
+ parent: { run: to.run, round: up.round, why: to.why },
84
+ warnings,
85
+ };
86
+ }
87
+ /**
88
+ * What a parent's next plan reads from its children. A stopped child gives known lines: its
89
+ * stop, its patterns with their sites per class, its dead ends (facets to skip). A child still
90
+ * going is open. The lines name the child run and the pattern: the ledger is their source.
91
+ */
92
+ export async function fromChildren(deps, run) {
93
+ const known = [];
94
+ const open = [];
95
+ for (const c of await childrenOf(deps, run)) {
96
+ const s = await stateOf(deps, c.run);
97
+ const ask = `"${c.ask.text}"`;
98
+ if (s.next) {
99
+ open.push(`child run ${c.run} (${ask}) has not stopped`);
100
+ continue;
101
+ }
102
+ const stop = s.edges.filter((e) => e.next === "stop").at(-1);
103
+ known.push(`child run ${c.run} (${ask}) stopped${stop ? `: ${stop.why}` : ""}`);
104
+ for (const p of s.patterns) {
105
+ const classes = Object.entries(classesOf(s, p.findings))
106
+ .map(([k, n]) => `${k} ${n}`)
107
+ .join(", ");
108
+ known.push(`${p.text} (run ${c.run}, pattern ${p.id}; sources: ${classes || "none kept"})`);
109
+ }
110
+ for (const d of s.dead)
111
+ known.push(`dead end, skip it: ${d.facet}: ${d.why} (run ${c.run})`);
112
+ }
113
+ return { known, open };
114
+ }
115
+ /** For a new child: what its parent and siblings already found that bears on its ask, with URLs. */
116
+ export async function fromSiblings(deps, parent, ask, n = 10) {
117
+ const runs = [parent, ...(await childrenOf(deps, parent)).map((c) => c.run)];
118
+ return (await recall(deps.ledger, ask, { runs, n })).map((r) => `${r.text} (${r.url})`);
119
+ }
120
+ /** The run's children, and what the whole tree under it read and cost. */
121
+ export async function runTree(deps, run) {
122
+ const spends = [];
123
+ let reads = 0;
124
+ const children = [];
125
+ const walk = async (id, top) => {
126
+ const s = await stateOf(deps, id);
127
+ spends.push(...s.spends);
128
+ reads += s.documents.length;
129
+ for (const c of await childrenOf(deps, id)) {
130
+ if (top) {
131
+ const cs = await stateOf(deps, c.run);
132
+ children.push({
133
+ run: c.run,
134
+ ask: c.ask.text,
135
+ why: c.parent?.why ?? "",
136
+ round: c.parent?.round ?? 1,
137
+ stopped: !cs.next,
138
+ patterns: cs.patterns.length,
139
+ reads: cs.documents.length,
140
+ });
141
+ }
142
+ await walk(c.run, false);
143
+ }
144
+ };
145
+ await walk(run, true);
146
+ return { children, reads, cost: costOf(spends) };
147
+ }
148
+ //# sourceMappingURL=tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.js","sourceRoot":"","sources":["../../src/engine/tree.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAiB,MAAM,YAAY,CAAC;AAE5D,iGAAiG;AACjG,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;AAM9C,MAAM,OAAO,GAAG,KAAK,EAAE,IAAW,EAAE,GAAW,EAAqB,EAAE,CACpE,IAAI,CAAC,GAAG,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1C,kGAAkG;AAClG,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAW,EAAE,GAAW;IACvD,MAAM,GAAG,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC9C,KAAK,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5D,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,IAAI,CAAC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QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM;oBAC5B,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM;iBAC3B,CAAC,CAAC;YACL,CAAC;YACD,MAAM,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC,CAAC;IACF,MAAM,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACtB,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;AACnD,CAAC"}
@@ -0,0 +1,138 @@
1
+ import { type Brief } from "./agent.js";
2
+ import type { Deps } from "./ports.js";
3
+ import { type RunState } from "./state.js";
4
+ type Who = {
5
+ from: string;
6
+ by: string;
7
+ };
8
+ type Answers = Record<string, Record<string, number>>;
9
+ export interface RunQuery extends Who {
10
+ id: string;
11
+ round: number;
12
+ at: string;
13
+ terms: string;
14
+ why: string;
15
+ site?: string;
16
+ facet?: string;
17
+ tier?: number;
18
+ follow?: {
19
+ url: string;
20
+ as: string;
21
+ document?: string;
22
+ };
23
+ /** Hits it wrote, then known hits it found again. */
24
+ hits: string[];
25
+ again: string[];
26
+ }
27
+ export interface RunHit extends Who {
28
+ id: string;
29
+ round: number;
30
+ url: string;
31
+ title?: string;
32
+ channel?: string;
33
+ snippet?: string;
34
+ date?: string;
35
+ length?: number;
36
+ /** The sources that returned it. */
37
+ sources: string[];
38
+ /** Every query that returned it, the first one first. */
39
+ queries: string[];
40
+ call?: {
41
+ verdict: "keep" | "drop";
42
+ why?: string;
43
+ } & Who;
44
+ judge?: Answers;
45
+ document?: string;
46
+ }
47
+ export interface RunDocument extends Who {
48
+ id: string;
49
+ hit: string;
50
+ url: string;
51
+ title?: string;
52
+ channel?: string;
53
+ media: string;
54
+ date?: string;
55
+ length?: number;
56
+ chars: number;
57
+ class?: string;
58
+ judge?: Answers;
59
+ verdict?: {
60
+ quality: string;
61
+ gap?: string;
62
+ };
63
+ /** The person record that owns it. */
64
+ person?: string;
65
+ }
66
+ export interface RunFinding extends Who {
67
+ id: string;
68
+ round: number;
69
+ document: string;
70
+ text: string;
71
+ quote?: string;
72
+ date?: string;
73
+ kept: boolean;
74
+ fixes?: string;
75
+ class?: string;
76
+ judge?: Answers;
77
+ checks: ({
78
+ ok: boolean;
79
+ why: string;
80
+ at: string;
81
+ } & Who)[];
82
+ }
83
+ /** One step of the back and forth: a decision with its why, or a step's end with its note. */
84
+ export interface Moment extends Who {
85
+ id: string;
86
+ at: string;
87
+ round: number;
88
+ step?: string;
89
+ type: string;
90
+ text: string;
91
+ why?: string;
92
+ /** The record it is about. */
93
+ on?: string;
94
+ ok?: boolean;
95
+ }
96
+ export interface RunView {
97
+ v: 1;
98
+ run: string;
99
+ brief: Brief;
100
+ queries: RunQuery[];
101
+ hits: RunHit[];
102
+ documents: RunDocument[];
103
+ findings: RunFinding[];
104
+ timeline: Moment[];
105
+ /** Spend per source and op. */
106
+ spend: {
107
+ source: string;
108
+ op: string;
109
+ calls: number;
110
+ failed: number;
111
+ usd: number;
112
+ }[];
113
+ }
114
+ /** One line per run for a list. */
115
+ export interface RunRow {
116
+ run: string;
117
+ ask: string;
118
+ kind: string;
119
+ parent: string | null;
120
+ round: number;
121
+ /** Null once an edge said stop. */
122
+ next: {
123
+ round: number;
124
+ step: string;
125
+ } | null;
126
+ note: string | null;
127
+ started: string;
128
+ updated: string;
129
+ hits: number;
130
+ documents: number;
131
+ kept: number;
132
+ usd: number;
133
+ }
134
+ export declare function rowOf(state: RunState): RunRow;
135
+ export declare function viewOf(state: RunState, b: Brief): RunView;
136
+ /** A run's view from its ledger. */
137
+ export declare function runView(deps: Deps, run: string): Promise<RunView>;
138
+ export {};
@@ -0,0 +1,188 @@
1
+ import { brief } from "./agent.js";
2
+ import { ownersOf } from "./people.js";
3
+ import { fold, kept } from "./state.js";
4
+ const who = (r) => ({ from: r.from, by: r.by });
5
+ const some = (v, k) => (v === undefined ? {} : { [k]: v });
6
+ export function rowOf(state) {
7
+ const s = state.snapshot;
8
+ return {
9
+ run: state.run,
10
+ ask: s?.ask.text ?? "",
11
+ kind: s?.ask.kind ?? "",
12
+ parent: s?.parent?.run ?? null,
13
+ round: state.round,
14
+ next: state.next,
15
+ note: state.note,
16
+ started: state.records[0]?.at ?? "",
17
+ updated: state.records.at(-1)?.at ?? "",
18
+ hits: state.hits.length,
19
+ documents: state.documents.length,
20
+ kept: state.findings.filter((f) => kept(state, f)).length,
21
+ usd: state.spends.reduce((a, x) => a + (x.usd ?? 0), 0),
22
+ };
23
+ }
24
+ /** The record a moment shows, or null for bulk records (hits, pages, the judge, spends). */
25
+ function momentOf(r) {
26
+ const base = { id: r.id, at: r.at, round: r.round, ...some(r.step, "step"), ...who(r) };
27
+ switch (r.type) {
28
+ case "snapshot":
29
+ return { ...base, type: r.type, text: `plan: ${r.ask.text}`, why: r.sources.join(", ") };
30
+ case "query":
31
+ return {
32
+ ...base,
33
+ type: r.type,
34
+ text: r.follow ? `follow ${r.follow.as} of ${r.follow.url}` : r.terms,
35
+ why: r.why,
36
+ ...some(r.facet, "on"),
37
+ };
38
+ case "call":
39
+ return { ...base, type: r.type, text: r.verdict, on: r.on, ...some(r.why, "why") };
40
+ case "check":
41
+ return {
42
+ ...base,
43
+ type: r.type,
44
+ text: r.ok ? "backed" : "failed",
45
+ on: r.on,
46
+ why: r.why,
47
+ ok: r.ok,
48
+ };
49
+ case "edge":
50
+ return { ...base, type: r.type, text: r.next, why: r.why };
51
+ case "done":
52
+ return { ...base, type: r.type, text: r.step, ok: r.ok, ...some(r.note, "why") };
53
+ case "gap":
54
+ return { ...base, type: r.type, text: r.note, ...some(r.on, "on") };
55
+ case "steer":
56
+ return { ...base, type: r.type, text: r.text };
57
+ case "class":
58
+ return { ...base, type: r.type, text: r.class, on: r.on, why: r.why };
59
+ case "pattern":
60
+ return { ...base, type: r.type, text: r.text };
61
+ case "person":
62
+ return { ...base, type: r.type, text: r.name, why: r.why };
63
+ case "dead":
64
+ return { ...base, type: r.type, text: r.facet, why: r.why };
65
+ case "draft":
66
+ return { ...base, type: r.type, text: r.for };
67
+ // A finding written by hand; the extract's bulk ones show in its step's end.
68
+ case "finding":
69
+ return r.step ? null : { ...base, type: r.type, text: r.text, on: r.document };
70
+ default:
71
+ return null;
72
+ }
73
+ }
74
+ export function viewOf(state, b) {
75
+ const calls = new Map();
76
+ for (const c of state.calls)
77
+ calls.set(c.on, c);
78
+ const docOfHit = new Map(state.documents.map((d) => [d.hit, d.id]));
79
+ const owners = ownersOf(state);
80
+ const verdicts = new Map(state.verdicts.map((v) => [v.document, v]));
81
+ const hitQueries = new Map(state.hits.map((h) => [h.id, [...h.queries]]));
82
+ const again = new Map();
83
+ for (const f of state.founds) {
84
+ hitQueries.get(f.hit)?.push(f.query);
85
+ again.set(f.query, [...(again.get(f.query) ?? []), f.hit]);
86
+ }
87
+ const wrote = new Map();
88
+ for (const h of state.hits) {
89
+ const q = h.queries[0];
90
+ if (q)
91
+ wrote.set(q, [...(wrote.get(q) ?? []), h.id]);
92
+ }
93
+ const checks = new Map();
94
+ for (const c of state.checks)
95
+ checks.set(c.on, [...(checks.get(c.on) ?? []), { ok: c.ok, why: c.why, at: c.at, ...who(c) }]);
96
+ const callOf = (id) => {
97
+ const c = calls.get(id);
98
+ return c ? { call: { verdict: c.verdict, ...some(c.why, "why"), ...who(c) } } : {};
99
+ };
100
+ const spend = new Map();
101
+ for (const s of state.spends) {
102
+ const k = `${s.source}\u0000${s.op}`;
103
+ const row = spend.get(k) ?? { source: s.source, op: s.op, calls: 0, failed: 0, usd: 0 };
104
+ row.calls++;
105
+ if (!s.ok)
106
+ row.failed++;
107
+ row.usd += s.usd ?? 0;
108
+ spend.set(k, row);
109
+ }
110
+ return {
111
+ v: 1,
112
+ run: state.run,
113
+ brief: b,
114
+ queries: state.queries.map((q) => ({
115
+ id: q.id,
116
+ round: q.round,
117
+ at: q.at,
118
+ terms: q.terms,
119
+ why: q.why,
120
+ ...some(q.site, "site"),
121
+ ...some(q.facet, "facet"),
122
+ ...some(q.tier, "tier"),
123
+ ...some(q.follow, "follow"),
124
+ hits: wrote.get(q.id) ?? [],
125
+ again: again.get(q.id) ?? [],
126
+ ...who(q),
127
+ })),
128
+ hits: state.hits.map((h) => ({
129
+ id: h.id,
130
+ round: h.round,
131
+ url: h.url,
132
+ ...some(h.title, "title"),
133
+ ...some(h.channel, "channel"),
134
+ ...some(h.snippet, "snippet"),
135
+ ...some(h.date, "date"),
136
+ ...some(h.length, "length"),
137
+ sources: h.sources,
138
+ queries: hitQueries.get(h.id) ?? h.queries,
139
+ ...callOf(h.id),
140
+ ...some(state.judged.get(h.id), "judge"),
141
+ ...some(docOfHit.get(h.id), "document"),
142
+ ...who(h),
143
+ })),
144
+ documents: state.documents.map((d) => {
145
+ const v = verdicts.get(d.id);
146
+ return {
147
+ id: d.id,
148
+ hit: d.hit,
149
+ url: d.url,
150
+ ...some(d.title, "title"),
151
+ ...some(d.channel ?? state.hits.find((h) => h.id === d.hit)?.channel, "channel"),
152
+ media: d.media,
153
+ ...some(d.date, "date"),
154
+ ...some(d.length, "length"),
155
+ chars: d.text.length,
156
+ ...some(state.classOf.get(d.id), "class"),
157
+ ...some(state.judged.get(d.id), "judge"),
158
+ ...(v ? { verdict: { quality: v.quality, ...some(v.gap, "gap") } } : {}),
159
+ ...some(owners.get(d.id)?.id, "person"),
160
+ ...who(d),
161
+ };
162
+ }),
163
+ findings: state.findings.map((f) => ({
164
+ id: f.id,
165
+ round: f.round,
166
+ document: f.document,
167
+ text: f.text,
168
+ ...some(f.proof.quote ?? undefined, "quote"),
169
+ ...some(f.date, "date"),
170
+ kept: kept(state, f),
171
+ ...some(f.fixes, "fixes"),
172
+ ...some(state.classOf.get(f.id), "class"),
173
+ ...some(state.judged.get(f.id), "judge"),
174
+ checks: checks.get(f.id) ?? [],
175
+ ...who(f),
176
+ })),
177
+ timeline: state.records.flatMap((r) => momentOf(r) ?? []),
178
+ spend: [...spend.values()].sort((a, b) => b.usd - a.usd || b.calls - a.calls),
179
+ };
180
+ }
181
+ /** A run's view from its ledger. */
182
+ export async function runView(deps, run) {
183
+ const records = await deps.ledger.trace(run);
184
+ if (!records.length)
185
+ throw new Error(`run ${run}: no records`);
186
+ return viewOf(fold(run, records), await brief(deps, run));
187
+ }
188
+ //# sourceMappingURL=view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/engine/view.ts"],"names":[],"mappings":"AAMA,OAAO,EAAc,KAAK,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAiB,MAAM,YAAY,CAAC;AAkHvD,MAAM,GAAG,GAAG,CAAC,CAAe,EAAO,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACnE,MAAM,IAAI,GAAG,CAAI,CAAgB,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAErF,MAAM,UAAU,KAAK,CAAC,KAAe;IACnC,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC;IACzB,OAAO;QACL,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE;QACtB,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE;QACvB,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,IAAI;QAC9B,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,IAAI,EAAE,KAAK,C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C,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;KAC9E,CAAC;AACJ,CAAC;AAED,oCAAoC;AACpC,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,IAAU,EAAE,GAAW;IACnD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7C,IAAI,CAAC,OAAO,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,OAAO,GAAG,cAAc,CAAC,CAAC;IAC/D,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * birdwatch: research from the open web, one step per command, every record in a ledger. Six
3
+ * doors: `./engine` (the source port, registry, run state, the step table and the runner),
4
+ * `./sources` (SearXNG, Exa, Google, arXiv, yt-dlp, the site readers, the fetcher, the ladder, a
5
+ * paste, the ledger), `./ledger` (the records, a folder of JSON lines per run per writer, yield
6
+ * rows), `./plan` (the ask, the plan file per ask kind, the planner's prompts), `./document`
7
+ * (`Document`, `Finding`, `Proof`, readers by media, the claim extractor) and this root (the
8
+ * engine's CLI commands, `addEngineCommands`, for a host that mounts them on its own program).
9
+ * Reading the web and files is `@wrenautomation/read`'s; every model call goes through
10
+ * `@wrenautomation/models`. Design: wren's `designs/2026-10-26-research-engine.md`.
11
+ */
12
+ export * from "./app/index.js";
13
+ export * from "./engine/index.js";
14
+ export * from "./ledger/index.js";
15
+ export * from "./sources/index.js";
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * birdwatch: research from the open web, one step per command, every record in a ledger. Six
3
+ * doors: `./engine` (the source port, registry, run state, the step table and the runner),
4
+ * `./sources` (SearXNG, Exa, Google, arXiv, yt-dlp, the site readers, the fetcher, the ladder, a
5
+ * paste, the ledger), `./ledger` (the records, a folder of JSON lines per run per writer, yield
6
+ * rows), `./plan` (the ask, the plan file per ask kind, the planner's prompts), `./document`
7
+ * (`Document`, `Finding`, `Proof`, readers by media, the claim extractor) and this root (the
8
+ * engine's CLI commands, `addEngineCommands`, for a host that mounts them on its own program).
9
+ * Reading the web and files is `@wrenautomation/read`'s; every model call goes through
10
+ * `@wrenautomation/models`. Design: wren's `designs/2026-10-26-research-engine.md`.
11
+ */
12
+ export * from "./app/index.js";
13
+ export * from "./engine/index.js";
14
+ export * from "./ledger/index.js";
15
+ export * from "./sources/index.js";
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { type AskKind, PlanFile } from "../plan/index.js";
2
+ import { type Filter, type Ledger, type YieldFilter } from "./ledger.js";
3
+ import { LedgerRecord } from "./records.js";
4
+ /** A line the backend could not read: a partial last line from a killed writer, or a record it does not know. */
5
+ export interface Problem {
6
+ file: string;
7
+ line: number;
8
+ why: string;
9
+ }
10
+ export declare class FilesLedger implements Ledger {
11
+ readonly root: string;
12
+ readonly writer: string;
13
+ /** Lines skipped on read, since this ledger was made. Report them; never throw on them. */
14
+ readonly problems: Problem[];
15
+ /** `writer` names this session's file: a person's name, a session id. `by` on a record stays data. */
16
+ constructor(root: string, writer: string);
17
+ runDir(run: string): string;
18
+ file(run: string): string;
19
+ append(record: LedgerRecord): Promise<void>;
20
+ /** The runs on disk, by name. */
21
+ runs(): Promise<string[]>;
22
+ private readFile;
23
+ trace(run: string): Promise<LedgerRecord[]>;
24
+ scan(filter?: Filter): Promise<LedgerRecord[]>;
25
+ yield(filter?: YieldFilter): Promise<{
26
+ hits: number;
27
+ reads: number;
28
+ proposed: number;
29
+ kept: number;
30
+ by?: string | undefined;
31
+ source?: string | undefined;
32
+ channel?: string | undefined;
33
+ kind?: "video" | "channel" | "web" | "person" | "site" | undefined;
34
+ }[]>;
35
+ planPath(kind: AskKind): string;
36
+ /** The tuned plan file for a kind, or null when the ledger has none (the stock plan file applies). */
37
+ readPlan(kind: AskKind): Promise<PlanFile | null>;
38
+ writePlan(planFile: PlanFile): Promise<string>;
39
+ }