kilocode icon indicating copy to clipboard operation
kilocode copied to clipboard

feat(core): add Gatekeeper config schema and policy defaults

Open shssoichiro opened this issue 6 months ago • 6 comments

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, and gatekeeper.soft_deny config fields.
  • Default gatekeeper.model to kilo-auto/balanced.
  • Keep this separate from small_model.
  • Default gatekeeper.context_aware to true when Gatekeeper is enabled and the user did not specify it.
  • Do not use permission.classifier or permission_classifier as 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

  • gatekeeper is more recognizable to users than classifier.
  • permission is already used for global permission overrides; nesting classifier config there creates UX and implementation confusion.
  • Users can already hard-deny actions through global permission config.
  • Timeout/token behavior should use existing provider/global model configuration unless a concrete Gatekeeper-specific need appears.

Acceptance criteria

  • Config validates with gatekeeper at top level.
  • gatekeeper.model defaults to kilo-auto/balanced.
  • small_model behavior is unchanged.
  • Explicit context_aware: false is preserved.
  • permission.classifier and permission_classifier are 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

shssoichiro avatar May 14 '26 18:05 shssoichiro

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 GlobalState type ({ config: Info; warnings: Warning[] }) to carry both the loaded config and any accumulated warnings out of the cached loadGlobal function.
  • loadGlobal now passes a local warnings array into every loadFile call and returns { config, warnings } as GlobalState.
  • The call site (loadInstanceState) now does warnings.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 a stage1_model field in a global kilo.json produces 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 issues
  • packages/opencode/src/config/config.ts — previous warning resolved
  • packages/opencode/src/kilocode/gatekeeper/config.ts — no issues
  • packages/opencode/src/kilocode/skills/kilo-config.md — no issues
  • packages/opencode/test/kilocode/config/config.test.ts — no issues (new test added)
  • packages/sdk/js/src/gen/types.gen.ts — no issues
  • packages/sdk/js/src/v2/gen/types.gen.ts — no issues
  • packages/sdk/openapi.json — no issues

Reviewed by claude-4.6-sonnet-20260217 · 858,831 tokens

kilo-code-bot[bot] avatar May 14 '26 18:05 kilo-code-bot[bot]

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.

marius-kilocode avatar May 15 '26 13:05 marius-kilocode

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.

shssoichiro avatar May 15 '26 13:05 shssoichiro

A few things I hope the eventual Gatekeeper runtime preserves:

  • gatekeeper.model should stay fully independent from the main working model and from small_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_aware should 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.

remesis avatar May 21 '26 00:05 remesis

@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 avatar May 27 '26 01:05 shssoichiro

@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?

marius-kilocode avatar Jun 17 '26 08:06 marius-kilocode

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.

github-actions[bot] avatar Jul 18 '26 06:07 github-actions[bot]

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

shssoichiro avatar Jul 18 '26 19:07 shssoichiro