@powerhousedao/host-core 6.2.3-dev.100

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.
@@ -0,0 +1,651 @@
1
+ import { C as RunnerKind, et as OutputPath, h as ReactorConfig, l as HostDefinition, lt as TokenKey, m as ReactorBackendKind, n as ChildWrapper, p as ReactorBackend, x as ReactorStorageConfig, y as ReactorProtocol } from "./host-schemas-BM7F21lf.mjs";
2
+ import { t as BuiltinEnv } from "./env-substitution-C_fVirPh.mjs";
3
+ import { z } from "zod";
4
+ import { PHConnectDefaultDrive, PHConnectRuntimeConfig } from "@powerhousedao/shared/clis";
5
+ //#region src/backend-projection.d.ts
6
+ /**
7
+ * Phase 4 (track R): project named host backends onto reactor-monitor's
8
+ * `ReactorDescriptor` shape — the input `provision()` takes. Pure and
9
+ * dependency-free; a type-assignability test pins the output to the real
10
+ * `ReactorDescriptor` so an upstream field rename fails this package's tests
11
+ * instead of silently drifting (D2.b: aligned locally, upstreaming not
12
+ * blocked on).
13
+ */
14
+ /** The browser-provisionable storage union — reactor-monitor's
15
+ * `ReactorStorageConfig` shape. `postgres` is the SERVER extension (D2.b): a
16
+ * switchboard backend's storage, never a provisioned browser reactor's. */
17
+ type ProjectedStorage = {
18
+ kind: "idb";
19
+ } | {
20
+ kind: "memory";
21
+ } | {
22
+ kind: "path";
23
+ dataDir: string;
24
+ };
25
+ interface ProjectedDescriptor {
26
+ kind: "in-process" | "worker" | "remote";
27
+ name: string;
28
+ storage?: ProjectedStorage;
29
+ packages?: {
30
+ cdnUrl?: string;
31
+ specs?: string[];
32
+ dynamic?: boolean;
33
+ };
34
+ featureFlags?: {
35
+ documentDecisions?: boolean;
36
+ authEnforcement?: boolean;
37
+ authGroups?: boolean;
38
+ authConditions?: boolean;
39
+ undoV3?: boolean;
40
+ };
41
+ remote?: {
42
+ url: string;
43
+ };
44
+ }
45
+ /** One backend → one descriptor. The protocol's featureFlags ride every
46
+ * descriptor (they are fleet consensus, not per-backend). A remote backend
47
+ * must carry remote.url — provision() requires it. */
48
+ export declare function backendToDescriptor(name: string, backend: ReactorBackend, protocol?: ReactorProtocol): ProjectedDescriptor;
49
+ /** All named backends, in placement-primary-first order (the order a
50
+ * createReactorClients step would provision them). */
51
+ export declare function backendsToDescriptors(reactor: ReactorConfig | undefined): ProjectedDescriptor[];
52
+ /**
53
+ * Structural multi-reactor (phase 4): true when the block names BOTH a local
54
+ * backend (in-process/worker — the tab's own reactor) and a remote one. This
55
+ * is the shape Connect's routing client serves; a lone remote backend is an
56
+ * attach-only host (assistant/agent shape), not a routed tab.
57
+ */
58
+ export declare function isStructuralMultiReactor(reactor: ReactorConfig | undefined): boolean;
59
+ /** The remote backends' drive addresses, placement order. */
60
+ export declare function remoteBackendUrls(reactor: ReactorConfig | undefined): string[];
61
+ /** A switchboard as Connect's served config names it, with its connection settings. */
62
+ type ServedRemoteBackend = {
63
+ name: string;
64
+ url: string;
65
+ } & Omit<NonNullable<ReactorBackend["remote"]>, "url">;
66
+ //#endregion
67
+ //#region src/reactor-config.d.ts
68
+ /** A switchboard host's own store. Prefers placement.primary, else
69
+ * "main"/"local", else the first. Connect refuses placement.primary: its
70
+ * reactor is {@link browserBackend}. */
71
+ export declare function primaryBackend(reactor: ReactorConfig | undefined): ReactorBackend | undefined;
72
+ /** The env vars a protocol block maps onto, with their string values. Only
73
+ * keys the block actually sets appear. */
74
+ export declare function protocolEnv(protocol: ReactorProtocol | undefined): Record<string, string>;
75
+ /** The switchboard config layer a reactor block maps to (the shape of
76
+ * `@powerhousedao/switchboard/config`'s input). Only keys the block sets. */
77
+ interface SwitchboardReactorLayer {
78
+ storage?: {
79
+ reactor?: {
80
+ url: string;
81
+ };
82
+ readModel?: {
83
+ url: string;
84
+ };
85
+ };
86
+ protocol?: ReactorProtocol;
87
+ packages?: {
88
+ dynamic: true;
89
+ };
90
+ features?: {
91
+ workflows: boolean;
92
+ };
93
+ }
94
+ /** The reactor block as a switchboard config layer. The reactor store and the
95
+ * read model are separate fields: `readModel.url` never moves the reactor. */
96
+ export declare function reactorBlockToSwitchboardConfig(reactor: ReactorConfig | undefined): SwitchboardReactorLayer;
97
+ /** The four reactor-client shapes a Connect host can select (mirrors the
98
+ * shared PHReactorClientMode; kept local to avoid an import cycle). */
99
+ type ReactorClientMode = "in-process" | "worker" | "remote" | "router";
100
+ /** Connect's browser reactor: its first in-process or worker backend. */
101
+ export declare function browserBackend(reactor: ReactorConfig | undefined): (ReactorBackend & {
102
+ name: string;
103
+ }) | undefined;
104
+ /**
105
+ * Which reactor client the backend topology asks for:
106
+ * - local (in-process/worker) AND remote backends -> `router`
107
+ * - remote backend(s) only -> `remote`
108
+ * - a worker backend -> `worker`
109
+ * - anything else local -> `in-process`
110
+ * `undefined` when no backends are declared — the caller then keeps the
111
+ * legacy reactorWorker/multiReactor behaviour untouched.
112
+ */
113
+ export declare function reactorClientMode(reactor: ReactorConfig | undefined): ReactorClientMode | undefined;
114
+ /** The router settings Connect serves: only the keys the host sets. */
115
+ interface ConnectRouterSettings {
116
+ /** A remote backend's host key; absent, the browser reactor (or the only switchboard). */
117
+ newDrives?: string;
118
+ probeTimeoutMs?: number;
119
+ provisionalRouteMs?: number;
120
+ }
121
+ /** The stores a browser reactor can keep: IndexedDB or none. */
122
+ type ConnectStorageKind = "idb" | "memory";
123
+ /** Why the browser reactor's declared store can't be served: Connect keeps
124
+ * IndexedDB instead of a folder or Postgres. */
125
+ export declare function unservedConnectStorage(reactor: ReactorConfig | undefined): string | undefined;
126
+ interface ConnectReactorProjection {
127
+ /** Patch merged into the connect runtime config (connect.*). */
128
+ connect: {
129
+ reactor?: ReactorProtocol;
130
+ instance?: {
131
+ reactorWorker?: boolean;
132
+ reactorClient?: ReactorClientMode;
133
+ storage?: ConnectStorageKind;
134
+ remoteBackends?: ServedRemoteBackend[];
135
+ router?: ConnectRouterSettings;
136
+ };
137
+ app?: {
138
+ workflowsEnabled?: boolean;
139
+ };
140
+ };
141
+ }
142
+ /** Project the reactor block onto the Connect runtime config: protocol →
143
+ * connect.reactor (same shape), backend topology → instance.reactorWorker
144
+ * (the browser reactor's kind), instance.reactorClient, instance.storage
145
+ * (the browser reactor's store), and with a
146
+ * switchboard instance.remoteBackends and instance.router, workflows →
147
+ * app.workflowsEnabled. */
148
+ export declare function projectReactorToConnect(reactor: ReactorConfig | undefined): ConnectReactorProjection;
149
+ /** Whether an env value means what the host's value does. The switchboard
150
+ * reads REACTOR_UNDO_V3 as on unless it is exactly "false". */
151
+ export declare function protocolEnvAgrees(varName: string, envValue: string, hostValue: string): boolean;
152
+ /** Each pre-set env var that CONTRADICTS the host's protocol block, as a
153
+ * message naming the var, the host value and the env value. An env var that
154
+ * merely matches, or is unset, is fine. */
155
+ export declare function protocolConflicts(protocol: ReactorProtocol | undefined, env: Readonly<Record<string, string | undefined>>, hostFile?: string): string[];
156
+ /**
157
+ * The enforcement teeth of single-sourcing: if a pre-set env var CONTRADICTS
158
+ * the host's protocol block, fail loudly naming the var, the host value, and
159
+ * the env value (phase-2 transition keeps an operator's explicit env as an
160
+ * escape hatch unless it disagrees with the protocol — see the WBS
161
+ * precedence note).
162
+ */
163
+ export declare function assertProtocolConsistency(protocol: ReactorProtocol | undefined, env: Record<string, string | undefined>, hostFile?: string): void;
164
+ //#endregion
165
+ //#region src/child-wrapper.d.ts
166
+ /** A member's host.js with its wrapper applied, tokens unresolved. */
167
+ type MemberDraft = Record<string, unknown> & {
168
+ name: string;
169
+ runner: HostDefinition["runner"];
170
+ };
171
+ /** Generic compound rule: `reactor`/`config` replace, `runner` key-merges. */
172
+ export declare function applyChildWrapper(base: HostDefinition, wrapper: ChildWrapper): MemberDraft;
173
+ //#endregion
174
+ //#region src/connect-projection.d.ts
175
+ /**
176
+ * Concatenate groups of `connect.drives.defaultDrives` in the order given,
177
+ * de-duplicating by drive identity (URL for remote entries, id for local
178
+ * ones). The first occurrence of a drive wins, so earlier groups keep their
179
+ * position and metadata — e.g. the Vetra drive `ph vetra` starts stays first
180
+ * even when the project's `powerhouse.config.json` lists the same drive.
181
+ */
182
+ export declare function mergeDefaultDrives(...groups: PHConnectDefaultDrive[][]): PHConnectDefaultDrive[];
183
+ /**
184
+ * Rebase a local drive URL onto a public base: keeps the /d/<slug> path,
185
+ * swaps the loopback origin for the public base. Browser clients behind a
186
+ * reverse proxy can't reach http://localhost:<port>. Non-loopback URLs
187
+ * (e.g. a remote drive) are already public and pass through unchanged, as do
188
+ * unparseable ones.
189
+ */
190
+ export declare function rebaseDriveUrl(driveUrl: string, publicBase: string): string;
191
+ interface DriveProjectionInput {
192
+ /** Drive URLs the compound's reactor member created, in display order
193
+ * (e.g. vetra, preview, workflows). Null/undefined entries are skipped. */
194
+ createdDriveUrls: (string | null | undefined)[];
195
+ /** The project's configured `connect.drives.defaultDrives`. */
196
+ configuredDefaultDrives?: PHConnectDefaultDrive[];
197
+ /** `--drives-public-base`: advertise proxy-reachable URLs to the browser. */
198
+ publicBase?: string | null;
199
+ }
200
+ /**
201
+ * The compound's drives projection: created drives first (rebased onto the
202
+ * public base when given), then the project's configured drives, de-duplicated
203
+ * — and `preserve-all`, because compound-injected drive lists change per
204
+ * launch context and must never detach drives the user added by hand.
205
+ */
206
+ export declare function projectDrivesIntoConnect(input: DriveProjectionInput): Pick<PHConnectRuntimeConfig, "drives">;
207
+ //#endregion
208
+ //#region src/run-record-schema.d.ts
209
+ export declare const runRecordMemberSchema: z.ZodObject<{
210
+ host: z.ZodString;
211
+ runnerModule: z.ZodString;
212
+ kind: z.ZodEnum<{
213
+ compound: "compound";
214
+ reactor: "reactor";
215
+ }>;
216
+ verb: z.ZodString;
217
+ outputs: z.ZodRecord<z.ZodString, z.ZodUnknown>;
218
+ }, z.core.$strict>;
219
+ export declare const runRecordSchema: z.ZodObject<{
220
+ version: z.ZodLiteral<2>;
221
+ host: z.ZodString;
222
+ projectName: z.ZodString;
223
+ kind: z.ZodEnum<{
224
+ compound: "compound";
225
+ reactor: "reactor";
226
+ }>;
227
+ verb: z.ZodString;
228
+ pid: z.ZodNumber;
229
+ startedAt: z.ZodString;
230
+ outputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
231
+ members: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
232
+ host: z.ZodString;
233
+ runnerModule: z.ZodString;
234
+ kind: z.ZodEnum<{
235
+ compound: "compound";
236
+ reactor: "reactor";
237
+ }>;
238
+ verb: z.ZodString;
239
+ outputs: z.ZodRecord<z.ZodString, z.ZodUnknown>;
240
+ }, z.core.$strict>>>;
241
+ extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
242
+ }, z.core.$strict>;
243
+ type RunRecord = z.infer<typeof runRecordSchema>;
244
+ type RunRecordMember = z.infer<typeof runRecordMemberSchema>;
245
+ //#endregion
246
+ //#region src/resolve/declared.d.ts
247
+ /**
248
+ * Declared validation (pipeline step 3) of a host's tokens, before anything
249
+ * runs: operator shapes, `$env` `optional` placement, and every `$output`
250
+ * path against the producer's `outputsSchema`. No environment value is read
251
+ * and no producer needs to be running. Pure: producers are looked up through
252
+ * a callback the node side fills.
253
+ */
254
+ /** Which host's outputs a `$output` token names: `host` is the producer's
255
+ * FOLDER (`hosts/<host>/`); `member` picks one compound member when two
256
+ * share a host. */
257
+ interface OutputRef {
258
+ host: string;
259
+ member?: string;
260
+ }
261
+ interface DeclaredIssue {
262
+ /** Host path of the token (`runner.plugins[0].config.drive`). */
263
+ path: string;
264
+ message: string;
265
+ }
266
+ export declare function refKey(ref: OutputRef): string;
267
+ /** The distinct producers a host's `$output` tokens name, in document order. */
268
+ export declare function outputRefsOf(host: unknown): OutputRef[];
269
+ /** Every `$output` token with its host path and producer (for the plan and
270
+ * `--explain outputs`). */
271
+ export declare function outputSitesOf(host: unknown): {
272
+ path: string;
273
+ ref: OutputRef;
274
+ outputPath: OutputPath;
275
+ }[];
276
+ /** Every `$env` token with its host path (for `--explain outputs`). */
277
+ export declare function envSitesOf(host: unknown): {
278
+ path: string;
279
+ name: string;
280
+ optional: boolean;
281
+ }[];
282
+ /** Operator shapes and placement: malformed operands, `$item`/`$key`
283
+ * outside any `$map` or naming an unknown binding, and
284
+ * `{ $env: { name, optional: true } }` anywhere but the direct value of an
285
+ * object property (it omits that property when unset). */
286
+ export declare function checkTokenSites(host: unknown): DeclaredIssue[];
287
+ /** What a producer lookup yields: its runner's `outputsSchema` (any zod
288
+ * instance), or why there is none. */
289
+ type OutputsSchemaLookup = {
290
+ schema: unknown;
291
+ label: string;
292
+ } | {
293
+ error: string;
294
+ };
295
+ /** The schema at `path` inside a zod schema (walking objects, records,
296
+ * arrays, tuples, unions and wrappers), or why the path does not exist. */
297
+ export declare function schemaAtPath(schema: unknown, path: OutputPath): {
298
+ ok: true;
299
+ schema: unknown;
300
+ } | {
301
+ ok: false;
302
+ at: number;
303
+ reason: string;
304
+ };
305
+ /** Every `$output` token's producer exists and its path is valid against
306
+ * the producer's `outputsSchema`; every `$map`'s `over` is a collection
307
+ * there (a record under `into: "record"`), and every `$item` path exists
308
+ * in the element schema of the map it binds. */
309
+ export declare function checkOutputPaths(host: unknown, outputsSchemaOf: (ref: OutputRef) => OutputsSchemaLookup): DeclaredIssue[];
310
+ //#endregion
311
+ //#region src/resolve/plan.d.ts
312
+ /**
313
+ * The dependency plan (pipeline step 4): which compound member consumes
314
+ * which member's outputs, and the start order that follows. Producers start
315
+ * before consumers; `config.startOrder` is optional and, when given, must
316
+ * agree with the tokens. Cycles fail. Pure.
317
+ */
318
+ export declare class PlanError extends Error {
319
+ constructor(message: string);
320
+ }
321
+ interface PlanMember {
322
+ /** The member key (`children.<key>`). */
323
+ key: string;
324
+ /** The member's host folder (`children.<key>.host`). */
325
+ host: string;
326
+ /** The producers its tokens name, with the host path of one token each. */
327
+ refs: {
328
+ ref: OutputRef;
329
+ path: string;
330
+ }[];
331
+ }
332
+ interface PlanEdge {
333
+ consumer: string;
334
+ producer: string;
335
+ /** Host path in the consumer of the (first) token behind this edge. */
336
+ path: string;
337
+ }
338
+ interface CompoundPlan {
339
+ /** Member keys in start order. */
340
+ order: string[];
341
+ edges: PlanEdge[];
342
+ /** "tokens": derived from the dependencies; "startOrder": the declared
343
+ * order, checked against them. */
344
+ source: "tokens" | "startOrder";
345
+ }
346
+ /** The member a ref names: the unique member running `ref.host`, or the
347
+ * member `ref.member` when given (it must run `ref.host`). */
348
+ export declare function memberForRef(ref: OutputRef, members: readonly Pick<PlanMember, "key" | "host">[]): {
349
+ key: string;
350
+ } | {
351
+ error: string;
352
+ };
353
+ export declare function planCompound(members: readonly PlanMember[], startOrder?: readonly string[]): CompoundPlan;
354
+ //#endregion
355
+ //#region src/resolve/resolve.d.ts
356
+ /**
357
+ * The resolver (pipeline step 5): replaces every token in a declared host
358
+ * with its value. `$output` reads the producer's outputs through an
359
+ * `OutputSource` (live compound members, or a standalone run record: the
360
+ * node adapters in ./node.ts); `$env` reads the environment map of the
361
+ * resolving process; `$map` renders its `to` template once per element of
362
+ * its `over` (arrays in order, records key-sorted; `$item`/`$key` read the
363
+ * element being rendered); the `"${userData}"`/`"${projectRoot}"` string
364
+ * sugar is substituted on the way. An `$output`/`$item` that reads a field
365
+ * absent from the data but optional in the producer's schema (codegen's
366
+ * `OutputToken<T | undefined>`) omits its enclosing property, like an unset
367
+ * optional `$env`. Pure and browser-safe.
368
+ */
369
+ type OutputLookup = {
370
+ status: "available";
371
+ outputs: unknown;
372
+ /** The producer's `outputsSchema`, when known: an absent field it
373
+ * marks optional omits the consuming property instead of failing. */
374
+ schema?: unknown;
375
+ } |
376
+ /** `message` is the complete, user-facing reason (e.g. "connect needs
377
+ * outputs from host "switchboard", which is not running. …"). */
378
+ {
379
+ status: "unavailable";
380
+ message: string;
381
+ };
382
+ interface OutputSource {
383
+ lookup(ref: OutputRef): OutputLookup;
384
+ }
385
+ interface ResolveSources {
386
+ /** Where `$output` tokens read. Absent: any `$output` fails. */
387
+ outputs?: OutputSource;
388
+ /** The resolving process's environment (`$env`). */
389
+ env?: Readonly<Record<string, string | undefined>>;
390
+ /** `userData`/`projectRoot`: always resolvable `$env` names and string
391
+ * sugar. */
392
+ builtins?: BuiltinEnv;
393
+ /** The host file named in errors (`hosts/connect/host.js`). */
394
+ where?: string;
395
+ }
396
+ export declare class TokenResolutionError extends Error {
397
+ /** The host path that failed and the reason, without the file prefix. */
398
+ readonly detail?: {
399
+ path: string;
400
+ reason: string;
401
+ };
402
+ constructor(message: string, detail?: {
403
+ path: string;
404
+ reason: string;
405
+ });
406
+ }
407
+ /**
408
+ * The `$map` elements an issue path (from resolved validation of a resolved
409
+ * host) passes through, as text: `$map element "workflows"`. Undefined when
410
+ * the path crosses no `$map`-rendered array. Walk the SAME object
411
+ * `resolveHostOutputs` returned (provenance is by identity).
412
+ */
413
+ export declare function describeMapElements(host: unknown, path: readonly PropertyKey[]): string | undefined;
414
+ /** A compound's own member set, for `deferSelf`. */
415
+ interface SelfMembers {
416
+ /** The compound's members: key (`children.<key>`) and host folder. */
417
+ members: readonly {
418
+ key: string;
419
+ host: string;
420
+ }[];
421
+ }
422
+ /** A token in a compound's own fields that reads one of its members. */
423
+ interface DeferredToken {
424
+ /** Host path (`config.agents.assistant.url`). */
425
+ path: string;
426
+ /** The member keys whose outputs it needs. */
427
+ members: string[];
428
+ }
429
+ interface DeferredResolution<T> {
430
+ /** The host with every token resolved EXCEPT the deferred ones (still in
431
+ * place) and the `children` wrappers (member-level: each member resolves
432
+ * its own). */
433
+ host: T;
434
+ deferred: DeferredToken[];
435
+ /** The member keys any deferred token needs (start them first). */
436
+ needs: string[];
437
+ /** Resolve the deferred tokens once those members have started, from
438
+ * their live outputs (e.g. `compoundOutputSource`); returns the fully
439
+ * resolved host (children still untouched). */
440
+ finish(outputs: OutputSource): T;
441
+ }
442
+ interface ResolveOptions {
443
+ /** Resolving a COMPOUND's own fields: tokens that read one of its members
444
+ * are deferred until those members have started (see
445
+ * `DeferredResolution`); `children` is left for the members. `"outputs"`
446
+ * defers every `$output` (its `members` are the producers' ref keys). */
447
+ deferSelf: SelfMembers | "outputs";
448
+ }
449
+ /**
450
+ * Resolve every token in a declared host (or any JSON-shaped value): the
451
+ * result has the same shape with tokens replaced by values, optional unset
452
+ * `$env` properties omitted and the built-in string sugar substituted (`$$`
453
+ * escapes are kept; validateHost unwraps them). Throws `TokenResolutionError` naming the host path;
454
+ * an `$output` whose producer is not running fails with the source's
455
+ * message (no fallback, no waiting).
456
+ *
457
+ * With `{ deferSelf }` (a compound resolving its own fields), returns a
458
+ * `DeferredResolution` instead: everything but the self-references now,
459
+ * and `finish(outputs)` for the rest once the members it needs run.
460
+ */
461
+ export declare function resolveHostOutputs<T>(host: T, sources: ResolveSources): T;
462
+ export declare function resolveHostOutputs<T>(host: T, sources: ResolveSources, options: ResolveOptions): DeferredResolution<T>;
463
+ //#endregion
464
+ //#region src/resolve/removed-forms.d.ts
465
+ /**
466
+ * The cross-host forms removed in T3 (typed-host-configs 3.7), detected
467
+ * before schema validation so the error names the token form that replaces
468
+ * each one instead of a bare "Unrecognized key". clint's `agents.*.host` and
469
+ * proxy `routes.*.member` are checked by the clint runner schemas.
470
+ */
471
+ interface RemovedForm {
472
+ /** Host path of the removed value. */
473
+ path: string;
474
+ message: string;
475
+ }
476
+ /** Every removed form in a host file (reactor or compound), in document
477
+ * order. Compound wrappers are checked too. */
478
+ export declare function findRemovedForms(host: unknown): RemovedForm[];
479
+ //#endregion
480
+ //#region src/resolve/sources.d.ts
481
+ /**
482
+ * The compound output source: a member's `$output` tokens read the live
483
+ * `RunnerHandle.outputs` of the members started before it. `schemas` (member
484
+ * key → its runner's `outputsSchema`) lets an absent optional output field
485
+ * omit the consuming property. Pure (the run-record source for standalone
486
+ * hosts is node: ./node.ts).
487
+ */
488
+ export declare function compoundOutputSource(members: readonly {
489
+ key: string;
490
+ host: string;
491
+ }[], started: ReadonlyMap<string, unknown>, compound: string, schemas?: ReadonlyMap<string, unknown>): OutputSource;
492
+ //#endregion
493
+ //#region src/resolve/walk.d.ts
494
+ /**
495
+ * Token discovery over a declared (JSON-shaped) host: where every operator
496
+ * sits and in which syntactic position, which is what declared validation
497
+ * (`$env` optional placement), the dependency plan and `--explain outputs`
498
+ * read. Pure: no node imports.
499
+ */
500
+ /** Where a token sits: the direct value of an object property, an array
501
+ * element, the whole value, a `$concat` part, a `$map`'s `over`, or the
502
+ * whole `to` template of a `$map` (the top of the rendered element). */
503
+ type TokenPosition = "property" | "element" | "root" | "concat" | "over" | "template";
504
+ /** An enclosing `$map`, as seen from a token inside its `to` template. */
505
+ interface MapScope {
506
+ /** Host path of the `$map` token. */
507
+ path: OutputPath;
508
+ /** Its binding name (`$map.as`), if any. */
509
+ as?: string;
510
+ /** The `$map` token itself. */
511
+ token: Record<string, unknown>;
512
+ }
513
+ interface TokenSite {
514
+ /** Property keys and array indices from the host root to the token
515
+ * (`$map` operands appear as `…$map.over` / `…$map.to…`). */
516
+ path: OutputPath;
517
+ key: TokenKey;
518
+ /** The token object itself (`{ $output: … }`, …). */
519
+ token: Record<string, unknown>;
520
+ position: TokenPosition;
521
+ /** The `$map`s whose template holds this token, outermost first (the
522
+ * innermost binding is last). A map's own `over` is in its OUTER scope. */
523
+ scopes: readonly MapScope[];
524
+ }
525
+ /** `a.b[2].c` (or `<root>`). */
526
+ export declare function formatPath(path: readonly (string | number)[]): string;
527
+ /** Every token in `value`, in document order. `$concat` parts and `$map`
528
+ * operands (`over`, then the `to` template) are visited: they may hold tokens
529
+ * themselves. Each site carries the `$map` scopes it sits in. A `$$` escape
530
+ * hides its operand. */
531
+ export declare function collectTokenSites(value: unknown): TokenSite[];
532
+ /** A one-line human rendering of a token, for `--explain` and messages. */
533
+ export declare function describeToken(token: unknown): string;
534
+ /** A display copy of `value` with every token replaced by `«description»`
535
+ * (for printing declared hosts, e.g. `--explain drives`). */
536
+ export declare function renderTokens<T>(value: T): T;
537
+ /** A copy of `value` with every `$$` escape replaced by its operand (the
538
+ * literal it protects). Run after the no-token walk. */
539
+ export declare function unwrapEscapes<T>(value: T): T;
540
+ //#endregion
541
+ //#region src/expect-host.d.ts
542
+ /**
543
+ * What a host amounts to once its pipeline has run (typed-host-configs G2,
544
+ * 2.2): the reactor-client shape its backends select, the drives it serves
545
+ * or attaches, the producers whose outputs it consumes and, for a compound,
546
+ * the start order and each member's expectation. Pure and platform-neutral:
547
+ * the caller runs load → declared validation → resolve → resolved
548
+ * validation (and plugin contribution discovery) and hands over the
549
+ * results. The returned value is JSON-only, so it can be pinned in a test
550
+ * table or shipped to another process (a future reactor-monitor).
551
+ */
552
+ /** One backend, in placement-primary-first order. */
553
+ interface ExpectedBackend {
554
+ name: string;
555
+ kind: ReactorBackendKind;
556
+ storage?: ReactorStorageConfig["kind"];
557
+ /** The RESOLVED storage dir (`"${userData}"` sugar and `$env` applied). */
558
+ dataDir?: string;
559
+ /** Why a provisioned reactor (a browser tab, reactor-monitor) cannot be
560
+ * built from this backend (`backendToDescriptor`): e.g. postgres storage
561
+ * is server-side only, a remote backend needs `remote.url`. Absent when
562
+ * it can. A switchboard's own backend may legitimately carry one. */
563
+ provisionError?: string;
564
+ }
565
+ /** One drive of the merged plan: plugin contributions first, then the
566
+ * host's own declarations (the host wins a slug). Identity is the DECLARED
567
+ * slug: a `projectHash` drive reports the flag, not a hashed id, so the
568
+ * expectation does not depend on where the project lives. */
569
+ interface ExpectedDrive {
570
+ slug: string;
571
+ kind: "local" | "remote";
572
+ /** "host" for `reactor.drives`; the plugin name for a contribution. */
573
+ source: string;
574
+ /** A remote drive's resolved URL. */
575
+ url?: string;
576
+ id?: string;
577
+ projectHash?: boolean | "id";
578
+ }
579
+ /** One `$output` token in the declared host. */
580
+ interface ConsumedOutput {
581
+ /** Host path of the token (`reactor.backends.sb.remote.url`). */
582
+ at: string;
583
+ host: string;
584
+ member?: string;
585
+ path: OutputPath;
586
+ }
587
+ interface HostExpectation {
588
+ name: string;
589
+ kind: RunnerKind;
590
+ /** The verb this host runs at: `runner.defaultVerb ?? "run"` standalone;
591
+ * for a compound member, its own effective verb under the compound's. */
592
+ verb: string;
593
+ /** Reactor hosts with backends: `reactorClientMode`. */
594
+ clientMode?: ReactorClientMode;
595
+ /** Reactor hosts: local AND remote backends (Connect's routing client). */
596
+ multiReactor?: boolean;
597
+ backends?: ExpectedBackend[];
598
+ /** The resolved URLs of the remote backends, placement order. */
599
+ remotes?: string[];
600
+ drives?: ExpectedDrive[];
601
+ /** Producers its own tokens read (`host` or `host#member`), sorted. */
602
+ dependsOn: string[];
603
+ consumes: ConsumedOutput[];
604
+ /** `$env` names its own tokens read, sorted (values are not recorded). */
605
+ env: string[];
606
+ /** Compound: member keys in start order. */
607
+ startOrder?: string[];
608
+ /** Compound: each member's expectation. */
609
+ members?: Record<string, MemberExpectation>;
610
+ }
611
+ interface MemberExpectation extends Omit<HostExpectation, "startOrder" | "members"> {
612
+ /** The member's host folder (`children.<key>.host`). */
613
+ host: string;
614
+ /** Member keys this member consumes (it starts after them), sorted. */
615
+ after: string[];
616
+ }
617
+ /** A drive a plugin contributes, as plugin contribution discovery reports
618
+ * it (`resolvePluginContributions`). */
619
+ interface ContributedDriveInput {
620
+ declaration: Record<string, unknown>;
621
+ source: string;
622
+ }
623
+ interface ExpectHostInput {
624
+ kind: RunnerKind;
625
+ /** The host as declared (tokens in place); a compound member's draft
626
+ * (its host.js with the wrapper applied). */
627
+ declared: Record<string, unknown>;
628
+ /** The resolved (and parsed) host. Default: `declared`. */
629
+ resolved?: Record<string, unknown>;
630
+ /** Drives the host's plugins contribute at its verb. */
631
+ contributed?: readonly ContributedDriveInput[];
632
+ /** Compound: its members, any order (the plan orders them). */
633
+ members?: readonly MemberInput[];
634
+ /** Compound: the dependency plan (`planCompound`). */
635
+ plan?: CompoundPlan;
636
+ }
637
+ interface MemberInput extends Omit<ExpectHostInput, "members" | "plan"> {
638
+ key: string;
639
+ host: string;
640
+ }
641
+ /**
642
+ * The expectation for one host. A reactor host's comes from its resolved
643
+ * reactor block and contributed drives; a compound's lists its members in
644
+ * plan order, each with the verb it runs at under the compound's own verb
645
+ * and the members it starts after.
646
+ */
647
+ export declare function expectHost(input: ExpectHostInput): HostExpectation;
648
+ //#endregion
649
+ export type { CompoundPlan, ConnectReactorProjection, ConnectRouterSettings, ConnectStorageKind, ConsumedOutput, ContributedDriveInput, DeclaredIssue, DeferredResolution, DeferredToken, DriveProjectionInput, ExpectHostInput, ExpectedBackend, ExpectedDrive, HostExpectation, MemberDraft, MemberExpectation, MemberInput, OutputLookup, OutputRef, OutputSource, OutputsSchemaLookup, PlanEdge, PlanMember, ProjectedDescriptor, ProjectedStorage, ReactorClientMode, RemovedForm, ResolveOptions, ResolveSources, RunRecord, RunRecordMember, SelfMembers, SwitchboardReactorLayer, TokenPosition, TokenSite };
650
+ export {};
651
+ //# sourceMappingURL=projection.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection.d.mts","names":[],"sources":["../src/backend-projection.ts","../src/reactor-config.ts","../src/child-wrapper.ts","../src/connect-projection.ts","../src/run-record-schema.ts","../src/resolve/declared.ts","../src/resolve/plan.ts","../src/resolve/resolve.ts","../src/resolve/removed-forms.ts","../src/resolve/sources.ts","../src/resolve/walk.ts","../src/expect-host.ts"],"mappings":";;;;;;;;;;;;;;;;KAmBY;EACN;;EACA;;EACA;EAAc;;UAEH;EACf;EACA;EACA,UAAU;EACV;IAAa;IAAiB;IAAkB;;EAChD;IACE;IACA;IACA;IACA;IACA;;EAEF;IAAW;;;;;;wBAgCG,oBACd,cACA,SAAS,gBACT,WAAW,kBACV;;;wBA2Ba,sBACd,SAAS,4BACR;;;;;;;wBAsBa,yBACd,SAAS;;wBAWK,kBACd,SAAS;;KASC;EAAwB;EAAc;IAAgB,KAChE,YAAY;;;;;;wBCjHE,eACd,SAAS,4BACR;;;wBA4Ba,YACd,UAAU,8BACT;;;UAmBc;EACf;IAAY;MAAY;;IAAe;MAAc;;;EACrD,WAAW;EACX;IAAa;;EACb;IAAa;;;;;wBAKC,gCACd,SAAS,4BACR;;;KAuBS;;wBAQI,eACd,SAAS,6BACP;EAAmB;;;;;;;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