🛂 The approval model: what a coding agent may do in a chitragupta project

Status: decided 2026-12-01; implemented for the webapp's Claude Code, Codex and OpenCode sessions, and for terminal sessions of all three. decide, the scope file, the scope guard and the terminal's answer (terminal.py) are in chitragupta/core/policy/; the three adapters, Claude Code's ask hook, OpenCode's gate plugin and the webapp's agent session, which writes the scope file and answers every call with decide, are in chitragupta/webapp/agent/, with the for this draft answer, the draft selector's binding, the bind snapshot, the gate after every edit and the rollback. The terminal's hook, OpenCode plugin and static rules (issue 1332) are written by chitragupta init and shipped in the release zip; the section In the terminal describes them. The tier table it reads is plans/1269-tier-table.md, the canonical table for issue 1269.

Written for anyone building or changing the webapp's agent session, a harness adapter, the scope guard, or the policy in chitragupta/core/. Assumed: HARNESS.md for how each harness is driven, including its section "Approval channels and per-call checks", which holds the measured facts this page relies on. Not covered here: the citation gate, which checks what a draft says. This page is about what the agent may do.

❗ The threat

The drafting skills read parsed PDF passages (draft retrieve, picks in outline.md). That text is untrusted. A passage can tell the agent to run a command, send data out, edit files, or record a sign-off. A person picking a passage for its claim may never read all of it. The agent cannot tell an instruction it was given from one it read.

🧭 The model in one paragraph

Three layers, one policy. A scope file the server owns says what the agent may currently change: read, or draft:<path>. Before a tool call runs, one function in chitragupta/core/, decide(action, scope) → allow | deny | ask, matches the call against the tier table's list for that scope. Inside every chitragupta command, a scope guard refuses any write the scope does not cover, so a flag that selects a write mode cannot slip past the list. Ask reaches a person as a card in the webapp's Agent pane, or as the harness's own prompt in a terminal. One agent session survives every change of scope, because the scope is a file that is re-read on every call, not a setting fixed when the agent starts.

🧱 The parts

The scope file

The scope guard, inside the core

One check, which every command's builder passes through before it runs, re-reads the scope file on every command; init, install and webapp, which have no builder, refuse whenever the variable is set:

The guard is what makes one list entry per command safe. argparse accepts any unambiguous abbreviation of a flag: --basel ran review agenda --baseline, and --wri ran --write (measured). So no list entry can tell a read from a write that a flag selects. The guard can, because it runs after argparse.

decide, and the tier table

decide takes the command line the harness is about to run, plus the current scope. It answers:

Write flags turn allow into ask. When a line matches an entry the scope allows, and a word in it selects a write mode whose row the scope does not list (the option itself, any abbreviation of it from -- and one letter up, or either with =), decide answers ask instead of allow. That is how review agenda --accept, draft dossier acronyms-suggest --apply and review union --write reach a card although each shares its entry with an allowed mode; under read, every flag-selected write asks the same way. The rule only ever asks more: it never turns anything into allow. The guard stays the last line, after argparse, and refuses any write the scope and the one-shot entries do not cover.

The tier table (plans/1269-tier-table.md) puts 103 rows (72 commands and 31 flag-selected modes) in five classes: 43 read, 27 regenerable output, 4 pipeline writers, 25 authored content, 4 excluded. A write whose only effect is a rebuildable cache (retrieval_index.json, retrieval_passage_index.json, content/overlap/) counts as a read, and so does chromadb's rewrite of content/chroma/ whenever a read opens the embedding index. A rewrite of a generated region of an authored file (draft references, figure sync) counts as authored content.

The read rule

One rule, in decide, for every harness. A read is allow when every path it names resolves inside:

Nothing the webapp keeps private is inside those roots. Reads of its runtime folder, of the scope file and its directory, and of the webapp's own harness homes (Codex's and OpenCode's) are deny. Any other read asks.

Harness What counts as a read
Claude Code the Read and NotebookRead tools. Glob and Grep always ask, for one call only: a pattern can reach past the root it names, and Grep reads hidden files
Codex it has no read tool: a plain read command line whose paths all fall inside the roots (below)
OpenCode the read, glob and grep tools

A plain read line is one plain command (no pipe, redirect, substitution or assignment) whose program and options are in this table, with the options first, each its own word, and at least one path after them:

Program Options
cat none
head, tail -n <number>
ls -l, -a, -1
sed -n, then one script <n>p or <n>,<m>p
grep -n, -i, -l, -c, -w, -F, -e <pattern>, -C, -A, -B and -m with a number; the pattern first unless -e gives it; files only

Every word is spelled so that a POSIX shell, zsh and PowerShell read it alike: bare, from letters, digits, ., _, / and -, or wholly in single or double quotes holding printable ASCII with no quote, backslash, backtick or $. A path holds no glob character, comma, tilde or non-ASCII letter, quoted or not; an absolute Windows path never counts. Anything else (sed -i, ls -R, wc, an option after a path, a combined -in, no path) is another program's line and asks.

A search never reads as a read. Every rg, rgrep, a grep with a recursive option (-r, -R, -d, --recursive and their spellings), and a grep naming a directory ask for one call only, once or deny, like a read outside the roots: a recursive search can follow a link planted under content/ to files outside it. Nothing private is under content/ (the webapp's runtime files are in its per-user folder), so a search there meets nothing of the webapp's.

The same plain read line run through Claude Code's Bash or OpenCode's bash is a read too, since decide sees only the line.

The draft scope's rows

Under draft:<path> the agent may also, for the bound draft only:

The rest stays outside the draft scope:

Each of these asks, every time. The three that share an entry with an allowed mode (--accept, --apply, union --write) ask through decide's write-flag rule above.

The bound draft's paths. draft:<path> names one .md or .tex file under content/drafts/, outside every figures/ directory; anything else in the scope file is unparseable, so read. Its paths follow the core's own rules: the dossier is content/dossiers/<path below drafts, minus suffix>/, the figures directory is figures/ beside the draft (shared by every draft in that directory), and the rendered and review mirrors are the draft's directory under content/rendered/ and content/review/. A draft row is allow when the first word after its entry is the bound draft, or, for figure new and figure look, the figures directory or a file in it. A write row whose draft is a flag's value (retrieve --log) is left to the guard.

A file tool may write less than a command:

scope.md asks, because set-language, which asks every time, and stamp write it; outline.md (the person's picks) and versions/ (what a rollback trusts) are written by commands only. Any other write asks as before.

Moving to a draft. A file write to another draft, or a draft row naming one, asks with the reason first_write under read and other_draft under draft:, and offers for this draft for that draft. A draft row's card offers no for this conversation: a grant keyed on the entry's words would cover every draft. For this draft is offered only where decide would allow the call under that draft.

The first change to a draft scope takes a dossier snapshot, and draft gate runs after every edit to the draft. So a bad session can be rolled back, and a fabricated citekey fails where it can be seen.

The always-denied list

These are refused whatever is clicked or granted:

A person runs these themselves, in a terminal or through a webapp button.

What these rules refuse that is harmless

Some of the rules above refuse lines that would have done no harm. This is accepted by the owner's decision: each rule fails closed, and the agent has another way to do the same work.

The webapp's runtime files moved out of the project with the for this draft answer (#1339), so nothing private is left under the root, and a recursive search of the project returned to the once-only card (owner, 2026-12-03). The unplaced_search rule, the glob rule and the move rule did not change with that move.

Answers to a card

A card offers for this conversation only when decide gives its ask a grant: another program's exact line, a chitragupta command, or a write to a path. These ask for one call only, once or deny:

A request that makes several calls, such as a Codex patch over several files, gets one answer from decide_all: any deny denies, every allow allows, and otherwise its card lists each path with its verdict, and offers for this conversation only when every asking call has a grant. The card's reason is the strongest asking one, whatever the order of the calls: a mode that asks every time, then an unknown tool, a read outside the read roots and a line that is not plain, then the rest. A sign-off is never joined: a request of several calls that holds one is refused, and the model is told to make the sign-off call on its own.

A sequence of reads is judged as its commands. A line of two or more plain commands joined by ; or &&, and by no other operator, gets the answer decide_all gives those commands as calls of one request, when every command but the last is a plain read line the read rule allows: ls content/drafts; ls content/dossiers is allowed, and ls content; make test offers for this conversation with the grant for make test. Each command is judged as if it ran alone, and that holds only while the commands before it change nothing: cd, a symbolic link or a written file would move what a later read reaches. So any other sequence stays one line that is not plain, asking once, and so does one whose last command is a chitragupta command that asks: its once is a one-shot scope-file entry, and the guard matches that against the one command it was written for.

Every grant ends with the conversation. A new conversation starts at read.

Sign-offs

draft spec sign and draft unit accept record that a person approved an outline or accepted a chapter. There are two ways to record one:

🖥 How ask reaches the person

In the webapp

The webapp drives the harness, and answers every approval request itself by calling decide:

How each harness is made to send every call to the webapp:

Every call reaches the webapp through The webapp answers
Claude Code --permission-prompt-tool stdio, plus a PreToolUse hook that answers ask for every call, so that auto-allowed reads and saved allow rules are covered too can_use_tool: allow or deny
Codex codex app-server with approvalPolicy: "untrusted", which asks for every command and patch, and a Codex home of the webapp's own with web search, image viewing and MCP servers off, since their calls never ask accept or decline
OpenCode opencode serve with "permission": "ask", behind a password of its own that every shell the agent runs sees empty, and a webapp plugin whose tool.execute.before refuses every call decide denies, even one that never asks once or reject, never always: OpenCode's always grants chitragupta * and overrides a configured deny

In the terminal

A terminal session has no server, so nothing rewrites a scope file and there is no card. The terminal's scope is fixed, terminal: the draft scope's rows for any draft under content/drafts/ and its dossier under content/dossiers/. decide reads it as it reads draft:<path>, with the path left free: a call's draft is the one the call names. No scope file parses to terminal, and it never binds a draft. One function in core/policy/terminal.py turns decide_all's verdict into each harness's answer; the hook and the plugin convert the harness's call into actions, refuse a write into the chitragupta package the hook runs from when that package lies inside the project, and print the answer. OpenCode's task call, which starts a subagent, is judged as Claude Code's Agent tool outside a webapp session.

Adapter deny ask Sign-offs
Claude Code PreToolUse hook, matcher *, in .claude/settings.json the hook's deny, with the reason; it blocks in bypass mode too the hook's ask, with the reason, for every call decide asks about, pytest and git included; it still asks in bypass mode ask, with the sign-off text when the line spells the command python -m chitragupta.draft ...; another spelling (chitragupta draft ..., cg draft ...) asks with the generic reason
Codex PreToolUse hook on Bash, apply_patch, Edit and Write in .codex/hooks.json, once the person has trusted it exit 2, with the reason on stderr and a deny on stdout; it blocks with approvals off too none: the call falls to Codex's own approval mode refused, with "Sign-offs are yours to run: <command>"
OpenCode tool.execute.before in .opencode/plugins/chitragupta-policy.js, which runs the Python hook that .opencode/chitragupta/policy.json names the plugin throws "*": "ask" under bash and under edit in .opencode/opencode.json: every shell call and file edit asks until the person answers "Allow always", and the prompt shows no reason refused by the plugin, with the same message

Generated static deny rules are a second line, there because a harness can skip or lose its hook. They are made from the always-denied list only: a webapp session loads them too and keeps every configured deny, so a static rule broader than what decide denies under every scope would change a webapp outcome. Each command rule matches whole words: Claude Code's permissions.deny holds Bash(<cmd>) and Bash(<cmd> *), and the always-denied paths as Edit(...) and Write(...), plus WebFetch and WebSearch; OpenCode's permission holds <cmd> and <cmd> * as deny under bash, beside "*": "ask", the same paths under edit, also beside "*": "ask", and webfetch: deny. OpenCode never gets a top-level permission["*"] nor an allow, since patterns cannot express a draft's paths. Codex gets none (1a). A release-zip project's rules also deny writes to chitragupta/**, pyproject.toml and scripts/**.

Where they come from. chitragupta init writes every harness's tree (.claude/, .codex/, .agents/, .opencode/) with the hook, the plugin and the static rules; it has no --agent option. Each hook runs the absolute path of the interpreter that ran init, with -I, so neither the project directory nor the environment can put a planted chitragupta/ ahead of the installed package, and passes --root with the project's path. On an existing config, init adds the policy only after the person confirms, and never loosens a rule the person set (it may tighten one: a bash or edit * allow becomes ask, and a hook entry carrying the policy marker is replaced). When the person declines it for an existing .opencode/opencode.json, init writes neither the OpenCode plugin nor a new policy.json. scripts/release.py writes the same into the release zip, which has no recorded interpreter and so runs python with the zip's own package. chitragupta doctor reports a harness config without the policy, a recorded interpreter that cannot run or is not the one doctor runs under (compared by path, and through links only within one directory, so python and python3 in one virtual environment are the same interpreter while two environments' python, which can link to one base interpreter, are not; it never runs that interpreter), a running chitragupta with no terminal_hook.py, a recorded --root naming another project, and a Codex PreToolUse hook that is not trusted. A Codex trust record is reported as existing, not as current: Codex keys it to a hash of the hook that doctor cannot recompute, so a record made before the hook last changed reads the same, and Codex skips the hook until the person trusts it again after chitragupta init. In chitragupta's own source checkout, whose configs carry no policy, it says nothing about it. The hook's 5-second deadline starts once its own code runs, under the harness's 10-second timeout; it answers deny on that deadline, on any error, and when chitragupta cannot be imported at all. A stall before the deadline starts (the interpreter starting, loading the hook's entry module) falls to the harness's timeout, which Claude Code and Codex treat as non-blocking and the OpenCode plugin treats as a refusal. The Claude Code and Codex hook command ends || exit 2, so a recorded interpreter that is gone (the shell's exit 127, which both harnesses would let through) refuses too; doctor reports a release-zip project with no python on PATH.

🔒 Failing closed

⚠ What a malicious passage can still do

It can Because
Make the agent ask for something harmful Asking is free; the person must read the card
Get a tired "yes" Approval fatigue. Grants are narrow, and the always-denied list holds whatever is clicked
Write misleading prose into the bound draft Only a person reading the draft catches it; the gate catches only a fabricated citekey
Read anything in the read tier Reads are allowed by design

In the webapp, it cannot (the terminal's limits are in SECURITY.md):

🔭 Later: a chitragupta-only tool

The next step, with issue 901's MCP server, is an agent with no shell and no file tools, only chitragupta's own: run(verb, args), write_draft(path, text). Its arguments arrive structured, so nothing has to be parsed. Three rules keep that move to one new adapter, with core/ unchanged:

  1. decide and the guard work on chitragupta's own command and scope, not on a harness's payload.
  2. Turning a harness's payload into a command line stays in the adapters.
  3. Grants and card text belong to core/.

🚫 Designs turned down