@startsimpli/integrations 0.2.129 → 0.2.131
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 +5 -5
- package/src/__tests__/extract-classify.test.ts +224 -0
- package/src/__tests__/fixtures/nov5-note.ts +35 -0
- package/src/__tests__/task-tracker-connection.test.tsx +155 -0
- package/src/__tests__/task-tracker-shared.test.ts +108 -0
- package/src/__tests__/tracker-linear-chip.test.tsx +87 -0
- package/src/__tests__/voice-sections.test.ts +5 -15
- package/src/api/connections.ts +14 -0
- package/src/components/index.ts +4 -0
- package/src/components/pages/ConnectionsPage.tsx +26 -2
- package/src/components/pages/TrackerPage.tsx +18 -0
- package/src/components/pages/task-tracker/ExternalLinkChip.tsx +53 -0
- package/src/components/pages/task-tracker/TaskTrackerSettings.tsx +112 -0
- package/src/components/pages/types.ts +4 -0
- package/src/components/pages/work-items.tsx +8 -1
- package/src/corpus/classify.ts +147 -0
- package/src/corpus/commitments.ts +0 -5
- package/src/corpus/entities.ts +17 -0
- package/src/corpus/extract.ts +72 -12
- package/src/corpus/index.ts +5 -0
- package/src/corpus/llm.ts +53 -0
- package/src/corpus/types.ts +51 -0
- package/src/index.ts +2 -0
- package/src/native/__tests__/task-tracker.test.tsx +206 -0
- package/src/native/app/FoundryApp.tsx +1 -1
- package/src/native/app/data.ts +5 -1
- package/src/native/app/registry.tsx +4 -2
- package/src/native/corpus/fake-data.ts +3 -3
- package/src/native/corpus/fake-tenant.ts +3 -0
- package/src/native/screens/connections/ConnectionsScreens.tsx +52 -12
- package/src/native/screens/connections/controller.ts +71 -1
- package/src/native/screens/connections/fake.ts +38 -7
- package/src/native/screens/connections/tab.tsx +25 -7
- package/src/native/task-tracker/SyncChips.tsx +35 -0
- package/src/native/task-tracker/TrackerSettingsScreen.tsx +85 -0
- package/src/native/task-tracker/index.ts +2 -0
- package/src/native/tracker/TrackerDetailScreen.tsx +14 -1
- package/src/native/tracker/TrackerListScreen.tsx +7 -1
- package/src/native/tracker/tab.tsx +16 -7
- package/src/task-tracker/index.ts +5 -0
- package/src/task-tracker/item-sync.ts +87 -0
- package/src/task-tracker/links.ts +34 -0
- package/src/task-tracker/settings-controller.ts +138 -0
- package/src/task-tracker/sync-config.ts +95 -0
- package/src/task-tracker/useTrackerName.ts +29 -0
package/src/corpus/extract.ts
CHANGED
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
* fit in a request — one document is about twenty seconds — so the sweep is a
|
|
42
42
|
* durable, resumable, leased RUN in `./runs`, and this is the step it is made of.
|
|
43
43
|
*/
|
|
44
|
+
import { applyDecisions, buildClassifyRequest, candidatesFromFocuses } from './classify';
|
|
44
45
|
import { EXTRACTOR_VERSION, applyResolutions, mergeDrafts, reconcile } from './commitments';
|
|
45
46
|
import { enforceScope } from './retrieval';
|
|
46
47
|
import { documentText, outcomeSections, documentParts, splitSections, words } from './text';
|
|
47
|
-
import { sectionKey } from './voice-sections';
|
|
48
48
|
import type {
|
|
49
49
|
Commitment,
|
|
50
50
|
CommitmentApi,
|
|
@@ -56,6 +56,7 @@ import type {
|
|
|
56
56
|
ExtractionDraft,
|
|
57
57
|
ExtractionModelFailure,
|
|
58
58
|
ExtractionResult,
|
|
59
|
+
PlanningApi,
|
|
59
60
|
ResolutionClaim,
|
|
60
61
|
SourceDocument,
|
|
61
62
|
VerificationRequest,
|
|
@@ -159,19 +160,17 @@ export function rulesExtract(document: SourceDocument): CommitmentDraft[] {
|
|
|
159
160
|
// Not widened for other sources: see the note on LEADING_BOLD for what a
|
|
160
161
|
// discussion heading costs in precision.
|
|
161
162
|
const voice = document.source === 'voice';
|
|
162
|
-
const projectOf = new Map(
|
|
163
|
-
(document.sectionFilings ?? []).filter((f) => f.focusId).map((f) => [sectionKey(f.label), f.focusId as string]),
|
|
164
|
-
);
|
|
165
163
|
|
|
166
164
|
const drafts: CommitmentDraft[] = [];
|
|
167
165
|
for (const section of voice ? splitSections(text).filter((s) => s.heading) : outcomeSections(text)) {
|
|
168
|
-
const focusId = voice ? projectOf.get(sectionKey(section.heading)) : undefined;
|
|
169
166
|
let current: { line: string; detail: string[] } | null = null;
|
|
170
167
|
const flush = () => {
|
|
171
168
|
if (!current) return;
|
|
172
169
|
const draft = toDraft(document, current.line, current.detail.join('\n'));
|
|
173
170
|
if (draft) {
|
|
174
|
-
|
|
171
|
+
// The heading is kept on the mention as presentation. It is NOT a project
|
|
172
|
+
// guess: which project an item is for is classified per item (./classify).
|
|
173
|
+
drafts.push({ ...draft, ...(voice ? { section: section.heading } : {}) });
|
|
175
174
|
}
|
|
176
175
|
current = null;
|
|
177
176
|
};
|
|
@@ -384,7 +383,11 @@ export interface ExtractRequest {
|
|
|
384
383
|
}
|
|
385
384
|
|
|
386
385
|
export interface ExtractDeps {
|
|
387
|
-
|
|
386
|
+
/**
|
|
387
|
+
* `listFocuses` is what a new item is classified against (bd startsim-v0mqh);
|
|
388
|
+
* without it, or without `extractor.classify`, new items stay unclassified.
|
|
389
|
+
*/
|
|
390
|
+
corpus: CorpusApi & Partial<CommitmentApi> & Partial<Pick<PlanningApi, 'listFocuses'>>;
|
|
388
391
|
extractor: CorpusExtractorLlm;
|
|
389
392
|
}
|
|
390
393
|
|
|
@@ -507,6 +510,9 @@ export async function extractCommitments(
|
|
|
507
510
|
// 6. resolutions, against the documents the scope guard approved and nothing else.
|
|
508
511
|
const resolutions = applyResolutions(reconciled.commitments, claims, { documents });
|
|
509
512
|
|
|
513
|
+
let classified: number | undefined;
|
|
514
|
+
let classifyFailure: ExtractionModelFailure | null | undefined;
|
|
515
|
+
|
|
510
516
|
// 7. write WHAT CHANGED, keyed on `external_id`.
|
|
511
517
|
//
|
|
512
518
|
// Not the whole corpus. The tenant has no bulk upsert (a list body is
|
|
@@ -516,13 +522,27 @@ export async function extractCommitments(
|
|
|
516
522
|
// the 60-second gateway once there were ninety-eight of them.
|
|
517
523
|
const changed = new Set([...reconciled.touched, ...resolutions.touched]);
|
|
518
524
|
if (corpus.saveCommitments && changed.size) {
|
|
519
|
-
//
|
|
520
|
-
//
|
|
521
|
-
//
|
|
525
|
+
// CLASSIFY WHAT THIS RUN CREATED (bd startsim-v0mqh). Only created rows: one
|
|
526
|
+
// that already existed may have been moved by a person, and a re-run must not
|
|
527
|
+
// undo that. Each new item gets one answer from the real project list - a
|
|
528
|
+
// project, `personal`, or nothing - never a guess from the note's sections.
|
|
522
529
|
const known = new Set(existing.map((item) => item.externalId));
|
|
530
|
+
const fresh = resolutions.commitments.filter((item) => changed.has(item.externalId) && !known.has(item.externalId));
|
|
531
|
+
const classification = await classifyFresh(fresh, { corpus, extractor, documents, promptText });
|
|
532
|
+
for (const item of fresh) {
|
|
533
|
+
const placed = classification.placed.get(item.externalId);
|
|
534
|
+
if (placed?.focusId) {
|
|
535
|
+
item.focusId = placed.focusId;
|
|
536
|
+
item.externalFocusId = placed.focusId;
|
|
537
|
+
} else if (placed?.destination) {
|
|
538
|
+
item.destination = placed.destination;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
classified = classification.placed.size;
|
|
542
|
+
classifyFailure = classification.failure;
|
|
523
543
|
const fileUnder: Record<string, string> = {};
|
|
524
|
-
for (const item of
|
|
525
|
-
if (
|
|
544
|
+
for (const item of fresh) {
|
|
545
|
+
if (item.focusId) fileUnder[item.externalId] = item.focusId;
|
|
526
546
|
}
|
|
527
547
|
const rows = resolutions.commitments.filter((item) => changed.has(item.externalId));
|
|
528
548
|
await (Object.keys(fileUnder).length ? corpus.saveCommitments(rows, { fileUnder }) : corpus.saveCommitments(rows));
|
|
@@ -548,10 +568,50 @@ export async function extractCommitments(
|
|
|
548
568
|
// it is the one that empties the list; a verifier that did not answer is
|
|
549
569
|
// reported when the proposer did.
|
|
550
570
|
modelFailure: modelFailure ?? checked.failure,
|
|
571
|
+
...(classified !== undefined ? { classified } : {}),
|
|
572
|
+
...(classifyFailure ? { classifyFailure } : {}),
|
|
551
573
|
};
|
|
552
574
|
void matched;
|
|
553
575
|
}
|
|
554
576
|
|
|
577
|
+
/**
|
|
578
|
+
* One batched classification of the new items against the open projects. Never
|
|
579
|
+
* throws: a model that did not answer leaves every item unclassified and the
|
|
580
|
+
* failure is returned, because the items themselves are the product and an
|
|
581
|
+
* unfiled item loses nothing.
|
|
582
|
+
*/
|
|
583
|
+
async function classifyFresh(
|
|
584
|
+
fresh: Commitment[],
|
|
585
|
+
ctx: {
|
|
586
|
+
corpus: ExtractDeps['corpus'];
|
|
587
|
+
extractor: CorpusExtractorLlm;
|
|
588
|
+
documents: SourceDocument[];
|
|
589
|
+
promptText: Map<string, string>;
|
|
590
|
+
},
|
|
591
|
+
): Promise<{ placed: ReturnType<typeof applyDecisions>; failure: ExtractionModelFailure | null }> {
|
|
592
|
+
const none = { placed: new Map(), failure: null };
|
|
593
|
+
if (!fresh.length || !ctx.extractor.classify || !ctx.corpus.listFocuses) return none;
|
|
594
|
+
try {
|
|
595
|
+
const focuses = await readAllFocuses(ctx.corpus.listFocuses.bind(ctx.corpus));
|
|
596
|
+
const candidates = candidatesFromFocuses(focuses);
|
|
597
|
+
const request = buildClassifyRequest(fresh, candidates, ctx.documents, (document) => ctx.promptText.get(document.id) ?? '');
|
|
598
|
+
const draft = await ctx.extractor.classify(request);
|
|
599
|
+
return { placed: applyDecisions(request.items, candidates, draft), failure: null };
|
|
600
|
+
} catch (err) {
|
|
601
|
+
return { placed: new Map(), failure: describeModelFailure('extract', err) };
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
async function readAllFocuses(list: NonNullable<PlanningApi['listFocuses']>) {
|
|
606
|
+
const out = [];
|
|
607
|
+
for (let page = 1; page <= 10; page++) {
|
|
608
|
+
const result = await list({ page, pageSize: 200 });
|
|
609
|
+
out.push(...result.results);
|
|
610
|
+
if (!result.next || result.results.length === 0) break;
|
|
611
|
+
}
|
|
612
|
+
return out;
|
|
613
|
+
}
|
|
614
|
+
|
|
555
615
|
/**
|
|
556
616
|
* Name the failure, and separate a blown deadline from everything else.
|
|
557
617
|
*
|
package/src/corpus/index.ts
CHANGED
|
@@ -119,6 +119,11 @@ export {
|
|
|
119
119
|
} from './extract';
|
|
120
120
|
export type { ExtractCommitmentsOptions, ExtractDeps, ExtractRequest } from './extract';
|
|
121
121
|
|
|
122
|
+
// Classifying each NEW item against the real project list (bd startsim-v0mqh).
|
|
123
|
+
export { applyDecisions, candidatesFromFocuses, PERSONAL } from './classify';
|
|
124
|
+
export type { Classified } from './classify';
|
|
125
|
+
export type { ClassifyCandidate, ClassifyDraft, ClassifyRequest } from './types';
|
|
126
|
+
|
|
122
127
|
// Extraction as a JOB — durable, leased, resumable (bd startsim-768w.38.28).
|
|
123
128
|
export {
|
|
124
129
|
EMPTY_TOTALS,
|
package/src/corpus/llm.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { SpeechService } from '@startsimpli/llm/speech';
|
|
|
20
20
|
import type { SpeechServiceConfig } from '@startsimpli/llm/speech';
|
|
21
21
|
|
|
22
22
|
import { answerSystemPrompt, renderAnswerPrompt } from './ask';
|
|
23
|
+
import { classifySystemPrompt, renderClassifyPrompt } from './classify';
|
|
23
24
|
import {
|
|
24
25
|
extractSystemPrompt,
|
|
25
26
|
renderExtractPrompt,
|
|
@@ -31,6 +32,8 @@ import type { AnalysisUsage, FocusChoice, TranscriptOutcome, VoiceAnalysis, Voic
|
|
|
31
32
|
import type {
|
|
32
33
|
AnswerDraft,
|
|
33
34
|
AnswerRequest,
|
|
35
|
+
ClassifyDraft,
|
|
36
|
+
ClassifyRequest,
|
|
34
37
|
CorpusExtractorLlm,
|
|
35
38
|
CorpusLlm,
|
|
36
39
|
ExtractionDraft,
|
|
@@ -321,6 +324,23 @@ export function parseVerificationDraft(raw: string): VerificationDraft | null {
|
|
|
321
324
|
};
|
|
322
325
|
}
|
|
323
326
|
|
|
327
|
+
/** The classifier's reply: `{decisions:[{id, project}]}`, or null when it is not that shape. */
|
|
328
|
+
export function parseClassifyDraft(raw: string): ClassifyDraft | null {
|
|
329
|
+
const extraction = extractJson(raw);
|
|
330
|
+
if (!extraction.success || !extraction.json || typeof extraction.json !== 'object') return null;
|
|
331
|
+
const decisions = (extraction.json as Record<string, unknown>).decisions;
|
|
332
|
+
if (!Array.isArray(decisions)) return null;
|
|
333
|
+
return {
|
|
334
|
+
decisions: decisions
|
|
335
|
+
.filter((entry): entry is Record<string, unknown> => Boolean(entry) && typeof entry === 'object')
|
|
336
|
+
.map((entry) => ({
|
|
337
|
+
id: String(entry.id ?? '').trim(),
|
|
338
|
+
project: typeof entry.project === 'string' && entry.project.trim() ? entry.project.trim() : null,
|
|
339
|
+
}))
|
|
340
|
+
.filter((decision) => decision.id !== ''),
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
|
|
324
344
|
/**
|
|
325
345
|
* A `CorpusExtractorLlm` backed by `@startsimpli/llm`.
|
|
326
346
|
*
|
|
@@ -437,6 +457,39 @@ export function createCorpusExtractor(options: CorpusLlmOptions = {}): CorpusExt
|
|
|
437
457
|
// not answer, and the caller must be able to tell the difference.
|
|
438
458
|
throw new Error('The verification pass did not return a usable result.');
|
|
439
459
|
},
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Where each NEW item belongs (bd startsim-v0mqh): ONE call over every item
|
|
463
|
+
* with echoed ids, one JSON-repair retry of the same request. Throws when the
|
|
464
|
+
* model did not answer, so an outage is never read as "nothing matched".
|
|
465
|
+
*/
|
|
466
|
+
async classify(input: ClassifyRequest): Promise<ClassifyDraft> {
|
|
467
|
+
if (!service.isAvailable()) {
|
|
468
|
+
throw new Error('No LLM provider is reachable. Configure ANTHROPIC_API_KEY for this tenant.');
|
|
469
|
+
}
|
|
470
|
+
const code = freshNonce();
|
|
471
|
+
const system = classifySystemPrompt();
|
|
472
|
+
const user = renderClassifyPrompt(input, (text, c) => untrustedDocument(text, c), code);
|
|
473
|
+
const first = await service.chat(user, system, call);
|
|
474
|
+
lastModel = first.model || lastModel;
|
|
475
|
+
const parsed = parseClassifyDraft(first.content);
|
|
476
|
+
if (parsed) return parsed;
|
|
477
|
+
const repair = await service.chat(
|
|
478
|
+
[
|
|
479
|
+
'Your previous response was not valid JSON in the required shape.',
|
|
480
|
+
'Return ONLY the JSON object {"decisions":[{"id":string,"project":string|null}]}.',
|
|
481
|
+
'',
|
|
482
|
+
'Your previous response was:',
|
|
483
|
+
first.content,
|
|
484
|
+
].join('\n'),
|
|
485
|
+
system,
|
|
486
|
+
call,
|
|
487
|
+
);
|
|
488
|
+
lastModel = repair.model || lastModel;
|
|
489
|
+
const repaired = parseClassifyDraft(repair.content);
|
|
490
|
+
if (repaired) return repaired;
|
|
491
|
+
throw new Error('The classification pass did not return a usable result.');
|
|
492
|
+
},
|
|
440
493
|
};
|
|
441
494
|
}
|
|
442
495
|
|
package/src/corpus/types.ts
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
* how a `SourceDocument` is stored. When bd startsim-768w.38.2 lands and the
|
|
25
25
|
* attribute names shift, `./entities.ts` is the one file that changes.
|
|
26
26
|
*/
|
|
27
|
+
import type { ItemSync } from '../task-tracker/item-sync';
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Which connector filled a record. FREE-FORM on purpose — `granola`, `dropbox`,
|
|
@@ -701,6 +702,18 @@ export interface Commitment {
|
|
|
701
702
|
* loading artefact.
|
|
702
703
|
*/
|
|
703
704
|
focusId?: string;
|
|
705
|
+
/**
|
|
706
|
+
* `personal` when classification found the item to be the owner's own errand
|
|
707
|
+
* rather than project work (bd startsim-v0mqh). The tracker connector reads it
|
|
708
|
+
* as "send to the personal container, or keep it Tandem-only until one is set".
|
|
709
|
+
* Mutually exclusive with `focusId`.
|
|
710
|
+
*/
|
|
711
|
+
destination?: 'personal';
|
|
712
|
+
/**
|
|
713
|
+
* The focus the push should file the tracker issue under (a copy of `focusId`
|
|
714
|
+
* at classification time, written to the row so the central push can read it).
|
|
715
|
+
*/
|
|
716
|
+
externalFocusId?: string;
|
|
704
717
|
/**
|
|
705
718
|
* Who owes it, as a MEMBER — the central user_id behind the subtree roster.
|
|
706
719
|
*
|
|
@@ -717,6 +730,8 @@ export interface Commitment {
|
|
|
717
730
|
* underscore is load-bearing and why this arrives from a browser as `Origin`.
|
|
718
731
|
*/
|
|
719
732
|
origin?: string;
|
|
733
|
+
/** Its link to a task tracker (identifier, state, sync health); absent when it has none. */
|
|
734
|
+
sync?: ItemSync;
|
|
720
735
|
mentions: CommitmentMention[];
|
|
721
736
|
firstSeenAt: string | null;
|
|
722
737
|
lastSeenAt: string | null;
|
|
@@ -907,9 +922,41 @@ export interface CorpusExtractorLlm {
|
|
|
907
922
|
* (feedback_batch_llm_calls) — never a call per item.
|
|
908
923
|
*/
|
|
909
924
|
verify?(input: VerificationRequest): Promise<VerificationDraft>;
|
|
925
|
+
/**
|
|
926
|
+
* File each NEW item under one of the real projects, or `personal`, or nothing
|
|
927
|
+
* (bd startsim-v0mqh). ONE batched call with echoed ids, like `verify`.
|
|
928
|
+
*
|
|
929
|
+
* OPTIONAL: an extractor without it leaves every new item unclassified, which
|
|
930
|
+
* is the honest state — never a guess from the note's section labels, which is
|
|
931
|
+
* the bug this replaced (startsim-8dttf). THROWS when the model did not answer,
|
|
932
|
+
* so "nothing matched" and "no check happened" stay different facts.
|
|
933
|
+
*/
|
|
934
|
+
classify?(input: ClassifyRequest): Promise<ClassifyDraft>;
|
|
910
935
|
describe(): LlmDescription;
|
|
911
936
|
}
|
|
912
937
|
|
|
938
|
+
/** A project an item can be filed under: a focus, as the classifier sees it. */
|
|
939
|
+
export interface ClassifyCandidate {
|
|
940
|
+
id: string;
|
|
941
|
+
title: string;
|
|
942
|
+
detail: string;
|
|
943
|
+
/** The focus row's stable external id, e.g. `focus:linear:<project id>`. */
|
|
944
|
+
externalKey: string;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
export interface ClassifyRequest {
|
|
948
|
+
/** NEW items only; `id` is echoed back on the decision. */
|
|
949
|
+
items: Array<{ id: string; title: string; detail: string; quote: string; documentId: string; owner?: string }>;
|
|
950
|
+
candidates: ClassifyCandidate[];
|
|
951
|
+
/** The notes the items came from, as UNTRUSTED context for the model. */
|
|
952
|
+
documents: Array<{ id: string; title: string; text: string }>;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
export interface ClassifyDraft {
|
|
956
|
+
/** `project` is a candidate id, `personal`, or null for "none fits". */
|
|
957
|
+
decisions: Array<{ id: string; project: string | null }>;
|
|
958
|
+
}
|
|
959
|
+
|
|
913
960
|
/**
|
|
914
961
|
* What the verifier is asked. The candidates AND the records they claim to come
|
|
915
962
|
* from, so the check is against the source rather than against the candidate's
|
|
@@ -1215,6 +1262,10 @@ export interface ExtractionResult {
|
|
|
1215
1262
|
* (bd startsim-768w.38.28).
|
|
1216
1263
|
*/
|
|
1217
1264
|
modelFailure: ExtractionModelFailure | null;
|
|
1265
|
+
/** New items the classifier placed (a project or personal). Absent when it did not run. */
|
|
1266
|
+
classified?: number;
|
|
1267
|
+
/** Why classification did not happen, when it was due and failed. */
|
|
1268
|
+
classifyFailure?: ExtractionModelFailure | null;
|
|
1218
1269
|
}
|
|
1219
1270
|
|
|
1220
1271
|
/**
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,8 @@ export * from './types/index';
|
|
|
12
12
|
export * from './api/index';
|
|
13
13
|
export * from './hooks/index';
|
|
14
14
|
export * from './components/index';
|
|
15
|
+
// Task-tracker sync (bd startsim-v95xs): what a to-do says about its tracker link, and `config.task_sync`.
|
|
16
|
+
export * from './task-tracker/index';
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* The corpus layer — the READ side of connections (bd startsim-768w.38.6 and
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/** startsim-04dfc: the phone shows the same task-tracker truth as the web: connect, settings, chips, badge states. */
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { act, allText, hostById, maybeById, press, render } from '../../../../ui-native/test/render';
|
|
4
|
+
import { createConnectionsController } from '../screens/connections/controller';
|
|
5
|
+
import { createFakeConnectionsApi } from '../screens/connections/fake';
|
|
6
|
+
import { ConnectionDetailScreen, ConnectionsListScreen } from '../screens/connections/ConnectionsScreens';
|
|
7
|
+
import { createSettingsController } from '../../task-tracker/settings-controller';
|
|
8
|
+
import { TrackerSettingsScreen } from '../task-tracker/TrackerSettingsScreen';
|
|
9
|
+
import { SyncChips } from '../task-tracker/SyncChips';
|
|
10
|
+
import { openTrackerLink } from '../../task-tracker/links';
|
|
11
|
+
import { TrackerListScreen } from '../tracker/TrackerListScreen';
|
|
12
|
+
import { createTrackerController } from '../tracker/controller';
|
|
13
|
+
import { createFakeNativeCorpusApi } from '../corpus/fake';
|
|
14
|
+
import type { Connection } from '../../components/pages/types';
|
|
15
|
+
|
|
16
|
+
const tick = () => new Promise((r) => setTimeout(r, 0));
|
|
17
|
+
const settle = () => act(async () => { await tick(); await tick(); });
|
|
18
|
+
async function until(check: () => boolean) { for (let i = 0; i < 50 && !check(); i += 1) await tick(); }
|
|
19
|
+
const entry = (api: ReturnType<typeof createFakeConnectionsApi>) => api.connectorCatalog().then((c) => c.results.find((e) => e.key === 'linear')!);
|
|
20
|
+
|
|
21
|
+
describe('connect a tracker from the Connections list', () => {
|
|
22
|
+
it('shows a Connect row from the catalog and opens the server consent url untouched', async () => {
|
|
23
|
+
const api = createFakeConnectionsApi();
|
|
24
|
+
const openUrl = vi.fn().mockResolvedValue(undefined);
|
|
25
|
+
const c = createConnectionsController({ api, openUrl, returnTo: 'tandemgo://connections' });
|
|
26
|
+
await until(() => !c.getState().loading);
|
|
27
|
+
const r = render(<ConnectionsListScreen controller={c} onOpen={vi.fn()} />);
|
|
28
|
+
await settle();
|
|
29
|
+
expect(allText(r)).toContain('Connect Linear');
|
|
30
|
+
await act(async () => { press(hostById(r, 'connect-linear')); await tick(); });
|
|
31
|
+
expect(api.calls.started).toEqual(['linear']);
|
|
32
|
+
expect(openUrl).toHaveBeenCalledWith('https://consent.example/linear/authorize?state=fake');
|
|
33
|
+
expect(c.getState().awaitingConsent).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('no opener, no Connect row: the pointer to the web stays', async () => {
|
|
37
|
+
const c = createConnectionsController({ api: createFakeConnectionsApi() });
|
|
38
|
+
await until(() => !c.getState().loading);
|
|
39
|
+
const r = render(<ConnectionsListScreen controller={c} onOpen={vi.fn()} />);
|
|
40
|
+
await settle();
|
|
41
|
+
expect(maybeById(r, 'connect-linear')).toHaveLength(0);
|
|
42
|
+
expect(allText(r)).toContain('Add new accounts on the web');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('coming back from the browser reads the connections and shows it connected', async () => {
|
|
46
|
+
const api = createFakeConnectionsApi();
|
|
47
|
+
const c = createConnectionsController({ api, openUrl: vi.fn().mockResolvedValue(undefined) });
|
|
48
|
+
await until(() => !c.getState().loading);
|
|
49
|
+
await c.connect(await entry(api));
|
|
50
|
+
expect(c.getState().rows.some((r) => r.connector_key === 'linear')).toBe(false);
|
|
51
|
+
api.completeConsent(); // the vendor redirected back to the web page
|
|
52
|
+
await c.returned(); // the app came to the foreground
|
|
53
|
+
expect(c.getState().rows.find((r) => r.connector_key === 'linear')).toMatchObject({ status: 'connected' });
|
|
54
|
+
expect(c.getState().awaitingConsent).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('a sign-in that finishes inside the app is read at once', async () => {
|
|
58
|
+
const api = createFakeConnectionsApi();
|
|
59
|
+
const c = createConnectionsController({ api, openUrl: async () => { api.completeConsent(); return { completed: true }; } });
|
|
60
|
+
await until(() => !c.getState().loading);
|
|
61
|
+
await c.connect(await entry(api));
|
|
62
|
+
expect(c.getState().rows.some((r) => r.connector_key === 'linear')).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('returned() does nothing when no sign-in was started (no needless reads)', async () => {
|
|
66
|
+
const api = createFakeConnectionsApi();
|
|
67
|
+
const c = createConnectionsController({ api, openUrl: vi.fn() });
|
|
68
|
+
await until(() => !c.getState().loading);
|
|
69
|
+
await c.returned();
|
|
70
|
+
expect(api.calls.connections).toBe(1);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('a refused start shows the reason and opens nothing', async () => {
|
|
74
|
+
const api = createFakeConnectionsApi();
|
|
75
|
+
api.startOAuth = vi.fn().mockRejectedValue(new Error('This connector is not open to members.'));
|
|
76
|
+
const openUrl = vi.fn();
|
|
77
|
+
const c = createConnectionsController({ api, openUrl });
|
|
78
|
+
await until(() => !c.getState().loading);
|
|
79
|
+
await c.connect(await entry(api));
|
|
80
|
+
expect(openUrl).not.toHaveBeenCalled();
|
|
81
|
+
expect(c.getState().actionError).toBe('This connector is not open to members.');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
async function connectedLinear() {
|
|
86
|
+
const api = createFakeConnectionsApi();
|
|
87
|
+
const openUrl = async () => { api.completeConsent(); return { completed: true }; };
|
|
88
|
+
const c = createConnectionsController({ api, openUrl });
|
|
89
|
+
await until(() => !c.getState().loading);
|
|
90
|
+
await c.connect(await entry(api));
|
|
91
|
+
const conn = c.getState().rows.find((r) => r.connector_key === 'linear') as Connection;
|
|
92
|
+
return { api, c, conn };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
describe('sync settings on the phone', () => {
|
|
96
|
+
it('loads team, project, state and user choices; saving sends the whole task_sync block', async () => {
|
|
97
|
+
const { api, conn } = await connectedLinear();
|
|
98
|
+
await api.updateConnectionConfig!(conn.id, { task_sync: { default_container_id: 'team-eng', project_focus: { p: 'f' } } });
|
|
99
|
+
const stored = (await api.connections()).results.find((r) => r.id === conn.id)!;
|
|
100
|
+
const s = createSettingsController({ api, connection: stored });
|
|
101
|
+
await s.load();
|
|
102
|
+
expect(Object.keys(s.getState().choices)).toEqual(['team', 'project', 'state', 'user']);
|
|
103
|
+
s.set({ default_project_id: 'proj-tandem', personal_container_id: 'team-per' });
|
|
104
|
+
await s.save();
|
|
105
|
+
expect(api.calls.saved.at(-1)).toEqual({ task_sync: {
|
|
106
|
+
default_container_id: 'team-eng', project_focus: { p: 'f' }, default_project_id: 'proj-tandem', personal_container_id: 'team-per',
|
|
107
|
+
} });
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('shows the state mapping with defaults and an override', async () => {
|
|
111
|
+
const { api, conn } = await connectedLinear();
|
|
112
|
+
const s = createSettingsController({ api, connection: conn });
|
|
113
|
+
await s.load();
|
|
114
|
+
s.setStatus('st-prog', 'blocked');
|
|
115
|
+
expect(s.getState().rows.map((r) => [r.name, r.status, r.overridden])).toEqual([
|
|
116
|
+
['Todo', 'open', false], ['In Progress', 'blocked', true], ['Done', 'done', false],
|
|
117
|
+
]);
|
|
118
|
+
s.setStatus('st-prog', 'in_progress');
|
|
119
|
+
expect(s.getState().rows[1].overridden).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('renders the screen, saves, and Sync now calls the narrow route', async () => {
|
|
123
|
+
const { api, conn } = await connectedLinear();
|
|
124
|
+
const s = createSettingsController({ api, connection: conn });
|
|
125
|
+
const r = render(<TrackerSettingsScreen controller={s} connection={conn} onBack={vi.fn()} />);
|
|
126
|
+
await settle();
|
|
127
|
+
expect(allText(r)).toContain('Where new to-dos go');
|
|
128
|
+
expect(allText(r)).toContain('In Progress');
|
|
129
|
+
await act(async () => { s.set({ default_container_id: 'team-eng' }); });
|
|
130
|
+
await act(async () => { press(hostById(r, 'settings-save')); await tick(); });
|
|
131
|
+
expect(api.calls.saved.at(-1)).toEqual({ task_sync: { default_container_id: 'team-eng' } });
|
|
132
|
+
await act(async () => { press(hostById(r, 'settings-sync-now')); await tick(); });
|
|
133
|
+
expect(api.calls.sync).toEqual([conn.id]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('the connection screen offers Sync settings and Sync now only for a task tracker, and says nothing is deleted', async () => {
|
|
137
|
+
const { c, conn } = await connectedLinear();
|
|
138
|
+
const open = vi.fn();
|
|
139
|
+
const r = render(<ConnectionDetailScreen controller={c} id={conn.id} onBack={vi.fn()} onOpenSettings={open} />);
|
|
140
|
+
await settle();
|
|
141
|
+
await act(async () => { press(hostById(r, 'connection-sync-settings')); });
|
|
142
|
+
expect(open).toHaveBeenCalledWith(expect.objectContaining({ id: conn.id }));
|
|
143
|
+
await act(async () => { press(hostById(r, 'connection-sync-now')); await tick(); });
|
|
144
|
+
expect(c.getState().syncNote).toMatch(/Syncing with Linear now/);
|
|
145
|
+
await act(async () => { press(hostById(r, 'connection-disconnect')); });
|
|
146
|
+
expect(allText(r)).toContain('Your to-dos stay in Tandem. Nothing is deleted in Linear');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('a calendar connection has neither', async () => {
|
|
150
|
+
const api = createFakeConnectionsApi();
|
|
151
|
+
const c = createConnectionsController({ api });
|
|
152
|
+
await until(() => !c.getState().loading);
|
|
153
|
+
const r = render(<ConnectionDetailScreen controller={c} id="cn1" onBack={vi.fn()} onOpenSettings={vi.fn()} />);
|
|
154
|
+
await settle();
|
|
155
|
+
expect(maybeById(r, 'connection-sync-settings')).toHaveLength(0);
|
|
156
|
+
expect(maybeById(r, 'connection-sync-now')).toHaveLength(0);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe('to-do chips', () => {
|
|
161
|
+
const sync = { state: 'synced' as const, key: 'ENG-12', url: 'https://linear.app/eng/issue/ENG-12/x', stateName: 'In Progress' };
|
|
162
|
+
|
|
163
|
+
it('shows the identifier and state, and tapping the identifier opens the url', () => {
|
|
164
|
+
const open = vi.fn();
|
|
165
|
+
const r = render(<SyncChips sync={sync} trackerName="Linear" onOpen={open} />);
|
|
166
|
+
expect(allText(r)).toContain('ENG-12');
|
|
167
|
+
expect(allText(r)).toContain('In Progress');
|
|
168
|
+
press(hostById(r, 'sync-chips-open'));
|
|
169
|
+
expect(open).toHaveBeenCalledWith(sync.url);
|
|
170
|
+
expect(hostById(r, 'sync-chips-open').props.accessibilityLabel).toBe('Open in Linear: ENG-12');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('the app link is tried first and https is the fallback', async () => {
|
|
174
|
+
const openURL = vi.fn().mockRejectedValueOnce(new Error('no app')).mockResolvedValue(true);
|
|
175
|
+
await openTrackerLink(sync.url, openURL);
|
|
176
|
+
expect(openURL.mock.calls.map((c) => c[0])).toEqual(['linear://eng/issue/ENG-12/x', sync.url]);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it.each([
|
|
180
|
+
['synced', undefined, 'Synced', 'Synced with Linear'],
|
|
181
|
+
['pending', undefined, 'Syncing', 'Waiting to sync with Linear'],
|
|
182
|
+
['error', 'rate limited', 'Out of sync', 'Out of sync with Linear: rate limited'],
|
|
183
|
+
['conflict', undefined, 'Out of sync', 'Sync conflict with Linear'],
|
|
184
|
+
] as const)('badge %s has text and a spoken label', (state, error, text, a11y) => {
|
|
185
|
+
const r = render(<SyncChips sync={{ state, key: 'ENG-1', ...(error ? { error } : {}) }} trackerName="Linear" />);
|
|
186
|
+
const badge = hostById(r, 'sync-chips-badge');
|
|
187
|
+
expect(allText(r)).toContain(text);
|
|
188
|
+
expect(badge.props.accessibilityLabel).toBe(a11y);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('nothing renders for a to-do with no tracker', () => {
|
|
192
|
+
const r = render(<SyncChips sync={undefined} />);
|
|
193
|
+
expect(maybeById(r, 'sync-chips')).toHaveLength(0);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('the to-do list shows the chips on linked rows only', async () => {
|
|
197
|
+
const controller = createTrackerController({ api: createFakeNativeCorpusApi() });
|
|
198
|
+
const r = render(<TrackerListScreen controller={controller} onOpen={vi.fn()} trackerName="Linear" onOpenLink={vi.fn()} />);
|
|
199
|
+
await act(async () => { await controller.start(); });
|
|
200
|
+
await settle();
|
|
201
|
+
expect(allText(r)).toContain('ENG-12');
|
|
202
|
+
expect(allText(r)).toContain('Out of sync');
|
|
203
|
+
expect(allText(r)).toContain('Tandem only');
|
|
204
|
+
expect(maybeById(r, 'todo-sync-c3')).toHaveLength(0); // an unlinked to-do carries no chip
|
|
205
|
+
});
|
|
206
|
+
});
|
|
@@ -131,7 +131,7 @@ function Root({ config, device, registry }: { config: FoundryAppConfig; device:
|
|
|
131
131
|
const recordRef = useRef<ReactNode>(record);
|
|
132
132
|
recordRef.current = record;
|
|
133
133
|
const tabs = useMemo(
|
|
134
|
-
() => buildFoundryTabs({ config: appConfig, corpus: data.corpus, notes: data.notes, record: () => recordRef.current, member: data.member }, registry),
|
|
134
|
+
() => buildFoundryTabs({ config: appConfig, corpus: data.corpus, notes: data.notes, record: () => recordRef.current, member: data.member, openUrl: data.openUrl ?? ((url) => Linking.openURL(url)) }, registry),
|
|
135
135
|
[appConfig, data, registry],
|
|
136
136
|
);
|
|
137
137
|
|
package/src/native/app/data.ts
CHANGED
|
@@ -18,6 +18,8 @@ export interface FoundryData {
|
|
|
18
18
|
corpus: NativeCorpusApi;
|
|
19
19
|
notes: VoiceNotesController | null;
|
|
20
20
|
member: { connections: MemberConnectionsApi; mcpTokens: McpTokensApi };
|
|
21
|
+
/** Replaces the app's URL opener (fakes: a sign-in page that "finishes" in place, since a simulator has no account to sign in with). */
|
|
22
|
+
openUrl?: (url: string) => Promise<unknown>;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
/**
|
|
@@ -28,11 +30,13 @@ export function createFoundryData(deps: { config: FoundryAppConfig; authorizedFe
|
|
|
28
30
|
const { config, authorizedFetch, fake, scenario } = deps;
|
|
29
31
|
const wantsNotes = config.tabs.some((t) => t.screen === 'notes');
|
|
30
32
|
if (fake) {
|
|
33
|
+
const fakeConnections = createFakeConnectionsApi({ connections: scenario === 'empty' ? [] : undefined });
|
|
31
34
|
return {
|
|
35
|
+
openUrl: async () => { fakeConnections.completeConsent(); return { completed: true }; },
|
|
32
36
|
corpus: createFakeNativeCorpusApi({ scenario, extraEntities: fakeEntityRows(config) }),
|
|
33
37
|
notes: wantsNotes ? createVoiceNotesController({ api: createFakeVoiceApi({ scenario }) }) : null,
|
|
34
38
|
member: {
|
|
35
|
-
connections: withScenario(
|
|
39
|
+
connections: withScenario(fakeConnections, scenario),
|
|
36
40
|
mcpTokens: withScenario(createFakeMcpTokensApi(), scenario),
|
|
37
41
|
},
|
|
38
42
|
};
|
|
@@ -28,6 +28,8 @@ export interface ScreenDeps {
|
|
|
28
28
|
record: () => ReactNode;
|
|
29
29
|
/** Member-level APIs for Connections and Connect Claude. */
|
|
30
30
|
member: { connections: MemberConnectionsApi; mcpTokens: McpTokensApi };
|
|
31
|
+
/** Opens a URL outside the app (`Linking.openURL`): a vendor's sign-in page, a tracker item. Absent in tests. */
|
|
32
|
+
openUrl?: (url: string) => Promise<unknown>;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
/** Builds one shell tab from its config entry. */
|
|
@@ -59,11 +61,11 @@ export const BUILTIN_FACTORIES: Record<string, ScreenFactory> = {
|
|
|
59
61
|
: <NotesListScreen controller={notes} displays={corpus.schema?.displays} onOpen={(n) => push(n.id)} />),
|
|
60
62
|
};
|
|
61
63
|
},
|
|
62
|
-
tracker: ({ config, corpus }, tab) => trackerTab({ api: corpus, key: tab.key, label: tabLabel(tab), notesKey: firstKey(config, 'notes') }),
|
|
64
|
+
tracker: ({ config, corpus, member, openUrl }, tab) => trackerTab({ api: corpus, key: tab.key, label: tabLabel(tab), notesKey: firstKey(config, 'notes'), memberConnections: member.connections, openUrl }),
|
|
63
65
|
library: ({ corpus }, tab) => libraryTab(corpus, { key: tab.key, label: tabLabel(tab) }),
|
|
64
66
|
ask: ({ corpus }, tab) => askTab(corpus, { key: tab.key, label: tabLabel(tab) }),
|
|
65
67
|
planning: ({ config, corpus }, tab) => createPlanningTab({ api: corpus, key: tab.key, label: tabLabel(tab), documentTab: firstKey(config, 'library') }),
|
|
66
|
-
connections: ({ member }, tab) => createConnectionsTab({ api: member.connections, key: tab.key, label: tabLabel(tab) }),
|
|
68
|
+
connections: ({ config, member, openUrl }, tab) => createConnectionsTab({ api: member.connections, key: tab.key, label: tabLabel(tab), openUrl, returnTo: `${config.app.scheme}://${tab.key}` }),
|
|
67
69
|
'connect-claude': ({ member }, tab) => createConnectClaudeTab({ api: member.mcpTokens, key: tab.key, label: tab.label ?? `Claude` }),
|
|
68
70
|
entity: ({ config, corpus }, tab) => {
|
|
69
71
|
const type = String(tab.options?.entityType);
|
|
@@ -24,10 +24,10 @@ export function sampleTenantEntities(): TenantEntity[] {
|
|
|
24
24
|
row('fma', 'focus', 'focus:marketing-agents', 'Marketing agents', '2026-09-02T00:00:00Z', { title: 'Marketing agents', status: 'on_track', category: 'product', progress: 0.7, sort_order: 2 }),
|
|
25
25
|
row('fdbg', 'focus', 'focus:debug', 'Debug', '2026-09-03T00:00:00Z', { title: 'Debug', status: 'at_risk', category: 'team', progress: 0.2, sort_order: 3 }),
|
|
26
26
|
|
|
27
|
-
commitment('c1', 'Finish exhibit list', '2026-11-03T14:40:00Z', { status: 'open', owner_name: 'Quinn', due_at: '2026-11-05T17:00:00Z', priority: 1, detail: 'Needed before the hearing.', mentions: [mention('n1', '2026-11-03T14:38:00Z', 'I still have to finish the exhibit list before the hearing.', 'Hearing prep')] }),
|
|
28
|
-
commitment('c2', 'Call Megan about the filing receipt', '2026-11-03T14:41:00Z', { status: 'open', owner_name: 'Quinn', due_at: '2026-11-04T17:00:00Z', priority: 2 }),
|
|
27
|
+
commitment('c1', 'Finish exhibit list', '2026-11-03T14:40:00Z', { status: 'open', owner_name: 'Quinn', due_at: '2026-11-05T17:00:00Z', priority: 1, detail: 'Needed before the hearing.', external_id: 'iss-12', external_key: 'ENG-12', external_url: 'https://linear.app/eng/issue/ENG-12/finish-exhibit-list', state_name: 'In Progress', sync_state: 'synced', mentions: [mention('n1', '2026-11-03T14:38:00Z', 'I still have to finish the exhibit list before the hearing.', 'Hearing prep')] }),
|
|
28
|
+
commitment('c2', 'Call Megan about the filing receipt', '2026-11-03T14:41:00Z', { status: 'open', owner_name: 'Quinn', due_at: '2026-11-04T17:00:00Z', priority: 2, external_id: 'iss-14', external_key: 'ENG-14', external_url: 'https://linear.app/eng/issue/ENG-14/call-megan', state_name: 'Todo', sync_state: 'error', sync_error: 'Linear is rate limiting us. Retrying.' }),
|
|
29
29
|
commitment('c3', 'Move weekly report to Monday', '2026-11-03T14:42:00Z', { status: 'open', owner_name: 'Quinn', source: 'granola', source_label: 'Granola', mentions: [mention('d2', '2026-11-02T15:00:00Z', 'Let us move the weekly report to Mondays.')] }),
|
|
30
|
-
commitment('c4', 'Book the dentist', '2026-11-03T14:43:00Z', { status: 'open', owner_name: 'Quinn', due_at: '2026-11-06T09:00:00Z' }),
|
|
30
|
+
commitment('c4', 'Book the dentist', '2026-11-03T14:43:00Z', { status: 'open', owner_name: 'Quinn', due_at: '2026-11-06T09:00:00Z', sync_state: 'unsynced' }),
|
|
31
31
|
commitment('c5', 'Send the revised proposal', '2026-10-28T10:00:00Z', { status: 'done', owner_name: 'Rae', resolved_at: '2026-10-30T10:00:00Z' }),
|
|
32
32
|
commitment('c6', 'Waiting on court clerk reply', '2026-10-29T10:00:00Z', { status: 'blocked', owner_name: 'Quinn', status_reason: 'Clerk has not answered' }),
|
|
33
33
|
|
|
@@ -277,6 +277,9 @@ export function createFakeTenantHttp(options: FakeTenantOptions = {}): FakeTenan
|
|
|
277
277
|
reads.set(key, seen);
|
|
278
278
|
const first = page.results[0];
|
|
279
279
|
if (seen < 2 || !first) return page;
|
|
280
|
+
// A change made in the tracker since the first read: linked rows come back in their next state.
|
|
281
|
+
const moved = page.results.map((r) => (dataOf(r).external_key ? { ...r, data: { ...dataOf(r), state_name: 'In Review' } } : r));
|
|
282
|
+
page = { ...page, results: moved };
|
|
280
283
|
const added = { ...first, id: `${first.id}-fresh`, name: REFRESH_ROW_TITLE, data: { ...dataOf(first), title: REFRESH_ROW_TITLE } };
|
|
281
284
|
return { ...page, count: page.count + 1, results: [added, ...page.results] };
|
|
282
285
|
}
|