failproofai 1.0.6 → 1.0.7-beta.1
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.
- package/.next/standalone/.next/BUILD_ID +1 -1
- package/.next/standalone/.next/build-manifest.json +3 -3
- package/.next/standalone/.next/prerender-manifest.json +4 -4
- package/.next/standalone/.next/required-server-files.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page.js +4 -4
- package/.next/standalone/.next/server/app/_global-error/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/_global-error.html +1 -1
- package/.next/standalone/.next/server/app/_global-error.rsc +7 -7
- package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +6 -6
- package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +7 -7
- package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/_not-found/page.js +4 -4
- package/.next/standalone/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/_not-found.html +1 -1
- package/.next/standalone/.next/server/app/_not-found.rsc +15 -15
- package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +15 -15
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +14 -14
- package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/api/audit/invite/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/audit/run/route.js +8 -7
- package/.next/standalone/.next/server/app/api/audit/run/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/audit/status/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/login-request/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/login-verify/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/logout/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/status/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/download/[project]/[session]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/audit/page/server-reference-manifest.json +2 -2
- package/.next/standalone/.next/server/app/audit/page.js +7 -5
- package/.next/standalone/.next/server/app/audit/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/audit/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/index.html +1 -1
- package/.next/standalone/.next/server/app/index.rsc +15 -15
- package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +14 -14
- package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +15 -15
- package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/page.js +6 -6
- package/.next/standalone/.next/server/app/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/policies/page/server-reference-manifest.json +14 -14
- package/.next/standalone/.next/server/app/policies/page.js +13 -11
- package/.next/standalone/.next/server/app/policies/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/policies/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/project/[name]/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/project/[name]/page.js +8 -7
- package/.next/standalone/.next/server/app/project/[name]/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/project/[name]/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/react-loadable-manifest.json +2 -2
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/server-reference-manifest.json +2 -2
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page.js +7 -7
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/projects/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/projects/page.js +7 -6
- package/.next/standalone/.next/server/app/projects/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/projects/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/settings/page/server-reference-manifest.json +41 -8
- package/.next/standalone/.next/server/app/settings/page.js +12 -9
- package/.next/standalone/.next/server/app/settings/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/settings/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/chunks/{[externals]__1msfs-h._.js → [externals]__19_pzeq._.js} +1 -1
- package/.next/standalone/.next/server/chunks/{[externals]__1_bftcl._.js → [externals]__1j-zsg5._.js} +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__0o07qi9._.js +1 -1
- package/.next/standalone/.next/server/chunks/{[root-of-the-server]__1_r2rbg._.js → [root-of-the-server]__1bf34x4._.js} +5 -7
- package/.next/standalone/.next/server/chunks/_09dz7xv._.js +21 -21
- package/.next/standalone/.next/server/chunks/_0tovk6q._.js +1 -1
- package/.next/standalone/.next/server/chunks/_0trp3yc._.js +1 -1
- package/.next/standalone/.next/server/chunks/_1ek68ln._.js +16 -16
- package/.next/standalone/.next/server/chunks/{_1c3k-8x._.js → _1q5i8mb._.js} +2 -2
- package/.next/standalone/.next/server/chunks/node_modules_posthog-node_dist_entrypoints_index_node_mjs_01r25oi._.js +2 -2
- package/.next/standalone/.next/server/chunks/node_modules_posthog-node_dist_entrypoints_index_node_mjs_09z9-p7._.js +2 -2
- package/.next/standalone/.next/server/chunks/package_json_[json]_cjs_1nxcc4v._.js +1 -1
- package/.next/standalone/.next/server/chunks/src_hooks_01frwmb._.js +5 -0
- package/.next/standalone/.next/server/chunks/src_hooks_18qtd42._.js +3 -0
- package/.next/standalone/.next/server/chunks/src_hooks_custom-hooks-loader_ts_0lnb3n3._.js +4 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__01bmjsj._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__04usis8._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__056wjo4._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__059yza8._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0eip4_k._.js +22 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0n0xg95._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0qcb0mg._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0qxnccm._.js +5 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0rwtwpm._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0s_yomn._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0soxz2z._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0yrsbd_._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__1svlq8e._.js → [root-of-the-server]__0yxwl6j._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__11mayhe._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__13d-wb6._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1b2dbet._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1dinjii._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__0cxe_2_._.js → [root-of-the-server]__1mf3zp6._.js} +3 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1pprgri._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1q4p5b8._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1qiz0e4._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_042cgl1._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_08x1r5t._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/{_0do6d26._.js → _0bn2oo8._.js} +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_0bqoto4._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_0uyu3jf._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_1feuvhb._.js +5 -0
- package/.next/standalone/.next/server/chunks/ssr/{_1es2j7i._.js → _1gb0ifp._.js} +5 -5
- package/.next/standalone/.next/server/chunks/ssr/{_1_qswah._.js → _1q46vxx._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/{_0h_douw._.js → _1w_5l7t._.js} +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_1zopuov._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/{_17o744m._.js → _214wgrp._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/_next-internal_server_app_policies_page_actions_1sp2-yo.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/app_actions_get-scheduled-audit_ts_0ei9sni._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/app_audit__components_audit-dashboard_tsx_0p9ud47._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_global-error_tsx_1kp6l3x._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_policies_hooks-client_tsx_19dqvpc._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/app_settings_02tf1h4._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/lib_utils_ts_0az0sfq._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/{node_modules_next_dist_0drixxt._.js → node_modules_next_dist_0w6mzq5._.js} +4 -4
- package/.next/standalone/.next/server/chunks/ssr/node_modules_next_dist_18_d8l1._.js +151 -0
- package/.next/standalone/.next/server/chunks/ssr/node_modules_posthog-node_dist_entrypoints_index_node_mjs_11bnuzn._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_095a_79._.js +5 -0
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_15t8kqj._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_18k8rl0._.js +12 -0
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_1fm2w5z._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_1j0zy3v._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_builtin-policies_ts_09j2ndl._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_fp-home_ts_0je3xkv._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_pack-cli_ts_0t7me65._.js +1 -1
- package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
- package/.next/standalone/.next/server/pages/404.html +1 -1
- package/.next/standalone/.next/server/pages/500.html +1 -1
- package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/server-reference-manifest.json +56 -23
- package/.next/standalone/.next/static/chunks/0cd-_8-c-m1ea.js +6 -0
- package/.next/standalone/.next/static/chunks/{40-wncjnguy4e.js → 0qrbdkv9qmvli.js} +1 -1
- package/.next/standalone/.next/static/chunks/{3-6zhytp6adkk.js → 0uldbut9y2-e8.js} +1 -1
- package/.next/standalone/.next/static/chunks/{2y4ycwcwfjv4k.js → 0vmd180qfntfb.js} +1 -1
- package/.next/standalone/.next/static/chunks/{25m8mg7bosgip.js → 12tvm75t5ffui.js} +1 -1
- package/.next/standalone/.next/static/chunks/1u5zsejmgrir_.js +1 -0
- package/.next/standalone/.next/static/chunks/258668t68du6b.js +1 -0
- package/.next/standalone/.next/static/chunks/285spx855h_3r.css +2 -0
- package/.next/standalone/.next/static/chunks/{35pw7zxhh76n7.js → 29fql3nbnfc9q.js} +1 -1
- package/.next/standalone/.next/static/chunks/2qv4hshejedtx.css +1 -0
- package/.next/standalone/.next/static/chunks/{0bepqeawy72n6.js → 2vkvu9-opa_1z.js} +1 -1
- package/.next/standalone/.next/static/chunks/34jpdb2xjm-x7.js +1 -0
- package/.next/standalone/.next/static/chunks/37lhv7wa3ywt6.js +1 -0
- package/.next/standalone/app/actions/get-jev-config.ts +409 -0
- package/.next/standalone/app/actions/pack-actions.ts +12 -0
- package/.next/standalone/app/actions/update-jev-config.ts +420 -0
- package/.next/standalone/app/components/jev-notices.tsx +96 -0
- package/.next/standalone/app/policies/hooks-client.tsx +9 -0
- package/.next/standalone/app/settings/jev-panel.tsx +469 -0
- package/.next/standalone/app/settings/page.tsx +20 -1
- package/.next/standalone/app/settings/settings-client.tsx +27 -1
- package/.next/standalone/app/settings/settings.css +79 -0
- package/.next/standalone/fp-cloud-cli/CHANGELOG.md +51 -3
- package/.next/standalone/fp-cloud-cli/README.md +1 -1
- package/.next/standalone/fp-cloud-cli/fp_cli/_version.py +1 -1
- package/.next/standalone/fp-cloud-cli/fp_cli/client.py +44 -0
- package/.next/standalone/fp-cloud-cli/fp_cli/commands/incidents_cmds.py +226 -5
- package/.next/standalone/fp-cloud-cli/fp_cli/models.py +11 -0
- package/.next/standalone/fp-cloud-cli/fp_cli/output.py +68 -1
- package/.next/standalone/fp-cloud-cli/pyproject.toml +1 -1
- package/.next/standalone/fp-cloud-cli/skill/SKILL.md +17 -2
- package/.next/standalone/fp-cloud-cli/skill/references/commands.md +7 -4
- package/.next/standalone/fp-cloud-cli/tests/test_alerting.py +184 -0
- package/.next/standalone/fp-cloud-cli/uv.lock +3 -3
- package/.next/standalone/package.json +11 -11
- package/.next/standalone/sdk/python/CHANGELOG.md +7 -0
- package/.next/standalone/sdk/python/failproofai_sdk/_version.py +1 -1
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/__init__.py +2 -0
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/authoring.py +24 -1
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/runtime.py +41 -6
- package/.next/standalone/sdk/python/tests/test_evaluator_runtime.py +88 -0
- package/.next/standalone/sdk/python/uv.lock +15 -15
- package/.next/standalone/server.js +1 -1
- package/bin/failproofai.mjs +115 -2
- package/dist/cli.mjs +9299 -2151
- package/dist/index.js +19 -1
- package/dist/worker.mjs +13761 -7834
- package/package.json +11 -11
- package/pi-extension/index.ts +11 -0
- package/scripts/build-policy-pack.mjs +39 -2
- package/src/hooks/builtin-policies.ts +21 -3
- package/src/hooks/cloud-enrollment-cli.ts +1 -1
- package/src/hooks/cloud-managed-policies.ts +22 -0
- package/src/hooks/custom-hooks-loader.ts +45 -7
- package/src/hooks/custom-hooks-registry.ts +45 -1
- package/src/hooks/effective-reviewers.ts +79 -0
- package/src/hooks/first-run-gate.ts +5 -0
- package/src/hooks/fp-home.ts +23 -0
- package/src/hooks/handler.ts +265 -6
- package/src/hooks/hook-activity-store.ts +105 -1
- package/src/hooks/hook-telemetry.ts +41 -0
- package/src/hooks/jev-activity.ts +385 -0
- package/src/hooks/jev-cli.ts +1193 -0
- package/src/hooks/loader-utils.ts +6 -0
- package/src/hooks/pack-cli.ts +278 -17
- package/src/hooks/pack-manifest.ts +479 -7
- package/src/hooks/pack-store.ts +156 -10
- package/src/hooks/policy-authority.ts +333 -0
- package/src/hooks/policy-catalog.ts +65 -0
- package/src/hooks/policy-evaluator.ts +940 -796
- package/src/hooks/policy-registry.ts +25 -0
- package/src/hooks/policy-reviewability.ts +229 -0
- package/src/hooks/policy-types.ts +126 -0
- package/src/hooks/semantic/combine.ts +541 -0
- package/src/hooks/semantic/compile.ts +176 -0
- package/src/hooks/semantic/decide.ts +392 -0
- package/src/hooks/semantic/envelope.ts +1296 -0
- package/src/hooks/semantic/evaluator.ts +547 -0
- package/src/hooks/semantic/facts.ts +292 -0
- package/src/hooks/semantic/intent.ts +1190 -0
- package/src/hooks/semantic/jev-client.ts +643 -0
- package/src/hooks/semantic/jev-config.ts +594 -0
- package/src/hooks/semantic/jev-review.ts +374 -0
- package/src/hooks/semantic/jev-stats.ts +289 -0
- package/src/hooks/semantic/jev-throttle.ts +421 -0
- package/src/hooks/semantic/pack-policies.ts +251 -0
- package/src/hooks/semantic/policies.ts +596 -0
- package/src/hooks/semantic/precondition-names.ts +60 -0
- package/src/hooks/semantic/preconditions.ts +58 -0
- package/src/hooks/semantic/redact.ts +2910 -0
- package/src/hooks/semantic/types.ts +145 -0
- package/src/hooks/semver-precedence.ts +128 -0
- package/src/hooks/worker-server.ts +119 -26
- package/src/index.ts +6 -0
- package/.next/standalone/.next/server/chunks/src_hooks_0iu54mz._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0-_ki57._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__013jr2b._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__01wy8d-._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__02npjtd._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0cg-bgc._.js +0 -5
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0cpu_mj._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0da85px._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0ftmoxc._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0p-5p8u._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0u3w0ll._.js +0 -22
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__17d_ffl._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__19d9tgz._.js +0 -5
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1ctpynv._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1jiwfsj._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1p2otjt._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1phc187._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/_06imw3p._.js +0 -5
- package/.next/standalone/.next/server/chunks/ssr/_1u8-lu2._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/app_settings_settings-client_tsx_20lq-mq._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_1cv9_c4._.js +0 -10
- package/.next/standalone/.next/static/chunks/0h-gz8e00478q.js +0 -1
- package/.next/standalone/.next/static/chunks/0qmsunv04x4na.css +0 -2
- package/.next/standalone/.next/static/chunks/2k9f4tyv04809.css +0 -1
- package/.next/standalone/.next/static/chunks/2lvr2pt70qn14.js +0 -1
- package/.next/standalone/.next/static/chunks/319c_91le7-h_.js +0 -1
- package/.next/standalone/.next/static/chunks/35m53kix7uaii.js +0 -6
- package/.next/standalone/.next/static/chunks/3xacd7qmuqlvs.js +0 -1
- /package/.next/standalone/.next/static/{LzR_etPlaZV9JZH09lEp3 → T8YAYM9h_64fKv705vug7}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{LzR_etPlaZV9JZH09lEp3 → T8YAYM9h_64fKv705vug7}/_clientMiddlewareManifest.js +0 -0
- /package/.next/standalone/.next/static/{LzR_etPlaZV9JZH09lEp3 → T8YAYM9h_64fKv705vug7}/_ssgManifest.js +0 -0
package/src/hooks/handler.ts
CHANGED
|
@@ -24,18 +24,26 @@ import {
|
|
|
24
24
|
OPENCLAW_EVENT_MAP,
|
|
25
25
|
ANTIGRAVITY_EVENT_MAP,
|
|
26
26
|
} from "./types";
|
|
27
|
+
import { existsSync } from "node:fs";
|
|
27
28
|
import { canonicalizeToolName, canonicalizeToolInput } from "./tool-name-canonicalize";
|
|
28
29
|
import { normalizeCliPayload } from "./normalize-cli-payload";
|
|
29
30
|
import type { PolicyFunction, PolicyResult, HooksConfig } from "./policy-types";
|
|
30
31
|
import { readMergedHooksConfig } from "./hooks-config";
|
|
31
32
|
import { registerBuiltinPolicies } from "./builtin-policies";
|
|
32
33
|
import { evaluatePolicies } from "./policy-evaluator";
|
|
34
|
+
// Types only: the semantic (Jev) modules are loaded with a dynamic import, and
|
|
35
|
+
// only once a Jev config exists, so an unconfigured machine never loads them.
|
|
36
|
+
import type { TwoTierReview } from "./semantic/combine";
|
|
37
|
+
import type { JevActivityFields } from "./semantic/combine";
|
|
38
|
+
import type { JevConfig } from "./semantic/jev-config";
|
|
33
39
|
import { clearPolicies, registerPolicy, getPoliciesForEvent } from "./policy-registry";
|
|
34
40
|
import { loadAllCustomHooks } from "./custom-hooks-loader";
|
|
41
|
+
import { authorityDeclarationFor, resolvePolicyAuthority, warnAuthority } from "./policy-authority";
|
|
35
42
|
import type { CustomHook } from "./policy-types";
|
|
36
43
|
import { persistHookActivity } from "./hook-activity-store";
|
|
37
44
|
import { deliveryHealth, deliveryHealthLine } from "./delivery-health";
|
|
38
45
|
import { trackHookEvent, flushHookTelemetry } from "./hook-telemetry";
|
|
46
|
+
import * as hookTelemetry from "./hook-telemetry";
|
|
39
47
|
import { resolveCwd } from "./resolve-cwd";
|
|
40
48
|
import { resolvePermissionMode } from "./resolve-permission-mode";
|
|
41
49
|
import { resolveTranscriptPath } from "./resolve-transcript-path";
|
|
@@ -46,6 +54,7 @@ import { readActiveCloudManagedPolicies, type CloudManagedPolicyArtifact } from
|
|
|
46
54
|
import { hasInstalledPacks, readInstalledPacks, type PackError, type ResolvedPack } from "./pack-manifest";
|
|
47
55
|
import { missingGuards, packFailureReason, combinedGuardMatch, guardsCover } from "./pack-failclosed";
|
|
48
56
|
import { readActivePause, type ActivePause } from "./session-pause";
|
|
57
|
+
import { jevConfigFile } from "./fp-home";
|
|
49
58
|
import { layoutWarningForHook } from "./fp-reset";
|
|
50
59
|
|
|
51
60
|
/**
|
|
@@ -153,6 +162,16 @@ export interface EvaluateHookEventOptions {
|
|
|
153
162
|
* written for.
|
|
154
163
|
*/
|
|
155
164
|
fallbackCwd?: string;
|
|
165
|
+
/**
|
|
166
|
+
* The warm worker's hook into its request queue. Called at most once, and
|
|
167
|
+
* only on the two-tier path, at the point this evaluation stops reading the
|
|
168
|
+
* process-global policy registry and starts waiting on Jev's network answer
|
|
169
|
+
* — so the next queued hook can run instead of every hook on the machine
|
|
170
|
+
* queueing behind that round trip. After it is called nothing in this
|
|
171
|
+
* evaluation reads the registry again. The one-shot path has no queue and
|
|
172
|
+
* leaves it unset.
|
|
173
|
+
*/
|
|
174
|
+
releaseRegistry?: () => void;
|
|
156
175
|
}
|
|
157
176
|
|
|
158
177
|
/**
|
|
@@ -186,6 +205,211 @@ async function runObserved(
|
|
|
186
205
|
}
|
|
187
206
|
}
|
|
188
207
|
|
|
208
|
+
// ── Two-tier (Jev) opt-in ────────────────────────────────────────────────────
|
|
209
|
+
//
|
|
210
|
+
// Jev reviews a call only when ALL of these hold, and the regex engine runs
|
|
211
|
+
// alone — exactly as it did before two tiers existed — otherwise:
|
|
212
|
+
//
|
|
213
|
+
// - a valid BYOK config exists (`~/.failproofai/jev.json`, global only);
|
|
214
|
+
// - `FAILPROOFAI_EVALUATOR` is not `legacy` (see "Turning Jev off" below);
|
|
215
|
+
// - this is not the fail-closed `forceDecision` path and no session pause is
|
|
216
|
+
// active — a pause suspends local policy, and Jev must not become a way to
|
|
217
|
+
// evaluate what the pause switched off;
|
|
218
|
+
// - the event is a gate (`PreToolUse` / `PermissionRequest`) for a named tool
|
|
219
|
+
// that the AGENT requested (see `isHumanAuthoredGate`).
|
|
220
|
+
//
|
|
221
|
+
// There is no cloud-deployment exclusion: cloud policies default to `hard`, so
|
|
222
|
+
// Jev can only make a centrally managed machine stricter, never weaker.
|
|
223
|
+
//
|
|
224
|
+
// Turning Jev off. The switch that works everywhere is the config file itself:
|
|
225
|
+
// it is read on every event, here, in whichever process evaluates — the
|
|
226
|
+
// daemon's warm worker included — so `failproofai jev remove` (or a `mode:
|
|
227
|
+
// "shadow"` config, which keeps enforcing the regex result) applies from the
|
|
228
|
+
// next tool call, with no restart. `FAILPROOFAI_EVALUATOR=legacy` is the dev
|
|
229
|
+
// escape hatch, read from the EVALUATING process's environment: it covers a
|
|
230
|
+
// one-shot hook (no daemon) and a worker whose own environment sets it, but
|
|
231
|
+
// not a variable exported in a shell on a daemon machine — the daemon
|
|
232
|
+
// forwards a hook's event, cli, stdin and cwd to the worker, never the hook
|
|
233
|
+
// process's environment. `failproofai jev status` says so when it sees the
|
|
234
|
+
// variable. A per-session switch for daemon machines would be a new field in
|
|
235
|
+
// the daemon protocol; there is none today.
|
|
236
|
+
|
|
237
|
+
/** The two gate events Jev reviews. Everything else is regex-only. */
|
|
238
|
+
const JEV_GATE_EVENTS: ReadonlySet<string> = new Set(["PreToolUse", "PermissionRequest"]);
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* A gate event that carries a command the HUMAN typed, not one the agent
|
|
242
|
+
* requested: Pi's `user_bash` (`!cmd` at Pi's prompt) canonicalizes to
|
|
243
|
+
* `PreToolUse` like an agent's `tool_call`. Jev judges an agent's request
|
|
244
|
+
* against what the human asked for, and says so to the model ("A coding agent
|
|
245
|
+
* has REQUESTED the tool call"); the human's own command is the human asking,
|
|
246
|
+
* and never appears in `user_said`, so Jev would judge it as an unrequested
|
|
247
|
+
* agent action and could block the human's own command. The regex policies
|
|
248
|
+
* still run on it exactly as they always have.
|
|
249
|
+
*/
|
|
250
|
+
function isHumanAuthoredGate(rawEventType: string | undefined, cli: IntegrationType): boolean {
|
|
251
|
+
return cli === "pi" && rawEventType === "user_bash";
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function jevForcedOff(opts: EvaluateHookEventOptions | undefined): boolean {
|
|
255
|
+
return process.env.FAILPROOFAI_EVALUATOR === "legacy" || !!opts?.forceDecision;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* The BYOK config (with the build's default mode, D2), or null (Jev off). A
|
|
260
|
+
* config that cannot be read is off, never a failure. Logged at info, like
|
|
261
|
+
* every configured-but-broken Jev path: warn-level lines reach the hook's
|
|
262
|
+
* stderr, which is the deny text itself on some CLIs (Factory's exit 2).
|
|
263
|
+
* `failproofai jev status` is where a broken config is made visible.
|
|
264
|
+
*
|
|
265
|
+
* The file is checked for BEFORE the import, and that order is the point. With
|
|
266
|
+
* no `jev.json` the answer is null however the module would have read it — so
|
|
267
|
+
* the stat decides it, and a machine that never configured Jev never evaluates
|
|
268
|
+
* a line of the semantic modules to be told what their absence already says.
|
|
269
|
+
* The same stat-rather-than-load trade `warnAuthority` makes, for the same
|
|
270
|
+
* reason. It short-circuits nothing but a null `loadJevConfig` would have
|
|
271
|
+
* returned itself: that function reads this path, and an absent file, an
|
|
272
|
+
* unreadable directory above it and a path that is not a file are all null
|
|
273
|
+
* there too.
|
|
274
|
+
*/
|
|
275
|
+
async function readJevConfig(): Promise<{ config: JevConfig; defaultMode: TwoTierReview["mode"] } | null> {
|
|
276
|
+
try {
|
|
277
|
+
if (!existsSync(jevConfigFile())) return null;
|
|
278
|
+
const { loadJevConfig, DEFAULT_JEV_MODE } = await import("./semantic/jev-config");
|
|
279
|
+
const config = loadJevConfig();
|
|
280
|
+
return config ? { config, defaultMode: DEFAULT_JEV_MODE } : null;
|
|
281
|
+
} catch (err) {
|
|
282
|
+
hookLogInfo(
|
|
283
|
+
`Jev config could not be read (${err instanceof Error ? err.message : String(err)}); the regex engine decides alone`,
|
|
284
|
+
);
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Start Jev's review of this call — before the regex policies run, so the two
|
|
291
|
+
* proceed in parallel — or return null for the regex-only path.
|
|
292
|
+
*/
|
|
293
|
+
async function startTwoTier(
|
|
294
|
+
canonicalEventType: string,
|
|
295
|
+
parsed: Record<string, unknown>,
|
|
296
|
+
session: SessionMetadata,
|
|
297
|
+
cli: IntegrationType,
|
|
298
|
+
opts: EvaluateHookEventOptions | undefined,
|
|
299
|
+
activePause: ActivePause | null,
|
|
300
|
+
): Promise<TwoTierReview | null> {
|
|
301
|
+
if (!JEV_GATE_EVENTS.has(canonicalEventType)) return null;
|
|
302
|
+
if (isHumanAuthoredGate(session.rawHookEventName, cli)) return null;
|
|
303
|
+
if (typeof parsed.tool_name !== "string" || parsed.tool_name.length === 0) return null;
|
|
304
|
+
if (jevForcedOff(opts) || activePause) return null;
|
|
305
|
+
const loaded = await readJevConfig();
|
|
306
|
+
if (!loaded) return null;
|
|
307
|
+
const cfg = loaded.config;
|
|
308
|
+
try {
|
|
309
|
+
const { startJevReview } = await import("./semantic/jev-review");
|
|
310
|
+
return startJevReview(cfg, {
|
|
311
|
+
eventType: canonicalEventType,
|
|
312
|
+
toolName: parsed.tool_name,
|
|
313
|
+
toolInput: parsed.tool_input,
|
|
314
|
+
cwd: session.cwd,
|
|
315
|
+
permissionMode: session.permissionMode,
|
|
316
|
+
sessionId: session.sessionId,
|
|
317
|
+
cli,
|
|
318
|
+
});
|
|
319
|
+
} catch (err) {
|
|
320
|
+
// Configured but unable to start: that is a fallback, and it is recorded
|
|
321
|
+
// as one — every regex verdict hard, the regex result final. Recorded as
|
|
322
|
+
// `error`, one of the reason codes the activity store and the collector
|
|
323
|
+
// know (T8's closed list); an unknown code would ship as `other`. Logged
|
|
324
|
+
// at info, off the hook's stderr (see `readJevConfig`); the activity row
|
|
325
|
+
// carries the fallback.
|
|
326
|
+
hookLogInfo(`Jev review could not start (${err instanceof Error ? err.message : String(err)})`);
|
|
327
|
+
return {
|
|
328
|
+
mode: cfg.mode === "shadow" || cfg.mode === "enforce" ? cfg.mode : loaded.defaultMode,
|
|
329
|
+
review: Promise.resolve({ kind: "fallback", reason: "error", latencyMs: null, model: null }),
|
|
330
|
+
abort: () => {},
|
|
331
|
+
authorityOf: () => ({ authority: "hard", reviewedBy: [] }),
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* The Jev properties for `hook_policy_triggered`, from T8's
|
|
338
|
+
* `jevTelemetryProperties` (decisions, reason codes, policy and model names,
|
|
339
|
+
* a latency — never command or prompt text). `{}` when the two-tier path did
|
|
340
|
+
* not run, so an unconfigured machine's event is unchanged, and `{}` when the
|
|
341
|
+
* helper is not in this build (it is T8's, not a §7 contract) or throws:
|
|
342
|
+
* telemetry never costs a hook its answer.
|
|
343
|
+
*
|
|
344
|
+
* Only its `jev_`-prefixed keys are kept. These are spread into an event whose
|
|
345
|
+
* core properties (`decision`, `policy_name`, `event_type`, …) are what the
|
|
346
|
+
* rollout is read from, and a helper owned by another task must not be able to
|
|
347
|
+
* overwrite one of them — silently, and only on two-tier machines — by
|
|
348
|
+
* emitting a key of that name. The helper is treated as untrusted in every
|
|
349
|
+
* other respect (absent, non-object, throwing); this is the same guard for
|
|
350
|
+
* what it returns.
|
|
351
|
+
*/
|
|
352
|
+
function jevTelemetry(activity: JevActivityFields | undefined): Record<string, unknown> {
|
|
353
|
+
if (!activity) return {};
|
|
354
|
+
try {
|
|
355
|
+
const build = (hookTelemetry as unknown as { jevTelemetryProperties?: (entry: JevActivityFields) => unknown })
|
|
356
|
+
.jevTelemetryProperties;
|
|
357
|
+
const props = typeof build === "function" ? build(activity) : null;
|
|
358
|
+
if (!props || typeof props !== "object" || Array.isArray(props)) return {};
|
|
359
|
+
return Object.fromEntries(Object.entries(props as Record<string, unknown>).filter(([key]) => key.startsWith("jev_")));
|
|
360
|
+
} catch {
|
|
361
|
+
return {};
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Record what the human just typed, for Jev to judge later calls against.
|
|
367
|
+
* Only when Jev is configured. Every canonical `UserPromptSubmit` is passed,
|
|
368
|
+
* except a prompt a policy denied on a CLI where that deny is known to hold
|
|
369
|
+
* (`ENFORCEMENT_CAPABILITY` says `block`): the agent never receives that
|
|
370
|
+
* prompt, so it cannot be what the agent is working on. Where a prompt deny
|
|
371
|
+
* is only observed — Goose, OpenCode, Antigravity — or not verified, the
|
|
372
|
+
* agent does get the prompt, and it is passed like any other. Which CLIs'
|
|
373
|
+
* prompt events count as human is decided inside `captureIntent` (T4).
|
|
374
|
+
* Never throws; a failure is logged at info (see `readJevConfig`).
|
|
375
|
+
*
|
|
376
|
+
* `captureIntent` gets the whole normalized payload (`payload`): the prompt
|
|
377
|
+
* text is in a different field on some harnesses (Goose: `message`), and the
|
|
378
|
+
* marks that tell a human's prompt from a subagent's or an extension's are
|
|
379
|
+
* elsewhere in it. `prompt` is §7's original field, still read by the
|
|
380
|
+
* contract stub; T4's implementation reads `payload` and ignores it.
|
|
381
|
+
*/
|
|
382
|
+
async function captureJevIntent(
|
|
383
|
+
canonicalEventType: string,
|
|
384
|
+
decision: "allow" | "deny" | "instruct",
|
|
385
|
+
parsed: Record<string, unknown>,
|
|
386
|
+
session: SessionMetadata,
|
|
387
|
+
cli: IntegrationType,
|
|
388
|
+
opts: EvaluateHookEventOptions | undefined,
|
|
389
|
+
): Promise<void> {
|
|
390
|
+
if (canonicalEventType !== "UserPromptSubmit" || jevForcedOff(opts)) return;
|
|
391
|
+
try {
|
|
392
|
+
if (!(await readJevConfig())) return;
|
|
393
|
+
if (decision === "deny") {
|
|
394
|
+
const { ENFORCEMENT_CAPABILITY } = await import("./enforcement-capability");
|
|
395
|
+
if (ENFORCEMENT_CAPABILITY[cli]?.UserPromptSubmit === "block") return;
|
|
396
|
+
}
|
|
397
|
+
const { captureIntent } = await import("./semantic/intent");
|
|
398
|
+
// Built first, then passed: the one object satisfies §7's shape and T4's.
|
|
399
|
+
const event = {
|
|
400
|
+
eventType: canonicalEventType,
|
|
401
|
+
sessionId: session.sessionId,
|
|
402
|
+
transcriptPath: session.transcriptPath,
|
|
403
|
+
cli,
|
|
404
|
+
payload: parsed,
|
|
405
|
+
prompt: parsed.prompt,
|
|
406
|
+
};
|
|
407
|
+
captureIntent(event);
|
|
408
|
+
} catch (err) {
|
|
409
|
+
hookLogInfo(`Jev intent capture failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
189
413
|
/**
|
|
190
414
|
* The core hook-evaluation logic, decoupled from process stdin/stdout so it
|
|
191
415
|
* can be called repeatedly inside a long-lived process (the daemon's warm
|
|
@@ -561,6 +785,14 @@ export async function evaluateHookEvent(
|
|
|
561
785
|
...(cloudManaged ? { cloudPolicyId: cloudManaged.id, cloudVersion: cloudManaged.version } : {}),
|
|
562
786
|
...(pack ? { packId: pack.id, packVersion: pack.version } : {}),
|
|
563
787
|
});
|
|
788
|
+
// Whether Jev may clear this policy's verdict. The cloud assignment or
|
|
789
|
+
// the pack manifest declares it for those routes, the hook itself only
|
|
790
|
+
// for the user's own files; anything unclear registers as hard. Said
|
|
791
|
+
// aloud when a `reviewable` claim is refused and Jev is configured, so
|
|
792
|
+
// an author is not left wondering why Jev never clears it.
|
|
793
|
+
const authority = authorityDeclarationFor(hook, { cloudManaged, pack });
|
|
794
|
+
const refused = resolvePolicyAuthority(authority).downgraded;
|
|
795
|
+
if (refused) warnAuthority(`${registeredName} asks to be reviewable, but ${refused} — it stays hard`);
|
|
564
796
|
registerPolicy(
|
|
565
797
|
registeredName,
|
|
566
798
|
hook.description ?? "",
|
|
@@ -572,6 +804,7 @@ export async function evaluateHookEvent(
|
|
|
572
804
|
// configured. Matched by the pack's own name for the policy, which is
|
|
573
805
|
// the name before the `pack/<id>@<version>/` prefix is applied.
|
|
574
806
|
pack?.policies.find((p) => p.name === hook.name)?.params,
|
|
807
|
+
authority,
|
|
575
808
|
);
|
|
576
809
|
}
|
|
577
810
|
|
|
@@ -660,19 +893,40 @@ export async function evaluateHookEvent(
|
|
|
660
893
|
);
|
|
661
894
|
}
|
|
662
895
|
|
|
896
|
+
// Two-tier: when a Jev config exists and this is a gate, Jev's request
|
|
897
|
+
// starts HERE, before any regex policy runs, and evaluatePolicies combines
|
|
898
|
+
// the two (see semantic/combine.ts). Otherwise this is null and the call
|
|
899
|
+
// below is exactly the regex-only evaluation it always was.
|
|
900
|
+
const twoTier = await startTwoTier(canonicalEventType, parsed, session, cli, opts, activePause);
|
|
901
|
+
// On the two-tier path the registry is read for the activity row BEFORE
|
|
902
|
+
// evaluating, because evaluatePolicies may hand the registry back to the
|
|
903
|
+
// warm worker's queue (`releaseRegistry`) while it waits on Jev, and the
|
|
904
|
+
// next request's clearPolicies() could then run under this one. Same
|
|
905
|
+
// cached lookup, same answer: nothing between here and there registers.
|
|
906
|
+
const matchedBeforeRelease = twoTier
|
|
907
|
+
? getPoliciesForEvent(canonicalEventType, parsed.tool_name as string | undefined).map((p) => p.name)
|
|
908
|
+
: null;
|
|
909
|
+
|
|
663
910
|
// Evaluate policies (use canonical PascalCase event type)
|
|
664
|
-
const result =
|
|
911
|
+
const result = twoTier
|
|
912
|
+
? await evaluatePolicies(canonicalEventType, parsed, session, config, {
|
|
913
|
+
...twoTier,
|
|
914
|
+
releaseRegistry: opts?.releaseRegistry,
|
|
915
|
+
})
|
|
916
|
+
: await evaluatePolicies(canonicalEventType, parsed, session, config);
|
|
665
917
|
const durationMs = Math.round(performance.now() - startTime);
|
|
666
918
|
hookLogInfo(`result=${result.decision} policy=${result.policyName ?? "none"} duration=${durationMs}ms`);
|
|
667
919
|
|
|
920
|
+
await captureJevIntent(canonicalEventType, result.decision, parsed, session, cli, opts);
|
|
921
|
+
|
|
668
922
|
// Which policies actually ran for this event, regardless of how they
|
|
669
923
|
// decided. `result.policyName` names only the decider — null on a plain
|
|
670
924
|
// allow — so without this a row cannot tell "your policy ran and allowed"
|
|
671
925
|
// from "no policy covers this event". The lookup is the same cached call
|
|
672
926
|
// the evaluator already made, so it costs nothing.
|
|
673
|
-
const matchedPolicies =
|
|
674
|
-
|
|
675
|
-
|
|
927
|
+
const matchedPolicies =
|
|
928
|
+
matchedBeforeRelease ??
|
|
929
|
+
getPoliciesForEvent(canonicalEventType, parsed.tool_name as string | undefined).map((p) => p.name);
|
|
676
930
|
|
|
677
931
|
// Persist activity to disk (visible in /policies activity tab)
|
|
678
932
|
const activityEntry = {
|
|
@@ -686,6 +940,8 @@ export async function evaluateHookEvent(
|
|
|
686
940
|
decision: result.decision,
|
|
687
941
|
reason: result.reason,
|
|
688
942
|
durationMs,
|
|
943
|
+
// How Jev took part (§7 fields). Absent unless the two-tier path ran.
|
|
944
|
+
...(result.twoTier ? result.twoTier.activity : {}),
|
|
689
945
|
sessionId: session.sessionId,
|
|
690
946
|
transcriptPath: session.transcriptPath,
|
|
691
947
|
cwd: session.cwd,
|
|
@@ -693,8 +949,10 @@ export async function evaluateHookEvent(
|
|
|
693
949
|
hookEventName: session.hookEventName,
|
|
694
950
|
// Attribution. A builtin is anything registered that is not in the map,
|
|
695
951
|
// so its absence is meaningful rather than missing — but only when a
|
|
696
|
-
// policy actually decided; a plain allow names nobody.
|
|
697
|
-
|
|
952
|
+
// policy actually decided; a plain allow names nobody. When Jev's own
|
|
953
|
+
// verdict decided, no registered policy did: `evaluator` + `jevDecision`
|
|
954
|
+
// say so, and claiming "builtin" here would be false.
|
|
955
|
+
...(result.policyName && !result.twoTier?.decidedByJev
|
|
698
956
|
? (() => {
|
|
699
957
|
const attribution = policyAttribution.get(result.policyName);
|
|
700
958
|
return {
|
|
@@ -751,6 +1009,7 @@ export async function evaluateHookEvent(
|
|
|
751
1009
|
convention_scope: conventionScope,
|
|
752
1010
|
has_custom_params: hasCustomParams,
|
|
753
1011
|
param_keys_overridden: paramKeysOverridden,
|
|
1012
|
+
...jevTelemetry(result.twoTier?.activity),
|
|
754
1013
|
});
|
|
755
1014
|
// Deny/instruct is exactly the response the daemon's warm worker
|
|
756
1015
|
// needs to return fast — a live network POST to PostHog on this path
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
import { join } from "node:path";
|
|
25
25
|
import type { IntegrationType } from "./types";
|
|
26
26
|
import { hookActivityDir } from "./fp-home";
|
|
27
|
+
import { sanitizeJevActivity } from "./jev-activity";
|
|
27
28
|
|
|
28
29
|
export const PAGE_SIZE = 25;
|
|
29
30
|
|
|
@@ -76,6 +77,36 @@ export interface HookActivityEntry {
|
|
|
76
77
|
matchedPolicies?: string[];
|
|
77
78
|
decision: "allow" | "deny" | "instruct";
|
|
78
79
|
reason: string | null;
|
|
80
|
+
/**
|
|
81
|
+
* The Jev (two-tier) fields. Present only when a Jev config (BYOK) exists and
|
|
82
|
+
* the call was a PreToolUse / PermissionRequest gate. Absent means the regex
|
|
83
|
+
* engine decided alone, exactly as before these fields existed.
|
|
84
|
+
*
|
|
85
|
+
* `evaluator`: `jev` (the two-tier path ran) or `jev-fallback` (Jev was
|
|
86
|
+
* unavailable, truncated or mismatched, so the regex result stood;
|
|
87
|
+
* `jevFallbackReason` says why). `jev` alone does NOT mean Jev answered:
|
|
88
|
+
* when a hard policy denies, Jev is aborted and the row carries
|
|
89
|
+
* `{ evaluator: "jev", jevMode }` and no other Jev field; when no semantic
|
|
90
|
+
* policy applies to the call, no request is sent and the row carries
|
|
91
|
+
* `{ evaluator: "jev", jevDecision: "allow", jevMode }`. Read a row with
|
|
92
|
+
* `jevOutcome` (`jev-activity.ts`): answered, fallback, not-consulted or
|
|
93
|
+
* no-request.
|
|
94
|
+
*
|
|
95
|
+
* Validated on write by `persistHookActivity` (see `jev-activity.ts`): an
|
|
96
|
+
* invalid value is dropped field by field, and `jevFallbackReason` is stored
|
|
97
|
+
* as a known code (`timeout`, `http-429`, `error`, …) or `other`, never free
|
|
98
|
+
* text. The collector ships these fields to FailproofAI Cloud.
|
|
99
|
+
*/
|
|
100
|
+
evaluator?: "jev" | "jev-fallback";
|
|
101
|
+
/** Jev's own verdict, before combining with the regex results. */
|
|
102
|
+
jevDecision?: "allow" | "instruct" | "deny";
|
|
103
|
+
/** Reviewable policies whose deny/instruct Jev cleared. */
|
|
104
|
+
jevCleared?: string[];
|
|
105
|
+
jevFallbackReason?: string;
|
|
106
|
+
jevLatencyMs?: number;
|
|
107
|
+
jevModel?: string;
|
|
108
|
+
/** `shadow` logs Jev but enforces the regex result; `enforce` applies the combine rules. */
|
|
109
|
+
jevMode?: "shadow" | "enforce";
|
|
79
110
|
durationMs: number;
|
|
80
111
|
sessionId?: string;
|
|
81
112
|
transcriptPath?: string;
|
|
@@ -194,7 +225,13 @@ function releaseLock(): void {
|
|
|
194
225
|
|
|
195
226
|
// ── Writing (synchronous — hook handler is short-lived) ──
|
|
196
227
|
|
|
197
|
-
export function persistHookActivity(
|
|
228
|
+
export function persistHookActivity(input: HookActivityEntry): void {
|
|
229
|
+
// The Jev fields are validated here, at the one door every row passes
|
|
230
|
+
// through, rather than trusted from the caller: they are shipped off the
|
|
231
|
+
// machine by the collector, and a fallback reason is the one field that can
|
|
232
|
+
// carry free text (see jev-activity.ts). A row with no Jev fields is written
|
|
233
|
+
// exactly as given.
|
|
234
|
+
const entry = sanitizeJevActivity(input);
|
|
198
235
|
ensureDir();
|
|
199
236
|
acquireLock();
|
|
200
237
|
try {
|
|
@@ -397,6 +434,72 @@ export function getAllHookActivityEntries(): HookActivityEntry[] {
|
|
|
397
434
|
return [...currentEntries, ...archiveEntries];
|
|
398
435
|
}
|
|
399
436
|
|
|
437
|
+
/** See {@link getHookActivityEntriesSince}. */
|
|
438
|
+
export const ROTATION_CLOCK_SLACK_MS = 10 * 60 * 1000;
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Every entry stamped at or after `sinceMs`, newest first — without reading the
|
|
442
|
+
* whole history.
|
|
443
|
+
*
|
|
444
|
+
* Pages are never pruned, so a long-lived machine has hundreds of them, and a
|
|
445
|
+
* windowed question ("how did Jev do in the last day") should not pay for all
|
|
446
|
+
* of them. It does not have to: an entry's timestamp is taken before it is
|
|
447
|
+
* appended, and a page is only renamed to `page-<rotatedAt>-<seq>` after its
|
|
448
|
+
* last append, so every entry in a page is at or before `rotatedAt`. Archives
|
|
449
|
+
* are listed newest first, so once one was rotated before the window opened,
|
|
450
|
+
* it and every older page lie wholly outside it and reading stops there.
|
|
451
|
+
*
|
|
452
|
+
* `current.jsonl` and the newest pages can still hold entries just outside the
|
|
453
|
+
* window (two hook processes race to append), hence the per-entry filter.
|
|
454
|
+
* The stop is taken with {@link ROTATION_CLOCK_SLACK_MS} to spare, so a clock
|
|
455
|
+
* stepped back a few minutes between two writes costs one extra page read
|
|
456
|
+
* rather than silently dropping rows from the window.
|
|
457
|
+
*
|
|
458
|
+
* No row is returned twice, although this reads without the writers' lock. A
|
|
459
|
+
* hook process can rotate `current.jsonl` into a new page between this reading
|
|
460
|
+
* `current.jsonl` and listing the pages, and that page then holds the rows just
|
|
461
|
+
* read. So the pages are listed once before `current.jsonl` is read; a page
|
|
462
|
+
* that appears only in the second listing was rotated during the read, and any
|
|
463
|
+
* of its rows that were also in `current.jsonl` are skipped. (A page rotated
|
|
464
|
+
* before the read holds none of them: `current.jsonl` was fresh by then.)
|
|
465
|
+
*/
|
|
466
|
+
export function getHookActivityEntriesSince(sinceMs: number): HookActivityEntry[] {
|
|
467
|
+
ensureDir();
|
|
468
|
+
const dir = storeDirValue();
|
|
469
|
+
const inWindow = (e: HookActivityEntry) => typeof e.timestamp === "number" && e.timestamp >= sinceMs;
|
|
470
|
+
const listedBefore = new Set(getArchiveFiles());
|
|
471
|
+
sinceReadProbe?.("before-current");
|
|
472
|
+
const current = readJsonlFile(join(dir, CURRENT_FILE));
|
|
473
|
+
sinceReadProbe?.("after-current");
|
|
474
|
+
const readFromCurrent = new Map<string, number>();
|
|
475
|
+
for (const e of current) {
|
|
476
|
+
const key = JSON.stringify(e);
|
|
477
|
+
readFromCurrent.set(key, (readFromCurrent.get(key) ?? 0) + 1);
|
|
478
|
+
}
|
|
479
|
+
const notReadYet = (e: HookActivityEntry): boolean => {
|
|
480
|
+
const key = JSON.stringify(e);
|
|
481
|
+
const n = readFromCurrent.get(key) ?? 0;
|
|
482
|
+
if (n === 0) return true;
|
|
483
|
+
readFromCurrent.set(key, n - 1);
|
|
484
|
+
return false;
|
|
485
|
+
};
|
|
486
|
+
const out = current.reverse().filter(inWindow);
|
|
487
|
+
for (const file of getArchiveFiles()) {
|
|
488
|
+
const rotatedAt = parseInt(file.slice(5, -6).split("-")[0], 10);
|
|
489
|
+
if (Number.isFinite(rotatedAt) && rotatedAt < sinceMs - ROTATION_CLOCK_SLACK_MS) break;
|
|
490
|
+
let entries = readJsonlFile(join(dir, file));
|
|
491
|
+
if (!listedBefore.has(file)) entries = entries.filter(notReadYet);
|
|
492
|
+
out.push(...entries.reverse().filter(inWindow));
|
|
493
|
+
}
|
|
494
|
+
return out;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** Test-only: runs between the reads of {@link getHookActivityEntriesSince}, to land a rotation exactly there. */
|
|
498
|
+
let sinceReadProbe: ((phase: "before-current" | "after-current") => void) | null = null;
|
|
499
|
+
export function _setSinceReadProbeForTest(probe: ((phase: "before-current" | "after-current") => void) | null): void {
|
|
500
|
+
sinceReadProbe = probe;
|
|
501
|
+
}
|
|
502
|
+
|
|
400
503
|
|
|
401
504
|
export function searchHookActivity(
|
|
402
505
|
filters: HookActivityFilters,
|
|
@@ -519,6 +622,7 @@ function getArchiveFiles(): string[] {
|
|
|
519
622
|
|
|
520
623
|
export function _resetForTest(testDir?: string): void {
|
|
521
624
|
rotateSeq = 0;
|
|
625
|
+
sinceReadProbe = null;
|
|
522
626
|
// null, not the default path: clearing the override lets the getter re-read
|
|
523
627
|
// FAILPROOFAI_HOME, which a test may have changed since this module loaded.
|
|
524
628
|
storeDirOverride = testDir ?? null;
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { version } from "../../package.json";
|
|
9
9
|
import { POSTHOG_API_KEY, POSTHOG_PRODUCT } from "../posthog-key";
|
|
10
10
|
import { isTelemetryEnabled } from "../../lib/telemetry-enabled";
|
|
11
|
+
import { jevOutcome, sanitizeJevActivity, type JevActivityFields } from "./jev-activity";
|
|
11
12
|
|
|
12
13
|
const API_KEY = POSTHOG_API_KEY;
|
|
13
14
|
const CAPTURE_URL = "https://us.i.posthog.com/capture/";
|
|
@@ -86,3 +87,43 @@ export async function flushHookTelemetry(): Promise<void> {
|
|
|
86
87
|
await Promise.allSettled([...pending]);
|
|
87
88
|
}
|
|
88
89
|
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The Jev (two-tier evaluator) properties for a hook telemetry event, built
|
|
93
|
+
* from the activity row's Jev fields — or `{}` when Jev was not involved, so
|
|
94
|
+
* spreading this into an event changes nothing on an unconfigured machine.
|
|
95
|
+
*
|
|
96
|
+
* Same rule as every other hook property: decisions, reason codes, policy and
|
|
97
|
+
* model names, and a latency — never command or prompt text. The row's fields
|
|
98
|
+
* go through the same normaliser the activity store applies on write, so a
|
|
99
|
+
* free-text fallback reason is reduced to its code here too.
|
|
100
|
+
*
|
|
101
|
+
* A call a hard policy denied before Jev's answer was read carries
|
|
102
|
+
* `jev_outcome: "not-consulted"`, and a call no semantic policy applied to (no
|
|
103
|
+
* request sent) `jev_outcome: "no-request"`; neither carries a Jev verdict,
|
|
104
|
+
* clears, latency or model: `jev_evaluator: "jev"` alone does not mean Jev
|
|
105
|
+
* answered (see `jevOutcome`).
|
|
106
|
+
*
|
|
107
|
+
* Meant to be spread into `hook_policy_triggered` by the handler:
|
|
108
|
+
* `{ ...existingProps, ...jevTelemetryProperties(activityEntry) }`.
|
|
109
|
+
*/
|
|
110
|
+
export function jevTelemetryProperties(entry: JevActivityFields): Record<string, unknown> {
|
|
111
|
+
const e = sanitizeJevActivity(entry);
|
|
112
|
+
const outcome = jevOutcome(e);
|
|
113
|
+
if (outcome === null) return {};
|
|
114
|
+
const props: Record<string, unknown> = { jev_evaluator: e.evaluator };
|
|
115
|
+
if (e.jevMode) props.jev_mode = e.jevMode;
|
|
116
|
+
if (outcome === "not-consulted" || outcome === "no-request") {
|
|
117
|
+
props.jev_outcome = outcome;
|
|
118
|
+
return props;
|
|
119
|
+
}
|
|
120
|
+
if (e.jevDecision) props.jev_decision = e.jevDecision;
|
|
121
|
+
if (e.jevCleared) {
|
|
122
|
+
props.jev_cleared = e.jevCleared;
|
|
123
|
+
props.jev_cleared_count = e.jevCleared.length;
|
|
124
|
+
}
|
|
125
|
+
if (e.jevFallbackReason) props.jev_fallback_reason = e.jevFallbackReason;
|
|
126
|
+
if (e.jevLatencyMs !== undefined) props.jev_latency_ms = e.jevLatencyMs;
|
|
127
|
+
if (e.jevModel) props.jev_model = e.jevModel;
|
|
128
|
+
return props;
|
|
129
|
+
}
|