@shiftleftpt/sbd-toe-mcp 0.10.3 → 0.11.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 (47) hide show
  1. package/assets/agent-guide.md +33 -0
  2. package/consumed-bundle.json +8 -8
  3. package/data/entities/proportionality.json +2 -2
  4. package/data/entities/sdlc_integration.json +2 -2
  5. package/data/publish/indexes/canonical_chunks.jsonl +4903 -4903
  6. package/data/publish/indexes/publication_manifest.json +4 -4
  7. package/data/publish/ontology/sbdtoe-ontology.yaml +1699 -21
  8. package/data/publish/overlay/framework_overlay_index.json +121 -11
  9. package/data/publish/overlay/overlay_mappings.jsonl +935 -646
  10. package/data/publish/runtime/artifact_requirements.json +218 -311
  11. package/data/publish/runtime/artifacts.json +82 -55
  12. package/data/publish/runtime/controls.json +870 -311
  13. package/data/publish/runtime/deterministic_manifest.json +2 -2
  14. package/data/publish/runtime/evidence_patterns.json +162 -162
  15. package/data/publish/runtime/requirement_control_links.json +2271 -1708
  16. package/data/publish/runtime/v1/manual_threat_mitigation.jsonl +233 -233
  17. package/data/publish/runtime/v1/v1_manifest.json +6 -4
  18. package/data/reports/run_manifest.json +4 -4
  19. package/dist/index.js +107 -4
  20. package/dist/index.js.map +1 -1
  21. package/dist/serving/affordances.d.ts +1 -0
  22. package/dist/serving/affordances.js +12 -3
  23. package/dist/serving/affordances.js.map +1 -1
  24. package/dist/serving/selection.d.ts +56 -0
  25. package/dist/serving/selection.js +289 -0
  26. package/dist/serving/selection.js.map +1 -0
  27. package/dist/tools/consult-security-requirements.d.ts +7 -0
  28. package/dist/tools/consult-security-requirements.js +38 -0
  29. package/dist/tools/consult-security-requirements.js.map +1 -1
  30. package/dist/tools/generate-sbd-toe-skill.js +7 -2
  31. package/dist/tools/generate-sbd-toe-skill.js.map +1 -1
  32. package/dist/tools/get-threat-landscape.js +36 -13
  33. package/dist/tools/get-threat-landscape.js.map +1 -1
  34. package/dist/tools/map-review-scope.d.ts +6 -0
  35. package/dist/tools/map-review-scope.js +19 -0
  36. package/dist/tools/map-review-scope.js.map +1 -1
  37. package/dist/tools/ontology-loader.d.ts +8 -0
  38. package/dist/tools/ontology-loader.js +9 -0
  39. package/dist/tools/ontology-loader.js.map +1 -1
  40. package/dist/tools/prepare-codegen-context.d.ts +625 -5
  41. package/dist/tools/prepare-codegen-context.js +1185 -81
  42. package/dist/tools/prepare-codegen-context.js.map +1 -1
  43. package/dist/tools/select-requirements.d.ts +53 -0
  44. package/dist/tools/select-requirements.js +99 -0
  45. package/dist/tools/select-requirements.js.map +1 -0
  46. package/package.json +4 -3
  47. package/prompts/sbd-toe-grounded-codegen.md +10 -0
@@ -29,6 +29,32 @@
29
29
  import type { Affordance } from "../serving/protocol-envelope.js";
30
30
  export type CodegenMode = "codegen" | "review" | "test-plan";
31
31
  export type RiskLevel = "L1" | "L2" | "L3";
32
+ /**
33
+ * Response ENCODING level (v2 token diet, epic v2-token-diet slice s1).
34
+ *
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).
53
+ *
54
+ * The default flips to `standard` only at graduation to the next stable
55
+ * release (documented as breaking) — never on the beta line.
56
+ */
57
+ export type CodegenDetailLevel = "ultrathin" | "minimal" | "standard" | "full";
32
58
  export interface PrepareCodegenContextInput {
33
59
  task: string;
34
60
  risk_level?: RiskLevel;
@@ -40,12 +66,21 @@ export interface PrepareCodegenContextInput {
40
66
  changed_files?: string[];
41
67
  regulatory_frameworks?: string[];
42
68
  include_regulatory_overlay?: boolean;
69
+ detail?: CodegenDetailLevel;
70
+ /**
71
+ * v2 token diet, s2 — escape hatch for clients that cannot make a second
72
+ * call: when true, `detail: "standard" | "minimal"` keeps `g2_context.relations`
73
+ * inline (dieted: no per-item `source`) instead of `relations_ref`.
74
+ * Ignored at `detail: "full"` (full is always byte-identical to the classic
75
+ * payload, relations inline).
76
+ */
77
+ include_relations?: boolean;
43
78
  debug?: boolean;
44
79
  }
45
80
  export type PrepareCodegenStatus = "ready_for_codegen" | "needs_clarification" | "needs_decomposition" | "unsupported_scope";
46
81
  export interface ActivationTraceEntry {
47
82
  /** Triggered by: explicit concern, task term, changed file, framework hint, semantic alias, compound term, or intent keyword. */
48
- source: "explicit_concern" | "task_term" | "compound_term" | "alias_expansion" | "intent_keyword" | "changed_file" | "regulatory_framework" | "risk_level" | "scope_gate";
83
+ source: "explicit_concern" | "task_term" | "compound_term" | "alias_expansion" | "intent_keyword" | "changed_file" | "regulatory_framework" | "risk_level" | "exposure" | "data_sensitivity" | "context_chapter" | "scope_gate";
49
84
  /** What the activation produced (concern, slice_family, framework_id, decision). */
50
85
  produced: string;
51
86
  /** The literal token or input that triggered the activation. */
@@ -202,6 +237,22 @@ export interface CompletenessReport {
202
237
  evidence_patterns_capped: number;
203
238
  /** Cap value applied during this resolution. */
204
239
  evidence_pattern_cap: number;
240
+ /**
241
+ * MP1 selection summary (G-mp1a O2, 2026-08-31): the requirement set comes from
242
+ * the selection engine (baseline ∪ context-activated chapters, narrowed by the
243
+ * task's declared signals). Never-silent: what the narrowing excluded is counted
244
+ * here and fully listed by the executable ref. Additive key.
245
+ */
246
+ selection?: {
247
+ eligible: number;
248
+ selected: number;
249
+ narrowed_out_categories: number;
250
+ narrowed_out_requirements: number;
251
+ narrowed_out_ref: {
252
+ tool: "select_sbd_toe_requirements";
253
+ note: string;
254
+ };
255
+ };
205
256
  }
206
257
  export interface SecurityRationaleTemplate {
207
258
  task: string;
@@ -261,12 +312,581 @@ export interface PrepareCodegenContextResultBlocked {
261
312
  notes: string[];
262
313
  };
263
314
  }
264
- export type PrepareCodegenContextResult = PrepareCodegenContextResultReady | PrepareCodegenContextResultBlocked;
265
- 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"];
315
+ /** An item shape with the repeated per-item `source` field removed (the
316
+ * provenance is carried once, in `provenance_legend`). */
317
+ export type WithoutSource<T> = Omit<T, "source">;
318
+ /**
319
+ * Inverted citation encoding (replaces `citation_map` in `standard`/`minimal`).
320
+ * Grouped by source; `source_data` is an ORDERED run-length map
321
+ * `file → count`: the first N₁ citable ids come from the first file, the
322
+ * next N₂ from the second, and so on. This preserves the exact per-id
323
+ * `{source, source_data}` of the classic `citation_map` with zero repetition.
324
+ *
325
+ * s3: the ids themselves are NOT repeated when they already appear verbatim in
326
+ * a payload section — `ids_from` lists, aligned 1:1 with the `source_data`
327
+ * files, the payload path whose ids (in payload order) are the run for that
328
+ * file. `keys(section[slice])` paths iterate the slice groups in order, then
329
+ * the entity-id keys in order. The explicit `ids` array is kept ONLY as a
330
+ * lossless fallback when a file has no static payload-path mapping (expected
331
+ * never for the published bundle). Exactly one of `ids_from`/`ids` is present.
332
+ */
333
+ export interface CitationsGroup {
334
+ /** Ordered map: published file → number of consecutive citable ids. */
335
+ source_data: Record<string, number>;
336
+ /** Payload paths (aligned with `source_data` keys) whose ids, in payload
337
+ * order, are the ids for each file's run. */
338
+ ids_from?: string[];
339
+ /** Lossless fallback: explicit ids, ordered by the `source_data` runs. */
340
+ ids?: string[];
341
+ }
342
+ export type CitationsBySource = Partial<Record<CitationMapEntry["source"], CitationsGroup>>;
343
+ /**
344
+ * `manual_grounding` grouped by (rastreabilidade_role, manual_chapter,
345
+ * manual_file, manual_commit_sha) — the fields that repeat verbatim across
346
+ * entries. Total information is preserved: `v1_entity_ids` lists every entry
347
+ * of the group, and `v1_entity_names` carries ONLY the names that are not
348
+ * already recoverable from the `g2_context` entity lists in the same payload
349
+ * (normally empty — names come from the same rastreabilidade source).
350
+ */
351
+ export interface ManualGroundingGroup {
352
+ rastreabilidade_role: string;
353
+ manual_chapter?: string | null;
354
+ manual_file?: string | null;
355
+ manual_commit_sha?: string;
356
+ v1_entity_ids: string[];
357
+ /** Lossless guard: names NOT recoverable via g2_context entity `name`. */
358
+ v1_entity_names?: Record<string, string>;
359
+ }
360
+ export interface ManualGroundingGrouped {
361
+ /** Number of flat entries the groups encode (dedup audit: sum of group sizes). */
362
+ total_entries: number;
363
+ groups: ManualGroundingGroup[];
364
+ /** Lossless guard: entries without a v1_entity_id (expected empty). */
365
+ ungrouped?: Array<WithoutSource<ManualGroundingEntry>>;
366
+ }
367
+ /**
368
+ * v2 token diet, s3b (revised ADENDA 2026-07-05) — minimal-form grounding
369
+ * group: the SAME group as {@link ManualGroundingGroup} (1:1, same order) with
370
+ * the per-group `v1_entity_ids` list replaced by its exact count (`entries`).
371
+ * The grounding id SET is NOT lost: every grounding v1_entity_id is an
372
+ * activated entity id already present verbatim in this payload's
373
+ * `g2_context` entity maps (the grounding is resolved FROM those ids) — only
374
+ * the id→(chapter,file) traceability assignment moves behind the executable
375
+ * `groups_ref` (same input, detail="standard"). Never silent: `entries`
376
+ * counts sum to `total_entries`.
377
+ */
378
+ export interface ManualGroundingMinimalGroup {
379
+ rastreabilidade_role: string;
380
+ manual_chapter?: string | null;
381
+ manual_file?: string | null;
382
+ /** Present ONLY when the sha could not be hoisted to the top level
383
+ * (mixed/absent shas across groups — never expected for the published
384
+ * bundle; lossless guard). */
385
+ manual_commit_sha?: string;
386
+ /** Exact number of v1_entity_ids the detail="standard" group carries. */
387
+ entries: number;
388
+ /** Lossless guard: names NOT recoverable via g2_context entity `name`
389
+ * (kept verbatim from the standard group; expected never). */
390
+ v1_entity_names?: Record<string, string>;
391
+ }
392
+ /** Executable reference to the full per-group grounding ids (s3b). */
393
+ export interface GroundingGroupsRef {
394
+ tool: "prepare_sbd_toe_codegen_context";
395
+ /** Merge over this call's input_echo: same input, detail="standard". */
396
+ with: {
397
+ detail: "standard";
398
+ };
399
+ note: string;
400
+ }
401
+ /**
402
+ * `manual_grounding` at `detail: "minimal"` (s3b revised): aggregated
403
+ * provenance — total count, the manual_commit_sha shared by every group
404
+ * (hoisted), and the (role, chapter, file) group list with per-group entry
405
+ * COUNTS instead of per-group id lists — plus the executable `groups_ref`.
406
+ * The citable id set is untouched (invariant 3): grounding ids never feed
407
+ * `citations`/`ids_from`, and the id set itself stays reconstructible from
408
+ * this same payload's g2_context entity maps without any extra call.
409
+ */
410
+ export interface ManualGroundingMinimal {
411
+ /** Number of flat detail="full" entries the groups encode (Σ entries). */
412
+ total_entries: number;
413
+ /** Hoisted provenance: present iff EVERY group carries this same sha
414
+ * (expected always for the published bundle); otherwise each group keeps
415
+ * its own `manual_commit_sha` inline (lossless guard). */
416
+ manual_commit_sha?: string;
417
+ groups: ManualGroundingMinimalGroup[];
418
+ /** How to obtain the full per-group v1_entity_ids (detail="standard"). */
419
+ groups_ref: GroundingGroupsRef;
420
+ /** Lossless guard: entries without a v1_entity_id (expected empty). */
421
+ ungrouped?: Array<WithoutSource<ManualGroundingEntry>>;
422
+ }
423
+ /**
424
+ * `manual_grounding` at `detail: "ultrathin"` (s3c): aggregate provenance ONLY
425
+ * — `{total_entries, manual_commit_sha, groups_ref}` — derived from the s3b
426
+ * minimal form with the (role, chapter, file) group list elided too. Never
427
+ * silent: `total_entries` is the exact flat detail="full" entry count and
428
+ * `groups_ref` is the executable reference (same input, detail="standard")
429
+ * that returns the full 1:1 grouping with per-group v1_entity_ids. Lossless
430
+ * guards (both expected never for the published bundle): if the sha could not
431
+ * be hoisted OR any group carries non-recoverable `v1_entity_names`, the s3b
432
+ * minimal `groups` list survives inline; `ungrouped` entries survive verbatim.
433
+ * Invariant-3 note (same as minimal): grounding ids never feed
434
+ * `citations`/`ids_from`, and the grounding id SET stays reconstructible from
435
+ * this same payload's g2_context entity maps without any extra call.
436
+ */
437
+ export interface ManualGroundingUltrathin {
438
+ /** Number of flat detail="full" entries the elided groups encode. */
439
+ total_entries: number;
440
+ /** Hoisted provenance (expected always: one published manual commit). */
441
+ manual_commit_sha?: string;
442
+ /** Lossless guard: present ONLY when hoisting failed or a group carried
443
+ * v1_entity_names (never expected) — the s3b minimal groups, verbatim. */
444
+ groups?: ManualGroundingMinimalGroup[];
445
+ /** How to obtain the full per-group v1_entity_ids (detail="standard"). */
446
+ groups_ref: GroundingGroupsRef;
447
+ /** Lossless guard: entries without a v1_entity_id (expected empty). */
448
+ ungrouped?: Array<WithoutSource<ManualGroundingEntry>>;
449
+ }
450
+ /**
451
+ * v2 token diet, s3 — dieted requirement projection. `category` is elided when
452
+ * (and only when) it equals the category segment of the `requirement_id` —
453
+ * the segment immediately before the number (`AUT-003` → `AUT`,
454
+ * `REQ-AGN-001` → `AGN`; consumer contract v1.10 §1.18, single source
455
+ * `src/serving/requirement-id.ts`). True for all 255 published requirements;
456
+ * the field survives verbatim on any future mismatch — lossless guard. `description` is the PUBLISHED bundle
457
+ * field (data/publish/runtime/requirements.json), verbatim, never paraphrased
458
+ * — the "how" the full projection historically dropped.
459
+ */
460
+ export interface DietedRequirement {
461
+ requirement_id: string;
462
+ name: string;
463
+ type?: string;
464
+ /** Present only on the (never expected) category ≠ id-category-segment mismatch. */
465
+ category?: string;
466
+ /** Verbatim `description` from the published bundle. */
467
+ description?: string;
468
+ }
469
+ /**
470
+ * v2 token diet, s3 — dieted control projection: classic fields minus `source`
471
+ * plus, for `confidence: "direct"` controls only, the verbatim published
472
+ * `description` (data/publish/runtime/controls.json).
473
+ */
474
+ export type DietedControl = WithoutSource<ActivatedScope["controls"][number]> & {
475
+ description?: string;
476
+ };
477
+ /**
478
+ * v2 token diet, s3c — executable reference left in `activated_scope` at
479
+ * `detail: "ultrathin"`, where the verbatim published `description` fields
480
+ * (the "how", s3) are elided from requirements and direct controls. Never
481
+ * silent: the lists themselves stay COMPLETE (same ids, same order, name
482
+ * always present — nothing id-only); only the description field moves behind
483
+ * this reference. detail="minimal" is the cheapest level that returns the
484
+ * same complete scope WITH the descriptions (verbatim, never paraphrased).
485
+ */
486
+ export interface ActivatedScopeDescriptionsRef {
487
+ tool: "prepare_sbd_toe_codegen_context";
488
+ /** Merge over this call's input_echo: same input, detail="minimal". */
489
+ with: {
490
+ detail: "minimal";
491
+ };
492
+ note: string;
493
+ }
494
+ export interface DietedActivatedScope {
495
+ requirements: DietedRequirement[];
496
+ controls: DietedControl[];
497
+ slices: Array<WithoutSource<ActivatedScope["slices"][number]>>;
498
+ regulatory_obligations: Array<WithoutSource<ActivatedScope["regulatory_obligations"][number]>>;
499
+ /** Present ONLY at detail="ultrathin" (s3c): how to obtain the verbatim
500
+ * published descriptions elided from requirements + direct controls. */
501
+ descriptions_ref?: ActivatedScopeDescriptionsRef;
502
+ }
503
+ /**
504
+ * v2 token diet, s2 — Relations on-demand. In `standard`/`minimal` the inline
505
+ * `g2_context.relations` array (~4.3K tokens) is replaced by a REFERENCE to
506
+ * executable calls of the `trace_sbd_toe_graph` tool whose union returns a
507
+ * superset of the elided relations. Anchors are activated slice_ids/entity_ids
508
+ * from THIS payload — domain ids, never internal IRIs (EPIC invariant 6).
509
+ *
510
+ * Relation kind → curated lens mapping (see buildRelationsRef):
511
+ * - (objective → mechanism/practice) edges, where the objective has a
512
+ * belongsToSlice edge to an activated slice S:
513
+ * `slice_implementation(anchor=S)` — each row (slice, objective, kind,
514
+ * target) carries BOTH the objective→target edge (kind selects the
515
+ * predicate) and the objective's belongsToSlice edge.
516
+ * - (objective, belongsToSlice, S) for objectives with ≥1 mechanism/practice
517
+ * edge: same `slice_implementation(anchor=S)` rows.
518
+ * - (objective → target) edges whose objective is activated but has NO
519
+ * belongsToSlice edge in the published graph (data gap):
520
+ * `objective_realization(anchor=objective)`.
521
+ * - (objective → target) edges where only the TARGET is activated
522
+ * (cross-slice): `mechanism_provenance(anchor=target)` — the predicate is
523
+ * recovered from the target's entity_type in this same payload.
524
+ * - (entity, belongsToSlice, slice) for Mechanism/Practice/Artifact subjects
525
+ * (and objectives without mechanism/practice edges): NO curated lens
526
+ * returns these edges, and they are 100% redundant with the payload — every
527
+ * `g2_context` entity already carries `slice_id`. Counted as
528
+ * `coverage.implicit_in_entities` (never silently dropped).
529
+ * - Anything not covered above stays INLINE in `residual_relations`
530
+ * (expected empty; never-silent guard).
531
+ */
532
+ export interface RelationsRefLensCall {
533
+ lens: "slice_implementation" | "objective_realization" | "mechanism_provenance";
534
+ /** Activated slice_id or entity_id from this payload (id, never an IRI). */
535
+ anchor: string;
536
+ }
537
+ export interface RelationsRef {
538
+ tool: "trace_sbd_toe_graph";
539
+ /** Executable calls whose union covers the lens-recoverable relations. */
540
+ lenses: RelationsRefLensCall[];
541
+ /** Exact number of relations that would go inline at detail=full (audit). */
542
+ total_relations: number;
543
+ /** Never-silent split of total_relations by recovery path. */
544
+ coverage: {
545
+ /** Recoverable by executing the `lenses` calls above. */
546
+ via_lenses: number;
547
+ /** belongsToSlice edges equal to the `slice_id` field of a g2_context entity. */
548
+ implicit_in_entities: number;
549
+ /** Relations kept inline in `residual_relations` (expected 0). */
550
+ residual_inline: number;
551
+ };
552
+ /** Only present when a relation is neither lens-recoverable nor implicit. */
553
+ residual_relations?: Array<WithoutSource<G2ContextRelation>>;
554
+ note: string;
555
+ }
556
+ /**
557
+ * v2 token diet, s3 — slice-grouped entity encoding for `standard`/`minimal`:
558
+ * `{ slice_id: { entity_id: name | null } }`. Lossless re-encoding of the
559
+ * classic entity list: `entity_type` is the list the map lives in,
560
+ * `slice_id` is the group key, `slice_family` is
561
+ * `activated_scope.slices[].objective_family` for that slice_id, and a `null`
562
+ * name means the full projection omits `name` (unnamed in rastreabilidade).
563
+ * Group/key order preserves the classic list order (insertion order).
564
+ */
565
+ export type SliceGroupedEntityNames = Record<string, Record<string, string | null>>;
566
+ /**
567
+ * v2 token diet, s3 — dieted evidence pattern: classic projection minus
568
+ * `source` (s1 legend) and minus the tool-computed `relevance_score` (the
569
+ * DETERMINISTIC list order — relevance_score desc, then id asc — already
570
+ * carries the ranking; documented in the codegen-instructions resource).
571
+ */
572
+ export type DietedEvidencePattern = Omit<G2ContextEvidencePattern, "source" | "relevance_score">;
573
+ export interface DietedG2Context {
574
+ control_objectives: SliceGroupedEntityNames;
575
+ mechanisms: SliceGroupedEntityNames;
576
+ practices: SliceGroupedEntityNames;
577
+ artifacts: SliceGroupedEntityNames;
578
+ /** Inline only with `include_relations: true` (s2); otherwise see relations_ref. */
579
+ relations?: Array<WithoutSource<G2ContextRelation>>;
580
+ /** Present when relations are elided (s2 default at standard/minimal). */
581
+ relations_ref?: RelationsRef;
582
+ /** s3: deterministic top-{@link STANDARD_EVIDENCE_PATTERN_CAP} prefix of the
583
+ * classic list (see completeness_report for the never-silent counts). */
584
+ evidence_patterns: DietedEvidencePattern[];
585
+ }
586
+ export interface DietedRegulatoryOverlayContext {
587
+ frameworks: Array<WithoutSource<RegulatoryOverlayContext["frameworks"][number]>>;
588
+ obligations: Array<WithoutSource<RegulatoryOverlayContext["obligations"][number]>>;
589
+ mappings: Array<WithoutSource<RegulatoryOverlayContext["mappings"][number]>>;
590
+ playbooks: Array<WithoutSource<RegulatoryOverlayContext["playbooks"][number]>>;
591
+ }
592
+ /**
593
+ * Inline legend for `standard`/`minimal` (s3: slim pointer — the full legend,
594
+ * including the section→source table and every derivation rule of the dieted
595
+ * encoding, lives in the `sbd://toe/codegen-instructions/{mode}` resource,
596
+ * section `detail_encoding`).
597
+ */
598
+ declare const PROVENANCE_LEGEND: {
599
+ readonly note: string;
600
+ };
601
+ export type ProvenanceLegend = typeof PROVENANCE_LEGEND;
602
+ /**
603
+ * v2 token diet, s4 — cheap turns, not fewer turns: short note (≈50 tokens)
604
+ * appended to every `standard`/`minimal` ready payload. The production
605
+ * write-test-edit loop is legitimate; what must not repeat is the cost of
606
+ * re-requesting THIS payload — an identical call returns a byte-identical
607
+ * result (deterministic, tested), so the context already in the session is
608
+ * the source for the loop. Follow-ups that genuinely need more go through
609
+ * `detail: "minimal"` or a targeted `consult_security_requirements` call —
610
+ * never a repeat of the full payload. `full` carries NO hint (byte-identical
611
+ * to the classic payload, EPIC invariant 1).
612
+ */
613
+ export declare const REPEAT_CALL_HINT: string;
614
+ /**
615
+ * v2 token diet, s3 — reference that replaces the inline
616
+ * `llm_codegen_instructions` + `security_rationale_template` boilerplate at
617
+ * `detail: "standard" | "minimal"` (both stay inline at `full`). The MCP
618
+ * resource carries, per mode, the exact instruction slots and the template
619
+ * skeleton; `active_conditions` lists which conditional slots apply to THIS
620
+ * call, so the inline full content is reconstructible byte-identically.
621
+ */
622
+ export interface CodegenInstructionsRef {
623
+ resource: string;
624
+ /** Conditional instruction slots active for this call (see the resource's
625
+ * `llm_codegen_instructions.slots[].when`). */
626
+ active_conditions: InstructionCondition[];
627
+ note: string;
628
+ }
629
+ /**
630
+ * v2 token diet, s3 — never-silent counter left in place of the elided
631
+ * `activation_trace` at `detail: "standard" | "minimal"` (the full trace is
632
+ * included when `debug: true`, and always at `detail: "full"`).
633
+ */
634
+ export interface ActivationTraceRef {
635
+ entries: number;
636
+ note: string;
637
+ }
638
+ /**
639
+ * v2 token diet, s3 — executable reference for retrieving the evidence
640
+ * patterns omitted by the standard cap (boundList discipline: the counts live
641
+ * in the same completeness_report; this says HOW to get the rest).
642
+ */
643
+ export interface EvidencePatternsRest {
644
+ tool: "prepare_sbd_toe_codegen_context";
645
+ /** Merge over this call's input_echo: same input, detail="full" (the
646
+ * classic top-25) at standard/minimal; detail="minimal" (the CHEAPEST level
647
+ * that returns patterns inline) at ultrathin (s3c). */
648
+ with: {
649
+ detail: "full";
650
+ } | {
651
+ detail: "minimal";
652
+ };
653
+ note: string;
654
+ }
655
+ /** Completeness report at `standard`/`minimal`: classic counters (with the
656
+ * s3 cap values) plus, when patterns were cut, the executable rest-reference. */
657
+ export type DietedCompletenessReport = CompletenessReport & {
658
+ evidence_patterns_rest?: EvidencePatternsRest;
659
+ };
660
+ /**
661
+ * v2 token diet, s3c — executable reference for the completeness diagnostics
662
+ * elided at `detail: "ultrathin"` (never silent: exact counts stay inline;
663
+ * detail="minimal" is the cheapest level whose completeness_report carries
664
+ * the full text arrays inline).
665
+ */
666
+ export interface V1DiagnosticsRef {
667
+ tool: "prepare_sbd_toe_codegen_context";
668
+ /** Merge over this call's input_echo: same input, detail="minimal". */
669
+ with: {
670
+ detail: "minimal";
671
+ };
672
+ note: string;
673
+ }
674
+ /**
675
+ * Completeness report at `detail: "ultrathin"` (s3c) — trimmed to the
676
+ * essentials that support the never-silent discipline. KEPT verbatim: every
677
+ * expected/returned count and m_recall (recall audit), named/unnamed entity
678
+ * counts, and the evidence counts (total / returned=0 / capped=total / cap=0)
679
+ * with the executable `evidence_patterns_rest`. CUT (serialization only, each
680
+ * replaced by its exact count + the executable `v1_diagnostics_ref` when any
681
+ * count > 0): the `v1_consistency_mismatches` and `v1_manifest_warnings` TEXT
682
+ * arrays (the verbose per-slice contract-warning strings, ~100 tokens/call).
683
+ */
684
+ export type UltrathinCompletenessReport = Omit<DietedCompletenessReport, "v1_consistency_mismatches" | "v1_manifest_warnings"> & {
685
+ /** Exact length of the elided v1_consistency_mismatches array (expected 0). */
686
+ v1_consistency_mismatches_count: number;
687
+ /** Exact length of the elided v1_manifest_warnings array. */
688
+ v1_manifest_warnings_count: number;
689
+ /** Present iff either count above is > 0: how to obtain the full texts. */
690
+ v1_diagnostics_ref?: V1DiagnosticsRef;
691
+ };
692
+ /**
693
+ * `ready_for_codegen` result at `detail: "standard" | "minimal"`. Same citable
694
+ * ID set as the full result (invariant 3) — the encoding is deduplicated (s1),
695
+ * relations are served on-demand (s2) and, since s3:
696
+ * - `g2_context.evidence_patterns` is capped 25→10 (deterministic prefix;
697
+ * never-silent counts + rest-reference in `completeness_report`);
698
+ * - `llm_codegen_instructions` + `security_rationale_template` move to the
699
+ * `sbd://toe/codegen-instructions/{mode}` MCP resource
700
+ * (`codegen_instructions_ref` carries the URI + active conditions);
701
+ * - `activation_trace` is included only with `debug: true`
702
+ * (`activation_trace_ref` keeps the never-silent count otherwise);
703
+ * - requirements and `direct` controls carry the verbatim published
704
+ * `description` (the "how"), and derivable fields (`category`,
705
+ * `entity_type`, `slice_family`, `relevance_score`, repeated citation ids)
706
+ * are elided per the resource's `detail_encoding` legend.
707
+ *
708
+ * s3b (revised per the 2026-07-05 operator ADENDA — NO top-N/subsetting):
709
+ * `minimal` diverges from `standard` ONLY in serialization of traceability,
710
+ * never in execution context. The activated scope (requirements + controls
711
+ * with descriptions, slices, obligations, g2 entities, citations,
712
+ * relations_ref) is byte-identical to `standard`; `minimal` additionally
713
+ * - caps `g2_context.evidence_patterns` 10→5 (same s3 mechanism: prefix,
714
+ * counts, rest-ref);
715
+ * - serves `manual_grounding` in the minimal form ({@link
716
+ * ManualGroundingMinimal}: counts + hoisted sha + executable groups_ref).
717
+ *
718
+ * s3c (`detail: "ultrathin"`, operator ADENDA 2026-07-05): one level below
719
+ * `minimal`, same rules (activated set COMPLETE, no top-k, nothing id-only,
720
+ * never silent). Diverges from `minimal` ONLY in:
721
+ * - requirements/controls WITHOUT the published `description` (fields kept:
722
+ * requirement {requirement_id, name, type}; control {control_id, name,
723
+ * domain, control_type, confidence}; the `category` lossless guard is
724
+ * unchanged) + executable `activated_scope.descriptions_ref`;
725
+ * - `g2_context.evidence_patterns` cap 5→0 (counts + rest-ref to the
726
+ * cheapest level that returns them: detail="minimal");
727
+ * - `manual_grounding` in the ultrathin form ({@link ManualGroundingUltrathin}:
728
+ * total + hoisted sha + executable groups_ref, group list elided);
729
+ * - `completeness_report` diagnostics trimmed ({@link
730
+ * UltrathinCompletenessReport}: text arrays → exact counts + executable ref).
731
+ * Everything else — g2 entity maps (id→name|null), relations_ref, citations,
732
+ * codegen_instructions_ref, repeat_call_hint, provenance, next — is
733
+ * byte-identical to the other dieted levels.
734
+ */
735
+ export interface PrepareCodegenContextResultReadyDieted {
736
+ status: "ready_for_codegen";
737
+ /** RF-H advisory band — adjacent tools the caller likely needs next. */
738
+ next?: Affordance[];
739
+ mode: CodegenMode;
740
+ input_echo: PrepareCodegenContextResultReady["input_echo"];
741
+ /** Present only with `debug: true` (s3); see activation_trace_ref otherwise. */
742
+ activation_trace?: ActivationTraceEntry[];
743
+ /** Present when activation_trace is elided (never-silent counter). */
744
+ activation_trace_ref?: ActivationTraceRef;
745
+ provenance_legend: ProvenanceLegend;
746
+ activated_scope: DietedActivatedScope;
747
+ g2_context: DietedG2Context;
748
+ /** Grouped (standard), minimal (s3b) or ultrathin form (s3c). */
749
+ manual_grounding: ManualGroundingGrouped | ManualGroundingMinimal | ManualGroundingUltrathin;
750
+ regulatory_overlay: DietedRegulatoryOverlayContext;
751
+ citations: CitationsBySource;
752
+ completeness_report: DietedCompletenessReport | UltrathinCompletenessReport;
753
+ codegen_instructions_ref: CodegenInstructionsRef;
754
+ /** s4 — reuse note ({@link REPEAT_CALL_HINT}): identical re-call is
755
+ * deterministic; the context already received is the loop's source. */
756
+ repeat_call_hint: string;
757
+ provenance: PrepareCodegenContextResultReady["provenance"];
758
+ debug?: PrepareCodegenContextResultReady["debug"];
759
+ }
760
+ export type PrepareCodegenContextResult = PrepareCodegenContextResultReady | PrepareCodegenContextResultReadyDieted | PrepareCodegenContextResultBlocked;
761
+ 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", "agents"];
266
762
  export type Concern = (typeof VALID_CONCERNS)[number];
763
+ export interface NormalizedInput {
764
+ task: string;
765
+ taskTrimmed: string;
766
+ taskLower: string;
767
+ tokenCount: number;
768
+ mode: CodegenMode;
769
+ risk_level?: RiskLevel;
770
+ stack?: string;
771
+ exposure?: PrepareCodegenContextInput["exposure"];
772
+ data_sensitivity?: PrepareCodegenContextInput["data_sensitivity"];
773
+ concerns: Concern[];
774
+ unknownConcerns: string[];
775
+ changed_files: string[];
776
+ regulatory_frameworks: string[];
777
+ include_regulatory_overlay: boolean;
778
+ debug: boolean;
779
+ }
780
+ export declare function normalizeInput(raw: unknown): NormalizedInput;
781
+ export interface ActivationResult {
782
+ concerns: Concern[];
783
+ sliceFamilies: string[];
784
+ /** P3 do ciclo MP1 (2026-08-31): famílias contadas para o gate de decomposição —
785
+ * UM SINAL = UMA SUPERFÍCIE. Só o concern PRIMÁRIO de cada sinal (posição 0 do
786
+ * mapeamento do termo/frase; explícitos/intents/ficheiros contam por si) contribui
787
+ * a sua família; concerns de suporte (posições secundárias, ex.: mtls→secrets,
788
+ * message queue→logging) activam categorias mas não são superfícies novas.
789
+ * `sliceFamilies` (grounding) fica intocado. */
790
+ decompositionFamilies: string[];
791
+ trace: ActivationTraceEntry[];
792
+ rejected: ActivationTraceEntry[];
793
+ notes: string[];
794
+ /** Per-concern aggregated score (max over contributing trace entries). */
795
+ concernScores: Map<Concern, number>;
796
+ /** Per-slice-family aggregated score. */
797
+ sliceFamilyScores: Map<string, number>;
798
+ }
799
+ export declare function activate(input: NormalizedInput): ActivationResult;
800
+ export declare function categoriesForConcerns(concerns: Concern[]): Set<string>;
801
+ /**
802
+ * Conditions under which a conditional instruction slot is included inline at
803
+ * `detail: "full"`. The dieted `codegen_instructions_ref.active_conditions`
804
+ * lists the conditions active for a given call, so a client reading the
805
+ * resource reconstructs the inline instruction list byte-identically.
806
+ */
807
+ export type InstructionCondition = "always" | "regulatory_overlay" | "risk_level:L1" | "risk_level:L2" | "risk_level:L3" | "citation_map_empty";
808
+ export interface InstructionSlot {
809
+ when: InstructionCondition;
810
+ text: string;
811
+ }
812
+ /**
813
+ * Ordered instruction slots for a mode. The emission order of
814
+ * {@link buildLlmInstructions} is EXACTLY this list filtered by active
815
+ * conditions — the classic (pre-s3) output is byte-identical by construction.
816
+ */
817
+ export declare function instructionSlotsForMode(mode: CodegenMode): InstructionSlot[];
818
+ export declare const CODEGEN_INSTRUCTION_MODES: readonly CodegenMode[];
819
+ export declare const CODEGEN_INSTRUCTIONS_RESOURCE_URI_PREFIX = "sbd://toe/codegen-instructions/";
820
+ export declare function codegenInstructionsResourceUri(mode: CodegenMode): string;
821
+ /**
822
+ * Full legend of the dieted (`standard`/`minimal`) encoding, published in the
823
+ * codegen-instructions resource. Every rule here is a lossless, deterministic
824
+ * derivation over the SAME payload (or an executable reference) — nothing is
825
+ * silently dropped (EPIC invariant 2) and no data changes, only serialization
826
+ * (EPIC invariant 4).
827
+ */
828
+ declare const DETAIL_ENCODING_LEGEND: {
829
+ readonly note: string;
830
+ readonly sources: {
831
+ readonly note: string;
832
+ readonly map: {
833
+ readonly "activated_scope.requirements": "runtime_v0";
834
+ readonly "activated_scope.controls": "runtime_v0";
835
+ readonly "activated_scope.slices": "runtime_v1";
836
+ readonly "activated_scope.regulatory_obligations": "overlay";
837
+ readonly "g2_context.control_objectives": "runtime_v1";
838
+ readonly "g2_context.mechanisms": "runtime_v1";
839
+ readonly "g2_context.practices": "runtime_v1";
840
+ readonly "g2_context.artifacts": "runtime_v1";
841
+ readonly "g2_context.relations": "runtime_v1";
842
+ readonly "g2_context.evidence_patterns": "runtime_v0";
843
+ readonly "manual_grounding.groups": "runtime_v1";
844
+ readonly "regulatory_overlay.frameworks": "overlay";
845
+ readonly "regulatory_overlay.obligations": "overlay";
846
+ readonly "regulatory_overlay.mappings": "overlay";
847
+ readonly "regulatory_overlay.playbooks": "overlay";
848
+ };
849
+ };
850
+ readonly citations: string;
851
+ readonly activated_scope_requirements: string;
852
+ readonly activated_scope_controls: string;
853
+ readonly g2_entities: string;
854
+ readonly evidence_patterns: string;
855
+ readonly manual_grounding_minimal: string;
856
+ readonly activation_trace: string;
857
+ readonly relations_ref: string;
858
+ readonly ultrathin: string;
859
+ };
860
+ export interface CodegenInstructionsResourceContent {
861
+ resource: string;
862
+ mode: CodegenMode;
863
+ note: string;
864
+ llm_codegen_instructions: {
865
+ assembly: string;
866
+ slots: InstructionSlot[];
867
+ };
868
+ security_rationale_template: {
869
+ assembly: string;
870
+ template: {
871
+ task: null;
872
+ } & Omit<SecurityRationaleTemplate, "task">;
873
+ };
874
+ detail_encoding: typeof DETAIL_ENCODING_LEGEND;
875
+ }
876
+ /**
877
+ * Content of the `sbd://toe/codegen-instructions/{mode}` MCP resource — the
878
+ * static-per-mode boilerplate that detail=standard/minimal payloads reference
879
+ * instead of carrying inline. Reconstructing the inline `full` content from
880
+ * this resource is byte-exact (tested):
881
+ * - llm_codegen_instructions = slots filtered by `when` ("always" +
882
+ * codegen_instructions_ref.active_conditions), in order;
883
+ * - security_rationale_template = template with `task` set to the trimmed
884
+ * task string (input_echo.task.trim()).
885
+ */
886
+ export declare function buildCodegenInstructionsResourceContent(mode: CodegenMode): CodegenInstructionsResourceContent;
267
887
  export declare function handlePrepareCodegenContext(raw: PrepareCodegenContextInput): PrepareCodegenContextResult;
268
888
  export declare const __wp5Lexicon: {
269
- 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"];
270
- CONCERN_TO_SLICE_FAMILY: Readonly<Record<"release" | "auth" | "logging" | "validation" | "api" | "config" | "integrity" | "distribution" | "ide" | "requirements" | "architecture" | "iac" | "encryption" | "monitoring" | "build" | "secrets" | "supply_chain" | "testing" | "threat_modeling" | "deployment" | "integration", string | null>>;
889
+ 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", "agents"];
890
+ CONCERN_TO_SLICE_FAMILY: Readonly<Record<"release" | "auth" | "logging" | "validation" | "api" | "config" | "integrity" | "distribution" | "ide" | "requirements" | "architecture" | "iac" | "encryption" | "agents" | "monitoring" | "build" | "secrets" | "supply_chain" | "testing" | "threat_modeling" | "deployment" | "integration", string | null>>;
271
891
  };
272
892
  export {};