failproofai 1.0.14 → 1.0.16-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/standalone/.next/BUILD_ID +1 -1
- package/.next/standalone/.next/build-manifest.json +23 -23
- package/.next/standalone/.next/prerender-manifest.json +4 -4
- package/.next/standalone/.next/required-server-files.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page/build-manifest.json +3 -3
- 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 +2 -2
- 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 +2 -2
- package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found/page/build-manifest.json +3 -3
- 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 +1 -1
- package/.next/standalone/.next/server/app/_not-found.rsc +4 -4
- package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +4 -4
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +3 -3
- package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- 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 +22 -21
- package/.next/standalone/.next/server/app/api/audit/run/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/audit/status/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/login-request/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/login-verify/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/logout/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/status/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/download/[project]/[session]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/audit/page/build-manifest.json +3 -3
- package/.next/standalone/.next/server/app/audit/page/server-reference-manifest.json +2 -2
- package/.next/standalone/.next/server/app/audit/page.js +4 -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 +4 -4
- package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +3 -3
- package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +4 -4
- package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/page/build-manifest.json +3 -3
- 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/build-manifest.json +3 -3
- package/.next/standalone/.next/server/app/policies/page/server-reference-manifest.json +14 -14
- package/.next/standalone/.next/server/app/policies/page.js +8 -7
- 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/build-manifest.json +3 -3
- 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/build-manifest.json +3 -3
- 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/build-manifest.json +3 -3
- 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/app/settings/page/build-manifest.json +3 -3
- package/.next/standalone/.next/server/app/settings/page/server-reference-manifest.json +8 -8
- package/.next/standalone/.next/server/app/settings/page.js +8 -7
- package/.next/standalone/.next/server/app/settings/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/settings/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__048f1wnr8pysf._.js +4 -4
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__1oclamblhzhrf._.js +1 -1
- package/.next/standalone/.next/server/chunks/_0tovk6q0miud6._.js +1 -1
- package/.next/standalone/.next/server/chunks/_0trp3ycqv17cl._.js +1 -1
- package/.next/standalone/.next/server/chunks/_1vslkoe35wok6._.js +1 -1
- package/.next/standalone/.next/server/chunks/node_modules_posthog-node_dist_entrypoints_index_node_mjs_01r25oigsgz07._.js +1 -1
- package/.next/standalone/.next/server/chunks/node_modules_posthog-node_dist_entrypoints_index_node_mjs_09z9-p77cu37y._.js +1 -1
- package/.next/standalone/.next/server/chunks/package_json_[json]_cjs_1nxcc4vkpxxu7._.js +1 -1
- package/.next/standalone/.next/server/chunks/src_hooks_0fmclqlaj83-2._.js +5 -0
- package/.next/standalone/.next/server/chunks/src_hooks_15j31lnj-km9r._.js +3 -0
- package/.next/standalone/.next/server/chunks/src_hooks_daemon-client_ts_0il_yu1zc0291._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__08ch3staq3ejw._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0bigvy9xmv2ka._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0ezoipo-r7_5k._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0h86bl2qf0k_o._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0pia5h3p8re4c._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0t76rmc_vci18._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__1vofkb2oq7p7e._.js → [root-of-the-server]__0tayeyopslkf1._.js} +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1-ey9fgesfbc0._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__15usvs-ms-0hf._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__16gb3_92zvk5x._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1avi2kypusyb_._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1r7drlqli-ado._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1vxwetblyf8vp._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_0eoura3_9gjb-._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_0f-kswpk5hx7v._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_0pedwblqdoh58._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_1_ozgifqv1ssi._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_1djqs9i27e4kg._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_1v4_ul3sj2lq_._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_next-internal_server_app_policies_page_actions_1sp2-yo5_vm5f.js +5 -5
- package/.next/standalone/.next/server/chunks/ssr/app_actions_get-scheduled-audit_ts_0ei9snixb5fd-._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_audit__components_audit-dashboard_tsx_0p9ud47q0xq5w._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_components_project-list_tsx_1ke6anr0vt64h._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_global-error_tsx_1kp6l3x33jqb6._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_policies_hooks-client_tsx_19dqvpcz0uxur._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_settings_02tf1h47jmhhd._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/{node_modules_html-to-image_es_index_0r9i9nq3-ei-l.js → node_modules_html-to-image_es_index_0wgfci23_yqs_.js} +1 -1
- package/.next/standalone/.next/server/chunks/ssr/node_modules_next_0bz67659f5z-3._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/node_modules_next_dist_1khq67j4vo9y4._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/node_modules_posthog-node_dist_entrypoints_index_node_mjs_11bnuznb72p7z._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/package_json_[json]_cjs_013tntikdft59._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_1-ytegsicaf2d._.js +5 -0
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_1euxn1va7c5gq._.js +5 -0
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_daemon-client_ts_0k41_i7jg6ndv._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_daemon-service_ts_0ibufora3s_bw._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_effective-reviewers_ts_1h4wtvo55j16x._.js +3 -0
- package/.next/standalone/.next/server/middleware-build-manifest.js +23 -23
- 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/preview-props.json +3 -3
- package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/server-reference-manifest.json +23 -23
- package/.next/standalone/.next/static/chunks/0fqjv13piwa6z.js +1 -0
- package/.next/standalone/.next/static/chunks/{435eshlryosz1.js → 0y9qczsccrmmf.js} +1 -1
- package/.next/standalone/.next/static/chunks/{110hwwc6agsr8.js → 0z70k3nof30ws.js} +1 -1
- package/.next/standalone/.next/static/chunks/{3hk5y4kny2ktd.js → 167exo9u6npy3.js} +1 -1
- package/.next/standalone/.next/static/chunks/{2zlfhyqvlvf7o.js → 1xwh61k4505md.js} +1 -1
- package/.next/standalone/.next/static/chunks/24nikgpkr0qas.js +1 -0
- package/.next/standalone/.next/static/chunks/{2wh64znsc_mo2.js → 2ayu58wi805x4.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0tiuj32d-qcy3.js → 2swcvie6i54dn.js} +1 -1
- package/.next/standalone/.next/static/chunks/2xx-2wehe-kwl.js +1 -0
- package/.next/standalone/.next/static/chunks/{2wye36b3mbzpa.js → 34rjkinfk6d4p.js} +1 -1
- package/.next/standalone/.next/static/chunks/{1i9zuw01f0ogt.js → 3r-j6pmqrq4l1.js} +2 -2
- package/.next/standalone/.next/static/chunks/3tfcj166ki-08.js +1 -0
- package/.next/standalone/.next/static/chunks/3uj5quosl7j_x.js +6 -0
- package/.next/standalone/assets/logos/failproof-dark.png +0 -0
- package/.next/standalone/assets/logos/failproof-light.png +0 -0
- package/.next/standalone/fp-cloud-cli/CHANGELOG.md +24 -3
- package/.next/standalone/fp-cloud-cli/fp_cli/_version.py +1 -1
- package/.next/standalone/fp-cloud-cli/uv.lock +6 -6
- package/.next/standalone/hermes-plugin/client.py +97 -37
- package/.next/standalone/hermes-plugin/plugin.yaml +1 -1
- package/.next/standalone/node_modules/@next/env/package.json +1 -1
- package/.next/standalone/node_modules/next/dist/build/swc/index.js +1 -1
- package/.next/standalone/node_modules/next/dist/compiled/next-server/app-page-turbo-experimental.runtime.prod.js +1 -1
- package/.next/standalone/node_modules/next/dist/compiled/next-server/app-page-turbo.runtime.prod.js +1 -1
- package/.next/standalone/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.prod.js +1 -1
- package/.next/standalone/node_modules/next/dist/lib/patch-incorrect-lockfile.js +3 -3
- package/.next/standalone/node_modules/next/dist/server/app-render/async-local-storage.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/base-http/node.js +7 -2
- package/.next/standalone/node_modules/next/dist/server/config.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/dev/hot-reloader-turbopack.js +2 -2
- package/.next/standalone/node_modules/next/dist/server/dev/hot-reloader-webpack.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/lib/app-info-log.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/lib/router-server.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/lib/start-server.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/lib/trace/tracer.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/use-cache/use-cache-wrapper.js +1 -1
- package/.next/standalone/node_modules/next/dist/telemetry/anonymous-meta.js +1 -1
- package/.next/standalone/node_modules/next/dist/telemetry/events/swc-load-failure.js +1 -1
- package/.next/standalone/node_modules/next/dist/telemetry/events/version.js +2 -2
- package/.next/standalone/node_modules/next/package.json +10 -10
- package/.next/standalone/package.json +10 -10
- package/.next/standalone/sdk/python/uv.lock +18 -18
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/package-lock.json +40 -40
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/package.json +1 -1
- package/.next/standalone/server.js +1 -1
- package/README.md +174 -83
- package/bin/failproofai.mjs +66 -90
- package/dist/cli.mjs +1422 -1490
- package/dist/worker.mjs +19 -4
- package/hermes-plugin/client.py +97 -37
- package/hermes-plugin/plugin.yaml +1 -1
- package/openclaw-plugin/daemon-client.js +157 -32
- package/openclaw-plugin/hooks.js +16 -1
- package/package.json +10 -10
- package/pi-extension/index.ts +2 -0
- package/src/hooks/cloud-managed-policies.ts +22 -0
- package/src/hooks/config-status.ts +34 -21
- package/src/hooks/configure-wizard.ts +16 -3
- package/src/hooks/daemon-client.ts +59 -16
- package/src/hooks/daemon-service.ts +167 -19
- package/src/hooks/delivery-health.ts +10 -0
- package/src/hooks/fp-home.ts +8 -0
- package/src/hooks/fp-reset.ts +8 -2
- package/src/hooks/gateway-restart.ts +248 -0
- package/src/hooks/handler.ts +39 -2
- package/src/hooks/hermes-update.ts +18 -2
- package/src/hooks/hook-activity-store.ts +5 -0
- package/src/hooks/manager.ts +43 -9
- package/src/hooks/shell-quote.ts +19 -0
- package/src/hooks/update-run.ts +276 -0
- package/.next/standalone/.next/server/chunks/src_hooks_0_em82s16zfym._.js +0 -5
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1xwr4hi-on27i._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/_0p1cb69sml__f._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_0agdmptetetdt._.js +0 -5
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_0mdwgjisv4fub._.js +0 -5
- package/.next/standalone/.next/static/chunks/107jrtkeylnrv.js +0 -6
- package/.next/standalone/.next/static/chunks/19e9khxgv8fb8.js +0 -1
- package/.next/standalone/.next/static/chunks/2codb6nb412m9.js +0 -1
- package/.next/standalone/.next/static/chunks/2maurwweshrsj.js +0 -1
- package/.next/standalone/.next/static/chunks/3v49ogp389dun.js +0 -1
- /package/.next/standalone/.next/static/{-iBiSmrLiylRKLAg77zlQ → _rnWxsoAWV0JPMURamq78}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{-iBiSmrLiylRKLAg77zlQ → _rnWxsoAWV0JPMURamq78}/_clientMiddlewareManifest.js +0 -0
- /package/.next/standalone/.next/static/{-iBiSmrLiylRKLAg77zlQ → _rnWxsoAWV0JPMURamq78}/_ssgManifest.js +0 -0
package/dist/worker.mjs
CHANGED
|
@@ -1167,7 +1167,7 @@ function instruct(reason) {
|
|
|
1167
1167
|
}
|
|
1168
1168
|
|
|
1169
1169
|
// package.json
|
|
1170
|
-
var version = "1.0.
|
|
1170
|
+
var version = "1.0.16-beta.0";
|
|
1171
1171
|
var init_package = () => {};
|
|
1172
1172
|
|
|
1173
1173
|
// src/hooks/agent-targets.ts
|
|
@@ -18248,6 +18248,15 @@ var init_enforcement_capability = __esm(() => {
|
|
|
18248
18248
|
|
|
18249
18249
|
// src/hooks/handler.ts
|
|
18250
18250
|
import { existsSync as existsSync22 } from "node:fs";
|
|
18251
|
+
function toolCallIdOf(parsed) {
|
|
18252
|
+
const hermes = parsed.hermes;
|
|
18253
|
+
const nested = hermes && typeof hermes === "object" && !Array.isArray(hermes) ? hermes.tool_call_id : undefined;
|
|
18254
|
+
for (const value of [parsed.tool_use_id, parsed.tool_call_id, parsed.toolCallId, parsed.toolUseId, nested]) {
|
|
18255
|
+
if (typeof value === "string" && value.length > 0 && value.length <= 256)
|
|
18256
|
+
return value;
|
|
18257
|
+
}
|
|
18258
|
+
return;
|
|
18259
|
+
}
|
|
18251
18260
|
function canonicalizeEventType(raw, cli) {
|
|
18252
18261
|
if (cli === "codex") {
|
|
18253
18262
|
const mapped = CODEX_EVENT_MAP[raw];
|
|
@@ -18476,6 +18485,7 @@ async function captureJevIntent(canonicalEventType, decision, parsed, session, c
|
|
|
18476
18485
|
}
|
|
18477
18486
|
async function evaluateHookEvent(eventType, cli = "claude", stdinPayload, opts) {
|
|
18478
18487
|
const startTime = performance.now();
|
|
18488
|
+
const arrivedAt = Date.now();
|
|
18479
18489
|
const layoutWarning = layoutWarningForHook();
|
|
18480
18490
|
if (layoutWarning)
|
|
18481
18491
|
hookLogWarn(layoutWarning);
|
|
@@ -18541,7 +18551,8 @@ async function evaluateHookEvent(eventType, cli = "claude", stdinPayload, opts)
|
|
|
18541
18551
|
const packsInstalledHere = hasInstalledRegexPacks();
|
|
18542
18552
|
const legacyNames = activePause || packsInstalledHere ? [] : config.enabledPolicies;
|
|
18543
18553
|
registerBuiltinPolicies(activePause ? [] : legacyNames);
|
|
18544
|
-
if (legacyNames.length > 0) {
|
|
18554
|
+
if (legacyNames.length > 0 && !legacyShimWarned) {
|
|
18555
|
+
legacyShimWarned = true;
|
|
18545
18556
|
hookLogWarn(`enforcing ${legacyNames.length} policies from this build because no pack is installed — ` + `run \`failproofai policies add FailproofAI/policies\` to move them into a real pack`);
|
|
18546
18557
|
}
|
|
18547
18558
|
const enabledBuiltinNames = new Set(legacyNames);
|
|
@@ -18739,8 +18750,12 @@ async function evaluateHookEvent(eventType, cli = "claude", stdinPayload, opts)
|
|
|
18739
18750
|
await captureJevIntent(canonicalEventType, result.decision, parsed, session, cli, opts, runtimeAgent);
|
|
18740
18751
|
const matchedPolicies = matchedBeforeRelease ?? getPoliciesForEvent(canonicalEventType, parsed.tool_name).map((p) => p.name);
|
|
18741
18752
|
const jevOrigin = result.policyName && result.twoTier?.decidedByJev ? result.twoTier.jevOrigin : undefined;
|
|
18753
|
+
const writtenAt = Date.now();
|
|
18754
|
+
const toolCallId = toolCallIdOf(parsed);
|
|
18742
18755
|
const activityEntry = {
|
|
18743
|
-
timestamp:
|
|
18756
|
+
timestamp: writtenAt,
|
|
18757
|
+
startedAt: Math.min(arrivedAt, writtenAt),
|
|
18758
|
+
...toolCallId ? { toolCallId } : {},
|
|
18744
18759
|
eventType: canonicalEventType,
|
|
18745
18760
|
integration: cli,
|
|
18746
18761
|
toolName: parsed.tool_name ?? null,
|
|
@@ -18823,7 +18838,7 @@ async function evaluateHookEvent(eventType, cli = "claude", stdinPayload, opts)
|
|
|
18823
18838
|
}
|
|
18824
18839
|
}
|
|
18825
18840
|
}
|
|
18826
|
-
var JEV_GATE_EVENTS;
|
|
18841
|
+
var legacyShimWarned = false, JEV_GATE_EVENTS;
|
|
18827
18842
|
var init_handler = __esm(() => {
|
|
18828
18843
|
init_types();
|
|
18829
18844
|
init_tool_name_canonicalize();
|
package/hermes-plugin/client.py
CHANGED
|
@@ -12,6 +12,13 @@ from pathlib import Path
|
|
|
12
12
|
from typing import Any, Mapping, Sequence
|
|
13
13
|
|
|
14
14
|
PROTOCOL_VERSION = 2
|
|
15
|
+
# Oldest daemon version this plugin falls back to (crates/fpai-ipc
|
|
16
|
+
# MIN_PROTOCOL_VERSION), and the first that carries agentSettingsPath.
|
|
17
|
+
MIN_PROTOCOL_VERSION = 1
|
|
18
|
+
AGENT_SETTINGS_PATH_SINCE = 2
|
|
19
|
+
# active.json schema that can target policies at agents (crates/failproofaid
|
|
20
|
+
# cloud_policies.rs SCOPED_DESIRED_STATE_SCHEMA_VERSION).
|
|
21
|
+
SCOPED_SCHEMA_VERSION = 3
|
|
15
22
|
MAX_FRAME_BYTES = 16 * 1024 * 1024
|
|
16
23
|
MAX_REQUEST_BYTES = 1024 * 1024
|
|
17
24
|
|
|
@@ -39,6 +46,36 @@ def daemon_socket_path() -> Path:
|
|
|
39
46
|
return home / "run" / "failproofaid.sock"
|
|
40
47
|
|
|
41
48
|
|
|
49
|
+
def _agent_targeted_deployment() -> bool:
|
|
50
|
+
"""Whether this machine's Cloud deployment targets policies at agents.
|
|
51
|
+
|
|
52
|
+
An older daemon evaluates without naming the agent, and a targeted policy
|
|
53
|
+
does not apply to an unknown one, so its answer could allow what that
|
|
54
|
+
policy denies: such a machine is never asked in the older version. A
|
|
55
|
+
deployment that exists but cannot be read counts as targeted.
|
|
56
|
+
"""
|
|
57
|
+
override = os.environ.get("FAILPROOFAI_CLOUD_POLICY_DIR", "").strip()
|
|
58
|
+
if override:
|
|
59
|
+
directory = Path(override).expanduser()
|
|
60
|
+
else:
|
|
61
|
+
root = os.environ.get("FAILPROOFAI_HOME", "").strip()
|
|
62
|
+
home = Path(root).expanduser() if root else Path.home() / ".failproofai"
|
|
63
|
+
directory = home / "policies" / "cloud-policies"
|
|
64
|
+
# Read directly: `Path.exists()` reports a permission error as absent, and
|
|
65
|
+
# only a manifest that is NOT THERE means no deployment.
|
|
66
|
+
try:
|
|
67
|
+
text = (directory / "active.json").read_text(encoding="utf-8")
|
|
68
|
+
except FileNotFoundError:
|
|
69
|
+
return False
|
|
70
|
+
except OSError:
|
|
71
|
+
return True
|
|
72
|
+
try:
|
|
73
|
+
version = json.loads(text).get("schemaVersion")
|
|
74
|
+
except (ValueError, AttributeError):
|
|
75
|
+
return True
|
|
76
|
+
return not (type(version) is int and version < SCOPED_SCHEMA_VERSION)
|
|
77
|
+
|
|
78
|
+
|
|
42
79
|
def _remaining_timeout(deadline: float) -> float:
|
|
43
80
|
remaining = deadline - time.monotonic()
|
|
44
81
|
if remaining <= 0:
|
|
@@ -70,41 +107,8 @@ def _string_list(value: object, field: str) -> tuple[str, ...]:
|
|
|
70
107
|
return tuple(value)
|
|
71
108
|
|
|
72
109
|
|
|
73
|
-
def
|
|
74
|
-
|
|
75
|
-
event: str,
|
|
76
|
-
payload: Mapping[str, Any],
|
|
77
|
-
cwd: str | None,
|
|
78
|
-
agent_settings_path: str | None = None,
|
|
79
|
-
connect_timeout_ms: int = 250,
|
|
80
|
-
evaluation_timeout_ms: int = 12_000,
|
|
81
|
-
) -> PolicyVerdict:
|
|
82
|
-
request = {
|
|
83
|
-
"type": "policyEvaluation",
|
|
84
|
-
"protocolVersion": PROTOCOL_VERSION,
|
|
85
|
-
"integration": "hermes",
|
|
86
|
-
"event": event,
|
|
87
|
-
"payload": dict(payload),
|
|
88
|
-
"cwd": cwd,
|
|
89
|
-
# An unknown profile is explicit. Omitting this field would let a new
|
|
90
|
-
# daemon's warm worker attribute the call to its own Hermes home.
|
|
91
|
-
"agentSettingsPath": agent_settings_path or "",
|
|
92
|
-
}
|
|
93
|
-
try:
|
|
94
|
-
body = json.dumps(
|
|
95
|
-
request,
|
|
96
|
-
ensure_ascii=False,
|
|
97
|
-
separators=(",", ":"),
|
|
98
|
-
default=lambda value: repr(value),
|
|
99
|
-
).encode("utf-8")
|
|
100
|
-
except (TypeError, ValueError) as exc:
|
|
101
|
-
raise EvaluationError(f"could not encode policy request: {exc}") from exc
|
|
102
|
-
if len(body) > MAX_REQUEST_BYTES:
|
|
103
|
-
raise EvaluationError("policy request exceeds the 1 MiB limit")
|
|
104
|
-
|
|
105
|
-
# One deadline covers connect, send and read: evaluation_timeout_ms is the
|
|
106
|
-
# longest a tool call can wait here. Connect is bounded by both budgets.
|
|
107
|
-
deadline = time.monotonic() + max(evaluation_timeout_ms, 1) / 1000
|
|
110
|
+
def _exchange(body: bytes, connect_timeout_ms: int, deadline: float) -> Any:
|
|
111
|
+
"""One framed request and its framed reply over a fresh connection."""
|
|
108
112
|
try:
|
|
109
113
|
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
|
|
110
114
|
sock.settimeout(min(max(connect_timeout_ms, 1) / 1000, _remaining_timeout(deadline)))
|
|
@@ -117,15 +121,71 @@ def evaluate_policy(
|
|
|
117
121
|
declared_length = struct.unpack(">I", _read_exact(sock, 4, deadline))[0]
|
|
118
122
|
if declared_length > MAX_FRAME_BYTES:
|
|
119
123
|
raise EvaluationError("failproofaid response exceeds the 16 MiB limit")
|
|
120
|
-
|
|
124
|
+
return json.loads(_read_exact(sock, declared_length, deadline).decode("utf-8"))
|
|
121
125
|
except EvaluationError:
|
|
122
126
|
raise
|
|
123
127
|
except (OSError, UnicodeError, ValueError, struct.error) as exc:
|
|
124
128
|
raise EvaluationError(f"failproofaid evaluation failed: {exc}") from exc
|
|
125
129
|
|
|
130
|
+
|
|
131
|
+
def evaluate_policy(
|
|
132
|
+
*,
|
|
133
|
+
event: str,
|
|
134
|
+
payload: Mapping[str, Any],
|
|
135
|
+
cwd: str | None,
|
|
136
|
+
agent_settings_path: str | None = None,
|
|
137
|
+
connect_timeout_ms: int = 250,
|
|
138
|
+
evaluation_timeout_ms: int = 12_000,
|
|
139
|
+
) -> PolicyVerdict:
|
|
140
|
+
def build(version: int) -> bytes:
|
|
141
|
+
request: dict[str, Any] = {
|
|
142
|
+
"type": "policyEvaluation",
|
|
143
|
+
"protocolVersion": version,
|
|
144
|
+
"integration": "hermes",
|
|
145
|
+
"event": event,
|
|
146
|
+
"payload": dict(payload),
|
|
147
|
+
"cwd": cwd,
|
|
148
|
+
}
|
|
149
|
+
if version >= AGENT_SETTINGS_PATH_SINCE:
|
|
150
|
+
# An unknown profile is explicit. Omitting this field would let a new
|
|
151
|
+
# daemon's warm worker attribute the call to its own Hermes home.
|
|
152
|
+
request["agentSettingsPath"] = agent_settings_path or ""
|
|
153
|
+
try:
|
|
154
|
+
body = json.dumps(
|
|
155
|
+
request,
|
|
156
|
+
ensure_ascii=False,
|
|
157
|
+
separators=(",", ":"),
|
|
158
|
+
default=lambda value: repr(value),
|
|
159
|
+
).encode("utf-8")
|
|
160
|
+
except (TypeError, ValueError) as exc:
|
|
161
|
+
raise EvaluationError(f"could not encode policy request: {exc}") from exc
|
|
162
|
+
if len(body) > MAX_REQUEST_BYTES:
|
|
163
|
+
raise EvaluationError("policy request exceeds the 1 MiB limit")
|
|
164
|
+
return body
|
|
165
|
+
|
|
166
|
+
# One deadline covers connect, send and read: evaluation_timeout_ms is the
|
|
167
|
+
# longest a tool call can wait here. Connect is bounded by both budgets.
|
|
168
|
+
deadline = time.monotonic() + max(evaluation_timeout_ms, 1) / 1000
|
|
169
|
+
version = PROTOCOL_VERSION
|
|
170
|
+
response = _exchange(build(version), connect_timeout_ms, deadline)
|
|
171
|
+
answered = response.get("protocolVersion") if isinstance(response, dict) else None
|
|
172
|
+
# An older daemon still inside the supported range: ask again in its version
|
|
173
|
+
# rather than block every call until it is replaced.
|
|
174
|
+
if (
|
|
175
|
+
type(answered) is int
|
|
176
|
+
and MIN_PROTOCOL_VERSION <= answered < PROTOCOL_VERSION
|
|
177
|
+
and not _agent_targeted_deployment()
|
|
178
|
+
):
|
|
179
|
+
version = answered
|
|
180
|
+
response = _exchange(build(version), connect_timeout_ms, deadline)
|
|
181
|
+
# Asked again after the answer: a targeted deployment activated while
|
|
182
|
+
# the older daemon was evaluating makes its answer unsafe too.
|
|
183
|
+
if _agent_targeted_deployment():
|
|
184
|
+
raise EvaluationError("failproofai protocol version mismatch")
|
|
185
|
+
|
|
126
186
|
if not isinstance(response, dict):
|
|
127
187
|
raise EvaluationError("failproofaid returned a non-object response")
|
|
128
|
-
if response.get("protocolVersion") !=
|
|
188
|
+
if response.get("protocolVersion") != version:
|
|
129
189
|
raise EvaluationError("failproofaid protocol version mismatch")
|
|
130
190
|
if response.get("type") == "error":
|
|
131
191
|
message = response.get("message")
|
|
@@ -15,11 +15,17 @@
|
|
|
15
15
|
* Self-contained on purpose — node built-ins only, nothing imported from
|
|
16
16
|
* outside this directory — because the capture copies nothing else.
|
|
17
17
|
*/
|
|
18
|
+
import { readFile } from "node:fs/promises";
|
|
18
19
|
import { createConnection } from "node:net";
|
|
20
|
+
import { performance } from "node:perf_hooks";
|
|
19
21
|
import { homedir } from "node:os";
|
|
20
22
|
import { resolve } from "node:path";
|
|
21
23
|
|
|
22
24
|
export const PROTOCOL_VERSION = 2;
|
|
25
|
+
// Oldest daemon version this plugin falls back to (crates/fpai-ipc
|
|
26
|
+
// MIN_PROTOCOL_VERSION), and the first that carries agentSettingsPath.
|
|
27
|
+
export const MIN_PROTOCOL_VERSION = 1;
|
|
28
|
+
const AGENT_SETTINGS_PATH_SINCE = 2;
|
|
23
29
|
// The daemon's frame limit (crates/fpai-ipc/src/framing.rs), both ways.
|
|
24
30
|
const MAX_FRAME_BYTES = 16 * 1024 * 1024;
|
|
25
31
|
// The payload limit the CLI applies to its stdin (handler.ts, read-stdin.ts).
|
|
@@ -28,12 +34,25 @@ const MAX_FRAME_BYTES = 16 * 1024 * 1024;
|
|
|
28
34
|
// applies to the envelope.
|
|
29
35
|
export const MAX_PAYLOAD_BYTES = 1_048_576;
|
|
30
36
|
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
|
|
37
|
+
// One budget for the whole request, matching the daemon's own read timeout on
|
|
38
|
+
// its worker (worker.rs).
|
|
39
|
+
//
|
|
40
|
+
// There is deliberately NO separate connect timeout. This client runs on the
|
|
41
|
+
// OpenClaw gateway's event loop, shared with every agent on the gateway. A
|
|
42
|
+
// Unix-socket connect to a live daemon completes in the kernel at once, but
|
|
43
|
+
// the gateway only learns of it on a later loop pass; while the gateway is
|
|
44
|
+
// busy (a cron burst, a large transcript, GC) a timer that is already overdue
|
|
45
|
+
// runs before that connect event. The 250 ms connect timer this replaced
|
|
46
|
+
// therefore measured gateway load, and reported a healthy daemon as
|
|
47
|
+
// unreachable (#1024). A daemon that is not there needs no timer: the connect
|
|
48
|
+
// fails at once with ENOENT or ECONNREFUSED. One that accepts and then hangs is
|
|
49
|
+
// caught by this budget.
|
|
36
50
|
export const RESPONSE_TIMEOUT_MS = 30_000;
|
|
51
|
+
// A connect that fails outright is retried once after this pause before the
|
|
52
|
+
// call fails closed: long enough to ride out a daemon restart re-binding its
|
|
53
|
+
// socket, short enough that a daemon that is really gone costs one tool call
|
|
54
|
+
// 100 ms.
|
|
55
|
+
export const UNREACHABLE_RETRY_DELAY_MS = 100;
|
|
37
56
|
|
|
38
57
|
const PROTOCOL_MISMATCH_MESSAGE =
|
|
39
58
|
"failproofaid is running a different protocol version than this plugin, so it cannot " +
|
|
@@ -42,6 +61,34 @@ const UNREACHABLE_MESSAGE =
|
|
|
42
61
|
"failproofaid could not be reached. This machine is configured to run hooks through it " +
|
|
43
62
|
"— check the daemon (see `failproofai config`) rather than retrying blindly.";
|
|
44
63
|
|
|
64
|
+
// active.json schema that can target policies at agents (crates/failproofaid
|
|
65
|
+
// cloud_policies.rs SCOPED_DESIRED_STATE_SCHEMA_VERSION).
|
|
66
|
+
const SCOPED_SCHEMA_VERSION = 3;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Whether this machine's Cloud deployment targets policies at agents. An older
|
|
70
|
+
* daemon evaluates without naming the agent, and a targeted policy does not
|
|
71
|
+
* apply to an unknown one, so such a machine is never asked in the older
|
|
72
|
+
* version. A deployment that exists but cannot be read counts as targeted.
|
|
73
|
+
*/
|
|
74
|
+
export async function agentTargetedDeployment(env = process.env, home = homedir()) {
|
|
75
|
+
const dir =
|
|
76
|
+
env.FAILPROOFAI_CLOUD_POLICY_DIR ||
|
|
77
|
+
resolve(env.FAILPROOFAI_HOME || resolve(home, ".failproofai"), "policies", "cloud-policies");
|
|
78
|
+
let text;
|
|
79
|
+
try {
|
|
80
|
+
text = await readFile(resolve(dir, "active.json"), "utf8");
|
|
81
|
+
} catch (err) {
|
|
82
|
+
return err?.code !== "ENOENT";
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const version = JSON.parse(text)?.schemaVersion;
|
|
86
|
+
return !(Number.isInteger(version) && version < SCOPED_SCHEMA_VERSION);
|
|
87
|
+
} catch {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
45
92
|
/** Mirrors `daemonSocket()` in src/hooks/fp-home.ts. */
|
|
46
93
|
export function daemonSocketPath(env = process.env, home = homedir()) {
|
|
47
94
|
return (
|
|
@@ -78,12 +125,12 @@ function failed(failure, message) {
|
|
|
78
125
|
* OpenClaw the evaluator always exits 0 and prints either nothing (allow) or
|
|
79
126
|
* one JSON object, so anything else is an evaluation failure — never an allow.
|
|
80
127
|
*/
|
|
81
|
-
function readHookResult(message) {
|
|
128
|
+
function readHookResult(message, protocolVersion) {
|
|
82
129
|
if (message === null || typeof message !== "object" || Array.isArray(message)) {
|
|
83
130
|
return failed("invalid", "failproofaid returned a non-object response");
|
|
84
131
|
}
|
|
85
|
-
if (message.protocolVersion !==
|
|
86
|
-
return failed("protocol-mismatch", PROTOCOL_MISMATCH_MESSAGE);
|
|
132
|
+
if (message.protocolVersion !== protocolVersion) {
|
|
133
|
+
return { ...failed("protocol-mismatch", PROTOCOL_MISMATCH_MESSAGE), daemonVersion: message.protocolVersion };
|
|
87
134
|
}
|
|
88
135
|
if (message.type === "error") {
|
|
89
136
|
const detail = typeof message.message === "string" && message.message ? message.message : "no detail";
|
|
@@ -144,16 +191,90 @@ function isVerdict(verdict) {
|
|
|
144
191
|
* CLI discards an oversized stdin and evaluates an empty payload;
|
|
145
192
|
* `oversized: true` lets the caller say so instead of discarding it silently.
|
|
146
193
|
*/
|
|
147
|
-
export function requestHookVerdict({
|
|
194
|
+
export async function requestHookVerdict(request) {
|
|
195
|
+
// One deadline for the whole call, shared by every attempt below (#1029).
|
|
196
|
+
const startedAt = performance.now();
|
|
197
|
+
const budgetMs = request.responseTimeoutMs ?? RESPONSE_TIMEOUT_MS;
|
|
198
|
+
const clock = { startedAt, budgetMs, deadline: startedAt + budgetMs };
|
|
199
|
+
|
|
200
|
+
const first = await requestWithRetry(PROTOCOL_VERSION, request, clock);
|
|
201
|
+
// An older daemon still inside the supported range: ask again in its version
|
|
202
|
+
// rather than block every call until it is replaced.
|
|
203
|
+
const older = first.ok ? undefined : first.daemonVersion;
|
|
204
|
+
if (
|
|
205
|
+
!Number.isInteger(older) ||
|
|
206
|
+
older < MIN_PROTOCOL_VERSION ||
|
|
207
|
+
older >= PROTOCOL_VERSION ||
|
|
208
|
+
(await agentTargetedDeployment())
|
|
209
|
+
) {
|
|
210
|
+
if (!first.ok) delete first.daemonVersion;
|
|
211
|
+
return first;
|
|
212
|
+
}
|
|
213
|
+
const retried = await requestWithRetry(older, request, clock);
|
|
214
|
+
// Asked again after the answer: a targeted deployment activated while the
|
|
215
|
+
// older daemon was evaluating makes its answer unsafe too.
|
|
216
|
+
if (await agentTargetedDeployment()) {
|
|
217
|
+
delete first.daemonVersion;
|
|
218
|
+
return first;
|
|
219
|
+
}
|
|
220
|
+
if (!retried.ok) delete retried.daemonVersion;
|
|
221
|
+
return retried;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* One request, asked a second time if the first never reached the daemon.
|
|
226
|
+
* Only `unreachable` is retried: nothing was sent, so asking again cannot
|
|
227
|
+
* evaluate a call twice. Every other failure came from a daemon that saw the
|
|
228
|
+
* request, and is returned as it is.
|
|
229
|
+
*
|
|
230
|
+
* Every attempt shares ONE deadline of `responseTimeoutMs`, set before the
|
|
231
|
+
* first and passed to each attempt as an absolute time: an attempt arms its
|
|
232
|
+
* timer with what is left of it just before connecting (so encoding time
|
|
233
|
+
* counts too), and the retry is skipped when the pause before it would use the
|
|
234
|
+
* rest. A fresh budget per attempt let a call wait twice as long, past the
|
|
235
|
+
* gateway's own hook timeout. Time is read from `performance.now()`, a
|
|
236
|
+
* monotonic clock, so a wall-clock change cannot stretch or shrink the budget.
|
|
237
|
+
*
|
|
238
|
+
* A failed retry keeps its own failure and agent-facing message; its `detail`
|
|
239
|
+
* (gateway log only) names both attempts, so the first attempt's cause is
|
|
240
|
+
* never lost behind the second's.
|
|
241
|
+
*/
|
|
242
|
+
async function requestWithRetry(protocolVersion, request, { startedAt, budgetMs, deadline }) {
|
|
243
|
+
const noTimeToRetry = (first) =>
|
|
244
|
+
({ ...first, detail: `${first.detail}; no time left in the ${budgetMs} ms budget to retry` });
|
|
245
|
+
|
|
246
|
+
const first = await requestOnce(protocolVersion, { ...request, deadline, budgetMs });
|
|
247
|
+
if (first.ok || first.failure !== "unreachable") return first;
|
|
248
|
+
|
|
249
|
+
const delayMs = request.retryDelayMs ?? UNREACHABLE_RETRY_DELAY_MS;
|
|
250
|
+
if (deadline - performance.now() - delayMs <= 0) return noTimeToRetry(first);
|
|
251
|
+
await new Promise((resume) => setTimeout(resume, delayMs));
|
|
252
|
+
if (deadline - performance.now() <= 0) return noTimeToRetry(first);
|
|
253
|
+
|
|
254
|
+
const second = await requestOnce(protocolVersion, { ...request, deadline, budgetMs });
|
|
255
|
+
if (second.ok) return second;
|
|
256
|
+
return {
|
|
257
|
+
...second,
|
|
258
|
+
detail:
|
|
259
|
+
`attempt 1: ${first.detail}; attempt 2: ${second.detail ?? second.message}; ` +
|
|
260
|
+
`2 attempts, ${Math.round(performance.now() - startedAt)} ms total`,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function requestOnce(protocolVersion, {
|
|
148
265
|
event,
|
|
149
266
|
payload,
|
|
150
267
|
cwd = "",
|
|
151
268
|
agentSettingsPath = "",
|
|
152
269
|
socketPath = daemonSocketPath(),
|
|
153
|
-
|
|
154
|
-
|
|
270
|
+
// The whole request's budget (for messages) and its absolute end on the
|
|
271
|
+
// performance.now() clock, shared with any retry.
|
|
272
|
+
budgetMs = RESPONSE_TIMEOUT_MS,
|
|
273
|
+
deadline = performance.now() + budgetMs,
|
|
155
274
|
}) {
|
|
156
275
|
return new Promise((done) => {
|
|
276
|
+
// Started before encoding, so the elapsed time in `detail` includes it.
|
|
277
|
+
const startedAt = performance.now();
|
|
157
278
|
let body;
|
|
158
279
|
let oversized = false;
|
|
159
280
|
try {
|
|
@@ -165,12 +286,12 @@ export function requestHookVerdict({
|
|
|
165
286
|
body = Buffer.from(
|
|
166
287
|
JSON.stringify({
|
|
167
288
|
type: "hook",
|
|
168
|
-
protocolVersion
|
|
289
|
+
protocolVersion,
|
|
169
290
|
hookEvent: event,
|
|
170
291
|
cli: "openclaw",
|
|
171
292
|
stdin,
|
|
172
293
|
...(typeof cwd === "string" && cwd ? { cwd } : {}),
|
|
173
|
-
agentSettingsPath: agentSettingsPath || "",
|
|
294
|
+
...(protocolVersion >= AGENT_SETTINGS_PATH_SINCE ? { agentSettingsPath: agentSettingsPath || "" } : {}),
|
|
174
295
|
}),
|
|
175
296
|
"utf8",
|
|
176
297
|
);
|
|
@@ -197,22 +318,32 @@ export function requestHookVerdict({
|
|
|
197
318
|
try { socket?.destroy(); } catch { /* already closed */ }
|
|
198
319
|
done(result);
|
|
199
320
|
};
|
|
321
|
+
// The agent-facing message stays the same; `detail` says what actually
|
|
322
|
+
// happened, for the gateway log (hooks.js), so the next field report can
|
|
323
|
+
// tell a missing socket from a refused one from a timeout.
|
|
324
|
+
const unreachable = (cause) =>
|
|
325
|
+
finish({ ...failed("unreachable", UNREACHABLE_MESSAGE), detail: `${cause} after ${Math.round(performance.now() - startedAt)} ms` });
|
|
200
326
|
|
|
327
|
+
// Measured after encoding, so a large payload's encoding time is charged
|
|
328
|
+
// to the same budget.
|
|
329
|
+
const remainingMs = deadline - performance.now();
|
|
330
|
+
if (remainingMs <= 0) {
|
|
331
|
+
unreachable("no time left in the request budget");
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
201
334
|
try {
|
|
202
335
|
socket = createConnection(socketPath);
|
|
203
|
-
} catch {
|
|
204
|
-
|
|
336
|
+
} catch (err) {
|
|
337
|
+
unreachable(err?.code ?? err?.message ?? String(err));
|
|
205
338
|
return;
|
|
206
339
|
}
|
|
207
|
-
timer = setTimeout(() =>
|
|
340
|
+
timer = setTimeout(() => {
|
|
341
|
+
if (connected) finish(failed("timeout", `failproofaid did not answer within ${budgetMs} ms`));
|
|
342
|
+
else unreachable("no connection within the request budget");
|
|
343
|
+
}, remainingMs);
|
|
208
344
|
|
|
209
345
|
socket.on("connect", () => {
|
|
210
346
|
connected = true;
|
|
211
|
-
clearTimeout(timer);
|
|
212
|
-
timer = setTimeout(
|
|
213
|
-
() => finish(failed("timeout", `failproofaid did not answer within ${responseTimeoutMs} ms`)),
|
|
214
|
-
responseTimeoutMs,
|
|
215
|
-
);
|
|
216
347
|
const header = Buffer.alloc(4);
|
|
217
348
|
header.writeUInt32BE(body.length, 0);
|
|
218
349
|
socket.write(Buffer.concat([header, body]));
|
|
@@ -233,22 +364,16 @@ export function requestHookVerdict({
|
|
|
233
364
|
finish(failed("invalid", "failproofaid returned a response that is not JSON"));
|
|
234
365
|
return;
|
|
235
366
|
}
|
|
236
|
-
const result = readHookResult(message);
|
|
367
|
+
const result = readHookResult(message, protocolVersion);
|
|
237
368
|
finish(result.ok && oversized ? { ...result, oversized: true } : result);
|
|
238
369
|
});
|
|
239
370
|
socket.on("error", (err) => {
|
|
240
|
-
finish(
|
|
241
|
-
|
|
242
|
-
? failed("evaluation", `failproofaid connection failed: ${err?.message ?? String(err)}`)
|
|
243
|
-
: failed("unreachable", UNREACHABLE_MESSAGE),
|
|
244
|
-
);
|
|
371
|
+
if (connected) finish(failed("evaluation", `failproofaid connection failed: ${err?.message ?? String(err)}`));
|
|
372
|
+
else unreachable(err?.code ?? err?.message ?? String(err));
|
|
245
373
|
});
|
|
246
374
|
socket.on("close", () => {
|
|
247
|
-
finish(
|
|
248
|
-
|
|
249
|
-
? failed("evaluation", "failproofaid closed the connection before returning a verdict")
|
|
250
|
-
: failed("unreachable", UNREACHABLE_MESSAGE),
|
|
251
|
-
);
|
|
375
|
+
if (connected) finish(failed("evaluation", "failproofaid closed the connection before returning a verdict"));
|
|
376
|
+
else unreachable("closed before connecting");
|
|
252
377
|
});
|
|
253
378
|
});
|
|
254
379
|
}
|
package/openclaw-plugin/hooks.js
CHANGED
|
@@ -34,6 +34,17 @@ const OBSERVATION_EVENTS = [
|
|
|
34
34
|
|
|
35
35
|
const HOOK_OPTIONS = { priority: 100, timeoutMs: 60_000 };
|
|
36
36
|
|
|
37
|
+
/** OpenClaw's id for the tool call a hook is about (on the event and the tool
|
|
38
|
+
* context of before/after_tool_call), the id its transcript records the call
|
|
39
|
+
* under. Sent as `tool_use_id` so the check joins that call in Cloud instead
|
|
40
|
+
* of sitting beside it by timestamp alone. */
|
|
41
|
+
function toolCallIdOf(p, c) {
|
|
42
|
+
for (const id of [p.toolCallId, c.toolCallId]) {
|
|
43
|
+
if (typeof id === "string" && id.length > 0) return id;
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
37
48
|
/** Claude-shaped stdin base. Extra keys are ignored by the evaluator's payload
|
|
38
49
|
* parser; they're forwarded for activity attribution. */
|
|
39
50
|
function baseMeta(payload, ctx, config, workspace) {
|
|
@@ -41,6 +52,7 @@ function baseMeta(payload, ctx, config, workspace) {
|
|
|
41
52
|
const c = ctx || {};
|
|
42
53
|
return {
|
|
43
54
|
session_id: c.sessionId ?? p.sessionId ?? c.sessionKey ?? p.sessionKey,
|
|
55
|
+
tool_use_id: toolCallIdOf(p, c),
|
|
44
56
|
cwd: workspace.resolveWorkspace(p, c, config) ?? process.cwd(),
|
|
45
57
|
transcript_path: p.transcriptPath,
|
|
46
58
|
stop_hook_active: p.stopHookActive === true,
|
|
@@ -92,7 +104,10 @@ export function registerFailproofaiHooks(api, {
|
|
|
92
104
|
} catch (err) {
|
|
93
105
|
result = { ok: false, message: `the failproofai plugin failed: ${err?.message ?? String(err)}` };
|
|
94
106
|
}
|
|
95
|
-
if (!result?.ok)
|
|
107
|
+
if (!result?.ok) {
|
|
108
|
+
const message = result?.message ?? "no verdict";
|
|
109
|
+
logFailure(api, event, result?.detail ? `${message} (${result.detail})` : message);
|
|
110
|
+
}
|
|
96
111
|
// Same outcome as the CLI's oversized stdin (warn, evaluate an empty
|
|
97
112
|
// payload), and said out loud for the same reason it is there.
|
|
98
113
|
else if (result.oversized) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "failproofai",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.16-beta.0",
|
|
4
|
+
"description": "The reliability layer for AI agents: see every failure, stop it in realtime. Policies hooked into 12 agent harnesses — Claude Code, Codex, Cursor, Hermes, OpenClaw and more — block the tool call before it runs. Local dashboard included, no account needed.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"failproofai": "./dist/cli.mjs",
|
|
7
7
|
"failproofaid": "./bin/failproofaid-shim.mjs"
|
|
@@ -127,15 +127,15 @@
|
|
|
127
127
|
"minimatch": "11.0.3"
|
|
128
128
|
},
|
|
129
129
|
"optionalDependencies": {
|
|
130
|
-
"@failproofai/failproofaid-linux-x64": "1.0.
|
|
131
|
-
"@failproofai/failproofaid-linux-arm64": "1.0.
|
|
132
|
-
"@failproofai/failproofaid-darwin-x64": "1.0.
|
|
133
|
-
"@failproofai/failproofaid-darwin-arm64": "1.0.
|
|
130
|
+
"@failproofai/failproofaid-linux-x64": "1.0.16-beta.0",
|
|
131
|
+
"@failproofai/failproofaid-linux-arm64": "1.0.16-beta.0",
|
|
132
|
+
"@failproofai/failproofaid-darwin-x64": "1.0.16-beta.0",
|
|
133
|
+
"@failproofai/failproofaid-darwin-arm64": "1.0.16-beta.0"
|
|
134
134
|
},
|
|
135
135
|
"failproofaidBinaries": {
|
|
136
|
-
"linux-x64": "
|
|
137
|
-
"linux-arm64": "
|
|
138
|
-
"darwin-x64": "
|
|
139
|
-
"darwin-arm64": "
|
|
136
|
+
"linux-x64": "201c0518311a351fafb7ba856a8a6f441d3100497c8ce68f2954575c57bd90a9",
|
|
137
|
+
"linux-arm64": "9dfbd061d38024e3680060fb753129b63e032404948f40db825517584a1b9fb4",
|
|
138
|
+
"darwin-x64": "9b4f2b8476cddbaca32f1afe1f5c37b542d08308f58cb23277cf885dc497c157",
|
|
139
|
+
"darwin-arm64": "3b7de91ac706baa744fc7c2c059ae5ebfd5b4600a6a3c726561d685cfb13c0e8"
|
|
140
140
|
}
|
|
141
141
|
}
|
package/pi-extension/index.ts
CHANGED
|
@@ -343,6 +343,7 @@ export default function failproofaiBridge(pi: PiExtensionApi) {
|
|
|
343
343
|
const decision = callPolicy("tool_call", {
|
|
344
344
|
tool_name: canonicalTool,
|
|
345
345
|
tool_input: canonicalizeToolInput(canonicalTool, e.input),
|
|
346
|
+
...(e.toolCallId ? { tool_use_id: e.toolCallId } : {}),
|
|
346
347
|
session_id: resolveSessionId(e.sessionId, resolveCwd(e.cwd)),
|
|
347
348
|
cwd: resolveCwd(e.cwd),
|
|
348
349
|
hook_event_name: "PreToolUse",
|
|
@@ -449,6 +450,7 @@ export default function failproofaiBridge(pi: PiExtensionApi) {
|
|
|
449
450
|
callPolicy("tool_result", {
|
|
450
451
|
tool_name: canonicalTool,
|
|
451
452
|
tool_input: canonicalizeToolInput(canonicalTool, e.input) ?? {},
|
|
453
|
+
...(e.toolCallId ? { tool_use_id: e.toolCallId } : {}),
|
|
452
454
|
tool_response: { content: e.content, isError: e.isError },
|
|
453
455
|
session_id: resolveSessionId(e.sessionId, resolveCwd(e.cwd)),
|
|
454
456
|
cwd: resolveCwd(e.cwd),
|
|
@@ -362,6 +362,28 @@ export function readCloudAgentScopeRequired(): boolean {
|
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
+
/**
|
|
366
|
+
* {@link readCloudAgentScopeRequired}, failing the other way: true unless the
|
|
367
|
+
* deployment is KNOWN not to target agents. For deciding whether an answer
|
|
368
|
+
* that names no agent may be used, where a manifest that exists but cannot be
|
|
369
|
+
* read must count as targeted. A machine in `oss` mode enforces no deployment.
|
|
370
|
+
*/
|
|
371
|
+
export function cloudDeploymentMayTargetAgents(): boolean {
|
|
372
|
+
if (disconnectedByConfig()) return false;
|
|
373
|
+
let text: string;
|
|
374
|
+
try {
|
|
375
|
+
text = readFileSync(resolve(cloudManagedPolicyRoot(), "active.json"), "utf8");
|
|
376
|
+
} catch (err) {
|
|
377
|
+
return (err as NodeJS.ErrnoException).code !== "ENOENT";
|
|
378
|
+
}
|
|
379
|
+
try {
|
|
380
|
+
const version = (JSON.parse(text) as { schemaVersion?: unknown })?.schemaVersion;
|
|
381
|
+
return !(typeof version === "number" && Number.isInteger(version) && version < 3);
|
|
382
|
+
} catch {
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
365
387
|
/**
|
|
366
388
|
* Cloud's Jev mode from `active.json`, or null — no deployment, no mode, or a
|
|
367
389
|
* file that cannot be read (which is then simply not a mode: the local
|