@startsimpli/integrations 0.2.145 → 0.2.146

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/package.json +4 -4
  2. package/src/__tests__/briefing-actions.test.ts +2 -0
  3. package/src/__tests__/briefing-reply.test.ts +334 -0
  4. package/src/__tests__/corpus-tracker.test.tsx +79 -0
  5. package/src/__tests__/owner-backfill.test.ts +114 -0
  6. package/src/__tests__/owner-link.test.ts +115 -0
  7. package/src/__tests__/owner-picker.test.tsx +70 -0
  8. package/src/__tests__/roster.test.ts +27 -0
  9. package/src/__tests__/tracker-sort.test.ts +28 -0
  10. package/src/components/index.ts +1 -0
  11. package/src/components/pages/TaskDetailPage.tsx +33 -2
  12. package/src/components/pages/TrackerPage.tsx +28 -6
  13. package/src/components/pages/task-tracker/OwnerPicker.tsx +82 -0
  14. package/src/components/pages/tracker/TrackerBoard.tsx +45 -0
  15. package/src/components/pages/tracker/TrackerToolbar.tsx +44 -0
  16. package/src/corpus/briefing/actions/execute.ts +5 -4
  17. package/src/corpus/briefing/actions/log.ts +1 -1
  18. package/src/corpus/briefing/actions/types.ts +21 -0
  19. package/src/corpus/briefing/index.ts +1 -0
  20. package/src/corpus/briefing/intent/model.ts +3 -0
  21. package/src/corpus/briefing/intent/resolve.ts +14 -6
  22. package/src/corpus/briefing/intent/types.ts +7 -0
  23. package/src/corpus/briefing/reply/handle.ts +174 -0
  24. package/src/corpus/briefing/reply/index.ts +6 -0
  25. package/src/corpus/briefing/reply/respond.ts +95 -0
  26. package/src/corpus/briefing/reply/types.ts +112 -0
  27. package/src/corpus/briefing/store.ts +14 -0
  28. package/src/corpus/client.ts +16 -18
  29. package/src/corpus/entities.ts +4 -0
  30. package/src/corpus/index.ts +4 -0
  31. package/src/corpus/owner-backfill.ts +200 -0
  32. package/src/corpus/owner-link.ts +160 -0
  33. package/src/corpus/roster.ts +53 -0
  34. package/src/corpus/tracker-groups.ts +8 -4
  35. package/src/corpus/tracker-sort.ts +51 -0
  36. package/src/corpus/types.ts +13 -1
  37. package/src/native/app/FoundryApp.tsx +25 -7
  38. package/src/native/app/__tests__/briefingLink.test.tsx +57 -0
  39. package/src/native/app/__tests__/briefingServices.test.ts +92 -0
  40. package/src/native/app/__tests__/launch.test.ts +2 -1
  41. package/src/native/app/briefingServices.ts +101 -0
  42. package/src/native/app/config/__tests__/briefingConfig.test.ts +49 -0
  43. package/src/native/app/config/links.ts +4 -1
  44. package/src/native/app/config/types.ts +13 -1
  45. package/src/native/app/config/validate.ts +20 -2
  46. package/src/native/app/data.ts +3 -3
  47. package/src/native/app/device.ts +3 -0
  48. package/src/native/app/launch.ts +4 -0
  49. package/src/native/app/registry.tsx +3 -1
  50. package/src/native/app/screens/RecordScreen.tsx +3 -2
  51. package/src/native/app/services.ts +11 -30
  52. package/src/native/app/strings.ts +28 -0
  53. package/src/native/briefing/BriefingCard.tsx +14 -2
  54. package/src/native/briefing/BriefingReply.tsx +68 -0
  55. package/src/native/briefing/__tests__/BriefingReply.test.tsx +144 -0
  56. package/src/native/briefing/__tests__/fakeReply.test.ts +46 -0
  57. package/src/native/briefing/__tests__/notify.test.ts +42 -1
  58. package/src/native/briefing/__tests__/replyApi.test.ts +43 -0
  59. package/src/native/briefing/__tests__/replyController.test.ts +230 -0
  60. package/src/native/briefing/__tests__/replyPosition.test.ts +116 -0
  61. package/src/native/briefing/audioPlayer.ts +9 -2
  62. package/src/native/briefing/controller.ts +50 -5
  63. package/src/native/briefing/fake.ts +25 -18
  64. package/src/native/briefing/fakeReply.ts +65 -0
  65. package/src/native/briefing/index.ts +8 -3
  66. package/src/native/briefing/notify.ts +42 -0
  67. package/src/native/briefing/reply.ts +261 -0
  68. package/src/native/briefing/replyApi.ts +82 -0
  69. package/src/native/recording/__tests__/deeplink.test.ts +20 -0
  70. package/src/native/recording/deeplink.ts +7 -0
  71. package/src/native/tracker/__tests__/itemsChanged.test.ts +13 -0
  72. package/src/native/tracker/tab.tsx +4 -1
@@ -0,0 +1,57 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+
3
+ const launchArgs: Record<string, string> = {};
4
+ const links: { handler: ((e: { url: string }) => void) | null } = { handler: null };
5
+ vi.mock('react-native', async () => {
6
+ const stub = await import('../../../../../ui-native/test/rn-stub');
7
+ return {
8
+ ...stub,
9
+ Settings: { get: (k: string) => launchArgs[k] },
10
+ StatusBar: 'StatusBar',
11
+ AppState: { currentState: 'active', addEventListener: () => ({ remove() {} }) },
12
+ Linking: { openURL: async () => {}, getInitialURL: async () => null, addEventListener: (_e: string, h: (e: { url: string }) => void) => { links.handler = h; return { remove() { links.handler = null; } }; } },
13
+ };
14
+ });
15
+
16
+ import { act, hostById, maybeById, render } from '../../../../../ui-native/test/render';
17
+ import { FoundryApp } from '../FoundryApp';
18
+ import type { FoundryDevice } from '../device';
19
+
20
+ const tick = () => act(async () => { await new Promise((res) => setTimeout(res, 40)); });
21
+ const files = new Map<string, string>();
22
+ const session = { info: async () => ({ category: 'playback', mode: 'default', options: [], sampleRate: 48000, inputs: [] }), onInterruption: () => () => undefined, onRouteChange: () => () => undefined };
23
+ let played = 0;
24
+ const device = (): FoundryDevice => ({
25
+ tokenStorage: { getRefreshToken: async () => null, setRefreshToken: async () => {}, clear: async () => {} },
26
+ files: { exists: async (p) => files.has(p), read: async (p) => files.get(p) ?? '', write: async (p, v) => { files.set(p, v); } },
27
+ documentUri: (n) => `file:///docs/${n}`,
28
+ recording: {
29
+ driver: {} as never, session, background: { begin: async () => 0, end: async () => undefined } as never,
30
+ permissions: { get: async () => ({ status: 'granted', granted: true, canAskAgain: true }), request: async () => ({ status: 'granted', granted: true, canAskAgain: true }) },
31
+ openSettings: async () => undefined, fileSize: async () => 1, removeFile: async () => undefined, listRecordings: async () => [], filePart: () => ({}) as Blob,
32
+ },
33
+ briefing: {
34
+ driver: {
35
+ configureSession: async () => undefined, load: () => undefined, play: () => { played += 1; }, pause: () => undefined, release: async () => undefined,
36
+ status: () => ({ playing: true, loaded: true, positionMillis: 1, durationMillis: 1000, ended: false }),
37
+ },
38
+ fixture: { uri: 'fixture://briefing' },
39
+ },
40
+ });
41
+ const config = { app: { name: 'Acme Go', scheme: 'acmego' }, tenant: { url: 'https://acme.example.com' }, features: { briefing: true, notes: false, ask: false, planning: false, connectClaude: false }, tabs: [{ screen: 'record' }, { screen: 'tracker' }] };
42
+
43
+ describe('the briefing link over the fakes', () => {
44
+ it('test_scheme_briefing_lands_on_go_and_plays_the_briefing_without_tapping', async () => {
45
+ launchArgs.tgFakeTabs = '1';
46
+ launchArgs.tgFakeBriefing = '1';
47
+ launchArgs.tgTab = 'tracker';
48
+ const r = render(<FoundryApp config={config} device={device()} />);
49
+ await tick();
50
+ expect(maybeById(r, 'briefing-stop')).toHaveLength(0);
51
+ await act(async () => { links.handler?.({ url: 'acmego://briefing' }); await new Promise((res) => setTimeout(res, 800)); });
52
+ expect(played).toBeGreaterThan(0);
53
+ expect(hostById(r, 'briefing-stop')).toBeTruthy();
54
+ expect(hostById(r, 'briefing-talk')).toBeTruthy();
55
+ delete launchArgs.tgTab;
56
+ });
57
+ });
@@ -0,0 +1,92 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+
3
+ vi.mock('react-native', async () => ({
4
+ ...(await import('../../../../../ui-native/test/rn-stub')),
5
+ AppState: { currentState: 'active', addEventListener: () => ({ remove() {} }) },
6
+ }));
7
+ import { createFoundryServices } from '../services';
8
+ import { createBanners } from '../banners';
9
+ import { foundryStrings } from '../strings';
10
+ import { resolveFoundryApp } from '../config/validate';
11
+ import { createFakeNativeCorpusApi } from '../../corpus/fake';
12
+ import { fakeBriefingRows } from '../../briefing/fakeReply';
13
+
14
+ const session = { info: async () => ({ category: 'playback', mode: 'default', options: [], sampleRate: 48000, inputs: [] }), onInterruption: () => () => undefined, onRouteChange: () => () => undefined };
15
+ const files = new Map<string, string>();
16
+ const device = (extra: object = {}) => ({
17
+ tokenStorage: { getRefreshToken: async () => null, setRefreshToken: async () => undefined, clear: async () => undefined },
18
+ files: { exists: async (p: string) => files.has(p), read: async (p: string) => files.get(p) ?? '', write: async (p: string, v: string) => { files.set(p, v); } },
19
+ documentUri: (n: string) => `file:///${n}`,
20
+ recording: {
21
+ driver: {}, session, background: { begin: async () => 0, end: async () => undefined }, permissions: { get: async () => ({ status: 'granted', granted: true, canAskAgain: true }), request: async () => ({ status: 'granted', granted: true, canAskAgain: true }) },
22
+ openSettings: async () => undefined, fileSize: async () => 1, removeFile: async () => undefined, listRecordings: async () => [], filePart: () => ({}) as Blob,
23
+ },
24
+ briefing: { driver: { configureSession: async () => undefined, load: () => undefined, play: () => undefined, pause: () => undefined, release: async () => undefined, status: () => ({ playing: true, loaded: true, positionMillis: 1, durationMillis: 1000, ended: false }) }, fixture: { uri: 'fixture://briefing' } },
25
+ ...extra,
26
+ }) as never;
27
+
28
+ const make = (features: object, dev = device(), fake = false) => {
29
+ const config = resolveFoundryApp({ app: { name: 'Acme Go', scheme: 'acmego' }, tenant: { url: 'https://acme.example.com' }, features: { ...features } });
30
+ const services = createFoundryServices({
31
+ config, device: dev, banners: createBanners(), strings: foundryStrings(config),
32
+ ...(fake ? { fakeBriefing: { corpus: createFakeNativeCorpusApi({ extraEntities: fakeBriefingRows() }), script: ['move this one to later'] } } : {}),
33
+ });
34
+ return { services, config };
35
+ };
36
+
37
+ describe('briefing services', () => {
38
+ it('test_reply_is_wired_by_default_when_the_briefing_is_on', () => {
39
+ const { services } = make({ briefing: true });
40
+ expect(services.briefing?.reply).toBeTruthy();
41
+ });
42
+
43
+ it('test_the_reply_can_be_switched_off_in_config', () => {
44
+ expect(make({ briefing: { reply: false } }).services.briefing?.reply).toBeNull();
45
+ });
46
+
47
+ it('test_a_reply_without_recording_bindings_is_a_clear_error_not_a_dead_button', () => {
48
+ const base = device() as any;
49
+ const noRec = { ...base, recording: undefined, briefing: { ...base.briefing, session } } as never;
50
+ expect(() => make({ briefing: true, recording: false }, noRec)).toThrow(/features\.briefing\.reply needs the recording bindings/);
51
+ });
52
+
53
+ it('test_the_briefing_link_opens_go_and_starts_the_briefing_once_signed_in', async () => {
54
+ const { services } = make({ briefing: true }, device(), true);
55
+ const open = vi.fn();
56
+ services.bindOpen(open);
57
+ const start = vi.spyOn(services.briefing!.controller, 'start').mockResolvedValue(undefined);
58
+ services.deepLink.handle('acmego://briefing');
59
+ expect(start).not.toHaveBeenCalled();
60
+ await services.deepLink.sessionReady();
61
+ expect(open).toHaveBeenCalledWith('go');
62
+ expect(start).toHaveBeenCalledTimes(1);
63
+ });
64
+
65
+ it('test_the_fake_briefing_schedules_a_notification_through_the_diagnostics_notifier', async () => {
66
+ const { services } = make({ briefing: true }, device(), true);
67
+ await services.briefing!.syncNotification();
68
+ const text = JSON.stringify(services.diag.entries());
69
+ expect(text).toContain('notification.scheduled');
70
+ expect(text).toContain('acmego://briefing');
71
+ });
72
+
73
+ it('test_the_fakes_never_reach_the_device_notifier_and_notification_can_be_turned_off', async () => {
74
+ const notifier = { schedule: vi.fn(async () => 'n1'), cancel: vi.fn(async () => undefined) };
75
+ const dev = device(); (dev as any).briefing.notifier = notifier;
76
+ const on = make({ briefing: true }, dev, true);
77
+ await on.services.briefing!.syncNotification();
78
+ expect(notifier.schedule).not.toHaveBeenCalled();
79
+ expect(JSON.stringify(on.services.diag.entries())).toContain('notification.scheduled');
80
+ const off = make({ briefing: { notification: false } }, device(), true);
81
+ await off.services.briefing!.syncNotification();
82
+ expect(JSON.stringify(off.services.diag.entries())).not.toContain('notification.scheduled');
83
+ });
84
+
85
+ it('test_a_real_sync_with_no_session_changes_nothing_and_never_throws', async () => {
86
+ const notifier = { schedule: vi.fn(async () => 'n1'), cancel: vi.fn(async () => undefined) };
87
+ const dev = device(); (dev as any).briefing.notifier = notifier;
88
+ const { services } = make({ briefing: true }, dev, false);
89
+ await expect(services.briefing!.syncNotification()).resolves.toBeUndefined();
90
+ expect(notifier.schedule).not.toHaveBeenCalled();
91
+ });
92
+ });
@@ -7,7 +7,7 @@ const args = (o: Record<string, string>) => (k: string) => o[k];
7
7
 
8
8
  describe('readLaunch', () => {
9
9
  it('a plain launch is real mode with nothing to open', () => {
10
- expect(readLaunch(args({}), config)).toEqual({ fake: false, scenario: 'normal', target: null, autostop: null, scheme: null, hapticProbe: false, fakeBriefing: false });
10
+ expect(readLaunch(args({}), config)).toEqual({ fake: false, scenario: 'normal', target: null, autostop: null, scheme: null, hapticProbe: false, fakeBriefing: false, fakeReply: [] });
11
11
  });
12
12
  it('-tgFakeTabs with -tgTab and -tgDetail', () => {
13
13
  expect(readLaunch(args({ tgFakeTabs: '1', tgTab: 'tracker', tgDetail: 'c1' }), config)).toMatchObject({ fake: true, target: { tab: 'tracker', id: 'c1' } });
@@ -20,6 +20,7 @@ describe('readLaunch', () => {
20
20
  it('-tgHapticProbe 1', () => {
21
21
  expect(readLaunch(args({ tgHapticProbe: '1' }), config).hapticProbe).toBe(true);
22
22
  expect(readLaunch(args({ tgFakeBriefing: '1' }), config).fakeBriefing).toBe(true);
23
+ expect(readLaunch(args({ tgFakeReply: 'move this one to later | undo' }), config).fakeReply).toEqual(['move this one to later', 'undo']);
23
24
  });
24
25
  it('-tgFakeState and -tgAutostop', () => {
25
26
  expect(readLaunch(args({ tgFakeTabs: '1', tgFakeState: 'empty', tgAutostop: '30' }), config)).toMatchObject({ scenario: 'empty', autostop: 30 });
@@ -0,0 +1,101 @@
1
+ import { createDiagnostics } from '../recording/diagnostics';
2
+ import { createPermissionFlow } from '../recording/permissions';
3
+ import { createRecorderAudio } from '../recording/recorderAudio';
4
+ import type { createSession } from '../recording/session';
5
+ import { createAudioPlayer } from '../briefing/audioPlayer';
6
+ import { createBriefingApi } from '../briefing/api';
7
+ import { createBriefingController } from '../briefing/controller';
8
+ import { createFakeBriefingApi } from '../briefing/fake';
9
+ import { createFakeBriefingReplyApi } from '../briefing/fakeReply';
10
+ import { syncMorningFromCentral, syncMorningNotification, type MorningNotifier } from '../briefing/notify';
11
+ import { createBriefingReplyController } from '../briefing/reply';
12
+ import { createBriefingReplyApi } from '../briefing/replyApi';
13
+ import type { FakeNativeCorpusApi } from '../corpus/fake';
14
+ import type { FoundryAppConfig } from './config/types';
15
+ import type { FoundryDevice } from './device';
16
+ import type { FoundryStrings } from './strings';
17
+
18
+ /** What `-tgFakeBriefing` runs over: the fake tenant the tabs read, and the lines `-tgFakeReply` "says". */
19
+ export interface FakeBriefingDeps {
20
+ corpus: FakeNativeCorpusApi;
21
+ script: string[];
22
+ }
23
+
24
+ const newReplyId = () => `br-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
25
+ const tick = (fn: () => void, ms: number) => { const h = setInterval(fn, ms); return () => clearInterval(h); };
26
+ const wait = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));
27
+ const zone = () => { try { return Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC'; } catch { return 'UTC'; } };
28
+
29
+ /**
30
+ * 'What's on the plate': the briefing flow over the device's playback driver (sharing the recorder's session inspector),
31
+ * the hold-to-talk reply (its own recorder instance: a reply is never a voice note), and the morning notification.
32
+ */
33
+ export function createBriefing(deps: {
34
+ config: FoundryAppConfig;
35
+ device: FoundryDevice;
36
+ session: ReturnType<typeof createSession>;
37
+ diag: ReturnType<typeof createDiagnostics>;
38
+ strings: FoundryStrings;
39
+ fake: FakeBriefingDeps | null;
40
+ }) {
41
+ const { config, device, session, diag, strings, fake } = deps;
42
+ const dev = device.briefing;
43
+ if (!dev) throw new Error('features.briefing is on but the device supplies no briefing bindings');
44
+ const inspector = dev.session ?? device.recording?.session;
45
+ if (!inspector) throw new Error('features.briefing needs an audio-session inspector (device.briefing.session or device.recording.session)');
46
+ const makePlayer = () => createAudioPlayer({ driver: dev.driver, session: inspector, diag, poll: tick, sleep: wait });
47
+ const player = makePlayer();
48
+ const api = fake
49
+ ? createFakeBriefingApi(dev.fixture)
50
+ : createBriefingApi({ tandemUrl: config.tenant.url, authorizedFetch: session.authorizedFetch, bearer: session.bearer });
51
+ const controller = createBriefingController({
52
+ api, player, diag,
53
+ messages: { failed: strings.briefingFailed, empty: strings.briefingEmpty, textOnly: strings.briefingTextOnly, audioFailed: strings.briefingAudioFailed },
54
+ });
55
+
56
+ const changed = new Set<() => void>();
57
+ const itemsChanged = { subscribe(l: () => void) { changed.add(l); return () => { changed.delete(l); }; } };
58
+ let reply: ReturnType<typeof createBriefingReplyController> | null = null;
59
+ if (config.briefing.reply) {
60
+ const rec = device.recording;
61
+ if (!rec) throw new Error('features.briefing.reply needs the recording bindings (features.recording on, device.recording supplied)');
62
+ // Its own recorder audio: an interruption here cancels nothing else, and a reply never reaches the upload queue.
63
+ const audio = createRecorderAudio({
64
+ driver: rec.driver, session: rec.session, fs: { size: rec.fileSize }, poll: tick, sleep: wait, diag, onInterrupted: () => undefined,
65
+ });
66
+ const permissions = createPermissionFlow({ perms: rec.permissions, openSettings: rec.openSettings, log: diag.log });
67
+ const replyApi = fake
68
+ ? createFakeBriefingReplyApi({ corpus: fake.corpus, script: fake.script })
69
+ : createBriefingReplyApi({ tandemUrl: config.tenant.url, authorizedFetch: session.authorizedFetch, bearer: session.bearer, filePart: rec.filePart });
70
+ reply = createBriefingReplyController({
71
+ briefing: controller, api: replyApi, audio, speaker: makePlayer(), removeFile: rec.removeFile, ensurePermission: permissions.ensure,
72
+ confirm: config.briefing.confirm, newId: newReplyId, diag, allowSilence: Boolean(fake),
73
+ strings: { micDenied: strings.micDenied, tooShort: strings.replyTooShort, notHeard: strings.replyNotHeard, failed: strings.replyFailed, noAudio: strings.replyNoAudio },
74
+ onChanged: () => { diag.log('reply.changed'); changed.forEach((l) => l()); },
75
+ });
76
+ }
77
+
78
+ /** Make the phone's morning notification match the person's setting (a fixed 07:30 in the fake). Never throws. */
79
+ async function syncNotification(): Promise<void> {
80
+ if (!config.briefing.notification) return;
81
+ // The fakes never touch the device's notification centre: they log what would be scheduled.
82
+ const notifier: MorningNotifier | undefined = fake ? {
83
+ schedule: async (plan) => { diag.log('notification.scheduled', { time: plan.time, deepLink: plan.deepLink, repeat: plan.repeat }); return 'fake'; },
84
+ cancel: async () => { diag.log('notification.cancelled'); },
85
+ } : dev?.notifier;
86
+ if (!notifier) return;
87
+ try {
88
+ const plan = fake
89
+ ? await syncMorningNotification(notifier, { enabled: true, morningTime: '07:30', timeZone: zone(), scheme: config.app.scheme })
90
+ : await syncMorningFromCentral({
91
+ notifier, authorizedFetch: session.authorizedFetch, centralUrl: config.tenant.centralUrl,
92
+ tenantSlug: config.tenant.slug ?? config.brand.authApp, scheme: config.app.scheme, timeZone: zone(),
93
+ });
94
+ diag.log('notification.synced', { scheduled: Boolean(plan), time: plan?.time ?? null });
95
+ } catch (e) {
96
+ diag.log('notification.failed', { error: e instanceof Error ? e.message : String(e) });
97
+ }
98
+ }
99
+
100
+ return { controller, player, reply, syncNotification, itemsChanged };
101
+ }
@@ -0,0 +1,49 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { createLinkResolver } from '../links';
3
+ import { resolveFoundryApp, validateFoundryApp } from '../validate';
4
+
5
+ const base = { app: { name: 'Acme Go', scheme: 'acmego' }, tenant: { url: 'https://acme.example.com' } };
6
+
7
+ describe('features.briefing', () => {
8
+ it('test_true_turns_the_briefing_on_with_reply_on_ask_free_auto_and_a_notification', () => {
9
+ const c = resolveFoundryApp({ ...base, features: { briefing: true } });
10
+ expect(c.features.briefing).toBe(true);
11
+ expect(c.briefing).toEqual({ reply: true, confirm: 'auto', notification: true });
12
+ });
13
+
14
+ it('test_off_by_default_and_the_options_are_inert_when_off', () => {
15
+ const c = resolveFoundryApp(base);
16
+ expect(c.features.briefing).toBe(false);
17
+ expect(c.briefing).toEqual({ reply: false, confirm: 'auto', notification: false });
18
+ });
19
+
20
+ it('test_an_object_turns_it_on_and_sets_the_options', () => {
21
+ const c = resolveFoundryApp({ ...base, features: { briefing: { reply: true, confirm: 'ask', notification: false } } });
22
+ expect(c.features.briefing).toBe(true);
23
+ expect(c.briefing).toEqual({ reply: true, confirm: 'ask', notification: false });
24
+ });
25
+
26
+ it('test_reply_can_be_switched_off_alone', () => {
27
+ expect(resolveFoundryApp({ ...base, features: { briefing: { reply: false } } }).briefing).toEqual({ reply: false, confirm: 'auto', notification: true });
28
+ });
29
+
30
+ it('test_bad_options_are_named_by_path', () => {
31
+ const r = validateFoundryApp({ ...base, features: { briefing: { reply: 'yes', confirm: 'maybe', morning: true } } });
32
+ expect(r.ok ? [] : r.issues.map((i) => i.path)).toEqual(['features.briefing.morning', 'features.briefing.reply', 'features.briefing.confirm']);
33
+ const s = validateFoundryApp({ ...base, features: { briefing: 'on' } });
34
+ expect(s.ok ? [] : s.issues.map((i) => i.path)).toEqual(['features.briefing']);
35
+ });
36
+ });
37
+
38
+ describe('the briefing link', () => {
39
+ it('test_scheme_briefing_opens_the_briefing_when_the_feature_is_on', () => {
40
+ const on = createLinkResolver(resolveFoundryApp({ ...base, features: { briefing: true } }));
41
+ expect(on.resolve('acmego://briefing')).toEqual({ kind: 'briefing' });
42
+ expect(on.resolve('acmego://briefing?from=notification')).toEqual({ kind: 'briefing' });
43
+ });
44
+ it('test_it_is_not_a_link_when_the_feature_is_off_or_the_recording_screen_is_missing', () => {
45
+ expect(createLinkResolver(resolveFoundryApp(base)).resolve('acmego://briefing')).toBeNull();
46
+ const noGo = createLinkResolver(resolveFoundryApp({ ...base, features: { briefing: true, recording: false } }));
47
+ expect(noGo.resolve('acmego://briefing')).toBeNull();
48
+ });
49
+ });
@@ -4,6 +4,8 @@ import type { FoundryAppConfig } from './types';
4
4
  /** What a link asks the app to do. */
5
5
  export type LinkAction =
6
6
  | { kind: 'record'; autostop?: number }
7
+ /** `<scheme>://briefing` (the morning notification): open the GO screen and play today's briefing. */
8
+ | { kind: 'briefing' }
7
9
  | { kind: 'open'; tab: string; id?: string };
8
10
 
9
11
  export interface LinkResolver {
@@ -31,7 +33,7 @@ function routeMatcher(pattern: string): (path: string) => string | null {
31
33
  }
32
34
 
33
35
  /**
34
- * The one deep-link table: `<scheme>://record[?autostop=N]`, `<scheme>://tab/<key>[/<id>]`,
36
+ * The one deep-link table: `<scheme>://record[?autostop=N]`, `<scheme>://briefing`, `<scheme>://tab/<key>[/<id>]`,
35
37
  * `<scheme>://entity/<type>/<id>`, `<scheme>://<key>[/<id>]`, plus the config's own `links.routes`; the same
36
38
  * paths on `https://<host>/...` for each host in `links.hosts` (universal links).
37
39
  */
@@ -59,6 +61,7 @@ export function createLinkResolver(config: LinkConfig): LinkResolver {
59
61
  const seconds = Number(new URLSearchParams(m[4] ?? '').get('autostop'));
60
62
  return Number.isFinite(seconds) && seconds > 0 ? { kind: 'record', autostop: seconds } : { kind: 'record' };
61
63
  }
64
+ if (head === 'briefing' && segs.length === 1 && config.features.briefing && config.features.recording) return { kind: 'briefing' };
62
65
  for (const r of routes) {
63
66
  const id = r.match(path);
64
67
  if (id !== null) return { kind: 'open', tab: r.tab, id };
@@ -27,6 +27,16 @@ export interface FoundryFeatures {
27
27
  briefing: boolean;
28
28
  }
29
29
 
30
+ /** What the briefing does beyond playing. `features.briefing` takes `true`, or an object with any of these. */
31
+ export interface BriefingSettings {
32
+ /** Hold-to-talk reply under the briefing (needs the tenant's /corpus/briefing/reply route and the recording bindings). */
33
+ reply: boolean;
34
+ /** `auto`: a sure reply is applied at once and shown with Undo. `ask`: show what was understood and wait for Do it. */
35
+ confirm: 'auto' | 'ask';
36
+ /** The morning notification that opens the briefing (the time is the person's own setting on central; needs a notifier from the device). */
37
+ notification: boolean;
38
+ }
39
+
30
40
  export interface FoundryTabConfig {
31
41
  /** Unique; also the launch-arg / deep-link name of the tab (`<scheme>://tab/<key>`). */
32
42
  key: string;
@@ -99,6 +109,8 @@ export interface FoundryAppConfig {
99
109
  };
100
110
  theme: { mode: 'dark' | 'light' | 'system' };
101
111
  features: FoundryFeatures;
112
+ /** The briefing's options; all off when `features.briefing` is. */
113
+ briefing: BriefingSettings;
102
114
  tabs: FoundryTabConfig[];
103
115
  /** Record types the Home tab counts, in order. */
104
116
  home: { types: FoundryHomeType[] };
@@ -124,7 +136,7 @@ export type FoundryAppInput = {
124
136
  brand?: Partial<FoundryAppConfig['brand']>;
125
137
  tenant: Pick<FoundryAppConfig['tenant'], 'url'> & Partial<FoundryAppConfig['tenant']>;
126
138
  theme?: Partial<FoundryAppConfig['theme']>;
127
- features?: Partial<FoundryFeatures>;
139
+ features?: Partial<Omit<FoundryFeatures, 'briefing'>> & { briefing?: boolean | Partial<BriefingSettings> };
128
140
  tabs?: FoundryTabConfig[];
129
141
  home?: Partial<FoundryAppConfig['home']>;
130
142
  entityTypes?: Record<string, FoundryEntityType>;
@@ -1,5 +1,5 @@
1
1
  import { ICON_PATHS } from '@startsimpli/ui-native/icons';
2
- import { BUILTIN_SCREENS, type ConfigIssue, type FoundryAppConfig, type FoundryAppInput, type FoundryTabConfig } from './types';
2
+ import { BUILTIN_SCREENS, type BriefingSettings, type ConfigIssue, type FoundryAppConfig, type FoundryAppInput, type FoundryTabConfig } from './types';
3
3
  import {
4
4
  DEFAULT_BASE, DEFAULT_CENTRAL_URL, DEFAULT_FEATURES, DEFAULT_HOME_TYPES, SCREEN_DEFAULTS, SCREEN_ENTITY_TYPES, SCREEN_FEATURE, defaultBrandTagline, defaultTabs,
5
5
  } from './defaults';
@@ -99,10 +99,27 @@ export function validateFoundryApp(input: unknown, options: ValidateOptions = {}
99
99
  const featuresIn = section('features');
100
100
  allowed(featuresIn, Object.keys(DEFAULT_FEATURES), 'features');
101
101
  const features = { ...DEFAULT_FEATURES };
102
+ let briefing: BriefingSettings = { reply: false, confirm: 'auto', notification: false };
102
103
  for (const k of Object.keys(DEFAULT_FEATURES) as Array<keyof typeof DEFAULT_FEATURES>) {
103
104
  const v = featuresIn[k];
104
105
  if (v === undefined) continue;
105
- if (typeof v !== 'boolean') bad(`features.${k}`, 'must be true or false'); else features[k] = v;
106
+ if (k === 'briefing' && isObj(v)) {
107
+ // The object form: it turns the briefing on and tunes it.
108
+ allowed(v, ['reply', 'confirm', 'notification'], 'features.briefing');
109
+ briefing = { reply: true, confirm: 'auto', notification: true };
110
+ for (const flag of ['reply', 'notification'] as const) {
111
+ if (v[flag] === undefined) continue;
112
+ if (typeof v[flag] !== 'boolean') bad(`features.briefing.${flag}`, 'must be true or false'); else briefing[flag] = v[flag] as boolean;
113
+ }
114
+ if (v.confirm !== undefined) {
115
+ if (v.confirm !== 'auto' && v.confirm !== 'ask') bad('features.briefing.confirm', 'must be "auto" or "ask"'); else briefing.confirm = v.confirm;
116
+ }
117
+ features.briefing = true;
118
+ } else if (typeof v !== 'boolean') bad(`features.${k}`, k === 'briefing' ? 'must be true, false or an object of options' : 'must be true or false');
119
+ else {
120
+ features[k] = v;
121
+ if (k === 'briefing' && v) briefing = { reply: true, confirm: 'auto', notification: true };
122
+ }
106
123
  }
107
124
 
108
125
  // tabs
@@ -199,6 +216,7 @@ export function validateFoundryApp(input: unknown, options: ValidateOptions = {}
199
216
  tenant: { url: trimSlash(tenant.url as string), centralUrl: trimSlash((tenant.centralUrl as string | undefined) ?? DEFAULT_CENTRAL_URL), ...(tenant.slug ? { slug: tenant.slug as string } : {}) },
200
217
  theme: { mode: (theme.mode as FoundryAppConfig['theme']['mode'] | undefined) ?? DEFAULT_BASE.theme.mode },
201
218
  features,
219
+ briefing,
202
220
  tabs,
203
221
  home: { types: homeTypes },
204
222
  entityTypes,
@@ -2,7 +2,7 @@ import { createConnectionsMeApi } from '../../api/connections';
2
2
  import { createMcpTokensApi, type McpTokensApi } from '../../api/mcp-tokens';
3
3
  import type { MemberConnectionsApi } from '../../components/pages/types';
4
4
  import { createNativeCorpusApi, type NativeCorpusApi } from '../corpus/api';
5
- import { createFakeNativeCorpusApi } from '../corpus/fake';
5
+ import { createFakeNativeCorpusApi, type FakeNativeCorpusApi } from '../corpus/fake';
6
6
  import { withScenario, type FakeScenario } from '../corpus/fake-scenarios';
7
7
  import { fakeEntityRows } from './fakeEntities';
8
8
  import { createFakeConnectionsApi } from '../screens/connections/fake';
@@ -26,14 +26,14 @@ export interface FoundryData {
26
26
  * The data layer every screen reads: the signed-in tenant over the session's authorized fetch, or in-memory fakes
27
27
  * (`fake`) for simulator checks that need no sign-in and no network.
28
28
  */
29
- export function createFoundryData(deps: { config: FoundryAppConfig; authorizedFetch: AuthorizedFetch; fake?: boolean; scenario?: FakeScenario }): FoundryData {
29
+ export function createFoundryData(deps: { config: FoundryAppConfig; authorizedFetch: AuthorizedFetch; fake?: boolean; scenario?: FakeScenario; /** The fake tenant to read, when something else (the fake briefing's replies) must write to the same rows. */ fakeCorpus?: FakeNativeCorpusApi }): FoundryData {
30
30
  const { config, authorizedFetch, fake, scenario } = deps;
31
31
  const wantsNotes = config.tabs.some((t) => t.screen === 'notes');
32
32
  if (fake) {
33
33
  const fakeConnections = createFakeConnectionsApi({ connections: scenario === 'empty' ? [] : undefined });
34
34
  return {
35
35
  openUrl: async () => { fakeConnections.completeConsent(); return { completed: true }; },
36
- corpus: createFakeNativeCorpusApi({ scenario, extraEntities: fakeEntityRows(config) }),
36
+ corpus: deps.fakeCorpus ?? createFakeNativeCorpusApi({ scenario, extraEntities: fakeEntityRows(config) }),
37
37
  notes: wantsNotes ? createVoiceNotesController({ api: createFakeVoiceApi({ scenario }) }) : null,
38
38
  member: {
39
39
  connections: withScenario(fakeConnections, scenario),
@@ -4,6 +4,7 @@ import type { BackgroundTasks } from '../recording/lifecycle';
4
4
  import type { PermissionsApi } from '../recording/permissions';
5
5
  import type { RecordingFile } from '../recording/recovery';
6
6
  import type { AudioPlayerDriver, PlaybackSource } from '../briefing/audioPlayer';
7
+ import type { MorningNotifier } from '../briefing/notify';
7
8
 
8
9
  export interface TextFiles {
9
10
  exists(path: string): Promise<boolean>;
@@ -32,6 +33,8 @@ export interface BriefingDevice {
32
33
  session?: SessionInspector;
33
34
  /** What `-tgFakeBriefing` plays: a bundled clip, since the fake briefing has no server behind it. */
34
35
  fixture?: PlaybackSource;
36
+ /** Schedules the morning notification (local, repeating) that opens `<scheme>://briefing`; `expo-notifications` in the template. Without one there is no morning notification. */
37
+ notifier?: MorningNotifier;
35
38
  }
36
39
 
37
40
  /**
@@ -12,6 +12,7 @@ import type { FoundryAppConfig } from './config/types';
12
12
  * -tgNote <id> open that note (device, real data)
13
13
  * -tgAutostop N start a timed recording after sign-in
14
14
  * -tgFakeBriefing 1 'What's on the plate' plays a bundled clip over a fixed briefing: no server, no sign-in (add -tgFakeTabs 1)
15
+ * -tgFakeReply "a|b" what the fake reply 'hears' on each hold-to-talk, in order (needs -tgFakeBriefing); default "move this one to later"
15
16
  * -tgHapticProbe 1 fire one haptic per interaction through the real engine; the diagnostics log shows each call and the engine's answer
16
17
  * -tgScheme light|dark override the config's theme mode (simulator checks of the light theme)
17
18
  */
@@ -26,6 +27,8 @@ export interface LaunchArgs {
26
27
  hapticProbe: boolean;
27
28
  /** `-tgFakeBriefing 1`: the briefing comes from a fixture with a bundled audio clip. */
28
29
  fakeBriefing: boolean;
30
+ /** `-tgFakeReply "a|b"`: what each recorded reply is taken to say, in order. */
31
+ fakeReply: string[];
29
32
  }
30
33
 
31
34
  export function readLaunch(get: (key: string) => unknown, config: Pick<FoundryAppConfig, 'tabs'>): LaunchArgs {
@@ -49,6 +52,7 @@ export function readLaunch(get: (key: string) => unknown, config: Pick<FoundryAp
49
52
  autostop: Number.isFinite(n) && n > 0 ? n : null,
50
53
  hapticProbe: str('tgHapticProbe') === '1',
51
54
  fakeBriefing: str('tgFakeBriefing') === '1',
55
+ fakeReply: str('tgFakeReply').split('|').map((l) => l.trim()).filter(Boolean),
52
56
  scheme: str('tgScheme') === 'light' ? 'light' : str('tgScheme') === 'dark' ? 'dark' : null,
53
57
  };
54
58
  }
@@ -30,6 +30,8 @@ export interface ScreenDeps {
30
30
  member: { connections: MemberConnectionsApi; mcpTokens: McpTokensApi };
31
31
  /** Opens a URL outside the app (`Linking.openURL`): a vendor's sign-in page, a tracker item. Absent in tests. */
32
32
  openUrl?: (url: string) => Promise<unknown>;
33
+ /** Fires when something outside a list changed its items (a spoken reply to the briefing): lists re-read. */
34
+ itemsChanged?: { subscribe(listener: () => void): () => void };
33
35
  }
34
36
 
35
37
  /** Builds one shell tab from its config entry. */
@@ -61,7 +63,7 @@ export const BUILTIN_FACTORIES: Record<string, ScreenFactory> = {
61
63
  : <NotesListScreen controller={notes} displays={corpus.schema?.displays} onOpen={(n) => push(n.id)} />),
62
64
  };
63
65
  },
64
- tracker: ({ config, corpus, member, openUrl }, tab) => trackerTab({ api: corpus, key: tab.key, label: tabLabel(tab), notesKey: firstKey(config, 'notes'), memberConnections: member.connections, openUrl }),
66
+ tracker: ({ config, corpus, member, openUrl, itemsChanged }, tab) => trackerTab({ api: corpus, itemsChanged, key: tab.key, label: tabLabel(tab), notesKey: firstKey(config, 'notes'), memberConnections: member.connections, openUrl }),
65
67
  library: ({ corpus }, tab) => libraryTab(corpus, { key: tab.key, label: tabLabel(tab) }),
66
68
  ask: ({ corpus }, tab) => askTab(corpus, { key: tab.key, label: tabLabel(tab) }),
67
69
  planning: ({ config, corpus }, tab) => createPlanningTab({ api: corpus, key: tab.key, label: tabLabel(tab), documentTab: firstKey(config, 'library') }),
@@ -6,6 +6,7 @@ import { noteSections } from '../../voice/sections';
6
6
  import { meterFraction } from '../../recording/levels';
7
7
  import { BriefingCard } from '../../briefing/BriefingCard';
8
8
  import type { BriefingController } from '../../briefing/controller';
9
+ import type { BriefingReplyController } from '../../briefing/reply';
9
10
  import type { RecorderState } from '../../recording/recorder';
10
11
  import type { FoundryServices } from '../services';
11
12
  import type { FoundryStrings } from '../strings';
@@ -13,7 +14,7 @@ import type { FoundryStrings } from '../strings';
13
14
  type Recording = NonNullable<FoundryServices['recording']>;
14
15
 
15
16
  /** The GO screen: one big button, a timer and level meter while recording, the last notes, and sign out. */
16
- export function RecordScreen({ recording, briefing, strings, onOpenDiagnostics, onSignOut }: { recording: Recording; briefing?: BriefingController | null; strings: FoundryStrings; onOpenDiagnostics: () => void; onSignOut: () => void }) {
17
+ export function RecordScreen({ recording, briefing, briefingReply, strings, onOpenDiagnostics, onSignOut }: { recording: Recording; briefing?: BriefingController | null; briefingReply?: BriefingReplyController | null; strings: FoundryStrings; onOpenDiagnostics: () => void; onSignOut: () => void }) {
17
18
  const theme = useTheme();
18
19
  const { recorder, notes: api, permissions } = recording;
19
20
  const [state, setState] = useState<RecorderState>(recorder.getState());
@@ -71,7 +72,7 @@ export function RecordScreen({ recording, briefing, strings, onOpenDiagnostics,
71
72
  void (isRecording ? recorder.stop() : (briefing?.handoffToRecording() ?? Promise.resolve()).then(() => recorder.go()));
72
73
  }}
73
74
  />
74
- {briefing && !isRecording ? <BriefingCard controller={briefing} strings={strings} /> : null}
75
+ {briefing && !isRecording ? <BriefingCard controller={briefing} reply={briefingReply} strings={strings} /> : null}
75
76
  {isRecording ? <Text testID="timer" style={[typeStyle(theme, 'largeTitle'), { textAlign: 'center', fontVariant: ['tabular-nums'] }]}>{mm}:{ss}</Text> : null}
76
77
  {state.phase === 'uploading' ? <Text variant="muted" style={{ textAlign: 'center' }}>{strings.sending}</Text> : null}
77
78
  {state.phase === 'sent' ? <Text variant="muted" style={{ textAlign: 'center' }} testID="status">{strings.sent}</Text> : null}
@@ -13,10 +13,7 @@ import type { Banners } from './banners';
13
13
  import { createLinkResolver } from './config/links';
14
14
  import type { FoundryAppConfig } from './config/types';
15
15
  import type { FoundryDevice, RecordingDevice } from './device';
16
- import { createAudioPlayer } from '../briefing/audioPlayer';
17
- import { createBriefingApi } from '../briefing/api';
18
- import { createBriefingController } from '../briefing/controller';
19
- import { createFakeBriefingApi } from '../briefing/fake';
16
+ import { createBriefing, type FakeBriefingDeps } from './briefingServices';
20
17
  import type { FoundryStrings } from './strings';
21
18
 
22
19
  const newId = () => `fa-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
@@ -103,35 +100,11 @@ function createRecording(deps: { config: FoundryAppConfig; device: FoundryDevice
103
100
  return { notes, queue, lifecycle, permissions, recorder, recoverAndDrain, pending };
104
101
  }
105
102
 
106
- /** 'What's on the plate': the briefing flow over the device's playback driver, sharing the recorder's session inspector. */
107
- function createBriefing(deps: { config: FoundryAppConfig; device: FoundryDevice; session: ReturnType<typeof createSession>; diag: ReturnType<typeof createDiagnostics>; strings: FoundryStrings; fake: boolean }) {
108
- const { config, device, session, diag, strings } = deps;
109
- const dev = device.briefing;
110
- if (!dev) throw new Error('features.briefing is on but the device supplies no briefing bindings');
111
- const inspector = dev.session ?? device.recording?.session;
112
- if (!inspector) throw new Error('features.briefing needs an audio-session inspector (device.briefing.session or device.recording.session)');
113
- const player = createAudioPlayer({
114
- driver: dev.driver,
115
- session: inspector,
116
- diag,
117
- poll: (fn, ms) => { const h = setInterval(fn, ms); return () => clearInterval(h); },
118
- sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
119
- });
120
- const api = deps.fake
121
- ? createFakeBriefingApi(dev.fixture)
122
- : createBriefingApi({ tandemUrl: config.tenant.url, authorizedFetch: session.authorizedFetch, bearer: session.bearer });
123
- const controller = createBriefingController({
124
- api, player, diag,
125
- messages: { failed: strings.briefingFailed, empty: strings.briefingEmpty, textOnly: strings.briefingTextOnly, audioFailed: strings.briefingAudioFailed },
126
- });
127
- return { controller, player };
128
- }
129
-
130
103
  /**
131
104
  * The composition root: session (sign-in, refresh, sign-out), diagnostics, the link router and, when recording is on,
132
105
  * the recorder with its upload queue. The app shell passes the device bindings; nothing here is Foundry-specific.
133
106
  */
134
- export function createFoundryServices(deps: { config: FoundryAppConfig; device: FoundryDevice; banners: Banners; strings: FoundryStrings; /** `-tgFakeBriefing`: a fixed briefing and the device's bundled clip. */ fakeBriefing?: boolean }) {
107
+ export function createFoundryServices(deps: { config: FoundryAppConfig; device: FoundryDevice; banners: Banners; strings: FoundryStrings; /** `-tgFakeBriefing`: a fixed briefing and the device's bundled clip over the fake tenant (and `-tgFakeReply`'s script). */ fakeBriefing?: FakeBriefingDeps | null }) {
135
108
  const { config, device, banners } = deps;
136
109
  const diagPath = device.documentUri('diagnostics.json');
137
110
  const diag = createDiagnostics({
@@ -152,10 +125,17 @@ export function createFoundryServices(deps: { config: FoundryAppConfig; device:
152
125
  ? createRecording({ config, device, rec: device.recording, session, diag, banners })
153
126
  : null;
154
127
 
155
- const briefing = config.features.briefing ? createBriefing({ config, device, session, diag, strings: deps.strings, fake: Boolean(deps.fakeBriefing) }) : null;
128
+ const briefing = config.features.briefing ? createBriefing({ config, device, session, diag, strings: deps.strings, fake: deps.fakeBriefing ?? null }) : null;
156
129
 
157
130
  let open: (tab: string, id?: string) => void = () => undefined;
131
+ const goTab = config.tabs.find((t) => t.screen === 'record')?.key;
158
132
  const deepLink = createDeepLink({
133
+ openBriefing: () => {
134
+ // The morning notification: land on GO and play today's briefing (a briefing already playing is left alone).
135
+ if (goTab) open(goTab);
136
+ const phase = briefing?.controller.getState().phase;
137
+ if (phase !== 'playing' && phase !== 'loading') void briefing?.controller.start();
138
+ },
159
139
  resolver: createLinkResolver(config),
160
140
  getPhase: () => recording?.recorder.getState().phase ?? 'idle',
161
141
  go: (o) => recording?.recorder.go(o),
@@ -172,6 +152,7 @@ export function createFoundryServices(deps: { config: FoundryAppConfig; device:
172
152
  /** After sign-in/restore. */
173
153
  async onReady() {
174
154
  if (recording) await recording.recoverAndDrain();
155
+ void briefing?.syncNotification();
175
156
  await deepLink.sessionReady();
176
157
  },
177
158
  /** App came to the foreground: renew a stale access token first (silently), then flush the upload queue. */