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
@@ -1,1157 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "runLifecycle", {
6
- enumerable: true,
7
- get: function() {
8
- return runLifecycle;
9
- }
10
- });
11
- var _nodecrypto = require("node:crypto");
12
- var _nodefs = require("node:fs");
13
- var _promises = require("node:fs/promises");
14
- var _nodeos = require("node:os");
15
- var _nodepath = require("node:path");
16
- var _crossspawncb = /*#__PURE__*/ _interop_require_default(require("cross-spawn-cb"));
17
- var _properlockfile = /*#__PURE__*/ _interop_require_default(require("proper-lockfile"));
18
- var _apm = require("./apm.js");
19
- var _config = require("./config.js");
20
- function _array_like_to_array(arr, len) {
21
- if (len == null || len > arr.length) len = arr.length;
22
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
23
- return arr2;
24
- }
25
- function _array_without_holes(arr) {
26
- if (Array.isArray(arr)) return _array_like_to_array(arr);
27
- }
28
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
29
- try {
30
- var info = gen[key](arg);
31
- var value = info.value;
32
- } catch (error) {
33
- reject(error);
34
- return;
35
- }
36
- if (info.done) resolve(value);
37
- else Promise.resolve(value).then(_next, _throw);
38
- }
39
- function _async_to_generator(fn) {
40
- return function() {
41
- var self = this, args = arguments;
42
- return new Promise(function(resolve, reject) {
43
- var gen = fn.apply(self, args);
44
- function _next(value) {
45
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
46
- }
47
- function _throw(err) {
48
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
49
- }
50
- _next(undefined);
51
- });
52
- };
53
- }
54
- function _instanceof(left, right) {
55
- "@swc/helpers - instanceof";
56
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
57
- return !!right[Symbol.hasInstance](left);
58
- } else return left instanceof right;
59
- }
60
- function _interop_require_default(obj) {
61
- return obj && obj.__esModule ? obj : {
62
- default: obj
63
- };
64
- }
65
- function _iterable_to_array(iter) {
66
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
67
- return Array.from(iter);
68
- }
69
- }
70
- function _non_iterable_spread() {
71
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
72
- }
73
- function _to_consumable_array(arr) {
74
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
75
- }
76
- function _ts_generator(thisArg, body) {
77
- var f, y, t, _ = {
78
- label: 0,
79
- sent: function() {
80
- if (t[0] & 1) throw t[1];
81
- return t[1];
82
- },
83
- trys: [],
84
- ops: []
85
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
86
- return d(g, "next", {
87
- value: verb(0)
88
- }), d(g, "throw", {
89
- value: verb(1)
90
- }), d(g, "return", {
91
- value: verb(2)
92
- }), typeof Symbol === "function" && d(g, Symbol.iterator, {
93
- value: function() {
94
- return this;
95
- }
96
- }), g;
97
- function verb(n) {
98
- return function(v) {
99
- return step([
100
- n,
101
- v
102
- ]);
103
- };
104
- }
105
- function step(op) {
106
- if (f) throw new TypeError("Generator is already executing.");
107
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
108
- 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;
109
- if (y = 0, t) op = [
110
- op[0] & 2,
111
- t.value
112
- ];
113
- switch(op[0]){
114
- case 0:
115
- case 1:
116
- t = op;
117
- break;
118
- case 4:
119
- _.label++;
120
- return {
121
- value: op[1],
122
- done: false
123
- };
124
- case 5:
125
- _.label++;
126
- y = op[1];
127
- op = [
128
- 0
129
- ];
130
- continue;
131
- case 7:
132
- op = _.ops.pop();
133
- _.trys.pop();
134
- continue;
135
- default:
136
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
137
- _ = 0;
138
- continue;
139
- }
140
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
141
- _.label = op[1];
142
- break;
143
- }
144
- if (op[0] === 6 && _.label < t[1]) {
145
- _.label = t[1];
146
- t = op;
147
- break;
148
- }
149
- if (t && _.label < t[2]) {
150
- _.label = t[2];
151
- _.ops.push(op);
152
- break;
153
- }
154
- if (t[2]) _.ops.pop();
155
- _.trys.pop();
156
- continue;
157
- }
158
- op = body.call(thisArg, _);
159
- } catch (e) {
160
- op = [
161
- 6,
162
- e
163
- ];
164
- y = 0;
165
- } finally{
166
- f = t = 0;
167
- }
168
- if (op[0] & 5) throw op[1];
169
- return {
170
- value: op[0] ? op[1] : void 0,
171
- done: true
172
- };
173
- }
174
- }
175
- function _ts_values(o) {
176
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
177
- if (m) {
178
- return m.call(o);
179
- }
180
- if (o && typeof o.length === "number") {
181
- return {
182
- next: function() {
183
- if (o && i >= o.length) {
184
- o = void 0;
185
- }
186
- return {
187
- value: o && o[i++],
188
- done: !o
189
- };
190
- }
191
- };
192
- }
193
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
194
- }
195
- function _type_of(obj) {
196
- "@swc/helpers - typeof";
197
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
198
- }
199
- function _unsupported_iterable_to_array(o, minLen) {
200
- if (!o) return;
201
- if (typeof o === "string") return _array_like_to_array(o, minLen);
202
- var n = Object.prototype.toString.call(o).slice(8, -1);
203
- if (n === "Object" && o.constructor) n = o.constructor.name;
204
- if (n === "Map" || n === "Set") return Array.from(o);
205
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
206
- }
207
- function inside(root, child) {
208
- var subpath = (0, _nodepath.relative)(root, child);
209
- return subpath === '' || subpath !== '..' && !subpath.startsWith("..".concat(_nodepath.sep)) && !(0, _nodepath.isAbsolute)(subpath);
210
- }
211
- function existingWithin(root, path, label) {
212
- return _async_to_generator(function() {
213
- var rootReal, candidate, candidateReal;
214
- return _ts_generator(this, function(_state) {
215
- switch(_state.label){
216
- case 0:
217
- return [
218
- 4,
219
- (0, _promises.realpath)(root)
220
- ];
221
- case 1:
222
- rootReal = _state.sent();
223
- candidate = (0, _nodepath.resolve)(rootReal, path);
224
- if (!inside(rootReal, candidate)) throw new Error("".concat(label, " escapes ").concat(root));
225
- return [
226
- 4,
227
- (0, _promises.realpath)(candidate)
228
- ];
229
- case 2:
230
- candidateReal = _state.sent();
231
- if (!inside(rootReal, candidateReal)) throw new Error("".concat(label, " resolves outside ").concat(root));
232
- return [
233
- 2,
234
- candidateReal
235
- ];
236
- }
237
- });
238
- })();
239
- }
240
- function pluginRoot(plugin, apmHome) {
241
- return (0, _nodepath.join)(apmHome, 'apm_modules', plugin.repo, plugin.path);
242
- }
243
- function destinations(plugin, policy, home, apmHome) {
244
- return _async_to_generator(function() {
245
- var output, root, _, nativeBase, _1, _plugin_nativePluginRoot, _2, error, nativeRoot, _3, error1, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step, err;
246
- return _ts_generator(this, function(_state) {
247
- switch(_state.label){
248
- case 0:
249
- output = new Set();
250
- root = pluginRoot(plugin, apmHome);
251
- if (!!policy.skill) return [
252
- 3,
253
- 4
254
- ];
255
- _ = output.add;
256
- return [
257
- 4,
258
- existingWithin((0, _nodepath.join)(apmHome, 'apm_modules'), (0, _nodepath.join)(plugin.repo, plugin.path), 'kept plugin')
259
- ];
260
- case 1:
261
- _.apply(output, [
262
- _state.sent()
263
- ]);
264
- if (!plugin.nativePluginRoot) return [
265
- 3,
266
- 3
267
- ];
268
- nativeBase = (0, _nodepath.join)(home, '.agents', 'plugins');
269
- if (!plugin.nativePluginRoot.startsWith('.agents/plugins/')) return [
270
- 3,
271
- 3
272
- ];
273
- _1 = output.add;
274
- return [
275
- 4,
276
- existingWithin(nativeBase, plugin.nativePluginRoot.slice('.agents/plugins/'.length), 'native plugin')
277
- ];
278
- case 2:
279
- _1.apply(output, [
280
- _state.sent()
281
- ]);
282
- _state.label = 3;
283
- case 3:
284
- return [
285
- 3,
286
- 20
287
- ];
288
- case 4:
289
- _state.trys.push([
290
- 4,
291
- 6,
292
- ,
293
- 7
294
- ]);
295
- _2 = output.add;
296
- return [
297
- 4,
298
- existingWithin(root, "skills/".concat(policy.skill), "kept skill ".concat(policy.skill))
299
- ];
300
- case 5:
301
- _2.apply(output, [
302
- _state.sent()
303
- ]);
304
- return [
305
- 3,
306
- 7
307
- ];
308
- case 6:
309
- error = _state.sent();
310
- if (!(error && (typeof error === "undefined" ? "undefined" : _type_of(error)) === 'object' && 'code' in error && error.code === 'ENOENT')) throw error;
311
- return [
312
- 3,
313
- 7
314
- ];
315
- case 7:
316
- if (!((_plugin_nativePluginRoot = plugin.nativePluginRoot) === null || _plugin_nativePluginRoot === void 0 ? void 0 : _plugin_nativePluginRoot.startsWith('.agents/plugins/'))) return [
317
- 3,
318
- 11
319
- ];
320
- nativeRoot = plugin.nativePluginRoot.slice('.agents/plugins/'.length);
321
- _state.label = 8;
322
- case 8:
323
- _state.trys.push([
324
- 8,
325
- 10,
326
- ,
327
- 11
328
- ]);
329
- _3 = output.add;
330
- return [
331
- 4,
332
- existingWithin((0, _nodepath.join)(home, '.agents', 'plugins'), "".concat(nativeRoot, "/skills/").concat(policy.skill), "native skill ".concat(policy.skill))
333
- ];
334
- case 9:
335
- _3.apply(output, [
336
- _state.sent()
337
- ]);
338
- return [
339
- 3,
340
- 11
341
- ];
342
- case 10:
343
- error1 = _state.sent();
344
- if (!(error1 && (typeof error1 === "undefined" ? "undefined" : _type_of(error1)) === 'object' && 'code' in error1 && error1.code === 'ENOENT')) throw error1;
345
- return [
346
- 3,
347
- 11
348
- ];
349
- case 11:
350
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
351
- _state.label = 12;
352
- case 12:
353
- _state.trys.push([
354
- 12,
355
- 17,
356
- 18,
357
- 19
358
- ]);
359
- _loop = function() {
360
- var file, parts, index, deployment, prefix, _;
361
- return _ts_generator(this, function(_state) {
362
- switch(_state.label){
363
- case 0:
364
- file = _step.value;
365
- parts = file.split('/');
366
- index = parts.lastIndexOf('skills');
367
- if (index < 0 || parts[index + 1] !== policy.skill) return [
368
- 2,
369
- "continue"
370
- ];
371
- deployment = parts.slice(0, index + 2).join('/');
372
- prefix = [
373
- '.agents/skills/',
374
- '.hermes/skills/',
375
- '.claude/skills/'
376
- ].find(function(candidate) {
377
- return deployment.startsWith(candidate);
378
- });
379
- if (!prefix) return [
380
- 3,
381
- 2
382
- ];
383
- _ = output.add;
384
- return [
385
- 4,
386
- existingWithin(home, deployment, "skill ".concat(policy.skill))
387
- ];
388
- case 1:
389
- _.apply(output, [
390
- _state.sent()
391
- ]);
392
- _state.label = 2;
393
- case 2:
394
- return [
395
- 2
396
- ];
397
- }
398
- });
399
- };
400
- _iterator = plugin.deployedFiles[Symbol.iterator]();
401
- _state.label = 13;
402
- case 13:
403
- if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
404
- 3,
405
- 16
406
- ];
407
- return [
408
- 5,
409
- _ts_values(_loop())
410
- ];
411
- case 14:
412
- _state.sent();
413
- _state.label = 15;
414
- case 15:
415
- _iteratorNormalCompletion = true;
416
- return [
417
- 3,
418
- 13
419
- ];
420
- case 16:
421
- return [
422
- 3,
423
- 19
424
- ];
425
- case 17:
426
- err = _state.sent();
427
- _didIteratorError = true;
428
- _iteratorError = err;
429
- return [
430
- 3,
431
- 19
432
- ];
433
- case 18:
434
- try {
435
- if (!_iteratorNormalCompletion && _iterator.return != null) {
436
- _iterator.return();
437
- }
438
- } finally{
439
- if (_didIteratorError) {
440
- throw _iteratorError;
441
- }
442
- }
443
- return [
444
- 7
445
- ];
446
- case 19:
447
- if (output.size === 0) throw new Error("no deployed copy found for skill ".concat(policy.skill));
448
- _state.label = 20;
449
- case 20:
450
- return [
451
- 2,
452
- _to_consumable_array(output)
453
- ];
454
- }
455
- });
456
- })();
457
- }
458
- function readState(path) {
459
- return _async_to_generator(function() {
460
- var value, _, item;
461
- return _ts_generator(this, function(_state) {
462
- switch(_state.label){
463
- case 0:
464
- if (!(0, _nodefs.existsSync)(path)) return [
465
- 2,
466
- {
467
- version: 1,
468
- receipts: {}
469
- }
470
- ];
471
- _ = JSON.parse;
472
- return [
473
- 4,
474
- (0, _promises.readFile)(path, 'utf8')
475
- ];
476
- case 1:
477
- value = _.apply(JSON, [
478
- _state.sent()
479
- ]);
480
- if (!value || (typeof value === "undefined" ? "undefined" : _type_of(value)) !== 'object' || Array.isArray(value)) throw new Error('state must be an object');
481
- item = value;
482
- if (item.version !== 1 || !item.receipts || _type_of(item.receipts) !== 'object' || Array.isArray(item.receipts)) throw new Error('unsupported state format');
483
- if (Object.values(item.receipts).some(function(receipt) {
484
- return typeof receipt !== 'string';
485
- })) throw new Error('invalid state receipt');
486
- return [
487
- 2,
488
- item
489
- ];
490
- }
491
- });
492
- })();
493
- }
494
- function saveState(path, state) {
495
- return _async_to_generator(function() {
496
- var temp, error, unused;
497
- return _ts_generator(this, function(_state) {
498
- switch(_state.label){
499
- case 0:
500
- temp = (0, _nodepath.join)((0, _nodepath.dirname)(path), ".state-".concat(process.pid, "-").concat(Date.now(), ".tmp"));
501
- _state.label = 1;
502
- case 1:
503
- _state.trys.push([
504
- 1,
505
- 4,
506
- ,
507
- 9
508
- ]);
509
- return [
510
- 4,
511
- (0, _promises.writeFile)(temp, "".concat(JSON.stringify(state, null, 2), "\n"), {
512
- mode: 384,
513
- flag: 'wx'
514
- })
515
- ];
516
- case 2:
517
- _state.sent();
518
- return [
519
- 4,
520
- (0, _promises.rename)(temp, path)
521
- ];
522
- case 3:
523
- _state.sent();
524
- return [
525
- 3,
526
- 9
527
- ];
528
- case 4:
529
- error = _state.sent();
530
- _state.label = 5;
531
- case 5:
532
- _state.trys.push([
533
- 5,
534
- 7,
535
- ,
536
- 8
537
- ]);
538
- return [
539
- 4,
540
- (0, _promises.unlink)(temp)
541
- ];
542
- case 6:
543
- _state.sent();
544
- return [
545
- 3,
546
- 8
547
- ];
548
- case 7:
549
- unused = _state.sent();
550
- return [
551
- 3,
552
- 8
553
- ];
554
- case 8:
555
- throw error;
556
- case 9:
557
- return [
558
- 2
559
- ];
560
- }
561
- });
562
- })();
563
- }
564
- function receiptKey(policy, destination) {
565
- return JSON.stringify([
566
- (0, _config.recordId)(policy),
567
- destination
568
- ]);
569
- }
570
- function digest(policy, command) {
571
- return (0, _nodecrypto.createHash)('sha256').update(JSON.stringify([
572
- (0, _config.recordId)(policy),
573
- command
574
- ])).digest('hex');
575
- }
576
- // The platform shell runs the configured string as written, as with npm and Node's `shell` option.
577
- function execute(command, cwd, environment) {
578
- return _async_to_generator(function() {
579
- return _ts_generator(this, function(_state) {
580
- switch(_state.label){
581
- case 0:
582
- return [
583
- 4,
584
- (0, _crossspawncb.default)(command, [], {
585
- cwd: cwd,
586
- env: environment,
587
- stdio: [
588
- 'ignore',
589
- 'inherit',
590
- 'inherit'
591
- ],
592
- shell: true
593
- })
594
- ];
595
- case 1:
596
- _state.sent();
597
- return [
598
- 2
599
- ];
600
- }
601
- });
602
- })();
603
- }
604
- function lockLoadError(error) {
605
- return !!error && (typeof error === "undefined" ? "undefined" : _type_of(error)) === 'object' && 'code' in error && error.code === 'ENOENT';
606
- }
607
- function runLifecycle(_0) {
608
- return _async_to_generator(function(mode) {
609
- var options, _options_home, _options_apmHome, _options_configPath, _options_environment, _options_output, home, apmHome, configPath, environment, output, config, locked, error, _options_event, apmDirectory, statePath, release, _tmp, _ref, _options_event1, _options_event2, state, failed, eventNames, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step, err, event, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _loop1, _iterator1, _step1, err;
610
- var _arguments = arguments;
611
- return _ts_generator(this, function(_state) {
612
- switch(_state.label){
613
- case 0:
614
- options = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
615
- home = (0, _nodepath.resolve)((_options_home = options.home) !== null && _options_home !== void 0 ? _options_home : (0, _nodeos.homedir)());
616
- apmHome = (0, _nodepath.resolve)((_options_apmHome = options.apmHome) !== null && _options_apmHome !== void 0 ? _options_apmHome : (0, _nodepath.join)(home, '.apm'));
617
- configPath = (_options_configPath = options.configPath) !== null && _options_configPath !== void 0 ? _options_configPath : (0, _nodepath.join)(home, '.config', 'agent-plugin-lifecycle', 'config.json');
618
- environment = (_options_environment = options.environment) !== null && _options_environment !== void 0 ? _options_environment : process.env;
619
- output = (_options_output = options.output) !== null && _options_output !== void 0 ? _options_output : console.log;
620
- return [
621
- 4,
622
- (0, _config.loadConfig)(configPath)
623
- ];
624
- case 1:
625
- config = _state.sent();
626
- _state.label = 2;
627
- case 2:
628
- _state.trys.push([
629
- 2,
630
- 4,
631
- ,
632
- 8
633
- ]);
634
- return [
635
- 4,
636
- (0, _apm.loadLock)((0, _nodepath.join)(apmHome, 'apm.lock.yaml'))
637
- ];
638
- case 3:
639
- locked = _state.sent();
640
- return [
641
- 3,
642
- 8
643
- ];
644
- case 4:
645
- error = _state.sent();
646
- if (!(mode === 'run' && ((_options_event = options.event) === null || _options_event === void 0 ? void 0 : _options_event.event) === 'post-uninstall' && lockLoadError(error))) return [
647
- 3,
648
- 6
649
- ];
650
- return [
651
- 4,
652
- (0, _promises.stat)(apmHome)
653
- ];
654
- case 5:
655
- apmDirectory = _state.sent();
656
- if (!apmDirectory.isDirectory()) throw error;
657
- locked = [];
658
- return [
659
- 3,
660
- 7
661
- ];
662
- case 6:
663
- throw error;
664
- case 7:
665
- return [
666
- 3,
667
- 8
668
- ];
669
- case 8:
670
- statePath = (0, _nodepath.join)((0, _nodepath.dirname)(configPath), 'state.json');
671
- if (!(mode === 'run')) return [
672
- 3,
673
- 10
674
- ];
675
- return [
676
- 4,
677
- (0, _promises.mkdir)((0, _nodepath.dirname)(statePath), {
678
- recursive: true,
679
- mode: 448
680
- })
681
- ];
682
- case 9:
683
- _state.sent();
684
- _state.label = 10;
685
- case 10:
686
- if (!(mode === 'run')) return [
687
- 3,
688
- 12
689
- ];
690
- return [
691
- 4,
692
- _properlockfile.default.lock((0, _nodepath.dirname)(statePath), {
693
- realpath: false
694
- })
695
- ];
696
- case 11:
697
- _tmp = _state.sent();
698
- return [
699
- 3,
700
- 13
701
- ];
702
- case 12:
703
- _tmp = undefined;
704
- _state.label = 13;
705
- case 13:
706
- release = _tmp;
707
- _state.label = 14;
708
- case 14:
709
- _state.trys.push([
710
- 14,
711
- ,
712
- 33,
713
- 35
714
- ]);
715
- return [
716
- 4,
717
- readState(statePath)
718
- ];
719
- case 15:
720
- state = _state.sent();
721
- failed = 0;
722
- if (!(mode === 'run' && ((_options_event1 = options.event) === null || _options_event1 === void 0 ? void 0 : _options_event1.event) === 'post-uninstall')) return [
723
- 3,
724
- 24
725
- ];
726
- eventNames = new Set(options.event.packages.map(function(param) {
727
- var name = param.name;
728
- return name;
729
- }));
730
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
731
- _state.label = 16;
732
- case 16:
733
- _state.trys.push([
734
- 16,
735
- 21,
736
- 22,
737
- 23
738
- ]);
739
- _loop = function() {
740
- var policy, _ref, _ref1, id, receiptKeys, sourceCandidate, sourcePartsValue, removedNameMatch, anyStillInstalled, command, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step1, key, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step2, key1, error;
741
- return _ts_generator(this, function(_state) {
742
- switch(_state.label){
743
- case 0:
744
- policy = _step.value;
745
- id = (0, _config.recordId)(policy);
746
- receiptKeys = Object.keys(state.receipts).filter(function(key) {
747
- try {
748
- return JSON.parse(key)[0] === id;
749
- } catch (unused) {
750
- return false;
751
- }
752
- });
753
- if (!receiptKeys.length) return [
754
- 2,
755
- "continue"
756
- ];
757
- sourceCandidate = policy.source.startsWith('.') || (0, _nodepath.isAbsolute)(policy.source) ? locked.find(function(plugin) {
758
- return plugin.localPath !== undefined && (0, _apm.samePath)(policy.source, plugin.localPath);
759
- }) : locked.find(function(plugin) {
760
- var _policy_path;
761
- return (0, _apm.matchesSource)(policy.source, plugin) && (plugin.path === ((_policy_path = policy.path) !== null && _policy_path !== void 0 ? _policy_path : '.') || plugin.localPath !== undefined);
762
- });
763
- sourcePartsValue = (0, _apm.sourceParts)(policy.source);
764
- removedNameMatch = eventNames.has((_ref = sourceCandidate === null || sourceCandidate === void 0 ? void 0 : sourceCandidate.repo) !== null && _ref !== void 0 ? _ref : '') || eventNames.has(sourceCandidate ? "".concat(sourceCandidate.host, "/").concat(sourceCandidate.repo) : '') || eventNames.has((_ref1 = sourcePartsValue === null || sourcePartsValue === void 0 ? void 0 : sourcePartsValue.repo) !== null && _ref1 !== void 0 ? _ref1 : '') || eventNames.has(sourcePartsValue ? "".concat(sourcePartsValue.host, "/").concat(sourcePartsValue.repo) : '') || // APM names a removed subfolder plugin `owner/repo/<folder>` (install and update events name it `owner/repo`); exact match only, so removing one folder never matches another plugin of the repository
765
- !!sourcePartsValue && !!policy.path && policy.path !== '.' && (eventNames.has("".concat(sourcePartsValue.repo, "/").concat(policy.path)) || eventNames.has("".concat(sourcePartsValue.host, "/").concat(sourcePartsValue.repo, "/").concat(policy.path))) || eventNames.has((0, _apm.localEventName)(policy.source)) || eventNames.has(policy.source);
766
- anyStillInstalled = locked.some(function(plugin) {
767
- var _policy_path;
768
- return (0, _apm.matchesSource)(policy.source, plugin) && plugin.path === ((_policy_path = policy.path) !== null && _policy_path !== void 0 ? _policy_path : '.');
769
- });
770
- if (anyStillInstalled || !removedNameMatch) return [
771
- 2,
772
- "continue"
773
- ];
774
- command = policy['post-uninstall'];
775
- if (!!command) return [
776
- 3,
777
- 2
778
- ];
779
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
780
- try {
781
- for(_iterator = receiptKeys[Symbol.iterator](); !(_iteratorNormalCompletion = (_step1 = _iterator.next()).done); _iteratorNormalCompletion = true){
782
- key = _step1.value;
783
- delete state.receipts[key];
784
- }
785
- } catch (err) {
786
- _didIteratorError = true;
787
- _iteratorError = err;
788
- } finally{
789
- try {
790
- if (!_iteratorNormalCompletion && _iterator.return != null) {
791
- _iterator.return();
792
- }
793
- } finally{
794
- if (_didIteratorError) {
795
- throw _iteratorError;
796
- }
797
- }
798
- }
799
- return [
800
- 4,
801
- saveState(statePath, state)
802
- ];
803
- case 1:
804
- _state.sent();
805
- return [
806
- 2,
807
- "continue"
808
- ];
809
- case 2:
810
- _state.trys.push([
811
- 2,
812
- 5,
813
- ,
814
- 6
815
- ]);
816
- return [
817
- 4,
818
- execute(command, home, environment)
819
- ];
820
- case 3:
821
- _state.sent();
822
- _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
823
- try {
824
- for(_iterator1 = receiptKeys[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step2 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
825
- key1 = _step2.value;
826
- delete state.receipts[key1];
827
- }
828
- } catch (err) {
829
- _didIteratorError1 = true;
830
- _iteratorError1 = err;
831
- } finally{
832
- try {
833
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
834
- _iterator1.return();
835
- }
836
- } finally{
837
- if (_didIteratorError1) {
838
- throw _iteratorError1;
839
- }
840
- }
841
- }
842
- return [
843
- 4,
844
- saveState(statePath, state)
845
- ];
846
- case 4:
847
- _state.sent();
848
- output("cleaned ".concat(id));
849
- return [
850
- 3,
851
- 6
852
- ];
853
- case 5:
854
- error = _state.sent();
855
- output("failed cleanup ".concat(id, ": ").concat(_instanceof(error, Error) ? error.message : String(error)));
856
- failed++;
857
- return [
858
- 3,
859
- 6
860
- ];
861
- case 6:
862
- return [
863
- 2
864
- ];
865
- }
866
- });
867
- };
868
- _iterator = config.plugins[Symbol.iterator]();
869
- _state.label = 17;
870
- case 17:
871
- if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
872
- 3,
873
- 20
874
- ];
875
- return [
876
- 5,
877
- _ts_values(_loop())
878
- ];
879
- case 18:
880
- _state.sent();
881
- _state.label = 19;
882
- case 19:
883
- _iteratorNormalCompletion = true;
884
- return [
885
- 3,
886
- 17
887
- ];
888
- case 20:
889
- return [
890
- 3,
891
- 23
892
- ];
893
- case 21:
894
- err = _state.sent();
895
- _didIteratorError = true;
896
- _iteratorError = err;
897
- return [
898
- 3,
899
- 23
900
- ];
901
- case 22:
902
- try {
903
- if (!_iteratorNormalCompletion && _iterator.return != null) {
904
- _iterator.return();
905
- }
906
- } finally{
907
- if (_didIteratorError) {
908
- throw _iteratorError;
909
- }
910
- }
911
- return [
912
- 7
913
- ];
914
- case 23:
915
- return [
916
- 2,
917
- failed ? 1 : 0
918
- ];
919
- case 24:
920
- if (mode === 'run' && !options.event) throw new Error('run requires an APM event');
921
- event = (_ref = (_options_event2 = options.event) === null || _options_event2 === void 0 ? void 0 : _options_event2.event) !== null && _ref !== void 0 ? _ref : 'post-install';
922
- _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
923
- _state.label = 25;
924
- case 25:
925
- _state.trys.push([
926
- 25,
927
- 30,
928
- 31,
929
- 32
930
- ]);
931
- _loop1 = function() {
932
- var policy, _policy_postupdate, command, matches, plugin, found, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, destination, key, validDigests, ready, err, error;
933
- return _ts_generator(this, function(_state) {
934
- switch(_state.label){
935
- case 0:
936
- policy = _step1.value;
937
- command = event === 'post-update' ? (_policy_postupdate = policy['post-update']) !== null && _policy_postupdate !== void 0 ? _policy_postupdate : policy['post-install'] : policy['post-install'];
938
- if (!command) return [
939
- 2,
940
- "continue"
941
- ];
942
- matches = locked.filter(function(plugin) {
943
- var _policy_path;
944
- return (0, _apm.matchesSource)(policy.source, plugin) && plugin.path === ((_policy_path = policy.path) !== null && _policy_path !== void 0 ? _policy_path : '.');
945
- });
946
- if (matches.length > 1) {
947
- output("failed ambiguous source/path record ".concat((0, _config.recordId)(policy)));
948
- failed++;
949
- return [
950
- 2,
951
- "continue"
952
- ];
953
- }
954
- if (!matches.length) {
955
- output("skipped source not installed ".concat((0, _config.recordId)(policy)));
956
- return [
957
- 2,
958
- "continue"
959
- ];
960
- }
961
- plugin = matches[0];
962
- _state.label = 1;
963
- case 1:
964
- _state.trys.push([
965
- 1,
966
- 14,
967
- ,
968
- 15
969
- ]);
970
- return [
971
- 4,
972
- destinations(plugin, policy, home, apmHome)
973
- ];
974
- case 2:
975
- found = _state.sent();
976
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
977
- _state.label = 3;
978
- case 3:
979
- _state.trys.push([
980
- 3,
981
- 11,
982
- 12,
983
- 13
984
- ]);
985
- _iterator = found[Symbol.iterator]();
986
- _state.label = 4;
987
- case 4:
988
- if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
989
- 3,
990
- 10
991
- ];
992
- destination = _step.value;
993
- key = receiptKey(policy, destination);
994
- if (!(mode === 'check')) return [
995
- 3,
996
- 5
997
- ];
998
- validDigests = [
999
- policy['post-install'],
1000
- policy['post-update']
1001
- ].filter(function(item) {
1002
- return !!item;
1003
- }).map(function(item) {
1004
- return digest(policy, item);
1005
- });
1006
- ready = validDigests.includes(state.receipts[key]);
1007
- output("".concat(ready ? 'ok' : 'missing', " ").concat((0, _config.recordId)(policy), " ").concat(destination));
1008
- if (!ready) failed++;
1009
- return [
1010
- 3,
1011
- 9
1012
- ];
1013
- case 5:
1014
- delete state.receipts[key];
1015
- return [
1016
- 4,
1017
- saveState(statePath, state)
1018
- ];
1019
- case 6:
1020
- _state.sent();
1021
- return [
1022
- 4,
1023
- execute(command, destination, environment)
1024
- ];
1025
- case 7:
1026
- _state.sent();
1027
- state.receipts[key] = digest(policy, command);
1028
- return [
1029
- 4,
1030
- saveState(statePath, state)
1031
- ];
1032
- case 8:
1033
- _state.sent();
1034
- output("ran ".concat((0, _config.recordId)(policy), " ").concat(destination));
1035
- _state.label = 9;
1036
- case 9:
1037
- _iteratorNormalCompletion = true;
1038
- return [
1039
- 3,
1040
- 4
1041
- ];
1042
- case 10:
1043
- return [
1044
- 3,
1045
- 13
1046
- ];
1047
- case 11:
1048
- err = _state.sent();
1049
- _didIteratorError = true;
1050
- _iteratorError = err;
1051
- return [
1052
- 3,
1053
- 13
1054
- ];
1055
- case 12:
1056
- try {
1057
- if (!_iteratorNormalCompletion && _iterator.return != null) {
1058
- _iterator.return();
1059
- }
1060
- } finally{
1061
- if (_didIteratorError) {
1062
- throw _iteratorError;
1063
- }
1064
- }
1065
- return [
1066
- 7
1067
- ];
1068
- case 13:
1069
- return [
1070
- 3,
1071
- 15
1072
- ];
1073
- case 14:
1074
- error = _state.sent();
1075
- output("failed ".concat((0, _config.recordId)(policy), ": ").concat(_instanceof(error, Error) ? error.message : String(error)));
1076
- failed++;
1077
- return [
1078
- 3,
1079
- 15
1080
- ];
1081
- case 15:
1082
- return [
1083
- 2
1084
- ];
1085
- }
1086
- });
1087
- };
1088
- _iterator1 = config.plugins[Symbol.iterator]();
1089
- _state.label = 26;
1090
- case 26:
1091
- if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done)) return [
1092
- 3,
1093
- 29
1094
- ];
1095
- return [
1096
- 5,
1097
- _ts_values(_loop1())
1098
- ];
1099
- case 27:
1100
- _state.sent();
1101
- _state.label = 28;
1102
- case 28:
1103
- _iteratorNormalCompletion1 = true;
1104
- return [
1105
- 3,
1106
- 26
1107
- ];
1108
- case 29:
1109
- return [
1110
- 3,
1111
- 32
1112
- ];
1113
- case 30:
1114
- err = _state.sent();
1115
- _didIteratorError1 = true;
1116
- _iteratorError1 = err;
1117
- return [
1118
- 3,
1119
- 32
1120
- ];
1121
- case 31:
1122
- try {
1123
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
1124
- _iterator1.return();
1125
- }
1126
- } finally{
1127
- if (_didIteratorError1) {
1128
- throw _iteratorError1;
1129
- }
1130
- }
1131
- return [
1132
- 7
1133
- ];
1134
- case 32:
1135
- return [
1136
- 2,
1137
- failed ? 1 : 0
1138
- ];
1139
- case 33:
1140
- return [
1141
- 4,
1142
- release === null || release === void 0 ? void 0 : release()
1143
- ];
1144
- case 34:
1145
- _state.sent();
1146
- return [
1147
- 7
1148
- ];
1149
- case 35:
1150
- return [
1151
- 2
1152
- ];
1153
- }
1154
- });
1155
- }).apply(this, arguments);
1156
- }
1157
- /* 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; }