agent-plugin-lifecycle 0.1.1 → 0.2.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # agent-plugin-lifecycle
2
2
 
3
- Run your own setup and cleanup commands when Agent Package Manager (APM) installs, updates or removes an agent plugin. APM copies a plugin into each agent harness but never runs the plugin's own code, so a plugin that needs `npm ci`, `uv sync` or any other setup arrives without it. `agent-plugin-lifecycle` is the hook APM calls after each event: it finds every copy APM deployed, runs the commands you configured for that plugin in each copy, and records whether they succeeded. Commands come only from your own config file, never from downloaded plugin files.
3
+ Run your own setup and cleanup commands when Agent Package Manager (APM) installs, updates or removes an agent plugin. APM copies a plugin into each agent harness but never runs the plugin's own code, so a plugin that needs `npm ci`, `uv sync` or any other setup arrives without it. `agent-plugin-lifecycle` is the hook APM calls after each event: it finds every copy APM deployed, runs the commands you configured for that plugin in each copy that needs it, and records whether they succeeded. Commands come only from your own config file, never from downloaded plugin files.
4
4
 
5
5
  Requires Node.js 22.18 or newer and APM.
6
6
 
@@ -13,19 +13,32 @@ agent-plugin-lifecycle --help
13
13
 
14
14
  ## Register the hook with APM
15
15
 
16
- Add the dispatcher to your user `~/.apm/apm.yml` for each event you want:
16
+ Add the dispatcher to your user `~/.apm/apm.yml` (or `$APM_HOME/apm.yml`) for each event you want:
17
17
 
18
18
  ```yaml
19
+ name: my-machine # APM requires name and version before the first install
20
+ version: 0.0.0
19
21
  lifecycle:
20
22
  post-install:
21
23
  - run: agent-plugin-lifecycle run
24
+ timeoutSec: 300
22
25
  post-update:
23
26
  - run: agent-plugin-lifecycle run
27
+ timeoutSec: 300
24
28
  post-uninstall:
25
29
  - run: agent-plugin-lifecycle run
30
+ timeoutSec: 300
31
+ dependencies:
32
+ apm:
33
+ - git: git@bitbucket.org:team/plugins.git
34
+ path: plugins/example
26
35
  ```
27
36
 
28
- It handles user-scope events; project-scope events are skipped.
37
+ - **`timeoutSec`**: APM stops a lifecycle command after 30 seconds unless the entry sets `timeoutSec` (seconds), kills it with everything it started, and still exits 0. One entry runs every configured command for the event, so give it enough time for all your installs.
38
+ - **SSH sources**: write the full `git@host:owner/repo.git` URL in `apm.yml`. The short `host/owner/repo` form that `apm install --ssh` writes is fetched over HTTPS on later runs.
39
+ - **Secrets**: APM removes environment variables whose names look like credentials (`NPM_TOKEN`, `*_API_KEY`, `*_PASSWORD` and similar) from lifecycle commands. If your commands need one, list it on the entry: `allowedEnvVars: [NPM_TOKEN]`.
40
+
41
+ The dispatcher handles user-scope events; project-scope events are skipped.
29
42
 
30
43
  ## Configure plugins
31
44
 
@@ -74,22 +87,55 @@ Then run `apm install` or `apm update` as usual; your commands run inside it.
74
87
 
75
88
  APM fires `post-update` when `apm update` moves a pinned source to a newer release tag. A source pinned to a commit in a repository without release tags does not move on `apm update`: change the pin and run `apm install --update`, which fires `post-install`. Either way your commands run, because `post-update` defaults to `post-install`.
76
89
 
90
+ ## Where and when the commands run
91
+
92
+ A command runs in each copy a harness reads: the skill folders APM deployed (`~/.agents/skills`, `~/.claude/skills`, `~/.hermes/skills`) and the native plugin folder (`~/.agents/plugins/<name>`). APM's own kept copy under `~/.apm/apm_modules/` is left alone, because a file written there makes the next `apm update` restore its cache and fire its events again. The one exception is a plugin whose only copy is the kept one (a target such as Copilot reads it in place); there the command runs in the kept copy.
93
+
94
+ A copy is skipped (`current` in the output) when the same command already succeeded there for the revision APM has locked (its commit and content hash). So an `apm update` with nothing new runs no command, and a changed plugin runs its command once per copy, even though APM fires both `post-install` and `post-update`.
95
+
96
+ APM runs the command after it has written the new plugin files into the copy, and waits for it to finish before the APM command returns. For that time the copy holds the new files next to the packages from the previous version, and if the command deletes and rebuilds them, as `npm ci` does, the copy has no packages until it finishes: a fraction of a second to a few seconds per copy, only when the plugin changed. A command may build its packages in another folder and rename them into place to shorten that gap; two renames still leave a short one.
97
+
77
98
  ## Check the result
78
99
 
100
+ Each time it runs your command in a copy, `agent-plugin-lifecycle` records whether the command exited successfully there. `agent-plugin-lifecycle check` prints that record, one line per copy, and exits 1 if any copy is not `ok`:
101
+
79
102
  ```sh
80
103
  agent-plugin-lifecycle check
81
104
  ```
82
105
 
83
- Prints `ok` or `missing` for every deployed copy of every installed, configured record, and exits 1 if any copy is `missing` (the current command never succeeded there). APM reports a failing hook as a warning and still finishes, so use `check` wherever a script needs a definite answer. To fix a record, correct its command and run `apm install` again.
106
+ | Status | Meaning |
107
+ |---|---|
108
+ | `ok` | Your current command succeeded in this copy for the version APM has installed |
109
+ | `missing` | It has not succeeded in this copy |
110
+ | `stale` | It last succeeded for an older version of the plugin, or an older command |
111
+ | `broken` | It succeeded, but the copy is gone |
112
+
113
+ With nothing installed it prints `nothing installed` and exits 0. It reports only what your commands did; it does not test the plugin itself.
114
+
115
+ Why it exists: when your command fails or runs past its `timeoutSec`, APM prints a warning and still exits 0, so a script cannot tell from APM alone. Run `check` after `apm install` or `apm update` in a script or scheduled job:
116
+
117
+ ```sh
118
+ apm update -g --yes && agent-plugin-lifecycle check
119
+ ```
120
+
121
+ When you run APM yourself and read its output, you do not need it. To fix a failed copy, correct the command and run `apm install` again.
122
+
123
+ ## Uninstall
124
+
125
+ APM keeps a skill or plugin folder that still holds files it did not write, such as the `node_modules` your command made, and says so. Before running the record's `post-uninstall` command, the dispatcher prints `left <path>` for each such copy; it deletes nothing. Remove those folders yourself, or have `post-uninstall` remove them.
84
126
 
85
127
  ## Rules for commands
86
128
 
87
129
  - A command is a string run through the platform shell (like an npm script), exactly as written; nothing from APM or the plugin is substituted into it. Quoting and syntax follow that machine's shell.
88
- - Make each command safe to repeat: it runs on every install and update.
130
+ - Make each command safe to repeat: it runs again whenever APM changes the plugin, and whenever a copy is recreated.
89
131
  - For npm inside a Claude Code plugin copy use `--no-bin-links` (or `npm_config_bin_links=false`). APM refuses later installs when that copy contains a symlink, and `node_modules/.bin` would add one.
90
132
  - A local `source` is the absolute path exactly as written in `apm.yml`.
91
133
  - `post-uninstall` runs from your home folder after the plugin's files are gone, so it can only use files you keep outside the plugin.
92
134
 
135
+ ## Upgrading from 0.1
136
+
137
+ The first `apm install` or `apm update` after upgrading runs each command once more in every copy, to record the locked revision; after that, unchanged copies are skipped. Commands no longer run in APM's kept copy when another copy exists; a `node_modules` folder an earlier version left there can be deleted.
138
+
93
139
  ## Agent skill
94
140
 
95
141
  ```sh