@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,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The default plan file per ask kind. A copy of one, tuned and stored beside a ledger, is how
|
|
3
|
+
* a run learns: the recipe changes, the planner does not. `birdwatch plans <kind>` prints one to start from.
|
|
4
|
+
*/
|
|
5
|
+
import { PlanFile as PlanFileShape, } from "../types.js";
|
|
6
|
+
const SHAPE_QUERIES = `Return ONLY a JSON object, no prose, exactly this shape:
|
|
7
|
+
{"queries": [{"terms": "...", "why": "..."}]}`;
|
|
8
|
+
const SHAPE_HITS = `Return ONLY a JSON object, no prose, exactly this shape:
|
|
9
|
+
{"hits": [{"url": "...", "read": true, "why": "..."}, {"url": "...", "read": false}]}`;
|
|
10
|
+
const SHAPE_EDGE = `Return ONLY a JSON object, no prose, exactly this shape:
|
|
11
|
+
{"next": "stop", "why": "..."}
|
|
12
|
+
where "next" is "stop", "again" (a new round from plan) or "back" (rerun one step of this round, named in "to": "plan", "fetch", "triage", "read" or "extract").`;
|
|
13
|
+
const CONTEXT = `Ask: {ask}
|
|
14
|
+
{steer}{open}Known already (look past these):
|
|
15
|
+
{known}
|
|
16
|
+
What yielded before (hits, reads, proposed, kept):
|
|
17
|
+
{yield}`;
|
|
18
|
+
const TRIAGE_RULES = `- One entry per hit, with its url as given. Mark "read": true for at most {n}.
|
|
19
|
+
- Read a hit when what it shows for free (title, snippet, channel, length, date) says it holds what the ask needs and is not known already.
|
|
20
|
+
- A hit returned by more than one source is a good sign, not a duplicate.
|
|
21
|
+
- "why" on a read only: one short line a person reads to agree or not. A skip has no "why".{age}`;
|
|
22
|
+
const REVIEW = `You decide what happens after one round of research.
|
|
23
|
+
|
|
24
|
+
${SHAPE_EDGE}
|
|
25
|
+
|
|
26
|
+
Rules:
|
|
27
|
+
- "stop" when the found lines answer the ask, or when another round would likely add nothing. New hits and kept findings that fall round by round point that way.
|
|
28
|
+
- "again" when the ask is still open and new queries could find more. The gaps say what is missing; say what to look for next in "why".
|
|
29
|
+
- "again" too when the reads were mostly "thin" or "off": the queries found the wrong pages, so plan different ones.
|
|
30
|
+
- "back" when one step of this round failed for a reason a rerun fixes (a source was down, reads timed out). Name the step in "to".
|
|
31
|
+
- The gaps are what a step or the person said this round lacks: a query with no new hits, a page no source could open. Weigh them like the verdicts.
|
|
32
|
+
- A check that failed means a finding's quote does not back it, and the finding was dropped. Many failed checks mean the reads were poor: say so in "why".{age}
|
|
33
|
+
- "why" is one short line a person reads to agree or not. On "again" it is what the next plan reads first.
|
|
34
|
+
|
|
35
|
+
Ask: {ask}
|
|
36
|
+
{steer}Round {round}; the budget is {rounds} rounds, a guard rail (past it the runner parks and a person decides), not a stop rule. Hits {hits}, reads {reads}, findings proposed {proposed}, kept {kept}.
|
|
37
|
+
Found (the source's date in brackets when it gives one):
|
|
38
|
+
{found}
|
|
39
|
+
Read (quality: rich, thin, off or empty; then the gap, what the ask still lacks):
|
|
40
|
+
{verdicts}
|
|
41
|
+
Gaps (the step or the person, then what is missing):
|
|
42
|
+
{gaps}
|
|
43
|
+
Checked (a sample of the kept findings, each against its document):
|
|
44
|
+
{checks}
|
|
45
|
+
Notes:
|
|
46
|
+
{notes}`;
|
|
47
|
+
/**
|
|
48
|
+
* The five sides a researcher covers before the reads start. One tree per round; the agent
|
|
49
|
+
* fills each facet with tries, in order of what it expects to work.
|
|
50
|
+
*/
|
|
51
|
+
export const TREE = {
|
|
52
|
+
facets: [
|
|
53
|
+
{ name: "number", why: "a figure: a rate, a price, a count, a date" },
|
|
54
|
+
{ name: "how", why: "how it is done: a method, a step list, a tool" },
|
|
55
|
+
{ name: "who", why: "who does it or buys it, in their own words" },
|
|
56
|
+
{ name: "counter", why: "the case against: what fails, who says no" },
|
|
57
|
+
{
|
|
58
|
+
name: "primary",
|
|
59
|
+
why: "the source itself: a study, a filing, a transcript, the maker's own page",
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
thin: 3,
|
|
63
|
+
};
|
|
64
|
+
const web = {
|
|
65
|
+
id: "birdwatch/web",
|
|
66
|
+
kind: "web",
|
|
67
|
+
version: 6,
|
|
68
|
+
propose: `You plan web searches for one research ask.
|
|
69
|
+
|
|
70
|
+
${SHAPE_QUERIES}
|
|
71
|
+
|
|
72
|
+
Rules:
|
|
73
|
+
- At most {n} queries, each 3 to 10 words, as a person types into a search engine.
|
|
74
|
+
- Each query finds a different kind of source: a survey or benchmark with numbers, a trade publication or industry association, people in the field talking (forums, Reddit, reviews), a government statistic.
|
|
75
|
+
- "why" says in one short line what the query would add that is not known yet.
|
|
76
|
+
- Put a year in a query only when fresh numbers matter. This year is {year}.
|
|
77
|
+
- No site: operators. Quotes only around a phrase that must match exactly.
|
|
78
|
+
|
|
79
|
+
${CONTEXT}`,
|
|
80
|
+
triage: `You decide which search hits to read for one research ask. A read costs time; a skip costs nothing.
|
|
81
|
+
|
|
82
|
+
${SHAPE_HITS}
|
|
83
|
+
|
|
84
|
+
Rules:
|
|
85
|
+
${TRIAGE_RULES}
|
|
86
|
+
- Prefer primary sources and people in the field over listicles and aggregators.
|
|
87
|
+
|
|
88
|
+
${CONTEXT}
|
|
89
|
+
Hits:
|
|
90
|
+
{hits}`,
|
|
91
|
+
review: REVIEW,
|
|
92
|
+
sources: ["searxng", "exa", "google"],
|
|
93
|
+
budget: { queries: 3, reads: 6, rounds: 3, checks: 3 },
|
|
94
|
+
tree: TREE,
|
|
95
|
+
age: "Prices, tools and numbers that move: prefer the last two years. A principle or a method can be old.",
|
|
96
|
+
};
|
|
97
|
+
const video = {
|
|
98
|
+
id: "birdwatch/video",
|
|
99
|
+
kind: "video",
|
|
100
|
+
version: 6,
|
|
101
|
+
propose: `You plan video searches for one research ask: talks, walkthroughs, interviews and reviews on YouTube and podcast feeds.
|
|
102
|
+
|
|
103
|
+
${SHAPE_QUERIES}
|
|
104
|
+
|
|
105
|
+
Rules:
|
|
106
|
+
- At most {n} queries, each 2 to 8 words, as a person types into a video search box.
|
|
107
|
+
- Each query reaches a different kind of speaker: a practitioner showing their work, a conference talk, an interview or podcast, a critic or reviewer.
|
|
108
|
+
- "why" says in one short line what the query would add that is not known yet.
|
|
109
|
+
- This year is {year}; add it only when the topic moves fast.
|
|
110
|
+
|
|
111
|
+
${CONTEXT}`,
|
|
112
|
+
triage: `You decide which videos to read (transcript and screen) for one research ask. A read costs minutes per video; a skip costs nothing.
|
|
113
|
+
|
|
114
|
+
${SHAPE_HITS}
|
|
115
|
+
|
|
116
|
+
Rules:
|
|
117
|
+
${TRIAGE_RULES}
|
|
118
|
+
- Length is in seconds. Skip a clip under 60 seconds unless the ask is about short-form video. Prefer 5 to 60 minutes.
|
|
119
|
+
- A channel that yielded nothing before is a reason to skip.
|
|
120
|
+
|
|
121
|
+
${CONTEXT}
|
|
122
|
+
Hits:
|
|
123
|
+
{hits}`,
|
|
124
|
+
review: REVIEW,
|
|
125
|
+
sources: ["youtube", "podcasts"],
|
|
126
|
+
budget: { queries: 3, reads: 4, rounds: 2, checks: 3 },
|
|
127
|
+
tree: TREE,
|
|
128
|
+
age: "Tools and platforms: prefer the last two years. A talk on a principle can be old.",
|
|
129
|
+
};
|
|
130
|
+
const channel = {
|
|
131
|
+
id: "birdwatch/channel",
|
|
132
|
+
kind: "channel",
|
|
133
|
+
version: 6,
|
|
134
|
+
propose: `You plan searches that find the people and channels worth following for one research ask: creators, newsletters, podcasts, forums.
|
|
135
|
+
|
|
136
|
+
${SHAPE_QUERIES}
|
|
137
|
+
|
|
138
|
+
Rules:
|
|
139
|
+
- At most {n} queries, each 3 to 10 words.
|
|
140
|
+
- Each query finds a different kind of channel: a creator on video, a writer or newsletter, a podcast, a community.
|
|
141
|
+
- "why" says in one short line what the query would add that is not known yet.
|
|
142
|
+
|
|
143
|
+
${CONTEXT}`,
|
|
144
|
+
triage: `You decide which channel pages to read for one research ask: a profile, an about page, a feed. A read costs time; a skip costs nothing.
|
|
145
|
+
|
|
146
|
+
${SHAPE_HITS}
|
|
147
|
+
|
|
148
|
+
Rules:
|
|
149
|
+
${TRIAGE_RULES}
|
|
150
|
+
- Prefer the channel's own page over a page about it.
|
|
151
|
+
|
|
152
|
+
${CONTEXT}
|
|
153
|
+
Hits:
|
|
154
|
+
{hits}`,
|
|
155
|
+
review: REVIEW,
|
|
156
|
+
sources: ["searxng", "youtube", "exa"],
|
|
157
|
+
budget: { queries: 3, reads: 6, rounds: 2, checks: 3 },
|
|
158
|
+
tree: TREE,
|
|
159
|
+
age: "A channel that has not posted in the last year counts for little.",
|
|
160
|
+
};
|
|
161
|
+
const person = {
|
|
162
|
+
id: "birdwatch/person",
|
|
163
|
+
kind: "person",
|
|
164
|
+
version: 6,
|
|
165
|
+
propose: `You plan searches about one person or company for one research ask: what they do, what they said, what others say about them.
|
|
166
|
+
|
|
167
|
+
${SHAPE_QUERIES}
|
|
168
|
+
|
|
169
|
+
Rules:
|
|
170
|
+
- At most {n} queries, each 3 to 10 words. Name the person or company in each, as written in the ask.
|
|
171
|
+
- Each query finds a different kind of page: their own site or profile, an interview or talk, press or reviews, a filing or directory.
|
|
172
|
+
- "why" says in one short line what the query would add that is not known yet.
|
|
173
|
+
- No site: operators.
|
|
174
|
+
|
|
175
|
+
${CONTEXT}`,
|
|
176
|
+
triage: `You decide which pages about one person or company to read for one research ask. A read costs time; a skip costs nothing.
|
|
177
|
+
|
|
178
|
+
${SHAPE_HITS}
|
|
179
|
+
|
|
180
|
+
Rules:
|
|
181
|
+
${TRIAGE_RULES}
|
|
182
|
+
- Skip a page about a different person or company with the same name.
|
|
183
|
+
- Prefer what they wrote or said over what a directory copied.
|
|
184
|
+
|
|
185
|
+
${CONTEXT}
|
|
186
|
+
Hits:
|
|
187
|
+
{hits}`,
|
|
188
|
+
review: REVIEW,
|
|
189
|
+
sources: ["searxng", "exa", "linkedin", "google"],
|
|
190
|
+
budget: { queries: 4, reads: 6, rounds: 2, checks: 3 },
|
|
191
|
+
tree: TREE,
|
|
192
|
+
age: "What they do now: prefer the latest pages. Their history can be old.",
|
|
193
|
+
};
|
|
194
|
+
const site = {
|
|
195
|
+
id: "birdwatch/site",
|
|
196
|
+
kind: "site",
|
|
197
|
+
version: 6,
|
|
198
|
+
propose: `You plan searches inside one website for one research ask. Every query runs on {site} only.
|
|
199
|
+
|
|
200
|
+
${SHAPE_QUERIES}
|
|
201
|
+
|
|
202
|
+
Rules:
|
|
203
|
+
- At most {n} queries, each 2 to 8 words, as a person types into the site's own search box.
|
|
204
|
+
- Each query reaches a different part of the site: its product or service pages, its pricing, its blog or help, its people.
|
|
205
|
+
- "why" says in one short line what the query would add that is not known yet.
|
|
206
|
+
- No site: operators: the site is set for you.
|
|
207
|
+
|
|
208
|
+
${CONTEXT}`,
|
|
209
|
+
triage: `You decide which pages of {site} to read for one research ask. A read costs time; a skip costs nothing.
|
|
210
|
+
|
|
211
|
+
${SHAPE_HITS}
|
|
212
|
+
|
|
213
|
+
Rules:
|
|
214
|
+
${TRIAGE_RULES}
|
|
215
|
+
- Skip a url off {site}.
|
|
216
|
+
|
|
217
|
+
${CONTEXT}
|
|
218
|
+
Hits:
|
|
219
|
+
{hits}`,
|
|
220
|
+
review: REVIEW,
|
|
221
|
+
sources: ["sitemap", "searxng", "fetch"],
|
|
222
|
+
budget: { queries: 4, reads: 8, rounds: 2, checks: 3 },
|
|
223
|
+
tree: TREE,
|
|
224
|
+
age: "When two pages of the site disagree, the later one counts.",
|
|
225
|
+
};
|
|
226
|
+
const DEFAULTS = { web, video, channel, person, site };
|
|
227
|
+
/** The default plan file for a kind, validated, as a fresh copy. */
|
|
228
|
+
export function defaultPlanFile(kind) {
|
|
229
|
+
return PlanFileShape.parse(structuredClone(DEFAULTS[kind]));
|
|
230
|
+
}
|
|
231
|
+
/** The plan file's word on age; a stored file from before version 4 takes its kind's default. Version 5: the review no longer says "at most". Version 6: `tree`, the query tree's guide. */
|
|
232
|
+
export const ageOf = (planFile) => planFile.age ?? DEFAULTS[planFile.kind].age;
|
|
233
|
+
/** The plan file's guide for a query tree; a stored file from before version 6 takes its kind's default. */
|
|
234
|
+
export const treeOf = (planFile) => planFile.tree ?? DEFAULTS[planFile.kind].tree;
|
|
235
|
+
export const PLAN_KINDS = Object.keys(DEFAULTS);
|
|
236
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plan/plans/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAGL,QAAQ,IAAI,aAAa,GAE1B,MAAM,aAAa,CAAC;AAErB,MAAM,aAAa,GAAG;8CACwB,CAAC;AAC/C,MAAM,UAAU,GAAG;sFACmE,CAAC;AACvF,MAAM,UAAU,GAAG;;iKAE8I,CAAC;AAElK,MAAM,OAAO,GAAG;;;;QAIR,CAAC;AAET,MAAM,YAAY,GAAG;;;iGAG4E,CAAC;AAElG,MAAM,MAAM,GAAG;;EAEb,UAAU;;;;;;;;;;;;;;;;;;;;;;QAsBJ,CAAC;AAET;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAAc;IAC7B,MAAM,EAAE;QACN,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,4CAA4C,EAAE;QACrE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,+CAA+C,EAAE;QACrE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,4CAA4C,EAAE;QAClE,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,2CAA2C,EAAE;QACrE;YACE,IAAI,EAAE,SAAS;YACf,GAAG,EAAE,0EAA0E;SA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F,MAAM,QAAQ,GAA8B,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAElF,oEAAoE;AACpE,MAAM,UAAU,eAAe,CAAC,IAAa;IAC3C,OAAO,aAAa,CAAC,KAAK,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,4LAA4L;AAC5L,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,QAAkB,EAAsB,EAAE,CAC9D,QAAQ,CAAC,GAAG,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC;AAE9C,4GAA4G;AAC5G,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,QAAkB,EAAa,EAAE,CACtD,QAAQ,CAAC,IAAI,IAAK,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAkB,CAAC;AAE/D,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAc,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Text the prompts take: what is known, what yielded, what a hit shows for free. */
|
|
2
|
+
import type { HitView, YieldRow } from "./types.js";
|
|
3
|
+
export declare const lines: (xs: readonly string[], none?: string) => string;
|
|
4
|
+
/** A line with a URL or a ledger id on it: a fact someone can go and check. */
|
|
5
|
+
export declare const sourced: (line: string) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* The ask with each known line that names no source moved to its premises. A run seeded with
|
|
8
|
+
* "the buyer is X" plans inside X unless something tests X; a sourced line is looked past.
|
|
9
|
+
*/
|
|
10
|
+
export declare function withPremises<A extends {
|
|
11
|
+
known?: readonly string[];
|
|
12
|
+
premises?: readonly string[];
|
|
13
|
+
}>(ask: A): A & {
|
|
14
|
+
known: string[];
|
|
15
|
+
premises: string[];
|
|
16
|
+
};
|
|
17
|
+
/** The known lines, then the premises under their own heading, or nothing more. */
|
|
18
|
+
export declare const renderKnown: (ask: {
|
|
19
|
+
known: readonly string[];
|
|
20
|
+
premises?: readonly string[];
|
|
21
|
+
}) => string;
|
|
22
|
+
/**
|
|
23
|
+
* "The person says:" and their lines, then their tests of a good source, or nothing: a prompt
|
|
24
|
+
* pays for a heading only when there is one. The tests ride the steer slot, so a stored plan file
|
|
25
|
+
* shows them with no new mark.
|
|
26
|
+
*/
|
|
27
|
+
export declare const renderSteer: (ask: {
|
|
28
|
+
steer?: readonly string[];
|
|
29
|
+
criteria?: readonly {
|
|
30
|
+
name: string;
|
|
31
|
+
question: string;
|
|
32
|
+
}[];
|
|
33
|
+
}) => string;
|
|
34
|
+
/** What the last round left open, under its heading, or nothing. */
|
|
35
|
+
export declare const renderOpen: (open: readonly string[] | undefined) => string;
|
|
36
|
+
/** The plan file's word on age as one more rule line, or nothing. */
|
|
37
|
+
export declare const renderAge: (age: string | undefined) => string;
|
|
38
|
+
/** One line per row, the keys it has first: `source=exa channel=... hits=12 reads=4 proposed=9 kept=3`. */
|
|
39
|
+
export declare function renderYield(rows: readonly YieldRow[]): string;
|
|
40
|
+
/** Numbered, one hit per line, only the fields it has. */
|
|
41
|
+
export declare function renderHits(hits: readonly HitView[]): string;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export const lines = (xs, none = "(nothing)") => xs.length ? xs.map((x) => `- ${x}`).join("\n") : none;
|
|
2
|
+
/** A line with a URL or a ledger id on it: a fact someone can go and check. */
|
|
3
|
+
export const sourced = (line) => /https?:\/\/\S|\b[0-9A-HJKMNP-TV-Z]{26}\b/.test(line);
|
|
4
|
+
/**
|
|
5
|
+
* The ask with each known line that names no source moved to its premises. A run seeded with
|
|
6
|
+
* "the buyer is X" plans inside X unless something tests X; a sourced line is looked past.
|
|
7
|
+
*/
|
|
8
|
+
export function withPremises(ask) {
|
|
9
|
+
const known = ask.known ?? [];
|
|
10
|
+
return {
|
|
11
|
+
...ask,
|
|
12
|
+
known: known.filter(sourced),
|
|
13
|
+
premises: [...new Set([...(ask.premises ?? []), ...known.filter((l) => !sourced(l))])],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** The known lines, then the premises under their own heading, or nothing more. */
|
|
17
|
+
export const renderKnown = (ask) => lines(ask.known) +
|
|
18
|
+
(ask.premises?.length
|
|
19
|
+
? `\nTaken as given, with no source (test each one: it may be wrong):\n${lines(ask.premises)}`
|
|
20
|
+
: "");
|
|
21
|
+
/**
|
|
22
|
+
* "The person says:" and their lines, then their tests of a good source, or nothing: a prompt
|
|
23
|
+
* pays for a heading only when there is one. The tests ride the steer slot, so a stored plan file
|
|
24
|
+
* shows them with no new mark.
|
|
25
|
+
*/
|
|
26
|
+
export const renderSteer = (ask) => (ask.steer?.length ? `The person says:\n${lines(ask.steer)}\n` : "") +
|
|
27
|
+
(ask.criteria?.length
|
|
28
|
+
? `The person's tests of a good source:\n${lines(ask.criteria.map((c) => `${c.name}: ${c.question}`))}\n`
|
|
29
|
+
: "");
|
|
30
|
+
/** What the last round left open, under its heading, or nothing. */
|
|
31
|
+
export const renderOpen = (open) => open?.length ? `The last round left open (plan for these first):\n${lines(open)}\n` : "";
|
|
32
|
+
/** The plan file's word on age as one more rule line, or nothing. */
|
|
33
|
+
export const renderAge = (age) => (age ? `\n- Age: ${age}` : "");
|
|
34
|
+
/** One line per row, the keys it has first: `source=exa channel=... hits=12 reads=4 proposed=9 kept=3`. */
|
|
35
|
+
export function renderYield(rows) {
|
|
36
|
+
if (!rows.length)
|
|
37
|
+
return "(no history yet)";
|
|
38
|
+
return rows
|
|
39
|
+
.map((r) => {
|
|
40
|
+
const who = ["by", "source", "channel", "kind"]
|
|
41
|
+
.filter((k) => r[k] !== undefined)
|
|
42
|
+
.map((k) => `${k}=${r[k]}`);
|
|
43
|
+
return `- ${[...who, `hits=${r.hits}`, `reads=${r.reads}`, `proposed=${r.proposed}`, `kept=${r.kept}`].join(" ")}`;
|
|
44
|
+
})
|
|
45
|
+
.join("\n");
|
|
46
|
+
}
|
|
47
|
+
const oneLine = (s, max) => {
|
|
48
|
+
const t = s.replace(/\s+/g, " ").trim();
|
|
49
|
+
return t.length > max ? `${t.slice(0, max - 1)}…` : t;
|
|
50
|
+
};
|
|
51
|
+
/** Numbered, one hit per line, only the fields it has. */
|
|
52
|
+
export function renderHits(hits) {
|
|
53
|
+
return hits
|
|
54
|
+
.map((h, i) => {
|
|
55
|
+
const parts = [h.url];
|
|
56
|
+
if (h.title)
|
|
57
|
+
parts.push(`title: ${oneLine(h.title, 120)}`);
|
|
58
|
+
if (h.channel)
|
|
59
|
+
parts.push(`channel: ${h.channel}`);
|
|
60
|
+
if (h.length !== undefined)
|
|
61
|
+
parts.push(`length: ${Math.round(h.length)}s`);
|
|
62
|
+
if (h.date)
|
|
63
|
+
parts.push(`date: ${h.date}`);
|
|
64
|
+
if (h.sources.length)
|
|
65
|
+
parts.push(`sources: ${h.sources.join(",")}`);
|
|
66
|
+
if (h.snippet)
|
|
67
|
+
parts.push(`snippet: ${oneLine(h.snippet, 240)}`);
|
|
68
|
+
const odds = Object.entries(h.odds ?? {});
|
|
69
|
+
if (odds.length)
|
|
70
|
+
parts.push(`judge (a cheap model's yes odds, a hint): ${odds.map(([k, v]) => `${k} ${v.toFixed(2)}`).join(", ")}`);
|
|
71
|
+
return `${i + 1}. ${parts.join(" | ")}`;
|
|
72
|
+
})
|
|
73
|
+
.join("\n");
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/plan/render.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAqB,EAAE,IAAI,GAAG,WAAW,EAAU,EAAE,CACzE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI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AO,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QACjE,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QAC1C,IAAI,IAAI,CAAC,MAAM;YACb,KAAK,CAAC,IAAI,CACR,6CAA6C,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACvG,CAAC;QACJ,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;IAC1C,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* After a round: stop, go again from plan, or back to one step. The model decides and says why;
|
|
3
|
+
* the round budget is a guard rail it sees (`{round}` of `{rounds}`), never a stop rule. The
|
|
4
|
+
* runner takes the edge and parks past the budget; the planner never loops.
|
|
5
|
+
*/
|
|
6
|
+
import type { Model } from "@wrenautomation/models";
|
|
7
|
+
import { type Edge, type PlanFile, type Round } from "./types.js";
|
|
8
|
+
export declare function reviewPrompt(round: Round, planFile: PlanFile): string;
|
|
9
|
+
export declare function review(round: Round, model: Model, options?: {
|
|
10
|
+
planFile?: PlanFile;
|
|
11
|
+
}): Promise<Edge>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { fill } from "./model.js";
|
|
2
|
+
import { ageOf, defaultPlanFile } from "./plans/index.js";
|
|
3
|
+
import { lines, renderAge, renderSteer } from "./render.js";
|
|
4
|
+
import { Step, z } from "./types.js";
|
|
5
|
+
const EdgeAnswer = z.object({
|
|
6
|
+
next: z.enum(["stop", "again", "back"]),
|
|
7
|
+
to: Step.optional(),
|
|
8
|
+
why: z.string(),
|
|
9
|
+
});
|
|
10
|
+
const verdictLine = (v) => `${v.url}: ${v.quality}${v.gap ? `. ${v.gap}` : ""}`;
|
|
11
|
+
/** A count with the earlier rounds' after it: rides the `{hits}` and `{kept}` slots, so a stored plan file shows it too. */
|
|
12
|
+
const trend = (now, before) => before.length ? `${now} (earlier rounds: ${before.join(", ")})` : now;
|
|
13
|
+
export function reviewPrompt(round, planFile) {
|
|
14
|
+
return fill(planFile.review, {
|
|
15
|
+
ask: round.ask.text,
|
|
16
|
+
steer: renderSteer(round.ask),
|
|
17
|
+
round: String(round.round),
|
|
18
|
+
rounds: String(round.budget.rounds),
|
|
19
|
+
hits: trend(`${round.hits} new`, round.earlier.map((e) => e.hits)),
|
|
20
|
+
reads: String(round.reads),
|
|
21
|
+
proposed: String(round.proposed),
|
|
22
|
+
kept: trend(String(round.kept), round.earlier.map((e) => e.kept)),
|
|
23
|
+
found: lines(round.found),
|
|
24
|
+
notes: lines(round.notes, "(none)"),
|
|
25
|
+
gaps: lines(round.gaps, "(none)"),
|
|
26
|
+
checks: lines(round.checks, "(none)"),
|
|
27
|
+
age: renderAge(ageOf(planFile)),
|
|
28
|
+
verdicts: lines(round.verdicts.map(verdictLine), "(none)"),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export async function review(round, model, options = {}) {
|
|
32
|
+
const planFile = options.planFile ?? defaultPlanFile(round.ask.kind);
|
|
33
|
+
const { value: out } = await model.ask(reviewPrompt(round, planFile), EdgeAnswer);
|
|
34
|
+
const edge = { next: out.next, why: out.why, from: "ai", by: model.id };
|
|
35
|
+
if (out.next === "back")
|
|
36
|
+
edge.to = out.to ?? "fetch";
|
|
37
|
+
return edge;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=review.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"review.js","sourceRoot":"","sources":["../../src/plan/review.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,IAAI,EAA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E,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;IAC9E,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM;QAAE,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC;IACrD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The filter before the read: for each hit, read or skip, from what the hit shows for free.
|
|
3
|
+
* Hits dedupe by url and keep every source that returned them. The model picks; the read budget
|
|
4
|
+
* caps it; a hit the model did not name is a skip, written down as one. The model writes a why
|
|
5
|
+
* on a read only: a skip's why is fixed text, so the answer pays for the reads alone.
|
|
6
|
+
*/
|
|
7
|
+
import type { Model } from "@wrenautomation/models";
|
|
8
|
+
import { HitView, type HitViewIn, type Plan, type PlanFile, type Triage, type YieldRow } from "./types.js";
|
|
9
|
+
/** What a skip says: the model named it and passed. */
|
|
10
|
+
export declare const SKIPPED = "skipped by the model";
|
|
11
|
+
/** One hit per url, sources merged, order of first sight. */
|
|
12
|
+
export declare function dedupeHits(hits: readonly HitViewIn[]): HitView[];
|
|
13
|
+
export declare function triagePrompt(hits: readonly HitView[], plan: Plan, planFile: PlanFile, yieldRows: readonly YieldRow[]): string;
|
|
14
|
+
/** Read or skip per hit, with why. Reads over the plan's budget flip to skips, in the model's order. */
|
|
15
|
+
export declare function triage(hits: readonly HitViewIn[], plan: Plan, model: Model, options?: {
|
|
16
|
+
planFile?: PlanFile;
|
|
17
|
+
yieldRows?: readonly YieldRow[];
|
|
18
|
+
}): Promise<Triage[]>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { fill } from "./model.js";
|
|
2
|
+
import { ageOf, defaultPlanFile } from "./plans/index.js";
|
|
3
|
+
import { renderAge, renderHits, renderKnown, renderOpen, renderSteer, renderYield, } from "./render.js";
|
|
4
|
+
import { HitView, z, } from "./types.js";
|
|
5
|
+
const TriageAnswer = z.object({
|
|
6
|
+
hits: z.array(z.object({ url: z.string(), read: z.boolean(), why: z.string().nullable().optional() })),
|
|
7
|
+
});
|
|
8
|
+
/** What a skip says: the model named it and passed. */
|
|
9
|
+
export const SKIPPED = "skipped by the model";
|
|
10
|
+
/** One hit per url, sources merged, order of first sight. */
|
|
11
|
+
export function dedupeHits(hits) {
|
|
12
|
+
const byUrl = new Map();
|
|
13
|
+
for (const h of hits.map((x) => HitView.parse(x))) {
|
|
14
|
+
const url = h.url.trim();
|
|
15
|
+
const have = byUrl.get(url);
|
|
16
|
+
if (!have) {
|
|
17
|
+
byUrl.set(url, { ...h, url, sources: [...new Set(h.sources)] });
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
for (const s of h.sources)
|
|
21
|
+
if (!have.sources.includes(s))
|
|
22
|
+
have.sources.push(s);
|
|
23
|
+
for (const k of ["title", "channel", "length", "date", "snippet"]) {
|
|
24
|
+
if (have[k] === undefined && h[k] !== undefined)
|
|
25
|
+
have[k] = h[k];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return [...byUrl.values()];
|
|
29
|
+
}
|
|
30
|
+
export function triagePrompt(hits, plan, planFile, yieldRows) {
|
|
31
|
+
return fill(planFile.triage, {
|
|
32
|
+
n: String(plan.budget.reads),
|
|
33
|
+
ask: plan.ask.text,
|
|
34
|
+
site: plan.ask.site ?? "",
|
|
35
|
+
steer: renderSteer(plan.ask),
|
|
36
|
+
open: renderOpen(plan.ask.open),
|
|
37
|
+
age: renderAge(ageOf(planFile)),
|
|
38
|
+
known: renderKnown(plan.ask),
|
|
39
|
+
yield: renderYield(yieldRows),
|
|
40
|
+
hits: renderHits(hits),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/** Read or skip per hit, with why. Reads over the plan's budget flip to skips, in the model's order. */
|
|
44
|
+
export async function triage(hits, plan, model, options = {}) {
|
|
45
|
+
const unique = dedupeHits(hits);
|
|
46
|
+
if (!unique.length)
|
|
47
|
+
return [];
|
|
48
|
+
const planFile = options.planFile ?? defaultPlanFile(plan.ask.kind);
|
|
49
|
+
const { value: out } = await model.ask(triagePrompt(unique, plan, planFile, options.yieldRows ?? []), TriageAnswer);
|
|
50
|
+
const said = new Map(out.hits.map((h) => [h.url.trim(), h]));
|
|
51
|
+
let reads = 0;
|
|
52
|
+
return unique.map((h) => {
|
|
53
|
+
const a = said.get(h.url);
|
|
54
|
+
const base = { url: h.url, from: "ai", by: model.id };
|
|
55
|
+
if (!a)
|
|
56
|
+
return { ...base, read: false, why: "not named by the model" };
|
|
57
|
+
if (!a.read)
|
|
58
|
+
return { ...base, read: false, why: a.why?.trim() || SKIPPED };
|
|
59
|
+
if (reads >= plan.budget.reads)
|
|
60
|
+
return { ...base, read: false, why: `over the read budget (${plan.budget.reads})` };
|
|
61
|
+
reads++;
|
|
62
|
+
return { ...base, read: true, why: a.why?.trim() || "read" };
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=triage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triage.js","sourceRoot":"","sources":["../../src/plan/triage.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EACL,SAAS,EACT,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,OAAO,EAMP,CAAC,GACF,MAAM,YAAY,CAAC;AAEpB,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,IAAI,EAAE,CAAC,CAAC,KAAK,CACX,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,C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