@startsimpli/integrations 0.2.133 → 0.2.135

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 (31) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/corpus-planning.test.tsx +13 -3
  3. package/src/__tests__/corpus-tracker.test.tsx +53 -69
  4. package/src/__tests__/focus-standings.test.tsx +3 -1
  5. package/src/__tests__/home-brief.test.tsx +84 -0
  6. package/src/__tests__/project-surfaces.test.tsx +1 -1
  7. package/src/__tests__/work-groups.test.ts +181 -0
  8. package/src/components/index.ts +1 -0
  9. package/src/components/pages/ConnectionsPage.tsx +7 -1402
  10. package/src/components/pages/PlanningPage.tsx +129 -67
  11. package/src/components/pages/TrackerPage.tsx +174 -149
  12. package/src/components/pages/connections/CapabilityPicker.tsx +75 -0
  13. package/src/components/pages/connections/CatalogCard.tsx +300 -0
  14. package/src/components/pages/connections/ConnectionCard.tsx +489 -0
  15. package/src/components/pages/connections/ConnectionForms.tsx +215 -0
  16. package/src/components/pages/connections/MemberPolicyToggle.tsx +106 -0
  17. package/src/components/pages/connections/bound-api.ts +175 -0
  18. package/src/components/pages/connections/copy.ts +74 -0
  19. package/src/components/pages/home/BriefCard.tsx +84 -0
  20. package/src/components/pages/home/CompactItemRow.tsx +61 -0
  21. package/src/components/pages/home/DueAcrossProjects.tsx +74 -0
  22. package/src/components/pages/home/HomeBriefPage.tsx +112 -0
  23. package/src/components/pages/home/RecentNotes.tsx +69 -0
  24. package/src/components/pages/home/index.ts +10 -0
  25. package/src/components/pages/home/useProjectNames.ts +23 -0
  26. package/src/components/pages/work-items.tsx +15 -9
  27. package/src/corpus/due-groups.ts +81 -0
  28. package/src/corpus/focus-overview.ts +54 -0
  29. package/src/corpus/index.ts +10 -0
  30. package/src/corpus/note-actions.ts +44 -0
  31. package/src/corpus/tracker-groups.ts +84 -0
@@ -0,0 +1,61 @@
1
+ /**
2
+ * ONE LINE PER ITEM — title, project chip, due, sync chip (bd startsim-cpzoz).
3
+ * The row Home's "Due across projects" and the Tracker both use, so the two
4
+ * screens cannot disagree about what a row says. Presentational: it fetches
5
+ * nothing and owns no state. Anything richer (the quote, the meetings it came
6
+ * from) is behind `onOpen`, not on the row.
7
+ */
8
+ import * as React from 'react';
9
+
10
+ import { ExternalLinkChip } from '../task-tracker/ExternalLinkChip';
11
+ import type { Commitment } from '../../../corpus/types';
12
+
13
+ /** "2d late", "today", "tomorrow", "in 3d", else a short date. */
14
+ export function dueLabel(days: number | null, due: string | null): string {
15
+ if (days === null || !due) return '';
16
+ if (days < 0) return `${-days}d late`;
17
+ if (days === 0) return 'today';
18
+ if (days === 1) return 'tomorrow';
19
+ if (days <= 7) return `in ${days}d`;
20
+ const d = new Date(`${due}T00:00:00Z`);
21
+ return d.toLocaleDateString(undefined, { month: 'short', day: 'numeric', timeZone: 'UTC' });
22
+ }
23
+
24
+ export interface CompactItemRowProps {
25
+ item: Commitment;
26
+ days: number | null;
27
+ due: string | null;
28
+ /** Project (focus) name; `undefined` shows no chip. */
29
+ project?: string;
30
+ trackerName?: string;
31
+ onOpen?: (item: Commitment) => void;
32
+ /** Per-row controls the host owns (archive, snooze, complete). */
33
+ actions?: React.ReactNode;
34
+ /** Show the status word for items that are not plainly open. Default true. */
35
+ showStatus?: boolean;
36
+ }
37
+
38
+ const CHIP = 'inline-flex max-w-[14rem] items-center truncate rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 text-xs text-gray-700';
39
+
40
+ export function CompactItemRow({ item, days, due, project, trackerName, onOpen, actions, showStatus = true }: CompactItemRowProps) {
41
+ const late = days !== null && days < 0 && item.status !== 'done';
42
+ const label = dueLabel(days, due);
43
+ return (
44
+ <li className="flex items-center gap-3 border-b border-gray-100 py-2 last:border-b-0" data-testid="item-row">
45
+ <div className="min-w-0 flex-1">
46
+ {onOpen ? (
47
+ <button type="button" className="block max-w-full truncate text-left text-sm font-medium text-gray-900 hover:underline" onClick={() => onOpen(item)}>
48
+ {item.title}
49
+ </button>
50
+ ) : <span className="block truncate text-sm font-medium text-gray-900">{item.title}</span>}
51
+ </div>
52
+ <div className="flex shrink-0 items-center gap-2">
53
+ {project ? <span className={CHIP} title={project}>{project}</span> : null}
54
+ {showStatus && item.status !== 'open' && item.status !== 'done' ? <span className={CHIP}>{item.status.replace('_', ' ')}</span> : null}
55
+ {item.sync ? <ExternalLinkChip sync={item.sync} trackerName={trackerName} className={CHIP} /> : null}
56
+ {label ? <span className={`w-16 text-right text-xs ${late ? 'font-semibold text-red-700' : 'text-gray-500'}`}>{label}</span> : null}
57
+ {actions}
58
+ </div>
59
+ </li>
60
+ );
61
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * DUE ACROSS PROJECTS — Overdue / Today / This week / Later, one row each, with
3
+ * the project as a chip (bd startsim-cpzoz). Takes the already-grouped result of
4
+ * `groupDue` so the rule lives in one tested place. Later is folded; so are the
5
+ * rows past `perGroup`, with the count on the button.
6
+ */
7
+ import * as React from 'react';
8
+
9
+ import type { DueGroups } from '../../../corpus/due-groups';
10
+ import type { Commitment } from '../../../corpus/types';
11
+ import { CompactItemRow } from './CompactItemRow';
12
+
13
+ const TONE: Record<string, string> = { overdue: 'text-red-700', today: 'text-gray-900', week: 'text-gray-900', later: 'text-gray-500' };
14
+
15
+ export function DueAcrossProjects({
16
+ due, projectNames = {}, perGroup = 6, trackerName, onOpen, onSeeAll,
17
+ }: {
18
+ due: DueGroups;
19
+ projectNames?: Record<string, string>;
20
+ perGroup?: number;
21
+ trackerName?: string;
22
+ onOpen?: (item: Commitment) => void;
23
+ /** "Open the Tracker" — shown when there is more than the home lists. */
24
+ onSeeAll?: () => void;
25
+ }) {
26
+ const [open, setOpen] = React.useState<Record<string, boolean>>({});
27
+ if (due.total === 0) {
28
+ return <p className="text-sm text-gray-500">Nothing is due. {due.undated ? `${due.undated} open item${due.undated === 1 ? ' has' : 's have'} no date.` : ''}</p>;
29
+ }
30
+ return (
31
+ <div className="space-y-4">
32
+ {due.groups.map((group) => {
33
+ const folded = group.bucket === 'later' && !open.later;
34
+ const shown = open[group.bucket] ? group.entries : group.entries.slice(0, perGroup);
35
+ return (
36
+ <section key={group.bucket} aria-label={group.label}>
37
+ <h3 className={`mb-1 flex items-baseline gap-2 text-sm font-semibold ${TONE[group.bucket]}`}>
38
+ {group.label}
39
+ <span className="text-xs font-normal text-gray-500">{group.entries.length}</span>
40
+ {group.bucket === 'later' ? (
41
+ <button type="button" className="text-xs font-normal text-blue-700 underline" onClick={() => setOpen({ ...open, later: !open.later })}>
42
+ {open.later ? 'hide' : 'show'}
43
+ </button>
44
+ ) : null}
45
+ </h3>
46
+ {folded ? null : (
47
+ <ul>
48
+ {shown.map((entry) => (
49
+ <CompactItemRow
50
+ key={entry.item.externalId}
51
+ item={entry.item} days={entry.days} due={entry.due}
52
+ project={entry.item.focusId ? projectNames[entry.item.focusId] : undefined}
53
+ trackerName={trackerName} onOpen={onOpen}
54
+ />
55
+ ))}
56
+ </ul>
57
+ )}
58
+ {!folded && group.entries.length > shown.length ? (
59
+ <button type="button" className="mt-1 text-xs text-blue-700 underline" onClick={() => setOpen({ ...open, [group.bucket]: true })}>
60
+ Show {group.entries.length - shown.length} more
61
+ </button>
62
+ ) : null}
63
+ </section>
64
+ );
65
+ })}
66
+ {due.undated || onSeeAll ? (
67
+ <p className="text-xs text-gray-500">
68
+ {due.undated ? `${due.undated} open item${due.undated === 1 ? ' has' : 's have'} no date. ` : ''}
69
+ {onSeeAll ? <button type="button" className="text-blue-700 underline" onClick={onSeeAll}>Open the Tracker</button> : null}
70
+ </p>
71
+ ) : null}
72
+ </div>
73
+ );
74
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * HOME — three things, fast to scan (bd startsim-cpzoz): today's brief (the text
3
+ * the app speaks), what is due across projects, and the recent notes with the
4
+ * actions that came out of them.
5
+ *
6
+ * `<HomeBriefPage brief={...} corpus={...} />` is the whole integration; an app
7
+ * adds a heading and navigation callbacks. Everything is read through the same
8
+ * injected corpus clients as the other page composers, and every list is a
9
+ * server-paginated read (one page each): open items with their project, the
10
+ * last 30 days of changed items for the notes join, the newest documents, and
11
+ * the project names.
12
+ */
13
+ import * as React from 'react';
14
+
15
+ import { groupDue } from '../../../corpus/due-groups';
16
+ import { isTask } from '../../../corpus/tracker-groups';
17
+ import { actionsByNote } from '../../../corpus/note-actions';
18
+ import { failureMessage } from '../../../corpus/work-item-logic';
19
+ import type { Commitment, CommitmentApi, CorpusApi, Focus, PlanningApi } from '../../../corpus/types';
20
+ import { BriefCard, type BriefCardApi } from './BriefCard';
21
+ import { DueAcrossProjects } from './DueAcrossProjects';
22
+ import { RecentNotes, type RecentNote } from './RecentNotes';
23
+
24
+ const NOTE_SUBTYPES = new Set(['meeting', 'voice_note']);
25
+ const DAY = 86_400_000;
26
+
27
+ export interface HomeBriefPageProps {
28
+ brief: BriefCardApi;
29
+ corpus: CorpusApi & CommitmentApi;
30
+ /** Names the project chips. Absent = no chips. */
31
+ listFocuses?: PlanningApi['listFocuses'];
32
+ timeZone?: string;
33
+ now?: number;
34
+ trackerName?: string;
35
+ onAsk?: () => void;
36
+ onOpenTracker?: () => void;
37
+ onOpenNote?: (documentId: string) => void;
38
+ onOpenItem?: (item: Commitment) => void;
39
+ /** How many recent notes to list. Default 6. */
40
+ noteCount?: number;
41
+ }
42
+
43
+ interface Data { open: Commitment[]; recent: Commitment[]; notes: RecentNote[]; names: Record<string, string> }
44
+
45
+ function Section({ title, children }: { title: string; children: React.ReactNode }) {
46
+ return (
47
+ <section className="space-y-3">
48
+ <h2 className="text-lg font-semibold text-gray-900">{title}</h2>
49
+ {children}
50
+ </section>
51
+ );
52
+ }
53
+
54
+ export function HomeBriefPage({
55
+ brief, corpus, listFocuses, timeZone, now, trackerName, onAsk, onOpenTracker, onOpenNote, onOpenItem, noteCount = 6,
56
+ }: HomeBriefPageProps) {
57
+ // Frozen once: a clock that changes every render re-fires the load effect.
58
+ const [mountedAt] = React.useState(() => Date.now());
59
+ const clock = now ?? mountedAt;
60
+ const corpusRef = React.useRef(corpus);
61
+ corpusRef.current = corpus;
62
+ const focusesRef = React.useRef(listFocuses);
63
+ focusesRef.current = listFocuses;
64
+ const [data, setData] = React.useState<Data | null>(null);
65
+ const [error, setError] = React.useState('');
66
+
67
+ React.useEffect(() => {
68
+ let live = true;
69
+ (async () => {
70
+ const c = corpusRef.current;
71
+ try {
72
+ const [open, recent, docs, focuses] = await Promise.all([
73
+ c.listCommitments({ status: ['open', 'in_progress', 'blocked'], withFocus: true, pageSize: 200 }),
74
+ c.listCommitments({ changedAfter: new Date(clock - 30 * DAY).toISOString(), pageSize: 200 }),
75
+ c.listDocuments({ order: 'recent', occurredAfter: new Date(clock - 30 * DAY).toISOString(), pageSize: noteCount * 3 }),
76
+ focusesRef.current ? focusesRef.current({ pageSize: 200 }).then((p) => p.results).catch((): Focus[] => []) : Promise.resolve([] as Focus[]),
77
+ ]);
78
+ if (!live) return;
79
+ const noteDocs = docs.results.filter((d) => NOTE_SUBTYPES.has(d.subtype ?? '')).slice(0, noteCount);
80
+ const joined = actionsByNote([...open.results, ...recent.results], noteDocs.map((d) => d.id));
81
+ setData({
82
+ open: open.results,
83
+ recent: recent.results,
84
+ notes: noteDocs.map((doc) => ({ doc, actions: joined.get(doc.id)! })),
85
+ names: Object.fromEntries(focuses.map((f) => [f.id, f.title])),
86
+ });
87
+ } catch (err) {
88
+ if (live) setError(failureMessage(err));
89
+ }
90
+ })();
91
+ return () => { live = false; };
92
+ }, [clock, noteCount, corpus]);
93
+
94
+ const due = React.useMemo(() => (data ? groupDue(data.open.filter(isTask), { now: clock, timeZone }) : null), [data, clock, timeZone]);
95
+
96
+ return (
97
+ <div className="space-y-8">
98
+ <BriefCard api={brief} onAsk={onAsk} />
99
+ {error ? <p className="text-sm text-red-600" role="alert">{error}</p> : null}
100
+ <Section title="Due across projects">
101
+ {due && data ? (
102
+ <DueAcrossProjects due={due} projectNames={data.names} trackerName={trackerName} onOpen={onOpenItem} onSeeAll={onOpenTracker} />
103
+ ) : error ? null : <p className="text-sm text-gray-500">Loading…</p>}
104
+ </Section>
105
+ <Section title="Recent notes">
106
+ {data ? (
107
+ <RecentNotes notes={data.notes} projectNames={data.names} now={clock} timeZone={timeZone} onOpenNote={onOpenNote} onOpenItem={onOpenItem} />
108
+ ) : error ? null : <p className="text-sm text-gray-500">Loading…</p>}
109
+ </Section>
110
+ </div>
111
+ );
112
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * RECENT NOTES, each with the actions that came out of it (bd startsim-cpzoz).
3
+ * A row is the note's title, when, and "N to-dos · M open"; opening it shows the
4
+ * summary and the to-dos themselves, each linking back to the full note. The
5
+ * join (`actionsByNote`) is done by the caller; this only draws it.
6
+ */
7
+ import * as React from 'react';
8
+
9
+ import { stripMarkdown } from '../../Markdown';
10
+ import type { NoteActions } from '../../../corpus/note-actions';
11
+ import type { Commitment, SourceDocument } from '../../../corpus/types';
12
+ import { CompactItemRow } from './CompactItemRow';
13
+ import { dueDay, localDate } from '../../../corpus/today';
14
+ import { daysBetween } from '../../../corpus/due-groups';
15
+
16
+ export interface RecentNote { doc: SourceDocument; actions: NoteActions }
17
+
18
+ export function RecentNotes({
19
+ notes, projectNames = {}, now, timeZone, onOpenNote, onOpenItem,
20
+ }: {
21
+ notes: RecentNote[];
22
+ projectNames?: Record<string, string>;
23
+ now: number;
24
+ timeZone?: string;
25
+ onOpenNote?: (documentId: string) => void;
26
+ onOpenItem?: (item: Commitment) => void;
27
+ }) {
28
+ if (!notes.length) return <p className="text-sm text-gray-500">No notes yet. Record one, or connect a meeting source.</p>;
29
+ const today = localDate(now, timeZone);
30
+ return (
31
+ <ul className="divide-y divide-gray-100 rounded-lg border border-gray-200 bg-white">
32
+ {notes.map(({ doc, actions }) => (
33
+ <li key={doc.id}>
34
+ <details className="group">
35
+ <summary className="flex cursor-pointer list-none items-center gap-3 px-4 py-3">
36
+ <span className="min-w-0 flex-1 truncate text-sm font-medium text-gray-900">{doc.title || 'Untitled note'}</span>
37
+ <span className="shrink-0 text-xs text-gray-500">
38
+ {actions.tasks.length === 0 ? 'no to-dos' : `${actions.tasks.length} to-do${actions.tasks.length === 1 ? '' : 's'} · ${actions.open} open`}
39
+ </span>
40
+ <span className="w-20 shrink-0 text-right text-xs text-gray-500">
41
+ {doc.occurredAt ? new Date(doc.occurredAt).toLocaleDateString(undefined, { month: 'short', day: 'numeric' }) : ''}
42
+ </span>
43
+ </summary>
44
+ <div className="space-y-3 px-4 pb-4">
45
+ {doc.summary ? <p className="whitespace-pre-line text-sm text-gray-700">{stripMarkdown(doc.summary)}</p> : null}
46
+ {actions.tasks.length ? (
47
+ <ul>
48
+ {actions.tasks.map((item) => {
49
+ const due = dueDay(item.dueAt, timeZone);
50
+ return (
51
+ <CompactItemRow
52
+ key={item.externalId} item={item} due={due} days={due ? daysBetween(today, due) : null}
53
+ project={item.focusId ? projectNames[item.focusId] : undefined} onOpen={onOpenItem}
54
+ />
55
+ );
56
+ })}
57
+ </ul>
58
+ ) : null}
59
+ {actions.statements ? <p className="text-xs text-gray-500">{actions.statements} decision{actions.statements === 1 ? '' : 's'} or question{actions.statements === 1 ? '' : 's'} noted</p> : null}
60
+ {onOpenNote ? (
61
+ <button type="button" className="text-sm text-blue-700 underline" onClick={() => onOpenNote(doc.id)}>Open the full note</button>
62
+ ) : null}
63
+ </div>
64
+ </details>
65
+ </li>
66
+ ))}
67
+ </ul>
68
+ );
69
+ }
@@ -0,0 +1,10 @@
1
+ export { BriefCard } from './BriefCard';
2
+ export type { BriefCardApi } from './BriefCard';
3
+ export { CompactItemRow, dueLabel } from './CompactItemRow';
4
+ export type { CompactItemRowProps } from './CompactItemRow';
5
+ export { DueAcrossProjects } from './DueAcrossProjects';
6
+ export { RecentNotes } from './RecentNotes';
7
+ export type { RecentNote } from './RecentNotes';
8
+ export { HomeBriefPage } from './HomeBriefPage';
9
+ export type { HomeBriefPageProps } from './HomeBriefPage';
10
+ export { useProjectNames } from './useProjectNames';
@@ -0,0 +1,23 @@
1
+ import * as React from 'react';
2
+
3
+ import type { PlanningApi } from '../../../corpus/types';
4
+
5
+ /**
6
+ * Project (focus) names by id, for the chip on a row. One server page of focuses,
7
+ * read once per mount; a refusal leaves the map empty and rows simply show no chip.
8
+ */
9
+ export function useProjectNames(listFocuses: PlanningApi['listFocuses'] | undefined): Record<string, string> {
10
+ const [names, setNames] = React.useState<Record<string, string>>({});
11
+ const ref = React.useRef(listFocuses);
12
+ ref.current = listFocuses;
13
+ const enabled = Boolean(listFocuses);
14
+ React.useEffect(() => {
15
+ if (!enabled) return undefined;
16
+ let live = true;
17
+ void ref.current!({ pageSize: 200 })
18
+ .then((page) => { if (live) setNames(Object.fromEntries(page.results.map((f) => [f.id, f.title]))); })
19
+ .catch(() => { /* no chips */ });
20
+ return () => { live = false; };
21
+ }, [enabled]);
22
+ return names;
23
+ }
@@ -60,6 +60,18 @@ import { isOverdue, priorityLabel } from '../../corpus/work-item-logic';
60
60
  * `related_to`). A banner that guessed would eventually announce a gap that had
61
61
  * been closed, which is exactly what shipped once already.
62
62
  */
63
+ export function unfilteredMessage<K extends string>(
64
+ requested: readonly K[],
65
+ applied: readonly string[],
66
+ query: Partial<Record<K, unknown>>,
67
+ ): string | null {
68
+ const unfiltered = requested.filter((key) => Boolean(query[key]) && !applied.includes(key));
69
+ if (!unfiltered.length) return null;
70
+ return `This workspace’s data API did not filter by ${unfiltered.join(', ')}, so this list was narrowed `
71
+ + 'in the browser over the records it could fetch. Counts are over that set, not over the whole '
72
+ + 'corpus.';
73
+ }
74
+
63
75
  export function UnfilteredNotice<K extends string>({
64
76
  requested, applied, query, className,
65
77
  }: {
@@ -68,15 +80,9 @@ export function UnfilteredNotice<K extends string>({
68
80
  query: Partial<Record<K, unknown>>;
69
81
  className: string;
70
82
  }) {
71
- const unfiltered = requested.filter((key) => Boolean(query[key]) && !applied.includes(key));
72
- if (!unfiltered.length) return null;
73
- return (
74
- <p className={className} role="status">
75
- This workspace’s data API did not filter by {unfiltered.join(', ')}, so this list was narrowed
76
- in the browser over the records it could fetch. Counts are over that set, not over the whole
77
- corpus.
78
- </p>
79
- );
83
+ const message = unfilteredMessage(requested, applied, query);
84
+ if (!message) return null;
85
+ return <p className={className} role="status">{message}</p>;
80
86
  }
81
87
 
82
88
  // ---------------------------------------------------------------------------
@@ -0,0 +1,81 @@
1
+ /**
2
+ * DUE ACROSS PROJECTS: open items with a date, grouped the way a person scans
3
+ * them — Overdue, Today, This week, Later (bd startsim-cpzoz). PURE: the clock
4
+ * and the reader's IANA zone come in, and the day arithmetic is done on
5
+ * calendar dates (never on instants), so a bare date and a UTC-midnight date
6
+ * mean the same day everywhere (see `dueDay`).
7
+ *
8
+ * Undated items are not "due" and are not listed; they are counted so a screen
9
+ * can say "N have no date" instead of pretending they do not exist. Finished
10
+ * items (done, dropped) are never due.
11
+ */
12
+ import { dueDay, localDate } from './today';
13
+ import type { Commitment } from './types';
14
+
15
+ export type DueBucket = 'overdue' | 'today' | 'week' | 'later';
16
+
17
+ export const DUE_LABELS: Record<DueBucket, string> = {
18
+ overdue: 'Overdue', today: 'Today', week: 'This week', later: 'Later',
19
+ };
20
+
21
+ /** "This week" is the seven days after today. */
22
+ export const WEEK_DAYS = 7;
23
+
24
+ export interface DueEntry<T = Commitment> {
25
+ item: T;
26
+ /** The calendar day it is due, in the reader's zone. */
27
+ due: string;
28
+ /** Whole days from today: negative is late. */
29
+ days: number;
30
+ }
31
+
32
+ export interface DueGroup<T = Commitment> { bucket: DueBucket; label: string; entries: DueEntry<T>[] }
33
+
34
+ export interface DueGroups<T = Commitment> {
35
+ groups: DueGroup<T>[];
36
+ /** Dated, open items listed in `groups`. */
37
+ total: number;
38
+ /** Open items with no date, left out of `groups`. */
39
+ undated: number;
40
+ }
41
+
42
+ type Dueable = Pick<Commitment, 'status' | 'dueAt'> & { priority?: number };
43
+
44
+ const FINISHED = new Set(['done', 'dropped']);
45
+
46
+ /** Whole calendar days from `from` to `to` (both `YYYY-MM-DD`). */
47
+ export function daysBetween(from: string, to: string): number {
48
+ const ms = (d: string) => Date.UTC(+d.slice(0, 4), +d.slice(5, 7) - 1, +d.slice(8, 10));
49
+ return Math.round((ms(to) - ms(from)) / 86_400_000);
50
+ }
51
+
52
+ export function bucketOf(days: number): DueBucket {
53
+ if (days < 0) return 'overdue';
54
+ if (days === 0) return 'today';
55
+ return days <= WEEK_DAYS ? 'week' : 'later';
56
+ }
57
+
58
+ export function groupDue<T extends Dueable>(
59
+ items: T[],
60
+ options: { now: number; timeZone?: string },
61
+ ): DueGroups<T> {
62
+ const timeZone = options.timeZone ?? 'UTC';
63
+ const today = localDate(options.now, timeZone);
64
+ const by: Record<DueBucket, DueEntry<T>[]> = { overdue: [], today: [], week: [], later: [] };
65
+ let undated = 0;
66
+ let total = 0;
67
+ for (const item of items) {
68
+ if (FINISHED.has(item.status)) continue;
69
+ const due = dueDay(item.dueAt, timeZone);
70
+ if (!due) { undated += 1; continue; }
71
+ const days = daysBetween(today, due);
72
+ by[bucketOf(days)].push({ item, due, days });
73
+ total += 1;
74
+ }
75
+ const order = (a: DueEntry<T>, b: DueEntry<T>) =>
76
+ a.due.localeCompare(b.due) || (a.item.priority ?? 99) - (b.item.priority ?? 99);
77
+ const groups = (Object.keys(by) as DueBucket[])
78
+ .filter((bucket) => by[bucket].length > 0)
79
+ .map((bucket) => ({ bucket, label: DUE_LABELS[bucket], entries: by[bucket].sort(order) }));
80
+ return { groups, total, undated };
81
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * PLANNING'S OVERVIEW: one row per ACTIVE focus — how many items are open, how
3
+ * many are overdue, and the next one due (bd startsim-u57lr). PURE; the items
4
+ * are the open items already fetched (server-paginated) with `focusId` filled.
5
+ *
6
+ * Most urgent first: more overdue, then the earliest next-due date, then the
7
+ * name. A focus nobody has put anything under is listed last, not hidden.
8
+ */
9
+ import { daysBetween } from './due-groups';
10
+ import { dueDay, localDate } from './today';
11
+ import type { Commitment, Focus } from './types';
12
+
13
+ const CLOSED_FOCUS = new Set(['completed', 'cancelled']);
14
+ const FINISHED = new Set(['done', 'dropped']);
15
+
16
+ export interface FocusSummary {
17
+ focus: Focus;
18
+ open: number;
19
+ overdue: number;
20
+ /** The open dated item due soonest (the most overdue one counts), or null. */
21
+ next: Commitment | null;
22
+ nextDue: string | null;
23
+ nextDays: number | null;
24
+ }
25
+
26
+ export function summarizeFocuses(
27
+ focuses: Focus[],
28
+ items: Commitment[],
29
+ options: { now: number; timeZone?: string },
30
+ ): FocusSummary[] {
31
+ const timeZone = options.timeZone ?? 'UTC';
32
+ const today = localDate(options.now, timeZone);
33
+ const rows = new Map<string, FocusSummary>();
34
+ for (const focus of focuses) {
35
+ if (CLOSED_FOCUS.has(focus.status)) continue;
36
+ rows.set(focus.id, { focus, open: 0, overdue: 0, next: null, nextDue: null, nextDays: null });
37
+ }
38
+ for (const item of items) {
39
+ const row = item.focusId ? rows.get(item.focusId) : undefined;
40
+ if (!row || FINISHED.has(item.status)) continue;
41
+ row.open += 1;
42
+ const due = dueDay(item.dueAt, timeZone);
43
+ if (!due) continue;
44
+ const days = daysBetween(today, due);
45
+ if (days < 0) row.overdue += 1;
46
+ if (row.nextDue === null || due < row.nextDue) {
47
+ row.next = item; row.nextDue = due; row.nextDays = days;
48
+ }
49
+ }
50
+ return [...rows.values()].sort((a, b) =>
51
+ b.overdue - a.overdue
52
+ || (a.nextDue ?? '9999').localeCompare(b.nextDue ?? '9999')
53
+ || a.focus.title.localeCompare(b.focus.title));
54
+ }
@@ -291,3 +291,13 @@ export { AMBIGUITY_GAP, openQuestions } from './extraction-fields';
291
291
  export type { FieldCandidate, FieldGuess, FieldSource, ItemFields } from './extraction-fields';
292
292
  export { resolveSectionFields } from './voice-due';
293
293
  export type { VoiceItemRecord } from './voice-due';
294
+
295
+ // Day-to-day groupings: Due across projects, the Tracker list, Planning's overview (bd startsim-cpzoz, startsim-u57lr).
296
+ export { DUE_LABELS, WEEK_DAYS, bucketOf, daysBetween, groupDue } from './due-groups';
297
+ export type { DueBucket, DueEntry, DueGroup, DueGroups } from './due-groups';
298
+ export { STALE_DAYS, groupTracker, isTask } from './tracker-groups';
299
+ export type { TrackerEntry, TrackerGroups } from './tracker-groups';
300
+ export { summarizeFocuses } from './focus-overview';
301
+ export type { FocusSummary } from './focus-overview';
302
+ export { actionsByNote } from './note-actions';
303
+ export type { NoteActions } from './note-actions';
@@ -0,0 +1,44 @@
1
+ /**
2
+ * WHICH ACTIONS CAME OUT OF WHICH NOTE (bd startsim-cpzoz). A commitment keeps
3
+ * every note that raised it in `mentions[].documentId`; this inverts that join
4
+ * for the handful of notes a screen is showing. Pure. Tasks are the to-dos
5
+ * (open ones first); meeting statements are only counted.
6
+ */
7
+ import { isTask } from './tracker-groups';
8
+ import type { Commitment } from './types';
9
+
10
+ export interface NoteActions {
11
+ /** To-dos raised in the note: open before finished, then by due date. */
12
+ tasks: Commitment[];
13
+ /** Decisions, needs, risks and questions it raised (not tasks). */
14
+ statements: number;
15
+ /** How many of `tasks` are still owed. */
16
+ open: number;
17
+ }
18
+
19
+ const FINISHED = new Set(['done', 'dropped']);
20
+
21
+ export function actionsByNote(commitments: Commitment[], noteIds: string[]): Map<string, NoteActions> {
22
+ const out = new Map<string, NoteActions>(noteIds.map((id) => [id, { tasks: [], statements: 0, open: 0 }]));
23
+ const counted = new Set<string>();
24
+ for (const item of commitments) {
25
+ // The same row can arrive from two reads (open, and changed lately).
26
+ if (counted.has(item.externalId)) continue;
27
+ counted.add(item.externalId);
28
+ const seen = new Set<string>();
29
+ for (const mention of item.mentions) {
30
+ const row = out.get(mention.documentId);
31
+ if (!row || seen.has(mention.documentId)) continue;
32
+ seen.add(mention.documentId);
33
+ if (!isTask(item)) { row.statements += 1; continue; }
34
+ row.tasks.push(item);
35
+ if (!FINISHED.has(item.status)) row.open += 1;
36
+ }
37
+ }
38
+ for (const row of out.values()) {
39
+ row.tasks.sort((a, b) =>
40
+ Number(FINISHED.has(a.status)) - Number(FINISHED.has(b.status))
41
+ || (a.dueAt ?? '9999').localeCompare(b.dueAt ?? '9999'));
42
+ }
43
+ return out;
44
+ }