failproofai 0.0.6-beta.2 → 0.0.6-beta.4
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 +3 -3
- package/.next/standalone/.next/required-server-files.json +7 -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.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 +2 -2
- package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +7 -7
- package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +3 -3
- package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +3 -3
- 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.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 +2 -2
- package/.next/standalone/.next/server/app/_not-found.rsc +17 -17
- package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +17 -17
- package/.next/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +4 -4
- package/.next/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +11 -11
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +3 -3
- package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/index.html +1 -1
- package/.next/standalone/.next/server/app/index.rsc +16 -16
- package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +16 -16
- package/.next/standalone/.next/server/app/index.segments/_head.segment.rsc +4 -4
- package/.next/standalone/.next/server/app/index.segments/_index.segment.rsc +11 -11
- 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.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 +8 -8
- 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.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.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.nft.json +1 -1
- package/.next/standalone/.next/server/app/projects/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__0g72weg._.js +1 -1
- package/.next/standalone/.next/server/chunks/package_json_[json]_cjs_0z7w.hh._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__092s1ta._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__09icjsf._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0g.lg8b._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0h..k-e._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0okos0k._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__0i5kvry._.js → [root-of-the-server]__0om-5pe._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0w6l33k._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__05akje6._.js → [root-of-the-server]__111.vxi._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__11pa2ra._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__12t-wym._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/_10lm7or._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/app_global-error_tsx_0xerkr6._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_policies_hooks-client_tsx_0q-m0y-._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/node_modules_posthog-node_dist_entrypoints_index_node_mjs_0mebn66._.js +1 -1
- package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
- package/.next/standalone/.next/server/pages/404.html +2 -2
- 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 +9 -9
- package/.next/standalone/.next/static/chunks/{05j1px0r8yzh6.js → 02dqjyv6_9mhq.js} +2 -2
- package/.next/standalone/.next/static/chunks/{14cl9poem30dq.js → 070orfsl6.xal.js} +1 -1
- package/.next/standalone/.next/static/chunks/0mir9jdxn35~s.css +1 -0
- package/.next/standalone/.next/static/chunks/{00j0rr7rh8ef8.js → 0o547jv-k_k35.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0ijk_kek9_wyx.js → 0pk2h2.mjxy.m.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0xpl.oscrakvx.js → 0rcwkbh24w38b.js} +1 -1
- package/.next/standalone/.next/static/chunks/{1052sguyd-.ka.js → 140xx_tfr~lm_.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0npb~873.wvg3.js → 169_e4dq~1~b6.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0badv41uxa56..js → 17ne4p.1sw1jy.js} +1 -1
- package/.next/standalone/next.config.ts +6 -0
- package/.next/standalone/package.json +2 -2
- package/.next/standalone/server.js +1 -1
- package/bin/failproofai.mjs +91 -4
- package/dist/cli.mjs +1155 -54
- package/package.json +2 -2
- package/scripts/prune-standalone.mjs +128 -0
- package/src/auth/login.ts +104 -0
- package/src/auth/logout.ts +50 -0
- package/src/auth/token-store.ts +64 -0
- package/src/hooks/builtin-policies.ts +22 -20
- package/src/hooks/handler.ts +35 -15
- package/src/relay/daemon.ts +362 -0
- package/src/relay/pid.ts +76 -0
- package/src/relay/queue.ts +225 -0
- package/.next/standalone/.claude/settings.json +0 -316
- package/.next/standalone/.failproofai/policies/review-policies.mjs +0 -113
- package/.next/standalone/.failproofai/policies/workflow-policies.mjs +0 -63
- package/.next/standalone/.failproofai/policies-config.json +0 -39
- package/.next/standalone/.next/static/chunks/0gu_a.a80ritd.css +0 -1
- package/.next/standalone/AGENTS.md +0 -80
- package/.next/standalone/CHANGELOG.md +0 -151
- package/.next/standalone/CLAUDE.md +0 -165
- package/.next/standalone/CONTRIBUTING.md +0 -76
- package/.next/standalone/Dockerfile.docs +0 -12
- package/.next/standalone/LICENSE +0 -42
- package/.next/standalone/README.md +0 -301
- package/.next/standalone/bin/failproofai.mjs +0 -352
- package/.next/standalone/bun.lock +0 -1119
- package/.next/standalone/components.json +0 -23
- package/.next/standalone/dist/cli.mjs +0 -3595
- package/.next/standalone/dist/index.js +0 -80
- package/.next/standalone/docs/ar/architecture.mdx +0 -334
- package/.next/standalone/docs/ar/built-in-policies.mdx +0 -574
- package/.next/standalone/docs/ar/cli/dashboard.mdx +0 -28
- package/.next/standalone/docs/ar/cli/environment-variables.mdx +0 -34
- package/.next/standalone/docs/ar/cli/hook.mdx +0 -31
- package/.next/standalone/docs/ar/cli/install-policies.mdx +0 -48
- package/.next/standalone/docs/ar/cli/list-policies.mdx +0 -31
- package/.next/standalone/docs/ar/cli/remove-policies.mdx +0 -43
- package/.next/standalone/docs/ar/cli/version.mdx +0 -13
- package/.next/standalone/docs/ar/configuration.mdx +0 -223
- package/.next/standalone/docs/ar/custom-policies.mdx +0 -354
- package/.next/standalone/docs/ar/dashboard.mdx +0 -142
- package/.next/standalone/docs/ar/examples.mdx +0 -307
- package/.next/standalone/docs/ar/for-agents.mdx +0 -39
- package/.next/standalone/docs/ar/getting-started.mdx +0 -187
- package/.next/standalone/docs/ar/introduction.mdx +0 -58
- package/.next/standalone/docs/ar/package-aliases.mdx +0 -82
- package/.next/standalone/docs/ar/testing.mdx +0 -261
- package/.next/standalone/docs/architecture.mdx +0 -332
- package/.next/standalone/docs/built-in-policies.mdx +0 -574
- package/.next/standalone/docs/cli/dashboard.mdx +0 -28
- package/.next/standalone/docs/cli/environment-variables.mdx +0 -34
- package/.next/standalone/docs/cli/hook.mdx +0 -30
- package/.next/standalone/docs/cli/install-policies.mdx +0 -47
- package/.next/standalone/docs/cli/list-policies.mdx +0 -31
- package/.next/standalone/docs/cli/remove-policies.mdx +0 -43
- package/.next/standalone/docs/cli/version.mdx +0 -12
- package/.next/standalone/docs/configuration.mdx +0 -222
- package/.next/standalone/docs/custom-policies.mdx +0 -353
- package/.next/standalone/docs/dashboard.mdx +0 -142
- package/.next/standalone/docs/de/architecture.mdx +0 -332
- package/.next/standalone/docs/de/built-in-policies.mdx +0 -574
- package/.next/standalone/docs/de/cli/dashboard.mdx +0 -28
- package/.next/standalone/docs/de/cli/environment-variables.mdx +0 -34
- package/.next/standalone/docs/de/cli/hook.mdx +0 -30
- package/.next/standalone/docs/de/cli/install-policies.mdx +0 -47
- package/.next/standalone/docs/de/cli/list-policies.mdx +0 -31
- package/.next/standalone/docs/de/cli/remove-policies.mdx +0 -43
- package/.next/standalone/docs/de/cli/version.mdx +0 -12
- package/.next/standalone/docs/de/configuration.mdx +0 -222
- package/.next/standalone/docs/de/custom-policies.mdx +0 -353
- package/.next/standalone/docs/de/dashboard.mdx +0 -142
- package/.next/standalone/docs/de/examples.mdx +0 -307
- package/.next/standalone/docs/de/for-agents.mdx +0 -38
- package/.next/standalone/docs/de/getting-started.mdx +0 -186
- package/.next/standalone/docs/de/introduction.mdx +0 -57
- package/.next/standalone/docs/de/package-aliases.mdx +0 -82
- package/.next/standalone/docs/de/testing.mdx +0 -260
- package/.next/standalone/docs/docs.json +0 -1002
- package/.next/standalone/docs/es/architecture.mdx +0 -332
- package/.next/standalone/docs/es/built-in-policies.mdx +0 -574
- package/.next/standalone/docs/es/cli/dashboard.mdx +0 -28
- package/.next/standalone/docs/es/cli/environment-variables.mdx +0 -34
- package/.next/standalone/docs/es/cli/hook.mdx +0 -30
- package/.next/standalone/docs/es/cli/install-policies.mdx +0 -47
- package/.next/standalone/docs/es/cli/list-policies.mdx +0 -31
- package/.next/standalone/docs/es/cli/remove-policies.mdx +0 -43
- package/.next/standalone/docs/es/cli/version.mdx +0 -12
- package/.next/standalone/docs/es/configuration.mdx +0 -222
- package/.next/standalone/docs/es/custom-policies.mdx +0 -353
- package/.next/standalone/docs/es/dashboard.mdx +0 -142
- package/.next/standalone/docs/es/examples.mdx +0 -307
- package/.next/standalone/docs/es/for-agents.mdx +0 -38
- package/.next/standalone/docs/es/getting-started.mdx +0 -186
- package/.next/standalone/docs/es/introduction.mdx +0 -57
- package/.next/standalone/docs/es/package-aliases.mdx +0 -82
- package/.next/standalone/docs/es/testing.mdx +0 -260
- package/.next/standalone/docs/examples.mdx +0 -307
- package/.next/standalone/docs/favicon.ico +0 -0
- package/.next/standalone/docs/for-agents.mdx +0 -38
- package/.next/standalone/docs/fr/architecture.mdx +0 -332
- package/.next/standalone/docs/fr/built-in-policies.mdx +0 -574
- package/.next/standalone/docs/fr/cli/dashboard.mdx +0 -28
- package/.next/standalone/docs/fr/cli/environment-variables.mdx +0 -34
- package/.next/standalone/docs/fr/cli/hook.mdx +0 -30
- package/.next/standalone/docs/fr/cli/install-policies.mdx +0 -47
- package/.next/standalone/docs/fr/cli/list-policies.mdx +0 -31
- package/.next/standalone/docs/fr/cli/remove-policies.mdx +0 -43
- package/.next/standalone/docs/fr/cli/version.mdx +0 -12
- package/.next/standalone/docs/fr/configuration.mdx +0 -222
- package/.next/standalone/docs/fr/custom-policies.mdx +0 -353
- package/.next/standalone/docs/fr/dashboard.mdx +0 -142
- package/.next/standalone/docs/fr/examples.mdx +0 -307
- package/.next/standalone/docs/fr/for-agents.mdx +0 -38
- package/.next/standalone/docs/fr/getting-started.mdx +0 -186
- package/.next/standalone/docs/fr/introduction.mdx +0 -57
- package/.next/standalone/docs/fr/package-aliases.mdx +0 -82
- package/.next/standalone/docs/fr/testing.mdx +0 -260
- package/.next/standalone/docs/getting-started.mdx +0 -186
- package/.next/standalone/docs/he/architecture.mdx +0 -333
- package/.next/standalone/docs/he/built-in-policies.mdx +0 -574
- package/.next/standalone/docs/he/cli/dashboard.mdx +0 -28
- package/.next/standalone/docs/he/cli/environment-variables.mdx +0 -34
- package/.next/standalone/docs/he/cli/hook.mdx +0 -30
- package/.next/standalone/docs/he/cli/install-policies.mdx +0 -47
- package/.next/standalone/docs/he/cli/list-policies.mdx +0 -32
- package/.next/standalone/docs/he/cli/remove-policies.mdx +0 -43
- package/.next/standalone/docs/he/cli/version.mdx +0 -12
- package/.next/standalone/docs/he/configuration.mdx +0 -223
- package/.next/standalone/docs/he/custom-policies.mdx +0 -353
- package/.next/standalone/docs/he/dashboard.mdx +0 -142
- package/.next/standalone/docs/he/examples.mdx +0 -307
- package/.next/standalone/docs/he/for-agents.mdx +0 -38
- package/.next/standalone/docs/he/getting-started.mdx +0 -186
- package/.next/standalone/docs/he/introduction.mdx +0 -57
- package/.next/standalone/docs/he/package-aliases.mdx +0 -82
- package/.next/standalone/docs/he/testing.mdx +0 -260
- package/.next/standalone/docs/hi/architecture.mdx +0 -334
- package/.next/standalone/docs/hi/built-in-policies.mdx +0 -576
- package/.next/standalone/docs/hi/cli/dashboard.mdx +0 -28
- package/.next/standalone/docs/hi/cli/environment-variables.mdx +0 -34
- package/.next/standalone/docs/hi/cli/hook.mdx +0 -30
- package/.next/standalone/docs/hi/cli/install-policies.mdx +0 -47
- package/.next/standalone/docs/hi/cli/list-policies.mdx +0 -31
- package/.next/standalone/docs/hi/cli/remove-policies.mdx +0 -43
- package/.next/standalone/docs/hi/cli/version.mdx +0 -12
- package/.next/standalone/docs/hi/configuration.mdx +0 -222
- package/.next/standalone/docs/hi/custom-policies.mdx +0 -354
- package/.next/standalone/docs/hi/dashboard.mdx +0 -142
- package/.next/standalone/docs/hi/examples.mdx +0 -309
- package/.next/standalone/docs/hi/for-agents.mdx +0 -38
- package/.next/standalone/docs/hi/getting-started.mdx +0 -187
- package/.next/standalone/docs/hi/introduction.mdx +0 -57
- package/.next/standalone/docs/hi/package-aliases.mdx +0 -82
- package/.next/standalone/docs/hi/testing.mdx +0 -260
- package/.next/standalone/docs/i18n/README.ar.md +0 -312
- package/.next/standalone/docs/i18n/README.de.md +0 -307
- package/.next/standalone/docs/i18n/README.es.md +0 -307
- package/.next/standalone/docs/i18n/README.fr.md +0 -307
- package/.next/standalone/docs/i18n/README.he.md +0 -312
- package/.next/standalone/docs/i18n/README.hi.md +0 -307
- package/.next/standalone/docs/i18n/README.it.md +0 -307
- package/.next/standalone/docs/i18n/README.ja.md +0 -307
- package/.next/standalone/docs/i18n/README.ko.md +0 -307
- package/.next/standalone/docs/i18n/README.pt-br.md +0 -307
- package/.next/standalone/docs/i18n/README.ru.md +0 -308
- package/.next/standalone/docs/i18n/README.tr.md +0 -307
- package/.next/standalone/docs/i18n/README.vi.md +0 -307
- package/.next/standalone/docs/i18n/README.zh.md +0 -307
- package/.next/standalone/docs/introduction.mdx +0 -57
- package/.next/standalone/docs/it/architecture.mdx +0 -334
- package/.next/standalone/docs/it/built-in-policies.mdx +0 -574
- package/.next/standalone/docs/it/cli/dashboard.mdx +0 -28
- package/.next/standalone/docs/it/cli/environment-variables.mdx +0 -34
- package/.next/standalone/docs/it/cli/hook.mdx +0 -30
- package/.next/standalone/docs/it/cli/install-policies.mdx +0 -47
- package/.next/standalone/docs/it/cli/list-policies.mdx +0 -31
- package/.next/standalone/docs/it/cli/remove-policies.mdx +0 -43
- package/.next/standalone/docs/it/cli/version.mdx +0 -12
- package/.next/standalone/docs/it/configuration.mdx +0 -222
- package/.next/standalone/docs/it/custom-policies.mdx +0 -353
- package/.next/standalone/docs/it/dashboard.mdx +0 -142
- package/.next/standalone/docs/it/examples.mdx +0 -307
- package/.next/standalone/docs/it/for-agents.mdx +0 -38
- package/.next/standalone/docs/it/getting-started.mdx +0 -186
- package/.next/standalone/docs/it/introduction.mdx +0 -57
- package/.next/standalone/docs/it/package-aliases.mdx +0 -82
- package/.next/standalone/docs/it/testing.mdx +0 -260
- package/.next/standalone/docs/ja/architecture.mdx +0 -332
- package/.next/standalone/docs/ja/built-in-policies.mdx +0 -572
- package/.next/standalone/docs/ja/cli/dashboard.mdx +0 -28
- package/.next/standalone/docs/ja/cli/environment-variables.mdx +0 -34
- package/.next/standalone/docs/ja/cli/hook.mdx +0 -30
- package/.next/standalone/docs/ja/cli/install-policies.mdx +0 -47
- package/.next/standalone/docs/ja/cli/list-policies.mdx +0 -31
- package/.next/standalone/docs/ja/cli/remove-policies.mdx +0 -43
- package/.next/standalone/docs/ja/cli/version.mdx +0 -12
- package/.next/standalone/docs/ja/configuration.mdx +0 -222
- package/.next/standalone/docs/ja/custom-policies.mdx +0 -353
- package/.next/standalone/docs/ja/dashboard.mdx +0 -142
- package/.next/standalone/docs/ja/examples.mdx +0 -307
- package/.next/standalone/docs/ja/for-agents.mdx +0 -38
- package/.next/standalone/docs/ja/getting-started.mdx +0 -186
- package/.next/standalone/docs/ja/introduction.mdx +0 -57
- package/.next/standalone/docs/ja/package-aliases.mdx +0 -82
- package/.next/standalone/docs/ja/testing.mdx +0 -260
- package/.next/standalone/docs/ko/architecture.mdx +0 -332
- package/.next/standalone/docs/ko/built-in-policies.mdx +0 -572
- package/.next/standalone/docs/ko/cli/dashboard.mdx +0 -28
- package/.next/standalone/docs/ko/cli/environment-variables.mdx +0 -34
- package/.next/standalone/docs/ko/cli/hook.mdx +0 -30
- package/.next/standalone/docs/ko/cli/install-policies.mdx +0 -47
- package/.next/standalone/docs/ko/cli/list-policies.mdx +0 -31
- package/.next/standalone/docs/ko/cli/remove-policies.mdx +0 -43
- package/.next/standalone/docs/ko/cli/version.mdx +0 -12
- package/.next/standalone/docs/ko/configuration.mdx +0 -222
- package/.next/standalone/docs/ko/custom-policies.mdx +0 -353
- package/.next/standalone/docs/ko/dashboard.mdx +0 -142
- package/.next/standalone/docs/ko/examples.mdx +0 -307
- package/.next/standalone/docs/ko/for-agents.mdx +0 -38
- package/.next/standalone/docs/ko/getting-started.mdx +0 -186
- package/.next/standalone/docs/ko/introduction.mdx +0 -57
- package/.next/standalone/docs/ko/package-aliases.mdx +0 -82
- package/.next/standalone/docs/ko/testing.mdx +0 -260
- package/.next/standalone/docs/logo/dark.svg +0 -21
- package/.next/standalone/docs/logo/exosphere-dark.png +0 -0
- package/.next/standalone/docs/logo/exosphere-light.png +0 -0
- package/.next/standalone/docs/logo/light.svg +0 -21
- package/.next/standalone/docs/package-aliases.mdx +0 -82
- package/.next/standalone/docs/pt-br/architecture.mdx +0 -332
- package/.next/standalone/docs/pt-br/built-in-policies.mdx +0 -574
- package/.next/standalone/docs/pt-br/cli/dashboard.mdx +0 -28
- package/.next/standalone/docs/pt-br/cli/environment-variables.mdx +0 -34
- package/.next/standalone/docs/pt-br/cli/hook.mdx +0 -30
- package/.next/standalone/docs/pt-br/cli/install-policies.mdx +0 -47
- package/.next/standalone/docs/pt-br/cli/list-policies.mdx +0 -31
- package/.next/standalone/docs/pt-br/cli/remove-policies.mdx +0 -43
- package/.next/standalone/docs/pt-br/cli/version.mdx +0 -12
- package/.next/standalone/docs/pt-br/configuration.mdx +0 -222
- package/.next/standalone/docs/pt-br/custom-policies.mdx +0 -353
- package/.next/standalone/docs/pt-br/dashboard.mdx +0 -142
- package/.next/standalone/docs/pt-br/examples.mdx +0 -307
- package/.next/standalone/docs/pt-br/for-agents.mdx +0 -38
- package/.next/standalone/docs/pt-br/getting-started.mdx +0 -186
- package/.next/standalone/docs/pt-br/introduction.mdx +0 -57
- package/.next/standalone/docs/pt-br/package-aliases.mdx +0 -82
- package/.next/standalone/docs/pt-br/testing.mdx +0 -260
- package/.next/standalone/docs/ru/architecture.mdx +0 -333
- package/.next/standalone/docs/ru/built-in-policies.mdx +0 -574
- package/.next/standalone/docs/ru/cli/dashboard.mdx +0 -28
- package/.next/standalone/docs/ru/cli/environment-variables.mdx +0 -34
- package/.next/standalone/docs/ru/cli/hook.mdx +0 -30
- package/.next/standalone/docs/ru/cli/install-policies.mdx +0 -48
- package/.next/standalone/docs/ru/cli/list-policies.mdx +0 -32
- package/.next/standalone/docs/ru/cli/remove-policies.mdx +0 -43
- package/.next/standalone/docs/ru/cli/version.mdx +0 -12
- package/.next/standalone/docs/ru/configuration.mdx +0 -222
- package/.next/standalone/docs/ru/custom-policies.mdx +0 -354
- package/.next/standalone/docs/ru/dashboard.mdx +0 -142
- package/.next/standalone/docs/ru/examples.mdx +0 -309
- package/.next/standalone/docs/ru/for-agents.mdx +0 -38
- package/.next/standalone/docs/ru/getting-started.mdx +0 -186
- package/.next/standalone/docs/ru/introduction.mdx +0 -57
- package/.next/standalone/docs/ru/package-aliases.mdx +0 -82
- package/.next/standalone/docs/ru/testing.mdx +0 -260
- package/.next/standalone/docs/testing.mdx +0 -260
- package/.next/standalone/docs/tr/architecture.mdx +0 -333
- package/.next/standalone/docs/tr/built-in-policies.mdx +0 -574
- package/.next/standalone/docs/tr/cli/dashboard.mdx +0 -28
- package/.next/standalone/docs/tr/cli/environment-variables.mdx +0 -34
- package/.next/standalone/docs/tr/cli/hook.mdx +0 -30
- package/.next/standalone/docs/tr/cli/install-policies.mdx +0 -47
- package/.next/standalone/docs/tr/cli/list-policies.mdx +0 -31
- package/.next/standalone/docs/tr/cli/remove-policies.mdx +0 -44
- package/.next/standalone/docs/tr/cli/version.mdx +0 -12
- package/.next/standalone/docs/tr/configuration.mdx +0 -222
- package/.next/standalone/docs/tr/custom-policies.mdx +0 -353
- package/.next/standalone/docs/tr/dashboard.mdx +0 -142
- package/.next/standalone/docs/tr/examples.mdx +0 -308
- package/.next/standalone/docs/tr/for-agents.mdx +0 -38
- package/.next/standalone/docs/tr/getting-started.mdx +0 -186
- package/.next/standalone/docs/tr/introduction.mdx +0 -57
- package/.next/standalone/docs/tr/package-aliases.mdx +0 -82
- package/.next/standalone/docs/tr/testing.mdx +0 -260
- package/.next/standalone/docs/vi/architecture.mdx +0 -334
- package/.next/standalone/docs/vi/built-in-policies.mdx +0 -575
- package/.next/standalone/docs/vi/cli/dashboard.mdx +0 -28
- package/.next/standalone/docs/vi/cli/environment-variables.mdx +0 -34
- package/.next/standalone/docs/vi/cli/hook.mdx +0 -30
- package/.next/standalone/docs/vi/cli/install-policies.mdx +0 -47
- package/.next/standalone/docs/vi/cli/list-policies.mdx +0 -31
- package/.next/standalone/docs/vi/cli/remove-policies.mdx +0 -43
- package/.next/standalone/docs/vi/cli/version.mdx +0 -13
- package/.next/standalone/docs/vi/configuration.mdx +0 -222
- package/.next/standalone/docs/vi/custom-policies.mdx +0 -353
- package/.next/standalone/docs/vi/dashboard.mdx +0 -142
- package/.next/standalone/docs/vi/examples.mdx +0 -308
- package/.next/standalone/docs/vi/for-agents.mdx +0 -38
- package/.next/standalone/docs/vi/getting-started.mdx +0 -186
- package/.next/standalone/docs/vi/introduction.mdx +0 -57
- package/.next/standalone/docs/vi/package-aliases.mdx +0 -82
- package/.next/standalone/docs/vi/testing.mdx +0 -260
- package/.next/standalone/docs/zh/architecture.mdx +0 -332
- package/.next/standalone/docs/zh/built-in-policies.mdx +0 -572
- package/.next/standalone/docs/zh/cli/dashboard.mdx +0 -28
- package/.next/standalone/docs/zh/cli/environment-variables.mdx +0 -34
- package/.next/standalone/docs/zh/cli/hook.mdx +0 -30
- package/.next/standalone/docs/zh/cli/install-policies.mdx +0 -47
- package/.next/standalone/docs/zh/cli/list-policies.mdx +0 -31
- package/.next/standalone/docs/zh/cli/remove-policies.mdx +0 -43
- package/.next/standalone/docs/zh/cli/version.mdx +0 -12
- package/.next/standalone/docs/zh/configuration.mdx +0 -222
- package/.next/standalone/docs/zh/custom-policies.mdx +0 -353
- package/.next/standalone/docs/zh/dashboard.mdx +0 -142
- package/.next/standalone/docs/zh/examples.mdx +0 -307
- package/.next/standalone/docs/zh/for-agents.mdx +0 -38
- package/.next/standalone/docs/zh/getting-started.mdx +0 -186
- package/.next/standalone/docs/zh/introduction.mdx +0 -57
- package/.next/standalone/docs/zh/package-aliases.mdx +0 -82
- package/.next/standalone/docs/zh/testing.mdx +0 -260
- package/.next/standalone/eslint.config.mjs +0 -15
- package/.next/standalone/examples/convention-policies/security-policies.mjs +0 -40
- package/.next/standalone/examples/convention-policies/workflow-policies.mjs +0 -41
- package/.next/standalone/examples/policies-advanced/index.js +0 -103
- package/.next/standalone/examples/policies-advanced/utils.js +0 -35
- package/.next/standalone/examples/policies-basic.js +0 -77
- package/.next/standalone/examples/policies-notification.js +0 -104
- package/.next/standalone/node_modules/@img/colour/color.cjs +0 -1594
- package/.next/standalone/node_modules/@img/colour/index.cjs +0 -1
- package/.next/standalone/node_modules/@img/colour/package.json +0 -45
- package/.next/standalone/node_modules/@img/sharp-libvips-linux-x64/README.md +0 -46
- package/.next/standalone/node_modules/@img/sharp-libvips-linux-x64/lib/glib-2.0/include/glibconfig.h +0 -221
- package/.next/standalone/node_modules/@img/sharp-libvips-linux-x64/lib/index.js +0 -1
- package/.next/standalone/node_modules/@img/sharp-libvips-linux-x64/lib/libvips-cpp.so.8.17.3 +0 -0
- package/.next/standalone/node_modules/@img/sharp-libvips-linux-x64/package.json +0 -42
- package/.next/standalone/node_modules/@img/sharp-libvips-linux-x64/versions.json +0 -30
- package/.next/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/README.md +0 -46
- package/.next/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/lib/glib-2.0/include/glibconfig.h +0 -221
- package/.next/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/lib/index.js +0 -1
- package/.next/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/lib/libvips-cpp.so.8.17.3 +0 -0
- package/.next/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/package.json +0 -42
- package/.next/standalone/node_modules/@img/sharp-libvips-linuxmusl-x64/versions.json +0 -30
- package/.next/standalone/node_modules/@img/sharp-linux-x64/lib/sharp-linux-x64.node +0 -0
- package/.next/standalone/node_modules/@img/sharp-linux-x64/package.json +0 -46
- package/.next/standalone/node_modules/@img/sharp-linuxmusl-x64/lib/sharp-linuxmusl-x64.node +0 -0
- package/.next/standalone/node_modules/@img/sharp-linuxmusl-x64/package.json +0 -46
- package/.next/standalone/node_modules/detect-libc/lib/detect-libc.js +0 -313
- package/.next/standalone/node_modules/detect-libc/lib/elf.js +0 -39
- package/.next/standalone/node_modules/detect-libc/lib/filesystem.js +0 -51
- package/.next/standalone/node_modules/detect-libc/lib/process.js +0 -24
- package/.next/standalone/node_modules/detect-libc/package.json +0 -44
- package/.next/standalone/node_modules/sharp/lib/channel.js +0 -177
- package/.next/standalone/node_modules/sharp/lib/colour.js +0 -195
- package/.next/standalone/node_modules/sharp/lib/composite.js +0 -212
- package/.next/standalone/node_modules/sharp/lib/constructor.js +0 -499
- package/.next/standalone/node_modules/sharp/lib/index.js +0 -16
- package/.next/standalone/node_modules/sharp/lib/input.js +0 -809
- package/.next/standalone/node_modules/sharp/lib/is.js +0 -143
- package/.next/standalone/node_modules/sharp/lib/libvips.js +0 -207
- package/.next/standalone/node_modules/sharp/lib/operation.js +0 -1016
- package/.next/standalone/node_modules/sharp/lib/output.js +0 -1666
- package/.next/standalone/node_modules/sharp/lib/resize.js +0 -595
- package/.next/standalone/node_modules/sharp/lib/sharp.js +0 -121
- package/.next/standalone/node_modules/sharp/lib/utility.js +0 -291
- package/.next/standalone/node_modules/sharp/node_modules/semver/classes/comparator.js +0 -143
- package/.next/standalone/node_modules/sharp/node_modules/semver/classes/range.js +0 -557
- package/.next/standalone/node_modules/sharp/node_modules/semver/classes/semver.js +0 -333
- package/.next/standalone/node_modules/sharp/node_modules/semver/functions/cmp.js +0 -54
- package/.next/standalone/node_modules/sharp/node_modules/semver/functions/coerce.js +0 -62
- package/.next/standalone/node_modules/sharp/node_modules/semver/functions/compare.js +0 -7
- package/.next/standalone/node_modules/sharp/node_modules/semver/functions/eq.js +0 -5
- package/.next/standalone/node_modules/sharp/node_modules/semver/functions/gt.js +0 -5
- package/.next/standalone/node_modules/sharp/node_modules/semver/functions/gte.js +0 -5
- package/.next/standalone/node_modules/sharp/node_modules/semver/functions/lt.js +0 -5
- package/.next/standalone/node_modules/sharp/node_modules/semver/functions/lte.js +0 -5
- package/.next/standalone/node_modules/sharp/node_modules/semver/functions/neq.js +0 -5
- package/.next/standalone/node_modules/sharp/node_modules/semver/functions/parse.js +0 -18
- package/.next/standalone/node_modules/sharp/node_modules/semver/functions/satisfies.js +0 -12
- package/.next/standalone/node_modules/sharp/node_modules/semver/internal/constants.js +0 -37
- package/.next/standalone/node_modules/sharp/node_modules/semver/internal/debug.js +0 -11
- package/.next/standalone/node_modules/sharp/node_modules/semver/internal/identifiers.js +0 -29
- package/.next/standalone/node_modules/sharp/node_modules/semver/internal/lrucache.js +0 -42
- package/.next/standalone/node_modules/sharp/node_modules/semver/internal/parse-options.js +0 -17
- package/.next/standalone/node_modules/sharp/node_modules/semver/internal/re.js +0 -223
- package/.next/standalone/node_modules/sharp/node_modules/semver/package.json +0 -78
- package/.next/standalone/node_modules/sharp/package.json +0 -202
- package/.next/standalone/scripts/alias-proxy.js +0 -18
- package/.next/standalone/scripts/dev.ts +0 -3
- package/.next/standalone/scripts/install-telemetry.mjs +0 -108
- package/.next/standalone/scripts/launch.ts +0 -83
- package/.next/standalone/scripts/parse-script-args.ts +0 -87
- package/.next/standalone/scripts/postinstall.mjs +0 -121
- package/.next/standalone/scripts/preuninstall.mjs +0 -131
- package/.next/standalone/scripts/publish-aliases.mjs +0 -87
- package/.next/standalone/scripts/start.ts +0 -3
- package/.next/standalone/scripts/sync-hook-events-prompt.md +0 -60
- package/.next/standalone/scripts/translate-docs/cache.ts +0 -62
- package/.next/standalone/scripts/translate-docs/cli.ts +0 -357
- package/.next/standalone/scripts/translate-docs/config.ts +0 -248
- package/.next/standalone/scripts/translate-docs/mdx-translator.ts +0 -153
- package/.next/standalone/scripts/translate-docs/mintlify-nav.ts +0 -107
- package/.next/standalone/scripts/translate-docs/readme-translator.ts +0 -154
- package/.next/standalone/scripts/translate-docs/translator.ts +0 -68
- package/.next/standalone/scripts/translate-docs/types.ts +0 -43
- package/.next/standalone/src/cli-error.ts +0 -18
- package/.next/standalone/src/hooks/builtin-policies.ts +0 -1613
- package/.next/standalone/src/hooks/custom-hooks-loader.ts +0 -205
- package/.next/standalone/src/hooks/custom-hooks-registry.ts +0 -30
- package/.next/standalone/src/hooks/handler.ts +0 -202
- package/.next/standalone/src/hooks/hook-activity-store.ts +0 -349
- package/.next/standalone/src/hooks/hook-logger.ts +0 -133
- package/.next/standalone/src/hooks/hook-telemetry.ts +0 -43
- package/.next/standalone/src/hooks/hooks-config.ts +0 -166
- package/.next/standalone/src/hooks/install-prompt.ts +0 -357
- package/.next/standalone/src/hooks/llm-client.ts +0 -90
- package/.next/standalone/src/hooks/loader-utils.ts +0 -178
- package/.next/standalone/src/hooks/manager.ts +0 -692
- package/.next/standalone/src/hooks/policy-evaluator.ts +0 -224
- package/.next/standalone/src/hooks/policy-helpers.ts +0 -16
- package/.next/standalone/src/hooks/policy-registry.ts +0 -90
- package/.next/standalone/src/hooks/policy-types.ts +0 -77
- package/.next/standalone/src/hooks/types.ts +0 -63
- package/.next/standalone/src/index.ts +0 -19
- package/.next/standalone/src/posthog-key.ts +0 -5
- package/.next/standalone/tailwind.config.ts +0 -11
- package/.next/standalone/tsconfig.json +0 -42
- package/.next/standalone/vitest.config.e2e.mts +0 -24
- package/.next/standalone/vitest.config.mts +0 -23
- /package/.next/standalone/.next/static/{A9pNTZdoYJTVyPAYwQMx5 → wOkJXoch1UmRAmyIuKZWc}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{A9pNTZdoYJTVyPAYwQMx5 → wOkJXoch1UmRAmyIuKZWc}/_clientMiddlewareManifest.js +0 -0
- /package/.next/standalone/.next/static/{A9pNTZdoYJTVyPAYwQMx5 → wOkJXoch1UmRAmyIuKZWc}/_ssgManifest.js +0 -0
|
@@ -1,349 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Disk persistence for hook activity entries using page-sized JSONL files.
|
|
3
|
-
*
|
|
4
|
-
* Storage location: ~/.failproofai/cache/hook-activity/
|
|
5
|
-
*
|
|
6
|
-
* File structure:
|
|
7
|
-
* - current.jsonl — actively written to, 0–PAGE_SIZE entries
|
|
8
|
-
* - page-{timestamp}-{seq}.jsonl — rotated archive files, exactly PAGE_SIZE entries each
|
|
9
|
-
*
|
|
10
|
-
* The hook handler is a short-lived process so writes are synchronous (no buffer).
|
|
11
|
-
* Dashboard reads are async and lazy (per-page).
|
|
12
|
-
*/
|
|
13
|
-
import {
|
|
14
|
-
readFileSync,
|
|
15
|
-
writeFileSync,
|
|
16
|
-
appendFileSync,
|
|
17
|
-
renameSync,
|
|
18
|
-
readdirSync,
|
|
19
|
-
mkdirSync,
|
|
20
|
-
existsSync,
|
|
21
|
-
statSync,
|
|
22
|
-
unlinkSync,
|
|
23
|
-
} from "node:fs";
|
|
24
|
-
import { join } from "node:path";
|
|
25
|
-
import { homedir } from "node:os";
|
|
26
|
-
|
|
27
|
-
export const PAGE_SIZE = 25;
|
|
28
|
-
|
|
29
|
-
const DEFAULT_STORE_DIR = join(homedir(), ".failproofai", "cache", "hook-activity");
|
|
30
|
-
const CURRENT_FILE = "current.jsonl";
|
|
31
|
-
const COUNT_FILE = "current.count"; // tracks line count; O(1) read/write vs rereading current.jsonl
|
|
32
|
-
const STATS_FILE = "stats.json";
|
|
33
|
-
const LOCK_FILE = "current.lock"; // advisory lock for concurrent hook processes
|
|
34
|
-
const LOCK_STALE_MS = 2000; // steal lock if older than 2 s (covers crashed processes)
|
|
35
|
-
|
|
36
|
-
let storeDir = DEFAULT_STORE_DIR;
|
|
37
|
-
let rotateSeq = 0;
|
|
38
|
-
|
|
39
|
-
// ── Types ──
|
|
40
|
-
|
|
41
|
-
export interface HookActivityEntry {
|
|
42
|
-
timestamp: number;
|
|
43
|
-
eventType: string;
|
|
44
|
-
toolName: string | null;
|
|
45
|
-
policyName: string | null;
|
|
46
|
-
policyNames?: string[];
|
|
47
|
-
decision: "allow" | "deny" | "instruct";
|
|
48
|
-
reason: string | null;
|
|
49
|
-
durationMs: number;
|
|
50
|
-
sessionId?: string;
|
|
51
|
-
transcriptPath?: string;
|
|
52
|
-
cwd?: string;
|
|
53
|
-
permissionMode?: string;
|
|
54
|
-
hookEventName?: string;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface HookActivityFilters {
|
|
58
|
-
decision?: "allow" | "deny" | "instruct";
|
|
59
|
-
eventType?: string;
|
|
60
|
-
policyName?: string;
|
|
61
|
-
sessionId?: string;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface HookActivityStats {
|
|
65
|
-
totalEvents: number;
|
|
66
|
-
denyCount: number;
|
|
67
|
-
topPolicy: string | null;
|
|
68
|
-
topPolicyCount: number;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// ── Directory setup ──
|
|
72
|
-
|
|
73
|
-
function ensureDir(): void {
|
|
74
|
-
if (!existsSync(storeDir)) {
|
|
75
|
-
mkdirSync(storeDir, { recursive: true });
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// ── Advisory lock (protects count + stats read-modify-write cycles) ──
|
|
80
|
-
|
|
81
|
-
function acquireLock(): void {
|
|
82
|
-
ensureDir();
|
|
83
|
-
const lockPath = join(storeDir, LOCK_FILE);
|
|
84
|
-
const deadline = Date.now() + LOCK_STALE_MS;
|
|
85
|
-
while (Date.now() < deadline) {
|
|
86
|
-
try {
|
|
87
|
-
// Exclusive create — fails with EEXIST if another process holds the lock
|
|
88
|
-
writeFileSync(lockPath, String(process.pid), { flag: "wx" });
|
|
89
|
-
return; // acquired
|
|
90
|
-
} catch (e) {
|
|
91
|
-
if ((e as NodeJS.ErrnoException).code !== "EEXIST") return; // unexpected — proceed unlocked
|
|
92
|
-
// Check if the lock is stale (process may have crashed)
|
|
93
|
-
try {
|
|
94
|
-
const s = statSync(lockPath);
|
|
95
|
-
if (Date.now() - s.mtimeMs > LOCK_STALE_MS) {
|
|
96
|
-
writeFileSync(lockPath, String(process.pid), "utf-8"); // steal stale lock
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
} catch { /* lock file disappeared — retry */ }
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
// Timed out — proceed without lock (best-effort, extremely rare)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function releaseLock(): void {
|
|
106
|
-
try { unlinkSync(join(storeDir, LOCK_FILE)); } catch { /* ignore */ }
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// ── Writing (synchronous — hook handler is short-lived) ──
|
|
110
|
-
|
|
111
|
-
export function persistHookActivity(entry: HookActivityEntry): void {
|
|
112
|
-
ensureDir();
|
|
113
|
-
acquireLock();
|
|
114
|
-
try {
|
|
115
|
-
const currentPath = join(storeDir, CURRENT_FILE);
|
|
116
|
-
const countPath = join(storeDir, COUNT_FILE);
|
|
117
|
-
|
|
118
|
-
const lineCount = readCount(countPath);
|
|
119
|
-
if (lineCount >= PAGE_SIZE) {
|
|
120
|
-
try {
|
|
121
|
-
rotate(currentPath, countPath);
|
|
122
|
-
} catch (e) {
|
|
123
|
-
if ((e as NodeJS.ErrnoException).code !== "ENOENT") throw e;
|
|
124
|
-
// Another process rotated concurrently — proceed to append to fresh file.
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
appendFileSync(currentPath, JSON.stringify(entry) + "\n", "utf-8");
|
|
129
|
-
writeCount(countPath, lineCount >= PAGE_SIZE ? 1 : lineCount + 1);
|
|
130
|
-
updateStats(entry);
|
|
131
|
-
} finally {
|
|
132
|
-
releaseLock();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function rotate(currentPath: string, countPath: string): void {
|
|
137
|
-
const archiveName = `page-${Date.now()}-${rotateSeq++}.jsonl`;
|
|
138
|
-
const archivePath = join(storeDir, archiveName);
|
|
139
|
-
renameSync(currentPath, archivePath);
|
|
140
|
-
// Reset count for the fresh file (write 0 — next append will set it to 1)
|
|
141
|
-
writeCount(countPath, 0);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// O(1) line count via a tiny sidecar file; avoids rereading current.jsonl.
|
|
145
|
-
function readCount(countPath: string): number {
|
|
146
|
-
try {
|
|
147
|
-
const n = parseInt(readFileSync(countPath, "utf-8"), 10);
|
|
148
|
-
return isNaN(n) ? 0 : n;
|
|
149
|
-
} catch {
|
|
150
|
-
return 0;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function writeCount(countPath: string, n: number): void {
|
|
155
|
-
try {
|
|
156
|
-
writeFileSync(countPath, String(n), "utf-8");
|
|
157
|
-
} catch {
|
|
158
|
-
// Non-fatal: worst case we recount from 0 next time
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function readFileSafe(filePath: string): string {
|
|
163
|
-
try {
|
|
164
|
-
return readFileSync(filePath, "utf-8");
|
|
165
|
-
} catch {
|
|
166
|
-
return "";
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// ── Incremental stats (O(1) reads/writes) ──
|
|
171
|
-
|
|
172
|
-
interface StoredStats {
|
|
173
|
-
totalEvents: number;
|
|
174
|
-
denyCount: number;
|
|
175
|
-
policyMap: Record<string, number>;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function readStoredStats(): StoredStats {
|
|
179
|
-
try {
|
|
180
|
-
return JSON.parse(readFileSync(join(storeDir, STATS_FILE), "utf-8")) as StoredStats;
|
|
181
|
-
} catch {
|
|
182
|
-
return { totalEvents: 0, denyCount: 0, policyMap: {} };
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function updateStats(entry: HookActivityEntry): void {
|
|
187
|
-
const s = readStoredStats();
|
|
188
|
-
s.totalEvents += 1;
|
|
189
|
-
if (entry.decision === "deny") s.denyCount += 1;
|
|
190
|
-
if (entry.policyNames && entry.policyNames.length > 0) {
|
|
191
|
-
for (const name of entry.policyNames) {
|
|
192
|
-
s.policyMap[name] = (s.policyMap[name] ?? 0) + 1;
|
|
193
|
-
}
|
|
194
|
-
} else if (entry.policyName) {
|
|
195
|
-
s.policyMap[entry.policyName] = (s.policyMap[entry.policyName] ?? 0) + 1;
|
|
196
|
-
}
|
|
197
|
-
// Write atomically: write to a PID-unique temp file then rename — prevents partial reads.
|
|
198
|
-
const tmpPath = join(storeDir, `stats.json.${process.pid}.tmp`);
|
|
199
|
-
try {
|
|
200
|
-
writeFileSync(tmpPath, JSON.stringify(s), "utf-8");
|
|
201
|
-
renameSync(tmpPath, join(storeDir, STATS_FILE));
|
|
202
|
-
} catch {
|
|
203
|
-
try { unlinkSync(tmpPath); } catch { /* ignore */ }
|
|
204
|
-
// Non-fatal: stats file write failure doesn't block the hook
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function readStats(): HookActivityStats {
|
|
209
|
-
const s = readStoredStats();
|
|
210
|
-
let topPolicy: string | null = null;
|
|
211
|
-
let topPolicyCount = 0;
|
|
212
|
-
for (const [name, count] of Object.entries(s.policyMap)) {
|
|
213
|
-
if (count > topPolicyCount) {
|
|
214
|
-
topPolicy = name;
|
|
215
|
-
topPolicyCount = count;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return { totalEvents: s.totalEvents, denyCount: s.denyCount, topPolicy, topPolicyCount };
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// ── Reading (lazy, per-page) ──
|
|
222
|
-
|
|
223
|
-
export function getHookActivityPage(page: number): HookActivityEntry[] {
|
|
224
|
-
ensureDir();
|
|
225
|
-
if (page < 1) return [];
|
|
226
|
-
|
|
227
|
-
if (page === 1) {
|
|
228
|
-
const currentPath = join(storeDir, CURRENT_FILE);
|
|
229
|
-
return readJsonlFile(currentPath).reverse();
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const archives = getArchiveFiles();
|
|
233
|
-
const archiveIndex = page - 2;
|
|
234
|
-
if (archiveIndex >= archives.length) return [];
|
|
235
|
-
|
|
236
|
-
return readJsonlFile(join(storeDir, archives[archiveIndex])).reverse();
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
export function getHookActivityPageCount(): number {
|
|
240
|
-
ensureDir();
|
|
241
|
-
return 1 + getArchiveFiles().length;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export function getAllHookActivityEntries(): HookActivityEntry[] {
|
|
245
|
-
ensureDir();
|
|
246
|
-
|
|
247
|
-
const currentPath = join(storeDir, CURRENT_FILE);
|
|
248
|
-
const currentEntries = readJsonlFile(currentPath).reverse();
|
|
249
|
-
|
|
250
|
-
const archives = getArchiveFiles();
|
|
251
|
-
const archiveEntries: HookActivityEntry[] = [];
|
|
252
|
-
for (const file of archives) {
|
|
253
|
-
const entries = readJsonlFile(join(storeDir, file));
|
|
254
|
-
archiveEntries.push(...entries.reverse());
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return [...currentEntries, ...archiveEntries];
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
export function searchHookActivity(
|
|
262
|
-
filters: HookActivityFilters,
|
|
263
|
-
page: number,
|
|
264
|
-
): { entries: HookActivityEntry[]; totalPages: number; page: number; stats: HookActivityStats } {
|
|
265
|
-
const all = getAllHookActivityEntries();
|
|
266
|
-
|
|
267
|
-
const filtered = all.filter((entry) => {
|
|
268
|
-
if (filters.decision && entry.decision !== filters.decision) return false;
|
|
269
|
-
if (filters.eventType && entry.eventType !== filters.eventType) return false;
|
|
270
|
-
if (
|
|
271
|
-
filters.policyName &&
|
|
272
|
-
(!entry.policyName || !entry.policyName.toLowerCase().includes(filters.policyName.toLowerCase()))
|
|
273
|
-
) {
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
if (
|
|
277
|
-
filters.sessionId &&
|
|
278
|
-
(!entry.sessionId || !entry.sessionId.toLowerCase().includes(filters.sessionId.toLowerCase()))
|
|
279
|
-
) {
|
|
280
|
-
return false;
|
|
281
|
-
}
|
|
282
|
-
return true;
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
const totalPages = Math.max(1, Math.ceil(filtered.length / PAGE_SIZE));
|
|
286
|
-
const start = (page - 1) * PAGE_SIZE;
|
|
287
|
-
const entries = filtered.slice(start, start + PAGE_SIZE);
|
|
288
|
-
// Stats come from the O(1) incremental stats file rather than a full rescan.
|
|
289
|
-
const stats = readStats();
|
|
290
|
-
|
|
291
|
-
return { entries, totalPages, page, stats };
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
export function getHookActivityHistory(page: number): {
|
|
295
|
-
entries: HookActivityEntry[];
|
|
296
|
-
totalPages: number;
|
|
297
|
-
page: number;
|
|
298
|
-
stats: HookActivityStats;
|
|
299
|
-
} {
|
|
300
|
-
const entries = getHookActivityPage(page);
|
|
301
|
-
const totalPages = getHookActivityPageCount();
|
|
302
|
-
// Stats come from the O(1) incremental stats file rather than a full rescan.
|
|
303
|
-
const stats = readStats();
|
|
304
|
-
return { entries, totalPages, page, stats };
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// ── Internal helpers ──
|
|
308
|
-
|
|
309
|
-
function readJsonlFile(filePath: string): HookActivityEntry[] {
|
|
310
|
-
const content = readFileSafe(filePath);
|
|
311
|
-
if (!content.trim()) return [];
|
|
312
|
-
|
|
313
|
-
const entries: HookActivityEntry[] = [];
|
|
314
|
-
for (const line of content.trim().split("\n")) {
|
|
315
|
-
try {
|
|
316
|
-
entries.push(JSON.parse(line) as HookActivityEntry);
|
|
317
|
-
} catch {
|
|
318
|
-
// Skip malformed lines
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
return entries;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
function getArchiveFiles(): string[] {
|
|
325
|
-
try {
|
|
326
|
-
const files = readdirSync(storeDir);
|
|
327
|
-
return files
|
|
328
|
-
.filter((f) => f.startsWith("page-") && f.endsWith(".jsonl"))
|
|
329
|
-
.sort((a, b) => {
|
|
330
|
-
const partsA = a.slice(5, -6).split("-");
|
|
331
|
-
const partsB = b.slice(5, -6).split("-");
|
|
332
|
-
const tsA = parseInt(partsA[0], 10);
|
|
333
|
-
const tsB = parseInt(partsB[0], 10);
|
|
334
|
-
if (tsA !== tsB) return tsB - tsA;
|
|
335
|
-
const seqA = partsA.length > 1 ? parseInt(partsA[1], 10) : 0;
|
|
336
|
-
const seqB = partsB.length > 1 ? parseInt(partsB[1], 10) : 0;
|
|
337
|
-
return seqB - seqA;
|
|
338
|
-
});
|
|
339
|
-
} catch {
|
|
340
|
-
return [];
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
// ── Test helpers ──
|
|
345
|
-
|
|
346
|
-
export function _resetForTest(testDir?: string): void {
|
|
347
|
-
rotateSeq = 0;
|
|
348
|
-
storeDir = testDir ?? DEFAULT_STORE_DIR;
|
|
349
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight logger for hook processes.
|
|
3
|
-
*
|
|
4
|
-
* ALL output goes to stderr (stdout is reserved for the hook JSON response
|
|
5
|
-
* that Claude Code reads).
|
|
6
|
-
*
|
|
7
|
-
* Optionally writes to a log file with size-based rotation.
|
|
8
|
-
*
|
|
9
|
-
* Env vars:
|
|
10
|
-
* FAILPROOFAI_LOG_LEVEL — info | warn | error (default: warn)
|
|
11
|
-
* FAILPROOFAI_HOOK_LOG_FILE — enable file logging:
|
|
12
|
-
* unset / "" → disabled (stderr only)
|
|
13
|
-
* "1" / "true" → enabled, writes to ~/.failproofai/logs/
|
|
14
|
-
* <path> → enabled, writes to that directory
|
|
15
|
-
*/
|
|
16
|
-
import {
|
|
17
|
-
appendFileSync,
|
|
18
|
-
renameSync,
|
|
19
|
-
mkdirSync,
|
|
20
|
-
existsSync,
|
|
21
|
-
statSync,
|
|
22
|
-
} from "node:fs";
|
|
23
|
-
import { join } from "node:path";
|
|
24
|
-
import { homedir } from "node:os";
|
|
25
|
-
|
|
26
|
-
export type LogLevel = "info" | "warn" | "error";
|
|
27
|
-
|
|
28
|
-
const LEVEL_ORDER: Record<LogLevel, number> = { info: 0, warn: 1, error: 2 };
|
|
29
|
-
const MAX_FILE_SIZE = 512 * 1024; // 500 KB
|
|
30
|
-
const LOG_FILENAME = "hooks.log";
|
|
31
|
-
const DEFAULT_LOG_DIR = join(homedir(), ".failproofai", "logs");
|
|
32
|
-
|
|
33
|
-
// ── State (lazy-initialized) ──
|
|
34
|
-
|
|
35
|
-
let resolved = false;
|
|
36
|
-
let currentLevel: LogLevel = "warn";
|
|
37
|
-
let fileLoggingEnabled = false;
|
|
38
|
-
let logDir = DEFAULT_LOG_DIR;
|
|
39
|
-
|
|
40
|
-
function ensureResolved(): void {
|
|
41
|
-
if (resolved) return;
|
|
42
|
-
resolved = true;
|
|
43
|
-
|
|
44
|
-
// Log level
|
|
45
|
-
const rawLevel = (process.env.FAILPROOFAI_LOG_LEVEL ?? "").toLowerCase();
|
|
46
|
-
if (rawLevel === "info" || rawLevel === "warn" || rawLevel === "error") {
|
|
47
|
-
currentLevel = rawLevel;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// File logging
|
|
51
|
-
const rawFile = (process.env.FAILPROOFAI_HOOK_LOG_FILE ?? "").trim();
|
|
52
|
-
if (rawFile) {
|
|
53
|
-
fileLoggingEnabled = true;
|
|
54
|
-
if (rawFile !== "1" && rawFile !== "true") {
|
|
55
|
-
logDir = rawFile;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function shouldEmit(level: LogLevel): boolean {
|
|
61
|
-
ensureResolved();
|
|
62
|
-
return LEVEL_ORDER[level] >= LEVEL_ORDER[currentLevel];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// ── Stderr output ──
|
|
66
|
-
|
|
67
|
-
function emitStderr(label: string, msg: string): void {
|
|
68
|
-
process.stderr.write(`[failproofai:hook] ${label} ${msg}\n`);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// ── File output (synchronous — hook processes are short-lived) ──
|
|
72
|
-
|
|
73
|
-
function ensureLogDir(): void {
|
|
74
|
-
if (!existsSync(logDir)) {
|
|
75
|
-
mkdirSync(logDir, { recursive: true });
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function rotateIfNeeded(filePath: string): void {
|
|
80
|
-
try {
|
|
81
|
-
const stats = statSync(filePath);
|
|
82
|
-
if (stats.size >= MAX_FILE_SIZE) {
|
|
83
|
-
const archiveName = `hooks-${Date.now()}.log`;
|
|
84
|
-
renameSync(filePath, join(logDir, archiveName));
|
|
85
|
-
}
|
|
86
|
-
} catch {
|
|
87
|
-
// File doesn't exist yet — nothing to rotate
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function appendToFile(label: string, msg: string): void {
|
|
92
|
-
if (!fileLoggingEnabled) return;
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
ensureLogDir();
|
|
96
|
-
const filePath = join(logDir, LOG_FILENAME);
|
|
97
|
-
rotateIfNeeded(filePath);
|
|
98
|
-
|
|
99
|
-
const timestamp = new Date().toISOString();
|
|
100
|
-
const line = `[${timestamp}] ${label} ${msg}\n`;
|
|
101
|
-
appendFileSync(filePath, line, "utf-8");
|
|
102
|
-
} catch {
|
|
103
|
-
// File logging is best-effort — never fail the hook
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// ── Public API ──
|
|
108
|
-
|
|
109
|
-
export function hookLogInfo(msg: string): void {
|
|
110
|
-
if (!shouldEmit("info")) return;
|
|
111
|
-
emitStderr("INFO", msg);
|
|
112
|
-
appendToFile("INFO", msg);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export function hookLogWarn(msg: string): void {
|
|
116
|
-
if (!shouldEmit("warn")) return;
|
|
117
|
-
emitStderr("WARN", msg);
|
|
118
|
-
appendToFile("WARN", msg);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function hookLogError(msg: string): void {
|
|
122
|
-
if (!shouldEmit("error")) return;
|
|
123
|
-
emitStderr("ERROR", msg);
|
|
124
|
-
appendToFile("ERROR", msg);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** Reset internal state (for testing only). */
|
|
128
|
-
export function _resetHookLogger(): void {
|
|
129
|
-
resolved = false;
|
|
130
|
-
currentLevel = "warn";
|
|
131
|
-
fileLoggingEnabled = false;
|
|
132
|
-
logDir = DEFAULT_LOG_DIR;
|
|
133
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight PostHog telemetry for the compiled hook binary.
|
|
3
|
-
*
|
|
4
|
-
* Uses fetch() directly instead of posthog-node, since the binary
|
|
5
|
-
* doesn't have access to node_modules at runtime.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { version } from "../../package.json";
|
|
9
|
-
import { POSTHOG_API_KEY } from "../posthog-key";
|
|
10
|
-
|
|
11
|
-
const API_KEY = POSTHOG_API_KEY;
|
|
12
|
-
const CAPTURE_URL = "https://us.i.posthog.com/capture/";
|
|
13
|
-
|
|
14
|
-
export async function trackHookEvent(
|
|
15
|
-
distinctId: string,
|
|
16
|
-
event: string,
|
|
17
|
-
properties?: Record<string, unknown>,
|
|
18
|
-
): Promise<void> {
|
|
19
|
-
if (process.env.FAILPROOFAI_TELEMETRY_DISABLED === "1") return;
|
|
20
|
-
|
|
21
|
-
const body = JSON.stringify({
|
|
22
|
-
api_key: process.env.FAILPROOFAI_POSTHOG_KEY ?? API_KEY,
|
|
23
|
-
event,
|
|
24
|
-
distinct_id: distinctId,
|
|
25
|
-
properties: { ...properties, $lib: "failproofai-hooks", failproofai_version: version },
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
await fetch(
|
|
30
|
-
process.env.FAILPROOFAI_POSTHOG_HOST
|
|
31
|
-
? `${process.env.FAILPROOFAI_POSTHOG_HOST}/capture/`
|
|
32
|
-
: CAPTURE_URL,
|
|
33
|
-
{
|
|
34
|
-
method: "POST",
|
|
35
|
-
headers: { "Content-Type": "application/json" },
|
|
36
|
-
body,
|
|
37
|
-
signal: AbortSignal.timeout(5000),
|
|
38
|
-
},
|
|
39
|
-
);
|
|
40
|
-
} catch {
|
|
41
|
-
// Telemetry is best-effort — never fail the hook
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Read/write the hooks configuration file at ~/.failproofai/policies-config.json.
|
|
3
|
-
*/
|
|
4
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "node:fs";
|
|
5
|
-
import { resolve, dirname } from "node:path";
|
|
6
|
-
import { homedir } from "node:os";
|
|
7
|
-
import type { HooksConfig } from "./policy-types";
|
|
8
|
-
import type { HookScope } from "./types";
|
|
9
|
-
import { hookLogInfo, hookLogWarn } from "./hook-logger";
|
|
10
|
-
|
|
11
|
-
function readConfigAt(path: string): Partial<HooksConfig> {
|
|
12
|
-
if (!existsSync(path)) return {};
|
|
13
|
-
try {
|
|
14
|
-
const raw = readFileSync(path, "utf8");
|
|
15
|
-
return JSON.parse(raw) as Partial<HooksConfig>;
|
|
16
|
-
} catch (err) {
|
|
17
|
-
hookLogWarn(`failed to parse config at ${path}: ${err instanceof Error ? err.message : String(err)}`);
|
|
18
|
-
return {};
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Read and merge hooks config from three scopes in priority order:
|
|
24
|
-
* 1. {cwd}/.failproofai/policies-config.json (project)
|
|
25
|
-
* 2. {cwd}/.failproofai/policies-config.local.json (local)
|
|
26
|
-
* 3. ~/.failproofai/policies-config.json (global)
|
|
27
|
-
*
|
|
28
|
-
* Merge rules:
|
|
29
|
-
* enabledPolicies: union + dedup across all three
|
|
30
|
-
* policyParams: per-policy key, first scope that defines it wins entirely
|
|
31
|
-
* customPoliciesPath: first scope that defines it wins
|
|
32
|
-
* llm: first scope that defines it wins
|
|
33
|
-
*/
|
|
34
|
-
export function readMergedHooksConfig(cwd?: string): HooksConfig {
|
|
35
|
-
const base = cwd ? resolve(cwd) : process.cwd();
|
|
36
|
-
const projectPath = resolve(base, ".failproofai", "policies-config.json");
|
|
37
|
-
const localPath = resolve(base, ".failproofai", "policies-config.local.json");
|
|
38
|
-
const globalPath = resolve(homedir(), ".failproofai", "policies-config.json");
|
|
39
|
-
|
|
40
|
-
const project = readConfigAt(projectPath);
|
|
41
|
-
const local = readConfigAt(localPath);
|
|
42
|
-
const global_ = readConfigAt(globalPath);
|
|
43
|
-
|
|
44
|
-
// enabledPolicies: union + dedup
|
|
45
|
-
const enabledSet = new Set<string>([
|
|
46
|
-
...(project.enabledPolicies ?? []),
|
|
47
|
-
...(local.enabledPolicies ?? []),
|
|
48
|
-
...(global_.enabledPolicies ?? []),
|
|
49
|
-
]);
|
|
50
|
-
|
|
51
|
-
// policyParams: per-policy, first scope wins
|
|
52
|
-
const mergedParams: Record<string, Record<string, unknown>> = {};
|
|
53
|
-
for (const scope of [project, local, global_]) {
|
|
54
|
-
if (!scope.policyParams) continue;
|
|
55
|
-
for (const [policyName, params] of Object.entries(scope.policyParams)) {
|
|
56
|
-
if (!(policyName in mergedParams)) {
|
|
57
|
-
mergedParams[policyName] = params;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// customPoliciesPath: first scope wins
|
|
63
|
-
const customPoliciesPath =
|
|
64
|
-
project.customPoliciesPath ?? local.customPoliciesPath ?? global_.customPoliciesPath;
|
|
65
|
-
|
|
66
|
-
// llm: first scope wins
|
|
67
|
-
const llm = project.llm ?? local.llm ?? global_.llm;
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
enabledPolicies: [...enabledSet],
|
|
71
|
-
...(Object.keys(mergedParams).length > 0 ? { policyParams: mergedParams } : {}),
|
|
72
|
-
...(customPoliciesPath !== undefined ? { customPoliciesPath } : {}),
|
|
73
|
-
...(llm !== undefined ? { llm } : {}),
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function getConfigPath(): string {
|
|
78
|
-
return resolve(homedir(), ".failproofai", "policies-config.json");
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function readHooksConfig(): HooksConfig {
|
|
82
|
-
const configPath = getConfigPath();
|
|
83
|
-
if (!existsSync(configPath)) {
|
|
84
|
-
return { enabledPolicies: [] };
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
const raw = readFileSync(configPath, "utf8");
|
|
88
|
-
return JSON.parse(raw) as HooksConfig;
|
|
89
|
-
} catch (err) {
|
|
90
|
-
hookLogWarn(`failed to parse config at ${configPath}: ${err instanceof Error ? err.message : String(err)}`);
|
|
91
|
-
return { enabledPolicies: [] };
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function writeHooksConfig(config: HooksConfig): void {
|
|
96
|
-
const configPath = getConfigPath();
|
|
97
|
-
const dir = dirname(configPath);
|
|
98
|
-
if (!existsSync(dir)) {
|
|
99
|
-
mkdirSync(dir, { recursive: true });
|
|
100
|
-
}
|
|
101
|
-
writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n", "utf8");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Resolve the policies-config path for a specific scope.
|
|
106
|
-
*/
|
|
107
|
-
export function getConfigPathForScope(scope: HookScope, cwd?: string): string {
|
|
108
|
-
const base = cwd ? resolve(cwd) : process.cwd();
|
|
109
|
-
switch (scope) {
|
|
110
|
-
case "user":
|
|
111
|
-
return resolve(homedir(), ".failproofai", "policies-config.json");
|
|
112
|
-
case "project":
|
|
113
|
-
return resolve(base, ".failproofai", "policies-config.json");
|
|
114
|
-
case "local":
|
|
115
|
-
return resolve(base, ".failproofai", "policies-config.local.json");
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Read hooks config from a single specific scope (not merged).
|
|
121
|
-
*/
|
|
122
|
-
export function readScopedHooksConfig(scope: HookScope, cwd?: string): HooksConfig {
|
|
123
|
-
const configPath = getConfigPathForScope(scope, cwd);
|
|
124
|
-
if (!existsSync(configPath)) {
|
|
125
|
-
return { enabledPolicies: [] };
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
const raw = readFileSync(configPath, "utf8");
|
|
129
|
-
return JSON.parse(raw) as HooksConfig;
|
|
130
|
-
} catch (err) {
|
|
131
|
-
hookLogWarn(`failed to parse config at ${configPath}: ${err instanceof Error ? err.message : String(err)}`);
|
|
132
|
-
return { enabledPolicies: [] };
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Write hooks config to the scope-appropriate path.
|
|
138
|
-
*/
|
|
139
|
-
export function writeScopedHooksConfig(config: HooksConfig, scope: HookScope, cwd?: string): void {
|
|
140
|
-
const configPath = getConfigPathForScope(scope, cwd);
|
|
141
|
-
const dir = dirname(configPath);
|
|
142
|
-
if (!existsSync(dir)) {
|
|
143
|
-
mkdirSync(dir, { recursive: true });
|
|
144
|
-
}
|
|
145
|
-
writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n", "utf8");
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export interface ResolvedLlmConfig {
|
|
149
|
-
baseUrl: string;
|
|
150
|
-
apiKey: string;
|
|
151
|
-
model: string;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export function readLlmConfig(cwd?: string): ResolvedLlmConfig | null {
|
|
155
|
-
const config = readMergedHooksConfig(cwd);
|
|
156
|
-
const baseUrl =
|
|
157
|
-
process.env.FAILPROOFAI_LLM_BASE_URL ?? config.llm?.baseUrl ?? "https://api.openai.com/v1";
|
|
158
|
-
const apiKey = process.env.FAILPROOFAI_LLM_API_KEY ?? config.llm?.apiKey;
|
|
159
|
-
const model = process.env.FAILPROOFAI_LLM_MODEL ?? config.llm?.model ?? "gpt-4o-mini";
|
|
160
|
-
const apiKeySource = process.env.FAILPROOFAI_LLM_API_KEY ? "env" : config.llm?.apiKey ? "file" : "missing";
|
|
161
|
-
const baseUrlSource = process.env.FAILPROOFAI_LLM_BASE_URL ? "env" : config.llm?.baseUrl ? "file" : "default";
|
|
162
|
-
const modelSource = process.env.FAILPROOFAI_LLM_MODEL ? "env" : config.llm?.model ? "file" : "default";
|
|
163
|
-
hookLogInfo(`llm-config: apiKey=${apiKeySource} baseUrl=${baseUrlSource}(${baseUrl}) model=${modelSource}(${model})`);
|
|
164
|
-
if (!apiKey) return null;
|
|
165
|
-
return { baseUrl, apiKey, model };
|
|
166
|
-
}
|