@startsimpli/integrations 0.2.150 → 0.2.152

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 (36) hide show
  1. package/package.json +7 -7
  2. package/src/__tests__/briefing-script.test.ts +26 -0
  3. package/src/__tests__/helpers/question-tenant.ts +45 -0
  4. package/src/__tests__/question-checkin.test.ts +139 -0
  5. package/src/__tests__/question-learn.test.ts +124 -0
  6. package/src/__tests__/question-voice-parse.test.ts +110 -0
  7. package/src/__tests__/question-voice.test.ts +225 -0
  8. package/src/__tests__/tracker-done-stamp.test.ts +42 -0
  9. package/src/__tests__/tracker-timeline-component.test.tsx +81 -0
  10. package/src/__tests__/tracker-timeline-reader.test.ts +94 -0
  11. package/src/__tests__/tracker-timeline.test.ts +209 -0
  12. package/src/__tests__/voice-due-inherited.test.ts +37 -0
  13. package/src/components/pages/TrackerPage.tsx +8 -0
  14. package/src/components/pages/tracker/TrackerTimeline.tsx +123 -0
  15. package/src/corpus/briefing/cache-key.ts +2 -2
  16. package/src/corpus/briefing/generate.ts +5 -1
  17. package/src/corpus/briefing/script.ts +12 -3
  18. package/src/corpus/briefing/speak.ts +8 -0
  19. package/src/corpus/briefing/types.ts +2 -0
  20. package/src/corpus/client.ts +12 -1
  21. package/src/corpus/questions/answer.ts +11 -1
  22. package/src/corpus/questions/checkin-handle.ts +67 -0
  23. package/src/corpus/questions/checkin.ts +103 -0
  24. package/src/corpus/questions/index.ts +11 -0
  25. package/src/corpus/questions/learn.ts +135 -0
  26. package/src/corpus/questions/respond.ts +76 -0
  27. package/src/corpus/questions/store.ts +5 -1
  28. package/src/corpus/questions/sync.ts +20 -3
  29. package/src/corpus/questions/types.ts +10 -2
  30. package/src/corpus/questions/voice-parse.ts +98 -0
  31. package/src/corpus/questions/voice.ts +227 -0
  32. package/src/corpus/tracker-timeline-client.ts +117 -0
  33. package/src/corpus/tracker-timeline.ts +228 -0
  34. package/src/corpus/types.ts +10 -0
  35. package/src/corpus/voice-due.ts +29 -4
  36. package/src/corpus/work-item-logic.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/integrations",
3
- "version": "0.2.150",
3
+ "version": "0.2.152",
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.172",
54
- "@startsimpli/utils": "^0.4.18",
55
- "@startsimpli/auth": "^0.4.50"
53
+ "@startsimpli/auth": "^0.4.50",
54
+ "@startsimpli/ui": "^0.4.174",
55
+ "@startsimpli/utils": "^0.4.18"
56
56
  },
57
57
  "peerDependenciesMeta": {
58
58
  "react": {
@@ -98,11 +98,11 @@
98
98
  "vitest": "^3.0.0",
99
99
  "react-native": "0.85.3",
100
100
  "react-native-safe-area-context": "~5.7.0",
101
- "@startsimpli/llm": "0.4.31",
102
- "@startsimpli/ui": "0.4.172",
101
+ "@startsimpli/ui": "0.4.174",
103
102
  "@startsimpli/ui-native": "0.1.14",
104
103
  "@startsimpli/auth": "0.4.50",
105
- "@startsimpli/utils": "0.4.18"
104
+ "@startsimpli/utils": "0.4.18",
105
+ "@startsimpli/llm": "0.4.31"
106
106
  },
107
107
  "scripts": {
108
108
  "type-check": "tsc --noEmit && tsc --noEmit -p tsconfig.native.json",
@@ -142,3 +142,29 @@ describe('writeBriefingScript', () => {
142
142
  expect(llm.write).not.toHaveBeenCalled();
143
143
  });
144
144
  });
145
+
146
+ describe('the pointer to the check-in (bd startsim-tmrvi)', () => {
147
+ it('ends the briefing with how many things are unsure, in the template and with the model', async () => {
148
+ const unsure = { ...briefing(), unsure: 2 };
149
+ for (const llm of [null, goodLlm()]) {
150
+ const script = await writeBriefingScript(unsure, llm, opts);
151
+ expect(script.text).toMatch(/I am also unsure about two things\. Say check in to go through them\.$/);
152
+ expect(script.segments[script.segments.length - 1].id).toBeNull();
153
+ }
154
+ });
155
+
156
+ it('says nothing about it when nothing is open, and in the singular for one', async () => {
157
+ expect((await writeBriefingScript(briefing(), null, opts)).text).not.toMatch(/unsure/);
158
+ expect((await writeBriefingScript({ ...briefing(), unsure: 1 }, null, opts)).text).toMatch(/unsure about one thing\. Say check in to go through it\./);
159
+ });
160
+
161
+ it('is said on a clear day too', async () => {
162
+ const clear = { ...brief([]), unsure: 3 };
163
+ expect((await writeBriefingScript(clear, null, opts)).text).toMatch(/Nothing is due today.*unsure about three things/);
164
+ });
165
+
166
+ it('changes the cache key, so the next tap regenerates', async () => {
167
+ const { briefingContentHash } = await import('../corpus/briefing/cache-key');
168
+ expect(briefingContentHash({ ...briefing(), unsure: 2 })).not.toBe(briefingContentHash(briefing()));
169
+ });
170
+ });
@@ -0,0 +1,45 @@
1
+ import { expect } from 'vitest';
2
+ import type { CorpusHttp } from '../../corpus/client';
3
+
4
+ export interface Row { id: string; entity_type: string; external_id: string; name: string; data: Record<string, unknown>; version: number }
5
+
6
+ /** A tenant in memory: list/get, shallow-merging upsert, and the PATCH door. */
7
+ export function tenant(seed: Array<Omit<Row, 'version'>> = []) {
8
+ const rows = new Map<string, Row>(seed.map((r) => [r.id, { ...r, version: 1 }]));
9
+ let next = 1000;
10
+ const http: CorpusHttp & { post: NonNullable<CorpusHttp['post']>; patch: NonNullable<CorpusHttp['patch']> } = {
11
+ async get(path, options) {
12
+ const clean = path.replace(/\/+$/, '');
13
+ if (clean === 'api/v1/entities') {
14
+ const type = String(options?.params?.type ?? '');
15
+ const all = [...rows.values()].filter((r) => r.entity_type === type);
16
+ return { results: all, next: null } as never;
17
+ }
18
+ const row = rows.get(decodeURIComponent(clean.split('/').pop() as string));
19
+ if (!row) throw Object.assign(new Error('nf'), { status: 404 });
20
+ return structuredClone(row) as never;
21
+ },
22
+ async post(path, body) {
23
+ const b = body as { entity_type: string; external_id: string; name?: string; data: Record<string, unknown> };
24
+ expect(path).toContain('upsert');
25
+ const hit = [...rows.values()].find((r) => r.entity_type === b.entity_type && r.external_id === b.external_id);
26
+ if (hit) {
27
+ hit.data = { ...hit.data, ...b.data };
28
+ if (b.name) hit.name = b.name;
29
+ hit.version += 1;
30
+ return structuredClone(hit) as never;
31
+ }
32
+ const row: Row = { id: `e${next++}`, entity_type: b.entity_type, external_id: b.external_id, name: b.name ?? '', data: { ...b.data }, version: 1 };
33
+ rows.set(row.id, row);
34
+ return structuredClone(row) as never;
35
+ },
36
+ async patch(path, body) {
37
+ const row = rows.get(decodeURIComponent(path.replace(/\/+$/, '').split('/').pop() as string)) as Row;
38
+ row.data = (body as { data: Record<string, unknown> }).data;
39
+ row.version += 1;
40
+ return structuredClone(row) as never;
41
+ },
42
+ };
43
+ return { rows, http };
44
+ }
45
+
@@ -0,0 +1,139 @@
1
+ /**
2
+ * The check-in: "there are N things I am unsure about" (bd startsim-tmrvi.4). Grouped, most important first,
3
+ * each with the guess Tandem is acting on, in words fit to be read aloud.
4
+ */
5
+ import { describe, expect, it } from 'vitest';
6
+
7
+ import { composeCheckIn } from '../corpus/questions/checkin';
8
+ import type { OpenQuestion } from '../corpus/questions';
9
+
10
+ const NOW = Date.parse('2026-11-04T15:00:00Z');
11
+ const TZ = 'America/New_York';
12
+ const q = (id: string, itemId: string, over: Partial<OpenQuestion>): OpenQuestion => ({
13
+ id, itemId, kind: 'due_date', question: 'When is this due?', status: 'open', candidates: [], score: 70, ownerSub: 'me', createdAt: '', updatedAt: '', ...over,
14
+ });
15
+ const titles = new Map([['a', 'Call the vet'], ['b', "Order dad's bench"], ['c', 'Pay LIN-123 invoice'], ['d', 'Plan offsite'], ['e', 'Email Sam'], ['f', 'Renew passport']]);
16
+ const make = (qs: OpenQuestion[], over = {}) => composeCheckIn(qs, { titles, now: NOW, timeZone: TZ, ...over });
17
+
18
+ describe('composeCheckIn', () => {
19
+ it('says nothing when nothing is open', () => {
20
+ const out = make([]);
21
+ expect(out.empty).toBe(true);
22
+ expect(out.text).toBe('');
23
+ });
24
+
25
+ it('counts the doubts and reads the best first, with its guess', () => {
26
+ const out = make([
27
+ q('1', 'b', { kind: 'team', question: 'Which team is this for?', score: 100 }),
28
+ q('2', 'a', { assumed: { value: '2026-11-06', confidence: 0.5, reason: 'said Friday on a Friday' }, score: 80 }),
29
+ ]);
30
+ expect(out.total).toBe(2);
31
+ expect(out.text).toMatch(/^I am not sure about two things\./);
32
+ expect(out.text.indexOf("Order dad's bench")).toBeLessThan(out.text.indexOf('Call the vet'));
33
+ expect(out.text).toMatch(/Friday the sixth/);
34
+ expect(out.entries[1].guess).toBe('Friday the sixth');
35
+ expect(out.entries[0].guess).toBeNull();
36
+ });
37
+
38
+ it('offers how to answer once, not per item', () => {
39
+ const out = make([q('1', 'a', {}), q('2', 'b', {})]);
40
+ expect(out.text.match(/say yes to keep/gi)?.length).toBe(1);
41
+ });
42
+
43
+ it('never reads ticket codes, markup or numeric dates aloud', () => {
44
+ const out = make([q('1', 'c', { assumed: { value: '2026-11-06', confidence: 0.5, reason: 'r' } })]);
45
+ expect(out.text).not.toMatch(/LIN-123|2026-11|\d{4}/);
46
+ });
47
+
48
+ it('speaks a project guess by its name', () => {
49
+ const out = make([q('1', 'a', { kind: 'project', question: 'Which project?', assumed: { value: 'f1', display: 'Marketing', confidence: 0.4, reason: 'r' } })]);
50
+ expect(out.text).toMatch(/Marketing/);
51
+ });
52
+
53
+ it('keeps it short: five items, then how many more', () => {
54
+ const many = ['a', 'b', 'c', 'd', 'e', 'f'].map((id, n) => q(String(n), id, { score: 70 - n }));
55
+ const out = make(many);
56
+ expect(out.entries).toHaveLength(5);
57
+ expect(out.remaining).toBe(1);
58
+ expect(out.text).toMatch(/one more/);
59
+ expect(out.text).toMatch(/six things/);
60
+ });
61
+
62
+ it('segments point at the question each stretch is about, so a reply can be resolved by position', () => {
63
+ const out = make([q('1', 'a', {}), q('2', 'b', {})]);
64
+ const ids = out.segments.filter((s) => s.id).map((s) => s.id);
65
+ expect(ids).toEqual(['1', '2']);
66
+ for (const s of out.segments) expect(out.text.slice(s.start, s.end).length).toBeGreaterThan(0);
67
+ });
68
+
69
+ it('says one thing in the singular', () => {
70
+ expect(make([q('1', 'a', {})]).text).toMatch(/^I am not sure about one thing\./);
71
+ });
72
+ });
73
+
74
+ import { vi } from 'vitest';
75
+ import { buildCheckIn } from '../corpus/questions/checkin-handle';
76
+ import { syncOpenQuestions } from '../corpus/questions';
77
+ import { createMemoryActionLog } from '../corpus/briefing/actions/log';
78
+ import { commitmentEditSeam } from '../corpus/briefing/actions/seam';
79
+ import { createPlanningApi } from '../corpus/client';
80
+ import { tenant } from './helpers/question-tenant';
81
+
82
+ describe('buildCheckIn', () => {
83
+ const SCOPE = { orgId: 'o' } as never;
84
+ const held = (id: string, title: string) => ({
85
+ id, entity_type: 'commitment', external_id: `commit:${id}`, name: title,
86
+ data: { title, status: 'open', open_question_kind: 'team', open_question: 'Which team is this for?', sync_state: 'needs_team' },
87
+ });
88
+ function setup(synth = true) {
89
+ const t = tenant([held('x', "Order dad's bench"), held('y', 'Call the vet')]);
90
+ const api = createPlanningApi({ http: t.http, scope: SCOPE, supportedFilters: [], resolveParticipants: false } as never);
91
+ const synthesize = vi.fn(async () => ({ audio: new Uint8Array([1]), mimeType: 'audio/mpeg', model: 'm', provider: 'p', usage: {} }));
92
+ const put = vi.fn(async () => 'ref-1');
93
+ const deps = {
94
+ http: t.http, scope: SCOPE, ownerSub: 'me', now: () => NOW, timeZone: TZ,
95
+ seam: commitmentEditSeam({ api, http: t.http, scope: SCOPE }),
96
+ patchItem: vi.fn(), options: async () => [], log: createMemoryActionLog(),
97
+ ...(synth ? { synthesize, audio: { put }, audioPath: (id: string) => `/a/${id}` } : {}),
98
+ };
99
+ return { deps, synthesize };
100
+ }
101
+
102
+ it('reads the queue with the item titles and offers the first question to answer', async () => {
103
+ const { deps } = setup(false);
104
+ const out = await buildCheckIn(deps);
105
+ expect(out.total).toBe(2);
106
+ expect(out.text).toMatch(/Order dad's bench|Call the vet/);
107
+ expect(out.firstQuestionId).toBe(out.entries[0].questionId);
108
+ expect(out.audioUrl).toBeNull();
109
+ });
110
+
111
+ it('speaks it once: asking again for the same words does not synthesize again', async () => {
112
+ const { deps, synthesize } = setup(true);
113
+ const a = await buildCheckIn(deps);
114
+ const b = await buildCheckIn(deps);
115
+ expect(a.audioUrl).toMatch(/^\/a\/checkin-/);
116
+ expect(b.audioUrl).toBe(a.audioUrl);
117
+ expect(synthesize).toHaveBeenCalledTimes(1);
118
+ });
119
+
120
+ it('is empty and silent when nothing is open', async () => {
121
+ const t = tenant([]);
122
+ const api = createPlanningApi({ http: t.http, scope: SCOPE, supportedFilters: [], resolveParticipants: false } as never);
123
+ const out = await buildCheckIn({
124
+ http: t.http, scope: SCOPE, ownerSub: 'me', now: () => NOW, seam: commitmentEditSeam({ api, http: t.http, scope: SCOPE }),
125
+ patchItem: vi.fn(), options: async () => [], log: createMemoryActionLog(),
126
+ } as never);
127
+ expect(out).toMatchObject({ empty: true, audioUrl: null, firstQuestionId: null });
128
+ void syncOpenQuestions;
129
+ });
130
+ });
131
+
132
+ describe('a guess stored as an id', () => {
133
+ it('is said by name when the name is known, and not at all when it is not', () => {
134
+ const unnamed = make([q('1', 'a', { kind: 'project', question: 'Which project?', assumed: { value: '854c5d84-d879', confidence: 0.4, reason: 'r' } })]);
135
+ expect(unnamed.text).not.toMatch(/854c/);
136
+ expect(unnamed.entries[0].guess).toBeNull();
137
+ expect(unnamed.text).toMatch(/which project/i);
138
+ });
139
+ });
@@ -0,0 +1,124 @@
1
+ // @vitest-environment node
2
+ /**
3
+ * Learning from answers, and using what was learned before asking (bd startsim-tmrvi.6, tmrvi.2).
4
+ * Two answers that agree make a habit; a habit that agrees with Tandem's guess saves a question.
5
+ */
6
+ import { describe, expect, it, vi } from 'vitest';
7
+
8
+ import { commitmentEditSeam } from '../corpus/briefing/actions/seam';
9
+ import { createPlanningApi } from '../corpus/client';
10
+ import { guessOf, unknownGuess } from '../corpus/extraction-fields';
11
+ import { answerQuestion, listOpenQuestions, syncOpenQuestions } from '../corpus/questions';
12
+ import { createPreferenceStore, learnFromAnswer, nextEvidence } from '../corpus/questions/learn';
13
+ import { tenant } from './helpers/question-tenant';
14
+
15
+ const SCOPE = { orgId: 'o' } as never;
16
+ const ME = 'me';
17
+ const NOW = Date.parse('2026-11-04T15:00:00Z');
18
+ const TZ = 'America/New_York';
19
+
20
+ describe('nextEvidence', () => {
21
+ it('counts agreement and notes conflict', () => {
22
+ let e = nextEvidence(undefined, 'a');
23
+ e = nextEvidence(e, 'a');
24
+ expect(e).toMatchObject({ value: 'a', count: 2, conflicts: 0 });
25
+ e = nextEvidence(e, 'b');
26
+ expect(e).toMatchObject({ value: 'a', count: 2, conflicts: 1 });
27
+ });
28
+ it('switches to the new answer when it wins', () => {
29
+ let e = nextEvidence(undefined, 'a');
30
+ e = nextEvidence(e, 'b');
31
+ e = nextEvidence(e, 'b');
32
+ expect(e.value).toBe('b');
33
+ });
34
+ });
35
+
36
+ const item = (id: string, data: Record<string, unknown> = {}) => ({
37
+ id, entity_type: 'commitment', external_id: `commit:${id}`, name: String(data.title ?? id),
38
+ data: { title: `Item ${id}`, status: 'open', mentions: [{ document_id: 'note1', quote: 'q' }], ...data },
39
+ });
40
+ const fields = (over: object) => ({ due: unknownGuess('x'), project: unknownGuess('x'), owner: unknownGuess('x'), priority: unknownGuess('x'), estimate: unknownGuess('x'), ...over });
41
+ const note = (records: unknown[]) => ({
42
+ id: 'note1', entity_type: 'source_document', external_id: 'voice:n1', name: 'n',
43
+ data: { source: 'voice', title: 'n', voice_items: JSON.stringify(records) },
44
+ });
45
+
46
+ function setup(rows: Parameters<typeof tenant>[0]) {
47
+ const t = tenant(rows);
48
+ const api = createPlanningApi({ http: t.http, scope: SCOPE, supportedFilters: [], resolveParticipants: false } as never);
49
+ const deps = {
50
+ http: t.http, scope: SCOPE, ownerSub: ME, now: () => NOW, timeZone: TZ,
51
+ seam: commitmentEditSeam({ api, http: t.http, scope: SCOPE }),
52
+ patchItem: vi.fn(async (id: string, wire: Record<string, unknown>) => { const r = t.rows.get(id)!; r.data = { ...r.data, ...wire }; }),
53
+ fileItem: vi.fn(async () => undefined),
54
+ };
55
+ return { t, deps };
56
+ }
57
+
58
+ describe('learning from answers', () => {
59
+ it('words in a title that keep going to one project become a habit; one answer is not yet', async () => {
60
+ const { t, deps } = setup([item('a', { title: 'Newsletter draft for November' })]);
61
+ const prefs = createPreferenceStore(deps);
62
+ await learnFromAnswer(deps, { kind: 'project', title: 'Newsletter draft for November', answer: { value: 'f-mkt' } });
63
+ expect((await prefs.confident('project_word', 'newsletter'))).toBeNull();
64
+ await learnFromAnswer(deps, { kind: 'project', title: 'Newsletter schedule', answer: { value: 'f-mkt' } });
65
+ expect((await prefs.confident('project_word', 'newsletter'))?.value).toBe('f-mkt');
66
+ expect(t.rows.size).toBeGreaterThan(0);
67
+ });
68
+
69
+ it('a conflicting answer makes it unsure again', async () => {
70
+ const { deps } = setup([]);
71
+ const prefs = createPreferenceStore(deps);
72
+ for (const v of ['f-mkt', 'f-mkt', 'f-ops']) await learnFromAnswer(deps, { kind: 'project', title: 'Newsletter', answer: { value: v } });
73
+ expect(await prefs.confident('project_word', 'newsletter')).toBeNull();
74
+ });
75
+
76
+ it('due dates learn the usual offset (today, tomorrow, no date) after three alike', async () => {
77
+ const { deps } = setup([]);
78
+ const prefs = createPreferenceStore(deps);
79
+ for (const d of ['2026-11-04', '2026-11-04']) await learnFromAnswer(deps, { kind: 'due_date', title: 'x', answer: { value: d } });
80
+ expect(await prefs.confident('due_offset', 'default')).toBeNull();
81
+ await learnFromAnswer(deps, { kind: 'due_date', title: 'y', answer: { value: '2026-11-04' } });
82
+ expect((await prefs.confident('due_offset', 'default'))?.value).toBe('0');
83
+ });
84
+
85
+ it('answering a question teaches (the real path)', async () => {
86
+ const { deps } = setup([
87
+ item('a', { title: 'Newsletter draft', external_focus_id: 'f-web' }),
88
+ note([{ section: 's', title: 'Newsletter draft', fields: fields({ project: guessOf('f-web', 0.4, 'assumed', 'r', { question: 'Which project?' }) }) }]),
89
+ ]);
90
+ await syncOpenQuestions(deps);
91
+ const [q] = await listOpenQuestions(deps);
92
+ await answerQuestion({ ...deps, learn: true } as never, q.id, { value: 'f-mkt' });
93
+ const stored = await createPreferenceStore(deps).all();
94
+ expect(stored.some((p) => p.kind === 'project_word' && p.key === 'newsletter' && p.value === 'f-mkt')).toBe(true);
95
+ });
96
+ });
97
+
98
+ describe('using what was learned before asking', () => {
99
+ const rows = () => [
100
+ item('a', { title: 'Newsletter draft', external_focus_id: 'f-mkt' }),
101
+ note([{ section: 's', title: 'Newsletter draft', fields: fields({ project: guessOf('f-mkt', 0.4, 'assumed', 'r', { question: 'Which project?' }) }) }]),
102
+ ];
103
+
104
+ it('does not ask when a habit agrees with the guess, and records why', async () => {
105
+ const { deps } = setup(rows());
106
+ for (let i = 0; i < 2; i += 1) await learnFromAnswer(deps, { kind: 'project', title: 'Newsletter', answer: { value: 'f-mkt' } });
107
+ const counts = await syncOpenQuestions(deps);
108
+ expect(await listOpenQuestions(deps)).toEqual([]);
109
+ expect(counts).toMatchObject({ opened: 0, decidedByContext: 1 });
110
+ });
111
+
112
+ it('still asks when the habit disagrees with the guess', async () => {
113
+ const { deps } = setup(rows());
114
+ for (let i = 0; i < 2; i += 1) await learnFromAnswer(deps, { kind: 'project', title: 'Newsletter', answer: { value: 'f-ops' } });
115
+ await syncOpenQuestions(deps);
116
+ expect(await listOpenQuestions(deps)).toHaveLength(1);
117
+ });
118
+
119
+ it('still asks when nothing was learned', async () => {
120
+ const { deps } = setup(rows());
121
+ await syncOpenQuestions(deps);
122
+ expect(await listOpenQuestions(deps)).toHaveLength(1);
123
+ });
124
+ });
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Answering a clarifying question by voice (bd startsim-tmrvi.5). The words people
3
+ * actually say to "When is this due?" / "Which project?" become one answer, or a
4
+ * short question back. Never a briefing action: "skip it" must not drop a to-do.
5
+ */
6
+ import { describe, expect, it } from 'vitest';
7
+
8
+ import { parseSpokenAnswer } from '../corpus/questions/voice-parse';
9
+ import type { OpenQuestion } from '../corpus/questions';
10
+
11
+ const NOW = Date.parse('2026-11-04T15:00:00Z'); // Wednesday 10:00 in New York
12
+ const TZ = 'America/New_York';
13
+
14
+ const q = (over: Partial<OpenQuestion>): OpenQuestion => ({
15
+ id: 'q1', itemId: 'i1', kind: 'due_date', question: 'When is this due?', status: 'open', candidates: [],
16
+ score: 70, ownerSub: 'me', createdAt: '', updatedAt: '', ...over,
17
+ });
18
+ const ctx = (options: Array<{ value: string; label: string }> = []) => ({ now: NOW, timeZone: TZ, options });
19
+
20
+ const PROJECTS = [
21
+ { value: 'f-mkt', label: 'Marketing' },
22
+ { value: 'f-web', label: 'Website redesign' },
23
+ { value: 'f-ops', label: 'Operations' },
24
+ ];
25
+
26
+ describe('parseSpokenAnswer: due date', () => {
27
+ const due = q({ assumed: { value: '2026-11-06', confidence: 0.5, reason: 'by Friday' } });
28
+
29
+ it.each([
30
+ ['today', '2026-11-04'],
31
+ ['tomorrow', '2026-11-05'],
32
+ ['next week', '2026-11-09'],
33
+ ['make it Friday please', '2026-11-06'],
34
+ ["let's say next Tuesday", '2026-11-10'],
35
+ ])('%s -> %s', (said, date) => {
36
+ const out = parseSpokenAnswer(due, said, ctx());
37
+ expect(out).toMatchObject({ kind: 'answer', value: date });
38
+ });
39
+
40
+ it('later clears the due date', () => {
41
+ expect(parseSpokenAnswer(due, 'someday', ctx())).toMatchObject({ kind: 'answer', value: '' });
42
+ });
43
+
44
+ it('keeps the guess on a yes', () => {
45
+ for (const said of ['yes', 'yeah that is right', 'keep it', 'sounds good', "that's fine"]) {
46
+ expect(parseSpokenAnswer(due, said, ctx())).toEqual({ kind: 'accept' });
47
+ }
48
+ });
49
+
50
+ it('skip is a skip, not a drop', () => {
51
+ for (const said of ['skip it', 'not now', 'ask me later', 'pass']) {
52
+ expect(parseSpokenAnswer(due, said, ctx())).toEqual({ kind: 'skip' });
53
+ }
54
+ });
55
+
56
+ it('asks again on something that is not a date', () => {
57
+ const out = parseSpokenAnswer(due, 'banana', ctx());
58
+ expect(out.kind).toBe('unclear');
59
+ });
60
+
61
+ it('undo is its own thing', () => {
62
+ expect(parseSpokenAnswer(due, 'undo that', ctx())).toEqual({ kind: 'undo' });
63
+ });
64
+
65
+ it('a yes with no guess to keep asks for the answer', () => {
66
+ const out = parseSpokenAnswer(q({}), 'yes', ctx());
67
+ expect(out.kind).toBe('unclear');
68
+ });
69
+ });
70
+
71
+ describe('parseSpokenAnswer: a choice (project, team, owner)', () => {
72
+ const project = q({ kind: 'project', question: 'Which project is this for?', candidates: [
73
+ { value: 'f-mkt', confidence: 0.5, reason: '' }, { value: 'f-web', confidence: 0.4, reason: '' },
74
+ ] });
75
+
76
+ it("that's the marketing project", () => {
77
+ expect(parseSpokenAnswer(project, "that's the marketing project", ctx(PROJECTS))).toMatchObject({ kind: 'answer', value: 'f-mkt', label: 'Marketing' });
78
+ });
79
+
80
+ it('picks by position among the options just offered', () => {
81
+ expect(parseSpokenAnswer(project, 'the second one', ctx(PROJECTS))).toMatchObject({ kind: 'answer', value: 'f-web' });
82
+ expect(parseSpokenAnswer(project, 'the first', ctx(PROJECTS))).toMatchObject({ kind: 'answer', value: 'f-mkt' });
83
+ });
84
+
85
+ it('names an option that was not among the candidates', () => {
86
+ expect(parseSpokenAnswer(project, 'operations', ctx(PROJECTS))).toMatchObject({ kind: 'answer', value: 'f-ops' });
87
+ });
88
+
89
+ it('asks which one when the words fit two', () => {
90
+ const two = [{ value: 'a', label: 'Marketing site' }, { value: 'b', label: 'Marketing email' }];
91
+ const out = parseSpokenAnswer(project, 'marketing', ctx(two));
92
+ expect(out).toMatchObject({ kind: 'unclear' });
93
+ expect((out as { question: string }).question).toMatch(/Marketing site/);
94
+ });
95
+
96
+ it('offers the candidates when nothing fits', () => {
97
+ const out = parseSpokenAnswer(project, 'the purple thing', ctx(PROJECTS));
98
+ expect(out.kind).toBe('unclear');
99
+ expect((out as { question: string }).question).toMatch(/Marketing/);
100
+ });
101
+
102
+ it('accepts the guess on a yes', () => {
103
+ const guessed = q({ kind: 'project', assumed: { value: 'f-mkt', display: 'Marketing', confidence: 0.6, reason: '' } });
104
+ expect(parseSpokenAnswer(guessed, 'yes', ctx(PROJECTS))).toEqual({ kind: 'accept' });
105
+ });
106
+
107
+ it('skip works here too', () => {
108
+ expect(parseSpokenAnswer(project, 'skip it', ctx(PROJECTS))).toEqual({ kind: 'skip' });
109
+ });
110
+ });