@startsimpli/integrations 0.2.213 → 0.2.215

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 (53) hide show
  1. package/package.json +5 -5
  2. package/src/__tests__/connect-claude.test.tsx +2 -0
  3. package/src/__tests__/corpus-tracker.test.tsx +13 -2
  4. package/src/__tests__/engine-decide.test.ts +160 -0
  5. package/src/__tests__/engine-extract-policy.test.ts +145 -0
  6. package/src/__tests__/engine-replay.test.ts +126 -0
  7. package/src/__tests__/engine-scheduled-run.test.ts +74 -0
  8. package/src/__tests__/extract-skips-tandem-authored.test.ts +34 -0
  9. package/src/__tests__/load-error.test.tsx +3 -1
  10. package/src/__tests__/suggested-items-hidden.test.ts +74 -0
  11. package/src/__tests__/suggestion-ui.test.tsx +97 -0
  12. package/src/__tests__/todo-table.test.tsx +2 -1
  13. package/src/components/pages/ConnectClaudePage.tsx +2 -1
  14. package/src/components/pages/TaskDetailPage.tsx +10 -0
  15. package/src/components/pages/TrackerPage.tsx +32 -10
  16. package/src/components/pages/tracker/Suggestion.tsx +66 -0
  17. package/src/components/table/todo-model.ts +1 -0
  18. package/src/corpus/activity.ts +2 -3
  19. package/src/corpus/ask-items.ts +2 -2
  20. package/src/corpus/briefing/compose.ts +2 -2
  21. package/src/corpus/briefing/weekly.ts +2 -2
  22. package/src/corpus/client.ts +2 -0
  23. package/src/corpus/commitments.ts +20 -3
  24. package/src/corpus/converse/briefing-queue.ts +2 -1
  25. package/src/corpus/converse/item-answers.ts +2 -2
  26. package/src/corpus/due-groups.ts +2 -2
  27. package/src/corpus/engine/apply.ts +111 -0
  28. package/src/corpus/engine/decide.ts +106 -0
  29. package/src/corpus/engine/dry-extract.ts +98 -0
  30. package/src/corpus/engine/graduation.ts +49 -0
  31. package/src/corpus/engine/index.ts +14 -0
  32. package/src/corpus/engine/replay.ts +222 -0
  33. package/src/corpus/engine/rules.ts +58 -0
  34. package/src/corpus/engine/sources.ts +16 -0
  35. package/src/corpus/engine/suggestion.ts +72 -0
  36. package/src/corpus/engine/types.ts +147 -0
  37. package/src/corpus/entities.ts +7 -1
  38. package/src/corpus/extract-prompts.ts +139 -0
  39. package/src/corpus/extract.ts +46 -139
  40. package/src/corpus/focus-overview.ts +2 -2
  41. package/src/corpus/index.ts +9 -0
  42. package/src/corpus/item-status.ts +17 -0
  43. package/src/corpus/note-actions.ts +3 -3
  44. package/src/corpus/questions/derive.ts +2 -1
  45. package/src/corpus/questions/sync.ts +2 -1
  46. package/src/corpus/runs.ts +21 -1
  47. package/src/corpus/today.ts +2 -2
  48. package/src/corpus/tracker-groups.ts +3 -0
  49. package/src/corpus/tracker-timeline-client.ts +1 -1
  50. package/src/corpus/types.ts +12 -2
  51. package/src/native/screens/connect-claude/ConnectClaudeScreen.tsx +1 -1
  52. package/src/native/screens/connect-claude/fake.ts +1 -1
  53. package/src/native/tracker/format.ts +1 -1
@@ -0,0 +1,74 @@
1
+ /**
2
+ * A SUGGESTED item is not on the owner's list until they accept it (bd
3
+ * startsim-vrmx5 slice 2). Today, the due groups, the weekly briefing and Ask
4
+ * all leave it out, exactly as they leave out a closed item.
5
+ */
6
+ import { describe, expect, it } from 'vitest';
7
+
8
+ import { selectItems } from '../corpus/ask-items';
9
+ import { composeWeekly } from '../corpus/briefing/weekly';
10
+ import { groupDue } from '../corpus/due-groups';
11
+ import { isLiveStatus, SUGGESTED_STATUS } from '../corpus/item-status';
12
+ import { todayKind } from '../corpus/today';
13
+ import type { Commitment } from '../corpus/types';
14
+
15
+ const NOW = Date.parse('2026-11-24T12:00:00Z');
16
+
17
+ describe('suggested items stay off every list until accepted', () => {
18
+ it('names the status once', () => {
19
+ expect(SUGGESTED_STATUS).toBe('suggested');
20
+ expect(isLiveStatus('open')).toBe(true);
21
+ expect(isLiveStatus('suggested')).toBe(false);
22
+ expect(isLiveStatus('done')).toBe(false);
23
+ });
24
+
25
+ it('is not in Today, even when overdue', () => {
26
+ expect(todayKind({ status: 'open' }, '2026-11-20', '2026-11-24')).toBe('overdue');
27
+ expect(todayKind({ status: 'suggested' }, '2026-11-20', '2026-11-24')).toBeNull();
28
+ });
29
+
30
+ it('is not counted in the due groups', () => {
31
+ const groups = groupDue([{ status: 'suggested', dueAt: '2026-11-20' }, { status: 'open', dueAt: null }], { now: NOW });
32
+ expect(groups.total).toBe(0);
33
+ });
34
+
35
+ it('is not slipping or upcoming in the weekly briefing', () => {
36
+ const summary = composeWeekly(
37
+ [{ id: 's', title: 't', status: 'suggested', dueAt: '2026-11-20', ownerSub: 'me' }],
38
+ { ownerSub: 'me', now: NOW },
39
+ );
40
+ expect(summary.counts).toEqual({ done: 0, slipping: 0, upcoming: 0 });
41
+ });
42
+
43
+ it('is not an answer in Ask', () => {
44
+ const item = { id: 's', status: 'suggested', dueAt: '2026-11-20', ownerSub: 'me', mentions: [] } as unknown as Commitment;
45
+ const picked = selectItems([item], { focus: 'slipping', mine: true, today: '2026-11-24' } as never, { now: NOW, ownerSub: 'me' });
46
+ expect(picked).toHaveLength(0);
47
+ });
48
+ });
49
+
50
+ describe('reading a suggested row back from the tenant', () => {
51
+ it('keeps the status and the decision instead of turning it into an open to-do', async () => {
52
+ const { toCommitment } = await import('../corpus/entities');
53
+ const row = { id: 'r1', external_id: 'commit:r1', name: 'Send the deck', owner_sub: 'me', data: {
54
+ title: 'Send the deck', status: 'suggested',
55
+ suggestion: { rule: 'C-MODEL', mode: 'propose', confidence: 0.8, reason: 'why', document_id: 'd', quote: 'q' },
56
+ } };
57
+ const item = toCommitment(row as never, { orgId: 'tandem' });
58
+ expect(item.status).toBe('suggested');
59
+ expect(item.suggestion).toMatchObject({ rule: 'C-MODEL', mode: 'propose', documentId: 'd' });
60
+ });
61
+ });
62
+
63
+ describe('the morning briefing', () => {
64
+ it('neither speaks nor counts a suggestion, even an overdue one', async () => {
65
+ const { composeBriefing } = await import('../corpus/briefing/compose');
66
+ const briefing = composeBriefing(
67
+ [{ id: 's', title: 'Suggested thing', status: 'suggested', dueAt: '2026-11-20', ownerSub: 'me' },
68
+ { id: 'o', title: 'Real thing', status: 'open', dueAt: '2026-11-20', ownerSub: 'me' }],
69
+ { ownerSub: 'me', now: NOW },
70
+ );
71
+ expect(briefing.total).toBe(1);
72
+ expect(briefing.items.map((i) => i.id)).toEqual(['o']);
73
+ });
74
+ });
@@ -0,0 +1,97 @@
1
+ /** A suggested to-do in the existing list: why it is there, Accept, Reject (bd startsim-vrmx5 slice 2). */
2
+ import * as React from 'react';
3
+ import { render, screen, waitFor, within } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+ import { describe, expect, it, vi } from 'vitest';
6
+
7
+ import { TrackerPage } from '../components/pages/TrackerPage';
8
+ import { TaskDetailPage } from '../components/pages/TaskDetailPage';
9
+ import { todoQuery } from '../components/table';
10
+ import type { Commitment, CommitmentTrackerApi } from '../corpus/types';
11
+
12
+ const NOW = Date.parse('2026-11-24T12:00:00Z');
13
+ const SCOPE = { orgId: 'tandem' };
14
+ const suggestion = { rule: 'C-MODEL' as const, mode: 'propose' as const, confidence: 0.8, reason: 'Said in the source and confirmed by the checker, with you as owner.', documentId: 'm1', quote: 'I will send the deck' };
15
+
16
+ const item = (externalId: string, title: string, extra: Partial<Commitment> = {}): Commitment => ({
17
+ id: externalId, externalId, dedupeKey: externalId, subtype: 'action', title, detail: '', status: 'open',
18
+ subjectKey: '', actionKey: '', mentions: [], firstSeenAt: '2026-11-20T00:00:00Z', lastSeenAt: '2026-11-20T00:00:00Z',
19
+ extractorVersion: 'x', source: 'granola', sourceLabel: 'Granola', scope: SCOPE, ...extra,
20
+ });
21
+
22
+ function statefulApi(rows: Commitment[]) {
23
+ const updateCommitment = vi.fn(async (it: Commitment, patch: object) => {
24
+ const i = rows.findIndex((r) => r.externalId === it.externalId);
25
+ rows[i] = { ...rows[i], ...patch } as Commitment;
26
+ return rows[i];
27
+ });
28
+ const api = {
29
+ listCommitments: vi.fn(async () => ({ count: rows.length, next: null, previous: null, results: [...rows], appliedFilters: [] })),
30
+ updateCommitment,
31
+ } as unknown as CommitmentTrackerApi;
32
+ return { api, updateCommitment };
33
+ }
34
+
35
+ describe('suggested to-dos in the to-do list', () => {
36
+ it('pins pending suggestions on top of page 1 of the Open view, asked of the server', async () => {
37
+ const dated = Array.from({ length: 3 }, (_, n) => item(`commit:d${n}`, `Dated ${n}`, { dueAt: `2026-11-2${n}` }));
38
+ const rows = [...dated, item('commit:s', 'Send the deck', { status: 'suggested', suggestion })];
39
+ const listCommitments = vi.fn(async (q: { status?: string[] }) => {
40
+ const results = rows.filter((r) => !q.status || q.status.includes(r.status));
41
+ return { count: results.length, next: null, previous: null, results, appliedFilters: ['status'] };
42
+ });
43
+ render(<TrackerPage api={{ listCommitments, updateCommitment: vi.fn() } as unknown as CommitmentTrackerApi} scope={SCOPE} now={NOW} />);
44
+ await screen.findByTestId('suggestion');
45
+ expect(listCommitments).toHaveBeenCalledWith(expect.objectContaining({ status: ['suggested'], page: 1 }));
46
+ const titles = screen.getAllByRole('row').map((r) => r.textContent ?? '').filter((t) => /Send the deck|Dated/.test(t));
47
+ expect(titles[0]).toMatch(/Send the deck/);
48
+ expect(todoQuery({ search: '', status: 'open', project: '', sort: null, page: 1, pageSize: 25 }).status).not.toContain('suggested');
49
+ });
50
+
51
+ it('shows why and the quote, and Accept puts it on the list as accepted', async () => {
52
+ const rows = [item('commit:s', 'Send the deck', { status: 'suggested', suggestion }), item('commit:o', 'Book the venue')];
53
+ const { api, updateCommitment } = statefulApi(rows);
54
+ render(<TrackerPage api={api} scope={SCOPE} now={NOW} />);
55
+ const note = await screen.findByTestId('suggestion');
56
+ expect(note).toHaveTextContent(/Suggested:.*confirmed by the checker.*“I will send the deck”/);
57
+ expect(screen.getAllByTestId('suggestion')).toHaveLength(1);
58
+ await userEvent.click(within(note).getByRole('button', { name: 'Accept' }));
59
+ await waitFor(() => expect(updateCommitment).toHaveBeenCalledWith(
60
+ expect.objectContaining({ externalId: 'commit:s' }),
61
+ expect.objectContaining({ status: 'open', suggestion: expect.objectContaining({ rule: 'C-MODEL', outcome: 'accepted' }) })));
62
+ await waitFor(() => expect(screen.queryByTestId('suggestion')).toBeNull());
63
+ });
64
+
65
+ it('Reject drops it and records the rejection for the rule', async () => {
66
+ const rows = [item('commit:s', 'Send the deck', { status: 'suggested', suggestion })];
67
+ const { api, updateCommitment } = statefulApi(rows);
68
+ render(<TrackerPage api={api} scope={SCOPE} now={NOW} />);
69
+ await userEvent.click(within(await screen.findByTestId('suggestion')).getByRole('button', { name: 'Reject' }));
70
+ await waitFor(() => expect(updateCommitment).toHaveBeenCalledWith(
71
+ expect.objectContaining({ externalId: 'commit:s' }),
72
+ expect.objectContaining({ status: 'dropped', suggestion: expect.objectContaining({ outcome: 'rejected' }) })));
73
+ });
74
+ });
75
+
76
+ describe('the item detail', () => {
77
+ it('says why Tandem added an item on its own, and Undo removes it as a rejection', async () => {
78
+ const acted = { ...suggestion, rule: 'C-VENDOR' as const, mode: 'act' as const, reason: 'Listed under the note’s next steps with you as owner.' };
79
+ const rows = [item('commit:a', 'Send the deck', { suggestion: acted })];
80
+ const { api, updateCommitment } = statefulApi(rows);
81
+ render(<TaskDetailPage api={api as never} scope={SCOPE as never} itemId="commit:a" />);
82
+ const why = await screen.findByTestId('engine-reason');
83
+ expect(why).toHaveTextContent(/Added by Tandem: Listed under the note’s next steps/);
84
+ await userEvent.click(within(why).getByRole('button', { name: 'Undo' }));
85
+ await waitFor(() => expect(updateCommitment).toHaveBeenCalledWith(
86
+ expect.anything(), expect.objectContaining({ status: 'dropped', suggestion: expect.objectContaining({ outcome: 'rejected' }) })));
87
+ });
88
+
89
+ it('offers Accept and Reject on a suggestion', async () => {
90
+ const rows = [item('commit:s', 'Send the deck', { status: 'suggested', suggestion })];
91
+ const { api, updateCommitment } = statefulApi(rows);
92
+ render(<TaskDetailPage api={api as never} scope={SCOPE as never} itemId="commit:s" />);
93
+ await userEvent.click(within(await screen.findByTestId('suggestion')).getByRole('button', { name: 'Accept' }));
94
+ await waitFor(() => expect(updateCommitment).toHaveBeenCalledWith(
95
+ expect.anything(), expect.objectContaining({ status: 'open', suggestion: expect.objectContaining({ outcome: 'accepted' }) })));
96
+ });
97
+ });
@@ -24,7 +24,8 @@ function api(rows: Commitment[], onQuery: (q: CommitmentQuery) => void = () => u
24
24
  const create = vi.fn(async (d: { title: string }) => todo(99, { title: d.title }));
25
25
  const impl: CommitmentTrackerApi = {
26
26
  async listCommitments(q: CommitmentQuery = {}): Promise<CorpusPage<Commitment>> {
27
- onQuery(q);
27
+ // The pinned-suggestions read (bd startsim-vrmx5) is not the list's query.
28
+ if (!(Array.isArray(q.status) && q.status.length === 1 && q.status[0] === 'suggested')) onQuery(q);
28
29
  return { count: total, next: null, previous: null, results: rows, appliedFilters: ['status', 'subtype', 'search', 'focus'] };
29
30
  },
30
31
  updateCommitment: update, createCommitment: create,
@@ -174,7 +174,8 @@ export function ConnectClaudePage({ api, classNames, foundrySlug }: ConnectClaud
174
174
  nobody can act on. */}
175
175
  <div className={cx(classNames, 'warning')} role="note">
176
176
  <strong>Before you create this:</strong> it reads this workspace <em>as
177
- you</em> — whatever you can see, it can see. It is shown once and
177
+ you</em> — whatever you can see, it can see — and it can also <strong>add, move
178
+ and delete events on your connected calendar</strong>. It is shown once and
178
179
  cannot be retrieved again, and it <strong>cannot be cancelled before
179
180
  it expires</strong>. Turning off your access to the workspace stops
180
181
  new ones being made; it does not switch this one off.
@@ -24,6 +24,8 @@ import { ExternalLinkChip } from './task-tracker/ExternalLinkChip';
24
24
  import { failureMessage } from './work-items';
25
25
  import { ProjectGuess } from './task-tracker/ProjectGuess';
26
26
  import { PossiblyDoneNote, markDonePatch, notDonePatch } from './tracker/PossiblyDone';
27
+ import { EngineReason, SuggestionNote, acceptPatch, rejectPatch } from './tracker/Suggestion';
28
+ import { SUGGESTED_STATUS } from '../../corpus/item-status';
27
29
  import type { MemberConnectionsApi } from './types';
28
30
 
29
31
  export interface TaskDetailPageProps {
@@ -203,6 +205,8 @@ export function TaskDetailPage({
203
205
  detail: form.detail,
204
206
  ownerName: form.owner.trim() || undefined,
205
207
  dueAt: form.due ? `${form.due}T00:00:00Z` : null,
208
+ // Editing a suggestion is accepting it with changes (bd startsim-vrmx5).
209
+ ...(item.status === SUGGESTED_STATUS && item.suggestion ? acceptPatch(item, true) : {}),
206
210
  };
207
211
  const updated = await apiRef.current.updateCommitment(item, patch);
208
212
  setItem({ ...item, ...patch, ...updated });
@@ -296,6 +300,12 @@ export function TaskDetailPage({
296
300
  </dl>
297
301
 
298
302
  {item.detail ? <p className="mt-3 whitespace-pre-wrap text-sm text-gray-700">{item.detail}</p> : null}
303
+ {canWrite ? (
304
+ <>
305
+ <SuggestionNote item={item} disabled={busy} onAccept={(it) => void patchItem(acceptPatch(it))} onReject={(it) => void patchItem(rejectPatch(it))} />
306
+ <EngineReason item={item} onUndo={item.status === 'done' || item.status === 'dropped' ? undefined : (it) => void patchItem(rejectPatch(it))} />
307
+ </>
308
+ ) : null}
299
309
  {canWrite ? (
300
310
  <PossiblyDoneNote
301
311
  item={item} disabled={busy}
@@ -26,6 +26,8 @@ import { useTrackerName } from '../../task-tracker/useTrackerName';
26
26
  import type { MemberConnectionsApi } from './types';
27
27
  import { failureMessage, unfilteredMessage } from './work-items';
28
28
  import { PossiblyDoneNote, markDonePatch, notDonePatch } from './tracker/PossiblyDone';
29
+ import { SuggestionNote, acceptPatch, rejectPatch } from './tracker/Suggestion';
30
+ import { SUGGESTED_STATUS } from '../../corpus/item-status';
29
31
  import { SweepPanel } from './tracker/SweepPanel';
30
32
  import { TrackerTimeline } from './tracker/TrackerTimeline';
31
33
  import { filterFromChip } from '../../corpus/tracker-timeline';
@@ -33,6 +35,7 @@ import { FilterSelect, TableToolbar, TodoTable, TODO_STATUS_FILTERS, readPageSiz
33
35
  import type { PageSize, TableSort } from '../table';
34
36
  import type {
35
37
  Commitment,
38
+ CommitmentStatus,
36
39
  CommitmentTrackerApi,
37
40
  CorpusScope,
38
41
  ExtractionRun,
@@ -62,6 +65,12 @@ export interface TrackerPageProps {
62
65
  * API pays for every one of them. Three seconds is fast enough that the bar
63
66
  * moves and slow enough that watching costs nothing.
64
67
  */
68
+ /**
69
+ * Show the manual "Pull from meetings" trigger. A host whose to-dos come from
70
+ * the scheduled per-owner pass turns it off (bd startsim-vrmx5 slice 3); the
71
+ * sweep's progress and errors still show here either way.
72
+ */
73
+ manualPull?: boolean;
65
74
  pollMs?: number;
66
75
  /**
67
76
  * How many times a stalled sweep may be picked back up without anybody
@@ -145,6 +154,7 @@ export function TrackerPage({
145
154
  projectNames = {},
146
155
  timeZone,
147
156
  showTimeline = true,
157
+ manualPull = true,
148
158
  focusId,
149
159
  initialSearch,
150
160
  classNames = {},
@@ -201,8 +211,15 @@ export function TrackerPage({
201
211
  setError('');
202
212
  setLoadFailed(false);
203
213
  try {
204
- const result = await apiRef.current.listCommitments(query);
205
- setRows(result.results);
214
+ // PENDING SUGGESTIONS FIRST (bd startsim-vrmx5): in the Open view they sit on
215
+ // top of page 1, so an undated suggestion is never buried under the dated list.
216
+ const pinned = query.status?.includes('open') && query.page === 1 && !query.search
217
+ ? apiRef.current.listCommitments({ ...query, status: [SUGGESTED_STATUS as CommitmentStatus], page: 1 })
218
+ // A server that ignored the filter must not duplicate the list: keep only real suggestions.
219
+ .then((page) => page.results.filter((row) => row.status === SUGGESTED_STATUS)).catch(() => [] as Commitment[])
220
+ : Promise.resolve([] as Commitment[]);
221
+ const [result, suggestions] = await Promise.all([apiRef.current.listCommitments(query), pinned]);
222
+ setRows([...suggestions, ...result.results.filter((row) => row.status !== SUGGESTED_STATUS)]);
206
223
  setTotal(result.count);
207
224
  setApplied(result.appliedFilters ?? []);
208
225
  if (result.results.length > 0) {
@@ -359,7 +376,7 @@ export function TrackerPage({
359
376
  ];
360
377
  const resetPage = <T,>(set: (v: T) => void) => (v: T) => { set(v); setPage(1); };
361
378
 
362
- const pullButton = canQueue ? (
379
+ const pullButton = !manualPull ? null : canQueue ? (
363
380
  /**
364
381
  * THE BUTTON NO LONGER WAITS, because it cannot: seventeen meetings is about six minutes of model
365
382
  * time and the tenant gateway closes a request at sixty seconds. It starts the job and the screen
@@ -408,7 +425,7 @@ export function TrackerPage({
408
425
  * here as well, and the warning says the server did not do it. (A server that applied it is trusted.)
409
426
  */
410
427
  const wanted = query.status;
411
- const shown = wanted && !applied.includes('status') ? rows.filter((r) => wanted.includes(r.status)) : rows;
428
+ const shown = wanted && !applied.includes('status') ? rows.filter((r) => r.status === SUGGESTED_STATUS || wanted.includes(r.status)) : rows;
412
429
  const warning = unfilteredMessage(['status'] as const, applied, query);
413
430
 
414
431
  return (
@@ -437,18 +454,23 @@ export function TrackerPage({
437
454
  onSnooze={canWrite ? (item) => void act(item, { dueAt: snoozeTo(7) }) : undefined}
438
455
  onDrop={canWrite ? (item) => void act(item, { status: 'dropped', statusReason: 'Dropped from the list' }) : undefined}
439
456
  below={canWrite ? (item) => (
440
- <PossiblyDoneNote
441
- item={item}
442
- onMarkDone={(it, c) => void act(it, markDonePatch(c))}
443
- onNotDone={(it, c) => void act(it, notDonePatch(it, c))}
444
- />
457
+ <>
458
+ <SuggestionNote item={item} onAccept={(it) => void act(it, acceptPatch(it))} onReject={(it) => void act(it, rejectPatch(it))} />
459
+ <PossiblyDoneNote
460
+ item={item}
461
+ onMarkDone={(it, c) => void act(it, markDonePatch(c))}
462
+ onNotDone={(it, c) => void act(it, notDonePatch(it, c))}
463
+ />
464
+ </>
445
465
  ) : undefined}
446
466
  sort={sort} onSort={resetPage(setSort)}
447
467
  page={page} pageSize={pageSize} total={total} onPage={setPage}
448
468
  onPageSize={(size) => { writePageSize('todos', size); setPageSizeState(size); setPage(1); }}
449
469
  loading={loading}
450
470
  emptyMessage={loadFailed ? '' : filtering ? 'No to-dos match.'
451
- : workspaceHasAny === false ? 'Nothing has been pulled out of your meetings yet. Connect a source, then run “Pull from meetings”.'
471
+ : workspaceHasAny === false ? (manualPull
472
+ ? 'Nothing has been pulled out of your meetings yet. Connect a source, then run “Pull from meetings”.'
473
+ : 'Nothing has been pulled out of your meetings yet. Connect a source; new notes are read every half hour.')
452
474
  : 'Nothing is owed right now.'}
453
475
  topRow={adding ? (
454
476
  <div className="flex items-center gap-2">
@@ -0,0 +1,66 @@
1
+ /**
2
+ * "Suggested: <why> “<quote>”" with Accept / Reject, drawn under a to-do the
3
+ * engine proposed (bd startsim-vrmx5 slice 2). Editing is the row's own open
4
+ * action, as for every item; accepting after an edit records "edited".
5
+ *
6
+ * Presentational: the host owns the write. Nothing here changes an item by itself.
7
+ */
8
+ import * as React from 'react';
9
+
10
+ import { stripMarkdown } from '../../Markdown';
11
+ import { SUGGESTED_STATUS } from '../../../corpus/item-status';
12
+ import type { Suggestion } from '../../../corpus/engine/suggestion';
13
+ import type { Commitment } from '../../../corpus/types';
14
+
15
+ const BTN = 'rounded border border-gray-300 px-2 py-0.5 text-xs text-gray-700 hover:border-gray-400';
16
+
17
+ const reviewed = (item: Commitment, outcome: NonNullable<Suggestion['outcome']>): Suggestion =>
18
+ ({ ...item.suggestion!, outcome, reviewedAt: new Date().toISOString() });
19
+
20
+ /** Accepting puts it on the list. If the owner changed it first, the review says so. */
21
+ export const acceptPatch = (item: Commitment, edited = false) => ({
22
+ status: 'open' as const,
23
+ suggestion: reviewed(item, edited ? 'edited' : 'accepted'),
24
+ });
25
+
26
+ /** Rejecting drops it, and the rejection is what teaches the rule. */
27
+ export const rejectPatch = (item: Commitment) => ({
28
+ status: 'dropped' as const,
29
+ statusReason: 'Suggestion rejected',
30
+ suggestion: reviewed(item, 'rejected'),
31
+ });
32
+
33
+ export function SuggestionNote({ item, onAccept, onReject, disabled }: {
34
+ item: Commitment;
35
+ onAccept: (item: Commitment) => void;
36
+ onReject: (item: Commitment) => void;
37
+ disabled?: boolean;
38
+ }) {
39
+ if (item.status !== SUGGESTED_STATUS || !item.suggestion) return null;
40
+ const { reason, quote } = item.suggestion;
41
+ return (
42
+ <div className="mt-1 flex flex-wrap items-center gap-2 text-xs text-sky-900 dark:text-sky-200" data-testid="suggestion">
43
+ <span className="min-w-0">
44
+ <span className="font-medium">Suggested:</span> {reason}
45
+ {quote ? <> “{stripMarkdown(quote)}”</> : null}
46
+ </span>
47
+ <button type="button" className={BTN} disabled={disabled} onClick={() => onAccept(item)}>Accept</button>
48
+ <button type="button" className={BTN} disabled={disabled} onClick={() => onReject(item)}>Reject</button>
49
+ </div>
50
+ );
51
+ }
52
+
53
+ /**
54
+ * The "why is this here" line for an item the engine added on its own, with its
55
+ * quote, and Undo: removing it records a rejection, which is what the rule learns from.
56
+ */
57
+ export function EngineReason({ item, onUndo }: { item: Commitment; onUndo?: (item: Commitment) => void }) {
58
+ if (!item.suggestion || item.status === SUGGESTED_STATUS || item.suggestion.mode !== 'act' || item.suggestion.outcome) return null;
59
+ const { reason, quote } = item.suggestion;
60
+ return (
61
+ <div className="mt-2 flex flex-wrap items-center gap-2 text-xs text-gray-500" data-testid="engine-reason">
62
+ <span className="min-w-0">Added by Tandem: {reason}{quote ? <> “{stripMarkdown(quote)}”</> : null}</span>
63
+ {onUndo ? <button type="button" className={BTN} onClick={() => onUndo(item)}>Undo</button> : null}
64
+ </div>
65
+ );
66
+ }
@@ -15,6 +15,7 @@ const STATUS: Record<CommitmentStatus, StatusCell> = {
15
15
  blocked: { label: 'Blocked', dot: 'bg-amber-500' },
16
16
  done: { label: 'Done', dot: 'bg-green-500' },
17
17
  dropped: { label: 'Dropped', dot: 'bg-gray-300' },
18
+ suggested: { label: 'Suggested', dot: 'bg-sky-400' },
18
19
  };
19
20
 
20
21
  /** ONE status per row: never repeated as a pill, a chip or a second word anywhere else. */
@@ -10,6 +10,7 @@ import { itemAsDocument } from './ask-items';
10
10
  import { addDays, questionWindow } from './ask-items-intent';
11
11
  import { speakable } from './briefing/speak';
12
12
  import { localDate } from './today';
13
+ import { isTandemAuthored } from './engine/sources';
13
14
  import type { Commitment, CommitmentApi, CorpusApi, SourceDocument } from './types';
14
15
 
15
16
  export type ActivityWindow = NonNullable<ReturnType<typeof questionWindow>>;
@@ -28,8 +29,6 @@ export const ACTIVITY_QUESTION = new RegExp(
28
29
  `^(?:catch me up on (?:${WINDOWS})\\W*$`
29
30
  + `|(?:what|which|anything|recap|summari[sz]e)\\b(?!.*\\b(?:about|regarding|concerning|with|for|related to)\\b)(?=.*\\b(?:did i|have i|i have|i've|i got|got done|was done|happened|accomplish\\w*|up to|did we)\\b)(?=.*\\b(?:${WINDOWS})\\b))`, 'i');
30
31
 
31
- /** Internal rows that are not "things he did" (the assistant's own bookkeeping). */
32
- const INTERNAL = new Set(['notify_state', 'relay_inbox', 'fleet_status', 'briefing_actions', 'decision', 'briefing']);
33
32
 
34
33
  const ownerOf = (i: Commitment): string | undefined => i.ownerSub || i.scope?.ownerSub || undefined;
35
34
 
@@ -53,7 +52,7 @@ export function activityOf(input: { items: Commitment[]; docs: SourceDocument[];
53
52
  .sort((a, b) => String(a.firstSeenAt).localeCompare(String(b.firstSeenAt)))
54
53
  .map((i) => ({ id: i.id, title: i.title, at: String(i.firstSeenAt), ...(ownerOf(i) ? { owner: ownerOf(i) } : {}) }));
55
54
  const notes = input.docs
56
- .filter((d) => !INTERNAL.has(String(d.source)) && inside(d.occurredAt))
55
+ .filter((d) => !isTandemAuthored(d.source) && inside(d.occurredAt))
57
56
  .sort((a, b) => String(a.occurredAt).localeCompare(String(b.occurredAt)))
58
57
  .map((d) => ({ id: d.id, title: d.title, kind: d.source === 'conversation' ? 'conversation' as const : d.source === 'voice' ? 'voice' as const : 'other' as const, at: String(d.occurredAt), ...(d.scope?.ownerSub ? { owner: d.scope.ownerSub } : {}) }));
59
58
  const byId = new Map(input.items.map((i) => [i.id, i]));
@@ -11,13 +11,13 @@ import { itemIntent, type ItemIntent } from './ask-items-intent';
11
11
  import { dueDay } from './today';
12
12
  import type { Commitment, CommitmentApi, CorpusScope, RetrievedDocument, SourceDocument } from './types';
13
13
  import { isInScope } from './retrieval';
14
+ import { isLiveStatus } from './item-status';
14
15
 
15
16
  export const ITEM_ID_PREFIX = 'item:';
16
17
  /** The item id behind a cited record id, or null when it is a document. */
17
18
  export const itemIdOf = (documentId: string): string | null =>
18
19
  documentId.startsWith(ITEM_ID_PREFIX) ? documentId.slice(ITEM_ID_PREFIX.length) : null;
19
20
  export const ITEM_SUBTYPE = 'tracked_item';
20
- const FINISHED = new Set(['done', 'dropped']);
21
21
  const LINEAR_FINISHED = new Set(['completed', 'canceled', 'cancelled']);
22
22
 
23
23
  export interface ItemContext {
@@ -63,7 +63,7 @@ export function itemAsDocument(item: Commitment, ctx: Omit<ItemContext, 'focusNa
63
63
  export function selectItems(items: Commitment[], intent: ItemIntent, ctx: ItemContext): Commitment[] {
64
64
  const zone = ctx.timeZone ?? 'UTC';
65
65
  const inWindow = (day: string | null) => Boolean(day && (!intent.from || day >= intent.from) && (!intent.to || day <= intent.to));
66
- const finished = (i: Commitment) => FINISHED.has(i.status) || LINEAR_FINISHED.has((i.sync?.stateName ?? '').toLowerCase());
66
+ const finished = (i: Commitment) => !isLiveStatus(i.status) || LINEAR_FINISHED.has((i.sync?.stateName ?? '').toLowerCase());
67
67
  const picked = items.filter((item) => {
68
68
  if (intent.mine && ctx.ownerSub && item.ownerSub !== ctx.ownerSub && !item.ownerSubs?.includes(ctx.ownerSub)) return false;
69
69
  const due = dueDay(item.dueAt, zone);
@@ -11,8 +11,8 @@ import { dueDay, localDate, todayKind } from '../today';
11
11
  import type {
12
12
  Briefing, BriefingEntry, BriefingItem, BriefingKind, BriefingOptions,
13
13
  } from './types';
14
+ import { isLiveStatus } from '../item-status';
14
15
 
15
- const FINISHED = new Set(['done', 'dropped']);
16
16
  const LINEAR_FINISHED = new Set(['completed', 'canceled', 'cancelled']);
17
17
  const DEFAULT_MAX_ITEMS = 8;
18
18
  const KIND_RANK: Record<BriefingKind, number> = { overdue: 0, in_progress: 1, due_today: 2 };
@@ -35,7 +35,7 @@ export function composeBriefing(items: BriefingItem[], options: BriefingOptions)
35
35
  const eligible: BriefingEntry[] = [];
36
36
  for (const item of items) {
37
37
  if (!item.ownerSub || item.ownerSub !== options.ownerSub) continue;
38
- if (FINISHED.has(item.status)) continue;
38
+ if (!isLiveStatus(item.status)) continue;
39
39
  if (item.linearState && LINEAR_FINISHED.has(item.linearState.toLowerCase())) continue;
40
40
  const due = dueDay(item.dueAt, timeZone);
41
41
  const kind = kindOf(item, due, today);
@@ -13,6 +13,7 @@
13
13
  import { dueDay, localDate } from '../today';
14
14
  import { isUnspeakable, partOfDay, speakCount, speakDate, speakable, wordCount } from './speak';
15
15
  import type { BriefingItem } from './types';
16
+ import { isLiveStatus } from '../item-status';
16
17
 
17
18
  export type WeeklyKind = 'done' | 'slipping' | 'upcoming';
18
19
 
@@ -46,7 +47,6 @@ export interface WeeklyOptions {
46
47
  perSection?: number;
47
48
  }
48
49
 
49
- const FINISHED = new Set(['done', 'dropped']);
50
50
  const LINEAR_FINISHED = new Set(['completed', 'canceled', 'cancelled']);
51
51
 
52
52
  const addDays = (day: string, n: number): string => {
@@ -76,7 +76,7 @@ export function composeWeekly(items: BriefingItem[], options: WeeklyOptions): We
76
76
  doneDate = dueDay(item.resolvedAt, timeZone);
77
77
  // "Done" counts only when we know WHEN: a done item with no timestamp is not evidence of this week.
78
78
  if (doneDate && doneDate >= from && doneDate <= today) kind = 'done';
79
- } else if (!FINISHED.has(item.status)) {
79
+ } else if (isLiveStatus(item.status)) {
80
80
  if (due && due < today) kind = 'slipping';
81
81
  else if (item.status === 'blocked' && !due) kind = 'slipping';
82
82
  else if (due && due >= today && due <= to) kind = 'upcoming';
@@ -31,6 +31,7 @@
31
31
  * so the edge is what is read. The join is cached, bounded and fails soft.
32
32
  */
33
33
  import { writePossiblyDone } from './possibly-done';
34
+ import { writeSuggestion } from './engine/suggestion';
34
35
  import { patchEditedItem } from './commitment-edit';
35
36
  import { readStandings } from './standings';
36
37
  import { createParticipantReader } from './participants';
@@ -1372,6 +1373,7 @@ export function createPlanningApi(options: CreateCorpusApiOptions): PlanningApi
1372
1373
  // the Tracker timeline's "done per day" reads this.
1373
1374
  else if (patch.status === 'done' && item.status !== 'done') wire.resolved_at = new Date((options.now ?? Date.now)()).toISOString();
1374
1375
  if (patch.possiblyDone !== undefined) wire.possibly_done = writePossiblyDone(patch.possiblyDone);
1376
+ if (patch.suggestion !== undefined) wire.suggestion = writeSuggestion(patch.suggestion);
1375
1377
  // `null` clears the mark: the tenant reads anything but 'private' as shared.
1376
1378
  if (patch.visibility !== undefined) {
1377
1379
  wire.visibility = patch.visibility ?? '';
@@ -197,6 +197,21 @@ export function isSameCommitment(a: CommitmentIdentity, b: CommitmentIdentity):
197
197
  return jaccard(a.actionTokens, b.actionTokens) >= bar;
198
198
  }
199
199
 
200
+ /**
201
+ * HOW two identities match, for the engine's merge-or-link choice (bd
202
+ * startsim-vrmx5). The same tiers and bars as `isSameCommitment`, reported
203
+ * rather than collapsed: `exact` is Tier 1, `anchored` is Tier 2 with an
204
+ * agreeing subject, `unanchored` is Tier 2 on wording alone.
205
+ */
206
+ export function matchStrength(a: CommitmentIdentity, b: CommitmentIdentity): 'exact' | 'anchored' | 'unanchored' | null {
207
+ if (a.dedupeKey === b.dedupeKey) return 'exact';
208
+ if (subjectsConflict(a, b)) return null;
209
+ const anchored = Boolean(a.subjectKey) && a.subjectKey === b.subjectKey;
210
+ const score = jaccard(a.actionTokens, b.actionTokens);
211
+ if (anchored) return score >= MERGE_THRESHOLD ? 'anchored' : null;
212
+ return score >= UNANCHORED_MERGE_THRESHOLD ? 'unanchored' : null;
213
+ }
214
+
200
215
  /** Two IDENTIFIERS that disagree. The one veto worth having. */
201
216
  function subjectsConflict(a: CommitmentIdentity, b: CommitmentIdentity): boolean {
202
217
  return (
@@ -404,7 +419,7 @@ function toMention(draft: CommitmentDraft, document: SourceDocument): Commitment
404
419
  };
405
420
  }
406
421
 
407
- function identityOf(commitment: Commitment): CommitmentIdentity {
422
+ export function identityOf(commitment: Commitment): CommitmentIdentity {
408
423
  return {
409
424
  subjectKey: commitment.subjectKey,
410
425
  subjectIsIdentifier: MATTER_HYPHENATED.test(commitment.subjectKey) || MATTER_BARE.test(commitment.subjectKey),
@@ -445,7 +460,7 @@ export interface ResolutionResult {
445
460
  export function applyResolutions(
446
461
  commitments: Commitment[],
447
462
  claims: ResolutionClaim[],
448
- context: { documents: SourceDocument[] },
463
+ context: { documents: SourceDocument[]; proposeOnly?: boolean },
449
464
  ): ResolutionResult {
450
465
  const byId = new Map(context.documents.map((document) => [document.id, document]));
451
466
  const out = commitments.map(cloneCommitment);
@@ -478,7 +493,9 @@ export function applyResolutions(
478
493
  }
479
494
 
480
495
  if (!best) continue;
481
- if (best.score >= best.bar) {
496
+ // Under the engine (bd startsim-vrmx5) a later source never closes an item on
497
+ // its own: the claim is kept on the item as "possibly done" for the owner.
498
+ if (best.score >= best.bar && !context.proposeOnly) {
482
499
  best.commitment.status = claim.outcome === 'dropped' ? 'dropped' : 'done';
483
500
  best.commitment.statusReason = claim.quote || claim.statement;
484
501
  best.commitment.resolvedBy = claim.documentId;
@@ -17,6 +17,7 @@ import { normalizeSpeech, spokenWhen, splitWhen } from '../briefing/intent/dates
17
17
  import type { VoiceAction } from '../briefing/intent/types';
18
18
  import { contentWords } from '../briefing/intent/match';
19
19
  import { dueDay, localDate } from '../today';
20
+ import { isLiveStatus } from '../item-status';
20
21
 
21
22
  export interface QueueItem {
22
23
  id: string;
@@ -129,7 +130,7 @@ function rank(a: { i: BriefingItem; day: string }, b: { i: BriefingItem; day: st
129
130
  export function rankQueue(input: QueueInput): { queue: QueueItem[]; older: number } {
130
131
  const today = localDate(input.now, input.timeZone);
131
132
  const skipped = new Set(input.skipped ?? []);
132
- const open = (i: BriefingItem) => !['done', 'dropped'].includes(i.status) && !['completed', 'canceled'].includes(i.linearState ?? '');
133
+ const open = (i: BriefingItem) => isLiveStatus(i.status) && !['completed', 'canceled'].includes(i.linearState ?? '');
133
134
  const ranked = input.items
134
135
  .filter(open)
135
136
  .filter((i) => !skipped.has(i.id))
@@ -8,6 +8,7 @@ import { speakable } from '../briefing/speak';
8
8
  import type { BriefingItem } from '../briefing/types';
9
9
  import { dueDay } from '../today';
10
10
  import type { ConverseSource } from './types';
11
+ import { isLiveStatus } from '../item-status';
11
12
 
12
13
  /** Words that may appear in a due-date question without making it about something else. */
13
14
  const PLAIN = new Set(('what whats what\'s which is are do does did have has had i my me mine the this next last that and a an all any anything ' +
@@ -15,7 +16,6 @@ const PLAIN = new Set(('what whats what\'s which is are do does did have has had
15
16
  'due overdue late behind slipping slipped missed today tomorrow yesterday week month weekend ' +
16
17
  'monday tuesday wednesday thursday friday saturday sunday').split(/\s+/));
17
18
 
18
- const FINISHED = new Set(['done', 'dropped']);
19
19
  const LINEAR_FINISHED = new Set(['completed', 'canceled', 'cancelled']);
20
20
 
21
21
  function listOf(titles: string[], total: number): string {
@@ -46,7 +46,7 @@ export function itemAnswer(input: { question: string; items: BriefingItem[]; now
46
46
  if (extra.some((w) => !covered.has(w) && !['for', 'in', 'on'].includes(w))) return null;
47
47
 
48
48
  const today = intent.today;
49
- const open = items.filter((i) => !FINISHED.has(i.status) && !LINEAR_FINISHED.has(i.linearState ?? '')
49
+ const open = items.filter((i) => isLiveStatus(i.status) && !LINEAR_FINISHED.has(i.linearState ?? '')
50
50
  && (!ownerSub || !i.ownerSub || i.ownerSub === ownerSub)
51
51
  && (!asked.size || (i.focusName && asked.has(i.focusName.trim()))));
52
52
  const dated = open.map((i) => ({ i, day: dueDay(i.dueAt, timeZone) }));
@@ -11,6 +11,7 @@
11
11
  */
12
12
  import { dueDay, localDate } from './today';
13
13
  import type { Commitment } from './types';
14
+ import { isLiveStatus } from './item-status';
14
15
 
15
16
  export type DueBucket = 'overdue' | 'today' | 'week' | 'later';
16
17
 
@@ -41,7 +42,6 @@ export interface DueGroups<T = Commitment> {
41
42
 
42
43
  type Dueable = Pick<Commitment, 'status' | 'dueAt'> & { priority?: number };
43
44
 
44
- const FINISHED = new Set(['done', 'dropped']);
45
45
 
46
46
  /** Whole calendar days from `from` to `to` (both `YYYY-MM-DD`). */
47
47
  export function daysBetween(from: string, to: string): number {
@@ -65,7 +65,7 @@ export function groupDue<T extends Dueable>(
65
65
  let undated = 0;
66
66
  let total = 0;
67
67
  for (const item of items) {
68
- if (FINISHED.has(item.status)) continue;
68
+ if (!isLiveStatus(item.status)) continue;
69
69
  const due = dueDay(item.dueAt, timeZone);
70
70
  if (!due) { undated += 1; continue; }
71
71
  const days = daysBetween(today, due);