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,149 @@
1
+ ---
2
+ description: Ship an hcm bundle with your software, so that its users can install its agent configuration with hcm. Covers a CLI subcommand such as "my-cli hcm init", an entry point of a library such as "python -m my_library hcm install" or "npx --no my-lib-hcm install" that installs the bundle of the project environment, and a bundle that users download separately from a git repository or a release. Use when the user builds a tool, app or library that comes with agent skills, subagents, MCP servers or other agent configuration. Also use it to upgrade software that ships a bundle with an older integration, for example a library whose "init" command registers the bundle, so that each project follows the bundle of its own environment. Also use it to sync bundle changes into test projects during development.
3
+ flavors: [integration]
4
+ ---
5
+
6
+ # Ship an hcm bundle with your software
7
+
8
+ Software can come with agent configuration. Examples are a skill that explains
9
+ a library, a subagent that uses a tool, and an MCP server that a tool supplies.
10
+ Put this configuration in an hcm bundle. Then give the bundle to hcm with one of
11
+ the strategies below. Use the `hcm-bundle-authoring` skill to write the bundle.
12
+
13
+ ## Choose a strategy
14
+
15
+ | Your software | Strategy | The user runs | Read |
16
+ | --- | --- | --- | --- |
17
+ | A CLI tool or app with its own command | A subcommand registers the bundle that ships in the package. | `my-cli hcm init` | [the CLI strategy](./cli.md) |
18
+ | A library or package that a project installs as a dependency | An entry point of the package installs the bundle from the environment of the project into that project. It does not change the registry. | `python -m my_library hcm install`, `npx --no my-lib-hcm install` | [the library strategy](./library.md) |
19
+ | Any software, when the bundle must be available without the package | The user downloads only the bundle folder, from a repository or a release. | `hcm registry add owner/repo/hcm-bundle#v1.2.0`, or `hcm registry add <clone-url>#v1.2.0:hcm-bundle` | [the remote strategy](./remote.md) |
20
+
21
+ You can use more than one strategy. For example, a Python library can supply
22
+ `python -m my_library hcm install` for its users, and a tag in its repository
23
+ for the users of other languages. Use the same bundle folder and the same
24
+ bundle name for all strategies.
25
+
26
+ ### Registry or source
27
+
28
+ Each installation of a bundle in a project follows one of two places. `hcm
29
+ update` reads the next version from that place.
30
+
31
+ | Mode | `hcm update` reads | Use it for |
32
+ | --- | --- | --- |
33
+ | `registry` | the registered bundle of the same name | a tool that the machine has one time: a CLI, an MCP server, an app |
34
+ | `source` | the folder or repository that the installation came from; the registry is not read | a library that each project installs into its own `.venv/` or `node_modules/` |
35
+
36
+ The CLI strategy uses `registry`. The library strategy uses `source`, with
37
+ `hcm install <bundle-folder> --track source`. Two projects can then pin two
38
+ versions of the library, and the registry cannot replace either version.
39
+
40
+ Code for Node.js, Python and Go is in [the examples](./examples.md).
41
+
42
+ ## Software that ships a bundle already
43
+
44
+ Older integrations of a library register the bundle with `init`, or remove and
45
+ install the bundle again after each upgrade. Such a library does not get the
46
+ new update features. To change it, and to move the projects of its users,
47
+ follow [Upgrade an existing integration](./migrate.md).
48
+
49
+ Do these steps first, to find what the software ships now:
50
+
51
+ 1. Find the entry point: a CLI subcommand, a module such as `my_library.hcm`, or a `bin` command such as `my-lib-hcm`.
52
+ 2. Read the hcm commands that it runs. Look for `hcm registry add`, `hcm install` and `hcm uninstall`.
53
+ 3. Find the bundle folder, and read its `hcm.yaml`.
54
+ 4. Find the tests and the README sections that mention hcm.
55
+
56
+ ## Shared rules
57
+
58
+ ### How hcm gets the bundle
59
+
60
+ - Your software runs the `hcm` command as a subprocess. It does not import hcm as a library, and it does not write the files in `~/.hcm/`. The registry format belongs to hcm, and the hcm of the user can be a different version.
61
+ - A CLI tool registers the bundle with `hcm registry add <folder>`. hcm copies the folder into its store, and records the folder as the source of the bundle.
62
+ - A library installs the bundle with `hcm install <folder> --track source`. hcm records the folder in the `.hcm/state.json` file of the project. It does not change the registry.
63
+ - Give hcm an absolute path, or a relative path that starts with `./`. hcm reads a path such as `vendor/my-lib/hcm-bundle` as the GitHub reference `owner/repo/path`, also when the local folder exists.
64
+ - `hcm update` reads the source folder again, through the registry or directly. Thus the source folder must stay in place. Do not give hcm a temporary folder. Examples of temporary folders are the environments of `npx` without a local install, `uvx` and `pipx run`.
65
+ - `hcm registry add` is idempotent. A second registration of the same bundle keeps its id and replaces the stored copy. Thus a user can run your registration command again at any time. This is also the upgrade path.
66
+ - The registry has one entry for each bundle name, for each user. The last registration of `my-lib` replaces the earlier one. If projects of one user need different versions of the bundle, use [the library strategy](./library.md), which does not use the registry.
67
+
68
+ ### Rules for the bundle
69
+
70
+ - Give the bundle the name of the package: `name: my-lib` in `hcm.yaml`. Use the same name as a prefix for its skills, subagents and MCP servers.
71
+ - Keep the bundle version equal to the package version. Add a test or a release step that compares the two versions.
72
+ - Keep all files of the bundle in its folder. A reference to a file outside the bundle folder breaks when hcm installs the bundle.
73
+ - Refer to a command by its name, for example `"command": "my-cli"` in an MCP file. Do not write an absolute path to an installed package. The path is different on each machine.
74
+ - If the bundle needs a value from the user, for example an API URL, declare a parameter. For a secret, declare `secret: true`, or use an environment variable in the MCP or settings file.
75
+ - If the bundle or the entry point needs a feature of a newer hcm, check for the option in the `--help` output of the hcm command. For example, `hcm install --help` contains `--track` when hcm can make an installation follow its source. If the option is not there, tell the user to upgrade hcm with `npm install -g harness-config-manager@latest`.
76
+ - If the agents need to know about hcm itself, add `hcm` to the `dependencies` of the bundle. Every hcm installation has the built-in `hcm` bundle.
77
+
78
+ ### Do not register from an install hook
79
+
80
+ Do not run hcm from an npm `postinstall` script or a Python build hook. Package
81
+ managers can skip these hooks, for example with `--ignore-scripts`. The hooks
82
+ also run in CI and in containers, where hcm is not available. And they change
83
+ the home folder of the user without consent. Give the user an explicit command.
84
+
85
+ ## Development mode
86
+
87
+ When you develop the software, you change its bundle often. Each test project
88
+ must get the latest files of your working copy:
89
+
90
+ - A CLI tool registers the working copy with `hcm registry add <folder> --dev`. Then `hcm update <name>` in each test project installs the latest files. See [Development mode](./cli.md#development-mode).
91
+ - A library needs no `--dev` option. Install the library from the checkout into each test project, with `pip install -e <checkout>` or `npm link`. Then run its `install` command there. The installation follows the bundle folder of the checkout, and `hcm update` installs each edit. See [the library strategy](./library.md#development-mode).
92
+
93
+ ## Test the integration
94
+
95
+ hcm reads the `HCM_HOME` environment variable. In each test, set it to a
96
+ temporary folder. Then the test does not change the real registry of the user.
97
+
98
+ `HCM_HOME` moves only the files of hcm. It does not move the home folders of
99
+ the harnesses. An install with `-s user` writes into the real home folder of the
100
+ user, for example `~/.claude/`. Thus use only project scope in tests.
101
+
102
+ For a CLI tool, which registers the bundle:
103
+
104
+ 1. Make a temporary folder. Set `HCM_HOME` to it for each subprocess.
105
+ 2. Run your registration command.
106
+ 3. Run `hcm registry list --json`. Make sure that it lists the bundle with the correct version.
107
+ 4. In a second temporary folder, run `hcm install <name> -t claude-code --no-prompt`, then `hcm status`.
108
+ 5. Run the registration command again. Make sure that the id of the entry did not change.
109
+
110
+ For a library, which installs the bundle into the project, follow
111
+ [Test the entry point](./library.md#test-the-entry-point). The main checks are
112
+ that the record has `"track": "source"`, and that a registered version of the
113
+ same bundle does not replace the version of the project.
114
+
115
+ Also run `hcm validate <bundle-folder>` and `hcm refs check --path <bundle-folder>`
116
+ in the test suite of your software.
117
+
118
+ ## More than one bundle
119
+
120
+ To ship more than one bundle, put each bundle in its own subfolder of one
121
+ folder. That folder is a collection. `hcm registry add <folder>` registers each
122
+ bundle in it, and each bundle keeps its own name.
123
+
124
+ Put an `hcm_manifest.yml` file in the collection folder. Give the name of your
125
+ software as the `collection` name:
126
+
127
+ ```
128
+ hcm-bundles/
129
+ ├── hcm_manifest.yml
130
+ ├── my-cli-core/hcm.yaml
131
+ └── my-cli-extras/hcm.yaml
132
+ ```
133
+
134
+ ```yaml
135
+ collection: my-cli
136
+ bundles: # optional; the default is each direct subfolder with an hcm.yaml
137
+ - my-cli-core
138
+ - my-cli-extras
139
+ ```
140
+
141
+ - Your registration command gives hcm the collection folder, not each bundle folder: `hcm registry add <hcm-bundles-folder>`. Only then does hcm record the collection name.
142
+ - Your removal command removes the whole collection: `hcm registry remove --collection my-cli`. Then a bundle that you dropped from a later release also goes.
143
+ - Give each bundle the name of the package as a prefix, for example `my-cli-core`.
144
+ - Keep the version of each bundle equal to the package version.
145
+ - In the test of the integration, run `hcm registry list --collection my-cli --json`. Make sure that it lists each bundle.
146
+ - A script can call your registration command without a terminal. If another source already uses the name, hcm then stops with a clash. Show the hcm output to the user. Give `--on-collection-clash` only when the user passes it to your command.
147
+
148
+ To write the collection, or to add a manifest to bundles that you ship now,
149
+ use the `hcm-bundle-authoring` skill.
@@ -0,0 +1,139 @@
1
+ # Strategy: a CLI subcommand
2
+
3
+ Use this strategy for a CLI tool or app with its own command. The bundle ships
4
+ inside the package of the tool, and a subcommand gives the bundle to hcm. In
5
+ this file, that subcommand is `my-cli hcm init`. Read the shared rules in
6
+ [the skill](./SKILL.md) first.
7
+
8
+ After `my-cli hcm init`, the bundle is in the hcm registry. The user then
9
+ installs it with hcm, in any project and for any harness:
10
+
11
+ ```bash
12
+ my-cli hcm init
13
+ hcm install my-cli -t claude-code
14
+ ```
15
+
16
+ ## Procedure
17
+
18
+ 1. Make the bundle. Use the `hcm-bundle-authoring` skill to write it.
19
+ 2. Put the bundle in a folder of the tool package, for example `hcm-bundle/`.
20
+ 3. Include the bundle folder in the package. For npm, add the folder to `files` in `package.json`. For Python, add it as package data. For a single binary, embed it.
21
+ 4. Add the `my-cli hcm init` subcommand. See [What hcm init does](#what-hcm-init-does).
22
+ 5. Add a `--dev` option to `my-cli hcm init` for the developers of the tool. See [Development mode](#development-mode).
23
+ 6. Optional: add `my-cli hcm remove`. It runs `hcm registry remove my-cli`. If the tool ships a collection, it runs `hcm registry remove --collection <name>`. See [More than one bundle](./SKILL.md#more-than-one-bundle).
24
+ 7. Test the subcommands as the shared rules tell, and with the steps in [Test development mode](#test-development-mode).
25
+ 8. Document the two commands for your users: `my-cli hcm init`, then `hcm install my-cli -t <harness>`.
26
+
27
+ ## What hcm init does
28
+
29
+ 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. Do not install hcm without the consent of the user.
30
+ 2. Find the bundle folder. Get it from the location of the installed tool, not from the current folder.
31
+ 3. If the bundle is embedded in a binary, write it to a permanent folder of the tool, for example `~/.cache/my-cli/hcm-bundle/`. Replace the old contents each time.
32
+ 4. Register the bundle: `hcm registry add <bundle-folder>`. If the command fails, show its output and exit with its exit code.
33
+ 5. Optional: if the user gives `--install`, run `hcm install my-cli` in the current folder. Pass through the `-t`, `-s`, `--flavor`, `--param` and `--no-prompt` options of the user.
34
+ 6. Print the next step: `hcm install my-cli -t <harness>`.
35
+
36
+ For a released tool, do not register with `hcm registry add --dev`. A `--dev`
37
+ entry has no stored copy. If the package folder moves, the entry stops working.
38
+ Use `--dev` only for the development mode below.
39
+
40
+ On Windows, npm installs hcm as `hcm.cmd`. Some subprocess functions do not find
41
+ a `.cmd` file without a shell. [The examples](./examples.md) show how to find it.
42
+
43
+ ## Development mode
44
+
45
+ When you develop the tool, you change its bundle often. You also want each test
46
+ project to get the changes fast. Development mode does this. `my-cli hcm init
47
+ --dev` registers the bundle folder of your working copy with
48
+ `hcm registry add <folder> --dev`. hcm then reads that folder in place, and it
49
+ keeps no stored copy.
50
+
51
+ After this registration, `hcm update` in a project installs the latest files of
52
+ the working copy:
53
+
54
+ - It writes the files that you changed.
55
+ - It adds the files that you added, and removes the files that you deleted.
56
+ - It does this when the bundle version is the same. You do not change the version for each edit.
57
+
58
+ ### What hcm init --dev does
59
+
60
+ 1. Find hcm, as in [What hcm init does](#what-hcm-init-does).
61
+ 2. Find the working copy of the bundle. If the user gives a path (`--dev <path>`), use it. Resolve a relative path from the current folder. If the user gives no path, use the bundle folder beside the code that runs.
62
+ 3. If the folder does not contain `hcm.yaml`, print an error and exit with a non-zero code.
63
+ 4. If the folder is in an installed copy of the tool, print a warning. Examples are a folder in `node_modules` or `site-packages`. Changes to the working copy do not go to that folder.
64
+ 5. Run `hcm registry add <folder> --dev`.
65
+ 6. Print the mode and the next step: `hcm update my-cli -t <harness>` in each test project.
66
+
67
+ A single binary has no working copy beside its code. For a binary, make the path
68
+ mandatory: `my-cli hcm init --dev ./hcm-bundle`.
69
+
70
+ The entry keeps the name `my-cli` and its id in both modes. Thus the projects
71
+ that have the bundle need no change when you switch the mode.
72
+
73
+ ### The development loop
74
+
75
+ 1. Run the tool from your working copy. For Node.js, run `npm link` in the checkout. For Python, run `pip install -e .`. For a binary, give the path to `--dev`.
76
+ 2. Register the working copy one time: `my-cli hcm init --dev`.
77
+ 3. Make sure that hcm reads the working copy. `hcm list` shows `[dev]` after `my-cli`. In `hcm registry list --json`, the entry has `"dev": true`.
78
+ 4. Install the bundle one time in each test project: `hcm install my-cli -t <harness> --no-prompt`.
79
+ 5. Edit the bundle in the working copy.
80
+ 6. Optional: check the bundle with `hcm validate <folder>`.
81
+ 7. In each test project, run `hcm update my-cli -t <harness> --no-prompt`.
82
+
83
+ To update many test projects with one command, use a script. See
84
+ [the sync scripts](./examples.md#sync-many-test-projects).
85
+
86
+ You can also install the bundle at user scope: `hcm install my-cli -t <harness>
87
+ -s user`. Then one `hcm update my-cli -s user` updates all projects of the user.
88
+ Do not install the same bundle at user scope and at project scope. The agent
89
+ then loads two copies.
90
+
91
+ ### Rules for development mode
92
+
93
+ - Edit the bundle only in the working copy. Do not edit the installed files in a test project. hcm reports an edited file as `modified`, and `hcm update` stops for that bundle in that project.
94
+ - To discard the edits in a test project, run `hcm update my-cli -t <harness> --force`.
95
+ - Do not make `--dev` the default. A user of the released tool needs the stored copy.
96
+ - In development mode, do not show the upgrade notice of [Upgrades](#upgrades). The versions are equal on purpose.
97
+ - Do not move or delete the working copy while the entry is in development mode. If you do, `hcm install` and `hcm update` fail for `my-cli`. Run `my-cli hcm init --dev <new-path>` to fix the entry.
98
+
99
+ ### Back to the released bundle
100
+
101
+ Run `my-cli hcm init` without `--dev` from the installed release of the tool.
102
+ hcm stores a copy of the released bundle again, and it keeps the id. Then run
103
+ `hcm update my-cli` in each project to install the released files.
104
+
105
+ If the tool still runs from the working copy, for example through `npm link`,
106
+ `my-cli hcm init` stores a copy of the working copy. Thus install the released
107
+ tool first. For Node.js, run `npm unlink -g my-cli`, then
108
+ `npm install -g my-cli`.
109
+
110
+ ## Upgrades
111
+
112
+ After an upgrade of the tool, tell the user to run these commands:
113
+
114
+ ```bash
115
+ my-cli hcm init # register the new bundle version
116
+ hcm update my-cli # install it into each project that has the old version
117
+ ```
118
+
119
+ The registry records the bundle folder of the tool as its source. Thus the user
120
+ can also use hcm alone after an upgrade, for example after `npm update -g
121
+ my-cli`:
122
+
123
+ | Command | Effect |
124
+ | --- | --- |
125
+ | `hcm registry update my-cli` | Reads the bundle folder again, and replaces the stored copy. It does not change a project. |
126
+ | `hcm update my-cli` | In a project: refreshes the registry entry, then installs the new version. |
127
+ | `hcm update my-cli --no-registry` | In a project: reads the bundle folder that the project recorded, and installs it. The registry does not change. If the registry has a different version, hcm warns. |
128
+
129
+ You can also show a notice when the tool starts. Compare the tool version with
130
+ the version of the `my-cli` entry in `hcm registry list --json`. If the two are
131
+ different, print the two commands. Do not show the notice when the entry has
132
+ `"dev": true`. Do not run hcm automatically each time the tool starts.
133
+
134
+ ## Test development mode
135
+
136
+ Do these steps after the shared test steps, with the same temporary `HCM_HOME`:
137
+
138
+ 1. Run `my-cli hcm init --dev <bundle-folder>`. Make sure that the entry has `"dev": true` and the same id.
139
+ 2. Change a file in the bundle folder. Run `hcm update my-cli -t claude-code --no-prompt` in the project folder. Make sure that the installed file has the change.
@@ -0,0 +1,338 @@
1
+ # Examples: `my-cli hcm init`
2
+
3
+ Each example registers the bundle with `hcm registry add`, and optionally
4
+ installs it. With `--dev`, it registers the working copy of the bundle with
5
+ `hcm registry add --dev` instead. See
6
+ [Development mode](./cli.md#development-mode). Change `my-cli` to the name of
7
+ your tool. Connect the functions to the argument parser of your tool.
8
+
9
+ A library does not register its bundle by default. It installs the bundle into
10
+ the project, and the installation follows the environment of the project. Copy
11
+ only the helpers from here, for example `hcm` or `_find_hcm`. Then add the
12
+ `install` command of [the library strategy](./library.md).
13
+
14
+ ## Node.js
15
+
16
+ The package layout:
17
+
18
+ ```
19
+ my-cli/
20
+ ├── package.json # "files": ["dist", "hcm-bundle"]
21
+ ├── hcm-bundle/
22
+ │ ├── hcm.yaml # name: my-cli
23
+ │ └── skills/my-cli/SKILL.md
24
+ └── src/commands/hcm.js
25
+ ```
26
+
27
+ ```js
28
+ // src/commands/hcm.js: the "my-cli hcm init" and "my-cli hcm remove" subcommands.
29
+ import { spawnSync } from 'node:child_process';
30
+ import { existsSync } from 'node:fs';
31
+ import path from 'node:path';
32
+ import { fileURLToPath } from 'node:url';
33
+
34
+ const BUNDLE_NAME = 'my-cli';
35
+ // This file is in src/commands/, two levels below the package root. After
36
+ // "npm link", this is the folder of your checkout.
37
+ const BUNDLE_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'hcm-bundle');
38
+
39
+ const isWindows = process.platform === 'win32';
40
+
41
+ /**
42
+ * Run hcm. On Windows, npm installs hcm as hcm.cmd, and Node runs a .cmd file
43
+ * only through a shell. The shell splits arguments at spaces, so quote each one.
44
+ */
45
+ function hcm(args, options = {}) {
46
+ const quoted = isWindows ? args.map((arg) => `"${arg}"`) : args;
47
+ return spawnSync('hcm', quoted, { shell: isWindows, stdio: 'inherit', ...options });
48
+ }
49
+
50
+ /**
51
+ * "my-cli hcm init [--dev [path]] [--install ...]".
52
+ * `dev`: register the working copy in place. `devPath`: the path after --dev.
53
+ */
54
+ export function hcmInit({ install = false, installArgs = [], dev = false, devPath } = {}) {
55
+ const probe = hcm(['--version'], { stdio: 'pipe', encoding: 'utf8' });
56
+ if (probe.error || probe.status !== 0) {
57
+ console.error('my-cli: hcm is not installed. Install it with: npm install -g harness-config-manager');
58
+ return 1;
59
+ }
60
+
61
+ // A relative --dev path is read from the current folder.
62
+ const bundleDir = dev && devPath ? path.resolve(devPath) : BUNDLE_DIR;
63
+
64
+ if (dev) {
65
+ if (!existsSync(path.join(bundleDir, 'hcm.yaml'))) {
66
+ console.error(`my-cli: ${bundleDir} has no hcm.yaml. Give the bundle folder: my-cli hcm init --dev <path>`);
67
+ return 1;
68
+ }
69
+ // An installed copy does not change when you edit the working copy.
70
+ if (bundleDir.split(path.sep).includes('node_modules')) {
71
+ console.warn(
72
+ `my-cli: ${bundleDir} is an installed copy, not a working copy. ` +
73
+ 'Run "npm link" in your checkout, or give the path: my-cli hcm init --dev <path>',
74
+ );
75
+ }
76
+ }
77
+
78
+ const added = hcm(['registry', 'add', bundleDir, ...(dev ? ['--dev'] : [])]);
79
+ if (added.status !== 0) return added.status ?? 1;
80
+
81
+ if (install) return hcm(['install', BUNDLE_NAME, ...installArgs]).status ?? 1;
82
+
83
+ console.log(
84
+ dev
85
+ ? `Development mode: hcm reads ${bundleDir} in place. ` +
86
+ `After each edit, run "hcm update ${BUNDLE_NAME}" in each test project.`
87
+ : `Next: hcm install ${BUNDLE_NAME} -t <harness>`,
88
+ );
89
+ return 0;
90
+ }
91
+
92
+ export function hcmRemove() {
93
+ return hcm(['registry', 'remove', BUNDLE_NAME]).status ?? 1;
94
+ }
95
+ ```
96
+
97
+ A test that keeps the two versions equal:
98
+
99
+ ```js
100
+ import assert from 'node:assert/strict';
101
+ import { readFileSync } from 'node:fs';
102
+ import { test } from 'node:test';
103
+
104
+ test('the hcm bundle has the version of the package', () => {
105
+ const { version } = JSON.parse(readFileSync('package.json', 'utf8'));
106
+ const manifest = readFileSync('hcm-bundle/hcm.yaml', 'utf8');
107
+ assert.match(manifest, new RegExp(`^version: ${version.replace(/\./g, '\\.')}$`, 'm'));
108
+ });
109
+ ```
110
+
111
+ ## Python
112
+
113
+ Ship the bundle as package data. With setuptools:
114
+
115
+ ```toml
116
+ # pyproject.toml
117
+ [tool.setuptools.package-data]
118
+ my_cli = ["hcm_bundle/**/*"]
119
+ ```
120
+
121
+ ```python
122
+ # my_cli/hcm.py: the "my-cli hcm init" and "my-cli hcm remove" subcommands.
123
+ import shutil
124
+ import subprocess
125
+ import sys
126
+ from pathlib import Path
127
+
128
+ BUNDLE_NAME = "my-cli"
129
+ # The bundle folder is package data, beside this file. After
130
+ # "pip install -e .", this is the folder of your checkout.
131
+ BUNDLE_DIR = Path(__file__).resolve().parent / "hcm_bundle"
132
+
133
+
134
+ def _find_hcm() -> str | None:
135
+ # shutil.which also finds hcm.cmd on Windows.
136
+ return shutil.which("hcm")
137
+
138
+
139
+ def hcm_init(
140
+ install: bool = False,
141
+ install_args: list[str] | None = None,
142
+ dev: bool = False,
143
+ dev_path: str | None = None,
144
+ ) -> int:
145
+ """my-cli hcm init [--dev [path]] [--install ...]"""
146
+ hcm = _find_hcm()
147
+ if hcm is None:
148
+ print(
149
+ "my-cli: hcm is not installed. Install it with: npm install -g harness-config-manager",
150
+ file=sys.stderr,
151
+ )
152
+ return 1
153
+
154
+ # A relative --dev path is read from the current folder.
155
+ bundle_dir = Path(dev_path).resolve() if dev and dev_path else BUNDLE_DIR
156
+
157
+ if dev:
158
+ if not (bundle_dir / "hcm.yaml").is_file():
159
+ print(
160
+ f"my-cli: {bundle_dir} has no hcm.yaml. "
161
+ "Give the bundle folder: my-cli hcm init --dev <path>",
162
+ file=sys.stderr,
163
+ )
164
+ return 1
165
+ # An installed copy does not change when you edit the working copy.
166
+ if "site-packages" in bundle_dir.parts:
167
+ print(
168
+ f"my-cli: {bundle_dir} is an installed copy, not a working copy. "
169
+ 'Run "pip install -e ." in your checkout, or give the path: my-cli hcm init --dev <path>',
170
+ file=sys.stderr,
171
+ )
172
+
173
+ command = [hcm, "registry", "add", str(bundle_dir)]
174
+ if dev:
175
+ command.append("--dev")
176
+ added = subprocess.run(command)
177
+ if added.returncode != 0:
178
+ return added.returncode
179
+
180
+ if install:
181
+ return subprocess.run([hcm, "install", BUNDLE_NAME, *(install_args or [])]).returncode
182
+
183
+ if dev:
184
+ print(
185
+ f"Development mode: hcm reads {bundle_dir} in place. "
186
+ f'After each edit, run "hcm update {BUNDLE_NAME}" in each test project.'
187
+ )
188
+ else:
189
+ print(f"Next: hcm install {BUNDLE_NAME} -t <harness>")
190
+ return 0
191
+
192
+
193
+ def hcm_remove() -> int:
194
+ hcm = _find_hcm()
195
+ if hcm is None:
196
+ return 1
197
+ return subprocess.run([hcm, "registry", "remove", BUNDLE_NAME]).returncode
198
+ ```
199
+
200
+ ## Go (a single binary)
201
+
202
+ A binary has no package folder. Embed the bundle, and write it to a permanent
203
+ folder before you register it. `hcm update` reads that folder again, so do not
204
+ use a temporary folder.
205
+
206
+ In development mode, the binary cannot find your working copy. Thus the path
207
+ after `--dev` is mandatory.
208
+
209
+ ```go
210
+ // hcm.go: the "my-cli hcm init" subcommand.
211
+ package main
212
+
213
+ import (
214
+ "embed"
215
+ "fmt"
216
+ "io/fs"
217
+ "os"
218
+ "os/exec"
219
+ "path/filepath"
220
+ )
221
+
222
+ // The "all:" prefix also embeds files whose names start with "." or "_".
223
+ //
224
+ //go:embed all:hcmbundle
225
+ var bundleFS embed.FS
226
+
227
+ const bundleName = "my-cli"
228
+
229
+ // hcmInit runs "my-cli hcm init". A non-empty devPath, from
230
+ // "my-cli hcm init --dev <path>", registers that working copy in place.
231
+ func hcmInit(devPath string) error {
232
+ hcm, err := exec.LookPath("hcm") // also finds hcm.cmd on Windows
233
+ if err != nil {
234
+ return fmt.Errorf("hcm is not installed. Install it with: npm install -g harness-config-manager")
235
+ }
236
+
237
+ if devPath != "" {
238
+ return hcmInitDev(hcm, devPath)
239
+ }
240
+
241
+ cache, err := os.UserCacheDir()
242
+ if err != nil {
243
+ return err
244
+ }
245
+ dir := filepath.Join(cache, bundleName, "hcm-bundle")
246
+
247
+ // Replace the old version, so that files deleted from the bundle go too.
248
+ if err := os.RemoveAll(dir); err != nil {
249
+ return err
250
+ }
251
+ sub, err := fs.Sub(bundleFS, "hcmbundle")
252
+ if err != nil {
253
+ return err
254
+ }
255
+ if err := os.CopyFS(dir, sub); err != nil { // Go 1.23 or later
256
+ return err
257
+ }
258
+
259
+ if err := run(hcm, "registry", "add", dir); err != nil {
260
+ return err
261
+ }
262
+ fmt.Printf("Next: hcm install %s -t <harness>\n", bundleName)
263
+ return nil
264
+ }
265
+
266
+ // hcmInitDev registers a working copy with --dev, so that hcm reads it in place.
267
+ func hcmInitDev(hcm, devPath string) error {
268
+ dir, err := filepath.Abs(devPath)
269
+ if err != nil {
270
+ return err
271
+ }
272
+ if _, err := os.Stat(filepath.Join(dir, "hcm.yaml")); err != nil {
273
+ return fmt.Errorf("%s has no hcm.yaml. Give the bundle folder: my-cli hcm init --dev <path>", dir)
274
+ }
275
+ if err := run(hcm, "registry", "add", dir, "--dev"); err != nil {
276
+ return err
277
+ }
278
+ fmt.Printf("Development mode: hcm reads %s in place. "+
279
+ "After each edit, run \"hcm update %s\" in each test project.\n", dir, bundleName)
280
+ return nil
281
+ }
282
+
283
+ func run(name string, args ...string) error {
284
+ cmd := exec.Command(name, args...)
285
+ cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
286
+ return cmd.Run()
287
+ }
288
+ ```
289
+
290
+ For Rust, the `include_dir` crate embeds a folder. Use the same procedure.
291
+
292
+ ## Sync many test projects
293
+
294
+ After each edit of the bundle, run `hcm update` in each test project. Put the
295
+ list of projects in a script. Change the paths and the harness.
296
+
297
+ ```bash
298
+ #!/usr/bin/env bash
299
+ # sync-hcm.sh: install the latest files of the my-cli bundle into each test project.
300
+ projects=(~/work/app-a ~/work/app-b ~/work/app-c)
301
+ for project in "${projects[@]}"; do
302
+ echo "== $project"
303
+ (cd "$project" && hcm update my-cli -t claude-code --no-prompt) || echo "update failed in $project"
304
+ done
305
+ ```
306
+
307
+ ```powershell
308
+ # sync-hcm.ps1: install the latest files of the my-cli bundle into each test project.
309
+ $projects = 'C:\work\app-a', 'C:\work\app-b', 'C:\work\app-c'
310
+ foreach ($project in $projects) {
311
+ Write-Host "== $project"
312
+ Push-Location $project
313
+ hcm update my-cli -t claude-code --no-prompt
314
+ if ($LASTEXITCODE -ne 0) { Write-Warning "update failed in $project" }
315
+ Pop-Location
316
+ }
317
+ ```
318
+
319
+ The tool can also supply this as a subcommand, for example
320
+ `my-cli hcm sync <project...>`. The subcommand runs `hcm update my-cli` in each
321
+ folder, with the `cwd` option of the subprocess.
322
+
323
+ ## Test with a temporary hcm home
324
+
325
+ ```bash
326
+ export HCM_HOME="$(mktemp -d)" # the real registry of the user stays unchanged
327
+ my-cli hcm init
328
+ hcm registry list --json # lists my-cli, with the version of the tool
329
+ cd "$(mktemp -d)"
330
+ hcm install my-cli -t claude-code --no-prompt
331
+ hcm status
332
+ my-cli hcm init # again: the id of my-cli stays the same
333
+ my-cli hcm init --dev /path/to/checkout/hcm-bundle
334
+ hcm registry list --json # the same id, now with "dev": true
335
+ ```
336
+
337
+ `HCM_HOME` does not move the home folders of the harnesses. Do not use
338
+ `-s user` in a test. It writes into the real `~/.claude/` and similar folders.