@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.
- package/package.json +6 -6
- package/src/__tests__/briefing-weekly.test.ts +80 -0
- package/src/__tests__/corpus-ask-items.test.ts +108 -0
- package/src/__tests__/corpus-planning.test.tsx +31 -0
- package/src/__tests__/home-brief.test.tsx +10 -0
- package/src/__tests__/home-needs-your-call.test.tsx +68 -0
- package/src/__tests__/measure/notes.ts +28 -0
- package/src/__tests__/measure/voice-notes.measure.test.ts +51 -0
- package/src/__tests__/needs-your-call.test.tsx +151 -0
- package/src/__tests__/question-evidence.test.ts +82 -0
- package/src/__tests__/question-inbox.test.ts +51 -0
- package/src/__tests__/question-voice.test.ts +18 -0
- package/src/components/index.ts +1 -0
- package/src/components/pages/AskPage.tsx +12 -2
- package/src/components/pages/PlanningPage.tsx +14 -4
- package/src/components/pages/home/BriefCard.tsx +31 -12
- package/src/components/pages/home/CompactItemRow.tsx +12 -2
- package/src/components/pages/home/DueAcrossProjects.tsx +4 -2
- package/src/components/pages/home/HomeBriefPage.tsx +32 -3
- package/src/components/pages/questions/NeedsYourCall.tsx +128 -0
- package/src/components/pages/questions/QuestionRow.tsx +78 -0
- package/src/components/pages/questions/index.ts +3 -0
- package/src/components/pages/questions/types.ts +36 -0
- package/src/corpus/ask-items-intent.ts +75 -0
- package/src/corpus/ask-items.ts +100 -0
- package/src/corpus/ask.ts +48 -5
- package/src/corpus/briefing/generate-weekly.ts +89 -0
- package/src/corpus/briefing/index.ts +5 -1
- package/src/corpus/briefing/respond.ts +11 -3
- package/src/corpus/briefing/types.ts +2 -0
- package/src/corpus/briefing/weekly.ts +155 -0
- package/src/corpus/index.ts +3 -0
- package/src/corpus/llm.ts +3 -2
- package/src/corpus/questions/evidence.ts +65 -0
- package/src/corpus/questions/inbox.ts +108 -0
- package/src/corpus/questions/index.ts +6 -1
- package/src/corpus/questions/items.ts +21 -0
- package/src/corpus/questions/learn.ts +16 -0
- package/src/corpus/questions/sync.ts +7 -3
- package/src/corpus/questions/types.ts +5 -1
- package/src/corpus/questions/voice.ts +23 -4
- package/src/corpus/types.ts +4 -0
- package/src/corpus/voice.ts +5 -2
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE WEEKLY SUMMARY (bd startsim-tmrvi): what got done, what is slipping and
|
|
3
|
+
* what is due in the coming week, for ONE person, spoken in the app.
|
|
4
|
+
*
|
|
5
|
+
* Built from the briefing's own parts: the same `BriefingItem` input, the same
|
|
6
|
+
* ownership and finished-state rules as `composeBriefing`, the same spoken-form
|
|
7
|
+
* helpers, the same store and delivery path (`generateWeekly`). PURE, like the
|
|
8
|
+
* composer: the caller passes `now` and the reader's zone.
|
|
9
|
+
*
|
|
10
|
+
* It is composed per OWNER and nothing here addresses anyone else: there is no
|
|
11
|
+
* recipient list, no email and no push, only a row the owner's own session reads.
|
|
12
|
+
*/
|
|
13
|
+
import { dueDay, localDate } from '../today';
|
|
14
|
+
import { isUnspeakable, partOfDay, speakCount, speakDate, speakable, wordCount } from './speak';
|
|
15
|
+
import type { BriefingItem } from './types';
|
|
16
|
+
|
|
17
|
+
export type WeeklyKind = 'done' | 'slipping' | 'upcoming';
|
|
18
|
+
|
|
19
|
+
export interface WeeklyEntry {
|
|
20
|
+
id: string;
|
|
21
|
+
title: string;
|
|
22
|
+
kind: WeeklyKind;
|
|
23
|
+
/** Project name, or `Personal`. */
|
|
24
|
+
group: string;
|
|
25
|
+
dueDate: string | null;
|
|
26
|
+
doneDate?: string | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface WeeklySummary {
|
|
30
|
+
done: WeeklyEntry[];
|
|
31
|
+
slipping: WeeklyEntry[];
|
|
32
|
+
upcoming: WeeklyEntry[];
|
|
33
|
+
counts: Record<WeeklyKind, number>;
|
|
34
|
+
empty: boolean;
|
|
35
|
+
/** First day (inclusive) of the look-back, today, and last day of the look-ahead. */
|
|
36
|
+
window: { from: string; today: string; to: string; timeZone: string };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface WeeklyOptions {
|
|
40
|
+
ownerSub: string;
|
|
41
|
+
now: number;
|
|
42
|
+
timeZone?: string;
|
|
43
|
+
/** Days back for "done" and ahead for "upcoming". Default 7. */
|
|
44
|
+
days?: number;
|
|
45
|
+
/** Entries kept per section. Default 8. */
|
|
46
|
+
perSection?: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const FINISHED = new Set(['done', 'dropped']);
|
|
50
|
+
const LINEAR_FINISHED = new Set(['completed', 'canceled', 'cancelled']);
|
|
51
|
+
|
|
52
|
+
const addDays = (day: string, n: number): string => {
|
|
53
|
+
const d = new Date(`${day}T00:00:00Z`);
|
|
54
|
+
d.setUTCDate(d.getUTCDate() + n);
|
|
55
|
+
return d.toISOString().slice(0, 10);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export function composeWeekly(items: BriefingItem[], options: WeeklyOptions): WeeklySummary {
|
|
59
|
+
const timeZone = options.timeZone ?? 'UTC';
|
|
60
|
+
const days = options.days ?? 7;
|
|
61
|
+
const max = options.perSection ?? 8;
|
|
62
|
+
const today = localDate(options.now, timeZone);
|
|
63
|
+
const from = addDays(today, -days);
|
|
64
|
+
const to = addDays(today, days);
|
|
65
|
+
const buckets: Record<WeeklyKind, WeeklyEntry[]> = { done: [], slipping: [], upcoming: [] };
|
|
66
|
+
const counts: Record<WeeklyKind, number> = { done: 0, slipping: 0, upcoming: 0 };
|
|
67
|
+
|
|
68
|
+
for (const item of items) {
|
|
69
|
+
if (!item.ownerSub || item.ownerSub !== options.ownerSub) continue;
|
|
70
|
+
const due = dueDay(item.dueAt, timeZone);
|
|
71
|
+
const group = item.focusName?.trim() || 'Personal';
|
|
72
|
+
const linearDone = Boolean(item.linearState && LINEAR_FINISHED.has(item.linearState.toLowerCase()));
|
|
73
|
+
let kind: WeeklyKind | null = null;
|
|
74
|
+
let doneDate: string | null = null;
|
|
75
|
+
if (item.status === 'done' || linearDone) {
|
|
76
|
+
doneDate = dueDay(item.resolvedAt, timeZone);
|
|
77
|
+
// "Done" counts only when we know WHEN: a done item with no timestamp is not evidence of this week.
|
|
78
|
+
if (doneDate && doneDate >= from && doneDate <= today) kind = 'done';
|
|
79
|
+
} else if (!FINISHED.has(item.status)) {
|
|
80
|
+
if (due && due < today) kind = 'slipping';
|
|
81
|
+
else if (item.status === 'blocked' && !due) kind = 'slipping';
|
|
82
|
+
else if (due && due >= today && due <= to) kind = 'upcoming';
|
|
83
|
+
}
|
|
84
|
+
if (!kind) continue;
|
|
85
|
+
counts[kind] += 1;
|
|
86
|
+
buckets[kind].push({ id: item.id, title: item.title, kind, group, dueDate: due, ...(doneDate ? { doneDate } : {}) });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const byDue = (a: WeeklyEntry, b: WeeklyEntry) => (a.dueDate ?? '9999').localeCompare(b.dueDate ?? '9999');
|
|
90
|
+
buckets.slipping.sort(byDue);
|
|
91
|
+
buckets.upcoming.sort(byDue);
|
|
92
|
+
buckets.done.sort((a, b) => (b.doneDate ?? '').localeCompare(a.doneDate ?? ''));
|
|
93
|
+
return {
|
|
94
|
+
done: buckets.done.slice(0, max),
|
|
95
|
+
slipping: buckets.slipping.slice(0, max),
|
|
96
|
+
upcoming: buckets.upcoming.slice(0, max),
|
|
97
|
+
counts,
|
|
98
|
+
empty: counts.done + counts.slipping + counts.upcoming === 0,
|
|
99
|
+
window: { from, today, to, timeZone },
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// -- the spoken script --------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
export interface WeeklyScriptOptions {
|
|
106
|
+
now: number;
|
|
107
|
+
timeZone?: string;
|
|
108
|
+
name?: string;
|
|
109
|
+
/** Items named per section before "and N more". Default 4. */
|
|
110
|
+
named?: number;
|
|
111
|
+
/** Word budget. Default 260. */
|
|
112
|
+
maxWords?: number;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface WeeklyScript { text: string; words: number; source: 'template' }
|
|
116
|
+
|
|
117
|
+
const title = (e: WeeklyEntry) => speakable(e.title) || 'an untitled item';
|
|
118
|
+
const list = (parts: string[]) => (parts.length < 2 ? parts.join('') : `${parts.slice(0, -1).join(', ')}, and ${parts[parts.length - 1]}`);
|
|
119
|
+
const cap = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
120
|
+
const noun = (n: number) => (n === 1 ? 'item' : 'items');
|
|
121
|
+
|
|
122
|
+
/** Deterministic wording: nothing a model could invent, nothing unspeakable. */
|
|
123
|
+
export function weeklyScript(summary: WeeklySummary, options: WeeklyScriptOptions): WeeklyScript {
|
|
124
|
+
const zone = options.timeZone ?? 'UTC';
|
|
125
|
+
const part = partOfDay(options.now, zone);
|
|
126
|
+
const named = options.named ?? 4;
|
|
127
|
+
const today = summary.window.today;
|
|
128
|
+
const sentences: string[] = [options.name ? `Good ${part}, ${options.name}. Here is your week.` : `Good ${part}. Here is your week.`];
|
|
129
|
+
if (summary.empty) {
|
|
130
|
+
sentences.push('Nothing was finished, nothing is slipping and nothing is due in the coming week.');
|
|
131
|
+
} else {
|
|
132
|
+
const { counts } = summary;
|
|
133
|
+
if (counts.done) {
|
|
134
|
+
const shown = summary.done.slice(0, named).map(title);
|
|
135
|
+
const more = counts.done - shown.length;
|
|
136
|
+
sentences.push(`You finished ${speakCount(counts.done)} ${noun(counts.done)} this past week: ${list(shown)}${more > 0 ? `, and ${speakCount(more)} more` : ''}.`);
|
|
137
|
+
} else sentences.push('Nothing was marked done this past week.');
|
|
138
|
+
if (counts.slipping) {
|
|
139
|
+
const shown = summary.slipping.slice(0, named).map((e) => `${title(e)}${e.dueDate ? `, due ${speakDate(e.dueDate, today)}` : ', blocked'}`);
|
|
140
|
+
const more = counts.slipping - shown.length;
|
|
141
|
+
sentences.push(`${cap(speakCount(counts.slipping))} ${noun(counts.slipping)} ${counts.slipping === 1 ? 'is' : 'are'} slipping: ${list(shown)}${more > 0 ? `, and ${speakCount(more)} more` : ''}.`);
|
|
142
|
+
} else sentences.push('Nothing is slipping.');
|
|
143
|
+
if (counts.upcoming) {
|
|
144
|
+
const shown = summary.upcoming.slice(0, named).map((e) => `${title(e)}, ${e.dueDate ? speakDate(e.dueDate, today) : ''}`.replace(/, $/, ''));
|
|
145
|
+
const more = counts.upcoming - shown.length;
|
|
146
|
+
sentences.push(`Coming up in the next week: ${list(shown)}${more > 0 ? `, and ${speakCount(more)} more` : ''}.`);
|
|
147
|
+
} else sentences.push('Nothing is due in the coming week.');
|
|
148
|
+
}
|
|
149
|
+
let text = sentences.join(' ');
|
|
150
|
+
const budget = options.maxWords ?? 260;
|
|
151
|
+
if (wordCount(text) > budget && (options.named ?? 4) > 1) return weeklyScript(summary, { ...options, named: named - 1 });
|
|
152
|
+
// A title that slipped past `speakable` must not reach the voice.
|
|
153
|
+
if (isUnspeakable(text)) text = text.replace(/\b\d{4}-\d{2}-\d{2}\b/g, 'a date');
|
|
154
|
+
return { text, words: wordCount(text), source: 'template' };
|
|
155
|
+
}
|
package/src/corpus/index.ts
CHANGED
|
@@ -109,6 +109,9 @@ export {
|
|
|
109
109
|
resolveCitations,
|
|
110
110
|
} from './ask';
|
|
111
111
|
export type { AskCorpusOptions } from './ask';
|
|
112
|
+
export { itemAsDocument, selectItems, retrieveItems, ITEM_ID_PREFIX, ITEM_SUBTYPE, itemIdOf } from './ask-items';
|
|
113
|
+
export { itemIntent } from './ask-items-intent';
|
|
114
|
+
export type { ItemIntent, ItemFocus } from './ask-items-intent';
|
|
112
115
|
|
|
113
116
|
// Extraction — conversations in, trackable commitments out (bd startsim-768w.38.25).
|
|
114
117
|
export {
|
package/src/corpus/llm.ts
CHANGED
|
@@ -570,7 +570,7 @@ function freshNonce(): string {
|
|
|
570
570
|
}
|
|
571
571
|
|
|
572
572
|
export function renderVoicePrompt(
|
|
573
|
-
input: { transcript: string; focuses: FocusChoice[]; now?: number; timeZone?: string },
|
|
573
|
+
input: { transcript: string; focuses: FocusChoice[]; now?: number; timeZone?: string; habits?: string[] },
|
|
574
574
|
nonce: () => string = freshNonce,
|
|
575
575
|
): string {
|
|
576
576
|
const list = input.focuses.length
|
|
@@ -582,7 +582,8 @@ export function renderVoicePrompt(
|
|
|
582
582
|
const code = nonce();
|
|
583
583
|
if (input.transcript.includes(code)) continue;
|
|
584
584
|
const recorded = input.now === undefined ? '' : `RECORDED_AT: ${recordedAtLine(input.now, input.timeZone || 'UTC')}\n\n`;
|
|
585
|
-
|
|
585
|
+
const habits = input.habits?.length ? `HABITS (what this speaker has told us before; a hint for choosing focusId when the topic really matches, never a reason to guess):\n${input.habits.join('\n')}\n\n` : '';
|
|
586
|
+
return `${recorded}PROJECTS (focusId must be one of these ids, or null):\n${list}\n\n${habits}TRANSCRIPT:\n${untrustedDocument(input.transcript, code)}`;
|
|
586
587
|
}
|
|
587
588
|
throw new Error('Could not pick a delimiter that the transcript does not contain.');
|
|
588
589
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RESOLVE FROM THE CORPUS BEFORE ASKING (bd startsim-tmrvi.2).
|
|
3
|
+
*
|
|
4
|
+
* Habits (learn.ts) come from the person's own past answers. This is the other half: evidence already in
|
|
5
|
+
* the workspace. Other to-dos from other notes, Linear issues (to-dos that carry a Linear key) and calendar
|
|
6
|
+
* events say where similar work lives and when things happen. Like a habit, evidence can only CONFIRM the
|
|
7
|
+
* guess Tandem is already acting on, never change it; any similar item pointing elsewhere keeps the
|
|
8
|
+
* question open. Pure: callers read the rows, this decides and says why.
|
|
9
|
+
*/
|
|
10
|
+
import { contentWords } from '../briefing/intent/match';
|
|
11
|
+
import type { EvidenceEvent } from './items';
|
|
12
|
+
import type { ItemView, QuestionKind } from './types';
|
|
13
|
+
|
|
14
|
+
const day = (v: string | null | undefined) => (v ? String(v).slice(0, 10) : '');
|
|
15
|
+
const long = (title: string) => [...new Set(contentWords(title).filter((w) => w.length >= 4))];
|
|
16
|
+
|
|
17
|
+
/** How many words two titles share. */
|
|
18
|
+
function shared(a: string[], b: string[]): string[] {
|
|
19
|
+
const set = new Set(b);
|
|
20
|
+
return a.filter((w) => set.has(w));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const label = (i: ItemView) => (i.linearKey ? `Linear ${i.linearKey}` : `"${i.title}"`);
|
|
24
|
+
|
|
25
|
+
/** Similar = at least two content words in common (one word is too loose to act on). */
|
|
26
|
+
function similarTo(item: ItemView, others: ItemView[]): ItemView[] {
|
|
27
|
+
const words = long(item.title);
|
|
28
|
+
if (words.length === 0) return [];
|
|
29
|
+
return others.filter((o) => o.id !== item.id && shared(words, long(o.title)).length >= 2);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ContextHit { agrees: true; evidence: string; source: 'items' | 'linear' | 'calendar' }
|
|
33
|
+
|
|
34
|
+
export function decideFromCorpus(
|
|
35
|
+
input: { kind: QuestionKind; item: ItemView; assumed?: { value: string | null } },
|
|
36
|
+
corpus: { items: ItemView[]; events: EvidenceEvent[] },
|
|
37
|
+
): ContextHit | null {
|
|
38
|
+
const assumed = input.assumed?.value;
|
|
39
|
+
if (!assumed) return null;
|
|
40
|
+
const { item } = input;
|
|
41
|
+
|
|
42
|
+
if (input.kind === 'project') {
|
|
43
|
+
const like = similarTo(item, corpus.items).filter((o) => o.focusId);
|
|
44
|
+
if (like.length < 2) return null;
|
|
45
|
+
if (like.some((o) => o.focusId !== assumed)) return null; // a similar item lives elsewhere: ask
|
|
46
|
+
const linear = like.some((o) => o.linearKey);
|
|
47
|
+
return {
|
|
48
|
+
agrees: true, source: linear ? 'linear' : 'items',
|
|
49
|
+
evidence: `${like.length} similar to-dos (${like.slice(0, 2).map(label).join(', ')}) are in the same project`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (input.kind === 'due_date') {
|
|
54
|
+
const target = day(assumed);
|
|
55
|
+
if (!target) return null;
|
|
56
|
+
const words = long(item.title);
|
|
57
|
+
const event = corpus.events.find((e) => e.date === target && shared(words, long(e.title)).length >= 1);
|
|
58
|
+
if (event) return { agrees: true, source: 'calendar', evidence: `calendar: "${event.title}" on ${target}` };
|
|
59
|
+
const linked = similarTo(item, corpus.items).filter((o) => o.linearKey && o.dueAt);
|
|
60
|
+
if (linked.length > 0 && linked.every((o) => day(o.dueAt) === target)) {
|
|
61
|
+
return { agrees: true, source: 'linear', evidence: `${label(linked[0] as ItemView)} is due ${target}` };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE "NEEDS YOUR CALL" INBOX, as pure functions (bd startsim-tmrvi.7): how a
|
|
3
|
+
* question reads as answer chips, how typed words become an answer, and what an
|
|
4
|
+
* answer does to the to-do it is about while the save is still in flight.
|
|
5
|
+
* No React, no storage, no clock: the card in components/pages/questions and a
|
|
6
|
+
* native screen can both use these.
|
|
7
|
+
*/
|
|
8
|
+
import { parseSpokenAnswer, type AnswerOption } from './voice-parse';
|
|
9
|
+
import type { OpenQuestion, QuestionAnswer } from './types';
|
|
10
|
+
|
|
11
|
+
export interface AnswerChip {
|
|
12
|
+
value: string;
|
|
13
|
+
label: string;
|
|
14
|
+
/** The value Tandem is already acting on: tapping it confirms the guess. */
|
|
15
|
+
assumed: boolean;
|
|
16
|
+
/** Why this one was offered, when the model said. */
|
|
17
|
+
reason?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ChipContext {
|
|
21
|
+
/** Names for ids (a project's id to its title, a member's sub to their name). */
|
|
22
|
+
labels?: Record<string, string>;
|
|
23
|
+
timeZone?: string;
|
|
24
|
+
/** More choices (team, owner) the host knows by name. */
|
|
25
|
+
options?: AnswerOption[];
|
|
26
|
+
/** Cap on offered chips. Default 4. */
|
|
27
|
+
max?: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const ISO_DAY = /^\d{4}-\d{2}-\d{2}/;
|
|
31
|
+
|
|
32
|
+
/** "Fri, Nov 14" for a date, the known name for an id, else the value as given. */
|
|
33
|
+
export function formatAnswerValue(q: Pick<OpenQuestion, 'kind'> & { options?: AnswerOption[] }, value: string, ctx: ChipContext = {}): string {
|
|
34
|
+
if (q.kind === 'due_date') {
|
|
35
|
+
if (!value) return 'No date';
|
|
36
|
+
if (!ISO_DAY.test(value)) return value;
|
|
37
|
+
const d = new Date(`${value.slice(0, 10)}T00:00:00Z`);
|
|
38
|
+
return d.toLocaleDateString(undefined, { weekday: 'short', month: 'short', day: 'numeric', timeZone: 'UTC' });
|
|
39
|
+
}
|
|
40
|
+
return ctx.labels?.[value] ?? ctx.options?.find((o) => o.value === value)?.label ?? (q as { options?: AnswerOption[] }).options?.find((o) => o.value === value)?.label ?? value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The label of what Tandem is assuming, for the quiet line under the question. */
|
|
44
|
+
export function assumedLabel(q: OpenQuestion, ctx: ChipContext = {}): string {
|
|
45
|
+
const a = q.assumed;
|
|
46
|
+
if (!a) return '';
|
|
47
|
+
if (a.display) return a.display;
|
|
48
|
+
return a.value ? formatAnswerValue(q, a.value, ctx) : '';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The assumed value first (one tap keeps it), then the other candidates, no repeats. */
|
|
52
|
+
export function chipsFor(q: OpenQuestion, ctx: ChipContext = {}): AnswerChip[] {
|
|
53
|
+
const out: AnswerChip[] = [];
|
|
54
|
+
const seen = new Set<string>();
|
|
55
|
+
const add = (chip: AnswerChip) => {
|
|
56
|
+
if (!chip.value && q.kind !== 'due_date') return;
|
|
57
|
+
if (seen.has(chip.value)) return;
|
|
58
|
+
seen.add(chip.value);
|
|
59
|
+
out.push(chip);
|
|
60
|
+
};
|
|
61
|
+
const a = q.assumed;
|
|
62
|
+
if (a?.value) add({ value: a.value, label: a.display ?? formatAnswerValue(q, a.value, ctx), assumed: true, ...(a.reason ? { reason: a.reason } : {}) });
|
|
63
|
+
for (const c of q.candidates) {
|
|
64
|
+
add({ value: c.value, label: formatAnswerValue(q, c.value, ctx), assumed: false, ...(c.reason ? { reason: c.reason } : {}) });
|
|
65
|
+
}
|
|
66
|
+
// No candidates (a team, say): offer the first named choices instead.
|
|
67
|
+
if (out.length === 0) {
|
|
68
|
+
for (const o of (ctx.options ?? q.options ?? []).slice(0, ctx.max ?? 4)) add({ value: o.value, label: o.label, assumed: false });
|
|
69
|
+
}
|
|
70
|
+
return out.slice(0, ctx.max ?? 4);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type TypedAnswer =
|
|
74
|
+
| { kind: 'answer'; answer: QuestionAnswer }
|
|
75
|
+
| { kind: 'skip' }
|
|
76
|
+
| { kind: 'unclear'; message: string };
|
|
77
|
+
|
|
78
|
+
/** What typed words mean: the same small grammar the voice answer uses, so the two cannot disagree. */
|
|
79
|
+
export function readTypedAnswer(
|
|
80
|
+
q: OpenQuestion, text: string, ctx: { now: number; timeZone?: string; options?: AnswerOption[]; labels?: Record<string, string> },
|
|
81
|
+
): TypedAnswer {
|
|
82
|
+
const options = ctx.options ?? Object.entries(ctx.labels ?? {}).map(([value, label]) => ({ value, label }));
|
|
83
|
+
const parsed = parseSpokenAnswer(q, text, { now: ctx.now, timeZone: ctx.timeZone ?? 'UTC', options });
|
|
84
|
+
switch (parsed.kind) {
|
|
85
|
+
case 'answer': return { kind: 'answer', answer: { value: parsed.value, ...(parsed.label ? { label: parsed.label } : {}) } };
|
|
86
|
+
case 'accept': {
|
|
87
|
+
const value = q.assumed?.value ?? '';
|
|
88
|
+
return value ? { kind: 'answer', answer: { value, ...(q.assumed?.display ? { label: q.assumed.display } : {}) } } : { kind: 'unclear', message: q.question };
|
|
89
|
+
}
|
|
90
|
+
case 'skip': return { kind: 'skip' };
|
|
91
|
+
case 'undo': return { kind: 'unclear', message: 'Nothing to undo here. Type the answer, or skip it.' };
|
|
92
|
+
case 'unclear': return { kind: 'unclear', message: parsed.question };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The fields of a to-do an answer can change. */
|
|
97
|
+
export interface AnswerableItem { id: string; dueAt?: string | null; focusId?: string; ownerName?: string }
|
|
98
|
+
|
|
99
|
+
/** The to-do as it will read once this answer is saved: shown while the save is in flight. */
|
|
100
|
+
export function applyAnswerToItem<T extends AnswerableItem>(item: T, q: Pick<OpenQuestion, 'kind' | 'itemId'>, answer: QuestionAnswer): T {
|
|
101
|
+
if (item.id !== q.itemId) return item;
|
|
102
|
+
switch (q.kind) {
|
|
103
|
+
case 'due_date': return { ...item, dueAt: answer.value || null };
|
|
104
|
+
case 'project': return { ...item, focusId: answer.value };
|
|
105
|
+
case 'ownership': return { ...item, ownerName: answer.label ?? answer.value };
|
|
106
|
+
default: return item;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -21,5 +21,10 @@ export { composeCheckIn } from './checkin';
|
|
|
21
21
|
export type { CheckIn, CheckInEntry, CheckInOptions } from './checkin';
|
|
22
22
|
export { buildCheckIn } from './checkin-handle';
|
|
23
23
|
export type { CheckInResult } from './checkin-handle';
|
|
24
|
-
export {
|
|
24
|
+
export { decideFromCorpus } from './evidence';
|
|
25
|
+
export type { ContextHit } from './evidence';
|
|
26
|
+
export type { EvidenceEvent } from './items';
|
|
27
|
+
export { createPreferenceStore, learnFromAnswer, nextEvidence, decideFromHabits, habitHints, PREFERENCE_ATTRIBUTES, PREFERENCE_LABEL, PREFERENCE_TYPE } from './learn';
|
|
25
28
|
export type { Preference, PreferenceKind } from './learn';
|
|
29
|
+
export { applyAnswerToItem, assumedLabel, chipsFor, formatAnswerValue, readTypedAnswer } from './inbox';
|
|
30
|
+
export type { AnswerChip, AnswerableItem, ChipContext, TypedAnswer } from './inbox';
|
|
@@ -9,6 +9,26 @@ const PAGE_SIZE = 200;
|
|
|
9
9
|
const MAX_PAGES = 100;
|
|
10
10
|
const str = (v: unknown): string => (typeof v === 'string' ? v : '');
|
|
11
11
|
|
|
12
|
+
/** A dated calendar entry; read tolerantly because tenants model them under different keys. */
|
|
13
|
+
export interface EvidenceEvent { title: string; date: string }
|
|
14
|
+
export const CALENDAR_EVENT_TYPE = 'calendar_event';
|
|
15
|
+
|
|
16
|
+
export async function readEvidenceEvents(http: CorpusHttp, entitiesPath: string, type = CALENDAR_EVENT_TYPE): Promise<EvidenceEvent[]> {
|
|
17
|
+
const out: EvidenceEvent[] = [];
|
|
18
|
+
for (let page = 1; page <= 20; page += 1) {
|
|
19
|
+
const res = await http.get<{ results?: TenantEntity[]; next?: string | null }>(entitiesPath, { params: { type, page, page_size: PAGE_SIZE } });
|
|
20
|
+
const rows = res.results ?? [];
|
|
21
|
+
for (const row of rows) {
|
|
22
|
+
const d = (row.data ?? {}) as Record<string, unknown>;
|
|
23
|
+
const date = str(d.start ?? d.starts_at ?? d.startsAt ?? d.date ?? d.start_date).slice(0, 10);
|
|
24
|
+
const title = str(d.title ?? d.summary ?? d.name ?? row.name);
|
|
25
|
+
if (date && title) out.push({ title, date });
|
|
26
|
+
}
|
|
27
|
+
if (!res.next || rows.length === 0) break;
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
|
|
12
32
|
export async function readItemViews(http: CorpusHttp, scope: CorpusScope, entitiesPath: string): Promise<ItemView[]> {
|
|
13
33
|
const out: ItemView[] = [];
|
|
14
34
|
for (let page = 1; page <= MAX_PAGES; page += 1) {
|
|
@@ -24,6 +44,7 @@ export async function readItemViews(http: CorpusHttp, scope: CorpusScope, entiti
|
|
|
24
44
|
id: c.id, title: c.title, status: c.status, dueAt: c.dueAt ?? null,
|
|
25
45
|
focusId: str(d.external_focus_id ?? d.externalFocusId), ownerName: c.ownerName ?? '', ownerSub: c.ownerSub ?? '',
|
|
26
46
|
...(noteId ? { noteId } : {}),
|
|
47
|
+
...(c.sync?.key ? { linearKey: c.sync.key } : {}),
|
|
27
48
|
openKind: str(d.open_question_kind ?? d.openQuestionKind),
|
|
28
49
|
openText: str(d.open_question ?? d.openQuestion),
|
|
29
50
|
});
|
|
@@ -133,3 +133,19 @@ export function decideFromHabits(
|
|
|
133
133
|
}
|
|
134
134
|
return null;
|
|
135
135
|
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Project habits as hints for the extraction prompt (bd startsim-tmrvi.18). Only confident ones, only for
|
|
139
|
+
* projects that still exist, and only as a hint: the model still chooses by what the section is about, and
|
|
140
|
+
* a habit never makes a project "stated".
|
|
141
|
+
*/
|
|
142
|
+
export function habitHints(prefs: Preference[], focuses: Array<{ id: string; title: string }>): string[] {
|
|
143
|
+
const byId = new Map(focuses.map((f) => [f.id, f.title]));
|
|
144
|
+
const grouped = new Map<string, string[]>();
|
|
145
|
+
for (const p of prefs) {
|
|
146
|
+
if (p.kind !== 'project_word' || !confidentIn(prefs, 'project_word', p.key)) continue;
|
|
147
|
+
if (!byId.has(p.value)) continue;
|
|
148
|
+
grouped.set(p.value, [...(grouped.get(p.value) ?? []), p.key]);
|
|
149
|
+
}
|
|
150
|
+
return [...grouped].slice(0, 10).map(([id, words]) => `- to-dos about ${words.slice(0, 8).join(', ')} usually go to ${id} (${byId.get(id)})`);
|
|
151
|
+
}
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import type { CorpusHttp } from '../client';
|
|
6
6
|
import type { CorpusScope } from '../types';
|
|
7
7
|
import { CLOSED_STATUSES, deriveQuestions, scoreOf } from './derive';
|
|
8
|
-
import {
|
|
8
|
+
import { decideFromCorpus } from './evidence';
|
|
9
|
+
import { readEvidenceEvents, readItemViews, readVoiceRecords } from './items';
|
|
9
10
|
import { createPreferenceStore, decideFromHabits } from './learn';
|
|
10
11
|
import { createQuestionStore } from './store';
|
|
11
12
|
import type { ItemView, OpenQuestion, QuestionResolution } from './types';
|
|
@@ -40,6 +41,7 @@ export async function syncOpenQuestions(deps: QuestionDeps): Promise<{ opened: n
|
|
|
40
41
|
const existing = new Map((await store.all()).map((q) => [key(q.itemId, q.kind), q]));
|
|
41
42
|
|
|
42
43
|
const prefs = await createPreferenceStore(deps).all().catch(() => []);
|
|
44
|
+
const events = await readEvidenceEvents(deps.http, path).catch(() => []);
|
|
43
45
|
let opened = 0, resolved = 0, expired = 0, decidedByContext = 0;
|
|
44
46
|
const wanted = new Set<string>();
|
|
45
47
|
|
|
@@ -56,11 +58,13 @@ export async function syncOpenQuestions(deps: QuestionDeps): Promise<{ opened: n
|
|
|
56
58
|
};
|
|
57
59
|
if (!have && d.assumed) {
|
|
58
60
|
// Context first: a learned habit that agrees with the guess settles it, and the row says why.
|
|
59
|
-
const
|
|
61
|
+
const item = byId.get(d.itemId);
|
|
62
|
+
const hit = decideFromHabits({ kind: d.kind, title: item?.title ?? '', assumed: d.assumed }, prefs, (deps.now ?? Date.now)(), deps.timeZone ?? 'UTC')
|
|
63
|
+
?? (item ? decideFromCorpus({ kind: d.kind, item, assumed: d.assumed }, { items, events }) : null);
|
|
60
64
|
if (hit) {
|
|
61
65
|
await store.put(d.itemId, d.kind, d.question, {
|
|
62
66
|
...body, status: 'resolved', resolution: 'context', resolved_at: iso(), created_at: iso(), updated_at: iso(),
|
|
63
|
-
answer: JSON.stringify({ value: d.assumed.value ?? '', label:
|
|
67
|
+
answer: JSON.stringify({ value: d.assumed.value ?? '', label: `${'source' in hit ? 'found' : 'learned'}: ${hit.evidence}` }),
|
|
64
68
|
});
|
|
65
69
|
decidedByContext += 1;
|
|
66
70
|
continue;
|
|
@@ -38,6 +38,8 @@ export interface OpenQuestion {
|
|
|
38
38
|
/** What Tandem is acting on until it is confirmed; absent for held items. */
|
|
39
39
|
assumed?: AssumedValue;
|
|
40
40
|
candidates: QuestionCandidate[];
|
|
41
|
+
/** Named choices the server attaches when listing (project names, teams); absent for owners. */
|
|
42
|
+
options?: Array<{ value: string; label: string }>;
|
|
41
43
|
/** Higher is asked first. */
|
|
42
44
|
score: number;
|
|
43
45
|
ownerSub: string;
|
|
@@ -60,7 +62,7 @@ export interface QuestionAnswer {
|
|
|
60
62
|
/** Set when the answer was spoken: the press that gave it, so a repeat press does nothing twice. */
|
|
61
63
|
via?: string;
|
|
62
64
|
/** What the item held before, so a spoken "undo" can put it back. */
|
|
63
|
-
prior?: { dueAt?: string | null };
|
|
65
|
+
prior?: { dueAt?: string | null; focusId?: string | null; ownerSub?: string; ownerName?: string };
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
/** What the queue needs to know about an item (from its commitment row). */
|
|
@@ -73,6 +75,8 @@ export interface ItemView {
|
|
|
73
75
|
ownerName: string;
|
|
74
76
|
ownerSub: string;
|
|
75
77
|
noteId?: string;
|
|
78
|
+
/** The Linear issue key when the item is synced to one. */
|
|
79
|
+
linearKey?: string;
|
|
76
80
|
openKind: string;
|
|
77
81
|
openText: string;
|
|
78
82
|
}
|
|
@@ -15,6 +15,7 @@ import type { BriefingAudio, BriefingSynthesize } from '../briefing/generate';
|
|
|
15
15
|
import { speakDatesIn, speakable } from '../briefing/speak';
|
|
16
16
|
import { localDate } from '../today';
|
|
17
17
|
import { answerQuestion, type AnswerDeps } from './answer';
|
|
18
|
+
import { readItemViews } from './items';
|
|
18
19
|
import { close, listOpenQuestions, storeFor } from './sync';
|
|
19
20
|
import type { OpenQuestion, QuestionAnswer } from './types';
|
|
20
21
|
import { parseSpokenAnswer, type AnswerOption } from './voice-parse';
|
|
@@ -112,12 +113,19 @@ async function undoLast(deps: VoiceAnswerDeps, now: number): Promise<{ text: str
|
|
|
112
113
|
.filter((q) => q.resolution === 'answered' && q.answer?.via && q.resolvedAt && now - Date.parse(q.resolvedAt) <= UNDO_WINDOW_MS)
|
|
113
114
|
.sort((a, b) => (b.resolvedAt ?? '').localeCompare(a.resolvedAt ?? ''))[0];
|
|
114
115
|
if (!last) return { text: 'There is nothing to undo.', question: null };
|
|
115
|
-
|
|
116
|
+
const prior = last.answer?.prior;
|
|
117
|
+
// A team answer also released the item to the tracker, so it cannot be quietly taken back.
|
|
118
|
+
if (!prior || !['due_date', 'project', 'ownership'].includes(last.kind)) {
|
|
116
119
|
return { text: 'I cannot undo that one by voice. You can change it on the item.', question: last };
|
|
117
120
|
}
|
|
118
121
|
const item = await deps.seam.load(last.itemId);
|
|
119
122
|
if (!item) return { text: 'That item is gone, so there is nothing to put back.', question: last };
|
|
120
|
-
await deps.seam.update(item, { dueAt:
|
|
123
|
+
if (last.kind === 'due_date') await deps.seam.update(item, { dueAt: prior.dueAt ?? null });
|
|
124
|
+
else if (last.kind === 'project') {
|
|
125
|
+
if (!deps.fileItem) return { text: 'I cannot undo that one by voice. You can change it on the item.', question: last };
|
|
126
|
+
await deps.fileItem(last.itemId, prior.focusId ?? null);
|
|
127
|
+
await deps.patchItem(last.itemId, { external_focus_id: prior.focusId ?? '' });
|
|
128
|
+
} else await deps.patchItem(last.itemId, { owner_sub: prior.ownerSub ?? '', owner_name: prior.ownerName ?? '' });
|
|
121
129
|
const at = new Date(now).toISOString();
|
|
122
130
|
const reopened = await storeFor(deps).put(last.itemId, last.kind, last.question, {
|
|
123
131
|
status: 'open', resolution: '', resolved_at: '', answer: '', updated_at: at,
|
|
@@ -222,6 +230,17 @@ export async function answerQuestionByVoice(deps: VoiceAnswerDeps, req: VoiceAns
|
|
|
222
230
|
|
|
223
231
|
/** Apply the answer, remembering what a due date was so "undo" can put it back. */
|
|
224
232
|
async function applyAnswer(deps: VoiceAnswerDeps, q: OpenQuestion, answer: QuestionAnswer): Promise<OpenQuestion> {
|
|
225
|
-
const prior =
|
|
226
|
-
return answerQuestion(deps, q.id, prior ? { ...answer, prior
|
|
233
|
+
const prior = await priorOf(deps, q);
|
|
234
|
+
return answerQuestion(deps, q.id, prior ? { ...answer, prior } : answer);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async function priorOf(deps: VoiceAnswerDeps, q: OpenQuestion): Promise<QuestionAnswer['prior'] | null> {
|
|
238
|
+
if (q.kind === 'due_date') {
|
|
239
|
+
const item = await deps.seam.load(q.itemId).catch(() => null);
|
|
240
|
+
return item ? { dueAt: item.dueAt ?? null } : null;
|
|
241
|
+
}
|
|
242
|
+
if (q.kind !== 'project' && q.kind !== 'ownership') return null;
|
|
243
|
+
const view = (await readItemViews(deps.http, deps.scope, deps.entitiesPath ?? 'api/v1/entities').catch(() => [])).find((i) => i.id === q.itemId);
|
|
244
|
+
if (!view) return null;
|
|
245
|
+
return q.kind === 'project' ? { focusId: view.focusId || null } : { ownerSub: view.ownerSub, ownerName: view.ownerName };
|
|
227
246
|
}
|
package/src/corpus/types.ts
CHANGED
|
@@ -557,6 +557,10 @@ export interface AnswerRequest {
|
|
|
557
557
|
mode: AskMode;
|
|
558
558
|
instructions?: string;
|
|
559
559
|
documents: PromptDocument[];
|
|
560
|
+
/** Today in the reader's zone, sent only with an item question so "overdue" has a reference. */
|
|
561
|
+
today?: string;
|
|
562
|
+
/** The date window the item selection used, in words (`this week (2026-11-09 to 2026-11-15)`). */
|
|
563
|
+
itemWindow?: string;
|
|
560
564
|
}
|
|
561
565
|
|
|
562
566
|
/** The structured shape the model must return. Validated before it is trusted. */
|
package/src/corpus/voice.ts
CHANGED
|
@@ -105,7 +105,7 @@ export interface VoiceUsage {
|
|
|
105
105
|
|
|
106
106
|
export interface VoiceAnalyzer {
|
|
107
107
|
/** `now` is when the note was recorded and `timeZone` the speaker's: the model is shown them so "today" means something. */
|
|
108
|
-
analyze(input: { transcript: string; focuses: FocusChoice[]; now?: number; timeZone?: string }): Promise<VoiceAnalysis>;
|
|
108
|
+
analyze(input: { transcript: string; focuses: FocusChoice[]; now?: number; timeZone?: string; habits?: string[] }): Promise<VoiceAnalysis>;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
export interface VoiceTranscriber {
|
|
@@ -214,6 +214,8 @@ export interface VoiceDeps {
|
|
|
214
214
|
analyzer: VoiceAnalyzer;
|
|
215
215
|
store: VoiceAudioStore;
|
|
216
216
|
listFocuses(): Promise<FocusChoice[]>;
|
|
217
|
+
/** Learned project habits as prompt hints (bd startsim-tmrvi.18); best effort. */
|
|
218
|
+
listHabits?(focuses: FocusChoice[]): Promise<string[]>;
|
|
217
219
|
now?: () => Date;
|
|
218
220
|
}
|
|
219
221
|
|
|
@@ -323,7 +325,8 @@ export async function finishVoiceNote(
|
|
|
323
325
|
const recordedAt = submission.recordedAt ? Date.parse(submission.recordedAt) : at.getTime();
|
|
324
326
|
const timeZone = isTimeZone(submission.timeZone) ? submission.timeZone : 'UTC';
|
|
325
327
|
const now = Number.isNaN(recordedAt) ? at.getTime() : recordedAt;
|
|
326
|
-
const
|
|
328
|
+
const habits = deps.listHabits ? await deps.listHabits(focuses).catch(() => [] as string[]) : [];
|
|
329
|
+
const heardAnalysis = await deps.analyzer.analyze({ transcript, focuses, now, timeZone, ...(habits.length ? { habits } : {}) });
|
|
327
330
|
// Dates are computed HERE from what was said, whatever the model did: its `when` words are
|
|
328
331
|
// resolved against the recording time and the speaker's zone, and a note-wide "plan for the
|
|
329
332
|
// day" fills the rest. The summary is re-rendered so each to-do carries its due date.
|