@intentius/chant 0.64.0 → 0.65.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.
@@ -0,0 +1,999 @@
1
+ /**
2
+ * The behaviour prediction contract (#2356) — what a lexicon's
3
+ * `predictBehaviour()` is allowed to mean.
4
+ *
5
+ * `describeResources()` (./observation.ts) answers whether a declared entity
6
+ * exists. `observeResourcesDeep()` (./deep-observation.ts) answers what its
7
+ * properties currently are. Both report facts a substrate was asked for. This
8
+ * third axis reports something no substrate holds: what the declared estate
9
+ * would *do* at a stated traffic level — cost per hour, how far each entity is
10
+ * from saturation, the error rate to expect, whether it survives a named
11
+ * failure, and a smaller size that would still carry the load.
12
+ *
13
+ * None of that is a measurement, and the type is built so it cannot be read as
14
+ * one.
15
+ *
16
+ * ## A prediction is not a bill
17
+ *
18
+ * The one failure mode that matters here is somebody quoting a modeled figure
19
+ * as money owed. Four things in this module work against that, and it is worth
20
+ * being exact about how much they buy, because an overstated guarantee is how
21
+ * a consumer ends up trusting one:
22
+ *
23
+ * 1. Money appears in exactly one shape, {@link PredictedRate}, and that
24
+ * shape carries a literal `rate: "per-hour"` discriminant. There is no
25
+ * field anywhere for an amount, a period, an account, an invoice or a
26
+ * due date, so an elapsed charge is not expressible *in this module's
27
+ * types*.
28
+ * 2. A figure cannot exist without {@link PredictedBehaviour.at}, the traffic
29
+ * level it was predicted for. A bill is for an hour that happened; this is
30
+ * for an hour the engine was asked to imagine.
31
+ * 3. {@link BehaviourProvenance} is required on every entity, and its
32
+ * {@link BehaviourProvenance.basis} is a closed two-value enum: `modeled`
33
+ * off list prices, or `validated` against a real bill. A figure that will
34
+ * not say which of the two it is cannot be constructed.
35
+ * 4. A refusal is a separate member of the {@link BehaviourResult} union with
36
+ * no figures on it at all, so "the engine is gone" and "the engine says
37
+ * zero" are different objects rather than the same object with zeroes in
38
+ * it. This one is airtight: there is no `entities` key on the refusal arm
39
+ * to be empty and no total to be zero.
40
+ *
41
+ * **What this does not do is make a bill a type error.** A consumer holding a
42
+ * {@link PredictedBehaviour} can write
43
+ * `const { rate, ...rest } = cost; return { amount: rest.perHour * hours }`
44
+ * and TypeScript will not object; the discriminant is a field on an object, and
45
+ * a field can be dropped. behold's own validator rebuilds `cost` as
46
+ * `{ perHour, currency }` and its estate sum carries no discriminant at all, so
47
+ * the marker is stripped by the first consumer *by design*. What the shape
48
+ * genuinely buys is that a bill cannot be constructed **accidentally** — every
49
+ * route from a prediction to something that reads as money owed has a
50
+ * deliberate destructure or cast in it, and shows up in review as one. Treat
51
+ * rules 1 to 3 as a speed bump with a name, and rule 4 as the enforced one.
52
+ *
53
+ * ## The engine sees no credential and writes nothing
54
+ *
55
+ * {@link PredictBehaviourOptions} mirrors `observeResourcesDeep`'s options
56
+ * field for field, plus `traffic`, `edges` and `edgeCoverage`, and then works
57
+ * against credentials on two levels. The type declares every obvious name
58
+ * `?: never`, which catches the deliberate attempt; and
59
+ * {@link screenBehaviourRequest} walks the whole request at runtime, matching
60
+ * credential-shaped **values** as well as credential-shaped keys, which is what
61
+ * catches the accident.
62
+ *
63
+ * `screenBehaviourRequest` is the one entry point — its own doc comment carries
64
+ * the call sequence, and nothing else here restates it. The runtime walk is the
65
+ * load-bearing half, because the type cannot see the two channels that actually
66
+ * carry a secret in practice: `entities[*].props` is `Record<string, unknown>`
67
+ * straight out of the build, and a lexicon surfacing a connection string puts
68
+ * one there without deciding to. See {@link assertNoCredentialInOptions} for
69
+ * exactly what the walk detects and, more importantly, what it does not.
70
+ *
71
+ * `edges` is the one place the options mirror breaks, and the field's own doc
72
+ * says why: the epic's input is a resource graph, a deep read has no use for
73
+ * neighbours, and a prediction is nothing but statements about paths through
74
+ * the estate. It carries `IREdge` (./graph-ir.ts) rather than an edge type of
75
+ * this contract's own, because that is already the shape both the declared
76
+ * path and the live path produce.
77
+ *
78
+ * Nothing in the options is a handle. There is no client, no transport, no
79
+ * apply callback, no writer — only strings, a name list and the entity map the
80
+ * build already produced. An engine handed this cannot reach the account even
81
+ * if it wanted to, which is the structural half of "it never writes".
82
+ *
83
+ * ## The tri-state, and why it is not `UnobservedReason`
84
+ *
85
+ * Behaviour keeps the same three-verdict discipline `./observation.ts`
86
+ * established — PREDICTED, NOT-PREDICTABLE-FOR-THIS-KIND, and NOT-PREDICTED
87
+ * with a named reason — but on a stricter total: every entity the caller asked
88
+ * about lands in `entities` or in `unpredicted`, never in neither. The thin
89
+ * read needs a third position because "the provider says it is not there" is a
90
+ * real answer with no row to sit on. A prediction has no such answer. An entity
91
+ * either got a figure or it did not, and when it did not there is a reason,
92
+ * so an entity in neither map means the lexicon lost track of it.
93
+ *
94
+ * {@link BehaviourUnpredictedReason} derives from `UnobservedReason` rather
95
+ * than restating it, so the four shared verdicts provably keep their spelling
96
+ * and their meaning. It differs in two ways, both deliberate:
97
+ *
98
+ * - `no-credentials` is **excluded**. A behaviour read has no credential to
99
+ * be missing — see the section above — so an enum that could say it would
100
+ * be inviting a lexicon to send an operator hunting for a variable this
101
+ * contract forbids.
102
+ * - Four reasons about the predictor itself are **added** — `no-engine`,
103
+ * `engine-unreachable`, `engine-out-of-credit` and `engine-over-quota` —
104
+ * because the epic wants a missing engine named and `no-binding` is about
105
+ * the environment resolving to no target, a different axis. They are four
106
+ * rather than one because each has a different remedy, and a refusal that
107
+ * names the wrong remedy is worse than a slow one: set a variable, check an
108
+ * address, pay for the account, or wait for a window. The last two arrive
109
+ * from an engine that answered perfectly well (#2359), so folding them into
110
+ * `engine-unreachable` would send somebody to debug a network that is fine.
111
+ *
112
+ * ## Deltas: the invariant is here, the presentation is not
113
+ *
114
+ * The epic wants a declared prediction and a live prediction shown as a delta,
115
+ * and #2358 posts one on a merge request. This module deliberately ships no
116
+ * delta type and no differencing function. What it ships is the one thing a
117
+ * hand-rolled diff silently loses, which is that a figure's context does not
118
+ * survive subtraction: {@link compareFigures} classifies a pair `comparable`,
119
+ * `mixed-basis`, `mixed-level` or `mixed-engine`, and the rule this contract
120
+ * binds its consumers to is that anything but `comparable` must be marked
121
+ * wherever it is shown. A `modeled` figure minus a `validated` one is not a
122
+ * change in the estate; part of that difference is the gap between a price list
123
+ * and an invoice. Nor is a 100 rps figure minus a 1000 rps one, which is why
124
+ * {@link compareProvenance} — which cannot see `at` and never could — is not
125
+ * the function to reach for. How the mark looks is #2358's to define. Whether
126
+ * there is one is not.
127
+ *
128
+ * ## Shape compatibility with the overlay
129
+ *
130
+ * {@link PredictedBehaviour} is the object `chant graph --live --overlay` puts
131
+ * on a node as `attrs._behaviour`.
132
+ *
133
+ * On the graph, `meta._behaviour` takes {@link BehaviourReportMeta} **or the
134
+ * whole {@link BehaviourRefusalReport}** — not a bare {@link BehaviourRefusal}.
135
+ * behold reads that key as `{ engine?, version?, at?, total?, refusal? }` and
136
+ * branches on the presence of `refusal`, so a bare `BehaviourRefusal` has no
137
+ * `refusal` key, falls through to the engine check, and is dropped as
138
+ * "meta.engine missing" — a refusal that renders as nothing at all, which is
139
+ * the one outcome this contract exists to prevent. #2360 implements this
140
+ * sentence, so it says what behold does.
141
+ *
142
+ * behold reads those keys and does arithmetic on the engine's figures; it never
143
+ * produces one of its own. Fields beyond what it reads (`cause` and `source` on
144
+ * a refusal, `edgeCoverage` on the meta) are additive and ignorable.
145
+ */
146
+ import type { UnobservedReason } from "./observation.js";
147
+ import type { IREdge } from "./graph-ir.js";
148
+ import type { DanglingRef } from "./graph-refs.js";
149
+ /**
150
+ * Whether a figure came off a price list or off a bill. Closed, and required on
151
+ * every prediction — this is the distinction that keeps rule 1 enforceable.
152
+ *
153
+ * - `modeled` — computed from published list prices and the engine's own model.
154
+ * The honest default, and the word a badge shows unless told otherwise.
155
+ * - `validated` — reconciled against a real invoice for a comparable estate.
156
+ */
157
+ export type BehaviourBasis = "modeled" | "validated";
158
+ export declare const BEHAVIOUR_BASES: readonly BehaviourBasis[];
159
+ /** True when `value` is a legal {@link BehaviourBasis}. */
160
+ export declare function isBehaviourBasis(value: unknown): value is BehaviourBasis;
161
+ /**
162
+ * Where one entity's numbers came from and how far they can be trusted.
163
+ * Required on every {@link PredictedBehaviour}, and per entity rather than per
164
+ * report, because one estate can be priced by two engines.
165
+ */
166
+ export interface BehaviourProvenance {
167
+ /** The engine that produced the figures, as it names itself (`acme-sim`). */
168
+ engine: string;
169
+ /** That engine's own version string (`1.4.2`). Never inferred. */
170
+ version: string;
171
+ /**
172
+ * The engine's stated tolerance, echoed verbatim (`±15%`). chant does not
173
+ * parse it and does not invent one for an engine that states none — an engine
174
+ * with nothing to say here has no business publishing a figure.
175
+ */
176
+ tolerance: string;
177
+ /** List prices, or a real bill. See {@link BehaviourBasis}. */
178
+ basis: BehaviourBasis;
179
+ }
180
+ /**
181
+ * The traffic level a prediction is for. A string the engine names and chant
182
+ * echoes, never a number chant does arithmetic on: `100 rps, p50`, `peak hour,
183
+ * black friday`, `steady state`. Required, because a figure without the
184
+ * question it answers is the figure most likely to be quoted as a bill.
185
+ */
186
+ export interface BehaviourTrafficLevel {
187
+ traffic: string;
188
+ }
189
+ /**
190
+ * Money, in the only shape this module has for it: a rate for one hypothetical
191
+ * hour at a stated traffic level.
192
+ *
193
+ * The literal `rate: "per-hour"` is load-bearing. It makes the type structurally
194
+ * distinct from any billing record — nothing that models an amount charged
195
+ * carries that field — so a `PredictedRate` cannot be passed where a charge is
196
+ * wanted, and a charge cannot be passed here.
197
+ */
198
+ export interface PredictedRate {
199
+ /** Discriminant. A rate for an imagined hour, never an amount charged for a real one. */
200
+ readonly rate: "per-hour";
201
+ /** The rate itself, in `currency` per hour. */
202
+ perHour: number;
203
+ /** ISO 4217 code, as the engine states it. chant converts nothing. */
204
+ currency: string;
205
+ }
206
+ /** Build a {@link PredictedRate}. Lexicons use this rather than writing the discriminant by hand. */
207
+ export declare function predictedRate(perHour: number, currency: string): PredictedRate;
208
+ /**
209
+ * How much of each axis is still free at the stated traffic level, as a
210
+ * fraction in `0..1`. Both axes are optional and an axis the engine does not
211
+ * model is **absent**, never `0` — zero headroom means saturated, which is the
212
+ * opposite claim.
213
+ */
214
+ export type BehaviourHeadroom = {
215
+ cpu: number;
216
+ latency?: number;
217
+ } | {
218
+ cpu?: number;
219
+ latency: number;
220
+ };
221
+ /** What an entity does when the named failure happens. Closed. */
222
+ export type ResilienceVerdict = "survives" | "degrades" | "fails";
223
+ /** Every legal {@link ResilienceVerdict}, for validation and conformance checks. */
224
+ export declare const RESILIENCE_VERDICTS: readonly ResilienceVerdict[];
225
+ /** True when `value` is a legal {@link ResilienceVerdict}. */
226
+ export declare function isResilienceVerdict(value: unknown): value is ResilienceVerdict;
227
+ /** The verdict under one named failure, and which failure it was tested against. */
228
+ export interface BehaviourResilience {
229
+ /**
230
+ * The failure, named by the engine and echoed verbatim: `one zone lost`,
231
+ * `primary database failover`. A verdict without its failure says nothing.
232
+ */
233
+ failure: string;
234
+ verdict: ResilienceVerdict;
235
+ /** Free text from the engine, when it has more to say than the verdict. */
236
+ note?: string;
237
+ }
238
+ /** A smaller size the engine believes would still carry the stated traffic. */
239
+ export interface BehaviourRightSize {
240
+ /** The size, in the provider's own vocabulary (`t3.small`, `db-f1-micro`). */
241
+ suggestion: string;
242
+ /** Why. A suggestion nobody can evaluate is noise. */
243
+ reason?: string;
244
+ }
245
+ /**
246
+ * One entity's prediction — the object that rides as `attrs._behaviour` on an
247
+ * overlay node.
248
+ *
249
+ * Everything here except `rightSize`, `resilience.note` and either
250
+ * {@link BehaviourHeadroom} axis is required. An entity the engine could not
251
+ * price does not get a thinned-out version of this block; it goes in
252
+ * {@link BehaviourReport.unpredicted} with a reason.
253
+ */
254
+ export interface PredictedBehaviour {
255
+ /** The traffic level every figure below is for. */
256
+ at: BehaviourTrafficLevel;
257
+ /** Cost per hour at `at`. */
258
+ cost: PredictedRate;
259
+ /** Distance from saturation at `at`. A modeled axis is present; an unmodeled one is absent. */
260
+ headroom: BehaviourHeadroom;
261
+ /** Expected fraction of requests failing at `at`, in `0..1`. */
262
+ errorRate: number;
263
+ /** The verdict under a named failure. */
264
+ resilience: BehaviourResilience;
265
+ /** Optional: a smaller size that would still do. */
266
+ rightSize?: BehaviourRightSize;
267
+ /** Which engine said all of this, and on what basis. Required. */
268
+ provenance: BehaviourProvenance;
269
+ }
270
+ /**
271
+ * Why one declared entity got no prediction. Total: a lexicon that cannot
272
+ * predict an entity must pick one of these, and consumers may switch
273
+ * exhaustively.
274
+ *
275
+ * Derived from {@link UnobservedReason} so the four shared verdicts keep their
276
+ * exact spelling and meaning:
277
+ *
278
+ * - `read-failed` — the engine was reached and the prediction errored.
279
+ * - `no-binding` — the environment resolves to no concrete target to predict.
280
+ * - `unsupported-kind` — the engine has no model for this entity type. The
281
+ * entity is perfectly real and may well cost money; this engine cannot say
282
+ * how much, and says so instead of returning zero.
283
+ * - `filtered` — reached but withheld by a caller-requested filter (`owned`).
284
+ *
285
+ * `no-credentials` is excluded on purpose: the engine is never handed one, so
286
+ * it can never be missing one. Two reasons are added for the predictor itself:
287
+ *
288
+ * - `no-engine` — no variable in the chain named an engine. Nothing is
289
+ * configured; this is a setup state, not a failure.
290
+ * - `engine-unreachable` — a variable named an engine and it did not answer.
291
+ * - `engine-out-of-credit` — the engine answered, and refused because the
292
+ * account behind it has no balance left (#2359).
293
+ * - `engine-over-quota` — the engine answered, and refused because a rate or
294
+ * volume limit is spent (#2359).
295
+ * - `credential-in-request` — the request itself carried something that must
296
+ * not leave the process, so nothing was sent. The one refusal chant raises
297
+ * about itself rather than about the engine; see
298
+ * {@link screenBehaviourRequest}.
299
+ *
300
+ * The last four are one axis split four ways, because each has a different
301
+ * remedy and a refusal exists to be acted on. `no-engine` wants a variable
302
+ * set. `engine-unreachable` wants the address checked. `engine-out-of-credit`
303
+ * wants somebody to pay, and no amount of waiting fixes it.
304
+ * `engine-over-quota` usually wants nothing but the window to roll over, and
305
+ * telling somebody to top up an account that is not empty sends them to the
306
+ * wrong place — as does folding either into `engine-unreachable`, which points
307
+ * at an address that is answering perfectly well.
308
+ */
309
+ export type BehaviourUnpredictedReason = Exclude<UnobservedReason, "no-credentials"> | "no-engine" | "engine-unreachable" | "engine-out-of-credit" | "engine-over-quota" | "credential-in-request";
310
+ /** Every legal {@link BehaviourUnpredictedReason}, for validation and conformance checks. */
311
+ export declare const BEHAVIOUR_UNPREDICTED_REASONS: readonly BehaviourUnpredictedReason[];
312
+ /** True when `value` is a legal {@link BehaviourUnpredictedReason}. */
313
+ export declare function isBehaviourUnpredictedReason(value: unknown): value is BehaviourUnpredictedReason;
314
+ /** One declared entity that got no prediction, and why. */
315
+ export interface UnpredictedEntity {
316
+ /** Declared entity type, when the lexicon knows it (it usually does — the entity is declared). */
317
+ type?: string;
318
+ /** Total verdict. */
319
+ reason: BehaviourUnpredictedReason;
320
+ /** Human-readable detail: the kind with no model, the call that failed. */
321
+ detail?: string;
322
+ }
323
+ /**
324
+ * Report-level facts about a run that produced figures. Rides as
325
+ * `meta._behaviour` on the overlay graph.
326
+ */
327
+ export interface BehaviourReportMeta {
328
+ /** The engine that answered for the run as a whole. */
329
+ engine: string;
330
+ /** Its version. */
331
+ version: string;
332
+ /** The traffic level the run was asked for, echoed from the request. */
333
+ at: BehaviourTrafficLevel;
334
+ /**
335
+ * An estate total, when the engine states one of its own. Optional, and
336
+ * emphatically not a field for chant or a consumer to fill in by summing —
337
+ * a consumer that sums does its own arithmetic and labels it as such.
338
+ */
339
+ total?: PredictedRate;
340
+ /**
341
+ * The edge coverage the run was given, echoed from the request (#2360).
342
+ *
343
+ * Required, and it is the whole reason `edgeCoverage` is worth stating. Held
344
+ * only on {@link PredictBehaviourOptions} it never reached a reader, so a
345
+ * consumer holding a report could not tell whether a "survives one zone lost"
346
+ * verdict was computed over a complete graph or over one whose builder had no
347
+ * idea what it had missed. Under this contract's own second constraint that
348
+ * makes the verdict a faked number the shape renders invisible — the failure
349
+ * the refusal arm exists to prevent, reappearing one level down.
350
+ *
351
+ * `behaviourReport` copies it from the request, so a lexicon does not restate
352
+ * it and cannot restate it differently.
353
+ */
354
+ edgeCoverage: BehaviourEdgeCoverage;
355
+ }
356
+ /**
357
+ * A run that produced figures. The `behaviour: "v1"` discriminant is a wire
358
+ * version for the same reason `observation: "v1"` is: consumers branch on it.
359
+ */
360
+ export interface BehaviourReport {
361
+ /** Discriminant + wire version. */
362
+ readonly behaviour: "v1";
363
+ /** Which engine ran, at what traffic level. */
364
+ meta: BehaviourReportMeta;
365
+ /** PREDICTED, keyed by chant entity name. */
366
+ entities: Record<string, PredictedBehaviour>;
367
+ /**
368
+ * NOT-PREDICTED, keyed by chant entity name, with a total reason. Together
369
+ * with `entities` this must cover every name the caller asked about.
370
+ */
371
+ unpredicted?: Record<string, UnpredictedEntity>;
372
+ }
373
+ /**
374
+ * Why there is no report at all, and what to do about it.
375
+ *
376
+ * `reason` and `remedy` are the two strings a consumer prints where the legend
377
+ * would go; `cause` and `source` are additive and switchable. The refusal is
378
+ * the lexicon's own text in the house style, naming the variable it wanted —
379
+ * see {@link noBehaviourEngineMessage}.
380
+ */
381
+ export interface BehaviourRefusal {
382
+ /** Total, switchable verdict. */
383
+ cause: BehaviourUnpredictedReason;
384
+ /** The sentence a consumer prints. Names what was missing. */
385
+ reason: string;
386
+ /** How to fix it. Names the variable and how to set it. */
387
+ remedy: string;
388
+ /** Which variable in the chain answered, when one did. Absent for `no-engine`. */
389
+ source?: string;
390
+ }
391
+ /**
392
+ * A run that produced nothing, and says why.
393
+ *
394
+ * A separate member of the union rather than a flag on {@link BehaviourReport},
395
+ * so a refusal has no `entities` map to be empty and no `meta.total` to be
396
+ * zero. "The engine is unreachable" and "the engine priced this estate at
397
+ * nothing" are different objects, and no amount of downstream carelessness can
398
+ * turn the first into the second.
399
+ */
400
+ export interface BehaviourRefusalReport {
401
+ /** Discriminant + wire version, shared with {@link BehaviourReport}. */
402
+ readonly behaviour: "v1";
403
+ /** The refusal. Present *instead of* every figure, never alongside one. */
404
+ refusal: BehaviourRefusal;
405
+ }
406
+ /** What `predictBehaviour()` returns: figures, or a named refusal. Never both, never neither. */
407
+ export type BehaviourResult = BehaviourReport | BehaviourRefusalReport;
408
+ /** True when the lexicon refused rather than predicting. */
409
+ export declare function isBehaviourRefusalReport(value: BehaviourResult): value is BehaviourRefusalReport;
410
+ /**
411
+ * True when `value` is either arm of the versioned {@link BehaviourResult}
412
+ * envelope.
413
+ *
414
+ * Both the discriminant AND an arm, because the discriminant alone is not the
415
+ * type. `{ behaviour: "v1" }` carries the version and is neither arm: it fails
416
+ * {@link isBehaviourRefusalReport}, so a consumer's `if (refusal) … else …`
417
+ * narrows it to {@link BehaviourReport}, and `result.entities` is `undefined`
418
+ * at a site TypeScript has been told cannot be.
419
+ */
420
+ export declare function isBehaviourResult(value: unknown): value is BehaviourResult;
421
+ /**
422
+ * Every rule behold's `validateBehaviourBlock` applies, applied here instead —
423
+ * before the block is built rather than after it has travelled.
424
+ *
425
+ * The rule set is deliberately, literally the same set. behold
426
+ * (`behold/src/behaviour.ts:209`) validates each block on arrival and **drops
427
+ * the whole block** with a diagnostic when one fails, so a block chant's types
428
+ * accept and behold's validator rejects renders nothing at all, having looked
429
+ * perfectly legal every step of the way here. Types cannot carry most of these:
430
+ * `tolerance: string` accepts `""`, `errorRate: number` accepts `1.2`, and
431
+ * `cost.perHour: number` accepts `-4`.
432
+ *
433
+ * The mapping, by behold's own numbering, so a future change there has a named
434
+ * place to land here:
435
+ *
436
+ * 2 `at.traffic` non-empty · 3 `cost.perHour` finite · 4 not negative ·
437
+ * 5 `cost.currency` non-empty · 6 `headroom` present · 7/8 each axis a
438
+ * fraction · 9 at least one axis · 10 `errorRate` a fraction ·
439
+ * 11 `resilience.failure` non-empty · 12 verdict in the closed set ·
440
+ * 13 `rightSize` implies a `suggestion` · 14 `provenance.engine` non-empty ·
441
+ * 15 `version` non-empty · 16 `tolerance` non-empty · 17 `basis` in the closed
442
+ * set.
443
+ *
444
+ * Rules 9 and 16 are the two chant is stricter on. Rule 9 is also a type here
445
+ * ({@link BehaviourHeadroom} is a union requiring one axis), so this is the
446
+ * backstop for a JavaScript caller. And on 16, behold accepts any non-empty
447
+ * string while this rejects `n/a`, `none`, `unknown` and friends: the epic asks
448
+ * for the engine's *stated* tolerance, and a word meaning "I have none to
449
+ * state" passes behold's check while defeating its purpose.
450
+ */
451
+ export declare function validateBehaviourBlock(name: string, block: PredictedBehaviour): void;
452
+ /** What a lexicon states about the run itself. Everything else in the meta is copied from the request. */
453
+ export interface BehaviourEngineStamp {
454
+ engine: string;
455
+ version: string;
456
+ /** An estate total, when the engine states one of its own. Never chant's sum. */
457
+ total?: PredictedRate;
458
+ }
459
+ /**
460
+ * Build a {@link BehaviourReport}, and refuse to build an invalid one.
461
+ *
462
+ * Takes the request rather than a hand-assembled meta, and derives `at`,
463
+ * `edgeCoverage` and the asked-for names from it. A lexicon states only what is
464
+ * genuinely its own — which engine answered, at what version, and a total if
465
+ * the engine has one — so the three fields that must agree with the request
466
+ * cannot be restated differently.
467
+ *
468
+ * That is a check and not a proof, and the distinction matters enough to say
469
+ * plainly: {@link BehaviourReport} is a plain interface, {@link isBehaviourResult}
470
+ * accepts a hand-built one, and a lexicon calling this with
471
+ * `entityNames: Object.keys(entities)` self-certifies. What passing the request
472
+ * buys is that the ordinary route is checked and the check names what is wrong;
473
+ * a consumer that needs the guarantee runs its own
474
+ * `validateBehaviourResult(result, askedFor)` on arrival, which is #2358's and
475
+ * #2360's to write.
476
+ *
477
+ * Refusals, all naming what went wrong:
478
+ *
479
+ * - an entity in neither map — the tri-state's whole point, and the one a
480
+ * `continue` in a lexicon's loop produces silently;
481
+ * - an entity in both maps — priced and unpriced at once;
482
+ * - a figure for something nobody asked about;
483
+ * - a block priced at a level the run did not ask for;
484
+ * - an edge-coverage claim that names no gap ({@link validateEdgeCoverage});
485
+ * - any block failing {@link validateBehaviourBlock}.
486
+ */
487
+ export declare function behaviourReport(request: Pick<PredictBehaviourOptions, "entityNames" | "traffic" | "edgeCoverage">, stamp: BehaviourEngineStamp, entities: Record<string, PredictedBehaviour>, unpredicted?: Record<string, UnpredictedEntity>): BehaviourReport;
488
+ /** Build a {@link BehaviourRefusalReport}. */
489
+ export declare function behaviourRefusal(refusal: BehaviourRefusal): BehaviourRefusalReport;
490
+ /**
491
+ * Whether two figures are a delta of like things.
492
+ *
493
+ * - `comparable` — same engine, same version, same tolerance, same basis. The
494
+ * difference between the two numbers is a difference in the estate.
495
+ * - `mixed-basis` — same engine and version, one figure `modeled` off list
496
+ * prices and the other `validated` against a bill. Subtracting these does
497
+ * not measure a change in the estate; part of the difference is the
498
+ * difference between a price list and an invoice.
499
+ * - `mixed-engine` — the engine, its version or its stated tolerance differs.
500
+ * Two models are not one scale, and a delta across them is arithmetic on
501
+ * numbers that were never on the same axis.
502
+ */
503
+ export type ProvenanceComparability = "comparable" | "mixed-basis" | "mixed-engine";
504
+ /**
505
+ * Classify a pair of *provenances*. Almost always the wrong function to call —
506
+ * see {@link compareFigures}, which is the one consumers want.
507
+ *
508
+ * The limit is structural rather than an oversight: `at` lives on
509
+ * {@link PredictedBehaviour} and not on {@link BehaviourProvenance}, so this
510
+ * function cannot see the traffic level and will happily answer `comparable`
511
+ * for a figure at 100 rps and a figure at 1000 rps. Two predictions of the same
512
+ * estate by the same engine at different levels are not a delta of like things;
513
+ * they are answers to different questions. Use this only where the two figures
514
+ * are already known to share a level.
515
+ */
516
+ export declare function compareProvenance(a: BehaviourProvenance, b: BehaviourProvenance): ProvenanceComparability;
517
+ /** One axis on which two figures fail to be a delta of like things. */
518
+ export type FigureMismatch = "mixed-engine" | "mixed-level" | "mixed-basis" | "mixed-currency" | "mixed-failure";
519
+ /**
520
+ * Every mismatch, in the order a consumer should show them — most fundamental
521
+ * first. Order is presentation; membership is the contract.
522
+ */
523
+ export declare const FIGURE_MISMATCHES: readonly FigureMismatch[];
524
+ /**
525
+ * Classify a pair of figures for delta purposes. **This is the one to call.**
526
+ *
527
+ * Returns **every** axis on which the two disagree, not the first. An earlier
528
+ * version returned one label and stopped at the first mismatch, which meant a
529
+ * pair differing in level AND basis reported `mixed-level` and dropped the
530
+ * basis crossing on the floor — a consumer told "different traffic level" would
531
+ * caption it as such and show a modeled-minus-validated difference underneath
532
+ * with nothing said. Precedence is a fine way to decide what to show first and
533
+ * a bad way to decide what to know.
534
+ *
535
+ * The axes:
536
+ *
537
+ * - `mixed-engine` — engine, version or tolerance differs. Two models are not
538
+ * one scale.
539
+ * - `mixed-level` — different `at`. The same question asked of two different
540
+ * worlds.
541
+ * - `mixed-currency` — different `cost.currency`. chant converts nothing, so
542
+ * USD minus EUR is not a number. behold already refuses to *sum* these
543
+ * (`behold/src/behaviour.ts`); permitting them to be *differenced* left this
544
+ * contract laxer than its own consumer.
545
+ * - `mixed-basis` — one figure off a price list, the other off an invoice.
546
+ * - `mixed-failure` — different `resilience.failure`. "Survives one zone lost"
547
+ * against "survives a region lost" are two verdicts about two events, and
548
+ * differencing the costs beside them implies they answer the same question.
549
+ *
550
+ * The rule this contract binds its consumers to, in one sentence: **a delta
551
+ * between two figures whose mismatch set is not empty must be marked as such
552
+ * wherever it is shown, and must never be presented as a plain difference.**
553
+ * How it is marked is #2358's to choose. Whether it must be marked is not.
554
+ */
555
+ export declare function compareFigures(a: PredictedBehaviour, b: PredictedBehaviour): ReadonlySet<FigureMismatch>;
556
+ /** The mismatches, ordered for display. A convenience over {@link compareFigures}. */
557
+ export declare function figureMismatches(a: PredictedBehaviour, b: PredictedBehaviour): FigureMismatch[];
558
+ /** True when two whole figures may be shown as a plain difference, with no mark. */
559
+ export declare function isComparableFigure(a: PredictedBehaviour, b: PredictedBehaviour): boolean;
560
+ /** True when two provenances may be shown as a plain difference. Level-blind — see {@link compareProvenance}. */
561
+ export declare function isComparableProvenance(a: BehaviourProvenance, b: BehaviourProvenance): boolean;
562
+ /**
563
+ * The engine a lexicon predicts against, and the variable that named it.
564
+ *
565
+ * `value` is an address — a URL, a socket path, a command on `PATH`. It is
566
+ * **not** a credential and this contract has no channel for one; see
567
+ * {@link PredictBehaviourOptions}. An engine that demands authentication is out
568
+ * of scope for the plugin surface, and a lexicon that needs one must reach it
569
+ * on its own transport without routing it through here.
570
+ */
571
+ export interface BehaviourEngineEndpoint {
572
+ /** The address the lexicon will predict against. */
573
+ value: string;
574
+ /** The variable it came from, so a refusal or a log line can name it. */
575
+ source: string;
576
+ }
577
+ /**
578
+ * The variables that can name a behaviour engine, most specific first. Exported
579
+ * so a refusal message and a test can agree on the chain without restating it.
580
+ *
581
+ * `lexicon` scopes the first entry, which is what lets an estate priced by two
582
+ * engines point each lexicon at its own without a per-call flag.
583
+ */
584
+ export declare function behaviourEngineVariables(lexicon: string): string[];
585
+ /**
586
+ * Resolve the engine one lexicon predicts against, most specific first. Pure —
587
+ * exported for testing.
588
+ *
589
+ * The chain is lexicon-scoped, then chant-scoped, then bare, for the same
590
+ * reason `gitlabNoteTokenFrom` reads `CHANT_GITLAB_TOKEN` before `GITLAB_TOKEN`
591
+ * (`./op/activities/reconcile.ts`): the narrower name exists so a project that
592
+ * has to differ can differ, and the wider one exists so a project that does not
593
+ * need to sets one variable.
594
+ *
595
+ * Returns `undefined` when nothing in the chain answered. That is `no-engine`,
596
+ * and the caller turns it into {@link noBehaviourEngineMessage} — never into an
597
+ * empty report.
598
+ */
599
+ export declare function behaviourEngineFrom(lexicon: string, env: Record<string, string | undefined>): BehaviourEngineEndpoint | undefined;
600
+ /** What a lexicon says when no variable in the chain names an engine. */
601
+ export declare function noBehaviourEngineMessage(lexicon: string): string;
602
+ /** What a lexicon says when a variable named an engine and the engine did not answer. */
603
+ export declare function unreachableBehaviourEngineMessage(lexicon: string, endpoint: BehaviourEngineEndpoint, detail: string): string;
604
+ /**
605
+ * The refusal for an estate with no engine configured. The whole of the
606
+ * `no-engine` path, so no lexicon has to assemble one by hand.
607
+ */
608
+ export declare function noBehaviourEngineRefusal(lexicon: string): BehaviourRefusalReport;
609
+ /** The refusal for a configured engine that did not answer. */
610
+ export declare function unreachableBehaviourEngineRefusal(lexicon: string, endpoint: BehaviourEngineEndpoint, detail: string): BehaviourRefusalReport;
611
+ /**
612
+ * What a lexicon says when the engine answered and refused for want of money
613
+ * (#2359). Distinct from unreachable on purpose: the address is fine, the
614
+ * request arrived, and telling somebody to check their networking wastes the
615
+ * one thing a refusal is for.
616
+ */
617
+ export declare function outOfCreditBehaviourEngineMessage(lexicon: string, endpoint: BehaviourEngineEndpoint, detail: string): string;
618
+ /** What a lexicon says when the engine answered and refused for a spent limit (#2359). */
619
+ export declare function overQuotaBehaviourEngineMessage(lexicon: string, endpoint: BehaviourEngineEndpoint, detail: string): string;
620
+ /** The refusal for an engine that answered and said the account has no balance (#2359). */
621
+ export declare function outOfCreditBehaviourEngineRefusal(lexicon: string, endpoint: BehaviourEngineEndpoint, detail: string): BehaviourRefusalReport;
622
+ /** The refusal for an engine that answered and said a limit is spent (#2359). */
623
+ export declare function overQuotaBehaviourEngineRefusal(lexicon: string, endpoint: BehaviourEngineEndpoint, detail: string): BehaviourRefusalReport;
624
+ /**
625
+ * Render a refusal for a terminal, in red.
626
+ *
627
+ * Red rather than the amber a degradation gets, because a missing engine is not
628
+ * a partial answer: every behaviour-derived figure and colour is gone, and the
629
+ * one thing the reader must not do is assume the numbers are merely late.
630
+ *
631
+ * `color` defaults to the same rule the rest of the CLI uses (`NO_COLOR`, and a
632
+ * TTY on stdout); pass it explicitly where the output is asserted on.
633
+ */
634
+ export declare function renderBehaviourRefusal(refusal: BehaviourRefusal, options?: {
635
+ color?: boolean;
636
+ }): string;
637
+ /**
638
+ * Names this contract refuses to carry, each declared `?: never` on
639
+ * {@link PredictBehaviourOptions} so the deliberate attempt is a compile error.
640
+ *
641
+ * This list is the *narrow* half of the guard and never the whole of it. A
642
+ * denylist of names cannot enforce "the engine never sees a credential" — the
643
+ * same argument that made `?: never` better than omission applies to every name
644
+ * the list omits, and `xApiKey`, `pat` and `Authorization` with a capital A all
645
+ * sailed past an earlier version of this file. What actually enforces the rule
646
+ * is {@link assertNoCredentialInOptions}, which walks values.
647
+ */
648
+ export declare const CREDENTIAL_OPTION_KEYS: readonly string[];
649
+ /**
650
+ * An engine address, safe to interpolate into a refusal that a merge-request
651
+ * comment will carry (#2358).
652
+ *
653
+ * `CHANT_BEHAVIOUR_ENGINE=https://svc:s3cr3t@engine.internal/predict?key=abc` is
654
+ * an ordinary way to point at an authenticated endpoint, and it is the shape
655
+ * this contract's own "resolve auth on your own transport" guidance produces.
656
+ * Printing it verbatim in a refusal publishes it.
657
+ *
658
+ * Three passes, in order:
659
+ *
660
+ * 1. The URL parse blanks `username`/`password`, and drops the query string and
661
+ * the fragment **whole** rather than by known parameter name — `?key=`,
662
+ * `?token=`, `?sig=` and `#access_token=` are all common and the set is not
663
+ * enumerable. The fragment matters on its own account: OAuth's implicit
664
+ * flow puts the access token there.
665
+ * 2. Inline command-line flag values (`--token=…`, `-p …`), for an engine that
666
+ * is a command on `PATH` rather than a URL.
667
+ * 3. {@link redactCredentialMaterial}, for env-held values and the token
668
+ * shapes chant knows.
669
+ *
670
+ * **What survives:** a credential written as a bare path segment
671
+ * (`https://host/predict/<token>/go`) unless it matches a known token shape.
672
+ * Nothing here can tell that segment from a resource id, and an earlier version
673
+ * of this doc claimed pass 3 caught it, which was wrong. If an engine
674
+ * authenticates by path, do not put its address in a variable whose refusal
675
+ * text is published.
676
+ */
677
+ export declare function redactEngineAddress(value: string, env?: Record<string, string | undefined>): string;
678
+ /**
679
+ * Engine-supplied detail, bounded and scrubbed before it reaches a refusal.
680
+ *
681
+ * `detail` on a credit or quota refusal is whatever the engine said, echoed.
682
+ * An engine is a third party: it can be verbose, and it can quote the request
683
+ * back at you, which is how a URL or an id ends up in a public comment. So the
684
+ * text is truncated, anything URL-shaped is reduced to its host, and the result
685
+ * goes through {@link redactCredentialMaterial}.
686
+ */
687
+ export declare function scrubEngineDetail(detail: string, env?: Record<string, string | undefined>): string;
688
+ /**
689
+ * How complete a request's edge list is (#2360).
690
+ *
691
+ * - `complete` — every reference between the named entities is in `edges`.
692
+ * Only claim this when the builder knows it: a declared-path build walking
693
+ * resolved `AttrRef`s does, a live rebuild over a partial catalog does not.
694
+ * - `partial` — some references are known to be missing, and `dangling` or
695
+ * `unresolvedKinds` says which. An engine may still answer, and should
696
+ * discount its own confidence.
697
+ * - `unknown` — the builder cannot say. Treat like `partial` and trust nothing
698
+ * that depends on reachability.
699
+ */
700
+ export type EdgeCoverageVerdict = "complete" | "partial" | "unknown";
701
+ /** Every legal {@link EdgeCoverageVerdict}. */
702
+ export declare const EDGE_COVERAGE_VERDICTS: readonly EdgeCoverageVerdict[];
703
+ /** True when `value` is a legal {@link EdgeCoverageVerdict}. */
704
+ export declare function isEdgeCoverageVerdict(value: unknown): value is EdgeCoverageVerdict;
705
+ /**
706
+ * What a caller knows about the completeness of the graph it is handing over.
707
+ *
708
+ * Note on `complete` with a non-empty {@link dangling}: that is **not** a
709
+ * contradiction and must not be "fixed". A dangling reference points at
710
+ * something outside the named entity set by definition — a cross-account VPC, a
711
+ * resource another team owns — so a builder can have found every edge among the
712
+ * entities it was asked about and still have references leaving the estate.
713
+ * `complete` is a claim about the edges *between the named entities*.
714
+ */
715
+ export interface BehaviourEdgeCoverage {
716
+ verdict: EdgeCoverageVerdict;
717
+ /**
718
+ * References that resolved to no entity in this request — the `dangling` list
719
+ * `reconstructEdges` (./graph-refs.ts) already returns and used to discard.
720
+ *
721
+ * `DanglingRef`, not a flattened string. The record carries `from`, and `from`
722
+ * is the field that says *which* entity's path leaves the estate; flattening
723
+ * to the target value alone leaves an engine knowing that something dangles
724
+ * and not what.
725
+ */
726
+ dangling?: readonly DanglingRef[];
727
+ /**
728
+ * Entity types the builder has no reference rules for, so nothing was looked
729
+ * for. This is the quiet one: a kind with no `RefRule` produces no edges and
730
+ * no complaint.
731
+ */
732
+ unresolvedKinds?: readonly string[];
733
+ /**
734
+ * Containment as traversable edges — populate from
735
+ * `reconstructEdges().containmentEdges` (./graph-refs.ts), **not** from the
736
+ * `containment: ContainmentPair[]` field beside it. The two are the same
737
+ * relationships in two shapes, and only the edge shape belongs here; the
738
+ * field was called `containment` and pointed #2360 straight at the wrong one.
739
+ *
740
+ * Carried separately from {@link PredictBehaviourOptions.edges} because
741
+ * `chant graph` draws containment as a boundary rather than a line, and
742
+ * putting it in `edges` would draw a line from every resource to its VPC. An
743
+ * engine asked whether an estate survives one zone lost needs the membership
744
+ * and `edges` will never have it.
745
+ */
746
+ containmentEdges?: readonly IREdge[];
747
+ }
748
+ /**
749
+ * Refuse an edge-coverage claim that does not say anything.
750
+ *
751
+ * `partial` means "some references are known to be missing", and a `partial`
752
+ * with neither `dangling` nor `unresolvedKinds` names none of them — which is
753
+ * `unknown` wearing a more confident word. Use `unknown` for "I cannot say";
754
+ * `partial` is for "I can say, and here it is".
755
+ */
756
+ /**
757
+ * A detached copy, frozen. The report's account of its own inputs must not
758
+ * change after the report exists, and `readonly` buys nothing at runtime.
759
+ */
760
+ export declare function copyEdgeCoverage(coverage: BehaviourEdgeCoverage): BehaviourEdgeCoverage;
761
+ export declare function validateEdgeCoverage(coverage: BehaviourEdgeCoverage): void;
762
+ /**
763
+ * What core hands a lexicon's `predictBehaviour`.
764
+ *
765
+ * The first seven fields are `observeResourcesDeep`'s options, field for field
766
+ * and doc for doc, so a caller that already drives the deep read drives this
767
+ * with the same object plus `traffic`. That is the point of the mirror: the two
768
+ * reads answer different questions about the same request.
769
+ *
770
+ * The `?: never` block is the enforcement half of "the engine never sees
771
+ * credentials". Declaring the keys rather than omitting them buys a real check:
772
+ * an omitted key is only caught by the excess-property check on an object
773
+ * literal, and slips through a spread or a widened variable, while `never`
774
+ * rejects a `string` from any position and names the field in the error.
775
+ */
776
+ export interface PredictBehaviourOptions {
777
+ environment: string;
778
+ buildOutput: string;
779
+ entityNames: string[];
780
+ entities: Map<string, {
781
+ entityType: string;
782
+ props: Record<string, unknown>;
783
+ }>;
784
+ /** Deployed stack to predict for, in a multi-stack project (see `stacks` in `ChantConfig`). */
785
+ stack?: string;
786
+ /** Region the stack is deployed in, mirroring the deep read (#1267). Omitted keeps the ambient default. */
787
+ region?: string;
788
+ /** Restrict to chant-owned resources (#119). An entity withheld here is `filtered`, not absent. */
789
+ owned?: boolean;
790
+ /**
791
+ * The traffic level to predict at, verbatim: `100 rps, p50`. The one field
792
+ * the deep read has no counterpart for, and the reason a prediction can never
793
+ * be mistaken for an observation — an observation is not *at* anything.
794
+ *
795
+ * chant does not parse it, does not default it, and does not convert it. An
796
+ * engine that cannot understand the level it was handed refuses; it does not
797
+ * substitute one it likes better.
798
+ */
799
+ traffic: string;
800
+ /**
801
+ * The edges between the entities above (#2355) — the half of "a resource
802
+ * graph" that a bag of nodes is not.
803
+ *
804
+ * This is the one field where the mirror of `observeResourcesDeep`'s options
805
+ * deliberately breaks, and it breaks because the two reads want different
806
+ * things. A deep read answers per entity and needs no neighbours: an S3
807
+ * bucket's live property tree is the same tree whether or not a Lambda reads
808
+ * from it. A prediction is the opposite. Headroom, an error rate and a
809
+ * resilience verdict under "one zone lost" are all statements about a path
810
+ * through the estate, and an engine handed nodes alone can only price each
811
+ * box in isolation, which is the arithmetic a consumer could already do for
812
+ * itself.
813
+ *
814
+ * `IREdge` (./graph-ir.ts) rather than an edge type of this contract's own,
815
+ * for one reason that outranks the tidiness of a purpose-built shape: it is
816
+ * already the engine-neutral edge that BOTH paths produce. `collectEdges`
817
+ * builds them from declared `AttrRef`s and lexicon-resolved entity
818
+ * references on the declared path, and `reconstructEdges` (./graph-refs.ts)
819
+ * rebuilds them from observed physical identifiers on the live path, which
820
+ * is the path #2360 assembles this request on. A second edge type here would
821
+ * put a lossy translation hop on each side, and the epic wants the declared
822
+ * prediction and the live prediction shown as a delta — two shapes that have
823
+ * each been through a different translation are the worst possible input to
824
+ * a delta. `DependencyObservation.edges` (./lexicon.ts) already carries
825
+ * `IREdge` for the same reason.
826
+ *
827
+ * `from` and `to` are chant entity names, the keys {@link entityNames} and
828
+ * {@link entities} use. An edge naming an entity outside `entityNames`
829
+ * points outside the estate the caller asked about, and an engine may ignore
830
+ * it.
831
+ *
832
+ * Required, and an empty array is a claim rather than a shrug: it says this
833
+ * estate's entities reference nothing of each other. A caller that has not
834
+ * computed edges must not pass `[]` and call it a graph, for the same reason
835
+ * absence and unreadness are separate verdicts everywhere else here — which
836
+ * is what {@link edgeCoverage} exists to let it say instead.
837
+ */
838
+ edges: readonly IREdge[];
839
+ /**
840
+ * How complete {@link edges} is, and what is known to be missing from it.
841
+ *
842
+ * `edges: []` cannot distinguish "nothing references anything" from "I could
843
+ * not work out what references what", and both are ordinary outcomes on the
844
+ * live path. `reconstructEdges` (./graph-refs.ts) returns `dangling` — the
845
+ * references it resolved to no observed node — and drops them; a kind with no
846
+ * `RefRule` in the lexicon's catalog contributes no edges at all and says
847
+ * nothing about it; and containment (a subnet inside a VPC) is deliberately
848
+ * not an edge, which means zone membership is absent from `edges` by design.
849
+ * An engine asked "does this survive one zone lost" over a graph with no zone
850
+ * membership answers confidently and wrongly.
851
+ *
852
+ * So the completeness is stated rather than assumed, and stated *now*, before
853
+ * five consumers are written against a field that silently means "complete".
854
+ */
855
+ edgeCoverage: BehaviourEdgeCoverage;
856
+ /** Not a channel. See {@link CREDENTIAL_OPTION_KEYS}. */
857
+ token?: never;
858
+ /** Not a channel. */
859
+ credential?: never;
860
+ /** Not a channel. */
861
+ credentials?: never;
862
+ /** Not a channel. */
863
+ secret?: never;
864
+ /** Not a channel. */
865
+ secrets?: never;
866
+ /** Not a channel. */
867
+ password?: never;
868
+ /** Not a channel. */
869
+ apiKey?: never;
870
+ /** Not a channel. */
871
+ accessKey?: never;
872
+ /** Not a channel. */
873
+ secretKey?: never;
874
+ /** Not a channel. */
875
+ sessionToken?: never;
876
+ /** Not a channel. */
877
+ auth?: never;
878
+ /** Not a channel. */
879
+ authorization?: never;
880
+ /** Not a channel. */
881
+ bearer?: never;
882
+ /** Not a channel. */
883
+ privateKey?: never;
884
+ }
885
+ /**
886
+ * Refuse a request carrying anything credential-shaped, anywhere in it.
887
+ *
888
+ * The `?: never` fields on {@link PredictBehaviourOptions} stop the deliberate
889
+ * attempt at compile time. This stops the accident, which is the one that
890
+ * happens: it walks **the whole request** — including `entities[*].props`,
891
+ * which is `Record<string, unknown>` straight out of the build and which no
892
+ * type on this contract can see into, and every field of every
893
+ * {@link import("./graph-ir.js").IREdge}.
894
+ *
895
+ * ## What it detects
896
+ *
897
+ * 1. **A credential-shaped value**, whatever the key is called: the PEM / JWT /
898
+ * `Bearer` shapes in `CREDENTIAL_SHAPES`, plus the provider-prefixed tokens
899
+ * in `CREDENTIAL_TOKEN_SHAPES` (GitHub, GitLab, OpenAI, Stripe, Slack, AWS,
900
+ * Google, npm).
901
+ * 2. **A password in userinfo**, with or without a scheme — `new URL()` for the
902
+ * former and a pattern for `app:hunter2@db.internal:5432/prod`, which is how
903
+ * a DSN is usually written and which `URL` will not parse at all.
904
+ * 3. **A credential-shaped key**, but only when its value is a string of at
905
+ * least {@link MIN_CREDENTIAL_LENGTH} characters that is not an evident
906
+ * reference, and only when the key is not in the reference family
907
+ * ({@link REFERENCE_KEY_SUFFIXES}).
908
+ *
909
+ * Rules 1 and 2 throw. Rule 3, and a structure deeper than the walk reads,
910
+ * produce a refusal instead — see {@link screenBehaviourRequest} for why the
911
+ * blast radii differ.
912
+ *
913
+ * **The name layer is a fast path, not a safety net.** After the gating above
914
+ * it fires on very little, and a credential under a benign name — `dsn`,
915
+ * `config`, `note` — is caught by rules 1 and 2 or not at all. That is the
916
+ * intended division of labour and the reason those two exist; do not read
917
+ * rule 3 as the guarantee.
918
+ *
919
+ * ## What it deliberately does not detect
920
+ *
921
+ * Rule 1 is **a denylist of known formats, not a proof**. A token from a
922
+ * provider nobody has added, an internal issuer's format, a bare random string
923
+ * or a base64 blob passes every rule here, as does a secret split across two
924
+ * fields or encoded. There is no entropy scoring, on purpose: this walks build
925
+ * output full of ids, ARNs, hashes and digests, and a heuristic that refuses
926
+ * those would refuse real projects rather than protect them. So the honest
927
+ * statement of the guarantee is that a credential a human would recognize on
928
+ * sight will not reach the engine by accident, and that a novel or opaque
929
+ * secret still can. A lexicon author putting secret material in `props` is
930
+ * outside what this contract can catch, and the remedy there is not to.
931
+ */
932
+ export type CredentialRule = "value-shape" | "key-name" | "walk-depth";
933
+ /** One thing the walk objected to, and which rule objected. */
934
+ export interface CredentialFinding {
935
+ /** Where in the request, as a readable path (`options.entities.get(db).props.dsn`). */
936
+ path: string;
937
+ rule: CredentialRule;
938
+ /** What was found, in words, for the message. Never the value itself. */
939
+ what: string;
940
+ }
941
+ /**
942
+ * Every objection the walk has to a request. Pure, and exported so a caller can
943
+ * decide what to do rather than take this module's word for it.
944
+ */
945
+ export declare function findCredentialsInOptions(options: object): CredentialFinding[];
946
+ /**
947
+ * Throw when the request carries something that **is** a credential.
948
+ *
949
+ * **Not the entry point.** This applies one of the three rules and discards the
950
+ * other two, so a `key-name` hit and a `walk-depth` hit both pass it silently.
951
+ * Call {@link screenBehaviourRequest}, which runs this and then acts on what is
952
+ * left. This stays exported because "did the request contain an actual token"
953
+ * is a question worth asking on its own, and because the split is what keeps
954
+ * the blast radii different.
955
+ *
956
+ * Only the value-shape rule throws, and throwing is deliberate: a live token in
957
+ * a request bound for a third party is not a degradation to report, it is a
958
+ * stop. Throwing is the whole-lexicon failure per `lexicon.ts`, which is the
959
+ * right blast radius for this and the wrong one for a suspicious field name.
960
+ */
961
+ export declare function assertNoCredentialInOptions(options: object): void;
962
+ /**
963
+ * Screen a whole request. **This is the entry point, and the only one.**
964
+ *
965
+ * This doc comment is the source of truth for the sequence; the module header
966
+ * and the authoring page both point here rather than restating it. A lexicon's
967
+ * `predictBehaviour` opens with exactly this and nothing else:
968
+ *
969
+ * ```ts
970
+ * const refusal = screenBehaviourRequest("acme", options);
971
+ * if (refusal) return refusal;
972
+ * ```
973
+ *
974
+ * Calling {@link assertNoCredentialInOptions} instead applies one rule of three
975
+ * and drops the rest, which is how a `ghp_…` token nested past the walk's depth
976
+ * budget, and an `awsSecretAccessKey` in `props`, both sailed through into a
977
+ * request that was then sent.
978
+ *
979
+ * Two outcomes, because two things are being caught and they deserve different
980
+ * blast radii:
981
+ *
982
+ * - a value that IS a credential throws, via
983
+ * {@link assertNoCredentialInOptions};
984
+ * - a merely suspicious field name, or a structure too deep to have been read,
985
+ * returns a {@link BehaviourRefusalReport} with cause
986
+ * `credential-in-request`. No overlay is drawn and the reason names the
987
+ * path, which is the contract's own answer to "no faked numbers" applied to
988
+ * its own guard.
989
+ *
990
+ * The split exists because the name arm is a heuristic and the old version
991
+ * threw on it. One `tags: { author: "…" }` anywhere in an estate killed the
992
+ * entire overlay with a stack trace, which is the exact failure mode constraint
993
+ * 2 was written against.
994
+ *
995
+ * Returns `undefined` when the request is clean, so a lexicon reads
996
+ * `const refusal = screenBehaviourRequest(name, options); if (refusal) return refusal;`
997
+ */
998
+ export declare function screenBehaviourRequest(lexicon: string, options: object): BehaviourRefusalReport | undefined;
999
+ //# sourceMappingURL=behaviour.d.ts.map