@evomap/evolver-cli 2.0.50 → 2.0.52
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/dist/assetEvolution.d.ts +9 -0
- package/dist/assetEvolution.js +164 -0
- package/dist/commandCatalog.d.ts +4 -0
- package/dist/commandCatalog.js +4 -0
- package/dist/containedWrite.d.ts +8 -0
- package/dist/containedWrite.js +79 -0
- package/dist/dispatch.js +8 -0
- package/dist/experience.js +34 -2
- package/dist/gene.d.ts +3 -0
- package/dist/gene.js +174 -0
- package/dist/jsonCommand.d.ts +34 -0
- package/dist/jsonCommand.js +118 -0
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +15 -5
- package/dist/pluginBundle.d.ts +2 -0
- package/dist/pluginBundle.js +37 -9
- package/dist/pluginDrafts.d.ts +19 -0
- package/dist/pluginDrafts.js +87 -0
- package/dist/pluginHosts.d.ts +13 -2
- package/dist/pluginHosts.js +88 -29
- package/dist/pluginInspection.d.ts +2 -2
- package/dist/pluginInspection.js +25 -19
- package/dist/pluginInstall.js +16 -12
- package/dist/pluginLauncher.d.ts +7 -0
- package/dist/pluginLauncher.js +40 -0
- package/dist/pluginLocalInspection.d.ts +7 -0
- package/dist/pluginLocalInspection.js +46 -0
- package/dist/pluginRuntime.d.ts +2 -1
- package/dist/pluginRuntime.js +10 -4
- package/dist/publishPolicy.d.ts +6 -0
- package/dist/publishPolicy.js +19 -0
- package/dist/redact.d.ts +3 -0
- package/dist/redact.js +27 -0
- package/dist/sessionIngest.d.ts +1 -0
- package/dist/sessionIngest.js +6 -3
- package/dist/skillFetch.d.ts +1 -0
- package/dist/skillFetch.js +18 -26
- package/dist/workflow.d.ts +2 -1
- package/dist/workflow.js +35 -12
- package/package.json +7 -7
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { authoring } from '@evomap/evolver-core';
|
|
2
|
+
export class JsonCommandError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.name = 'JsonCommandError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export const SMALL_REQUEST_BYTES = 64 * 1024;
|
|
11
|
+
export const LARGE_REQUEST_BYTES = 512 * 1024;
|
|
12
|
+
const MAX_ERROR_CHARS = 300;
|
|
13
|
+
function envLocale(io) {
|
|
14
|
+
return authoring.authoringLocale(undefined, io.env ?? process.env);
|
|
15
|
+
}
|
|
16
|
+
export function requestLocale(request, io) {
|
|
17
|
+
return authoring.authoringLocale(request['locale'], io.env ?? process.env);
|
|
18
|
+
}
|
|
19
|
+
export function inputError(locale, zh, en) {
|
|
20
|
+
return new JsonCommandError('INPUT_INVALID', authoring.say(locale, zh, en));
|
|
21
|
+
}
|
|
22
|
+
/** One JSON object on stdin (an interactive terminal counts as `{}`), bounded before it is parsed. */
|
|
23
|
+
export async function readJsonRequest(limit, io) {
|
|
24
|
+
const stdin = io.stdin ?? process.stdin;
|
|
25
|
+
const locale = envLocale(io);
|
|
26
|
+
if (stdin.isTTY)
|
|
27
|
+
return {};
|
|
28
|
+
const chunks = [];
|
|
29
|
+
let bytes = 0;
|
|
30
|
+
for await (const chunk of stdin) {
|
|
31
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
32
|
+
bytes += buffer.length;
|
|
33
|
+
if (bytes > limit)
|
|
34
|
+
throw inputError(locale, `请求超过 ${limit / 1024} KiB 上限。`, `The request exceeds the ${limit / 1024} KiB limit.`);
|
|
35
|
+
chunks.push(buffer);
|
|
36
|
+
}
|
|
37
|
+
let parsed;
|
|
38
|
+
try {
|
|
39
|
+
parsed = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(Buffer.concat(chunks)) || '{}');
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
throw inputError(locale, '请求不是有效的 JSON。', 'The request is not valid JSON.');
|
|
43
|
+
}
|
|
44
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
45
|
+
throw inputError(locale, '请求需要是一个 JSON 对象。', 'The request must be a JSON object.');
|
|
46
|
+
return parsed;
|
|
47
|
+
}
|
|
48
|
+
function clipped(message) {
|
|
49
|
+
return message.length > MAX_ERROR_CHARS ? `${message.slice(0, MAX_ERROR_CHARS - 1)}…` : message;
|
|
50
|
+
}
|
|
51
|
+
/** The versioned envelope every Desktop-facing command shares: one line of JSON, exit 0 when ok and 1 otherwise. */
|
|
52
|
+
export async function runJsonCommand(schema, operation, io, run) {
|
|
53
|
+
const stdout = io.stdout ?? ((text) => { process.stdout.write(text); });
|
|
54
|
+
const emit = (payload) => stdout(`${JSON.stringify({ schema, operation, ...payload })}\n`);
|
|
55
|
+
try {
|
|
56
|
+
emit({ ok: true, result: await run() });
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
const failure = error instanceof JsonCommandError ? error
|
|
61
|
+
: new JsonCommandError('INTERNAL', authoring.say(envLocale(io), '命令执行失败,请检查本地 Evolver 安装与目录权限。', 'The command failed; check the local Evolver installation and directory permissions.'));
|
|
62
|
+
emit({ ok: false, code: failure.code, error: clipped(failure.message) });
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export function optionalString(request, key, locale, maxChars = 100_000) {
|
|
67
|
+
const value = request[key];
|
|
68
|
+
if (value === undefined || value === null)
|
|
69
|
+
return undefined;
|
|
70
|
+
if (typeof value !== 'string' || value.length > maxChars || value.includes('\0'))
|
|
71
|
+
throw inputError(locale, `${key} 需要是不超过 ${maxChars} 字的文本。`, `${key} must be text of at most ${maxChars} characters.`);
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
export function requiredString(request, key, locale, maxChars = 100_000) {
|
|
75
|
+
const value = optionalString(request, key, locale, maxChars);
|
|
76
|
+
if (value === undefined)
|
|
77
|
+
throw inputError(locale, `缺少 ${key}。`, `Missing ${key}.`);
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
export function optionalStrings(request, key, locale, maxItems = 200, maxChars = 2000) {
|
|
81
|
+
const value = request[key];
|
|
82
|
+
if (value === undefined || value === null)
|
|
83
|
+
return undefined;
|
|
84
|
+
if (!Array.isArray(value) || value.length > maxItems || value.some((item) => typeof item !== 'string' || item.length > maxChars || item.includes('\0'))) {
|
|
85
|
+
throw inputError(locale, `${key} 需要是最多 ${maxItems} 条文本的列表。`, `${key} must be a list of at most ${maxItems} strings.`);
|
|
86
|
+
}
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
export function optionalEnum(request, key, values, locale) {
|
|
90
|
+
const value = request[key];
|
|
91
|
+
if (value === undefined || value === null)
|
|
92
|
+
return undefined;
|
|
93
|
+
if (!values.includes(value))
|
|
94
|
+
throw inputError(locale, `${key} 只能是 ${values.join('、')}。`, `${key} must be one of ${values.join(', ')}.`);
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
export function requiredEnum(request, key, values, locale) {
|
|
98
|
+
const value = optionalEnum(request, key, values, locale);
|
|
99
|
+
if (value === undefined)
|
|
100
|
+
throw inputError(locale, `缺少 ${key}(${values.join('、')})。`, `Missing ${key} (${values.join(', ')}).`);
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
export function requiredObject(request, key, locale) {
|
|
104
|
+
const value = request[key];
|
|
105
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
106
|
+
throw inputError(locale, `缺少 ${key} 对象。`, `Missing the ${key} object.`);
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
/** The operation word and that the remaining flags are only `--json`; anything else is an input error. */
|
|
110
|
+
export function operationOf(argv, operations, io) {
|
|
111
|
+
const operation = argv[0] ?? '';
|
|
112
|
+
const locale = envLocale(io);
|
|
113
|
+
if (!operations.includes(operation)) {
|
|
114
|
+
return { operation, error: inputError(locale, `不支持的操作,可用:${operations.join('、')}。`, `Unsupported operation; use one of ${operations.join(', ')}.`) };
|
|
115
|
+
}
|
|
116
|
+
const extra = argv.slice(1).find((arg) => arg !== '--json');
|
|
117
|
+
return extra ? { operation, error: inputError(locale, `不支持的参数:${extra.slice(0, 40)}`, `Unsupported argument: ${extra.slice(0, 40)}`) } : { operation };
|
|
118
|
+
}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type PluginRuntime } from './pluginRuntime.js';
|
|
2
|
-
export declare const PLUGIN_USAGE = "Usage: evolver plugin list [--json]\n evolver plugin install [--host <host>] [--scope user|project] [--root <dir>]\n [--profile <dsh-profile>] [--trust] [--dry-run] [--json]\n\nHosts: claude-code, codex, grok, qoder, antigravity, opencode, dsh,\n cursor, workbuddy, mcp-generic\nDefault scope: user. dsh default profile: dsh-tui.\n--trust says you trust the plugin's hooks; only hosts that require it (grok) accept it.\nWith no host, only a single discovered native host is selected; otherwise choose --host.\nCursor, WorkBuddy and generic MCP return manual_required without writing client config.\nDry-run performs no download, host command or config write and proves no installed state.\nInstallation uses EvoMap/evolver-agent-plugin and does not replace setup-hooks.\nExit codes: 0 verified install/already-installed/list/preview; 2 action required\n(including trust_required and profile_store_mismatch); 1 conflict or failure.\n";
|
|
2
|
+
export declare const PLUGIN_USAGE = "Usage: evolver plugin list [--json]\n evolver plugin install [--host <host>] [--scope user|project] [--root <dir>]\n [--profile <dsh-profile>] [--trust] [--dry-run] [--json]\n\nHosts: claude-code, codex, grok, qoder, antigravity, opencode, dsh, zcode,\n kimi, stepcode, minimax, cursor, workbuddy, mcp-generic\nDefault scope: user. dsh default profile: dsh-tui.\n--trust says you trust the plugin's hooks; only hosts that require it (grok) accept it.\nWith no host, only a single discovered native host is selected; otherwise choose --host.\nCursor, WorkBuddy and generic MCP return manual_required without writing client config.\nKimi Code and Step Code install on Windows only; ZCode on Windows and macOS.\nDry-run performs no download, host command or config write and proves no installed state.\nInstallation uses EvoMap/evolver-agent-plugin and does not replace setup-hooks.\nExit codes: 0 verified install/already-installed/list/preview; 2 action required\n(including trust_required and profile_store_mismatch); 1 conflict or failure.\n";
|
|
3
3
|
export interface PluginCommandDeps {
|
|
4
4
|
runtime?: PluginRuntime;
|
|
5
5
|
stdout?: (text: string) => void;
|
package/dist/plugin.js
CHANGED
|
@@ -2,17 +2,19 @@ import { realpathSync, statSync } from 'node:fs';
|
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { PLUGIN_HOSTS, pluginHostNamed } from './pluginHosts.js';
|
|
4
4
|
import { installAgentPlugin } from './pluginInstall.js';
|
|
5
|
+
import { expectedHostLauncher, hostLauncher } from './pluginLauncher.js';
|
|
5
6
|
import { createPluginRuntime, PluginInstallError } from './pluginRuntime.js';
|
|
6
7
|
export const PLUGIN_USAGE = `Usage: evolver plugin list [--json]
|
|
7
8
|
evolver plugin install [--host <host>] [--scope user|project] [--root <dir>]
|
|
8
9
|
[--profile <dsh-profile>] [--trust] [--dry-run] [--json]
|
|
9
10
|
|
|
10
|
-
Hosts: claude-code, codex, grok, qoder, antigravity, opencode, dsh,
|
|
11
|
-
cursor, workbuddy, mcp-generic
|
|
11
|
+
Hosts: claude-code, codex, grok, qoder, antigravity, opencode, dsh, zcode,
|
|
12
|
+
kimi, stepcode, minimax, cursor, workbuddy, mcp-generic
|
|
12
13
|
Default scope: user. dsh default profile: dsh-tui.
|
|
13
14
|
--trust says you trust the plugin's hooks; only hosts that require it (grok) accept it.
|
|
14
15
|
With no host, only a single discovered native host is selected; otherwise choose --host.
|
|
15
16
|
Cursor, WorkBuddy and generic MCP return manual_required without writing client config.
|
|
17
|
+
Kimi Code and Step Code install on Windows only; ZCode on Windows and macOS.
|
|
16
18
|
Dry-run performs no download, host command or config write and proves no installed state.
|
|
17
19
|
Installation uses EvoMap/evolver-agent-plugin and does not replace setup-hooks.
|
|
18
20
|
Exit codes: 0 verified install/already-installed/list/preview; 2 action required
|
|
@@ -68,7 +70,7 @@ function installOptions(flags, runtime) {
|
|
|
68
70
|
if (flags.host && !host)
|
|
69
71
|
throw new PluginInstallError('invalid_arguments', 'Unknown plugin host. Use evolver plugin list to see supported entries.');
|
|
70
72
|
if (!host) {
|
|
71
|
-
const found = PLUGIN_HOSTS.filter(candidate => candidate.kind !== 'manual' && candidate
|
|
73
|
+
const found = PLUGIN_HOSTS.filter(candidate => candidate.kind !== 'manual' && supportsPlatform(candidate, runtime) && hostLauncher(runtime, candidate));
|
|
72
74
|
if (found.length !== 1)
|
|
73
75
|
throw new PluginInstallError('selection_required', found.length === 0
|
|
74
76
|
? 'No native plugin host was found on PATH. Choose --host explicitly; plugin list includes manual entries.'
|
|
@@ -89,6 +91,8 @@ function installOptions(flags, runtime) {
|
|
|
89
91
|
const profile = flags.profile ?? 'dsh-tui';
|
|
90
92
|
if (!/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(profile))
|
|
91
93
|
throw new PluginInstallError('invalid_arguments', '--profile must be a simple dsh profile name, not a path or command.');
|
|
94
|
+
if (!supportsPlatform(host, runtime))
|
|
95
|
+
throw new PluginInstallError('unsupported_capability', `${host.label} plugin installation is supported on ${host.platforms.map(platformName).join(' and ')} only; this machine runs ${platformName(runtime.platform)}.`);
|
|
92
96
|
let root = resolve(runtime.cwd, flags.root ?? '.');
|
|
93
97
|
if (!flags.dryRun && host.kind !== 'manual') {
|
|
94
98
|
try {
|
|
@@ -100,7 +104,13 @@ function installOptions(flags, runtime) {
|
|
|
100
104
|
throw new PluginInstallError('invalid_arguments', '--root must identify an existing project/working directory.');
|
|
101
105
|
}
|
|
102
106
|
}
|
|
103
|
-
|
|
107
|
+
const launcher = hostLauncher(runtime, host) ?? expectedHostLauncher(runtime, host);
|
|
108
|
+
return { host, scope: scope, root, profile, dryRun: flags.dryRun, trust: flags.trust, launcher };
|
|
109
|
+
}
|
|
110
|
+
const PLATFORM_NAMES = { win32: 'Windows', darwin: 'macOS', linux: 'Linux' };
|
|
111
|
+
const platformName = (platform) => PLATFORM_NAMES[platform] ?? platform;
|
|
112
|
+
function supportsPlatform(host, runtime) {
|
|
113
|
+
return !host.platforms || host.platforms.includes(runtime.platform);
|
|
104
114
|
}
|
|
105
115
|
export async function runPluginCommand(argv, deps = {}) {
|
|
106
116
|
const stdout = deps.stdout ?? (text => { process.stdout.write(text); });
|
|
@@ -115,7 +125,7 @@ export async function runPluginCommand(argv, deps = {}) {
|
|
|
115
125
|
return 0;
|
|
116
126
|
}
|
|
117
127
|
if (flags.action === 'list') {
|
|
118
|
-
const hosts = PLUGIN_HOSTS.map(host => ({ id: host.id, label: host.label, mode: host.kind === 'manual' ? 'manual' : 'native', cli: host.command ?? null, cliFound: Boolean(
|
|
128
|
+
const hosts = PLUGIN_HOSTS.map(host => ({ id: host.id, label: host.label, mode: host.kind === 'manual' ? 'manual' : 'native', cli: host.command ?? null, cliFound: Boolean(hostLauncher(runtime, host)), minimumVersion: host.minimumVersion ?? null, requiresTrust: Boolean(host.requiresTrust), scopes: host.scopes, platforms: host.platforms ?? null, instructions: host.instructions }));
|
|
119
129
|
stdout(json ? `${JSON.stringify({ ok: true, action: 'list', hosts })}\n` : `${hosts.map(host => `${host.id.padEnd(14)} ${host.mode.padEnd(7)} ${host.cliFound ? 'CLI found' : 'CLI not found / not required'}; scopes=${host.scopes.join('|')}`).join('\n')}\nCLI detection is not installation or version verification.\n`);
|
|
120
130
|
return 0;
|
|
121
131
|
}
|
package/dist/pluginBundle.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type PluginHost } from './pluginHosts.js';
|
|
2
2
|
import { type PluginRuntime } from './pluginRuntime.js';
|
|
3
3
|
export declare function validatePackedBundle(bundle: string, host: PluginHost): void;
|
|
4
|
+
/** A host-registered folder is trusted only as a valid packed bundle inside a release checkout this installer owns. */
|
|
5
|
+
export declare function isManagedPackedBundle(runtime: PluginRuntime, host: PluginHost, folder: string): boolean;
|
|
4
6
|
export declare function ensureAgentPluginBundle(runtime: PluginRuntime, host: PluginHost): Promise<string>;
|
package/dist/pluginBundle.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { withOwnedPluginLock } from './pluginLock.js';
|
|
2
2
|
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { AGENT_PLUGIN_GIT_URL, AGENT_PLUGIN_NAME, AGENT_PLUGIN_REPOSITORY, AGENT_PLUGIN_RELEASE } from './pluginHosts.js';
|
|
5
|
-
import { agentPluginRepositoryMatches } from './pluginInspection.js';
|
|
3
|
+
import { join, relative, sep } from 'node:path';
|
|
4
|
+
import { AGENT_PLUGIN_GIT_URL, AGENT_PLUGIN_NAME, AGENT_PLUGIN_REPOSITORY, AGENT_PLUGIN_RELEASE, agentPluginRepositoryMatches } from './pluginHosts.js';
|
|
6
5
|
import { assertPluginManagedPath, checkedPluginCommand, pluginHome, PluginInstallError, readPluginJson, readPluginText } from './pluginRuntime.js';
|
|
7
6
|
const RECEIPT = '.evolver-plugin-checkout.json';
|
|
8
7
|
export function validatePackedBundle(bundle, host) {
|
|
@@ -10,15 +9,14 @@ export function validatePackedBundle(bundle, host) {
|
|
|
10
9
|
if (root.isSymbolicLink() || !root.isDirectory())
|
|
11
10
|
throw new PluginInstallError('failed', 'The plugin bundle root is not an ordinary owned directory.');
|
|
12
11
|
const manifest = readPluginJson(join(bundle, host.manifest));
|
|
13
|
-
const expectedName = host.
|
|
12
|
+
const expectedName = host.packageName ?? AGENT_PLUGIN_NAME;
|
|
14
13
|
if (readPluginText(join(bundle, '.evolver-packed'))?.trim() !== host.id || manifest?.['name'] !== expectedName || typeof manifest['version'] !== 'string') {
|
|
15
14
|
throw new PluginInstallError('failed', `The release branch has no valid packed ${host.label} plugin. No host installation was attempted.`);
|
|
16
15
|
}
|
|
17
16
|
const repository = typeof manifest['repository'] === 'string' ? manifest['repository'] : manifest['repository']?.url;
|
|
18
17
|
if (!agentPluginRepositoryMatches(repository))
|
|
19
18
|
throw new PluginInstallError('failed', 'The packed plugin manifest identifies another repository.');
|
|
20
|
-
|
|
21
|
-
if (entries.some(entry => readPluginText(join(bundle, entry)) === undefined))
|
|
19
|
+
if (host.entries.some(entry => readPluginText(join(bundle, entry)) === undefined))
|
|
22
20
|
throw new PluginInstallError('failed', 'The packed plugin is missing an entry module.');
|
|
23
21
|
const queue = [bundle];
|
|
24
22
|
let count = 0;
|
|
@@ -34,8 +32,37 @@ export function validatePackedBundle(bundle, host) {
|
|
|
34
32
|
}
|
|
35
33
|
}
|
|
36
34
|
}
|
|
35
|
+
function agentPluginCacheBase(runtime) {
|
|
36
|
+
return join(realpathSync(pluginHome(runtime)), '.evolver', 'plugins', 'evolver-agent-plugin');
|
|
37
|
+
}
|
|
38
|
+
/** A host-registered folder is trusted only as a valid packed bundle inside a release checkout this installer owns. */
|
|
39
|
+
export function isManagedPackedBundle(runtime, host, folder) {
|
|
40
|
+
try {
|
|
41
|
+
const parts = relative(agentPluginCacheBase(runtime), realpathSync(folder)).split(sep);
|
|
42
|
+
if (parts.length !== 4 || !/^[a-f0-9]{40}$/.test(parts[0]) || parts[1] !== host.id || parts[2] !== 'dist' || parts[3] !== host.id)
|
|
43
|
+
return false;
|
|
44
|
+
validatePackedBundle(folder, host);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** `git status` must not run a command configured inside the cached checkout, so fsmonitor is forced off. */
|
|
52
|
+
async function assertPristineCheckout(runtime, checkout, commit) {
|
|
53
|
+
const git = ['-C', checkout, '-c', 'core.fsmonitor=false'];
|
|
54
|
+
const head = await checkedPluginCommand(runtime, 'git', [...git, 'rev-parse', 'HEAD']);
|
|
55
|
+
const changes = await checkedPluginCommand(runtime, 'git', [...git, 'status', '--porcelain', '--untracked-files=all', '--', '.', `:(exclude)${RECEIPT}`]);
|
|
56
|
+
if (head.stdout.trim() !== commit || changes.stdout.trim() !== '') {
|
|
57
|
+
throw new PluginInstallError('conflict', `The cached release checkout ${checkout} was modified after download; remove it and retry.`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** A script host's installer imports the checkout's scripts, shared lib and host adapters next to its packed folder. */
|
|
61
|
+
function checkoutPaths(host) {
|
|
62
|
+
return host.kind === 'script' ? [`dist/${host.id}`, 'scripts', 'lib', 'hosts'] : [`dist/${host.id}`];
|
|
63
|
+
}
|
|
37
64
|
export async function ensureAgentPluginBundle(runtime, host) {
|
|
38
|
-
if (host.kind !== 'bundle')
|
|
65
|
+
if (host.kind !== 'bundle' && host.kind !== 'script')
|
|
39
66
|
throw new PluginInstallError('unsupported_capability', 'This host uses its native source installer, not the packed-checkout download path.');
|
|
40
67
|
if (!runtime.available('git'))
|
|
41
68
|
throw new PluginInstallError('host_missing', 'Git is required to fetch the packed plugin release.');
|
|
@@ -44,7 +71,7 @@ export async function ensureAgentPluginBundle(runtime, host) {
|
|
|
44
71
|
if (matches.length !== 1)
|
|
45
72
|
throw new PluginInstallError('failed', 'The plugin release branch did not resolve to one commit.');
|
|
46
73
|
const commit = matches[0][1];
|
|
47
|
-
const base =
|
|
74
|
+
const base = agentPluginCacheBase(runtime);
|
|
48
75
|
assertPluginManagedPath(base);
|
|
49
76
|
mkdirSync(base, { recursive: true, mode: 0o700 });
|
|
50
77
|
const lockPath = join(base, `${host.id}.lock`);
|
|
@@ -60,6 +87,7 @@ export async function ensureAgentPluginBundle(runtime, host) {
|
|
|
60
87
|
throw new PluginInstallError('conflict', 'The plugin cache directory is not an owned, matching release checkout.');
|
|
61
88
|
}
|
|
62
89
|
validatePackedBundle(join(checkout, 'dist', host.id), host);
|
|
90
|
+
await assertPristineCheckout(runtime, checkout, commit);
|
|
63
91
|
return join(checkout, 'dist');
|
|
64
92
|
}
|
|
65
93
|
stage = mkdtempSync(join(base, `.${host.id}-`));
|
|
@@ -69,7 +97,7 @@ export async function ensureAgentPluginBundle(runtime, host) {
|
|
|
69
97
|
const noHooks = join(stage, 'no-hooks');
|
|
70
98
|
mkdirSync(noHooks, { mode: 0o700 });
|
|
71
99
|
await checkedPluginCommand(runtime, 'git', ['-c', `core.hooksPath=${noHooks}`, 'clone', '--depth', '1', '--branch', AGENT_PLUGIN_RELEASE, '--filter=blob:none', '--sparse', AGENT_PLUGIN_GIT_URL, source], runtime.cwd, 120_000);
|
|
72
|
-
await checkedPluginCommand(runtime, 'git', ['-C', source, '-c', `core.hooksPath=${noHooks}`, 'sparse-checkout', 'set',
|
|
100
|
+
await checkedPluginCommand(runtime, 'git', ['-C', source, '-c', `core.hooksPath=${noHooks}`, 'sparse-checkout', 'set', ...checkoutPaths(host)], runtime.cwd, 120_000);
|
|
73
101
|
const head = await checkedPluginCommand(runtime, 'git', ['-C', source, 'rev-parse', 'HEAD']);
|
|
74
102
|
if (head.stdout.trim() !== commit)
|
|
75
103
|
throw new PluginInstallError('failed', 'The plugin release changed while downloading. Retry to use a consistent release.');
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface PluginDraft {
|
|
2
|
+
id: string;
|
|
3
|
+
runtime: string;
|
|
4
|
+
title: string;
|
|
5
|
+
summary: string;
|
|
6
|
+
score: number | null;
|
|
7
|
+
createdAt: string;
|
|
8
|
+
gene: Record<string, unknown> | null;
|
|
9
|
+
capsule: Record<string, unknown> | null;
|
|
10
|
+
}
|
|
11
|
+
export interface PluginDrafts {
|
|
12
|
+
drafts: PluginDraft[];
|
|
13
|
+
/** Runtimes whose drafts file exists but could not be read: missing drafts there are unknown, not absent. */
|
|
14
|
+
unreadable: string[];
|
|
15
|
+
}
|
|
16
|
+
export declare const RUNTIME_NAME: RegExp;
|
|
17
|
+
/** The agent plugin's unconfirmed distillation drafts (`~/.evolver/state/<runtime>-distill-drafts.json`), read in place. */
|
|
18
|
+
export declare function pluginDrafts(env: Readonly<Record<string, string | undefined>>, runtime?: string): PluginDrafts;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
export const RUNTIME_NAME = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
5
|
+
const DRAFTS_FILE = /^([a-z0-9][a-z0-9-]{0,39})-distill-drafts\.json$/;
|
|
6
|
+
const MAX_FILE_BYTES = 16 * 1024 * 1024;
|
|
7
|
+
const isRecord = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
8
|
+
function stateDir(env) {
|
|
9
|
+
return join(env['HOME'] || env['USERPROFILE'] || homedir(), '.evolver', 'state');
|
|
10
|
+
}
|
|
11
|
+
const MAX_DATE_MS = 8.64e15;
|
|
12
|
+
/** One malformed timestamp blanks that draft's date; it must not make the whole file unreadable. */
|
|
13
|
+
function isoTime(value) {
|
|
14
|
+
const time = typeof value === 'number' ? value : typeof value === 'string' ? Date.parse(value) : Number.NaN;
|
|
15
|
+
return Number.isFinite(time) && Math.abs(time) <= MAX_DATE_MS ? new Date(time).toISOString() : '';
|
|
16
|
+
}
|
|
17
|
+
function assetOf(assets, type) {
|
|
18
|
+
return Array.isArray(assets) ? assets.find((asset) => isRecord(asset) && asset['type'] === type) ?? null : null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Reads through one descriptor, so the size checked is the size read. The path must be a regular file before opening and the
|
|
22
|
+
* opened file must be that same file, which also holds where `O_NOFOLLOW` does not exist (Windows).
|
|
23
|
+
*/
|
|
24
|
+
function readBounded(path) {
|
|
25
|
+
const before = lstatSync(path);
|
|
26
|
+
if (!before.isFile())
|
|
27
|
+
throw new Error('drafts_file_unreadable');
|
|
28
|
+
const fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
29
|
+
try {
|
|
30
|
+
const stat = fstatSync(fd);
|
|
31
|
+
if (!stat.isFile() || stat.dev !== before.dev || stat.ino !== before.ino || stat.size > MAX_FILE_BYTES)
|
|
32
|
+
throw new Error('drafts_file_unreadable');
|
|
33
|
+
const buffer = Buffer.alloc(MAX_FILE_BYTES + 1);
|
|
34
|
+
let length = 0;
|
|
35
|
+
for (let read = -1; read !== 0 && length <= MAX_FILE_BYTES;) {
|
|
36
|
+
read = readSync(fd, buffer, length, buffer.length - length, length);
|
|
37
|
+
length += read;
|
|
38
|
+
}
|
|
39
|
+
if (length > MAX_FILE_BYTES)
|
|
40
|
+
throw new Error('drafts_file_unreadable');
|
|
41
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(buffer.subarray(0, length));
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
closeSync(fd);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function draftsIn(path, runtime) {
|
|
48
|
+
const rows = JSON.parse(readBounded(path));
|
|
49
|
+
if (!Array.isArray(rows))
|
|
50
|
+
throw new Error('drafts_file_unreadable');
|
|
51
|
+
return rows.filter(isRecord).filter((row) => typeof row['id'] === 'string' || typeof row['id'] === 'number').map((row) => ({
|
|
52
|
+
id: String(row['id']),
|
|
53
|
+
runtime,
|
|
54
|
+
title: typeof row['title'] === 'string' ? row['title'] : '',
|
|
55
|
+
summary: typeof row['summary'] === 'string' ? row['summary'] : '',
|
|
56
|
+
score: typeof row['score'] === 'number' ? row['score'] : null,
|
|
57
|
+
createdAt: isoTime(row['createdAt']),
|
|
58
|
+
gene: assetOf(row['assets'], 'Gene'),
|
|
59
|
+
capsule: assetOf(row['assets'], 'Capsule'),
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
/** The agent plugin's unconfirmed distillation drafts (`~/.evolver/state/<runtime>-distill-drafts.json`), read in place. */
|
|
63
|
+
export function pluginDrafts(env, runtime) {
|
|
64
|
+
let names;
|
|
65
|
+
try {
|
|
66
|
+
names = readdirSync(stateDir(env));
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error.code === 'ENOENT')
|
|
70
|
+
return { drafts: [], unreadable: [] };
|
|
71
|
+
throw new Error('drafts_state_unreadable', { cause: error });
|
|
72
|
+
}
|
|
73
|
+
const drafts = [];
|
|
74
|
+
const unreadable = [];
|
|
75
|
+
for (const name of names) {
|
|
76
|
+
const owner = DRAFTS_FILE.exec(name)?.[1];
|
|
77
|
+
if (!owner || (runtime !== undefined && owner !== runtime))
|
|
78
|
+
continue;
|
|
79
|
+
try {
|
|
80
|
+
drafts.push(...draftsIn(join(stateDir(env), name), owner));
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
unreadable.push(owner);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return { drafts: drafts.sort((a, b) => b.createdAt.localeCompare(a.createdAt)), unreadable };
|
|
87
|
+
}
|
package/dist/pluginHosts.d.ts
CHANGED
|
@@ -3,18 +3,27 @@ export declare const AGENT_PLUGIN_GIT_URL = "https://github.com/EvoMap/evolver-a
|
|
|
3
3
|
export declare const AGENT_PLUGIN_NAME = "evolver-plugin";
|
|
4
4
|
export declare const AGENT_PLUGIN_RELEASE = "release";
|
|
5
5
|
export declare const DSH_PLUGIN_SOURCE = "github:EvoMap/evolver-agent-plugin#release&path:dist/dsh";
|
|
6
|
+
export declare function agentPluginRepositoryMatches(value: unknown): boolean;
|
|
6
7
|
export type PluginScope = 'user' | 'project';
|
|
7
|
-
type PluginHostId = 'claude-code' | 'codex' | 'grok' | 'qoder' | 'antigravity' | 'opencode' | 'dsh' | 'cursor' | 'workbuddy' | 'mcp-generic';
|
|
8
|
+
type PluginHostId = 'claude-code' | 'codex' | 'grok' | 'qoder' | 'antigravity' | 'opencode' | 'dsh' | 'zcode' | 'kimi' | 'stepcode' | 'minimax' | 'cursor' | 'workbuddy' | 'mcp-generic';
|
|
8
9
|
export interface PluginHost {
|
|
9
10
|
id: PluginHostId;
|
|
10
11
|
label: string;
|
|
11
12
|
command?: string;
|
|
12
13
|
minimumVersion?: string;
|
|
13
|
-
|
|
14
|
+
/** `script` runs the release checkout's own installer for the host. */
|
|
15
|
+
kind: 'marketplace' | 'bundle' | 'script' | 'profile' | 'manual';
|
|
14
16
|
scopes: readonly PluginScope[];
|
|
17
|
+
/** Hosts whose adapter is accepted only on these platforms. */
|
|
18
|
+
platforms?: readonly NodeJS.Platform[];
|
|
15
19
|
management?: 'plugin' | 'plugins';
|
|
16
20
|
marketplace?: string;
|
|
17
21
|
manifest?: string;
|
|
22
|
+
packageName?: string;
|
|
23
|
+
/** Files an installed (and packed) plugin must contain besides its manifest. */
|
|
24
|
+
entries: readonly string[];
|
|
25
|
+
/** The release checkout's installer, for `script` hosts. */
|
|
26
|
+
installer?: string;
|
|
18
27
|
/** Where the packed plugin sits inside the checkout path the host's inventory reports. */
|
|
19
28
|
packedSubdir?: string;
|
|
20
29
|
/** The host's installer refuses to install hooks/MCP/skills until the user passes its trust flag. */
|
|
@@ -31,6 +40,8 @@ export interface PluginInstallOptions {
|
|
|
31
40
|
profile: string;
|
|
32
41
|
dryRun: boolean;
|
|
33
42
|
trust: boolean;
|
|
43
|
+
/** The host CLI's argv prefix: its command, or node plus a CLI script for hosts that ship one. */
|
|
44
|
+
launcher: readonly string[];
|
|
34
45
|
}
|
|
35
46
|
export interface PluginCommandStep {
|
|
36
47
|
name: string;
|