@reticlehq/core 3.7.0 → 3.8.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 (108) hide show
  1. package/dist/activation-entry.d.ts +9 -0
  2. package/dist/activation-entry.js +9 -0
  3. package/dist/artifacts/drive-script.d.ts +64 -64
  4. package/dist/artifacts/flow-constants.d.ts +15 -0
  5. package/dist/artifacts/flow-constants.js +15 -0
  6. package/dist/artifacts/flow-expect-flat.d.ts +8 -8
  7. package/dist/artifacts/flow-results.d.ts +11 -0
  8. package/dist/artifacts/flow-types.d.ts +164 -118
  9. package/dist/artifacts/flow-types.js +12 -0
  10. package/dist/artifacts/harness-credits.d.ts +6 -3
  11. package/dist/artifacts/harness-credits.js +9 -6
  12. package/dist/artifacts/harness-map.d.ts +6 -6
  13. package/dist/artifacts/impact.d.ts +77 -80
  14. package/dist/artifacts/impact.js +34 -17
  15. package/dist/artifacts/journal.d.ts +25 -6
  16. package/dist/artifacts/journal.js +13 -0
  17. package/dist/artifacts/prompt-context.d.ts +12 -0
  18. package/dist/artifacts/prompt-context.js +14 -3
  19. package/dist/graph/app-graph.d.ts +137 -0
  20. package/dist/graph/app-graph.js +498 -0
  21. package/dist/hooks/hook-events.d.ts +22 -22
  22. package/dist/hud-entry.js +1 -1
  23. package/dist/identity/checkout.d.ts +41 -0
  24. package/dist/identity/checkout.js +118 -0
  25. package/dist/identity/state-dir.d.ts +23 -0
  26. package/dist/identity/state-dir.js +43 -0
  27. package/dist/index.d.ts +10 -0
  28. package/dist/index.js +10 -0
  29. package/dist/onboarding.d.ts +22 -1
  30. package/dist/onboarding.js +19 -0
  31. package/dist/registry/dev-server-registry.d.ts +2 -2
  32. package/dist/schema/event-message.json +3 -1
  33. package/dist/schema/event-payloads.json +116 -1
  34. package/dist/schema/event-type.json +3 -1
  35. package/dist/schema/hello-message.json +21 -0
  36. package/dist/schema/reticle-event.json +3 -1
  37. package/dist/schema/reticle-message.json +24 -1
  38. package/dist/telemetry-bug.d.ts +6 -6
  39. package/dist/telemetry-entry.d.ts +1 -1
  40. package/dist/telemetry-entry.js +1 -1
  41. package/dist/telemetry-feedback.d.ts +14 -0
  42. package/dist/telemetry-feedback.js +19 -0
  43. package/dist/telemetry-refusal.d.ts +2 -2
  44. package/dist/telemetry-session.d.ts +23 -8
  45. package/dist/telemetry-session.js +15 -4
  46. package/dist/telemetry-signals.d.ts +227 -9
  47. package/dist/telemetry-signals.js +88 -1
  48. package/dist/telemetry.d.ts +379 -72
  49. package/dist/telemetry.js +71 -5
  50. package/dist/verdict/check-sentence.d.ts +34 -0
  51. package/dist/verdict/check-sentence.js +228 -0
  52. package/dist/verdict/consequence.d.ts +15 -0
  53. package/dist/verdict/consequence.js +11 -0
  54. package/dist/verdict/findings.d.ts +10 -0
  55. package/dist/verdict/findings.js +13 -0
  56. package/dist/verdict/instrumentation-coverage.d.ts +3 -34
  57. package/dist/verdict/instrumentation-coverage.js +14 -58
  58. package/dist/verdict/instrumentation-gap.d.ts +79 -0
  59. package/dist/verdict/instrumentation-gap.js +64 -0
  60. package/dist/verdict/predicate-tree.d.ts +2 -0
  61. package/dist/verdict/predicate-tree.js +16 -0
  62. package/dist/verdict/predicate.d.ts +2 -1
  63. package/dist/verdict/predicate.js +103 -12
  64. package/dist/verdict/property-assertion.d.ts +2 -2
  65. package/dist/verdict/run-report.d.ts +166 -0
  66. package/dist/verdict/run-report.js +53 -0
  67. package/dist/verdict/security.d.ts +36 -2
  68. package/dist/verdict/security.js +94 -14
  69. package/dist/verdict/verification-run.d.ts +95 -38
  70. package/dist/verdict/verification-run.js +33 -2
  71. package/dist/verdict/verify-progress.d.ts +6 -6
  72. package/dist/wire/constants/constants.d.ts +56 -141
  73. package/dist/wire/constants/constants.js +64 -144
  74. package/dist/wire/constants/discovery.d.ts +4 -4
  75. package/dist/wire/constants/discovery.js +4 -4
  76. package/dist/wire/constants/event-types.d.ts +35 -1
  77. package/dist/wire/constants/event-types.js +33 -1
  78. package/dist/wire/constants/hud-controls.js +0 -2
  79. package/dist/wire/constants/hud-use.d.ts +4 -0
  80. package/dist/wire/constants/hud-use.js +4 -0
  81. package/dist/wire/constants/mcp-wire.d.ts +16 -0
  82. package/dist/wire/constants/mcp-wire.js +16 -0
  83. package/dist/wire/constants/response-body-reason.d.ts +19 -0
  84. package/dist/wire/constants/response-body-reason.js +18 -0
  85. package/dist/wire/constants/reticle-env.d.ts +138 -0
  86. package/dist/wire/constants/reticle-env.js +138 -0
  87. package/dist/wire/constants/session-constants.d.ts +11 -0
  88. package/dist/wire/constants/session-constants.js +11 -0
  89. package/dist/wire/event-payloads.d.ts +150 -36
  90. package/dist/wire/event-payloads.js +83 -16
  91. package/dist/wire/messages.d.ts +102 -36
  92. package/dist/wire/messages.js +16 -0
  93. package/dist/wire/narrow.d.ts +6 -0
  94. package/dist/wire/narrow.js +26 -0
  95. package/dist/wire/next-step.d.ts +90 -0
  96. package/dist/wire/next-step.js +37 -0
  97. package/dist/wire/platform-link.d.ts +7 -0
  98. package/dist/wire/platform-link.js +12 -6
  99. package/dist/wire/production/activation-ticket.d.ts +64 -0
  100. package/dist/wire/production/activation-ticket.js +148 -0
  101. package/dist/wire/production/hello-mode.d.ts +35 -0
  102. package/dist/wire/production/hello-mode.js +32 -0
  103. package/dist/wire/production/production-policy.d.ts +138 -0
  104. package/dist/wire/production/production-policy.js +133 -0
  105. package/dist/wire/tool-names.d.ts +2 -0
  106. package/dist/wire/tool-names.js +2 -0
  107. package/dist/wire/types.d.ts +73 -48
  108. package/package.json +5 -1
@@ -102,6 +102,13 @@ export interface ToolSessionResult {
102
102
  result?: unknown;
103
103
  error?: string;
104
104
  ms: number;
105
+ /**
106
+ * When the call started and ended on the daemon's clock (epoch ms). The platform saw only its own
107
+ * send and the reply, which folds the network and the queue into the tool's time. Optional: an
108
+ * older daemon does not send them.
109
+ */
110
+ startedAt?: number;
111
+ endedAt?: number;
105
112
  }
106
113
  /** The platform's answer to a session ask: the next calls, or that the drive is over. */
107
114
  export interface ToolSessionReply {
@@ -89,8 +89,9 @@ const SPEC_FIELDS = {
89
89
  export function parseDriveSpec(raw) {
90
90
  const ignored = [];
91
91
  const spec = {};
92
- if ('object' !== typeof raw || null === raw || Array.isArray(raw))
92
+ if ('object' !== typeof raw || null === raw || Array.isArray(raw)) {
93
93
  return { spec, ignored };
94
+ }
94
95
  for (const [field, value] of Object.entries(raw)) {
95
96
  const schema = SPEC_FIELDS[field];
96
97
  if (schema === undefined) {
@@ -98,10 +99,12 @@ export function parseDriveSpec(raw) {
98
99
  continue;
99
100
  }
100
101
  const parsed = schema.safeParse(value);
101
- if (parsed.success)
102
+ if (parsed.success) {
102
103
  spec[field] = parsed.data;
103
- else
104
+ }
105
+ else {
104
106
  ignored.push({ field, reason: SpecIgnoredReason.INVALID });
107
+ }
105
108
  }
106
109
  return { spec, ignored };
107
110
  }
@@ -135,8 +138,9 @@ const SessionCallSchema = z.object({
135
138
  * dropped; the platform sees no result for its `seq` and decides what that means.
136
139
  */
137
140
  export function parseToolSessionReply(raw) {
138
- if ('object' !== typeof raw || null === raw)
141
+ if ('object' !== typeof raw || null === raw) {
139
142
  return { calls: [], done: true };
143
+ }
140
144
  const record = raw;
141
145
  const calls = (Array.isArray(record.calls) ? record.calls : [])
142
146
  .slice(0, TOOL_SESSION_LIMITS.MAX_BATCH)
@@ -160,12 +164,14 @@ export function parseLinkNotices(raw) {
160
164
  const levels = new Set(Object.values(LinkNoticeLevel));
161
165
  return (Array.isArray(raw) ? raw : [])
162
166
  .flatMap((entry) => {
163
- if ('object' !== typeof entry || null === entry)
167
+ if ('object' !== typeof entry || null === entry) {
164
168
  return [];
169
+ }
165
170
  const notice = entry;
166
171
  const text = 'string' === typeof notice.text ? notice.text.trim() : '';
167
- if ('string' !== typeof notice.level || !levels.has(notice.level) || 0 === text.length)
172
+ if ('string' !== typeof notice.level || !levels.has(notice.level) || 0 === text.length) {
168
173
  return [];
174
+ }
169
175
  const url = 'string' === typeof notice.url && /^https?:\/\//i.test(notice.url) ? notice.url : undefined;
170
176
  return [
171
177
  {
@@ -0,0 +1,64 @@
1
+ import { HelloScope } from './hello-mode.js';
2
+ /**
3
+ * The activation ticket a page checks for itself before it loads the SDK on a live site.
4
+ *
5
+ * The service mints it and signs it with Ed25519. The page carries only the public key, so it can
6
+ * check the ticket with no round trip and no secret. Format: `<payload>.<signature>`. Both parts
7
+ * are base64url. `payload` is the JSON of `ActivationTicketPayload`, and the signature covers the
8
+ * ASCII bytes of the payload part as it is written.
9
+ *
10
+ * Hand-narrowed and not a zod schema on purpose: the page-side loader imports this file, and zod
11
+ * would put a schema library into every page load of a live site to check six fields.
12
+ */
13
+ /** The query parameter the site opens with. The page loader removes it from the address bar. */
14
+ export declare const PRODUCTION_ACTIVATE_PARAM = "reticle_activate";
15
+ /** The only ticket format this file reads. A new format gets a new number. */
16
+ export declare const ACTIVATION_TICKET_VERSION = 1;
17
+ export interface ActivationTicketPayload {
18
+ v: typeof ACTIVATION_TICKET_VERSION;
19
+ /** The single-use HELLO token the bridge minted for this drive. The page sends it as `token`. */
20
+ nonce: string;
21
+ /** The page origin the ticket is for. Another origin refuses it. */
22
+ origin: string;
23
+ /** The bridge the page connects to. `wss://`, or `ws://` on a loopback host only. */
24
+ bridge: string;
25
+ scope: HelloScope;
26
+ /** When the ticket stops being valid, in epoch ms. */
27
+ exp: number;
28
+ }
29
+ /** Why a page refused a ticket. The page does nothing in each case. */
30
+ export declare const ActivationRefusal: {
31
+ readonly MALFORMED: "malformed ticket";
32
+ readonly BAD_SIGNATURE: "the signature does not verify";
33
+ readonly EXPIRED: "the ticket expired";
34
+ readonly WRONG_ORIGIN: "the ticket is for another origin";
35
+ readonly INSECURE_BRIDGE: "the bridge is not wss:// or a loopback ws://";
36
+ };
37
+ export type ActivationRefusal = (typeof ActivationRefusal)[keyof typeof ActivationRefusal];
38
+ export type ActivationVerdict = {
39
+ ok: true;
40
+ payload: ActivationTicketPayload;
41
+ } | {
42
+ ok: false;
43
+ reason: ActivationRefusal;
44
+ };
45
+ type Subtle = typeof globalThis.crypto.subtle;
46
+ type SigningKey = Parameters<Subtle['sign']>[1];
47
+ export declare function toBase64Url(bytes: Uint8Array): string;
48
+ /**
49
+ * Check a ticket against the service's public key (base64url, raw 32 bytes), the page origin and
50
+ * the clock. Never throws.
51
+ */
52
+ export declare function verifyActivationTicket(ticket: string, options: {
53
+ publicKey: string;
54
+ origin: string;
55
+ now: number;
56
+ subtle?: Subtle;
57
+ }): Promise<ActivationVerdict>;
58
+ /**
59
+ * Mint a ticket. For the service only: it holds the Ed25519 private key, and the key never leaves
60
+ * it. Import a PKCS#8 key with `crypto.subtle.importKey('pkcs8', der, { name: 'Ed25519' }, false,
61
+ * ['sign'])`.
62
+ */
63
+ export declare function signActivationTicket(privateKey: SigningKey, payload: ActivationTicketPayload, subtle?: Subtle): Promise<string>;
64
+ export {};
@@ -0,0 +1,148 @@
1
+ import { HelloScope } from './hello-mode.js';
2
+ import { isLoopbackHostname } from '../../verdict/security.js';
3
+ /**
4
+ * The activation ticket a page checks for itself before it loads the SDK on a live site.
5
+ *
6
+ * The service mints it and signs it with Ed25519. The page carries only the public key, so it can
7
+ * check the ticket with no round trip and no secret. Format: `<payload>.<signature>`. Both parts
8
+ * are base64url. `payload` is the JSON of `ActivationTicketPayload`, and the signature covers the
9
+ * ASCII bytes of the payload part as it is written.
10
+ *
11
+ * Hand-narrowed and not a zod schema on purpose: the page-side loader imports this file, and zod
12
+ * would put a schema library into every page load of a live site to check six fields.
13
+ */
14
+ /** The query parameter the site opens with. The page loader removes it from the address bar. */
15
+ export const PRODUCTION_ACTIVATE_PARAM = 'reticle_activate';
16
+ /** The only ticket format this file reads. A new format gets a new number. */
17
+ export const ACTIVATION_TICKET_VERSION = 1;
18
+ /** Joins the payload part and the signature part. */
19
+ const TICKET_SEPARATOR = '.';
20
+ const ED25519 = 'Ed25519';
21
+ const RAW_KEY_FORMAT = 'raw';
22
+ const WS_PROTOCOL = 'ws:';
23
+ const WSS_PROTOCOL = 'wss:';
24
+ /** Bounds, so a page never parses an unbounded string from its own address bar. */
25
+ const MAX_TICKET_LENGTH = 4096;
26
+ const MAX_FIELD_LENGTH = 2048;
27
+ /** Why a page refused a ticket. The page does nothing in each case. */
28
+ export const ActivationRefusal = {
29
+ MALFORMED: 'malformed ticket',
30
+ BAD_SIGNATURE: 'the signature does not verify',
31
+ EXPIRED: 'the ticket expired',
32
+ WRONG_ORIGIN: 'the ticket is for another origin',
33
+ INSECURE_BRIDGE: 'the bridge is not wss:// or a loopback ws://',
34
+ };
35
+ export function toBase64Url(bytes) {
36
+ let binary = '';
37
+ for (const byte of bytes)
38
+ binary += String.fromCharCode(byte);
39
+ return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
40
+ }
41
+ /** Undefined when the text is not base64url. */
42
+ function fromBase64Url(text) {
43
+ if (!/^[A-Za-z0-9_-]*$/.test(text))
44
+ return undefined;
45
+ try {
46
+ const binary = atob(text.replace(/-/g, '+').replace(/_/g, '/'));
47
+ const bytes = new Uint8Array(binary.length);
48
+ for (let i = 0; i < binary.length; i++)
49
+ bytes[i] = binary.charCodeAt(i);
50
+ return bytes;
51
+ }
52
+ catch {
53
+ return undefined;
54
+ }
55
+ }
56
+ const isText = (value) => 'string' === typeof value && 0 < value.length && value.length <= MAX_FIELD_LENGTH;
57
+ function readPayload(part) {
58
+ const bytes = fromBase64Url(part);
59
+ if (bytes === undefined)
60
+ return undefined;
61
+ let value;
62
+ try {
63
+ value = JSON.parse(new TextDecoder().decode(bytes));
64
+ }
65
+ catch {
66
+ return undefined;
67
+ }
68
+ if (typeof value !== 'object' || null === value)
69
+ return undefined;
70
+ const p = value;
71
+ const scope = Object.values(HelloScope).find((s) => s === p.scope);
72
+ if (p.v !== ACTIVATION_TICKET_VERSION ||
73
+ !isText(p.nonce) ||
74
+ !isText(p.origin) ||
75
+ !isText(p.bridge) ||
76
+ scope === undefined ||
77
+ typeof p.exp !== 'number' ||
78
+ !Number.isFinite(p.exp)) {
79
+ return undefined;
80
+ }
81
+ return {
82
+ v: ACTIVATION_TICKET_VERSION,
83
+ nonce: p.nonce,
84
+ origin: p.origin,
85
+ bridge: p.bridge,
86
+ scope,
87
+ exp: p.exp,
88
+ };
89
+ }
90
+ function secureBridge(bridge) {
91
+ try {
92
+ const url = new URL(bridge);
93
+ if (url.protocol === WSS_PROTOCOL)
94
+ return true;
95
+ return url.protocol === WS_PROTOCOL && isLoopbackHostname(url.hostname);
96
+ }
97
+ catch {
98
+ return false;
99
+ }
100
+ }
101
+ async function signatureVerifies(subtle, publicKey, signature, signed) {
102
+ const raw = fromBase64Url(publicKey);
103
+ if (raw === undefined)
104
+ return false;
105
+ try {
106
+ const key = await subtle.importKey(RAW_KEY_FORMAT, raw, { name: ED25519 }, false, ['verify']);
107
+ return await subtle.verify({ name: ED25519 }, key, signature, signed);
108
+ }
109
+ catch {
110
+ // A malformed key, or a browser with no Ed25519. Both mean: do not activate.
111
+ return false;
112
+ }
113
+ }
114
+ /**
115
+ * Check a ticket against the service's public key (base64url, raw 32 bytes), the page origin and
116
+ * the clock. Never throws.
117
+ */
118
+ export async function verifyActivationTicket(ticket, options) {
119
+ const parts = ticket.length <= MAX_TICKET_LENGTH ? ticket.split(TICKET_SEPARATOR) : [];
120
+ const [payloadPart, signaturePart] = parts;
121
+ const payload = 2 === parts.length && payloadPart !== undefined ? readPayload(payloadPart) : undefined;
122
+ const signature = signaturePart === undefined ? undefined : fromBase64Url(signaturePart);
123
+ if (payload === undefined || signature === undefined || payloadPart === undefined) {
124
+ return { ok: false, reason: ActivationRefusal.MALFORMED };
125
+ }
126
+ const subtle = options.subtle ?? globalThis.crypto.subtle;
127
+ const signed = new TextEncoder().encode(payloadPart);
128
+ if (!(await signatureVerifies(subtle, options.publicKey, signature, signed))) {
129
+ return { ok: false, reason: ActivationRefusal.BAD_SIGNATURE };
130
+ }
131
+ if (payload.exp <= options.now)
132
+ return { ok: false, reason: ActivationRefusal.EXPIRED };
133
+ if (payload.origin !== options.origin)
134
+ return { ok: false, reason: ActivationRefusal.WRONG_ORIGIN };
135
+ if (!secureBridge(payload.bridge))
136
+ return { ok: false, reason: ActivationRefusal.INSECURE_BRIDGE };
137
+ return { ok: true, payload };
138
+ }
139
+ /**
140
+ * Mint a ticket. For the service only: it holds the Ed25519 private key, and the key never leaves
141
+ * it. Import a PKCS#8 key with `crypto.subtle.importKey('pkcs8', der, { name: 'Ed25519' }, false,
142
+ * ['sign'])`.
143
+ */
144
+ export async function signActivationTicket(privateKey, payload, subtle = globalThis.crypto.subtle) {
145
+ const payloadPart = toBase64Url(new TextEncoder().encode(JSON.stringify(payload)));
146
+ const signature = await subtle.sign({ name: ED25519 }, privateKey, new TextEncoder().encode(payloadPart));
147
+ return `${payloadPart}${TICKET_SEPARATOR}${toBase64Url(new Uint8Array(signature))}`;
148
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Where a page runs and what a drive may do there, as a HELLO announces it.
3
+ *
4
+ * A leaf on purpose: the browser SDK sends these two words, and nothing else about production mode
5
+ * belongs in a page's first load. The policy that reads them lives in `production-policy.ts`.
6
+ */
7
+ /** The environment a page says it runs in. Absent means `development`, which is every older SDK. */
8
+ export declare const HelloEnv: {
9
+ readonly DEVELOPMENT: "development";
10
+ readonly PRODUCTION: "production";
11
+ };
12
+ export type HelloEnv = (typeof HelloEnv)[keyof typeof HelloEnv];
13
+ /**
14
+ * What a drive may do on the page. `observe` reads only. `act` also clicks and types.
15
+ * Absent means `act` in development. A production HELLO must say which.
16
+ */
17
+ export declare const HelloScope: {
18
+ readonly OBSERVE: "observe";
19
+ readonly ACT: "act";
20
+ };
21
+ export type HelloScope = (typeof HelloScope)[keyof typeof HelloScope];
22
+ /**
23
+ * Who put the SDK in this page. Absent means `installed`: every SDK before this field was one the app
24
+ * imported itself.
25
+ *
26
+ * `injected` is a page a hosted verifier instrumented from outside (a URL-only check), with nothing
27
+ * in the app's own code. Whatever such a session reports (a framework, stores found in the React
28
+ * tree) came from the verifier, not the app. A reader must not count it as the app having the SDK
29
+ * installed: signals, registered module stores and file:line still need the app to add them.
30
+ */
31
+ export declare const HelloInstrumentation: {
32
+ readonly INSTALLED: "installed";
33
+ readonly INJECTED: "injected";
34
+ };
35
+ export type HelloInstrumentation = (typeof HelloInstrumentation)[keyof typeof HelloInstrumentation];
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Where a page runs and what a drive may do there, as a HELLO announces it.
3
+ *
4
+ * A leaf on purpose: the browser SDK sends these two words, and nothing else about production mode
5
+ * belongs in a page's first load. The policy that reads them lives in `production-policy.ts`.
6
+ */
7
+ /** The environment a page says it runs in. Absent means `development`, which is every older SDK. */
8
+ export const HelloEnv = {
9
+ DEVELOPMENT: 'development',
10
+ PRODUCTION: 'production',
11
+ };
12
+ /**
13
+ * What a drive may do on the page. `observe` reads only. `act` also clicks and types.
14
+ * Absent means `act` in development. A production HELLO must say which.
15
+ */
16
+ export const HelloScope = {
17
+ OBSERVE: 'observe',
18
+ ACT: 'act',
19
+ };
20
+ /**
21
+ * Who put the SDK in this page. Absent means `installed`: every SDK before this field was one the app
22
+ * imported itself.
23
+ *
24
+ * `injected` is a page a hosted verifier instrumented from outside (a URL-only check), with nothing
25
+ * in the app's own code. Whatever such a session reports (a framework, stores found in the React
26
+ * tree) came from the verifier, not the app. A reader must not count it as the app having the SDK
27
+ * installed: signals, registered module stores and file:line still need the app to add them.
28
+ */
29
+ export const HelloInstrumentation = {
30
+ INSTALLED: 'installed',
31
+ INJECTED: 'injected',
32
+ };
@@ -0,0 +1,138 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * The production action policy: what a drive on a live site may not do unless its intent says so.
4
+ *
5
+ * A wire contract because two sides supply it. The engine ships `DEFAULT_PRODUCTION_POLICY`; the
6
+ * service that issues the activation ticket may send its own list, which replaces the default for
7
+ * that drive. The daemon enforces it where commands are dispatched, never in the page.
8
+ */
9
+ /** Each refusal names one of these. The text follows "production policy: " in the refusal. */
10
+ export declare const ProductionRule: {
11
+ readonly PAYMENT: "payment or checkout";
12
+ readonly DELETE_WORKSPACE: "delete a workspace or project";
13
+ readonly REVOKE_KEY: "revoke or rotate a key";
14
+ readonly SEND_INVITE: "send an invite or email";
15
+ readonly CANCEL_SUBSCRIPTION: "cancel a subscription";
16
+ readonly CHANGE_ROLE: "change a member's role";
17
+ /** `scope: "observe"` reads only. */
18
+ readonly OBSERVE_ONLY: "the session scope is observe, so it does not act";
19
+ /** The drive stays on the origin it was activated for. */
20
+ readonly OFF_ORIGIN: "leave the activated origin";
21
+ /** The nonce's time is up; the drive is over. */
22
+ readonly EXPIRED: "the session nonce expired";
23
+ };
24
+ export type ProductionRule = (typeof ProductionRule)[keyof typeof ProductionRule];
25
+ /** The rules an intent can allow. The other three are never lifted. */
26
+ export declare const LIFTABLE_PRODUCTION_RULES: readonly ["payment or checkout", "delete a workspace or project", "revoke or rotate a key", "send an invite or email", "cancel a subscription", "change a member's role"];
27
+ export type LiftableProductionRule = (typeof LIFTABLE_PRODUCTION_RULES)[number];
28
+ /**
29
+ * One request the policy refuses: an HTTP method and a path pattern (a RegExp source, matched
30
+ * case-insensitively anywhere in the URL's pathname).
31
+ */
32
+ export declare const ProductionPolicyEntrySchema: z.ZodObject<{
33
+ rule: z.ZodEnum<["payment or checkout", "delete a workspace or project", "revoke or rotate a key", "send an invite or email", "cancel a subscription", "change a member's role"]>;
34
+ methods: z.ZodArray<z.ZodString, "many">;
35
+ path: z.ZodEffects<z.ZodString, string, string>;
36
+ }, "strip", z.ZodTypeAny, {
37
+ path: string;
38
+ rule: "payment or checkout" | "delete a workspace or project" | "revoke or rotate a key" | "send an invite or email" | "cancel a subscription" | "change a member's role";
39
+ methods: string[];
40
+ }, {
41
+ path: string;
42
+ rule: "payment or checkout" | "delete a workspace or project" | "revoke or rotate a key" | "send an invite or email" | "cancel a subscription" | "change a member's role";
43
+ methods: string[];
44
+ }>;
45
+ export type ProductionPolicyEntry = z.infer<typeof ProductionPolicyEntrySchema>;
46
+ export declare const ProductionPolicySchema: z.ZodArray<z.ZodObject<{
47
+ rule: z.ZodEnum<["payment or checkout", "delete a workspace or project", "revoke or rotate a key", "send an invite or email", "cancel a subscription", "change a member's role"]>;
48
+ methods: z.ZodArray<z.ZodString, "many">;
49
+ path: z.ZodEffects<z.ZodString, string, string>;
50
+ }, "strip", z.ZodTypeAny, {
51
+ path: string;
52
+ rule: "payment or checkout" | "delete a workspace or project" | "revoke or rotate a key" | "send an invite or email" | "cancel a subscription" | "change a member's role";
53
+ methods: string[];
54
+ }, {
55
+ path: string;
56
+ rule: "payment or checkout" | "delete a workspace or project" | "revoke or rotate a key" | "send an invite or email" | "cancel a subscription" | "change a member's role";
57
+ methods: string[];
58
+ }>, "many">;
59
+ /** The default list: the REST shapes of the six refused actions. A service may send its own. */
60
+ export declare const DEFAULT_PRODUCTION_POLICY: readonly ProductionPolicyEntry[];
61
+ /** What the refusal says. Every refusal is this sentence; nothing is a silent no-op. */
62
+ export declare const PRODUCTION_REFUSAL_PREFIX = "refused: production policy: ";
63
+ export declare const productionRefusal: (rule: ProductionRule) => string;
64
+ /** The service route that issues an activation ticket, authenticated with the person's API key. */
65
+ export declare const PRODUCTION_TICKET_PATH = "/v1/production-mode/tickets";
66
+ export declare const ProductionTicketRequestSchema: z.ZodObject<{
67
+ workspaceId: z.ZodString;
68
+ /** The single-use HELLO token the daemon minted for this drive. */
69
+ nonce: z.ZodString;
70
+ /** The daemon's bridge port. The service puts it in the page's bootstrap and its CSP. */
71
+ bridgePort: z.ZodNumber;
72
+ scope: z.ZodNativeEnum<{
73
+ readonly OBSERVE: "observe";
74
+ readonly ACT: "act";
75
+ }>;
76
+ /**
77
+ * The site origin the lease opens: the ticket's `origin`. Optional only so an older daemon still
78
+ * gets a ticket; a service that is told it binds the ticket to it rather than guessing.
79
+ */
80
+ origin: z.ZodOptional<z.ZodString>;
81
+ /**
82
+ * The bridge the page must dial (`ws://127.0.0.1:<port>/reticle` for the daemon's own): the
83
+ * ticket's `bridge`. Optional for the same reason; absent, the service builds it from `bridgePort`.
84
+ */
85
+ bridge: z.ZodOptional<z.ZodString>;
86
+ }, "strip", z.ZodTypeAny, {
87
+ scope: "observe" | "act";
88
+ nonce: string;
89
+ workspaceId: string;
90
+ bridgePort: number;
91
+ origin?: string | undefined;
92
+ bridge?: string | undefined;
93
+ }, {
94
+ scope: "observe" | "act";
95
+ nonce: string;
96
+ workspaceId: string;
97
+ bridgePort: number;
98
+ origin?: string | undefined;
99
+ bridge?: string | undefined;
100
+ }>;
101
+ export type ProductionTicketRequest = z.infer<typeof ProductionTicketRequestSchema>;
102
+ export declare const ProductionTicketResponseSchema: z.ZodObject<{
103
+ /** Signed by the service (format: `activation-ticket.ts`). The lease opens `<url>?reticle_activate=<ticket>`. */
104
+ ticket: z.ZodString;
105
+ /** When the ticket must be redeemed by (ISO 8601). Informational. */
106
+ expiresAt: z.ZodOptional<z.ZodString>;
107
+ /** The service's own refused requests for this drive. Absent: `DEFAULT_PRODUCTION_POLICY`. */
108
+ policy: z.ZodOptional<z.ZodArray<z.ZodObject<{
109
+ rule: z.ZodEnum<["payment or checkout", "delete a workspace or project", "revoke or rotate a key", "send an invite or email", "cancel a subscription", "change a member's role"]>;
110
+ methods: z.ZodArray<z.ZodString, "many">;
111
+ path: z.ZodEffects<z.ZodString, string, string>;
112
+ }, "strip", z.ZodTypeAny, {
113
+ path: string;
114
+ rule: "payment or checkout" | "delete a workspace or project" | "revoke or rotate a key" | "send an invite or email" | "cancel a subscription" | "change a member's role";
115
+ methods: string[];
116
+ }, {
117
+ path: string;
118
+ rule: "payment or checkout" | "delete a workspace or project" | "revoke or rotate a key" | "send an invite or email" | "cancel a subscription" | "change a member's role";
119
+ methods: string[];
120
+ }>, "many">>;
121
+ }, "strip", z.ZodTypeAny, {
122
+ ticket: string;
123
+ expiresAt?: string | undefined;
124
+ policy?: {
125
+ path: string;
126
+ rule: "payment or checkout" | "delete a workspace or project" | "revoke or rotate a key" | "send an invite or email" | "cancel a subscription" | "change a member's role";
127
+ methods: string[];
128
+ }[] | undefined;
129
+ }, {
130
+ ticket: string;
131
+ expiresAt?: string | undefined;
132
+ policy?: {
133
+ path: string;
134
+ rule: "payment or checkout" | "delete a workspace or project" | "revoke or rotate a key" | "send an invite or email" | "cancel a subscription" | "change a member's role";
135
+ methods: string[];
136
+ }[] | undefined;
137
+ }>;
138
+ export type ProductionTicketResponse = z.infer<typeof ProductionTicketResponseSchema>;
@@ -0,0 +1,133 @@
1
+ import { z } from 'zod';
2
+ import { HelloScope } from './hello-mode.js';
3
+ /**
4
+ * The production action policy: what a drive on a live site may not do unless its intent says so.
5
+ *
6
+ * A wire contract because two sides supply it. The engine ships `DEFAULT_PRODUCTION_POLICY`; the
7
+ * service that issues the activation ticket may send its own list, which replaces the default for
8
+ * that drive. The daemon enforces it where commands are dispatched, never in the page.
9
+ */
10
+ /** Each refusal names one of these. The text follows "production policy: " in the refusal. */
11
+ export const ProductionRule = {
12
+ PAYMENT: 'payment or checkout',
13
+ DELETE_WORKSPACE: 'delete a workspace or project',
14
+ REVOKE_KEY: 'revoke or rotate a key',
15
+ SEND_INVITE: 'send an invite or email',
16
+ CANCEL_SUBSCRIPTION: 'cancel a subscription',
17
+ CHANGE_ROLE: "change a member's role",
18
+ /** `scope: "observe"` reads only. */
19
+ OBSERVE_ONLY: 'the session scope is observe, so it does not act',
20
+ /** The drive stays on the origin it was activated for. */
21
+ OFF_ORIGIN: 'leave the activated origin',
22
+ /** The nonce's time is up; the drive is over. */
23
+ EXPIRED: 'the session nonce expired',
24
+ };
25
+ /** The rules an intent can allow. The other three are never lifted. */
26
+ export const LIFTABLE_PRODUCTION_RULES = [
27
+ ProductionRule.PAYMENT,
28
+ ProductionRule.DELETE_WORKSPACE,
29
+ ProductionRule.REVOKE_KEY,
30
+ ProductionRule.SEND_INVITE,
31
+ ProductionRule.CANCEL_SUBSCRIPTION,
32
+ ProductionRule.CHANGE_ROLE,
33
+ ];
34
+ /** Limits on a supplied policy list, so a ticket cannot hand the daemon an unbounded regex load. */
35
+ const MAX_POLICY_ENTRIES = 64;
36
+ const MAX_POLICY_PATTERN_LENGTH = 256;
37
+ /**
38
+ * One request the policy refuses: an HTTP method and a path pattern (a RegExp source, matched
39
+ * case-insensitively anywhere in the URL's pathname).
40
+ */
41
+ export const ProductionPolicyEntrySchema = z.object({
42
+ rule: z.enum(LIFTABLE_PRODUCTION_RULES),
43
+ methods: z.array(z.string().min(1).max(16)).min(1).max(8),
44
+ path: z
45
+ .string()
46
+ .min(1)
47
+ .max(MAX_POLICY_PATTERN_LENGTH)
48
+ .refine((source) => {
49
+ try {
50
+ new RegExp(source, 'i');
51
+ return true;
52
+ }
53
+ catch {
54
+ return false;
55
+ }
56
+ }, 'not a valid regular expression'),
57
+ });
58
+ export const ProductionPolicySchema = z.array(ProductionPolicyEntrySchema).max(MAX_POLICY_ENTRIES);
59
+ /** The default list: the REST shapes of the six refused actions. A service may send its own. */
60
+ export const DEFAULT_PRODUCTION_POLICY = [
61
+ {
62
+ rule: ProductionRule.CANCEL_SUBSCRIPTION,
63
+ methods: ['DELETE'],
64
+ path: '/subscriptions?(/[^/]+)?/?$',
65
+ },
66
+ {
67
+ rule: ProductionRule.CANCEL_SUBSCRIPTION,
68
+ methods: ['POST', 'PUT', 'PATCH'],
69
+ path: '/subscriptions?(/[^/]+)?/cancel',
70
+ },
71
+ {
72
+ rule: ProductionRule.PAYMENT,
73
+ methods: ['POST', 'PUT', 'PATCH'],
74
+ path: '/(billing|checkout|payments?|subscriptions?|purchases?|orders?)(/|$)',
75
+ },
76
+ {
77
+ rule: ProductionRule.DELETE_WORKSPACE,
78
+ methods: ['DELETE'],
79
+ path: '/(workspaces?|orgs?|organi[sz]ations?|projects?)/[^/]+/?$',
80
+ },
81
+ { rule: ProductionRule.REVOKE_KEY, methods: ['DELETE'], path: '/(api-?)?keys?/[^/]+/?$' },
82
+ {
83
+ rule: ProductionRule.REVOKE_KEY,
84
+ methods: ['POST', 'PUT', 'PATCH'],
85
+ path: '/(api-?keys?|keys?|tokens?|secrets?)(/[^/]+)?/(rotate|revoke|regenerate|roll)',
86
+ },
87
+ {
88
+ rule: ProductionRule.SEND_INVITE,
89
+ methods: ['POST', 'PUT'],
90
+ path: '/(invites?|invitations?|emails?|mail)(/|$)',
91
+ },
92
+ {
93
+ rule: ProductionRule.CHANGE_ROLE,
94
+ methods: ['PATCH', 'PUT', 'POST'],
95
+ path: '/members?/[^/]+(/role)?/?$',
96
+ },
97
+ ];
98
+ /** What the refusal says. Every refusal is this sentence; nothing is a silent no-op. */
99
+ export const PRODUCTION_REFUSAL_PREFIX = 'refused: production policy: ';
100
+ export const productionRefusal = (rule) => `${PRODUCTION_REFUSAL_PREFIX}${rule}. ` +
101
+ (LIFTABLE_PRODUCTION_RULES.includes(rule)
102
+ ? 'A production drive does this only when its declared intent names it ' +
103
+ '(reticle_lease production.intent).'
104
+ : 'No intent allows this.');
105
+ // ── The activation ticket: daemon -> service ───────────────────────────────────────────────────
106
+ /** The service route that issues an activation ticket, authenticated with the person's API key. */
107
+ export const PRODUCTION_TICKET_PATH = '/v1/production-mode/tickets';
108
+ export const ProductionTicketRequestSchema = z.object({
109
+ workspaceId: z.string().min(1).max(128),
110
+ /** The single-use HELLO token the daemon minted for this drive. */
111
+ nonce: z.string().min(1).max(256),
112
+ /** The daemon's bridge port. The service puts it in the page's bootstrap and its CSP. */
113
+ bridgePort: z.number().int().min(1).max(65535),
114
+ scope: z.nativeEnum(HelloScope),
115
+ /**
116
+ * The site origin the lease opens: the ticket's `origin`. Optional only so an older daemon still
117
+ * gets a ticket; a service that is told it binds the ticket to it rather than guessing.
118
+ */
119
+ origin: z.string().url().max(2048).optional(),
120
+ /**
121
+ * The bridge the page must dial (`ws://127.0.0.1:<port>/reticle` for the daemon's own): the
122
+ * ticket's `bridge`. Optional for the same reason; absent, the service builds it from `bridgePort`.
123
+ */
124
+ bridge: z.string().url().max(2048).optional(),
125
+ });
126
+ export const ProductionTicketResponseSchema = z.object({
127
+ /** Signed by the service (format: `activation-ticket.ts`). The lease opens `<url>?reticle_activate=<ticket>`. */
128
+ ticket: z.string().min(1).max(4096),
129
+ /** When the ticket must be redeemed by (ISO 8601). Informational. */
130
+ expiresAt: z.string().max(64).optional(),
131
+ /** The service's own refused requests for this drive. Absent: `DEFAULT_PRODUCTION_POLICY`. */
132
+ policy: ProductionPolicySchema.optional(),
133
+ });
@@ -72,6 +72,8 @@ export declare const ReticleTool: {
72
72
  readonly INTENT: "reticle_intent";
73
73
  /** what THIS run has established, proved, and not yet discharged — pulled when memory is gone. */
74
74
  readonly CONTEXT: "reticle_context";
75
+ /** the app as the App Graph sees it, folded from the project's journals: screens, frontier, a path. */
76
+ readonly MAP: "reticle_map";
75
77
  readonly VERIFY: "reticle_verify";
76
78
  /** read cross-run history (.reticle/project.json) + diff-vs-last for a name. */
77
79
  readonly PROJECT: "reticle_project";
@@ -82,6 +82,8 @@ export const ReticleTool = {
82
82
  INTENT: 'reticle_intent',
83
83
  /** what THIS run has established, proved, and not yet discharged — pulled when memory is gone. */
84
84
  CONTEXT: 'reticle_context',
85
+ /** the app as the App Graph sees it, folded from the project's journals: screens, frontier, a path. */
86
+ MAP: 'reticle_map',
85
87
  VERIFY: 'reticle_verify',
86
88
  /** read cross-run history (.reticle/project.json) + diff-vs-last for a name. */
87
89
  PROJECT: 'reticle_project',