feat(core): add Gatekeeper config schema and policy defaults
Goal
Add the top-level gatekeeper configuration contract used by CLI, clients, and Gateway-triggered behavior.
Scope
- Add
gatekeeper.enabled,gatekeeper.model,gatekeeper.context_aware,gatekeeper.environment,gatekeeper.allow, andgatekeeper.soft_denyconfig fields. - Default
gatekeeper.modeltokilo-auto/balanced. - Keep this separate from
small_model. - Default
gatekeeper.context_awaretotruewhen Gatekeeper is enabled and the user did not specify it. - Do not use
permission.classifierorpermission_classifieras the primary config shape. - Avoid v1 fields for two-stage or expanded policy behavior unless separately approved, including
stage1_model,stage2_model,mode,hard_deny, timeout, and max-token fields. - Mirror new config schema wherever CLI config schema metadata is exposed.
Rationale
gatekeeperis more recognizable to users thanclassifier.permissionis already used for global permission overrides; nesting classifier config there creates UX and implementation confusion.- Users can already hard-deny actions through global
permissionconfig. - Timeout/token behavior should use existing provider/global model configuration unless a concrete Gatekeeper-specific need appears.
Acceptance criteria
- Config validates with
gatekeeperat top level. gatekeeper.modeldefaults tokilo-auto/balanced.small_modelbehavior is unchanged.- Explicit
context_aware: falseis preserved. permission.classifierandpermission_classifierare not required for new configs.- Unsupported two-stage/stage-model fields are not introduced in v1.
Testing
- Config schema/unit tests cover defaults, explicit overrides, and null/delete behavior if supported by surrounding config patterns.
Related Issues
#7684, #9138, #10249
Code Review Summary
Status: No Issues Found | Recommendation: Merge
What Changed Since Last Review
The previous WARNING — loadGlobal silently dropping legacy Gatekeeper field warnings from global config files — has been resolved in this commit.
Fix summary:
- Introduced a
GlobalStatetype ({ config: Info; warnings: Warning[] }) to carry both the loaded config and any accumulated warnings out of the cachedloadGlobalfunction. loadGlobalnow passes a localwarningsarray into everyloadFilecall and returns{ config, warnings }asGlobalState.- The call site (
loadInstanceState) now doeswarnings.push(...global.warnings)to propagate global-config warnings into the per-request warnings array. - A new integration test (
"reports warnings for unsupported gatekeeper v1 fields in global config") validates end-to-end that astage1_modelfield in a globalkilo.jsonproduces a warning visible to callers.
Other Observations (not in diff)
Cloud schema mirror may still be needed (config.ts:176–178, cloud repo)
The NOTE comment in Config.Info states that any new kilocode_change key added to Config.Info must also be mirrored in apps/web/src/app/config.json/extras.ts in the cloud repo. The gatekeeper field is a new kilocode_change key. The PR description mentions this acceptance criterion. Please confirm this has been done or tracked as a follow-up.
Files Reviewed (8 files)
.changeset/gatekeeper-config.md— no issuespackages/opencode/src/config/config.ts— previous warning resolvedpackages/opencode/src/kilocode/gatekeeper/config.ts— no issuespackages/opencode/src/kilocode/skills/kilo-config.md— no issuespackages/opencode/test/kilocode/config/config.test.ts— no issues (new test added)packages/sdk/js/src/gen/types.gen.ts— no issuespackages/sdk/js/src/v2/gen/types.gen.ts— no issuespackages/sdk/openapi.json— no issues
Reviewed by claude-4.6-sonnet-20260217 · 858,831 tokens
Small correction to my review note: in current Kilo terms, the comparison point is Auto Approve, not YOLO mode.
The legacy extension implementation I was referencing lived on the old YOLO path, but the product concern for this PR is the same: if this new CLI gatekeeper contract is intended to replace that safety layer, we should be explicit about how it will integrate with today's Auto Approve flow. Right now this PR adds config only, while the old extension behavior had an actual approval interception point and deny path.
Regarding point 1, the purpose of PR'ing the config only is to keep each PR small, to avoid the issue we had with Indexing where it was difficult to review and had excessive merge conflicts due to landing it all at once. The intent was to also have all functionality behind an experimental flag until everything is merged, although I can also see how having the config exist may lead some users to want to use it.
Keeping a long-running feature branch would resolve the review difficulties, though may still encounter merge conflict issues if the branch becomes large. Let me know how you'd like to proceed on this note.
The intent on how this integrates with today's Auto Approve flow matches the spec you wrote up in #9138: That is, any Allow or Ask commands will go through the Gatekeeper model, and any Deny commands will be auto-denied.
Your concern about config file writes is valid. I had a later work item to implement migration from legacy config, but I may need to implement that as part of this PR to avoid the write conflicts you mentioned.
A few things I hope the eventual Gatekeeper runtime preserves:
gatekeeper.modelshould stay fully independent from the main working model and fromsmall_model, so users can point the reviewer at any configured provider/model, including a local/OpenAI-compatible endpoint on another machine or a frontier API model.context_awareshould distinguish direct user/session intent from untrusted evidence. Prior user permissions in the current chat/session should be considered, but tool output, web content, file content, and prompt-injection text should not be able to grant permission.- Gatekeeper should sit on the actual permission interception path, not only bash. Ideally it should cover shell commands, file edits/writes, webfetch/network access, MCP tools, task/subagent spawns, and external-directory access.
- Runtime failures, malformed model output, and timeouts should fail closed.
The config shape here seems compatible with that, especially with gatekeeper.model separate from small_model; I just wanted to make sure these requirements stay visible before the runtime behavior lands.
@marius-kilocode which way would you like to move forward with this feature? I'll need to do a rebase, but we can either go forward merging directly into main behind the feature flag, or we can keep a long-running feature branch. Let me know and we can go with it, thanks!
@shssoichiro let's go ahead with this. Since this is all behind a feature flag, do you have an estimate on how many PR's we will need for this?
To stay organized pull requests are automatically closed after 30 days of inactivity. If the pull request is still relevant please reopen it or create a fresh new one.
I should have caught up with this sooner. I'd estimate about 9 PRs, but the real number could be slightly higher or lower.
These are the tasks I currently have:
- Add Gatekeeper config schema (this PR)
- Route inspected permission requests through Gatekeeper
- Execute and parse client-side Gatekeeper requests
- Add Gatekeeper denial counters to prevent doom looping
- Add Gateway prompt-injection probe for Gatekeeper sessions
- Visibility for Gatekeeper status, decisions, and cost in UI
- Add CLI inspection and configuration commands
- Add UI settings interface
- Expand Gatekeeper with context-aware probes