@clear-capabilities/agentic-security-scanner 0.144.0 → 0.147.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 (209) hide show
  1. package/CHANGELOG.md +390 -0
  2. package/bin/agentic-security.js +3813 -83
  3. package/dist/1122.index.js +702 -0
  4. package/dist/{301.index.js → 1301.index.js} +2 -2
  5. package/dist/1379.index.js +591 -0
  6. package/dist/{444.index.js → 1444.index.js} +13 -4
  7. package/dist/{660.index.js → 1660.index.js} +2 -2
  8. package/dist/{700.index.js → 1700.index.js} +2 -2
  9. package/dist/{905.index.js → 1905.index.js} +3 -3
  10. package/dist/{920.index.js → 1920.index.js} +3 -3
  11. package/dist/{238.index.js → 2238.index.js} +3 -3
  12. package/dist/2271.index.js +165 -0
  13. package/dist/{985.index.js → 2376.index.js} +1260 -340
  14. package/dist/2432.index.js +793 -0
  15. package/dist/2659.index.js +93 -0
  16. package/dist/{826.index.js → 2826.index.js} +2 -2
  17. package/dist/{830.index.js → 2830.index.js} +2 -2
  18. package/dist/2923.index.js +298 -0
  19. package/dist/{1.index.js → 3001.index.js} +5 -5
  20. package/dist/{117.index.js → 3117.index.js} +3 -3
  21. package/dist/3180.index.js +307 -0
  22. package/dist/3276.index.js +117 -0
  23. package/dist/{415.index.js → 3415.index.js} +2 -2
  24. package/dist/{499.index.js → 3499.index.js} +2 -2
  25. package/dist/3518.index.js +450 -0
  26. package/dist/{526.index.js → 3526.index.js} +14 -6
  27. package/dist/{736.index.js → 3736.index.js} +4 -4
  28. package/dist/{839.index.js → 3839.index.js} +4 -4
  29. package/dist/{113.index.js → 4113.index.js} +14 -6
  30. package/dist/{265.index.js → 4265.index.js} +2 -2
  31. package/dist/{384.index.js → 4384.index.js} +3 -3
  32. package/dist/4547.index.js +268 -0
  33. package/dist/4863.index.js +422 -0
  34. package/dist/{970.index.js → 4970.index.js} +67 -3
  35. package/dist/5051.index.js +770 -0
  36. package/dist/{144.index.js → 5144.index.js} +5 -5
  37. package/dist/{333.index.js → 5333.index.js} +3 -3
  38. package/dist/5343.index.js +185 -0
  39. package/dist/5350.index.js +866 -0
  40. package/dist/5561.index.js +436 -0
  41. package/dist/{637.index.js → 5637.index.js} +29 -7
  42. package/dist/{449.index.js → 5830.index.js} +78 -14
  43. package/dist/6626.index.js +532 -0
  44. package/dist/6662.index.js +297 -0
  45. package/dist/{675.index.js → 6675.index.js} +5 -5
  46. package/dist/{730.index.js → 6730.index.js} +6 -6
  47. package/dist/6829.index.js +225 -0
  48. package/dist/6944.index.js +130 -0
  49. package/dist/{178.index.js → 7178.index.js} +26 -8
  50. package/dist/{227.index.js → 7227.index.js} +2 -2
  51. package/dist/7310.index.js +520 -0
  52. package/dist/{552.index.js → 7552.index.js} +4 -4
  53. package/dist/7709.index.js +78 -0
  54. package/dist/8218.index.js +160 -0
  55. package/dist/{476.index.js → 8476.index.js} +4 -4
  56. package/dist/{513.index.js → 8513.index.js} +5 -5
  57. package/dist/{520.index.js → 8520.index.js} +2 -2
  58. package/dist/{718.index.js → 8718.index.js} +2 -2
  59. package/dist/{752.index.js → 8752.index.js} +2 -2
  60. package/dist/8846.index.js +100 -0
  61. package/dist/{435.index.js → 9091.index.js} +580 -187
  62. package/dist/{207.index.js → 9207.index.js} +2 -2
  63. package/dist/{220.index.js → 9220.index.js} +2 -2
  64. package/dist/9390.index.js +163 -0
  65. package/dist/{503.index.js → 9503.index.js} +2 -2
  66. package/dist/{801.index.js → 9801.index.js} +2 -2
  67. package/dist/{824.index.js → 9824.index.js} +2 -2
  68. package/dist/agentic-security.mjs +16 -16
  69. package/dist/agentic-security.mjs.sha256 +1 -1
  70. package/dist/compliance-frameworks/hipaa-security-rule.json +3 -2
  71. package/package.json +23 -10
  72. package/src/compare.js +6 -1
  73. package/src/dataflow/CLAUDE.md +2 -2
  74. package/src/dataflow/catalog.js +42 -0
  75. package/src/dataflow/orm-write-catalog.js +175 -0
  76. package/src/engine.js +580 -30
  77. package/src/fix/apply-fix-service.js +1 -0
  78. package/src/history-scan.js +22 -5
  79. package/src/ir/CLAUDE.md +2 -1
  80. package/src/ir/chrome-probe.mjs +150 -0
  81. package/src/ir/parser-js.js +94 -7
  82. package/src/lineage/CLAUDE.md +1203 -0
  83. package/src/lineage/DESIGN_DESTINATION_RESOLVER.md +156 -0
  84. package/src/lineage/DESIGN_GRAPH_BUILDER.md +938 -0
  85. package/src/lineage/DESIGN_HANDLING_ANALYZER.md +355 -0
  86. package/src/lineage/DESIGN_INTRAPROCEDURAL.md +628 -0
  87. package/src/lineage/DESIGN_PATH_PROVENANCE.md +3451 -0
  88. package/src/lineage/DESIGN_QUEUE_DETAIL.md +120 -0
  89. package/src/lineage/DESIGN_REGISTRIES.md +880 -0
  90. package/src/lineage/DESIGN_STORE_DETAIL.md +143 -0
  91. package/src/lineage/DESIGN_TRANSIT_PROTECTION.md +245 -0
  92. package/src/lineage/classification.js +56 -0
  93. package/src/lineage/coverage.js +658 -0
  94. package/src/lineage/cross-repo-link.js +107 -0
  95. package/src/lineage/dataflow-graph.schema.json +184 -0
  96. package/src/lineage/decision-story.js +206 -0
  97. package/src/lineage/drift-policy.js +279 -0
  98. package/src/lineage/driver.js +135 -0
  99. package/src/lineage/engine.js +992 -0
  100. package/src/lineage/export-briefing.js +628 -0
  101. package/src/lineage/export-csv.js +62 -0
  102. package/src/lineage/export-json.js +238 -0
  103. package/src/lineage/export-privacy.js +258 -0
  104. package/src/lineage/federation-loader.js +111 -0
  105. package/src/lineage/field-identity.js +78 -0
  106. package/src/lineage/fixtures/build-flagship-fixture.mjs +272 -0
  107. package/src/lineage/fixtures/flagship-graph.json +1453 -0
  108. package/src/lineage/flow-grade.js +221 -0
  109. package/src/lineage/governance-edit.js +169 -0
  110. package/src/lineage/graph-builder.js +1114 -0
  111. package/src/lineage/graph-diff.js +431 -0
  112. package/src/lineage/graph-snapshot.js +180 -0
  113. package/src/lineage/handling-analyzer.js +168 -0
  114. package/src/lineage/ids.js +349 -0
  115. package/src/lineage/impact-assessment.js +76 -0
  116. package/src/lineage/impact-engine.js +268 -0
  117. package/src/lineage/index.js +281 -0
  118. package/src/lineage/language-coverage-tiers.js +58 -0
  119. package/src/lineage/obligation-mapping.js +126 -0
  120. package/src/lineage/obligation-predicates.js +235 -0
  121. package/src/lineage/observation-adapters.js +282 -0
  122. package/src/lineage/observation-correlation.js +622 -0
  123. package/src/lineage/observation-store.js +497 -0
  124. package/src/lineage/path-query.js +410 -0
  125. package/src/lineage/path-store.js +400 -0
  126. package/src/lineage/protection.js +53 -0
  127. package/src/lineage/recipient-profile.js +192 -0
  128. package/src/lineage/recipient-registry.js +394 -0
  129. package/src/lineage/redact-graph.js +224 -0
  130. package/src/lineage/remediation.js +417 -0
  131. package/src/lineage/resolve-destination.js +91 -0
  132. package/src/lineage/runtime-observation.js +464 -0
  133. package/src/lineage/scenario-diff.js +84 -0
  134. package/src/lineage/scenario-engine.js +251 -0
  135. package/src/lineage/scenario.js +101 -0
  136. package/src/lineage/schema.js +167 -0
  137. package/src/lineage/sink-registry.js +427 -0
  138. package/src/lineage/source-registry.js +357 -0
  139. package/src/lineage/source-seeding.js +212 -0
  140. package/src/lineage/summaries.js +590 -0
  141. package/src/lineage/transform-catalog.js +397 -0
  142. package/src/lineage/transit-protection.js +150 -0
  143. package/src/lineage/validate.js +285 -0
  144. package/src/lsp/server.js +49 -2
  145. package/src/mcp/CLAUDE.md +7 -1
  146. package/src/mcp/dataflow-tools.js +160 -0
  147. package/src/mcp/server.js +1 -1
  148. package/src/mcp/tools.js +22 -1
  149. package/src/pipeline/assurance-mode.js +64 -1
  150. package/src/pipeline/finding-schema.js +8 -1
  151. package/src/pipeline/scan-health.js +19 -1
  152. package/src/posture/CLAUDE.md +140 -0
  153. package/src/posture/accuracy-scorecard.js +60 -0
  154. package/src/posture/artifact-registry.js +76 -0
  155. package/src/posture/auditor-walkthrough.js +192 -13
  156. package/src/posture/compliance-frameworks/hipaa-security-rule.json +3 -2
  157. package/src/posture/compliance-policy.js +12 -2
  158. package/src/posture/cross-repo-memory.js +7 -2
  159. package/src/posture/fix-history.js +25 -2
  160. package/src/posture/fix-verify.js +9 -1
  161. package/src/posture/fleet.js +0 -0
  162. package/src/posture/git-history.js +13 -5
  163. package/src/posture/material-change.js +21 -2
  164. package/src/posture/mttr.js +75 -12
  165. package/src/posture/obligation-evidence-pack.js +202 -0
  166. package/src/posture/pre-incident-archaeology.js +39 -7
  167. package/src/posture/privacy-framework.js +14 -0
  168. package/src/posture/provenance/ai-authorship.js +68 -0
  169. package/src/posture/provenance/branch-entry.js +80 -0
  170. package/src/posture/provenance/cache.js +143 -0
  171. package/src/posture/provenance/confidence.js +36 -0
  172. package/src/posture/provenance/coordinator.js +786 -0
  173. package/src/posture/provenance/dag-walk.js +249 -0
  174. package/src/posture/provenance/evidence-attribution.js +59 -0
  175. package/src/posture/provenance/git-evidence.js +310 -0
  176. package/src/posture/provenance/lifecycle.js +208 -0
  177. package/src/posture/provenance/missing-control-resolver.js +137 -0
  178. package/src/posture/provenance/origin-resolver.js +342 -0
  179. package/src/posture/provenance/predicate-replay.js +133 -0
  180. package/src/posture/provenance/providers/config.js +39 -0
  181. package/src/posture/provenance/providers/github.js +62 -0
  182. package/src/posture/provenance/providers/gitlab.js +58 -0
  183. package/src/posture/provenance/repo-lineage.js +74 -0
  184. package/src/posture/provenance/sca-origin.js +139 -0
  185. package/src/posture/provenance/schema.js +255 -0
  186. package/src/posture/provenance/transitive-sca.js +147 -0
  187. package/src/posture/provenance/validate.js +30 -0
  188. package/src/posture/provenance-evidence-bundle.js +144 -0
  189. package/src/posture/remediation-ledger.js +337 -0
  190. package/src/posture/sbom-diff.js +15 -2
  191. package/src/posture/secret-history.js +10 -2
  192. package/src/posture/state-dir.js +38 -14
  193. package/src/posture/vuln-archaeology.js +8 -2
  194. package/src/pr-delta.js +25 -4
  195. package/src/report/index.js +197 -3
  196. package/src/runScan.js +34 -5
  197. package/src/sast/rate-limit.js +33 -3
  198. package/src/server/CLAUDE.md +47 -0
  199. package/src/server/graph-loader.js +141 -0
  200. package/src/server/http-server.js +325 -0
  201. package/src/server/routes.js +129 -0
  202. package/src/server/security.js +111 -0
  203. package/src/server/static-assets.js +139 -0
  204. package/src/util/git-hardening.js +128 -0
  205. package/dist/11.index.js +0 -353
  206. package/dist/259.index.js +0 -975
  207. package/dist/317.index.js +0 -300
  208. package/dist/609.index.js +0 -741
  209. package/dist/838.index.js +0 -152
@@ -0,0 +1,268 @@
1
+ export const id = 4547;
2
+ export const ids = [4547];
3
+ export const modules = {
4
+
5
+ /***/ 4547:
6
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
+
8
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
+ /* harmony export */ applyScenario: () => (/* binding */ applyScenario)
10
+ /* harmony export */ });
11
+ /* harmony import */ var _protection_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(965);
12
+ /* harmony import */ var _dataflow_privacy_sink_policy_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3138);
13
+ // scenario-engine.js — M5 deliverable #3a (FR-502): the clone-and-
14
+ // override engine. Deep-clones the base graph, applies each declared
15
+ // Scenario operation, then re-runs the SAME two pure aggregators
16
+ // graph-builder.js's own real pipeline uses (aggregateVerdicts,
17
+ // isSinkPermitted) over only the flows an operation actually touched —
18
+ // never re-running the taint/path pipeline, per this sub-project's own
19
+ // scoping doc.
20
+ //
21
+ // The exact recomputation this module mirrors, confirmed by direct
22
+ // read of graph-builder.js's own real edge/flow minting pass:
23
+ // flow.protectionSummary = aggregateVerdicts([
24
+ // edge.protection.transit.verdict,
25
+ // edge.protection.atRest.verdict,
26
+ // edge.protection.handling.verdict,
27
+ // ])
28
+ // flow.policyVerdict = isSinkPermitted(dataElement.dataClasses, sinkNode.subtype,
29
+ // opts.privacySinkPolicy, { environment: opts.environment, destination: sinkNode.destination?.literalValue ?? null })
30
+ // ? 'permitted' : 'prohibited' (or 'not_evaluated' if no policy/classes/sinkKind)
31
+
32
+
33
+
34
+
35
+ function _deepClone(v) { return JSON.parse(JSON.stringify(v)); }
36
+
37
+ function _byId(arr) { return new Map((arr ?? []).map((x) => [x.id, x])); }
38
+
39
+ // Aggregates protectionSummary across EVERY edge belonging to `flow`, not
40
+ // just one of them — a flow's `edgeIds` can in principle name more than
41
+ // one edge (graph-builder.js's own real flows are always single-edge
42
+ // today, but the schema and this module both accept a multi-edge array
43
+ // with no restriction), and aggregateVerdicts's own documented purpose is
44
+ // exactly this cross-branch/cross-edge reduction (PRD §8.4). Picking a
45
+ // single arbitrary edge here would silently go stale the moment a
46
+ // scenario is built against a genuinely multi-hop flow.
47
+ function _recomputeProtectionSummaryForFlow(flow, graph) {
48
+ const edges = graph.edges.filter((e) => flow.edgeIds.includes(e.id));
49
+ const verdicts = edges.flatMap((e) => [
50
+ e.protection.transit.verdict,
51
+ e.protection.atRest.verdict,
52
+ e.protection.handling.verdict,
53
+ ]);
54
+ return (0,_protection_js__WEBPACK_IMPORTED_MODULE_0__/* .aggregateVerdicts */ .SX)(verdicts);
55
+ }
56
+
57
+ function _recomputePolicyVerdict(flow, graph, opts) {
58
+ if (opts.privacySinkPolicy == null) return null; // signal: leave flow.policyVerdict untouched
59
+ const de = graph.dataElements.find((d) => flow.dataElementIds.includes(d.id));
60
+ const sinkNode = graph.nodes.find((n) => n.id === flow.sink);
61
+ const classes = de?.dataClasses ?? [];
62
+ const sinkKind = sinkNode?.subtype ?? null;
63
+ if (!classes.length || !sinkKind) return 'not_evaluated';
64
+ const ctx = {
65
+ environment: opts.environment ?? process.env.AGENTIC_SECURITY_ENVIRONMENT ?? null,
66
+ destination: sinkNode?.destination?.literalValue ?? null,
67
+ };
68
+ return (0,_dataflow_privacy_sink_policy_js__WEBPACK_IMPORTED_MODULE_1__/* .isSinkPermitted */ .i$)(classes, sinkKind, opts.privacySinkPolicy, ctx) ? 'permitted' : 'prohibited';
69
+ }
70
+
71
+ // Every flow using this edge (by edgeIds membership) gets protectionSummary
72
+ // recomputed; policyVerdict only for flows whose sink node's destination
73
+ // or the flow's own dataClasses could plausibly have changed — but since
74
+ // applyScenario always calls this after ANY node/edge touch to be safe
75
+ // (recomputation is cheap and idempotent), scope is simply "every flow
76
+ // touching this edge or this node".
77
+ function _touchedFlows(graph, { edgeId, nodeId }) {
78
+ return graph.flows.filter((f) =>
79
+ (edgeId && f.edgeIds.includes(edgeId)) ||
80
+ (nodeId && (f.source === nodeId || f.sink === nodeId)));
81
+ }
82
+
83
+ function _recomputeTouchedFlows(graph, touch, opts) {
84
+ for (const flow of _touchedFlows(graph, touch)) {
85
+ flow.protectionSummary = _recomputeProtectionSummaryForFlow(flow, graph);
86
+ const newPolicyVerdict = _recomputePolicyVerdict(flow, graph, opts);
87
+ if (newPolicyVerdict !== null) flow.policyVerdict = newPolicyVerdict;
88
+ }
89
+ }
90
+
91
+ function _applyRequireTransitProtection(graph, op) {
92
+ const edge = _byId(graph.edges).get(op.targetEdgeId);
93
+ if (!edge) return { ok: false, reason: `targetEdgeId "${op.targetEdgeId}" not found in graph.edges` };
94
+ edge.protection.transit = { verdict: 'protected', evidenceGrade: 'assumed' };
95
+ _recomputeTouchedFlows(graph, { edgeId: edge.id }, op._opts);
96
+ return { ok: true };
97
+ }
98
+
99
+ function _applyHandling(graph, op) {
100
+ const edge = _byId(graph.edges).get(op.targetEdgeId);
101
+ if (!edge) return { ok: false, reason: `targetEdgeId "${op.targetEdgeId}" not found in graph.edges` };
102
+ // Mirrors graph-builder.js's own gate (~line 757): 'encrypted' handling
103
+ // only earns the atRest 'protected' verdict when the edge's sink node
104
+ // is store-kind (database/file/object-storage/cache/client-storage/
105
+ // backup/export). For any other sink kind (e.g. 'external-api',
106
+ // 'queue') "at rest" isn't even a meaningful concept — falls through to
107
+ // the same 'handling' dimension the non-encrypted case already sets.
108
+ const sinkNode = graph.nodes.find((n) => n.id === edge.to);
109
+ if (op.handling === 'encrypted' && sinkNode?.kind === 'store') {
110
+ edge.protection.atRest = { verdict: 'protected', evidenceGrade: 'assumed' };
111
+ } else {
112
+ edge.protection.handling = { verdict: 'protected', evidenceGrade: 'assumed' };
113
+ }
114
+ _recomputeTouchedFlows(graph, { edgeId: edge.id }, op._opts);
115
+ return { ok: true };
116
+ }
117
+
118
+ function _applyRemoveEntity(graph, op) {
119
+ const node = _byId(graph.nodes).get(op.targetNodeId);
120
+ if (!node) return { ok: false, reason: `targetNodeId "${op.targetNodeId}" not found in graph.nodes` };
121
+ const removedEdgeIds = new Set(graph.edges.filter((e) => e.from === node.id || e.to === node.id).map((e) => e.id));
122
+ graph.edges = graph.edges.filter((e) => !removedEdgeIds.has(e.id));
123
+ graph.flows = graph.flows.filter((f) => f.source !== node.id && f.sink !== node.id
124
+ && !f.edgeIds.some((id) => removedEdgeIds.has(id)));
125
+ graph.nodes = graph.nodes.filter((n) => n.id !== node.id);
126
+ // Cascade-prune graph.recipientProfiles[] too — a RecipientProfile whose
127
+ // contributingGraphIds referenced ONLY this now-removed node must not
128
+ // survive dangling (a downstream `dataflow export --format recipients`
129
+ // consumer filters by exactly contributingGraphIds against surviving
130
+ // node ids); a profile with OTHER surviving contributing ids just loses
131
+ // this one id, never the whole record. Guarded on the array existing —
132
+ // the base graph shape used throughout this sub-project's own tests
133
+ // doesn't always include it. A profile with NO contributingGraphIds at
134
+ // all (null/undefined — real graph-builder.js output always mints a
135
+ // non-empty array, so this is defensive against a hand-built/external
136
+ // graph only) is left untouched rather than normalized to `[]` and
137
+ // dropped, since a missing array is not evidence the profile referenced
138
+ // this node.
139
+ // NOTE (final-review re-review N2, disclosed not fixed): this cascade
140
+ // is real graph mutation, but scenario-diff.js's WATCHED_SCENARIO_FIELDS
141
+ // has no `recipientProfile` kind, so diffScenarioGraph's own delta
142
+ // report stays silent about a recipient record that disappeared or lost
143
+ // a contributing id here — a future increment's fuller fix, not scope
144
+ // creep for this pass.
145
+ if (graph.recipientProfiles?.length) {
146
+ graph.recipientProfiles = graph.recipientProfiles
147
+ .map((rp) => (rp.contributingGraphIds == null ? rp
148
+ : { ...rp, contributingGraphIds: rp.contributingGraphIds.filter((id) => id !== node.id) }))
149
+ .filter((rp) => rp.contributingGraphIds == null || rp.contributingGraphIds.length > 0);
150
+ }
151
+ return { ok: true };
152
+ }
153
+
154
+ // Scoped, at the applier level, to exactly `node.destination` — this
155
+ // sub-project's own scoping doc maps "replace a provider or move region"
156
+ // onto node.destination, the graph-level equivalent of a recipient's
157
+ // technical endpoint, and nothing else. scenario.js's own
158
+ // SCENARIO_OPERATION_REQUIRED_FIELDS only requires `field` be a non-empty
159
+ // string, never restricts its value — a real applied write to any other
160
+ // top-level node field (e.g. 'subtype') would land on the node but be
161
+ // completely invisible to scenario-diff.js's WATCHED_SCENARIO_FIELDS.node
162
+ // (which only watches 'destination'/'storeDetail'), since that list can
163
+ // only stay exhaustive if this applier never writes outside it. Rejecting
164
+ // any other field here — never widening the watch list — is what keeps
165
+ // that list exhaustive by construction. Mirrors the existing "skip a
166
+ // target id it can't find" pattern: reported in skippedOperations, never
167
+ // thrown.
168
+ function _applyReplaceRecipientFact(graph, op) {
169
+ const node = _byId(graph.nodes).get(op.targetNodeId);
170
+ if (!node) return { ok: false, reason: `targetNodeId "${op.targetNodeId}" not found in graph.nodes` };
171
+ if (op.field !== 'destination') {
172
+ return { ok: false, reason: `replace_recipient_fact only supports field "destination" (got "${op.field}") — this operation is scoped to a node's recipient/destination fact only` };
173
+ }
174
+ node[op.field] = _deepClone(op.value);
175
+ // The destination just changed — any edge.protection.transit verdict INTO
176
+ // this node was derived from the OLD destination (transit-protection.js's
177
+ // resolveTransitProtectionForSite is keyed on the sink's own destination)
178
+ // and is now stale. Never let a stale verdict survive with a real (non-
179
+ // 'assumed') evidence grade — reset to the honest "we don't know anymore"
180
+ // state rather than re-derive (re-deriving needs transitEvidenceByFile,
181
+ // IR-level data unavailable post-build) or silently keep the old verdict.
182
+ // NOTE (final-review re-review N1, disclosed not fixed): this demotion is
183
+ // per-EDGE and is always honest at that level (and always visible in
184
+ // diffScenarioGraph's own delta, since edge.protection.transit is a
185
+ // WATCHED_SCENARIO_FIELDS.edge entry) — but flow.protectionSummary
186
+ // aggregates transit/atRest/handling via aggregateVerdicts, whose
187
+ // precedence ranks not_assessed LAST, so a scenario that ALSO sets this
188
+ // edge's own handling dimension to 'protected' (via apply_handling) in
189
+ // the SAME operations list can mask the demotion at the flow-summary
190
+ // level, even though the masking verdict itself is honestly graded
191
+ // 'assumed'. graph-builder.js's own cross-dimension aggregation is
192
+ // documented safe only because transit/atRest are mutually exclusive by
193
+ // construction and handling is "never written" by any real analyzer —
194
+ // this module (scenario-engine.js) is the one exception to that last
195
+ // clause, which is exactly what makes the masking reachable here.
196
+ for (const edge of graph.edges) {
197
+ if (edge.to === node.id) {
198
+ edge.protection.transit = { verdict: 'not_assessed', evidenceGrade: 'none' };
199
+ }
200
+ }
201
+ _recomputeTouchedFlows(graph, { nodeId: node.id }, op._opts);
202
+ return { ok: true };
203
+ }
204
+
205
+ function _applyChangeStorageFact(graph, op) {
206
+ const node = _byId(graph.nodes).get(op.targetNodeId);
207
+ if (!node) return { ok: false, reason: `targetNodeId "${op.targetNodeId}" not found in graph.nodes` };
208
+ node.storeDetail = { ...(node.storeDetail ?? {}), [op.field]: _deepClone(op.value) };
209
+ return { ok: true };
210
+ }
211
+
212
+ function _applyChangeGovernanceFact(graph, op) {
213
+ const flow = _byId(graph.flows).get(op.targetFlowId);
214
+ if (!flow) return { ok: false, reason: `targetFlowId "${op.targetFlowId}" not found in graph.flows` };
215
+ flow.governanceRefs = { ...(flow.governanceRefs ?? {}), [op.field]: _deepClone(op.value) };
216
+ return { ok: true };
217
+ }
218
+
219
+ const _APPLIERS = {
220
+ require_transit_protection: _applyRequireTransitProtection,
221
+ apply_handling: _applyHandling,
222
+ remove_entity: _applyRemoveEntity,
223
+ replace_recipient_fact: _applyReplaceRecipientFact,
224
+ change_storage_fact: _applyChangeStorageFact,
225
+ change_governance_fact: _applyChangeGovernanceFact,
226
+ };
227
+
228
+ /**
229
+ * Apply `scenario.operations` to a deep clone of `baseGraph`. Never
230
+ * mutates `baseGraph`. An operation whose target id does not exist in
231
+ * the graph is skipped (reported in `skippedOperations`), never thrown —
232
+ * a Scenario written against an older snapshot must degrade honestly.
233
+ * `opts.privacySinkPolicy`/`opts.environment` mirror graph-builder.js's
234
+ * own opts; omitting privacySinkPolicy means policyVerdict
235
+ * recomputation is skipped entirely (base value kept on every touched
236
+ * flow) rather than guessed.
237
+ *
238
+ * Scenario-shape validation (`validateScenario`, `scenario.js`) is the
239
+ * CALLER's responsibility, not this module's — this function does no
240
+ * upfront shape checking beyond each operation's own per-target `_byId`
241
+ * lookup. An unrecognized `op.kind` is skipped via the `_APPLIERS` map
242
+ * lookup below rather than validated against `SCENARIO_OPERATION_KINDS`
243
+ * ahead of time. This mirrors `recipient-profile.js`'s own precedent,
244
+ * where `validateRecipientProfile` is never called internally by any
245
+ * producer either — the CLI layer (Task 4) calls `validateScenario`
246
+ * before `applyScenario`, by design.
247
+ */
248
+ function applyScenario(baseGraph, scenario, opts = {}) {
249
+ const graph = _deepClone(baseGraph);
250
+ const appliedOperations = [];
251
+ const skippedOperations = [];
252
+ for (const op of scenario.operations ?? []) {
253
+ const applier = _APPLIERS[op.kind];
254
+ if (!applier) {
255
+ skippedOperations.push({ operation: op, reason: `unrecognized operation kind "${op.kind}"` });
256
+ continue;
257
+ }
258
+ const result = applier(graph, { ...op, _opts: opts });
259
+ if (result.ok) appliedOperations.push({ operation: op });
260
+ else skippedOperations.push({ operation: op, reason: result.reason });
261
+ }
262
+ return { graph, appliedOperations, skippedOperations };
263
+ }
264
+
265
+
266
+ /***/ })
267
+
268
+ };