MoonshotAI / MoonshotAI/kimi-code

Feature request: Structured policy API for security hooks (PreToolUse)

Open
#3,360 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

Feature request: Structured policy API for security hooks (PreToolUse)

Context

Security hooks (e.g. the local permission hook, Aegis) decide allow/deny by parsing the command string received from the runtime. Documented on 2026-08-29:

Command Actual intent Hook verdict Failure mode
printf '...' >> ~/.bashrc legitimate append blocked ("dangerous pattern") false positive: judged on shape, not effect
python3 aegis-mode.py status read-only status query blocked false positive: the string contains a protected path but never modifies it
cmd1 && cmd2 chains two operations approved false negative: chaining decomposes the command out of reach of the analysis

Net effect: friction on safe commands AND a bypass on compound commands — the worst of both worlds for a security layer.

Problem or Gap

Hooks receive a raw command string. Substring matching cannot distinguish "mentions a protected path" from "writes to a protected path", and it cannot see the individual operations of a &&/||/; chain. Policy decisions therefore produce both false positives and false negatives.

Proposal

  1. Structured call representation: PreToolUse hooks receive a structured representation of the call instead of a string — the tool invoked, typed arguments, and for shell commands the decomposed operations (each segment of a chain presented as a distinct, individually analyzable operation).
  2. Structured decision object: the hook returns {action: allow|deny|ask, reason, scope} instead of an exit code/string — scope allowing the decision to target a single operation of a chain.
  3. Queryable audit trail: every decision (allow/deny/ask) is logged in a queryable audit trail: timestamp, concerned call, triggering rule, verdict.

Prior art (open source): deepseek-harness monorepo 0.1.2-alpha.1, packages/guard/command-policy/ — a declarative policy engine.

Impact

  • Fewer false positives: verdicts on operation semantics instead of substrings.
  • No cheap bypass: each chain operation is individually analyzed.
  • Auditability: decisions are recorded with their rule and reason, queryable after the fact.

Acceptance criteria

  1. A PreToolUse hook receives the decomposed operations of a && chain (one entry per operation, typed arguments).
  2. The hook decision is consumed by the runtime as a structured object; an ask on a single operation of a chain only gates that operation.
  3. Every decision is queryable in the audit trail (command, rule, verdict, timestamp).
  4. The two 2026-08-29 false positives (printf >> ~/.bashrc, python3 aegis-mode.py status) are no longer blocked by substring matching.
  5. Commands that cannot be safely decomposed (complex quoting/substitutions) fall back conservatively to ask on the whole command.
  6. A malformed hook decision falls back to the safe default (ask) and logs the error.
  7. Hooks for tools without a structured representation receive the current string fallback (no crash).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the PreToolUse hook and runtime decision-handling entry points, then trace the current string-based hook contract and fallback behavior. Compare the existing flow with the acceptance criteria, including chain decomposition, structured decisions, audit logging, conservative fallbacks, and malformed responses. Done means the listed scenarios are covered by implementation and tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
shell, typescript
Domain
cli, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.