MoonshotAI / MoonshotAI/kimi-code
Feature request: Structured policy API for security hooks (PreToolUse)
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
- 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).
- Structured decision object: the hook returns
{action: allow|deny|ask, reason, scope}instead of an exit code/string —scopeallowing the decision to target a single operation of a chain. - 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
- A PreToolUse hook receives the decomposed operations of a
&&chain (one entry per operation, typed arguments). - The hook decision is consumed by the runtime as a structured object; an
askon a single operation of a chain only gates that operation. - Every decision is queryable in the audit trail (command, rule, verdict, timestamp).
- The two 2026-08-29 false positives (
printf >> ~/.bashrc,python3 aegis-mode.py status) are no longer blocked by substring matching. - Commands that cannot be safely decomposed (complex quoting/substitutions) fall back conservatively to
askon the whole command. - A malformed hook decision falls back to the safe default (
ask) and logs the error. - Hooks for tools without a structured representation receive the current string fallback (no crash).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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