Skip to content

fix(acp): carry deny/ask rules from a BOM-saved Claude settings file - #16423

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/13656-bom-user-config-readers
Oct 4, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/13656-bom-user-config-readers

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: a hand-edited agent.json, owned kiro agent spec, or project Claude settings file saved with a UTF-8 BOM is read as what it says, not as an empty or absent file.

Windows editors (Notepad, PowerShell Out-File, VS Code "UTF-8 with BOM") write EF BB BF before the JSON, and json.loads on decoded text refuses a leading U+FEFF. Three readers still parse that way:

  • build_agent_config reads ~/.kiro/crew/agent.json (the user's agent overrides) through agent._load_json, which answers {}. The overrides silently stop applying.
  • _sanitize_agent_hooks reads the owned kiro agent specs the same way, sees {}, and skips the file, so a legacy hook key kiro-cli rejects stays in it.
  • _project_settings_restrictions reads a project's .claude/settings.local.json / .claude/settings.json and answers [] ("no rules") on a parse error. When Crew leaves the project tier out of a claude session, it carries those files' permissions.deny / permissions.ask rules inline. A BOM-saved file dropped them, and a hooks or sandbox key in it no longer withheld the exclusion.

Why it matters

One invisible byte, added by an ordinary editor, turns off a user's agent overrides, and in the Claude case drops the project's deny/ask rules from the session. The MCP config, agent-spec and workspace cli.json readers already accept the mark (#13635, #16209, #16251). These are the remaining readers from the #13656 audit outside the open config.json (#16283 / #16286) and .env (#15596) PRs.

Not a goal

What changed (motivation → approach → change)

Symptom → _project_settings_restrictions calls json.loads on decoded text → parse through the existing kiro_crew.user_json.loads_user_json, the one mechanism #16209 added for user-owned JSON.

  • acp/client.py _project_settings_restrictions: a BOM-saved project .claude/settings*.json has its deny/ask rules carried, and its hooks / sandbox keys withhold the exclusion as for a plain file.
  • user_json.py: docstring names the file classes it now serves, and notes that a reader handing json.loads raw bytes already drops the mark.
  • The agent.json overrides and owned-spec hook sanitizer were already made BOM-safe on main by fix(config): read a BOM-saved config.json in every remaining reader #16432 (through agent._load_json). This PR keeps no code change there, only regression tests.

Reader inventory for #13656

Found from the sinks (json.load / json.loads on a file read), then classed by who owns and edits the file.

Changed here:

Reader File
acp.client._project_settings_restrictions project .claude/settings*.json

Already BOM-safe on main (no change needed):

Reader Why
agent._load_json callers: build_agent_config (agent.json overrides), _sanitize_agent_hooks (owned specs), config.json reads #16432
acp.skill_projection._settings (global + workspace cli.json) calls json.loads(bytes); its encoding detection already decodes a leading BOM
providers/acp.py cli.json overlay readers #16251
MCP configs, agent specs via agent_spec_format, ~/.claude.json via dashboard/handlers/mcp.py, onboarding scan #13635, #16209

Deliberately left:

Reader Why
config.json readers not yet converted #16283 / #16286 and #16432 own this file
.env readers #15596
sandbox.kiro_internal_sandbox_enabled (~/.kiro/settings/amazon-internal.json) KiroCrew must read it exactly as kiro-cli does. Today a BOM file reads as "kiro-cli sandbox off", so KiroCrew applies its own sandbox. Accepting the mark would delegate isolation to kiro-cli's sandbox, which kiro-cli may not have turned on if it refuses the mark (not verified). The current reading is safe in both cases
agent._existing_specs_are_mine provenance check before Crew rebuilds an agents dir; a BOM spec reads as "not Crew's", which errs toward not deleting a file
platform/governance._read_json_file admin-deployed governance policy; fails closed and loud today. Accepting the mark is a governance-owner call
App manifests (app.json, AppManifest.from_json_file, install/registry pipeline) and theme packages packaged artifacts with one consistent loud refusal at install/validate time, not silently dropped config
Crew-written state (webhook hooks.json, crons, ledgers, .meta.json, workflow library, seed provenance, etc.) Crew writes these with json.dumps; no BOM appears unless a person edits internal state
Network / subprocess payloads not files a person saves

Backwards compatibility

Compatible: input without a leading U+FEFF parses exactly as before. The only newly accepted input is one leading U+FEFF.

Removes nothing: the change only widens what one reader accepts.

Tests

  • test/test_claude_project_settings_bom.py: a BOM-saved project settings file's deny/ask rules are returned, and a BOM-saved file with hooks withholds the exclusion (None). Both fail with the client.py hunk reverted ([] == [('deny', …)], [] is None).
  • test/test_agent.py::TestInstallAgent::test_fresh_install_applies_bom_saved_user_overrides and TestKiroHooksFiltering::test_sanitize_agent_hooks_repairs_a_bom_saved_owned_file: regression cover for the fix(config): read a BOM-saved config.json in every remaining reader #16432 behaviour at the two user-facing callers (override applied; repaired spec written back without the mark).

Local: BOM, user-json and agent BOM tests pass on base 150fce3c3c; flake8 clean.

Manual verification

N/A — unit coverage drives the changed reader with a real BOM-prefixed file.

Related Issues

Refs #13656

Pattern harvest

Rule candidate: semgrep
Pattern: json.loads(<path>.read_text(...)) / json.loads(raw.decode("utf-8")) on a user-owned config path instead of kiro_crew.user_json; json.loads(bytes) is already BOM-safe.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@iamwhatever
iamwhatever requested a review from a team as a code owner October 3, 2026 07:57
@iamwhatever
iamwhatever requested a review from CrysisDeu October 3, 2026 07:57
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of dc7bc652fb3b82c4d7e41b5b96a116eac0db164c — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] dc7bc65

Description read

[DESCRIPTION-READ] 93b4092ab6241c3268f8dc8d7bfa9dab34080090f7f98af3d7ab923a2f2fc570

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of dc7bc652fb3b82c4d7e41b5b96a116eac0db164c — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Nothing to check.

What this change ships

Inventory (3 items) — 3 justified

Intent: when a person saves their project's Claude settings file with a UTF-8 BOM, its deny/ask rules and its hooks/sandbox guard should still reach the session. This is a FIX.

  1. A BOM-saved project .claude/settings*.json now has its deny/ask rules carried, and a hooks/sandbox key in it now withholds the exclusion. This goes through the existing user_json.loads_user_json, which 45 call sites already use. — justified
  2. The user_json.py docstring now names the agent.json, ~/.claude.json and project Claude settings readers it serves. — justified
  3. Regression tests for BOM-saved agent.json overrides and owned-spec hook repair. These pin the behaviour fix(config): read a BOM-saved config.json in every remaining reader #16432 shipped in agent._load_json, which already calls loads_user_json at agent.py:1467. — justified

[FIRST-PRINCIPLES-REVIEWED] dc7bc65

Description read

[DESCRIPTION-READ] 9ab8b67b97f7e66aa57bef932273a67402ff85f51f48813ecedf1c1caee8c713

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed dc7bc652fb3b82c4d7e41b5b96a116eac0db164c — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] dc7bc65

Verdict parsed from the review's SHA-scoped output markers for commit dc7bc652fb3b82c4d7e41b5b96a116eac0db164c.

False positive or not applicable? A repository writer can comment:
/ai-review override fable dc7bc652fb3b82c4d7e41b5b96a116eac0db164c: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of dc7bc652fb3b82c4d7e41b5b96a116eac0db164c and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] dc7bc65

False positive or not applicable? A repository writer can comment:
/ai-review override gpt dc7bc652fb3b82c4d7e41b5b96a116eac0db164c: <one-sentence reason>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 3, 2026
@iamwhatever
iamwhatever force-pushed the fix/13656-bom-user-config-readers branch from f26c52b to 64f7cc7 Compare October 3, 2026 17:57
@iamwhatever

Copy link
Copy Markdown
Contributor Author

[operator: iamwhatever] Rebased onto origin/main 150fce3 to pick up #16441 / #16487, which fix the Windows (8) red in test_lesson_startup_embedding.py (not touched by this PR). New head 64f7cc7; CI re-running.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 3, 2026
…gs file

A Windows editor saves UTF-8 "with BOM" by default, and json.loads refuses a
leading U+FEFF. _project_settings_restrictions read a project's
.claude/settings*.json that way as "no rules", so excluding the project tier
dropped its deny/ask rules, and a hooks or sandbox key no longer withheld the
exclusion. It now parses through kiro_crew.user_json.

Regression tests also cover the agent.json overrides and the owned-spec hook
sanitizer, which read through agent._load_json and are BOM-safe on main.

Refs #13656
@iamwhatever
iamwhatever force-pushed the fix/13656-bom-user-config-readers branch from 64f7cc7 to dc7bc65 Compare October 3, 2026 18:04
@iamwhatever iamwhatever changed the title fix(config): read BOM-saved agent.json, owned specs and Claude settings fix(acp): carry deny/ask rules from a BOM-saved Claude settings file Oct 3, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

[operator: iamwhatever] First Principles BLOCK on 64f7cc7fde: upheld, verified in code. On base 150fce3c3c, agent._load_json already parses through loads_user_json (#16432, src/kiro_crew/agent.py:_load_json), and test_agent_loader_keeps_judging_crew_config_like_the_config_loader now pins that. My revert check was run against the older base.

Fixed in dc7bc652fb: both agent.py hunks removed (the file now matches main). The two test_agent.py BOM tests stay as regression cover for #16432 at its user-facing callers; the PR body says so. The client.py fix and its tests are unchanged.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 3, 2026
@chenmingwei23
chenmingwei23 merged commit 517fd2b into main Oct 4, 2026
101 of 107 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/13656-bom-user-config-readers branch October 4, 2026 06:18
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants