@startsimpli/integrations 0.2.201 → 0.2.202

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 (85) hide show
  1. package/package.json +5 -5
  2. package/src/__tests__/briefing-markdown.test.ts +64 -0
  3. package/src/__tests__/converse-cards.test.ts +53 -0
  4. package/src/__tests__/converse-page.test.tsx +148 -37
  5. package/src/__tests__/converse-roci.test.ts +22 -0
  6. package/src/__tests__/converse-structure.test.ts +27 -0
  7. package/src/__tests__/converse-view.test.ts +46 -0
  8. package/src/__tests__/corpus-tracker.test.tsx +32 -176
  9. package/src/__tests__/data-table-logic.test.ts +75 -0
  10. package/src/__tests__/data-table.test.tsx +133 -0
  11. package/src/__tests__/home-brief.test.tsx +25 -40
  12. package/src/__tests__/library-call-shape.test.tsx +164 -0
  13. package/src/__tests__/load-error.test.tsx +1 -1
  14. package/src/__tests__/mini-markdown.test.tsx +24 -0
  15. package/src/__tests__/overview-page.test.tsx +36 -6
  16. package/src/__tests__/plan-shell.test.tsx +6 -4
  17. package/src/__tests__/timeline-events.test.ts +65 -0
  18. package/src/__tests__/timeline-table.test.tsx +66 -0
  19. package/src/__tests__/todo-table-model.test.ts +75 -0
  20. package/src/__tests__/todo-table.test.tsx +202 -0
  21. package/src/__tests__/tracker-timeline-component.test.tsx +4 -4
  22. package/src/__tests__/tracker-timeline-reader.test.ts +1 -1
  23. package/src/comms/__tests__/app-sends-page.test.tsx +69 -0
  24. package/src/comms/api/comms.ts +23 -0
  25. package/src/comms/components/ResultsPanel.tsx +2 -2
  26. package/src/comms/components/SendLog.tsx +20 -8
  27. package/src/comms/components/index.ts +1 -0
  28. package/src/comms/components/pages/AppSendsPage.tsx +58 -0
  29. package/src/comms/hooks/index.ts +8 -3
  30. package/src/components/FolderTree.tsx +12 -3
  31. package/src/components/index.ts +2 -1
  32. package/src/components/pages/ConversePage.tsx +114 -105
  33. package/src/components/pages/LibraryPage.tsx +63 -24
  34. package/src/components/pages/TrackerPage.tsx +170 -474
  35. package/src/components/pages/converse/CardView.tsx +72 -0
  36. package/src/components/pages/converse/SettingsMenu.tsx +37 -0
  37. package/src/components/pages/converse/Thread.tsx +48 -33
  38. package/src/components/pages/converse/useNeedsYou.ts +60 -0
  39. package/src/components/pages/home/BriefCard.tsx +16 -7
  40. package/src/components/pages/home/HomeBriefPage.tsx +6 -91
  41. package/src/components/pages/home/MiniMarkdown.tsx +51 -0
  42. package/src/components/pages/home/{DueSoonLine.tsx → dueSoonText.ts} +2 -11
  43. package/src/components/pages/home/index.ts +1 -1
  44. package/src/components/pages/overview/OverviewPage.tsx +46 -83
  45. package/src/components/pages/plan/TalkPage.tsx +5 -14
  46. package/src/components/pages/plan/TimelinePage.tsx +4 -2
  47. package/src/components/pages/tracker/SweepPanel.tsx +108 -0
  48. package/src/components/pages/tracker/TimelineTable.tsx +70 -0
  49. package/src/components/pages/tracker/TrackerTimeline.tsx +32 -15
  50. package/src/components/table/DataTable.tsx +92 -0
  51. package/src/components/table/RowMenu.tsx +35 -0
  52. package/src/components/table/TablePagination.tsx +63 -0
  53. package/src/components/table/TableToolbar.tsx +56 -0
  54. package/src/components/table/TodoTable.tsx +142 -0
  55. package/src/components/table/index.ts +10 -0
  56. package/src/components/table/table-logic.ts +60 -0
  57. package/src/components/table/todo-model.ts +93 -0
  58. package/src/corpus/briefing/generate-weekly.ts +4 -0
  59. package/src/corpus/briefing/generate.ts +4 -0
  60. package/src/corpus/briefing/index.ts +1 -0
  61. package/src/corpus/briefing/markdown.ts +71 -0
  62. package/src/corpus/client.ts +38 -146
  63. package/src/corpus/converse/cards.ts +69 -0
  64. package/src/corpus/converse/index.ts +6 -0
  65. package/src/corpus/converse/roci.ts +13 -0
  66. package/src/corpus/converse/structure.ts +39 -0
  67. package/src/corpus/converse/view.ts +34 -0
  68. package/src/corpus/index.ts +2 -0
  69. package/src/corpus/participants.ts +220 -0
  70. package/src/corpus/timeline-events.ts +83 -0
  71. package/src/corpus/tracker-sort.ts +9 -3
  72. package/src/corpus/tracker-timeline-client.ts +2 -0
  73. package/src/corpus/tracker-timeline.ts +4 -0
  74. package/src/corpus/types.ts +32 -5
  75. package/src/native/app/__tests__/plan-talk-registry.test.tsx +2 -1
  76. package/src/native/converse/ConverseScreen.tsx +3 -5
  77. package/src/native/home/HomeScreen.tsx +1 -1
  78. package/src/native/home/tab.tsx +1 -2
  79. package/src/native/plan/PlanTab.tsx +1 -2
  80. package/src/native/plan/__tests__/plan-tab.test.tsx +5 -5
  81. package/src/native/talk/TalkTab.tsx +1 -1
  82. package/src/native/talk/__tests__/talk-tab.test.tsx +1 -1
  83. package/src/__tests__/home-needs-your-call.test.tsx +0 -65
  84. package/src/components/pages/tracker/TrackerBoard.tsx +0 -45
  85. package/src/components/pages/tracker/TrackerToolbar.tsx +0 -44
@@ -0,0 +1,63 @@
1
+ /**
2
+ * THE ONE PAGINATION FOOTER: every table (to-dos, Timeline, Library, Sources, Overview)
3
+ * pages through this. A single compact row: rows per page, "1-25 of 41", first / previous,
4
+ * "Page [ n ] of Y", next / last. Server-side only: it never holds rows, it reports the page
5
+ * and the size and the host asks the server.
6
+ */
7
+ import * as React from 'react';
8
+
9
+ import { PAGE_SIZES, pageCount, parsePageInput, rangeLabel, type PageSize } from './table-logic';
10
+
11
+ export interface TablePaginationProps {
12
+ page: number;
13
+ pageSize: PageSize;
14
+ total: number;
15
+ onPage: (page: number) => void;
16
+ onPageSize: (size: PageSize) => void;
17
+ }
18
+
19
+ const NAV = 'rounded border border-gray-300 px-2 py-1 text-xs text-gray-700 hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-40 dark:border-gray-600 dark:text-gray-200 dark:hover:bg-gray-800';
20
+ const FIELD = 'rounded border border-gray-300 bg-white px-1.5 py-1 text-xs text-gray-800 dark:border-gray-600 dark:bg-gray-900 dark:text-gray-100';
21
+
22
+ export function TablePagination({ page, pageSize, total, onPage, onPageSize }: TablePaginationProps) {
23
+ const pages = pageCount(total, pageSize);
24
+ const [jump, setJump] = React.useState(String(page));
25
+ React.useEffect(() => setJump(String(page)), [page]);
26
+ const go = (n: number) => { if (n !== page) onPage(n); };
27
+
28
+ return (
29
+ <nav aria-label="Pagination" className="flex flex-wrap items-center gap-x-4 gap-y-2 border-t border-gray-200 px-3 py-2 text-xs text-gray-600 dark:border-gray-700 dark:text-gray-300">
30
+ <label className="flex items-center gap-1.5">
31
+ Rows per page
32
+ <select
33
+ className={FIELD} aria-label="Rows per page" value={pageSize}
34
+ onChange={(e) => onPageSize(Number(e.target.value) as PageSize)}
35
+ >
36
+ {PAGE_SIZES.map((n) => <option key={n} value={n}>{n}</option>)}
37
+ </select>
38
+ </label>
39
+ <span className="tabular-nums" data-testid="page-range">{rangeLabel(page, pageSize, total)}</span>
40
+ <div className="ml-auto flex items-center gap-1.5">
41
+ <button type="button" className={NAV} aria-label="First page" disabled={page <= 1} onClick={() => go(1)}>«</button>
42
+ <button type="button" className={NAV} aria-label="Previous page" disabled={page <= 1} onClick={() => go(page - 1)}>‹</button>
43
+ <label className="flex items-center gap-1.5">
44
+ Page
45
+ <input
46
+ className={`${FIELD} w-12 text-center tabular-nums`} aria-label="Go to page" inputMode="numeric" value={jump}
47
+ onChange={(e) => setJump(e.target.value)}
48
+ onKeyDown={(e) => {
49
+ if (e.key !== 'Enter') return;
50
+ const n = parsePageInput(jump, pages);
51
+ if (n === null) { setJump(String(page)); return; }
52
+ setJump(String(n));
53
+ go(n);
54
+ }}
55
+ />
56
+ <span>of {pages}</span>
57
+ </label>
58
+ <button type="button" className={NAV} aria-label="Next page" disabled={page >= pages} onClick={() => go(page + 1)}>›</button>
59
+ <button type="button" className={NAV} aria-label="Last page" disabled={page >= pages} onClick={() => go(pages)}>»</button>
60
+ </div>
61
+ </nav>
62
+ );
63
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * THE ONE TOOLBAR: a search box with a magnifier, any number of dropdown filters, and at
3
+ * most ONE filled primary action. Never pill rows for filters, never a second input that
4
+ * looks like search (so add and search cannot be confused: the only filled control is the action).
5
+ */
6
+ import * as React from 'react';
7
+
8
+ export interface FilterOption { value: string; label: string }
9
+
10
+ export function FilterSelect({ label, value, options, onChange }: {
11
+ label: string; value: string; options: FilterOption[]; onChange: (value: string) => void;
12
+ }) {
13
+ return (
14
+ <select
15
+ aria-label={label} value={value} onChange={(e) => onChange(e.target.value)}
16
+ className="h-9 max-w-[13rem] rounded-md border border-gray-300 bg-white px-2.5 text-sm text-gray-800 dark:border-gray-600 dark:bg-gray-900 dark:text-gray-100"
17
+ >
18
+ {options.map((o) => <option key={o.value} value={o.value}>{o.label}</option>)}
19
+ </select>
20
+ );
21
+ }
22
+
23
+ export function TableToolbar({ search, onSearch, searchLabel, searchPlaceholder, action, children }: {
24
+ search: string;
25
+ onSearch: (value: string) => void;
26
+ /** The accessible name, e.g. "Search to-dos". */
27
+ searchLabel: string;
28
+ searchPlaceholder?: string;
29
+ action?: { label: string; onClick: () => void; disabled?: boolean };
30
+ /** Dropdown filters, left to right. */
31
+ children?: React.ReactNode;
32
+ }) {
33
+ return (
34
+ <div className="flex flex-wrap items-center gap-2">
35
+ <div className="relative min-w-[12rem] flex-1 sm:max-w-sm">
36
+ <svg aria-hidden viewBox="0 0 20 20" className="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400" fill="none" stroke="currentColor" strokeWidth="2">
37
+ <circle cx="9" cy="9" r="6" /><path d="m14 14 4 4" strokeLinecap="round" />
38
+ </svg>
39
+ <input
40
+ type="search" role="searchbox" aria-label={searchLabel} placeholder={searchPlaceholder ?? searchLabel}
41
+ value={search} onChange={(e) => onSearch(e.target.value)}
42
+ className="h-9 w-full rounded-md border border-gray-300 bg-white pl-8 pr-3 text-sm text-gray-900 placeholder:text-gray-400 dark:border-gray-600 dark:bg-gray-900 dark:text-gray-100"
43
+ />
44
+ </div>
45
+ {children}
46
+ {action ? (
47
+ <button
48
+ type="button" onClick={action.onClick} disabled={action.disabled}
49
+ className="ml-auto h-9 rounded-md bg-gray-900 px-3.5 text-sm font-medium text-white hover:bg-gray-700 disabled:opacity-50 dark:bg-gray-100 dark:text-gray-900 dark:hover:bg-gray-300"
50
+ >
51
+ + {action.label}
52
+ </button>
53
+ ) : null}
54
+ </div>
55
+ );
56
+ }
@@ -0,0 +1,142 @@
1
+ /**
2
+ * THE ONE TO-DO TABLE. Today, Strategy, a project and every other to-do list mount this and nothing
3
+ * else: checkbox (Mark done) | to-do | project | key | ONE status (dot + label) | due | row menu.
4
+ * Overdue is plain red text in the due column; there are no pill rows, no second status, no chips.
5
+ * Presentational: the host owns the reads and writes, and sorting / paging are its server queries.
6
+ */
7
+ import * as React from 'react';
8
+
9
+ import { stripMarkdown } from '../Markdown';
10
+ import { syncChip } from '../../task-tracker/item-sync';
11
+ import type { Commitment } from '../../corpus/types';
12
+ import { DataTable, type DataTableColumn, type DataTableProps } from './DataTable';
13
+ import { RowMenu, type RowMenuItem } from './RowMenu';
14
+ import { dueCell, statusCell } from './todo-model';
15
+
16
+ export interface TodoTableProps
17
+ extends Pick<DataTableProps<Commitment>, 'sort' | 'onSort' | 'page' | 'pageSize' | 'total' | 'onPage' | 'onPageSize' | 'loading' | 'emptyMessage' | 'topRow'> {
18
+ tableId?: string;
19
+ items: Commitment[];
20
+ now: number;
21
+ timeZone?: string;
22
+ /** Project (focus) names by id. */
23
+ projectNames?: Record<string, string>;
24
+ /** The tracker's display name, for "Open in <tracker>". */
25
+ trackerName?: string;
26
+ /** Hide the project column when the whole table is already one project. */
27
+ hideProject?: boolean;
28
+ onOpen?: (item: Commitment) => void;
29
+ /** Present: the checkbox and menu write. Absent: the table is read-only. */
30
+ onToggleDone?: (item: Commitment, done: boolean) => void;
31
+ onSnooze?: (item: Commitment) => void;
32
+ onDrop?: (item: Commitment) => void;
33
+ /** Extra content under a title (e.g. a "Possibly done" note). */
34
+ below?: (item: Commitment) => React.ReactNode;
35
+ }
36
+
37
+ const MUTED = 'text-gray-500 dark:text-gray-400';
38
+
39
+ export function TodoTable({
40
+ tableId = 'todos', items, now, timeZone, projectNames = {}, trackerName, hideProject, onOpen, onToggleDone, onSnooze, onDrop, below, ...table
41
+ }: TodoTableProps) {
42
+ const columns = React.useMemo<Array<DataTableColumn<Commitment>>>(() => {
43
+ const cols: Array<DataTableColumn<Commitment>> = [
44
+ {
45
+ key: 'done', header: 'Mark done', srOnlyHeader: true, className: 'w-10',
46
+ render: (item) => (
47
+ <input
48
+ type="checkbox" aria-label={`Mark done: ${item.title}`} checked={item.status === 'done'} disabled={!onToggleDone}
49
+ onChange={(e) => onToggleDone?.(item, e.target.checked)}
50
+ className="h-4 w-4 rounded border-gray-300"
51
+ />
52
+ ),
53
+ },
54
+ {
55
+ key: 'title', header: 'To-do', sortable: true,
56
+ render: (item) => {
57
+ const finished = item.status === 'done' || item.status === 'dropped';
58
+ const latest = [...item.mentions].filter((m) => m.quote).sort((a, b) => (b.occurredAt ?? '').localeCompare(a.occurredAt ?? ''))[0];
59
+ return (
60
+ <div className="min-w-0 max-w-[7rem] md:max-w-[20rem]">
61
+ {onOpen ? (
62
+ <button type="button" onClick={() => onOpen(item)} className={`block max-w-full truncate text-left font-medium hover:underline ${finished ? 'text-gray-500 line-through' : 'text-gray-900 dark:text-gray-100'}`}>{item.title}</button>
63
+ ) : <span className="block truncate font-medium text-gray-900 dark:text-gray-100">{item.title}</span>}
64
+ {item.status === 'blocked' && item.statusReason ? <span className={`block truncate text-xs ${MUTED}`}>Blocked: {item.statusReason}</span> : null}
65
+ {latest ? <span className={`block truncate text-xs ${MUTED}`} data-testid="item-evidence">“{stripMarkdown(latest.quote)}”</span> : null}
66
+ {below?.(item)}
67
+ </div>
68
+ );
69
+ },
70
+ },
71
+ ];
72
+ if (!hideProject) {
73
+ cols.push({
74
+ key: 'project', header: 'Project', hideOnPhone: true, className: 'w-40 max-w-[10rem]',
75
+ render: (item) => {
76
+ const name = item.focusId ? projectNames[item.focusId] : undefined;
77
+ return name
78
+ ? <span className="block truncate text-gray-700 dark:text-gray-200" title={name}>{name}{item.projectBasis ? <span className={`italic ${MUTED}`}> (guessed)</span> : null}</span>
79
+ : <span className={MUTED}>–</span>;
80
+ },
81
+ });
82
+ }
83
+ cols.push(
84
+ {
85
+ key: 'key', header: 'Key', hideOnPhone: true, className: 'w-24 whitespace-nowrap',
86
+ render: (item) => {
87
+ const chip = item.sync ? syncChip(item.sync, trackerName) : null;
88
+ if (!chip?.identifier) return <span className={MUTED}>–</span>;
89
+ const attention = item.sync && (item.sync.state === 'error' || item.sync.state === 'conflict');
90
+ return (
91
+ <span className="inline-flex items-center gap-1 tabular-nums">
92
+ {chip.url
93
+ ? <a href={chip.url} target="_blank" rel="noreferrer" title={chip.openLabel} className={`${MUTED} hover:underline`}>{chip.identifier}</a>
94
+ : <span className={MUTED}>{chip.identifier}</span>}
95
+ {attention ? <span role="img" aria-label={chip.badge.a11y} title={chip.badge.detail ?? chip.badge.text} className="text-amber-600">!</span> : null}
96
+ </span>
97
+ );
98
+ },
99
+ },
100
+ {
101
+ key: 'status', header: 'Status', sortable: true, className: 'md:w-36 whitespace-nowrap',
102
+ render: (item) => {
103
+ const s = statusCell(item.status);
104
+ return (
105
+ <span className="inline-flex items-center gap-2 whitespace-nowrap text-gray-700 dark:text-gray-200" title={item.statusReason || undefined}>
106
+ <span aria-hidden className={`h-2 w-2 shrink-0 rounded-full ${s.dot}`} /><span className="sr-only md:not-sr-only">{s.label}</span>
107
+ </span>
108
+ );
109
+ },
110
+ },
111
+ {
112
+ key: 'due', header: 'Due', sortable: true, className: 'md:w-32 whitespace-nowrap',
113
+ render: (item) => {
114
+ const d = dueCell(item, now, timeZone);
115
+ const tone = d.tone === 'overdue' ? 'font-medium text-red-600 dark:text-red-400' : d.tone === 'none' ? MUTED : 'text-gray-700 dark:text-gray-200';
116
+ return <span className={tone} title={d.exact} data-due-tone={d.tone}>{d.text}</span>;
117
+ },
118
+ },
119
+ {
120
+ key: 'menu', header: 'Actions', srOnlyHeader: true, className: 'w-10 text-right',
121
+ render: (item) => {
122
+ const chip = item.sync ? syncChip(item.sync, trackerName) : null;
123
+ const entries: RowMenuItem[] = [];
124
+ if (onOpen) entries.push({ label: 'Edit', onSelect: () => onOpen(item) });
125
+ if (onSnooze) entries.push({ label: 'Snooze a week', onSelect: () => onSnooze(item) });
126
+ if (chip?.url) entries.push({ label: chip.openLabel, href: chip.url });
127
+ if (onDrop) entries.push({ label: 'Drop', onSelect: () => onDrop(item) });
128
+ return entries.length ? <RowMenu label={`Actions for ${item.title}`} items={entries} /> : null;
129
+ },
130
+ },
131
+ );
132
+ return cols;
133
+ }, [hideProject, onOpen, onToggleDone, onSnooze, onDrop, projectNames, trackerName, now, timeZone, below]);
134
+
135
+ return (
136
+ <DataTable<Commitment>
137
+ tableId={tableId} columns={columns} rows={items} rowKey={(i) => i.externalId}
138
+ rowClassName={(i) => (i.status === 'done' || i.status === 'dropped' ? 'opacity-70' : '')}
139
+ {...table}
140
+ />
141
+ );
142
+ }
@@ -0,0 +1,10 @@
1
+ export { DataTable } from './DataTable';
2
+ export type { DataTableColumn, DataTableProps } from './DataTable';
3
+ export { TablePagination } from './TablePagination';
4
+ export { TableToolbar, FilterSelect } from './TableToolbar';
5
+ export type { FilterOption } from './TableToolbar';
6
+ export * from './table-logic';
7
+ export { TodoTable } from './TodoTable';
8
+ export type { TodoTableProps } from './TodoTable';
9
+ export { RowMenu } from './RowMenu';
10
+ export * from './todo-model';
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Pure rules for the ONE shared table: sorting, paging, and the remembered page size.
3
+ * No React here, so every table (to-dos, Timeline, Library, Sources, Overview) pages
4
+ * and sorts the same way and the rules are testable without a DOM.
5
+ */
6
+ export type SortDir = 'asc' | 'desc';
7
+ export interface TableSort { key: string; dir: SortDir }
8
+
9
+ export const PAGE_SIZES = [25, 50, 100] as const;
10
+ export type PageSize = (typeof PAGE_SIZES)[number];
11
+ export const DEFAULT_PAGE_SIZE: PageSize = 25;
12
+
13
+ /** Click a header: a new column starts ascending, the same column flips. */
14
+ export function nextSort(current: TableSort | null, key: string): TableSort {
15
+ if (current && current.key === key) return { key, dir: current.dir === 'asc' ? 'desc' : 'asc' };
16
+ return { key, dir: 'asc' };
17
+ }
18
+
19
+ export function ariaSort(current: TableSort | null, key: string): 'ascending' | 'descending' | 'none' {
20
+ if (!current || current.key !== key) return 'none';
21
+ return current.dir === 'asc' ? 'ascending' : 'descending';
22
+ }
23
+
24
+ export const pageCount = (total: number, size: number): number => Math.max(1, Math.ceil(total / Math.max(1, size)));
25
+
26
+ export const clampPage = (page: number, total: number, size: number): number =>
27
+ Math.min(Math.max(1, Math.floor(page) || 1), pageCount(total, size));
28
+
29
+ /** "1-25 of 41". An empty table reads "0 of 0". */
30
+ export function rangeLabel(page: number, size: number, total: number): string {
31
+ if (total <= 0) return '0 of 0';
32
+ const from = (page - 1) * size + 1;
33
+ const to = Math.min(total, page * size);
34
+ return `${from}-${to} of ${total}`;
35
+ }
36
+
37
+ /** The jump box: a whole number, clamped into range; anything else is no jump. */
38
+ export function parsePageInput(raw: string, pages: number): number | null {
39
+ const text = raw.trim();
40
+ if (!/^\d+$/.test(text)) return null;
41
+ return Math.min(Math.max(1, Number(text)), pages);
42
+ }
43
+
44
+ interface Store { getItem(key: string): string | null; setItem(key: string, value: string): void }
45
+ const keyFor = (table: string) => `tandem.table.${table}.pageSize`;
46
+ const browserStore = (): Store | null => {
47
+ try { return typeof localStorage === 'undefined' ? null : localStorage; } catch { return null; }
48
+ };
49
+
50
+ /** Rows per page, remembered per table. Storage can be blocked or throw; the default stands in. */
51
+ export function readPageSize(table: string, store: Store | null = browserStore()): PageSize {
52
+ try {
53
+ const n = Number(store?.getItem(keyFor(table)));
54
+ return (PAGE_SIZES as readonly number[]).includes(n) ? (n as PageSize) : DEFAULT_PAGE_SIZE;
55
+ } catch { return DEFAULT_PAGE_SIZE; }
56
+ }
57
+
58
+ export function writePageSize(table: string, size: PageSize, store: Store | null = browserStore()): void {
59
+ try { store?.setItem(keyFor(table), String(size)); } catch { /* remembered size is a convenience */ }
60
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ * What the to-do table shows, as data: the ONE status (dot + label), the due cell, and the
3
+ * query the toolbar and headers become. Pure; the table component only draws these.
4
+ */
5
+ import type { Commitment, CommitmentQuery, CommitmentSort, CommitmentStatus } from '../../corpus/types';
6
+ import { localDate, dueDay } from '../../corpus/today';
7
+ import { daysBetween } from '../../corpus/due-groups';
8
+ import type { PageSize, TableSort } from './table-logic';
9
+
10
+ export interface StatusCell { label: string; /** Tailwind classes for the dot. */ dot: string }
11
+
12
+ const STATUS: Record<CommitmentStatus, StatusCell> = {
13
+ open: { label: 'To do', dot: 'bg-gray-400' },
14
+ in_progress: { label: 'In progress', dot: 'bg-blue-500' },
15
+ blocked: { label: 'Blocked', dot: 'bg-amber-500' },
16
+ done: { label: 'Done', dot: 'bg-green-500' },
17
+ dropped: { label: 'Dropped', dot: 'bg-gray-300' },
18
+ };
19
+
20
+ /** ONE status per row: never repeated as a pill, a chip or a second word anywhere else. */
21
+ export const statusCell = (status: CommitmentStatus): StatusCell => STATUS[status] ?? STATUS.open;
22
+
23
+ export interface DueCell {
24
+ text: string;
25
+ /** `overdue` is the only red: plain coloured text in the due column, never a pill. */
26
+ tone: 'overdue' | 'plain' | 'none';
27
+ /** The exact day, for the hover. */
28
+ exact?: string;
29
+ }
30
+
31
+ const plural = (n: number, unit: string) => `${n} ${unit}${n === 1 ? '' : 's'}`;
32
+
33
+ export function dueCell(item: Pick<Commitment, 'dueAt' | 'status'>, now: number, timeZone = 'UTC'): DueCell {
34
+ const day = dueDay(item.dueAt, timeZone);
35
+ if (!day) return { text: '–', tone: 'none' };
36
+ const days = daysBetween(localDate(now, timeZone), day);
37
+ const finished = item.status === 'done' || item.status === 'dropped';
38
+ const date = new Date(`${day}T00:00:00Z`).toLocaleDateString('en-US', { month: 'short', day: 'numeric', timeZone: 'UTC' });
39
+ if (days < 0) return { text: finished ? date : `${plural(-days, 'day')} late`, tone: finished ? 'plain' : 'overdue', exact: day };
40
+ if (days === 0) return { text: 'Today', tone: 'plain', exact: day };
41
+ if (days === 1) return { text: 'Tomorrow', tone: 'plain', exact: day };
42
+ if (days <= 7) return { text: `In ${plural(days, 'day')}`, tone: 'plain', exact: day };
43
+ return { text: date, tone: 'plain', exact: day };
44
+ }
45
+
46
+ export const TODO_STATUS_FILTERS = [
47
+ { value: 'open', label: 'Open' },
48
+ { value: 'todo', label: 'To do' },
49
+ { value: 'in_progress', label: 'In progress' },
50
+ { value: 'blocked', label: 'Blocked' },
51
+ { value: 'done', label: 'Done' },
52
+ { value: 'all', label: 'All' },
53
+ ] as const;
54
+
55
+ const STATUS_QUERY: Record<string, CommitmentStatus[] | undefined> = {
56
+ open: ['open', 'in_progress', 'blocked'],
57
+ todo: ['open'],
58
+ in_progress: ['in_progress'],
59
+ blocked: ['blocked'],
60
+ done: ['done', 'dropped'],
61
+ all: undefined,
62
+ };
63
+
64
+ /** Sortable headers → server sort keys. Project is an edge, not an attribute, so it cannot be ordered server-side. */
65
+ export const TODO_SORT_KEYS: Record<string, CommitmentSort> = { title: 'title', due: 'due', status: 'status' };
66
+
67
+ export interface TodoTableState {
68
+ search: string;
69
+ status: string;
70
+ project: string;
71
+ sort: TableSort | null;
72
+ page: number;
73
+ pageSize: PageSize;
74
+ }
75
+
76
+ /** Search, filters, sort and page all go to the server. */
77
+ export function todoQuery(state: TodoTableState, fixedFocus?: string): CommitmentQuery {
78
+ const focus = fixedFocus || state.project;
79
+ const status = STATUS_QUERY[state.status] ?? (state.status === 'all' ? undefined : STATUS_QUERY.open);
80
+ const sort = state.sort ? TODO_SORT_KEYS[state.sort.key] : undefined;
81
+ const search = state.search.trim();
82
+ return {
83
+ ...(status ? { status } : {}),
84
+ subtype: ['action', 'requirement'],
85
+ withFocus: true,
86
+ ...(focus ? { focus } : {}),
87
+ ...(search ? { search } : {}),
88
+ sort: sort ?? 'due',
89
+ ...(sort && state.sort ? { sortDir: state.sort.dir } : {}),
90
+ page: state.page,
91
+ pageSize: state.pageSize,
92
+ };
93
+ }
@@ -5,6 +5,7 @@
5
5
  * best-effort. SAME deps, SAME store, SAME audio path; only the composer and the
6
6
  * wording differ. The row is the OWNER'S: there is no delivery beyond the app.
7
7
  */
8
+ import { weeklyMarkdown } from './markdown';
8
9
  import { hashString } from './cache-key';
9
10
  import { composeWeekly, weeklyScript } from './weekly';
10
11
  import { createEntityBriefingStore, type BriefingRecord } from './store';
@@ -17,6 +18,8 @@ export const weeklyExternalId = (ownerSub: string, localDate: string) => `weekly
17
18
  export interface WeeklyResult {
18
19
  summaryId: string;
19
20
  text: string;
21
+ /** The same week as a short structured view for the screen. */
22
+ markdown?: string;
20
23
  audioUrl: string | null;
21
24
  audioReason?: string;
22
25
  counts: WeeklySummary['counts'];
@@ -46,6 +49,7 @@ export async function generateWeekly(deps: BriefingDeps, request: BriefingReques
46
49
  const result = (record: BriefingRecord, audioUrl: string | null, cached: boolean, reason?: string): WeeklyResult => ({
47
50
  summaryId: record.id,
48
51
  text: record.text,
52
+ markdown: weeklyMarkdown(summary),
49
53
  audioUrl,
50
54
  ...(audioUrl ? {} : { audioReason: reason ?? record.audioReason ?? 'No audio was generated.' }),
51
55
  counts: summary.counts,
@@ -15,6 +15,7 @@
15
15
  import type { CorpusHttp } from '../client';
16
16
  import { briefingContentHash } from './cache-key';
17
17
  import { composeBriefing } from './compose';
18
+ import { briefingMarkdown } from './markdown';
18
19
  import { writeBriefingScript, type BriefingScriptLlm } from './script';
19
20
  import {
20
21
  briefingExternalId, createEntityBriefingStore, offsetsOf,
@@ -70,6 +71,8 @@ export interface BriefingRequest {
70
71
  export interface BriefingResult {
71
72
  briefingId: string;
72
73
  text: string;
74
+ /** The same items as a short structured view for the screen (the spoken `text` is for the voice). */
75
+ markdown?: string;
73
76
  audioUrl: string | null;
74
77
  /** Why there is no audio, when there is none. */
75
78
  audioReason?: string;
@@ -108,6 +111,7 @@ export async function generateBriefing(deps: BriefingDeps, request: BriefingRequ
108
111
  const result = (record: BriefingRecord, audioUrl: string | null, cached: boolean, reason?: string): BriefingResult => ({
109
112
  briefingId: record.id,
110
113
  text: record.text,
114
+ markdown: briefingMarkdown(record.items, record.remaining),
111
115
  audioUrl,
112
116
  ...(audioUrl ? {} : { audioReason: reason ?? record.audioReason ?? 'No audio was generated.' }),
113
117
  items: record.items,
@@ -18,3 +18,4 @@ export { briefingContentHash, hashString, SCRIPT_VERSION } from './cache-key';
18
18
  export * from './intent';
19
19
  export * from './actions';
20
20
  export * from './reply';
21
+ export { briefingMarkdown, weeklyMarkdown } from './markdown';
@@ -0,0 +1,71 @@
1
+ /**
2
+ * THE BRIEF ON SCREEN: the same composed items the spoken script is about, laid out to read at a glance
3
+ * (headings, one short bullet per item). The spoken text is NOT this: it is written for a voice and its
4
+ * offsets resolve voice replies, so it stays as it is. Pure and deterministic: no model, no clock.
5
+ */
6
+ import type { WeeklyEntry, WeeklySummary } from './weekly';
7
+ import type { BriefingEntry, BriefingKind } from './types';
8
+
9
+ const GROUPS: Array<{ kind: BriefingKind; heading: string }> = [
10
+ { kind: 'overdue', heading: 'Overdue' },
11
+ { kind: 'in_progress', heading: 'In progress' },
12
+ { kind: 'due_today', heading: 'Due today' },
13
+ ];
14
+
15
+ const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
16
+
17
+ /** `2026-11-03` -> `Nov 3`; anything else is dropped rather than shown raw. */
18
+ function shortDate(day: string | null): string {
19
+ const m = day ? /^(\d{4})-(\d{2})-(\d{2})/.exec(day) : null;
20
+ const month = m ? MONTHS[Number(m[2]) - 1] : undefined;
21
+ return m && month ? `${month} ${Number(m[3])}` : '';
22
+ }
23
+
24
+ /** One line, no markup characters: a title cannot open a heading, a list or bold. */
25
+ function plain(text: string): string {
26
+ return text.replace(/[*_#`<>[\]]/g, '').replace(/\s+/g, ' ').trim();
27
+ }
28
+
29
+ export function briefingMarkdown(items: BriefingEntry[], remaining: number): string {
30
+ if (items.length === 0 && remaining <= 0) return 'Nothing is due today, and nothing is overdue.';
31
+ const blocks: string[] = [];
32
+ for (const { kind, heading } of GROUPS) {
33
+ const rows = items.filter((i) => i.kind === kind);
34
+ if (!rows.length) continue;
35
+ const lines = rows.map((i) => {
36
+ const bits = [`**${plain(i.title) || 'Untitled'}**`];
37
+ if (i.group && i.group !== 'Personal') bits.push(plain(i.group));
38
+ const when = kind === 'overdue' ? shortDate(i.dueDate) : '';
39
+ if (when) bits.push(`was due ${when}`);
40
+ return `- ${bits.join(' · ')}`;
41
+ });
42
+ blocks.push([`## ${heading}`, ...lines].join('\n'));
43
+ }
44
+ if (remaining > 0) blocks.push(`_${remaining} more not shown._`);
45
+ return blocks.join('\n\n');
46
+ }
47
+
48
+ /** The week on screen: finished, slipping, coming up. One short bullet each, with the date that matters. */
49
+ export function weeklyMarkdown(summary: WeeklySummary): string {
50
+ if (summary.empty) return 'Nothing finished, nothing slipping and nothing due in the next week.';
51
+ const row = (e: WeeklyEntry, date: string, label: string) => {
52
+ const bits = [`**${plain(e.title) || 'Untitled'}**`];
53
+ if (e.group && e.group !== 'Personal') bits.push(plain(e.group));
54
+ const d = shortDate(date);
55
+ if (d) bits.push(`${label} ${d}`.trim());
56
+ return `- ${bits.join(' · ')}`;
57
+ };
58
+ const sections: Array<[string, WeeklyEntry[], number, (e: WeeklyEntry) => string]> = [
59
+ ['Finished', summary.done, summary.counts.done, (e) => row(e, e.doneDate ?? '', '')],
60
+ ['Slipping', summary.slipping, summary.counts.slipping, (e) => row(e, e.dueDate ?? '', 'was due')],
61
+ ['Coming up', summary.upcoming, summary.counts.upcoming, (e) => row(e, e.dueDate ?? '', 'due')],
62
+ ];
63
+ const blocks: string[] = [];
64
+ for (const [title, rows, total, line] of sections) {
65
+ if (!rows.length) continue;
66
+ const lines = rows.map(line);
67
+ if (total > rows.length) lines.push(`_${total - rows.length} more._`);
68
+ blocks.push([`## ${title} · ${total}`, ...lines].join('\n'));
69
+ }
70
+ return blocks.join('\n\n');
71
+ }