Repository navigation
Track local agent profiles and enforce scoped Cloud deployments #874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chhhee10
merged 8 commits into
feat/cloud-jev-policies
from
feat/agent-scoped-cloud-policies
Oct 5, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0f26c6e
feat(enforcement): track agent profiles and enforce scoped Cloud poli…
chhhee10 1020299
fix(enforcement): bind agent scope to the originating hook
chhhee10 cc41294
test(enforcement): replay shared agent target selector cases
chhhee10 2f920d7
docs(policies): explain agent-scoped Cloud deployments
chhhee10 5d8343a
refactor(cloud): validate authority targets once per policy
chhhee10 18b5f11
fix(ipc): require v2 daemon for scoped agent identity
chhhee10 8c22f31
fix(roster): preserve existing profile IDs at capacity
chhhee10 1924794
fix(roster): reclaim unassigned stale profiles at capacity, cap 256
chhhee10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // @vitest-environment node | ||
| import { describe, expect, it } from "vitest"; | ||
| import { createHash } from "node:crypto"; | ||
| import { chmodSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import { createFixtureEnv } from "../helpers/fixture-env"; | ||
| import { assertAllow, assertPreToolUseDeny, runHook } from "../helpers/hook-runner"; | ||
|
|
||
| describe("real CLI hook distinguishes simultaneous project and user profiles", () => { | ||
| it("applies targeted Cloud JS only when the installed hook carries its actual settings scope", () => { | ||
| const fixture = createFixtureEnv(); | ||
| const projectSettings = join(fixture.cwd, ".claude", "settings.json"); | ||
| const userSettings = join(fixture.home, ".claude", "settings.json"); | ||
| mkdirSync(join(fixture.cwd, ".claude"), { recursive: true }); | ||
| mkdirSync(join(fixture.home, ".claude"), { recursive: true }); | ||
| writeFileSync(projectSettings, '{"hooks":"failproofai --hook PreToolUse --agent-scope project"}'); | ||
| writeFileSync(userSettings, '{"hooks":"failproofai --hook PreToolUse --agent-scope user"}'); | ||
|
|
||
| const fpHome = join(fixture.home, ".failproofai"); | ||
| const rosterDir = join(fpHome, "agents"); | ||
| mkdirSync(rosterDir, { recursive: true }); | ||
| const projectId = "agt_1234567890abcdef"; | ||
| const userId = "agt_abcdef1234567890"; | ||
| const roster = join(rosterDir, "roster.json"); | ||
| writeFileSync(roster, JSON.stringify({ | ||
| schemaVersion: 1, generation: 2, | ||
| agents: [ | ||
| { integration: "claude", instanceId: projectId, settingsPath: projectSettings, | ||
| profileLabel: "project", scope: "project", hookInstalled: true }, | ||
| { integration: "claude", instanceId: userId, settingsPath: userSettings, | ||
| profileLabel: "user", scope: "user", hookInstalled: true }, | ||
| ], | ||
| }), { mode: 0o600 }); | ||
| chmodSync(roster, 0o600); | ||
|
|
||
| const cloudDir = join(fpHome, "policies", "cloud-policies"); | ||
| mkdirSync(join(cloudDir, "artifacts"), { recursive: true }); | ||
| const source = `import { customPolicies, deny } from "failproofai"; | ||
| customPolicies.add({ | ||
| name: "only-project", description: "Only this installation", | ||
| match: { events: ["PreToolUse"] }, | ||
| fn: async () => deny("project agent"), | ||
| });`; | ||
| const digest = createHash("sha256").update(source).digest("hex"); | ||
| const artifact = `artifacts/${digest}.mjs`; | ||
| writeFileSync(join(cloudDir, artifact), source); | ||
| writeFileSync(join(cloudDir, "active.json"), JSON.stringify({ | ||
| schemaVersion: 3, deployment: 1, | ||
| policies: [{ | ||
| id: "scope-check", version: 1, sha256: digest, path: artifact, effect: "enforce", | ||
| agentTargets: [{ integration: "claude", instanceId: projectId }], | ||
| }], | ||
| })); | ||
|
|
||
| const payload = { | ||
| session_id: "scope-test", hook_event_name: "PreToolUse", | ||
| tool_name: "Bash", tool_input: { command: "ls" }, cwd: fixture.cwd, | ||
| }; | ||
| const project = runHook("PreToolUse", payload, { | ||
| homeDir: fixture.home, cwd: fixture.cwd, agentScope: "project", | ||
| }); | ||
| assertPreToolUseDeny(project); | ||
|
|
||
| const user = runHook("PreToolUse", payload, { | ||
| homeDir: fixture.home, cwd: fixture.cwd, agentScope: "user", | ||
| }); | ||
| assertAllow(user); | ||
|
|
||
| const legacyAmbiguous = runHook("PreToolUse", payload, { | ||
| homeDir: fixture.home, cwd: fixture.cwd, | ||
| }); | ||
| assertAllow(legacyAmbiguous); | ||
| const report = JSON.parse(readFileSync(join(cloudDir, "errors.json"), "utf8")); | ||
| expect(report.errors).toContainEqual(expect.objectContaining({ | ||
| id: "agentScope", message: expect.stringContaining("agent_scope_unresolved"), | ||
| })); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "cases": [ | ||
| {"name":"unscoped", "schemaVersion":2, "targets":null, "agent":null, "valid":true, "matches":true}, | ||
| {"name":"integration-all-profiles", "schemaVersion":3, "targets":[{"integration":"claude"}], "agent":{"integration":"claude","instanceId":"agt_1111111111111111"}, "valid":true, "matches":true}, | ||
| {"name":"integration-other-agent", "schemaVersion":3, "targets":[{"integration":"claude"}], "agent":{"integration":"codex","instanceId":"agt_1111111111111111"}, "valid":true, "matches":false}, | ||
| {"name":"profile-exact", "schemaVersion":3, "targets":[{"integration":"hermes","instanceId":"agt_2222222222222222"}], "agent":{"integration":"hermes","instanceId":"agt_2222222222222222"}, "valid":true, "matches":true}, | ||
| {"name":"profile-other-instance", "schemaVersion":3, "targets":[{"integration":"hermes","instanceId":"agt_2222222222222222"}], "agent":{"integration":"hermes","instanceId":"agt_3333333333333333"}, "valid":true, "matches":false}, | ||
| {"name":"profile-other-integration", "schemaVersion":3, "targets":[{"integration":"hermes","instanceId":"agt_2222222222222222"}], "agent":{"integration":"codex","instanceId":"agt_2222222222222222"}, "valid":true, "matches":false}, | ||
| {"name":"scope-unresolved", "schemaVersion":3, "targets":[{"integration":"codex"}], "agent":null, "valid":true, "matches":false}, | ||
| {"name":"or-combination", "schemaVersion":3, "targets":[{"integration":"claude"},{"integration":"hermes","instanceId":"agt_2222222222222222"}], "agent":{"integration":"hermes","instanceId":"agt_2222222222222222"}, "valid":true, "matches":true}, | ||
| {"name":"both-halves-same-scope", "schemaVersion":3, "targets":[{"integration":"codex"}], "agent":{"integration":"codex","instanceId":"agt_4444444444444444"}, "valid":true, "matches":true}, | ||
| {"name":"empty-array", "schemaVersion":3, "targets":[], "agent":null, "valid":false}, | ||
| {"name":"duplicate-selector", "schemaVersion":3, "targets":[{"integration":"codex"},{"integration":"codex"}], "agent":null, "valid":false}, | ||
| {"name":"unknown-integration", "schemaVersion":3, "targets":[{"integration":"invented"}], "agent":null, "valid":false}, | ||
| {"name":"invalid-profile-id", "schemaVersion":3, "targets":[{"integration":"hermes","instanceId":"bad"}], "agent":null, "valid":false}, | ||
| {"name":"scoped-in-schema-two", "schemaVersion":2, "targets":[{"integration":"claude"}], "agent":null, "valid":false} | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Use the current October 2026 date for the changelog heading.
CHANGELOG.mduses2026-09-30, which is earlier than the current date in October 2026. Update the heading to today's date and keep version1.0.10-beta.0frompackage.json.🤖 Prompt for AI Agents