@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/integrations",
3
- "version": "0.2.214",
3
+ "version": "0.2.216",
4
4
  "description": "Provider-agnostic types, API clients, hooks, and UI primitives for email + calendar integrations across StartSimpli apps, plus foundry customer email (subpath ./comms).",
5
5
  "license": "MIT",
6
6
  "homepage": "https://startsimpli.com",
@@ -50,8 +50,8 @@
50
50
  "react-native": ">=0.74.0",
51
51
  "@startsimpli/ui-native": ">=0.1.12",
52
52
  "react-native-safe-area-context": ">=4.0.0",
53
- "@startsimpli/ui": "^0.4.205",
54
- "@startsimpli/auth": "^0.4.60",
53
+ "@startsimpli/ui": "^0.4.207",
54
+ "@startsimpli/auth": "^0.4.62",
55
55
  "@startsimpli/utils": "^0.4.21"
56
56
  },
57
57
  "peerDependenciesMeta": {
@@ -99,9 +99,9 @@
99
99
  "react-native": "0.85.3",
100
100
  "react-native-safe-area-context": "~5.7.0",
101
101
  "@startsimpli/llm": "0.4.31",
102
- "@startsimpli/ui": "0.4.205",
102
+ "@startsimpli/ui": "0.4.207",
103
103
  "@startsimpli/ui-native": "0.1.15",
104
- "@startsimpli/auth": "0.4.60",
104
+ "@startsimpli/auth": "0.4.62",
105
105
  "@startsimpli/utils": "0.4.21"
106
106
  },
107
107
  "scripts": {
@@ -0,0 +1,47 @@
1
+ /**
2
+ * A briefing row is a source_document with NO body/summary (the to-do extractor
3
+ * must not re-extract from it) and its script in `briefing_text`. The Library
4
+ * must still SHOW that script, while Ask must never retrieve it: a briefing is a
5
+ * view of the to-dos, never a source of them.
6
+ */
7
+ import { describe, expect, it } from 'vitest';
8
+
9
+ import { toSourceDocument } from '../corpus/entities';
10
+ import { rankDocuments } from '../corpus/retrieval';
11
+
12
+ const SCOPE = { orgId: 'o' } as never;
13
+ const SAID = 'Good morning. You have three overdue items. First, send the quarterly deck to the board.';
14
+
15
+ const briefing = (data: Record<string, unknown> = {}) =>
16
+ toSourceDocument(
17
+ { id: 'b1', name: 'Briefing 2026-11-25', external_id: 'briefing:2026-11-25:u1', data: { source: 'briefing', briefing_text: SAID, ...data } } as never,
18
+ SCOPE,
19
+ );
20
+
21
+ describe('a briefing record in the Library', () => {
22
+ it('test_shows_what_was_said_as_a_section_not_an_empty_record', () => {
23
+ const doc = briefing();
24
+ expect(doc.sections.map((s) => s.text)).toContain(SAID);
25
+ expect(doc.sections[0].label).toBe('What was said');
26
+ });
27
+ it('test_still_has_no_body_or_summary_so_the_extractor_gets_nothing', () => {
28
+ const doc = briefing();
29
+ expect(doc.body).toBe('');
30
+ expect(doc.summary).toBeUndefined();
31
+ });
32
+ it('test_reads_the_camelCase_spelling_too', () => {
33
+ const doc = briefing({ briefing_text: undefined, briefingText: SAID });
34
+ expect(doc.sections.map((s) => s.text)).toContain(SAID);
35
+ });
36
+ });
37
+
38
+ describe('Ask retrieval', () => {
39
+ it('test_never_retrieves_a_briefing_even_when_the_question_matches_its_words', () => {
40
+ const other = toSourceDocument(
41
+ { id: 'n1', name: 'Board prep', data: { source: 'voice', title: 'Board prep', summary: 'Send the quarterly deck to the board.' } } as never,
42
+ SCOPE,
43
+ );
44
+ const ranked = rankDocuments([briefing(), other], 'quarterly deck board');
45
+ expect(ranked.map((r) => r.document.id)).toEqual(['n1']);
46
+ });
47
+ });
@@ -81,6 +81,8 @@ describe('ConnectClaudePage', () => {
81
81
  expect(note.textContent).toMatch(/shown once/i);
82
82
  // ...and specifically that losing the seat does not switch it off.
83
83
  expect(note.textContent).toMatch(/does not switch this one off/i);
84
+ // ...and that it can WRITE to the calendar, not only read (ENG-153).
85
+ expect(note.textContent).toMatch(/add, move\s+and delete events on your connected calendar/i);
84
86
  });
85
87
 
86
88
  it('shows WHOSE data the token reads, from the server, not the browser', async () => {
@@ -81,7 +81,8 @@ function makeApi(options: {
81
81
  const rows = options.rows ?? ROWS;
82
82
  return {
83
83
  async listCommitments(query: CommitmentQuery = {}): Promise<CorpusPage<Commitment>> {
84
- options.onQuery?.(query);
84
+ // The pinned-suggestions read (bd startsim-vrmx5) is not the list's query.
85
+ if (!(Array.isArray(query.status) && query.status.length === 1 && query.status[0] === 'suggested')) options.onQuery?.(query);
85
86
  // Deliberately returns EVERYTHING, like the tenant API does today: the
86
87
  // screen has to be correct against a server that ignores the filters.
87
88
  return {
@@ -641,7 +642,8 @@ describe('TrackerPage — 400+ open to-dos, paged by the server (bd startsim-768
641
642
  function pagedApi(onQuery: (q: CommitmentQuery) => void): CommitmentTrackerApi {
642
643
  return {
643
644
  async listCommitments(query: CommitmentQuery = {}) {
644
- onQuery(query);
645
+ // The pinned-suggestions read (bd startsim-vrmx5) is not the list's query.
646
+ if (!(Array.isArray(query.status) && query.status.length === 1 && query.status[0] === 'suggested')) onQuery(query);
645
647
  const size = Math.min(query.pageSize ?? 50, 200);
646
648
  const page = query.page ?? 1;
647
649
  const slice = MANY.slice((page - 1) * size, page * size);
@@ -676,3 +678,12 @@ describe('TrackerPage — a guessed project (bd startsim-tmrvi.22)', () => {
676
678
  expect(screen.getAllByText(/\(guessed\)/)).toHaveLength(1);
677
679
  });
678
680
  });
681
+
682
+ describe('TrackerPage with the scheduled pass (bd startsim-vrmx5)', () => {
683
+ it('shows no manual pull when the host turns it off, and says when notes are read', async () => {
684
+ const api = { listCommitments: async () => ({ count: 0, next: null, previous: null, results: [], appliedFilters: ['status'] }), startExtraction: async () => ({}), getExtractionRun: async () => null } as unknown as CommitmentTrackerApi;
685
+ render(<TrackerPage api={api} scope={SCOPE} manualPull={false} />);
686
+ expect(await screen.findByText(/new notes are read every half hour/)).toBeInTheDocument();
687
+ expect(screen.queryByRole('button', { name: /Pull from meetings/i })).not.toBeInTheDocument();
688
+ });
689
+ });
@@ -0,0 +1,160 @@
1
+ /**
2
+ * THE DECISION POLICY (bd startsim-vrmx5, Todo: ENG-151). One case per rule,
3
+ * plus the refusals that must win over every other rule.
4
+ */
5
+ import { describe, expect, it } from 'vitest';
6
+
7
+ import { decide, GRADUATION_MIN_LABELS, standingOf } from '../corpus/engine';
8
+ import type { DecisionLabel, ItemCandidate, ResolutionCandidate, RuleId } from '../corpus/engine';
9
+
10
+ const ME = 'sub-me';
11
+ const THEM = 'sub-them';
12
+ const ctx = { ownerSub: ME };
13
+
14
+ const item = (over: Partial<ItemCandidate> = {}): ItemCandidate => ({
15
+ kind: 'item', documentId: 'doc-1', documentOwnerSub: ME, documentSource: 'granola', quote: 'Send the deck (Quinn)',
16
+ extractor: 'rules', grounded: true, verified: true, owner: 'self', subtype: 'action', status: 'open',
17
+ participantCount: 3, match: null, ...over,
18
+ });
19
+
20
+ const resolution = (over: Partial<ResolutionCandidate> = {}): ResolutionCandidate => ({
21
+ kind: 'resolution', documentId: 'doc-2', documentOwnerSub: ME, documentSource: 'gmail', quote: 'deck is sent',
22
+ outcome: 'done', matches: [{ itemId: 'item-1', strength: 'anchored', itemOwnerSub: ME }], ...over,
23
+ });
24
+
25
+ const labels = (rule: RuleId, accepted: number, rejected: number, actor: DecisionLabel['actor'] = 'human'): DecisionLabel[] => [
26
+ ...Array.from({ length: accepted }, () => ({ rule, outcome: 'accepted' as const, actor })),
27
+ ...Array.from({ length: rejected }, () => ({ rule, outcome: 'rejected' as const, actor })),
28
+ ];
29
+
30
+ describe('refusals come first', () => {
31
+ it('never reads another owner’s source, whatever the evidence says', () => {
32
+ const d = decide(item({ documentOwnerSub: THEM }), ctx);
33
+ expect([d.rule, d.verb, d.mode]).toEqual(['X-OWNER', 'ignore', 'skip']);
34
+ });
35
+
36
+ it('treats a source with no owner as not the owner’s', () => {
37
+ expect(decide(item({ documentOwnerSub: null }), ctx).rule).toBe('X-OWNER');
38
+ });
39
+
40
+ it('refuses everything when the pass has no owner', () => {
41
+ expect(decide(item(), { ownerSub: '' }).rule).toBe('X-OWNER');
42
+ });
43
+
44
+ it('never reads Tandem’s own briefing back as new work', () => {
45
+ expect(decide(item({ documentSource: 'briefing' }), ctx).rule).toBe('X-SELF');
46
+ });
47
+
48
+ it('drops an ungrounded quote and an unverified model item', () => {
49
+ expect(decide(item({ grounded: false }), ctx).rule).toBe('X-UNGROUNDED');
50
+ expect(decide(item({ extractor: 'model', verified: false }), ctx).rule).toBe('X-UNVERIFIED');
51
+ });
52
+ });
53
+
54
+ describe('creating', () => {
55
+ it('acts on the note-taker’s own next-steps bullet owned by the owner', () => {
56
+ const d = decide(item(), ctx);
57
+ expect([d.rule, d.verb, d.mode]).toEqual(['C-VENDOR', 'create', 'act']);
58
+ expect(d.evidence).toEqual({ documentId: 'doc-1', quote: 'Send the deck (Quinn)' });
59
+ expect(d.reversible).toBe(true);
60
+ expect(d.confidence).toBeCloseTo(0.985);
61
+ });
62
+
63
+ it('only proposes a verified model item until the owner’s reviews graduate it', () => {
64
+ const d = decide(item({ extractor: 'model' }), ctx);
65
+ expect([d.rule, d.mode]).toEqual(['C-MODEL', 'propose']);
66
+ });
67
+
68
+ it('ignores someone else’s commitment in a group meeting', () => {
69
+ expect(decide(item({ owner: 'other', participantCount: 4 }), ctx).rule).toBe('X-OTHERS');
70
+ });
71
+
72
+ it('proposes "waiting on" when someone else owes the owner', () => {
73
+ expect(decide(item({ owner: 'other', participantCount: 1 }), ctx).rule).toBe('C-WAITING');
74
+ expect(decide(item({ owner: 'other', subtype: 'need', participantCount: 5 }), ctx).rule).toBe('C-WAITING');
75
+ expect(decide(item({ owner: 'other', status: 'blocked', participantCount: 5 }), ctx).rule).toBe('C-WAITING');
76
+ });
77
+
78
+ it('proposes an item nobody was named on', () => {
79
+ expect(decide(item({ owner: 'none' }), ctx)).toMatchObject({ rule: 'C-UNOWNED', mode: 'propose' });
80
+ });
81
+ });
82
+
83
+ describe('merging and linking', () => {
84
+ it('merges an exact restatement without asking', () => {
85
+ const d = decide(item({ extractor: 'model', match: { itemId: 'item-1', strength: 'exact', itemOwnerSub: ME } }), ctx);
86
+ expect(d).toMatchObject({ rule: 'L-EXACT', verb: 'merge', mode: 'act', targetId: 'item-1' });
87
+ });
88
+
89
+ it('proposes a near match and a related link', () => {
90
+ expect(decide(item({ match: { itemId: 'i', strength: 'anchored', itemOwnerSub: ME } }), ctx))
91
+ .toMatchObject({ rule: 'L-NEAR', verb: 'merge', mode: 'propose' });
92
+ expect(decide(item({ match: { itemId: 'i', strength: 'unanchored', itemOwnerSub: ME } }), ctx))
93
+ .toMatchObject({ rule: 'L-RELATED', verb: 'link', mode: 'propose' });
94
+ });
95
+
96
+ it('never merges onto another owner’s item: it is a new item of the owner’s own', () => {
97
+ const d = decide(item({ match: { itemId: 'theirs', strength: 'exact', itemOwnerSub: THEM } }), ctx);
98
+ expect(d.rule).toBe('C-VENDOR');
99
+ expect(d.targetId).toBeUndefined();
100
+ });
101
+ });
102
+
103
+ describe('updating', () => {
104
+ it('proposes closing an item a later source says is done', () => {
105
+ expect(decide(resolution(), ctx)).toMatchObject({ rule: 'U-RESOLVED', verb: 'update', mode: 'propose', targetId: 'item-1' });
106
+ });
107
+
108
+ it('says so when more than one item could fit', () => {
109
+ const d = decide(resolution({ matches: [
110
+ { itemId: 'a', strength: 'anchored', itemOwnerSub: ME }, { itemId: 'b', strength: 'unanchored', itemOwnerSub: ME },
111
+ ] }), ctx);
112
+ expect(d.reason).toMatch(/more than one/);
113
+ });
114
+
115
+ it('ignores a resolution that matches nothing of the owner’s', () => {
116
+ expect(decide(resolution({ matches: [] }), ctx).rule).toBe('X-NO-MATCH');
117
+ expect(decide(resolution({ matches: [{ itemId: 'x', strength: 'anchored', itemOwnerSub: THEM }] }), ctx).rule).toBe('X-NO-MATCH');
118
+ });
119
+
120
+ it('leaves a status or date the owner set by hand', () => {
121
+ expect(decide(resolution({ humanEdited: ['status'] }), ctx).rule).toBe('X-HUMAN');
122
+ expect(decide({
123
+ kind: 'date', documentId: 'd', documentOwnerSub: ME, documentSource: 'gmail', quote: 'by Friday',
124
+ itemId: 'item-1', dueAt: '2026-11-28', humanEdited: ['due_at'],
125
+ }, ctx).rule).toBe('X-HUMAN');
126
+ });
127
+
128
+ it('proposes a stated new date, and acts on a tracker state change', () => {
129
+ expect(decide({
130
+ kind: 'date', documentId: 'd', documentOwnerSub: ME, documentSource: 'gmail', quote: 'by Friday',
131
+ itemId: 'item-1', dueAt: '2026-11-28',
132
+ }, ctx)).toMatchObject({ rule: 'U-DATE', mode: 'propose' });
133
+ expect(decide({
134
+ kind: 'remote', documentId: 'linear:ENG-1', documentOwnerSub: ME, documentSource: 'linear', quote: '', itemId: 'item-1', field: 'status',
135
+ }, ctx)).toMatchObject({ rule: 'U-REMOTE', mode: 'act' });
136
+ });
137
+ });
138
+
139
+ describe('graduation', () => {
140
+ it(`acts once the owner accepted >= 90% of >= ${GRADUATION_MIN_LABELS} suggestions`, () => {
141
+ expect(decide(item({ extractor: 'model' }), ctx, labels('C-MODEL', 27, 3)).mode).toBe('act');
142
+ expect(decide(item({ extractor: 'model' }), ctx, labels('C-MODEL', 27, 3)).confidence).toBeCloseTo(0.9);
143
+ });
144
+
145
+ it('keeps proposing below the bar or with too few reviews', () => {
146
+ expect(decide(item({ extractor: 'model' }), ctx, labels('C-MODEL', 26, 4)).mode).toBe('propose');
147
+ expect(decide(item({ extractor: 'model' }), ctx, labels('C-MODEL', 29, 0)).mode).toBe('propose');
148
+ });
149
+
150
+ it('does not count automation as the owner agreeing', () => {
151
+ expect(standingOf('C-MODEL', labels('C-MODEL', 40, 0, 'automation')).mode).toBe('propose');
152
+ });
153
+
154
+ it('never lets an ignore rule act, and keeps the three safe rules acting', () => {
155
+ expect(standingOf('X-OTHERS', labels('X-OTHERS', 40, 0)).mode).toBe('skip');
156
+ expect(standingOf('C-VENDOR', []).mode).toBe('act');
157
+ expect(standingOf('U-REMOTE', []).mode).toBe('act');
158
+ expect(standingOf('L-EXACT', []).mode).toBe('act');
159
+ });
160
+ });
@@ -0,0 +1,145 @@
1
+ /**
2
+ * The decision policy inside extraction's write path (bd startsim-vrmx5 slice 2).
3
+ */
4
+ import { describe, expect, it } from 'vitest';
5
+
6
+ import { applyResolutions, commitmentIdentity } from '../corpus/commitments';
7
+ import { labelsFrom, readSuggestion, writeSuggestion } from '../corpus/engine/suggestion';
8
+ import { ownerRelationOf } from '../corpus/engine/apply';
9
+ import { extractCommitments } from '../corpus/extract';
10
+ import { createFixtureCorpusApi, createFixtureExtractor, FIXTURE_ORG, FIXTURE_TRACKED_DOCUMENTS } from '../corpus/fixtures';
11
+ import type { Commitment } from '../corpus/types';
12
+
13
+ const TANDEM = { orgId: FIXTURE_ORG };
14
+ const OWNER = 'usr_dana';
15
+
16
+ function harness() {
17
+ const corpus = createFixtureCorpusApi({ scope: TANDEM, documents: FIXTURE_TRACKED_DOCUMENTS });
18
+ const saved: Commitment[] = [];
19
+ (corpus as { listCommitments?: unknown }).listCommitments = async () => ({ count: 0, next: null, previous: null, results: [] });
20
+ (corpus as { saveCommitments?: unknown }).saveCommitments = async (rows: Commitment[]) => { saved.push(...rows); };
21
+ return { corpus, saved };
22
+ }
23
+
24
+ describe('extraction under the engine', () => {
25
+ it('acts on the owner’s next-steps bullets, suggests the rest, and drops other people’s', async () => {
26
+ const { corpus, saved } = harness();
27
+ const result = await extractCommitments(
28
+ { scope: TANDEM, engine: { ownerSub: OWNER, ownerNames: ['Rae'] } },
29
+ { corpus, extractor: createFixtureExtractor() },
30
+ );
31
+ expect(saved.length).toBeGreaterThan(0);
32
+ for (const row of saved) expect(row.suggestion).toBeDefined();
33
+ const acted = saved.filter((r) => r.status !== 'suggested');
34
+ const suggested = saved.filter((r) => r.status === 'suggested');
35
+ expect(acted.every((r) => r.suggestion!.rule === 'C-VENDOR' && r.ownerName === 'Rae')).toBe(true);
36
+ expect(acted.every((r) => r.ownerSub === OWNER)).toBe(true);
37
+ expect(suggested.every((r) => r.suggestion!.mode === 'propose')).toBe(true);
38
+ expect(saved.some((r) => r.ownerName === 'Ola')).toBe(false);
39
+ expect(result.engine).toMatchObject({ acted: acted.length, proposed: suggested.length });
40
+ expect(result.engine!.skipped['X-OTHERS']).toBeGreaterThan(0);
41
+ });
42
+
43
+ it('writes nothing from another owner’s documents', async () => {
44
+ const { corpus, saved } = harness();
45
+ await extractCommitments(
46
+ { scope: TANDEM, engine: { ownerSub: 'usr_someone_else', ownerNames: ['Rae'] } },
47
+ { corpus, extractor: createFixtureExtractor() },
48
+ );
49
+ expect(saved).toEqual([]);
50
+ });
51
+
52
+ it('leaves the old behaviour alone when the engine is not asked for', async () => {
53
+ const { corpus, saved } = harness();
54
+ await extractCommitments({ scope: TANDEM }, { corpus, extractor: createFixtureExtractor() });
55
+ expect(saved.length).toBeGreaterThan(0);
56
+ expect(saved.some((r) => r.suggestion)).toBe(false);
57
+ expect(saved.some((r) => r.status === 'suggested')).toBe(false);
58
+ });
59
+ });
60
+
61
+ describe('resolutions under the engine', () => {
62
+ it('keeps a "that is done" claim on the item instead of closing it', () => {
63
+ const doc = { ...FIXTURE_TRACKED_DOCUMENTS[0], id: 'later', occurredAt: '2026-12-01T00:00:00Z' };
64
+ const identity = commitmentIdentity({ title: 'Send the signed engagement letter', subject: '2040-01' });
65
+ const item = {
66
+ id: 'c1', externalId: 'commit:c1', dedupeKey: identity.dedupeKey, subtype: 'action', title: 'Send the signed engagement letter',
67
+ detail: '', status: 'open', subject: '2040-01', subjectKey: identity.subjectKey, actionKey: identity.actionKey,
68
+ mentions: [], firstSeenAt: '2026-11-01T00:00:00Z', lastSeenAt: null, extractorVersion: 'x', source: 'granola',
69
+ sourceLabel: 'Granola', scope: TANDEM,
70
+ } as unknown as Commitment;
71
+ const claim = { documentId: 'later', subject: '2040-01', statement: 'Sent the signed engagement letter', quote: 'q', outcome: 'done' as const };
72
+ expect(applyResolutions([item], [claim], { documents: [doc] }).commitments[0].status).toBe('done');
73
+ const proposed = applyResolutions([item], [claim], { documents: [doc], proposeOnly: true });
74
+ expect(proposed.commitments[0].status).toBe('open');
75
+ expect(proposed.needsReview).toHaveLength(1);
76
+ });
77
+ });
78
+
79
+ describe('the stored decision', () => {
80
+ it('round-trips and turns reviews into labels', () => {
81
+ const s = { rule: 'C-MODEL' as const, mode: 'propose' as const, confidence: 0.8, reason: 'r', documentId: 'd', quote: 'q', outcome: 'rejected' as const };
82
+ expect(readSuggestion(writeSuggestion(s))).toEqual(s);
83
+ expect(readSuggestion({ rule: 'NOT-A-RULE' })).toBeUndefined();
84
+ expect(labelsFrom([{ suggestion: s }, {}])).toEqual([{ rule: 'C-MODEL', outcome: 'rejected', actor: 'human' }]);
85
+ });
86
+
87
+ it('recognises the owner by id or by a name they go by', () => {
88
+ const scope = { ownerSub: 'me', ownerNames: ['Quinn'] };
89
+ expect(ownerRelationOf({ ownerSub: 'me' }, scope)).toBe('self');
90
+ expect(ownerRelationOf({ ownerName: 'Quinn Osha' }, scope)).toBe('self');
91
+ expect(ownerRelationOf({ ownerName: 'Jurga' }, scope)).toBe('other');
92
+ expect(ownerRelationOf({}, scope)).toBe('none');
93
+ });
94
+ });
95
+
96
+ describe('owner names', () => {
97
+ it('learns the names a person goes by from items already linked to them', async () => {
98
+ const { ownerNamesFrom } = await import('../corpus/engine/apply');
99
+ const items = [
100
+ { ownerName: 'Quinn', ownerSub: 'me' }, { ownerName: 'Quinn', ownerSub: 'me' }, { ownerName: 'Quinn Osha', ownerSubs: ['me'] },
101
+ { ownerName: 'Jurga', ownerSub: 'them' }, { ownerName: 'Quinn, Jurga', ownerSub: 'me' }, { ownerSub: 'me' },
102
+ ];
103
+ expect(ownerNamesFrom(items, 'me')).toEqual(['Quinn']); // 'Quinn Osha' is on one linked item only
104
+ });
105
+ });
106
+
107
+ describe('graduation in the live path', () => {
108
+ it('acts on a rule the owner has accepted >= 90% of >= 30 times, read from their own reviewed items', async () => {
109
+ const first = harness();
110
+ await extractCommitments({ scope: TANDEM, engine: { ownerSub: OWNER, ownerNames: ['Rae'] } }, { corpus: first.corpus, extractor: createFixtureExtractor() });
111
+ const proposed = first.saved.find((r) => r.status === 'suggested');
112
+ expect(proposed).toBeDefined();
113
+ const rule = proposed!.suggestion!.rule;
114
+
115
+ const reviewed = Array.from({ length: 30 }, (_, n) => ({
116
+ id: `r${n}`, externalId: `commit:r${n}`, dedupeKey: `r${n}`, subtype: 'action', title: `Reviewed ${n}`, detail: '',
117
+ status: 'open', subjectKey: '', actionKey: `reviewed.${n}`, mentions: [], firstSeenAt: null, lastSeenAt: null,
118
+ extractorVersion: 'x', source: 'granola', sourceLabel: 'Granola', scope: { ...TANDEM, ownerSub: OWNER },
119
+ suggestion: { rule, mode: 'propose', confidence: 0.8, reason: '', documentId: 'd', quote: 'q', outcome: 'accepted' },
120
+ })) as unknown as Commitment[];
121
+ const second = harness();
122
+ (second.corpus as { listCommitments?: unknown }).listCommitments = async () => ({ count: 30, next: null, previous: null, results: reviewed });
123
+ await extractCommitments({ scope: TANDEM, engine: { ownerSub: OWNER, ownerNames: ['Rae'] } }, { corpus: second.corpus, extractor: createFixtureExtractor() });
124
+ const same = second.saved.find((r) => r.externalId === proposed!.externalId);
125
+ expect(same?.status).not.toBe('suggested');
126
+ expect(same?.suggestion).toMatchObject({ rule, mode: 'act' });
127
+ });
128
+ });
129
+
130
+ describe('meeting size without resolved participants', () => {
131
+ it('reads the connector head count, so a one-to-one is a one-to-one', async () => {
132
+ const { applyPolicy } = await import('../corpus/engine/apply');
133
+ const doc = { ...FIXTURE_TRACKED_DOCUMENTS[0], participants: [], participantCount: 2, scope: { ...TANDEM, ownerSub: OWNER } };
134
+ const theirs = {
135
+ id: 'x', externalId: 'commit:x', dedupeKey: 'x', subtype: 'action', title: 'Send the positioning doc', detail: '', status: 'open',
136
+ subjectKey: '', actionKey: 'x', ownerName: 'Jurga', firstSeenAt: null, lastSeenAt: null, extractorVersion: 'x',
137
+ source: 'granola', sourceLabel: 'Granola', scope: TANDEM,
138
+ mentions: [{ documentId: doc.id, originKey: 'rules:x', occurredAt: null, quote: 'q', extractor: 'rules' }],
139
+ } as unknown as Commitment;
140
+ const oneToOne = applyPolicy([theirs], { scope: { ownerSub: OWNER, ownerNames: ['Rae'] }, documents: [doc] });
141
+ expect(oneToOne.kept[0]?.suggestion?.rule).toBe('C-WAITING');
142
+ const group = applyPolicy([theirs], { scope: { ownerSub: OWNER, ownerNames: ['Rae'] }, documents: [{ ...doc, participantCount: 6 }] });
143
+ expect(group.skipped['X-OTHERS']).toBe(1);
144
+ });
145
+ });
@@ -0,0 +1,126 @@
1
+ /**
2
+ * The dry run over stored evidence (bd startsim-vrmx5 slice 1): counts per rule,
3
+ * ids only, and never a word of anyone's notes in the formatted report.
4
+ */
5
+ import { describe, expect, it } from 'vitest';
6
+
7
+ import { commitmentIdentity } from '../corpus/commitments';
8
+ import { formatReplay, replayWindow } from '../corpus/engine';
9
+ import type { Commitment, CommitmentMention, SourceDocument } from '../corpus/types';
10
+
11
+ const ME = 'sub-me';
12
+ const THEM = 'sub-them';
13
+
14
+ const doc = (id: string, over: Partial<SourceDocument> = {}): SourceDocument => ({
15
+ id, title: `secret title ${id}`, body: 'secret body', sections: [], occurredAt: '2026-11-20T10:00:00Z',
16
+ source: 'granola', sourceLabel: 'Granola', sourceRef: id, participants: [], scope: { orgId: 'tandem', ownerSub: ME },
17
+ ...over,
18
+ });
19
+
20
+ const mention = (documentId: string, over: Partial<CommitmentMention> = {}): CommitmentMention => ({
21
+ documentId, originKey: `rules:${documentId}`, occurredAt: '2026-11-20T10:00:00Z', quote: 'secret quote', extractor: 'rules', ...over,
22
+ });
23
+
24
+ const item = (id: string, title: string, mentions: CommitmentMention[], over: Partial<Commitment> = {}): Commitment => {
25
+ const identity = commitmentIdentity({ title, subject: over.subject });
26
+ return {
27
+ id, externalId: `commit:${id}`, dedupeKey: identity.dedupeKey, subtype: 'action', title, detail: '',
28
+ status: 'open', subjectKey: identity.subjectKey, actionKey: identity.actionKey, mentions,
29
+ firstSeenAt: mentions[0]?.occurredAt ?? null, lastSeenAt: null, extractorVersion: 'rules+model@1',
30
+ source: 'granola', sourceLabel: 'Granola', scope: { orgId: 'tandem', ownerSub: ME }, ownerName: 'Quinn',
31
+ ...over,
32
+ } as Commitment;
33
+ };
34
+
35
+ describe('replayWindow', () => {
36
+ const documents = [
37
+ doc('d1'),
38
+ doc('d2', { occurredAt: '2026-11-21T10:00:00Z' }),
39
+ doc('theirs', { scope: { orgId: 'tandem', ownerSub: THEM } }),
40
+ doc('brief', { source: 'briefing' }),
41
+ doc('old', { occurredAt: '2026-10-01T10:00:00Z' }),
42
+ doc('quiet'),
43
+ ];
44
+ const items = [
45
+ item('a', 'Send the pricing deck', [mention('d1'), mention('d2', { originKey: 'rules:d1' })]),
46
+ item('b', 'Review the contract', [mention('d1', { extractor: 'model' })]),
47
+ item('c', 'Book the venue', [mention('d1')], { ownerName: 'Jurga' }),
48
+ item('d', 'Draft the memo', [mention('theirs')], { scope: { orgId: 'tandem', ownerSub: THEM } }),
49
+ item('e', 'Pay the invoice', [mention('d1')], { status: 'done', resolvedBy: 'd2', statusReason: 'secret reason' }),
50
+ ];
51
+ const report = replayWindow({
52
+ ownerSub: ME, ownerNames: ['Quinn'], documents, items, since: '2026-11-10',
53
+ participantCounts: new Map([['d1', 4], ['d2', 2]]),
54
+ });
55
+ const count = (rule: string) => report.byRule.filter((g) => g.rule === rule).reduce((n, g) => n + g.count, 0);
56
+
57
+ it('reads only the owner’s documents in the window, and skips Tandem’s own and other owners’', () => {
58
+ expect(report.documentsInWindow).toBe(5);
59
+ expect(report.documentsRead).toBe(3);
60
+ expect(count('X-OWNER')).toBe(1);
61
+ expect(count('X-SELF')).toBe(1);
62
+ expect(report.documentsWithNothing).toBe(1);
63
+ });
64
+
65
+ it('decides each stored mention and resolution by rule', () => {
66
+ expect(count('C-VENDOR')).toBe(2); // a's first mention, e
67
+ expect(count('L-EXACT')).toBe(1); // a's second mention, same origin key
68
+ expect(count('C-MODEL')).toBe(1); // b
69
+ expect(count('X-OTHERS')).toBe(1); // c: Jurga's, group meeting
70
+ expect(count('U-RESOLVED')).toBe(1); // e closed by d2
71
+ expect(report.byMode.act + report.byMode.propose + report.byMode.skip).toBe(report.rows.length);
72
+ });
73
+
74
+ it('never puts source text in the formatted report', () => {
75
+ const text = formatReplay(report);
76
+ expect(text).not.toMatch(/secret|Send the|pricing|Jurga/);
77
+ expect(text).toMatch(/C-VENDOR\s+act\s+2/);
78
+ });
79
+ });
80
+
81
+ describe('dryExtract', () => {
82
+ it('runs real extraction over the owner’s window without writing, and the replay judges what it would add', async () => {
83
+ const { dryExtract } = await import('../corpus/engine');
84
+ const { createFixtureExtractor, FIXTURE_TRACKED_DOCUMENTS } = await import('../corpus/fixtures');
85
+ const mine = FIXTURE_TRACKED_DOCUMENTS.map((d) => ({ ...d, scope: { orgId: 'tandem', ownerSub: ME } }));
86
+ const theirs = { ...FIXTURE_TRACKED_DOCUMENTS[0], id: 'theirs', scope: { orgId: 'tandem', ownerSub: THEM } };
87
+ const briefing = { ...FIXTURE_TRACKED_DOCUMENTS[0], id: 'brief', source: 'briefing', scope: { orgId: 'tandem', ownerSub: ME } };
88
+ const result = await dryExtract({
89
+ ownerSub: ME, orgId: 'tandem', documents: [...mine, theirs, briefing], existing: [],
90
+ extractor: createFixtureExtractor(),
91
+ });
92
+ expect(result.documentsProcessed).toBe(mine.length);
93
+ expect(result.rows.length).toBeGreaterThan(0);
94
+ expect(result.rows.every((row) => row.scope.ownerSub === ME)).toBe(true);
95
+ const touched = new Set(result.rows.flatMap((row) => row.mentions.map((m) => m.documentId)));
96
+ expect(touched.has('theirs') || touched.has('brief')).toBe(false);
97
+
98
+ const report = replayWindow({ ownerSub: ME, ownerNames: [], documents: mine, items: result.rows, since: '2000-01-01' });
99
+ expect(report.rows.filter((r) => r.candidate === 'item').length).toBeGreaterThan(0);
100
+ });
101
+ });
102
+
103
+ describe('replay by source', () => {
104
+ it('splits decisions per source so dictated notes and meetings are not pooled', () => {
105
+ const documents = [doc('m1'), doc('v1', { source: 'voice' })];
106
+ const items = [
107
+ item('a', 'Send the pricing deck', [mention('m1')]),
108
+ item('b', 'Call the bank', [mention('v1', { extractor: 'model' })]),
109
+ ];
110
+ const report = replayWindow({ ownerSub: ME, ownerNames: ['Quinn'], documents, items, since: '2026-11-10' });
111
+ expect(report.bySource).toEqual(expect.arrayContaining([
112
+ { source: 'granola', rule: 'C-VENDOR', mode: 'act', count: 1 },
113
+ { source: 'voice', rule: 'C-MODEL', mode: 'propose', count: 1 },
114
+ ]));
115
+ });
116
+ });
117
+
118
+ describe('formatReplay ids', () => {
119
+ it('shows the distinguishing part of a new row id, not its prefix', () => {
120
+ const report = replayWindow({
121
+ ownerSub: ME, ownerNames: ['Quinn'], documents: [doc('m1')], since: '2026-11-10',
122
+ items: [item('commit:abcdef1234', 'Send the pricing deck', [mention('m1')])],
123
+ });
124
+ expect(formatReplay(report)).toMatch(/abcdef12/);
125
+ });
126
+ });
@@ -0,0 +1,82 @@
1
+ /**
2
+ * The scheduled pass (bd startsim-vrmx5 slice 3): every run after the first reads
3
+ * only what arrived since the last finished one, and skips sources that already
4
+ * made their items when they were captured (voice notes, conversations).
5
+ */
6
+ import { describe, expect, it, vi } from 'vitest';
7
+
8
+ import { extractCommitments } from '../corpus/extract';
9
+ import { driveExtractionRun, startExtractionRun } from '../corpus/runs';
10
+ import {
11
+ createFixtureCorpusApi, createFixtureExtractor, createFixtureRunStore, FIXTURE_ORG, FIXTURE_TRACKED_DOCUMENTS,
12
+ } from '../corpus/fixtures';
13
+ import type { Commitment, CommitmentApi, CorpusApi } from '../corpus/types';
14
+
15
+ const TANDEM = { orgId: FIXTURE_ORG };
16
+ const docs = FIXTURE_TRACKED_DOCUMENTS.map((doc, n) => ({ ...doc, ingestedAt: `2026-11-2${n}T00:00:00Z` }));
17
+
18
+ function corpusOf(documents = docs) {
19
+ const corpus = createFixtureCorpusApi({ scope: TANDEM, documents }) as CorpusApi & CommitmentApi;
20
+ const tracked = new Map<string, Commitment>();
21
+ corpus.listCommitments = async () => ({ count: tracked.size, next: null, previous: null, results: [...tracked.values()] });
22
+ corpus.saveCommitments = async (items: Commitment[]) => { for (const item of items) tracked.set(item.externalId, item); };
23
+ return corpus;
24
+ }
25
+
26
+ describe('extraction narrowed for a scheduled pass', () => {
27
+ it('reads only documents that arrived after `since`', async () => {
28
+ const extractor = createFixtureExtractor();
29
+ const spy = vi.spyOn(extractor, 'extract');
30
+ const result = await extractCommitments({ scope: TANDEM, since: '2026-11-20T12:00:00Z' }, { corpus: corpusOf(), extractor });
31
+ const sent = spy.mock.calls.flatMap((call) => call[0].documents.map((d) => d.id));
32
+ expect(result.totalDocuments).toBe(docs.length - 1);
33
+ expect(sent).not.toContain(docs[0].id);
34
+ });
35
+
36
+ it('skips the sources it is told to', async () => {
37
+ const voice = { ...docs[0], id: 'voice-1', source: 'voice' };
38
+ const result = await extractCommitments({ scope: TANDEM, skipSources: ['voice'] }, { corpus: corpusOf([voice, docs[1]]), extractor: createFixtureExtractor() });
39
+ expect(result.documentIds).not.toContain('voice-1');
40
+ expect(result.totalDocuments).toBe(1);
41
+ });
42
+ });
43
+
44
+ describe('an incremental run', () => {
45
+ it('starts the next run from when the last finished one started, and carries the skipped sources', async () => {
46
+ const corpus = corpusOf();
47
+ const store = createFixtureRunStore();
48
+ const extractor = createFixtureExtractor();
49
+ let clock = Date.parse('2026-11-23T00:00:00Z');
50
+ const now = () => clock;
51
+
52
+ const first = await startExtractionRun({ scope: TANDEM, incremental: true, skipSources: ['voice'] }, { corpus, extractor, runs: store }, { now });
53
+ expect(first.since ?? null).toBeNull();
54
+ expect(first.skipSources).toEqual(['voice']);
55
+ const done = await driveExtractionRun(first, { corpus, extractor, runs: store }, { documentsPerSlice: 5, now });
56
+ expect(done.status).toBe('succeeded');
57
+
58
+ clock = Date.parse('2026-11-24T00:00:00Z');
59
+ const second = await startExtractionRun({ scope: TANDEM, incremental: true, skipSources: ['voice'] }, { corpus, extractor, runs: store }, { now });
60
+ expect(second.since).toBe(first.startedAt);
61
+ const after = await driveExtractionRun(second, { corpus, extractor, runs: store }, { documentsPerSlice: 5, now });
62
+ expect(after.totals.documentsProcessed).toBe(0);
63
+ });
64
+
65
+ it('a manual run still sweeps everything', async () => {
66
+ const corpus = corpusOf();
67
+ const store = createFixtureRunStore();
68
+ const extractor = createFixtureExtractor();
69
+ const first = await startExtractionRun({ scope: TANDEM }, { corpus, extractor, runs: store });
70
+ await driveExtractionRun(first, { corpus, extractor, runs: store }, { documentsPerSlice: 5 });
71
+ const second = await startExtractionRun({ scope: TANDEM }, { corpus, extractor, runs: store });
72
+ expect(second.since ?? null).toBeNull();
73
+ });
74
+ });
75
+
76
+ describe('the run record holds ids, never words from anyone\'s notes', () => {
77
+ it('keeps the item and document of a "needs review" claim and drops its quote', async () => {
78
+ const { reviewRefs } = await import('../corpus/runs');
79
+ expect(reviewRefs([{ commitmentId: 'commit:a', documentId: 'd1', quote: 'private words' }]))
80
+ .toEqual([{ commitmentId: 'commit:a', documentId: 'd1' }]);
81
+ });
82
+ });