Skip to content

feat(hooks): browse, edit and remove unmanaged hooks in the import dialog - #920

Merged
runkids merged 13 commits into
mainfrom
runkids/hooks-import-manage
Nov 16, 2026
Merged

runkids merged 13 commits into
mainfrom
runkids/hooks-import-manage

Conversation

@runkids

@runkids runkids commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Type

  • Bug fix
  • Small improvement (docs, typo, minor refactor)
  • Feature proposal (proposals/ only — see CONTRIBUTING.md)
  • Approved feature or large change (the linked issue has the approved label) — requested by the maintainer directly; there is no issue

Linked 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.

  • One target at a time. A rail lists the targets with "checked / total". The header of the list always names the target and its file.
  • Two-line rows. Each row shows the event, tool filter, command count and the script it runs. Opening a row shows the full commands and the name it gets in skillshare. One row is open at a time.
  • Edit or remove without importing. A hook that is an event in a target's settings file gets a pencil and a trash button. The editor has one section per command, with a multi-line command editor, a Format button and variable chips.
  • Nothing is written until reviewed. Edits and removals stay 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.

Import dialog listing Claude's unmanaged hooks, with one row expanded

Edit: one section per command; the second command after Format.

Editor for an unmanaged hook with a formatted multi-line command

Pending: an edited hook and a removed hook, not written yet.

Rows marked pending with Undo, and a footer offering Review changes

Review: what will happen, and the file diff, before anything is written.

Review step with import, edit and remove summaries and the settings.json diff

How it works

  • internal/hooks/native_edit.go adds PreviewNativeEdits and ApplyNativeEdits. An edit names a hook by its content as read, and gives what replaces it. The source and the ledger are not touched.
  • Content that a ledger record holds is refused, both as the hook to change and as the value to write, so a managed hook never gets an indistinguishable copy.
  • The write goes through the existing applyScoped path: revision check, backup record, journal, atomic write. PreviewRestore now restores such a backup by finding the element by content.
  • POST /api/hooks/native and POST /api/hooks/native/preview sit behind the same local-origin guard as the other hooks routes. Apply writes a hooks edit-native oplog entry.
  • On apply, the dialog writes the target files first and then imports. If anything fails after a write, it reads the targets again, so a retry sends only what is still pending.
  • Format only changes line breaks and indentation. It returns the command unchanged when it meets syntax it does not model exactly (heredocs, backticks, comments, expansions inside double quotes, escaped whitespace, case fall-through).

Checks run

  • make check in the devcontainer: passed.
  • UI: pnpm run test (950 tests), pnpm run build, pnpm run lint (0 errors): passed.
  • python3 scripts/ai-context.py check: passed.
  • By hand in the dashboard: edit, format, remove, review, apply, then restore the backup from the Backups dialog.
  • Not run: the website build, and the ai_docs/tests E2E runbooks.

Not covered

  • There is no CLI command for editing an unmanaged hook; this is dashboard only.
  • Account targets such as codex-2 and a write that fails part-way through several files have no test.
  • Removing an unmanaged hook does not update the stored index of a managed hook later in the same event. The managed hook is still found by content (tested). What a later hand-edit plus take-over does in that state was not compared with main.
  • A row with a pending edit cannot be imported in the same pass.

Checklist

  • I've read CONTRIBUTING.md, including its AI-assisted contributions section
  • I've reviewed every line of the diff and can explain it — AI-assisted change; the maintainer's read-through is still to come
  • Tests included and passing (make check) — for code changes
  • No unrelated changes in the diff
  • Scope is focused — one concern per PR

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T14:50:04.240207Z 4474cae Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread internal/hooks/apply.go
Comment on lines +1027 to +1031
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, ", ")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +100 to +105
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@runkids

runkids commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

@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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +172 to +174
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({});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/hooks/apply.go Outdated
Comment on lines +1014 to +1016
if _, back := unowned(op.Event, op.Before); back {
conflict("the hook is already in the file; this backup may have been restored before")
break

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@runkids

runkids commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

@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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread internal/hooks/apply.go
Comment on lines +1019 to +1021
if copies > op.Twins {
conflict("the hook is already in the file; this backup may have been restored before")
break

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@runkids

runkids commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 98a297216d

ℹ️ 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".

…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
@runkids

runkids commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 4474caeaa7

ℹ️ 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".

@runkids
runkids merged commit 0dc2018 into main Nov 16, 2026
9 checks passed
@runkids
runkids deleted the runkids/hooks-import-manage branch November 16, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant