@shiftleftpt/sbd-toe-mcp 0.20.0 → 0.21.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 (53) hide show
  1. package/README.md +2 -2
  2. package/dist/index.js +107 -266
  3. package/dist/index.js.map +1 -1
  4. package/dist/resources/sbd-toe-resources.js +1 -1
  5. package/dist/resources/sbd-toe-resources.js.map +1 -1
  6. package/dist/serving/adjacency.d.ts +68 -0
  7. package/dist/serving/adjacency.js +127 -0
  8. package/dist/serving/adjacency.js.map +1 -0
  9. package/dist/serving/affordances.js +4 -5
  10. package/dist/serving/affordances.js.map +1 -1
  11. package/dist/serving/agent-guide.js +5 -3
  12. package/dist/serving/agent-guide.js.map +1 -1
  13. package/dist/serving/behaviour-notes.d.ts +2 -2
  14. package/dist/serving/behaviour-notes.js +2 -8
  15. package/dist/serving/behaviour-notes.js.map +1 -1
  16. package/dist/serving/notes.d.ts +41 -0
  17. package/dist/serving/notes.js +43 -0
  18. package/dist/serving/notes.js.map +1 -0
  19. package/dist/serving/payload-ceilings.d.ts +73 -11
  20. package/dist/serving/payload-ceilings.js +85 -24
  21. package/dist/serving/payload-ceilings.js.map +1 -1
  22. package/dist/serving/response-shaping.d.ts +10 -0
  23. package/dist/serving/response-shaping.js +26 -0
  24. package/dist/serving/response-shaping.js.map +1 -1
  25. package/dist/serving/server-surface.d.ts +10 -0
  26. package/dist/serving/server-surface.js +14 -2
  27. package/dist/serving/server-surface.js.map +1 -1
  28. package/dist/serving/surface-history.d.ts +118 -0
  29. package/dist/serving/surface-history.js +119 -0
  30. package/dist/serving/surface-history.js.map +1 -0
  31. package/dist/tools/assess-implementation.d.ts +9 -0
  32. package/dist/tools/assess-implementation.js +7 -1
  33. package/dist/tools/assess-implementation.js.map +1 -1
  34. package/dist/tools/get-guide-by-role.d.ts +40 -0
  35. package/dist/tools/get-guide-by-role.js +158 -4
  36. package/dist/tools/get-guide-by-role.js.map +1 -1
  37. package/dist/tools/get-macro-processes.js +18 -8
  38. package/dist/tools/get-macro-processes.js.map +1 -1
  39. package/dist/tools/get-threat-landscape.js +11 -5
  40. package/dist/tools/get-threat-landscape.js.map +1 -1
  41. package/dist/tools/ontology-loader.d.ts +7 -0
  42. package/dist/tools/ontology-loader.js +2 -0
  43. package/dist/tools/ontology-loader.js.map +1 -1
  44. package/dist/tools/prepare-codegen-context.d.ts +339 -276
  45. package/dist/tools/prepare-codegen-context.js +454 -530
  46. package/dist/tools/prepare-codegen-context.js.map +1 -1
  47. package/dist/tools/resolve-entities.js +8 -4
  48. package/dist/tools/resolve-entities.js.map +1 -1
  49. package/dist/tools/select-requirements.d.ts +2 -1
  50. package/dist/tools/select-requirements.js +23 -8
  51. package/dist/tools/select-requirements.js.map +1 -1
  52. package/package.json +1 -1
  53. package/prompts/sbd-toe-grounded-codegen.md +11 -11
@@ -13,7 +13,7 @@
13
13
  * 3. Resolution: pull deterministic data from the three published sources
14
14
  * (runtime v0, runtime v1, overlay).
15
15
  * 4. Output: produce `activated_scope`, `g2_context`, `manual_grounding`,
16
- * `regulatory_overlay`, `citation_map`, `completeness_report`,
16
+ * `regulatory_overlay`, `citations` (0.21 §3: invertido em todos os níveis), `completeness_report`,
17
17
  * `llm_codegen_instructions` and `security_rationale_template`.
18
18
  *
19
19
  * Strict rules:
@@ -27,34 +27,34 @@
27
27
  * `unsupported_scope` for the overlay branch — never silently empty.
28
28
  */
29
29
  import type { Affordance } from "../serving/protocol-envelope.js";
30
+ import { type SizeEstimate } from "../serving/response-shaping.js";
31
+ import { type AdjacencySignal } from "../serving/adjacency.js";
32
+ import { NOTES_HEADER, type NoteId } from "../serving/notes.js";
30
33
  export type CodegenMode = "codegen" | "review" | "test-plan";
31
34
  export type RiskLevel = "L1" | "L2" | "L3";
32
35
  /**
33
- * Response ENCODING level (v2 token diet, epic v2-token-diet slice s1).
36
+ * Nível da resposta — linha 0.21 (§5, ratificada pelo lead 2026-09-25).
34
37
  *
35
- * - `full` (default): classic payload, byte-identical to previous releases —
36
- * whether `detail` is omitted or explicitly "full".
37
- * - `standard` / `minimal`: same citable ID set, deduplicated encoding
38
- * (inverted `citations`, grouped `manual_grounding`, top-level
39
- * `provenance_legend` instead of per-item `source`). No information is
40
- * lost — only the serialization changes. Since s3b (revised ADENDA
41
- * 2026-07-05 — no top-N/subsetting) `minimal` differs from `standard`
42
- * ONLY in traceability serialization: evidence cap 10→5 and the minimal
43
- * `manual_grounding` form; the activated scope stays complete and
44
- * byte-identical to `standard`.
45
- * - `ultrathin` (s3c, reactivated by the operator 2026-07-05): one level below
46
- * `minimal`, same rules (COMPLETE activated set, no top-k, nothing id-only,
47
- * never silent) but requirements/controls WITHOUT the published
48
- * `description` (executable `descriptions_ref` → detail="minimal"),
49
- * evidence_patterns 0 inline (counts + rest-ref → detail="minimal"),
50
- * `manual_grounding` reduced to {total_entries, manual_commit_sha,
51
- * groups_ref} and `completeness_report` diagnostics trimmed to exact counts
52
- * (+ executable ref). Citable ID set unchanged (invariant 3).
38
+ * O eixo deixou de ser «quanto detalhe» e passou a «o que está INLINE e o que
39
+ * está POR REFERÊNCIA». Uma coisa saiu do eixo: a descrição publicada de cada
40
+ * requisito NUNCA sai, em nenhum nível (§1 — o requisito fundido).
53
41
  *
54
- * The default flips to `standard` only at graduation to the next stable
55
- * release (documented as breaking) — never on the beta line.
42
+ * - `lista` — todo o requisito activado vem completo e verbatim (id, nome,
43
+ * descrição, como se verifica, que prova se espera), com os ids
44
+ * citáveis e as instruções que proíbem inventar ids. O
45
+ * ancoramento no manual vem por referência.
46
+ * - `standard` — o que a `lista` promete (a adjacência detalhada inline chega
47
+ * na §2; até lá difere da `lista` só no eco do nível).
48
+ * - `full` — o que o `standard` promete, e mais: o ancoramento no manual
49
+ * verbatim inline, as relações do grafo inline e o traço de
50
+ * activação. É o nível da completude: não promete caber,
51
+ * promete não faltar — e declara o preço em `size_estimate`.
52
+ *
53
+ * `ultrathin` reformou-se (a sua razão documentada era cortar a descrição) e
54
+ * `minimal` passou a chamar-se `lista` (herda-lhe o envelope de 8.450 tk).
55
+ * O default continua a ser `full` (omissão ≡ "full").
56
56
  */
57
- export type CodegenDetailLevel = "ultrathin" | "minimal" | "standard" | "full";
57
+ export type CodegenDetailLevel = "lista" | "standard" | "full";
58
58
  export interface PrepareCodegenContextInput {
59
59
  task: string;
60
60
  risk_level?: RiskLevel;
@@ -77,15 +77,22 @@ export interface PrepareCodegenContextInput {
77
77
  * Substituem o casamento de substring sobre o texto livre de `stack`.
78
78
  */
79
79
  technologies?: string[];
80
+ /**
81
+ * 0.21 §6 — FORMA B no prepare (como no select): declarações ESTRUTURAIS, verdadeiras e
82
+ * verificáveis contra o catálogo. É o que torna um lote de decomposição EXECUTÁVEL: cada
83
+ * lote é a partição das categorias que a tua declaração activou, e a união dos lotes é o
84
+ * conjunto inteiro (m_recall = 1, testado). Só no caminho declarativo.
85
+ */
86
+ chapters?: string[];
87
+ categories?: string[];
80
88
  regulatory_frameworks?: string[];
81
89
  include_regulatory_overlay?: boolean;
82
90
  detail?: CodegenDetailLevel;
83
91
  /**
84
92
  * v2 token diet, s2 — escape hatch for clients that cannot make a second
85
- * call: when true, `detail: "standard" | "minimal"` keeps `g2_context.relations`
93
+ * call: when true, `detail: "lista" | "standard"` keeps `g2_context.relations`
86
94
  * inline (dieted: no per-item `source`) instead of `relations_ref`.
87
- * Ignored at `detail: "full"` (full is always byte-identical to the classic
88
- * payload, relations inline).
95
+ * Ignored at `detail: "full"` (relations always inline there).
89
96
  */
90
97
  include_relations?: boolean;
91
98
  debug?: boolean;
@@ -120,13 +127,70 @@ export interface ActivationTraceEntry {
120
127
  /** Auditable reason explaining why the activation fired. */
121
128
  reason: string;
122
129
  }
130
+ /**
131
+ * 0.21 §1 — O REQUISITO FUNDIDO: um objecto por requisito, inline em TODOS os
132
+ * níveis. Antes, `activated_scope.requirements` trazia {requirement_id, name,
133
+ * category, type} e o «como verifico» vivia num bloco à parte
134
+ * (`g2_context.evidence_patterns`, chaveado por `maps_to_requirement_id`,
135
+ * capado a 25/10/5/0 por nível) — o modelo tinha de fazer o join, e um modelo
136
+ * apressado pegava no nome de três palavras e preenchia o resto de cabeça.
137
+ * Agora o requisito é UMA coisa: id, nome, descrição publicada (nunca sai),
138
+ * verificação e prova esperada — verbatim do bundle (requirements.json +
139
+ * evidence_patterns.json, 1:1 por requisito no KG v1.12.0). Os campos do
140
+ * padrão que NÃO vêm inline (evidence_pattern_id, control_id,
141
+ * expected_artifact_type_ids) mudam de sítio e passam a referenciados —
142
+ * `completeness_report.verification.by_ref` é a chamada executável.
143
+ */
144
+ export interface FusedRequirement {
145
+ id: string;
146
+ name: string;
147
+ /** Published `type` (base | domain-specific) — not derivable, kept inline. */
148
+ type?: string;
149
+ /** Lossless guard: present ONLY when not derivable from the id's category segment (expected never). */
150
+ category?: string;
151
+ /** Verbatim published description — NEVER elided, at any level (0.21 §1). */
152
+ description?: string;
153
+ /** Verbatim `verification_logic` of the requirement's published evidence pattern. */
154
+ verify?: string;
155
+ /** Verbatim `evidence_expectation` of the same pattern. */
156
+ evidence?: string;
157
+ /** Present at detail="full" only (the dieted levels carry it once, in `provenance_legend`). */
158
+ source?: "runtime_v0";
159
+ }
160
+ /**
161
+ * 0.21 §2 — A ADJACÊNCIA DECLARADA, ligada ao prepare. EM TODOS OS NÍVEIS, o mais magro
162
+ * incluído: não é nível de detalhe, é correcção — quem pede o modo barato é quem mais
163
+ * provavelmente sub-declarou, e um modo barato que cale «faltou-te privacidade» é pior do
164
+ * que não existir. Aritmética sobre o vocabulário fechado (src/serving/adjacency.ts): para
165
+ * cada valor NÃO declarado, a mesma selecção determinística com esse valor acrescentado,
166
+ * contando os ids que entrariam. Nunca leitura da tarefa. O resumo (top-N por impacto +
167
+ * denominadores) vai inline sempre; o detalhe (todos os sinais) vai inline em
168
+ * standard/full e por referência executável em lista — é o separador dos dois níveis.
169
+ * Em `selection_mode: "discover"` a adjacência é relativa à DECLARAÇÃO feita (a aritmética
170
+ * não lê o conjunto inferido): com declaração vazia, todo o vocabulário é adjacente.
171
+ */
172
+ export interface PrepareAdjacency {
173
+ /** Top-N por would_add (desempate estável: kind, depois nome). O nome do campo é a frase. */
174
+ undeclared_that_would_change_the_set: AdjacencySignal[];
175
+ /** Valores do vocabulário sondados (todos os não declarados). */
176
+ scanned: number;
177
+ /** Quantos mudariam o conjunto — o DENOMINADOR do resumo. */
178
+ would_change_the_set: number;
179
+ /** Quantos vão nomeados no resumo. */
180
+ shown: number;
181
+ /** standard/full: a lista COMPLETA (o resumo é o seu prefixo). */
182
+ detail?: AdjacencySignal[];
183
+ /** lista: onde está a lista completa — executável verbatim. */
184
+ detail_ref?: {
185
+ tool: "prepare_sbd_toe_codegen_context";
186
+ with: {
187
+ detail: "standard";
188
+ };
189
+ note_id: NoteId;
190
+ };
191
+ }
123
192
  export interface ActivatedScope {
124
- requirements: Array<{
125
- requirement_id: string;
126
- name: string;
127
- category: string;
128
- source: "runtime_v0";
129
- }>;
193
+ requirements: FusedRequirement[];
130
194
  controls: Array<{
131
195
  control_id: string;
132
196
  name: string;
@@ -134,6 +198,8 @@ export interface ActivatedScope {
134
198
  control_type: string;
135
199
  source: "runtime_v0";
136
200
  confidence: "direct" | "derived";
201
+ /** 0.21 §1: verbatim published description, `direct` controls only, at every level. */
202
+ description?: string;
137
203
  }>;
138
204
  slices: Array<{
139
205
  slice_id: string;
@@ -166,24 +232,21 @@ export interface G2ContextRelation {
166
232
  object_type: string | null;
167
233
  source: "runtime_v1";
168
234
  }
169
- export interface G2ContextEvidencePattern {
170
- id: string;
171
- maps_to_requirement_id?: string;
172
- maps_to_control_id?: string;
173
- evidence_expectation?: string;
174
- verification_logic?: string;
175
- expected_artifact_type_ids?: string[];
176
- /** Score in [0,1] driving cap order. 1.0 = direct control match, 0.7 = active requirement, 0.5 = derived control match. */
177
- relevance_score: number;
178
- source: "runtime_v0";
179
- }
235
+ /**
236
+ * 0.21 §1 — `g2_context.evidence_patterns` DEIXOU DE SER BLOCO. O «como
237
+ * verifico» de cada requisito activado vai inline no próprio requisito
238
+ * ({@link FusedRequirement}.verify/.evidence); os caps 25/10/5/0 por nível
239
+ * morreram com ele. Os padrões que só tocavam o âmbito por um CONTROLO
240
+ * activado (requisito fora do conjunto) não são inlinados — pertencem a
241
+ * outros requisitos — e ficam contados + referenciados em
242
+ * `completeness_report.verification` (nunca silencioso).
243
+ */
180
244
  export interface G2Context {
181
245
  control_objectives: G2ContextEntity[];
182
246
  mechanisms: G2ContextEntity[];
183
247
  practices: G2ContextEntity[];
184
248
  artifacts: G2ContextEntity[];
185
249
  relations: G2ContextRelation[];
186
- evidence_patterns: G2ContextEvidencePattern[];
187
250
  }
188
251
  export interface ManualGroundingEntry {
189
252
  rastreabilidade_role: string;
@@ -248,14 +311,8 @@ export interface CompletenessReport {
248
311
  unnamed_v1_entities: number;
249
312
  v1_consistency_mismatches: string[];
250
313
  v1_manifest_warnings: string[];
251
- /** Total evidence patterns matched before the relevance cap was applied. */
252
- evidence_patterns_total: number;
253
- /** Patterns retained in `g2_context.evidence_patterns` after the cap. */
254
- evidence_patterns_returned: number;
255
- /** Patterns dropped because of the cap (visible in debug.rejected_candidates). */
256
- evidence_patterns_capped: number;
257
- /** Cap value applied during this resolution. */
258
- evidence_pattern_cap: number;
314
+ /** 0.21 §1 — never-silent summary of the fused verification (see {@link VerificationSummary}). */
315
+ verification: VerificationSummary;
259
316
  /**
260
317
  * MP1 selection summary (G-mp1a O2, 2026-08-31): the requirement set comes from
261
318
  * the selection engine (baseline ∪ context-activated chapters, narrowed by the
@@ -268,7 +325,7 @@ export interface CompletenessReport {
268
325
  narrowed_out_categories: number;
269
326
  narrowed_out_requirements: number;
270
327
  /** Opcionais no perfil ultrathin (dieta s3c): a banda continua declarada no
271
- * select e nos perfis standard/minimal/full; recuperação via narrowed_out_ref. */
328
+ * select e em todos os níveis (0.21: lista/standard/full); recuperação via narrowed_out_ref. */
272
329
  excluded_by_level_categories?: number;
273
330
  excluded_by_level_requirements?: number;
274
331
  /** 0.19.0 (dieta por forma — tectos vigiam): fracção só-lexical da selecção; o
@@ -276,7 +333,49 @@ export interface CompletenessReport {
276
333
  lexical_share?: number;
277
334
  narrowed_out_ref: {
278
335
  tool: "select_sbd_toe_requirements";
279
- note: string;
336
+ note_id: NoteId;
337
+ };
338
+ };
339
+ }
340
+ /**
341
+ * 0.21 §1 — sumário NUNCA-SILENCIOSO da verificação fundida. Substitui os
342
+ * contadores do cap (total/returned/capped/cap) que morreram com o bloco.
343
+ * Cada número tem denominador nomeado; cada coisa que não vem inline tem a
344
+ * chamada executável que a devolve.
345
+ */
346
+ export interface VerificationSummary {
347
+ /** Denominator: activated requirements (= activated_scope.requirements.length). */
348
+ requirements: number;
349
+ /** Requirements carrying BOTH `verify` and `evidence` inline. */
350
+ with_verify_and_evidence: number;
351
+ /** Requirements whose published pattern lacks `verify` and/or `evidence` (expected 0 on KG v1.12.0). */
352
+ partial: number;
353
+ /** Requirements with NO published evidence pattern at all (expected 0 on KG v1.12.0). */
354
+ without_pattern: number;
355
+ /**
356
+ * Pattern fields NOT inlined in the fused requirement (evidence_pattern_id,
357
+ * control_id, expected_artifact_type_ids) — moved by reference: the
358
+ * verification matrix serves the full row per requirement (≤50 ids/call).
359
+ */
360
+ by_ref: {
361
+ tool: "get_sbd_toe_verification_matrix";
362
+ with: string;
363
+ /** Number of calls needed to cover every activated requirement (⌈requirements/50⌉). */
364
+ calls: number;
365
+ fields: ["evidence_pattern_id", "control_id", "expected_artifact_type_ids"];
366
+ note_id: NoteId;
367
+ };
368
+ /**
369
+ * Published patterns linked to an ACTIVATED control whose requirement is NOT
370
+ * in the activated set. Never inlined (they belong to other requirements);
371
+ * counted here and reachable by the executable ref.
372
+ */
373
+ related_by_control_outside_scope: {
374
+ count: number;
375
+ ref: {
376
+ tool: "resolve_entities";
377
+ with: string;
378
+ note_id: NoteId;
280
379
  };
281
380
  };
282
381
  }
@@ -284,7 +383,7 @@ export interface SecurityRationaleTemplate {
284
383
  task: string;
285
384
  decisions: Array<{
286
385
  decision: "<fill: what design choice was made>";
287
- rationale: "<fill: why, citing IDs from citation_map>";
386
+ rationale: "<fill: why, citing IDs from citations>";
288
387
  cited_ids: ["<requirement_id|control_id|slice_id|obligation_id>"];
289
388
  }>;
290
389
  validations: Array<{
@@ -301,6 +400,8 @@ export interface SecurityRationaleTemplate {
301
400
  }
302
401
  export interface PrepareCodegenContextResultReady {
303
402
  status: "ready_for_codegen";
403
+ /** 0.21 §6-c — como resolver qualquer `note_id` deste payload (um cabeçalho, não N notas). */
404
+ notes: typeof NOTES_HEADER;
304
405
  /** RF-H advisory band — adjacent tools the caller likely needs next. */
305
406
  next?: Affordance[];
306
407
  mode: CodegenMode;
@@ -309,6 +410,8 @@ export interface PrepareCodegenContextResultReady {
309
410
  };
310
411
  activation_trace: ActivationTraceEntry[];
311
412
  activated_scope: ActivatedScope;
413
+ /** 0.21 §2 — resumo + detalhe inline (full). */
414
+ adjacency: PrepareAdjacency;
312
415
  g2_context: G2Context;
313
416
  manual_grounding: ManualGroundingEntry[];
314
417
  regulatory_overlay: RegulatoryOverlayContext;
@@ -325,11 +428,46 @@ export interface PrepareCodegenContextResultReady {
325
428
  runtime_v1: string;
326
429
  overlay: string | "absent";
327
430
  };
431
+ /**
432
+ * 0.21 §5 — o preço DECLARADO desta resposta (chars e ≈tokens = chars/4, a
433
+ * mesma régua da medição). `full` não tem tecto: não promete caber, promete
434
+ * não faltar — e diz quanto custou. Presente em todos os níveis.
435
+ */
436
+ size_estimate?: DeclaredSize;
328
437
  debug?: {
329
438
  rejected_candidates: ActivationTraceEntry[];
330
439
  notes: string[];
331
440
  };
332
441
  }
442
+ /**
443
+ * 0.21 §5 — o preço declarado, e o envelope contra o qual se lê. `full` não
444
+ * tem envelope (promessa = completude). Nos níveis com envelope herdado
445
+ * (lista 8.450, standard 9.200) o payload diz se coube: `within_envelope`.
446
+ * Quando não coube, DIZ-O — nunca em silêncio (é a regra da casa desde a
447
+ * 0.19.4): o tecto por-id é o ratificado, mas o custo por requisito da forma
448
+ * fundida é o medido, e quando os dois não fecham o consumidor lê-o aqui.
449
+ */
450
+ export type DeclaredSize = SizeEstimate & {
451
+ envelope_tk?: number;
452
+ within_envelope?: boolean;
453
+ note_id?: NoteId;
454
+ };
455
+ export interface DecompositionBatch {
456
+ /** A receita EXECUTÁVEL: re-chama o prepare com estes campos (mais task, risk_level e detail). */
457
+ with: {
458
+ categories: string[];
459
+ technologies?: string[];
460
+ changed_files?: string[];
461
+ };
462
+ /** Contagem REAL do lote (selecção corrida), ≤ tecto por construção. */
463
+ requirements: number;
464
+ /** De onde vieram estas categorias na tua declaração: concerns e activadores largos (efeito preservado). */
465
+ derived_from: {
466
+ concerns: string[];
467
+ exposure?: string;
468
+ data_sensitivity?: string;
469
+ };
470
+ }
333
471
  export interface PrepareCodegenContextResultBlocked {
334
472
  status: "needs_clarification" | "needs_decomposition" | "unsupported_scope" | "needs_input";
335
473
  /**
@@ -352,13 +490,33 @@ export interface PrepareCodegenContextResultBlocked {
352
490
  cost_per_req_tk: number;
353
491
  projected_tk: number;
354
492
  promise_tk: number;
355
- batches: Array<{
356
- concerns: string[];
357
- estimated_requirements: number;
358
- }>;
493
+ /**
494
+ * 0.21 §6 (condição da decisão (a), lead 2026-09-25): os lotes SOMAM O TODO. Cada lote é
495
+ * uma declaração ESTRUTURAL (`categories` — a partição exacta das categorias que a tua
496
+ * declaração activou), com `technologies` e `changed_files` preservados literalmente;
497
+ * `exposure`/`data_sensitivity` estão preservados pelo seu EFEITO (as categorias que
498
+ * produziram entram na partição) e não re-declarados — re-declará-los somaria as suas
499
+ * categorias a todos os lotes e nenhum caberia. `requirements` é a contagem REAL do lote
500
+ * (a selecção corre-se), não uma estimativa; a união dos lotes ⊇ a selecção inteira.
501
+ */
502
+ batches: DecompositionBatch[];
503
+ /** Denominador da prova: união dos lotes vs selecção inteira (m_recall = 1 por construção; verificado nos testes). */
504
+ union: {
505
+ requirements: number;
506
+ recall: number;
507
+ };
359
508
  };
360
509
  /** RF-H advisory band — adjacent tools the caller likely needs next. */
361
510
  next?: Affordance[];
511
+ /**
512
+ * 0.21 §6 — em `needs_input`, o objecto do motor (razão, recurso do vocabulário, exemplo,
513
+ * candidatos a confirmar, declarações inertes) mais `valid_values`: para cada eixo que ficou
514
+ * inerte (stack/technologies, exposure, data_sensitivity), a LISTA dos valores válidos — o
515
+ * erro nomeia o vocabulário, não só o aponta.
516
+ */
517
+ needs_input?: Record<string, unknown> & {
518
+ valid_values?: Record<string, string[]>;
519
+ };
362
520
  mode: CodegenMode;
363
521
  input_echo: Required<Pick<PrepareCodegenContextInput, "task">> & Omit<PrepareCodegenContextInput, "task"> & {
364
522
  task_role?: string;
@@ -375,7 +533,7 @@ export interface PrepareCodegenContextResultBlocked {
375
533
  * provenance is carried once, in `provenance_legend`). */
376
534
  export type WithoutSource<T> = Omit<T, "source">;
377
535
  /**
378
- * Inverted citation encoding (replaces `citation_map` in `standard`/`minimal`).
536
+ * Inverted citation encoding (replaces `citation_map` in `lista`/`standard`).
379
537
  * Grouped by source; `source_data` is an ORDERED run-length map
380
538
  * `file → count`: the first N₁ citable ids come from the first file, the
381
539
  * next N₂ from the second, and so on. This preserves the exact per-id
@@ -448,17 +606,17 @@ export interface ManualGroundingMinimalGroup {
448
606
  * (kept verbatim from the standard group; expected never). */
449
607
  v1_entity_names?: Record<string, string>;
450
608
  }
451
- /** Executable reference to the full per-group grounding ids (s3b). */
452
- export interface GroundingGroupsRef {
609
+ /** Executable reference to the flat, verbatim grounding entries (detail="full"). */
610
+ export interface GroundingEntriesRef {
453
611
  tool: "prepare_sbd_toe_codegen_context";
454
- /** Merge over this call's input_echo: same input, detail="standard". */
612
+ /** Merge over this call's input_echo: same input, detail="full". */
455
613
  with: {
456
- detail: "standard";
614
+ detail: "full";
457
615
  };
458
- note: string;
616
+ note_id: NoteId;
459
617
  }
460
618
  /**
461
- * `manual_grounding` at `detail: "minimal"` (s3b revised): aggregated
619
+ * `manual_grounding` at `detail: "lista" | "standard"` (0.21; born as the s3b minimal form): aggregated
462
620
  * provenance — total count, the manual_commit_sha shared by every group
463
621
  * (hoisted), and the (role, chapter, file) group list with per-group entry
464
622
  * COUNTS instead of per-group id lists — plus the executable `groups_ref`.
@@ -474,13 +632,13 @@ export interface ManualGroundingMinimal {
474
632
  * its own `manual_commit_sha` inline (lossless guard). */
475
633
  manual_commit_sha?: string;
476
634
  groups: ManualGroundingMinimalGroup[];
477
- /** How to obtain the full per-group v1_entity_ids (detail="standard"). */
478
- groups_ref: GroundingGroupsRef;
635
+ /** 0.21: how to obtain the verbatim flat entries (detail="full" — the only level that inlines the grounding). */
636
+ entries_ref: GroundingEntriesRef;
479
637
  /** Lossless guard: entries without a v1_entity_id (expected empty). */
480
638
  ungrouped?: Array<WithoutSource<ManualGroundingEntry>>;
481
639
  }
482
640
  /**
483
- * `manual_grounding` at `detail: "ultrathin"` (s3c): aggregate provenance ONLY
641
+ * RETIRADO na 0.21 (era `manual_grounding` at `detail: "ultrathin"`): aggregate provenance ONLY
484
642
  * — `{total_entries, manual_commit_sha, groups_ref}` — derived from the s3b
485
643
  * minimal form with the (role, chapter, file) group list elided too. Never
486
644
  * silent: `total_entries` is the exact flat detail="full" entry count and
@@ -493,74 +651,27 @@ export interface ManualGroundingMinimal {
493
651
  * `citations`/`ids_from`, and the grounding id SET stays reconstructible from
494
652
  * this same payload's g2_context entity maps without any extra call.
495
653
  */
496
- export interface ManualGroundingUltrathin {
497
- /** Number of flat detail="full" entries the elided groups encode. */
498
- total_entries: number;
499
- /** Hoisted provenance (expected always: one published manual commit). */
500
- manual_commit_sha?: string;
501
- /** Lossless guard: present ONLY when hoisting failed or a group carried
502
- * v1_entity_names (never expected) — the s3b minimal groups, verbatim. */
503
- groups?: ManualGroundingMinimalGroup[];
504
- /** How to obtain the full per-group v1_entity_ids (detail="standard"). */
505
- groups_ref: GroundingGroupsRef;
506
- /** Lossless guard: entries without a v1_entity_id (expected empty). */
507
- ungrouped?: Array<WithoutSource<ManualGroundingEntry>>;
508
- }
509
654
  /**
510
- * v2 token diet, s3 — dieted requirement projection. `category` is elided when
511
- * (and only when) it equals the category segment of the `requirement_id` —
512
- * the segment immediately before the number (`AUT-003` → `AUT`,
513
- * `REQ-AGN-001` → `AGN`; consumer contract v1.10 §1.18, single source
514
- * `src/serving/requirement-id.ts`). True for all 255 published requirements;
515
- * the field survives verbatim on any future mismatch — lossless guard. `description` is the PUBLISHED bundle
516
- * field (data/publish/runtime/requirements.json), verbatim, never paraphrased
517
- * — the "how" the full projection historically dropped.
655
+ * 0.21 §1 — dieted requirement = the fused requirement without the per-item
656
+ * `source` (carried once in `provenance_legend`). `category` is elided when
657
+ * (and only when) it equals the id's category segment (`AUT-003` → `AUT`,
658
+ * `REQ-AGN-001` → `AGN`; consumer contract v1.10 §1.18) — lossless guard.
518
659
  */
519
- export interface DietedRequirement {
520
- requirement_id: string;
521
- name: string;
522
- type?: string;
523
- /** Present only on the (never expected) category ≠ id-category-segment mismatch. */
524
- category?: string;
525
- /** Verbatim `description` from the published bundle. */
526
- description?: string;
527
- }
660
+ export type DietedRequirement = WithoutSource<FusedRequirement>;
528
661
  /**
529
662
  * v2 token diet, s3 — dieted control projection: classic fields minus `source`
530
663
  * plus, for `confidence: "direct"` controls only, the verbatim published
531
664
  * `description` (data/publish/runtime/controls.json).
532
665
  */
533
- export type DietedControl = WithoutSource<ActivatedScope["controls"][number]> & {
534
- description?: string;
535
- };
536
- /**
537
- * v2 token diet, s3c — executable reference left in `activated_scope` at
538
- * `detail: "ultrathin"`, where the verbatim published `description` fields
539
- * (the "how", s3) are elided from requirements and direct controls. Never
540
- * silent: the lists themselves stay COMPLETE (same ids, same order, name
541
- * always present — nothing id-only); only the description field moves behind
542
- * this reference. detail="minimal" is the cheapest level that returns the
543
- * same complete scope WITH the descriptions (verbatim, never paraphrased).
544
- */
545
- export interface ActivatedScopeDescriptionsRef {
546
- tool: "prepare_sbd_toe_codegen_context";
547
- /** Merge over this call's input_echo: same input, detail="minimal". */
548
- with: {
549
- detail: "minimal";
550
- };
551
- note: string;
552
- }
666
+ export type DietedControl = WithoutSource<ActivatedScope["controls"][number]>;
553
667
  export interface DietedActivatedScope {
554
668
  requirements: DietedRequirement[];
555
669
  controls: DietedControl[];
556
670
  slices: Array<WithoutSource<ActivatedScope["slices"][number]>>;
557
671
  regulatory_obligations: Array<WithoutSource<ActivatedScope["regulatory_obligations"][number]>>;
558
- /** Present ONLY at detail="ultrathin" (s3c): how to obtain the verbatim
559
- * published descriptions elided from requirements + direct controls. */
560
- descriptions_ref?: ActivatedScopeDescriptionsRef;
561
672
  }
562
673
  /**
563
- * v2 token diet, s2 — Relations on-demand. In `standard`/`minimal` the inline
674
+ * v2 token diet, s2 — Relations on-demand. In `lista`/`standard` the inline
564
675
  * `g2_context.relations` array (~4.3K tokens) is replaced by a REFERENCE to
565
676
  * executable calls of the `trace_sbd_toe_graph` tool whose union returns a
566
677
  * superset of the elided relations. Anchors are activated slice_ids/entity_ids
@@ -610,10 +721,10 @@ export interface RelationsRef {
610
721
  };
611
722
  /** Only present when a relation is neither lens-recoverable nor implicit. */
612
723
  residual_relations?: Array<WithoutSource<G2ContextRelation>>;
613
- note: string;
724
+ note_id: NoteId;
614
725
  }
615
726
  /**
616
- * v2 token diet, s3 — slice-grouped entity encoding for `standard`/`minimal`:
727
+ * v2 token diet, s3 — slice-grouped entity encoding for `lista`/`standard`:
617
728
  * `{ slice_id: { entity_id: name | null } }`. Lossless re-encoding of the
618
729
  * classic entity list: `entity_type` is the list the map lives in,
619
730
  * `slice_id` is the group key, `slice_family` is
@@ -622,13 +733,6 @@ export interface RelationsRef {
622
733
  * Group/key order preserves the classic list order (insertion order).
623
734
  */
624
735
  export type SliceGroupedEntityNames = Record<string, Record<string, string | null>>;
625
- /**
626
- * v2 token diet, s3 — dieted evidence pattern: classic projection minus
627
- * `source` (s1 legend) and minus the tool-computed `relevance_score` (the
628
- * DETERMINISTIC list order — relevance_score desc, then id asc — already
629
- * carries the ranking; documented in the codegen-instructions resource).
630
- */
631
- export type DietedEvidencePattern = Omit<G2ContextEvidencePattern, "source" | "relevance_score">;
632
736
  export interface DietedG2Context {
633
737
  control_objectives: SliceGroupedEntityNames;
634
738
  mechanisms: SliceGroupedEntityNames;
@@ -636,12 +740,43 @@ export interface DietedG2Context {
636
740
  artifacts: SliceGroupedEntityNames;
637
741
  /** Inline only with `include_relations: true` (s2); otherwise see relations_ref. */
638
742
  relations?: Array<WithoutSource<G2ContextRelation>>;
639
- /** Present when relations are elided (s2 default at standard/minimal). */
640
- relations_ref?: RelationsRef;
641
- /** s3: deterministic top-{@link STANDARD_EVIDENCE_PATTERN_CAP} prefix of the
642
- * classic list (see completeness_report for the never-silent counts). */
643
- evidence_patterns: DietedEvidencePattern[];
743
+ /** 0.21 §3: relations LEAVE the dieted levels — this never-silent summary replaces relations_ref
744
+ * (0 of the relations point outside what the payload already carries in the measured cases;
745
+ * any that cannot be recovered from the payload or a lens stays inline in residual_relations). */
746
+ relations_summary?: RelationsSummary;
747
+ /** Only present when a relation is neither lens-recoverable nor implicit (expected 0). */
748
+ residual_relations?: Array<WithoutSource<G2ContextRelation>>;
644
749
  }
750
+ /**
751
+ * 0.21 §3 — «relations saem» dos níveis dieted: medido, as relações activadas
752
+ * ligam nós que o payload JÁ recebeu (belongsToSlice ≡ slice_id da entidade;
753
+ * objective→mechanism/practice recuperável por trace_sbd_toe_graph). Fica a
754
+ * contabilidade exacta (a mesma do relations_ref do full) e o caminho de volta.
755
+ */
756
+ export interface RelationsSummary {
757
+ total_relations: number;
758
+ via_lenses: number;
759
+ implicit_in_entities: number;
760
+ residual_inline: number;
761
+ note_id: NoteId;
762
+ }
763
+ /**
764
+ * 0.21 §3 — o `full` SERVIDO: o classic com duas mudanças de forma, sem mudança
765
+ * de conjunto (invariante 3): `citations` invertido (legenda por fonte + ids
766
+ * referenciados por caminho do payload — a função de `citation_map` era «estes
767
+ * ids são legais», e a forma repetia {source, source_data} uma vez por id) e
768
+ * `relations_ref` em vez das relations inline (`include_relations: true`
769
+ * repõe-nas). O core continua a construir citation_map/relations internamente.
770
+ */
771
+ export type PrepareCodegenContextResultReadyFull = Omit<PrepareCodegenContextResultReady, "citation_map" | "g2_context"> & {
772
+ citations: CitationsBySource;
773
+ g2_context: Omit<G2Context, "relations"> & {
774
+ /** Inline only with `include_relations: true`. */
775
+ relations?: G2ContextRelation[];
776
+ /** Default at full: executable trace_sbd_toe_graph calls + exact coverage accounting. */
777
+ relations_ref?: RelationsRef;
778
+ };
779
+ };
645
780
  export interface DietedRegulatoryOverlayContext {
646
781
  frameworks: Array<WithoutSource<RegulatoryOverlayContext["frameworks"][number]>>;
647
782
  obligations: Array<WithoutSource<RegulatoryOverlayContext["obligations"][number]>>;
@@ -649,42 +784,23 @@ export interface DietedRegulatoryOverlayContext {
649
784
  playbooks: Array<WithoutSource<RegulatoryOverlayContext["playbooks"][number]>>;
650
785
  }
651
786
  /**
652
- * Inline legend for `standard`/`minimal` (s3: slim pointer — the full legend,
653
- * including the section→source table and every derivation rule of the dieted
654
- * encoding, lives in the `sbd://toe/codegen-instructions/{mode}` resource,
655
- * section `detail_encoding`).
787
+ * Inline legend for `lista`/`standard` (0.21): slim pointer — the full legend
788
+ * (section→source table + every derivation rule of the dieted encoding) lives
789
+ * in the `sbd://toe/codegen-instructions/{mode}` resource, `detail_encoding`.
656
790
  */
657
791
  declare const PROVENANCE_LEGEND: {
658
- readonly note: string;
792
+ readonly note_id: NoteId;
659
793
  };
660
794
  export type ProvenanceLegend = typeof PROVENANCE_LEGEND;
661
795
  /**
662
- * v2 token diet, s4 — cheap turns, not fewer turns: short note (≈50 tokens)
663
- * appended to every `standard`/`minimal` ready payload. The production
664
- * write-test-edit loop is legitimate; what must not repeat is the cost of
665
- * re-requesting THIS payload — an identical call returns a byte-identical
666
- * result (deterministic, tested), so the context already in the session is
667
- * the source for the loop. Follow-ups that genuinely need more go through
668
- * `detail: "minimal"` or a targeted `consult_security_requirements` call —
669
- * never a repeat of the full payload. `full` carries NO hint (byte-identical
670
- * to the classic payload, EPIC invariant 1).
796
+ * v2 token diet, s4 — cheap turns, not fewer turns: short note appended to
797
+ * every `lista`/`standard` ready payload. An identical call returns a
798
+ * byte-identical result (deterministic, tested), so the context already in the
799
+ * session is the source for the write-test-edit loop. Follow-ups that need the
800
+ * inline grounding/relations/trace go through `detail: "full"` (declared
801
+ * price in size_estimate) or a targeted `consult_security_requirements` call.
671
802
  */
672
- export declare const REPEAT_CALL_HINT = "Identical input returns this exact payload (deterministic) \u2014 reuse the context already received; deepen via detail:'minimal' or a targeted consult_security_requirements.";
673
- /**
674
- * v2 token diet, s3 — reference that replaces the inline
675
- * `llm_codegen_instructions` + `security_rationale_template` boilerplate at
676
- * `detail: "standard" | "minimal"` (both stay inline at `full`). The MCP
677
- * resource carries, per mode, the exact instruction slots and the template
678
- * skeleton; `active_conditions` lists which conditional slots apply to THIS
679
- * call, so the inline full content is reconstructible byte-identically.
680
- */
681
- export interface CodegenInstructionsRef {
682
- resource: string;
683
- /** Conditional instruction slots active for this call (see the resource's
684
- * `llm_codegen_instructions.slots[].when`). */
685
- active_conditions: InstructionCondition[];
686
- note: string;
687
- }
803
+ export declare const REPEAT_CALL_HINT: string;
688
804
  /**
689
805
  * v2 token diet, s3 — never-silent counter left in place of the elided
690
806
  * `activation_trace` at `detail: "standard" | "minimal"` (the full trace is
@@ -692,107 +808,27 @@ export interface CodegenInstructionsRef {
692
808
  */
693
809
  export interface ActivationTraceRef {
694
810
  entries: number;
695
- note: string;
811
+ note_id: NoteId;
696
812
  }
697
813
  /**
698
- * v2 token diet, s3 — executable reference for retrieving the evidence
699
- * patterns omitted by the standard cap (boundList discipline: the counts live
700
- * in the same completeness_report; this says HOW to get the rest).
701
- */
702
- export interface EvidencePatternsRest {
703
- tool: "prepare_sbd_toe_codegen_context";
704
- /** Merge over this call's input_echo: same input, detail="full" (the
705
- * classic top-25) at standard/minimal; detail="minimal" (the CHEAPEST level
706
- * that returns patterns inline) at ultrathin (s3c). */
707
- with: {
708
- detail: "full";
709
- } | {
710
- detail: "minimal";
711
- };
712
- note: string;
713
- }
714
- /** Completeness report at `standard`/`minimal`: classic counters (with the
715
- * s3 cap values) plus, when patterns were cut, the executable rest-reference. */
716
- export type DietedCompletenessReport = CompletenessReport & {
717
- evidence_patterns_rest?: EvidencePatternsRest;
718
- };
719
- /**
720
- * v2 token diet, s3c — executable reference for the completeness diagnostics
721
- * elided at `detail: "ultrathin"` (never silent: exact counts stay inline;
722
- * detail="minimal" is the cheapest level whose completeness_report carries
723
- * the full text arrays inline).
724
- */
725
- export interface V1DiagnosticsRef {
726
- tool: "prepare_sbd_toe_codegen_context";
727
- /** Merge over this call's input_echo: same input, detail="minimal". */
728
- with: {
729
- detail: "minimal";
730
- };
731
- note: string;
732
- }
733
- /**
734
- * Completeness report at `detail: "ultrathin"` (s3c) — trimmed to the
735
- * essentials that support the never-silent discipline. KEPT verbatim: every
736
- * expected/returned count and m_recall (recall audit), named/unnamed entity
737
- * counts, and the evidence counts (total / returned=0 / capped=total / cap=0)
738
- * with the executable `evidence_patterns_rest`. CUT (serialization only, each
739
- * replaced by its exact count + the executable `v1_diagnostics_ref` when any
740
- * count > 0): the `v1_consistency_mismatches` and `v1_manifest_warnings` TEXT
741
- * arrays (the verbose per-slice contract-warning strings, ~100 tokens/call).
742
- */
743
- export type UltrathinCompletenessReport = Omit<DietedCompletenessReport, "v1_consistency_mismatches" | "v1_manifest_warnings"> & {
744
- /** Exact length of the elided v1_consistency_mismatches array (expected 0). */
745
- v1_consistency_mismatches_count: number;
746
- /** Exact length of the elided v1_manifest_warnings array. */
747
- v1_manifest_warnings_count: number;
748
- /** Present iff either count above is > 0: how to obtain the full texts. */
749
- v1_diagnostics_ref?: V1DiagnosticsRef;
750
- };
751
- /**
752
- * `ready_for_codegen` result at `detail: "standard" | "minimal"`. Same citable
753
- * ID set as the full result (invariant 3) — the encoding is deduplicated (s1),
754
- * relations are served on-demand (s2) and, since s3:
755
- * - `g2_context.evidence_patterns` is capped 25→10 (deterministic prefix;
756
- * never-silent counts + rest-reference in `completeness_report`);
757
- * - `llm_codegen_instructions` + `security_rationale_template` move to the
758
- * `sbd://toe/codegen-instructions/{mode}` MCP resource
759
- * (`codegen_instructions_ref` carries the URI + active conditions);
814
+ * `ready_for_codegen` result at `detail: "lista" | "standard"` (0.21). Same
815
+ * citable ID set as the full result (invariant 3) — the encoding is
816
+ * deduplicated (s1), relations are served on-demand (s2), and since 0.21 §1:
817
+ * - every requirement is the FUSED object (id, name, type, description,
818
+ * verify, evidence) — the description never leaves;
819
+ * - `llm_codegen_instructions` + `security_rationale_template` are INLINE
820
+ * (they are what stops id invention);
821
+ * - `manual_grounding` is the counts+sha form with an executable
822
+ * `entries_ref` → detail="full" (the only level that inlines it);
760
823
  * - `activation_trace` is included only with `debug: true`
761
- * (`activation_trace_ref` keeps the never-silent count otherwise);
762
- * - requirements and `direct` controls carry the verbatim published
763
- * `description` (the "how"), and derivable fields (`category`,
764
- * `entity_type`, `slice_family`, `relevance_score`, repeated citation ids)
765
- * are elided per the resource's `detail_encoding` legend.
766
- *
767
- * s3b (revised per the 2026-07-05 operator ADENDA — NO top-N/subsetting):
768
- * `minimal` diverges from `standard` ONLY in serialization of traceability,
769
- * never in execution context. The activated scope (requirements + controls
770
- * with descriptions, slices, obligations, g2 entities, citations,
771
- * relations_ref) is byte-identical to `standard`; `minimal` additionally
772
- * - caps `g2_context.evidence_patterns` 10→5 (same s3 mechanism: prefix,
773
- * counts, rest-ref);
774
- * - serves `manual_grounding` in the minimal form ({@link
775
- * ManualGroundingMinimal}: counts + hoisted sha + executable groups_ref).
776
- *
777
- * s3c (`detail: "ultrathin"`, operator ADENDA 2026-07-05): one level below
778
- * `minimal`, same rules (activated set COMPLETE, no top-k, nothing id-only,
779
- * never silent). Diverges from `minimal` ONLY in:
780
- * - requirements/controls WITHOUT the published `description` (fields kept:
781
- * requirement {requirement_id, name, type}; control {control_id, name,
782
- * domain, control_type, confidence}; the `category` lossless guard is
783
- * unchanged) + executable `activated_scope.descriptions_ref`;
784
- * - `g2_context.evidence_patterns` cap 5→0 (counts + rest-ref to the
785
- * cheapest level that returns them: detail="minimal");
786
- * - `manual_grounding` in the ultrathin form ({@link ManualGroundingUltrathin}:
787
- * total + hoisted sha + executable groups_ref, group list elided);
788
- * - `completeness_report` diagnostics trimmed ({@link
789
- * UltrathinCompletenessReport}: text arrays → exact counts + executable ref).
790
- * Everything else — g2 entity maps (id→name|null), relations_ref, citations,
791
- * codegen_instructions_ref, repeat_call_hint, provenance, next — is
792
- * byte-identical to the other dieted levels.
824
+ * (`activation_trace_ref` keeps the never-silent count otherwise).
825
+ * `lista` and `standard` differ only in the echoed level until the §2
826
+ * adjacency detail lands (declared, not decided: see decisions/0003 §6.2).
793
827
  */
794
828
  export interface PrepareCodegenContextResultReadyDieted {
795
829
  status: "ready_for_codegen";
830
+ /** 0.21 §6-c — como resolver qualquer `note_id` deste payload. */
831
+ notes: typeof NOTES_HEADER;
796
832
  /** RF-H advisory band — adjacent tools the caller likely needs next. */
797
833
  next?: Affordance[];
798
834
  mode: CodegenMode;
@@ -803,20 +839,27 @@ export interface PrepareCodegenContextResultReadyDieted {
803
839
  activation_trace_ref?: ActivationTraceRef;
804
840
  provenance_legend: ProvenanceLegend;
805
841
  activated_scope: DietedActivatedScope;
842
+ /** 0.21 §2 — resumo inline sempre; detalhe inline (standard) ou por referência (lista). */
843
+ adjacency: PrepareAdjacency;
806
844
  g2_context: DietedG2Context;
807
- /** Grouped (standard), minimal (s3b) or ultrathin form (s3c). */
808
- manual_grounding: ManualGroundingGrouped | ManualGroundingMinimal | ManualGroundingUltrathin;
845
+ /** Counts + hoisted sha + executable entries_ref (detail="full"). */
846
+ manual_grounding: ManualGroundingMinimal;
809
847
  regulatory_overlay: DietedRegulatoryOverlayContext;
810
848
  citations: CitationsBySource;
811
- completeness_report: DietedCompletenessReport | UltrathinCompletenessReport;
812
- codegen_instructions_ref: CodegenInstructionsRef;
813
- /** s4 — reuse note ({@link REPEAT_CALL_HINT}): identical re-call is
849
+ completeness_report: CompletenessReport;
850
+ llm_codegen_instructions: string[];
851
+ security_rationale_template: SecurityRationaleTemplate;
852
+ /** s4 — reuse note (texto em sbd://toe/notes/prepare.repeat_call_hint): identical re-call is
814
853
  * deterministic; the context already received is the loop's source. */
815
- repeat_call_hint: string;
854
+ repeat_call_hint: {
855
+ note_id: NoteId;
856
+ };
816
857
  provenance: PrepareCodegenContextResultReady["provenance"];
858
+ /** 0.21 §5 — declared price of this response (chars, ≈tokens, envelope). */
859
+ size_estimate?: DeclaredSize;
817
860
  debug?: PrepareCodegenContextResultReady["debug"];
818
861
  }
819
- export type PrepareCodegenContextResult = PrepareCodegenContextResultReady | PrepareCodegenContextResultReadyDieted | PrepareCodegenContextResultBlocked;
862
+ export type PrepareCodegenContextResult = PrepareCodegenContextResultReadyFull | PrepareCodegenContextResultReadyDieted | PrepareCodegenContextResultBlocked;
820
863
  export declare const VALID_CONCERNS: readonly ["auth", "logging", "validation", "api", "config", "integrity", "distribution", "ide", "requirements", "architecture", "iac", "encryption", "secrets", "build", "supply_chain", "testing", "threat_modeling", "monitoring", "release", "deployment", "integration", "files", "privacy", "agents"];
821
864
  export type Concern = (typeof VALID_CONCERNS)[number];
822
865
  /**
@@ -880,7 +923,7 @@ export declare function categoriesForConcerns(concerns: Concern[]): Set<string>;
880
923
  * lists the conditions active for a given call, so a client reading the
881
924
  * resource reconstructs the inline instruction list byte-identically.
882
925
  */
883
- export type InstructionCondition = "always" | "regulatory_overlay" | "risk_level:L1" | "risk_level:L2" | "risk_level:L3" | "citation_map_empty";
926
+ export type InstructionCondition = "always" | "regulatory_overlay" | "risk_level:L1" | "risk_level:L2" | "risk_level:L3" | "citations_empty";
884
927
  export interface InstructionSlot {
885
928
  when: InstructionCondition;
886
929
  text: string;
@@ -895,14 +938,16 @@ export declare const CODEGEN_INSTRUCTION_MODES: readonly CodegenMode[];
895
938
  export declare const CODEGEN_INSTRUCTIONS_RESOURCE_URI_PREFIX = "sbd://toe/codegen-instructions/";
896
939
  export declare function codegenInstructionsResourceUri(mode: CodegenMode): string;
897
940
  /**
898
- * Full legend of the dieted (`standard`/`minimal`) encoding, published in the
941
+ * Full legend of the dieted (`lista`/`standard`) encoding, published in the
899
942
  * codegen-instructions resource. Every rule here is a lossless, deterministic
900
943
  * derivation over the SAME payload (or an executable reference) — nothing is
901
944
  * silently dropped (EPIC invariant 2) and no data changes, only serialization
902
- * (EPIC invariant 4).
945
+ * (EPIC invariant 4). 0.21 §1: the requirement is fused (description never
946
+ * leaves) and the evidence_patterns block is gone at every level.
903
947
  */
904
948
  declare const DETAIL_ENCODING_LEGEND: {
905
949
  readonly note: string;
950
+ readonly levels: string;
906
951
  readonly sources: {
907
952
  readonly note: string;
908
953
  readonly map: {
@@ -915,7 +960,6 @@ declare const DETAIL_ENCODING_LEGEND: {
915
960
  readonly "g2_context.practices": "runtime_v1";
916
961
  readonly "g2_context.artifacts": "runtime_v1";
917
962
  readonly "g2_context.relations": "runtime_v1";
918
- readonly "g2_context.evidence_patterns": "runtime_v0";
919
963
  readonly "manual_grounding.groups": "runtime_v1";
920
964
  readonly "regulatory_overlay.frameworks": "overlay";
921
965
  readonly "regulatory_overlay.obligations": "overlay";
@@ -926,12 +970,12 @@ declare const DETAIL_ENCODING_LEGEND: {
926
970
  readonly citations: string;
927
971
  readonly activated_scope_requirements: string;
928
972
  readonly activated_scope_controls: string;
973
+ readonly adjacency: string;
929
974
  readonly g2_entities: string;
930
- readonly evidence_patterns: string;
931
- readonly manual_grounding_minimal: string;
975
+ readonly verification: string;
976
+ readonly manual_grounding: string;
932
977
  readonly activation_trace: string;
933
978
  readonly relations_ref: string;
934
- readonly ultrathin: string;
935
979
  };
936
980
  export interface CodegenInstructionsResourceContent {
937
981
  resource: string;
@@ -961,6 +1005,25 @@ export interface CodegenInstructionsResourceContent {
961
1005
  * task string (input_echo.task.trim()).
962
1006
  */
963
1007
  export declare function buildCodegenInstructionsResourceContent(mode: CodegenMode): CodegenInstructionsResourceContent;
1008
+ /**
1009
+ * 0.21 §3 — resolve the ids of a `citations` block over the payload that carries it
1010
+ * (any level): `section.list[].field` iterates a list; `keys(g2_context.<list>[slice])`
1011
+ * iterates the slice groups then the entity-id keys. Explicit `ids` is the lossless
1012
+ * fallback. Exported so consumers and tests read ids by the SAME published rule.
1013
+ */
1014
+ export declare function citableIds(payload: unknown): string[];
1015
+ /**
1016
+ * 0.21 — a forma por nível é uma TABELA, não ramos: o que cada nível põe
1017
+ * inline e o que põe por referência. Parametrizável de propósito — a §4 do
1018
+ * despacho (o Mensor mede se o `manual_grounding` vai inline ou por
1019
+ * referência) e o «2 ou 3 níveis» ficam em aberto e decidem-se aqui, numa
1020
+ * linha, sem reescrever o servidor.
1021
+ */
1022
+ export declare const LEVEL_FORM: Readonly<Record<Exclude<CodegenDetailLevel, "full">, {
1023
+ manual_grounding: "ref";
1024
+ relations: "ref";
1025
+ adjacency_detail: "ref" | "inline";
1026
+ }>>;
964
1027
  export declare function handlePrepareCodegenContext(raw: PrepareCodegenContextInput): PrepareCodegenContextResult;
965
1028
  export declare const __wp5Lexicon: {
966
1029
  VALID_CONCERNS: readonly ["auth", "logging", "validation", "api", "config", "integrity", "distribution", "ide", "requirements", "architecture", "iac", "encryption", "secrets", "build", "supply_chain", "testing", "threat_modeling", "monitoring", "release", "deployment", "integration", "files", "privacy", "agents"];