harness-config-manager 0.1.0

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 (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1547 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +584 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/commands/config.d.ts +7 -0
  7. package/dist/commands/config.js +49 -0
  8. package/dist/commands/config.js.map +1 -0
  9. package/dist/commands/context.d.ts +24 -0
  10. package/dist/commands/context.js +329 -0
  11. package/dist/commands/context.js.map +1 -0
  12. package/dist/commands/export.d.ts +19 -0
  13. package/dist/commands/export.js +116 -0
  14. package/dist/commands/export.js.map +1 -0
  15. package/dist/commands/import.d.ts +33 -0
  16. package/dist/commands/import.js +81 -0
  17. package/dist/commands/import.js.map +1 -0
  18. package/dist/commands/info.d.ts +19 -0
  19. package/dist/commands/info.js +235 -0
  20. package/dist/commands/info.js.map +1 -0
  21. package/dist/commands/init.d.ts +5 -0
  22. package/dist/commands/init.js +116 -0
  23. package/dist/commands/init.js.map +1 -0
  24. package/dist/commands/install.d.ts +119 -0
  25. package/dist/commands/install.js +533 -0
  26. package/dist/commands/install.js.map +1 -0
  27. package/dist/commands/list.d.ts +9 -0
  28. package/dist/commands/list.js +102 -0
  29. package/dist/commands/list.js.map +1 -0
  30. package/dist/commands/params.d.ts +58 -0
  31. package/dist/commands/params.js +366 -0
  32. package/dist/commands/params.js.map +1 -0
  33. package/dist/commands/refs.d.ts +60 -0
  34. package/dist/commands/refs.js +329 -0
  35. package/dist/commands/refs.js.map +1 -0
  36. package/dist/commands/registry.d.ts +18 -0
  37. package/dist/commands/registry.js +173 -0
  38. package/dist/commands/registry.js.map +1 -0
  39. package/dist/commands/status.d.ts +10 -0
  40. package/dist/commands/status.js +83 -0
  41. package/dist/commands/status.js.map +1 -0
  42. package/dist/commands/targets.d.ts +8 -0
  43. package/dist/commands/targets.js +61 -0
  44. package/dist/commands/targets.js.map +1 -0
  45. package/dist/commands/uninstall.d.ts +71 -0
  46. package/dist/commands/uninstall.js +322 -0
  47. package/dist/commands/uninstall.js.map +1 -0
  48. package/dist/commands/update.d.ts +66 -0
  49. package/dist/commands/update.js +384 -0
  50. package/dist/commands/update.js.map +1 -0
  51. package/dist/commands/validate.d.ts +3 -0
  52. package/dist/commands/validate.js +38 -0
  53. package/dist/commands/validate.js.map +1 -0
  54. package/dist/core/bundle.d.ts +49 -0
  55. package/dist/core/bundle.js +326 -0
  56. package/dist/core/bundle.js.map +1 -0
  57. package/dist/core/config.d.ts +65 -0
  58. package/dist/core/config.js +112 -0
  59. package/dist/core/config.js.map +1 -0
  60. package/dist/core/conflicts.d.ts +67 -0
  61. package/dist/core/conflicts.js +300 -0
  62. package/dist/core/conflicts.js.map +1 -0
  63. package/dist/core/context.d.ts +139 -0
  64. package/dist/core/context.js +432 -0
  65. package/dist/core/context.js.map +1 -0
  66. package/dist/core/deps.d.ts +62 -0
  67. package/dist/core/deps.js +339 -0
  68. package/dist/core/deps.js.map +1 -0
  69. package/dist/core/errors.d.ts +21 -0
  70. package/dist/core/errors.js +26 -0
  71. package/dist/core/errors.js.map +1 -0
  72. package/dist/core/executor.d.ts +9 -0
  73. package/dist/core/executor.js +139 -0
  74. package/dist/core/executor.js.map +1 -0
  75. package/dist/core/flavors.d.ts +128 -0
  76. package/dist/core/flavors.js +386 -0
  77. package/dist/core/flavors.js.map +1 -0
  78. package/dist/core/frontmatter.d.ts +6 -0
  79. package/dist/core/frontmatter.js +20 -0
  80. package/dist/core/frontmatter.js.map +1 -0
  81. package/dist/core/fsx.d.ts +40 -0
  82. package/dist/core/fsx.js +180 -0
  83. package/dist/core/fsx.js.map +1 -0
  84. package/dist/core/github.d.ts +37 -0
  85. package/dist/core/github.js +157 -0
  86. package/dist/core/github.js.map +1 -0
  87. package/dist/core/harnesses.d.ts +142 -0
  88. package/dist/core/harnesses.js +215 -0
  89. package/dist/core/harnesses.js.map +1 -0
  90. package/dist/core/hash.d.ts +12 -0
  91. package/dist/core/hash.js +34 -0
  92. package/dist/core/hash.js.map +1 -0
  93. package/dist/core/logger.d.ts +16 -0
  94. package/dist/core/logger.js +36 -0
  95. package/dist/core/logger.js.map +1 -0
  96. package/dist/core/overlap.d.ts +79 -0
  97. package/dist/core/overlap.js +155 -0
  98. package/dist/core/overlap.js.map +1 -0
  99. package/dist/core/parameters.d.ts +249 -0
  100. package/dist/core/parameters.js +944 -0
  101. package/dist/core/parameters.js.map +1 -0
  102. package/dist/core/paths.d.ts +20 -0
  103. package/dist/core/paths.js +35 -0
  104. package/dist/core/paths.js.map +1 -0
  105. package/dist/core/planner.d.ts +36 -0
  106. package/dist/core/planner.js +364 -0
  107. package/dist/core/planner.js.map +1 -0
  108. package/dist/core/prompt.d.ts +52 -0
  109. package/dist/core/prompt.js +197 -0
  110. package/dist/core/prompt.js.map +1 -0
  111. package/dist/core/refmap.d.ts +91 -0
  112. package/dist/core/refmap.js +331 -0
  113. package/dist/core/refmap.js.map +1 -0
  114. package/dist/core/refs.d.ts +297 -0
  115. package/dist/core/refs.js +801 -0
  116. package/dist/core/refs.js.map +1 -0
  117. package/dist/core/registry.d.ts +119 -0
  118. package/dist/core/registry.js +363 -0
  119. package/dist/core/registry.js.map +1 -0
  120. package/dist/core/rename.d.ts +36 -0
  121. package/dist/core/rename.js +74 -0
  122. package/dist/core/rename.js.map +1 -0
  123. package/dist/core/rollback.d.ts +38 -0
  124. package/dist/core/rollback.js +226 -0
  125. package/dist/core/rollback.js.map +1 -0
  126. package/dist/core/semver.d.ts +56 -0
  127. package/dist/core/semver.js +214 -0
  128. package/dist/core/semver.js.map +1 -0
  129. package/dist/core/state.d.ts +99 -0
  130. package/dist/core/state.js +196 -0
  131. package/dist/core/state.js.map +1 -0
  132. package/dist/core/store.d.ts +30 -0
  133. package/dist/core/store.js +54 -0
  134. package/dist/core/store.js.map +1 -0
  135. package/dist/core/types.d.ts +515 -0
  136. package/dist/core/types.js +49 -0
  137. package/dist/core/types.js.map +1 -0
  138. package/dist/index.d.ts +16 -0
  139. package/dist/index.js +16 -0
  140. package/dist/index.js.map +1 -0
  141. package/dist/merge/blocks.d.ts +48 -0
  142. package/dist/merge/blocks.js +0 -0
  143. package/dist/merge/blocks.js.map +1 -0
  144. package/dist/merge/json-merge.d.ts +66 -0
  145. package/dist/merge/json-merge.js +176 -0
  146. package/dist/merge/json-merge.js.map +1 -0
  147. package/dist/merge/toml.d.ts +48 -0
  148. package/dist/merge/toml.js +118 -0
  149. package/dist/merge/toml.js.map +1 -0
  150. package/dist/targets/claude-code.d.ts +11 -0
  151. package/dist/targets/claude-code.js +94 -0
  152. package/dist/targets/claude-code.js.map +1 -0
  153. package/dist/targets/copilot.d.ts +13 -0
  154. package/dist/targets/copilot.js +126 -0
  155. package/dist/targets/copilot.js.map +1 -0
  156. package/dist/targets/index.d.ts +20 -0
  157. package/dist/targets/index.js +60 -0
  158. package/dist/targets/index.js.map +1 -0
  159. package/dist/targets/opencode.d.ts +32 -0
  160. package/dist/targets/opencode.js +172 -0
  161. package/dist/targets/opencode.js.map +1 -0
  162. package/dist/targets/pi.d.ts +42 -0
  163. package/dist/targets/pi.js +134 -0
  164. package/dist/targets/pi.js.map +1 -0
  165. package/dist/targets/reasonix.d.ts +27 -0
  166. package/dist/targets/reasonix.js +192 -0
  167. package/dist/targets/reasonix.js.map +1 -0
  168. package/dist/targets/shared.d.ts +33 -0
  169. package/dist/targets/shared.js +109 -0
  170. package/dist/targets/shared.js.map +1 -0
  171. package/dist/targets/types.d.ts +40 -0
  172. package/dist/targets/types.js +17 -0
  173. package/dist/targets/types.js.map +1 -0
  174. package/docs/authoring-bundles.md +828 -0
  175. package/package.json +74 -0
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Which harnesses is this folder actually used by, and does a command have to
3
+ * say which one it means?
4
+ *
5
+ * A project folder is not one harness's. The same directory can hold
6
+ * `.claude/`, `.reasonix/` and `.pi/` side by side, because the person working
7
+ * in it uses all three. Everything hcm records is already per-target -- an
8
+ * installation is keyed `bundle@target@scope` -- but the *commands* used to
9
+ * assume otherwise: `hcm install my-kit` with no `-t` meant all five harnesses,
10
+ * and `hcm uninstall my-kit` meant every one it could find.
11
+ *
12
+ * That default is fine in a folder set up for one harness and wrong in a folder
13
+ * set up for three, where it silently touches harnesses the user was not
14
+ * thinking about. So: work out which harnesses are here, and when an operation
15
+ * would span more than one of them, make the user say which.
16
+ *
17
+ * Presence is read from two places, because either alone is incomplete:
18
+ *
19
+ * markers directories and files only that harness uses (`core/targets`
20
+ * declares them). This is what finds a harness hcm never installed
21
+ * into -- the usual case, since people set their harnesses up first.
22
+ * ledger what hcm has installed here. This is what finds a harness whose
23
+ * own files have not been created yet.
24
+ */
25
+ import { resolveRequireTarget } from './config.js';
26
+ import { HcmError } from './errors.js';
27
+ import { fromPosix, pathExists } from './fsx.js';
28
+ import { isInteractive, multiSelect } from './prompt.js';
29
+ import { readState } from './state.js';
30
+ import { getTarget, resolveTargetId, TARGET_IDS, TARGETS } from '../targets/index.js';
31
+ /** The word `-t` accepts for "every harness", the explicit form of the old default. */
32
+ export const ALL_TARGETS = 'all';
33
+ /**
34
+ * The harnesses in use at `scope`, in the order `hcm targets` lists them.
35
+ *
36
+ * Only a harness with real evidence is included -- an empty project has none,
37
+ * which is what keeps the ambiguity gate below quiet in a fresh checkout.
38
+ */
39
+ export async function detectHarnesses(scope, cwd) {
40
+ const state = await readState(scope, cwd);
41
+ const installed = new Set(state.installations.map((record) => record.target));
42
+ const found = [];
43
+ for (const target of TARGETS) {
44
+ const root = target.scopeRoot(scope, cwd);
45
+ const markers = [];
46
+ for (const marker of target.markers(scope)) {
47
+ // `.` is the scope root itself: for a harness whose user-scope root is
48
+ // its own config directory, the directory existing *is* the evidence.
49
+ const candidate = marker === '.' ? root : fromPosix(root, marker);
50
+ if (await pathExists(candidate))
51
+ markers.push(marker);
52
+ }
53
+ if (markers.length === 0 && !installed.has(target.id))
54
+ continue;
55
+ found.push({ target: target.id, root, markers, installed: installed.has(target.id) });
56
+ }
57
+ return found;
58
+ }
59
+ /** "Claude Code, Pi and Reasonix" -- for messages about what was found. */
60
+ export function describeHarnesses(found) {
61
+ const titles = found.map((harness) => getTarget(harness.target).title);
62
+ if (titles.length <= 1)
63
+ return titles.join('');
64
+ return `${titles.slice(0, -1).join(', ')} and ${titles[titles.length - 1]}`;
65
+ }
66
+ /** Why hcm thinks a harness is here, for `hcm targets` and `hcm status`. */
67
+ export function describeEvidence(harness) {
68
+ const parts = [
69
+ // `.` is the root itself, which is only informative spelled out.
70
+ ...harness.markers.map((marker) => (marker === '.' ? harness.root : marker)),
71
+ ...(harness.installed ? ['installed by hcm'] : []),
72
+ ];
73
+ return parts.join(', ');
74
+ }
75
+ // ---------------------------------------------------------------------------
76
+ // Expanding what `-t` was given
77
+ // ---------------------------------------------------------------------------
78
+ /**
79
+ * Turn the raw `-t` values into target ids: several harnesses at once, each
80
+ * named by id, alias or unambiguous prefix, with `all` meaning every one.
81
+ *
82
+ * -t pi -> [pi]
83
+ * -t claude pi -> [claude-code, pi]
84
+ * -t all -> every harness
85
+ *
86
+ * `all` is how you ask for the blanket behaviour once the gate below starts
87
+ * asking: it means the same thing as naming every harness, and it is recorded
88
+ * as an answer rather than an absence of one.
89
+ *
90
+ * Duplicates are dropped rather than refused -- `-t pi -t pi` and `-t claude
91
+ * claude-code` are the same request said twice, and installing twice into one
92
+ * harness is not a thing anybody means.
93
+ */
94
+ export function expandTargets(values) {
95
+ if (!values || values.length === 0)
96
+ return undefined;
97
+ if (values.includes(ALL_TARGETS))
98
+ return [...TARGET_IDS];
99
+ // resolveTargetId rejects anything unknown, which is what makes this the one
100
+ // place a target name has to be validated.
101
+ return [...new Set(values.map((value) => resolveTargetId(value)))];
102
+ }
103
+ /**
104
+ * The harnesses this folder is already committed to, in `available` order.
105
+ *
106
+ * The ledger first: a harness hcm has installed into here is one the user has
107
+ * decided about, and re-running `hcm install` almost always means "the same
108
+ * places as last time". Only when nothing has been installed yet does harness
109
+ * *presence* stand in for it -- a folder with a `.claude/` directory and an
110
+ * empty ledger is a Claude Code folder, whoever created that directory.
111
+ */
112
+ export async function initializedTargets(scope, cwd, available) {
113
+ const offered = new Set(available);
114
+ const state = await readState(scope, cwd);
115
+ const installed = new Set(state.installations.map((record) => record.target).filter((id) => offered.has(id)));
116
+ if (installed.size > 0)
117
+ return available.filter((id) => installed.has(id));
118
+ const found = await detectHarnesses(scope, cwd);
119
+ const present = new Set(found.map((harness) => harness.target));
120
+ return available.filter((id) => present.has(id));
121
+ }
122
+ /**
123
+ * Settle which harnesses to install into when `-t` did not say.
124
+ *
125
+ * The old answer was "every one of them", which is right in a folder that uses
126
+ * one harness and wrong in a folder that uses three -- and `requireTargetChoice`
127
+ * could only refuse the command, which is a poor thing to do to someone who is
128
+ * sitting at a terminal and can simply be asked. So ask, with what the folder
129
+ * is already set up for ticked.
130
+ *
131
+ * Returns undefined when there was no question to ask -- one harness on offer,
132
+ * no terminal, `--no-prompt` -- and the caller carries on with the behaviour it
133
+ * had before, `requireTargetChoice` gate included.
134
+ */
135
+ export async function chooseTargets(options) {
136
+ const available = [...options.available];
137
+ if (available.length < 2)
138
+ return undefined;
139
+ // Checked before the chooser rather than alongside it: --no-prompt means no
140
+ // question is asked, whoever would have answered it.
141
+ if (options.prompt === false)
142
+ return undefined;
143
+ const chooser = options.chooser ?? (isInteractive() ? promptForTargets : undefined);
144
+ if (!chooser)
145
+ return undefined;
146
+ const here = await initializedTargets(options.scope, options.cwd, available);
147
+ const picked = await chooser({
148
+ available,
149
+ // A folder that is set up for nothing yet has no answer to give, so the
150
+ // menu opens on the historical default -- every harness -- ticked and
151
+ // visible rather than applied behind the user's back.
152
+ preselected: here.length > 0 ? here : available,
153
+ here,
154
+ });
155
+ // An empty answer is not a narrowing to nothing; it means the question did
156
+ // not settle anything, and the caller's own default stands.
157
+ return picked.length > 0 ? [...new Set(picked)] : undefined;
158
+ }
159
+ /** The terminal's answer: a ticked menu of the harnesses on offer. */
160
+ export const promptForTargets = (question) => multiSelect('Which harness(es) should this install into?', question.available.map((id) => ({
161
+ value: id,
162
+ label: getTarget(id).title,
163
+ ...(question.here.includes(id) ? { detail: 'already set up in this folder' } : {}),
164
+ })), question.preselected);
165
+ /**
166
+ * Refuse an operation that would silently span harnesses the user did not name.
167
+ *
168
+ * Deliberately narrow, so it never gets in the way of an unambiguous command:
169
+ * it fires only when the folder is set up for more than one harness *and* this
170
+ * particular operation would affect more than one. Uninstalling a bundle that
171
+ * only ever went into Claude Code needs no `-t` however many harnesses are
172
+ * configured alongside it.
173
+ *
174
+ * Returns the harnesses found, so callers can go on to report the file overlaps
175
+ * between them without detecting twice.
176
+ */
177
+ export async function requireTargetChoice(choice) {
178
+ const found = await detectHarnesses(choice.scope, choice.cwd);
179
+ if (choice.chosen && choice.chosen.length > 0)
180
+ return found;
181
+ const policy = await resolveRequireTarget();
182
+ if (policy === 'never')
183
+ return found;
184
+ if (policy === 'auto' && found.length < 2)
185
+ return found;
186
+ if (choice.affected.length < 2)
187
+ return found;
188
+ const affected = choice.affected.join(', ');
189
+ const first = choice.affected[0];
190
+ throw new HcmError(found.length > 1
191
+ ? `This folder is set up for more than one harness (${describeHarnesses(found)}), ` +
192
+ `so "${choice.command}" needs to be told which one to act on`
193
+ : `"${choice.command}" would affect ${choice.affected.length} harnesses and ` +
194
+ 'requireTarget is set to "always"', [
195
+ `It would otherwise affect: ${affected}`,
196
+ `Name one or more: ${choice.command} -t ${first}`,
197
+ `Or every harness: ${choice.command} -t ${ALL_TARGETS}`,
198
+ ].join('\n'));
199
+ }
200
+ /**
201
+ * Installing into every harness in a folder that only uses one is not ambiguous
202
+ * -- there is nothing to ask -- but it is almost certainly not what was meant,
203
+ * so say what is about to happen rather than refusing it.
204
+ */
205
+ export function warnIfWiderThanTheFolder(found, chosen, affected, command, warn) {
206
+ if (chosen && chosen.length > 0)
207
+ return;
208
+ if (found.length !== 1 || affected.length < 2)
209
+ return;
210
+ const only = found[0];
211
+ const title = getTarget(only.target).title;
212
+ warn(`installing into ${affected.length} harnesses; only ${title} is set up in this folder ` +
213
+ `-- "${command} -t ${only.target}" installs just there`);
214
+ }
215
+ //# sourceMappingURL=harnesses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harnesses.js","sourceRoot":"","sources":["../../src/core/harnesses.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEtF,uFAAuF;AACvF,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC;AAYjC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,KAAY,EAAE,GAAW;IAC7D,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAE9E,MAAM,KAAK,GAAsB,EAAE,CAAC;IAEpC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC1C,MAAM,OAAO,GAAa,EAAE,CAAC;QAE7B,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,CAA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@
1
+ /** sha256 of arbitrary bytes or text, hex encoded. */
2
+ export declare function sha256(input: string | Buffer): string;
3
+ /**
4
+ * Deterministic JSON serialisation: object keys sorted at every level so that
5
+ * a value hashes identically no matter how the host file was formatted or
6
+ * reordered. This is what makes "is this still the value we wrote?" reliable.
7
+ */
8
+ export declare function canonicalJson(value: unknown): string;
9
+ /** sha256 of the canonical JSON form of a value. */
10
+ export declare function hashValue(value: unknown): string;
11
+ /** Structural equality via canonical JSON. */
12
+ export declare function valuesEqual(a: unknown, b: unknown): boolean;
@@ -0,0 +1,34 @@
1
+ import { createHash } from 'node:crypto';
2
+ /** sha256 of arbitrary bytes or text, hex encoded. */
3
+ export function sha256(input) {
4
+ return createHash('sha256').update(input).digest('hex');
5
+ }
6
+ /**
7
+ * Deterministic JSON serialisation: object keys sorted at every level so that
8
+ * a value hashes identically no matter how the host file was formatted or
9
+ * reordered. This is what makes "is this still the value we wrote?" reliable.
10
+ */
11
+ export function canonicalJson(value) {
12
+ return JSON.stringify(sortValue(value));
13
+ }
14
+ function sortValue(value) {
15
+ if (Array.isArray(value))
16
+ return value.map(sortValue);
17
+ if (value && typeof value === 'object') {
18
+ const source = value;
19
+ const out = {};
20
+ for (const key of Object.keys(source).sort())
21
+ out[key] = sortValue(source[key]);
22
+ return out;
23
+ }
24
+ return value;
25
+ }
26
+ /** sha256 of the canonical JSON form of a value. */
27
+ export function hashValue(value) {
28
+ return sha256(canonicalJson(value));
29
+ }
30
+ /** Structural equality via canonical JSON. */
31
+ export function valuesEqual(a, b) {
32
+ return canonicalJson(a) === canonicalJson(b);
33
+ }
34
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/core/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,sDAAsD;AACtD,MAAM,UAAU,MAAM,CAAC,KAAsB;IAC3C,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACtD,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,KAAgC,CAAC;QAChD,MAAM,GAAG,GAA4B,EAAE,CAAC;QACxC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAChF,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,WAAW,CAAC,CAAU,EAAE,CAAU;IAChD,OAAO,aAAa,CAAC,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,16 @@
1
+ export declare function configureLogger(options: {
2
+ quiet?: boolean;
3
+ verbose?: boolean;
4
+ }): void;
5
+ export declare const log: {
6
+ info(message: string): void;
7
+ step(message: string): void;
8
+ success(message: string): void;
9
+ warn(message: string): void;
10
+ error(message: string): void;
11
+ debug(message: string): void;
12
+ plain(message: string): void;
13
+ };
14
+ export declare const color: import("picocolors/types.js").Colors & {
15
+ createColors: (enabled?: boolean) => import("picocolors/types.js").Colors;
16
+ };
@@ -0,0 +1,36 @@
1
+ import pc from 'picocolors';
2
+ let quiet = false;
3
+ let verbose = false;
4
+ export function configureLogger(options) {
5
+ quiet = options.quiet ?? false;
6
+ verbose = options.verbose ?? false;
7
+ }
8
+ export const log = {
9
+ info(message) {
10
+ if (!quiet)
11
+ console.log(message);
12
+ },
13
+ step(message) {
14
+ if (!quiet)
15
+ console.log(`${pc.cyan('•')} ${message}`);
16
+ },
17
+ success(message) {
18
+ if (!quiet)
19
+ console.log(`${pc.green('✔')} ${message}`);
20
+ },
21
+ warn(message) {
22
+ console.warn(`${pc.yellow('!')} ${message}`);
23
+ },
24
+ error(message) {
25
+ console.error(`${pc.red('✖')} ${message}`);
26
+ },
27
+ debug(message) {
28
+ if (verbose && !quiet)
29
+ console.log(pc.dim(` ${message}`));
30
+ },
31
+ plain(message) {
32
+ console.log(message);
33
+ },
34
+ };
35
+ export const color = pc;
36
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,IAAI,KAAK,GAAG,KAAK,CAAC;AAClB,IAAI,OAAO,GAAG,KAAK,CAAC;AAEpB,MAAM,UAAU,eAAe,CAAC,OAA+C;IAC7E,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;IAC/B,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC;AACrC,CAAC;AAED,MAAM,CAAC,MAAM,GAAG,GAAG;IACjB,IAAI,CAAC,OAAe;QAClB,IAAI,CAAC,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IACD,IAAI,CAAC,OAAe;QAClB,IAAI,CAAC,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,CAAC,OAAe;QACrB,IAAI,CAAC,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC;IACzD,CAAC;IACD,IAAI,CAAC,OAAe;QAClB,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,KAAK,CAAC,OAAe;QACnB,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC;IAC7C,CAAC;IACD,KAAK,CAAC,OAAe;QACnB,IAAI,OAAO,IAAI,CAAC,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;IACD,KAAK,CAAC,OAAe;QACnB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Files two harnesses both read.
3
+ *
4
+ * Most of what hcm writes belongs to exactly one harness: `.claude/agents/` is
5
+ * Claude Code's and nobody else's, so installing there and uninstalling there
6
+ * are complete operations. Two files are not like that:
7
+ *
8
+ * .mcp.json Claude Code and Pi both read `mcpServers.<name>`
9
+ * AGENTS.md OpenCode and Pi both read the whole file
10
+ *
11
+ * hcm's own bookkeeping copes with this already -- claims are keyed by absolute
12
+ * path (`core/state.ts`), so an item is written once and claimed by every
13
+ * installation that wanted it, and it survives until the last claim goes. What
14
+ * the bookkeeping cannot do is make the *harnesses* behave as if the file were
15
+ * per-harness, and that is where the surprise lives:
16
+ *
17
+ * hcm uninstall my-kit -t reasonix leaves .mcp.json alone if Claude Code
18
+ * still claims the server -- and Pi,
19
+ * reading the same file, still has it
20
+ * hcm install my-kit -t claude-code writes a server Pi can also see, in a
21
+ * folder where Pi is set up
22
+ *
23
+ * Neither is a bug: it is what "one file, two readers" means. But it is not
24
+ * what "-t" suggests, so it is worth saying out loud.
25
+ *
26
+ * The overlaps are computed rather than listed. Each target is asked what it
27
+ * would write for a probe resource of each kind it supports, and paths that
28
+ * land in the same place for two targets are shared by construction -- so a new
29
+ * adapter, or a change to an existing one, is accounted for without anybody
30
+ * remembering to update a table here.
31
+ */
32
+ import type { ResourceKind, Scope, TargetId, TargetOptions } from './types.js';
33
+ /** One file, and the harnesses that write to it at a given scope. */
34
+ export interface SharedFile {
35
+ /** Absolute path, lower-cased -- the same key `core/state.ts` claims by. */
36
+ key: string;
37
+ /** How each harness spells the path, relative to its own scope root. */
38
+ readers: {
39
+ target: TargetId;
40
+ path: string;
41
+ kinds: ResourceKind[];
42
+ }[];
43
+ }
44
+ /**
45
+ * A path this run is about to touch that another harness also reads.
46
+ * `others` is only ever harnesses actually set up in the folder: a warning
47
+ * about Pi in a project with no Pi in it would be noise.
48
+ */
49
+ export interface SharedFileNotice {
50
+ /** The path as the acting harness spells it. */
51
+ path: string;
52
+ others: TargetId[];
53
+ }
54
+ /**
55
+ * Files written by more than one of `targets` at this scope.
56
+ *
57
+ * Note this is a question about *harnesses*, not about bundles: two harnesses
58
+ * whose layouts happen to collide share the file whatever is installed in it.
59
+ */
60
+ export declare function sharedFiles(targets: readonly TargetId[], scope: Scope, cwd: string, options?: TargetOptions): SharedFile[];
61
+ /**
62
+ * The shared-file warnings for one harness's writes.
63
+ *
64
+ * `paths` are as that harness spells them -- plan action paths, or receipt
65
+ * paths, both of which are relative to its own scope root.
66
+ */
67
+ export declare function sharedFileNotices(params: {
68
+ target: TargetId;
69
+ paths: readonly string[];
70
+ scope: Scope;
71
+ cwd: string;
72
+ /** Harnesses set up in this folder. Anything else is not worth mentioning. */
73
+ present: readonly TargetId[];
74
+ options?: TargetOptions;
75
+ }): SharedFileNotice[];
76
+ /** "Pi", or "Pi and OpenCode" -- the harnesses on the other side of a file. */
77
+ export declare function describeReaders(targets: readonly TargetId[]): string;
78
+ /** Every overlap that exists at a scope, for `hcm targets`. */
79
+ export declare function allSharedFiles(scope: Scope, cwd: string): SharedFile[];
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Files two harnesses both read.
3
+ *
4
+ * Most of what hcm writes belongs to exactly one harness: `.claude/agents/` is
5
+ * Claude Code's and nobody else's, so installing there and uninstalling there
6
+ * are complete operations. Two files are not like that:
7
+ *
8
+ * .mcp.json Claude Code and Pi both read `mcpServers.<name>`
9
+ * AGENTS.md OpenCode and Pi both read the whole file
10
+ *
11
+ * hcm's own bookkeeping copes with this already -- claims are keyed by absolute
12
+ * path (`core/state.ts`), so an item is written once and claimed by every
13
+ * installation that wanted it, and it survives until the last claim goes. What
14
+ * the bookkeeping cannot do is make the *harnesses* behave as if the file were
15
+ * per-harness, and that is where the surprise lives:
16
+ *
17
+ * hcm uninstall my-kit -t reasonix leaves .mcp.json alone if Claude Code
18
+ * still claims the server -- and Pi,
19
+ * reading the same file, still has it
20
+ * hcm install my-kit -t claude-code writes a server Pi can also see, in a
21
+ * folder where Pi is set up
22
+ *
23
+ * Neither is a bug: it is what "one file, two readers" means. But it is not
24
+ * what "-t" suggests, so it is worth saying out loud.
25
+ *
26
+ * The overlaps are computed rather than listed. Each target is asked what it
27
+ * would write for a probe resource of each kind it supports, and paths that
28
+ * land in the same place for two targets are shared by construction -- so a new
29
+ * adapter, or a change to an existing one, is accounted for without anybody
30
+ * remembering to update a table here.
31
+ */
32
+ import { fromPosix } from './fsx.js';
33
+ import { getTarget, TARGET_IDS } from '../targets/index.js';
34
+ /** The name every probe resource carries, so a stray one is recognisable. */
35
+ const PROBE = 'hcm-probe';
36
+ /**
37
+ * Files written by more than one of `targets` at this scope.
38
+ *
39
+ * Note this is a question about *harnesses*, not about bundles: two harnesses
40
+ * whose layouts happen to collide share the file whatever is installed in it.
41
+ */
42
+ export function sharedFiles(targets, scope, cwd, options = {}) {
43
+ const byKey = new Map();
44
+ for (const id of targets) {
45
+ const target = getTarget(id);
46
+ const root = target.scopeRoot(scope, cwd);
47
+ for (const [path, kinds] of writtenPaths(id, scope, options)) {
48
+ const key = fromPosix(root, path).toLowerCase();
49
+ const entry = byKey.get(key) ?? { key, readers: [] };
50
+ entry.readers.push({ target: id, path, kinds });
51
+ byKey.set(key, entry);
52
+ }
53
+ }
54
+ return [...byKey.values()].filter((file) => new Set(file.readers.map((reader) => reader.target)).size > 1);
55
+ }
56
+ /**
57
+ * Which paths one target writes, and for which kinds.
58
+ *
59
+ * Probing with a fixed name is enough because the question is whether two
60
+ * layouts collide, and a layout that collides for one name collides for all of
61
+ * them: `.mcp.json` is `.mcp.json` whatever the server is called, and
62
+ * `.claude/agents/<n>.md` can never be `.pi/skills/<n>/SKILL.md`.
63
+ */
64
+ function writtenPaths(id, scope, options) {
65
+ const target = getTarget(id);
66
+ const paths = new Map();
67
+ for (const kind of target.supports) {
68
+ const resource = probeResource(kind);
69
+ if (!resource)
70
+ continue;
71
+ for (const action of target.actions(resource, { bundle: PROBE, scope, options })) {
72
+ const kinds = paths.get(action.path) ?? [];
73
+ if (!kinds.includes(kind))
74
+ kinds.push(kind);
75
+ paths.set(action.path, kinds);
76
+ }
77
+ }
78
+ return paths;
79
+ }
80
+ /**
81
+ * A resource that exists only to be asked "where would you go?".
82
+ *
83
+ * Assets are left out: mapping one reads the file it ships, and there is
84
+ * nothing to read here. They land in a per-harness directory in every target,
85
+ * so there is no overlap to miss.
86
+ */
87
+ function probeResource(kind) {
88
+ if (kind === 'asset')
89
+ return undefined;
90
+ const base = {
91
+ kind,
92
+ name: PROBE,
93
+ bundlePath: `${kind}/${PROBE}`,
94
+ primaryFile: '',
95
+ files: [],
96
+ frontmatter: { description: 'probe' },
97
+ body: '',
98
+ // Common, so no flavor selection can filter the probe out from under us.
99
+ flavors: [],
100
+ };
101
+ switch (kind) {
102
+ // Only SKILL.md, which is rendered rather than copied -- any other file
103
+ // would have to be read off disk.
104
+ case 'skill':
105
+ return { ...base, files: [{ absolutePath: '', relativePath: 'SKILL.md' }] };
106
+ case 'mcp':
107
+ return { ...base, data: { command: PROBE } };
108
+ // One leaf, so the settings mapping produces one write rather than none.
109
+ case 'settings':
110
+ return { ...base, data: { [PROBE]: true } };
111
+ default:
112
+ return base;
113
+ }
114
+ }
115
+ /**
116
+ * The shared-file warnings for one harness's writes.
117
+ *
118
+ * `paths` are as that harness spells them -- plan action paths, or receipt
119
+ * paths, both of which are relative to its own scope root.
120
+ */
121
+ export function sharedFileNotices(params) {
122
+ const others = params.present.filter((id) => id !== params.target);
123
+ if (others.length === 0)
124
+ return [];
125
+ const shared = sharedFiles([params.target, ...others], params.scope, params.cwd, params.options ?? {});
126
+ if (shared.length === 0)
127
+ return [];
128
+ const root = getTarget(params.target).scopeRoot(params.scope, params.cwd);
129
+ const notices = new Map();
130
+ for (const path of params.paths) {
131
+ const key = fromPosix(root, path).toLowerCase();
132
+ const file = shared.find((candidate) => candidate.key === key);
133
+ if (!file)
134
+ continue;
135
+ const readers = file.readers
136
+ .map((reader) => reader.target)
137
+ .filter((id) => id !== params.target);
138
+ if (readers.length === 0)
139
+ continue;
140
+ notices.set(path, { path, others: [...new Set(readers)] });
141
+ }
142
+ return [...notices.values()];
143
+ }
144
+ /** "Pi", or "Pi and OpenCode" -- the harnesses on the other side of a file. */
145
+ export function describeReaders(targets) {
146
+ const titles = targets.map((id) => getTarget(id).title);
147
+ if (titles.length <= 1)
148
+ return titles.join('');
149
+ return `${titles.slice(0, -1).join(', ')} and ${titles[titles.length - 1]}`;
150
+ }
151
+ /** Every overlap that exists at a scope, for `hcm targets`. */
152
+ export function allSharedFiles(scope, cwd) {
153
+ return sharedFiles(TARGET_IDS, scope, cwd);
154
+ }
155
+ //# sourceMappingURL=over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