intern-agent 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- intern_agent-0.1.0/LICENSE +21 -0
- intern_agent-0.1.0/PKG-INFO +242 -0
- intern_agent-0.1.0/README.md +211 -0
- intern_agent-0.1.0/intern_agent/__init__.py +2 -0
- intern_agent-0.1.0/intern_agent/__main__.py +5 -0
- intern_agent-0.1.0/intern_agent/adapters/__init__.py +41 -0
- intern_agent-0.1.0/intern_agent/adapters/claude_code.py +22 -0
- intern_agent-0.1.0/intern_agent/adapters/codex.py +235 -0
- intern_agent-0.1.0/intern_agent/adapters/generic.py +57 -0
- intern_agent-0.1.0/intern_agent/agentenv.py +60 -0
- intern_agent-0.1.0/intern_agent/capture.py +165 -0
- intern_agent-0.1.0/intern_agent/cli.py +823 -0
- intern_agent-0.1.0/intern_agent/config.py +100 -0
- intern_agent-0.1.0/intern_agent/counters.py +136 -0
- intern_agent-0.1.0/intern_agent/detect.py +125 -0
- intern_agent-0.1.0/intern_agent/distill.py +540 -0
- intern_agent-0.1.0/intern_agent/doctor.py +180 -0
- intern_agent-0.1.0/intern_agent/entry.py +137 -0
- intern_agent-0.1.0/intern_agent/evaluate.py +283 -0
- intern_agent-0.1.0/intern_agent/events.py +88 -0
- intern_agent-0.1.0/intern_agent/export.py +119 -0
- intern_agent-0.1.0/intern_agent/frontmatter.py +53 -0
- intern_agent-0.1.0/intern_agent/fsutil.py +80 -0
- intern_agent-0.1.0/intern_agent/guard.py +609 -0
- intern_agent-0.1.0/intern_agent/hooks.py +218 -0
- intern_agent-0.1.0/intern_agent/implicit.py +433 -0
- intern_agent-0.1.0/intern_agent/integrity.py +122 -0
- intern_agent-0.1.0/intern_agent/lesson.py +159 -0
- intern_agent-0.1.0/intern_agent/lifecycle.py +226 -0
- intern_agent-0.1.0/intern_agent/llm.py +112 -0
- intern_agent-0.1.0/intern_agent/lock.py +42 -0
- intern_agent-0.1.0/intern_agent/migrate.py +165 -0
- intern_agent-0.1.0/intern_agent/prompts/distill.md +33 -0
- intern_agent-0.1.0/intern_agent/prompts/eval_arm.md +9 -0
- intern_agent-0.1.0/intern_agent/prompts/eval_judge.md +24 -0
- intern_agent-0.1.0/intern_agent/redact.py +98 -0
- intern_agent-0.1.0/intern_agent/report.py +178 -0
- intern_agent-0.1.0/intern_agent/retrieve.py +267 -0
- intern_agent-0.1.0/intern_agent/review.py +78 -0
- intern_agent-0.1.0/intern_agent/rules.py +468 -0
- intern_agent-0.1.0/intern_agent/store.py +110 -0
- intern_agent-0.1.0/intern_agent/textsim.py +60 -0
- intern_agent-0.1.0/intern_agent/toml_lite.py +186 -0
- intern_agent-0.1.0/intern_agent/toolcache.py +43 -0
- intern_agent-0.1.0/intern_agent/transcript.py +648 -0
- intern_agent-0.1.0/intern_agent/trust.py +50 -0
- intern_agent-0.1.0/intern_agent.egg-info/PKG-INFO +242 -0
- intern_agent-0.1.0/intern_agent.egg-info/SOURCES.txt +61 -0
- intern_agent-0.1.0/intern_agent.egg-info/dependency_links.txt +1 -0
- intern_agent-0.1.0/intern_agent.egg-info/entry_points.txt +2 -0
- intern_agent-0.1.0/intern_agent.egg-info/top_level.txt +1 -0
- intern_agent-0.1.0/pyproject.toml +50 -0
- intern_agent-0.1.0/setup.cfg +4 -0
- intern_agent-0.1.0/tests/test_cli.py +81 -0
- intern_agent-0.1.0/tests/test_core.py +191 -0
- intern_agent-0.1.0/tests/test_detect_transcript.py +222 -0
- intern_agent-0.1.0/tests/test_distill_recall.py +335 -0
- intern_agent-0.1.0/tests/test_hooks.py +182 -0
- intern_agent-0.1.0/tests/test_review_fixes.py +343 -0
- intern_agent-0.1.0/tests/test_security.py +613 -0
- intern_agent-0.1.0/tests/test_stage2.py +482 -0
- intern_agent-0.1.0/tests/test_stage3.py +524 -0
- intern_agent-0.1.0/tests/test_stage4.py +693 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 denizbarish
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: intern-agent
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lessons a coding agent learns from its own mistakes, and checks that it keeps them.
|
|
5
|
+
Author: denizbarish
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/denizbarish/intern
|
|
8
|
+
Project-URL: Repository, https://github.com/denizbarish/intern
|
|
9
|
+
Project-URL: Issues, https://github.com/denizbarish/intern/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/denizbarish/intern/blob/main/CHANGELOG.md
|
|
11
|
+
Project-URL: Documentation, https://github.com/denizbarish/intern/tree/main/docs
|
|
12
|
+
Keywords: coding-agent,claude-code,codex,agents-md,lessons,memory,hooks,guardrails
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: MacOS
|
|
17
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Topic :: Software Development
|
|
26
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
27
|
+
Requires-Python: >=3.9
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# intern
|
|
33
|
+
|
|
34
|
+
Coding agents repeat their mistakes. You correct one on Monday and it makes the same mistake on Thursday,
|
|
35
|
+
because the correction lived in a chat that is gone. Memory tools help the agent *remember* a rule, but
|
|
36
|
+
remembering is not obeying: agents with a memory layer still broke 57.5% of the preferences that applied
|
|
37
|
+
to their task ([TellOnce, arXiv 2606.13174](https://arxiv.org/abs/2606.13174)).
|
|
38
|
+
|
|
39
|
+
intern treats every correction as a lesson and checks whether the lesson holds. Lessons are plain markdown
|
|
40
|
+
files you can read, edit, `git diff` and delete. It works with Claude Code (plugin), Codex CLI (hooks) and
|
|
41
|
+
any agent that can run a command from a hook or read `AGENTS.md`.
|
|
42
|
+
|
|
43
|
+
## How it works
|
|
44
|
+
|
|
45
|
+
1. **Capture** what went wrong: your corrections ("no, not like that", "yine olmadı"), a tool call you
|
|
46
|
+
rejected, a file you put back, a command that failed three times, the agent's own friction, review
|
|
47
|
+
findings.
|
|
48
|
+
2. **Distill** each signal into a lesson with an LLM: context, what was done, what to do instead, why, and
|
|
49
|
+
the scope where it applies (paths, tools, intents). A signal from a turn that read outside content
|
|
50
|
+
(web, issues, MCP) becomes an untrusted lesson that is never recalled until you approve it.
|
|
51
|
+
3. **Recall** only the lessons that match the work at hand, before the prompt or the tool call where they
|
|
52
|
+
matter: at most 3 lessons and 600 tokens, each once per session.
|
|
53
|
+
4. **Measure** each lesson: how often it was shown, how often it was broken anyway (`intern report`), and,
|
|
54
|
+
if you pay for it, a blind replay with and without the lesson (`intern eval`).
|
|
55
|
+
5. **Promote** a lesson that keeps being broken into a binding rule (a guard check before the tool call, an
|
|
56
|
+
instruction), only after you approve it in your own terminal.
|
|
57
|
+
|
|
58
|
+
## Install
|
|
59
|
+
|
|
60
|
+
Python 3.9 or newer, no dependencies.
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
pip install intern-agent
|
|
64
|
+
intern --version
|
|
65
|
+
intern doctor # what is missing in your agent's settings to protect intern's state
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Claude Code
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
/plugin marketplace add denizbarish/intern
|
|
72
|
+
/plugin install intern@intern
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The plugin adds three hooks (`UserPromptSubmit`, `PreToolUse`, `Stop`), the commands
|
|
76
|
+
`/intern:intern <note>`, `/intern:intern-report`, `/intern:intern-rules`, `/intern:intern-eval` and
|
|
77
|
+
`/intern:intern-review`, a skill that tells the agent when to record a papercut or a review finding, and
|
|
78
|
+
the `intern` curator subagent. Ask "what do I keep correcting?" or run `/intern:intern-review`: the
|
|
79
|
+
subagent reads the report, distills waiting events (after asking, it costs a model call), finds duplicate
|
|
80
|
+
lessons, tests proposed rules against examples with `intern guard --test`, and lists the commands only you
|
|
81
|
+
should run (`intern approve`, `approve-rule`, `reject`, `rm`). It has no Write or Edit tool and never runs
|
|
82
|
+
those commands; the guard would deny them anyway. The hooks call `intern` from `PATH`, or
|
|
83
|
+
`python3 -m intern_agent`, so install the package as well.
|
|
84
|
+
|
|
85
|
+
### Codex CLI
|
|
86
|
+
|
|
87
|
+
Codex runs hooks from `~/.codex/hooks.json` (or `[hooks]` in `config.toml`). Add:
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"hooks": {
|
|
92
|
+
"UserPromptSubmit": [{"hooks": [{"type": "command", "command": "intern hook user-prompt --agent codex", "timeout": 10}]}],
|
|
93
|
+
"PreToolUse": [{"hooks": [{"type": "command", "command": "intern hook pre-tool --agent codex", "timeout": 10}]}],
|
|
94
|
+
"Stop": [{"hooks": [{"type": "command", "command": "intern hook stop --agent codex", "timeout": 10}]}]
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
then review and trust the hooks with `/hooks` in the Codex CLI. What works and what does not, compared with
|
|
100
|
+
Claude Code:
|
|
101
|
+
|
|
102
|
+
- Recall before prompts and tool calls, corrections, papercuts and distill work the same.
|
|
103
|
+
- The guard sees shell calls and `apply_patch` edits (each file in the patch is checked). Codex documents
|
|
104
|
+
no "ask" answer for a hook, so an ask becomes a deny that says why; run the command yourself if you meant
|
|
105
|
+
it. Hosted tools such as web search run no hook, and the Codex docs call tool hooks "a useful guardrail,
|
|
106
|
+
not a complete enforcement boundary".
|
|
107
|
+
- Nothing ties a Codex hook to its session file the way `CLAUDE_CODE_SESSION_ID` does for Claude Code, so a
|
|
108
|
+
correction captured in Codex is never verified: its lesson waits as untrusted until `intern approve`.
|
|
109
|
+
- Rejected tool calls and reverted files are not detected in Codex (they come from Claude Code's
|
|
110
|
+
transcript format). The Codex session file is read only for context, and its format is not a stable
|
|
111
|
+
interface: when it changes, the context gets thinner, nothing else breaks.
|
|
112
|
+
- If you prefer no hooks at all, write the rules into `AGENTS.md` as instructions:
|
|
113
|
+
`intern export --format agents --write AGENTS.md`. Instructions are not enforced; the agent may ignore them.
|
|
114
|
+
|
|
115
|
+
### Any agent
|
|
116
|
+
|
|
117
|
+
An agent with a hook or plugin system calls the same commands with `--agent generic`, which reads and
|
|
118
|
+
writes plain JSON:
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
# before a prompt: prints {"context": "..."} with the lessons that apply, or nothing
|
|
122
|
+
echo '{"session_id": "s1", "cwd": "/repo", "prompt": "no, use pnpm", "agent_action": "tools: Bash npm i"}' \
|
|
123
|
+
| intern hook user-prompt --agent generic
|
|
124
|
+
# before a tool call: prints {"decision": "deny"|"ask", "reason": "..."}, or {"context": "..."}, or nothing
|
|
125
|
+
echo '{"session_id": "s1", "cwd": "/repo", "tool_name": "Bash", "tool_input": {"command": "git push -f"}}' \
|
|
126
|
+
| intern hook pre-tool --agent generic
|
|
127
|
+
# at the end of a turn: starts distill in the background when events are waiting
|
|
128
|
+
echo '{"session_id": "s1", "cwd": "/repo"}' | intern hook stop --agent generic
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Name shell tools `Bash` with `tool_input.command`, and file edits `Edit` or `Write` with
|
|
132
|
+
`tool_input.file_path`, to get the guard's checks. Your hook must treat a decision as binding and a crash
|
|
133
|
+
or unreadable output as "stop": the guard fails closed only if its caller does. Events can also be
|
|
134
|
+
recorded directly with `intern capture --gate <gate>`, which reads one JSON object on stdin:
|
|
135
|
+
|
|
136
|
+
| Gate | Fields |
|
|
137
|
+
|---|---|
|
|
138
|
+
| `user-correction` | `prompt` (required), `cwd`, `tool`, `paths`, `agent_action`, `outside` |
|
|
139
|
+
| `papercut` | `target`, `kind`, `happened` (required); `tried`, `expected`, `fix`, `workaround` |
|
|
140
|
+
| `review-finding` | `finding` (required); `reviewer`, `file`, `line`, `severity`, `fix` |
|
|
141
|
+
| `deferred` | `item` (required); `reason`, `by` |
|
|
142
|
+
| `manual` | `note` or `title` (required); `context`, `did`, `instead`, `why`, `do`, `dont`, `tools`, `intents` |
|
|
143
|
+
|
|
144
|
+
Agents that read only instruction files get the rules and lessons as text:
|
|
145
|
+
|
|
146
|
+
```sh
|
|
147
|
+
intern export --format agents --write AGENTS.md # Codex, Cursor, and others that read AGENTS.md
|
|
148
|
+
intern export --format claude --write CLAUDE.md # Claude Code without the plugin
|
|
149
|
+
intern export --format cursor --write .cursor/rules/intern.mdc # Cursor project rule, alwaysApply: true
|
|
150
|
+
intern export --format agents --project --write AGENTS.md # only this repository's lessons
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The block sits between `<!-- intern:begin -->` and `<!-- intern:end -->`; running it again replaces only
|
|
154
|
+
that block.
|
|
155
|
+
|
|
156
|
+
## Security model and its limits
|
|
157
|
+
|
|
158
|
+
intern runs as the same OS user as the agent it watches, so on its own it cannot stop an agent that is set
|
|
159
|
+
on rewriting `~/.intern`. What it does:
|
|
160
|
+
|
|
161
|
+
- **Trust comes from people, not from the agent.** A lesson born in an agent session, from outside
|
|
162
|
+
content, or from a signal intern cannot verify is untrusted and never recalled. `approve`, `approve-rule`,
|
|
163
|
+
`reject`, `disable-rule`, `trust` and `rm` of a lesson with a rule ask you to type the id on `/dev/tty`,
|
|
164
|
+
and refuse when an agent variable is set. Untrusted lesson ids are also kept in `integrity.json`, so
|
|
165
|
+
deleting `untrusted: true` from a lesson file grants nothing.
|
|
166
|
+
- **A guard before every tool call**, fail-closed: built-in protection of intern's files, the agents'
|
|
167
|
+
transcripts, settings and plugin folders, and of the commands that grant trust; then your approved rules.
|
|
168
|
+
- **Integrity checks** on the rules and the trust list: a change made outside intern makes the guard ask.
|
|
169
|
+
- **The boundary is your agent's settings.** `intern doctor` checks Claude Code's permission deny rules and
|
|
170
|
+
sandbox for the files that carry trust, never writes them, and prints the JSON to add.
|
|
171
|
+
|
|
172
|
+
Known limits, in full in [docs/security.md](docs/security.md): the guard reads shell commands as text and
|
|
173
|
+
can be dodged by obfuscation (`int"ern"`, `cd .intern && ...`); an agent that clears its environment and
|
|
174
|
+
drives `intern approve` through a pseudo-terminal it controls can answer the confirmation itself (the guard
|
|
175
|
+
denies the obvious forms; the permission rules are what stop it); an agent with write access to
|
|
176
|
+
`integrity.json` and a rule file can change both consistently. Run `intern doctor` and add what it asks for.
|
|
177
|
+
|
|
178
|
+
## Commands
|
|
179
|
+
|
|
180
|
+
| Command | What it does |
|
|
181
|
+
|---|---|
|
|
182
|
+
| `intern add "<title>" [--did --instead --why --tool --path --intent --project]` | Write a lesson by hand |
|
|
183
|
+
| `intern list [--kind K] [--json]` | List lessons from the global and project stores |
|
|
184
|
+
| `intern show <id> [--json]` | Print one lesson |
|
|
185
|
+
| `intern rm <id> [--yes]` | Delete a lesson (asks on the terminal when it has a rule) |
|
|
186
|
+
| `intern capture --gate <gate> [--json]` | Record an event from stdin JSON |
|
|
187
|
+
| `intern distill [--since 7d] [--dry-run] [--json]` | Turn waiting events into lessons (an LLM call) |
|
|
188
|
+
| `intern recall [--tool-only] [--json]` | Lessons for stdin JSON `{prompt, cwd, tool, tool_input, files}` |
|
|
189
|
+
| `intern hook <user-prompt\|pre-tool\|stop> [--agent claude-code\|codex\|generic]` | Hook entry point |
|
|
190
|
+
| `intern trust [path]` | Recall this repository's `.intern/` lessons (you type the folder name) |
|
|
191
|
+
| `intern approve <id>` | Recall an untrusted lesson (you type the id) |
|
|
192
|
+
| `intern stats [--json]` | Event counts, distill outcomes, correction false positive rate |
|
|
193
|
+
| `intern promote <id> [--kind --tool --pattern --unless --decision --message --text]` | Propose a rule |
|
|
194
|
+
| `intern rules [--all] [--json]` | Proposed and active rules |
|
|
195
|
+
| `intern approve-rule <id>` / `reject <id>` / `disable-rule <id>` | Turn a rule on, down or off (you type the id) |
|
|
196
|
+
| `intern guard --test <rule> '<command or path>' [--tool T]` | Try a hook-check rule against an example |
|
|
197
|
+
| `intern retire [--dry-run]` / `restore <id>` | Archive lessons unbroken for 90 days / bring one back |
|
|
198
|
+
| `intern report [--since 30d] [--json\|--markdown]` | Exposures, violations, compliance, rule proposals |
|
|
199
|
+
| `intern doctor [--json]` | Check the settings that protect intern, and intern's own state |
|
|
200
|
+
| `intern import-review <file\|-> [--reviewer R] [--dry-run]` | Record `file:line \| severity \| finding \| fix` lines |
|
|
201
|
+
| `intern eval <id> [--cases N] [--budget-usd X] [--dry-run] [--yes]` | Blind replay with and without the lesson (paid) |
|
|
202
|
+
| `intern import --from-markdown <path> [--source S] [--direct] [--dry-run]` | Import lessons kept in markdown |
|
|
203
|
+
| `intern export [--agents-md \| --format agents\|claude\|cursor] [--project] [--write PATH]` | Rules and lessons as an instruction block |
|
|
204
|
+
|
|
205
|
+
## Where things live
|
|
206
|
+
|
|
207
|
+
| Path | What |
|
|
208
|
+
|---|---|
|
|
209
|
+
| `~/.intern/` (or `$INTERN_HOME`) | Global lessons (`lessons/`), events, rules, `config.toml`; folders are mode 0700 |
|
|
210
|
+
| `<repo>/.intern/` | One repository's lessons (`intern add --project`); recalled only after `intern trust` |
|
|
211
|
+
| `events.jsonl` | Append-only raw signals; secrets, e-mail, card and phone numbers masked before writing |
|
|
212
|
+
| `stats.jsonl` | Every count: distill decisions, exposures, violations, blocked calls |
|
|
213
|
+
| `rules/`, `rules.cache` | Rule files and the active hook-check rules the guard reads |
|
|
214
|
+
| `integrity.json`, `trusted_projects.json` | The record of what a person approved and trusted |
|
|
215
|
+
| `sessions/` | Per session: lessons shown, transcript scan state, files the agent changed (removed after 7 days) |
|
|
216
|
+
| `archive/`, `evals.jsonl`, `distill.log` | Retired lessons, eval results, the background distill log |
|
|
217
|
+
|
|
218
|
+
The lesson file format is in [docs/lessons-format.md](docs/lessons-format.md), the modules and data flow
|
|
219
|
+
in [docs/architecture.md](docs/architecture.md). Settings (`config.toml`, every key optional) are listed
|
|
220
|
+
in `intern_agent/config.py`; `INTERN_LLM_CMD` overrides the distill command, which by default runs
|
|
221
|
+
`claude -p` with no tools, MCP servers, skills or settings files.
|
|
222
|
+
|
|
223
|
+
## Roadmap
|
|
224
|
+
|
|
225
|
+
All four stages of the design are done: the store and CLI (0), capture, distill and recall for Claude Code
|
|
226
|
+
(1), counters, rules, guard and report (2), implicit signals, review findings, eval and import (3), and
|
|
227
|
+
Codex, generic and `AGENTS.md` agents (4). Ideas for later, not promises:
|
|
228
|
+
|
|
229
|
+
- Verified corrections for Codex, if Codex exposes a session id to hook processes.
|
|
230
|
+
- Rejected calls and reverts for Codex from its approval events.
|
|
231
|
+
- A `lint` and `test` rule kind that writes the check into the project, with approval.
|
|
232
|
+
- Lessons shared across a team through a reviewed, signed file instead of a cloned `.intern/`.
|
|
233
|
+
|
|
234
|
+
## Contributing
|
|
235
|
+
|
|
236
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). In short: standard library only, Python 3.9, tests with
|
|
237
|
+
`python3 -m unittest discover -s tests`, and every change that touches trust gets a test that tries to
|
|
238
|
+
get around it.
|
|
239
|
+
|
|
240
|
+
## License
|
|
241
|
+
|
|
242
|
+
MIT
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# intern
|
|
2
|
+
|
|
3
|
+
Coding agents repeat their mistakes. You correct one on Monday and it makes the same mistake on Thursday,
|
|
4
|
+
because the correction lived in a chat that is gone. Memory tools help the agent *remember* a rule, but
|
|
5
|
+
remembering is not obeying: agents with a memory layer still broke 57.5% of the preferences that applied
|
|
6
|
+
to their task ([TellOnce, arXiv 2606.13174](https://arxiv.org/abs/2606.13174)).
|
|
7
|
+
|
|
8
|
+
intern treats every correction as a lesson and checks whether the lesson holds. Lessons are plain markdown
|
|
9
|
+
files you can read, edit, `git diff` and delete. It works with Claude Code (plugin), Codex CLI (hooks) and
|
|
10
|
+
any agent that can run a command from a hook or read `AGENTS.md`.
|
|
11
|
+
|
|
12
|
+
## How it works
|
|
13
|
+
|
|
14
|
+
1. **Capture** what went wrong: your corrections ("no, not like that", "yine olmadı"), a tool call you
|
|
15
|
+
rejected, a file you put back, a command that failed three times, the agent's own friction, review
|
|
16
|
+
findings.
|
|
17
|
+
2. **Distill** each signal into a lesson with an LLM: context, what was done, what to do instead, why, and
|
|
18
|
+
the scope where it applies (paths, tools, intents). A signal from a turn that read outside content
|
|
19
|
+
(web, issues, MCP) becomes an untrusted lesson that is never recalled until you approve it.
|
|
20
|
+
3. **Recall** only the lessons that match the work at hand, before the prompt or the tool call where they
|
|
21
|
+
matter: at most 3 lessons and 600 tokens, each once per session.
|
|
22
|
+
4. **Measure** each lesson: how often it was shown, how often it was broken anyway (`intern report`), and,
|
|
23
|
+
if you pay for it, a blind replay with and without the lesson (`intern eval`).
|
|
24
|
+
5. **Promote** a lesson that keeps being broken into a binding rule (a guard check before the tool call, an
|
|
25
|
+
instruction), only after you approve it in your own terminal.
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
Python 3.9 or newer, no dependencies.
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
pip install intern-agent
|
|
33
|
+
intern --version
|
|
34
|
+
intern doctor # what is missing in your agent's settings to protect intern's state
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Claude Code
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
/plugin marketplace add denizbarish/intern
|
|
41
|
+
/plugin install intern@intern
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The plugin adds three hooks (`UserPromptSubmit`, `PreToolUse`, `Stop`), the commands
|
|
45
|
+
`/intern:intern <note>`, `/intern:intern-report`, `/intern:intern-rules`, `/intern:intern-eval` and
|
|
46
|
+
`/intern:intern-review`, a skill that tells the agent when to record a papercut or a review finding, and
|
|
47
|
+
the `intern` curator subagent. Ask "what do I keep correcting?" or run `/intern:intern-review`: the
|
|
48
|
+
subagent reads the report, distills waiting events (after asking, it costs a model call), finds duplicate
|
|
49
|
+
lessons, tests proposed rules against examples with `intern guard --test`, and lists the commands only you
|
|
50
|
+
should run (`intern approve`, `approve-rule`, `reject`, `rm`). It has no Write or Edit tool and never runs
|
|
51
|
+
those commands; the guard would deny them anyway. The hooks call `intern` from `PATH`, or
|
|
52
|
+
`python3 -m intern_agent`, so install the package as well.
|
|
53
|
+
|
|
54
|
+
### Codex CLI
|
|
55
|
+
|
|
56
|
+
Codex runs hooks from `~/.codex/hooks.json` (or `[hooks]` in `config.toml`). Add:
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"hooks": {
|
|
61
|
+
"UserPromptSubmit": [{"hooks": [{"type": "command", "command": "intern hook user-prompt --agent codex", "timeout": 10}]}],
|
|
62
|
+
"PreToolUse": [{"hooks": [{"type": "command", "command": "intern hook pre-tool --agent codex", "timeout": 10}]}],
|
|
63
|
+
"Stop": [{"hooks": [{"type": "command", "command": "intern hook stop --agent codex", "timeout": 10}]}]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
then review and trust the hooks with `/hooks` in the Codex CLI. What works and what does not, compared with
|
|
69
|
+
Claude Code:
|
|
70
|
+
|
|
71
|
+
- Recall before prompts and tool calls, corrections, papercuts and distill work the same.
|
|
72
|
+
- The guard sees shell calls and `apply_patch` edits (each file in the patch is checked). Codex documents
|
|
73
|
+
no "ask" answer for a hook, so an ask becomes a deny that says why; run the command yourself if you meant
|
|
74
|
+
it. Hosted tools such as web search run no hook, and the Codex docs call tool hooks "a useful guardrail,
|
|
75
|
+
not a complete enforcement boundary".
|
|
76
|
+
- Nothing ties a Codex hook to its session file the way `CLAUDE_CODE_SESSION_ID` does for Claude Code, so a
|
|
77
|
+
correction captured in Codex is never verified: its lesson waits as untrusted until `intern approve`.
|
|
78
|
+
- Rejected tool calls and reverted files are not detected in Codex (they come from Claude Code's
|
|
79
|
+
transcript format). The Codex session file is read only for context, and its format is not a stable
|
|
80
|
+
interface: when it changes, the context gets thinner, nothing else breaks.
|
|
81
|
+
- If you prefer no hooks at all, write the rules into `AGENTS.md` as instructions:
|
|
82
|
+
`intern export --format agents --write AGENTS.md`. Instructions are not enforced; the agent may ignore them.
|
|
83
|
+
|
|
84
|
+
### Any agent
|
|
85
|
+
|
|
86
|
+
An agent with a hook or plugin system calls the same commands with `--agent generic`, which reads and
|
|
87
|
+
writes plain JSON:
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
# before a prompt: prints {"context": "..."} with the lessons that apply, or nothing
|
|
91
|
+
echo '{"session_id": "s1", "cwd": "/repo", "prompt": "no, use pnpm", "agent_action": "tools: Bash npm i"}' \
|
|
92
|
+
| intern hook user-prompt --agent generic
|
|
93
|
+
# before a tool call: prints {"decision": "deny"|"ask", "reason": "..."}, or {"context": "..."}, or nothing
|
|
94
|
+
echo '{"session_id": "s1", "cwd": "/repo", "tool_name": "Bash", "tool_input": {"command": "git push -f"}}' \
|
|
95
|
+
| intern hook pre-tool --agent generic
|
|
96
|
+
# at the end of a turn: starts distill in the background when events are waiting
|
|
97
|
+
echo '{"session_id": "s1", "cwd": "/repo"}' | intern hook stop --agent generic
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Name shell tools `Bash` with `tool_input.command`, and file edits `Edit` or `Write` with
|
|
101
|
+
`tool_input.file_path`, to get the guard's checks. Your hook must treat a decision as binding and a crash
|
|
102
|
+
or unreadable output as "stop": the guard fails closed only if its caller does. Events can also be
|
|
103
|
+
recorded directly with `intern capture --gate <gate>`, which reads one JSON object on stdin:
|
|
104
|
+
|
|
105
|
+
| Gate | Fields |
|
|
106
|
+
|---|---|
|
|
107
|
+
| `user-correction` | `prompt` (required), `cwd`, `tool`, `paths`, `agent_action`, `outside` |
|
|
108
|
+
| `papercut` | `target`, `kind`, `happened` (required); `tried`, `expected`, `fix`, `workaround` |
|
|
109
|
+
| `review-finding` | `finding` (required); `reviewer`, `file`, `line`, `severity`, `fix` |
|
|
110
|
+
| `deferred` | `item` (required); `reason`, `by` |
|
|
111
|
+
| `manual` | `note` or `title` (required); `context`, `did`, `instead`, `why`, `do`, `dont`, `tools`, `intents` |
|
|
112
|
+
|
|
113
|
+
Agents that read only instruction files get the rules and lessons as text:
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
intern export --format agents --write AGENTS.md # Codex, Cursor, and others that read AGENTS.md
|
|
117
|
+
intern export --format claude --write CLAUDE.md # Claude Code without the plugin
|
|
118
|
+
intern export --format cursor --write .cursor/rules/intern.mdc # Cursor project rule, alwaysApply: true
|
|
119
|
+
intern export --format agents --project --write AGENTS.md # only this repository's lessons
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The block sits between `<!-- intern:begin -->` and `<!-- intern:end -->`; running it again replaces only
|
|
123
|
+
that block.
|
|
124
|
+
|
|
125
|
+
## Security model and its limits
|
|
126
|
+
|
|
127
|
+
intern runs as the same OS user as the agent it watches, so on its own it cannot stop an agent that is set
|
|
128
|
+
on rewriting `~/.intern`. What it does:
|
|
129
|
+
|
|
130
|
+
- **Trust comes from people, not from the agent.** A lesson born in an agent session, from outside
|
|
131
|
+
content, or from a signal intern cannot verify is untrusted and never recalled. `approve`, `approve-rule`,
|
|
132
|
+
`reject`, `disable-rule`, `trust` and `rm` of a lesson with a rule ask you to type the id on `/dev/tty`,
|
|
133
|
+
and refuse when an agent variable is set. Untrusted lesson ids are also kept in `integrity.json`, so
|
|
134
|
+
deleting `untrusted: true` from a lesson file grants nothing.
|
|
135
|
+
- **A guard before every tool call**, fail-closed: built-in protection of intern's files, the agents'
|
|
136
|
+
transcripts, settings and plugin folders, and of the commands that grant trust; then your approved rules.
|
|
137
|
+
- **Integrity checks** on the rules and the trust list: a change made outside intern makes the guard ask.
|
|
138
|
+
- **The boundary is your agent's settings.** `intern doctor` checks Claude Code's permission deny rules and
|
|
139
|
+
sandbox for the files that carry trust, never writes them, and prints the JSON to add.
|
|
140
|
+
|
|
141
|
+
Known limits, in full in [docs/security.md](docs/security.md): the guard reads shell commands as text and
|
|
142
|
+
can be dodged by obfuscation (`int"ern"`, `cd .intern && ...`); an agent that clears its environment and
|
|
143
|
+
drives `intern approve` through a pseudo-terminal it controls can answer the confirmation itself (the guard
|
|
144
|
+
denies the obvious forms; the permission rules are what stop it); an agent with write access to
|
|
145
|
+
`integrity.json` and a rule file can change both consistently. Run `intern doctor` and add what it asks for.
|
|
146
|
+
|
|
147
|
+
## Commands
|
|
148
|
+
|
|
149
|
+
| Command | What it does |
|
|
150
|
+
|---|---|
|
|
151
|
+
| `intern add "<title>" [--did --instead --why --tool --path --intent --project]` | Write a lesson by hand |
|
|
152
|
+
| `intern list [--kind K] [--json]` | List lessons from the global and project stores |
|
|
153
|
+
| `intern show <id> [--json]` | Print one lesson |
|
|
154
|
+
| `intern rm <id> [--yes]` | Delete a lesson (asks on the terminal when it has a rule) |
|
|
155
|
+
| `intern capture --gate <gate> [--json]` | Record an event from stdin JSON |
|
|
156
|
+
| `intern distill [--since 7d] [--dry-run] [--json]` | Turn waiting events into lessons (an LLM call) |
|
|
157
|
+
| `intern recall [--tool-only] [--json]` | Lessons for stdin JSON `{prompt, cwd, tool, tool_input, files}` |
|
|
158
|
+
| `intern hook <user-prompt\|pre-tool\|stop> [--agent claude-code\|codex\|generic]` | Hook entry point |
|
|
159
|
+
| `intern trust [path]` | Recall this repository's `.intern/` lessons (you type the folder name) |
|
|
160
|
+
| `intern approve <id>` | Recall an untrusted lesson (you type the id) |
|
|
161
|
+
| `intern stats [--json]` | Event counts, distill outcomes, correction false positive rate |
|
|
162
|
+
| `intern promote <id> [--kind --tool --pattern --unless --decision --message --text]` | Propose a rule |
|
|
163
|
+
| `intern rules [--all] [--json]` | Proposed and active rules |
|
|
164
|
+
| `intern approve-rule <id>` / `reject <id>` / `disable-rule <id>` | Turn a rule on, down or off (you type the id) |
|
|
165
|
+
| `intern guard --test <rule> '<command or path>' [--tool T]` | Try a hook-check rule against an example |
|
|
166
|
+
| `intern retire [--dry-run]` / `restore <id>` | Archive lessons unbroken for 90 days / bring one back |
|
|
167
|
+
| `intern report [--since 30d] [--json\|--markdown]` | Exposures, violations, compliance, rule proposals |
|
|
168
|
+
| `intern doctor [--json]` | Check the settings that protect intern, and intern's own state |
|
|
169
|
+
| `intern import-review <file\|-> [--reviewer R] [--dry-run]` | Record `file:line \| severity \| finding \| fix` lines |
|
|
170
|
+
| `intern eval <id> [--cases N] [--budget-usd X] [--dry-run] [--yes]` | Blind replay with and without the lesson (paid) |
|
|
171
|
+
| `intern import --from-markdown <path> [--source S] [--direct] [--dry-run]` | Import lessons kept in markdown |
|
|
172
|
+
| `intern export [--agents-md \| --format agents\|claude\|cursor] [--project] [--write PATH]` | Rules and lessons as an instruction block |
|
|
173
|
+
|
|
174
|
+
## Where things live
|
|
175
|
+
|
|
176
|
+
| Path | What |
|
|
177
|
+
|---|---|
|
|
178
|
+
| `~/.intern/` (or `$INTERN_HOME`) | Global lessons (`lessons/`), events, rules, `config.toml`; folders are mode 0700 |
|
|
179
|
+
| `<repo>/.intern/` | One repository's lessons (`intern add --project`); recalled only after `intern trust` |
|
|
180
|
+
| `events.jsonl` | Append-only raw signals; secrets, e-mail, card and phone numbers masked before writing |
|
|
181
|
+
| `stats.jsonl` | Every count: distill decisions, exposures, violations, blocked calls |
|
|
182
|
+
| `rules/`, `rules.cache` | Rule files and the active hook-check rules the guard reads |
|
|
183
|
+
| `integrity.json`, `trusted_projects.json` | The record of what a person approved and trusted |
|
|
184
|
+
| `sessions/` | Per session: lessons shown, transcript scan state, files the agent changed (removed after 7 days) |
|
|
185
|
+
| `archive/`, `evals.jsonl`, `distill.log` | Retired lessons, eval results, the background distill log |
|
|
186
|
+
|
|
187
|
+
The lesson file format is in [docs/lessons-format.md](docs/lessons-format.md), the modules and data flow
|
|
188
|
+
in [docs/architecture.md](docs/architecture.md). Settings (`config.toml`, every key optional) are listed
|
|
189
|
+
in `intern_agent/config.py`; `INTERN_LLM_CMD` overrides the distill command, which by default runs
|
|
190
|
+
`claude -p` with no tools, MCP servers, skills or settings files.
|
|
191
|
+
|
|
192
|
+
## Roadmap
|
|
193
|
+
|
|
194
|
+
All four stages of the design are done: the store and CLI (0), capture, distill and recall for Claude Code
|
|
195
|
+
(1), counters, rules, guard and report (2), implicit signals, review findings, eval and import (3), and
|
|
196
|
+
Codex, generic and `AGENTS.md` agents (4). Ideas for later, not promises:
|
|
197
|
+
|
|
198
|
+
- Verified corrections for Codex, if Codex exposes a session id to hook processes.
|
|
199
|
+
- Rejected calls and reverts for Codex from its approval events.
|
|
200
|
+
- A `lint` and `test` rule kind that writes the check into the project, with approval.
|
|
201
|
+
- Lessons shared across a team through a reviewed, signed file instead of a cloned `.intern/`.
|
|
202
|
+
|
|
203
|
+
## Contributing
|
|
204
|
+
|
|
205
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). In short: standard library only, Python 3.9, tests with
|
|
206
|
+
`python3 -m unittest discover -s tests`, and every change that touches trust gets a test that tries to
|
|
207
|
+
get around it.
|
|
208
|
+
|
|
209
|
+
## License
|
|
210
|
+
|
|
211
|
+
MIT
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Agent adapters: the only code that knows a particular agent's hook format (spec K1).
|
|
2
|
+
|
|
3
|
+
The core (hooks.py, guard.py, capture.py, retrieve.py) works on one **canonical hook input**, a JSON
|
|
4
|
+
object with Claude Code's field names because that adapter came first:
|
|
5
|
+
|
|
6
|
+
{"session_id": str, "cwd": str, "prompt": str, # user-prompt
|
|
7
|
+
"tool_name": str, "tool_input": object, # pre-tool
|
|
8
|
+
"transcript_path": str | null, # read only by the claude-code adapter path
|
|
9
|
+
"agent_action": str, "outside": bool, "tool": str, "paths": [str]} # optional, from the adapter
|
|
10
|
+
|
|
11
|
+
and answers with canonical output: ``""`` for nothing, or Claude Code's ``hookSpecificOutput`` JSON
|
|
12
|
+
(``additionalContext`` for added context, ``permissionDecision`` ``ask``/``deny`` with a reason). Each
|
|
13
|
+
adapter has two pure functions:
|
|
14
|
+
|
|
15
|
+
- ``normalize(event, data) -> dict``: the agent's hook input to canonical input. It may read the agent's
|
|
16
|
+
own session file to fill ``agent_action``, ``outside``, ``tool`` and ``paths`` (what the agent did in the
|
|
17
|
+
turn the user is reacting to).
|
|
18
|
+
- ``render(event, out) -> str``: canonical output to what the agent's hook runner expects. An adapter
|
|
19
|
+
whose agent cannot "ask" turns ask into deny: a guard never fails open.
|
|
20
|
+
|
|
21
|
+
``intern hook <event> --agent claude-code|codex|generic`` picks one; claude-code is the default and its
|
|
22
|
+
adapter changes nothing, so existing installs behave exactly as before.
|
|
23
|
+
"""
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
from types import ModuleType
|
|
27
|
+
|
|
28
|
+
AGENTS = ("claude-code", "codex", "generic")
|
|
29
|
+
DEFAULT = "claude-code"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def get(name: str) -> ModuleType:
|
|
33
|
+
if name == "claude-code":
|
|
34
|
+
from . import claude_code as module
|
|
35
|
+
elif name == "codex":
|
|
36
|
+
from . import codex as module
|
|
37
|
+
elif name == "generic":
|
|
38
|
+
from . import generic as module
|
|
39
|
+
else:
|
|
40
|
+
raise ValueError(f"unknown agent {name!r}; use one of {', '.join(AGENTS)}")
|
|
41
|
+
return module
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Claude Code: the canonical format is Claude Code's own, so input and output pass through unchanged.
|
|
2
|
+
|
|
3
|
+
What is Claude Code specific beyond the field names stays where it was and is used only on this path:
|
|
4
|
+
transcript.py reads ``~/.claude/projects/<cwd slug>/<session>.jsonl`` (the turn before a correction, the
|
|
5
|
+
human message that verifies it), implicit.py reads rejections, repeated failures and file edits from it
|
|
6
|
+
at Stop, and both trust a transcript only when ``CLAUDE_CODE_SESSION_ID`` (set by Claude Code in hook
|
|
7
|
+
processes) matches the hook's ``session_id``.
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from typing import Any, Dict
|
|
12
|
+
|
|
13
|
+
NAME = "claude-code"
|
|
14
|
+
READS_TRANSCRIPT = True
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def normalize(event: str, data: Dict[str, Any]) -> Dict[str, Any]:
|
|
18
|
+
return data
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def render(event: str, out: str) -> str:
|
|
22
|
+
return out
|