@startsimpli/integrations 0.2.149 → 0.2.151
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/__tests__/connection-check-reason.test.tsx +85 -0
- package/src/__tests__/focus-history.test.ts +90 -0
- package/src/__tests__/goal-rows.test.ts +51 -0
- package/src/__tests__/goals-page.test.tsx +124 -0
- package/src/__tests__/helpers/question-tenant.ts +45 -0
- package/src/__tests__/question-checkin.test.ts +139 -0
- package/src/__tests__/question-voice-parse.test.ts +110 -0
- package/src/__tests__/question-voice.test.ts +208 -0
- package/src/__tests__/stated-date-extract.test.ts +119 -0
- package/src/__tests__/stated-date.test.ts +107 -0
- package/src/__tests__/tracker-done-stamp.test.ts +42 -0
- package/src/__tests__/tracker-timeline-component.test.tsx +81 -0
- package/src/__tests__/tracker-timeline-reader.test.ts +94 -0
- package/src/__tests__/tracker-timeline.test.ts +209 -0
- package/src/components/index.ts +1 -0
- package/src/components/pages/PlanningPage.tsx +16 -2
- package/src/components/pages/TrackerPage.tsx +8 -0
- package/src/components/pages/connections/ConnectionCard.tsx +12 -0
- package/src/components/pages/connections/bound-api.ts +1 -1
- package/src/components/pages/goals/FocusProgressHistory.tsx +77 -0
- package/src/components/pages/goals/GoalsPage.tsx +186 -0
- package/src/components/pages/goals/index.ts +4 -0
- package/src/components/pages/tracker/TrackerTimeline.tsx +123 -0
- package/src/components/pages/types.ts +2 -2
- package/src/corpus/client.ts +27 -1
- package/src/corpus/commitments.ts +3 -1
- package/src/corpus/extract.ts +8 -6
- package/src/corpus/focus-history.ts +104 -0
- package/src/corpus/goal-rows.ts +29 -0
- package/src/corpus/index.ts +6 -0
- package/src/corpus/questions/checkin-handle.ts +67 -0
- package/src/corpus/questions/checkin.ts +103 -0
- package/src/corpus/questions/index.ts +9 -0
- package/src/corpus/questions/respond.ts +76 -0
- package/src/corpus/questions/store.ts +5 -1
- package/src/corpus/questions/sync.ts +1 -0
- package/src/corpus/questions/types.ts +10 -2
- package/src/corpus/questions/voice-parse.ts +98 -0
- package/src/corpus/questions/voice.ts +225 -0
- package/src/corpus/spoken-time.ts +4 -4
- package/src/corpus/stated-date.ts +187 -0
- package/src/corpus/tracker-timeline-client.ts +117 -0
- package/src/corpus/tracker-timeline.ts +228 -0
- package/src/corpus/types.ts +25 -1
- package/src/corpus/work-item-logic.ts +1 -1
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GOALS - every focus as a goal with its measurable progress
|
|
5
|
+
* (`<GoalsPage api={planningApi} scope={scope} onOpenFocus={...} />`).
|
|
6
|
+
*
|
|
7
|
+
* The table itself is the shared `GoalProgressTable` from
|
|
8
|
+
* `@startsimpli/ui/insights`; this composer only adds what a list over a
|
|
9
|
+
* server needs around it: server-side filter, sort and pagination (CLAUDE.md
|
|
10
|
+
* rule 8), and the row -> focus-detail hand-off. A qualitative focus (no target)
|
|
11
|
+
* reads "No target", never 0%.
|
|
12
|
+
*
|
|
13
|
+
* Nothing here writes. The clock is read once at mount (or injected via `now`),
|
|
14
|
+
* so "overdue" cannot change between renders.
|
|
15
|
+
*/
|
|
16
|
+
import * as React from 'react';
|
|
17
|
+
import { GoalProgressTable } from '@startsimpli/ui/insights';
|
|
18
|
+
|
|
19
|
+
import { focusToGoalRow } from '../../../corpus/goal-rows';
|
|
20
|
+
import type { CorpusPage, CorpusScope, Focus, FocusQuery, FocusStatus, PlanningApi } from '../../../corpus/types';
|
|
21
|
+
import { failureMessage } from '../work-items';
|
|
22
|
+
|
|
23
|
+
export interface GoalsPageProps {
|
|
24
|
+
api: Pick<PlanningApi, 'listFocuses'>;
|
|
25
|
+
scope: CorpusScope;
|
|
26
|
+
/** Row click: open this focus's detail (the Planning page's focus view). */
|
|
27
|
+
onOpenFocus?: (focusId: string) => void;
|
|
28
|
+
/** Injectable clock (ms). Defaults to the moment this mounted. */
|
|
29
|
+
now?: number;
|
|
30
|
+
timeZone?: string;
|
|
31
|
+
pageSize?: number;
|
|
32
|
+
classNames?: Partial<Record<'root' | 'toolbar' | 'input' | 'button' | 'muted' | 'error' | 'warning', string>>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const ALL_STATUSES: FocusStatus[] = ['draft', 'active', 'on_track', 'at_risk', 'off_track', 'completed', 'cancelled'];
|
|
36
|
+
/** The default view: everything still in play. Cancelled is one pick away. */
|
|
37
|
+
const IN_PLAY = ALL_STATUSES.filter((s) => s !== 'cancelled');
|
|
38
|
+
|
|
39
|
+
const SORTS: Array<{ value: NonNullable<FocusQuery['orderBy']>; label: string }> = [
|
|
40
|
+
{ value: 'progress', label: 'Worst off first' },
|
|
41
|
+
{ value: '-progress', label: 'Best off first' },
|
|
42
|
+
{ value: 'endDate', label: 'Due date' },
|
|
43
|
+
{ value: 'title', label: 'Title' },
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const DEFAULTS = {
|
|
47
|
+
root: 'space-y-4',
|
|
48
|
+
toolbar: 'flex flex-wrap items-center gap-2',
|
|
49
|
+
input: 'rounded-md border border-gray-300 px-3 py-1.5 text-sm',
|
|
50
|
+
button: 'rounded-md border border-gray-300 px-3 py-1.5 text-sm font-medium text-gray-800 disabled:opacity-50',
|
|
51
|
+
muted: 'text-sm text-gray-500',
|
|
52
|
+
error: 'text-sm text-red-600',
|
|
53
|
+
warning: 'rounded-md border border-amber-300 bg-amber-50 p-3 text-sm text-amber-900',
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** Local calendar day of `ms` in `timeZone` (default UTC). */
|
|
57
|
+
function isoDay(ms: number, timeZone = 'UTC'): string {
|
|
58
|
+
return new Intl.DateTimeFormat('en-CA', { timeZone, year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date(ms));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function GoalsPage({ api, scope, onOpenFocus, now, timeZone, pageSize = 25, classNames = {} }: GoalsPageProps) {
|
|
62
|
+
const cn = { ...DEFAULTS, ...classNames };
|
|
63
|
+
const [mountedAt] = React.useState(() => Date.now());
|
|
64
|
+
const today = isoDay(now ?? mountedAt, timeZone);
|
|
65
|
+
|
|
66
|
+
const apiRef = React.useRef(api);
|
|
67
|
+
apiRef.current = api;
|
|
68
|
+
|
|
69
|
+
const [statusPick, setStatusPick] = React.useState<'in_play' | 'all' | FocusStatus>('in_play');
|
|
70
|
+
const [orderBy, setOrderBy] = React.useState<NonNullable<FocusQuery['orderBy']>>('progress');
|
|
71
|
+
const [typed, setTyped] = React.useState('');
|
|
72
|
+
const [search, setSearch] = React.useState('');
|
|
73
|
+
const [page, setPage] = React.useState(1);
|
|
74
|
+
const [result, setResult] = React.useState<CorpusPage<Focus> | null>(null);
|
|
75
|
+
const [error, setError] = React.useState('');
|
|
76
|
+
const [loading, setLoading] = React.useState(true);
|
|
77
|
+
|
|
78
|
+
const query = React.useMemo<FocusQuery>(() => ({
|
|
79
|
+
...(statusPick === 'in_play' ? { status: IN_PLAY } : statusPick === 'all' ? {} : { status: statusPick }),
|
|
80
|
+
...(search ? { search } : {}),
|
|
81
|
+
orderBy,
|
|
82
|
+
page,
|
|
83
|
+
pageSize,
|
|
84
|
+
}), [statusPick, search, orderBy, page, pageSize]);
|
|
85
|
+
|
|
86
|
+
React.useEffect(() => {
|
|
87
|
+
let live = true;
|
|
88
|
+
setLoading(true);
|
|
89
|
+
setError('');
|
|
90
|
+
apiRef.current.listFocuses(query)
|
|
91
|
+
.then((got) => { if (live) setResult(got); })
|
|
92
|
+
.catch((err) => { if (live) { setResult(null); setError(failureMessage(err)); } })
|
|
93
|
+
.finally(() => { if (live) setLoading(false); });
|
|
94
|
+
return () => { live = false; };
|
|
95
|
+
// `scope.orgId`, not `scope`: a rebuilt scope object must not refetch.
|
|
96
|
+
}, [query, scope.orgId]);
|
|
97
|
+
|
|
98
|
+
const focuses = result?.results ?? [];
|
|
99
|
+
const rows = React.useMemo(() => focuses.map(focusToGoalRow), [focuses]);
|
|
100
|
+
const byId = React.useMemo(() => new Map(focuses.map((f) => [f.id, f])), [focuses]);
|
|
101
|
+
const count = result?.count ?? 0;
|
|
102
|
+
const from = count === 0 ? 0 : (page - 1) * pageSize + 1;
|
|
103
|
+
const to = (page - 1) * pageSize + focuses.length;
|
|
104
|
+
|
|
105
|
+
// [] means the server did not say; only a non-empty report can contradict a filter.
|
|
106
|
+
const applied = result?.appliedFilters ?? [];
|
|
107
|
+
const ignored = applied.length > 0 ? [
|
|
108
|
+
...(query.status && !applied.some((a) => a.startsWith('attr.status') || a === 'status') ? ['status'] : []),
|
|
109
|
+
...(query.search && !applied.includes('search') ? ['search'] : []),
|
|
110
|
+
] : [];
|
|
111
|
+
|
|
112
|
+
const change = <T,>(set: (v: T) => void) => (v: T) => { set(v); setPage(1); };
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<div className={cn.root}>
|
|
116
|
+
<form
|
|
117
|
+
className={cn.toolbar}
|
|
118
|
+
role="search"
|
|
119
|
+
onSubmit={(e) => { e.preventDefault(); setSearch(typed.trim()); setPage(1); }}
|
|
120
|
+
>
|
|
121
|
+
<input
|
|
122
|
+
className={cn.input}
|
|
123
|
+
aria-label="Search goals"
|
|
124
|
+
placeholder="Search goals"
|
|
125
|
+
value={typed}
|
|
126
|
+
onChange={(e) => setTyped(e.target.value)}
|
|
127
|
+
/>
|
|
128
|
+
<button type="submit" className={cn.button}>Search</button>
|
|
129
|
+
<label className="ml-auto flex items-center gap-2 text-sm">
|
|
130
|
+
Status
|
|
131
|
+
<select
|
|
132
|
+
className={cn.input}
|
|
133
|
+
aria-label="Filter by status"
|
|
134
|
+
value={statusPick}
|
|
135
|
+
onChange={(e) => change(setStatusPick)(e.target.value as typeof statusPick)}
|
|
136
|
+
>
|
|
137
|
+
<option value="in_play">In play</option>
|
|
138
|
+
<option value="all">All statuses</option>
|
|
139
|
+
{ALL_STATUSES.map((s) => <option key={s} value={s}>{s.replace(/_/g, ' ')}</option>)}
|
|
140
|
+
</select>
|
|
141
|
+
</label>
|
|
142
|
+
<label className="flex items-center gap-2 text-sm">
|
|
143
|
+
Sort
|
|
144
|
+
<select
|
|
145
|
+
className={cn.input}
|
|
146
|
+
aria-label="Sort goals"
|
|
147
|
+
value={orderBy}
|
|
148
|
+
onChange={(e) => change(setOrderBy)(e.target.value as typeof orderBy)}
|
|
149
|
+
>
|
|
150
|
+
{SORTS.map((s) => <option key={s.value} value={s.value}>{s.label}</option>)}
|
|
151
|
+
</select>
|
|
152
|
+
</label>
|
|
153
|
+
</form>
|
|
154
|
+
|
|
155
|
+
{ignored.length ? (
|
|
156
|
+
<p className={cn.warning} role="status">
|
|
157
|
+
This workspace’s data API did not filter by {ignored.join(', ')}, so this page may include goals that do not match.
|
|
158
|
+
</p>
|
|
159
|
+
) : null}
|
|
160
|
+
{error ? <p className={cn.error} role="alert">{error}</p> : null}
|
|
161
|
+
|
|
162
|
+
<GoalProgressTable
|
|
163
|
+
rows={rows}
|
|
164
|
+
// A cancelled goal is not "overdue"; the table only knows done-like
|
|
165
|
+
// statuses, so overdue is not computed while looking at cancelled ones.
|
|
166
|
+
today={statusPick === 'cancelled' ? undefined : today}
|
|
167
|
+
emptyMessage={loading ? 'Loading goals…' : 'No goals match.'}
|
|
168
|
+
onRowClick={onOpenFocus ? (row) => { if (byId.has(row.id)) onOpenFocus(row.id); } : undefined}
|
|
169
|
+
/>
|
|
170
|
+
|
|
171
|
+
<div className="flex items-center justify-between">
|
|
172
|
+
<p className={cn.muted} data-testid="goals-range">
|
|
173
|
+
{count === 0 ? '0 goals' : `Showing ${from}–${to} of ${count}`}
|
|
174
|
+
</p>
|
|
175
|
+
<div className="flex gap-2">
|
|
176
|
+
<button type="button" className={cn.button} disabled={loading || page <= 1} onClick={() => setPage((p) => p - 1)}>
|
|
177
|
+
Previous
|
|
178
|
+
</button>
|
|
179
|
+
<button type="button" className={cn.button} disabled={loading || !result?.next} onClick={() => setPage((p) => p + 1)}>
|
|
180
|
+
Next
|
|
181
|
+
</button>
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
</div>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE TRACKER'S TIMELINE STRIP: created / done / overdue per day over a 7/30/60/90
|
|
3
|
+
* day window, and the to-dos behind those numbers in a table. Drawn by the
|
|
4
|
+
* shared `@startsimpli/ui/insights` components; this file only supplies data and
|
|
5
|
+
* keeps ONE range state that drives both.
|
|
6
|
+
*
|
|
7
|
+
* Reads are server-side and bounded (see `tracker-timeline-client`). The effect
|
|
8
|
+
* is keyed on the workspace, the reader's day and a SERIALISED filter, with the
|
|
9
|
+
* api held in a ref and the free-text filter debounced: this page has already
|
|
10
|
+
* shipped one request runaway, and a timeline that re-read on every keystroke
|
|
11
|
+
* or render would be a second.
|
|
12
|
+
*/
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
import { DEFAULT_RANGES, RangeEventTable, RangeSelector, RangeTimelineChart } from '@startsimpli/ui/insights';
|
|
15
|
+
|
|
16
|
+
import { buildTimeline, anchorOf, type TimelineFilter } from '../../../corpus/tracker-timeline';
|
|
17
|
+
import type { TimelineRead } from '../../../corpus/tracker-timeline-client';
|
|
18
|
+
import type { CommitmentTrackerApi } from '../../../corpus/types';
|
|
19
|
+
import { failureMessage } from '../work-items';
|
|
20
|
+
|
|
21
|
+
export interface TrackerTimelineProps {
|
|
22
|
+
api: Pick<CommitmentTrackerApi, 'timeline'>;
|
|
23
|
+
/** The workspace; a change re-reads. */
|
|
24
|
+
orgId: string;
|
|
25
|
+
filter: TimelineFilter;
|
|
26
|
+
/** Frozen by the page; the anchor day comes from this, never from a clock read here. */
|
|
27
|
+
now: number;
|
|
28
|
+
timeZone?: string;
|
|
29
|
+
/** Free-text filters wait this long before they become a server query. */
|
|
30
|
+
debounceMs?: number;
|
|
31
|
+
className?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const FILTER_DEBOUNCE_MS = 400;
|
|
35
|
+
|
|
36
|
+
function useDebounced<T>(value: T, ms: number): T {
|
|
37
|
+
const [held, setHeld] = React.useState(value);
|
|
38
|
+
React.useEffect(() => {
|
|
39
|
+
if (ms <= 0) { setHeld(value); return undefined; }
|
|
40
|
+
const timer = setTimeout(() => setHeld(value), ms);
|
|
41
|
+
return () => clearTimeout(timer);
|
|
42
|
+
}, [value, ms]);
|
|
43
|
+
return held;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function TrackerTimeline({
|
|
47
|
+
api, orgId, filter, now, timeZone = 'UTC', debounceMs = FILTER_DEBOUNCE_MS, className,
|
|
48
|
+
}: TrackerTimelineProps) {
|
|
49
|
+
const apiRef = React.useRef(api);
|
|
50
|
+
apiRef.current = api;
|
|
51
|
+
const [range, setRange] = React.useState('30d');
|
|
52
|
+
const [read, setRead] = React.useState<TimelineRead | null>(null);
|
|
53
|
+
const [error, setError] = React.useState('');
|
|
54
|
+
const [loading, setLoading] = React.useState(true);
|
|
55
|
+
|
|
56
|
+
const debouncedSearch = useDebounced(filter.search ?? '', debounceMs);
|
|
57
|
+
const filterKey = JSON.stringify({
|
|
58
|
+
status: filter.status ?? null, overdueOnly: Boolean(filter.overdueOnly),
|
|
59
|
+
owner: filter.owner ?? '', search: debouncedSearch,
|
|
60
|
+
});
|
|
61
|
+
const anchor = anchorOf(now, timeZone);
|
|
62
|
+
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
let live = true;
|
|
65
|
+
setLoading(true);
|
|
66
|
+
setError('');
|
|
67
|
+
const f = JSON.parse(filterKey) as { status: TimelineFilter['status'] | null; overdueOnly: boolean; owner: string; search: string };
|
|
68
|
+
apiRef.current.timeline!(
|
|
69
|
+
{ ...(f.status ? { status: f.status } : {}), ...(f.overdueOnly ? { overdueOnly: true } : {}), owner: f.owner, search: f.search },
|
|
70
|
+
{ now, timeZone },
|
|
71
|
+
)
|
|
72
|
+
.then((data) => { if (live) setRead(data); })
|
|
73
|
+
.catch((err) => { if (live) { setRead(null); setError(failureMessage(err)); } })
|
|
74
|
+
.finally(() => { if (live) setLoading(false); });
|
|
75
|
+
return () => { live = false; };
|
|
76
|
+
// `now` is the page's frozen clock; the anchor day stands in for it.
|
|
77
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
|
+
}, [orgId, filterKey, anchor, timeZone]);
|
|
79
|
+
|
|
80
|
+
const built = React.useMemo(() => (read ? buildTimeline(read, now, timeZone) : null), [read, now, timeZone]);
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<section className={className ?? 'space-y-4'} aria-label="Tracker timeline" data-testid="tracker-timeline">
|
|
84
|
+
<h2 className="text-lg font-semibold text-gray-900">Timeline</h2>
|
|
85
|
+
{error ? <p className="text-sm text-red-600" role="alert">{error}</p> : null}
|
|
86
|
+
{loading && !built ? <p className="text-sm text-gray-500">Loading the timeline…</p> : null}
|
|
87
|
+
{built ? (
|
|
88
|
+
<>
|
|
89
|
+
<RangeSelector value={range} ranges={DEFAULT_RANGES} onChange={setRange} />
|
|
90
|
+
<RangeTimelineChart
|
|
91
|
+
series={built.series}
|
|
92
|
+
anchor={anchor}
|
|
93
|
+
direction="back"
|
|
94
|
+
unit="number"
|
|
95
|
+
title="Created, done and overdue"
|
|
96
|
+
range={range}
|
|
97
|
+
hideRangeSelector
|
|
98
|
+
height={260}
|
|
99
|
+
/>
|
|
100
|
+
{built.estimatedDone > 0 ? (
|
|
101
|
+
<p className="text-xs text-gray-500" data-testid="timeline-estimated">
|
|
102
|
+
{built.estimatedDone} done {built.estimatedDone === 1 ? 'to-do has' : 'to-dos have'} no completion date and {built.estimatedDone === 1 ? 'is' : 'are'} counted on the day {built.estimatedDone === 1 ? 'it was' : 'they were'} last updated.
|
|
103
|
+
</p>
|
|
104
|
+
) : null}
|
|
105
|
+
<RangeEventTable
|
|
106
|
+
points={built.points}
|
|
107
|
+
anchor={anchor}
|
|
108
|
+
direction="back"
|
|
109
|
+
range={range}
|
|
110
|
+
hideRangeSelector
|
|
111
|
+
showCategory
|
|
112
|
+
pageSize={10}
|
|
113
|
+
title="To-dos in this window"
|
|
114
|
+
emptyMessage="No to-dos in this window."
|
|
115
|
+
/>
|
|
116
|
+
{read?.truncated ? (
|
|
117
|
+
<p className="text-xs text-gray-500">The table lists the newest 200 per kind; the chart counts all of them.</p>
|
|
118
|
+
) : null}
|
|
119
|
+
</>
|
|
120
|
+
) : null}
|
|
121
|
+
</section>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
@@ -266,7 +266,7 @@ export interface ConnectionsApi {
|
|
|
266
266
|
config?: Record<string, unknown>;
|
|
267
267
|
}): Promise<Connection>;
|
|
268
268
|
checkConnection(slug: string, id: string): Promise<{
|
|
269
|
-
ok: boolean; account_label: string; detail: string;
|
|
269
|
+
ok: boolean; account_label: string; detail: string; reason?: string; next_step?: string;
|
|
270
270
|
}>;
|
|
271
271
|
|
|
272
272
|
/**
|
|
@@ -440,7 +440,7 @@ export interface MemberConnectionsApi {
|
|
|
440
440
|
id: string, config: Record<string, unknown>,
|
|
441
441
|
): Promise<Connection>;
|
|
442
442
|
checkConnection(id: string): Promise<{
|
|
443
|
-
ok: boolean; account_label: string; detail: string;
|
|
443
|
+
ok: boolean; account_label: string; detail: string; reason?: string; next_step?: string;
|
|
444
444
|
}>;
|
|
445
445
|
/** Task-tracker connections: push what is pending now (bd startsim-el0zf). Optional for older clients. */
|
|
446
446
|
syncConnectionNow?(id: string): Promise<{ queued: boolean }>;
|
package/src/corpus/client.ts
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
*/
|
|
33
33
|
import { patchEditedItem } from './commitment-edit';
|
|
34
34
|
import { readStandings } from './standings';
|
|
35
|
+
import { createTimelineReader } from './tracker-timeline-client';
|
|
35
36
|
import {
|
|
36
37
|
DEFAULT_PARTICIPANT_EDGES,
|
|
37
38
|
FOLDER_ROOT,
|
|
@@ -63,12 +64,14 @@ import {
|
|
|
63
64
|
focusToEntity,
|
|
64
65
|
toFocus,
|
|
65
66
|
} from './planning';
|
|
67
|
+
import { toFocusRevision } from './focus-history';
|
|
66
68
|
import { commitmentOrder } from './tracker-sort';
|
|
67
69
|
import type {
|
|
68
70
|
Commitment,
|
|
69
71
|
SaveCommitmentsOptions,
|
|
70
72
|
CommitmentApi,
|
|
71
73
|
CommitmentQuery,
|
|
74
|
+
CommitmentTrackerApi,
|
|
72
75
|
CorpusApi,
|
|
73
76
|
CorpusFolder,
|
|
74
77
|
CorpusPage,
|
|
@@ -123,6 +126,8 @@ export interface CorpusHttp {
|
|
|
123
126
|
|
|
124
127
|
export interface CreateCorpusApiOptions {
|
|
125
128
|
http: CorpusHttp;
|
|
129
|
+
/** Injectable clock (ms), for the completion stamp. Default `Date.now`. */
|
|
130
|
+
now?: () => number;
|
|
126
131
|
/** The asking principal's scope, used as the fallback when a row omits its own. */
|
|
127
132
|
scope: CorpusScope;
|
|
128
133
|
/** Override when a tenant modelled its types under different keys. */
|
|
@@ -507,7 +512,7 @@ function undetermined(what: string): Error & { status: number } {
|
|
|
507
512
|
|
|
508
513
|
export function createCorpusApi(
|
|
509
514
|
options: CreateCorpusApiOptions,
|
|
510
|
-
): CorpusApi & CommitmentApi & ExtractionRunStore {
|
|
515
|
+
): CorpusApi & CommitmentApi & ExtractionRunStore & Pick<CommitmentTrackerApi, 'timeline'> {
|
|
511
516
|
const {
|
|
512
517
|
http,
|
|
513
518
|
scope,
|
|
@@ -722,6 +727,9 @@ export function createCorpusApi(
|
|
|
722
727
|
return {
|
|
723
728
|
...createFilingApi(http, { entities, relationships }),
|
|
724
729
|
|
|
730
|
+
// The Tracker timeline's server reads (grouped counts + one capped page per series).
|
|
731
|
+
timeline: createTimelineReader({ http, type: types.commitment, entitiesPath: entities }),
|
|
732
|
+
|
|
725
733
|
async listDocuments(query) {
|
|
726
734
|
const documents = await page<TenantEntity>(types.document, query, (entity) => entity);
|
|
727
735
|
// Skip the edge read entirely for an empty page: an empty corpus should
|
|
@@ -1231,6 +1239,7 @@ export function createPlanningApi(options: CreateCorpusApiOptions): PlanningApi
|
|
|
1231
1239
|
'-progress': '-attr.progress',
|
|
1232
1240
|
sortOrder: 'attr.sort_order',
|
|
1233
1241
|
title: 'attr.title',
|
|
1242
|
+
endDate: 'attr.end_date',
|
|
1234
1243
|
} as const)[query.orderBy ?? 'progress'],
|
|
1235
1244
|
};
|
|
1236
1245
|
if (statuses.length === 1) out['attr.status'] = statuses[0];
|
|
@@ -1326,6 +1335,19 @@ export function createPlanningApi(options: CreateCorpusApiOptions): PlanningApi
|
|
|
1326
1335
|
|
|
1327
1336
|
listFocuses: (query: FocusQuery = {}) => focusPage(focusParams(query)),
|
|
1328
1337
|
|
|
1338
|
+
/** Only the saves that touched `current_value` (`?field=` is a key test on the trail). */
|
|
1339
|
+
async listFocusRevisions(focusId: string, query: { page?: number; pageSize?: number } = {}) {
|
|
1340
|
+
const response = await http.get<DrfPage<unknown>>(`${entities}/${encodeURIComponent(focusId)}/revisions/`, {
|
|
1341
|
+
params: { field: 'current_value', page: query.page ?? 1, ...(query.pageSize ? { page_size: Math.min(query.pageSize, 200) } : {}) },
|
|
1342
|
+
});
|
|
1343
|
+
return {
|
|
1344
|
+
count: response.count ?? response.results?.length ?? 0,
|
|
1345
|
+
next: response.next ?? null,
|
|
1346
|
+
previous: response.previous ?? null,
|
|
1347
|
+
results: (response.results ?? []).map(toFocusRevision),
|
|
1348
|
+
};
|
|
1349
|
+
},
|
|
1350
|
+
|
|
1329
1351
|
/**
|
|
1330
1352
|
* The children of a focus, one level.
|
|
1331
1353
|
*
|
|
@@ -1425,6 +1447,10 @@ export function createPlanningApi(options: CreateCorpusApiOptions): PlanningApi
|
|
|
1425
1447
|
if (patch.subtype !== undefined) wire.subtype = patch.subtype;
|
|
1426
1448
|
if (patch.priority !== undefined) wire.priority = patch.priority;
|
|
1427
1449
|
if (patch.resolvedAt !== undefined) wire.resolved_at = patch.resolvedAt;
|
|
1450
|
+
// WHEN it was finished, stamped on the transition to done only (never on
|
|
1451
|
+
// an edit to an already-done item, never over a value the caller sent):
|
|
1452
|
+
// the Tracker timeline's "done per day" reads this.
|
|
1453
|
+
else if (patch.status === 'done' && item.status !== 'done') wire.resolved_at = new Date((options.now ?? Date.now)()).toISOString();
|
|
1428
1454
|
// `null` clears the mark: the tenant reads anything but 'private' as shared.
|
|
1429
1455
|
if (patch.visibility !== undefined) {
|
|
1430
1456
|
wire.visibility = patch.visibility ?? '';
|
|
@@ -285,7 +285,9 @@ export function reconcile(
|
|
|
285
285
|
// already recorded. A person ticking something off on the screen must
|
|
286
286
|
// survive the next run, or the screen is a suggestion box.
|
|
287
287
|
if (!match.ownerName && lead.ownerName) match.ownerName = lead.ownerName;
|
|
288
|
-
|
|
288
|
+
// A date read from the text goes onto rows the run creates, not onto rows that already
|
|
289
|
+
// exist (bd startsim-768w.38.30): backfilling live rows is a deliberate act of its own.
|
|
290
|
+
if (!match.dueAt && lead.dueAt && !lead.dueOnCreateOnly) {
|
|
289
291
|
match.dueAt = lead.dueAt;
|
|
290
292
|
if (lead.dueBasis) match.dueBasis = lead.dueBasis;
|
|
291
293
|
if (lead.dueConfidence !== undefined) match.dueConfidence = lead.dueConfidence;
|
package/src/corpus/extract.ts
CHANGED
|
@@ -46,6 +46,7 @@ import { applyTeamDecisions, buildTeamRequest } from './classify-team';
|
|
|
46
46
|
import { EXTRACTOR_VERSION, applyResolutions, mergeDrafts, reconcile } from './commitments';
|
|
47
47
|
import { enforceScope } from './retrieval';
|
|
48
48
|
import { META_LINE, parseItemMeta } from './extraction-fields';
|
|
49
|
+
import { withStatedDue } from './stated-date';
|
|
49
50
|
import type { ItemMeta } from './extraction-fields';
|
|
50
51
|
import { documentText, outcomeSections, documentParts, splitSections, words } from './text';
|
|
51
52
|
import type {
|
|
@@ -234,7 +235,7 @@ function toDraft(document: SourceDocument, line: string, detail: string): Commit
|
|
|
234
235
|
// document anyway, so nothing is lost by being strict here.
|
|
235
236
|
if (title.split(/\s+/).length < 3) return null;
|
|
236
237
|
|
|
237
|
-
return {
|
|
238
|
+
return withStatedDue({
|
|
238
239
|
documentId: document.id,
|
|
239
240
|
// Byte-stable: derived from the vendor's own words, never from a model.
|
|
240
241
|
originKey: `rules:${slug(title)}`,
|
|
@@ -247,7 +248,7 @@ function toDraft(document: SourceDocument, line: string, detail: string): Commit
|
|
|
247
248
|
// against the record without opening it.
|
|
248
249
|
quote: line.trim(),
|
|
249
250
|
extractor: 'rules',
|
|
250
|
-
};
|
|
251
|
+
}, document);
|
|
251
252
|
}
|
|
252
253
|
|
|
253
254
|
const slug = (text: string) =>
|
|
@@ -274,9 +275,9 @@ export function extractSystemPrompt(): string {
|
|
|
274
275
|
'For every item, copy a short verbatim "quote" from the document it came from, and echo that document\'s exact id. The quote must appear in the document CHARACTER FOR CHARACTER — it is checked, and an item whose quote is not found is discarded.',
|
|
275
276
|
'Set "subject" to what the item is ABOUT — a matter or case number, a property, a client, a system, a person. Copy an identifier verbatim when the text has one.',
|
|
276
277
|
'Set "owner" only to a name the document actually names. Leave it out otherwise.',
|
|
277
|
-
'
|
|
278
|
+
'Never estimate or invent a due date, and do not compute one: the system reads the date itself from your "quote". When the item has a stated date or day ("by 29th July", "tomorrow", "on Monday"), make sure those exact words are inside the quote; when the document states none, say nothing about a date.',
|
|
278
279
|
'Also report RESOLUTIONS: statements that something previously outstanding is now done or abandoned. Give the subject, what happened, and a verbatim quote.',
|
|
279
|
-
'Respond with JSON only: {"items":[{"documentId":string,"subtype":"action"|"decision"|"need"|"risk"|"question","title":string,"detail":string,"status":"open"|"done"|"blocked","owner":string,"subject":string,"
|
|
280
|
+
'Respond with JSON only: {"items":[{"documentId":string,"subtype":"action"|"decision"|"need"|"risk"|"question","title":string,"detail":string,"status":"open"|"done"|"blocked","owner":string,"subject":string,"quote":string}],"resolutions":[{"documentId":string,"subject":string,"statement":string,"quote":string,"outcome":"done"|"dropped"}]}',
|
|
280
281
|
'"title" must be one short imperative line.',
|
|
281
282
|
].join('\n');
|
|
282
283
|
}
|
|
@@ -525,7 +526,9 @@ export async function extractCommitments(
|
|
|
525
526
|
promptText,
|
|
526
527
|
extractor,
|
|
527
528
|
});
|
|
528
|
-
const
|
|
529
|
+
const documentById = new Map(documents.map((document) => [document.id, document]));
|
|
530
|
+
// The model's own `dueAt` is never read; a stated date is resolved from its quote, in code.
|
|
531
|
+
const modelDrafts = checked.kept.map((item) => withStatedDue(item, documentById.get(item.documentId) ?? { occurredAt: null }));
|
|
529
532
|
|
|
530
533
|
// 5. identity, dedupe within the run, then against what is stored.
|
|
531
534
|
const groups = mergeDrafts([...ruleDrafts, ...modelDrafts]);
|
|
@@ -1008,7 +1011,6 @@ function normaliseItems(
|
|
|
1008
1011
|
status: STATUSES.has(status) ? status : 'open',
|
|
1009
1012
|
...(owner && owner.length <= 60 ? { ownerName: owner } : {}),
|
|
1010
1013
|
...(item.subject ? { subject: String(item.subject).trim() } : {}),
|
|
1011
|
-
...(item.dueAt ? { dueAt: String(item.dueAt) } : {}),
|
|
1012
1014
|
quote: String(item.quote ?? '').trim(),
|
|
1013
1015
|
extractor: 'model',
|
|
1014
1016
|
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Progress over time for ONE focus, read from the tenant's append-only revision
|
|
3
|
+
* trail (`GET /entities/<id>/revisions/?field=current_value`, start-simpli-api
|
|
4
|
+
* tenant-starter) - never from a store of our own and never invented.
|
|
5
|
+
*
|
|
6
|
+
* WHAT THE DATA IS: each save that moved `current_value` left a row with
|
|
7
|
+
* `metadata.changed.current_value.{before,after}` and a timestamp. So the series
|
|
8
|
+
* starts at the first RECORDED change; nothing is extrapolated before it, and a
|
|
9
|
+
* focus that never had its value changed has no history to chart.
|
|
10
|
+
*/
|
|
11
|
+
import type { TimelinePoint } from '@startsimpli/ui/insights';
|
|
12
|
+
import type { CorpusPage } from './types';
|
|
13
|
+
|
|
14
|
+
export interface FocusRevision {
|
|
15
|
+
version: number;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
actor?: string;
|
|
18
|
+
/** Present only when this save moved `current_value`. */
|
|
19
|
+
currentValue?: { before?: unknown; after?: unknown };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type Raw = Record<string, unknown>;
|
|
23
|
+
const asObj = (v: unknown): Raw => (v && typeof v === 'object' && !Array.isArray(v) ? (v as Raw) : {});
|
|
24
|
+
|
|
25
|
+
/** Reads both spellings: the browser client camelCases response keys. */
|
|
26
|
+
export function toFocusRevision(raw: unknown): FocusRevision {
|
|
27
|
+
const r = asObj(raw);
|
|
28
|
+
const changed = asObj(asObj(r.metadata).changed);
|
|
29
|
+
const cv = changed.current_value ?? changed.currentValue;
|
|
30
|
+
const actor = r.actor_label ?? r.actorLabel ?? r.actor_sub ?? r.actorSub;
|
|
31
|
+
return {
|
|
32
|
+
version: Number(r.version) || 0,
|
|
33
|
+
createdAt: String(r.created_at ?? r.createdAt ?? ''),
|
|
34
|
+
...(typeof actor === 'string' && actor ? { actor } : {}),
|
|
35
|
+
...(cv && typeof cv === 'object' ? { currentValue: cv as { before?: unknown; after?: unknown } } : {}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function num(v: unknown): number | undefined {
|
|
40
|
+
if (typeof v === 'number') return Number.isFinite(v) ? v : undefined;
|
|
41
|
+
if (typeof v === 'string' && v.trim()) {
|
|
42
|
+
const n = Number(v);
|
|
43
|
+
return Number.isFinite(n) ? n : undefined;
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const day = (iso: string) => iso.slice(0, 10);
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Chart points, oldest first. Each day carries its end-of-day value and one
|
|
52
|
+
* event per save (delta = after - before). The last value is held to `anchor` so
|
|
53
|
+
* a short window is not empty; that is the value persisting, not a new fact.
|
|
54
|
+
* No numeric change recorded -> no points (never a flat line).
|
|
55
|
+
*/
|
|
56
|
+
export function currentValueSeries(
|
|
57
|
+
revisions: FocusRevision[],
|
|
58
|
+
anchor: string,
|
|
59
|
+
): { points: TimelinePoint[]; since?: string } {
|
|
60
|
+
const changes = revisions
|
|
61
|
+
.filter((r) => r.currentValue && num(r.currentValue.after) !== undefined && r.createdAt)
|
|
62
|
+
.sort((a, b) => a.createdAt.localeCompare(b.createdAt) || a.version - b.version);
|
|
63
|
+
if (!changes.length) return { points: [] };
|
|
64
|
+
const byDay = new Map<string, TimelinePoint>();
|
|
65
|
+
for (const r of changes) {
|
|
66
|
+
const after = num(r.currentValue!.after) as number;
|
|
67
|
+
const before = num(r.currentValue!.before) ?? 0;
|
|
68
|
+
const d = day(r.createdAt);
|
|
69
|
+
const point = byDay.get(d) ?? { date: d, value: after, events: [] };
|
|
70
|
+
point.value = after;
|
|
71
|
+
point.events = [...(point.events ?? []), {
|
|
72
|
+
id: `rev-${r.version}`,
|
|
73
|
+
label: r.actor ? `Updated by ${r.actor}` : 'Updated',
|
|
74
|
+
delta: after - before,
|
|
75
|
+
}];
|
|
76
|
+
byDay.set(d, point);
|
|
77
|
+
}
|
|
78
|
+
const points = [...byDay.values()];
|
|
79
|
+
const last = points[points.length - 1];
|
|
80
|
+
if (last.date < anchor) points.push({ date: anchor, value: last.value, events: [] });
|
|
81
|
+
return { points, since: points[0].date };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const WINDOW_DAYS = 90;
|
|
85
|
+
const DAY_MS = 86_400_000;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Reads revision pages (newest first) until one reaches back past the longest
|
|
89
|
+
* window or the trail ends. Server-paginated; no fixed page cap.
|
|
90
|
+
*/
|
|
91
|
+
export async function loadCurrentValueRevisions(
|
|
92
|
+
fetchPage: (page: number) => Promise<CorpusPage<FocusRevision>>,
|
|
93
|
+
anchor: string,
|
|
94
|
+
): Promise<FocusRevision[]> {
|
|
95
|
+
const cutoff = new Date(Date.parse(`${anchor}T00:00:00Z`) - WINDOW_DAYS * DAY_MS).toISOString().slice(0, 10);
|
|
96
|
+
const out: FocusRevision[] = [];
|
|
97
|
+
for (let page = 1; ; page += 1) {
|
|
98
|
+
const got = await fetchPage(page);
|
|
99
|
+
out.push(...got.results);
|
|
100
|
+
const oldest = got.results.at(-1)?.createdAt;
|
|
101
|
+
if (!got.next || got.results.length === 0 || (oldest && day(oldest) < cutoff)) break;
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Focus -> the shared goal-table row (`@startsimpli/ui/insights` GoalRow).
|
|
3
|
+
*
|
|
4
|
+
* THE ONE RULE: "no target" stays "no target". A qualitative focus has no
|
|
5
|
+
* `targetValue`; the table shows it as "No target" and never as 0%. So target and
|
|
6
|
+
* current are sent only together and only when the target is a positive number.
|
|
7
|
+
* Item counts (`FocusStanding`) and the stored `progress` field are NOT mapped
|
|
8
|
+
* into them: that would turn a qualitative focus into a measurable one.
|
|
9
|
+
*/
|
|
10
|
+
import type { GoalRow } from '@startsimpli/ui/insights';
|
|
11
|
+
import { focusStatusLabel } from './planning';
|
|
12
|
+
import type { Focus } from './types';
|
|
13
|
+
|
|
14
|
+
export function focusToGoalRow(focus: Focus): GoalRow {
|
|
15
|
+
const measurable = typeof focus.targetValue === 'number' && focus.targetValue > 0;
|
|
16
|
+
const subtype = focus.subtype || focus.category;
|
|
17
|
+
return {
|
|
18
|
+
id: focus.id,
|
|
19
|
+
title: focus.title,
|
|
20
|
+
...(subtype ? { subtype } : {}),
|
|
21
|
+
...(focus.ownerName ? { owner: focus.ownerName } : {}),
|
|
22
|
+
...(focus.endDate ? { due: focus.endDate.slice(0, 10) } : {}),
|
|
23
|
+
status: focusStatusLabel(focus.status),
|
|
24
|
+
...(measurable
|
|
25
|
+
? { target: focus.targetValue as number, current: focus.currentValue ?? 0 }
|
|
26
|
+
: {}),
|
|
27
|
+
...(measurable && focus.unit ? { unit: focus.unit } : {}),
|
|
28
|
+
};
|
|
29
|
+
}
|
package/src/corpus/index.ts
CHANGED
|
@@ -288,6 +288,9 @@ export * from './briefing';
|
|
|
288
288
|
// Spoken time -> due dates, and the per-field guesses extraction reports (bd startsim-b7kir).
|
|
289
289
|
export { isTimeZone, noteWideWhen, resolveSpokenTime } from './spoken-time';
|
|
290
290
|
export type { SpokenCandidate, SpokenConfidence, SpokenTime } from './spoken-time';
|
|
291
|
+
// Dates a meeting states -> due dates (bd startsim-768w.38.30).
|
|
292
|
+
export { resolveStatedDate, withStatedDue } from './stated-date';
|
|
293
|
+
export type { StatedDate, StatedDateOptions } from './stated-date';
|
|
291
294
|
export { AMBIGUITY_GAP, openQuestions } from './extraction-fields';
|
|
292
295
|
export type { FieldCandidate, FieldGuess, FieldSource, ItemFields } from './extraction-fields';
|
|
293
296
|
export { resolveSectionFields } from './voice-due';
|
|
@@ -301,6 +304,9 @@ export type { TrackerEntry, TrackerGroups } from './tracker-groups';
|
|
|
301
304
|
export { DEFAULT_TRACKER_SORT, TRACKER_SORTS, commitmentOrder, compareCommitments } from './tracker-sort';
|
|
302
305
|
export { summarizeFocuses } from './focus-overview';
|
|
303
306
|
export type { FocusSummary } from './focus-overview';
|
|
307
|
+
export { focusToGoalRow } from './goal-rows';
|
|
308
|
+
export { currentValueSeries, loadCurrentValueRevisions, toFocusRevision } from './focus-history';
|
|
309
|
+
export type { FocusRevision } from './focus-history';
|
|
304
310
|
export { actionsByNote } from './note-actions';
|
|
305
311
|
export type { NoteActions } from './note-actions';
|
|
306
312
|
|