failproofai 1.0.15 → 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 +13 -13
- 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 +2 -2
- 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 +2 -2
- 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 +2 -2
- 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 +2 -2
- package/.next/standalone/.next/server/app/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/policies/page/build-manifest.json +2 -2
- 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 +2 -2
- 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 +2 -2
- 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 +2 -2
- 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 +2 -2
- 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/_0tovk6q0miud6._.js +1 -1
- package/.next/standalone/.next/server/chunks/_0trp3ycqv17cl._.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]__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/_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/_1djqs9i27e4kg._.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_0e3yg5gbcfsai.js → node_modules_html-to-image_es_index_0wgfci23_yqs_.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 +13 -13
- 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/{0oxlfb02aqo3e.js → 0fqjv13piwa6z.js} +1 -1
- package/.next/standalone/.next/static/chunks/{1osrmi14e2jub.js → 0y9qczsccrmmf.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0p14j2e6dnj1x.js → 0z70k3nof30ws.js} +1 -1
- package/.next/standalone/.next/static/chunks/{05g1pu2r8o5q3.js → 167exo9u6npy3.js} +1 -1
- package/.next/standalone/.next/static/chunks/{098vx6twrn-vk.js → 1xwh61k4505md.js} +1 -1
- package/.next/standalone/.next/static/chunks/{3d6_vjbvr0c2n.js → 24nikgpkr0qas.js} +1 -1
- package/.next/standalone/.next/static/chunks/{38lnk75xvqiug.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/{1i9zuw01f0ogt.js → 3r-j6pmqrq4l1.js} +2 -2
- package/.next/standalone/.next/static/chunks/{2zwsbp8xyfv__.js → 3tfcj166ki-08.js} +1 -1
- package/.next/standalone/.next/static/chunks/{12ys9uaq6i1h2.js → 3uj5quosl7j_x.js} +1 -1
- package/.next/standalone/hermes-plugin/client.py +97 -37
- package/.next/standalone/hermes-plugin/plugin.yaml +1 -1
- package/.next/standalone/package.json +9 -9
- package/.next/standalone/server.js +1 -1
- package/bin/failproofai.mjs +66 -90
- package/dist/cli.mjs +1421 -1489
- 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 +72 -16
- package/openclaw-plugin/hooks.js +12 -0
- package/package.json +9 -9
- 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]__05-glpesefmmi._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/_0ge1hz9485xpp._.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/2o8j51ujh1ox4.js +0 -1
- /package/.next/standalone/.next/static/{-AugwIGiiIYcahO4J7mdM → _rnWxsoAWV0JPMURamq78}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{-AugwIGiiIYcahO4J7mdM → _rnWxsoAWV0JPMURamq78}/_clientMiddlewareManifest.js +0 -0
- /package/.next/standalone/.next/static/{-AugwIGiiIYcahO4J7mdM → _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,12 +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";
|
|
19
20
|
import { performance } from "node:perf_hooks";
|
|
20
21
|
import { homedir } from "node:os";
|
|
21
22
|
import { resolve } from "node:path";
|
|
22
23
|
|
|
23
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;
|
|
24
29
|
// The daemon's frame limit (crates/fpai-ipc/src/framing.rs), both ways.
|
|
25
30
|
const MAX_FRAME_BYTES = 16 * 1024 * 1024;
|
|
26
31
|
// The payload limit the CLI applies to its stdin (handler.ts, read-stdin.ts).
|
|
@@ -56,6 +61,34 @@ const UNREACHABLE_MESSAGE =
|
|
|
56
61
|
"failproofaid could not be reached. This machine is configured to run hooks through it " +
|
|
57
62
|
"— check the daemon (see `failproofai config`) rather than retrying blindly.";
|
|
58
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
|
+
|
|
59
92
|
/** Mirrors `daemonSocket()` in src/hooks/fp-home.ts. */
|
|
60
93
|
export function daemonSocketPath(env = process.env, home = homedir()) {
|
|
61
94
|
return (
|
|
@@ -92,12 +125,12 @@ function failed(failure, message) {
|
|
|
92
125
|
* OpenClaw the evaluator always exits 0 and prints either nothing (allow) or
|
|
93
126
|
* one JSON object, so anything else is an evaluation failure — never an allow.
|
|
94
127
|
*/
|
|
95
|
-
function readHookResult(message) {
|
|
128
|
+
function readHookResult(message, protocolVersion) {
|
|
96
129
|
if (message === null || typeof message !== "object" || Array.isArray(message)) {
|
|
97
130
|
return failed("invalid", "failproofaid returned a non-object response");
|
|
98
131
|
}
|
|
99
|
-
if (message.protocolVersion !==
|
|
100
|
-
return failed("protocol-mismatch", PROTOCOL_MISMATCH_MESSAGE);
|
|
132
|
+
if (message.protocolVersion !== protocolVersion) {
|
|
133
|
+
return { ...failed("protocol-mismatch", PROTOCOL_MISMATCH_MESSAGE), daemonVersion: message.protocolVersion };
|
|
101
134
|
}
|
|
102
135
|
if (message.type === "error") {
|
|
103
136
|
const detail = typeof message.message === "string" && message.message ? message.message : "no detail";
|
|
@@ -158,8 +191,34 @@ function isVerdict(verdict) {
|
|
|
158
191
|
* CLI discards an oversized stdin and evaluates an empty payload;
|
|
159
192
|
* `oversized: true` lets the caller say so instead of discarding it silently.
|
|
160
193
|
*/
|
|
161
|
-
export function requestHookVerdict(request) {
|
|
162
|
-
|
|
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;
|
|
163
222
|
}
|
|
164
223
|
|
|
165
224
|
/**
|
|
@@ -168,7 +227,7 @@ export function requestHookVerdict(request) {
|
|
|
168
227
|
* evaluate a call twice. Every other failure came from a daemon that saw the
|
|
169
228
|
* request, and is returned as it is.
|
|
170
229
|
*
|
|
171
|
-
*
|
|
230
|
+
* Every attempt shares ONE deadline of `responseTimeoutMs`, set before the
|
|
172
231
|
* first and passed to each attempt as an absolute time: an attempt arms its
|
|
173
232
|
* timer with what is left of it just before connecting (so encoding time
|
|
174
233
|
* counts too), and the retry is skipped when the pause before it would use the
|
|
@@ -180,14 +239,11 @@ export function requestHookVerdict(request) {
|
|
|
180
239
|
* (gateway log only) names both attempts, so the first attempt's cause is
|
|
181
240
|
* never lost behind the second's.
|
|
182
241
|
*/
|
|
183
|
-
async function requestWithRetry(request) {
|
|
184
|
-
const startedAt = performance.now();
|
|
185
|
-
const budgetMs = request.responseTimeoutMs ?? RESPONSE_TIMEOUT_MS;
|
|
186
|
-
const deadline = startedAt + budgetMs;
|
|
242
|
+
async function requestWithRetry(protocolVersion, request, { startedAt, budgetMs, deadline }) {
|
|
187
243
|
const noTimeToRetry = (first) =>
|
|
188
244
|
({ ...first, detail: `${first.detail}; no time left in the ${budgetMs} ms budget to retry` });
|
|
189
245
|
|
|
190
|
-
const first = await requestOnce({ ...request, deadline, budgetMs });
|
|
246
|
+
const first = await requestOnce(protocolVersion, { ...request, deadline, budgetMs });
|
|
191
247
|
if (first.ok || first.failure !== "unreachable") return first;
|
|
192
248
|
|
|
193
249
|
const delayMs = request.retryDelayMs ?? UNREACHABLE_RETRY_DELAY_MS;
|
|
@@ -195,7 +251,7 @@ async function requestWithRetry(request) {
|
|
|
195
251
|
await new Promise((resume) => setTimeout(resume, delayMs));
|
|
196
252
|
if (deadline - performance.now() <= 0) return noTimeToRetry(first);
|
|
197
253
|
|
|
198
|
-
const second = await requestOnce({ ...request, deadline, budgetMs });
|
|
254
|
+
const second = await requestOnce(protocolVersion, { ...request, deadline, budgetMs });
|
|
199
255
|
if (second.ok) return second;
|
|
200
256
|
return {
|
|
201
257
|
...second,
|
|
@@ -205,7 +261,7 @@ async function requestWithRetry(request) {
|
|
|
205
261
|
};
|
|
206
262
|
}
|
|
207
263
|
|
|
208
|
-
function requestOnce({
|
|
264
|
+
function requestOnce(protocolVersion, {
|
|
209
265
|
event,
|
|
210
266
|
payload,
|
|
211
267
|
cwd = "",
|
|
@@ -230,12 +286,12 @@ function requestOnce({
|
|
|
230
286
|
body = Buffer.from(
|
|
231
287
|
JSON.stringify({
|
|
232
288
|
type: "hook",
|
|
233
|
-
protocolVersion
|
|
289
|
+
protocolVersion,
|
|
234
290
|
hookEvent: event,
|
|
235
291
|
cli: "openclaw",
|
|
236
292
|
stdin,
|
|
237
293
|
...(typeof cwd === "string" && cwd ? { cwd } : {}),
|
|
238
|
-
agentSettingsPath: agentSettingsPath || "",
|
|
294
|
+
...(protocolVersion >= AGENT_SETTINGS_PATH_SINCE ? { agentSettingsPath: agentSettingsPath || "" } : {}),
|
|
239
295
|
}),
|
|
240
296
|
"utf8",
|
|
241
297
|
);
|
|
@@ -308,7 +364,7 @@ function requestOnce({
|
|
|
308
364
|
finish(failed("invalid", "failproofaid returned a response that is not JSON"));
|
|
309
365
|
return;
|
|
310
366
|
}
|
|
311
|
-
const result = readHookResult(message);
|
|
367
|
+
const result = readHookResult(message, protocolVersion);
|
|
312
368
|
finish(result.ok && oversized ? { ...result, oversized: true } : result);
|
|
313
369
|
});
|
|
314
370
|
socket.on("error", (err) => {
|
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,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "failproofai",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16-beta.0",
|
|
4
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",
|
|
@@ -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
|
|
@@ -27,7 +27,6 @@ import { readCloudCredentials } from "./cloud-enrollment";
|
|
|
27
27
|
import { CODEX_UNTRUSTED_NOTICE, codexHookTrust, type CodexHookTrust } from "./codex-system-hooks";
|
|
28
28
|
import { describeMachine } from "./cloud-enrollment-cli";
|
|
29
29
|
import { cloudBaseFor } from "./cloud-connection";
|
|
30
|
-
import { listActiveCloudManagedPolicies } from "./cloud-managed-policies";
|
|
31
30
|
import { readIngestCredential } from "./collector-config";
|
|
32
31
|
import { discoverPolicyFiles } from "./custom-hooks-loader";
|
|
33
32
|
import { daemonSocketPresent, isDaemonConfigured } from "./daemon-client";
|
|
@@ -44,7 +43,7 @@ import { isAgentTraced, readConfig, readCredentials, readVersionFile } from "./f
|
|
|
44
43
|
import { collectorHealthFile, customPoliciesDir } from "./fp-home";
|
|
45
44
|
import { configuredCustomPolicyPaths, findProjectConfigDir, readMergedHooksConfig } from "./hooks-config";
|
|
46
45
|
import { detectInstalledClis, listInstallableIds } from "./integrations";
|
|
47
|
-
import { notEnforcingReason, type NotEnforcingReason } from "./manager";
|
|
46
|
+
import { cloudPolicyStatus, notEnforcingReason, type NotEnforcingReason } from "./manager";
|
|
48
47
|
import { hasInstalledRegexPacks, readInstalledPacks } from "./pack-manifest";
|
|
49
48
|
import { CORE_SOURCE } from "./pack-store";
|
|
50
49
|
import { formatDuration, listActivePauses } from "./session-pause";
|
|
@@ -84,6 +83,8 @@ export type StatusCloud =
|
|
|
84
83
|
| {
|
|
85
84
|
kind: "file";
|
|
86
85
|
host: string;
|
|
86
|
+
/** The dashboard as configured, path included. */
|
|
87
|
+
url?: string;
|
|
87
88
|
/** The org as the server named it at connect time, when it did. */
|
|
88
89
|
org?: string;
|
|
89
90
|
machine?: string;
|
|
@@ -258,17 +259,12 @@ export function summarizePolicySources(cwd?: string): StatusPolicies {
|
|
|
258
259
|
// An unreadable manifest is reported by `failproofai policies`.
|
|
259
260
|
}
|
|
260
261
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
else summary.cloudOn++;
|
|
268
|
-
}
|
|
269
|
-
} catch {
|
|
270
|
-
// No deployment, or an unreadable one: nothing comes from there.
|
|
271
|
-
}
|
|
262
|
+
// Every assignment, whatever agent it targets, JS and Cloud Jev alike:
|
|
263
|
+
// counting JS alone showed "None installed" beside a Jev-only deployment the
|
|
264
|
+
// line below it called enforcing.
|
|
265
|
+
const cloud = cloudPolicyStatus();
|
|
266
|
+
summary.cloudOn += cloud.count;
|
|
267
|
+
summary.observing += cloud.observingCount;
|
|
272
268
|
|
|
273
269
|
// Deduplicated by path: run from the home directory, the project's convention
|
|
274
270
|
// folder IS the global one.
|
|
@@ -323,6 +319,7 @@ export async function gatherStatusFacts(deps: StatusDeps = {}): Promise<StatusFa
|
|
|
323
319
|
cloud = {
|
|
324
320
|
kind: "file",
|
|
325
321
|
host,
|
|
322
|
+
url: base,
|
|
326
323
|
...(orgName ? { org: orgName } : {}),
|
|
327
324
|
...(machineId ? { machine: describeMachine(machineId, creds?.machineLabel) } : {}),
|
|
328
325
|
pullsPolicies: Boolean(creds),
|
|
@@ -434,9 +431,13 @@ export function pickStatusAttention(facts: StatusFacts): StatusAttention | null
|
|
|
434
431
|
? "failproofai config"
|
|
435
432
|
: facts.notEnforcing === "observe-only"
|
|
436
433
|
? "failproofai policies"
|
|
437
|
-
:
|
|
438
|
-
?
|
|
439
|
-
:
|
|
434
|
+
: cloud.kind === "env"
|
|
435
|
+
? cloud.url
|
|
436
|
+
: cloud.kind === "file" && cloud.pullsPolicies
|
|
437
|
+
? (cloud.url ?? cloud.host)
|
|
438
|
+
: policies.packsInstalled > 0
|
|
439
|
+
? "failproofai policies add"
|
|
440
|
+
: `failproofai policies add ${CORE_SOURCE}`;
|
|
440
441
|
return { severity: "caution", text: "Policies are not enforcing yet.", fix };
|
|
441
442
|
}
|
|
442
443
|
if (facts.codex?.kind === "untrusted") {
|
|
@@ -530,20 +531,31 @@ export function renderStatusScreen(facts: StatusFacts, opts: ScreenKitOpts & { c
|
|
|
530
531
|
if (!health.delivering) return `${kit.off} Not delivering, failproofaid has no key`;
|
|
531
532
|
// Batches an earlier key had refused wait for the daemon to re-send them
|
|
532
533
|
// with the key that works now: queued, not refused.
|
|
533
|
-
|
|
534
|
+
// So do batches an outage parked: the daemon retries them itself.
|
|
535
|
+
const retrying = refused.retrying ?? 0;
|
|
536
|
+
const pending = queued + (refused.resending ?? 0) + retrying;
|
|
534
537
|
const backlog = pending === 0 ? "nothing queued" : `${many(pending, "batch", "batches")} queued`;
|
|
538
|
+
// A long outage moves the spool into `failed/` batch by batch, so the spool
|
|
539
|
+
// alone always looks young: the parked batches' age counts too.
|
|
540
|
+
const waiting = queued + retrying;
|
|
541
|
+
const oldestWaitingMs = Math.max(
|
|
542
|
+
queued > 0 ? (oldestQueuedMs ?? 0) : 0,
|
|
543
|
+
retrying > 0 ? (refused.oldestAgeMs ?? 0) : 0,
|
|
544
|
+
);
|
|
535
545
|
const stuck =
|
|
536
|
-
|
|
537
|
-
|
|
546
|
+
waiting > 0 &&
|
|
547
|
+
oldestWaitingMs > STATUS_QUEUE_STUCK_MS &&
|
|
538
548
|
(health.lastOkAt === undefined || now - health.lastOkAt > STATUS_QUEUE_STUCK_MS);
|
|
539
549
|
if (stuck) {
|
|
540
550
|
const last = health.lastOkAt !== undefined ? `last delivered ${ago(health.lastOkAt)}` : "nothing delivered since failproofaid started";
|
|
541
|
-
return kit.caution(`${many(
|
|
551
|
+
return kit.caution(`${many(waiting, "batch", "batches")} queued, oldest ${formatDuration(oldestWaitingMs)}, ${last}`);
|
|
542
552
|
}
|
|
543
553
|
const lastEvent = health.lastEventAt !== undefined ? `last event ${ago(health.lastEventAt)}` : "no events since failproofaid started";
|
|
544
554
|
return `${kit.on} Healthy, ${lastEvent}, ${backlog}`;
|
|
545
555
|
};
|
|
546
556
|
|
|
557
|
+
// Its policies are deployed from Cloud, so "install some" is the wrong advice.
|
|
558
|
+
const cloudManaged = cloud.kind === "env" || (cloud.kind === "file" && cloud.pullsPolicies);
|
|
547
559
|
const policiesValue = (): string => {
|
|
548
560
|
const clauses: string[] = [];
|
|
549
561
|
if (policies.packOn > 0) {
|
|
@@ -558,7 +570,8 @@ export function renderStatusScreen(facts: StatusFacts, opts: ScreenKitOpts & { c
|
|
|
558
570
|
if (policies.observing > 0) clauses.push(`${policies.observing} observing`);
|
|
559
571
|
if (policies.refusedPacks > 0) clauses.push(`${many(policies.refusedPacks, "pack")} will not load`);
|
|
560
572
|
if (clauses.length > 0) return clauses.join(", ");
|
|
561
|
-
|
|
573
|
+
if (policies.anyPack) return `0 on from ${policies.anyPack}`;
|
|
574
|
+
return cloudManaged ? "None deployed from Cloud" : "None installed";
|
|
562
575
|
};
|
|
563
576
|
|
|
564
577
|
// Only when failproofai's Codex hooks are installed at user scope: whether
|