failproofai 1.0.0-beta.4 → 1.0.0-beta.6
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/app-path-routes-manifest.json +2 -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 +1 -1
- package/.next/standalone/.next/routes-manifest.json +6 -0
- 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 +3 -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 +3 -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 +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/_head.segment.rsc +4 -4
- package/.next/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +10 -10
- 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/api/audit/invite/route.js +3 -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 +4 -3
- 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 +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 +2 -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 +3 -2
- 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 +3 -2
- package/.next/standalone/.next/server/app/api/auth/logout/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/reminder/route.js +3 -2
- package/.next/standalone/.next/server/app/api/auth/reminder/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/status/route.js +3 -2
- 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 +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 +5 -3
- 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 +2 -2
- package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +15 -15
- package/.next/standalone/.next/server/app/index.segments/_head.segment.rsc +4 -4
- package/.next/standalone/.next/server/app/index.segments/_index.segment.rsc +10 -10
- 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 +3 -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 +10 -10
- package/.next/standalone/.next/server/app/policies/page.js +4 -2
- 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 +4 -2
- 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 +6 -4
- 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 +4 -2
- 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/app-paths-manifest.json +3 -0
- package/.next/standalone/.next/server/app/settings/page/build-manifest.json +18 -0
- package/.next/standalone/.next/server/app/settings/page/next-font-manifest.json +6 -0
- package/.next/standalone/.next/server/app/settings/page/react-loadable-manifest.json +1 -0
- package/.next/standalone/.next/server/app/settings/page/server-reference-manifest.json +53 -0
- package/.next/standalone/.next/server/app/settings/page.js +18 -0
- package/.next/standalone/.next/server/app/settings/page.js.map +5 -0
- package/.next/standalone/.next/server/app/settings/page.js.nft.json +1 -0
- package/.next/standalone/.next/server/app/settings/page_client-reference-manifest.js +3 -0
- package/.next/standalone/.next/server/app-paths-manifest.json +2 -1
- package/.next/standalone/.next/server/chunks/{[externals]__1nl3dvw._.js → [externals]__0r-zamh._.js} +2 -2
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__06hexd0._.js +3 -0
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__094p1f1._.js +3 -0
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__0_0xu5z._.js +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__0ed01_d._.js +3 -0
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__0g0vcwt._.js +3 -0
- package/.next/standalone/.next/server/chunks/{[root-of-the-server]__0h3lfmp._.js → [root-of-the-server]__0ky_n0r._.js} +2 -2
- package/.next/standalone/.next/server/chunks/{[root-of-the-server]__18d-9oi._.js → [root-of-the-server]__0lk_935._.js} +2 -2
- package/.next/standalone/.next/server/chunks/{[root-of-the-server]__1p7s8-d._.js → [root-of-the-server]__0pbp9fe._.js} +2 -2
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__0q-v9z2._.js +1 -1
- package/.next/standalone/.next/server/chunks/{[root-of-the-server]__10oa-v9._.js → [root-of-the-server]__0v2fpxe._.js} +2 -2
- package/.next/standalone/.next/server/chunks/{[root-of-the-server]__0sb_5m8._.js → [root-of-the-server]__131ebum._.js} +3 -3
- package/.next/standalone/.next/server/chunks/{[root-of-the-server]__0-dh5jy._.js → [root-of-the-server]__1_ps0jw._.js} +2 -2
- package/.next/standalone/.next/server/chunks/{[root-of-the-server]__0l4vuqm._.js → [root-of-the-server]__1a7i2q4._.js} +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__1ibjy5x._.js +3 -0
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__1iny24d._.js +3 -0
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__1tvn4wf._.js +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__1tyedjt._.js +3 -0
- package/.next/standalone/.next/server/chunks/_0lxbzdq._.js +5 -0
- package/.next/standalone/.next/server/chunks/_1zuiiy3._.js +5 -0
- package/.next/standalone/.next/server/chunks/lib_telemetry_ts_0dctyyw._.js +5 -0
- package/.next/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_17k9e3w.js +5 -5
- package/.next/standalone/.next/server/chunks/package_json_[json]_cjs_1nxcc4v._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__06bp_fg._.js +5 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__074qmkp._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0spkm68._.js +10 -10
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1_a_gwn._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1a2hcb_._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1e7-pa7._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__0rtdfof._.js → [root-of-the-server]__1rdruw4._.js} +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1rv-sc9._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1tyf0tc._.js +5 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1u-wx42._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1v185mo._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__0rag5dg._.js → [root-of-the-server]__1yw368c._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/_0-yi74u._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_04mekdy._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_0igtyj5._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_0r-dsre._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_0rjgfln._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_0se484m._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_0uz7o9y._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_11_p9y8._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_1fahg9e._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_1gmzkwj._.js +5 -0
- package/.next/standalone/.next/server/chunks/ssr/_1w8sola._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_1w_6p9g._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/app_audit__components_audit-dashboard_tsx_0p9ud47._.js +2 -2
- 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/node_modules_next_dist_esm_build_templates_app-page_0dwo94s.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_builtin-policies_ts_09j2ndl._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_fp-config_ts_04t589g._.js +5 -0
- package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
- package/.next/standalone/.next/server/middleware.js +2 -2
- 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 +54 -12
- package/.next/standalone/.next/static/chunks/{2c90h1g6x8z8y.js → 0_2n13i94rnw5.js} +1 -1
- package/.next/standalone/.next/static/chunks/1bm0q12hgs22l.css +2 -0
- package/.next/standalone/.next/static/chunks/1v1gqvpjk62jm.js +1 -0
- package/.next/standalone/.next/static/chunks/23557z4e6dtsr.js +1 -0
- package/.next/standalone/.next/static/chunks/28zkwzu50puki.js +1 -0
- package/.next/standalone/.next/static/chunks/2uvhw57mf9lg_.css +2 -0
- package/.next/standalone/.next/static/chunks/3081gykdubv8b.js +1 -0
- package/.next/standalone/.next/static/chunks/{06jakt_xhoolk.js → 34fa65k0cldkj.js} +1 -1
- package/.next/standalone/.next/static/chunks/35v07j9gc1pvr.js +6 -0
- package/.next/standalone/.next/static/chunks/{2zb3m1tzq6h98.js → 3f_939wi3kfnx.js} +22 -22
- package/.next/standalone/.next/static/chunks/{31cqiv_cpgj9m.js → 3p1vpm2_-tfwm.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0ue9ak_xexiqh.js → 3rbpw_waieafm.js} +1 -1
- package/.next/standalone/.next/static/chunks/40ffnfpkeyvb0.js +1 -0
- package/.next/standalone/app/actions/get-hooks-config.ts +2 -1
- package/.next/standalone/app/actions/get-scheduled-audit.ts +70 -0
- package/.next/standalone/app/actions/update-scheduled-audit.ts +44 -0
- package/.next/standalone/app/api/audit/run/route.ts +28 -0
- package/.next/standalone/app/api/audit/status/route.ts +13 -1
- package/.next/standalone/app/api/auth/status/route.ts +1 -1
- package/.next/standalone/app/audit/_components/auth-dialog.css +159 -0
- package/.next/standalone/app/audit/_components/auth-dialog.tsx +3 -0
- package/.next/standalone/app/audit/audit-styles.css +6 -149
- package/.next/standalone/app/settings/page.tsx +31 -0
- package/.next/standalone/app/settings/settings-client.tsx +488 -0
- package/.next/standalone/components/navbar.tsx +2 -0
- package/.next/standalone/lib/auth/api-server-client.ts +2 -3
- package/.next/standalone/lib/auth/auth-store.ts +4 -4
- package/.next/standalone/lib/codex-sessions.ts +2 -1
- package/.next/standalone/lib/dashboard-host.ts +101 -0
- package/.next/standalone/lib/install-check.ts +22 -7
- package/.next/standalone/lib/pi-sessions.ts +99 -14
- package/.next/standalone/lib/telemetry-enabled.ts +54 -0
- package/.next/standalone/lib/telemetry-id.ts +52 -1
- package/.next/standalone/lib/telemetry.ts +8 -4
- package/.next/standalone/node_modules/react/cjs/react.development.js +1 -1
- package/.next/standalone/node_modules/react/cjs/react.production.js +1 -1
- package/.next/standalone/node_modules/react/package.json +3 -3
- package/.next/standalone/node_modules/react-dom/cjs/react-dom-server-legacy.browser.production.js +1 -1
- package/.next/standalone/node_modules/react-dom/cjs/react-dom-server-legacy.node.production.js +1 -1
- package/.next/standalone/node_modules/react-dom/cjs/react-dom-server.browser.production.js +3 -3
- package/.next/standalone/node_modules/react-dom/cjs/react-dom-server.edge.production.js +3 -3
- package/.next/standalone/node_modules/react-dom/cjs/react-dom-server.node.production.js +3 -3
- package/.next/standalone/node_modules/react-dom/cjs/react-dom.production.js +1 -1
- package/.next/standalone/node_modules/react-dom/package.json +4 -4
- package/.next/standalone/package.json +7 -6
- package/.next/standalone/proxy.ts +89 -1
- package/.next/standalone/server.js +1 -1
- package/bin/failproofai.mjs +197 -80
- package/dist/cli.mjs +17699 -15345
- package/dist/worker.mjs +1620 -257
- package/lib/auth/api-server-client.ts +2 -3
- package/lib/auth/auth-store.ts +4 -4
- package/lib/codex-sessions.ts +2 -1
- package/lib/dashboard-host.ts +101 -0
- package/lib/install-check.ts +22 -7
- package/lib/pi-sessions.ts +99 -14
- package/lib/telemetry-enabled.ts +54 -0
- package/lib/telemetry-id.ts +52 -1
- package/lib/telemetry.ts +8 -4
- package/package.json +7 -6
- package/scripts/install-telemetry.mjs +8 -1
- package/scripts/launch.ts +25 -3
- package/scripts/parse-script-args.ts +17 -1
- package/scripts/prune-standalone.mjs +20 -0
- package/scripts/translate-docs/readme-translator.ts +163 -4
- package/scripts/validate-mdx.ts +153 -13
- package/src/audit/audit-lock.ts +285 -0
- package/src/audit/audit-schedule.ts +111 -0
- package/src/audit/cache.ts +18 -4
- package/src/audit/cli-adapters/goose.ts +2 -1
- package/src/audit/cli-adapters/hermes.ts +28 -10
- package/src/audit/cli.ts +191 -35
- package/src/audit/dashboard-cache.ts +2 -1
- package/src/hooks/builtin-policies.ts +100 -3
- package/src/hooks/cloud-connection.ts +163 -14
- package/src/hooks/cloud-enrollment-cli.ts +119 -21
- package/src/hooks/cloud-enrollment.ts +87 -17
- package/src/hooks/cloud-introspect.ts +147 -0
- package/src/hooks/cloud-managed-policies.ts +33 -2
- package/src/hooks/collector-config.ts +32 -40
- package/src/hooks/configure-wizard.ts +696 -318
- package/src/hooks/custom-hooks-loader.ts +125 -11
- package/src/hooks/daemon-client.ts +83 -17
- package/src/hooks/daemon-download.ts +54 -2
- package/src/hooks/daemon-service.ts +595 -27
- package/src/hooks/first-run-gate.ts +39 -0
- package/src/hooks/fp-config.ts +497 -0
- package/src/hooks/fp-home.ts +342 -0
- package/src/hooks/fp-reset.ts +332 -0
- package/src/hooks/handler.ts +42 -1
- package/src/hooks/hook-activity-store.ts +35 -20
- package/src/hooks/hook-logger.ts +2 -1
- package/src/hooks/hook-telemetry.ts +5 -1
- package/src/hooks/hooks-config.ts +4 -3
- package/src/hooks/loader-utils.ts +166 -5
- package/src/hooks/manager.ts +5 -4
- package/src/hooks/onboarding-lock.ts +119 -0
- package/src/hooks/policy-types.ts +0 -7
- package/src/hooks/session-pause-cli.ts +15 -13
- package/src/hooks/session-pause.ts +36 -4
- package/src/hooks/setup-state.ts +256 -0
- package/src/hooks/tui.ts +4 -4
- package/src/hooks/worker-server.ts +53 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__0f8nu8d._.js +0 -3
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__0szqzl8._.js +0 -3
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__17g9wh7._.js +0 -3
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__19120tr._.js +0 -3
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__1fwl2mz._.js +0 -3
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__1myjm-d._.js +0 -3
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__1rhmvod._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__02r5bgf._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0cmdyn_._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0e8sjqm._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0lkzqax._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0ls0gsr._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0n_uvv0._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0qucxyj._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0sdrz-j._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0u02miy._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__14dd6h8._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1j4u3yd._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1zqz4v8._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/_1m_p7pi._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/node_modules_html-to-image_es_index_1q9xxca.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_1ezd2jf._.js +0 -5
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_1tnuifj._.js +0 -5
- package/.next/standalone/.next/static/chunks/0h7auy7hzjyhw.js +0 -1
- package/.next/standalone/.next/static/chunks/0oe2-hp0_2tzs.js +0 -6
- package/.next/standalone/.next/static/chunks/1fw3pxobk_otl.js +0 -1
- package/.next/standalone/.next/static/chunks/3h5_3u46gu9jx.js +0 -1
- package/.next/standalone/.next/static/chunks/3i27c3hcriawq.css +0 -1
- package/.next/standalone/.next/static/chunks/3zdwnnthucs_1.css +0 -2
- package/.next/standalone/.next/static/chunks/43a1ywqsg9bq9.js +0 -1
- package/.next/standalone/Cargo.lock +0 -2222
- package/.next/standalone/Cargo.toml +0 -9
- package/.next/standalone/crates/CLOUD_POLICIES.md +0 -136
- package/.next/standalone/crates/PROTOCOL.md +0 -122
- package/.next/standalone/crates/failproofaid/Cargo.toml +0 -25
- package/.next/standalone/crates/failproofaid/src/cloud_client.rs +0 -484
- package/.next/standalone/crates/failproofaid/src/cloud_policies.rs +0 -921
- package/.next/standalone/crates/failproofaid/src/lock.rs +0 -81
- package/.next/standalone/crates/failproofaid/src/main.rs +0 -532
- package/.next/standalone/crates/failproofaid/src/paths.rs +0 -201
- package/.next/standalone/crates/failproofaid/src/server.rs +0 -502
- package/.next/standalone/crates/failproofaid/src/worker.rs +0 -400
- package/.next/standalone/crates/failproofaid/tests/daemon_e2e.rs +0 -241
- package/.next/standalone/crates/fpai-collect/Cargo.toml +0 -43
- package/.next/standalone/crates/fpai-collect/src/config.rs +0 -412
- package/.next/standalone/crates/fpai-collect/src/cursor.rs +0 -520
- package/.next/standalone/crates/fpai-collect/src/delivery.rs +0 -472
- package/.next/standalone/crates/fpai-collect/src/filetail.rs +0 -484
- package/.next/standalone/crates/fpai-collect/src/health.rs +0 -369
- package/.next/standalone/crates/fpai-collect/src/lib.rs +0 -34
- package/.next/standalone/crates/fpai-collect/src/redact.rs +0 -516
- package/.next/standalone/crates/fpai-collect/src/sources/claude/mod.rs +0 -279
- package/.next/standalone/crates/fpai-collect/src/sources/claude/transform.rs +0 -619
- package/.next/standalone/crates/fpai-collect/src/sources/codex/mod.rs +0 -156
- package/.next/standalone/crates/fpai-collect/src/sources/codex/transform.rs +0 -715
- package/.next/standalone/crates/fpai-collect/src/sources/copilot/mod.rs +0 -158
- package/.next/standalone/crates/fpai-collect/src/sources/copilot/transform.rs +0 -512
- package/.next/standalone/crates/fpai-collect/src/sources/goose/mod.rs +0 -511
- package/.next/standalone/crates/fpai-collect/src/sources/goose/transform.rs +0 -586
- package/.next/standalone/crates/fpai-collect/src/sources/hermes/mod.rs +0 -318
- package/.next/standalone/crates/fpai-collect/src/sources/hermes/transform.rs +0 -579
- package/.next/standalone/crates/fpai-collect/src/sources/hooks/mod.rs +0 -310
- package/.next/standalone/crates/fpai-collect/src/sources/hooks/transform.rs +0 -448
- package/.next/standalone/crates/fpai-collect/src/sources/mod.rs +0 -23
- package/.next/standalone/crates/fpai-collect/src/sources/openclaw/mod.rs +0 -176
- package/.next/standalone/crates/fpai-collect/src/sources/openclaw/transform.rs +0 -500
- package/.next/standalone/crates/fpai-collect/src/sources/opencode/mod.rs +0 -315
- package/.next/standalone/crates/fpai-collect/src/sources/opencode/transform.rs +0 -493
- package/.next/standalone/crates/fpai-collect/src/sources/pi/mod.rs +0 -201
- package/.next/standalone/crates/fpai-collect/src/sources/pi/transform.rs +0 -533
- package/.next/standalone/crates/fpai-collect/src/spool.rs +0 -458
- package/.next/standalone/crates/fpai-collect/src/sqlitepoll.rs +0 -387
- package/.next/standalone/crates/fpai-collect/src/supervisor.rs +0 -423
- package/.next/standalone/crates/fpai-collect/src/uploader.rs +0 -600
- package/.next/standalone/crates/fpai-collect/tests/claude_source.rs +0 -738
- package/.next/standalone/crates/fpai-collect/tests/claude_subagents.rs +0 -393
- package/.next/standalone/crates/fpai-collect/tests/codex_source.rs +0 -975
- package/.next/standalone/crates/fpai-collect/tests/config.rs +0 -286
- package/.next/standalone/crates/fpai-collect/tests/copilot_source.rs +0 -1019
- package/.next/standalone/crates/fpai-collect/tests/delivery.rs +0 -281
- package/.next/standalone/crates/fpai-collect/tests/goose_source.rs +0 -1008
- package/.next/standalone/crates/fpai-collect/tests/hermes_source.rs +0 -1129
- package/.next/standalone/crates/fpai-collect/tests/hooks_source.rs +0 -621
- package/.next/standalone/crates/fpai-collect/tests/openclaw_source.rs +0 -854
- package/.next/standalone/crates/fpai-collect/tests/opencode_source.rs +0 -1478
- package/.next/standalone/crates/fpai-collect/tests/pi_source.rs +0 -1191
- package/.next/standalone/crates/fpai-collect/tests/supervisor.rs +0 -290
- package/.next/standalone/crates/fpai-collect/tests/uploader.rs +0 -506
- package/.next/standalone/crates/fpai-ipc/Cargo.toml +0 -16
- package/.next/standalone/crates/fpai-ipc/src/envelope.rs +0 -175
- package/.next/standalone/crates/fpai-ipc/src/framing.rs +0 -177
- package/.next/standalone/crates/fpai-ipc/src/lib.rs +0 -10
- package/.next/standalone/crates/fpai-ipc/src/peer.rs +0 -80
- package/.next/standalone/docker-hook-sync/Dockerfile +0 -79
- package/.next/standalone/docker-hook-sync/entrypoint.sh +0 -109
- package/.next/standalone/integration-suite/Dockerfile +0 -47
- package/.next/standalone/integration-suite/README.md +0 -129
- package/.next/standalone/integration-suite/canary-policies.mjs +0 -45
- package/.next/standalone/integration-suite/capture-tokens.sh +0 -48
- package/.next/standalone/integration-suite/ci-entrypoint.sh +0 -179
- package/.next/standalone/integration-suite/inject-tokens.sh +0 -44
- package/.next/standalone/integration-suite/install-clis.sh +0 -136
- package/.next/standalone/integration-suite/probe-cli.sh +0 -248
- package/.next/standalone/integration-suite/report.js +0 -120
- package/.next/standalone/integration-suite/run.sh +0 -159
- package/.next/standalone/openclaw-plugin/index.js +0 -223
- package/.next/standalone/openclaw-plugin/openclaw.plugin.json +0 -6
- package/.next/standalone/openclaw-plugin/package.json +0 -12
- package/.next/standalone/osv-scanner.toml +0 -17
- package/.next/standalone/pi-extension/index.ts +0 -524
- package/.next/standalone/pi-extension/package.json +0 -12
- package/.next/standalone/postcss.config.mjs +0 -8
- package/.next/standalone/readme-arch-hq.gif +0 -0
- package/.next/standalone/rust-toolchain.toml +0 -4
- package/src/auth/cli.ts +0 -371
- /package/.next/standalone/.next/static/{StV6Lay7Q1cU4ysYCFJmH → Ptn8aBQl_cnNgOd0ebyv0}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{StV6Lay7Q1cU4ysYCFJmH → Ptn8aBQl_cnNgOd0ebyv0}/_clientMiddlewareManifest.js +0 -0
- /package/.next/standalone/.next/static/{StV6Lay7Q1cU4ysYCFJmH → Ptn8aBQl_cnNgOd0ebyv0}/_ssgManifest.js +0 -0
|
@@ -23,6 +23,9 @@ import { execFileSync } from "node:child_process";
|
|
|
23
23
|
import { hookLogWarn } from "./hook-logger";
|
|
24
24
|
import { getConfigPathForScope } from "./hooks-config";
|
|
25
25
|
import { downloadFailproofaidBinary, installFromNpmPackage, installedBinaryPath } from "./daemon-download";
|
|
26
|
+
import { logsDir } from "./fp-home";
|
|
27
|
+
import { version } from "../../package.json";
|
|
28
|
+
import { readVersionFile, updateConfig, writeVersionFile } from "./fp-config";
|
|
26
29
|
|
|
27
30
|
/**
|
|
28
31
|
* Every `systemctl --user` / `launchctl` call is bounded. Both talk to a
|
|
@@ -76,19 +79,16 @@ const SUDO_PROMPT_TIMEOUT_MS = 120_000;
|
|
|
76
79
|
* Global scope only: whether *this machine* runs a daemon is not a
|
|
77
80
|
* per-project setting.
|
|
78
81
|
*/
|
|
79
|
-
export function setDaemonConfigured(value: boolean): void {
|
|
80
|
-
const path = getConfigPathForScope("user");
|
|
81
|
-
let config: Record<string, unknown> = {};
|
|
82
|
+
export function setDaemonConfigured(value: boolean, installedVersion?: string): void {
|
|
82
83
|
try {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
writeFileSync(path, JSON.stringify(config, null, 2) + "\n", "utf8");
|
|
84
|
+
updateConfig({ daemon: { configured: value } });
|
|
85
|
+
// The version lives in VERSION, not here. One file is ABOUT versions and
|
|
86
|
+
// one copy cannot disagree with itself; keeping a second in config.toml
|
|
87
|
+
// would be a field that drifts out of step with the file beside it —
|
|
88
|
+
// exactly the class of bug the single path module exists to prevent.
|
|
89
|
+
// Cleared on uninstall: a recorded binary version for a service that is no
|
|
90
|
+
// longer configured is a claim about this machine that is no longer true.
|
|
91
|
+
writeVersionFile({ daemon: value ? installedVersion : undefined, clearDaemon: !value });
|
|
92
92
|
} catch {
|
|
93
93
|
/* best-effort: never fail a completed setup (or uninstall) over this flag */
|
|
94
94
|
}
|
|
@@ -225,12 +225,94 @@ export function resolveWorkerCommand(): string | null {
|
|
|
225
225
|
return `${shellQuote(process.execPath)} ${shellQuote(workerScript)}`;
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Resolves the command the daemon should use to run a one-shot `failproofai`
|
|
230
|
+
* CLI task — today the scheduled audit — passed through as
|
|
231
|
+
* `FAILPROOFAI_CLI_CMD` in the service's own environment.
|
|
232
|
+
*
|
|
233
|
+
* Everything `resolveWorkerCommand` says about `process.execPath` and the
|
|
234
|
+
* shell quoting applies here verbatim, for the same reason: a system-scope
|
|
235
|
+
* unit gets no login environment, so its PATH is the system default, and the
|
|
236
|
+
* single most common Node install (nvm) is on no system PATH. The difference
|
|
237
|
+
* is the consequence of getting it wrong. A worker that cannot start makes the
|
|
238
|
+
* daemon visibly unhealthy; an audit that cannot start is SILENT — the config
|
|
239
|
+
* says the scan is on, nothing ever runs, and the only symptom is a dashboard
|
|
240
|
+
* that quietly stops moving.
|
|
241
|
+
*
|
|
242
|
+
* `dist/cli.mjs` (package.json's `bin.failproofai`), not `bin/failproofai.mjs`
|
|
243
|
+
* — the latter has a `#!/usr/bin/env bun` shebang and uses syntax node cannot
|
|
244
|
+
* load (a bare `import … from "../package.json"`, extensionless `.ts`
|
|
245
|
+
* specifiers). Only the bundle is node-runnable, and it sits beside the
|
|
246
|
+
* `dist/worker.mjs` the worker command already points at.
|
|
247
|
+
*/
|
|
248
|
+
export function resolveCliCommand(): string | null {
|
|
249
|
+
if (process.env.FAILPROOFAI_CLI_CMD) return process.env.FAILPROOFAI_CLI_CMD;
|
|
250
|
+
|
|
251
|
+
const packageRoot = process.env.FAILPROOFAI_PACKAGE_ROOT;
|
|
252
|
+
if (!packageRoot) return null;
|
|
253
|
+
const cliScript = resolve(packageRoot, "dist", "cli.mjs");
|
|
254
|
+
if (!existsSync(cliScript)) return null;
|
|
255
|
+
return `${shellQuote(process.execPath)} ${shellQuote(cliScript)}`;
|
|
256
|
+
}
|
|
257
|
+
|
|
228
258
|
/** POSIX single-quoting: everything is literal inside '…', and a literal
|
|
229
259
|
* quote is closed, escaped and reopened. */
|
|
230
260
|
function shellQuote(value: string): string {
|
|
231
261
|
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
232
262
|
}
|
|
233
263
|
|
|
264
|
+
/**
|
|
265
|
+
* The environment the service definition carries, built once so the systemd
|
|
266
|
+
* and launchd renderers cannot drift apart — a variable added to one and not
|
|
267
|
+
* the other is invisible until somebody runs the other platform.
|
|
268
|
+
*
|
|
269
|
+
* Order is fixed rather than incidental: `upgradedServiceDefinition` rebuilds
|
|
270
|
+
* a definition from these renderers, so a stable order is what makes a
|
|
271
|
+
* rewritten unit byte-identical to a freshly installed one rather than merely
|
|
272
|
+
* equivalent — which is the difference between a diff a human can read and one
|
|
273
|
+
* they stop reading.
|
|
274
|
+
*/
|
|
275
|
+
/**
|
|
276
|
+
* Characters that cannot appear in a value interpolated into a systemd unit.
|
|
277
|
+
*
|
|
278
|
+
* A newline ENDS THE DIRECTIVE, so a path containing one injects arbitrary
|
|
279
|
+
* settings into a file that is installed root-owned at `/etc/systemd/system`
|
|
280
|
+
* and loaded at every boot. A double quote closes `Environment="..."` early and
|
|
281
|
+
* does the same; a backslash is systemd's own escape character inside a quoted
|
|
282
|
+
* value and makes the result unpredictable rather than merely wrong.
|
|
283
|
+
*
|
|
284
|
+
* The mechanism is demonstrated by this repo's own test, which sets
|
|
285
|
+
* `FAILPROOFAI_CLI_CMD` to `/usr/bin/true"\nUser=failproofai-no-such-user` and
|
|
286
|
+
* relies on systemd HONOURING the injected `User=` — it passes only because the
|
|
287
|
+
* injected user does not exist. A valid one (`User=root`, or an added
|
|
288
|
+
* `ExecStartPre=`) would have succeeded silently, undoing the
|
|
289
|
+
* "root-installed but never root-run" invariant the whole design rests on.
|
|
290
|
+
*
|
|
291
|
+
* These values are resolved paths and commands; none can legitimately contain
|
|
292
|
+
* any of these characters. So this REJECTS rather than escaping — a unit that
|
|
293
|
+
* refuses to be written is a clear failure, and inventing an escaping scheme
|
|
294
|
+
* for systemd's grammar is a larger surface than the problem.
|
|
295
|
+
*/
|
|
296
|
+
const UNIT_UNSAFE_RE = /["\\\r\n]/;
|
|
297
|
+
|
|
298
|
+
/** Throws when a value cannot be safely interpolated into a unit file. */
|
|
299
|
+
function assertUnitSafe(value: string, field: string): string {
|
|
300
|
+
if (UNIT_UNSAFE_RE.test(value)) {
|
|
301
|
+
throw new Error(
|
|
302
|
+
`refusing to write a service definition: ${field} contains a quote, backslash or newline ` +
|
|
303
|
+
`(${JSON.stringify(value)}), which would inject directives into a root-owned unit file`,
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
return value;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function serviceEnvironment(workerCmd: string | null, cliCmd: string | null): [string, string][] {
|
|
310
|
+
const entries: [string, string][] = [];
|
|
311
|
+
if (workerCmd) entries.push(["FAILPROOFAI_WORKER_CMD", workerCmd]);
|
|
312
|
+
if (cliCmd) entries.push(["FAILPROOFAI_CLI_CMD", cliCmd]);
|
|
313
|
+
return entries;
|
|
314
|
+
}
|
|
315
|
+
|
|
234
316
|
/**
|
|
235
317
|
* The account the daemon runs as. The service is root-*installed* but never
|
|
236
318
|
* root-*run*: everything it touches (the socket, the lock, the policy config)
|
|
@@ -321,6 +403,22 @@ export function daemonStatusCommand(): string | null {
|
|
|
321
403
|
: `sudo launchctl print system/${launchdLabel()}`;
|
|
322
404
|
}
|
|
323
405
|
|
|
406
|
+
/**
|
|
407
|
+
* The command that restarts the daemon, for the places where a config change
|
|
408
|
+
* only takes effect on the next start.
|
|
409
|
+
*
|
|
410
|
+
* `--disconnect` is the motivating case: the collector manager starts once for
|
|
411
|
+
* the daemon's lifetime and the uploader caches its bearer key at construction,
|
|
412
|
+
* so removing the credential file changes nothing about the process already
|
|
413
|
+
* running.
|
|
414
|
+
*/
|
|
415
|
+
export function daemonRestartCommand(): string | null {
|
|
416
|
+
if (!isDaemonSupportedPlatform()) return null;
|
|
417
|
+
return process.platform === "linux"
|
|
418
|
+
? `sudo systemctl restart ${systemdUnitName()}`
|
|
419
|
+
: `sudo launchctl kickstart -k system/${launchdLabel()}`;
|
|
420
|
+
}
|
|
421
|
+
|
|
324
422
|
/**
|
|
325
423
|
* Acquires sudo credentials up front, prompting in the terminal if needed.
|
|
326
424
|
*
|
|
@@ -457,11 +555,19 @@ function removeLegacyUserService(): void {
|
|
|
457
555
|
}
|
|
458
556
|
}
|
|
459
557
|
|
|
460
|
-
export function systemdUnitContents(
|
|
461
|
-
|
|
558
|
+
export function systemdUnitContents(
|
|
559
|
+
binaryPath: string,
|
|
560
|
+
workerCmd: string | null,
|
|
561
|
+
cliCmd: string | null = null,
|
|
562
|
+
): string {
|
|
563
|
+
// Quoted because every value here contains a space or a path — systemd's
|
|
462
564
|
// Environment= requires quoting whenever the value does.
|
|
463
|
-
const
|
|
464
|
-
|
|
565
|
+
const envLines = serviceEnvironment(workerCmd, cliCmd)
|
|
566
|
+
.map(([key, value]) => `Environment="${key}=${assertUnitSafe(value, key)}"\n`)
|
|
567
|
+
.join("");
|
|
568
|
+
const user = assertUnitSafe(serviceUser(), "User");
|
|
569
|
+
assertUnitSafe(binaryPath, "ExecStart");
|
|
570
|
+
assertUnitSafe(homedir(), "HOME");
|
|
465
571
|
return `[Unit]
|
|
466
572
|
Description=failproofai background daemon (failproofaid) for ${user}
|
|
467
573
|
After=network.target
|
|
@@ -474,7 +580,7 @@ User=${user}
|
|
|
474
580
|
# HOME ("HOME is not set; failproofaid is user-scope only"), so the one
|
|
475
581
|
# variable it cannot do without is not left to a version-dependent default.
|
|
476
582
|
Environment="HOME=${homedir()}"
|
|
477
|
-
${
|
|
583
|
+
${envLines}ExecStart=${binaryPath}
|
|
478
584
|
Restart=on-failure
|
|
479
585
|
RestartSec=2
|
|
480
586
|
|
|
@@ -490,12 +596,27 @@ function escapeXml(s: string): string {
|
|
|
490
596
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
491
597
|
}
|
|
492
598
|
|
|
493
|
-
function
|
|
494
|
-
|
|
599
|
+
function unescapeXml(s: string): string {
|
|
600
|
+
// & last, or an escaped `&lt;` would come back as `<`.
|
|
601
|
+
return s.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Exported for the same reason `systemdUnitContents` is: it is the only way to
|
|
606
|
+
* assert the plist's shape from a Linux CI runner, and this is the half of the
|
|
607
|
+
* pair no Linux test run can otherwise reach.
|
|
608
|
+
*/
|
|
609
|
+
export function launchdPlistContents(
|
|
610
|
+
binaryPath: string,
|
|
611
|
+
logDir: string,
|
|
612
|
+
workerCmd: string | null,
|
|
613
|
+
cliCmd: string | null = null,
|
|
614
|
+
): string {
|
|
615
|
+
const env = serviceEnvironment(workerCmd, cliCmd);
|
|
616
|
+
const envBlock = env.length
|
|
495
617
|
? ` <key>EnvironmentVariables</key>
|
|
496
618
|
<dict>
|
|
497
|
-
<key
|
|
498
|
-
<string>${escapeXml(workerCmd)}</string>
|
|
619
|
+
${env.map(([key, value]) => ` <key>${key}</key>\n <string>${escapeXml(value)}</string>`).join("\n")}
|
|
499
620
|
</dict>
|
|
500
621
|
`
|
|
501
622
|
: "";
|
|
@@ -538,10 +659,14 @@ export interface DaemonInstallResult {
|
|
|
538
659
|
* machine that cannot elevate can be told exactly what to run rather than
|
|
539
660
|
* just that something failed.
|
|
540
661
|
*/
|
|
541
|
-
function daemonInstallCommands(
|
|
662
|
+
function daemonInstallCommands(
|
|
663
|
+
binaryPath: string,
|
|
664
|
+
workerCmd: string | null,
|
|
665
|
+
cliCmd: string | null,
|
|
666
|
+
): string[] {
|
|
542
667
|
if (process.platform === "linux") {
|
|
543
668
|
return [
|
|
544
|
-
`sudo tee ${systemdUnitPath()} <<'EOF'\n${systemdUnitContents(binaryPath, workerCmd)}EOF`,
|
|
669
|
+
`sudo tee ${systemdUnitPath()} <<'EOF'\n${systemdUnitContents(binaryPath, workerCmd, cliCmd)}EOF`,
|
|
545
670
|
"sudo systemctl daemon-reload",
|
|
546
671
|
`sudo systemctl enable --now ${systemdUnitName()}`,
|
|
547
672
|
];
|
|
@@ -577,6 +702,11 @@ export async function installDaemonService(): Promise<DaemonInstallResult> {
|
|
|
577
702
|
// environment is what makes a *service-managed* daemon actually find its
|
|
578
703
|
// worker regardless of what cwd the service manager starts it from.
|
|
579
704
|
const workerCmd = resolveWorkerCommand();
|
|
705
|
+
// Same best-effort footing as the worker command, and null is survivable in
|
|
706
|
+
// the same way — the daemon just has no way to run an audit. Unlike the
|
|
707
|
+
// worker, there is no relative-path fallback to degrade to, which is exactly
|
|
708
|
+
// why it is resolved here where FAILPROOFAI_PACKAGE_ROOT is reliably set.
|
|
709
|
+
const cliCmd = resolveCliCommand();
|
|
580
710
|
|
|
581
711
|
// The service is installed system-wide, which needs root. Check before
|
|
582
712
|
// writing anything, so a machine that cannot elevate gets the exact
|
|
@@ -588,7 +718,7 @@ export async function installDaemonService(): Promise<DaemonInstallResult> {
|
|
|
588
718
|
"root privileges are required to install the failproofaid system service, and sudo credentials were not available. " +
|
|
589
719
|
"Re-run `failproofai config` and approve the sudo prompt — do NOT run the CLI itself under sudo, which would " +
|
|
590
720
|
"configure root's account instead of yours. To install by hand: " +
|
|
591
|
-
daemonInstallCommands(binaryPath, workerCmd).join(" && "),
|
|
721
|
+
daemonInstallCommands(binaryPath, workerCmd, cliCmd).join(" && "),
|
|
592
722
|
};
|
|
593
723
|
}
|
|
594
724
|
|
|
@@ -600,12 +730,12 @@ export async function installDaemonService(): Promise<DaemonInstallResult> {
|
|
|
600
730
|
|
|
601
731
|
try {
|
|
602
732
|
if (process.platform === "linux") {
|
|
603
|
-
writePrivilegedFile(systemdUnitPath(), systemdUnitContents(binaryPath, workerCmd));
|
|
733
|
+
writePrivilegedFile(systemdUnitPath(), systemdUnitContents(binaryPath, workerCmd, cliCmd));
|
|
604
734
|
runPrivileged("systemctl", ["daemon-reload"]);
|
|
605
735
|
runPrivileged("systemctl", ["enable", "--now", systemdUnitName()]);
|
|
606
736
|
} else {
|
|
607
737
|
const plistPath = launchdPlistPath();
|
|
608
|
-
const logDir =
|
|
738
|
+
const logDir = logsDir();
|
|
609
739
|
mkdirSync(logDir, { recursive: true });
|
|
610
740
|
// Unload any previously-loaded copy first — reloading with a changed
|
|
611
741
|
// binary path (e.g. after an upgrade) is a no-op under plain `load`
|
|
@@ -615,7 +745,7 @@ export async function installDaemonService(): Promise<DaemonInstallResult> {
|
|
|
615
745
|
} catch {
|
|
616
746
|
// Wasn't loaded — fine, this is the common case on a fresh install.
|
|
617
747
|
}
|
|
618
|
-
writePrivilegedFile(plistPath, launchdPlistContents(binaryPath, logDir, workerCmd));
|
|
748
|
+
writePrivilegedFile(plistPath, launchdPlistContents(binaryPath, logDir, workerCmd, cliCmd));
|
|
619
749
|
runPrivileged("launchctl", ["load", "-w", plistPath]);
|
|
620
750
|
}
|
|
621
751
|
} catch (err) {
|
|
@@ -636,9 +766,70 @@ export async function installDaemonService(): Promise<DaemonInstallResult> {
|
|
|
636
766
|
hookLogWarn(`daemon service install failed: ${reason}`);
|
|
637
767
|
return { installed: false, reason };
|
|
638
768
|
}
|
|
769
|
+
|
|
770
|
+
// NOTE: this reports that the SERVICE is installed and running, which is all
|
|
771
|
+
// it can honestly claim. Whether the daemon can actually evaluate a hook is a
|
|
772
|
+
// separate question, answered by `probeDaemonEndToEnd()` — and the caller
|
|
773
|
+
// must ask it before setting `daemonConfigured`, because that flag is what
|
|
774
|
+
// makes an unanswering daemon deny every tool call. `configure-wizard.ts`
|
|
775
|
+
// does exactly that. Keeping the two apart matters: "the unit was written and
|
|
776
|
+
// systemd started it" is testable against a stub binary, and folding the
|
|
777
|
+
// probe in here would mean this function could never be tested without a real
|
|
778
|
+
// failproofaid.
|
|
639
779
|
return { installed: true };
|
|
640
780
|
}
|
|
641
781
|
|
|
782
|
+
/**
|
|
783
|
+
* How long the health probe waits for the daemon to answer a real hook.
|
|
784
|
+
*
|
|
785
|
+
* Far below the hook path's 30s: this runs from an interactive command, and
|
|
786
|
+
* the cold start it is most likely to be waiting on (`worker.rs` pre-warms the
|
|
787
|
+
* worker, ~700ms of Node startup) is comfortably inside it. A daemon that
|
|
788
|
+
* cannot answer a trivial event in this long is not one to hand a machine's
|
|
789
|
+
* fail-closed enforcement to.
|
|
790
|
+
*/
|
|
791
|
+
const DAEMON_PROBE_TIMEOUT_MS = 5_000;
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Ask the daemon to evaluate a real hook, end to end.
|
|
795
|
+
*
|
|
796
|
+
* The thing this catches that nothing else did: a unit that is *running* while
|
|
797
|
+
* the worker behind it cannot start. `ExecStart` bakes in `process.execPath`
|
|
798
|
+
* and an absolute `dist/worker.mjs`, so an `nvm uninstall 20` leaves a service
|
|
799
|
+
* systemd reports as perfectly active and a worker that dies on every spawn.
|
|
800
|
+
* Every existing check passes that machine — `waitForDaemonRunning()` asks the
|
|
801
|
+
* service manager, `Ping` is answered in `server.rs` without ever touching the
|
|
802
|
+
* worker, a null `resolveWorkerCommand()` is treated as best-effort, and
|
|
803
|
+
* `Worker::warm()` swallows its own failure. `daemonConfigured` then gets set,
|
|
804
|
+
* and because that flag makes every hook fail closed, the machine denies every
|
|
805
|
+
* tool call across all 12 CLIs — including `UserPromptSubmit`, so the user
|
|
806
|
+
* cannot even talk to their agent to ask why.
|
|
807
|
+
*
|
|
808
|
+
* `SessionStart` rather than a tool event: it traverses the identical path
|
|
809
|
+
* (socket → daemon → worker → `evaluateHookEvent`) but describes nothing a
|
|
810
|
+
* policy would deny and records no tool decision, so probing cannot itself
|
|
811
|
+
* change what the machine does.
|
|
812
|
+
*/
|
|
813
|
+
export async function probeDaemonEndToEnd(): Promise<boolean> {
|
|
814
|
+
try {
|
|
815
|
+
const { attemptDaemonHook } = await import("./daemon-client");
|
|
816
|
+
const attempt = await attemptDaemonHook(
|
|
817
|
+
{
|
|
818
|
+
hookEvent: "SessionStart",
|
|
819
|
+
cli: "claude",
|
|
820
|
+
stdin: JSON.stringify({ hook_event_name: "SessionStart", source: "failproofai-health-probe" }),
|
|
821
|
+
},
|
|
822
|
+
{ responseTimeoutMs: DAEMON_PROBE_TIMEOUT_MS },
|
|
823
|
+
);
|
|
824
|
+
// A protocol mismatch is a REACHABLE daemon of the wrong vintage. The hook
|
|
825
|
+
// path already falls back rather than denying for that case, so it is not
|
|
826
|
+
// the lockout this probe exists to find.
|
|
827
|
+
return attempt.ok || attempt.failure === "protocol-mismatch";
|
|
828
|
+
} catch {
|
|
829
|
+
return false;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
|
|
642
833
|
/**
|
|
643
834
|
* Waits for the service to report running, then re-checks after a settle
|
|
644
835
|
* window (see `SERVICE_SETTLE_MS`) so a daemon that dies at startup doesn't
|
|
@@ -655,6 +846,353 @@ async function waitForDaemonRunning(): Promise<boolean> {
|
|
|
655
846
|
return daemonServiceStatus() === "running";
|
|
656
847
|
}
|
|
657
848
|
|
|
849
|
+
// ── Upgrading a service definition that predates a variable ──────────────────
|
|
850
|
+
//
|
|
851
|
+
// A machine that installed the daemon before `FAILPROOFAI_CLI_CMD` existed
|
|
852
|
+
// keeps its old unit forever: `npm i -g failproofai@latest` replaces the CLI
|
|
853
|
+
// and never touches /etc/systemd/system, and the wizard's own "already
|
|
854
|
+
// installed and running — leaving it alone" branch skips it too. The daemon
|
|
855
|
+
// then has no way to spawn an audit while `config.toml` says the scheduled
|
|
856
|
+
// scan is on, and nothing anywhere reports a fault. This is the single most
|
|
857
|
+
// likely way the whole feature ends up dead on real machines, so it gets an
|
|
858
|
+
// explicit detect-and-rewrite rather than an assumption that reinstalls happen.
|
|
859
|
+
|
|
860
|
+
/** Reads the installed unit / plist, or null when no service is installed. */
|
|
861
|
+
function readInstalledServiceDefinition(): string | null {
|
|
862
|
+
if (!isDaemonSupportedPlatform()) return null;
|
|
863
|
+
const path = daemonServiceFilePath();
|
|
864
|
+
if (!path || !existsSync(path)) return null;
|
|
865
|
+
try {
|
|
866
|
+
return readFileSync(path, "utf8");
|
|
867
|
+
} catch {
|
|
868
|
+
// Unreadable is not "absent": claiming no service is installed would let a
|
|
869
|
+
// caller reinstall over something it cannot see. Treated as "nothing to
|
|
870
|
+
// upgrade" by the one caller below, which is the inert direction.
|
|
871
|
+
return null;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* Reads one variable back out of an installed service definition.
|
|
877
|
+
*
|
|
878
|
+
* Used to carry values FORWARD across a rewrite. A rewrite resolves each
|
|
879
|
+
* command from this process, and a resolution that comes back null (no
|
|
880
|
+
* `FAILPROOFAI_PACKAGE_ROOT`, a `dist/` that moved) must never be allowed to
|
|
881
|
+
* silently DELETE a working line from a working unit — the rewrite exists to
|
|
882
|
+
* add a variable, not to drop one.
|
|
883
|
+
*/
|
|
884
|
+
function installedEnvValue(definition: string, name: string): string | null {
|
|
885
|
+
if (process.platform === "linux") {
|
|
886
|
+
const m = new RegExp(`^Environment="${name}=(.*)"$`, "m").exec(definition);
|
|
887
|
+
return m ? m[1] : null;
|
|
888
|
+
}
|
|
889
|
+
const m = new RegExp(`<key>${name}</key>\\s*<string>([^<]*)</string>`).exec(definition);
|
|
890
|
+
return m ? unescapeXml(m[1]) : null;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* The binary an installed definition currently starts.
|
|
895
|
+
*
|
|
896
|
+
* Preserved across a rewrite rather than re-resolved, because the two disagree
|
|
897
|
+
* in exactly the upgrade case this is for: `installedBinaryPath()` is
|
|
898
|
+
* version-stamped (`failproofaid-<version>`), so right after a CLI upgrade the
|
|
899
|
+
* binary for the NEW version is not on disk yet and resolution returns null,
|
|
900
|
+
* while the unit still points at the older binary that is there and running.
|
|
901
|
+
* Re-resolving would either refuse to rewrite or repoint a live service at a
|
|
902
|
+
* file that does not exist.
|
|
903
|
+
*/
|
|
904
|
+
function installedExecStart(definition: string): string | null {
|
|
905
|
+
if (process.platform === "linux") {
|
|
906
|
+
const m = /^ExecStart=(.+)$/m.exec(definition);
|
|
907
|
+
return m ? m[1].trim() : null;
|
|
908
|
+
}
|
|
909
|
+
const m = /<key>ProgramArguments<\/key>\s*<array>\s*<string>([^<]*)<\/string>/.exec(definition);
|
|
910
|
+
return m ? unescapeXml(m[1]) : null;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* True when a service IS installed but its definition predates
|
|
915
|
+
* `FAILPROOFAI_CLI_CMD`.
|
|
916
|
+
*
|
|
917
|
+
* Deliberately a content check against the definition on disk, not a revision
|
|
918
|
+
* number mirrored into `config.toml`. The mirror is the tempting shape — it is
|
|
919
|
+
* how `daemon.installed_version` is modelled — but that field is declared,
|
|
920
|
+
* read and cleared and has never once been WRITTEN (both `setDaemonConfigured`
|
|
921
|
+
* call sites pass no version), which is precisely how a mirror fails: it
|
|
922
|
+
* reports "current" for a unit nobody updated. A false negative here is the
|
|
923
|
+
* permanently-inert audit lane this function exists to catch, and the unit
|
|
924
|
+
* itself cannot lie about what it contains.
|
|
925
|
+
*/
|
|
926
|
+
export function daemonServiceNeedsUpgrade(): boolean {
|
|
927
|
+
const definition = readInstalledServiceDefinition();
|
|
928
|
+
if (definition === null) return false;
|
|
929
|
+
return !definition.includes("FAILPROOFAI_CLI_CMD");
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* The definition an installed one should become: regenerated by the same
|
|
934
|
+
* renderers a fresh install uses, carrying forward everything this process
|
|
935
|
+
* cannot re-resolve. `null` when the input has no readable start command,
|
|
936
|
+
* which means it is not a definition failproofai wrote and must be left alone.
|
|
937
|
+
*
|
|
938
|
+
* Split out from `ensureDaemonServiceCurrent` and kept pure — no privilege, no
|
|
939
|
+
* service manager, no writes — because the rewrite itself can only be
|
|
940
|
+
* exercised end-to-end on a machine with root AND the matching service
|
|
941
|
+
* manager. That is nowhere on a Linux CI runner for the launchd half, and
|
|
942
|
+
* nowhere at all on a developer box without passwordless sudo, so the one
|
|
943
|
+
* transformation that must not be wrong would otherwise be the one thing no
|
|
944
|
+
* ordinary test run ever executes.
|
|
945
|
+
*/
|
|
946
|
+
export function upgradedServiceDefinition(
|
|
947
|
+
definition: string,
|
|
948
|
+
cliCmd: string,
|
|
949
|
+
logDir: string,
|
|
950
|
+
): string | null {
|
|
951
|
+
const binaryPath = installedExecStart(definition);
|
|
952
|
+
if (!binaryPath) return null;
|
|
953
|
+
const workerCmd = resolveWorkerCommand() ?? installedEnvValue(definition, "FAILPROOFAI_WORKER_CMD");
|
|
954
|
+
try {
|
|
955
|
+
return process.platform === "linux"
|
|
956
|
+
? systemdUnitContents(binaryPath, workerCmd, cliCmd)
|
|
957
|
+
: launchdPlistContents(binaryPath, logDir, workerCmd, cliCmd);
|
|
958
|
+
} catch (err) {
|
|
959
|
+
// A value that cannot be safely interpolated is reported as "no usable
|
|
960
|
+
// definition" rather than thrown: this runs against a HEALTHY, RUNNING
|
|
961
|
+
// daemon and the caller's contract is an outcome, not an exception. The
|
|
962
|
+
// refusal happens before anything is written or stopped, so the machine is
|
|
963
|
+
// left exactly as it was.
|
|
964
|
+
hookLogWarn(
|
|
965
|
+
`service definition not rewritten: ${err instanceof Error ? err.message : String(err)}`,
|
|
966
|
+
);
|
|
967
|
+
return null;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
export type DaemonUpgradeOutcome =
|
|
972
|
+
/** No service installed, or its definition already carries the variable. */
|
|
973
|
+
| "current"
|
|
974
|
+
/** The definition was rewritten and the service came back running. */
|
|
975
|
+
| "rewritten"
|
|
976
|
+
/** It needed a rewrite and did not get one. `reason` says why. */
|
|
977
|
+
| "failed";
|
|
978
|
+
|
|
979
|
+
export interface DaemonUpgradeResult {
|
|
980
|
+
outcome: DaemonUpgradeOutcome;
|
|
981
|
+
reason?: string;
|
|
982
|
+
/**
|
|
983
|
+
* Whether failproofaid is running when this returns — probed, never
|
|
984
|
+
* inferred from what the commands returned.
|
|
985
|
+
*
|
|
986
|
+
* Set on every outcome that touched the service, because on a
|
|
987
|
+
* `daemonConfigured` machine a stopped daemon is not a lost feature: every
|
|
988
|
+
* hook event fails closed, across all 12 CLIs, until somebody hand-edits
|
|
989
|
+
* `policies-config.json`. The caller needs to know that specifically, not
|
|
990
|
+
* just that "the refresh failed".
|
|
991
|
+
*/
|
|
992
|
+
daemonRunning?: boolean;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
/**
|
|
996
|
+
* Restart the systemd unit, clearing any start-limit latch first.
|
|
997
|
+
*
|
|
998
|
+
* The unit ships `Restart=on-failure` with `RestartSec=2`, so a definition
|
|
999
|
+
* systemd accepts but cannot run (a poisoned `User=`, a missing binary) does
|
|
1000
|
+
* not fail once — it cycles, and within `DefaultStartLimitIntervalSec` (10s) it
|
|
1001
|
+
* trips `DefaultStartLimitBurst` (5) and latches into "start request repeated
|
|
1002
|
+
* too quickly". On systemd 255 — what ubuntu-24.04 and GitHub's runners ship —
|
|
1003
|
+
* that latch is sticky at the unit level: a later `systemctl restart` is refused
|
|
1004
|
+
* even after the definition on disk has been REPLACED with a good one. A
|
|
1005
|
+
* rollback that restores a perfectly runnable unit then still cannot start it,
|
|
1006
|
+
* and the machine stays fail-closed against a daemon that never comes back.
|
|
1007
|
+
* `reset-failed` clears the failure counter so the restart is deterministic; on
|
|
1008
|
+
* a healthy unit it is a no-op. Best-effort — a `reset-failed` that errors (the
|
|
1009
|
+
* unit was never failed) must never abort the restart that is the real step.
|
|
1010
|
+
*/
|
|
1011
|
+
function restartSystemdUnit(): void {
|
|
1012
|
+
try {
|
|
1013
|
+
runPrivileged("systemctl", ["reset-failed", systemdUnitName()]);
|
|
1014
|
+
} catch {
|
|
1015
|
+
// The restart below is the operative step; do not let a reset-failed
|
|
1016
|
+
// that errored on an already-clean unit swallow it.
|
|
1017
|
+
}
|
|
1018
|
+
runPrivileged("systemctl", ["restart", systemdUnitName()]);
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* Puts a previous service definition back and starts the service again,
|
|
1023
|
+
* answering whether failproofaid is running once it has.
|
|
1024
|
+
*
|
|
1025
|
+
* `ensureDaemonServiceCurrent` is the only caller, and it runs exclusively
|
|
1026
|
+
* against a machine whose daemon is UP — which is what makes a half-applied
|
|
1027
|
+
* rewrite so much worse than no rewrite. Stopping a healthy daemon and failing
|
|
1028
|
+
* to start it again trades a dead audit lane for a machine that denies every
|
|
1029
|
+
* tool call, so the refresh must be able to undo itself.
|
|
1030
|
+
*
|
|
1031
|
+
* Best-effort and never throws: it only ever runs where something has already
|
|
1032
|
+
* gone wrong. The return value is `waitForDaemonRunning()` rather than "the
|
|
1033
|
+
* commands succeeded" on purpose — the common rollback failure is a lost sudo
|
|
1034
|
+
* credential, which means nothing was written and the daemon was never down.
|
|
1035
|
+
*/
|
|
1036
|
+
async function restoreServiceDefinition(previous: string): Promise<boolean> {
|
|
1037
|
+
try {
|
|
1038
|
+
if (process.platform === "linux") {
|
|
1039
|
+
writePrivilegedFile(systemdUnitPath(), previous);
|
|
1040
|
+
runPrivileged("systemctl", ["daemon-reload"]);
|
|
1041
|
+
// reset-failed first: the failed rewrite we are undoing has been cycling
|
|
1042
|
+
// under Restart=on-failure and may have tripped systemd's start-limit,
|
|
1043
|
+
// which on systemd 255 refuses to start even this restored, good unit.
|
|
1044
|
+
restartSystemdUnit();
|
|
1045
|
+
} else {
|
|
1046
|
+
const plistPath = launchdPlistPath();
|
|
1047
|
+
try {
|
|
1048
|
+
runPrivileged("launchctl", ["unload", plistPath]);
|
|
1049
|
+
} catch {
|
|
1050
|
+
// Already unloaded — getting the old definition loaded is the point.
|
|
1051
|
+
}
|
|
1052
|
+
writePrivilegedFile(plistPath, previous);
|
|
1053
|
+
runPrivileged("launchctl", ["load", "-w", plistPath]);
|
|
1054
|
+
}
|
|
1055
|
+
} catch (err) {
|
|
1056
|
+
hookLogWarn(
|
|
1057
|
+
`daemon service definition rollback failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
1058
|
+
);
|
|
1059
|
+
// Not a verdict on the daemon — fall through to the probe below, which is.
|
|
1060
|
+
}
|
|
1061
|
+
return waitForDaemonRunning();
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* The one exit for every way a refresh can fail after it started touching the
|
|
1066
|
+
* service. Rolls back when there is something to roll back to, then reports
|
|
1067
|
+
* the daemon's actual state.
|
|
1068
|
+
*/
|
|
1069
|
+
async function refreshFailed(message: string, previous: string | null): Promise<DaemonUpgradeResult> {
|
|
1070
|
+
hookLogWarn(`daemon service unit refresh failed: ${message}`);
|
|
1071
|
+
const running =
|
|
1072
|
+
previous === null ? daemonServiceStatus() === "running" : await restoreServiceDefinition(previous);
|
|
1073
|
+
return {
|
|
1074
|
+
outcome: "failed",
|
|
1075
|
+
daemonRunning: running,
|
|
1076
|
+
reason: running
|
|
1077
|
+
? message
|
|
1078
|
+
: `${message}. The previous service definition could not be restored either, so failproofaid is NOT running`,
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
/**
|
|
1083
|
+
* Brings an already-installed service definition up to date, in place.
|
|
1084
|
+
*
|
|
1085
|
+
* Narrower than `installDaemonService` on purpose, and it is the narrowness
|
|
1086
|
+
* that makes it safe to run against a healthy machine: it never downloads, it
|
|
1087
|
+
* never touches a machine that has no service, and it keeps the ExecStart and
|
|
1088
|
+
* any environment value it cannot re-resolve. Everything past the first
|
|
1089
|
+
* privileged write is undone by `restoreServiceDefinition` if the daemon does
|
|
1090
|
+
* not come back, so the worst outcome really is the machine it started with —
|
|
1091
|
+
* and when even the rollback cannot get the daemon up, that fact rides out on
|
|
1092
|
+
* `daemonRunning` rather than being folded into a generic failure, because the
|
|
1093
|
+
* caller has to stop asserting `daemonConfigured` over a daemon that is gone.
|
|
1094
|
+
*
|
|
1095
|
+
* It DOES restart the service, which `installDaemonService` does not do on
|
|
1096
|
+
* Linux (`enable --now` is a no-op against an already-active unit, so a
|
|
1097
|
+
* rewritten unit's environment reaches the running process only at the next
|
|
1098
|
+
* boot). Without the restart this "fix" would leave the audit lane inert for
|
|
1099
|
+
* however long the machine stays up — which is the bug, not a smaller version
|
|
1100
|
+
* of it. The restart costs a sub-second window in which a hook can find no
|
|
1101
|
+
* daemon and fail closed, so it is confined to the wizard: `failproofai
|
|
1102
|
+
* config` is an explicit, attended reconfiguration, and the same window
|
|
1103
|
+
* already exists on macOS, where install unloads and reloads on every run.
|
|
1104
|
+
*/
|
|
1105
|
+
export async function ensureDaemonServiceCurrent(): Promise<DaemonUpgradeResult> {
|
|
1106
|
+
const definition = readInstalledServiceDefinition();
|
|
1107
|
+
if (definition === null || definition.includes("FAILPROOFAI_CLI_CMD")) {
|
|
1108
|
+
return { outcome: "current" };
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
const cliCmd = resolveCliCommand();
|
|
1112
|
+
if (!cliCmd) {
|
|
1113
|
+
return {
|
|
1114
|
+
outcome: "failed",
|
|
1115
|
+
reason:
|
|
1116
|
+
"the failproofai CLI entry point (dist/cli.mjs) could not be located, so there is nothing to " +
|
|
1117
|
+
"write into the unit. Re-run `failproofai config` from a complete install.",
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
const logDir = logsDir();
|
|
1122
|
+
const upgraded = upgradedServiceDefinition(definition, cliCmd, logDir);
|
|
1123
|
+
if (!upgraded) {
|
|
1124
|
+
return {
|
|
1125
|
+
outcome: "failed",
|
|
1126
|
+
reason:
|
|
1127
|
+
`no safe replacement could be composed for the service definition at ${daemonServiceFilePath()} — ` +
|
|
1128
|
+
`either it has no readable start command (it looks hand-edited) or a value that would go into it ` +
|
|
1129
|
+
`contains a quote, backslash or newline. It was left alone.`,
|
|
1130
|
+
// Reported because nothing was touched: the refusal happens before any
|
|
1131
|
+
// write and before any stop, so whatever was running still is. The
|
|
1132
|
+
// wizard branches on this to decide whether to clear `daemonConfigured`,
|
|
1133
|
+
// and omitting it here would have read as "the daemon may be down" on a
|
|
1134
|
+
// machine whose daemon is perfectly healthy — which on a
|
|
1135
|
+
// `daemonConfigured` box is the difference between a lost audit lane and
|
|
1136
|
+
// every tool call denied.
|
|
1137
|
+
daemonRunning: daemonServiceStatus() === "running",
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
if (!canElevate()) {
|
|
1142
|
+
return {
|
|
1143
|
+
outcome: "failed",
|
|
1144
|
+
reason: `root privileges are required to rewrite ${daemonServiceFilePath()}, and sudo credentials were not available`,
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
// What to put back if this goes wrong, and from which point. Set BEFORE the
|
|
1149
|
+
// step that can leave the machine changed, not after it succeeds: on Linux
|
|
1150
|
+
// `writePrivilegedFile` is an `install` copy straight onto the unit path, so
|
|
1151
|
+
// a failure part-way through leaves a truncated unit behind, and on macOS
|
|
1152
|
+
// the unload has already stopped the daemon before anything is written.
|
|
1153
|
+
let previous: string | null = null;
|
|
1154
|
+
|
|
1155
|
+
try {
|
|
1156
|
+
if (process.platform === "linux") {
|
|
1157
|
+
previous = definition;
|
|
1158
|
+
writePrivilegedFile(systemdUnitPath(), upgraded);
|
|
1159
|
+
runPrivileged("systemctl", ["daemon-reload"]);
|
|
1160
|
+
// `restart`, not `enable --now`: the unit is already enabled and active,
|
|
1161
|
+
// so `--now` would return success having changed nothing and the daemon
|
|
1162
|
+
// would keep the environment it was started with. reset-failed first so a
|
|
1163
|
+
// machine that arrived here with an already-latched start-limit (a prior
|
|
1164
|
+
// failed refresh) can still be upgraded.
|
|
1165
|
+
restartSystemdUnit();
|
|
1166
|
+
} else {
|
|
1167
|
+
const plistPath = launchdPlistPath();
|
|
1168
|
+
mkdirSync(logDir, { recursive: true });
|
|
1169
|
+
previous = definition;
|
|
1170
|
+
try {
|
|
1171
|
+
runPrivileged("launchctl", ["unload", plistPath]);
|
|
1172
|
+
} catch {
|
|
1173
|
+
// Not loaded — the rewrite is still the point.
|
|
1174
|
+
}
|
|
1175
|
+
writePrivilegedFile(plistPath, upgraded);
|
|
1176
|
+
runPrivileged("launchctl", ["load", "-w", plistPath]);
|
|
1177
|
+
}
|
|
1178
|
+
} catch (err) {
|
|
1179
|
+
return refreshFailed(err instanceof Error ? err.message : String(err), previous);
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
// The service was running when this started, so anything short of running
|
|
1183
|
+
// now is a regression this call caused — and on a daemon-configured machine
|
|
1184
|
+
// that is every tool call failing closed. A unit that parses but will not
|
|
1185
|
+
// start is exactly the case `systemctl restart`'s exit code does not catch,
|
|
1186
|
+
// so this is the check that hands it to the rollback.
|
|
1187
|
+
if (!(await waitForDaemonRunning())) {
|
|
1188
|
+
return refreshFailed(
|
|
1189
|
+
`the service definition was refreshed but failproofaid did not come back within ${SERVICE_START_TIMEOUT_MS}ms (status: ${daemonServiceStatus()})`,
|
|
1190
|
+
previous,
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
return { outcome: "rewritten", daemonRunning: true };
|
|
1194
|
+
}
|
|
1195
|
+
|
|
658
1196
|
/**
|
|
659
1197
|
* Stops and removes the service, and clears the `daemonConfigured` marker
|
|
660
1198
|
* so this machine goes back to in-process evaluation. Best-effort: never
|
|
@@ -715,6 +1253,36 @@ export async function uninstallDaemonService(): Promise<void> {
|
|
|
715
1253
|
* file exists — a unit can be installed but crash-looped into a stopped
|
|
716
1254
|
* state.
|
|
717
1255
|
*/
|
|
1256
|
+
/**
|
|
1257
|
+
* Whether the installed daemon is a different version than this CLI expects.
|
|
1258
|
+
*
|
|
1259
|
+
* The expected version is this CLI's OWN — no lookup, no registry call, no
|
|
1260
|
+
* network. `package.json` and `Cargo.toml` are held identical by CI, and every
|
|
1261
|
+
* downstream path (the download URL, the binary filename, the npm pin) is
|
|
1262
|
+
* derived from that one number, so a CLI can never want a daemon version that
|
|
1263
|
+
* was not published alongside it.
|
|
1264
|
+
*
|
|
1265
|
+
* Returns null when the question does not apply, and the exclusions are the
|
|
1266
|
+
* point:
|
|
1267
|
+
*
|
|
1268
|
+
* • FAILPROOFAI_DAEMON_BINARY — someone named a binary explicitly; its
|
|
1269
|
+
* version is their business, not ours to second-guess.
|
|
1270
|
+
* • a locally-built target/{release,debug} binary — the developer's own
|
|
1271
|
+
* build. Reporting it "stale" on every command would be noise about the
|
|
1272
|
+
* exact setup this repo tells contributors to use.
|
|
1273
|
+
*
|
|
1274
|
+
* Only the managed `~/.failproofai/bin/failproofaid-<version>` path is
|
|
1275
|
+
* checked, because it is the only one whose version we actually own.
|
|
1276
|
+
*/
|
|
1277
|
+
export function daemonVersionSkew(): { installed: string; expected: string } | null {
|
|
1278
|
+
if (process.env.FAILPROOFAI_DAEMON_BINARY) return null;
|
|
1279
|
+
const recorded = readVersionFile()?.daemon;
|
|
1280
|
+
if (!recorded) return null;
|
|
1281
|
+
// Managed installs only — see the exclusions above.
|
|
1282
|
+
if (!existsSync(installedBinaryPath(recorded))) return null;
|
|
1283
|
+
return recorded === version ? null : { installed: recorded, expected: version };
|
|
1284
|
+
}
|
|
1285
|
+
|
|
718
1286
|
export function daemonServiceStatus(): DaemonServiceStatus {
|
|
719
1287
|
if (!isDaemonSupportedPlatform()) return "unsupported-platform";
|
|
720
1288
|
|