Repository navigation
feat(hooks): browse, edit and remove unmanaged hooks in the import dialog - #920
Conversation
…alog The import dialog listed every target's hooks in one long scroll of full commands, so it was hard to read and hard to tell which target a row belonged to. It also offered no way to change a hook without first handing it to skillshare. The dialog now shows one target at a time from a rail, with two-line rows that open to the full commands. A hook that lives as an event in a target's settings file can be edited or removed in place: the change stays pending, a review step shows the file diff, and only then is the file written, with a backup that restores it. The hook stays unmanaged. The write is a new operation in internal/hooks (PreviewNativeEdits and ApplyNativeEdits) that addresses elements by content, refuses anything a ledger record holds, and reuses the existing backup and journal path. Whole-file hooks, Copilot files and Antigravity blocks still have to be imported first.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9f1818ad49
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if op.Key == "" { | ||
| // An unmanaged hook has no entry to name and no ownership to restore. | ||
| if !strings.Contains(", "+change.Name+", ", ", "+op.Event+", ") { | ||
| change.Name = strings.TrimPrefix(change.Name+", "+op.Event, ", ") | ||
| } |
There was a problem hiding this comment.
Prevent repeated restores from duplicating removed native hooks
After removing an unmanaged hook in the import dialog, restoring its backup twice from Backups appends two copies of the original hook. Native removal operations have an empty ownership key, so sameRecord("", nil) always succeeds, and the removal-restore branch unconditionally appends op.Before. This new branch leaves no state that would invalidate another restore of the same backup. Consequently, repeated restores silently multiply hook executions instead of reporting that the removal has already been undone. Check the restored content or otherwise track restoration before accepting another append.
AGENTS.md reference: AGENTS.md:L36-L36
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 7b64a2c. A removal of an unmanaged hook has no ledger record, so nothing marked the backup as restored. PreviewRestore now reports a conflict when the removed hook is already in the file, so a second restore is blocked instead of appending. The other two kinds of op were already safe: restoring an update or an added element looks for the written value, which is gone after the first restore. Covered by TestNativeEdit_RestoringARemovalTwiceIsRefused.
| const changeOf = (row: ImportRow): NativeChange | undefined => { | ||
| const change = changes[row.id]; | ||
| return change && ('remove' in change || !sameEvents(change.events, rowEvents(row))) ? change : undefined; | ||
| }; | ||
| // A hook with a pending edit or removal is written to its target file as it is, not imported in the same pass. | ||
| const checked = (row: ImportRow) => importable(row) && !changeOf(row) && !unchecked.includes(row.id); |
There was a problem hiding this comment.
Reconcile completed native edits across event-based rows
If native changes succeed but a subsequent import fails, retry reconciliation breaks when an edit changes the event layout. For example, add a SessionEnd command to a Stop hook using the editor: after refetch, Import returns separate Stop and SessionEnd candidates, so the Stop row never equals the saved two-event change and retrying appends SessionEnd again. Moving Stop entirely to SessionEnd instead creates a new row ID that is automatically selected for import, despite the user's choice to leave it unmanaged. Both changeOf and the unchecked-ID recovery need to reconcile completed edits across the resulting event candidates, rather than assuming candidate identity and event grouping stay unchanged.
AGENTS.md reference: AGENTS.md:L36-L36
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 7b64a2c. The dialog no longer matches completed edits back to rows. Once the native write goes through, or fails after reporting files it already applied, every pending change is dropped, so none is sent again. For the targets that were written, only the rows picked before stay picked, so a row produced by the edit (a command moved or added under another event) is not imported by default. The rendered test for a failed import after a successful write now reads back a moved command as a new row.
Two ways an unmanaged hook could end up in a target file twice: Restoring the backup of a removal a second time appended the hook again. An unmanaged hook has no ledger record, so nothing marked the backup as restored. PreviewRestore now reports a conflict when the removed hook is already in the file. When the dialog's native write succeeded and a later import failed, the retry compared each pending change with the row it was made in. An edit that moves or adds a command under another event comes back as other rows, so the change stayed pending and was written again, and the new row was picked for import. The dialog now drops every change once the write went through (or reports files it already applied), and keeps only the rows picked before as imports for the targets it wrote.
|
@codex review |
Keep the next release on the patch version the maintainer asked for, instead of the 0.31.0 that Release Please derives from the feat commit. Release-As: 0.30.9
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7b64a2cd0f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const frozen = Object.fromEntries([...new Set(changed.map((r) => r.target))].map((target) => [target, chosen.filter((r) => r.target === target).map((r) => r.id)])); | ||
| setKept((prev) => ({ ...prev, ...frozen })); | ||
| setChanges({}); |
There was a problem hiding this comment.
Preserve pending edits for files a partial write did not reach
When edits span multiple targets and a later file fails to write, the API reports “already applied” for only the successful files, but this branch clears every pending edit. For example, if Claude writes successfully and Gemini's directory is not writable, the Gemini edit or removal disappears even though its file is unchanged. Retrying then offers no way to apply that discarded change without recreating it. Clear only changes belonging to successfully applied files, preserving drafts for the remaining targets.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 554460c. A partial failure now lists the files it wrote in error_params.applied, and the dialog drops only the changes of those files. Changes for a file the write did not reach stay pending and go into the next review. Covered by TestWriteHooksFailure_ListsAppliedFiles and a rendered two-target test in HookDialog.test.tsx.
| if _, back := unowned(op.Event, op.Before); back { | ||
| conflict("the hook is already in the file; this backup may have been restored before") | ||
| break |
There was a problem hiding this comment.
Account for surviving duplicates before refusing restoration
When an event contains two identical unmanaged registrations and the editor removes only one, the surviving registration makes this check reject the backup's first restore as already restored. This state is reachable entirely through the dashboard: add an identical command card, apply, then reopen the editor and remove one copy. The removal records only the deleted element, so finding matching content does not establish that it was restored. Compare the expected multiplicity or track restoration explicitly so a legitimate backup can restore the original registrations.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 554460c. Each change to an unmanaged hook now records how many hooks with the same content the write left in the event (twins), and a restore is refused only when the file holds more than that. So removing one of two identical hooks restores once and is refused the second time. This also corrects my earlier reply: restoring an update was not safe. Removing the first of two hooks is stored as an update plus a removal and could be restored twice; the same count now covers updates. Tests: TestNativeEdit_RestoresARemovedTwinOnce, TestNativeEdit_RestoringAShiftedRemovalTwiceIsRefused, TestNativeEdit_RestoringARemovalAfterImportingTheHookIsRefused.
…n edits The check that refuses a second restore of a removed unmanaged hook looked for any unmanaged hook with the same content. When one of two identical hooks was removed, the survivor made the first restore look done. A removal that shifts later hooks is stored as an update plus a removal, which the check did not cover, and a restored hook that was imported afterwards no longer counted, so those backups could still restore twice. Every change to an unmanaged hook now records how many identical hooks the write left, and a restore is refused only when the file holds more than that. When a native write failed after its first file, the dialog dropped every pending change, including those of files the write never reached. The failure response now lists the applied files in error_params, and the dialog drops only the changes of those files. Pasted candidates are no longer unpicked by a write to the target they were pasted for.
|
@codex review |
An open row in the import dialog showed the pencil and trash icons next to the labelled Edit and Remove buttons below, which do the same thing. The icons now hide while the row is open; their space is kept so the chevron stays where it was clicked.
Keep the next release on the patch version the maintainer asked for, instead of the 0.31.0 that Release Please derives from the feat commit. Release-As: 0.30.9
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 554460c45c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if copies > op.Twins { | ||
| conflict("the hook is already in the file; this backup may have been restored before") | ||
| break |
There was a problem hiding this comment.
Populate twin counts for restore-generated backups
In the dashboard, start with unmanaged registrations A and B in one event, edit A to B, then restore that edit's backup. The file correctly returns to A/B, but restoring the new backup created by that restore is incorrectly blocked as already restored. PreviewRestore constructs the inverse update with Before=B and the default Twins=0, and applyScoped saves it unchanged; this check therefore rejects the surviving B. Only PreviewNativeEdits currently calculates twin counts. Calculate them for restore-generated operations too, preferably in the shared backup-writing path, so users can undo a restore through Backups.
AGENTS.md reference: AGENTS.md:L36-L36
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b174c07. The twin count is now computed where every backup is written (applyScoped), so the backup a restore writes carries it too and can be restored in turn. Covered by TestNativeEdit_RestoreCanBeUndoneWhenATwinSurvives.
…dits Only the native edit preview recorded how many identical hooks a write left, so the backup a restore writes had no count. Undoing a restore through Backups was then refused whenever a hook with the same content was still in the file. The count now happens where every backup is written.
The labelled Edit and Remove buttons under an open row repeated the icons and stood out too much, so they are gone and the icons stay visible on open rows again. Each icon now has a tooltip that says what it does.
Keep the next release on the patch version the maintainer asked for, instead of the 0.31.0 that Release Please derives from the feat commit. Release-As: 0.30.9
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…and fills The dialog mixed a grey rail, a grey footer, grey expanded rows and a divider around every region, and the editor stacked its own Cancel and Done above the dialog's. It read as cluttered, and a long JSON line pushed the editor's controls out of the dialog. The dialog now sits on the page background with the hook list, or the editor, as one card. Rows are separated only by the list separator, the row icons are neutral until hovered, and code is the only sunken fill. One row is open at a time, and a single command no longer repeats its event as a heading. While a hook is edited, the dialog's footer holds the editor's actions, so there is one row of buttons and Cancel returns to the list instead of closing the dialog with the draft. Commands are sections of the card and wrap instead of scrolling sideways. The dialog is larger. The hint is one line, the edit note moved to the footer, and the name field is labelled by where the name is used.
Keep the next release on the patch version the maintainer asked for, instead of the 0.31.0 that Release Please derives from the feat commit. Release-As: 0.30.9
The review step still had the white body, the grey footer and the bordered summary box, so it looked like a different dialog from the list it follows. It now sits on the page background with the summary as one card, and the removal tile is neutral with only its icon in the danger colour.
Keep the next release on the patch version the maintainer asked for, instead of the 0.31.0 that Release Please derives from the feat commit. Release-As: 0.30.9
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Type
proposals/only — see CONTRIBUTING.md)approvedlabel) — requested by the maintainer directly; there is no issueLinked Issue
None. The maintainer asked for this redesign from a screenshot of the current dialog.
What changes
The dashboard's Import hooks dialog listed every target's hooks in one long scroll of full commands. It was hard to read, hard to tell which target a row belonged to, and a hook could not be changed without importing it first.
pending. A review step lists what will be imported, edited and removed, and shows the file diff. The file is backed up before it is written, and the hook stays unmanaged.Editing in place works for Claude, Codex, Gemini, Cursor, Qwen, and Droid's
hooks.json. Whole-file hooks (Pi, OMP, Amp, OpenCode), Copilot files, Antigravity blocks and pasted content still have to be imported first.Screenshots
Browse: one target at a time, a row opened to its full commands.
Edit: one section per command; the second command after Format.
Pending: an edited hook and a removed hook, not written yet.
Review: what will happen, and the file diff, before anything is written.
How it works
internal/hooks/native_edit.goaddsPreviewNativeEditsandApplyNativeEdits. An edit names a hook by its content as read, and gives what replaces it. The source and the ledger are not touched.applyScopedpath: revision check, backup record, journal, atomic write.PreviewRestorenow restores such a backup by finding the element by content.POST /api/hooks/nativeandPOST /api/hooks/native/previewsit behind the same local-origin guard as the other hooks routes. Apply writes ahooks edit-nativeoplog entry.Checks run
make checkin the devcontainer: passed.pnpm run test(950 tests),pnpm run build,pnpm run lint(0 errors): passed.python3 scripts/ai-context.py check: passed.ai_docs/testsE2E runbooks.Not covered
codex-2and a write that fails part-way through several files have no test.main.Checklist
make check) — for code changes