@startsimpli/integrations 0.2.214 → 0.2.216

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 (56) hide show
  1. package/package.json +5 -5
  2. package/src/__tests__/briefing-record-library.test.ts +47 -0
  3. package/src/__tests__/connect-claude.test.tsx +2 -0
  4. package/src/__tests__/corpus-tracker.test.tsx +13 -2
  5. package/src/__tests__/engine-decide.test.ts +160 -0
  6. package/src/__tests__/engine-extract-policy.test.ts +145 -0
  7. package/src/__tests__/engine-replay.test.ts +126 -0
  8. package/src/__tests__/engine-scheduled-run.test.ts +82 -0
  9. package/src/__tests__/extract-skips-tandem-authored.test.ts +34 -0
  10. package/src/__tests__/load-error.test.tsx +3 -1
  11. package/src/__tests__/suggested-items-hidden.test.ts +74 -0
  12. package/src/__tests__/suggestion-ui.test.tsx +97 -0
  13. package/src/__tests__/todo-table.test.tsx +2 -1
  14. package/src/components/pages/ConnectClaudePage.tsx +2 -1
  15. package/src/components/pages/TaskDetailPage.tsx +10 -0
  16. package/src/components/pages/TrackerPage.tsx +32 -10
  17. package/src/components/pages/tracker/Suggestion.tsx +66 -0
  18. package/src/components/table/todo-model.ts +1 -0
  19. package/src/corpus/activity.ts +2 -3
  20. package/src/corpus/ask-items.ts +2 -2
  21. package/src/corpus/briefing/compose.ts +2 -2
  22. package/src/corpus/briefing/weekly.ts +2 -2
  23. package/src/corpus/briefing-text.ts +11 -0
  24. package/src/corpus/client.ts +2 -0
  25. package/src/corpus/commitments.ts +20 -3
  26. package/src/corpus/converse/briefing-queue.ts +2 -1
  27. package/src/corpus/converse/item-answers.ts +2 -2
  28. package/src/corpus/due-groups.ts +2 -2
  29. package/src/corpus/engine/apply.ts +111 -0
  30. package/src/corpus/engine/decide.ts +106 -0
  31. package/src/corpus/engine/dry-extract.ts +98 -0
  32. package/src/corpus/engine/graduation.ts +49 -0
  33. package/src/corpus/engine/index.ts +14 -0
  34. package/src/corpus/engine/replay.ts +222 -0
  35. package/src/corpus/engine/rules.ts +58 -0
  36. package/src/corpus/engine/sources.ts +16 -0
  37. package/src/corpus/engine/suggestion.ts +72 -0
  38. package/src/corpus/engine/types.ts +147 -0
  39. package/src/corpus/entities.ts +9 -2
  40. package/src/corpus/extract-prompts.ts +139 -0
  41. package/src/corpus/extract.ts +46 -139
  42. package/src/corpus/focus-overview.ts +2 -2
  43. package/src/corpus/index.ts +9 -0
  44. package/src/corpus/item-status.ts +17 -0
  45. package/src/corpus/note-actions.ts +3 -3
  46. package/src/corpus/questions/derive.ts +2 -1
  47. package/src/corpus/questions/sync.ts +2 -1
  48. package/src/corpus/retrieval.ts +3 -0
  49. package/src/corpus/runs.ts +31 -2
  50. package/src/corpus/today.ts +2 -2
  51. package/src/corpus/tracker-groups.ts +3 -0
  52. package/src/corpus/tracker-timeline-client.ts +1 -1
  53. package/src/corpus/types.ts +13 -3
  54. package/src/native/screens/connect-claude/ConnectClaudeScreen.tsx +1 -1
  55. package/src/native/screens/connect-claude/fake.ts +1 -1
  56. package/src/native/tracker/format.ts +1 -1
@@ -0,0 +1,58 @@
1
+ /**
2
+ * THE RULE TABLE (bd startsim-vrmx5). One row per rule the engine can fire.
3
+ *
4
+ * `auto` is the starting mode. Only three rules start as `act`, and each one is
5
+ * either deterministic or carries a source of record:
6
+ *
7
+ * C-VENDOR the note-taker's own action list, parsed by fixed rules
8
+ * (measured 98.5% precision, eval/extraction-eval.test.ts, 2026-08-10)
9
+ * U-REMOTE the tracker itself changed the state
10
+ * L-EXACT the identical identity key: a restatement, not a judgement
11
+ *
12
+ * Every other rule starts as `propose` and graduates to `act` only once the
13
+ * owner's own reviews show it right often enough (./graduation).
14
+ *
15
+ * `prior` is the confidence a rule carries before labels exist. Where a number
16
+ * was measured it is that number; where nothing was measured it is deliberately
17
+ * low, so the rule stays a suggestion until the owner's reviews say otherwise.
18
+ */
19
+ import type { EngineVerb, RuleId } from './types';
20
+
21
+ export interface RuleSpec {
22
+ id: RuleId;
23
+ verb: EngineVerb;
24
+ /** Starting mode before any labels. Ignore rules never act. */
25
+ auto: 'act' | 'propose' | 'skip';
26
+ prior: number;
27
+ /** The plain sentence the "why" view shows. */
28
+ reason: string;
29
+ }
30
+
31
+ const spec = (id: RuleId, verb: EngineVerb, auto: RuleSpec['auto'], prior: number, reason: string): RuleSpec =>
32
+ ({ id, verb, auto, prior, reason });
33
+
34
+ export const RULES: Readonly<Record<RuleId, RuleSpec>> = {
35
+ 'X-OWNER': spec('X-OWNER', 'ignore', 'skip', 1, 'The source belongs to someone else, so it is not read for you.'),
36
+ 'X-SELF': spec('X-SELF', 'ignore', 'skip', 1, 'Tandem wrote this source itself; it is never read back as new work.'),
37
+ 'X-UNGROUNDED': spec('X-UNGROUNDED', 'ignore', 'skip', 1, 'The quote it rests on is not in the source.'),
38
+ 'X-UNVERIFIED': spec('X-UNVERIFIED', 'ignore', 'skip', 1, 'The checker could not find where somebody took this on.'),
39
+ 'X-OTHERS': spec('X-OTHERS', 'ignore', 'skip', 1, 'Someone else took this on, and it is not owed to you.'),
40
+ 'X-HUMAN': spec('X-HUMAN', 'ignore', 'skip', 1, 'You set this yourself, so it is left as you set it.'),
41
+ 'X-NO-MATCH': spec('X-NO-MATCH', 'ignore', 'skip', 1, 'It does not match anything open on your list.'),
42
+
43
+ 'C-VENDOR': spec('C-VENDOR', 'create', 'act', 0.985, 'Listed under the note\'s next steps with you as owner.'),
44
+ 'C-MODEL': spec('C-MODEL', 'create', 'propose', 0.8, 'Said in the source and confirmed by the checker, with you as owner.'),
45
+ 'C-WAITING': spec('C-WAITING', 'create', 'propose', 0.6, 'Someone committed this to you; tracked as waiting on them.'),
46
+ 'C-UNOWNED': spec('C-UNOWNED', 'create', 'propose', 0.5, 'Agreed in the source, but nobody was named as owner.'),
47
+
48
+ 'L-EXACT': spec('L-EXACT', 'merge', 'act', 0.99, 'The same item again; the new mention is added to it.'),
49
+ 'L-NEAR': spec('L-NEAR', 'merge', 'propose', 0.8, 'Same subject and nearly the same wording as an item you have.'),
50
+ 'L-RELATED': spec('L-RELATED', 'link', 'propose', 0.6, 'Close to an item you have, without a shared subject.'),
51
+
52
+ 'U-REMOTE': spec('U-REMOTE', 'update', 'act', 0.99, 'Changed in your tracker, which is the record for this item.'),
53
+ 'U-RESOLVED': spec('U-RESOLVED', 'update', 'propose', 0.7, 'A later source says this is finished or dropped.'),
54
+ 'U-DATE': spec('U-DATE', 'update', 'propose', 0.6, 'A later source states a new date for this.'),
55
+ };
56
+
57
+ /** The three rules allowed to act before any review (Quinn, 2026-11-24 via the relay). */
58
+ export const SAFE_RULES: ReadonlySet<RuleId> = new Set<RuleId>(['C-VENDOR', 'U-REMOTE', 'L-EXACT']);
@@ -0,0 +1,16 @@
1
+ /**
2
+ * SOURCES TANDEM WROTE ITSELF (bd startsim-vrmx5).
3
+ *
4
+ * The morning briefing, the notify state, the relay inbox and the rest are
5
+ * stored as source documents so Ask and the timeline can cite them, but they are
6
+ * Tandem's own output. Reading them back as new evidence is a loop: a briefing
7
+ * that lists "send the deck" would be extracted as a fresh "send the deck".
8
+ * Extraction, the engine and the activity recap all skip them, from this one list.
9
+ */
10
+ export const TANDEM_AUTHORED_SOURCES: ReadonlySet<string> = new Set([
11
+ 'notify_state', 'relay_inbox', 'fleet_status', 'briefing_actions', 'decision', 'briefing',
12
+ ]);
13
+
14
+ export function isTandemAuthored(source: string | null | undefined): boolean {
15
+ return TANDEM_AUTHORED_SOURCES.has(String(source ?? ''));
16
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * WHY AN ITEM IS ON THE LIST, stored on the item (bd startsim-vrmx5 slice 2).
3
+ *
4
+ * Every item the engine wrote carries the decision that put it there: the rule,
5
+ * the confidence, the plain reason, and the quote and source it rests on. The
6
+ * to-do list reads it for the "why" line and for the accept / edit / reject
7
+ * buttons on a suggestion; the owner's answer is written back as `outcome`, and
8
+ * those answers are the labels that graduate a rule (./graduation).
9
+ */
10
+ import type { Decision, DecisionLabel, EngineMode, RuleId } from './types';
11
+ import { RULES } from './rules';
12
+
13
+ export interface Suggestion {
14
+ rule: RuleId;
15
+ mode: EngineMode;
16
+ confidence: number;
17
+ reason: string;
18
+ documentId: string;
19
+ quote: string;
20
+ /** Set when the owner reviews a suggestion. */
21
+ outcome?: 'accepted' | 'edited' | 'rejected';
22
+ reviewedAt?: string;
23
+ }
24
+
25
+ export function suggestionOf(decision: Decision): Suggestion {
26
+ return {
27
+ rule: decision.rule,
28
+ mode: decision.mode,
29
+ confidence: Math.round(decision.confidence * 1000) / 1000,
30
+ reason: decision.reason,
31
+ documentId: decision.evidence.documentId,
32
+ quote: decision.evidence.quote.slice(0, 400),
33
+ };
34
+ }
35
+
36
+ const OUTCOMES = new Set(['accepted', 'edited', 'rejected']);
37
+ const MODES = new Set(['act', 'propose', 'skip']);
38
+
39
+ export function readSuggestion(raw: unknown): Suggestion | undefined {
40
+ if (!raw || typeof raw !== 'object') return undefined;
41
+ const r = raw as Record<string, unknown>;
42
+ const rule = String(r.rule ?? '') as RuleId;
43
+ if (!(rule in RULES)) return undefined;
44
+ const mode = String(r.mode ?? '');
45
+ const outcome = String(r.outcome ?? '');
46
+ return {
47
+ rule,
48
+ mode: (MODES.has(mode) ? mode : 'propose') as EngineMode,
49
+ confidence: Number(r.confidence ?? 0) || 0,
50
+ reason: String(r.reason ?? ''),
51
+ documentId: String(r.document_id ?? r.documentId ?? ''),
52
+ quote: String(r.quote ?? ''),
53
+ ...(OUTCOMES.has(outcome) ? { outcome: outcome as Suggestion['outcome'] } : {}),
54
+ ...(r.reviewed_at || r.reviewedAt ? { reviewedAt: String(r.reviewed_at ?? r.reviewedAt) } : {}),
55
+ };
56
+ }
57
+
58
+ export function writeSuggestion(s: Suggestion): Record<string, unknown> {
59
+ return {
60
+ rule: s.rule, mode: s.mode, confidence: s.confidence, reason: s.reason,
61
+ document_id: s.documentId, quote: s.quote,
62
+ ...(s.outcome ? { outcome: s.outcome } : {}),
63
+ ...(s.reviewedAt ? { reviewed_at: s.reviewedAt } : {}),
64
+ };
65
+ }
66
+
67
+ /** Labels for graduation from items the owner reviewed. Automation never reviews. */
68
+ export function labelsFrom(items: Array<{ suggestion?: Suggestion }>): DecisionLabel[] {
69
+ return items.flatMap((item) => item.suggestion?.outcome
70
+ ? [{ rule: item.suggestion.rule, outcome: item.suggestion.outcome, actor: 'human' as const }]
71
+ : []);
72
+ }
@@ -0,0 +1,147 @@
1
+ /**
2
+ * THE TANDEM ENGINE'S VOCABULARY (bd startsim-vrmx5, Todo: ENG-151).
3
+ *
4
+ * The engine answers one question for every piece of evidence a pass finds:
5
+ * what, if anything, should change on this person's to-do list, and why. It is
6
+ * a pure function (`decide`) so the same evidence always gets the same answer,
7
+ * and every answer names the rule that produced it, the quote it rests on and
8
+ * whether it is applied now or offered as a suggestion.
9
+ */
10
+
11
+ /** What the engine would do with a piece of evidence. */
12
+ export type EngineVerb = 'create' | 'update' | 'merge' | 'link' | 'ignore';
13
+
14
+ /**
15
+ * Whether a decision is applied, offered, or nothing happens.
16
+ *
17
+ * act applied by the pass, reversible from the item's history
18
+ * propose shown as a suggestion in the to-do list (accept / edit / reject)
19
+ * skip nothing changes; the reason is still recorded for the dry run
20
+ */
21
+ export type EngineMode = 'act' | 'propose' | 'skip';
22
+
23
+ /** Stable rule ids. Labels, graduation and the dry-run report key on these. */
24
+ export type RuleId =
25
+ // ignore
26
+ | 'X-OWNER' // evidence from another person's source: never crosses owners
27
+ | 'X-SELF' // Tandem wrote the source itself (briefings, bookkeeping)
28
+ | 'X-UNGROUNDED' // quote not found in the source
29
+ | 'X-UNVERIFIED' // model candidate the verifier did not confirm
30
+ | 'X-OTHERS' // someone else's commitment that does not involve the owner
31
+ | 'X-HUMAN' // would overwrite a field a person set
32
+ | 'X-NO-MATCH' // a resolution or date that matches no open item
33
+ // create
34
+ | 'C-VENDOR' // the note-taker's own "Next steps" bullet owned by the owner
35
+ | 'C-MODEL' // a verified model item owned by the owner
36
+ | 'C-WAITING' // someone else's commitment TO the owner (waiting on)
37
+ | 'C-UNOWNED' // a verified item with no owner named
38
+ // merge / link
39
+ | 'L-EXACT' // same identity key as an existing item
40
+ | 'L-NEAR' // same subject, close wording
41
+ | 'L-RELATED' // close wording, no shared subject: link, do not merge
42
+ // update
43
+ | 'U-REMOTE' // the tracker (source of record) changed status
44
+ | 'U-RESOLVED' // a later source says an open item is done or dropped
45
+ | 'U-DATE'; // a later source states a new date for an open item
46
+
47
+ /** Who the evidence is about, relative to the person the pass runs for. */
48
+ export type OwnerRelation = 'self' | 'other' | 'none';
49
+
50
+ /** How an incoming statement matches an item already on the list. */
51
+ export type MatchStrength = 'exact' | 'anchored' | 'unanchored';
52
+
53
+ /**
54
+ * One piece of evidence, already reduced to facts. Building a candidate is the
55
+ * caller's job (extraction, the tracker sync, the dry-run replay); judging it is
56
+ * the engine's.
57
+ */
58
+ export type Candidate = ItemCandidate | ResolutionCandidate | DateCandidate | RemoteCandidate;
59
+
60
+ interface CandidateBase {
61
+ /** The source document (or tracker event) the evidence came from. */
62
+ documentId: string;
63
+ /** Row owner of that source. The pass may only act when this is the pass owner. */
64
+ documentOwnerSub: string | null;
65
+ /** The document's source key (granola, gmail, briefing, ...). */
66
+ documentSource: string;
67
+ /** Verbatim span the evidence rests on. */
68
+ quote: string;
69
+ }
70
+
71
+ /** A proposed to-do from a note, an email or a voice capture. */
72
+ export interface ItemCandidate extends CandidateBase {
73
+ kind: 'item';
74
+ extractor: 'rules' | 'model';
75
+ /** The quote was found in the document (grounding gate). */
76
+ grounded: boolean;
77
+ /** The adversarial verifier confirmed it. Always true for the rules pass. */
78
+ verified: boolean;
79
+ owner: OwnerRelation;
80
+ subtype: string;
81
+ status: string;
82
+ /** People on the source besides the owner. A one-to-one makes "theirs" also "to me". */
83
+ participantCount: number;
84
+ /** The best match on the owner's list, if any. */
85
+ match?: ItemMatch | null;
86
+ }
87
+
88
+ /** An existing item a statement matches. Its owner is checked: no merge across owners. */
89
+ export interface ItemMatch {
90
+ itemId: string;
91
+ strength: MatchStrength;
92
+ itemOwnerSub: string | null;
93
+ }
94
+
95
+ /** "That is done" / "we dropped that", said in a later source. */
96
+ export interface ResolutionCandidate extends CandidateBase {
97
+ kind: 'resolution';
98
+ outcome: 'done' | 'dropped';
99
+ /** Open items the claim could be about, best first. */
100
+ matches: ItemMatch[];
101
+ /** Fields on the best match that a person set. */
102
+ humanEdited?: string[];
103
+ }
104
+
105
+ /** A new date stated for an item already on the list. */
106
+ export interface DateCandidate extends CandidateBase {
107
+ kind: 'date';
108
+ itemId: string | null;
109
+ dueAt: string;
110
+ humanEdited?: string[];
111
+ }
112
+
113
+ /** The tracker (Linear) changed an item's state. */
114
+ export interface RemoteCandidate extends CandidateBase {
115
+ kind: 'remote';
116
+ itemId: string;
117
+ field: string;
118
+ }
119
+
120
+ /** The person this pass runs for. */
121
+ export interface DecisionContext {
122
+ ownerSub: string;
123
+ }
124
+
125
+ /** The answer for one candidate. Everything the "why" view and undo need. */
126
+ export interface Decision {
127
+ verb: EngineVerb;
128
+ mode: EngineMode;
129
+ rule: RuleId;
130
+ /** The rule's measured precision, or its prior before enough labels exist. */
131
+ confidence: number;
132
+ /** One plain sentence for the "why did you do this" view. */
133
+ reason: string;
134
+ evidence: { documentId: string; quote: string };
135
+ /** The existing item this changes, when it changes one. */
136
+ targetId?: string;
137
+ /** Every applied change can be undone from the stored prior values. */
138
+ reversible: boolean;
139
+ }
140
+
141
+ /** A reviewed decision: what the owner did with it. Feeds graduation and evals. */
142
+ export interface DecisionLabel {
143
+ rule: RuleId;
144
+ outcome: 'accepted' | 'edited' | 'rejected';
145
+ /** Only labels from a person count; automation never grades the engine. */
146
+ actor: 'human' | 'automation';
147
+ }
@@ -22,7 +22,9 @@
22
22
  * blanks itself because an attribute was renamed is worse than one that shows a
23
23
  * row with a missing subtitle.
24
24
  */
25
+ import { briefingSections } from './briefing-text';
25
26
  import { readPossiblyDone, writePossiblyDone } from './possibly-done';
27
+ import { readSuggestion, writeSuggestion } from './engine/suggestion';
26
28
  import { withSourceEntity } from './source-entity';
27
29
  import { decodeOwnerSubs, encodeOwnerSubs } from './owner-link';
28
30
  import { readItemSync, type ItemSync } from '../task-tracker/item-sync';
@@ -516,7 +518,7 @@ export function toSourceDocument(
516
518
  const summary = asText(pick(data, 'summary', 'description'));
517
519
  const fullText = asText(pick(data, 'body', 'text', 'content'));
518
520
 
519
- const sections = toSections(pick(data, 'sections'));
521
+ const sections = [...toSections(pick(data, 'sections')), ...briefingSections(data)];
520
522
  // A source that stored its long-form under a bare attribute rather than in
521
523
  // `sections` still contributes one. Listed keys are storage spellings, not
522
524
  // vendor knowledge: the same loop picks up a Drive connector's `extracted_text`.
@@ -558,6 +560,9 @@ export function toSourceDocument(
558
560
  // delivery writes typed edges and a bare `participant_count`. Reading only
559
561
  // the first is what made `participants` empty on every document the pipeline
560
562
  // has ever delivered (bd startsim-768w.38.22).
563
+ // The connector's own head count, kept even when participants are not resolved (bd startsim-vrmx5).
564
+ ...(Number(pick(data, 'participant_count', 'participantCount')) > 0
565
+ ? { participantCount: Number(pick(data, 'participant_count', 'participantCount')) } : {}),
561
566
  participants: mergeParticipants(
562
567
  asList(pick(data, 'participants', 'attendees', 'parties'))
563
568
  .map(toPartyRef)
@@ -718,7 +723,7 @@ export function toCommitment(
718
723
  subtype: asText(pick(data, 'subtype')) || 'action',
719
724
  title: asText(pick(data, 'title')) || entity.name || 'Untitled item',
720
725
  detail: asText(pick(data, 'detail', 'description')),
721
- status: ['open', 'in_progress', 'done', 'blocked', 'dropped'].includes(status) ? status : 'open',
726
+ status: ['open', 'in_progress', 'done', 'blocked', 'dropped', 'suggested'].includes(status) ? status : 'open',
722
727
  ...(pick(data, 'status_reason', 'statusReason')
723
728
  ? { statusReason: asText(pick(data, 'status_reason', 'statusReason')) } : {}),
724
729
  ...(pick(data, 'resolved_by', 'resolvedBy')
@@ -751,6 +756,7 @@ export function toCommitment(
751
756
  ? { origin: asText(pick(data, ORIGIN_KEY, 'Origin')) } : {}),
752
757
  ...withSync(data),
753
758
  mentions,
759
+ ...(readSuggestion(pick(data, 'suggestion')) ? { suggestion: readSuggestion(pick(data, 'suggestion')) } : {}),
754
760
  ...(readPossiblyDone(pick(data, 'possibly_done', 'possiblyDone')).length
755
761
  ? { possiblyDone: readPossiblyDone(pick(data, 'possibly_done', 'possiblyDone')) } : {}),
756
762
  firstSeenAt: asIso(pick(data, 'first_seen_at', 'firstSeenAt')),
@@ -844,6 +850,7 @@ export function commitmentToEntity(commitment: Commitment): {
844
850
  ...(mention.section ? { section: mention.section } : {}),
845
851
  })),
846
852
  ...(commitment.possiblyDone?.length ? { possibly_done: writePossiblyDone(commitment.possiblyDone) } : {}),
853
+ ...(commitment.suggestion ? { suggestion: writeSuggestion(commitment.suggestion) } : {}),
847
854
  extractor_version: commitment.extractorVersion,
848
855
  source: commitment.source,
849
856
  // Marks the row as pipeline-written, the same way the corpus delivery
@@ -0,0 +1,139 @@
1
+ /**
2
+ * THE EXTRACTION AND VERIFICATION PROMPTS, split out of ./extract so the
3
+ * pipeline file stays readable. Behaviour lives in ./extract; this file is the
4
+ * wording the model sees, and every rule in it is also enforced in code there.
5
+ */
6
+ import type { VerificationRequest } from './types';
7
+
8
+ // ---------------------------------------------------------------------------
9
+ // the prompt
10
+ // ---------------------------------------------------------------------------
11
+
12
+ /**
13
+ * Every rule in here is also enforced in code, because a prompt is a request and
14
+ * a check is a guarantee. What the prompt uniquely buys is the two things code
15
+ * cannot derive: what a statement is ABOUT, and whether a later meeting settled
16
+ * an earlier one.
17
+ */
18
+ export function extractSystemPrompt(): string {
19
+ return [
20
+ 'You read meeting records for one company and turn them into trackable items.',
21
+ 'You are given documents that ALREADY have some items extracted from them, listed under ALREADY_FOUND. Do NOT repeat those. Find what they missed.',
22
+ 'A document may contain a curated summary AND the verbatim transcript of the same meeting. ALREADY_FOUND was taken from the summary, so the items worth reporting are the ones that were said out loud and never made it into the summary.',
23
+ 'An item is something a person now owes, has decided, needs, is at risk from, or has asked. It must be stated in the document — never inferred, never invented.',
24
+ 'People in conversation say things they are not committing to. "We should probably look at that", "maybe next quarter", thinking aloud, reading an agenda, or describing what somebody else already did are NOT items.',
25
+ 'BUT A VAGUE OPENING FOLLOWED BY A DECISION IS AN ITEM. "Somebody has to cancel that seat" — "put it on Megan" is one commitment with an owner, not two hedges. So is "we need to ask the city about the sidewalk" when nobody argues and the group moves on. Read the exchange, not the sentence: what matters is whether the thing ends up settled, and who ends up holding it.',
26
+ 'For every item, copy a short verbatim "quote" from the document it came from, and echo that document\'s exact id. The quote must appear in the document CHARACTER FOR CHARACTER — it is checked, and an item whose quote is not found is discarded.',
27
+ 'Set "subject" to what the item is ABOUT — a matter or case number, a property, a client, a system, a person. Copy an identifier verbatim when the text has one.',
28
+ 'Set "owner" only to a name the document actually names. Leave it out otherwise.',
29
+ 'Never estimate or invent a due date, and do not compute one: the system reads the date itself from your "quote". When the item has a stated date or day ("by 29th July", "tomorrow", "on Monday"), make sure those exact words are inside the quote; when the document states none, say nothing about a date.',
30
+ 'Some documents are EMAILS (kind: email). The text starts with From, To and Direction lines. Direction "sent" means the mailbox owner wrote it, so commitments in it ("I will send...", "I will update...") belong to the owner. Direction "received" means somebody wrote to the owner: what the sender promises is theirs, what they ask for is the owner\'s.',
31
+ 'In an email, "waiting on" matters as much as "to do": when the writer says they are blocked on, or waiting for, another person ("waiting on your reply", "I need the sheet before Friday"), report a "need" with status "blocked", owner set to the person being waited on, and the writer named in the detail. Quoted older messages (lines starting with >) are history, not new statements.',
32
+ 'An issue key such as ENG-42 in a document is a strong "subject": copy it verbatim, including when the email says the work is finished or moved.',
33
+ 'Also report RESOLUTIONS: statements that something previously outstanding is now done or abandoned. Give the subject, what happened, and a verbatim quote.',
34
+ 'Respond with JSON only: {"items":[{"documentId":string,"subtype":"action"|"decision"|"need"|"risk"|"question","title":string,"detail":string,"status":"open"|"done"|"blocked","owner":string,"subject":string,"quote":string}],"resolutions":[{"documentId":string,"subject":string,"statement":string,"quote":string,"outcome":"done"|"dropped"}]}',
35
+ '"title" must be one short imperative line.',
36
+ ].join('\n');
37
+ }
38
+
39
+ /** ONE payload carrying every document, each tagged with the id to echo. */
40
+ export function renderExtractPrompt(input: {
41
+ documents: Array<{
42
+ id: string; title: string; source: string; occurredAt: string | null;
43
+ participants: string[]; kind?: string; text: string; alreadyFound: string[];
44
+ }>;
45
+ }): string {
46
+ const blocks = input.documents.map((document) =>
47
+ [
48
+ `<document id="${document.id}">`,
49
+ `title: ${document.title}`,
50
+ `source: ${document.source}`,
51
+ document.kind ? `kind: ${document.kind}` : '',
52
+ `occurred_at: ${document.occurredAt ?? 'unknown'}`,
53
+ document.participants.length ? `participants: ${document.participants.join(', ')}` : '',
54
+ document.alreadyFound.length
55
+ ? `ALREADY_FOUND (do not repeat these):\n${document.alreadyFound.map((title) => `- ${title}`).join('\n')}`
56
+ : 'ALREADY_FOUND: none',
57
+ '',
58
+ document.text,
59
+ '</document>',
60
+ ]
61
+ .filter((line) => line !== '')
62
+ .join('\n'),
63
+ );
64
+ return [`DOCUMENTS (${input.documents.length}):`, blocks.join('\n\n')].join('\n');
65
+ }
66
+
67
+ // ---------------------------------------------------------------------------
68
+ // the verification prompt
69
+ // ---------------------------------------------------------------------------
70
+
71
+ /**
72
+ * THE PRICE OF READING MORE TEXT.
73
+ *
74
+ * Measured on the summaries alone, adding the model pass took recall 56.1% →
75
+ * 65.9% and precision 95.8% → 67.5%. A transcript is roughly ten times the text
76
+ * and it is text of a different KIND — verbatim speech is full of sentences that
77
+ * have the grammar of a commitment and none of the substance. "I'll take a look
78
+ * at that", said and forgotten, is indistinguishable from a commitment to any
79
+ * extractor working sentence by sentence. So more text does not make the model
80
+ * pass more precise; it makes it less precise, and the recall it buys is only
81
+ * worth having if something else pays the precision back.
82
+ *
83
+ * This is that something else. A SECOND, CHEAPER, ADVERSARIAL pass whose only
84
+ * job is to say no: given the record and a candidate, is this a thing a named
85
+ * person actually took on, and where exactly does it say so. Anything it will
86
+ * not stand behind with a span from the record is dropped.
87
+ *
88
+ * It is deliberately asked as a REFUSAL task rather than a scoring one. "Rate
89
+ * your confidence 0-1" produces a number nobody can act on and a threshold
90
+ * nobody can defend; "quote the sentence where this was agreed, or say it was
91
+ * not" produces evidence, and evidence can be checked in code.
92
+ */
93
+ export function verifySystemPrompt(): string {
94
+ return [
95
+ 'You are checking a list of proposed commitments against the meeting records they were taken from. You are the last check before these appear on somebody\'s to-do list.',
96
+ 'For each candidate, decide ONE thing: did a specific person, in this document, actually take on this specific thing?',
97
+ 'Confirm it ONLY if you can copy the span of the document that says so. The span must appear in the document character for character.',
98
+ // MEASURED, and the obvious loosening is the wrong call. This line used to
99
+ // read "an unowned item can still be real — judge whether the document
100
+ // states it as settled or required, not whether it names a person", which is
101
+ // a perfectly good argument: the `need` subtype exists precisely for a
102
+ // stated requirement with nobody on it. Run it and the verifier keeps 56% of
103
+ // candidates instead of 37%, and the whole run scores 66.1% recall at 65.5%
104
+ // precision instead of 65.3% at 75.5%. One point of recall for ten points of
105
+ // precision. Requiring somebody to be on the hook is what makes this pass
106
+ // worth its own model call; without it the verifier agrees with the
107
+ // extractor, which is not a check.
108
+ 'Refuse it if: nobody owns it; it is a suggestion, a hypothetical, a hedge ("we should", "maybe", "at some point"); it describes something already finished; it is somebody reading an agenda or restating a topic; it is a scheduling note like when the next call is; or you cannot find where the document says it.',
109
+ 'Refusing a real commitment costs one missing row. Confirming an invented one puts work on a person who never agreed to it and makes the whole list untrustworthy. When you are unsure, refuse.',
110
+ 'Echo every candidate id back exactly once.',
111
+ 'Respond with JSON only: {"verdicts":[{"id":string,"confirmed":boolean,"quote":string,"reason":string}]}',
112
+ ].join('\n');
113
+ }
114
+
115
+ /** ONE payload carrying every candidate and the records they claim to come from. */
116
+ export function renderVerifyPrompt(input: VerificationRequest): string {
117
+ const documents = input.documents.map((document) =>
118
+ [`<document id="${document.id}">`, `title: ${document.title}`, '', document.text, '</document>'].join('\n'),
119
+ );
120
+ const candidates = input.candidates.map((candidate) =>
121
+ [
122
+ `<candidate id="${candidate.id}" document="${candidate.documentId}">`,
123
+ `kind: ${candidate.subtype}`,
124
+ `statement: ${candidate.title}`,
125
+ candidate.owner ? `claimed owner: ${candidate.owner}` : '',
126
+ `claimed evidence: ${candidate.quote}`,
127
+ '</candidate>',
128
+ ]
129
+ .filter(Boolean)
130
+ .join('\n'),
131
+ );
132
+ return [
133
+ `DOCUMENTS (${input.documents.length}):`,
134
+ documents.join('\n\n'),
135
+ '',
136
+ `CANDIDATES (${input.candidates.length}):`,
137
+ candidates.join('\n'),
138
+ ].join('\n');
139
+ }