@clear-capabilities/agentic-security-scanner 0.149.4 → 0.150.2

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 (96) hide show
  1. package/CHANGELOG.md +138 -0
  2. package/bin/agentic-security.js +533 -2
  3. package/dist/1122.index.js +16 -16
  4. package/dist/1208.index.js +23 -0
  5. package/dist/1301.index.js +3 -3
  6. package/dist/1310.index.js +3161 -0
  7. package/dist/1379.index.js +3 -3
  8. package/dist/1444.index.js +3 -3
  9. package/dist/1660.index.js +1 -1
  10. package/dist/1700.index.js +5 -5
  11. package/dist/1905.index.js +107 -12
  12. package/dist/1920.index.js +10 -10
  13. package/dist/2238.index.js +4 -4
  14. package/dist/2271.index.js +3 -3
  15. package/dist/2432.index.js +8 -8
  16. package/dist/2659.index.js +1 -1
  17. package/dist/2826.index.js +2 -2
  18. package/dist/2830.index.js +3 -3
  19. package/dist/2923.index.js +1 -1
  20. package/dist/3001.index.js +4 -4
  21. package/dist/3117.index.js +4 -4
  22. package/dist/3180.index.js +9 -9
  23. package/dist/3276.index.js +1 -1
  24. package/dist/3415.index.js +1 -1
  25. package/dist/3499.index.js +1 -1
  26. package/dist/3518.index.js +4 -4
  27. package/dist/3736.index.js +7 -7
  28. package/dist/3839.index.js +4 -4
  29. package/dist/4113.index.js +441 -418
  30. package/dist/4265.index.js +4 -4
  31. package/dist/4384.index.js +8 -3
  32. package/dist/4399.index.js +292 -0
  33. package/dist/4547.index.js +2 -2
  34. package/dist/4863.index.js +6 -6
  35. package/dist/4970.index.js +2 -2
  36. package/dist/5051.index.js +15 -15
  37. package/dist/5144.index.js +4 -4
  38. package/dist/5333.index.js +8 -8
  39. package/dist/5343.index.js +2 -2
  40. package/dist/5350.index.js +6 -6
  41. package/dist/5561.index.js +1 -1
  42. package/dist/5637.index.js +10 -5
  43. package/dist/5724.index.js +21642 -0
  44. package/dist/5756.index.js +588 -0
  45. package/dist/5830.index.js +3 -3
  46. package/dist/6257.index.js +170 -0
  47. package/dist/6626.index.js +5 -5
  48. package/dist/6662.index.js +1 -1
  49. package/dist/6675.index.js +4 -4
  50. package/dist/6730.index.js +10 -10
  51. package/dist/6829.index.js +4 -4
  52. package/dist/6944.index.js +2 -2
  53. package/dist/6994.index.js +143 -0
  54. package/dist/7039.index.js +541 -0
  55. package/dist/7178.index.js +11 -6
  56. package/dist/7227.index.js +3 -3
  57. package/dist/7552.index.js +2 -2
  58. package/dist/7709.index.js +2 -2
  59. package/dist/7838.index.js +1037 -0
  60. package/dist/8218.index.js +4 -4
  61. package/dist/8476.index.js +4 -4
  62. package/dist/8513.index.js +8 -8
  63. package/dist/8520.index.js +1 -1
  64. package/dist/8752.index.js +4 -4
  65. package/dist/9207.index.js +2 -2
  66. package/dist/9220.index.js +5 -5
  67. package/dist/9390.index.js +6 -6
  68. package/dist/9503.index.js +2 -2
  69. package/dist/9560.index.js +3221 -0
  70. package/dist/957.index.js +127 -0
  71. package/dist/9801.index.js +1 -1
  72. package/dist/9824.index.js +5 -5
  73. package/dist/agentic-security.mjs +23 -23
  74. package/dist/agentic-security.mjs.sha256 +1 -1
  75. package/package.json +4 -3
  76. package/src/discovery/disprove.js +6 -1
  77. package/src/discovery/hunter.js +10 -1
  78. package/src/discovery/llm-invoke.js +77 -0
  79. package/src/egress/policy.js +11 -1
  80. package/src/egress/redact.js +1 -1
  81. package/src/engine.js +37 -1
  82. package/src/llm-validator/agent-loop.js +215 -0
  83. package/src/llm-validator/agent-tools.js +271 -0
  84. package/src/llm-validator/explain-proposal.js +106 -0
  85. package/src/llm-validator/fix-proposal.js +149 -0
  86. package/src/llm-validator/index.js +51 -3
  87. package/src/llm-validator/model-capabilities.js +269 -0
  88. package/src/llm-validator/model-probe.js +232 -0
  89. package/src/llm-validator/model-status.js +27 -0
  90. package/src/llm-validator/ollama-provider.js +382 -0
  91. package/src/llm-validator/oom-feedback.js +69 -0
  92. package/src/llm-validator/poc-proposal.js +122 -0
  93. package/src/llm-validator/providers.js +75 -0
  94. package/src/llm-validator/redact.js +177 -11
  95. package/src/report/index.js +33 -0
  96. package/src/sast/java-ast-folding.js +18 -2
@@ -0,0 +1,541 @@
1
+ export const id = 7039;
2
+ export const ids = [7039,4399];
3
+ export const modules = {
4
+
5
+ /***/ 54399:
6
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
+
8
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
+ /* harmony export */ MEMORY_PROFILES: () => (/* binding */ MEMORY_PROFILES),
10
+ /* harmony export */ capabilitiesFromFamilyHint: () => (/* binding */ capabilitiesFromFamilyHint),
11
+ /* harmony export */ classifyModelFamily: () => (/* binding */ classifyModelFamily),
12
+ /* harmony export */ detectMemoryTier: () => (/* binding */ detectMemoryTier),
13
+ /* harmony export */ detectSystemMemory: () => (/* binding */ detectSystemMemory),
14
+ /* harmony export */ recommendAdmission: () => (/* binding */ recommendAdmission)
15
+ /* harmony export */ });
16
+ /* unused harmony exports KNOWN_MODEL_SIZE_GB, evaluateMemoryAdmission */
17
+ /* harmony import */ var node_os__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(48161);
18
+ /* harmony import */ var _oom_feedback_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6782);
19
+ // Model family hints, RAM-aware memory profiles, and the memory-admission
20
+ // check for the Ollama provider (agentic-security-ollama-offline-prd.md
21
+ // §13, §14, §15, §22.3, §30).
22
+ //
23
+ // FAMILY HINTS ARE DEFAULTS, NEVER AUTHORITY (PRD §12/§13). A name like
24
+ // `gemma4:e2b` tells us nothing Ollama itself won't confirm — it only lets the
25
+ // harness suggest a sane default before any network call. If a model actually
26
+ // installed under a family-hinted name lacks a capability the hint implied,
27
+ // the runtime probe (model-probe.js, added when tool-calling/structured-output
28
+ // probing lands) always wins. This module only classifies and estimates; it
29
+ // never asserts a capability is present.
30
+ //
31
+ // MEMORY NUMBERS ARE ESTIMATES, NOT PROMISES (PRD §22.3, §14.1). Ollama
32
+ // artifact sizes and this module's headroom reserves are best-effort figures
33
+ // sourced from what Ollama currently publishes; they exist so the harness can
34
+ // fail BEFORE an OS-level OOM, not so it can claim an exact answer. Every
35
+ // admission decision leaves a stated safety margin rather than trying to pack
36
+ // memory to the byte.
37
+
38
+
39
+
40
+
41
+ // PRD §12/§13 FR-1203 — non-authoritative family hint from a model name.
42
+ // Longest/most-specific pattern first so `qwen3.5:4b` doesn't fall through to
43
+ // the bare `qwen` bucket.
44
+ const FAMILY_PATTERNS = [
45
+ [/^qwen3\.5/i, 'qwen3.5'],
46
+ [/^qwen3-coder-next/i, 'qwen3-coder-next'],
47
+ [/^qwen3-coder/i, 'qwen3-coder'],
48
+ [/^qwen2\.5-coder/i, 'qwen2.5-coder'],
49
+ [/^qwen3/i, 'qwen3'],
50
+ [/^qwen/i, 'qwen'],
51
+ [/^gemma4/i, 'gemma4'],
52
+ [/^functiongemma/i, 'functiongemma'],
53
+ [/^gemma3/i, 'gemma3'],
54
+ [/^gemma/i, 'gemma'],
55
+ ];
56
+
57
+ /** Non-authoritative family classification for defaults/messaging only. */
58
+ function classifyModelFamily(modelName) {
59
+ const name = String(modelName || '').trim();
60
+ for (const [re, family] of FAMILY_PATTERNS) if (re.test(name)) return family;
61
+ return 'unknown';
62
+ }
63
+
64
+ // PRD §13.1 — non-authoritative defaults per family, overridden by any real
65
+ // runtime probe result (model-probe.js). `tools`/`structuredJson`/`thinking`
66
+ // are 'unknown' where Ollama's own behavior varies by specific tag/quant
67
+ // rather than by family alone.
68
+ const FAMILY_CAPABILITY_HINTS = {
69
+ 'qwen3.5': { chat: true, structuredJson: true, tools: true, thinking: 'unknown' },
70
+ qwen3: { chat: true, structuredJson: true, tools: true, thinking: 'unknown' },
71
+ 'qwen3-coder': { chat: true, structuredJson: true, tools: true, thinking: false },
72
+ 'qwen3-coder-next': { chat: true, structuredJson: true, tools: true, thinking: false },
73
+ 'qwen2.5-coder': { chat: true, structuredJson: true, tools: 'unknown', thinking: false },
74
+ qwen: { chat: true, structuredJson: 'unknown', tools: 'unknown', thinking: 'unknown' },
75
+ gemma4: { chat: true, structuredJson: true, tools: true, thinking: 'unknown' },
76
+ functiongemma: { chat: true, structuredJson: 'unknown', tools: true, thinking: false },
77
+ gemma3: { chat: true, structuredJson: true, tools: false, thinking: false },
78
+ gemma: { chat: true, structuredJson: 'unknown', tools: 'unknown', thinking: 'unknown' },
79
+ unknown: { chat: true, structuredJson: 'unknown', tools: 'unknown', thinking: 'unknown' },
80
+ };
81
+
82
+ /**
83
+ * Build the PRD §13.1 ModelCapabilities object from a family hint alone
84
+ * (Layer B). Layer A (Ollama's own /api/show metadata) and Layer C (runtime
85
+ * probes) are applied by the caller and override these fields — this
86
+ * function only ever sets `source.familyHint: true`.
87
+ */
88
+ function capabilitiesFromFamilyHint(modelName) {
89
+ const family = classifyModelFamily(modelName);
90
+ const hint = FAMILY_CAPABILITY_HINTS[family] || FAMILY_CAPABILITY_HINTS.unknown;
91
+ return {
92
+ chat: hint.chat,
93
+ structuredJson: hint.structuredJson,
94
+ tools: hint.tools,
95
+ thinking: hint.thinking,
96
+ vision: false,
97
+ contextTokens: undefined,
98
+ source: { metadata: false, familyHint: true, runtimeProbe: false },
99
+ };
100
+ }
101
+
102
+ // ── RAM-aware memory profiles (PRD §14.4, §15.2, §22.3, §30) ───────────────
103
+
104
+ const MB = 1024 * 1024;
105
+ const GB = 1024 * MB;
106
+
107
+ // Best-effort artifact sizes as currently distributed by Ollama, used only to
108
+ // pick a SENSIBLE STARTING recommendation — the real admission decision below
109
+ // uses actually-free memory, not this table. Keep in sync with the PRD's own
110
+ // cited figures; a stale entry only affects the suggested default, never the
111
+ // admission math (which reads real os.freemem()).
112
+ const KNOWN_MODEL_SIZE_GB = Object.freeze({
113
+ 'qwen3.5:2b': 1.7,
114
+ 'qwen3.5:4b': 3.4,
115
+ 'qwen3.5:9b': 6.6,
116
+ 'gemma4:e2b': 7.2,
117
+ 'gemma4:12b': 7.6,
118
+ 'gemma4:latest': 9.6,
119
+ });
120
+
121
+ /** PRD §30 profile presets. `auto` picks between these by detected RAM. */
122
+ const MEMORY_PROFILES = Object.freeze({
123
+ '8gb': {
124
+ label: '8gb',
125
+ preferredModel: 'qwen3.5:4b',
126
+ fallbackModel: 'qwen3.5:2b',
127
+ initialContextTokens: 4096,
128
+ targetContextTokens: 8192,
129
+ maxConcurrency: 1,
130
+ minFreeRamMb: 1536,
131
+ },
132
+ '16gb-qwen': {
133
+ label: '16gb-qwen',
134
+ preferredModel: 'qwen3.5:9b',
135
+ fallbackModel: 'qwen3.5:4b',
136
+ initialContextTokens: 16384,
137
+ targetContextTokens: 32768,
138
+ maxConcurrency: 1,
139
+ minFreeRamMb: 2048,
140
+ },
141
+ '16gb-gemma': {
142
+ label: '16gb-gemma',
143
+ preferredModel: 'gemma4:e2b',
144
+ fallbackModel: 'qwen3.5:4b',
145
+ initialContextTokens: 8192,
146
+ targetContextTokens: 16384,
147
+ maxConcurrency: 1,
148
+ minFreeRamMb: 2048,
149
+ },
150
+ });
151
+
152
+ /**
153
+ * PRD §22.3 — detect total/available system RAM. Thin wrapper over `os` so
154
+ * tests can inject fake values without mocking the `os` module globally.
155
+ */
156
+ function detectSystemMemory({ totalBytes, freeBytes } = {}) {
157
+ return {
158
+ totalBytes: Number.isFinite(totalBytes) ? totalBytes : node_os__WEBPACK_IMPORTED_MODULE_0__.totalmem(),
159
+ freeBytes: Number.isFinite(freeBytes) ? freeBytes : node_os__WEBPACK_IMPORTED_MODULE_0__.freemem(),
160
+ };
161
+ }
162
+
163
+ /**
164
+ * Pick the RAM tier ('8gb' | '16gb') a machine falls into. Anything under
165
+ * ~9 GB total is treated as the 8 GB tier — real "8 GB" machines report
166
+ * slightly less than 8*1024^3 bytes to userspace (firmware/GPU reservations),
167
+ * so a hard `< 8*GB` cutoff would misclassify real 8 GB hardware as unknown.
168
+ */
169
+ function detectMemoryTier(totalBytes) {
170
+ if (!Number.isFinite(totalBytes) || totalBytes <= 0) return 'unknown';
171
+ if (totalBytes < 9 * GB) return '8gb';
172
+ return '16gb';
173
+ }
174
+
175
+ /**
176
+ * PRD §22.3 admission algorithm: does `contextTokens` at `model` fit in
177
+ * currently-free memory with the configured reserve intact?
178
+ *
179
+ * This is deliberately conservative and coarse (PRD "avoid pretending memory
180
+ * estimates are exact"): model residency is estimated from KNOWN_MODEL_SIZE_GB
181
+ * when available (falling back to a pessimistic 8 GB assumption for an
182
+ * unrecognized tag so an unknown model never LOOKS safer than a known large
183
+ * one), and KV-cache growth is approximated as a fixed per-1K-token cost
184
+ * rather than modeled per-architecture — real KV cache size depends on layer
185
+ * count/head count/quantization the harness cannot know without Ollama's own
186
+ * runtime numbers.
187
+ */
188
+ const ESTIMATED_KV_CACHE_MB_PER_1K_TOKENS = 32; // conservative, model-independent approximation
189
+ const RUNTIME_OVERHEAD_MB = 512; // Ollama server + OS scheduler slack, independent of model size
190
+
191
+ function evaluateMemoryAdmission({
192
+ modelName,
193
+ contextTokens,
194
+ freeBytes,
195
+ minFreeRamMb,
196
+ modelSizeGb,
197
+ } = {}) {
198
+ const sizeGb = Number.isFinite(modelSizeGb) ? modelSizeGb : (KNOWN_MODEL_SIZE_GB[modelName] ?? 8);
199
+ const modelMb = sizeGb * 1024;
200
+ const kvCacheMb = (Number(contextTokens) || 0) / 1000 * ESTIMATED_KV_CACHE_MB_PER_1K_TOKENS;
201
+ const requiredMb = modelMb + kvCacheMb + RUNTIME_OVERHEAD_MB + (Number(minFreeRamMb) || 0);
202
+ const freeMb = (Number(freeBytes) || 0) / MB;
203
+ const admitted = freeMb >= requiredMb;
204
+ return {
205
+ admitted,
206
+ freeMb: Math.round(freeMb),
207
+ requiredMb: Math.round(requiredMb),
208
+ modelEstimateMb: Math.round(modelMb),
209
+ kvCacheEstimateMb: Math.round(kvCacheMb),
210
+ reserveMb: Number(minFreeRamMb) || 0,
211
+ };
212
+ }
213
+
214
+ /**
215
+ * Full recommendation flow (PRD §22 "Memory admission algorithm"):
216
+ * try the profile's preferred context, shrink it, then fall back to the
217
+ * profile's smaller model, before ever declaring the profile unusable.
218
+ * Never recommends cloud — the worst outcome this function can return is
219
+ * `{admitted:false}` with a human-readable explanation, which callers treat
220
+ * as "run deterministic-only" (PRD §23.4).
221
+ */
222
+ function recommendAdmission(opts = {}) {
223
+ const result = _recommendAdmissionCore(opts);
224
+ // Adversarial-review fix (2026-09): a memory-admission ESTIMATE that
225
+ // actually caused a real OOM (ollama-provider.js's callOllamaChat now
226
+ // records this via oom-feedback.js) used to have no way to affect a
227
+ // future admission decision for the SAME model on the SAME machine — the
228
+ // exact same "admitted: true" would repeat forever. This does not
229
+ // recalibrate the underlying estimate (that needs real hardware variety
230
+ // one machine's observed failures can't substitute for); it attaches an
231
+ // honest warning so the decision is no longer presented with unqualified
232
+ // confidence.
233
+ const chosenModel = result.model || opts.requestedModel;
234
+ const prior = chosenModel ? (0,_oom_feedback_js__WEBPACK_IMPORTED_MODULE_1__/* .priorOOMFor */ .NL)(chosenModel) : null;
235
+ if (prior) {
236
+ return {
237
+ ...result,
238
+ priorOOMWarning: `'${chosenModel}' has previously failed with an out-of-memory error on this machine ` +
239
+ `(${prior.count} time${prior.count === 1 ? '' : 's'}, most recently ${new Date(prior.lastAt).toISOString()}). ` +
240
+ 'The memory estimate below may be optimistic for your hardware.',
241
+ };
242
+ }
243
+ return result;
244
+ }
245
+
246
+ function _recommendAdmissionCore({ profile, freeBytes, requestedContextTokens, requestedModel } = {}) {
247
+ const p = MEMORY_PROFILES[profile];
248
+ if (!p) return { admitted: false, reason: `unknown memory profile '${profile}'` };
249
+
250
+ const model = requestedModel || p.preferredModel;
251
+ const attempts = [];
252
+
253
+ // 1. Requested (or target) context at the requested/preferred model.
254
+ const primaryContext = Number.isFinite(requestedContextTokens) ? requestedContextTokens : p.targetContextTokens;
255
+ let check = evaluateMemoryAdmission({ modelName: model, contextTokens: primaryContext, freeBytes, minFreeRamMb: p.minFreeRamMb });
256
+ attempts.push({ model, contextTokens: primaryContext, ...check });
257
+ if (check.admitted) return { admitted: true, model, contextTokens: primaryContext, attempts };
258
+
259
+ // 2. Reduce context to the profile's conservative initial value first —
260
+ // PRD FR-2104: "shrink context before declaring an otherwise compatible
261
+ // model unusable."
262
+ if (primaryContext !== p.initialContextTokens) {
263
+ check = evaluateMemoryAdmission({ modelName: model, contextTokens: p.initialContextTokens, freeBytes, minFreeRamMb: p.minFreeRamMb });
264
+ attempts.push({ model, contextTokens: p.initialContextTokens, ...check });
265
+ if (check.admitted) return { admitted: true, model, contextTokens: p.initialContextTokens, attempts, reducedContext: true };
266
+ }
267
+
268
+ // 3. Fall back to the profile's smaller model at its initial context.
269
+ if (p.fallbackModel && p.fallbackModel !== model) {
270
+ check = evaluateMemoryAdmission({ modelName: p.fallbackModel, contextTokens: p.initialContextTokens, freeBytes, minFreeRamMb: p.minFreeRamMb });
271
+ attempts.push({ model: p.fallbackModel, contextTokens: p.initialContextTokens, ...check });
272
+ if (check.admitted) {
273
+ return {
274
+ admitted: true, model: p.fallbackModel, contextTokens: p.initialContextTokens, attempts,
275
+ reducedContext: true, fellBackToSmallerModel: true,
276
+ };
277
+ }
278
+ }
279
+
280
+ // 4. Nothing fits — deterministic-only, never cloud.
281
+ return {
282
+ admitted: false,
283
+ attempts,
284
+ reason: `No local model/context combination fit in available memory with the configured reserve. ` +
285
+ `Recommend deterministic-only scanning, or free memory before retrying.`,
286
+ };
287
+ }
288
+
289
+
290
+ /***/ }),
291
+
292
+ /***/ 27039:
293
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
294
+
295
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
296
+ /* harmony export */ getModelCapabilities: () => (/* binding */ getModelCapabilities)
297
+ /* harmony export */ });
298
+ /* unused harmony exports DEFAULT_CACHE_TTL_MS, capabilitiesFromShowMetadata, probeStructuredOutput, probeToolCalling, _internals */
299
+ /* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(73024);
300
+ /* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(76760);
301
+ /* harmony import */ var node_os__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(48161);
302
+ /* harmony import */ var node_crypto__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(77598);
303
+ /* harmony import */ var _ollama_provider_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(23837);
304
+ /* harmony import */ var _model_capabilities_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(54399);
305
+ // PRD §13.2 — the three-layer model capability detection strategy.
306
+ //
307
+ // LAYER A (metadata) is the cheapest and most authoritative: Ollama's own
308
+ // `/api/show` response, when it reports a `capabilities` array, is not a
309
+ // guess. LAYER B (model-capabilities.js's family hint) is a non-authoritative
310
+ // default used only where Layer A is silent. LAYER C (this module's
311
+ // `probeStructuredOutput`/`probeToolCalling`) is the most expensive — it
312
+ // consumes real inference time — so it is OPT-IN (the caller decides when
313
+ // "necessary" per the PRD's own wording), never run implicitly on every
314
+ // `models doctor`/`models inspect` invocation.
315
+ //
316
+ // PRECEDENCE: Layer C overrides Layer A overrides Layer B, field by field. A
317
+ // field only ever gets overridden by a MORE authoritative layer that actually
318
+ // has an opinion — a probe that couldn't run (offline/timeout) leaves the
319
+ // field exactly as the layer below it set it, it never downgrades to
320
+ // 'unknown'.
321
+ //
322
+ // CACHE KEY = Ollama version + model digest + model name (PRD §13.2 exactly).
323
+ // Digest is load-bearing: `ollama pull` replacing a tag's underlying weights
324
+ // must invalidate the cache even though the name/tag string is unchanged.
325
+ // Same disk-cache directory convention as sca/sigstore-verify.js and
326
+ // engine.js's OSV cache (`~/.claude/agentic-security/<name>/`).
327
+ //
328
+ // TTL + force-reprobe (adversarial-review fix, 2026-09). The key-based
329
+ // invalidation above is real but not complete: this module's own comment
330
+ // used to claim the entry is safe "forever" because the key changes when
331
+ // the model does — but `/api/show` doesn't expose a digest on every Ollama
332
+ // version (falls back to model NAME alone then, a few lines below), so a
333
+ // same-tag re-pull, or simply an unlucky single-trial probe the first time
334
+ // (see probeStructuredOutput/probeToolCalling's own single-call design),
335
+ // had no way to ever self-correct short of a user manually deleting a file
336
+ // under `~/.claude/agentic-security/`. Two independent fixes, since either
337
+ // alone leaves a real gap: a default TTL as a safety net for the case
338
+ // nobody notices, and an explicit `force` option (`models test --force`)
339
+ // for the case someone DOES suspect a stale answer and wants it right now.
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+
348
+ const CACHE_DIR = node_path__WEBPACK_IMPORTED_MODULE_1__.join(node_os__WEBPACK_IMPORTED_MODULE_2__.homedir(), '.claude', 'agentic-security', 'ollama-capability-cache');
349
+
350
+ // Default safety-net TTL: 30 days. Not the primary invalidation mechanism
351
+ // (the key is) — a backstop for the cases the key can't see: a same-tag
352
+ // re-pull on an Ollama version that doesn't expose a digest, or a single
353
+ // unlucky probe trial that happened to pass/fail against the model's true
354
+ // behavior. Overridable for anyone who wants a tighter or looser bound.
355
+ const DEFAULT_CACHE_TTL_MS = 30 * 24 * 60 * 60 * 1000;
356
+
357
+ function _ensureCacheDir() { try { node_fs__WEBPACK_IMPORTED_MODULE_0__.mkdirSync(CACHE_DIR, { recursive: true }); } catch {} }
358
+ function _cacheKey(ollamaVersion, modelDigest, modelName) {
359
+ return node_crypto__WEBPACK_IMPORTED_MODULE_3__.createHash('sha256').update(`${ollamaVersion}::${modelDigest}::${modelName}`).digest('hex');
360
+ }
361
+ function _cachePath(key) { return node_path__WEBPACK_IMPORTED_MODULE_1__.join(CACHE_DIR, key + '.json'); }
362
+
363
+ /**
364
+ * @returns {object|null} the cached probe RESULT (not the envelope), or
365
+ * `null` on a miss, a parse failure, OR an entry older than `ttlMs`.
366
+ */
367
+ function _readProbeCache(key, ttlMs) {
368
+ let envelope;
369
+ try { envelope = JSON.parse(node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync(_cachePath(key), 'utf8')); } catch { return null; }
370
+ // Backward-compatible with a pre-TTL cache file that was just the bare
371
+ // result object (no `probedAt`) — treat an entry with no timestamp as
372
+ // fresh rather than discarding every cache written before this fix.
373
+ if (envelope && typeof envelope === 'object' && 'probedAt' in envelope && 'result' in envelope) {
374
+ if (Number.isFinite(ttlMs) && ttlMs > 0 && Date.now() - envelope.probedAt > ttlMs) return null;
375
+ return envelope.result;
376
+ }
377
+ return envelope;
378
+ }
379
+ function _writeProbeCache(key, value) {
380
+ _ensureCacheDir();
381
+ try { node_fs__WEBPACK_IMPORTED_MODULE_0__.writeFileSync(_cachePath(key), JSON.stringify({ probedAt: Date.now(), result: value })); } catch {}
382
+ }
383
+
384
+ /**
385
+ * PRD §13.2 Layer A — parse `/api/show`'s response into the subset of
386
+ * ModelCapabilities it can actually speak to. A field this layer has no
387
+ * opinion on is omitted (not set to `false`) so the caller's merge never
388
+ * mistakes silence for a negative.
389
+ */
390
+ function capabilitiesFromShowMetadata(show) {
391
+ const out = { source: { metadata: true } };
392
+ if (Array.isArray(show?.capabilities) && show.capabilities.length > 0) {
393
+ const caps = show.capabilities;
394
+ out.chat = caps.includes('completion') || caps.includes('chat');
395
+ out.tools = caps.includes('tools');
396
+ out.vision = caps.includes('vision');
397
+ out.thinking = caps.includes('thinking');
398
+ }
399
+ const modelInfo = show?.modelInfo;
400
+ if (modelInfo && typeof modelInfo === 'object') {
401
+ const ctxKey = Object.keys(modelInfo).find((k) => k.endsWith('.context_length'));
402
+ if (ctxKey && Number.isFinite(modelInfo[ctxKey])) out.contextTokens = modelInfo[ctxKey];
403
+ }
404
+ return out;
405
+ }
406
+
407
+ /**
408
+ * PRD §13.2 Layer C — structured-output probe. A tiny schema, a request for
409
+ * `{"ok": true}`, verified end to end through the SAME
410
+ * callOllamaStructured() bounded-retry path every real structured call uses
411
+ * (not a bespoke lighter-weight check that could disagree with production
412
+ * behavior).
413
+ */
414
+ const PROBE_SCHEMA = { type: 'object', required: ['ok'], properties: { ok: { type: 'boolean' } } };
415
+
416
+ async function probeStructuredOutput({ host, model, timeouts, keepAlive } = {}) {
417
+ const r = await (0,_ollama_provider_js__WEBPACK_IMPORTED_MODULE_4__/* .callOllamaStructured */ .uM)({
418
+ host, model,
419
+ messages: [{ role: 'user', content: 'Reply with ONLY a JSON object: {"ok": true}' }],
420
+ schema: PROBE_SCHEMA,
421
+ validateFn: (obj) => (obj && obj.ok === true ? { ok: true, value: obj } : { ok: false }),
422
+ keepAlive, timeouts,
423
+ });
424
+ if (r.ok) return { supported: true };
425
+ // A transport-level failure (server unreachable, timed out) tells us
426
+ // nothing about the MODEL's capability — leave it 'unknown' rather than
427
+ // reporting a false negative for an offline/slow server.
428
+ if (['ollama-unreachable', 'ollama-not-running', 'ollama-timeout', 'ollama-model-not-installed'].includes(r.code)) {
429
+ return { supported: 'unknown', reason: r.reason || r.code };
430
+ }
431
+ return { supported: false, reason: r.reason || r.code };
432
+ }
433
+
434
+ /**
435
+ * PRD §13.2 Layer C — tool-calling probe. One harmless `echo_capability_probe`
436
+ * function; success is Ollama returning a structured `tool_calls` entry
437
+ * naming it, not a check on what the model chose to reply with in prose.
438
+ */
439
+ const PROBE_TOOL = {
440
+ type: 'function',
441
+ function: {
442
+ name: 'echo_capability_probe',
443
+ description: 'Echo back the given value. Used only to test whether this model supports tool calling.',
444
+ parameters: { type: 'object', required: ['value'], properties: { value: { type: 'string' } } },
445
+ },
446
+ };
447
+
448
+ async function probeToolCalling({ host, model, timeouts, keepAlive } = {}) {
449
+ const r = await (0,_ollama_provider_js__WEBPACK_IMPORTED_MODULE_4__/* .callOllamaChat */ .L5)({
450
+ host, model,
451
+ messages: [{ role: 'user', content: 'Call the echo_capability_probe function with value set to "probe-ok". Reply with nothing else.' }],
452
+ tools: [PROBE_TOOL],
453
+ keepAlive, timeouts,
454
+ });
455
+ if (!r.ok) {
456
+ if (['ollama-unreachable', 'ollama-not-running', 'ollama-timeout', 'ollama-model-not-installed'].includes(r.code)) {
457
+ return { supported: 'unknown', reason: r.reason || r.code };
458
+ }
459
+ return { supported: false, reason: r.reason || r.code };
460
+ }
461
+ const calls = r.result.toolCalls || [];
462
+ const called = calls.some((c) => c?.function?.name === 'echo_capability_probe');
463
+ return called ? { supported: true } : { supported: false, reason: 'model did not emit a tool_calls entry for the probe function' };
464
+ }
465
+
466
+ function _mergeLayer(base, overlay, sourceFlag) {
467
+ const merged = { ...base };
468
+ let touched = false;
469
+ for (const field of ['chat', 'structuredJson', 'tools', 'thinking', 'vision', 'contextTokens']) {
470
+ if (overlay[field] !== undefined) { merged[field] = overlay[field]; touched = true; }
471
+ }
472
+ if (touched) merged.source = { ...merged.source, [sourceFlag]: true };
473
+ return merged;
474
+ }
475
+
476
+ /**
477
+ * Orchestrates all three layers (PRD §13.2) with caching (PRD: "so startup
478
+ * does not repeatedly consume inference time"). `probe: true` opts into
479
+ * Layer C — omitted or false, this returns Layer A+B only, which is what
480
+ * every non-probing caller (models list/inspect/doctor's default path)
481
+ * should use, since Layer C spends real inference time on the user's
482
+ * machine.
483
+ *
484
+ * `force: true` (adversarial-review fix, 2026-09 — `models test --force`)
485
+ * skips reading the cache — always runs a fresh probe and overwrites
486
+ * whatever was there. `ttlMs` (default 30 days, `DEFAULT_CACHE_TTL_MS`)
487
+ * bounds how long a cached entry is trusted without either; pass `0`/
488
+ * `Infinity` to disable the TTL safety net entirely and rely on the key
489
+ * alone, matching this module's original design intent.
490
+ *
491
+ * @returns {{ok:true, capabilities:object, cached:boolean} | {ok:false, code, reason}}
492
+ */
493
+ async function getModelCapabilities({ host, model, env = process.env, probe = false, force = false, ttlMs = DEFAULT_CACHE_TTL_MS, timeouts, keepAlive } = {}) {
494
+ let capabilities = (0,_model_capabilities_js__WEBPACK_IMPORTED_MODULE_5__.capabilitiesFromFamilyHint)(model);
495
+
496
+ const show = await (0,_ollama_provider_js__WEBPACK_IMPORTED_MODULE_4__/* .showOllamaModel */ .$G)({ host, model, timeouts });
497
+ if (show.ok) {
498
+ capabilities = _mergeLayer(capabilities, capabilitiesFromShowMetadata(show), 'metadata');
499
+ }
500
+
501
+ if (!probe) {
502
+ return { ok: true, capabilities, cached: false };
503
+ }
504
+
505
+ const versionResult = await (0,_ollama_provider_js__WEBPACK_IMPORTED_MODULE_4__/* .getOllamaVersion */ .zm)({ host, timeouts });
506
+ const ollamaVersion = versionResult.ok ? versionResult.version : 'unknown-version';
507
+ // The digest is whatever Layer A's /api/show reported under `details`
508
+ // (Ollama does not expose it on /api/show consistently across versions —
509
+ // fall back to the model name alone, which still invalidates on a tag
510
+ // change, just not on a same-tag re-pull).
511
+ const modelDigest = show.ok && show.details?.digest ? show.details.digest : 'unknown-digest';
512
+ const cacheKey = _cacheKey(ollamaVersion, modelDigest, model);
513
+
514
+ const cached = force ? null : _readProbeCache(cacheKey, ttlMs);
515
+ if (cached) {
516
+ return { ok: true, capabilities: _mergeLayer(capabilities, cached, 'runtimeProbe'), cached: true };
517
+ }
518
+
519
+ const [structured, tools] = await Promise.all([
520
+ probeStructuredOutput({ host, model, timeouts, keepAlive }),
521
+ probeToolCalling({ host, model, timeouts, keepAlive }),
522
+ ]);
523
+
524
+ const probeResult = {};
525
+ if (structured.supported !== 'unknown') probeResult.structuredJson = structured.supported;
526
+ if (tools.supported !== 'unknown') probeResult.tools = tools.supported;
527
+
528
+ // Only cache a probe that actually resolved something — an all-'unknown'
529
+ // result (server unreachable mid-probe) would otherwise poison the cache
530
+ // with a permanent non-answer.
531
+ if (Object.keys(probeResult).length > 0) _writeProbeCache(cacheKey, probeResult);
532
+
533
+ return { ok: true, capabilities: _mergeLayer(capabilities, probeResult, 'runtimeProbe'), cached: false };
534
+ }
535
+
536
+ const _internals = { CACHE_DIR, _cacheKey, _cachePath };
537
+
538
+
539
+ /***/ })
540
+
541
+ };
@@ -3,18 +3,21 @@ export const ids = [7178];
3
3
  export const modules = {
4
4
 
5
5
  /***/ 7178:
6
- /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
6
+ /***/ ((__webpack_module__, __webpack_exports__, __webpack_require__) => {
7
7
 
8
+ __webpack_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
8
9
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
10
  /* harmony export */ runHistory: () => (/* binding */ runHistory),
10
11
  /* harmony export */ runWhatIf: () => (/* binding */ runWhatIf)
11
12
  /* harmony export */ });
12
13
  /* unused harmony export listHistoricalRefs */
13
- /* harmony import */ var node_child_process__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1421);
14
- /* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3024);
15
- /* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6760);
16
- /* harmony import */ var _util_git_hardening_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(8844);
17
- /* harmony import */ var _engine_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(9753);
14
+ /* harmony import */ var node_child_process__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(31421);
15
+ /* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(73024);
16
+ /* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(76760);
17
+ /* harmony import */ var _util_git_hardening_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(78844);
18
+ /* harmony import */ var _engine_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(67198);
19
+ var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_engine_js__WEBPACK_IMPORTED_MODULE_4__]);
20
+ _engine_js__WEBPACK_IMPORTED_MODULE_4__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];
18
21
  // Time-travel + counterfactual scanning (v0.68).
19
22
  //
20
23
  // Two new modes that exploit the pure-input shape of runFullScan:
@@ -262,6 +265,8 @@ function _walkWorkingTree(root) {
262
265
  return out;
263
266
  }
264
267
 
268
+ __webpack_async_result__();
269
+ } catch(e) { __webpack_async_result__(e); } });
265
270
 
266
271
  /***/ })
267
272
 
@@ -2,15 +2,15 @@ export const id = 7227;
2
2
  export const ids = [7227];
3
3
  export const modules = {
4
4
 
5
- /***/ 7227:
5
+ /***/ 67227:
6
6
  /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
7
 
8
8
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
9
  /* harmony export */ evaluatePolicy: () => (/* binding */ evaluatePolicy)
10
10
  /* harmony export */ });
11
11
  /* unused harmony export _internals */
12
- /* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3024);
13
- /* harmony import */ var node_child_process__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1421);
12
+ /* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(73024);
13
+ /* harmony import */ var node_child_process__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(31421);
14
14
  // Policy-as-code gate (FR-SDLC-9).
15
15
  //
16
16
  // Today's CI gate is `--fail-on <severity>`. That's coarse. Customers want
@@ -2,7 +2,7 @@ export const id = 7552;
2
2
  export const ids = [7552];
3
3
  export const modules = {
4
4
 
5
- /***/ 7552:
5
+ /***/ 67552:
6
6
  /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
7
 
8
8
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
@@ -12,7 +12,7 @@ export const modules = {
12
12
  /* harmony export */ writeExportReport: () => (/* binding */ writeExportReport)
13
13
  /* harmony export */ });
14
14
  /* unused harmony exports DELETION_REPORT_FILE, EXPORT_REPORT_FILE */
15
- /* harmony import */ var _state_dir_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1174);
15
+ /* harmony import */ var _state_dir_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(31174);
16
16
  // FR-706 (assurance-hardening PRD): manifest-based export and deletion
17
17
  // reports — "Operators can prove what was exported, deleted, retained, or
18
18
  // failed."
@@ -2,13 +2,13 @@ export const id = 7709;
2
2
  export const ids = [7709];
3
3
  export const modules = {
4
4
 
5
- /***/ 7709:
5
+ /***/ 17709:
6
6
  /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
7
 
8
8
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
9
  /* harmony export */ exportFlowsCSV: () => (/* binding */ exportFlowsCSV)
10
10
  /* harmony export */ });
11
- /* harmony import */ var _protection_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(965);
11
+ /* harmony import */ var _protection_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(80965);
12
12
  // export-csv.js — Milestone 4, sub-project JSON/CSV export.
13
13
  //
14
14
  // One row per FLOW (not node, not edge — the closest analogue in this