fix(copilot): make copilotcli hook import platform-independent and preserve cwd on copilot import - #2635
Merged
Conversation
…e cwd - copilotcli: when a hook entry carries both bash and powershell, always take bash instead of tie-breaking on process.platform, so importing the same file yields the same canonical config on every machine (matches the copilot fix from #2621). - copilot: import dropped documented non-command keys such as cwd, which generate re-emits through rest, so an import then regenerate destroyed them. Preserve them via an importPassthrough helper mirroring the copilotcli sibling, and read the timeout alias the sibling already accepts. - copilotcli: correct a doc comment that claimed generate never writes the portable command field. Closes #2622
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.
Two hooks asymmetries between the
copilotandcopilotcliadapters, where each file already contained the correct implementation of the other's bug.Fix A —
copilotcliimport was machine-dependentresolveImportCommandinsrc/features/hooks/copilotcli-hooks.tstie-broke a hook entry carrying bothbashandpowershellonprocess.platform === "win32". Importing the samecopilotcli-hooks.jsontherefore produced a different rulesync hooks file depending on which contributor ran the import — churn for anyone who checks the result in.Ported the fix already applied to the
copilotsibling in #2621: always take{ command: entry.bash, shell: "bash" }and warn naming the ignoredpowershell, with the warning worded to match the sibling's.Fix B —
copilotimport dropped documented keyscopilotHooksToCanonicalinsrc/features/hooks/copilot-hooks.tsrebuilt each canonical definition from onlycommand/shell/env/timeout. Generate re-emits any non-canonical key verbatim throughrest, so a documented field likecwdsurvived generate but was destroyed by an import → regenerate cycle.Mirrored the
importPassthroughhelper fromcopilotcli-hooks.ts:289, preservingcwdandenv. No canonical schema change was needed —HookDefinitionSchemais az.looseObject.url/headers/allowedEnvVarsare deliberately not preserved here: unlike the CLI, thecopilotgenerate path emits onlycommandhooks, so those keys have no round trip to protect.Fix C — stale doc comment
The comment on the
commandfield atcopilotcli-hooks.ts:122-124claimed the portable field is "import-only here — generate always writes the platform-specific field". Generate has keyed off the canonicalshellselector since #2621 (const commandField = def.shell ?? "command";), so it does write the portable field whenevershellis unset. Corrected.Also aligned
copilotimport read onlytimeoutSecand ignored the documentedtimeoutalias thatcopilotclialready accepts. Both spellings are now read, withtimeoutSecwinning when both are present — same precedence as the sibling.Tests
Round-trip cases in both
.test.tsfiles, including the cross-platform-identical import assertion introduced by #2621 (process.platformmocked towin32, same canonical output expected).Verification
pnpm cichecknpx vitest run --config vitest.e2e.config.ts src/e2e/e2e-hooks.spec.tsCloses #2622
Part of #2401 (the two hooks asymmetries recorded in its 2026-08-07 comment)