@startsimpli/integrations 0.2.158 → 0.2.162

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 (43) hide show
  1. package/package.json +6 -6
  2. package/src/__tests__/briefing-weekly.test.ts +80 -0
  3. package/src/__tests__/corpus-ask-items.test.ts +108 -0
  4. package/src/__tests__/corpus-planning.test.tsx +31 -0
  5. package/src/__tests__/home-brief.test.tsx +10 -0
  6. package/src/__tests__/home-needs-your-call.test.tsx +68 -0
  7. package/src/__tests__/measure/notes.ts +28 -0
  8. package/src/__tests__/measure/voice-notes.measure.test.ts +51 -0
  9. package/src/__tests__/needs-your-call.test.tsx +151 -0
  10. package/src/__tests__/question-evidence.test.ts +82 -0
  11. package/src/__tests__/question-inbox.test.ts +51 -0
  12. package/src/__tests__/question-voice.test.ts +18 -0
  13. package/src/components/index.ts +1 -0
  14. package/src/components/pages/AskPage.tsx +12 -2
  15. package/src/components/pages/PlanningPage.tsx +14 -4
  16. package/src/components/pages/home/BriefCard.tsx +31 -12
  17. package/src/components/pages/home/CompactItemRow.tsx +12 -2
  18. package/src/components/pages/home/DueAcrossProjects.tsx +4 -2
  19. package/src/components/pages/home/HomeBriefPage.tsx +32 -3
  20. package/src/components/pages/questions/NeedsYourCall.tsx +128 -0
  21. package/src/components/pages/questions/QuestionRow.tsx +78 -0
  22. package/src/components/pages/questions/index.ts +3 -0
  23. package/src/components/pages/questions/types.ts +36 -0
  24. package/src/corpus/ask-items-intent.ts +75 -0
  25. package/src/corpus/ask-items.ts +100 -0
  26. package/src/corpus/ask.ts +48 -5
  27. package/src/corpus/briefing/generate-weekly.ts +89 -0
  28. package/src/corpus/briefing/index.ts +5 -1
  29. package/src/corpus/briefing/respond.ts +11 -3
  30. package/src/corpus/briefing/types.ts +2 -0
  31. package/src/corpus/briefing/weekly.ts +155 -0
  32. package/src/corpus/index.ts +3 -0
  33. package/src/corpus/llm.ts +3 -2
  34. package/src/corpus/questions/evidence.ts +65 -0
  35. package/src/corpus/questions/inbox.ts +108 -0
  36. package/src/corpus/questions/index.ts +6 -1
  37. package/src/corpus/questions/items.ts +21 -0
  38. package/src/corpus/questions/learn.ts +16 -0
  39. package/src/corpus/questions/sync.ts +7 -3
  40. package/src/corpus/questions/types.ts +5 -1
  41. package/src/corpus/questions/voice.ts +23 -4
  42. package/src/corpus/types.ts +4 -0
  43. package/src/corpus/voice.ts +5 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/integrations",
3
- "version": "0.2.158",
3
+ "version": "0.2.162",
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,9 +50,9 @@
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.180",
54
- "@startsimpli/utils": "^0.4.18",
55
- "@startsimpli/auth": "^0.4.51"
53
+ "@startsimpli/ui": "^0.4.181",
54
+ "@startsimpli/auth": "^0.4.52",
55
+ "@startsimpli/utils": "^0.4.18"
56
56
  },
57
57
  "peerDependenciesMeta": {
58
58
  "react": {
@@ -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.180",
102
+ "@startsimpli/ui": "0.4.181",
103
103
  "@startsimpli/ui-native": "0.1.14",
104
- "@startsimpli/auth": "0.4.51",
104
+ "@startsimpli/auth": "0.4.52",
105
105
  "@startsimpli/utils": "0.4.18"
106
106
  },
107
107
  "scripts": {
@@ -0,0 +1,80 @@
1
+ /** The weekly summary (bd startsim-tmrvi): pure composer, deterministic script, owner-only. */
2
+ import { describe, expect, it } from 'vitest';
3
+
4
+ import { composeWeekly, weeklyScript } from '../corpus/briefing/weekly';
5
+ import { generateWeekly } from '../corpus/briefing/generate-weekly';
6
+ import type { BriefingItem } from '../corpus/briefing/types';
7
+ import type { BriefingRecord, BriefingStore } from '../corpus/briefing/store';
8
+
9
+ const NOW = Date.parse('2026-11-11T15:00:00Z'); // Wednesday
10
+ const it_ = (id: string, over: Partial<BriefingItem>): BriefingItem => ({ id, title: `Thing ${id}`, status: 'open', ownerSub: 'q', ...over });
11
+ const ITEMS: BriefingItem[] = [
12
+ it_('d1', { status: 'done', resolvedAt: '2026-11-09T10:00:00Z' }),
13
+ it_('d2', { status: 'done', resolvedAt: '2026-10-01T10:00:00Z' }),
14
+ it_('d3', { status: 'done' }),
15
+ it_('s1', { dueAt: '2026-11-06' }),
16
+ it_('s2', { status: 'blocked' }),
17
+ it_('u1', { dueAt: '2026-11-13', focusName: 'Marketing' }),
18
+ it_('u2', { dueAt: '2026-11-30' }),
19
+ it_('x1', { dueAt: '2026-11-06', ownerSub: 'someone-else' }),
20
+ it_('x2', { dueAt: '2026-11-06', status: 'dropped' }),
21
+ ];
22
+
23
+ describe('composeWeekly', () => {
24
+ const w = composeWeekly(ITEMS, { ownerSub: 'q', now: NOW });
25
+ it('buckets by state and date, for the owner only', () => {
26
+ expect(w.done.map((e) => e.id)).toEqual(['d1']);
27
+ expect(w.slipping.map((e) => e.id)).toEqual(['s1', 's2']);
28
+ expect(w.upcoming.map((e) => e.id)).toEqual(['u1']);
29
+ expect(w.empty).toBe(false);
30
+ });
31
+ it('a done item with no finish time is not counted', () => {
32
+ expect(w.counts.done).toBe(1);
33
+ });
34
+ });
35
+
36
+ describe('weeklyScript', () => {
37
+ it('speaks all three sections and never leaks a numeric date', () => {
38
+ const text = weeklyScript(composeWeekly(ITEMS, { ownerSub: 'q', now: NOW }), { now: NOW, name: 'Quinn' }).text;
39
+ expect(text).toContain('Good afternoon, Quinn');
40
+ expect(text).toMatch(/finished one item/);
41
+ expect(text).toMatch(/Two items are slipping/);
42
+ expect(text).toMatch(/Coming up/);
43
+ expect(text).not.toMatch(/\d{4}-\d{2}-\d{2}/);
44
+ });
45
+ it('says so when the week is empty', () => {
46
+ const text = weeklyScript(composeWeekly([], { ownerSub: 'q', now: NOW }), { now: NOW }).text;
47
+ expect(text).toMatch(/Nothing was finished/);
48
+ });
49
+ });
50
+
51
+ describe('generateWeekly', () => {
52
+ function deps(saved: BriefingRecord[]) {
53
+ const store: BriefingStore = {
54
+ async find(id) { return saved.find((r) => r.externalId === id) ?? null; },
55
+ async get() { return null; },
56
+ async save(draft) { const r = { ...draft, id: `row${saved.length}` } as BriefingRecord; saved.push(r); return r; },
57
+ };
58
+ let speech = 0;
59
+ return {
60
+ speech: () => speech,
61
+ d: {
62
+ http: { get: async () => ({}), post: async () => ({}) } as never,
63
+ orgId: 'o', ownerSub: 'q', loadItems: async () => ITEMS, scriptLlm: null, store, now: () => NOW,
64
+ synthesize: async () => { speech += 1; return { audio: new Uint8Array([1]), mimeType: 'audio/mpeg', model: 'm', provider: 'p', usage: {} }; },
65
+ audio: { put: async () => 'ref', url: async () => 'http://audio' },
66
+ },
67
+ };
68
+ }
69
+ it('keeps one row, and a repeat tap does not synthesize again', async () => {
70
+ const saved: BriefingRecord[] = [];
71
+ const { d, speech } = deps(saved);
72
+ const first = await generateWeekly(d);
73
+ const second = await generateWeekly(d);
74
+ expect(first.cached).toBe(false);
75
+ expect(second.cached).toBe(true);
76
+ expect(saved).toHaveLength(1);
77
+ expect(speech()).toBe(1);
78
+ expect(saved[0].externalId).toBe('weekly:2026-11-11:q');
79
+ });
80
+ });
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Ask over tracked items (bd startsim-tmrvi): dates and states are decided in
3
+ * code, the answer must cite the item records, and an item question with nothing
4
+ * matching must say so instead of asking a model.
5
+ */
6
+ import { describe, expect, it } from 'vitest';
7
+
8
+ import { askCorpus } from '../corpus/ask';
9
+ import { itemIntent } from '../corpus/ask-items-intent';
10
+ import { selectItems } from '../corpus/ask-items';
11
+ import { createFixtureCorpusApi, FIXTURE_ORG } from '../corpus/fixtures';
12
+ import type { AnswerDraft, AnswerRequest, Commitment, CorpusLlm } from '../corpus/types';
13
+
14
+ const SCOPE = { orgId: FIXTURE_ORG };
15
+ // Wednesday 2026-11-11, noon UTC.
16
+ const NOW = Date.parse('2026-11-11T12:00:00Z');
17
+
18
+ function item(id: string, over: Partial<Commitment>): Commitment {
19
+ return {
20
+ id, externalId: `commit:${id}`, dedupeKey: id, subtype: 'task', title: `Item ${id}`, detail: '', status: 'open',
21
+ subjectKey: '', actionKey: '', mentions: [], firstSeenAt: '2026-10-01T00:00:00Z', lastSeenAt: null,
22
+ extractorVersion: 'x', source: 'voice', sourceLabel: 'Voice', scope: SCOPE, ownerSub: 'me', ...over,
23
+ } as Commitment;
24
+ }
25
+ const ITEMS = [
26
+ item('a', { title: 'Send the Acme deck', dueAt: '2026-11-13', ownerName: 'Quinn' }),
27
+ item('b', { title: 'Fix login bug', dueAt: '2026-11-05', status: 'in_progress', sync: { state: 'synced', key: 'TAN-7', stateName: 'In Progress' } }),
28
+ item('c', { title: 'Old finished thing', dueAt: '2026-11-05', status: 'done' }),
29
+ item('d', { title: 'Someone elses', dueAt: '2026-11-13', ownerSub: 'other' }),
30
+ item('e', { title: 'Next week thing', dueAt: '2026-11-17' }),
31
+ ];
32
+ const commitments = { listCommitments: async () => ({ count: ITEMS.length, next: null, previous: null, results: ITEMS }) };
33
+
34
+ function llmCiting(ids: string[], calls: AnswerRequest[] = []): CorpusLlm {
35
+ return {
36
+ describe: () => ({ provider: 'scripted', model: 's', live: false }),
37
+ async answer(input): Promise<AnswerDraft> {
38
+ calls.push(input);
39
+ return { answer: 'ok', citations: ids.map((documentId) => ({ documentId })) };
40
+ },
41
+ };
42
+ }
43
+
44
+ describe('itemIntent', () => {
45
+ it('is null for a question that is not about items', () => {
46
+ expect(itemIntent('what did Acme say about pricing', NOW)).toBeNull();
47
+ });
48
+ it('reads Friday as the coming Friday', () => {
49
+ const i = itemIntent('what is due Friday', NOW)!;
50
+ expect([i.focus, i.from, i.to]).toEqual(['due', '2026-11-13', '2026-11-13']);
51
+ });
52
+ it('reads this week as Monday to Sunday', () => {
53
+ const i = itemIntent('what did I commit to this week?', NOW)!;
54
+ expect([i.focus, i.from, i.to, i.mine]).toEqual(['committed', '2026-11-09', '2026-11-15', true]);
55
+ });
56
+ it('uses the reader zone for today', () => {
57
+ expect(itemIntent('what is overdue', Date.parse('2026-11-12T02:00:00Z'), 'America/New_York')!.today).toBe('2026-11-11');
58
+ });
59
+ });
60
+
61
+ describe('selectItems', () => {
62
+ const ctx = { now: NOW, ownerSub: 'me' };
63
+ it('slipping = unfinished and past due, never done ones', () => {
64
+ const ids = selectItems(ITEMS, itemIntent('what is slipping', NOW)!, ctx).map((i) => i.id);
65
+ expect(ids).toEqual(['b']);
66
+ });
67
+ it('due Friday, mine only when asked for mine', () => {
68
+ expect(selectItems(ITEMS, itemIntent('what is due Friday', NOW)!, ctx).map((i) => i.id)).toEqual(['a', 'd']);
69
+ expect(selectItems(ITEMS, itemIntent('what do I have due Friday', NOW)!, ctx).map((i) => i.id)).toEqual(['a']);
70
+ });
71
+ });
72
+
73
+ describe('askCorpus over items', () => {
74
+ const corpus = createFixtureCorpusApi({ scope: SCOPE });
75
+ it('puts the matching items first, cites them by item: id, and sends today', async () => {
76
+ const calls: AnswerRequest[] = [];
77
+ const result = await askCorpus(
78
+ { question: 'what is slipping?', mode: 'ask', scope: SCOPE },
79
+ { corpus, commitments, llm: llmCiting(['item:commit:b'], calls) },
80
+ { now: NOW, ownerSub: 'me' },
81
+ );
82
+ expect(calls).toHaveLength(1);
83
+ expect(calls[0].documents[0].id).toBe('item:commit:b');
84
+ expect(calls[0].documents[0].text).toContain('Linear: TAN-7 — In Progress');
85
+ expect(calls[0].today).toBe('2026-11-11');
86
+ expect(result.status).toBe('answered');
87
+ expect(result.citations[0].document.subtype).toBe('tracked_item');
88
+ });
89
+ it('does not touch the model when nothing matches and no documents do', async () => {
90
+ const calls: AnswerRequest[] = [];
91
+ const result = await askCorpus(
92
+ { question: 'what is due zzzqq tomorrow', mode: 'ask', scope: SCOPE },
93
+ { corpus, commitments, llm: llmCiting([], calls) },
94
+ { now: NOW, ownerSub: 'me' },
95
+ );
96
+ expect(result.status).toBe('no_evidence');
97
+ expect(calls).toHaveLength(0);
98
+ });
99
+ it('a non-item question never reads commitments', async () => {
100
+ let reads = 0;
101
+ await askCorpus(
102
+ { question: 'Acme renewal rate and seats', mode: 'ask', scope: SCOPE },
103
+ { corpus, commitments: { listCommitments: async () => { reads += 1; return { count: 0, next: null, previous: null, results: [] }; } }, llm: llmCiting([]) },
104
+ { now: NOW },
105
+ );
106
+ expect(reads).toBe(0);
107
+ });
108
+ });
@@ -477,6 +477,37 @@ describe('PlanningPage', () => {
477
477
  await waitFor(() => expect(screen.getByText('Nothing filed under this yet')).toBeTruthy());
478
478
  });
479
479
 
480
+ it('lists in-progress items under a focus, not only open ones', async () => {
481
+ render(
482
+ <PlanningPage
483
+ api={fakeApi({
484
+ focuses: [FOCUS],
485
+ items: [commitment({ externalId: 'commit:wip', title: 'Draft the term sheet', status: 'in_progress' })],
486
+ })}
487
+ scope={SCOPE}
488
+ now={NOW}
489
+ />,
490
+ );
491
+ await userEvent.click(await screen.findByRole('button', { name: /Close the Series A/ }));
492
+ expect(await screen.findByText('Draft the term sheet')).toBeTruthy();
493
+ });
494
+
495
+ it('opens a focus whose work is all finished on its closed items, asking for done and dropped', async () => {
496
+ const queries: Array<{ status?: unknown }> = [];
497
+ const done = commitment({ externalId: 'commit:old', title: 'Ship the pilot', status: 'done' });
498
+ const api = fakeApi({ focuses: [FOCUS], onList: (q) => queries.push(q as { status?: unknown }) });
499
+ api.listCommitments = async (query) => {
500
+ queries.push(query as { status?: unknown });
501
+ const wanted = Array.isArray(query.status) ? query.status : [query.status];
502
+ const results = wanted.includes('done') ? [done] : [];
503
+ return { count: results.length, next: null, previous: null, results, appliedFilters: ['status'] };
504
+ };
505
+ render(<PlanningPage api={api} scope={SCOPE} now={NOW} />);
506
+ await userEvent.click(await screen.findByRole('button', { name: /Close the Series A/ }));
507
+ expect(await screen.findByText('Ship the pilot')).toBeTruthy();
508
+ expect(queries.some((q) => Array.isArray(q.status) && q.status.includes('dropped'))).toBe(true);
509
+ });
510
+
480
511
  it('reports done over total from counts', async () => {
481
512
  render(
482
513
  <PlanningPage
@@ -50,6 +50,16 @@ describe('HomeBriefPage', () => {
50
50
  expect(fetch.mock.calls[0]).toHaveLength(0);
51
51
  });
52
52
 
53
+ it('shows the weekly summary only when asked, and never loads it on mount', async () => {
54
+ const weekly = vi.fn(async () => ({ text: 'Here is your week. You finished two items.', audioUrl: null, audioReason: 'No audio.' }));
55
+ render(<HomeBriefPage brief={{ fetch: async () => RESULT }} weekly={{ fetch: weekly }} corpus={corpus()} now={NOW} timeZone="UTC" />);
56
+ await screen.findByTestId('brief-text');
57
+ expect(weekly).not.toHaveBeenCalled();
58
+ await userEvent.click(screen.getByRole('button', { name: 'Show your week' }));
59
+ expect(await screen.findByText('Here is your week. You finished two items.')).toBeInTheDocument();
60
+ expect(weekly).toHaveBeenCalledTimes(1);
61
+ });
62
+
53
63
  it('groups what is due with the project as a chip', async () => {
54
64
  render(
55
65
  <HomeBriefPage
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Home with "Needs your call" (bd startsim-tmrvi.7): an answer shows on the to-do it was about
3
+ * straight away, a guessed date reads quietly, and a failed save puts everything back.
4
+ */
5
+ import * as React from 'react';
6
+ import { render, screen, waitFor, within } from '@testing-library/react';
7
+ import userEvent from '@testing-library/user-event';
8
+ import { describe, expect, it, vi } from 'vitest';
9
+
10
+ import { HomeBriefPage } from '../components/pages/home';
11
+ import type { NeedsYourCallApi } from '../components/pages/questions';
12
+ import type { BriefingResult } from '../corpus/briefing';
13
+ import type { OpenQuestion } from '../corpus/questions';
14
+ import type { Commitment, CommitmentApi, CorpusApi } from '../corpus/types';
15
+
16
+ const NOW = Date.parse('2026-11-06T17:00:00Z');
17
+ const RESULT = { briefingId: 'b1', text: 'Good morning.', audioUrl: null, items: [], remaining: 0, context: { itemIds: [], localDate: '2026-11-06', timeZone: 'UTC', offsets: [] }, scriptSource: 'template', cached: true, ms: 1 } as unknown as BriefingResult;
18
+
19
+ function item(id: string, over: Partial<Commitment> = {}): Commitment {
20
+ return {
21
+ id, externalId: `commit:${id}`, dedupeKey: id, subtype: 'action', title: id, detail: '', status: 'open', subjectKey: '', actionKey: '',
22
+ mentions: [], firstSeenAt: null, lastSeenAt: null, extractorVersion: 't', source: 'granola', sourceLabel: 'G', scope: { orgId: 'o' }, ...over,
23
+ } as Commitment;
24
+ }
25
+ const corpus = (): CorpusApi & CommitmentApi => ({
26
+ async listCommitments() { return { count: 1, next: null, previous: null, results: [item('Send the term sheet', { dueAt: '2026-11-13' })] }; },
27
+ async listDocuments() { return { count: 0, next: null, previous: null, results: [] }; },
28
+ }) as unknown as CorpusApi & CommitmentApi;
29
+
30
+ const QUESTION: OpenQuestion = {
31
+ id: 'q1', itemId: 'Send the term sheet', kind: 'due_date', question: 'Is next Friday right?', status: 'open', score: 80,
32
+ assumed: { value: '2026-11-13', confidence: 0.4, reason: '' }, candidates: [{ value: '2026-11-09', confidence: 0.3, reason: '' }],
33
+ ownerSub: 'u1', createdAt: '', updatedAt: '',
34
+ };
35
+ const questions = (answer: NeedsYourCallApi['answer']): NeedsYourCallApi => ({ list: async () => [QUESTION], answer, skip: async () => undefined });
36
+ const page = (api: NeedsYourCallApi) => <HomeBriefPage brief={{ fetch: async () => RESULT }} corpus={corpus()} now={NOW} timeZone="UTC" questions={api} />;
37
+
38
+ describe('Home: Needs your call', () => {
39
+ it('marks a guessed date lightly on its to-do', async () => {
40
+ render(page(questions(async () => undefined)));
41
+ const row = await screen.findByTestId('item-row');
42
+ await waitFor(() => expect(within(row).getByText('~in 7d')).toHaveAttribute('data-guess', 'true'));
43
+ });
44
+
45
+ it('moves the to-do to the answered day at once, and the guess mark goes', async () => {
46
+ render(page(questions(async () => undefined)));
47
+ await screen.findByText('Is next Friday right?');
48
+ await userEvent.click(screen.getByRole('button', { name: /^Mon, Nov 9$/ }));
49
+ const row = await screen.findByTestId('item-row');
50
+ expect(within(row).getByText('in 3d')).toBeInTheDocument();
51
+ expect(row.querySelector('[data-guess]')).toBeNull();
52
+ });
53
+
54
+ it('puts the date back when the save fails', async () => {
55
+ render(page(questions(async () => { throw new Error('boom'); })));
56
+ await screen.findByText('Is next Friday right?');
57
+ await userEvent.click(screen.getByRole('button', { name: /^Mon, Nov 9$/ }));
58
+ expect(await screen.findByRole('alert')).toBeInTheDocument();
59
+ const row = screen.getByTestId('item-row');
60
+ expect(within(row).getByText('~in 7d')).toBeInTheDocument();
61
+ });
62
+
63
+ it('shows no section without a questions api', async () => {
64
+ render(<HomeBriefPage brief={{ fetch: async () => RESULT }} corpus={corpus()} now={NOW} timeZone="UTC" />);
65
+ await screen.findByTestId('item-row');
66
+ expect(screen.queryByTestId('needs-your-call')).toBeNull();
67
+ });
68
+ });
@@ -0,0 +1,28 @@
1
+ /** Spoken notes with what a careful human would say each to-do's due date and project are (bd startsim-tmrvi.8). */
2
+ export const NOW = Date.parse('2026-11-09T15:00:00Z'); // Monday 10:00 in New York
3
+ export const TIME_ZONE = 'America/New_York';
4
+ export const FOCUSES = [
5
+ { id: 'f-mkt', title: 'Marketing' }, { id: 'f-eng', title: 'Engineering' }, { id: 'f-ops', title: 'Operations' },
6
+ ];
7
+ /** due: ISO day, or '' when nothing was said. project: a focus id, or '' when it is personal or unclear. */
8
+ export interface Truth { match: string; due: string; project: string }
9
+ export interface MeasuredNote { transcript: string; truth: Truth[] }
10
+
11
+ export const NOTES: MeasuredNote[] = [
12
+ { transcript: 'Okay quick brain dump. I need to call the vet by Friday. Also send the invoice to Sam for the website thing. And somebody has to fix the login bug soon. Oh, and buy a birthday present for my sister.',
13
+ truth: [{ match: 'vet', due: '2026-11-13', project: '' }, { match: 'invoice', due: '', project: '' }, { match: 'login', due: '', project: 'f-eng' }, { match: 'birthday', due: '', project: '' }] },
14
+ { transcript: 'Marketing stuff for this week. Draft the November newsletter by Wednesday. Book the photographer for the launch shoot, tomorrow. Review the ad budget with Priya on Thursday.',
15
+ truth: [{ match: 'newsletter', due: '2026-11-11', project: 'f-mkt' }, { match: 'photographer', due: '2026-11-10', project: 'f-mkt' }, { match: 'budget', due: '2026-11-12', project: 'f-mkt' }] },
16
+ { transcript: 'Engineering notes. The checkout page times out on mobile, that needs fixing today. Upgrade the database driver sometime next week. Write up the incident report from last night.',
17
+ truth: [{ match: 'checkout', due: '2026-11-09', project: 'f-eng' }, { match: 'driver', due: '', project: 'f-eng' }, { match: 'incident', due: '', project: 'f-eng' }] },
18
+ { transcript: 'Operations. Renew the office lease before the end of the month. Order new laptops for the two new hires. Schedule the fire drill for next Tuesday.',
19
+ truth: [{ match: 'lease', due: '2026-11-30', project: 'f-ops' }, { match: 'laptops', due: '', project: 'f-ops' }, { match: 'fire drill', due: '2026-11-17', project: 'f-ops' }] },
20
+ { transcript: 'Personal stuff. Pick up the dry cleaning tomorrow. Book a dentist appointment. Call mom on Sunday.',
21
+ truth: [{ match: 'dry cleaning', due: '2026-11-10', project: '' }, { match: 'dentist', due: '', project: '' }, { match: 'mom', due: '2026-11-15', project: '' }] },
22
+ { transcript: 'All of these are for Friday. Send the press release, finish the sales deck, and confirm the venue.',
23
+ truth: [{ match: 'press release', due: '2026-11-13', project: 'f-mkt' }, { match: 'deck', due: '2026-11-13', project: 'f-mkt' }, { match: 'venue', due: '2026-11-13', project: '' }] },
24
+ { transcript: 'Remind me to look into the pricing page experiment. Also the on-call rota needs updating, and we should ask legal about the vendor contract.',
25
+ truth: [{ match: 'pricing', due: '', project: 'f-mkt' }, { match: 'rota', due: '', project: 'f-eng' }, { match: 'contract', due: '', project: 'f-ops' }] },
26
+ { transcript: 'Today I have to merge the auth refactor, reply to the investor email, and pay the AWS bill. The AWS bill is due on the fifteenth.',
27
+ truth: [{ match: 'auth', due: '2026-11-09', project: 'f-eng' }, { match: 'investor', due: '2026-11-09', project: '' }, { match: 'aws', due: '2026-11-15', project: 'f-ops' }] },
28
+ ];
@@ -0,0 +1,51 @@
1
+ // @vitest-environment node
2
+ /**
3
+ * Real-model measurement of the clarifying-question loop (bd startsim-tmrvi.8). NOT a unit test: it calls a
4
+ * paid model, so it runs only with MEASURE_VOICE=1 and a key in the environment.
5
+ * MEASURE_VOICE=1 npx vitest run src/__tests__/measure
6
+ * It prints questions per note and how often a field Tandem acted on without asking was actually wrong.
7
+ */
8
+ import { describe, expect, it } from 'vitest';
9
+
10
+ import { createVoiceAnalyzer } from '../../corpus/llm';
11
+ import { resolveSectionFields } from '../../corpus/voice-due';
12
+ import { FOCUSES, NOTES, NOW, TIME_ZONE } from './notes';
13
+
14
+ const day = (v: unknown) => (v == null ? '' : String(v).slice(0, 10));
15
+
16
+ describe.skipIf(!process.env.MEASURE_VOICE)('voice notes with a real model', () => {
17
+ it('measures questions per note and wrong silent assumptions', async () => {
18
+ const analyzer = createVoiceAnalyzer();
19
+ const rows: string[] = [];
20
+ let questions = 0, items = 0, silent = 0, silentWrong = 0, askedFine = 0, askedTotal = 0, missing = 0, matched = 0;
21
+ for (const note of NOTES) {
22
+ const a = await analyzer.analyze({ transcript: note.transcript, focuses: FOCUSES, now: NOW, timeZone: TIME_ZONE });
23
+ const r = resolveSectionFields(a.sections ?? [], {
24
+ now: NOW, timeZone: TIME_ZONE, transcript: note.transcript, noteWhen: a.noteWhen,
25
+ focusTitles: Object.fromEntries(FOCUSES.map((f) => [f.id, f.title])),
26
+ });
27
+ questions += r.flagged;
28
+ for (const t of note.truth) {
29
+ const rec = r.records.find((x) => x.title.toLowerCase().includes(t.match));
30
+ if (!rec) { missing += 1; rows.push(` MISSING item "${t.match}"`); continue; }
31
+ matched += 1; items += 1;
32
+ for (const [name, want, got] of [['due', t.due, day(rec.fields.due.value)], ['project', t.project, String(rec.fields.project.value ?? '').replace(/^personal$/, '')] as const]) {
33
+ const g = rec.fields[name as 'due' | 'project'];
34
+ const asked = Boolean(g.question);
35
+ if (asked) { askedTotal += 1; if (got === want) askedFine += 1; continue; }
36
+ silent += 1;
37
+ if (got !== want) { silentWrong += 1; rows.push(` WRONG ${name} "${rec.title}": acted ${JSON.stringify(got)} wanted ${JSON.stringify(want)} (${g.source}: ${g.reason})`); }
38
+ }
39
+ }
40
+ }
41
+ const out = [
42
+ `notes=${NOTES.length} items matched=${matched} missing=${missing}`,
43
+ `questions per note=${(questions / NOTES.length).toFixed(2)} (${questions} total)`,
44
+ `silent field decisions=${silent}, wrong=${silentWrong} (${silent ? ((100 * silentWrong) / silent).toFixed(1) : 0}%)`,
45
+ `field questions asked=${askedTotal}, of which the guess was already right=${askedFine}`,
46
+ ...rows,
47
+ ].join('\n');
48
+ console.log(out);
49
+ expect(matched).toBeGreaterThan(0);
50
+ }, 600_000);
51
+ });
@@ -0,0 +1,151 @@
1
+ /**
2
+ * "NEEDS YOUR CALL" (bd startsim-tmrvi.7): the open clarifying questions on Home, answered with a tap.
3
+ */
4
+ import * as React from 'react';
5
+ import { render, screen, waitFor, within } from '@testing-library/react';
6
+ import userEvent from '@testing-library/user-event';
7
+ import { describe, expect, it, vi } from 'vitest';
8
+
9
+ import { NeedsYourCall } from '../components/pages/questions';
10
+ import type { NeedsYourCallApi } from '../components/pages/questions';
11
+ import type { OpenQuestion } from '../corpus/questions';
12
+
13
+ const NOW = Date.parse('2026-11-06T17:00:00Z');
14
+
15
+ function q(id: string, over: Partial<OpenQuestion> = {}): OpenQuestion {
16
+ return {
17
+ id, itemId: `item-${id}`, kind: 'due_date', question: 'When is this due?', status: 'open', candidates: [], score: 70,
18
+ ownerSub: 'u1', createdAt: '2026-11-06T10:00:00Z', updatedAt: '2026-11-06T10:00:00Z', ...over,
19
+ };
20
+ }
21
+
22
+ const DUE = q('a', {
23
+ question: 'Is Friday the right due date?', score: 80,
24
+ assumed: { value: '2026-11-13', confidence: 0.4, reason: 'You said "end of the week".' },
25
+ candidates: [{ value: '2026-11-12', confidence: 0.3, reason: 'Thursday' }, { value: '2026-11-16', confidence: 0.2, reason: 'Monday' }],
26
+ });
27
+ const PROJECT = q('b', {
28
+ kind: 'project', question: 'Which project is this for?', score: 60,
29
+ candidates: [{ value: 'f1', confidence: 0.5, reason: '' }, { value: 'f2', confidence: 0.3, reason: '' }],
30
+ });
31
+ const TITLES: Record<string, string> = { 'item-a': 'Send the term sheet', 'item-b': 'Book the venue' };
32
+
33
+ function api(over: Partial<NeedsYourCallApi> = {}, list: OpenQuestion[] = [PROJECT, DUE]): NeedsYourCallApi {
34
+ return { list: vi.fn(async () => list), answer: vi.fn(async () => undefined), skip: vi.fn(async () => undefined), ...over };
35
+ }
36
+ const ui = (a: NeedsYourCallApi, extra: Partial<React.ComponentProps<typeof NeedsYourCall>> = {}) => (
37
+ <NeedsYourCall api={a} now={NOW} timeZone="UTC" itemTitle={(id) => TITLES[id]} projectNames={{ f1: 'Launch v2', f2: 'Ops' }} {...extra} />
38
+ );
39
+
40
+ describe('NeedsYourCall', () => {
41
+ it('lists the questions best first, each with its to-do and chips', async () => {
42
+ render(ui(api()));
43
+ const rows = await screen.findAllByTestId('question-row');
44
+ expect(rows).toHaveLength(2);
45
+ expect(within(rows[0]).getByText('Send the term sheet')).toBeInTheDocument();
46
+ expect(within(rows[0]).getByText('Is Friday the right due date?')).toBeInTheDocument();
47
+ expect(within(rows[1]).getByText('Book the venue')).toBeInTheDocument();
48
+ expect(within(rows[1]).getByRole('button', { name: 'Launch v2' })).toBeInTheDocument();
49
+ expect(screen.getByRole('region', { name: /needs your call/i })).toBeInTheDocument();
50
+ });
51
+
52
+ it('shows the assumed value quietly, as a plain sentence and a one-tap keep', async () => {
53
+ render(ui(api()));
54
+ const row = (await screen.findAllByTestId('question-row'))[0];
55
+ expect(within(row).getByText(/going with Fri, Nov 13/)).toBeInTheDocument();
56
+ expect(within(row).getByRole('button', { name: 'Keep Fri, Nov 13' })).toBeInTheDocument();
57
+ expect(within(row).queryByRole('alert')).toBeNull();
58
+ });
59
+
60
+ it('answers on a tap: the row leaves at once and the answer is saved', async () => {
61
+ const a = api();
62
+ const onApplied = vi.fn();
63
+ render(ui(a, { onApplied }));
64
+ const row = (await screen.findAllByTestId('question-row'))[1];
65
+ await userEvent.click(within(row).getByRole('button', { name: 'Launch v2' }));
66
+ expect(screen.getAllByTestId('question-row')).toHaveLength(1);
67
+ expect(a.answer).toHaveBeenCalledWith(expect.objectContaining({ id: 'b' }), { value: 'f1', label: 'Launch v2' });
68
+ expect(onApplied).toHaveBeenCalledWith(expect.objectContaining({ id: 'b' }), { value: 'f1', label: 'Launch v2' });
69
+ await waitFor(() => expect(screen.getByRole('status')).toHaveTextContent('Saved.'));
70
+ });
71
+
72
+ it('puts the question back and undoes the change when the save fails', async () => {
73
+ const a = api({ answer: vi.fn(async () => { throw new Error('boom'); }) });
74
+ const onReverted = vi.fn();
75
+ render(ui(a, { onReverted }));
76
+ const row = (await screen.findAllByTestId('question-row'))[1];
77
+ await userEvent.click(within(row).getByRole('button', { name: 'Launch v2' }));
78
+ expect(await screen.findByRole('alert')).toHaveTextContent('did not save');
79
+ const rows = screen.getAllByTestId('question-row');
80
+ expect(rows).toHaveLength(2);
81
+ expect(within(rows[1]).getByText('Book the venue')).toBeInTheDocument();
82
+ expect(onReverted).toHaveBeenCalledWith(expect.objectContaining({ id: 'b' }));
83
+ });
84
+
85
+ it('skips on request, and restores the question if that fails', async () => {
86
+ const a = api();
87
+ render(ui(a));
88
+ await userEvent.click(within((await screen.findAllByTestId('question-row'))[0]).getByRole('button', { name: 'Skip it' }));
89
+ expect(a.skip).toHaveBeenCalledWith(expect.objectContaining({ id: 'a' }));
90
+ expect(screen.getAllByTestId('question-row')).toHaveLength(1);
91
+ });
92
+
93
+ it('brings a skipped question back when the skip does not save', async () => {
94
+ render(ui(api({ skip: vi.fn(async () => { throw new Error('no'); }) })));
95
+ const rows = await screen.findAllByTestId('question-row');
96
+ await userEvent.click(within(rows[1]).getByRole('button', { name: 'Skip it' }));
97
+ expect(await screen.findByRole('alert')).toHaveTextContent('did not save');
98
+ expect(screen.getAllByTestId('question-row')).toHaveLength(2);
99
+ });
100
+
101
+ it('reads a typed answer like a spoken one', async () => {
102
+ const a = api();
103
+ render(ui(a));
104
+ const row = (await screen.findAllByTestId('question-row'))[0];
105
+ await userEvent.click(within(row).getByRole('button', { name: 'Something else' }));
106
+ await userEvent.type(within(row).getByLabelText(/your answer for send the term sheet/i), 'tomorrow{enter}');
107
+ expect(a.answer).toHaveBeenCalledWith(expect.objectContaining({ id: 'a' }), { value: '2026-11-07' });
108
+ });
109
+
110
+ it('asks again, without saving, when the typed words mean nothing', async () => {
111
+ const a = api();
112
+ render(ui(a));
113
+ const row = (await screen.findAllByTestId('question-row'))[0];
114
+ await userEvent.click(within(row).getByRole('button', { name: 'Something else' }));
115
+ await userEvent.type(within(row).getByLabelText(/your answer/i), 'purple{enter}');
116
+ expect(a.answer).not.toHaveBeenCalled();
117
+ expect(within(row).getByRole('status')).toHaveTextContent(/day/i);
118
+ });
119
+
120
+ it('is calm when nothing is open', async () => {
121
+ render(ui(api({}, [])));
122
+ expect(await screen.findByText('Nothing needs your call.')).toBeInTheDocument();
123
+ expect(screen.queryByRole('alert')).toBeNull();
124
+ });
125
+
126
+ it('shows a page at a time', async () => {
127
+ const many = Array.from({ length: 7 }, (_, i) => q(`n${i}`, { score: 70 - i }));
128
+ render(ui(api({}, many), { pageSize: 3 }));
129
+ expect(await screen.findAllByTestId('question-row')).toHaveLength(3);
130
+ await userEvent.click(screen.getByRole('button', { name: 'Show 3 more' }));
131
+ expect(screen.getAllByTestId('question-row')).toHaveLength(6);
132
+ });
133
+
134
+ it('says so, and offers a retry, when the list cannot be read', async () => {
135
+ const list = vi.fn().mockRejectedValueOnce(new Error('down')).mockResolvedValue([DUE]);
136
+ render(ui(api({ list })));
137
+ await userEvent.click(await screen.findByRole('button', { name: 'Try again' }));
138
+ expect(await screen.findByText('Is Friday the right due date?')).toBeInTheDocument();
139
+ });
140
+
141
+ it('asks the host for choices a team or owner question can name', async () => {
142
+ const team = q('t', { kind: 'team', question: 'Which team is this for?', itemId: 'item-b' });
143
+ const options = vi.fn(async () => [{ value: 'tm1', label: 'Platform' }]);
144
+ const a = api({}, [team]);
145
+ render(ui(a, { options }));
146
+ await screen.findByText('Which team is this for?');
147
+ const row = screen.getByTestId('question-row');
148
+ await userEvent.click(await within(row).findByRole('button', { name: 'Platform' }));
149
+ expect(a.answer).toHaveBeenCalledWith(expect.objectContaining({ id: 't' }), { value: 'tm1', label: 'Platform' });
150
+ });
151
+ });