@hassangameryt/freeflow 0.5.0 → 0.6.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 (284) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.codex-plugin/plugin.json +1 -1
  4. package/README.md +148 -154
  5. package/capabilities/cognitive-routing/SKILL.md +229 -0
  6. package/capabilities/context-virtualization/SKILL.md +103 -0
  7. package/capabilities/conversation-history/SKILL.md +53 -0
  8. package/command-surface.json +6 -13
  9. package/hooks/freeflow-runtime-context.mjs +35 -91
  10. package/hooks/tests/check-runtime-context-hook.sh +56 -39
  11. package/package.json +24 -16
  12. package/pi-extension/dist/cognitive-routing/commands.js +96 -0
  13. package/pi-extension/dist/cognitive-routing/config.js +236 -0
  14. package/pi-extension/dist/cognitive-routing/controller.js +862 -0
  15. package/pi-extension/dist/cognitive-routing/history.js +439 -0
  16. package/pi-extension/dist/cognitive-routing/host.js +126 -0
  17. package/pi-extension/dist/cognitive-routing/runtime.js +43 -0
  18. package/pi-extension/dist/cognitive-routing/tool.js +211 -0
  19. package/pi-extension/dist/cognitive-routing/types.js +6 -0
  20. package/pi-extension/dist/context-virtualization/commands.js +89 -0
  21. package/pi-extension/dist/context-virtualization/projector.js +42 -0
  22. package/pi-extension/dist/context-virtualization/runtime.js +356 -0
  23. package/pi-extension/dist/context-virtualization/state.js +57 -0
  24. package/pi-extension/dist/context-virtualization/types.js +10 -0
  25. package/pi-extension/dist/conversation-history/passages.js +66 -0
  26. package/pi-extension/dist/conversation-history/ranking.js +105 -0
  27. package/pi-extension/dist/conversation-history/runtime.js +226 -0
  28. package/pi-extension/dist/conversation-history/search.js +56 -0
  29. package/pi-extension/dist/conversation-history/types.js +1 -0
  30. package/pi-extension/dist/freeflow-context/resolver.js +120 -0
  31. package/pi-extension/dist/freeflow-context/runtime.js +80 -0
  32. package/pi-extension/dist/freeflow-context/source-projector.js +95 -0
  33. package/pi-extension/dist/freeflow-context/tool.js +308 -0
  34. package/pi-extension/dist/freeflow-context/types.js +12 -0
  35. package/pi-extension/dist/freeflow-context/visibility.js +28 -0
  36. package/pi-extension/dist/index.js +516 -98
  37. package/pi-extension/dist/runtime/runtime-context.js +318 -271
  38. package/pi-extension/dist/runtime/runtime-identity.js +5 -0
  39. package/pi-extension/dist/settings/settings-tui.js +78 -0
  40. package/pi-extension/dist/settings/settings-ui.js +593 -563
  41. package/pi-extension/dist/ui/text-component.js +57 -0
  42. package/pi-extension/src/cognitive-routing/commands.ts +119 -0
  43. package/pi-extension/src/cognitive-routing/config.ts +307 -0
  44. package/pi-extension/src/cognitive-routing/controller.ts +1118 -0
  45. package/pi-extension/src/cognitive-routing/history.ts +638 -0
  46. package/pi-extension/src/cognitive-routing/host.ts +172 -0
  47. package/pi-extension/src/cognitive-routing/runtime.ts +57 -0
  48. package/pi-extension/src/cognitive-routing/tool.ts +272 -0
  49. package/pi-extension/src/cognitive-routing/types.ts +89 -0
  50. package/pi-extension/src/context-virtualization/commands.ts +111 -0
  51. package/pi-extension/src/context-virtualization/projector.ts +62 -0
  52. package/pi-extension/src/context-virtualization/runtime.ts +406 -0
  53. package/pi-extension/src/context-virtualization/state.ts +79 -0
  54. package/pi-extension/src/context-virtualization/types.ts +92 -0
  55. package/pi-extension/src/conversation-history/passages.ts +81 -0
  56. package/pi-extension/src/conversation-history/ranking.ts +155 -0
  57. package/pi-extension/src/conversation-history/runtime.ts +250 -0
  58. package/pi-extension/src/conversation-history/search.ts +79 -0
  59. package/pi-extension/src/conversation-history/types.ts +31 -0
  60. package/pi-extension/src/freeflow-context/resolver.ts +139 -0
  61. package/pi-extension/src/freeflow-context/runtime.ts +100 -0
  62. package/pi-extension/src/freeflow-context/source-projector.ts +106 -0
  63. package/pi-extension/src/freeflow-context/tool.ts +360 -0
  64. package/pi-extension/src/freeflow-context/types.ts +70 -0
  65. package/pi-extension/src/freeflow-context/visibility.ts +53 -0
  66. package/pi-extension/src/index.ts +553 -101
  67. package/pi-extension/src/runtime/runtime-context.ts +339 -281
  68. package/pi-extension/src/runtime/runtime-identity.ts +8 -0
  69. package/pi-extension/src/settings/settings-tui.ts +93 -0
  70. package/pi-extension/src/settings/settings-ui.ts +700 -613
  71. package/pi-extension/src/ui/text-component.ts +66 -0
  72. package/pi-extension/tests/cognitive-routing/commands.test.js +134 -0
  73. package/pi-extension/tests/cognitive-routing/controller.test.js +1099 -0
  74. package/pi-extension/tests/cognitive-routing/extension-lifecycle.test.js +1071 -0
  75. package/pi-extension/tests/cognitive-routing/history.test.js +274 -0
  76. package/pi-extension/tests/cognitive-routing/host-fixture.js +4 -0
  77. package/pi-extension/tests/cognitive-routing/host-identity.test.js +63 -0
  78. package/pi-extension/tests/cognitive-routing/profile-resolution.test.js +236 -0
  79. package/pi-extension/tests/cognitive-routing/tool.test.js +230 -0
  80. package/pi-extension/tests/context-virtualization/extension.test.js +749 -0
  81. package/pi-extension/tests/context-virtualization/projector.test.js +110 -0
  82. package/pi-extension/tests/context-virtualization/runtime.test.js +216 -0
  83. package/pi-extension/tests/conversation-history/runtime.test.js +98 -0
  84. package/pi-extension/tests/conversation-history/search.test.js +97 -0
  85. package/pi-extension/tests/integration/pi-extension.test.js +927 -2048
  86. package/pi-extension/tests/integration/prompt-architecture.test.js +305 -0
  87. package/runtime/prompts/cognitive-routing.md +9 -0
  88. package/runtime/prompts/context-virtualization.md +3 -0
  89. package/runtime/prompts/conversation-history.md +3 -0
  90. package/runtime/prompts/core.md +13 -0
  91. package/runtime/prompts/interaction-contract.md +7 -0
  92. package/runtime/prompts/skills.md +65 -0
  93. package/skills/action-selection/SKILL.md +91 -0
  94. package/skills/bypass/SKILL.md +3 -2
  95. package/skills/commit-work/SKILL.md +1 -1
  96. package/skills/commit-work/references/staging-decisions.md +1 -1
  97. package/skills/decision-gate/SKILL.md +1 -1
  98. package/skills/design-for-depth/SKILL.md +14 -33
  99. package/skills/design-for-depth/references/design-pressure-signals.md +1 -1
  100. package/skills/design-for-depth/references/interface-design-loop.md +1 -1
  101. package/skills/design-for-depth/references/software-design-philosophy.md +1 -1
  102. package/skills/diagnose-failure/SKILL.md +20 -14
  103. package/skills/diagnose-failure/references/diagnostic-loop-catalog.md +1 -3
  104. package/skills/diagnose-failure/references/{flaky-and-performance.md → flaky-and-performance-diagnosis.md} +1 -1
  105. package/skills/discuss/SKILL.md +34 -22
  106. package/skills/discuss/references/discussion-continuity.md +71 -0
  107. package/skills/evaluate-skill/SKILL.md +5 -5
  108. package/skills/evaluate-skill/references/{definition-schema.md → evaluation-definition-schema.md} +42 -2
  109. package/skills/evaluate-skill/references/execution-and-evidence.md +8 -3
  110. package/skills/evaluate-skill/scripts/lib/definitions.mjs +114 -3
  111. package/skills/evaluate-skill/scripts/lib/grade-interaction.mjs +156 -1
  112. package/skills/evaluate-skill/scripts/lib/grade.mjs +9 -1
  113. package/skills/evaluate-skill/scripts/lib/pi.mjs +147 -32
  114. package/skills/evaluate-skill/scripts/lib/rpc.mjs +4 -4
  115. package/skills/evaluate-skill/scripts/lib/runner.mjs +36 -14
  116. package/skills/evaluate-skill/scripts/lib/sandbox.mjs +92 -0
  117. package/skills/evaluate-skill/scripts/pi-guard.mjs +1 -1
  118. package/skills/evaluate-skill/scripts/pi-observer.mjs +66 -0
  119. package/skills/evaluate-skill/scripts/skill-eval.mjs +6 -5
  120. package/skills/execute-work/SKILL.md +18 -15
  121. package/skills/execute-work/references/code-practices.md +1 -1
  122. package/skills/execute-work/references/execute-work-edges.md +42 -0
  123. package/skills/finish-branch/SKILL.md +2 -2
  124. package/skills/finish-branch/references/integration-options.md +1 -1
  125. package/skills/handoff/SKILL.md +3 -3
  126. package/skills/launch-work/SKILL.md +1 -1
  127. package/skills/launch-work/references/launch-readiness.md +2 -2
  128. package/skills/migration-work/SKILL.md +2 -2
  129. package/skills/migration-work/references/migration-lifecycle.md +1 -1
  130. package/skills/mode-contract/SKILL.md +4 -4
  131. package/skills/release-work/SKILL.md +1 -1
  132. package/skills/release-work/references/release-evidence.md +1 -1
  133. package/skills/review-artifact/SKILL.md +28 -26
  134. package/skills/review-work/SKILL.md +28 -26
  135. package/skills/review-work/references/{reviewer-prompt.md → independent-work-reviewer-contract.md} +1 -1
  136. package/skills/review-work/references/security-risk-lens.md +1 -1
  137. package/skills/setup-freeflow/SKILL.md +3 -1
  138. package/skills/setup-freeflow/references/activation-contract.md +2 -2
  139. package/skills/setup-freeflow/references/host-setup.md +2 -2
  140. package/skills/simplify-code/SKILL.md +1 -1
  141. package/skills/simplify-code/references/simplification-patterns.md +1 -1
  142. package/skills/tdd/SKILL.md +18 -38
  143. package/skills/tdd/references/test-design.md +2 -2
  144. package/skills/track-work/SKILL.md +362 -58
  145. package/skills/track-work/scripts/lib/codec.mjs +570 -0
  146. package/skills/track-work/scripts/lib/commands.mjs +568 -0
  147. package/skills/track-work/scripts/lib/contract.mjs +303 -0
  148. package/skills/track-work/scripts/lib/model.mjs +506 -0
  149. package/skills/track-work/scripts/lib/operations.mjs +965 -0
  150. package/skills/track-work/scripts/lib/record-store.mjs +264 -0
  151. package/skills/track-work/scripts/lib/result.mjs +37 -0
  152. package/skills/track-work/scripts/lib/rewrites.mjs +740 -0
  153. package/skills/track-work/scripts/lib/schema.mjs +277 -0
  154. package/skills/track-work/scripts/lib/source-inventory.mjs +162 -0
  155. package/skills/track-work/scripts/lib/views.mjs +443 -0
  156. package/skills/track-work/scripts/lib/workspace.mjs +134 -0
  157. package/skills/track-work/scripts/working-record.mjs +122 -0
  158. package/skills/verify-work/SKILL.md +14 -2
  159. package/skills/verify-work/references/browser-runtime-evidence.md +1 -1
  160. package/skills/verify-work/references/integration-evidence.md +1 -1
  161. package/skills/verify-work/references/performance-evidence.md +1 -1
  162. package/skills/workflow/SKILL.md +105 -53
  163. package/skills/workflow/references/domain-skill-composition.md +22 -42
  164. package/skills/write-plan/SKILL.md +1 -1
  165. package/skills/write-skill/SKILL.md +3 -2
  166. package/skills/write-skill/references/progressive-disclosure.md +17 -3
  167. package/capabilities/output-router/SKILL.md +0 -206
  168. package/capabilities/output-router/references/safety-policy.md +0 -40
  169. package/capabilities/output-router/references/setup.md +0 -110
  170. package/pi-extension/dist/output-router/host-producer-identification.js +0 -232
  171. package/pi-extension/dist/output-router/native-safety-net.js +0 -216
  172. package/pi-extension/dist/output-router/observed-tool-routing.js +0 -122
  173. package/pi-extension/dist/output-router/renderers.js +0 -1023
  174. package/pi-extension/dist/output-router/router-tools.js +0 -554
  175. package/pi-extension/dist/output-router/schemas.js +0 -383
  176. package/pi-extension/dist/output-router/status.js +0 -744
  177. package/pi-extension/dist/output-router/utils.js +0 -502
  178. package/pi-extension/src/output-router/host-producer-identification.ts +0 -256
  179. package/pi-extension/src/output-router/native-safety-net.ts +0 -248
  180. package/pi-extension/src/output-router/observed-tool-routing.ts +0 -134
  181. package/pi-extension/src/output-router/renderers.ts +0 -1108
  182. package/pi-extension/src/output-router/router-tools.ts +0 -579
  183. package/pi-extension/src/output-router/schemas.ts +0 -387
  184. package/pi-extension/src/output-router/status.ts +0 -791
  185. package/pi-extension/src/output-router/utils.ts +0 -554
  186. package/pi-extension/tests/output-router/observed-producers.test.js +0 -132
  187. package/pi-extension/tests/output-router/search.test.js +0 -722
  188. package/router/dist/benchmarks/benchmark-harness.d.ts +0 -35
  189. package/router/dist/benchmarks/benchmark-harness.js +0 -92
  190. package/router/dist/benchmarks/benchmarks.d.ts +0 -109
  191. package/router/dist/benchmarks/benchmarks.js +0 -979
  192. package/router/dist/benchmarks/codex-qa-benchmarks.d.ts +0 -95
  193. package/router/dist/benchmarks/codex-qa-benchmarks.js +0 -500
  194. package/router/dist/benchmarks/command-benchmarks.d.ts +0 -143
  195. package/router/dist/benchmarks/command-benchmarks.js +0 -698
  196. package/router/dist/benchmarks/context-mode-normalized-benchmarks.d.ts +0 -82
  197. package/router/dist/benchmarks/context-mode-normalized-benchmarks.js +0 -773
  198. package/router/dist/benchmarks/context-mode-real-deep-benchmark.d.ts +0 -132
  199. package/router/dist/benchmarks/context-mode-real-deep-benchmark.js +0 -1380
  200. package/router/dist/benchmarks/context-saving-baseline.d.ts +0 -60
  201. package/router/dist/benchmarks/context-saving-baseline.js +0 -470
  202. package/router/dist/benchmarks/index-benchmarks.d.ts +0 -103
  203. package/router/dist/benchmarks/index-benchmarks.js +0 -862
  204. package/router/dist/benchmarks/storage-policy-benchmarks.d.ts +0 -101
  205. package/router/dist/benchmarks/storage-policy-benchmarks.js +0 -618
  206. package/router/dist/benchmarks/vault-index-benchmarks.d.ts +0 -56
  207. package/router/dist/benchmarks/vault-index-benchmarks.js +0 -322
  208. package/router/dist/config/config.d.ts +0 -103
  209. package/router/dist/config/config.js +0 -632
  210. package/router/dist/config/router-contract.d.ts +0 -10
  211. package/router/dist/config/router-contract.js +0 -54
  212. package/router/dist/config/schema.d.ts +0 -27
  213. package/router/dist/config/schema.js +0 -648
  214. package/router/dist/config/types.d.ts +0 -573
  215. package/router/dist/config/types.js +0 -41
  216. package/router/dist/evidence/bounded-evidence.d.ts +0 -40
  217. package/router/dist/evidence/bounded-evidence.js +0 -323
  218. package/router/dist/evidence/evidence-range-selector.d.ts +0 -24
  219. package/router/dist/evidence/evidence-range-selector.js +0 -232
  220. package/router/dist/evidence/evidence-search.d.ts +0 -27
  221. package/router/dist/evidence/evidence-search.js +0 -490
  222. package/router/dist/evidence/evidence.d.ts +0 -38
  223. package/router/dist/evidence/evidence.js +0 -200
  224. package/router/dist/evidence/failure-contracts.d.ts +0 -37
  225. package/router/dist/evidence/failure-contracts.js +0 -166
  226. package/router/dist/evidence/line-ranges.d.ts +0 -24
  227. package/router/dist/evidence/line-ranges.js +0 -22
  228. package/router/dist/experiments/local-index.d.ts +0 -64
  229. package/router/dist/experiments/local-index.js +0 -581
  230. package/router/dist/index.d.ts +0 -30
  231. package/router/dist/index.js +0 -32
  232. package/router/dist/local/local-traversal.d.ts +0 -18
  233. package/router/dist/local/local-traversal.js +0 -334
  234. package/router/dist/processing/engine.d.ts +0 -132
  235. package/router/dist/processing/engine.js +0 -533
  236. package/router/dist/processing/reducers.d.ts +0 -280
  237. package/router/dist/processing/reducers.js +0 -1673
  238. package/router/dist/processing/renderers.d.ts +0 -31
  239. package/router/dist/processing/renderers.js +0 -195
  240. package/router/dist/processing/scripts.d.ts +0 -91
  241. package/router/dist/processing/scripts.js +0 -386
  242. package/router/dist/repo/repo-traversal.d.ts +0 -18
  243. package/router/dist/repo/repo-traversal.js +0 -245
  244. package/router/dist/routing/observed-reducers.d.ts +0 -41
  245. package/router/dist/routing/observed-reducers.js +0 -661
  246. package/router/dist/routing/observed-routing.d.ts +0 -26
  247. package/router/dist/routing/observed-routing.js +0 -378
  248. package/router/dist/routing/parsers.d.ts +0 -16
  249. package/router/dist/routing/parsers.js +0 -521
  250. package/router/dist/routing/run-filters.d.ts +0 -60
  251. package/router/dist/routing/run-filters.js +0 -238
  252. package/router/dist/routing/run-reducers.d.ts +0 -49
  253. package/router/dist/routing/run-reducers.js +0 -122
  254. package/router/dist/sandbox/adapter-roots.d.ts +0 -46
  255. package/router/dist/sandbox/adapter-roots.js +0 -66
  256. package/router/dist/sandbox/eryx-python-adapter.d.ts +0 -13
  257. package/router/dist/sandbox/eryx-python-adapter.js +0 -868
  258. package/router/dist/sandbox/jq-wasm-adapter.d.ts +0 -9
  259. package/router/dist/sandbox/jq-wasm-adapter.js +0 -429
  260. package/router/dist/sandbox/quickjs-wasi-adapter.d.ts +0 -13
  261. package/router/dist/sandbox/quickjs-wasi-adapter.js +0 -384
  262. package/router/dist/sandbox/script-sandbox.d.ts +0 -134
  263. package/router/dist/sandbox/script-sandbox.js +0 -337
  264. package/router/dist/setup/script-transform-adapters.d.ts +0 -32
  265. package/router/dist/setup/script-transform-adapters.js +0 -278
  266. package/router/dist/tools/batch.d.ts +0 -33
  267. package/router/dist/tools/batch.js +0 -586
  268. package/router/dist/tools/run.d.ts +0 -62
  269. package/router/dist/tools/run.js +0 -1304
  270. package/router/dist/tools/search.d.ts +0 -66
  271. package/router/dist/tools/search.js +0 -1364
  272. package/router/dist/transform/engine.d.ts +0 -168
  273. package/router/dist/transform/engine.js +0 -2072
  274. package/router/dist/vault/vault-index.d.ts +0 -125
  275. package/router/dist/vault/vault-index.js +0 -416
  276. package/router/dist/vault/vault.d.ts +0 -138
  277. package/router/dist/vault/vault.js +0 -630
  278. package/runtime/interaction-contract.md +0 -16
  279. package/skills/discuss/references/checkpoints.md +0 -66
  280. package/skills/execute-work/references/execution-loop.md +0 -77
  281. package/skills/track-work/references/working-record-schema.md +0 -378
  282. package/skills/workflow/references/workflow-loop.md +0 -92
  283. /package/skills/handoff/references/{templates.md → handoff-templates.md} +0 -0
  284. /package/skills/review-artifact/references/{reviewer-prompt.md → independent-artifact-reviewer-contract.md} +0 -0
@@ -1,632 +0,0 @@
1
- import { isValidPostToolRoutingMode, validatePositiveIntegerThreshold } from "./router-contract.js";
2
- import {
3
- OBSERVED_ROUTING_FAILURE_MODES,
4
- OBSERVED_ROUTING_PERSISTENCE_MODES,
5
- OUTPUT_ROUTER_PROFILES,
6
- RESERVED_OBSERVED_ROUTING_PERSISTENCE_MODES,
7
- STORAGE_POLICY_MODES,
8
- } from "./types.js";
9
- export const OUTPUT_ROUTER_SKILL_PATH = "capabilities/output-router/SKILL.md";
10
- export const DEFAULT_VAULT_ROOT = "~/.cache/freeflow-router/vault";
11
- export const DEFAULT_POST_TOOL_ROUTING = "off";
12
- export const DEFAULT_OUTPUT_ROUTER_ENABLED = false;
13
- export const DEFAULT_OUTPUT_ROUTER_PROFILE = "standard";
14
- export const DEFAULT_STORAGE_POLICY = "hybrid-dedupe";
15
- export const DEFAULT_VAULT_RETENTION = {
16
- strategy: "ttl",
17
- ttlDays: 7,
18
- };
19
- export const DEFAULT_ROUTER_THRESHOLDS = {
20
- largeOutputBytes: 64_000,
21
- largeOutputLines: 1_000,
22
- };
23
- export const DEFAULT_OBSERVED_ROUTING_PERSISTENCE = "none";
24
- export const SAFE_OBSERVED_ROUTING_PERSISTENCE_FALLBACK = "metadata-only";
25
- export const DEFAULT_OBSERVED_ROUTING_CONFIG = {
26
- enabled: false,
27
- onRoutingFailure: "fail-open",
28
- mcp: { servers: {} },
29
- web: { enabled: false, persistence: DEFAULT_OBSERVED_ROUTING_PERSISTENCE },
30
- fetch: { enabled: false, persistence: DEFAULT_OBSERVED_ROUTING_PERSISTENCE },
31
- codeSearch: { enabled: false, persistence: DEFAULT_OBSERVED_ROUTING_PERSISTENCE },
32
- };
33
- export const SCRIPT_TRANSFORM_LANGUAGES = ["javascript", "python", "jq"];
34
- export const DEFAULT_SCRIPT_TRANSFORM_LIMITS = {
35
- timeoutMs: 5_000,
36
- maxInputBytes: 1_048_576,
37
- maxOutputBytes: 65_536,
38
- };
39
- export const MAX_SCRIPT_TRANSFORM_LIMITS = {
40
- timeoutMs: 30_000,
41
- maxInputBytes: 10_485_760,
42
- maxOutputBytes: 1_048_576,
43
- };
44
- export const DEFAULT_SCRIPT_TRANSFORM_CONFIG = {
45
- enabled: false,
46
- sandbox: "auto",
47
- languages: [...SCRIPT_TRANSFORM_LANGUAGES],
48
- network: "off",
49
- limits: { ...DEFAULT_SCRIPT_TRANSFORM_LIMITS },
50
- rawScriptPersistence: "disabled",
51
- };
52
- export const DEFAULT_LOCAL_FREEFLOW_CONFIG = {
53
- processing: {
54
- unsafeUnsandboxed: {
55
- enabled: false,
56
- },
57
- },
58
- };
59
- export function createDefaultRouterConfig(options = {}) {
60
- return {
61
- enabled: DEFAULT_OUTPUT_ROUTER_ENABLED,
62
- profile: DEFAULT_OUTPUT_ROUTER_PROFILE,
63
- postToolRouting: DEFAULT_POST_TOOL_ROUTING,
64
- storagePolicy: DEFAULT_STORAGE_POLICY,
65
- thresholds: { ...DEFAULT_ROUTER_THRESHOLDS },
66
- vault: {
67
- root: options.vaultRoot ?? DEFAULT_VAULT_ROOT,
68
- retention: options.vaultRetention ?? DEFAULT_VAULT_RETENTION,
69
- },
70
- };
71
- }
72
- export function normalizeRouterConfig(input) {
73
- const config = createDefaultRouterConfig();
74
- const warnings = [];
75
- if (input === undefined || input === null) {
76
- return { config, warnings };
77
- }
78
- if (!isRecord(input)) {
79
- return {
80
- config,
81
- warnings: ["outputRouter config must be an object; using built-in output router defaults."],
82
- };
83
- }
84
- applyRouterEnabled(config, warnings, input.enabled);
85
- applyRouterProfile(config, warnings, input.profile);
86
- applyPostToolRouting(config, warnings, input.postToolRouting);
87
- applyStringEnum(
88
- config,
89
- warnings,
90
- input.storagePolicy,
91
- "storagePolicy",
92
- "outputRouter.storagePolicy",
93
- STORAGE_POLICY_MODES,
94
- DEFAULT_STORAGE_POLICY,
95
- );
96
- applyRouterThresholds(config, warnings, input);
97
- applyRouterVault(config, warnings, input);
98
- applyRouterHints(config, warnings, input);
99
- return { config, warnings };
100
- }
101
- export function normalizeObservedRoutingConfig(input) {
102
- const config = createDefaultObservedRoutingConfig();
103
- const warnings = [];
104
- if (input === undefined || input === null) {
105
- return { config, warnings };
106
- }
107
- if (!isRecord(input)) {
108
- return {
109
- config,
110
- warnings: ["observedRouting config must be an object; observed routing is off by default."],
111
- };
112
- }
113
- applyObservedRoutingEnabled(config, warnings, input.enabled);
114
- applyStringEnum(
115
- config,
116
- warnings,
117
- input.onRoutingFailure,
118
- "onRoutingFailure",
119
- "observedRouting.onRoutingFailure",
120
- OBSERVED_ROUTING_FAILURE_MODES,
121
- DEFAULT_OBSERVED_ROUTING_CONFIG.onRoutingFailure,
122
- );
123
- applyObservedMcpConfig(config, warnings, input.mcp);
124
- config.web = parseObservedProducerConfig(input.web, "observedRouting.web", warnings);
125
- config.fetch = parseObservedProducerConfig(input.fetch, "observedRouting.fetch", warnings);
126
- config.codeSearch = parseObservedProducerConfig(input.codeSearch, "observedRouting.codeSearch", warnings);
127
- return { config, warnings };
128
- }
129
- export function normalizeScriptTransformConfig(input) {
130
- const config = {
131
- ...DEFAULT_SCRIPT_TRANSFORM_CONFIG,
132
- languages: [...DEFAULT_SCRIPT_TRANSFORM_CONFIG.languages],
133
- limits: { ...DEFAULT_SCRIPT_TRANSFORM_CONFIG.limits },
134
- };
135
- const warnings = [];
136
- if (input === undefined || input === null) {
137
- return { config, warnings };
138
- }
139
- if (!isRecord(input)) {
140
- return {
141
- config,
142
- warnings: ["scriptTransform config must be an object; script transform is disabled by default."],
143
- };
144
- }
145
- if (input.enabled !== undefined) {
146
- if (typeof input.enabled === "boolean") {
147
- config.enabled = input.enabled;
148
- } else {
149
- warnings.push(`Invalid scriptTransform.enabled=${JSON.stringify(input.enabled)}; using false.`);
150
- }
151
- }
152
- applyStringEnum(
153
- config,
154
- warnings,
155
- input.sandbox,
156
- "sandbox",
157
- "scriptTransform.sandbox",
158
- ["auto"],
159
- DEFAULT_SCRIPT_TRANSFORM_CONFIG.sandbox,
160
- );
161
- applyStringEnum(
162
- config,
163
- warnings,
164
- input.network,
165
- "network",
166
- "scriptTransform.network",
167
- ["off"],
168
- DEFAULT_SCRIPT_TRANSFORM_CONFIG.network,
169
- );
170
- applyStringEnum(
171
- config,
172
- warnings,
173
- input.rawScriptPersistence,
174
- "rawScriptPersistence",
175
- "scriptTransform.rawScriptPersistence",
176
- ["disabled"],
177
- DEFAULT_SCRIPT_TRANSFORM_CONFIG.rawScriptPersistence,
178
- );
179
- applyScriptTransformLanguages(config, warnings, input.languages);
180
- applyScriptTransformLimits(config, warnings, input.limits);
181
- return { config, warnings };
182
- }
183
- export function normalizeLocalFreeflowConfig(input) {
184
- const config = {
185
- processing: {
186
- unsafeUnsandboxed: { ...DEFAULT_LOCAL_FREEFLOW_CONFIG.processing.unsafeUnsandboxed },
187
- },
188
- };
189
- const warnings = [];
190
- if (input === undefined || input === null) {
191
- return { config, warnings };
192
- }
193
- if (!isRecord(input)) {
194
- return {
195
- config,
196
- warnings: [".freeflow/local.json must be an object; local unsafe processing opt-ins are disabled."],
197
- };
198
- }
199
- if (input.processing === undefined) {
200
- return { config, warnings };
201
- }
202
- if (!isRecord(input.processing)) {
203
- warnings.push("Invalid local processing config; expected an object. unsafeUnsandboxed remains disabled.");
204
- return { config, warnings };
205
- }
206
- const unsafe = input.processing.unsafeUnsandboxed;
207
- if (unsafe === undefined) {
208
- return { config, warnings };
209
- }
210
- if (!isRecord(unsafe)) {
211
- warnings.push(
212
- "Invalid local processing.unsafeUnsandboxed config; expected an object with enabled boolean. unsafeUnsandboxed remains disabled.",
213
- );
214
- return { config, warnings };
215
- }
216
- if (typeof unsafe.enabled === "boolean") {
217
- config.processing.unsafeUnsandboxed.enabled = unsafe.enabled;
218
- } else if (unsafe.enabled !== undefined) {
219
- warnings.push(`Invalid local processing.unsafeUnsandboxed.enabled=${JSON.stringify(unsafe.enabled)}; using false.`);
220
- }
221
- return { config, warnings };
222
- }
223
- export function normalizeFreeflowConfig(input) {
224
- const warnings = [];
225
- if (input !== undefined && input !== null && !isRecord(input)) {
226
- const router = normalizeRouterConfig(undefined);
227
- const observedRouting = normalizeObservedRoutingConfig(undefined);
228
- const scriptTransform = normalizeScriptTransformConfig(undefined);
229
- return {
230
- config: {
231
- outputRouter: router.config,
232
- observedRouting: observedRouting.config,
233
- scriptTransform: scriptTransform.config,
234
- },
235
- warnings: ["Freeflow config must be an object; using built-in defaults."],
236
- };
237
- }
238
- const source = isRecord(input) ? input : {};
239
- if (source.processing !== undefined) {
240
- warnings.push(
241
- ".freeflow/config.json processing config is ignored; unsafe unsandboxed processing must be enabled in local-only .freeflow/local.json.",
242
- );
243
- }
244
- const routerSource = source.outputRouter;
245
- const routerSourceRecord = isRecord(routerSource) ? routerSource : {};
246
- const router = normalizeRouterConfig(routerSource);
247
- const observedRoutingSource =
248
- routerSourceRecord.observedRouting !== undefined ? routerSourceRecord.observedRouting : source.observedRouting;
249
- const observedRouting = normalizeObservedRoutingConfig(observedRoutingSource);
250
- const observedRoutingWarnings =
251
- routerSourceRecord.observedRouting !== undefined
252
- ? prefixConfigWarnings(observedRouting.warnings, "observedRouting", "outputRouter.observedRouting")
253
- : observedRouting.warnings;
254
- const scriptTransformSource =
255
- routerSourceRecord.scriptTransform !== undefined ? routerSourceRecord.scriptTransform : source.scriptTransform;
256
- const scriptTransform = normalizeScriptTransformConfig(scriptTransformSource);
257
- const scriptTransformWarnings =
258
- routerSourceRecord.scriptTransform !== undefined
259
- ? prefixConfigWarnings(scriptTransform.warnings, "scriptTransform", "outputRouter.scriptTransform")
260
- : scriptTransform.warnings;
261
- const effectiveObservedRouting = router.config.enabled
262
- ? observedRouting.config
263
- : { ...observedRouting.config, enabled: false };
264
- const effectiveScriptTransform = router.config.enabled
265
- ? scriptTransform.config
266
- : { ...scriptTransform.config, enabled: false };
267
- warnings.push(...router.warnings, ...observedRoutingWarnings, ...scriptTransformWarnings);
268
- return {
269
- config: {
270
- outputRouter: router.config,
271
- observedRouting: effectiveObservedRouting,
272
- scriptTransform: effectiveScriptTransform,
273
- },
274
- warnings,
275
- };
276
- }
277
- function isRecord(value) {
278
- return typeof value === "object" && value !== null && !Array.isArray(value);
279
- }
280
- function prefixConfigWarnings(warnings, from, to) {
281
- return warnings.map((warning) => warning.replaceAll(from, to));
282
- }
283
- function applyRouterEnabled(config, warnings, value) {
284
- if (value === undefined) {
285
- return;
286
- }
287
- if (typeof value === "boolean") {
288
- config.enabled = value;
289
- return;
290
- }
291
- warnings.push(`Invalid outputRouter.enabled=${JSON.stringify(value)}; using ${DEFAULT_OUTPUT_ROUTER_ENABLED}.`);
292
- }
293
- function applyRouterProfile(config, warnings, value) {
294
- if (value === undefined) {
295
- return;
296
- }
297
- if (isStringIn(value, OUTPUT_ROUTER_PROFILES)) {
298
- config.profile = value;
299
- return;
300
- }
301
- warnings.push(`Invalid outputRouter.profile=${JSON.stringify(value)}; using ${DEFAULT_OUTPUT_ROUTER_PROFILE}.`);
302
- }
303
- function applyPostToolRouting(config, warnings, value) {
304
- if (value === undefined) {
305
- return;
306
- }
307
- if (isValidPostToolRoutingMode(value)) {
308
- config.postToolRouting = value;
309
- return;
310
- }
311
- warnings.push(`Invalid outputRouter.postToolRouting=${JSON.stringify(value)}; using ${DEFAULT_POST_TOOL_ROUTING}.`);
312
- }
313
- function applyRouterThresholds(config, warnings, input) {
314
- const thresholds = input.thresholds;
315
- const thresholdRecord = isRecord(thresholds) ? thresholds : {};
316
- if (thresholds !== undefined && !isRecord(thresholds)) {
317
- warnings.push("Invalid outputRouter.thresholds; expected an object with positive integer thresholds.");
318
- }
319
- applyPositiveInteger(
320
- config.thresholds,
321
- warnings,
322
- thresholdRecord.largeOutputBytes ?? input.largeOutputBytes,
323
- "largeOutputBytes",
324
- thresholdRecord.largeOutputBytes !== undefined
325
- ? "outputRouter.thresholds.largeOutputBytes"
326
- : "outputRouter.largeOutputBytes",
327
- );
328
- applyPositiveInteger(
329
- config.thresholds,
330
- warnings,
331
- thresholdRecord.largeOutputLines ?? input.largeOutputLines,
332
- "largeOutputLines",
333
- thresholdRecord.largeOutputLines !== undefined
334
- ? "outputRouter.thresholds.largeOutputLines"
335
- : "outputRouter.largeOutputLines",
336
- );
337
- }
338
- function applyPositiveInteger(thresholds, warnings, value, key, path) {
339
- if (value === undefined) {
340
- return;
341
- }
342
- if (validatePositiveIntegerThreshold(value, path).length === 0) {
343
- thresholds[key] = value;
344
- return;
345
- }
346
- warnings.push(`Invalid ${path}=${JSON.stringify(value)}; using ${DEFAULT_ROUTER_THRESHOLDS[key]}.`);
347
- }
348
- function applyRouterVault(config, warnings, input) {
349
- const vault = input.vault;
350
- const vaultRecord = isRecord(vault) ? vault : {};
351
- if (vault !== undefined && !isRecord(vault)) {
352
- warnings.push("Invalid outputRouter.vault; expected an object with root and retention.");
353
- }
354
- applyVaultRoot(
355
- config,
356
- warnings,
357
- vaultRecord.root ?? input.vaultRoot,
358
- vaultRecord.root !== undefined ? "outputRouter.vault.root" : "outputRouter.vaultRoot",
359
- );
360
- const retention = vaultRecord.retention;
361
- if (retention !== undefined) {
362
- applyVaultRetentionPolicy(config, warnings, retention);
363
- } else {
364
- applyVaultRetentionDays(
365
- config,
366
- warnings,
367
- vaultRecord.retentionDays ?? input.vaultRetentionDays,
368
- vaultRecord.retentionDays !== undefined ? "outputRouter.vault.retentionDays" : "outputRouter.vaultRetentionDays",
369
- );
370
- }
371
- }
372
- function applyVaultRoot(config, warnings, value, path) {
373
- if (value === undefined) {
374
- return;
375
- }
376
- if (typeof value === "string" && value.trim().length > 0) {
377
- config.vault.root = value;
378
- return;
379
- }
380
- warnings.push(`Invalid ${path}=${JSON.stringify(value)}; using ${DEFAULT_VAULT_ROOT}.`);
381
- }
382
- function applyVaultRetentionPolicy(config, warnings, value) {
383
- if (!isRecord(value)) {
384
- warnings.push(
385
- "Invalid outputRouter.vault.retention; expected { strategy: 'ttl', ttlDays } or { strategy: 'manual' }.",
386
- );
387
- return;
388
- }
389
- if (value.strategy === "manual") {
390
- config.vault.retention = { strategy: "manual" };
391
- return;
392
- }
393
- if (value.strategy === undefined || value.strategy === "ttl") {
394
- applyVaultRetentionDays(config, warnings, value.ttlDays, "outputRouter.vault.retention.ttlDays");
395
- return;
396
- }
397
- warnings.push(
398
- `Invalid outputRouter.vault.retention.strategy=${JSON.stringify(value.strategy)}; using ${DEFAULT_VAULT_RETENTION.strategy}.`,
399
- );
400
- }
401
- function applyVaultRetentionDays(config, warnings, value, path) {
402
- if (value === undefined) {
403
- return;
404
- }
405
- if (validatePositiveIntegerThreshold(value, path).length === 0) {
406
- config.vault.retention = { strategy: "ttl", ttlDays: value };
407
- return;
408
- }
409
- warnings.push(`Invalid ${path}=${JSON.stringify(value)}; using ${DEFAULT_VAULT_RETENTION.ttlDays}.`);
410
- }
411
- function applyRouterHints(config, warnings, input) {
412
- const hintsInput = input.hints;
413
- const hintsRecord = isRecord(hintsInput) ? hintsInput : {};
414
- if (hintsInput !== undefined && !isRecord(hintsInput)) {
415
- warnings.push(
416
- "Invalid outputRouter.hints; expected an object with generatedPathGlobs/noisyCommandPatterns arrays.",
417
- );
418
- }
419
- const generatedPaths = hintsRecord.generatedPathGlobs ?? input.generatedPaths;
420
- const noisyCommandHints = hintsRecord.noisyCommandPatterns ?? input.noisyCommandHints;
421
- const hints = {};
422
- if (generatedPaths !== undefined) {
423
- const parsed = parseStringArray(
424
- generatedPaths,
425
- hintsRecord.generatedPathGlobs !== undefined
426
- ? "outputRouter.hints.generatedPathGlobs"
427
- : "outputRouter.generatedPaths",
428
- warnings,
429
- );
430
- if (parsed) {
431
- hints.generatedPathGlobs = parsed;
432
- }
433
- }
434
- if (noisyCommandHints !== undefined) {
435
- const parsed = parseStringArray(
436
- noisyCommandHints,
437
- hintsRecord.noisyCommandPatterns !== undefined
438
- ? "outputRouter.hints.noisyCommandPatterns"
439
- : "outputRouter.noisyCommandHints",
440
- warnings,
441
- );
442
- if (parsed) {
443
- hints.noisyCommandPatterns = parsed;
444
- }
445
- }
446
- if (hints.generatedPathGlobs || hints.noisyCommandPatterns) {
447
- config.hints = hints;
448
- }
449
- }
450
- function applyScriptTransformLanguages(config, warnings, value) {
451
- if (value === undefined) {
452
- return;
453
- }
454
- if (!Array.isArray(value)) {
455
- warnings.push("Invalid scriptTransform.languages; expected an array of supported language ids.");
456
- return;
457
- }
458
- const languages = [];
459
- for (const item of value) {
460
- if (isStringIn(item, SCRIPT_TRANSFORM_LANGUAGES)) {
461
- if (!languages.includes(item)) {
462
- languages.push(item);
463
- }
464
- } else {
465
- warnings.push(
466
- `Invalid scriptTransform.languages entry=${JSON.stringify(item)}; supported languages are ${SCRIPT_TRANSFORM_LANGUAGES.join(", ")}.`,
467
- );
468
- }
469
- }
470
- if (languages.length > 0) {
471
- config.languages = languages;
472
- }
473
- }
474
- function applyScriptTransformLimits(config, warnings, value) {
475
- if (value === undefined) {
476
- return;
477
- }
478
- if (!isRecord(value)) {
479
- warnings.push("Invalid scriptTransform.limits; expected an object with positive integer limits.");
480
- return;
481
- }
482
- applyScriptLimit(config, warnings, value.timeoutMs, "timeoutMs");
483
- applyScriptLimit(config, warnings, value.maxInputBytes, "maxInputBytes");
484
- applyScriptLimit(config, warnings, value.maxOutputBytes, "maxOutputBytes");
485
- }
486
- function applyScriptLimit(config, warnings, value, key) {
487
- if (value === undefined) {
488
- return;
489
- }
490
- const max = MAX_SCRIPT_TRANSFORM_LIMITS[key];
491
- if (Number.isInteger(value) && Number(value) > 0 && Number(value) <= max) {
492
- config.limits[key] = Number(value);
493
- return;
494
- }
495
- warnings.push(
496
- `Invalid scriptTransform.limits.${key}=${JSON.stringify(value)}; using ${DEFAULT_SCRIPT_TRANSFORM_LIMITS[key]}.`,
497
- );
498
- }
499
- function applyStringEnum(config, warnings, value, key, path, allowed, fallback) {
500
- if (value === undefined) {
501
- return;
502
- }
503
- if (isStringIn(value, allowed)) {
504
- config[String(key)] = value;
505
- return;
506
- }
507
- warnings.push(`Invalid ${path}=${JSON.stringify(value)}; using ${fallback}.`);
508
- }
509
- function createDefaultObservedRoutingConfig() {
510
- return {
511
- enabled: DEFAULT_OBSERVED_ROUTING_CONFIG.enabled,
512
- onRoutingFailure: DEFAULT_OBSERVED_ROUTING_CONFIG.onRoutingFailure,
513
- mcp: { servers: {} },
514
- web: { ...DEFAULT_OBSERVED_ROUTING_CONFIG.web },
515
- fetch: { ...DEFAULT_OBSERVED_ROUTING_CONFIG.fetch },
516
- codeSearch: { ...DEFAULT_OBSERVED_ROUTING_CONFIG.codeSearch },
517
- };
518
- }
519
- function applyObservedRoutingEnabled(config, warnings, value) {
520
- if (value === undefined) {
521
- return;
522
- }
523
- if (typeof value === "boolean") {
524
- config.enabled = value;
525
- return;
526
- }
527
- warnings.push(
528
- `Invalid observedRouting.enabled=${JSON.stringify(value)}; using ${DEFAULT_OBSERVED_ROUTING_CONFIG.enabled}.`,
529
- );
530
- }
531
- function applyObservedMcpConfig(config, warnings, value) {
532
- if (value === undefined) {
533
- return;
534
- }
535
- if (!isRecord(value)) {
536
- warnings.push(
537
- "Invalid observedRouting.mcp; expected an object with explicit servers. MCP observed routing remains disabled.",
538
- );
539
- return;
540
- }
541
- if (value.servers === undefined) {
542
- return;
543
- }
544
- if (!isRecord(value.servers)) {
545
- warnings.push("Invalid observedRouting.mcp.servers; expected an object keyed by MCP server id.");
546
- return;
547
- }
548
- for (const [serverId, serverConfig] of Object.entries(value.servers)) {
549
- const normalizedServerId = parseConfigString(serverId, "observedRouting.mcp.servers server id", warnings);
550
- if (!normalizedServerId) {
551
- continue;
552
- }
553
- config.mcp.servers[normalizedServerId] = parseObservedProducerConfig(
554
- serverConfig,
555
- `observedRouting.mcp.servers.${normalizedServerId}`,
556
- warnings,
557
- );
558
- }
559
- }
560
- function parseObservedProducerConfig(value, path, warnings) {
561
- const fallback = { enabled: false, persistence: DEFAULT_OBSERVED_ROUTING_PERSISTENCE };
562
- if (value === undefined || value === null) {
563
- return fallback;
564
- }
565
- if (!isRecord(value)) {
566
- warnings.push(
567
- `Invalid ${path}; expected an object with enabled and persistence. Observed routing remains disabled for this producer.`,
568
- );
569
- return fallback;
570
- }
571
- const enabled = parseObservedProducerEnabled(value.enabled, path, warnings);
572
- const persistence = parseObservedPersistence(value.persistence, `${path}.persistence`, enabled, warnings);
573
- return { enabled, persistence };
574
- }
575
- function parseObservedProducerEnabled(value, path, warnings) {
576
- if (value === undefined) {
577
- return false;
578
- }
579
- if (typeof value === "boolean") {
580
- return value;
581
- }
582
- warnings.push(`Invalid ${path}.enabled=${JSON.stringify(value)}; using false.`);
583
- return false;
584
- }
585
- function parseObservedPersistence(value, path, enabled, warnings) {
586
- if (value === undefined) {
587
- if (enabled) {
588
- warnings.push(
589
- `Missing ${path}; setup must choose persistence explicitly. Using ${SAFE_OBSERVED_ROUTING_PERSISTENCE_FALLBACK}.`,
590
- );
591
- return SAFE_OBSERVED_ROUTING_PERSISTENCE_FALLBACK;
592
- }
593
- return DEFAULT_OBSERVED_ROUTING_PERSISTENCE;
594
- }
595
- if (isStringIn(value, OBSERVED_ROUTING_PERSISTENCE_MODES)) {
596
- return value;
597
- }
598
- if (isStringIn(value, RESERVED_OBSERVED_ROUTING_PERSISTENCE_MODES)) {
599
- warnings.push(
600
- `Unsupported ${path}=${JSON.stringify(value)}; redacted persistence is reserved for future work. Using ${SAFE_OBSERVED_ROUTING_PERSISTENCE_FALLBACK}.`,
601
- );
602
- return SAFE_OBSERVED_ROUTING_PERSISTENCE_FALLBACK;
603
- }
604
- const fallback = enabled ? SAFE_OBSERVED_ROUTING_PERSISTENCE_FALLBACK : DEFAULT_OBSERVED_ROUTING_PERSISTENCE;
605
- warnings.push(`Invalid ${path}=${JSON.stringify(value)}; expected exact, metadata-only, or none. Using ${fallback}.`);
606
- return fallback;
607
- }
608
- function parseConfigString(value, path, warnings) {
609
- if (
610
- typeof value !== "string" ||
611
- value.trim().length === 0 ||
612
- /[\u0000-\u001F\u007F-\u009F\u2028\u2029]/.test(value)
613
- ) {
614
- warnings.push(`Invalid ${path}; expected a non-empty single-line string.`);
615
- return undefined;
616
- }
617
- return value.trim();
618
- }
619
- function isStringIn(value, allowed) {
620
- return typeof value === "string" && allowed.includes(value);
621
- }
622
- function parseStringArray(value, path, warnings) {
623
- if (!Array.isArray(value)) {
624
- warnings.push(`Invalid ${path}; expected an array of strings.`);
625
- return undefined;
626
- }
627
- if (!value.every((item) => typeof item === "string")) {
628
- warnings.push(`Invalid ${path}; expected an array of strings.`);
629
- return undefined;
630
- }
631
- return value;
632
- }
@@ -1,10 +0,0 @@
1
- import type { PostToolRoutingMode } from "./types.js";
2
- export interface RouterContractIssue {
3
- path: string;
4
- message: string;
5
- }
6
- export declare function isValidPostToolRoutingMode(value: unknown): value is PostToolRoutingMode;
7
- export declare function isNativeSafetyNetEnabled(value: unknown): boolean;
8
- export declare function validatePositiveIntegerThreshold(value: unknown, path: string): RouterContractIssue[];
9
- export declare function validateVaultRetentionPolicy(value: unknown, path: string): RouterContractIssue[];
10
- export declare function validateNormalizedRouterHints(value: unknown, path: string): RouterContractIssue[];
@@ -1,54 +0,0 @@
1
- import { POST_TOOL_ROUTING_MODES } from "./types.js";
2
- export function isValidPostToolRoutingMode(value) {
3
- return typeof value === "string" && POST_TOOL_ROUTING_MODES.includes(value);
4
- }
5
- export function isNativeSafetyNetEnabled(value) {
6
- return value === "safety-net" || value === "strict";
7
- }
8
- export function validatePositiveIntegerThreshold(value, path) {
9
- if (typeof value === "number" && Number.isInteger(value) && Number.isFinite(value) && value > 0) {
10
- return [];
11
- }
12
- return [{ path, message: "Expected a positive integer." }];
13
- }
14
- export function validateVaultRetentionPolicy(value, path) {
15
- if (!isRecord(value)) {
16
- return [{ path, message: "Expected retention policy object." }];
17
- }
18
- if (value.strategy === "manual") {
19
- return [];
20
- }
21
- if (value.strategy === "ttl") {
22
- const ttlIssues = validatePositiveIntegerThreshold(value.ttlDays, `${path}.ttlDays`);
23
- return ttlIssues.length ? ttlIssues : [];
24
- }
25
- return [{ path: `${path}.strategy`, message: "Expected retention strategy manual or ttl." }];
26
- }
27
- export function validateNormalizedRouterHints(value, path) {
28
- if (value === undefined) {
29
- return [];
30
- }
31
- if (!isRecord(value)) {
32
- return [{ path, message: "Expected hints object." }];
33
- }
34
- return [
35
- ...validateOptionalStringArray(value.generatedPathGlobs, `${path}.generatedPathGlobs`),
36
- ...validateOptionalStringArray(value.noisyCommandPatterns, `${path}.noisyCommandPatterns`),
37
- ];
38
- }
39
- function validateOptionalStringArray(value, path) {
40
- if (value === undefined) {
41
- return [];
42
- }
43
- if (!Array.isArray(value)) {
44
- return [{ path, message: "Expected an array of non-empty strings." }];
45
- }
46
- const invalidIndex = value.findIndex((item) => typeof item !== "string" || item.length === 0);
47
- if (invalidIndex !== -1) {
48
- return [{ path: `${path}[${invalidIndex}]`, message: "Expected a non-empty string." }];
49
- }
50
- return [];
51
- }
52
- function isRecord(value) {
53
- return typeof value === "object" && value !== null && !Array.isArray(value);
54
- }