@startsimpli/integrations 0.2.132 → 0.2.134

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/integrations",
3
- "version": "0.2.132",
3
+ "version": "0.2.134",
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",
@@ -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.171",
103
102
  "@startsimpli/ui-native": "0.1.14",
104
103
  "@startsimpli/auth": "0.4.50",
104
+ "@startsimpli/ui": "0.4.171",
105
105
  "@startsimpli/utils": "0.4.17"
106
106
  },
107
107
  "scripts": {
@@ -0,0 +1,72 @@
1
+ /**
2
+ * REAL NOTES, REPLAYED (bd startsim-b7kir). Quinn's three morning voice notes on
3
+ * 2026-11-05 and 2026-11-06 (America/Boise), transcripts verbatim, and the
4
+ * analysis the PRODUCTION model gave them: sections and items exactly as stored,
5
+ * with no timing at all. That is the defect: "things for the day" came out with
6
+ * no due date, so the briefing and Today were empty.
7
+ */
8
+ export const QUINN_TZ = 'America/Boise';
9
+
10
+ export const FOCUS_IDS = {
11
+ debug: 'fc119ad0-ea7e-4e88-967f-4d91b672fcb5',
12
+ agents: '7fc037a9-acc5-44ee-a0fb-3be59e390274',
13
+ crochet: '007ebaae-db9f-40e5-97cc-dc92e3502568',
14
+ };
15
+ export const QUINN_FOCUSES = [
16
+ { id: FOCUS_IDS.debug, title: 'DebuggAI Platform', detail: 'DebuggAI browser testing product' },
17
+ { id: FOCUS_IDS.agents, title: 'Marketing Agents', detail: 'OGMC marketing agents tenant' },
18
+ { id: FOCUS_IDS.crochet, title: 'Crochets', detail: 'Crochet pattern marketplace' },
19
+ ];
20
+
21
+ export interface ReplayNote {
22
+ id: string;
23
+ recordedAt: string;
24
+ transcript: string;
25
+ /** What the production model returned (no timing fields). */
26
+ reply: { title: string; summary: string; sections: Array<{ label: string; kind: string; focusId: string | null; summary: string; items: Array<{ title: string }> }> };
27
+ }
28
+
29
+ export const QUINN_NOTES: ReplayNote[] = [
30
+ {
31
+ id: "nov6-work",
32
+ recordedAt: "2026-11-06T15:37:26.791Z",
33
+ transcript: "All right, now on to work stuff for the day. I gotta check the debug AI backend and UI updates. We've made some fixes against the UI mockups, so I need to check those and move on to other pages. I've got to do two sessions of 15 minutes, so that's two separate tasks, each 15 minutes on debug UI. I have to do the same two tasks each 15 minutes long for marketing agent's UI. I also have to run through a quick check of the V2 marketing agent's deployed app because we made changes there. On the Quinn AI project, which is a personal effort, personal work, I guess, still under work, but it is running simulations against my actual efforts versus the organization-generated efforts, and I need to review and provide feedback on, what do we have left, on the animated video builder. We did two videos for debug resources yesterday. I'd like to do at least two more today for the top articles and potentially even one of the landing pages. On Crochet's app, we're pushing updates using the new engine and the new model designs to the website, which is editing, production data, like the early models, and even though in production were pretty shitty, so it's not a huge risk, but I do have to go manually check at least a few of those before we continue on with that project.",
34
+ reply: {
35
+ title: "Daily Work Tasks",
36
+ summary: 'Tasks for the day.',
37
+ sections: [
38
+ { label: "DebuggAI Platform", kind: "project", focusId: FOCUS_IDS.debug, summary: '', items: [{ title: "Check the debug AI backend and UI updates" }, { title: "Complete two sessions of 15 minutes on debug UI" }] },
39
+ { label: "Marketing Agents", kind: "project", focusId: FOCUS_IDS.agents, summary: '', items: [{ title: "Complete two sessions of 15 minutes on marketing agent's UI" }, { title: "Run a quick check of the V2 marketing agent's deployed app" }] },
40
+ { label: "Quinn AI", kind: "personal", focusId: null, summary: '', items: [{ title: "Review and provide feedback on animated video builder" }] },
41
+ { label: "DebuggAI Resources", kind: "project", focusId: FOCUS_IDS.debug, summary: '', items: [{ title: "Create two videos for top articles" }, { title: "Create one video for landing pages" }] },
42
+ { label: "Crochets", kind: "project", focusId: FOCUS_IDS.crochet, summary: '', items: [{ title: "Manually check production data before continuing updates" }] },
43
+ ],
44
+ },
45
+ },
46
+ {
47
+ id: "nov6-personal",
48
+ recordedAt: "2026-11-06T15:34:59.299Z",
49
+ transcript: "All right, today is starting on the personal side. Woke up at about 7:30, which was good. In bed still too early at like 9 o'clock. You drink a good amount, which we're working on reducing, particularly this weekend. Hmm, what else? Coffee was good, stopped by noon or 1, and my meds last took at noon as well, so those checked out. I had a good number of walks with Quanta, did two rounds of like mountain biking around the property, which was good as well. So, yeah, looking to keep that today, and particularly to add a stretching in front of the TV as a goal.",
50
+ reply: {
51
+ title: "Personal Health Goals",
52
+ summary: 'Tasks for the day.',
53
+ sections: [
54
+ { label: "Personal", kind: "personal", focusId: null, summary: '', items: [{ title: "Reduce alcohol consumption this weekend" }, { title: "Add stretching in front of the TV today" }] },
55
+ ],
56
+ },
57
+ },
58
+ {
59
+ id: "nov5-daily",
60
+ recordedAt: "2026-11-05T15:31:19.906Z",
61
+ transcript: "Um, all right, well, today, doing pretty well. Uh, just finally followed up with uh John slash Panda uh via WhatsApp, um, so I still need to call him. Um, from a personal standpoint, woke up at about 7:45, relatively naturally, uh, was in bed a little too early at 9, and then sort of tried to fall asleep at 11. Um, from my sleep goals from yesterday, I didn't have coffee past 1. I had my second um ADHD med at noon. Um, and again, in bed at 9, which is a little bit before the goal of 11. Um, intention for the day has not been set, uh, but I need to do that uh sometime in the next few hours. Um, in terms of my sole goals personally for the day, uh, I wanna work on my dad's bench present uh a bit more. I wanna check out uh some of the tasks in the gardening uh greenhouse. Um, from a physical uh goal today standpoint, I want to do at least two decent length walks, um, mountain bike with Quanta again for a bit, uh, and then do some Achilles stretching uh in front of the TV. Um, in terms of work goals for today, high level, um, I need to uh go through the debug backend uh API work that was done yesterday, uh, and validate that it works. I've got to spend two 15-minute blocks on the debug UI wireframes. I've also got to spend two 15-minute chunks on the marketing agents wireframes. Um, then there's also the marketing agent's um redeploy of the V2 app that I need to click through and review. And then on the Crochets app, I need to ensure that our new model designs can be pulled into the Crochet SDK layer and viewer nicely, and then publish those changes.",
62
+ reply: {
63
+ title: "Daily Goals and Tasks",
64
+ summary: 'Tasks for the day.',
65
+ sections: [
66
+ { label: "Personal", kind: "personal", focusId: null, summary: '', items: [{ title: "Set intention for the day" }, { title: "Work on dad's bench present" }, { title: "Check tasks in gardening greenhouse" }, { title: "Do at least two decent length walks" }, { title: "Mountain bike with Quanta" }, { title: "Do Achilles stretching in front of the TV" }] },
67
+ { label: "DebuggAI Platform", kind: "project", focusId: FOCUS_IDS.debug, summary: '', items: [{ title: "Go through debug backend API work and validate" }, { title: "Spend two 15-minute blocks on debug UI wireframes" }, { title: "Spend two 15-minute chunks on marketing agents wireframes" }, { title: "Review redeploy of the V2 app for marketing agents" }] },
68
+ { label: "Crochets", kind: "project", focusId: FOCUS_IDS.crochet, summary: '', items: [{ title: "Ensure new model designs can be pulled into Crochet SDK layer and viewer" }, { title: "Publish changes to the Crochets app" }] },
69
+ ],
70
+ },
71
+ },
72
+ ];
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Spoken time phrases -> due dates (bd startsim-b7kir). Pure and model-free: the
3
+ * model may quote the phrase it heard, but the DATE is always computed here,
4
+ * from when the note was recorded and the speaker's own time zone.
5
+ */
6
+ import { describe, expect, it } from 'vitest';
7
+
8
+ import { noteWideWhen, resolveSpokenTime } from '../corpus/spoken-time';
9
+
10
+ // Fri 2026-11-06 08:37 in Boise (MST, UTC-7): the real morning of the two notes.
11
+ const NOW = Date.parse('2026-11-06T15:37:26.791Z');
12
+ const TZ = 'America/Boise';
13
+ const at = (text: string, now = NOW, timeZone = TZ) => resolveSpokenTime(text, { now, timeZone });
14
+ const instant = (local: string) => new Date(local).toISOString(); // local given with explicit offset
15
+
16
+ describe('resolveSpokenTime', () => {
17
+ it.each([
18
+ ['things I need to do today', '2026-11-06'],
19
+ ['I will do it this morning', '2026-11-06'],
20
+ ['this afternoon', '2026-11-06'],
21
+ ['tonight', '2026-11-06'],
22
+ ['by end of day', '2026-11-06'],
23
+ ['tomorrow', '2026-11-07'],
24
+ ['the day after tomorrow', '2026-11-08'],
25
+ ['by Friday', '2026-11-06'],
26
+ ['by Monday', '2026-11-09'],
27
+ ['on Wednesday', '2026-11-11'],
28
+ ['next Friday', '2026-11-13'],
29
+ ['next Monday', '2026-11-09'],
30
+ ['this week', '2026-11-06'],
31
+ ['by the end of the week', '2026-11-06'],
32
+ ['next week', '2026-11-13'],
33
+ ['this weekend', '2026-11-08'],
34
+ ['next weekend', '2026-11-15'],
35
+ ['in 3 days', '2026-11-09'],
36
+ ['in two weeks', '2026-11-20'],
37
+ ['by the end of the month', '2026-11-30'],
38
+ ['on November 20', '2026-11-20'],
39
+ ['by the 20th', '2026-11-20'],
40
+ ['ASAP', '2026-11-06'],
41
+ ['right away', '2026-11-06'],
42
+ ['sometime in the next few hours', '2026-11-06'],
43
+ ])('%s -> %s', (phrase, date) => {
44
+ const r = at(phrase);
45
+ expect(r?.kind).toBe('dated');
46
+ expect(r?.date).toBe(date);
47
+ expect(r?.time ?? null).toBeNull();
48
+ expect(r?.dueAt).toBe(date);
49
+ });
50
+
51
+ it('keeps the speaker\'s local day when UTC has already rolled over', () => {
52
+ const evening = Date.parse('2026-11-07T03:30:00Z'); // 20:30 Friday in Boise, Saturday in UTC
53
+ expect(at('today', evening)?.date).toBe('2026-11-06');
54
+ expect(at('tomorrow', evening)?.date).toBe('2026-11-07');
55
+ expect(at('tonight', evening)?.date).toBe('2026-11-06');
56
+ });
57
+
58
+ it('turns a spoken clock time into an instant in the speaker\'s zone', () => {
59
+ const r = at('before the call at 2');
60
+ expect(r).toMatchObject({ kind: 'dated', date: '2026-11-06', time: '14:00' });
61
+ expect(r?.dueAt).toBe(instant('2026-11-06T14:00:00-07:00'));
62
+ expect(at('at 9')?.time).toBe('09:00');
63
+ expect(at('by noon')?.time).toBe('12:00');
64
+ expect(at('tomorrow at 3:30pm')).toMatchObject({ date: '2026-11-07', time: '15:30' });
65
+ expect(at('Friday at 2pm')).toMatchObject({ date: '2026-11-06', time: '14:00' });
66
+ });
67
+
68
+ it('rolls a clock time that has already passed to tomorrow', () => {
69
+ const afternoon = Date.parse('2026-11-06T22:00:00Z'); // 15:00 Boise
70
+ expect(at('at 2', afternoon)?.date).toBe('2026-11-07');
71
+ expect(at('at 4pm', afternoon)?.date).toBe('2026-11-06');
72
+ });
73
+
74
+ it('measures relative hours from the moment of recording', () => {
75
+ const r = at('in two hours');
76
+ expect(r?.dueAt).toBe(new Date(NOW + 2 * 3_600_000).toISOString());
77
+ expect(r?.time).toBe('10:37');
78
+ });
79
+
80
+ it('says how sure it is', () => {
81
+ expect(at('today')?.confidence).toBe('exact');
82
+ expect(at('tomorrow')?.confidence).toBe('exact');
83
+ expect(at('this week')?.confidence).toBe('approximate');
84
+ expect(at('next week')?.confidence).toBe('approximate');
85
+ expect(at('ASAP')?.confidence).toBe('approximate');
86
+ expect(at('at 2')?.confidence).toBe('approximate'); // no am/pm said
87
+ expect(at('at 2pm')?.confidence).toBe('exact');
88
+ });
89
+
90
+ it('flags urgency as a priority, not just a date', () => {
91
+ expect(at('do it ASAP')?.priority).toBe(1);
92
+ expect(at('this is urgent')?.priority).toBe(1);
93
+ expect(at('tomorrow')?.priority).toBeUndefined();
94
+ });
95
+
96
+ it('leaves "sometime" unscheduled instead of guessing', () => {
97
+ for (const phrase of ['sometime', 'at some point', 'eventually', 'someday', 'when I get a chance']) {
98
+ expect(at(phrase)).toMatchObject({ kind: 'unscheduled' });
99
+ expect(at(phrase)?.dueAt).toBeUndefined();
100
+ }
101
+ });
102
+
103
+ it('returns null when nothing about time was said, and ignores the past', () => {
104
+ expect(at('check the backend and the UI updates')).toBeNull();
105
+ expect(at('we did two videos yesterday')).toBeNull();
106
+ expect(at('')).toBeNull();
107
+ });
108
+ });
109
+
110
+ describe('noteWideWhen: a plan for the day applies to everything under it', () => {
111
+ it.each([
112
+ 'All right, now on to work stuff for the day. I gotta check the backend.',
113
+ 'These are the things I need to do today.',
114
+ 'In terms of work goals for today, high level, I need to go through the API work.',
115
+ 'Um, in terms of my sole goals personally for the day, I wanna work on the bench.',
116
+ 'Looking to keep that today, and add stretching as a goal.',
117
+ ])('%s', (text) => {
118
+ expect(noteWideWhen(text, { now: NOW, timeZone: TZ })).toMatchObject({ kind: 'dated', date: '2026-11-06', confidence: 'inherited' });
119
+ });
120
+
121
+ it.each([
122
+ 'Someday I should learn to weld. Also call the dentist.',
123
+ 'We did two videos yesterday. Review the animated builder.',
124
+ 'Today is Friday and the weather is nice.',
125
+ ])('does not invent a day: %s', (text) => {
126
+ expect(noteWideWhen(text, { now: NOW, timeZone: TZ })).toBeNull();
127
+ });
128
+ });
@@ -0,0 +1,80 @@
1
+ // @vitest-environment node
2
+ /**
3
+ * REAL-MODEL eval of timing extraction (bd startsim-b7kir). Paid, so gated: `VOICE_DUE_EVAL=1`.
4
+ * Replays the three real transcripts through the real analyzer and the real finish pipeline.
5
+ * Keys come from the environment of this one command. Prints a table and one JSON line.
6
+ */
7
+ import { describe, expect, it } from 'vitest';
8
+
9
+ import { toSourceDocument } from '../corpus/entities';
10
+ import { rulesExtract } from '../corpus/extract';
11
+ import { openQuestions } from '../corpus/extraction-fields';
12
+ import { createVoiceAnalyzer } from '../corpus/llm';
13
+ import { finishVoiceNote, startVoiceNote } from '../corpus/voice';
14
+ import type { VoiceDeps } from '../corpus/voice';
15
+ import type { VoiceItemRecord } from '../corpus/voice-due';
16
+ import { QUINN_FOCUSES, QUINN_NOTES, QUINN_TZ } from './fixtures/voice-quinn-notes';
17
+
18
+ const enabled = process.env.VOICE_DUE_EVAL === '1';
19
+
20
+ /** What a person would say each to-do is due, by title keyword; everything else follows the note's day. */
21
+ const WANT: Record<string, Record<string, string>> = {
22
+ 'nov6-personal': { weekend: '2026-11-08', drinking: '2026-11-08', alcohol: '2026-11-08' },
23
+ };
24
+ const DAY: Record<string, string> = { 'nov6-work': '2026-11-06', 'nov6-personal': '2026-11-06', 'nov5-daily': '2026-11-05' };
25
+
26
+ /** What a careful person would list for the work note (keywords any one title must contain). */
27
+ const GOLD_WORK: string[][] = [
28
+ ['backend'], ['debug', 'ui'], ['debug', 'ui'], ['agent', 'ui'], ['agent', 'ui'], ['v2'], ['animated'],
29
+ ['video', 'article'], ['video', 'landing'], ['crochet', 'check'],
30
+ ];
31
+ const goldRecall = (titles: string[]): number => {
32
+ const pool = titles.map((t) => t.toLowerCase());
33
+ let hit = 0;
34
+ for (const keys of GOLD_WORK) {
35
+ const i = pool.findIndex((t) => keys.every((k) => t.includes(k)));
36
+ if (i >= 0) { hit++; pool.splice(i, 1); }
37
+ }
38
+ return hit;
39
+ };
40
+
41
+ describe.skipIf(!enabled)('timing extraction with the real model', () => {
42
+ it('dates the items the speaker meant for the day', async () => {
43
+ const analyzer = createVoiceAnalyzer();
44
+ const rows: Array<Record<string, unknown>> = [];
45
+ const workTitles: string[] = [];
46
+ let total = 0, dated = 0, right = 0, flagged = 0, withPriority = 0, withEstimate = 0, tokens = 0;
47
+ for (const note of QUINN_NOTES) {
48
+ const posts: Array<{ data: Record<string, unknown> }> = [];
49
+ const deps: VoiceDeps = {
50
+ http: { get: async () => ({}) as never, post: async (_p: string, b?: unknown) => { posts.push(b as never); return { id: 'r' } as never; } },
51
+ transcriber: { transcribe: async () => note.transcript },
52
+ analyzer, store: { put: async () => 's3://x' }, listFocuses: async () => QUINN_FOCUSES, now: () => new Date(note.recordedAt),
53
+ };
54
+ const sub = { noteId: note.id, audio: new Uint8Array([1]), mimeType: 'audio/m4a', timeZone: QUINN_TZ };
55
+ await finishVoiceNote(await startVoiceNote(sub, deps), sub, deps);
56
+ const ready = posts.filter((p) => p.data?.voice_status === 'ready').at(-1)!.data;
57
+ tokens += Number((ready.voice_usage as Record<string, number>)?.tokens_in ?? 0) + Number((ready.voice_usage as Record<string, number>)?.tokens_out ?? 0);
58
+ const doc = toSourceDocument({ id: note.id, name: note.id, data: { source: 'voice', title: 't', summary: ready.summary, body: note.transcript } } as never, { orgId: 'o' } as never);
59
+ const drafts = rulesExtract(doc);
60
+ const records = JSON.parse(String(ready.voice_items ?? '[]')) as VoiceItemRecord[];
61
+ for (const d of drafts) {
62
+ if (note.id === 'nov6-work') workTitles.push(d.title);
63
+ total++;
64
+ const want = Object.entries(WANT[note.id] ?? {}).find(([k]) => d.title.toLowerCase().includes(k))?.[1] ?? DAY[note.id];
65
+ if (d.dueAt) dated++;
66
+ if (d.dueAt?.slice(0, 10) === want) right++;
67
+ if (d.priority !== undefined) withPriority++;
68
+ if (d.estimateMinutes) withEstimate++;
69
+ rows.push({ note: note.id, title: d.title, due: d.dueAt ?? '-', want, est: d.estimateMinutes ?? '-', pri: d.priority ?? '-' });
70
+ }
71
+ for (const r of records) if (!r.fields.due.value) console.log('UNDATED', note.id, '|', r.title, '|', r.fields.due.reason);
72
+ flagged += records.filter((r) => openQuestions(r.fields).length).length;
73
+ console.log(note.id, 'questions:', JSON.stringify(records.flatMap((r) => openQuestions(r.fields).map((q) => `${r.title}: ${q.question}`))));
74
+ }
75
+ console.table(rows);
76
+ console.log('GOLD_WORK_RECALL', goldRecall(workTitles), '/', GOLD_WORK.length);
77
+ console.log(JSON.stringify({ items: total, dated, right, flagged, withPriority, withEstimate, tokens }));
78
+ expect(total).toBeGreaterThan(0);
79
+ }, 180_000);
80
+ });
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Quinn's real notes, replayed through finish -> extract -> Today
3
+ * (bd startsim-b7kir). The model reply is the production one, which carries no
4
+ * timing at all: everything below comes from the deterministic resolver.
5
+ */
6
+ import { describe, expect, it } from 'vitest';
7
+
8
+ import { toSourceDocument } from '../corpus/entities';
9
+ import { rulesExtract } from '../corpus/extract';
10
+ import { parseVoiceAnalysis } from '../corpus/llm';
11
+ import { selectToday } from '../corpus/today';
12
+ import { openQuestions } from '../corpus/extraction-fields';
13
+ import type { ItemFields } from '../corpus/extraction-fields';
14
+ import { finishVoiceNote, startVoiceNote } from '../corpus/voice';
15
+ import type { VoiceAnalysis, VoiceDeps } from '../corpus/voice';
16
+ import type { VoiceItemRecord } from '../corpus/voice-due';
17
+ import { QUINN_FOCUSES, QUINN_NOTES, QUINN_TZ } from './fixtures/voice-quinn-notes';
18
+ import type { ReplayNote } from './fixtures/voice-quinn-notes';
19
+
20
+ interface Replayed { summary: string; body: string; items: VoiceItemRecord[]; drafts: ReturnType<typeof rulesExtract> }
21
+
22
+ /** Runs the note through the real pipeline with the model replaced by its recorded reply. */
23
+ async function replay(note: ReplayNote, reply: unknown = note.reply, timeZone = QUINN_TZ): Promise<Replayed> {
24
+ const rows: Array<{ data: Record<string, unknown> }> = [];
25
+ const deps: VoiceDeps = {
26
+ http: { get: async () => ({}) as never, post: async (_path: string, body?: unknown) => { rows.push(body as never); return { id: 'row-1' } as never; } },
27
+ transcriber: { transcribe: async () => note.transcript },
28
+ analyzer: { analyze: async (input): Promise<VoiceAnalysis> => parseVoiceAnalysis(JSON.stringify(reply), input.focuses)! },
29
+ store: { put: async () => 's3://x' },
30
+ listFocuses: async () => QUINN_FOCUSES,
31
+ now: () => new Date(note.recordedAt),
32
+ };
33
+ const submission = { noteId: note.id, audio: new Uint8Array([1]), mimeType: 'audio/m4a', timeZone };
34
+ const started = await startVoiceNote(submission, deps);
35
+ await finishVoiceNote(started, submission, deps);
36
+ const ready = rows.filter((r) => r.data?.voice_status === 'ready').at(-1)!.data;
37
+ const summary = String(ready.summary);
38
+ const doc = toSourceDocument(
39
+ { id: note.id, name: note.id, data: { source: 'voice', title: 't', summary, body: note.transcript, occurred_at: note.recordedAt } } as never,
40
+ { orgId: 'o' } as never,
41
+ );
42
+ return {
43
+ summary, body: note.transcript, drafts: rulesExtract(doc),
44
+ items: JSON.parse(String(ready.voice_items ?? '[]')) as VoiceItemRecord[],
45
+ };
46
+ }
47
+
48
+ const byTitle = (r: Replayed, part: string) => {
49
+ const d = r.drafts.find((x) => x.title.toLowerCase().includes(part.toLowerCase()));
50
+ if (!d) throw new Error(`no draft with "${part}": ${r.drafts.map((x) => x.title).join(' | ')}`);
51
+ return d;
52
+ };
53
+ const [WORK, PERSONAL, NOV5] = QUINN_NOTES;
54
+
55
+ describe('Nov 6 work note: "work stuff for the day"', () => {
56
+ it('gives every to-do a due date of that day, marked as assumed from the plan', async () => {
57
+ const r = await replay(WORK);
58
+ expect(r.drafts).toHaveLength(8);
59
+ for (const d of r.drafts) expect(d.dueAt, d.title).toBe('2026-11-06');
60
+ expect(byTitle(r, 'debug AI backend').dueBasis).toMatch(/assumed/);
61
+ expect(byTitle(r, 'debug AI backend').dueConfidence).toBeLessThan(0.8);
62
+ });
63
+
64
+ it('keeps what the speaker said about the item over the note-wide plan', async () => {
65
+ const r = await replay(WORK);
66
+ const videos = r.items.find((i) => i.title.includes('landing pages'))!.fields;
67
+ expect(videos.due.source).toBe('stated'); // "I'd like to do at least two more today"
68
+ });
69
+
70
+ it('"two sessions of 15 minutes" is one item of 30 minutes (the tracker cannot tell sessions apart)', async () => {
71
+ const r = await replay(WORK);
72
+ const sessions = r.drafts.filter((d) => /sessions of 15 minutes/.test(d.title));
73
+ expect(sessions).toHaveLength(2);
74
+ expect(sessions.every((d) => d.estimateMinutes === 30)).toBe(true);
75
+ expect(byTitle(r, 'quick check').estimateMinutes).toBeUndefined();
76
+ });
77
+
78
+ it('does not carry the whole transcript into the last item', async () => {
79
+ const r = await replay(WORK);
80
+ for (const d of r.drafts) expect(d.detail.length, d.title).toBeLessThan(200);
81
+ });
82
+
83
+ it('is not silent about the one genuine doubt: is Quinn AI personal or work?', async () => {
84
+ const r = await replay(WORK);
85
+ const quinn = r.items.find((i) => i.section === 'Quinn AI')!.fields;
86
+ expect(quinn.project.question).toMatch(/personal or work/i);
87
+ expect(quinn.project.candidates.map((c) => c.value)).toEqual(['personal', 'work']);
88
+ expect(r.items.filter((i) => openQuestions(i.fields).length)).toHaveLength(1);
89
+ });
90
+
91
+ it('shows up in Today and in the briefing selector', async () => {
92
+ const r = await replay(WORK);
93
+ const today = selectToday(r.drafts.map((d) => ({ status: 'open', dueAt: d.dueAt, title: d.title })), { now: Date.parse(WORK.recordedAt), timeZone: QUINN_TZ });
94
+ expect(today).toHaveLength(8);
95
+ expect(today.every((e) => e.kind === 'due_today')).toBe(true);
96
+ // The evening of the same day is still today for Quinn, though UTC has rolled over.
97
+ const evening = selectToday(r.drafts.map((d) => ({ status: 'open', dueAt: d.dueAt })), { now: Date.parse('2026-11-07T03:00:00Z'), timeZone: QUINN_TZ });
98
+ expect(evening).toHaveLength(8);
99
+ });
100
+ });
101
+
102
+ describe('Nov 6 personal note', () => {
103
+ it('"this weekend" is Sunday and "today" is today', async () => {
104
+ const r = await replay(PERSONAL);
105
+ expect(byTitle(r, 'alcohol').dueAt).toBe('2026-11-08');
106
+ expect(byTitle(r, 'stretching').dueAt).toBe('2026-11-06');
107
+ });
108
+
109
+ it('files the personal section as personal with confidence', async () => {
110
+ const r = await replay(PERSONAL);
111
+ expect(r.items[0].fields.project).toMatchObject({ value: 'personal', source: 'stated' });
112
+ });
113
+ });
114
+
115
+ describe('Nov 5 note: "goals for the day"', () => {
116
+ it('every to-do is due that day, in the zone it was said in', async () => {
117
+ const r = await replay(NOV5);
118
+ expect(r.drafts).toHaveLength(12);
119
+ for (const d of r.drafts) expect(d.dueAt, d.title).toBe('2026-11-05');
120
+ });
121
+
122
+ it('"sometime in the next few hours" is today, stated', async () => {
123
+ const r = await replay(NOV5);
124
+ const f = r.items.find((i) => i.title.includes('intention'))!.fields;
125
+ expect(f.due.value).toBe('2026-11-05');
126
+ expect(f.due.source).toBe('stated');
127
+ });
128
+ });
129
+
130
+ describe('unscheduled stays unscheduled', () => {
131
+ const note = (transcript: string, items: Array<Record<string, unknown>>, extra: Record<string, unknown> = {}): ReplayNote => ({
132
+ id: 'u', recordedAt: '2026-11-06T15:37:26.791Z', transcript,
133
+ reply: { title: 'T', summary: 'S', sections: [{ label: 'Personal', kind: 'personal', focusId: null, summary: '', items, ...extra }] } as never,
134
+ });
135
+
136
+ it('a note with no time words gets no dates', async () => {
137
+ const r = await replay(note('Someday I should learn to weld. Also I need to call the dentist about the cleaning.',
138
+ [{ title: 'Learn to weld properly' }, { title: 'Call the dentist about cleaning' }]));
139
+ expect(r.drafts.map((d) => d.dueAt)).toEqual([undefined, undefined]);
140
+ expect(r.items.every((i) => i.fields.due.value === null)).toBe(true);
141
+ });
142
+
143
+ it('"sometime" opts an item out of the plan for the day', async () => {
144
+ const r = await replay(note('These are the things I need to do today. Fix the kitchen sink. Sometime I should repaint the shed.',
145
+ [{ title: 'Fix the kitchen sink' }, { title: 'Repaint the shed', when: 'sometime' }]));
146
+ expect(byTitle(r, 'sink').dueAt).toBe('2026-11-06');
147
+ expect(byTitle(r, 'shed').dueAt).toBeUndefined();
148
+ });
149
+
150
+ it('the sentence an item came from can opt it out without any model help', async () => {
151
+ const r = await replay(note('These are the things I need to do today. Fix the kitchen sink. Sometime I should repaint the garden shed.',
152
+ [{ title: 'Fix the kitchen sink' }, { title: 'Repaint the garden shed' }]));
153
+ expect(byTitle(r, 'shed').dueAt).toBeUndefined();
154
+ expect(r.items.find((i) => i.title.includes('shed'))!.fields.due.reason).toMatch(/left open/);
155
+ });
156
+ });
157
+
158
+ describe('model-reported timing is resolved in code', () => {
159
+ const withWhen = (items: Array<Record<string, unknown>>, section: Record<string, unknown> = {}): ReplayNote => ({
160
+ id: 'w', recordedAt: '2026-11-06T15:37:26.791Z', transcript: 'Call the bank by Friday. Send the invoice before the call at 2.',
161
+ reply: { title: 'T', summary: 'S', sections: [{ label: 'Work', kind: 'other', focusId: null, summary: '', items, ...section }] } as never,
162
+ });
163
+
164
+ it('turns "before the call at 2" into an instant in the speaker\'s zone', async () => {
165
+ const r = await replay(withWhen([{ title: 'Send the invoice to Malin', when: 'before the call at 2' }]));
166
+ expect(r.drafts[0].dueAt).toBe(new Date('2026-11-06T14:00:00-07:00').toISOString());
167
+ });
168
+
169
+ it('never trusts a date the model wrote itself', async () => {
170
+ const r = await replay(withWhen([{ title: 'Renew the library card', when: '1999-01-01' }]));
171
+ expect(r.drafts[0].dueAt).toBeUndefined();
172
+ });
173
+
174
+ it('carries priority and an explicit estimate', async () => {
175
+ const r = await replay(withWhen([{ title: 'Call the bank about the wire', when: 'ASAP', priority: 'high', estimateMinutes: 20 }]));
176
+ expect(r.drafts[0]).toMatchObject({ dueAt: '2026-11-06', priority: 1, estimateMinutes: 20 });
177
+ });
178
+
179
+ it('asks about "Friday" said on a Friday instead of guessing silently', async () => {
180
+ const r = await replay(withWhen([{ title: 'Call the bank about the wire', when: 'by Friday' }]));
181
+ const due = r.items[0].fields.due;
182
+ expect(due.value).toBe('2026-11-06');
183
+ expect(due.question).toMatch(/2026-11-06 or 2026-11-13/);
184
+ expect(due.candidates).toHaveLength(2);
185
+ });
186
+ });
187
+
188
+ describe('measure: how many items are flagged', () => {
189
+ it('flags 1 of 22 items across the three real notes, and only for a genuine ambiguity', async () => {
190
+ const all = await Promise.all(QUINN_NOTES.map((n) => replay(n)));
191
+ const items = all.flatMap((r) => r.items);
192
+ const flagged = items.filter((i) => openQuestions(i.fields as ItemFields).length);
193
+ expect(items).toHaveLength(22);
194
+ expect(flagged.map((i) => i.title)).toEqual(['Review and provide feedback on animated video builder']);
195
+ const dated = items.filter((i) => i.fields.due.value);
196
+ expect(dated).toHaveLength(22);
197
+ });
198
+ });
199
+
200
+ describe('the model call carries the clock', () => {
201
+ it('shows the model when the speaker is talking, and keeps what it quoted', async () => {
202
+ const { renderVoicePrompt, voiceSystemPrompt } = await import('../corpus/llm');
203
+ const prompt = renderVoicePrompt({ transcript: 'hi', focuses: [], now: Date.parse(WORK.recordedAt), timeZone: QUINN_TZ });
204
+ expect(prompt).toContain('RECORDED_AT: Friday, November 6, 2026 at 8:37 AM (America/Boise)');
205
+ expect(voiceSystemPrompt()).toMatch(/never a date/);
206
+ const parsed = parseVoiceAnalysis(JSON.stringify({
207
+ title: 'T', summary: 'S', when: 'today',
208
+ sections: [{ label: 'L', kind: 'other', focusId: null, summary: '', when: 'this week', items: [{ title: 'Do the thing now', when: 'tonight', priority: 'urgent', estimateMinutes: 45 }] }],
209
+ }), [])!;
210
+ expect(parsed.noteWhen).toBe('today');
211
+ expect(parsed.sections![0].when).toBe('this week');
212
+ expect(parsed.sections![0].items[0]).toMatchObject({ when: 'tonight', priority: 1, estimateMinutes: 45 });
213
+ });
214
+
215
+ it('survives a bad time zone from a client', async () => {
216
+ const r = await replay(NOV5, NOV5.reply, 'Mars/Olympus');
217
+ expect(r.drafts.every((d) => d.dueAt === '2026-11-05')).toBe(true);
218
+ });
219
+ });
@@ -285,7 +285,13 @@ export function reconcile(
285
285
  // already recorded. A person ticking something off on the screen must
286
286
  // survive the next run, or the screen is a suggestion box.
287
287
  if (!match.ownerName && lead.ownerName) match.ownerName = lead.ownerName;
288
- if (!match.dueAt && lead.dueAt) match.dueAt = lead.dueAt;
288
+ if (!match.dueAt && lead.dueAt) {
289
+ match.dueAt = lead.dueAt;
290
+ if (lead.dueBasis) match.dueBasis = lead.dueBasis;
291
+ if (lead.dueConfidence !== undefined) match.dueConfidence = lead.dueConfidence;
292
+ }
293
+ if (match.priority === undefined && lead.priority !== undefined) match.priority = lead.priority;
294
+ if (match.estimateMinutes === undefined && lead.estimateMinutes !== undefined) match.estimateMinutes = lead.estimateMinutes;
289
295
  if (!match.detail && lead.detail) match.detail = lead.detail;
290
296
  // Only a row that ACTUALLY changed is written. Marking every match dirty
291
297
  // would make a repeat run rewrite the corpus for no reason, which is the
@@ -310,6 +316,10 @@ export function reconcile(
310
316
  subjectKey: group.identity.subjectKey,
311
317
  actionKey: group.identity.actionKey,
312
318
  ...(lead.dueAt ? { dueAt: lead.dueAt } : {}),
319
+ ...(lead.dueAt && lead.dueBasis ? { dueBasis: lead.dueBasis } : {}),
320
+ ...(lead.dueAt && lead.dueConfidence !== undefined ? { dueConfidence: lead.dueConfidence } : {}),
321
+ ...(lead.priority !== undefined ? { priority: lead.priority } : {}),
322
+ ...(lead.estimateMinutes !== undefined ? { estimateMinutes: lead.estimateMinutes } : {}),
313
323
  mentions: [],
314
324
  firstSeenAt: null,
315
325
  lastSeenAt: null,
@@ -361,6 +371,8 @@ function signature(commitment: Commitment): string {
361
371
  commitment.statusReason ?? '',
362
372
  commitment.ownerName ?? '',
363
373
  commitment.dueAt ?? '',
374
+ commitment.priority ?? '',
375
+ commitment.estimateMinutes ?? '',
364
376
  commitment.resolvedBy ?? '',
365
377
  commitment.firstSeenAt ?? '',
366
378
  commitment.lastSeenAt ?? '',
@@ -729,6 +729,11 @@ export function toCommitment(
729
729
  dueAt: asIso(pick(data, 'due_at', 'dueAt')),
730
730
  ...(asNumber(pick(data, 'priority')) !== undefined
731
731
  ? { priority: asNumber(pick(data, 'priority')) } : {}),
732
+ ...(asNumber(pick(data, 'estimate_minutes', 'estimateMinutes')) !== undefined
733
+ ? { estimateMinutes: asNumber(pick(data, 'estimate_minutes', 'estimateMinutes')) } : {}),
734
+ ...(pick(data, 'due_basis', 'dueBasis') ? { dueBasis: asText(pick(data, 'due_basis', 'dueBasis')) } : {}),
735
+ ...(asNumber(pick(data, 'due_confidence', 'dueConfidence')) !== undefined
736
+ ? { dueConfidence: asNumber(pick(data, 'due_confidence', 'dueConfidence')) } : {}),
732
737
  ...(pick(data, 'owner_sub', 'ownerSub')
733
738
  ? { ownerSub: asText(pick(data, 'owner_sub', 'ownerSub')) } : {}),
734
739
  // Both spellings, for the reason spelled out on ORIGIN_KEY above: the
@@ -803,6 +808,9 @@ export function commitmentToEntity(commitment: Commitment): {
803
808
  dedupe_key: commitment.dedupeKey,
804
809
  ...(commitment.dueAt ? { due_at: commitment.dueAt } : {}),
805
810
  ...(commitment.priority !== undefined ? { priority: commitment.priority } : {}),
811
+ ...(commitment.estimateMinutes !== undefined ? { estimate_minutes: commitment.estimateMinutes } : {}),
812
+ ...(commitment.dueBasis ? { due_basis: commitment.dueBasis } : {}),
813
+ ...(commitment.dueConfidence !== undefined ? { due_confidence: commitment.dueConfidence } : {}),
806
814
  ...(commitment.ownerSub ? { owner_sub: commitment.ownerSub } : {}),
807
815
  ...(commitment.destination ? { destination: commitment.destination } : {}),
808
816
  ...(commitment.externalFocusId ? { external_focus_id: commitment.externalFocusId } : {}),
@@ -44,6 +44,8 @@
44
44
  import { applyDecisions, buildClassifyRequest, candidatesFromFocuses } from './classify';
45
45
  import { EXTRACTOR_VERSION, applyResolutions, mergeDrafts, reconcile } from './commitments';
46
46
  import { enforceScope } from './retrieval';
47
+ import { META_LINE, parseItemMeta } from './extraction-fields';
48
+ import type { ItemMeta } from './extraction-fields';
47
49
  import { documentText, outcomeSections, documentParts, splitSections, words } from './text';
48
50
  import type {
49
51
  Commitment,
@@ -163,10 +165,11 @@ export function rulesExtract(document: SourceDocument): CommitmentDraft[] {
163
165
 
164
166
  const drafts: CommitmentDraft[] = [];
165
167
  for (const section of voice ? splitSections(text).filter((s) => s.heading) : outcomeSections(text)) {
166
- let current: { line: string; detail: string[] } | null = null;
168
+ let current: { line: string; detail: string[]; meta?: ItemMeta } | null = null;
167
169
  const flush = () => {
168
170
  if (!current) return;
169
171
  const draft = toDraft(document, current.line, current.detail.join('\n'));
172
+ if (draft && current.meta) applyMeta(draft, current.meta);
170
173
  if (draft) {
171
174
  // The heading is kept on the mention as presentation. It is NOT a project
172
175
  // guess: which project an item is for is classified per item (./classify).
@@ -179,6 +182,14 @@ export function rulesExtract(document: SourceDocument): CommitmentDraft[] {
179
182
  if (bullet) {
180
183
  flush();
181
184
  current = { line: line.trim(), detail: [] };
185
+ } else if (current && META_LINE.test(line)) {
186
+ // The resolved due date / priority / estimate under a voice bullet (./extraction-fields).
187
+ const meta = parseItemMeta(line);
188
+ if (meta) current.meta = { ...current.meta, ...meta };
189
+ } else if (voice && current && !line.trim()) {
190
+ // A voice summary ends an item at the blank line. Without this the LAST bullet swallowed the
191
+ // transcript that follows the summary as its "detail" (seen on both real notes).
192
+ flush();
182
193
  } else if (current && line.trim()) {
183
194
  current.detail.push(line.trim());
184
195
  }
@@ -188,6 +199,14 @@ export function rulesExtract(document: SourceDocument): CommitmentDraft[] {
188
199
  return drafts;
189
200
  }
190
201
 
202
+ function applyMeta(draft: CommitmentDraft, meta: ItemMeta): void {
203
+ if (meta.dueAt) draft.dueAt = meta.dueAt;
204
+ if (meta.dueBasis) draft.dueBasis = meta.dueBasis;
205
+ if (meta.dueConfidence !== undefined) draft.dueConfidence = meta.dueConfidence;
206
+ if (meta.priority !== undefined) draft.priority = meta.priority;
207
+ if (meta.estimateMinutes !== undefined) draft.estimateMinutes = meta.estimateMinutes;
208
+ }
209
+
191
210
  function toDraft(document: SourceDocument, line: string, detail: string): CommitmentDraft | null {
192
211
  const content = line.replace(BULLET, '$1').trim();
193
212
  const bold = LEADING_BOLD.exec(content);