@startsimpli/integrations 0.2.148 → 0.2.150
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -6
- package/src/__tests__/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__/liabilities.test.ts +224 -0
- package/src/__tests__/liability-plan-page.test.tsx +46 -0
- package/src/__tests__/stated-date-extract.test.ts +119 -0
- package/src/__tests__/stated-date.test.ts +107 -0
- package/src/components/index.ts +2 -0
- package/src/components/pages/LiabilityPlanPage.tsx +203 -0
- package/src/components/pages/PlanningPage.tsx +16 -2
- 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/types.ts +2 -2
- package/src/corpus/client.ts +18 -0
- 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 +10 -0
- package/src/corpus/liabilities.ts +238 -0
- package/src/corpus/liability-client.ts +101 -0
- package/src/corpus/liability-plan.ts +40 -0
- package/src/corpus/planning.ts +8 -0
- package/src/corpus/spoken-time.ts +4 -4
- package/src/corpus/stated-date.ts +187 -0
- package/src/corpus/types.ts +24 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The extractor carries the dates a meeting states onto the rows it creates
|
|
3
|
+
* (bd startsim-768w.38.30) - and invents none.
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, it } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { mergeDrafts, reconcile } from '../corpus/commitments';
|
|
8
|
+
import { extractCommitments, extractSystemPrompt, rulesExtract } from '../corpus/extract';
|
|
9
|
+
import { createFixtureCorpusApi, createFixtureExtractor, FIXTURE_ORG } from '../corpus/fixtures';
|
|
10
|
+
import type { Commitment, CorpusExtractorLlm, SourceDocument } from '../corpus/types';
|
|
11
|
+
|
|
12
|
+
const TANDEM = { orgId: FIXTURE_ORG };
|
|
13
|
+
const MEETING = '2026-08-05T15:00:00Z';
|
|
14
|
+
|
|
15
|
+
const BODY = [
|
|
16
|
+
'## Discussion',
|
|
17
|
+
'',
|
|
18
|
+
'- Kevin said the vendor contract will be signed by 29th July, nothing else changes there.',
|
|
19
|
+
'- Peggy will circulate the revised budget tomorrow after the board call.',
|
|
20
|
+
'- Julia thinks someone should probably revisit the onboarding emails at some point.',
|
|
21
|
+
'',
|
|
22
|
+
'## Next Steps',
|
|
23
|
+
'',
|
|
24
|
+
'- **Complete the equity item today** (Jonathan)',
|
|
25
|
+
'- **Pay the Rexford invoice by 11th August** (Kate)',
|
|
26
|
+
'- **Schedule call with Peggy for next week**',
|
|
27
|
+
'- **Review the data room permissions urgently** (Brian)',
|
|
28
|
+
'- **Send the revised term sheet on Wednesday** (Kevin)',
|
|
29
|
+
].join('\n');
|
|
30
|
+
|
|
31
|
+
function meeting(occurredAt: string | null = MEETING): SourceDocument {
|
|
32
|
+
return {
|
|
33
|
+
id: 'm1', title: 'Weekly sync', body: BODY, sections: [], occurredAt,
|
|
34
|
+
source: 'granola', sourceLabel: 'Granola', sourceRef: 'granola:m1', participants: [], scope: TANDEM,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const modelItems = (): CorpusExtractorLlm => ({
|
|
39
|
+
...createFixtureExtractor(),
|
|
40
|
+
async extract() {
|
|
41
|
+
return {
|
|
42
|
+
items: [
|
|
43
|
+
// the date is in the quote: code resolves it, whatever the model wrote
|
|
44
|
+
{ documentId: 'm1', title: 'Circulate the revised budget', quote: 'Peggy will circulate the revised budget tomorrow after the board call.', dueAt: '2031-01-01' },
|
|
45
|
+
{ documentId: 'm1', title: 'Get the vendor contract signed', quote: 'the vendor contract will be signed by 29th July', dueAt: null },
|
|
46
|
+
// the model estimated a date nobody stated
|
|
47
|
+
{ documentId: 'm1', title: 'Revisit the onboarding emails', quote: 'someone should probably revisit the onboarding emails at some point', dueAt: '2026-08-12' },
|
|
48
|
+
],
|
|
49
|
+
resolutions: [],
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('rules extraction carries stated dates', () => {
|
|
55
|
+
const byTitle = (occurredAt?: string | null) => Object.fromEntries(rulesExtract(meeting(occurredAt)).map((d) => [d.title, d]));
|
|
56
|
+
|
|
57
|
+
it('resolves absolute and relative dates against the meeting date', () => {
|
|
58
|
+
const d = byTitle();
|
|
59
|
+
expect(d['Complete the equity item today'].dueAt).toBe('2026-08-05T23:59:59Z');
|
|
60
|
+
expect(d['Pay the Rexford invoice by 11th August'].dueAt).toBe('2026-08-11T23:59:59Z');
|
|
61
|
+
expect(d['Send the revised term sheet on Wednesday']?.dueAt).toBeUndefined(); // said on a Wednesday: ambiguous
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('records what it read, as the row\'s due basis', () => {
|
|
65
|
+
const d = byTitle()['Complete the equity item today'];
|
|
66
|
+
expect(d.dueBasis).toContain('today');
|
|
67
|
+
expect(d.dueConfidence).toBeGreaterThan(0.8);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('leaves spans, urgency and undated items without a date', () => {
|
|
71
|
+
const d = byTitle();
|
|
72
|
+
expect(d['Schedule call with Peggy for next week'].dueAt).toBeUndefined();
|
|
73
|
+
expect(d['Review the data room permissions urgently'].dueAt).toBeUndefined();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('cannot resolve "today" without a meeting date, but still reads an absolute one', () => {
|
|
77
|
+
const d = byTitle(null);
|
|
78
|
+
expect(d['Complete the equity item today'].dueAt).toBeUndefined();
|
|
79
|
+
expect(d['Pay the Rexford invoice by 11th August'].dueAt).toBeUndefined(); // no year, no anchor: a guess
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('model extraction never supplies a date of its own', () => {
|
|
84
|
+
it('resolves the date from the quote, ignores the model\'s own dueAt, and leaves undated items unset', async () => {
|
|
85
|
+
const corpus = createFixtureCorpusApi({ scope: TANDEM, documents: [meeting()] });
|
|
86
|
+
const rows: Commitment[] = [];
|
|
87
|
+
(corpus as { listCommitments?: unknown }).listCommitments = async () => ({ count: 0, next: null, previous: null, results: [] });
|
|
88
|
+
(corpus as { saveCommitments?: unknown }).saveCommitments = async (items: Commitment[]) => { rows.push(...items); };
|
|
89
|
+
await extractCommitments({ scope: TANDEM }, { corpus, extractor: modelItems() });
|
|
90
|
+
const row = (needle: string) => rows.find((r) => r.title.includes(needle));
|
|
91
|
+
|
|
92
|
+
expect(row('Circulate the revised budget')?.dueAt).toBe('2026-08-06T23:59:59Z');
|
|
93
|
+
expect(row('vendor contract signed')?.dueAt).toBe('2026-07-29T23:59:59Z');
|
|
94
|
+
expect(row('Revisit the onboarding emails')).toBeDefined();
|
|
95
|
+
expect(row('Revisit the onboarding emails')?.dueAt).toBeUndefined();
|
|
96
|
+
expect(row('Complete the equity item today')?.dueAt).toBe('2026-08-05T23:59:59Z');
|
|
97
|
+
expect(row('Schedule call with Peggy')?.dueAt).toBeUndefined();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('still tells the model never to estimate a date', () => {
|
|
101
|
+
expect(extractSystemPrompt()).toMatch(/never estimate/i);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('rows that already exist are not touched', () => {
|
|
106
|
+
it('does not fill a due date onto an existing row, only onto a row it creates', () => {
|
|
107
|
+
const doc = meeting();
|
|
108
|
+
const drafts = rulesExtract(doc);
|
|
109
|
+
const first = reconcile([], mergeDrafts(drafts), { scope: TANDEM, documents: [doc] });
|
|
110
|
+
// The live rows were written before dates were read: none has one.
|
|
111
|
+
const live = first.commitments.map((c) => { const { dueAt, dueBasis, dueConfidence, ...rest } = c; void dueAt; void dueBasis; void dueConfidence; return rest; });
|
|
112
|
+
const second = reconcile(live, mergeDrafts(drafts), { scope: TANDEM, documents: [doc] });
|
|
113
|
+
expect(second.created).toBe(0);
|
|
114
|
+
expect(second.commitments.every((c) => c.dueAt === undefined)).toBe(true);
|
|
115
|
+
expect(second.touched).toEqual([]);
|
|
116
|
+
// ...while a fresh row does carry it.
|
|
117
|
+
expect(first.commitments.find((c) => c.title.includes('equity'))?.dueAt).toBe('2026-08-05T23:59:59Z');
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dates a meeting STATES -> due dates (bd startsim-768w.38.30). Pure and model-free:
|
|
3
|
+
* the date is computed from the meeting's own date; nothing is ever estimated.
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, it } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { resolveStatedDate } from '../corpus/stated-date';
|
|
8
|
+
|
|
9
|
+
// Wed 2026-08-05, the meeting the bead was measured on.
|
|
10
|
+
const MEETING = '2026-08-05T15:00:00Z';
|
|
11
|
+
const due = (text: string, anchor = MEETING, timeZone?: string) => resolveStatedDate(text, anchor, timeZone ? { timeZone } : {})?.dueAt ?? null;
|
|
12
|
+
|
|
13
|
+
describe('resolveStatedDate', () => {
|
|
14
|
+
it.each([
|
|
15
|
+
// relative, anchored to the meeting date
|
|
16
|
+
['Complete the equity item today', '2026-08-05T23:59:59Z'],
|
|
17
|
+
['**Complete the equity item** (Jonathan) - today', '2026-08-05T23:59:59Z'],
|
|
18
|
+
['Send the deck this afternoon', '2026-08-05T23:59:59Z'],
|
|
19
|
+
['Send the deck tonight', '2026-08-05T23:59:59Z'],
|
|
20
|
+
['Send the deck by end of day', '2026-08-05T23:59:59Z'],
|
|
21
|
+
['Send the deck tomorrow', '2026-08-06T23:59:59Z'],
|
|
22
|
+
['Send the deck the day after tomorrow', '2026-08-07T23:59:59Z'],
|
|
23
|
+
['Send the deck by Friday', '2026-08-07T23:59:59Z'],
|
|
24
|
+
['Send the deck on Monday', '2026-08-10T23:59:59Z'],
|
|
25
|
+
['Send the deck this Thursday', '2026-08-06T23:59:59Z'],
|
|
26
|
+
['Send the deck in 2 days', '2026-08-07T23:59:59Z'],
|
|
27
|
+
['Send the deck in two weeks', '2026-08-19T23:59:59Z'],
|
|
28
|
+
['Send the deck in a week', '2026-08-12T23:59:59Z'],
|
|
29
|
+
// absolute
|
|
30
|
+
['Pay the invoice by 29th July', '2026-07-29T23:59:59Z'],
|
|
31
|
+
['Pay the invoice by July 29', '2026-07-29T23:59:59Z'],
|
|
32
|
+
['Pay the invoice by 11th August', '2026-08-11T23:59:59Z'],
|
|
33
|
+
['Pay the invoice by 11 of August', '2026-08-11T23:59:59Z'],
|
|
34
|
+
['Pay the invoice by Oct 29', '2026-10-29T23:59:59Z'],
|
|
35
|
+
['Pay the invoice by October 29th, 2027', '2027-10-29T23:59:59Z'],
|
|
36
|
+
['Pay the invoice by 2026-09-01', '2026-09-01T23:59:59Z'],
|
|
37
|
+
// the same date said twice is still one date
|
|
38
|
+
['Send the deck tomorrow, yes tomorrow', '2026-08-06T23:59:59Z'],
|
|
39
|
+
])('%s -> %s', (text, expected) => {
|
|
40
|
+
expect(due(text)).toBe(expected);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it.each([
|
|
44
|
+
// no date at all
|
|
45
|
+
['Follow up with the vendor'],
|
|
46
|
+
['Look into the pricing page'],
|
|
47
|
+
// urgency is not a date
|
|
48
|
+
['Fix the login bug urgently'],
|
|
49
|
+
['Send the deck asap'],
|
|
50
|
+
['Send the deck soon'],
|
|
51
|
+
// a span, not a day: choosing a day would be estimating
|
|
52
|
+
['Send the deck next week'],
|
|
53
|
+
['Send the deck this week'],
|
|
54
|
+
['Send the deck by end of week'],
|
|
55
|
+
['Send the deck next month'],
|
|
56
|
+
['Send the deck in a few days'],
|
|
57
|
+
['Send the deck in a couple of weeks'],
|
|
58
|
+
// "next Friday" has two readings
|
|
59
|
+
['Send the deck next Friday'],
|
|
60
|
+
// said on a Wednesday: today or a week from now
|
|
61
|
+
['Send the deck on Wednesday'],
|
|
62
|
+
// two different dates in one item
|
|
63
|
+
['Send the deck tomorrow and the contract by 29th July'],
|
|
64
|
+
['Send the deck on Monday, review it by Friday'],
|
|
65
|
+
// past tense references and a bare month
|
|
66
|
+
['Revisit what we agreed last Friday'],
|
|
67
|
+
['Revisit what we agreed 3 days ago'],
|
|
68
|
+
['Send the deck in May'],
|
|
69
|
+
// not a calendar day
|
|
70
|
+
['Fix bug 29 in July build'],
|
|
71
|
+
['Pay the invoice by February 30'],
|
|
72
|
+
// a date so far from the meeting that the year is a guess
|
|
73
|
+
['Pay the invoice by March 3'],
|
|
74
|
+
// not a date
|
|
75
|
+
['Review the Monday.com integration'],
|
|
76
|
+
[''],
|
|
77
|
+
])('stays unset: %s', (text) => {
|
|
78
|
+
expect(due(text)).toBeNull();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('is computed in the stated time zone, so a late-evening meeting keeps its own day', () => {
|
|
82
|
+
// 2026-08-06 03:30Z is still Wed 5 Aug 20:30 in Los Angeles.
|
|
83
|
+
const late = '2026-08-06T03:30:00Z';
|
|
84
|
+
expect(due('Send the deck today', late)).toBe('2026-08-06T23:59:59Z');
|
|
85
|
+
expect(resolveStatedDate('Send the deck today', late, { timeZone: 'America/Los_Angeles' })?.date).toBe('2026-08-05');
|
|
86
|
+
expect(due('Send the deck today', late, 'America/Los_Angeles')).toBe('2026-08-06T06:59:59.000Z'.replace('.000Z', 'Z'));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('says what it read and how sure it is', () => {
|
|
90
|
+
const r = resolveStatedDate('Pay it by 29th July', MEETING);
|
|
91
|
+
expect(r).toMatchObject({ date: '2026-07-29', kind: 'absolute', phrase: expect.stringMatching(/29th July/i) });
|
|
92
|
+
expect(r?.basis).toContain('29th July');
|
|
93
|
+
const t = resolveStatedDate('Send it tomorrow', MEETING);
|
|
94
|
+
expect(t).toMatchObject({ date: '2026-08-06', kind: 'relative' });
|
|
95
|
+
expect(t?.basis).toContain('2026-08-05');
|
|
96
|
+
expect(t!.confidence).toBeGreaterThan(0.8);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('needs a usable meeting date for relative phrases, but not for absolute ones', () => {
|
|
100
|
+
expect(due('Send it tomorrow', '')).toBeNull();
|
|
101
|
+
expect(due('Send it tomorrow', 'not a date')).toBeNull();
|
|
102
|
+
expect(due('Send it by 2026-09-01', '')).toBe('2026-09-01T23:59:59Z');
|
|
103
|
+
expect(due('Send it by 29th July 2026', 'not a date')).toBe('2026-07-29T23:59:59Z');
|
|
104
|
+
// no year and no meeting date: the year would be a guess
|
|
105
|
+
expect(due('Send it by 29th July', '')).toBeNull();
|
|
106
|
+
});
|
|
107
|
+
});
|
package/src/components/index.ts
CHANGED
|
@@ -53,6 +53,8 @@ export { ExternalLinkChip } from './pages/task-tracker/ExternalLinkChip';
|
|
|
53
53
|
// row, the honesty banner, the overdue/changed predicates — so two views over
|
|
54
54
|
// one list cannot drift into disagreeing about what they mean.
|
|
55
55
|
export * from './pages/PlanningPage';
|
|
56
|
+
export * from './pages/goals';
|
|
57
|
+
export * from './pages/LiabilityPlanPage';
|
|
56
58
|
export {
|
|
57
59
|
PRIORITY_LABELS,
|
|
58
60
|
UnfilteredNotice,
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* LIABILITY PLAN — what is owed, and how fast a payoff scenario clears it
|
|
5
|
+
* (bd startsim-a01ps.8).
|
|
6
|
+
*
|
|
7
|
+
* A composer over two shared things and adds almost nothing of its own: the
|
|
8
|
+
* tenant's generic `liability` rows (via `LiabilityApi`) and the payoff UI in
|
|
9
|
+
* `@startsimpli/ui/payoff`, fed by `runPayoffScenario` (the shared engine).
|
|
10
|
+
*
|
|
11
|
+
* A SCENARIO IS A FOCUS. "Save scenario" writes a `focus` with subtype
|
|
12
|
+
* `payoff_scenario`; saved ones are listed back with `listFocuses({subtype})`.
|
|
13
|
+
* Saving is an explicit click and NEVER an effect: a render that wrote would be
|
|
14
|
+
* the write-loop recorded on `TrackerPageProps.now`.
|
|
15
|
+
*/
|
|
16
|
+
import * as React from 'react';
|
|
17
|
+
import {
|
|
18
|
+
PayoffBalanceChart,
|
|
19
|
+
PayoffScheduleTable,
|
|
20
|
+
PayoffSummaryCards,
|
|
21
|
+
RangeSlider,
|
|
22
|
+
ScenarioCompare,
|
|
23
|
+
moneyWhole,
|
|
24
|
+
} from '@startsimpli/ui/payoff';
|
|
25
|
+
import type { PayoffStrategy } from '@startsimpli/utils';
|
|
26
|
+
|
|
27
|
+
import type { LiabilityApi } from '../../corpus/liability-client';
|
|
28
|
+
import { runPayoffScenario } from '../../corpus/liability-plan';
|
|
29
|
+
import {
|
|
30
|
+
PAYOFF_SCENARIO,
|
|
31
|
+
scenarioFocusDraft,
|
|
32
|
+
scenarioParamsFromFocus,
|
|
33
|
+
type Liability,
|
|
34
|
+
type PayoffScenarioParams,
|
|
35
|
+
} from '../../corpus/liabilities';
|
|
36
|
+
import type { Focus, PlanningApi } from '../../corpus/types';
|
|
37
|
+
|
|
38
|
+
export interface LiabilityPlanPageProps {
|
|
39
|
+
api: LiabilityApi & Partial<Pick<PlanningApi, 'listFocuses' | 'createFocus'>>;
|
|
40
|
+
/** Epoch ms. Injected so a render never reads the clock. */
|
|
41
|
+
now: number;
|
|
42
|
+
/** Nest saved scenarios under this focus (the plan they vary). */
|
|
43
|
+
parentFocusId?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const KINDS = ['credit_card', 'mortgage', 'student_loan', 'auto_loan', 'personal_loan', 'line_of_credit', 'other'];
|
|
47
|
+
const label = (s: string) => s.replace(/_/g, ' ');
|
|
48
|
+
const strategyName = (s: PayoffStrategy) => (s === 'avalanche' ? 'Avalanche' : 'Snowball');
|
|
49
|
+
|
|
50
|
+
/** First day of the month after `now`, as the engine's `startDate`. */
|
|
51
|
+
function nextMonthStart(now: number): string {
|
|
52
|
+
const d = new Date(now);
|
|
53
|
+
return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + 1, 1)).toISOString().slice(0, 10);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function LiabilityPlanPage({ api, now, parentFocusId }: LiabilityPlanPageProps) {
|
|
57
|
+
const [liabilities, setLiabilities] = React.useState<Liability[] | null>(null);
|
|
58
|
+
const [saved, setSaved] = React.useState<Array<{ focus: Focus; params: PayoffScenarioParams }>>([]);
|
|
59
|
+
const [error, setError] = React.useState<string | null>(null);
|
|
60
|
+
const [strategy, setStrategy] = React.useState<PayoffStrategy>('avalanche');
|
|
61
|
+
const [extra, setExtra] = React.useState(300);
|
|
62
|
+
const startDate = React.useMemo(() => nextMonthStart(now), [now]);
|
|
63
|
+
|
|
64
|
+
const apiRef = React.useRef(api);
|
|
65
|
+
apiRef.current = api;
|
|
66
|
+
|
|
67
|
+
const load = React.useCallback(async () => {
|
|
68
|
+
try {
|
|
69
|
+
const page = await apiRef.current.listLiabilities({ pageSize: 200 });
|
|
70
|
+
setLiabilities(page.results);
|
|
71
|
+
const focuses = await apiRef.current.listFocuses?.({ subtype: PAYOFF_SCENARIO, pageSize: 50 });
|
|
72
|
+
setSaved((focuses?.results ?? []).flatMap((focus) => {
|
|
73
|
+
const params = scenarioParamsFromFocus(focus);
|
|
74
|
+
return params ? [{ focus, params }] : [];
|
|
75
|
+
}));
|
|
76
|
+
} catch (e) {
|
|
77
|
+
setError(e instanceof Error ? e.message : 'Could not load liabilities.');
|
|
78
|
+
}
|
|
79
|
+
}, []);
|
|
80
|
+
React.useEffect(() => { void load(); }, [load]);
|
|
81
|
+
|
|
82
|
+
const base = React.useMemo(
|
|
83
|
+
() => runPayoffScenario(liabilities ?? [], { strategy, startDate }),
|
|
84
|
+
[liabilities, strategy, startDate],
|
|
85
|
+
);
|
|
86
|
+
const minimums = base.monthlyPayment;
|
|
87
|
+
const payment = minimums + extra;
|
|
88
|
+
const params: PayoffScenarioParams = { strategy, monthlyPayment: payment, startDate };
|
|
89
|
+
const current = React.useMemo(() => runPayoffScenario(liabilities ?? [], params), [liabilities, strategy, payment, startDate]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
90
|
+
|
|
91
|
+
const scenarios = React.useMemo(() => {
|
|
92
|
+
const L = liabilities ?? [];
|
|
93
|
+
const other: PayoffStrategy = strategy === 'avalanche' ? 'snowball' : 'avalanche';
|
|
94
|
+
return [
|
|
95
|
+
{ id: 'minimums', label: 'Minimums only', schedule: runPayoffScenario(L, { strategy, monthlyPayment: minimums, startDate }).schedule },
|
|
96
|
+
{ id: 'current', label: `${strategyName(strategy)} at ${moneyWhole(payment)}/mo`, schedule: current.schedule },
|
|
97
|
+
{ id: 'other', label: `${strategyName(other)} at ${moneyWhole(payment)}/mo`, schedule: runPayoffScenario(L, { strategy: other, monthlyPayment: payment, startDate }).schedule },
|
|
98
|
+
...saved.map((s) => ({
|
|
99
|
+
id: s.focus.id,
|
|
100
|
+
label: `${s.focus.title} (saved)`,
|
|
101
|
+
schedule: runPayoffScenario(L, { startDate, ...s.params }).schedule,
|
|
102
|
+
})),
|
|
103
|
+
];
|
|
104
|
+
}, [liabilities, strategy, minimums, payment, startDate, current, saved]);
|
|
105
|
+
|
|
106
|
+
async function addLiability(form: HTMLFormElement) {
|
|
107
|
+
const f = new FormData(form);
|
|
108
|
+
const n = (k: string) => (String(f.get(k) ?? '').trim() === '' ? undefined : Number(f.get(k)));
|
|
109
|
+
try {
|
|
110
|
+
await apiRef.current.createLiability?.({
|
|
111
|
+
title: String(f.get('title') ?? '').trim(),
|
|
112
|
+
subtype: String(f.get('subtype') ?? 'other'),
|
|
113
|
+
balance: n('balance'), apr: n('apr'), minPayment: n('minPayment'),
|
|
114
|
+
});
|
|
115
|
+
form.reset();
|
|
116
|
+
await load();
|
|
117
|
+
} catch (e) {
|
|
118
|
+
setError(e instanceof Error ? e.message : 'Could not add the liability.');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function saveScenario() {
|
|
123
|
+
try {
|
|
124
|
+
await apiRef.current.createFocus?.(
|
|
125
|
+
scenarioFocusDraft(`${strategyName(strategy)} at ${moneyWhole(payment)}/mo`, params, { parentId: parentFocusId }),
|
|
126
|
+
);
|
|
127
|
+
await load();
|
|
128
|
+
} catch (e) {
|
|
129
|
+
setError(e instanceof Error ? e.message : 'Could not save the scenario.');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (liabilities === null && !error) return <p data-testid="liabilities-loading">Loading liabilities…</p>;
|
|
134
|
+
|
|
135
|
+
const total = (liabilities ?? []).reduce((s, l) => s + (l.status === 'active' ? l.balance ?? 0 : 0), 0);
|
|
136
|
+
return (
|
|
137
|
+
<div className="space-y-8" data-testid="liability-plan">
|
|
138
|
+
<header className="space-y-1">
|
|
139
|
+
<h1 className="text-2xl font-semibold">Debt plan</h1>
|
|
140
|
+
<p className="text-sm text-muted-foreground" data-testid="liability-total">
|
|
141
|
+
{liabilities?.length ?? 0} liabilities · {moneyWhole(total)} owed
|
|
142
|
+
</p>
|
|
143
|
+
</header>
|
|
144
|
+
{error ? <p role="alert" className="text-sm text-red-600">{error}</p> : null}
|
|
145
|
+
|
|
146
|
+
<section className="space-y-2">
|
|
147
|
+
<h2 className="text-lg font-medium">Liabilities</h2>
|
|
148
|
+
{liabilities?.length ? (
|
|
149
|
+
<table className="w-full text-sm" data-testid="liability-table">
|
|
150
|
+
<thead><tr className="text-left text-muted-foreground"><th>Name</th><th>Kind</th><th className="text-right">Balance</th><th className="text-right">APR</th><th className="text-right">Minimum</th></tr></thead>
|
|
151
|
+
<tbody>
|
|
152
|
+
{liabilities.map((l) => (
|
|
153
|
+
<tr key={l.id} data-testid="liability-row">
|
|
154
|
+
<td>{l.title}</td><td className="capitalize">{label(l.subtype)}</td>
|
|
155
|
+
<td className="text-right tabular-nums">{l.balance !== undefined ? moneyWhole(l.balance) : '—'}</td>
|
|
156
|
+
<td className="text-right tabular-nums">{l.apr !== undefined ? `${l.apr}%` : '—'}</td>
|
|
157
|
+
<td className="text-right tabular-nums">{l.minPayment !== undefined ? moneyWhole(l.minPayment) : '—'}</td>
|
|
158
|
+
</tr>
|
|
159
|
+
))}
|
|
160
|
+
</tbody>
|
|
161
|
+
</table>
|
|
162
|
+
) : <p className="text-sm text-muted-foreground">Nothing owed yet. Add a liability below.</p>}
|
|
163
|
+
{api.createLiability ? (
|
|
164
|
+
<form className="flex flex-wrap items-end gap-2" onSubmit={(e) => { e.preventDefault(); void addLiability(e.currentTarget); }} data-testid="liability-form">
|
|
165
|
+
<input name="title" required placeholder="Name" aria-label="Name" className="rounded-md border px-2 py-1" />
|
|
166
|
+
<select name="subtype" aria-label="Kind" className="rounded-md border px-2 py-1">{KINDS.map((k) => <option key={k} value={k}>{label(k)}</option>)}</select>
|
|
167
|
+
<input name="balance" type="number" min="0" step="any" placeholder="Balance" aria-label="Balance" className="w-28 rounded-md border px-2 py-1" />
|
|
168
|
+
<input name="apr" type="number" min="0" max="100" step="any" placeholder="APR %" aria-label="APR" className="w-24 rounded-md border px-2 py-1" />
|
|
169
|
+
<input name="minPayment" type="number" min="0" step="any" placeholder="Minimum" aria-label="Minimum payment" className="w-28 rounded-md border px-2 py-1" />
|
|
170
|
+
<button type="submit" className="rounded-md border px-3 py-1">Add liability</button>
|
|
171
|
+
</form>
|
|
172
|
+
) : null}
|
|
173
|
+
</section>
|
|
174
|
+
|
|
175
|
+
{current.debts.length ? (
|
|
176
|
+
<>
|
|
177
|
+
<section className="grid gap-6 sm:grid-cols-2">
|
|
178
|
+
<RangeSlider label="Extra per month" min={0} max={1500} step={25} value={extra} onChange={setExtra} format={moneyWhole} />
|
|
179
|
+
<div className="space-y-2">
|
|
180
|
+
<p className="text-sm font-medium">Strategy</p>
|
|
181
|
+
<div className="flex gap-2">
|
|
182
|
+
{(['avalanche', 'snowball'] as const).map((s) => (
|
|
183
|
+
<button key={s} type="button" onClick={() => setStrategy(s)} aria-pressed={strategy === s}
|
|
184
|
+
className={'rounded-md border px-3 py-1.5 text-sm capitalize ' + (strategy === s ? 'bg-primary text-primary-foreground' : '')}>{s}</button>
|
|
185
|
+
))}
|
|
186
|
+
</div>
|
|
187
|
+
</div>
|
|
188
|
+
</section>
|
|
189
|
+
<PayoffSummaryCards schedule={current.schedule} startingBalance={current.startingBalance} currentBalance={current.startingBalance} />
|
|
190
|
+
<PayoffBalanceChart schedule={current.schedule} debts={current.labels} />
|
|
191
|
+
<section className="space-y-2">
|
|
192
|
+
<div className="flex items-center justify-between">
|
|
193
|
+
<h2 className="text-lg font-medium">Scenarios</h2>
|
|
194
|
+
{api.createFocus ? <button type="button" onClick={() => void saveScenario()} className="rounded-md border px-3 py-1 text-sm" data-testid="save-scenario">Save this scenario</button> : null}
|
|
195
|
+
</div>
|
|
196
|
+
<ScenarioCompare scenarios={scenarios} />
|
|
197
|
+
</section>
|
|
198
|
+
<section className="space-y-2"><h2 className="text-lg font-medium">Payment schedule</h2><PayoffScheduleTable schedule={current.schedule} debts={current.labels} /></section>
|
|
199
|
+
</>
|
|
200
|
+
) : null}
|
|
201
|
+
</div>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
@@ -33,6 +33,7 @@ import * as React from 'react';
|
|
|
33
33
|
|
|
34
34
|
import { displayProgress, focusStatusLabel, standingLabel } from '../../corpus/planning';
|
|
35
35
|
import { FocusDocuments } from '../FocusDocuments';
|
|
36
|
+
import { FocusProgressHistory } from './goals/FocusProgressHistory';
|
|
36
37
|
import {
|
|
37
38
|
WorkItemRow,
|
|
38
39
|
compareForScreen,
|
|
@@ -121,11 +122,18 @@ export interface PlanningPageProps {
|
|
|
121
122
|
now?: number;
|
|
122
123
|
/** The reader's IANA zone, for "overdue" and "next due". Default UTC. */
|
|
123
124
|
timeZone?: string;
|
|
125
|
+
/**
|
|
126
|
+
* Optional CONTROLLED selection: the id of the focus whose detail is open.
|
|
127
|
+
* Lets a host route straight to one (`/planning?focus=<id>`), e.g. from the
|
|
128
|
+
* Goals table. Omit both and the page keeps its own selection.
|
|
129
|
+
*/
|
|
130
|
+
focusId?: string | null;
|
|
131
|
+
onFocusChange?: (focusId: string | null) => void;
|
|
124
132
|
classNames?: Partial<Record<PlanningSlot, string>>;
|
|
125
133
|
}
|
|
126
134
|
|
|
127
135
|
export function PlanningPage({
|
|
128
|
-
api, scope, onOpenDocument, now, timeZone, classNames = {},
|
|
136
|
+
api, scope, onOpenDocument, now, timeZone, focusId, onFocusChange, classNames = {},
|
|
129
137
|
}: PlanningPageProps) {
|
|
130
138
|
const cn = { ...DEFAULTS, ...classNames };
|
|
131
139
|
|
|
@@ -140,7 +148,12 @@ export function PlanningPage({
|
|
|
140
148
|
|
|
141
149
|
const [focuses, setFocuses] = React.useState<Focus[]>([]);
|
|
142
150
|
const [standings, setStandings] = React.useState<Record<string, FocusStanding>>({});
|
|
143
|
-
const [
|
|
151
|
+
const [innerSelected, setInnerSelected] = React.useState<string | null>(null);
|
|
152
|
+
const selected = focusId !== undefined ? focusId : innerSelected;
|
|
153
|
+
const setSelected = React.useCallback((id: string | null) => {
|
|
154
|
+
setInnerSelected(id);
|
|
155
|
+
onFocusChange?.(id);
|
|
156
|
+
}, [onFocusChange]);
|
|
144
157
|
const [items, setItems] = React.useState<Commitment[]>([]);
|
|
145
158
|
const [applied, setApplied] = React.useState<string[]>([]);
|
|
146
159
|
const [members, setMembers] = React.useState<Array<{ sub: string; email: string; name?: string }>>([]);
|
|
@@ -372,6 +385,7 @@ export function PlanningPage({
|
|
|
372
385
|
classNames={cn}
|
|
373
386
|
onSelect={() => setSelected(null)}
|
|
374
387
|
/>
|
|
388
|
+
<FocusProgressHistory focus={selectedFocus} api={api} />
|
|
375
389
|
{error ? <p className={cn.error} role="alert">{error}</p> : null}
|
|
376
390
|
</section>
|
|
377
391
|
|
|
@@ -30,6 +30,7 @@ export function ConnectionCard({
|
|
|
30
30
|
const [busy, setBusy] = React.useState('');
|
|
31
31
|
const [error, setError] = React.useState('');
|
|
32
32
|
const [notice, setNotice] = React.useState('');
|
|
33
|
+
const [checkWhy, setCheckWhy] = React.useState<{ reason: string; next_step: string } | null>(null);
|
|
33
34
|
/** Sentences the SERVER wrote about the last settings save. Never composed here. */
|
|
34
35
|
const [notices, setNotices] = React.useState<string[]>([]);
|
|
35
36
|
const [replacing, setReplacing] = React.useState(false);
|
|
@@ -133,8 +134,10 @@ export function ConnectionCard({
|
|
|
133
134
|
className={cn.button}
|
|
134
135
|
disabled={Boolean(busy)}
|
|
135
136
|
onClick={() => void guard('check', async () => {
|
|
137
|
+
setCheckWhy(null);
|
|
136
138
|
const res = await api.checkConnection(connection.id);
|
|
137
139
|
setNotice(res.detail || (res.ok ? 'Connection is healthy.' : ''));
|
|
140
|
+
setCheckWhy(res.reason ? { reason: res.reason, next_step: res.next_step ?? '' } : null);
|
|
138
141
|
onChanged();
|
|
139
142
|
})}
|
|
140
143
|
>
|
|
@@ -394,6 +397,15 @@ export function ConnectionCard({
|
|
|
394
397
|
</CapabilityPicker>
|
|
395
398
|
|
|
396
399
|
{notice ? <p className={cn.muted}>{notice}</p> : null}
|
|
400
|
+
{/* A key that authenticated but sees nothing: the connector's own words for
|
|
401
|
+
why and what to do (bd startsim-768w.38.16). Generic, so no vendor is named
|
|
402
|
+
here, and `detail` above is never replaced by it. */}
|
|
403
|
+
{checkWhy ? (
|
|
404
|
+
<div className={cn.card} data-check-reason>
|
|
405
|
+
<p className="text-sm text-gray-900">{checkWhy.reason}</p>
|
|
406
|
+
{checkWhy.next_step ? <p className={cn.muted}>{checkWhy.next_step}</p> : null}
|
|
407
|
+
</div>
|
|
408
|
+
) : null}
|
|
397
409
|
{/* WHAT THE CHANGE COSTS, in the server's words. Rendered verbatim: this
|
|
398
410
|
file names no vendor and cannot know which settings restart a walk. */}
|
|
399
411
|
{notices.map((said) => (
|
|
@@ -51,7 +51,7 @@ export interface BoundApi {
|
|
|
51
51
|
config?: Record<string, unknown>;
|
|
52
52
|
capabilities_enabled?: string[];
|
|
53
53
|
}): Promise<Connection>;
|
|
54
|
-
checkConnection(id: string): Promise<{ ok: boolean; account_label: string; detail: string }>;
|
|
54
|
+
checkConnection(id: string): Promise<{ ok: boolean; account_label: string; detail: string; reason?: string; next_step?: string }>;
|
|
55
55
|
rotateCredential(id: string, credentials: Record<string, unknown>): Promise<Connection>;
|
|
56
56
|
disconnect(id: string): Promise<void>;
|
|
57
57
|
updateConnection?(id: string, input: {
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A focus's progress over time, drawn by the shared `RangeTimelineChart`
|
|
5
|
+
* (`@startsimpli/ui/insights`) from the tenant's revision trail. See
|
|
6
|
+
* `corpus/focus-history.ts` for what the data is and what it is not.
|
|
7
|
+
*
|
|
8
|
+
* Shown only for a MEASURABLE focus (a target above zero): a qualitative focus has
|
|
9
|
+
* no progress number to chart. `today` is injected and the clock is read once at
|
|
10
|
+
* mount; this never calls `Date.now()` in render.
|
|
11
|
+
*/
|
|
12
|
+
import * as React from 'react';
|
|
13
|
+
import { RangeTimelineChart } from '@startsimpli/ui/insights';
|
|
14
|
+
|
|
15
|
+
import { currentValueSeries, loadCurrentValueRevisions, type FocusRevision } from '../../../corpus/focus-history';
|
|
16
|
+
import type { Focus, PlanningApi } from '../../../corpus/types';
|
|
17
|
+
|
|
18
|
+
export interface FocusProgressHistoryProps {
|
|
19
|
+
focus: Focus;
|
|
20
|
+
api: Pick<PlanningApi, 'listFocusRevisions'>;
|
|
21
|
+
/** ISO date the window ends on. Defaults to the day this mounted. */
|
|
22
|
+
today?: string;
|
|
23
|
+
className?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type State = { kind: 'loading' } | { kind: 'ready'; revisions: FocusRevision[] } | { kind: 'unavailable' };
|
|
27
|
+
|
|
28
|
+
export function FocusProgressHistory({ focus, api, today, className }: FocusProgressHistoryProps) {
|
|
29
|
+
const [mounted] = React.useState(() => new Date().toISOString().slice(0, 10));
|
|
30
|
+
const anchor = today ?? mounted;
|
|
31
|
+
const [state, setState] = React.useState<State>({ kind: 'loading' });
|
|
32
|
+
const apiRef = React.useRef(api);
|
|
33
|
+
apiRef.current = api;
|
|
34
|
+
const measurable = typeof focus.targetValue === 'number' && focus.targetValue > 0;
|
|
35
|
+
const read = api.listFocusRevisions;
|
|
36
|
+
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
if (!read || !measurable) return undefined;
|
|
39
|
+
let live = true;
|
|
40
|
+
setState({ kind: 'loading' });
|
|
41
|
+
loadCurrentValueRevisions((page) => apiRef.current.listFocusRevisions!(focus.id, { page, pageSize: 100 }), anchor)
|
|
42
|
+
.then((revisions) => { if (live) setState({ kind: 'ready', revisions }); })
|
|
43
|
+
.catch(() => { if (live) setState({ kind: 'unavailable' }); });
|
|
44
|
+
return () => { live = false; };
|
|
45
|
+
}, [read, measurable, focus.id, anchor]);
|
|
46
|
+
|
|
47
|
+
const { points, since } = React.useMemo(
|
|
48
|
+
() => (state.kind === 'ready' ? currentValueSeries(state.revisions, anchor) : { points: [] as never[], since: undefined }),
|
|
49
|
+
[state, anchor],
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (!read || !measurable) return null;
|
|
53
|
+
return (
|
|
54
|
+
<section className={className ?? 'space-y-2'} aria-label="Progress over time" data-testid="focus-progress-history">
|
|
55
|
+
{state.kind === 'loading' ? <p className="text-sm text-gray-500">Loading progress history…</p> : null}
|
|
56
|
+
{state.kind === 'unavailable' ? (
|
|
57
|
+
<p className="text-sm text-gray-500">Progress history is not available for this workspace yet.</p>
|
|
58
|
+
) : null}
|
|
59
|
+
{state.kind === 'ready' && points.length === 0 ? (
|
|
60
|
+
<p className="text-sm text-gray-500">No progress changes recorded yet. The chart fills in as the current value is updated.</p>
|
|
61
|
+
) : null}
|
|
62
|
+
{state.kind === 'ready' && points.length > 0 ? (
|
|
63
|
+
<>
|
|
64
|
+
<RangeTimelineChart
|
|
65
|
+
title="Progress over time"
|
|
66
|
+
points={points}
|
|
67
|
+
anchor={anchor}
|
|
68
|
+
direction="back"
|
|
69
|
+
defaultRange="90d"
|
|
70
|
+
height={240}
|
|
71
|
+
/>
|
|
72
|
+
<p className="text-xs text-gray-500">Recorded since {since}. Earlier values were not tracked.</p>
|
|
73
|
+
</>
|
|
74
|
+
) : null}
|
|
75
|
+
</section>
|
|
76
|
+
);
|
|
77
|
+
}
|