@detergent-software/atk 9.4.0-dev.3 → 9.4.0-dev.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/CHANGELOG.md +227 -0
  2. package/README.md +2 -2
  3. package/build/command-manifest.json +5 -5
  4. package/build/commands/audit.d.ts.map +1 -1
  5. package/build/commands/audit.js +7 -4
  6. package/build/commands/audit.js.map +1 -1
  7. package/build/commands/diff.d.ts.map +1 -1
  8. package/build/commands/diff.js +10 -10
  9. package/build/commands/diff.js.map +1 -1
  10. package/build/commands/info.d.ts.map +1 -1
  11. package/build/commands/info.js +16 -14
  12. package/build/commands/info.js.map +1 -1
  13. package/build/commands/init.d.ts.map +1 -1
  14. package/build/commands/init.js +1 -1
  15. package/build/commands/init.js.map +1 -1
  16. package/build/commands/install.d.ts.map +1 -1
  17. package/build/commands/install.js +153 -67
  18. package/build/commands/install.js.map +1 -1
  19. package/build/commands/move.d.ts.map +1 -1
  20. package/build/commands/move.js +5 -4
  21. package/build/commands/move.js.map +1 -1
  22. package/build/commands/outdated.js +1 -1
  23. package/build/commands/outdated.js.map +1 -1
  24. package/build/commands/update.d.ts.map +1 -1
  25. package/build/commands/update.js +14 -7
  26. package/build/commands/update.js.map +1 -1
  27. package/build/commands/why.d.ts.map +1 -1
  28. package/build/commands/why.js +28 -7
  29. package/build/commands/why.js.map +1 -1
  30. package/build/components/DiffView.d.ts +3 -1
  31. package/build/components/DiffView.d.ts.map +1 -1
  32. package/build/components/DiffView.js +2 -2
  33. package/build/components/DiffView.js.map +1 -1
  34. package/build/components/InitSuccess.d.ts.map +1 -1
  35. package/build/components/InitSuccess.js +4 -1
  36. package/build/components/InitSuccess.js.map +1 -1
  37. package/build/components/InstallSummary.d.ts +7 -2
  38. package/build/components/InstallSummary.d.ts.map +1 -1
  39. package/build/components/InstallSummary.js +3 -1
  40. package/build/components/InstallSummary.js.map +1 -1
  41. package/build/hooks/useInitState.d.ts +9 -1
  42. package/build/hooks/useInitState.d.ts.map +1 -1
  43. package/build/hooks/useInitState.js +52 -10
  44. package/build/hooks/useInitState.js.map +1 -1
  45. package/build/hooks/useListActions.d.ts.map +1 -1
  46. package/build/hooks/useListActions.js +9 -2
  47. package/build/hooks/useListActions.js.map +1 -1
  48. package/build/lib/adapter.d.ts +14 -9
  49. package/build/lib/adapter.d.ts.map +1 -1
  50. package/build/lib/adapter.js +46 -8
  51. package/build/lib/adapter.js.map +1 -1
  52. package/build/lib/asset-tools.d.ts +10 -0
  53. package/build/lib/asset-tools.d.ts.map +1 -1
  54. package/build/lib/asset-tools.js +18 -0
  55. package/build/lib/asset-tools.js.map +1 -1
  56. package/build/lib/completion/candidates.d.ts.map +1 -1
  57. package/build/lib/completion/candidates.js +21 -8
  58. package/build/lib/completion/candidates.js.map +1 -1
  59. package/build/lib/config-entries.d.ts +3 -3
  60. package/build/lib/config-entries.d.ts.map +1 -1
  61. package/build/lib/config-entries.js +16 -6
  62. package/build/lib/config-entries.js.map +1 -1
  63. package/build/lib/config-lock.d.ts +2 -1
  64. package/build/lib/config-lock.d.ts.map +1 -1
  65. package/build/lib/config-lock.js +10 -2
  66. package/build/lib/config-lock.js.map +1 -1
  67. package/build/lib/cross-scope.d.ts +6 -2
  68. package/build/lib/cross-scope.d.ts.map +1 -1
  69. package/build/lib/cross-scope.js +20 -13
  70. package/build/lib/cross-scope.js.map +1 -1
  71. package/build/lib/diagnostics.d.ts +3 -2
  72. package/build/lib/diagnostics.d.ts.map +1 -1
  73. package/build/lib/diagnostics.js +6 -4
  74. package/build/lib/diagnostics.js.map +1 -1
  75. package/build/lib/diff-command.d.ts +7 -2
  76. package/build/lib/diff-command.d.ts.map +1 -1
  77. package/build/lib/diff-command.js +14 -10
  78. package/build/lib/diff-command.js.map +1 -1
  79. package/build/lib/gitignore.d.ts +8 -0
  80. package/build/lib/gitignore.d.ts.map +1 -1
  81. package/build/lib/gitignore.js +51 -6
  82. package/build/lib/gitignore.js.map +1 -1
  83. package/build/lib/hook-config.d.ts +90 -7
  84. package/build/lib/hook-config.d.ts.map +1 -1
  85. package/build/lib/hook-config.js +135 -11
  86. package/build/lib/hook-config.js.map +1 -1
  87. package/build/lib/hook-script.d.ts +45 -0
  88. package/build/lib/hook-script.d.ts.map +1 -1
  89. package/build/lib/hook-script.js +118 -1
  90. package/build/lib/hook-script.js.map +1 -1
  91. package/build/lib/init.d.ts +34 -12
  92. package/build/lib/init.d.ts.map +1 -1
  93. package/build/lib/init.js +180 -32
  94. package/build/lib/init.js.map +1 -1
  95. package/build/lib/install-targets.d.ts +35 -8
  96. package/build/lib/install-targets.d.ts.map +1 -1
  97. package/build/lib/install-targets.js +87 -14
  98. package/build/lib/install-targets.js.map +1 -1
  99. package/build/lib/installer.d.ts +18 -2
  100. package/build/lib/installer.d.ts.map +1 -1
  101. package/build/lib/installer.js +215 -38
  102. package/build/lib/installer.js.map +1 -1
  103. package/build/lib/local-edits.d.ts +7 -0
  104. package/build/lib/local-edits.d.ts.map +1 -1
  105. package/build/lib/local-edits.js +21 -2
  106. package/build/lib/local-edits.js.map +1 -1
  107. package/build/lib/mover.d.ts +5 -4
  108. package/build/lib/mover.d.ts.map +1 -1
  109. package/build/lib/mover.js +23 -27
  110. package/build/lib/mover.js.map +1 -1
  111. package/build/lib/multi-tool-install.d.ts +48 -11
  112. package/build/lib/multi-tool-install.d.ts.map +1 -1
  113. package/build/lib/multi-tool-install.js +165 -36
  114. package/build/lib/multi-tool-install.js.map +1 -1
  115. package/build/lib/named-entry.d.ts +12 -0
  116. package/build/lib/named-entry.d.ts.map +1 -1
  117. package/build/lib/named-entry.js +16 -8
  118. package/build/lib/named-entry.js.map +1 -1
  119. package/build/lib/schemas/adapter.d.ts +30 -0
  120. package/build/lib/schemas/adapter.d.ts.map +1 -1
  121. package/build/lib/schemas/adapter.js +27 -5
  122. package/build/lib/schemas/adapter.js.map +1 -1
  123. package/build/lib/sync.d.ts +7 -0
  124. package/build/lib/sync.d.ts.map +1 -1
  125. package/build/lib/sync.js +54 -6
  126. package/build/lib/sync.js.map +1 -1
  127. package/build/lib/touched-paths.d.ts.map +1 -1
  128. package/build/lib/touched-paths.js +2 -1
  129. package/build/lib/touched-paths.js.map +1 -1
  130. package/build/lib/uninstaller.d.ts.map +1 -1
  131. package/build/lib/uninstaller.js +11 -3
  132. package/build/lib/uninstaller.js.map +1 -1
  133. package/build/lib/updater.d.ts +32 -5
  134. package/build/lib/updater.d.ts.map +1 -1
  135. package/build/lib/updater.js +129 -14
  136. package/build/lib/updater.js.map +1 -1
  137. package/package.json +1 -1
  138. package/tool-adapters/claude-code.json +1 -1
  139. package/tool-adapters/codex-cli.json +5 -1
  140. package/tool-adapters/copilot-cli.json +58 -9
@@ -1,5 +1,5 @@
1
1
  import type { PlacementConfig } from './schemas/adapter.js';
2
- import type { HookEventBinding } from './schemas/index.js';
2
+ import type { HookConfig, HookEventBinding } from './schemas/index.js';
3
3
  /**
4
4
  * Helpers for translating a hook asset's `hookConfig` event bindings into
5
5
  * tool-valid hook config (e.g. Claude Code's `.claude/settings.json` `hooks`
@@ -13,6 +13,31 @@ import type { HookEventBinding } from './schemas/index.js';
13
13
  * This module is intentionally dependency-free so it can be shared by the
14
14
  * installer, uninstaller, and checksum verifier without import cycles.
15
15
  */
16
+ /**
17
+ * A Copilot CLI hook entry under an event array. Copilot runs `bash` on Linux and macOS and
18
+ * `powershell` on Windows; ATK writes the same command in both, one that both shells run, unless
19
+ * the placement has a `configCommandPowershell` ({@link hookPowershellCommand}).
20
+ *
21
+ * Copilot CLI 1.0.105 also runs the hooks in a project's `.claude/settings.json`, and sets
22
+ * `CLAUDE_PROJECT_DIR` for every hook, which 0.0.422 did neither of (ATK-820). So the project
23
+ * adapter's commands exit at once when that variable is set, Claude Code's copy of the script is
24
+ * there (executable, for a `.sh`; ATK gitignores the scripts but not the settings) and Claude Code's
25
+ * settings register it: a hook installed for both tools then runs once in Copilot, from Claude
26
+ * Code's entry. For a `.sh` hook's `bash`, the settings have to register Claude Code's command with
27
+ * the path quoted (`"$CLAUDE_PROJECT_DIR"/…`, ATK-850; behind {@link deriveHookCommand}'s
28
+ * PowerShell prefix since ATK-849, without it as the CLI before wrote it), or the unquoted one an
29
+ * older CLI wrote while the project's path has no space: from a path with a space that one fails,
30
+ * and sync rewrites it only
31
+ * for a developer who has Claude Code set up. A `.sh` hook's `powershell` has no guard, since on
32
+ * Windows Copilot runs Claude Code's command in PowerShell, where it steps aside (ATK-849) or, as an
33
+ * older CLI wrote it, fails, and Copilot's own entry is the run that works.
34
+ */
35
+ export interface CopilotHookEntry {
36
+ bash: string;
37
+ powershell: string;
38
+ timeoutSec?: number;
39
+ type: 'command';
40
+ }
16
41
  /** A single Claude-Code-style hook command entry. */
17
42
  export interface HookCommand {
18
43
  command: string;
@@ -24,6 +49,22 @@ export interface HookGroup {
24
49
  hooks: HookCommand[];
25
50
  matcher?: string;
26
51
  }
52
+ /** A `hookConfig` event a hook placement leaves out, and why. */
53
+ export interface LeftOutHookEvent {
54
+ event: string;
55
+ reason: 'duplicate' | 'matcher' | 'unknown-event';
56
+ }
57
+ /** One event a hook placement registers, by the tool's own name for it. */
58
+ export interface PlacedHookEvent {
59
+ binding: HookEventBinding | undefined;
60
+ event: string;
61
+ }
62
+ /**
63
+ * Build the entry a hook placement appends under an event, in its `configHookFormat`: a
64
+ * matcher-group ({@link buildHookGroup}) by default, or a Copilot CLI entry, whose timeout is
65
+ * `timeoutSec` and whose `powershell` is `powershellCommand` (the `command` without one).
66
+ */
67
+ export declare function buildHookEntry(placement: Pick<PlacementConfig, 'configHookFormat'>, command: string, binding: HookEventBinding | undefined, powershellCommand?: string): CopilotHookEntry | HookGroup;
27
68
  /**
28
69
  * Build a tool-valid hook matcher-group for a single event binding.
29
70
  * Only includes `matcher`/`timeout` when set, keeping config (and its checksum) minimal.
@@ -32,29 +73,71 @@ export declare function buildHookGroup(command: string, binding: HookEventBindin
32
73
  /**
33
74
  * Derive the hook command string from the placement's command prefix and the
34
75
  * installed script's project-relative POSIX path.
35
- * e.g. ("$CLAUDE_PROJECT_DIR/", ".claude/hooks/notify-on-stop.sh")
36
- * -> "$CLAUDE_PROJECT_DIR/.claude/hooks/notify-on-stop.sh"
76
+ * e.g. (': "$(exit 0)"; exec "$CLAUDE_PROJECT_DIR"/', ".claude/hooks/notify-on-stop.sh")
77
+ * -> ': "$(exit 0)"; exec "$CLAUDE_PROJECT_DIR"/.claude/hooks/notify-on-stop.sh'
78
+ *
79
+ * Claude Code's prefix is for Copilot CLI, which runs the hooks in `.claude/settings.json` too, in
80
+ * PowerShell on Windows (ATK-849). PowerShell can't parse `"$CLAUDE_PROJECT_DIR"/…` as a command, so
81
+ * that entry failed, and on preToolUse Copilot denied every tool. Bash expands `$(exit 0)` to nothing
82
+ * and `exec` runs the script with its stdin and exit code; PowerShell parses the line and runs the
83
+ * `exit 0` while evaluating `:`'s argument, so the entry steps aside there.
37
84
  */
38
85
  export declare function deriveHookCommand(commandPrefix: string | undefined, installedRelPath: string): string;
39
86
  /**
40
87
  * The command a hook placement registers for an asset: the placement's `configCommand` template
41
88
  * when it has one (a command that doesn't name the installed path, such as a user hook's
42
89
  * `"${CLAUDE_CONFIG_DIR:-$HOME/.claude}/hooks/x.sh"`, or one that names it as `{path}`, such as a
43
- * node hook's), otherwise {@link deriveHookCommand}.
90
+ * node hook's, or as `{homePath}`), otherwise {@link deriveHookCommand}. `{homePath}` is the
91
+ * user-root-relative path from `$HOME`, which bash and PowerShell both expand, or the path itself
92
+ * when it is absolute (a moved user config directory on another drive).
44
93
  */
45
94
  export declare function hookCommand(placement: Pick<PlacementConfig, 'configCommand' | 'configCommandPrefix' | 'path'>, assetName: string): string;
95
+ /**
96
+ * The events a hook placement registers for a `hookConfig`, by the tool's own names
97
+ * (`configHookEvents`), and the ones it leaves out: an event the map doesn't know, and, for
98
+ * Copilot CLI, a binding with a `matcher`, whose tool names are Claude Code's (`Bash`) and which
99
+ * a Copilot entry can't hold (run on every tool instead, a filtered hook would do the wrong thing).
100
+ * An event already named as the tool names it is taken as it is; a second binding for an event
101
+ * already taken is left out.
102
+ */
103
+ export declare function hookEventsFor(placement: Pick<PlacementConfig, 'configHookEvents' | 'configHookFormat'>, hookConfig: HookConfig | undefined): {
104
+ events: PlacedHookEvent[];
105
+ leftOut: LeftOutHookEvent[];
106
+ };
46
107
  /**
47
108
  * Return true if a value looks like a hook matcher-group whose nested command
48
- * entries include the given command — i.e. the group ATK owns for that asset.
109
+ * entries include the given command — i.e. the group ATK owns for that asset —
110
+ * or a Copilot CLI entry whose `bash` command is it.
49
111
  * Tolerant of arbitrary/foreign group shapes (returns false rather than throwing).
50
112
  */
51
113
  export declare function hookGroupOwnsCommand(group: unknown, command: string): boolean;
114
+ /**
115
+ * The command a Copilot CLI entry's `powershell` runs on Windows: the placement's
116
+ * `configCommandPowershell` template, filled as {@link hookCommand} fills `configCommand`, or the
117
+ * {@link hookCommand} itself without one. A `.sh` hook's template finds Git Bash, since the `bash`
118
+ * PowerShell finds first on `PATH` is often WSL's (`System32\bash.exe`).
119
+ */
120
+ export declare function hookPowershellCommand(placement: Pick<PlacementConfig, 'configCommand' | 'configCommandPowershell' | 'configCommandPrefix' | 'path'>, assetName: string): string;
121
+ /**
122
+ * Whether a config file holds nothing once ATK's entries are out of it: no keys, or only the
123
+ * `version` of a Copilot CLI hook file, which ATK writes and is the whole file without its hooks.
124
+ */
125
+ export declare function isEmptyHookConfig(config: Record<string, unknown>): boolean;
52
126
  /** Whether a hook's manifest entrypoint is an ES module, which a placement's `nodeEntrypoint` runs with node. */
53
127
  export declare function isNodeHookEntrypoint(entrypoint: string | undefined): boolean;
128
+ /** Why a hook placement leaves out a `hookConfig` event, as the end of a sentence. */
129
+ export declare function leftOutHookEventReason(left: LeftOutHookEvent, toolName: string): string;
130
+ /**
131
+ * {@link placementForEntrypoint}, with `{name}` in its `configFile` filled in: a placement that
132
+ * writes one config file per hook (Copilot CLI's `.github/hooks/{name}.json`) names it after the
133
+ * asset. A shared config file has no `{name}` and stays as it is.
134
+ */
135
+ export declare function placementForAsset<P extends PlacementConfig | undefined>(placement: P, entrypoint: string | undefined, assetName: string): P;
54
136
  /**
55
137
  * The placement a hook asset is placed with: its `nodeEntrypoint` path and command when the asset's
56
- * entrypoint is an ES module, otherwise the placement itself. A `.sh` hook is run by the shell the
57
- * tool picks, which on Windows can be cmd, where neither `$VAR` nor a `.sh` script works; an
138
+ * entrypoint is an ES module, its `jsonEntrypoint` path alone (no config merge) when the entrypoint
139
+ * is the tool's own hook config, otherwise the placement itself. A `.sh` hook is run by the shell
140
+ * the tool picks, which on Windows can be cmd, where neither `$VAR` nor a `.sh` script works; an
58
141
  * `.mjs` hook run by node behaves the same under every shell.
59
142
  */
60
143
  export declare function placementForEntrypoint<P extends PlacementConfig | undefined>(placement: P, entrypoint: string | undefined): P;
@@ -1 +1 @@
1
- {"version":3,"file":"hook-config.d.ts","sourceRoot":"","sources":["../../src/lib/hook-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D;;;;;;;;;;;;GAYG;AAEH,qDAAqD;AACrD,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,0EAA0E;AAC1E,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,SAAS,GAAG,SAAS,CAUhG;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,EAAE,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAEr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kB5D;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAY7E;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,IAAI,CAAC,eAAe,EAAE,eAAe,GAAG,yBAAyB,GAAG,qBAAqB,GAAG,MAAM,CAAC,EAC9G,SAAS,EAAE,MAAM,GAChB,MAAM,CAKR;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAG1E;AAED,iHAAiH;AACjH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAE5E;AAED,sFAAsF;AACtF,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CASvF;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,eAAe,GAAG,SAAS,EACrE,SAAS,EAAE,CAAC,EACZ,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,SAAS,EAAE,MAAM,GAChB,CAAC,CAMH;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,eAAe,GAAG,SAAS,EAC1E,SAAS,EAAE,CAAC,EACZ,UAAU,EAAE,MAAM,GAAG,SAAS,GAC7B,CAAC,CAgBH;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,GACd,OAAO,CA2BT"}
@@ -1,3 +1,20 @@
1
+ import { isAbsolute } from 'node:path';
2
+ /**
3
+ * Build the entry a hook placement appends under an event, in its `configHookFormat`: a
4
+ * matcher-group ({@link buildHookGroup}) by default, or a Copilot CLI entry, whose timeout is
5
+ * `timeoutSec` and whose `powershell` is `powershellCommand` (the `command` without one).
6
+ */
7
+ export function buildHookEntry(placement, command, binding, powershellCommand = command) {
8
+ if (placement.configHookFormat !== 'copilot') {
9
+ return buildHookGroup(command, binding);
10
+ }
11
+ return {
12
+ bash: command,
13
+ powershell: powershellCommand,
14
+ type: 'command',
15
+ ...(binding?.timeout !== undefined ? { timeoutSec: binding.timeout } : {}),
16
+ };
17
+ }
1
18
  /**
2
19
  * Build a tool-valid hook matcher-group for a single event binding.
3
20
  * Only includes `matcher`/`timeout` when set, keeping config (and its checksum) minimal.
@@ -16,8 +33,14 @@ export function buildHookGroup(command, binding) {
16
33
  /**
17
34
  * Derive the hook command string from the placement's command prefix and the
18
35
  * installed script's project-relative POSIX path.
19
- * e.g. ("$CLAUDE_PROJECT_DIR/", ".claude/hooks/notify-on-stop.sh")
20
- * -> "$CLAUDE_PROJECT_DIR/.claude/hooks/notify-on-stop.sh"
36
+ * e.g. (': "$(exit 0)"; exec "$CLAUDE_PROJECT_DIR"/', ".claude/hooks/notify-on-stop.sh")
37
+ * -> ': "$(exit 0)"; exec "$CLAUDE_PROJECT_DIR"/.claude/hooks/notify-on-stop.sh'
38
+ *
39
+ * Claude Code's prefix is for Copilot CLI, which runs the hooks in `.claude/settings.json` too, in
40
+ * PowerShell on Windows (ATK-849). PowerShell can't parse `"$CLAUDE_PROJECT_DIR"/…` as a command, so
41
+ * that entry failed, and on preToolUse Copilot denied every tool. Bash expands `$(exit 0)` to nothing
42
+ * and `exec` runs the script with its stdin and exit code; PowerShell parses the line and runs the
43
+ * `exit 0` while evaluating `:`'s argument, so the entry steps aside there.
21
44
  */
22
45
  export function deriveHookCommand(commandPrefix, installedRelPath) {
23
46
  return `${commandPrefix ?? ''}${installedRelPath}`;
@@ -26,46 +49,135 @@ export function deriveHookCommand(commandPrefix, installedRelPath) {
26
49
  * The command a hook placement registers for an asset: the placement's `configCommand` template
27
50
  * when it has one (a command that doesn't name the installed path, such as a user hook's
28
51
  * `"${CLAUDE_CONFIG_DIR:-$HOME/.claude}/hooks/x.sh"`, or one that names it as `{path}`, such as a
29
- * node hook's), otherwise {@link deriveHookCommand}.
52
+ * node hook's, or as `{homePath}`), otherwise {@link deriveHookCommand}. `{homePath}` is the
53
+ * user-root-relative path from `$HOME`, which bash and PowerShell both expand, or the path itself
54
+ * when it is absolute (a moved user config directory on another drive).
30
55
  */
31
56
  export function hookCommand(placement, assetName) {
32
- const installedPath = placement.path.replace(/\{name\}/g, assetName);
33
57
  if (placement.configCommand !== undefined) {
34
- return placement.configCommand.replace(/\{path\}/g, installedPath).replace(/\{name\}/g, assetName);
58
+ return fillCommandTemplate(placement.configCommand, placement, assetName);
35
59
  }
36
- return deriveHookCommand(placement.configCommandPrefix, installedPath);
60
+ return deriveHookCommand(placement.configCommandPrefix, placement.path.replace(/\{name\}/g, assetName));
61
+ }
62
+ /**
63
+ * The events a hook placement registers for a `hookConfig`, by the tool's own names
64
+ * (`configHookEvents`), and the ones it leaves out: an event the map doesn't know, and, for
65
+ * Copilot CLI, a binding with a `matcher`, whose tool names are Claude Code's (`Bash`) and which
66
+ * a Copilot entry can't hold (run on every tool instead, a filtered hook would do the wrong thing).
67
+ * An event already named as the tool names it is taken as it is; a second binding for an event
68
+ * already taken is left out.
69
+ */
70
+ export function hookEventsFor(placement, hookConfig) {
71
+ const events = [];
72
+ const leftOut = [];
73
+ const names = placement.configHookEvents;
74
+ const toolNames = new Set(Object.values(names ?? {}));
75
+ for (const [event, binding] of Object.entries(hookConfig ?? {})) {
76
+ const toolEvent = names ? (names[event] ?? (toolNames.has(event) ? event : undefined)) : event;
77
+ if (toolEvent === undefined) {
78
+ leftOut.push({ event, reason: 'unknown-event' });
79
+ }
80
+ else if (events.some((e) => e.event === toolEvent)) {
81
+ leftOut.push({ event, reason: 'duplicate' });
82
+ }
83
+ else if (placement.configHookFormat === 'copilot' && binding?.matcher) {
84
+ leftOut.push({ event, reason: 'matcher' });
85
+ }
86
+ else {
87
+ events.push({ binding, event: toolEvent });
88
+ }
89
+ }
90
+ return { events, leftOut };
37
91
  }
38
92
  /**
39
93
  * Return true if a value looks like a hook matcher-group whose nested command
40
- * entries include the given command — i.e. the group ATK owns for that asset.
94
+ * entries include the given command — i.e. the group ATK owns for that asset —
95
+ * or a Copilot CLI entry whose `bash` command is it.
41
96
  * Tolerant of arbitrary/foreign group shapes (returns false rather than throwing).
42
97
  */
43
98
  export function hookGroupOwnsCommand(group, command) {
44
99
  if (!group || typeof group !== 'object') {
45
100
  return false;
46
101
  }
102
+ if (group.bash === command) {
103
+ return true;
104
+ }
47
105
  const hooks = group.hooks;
48
106
  if (!Array.isArray(hooks)) {
49
107
  return false;
50
108
  }
51
109
  return hooks.some((h) => !!h && typeof h === 'object' && h.command === command);
52
110
  }
111
+ /**
112
+ * The command a Copilot CLI entry's `powershell` runs on Windows: the placement's
113
+ * `configCommandPowershell` template, filled as {@link hookCommand} fills `configCommand`, or the
114
+ * {@link hookCommand} itself without one. A `.sh` hook's template finds Git Bash, since the `bash`
115
+ * PowerShell finds first on `PATH` is often WSL's (`System32\bash.exe`).
116
+ */
117
+ export function hookPowershellCommand(placement, assetName) {
118
+ if (placement.configCommandPowershell === undefined) {
119
+ return hookCommand(placement, assetName);
120
+ }
121
+ return fillCommandTemplate(placement.configCommandPowershell, placement, assetName);
122
+ }
123
+ /**
124
+ * Whether a config file holds nothing once ATK's entries are out of it: no keys, or only the
125
+ * `version` of a Copilot CLI hook file, which ATK writes and is the whole file without its hooks.
126
+ */
127
+ export function isEmptyHookConfig(config) {
128
+ const keys = Object.keys(config);
129
+ return keys.length === 0 || (keys.length === 1 && keys[0] === 'version');
130
+ }
53
131
  /** Whether a hook's manifest entrypoint is an ES module, which a placement's `nodeEntrypoint` runs with node. */
54
132
  export function isNodeHookEntrypoint(entrypoint) {
55
133
  return entrypoint?.endsWith('.mjs') ?? false;
56
134
  }
135
+ /** Why a hook placement leaves out a `hookConfig` event, as the end of a sentence. */
136
+ export function leftOutHookEventReason(left, toolName) {
137
+ switch (left.reason) {
138
+ case 'duplicate':
139
+ return `another of its events has the same name in ${toolName}`;
140
+ case 'matcher':
141
+ return `its matcher names Claude Code's tools, and ${toolName} has no matcher for it`;
142
+ case 'unknown-event':
143
+ return `${toolName} has no such hook event`;
144
+ }
145
+ }
146
+ /**
147
+ * {@link placementForEntrypoint}, with `{name}` in its `configFile` filled in: a placement that
148
+ * writes one config file per hook (Copilot CLI's `.github/hooks/{name}.json`) names it after the
149
+ * asset. A shared config file has no `{name}` and stays as it is.
150
+ */
151
+ export function placementForAsset(placement, entrypoint, assetName) {
152
+ const resolved = placementForEntrypoint(placement, entrypoint);
153
+ if (!resolved?.configFile?.includes('{name}')) {
154
+ return resolved;
155
+ }
156
+ return { ...resolved, configFile: resolved.configFile.replace(/\{name\}/g, assetName) };
157
+ }
57
158
  /**
58
159
  * The placement a hook asset is placed with: its `nodeEntrypoint` path and command when the asset's
59
- * entrypoint is an ES module, otherwise the placement itself. A `.sh` hook is run by the shell the
60
- * tool picks, which on Windows can be cmd, where neither `$VAR` nor a `.sh` script works; an
160
+ * entrypoint is an ES module, its `jsonEntrypoint` path alone (no config merge) when the entrypoint
161
+ * is the tool's own hook config, otherwise the placement itself. A `.sh` hook is run by the shell
162
+ * the tool picks, which on Windows can be cmd, where neither `$VAR` nor a `.sh` script works; an
61
163
  * `.mjs` hook run by node behaves the same under every shell.
62
164
  */
63
165
  export function placementForEntrypoint(placement, entrypoint) {
166
+ if (placement?.jsonEntrypoint && entrypoint?.endsWith('.json')) {
167
+ return { path: placement.jsonEntrypoint.path };
168
+ }
64
169
  if (!placement?.nodeEntrypoint || !isNodeHookEntrypoint(entrypoint)) {
65
170
  return placement;
66
171
  }
67
- const { configCommandPrefix: _prefix, nodeEntrypoint, ...rest } = placement;
68
- return { ...rest, configCommand: nodeEntrypoint.configCommand, path: nodeEntrypoint.path };
172
+ const { configCommandPowershell: _powershell, configCommandPrefix: _prefix, nodeEntrypoint, ...rest } = placement;
173
+ return {
174
+ ...rest,
175
+ configCommand: nodeEntrypoint.configCommand,
176
+ ...(nodeEntrypoint.configCommandPowershell !== undefined
177
+ ? { configCommandPowershell: nodeEntrypoint.configCommandPowershell }
178
+ : {}),
179
+ path: nodeEntrypoint.path,
180
+ };
69
181
  }
70
182
  /**
71
183
  * Remove the hook group owned by `command` from `config[configKey][event]` (an array),
@@ -98,4 +210,16 @@ export function removeHookGroup(config, configKey, event, command) {
98
210
  }
99
211
  return true;
100
212
  }
213
+ /**
214
+ * A hook command template with its placeholders filled for an asset: `{path}` (the placed path),
215
+ * `{homePath}` (`$HOME/` + that path, or the path itself when it is absolute) and `{name}`.
216
+ */
217
+ function fillCommandTemplate(template, placement, assetName) {
218
+ const installedPath = placement.path.replace(/\{name\}/g, assetName);
219
+ const homePath = isAbsolute(installedPath) ? installedPath : `$HOME/${installedPath}`;
220
+ return template
221
+ .replace(/\{path\}/g, installedPath)
222
+ .replace(/\{homePath\}/g, homePath)
223
+ .replace(/\{name\}/g, assetName);
224
+ }
101
225
  //# sourceMappingURL=hook-config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hook-config.js","sourceRoot":"","sources":["../../src/lib/hook-config.ts"],"names":[],"mappings":"AA8BA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,OAAqC;IACnF,MAAM,WAAW,GAAgB;QAC/B,OAAO;QACP,IAAI,EAAE,SAAS;QACf,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACxE,CAAC;IACF,OAAO;QACL,KAAK,EAAE,CAAC,WAAW,CAAC;QACpB,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1D,CAAC;AACJ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C,CAAC"}
@@ -1,4 +1,7 @@
1
1
  import type { PlacementConfig } from './schemas/adapter.js';
2
+ import type { InstalledAsset } from './schemas/lockfile.js';
3
+ /** Whether `content` is a published file of the hook (see `isPublishedContent`). */
4
+ export type PublishedCheck = (content: Uint8Array) => Promise<boolean>;
2
5
  /**
3
6
  * Project-relative path of the script a hook placement registers as its command, or
4
7
  * undefined when the tool does not run the installed file directly.
@@ -12,15 +15,57 @@ import type { PlacementConfig } from './schemas/adapter.js';
12
15
  * ships lands at this same path, and skills such as `/worktree-gc` run that wrapper directly.
13
16
  */
14
17
  export declare function hookScriptPath(placement: PlacementConfig | undefined, assetName: string): string | undefined;
18
+ /**
19
+ * Whether the file at `path` is the hook file ATK generates for hook `name` (Copilot CLI's
20
+ * `.github/hooks/{name}.json`): readable config holding nothing but the hook's own entries, each
21
+ * owned by one of `recorded` (the commands the asset's lockfile entries recorded for the tool, which
22
+ * may be an older CLI's) or by a command the placement's scripts register for the hook now (`.sh`,
23
+ * or `.mjs` run with node). Another hook's entry, or one the user wrote, makes it someone else's.
24
+ * `placement` is the adapter's hook placement, not one resolved for an entrypoint.
25
+ */
26
+ export declare function isGeneratedHookFile(placement: PlacementConfig | undefined, name: string, path: string, recorded?: string[]): Promise<boolean>;
27
+ /**
28
+ * The absolute path a hook whose `entrypoint` is the tool's own hook JSON is placed at, when the
29
+ * adapter's hook `placement` writes a script version's hook file there too (Copilot CLI's
30
+ * `.github/hooks/{name}.json`), or undefined for any other hook or placement.
31
+ */
32
+ export declare function jsonHookFilePath(placement: PlacementConfig | undefined, entrypoint: string | undefined, name: string, projectDir: string): string | undefined;
15
33
  /**
16
34
  * True when the file exists but the current user cannot execute it. Always false on
17
35
  * Windows, which has no exec bit, and for a missing file (checksum checks report that).
18
36
  */
19
37
  export declare function lacksExecBit(filePath: string, platform?: NodeJS.Platform): Promise<boolean>;
38
+ /**
39
+ * The scripts the adapter's hook `placement` places for hook `name` (`{name}.sh`, and `{name}.mjs`
40
+ * for an ES module) that hold a file of the hook: the bytes of a file the given entries of the asset
41
+ * recorded or, with `published`, of a file a published version of it shipped. Under a version whose
42
+ * entrypoint is the tool's own hook JSON, those that version doesn't place itself beside the JSON
43
+ * are what a script version left (ATK-818); the caller leaves out the ones it places. Anything else
44
+ * at those paths stays. Absolute paths.
45
+ */
46
+ export declare function leftoverHookScripts(placement: PlacementConfig | undefined, name: string, installed: Array<Pick<InstalledAsset, 'files'> | undefined>, projectDir: string, published?: PublishedCheck): Promise<string[]>;
20
47
  /**
21
48
  * Add an exec bit wherever the file has a read bit, like `chmod +x` under the user's
22
49
  * umask: 644 becomes 755 and 600 becomes 700. The registry stores scripts as 644 and the
23
50
  * API serves bytes only, so the installer has to set the mode itself. No-op on Windows.
24
51
  */
25
52
  export declare function makeExecutable(filePath: string, platform?: NodeJS.Platform): Promise<void>;
53
+ /**
54
+ * The absolute path of a file of the hook at the path of its own config file (Copilot CLI's
55
+ * `.github/hooks/{name}.json`), which the hook file is written to in its place, or undefined when
56
+ * there is none:
57
+ * - the copy of the hook's script that a CLI before ATK-204 saved there, which the tool can't read
58
+ * as config: it holds the bytes of a file the given entries of the asset recorded, or is a script
59
+ * (`#!`), which no config file starts with (the lockfile may already record a newer version);
60
+ * - with `json`, the hook's own JSON, which a version whose entrypoint it is placed there as it is
61
+ * (ATK-818): it holds the bytes of a recorded file or of a file a published version shipped,
62
+ * since a sync over a lockfile a teammate's update wrote has no record of it. ATK's own hook file,
63
+ * by its current commands or the ones `json.recorded` names, is not one, and neither is config
64
+ * with anything else in it: the hook's entries are merged into both.
65
+ * `placement` is the adapter's hook placement, not one resolved for an entrypoint.
66
+ */
67
+ export declare function misplacedHookCopy(placement: PlacementConfig | undefined, name: string, installed: Array<Pick<InstalledAsset, 'files'> | undefined>, projectDir: string, json?: {
68
+ published: PublishedCheck;
69
+ recorded: string[];
70
+ }): Promise<string | undefined>;
26
71
  //# sourceMappingURL=hook-script.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hook-script.d.ts","sourceRoot":"","sources":["../../src/lib/hook-script.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,eAAe,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE5G;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,OAAO,CAAC,OAAO,CAAC,CASnH;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAOlH"}
1
+ {"version":3,"file":"hook-script.d.ts","sourceRoot":"","sources":["../../src/lib/hook-script.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAO5D,oFAAoF;AACpF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAEvE;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,eAAe,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE5G;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,eAAe,GAAG,SAAS,EACtC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,MAAM,EAAO,GACtB,OAAO,CAAC,OAAO,CAAC,CAsBlB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,eAAe,GAAG,SAAS,EACtC,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB,MAAM,GAAG,SAAS,CAMpB;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,OAAO,CAAC,OAAO,CAAC,CASnH;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,eAAe,GAAG,SAAS,EACtC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC,EAC3D,UAAU,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,MAAM,EAAE,CAAC,CASnB;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAOlH;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,eAAe,GAAG,SAAS,EACtC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC,EAC3D,UAAU,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE;IAAE,SAAS,EAAE,cAAc,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,GACvD,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAiB7B"}
@@ -1,4 +1,9 @@
1
- import { access, chmod, constants, stat } from 'node:fs/promises';
1
+ import { existsSync } from 'node:fs';
2
+ import { access, chmod, constants, readFile, stat } from 'node:fs/promises';
3
+ import { hashBytes } from './checksum.js';
4
+ import { readConfigFile, resolveConfigFormat } from './config-file.js';
5
+ import { hookCommand, hookGroupOwnsCommand, placementForEntrypoint } from './hook-config.js';
6
+ import { fromRoot } from './root-path.js';
2
7
  /**
3
8
  * Project-relative path of the script a hook placement registers as its command, or
4
9
  * undefined when the tool does not run the installed file directly.
@@ -14,6 +19,51 @@ import { access, chmod, constants, stat } from 'node:fs/promises';
14
19
  export function hookScriptPath(placement, assetName) {
15
20
  return placement?.configHookMerge ? placement.path.replace(/\{name\}/g, assetName) : undefined;
16
21
  }
22
+ /**
23
+ * Whether the file at `path` is the hook file ATK generates for hook `name` (Copilot CLI's
24
+ * `.github/hooks/{name}.json`): readable config holding nothing but the hook's own entries, each
25
+ * owned by one of `recorded` (the commands the asset's lockfile entries recorded for the tool, which
26
+ * may be an older CLI's) or by a command the placement's scripts register for the hook now (`.sh`,
27
+ * or `.mjs` run with node). Another hook's entry, or one the user wrote, makes it someone else's.
28
+ * `placement` is the adapter's hook placement, not one resolved for an entrypoint.
29
+ */
30
+ export async function isGeneratedHookFile(placement, name, path, recorded = []) {
31
+ if (!placement?.configHookMerge || !placement.configKey || !existsSync(path))
32
+ return false;
33
+ let config;
34
+ try {
35
+ config = await readConfigFile(path, resolveConfigFormat(path, placement));
36
+ }
37
+ catch {
38
+ return false;
39
+ }
40
+ const commands = [
41
+ ...recorded,
42
+ hookCommand(placement, name),
43
+ ...(placement.nodeEntrypoint ? [hookCommand(placementForEntrypoint(placement, `${name}.mjs`), name)] : []),
44
+ ];
45
+ const { [placement.configKey]: section, ...rest } = config;
46
+ if (Object.keys(rest).some((key) => key !== 'version'))
47
+ return false;
48
+ if (section === undefined)
49
+ return true;
50
+ if (!section || typeof section !== 'object' || Array.isArray(section))
51
+ return false;
52
+ return Object.values(section).every((groups) => Array.isArray(groups) &&
53
+ groups.every((group) => commands.some((command) => hookGroupOwnsCommand(group, command))));
54
+ }
55
+ /**
56
+ * The absolute path a hook whose `entrypoint` is the tool's own hook JSON is placed at, when the
57
+ * adapter's hook `placement` writes a script version's hook file there too (Copilot CLI's
58
+ * `.github/hooks/{name}.json`), or undefined for any other hook or placement.
59
+ */
60
+ export function jsonHookFilePath(placement, entrypoint, name, projectDir) {
61
+ const template = placement?.jsonEntrypoint?.path;
62
+ if (!template || !placement.configHookMerge || placement.configFile !== template || !entrypoint?.endsWith('.json')) {
63
+ return undefined;
64
+ }
65
+ return fromRoot(projectDir, template.replace(/\{name\}/g, name));
66
+ }
17
67
  /**
18
68
  * True when the file exists but the current user cannot execute it. Always false on
19
69
  * Windows, which has no exec bit, and for a missing file (checksum checks report that).
@@ -31,6 +81,27 @@ export async function lacksExecBit(filePath, platform = process.platform) {
31
81
  return true;
32
82
  }
33
83
  }
84
+ /**
85
+ * The scripts the adapter's hook `placement` places for hook `name` (`{name}.sh`, and `{name}.mjs`
86
+ * for an ES module) that hold a file of the hook: the bytes of a file the given entries of the asset
87
+ * recorded or, with `published`, of a file a published version of it shipped. Under a version whose
88
+ * entrypoint is the tool's own hook JSON, those that version doesn't place itself beside the JSON
89
+ * are what a script version left (ATK-818); the caller leaves out the ones it places. Anything else
90
+ * at those paths stays. Absolute paths.
91
+ */
92
+ export async function leftoverHookScripts(placement, name, installed, projectDir, published) {
93
+ if (!placement?.configHookMerge)
94
+ return [];
95
+ const leftovers = [];
96
+ for (const template of [placement.path, placement.nodeEntrypoint?.path]) {
97
+ const path = template && fromRoot(projectDir, template.replace(/\{name\}/g, name));
98
+ if (!path || !existsSync(path))
99
+ continue;
100
+ if (await holdsHookFile(await readFile(path), installed, published))
101
+ leftovers.push(path);
102
+ }
103
+ return leftovers;
104
+ }
34
105
  /**
35
106
  * Add an exec bit wherever the file has a read bit, like `chmod +x` under the user's
36
107
  * umask: 644 becomes 755 and 600 becomes 700. The registry stores scripts as 644 and the
@@ -45,4 +116,50 @@ export async function makeExecutable(filePath, platform = process.platform) {
45
116
  await chmod(filePath, executable);
46
117
  }
47
118
  }
119
+ /**
120
+ * The absolute path of a file of the hook at the path of its own config file (Copilot CLI's
121
+ * `.github/hooks/{name}.json`), which the hook file is written to in its place, or undefined when
122
+ * there is none:
123
+ * - the copy of the hook's script that a CLI before ATK-204 saved there, which the tool can't read
124
+ * as config: it holds the bytes of a file the given entries of the asset recorded, or is a script
125
+ * (`#!`), which no config file starts with (the lockfile may already record a newer version);
126
+ * - with `json`, the hook's own JSON, which a version whose entrypoint it is placed there as it is
127
+ * (ATK-818): it holds the bytes of a recorded file or of a file a published version shipped,
128
+ * since a sync over a lockfile a teammate's update wrote has no record of it. ATK's own hook file,
129
+ * by its current commands or the ones `json.recorded` names, is not one, and neither is config
130
+ * with anything else in it: the hook's entries are merged into both.
131
+ * `placement` is the adapter's hook placement, not one resolved for an entrypoint.
132
+ */
133
+ export async function misplacedHookCopy(placement, name, installed, projectDir, json) {
134
+ if (!placement?.configHookMerge || !placement.configFile?.includes('{name}'))
135
+ return undefined;
136
+ const path = fromRoot(projectDir, placement.configFile.replace(/\{name\}/g, name));
137
+ if (!existsSync(path))
138
+ return undefined;
139
+ const content = await readFile(path);
140
+ try {
141
+ await readConfigFile(path, resolveConfigFormat(path, placement));
142
+ }
143
+ catch {
144
+ // Not config: maybe the misplaced copy of the script.
145
+ if (!installed.some(Boolean))
146
+ return undefined;
147
+ return (await holdsHookFile(content, installed)) || content.subarray(0, 2).toString() === '#!' ? path : undefined;
148
+ }
149
+ if (!json)
150
+ return undefined;
151
+ if (await holdsHookFile(content, installed))
152
+ return path;
153
+ // ATK's own hook file needs no published check.
154
+ if (await isGeneratedHookFile(placement, name, path, json.recorded))
155
+ return undefined;
156
+ return (await json.published(content)) ? path : undefined;
157
+ }
158
+ /** Whether `content` is a file one of `installed` recorded or, with `published`, a published one. */
159
+ async function holdsHookFile(content, installed, published) {
160
+ const checksum = hashBytes(content);
161
+ if (installed.some((entry) => entry?.files.some((f) => f.checksum === checksum)))
162
+ return true;
163
+ return published ? published(content) : false;
164
+ }
48
165
  //# sourceMappingURL=hook-script.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hook-script.js","sourceRoot":"","sources":["../../src/lib/hook-script.ts"],"names":[],"mappings":"AA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