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.
- package/README.md +243 -90
- package/bin/cli.js +8 -1
- package/dist/cjs/apm.d.cts +62 -13
- package/dist/cjs/apm.d.ts +62 -13
- package/dist/cjs/apm.js +534 -115
- package/dist/cjs/apm.js.map +1 -1
- package/dist/cjs/approvals.d.cts +26 -0
- package/dist/cjs/approvals.d.ts +26 -0
- package/dist/cjs/approvals.js +302 -0
- package/dist/cjs/approvals.js.map +1 -0
- package/dist/cjs/cli/index.d.cts +5 -0
- package/dist/cjs/cli/index.d.ts +5 -0
- package/dist/cjs/cli/index.js +53 -0
- package/dist/cjs/cli/index.js.map +1 -0
- package/dist/cjs/cli/install.d.cts +17 -0
- package/dist/cjs/cli/install.d.ts +17 -0
- package/dist/cjs/cli/install.js +308 -0
- package/dist/cjs/cli/install.js.map +1 -0
- package/dist/cjs/cli/report.d.cts +6 -0
- package/dist/cjs/cli/report.d.ts +6 -0
- package/dist/cjs/cli/report.js +47 -0
- package/dist/cjs/cli/report.js.map +1 -0
- package/dist/cjs/cli/status.d.cts +2 -0
- package/dist/cjs/cli/status.d.ts +2 -0
- package/dist/cjs/cli/status.js +222 -0
- package/dist/cjs/cli/status.js.map +1 -0
- package/dist/cjs/cli/types.d.cts +10 -0
- package/dist/cjs/cli/types.d.ts +10 -0
- package/dist/cjs/cli/types.js +6 -0
- package/dist/cjs/cli/types.js.map +1 -0
- package/dist/cjs/cli/usage.d.cts +2 -0
- package/dist/cjs/cli/usage.d.ts +2 -0
- package/dist/cjs/cli/usage.js +21 -0
- package/dist/cjs/cli/usage.js.map +1 -0
- package/dist/cjs/cli.d.cts +2 -1
- package/dist/cjs/cli.d.ts +2 -1
- package/dist/cjs/cli.js +65 -204
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/constants.d.cts +35 -0
- package/dist/cjs/constants.d.ts +35 -0
- package/dist/cjs/constants.js +115 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/copies.d.cts +40 -0
- package/dist/cjs/copies.d.ts +40 -0
- package/dist/cjs/copies.js +937 -0
- package/dist/cjs/copies.js.map +1 -0
- package/dist/cjs/index.d.cts +3 -6
- package/dist/cjs/index.d.ts +3 -6
- package/dist/cjs/index.js +20 -19
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/install.d.cts +6 -0
- package/dist/cjs/install.d.ts +6 -0
- package/dist/cjs/install.js +511 -0
- package/dist/cjs/install.js.map +1 -0
- package/dist/cjs/lib/errors.d.cts +5 -0
- package/dist/cjs/lib/errors.d.ts +5 -0
- package/dist/cjs/lib/errors.js +41 -0
- package/dist/cjs/lib/errors.js.map +1 -0
- package/dist/cjs/lib/object.d.cts +2 -0
- package/dist/cjs/lib/object.d.ts +2 -0
- package/dist/cjs/lib/object.js +18 -0
- package/dist/cjs/lib/object.js.map +1 -0
- package/dist/cjs/lib/options.d.cts +10 -0
- package/dist/cjs/lib/options.d.ts +10 -0
- package/dist/cjs/lib/options.js +26 -0
- package/dist/cjs/lib/options.js.map +1 -0
- package/dist/cjs/lib/run.d.cts +2 -0
- package/dist/cjs/lib/run.d.ts +2 -0
- package/dist/cjs/lib/run.js +40 -0
- package/dist/cjs/lib/run.js.map +1 -0
- package/dist/cjs/lib/store.d.cts +9 -0
- package/dist/cjs/lib/store.d.ts +9 -0
- package/dist/cjs/lib/store.js +418 -0
- package/dist/cjs/lib/store.js.map +1 -0
- package/dist/cjs/lib/visible.d.cts +9 -0
- package/dist/cjs/lib/visible.d.ts +9 -0
- package/dist/cjs/lib/visible.js +26 -0
- package/dist/cjs/lib/visible.js.map +1 -0
- package/dist/cjs/manifest.d.cts +4 -0
- package/dist/cjs/manifest.d.ts +4 -0
- package/dist/cjs/{config.js → manifest.js} +33 -94
- package/dist/cjs/manifest.js.map +1 -0
- package/dist/cjs/state.d.cts +17 -0
- package/dist/cjs/state.d.ts +17 -0
- package/dist/cjs/state.js +143 -0
- package/dist/cjs/state.js.map +1 -0
- package/dist/cjs/status.d.cts +3 -0
- package/dist/cjs/status.d.ts +3 -0
- package/dist/cjs/status.js +273 -0
- package/dist/cjs/status.js.map +1 -0
- package/dist/cjs/types.d.cts +39 -0
- package/dist/cjs/types.d.ts +39 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/apm.d.ts +62 -13
- package/dist/esm/apm.js +208 -96
- package/dist/esm/apm.js.map +1 -1
- package/dist/esm/approvals.d.ts +26 -0
- package/dist/esm/approvals.js +43 -0
- package/dist/esm/approvals.js.map +1 -0
- package/dist/esm/cli/index.d.ts +5 -0
- package/dist/esm/cli/index.js +5 -0
- package/dist/esm/cli/index.js.map +1 -0
- package/dist/esm/cli/install.d.ts +17 -0
- package/dist/esm/cli/install.js +89 -0
- package/dist/esm/cli/install.js.map +1 -0
- package/dist/esm/cli/report.d.ts +6 -0
- package/dist/esm/cli/report.js +21 -0
- package/dist/esm/cli/report.js.map +1 -0
- package/dist/esm/cli/status.d.ts +2 -0
- package/dist/esm/cli/status.js +41 -0
- package/dist/esm/cli/status.js.map +1 -0
- package/dist/esm/cli/types.d.ts +10 -0
- package/dist/esm/cli/types.js +2 -0
- package/dist/esm/cli/types.js.map +1 -0
- package/dist/esm/cli/usage.d.ts +2 -0
- package/dist/esm/cli/usage.js +2 -0
- package/dist/esm/cli/usage.js.map +1 -0
- package/dist/esm/cli.d.ts +2 -1
- package/dist/esm/cli.js +46 -65
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/constants.d.ts +35 -0
- package/dist/esm/constants.js +37 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/copies.d.ts +40 -0
- package/dist/esm/copies.js +226 -0
- package/dist/esm/copies.js.map +1 -0
- package/dist/esm/index.d.ts +3 -6
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/install.d.ts +6 -0
- package/dist/esm/install.js +116 -0
- package/dist/esm/install.js.map +1 -0
- package/dist/esm/lib/errors.d.ts +5 -0
- package/dist/esm/lib/errors.js +9 -0
- package/dist/esm/lib/errors.js.map +1 -0
- package/dist/esm/lib/object.d.ts +2 -0
- package/dist/esm/lib/object.js +3 -0
- package/dist/esm/lib/object.js.map +1 -0
- package/dist/esm/lib/options.d.ts +10 -0
- package/dist/esm/lib/options.js +15 -0
- package/dist/esm/lib/options.js.map +1 -0
- package/dist/esm/lib/run.d.ts +2 -0
- package/dist/esm/lib/run.js +29 -0
- package/dist/esm/lib/run.js.map +1 -0
- package/dist/esm/lib/store.d.ts +9 -0
- package/dist/esm/lib/store.js +91 -0
- package/dist/esm/lib/store.js.map +1 -0
- package/dist/esm/lib/visible.d.ts +9 -0
- package/dist/esm/lib/visible.js +12 -0
- package/dist/esm/lib/visible.js.map +1 -0
- package/dist/esm/manifest.d.ts +4 -0
- package/dist/esm/manifest.js +25 -0
- package/dist/esm/manifest.js.map +1 -0
- package/dist/esm/state.d.ts +17 -0
- package/dist/esm/state.js +32 -0
- package/dist/esm/state.js.map +1 -0
- package/dist/esm/status.d.ts +3 -0
- package/dist/esm/status.js +44 -0
- package/dist/esm/status.js.map +1 -0
- package/dist/esm/types.d.ts +39 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +25 -9
- package/config/config.example.json +0 -22
- package/dist/cjs/config.d.cts +0 -16
- package/dist/cjs/config.d.ts +0 -16
- package/dist/cjs/config.js.map +0 -1
- package/dist/cjs/runner.d.cts +0 -19
- package/dist/cjs/runner.d.ts +0 -19
- package/dist/cjs/runner.js +0 -1391
- package/dist/cjs/runner.js.map +0 -1
- package/dist/esm/config.d.ts +0 -16
- package/dist/esm/config.js +0 -74
- package/dist/esm/config.js.map +0 -1
- package/dist/esm/runner.d.ts +0 -19
- package/dist/esm/runner.js +0 -335
- package/dist/esm/runner.js.map +0 -1
package/dist/esm/apm.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import { basename,
|
|
1
|
+
import { readdir, readFile, realpath } from 'node:fs/promises';
|
|
2
|
+
import { basename, isAbsolute, join, resolve } from 'node:path';
|
|
3
3
|
import { parse } from 'yaml';
|
|
4
|
+
import { APM_LOCK, APM_MODULES, SKILLS } from './constants.js';
|
|
5
|
+
import { message, missing } from './lib/errors.js';
|
|
6
|
+
import { isRecord } from './lib/object.js';
|
|
7
|
+
export const isUnreadable = (row)=>'reason' in row;
|
|
4
8
|
function record(value, label) {
|
|
5
|
-
if (!
|
|
9
|
+
if (!isRecord(value)) throw new Error(`${label} must be an object`);
|
|
6
10
|
return value;
|
|
7
11
|
}
|
|
8
12
|
function requiredString(value, label) {
|
|
@@ -15,107 +19,215 @@ function safePath(value, label, dot = false) {
|
|
|
15
19
|
if (path.startsWith('/') || path.includes('\\') || /^[A-Za-z]:/.test(path) || path.split('/').some((part)=>!part || part === '.' || part === '..')) throw new Error(`${label} contains an unsafe path segment`);
|
|
16
20
|
return path;
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
host: host.toLowerCase(),
|
|
43
|
-
repo: path
|
|
44
|
-
};
|
|
22
|
+
function optionalRecord(value, label) {
|
|
23
|
+
return value === undefined || value === null ? undefined : record(value, label);
|
|
24
|
+
}
|
|
25
|
+
function optionalString(value, label) {
|
|
26
|
+
return value === undefined || value === null ? undefined : requiredString(value, label);
|
|
27
|
+
}
|
|
28
|
+
function deployedFiles(value, label, absolute) {
|
|
29
|
+
const deployed = value !== null && value !== void 0 ? value : [];
|
|
30
|
+
if (!Array.isArray(deployed) || !deployed.every((file)=>typeof file === 'string')) throw new Error(`${label}.deployed_files must be an array of paths`);
|
|
31
|
+
return deployed.map((file, index)=>absolute && isAbsolute(file) ? file : safePath(file, `${label}.deployed_files[${index}]`));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `repo_url` as a path, and the host when it is a URL (APM's spec: `host` is recorded "when not inferable from `repo_url`"). An unsafe
|
|
35
|
+
* path throws, for the whole lock; a value that names no path (empty, or a URL that does not parse) is `undefined`, for its row alone.
|
|
36
|
+
*/ function repository(value, label) {
|
|
37
|
+
if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(value)) return value ? {
|
|
38
|
+
repo: safePath(value, label)
|
|
39
|
+
} : undefined;
|
|
40
|
+
const url = URL.parse(value);
|
|
41
|
+
const path = url === null || url === void 0 ? void 0 : url.pathname.slice(1);
|
|
42
|
+
return url && path ? {
|
|
43
|
+
host: url.host,
|
|
44
|
+
repo: safePath(path, label)
|
|
45
|
+
} : undefined;
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
export function matchesSource(policySource, plugin, platform = process.platform) {
|
|
52
|
-
if (plugin.localPath !== undefined) return samePath(policySource, plugin.localPath, platform);
|
|
53
|
-
const parts = sourceParts(policySource);
|
|
54
|
-
return !!parts && parts.host === plugin.host.toLowerCase() && parts.repo === plugin.repo.replace(/\.git$/, '');
|
|
55
|
-
}
|
|
56
|
-
export function localEventName(source) {
|
|
57
|
-
return `_local/${basename(source).replace(/\/$/, '')}`;
|
|
58
|
-
}
|
|
59
|
-
export function lockIdentity(plugin) {
|
|
60
|
-
var _plugin_localPath;
|
|
61
|
-
return JSON.stringify([
|
|
62
|
-
plugin.host,
|
|
63
|
-
plugin.repo,
|
|
64
|
-
plugin.path,
|
|
65
|
-
(_plugin_localPath = plugin.localPath) !== null && _plugin_localPath !== void 0 ? _plugin_localPath : null
|
|
66
|
-
]);
|
|
67
|
-
}
|
|
68
|
-
export function parseLock(value) {
|
|
47
|
+
/**
|
|
48
|
+
* The rows of a parsed lock. A path that could leave its root makes the whole lock unreadable; any other problem makes only its row
|
|
49
|
+
* unreadable. `absolute` accepts absolute deployed paths, which only a user-scope lock may hold.
|
|
50
|
+
*/ export function parseLock(value, absolute = false) {
|
|
69
51
|
const root = record(value, 'APM lock');
|
|
70
52
|
if (!Array.isArray(root.dependencies)) throw new Error('APM lock dependencies must be an array');
|
|
71
53
|
const seen = new Set();
|
|
72
|
-
return root.dependencies.map((
|
|
54
|
+
return root.dependencies.map((source, index)=>{
|
|
73
55
|
const label = `APM lock dependencies[${index}]`;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
56
|
+
if (!isRecord(source)) return {
|
|
57
|
+
name: `dependencies[${index}]`,
|
|
58
|
+
reason: `${label} must be an object`,
|
|
59
|
+
deployedFiles: []
|
|
60
|
+
};
|
|
61
|
+
const local = source.source === 'local';
|
|
62
|
+
// the paths: where apl looks for copies, and APM's cache of the package
|
|
63
|
+
const native = optionalRecord(source.native_plugin, `${label}.native_plugin`);
|
|
64
|
+
const nativePluginRoot = native ? safePath(native.root, `${label}.native_plugin.root`) : undefined;
|
|
65
|
+
const deployed = deployedFiles(source.deployed_files, label, absolute);
|
|
66
|
+
const located = typeof source.repo_url === 'string' ? repository(source.repo_url, `${label}.repo_url`) : undefined;
|
|
67
|
+
// APM writes no virtual_path for a plugin at the repository root
|
|
68
|
+
const path = local || source.virtual_path === undefined || source.virtual_path === null ? '.' : safePath(source.virtual_path, `${label}.virtual_path`, true);
|
|
69
|
+
try {
|
|
70
|
+
var _item_host, _item_localPath;
|
|
71
|
+
if (!located) throw new Error(`${label}.repo_url must be a repository path or URL`);
|
|
72
|
+
const revision = [
|
|
73
|
+
optionalString(source.resolved_commit, `${label}.resolved_commit`),
|
|
74
|
+
optionalString(source.resolved_hash, `${label}.resolved_hash`),
|
|
75
|
+
optionalString(source.content_hash, `${label}.content_hash`)
|
|
76
|
+
].filter(Boolean).join(':');
|
|
77
|
+
if (!revision) throw new Error(`${label} has none of resolved_commit, resolved_hash and content_hash`);
|
|
78
|
+
let item;
|
|
79
|
+
if (local) {
|
|
80
|
+
if (!located.repo.startsWith('_local/')) throw new Error(`${label}.repo_url is not a local package key`);
|
|
81
|
+
item = {
|
|
82
|
+
repo: located.repo,
|
|
83
|
+
path,
|
|
84
|
+
localPath: requiredString(source.local_path, `${label}.local_path`),
|
|
85
|
+
revision,
|
|
86
|
+
nativePluginRoot,
|
|
87
|
+
deployedFiles: deployed
|
|
88
|
+
};
|
|
89
|
+
} else {
|
|
90
|
+
var _optionalString;
|
|
91
|
+
const host = (_optionalString = optionalString(source.host, `${label}.host`)) !== null && _optionalString !== void 0 ? _optionalString : located.host;
|
|
92
|
+
if (source.port !== undefined && source.port !== null && !Number.isInteger(source.port)) throw new Error(`${label}.port must be an integer`);
|
|
93
|
+
const port = host === undefined || source.port === undefined || source.port === null ? '' : `:${source.port}`;
|
|
94
|
+
item = {
|
|
95
|
+
...host === undefined ? {} : {
|
|
96
|
+
host: `${host}${port}`
|
|
97
|
+
},
|
|
98
|
+
repo: located.repo,
|
|
99
|
+
path,
|
|
100
|
+
revision,
|
|
101
|
+
nativePluginRoot,
|
|
102
|
+
deployedFiles: deployed
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const identity = JSON.stringify([
|
|
106
|
+
(_item_host = item.host) !== null && _item_host !== void 0 ? _item_host : null,
|
|
107
|
+
item.repo,
|
|
108
|
+
item.path,
|
|
109
|
+
(_item_localPath = item.localPath) !== null && _item_localPath !== void 0 ? _item_localPath : null
|
|
110
|
+
]);
|
|
111
|
+
if (seen.has(identity)) throw new Error(`${label} duplicates another lock entry`);
|
|
112
|
+
seen.add(identity);
|
|
113
|
+
return item;
|
|
114
|
+
} catch (error) {
|
|
115
|
+
return {
|
|
116
|
+
name: typeof source.repo_url === 'string' && source.repo_url ? source.repo_url : `dependencies[${index}]`,
|
|
117
|
+
reason: message(error),
|
|
109
118
|
nativePluginRoot,
|
|
110
|
-
deployedFiles
|
|
119
|
+
deployedFiles: deployed
|
|
111
120
|
};
|
|
112
121
|
}
|
|
113
|
-
const identity = lockIdentity(plugin);
|
|
114
|
-
if (seen.has(identity)) throw new Error(`${label} duplicates another lock entry`);
|
|
115
|
-
seen.add(identity);
|
|
116
|
-
return plugin;
|
|
117
122
|
});
|
|
118
123
|
}
|
|
119
|
-
export async function
|
|
120
|
-
|
|
124
|
+
/** The rows of an APM lock file, or undefined when the file does not exist. `absolute` as for `parseLock`. */ export async function readLock(path, absolute = false) {
|
|
125
|
+
let text;
|
|
126
|
+
try {
|
|
127
|
+
text = await readFile(path, 'utf8');
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (missing(error)) return undefined;
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
// no pretty errors: the message quotes none of the file
|
|
134
|
+
return parseLock(parse(text, {
|
|
135
|
+
prettyErrors: false
|
|
136
|
+
}), absolute);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
throw new Error(`cannot read ${path}: ${message(error)}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async function samePlace(left, right) {
|
|
142
|
+
try {
|
|
143
|
+
return await realpath(left) === await realpath(right);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (missing(error)) return false;
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** The user scope with `global`, or when `cwd` is the APM home (where APM starts a user-scope lifecycle command); otherwise the project in `cwd`. */ export async function resolveScope(options) {
|
|
150
|
+
const { cwd, home, apmHome } = options;
|
|
151
|
+
if (options.global || await samePlace(cwd, apmHome)) return {
|
|
152
|
+
global: true,
|
|
153
|
+
lock: join(apmHome, APM_LOCK),
|
|
154
|
+
root: home,
|
|
155
|
+
manifestRoot: apmHome,
|
|
156
|
+
modules: join(apmHome, APM_MODULES)
|
|
157
|
+
};
|
|
158
|
+
return {
|
|
159
|
+
global: false,
|
|
160
|
+
lock: join(cwd, APM_LOCK),
|
|
161
|
+
root: cwd,
|
|
162
|
+
manifestRoot: cwd,
|
|
163
|
+
modules: join(cwd, APM_MODULES)
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const native = (path)=>join(...path.split('/'));
|
|
167
|
+
async function skillFolders(folder, bound) {
|
|
168
|
+
try {
|
|
169
|
+
const entries = await readdir(join(folder, SKILLS), {
|
|
170
|
+
withFileTypes: true
|
|
171
|
+
});
|
|
172
|
+
return entries.filter((entry)=>entry.isDirectory()).map((entry)=>entry.name).sort().map((name)=>({
|
|
173
|
+
folder: join(folder, SKILLS, name),
|
|
174
|
+
within: `${SKILLS}/${name}`,
|
|
175
|
+
...bound === undefined ? {} : {
|
|
176
|
+
bound
|
|
177
|
+
}
|
|
178
|
+
}));
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (missing(error)) return [];
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/** A folder and its `skills/<name>/` folders. */ async function withSkills(folder, bound) {
|
|
185
|
+
return [
|
|
186
|
+
{
|
|
187
|
+
folder,
|
|
188
|
+
within: '',
|
|
189
|
+
...bound === undefined ? {} : {
|
|
190
|
+
bound
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
...await skillFolders(folder, bound)
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
/** `entry` is a folder in APM's record: another recorded path lies under it. */ function recordedFolder(entry, entries) {
|
|
197
|
+
return entries.some((other)=>other.length > entry.length && other.startsWith(entry) && (other[entry.length] === '/' || other[entry.length] === '\\'));
|
|
198
|
+
}
|
|
199
|
+
/** The folders a row records: each folder in `deployed_files` (a skill folder, at `skills/<its name>`), and the native plugin folder with its skills. */ export async function recordedFolders(item, scope) {
|
|
200
|
+
const folders = [];
|
|
201
|
+
const seen = new Set();
|
|
202
|
+
for (const entry of item.deployedFiles){
|
|
203
|
+
if (!recordedFolder(entry, item.deployedFiles)) continue;
|
|
204
|
+
const absolute = isAbsolute(entry);
|
|
205
|
+
// an absolute path in the platform's own form: APM on Windows records `D:/...` with forward slashes
|
|
206
|
+
const folder = absolute ? resolve(entry) : join(scope.root, native(entry));
|
|
207
|
+
if (seen.has(folder)) continue;
|
|
208
|
+
seen.add(folder);
|
|
209
|
+
folders.push({
|
|
210
|
+
folder,
|
|
211
|
+
within: `${SKILLS}/${basename(folder)}`,
|
|
212
|
+
...absolute ? {} : {
|
|
213
|
+
bound: scope.root
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
if (item.nativePluginRoot) {
|
|
218
|
+
for (const found of (await withSkills(join(scope.root, native(item.nativePluginRoot)), scope.root)))if (!seen.has(found.folder)) folders.push(found);
|
|
219
|
+
}
|
|
220
|
+
return folders;
|
|
221
|
+
}
|
|
222
|
+
/** The folders a package's row records, and the root and skills of its APM cache copy whose place in the package no recorded folder carries. */ export async function packageFolders(item, scope) {
|
|
223
|
+
const folders = await recordedFolders(item, scope);
|
|
224
|
+
const carried = new Set(folders.map((found)=>found.within));
|
|
225
|
+
// the cache is never read or run, so it has no bound
|
|
226
|
+
const cache = (await withSkills(join(scope.modules, native(item.repo), ...item.path === '.' ? [] : [
|
|
227
|
+
native(item.path)
|
|
228
|
+
]))).filter((found)=>!carried.has(found.within));
|
|
229
|
+
return {
|
|
230
|
+
folders,
|
|
231
|
+
cache
|
|
232
|
+
};
|
|
121
233
|
}
|
package/dist/esm/apm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/agent-plugin-lifecycle/src/apm.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { basename, posix, win32 } from 'node:path';\nimport { parse } from 'yaml';\n\nexport interface LockedPlugin {\n host: string;\n repo: string;\n path: string;\n revision: string;\n localPath?: string;\n nativePluginRoot?: string;\n deployedFiles: string[];\n}\nfunction record(value: unknown, label: string): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error(`${label} must be an object`);\n return value as Record<string, unknown>;\n}\nfunction requiredString(value: unknown, label: string): string {\n if (typeof value !== 'string' || !value) throw new Error(`${label} must be a nonempty string`);\n return value;\n}\nfunction safePath(value: unknown, label: string, dot = false): string {\n const path = requiredString(value, label);\n if (dot && path === '.') return path;\n if (path.startsWith('/') || path.includes('\\\\') || /^[A-Za-z]:/.test(path) || path.split('/').some((part) => !part || part === '.' || part === '..')) throw new Error(`${label} contains an unsafe path segment`);\n return path;\n}\nexport function sourceParts(source: string): { host: string; repo: string } | undefined {\n let host: string;\n let path: string;\n const scp = source.includes('://') ? null : /^(?:[^@/:]+@)?([^/:]+):(.+)$/.exec(source);\n if (scp) {\n host = scp[1];\n path = scp[2];\n } else {\n try {\n const url = new URL(source);\n if (!['https:', 'ssh:', 'http:'].includes(url.protocol)) return undefined;\n host = url.hostname;\n path = url.pathname.replace(/^\\//, '');\n } catch {\n return undefined;\n }\n }\n path = path.replace(/\\.git$/, '').replace(/\\/$/, '');\n if (!host || !path || path.split('/').some((part) => !part || part === '.' || part === '..')) return undefined;\n return { host: host.toLowerCase(), repo: path };\n}\n// Same path whatever separators or trailing slash either side was written with; Windows paths also ignore case.\nexport function samePath(left: string, right: string, platform: NodeJS.Platform = process.platform): boolean {\n if (platform !== 'win32') return posix.resolve(left) === posix.resolve(right);\n return win32.resolve(left).toLowerCase() === win32.resolve(right).toLowerCase();\n}\nexport function matchesSource(policySource: string, plugin: LockedPlugin, platform: NodeJS.Platform = process.platform): boolean {\n if (plugin.localPath !== undefined) return samePath(policySource, plugin.localPath, platform);\n const parts = sourceParts(policySource);\n return !!parts && parts.host === plugin.host.toLowerCase() && parts.repo === plugin.repo.replace(/\\.git$/, '');\n}\nexport function localEventName(source: string): string {\n return `_local/${basename(source).replace(/\\/$/, '')}`;\n}\nexport function lockIdentity(plugin: LockedPlugin): string {\n return JSON.stringify([plugin.host, plugin.repo, plugin.path, plugin.localPath ?? null]);\n}\nexport function parseLock(value: unknown): LockedPlugin[] {\n const root = record(value, 'APM lock');\n if (!Array.isArray(root.dependencies)) throw new Error('APM lock dependencies must be an array');\n const seen = new Set<string>();\n return root.dependencies.map((raw, index): LockedPlugin => {\n const label = `APM lock dependencies[${index}]`;\n const source = record(raw, label);\n let plugin: LockedPlugin;\n if (source.source === 'local' && source.package_type === 'agent_plugin') {\n const repo = safePath(source.repo_url, `${label}.repo_url`);\n if (!repo.startsWith('_local/')) throw new Error(`${label}.repo_url is not a local plugin key`);\n const localPath = requiredString(source.local_path, `${label}.local_path`);\n const hash = requiredString(source.content_hash, `${label}.content_hash`);\n if (!/^sha256:[0-9a-f]{64}$/.test(hash)) throw new Error(`${label} has invalid content hash`);\n plugin = { host: 'local', repo, path: '.', revision: hash, localPath, deployedFiles: [] };\n } else {\n const host = requiredString(source.host, `${label}.host`);\n const repo = safePath(source.repo_url, `${label}.repo_url`);\n // APM writes no virtual_path for a plugin at the repository root (recorded from APM 0.37.0)\n const path = source.virtual_path === undefined || source.virtual_path === null ? '.' : safePath(source.virtual_path, `${label}.virtual_path`, true);\n const commit = requiredString(source.resolved_commit, `${label}.resolved_commit`);\n const hash = requiredString(source.content_hash, `${label}.content_hash`);\n if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(commit) || !/^sha256:[0-9a-f]{64}$/.test(hash)) throw new Error(`${label} has invalid revision evidence`);\n const native = source.native_plugin === undefined || source.native_plugin === null ? undefined : record(source.native_plugin, `${label}.native_plugin`);\n const nativePluginRoot = native ? safePath(native.root, `${label}.native_plugin.root`) : undefined;\n const deployed = source.deployed_files ?? [];\n if (!Array.isArray(deployed) || !deployed.every((file) => typeof file === 'string')) throw new Error(`${label}.deployed_files must be an array of paths`);\n const deployedFiles = deployed.map((file: string, fileIndex: number) => safePath(file, `${label}.deployed_files[${fileIndex}]`));\n plugin = { host, repo, path, revision: `${commit}:${hash}`, nativePluginRoot, deployedFiles };\n }\n const identity = lockIdentity(plugin);\n if (seen.has(identity)) throw new Error(`${label} duplicates another lock entry`);\n seen.add(identity);\n return plugin;\n });\n}\nexport async function loadLock(path: string): Promise<LockedPlugin[]> {\n return parseLock(parse(await readFile(path, 'utf8')));\n}\n"],"names":["readFile","basename","posix","win32","parse","record","value","label","Array","isArray","Error","requiredString","safePath","dot","path","startsWith","includes","test","split","some","part","sourceParts","source","host","scp","exec","url","URL","protocol","undefined","hostname","pathname","replace","toLowerCase","repo","samePath","left","right","platform","process","resolve","matchesSource","policySource","plugin","localPath","parts","localEventName","lockIdentity","JSON","stringify","parseLock","root","dependencies","seen","Set","map","raw","index","package_type","repo_url","local_path","hash","content_hash","revision","deployedFiles","virtual_path","commit","resolved_commit","native","native_plugin","nativePluginRoot","deployed","deployed_files","every","file","fileIndex","identity","has","add","loadLock"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,mBAAmB;AAC5C,SAASC,QAAQ,EAAEC,KAAK,EAAEC,KAAK,QAAQ,YAAY;AACnD,SAASC,KAAK,QAAQ,OAAO;AAW7B,SAASC,OAAOC,KAAc,EAAEC,KAAa;IAC3C,IAAI,CAACD,SAAS,OAAOA,UAAU,YAAYE,MAAMC,OAAO,CAACH,QAAQ,MAAM,IAAII,MAAM,GAAGH,MAAM,kBAAkB,CAAC;IAC7G,OA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AC,wBAAwBjD,IAAI,CAAC4C,OAAO,MAAM,IAAInD,MAAM,GAAGH,MAAM,8BAA8B,CAAC;YACpJ,MAAM6D,SAAS9C,OAAO+C,aAAa,KAAKxC,aAAaP,OAAO+C,aAAa,KAAK,OAAOxC,YAAYxB,OAAOiB,OAAO+C,aAAa,EAAE,GAAG9D,MAAM,cAAc,CAAC;YACtJ,MAAM+D,mBAAmBF,SAASxD,SAASwD,OAAOjB,IAAI,EAAE,GAAG5C,MAAM,mBAAmB,CAAC,IAAIsB;YACzF,MAAM0C,YAAWjD,yBAAAA,OAAOkD,cAAc,cAArBlD,oCAAAA,yBAAyB,EAAE;YAC5C,IAAI,CAACd,MAAMC,OAAO,CAAC8D,aAAa,CAACA,SAASE,KAAK,CAAC,CAACC,OAAS,OAAOA,SAAS,WAAW,MAAM,IAAIhE,MAAM,GAAGH,MAAM,yCAAyC,CAAC;YACxJ,MAAMyD,gBAAgBO,SAAShB,GAAG,CAAC,CAACmB,MAAcC,YAAsB/D,SAAS8D,MAAM,GAAGnE,MAAM,gBAAgB,EAAEoE,UAAU,CAAC,CAAC;YAC9HhC,SAAS;gBAAEpB;gBAAMW;gBAAMpB;gBAAMiD,UAAU,GAAGG,OAAO,CAAC,EAAEL,MAAM;gBAAES;gBAAkBN;YAAc;QAC9F;QACA,MAAMY,WAAW7B,aAAaJ;QAC9B,IAAIU,KAAKwB,GAAG,CAACD,WAAW,MAAM,IAAIlE,MAAM,GAAGH,MAAM,8BAA8B,CAAC;QAChF8C,KAAKyB,GAAG,CAACF;QACT,OAAOjC;IACT;AACF;AACA,OAAO,eAAeoC,SAASjE,IAAY;IACzC,OAAOoC,UAAU9C,MAAM,MAAMJ,SAASc,MAAM;AAC9C"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/agent-plugin-lifecycle/src/apm.ts"],"sourcesContent":["import { readdir, readFile, realpath } from 'node:fs/promises';\nimport { basename, isAbsolute, join, resolve } from 'node:path';\nimport { parse } from 'yaml';\nimport { APM_LOCK, APM_MODULES, SKILLS } from './constants.ts';\nimport { message, missing } from './lib/errors.ts';\nimport { isRecord } from './lib/object.ts';\n\n/**\n * One `dependencies` row of APM's `apm.lock.yaml`. Paths are relative POSIX paths, checked to stay inside their root; a user-scope lock may\n * also record absolute deployed paths (a harness folder moved outside the home, as with `CLAUDE_CONFIG_DIR`).\n */\nexport interface LockedPackage {\n /** `<host>` or `<host>:<port>`; absent for a local path and for a row that records none. */\n host?: string;\n /** `owner/repo` for Git, `_local/<folder>` for a local path; with `path`, APM's cache copy under `apm_modules`. */\n repo: string;\n /** The plugin's folder inside the repository, `.` for the root. */\n path: string;\n /** The local source path exactly as APM wrote it. */\n localPath?: string;\n /** Whichever of `resolved_commit`, `resolved_hash` and `content_hash` the row has, joined by `:`. */\n revision: string;\n nativePluginRoot?: string;\n deployedFiles: string[];\n}\n/** A row `apl` cannot use, named by its `repo_url` (or its place in the lock); its recorded paths passed the path checks. */\nexport interface UnreadableRow {\n name: string;\n reason: string;\n nativePluginRoot?: string;\n deployedFiles: string[];\n}\nexport type LockRow = LockedPackage | UnreadableRow;\nexport const isUnreadable = (row: LockRow): row is UnreadableRow => 'reason' in row;\n/** Where one APM scope keeps its lock and deploys its copies. */\nexport interface Scope {\n global: boolean;\n lock: string;\n /** The folder deployed paths in the lock are relative to: the project, or the home. */\n root: string;\n /** The folder holding `apm.yml`; relative local paths are relative to it. */\n manifestRoot: string;\n /** APM's cache of each package (`apm_modules`), where scripts never run. */\n modules: string;\n}\n/** A folder the lock names for a package, and where it sits inside the package (`''` or `skills/<name>`). */\nexport interface PackageFolder {\n folder: string;\n within: string;\n /** The folder its real path must stay inside: the scope root for a relative path; none for an absolute path in a user-scope lock. */\n bound?: string;\n}\n/** The copies the lock records for a package, and each folder of APM's cache of it whose place in the package no recorded folder carries. */\nexport interface PackageFolders {\n folders: PackageFolder[];\n cache: PackageFolder[];\n}\n\nfunction record(value: unknown, label: string): Record<string, unknown> {\n if (!isRecord(value)) throw new Error(`${label} must be an object`);\n return value;\n}\nfunction requiredString(value: unknown, label: string): string {\n if (typeof value !== 'string' || !value) throw new Error(`${label} must be a nonempty string`);\n return value;\n}\nfunction safePath(value: unknown, label: string, dot = false): string {\n const path = requiredString(value, label);\n if (dot && path === '.') return path;\n if (path.startsWith('/') || path.includes('\\\\') || /^[A-Za-z]:/.test(path) || path.split('/').some((part) => !part || part === '.' || part === '..')) throw new Error(`${label} contains an unsafe path segment`);\n return path;\n}\nfunction optionalRecord(value: unknown, label: string): Record<string, unknown> | undefined {\n return value === undefined || value === null ? undefined : record(value, label);\n}\nfunction optionalString(value: unknown, label: string): string | undefined {\n return value === undefined || value === null ? undefined : requiredString(value, label);\n}\nfunction deployedFiles(value: unknown, label: string, absolute: boolean): string[] {\n const deployed = value ?? [];\n if (!Array.isArray(deployed) || !deployed.every((file) => typeof file === 'string')) throw new Error(`${label}.deployed_files must be an array of paths`);\n return deployed.map((file: string, index: number) => (absolute && isAbsolute(file) ? file : safePath(file, `${label}.deployed_files[${index}]`)));\n}\n/**\n * `repo_url` as a path, and the host when it is a URL (APM's spec: `host` is recorded \"when not inferable from `repo_url`\"). An unsafe\n * path throws, for the whole lock; a value that names no path (empty, or a URL that does not parse) is `undefined`, for its row alone.\n */\nfunction repository(value: string, label: string): { host?: string; repo: string } | undefined {\n if (!/^[a-z][a-z0-9+.-]*:\\/\\//i.test(value)) return value ? { repo: safePath(value, label) } : undefined;\n const url = URL.parse(value);\n const path = url?.pathname.slice(1);\n return url && path ? { host: url.host, repo: safePath(path, label) } : undefined;\n}\n\n/**\n * The rows of a parsed lock. A path that could leave its root makes the whole lock unreadable; any other problem makes only its row\n * unreadable. `absolute` accepts absolute deployed paths, which only a user-scope lock may hold.\n */\nexport function parseLock(value: unknown, absolute = false): LockRow[] {\n const root = record(value, 'APM lock');\n if (!Array.isArray(root.dependencies)) throw new Error('APM lock dependencies must be an array');\n const seen = new Set<string>();\n return root.dependencies.map((source, index): LockRow => {\n const label = `APM lock dependencies[${index}]`;\n if (!isRecord(source)) return { name: `dependencies[${index}]`, reason: `${label} must be an object`, deployedFiles: [] };\n const local = source.source === 'local';\n // the paths: where apl looks for copies, and APM's cache of the package\n const native = optionalRecord(source.native_plugin, `${label}.native_plugin`);\n const nativePluginRoot = native ? safePath(native.root, `${label}.native_plugin.root`) : undefined;\n const deployed = deployedFiles(source.deployed_files, label, absolute);\n const located = typeof source.repo_url === 'string' ? repository(source.repo_url, `${label}.repo_url`) : undefined;\n // APM writes no virtual_path for a plugin at the repository root\n const path = local || source.virtual_path === undefined || source.virtual_path === null ? '.' : safePath(source.virtual_path, `${label}.virtual_path`, true);\n try {\n if (!located) throw new Error(`${label}.repo_url must be a repository path or URL`);\n const revision = [optionalString(source.resolved_commit, `${label}.resolved_commit`), optionalString(source.resolved_hash, `${label}.resolved_hash`), optionalString(source.content_hash, `${label}.content_hash`)].filter(Boolean).join(':');\n if (!revision) throw new Error(`${label} has none of resolved_commit, resolved_hash and content_hash`);\n let item: LockedPackage;\n if (local) {\n if (!located.repo.startsWith('_local/')) throw new Error(`${label}.repo_url is not a local package key`);\n item = { repo: located.repo, path, localPath: requiredString(source.local_path, `${label}.local_path`), revision, nativePluginRoot, deployedFiles: deployed };\n } else {\n const host = optionalString(source.host, `${label}.host`) ?? located.host;\n if (source.port !== undefined && source.port !== null && !Number.isInteger(source.port)) throw new Error(`${label}.port must be an integer`);\n const port = host === undefined || source.port === undefined || source.port === null ? '' : `:${source.port}`;\n item = { ...(host === undefined ? {} : { host: `${host}${port}` }), repo: located.repo, path, revision, nativePluginRoot, deployedFiles: deployed };\n }\n const identity = JSON.stringify([item.host ?? null, item.repo, item.path, item.localPath ?? null]);\n if (seen.has(identity)) throw new Error(`${label} duplicates another lock entry`);\n seen.add(identity);\n return item;\n } catch (error) {\n return { name: typeof source.repo_url === 'string' && source.repo_url ? source.repo_url : `dependencies[${index}]`, reason: message(error), nativePluginRoot, deployedFiles: deployed };\n }\n });\n}\n\n/** The rows of an APM lock file, or undefined when the file does not exist. `absolute` as for `parseLock`. */\nexport async function readLock(path: string, absolute = false): Promise<LockRow[] | undefined> {\n let text: string;\n try {\n text = await readFile(path, 'utf8');\n } catch (error) {\n if (missing(error)) return undefined;\n throw error;\n }\n try {\n // no pretty errors: the message quotes none of the file\n return parseLock(parse(text, { prettyErrors: false }), absolute);\n } catch (error) {\n throw new Error(`cannot read ${path}: ${message(error)}`);\n }\n}\n\nasync function samePlace(left: string, right: string): Promise<boolean> {\n try {\n return (await realpath(left)) === (await realpath(right));\n } catch (error) {\n if (missing(error)) return false;\n throw error;\n }\n}\n/** The user scope with `global`, or when `cwd` is the APM home (where APM starts a user-scope lifecycle command); otherwise the project in `cwd`. */\nexport async function resolveScope(options: { global: boolean; cwd: string; home: string; apmHome: string }): Promise<Scope> {\n const { cwd, home, apmHome } = options;\n if (options.global || (await samePlace(cwd, apmHome))) return { global: true, lock: join(apmHome, APM_LOCK), root: home, manifestRoot: apmHome, modules: join(apmHome, APM_MODULES) };\n return { global: false, lock: join(cwd, APM_LOCK), root: cwd, manifestRoot: cwd, modules: join(cwd, APM_MODULES) };\n}\n\nconst native = (path: string) => join(...path.split('/'));\nasync function skillFolders(folder: string, bound?: string): Promise<PackageFolder[]> {\n try {\n const entries = await readdir(join(folder, SKILLS), { withFileTypes: true });\n return entries\n .filter((entry) => entry.isDirectory())\n .map((entry) => entry.name)\n .sort()\n .map((name) => ({ folder: join(folder, SKILLS, name), within: `${SKILLS}/${name}`, ...(bound === undefined ? {} : { bound }) }));\n } catch (error) {\n if (missing(error)) return [];\n throw error;\n }\n}\n/** A folder and its `skills/<name>/` folders. */\nasync function withSkills(folder: string, bound?: string): Promise<PackageFolder[]> {\n return [{ folder, within: '', ...(bound === undefined ? {} : { bound }) }, ...(await skillFolders(folder, bound))];\n}\n/** `entry` is a folder in APM's record: another recorded path lies under it. */\nfunction recordedFolder(entry: string, entries: string[]): boolean {\n return entries.some((other) => other.length > entry.length && other.startsWith(entry) && (other[entry.length] === '/' || other[entry.length] === '\\\\'));\n}\n/** The folders a row records: each folder in `deployed_files` (a skill folder, at `skills/<its name>`), and the native plugin folder with its skills. */\nexport async function recordedFolders(item: Pick<LockedPackage, 'deployedFiles' | 'nativePluginRoot'>, scope: Scope): Promise<PackageFolder[]> {\n const folders: PackageFolder[] = [];\n const seen = new Set<string>();\n for (const entry of item.deployedFiles) {\n if (!recordedFolder(entry, item.deployedFiles)) continue;\n const absolute = isAbsolute(entry);\n // an absolute path in the platform's own form: APM on Windows records `D:/...` with forward slashes\n const folder = absolute ? resolve(entry) : join(scope.root, native(entry));\n if (seen.has(folder)) continue;\n seen.add(folder);\n folders.push({ folder, within: `${SKILLS}/${basename(folder)}`, ...(absolute ? {} : { bound: scope.root }) });\n }\n if (item.nativePluginRoot) for (const found of await withSkills(join(scope.root, native(item.nativePluginRoot)), scope.root)) if (!seen.has(found.folder)) folders.push(found);\n return folders;\n}\n/** The folders a package's row records, and the root and skills of its APM cache copy whose place in the package no recorded folder carries. */\nexport async function packageFolders(item: LockedPackage, scope: Scope): Promise<PackageFolders> {\n const folders = await recordedFolders(item, scope);\n const carried = new Set(folders.map((found) => found.within));\n // the cache is never read or run, so it has no bound\n const cache = (await withSkills(join(scope.modules, native(item.repo), ...(item.path === '.' ? [] : [native(item.path)])))).filter((found) => !carried.has(found.within));\n return { folders, cache };\n}\n"],"names":["readdir","readFile","realpath","basename","isAbsolute","join","resolve","parse","APM_LOCK","APM_MODULES","SKILLS","message","missing","isRecord","isUnreadable","row","record","value","label","Error","requiredString","safePath","dot","path","startsWith","includes","test","split","some","part","optionalRecord","undefined","optionalString","deployedFiles","absolute","deployed","Array","isArray","every","file","map","index","repository","repo","url","URL","pathname","slice","host","parseLock","root","dependencies","seen","Set","source","name","reason","local","native","native_plugin","nativePluginRoot","deployed_files","located","repo_url","virtual_path","item","revision","resolved_commit","resolved_hash","content_hash","filter","Boolean","localPath","local_path","port","Number","isInteger","identity","JSON","stringify","has","add","error","readLock","text","prettyErrors","samePlace","left","right","resolveScope","options","cwd","home","apmHome","global","lock","manifestRoot","modules","skillFolders","folder","bound","entries","withFileTypes","entry","isDirectory","sort","within","withSkills","recordedFolder","other","length","recordedFolders","scope","folders","push","found","packageFolders","carried","cache"],"mappings":"AAAA,SAASA,OAAO,EAAEC,QAAQ,EAAEC,QAAQ,QAAQ,mBAAmB;AAC/D,SAASC,QAAQ,EAAEC,UAAU,EAAEC,IAAI,EAAEC,OAAO,QAAQ,YAAY;AAChE,SAASC,KAAK,QAAQ,OAAO;AAC7B,SAASC,QAAQ,EAAEC,WAAW,EAAEC,MAAM,QAAQ,iBAAiB;AAC/D,SAASC,OAAO,EAAEC,OAAO,QAAQ,kBAAkB;AACnD,SAASC,QAAQ,QAAQ,kBAAkB;AA4B3C,OAAO,MAAMC,eAAe,CAACC,MAAuC,YAAYA,IAAI;AAyBpF,SAASC,OAAOC,KAAc,EAAEC,KAAa;IAC3C,IAAI,CAACL,SAASI,QAAQ,MAAM,IAAIE,MAAM,GAAGD,MAAM,kBAAkB,CAAC;IAClE,OAAOD;AACT;AACA,SAASG,eAAeH,KAAc,EAAEC,KAAa;IACnD,IAAI,OAAOD,UAAU,YAAY,CAACA,OAAO,MAAM,IAAIE,MAAM,GAAGD,MAAM,0BAA0B,CAAC;IAC7F,OAAOD;AACT;AACA,SAASI,SAASJ,KAAc,EAAEC,KAAa,EAAEI,MAAM,KAAK;IAC1D,MAAMC,OAAOH,eAAeH,OAAOC;IACnC,IAAII,OAAOC,SAAS,KAAK,OAAOA;IAChC,IAAIA,KAAKC,UAAU,CAAC,QAAQD,KAAKE,QAAQ,CAAC,SAAS,aAAaC,IAAI,CAACH,SAASA,KAAKI,KAAK,CAAC,KAAKC,IAAI,CAAC,CAACC,OAAS,CAACA,QAAQA,SAAS,OAAOA,SAAS,OAAO,MAAM,IAAIV,MAAM,GAAGD,MAAM,gCAAgC,CAAC;IAChN,OAAOK;AACT;AACA,SAASO,eAAeb,KAAc,EAAEC,KAAa;IACnD,OAAO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EAAG+C,MAAM,CAAC,CAAC6C,QAAU,CAACE,QAAQrC,GAAG,CAACmC,MAAMT,MAAM;IACvK,OAAO;QAAEO;QAASK;IAAM;AAC1B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface Approval {
|
|
2
|
+
scripts: {
|
|
3
|
+
install: string;
|
|
4
|
+
};
|
|
5
|
+
/** ISO time the approval was given. */
|
|
6
|
+
approved: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* `~/.apl/approvals.json` without its `version`: for each place (the real path of the project folder, of the APM home, or of a
|
|
10
|
+
* named folder), one entry per id.
|
|
11
|
+
*/
|
|
12
|
+
export interface Approvals {
|
|
13
|
+
approvals: Record<string, Record<string, Approval>>;
|
|
14
|
+
}
|
|
15
|
+
export declare function parseApprovals(value: Record<string, unknown>): Approvals;
|
|
16
|
+
/** The command text approved for `id` in `place` equals `install`. An approval in any other place does not count. */
|
|
17
|
+
export declare function isApproved(approvals: Approvals, place: string, id: string, install: string): boolean;
|
|
18
|
+
export declare function readApprovals(home: string): Promise<Approvals>;
|
|
19
|
+
/** One approval given: `install` approved for `id` in `place`. */
|
|
20
|
+
export interface Approved {
|
|
21
|
+
place: string;
|
|
22
|
+
id: string;
|
|
23
|
+
install: string;
|
|
24
|
+
}
|
|
25
|
+
/** Saves the approvals in one write, each replacing any earlier entry for its place and id. */
|
|
26
|
+
export declare function saveApprovals(home: string, approved: Approved[], now?: Date): Promise<Approvals>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { APL_DIR, APPROVALS_FILE } from './constants.js';
|
|
3
|
+
import { isRecord } from './lib/object.js';
|
|
4
|
+
import { readStore, updateStore } from './lib/store.js';
|
|
5
|
+
export function parseApprovals(value) {
|
|
6
|
+
const { approvals } = value;
|
|
7
|
+
if (!isRecord(approvals)) throw new Error('approvals must be an object');
|
|
8
|
+
for (const [place, entries] of Object.entries(approvals)){
|
|
9
|
+
if (!isRecord(entries)) throw new Error(`approvals for ${place} must be an object`);
|
|
10
|
+
for (const [id, entry] of Object.entries(entries)){
|
|
11
|
+
const item = entry;
|
|
12
|
+
if (!isRecord(item) || !isRecord(item.scripts) || typeof item.scripts.install !== 'string' || typeof item.approved !== 'string') throw new Error(`approval for ${id} in ${place} must have scripts.install and approved strings`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
approvals: approvals
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const empty = ()=>({
|
|
20
|
+
approvals: {}
|
|
21
|
+
});
|
|
22
|
+
/** The command text approved for `id` in `place` equals `install`. An approval in any other place does not count. */ export function isApproved(approvals, place, id, install) {
|
|
23
|
+
if (!Object.hasOwn(approvals.approvals, place)) return false;
|
|
24
|
+
const entries = approvals.approvals[place];
|
|
25
|
+
return Object.hasOwn(entries, id) && entries[id].scripts.install === install;
|
|
26
|
+
}
|
|
27
|
+
export function readApprovals(home) {
|
|
28
|
+
return readStore(join(home, APL_DIR, APPROVALS_FILE), parseApprovals, empty);
|
|
29
|
+
}
|
|
30
|
+
/** Saves the approvals in one write, each replacing any earlier entry for its place and id. */ export async function saveApprovals(home, approved, now = new Date()) {
|
|
31
|
+
return updateStore(join(home, APL_DIR), APPROVALS_FILE, parseApprovals, empty, (value)=>{
|
|
32
|
+
for (const { place, id, install } of approved){
|
|
33
|
+
const entries = Object.hasOwn(value.approvals, place) ? value.approvals[place] : {};
|
|
34
|
+
entries[id] = {
|
|
35
|
+
scripts: {
|
|
36
|
+
install
|
|
37
|
+
},
|
|
38
|
+
approved: now.toISOString()
|
|
39
|
+
};
|
|
40
|
+
value.approvals[place] = entries;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/agent-plugin-lifecycle/src/approvals.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { APL_DIR, APPROVALS_FILE } from './constants.ts';\nimport { isRecord } from './lib/object.ts';\nimport { readStore, updateStore } from './lib/store.ts';\n\nexport interface Approval {\n scripts: { install: string };\n /** ISO time the approval was given. */\n approved: string;\n}\n/**\n * `~/.apl/approvals.json` without its `version`: for each place (the real path of the project folder, of the APM home, or of a\n * named folder), one entry per id.\n */\nexport interface Approvals {\n approvals: Record<string, Record<string, Approval>>;\n}\n\nexport function parseApprovals(value: Record<string, unknown>): Approvals {\n const { approvals } = value;\n if (!isRecord(approvals)) throw new Error('approvals must be an object');\n for (const [place, entries] of Object.entries(approvals)) {\n if (!isRecord(entries)) throw new Error(`approvals for ${place} must be an object`);\n for (const [id, entry] of Object.entries(entries)) {\n const item = entry as Partial<Approval> | null;\n if (!isRecord(item) || !isRecord(item.scripts) || typeof item.scripts.install !== 'string' || typeof item.approved !== 'string') throw new Error(`approval for ${id} in ${place} must have scripts.install and approved strings`);\n }\n }\n return { approvals: approvals as Approvals['approvals'] };\n}\nconst empty = (): Approvals => ({ approvals: {} });\n\n/** The command text approved for `id` in `place` equals `install`. An approval in any other place does not count. */\nexport function isApproved(approvals: Approvals, place: string, id: string, install: string): boolean {\n if (!Object.hasOwn(approvals.approvals, place)) return false;\n const entries = approvals.approvals[place];\n return Object.hasOwn(entries, id) && entries[id].scripts.install === install;\n}\n\nexport function readApprovals(home: string): Promise<Approvals> {\n return readStore(join(home, APL_DIR, APPROVALS_FILE), parseApprovals, empty);\n}\n\n/** One approval given: `install` approved for `id` in `place`. */\nexport interface Approved {\n place: string;\n id: string;\n install: string;\n}\n/** Saves the approvals in one write, each replacing any earlier entry for its place and id. */\nexport async function saveApprovals(home: string, approved: Approved[], now: Date = new Date()): Promise<Approvals> {\n return updateStore(join(home, APL_DIR), APPROVALS_FILE, parseApprovals, empty, (value) => {\n for (const { place, id, install } of approved) {\n const entries = Object.hasOwn(value.approvals, place) ? value.approvals[place] : {};\n entries[id] = { scripts: { install }, approved: now.toISOString() };\n value.approvals[place] = entries;\n }\n });\n}\n"],"names":["join","APL_DIR","APPROVALS_FILE","isRecord","readStore","updateStore","parseApprovals","value","approvals","Error","place","entries","Object","id","entry","item","scripts","install","approved","empty","isApproved","hasOwn","readApprovals","home","saveApprovals","now","Date","toISOString"],"mappings":"AAAA,SAASA,IAAI,QAAQ,YAAY;AACjC,SAASC,OAAO,EAAEC,cAAc,QAAQ,iBAAiB;AACzD,SAASC,QAAQ,QAAQ,kBAAkB;AAC3C,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AAexD,OAAO,SAASC,eAAeC,KAA8B;IAC3D,MAAM,EAAEC,SAAS,EAAE,GAAGD;IACtB,IAAI,CAACJ,SAASK,YAAY,MAAM,IAAIC,MAAM;IAC1C,KAAK,MAAM,CAACC,OAAOC,QAAQ,IAAIC,OAAOD,OAAO,CAACH,WAAY;QACxD,IAAI,CAACL,SAASQ,UAAU,MAAM,IAAIF,MAAM,CAAC,cAAc,EAAEC,MAAM,kBAAkB,CAAC;QAClF,KAAK,MAAM,CAACG,IAAIC,MAAM,IAAIF,OAAOD,OAAO,CAACA,SAAU;YACjD,MAAMI,OAAOD;YACb,IAAI,CAACX,SAASY,SAAS,CAACZ,SAASY,KAAKC,OAAO,KAAK,OAAOD,KAAKC,OAAO,CAACC,OAAO,KAAK,YAAY,OAAOF,KAAKG,QAAQ,KAAK,UAAU,MAAM,IAAIT,MAAM,CAAC,aAAa,EAAEI,GAAG,IAAI,EAAEH,MAAM,+CAA+C,CAAC;QAClO;IACF;IACA,OAAO;QAAEF,WAAWA;IAAoC;AAC1D;AACA,MAAMW,QAAQ,IAAkB,CAAA;QAAEX,WAAW,CAAC;IAAE,CAAA;AAEhD,mHAAmH,GACnH,OAAO,SAASY,WAAWZ,SAAoB,EAAEE,KAAa,EAAEG,EAAU,EAAEI,OAAe;IACzF,IAAI,CAACL,OAAOS,MAAM,CAACb,UAAUA,SAAS,EAAEE,QAAQ,OAAO;IACvD,MAAMC,UAAUH,UAAUA,SAAS,CAACE,MAAM;IAC1C,OAAOE,OAAOS,MAAM,CAACV,SAASE,OAAOF,OAAO,CAACE,GAAG,CAACG,OAAO,CAACC,OAAO,KAAKA;AACvE;AAEA,OAAO,SAASK,cAAcC,IAAY;IACxC,OAAOnB,UAAUJ,KAAKuB,MAAMtB,SAASC,iBAAiBI,gBAAgBa;AACxE;AAQA,6FAA6F,GAC7F,OAAO,eAAeK,cAAcD,IAAY,EAAEL,QAAoB,EAAEO,MAAY,IAAIC,MAAM;IAC5F,OAAOrB,YAAYL,KAAKuB,MAAMtB,UAAUC,gBAAgBI,gBAAgBa,OAAO,CAACZ;QAC9E,KAAK,MAAM,EAAEG,KAAK,EAAEG,EAAE,EAAEI,OAAO,EAAE,IAAIC,SAAU;YAC7C,MAAMP,UAAUC,OAAOS,MAAM,CAACd,MAAMC,SAAS,EAAEE,SAASH,MAAMC,SAAS,CAACE,MAAM,GAAG,CAAC;YAClFC,OAAO,CAACE,GAAG,GAAG;gBAAEG,SAAS;oBAAEC;gBAAQ;gBAAGC,UAAUO,IAAIE,WAAW;YAAG;YAClEpB,MAAMC,SAAS,CAACE,MAAM,GAAGC;QAC3B;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/agent-plugin-lifecycle/src/cli/index.ts"],"sourcesContent":["import type { Command } from './types.ts';\n\n// Lazy registry: a command's imports load only when it runs.\nexport const COMMANDS: Record<string, () => Promise<{ default: Command }>> = {\n install: () => import('./install.ts'),\n status: () => import('./status.ts'),\n};\n\nexport type { Command, Ctx } from './types.ts';\n"],"names":["COMMANDS","install","status"],"mappings":"AAEA,6DAA6D;AAC7D,OAAO,MAAMA,WAAgE;IAC3EC,SAAS,IAAM,MAAM,CAAC;IACtBC,QAAQ,IAAM,MAAM,CAAC;AACvB,EAAE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ApprovalRequest } from '../types.js';
|
|
2
|
+
import type { Ctx } from './types.js';
|
|
3
|
+
/** What the question prints before the prompt. */
|
|
4
|
+
export declare function requestText(request: ApprovalRequest): string;
|
|
5
|
+
export declare const PROMPT = "Run it? [y/N] ";
|
|
6
|
+
export interface QuestionStreams {
|
|
7
|
+
input: NodeJS.ReadableStream;
|
|
8
|
+
output: NodeJS.WritableStream;
|
|
9
|
+
/** Called on Ctrl+C at the question; the CLI exits 130 there, before any approval is saved or any script runs. */
|
|
10
|
+
interrupt: () => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The approval question as an `approve` function, with a readline interface per question so the terminal is normal again while scripts
|
|
14
|
+
* run. `y` or `yes` approves; anything else, or end of input (Ctrl+D), answers no.
|
|
15
|
+
*/
|
|
16
|
+
export declare function questioner({ input, output, interrupt }: QuestionStreams): (request: ApprovalRequest) => Promise<boolean>;
|
|
17
|
+
export default function installCommand(ctx: Ctx): Promise<number>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline/promises';
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
import { EXIT_INTERRUPTED } from '../constants.js';
|
|
4
|
+
import { install } from '../install.js';
|
|
5
|
+
import { message } from '../lib/errors.js';
|
|
6
|
+
import { visible } from '../lib/visible.js';
|
|
7
|
+
import { print, summarize } from './report.js';
|
|
8
|
+
import { INSTALL_USAGE as USAGE } from './usage.js';
|
|
9
|
+
const parse = (args)=>parseArgs({
|
|
10
|
+
args,
|
|
11
|
+
allowPositionals: true,
|
|
12
|
+
options: {
|
|
13
|
+
global: {
|
|
14
|
+
type: 'boolean',
|
|
15
|
+
short: 'g'
|
|
16
|
+
},
|
|
17
|
+
yes: {
|
|
18
|
+
type: 'boolean',
|
|
19
|
+
short: 'y'
|
|
20
|
+
},
|
|
21
|
+
help: {
|
|
22
|
+
type: 'boolean',
|
|
23
|
+
short: 'h'
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
/** What the question prints before the prompt. */ export function requestText(request) {
|
|
28
|
+
return `${visible(request.id)} wants to run\n install: ${visible(request.scripts.install)}\nin\n${request.folders.map((folder)=>` ${visible(folder)}\n`).join('')}`;
|
|
29
|
+
}
|
|
30
|
+
export const PROMPT = 'Run it? [y/N] ';
|
|
31
|
+
/**
|
|
32
|
+
* The approval question as an `approve` function, with a readline interface per question so the terminal is normal again while scripts
|
|
33
|
+
* run. `y` or `yes` approves; anything else, or end of input (Ctrl+D), answers no.
|
|
34
|
+
*/ export function questioner({ input, output, interrupt }) {
|
|
35
|
+
return async (request)=>{
|
|
36
|
+
output.write(requestText(request));
|
|
37
|
+
const terminal = createInterface({
|
|
38
|
+
input,
|
|
39
|
+
output
|
|
40
|
+
});
|
|
41
|
+
terminal.on('SIGINT', ()=>{
|
|
42
|
+
output.write('\n');
|
|
43
|
+
interrupt();
|
|
44
|
+
});
|
|
45
|
+
try {
|
|
46
|
+
// a pending question does not always settle when input ends, so the interface closing answers it first
|
|
47
|
+
const answer = await new Promise((resolve, reject)=>{
|
|
48
|
+
terminal.on('close', ()=>resolve(undefined));
|
|
49
|
+
terminal.question(PROMPT).then(resolve, reject);
|
|
50
|
+
});
|
|
51
|
+
if (answer === undefined) output.write('\n');
|
|
52
|
+
return answer !== undefined && [
|
|
53
|
+
'y',
|
|
54
|
+
'yes'
|
|
55
|
+
].includes(answer.trim().toLowerCase());
|
|
56
|
+
} finally{
|
|
57
|
+
terminal.close();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export default async function installCommand(ctx) {
|
|
62
|
+
let parsed;
|
|
63
|
+
try {
|
|
64
|
+
parsed = parse(ctx.rest);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
return ctx.usageError(`${visible(message(error))}\nusage: ${ctx.name} ${USAGE}`);
|
|
67
|
+
}
|
|
68
|
+
const { values, positionals } = parsed;
|
|
69
|
+
if (values.help) {
|
|
70
|
+
console.log(`usage: ${ctx.name} ${USAGE}\n\nRuns the install script in each copy, asking before any that is not approved.\n -g, --global the user scope (~/.apm) instead of the project here\n -y, --yes approve every unapproved script without asking`);
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
if (values.global && positionals.length) return ctx.usageError(`-g cannot be combined with folders\nusage: ${ctx.name} ${USAGE}`);
|
|
74
|
+
// the question needs a terminal on both standard input and output; without one, unapproved copies are only reported
|
|
75
|
+
const ask = questioner({
|
|
76
|
+
input: process.stdin,
|
|
77
|
+
output: process.stdout,
|
|
78
|
+
interrupt: ()=>process.exit(EXIT_INTERRUPTED)
|
|
79
|
+
});
|
|
80
|
+
const approve = values.yes ? async ()=>true : process.stdin.isTTY && process.stdout.isTTY ? ask : undefined;
|
|
81
|
+
// each line is printed as its result is known, so a run killed part-way shows what finished
|
|
82
|
+
return summarize(await install({
|
|
83
|
+
global: values.global,
|
|
84
|
+
folders: positionals,
|
|
85
|
+
apmHome: process.env.APM_HOME || undefined,
|
|
86
|
+
approve,
|
|
87
|
+
onResult: print
|
|
88
|
+
}));
|
|
89
|
+
}
|