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