@reticlehq/core 2.14.0 → 3.1.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.
- package/dist/{artifacts-entry.d.ts → artifacts/artifacts-entry.d.ts} +7 -7
- package/dist/{artifacts-entry.js → artifacts/artifacts-entry.js} +7 -7
- package/dist/artifacts/flow-composition.d.ts +30 -0
- package/dist/artifacts/flow-composition.js +19 -0
- package/dist/{flow-constants.d.ts → artifacts/flow-constants.d.ts} +89 -3
- package/dist/{flow-constants.js → artifacts/flow-constants.js} +95 -4
- package/dist/artifacts/flow-mutation-target.d.ts +39 -0
- package/dist/artifacts/flow-mutation-target.js +89 -0
- package/dist/artifacts/flow-order.d.ts +30 -0
- package/dist/artifacts/flow-order.js +49 -0
- package/dist/artifacts/flow-select.d.ts +56 -0
- package/dist/artifacts/flow-select.js +56 -0
- package/dist/artifacts/flow-step-tool.d.ts +31 -0
- package/dist/artifacts/flow-step-tool.js +31 -0
- package/dist/artifacts/flow-types.d.ts +3736 -0
- package/dist/artifacts/flow-types.js +463 -0
- package/dist/artifacts/flow-unreached.d.ts +12 -0
- package/dist/artifacts/flow-unreached.js +24 -0
- package/dist/{impact.d.ts → artifacts/impact.d.ts} +119 -103
- package/dist/{impact.js → artifacts/impact.js} +14 -5
- package/dist/{journal.d.ts → artifacts/journal.d.ts} +51 -7
- package/dist/{journal.js → artifacts/journal.js} +38 -2
- package/dist/artifacts/step-effect.d.ts +29 -0
- package/dist/artifacts/step-effect.js +28 -0
- package/dist/hooks/hook-events.d.ts +311 -0
- package/dist/hooks/hook-events.js +127 -0
- package/dist/hooks/hooks-entry.d.ts +9 -0
- package/dist/hooks/hooks-entry.js +9 -0
- package/dist/{brand.d.ts → identity/brand.d.ts} +7 -0
- package/dist/{contract-fingerprint.d.ts → identity/contract-fingerprint.d.ts} +21 -3
- package/dist/{contract-fingerprint.js → identity/contract-fingerprint.js} +22 -4
- package/dist/{document-identity.d.ts → identity/document-identity.d.ts} +4 -5
- package/dist/{document-identity.js → identity/document-identity.js} +4 -5
- package/dist/{source-constants.d.ts → identity/source-constants.d.ts} +4 -4
- package/dist/{source-constants.js → identity/source-constants.js} +4 -4
- package/dist/index.d.ts +56 -43
- package/dist/index.js +65 -45
- package/dist/onboarding.d.ts +114 -0
- package/dist/onboarding.js +141 -0
- package/dist/realm/registry.d.ts +212 -0
- package/dist/realm/registry.js +302 -0
- package/dist/{dev-server-registry.d.ts → registry/dev-server-registry.d.ts} +6 -7
- package/dist/{dev-server-registry.js → registry/dev-server-registry.js} +28 -19
- package/dist/{project-registry.d.ts → registry/project-registry.d.ts} +5 -5
- package/dist/{project-registry.js → registry/project-registry.js} +5 -5
- package/dist/schema/command-name.json +31 -0
- package/dist/schema/event-payloads.json +791 -0
- package/dist/schema/hello-message.json +70 -2
- package/dist/schema/reticle-message.json +70 -2
- package/dist/telemetry-entry.d.ts +1 -1
- package/dist/telemetry-entry.js +1 -1
- package/dist/telemetry-feedback.d.ts +15 -16
- package/dist/telemetry-feedback.js +11 -12
- package/dist/telemetry-license.d.ts +1 -1
- package/dist/telemetry-license.js +1 -1
- package/dist/telemetry-refusal.d.ts +11 -11
- package/dist/telemetry-refusal.js +7 -8
- package/dist/telemetry-session.d.ts +51 -59
- package/dist/telemetry-session.js +47 -55
- package/dist/telemetry.d.ts +243 -214
- package/dist/telemetry.js +83 -98
- package/dist/tour-entry.d.ts +10 -0
- package/dist/tour-entry.js +10 -0
- package/dist/tour.d.ts +125 -0
- package/dist/tour.js +165 -0
- package/dist/{consequence.d.ts → verdict/consequence.d.ts} +32 -15
- package/dist/{consequence.js → verdict/consequence.js} +9 -31
- package/dist/{finding-fingerprint.js → verdict/finding-fingerprint.js} +1 -1
- package/dist/{findings.d.ts → verdict/findings.d.ts} +86 -39
- package/dist/{findings.js → verdict/findings.js} +103 -49
- package/dist/{instrumentation-gap.d.ts → verdict/instrumentation-gap.d.ts} +7 -14
- package/dist/{instrumentation-gap.js → verdict/instrumentation-gap.js} +7 -15
- package/dist/{intent.d.ts → verdict/intent.d.ts} +35 -46
- package/dist/{intent.js → verdict/intent.js} +11 -22
- package/dist/verdict/revision.d.ts +44 -0
- package/dist/verdict/revision.js +53 -0
- package/dist/{run-context.d.ts → verdict/run-context.d.ts} +13 -34
- package/dist/{run-context.js → verdict/run-context.js} +15 -36
- package/dist/{security.js → verdict/security.js} +12 -21
- package/dist/{verification-run.d.ts → verdict/verification-run.d.ts} +381 -105
- package/dist/{verification-run.js → verdict/verification-run.js} +157 -21
- package/dist/{verified-constants.d.ts → verdict/verified-constants.d.ts} +25 -13
- package/dist/{verified-constants.js → verdict/verified-constants.js} +25 -13
- package/dist/{verify-progress.d.ts → verdict/verify-progress.d.ts} +18 -22
- package/dist/{verify-progress.js → verdict/verify-progress.js} +6 -10
- package/dist/wire/channel.d.ts +46 -0
- package/dist/wire/channel.js +95 -0
- package/dist/{constants.d.ts → wire/constants/constants.d.ts} +91 -28
- package/dist/{constants.js → wire/constants/constants.js} +105 -28
- package/dist/{session-constants.d.ts → wire/constants/session-constants.d.ts} +9 -2
- package/dist/{session-constants.js → wire/constants/session-constants.js} +9 -2
- package/dist/{desktop-contract.js → wire/desktop-contract.js} +1 -1
- package/dist/{event-classification.js → wire/event-classification.js} +1 -1
- package/dist/{event-payloads.d.ts → wire/event-payloads.d.ts} +68 -13
- package/dist/{event-payloads.js → wire/event-payloads.js} +21 -3
- package/dist/{event-priority.d.ts → wire/event-priority.d.ts} +1 -4
- package/dist/{event-priority.js → wire/event-priority.js} +2 -5
- package/dist/{global-press.js → wire/global-press.js} +1 -1
- package/dist/{messages.d.ts → wire/messages.d.ts} +239 -48
- package/dist/{messages.js → wire/messages.js} +68 -5
- package/dist/wire/narrow.d.ts +39 -0
- package/dist/wire/narrow.js +45 -0
- package/dist/{net.d.ts → wire/net.d.ts} +12 -13
- package/dist/{net.js → wire/net.js} +12 -13
- package/dist/wire/platform.d.ts +37 -0
- package/dist/wire/platform.js +36 -0
- package/dist/{redaction.js → wire/redaction.js} +12 -12
- package/dist/wire/tool-names.d.ts +133 -0
- package/dist/wire/tool-names.js +142 -0
- package/dist/{toon.js → wire/toon.js} +1 -1
- package/dist/{types.d.ts → wire/types.d.ts} +77 -76
- package/dist/{types.js → wire/types.js} +4 -3
- package/dist/{no-session-reason.d.ts → words/no-session-reason.d.ts} +7 -3
- package/dist/{no-session-reason.js → words/no-session-reason.js} +7 -3
- package/dist/{notices.d.ts → words/notices.d.ts} +8 -12
- package/dist/{notices.js → words/notices.js} +8 -12
- package/package.json +16 -7
- package/dist/flow-types.d.ts +0 -1711
- package/dist/flow-types.js +0 -247
- package/dist/{impact-savings.d.ts → artifacts/impact-savings.d.ts} +0 -0
- package/dist/{impact-savings.js → artifacts/impact-savings.js} +0 -0
- package/dist/{brand.js → identity/brand.js} +0 -0
- package/dist/{edit-epoch.d.ts → identity/edit-epoch.d.ts} +0 -0
- package/dist/{edit-epoch.js → identity/edit-epoch.js} +0 -0
- package/dist/{project-id.d.ts → identity/project-id.d.ts} +0 -0
- package/dist/{project-id.js → identity/project-id.js} +0 -0
- package/dist/{daemon-registry.d.ts → registry/daemon-registry.d.ts} +0 -0
- package/dist/{daemon-registry.js → registry/daemon-registry.js} +0 -0
- package/dist/{finding-fingerprint.d.ts → verdict/finding-fingerprint.d.ts} +0 -0
- package/dist/{security.d.ts → verdict/security.d.ts} +0 -0
- package/dist/{desktop-contract.d.ts → wire/desktop-contract.d.ts} +0 -0
- package/dist/{event-classification.d.ts → wire/event-classification.d.ts} +0 -0
- package/dist/{global-press.d.ts → wire/global-press.d.ts} +0 -0
- package/dist/{redaction.d.ts → wire/redaction.d.ts} +0 -0
- package/dist/{state-select.d.ts → wire/state-select.d.ts} +0 -0
- package/dist/{state-select.js → wire/state-select.js} +0 -0
- package/dist/{toon.d.ts → wire/toon.d.ts} +0 -0
- package/dist/{browser-misdirect.d.ts → words/browser-misdirect.d.ts} +0 -0
- package/dist/{browser-misdirect.js → words/browser-misdirect.js} +0 -0
- package/dist/{unreachable-notice.d.ts → words/unreachable-notice.d.ts} +0 -0
- package/dist/{unreachable-notice.js → words/unreachable-notice.js} +0 -0
- package/dist/{upgrade.d.ts → words/upgrade.d.ts} +2 -2
- /package/dist/{upgrade.js → words/upgrade.js} +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The three phases between "never heard of Reticle" and "it produced a verdict on my app".
|
|
4
|
+
*
|
|
5
|
+
* Named as one vocabulary because the question they exist to answer is one question: WHERE do people
|
|
6
|
+
* stop. Prior measurement put the break at instrumentation — user retention strong, verification
|
|
7
|
+
* retention far weaker — and `init_completed` cannot see that, because it fires when the files are
|
|
8
|
+
* written and the story continues for minutes afterwards.
|
|
9
|
+
*/
|
|
10
|
+
export const OnboardingPhase = {
|
|
11
|
+
/** Getting the CLI onto the machine and the MCP registered with the agents that are there. */
|
|
12
|
+
INSTALL: 'install',
|
|
13
|
+
/** Being shown what Reticle is and how it is driven, before being asked to drive anything. */
|
|
14
|
+
ONBOARD: 'onboard',
|
|
15
|
+
/** Instrumenting a real project and driving it until something is actually proved. */
|
|
16
|
+
FIRST_RUN: 'first_run',
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* What became of one step.
|
|
20
|
+
*
|
|
21
|
+
* `ABANDONED` is the one that earns its place: a step that is STARTED and never resolved is
|
|
22
|
+
* indistinguishable from one that was never reached, and both read as "we never got there" in a
|
|
23
|
+
* funnel. Saying a person walked away from a step we know they began is a different fact from
|
|
24
|
+
* saying the step failed, and only one of them is our bug.
|
|
25
|
+
*/
|
|
26
|
+
export const OnboardingStepStatus = {
|
|
27
|
+
STARTED: 'started',
|
|
28
|
+
COMPLETED: 'completed',
|
|
29
|
+
FAILED: 'failed',
|
|
30
|
+
ABANDONED: 'abandoned',
|
|
31
|
+
/** Nothing to do — already installed, already instrumented. Not a loss, and not a win either. */
|
|
32
|
+
SKIPPED: 'skipped',
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The steps, per phase, as ONE table.
|
|
36
|
+
*
|
|
37
|
+
* Written down here rather than as string literals at each emit site, for the reason rule 4 exists:
|
|
38
|
+
* a vocabulary copied into the place that uses it drifts from the place that reads it, and the
|
|
39
|
+
* reader is a dashboard nobody re-checks. A step that is renamed here is renamed everywhere or it
|
|
40
|
+
* does not compile.
|
|
41
|
+
*
|
|
42
|
+
* The ORDER matters and is the funnel: each phase's steps are listed in the sequence they occur, so
|
|
43
|
+
* a drop-off curve is this array with counts against it.
|
|
44
|
+
*/
|
|
45
|
+
export const OnboardingSteps = {
|
|
46
|
+
[OnboardingPhase.INSTALL]: [
|
|
47
|
+
/** The one-line installer ran at all — the first thing we can possibly know about someone. */
|
|
48
|
+
'script_started',
|
|
49
|
+
/** A usable runtime was found or provisioned. The commonest reason an install dies on a clean box. */
|
|
50
|
+
'runtime_ready',
|
|
51
|
+
'cli_installed',
|
|
52
|
+
/** Which coding agents are on this machine. Zero is a real answer and not a failure. */
|
|
53
|
+
'agents_detected',
|
|
54
|
+
/** The MCP server registered with them. The step most likely to fail silently — see InitOutcome. */
|
|
55
|
+
'mcp_registered',
|
|
56
|
+
],
|
|
57
|
+
[OnboardingPhase.ONBOARD]: [
|
|
58
|
+
'tour_started',
|
|
59
|
+
/** Shown what Reticle is FOR, before being asked to run anything. */
|
|
60
|
+
'concept_shown',
|
|
61
|
+
/** The first look at a real page. */
|
|
62
|
+
'first_look',
|
|
63
|
+
/** The first action driven through Reticle. */
|
|
64
|
+
'first_act',
|
|
65
|
+
/**
|
|
66
|
+
* The first VERDICT. The tour ends here on purpose: a tour that ends at "you can see the page"
|
|
67
|
+
* has taught the least valuable half, and an agent that learns only to look reports that it
|
|
68
|
+
* looked. Same reasoning as `tutorial.ts`, which already ends here.
|
|
69
|
+
*/
|
|
70
|
+
'first_verdict',
|
|
71
|
+
],
|
|
72
|
+
[OnboardingPhase.FIRST_RUN]: [
|
|
73
|
+
'project_detected',
|
|
74
|
+
/** The SDK is in the bundle. Files written is NOT this — see `app_instrumented`. */
|
|
75
|
+
'instrumented',
|
|
76
|
+
/** A page loaded and the SDK dialled the bridge. The half of the install nothing else can see. */
|
|
77
|
+
'app_connected',
|
|
78
|
+
/** Something was driven. */
|
|
79
|
+
'driven',
|
|
80
|
+
/** A flow was recorded from that drive, which is what makes the SECOND run cheap. */
|
|
81
|
+
'flow_recorded',
|
|
82
|
+
/**
|
|
83
|
+
* A verdict was produced on the user's own app. THE conversion event.
|
|
84
|
+
*
|
|
85
|
+
* Everything before this is setup that proved nothing. Prior measurement put the break here —
|
|
86
|
+
* strong user retention, far weaker verification retention — and no existing event marks it,
|
|
87
|
+
* because `init_completed` fires when files are written and this is minutes later.
|
|
88
|
+
*/
|
|
89
|
+
'verdict_produced',
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* ONE event for every step of every phase, rather than an event name per step.
|
|
94
|
+
*
|
|
95
|
+
* The kinds list is already at the size where a reader has to scan it, and a name per step would
|
|
96
|
+
* mean every funnel query naming the steps it spans — so moving, renaming or inserting a step
|
|
97
|
+
* silently breaks the queries that were watching it. A phase + step pair keeps the funnel a GROUP BY
|
|
98
|
+
* instead of a union, and a new step arrives in the existing chart rather than beside it.
|
|
99
|
+
*
|
|
100
|
+
* `step` is one of our own names and never a path, a URL or anything the user typed — rule 3. The
|
|
101
|
+
* schema caps it for the same reason every other free-ish field here is capped.
|
|
102
|
+
*/
|
|
103
|
+
/**
|
|
104
|
+
* Every step name, flattened — the closed set `step` is allowed to be.
|
|
105
|
+
*
|
|
106
|
+
* Derived from `OnboardingSteps` rather than retyped, so a step added there is accepted here on the
|
|
107
|
+
* same edit and a step renamed cannot be accepted under both spellings.
|
|
108
|
+
*/
|
|
109
|
+
const ALL_ONBOARDING_STEPS = Object.values(OnboardingSteps).flatMap((steps) => [...steps]);
|
|
110
|
+
export const OnboardingStepSchema = z.object({
|
|
111
|
+
phase: z.nativeEnum(OnboardingPhase),
|
|
112
|
+
/**
|
|
113
|
+
* Our name for the step, and ONLY one of ours.
|
|
114
|
+
*
|
|
115
|
+
* This was `z.string().max(48)`, with a comment promising it was never user text — and a cap is
|
|
116
|
+
* not a promise. `/Users/someone/secret/project` is 28 characters and validated cleanly, which is
|
|
117
|
+
* a rule-3 leak (names, never values) reaching the wire from the one payload a person can edit:
|
|
118
|
+
* the installer's breadcrumb file, on disk, in their own home directory.
|
|
119
|
+
*
|
|
120
|
+
* A closed set makes the promise enforceable instead of aspirational. Found by the test written
|
|
121
|
+
* for that file, not by reading this line.
|
|
122
|
+
*/
|
|
123
|
+
step: z.enum(ALL_ONBOARDING_STEPS),
|
|
124
|
+
status: z.nativeEnum(OnboardingStepStatus),
|
|
125
|
+
/**
|
|
126
|
+
* Milliseconds this step took. Absent when the step is instantaneous or not timed — absent means
|
|
127
|
+
* NOT MEASURED, never zero, because a zero would pull every average toward a duration nobody had.
|
|
128
|
+
*/
|
|
129
|
+
elapsedMs: z.number().int().nonnegative().optional(),
|
|
130
|
+
/** Classified cause when it failed — our vocabulary, never a raw error or a path. */
|
|
131
|
+
reason: z.string().max(64).optional(),
|
|
132
|
+
/** The stack it was detected on, so a phase that only fails on one framework is visible. */
|
|
133
|
+
stack: z.string().max(64).optional(),
|
|
134
|
+
/**
|
|
135
|
+
* True when nobody was asked anything — the zero-human-input path an agent takes from a link.
|
|
136
|
+
*
|
|
137
|
+
* Recorded because the two audiences fail differently and a funnel that mixes them explains
|
|
138
|
+
* neither: a human abandons a step, an agent's run exits.
|
|
139
|
+
*/
|
|
140
|
+
unattended: z.boolean().optional(),
|
|
141
|
+
});
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One record per realm, in a table the compiler refuses to leave a hole in.
|
|
3
|
+
*
|
|
4
|
+
* NOT the protocol's `Realm`. That is an abstract class in `open-verification` describing what
|
|
5
|
+
* a realm can DO -- eight questions an implementation answers. This describes what a realm IS LIKE:
|
|
6
|
+
* four fixed traits the rest of the codebase branches on. It is a lookup table, not a specification.
|
|
7
|
+
*
|
|
8
|
+
* A realm is the kind of place an app runs: a browser tab, an Electron window, a Tauri window. The
|
|
9
|
+
* four traits are whether it is a desktop shell, whether it draws with WebKit, whether its coverage
|
|
10
|
+
* warnings are its own, and whether its visual baselines get their own directory.
|
|
11
|
+
*
|
|
12
|
+
* Adding a realm is one row. `Record<AppRuntime, RealmTraits>` means leaving it out is a COMPILE
|
|
13
|
+
* error rather than a silent default — a scattered `if` gives a new realm the *web* answer, which
|
|
14
|
+
* is the answer most likely to look plausible and be wrong. That is the whole reason this is a
|
|
15
|
+
* table and not a lookup function with a fallback.
|
|
16
|
+
*
|
|
17
|
+
* Deliberately NOT here: anything a realm DOES rather than is. Which screenshot backend to call,
|
|
18
|
+
* how to patch a build config, what a connect snippet looks like — those are code and live with the
|
|
19
|
+
* code that runs them. This table holds facts you could write on an index card.
|
|
20
|
+
*/
|
|
21
|
+
import { type DeterminismProfile, Surface, type SubjectRef } from 'open-verification';
|
|
22
|
+
import { AppRuntime } from '../telemetry-feedback.js';
|
|
23
|
+
import { PlatformProfile } from '../wire/platform.js';
|
|
24
|
+
/** What Reticle needs to know about a realm that it cannot work out by looking. */
|
|
25
|
+
export interface RealmTraits {
|
|
26
|
+
/**
|
|
27
|
+
* Which of the protocol's surfaces this realm IS.
|
|
28
|
+
*
|
|
29
|
+
* Declared rather than derived. `surfaceOf` used to ask `isDesktopShell ? DESKTOP : WEB`, so of
|
|
30
|
+
* the six surfaces the protocol names — web, desktop, mobile, service, game, device — only two
|
|
31
|
+
* could ever be returned, while `DETERMINISM_BY_SURFACE` already carried a correct row for all
|
|
32
|
+
* six. A mobile, service, game or device realm had no way to be NAMED even though the rules
|
|
33
|
+
* governing it were written and waiting.
|
|
34
|
+
*
|
|
35
|
+
* A boolean answers two questions; a surface is not a question with two answers. With this here,
|
|
36
|
+
* adding a domain is a row in the table below rather than an edit to a branch — and the branch is
|
|
37
|
+
* the thing that would have answered `web` to everything it had not heard of.
|
|
38
|
+
*/
|
|
39
|
+
readonly surface: Surface;
|
|
40
|
+
/**
|
|
41
|
+
* Does the app run in a window of its own, rather than a browser tab?
|
|
42
|
+
*
|
|
43
|
+
* Decides whether advice about dev servers and tabs applies, and whether desktop-only coverage
|
|
44
|
+
* warnings are worth showing.
|
|
45
|
+
*/
|
|
46
|
+
readonly isDesktopShell: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Does it draw with WebKit?
|
|
49
|
+
*
|
|
50
|
+
* A hidden WebKit window stops executing while still answering screenshots, so a command that
|
|
51
|
+
* times out there needs different advice: park the window off-screen rather than hiding it.
|
|
52
|
+
*/
|
|
53
|
+
readonly usesWebKit: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Does it raise coverage warnings that make no sense for any other realm?
|
|
56
|
+
*
|
|
57
|
+
* Only Electron does, and this is narrower than "is a desktop shell", which is what it looks like
|
|
58
|
+
* at first glance. The warnings in question are about IPC going unobserved, and they exist because
|
|
59
|
+
* an Electron renderer needs a preload script to see its own IPC: without one, everything is
|
|
60
|
+
* unobserved and nothing says so.
|
|
61
|
+
*
|
|
62
|
+
* Tauri is a desktop shell and raises none of them, because its `invoke` travels as an ordinary
|
|
63
|
+
* fetch to a custom protocol and is already visible. A browser tab has no IPC at all.
|
|
64
|
+
*
|
|
65
|
+
* Reported for the wrong realm, a missing-preload warning reads as an un-instrumented app -- which
|
|
66
|
+
* is how a plain Vite page once looked like a broken Electron install.
|
|
67
|
+
*/
|
|
68
|
+
readonly ownsCoverageKinds: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Do its visual baselines live in a directory of their own?
|
|
71
|
+
*
|
|
72
|
+
* The web is the default and keeps the top-level directory it has always had; anything else is
|
|
73
|
+
* filed under its own name, so two realms of one project cannot overwrite each other's pictures.
|
|
74
|
+
*/
|
|
75
|
+
readonly hasOwnBaselineDirectory: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* How a project on disk says it is this realm, or `undefined` when nothing marks it.
|
|
78
|
+
*
|
|
79
|
+
* A fact you could write on an index card, which is why it belongs here: a Tauri project has a
|
|
80
|
+
* `src-tauri/tauri.conf.json`, an Electron project depends on `electron`. What to DO once you know
|
|
81
|
+
* stays where it is; this only answers which realm you are looking at.
|
|
82
|
+
*
|
|
83
|
+
* The web has no marker, and that is the point rather than an omission. A web project is a project
|
|
84
|
+
* with none of the others' markers, so giving it one would make every project match two realms.
|
|
85
|
+
*/
|
|
86
|
+
readonly projectMarker?: {
|
|
87
|
+
readonly file: string;
|
|
88
|
+
} | {
|
|
89
|
+
readonly dependency: string;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Every realm Reticle knows about.
|
|
94
|
+
*
|
|
95
|
+
* Adding one is a row here plus a value on `AppRuntime`. The compiler will not let you add the value
|
|
96
|
+
* without the row, which is the point: the alternative is a lookup that quietly answers "web".
|
|
97
|
+
*/
|
|
98
|
+
export declare const REALMS: Record<AppRuntime, RealmTraits>;
|
|
99
|
+
/**
|
|
100
|
+
* Is this a realm this build knows about?
|
|
101
|
+
*
|
|
102
|
+
* Asked where a runtime arrives from the page and has to be accepted or ignored. Derived from the
|
|
103
|
+
* table rather than listed again, because a list repeated somewhere else is a list that gets one
|
|
104
|
+
* entry behind: a realm missing from it is not rejected loudly, its name is simply dropped, and every
|
|
105
|
+
* later question about that session answers as though the page never said what it was.
|
|
106
|
+
*
|
|
107
|
+
* Written as a type guard so the caller gets the narrowing the hand-written chain of comparisons gave
|
|
108
|
+
* it for free. Without that, replacing the chain would have widened a field back to a plain string,
|
|
109
|
+
* and the compiler would stop catching a runtime this package does not know.
|
|
110
|
+
*/
|
|
111
|
+
export declare function isKnownRealm(runtime: string | undefined): runtime is AppRuntime;
|
|
112
|
+
/**
|
|
113
|
+
* Teach this process about a realm it does not ship.
|
|
114
|
+
*
|
|
115
|
+
* The `x-` prefix is required for two reasons that are both about the future: a third-party name
|
|
116
|
+
* can never collide with one this package later ships, and a reader can tell at a glance which
|
|
117
|
+
* realms this package ships and which a host added. It is the same convention `ChannelIdSchema` already
|
|
118
|
+
* enforces for channels.
|
|
119
|
+
*
|
|
120
|
+
* Throws rather than returning a result. A realm that failed to register would answer `web` to
|
|
121
|
+
* everything — the most plausible-looking wrong answer available — and the caller is a host at
|
|
122
|
+
* startup, where a throw is read immediately and a silent miss is not read at all.
|
|
123
|
+
*
|
|
124
|
+
* CEILING, invisible from the signature: there is no host seam in the daemon. `reticle serve`
|
|
125
|
+
* imports no user module, so nothing outside this repository has a moment in which to call this,
|
|
126
|
+
* and every realm Reticle ships is a row in `REALMS` rather than a registration. Adding a realm
|
|
127
|
+
* today means a change to `@reticlehq/core`.
|
|
128
|
+
*/
|
|
129
|
+
export declare function registerRealm(runtime: string, traits: RealmTraits): void;
|
|
130
|
+
/** Every runtime this process understands: the built-ins, plus whatever a host registered. */
|
|
131
|
+
export declare function knownRuntimes(): string[];
|
|
132
|
+
/** Forget every registered realm. For tests and for a host rebuilding its own registry. */
|
|
133
|
+
export declare function resetRegisteredRealms(): void;
|
|
134
|
+
export declare function realmOf(runtime: string | undefined): RealmTraits;
|
|
135
|
+
/**
|
|
136
|
+
* The protocol's surface for a realm.
|
|
137
|
+
*
|
|
138
|
+
* Reads `isDesktopShell` rather than testing the runtime again, which is the whole reason this
|
|
139
|
+
* table exists: a third place branching on `electron || tauri` is a third place to forget a realm,
|
|
140
|
+
* and the answer it would forget into is the web one -- the answer most likely to look plausible
|
|
141
|
+
* and be wrong.
|
|
142
|
+
*
|
|
143
|
+
* An unknown or absent runtime answers `web`, like everything else here. For a surface that IS an
|
|
144
|
+
* assumption rather than a fact: a `SubjectRef` requires one and the handshake carries no other
|
|
145
|
+
* tell, so the error is a desktop app identified as a page, which understates the subject rather
|
|
146
|
+
* than misdescribing it.
|
|
147
|
+
*/
|
|
148
|
+
export declare function surfaceOf(runtime: string | undefined): Surface;
|
|
149
|
+
/**
|
|
150
|
+
* What a subject's identity is read from.
|
|
151
|
+
*
|
|
152
|
+
* Structural rather than a `Session`, so the identity can be taken where a full session is not in
|
|
153
|
+
* hand -- the run artifact is assembled at teardown from a narrowed view of one. Naming it is the
|
|
154
|
+
* point: there is exactly ONE definition of what identifies a subject, and a second place
|
|
155
|
+
* computing `surface` and `instance` its own way is how two artifacts about the same session come
|
|
156
|
+
* to disagree about what was verified.
|
|
157
|
+
*/
|
|
158
|
+
export interface SubjectFacts {
|
|
159
|
+
readonly id: string;
|
|
160
|
+
readonly url: string;
|
|
161
|
+
readonly runtime?: string | undefined;
|
|
162
|
+
readonly currentDocumentId?: string | undefined;
|
|
163
|
+
readonly currentEditEpoch?: number | undefined;
|
|
164
|
+
}
|
|
165
|
+
/** The protocol's identity for a connected subject. */
|
|
166
|
+
export declare function subjectOf(facts: SubjectFacts): SubjectRef;
|
|
167
|
+
/**
|
|
168
|
+
* Which realm a project on disk is, judged only by its markers.
|
|
169
|
+
*
|
|
170
|
+
* A project can carry more than one marker, so precedence has to be decided rather than inherited
|
|
171
|
+
* from whatever order the table happens to be written in.
|
|
172
|
+
*
|
|
173
|
+
* A CONFIG FILE beats a DEPENDENCY. A file like `src-tauri/tauri.conf.json` exists because somebody
|
|
174
|
+
* set this project up to be that kind of app; a dependency can be transitive, vestigial, or left
|
|
175
|
+
* behind by something that was tried and abandoned. The stronger claim wins, which is also what the
|
|
176
|
+
* hand-written checks this replaces already did.
|
|
177
|
+
*
|
|
178
|
+
* Returns undefined rather than the web when nothing matches. "This is a plain web project" and "I
|
|
179
|
+
* could not tell" are the same observation here, and naming it `web` would state more than was seen.
|
|
180
|
+
*/
|
|
181
|
+
export declare function realmOfProject(hasFile: (path: string) => boolean, hasDependency: (name: string) => boolean): AppRuntime | undefined;
|
|
182
|
+
/** The kind of surface a shell presents, or undefined if we have never heard of the shell. */
|
|
183
|
+
export declare function profileOfRuntime(runtime: string | undefined): PlatformProfile | undefined;
|
|
184
|
+
/**
|
|
185
|
+
* How each kind of surface may be DRIVEN.
|
|
186
|
+
*
|
|
187
|
+
* "Resume is nearly free, just re-run the prefix at 27 ms a step" is true of a browser and FALSE
|
|
188
|
+
* AND DANGEROUS on hardware, where re-driving a prefix moves a physical
|
|
189
|
+
* arm, costs real time, and may not be idempotent. The protocol already decides this from a declared
|
|
190
|
+
* profile via `resumeStrategy`; what was missing was anywhere for server code to GET a profile,
|
|
191
|
+
* because a `Realm` object is constructed only by the conformance client and the code that resumes a
|
|
192
|
+
* replay has no realm to ask.
|
|
193
|
+
*
|
|
194
|
+
* A determinism profile is a property of the KIND of subject, not of one realm instance, so it lives
|
|
195
|
+
* here beside the other facts about kinds. That is what makes the rule enforceable on the path that
|
|
196
|
+
* actually resumes, today, rather than after some future wiring.
|
|
197
|
+
*
|
|
198
|
+
* Every surface the vocabulary names is declared. A missing entry would fall through to the web
|
|
199
|
+
* answer, and the web answer is the permissive one — which is the wrong direction to be wrong in
|
|
200
|
+
* when the question is "may I silently re-send this payment".
|
|
201
|
+
*/
|
|
202
|
+
export declare const DETERMINISM_BY_SURFACE: Record<Surface, DeterminismProfile>;
|
|
203
|
+
/** The declared profile for a surface. */
|
|
204
|
+
export declare function determinismFor(surface: Surface): DeterminismProfile;
|
|
205
|
+
/**
|
|
206
|
+
* May a resume re-drive the steps before the one asked for?
|
|
207
|
+
*
|
|
208
|
+
* The one question the resume path has to ask before it silently repeats somebody's actions. Derived
|
|
209
|
+
* through the protocol's own `resumeStrategy` rather than by reading `replayPrefix` here, so this
|
|
210
|
+
* cannot drift from the rule the specification publishes.
|
|
211
|
+
*/
|
|
212
|
+
export declare function mayResumeByReplayingPrefix(surface: Surface): boolean;
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One record per realm, in a table the compiler refuses to leave a hole in.
|
|
3
|
+
*
|
|
4
|
+
* NOT the protocol's `Realm`. That is an abstract class in `open-verification` describing what
|
|
5
|
+
* a realm can DO -- eight questions an implementation answers. This describes what a realm IS LIKE:
|
|
6
|
+
* four fixed traits the rest of the codebase branches on. It is a lookup table, not a specification.
|
|
7
|
+
*
|
|
8
|
+
* A realm is the kind of place an app runs: a browser tab, an Electron window, a Tauri window. The
|
|
9
|
+
* four traits are whether it is a desktop shell, whether it draws with WebKit, whether its coverage
|
|
10
|
+
* warnings are its own, and whether its visual baselines get their own directory.
|
|
11
|
+
*
|
|
12
|
+
* Adding a realm is one row. `Record<AppRuntime, RealmTraits>` means leaving it out is a COMPILE
|
|
13
|
+
* error rather than a silent default — a scattered `if` gives a new realm the *web* answer, which
|
|
14
|
+
* is the answer most likely to look plausible and be wrong. That is the whole reason this is a
|
|
15
|
+
* table and not a lookup function with a fallback.
|
|
16
|
+
*
|
|
17
|
+
* Deliberately NOT here: anything a realm DOES rather than is. Which screenshot backend to call,
|
|
18
|
+
* how to patch a build config, what a connect snippet looks like — those are code and live with the
|
|
19
|
+
* code that runs them. This table holds facts you could write on an index card.
|
|
20
|
+
*/
|
|
21
|
+
import { ResumeStrategy, resumeStrategy, Surface, } from 'open-verification';
|
|
22
|
+
import { AppRuntime } from '../telemetry-feedback.js';
|
|
23
|
+
import { PlatformProfile } from '../wire/platform.js';
|
|
24
|
+
/**
|
|
25
|
+
* Every realm Reticle knows about.
|
|
26
|
+
*
|
|
27
|
+
* Adding one is a row here plus a value on `AppRuntime`. The compiler will not let you add the value
|
|
28
|
+
* without the row, which is the point: the alternative is a lookup that quietly answers "web".
|
|
29
|
+
*/
|
|
30
|
+
export const REALMS = {
|
|
31
|
+
[AppRuntime.WEB]: {
|
|
32
|
+
surface: Surface.WEB,
|
|
33
|
+
isDesktopShell: false,
|
|
34
|
+
usesWebKit: false,
|
|
35
|
+
ownsCoverageKinds: false,
|
|
36
|
+
hasOwnBaselineDirectory: false,
|
|
37
|
+
},
|
|
38
|
+
[AppRuntime.ELECTRON]: {
|
|
39
|
+
surface: Surface.DESKTOP,
|
|
40
|
+
isDesktopShell: true,
|
|
41
|
+
// No config file of its own: an Electron app is one that depends on Electron.
|
|
42
|
+
projectMarker: { dependency: 'electron' },
|
|
43
|
+
// Chromium, whatever the host operating system is.
|
|
44
|
+
usesWebKit: false,
|
|
45
|
+
ownsCoverageKinds: true,
|
|
46
|
+
hasOwnBaselineDirectory: true,
|
|
47
|
+
},
|
|
48
|
+
[AppRuntime.TAURI]: {
|
|
49
|
+
surface: Surface.DESKTOP,
|
|
50
|
+
isDesktopShell: true,
|
|
51
|
+
projectMarker: { file: 'src-tauri/tauri.conf.json' },
|
|
52
|
+
// The system webview: WKWebView on macOS, WebKitGTK on Linux.
|
|
53
|
+
usesWebKit: true,
|
|
54
|
+
// A desktop shell that raises none of its own coverage warnings. Its `invoke` is a fetch to a
|
|
55
|
+
// custom protocol, so the IPC is already observed and there is no unobserved-IPC case to report.
|
|
56
|
+
// The obvious grouping -- "the two desktop ones behave alike" -- is wrong here.
|
|
57
|
+
ownsCoverageKinds: false,
|
|
58
|
+
hasOwnBaselineDirectory: true,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Is this a realm this build knows about?
|
|
63
|
+
*
|
|
64
|
+
* Asked where a runtime arrives from the page and has to be accepted or ignored. Derived from the
|
|
65
|
+
* table rather than listed again, because a list repeated somewhere else is a list that gets one
|
|
66
|
+
* entry behind: a realm missing from it is not rejected loudly, its name is simply dropped, and every
|
|
67
|
+
* later question about that session answers as though the page never said what it was.
|
|
68
|
+
*
|
|
69
|
+
* Written as a type guard so the caller gets the narrowing the hand-written chain of comparisons gave
|
|
70
|
+
* it for free. Without that, replacing the chain would have widened a field back to a plain string,
|
|
71
|
+
* and the compiler would stop catching a runtime this package does not know.
|
|
72
|
+
*/
|
|
73
|
+
export function isKnownRealm(runtime) {
|
|
74
|
+
return runtime !== undefined && Object.hasOwn(REALMS, runtime);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The facts for a realm, or the web's, when the page has not said which it is.
|
|
78
|
+
*
|
|
79
|
+
* An older SDK sends no runtime at all. Reading that silence as a desktop shell would show desktop
|
|
80
|
+
* warnings to every browser tab connected by an older client, so the unknown case answers as the web:
|
|
81
|
+
* the realm with the fewest special cases, and the one almost every unknown session actually is.
|
|
82
|
+
*
|
|
83
|
+
* Takes a plain string rather than the enum, deliberately. What arrives here came off the wire from
|
|
84
|
+
* a page that may be newer than this build, so "a realm I have never heard of" is a case that has to
|
|
85
|
+
* exist -- and typing the parameter as the enum would describe a guarantee the wire cannot make.
|
|
86
|
+
*/
|
|
87
|
+
/**
|
|
88
|
+
* Realms a host registered at startup, for domains this package does not ship.
|
|
89
|
+
*
|
|
90
|
+
* `REALMS` above is a compile-checked `Record<AppRuntime, …>` and stays that way: leaving out a
|
|
91
|
+
* shell this package ships must remain a compile error. But that same shape is a wall for everybody else —
|
|
92
|
+
* an Android realm, a game realm, a CLI realm cannot be NAMED without a pull request against
|
|
93
|
+
* `@reticlehq/core`, and a protocol meant for industries that have never heard of this repository
|
|
94
|
+
* cannot require one.
|
|
95
|
+
*
|
|
96
|
+
* Separate map rather than a mutable `REALMS`, so a registration can never shadow or delete a
|
|
97
|
+
* built-in. Extension must not mean an adopter can redefine `web`.
|
|
98
|
+
*/
|
|
99
|
+
const REGISTERED = new Map();
|
|
100
|
+
/** The prefix every extension in this protocol carries. Not decoration — see `registerRealm`. */
|
|
101
|
+
const EXTENSION_PREFIX = 'x-';
|
|
102
|
+
/**
|
|
103
|
+
* Teach this process about a realm it does not ship.
|
|
104
|
+
*
|
|
105
|
+
* The `x-` prefix is required for two reasons that are both about the future: a third-party name
|
|
106
|
+
* can never collide with one this package later ships, and a reader can tell at a glance which
|
|
107
|
+
* realms this package ships and which a host added. It is the same convention `ChannelIdSchema` already
|
|
108
|
+
* enforces for channels.
|
|
109
|
+
*
|
|
110
|
+
* Throws rather than returning a result. A realm that failed to register would answer `web` to
|
|
111
|
+
* everything — the most plausible-looking wrong answer available — and the caller is a host at
|
|
112
|
+
* startup, where a throw is read immediately and a silent miss is not read at all.
|
|
113
|
+
*
|
|
114
|
+
* CEILING, invisible from the signature: there is no host seam in the daemon. `reticle serve`
|
|
115
|
+
* imports no user module, so nothing outside this repository has a moment in which to call this,
|
|
116
|
+
* and every realm Reticle ships is a row in `REALMS` rather than a registration. Adding a realm
|
|
117
|
+
* today means a change to `@reticlehq/core`.
|
|
118
|
+
*/
|
|
119
|
+
export function registerRealm(runtime, traits) {
|
|
120
|
+
if (!runtime.startsWith(EXTENSION_PREFIX)) {
|
|
121
|
+
throw new Error(`realm "${runtime}" must start with "${EXTENSION_PREFIX}" — the prefix keeps a realm this ` +
|
|
122
|
+
'package might later ship from colliding with yours, and tells a reader whose realm it is.');
|
|
123
|
+
}
|
|
124
|
+
if (Object.hasOwn(REALMS, runtime)) {
|
|
125
|
+
throw new Error(`realm "${runtime}" is built in and cannot be redefined`);
|
|
126
|
+
}
|
|
127
|
+
REGISTERED.set(runtime, traits);
|
|
128
|
+
}
|
|
129
|
+
/** Every runtime this process understands: the built-ins, plus whatever a host registered. */
|
|
130
|
+
export function knownRuntimes() {
|
|
131
|
+
return [...Object.keys(REALMS), ...REGISTERED.keys()];
|
|
132
|
+
}
|
|
133
|
+
/** Forget every registered realm. For tests and for a host rebuilding its own registry. */
|
|
134
|
+
export function resetRegisteredRealms() {
|
|
135
|
+
REGISTERED.clear();
|
|
136
|
+
}
|
|
137
|
+
export function realmOf(runtime) {
|
|
138
|
+
const name = runtime ?? '';
|
|
139
|
+
if (Object.hasOwn(REALMS, name))
|
|
140
|
+
return REALMS[name];
|
|
141
|
+
return REGISTERED.get(name) ?? REALMS[AppRuntime.WEB];
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The protocol's surface for a realm.
|
|
145
|
+
*
|
|
146
|
+
* Reads `isDesktopShell` rather than testing the runtime again, which is the whole reason this
|
|
147
|
+
* table exists: a third place branching on `electron || tauri` is a third place to forget a realm,
|
|
148
|
+
* and the answer it would forget into is the web one -- the answer most likely to look plausible
|
|
149
|
+
* and be wrong.
|
|
150
|
+
*
|
|
151
|
+
* An unknown or absent runtime answers `web`, like everything else here. For a surface that IS an
|
|
152
|
+
* assumption rather than a fact: a `SubjectRef` requires one and the handshake carries no other
|
|
153
|
+
* tell, so the error is a desktop app identified as a page, which understates the subject rather
|
|
154
|
+
* than misdescribing it.
|
|
155
|
+
*/
|
|
156
|
+
export function surfaceOf(runtime) {
|
|
157
|
+
return realmOf(runtime).surface;
|
|
158
|
+
}
|
|
159
|
+
/** The protocol's identity for a connected subject. */
|
|
160
|
+
export function subjectOf(facts) {
|
|
161
|
+
const epoch = facts.currentEditEpoch;
|
|
162
|
+
return {
|
|
163
|
+
surface: surfaceOf(facts.runtime),
|
|
164
|
+
// The document id when there is one. Falling back to the session id is a WEAKER identity --
|
|
165
|
+
// it survives a navigation that should have invalidated it -- so it is used only before the
|
|
166
|
+
// first document is known, never as a substitute for one.
|
|
167
|
+
instance: facts.currentDocumentId ?? facts.id,
|
|
168
|
+
...(epoch === undefined ? {} : { epoch }),
|
|
169
|
+
locator: facts.url,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Which realm a project on disk is, judged only by its markers.
|
|
174
|
+
*
|
|
175
|
+
* A project can carry more than one marker, so precedence has to be decided rather than inherited
|
|
176
|
+
* from whatever order the table happens to be written in.
|
|
177
|
+
*
|
|
178
|
+
* A CONFIG FILE beats a DEPENDENCY. A file like `src-tauri/tauri.conf.json` exists because somebody
|
|
179
|
+
* set this project up to be that kind of app; a dependency can be transitive, vestigial, or left
|
|
180
|
+
* behind by something that was tried and abandoned. The stronger claim wins, which is also what the
|
|
181
|
+
* hand-written checks this replaces already did.
|
|
182
|
+
*
|
|
183
|
+
* Returns undefined rather than the web when nothing matches. "This is a plain web project" and "I
|
|
184
|
+
* could not tell" are the same observation here, and naming it `web` would state more than was seen.
|
|
185
|
+
*/
|
|
186
|
+
export function realmOfProject(hasFile, hasDependency) {
|
|
187
|
+
const marked = Object.entries(REALMS).filter(([, realm]) => realm.projectMarker !== undefined);
|
|
188
|
+
for (const [runtime, realm] of marked) {
|
|
189
|
+
const marker = realm.projectMarker;
|
|
190
|
+
if (marker !== undefined && 'file' in marker && hasFile(marker.file))
|
|
191
|
+
return runtime;
|
|
192
|
+
}
|
|
193
|
+
for (const [runtime, realm] of marked) {
|
|
194
|
+
const marker = realm.projectMarker;
|
|
195
|
+
if (marker !== undefined && 'dependency' in marker && hasDependency(marker.dependency)) {
|
|
196
|
+
return runtime;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Which kind of surface each known shell presents.
|
|
203
|
+
*
|
|
204
|
+
* The bridge between the two vocabularies, kept here rather than beside `PlatformProfile` so that
|
|
205
|
+
* the profile list itself depends on nothing. A connection that says which shell it is, and not
|
|
206
|
+
* which surface, still gets a surface -- which is what lets an older SDK keep working.
|
|
207
|
+
*
|
|
208
|
+
* `Record<AppRuntime, PlatformProfile>` means a new shell cannot be added without answering this.
|
|
209
|
+
*/
|
|
210
|
+
const PROFILE_OF_RUNTIME = {
|
|
211
|
+
[AppRuntime.WEB]: PlatformProfile.WEB,
|
|
212
|
+
// Both are a web page in somebody else's window. That they are one profile is the entire point.
|
|
213
|
+
[AppRuntime.ELECTRON]: PlatformProfile.WEBVIEW,
|
|
214
|
+
[AppRuntime.TAURI]: PlatformProfile.WEBVIEW,
|
|
215
|
+
};
|
|
216
|
+
/** The kind of surface a shell presents, or undefined if we have never heard of the shell. */
|
|
217
|
+
export function profileOfRuntime(runtime) {
|
|
218
|
+
if (runtime === undefined)
|
|
219
|
+
return undefined;
|
|
220
|
+
return PROFILE_OF_RUNTIME[runtime];
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* How each kind of surface may be DRIVEN.
|
|
224
|
+
*
|
|
225
|
+
* "Resume is nearly free, just re-run the prefix at 27 ms a step" is true of a browser and FALSE
|
|
226
|
+
* AND DANGEROUS on hardware, where re-driving a prefix moves a physical
|
|
227
|
+
* arm, costs real time, and may not be idempotent. The protocol already decides this from a declared
|
|
228
|
+
* profile via `resumeStrategy`; what was missing was anywhere for server code to GET a profile,
|
|
229
|
+
* because a `Realm` object is constructed only by the conformance client and the code that resumes a
|
|
230
|
+
* replay has no realm to ask.
|
|
231
|
+
*
|
|
232
|
+
* A determinism profile is a property of the KIND of subject, not of one realm instance, so it lives
|
|
233
|
+
* here beside the other facts about kinds. That is what makes the rule enforceable on the path that
|
|
234
|
+
* actually resumes, today, rather than after some future wiring.
|
|
235
|
+
*
|
|
236
|
+
* Every surface the vocabulary names is declared. A missing entry would fall through to the web
|
|
237
|
+
* answer, and the web answer is the permissive one — which is the wrong direction to be wrong in
|
|
238
|
+
* when the question is "may I silently re-send this payment".
|
|
239
|
+
*/
|
|
240
|
+
export const DETERMINISM_BY_SURFACE = {
|
|
241
|
+
[Surface.WEB]: {
|
|
242
|
+
reset: 'cheap',
|
|
243
|
+
replayPrefix: 'free',
|
|
244
|
+
time: 'injectable',
|
|
245
|
+
observation: 'exact',
|
|
246
|
+
actions: 'reversible',
|
|
247
|
+
},
|
|
248
|
+
/** A browser in a shell: the page behaves the same, the shell adds windows and menus. */
|
|
249
|
+
[Surface.DESKTOP]: {
|
|
250
|
+
reset: 'cheap',
|
|
251
|
+
replayPrefix: 'free',
|
|
252
|
+
time: 'injectable',
|
|
253
|
+
observation: 'exact',
|
|
254
|
+
actions: 'reversible',
|
|
255
|
+
},
|
|
256
|
+
/** A cold start is the reset, and it is not cheap. */
|
|
257
|
+
[Surface.MOBILE]: {
|
|
258
|
+
reset: 'costly',
|
|
259
|
+
replayPrefix: 'costly',
|
|
260
|
+
time: 'wall',
|
|
261
|
+
observation: 'exact',
|
|
262
|
+
actions: 'reversible',
|
|
263
|
+
},
|
|
264
|
+
/** A POST is not idempotent. Re-driving a prefix to reach step N re-sends everything before it. */
|
|
265
|
+
[Surface.SERVICE]: {
|
|
266
|
+
reset: 'costly',
|
|
267
|
+
replayPrefix: 'unsafe',
|
|
268
|
+
time: 'wall',
|
|
269
|
+
observation: 'exact',
|
|
270
|
+
actions: 'irreversible',
|
|
271
|
+
},
|
|
272
|
+
/** Frame-stepped and seedable, which makes a game the MOST deterministic subject here. */
|
|
273
|
+
[Surface.GAME]: {
|
|
274
|
+
reset: 'cheap',
|
|
275
|
+
replayPrefix: 'free',
|
|
276
|
+
time: 'stepped',
|
|
277
|
+
observation: 'exact',
|
|
278
|
+
actions: 'reversible',
|
|
279
|
+
},
|
|
280
|
+
/** A sensor reads a region, not a value, and an actuator cannot be un-moved. */
|
|
281
|
+
[Surface.DEVICE]: {
|
|
282
|
+
reset: 'costly',
|
|
283
|
+
replayPrefix: 'unsafe',
|
|
284
|
+
time: 'wall',
|
|
285
|
+
observation: 'sampled',
|
|
286
|
+
actions: 'irreversible',
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
/** The declared profile for a surface. */
|
|
290
|
+
export function determinismFor(surface) {
|
|
291
|
+
return DETERMINISM_BY_SURFACE[surface];
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* May a resume re-drive the steps before the one asked for?
|
|
295
|
+
*
|
|
296
|
+
* The one question the resume path has to ask before it silently repeats somebody's actions. Derived
|
|
297
|
+
* through the protocol's own `resumeStrategy` rather than by reading `replayPrefix` here, so this
|
|
298
|
+
* cannot drift from the rule the specification publishes.
|
|
299
|
+
*/
|
|
300
|
+
export function mayResumeByReplayingPrefix(surface) {
|
|
301
|
+
return ResumeStrategy.REFUSE !== resumeStrategy(determinismFor(surface));
|
|
302
|
+
}
|