Repository navigation
Coding agents: Cursor's StrReplace, ApplyPatch and EditNotebook are decided as the edits they are - #767
Merged
Conversation
…ecided as the edits they are Cursor 3.29.15 names its edit tools StrReplace, Write, Delete, EditNotebook and ApplyPatch (an older prompt: search_replace, write, delete_file, edit_notebook), as Purv-Kabaria found in #755. The Cursor mapping had none of the edit names, so a payload naming them was decided as an unknown tool, a flag: a StrReplace of ~/.cursor/hooks.json ran where a Write of it is held (TK-F009), and one of .env where an Edit of it is denied (TK-D005). StrReplace and search_replace map to Edit, write to Write, delete_file to Edit (as Delete), EditNotebook and edit_notebook to NotebookEdit on their target_notebook. ApplyPatch maps to Edit on every file a patch header names, in any argument, as Cursor reads it (a JSON {"patch": ...} unwrapped, each line trimmed as JavaScript trims). TK-F009 now covers NotebookEdit, the only file-write rule without it. Evals: the packs' new policy hash (no result changed). Cursor's own preToolUse hook (read in 3.26.13 and 3.29.15) sends an edit by any of these tools as a Read and then a Write of the whole file, which was already held; docs/limits.md says so and lists the names it sends that stay unmapped. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
…inear trim; TK-F016 reads NotebookEdit From the review of #767: - A Cursor edit Tracekit can't read a file from (an ApplyPatch with no file header, an empty or non-string patch, a StrReplace, search_replace, write, delete_file, EditNotebook or edit_notebook without a string in the argument its tool reads its file from) was mapped to an Edit of no file and allowed. It now keeps its own name, an unknown tool, decided exactly as on main. - ApplyPatch reads \r and \r\n as line ends, as Cursor does: a CR-only patch of ~/.cursor/hooks.json was decided on no file. It is held. - JavaScript's trim() is str.strip over JavaScript's whitespace (JS_SPACE), not a regex that took 4.65 s on a line of 40,000 spaces; OpenCode's and Cline's patch and here-doc readers used the same regex. JSON is tried only on text starting with {. - TK-F016 also reads NotebookEdit, as TK-F009 now does. Coding pack 2026.11-v2-83 (v2-82 is #761's); eval results get the new policy hashes, no result changed. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
…ine's readers in the timing test
An ApplyPatch argument that starts with { and that Python's json module
can't read (nesting past its recursion limit, an integer past its digit
limit) now leaves the whole patch unread: the call keeps its own name, an
unknown tool, decided as on main, whatever headers its other arguments hold.
The CPU-time test also runs Cline's apply_patch and run_commands here-doc
readers, on a line with a run of spaces inside it.
Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
This was referenced Nov 12, 2026
…t of a patch or notebook edit is decided From the review of #767: - An ApplyPatch argument starting with { that isn't JSON (json.JSONDecodeError) no longer leaves the patch unread: Cursor's JSON.parse fails on it too and Cursor reads the text as the patch, so Tracekit does as well. A patch with a "{" note beside it, or a first line of "{", is decided on its files. - ApplyPatch and EditNotebook decide every path argument the input names (file_path, path, target_file, filePath, target_notebook, paths) beside the file the tool reads, as Cursor's other tools already did. - The unknown-tool test decides at runtime which JSON this Python reads: 3.12 and later read nesting 5,000 deep, and the patch is then held as an Edit of the hooks file. - docs/coding-agents.md says so. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
Member
Author
|
This lands in #799 (a merge train of the policy PRs), which renumbers rule ids and re-records the evals once; your commits stay as they are and this PR will show as merged. |
kausthubhk
pushed a commit
to kausthubhk/Tracekit
that referenced
this pull request
Nov 14, 2026
Carries Cygnux-Labs#731 onto main (5d88184): Cygnux-Labs#732 took v2-81 and the open Cygnux-Labs#761 and Cygnux-Labs#767 claim the next numbers, so this takes v2-84; the final number is settled at merge. E17 is 853/853 with 1 false alarm in 901; E21's held-out pool is 259/420 on default and 286/420 on strict, and strict holds 47 of E17's 901 benign calls. The blind pools don't move. The held-out table in docs/evaluation.md quotes the new rows; the machine, engine-version and latency fields stay main's. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
kausthubhk
pushed a commit
to kausthubhk/Tracekit
that referenced
this pull request
Nov 14, 2026
Cygnux-Labs#761 also took v2-82, and the open Cygnux-Labs#767 and Cygnux-Labs#731 claim the next numbers, so this takes v2-85; the final number is settled at merge. Only the policy hashes move: E17 is 846/846 with 1 false alarm in 904, E21's held-out pool is 255/420 on default and 285/420 on strict, and amandeavor's blind pool is 37 and 40 of 45. The machine, engine-version and latency fields stay main's. Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Purv-Kabaria found, in #755, the names Cursor 3.29.15 gives its edit tools:
StrReplace(path,old_string,new_string,replace_all),Write(path,contents),Delete(path),EditNotebookandApplyPatch(Codexmodels only), and in an older prompt version
search_replace,write,delete_fileandedit_notebook.Tracekit's Cursor mapping (
CURSOR_TOOLS) had none of the edit names. A payload that named them was decided as anunknown tool, which the dev and coding packs only flag. So a
StrReplaceof~/.cursor/hooks.jsonwas allowed wherea
Writeof it is held (TK-F009), and aStrReplaceof.envwas allowed where anEditof it is denied(
TK-D005), on the v1 and the v2 hook.What Cursor's own
preToolUsehook sends, read from the code of Cursor 3.26.13 (installed) and 3.29.15 (currentstable, downloaded from cursor.com): Cursor fires the hook where a call runs, not with the model's tool name. An edit
by
StrReplace,ApplyPatchorEditNotebookreaches the hook as aReadof the file and then aWritewithfile_pathand the whole newcontent, both under the model's call id; a delete asDeletewithfile_path. Cursoralso translates a Claude Code hook's
Editmatcher to itsWrite. So the live hook already held these edits asWrites. The model's names reach Tracekit where a payload carries them: Cursor's transcripts, whichtracekit auditreplays through this mapping (#755), and any Cursor build that sends them.
Changes
StrReplaceandsearch_replace→Edit;write→Write;delete_file→Edit, asDeleteis;EditNotebookandedit_notebook→NotebookEdit, decided ontarget_notebook(now inCURSOR_PATH_ARGS). Eachis mapped only when the argument its tool reads its file from (
path,file_path,file_path,target_file,target_notebook, from Cursor 3.29.15's schemas) holds a string; otherwise the name passes through unmapped, anunknown tool, exactly as on main. Cursor refuses such a call.
ApplyPatch→Edit, withpathsset to every file a patch header names, in whichever argument holds it, asFactory Droid's is read. It is read the way Cursor reads it: a JSON
{"patch": ...}is unwrapped (tried only when thetrimmed text starts with
{; text that isn't JSON is read as the patch it is),\rand\r\nare read as\n,and each line is trimmed as JavaScript trims it. A path argument sent beside the patch (
path,file_path,paths, …) doesn't replace its files and is decided with them, as is one beside anEditNotebook'starget_notebook. A patch Tracekit can't read, such as one with no file header (none, empty,{},{"patch": 5}),passes through unmapped and is decided as an unknown tool, as on main.
TK-F009(an agent's edit of its harness's settings, held) andTK-F016(ANTHROPIC_BASE_URLin a call'sarguments, flagged) now also cover
NotebookEdit. They were the two file-write rules in the packs without it, so anEditNotebookof~/.cursor/hooks.jsonwould still have run. The coding pack's version is2026.11-v2-83:v2-82is taken by Coding agents: hooks for CodeBuddy Code (#757) #761, which is still open.strict.yamlitself is unchanged; it gets the change throughextends, as with earlier coding-pack changes. The eval results get the packs' new policy hashes; no result changed.trim()is nowstr.stripover JavaScript's whitespace set (JS_SPACE) instead of a regex that tookquadratic time on a long run of spaces (4.65 s for 40,000). That regex was used for OpenCode's and Cline's patches and
Cline's here-docs too, so all of them now use
JS_SPACE. Python's\salso stripped\x1c-\x1fand\x85,which JavaScript keeps.
docs/coding-agents.md; adocs/limits.mdrow on what Cursor's hook sends and the namesit sends that stay unmapped (
Fetch,List,ReadLints,WriteShellStdin, which carries the typed text's lengthbut not the text,
FetchMcpResource, …);NotebookEditin theTK-F009andTK-F016rows.How I ran it as a user
tracekit init --dev --v2 --agent cursorin a temporaryHOME, then thepreToolUseandpostToolUsecommands itwrote, run through a shell as Cursor runs them, with Cursor 3.29.15's payload shapes:
The dev signer that run started loaded the packs from the main checkout, so
EditNotebookof the hooks file wentthrough there (
NotebookEditwasn't inTK-F009yet);test_cursor_edit_tools_are_decided_as_the_edits_they_arein
tests/test_harness_hooks_v2.pyruns the same payloads through a signer with this branch's packs, where it is held.Tests
Each fails on main:
tests/test_signer_policy.pyCodingPack.test_cursor_edit_tools_are_decided_as_the_edits_they_are: every Cursorname, on
~/.cursor/hooks.json,.envand a project file, is decided as its Claude Code form (same verdict andrule ids) on the dev, coding, server and strict packs, on both regex engines; the hooks file is held as a
Writeofit is (
TK-F009),.envdenied (TK-D005), the project file neverTK-UNKNOWN-TOOL.tests/test_harness_hooks_v2.pyOnTheDevPolicy.test_cursor_edit_tools_are_decided_as_the_edits_they_are: the v2hook against a real signer, starting with the Read-then-Write Cursor sends; the signed decisions name
Edit,WriteandNotebookEdit.tests/test_agent_hooks.py:Harnesses.test_cursor_edit_tools_are_decided_as_edits(the v1 hook against a realdaemon) and
CursorTools.test_each_is_decided_on_the_file_its_tool_reads(v1 and v2 policy, with decoy path keys).Added after the first review, each failing on the first head (dc03b4d):
.envis denied: in the every-pack test,the v2 hook test and the v1 policy test.
CodingPack.test_a_cursor_edit_naming_no_file_stays_an_unknown_tool: on each pack and engine, a header-less, empty,{},{"patch": 5}or blank-header patch, and aStrReplace,search_replace,write,delete_file,EditNotebookoredit_notebookwithout a string in its file argument, keeps its own name, getsTK-UNKNOWN-TOOL,and is never allowed. The v2 hook test checks the signed decision says the same, and
CursorTools.test_one_naming_no_file_is_left_to_the_v1_policy_as_beforechecks the v1 side.CodingPack.test_a_notebook_edit_naming_the_model_endpoint_is_flagged:TK-F016flags aNotebookEdit, and aCursor
EditNotebook, that setsANTHROPIC_BASE_URL.CursorTools.test_a_long_run_of_spaces_takes_linear_time: a Cursor patch, an OpenCode patch, a Cline patch and aCline here-doc, each with a run of 40,000 spaces inside a line, take under 1 s of CPU time together
(
time.process_time); the removed regex took about 4 s on one such line.The reviewer's probes on this head: every unreadable shape decides exactly as on main on all four packs, v1 included;
each CR-only shape is held through the real v2 hook and signer.
Added after the second review, each failing on 85d6fd9:
"{"argument beside it, and a patch whose first line is{, are decided ontheir files (held on the hooks file, denied on
.env) instead of as unknown tools.CodingPack.test_every_path_argument_of_a_cursor_edit_is_decided: anEditNotebook,edit_notebookorApplyPatchwith/w/.envin another path argument (file_path,path,target_file,paths) is denied(
TK-D005) on each pack and engine.test_a_cursor_edit_naming_no_file_stays_an_unknown_tooldecides at run time which JSON this Python'sjsonmodule reads: Python 3.12 and later read nesting 5,000 deep, where 3.11 doesn't, and a patch it reads is held as an
edit of the hooks file. On 85d6fd9 it failed on 3.13 (8 subtests), and 3.12's
jsonreads the same input.The gate in the worktree (
make test-ts lint build test) on this head, on two Pythons. 3.11: TypeScript 162 tests, 152 passed, 10 skipped, 0 failed; pyflakes clean; the wheel and sdist built and passedtwine check; pytest 5001 passed, 394 skipped, 10 xfailed, 64875 subtests passed. 3.13 (a stdlib venv, as CI makes): TypeScript the same; pyflakes clean; build andtwine checkpassed; pytest 5111 passed, 284 skipped, 10 xfailed, 64945 subtests passed. The branch merged main up to #736; it doesn't take main's later commits, so that the merge train with the other policy PRs settles the pack version and the eval policy hashes once.Checklist
make checkpasses (lint, tests, build);make test-tstoo ifsdk/typescript/changedCHANGELOG.md)docs/threat-model-laptop.md,docs/threat-model-server.md)git commit -s, seeCONTRIBUTING.md)Security invariants
approval identity) is newly trusted by the signer or verifier
Evidence format
core.sig_message,ledger.make_record, the v1 schema, howthe verifier treats existing bundles) or the published v2 format
docs/sample/andtests/fixtures/) still verify, and the change is called out above