Repository navigation
feat(hooks): a PreToolUse hook denies uno_app_restart while Hot Reload applied every edit since the last start - #203
vatsashah45 wants to merge 6 commits into
Conversation
With the DevServer CLI present but no app connected yet, `hot-reload-status` answers without a verdict (exit code 0), and the hook fell through to its reminder on every scaffolding edit: 14 to 20 notes a session before the first `uno_app_start`, 4.5k to 8.4k persistent tokens of hook text, and an agent that learned to skim the hook's notes. Now a no-verdict answer prints nothing; the reminder stays for a machine without the CLI. `Test-Hooks.ps1` covers the case. Validated on three catalog sessions (unoplatform/private#1220): zero notes before the first start, hook text in context down to 3.2k–5.3k tokens. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…d applied every edit since the last start Nine catalog sessions restarted 6 to 13 times each right after the hook had said `applied`, a third of their launches, and two A/Bs of the skill text (unoplatform/private#1217, #1220) moved that by nothing: the restart is decided from what the agent believes about Hot Reload. So the hook decides. `hot-reload-edit.sh` records each verdict for the session, and any edit to a file that runs at startup (App.xaml.cs, Program.cs, project, props, appsettings, manifest). `app-restart-guard.sh pre` denies `uno_app_restart` while the last verdict is applied, no changes or superseded and no such file changed, with the reason and the way out (assert; or `uno_app_close` then `uno_app_start` for other arguments, data or platform); a pending verdict is denied until the status tool answers; a RudeEdit, InternalError, compile failure, ignored edit, a startup-file edit, no CLI, or no edit since the last start lets it through. `app-restart-guard.sh post` clears the state on a start or restart. State lives in $TMPDIR/uno-studio-hooks/<session_id>.state. Test-Hooks.ps1 covers the guard; the README's hooks row says what it does. Co-Authored-By: Claude Fable 5.1 <[email protected]>
record() reused the `startup` variable that the applied message appends for an App.xaml.cs edit, so every applied note ended in "uno_app_start.0" and the startup sentence never appeared (catalog-20261020-213956, all three sessions). The test now checks the end of the applied note and the App.xaml.cs sentence, and clears the guard state before its cases. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Validation: three catalog sessions on this branch at
|
…a denied restart does not become close+start In catalog-20261020-213956 every denied restart turned into uno_app_close then uno_app_start, the path the deny reason leaves open. The guard now denies the close once, with the reason, when every edit since the last start was applied and none touched startup code; the same call again goes through, so a real close costs one extra call and nothing dead-ends. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Follow-up to the validation above, in 1c6aacb: a |
…nce, so a denied restart does not become close+start" This reverts commit 1c6aacb.
Only an edit refreshes the recorded verdict, so a pending one went stale after the status tool had answered Ready (catalog-20261021-103500 A2, on Android: two denials and a failed restart before the agent rewrote its code). The guard now denies a pending restart once per edit and says so; the same call again goes through. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Second run, on
Net on the branch: the restart guard, the pending-once fix and the applied-note fix. The relaunch habit that remains is close + start with the same arguments; a window-size argument on |
Stacked on #202 (merge that first; this diff shows only its own commit once #202 is in). The enforcement #201 could not be: a hook that denies the restart instead of a sentence that asks the agent not to.
Why a hook
Nine catalog sessions on this plugin restarted the app 6 to 13 times each right after the Hot Reload hook had said
applied, a third of all their launches, for reasons like "constructor changes need a fresh model instance" or "restarting cleanly". Two A/Bs of theuno-testingtext (unoplatform/private#1217 ondev/steve/uno-testing-loop, unoplatform/private#1220 on #201's branch) moved that by nothing: the restart is decided from what the agent believes about Hot Reload, and the skill is loaded in about half the sessions anyway. APreToolUsehook is read every time.What it does
hot-reload-edit.shnow records, per session ($TMPDIR/uno-studio-hooks/<session_id>.state), the last verdict it got from the DevServer and whether any edit since the last start touched a file that runs at startup:App.xaml.cs,Program.cs,.csproj,.props,.targets, solution,global.json,appsettings*.json, manifests,.plist. Those edits are recorded for every file type, not only.xaml/.cs.app-restart-guard.sh pre(PreToolUseonmcp__.*__uno_execute_tool) deniesuno_app_restartwhile the last verdict isapplied,no changesorsupersededand no startup file changed. The reason says why and what to do: re-enter the state under test and assert; a restart is allowed after RudeEdit, InternalError, a compile failure or a startup-file edit;uno_app_closethenuno_app_startfor other arguments, data or platform. Apendingverdict is denied untiluno_app_hot_reload_statusanswers. Everything else goes through: no edit since the last start, an ignored edit, no CLI on the machine.app-restart-guard.sh post(PostToolUseon the same tool) clears the state onuno_app_startoruno_app_restart.uno_app_restartis guarded.uno_app_close+uno_app_startis the legitimate way to relaunch with other arguments or data, so it stays open; if the sessions move to that pair to get around the guard, the next step is to denyuno_app_closeunder the same condition unless the following start changes arguments or target.Test-Hooks.ps1runs the pair through the sequence (applied → denied; restart → cleared; rude edit, project file,App.xaml.cs, no CLI → allowed; pending → denied with the status advice).Test-Plugin.ps1passes. Not yet measured on a catalog run: that is the next skill-ab invocation, with this branch as-A.🤖 Generated with Claude Code