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.
@@ -0,0 +1,366 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ var _nodeutil = require("node:util");
6
+ var _runner = require("./runner.js");
7
+ function _async_iterator(iterable) {
8
+ var method, async, sync, retry = 2;
9
+ for("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;){
10
+ if (async && null != (method = iterable[async])) return method.call(iterable);
11
+ if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable));
12
+ async = "@@asyncIterator", sync = "@@iterator";
13
+ }
14
+ throw new TypeError("Object is not async iterable");
15
+ }
16
+ function AsyncFromSyncIterator(s) {
17
+ function AsyncFromSyncIteratorContinuation(r) {
18
+ if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object."));
19
+ var done = r.done;
20
+ return Promise.resolve(r.value).then(function(value) {
21
+ return {
22
+ value: value,
23
+ done: done
24
+ };
25
+ });
26
+ }
27
+ return AsyncFromSyncIterator = function(s) {
28
+ this.s = s, this.n = s.next;
29
+ }, AsyncFromSyncIterator.prototype = {
30
+ s: null,
31
+ n: null,
32
+ next: function() {
33
+ return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
34
+ },
35
+ return: function(value) {
36
+ var ret = this.s.return;
37
+ return void 0 === ret ? Promise.resolve({
38
+ value: value,
39
+ done: !0
40
+ }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments));
41
+ },
42
+ throw: function(value) {
43
+ var thr = this.s.return;
44
+ return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments));
45
+ }
46
+ }, new AsyncFromSyncIterator(s);
47
+ }
48
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
49
+ try {
50
+ var info = gen[key](arg);
51
+ var value = info.value;
52
+ } catch (error) {
53
+ reject(error);
54
+ return;
55
+ }
56
+ if (info.done) resolve(value);
57
+ else Promise.resolve(value).then(_next, _throw);
58
+ }
59
+ function _async_to_generator(fn) {
60
+ return function() {
61
+ var self = this, args = arguments;
62
+ return new Promise(function(resolve, reject) {
63
+ var gen = fn.apply(self, args);
64
+ function _next(value) {
65
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
66
+ }
67
+ function _throw(err) {
68
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
69
+ }
70
+ _next(undefined);
71
+ });
72
+ };
73
+ }
74
+ function _instanceof(left, right) {
75
+ "@swc/helpers - instanceof";
76
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
77
+ return !!right[Symbol.hasInstance](left);
78
+ } else return left instanceof right;
79
+ }
80
+ function _ts_generator(thisArg, body) {
81
+ var f, y, t, _ = {
82
+ label: 0,
83
+ sent: function() {
84
+ if (t[0] & 1) throw t[1];
85
+ return t[1];
86
+ },
87
+ trys: [],
88
+ ops: []
89
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
90
+ return d(g, "next", {
91
+ value: verb(0)
92
+ }), d(g, "throw", {
93
+ value: verb(1)
94
+ }), d(g, "return", {
95
+ value: verb(2)
96
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
97
+ value: function() {
98
+ return this;
99
+ }
100
+ }), g;
101
+ function verb(n) {
102
+ return function(v) {
103
+ return step([
104
+ n,
105
+ v
106
+ ]);
107
+ };
108
+ }
109
+ function step(op) {
110
+ if (f) throw new TypeError("Generator is already executing.");
111
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
112
+ 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;
113
+ if (y = 0, t) op = [
114
+ op[0] & 2,
115
+ t.value
116
+ ];
117
+ switch(op[0]){
118
+ case 0:
119
+ case 1:
120
+ t = op;
121
+ break;
122
+ case 4:
123
+ _.label++;
124
+ return {
125
+ value: op[1],
126
+ done: false
127
+ };
128
+ case 5:
129
+ _.label++;
130
+ y = op[1];
131
+ op = [
132
+ 0
133
+ ];
134
+ continue;
135
+ case 7:
136
+ op = _.ops.pop();
137
+ _.trys.pop();
138
+ continue;
139
+ default:
140
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
141
+ _ = 0;
142
+ continue;
143
+ }
144
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
145
+ _.label = op[1];
146
+ break;
147
+ }
148
+ if (op[0] === 6 && _.label < t[1]) {
149
+ _.label = t[1];
150
+ t = op;
151
+ break;
152
+ }
153
+ if (t && _.label < t[2]) {
154
+ _.label = t[2];
155
+ _.ops.push(op);
156
+ break;
157
+ }
158
+ if (t[2]) _.ops.pop();
159
+ _.trys.pop();
160
+ continue;
161
+ }
162
+ op = body.call(thisArg, _);
163
+ } catch (e) {
164
+ op = [
165
+ 6,
166
+ e
167
+ ];
168
+ y = 0;
169
+ } finally{
170
+ f = t = 0;
171
+ }
172
+ if (op[0] & 5) throw op[1];
173
+ return {
174
+ value: op[0] ? op[1] : void 0,
175
+ done: true
176
+ };
177
+ }
178
+ }
179
+ function _type_of(obj) {
180
+ "@swc/helpers - typeof";
181
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
182
+ }
183
+ var HELP = "agent-plugin-lifecycle\n\nUsage:\n agent-plugin-lifecycle run Dispatch an APM post-install/update/uninstall event from stdin\n agent-plugin-lifecycle check Report missing or failed plugin setup\n agent-plugin-lifecycle --help\n\nPolicy: ~/.config/agent-plugin-lifecycle/config.json\nAPM lock: ~/.apm/apm.lock.yaml (or $APM_HOME/apm.lock.yaml)\n";
184
+ function readEvent() {
185
+ return _async_to_generator(function() {
186
+ var payload, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, err, event, value;
187
+ return _ts_generator(this, function(_state) {
188
+ switch(_state.label){
189
+ case 0:
190
+ if (process.stdin.isTTY) throw new Error('run requires an APM event on stdin');
191
+ payload = '';
192
+ _iteratorAbruptCompletion = false, _didIteratorError = false;
193
+ _state.label = 1;
194
+ case 1:
195
+ _state.trys.push([
196
+ 1,
197
+ 6,
198
+ 7,
199
+ 12
200
+ ]);
201
+ _iterator = _async_iterator(process.stdin);
202
+ _state.label = 2;
203
+ case 2:
204
+ return [
205
+ 4,
206
+ _iterator.next()
207
+ ];
208
+ case 3:
209
+ if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
210
+ 3,
211
+ 5
212
+ ];
213
+ _value = _step.value;
214
+ chunk = _value;
215
+ payload += chunk.toString();
216
+ if (payload.length > 1024 * 1024) throw new Error('APM event exceeds 1 MiB');
217
+ _state.label = 4;
218
+ case 4:
219
+ _iteratorAbruptCompletion = false;
220
+ return [
221
+ 3,
222
+ 2
223
+ ];
224
+ case 5:
225
+ return [
226
+ 3,
227
+ 12
228
+ ];
229
+ case 6:
230
+ err = _state.sent();
231
+ _didIteratorError = true;
232
+ _iteratorError = err;
233
+ return [
234
+ 3,
235
+ 12
236
+ ];
237
+ case 7:
238
+ _state.trys.push([
239
+ 7,
240
+ ,
241
+ 10,
242
+ 11
243
+ ]);
244
+ if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
245
+ 3,
246
+ 9
247
+ ];
248
+ return [
249
+ 4,
250
+ _iterator.return()
251
+ ];
252
+ case 8:
253
+ _state.sent();
254
+ _state.label = 9;
255
+ case 9:
256
+ return [
257
+ 3,
258
+ 11
259
+ ];
260
+ case 10:
261
+ if (_didIteratorError) {
262
+ throw _iteratorError;
263
+ }
264
+ return [
265
+ 7
266
+ ];
267
+ case 11:
268
+ return [
269
+ 7
270
+ ];
271
+ case 12:
272
+ if (!payload.trim()) throw new Error('run requires an APM event on stdin');
273
+ event = JSON.parse(payload);
274
+ if (!event || (typeof event === "undefined" ? "undefined" : _type_of(event)) !== 'object' || Array.isArray(event)) throw new Error('APM event must be an object');
275
+ value = event;
276
+ if (value.schema_version !== 1 || ![
277
+ 'post-install',
278
+ 'post-update',
279
+ 'post-uninstall'
280
+ ].includes(String(value.event)) || ![
281
+ 'user',
282
+ 'project'
283
+ ].includes(String(value.scope)) || !Array.isArray(value.packages) || !value.packages.every(function(p) {
284
+ return p && (typeof p === "undefined" ? "undefined" : _type_of(p)) === 'object' && typeof p.name === 'string' && (p.reference === null || typeof p.reference === 'string');
285
+ })) {
286
+ throw new Error('unsupported APM lifecycle event');
287
+ }
288
+ return [
289
+ 2,
290
+ value
291
+ ];
292
+ }
293
+ });
294
+ })();
295
+ }
296
+ function main() {
297
+ return _async_to_generator(function() {
298
+ var _parseArgs, values, positionals, event, _tmp;
299
+ return _ts_generator(this, function(_state) {
300
+ switch(_state.label){
301
+ case 0:
302
+ _parseArgs = (0, _nodeutil.parseArgs)({
303
+ args: process.argv.slice(2),
304
+ options: {
305
+ help: {
306
+ type: 'boolean',
307
+ short: 'h'
308
+ }
309
+ },
310
+ allowPositionals: true
311
+ }), values = _parseArgs.values, positionals = _parseArgs.positionals;
312
+ if (values.help || positionals.length === 0) {
313
+ process.stdout.write(HELP);
314
+ return [
315
+ 2,
316
+ 0
317
+ ];
318
+ }
319
+ if (positionals.length !== 1 || ![
320
+ 'run',
321
+ 'check'
322
+ ].includes(positionals[0])) throw new Error('expected run or check; use --help');
323
+ if (!(positionals[0] === 'run')) return [
324
+ 3,
325
+ 2
326
+ ];
327
+ return [
328
+ 4,
329
+ readEvent()
330
+ ];
331
+ case 1:
332
+ _tmp = _state.sent();
333
+ return [
334
+ 3,
335
+ 3
336
+ ];
337
+ case 2:
338
+ _tmp = undefined;
339
+ _state.label = 3;
340
+ case 3:
341
+ event = _tmp;
342
+ if ((event === null || event === void 0 ? void 0 : event.scope) !== undefined && event.scope !== 'user') {
343
+ console.log("skipped APM ".concat(event.scope, " scope event"));
344
+ return [
345
+ 2,
346
+ 0
347
+ ];
348
+ }
349
+ return [
350
+ 2,
351
+ (0, _runner.runLifecycle)(positionals[0], {
352
+ apmHome: process.env.APM_HOME,
353
+ event: event
354
+ })
355
+ ];
356
+ }
357
+ });
358
+ })();
359
+ }
360
+ main().then(function(status) {
361
+ process.exitCode = status;
362
+ }).catch(function(error) {
363
+ console.error("agent-plugin-lifecycle: ".concat(_instanceof(error, Error) ? error.message : String(error)));
364
+ process.exitCode = 2;
365
+ });
366
+ /* 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/cli.ts"],"sourcesContent":["import { parseArgs } from 'node:util';\n\nimport { runLifecycle } from './runner.js';\n\nconst HELP = `agent-plugin-lifecycle\n\nUsage:\n agent-plugin-lifecycle run Dispatch an APM post-install/update/uninstall event from stdin\n agent-plugin-lifecycle check Report missing or failed plugin setup\n agent-plugin-lifecycle --help\n\nPolicy: ~/.config/agent-plugin-lifecycle/config.json\nAPM lock: ~/.apm/apm.lock.yaml (or $APM_HOME/apm.lock.yaml)\n`;\n\nasync function readEvent(): Promise<import('./runner.js').LifecycleEvent> {\n if (process.stdin.isTTY) throw new Error('run requires an APM event on stdin');\n let payload = '';\n for await (const chunk of process.stdin) {\n payload += chunk.toString();\n if (payload.length > 1024 * 1024) throw new Error('APM event exceeds 1 MiB');\n }\n if (!payload.trim()) throw new Error('run requires an APM event on stdin');\n const event: unknown = JSON.parse(payload);\n if (!event || typeof event !== 'object' || Array.isArray(event)) throw new Error('APM event must be an object');\n const value = event as Record<string, unknown>;\n if (\n value.schema_version !== 1 ||\n !['post-install', 'post-update', 'post-uninstall'].includes(String(value.event)) ||\n !['user', 'project'].includes(String(value.scope)) ||\n !Array.isArray(value.packages) ||\n !value.packages.every((p) => p && typeof p === 'object' && typeof p.name === 'string' && (p.reference === null || typeof p.reference === 'string'))\n ) {\n throw new Error('unsupported APM lifecycle event');\n }\n return value as unknown as import('./runner.js').LifecycleEvent;\n}\n\nasync function main(): Promise<number> {\n const { values, positionals } = parseArgs({\n args: process.argv.slice(2),\n options: { help: { type: 'boolean', short: 'h' } },\n allowPositionals: true,\n });\n if (values.help || positionals.length === 0) {\n process.stdout.write(HELP);\n return 0;\n }\n if (positionals.length !== 1 || !['run', 'check'].includes(positionals[0])) throw new Error('expected run or check; use --help');\n const event = positionals[0] === 'run' ? await readEvent() : undefined;\n if (event?.scope !== undefined && event.scope !== 'user') {\n console.log(`skipped APM ${event.scope} scope event`);\n return 0;\n }\n return runLifecycle(positionals[0] as 'run' | 'check', { apmHome: process.env.APM_HOME, event });\n}\n\nmain()\n .then((status) => {\n process.exitCode = status;\n })\n .catch((error: unknown) => {\n console.error(`agent-plugin-lifecycle: ${error instanceof Error ? error.message : String(error)}`);\n process.exitCode = 2;\n });\n"],"names":["HELP","readEvent","payload","chunk","event","value","process","stdin","isTTY","Error","toString","length","trim","JSON","parse","Array","isArray","schema_version","includes","String","scope","packages","every","p","name","reference","main","parseArgs","values","positionals","args","argv","slice","options","help","type","short","allowPositionals","stdout","write","undefined","console","log","runLifecycle","apmHome","env","APM_HOME","then","status","exitCode","catch","error","message"],"mappings":";;;;wBAA0B;sBAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE7B,IAAMA,OAAO;AAWb,SAAeC;;YAETC,iGACaC,YAKXC,OAEAC;;;;oBATN,IAAIC,QAAQC,KAAK,CAACC,KAAK,EAAE,MAAM,IAAIC,M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WAAxBC,QAAQC,cAAgBF,WAAhBE;oBAKhB,IAAID,OAAOM,IAAI,IAAIL,YAAYlB,MAAM,KAAK,GAAG;wBAC3CL,QAAQgC,MAAM,CAACC,KAAK,CAACvC;wBACrB;;4BAAO;;oBACT;oBACA,IAAI6B,YAAYlB,MAAM,KAAK,KAAK,CAAC;wBAAC;wBAAO;sBAASO,QAAQ,CAACW,WAAW,CAAC,EAAE,GAAG,MAAM,IAAIpB,MAAM;yBAC9EoB,CAAAA,WAAW,CAAC,EAAE,KAAK,KAAI,GAAvBA;;;;oBAA2B;;wBAAM5B;;;2BAAN;;;;;;2BAAoBuC;;;oBAAvDpC;oBACN,IAAIA,CAAAA,kBAAAA,4BAAAA,MAAOgB,KAAK,MAAKoB,aAAapC,MAAMgB,KAAK,KAAK,QAAQ;wBACxDqB,QAAQC,GAAG,CAAC,AAAC,eAA0B,OAAZtC,MAAMgB,KAAK,EAAC;wBACvC;;4BAAO;;oBACT;oBACA;;wBAAOuB,IAAAA,oBAAY,EAACd,WAAW,CAAC,EAAE,EAAqB;4BAAEe,SAAStC,QAAQuC,GAAG,CAACC,QAAQ;4BAAE1C,OAAAA;wBAAM;;;;IAChG;;AAEAsB,OACGqB,IAAI,CAAC,SAACC;IACL1C,QAAQ2C,QAAQ,GAAGD;AACrB,GACCE,KAAK,CAAC,SAACC;IACNV,QAAQU,KAAK,CAAC,AAAC,2BAAiF,OAAvDA,AAAK,YAALA,OAAiB1C,SAAQ0C,MAAMC,OAAO,GAAGjC,OAAOgC;IACzF7C,QAAQ2C,QAAQ,GAAG;AACrB"}
@@ -0,0 +1,16 @@
1
+ export type Platform = 'darwin' | 'linux' | 'win32';
2
+ export interface PluginPolicy {
3
+ source: string;
4
+ path?: string;
5
+ skill?: string;
6
+ 'post-install'?: string;
7
+ 'post-update'?: string;
8
+ 'post-uninstall'?: string;
9
+ }
10
+ export interface Config {
11
+ version: 1;
12
+ plugins: PluginPolicy[];
13
+ }
14
+ export declare function recordId(plugin: PluginPolicy): string;
15
+ export declare function parseConfig(value: unknown): Config;
16
+ export declare function loadConfig(path: string): Promise<Config>;
@@ -0,0 +1,16 @@
1
+ export type Platform = 'darwin' | 'linux' | 'win32';
2
+ export interface PluginPolicy {
3
+ source: string;
4
+ path?: string;
5
+ skill?: string;
6
+ 'post-install'?: string;
7
+ 'post-update'?: string;
8
+ 'post-uninstall'?: string;
9
+ }
10
+ export interface Config {
11
+ version: 1;
12
+ plugins: PluginPolicy[];
13
+ }
14
+ export declare function recordId(plugin: PluginPolicy): string;
15
+ export declare function parseConfig(value: unknown): Config;
16
+ export declare function loadConfig(path: string): Promise<Config>;
@@ -0,0 +1,251 @@
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 loadConfig () {
13
+ return loadConfig;
14
+ },
15
+ get parseConfig () {
16
+ return parseConfig;
17
+ },
18
+ get recordId () {
19
+ return recordId;
20
+ }
21
+ });
22
+ var _promises = require("node:fs/promises");
23
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
24
+ try {
25
+ var info = gen[key](arg);
26
+ var value = info.value;
27
+ } catch (error) {
28
+ reject(error);
29
+ return;
30
+ }
31
+ if (info.done) resolve(value);
32
+ else Promise.resolve(value).then(_next, _throw);
33
+ }
34
+ function _async_to_generator(fn) {
35
+ return function() {
36
+ var self = this, args = arguments;
37
+ return new Promise(function(resolve, reject) {
38
+ var gen = fn.apply(self, args);
39
+ function _next(value) {
40
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
41
+ }
42
+ function _throw(err) {
43
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
44
+ }
45
+ _next(undefined);
46
+ });
47
+ };
48
+ }
49
+ function _ts_generator(thisArg, body) {
50
+ var f, y, t, _ = {
51
+ label: 0,
52
+ sent: function() {
53
+ if (t[0] & 1) throw t[1];
54
+ return t[1];
55
+ },
56
+ trys: [],
57
+ ops: []
58
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
59
+ return d(g, "next", {
60
+ value: verb(0)
61
+ }), d(g, "throw", {
62
+ value: verb(1)
63
+ }), d(g, "return", {
64
+ value: verb(2)
65
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
66
+ value: function() {
67
+ return this;
68
+ }
69
+ }), g;
70
+ function verb(n) {
71
+ return function(v) {
72
+ return step([
73
+ n,
74
+ v
75
+ ]);
76
+ };
77
+ }
78
+ function step(op) {
79
+ if (f) throw new TypeError("Generator is already executing.");
80
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
81
+ 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;
82
+ if (y = 0, t) op = [
83
+ op[0] & 2,
84
+ t.value
85
+ ];
86
+ switch(op[0]){
87
+ case 0:
88
+ case 1:
89
+ t = op;
90
+ break;
91
+ case 4:
92
+ _.label++;
93
+ return {
94
+ value: op[1],
95
+ done: false
96
+ };
97
+ case 5:
98
+ _.label++;
99
+ y = op[1];
100
+ op = [
101
+ 0
102
+ ];
103
+ continue;
104
+ case 7:
105
+ op = _.ops.pop();
106
+ _.trys.pop();
107
+ continue;
108
+ default:
109
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
110
+ _ = 0;
111
+ continue;
112
+ }
113
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
114
+ _.label = op[1];
115
+ break;
116
+ }
117
+ if (op[0] === 6 && _.label < t[1]) {
118
+ _.label = t[1];
119
+ t = op;
120
+ break;
121
+ }
122
+ if (t && _.label < t[2]) {
123
+ _.label = t[2];
124
+ _.ops.push(op);
125
+ break;
126
+ }
127
+ if (t[2]) _.ops.pop();
128
+ _.trys.pop();
129
+ continue;
130
+ }
131
+ op = body.call(thisArg, _);
132
+ } catch (e) {
133
+ op = [
134
+ 6,
135
+ e
136
+ ];
137
+ y = 0;
138
+ } finally{
139
+ f = t = 0;
140
+ }
141
+ if (op[0] & 5) throw op[1];
142
+ return {
143
+ value: op[0] ? op[1] : void 0,
144
+ done: true
145
+ };
146
+ }
147
+ }
148
+ function _type_of(obj) {
149
+ "@swc/helpers - typeof";
150
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
151
+ }
152
+ function object(value, label, allowed) {
153
+ if (!value || (typeof value === "undefined" ? "undefined" : _type_of(value)) !== 'object' || Array.isArray(value)) throw new Error("".concat(label, " must be an object"));
154
+ var result = value;
155
+ var unknown = Object.keys(result).find(function(key) {
156
+ return !allowed.includes(key);
157
+ });
158
+ if (unknown) throw new Error("".concat(label, " has unknown field: ").concat(unknown));
159
+ return result;
160
+ }
161
+ function nonempty(value, label) {
162
+ if (typeof value !== 'string' || !value.trim()) throw new Error("".concat(label, " must be a nonempty string"));
163
+ return value;
164
+ }
165
+ function relativePath(value, label) {
166
+ var path = nonempty(value, label);
167
+ if (path === '.') return path;
168
+ if (path.startsWith('/') || path.startsWith('\\') || /^[A-Za-z]:/.test(path) || path.includes('\\') || path.split('/').some(function(part) {
169
+ return !part || part === '.' || part === '..';
170
+ })) {
171
+ throw new Error("".concat(label, " must be a safe relative POSIX path"));
172
+ }
173
+ return path;
174
+ }
175
+ function recordId(plugin) {
176
+ var _plugin_path, _plugin_skill;
177
+ return JSON.stringify([
178
+ plugin.source,
179
+ (_plugin_path = plugin.path) !== null && _plugin_path !== void 0 ? _plugin_path : '.',
180
+ (_plugin_skill = plugin.skill) !== null && _plugin_skill !== void 0 ? _plugin_skill : null
181
+ ]);
182
+ }
183
+ function parseConfig(value) {
184
+ var root = object(value, 'config', [
185
+ 'version',
186
+ 'plugins'
187
+ ]);
188
+ if (root.version !== 1 || !Array.isArray(root.plugins)) throw new Error('config must have version 1 and a plugins array');
189
+ var seen = new Set();
190
+ var plugins = root.plugins.map(function(raw, index) {
191
+ var label = "plugins[".concat(index, "]");
192
+ var item = object(raw, label, [
193
+ 'source',
194
+ 'path',
195
+ 'skill',
196
+ 'post-install',
197
+ 'post-update',
198
+ 'post-uninstall'
199
+ ]);
200
+ var source = nonempty(item.source, "".concat(label, ".source"));
201
+ var path = item.path === undefined ? undefined : relativePath(item.path, "".concat(label, ".path"));
202
+ var skill = item.skill === undefined ? undefined : nonempty(item.skill, "".concat(label, ".skill"));
203
+ if (skill && (skill.includes('/') || skill.includes('\\') || skill === '.' || skill === '..')) throw new Error("".concat(label, ".skill must be one directory name"));
204
+ var plugin = {
205
+ source: source,
206
+ path: path,
207
+ skill: skill
208
+ };
209
+ for(var _i = 0, _iter = [
210
+ 'post-install',
211
+ 'post-update',
212
+ 'post-uninstall'
213
+ ]; _i < _iter.length; _i++){
214
+ var event = _iter[_i];
215
+ if (item[event] !== undefined) plugin[event] = nonempty(item[event], "".concat(label, ".").concat(event));
216
+ }
217
+ var id = recordId(plugin);
218
+ if (seen.has(id)) throw new Error("".concat(label, " duplicates another source/path/skill record"));
219
+ seen.add(id);
220
+ return plugin;
221
+ });
222
+ return {
223
+ version: 1,
224
+ plugins: plugins
225
+ };
226
+ }
227
+ function loadConfig(path) {
228
+ return _async_to_generator(function() {
229
+ var _;
230
+ return _ts_generator(this, function(_state) {
231
+ switch(_state.label){
232
+ case 0:
233
+ _ = JSON.parse;
234
+ return [
235
+ 4,
236
+ (0, _promises.readFile)(path, 'utf8')
237
+ ];
238
+ case 1:
239
+ return [
240
+ 2,
241
+ parseConfig.apply(void 0, [
242
+ _.apply(JSON, [
243
+ _state.sent()
244
+ ])
245
+ ])
246
+ ];
247
+ }
248
+ });
249
+ })();
250
+ }
251
+ /* 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/config.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\n\nexport type Platform = 'darwin' | 'linux' | 'win32';\nexport interface PluginPolicy {\n source: string;\n path?: string;\n skill?: string;\n 'post-install'?: string;\n 'post-update'?: string;\n 'post-uninstall'?: string;\n}\nexport interface Config {\n version: 1;\n plugins: PluginPolicy[];\n}\n\nfunction object(value: unknown, label: string, allowed: string[]): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error(`${label} must be an object`);\n const result = value as Record<string, unknown>;\n const unknown = Object.keys(result).find((key) => !allowed.includes(key));\n if (unknown) throw new Error(`${label} has unknown field: ${unknown}`);\n return result;\n}\nfunction nonempty(value: unknown, label: string): string {\n if (typeof value !== 'string' || !value.trim()) throw new Error(`${label} must be a nonempty string`);\n return value;\n}\nfunction relativePath(value: unknown, label: string): string {\n const path = nonempty(value, label);\n if (path === '.') return path;\n if (path.startsWith('/') || path.startsWith('\\\\') || /^[A-Za-z]:/.test(path) || path.includes('\\\\') || path.split('/').some((part) => !part || part === '.' || part === '..')) {\n throw new Error(`${label} must be a safe relative POSIX path`);\n }\n return path;\n}\nexport function recordId(plugin: PluginPolicy): string {\n return JSON.stringify([plugin.source, plugin.path ?? '.', plugin.skill ?? null]);\n}\nexport function parseConfig(value: unknown): Config {\n const root = object(value, 'config', ['version', 'plugins']);\n if (root.version !== 1 || !Array.isArray(root.plugins)) throw new Error('config must have version 1 and a plugins array');\n const seen = new Set<string>();\n const plugins = root.plugins.map((raw, index): PluginPolicy => {\n const label = `plugins[${index}]`;\n const item = object(raw, label, ['source', 'path', 'skill', 'post-install', 'post-update', 'post-uninstall']);\n const source = nonempty(item.source, `${label}.source`);\n const path = item.path === undefined ? undefined : relativePath(item.path, `${label}.path`);\n const skill = item.skill === undefined ? undefined : nonempty(item.skill, `${label}.skill`);\n if (skill && (skill.includes('/') || skill.includes('\\\\') || skill === '.' || skill === '..')) throw new Error(`${label}.skill must be one directory name`);\n const plugin: PluginPolicy = { source, path, skill };\n for (const event of ['post-install', 'post-update', 'post-uninstall'] as const) {\n if (item[event] !== undefined) plugin[event] = nonempty(item[event], `${label}.${event}`);\n }\n const id = recordId(plugin);\n if (seen.has(id)) throw new Error(`${label} duplicates another source/path/skill record`);\n seen.add(id);\n return plugin;\n });\n return { version: 1, plugins };\n}\nexport async function loadConfig(path: string): Promise<Config> {\n return parseConfig(JSON.parse(await readFile(path, 'utf8')));\n}\n"],"names":["loadConfig","parseConfig","recordId","object","value","label","allowed","Array","isArray","Error","result","unknown","Object","keys","find","key","includes","nonempty","trim","relativePath","path","startsWith","test","split","some","part","plugin","JSON","stringify","source","skill","root","version","plugins","seen","Set","map","raw","index","item","undefined","event","id","has","add","parse","readFile"],"mappings":";;;;;;;;;;;QA4DsBA;eAAAA;;QAtBNC;eAAAA;;QAHAC;eAAAA;;;wBAnCS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBzB,SAASC,OAAOC,KAAc,EAAEC,KAAa,EAAEC,OAAiB;IAC9D,IAAI,CAACF,SAAS,CAAA,OAAOA,sCAAP,SAAOA,MAAI,MAAM,YAAYG,MAAMC,OAAO,CAACJ,QAAQ,MAAM,IAAIK,MAAM,AAAC,GAAQ,OAANJ,OAAM;IAC1F,IAAMK,SAASN;IACf,IAAMO,UAAUC,OAAOC,IAAI,CAACH,QAAQI,IAAI,CAAC,SAACC;eAAQ,CAACT,QAAQU,QAAQ,CAACD;;IACpE,IAAIJ,SAAS,MAAM,IAAIF,MAAM,AAAC,GAA8BE,OAA5BN,OAAM,wBAA8B,OAARM;IAC5D,OAAOD;AACT;AACA,SAAS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Q,OAANxB,OAAM;QAC9C,IAAMe,OAAOmB,KAAKnB,IAAI,KAAKoB,YAAYA,YAAYrB,aAAaoB,KAAKnB,IAAI,EAAE,AAAC,GAAQ,OAANf,OAAM;QACpF,IAAMyB,QAAQS,KAAKT,KAAK,KAAKU,YAAYA,YAAYvB,SAASsB,KAAKT,KAAK,EAAE,AAAC,GAAQ,OAANzB,OAAM;QACnF,IAAIyB,SAAUA,CAAAA,MAAMd,QAAQ,CAAC,QAAQc,MAAMd,QAAQ,CAAC,SAASc,UAAU,OAAOA,UAAU,IAAG,GAAI,MAAM,IAAIrB,MAAM,AAAC,GAAQ,OAANJ,OAAM;QACxH,IAAMqB,SAAuB;YAAEG,QAAAA;YAAQT,MAAAA;YAAMU,OAAAA;QAAM;QACnD,gBAAoB,QAAA;YAAC;YAAgB;YAAe;SAAiB,OAAjD,mBAA4D;gBAArEW,QAAS;YAClB,IAAIF,IAAI,CAACE,MAAM,KAAKD,WAAWd,MAAM,CAACe,MAAM,GAAGxB,SAASsB,IAAI,CAACE,MAAM,EAAE,AAAC,GAAWA,OAATpC,OAAM,KAAS,OAANoC;QACnF;QACA,IAAMC,KAAKxC,SAASwB;QACpB,IAAIQ,KAAKS,GAAG,CAACD,KAAK,MAAM,IAAIjC,MAAM,AAAC,GAAQ,OAANJ,OAAM;QAC3C6B,KAAKU,GAAG,CAACF;QACT,OAAOhB;IACT;IACA,OAAO;QAAEM,SAAS;QAAGC,SAAAA;IAAQ;AAC/B;AACO,SAAejC,WAAWoB,IAAY;;;;;;wBACxBO,KAAKkB,KAAK;oBAAC;;wBAAMC,IAAAA,kBAAQ,EAAC1B,MAAM;;;oBAAnD;;wBAAOnB;4BAAY0B,QAAAA;gCAAW;;;;;;IAChC"}
@@ -0,0 +1,6 @@
1
+ export type { LockedPlugin } from './apm.js';
2
+ export { matchesSource, parseLock, sourceParts } from './apm.js';
3
+ export type { Config, PluginPolicy } from './config.js';
4
+ export { parseConfig, recordId } from './config.js';
5
+ export type { LifecycleEvent, Mode, RunOptions } from './runner.js';
6
+ export { runLifecycle } from './runner.js';