agent-plugin-lifecycle 0.1.1 → 0.3.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 (178) hide show
  1. package/README.md +256 -57
  2. package/bin/cli.js +8 -1
  3. package/dist/cjs/apm.d.cts +62 -13
  4. package/dist/cjs/apm.d.ts +62 -13
  5. package/dist/cjs/apm.js +534 -115
  6. package/dist/cjs/apm.js.map +1 -1
  7. package/dist/cjs/approvals.d.cts +26 -0
  8. package/dist/cjs/approvals.d.ts +26 -0
  9. package/dist/cjs/approvals.js +302 -0
  10. package/dist/cjs/approvals.js.map +1 -0
  11. package/dist/cjs/cli/index.d.cts +5 -0
  12. package/dist/cjs/cli/index.d.ts +5 -0
  13. package/dist/cjs/cli/index.js +53 -0
  14. package/dist/cjs/cli/index.js.map +1 -0
  15. package/dist/cjs/cli/install.d.cts +17 -0
  16. package/dist/cjs/cli/install.d.ts +17 -0
  17. package/dist/cjs/cli/install.js +308 -0
  18. package/dist/cjs/cli/install.js.map +1 -0
  19. package/dist/cjs/cli/report.d.cts +6 -0
  20. package/dist/cjs/cli/report.d.ts +6 -0
  21. package/dist/cjs/cli/report.js +47 -0
  22. package/dist/cjs/cli/report.js.map +1 -0
  23. package/dist/cjs/cli/status.d.cts +2 -0
  24. package/dist/cjs/cli/status.d.ts +2 -0
  25. package/dist/cjs/cli/status.js +222 -0
  26. package/dist/cjs/cli/status.js.map +1 -0
  27. package/dist/cjs/cli/types.d.cts +10 -0
  28. package/dist/cjs/cli/types.d.ts +10 -0
  29. package/dist/cjs/cli/types.js +6 -0
  30. package/dist/cjs/cli/types.js.map +1 -0
  31. package/dist/cjs/cli/usage.d.cts +2 -0
  32. package/dist/cjs/cli/usage.d.ts +2 -0
  33. package/dist/cjs/cli/usage.js +21 -0
  34. package/dist/cjs/cli/usage.js.map +1 -0
  35. package/dist/cjs/cli.d.cts +2 -1
  36. package/dist/cjs/cli.d.ts +2 -1
  37. package/dist/cjs/cli.js +65 -204
  38. package/dist/cjs/cli.js.map +1 -1
  39. package/dist/cjs/constants.d.cts +35 -0
  40. package/dist/cjs/constants.d.ts +35 -0
  41. package/dist/cjs/constants.js +115 -0
  42. package/dist/cjs/constants.js.map +1 -0
  43. package/dist/cjs/copies.d.cts +40 -0
  44. package/dist/cjs/copies.d.ts +40 -0
  45. package/dist/cjs/copies.js +937 -0
  46. package/dist/cjs/copies.js.map +1 -0
  47. package/dist/cjs/index.d.cts +3 -6
  48. package/dist/cjs/index.d.ts +3 -6
  49. package/dist/cjs/index.js +20 -19
  50. package/dist/cjs/index.js.map +1 -1
  51. package/dist/cjs/install.d.cts +6 -0
  52. package/dist/cjs/install.d.ts +6 -0
  53. package/dist/cjs/install.js +511 -0
  54. package/dist/cjs/install.js.map +1 -0
  55. package/dist/cjs/lib/errors.d.cts +5 -0
  56. package/dist/cjs/lib/errors.d.ts +5 -0
  57. package/dist/cjs/lib/errors.js +41 -0
  58. package/dist/cjs/lib/errors.js.map +1 -0
  59. package/dist/cjs/lib/object.d.cts +2 -0
  60. package/dist/cjs/lib/object.d.ts +2 -0
  61. package/dist/cjs/lib/object.js +18 -0
  62. package/dist/cjs/lib/object.js.map +1 -0
  63. package/dist/cjs/lib/options.d.cts +10 -0
  64. package/dist/cjs/lib/options.d.ts +10 -0
  65. package/dist/cjs/lib/options.js +26 -0
  66. package/dist/cjs/lib/options.js.map +1 -0
  67. package/dist/cjs/lib/run.d.cts +2 -0
  68. package/dist/cjs/lib/run.d.ts +2 -0
  69. package/dist/cjs/lib/run.js +40 -0
  70. package/dist/cjs/lib/run.js.map +1 -0
  71. package/dist/cjs/lib/store.d.cts +9 -0
  72. package/dist/cjs/lib/store.d.ts +9 -0
  73. package/dist/cjs/lib/store.js +418 -0
  74. package/dist/cjs/lib/store.js.map +1 -0
  75. package/dist/cjs/lib/visible.d.cts +9 -0
  76. package/dist/cjs/lib/visible.d.ts +9 -0
  77. package/dist/cjs/lib/visible.js +26 -0
  78. package/dist/cjs/lib/visible.js.map +1 -0
  79. package/dist/cjs/manifest.d.cts +4 -0
  80. package/dist/cjs/manifest.d.ts +4 -0
  81. package/dist/cjs/{config.js → manifest.js} +33 -94
  82. package/dist/cjs/manifest.js.map +1 -0
  83. package/dist/cjs/state.d.cts +17 -0
  84. package/dist/cjs/state.d.ts +17 -0
  85. package/dist/cjs/state.js +143 -0
  86. package/dist/cjs/state.js.map +1 -0
  87. package/dist/cjs/status.d.cts +3 -0
  88. package/dist/cjs/status.d.ts +3 -0
  89. package/dist/cjs/status.js +273 -0
  90. package/dist/cjs/status.js.map +1 -0
  91. package/dist/cjs/types.d.cts +39 -0
  92. package/dist/cjs/types.d.ts +39 -0
  93. package/dist/cjs/types.js +5 -0
  94. package/dist/cjs/types.js.map +1 -0
  95. package/dist/esm/apm.d.ts +62 -13
  96. package/dist/esm/apm.js +208 -96
  97. package/dist/esm/apm.js.map +1 -1
  98. package/dist/esm/approvals.d.ts +26 -0
  99. package/dist/esm/approvals.js +43 -0
  100. package/dist/esm/approvals.js.map +1 -0
  101. package/dist/esm/cli/index.d.ts +5 -0
  102. package/dist/esm/cli/index.js +5 -0
  103. package/dist/esm/cli/index.js.map +1 -0
  104. package/dist/esm/cli/install.d.ts +17 -0
  105. package/dist/esm/cli/install.js +89 -0
  106. package/dist/esm/cli/install.js.map +1 -0
  107. package/dist/esm/cli/report.d.ts +6 -0
  108. package/dist/esm/cli/report.js +21 -0
  109. package/dist/esm/cli/report.js.map +1 -0
  110. package/dist/esm/cli/status.d.ts +2 -0
  111. package/dist/esm/cli/status.js +41 -0
  112. package/dist/esm/cli/status.js.map +1 -0
  113. package/dist/esm/cli/types.d.ts +10 -0
  114. package/dist/esm/cli/types.js +2 -0
  115. package/dist/esm/cli/types.js.map +1 -0
  116. package/dist/esm/cli/usage.d.ts +2 -0
  117. package/dist/esm/cli/usage.js +2 -0
  118. package/dist/esm/cli/usage.js.map +1 -0
  119. package/dist/esm/cli.d.ts +2 -1
  120. package/dist/esm/cli.js +46 -65
  121. package/dist/esm/cli.js.map +1 -1
  122. package/dist/esm/constants.d.ts +35 -0
  123. package/dist/esm/constants.js +37 -0
  124. package/dist/esm/constants.js.map +1 -0
  125. package/dist/esm/copies.d.ts +40 -0
  126. package/dist/esm/copies.js +226 -0
  127. package/dist/esm/copies.js.map +1 -0
  128. package/dist/esm/index.d.ts +3 -6
  129. package/dist/esm/index.js +3 -3
  130. package/dist/esm/index.js.map +1 -1
  131. package/dist/esm/install.d.ts +6 -0
  132. package/dist/esm/install.js +116 -0
  133. package/dist/esm/install.js.map +1 -0
  134. package/dist/esm/lib/errors.d.ts +5 -0
  135. package/dist/esm/lib/errors.js +9 -0
  136. package/dist/esm/lib/errors.js.map +1 -0
  137. package/dist/esm/lib/object.d.ts +2 -0
  138. package/dist/esm/lib/object.js +3 -0
  139. package/dist/esm/lib/object.js.map +1 -0
  140. package/dist/esm/lib/options.d.ts +10 -0
  141. package/dist/esm/lib/options.js +15 -0
  142. package/dist/esm/lib/options.js.map +1 -0
  143. package/dist/esm/lib/run.d.ts +2 -0
  144. package/dist/esm/lib/run.js +29 -0
  145. package/dist/esm/lib/run.js.map +1 -0
  146. package/dist/esm/lib/store.d.ts +9 -0
  147. package/dist/esm/lib/store.js +91 -0
  148. package/dist/esm/lib/store.js.map +1 -0
  149. package/dist/esm/lib/visible.d.ts +9 -0
  150. package/dist/esm/lib/visible.js +12 -0
  151. package/dist/esm/lib/visible.js.map +1 -0
  152. package/dist/esm/manifest.d.ts +4 -0
  153. package/dist/esm/manifest.js +25 -0
  154. package/dist/esm/manifest.js.map +1 -0
  155. package/dist/esm/state.d.ts +17 -0
  156. package/dist/esm/state.js +32 -0
  157. package/dist/esm/state.js.map +1 -0
  158. package/dist/esm/status.d.ts +3 -0
  159. package/dist/esm/status.js +44 -0
  160. package/dist/esm/status.js.map +1 -0
  161. package/dist/esm/types.d.ts +39 -0
  162. package/dist/esm/types.js +1 -0
  163. package/dist/esm/types.js.map +1 -0
  164. package/package.json +25 -9
  165. package/config/config.example.json +0 -22
  166. package/dist/cjs/config.d.cts +0 -16
  167. package/dist/cjs/config.d.ts +0 -16
  168. package/dist/cjs/config.js.map +0 -1
  169. package/dist/cjs/runner.d.cts +0 -19
  170. package/dist/cjs/runner.d.ts +0 -19
  171. package/dist/cjs/runner.js +0 -1157
  172. package/dist/cjs/runner.js.map +0 -1
  173. package/dist/esm/config.d.ts +0 -16
  174. package/dist/esm/config.js +0 -74
  175. package/dist/esm/config.js.map +0 -1
  176. package/dist/esm/runner.d.ts +0 -19
  177. package/dist/esm/runner.js +0 -248
  178. package/dist/esm/runner.js.map +0 -1
package/README.md CHANGED
@@ -1,94 +1,293 @@
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
+ Lets an agent plugin or skill ship its own setup command, and runs it on your machine only after you approve it. The author puts an `apl.json` beside the plugin or skill:
4
4
 
5
- Requires Node.js 22.18 or newer and APM.
5
+ ```json
6
+ { "scripts": { "install": "npm ci --no-bin-links" } }
7
+ ```
8
+
9
+ An installer puts one copy of a plugin or skill in the folder of each agent harness (the agent tool that loads it, such as Claude Code, Copilot or Codex). The `apl` command finds each of those copies, asks you once per project (or once for your user install) whether to run the command, and runs it in each copy. After that, Agent Package Manager (APM) can call `apl install` after every install and update, so approved scripts run on their own and a changed plugin runs again once. Nothing runs that you have not approved, and you are asked again when the command changes ([Security model](#security-model)).
10
+
11
+ Installers copy plugins and skills into each harness but run none of their code: APM, the skills CLI, Claude Code and Codex all leave a plugin that needs `npm ci`, `uv sync` or any other setup without it. `apl` fills that gap.
12
+
13
+ Works with:
14
+
15
+ | Installer | How `apl` finds the copies | Runs on its own |
16
+ |---|---|---|
17
+ | [Agent Package Manager (APM)](https://github.com/microsoft/apm), `apm`; tested with APM 0.39.1 | APM's lock file, at project and user (`-g`) scope | yes, from APM's `post-install` entry |
18
+ | [The skills CLI](https://github.com/vercel-labs/skills), `npx skills add` | you name the folders | no: it has no install hook |
19
+ | Claude Code, Codex, or copying by hand | you name the folders | no |
6
20
 
7
- ## Install
21
+ Requires Node.js 22.18 or newer, on macOS, Linux or Windows.
8
22
 
9
23
  ```sh
10
- npm install -g agent-plugin-lifecycle
11
- agent-plugin-lifecycle --help
24
+ npm install -g agent-plugin-lifecycle # installs the `apl` command (also as `agent-plugin-lifecycle`)
25
+ apl --help
12
26
  ```
13
27
 
14
- ## Register the hook with APM
28
+ The npm package `apl` belongs to someone else: install `agent-plugin-lifecycle`, or run it once with `npx agent-plugin-lifecycle`. Coming from 0.2.0: follow the [upgrade steps](CHANGELOG.md#upgrading-from-02) once on each machine.
29
+
30
+ ## For plugin and skill authors: add `apl.json`
31
+
32
+ Put `apl.json` in the folder that needs the setup:
33
+
34
+ - a skill: beside its `SKILL.md` (`skills/<name>/apl.json`). It arrives in every copy of the skill an installer deploys.
35
+ - a plugin: at the plugin root (beside `plugin.json`, or beside `.claude-plugin/` for a Claude Code plugin), not inside `.claude-plugin/`. It arrives in the plugin's native copy (`.agents/plugins/<name>/`).
36
+
37
+ | Field | Meaning |
38
+ |---|---|
39
+ | `scripts.install` | A nonempty command string. Runs after the plugin or skill is installed and after it is updated. |
40
+
41
+ Unknown fields and other script names are ignored. A file with no `scripts.install` has nothing to run.
42
+
43
+ Rules for the command:
44
+
45
+ - It runs through the platform shell (`sh`, or `cmd.exe` on Windows), exactly as written, with the folder that holds `apl.json` as its working directory. Write it for both shells if your users run both, or call a script: `node setup.js`.
46
+ - Standard input is closed. Its output, standard output included, goes to `apl`'s standard error.
47
+ - Make it safe to repeat, as `npm ci` and `uv sync` are. It runs again in each copy when the plugin changes or a copy is recreated.
48
+ - For npm in a plugin copy use `npm ci --no-bin-links`. APM refuses later installs of a copy that contains a symlink, and `node_modules/.bin` would add one.
49
+ - Do not put `apl.json` under `.apm/`, which APM strips from deployed copies. An `apl.json` at the root of a repository of plain skills reaches no skill copy, only APM's cache, so it is reported `skipped` and never runs; put it in each `skills/<name>/`.
50
+ - Changing the command makes every user approve it again.
51
+
52
+ Check it on your own copy: name the folder, approve with `-y`, then ask for its status. Your script's output comes first, then `apl`'s line:
53
+
54
+ ```console
55
+ $ apl install -y skills/report
56
+ added 12 packages in 1s
57
+ ran /Users/me/team-skills/skills/report /Users/me/team-skills/skills/report
58
+ $ apl status skills/report
59
+ ok /Users/me/team-skills/skills/report /Users/me/team-skills/skills/report
60
+ ```
61
+
62
+ A misspelt key, such as `postinstall`, gives `failed …: apl.json has no scripts.install` instead.
63
+
64
+ ## For machine owners: approve and run
65
+
66
+ ### With Agent Package Manager (APM)
15
67
 
16
- Add the dispatcher to your user `~/.apm/apm.yml` for each event you want:
68
+ Install a plugin or skill with APM as usual, in a project or with `-g` for your user:
69
+
70
+ ```sh
71
+ apm install team/skills
72
+ ```
73
+
74
+ Register `apl install` once in your user `~/.apm/apm.yml`. The entry fires for project installs and for `-g` installs alike, and APM fires `post-install` on every update too:
17
75
 
18
76
  ```yaml
77
+ name: my-machine # APM requires name and version in this file
78
+ version: 0.0.0
19
79
  lifecycle:
20
80
  post-install:
21
- - run: agent-plugin-lifecycle run
22
- post-update:
23
- - run: agent-plugin-lifecycle run
24
- post-uninstall:
25
- - run: agent-plugin-lifecycle run
81
+ - run: apl install
82
+ timeoutSec: 300
83
+ ```
84
+
85
+ - **`timeoutSec`**: APM kills a lifecycle command after 30 seconds unless the entry sets `timeoutSec`, and still exits 0. One `apl install` runs every script that is due, so allow time for all of them.
86
+ - **Secrets**: APM removes environment variables whose names look like credentials (`NPM_TOKEN`, `*_API_KEY`, `*_PASSWORD` and similar) from lifecycle commands. If a script needs one, list it on the entry: `allowedEnvVars: [NPM_TOKEN]`.
87
+ - APM writes the command's output to `~/.apm/logs/scripts.log`, not to your terminal.
88
+
89
+ Check the registration: `apm lifecycle` lists the entry (`post-install | command | apl install | user`).
90
+
91
+ The first time in each project, APM's run has no terminal, so `apl` approves nothing and APM prints:
92
+
93
+ ```
94
+ [!] Lifecycle post-install command script exited with code 1; continuing. Output: /Users/me/.apm/logs/scripts.log
26
95
  ```
27
96
 
28
- It handles user-scope events; project-scope events are skipped.
97
+ That is `apl` reporting a script waiting for your approval. Run `apl install` yourself, in the project (or with `-g` for a user install). It asks once per plugin or skill:
29
98
 
30
- ## Configure plugins
99
+ ```console
100
+ $ apl install
101
+ github.com/team/skills:skills/report wants to run
102
+ install: npm ci --no-bin-links
103
+ in
104
+ /Users/me/project/.agents/skills/report
105
+ /Users/me/project/.claude/skills/report
106
+ Run it? [y/N] y
107
+ added 12 packages in 1s
108
+ ran github.com/team/skills:skills/report /Users/me/project/.agents/skills/report
109
+ added 12 packages in 1s
110
+ ran github.com/team/skills:skills/report /Users/me/project/.claude/skills/report
111
+ ```
112
+
113
+ From then on APM's entry runs it: approved scripts run in every new or changed copy, and APM's own run never asks, so a script you have not approved is only reported (the same line from APM again). Check the result after APM:
114
+
115
+ ```sh
116
+ apm update && apl status
117
+ ```
118
+
119
+ `apl install -y` approves every unapproved script without asking and saves those approvals, for CI or a machine you set up from a script. All questions come before any script runs, and the approvals are saved after the last one: Ctrl+C at any question stops `apl` (exit 130) with nothing saved and nothing run.
120
+
121
+ ### With the skills CLI (`npx skills`)
122
+
123
+ The skills CLI has no install hook, so you run `apl` on the folders it creates. It writes the skill once under `.agents/skills/<name>` and links each other agent's folder to it (`.claude/skills/<name>` for Claude Code):
124
+
125
+ ```console
126
+ $ npx skills add team/skills --skill report -a claude-code -a codex
127
+ $ apl install .agents/skills/report .claude/skills/report
128
+ /Users/me/project/.agents/skills/report wants to run
129
+ install: npm ci --no-bin-links
130
+ in
131
+ /Users/me/project/.agents/skills/report
132
+ Run it? [y/N] y
133
+ added 12 packages in 1s
134
+ ran /Users/me/project/.agents/skills/report /Users/me/project/.agents/skills/report
135
+ $ apl status .agents/skills/report .claude/skills/report
136
+ ok /Users/me/project/.agents/skills/report /Users/me/project/.agents/skills/report
137
+ ```
31
138
 
32
- Put your commands in `~/.config/agent-plugin-lifecycle/config.json`:
139
+ The link resolves to the same folder, so it is one copy: one question, one line. With Claude Code alone (`-a claude-code`), the skills CLI copies the skill straight into `.claude/skills/<name>`; name that folder. With `-g`, the skills CLI writes under your home instead (`~/.agents/skills/report`, `~/.claude/skills/report`); name those folders. After `npx skills update`, run the same `apl install` again: a named folder's script runs every time you name it, because there is no installed revision to compare.
140
+
141
+ A named folder is its own id and place, so its path appears twice in each line. Each folder must hold an `apl.json` with a `scripts.install`. A folder named twice, also through a link, runs once.
142
+
143
+ ### Any other installer, or by hand
144
+
145
+ For Claude Code, Codex, a skill you copied, or any other installer, name the folders the same way: `apl install <folder>...`, then `apl status <folder>...`.
146
+
147
+ ## Security model
148
+
149
+ `apl` combines the install-script approval model of npm and other package managers with APM's rules for lifecycle trust:
150
+
151
+ - **Blocked by default.** No script runs until you approve it, the same default as npm's `allowScripts`, pnpm's `allowBuilds`, Bun's `trustedDependencies` and Deno's `allowScripts`.
152
+ - **You approve the exact command.** The question shows the command text, and a changed command is asked again.
153
+ - **An approval belongs to one place:** one project, your user install, or one named folder. As in npm, where `allowScripts` belongs to the project being installed, approving a skill in one project approves it nowhere else.
154
+ - **Approvals are stored per user in `~/.apl`, never in the project.** This is APM's rule for its own lifecycle trust: a file in the project could be committed by its author, so a cloned project could approve its own scripts. Also, `apl.json` ships inside each plugin or skill, so a project has no `apl` file of its own, where npm has `package.json`.
155
+ - **`~/.apl` must be yours.** On macOS and Linux, `apl` stops (exit 2) when `~/.apl` or a file in it is not owned by you or is writable by group or others, as OpenSSH does for `~/.ssh`. Fix it with `chmod go-w`.
156
+ - **Nothing is approved silently.** When APM runs `apl` there is no terminal, so `apl` asks nothing and runs only what is already approved. `-y` is the one explicit way to approve without a question.
157
+ - **`-y` approves everything unapproved at that moment, and saves it.** When an agent runs `apl install -y`, the agent approves for you: keep that command on ask in your agent's permissions, or run `apl install` yourself in a terminal.
158
+ - **Approval covers the command, not the version or the files it runs.** npm pins an approval to the version by default; `apl` does not pin the revision, because APM's run cannot ask: an update with the same command runs without a question. A new version can also change what `npm ci` installs without changing the command.
159
+ - **The id is a claim made by the lock.** It is the source APM's lock records; `apl` does not verify that a folder's content came from it. After you approve in a project, anyone who can change that project's lock file or its deployed folders can run code under that approval at the next install, as anyone who can change `package.json` can in npm: approve only in projects whose changes you trust.
160
+
161
+ ## Which copies `apl` uses
162
+
163
+ With no folder, `apl` reads APM's lock file and looks for `apl.json` in each copy it names:
164
+
165
+ | Scope | Lock file | Copies |
166
+ |---|---|---|
167
+ | Project (default) | `./apm.lock.yaml` | under the current folder |
168
+ | User (`-g`, or `apl` run in the APM home, as APM runs it for `-g`) | `$APM_HOME/apm.lock.yaml`, default `~/.apm/apm.lock.yaml` | under your home folder |
169
+
170
+ With no folder and no `-g`, the current folder must hold an `apm.lock.yaml`; otherwise `apl` stops with `no apm.lock.yaml here: pass -g or a folder`.
171
+
172
+ The copies are the folders APM recorded in the lock:
173
+
174
+ - each skill folder APM deployed (`deployed_files`), wherever the harness keeps it, including a folder moved by `CLAUDE_CONFIG_DIR`;
175
+ - the native plugin folder (`native_plugin.root`, `.agents/plugins/<name>`), and each `skills/<name>/` inside it.
176
+
177
+ Scripts found through APM's lock never run in APM's cache (`apm_modules/`), because APM restores it on the next `apm update`, deleting the script's output:
178
+
179
+ - a lock entry or a link that points into the cache is not run;
180
+ - an `apl.json` in the cache that no recorded folder carries (the package root's, or a skill's) is reported `skipped` (`APM's cache is the only copy; scripts do not run there`);
181
+ - a folder you name yourself runs wherever it is.
182
+
183
+ Paths and links:
184
+
185
+ - In a project lock every recorded path must be relative; otherwise the lock is unreadable (exit 2).
186
+ - A folder the lock names is not read or run when its real path, after following links, is outside the project. At user scope a relative path must stay inside your home in the same way.
187
+ - At user scope an absolute path APM recorded, such as a `CLAUDE_CONFIG_DIR` outside your home, is used as it is, since that lock is your own file written by APM.
188
+ - A copy's `apl.json` that is a link to a file outside the project (or, for a relative path at user scope, outside your home) is refused the same way.
189
+ - A refused copy is reported `failed` (`resolves to …, outside …`); a refused folder only when its target holds an `apl.json`.
190
+
191
+ Two more cases fail without running anything:
192
+
193
+ - When copies of one id carry different commands, each is reported `failed` (`copies of <id> disagree on install`) and nothing is asked for them.
194
+ - A lock row `apl` cannot use for another reason (a field of the wrong type, no revision) is one `failed` line naming the row and the lock; the other rows carry on.
195
+
196
+ ## Approvals
197
+
198
+ You approve an **id** in a **place**. The approval covers every copy with that id in that place, and nothing anywhere else:
199
+
200
+ | Copy found through | Id | Example |
201
+ |---|---|---|
202
+ | APM, Git source | `<host>/<repo>`, then `/<path>` for a plugin in a subfolder, then `:<folder>` when `apl.json` is below the package root | `github.com/vercel-labs/skills:skills/find-skills` |
203
+ | APM, local path | the absolute source path, then `:<folder>` | `/Users/me/plugins/demo:skills/hello` |
204
+ | Named folder | the folder's real absolute path | `/Users/me/project/.claude/skills/report` |
205
+
206
+ | Run | Place |
207
+ |---|---|
208
+ | A project | the real path of the project folder (the one holding `apm.lock.yaml`) |
209
+ | The user scope (`-g`) | the real path of the APM home, default `~/.apm` |
210
+ | A named folder | the folder's real path (the same as its id) |
211
+
212
+ So the same plugin is approved separately in each project and for your user install, and a project you clone cannot run a script by naming a source you approved somewhere else. A project you move or clone again is a new place and is asked again.
213
+
214
+ A script runs only when `~/.apl/approvals.json` holds, under the copy's place, the exact command text for its id:
33
215
 
34
216
  ```json
35
217
  {
36
218
  "version": 1,
37
- "plugins": [
38
- {
39
- "source": "git@bitbucket.org:team/plugins.git",
40
- "path": "plugins/example",
41
- "post-install": "npm ci --prefix server --no-bin-links",
42
- "post-uninstall": "node .config/agent-plugin-lifecycle/cleanup-example.js"
43
- },
44
- {
45
- "source": "git@bitbucket.org:team/plugins.git",
46
- "path": "plugins/example",
47
- "skill": "hello-node",
48
- "post-install": "npm ci --no-bin-links"
219
+ "approvals": {
220
+ "/Users/me/project": {
221
+ "github.com/team/skills:skills/report": {
222
+ "scripts": { "install": "npm ci --no-bin-links" },
223
+ "approved": "2026-11-26T20:15:00.000Z"
224
+ }
49
225
  }
50
- ]
226
+ }
51
227
  }
52
228
  ```
53
229
 
54
- Each record names one plugin or skill:
230
+ Answering anything but `y` saves nothing, and you are asked again next time. A script you never want stays `unapproved`: uninstall the plugin, or accept that `apl status` exits 1. To revoke an approval, delete its entry. Approvals belong to you and are never read from a project.
55
231
 
56
- | Field | Meaning |
57
- |---|---|
58
- | `source` | Git URL, or the absolute local path written in the plugin's `apm.yml` dependency |
59
- | `path` | Relative folder of the plugin inside the repository; default `.` |
60
- | `skill` | Run in each deployed copy of this skill instead of the whole plugin |
61
- | `post-install` | Runs in each deployed copy after install |
62
- | `post-update` | Runs in each deployed copy after update; defaults to `post-install` |
63
- | `post-uninstall` | Runs once after APM removes the plugin |
232
+ `~/.apl/state.json` records the last successful run in each copy (command, and the revision APM locked), so a copy that is already current is skipped. The record is removed while a script runs, so a failed or killed run leaves the copy `missing`. Both files are private to you (`0700` folder, `0600` files on macOS and Linux).
64
233
 
65
- A repository of plain skills (`skills/<name>/SKILL.md`, no plugin manifest) works the same way: select the skills on its `apm.yml` entry with `skills: [name]` (what `apm install owner/repo --skill name` writes), and give each one a record with `source` and `skill`, no `path`:
234
+ ## Commands
66
235
 
67
- ```json
68
- { "source": "https://github.com/team/skills.git", "skill": "report", "post-install": "npm ci --no-bin-links" }
69
236
  ```
237
+ apl install [-g] [-y] [folder...] Run install scripts, asking before any that are not approved
238
+ apl status [-g] [folder...] Report each copy; exit 1 unless every copy is ok
239
+ apl --help | -h
240
+ apl --version | -v
241
+ ```
242
+
243
+ | Flag | Meaning |
244
+ |---|---|
245
+ | `-g`, `--global` | The user scope (`~/.apm`) instead of the project in the current folder, as with APM's `-g`. Not allowed with folders. |
246
+ | `-y`, `--yes` | `install` only: approve every unapproved script without asking, and save the approvals. |
70
247
 
71
- A full example is in [config/config.example.json](config/config.example.json).
248
+ `apl install` asks only when standard input and output are a terminal. It prints one line per copy, each as soon as its result is known (so it follows its script's output, and a run APM kills still shows what finished), or `nothing installed`. Standard output holds only these lines; scripts print to standard error.
72
249
 
73
- Then run `apm install` or `apm update` as usual; your commands run inside it.
250
+ | Line | Meaning |
251
+ |---|---|
252
+ | `ran <id> <folder>` | The script succeeded and the run was recorded. |
253
+ | `current <id> <folder>` | Already succeeded for this command and revision; skipped. |
254
+ | `unapproved <id> <folder>` | Not approved; not run. |
255
+ | `failed <id> <folder>: <reason>` | The script exited non-zero, `apl.json` is invalid, the folder links outside the scope, copies of the id disagree on the command, a lock row cannot be used, or a named folder has no `apl.json` or no `scripts.install`. |
256
+ | `skipped <id> <folder>: <reason>` | APM's cache is the only copy; scripts do not run there. |
74
257
 
75
- 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`.
258
+ `apl status` changes nothing:
76
259
 
77
- ## Check the result
260
+ | Line | Meaning |
261
+ |---|---|
262
+ | `ok <id> <folder>` | The current command succeeded here for the installed revision. |
263
+ | `missing <id> <folder>` | Approved, but it has not succeeded here. |
264
+ | `stale <id> <folder>` | It last succeeded for an older revision or an older command. |
265
+ | `unapproved <id> <folder>` | The command is not approved. |
266
+ | `failed <id> <folder>: <reason>` | `apl.json` is invalid, the folder links outside the scope, copies of the id disagree on the command, a lock row cannot be used, or a named folder has no `apl.json` or no `scripts.install`. |
267
+ | `skipped <id> <folder>: <reason>` | APM's cache is the only copy; scripts do not run there. |
268
+ | `left <folder>` | A folder a script ran in whose package APM has since removed. APM keeps a folder that holds files it did not write, such as `node_modules`; remove it yourself. |
78
269
 
79
- ```sh
80
- agent-plugin-lifecycle check
81
- ```
270
+ Everything `apl` prints from a plugin, a lock or a folder name is escaped: the question (id, command, folders), every result line (id, folder, reason) and the error message of exit code 2. A value prints as it is when every character is printable ASCII, it has no leading or trailing space and it does not start with `"`; in a result line, an id or folder must also have no space. Any other value prints as a JSON string (the form a command has in `apl.json`), with every other character escaped in ASCII. So a Windows path or a command with quotes reads as written, a field that starts with `"` is always a JSON string, and the text you approve is the text that runs.
82
271
 
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.
272
+ | Exit code | Meaning |
273
+ |---|---|
274
+ | 0 | Every copy is `ran`, `current`, `ok` or `skipped` (`left` lines do not count), or nothing is installed. |
275
+ | 1 | At least one copy is `unapproved`, `failed`, `missing` or `stale`. |
276
+ | 2 | `apl` could not do its work: bad arguments, an unreadable lock file, an unwritable `~/.apl`, or a `~/.apl` that others can write. |
277
+ | 130 | Ctrl+C at the approval question; nothing was saved or run. |
278
+
279
+ APM exits 0 even when a lifecycle command fails or times out, so a script that relies on the setup should run `apl status` after APM.
280
+
281
+ ## Library
84
282
 
85
- ## Rules for commands
283
+ ```ts
284
+ import { status } from 'agent-plugin-lifecycle';
285
+
286
+ const results = await status({ folders: ['.claude/skills/report'] });
287
+ for (const result of results) console.log(result.status, result.folder);
288
+ ```
86
289
 
87
- - 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.
89
- - 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
- - A local `source` is the absolute path exactly as written in `apm.yml`.
91
- - `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.
290
+ `install` and `status` each return one `{ status, id, folder, reason }` per line above and print nothing. `install({ approve })` takes an async function that receives `{ id, scripts: { install }, folders }` and resolves to `true` to approve; without it, unapproved copies are not run. `install({ onResult })` is called with each result as soon as it is known. The options `home`, `apmHome`, `cwd`, `environment`, `global` and `folders` are described in the generated types.
92
291
 
93
292
  ## Agent skill
94
293
 
@@ -96,8 +295,8 @@ Prints `ok` or `missing` for every deployed copy of every installed, configured
96
295
  npx skills add kmalakoff/agent-plugin-lifecycle # -g for global, -a <agent> to target
97
296
  ```
98
297
 
99
- The skill teaches an agent to set up this hook, write the config for a plugin and check the result. It installs from Git through this command, separately from the npm package.
298
+ The skill teaches an agent to add an `apl.json` to a plugin or skill, register `apl install` with APM, approve scripts and read `apl status`. It installs from Git, separately from the npm package.
100
299
 
101
- ## License
300
+ ## Help and license
102
301
 
103
- MIT
302
+ Questions and bugs: [GitHub issues](https://github.com/kmalakoff/agent-plugin-lifecycle/issues). MIT license.
package/bin/cli.js CHANGED
@@ -1,2 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import '../dist/esm/cli.js';
2
+
3
+ // biome-ignore lint/security/noGlobalEval: dual esm and cjs
4
+ if (typeof require === 'undefined') eval("import('../dist/esm/cli.js').then((cli) => cli.default(process.argv.slice(2), 'apl')).catch((err) => { console.error(err); process.exit(2); });");
5
+ else
6
+ require('../dist/cjs/cli.js')(process.argv.slice(2), 'apl').catch((err) => {
7
+ console.error(err);
8
+ process.exit(2);
9
+ });
@@ -1,19 +1,68 @@
1
- export interface LockedPlugin {
2
- host: string;
1
+ /**
2
+ * One `dependencies` row of APM's `apm.lock.yaml`. Paths are relative POSIX paths, checked to stay inside their root; a user-scope lock may
3
+ * also record absolute deployed paths (a harness folder moved outside the home, as with `CLAUDE_CONFIG_DIR`).
4
+ */
5
+ export interface LockedPackage {
6
+ /** `<host>` or `<host>:<port>`; absent for a local path and for a row that records none. */
7
+ host?: string;
8
+ /** `owner/repo` for Git, `_local/<folder>` for a local path; with `path`, APM's cache copy under `apm_modules`. */
3
9
  repo: string;
10
+ /** The plugin's folder inside the repository, `.` for the root. */
4
11
  path: string;
5
- revision: string;
12
+ /** The local source path exactly as APM wrote it. */
6
13
  localPath?: string;
14
+ /** Whichever of `resolved_commit`, `resolved_hash` and `content_hash` the row has, joined by `:`. */
15
+ revision: string;
7
16
  nativePluginRoot?: string;
8
17
  deployedFiles: string[];
9
18
  }
10
- export declare function sourceParts(source: string): {
11
- host: string;
12
- repo: string;
13
- } | undefined;
14
- export declare function samePath(left: string, right: string, platform?: NodeJS.Platform): boolean;
15
- export declare function matchesSource(policySource: string, plugin: LockedPlugin, platform?: NodeJS.Platform): boolean;
16
- export declare function localEventName(source: string): string;
17
- export declare function lockIdentity(plugin: LockedPlugin): string;
18
- export declare function parseLock(value: unknown): LockedPlugin[];
19
- export declare function loadLock(path: string): Promise<LockedPlugin[]>;
19
+ /** A row `apl` cannot use, named by its `repo_url` (or its place in the lock); its recorded paths passed the path checks. */
20
+ export interface UnreadableRow {
21
+ name: string;
22
+ reason: string;
23
+ nativePluginRoot?: string;
24
+ deployedFiles: string[];
25
+ }
26
+ export type LockRow = LockedPackage | UnreadableRow;
27
+ export declare const isUnreadable: (row: LockRow) => row is UnreadableRow;
28
+ /** Where one APM scope keeps its lock and deploys its copies. */
29
+ export interface Scope {
30
+ global: boolean;
31
+ lock: string;
32
+ /** The folder deployed paths in the lock are relative to: the project, or the home. */
33
+ root: string;
34
+ /** The folder holding `apm.yml`; relative local paths are relative to it. */
35
+ manifestRoot: string;
36
+ /** APM's cache of each package (`apm_modules`), where scripts never run. */
37
+ modules: string;
38
+ }
39
+ /** A folder the lock names for a package, and where it sits inside the package (`''` or `skills/<name>`). */
40
+ export interface PackageFolder {
41
+ folder: string;
42
+ within: string;
43
+ /** The folder its real path must stay inside: the scope root for a relative path; none for an absolute path in a user-scope lock. */
44
+ bound?: string;
45
+ }
46
+ /** The copies the lock records for a package, and each folder of APM's cache of it whose place in the package no recorded folder carries. */
47
+ export interface PackageFolders {
48
+ folders: PackageFolder[];
49
+ cache: PackageFolder[];
50
+ }
51
+ /**
52
+ * The rows of a parsed lock. A path that could leave its root makes the whole lock unreadable; any other problem makes only its row
53
+ * unreadable. `absolute` accepts absolute deployed paths, which only a user-scope lock may hold.
54
+ */
55
+ export declare function parseLock(value: unknown, absolute?: boolean): LockRow[];
56
+ /** The rows of an APM lock file, or undefined when the file does not exist. `absolute` as for `parseLock`. */
57
+ export declare function readLock(path: string, absolute?: boolean): Promise<LockRow[] | undefined>;
58
+ /** The user scope with `global`, or when `cwd` is the APM home (where APM starts a user-scope lifecycle command); otherwise the project in `cwd`. */
59
+ export declare function resolveScope(options: {
60
+ global: boolean;
61
+ cwd: string;
62
+ home: string;
63
+ apmHome: string;
64
+ }): Promise<Scope>;
65
+ /** The folders a row records: each folder in `deployed_files` (a skill folder, at `skills/<its name>`), and the native plugin folder with its skills. */
66
+ export declare function recordedFolders(item: Pick<LockedPackage, 'deployedFiles' | 'nativePluginRoot'>, scope: Scope): Promise<PackageFolder[]>;
67
+ /** The folders a package's row records, and the root and skills of its APM cache copy whose place in the package no recorded folder carries. */
68
+ export declare function packageFolders(item: LockedPackage, scope: Scope): Promise<PackageFolders>;
package/dist/cjs/apm.d.ts CHANGED
@@ -1,19 +1,68 @@
1
- export interface LockedPlugin {
2
- host: string;
1
+ /**
2
+ * One `dependencies` row of APM's `apm.lock.yaml`. Paths are relative POSIX paths, checked to stay inside their root; a user-scope lock may
3
+ * also record absolute deployed paths (a harness folder moved outside the home, as with `CLAUDE_CONFIG_DIR`).
4
+ */
5
+ export interface LockedPackage {
6
+ /** `<host>` or `<host>:<port>`; absent for a local path and for a row that records none. */
7
+ host?: string;
8
+ /** `owner/repo` for Git, `_local/<folder>` for a local path; with `path`, APM's cache copy under `apm_modules`. */
3
9
  repo: string;
10
+ /** The plugin's folder inside the repository, `.` for the root. */
4
11
  path: string;
5
- revision: string;
12
+ /** The local source path exactly as APM wrote it. */
6
13
  localPath?: string;
14
+ /** Whichever of `resolved_commit`, `resolved_hash` and `content_hash` the row has, joined by `:`. */
15
+ revision: string;
7
16
  nativePluginRoot?: string;
8
17
  deployedFiles: string[];
9
18
  }
10
- export declare function sourceParts(source: string): {
11
- host: string;
12
- repo: string;
13
- } | undefined;
14
- export declare function samePath(left: string, right: string, platform?: NodeJS.Platform): boolean;
15
- export declare function matchesSource(policySource: string, plugin: LockedPlugin, platform?: NodeJS.Platform): boolean;
16
- export declare function localEventName(source: string): string;
17
- export declare function lockIdentity(plugin: LockedPlugin): string;
18
- export declare function parseLock(value: unknown): LockedPlugin[];
19
- export declare function loadLock(path: string): Promise<LockedPlugin[]>;
19
+ /** A row `apl` cannot use, named by its `repo_url` (or its place in the lock); its recorded paths passed the path checks. */
20
+ export interface UnreadableRow {
21
+ name: string;
22
+ reason: string;
23
+ nativePluginRoot?: string;
24
+ deployedFiles: string[];
25
+ }
26
+ export type LockRow = LockedPackage | UnreadableRow;
27
+ export declare const isUnreadable: (row: LockRow) => row is UnreadableRow;
28
+ /** Where one APM scope keeps its lock and deploys its copies. */
29
+ export interface Scope {
30
+ global: boolean;
31
+ lock: string;
32
+ /** The folder deployed paths in the lock are relative to: the project, or the home. */
33
+ root: string;
34
+ /** The folder holding `apm.yml`; relative local paths are relative to it. */
35
+ manifestRoot: string;
36
+ /** APM's cache of each package (`apm_modules`), where scripts never run. */
37
+ modules: string;
38
+ }
39
+ /** A folder the lock names for a package, and where it sits inside the package (`''` or `skills/<name>`). */
40
+ export interface PackageFolder {
41
+ folder: string;
42
+ within: string;
43
+ /** The folder its real path must stay inside: the scope root for a relative path; none for an absolute path in a user-scope lock. */
44
+ bound?: string;
45
+ }
46
+ /** The copies the lock records for a package, and each folder of APM's cache of it whose place in the package no recorded folder carries. */
47
+ export interface PackageFolders {
48
+ folders: PackageFolder[];
49
+ cache: PackageFolder[];
50
+ }
51
+ /**
52
+ * The rows of a parsed lock. A path that could leave its root makes the whole lock unreadable; any other problem makes only its row
53
+ * unreadable. `absolute` accepts absolute deployed paths, which only a user-scope lock may hold.
54
+ */
55
+ export declare function parseLock(value: unknown, absolute?: boolean): LockRow[];
56
+ /** The rows of an APM lock file, or undefined when the file does not exist. `absolute` as for `parseLock`. */
57
+ export declare function readLock(path: string, absolute?: boolean): Promise<LockRow[] | undefined>;
58
+ /** The user scope with `global`, or when `cwd` is the APM home (where APM starts a user-scope lifecycle command); otherwise the project in `cwd`. */
59
+ export declare function resolveScope(options: {
60
+ global: boolean;
61
+ cwd: string;
62
+ home: string;
63
+ apmHome: string;
64
+ }): Promise<Scope>;
65
+ /** The folders a row records: each folder in `deployed_files` (a skill folder, at `skills/<its name>`), and the native plugin folder with its skills. */
66
+ export declare function recordedFolders(item: Pick<LockedPackage, 'deployedFiles' | 'nativePluginRoot'>, scope: Scope): Promise<PackageFolder[]>;
67
+ /** The folders a package's row records, and the root and skills of its APM cache copy whose place in the package no recorded folder carries. */
68
+ export declare function packageFolders(item: LockedPackage, scope: Scope): Promise<PackageFolders>;