harness-config-manager 0.1.0 → 0.1.4

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 (104) hide show
  1. package/README.md +422 -68
  2. package/builtin/hcm/README.md +23 -0
  3. package/builtin/hcm/context/10-hcm.md +14 -0
  4. package/builtin/hcm/hcm.yaml +16 -0
  5. package/builtin/hcm/skills/hcm-bundle-authoring/SKILL.md +119 -0
  6. package/builtin/hcm/skills/hcm-bundle-authoring/collections.md +168 -0
  7. package/builtin/hcm/skills/hcm-bundle-authoring/reference.md +222 -0
  8. package/builtin/hcm/skills/hcm-integration/SKILL.md +149 -0
  9. package/builtin/hcm/skills/hcm-integration/cli.md +139 -0
  10. package/builtin/hcm/skills/hcm-integration/examples.md +338 -0
  11. package/builtin/hcm/skills/hcm-integration/library.md +399 -0
  12. package/builtin/hcm/skills/hcm-integration/migrate.md +204 -0
  13. package/builtin/hcm/skills/hcm-integration/remote.md +204 -0
  14. package/builtin/hcm/skills/hcm-usage/SKILL.md +241 -0
  15. package/builtin/hcm/skills/hcm-usage/commands.md +76 -0
  16. package/dist/cli.js +61 -14
  17. package/dist/cli.js.map +1 -1
  18. package/dist/commands/export.d.ts +4 -2
  19. package/dist/commands/export.js +8 -9
  20. package/dist/commands/export.js.map +1 -1
  21. package/dist/commands/import.js +10 -1
  22. package/dist/commands/import.js.map +1 -1
  23. package/dist/commands/info.js +3 -3
  24. package/dist/commands/info.js.map +1 -1
  25. package/dist/commands/init.js +2 -1
  26. package/dist/commands/init.js.map +1 -1
  27. package/dist/commands/install.d.ts +25 -1
  28. package/dist/commands/install.js +118 -9
  29. package/dist/commands/install.js.map +1 -1
  30. package/dist/commands/list.d.ts +3 -1
  31. package/dist/commands/list.js +28 -5
  32. package/dist/commands/list.js.map +1 -1
  33. package/dist/commands/registry.d.ts +25 -0
  34. package/dist/commands/registry.js +134 -20
  35. package/dist/commands/registry.js.map +1 -1
  36. package/dist/commands/update.d.ts +31 -6
  37. package/dist/commands/update.js +294 -108
  38. package/dist/commands/update.js.map +1 -1
  39. package/dist/core/builtin.d.ts +33 -0
  40. package/dist/core/builtin.js +37 -0
  41. package/dist/core/builtin.js.map +1 -0
  42. package/dist/core/bundle.d.ts +20 -1
  43. package/dist/core/bundle.js +77 -4
  44. package/dist/core/bundle.js.map +1 -1
  45. package/dist/core/collection-clash.d.ts +82 -0
  46. package/dist/core/collection-clash.js +186 -0
  47. package/dist/core/collection-clash.js.map +1 -0
  48. package/dist/core/collection.d.ts +37 -0
  49. package/dist/core/collection.js +113 -0
  50. package/dist/core/collection.js.map +1 -0
  51. package/dist/core/config.d.ts +2 -2
  52. package/dist/core/config.js +1 -1
  53. package/dist/core/config.js.map +1 -1
  54. package/dist/core/conflicts.d.ts +39 -5
  55. package/dist/core/conflicts.js +169 -32
  56. package/dist/core/conflicts.js.map +1 -1
  57. package/dist/core/deps.d.ts +1 -1
  58. package/dist/core/deps.js +8 -8
  59. package/dist/core/deps.js.map +1 -1
  60. package/dist/core/errors.d.ts +2 -2
  61. package/dist/core/errors.js +1 -1
  62. package/dist/core/errors.js.map +1 -1
  63. package/dist/core/git-http.d.ts +111 -0
  64. package/dist/core/git-http.js +546 -0
  65. package/dist/core/git-http.js.map +1 -0
  66. package/dist/core/git.d.ts +63 -0
  67. package/dist/core/git.js +149 -0
  68. package/dist/core/git.js.map +1 -0
  69. package/dist/core/github.d.ts +8 -6
  70. package/dist/core/github.js +24 -2
  71. package/dist/core/github.js.map +1 -1
  72. package/dist/core/paths.d.ts +1 -1
  73. package/dist/core/paths.js +1 -1
  74. package/dist/core/paths.js.map +1 -1
  75. package/dist/core/planner.js +41 -15
  76. package/dist/core/planner.js.map +1 -1
  77. package/dist/core/refs.js +2 -1
  78. package/dist/core/refs.js.map +1 -1
  79. package/dist/core/registry.d.ts +58 -13
  80. package/dist/core/registry.js +221 -36
  81. package/dist/core/registry.js.map +1 -1
  82. package/dist/core/rename.d.ts +49 -10
  83. package/dist/core/rename.js +67 -10
  84. package/dist/core/rename.js.map +1 -1
  85. package/dist/core/store.d.ts +3 -4
  86. package/dist/core/store.js +1 -1
  87. package/dist/core/store.js.map +1 -1
  88. package/dist/core/tracking.d.ts +61 -0
  89. package/dist/core/tracking.js +106 -0
  90. package/dist/core/tracking.js.map +1 -0
  91. package/dist/core/types.d.ts +84 -3
  92. package/dist/core/types.js.map +1 -1
  93. package/dist/index.d.ts +3 -2
  94. package/dist/index.js +3 -2
  95. package/dist/index.js.map +1 -1
  96. package/dist/targets/copilot-cli.d.ts +41 -0
  97. package/dist/targets/copilot-cli.js +181 -0
  98. package/dist/targets/copilot-cli.js.map +1 -0
  99. package/dist/targets/index.d.ts +2 -2
  100. package/dist/targets/index.js +11 -3
  101. package/dist/targets/index.js.map +1 -1
  102. package/docs/authoring-bundles.md +895 -828
  103. package/docs/shipping-bundles.md +181 -0
  104. package/package.json +6 -3
@@ -0,0 +1,399 @@
1
+ # Strategy: an entry point of a library
2
+
3
+ Use this strategy for a library or package that a project installs as a
4
+ dependency, with pip, uv, Poetry, npm, pnpm or Yarn. The bundle ships inside
5
+ the package. A small entry point of the package installs the bundle into the
6
+ project. The user runs it with the package manager of the project, so no global
7
+ command is necessary. Read the shared rules in [the skill](./SKILL.md) first.
8
+
9
+ If the library ships a bundle with an older integration already, for example
10
+ an `init` command that registers the bundle, read
11
+ [Upgrade an existing integration](./migrate.md) too.
12
+
13
+ | Language | The user runs | The entry point is |
14
+ | --- | --- | --- |
15
+ | Python | `python -m my_library hcm install -t claude-code` | the module `my_library.hcm`, called from the `__main__.py` of the package |
16
+ | Node.js | `npx --no my-lib-hcm install -t claude-code` | the `bin` command `my-lib-hcm` of the package |
17
+
18
+ ## Why the library does not use the registry
19
+
20
+ Each project has its own environment: a `.venv/`, a `node_modules/`. Project A
21
+ can pin version 1 of the library, and project B version 2. Each project needs
22
+ the bundle of its own version. The hcm registry has one entry for each bundle
23
+ name, for each user. Thus one registration cannot serve both projects.
24
+
25
+ So the entry point installs the bundle straight into the current project, from
26
+ the folder in the environment of that project. It gives hcm `--track source`.
27
+ hcm records that folder in the `.hcm/state.json` file of the project, and does
28
+ not change the registry. Then:
29
+
30
+ - After an upgrade of the library, `hcm update` in the project reads the folder again, and installs the new version.
31
+ - `hcm update` does not read the registry for this bundle. A registered `my-lib` in another version does not replace the version of the project.
32
+ - If the registry has a different version of the bundle, `hcm install` and `hcm update` show a warning. `hcm list --installed` marks the installation `[source]`.
33
+ - When the folder is inside the project, hcm also records it as a path relative to the project. A teammate's checkout then reads its own environment.
34
+
35
+ ## The commands of the entry point
36
+
37
+ | Command | Effect |
38
+ | --- | --- |
39
+ | `install [-t <harness...>]` | Installs the bundle of this package version into the current project. It follows the folder in the environment. With no `-t`, it repairs the harnesses that have the bundle, for example after the environment moved. |
40
+ | `uninstall` | Optional. Runs `hcm uninstall my-lib -t all` in the current project. |
41
+ | `init` | Optional. Registers the bundle for the user, as [the CLI strategy](./cli.md#what-hcm-init-does) does. Supply it only if the library is also installed one time per machine, for example with `pipx install` or `npm install -g`. It takes the `--dev` option of [development mode](./cli.md#development-mode). |
42
+ | `remove` | Optional, with `init` only. Unregisters the bundle: `hcm registry remove my-lib`. |
43
+
44
+ ## What install does
45
+
46
+ 1. Find hcm. Run `hcm --version`. If the command fails, print `npm install -g harness-config-manager` as the install command, and exit with a non-zero code.
47
+ 2. Run `hcm install --help`. If the output does not contain `--track`, the hcm is too old. Print `npm install -g harness-config-manager@latest` as the upgrade command, and exit with a non-zero code.
48
+ 3. Find the bundle folder from the location of the installed package, not from the current folder.
49
+ 4. Run `hcm list --installed --scope project --json`. Find the harnesses that have the bundle in this project.
50
+ 5. If the bundle is installed already, run `hcm update my-lib --from <bundle-folder> -t <those harnesses> --no-prompt`. This points the installations at the folder of this environment. It removes the files of the old version, and it keeps the parameter values.
51
+ 6. For each requested harness that does not have the bundle, run `hcm install <bundle-folder> --track source -t <harness...> --no-prompt`.
52
+ 7. Print the next step: after each upgrade of the library, run `hcm update`.
53
+
54
+ Use the full harness ids in step 6, for example `claude-code`. The list of step
55
+ 4 has full ids, and a short form such as `claude` does not compare equal to it.
56
+
57
+ ## Python
58
+
59
+ ### Package the bundle
60
+
61
+ Put the bundle beside the code, as package data:
62
+
63
+ ```
64
+ my_library/
65
+ ├── __init__.py
66
+ ├── __main__.py # python -m my_library hcm ...
67
+ ├── hcm.py # the entry point
68
+ └── hcm_bundle/
69
+ ├── hcm.yaml # name: my-library
70
+ └── skills/my-library/SKILL.md
71
+ ```
72
+
73
+ ```toml
74
+ # pyproject.toml, with setuptools
75
+ [tool.setuptools.package-data]
76
+ my_library = ["hcm_bundle/**/*"]
77
+ ```
78
+
79
+ Hatchling and Poetry include the files in the package folder by default. Make
80
+ sure that the built wheel contains `hcm_bundle/`, for example with
81
+ `unzip -l dist/*.whl`.
82
+
83
+ ### The module
84
+
85
+ Start from the Python code in [the examples](./examples.md#python). Copy
86
+ `_find_hcm`, and change `BUNDLE_NAME`. Copy `hcm_init` and `hcm_remove` only if
87
+ you supply `init`. Then add these functions:
88
+
89
+ ```python
90
+ # my_library/hcm.py, after the functions from the examples.
91
+ import argparse
92
+ import json
93
+
94
+
95
+ def _hcm_tracks_sources(hcm: str) -> bool:
96
+ """True when this hcm has "hcm install --track"."""
97
+ help_text = subprocess.run([hcm, "install", "--help"], capture_output=True, text=True).stdout
98
+ return "--track" in help_text
99
+
100
+
101
+ def hcm_install_here(targets: list[str]) -> int:
102
+ """Install the bundle of this environment into the current project.
103
+
104
+ The installation follows this folder (--track source). After an upgrade of
105
+ the library, "hcm update" in the project reads the folder again.
106
+ """
107
+ hcm = _find_hcm()
108
+ if hcm is None:
109
+ print("my-library: hcm is not installed. Install it with: npm install -g harness-config-manager", file=sys.stderr)
110
+ return 1
111
+ if not _hcm_tracks_sources(hcm):
112
+ print("my-library: this hcm is too old. Upgrade it with: npm install -g harness-config-manager@latest", file=sys.stderr)
113
+ return 1
114
+
115
+ listed = subprocess.run(
116
+ [hcm, "list", "--installed", "--scope", "project", "--json"],
117
+ capture_output=True,
118
+ text=True,
119
+ )
120
+ if listed.returncode != 0:
121
+ print(listed.stderr, file=sys.stderr)
122
+ return listed.returncode
123
+ installed_in = sorted({r["target"] for r in json.loads(listed.stdout) if r["bundle"] == BUNDLE_NAME})
124
+
125
+ # Installed already: follow the folder of this environment from now on.
126
+ # The update removes the files of the old version, and keeps the parameters.
127
+ if installed_in:
128
+ updated = subprocess.run(
129
+ [hcm, "update", BUNDLE_NAME, "--from", str(BUNDLE_DIR), "-t", *installed_in, "--no-prompt"]
130
+ )
131
+ if updated.returncode != 0:
132
+ return updated.returncode
133
+
134
+ missing = [target for target in targets if target not in installed_in]
135
+ if not installed_in and not missing:
136
+ print("my-library: name the harnesses, for example: -t claude-code", file=sys.stderr)
137
+ return 2
138
+ if missing:
139
+ added = subprocess.run(
140
+ [hcm, "install", str(BUNDLE_DIR), "--track", "source", "-t", *missing, "--no-prompt"]
141
+ )
142
+ if added.returncode != 0:
143
+ return added.returncode
144
+
145
+ print('After each upgrade of my-library, run "hcm update" in this project.')
146
+ return 0
147
+
148
+
149
+ def hcm_uninstall_here() -> int:
150
+ """Remove the bundle from the current project."""
151
+ hcm = _find_hcm()
152
+ if hcm is None:
153
+ return 1
154
+ return subprocess.run([hcm, "uninstall", BUNDLE_NAME, "-t", "all"]).returncode
155
+
156
+
157
+ def main(argv: list[str] | None = None) -> int:
158
+ parser = argparse.ArgumentParser(prog="python -m my_library hcm", description="Connect my-library to hcm.")
159
+ commands = parser.add_subparsers(dest="command", required=True)
160
+
161
+ install = commands.add_parser("install", help="install the bundle of this environment into the current project")
162
+ install.add_argument("-t", "--target", nargs="+", default=[],
163
+ help="the harnesses, by full id, for example claude-code")
164
+
165
+ commands.add_parser("uninstall", help="remove the bundle from the current project")
166
+
167
+ args = parser.parse_args(argv)
168
+ if args.command == "install":
169
+ return hcm_install_here(args.target)
170
+ return hcm_uninstall_here()
171
+
172
+
173
+ if __name__ == "__main__":
174
+ sys.exit(main())
175
+ ```
176
+
177
+ To supply `init` and `remove` too, add their parsers, and call `hcm_init` and
178
+ `hcm_remove` from the examples.
179
+
180
+ Make `python -m my_library hcm install` work with a `__main__.py`. If the
181
+ package has a `__main__.py` already, add the `hcm` branch to it:
182
+
183
+ ```python
184
+ # my_library/__main__.py
185
+ import sys
186
+
187
+ from my_library.hcm import main as hcm_main
188
+
189
+ if len(sys.argv) > 1 and sys.argv[1] == "hcm":
190
+ sys.exit(hcm_main(sys.argv[2:]))
191
+ ```
192
+
193
+ A module name cannot contain `-`. Thus the user runs `python -m my_library`,
194
+ with the import name of the package, not with its distribution name.
195
+ `python -m my_library.hcm install` also works, without the `__main__.py`.
196
+
197
+ ### Run it with the interpreter of the project
198
+
199
+ The bundle folder is in the environment of the project. Run the module with the
200
+ Python of that environment:
201
+
202
+ ```bash
203
+ .venv/bin/python -m my_library hcm install -t claude-code # a virtual environment
204
+ uv run python -m my_library hcm install -t claude-code # uv
205
+ poetry run python -m my_library hcm install -t claude-code # Poetry
206
+ ```
207
+
208
+ Do not run it with `uvx` or `pipx run`. These tools use a temporary
209
+ environment, and `hcm update` cannot read the bundle folder again after the
210
+ environment is gone.
211
+
212
+ ## Node.js and TypeScript
213
+
214
+ ### Package the bundle
215
+
216
+ Add a `bin` command for hcm to the library, and include the bundle folder:
217
+
218
+ ```json
219
+ {
220
+ "name": "my-lib",
221
+ "bin": { "my-lib-hcm": "./hcm/cli.js" },
222
+ "files": ["dist", "hcm", "hcm-bundle"]
223
+ }
224
+ ```
225
+
226
+ ```
227
+ my-lib/
228
+ ├── package.json
229
+ ├── hcm/
230
+ │ ├── cli.js # the bin command
231
+ │ └── hcm.js # hcmInstallHere, hcmUninstallHere
232
+ └── hcm-bundle/
233
+ ├── hcm.yaml # name: my-lib
234
+ └── skills/my-lib/SKILL.md
235
+ ```
236
+
237
+ Give the command a name with the package name in it, for example `my-lib-hcm`.
238
+ A short name such as `hcm` collides with hcm itself.
239
+
240
+ For a TypeScript library, the `bin` file must be JavaScript. Compile it, point
241
+ `bin` to the compiled file, and get the bundle folder from the location of the
242
+ compiled file.
243
+
244
+ ### The bin command
245
+
246
+ Start from the Node.js code in [the examples](./examples.md#nodejs). Copy the
247
+ `hcm` function, and change `BUNDLE_NAME`. Copy it into the `hcm` folder of the
248
+ package, as the layout above shows. The file is one level below the package
249
+ root, so change the bundle folder:
250
+
251
+ ```js
252
+ const BUNDLE_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'hcm-bundle');
253
+ ```
254
+
255
+ Then add the per-project install:
256
+
257
+ ```js
258
+ // hcm/hcm.js, after the functions from the examples.
259
+
260
+ /**
261
+ * Install the bundle of this node_modules into the current project. The
262
+ * installation follows this folder, so "hcm update" reads it again after an
263
+ * upgrade of the package.
264
+ */
265
+ export function hcmInstallHere(targets) {
266
+ const help = hcm(['install', '--help'], { stdio: 'pipe', encoding: 'utf8' });
267
+ if (help.error || help.status !== 0) {
268
+ console.error('my-lib: hcm is not installed. Install it with: npm install -g harness-config-manager');
269
+ return 1;
270
+ }
271
+ if (!help.stdout.includes('--track')) {
272
+ console.error('my-lib: this hcm is too old. Upgrade it with: npm install -g harness-config-manager@latest');
273
+ return 1;
274
+ }
275
+
276
+ const listed = hcm(['list', '--installed', '--scope', 'project', '--json'], {
277
+ stdio: 'pipe',
278
+ encoding: 'utf8',
279
+ });
280
+ if (listed.status !== 0) return listed.status ?? 1;
281
+
282
+ const installedIn = [
283
+ ...new Set(
284
+ JSON.parse(listed.stdout)
285
+ .filter((record) => record.bundle === BUNDLE_NAME)
286
+ .map((record) => record.target),
287
+ ),
288
+ ];
289
+
290
+ // Installed already: follow the folder of this node_modules from now on.
291
+ // The update removes the files of the old version, and keeps the parameters.
292
+ if (installedIn.length > 0) {
293
+ const updated = hcm(['update', BUNDLE_NAME, '--from', BUNDLE_DIR, '-t', ...installedIn, '--no-prompt']);
294
+ if (updated.status !== 0) return updated.status ?? 1;
295
+ }
296
+
297
+ const missing = targets.filter((target) => !installedIn.includes(target));
298
+ if (installedIn.length === 0 && missing.length === 0) {
299
+ console.error('my-lib: name the harnesses, for example: -t claude-code');
300
+ return 2;
301
+ }
302
+ if (missing.length > 0) {
303
+ const added = hcm(['install', BUNDLE_DIR, '--track', 'source', '-t', ...missing, '--no-prompt']);
304
+ if (added.status !== 0) return added.status ?? 1;
305
+ }
306
+
307
+ console.log('After each upgrade of my-lib, run "hcm update" in this project.');
308
+ return 0;
309
+ }
310
+
311
+ /** Remove the bundle from the current project. */
312
+ export function hcmUninstallHere() {
313
+ return hcm(['uninstall', BUNDLE_NAME, '-t', 'all']).status ?? 1;
314
+ }
315
+ ```
316
+
317
+ ```js
318
+ #!/usr/bin/env node
319
+ // hcm/cli.js: my-lib-hcm install [-t <harness...>] | uninstall
320
+ import { hcmInstallHere, hcmUninstallHere } from './hcm.js';
321
+
322
+ const [command, ...rest] = process.argv.slice(2);
323
+
324
+ function targetsOption(args) {
325
+ const index = args.findIndex((arg) => arg === '-t' || arg === '--target');
326
+ return index < 0 ? [] : args.slice(index + 1).filter((arg) => !arg.startsWith('-'));
327
+ }
328
+
329
+ let status;
330
+ if (command === 'install') {
331
+ status = hcmInstallHere(targetsOption(rest));
332
+ } else if (command === 'uninstall') {
333
+ status = hcmUninstallHere();
334
+ } else {
335
+ console.error('Usage: my-lib-hcm install [-t <harness...>] | uninstall');
336
+ status = 2;
337
+ }
338
+ process.exit(status);
339
+ ```
340
+
341
+ ### Run it with the package manager of the project
342
+
343
+ ```bash
344
+ npx --no my-lib-hcm install -t claude-code # npm
345
+ pnpm exec my-lib-hcm install -t claude-code # pnpm
346
+ yarn run my-lib-hcm install -t claude-code # Yarn
347
+ ```
348
+
349
+ `--no` stops `npx` when the package is not a dependency of the project. Without
350
+ it, `npx` can download a package with that name from the npm registry and run
351
+ it. That package can be a different program, and its folder is temporary.
352
+
353
+ ## Test the entry point
354
+
355
+ Set `HCM_HOME` to a temporary folder in each test, as
356
+ [the skill](./SKILL.md#test-the-integration) tells. Then do these steps:
357
+
358
+ 1. Make a temporary project folder with an environment that has the library.
359
+ 2. In that folder, run `python -m my_library hcm install -t claude-code`, or `npx --no my-lib-hcm install -t claude-code`.
360
+ 3. Run `hcm list --installed --scope project --json`. Make sure that the record of the bundle has `"track": "source"` and the version of the package.
361
+ 4. Make sure that `hcm registry list --json` does not list the bundle.
362
+ 5. Run the `install` command again, with no `-t`. Make sure that it succeeds.
363
+ 6. Copy the bundle folder, change the version in the copy, and register the copy: `hcm registry add <copy>`. Run `hcm update`. Make sure that the installed version did not change.
364
+ 7. Run `hcm validate <bundle-folder>` and `hcm refs check --path <bundle-folder>`.
365
+
366
+ ## A teammate's checkout
367
+
368
+ Commit `.hcm/state.json` with the installed files. When the bundle folder is
369
+ inside the project, the record has its path relative to the project, for example
370
+ `.venv/lib/python3.12/site-packages/my_library/hcm_bundle`. A teammate creates
371
+ the environment, installs the dependencies, and runs `hcm update`. hcm reads the
372
+ bundle folder of the teammate's environment.
373
+
374
+ The relative path can be different on another machine, for example with another
375
+ Python version, or with an environment outside the project. Then `hcm update`
376
+ reports that the folder does not exist. Run the `install` command of the entry
377
+ point again. It points the installation at the folder of that environment.
378
+
379
+ ## Upgrades
380
+
381
+ After an upgrade of the library, run `hcm update` in the project. Put this in
382
+ the upgrade notes of each release:
383
+
384
+ ```bash
385
+ pip install -U my-library # or: npm update my-lib
386
+ hcm update # reads the bundle of the new version
387
+ ```
388
+
389
+ If the environment moved, for example after you created the `.venv/` again in
390
+ another place, run the `install` command of the entry point again.
391
+
392
+ ## Development mode
393
+
394
+ To test changes to the bundle in other projects, install the library from your
395
+ working copy in those projects. For Python, run `pip install -e <checkout>`.
396
+ For Node.js, run `npm link` in the checkout and `npm link my-lib` in the
397
+ project. Then run the `install` command of the entry point in each test project.
398
+ The bundle folder is then the folder of your working copy, and the installation
399
+ follows it. After each edit, run `hcm update` in each test project.
@@ -0,0 +1,204 @@
1
+ # Upgrade an existing integration
2
+
3
+ Use this file when your software already ships an hcm bundle, and you want the
4
+ new update features of hcm. Read the shared rules in [the skill](./SKILL.md)
5
+ first.
6
+
7
+ ## What changed in hcm
8
+
9
+ hcm now records, for each installation in a project, where `hcm update` reads
10
+ the next version:
11
+
12
+ | Mode | `hcm update` reads | Set by |
13
+ | --- | --- | --- |
14
+ | `registry` | the registered bundle of the same name | an install by name or id |
15
+ | `source` | the folder or repository that the installation came from; the registry is not read | `hcm install <folder> --track source` |
16
+
17
+ With no recorded mode, an installation follows the registry when a bundle of
18
+ its name is registered. Else it follows its source.
19
+
20
+ This changes what a library can do:
21
+
22
+ | Before | Now |
23
+ | --- | --- |
24
+ | `hcm update` skipped a bundle that was installed from a folder and not registered. | `hcm update` reads that folder again. |
25
+ | A registered bundle of the same name replaced a per-project install at the next `hcm update`. | An installation with `--track source` ignores the registry. |
26
+ | After each upgrade of the library, the user ran the `install` command of the library again. That command removed the bundle and installed it again, and the parameter values were lost. | The user runs `hcm update`. The update removes the files that the new version deleted, and it keeps the parameter values. |
27
+ | To point an installation at another folder, the user removed it and installed it again. | `hcm update <bundle> --from <folder>` points it at the new folder. |
28
+ | hcm recorded only the absolute path of the folder. | For a folder inside the project, hcm also records the path relative to the project. A teammate's checkout reads its own `.venv/` or `node_modules/`. |
29
+ | Nothing told the user that the project and the registry had different versions. | `hcm install` and `hcm update` warn. `hcm list --installed` marks the installation `[source]`, and shows the registered version. |
30
+
31
+ Also new: `hcm update --no-registry` reads each installation from its recorded
32
+ source one time, and does not change the registry.
33
+
34
+ ## Find your case
35
+
36
+ | You ship today | What to change | Read |
37
+ | --- | --- | --- |
38
+ | A CLI tool with `my-cli hcm init` | Nothing is necessary. You can add the new commands to your upgrade notes. | [A CLI tool](#a-cli-tool) |
39
+ | A library with only `init`, which registers the bundle | Add an `install` command that follows the environment of the project. Make it the documented command. | [A library](#a-library) |
40
+ | A library with `init` and an `install` command that removes the bundle and installs it again | Change the `install` command. Make it the documented command. | [A library](#a-library) |
41
+ | A bundle that users download from a repository | Nothing is necessary. You can document a pin for each project. | [A separate download](#a-separate-download) |
42
+
43
+ ## Check the hcm version
44
+
45
+ The new commands need an hcm that has the `--track` option. Check for the
46
+ option, not for a version number. Do this check in each command that uses
47
+ `--track` or `--from`:
48
+
49
+ 1. Run `hcm install --help`.
50
+ 2. If the output does not contain `--track`, print this message, and exit with a non-zero code: `my-lib needs a newer hcm. Upgrade it with: npm install -g harness-config-manager@latest`.
51
+
52
+ ```python
53
+ def _hcm_tracks_sources(hcm: str) -> bool:
54
+ """True when this hcm has "hcm install --track"."""
55
+ help_text = subprocess.run([hcm, "install", "--help"], capture_output=True, text=True).stdout
56
+ return "--track" in help_text
57
+ ```
58
+
59
+ ```js
60
+ /** True when this hcm has "hcm install --track". */
61
+ function hcmTracksSources() {
62
+ const help = hcm(['install', '--help'], { stdio: 'pipe', encoding: 'utf8' });
63
+ return help.status === 0 && help.stdout.includes('--track');
64
+ }
65
+ ```
66
+
67
+ Do not go back to the old behavior on an old hcm. The old behavior loses
68
+ parameter values, and the registry can replace the version of the project.
69
+
70
+ ## A library
71
+
72
+ ### Change the entry point
73
+
74
+ 1. Keep the bundle folder in the package, as package data. Do not change its name or its place. The installations of your users record that folder.
75
+ 2. Add the `hcm` branch to the `__main__.py` of the package, so that `python -m my_library hcm install` works. Keep `python -m my_library.hcm` working too. Users and scripts can call it.
76
+ 3. Add the hcm version check above to the `install` command.
77
+ 4. Change the `install` command. Use the code in [the library strategy](./library.md#the-module) for Python, or in [the bin command](./library.md#the-bin-command) for Node.js. The change is:
78
+
79
+ | Remove | Add |
80
+ | --- | --- |
81
+ | The call to `hcm uninstall` before the install | For the harnesses that have the bundle: `hcm update my-lib --from <bundle-folder> -t <harness...> --no-prompt` |
82
+ | `hcm install <bundle-folder> -t <harness...>` | For the other harnesses: `hcm install <bundle-folder> --track source -t <harness...> --no-prompt` |
83
+
84
+ 5. Make `-t` optional when the bundle is installed already. Then `python -m my_library hcm install` with no options repairs the installation, for example after the `.venv/` moved.
85
+ 6. Change the message at the end of the command: `After each upgrade of my-lib, run "hcm update" in this project.`
86
+ 7. Keep `init` only if users can also install the library one time for each machine, for example with `pipx install` or `npm install -g`. Else delete it, and delete its documentation. If you keep it, do not call it "the usual case" in the help text.
87
+ 8. If your `remove` command unregisters the bundle today, keep that meaning. Users can have scripts that call it. Add an `uninstall` command that removes the bundle from the current project: `hcm uninstall my-lib -t all`.
88
+
89
+ Do not run the `install` command from a package hook. The rule in
90
+ [the skill](./SKILL.md#do-not-register-from-an-install-hook) applies to
91
+ `install` too.
92
+
93
+ ### Change the tests
94
+
95
+ Replace the registration tests of the library with these steps. Set `HCM_HOME`
96
+ to a temporary folder, as [the skill](./SKILL.md#test-the-integration) tells.
97
+
98
+ 1. Make a temporary project folder with an environment that has the library.
99
+ 2. Run `python -m my_library hcm install -t claude-code`.
100
+ 3. Run `hcm list --installed --scope project --json`. Make sure that the record of `my-lib` has `"track": "source"` and the version of the package.
101
+ 4. Make sure that `hcm registry list --json` does not list `my-lib`.
102
+ 5. Run the `install` command again. Make sure that it succeeds, and that the record is the same.
103
+ 6. Register another version of the bundle: change the version in a copy of the bundle folder, and run `hcm registry add <copy>`. Run `hcm update`. Make sure that the installed version did not change.
104
+
105
+ ### Change the documentation
106
+
107
+ Replace the install and upgrade instructions in the README of the library:
108
+
109
+ ````markdown
110
+ ## Agent configuration (hcm)
111
+
112
+ This library comes with agent skills for hcm (harness-config-manager).
113
+ Install them into a project, from the environment of that project:
114
+
115
+ ```bash
116
+ npm install -g harness-config-manager # one time for each machine
117
+ python -m my_library hcm install -t claude-code
118
+ ```
119
+
120
+ After each upgrade of my-library, run `hcm update` in the project. Each project
121
+ gets the skills of the my-library version that it has.
122
+ ````
123
+
124
+ Put a note in the release notes of the first version with the change. Use
125
+ the text of [Move the projects of your users](#move-the-projects-of-your-users).
126
+
127
+ ### Move the projects of your users
128
+
129
+ A project that has the bundle from an older integration has one of two
130
+ shapes. `hcm list --installed` shows which one:
131
+
132
+ | The line of `my-lib` | Shape | Meaning |
133
+ | --- | --- | --- |
134
+ | No `[source]` mark | A | It follows the registry. It came from `init` and `hcm install my-lib`. |
135
+ | `[source]`, and a folder in the environment of the project | B | It follows that folder. It came from the old `install` command, and nothing registered `my-lib`. |
136
+
137
+ For both shapes, the user does the same steps in each project:
138
+
139
+ 1. Upgrade hcm and the library.
140
+ 2. Run `python -m my_library hcm install`. The bundle is installed, so the command runs `hcm update my-lib --from <bundle-folder>`.
141
+ 3. Run `hcm list --installed`. Make sure that the line of `my-lib` has `[source]` and the folder of the environment.
142
+
143
+ Step 2 records the mode. A shape B project follows its folder already, but
144
+ only because `my-lib` is not registered. If somebody registers `my-lib` later,
145
+ it follows the registry again. Step 2 prevents that.
146
+
147
+ When no project follows the registry, the user can remove the registered entry:
148
+ `hcm registry remove my-lib`. Remove it only after step 2 in each project. A
149
+ shape A project that still follows the registry then reads the folder that the
150
+ registry recorded. Usually, that folder is in the environment of the project
151
+ that ran `init`, and it has the wrong version.
152
+
153
+ ### A teammate's checkout
154
+
155
+ Tell the users to commit `.hcm/state.json` with the installed files. When the
156
+ bundle folder is inside the project, the record has its path relative to the
157
+ project. A teammate creates the environment, and runs `hcm update`.
158
+
159
+ If the environment of the teammate has another layout, for example another
160
+ Python version in the path, `hcm update` reports that the folder does not
161
+ exist. The teammate then runs `python -m my_library hcm install`.
162
+
163
+ ## A CLI tool
164
+
165
+ The CLI strategy does not change. `my-cli hcm init` registers the bundle, and
166
+ each project follows the registry.
167
+
168
+ You can add these commands to your upgrade notes:
169
+
170
+ ```bash
171
+ npm update -g my-cli
172
+ hcm registry update my-cli # read the new bundle into the registry
173
+ hcm update # in each project
174
+ hcm update --no-registry # or: one project, from the tool folder, with no change to the registry
175
+ ```
176
+
177
+ If your tool is also a dependency of projects, for example a Python tool that
178
+ each project installs into its `.venv/`, also add the `install` command of
179
+ [the library strategy](./library.md). Then each project can follow its own
180
+ version of the tool.
181
+
182
+ ## A separate download
183
+
184
+ Users can now pin a release for each project, with no registration. Add this
185
+ to the instructions for your users:
186
+
187
+ ```bash
188
+ hcm install owner/repo/hcm-bundle#v1.2.0 --track source -t claude-code
189
+ hcm update my-lib --from owner/repo/hcm-bundle#v1.3.0 # move to a new release
190
+ ```
191
+
192
+ See [Pin the version in a project](./remote.md#pin-the-version-in-a-project).
193
+
194
+ ## Checklist
195
+
196
+ - [ ] The entry point checks that hcm has `--track`.
197
+ - [ ] `install` runs `hcm update --from` for the harnesses that have the bundle, and `hcm install --track source` for the others.
198
+ - [ ] `install` does not call `hcm uninstall`.
199
+ - [ ] `python -m my_library hcm install` works, or `npx --no my-lib-hcm install` for Node.js.
200
+ - [ ] `init` is gone, or documented only for one install for each machine.
201
+ - [ ] `remove` keeps its old meaning. `uninstall` removes the bundle from the project.
202
+ - [ ] The tests check `"track": "source"`, and that a registered version does not replace the project version.
203
+ - [ ] The README tells users to run `hcm update` after an upgrade.
204
+ - [ ] The release notes tell users to run the `install` command one time in each project.