@reticlehq/core 3.5.0 → 3.7.0

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 (113) hide show
  1. package/dist/artifacts/artifacts-entry.d.ts +4 -0
  2. package/dist/artifacts/artifacts-entry.js +4 -0
  3. package/dist/artifacts/drive-script.d.ts +1404 -0
  4. package/dist/artifacts/drive-script.js +220 -0
  5. package/dist/artifacts/flow-constants.d.ts +19 -0
  6. package/dist/artifacts/flow-constants.js +21 -0
  7. package/dist/artifacts/flow-results.d.ts +450 -0
  8. package/dist/artifacts/flow-results.js +1 -0
  9. package/dist/artifacts/flow-types.d.ts +75 -427
  10. package/dist/artifacts/flow-types.js +15 -2
  11. package/dist/artifacts/harness-credits.d.ts +39 -0
  12. package/dist/artifacts/harness-credits.js +69 -0
  13. package/dist/artifacts/harness-map.d.ts +98 -0
  14. package/dist/artifacts/harness-map.js +36 -0
  15. package/dist/artifacts/hud-notices.d.ts +134 -0
  16. package/dist/artifacts/hud-notices.js +124 -0
  17. package/dist/artifacts/impact.d.ts +489 -189
  18. package/dist/artifacts/impact.js +90 -47
  19. package/dist/artifacts/journal.d.ts +105 -5
  20. package/dist/artifacts/journal.js +41 -0
  21. package/dist/artifacts/prompt-context.d.ts +105 -0
  22. package/dist/artifacts/prompt-context.js +108 -0
  23. package/dist/artifacts/screenshot-upload.d.ts +51 -0
  24. package/dist/artifacts/screenshot-upload.js +26 -0
  25. package/dist/desktop-contract.cjs +1 -0
  26. package/dist/desktop-contract.d.cts +1 -0
  27. package/dist/hooks/hook-events.d.ts +4 -4
  28. package/dist/hud-entry.d.ts +2 -0
  29. package/dist/hud-entry.js +4 -0
  30. package/dist/identity/contract-fingerprint.d.ts +9 -0
  31. package/dist/identity/contract-fingerprint.js +12 -0
  32. package/dist/identity/testid-attribute.d.ts +18 -0
  33. package/dist/identity/testid-attribute.js +24 -0
  34. package/dist/index.d.ts +9 -1
  35. package/dist/index.js +9 -1
  36. package/dist/onboarding.d.ts +10 -2
  37. package/dist/onboarding.js +6 -0
  38. package/dist/realm/registry.js +19 -1
  39. package/dist/schema/command-message.json +36 -0
  40. package/dist/schema/command-name.json +5 -1
  41. package/dist/schema/event-payloads.json +56 -2
  42. package/dist/schema/reticle-message.json +36 -0
  43. package/dist/telemetry-bug.d.ts +169 -0
  44. package/dist/telemetry-bug.js +123 -0
  45. package/dist/telemetry-entry.d.ts +1 -0
  46. package/dist/telemetry-entry.js +1 -0
  47. package/dist/telemetry-feedback.d.ts +2 -2
  48. package/dist/telemetry-refusal.d.ts +5 -4
  49. package/dist/telemetry-session.d.ts +79 -1
  50. package/dist/telemetry-session.js +57 -1
  51. package/dist/telemetry-signals.d.ts +339 -0
  52. package/dist/telemetry-signals.js +138 -0
  53. package/dist/telemetry.d.ts +330 -276
  54. package/dist/telemetry.js +40 -115
  55. package/dist/tour.d.ts +1 -0
  56. package/dist/tour.js +13 -5
  57. package/dist/verdict/consequence.d.ts +3 -0
  58. package/dist/verdict/disparity.d.ts +105 -0
  59. package/dist/verdict/disparity.js +40 -0
  60. package/dist/verdict/findings.d.ts +11 -0
  61. package/dist/verdict/findings.js +16 -0
  62. package/dist/verdict/instrumentation-coverage.d.ts +115 -0
  63. package/dist/verdict/instrumentation-coverage.js +226 -0
  64. package/dist/verdict/instrumentation-gap.js +1 -1
  65. package/dist/verdict/intent.d.ts +19 -5
  66. package/dist/verdict/intent.js +13 -1
  67. package/dist/verdict/predicate-tree.d.ts +15 -0
  68. package/dist/verdict/predicate-tree.js +21 -0
  69. package/dist/verdict/predicate.d.ts +28 -0
  70. package/dist/verdict/predicate.js +94 -15
  71. package/dist/verdict/security.d.ts +25 -0
  72. package/dist/verdict/security.js +82 -0
  73. package/dist/verdict/verdict-attribution.js +1 -0
  74. package/dist/verdict/verification-run.d.ts +638 -32
  75. package/dist/verdict/verification-run.js +90 -0
  76. package/dist/verdict/verified-constants.d.ts +19 -0
  77. package/dist/verdict/verified-constants.js +22 -0
  78. package/dist/wire/constants/constants.d.ts +60 -32
  79. package/dist/wire/constants/constants.js +61 -33
  80. package/dist/wire/constants/hud-controls.d.ts +1 -1
  81. package/dist/wire/constants/hud-controls.js +34 -1
  82. package/dist/wire/constants/hud-use.d.ts +89 -1
  83. package/dist/wire/constants/hud-use.js +62 -1
  84. package/dist/wire/constants/mcp-wire.d.ts +10 -0
  85. package/dist/wire/constants/mcp-wire.js +10 -0
  86. package/dist/wire/constants/reticle-chrome.d.ts +19 -0
  87. package/dist/wire/constants/reticle-chrome.js +19 -0
  88. package/dist/wire/constants/session-constants.d.ts +21 -0
  89. package/dist/wire/constants/session-constants.js +21 -0
  90. package/dist/wire/desktop-contract.d.ts +11 -0
  91. package/dist/wire/desktop-contract.js +14 -0
  92. package/dist/wire/event-payloads.d.ts +77 -4
  93. package/dist/wire/event-payloads.js +27 -0
  94. package/dist/wire/global-press.d.ts +34 -3
  95. package/dist/wire/global-press.js +91 -3
  96. package/dist/wire/hold.d.ts +14 -0
  97. package/dist/wire/hold.js +18 -0
  98. package/dist/wire/messages.d.ts +129 -32
  99. package/dist/wire/messages.js +17 -1
  100. package/dist/wire/platform-link.d.ts +238 -0
  101. package/dist/wire/platform-link.js +234 -0
  102. package/dist/wire/tool-names.d.ts +2 -0
  103. package/dist/wire/tool-names.js +2 -0
  104. package/dist/wire/types.d.ts +26 -6
  105. package/dist/wire/types.js +5 -0
  106. package/dist/words/no-session-reason.d.ts +7 -0
  107. package/dist/words/no-session-reason.js +7 -0
  108. package/dist/words/notices.d.ts +1 -1
  109. package/dist/words/notices.js +5 -3
  110. package/dist/words/upgrade.js +1 -1
  111. package/dist/words/writing-rule.d.ts +14 -0
  112. package/dist/words/writing-rule.js +17 -0
  113. package/package.json +1 -1
@@ -15,7 +15,10 @@ export { FlowExpectSchema } from './flow-expect-flat.js';
15
15
  // Its own directory's constants, which this file had been reaching through `wire/constants/constants.js`
16
16
  // to get -- the clearest cost of that re-export: artifacts went out to wire to fetch a symbol
17
17
  // that had been sitting next door the whole time.
18
- import { AnchorKind, FlowStatus, } from './flow-constants.js';
18
+ import { AnchorKind, FlowStatus } from './flow-constants.js';
19
+ // The replay, suite and heal result envelopes live in their own module, re-exported for the same
20
+ // reason as the flat expect above.
21
+ export * from './flow-results.js';
19
22
  /**
20
23
  * The MCP tool names that can appear as a recorded flow step's `tool`. These are the ONLY tool names
21
24
  * that cross the wire into a persisted flow file — the browser recorder stamps them, the server replays
@@ -43,6 +46,10 @@ export const FlowAnchorSchema = z.discriminatedUnion('kind', [
43
46
  kind: z.literal(AnchorKind.ROLE),
44
47
  role: z.string().min(1),
45
48
  name: z.string().optional(),
49
+ // Which of several same-named controls was recorded, in page order, and how many there were.
50
+ // Honoured only while the page still has exactly `of` of them; otherwise the step is ambiguous.
51
+ nth: z.number().int().min(0).optional(),
52
+ of: z.number().int().min(2).optional(),
46
53
  }),
47
54
  z.object({ kind: z.literal(AnchorKind.SIGNAL), name: z.string().min(1) }),
48
55
  // Auto-anchor: re-find an element by component identity / source location when it has no testid.
@@ -139,7 +146,7 @@ const baseFlowStep = z.object({
139
146
  args: z.record(z.unknown()).optional(),
140
147
  expect: ExpectSchema.optional(),
141
148
  degraded: z.boolean().optional(),
142
- timeoutMs: z.number().int().positive().optional(),
149
+ timeoutMs: z.number().int().nonnegative().optional(),
143
150
  invoke: z.string().min(1).optional(),
144
151
  /** See FlowStep.page / FlowStep.endPage. */
145
152
  page: z.string().optional(),
@@ -200,6 +207,12 @@ export const FlowFileSchema = z.object({
200
207
  * the on-disk version stays FLOW_FILE_VERSION 1.
201
208
  */
202
209
  startPath: z.string().optional(),
210
+ /**
211
+ * The saved flow this one was generated from, with different parameters (a fixture's customer,
212
+ * a seeded id). A suite that writes runtime copies of a template and deletes them after replay
213
+ * proved the template, and a strict pass of a copy counts toward it in the gate (#1321).
214
+ */
215
+ template: z.string().min(1).optional(),
203
216
  // FUTURE: fixtures/preconditions — schema slot reserved, unpopulated this cut. The recorder
204
217
  // never writes it and no fixture runner exists.
205
218
  fixture: z.string().optional(),
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Harness credits, as the platform grants them and as every surface says them.
3
+ *
4
+ * One file because the HUD's row and the daemon's refusal must say the same sentence: when the two
5
+ * were written apart, the HUD offered "a free monthly allowance" the platform no longer grants.
6
+ * The numbers are always the platform's (`limit`); only the trial length is not on the wire.
7
+ *
8
+ * Served from `@reticlehq/core/hud` only: from the root entry it rode into every page's first load.
9
+ */
10
+ import { CreditKind } from './impact.js';
11
+ /** The trial a card starts. Not on the wire; the platform's own sentence names it the same. */
12
+ export declare const TRIAL_DAYS = 14;
13
+ /** What a new account is granted, and what a card's trial grants. The platform's numbers, said. */
14
+ export declare const FREE_CREDITS = 10;
15
+ export declare const TRIAL_CREDITS = 500;
16
+ /** What a signed-out HUD says the Harness costs to try. */
17
+ export declare const SIGN_UP_PITCH: string;
18
+ /** The platform's offer, worded once: what a card starts, and what an account gets without one. */
19
+ export declare const TRIAL_OFFER: string;
20
+ export interface Credits {
21
+ used: number;
22
+ limit: number;
23
+ kind?: CreditKind | undefined;
24
+ /** Whole days the grant has left, when the platform gave an end date. Absent: not said. */
25
+ daysLeft?: number | undefined;
26
+ }
27
+ /** Nothing left. An unbounded plan (no credits reported) never is. */
28
+ export declare function creditsSpent(credits: Credits | undefined): boolean;
29
+ /** "8 of 10 free credits", "420 of 500 trial credits", else "N of M credits left". */
30
+ export declare function creditsLeftText(credits: Credits): string;
31
+ /** "Trial: 120 of 500 credits used · 380 left · 9 days left"; days only when the platform said. */
32
+ export declare function creditsUsageText(credits: Credits): string;
33
+ /** The sentence for no credits left, and the one thing that gets more when there is one. */
34
+ export declare function creditsUsedText(credits: Credits): {
35
+ said: string;
36
+ action?: string;
37
+ };
38
+ /** The same, as one terminal line, with where to act when there is somewhere. */
39
+ export declare function creditsUsedLine(credits: Credits, planUrl: string): string;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Harness credits, as the platform grants them and as every surface says them.
3
+ *
4
+ * One file because the HUD's row and the daemon's refusal must say the same sentence: when the two
5
+ * were written apart, the HUD offered "a free monthly allowance" the platform no longer grants.
6
+ * The numbers are always the platform's (`limit`); only the trial length is not on the wire.
7
+ *
8
+ * Served from `@reticlehq/core/hud` only: from the root entry it rode into every page's first load.
9
+ */
10
+ import { CreditKind } from './impact.js';
11
+ /** The trial a card starts. Not on the wire; the platform's own sentence names it the same. */
12
+ export const TRIAL_DAYS = 14;
13
+ /** What a new account is granted, and what a card's trial grants. The platform's numbers, said. */
14
+ export const FREE_CREDITS = 10;
15
+ export const TRIAL_CREDITS = 500;
16
+ /** What a signed-out HUD says the Harness costs to try. */
17
+ export const SIGN_UP_PITCH = `Sign up: ${String(FREE_CREDITS)} free credits to try Reticle Harness · ` +
18
+ `add a card for a ${String(TRIAL_CREDITS)}-credit, ${String(TRIAL_DAYS)}-day trial`;
19
+ /** The platform's offer, worded once: what a card starts, and what an account gets without one. */
20
+ export const TRIAL_OFFER = `a card starts a ${String(TRIAL_DAYS)}-day trial with ${String(TRIAL_CREDITS)} Harness credits; ` +
21
+ `without one, ${String(FREE_CREDITS)} sign-up credits`;
22
+ /** A credit count: each model call is charged its exact share, so up to two decimals, never floored. */
23
+ const count = (n) => n.toLocaleString('en-US', { maximumFractionDigits: 2 });
24
+ /** Nothing left. An unbounded plan (no credits reported) never is. */
25
+ export function creditsSpent(credits) {
26
+ return credits !== undefined && credits.used >= credits.limit;
27
+ }
28
+ /** "8 of 10 free credits", "420 of 500 trial credits", else "N of M credits left". */
29
+ export function creditsLeftText(credits) {
30
+ const of = `${count(Math.max(0, credits.limit - credits.used))} of ${count(credits.limit)}`;
31
+ if (CreditKind.FREE === credits.kind)
32
+ return `${of} free credits`;
33
+ if (CreditKind.TRIAL === credits.kind)
34
+ return `${of} trial credits`;
35
+ return `${of} credits left`;
36
+ }
37
+ const GRANT_LABEL = {
38
+ [CreditKind.FREE]: 'Free',
39
+ [CreditKind.TRIAL]: 'Trial',
40
+ };
41
+ /** "Trial: 120 of 500 credits used · 380 left · 9 days left"; days only when the platform said. */
42
+ export function creditsUsageText(credits) {
43
+ const label = credits.kind === undefined ? undefined : GRANT_LABEL[credits.kind];
44
+ const left = Math.max(0, credits.limit - credits.used);
45
+ const days = credits.daysLeft === undefined
46
+ ? ''
47
+ : ` · ${String(credits.daysLeft)} day${1 === credits.daysLeft ? '' : 's'} left`;
48
+ return `${label === undefined ? '' : `${label}: `}${count(credits.used)} of ${count(credits.limit)} credits used · ${count(left)} left${days}`;
49
+ }
50
+ /** The sentence for no credits left, and the one thing that gets more when there is one. */
51
+ export function creditsUsedText(credits) {
52
+ if (CreditKind.FREE === credits.kind)
53
+ return {
54
+ said: `Your ${count(credits.limit)} free credits are used.`,
55
+ action: `Add a card to start your ${String(TRIAL_DAYS)}-day trial`,
56
+ };
57
+ if (CreditKind.TRIAL === credits.kind)
58
+ return {
59
+ said: `Your ${count(credits.limit)} trial credits are used. Pro starts when your trial ends.`,
60
+ };
61
+ return { said: "This month's credits are used. They renew over the next 30 days." };
62
+ }
63
+ /** The same, as one terminal line, with where to act when there is somewhere. */
64
+ export function creditsUsedLine(credits, planUrl) {
65
+ const text = creditsUsedText(credits);
66
+ if (text.action !== undefined)
67
+ return `${text.said} ${text.action}: ${planUrl}`;
68
+ return CreditKind.TRIAL === credits.kind ? `${text.said} Plan: ${planUrl}` : text.said;
69
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * The Harness's map of an app: the pages a survey reached before a drive, and what each showed.
3
+ *
4
+ * Built on the daemon with no model (the survey clicks nav links and toggles, never a field and never
5
+ * a write), kept in `.reticle/harness-map.json`, refreshed from what each drive reads, and sent to the
6
+ * platform when a drive starts. A drive that misses its goal on one page looks it up here instead of
7
+ * guessing, and the search before grading starts from it.
8
+ */
9
+ import { z } from 'zod';
10
+ /** Bounds on what one map holds: a dashboard's pages, not its rows. */
11
+ export declare const HarnessMapLimit: {
12
+ readonly PAGES: 40;
13
+ readonly TEXTS: 60;
14
+ readonly CONTROLS: 40;
15
+ readonly TEXT: 200;
16
+ };
17
+ export declare const HarnessMapPageSchema: z.ZodObject<{
18
+ /** The page's path (and hash), without its query or Reticle's own parameters. */
19
+ route: z.ZodString;
20
+ /** Its first heading, when it has one. */
21
+ heading: z.ZodOptional<z.ZodString>;
22
+ /** The words it showed: headings, labels and text, in reading order. */
23
+ texts: z.ZodArray<z.ZodString, "many">;
24
+ /** Its controls, as `role "name"`. */
25
+ controls: z.ZodArray<z.ZodString, "many">;
26
+ /** How the survey got here: the control on the start page, or absent for the start page. */
27
+ reachedBy: z.ZodOptional<z.ZodString>;
28
+ /** When this page was last read (epoch ms, injected). */
29
+ at: z.ZodNumber;
30
+ }, "strip", z.ZodTypeAny, {
31
+ route: string;
32
+ at: number;
33
+ texts: string[];
34
+ controls: string[];
35
+ heading?: string | undefined;
36
+ reachedBy?: string | undefined;
37
+ }, {
38
+ route: string;
39
+ at: number;
40
+ texts: string[];
41
+ controls: string[];
42
+ heading?: string | undefined;
43
+ reachedBy?: string | undefined;
44
+ }>;
45
+ export type HarnessMapPage = z.infer<typeof HarnessMapPageSchema>;
46
+ export declare const HarnessMapSchema: z.ZodObject<{
47
+ /** When the survey last ran (epoch ms, injected); a drive's own reads refresh pages, not this. */
48
+ surveyedAt: z.ZodNumber;
49
+ pages: z.ZodArray<z.ZodObject<{
50
+ /** The page's path (and hash), without its query or Reticle's own parameters. */
51
+ route: z.ZodString;
52
+ /** Its first heading, when it has one. */
53
+ heading: z.ZodOptional<z.ZodString>;
54
+ /** The words it showed: headings, labels and text, in reading order. */
55
+ texts: z.ZodArray<z.ZodString, "many">;
56
+ /** Its controls, as `role "name"`. */
57
+ controls: z.ZodArray<z.ZodString, "many">;
58
+ /** How the survey got here: the control on the start page, or absent for the start page. */
59
+ reachedBy: z.ZodOptional<z.ZodString>;
60
+ /** When this page was last read (epoch ms, injected). */
61
+ at: z.ZodNumber;
62
+ }, "strip", z.ZodTypeAny, {
63
+ route: string;
64
+ at: number;
65
+ texts: string[];
66
+ controls: string[];
67
+ heading?: string | undefined;
68
+ reachedBy?: string | undefined;
69
+ }, {
70
+ route: string;
71
+ at: number;
72
+ texts: string[];
73
+ controls: string[];
74
+ heading?: string | undefined;
75
+ reachedBy?: string | undefined;
76
+ }>, "many">;
77
+ }, "strip", z.ZodTypeAny, {
78
+ surveyedAt: number;
79
+ pages: {
80
+ route: string;
81
+ at: number;
82
+ texts: string[];
83
+ controls: string[];
84
+ heading?: string | undefined;
85
+ reachedBy?: string | undefined;
86
+ }[];
87
+ }, {
88
+ surveyedAt: number;
89
+ pages: {
90
+ route: string;
91
+ at: number;
92
+ texts: string[];
93
+ controls: string[];
94
+ heading?: string | undefined;
95
+ reachedBy?: string | undefined;
96
+ }[];
97
+ }>;
98
+ export type HarnessMap = z.infer<typeof HarnessMapSchema>;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The Harness's map of an app: the pages a survey reached before a drive, and what each showed.
3
+ *
4
+ * Built on the daemon with no model (the survey clicks nav links and toggles, never a field and never
5
+ * a write), kept in `.reticle/harness-map.json`, refreshed from what each drive reads, and sent to the
6
+ * platform when a drive starts. A drive that misses its goal on one page looks it up here instead of
7
+ * guessing, and the search before grading starts from it.
8
+ */
9
+ import { z } from 'zod';
10
+ /** Bounds on what one map holds: a dashboard's pages, not its rows. */
11
+ export const HarnessMapLimit = {
12
+ PAGES: 40,
13
+ TEXTS: 60,
14
+ CONTROLS: 40,
15
+ TEXT: 200,
16
+ };
17
+ const Text = z.string().max(HarnessMapLimit.TEXT);
18
+ export const HarnessMapPageSchema = z.object({
19
+ /** The page's path (and hash), without its query or Reticle's own parameters. */
20
+ route: Text.min(1),
21
+ /** Its first heading, when it has one. */
22
+ heading: Text.optional(),
23
+ /** The words it showed: headings, labels and text, in reading order. */
24
+ texts: z.array(Text).max(HarnessMapLimit.TEXTS),
25
+ /** Its controls, as `role "name"`. */
26
+ controls: z.array(Text).max(HarnessMapLimit.CONTROLS),
27
+ /** How the survey got here: the control on the start page, or absent for the start page. */
28
+ reachedBy: Text.optional(),
29
+ /** When this page was last read (epoch ms, injected). */
30
+ at: z.number().int().min(0),
31
+ });
32
+ export const HarnessMapSchema = z.object({
33
+ /** When the survey last ran (epoch ms, injected); a drive's own reads refresh pages, not this. */
34
+ surveyedAt: z.number().int().min(0),
35
+ pages: z.array(HarnessMapPageSchema).max(HarnessMapLimit.PAGES),
36
+ });
@@ -0,0 +1,134 @@
1
+ /**
2
+ * The notices the HUD's rail shows, edited without a release.
3
+ *
4
+ * The slides used to be compiled into the SDK, so changing a sentence meant shipping a version. The
5
+ * daemon now fetches a small JSON file from our own site, keeps the entries that apply to this
6
+ * machine, and pushes them to the HUD in the impact snapshot. The page never fetches it: the HUD runs
7
+ * inside somebody else's app, whose Content-Security-Policy may forbid the request.
8
+ *
9
+ * Everything here is pure. Fetching and caching live in the daemon; the clock arrives as an argument.
10
+ */
11
+ import { z } from 'zod';
12
+ /** Where the daemon reads the notices from. Overridable for self-hosting and tests. */
13
+ export declare const HUD_NOTICES_URL = "https://reticle.sh/hud/notices.v1.json";
14
+ export declare const NOTICES_FILE_VERSION = 1;
15
+ /** What the HUD renders. Only display fields: the audience rules never leave the daemon. */
16
+ export declare const HudNoticeSchema: z.ZodObject<{
17
+ id: z.ZodString;
18
+ kicker: z.ZodOptional<z.ZodString>;
19
+ title: z.ZodString;
20
+ detail: z.ZodOptional<z.ZodString>;
21
+ cta: z.ZodOptional<z.ZodObject<{
22
+ label: z.ZodString;
23
+ url: z.ZodEffects<z.ZodString, string, string>;
24
+ }, "strip", z.ZodTypeAny, {
25
+ label: string;
26
+ url: string;
27
+ }, {
28
+ label: string;
29
+ url: string;
30
+ }>>;
31
+ }, "strip", z.ZodTypeAny, {
32
+ id: string;
33
+ title: string;
34
+ detail?: string | undefined;
35
+ kicker?: string | undefined;
36
+ cta?: {
37
+ label: string;
38
+ url: string;
39
+ } | undefined;
40
+ }, {
41
+ id: string;
42
+ title: string;
43
+ detail?: string | undefined;
44
+ kicker?: string | undefined;
45
+ cta?: {
46
+ label: string;
47
+ url: string;
48
+ } | undefined;
49
+ }>;
50
+ export type HudNotice = z.infer<typeof HudNoticeSchema>;
51
+ /** One entry in the file: a notice plus who sees it and when. */
52
+ export declare const HudNoticeEntrySchema: z.ZodObject<{
53
+ id: z.ZodString;
54
+ kicker: z.ZodOptional<z.ZodString>;
55
+ title: z.ZodString;
56
+ detail: z.ZodOptional<z.ZodString>;
57
+ cta: z.ZodOptional<z.ZodObject<{
58
+ label: z.ZodString;
59
+ url: z.ZodEffects<z.ZodString, string, string>;
60
+ }, "strip", z.ZodTypeAny, {
61
+ label: string;
62
+ url: string;
63
+ }, {
64
+ label: string;
65
+ url: string;
66
+ }>>;
67
+ } & {
68
+ audience: z.ZodOptional<z.ZodObject<{
69
+ signedIn: z.ZodOptional<z.ZodBoolean>;
70
+ entitled: z.ZodOptional<z.ZodBoolean>;
71
+ }, "strip", z.ZodTypeAny, {
72
+ signedIn?: boolean | undefined;
73
+ entitled?: boolean | undefined;
74
+ }, {
75
+ signedIn?: boolean | undefined;
76
+ entitled?: boolean | undefined;
77
+ }>>;
78
+ /** ISO dates. Shown from `from` (inclusive) until `until` (exclusive). */
79
+ from: z.ZodOptional<z.ZodString>;
80
+ until: z.ZodOptional<z.ZodString>;
81
+ /** Oldest SDK that can show it, e.g. "x.y.z". */
82
+ minSdk: z.ZodOptional<z.ZodString>;
83
+ /** Higher shows first. */
84
+ weight: z.ZodOptional<z.ZodNumber>;
85
+ }, "strip", z.ZodTypeAny, {
86
+ id: string;
87
+ title: string;
88
+ from?: string | undefined;
89
+ detail?: string | undefined;
90
+ until?: string | undefined;
91
+ kicker?: string | undefined;
92
+ cta?: {
93
+ label: string;
94
+ url: string;
95
+ } | undefined;
96
+ audience?: {
97
+ signedIn?: boolean | undefined;
98
+ entitled?: boolean | undefined;
99
+ } | undefined;
100
+ minSdk?: string | undefined;
101
+ weight?: number | undefined;
102
+ }, {
103
+ id: string;
104
+ title: string;
105
+ from?: string | undefined;
106
+ detail?: string | undefined;
107
+ until?: string | undefined;
108
+ kicker?: string | undefined;
109
+ cta?: {
110
+ label: string;
111
+ url: string;
112
+ } | undefined;
113
+ audience?: {
114
+ signedIn?: boolean | undefined;
115
+ entitled?: boolean | undefined;
116
+ } | undefined;
117
+ minSdk?: string | undefined;
118
+ weight?: number | undefined;
119
+ }>;
120
+ export type HudNoticeEntry = z.infer<typeof HudNoticeEntrySchema>;
121
+ /**
122
+ * The entries in a notices file this SDK understands. An unknown version or shape answers nothing,
123
+ * and a bad entry is dropped on its own, so one typo cannot take the whole rail down.
124
+ */
125
+ export declare function parseHudNotices(file: unknown): HudNoticeEntry[];
126
+ /** What is known about this machine when choosing. `undefined` means "not heard yet". */
127
+ export interface NoticeContext {
128
+ signedIn: boolean | undefined;
129
+ entitled: boolean | undefined;
130
+ sdkVersion: string;
131
+ now: number;
132
+ }
133
+ /** The notices this machine should see now, heaviest first, display fields only. */
134
+ export declare function selectNotices(entries: readonly HudNoticeEntry[], ctx: NoticeContext): HudNotice[];
@@ -0,0 +1,124 @@
1
+ /**
2
+ * The notices the HUD's rail shows, edited without a release.
3
+ *
4
+ * The slides used to be compiled into the SDK, so changing a sentence meant shipping a version. The
5
+ * daemon now fetches a small JSON file from our own site, keeps the entries that apply to this
6
+ * machine, and pushes them to the HUD in the impact snapshot. The page never fetches it: the HUD runs
7
+ * inside somebody else's app, whose Content-Security-Policy may forbid the request.
8
+ *
9
+ * Everything here is pure. Fetching and caching live in the daemon; the clock arrives as an argument.
10
+ */
11
+ import { z } from 'zod';
12
+ /** Where the daemon reads the notices from. Overridable for self-hosting and tests. */
13
+ export const HUD_NOTICES_URL = 'https://reticle.sh/hud/notices.v1.json';
14
+ export const NOTICES_FILE_VERSION = 1;
15
+ /** More than this and the rail stops being a rail. */
16
+ const MAX_SHOWN = 5;
17
+ /**
18
+ * Hosts a notice may link to. A notice is text we wrote, but the file is fetched over the network,
19
+ * so its links are held to our own sites rather than trusted: nothing in it can send somebody
20
+ * elsewhere, and no scheme but https can run.
21
+ */
22
+ const LINK_HOSTS = new Set([
23
+ 'reticle.sh',
24
+ 'www.reticle.sh',
25
+ 'app.reticle.sh',
26
+ 'docs.reticle.sh',
27
+ ]);
28
+ const GITHUB_HOST = 'github.com';
29
+ const GITHUB_ORG_PATH = '/reticlehq/';
30
+ function isOurLink(raw) {
31
+ try {
32
+ const url = new URL(raw);
33
+ if ('https:' !== url.protocol)
34
+ return false;
35
+ if (LINK_HOSTS.has(url.hostname))
36
+ return true;
37
+ return GITHUB_HOST === url.hostname && url.pathname.startsWith(GITHUB_ORG_PATH);
38
+ }
39
+ catch {
40
+ return false;
41
+ }
42
+ }
43
+ /** What the HUD renders. Only display fields: the audience rules never leave the daemon. */
44
+ export const HudNoticeSchema = z.object({
45
+ id: z.string().regex(/^[a-z0-9-]{1,48}$/),
46
+ kicker: z.string().min(1).max(40).optional(),
47
+ title: z.string().min(1).max(80),
48
+ detail: z.string().min(1).max(120).optional(),
49
+ cta: z.object({ label: z.string().min(1).max(24), url: z.string().refine(isOurLink) }).optional(),
50
+ });
51
+ /** `true`/`false` match that state only; absent matches anybody. */
52
+ const AudienceSchema = z.object({
53
+ signedIn: z.boolean().optional(),
54
+ entitled: z.boolean().optional(),
55
+ });
56
+ /** One entry in the file: a notice plus who sees it and when. */
57
+ export const HudNoticeEntrySchema = HudNoticeSchema.extend({
58
+ audience: AudienceSchema.optional(),
59
+ /** ISO dates. Shown from `from` (inclusive) until `until` (exclusive). */
60
+ from: z.string().optional(),
61
+ until: z.string().optional(),
62
+ /** Oldest SDK that can show it, e.g. "x.y.z". */
63
+ minSdk: z.string().optional(),
64
+ /** Higher shows first. */
65
+ weight: z.number().optional(),
66
+ });
67
+ /**
68
+ * The entries in a notices file this SDK understands. An unknown version or shape answers nothing,
69
+ * and a bad entry is dropped on its own, so one typo cannot take the whole rail down.
70
+ */
71
+ export function parseHudNotices(file) {
72
+ if ('object' !== typeof file || null === file)
73
+ return [];
74
+ const record = file;
75
+ if (NOTICES_FILE_VERSION !== record['version'] || !Array.isArray(record['notices']))
76
+ return [];
77
+ const entries = [];
78
+ for (const raw of record['notices']) {
79
+ const parsed = HudNoticeEntrySchema.safeParse(raw);
80
+ if (parsed.success)
81
+ entries.push(parsed.data);
82
+ }
83
+ return entries;
84
+ }
85
+ function matches(want, have) {
86
+ return want === undefined || want === have;
87
+ }
88
+ /** Numeric dotted-version compare: `a >= b`. A part that is not a number counts as 0. */
89
+ function versionAtLeast(a, b) {
90
+ const pa = a.split('.').map((p) => Number.parseInt(p, 10) || 0);
91
+ const pb = b.split('.').map((p) => Number.parseInt(p, 10) || 0);
92
+ for (let i = 0; i < Math.max(pa.length, pb.length); i += 1) {
93
+ const d = (pa[i] ?? 0) - (pb[i] ?? 0);
94
+ if (0 !== d)
95
+ return d > 0;
96
+ }
97
+ return true;
98
+ }
99
+ function inWindow(entry, now) {
100
+ const from = entry.from === undefined ? Number.NaN : Date.parse(entry.from);
101
+ const until = entry.until === undefined ? Number.NaN : Date.parse(entry.until);
102
+ if (!Number.isNaN(from) && now < from)
103
+ return false;
104
+ if (!Number.isNaN(until) && now >= until)
105
+ return false;
106
+ return true;
107
+ }
108
+ /** The notices this machine should see now, heaviest first, display fields only. */
109
+ export function selectNotices(entries, ctx) {
110
+ return entries
111
+ .filter((e) => matches(e.audience?.signedIn, ctx.signedIn) &&
112
+ matches(e.audience?.entitled, ctx.entitled) &&
113
+ inWindow(e, ctx.now) &&
114
+ (e.minSdk === undefined || versionAtLeast(ctx.sdkVersion, e.minSdk)))
115
+ .sort((a, b) => (b.weight ?? 0) - (a.weight ?? 0))
116
+ .slice(0, MAX_SHOWN)
117
+ .map(({ id, kicker, title, detail, cta }) => ({
118
+ id,
119
+ ...(kicker === undefined ? {} : { kicker }),
120
+ title,
121
+ ...(detail === undefined ? {} : { detail }),
122
+ ...(cta === undefined ? {} : { cta }),
123
+ }));
124
+ }