agent-plugin-lifecycle 0.0.0-stage → 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Kevin Malakoff
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ wof this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,103 @@
1
- # Temporary Holding Version
1
+ # agent-plugin-lifecycle
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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.
4
+
5
+ Requires Node.js 22.18 or newer and APM.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install -g agent-plugin-lifecycle
11
+ agent-plugin-lifecycle --help
12
+ ```
13
+
14
+ ## Register the hook with APM
15
+
16
+ Add the dispatcher to your user `~/.apm/apm.yml` for each event you want:
17
+
18
+ ```yaml
19
+ lifecycle:
20
+ 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
26
+ ```
27
+
28
+ It handles user-scope events; project-scope events are skipped.
29
+
30
+ ## Configure plugins
31
+
32
+ Put your commands in `~/.config/agent-plugin-lifecycle/config.json`:
33
+
34
+ ```json
35
+ {
36
+ "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"
49
+ }
50
+ ]
51
+ }
52
+ ```
53
+
54
+ Each record names one plugin or skill:
55
+
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 |
64
+
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`:
66
+
67
+ ```json
68
+ { "source": "https://github.com/team/skills.git", "skill": "report", "post-install": "npm ci --no-bin-links" }
69
+ ```
70
+
71
+ A full example is in [config/config.example.json](config/config.example.json).
72
+
73
+ Then run `apm install` or `apm update` as usual; your commands run inside it.
74
+
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`.
76
+
77
+ ## Check the result
78
+
79
+ ```sh
80
+ agent-plugin-lifecycle check
81
+ ```
82
+
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.
84
+
85
+ ## Rules for commands
86
+
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.
92
+
93
+ ## Agent skill
94
+
95
+ ```sh
96
+ npx skills add kmalakoff/agent-plugin-lifecycle # -g for global, -a <agent> to target
97
+ ```
98
+
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.
100
+
101
+ ## License
102
+
103
+ MIT
package/bin/cli.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import '../dist/esm/cli.js';
@@ -0,0 +1,22 @@
1
+ {
2
+ "version": 1,
3
+ "plugins": [
4
+ {
5
+ "source": "git@bitbucket.org:team/plugins.git",
6
+ "path": "plugins/example",
7
+ "post-install": "npm ci --prefix server --no-bin-links",
8
+ "post-update": "npm ci --prefix server --no-bin-links",
9
+ "post-uninstall": "node .config/agent-plugin-lifecycle/cleanup-example.js"
10
+ },
11
+ {
12
+ "source": "git@bitbucket.org:team/plugins.git",
13
+ "path": "plugins/example",
14
+ "skill": "hello-node",
15
+ "post-install": "npm ci --no-bin-links"
16
+ },
17
+ {
18
+ "source": "/absolute/path/to/local-plugin",
19
+ "post-install": "npm ci --no-bin-links"
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,19 @@
1
+ export interface LockedPlugin {
2
+ host: string;
3
+ repo: string;
4
+ path: string;
5
+ revision: string;
6
+ localPath?: string;
7
+ nativePluginRoot?: string;
8
+ deployedFiles: string[];
9
+ }
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[]>;
@@ -0,0 +1,19 @@
1
+ export interface LockedPlugin {
2
+ host: string;
3
+ repo: string;
4
+ path: string;
5
+ revision: string;
6
+ localPath?: string;
7
+ nativePluginRoot?: string;
8
+ deployedFiles: string[];
9
+ }
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[]>;
@@ -0,0 +1,313 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get loadLock () {
13
+ return loadLock;
14
+ },
15
+ get localEventName () {
16
+ return localEventName;
17
+ },
18
+ get lockIdentity () {
19
+ return lockIdentity;
20
+ },
21
+ get matchesSource () {
22
+ return matchesSource;
23
+ },
24
+ get parseLock () {
25
+ return parseLock;
26
+ },
27
+ get samePath () {
28
+ return samePath;
29
+ },
30
+ get sourceParts () {
31
+ return sourceParts;
32
+ }
33
+ });
34
+ var _promises = require("node:fs/promises");
35
+ var _nodepath = require("node:path");
36
+ var _yaml = require("yaml");
37
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
38
+ try {
39
+ var info = gen[key](arg);
40
+ var value = info.value;
41
+ } catch (error) {
42
+ reject(error);
43
+ return;
44
+ }
45
+ if (info.done) resolve(value);
46
+ else Promise.resolve(value).then(_next, _throw);
47
+ }
48
+ function _async_to_generator(fn) {
49
+ return function() {
50
+ var self = this, args = arguments;
51
+ return new Promise(function(resolve, reject) {
52
+ var gen = fn.apply(self, args);
53
+ function _next(value) {
54
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
55
+ }
56
+ function _throw(err) {
57
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
58
+ }
59
+ _next(undefined);
60
+ });
61
+ };
62
+ }
63
+ function _ts_generator(thisArg, body) {
64
+ var f, y, t, _ = {
65
+ label: 0,
66
+ sent: function() {
67
+ if (t[0] & 1) throw t[1];
68
+ return t[1];
69
+ },
70
+ trys: [],
71
+ ops: []
72
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
73
+ return d(g, "next", {
74
+ value: verb(0)
75
+ }), d(g, "throw", {
76
+ value: verb(1)
77
+ }), d(g, "return", {
78
+ value: verb(2)
79
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
80
+ value: function() {
81
+ return this;
82
+ }
83
+ }), g;
84
+ function verb(n) {
85
+ return function(v) {
86
+ return step([
87
+ n,
88
+ v
89
+ ]);
90
+ };
91
+ }
92
+ function step(op) {
93
+ if (f) throw new TypeError("Generator is already executing.");
94
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
95
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
96
+ if (y = 0, t) op = [
97
+ op[0] & 2,
98
+ t.value
99
+ ];
100
+ switch(op[0]){
101
+ case 0:
102
+ case 1:
103
+ t = op;
104
+ break;
105
+ case 4:
106
+ _.label++;
107
+ return {
108
+ value: op[1],
109
+ done: false
110
+ };
111
+ case 5:
112
+ _.label++;
113
+ y = op[1];
114
+ op = [
115
+ 0
116
+ ];
117
+ continue;
118
+ case 7:
119
+ op = _.ops.pop();
120
+ _.trys.pop();
121
+ continue;
122
+ default:
123
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
124
+ _ = 0;
125
+ continue;
126
+ }
127
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
128
+ _.label = op[1];
129
+ break;
130
+ }
131
+ if (op[0] === 6 && _.label < t[1]) {
132
+ _.label = t[1];
133
+ t = op;
134
+ break;
135
+ }
136
+ if (t && _.label < t[2]) {
137
+ _.label = t[2];
138
+ _.ops.push(op);
139
+ break;
140
+ }
141
+ if (t[2]) _.ops.pop();
142
+ _.trys.pop();
143
+ continue;
144
+ }
145
+ op = body.call(thisArg, _);
146
+ } catch (e) {
147
+ op = [
148
+ 6,
149
+ e
150
+ ];
151
+ y = 0;
152
+ } finally{
153
+ f = t = 0;
154
+ }
155
+ if (op[0] & 5) throw op[1];
156
+ return {
157
+ value: op[0] ? op[1] : void 0,
158
+ done: true
159
+ };
160
+ }
161
+ }
162
+ function _type_of(obj) {
163
+ "@swc/helpers - typeof";
164
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
165
+ }
166
+ function record(value, label) {
167
+ if (!value || (typeof value === "undefined" ? "undefined" : _type_of(value)) !== 'object' || Array.isArray(value)) throw new Error("".concat(label, " must be an object"));
168
+ return value;
169
+ }
170
+ function requiredString(value, label) {
171
+ if (typeof value !== 'string' || !value) throw new Error("".concat(label, " must be a nonempty string"));
172
+ return value;
173
+ }
174
+ function safePath(value, label) {
175
+ var dot = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
176
+ var path = requiredString(value, label);
177
+ if (dot && path === '.') return path;
178
+ if (path.startsWith('/') || path.includes('\\') || /^[A-Za-z]:/.test(path) || path.split('/').some(function(part) {
179
+ return !part || part === '.' || part === '..';
180
+ })) throw new Error("".concat(label, " contains an unsafe path segment"));
181
+ return path;
182
+ }
183
+ function sourceParts(source) {
184
+ var host;
185
+ var path;
186
+ var scp = source.includes('://') ? null : /^(?:[^@/:]+@)?([^/:]+):(.+)$/.exec(source);
187
+ if (scp) {
188
+ host = scp[1];
189
+ path = scp[2];
190
+ } else {
191
+ try {
192
+ var url = new URL(source);
193
+ if (![
194
+ 'https:',
195
+ 'ssh:',
196
+ 'http:'
197
+ ].includes(url.protocol)) return undefined;
198
+ host = url.hostname;
199
+ path = url.pathname.replace(/^\//, '');
200
+ } catch (unused) {
201
+ return undefined;
202
+ }
203
+ }
204
+ path = path.replace(/\.git$/, '').replace(/\/$/, '');
205
+ if (!host || !path || path.split('/').some(function(part) {
206
+ return !part || part === '.' || part === '..';
207
+ })) return undefined;
208
+ return {
209
+ host: host.toLowerCase(),
210
+ repo: path
211
+ };
212
+ }
213
+ function samePath(left, right) {
214
+ var platform = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : process.platform;
215
+ if (platform !== 'win32') return _nodepath.posix.resolve(left) === _nodepath.posix.resolve(right);
216
+ return _nodepath.win32.resolve(left).toLowerCase() === _nodepath.win32.resolve(right).toLowerCase();
217
+ }
218
+ function matchesSource(policySource, plugin) {
219
+ var platform = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : process.platform;
220
+ if (plugin.localPath !== undefined) return samePath(policySource, plugin.localPath, platform);
221
+ var parts = sourceParts(policySource);
222
+ return !!parts && parts.host === plugin.host.toLowerCase() && parts.repo === plugin.repo.replace(/\.git$/, '');
223
+ }
224
+ function localEventName(source) {
225
+ return "_local/".concat((0, _nodepath.basename)(source).replace(/\/$/, ''));
226
+ }
227
+ function lockIdentity(plugin) {
228
+ var _plugin_localPath;
229
+ return JSON.stringify([
230
+ plugin.host,
231
+ plugin.repo,
232
+ plugin.path,
233
+ (_plugin_localPath = plugin.localPath) !== null && _plugin_localPath !== void 0 ? _plugin_localPath : null
234
+ ]);
235
+ }
236
+ function parseLock(value) {
237
+ var root = record(value, 'APM lock');
238
+ if (!Array.isArray(root.dependencies)) throw new Error('APM lock dependencies must be an array');
239
+ var seen = new Set();
240
+ return root.dependencies.map(function(raw, index) {
241
+ var label = "APM lock dependencies[".concat(index, "]");
242
+ var source = record(raw, label);
243
+ var plugin;
244
+ if (source.source === 'local' && source.package_type === 'agent_plugin') {
245
+ var repo = safePath(source.repo_url, "".concat(label, ".repo_url"));
246
+ if (!repo.startsWith('_local/')) throw new Error("".concat(label, ".repo_url is not a local plugin key"));
247
+ var localPath = requiredString(source.local_path, "".concat(label, ".local_path"));
248
+ var hash = requiredString(source.content_hash, "".concat(label, ".content_hash"));
249
+ if (!/^sha256:[0-9a-f]{64}$/.test(hash)) throw new Error("".concat(label, " has invalid content hash"));
250
+ plugin = {
251
+ host: 'local',
252
+ repo: repo,
253
+ path: '.',
254
+ revision: hash,
255
+ localPath: localPath,
256
+ deployedFiles: []
257
+ };
258
+ } else {
259
+ var _source_deployed_files;
260
+ var host = requiredString(source.host, "".concat(label, ".host"));
261
+ var repo1 = safePath(source.repo_url, "".concat(label, ".repo_url"));
262
+ // APM writes no virtual_path for a plugin at the repository root (recorded from APM 0.37.0)
263
+ var path = source.virtual_path === undefined || source.virtual_path === null ? '.' : safePath(source.virtual_path, "".concat(label, ".virtual_path"), true);
264
+ var commit = requiredString(source.resolved_commit, "".concat(label, ".resolved_commit"));
265
+ var hash1 = requiredString(source.content_hash, "".concat(label, ".content_hash"));
266
+ if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(commit) || !/^sha256:[0-9a-f]{64}$/.test(hash1)) throw new Error("".concat(label, " has invalid revision evidence"));
267
+ var native = source.native_plugin === undefined || source.native_plugin === null ? undefined : record(source.native_plugin, "".concat(label, ".native_plugin"));
268
+ var nativePluginRoot = native ? safePath(native.root, "".concat(label, ".native_plugin.root")) : undefined;
269
+ var deployed = (_source_deployed_files = source.deployed_files) !== null && _source_deployed_files !== void 0 ? _source_deployed_files : [];
270
+ if (!Array.isArray(deployed) || !deployed.every(function(file) {
271
+ return typeof file === 'string';
272
+ })) throw new Error("".concat(label, ".deployed_files must be an array of paths"));
273
+ var deployedFiles = deployed.map(function(file, fileIndex) {
274
+ return safePath(file, "".concat(label, ".deployed_files[").concat(fileIndex, "]"));
275
+ });
276
+ plugin = {
277
+ host: host,
278
+ repo: repo1,
279
+ path: path,
280
+ revision: "".concat(commit, ":").concat(hash1),
281
+ nativePluginRoot: nativePluginRoot,
282
+ deployedFiles: deployedFiles
283
+ };
284
+ }
285
+ var identity = lockIdentity(plugin);
286
+ if (seen.has(identity)) throw new Error("".concat(label, " duplicates another lock entry"));
287
+ seen.add(identity);
288
+ return plugin;
289
+ });
290
+ }
291
+ function loadLock(path) {
292
+ return _async_to_generator(function() {
293
+ return _ts_generator(this, function(_state) {
294
+ switch(_state.label){
295
+ case 0:
296
+ return [
297
+ 4,
298
+ (0, _promises.readFile)(path, 'utf8')
299
+ ];
300
+ case 1:
301
+ return [
302
+ 2,
303
+ parseLock.apply(void 0, [
304
+ _yaml.parse.apply(void 0, [
305
+ _state.sent()
306
+ ])
307
+ ])
308
+ ];
309
+ }
310
+ });
311
+ })();
312
+ }
313
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/open-source/ai/agent-plugin-lifecycle/src/apm.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { basename, posix, win32 } from 'node:path';\nimport { parse } from 'yaml';\n\nexport interface LockedPlugin {\n host: string;\n repo: string;\n path: string;\n revision: string;\n localPath?: string;\n nativePluginRoot?: string;\n deployedFiles: string[];\n}\nfunction record(value: unknown, label: string): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error(`${label} must be an object`);\n return value as Record<string, unknown>;\n}\nfunction requiredString(value: unknown, label: string): string {\n if (typeof value !== 'string' || !value) throw new Error(`${label} must be a nonempty string`);\n return value;\n}\nfunction safePath(value: unknown, label: string, dot = false): string {\n const path = requiredString(value, label);\n if (dot && path === '.') return path;\n if (path.startsWith('/') || path.includes('\\\\') || /^[A-Za-z]:/.test(path) || path.split('/').some((part) => !part || part === '.' || part === '..')) throw new Error(`${label} contains an unsafe path segment`);\n return path;\n}\nexport function sourceParts(source: string): { host: string; repo: string } | undefined {\n let host: string;\n let path: string;\n const scp = source.includes('://') ? null : /^(?:[^@/:]+@)?([^/:]+):(.+)$/.exec(source);\n if (scp) {\n host = scp[1];\n path = scp[2];\n } else {\n try {\n const url = new URL(source);\n if (!['https:', 'ssh:', 'http:'].includes(url.protocol)) return undefined;\n host = url.hostname;\n path = url.pathname.replace(/^\\//, '');\n } catch {\n return undefined;\n }\n }\n path = path.replace(/\\.git$/, '').replace(/\\/$/, '');\n if (!host || !path || path.split('/').some((part) => !part || part === '.' || part === '..')) return undefined;\n return { host: host.toLowerCase(), repo: path };\n}\n// Same path whatever separators or trailing slash either side was written with; Windows paths also ignore case.\nexport function samePath(left: string, right: string, platform: NodeJS.Platform = process.platform): boolean {\n if (platform !== 'win32') return posix.resolve(left) === posix.resolve(right);\n return win32.resolve(left).toLowerCase() === win32.resolve(right).toLowerCase();\n}\nexport function matchesSource(policySource: string, plugin: LockedPlugin, platform: NodeJS.Platform = process.platform): boolean {\n if (plugin.localPath !== undefined) return samePath(policySource, plugin.localPath, platform);\n const parts = sourceParts(policySource);\n return !!parts && parts.host === plugin.host.toLowerCase() && parts.repo === plugin.repo.replace(/\\.git$/, '');\n}\nexport function localEventName(source: string): string {\n return `_local/${basename(source).replace(/\\/$/, '')}`;\n}\nexport function lockIdentity(plugin: LockedPlugin): string {\n return JSON.stringify([plugin.host, plugin.repo, plugin.path, plugin.localPath ?? null]);\n}\nexport function parseLock(value: unknown): LockedPlugin[] {\n const root = record(value, 'APM lock');\n if (!Array.isArray(root.dependencies)) throw new Error('APM lock dependencies must be an array');\n const seen = new Set<string>();\n return root.dependencies.map((raw, index): LockedPlugin => {\n const label = `APM lock dependencies[${index}]`;\n const source = record(raw, label);\n let plugin: LockedPlugin;\n if (source.source === 'local' && source.package_type === 'agent_plugin') {\n const repo = safePath(source.repo_url, `${label}.repo_url`);\n if (!repo.startsWith('_local/')) throw new Error(`${label}.repo_url is not a local plugin key`);\n const localPath = requiredString(source.local_path, `${label}.local_path`);\n const hash = requiredString(source.content_hash, `${label}.content_hash`);\n if (!/^sha256:[0-9a-f]{64}$/.test(hash)) throw new Error(`${label} has invalid content hash`);\n plugin = { host: 'local', repo, path: '.', revision: hash, localPath, deployedFiles: [] };\n } else {\n const host = requiredString(source.host, `${label}.host`);\n const repo = safePath(source.repo_url, `${label}.repo_url`);\n // APM writes no virtual_path for a plugin at the repository root (recorded from APM 0.37.0)\n const path = source.virtual_path === undefined || source.virtual_path === null ? '.' : safePath(source.virtual_path, `${label}.virtual_path`, true);\n const commit = requiredString(source.resolved_commit, `${label}.resolved_commit`);\n const hash = requiredString(source.content_hash, `${label}.content_hash`);\n if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(commit) || !/^sha256:[0-9a-f]{64}$/.test(hash)) throw new Error(`${label} has invalid revision evidence`);\n const native = source.native_plugin === undefined || source.native_plugin === null ? undefined : record(source.native_plugin, `${label}.native_plugin`);\n const nativePluginRoot = native ? safePath(native.root, `${label}.native_plugin.root`) : undefined;\n const deployed = source.deployed_files ?? [];\n if (!Array.isArray(deployed) || !deployed.every((file) => typeof file === 'string')) throw new Error(`${label}.deployed_files must be an array of paths`);\n const deployedFiles = deployed.map((file: string, fileIndex: number) => safePath(file, `${label}.deployed_files[${fileIndex}]`));\n plugin = { host, repo, path, revision: `${commit}:${hash}`, nativePluginRoot, deployedFiles };\n }\n const identity = lockIdentity(plugin);\n if (seen.has(identity)) throw new Error(`${label} duplicates another lock entry`);\n seen.add(identity);\n return plugin;\n });\n}\nexport async function loadLock(path: string): Promise<LockedPlugin[]> {\n return parseLock(parse(await readFile(path, 'utf8')));\n}\n"],"names":["loadLock","localEventName","lockIdentity","matchesSource","parseLock","samePath","sourceParts","record","value","label","Array","isArray","Error","requiredString","safePath","dot","path","startsWith","includes","test","split","some","part","source","host","scp","exec","url","URL","protocol","undefined","hostname","pathname","replace","toLowerCase","repo","left","right","platform","process","posix","resolve","win32","policySource","plugin","localPath","parts","basename","JSON","stringify","root","dependencies","seen","Set","map","raw","index","package_type","repo_url","local_path","hash","content_hash","revision","deployedFiles","virtual_path","commit","resolved_commit","native","native_plugin","nativePluginRoot","deployed","deployed_files","every","file","fileIndex","identity","has","add","readFile","parse"],"mappings":";;;;;;;;;;;QAoGsBA;eAAAA;;QA1CNC;eAAAA;;QAGAC;eAAAA;;QARAC;eAAAA;;QAWAC;eAAAA;;QAfAC;eAAAA;;QAtBAC;eAAAA;;;wBA3BS;wBACc;oBACjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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