@evomap/evolver-cli 2.0.46 → 2.0.47

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 (53) hide show
  1. package/dist/autoexec.d.ts +1 -2
  2. package/dist/autoexec.js +2 -7
  3. package/dist/cliEntry.js +8 -0
  4. package/dist/commandCatalog.d.ts +4 -0
  5. package/dist/commandCatalog.js +4 -0
  6. package/dist/dispatch.js +8 -0
  7. package/dist/experience.d.ts +2 -0
  8. package/dist/experience.js +229 -0
  9. package/dist/feedbackDestinationIdentity.d.ts +1 -0
  10. package/dist/feedbackDestinationIdentity.js +8 -0
  11. package/dist/kernelTriggerFeedback.d.ts +13 -0
  12. package/dist/kernelTriggerFeedback.js +65 -0
  13. package/dist/lifecycle.js +4 -1
  14. package/dist/lifecycleBootstrapTransaction.js +13 -7
  15. package/dist/localMemoryGraph.d.ts +38 -0
  16. package/dist/localMemoryGraph.js +192 -7
  17. package/dist/localTriggerFeedback.d.ts +30 -0
  18. package/dist/localTriggerFeedback.js +126 -0
  19. package/dist/mcpStdio.d.ts +1 -0
  20. package/dist/mcpStdio.js +9 -0
  21. package/dist/plugin.d.ts +8 -0
  22. package/dist/plugin.js +132 -0
  23. package/dist/pluginBundle.d.ts +3 -0
  24. package/dist/pluginBundle.js +94 -0
  25. package/dist/pluginHosts.d.ts +36 -0
  26. package/dist/pluginHosts.js +120 -0
  27. package/dist/pluginInspection.d.ts +22 -0
  28. package/dist/pluginInspection.js +237 -0
  29. package/dist/pluginInstall.d.ts +19 -0
  30. package/dist/pluginInstall.js +84 -0
  31. package/dist/pluginLock.d.ts +4 -0
  32. package/dist/pluginLock.js +52 -0
  33. package/dist/pluginRuntime.d.ts +31 -0
  34. package/dist/pluginRuntime.js +191 -0
  35. package/dist/recipe.d.ts +1 -1
  36. package/dist/recipe.js +14 -5
  37. package/dist/setupHooks.js +5 -3
  38. package/dist/setupHooksLifecycle.d.ts +2 -0
  39. package/dist/setupHooksLifecycle.js +52 -52
  40. package/dist/sourceQualification.js +6 -2
  41. package/dist/triggerFeedbackCli.d.ts +15 -0
  42. package/dist/triggerFeedbackCli.js +146 -0
  43. package/dist/triggerFeedbackDelivery.d.ts +9 -0
  44. package/dist/triggerFeedbackDelivery.js +29 -0
  45. package/dist/triggerFeedbackHub.d.ts +7 -0
  46. package/dist/triggerFeedbackHub.js +62 -0
  47. package/dist/triggerFeedbackRecovery.d.ts +15 -0
  48. package/dist/triggerFeedbackRecovery.js +124 -0
  49. package/dist/triggerFeedbackSync.d.ts +23 -0
  50. package/dist/triggerFeedbackSync.js +98 -0
  51. package/dist/triggerFeedbackSyncState.d.ts +42 -0
  52. package/dist/triggerFeedbackSyncState.js +112 -0
  53. package/package.json +7 -7
@@ -0,0 +1,36 @@
1
+ export declare const AGENT_PLUGIN_REPOSITORY = "EvoMap/evolver-agent-plugin";
2
+ export declare const AGENT_PLUGIN_GIT_URL = "https://github.com/EvoMap/evolver-agent-plugin.git";
3
+ export declare const AGENT_PLUGIN_NAME = "evolver-plugin";
4
+ export declare const AGENT_PLUGIN_RELEASE = "release";
5
+ export type PluginScope = 'user' | 'project';
6
+ type PluginHostId = 'claude-code' | 'codex' | 'grok' | 'qoder' | 'antigravity' | 'opencode' | 'dsh' | 'cursor' | 'workbuddy' | 'mcp-generic';
7
+ export interface PluginHost {
8
+ id: PluginHostId;
9
+ label: string;
10
+ command?: string;
11
+ minimumVersion?: string;
12
+ kind: 'marketplace' | 'bundle' | 'profile' | 'manual';
13
+ scopes: readonly PluginScope[];
14
+ management?: 'plugin' | 'plugins';
15
+ marketplace?: string;
16
+ manifest?: string;
17
+ legacyNames: readonly string[];
18
+ instructions: readonly string[];
19
+ }
20
+ export declare const PLUGIN_HOSTS: readonly PluginHost[];
21
+ export declare function pluginHostNamed(name: string): PluginHost | undefined;
22
+ export interface PluginInstallOptions {
23
+ host: PluginHost;
24
+ scope: PluginScope;
25
+ root: string;
26
+ profile: string;
27
+ dryRun: boolean;
28
+ }
29
+ export interface PluginCommandStep {
30
+ name: string;
31
+ command: string;
32
+ args: readonly string[];
33
+ }
34
+ export declare function pluginInstallSteps(options: PluginInstallOptions, bundle?: string): PluginCommandStep[];
35
+ export declare function pluginRollbackInstructions(options: PluginInstallOptions, bundle?: string): string[];
36
+ export {};
@@ -0,0 +1,120 @@
1
+ export const AGENT_PLUGIN_REPOSITORY = 'EvoMap/evolver-agent-plugin';
2
+ export const AGENT_PLUGIN_GIT_URL = `https://github.com/${AGENT_PLUGIN_REPOSITORY}.git`;
3
+ export const AGENT_PLUGIN_NAME = 'evolver-plugin';
4
+ export const AGENT_PLUGIN_RELEASE = 'release';
5
+ export const PLUGIN_HOSTS = [
6
+ {
7
+ id: 'claude-code', label: 'Claude Code', command: 'claude', minimumVersion: '2.1.286',
8
+ kind: 'marketplace', management: 'plugin', marketplace: 'evolver-agent-plugin',
9
+ scopes: ['user', 'project'], manifest: '.claude-plugin/plugin.json',
10
+ legacyNames: ['evolver', 'evolver-mods', 'evolver-agent-plugin'],
11
+ instructions: ['Restart Claude Code. Installed hooks modules also require the host rollout flag; an installed plugin is not proof that recall is active.'],
12
+ },
13
+ {
14
+ id: 'codex', label: 'Codex', command: 'codex', kind: 'marketplace', management: 'plugin', marketplace: 'evomap',
15
+ scopes: ['user'], manifest: '.codex-plugin/plugin.json', legacyNames: ['evolver'],
16
+ instructions: ['Open /hooks in Codex, review and trust the Evolver hooks, then start a new thread.'],
17
+ },
18
+ {
19
+ id: 'grok', label: 'Grok CLI', command: 'grok', minimumVersion: '1.0.70',
20
+ kind: 'marketplace', management: 'plugin', marketplace: 'evomap', scopes: ['user'], manifest: '.grok-plugin/plugin.json',
21
+ legacyNames: ['evolver', 'evolver-grok-plugin'],
22
+ instructions: ['Restart Grok and review its hook trust settings. Recall reaches the first tool result; a turn without tools receives no strategy.'],
23
+ },
24
+ {
25
+ id: 'qoder', label: 'Qoder CLI', command: 'qodercli', minimumVersion: '1.1.79',
26
+ kind: 'marketplace', management: 'plugins', marketplace: 'evomap', scopes: ['user'], manifest: '.qoder-plugin/plugin.json',
27
+ legacyNames: ['evolver', 'evolver-qoder-plugin'], instructions: ['Start a new Qoder session or run /plugins reload.'],
28
+ },
29
+ {
30
+ id: 'antigravity', label: 'Antigravity', command: 'agy', kind: 'bundle', management: 'plugin',
31
+ scopes: ['user'], manifest: 'plugin.json', legacyNames: ['evolver-antigravity-plugin'],
32
+ instructions: ['Restart Antigravity. Its commands run from the installed plugin with node bin/command.mjs antigravity <command>.'],
33
+ },
34
+ {
35
+ id: 'opencode', label: 'OpenCode', command: 'opencode', minimumVersion: '1.19.4', kind: 'bundle',
36
+ scopes: ['user', 'project'], manifest: 'package.json', legacyNames: ['evolver-opencode-plugin'],
37
+ instructions: ['Restart OpenCode. Both the server entry in opencode.json and the TUI entry in tui.json must be registered.'],
38
+ },
39
+ {
40
+ id: 'dsh', label: 'DeepSeek Harness', command: 'dsh', minimumVersion: '0.1.5', kind: 'profile',
41
+ scopes: ['user'], manifest: 'package.json', legacyNames: ['@evomap/dsh-evolver'],
42
+ instructions: ['Restart dsh. Installation applies only to the selected profile; repeat for other profiles. DSH Desktop requires its own bundled CLI/profile.'],
43
+ },
44
+ {
45
+ id: 'cursor', label: 'Cursor', command: 'cursor-agent', kind: 'manual', scopes: ['user'],
46
+ legacyNames: ['evolver-cursor-plugin'],
47
+ instructions: [
48
+ `In Cursor's plugin marketplace, add ${AGENT_PLUGIN_REPOSITORY} and install evolver-plugin.`,
49
+ 'Remove or disable the standalone Evolver plugin first to avoid duplicate recall and reports; keep its data.',
50
+ 'Reload the Cursor window and inspect Settings → Hooks. The current Cursor CLI has no verified plugin-install command.',
51
+ ],
52
+ },
53
+ {
54
+ id: 'workbuddy', label: 'WorkBuddy / CodeBuddy', command: 'codebuddy', kind: 'manual', scopes: ['user', 'project'],
55
+ legacyNames: ['evolver'],
56
+ instructions: [
57
+ 'In WorkBuddy, if the standalone plugin is installed: /plugin uninstall evolver@evomap-workbuddy --keep-data (repeat with --scope project where applicable).',
58
+ 'Remove the old marketplace only after reviewing its other plugins: /plugin marketplace remove evomap-workbuddy',
59
+ `/plugin marketplace add ${AGENT_PLUGIN_REPOSITORY}`,
60
+ '/plugin install evolver-plugin@evomap-workbuddy',
61
+ 'Restart WorkBuddy. These are commands in its plugin UI, not a verified codebuddy shell subcommand.',
62
+ ],
63
+ },
64
+ {
65
+ id: 'mcp-generic', label: 'Generic MCP client', kind: 'manual', scopes: ['user'], legacyNames: [],
66
+ instructions: [
67
+ `git clone --depth 1 --branch release ${AGENT_PLUGIN_GIT_URL}`,
68
+ 'In that checkout, run npm ci; the stdio server requires the MCP SDK.',
69
+ 'Register node <absolute-checkout>/bin/mcp.mjs mcp-generic using the selected client\'s own MCP configuration/CLI.',
70
+ 'The client must call recall/report/distill itself. Registration and agent-reported checks are not automatic hook integration.',
71
+ ],
72
+ },
73
+ ];
74
+ export function pluginHostNamed(name) {
75
+ const aliases = { claude: 'claude-code', codebuddy: 'workbuddy', 'deepseek-harness': 'dsh', mcp: 'mcp-generic' };
76
+ return PLUGIN_HOSTS.find(host => host.id === (aliases[name] ?? name));
77
+ }
78
+ export function pluginInstallSteps(options, bundle = '<release-checkout>/dist') {
79
+ const { host, scope, profile } = options;
80
+ const command = host.command ?? '';
81
+ if (host.kind === 'marketplace') {
82
+ const management = host.management;
83
+ const selector = host.id === 'grok' ? AGENT_PLUGIN_NAME : `${AGENT_PLUGIN_NAME}@${host.marketplace}`;
84
+ const add = [management, 'marketplace', 'add', AGENT_PLUGIN_REPOSITORY];
85
+ const install = host.id === 'codex'
86
+ ? [management, 'add', selector, '--json']
87
+ : [management, 'install', selector, ...(host.id === 'claude-code' ? ['--scope', scope, '--json'] : [])];
88
+ return [
89
+ { name: 'marketplace', command, args: add },
90
+ { name: 'install', command, args: install },
91
+ ];
92
+ }
93
+ if (host.id === 'antigravity')
94
+ return [{ name: 'install', command, args: ['plugin', 'install', `${bundle}/antigravity`] }];
95
+ if (host.id === 'opencode')
96
+ return [{ name: 'install', command, args: ['plugin', `${bundle}/opencode`, ...(scope === 'user' ? ['-g'] : [])] }];
97
+ if (host.id === 'dsh')
98
+ return [{
99
+ name: 'install', command, args: ['plugin', '--profile', profile, 'add', '-w', `github:${AGENT_PLUGIN_REPOSITORY}#${AGENT_PLUGIN_RELEASE}&path:dist/dsh`],
100
+ }];
101
+ return [];
102
+ }
103
+ export function pluginRollbackInstructions(options, bundle) {
104
+ const { host, scope, profile } = options;
105
+ if (host.id === 'claude-code')
106
+ return [`claude plugin uninstall ${AGENT_PLUGIN_NAME}@${host.marketplace} --scope ${scope} --keep-data`];
107
+ if (host.id === 'codex')
108
+ return [`codex plugin remove ${AGENT_PLUGIN_NAME}@${host.marketplace}`];
109
+ if (host.id === 'grok')
110
+ return ['grok plugin uninstall evolver-plugin'];
111
+ if (host.id === 'qoder')
112
+ return ['qodercli plugins uninstall evolver-plugin@evomap'];
113
+ if (host.id === 'antigravity')
114
+ return ['agy plugin uninstall evolver-plugin'];
115
+ if (host.id === 'dsh')
116
+ return [`dsh plugin --profile ${profile} remove @evomap/dsh-evolver`];
117
+ if (host.id === 'opencode')
118
+ return [`Remove only this plugin's ${bundle ?? '<installed-bundle>'}/opencode/server.mjs and tui.mjs entries from opencode.json and tui.json; preserve neighboring configuration.`];
119
+ return [];
120
+ }
@@ -0,0 +1,22 @@
1
+ import { type PluginInstallOptions, type PluginHost } from './pluginHosts.js';
2
+ import { type PluginRuntime } from './pluginRuntime.js';
3
+ export interface InstalledAgentPlugin {
4
+ id: string;
5
+ name: string;
6
+ version: string;
7
+ enabled: boolean;
8
+ scope?: string;
9
+ path?: string;
10
+ raw: Record<string, unknown>;
11
+ }
12
+ /** A host registration snapshot; only verifyPluginManifest confirms a usable installed artifact. */
13
+ export interface PluginInspection {
14
+ installed?: InstalledAgentPlugin;
15
+ marketplacePresent: boolean;
16
+ conflicts: string[];
17
+ }
18
+ export declare function installedPluginsFromJson(value: unknown, host: PluginHost): InstalledAgentPlugin[];
19
+ export declare function agentPluginRepositoryMatches(value: unknown): boolean;
20
+ export declare function verifyPluginManifest(runtime: PluginRuntime, options: PluginInstallOptions, plugin: InstalledAgentPlugin, installAnswer?: unknown): string;
21
+ export declare function inspectOpenCodePlugin(runtime: PluginRuntime, options: PluginInstallOptions): PluginInspection;
22
+ export declare function inspectAgentPlugin(runtime: PluginRuntime, options: PluginInstallOptions): Promise<PluginInspection>;
@@ -0,0 +1,237 @@
1
+ import { resolveOpenCodeConfig } from '@evomap/evolver-mcp';
2
+ import { existsSync } from 'node:fs';
3
+ import { dirname, join, resolve } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { AGENT_PLUGIN_GIT_URL, AGENT_PLUGIN_NAME, AGENT_PLUGIN_REPOSITORY } from './pluginHosts.js';
6
+ import { checkedPluginCommand, objectOf, pluginHome, pluginJson, pluginVersionAtLeast, PluginInstallError, readPluginJson, readPluginText } from './pluginRuntime.js';
7
+ function listRecords(value, key, label) {
8
+ const list = Array.isArray(value) ? value : objectOf(value)?.[key];
9
+ if (!Array.isArray(list) || list.some(record => !objectOf(record))) {
10
+ throw new PluginInstallError('unsupported_capability', `${label} has an unsupported list shape; no installed state can be inferred.`);
11
+ }
12
+ return list;
13
+ }
14
+ const stringOf = (value) => typeof value === 'string' && value.length > 0 ? value : undefined;
15
+ export function installedPluginsFromJson(value, host) {
16
+ const records = listRecords(value, host.id === 'codex' ? 'installed' : 'plugins', `${host.label} plugin list`);
17
+ return records.filter(record => record['installed'] !== false).map(raw => {
18
+ const id = stringOf(raw['id']) ?? stringOf(raw['pluginId']) ?? stringOf(raw['name']);
19
+ const name = stringOf(raw['name']) ?? id?.split('@')[0];
20
+ if (!id || !name)
21
+ throw new PluginInstallError('unsupported_capability', `${host.label} plugin list has an unnamed entry.`);
22
+ return {
23
+ id, name, version: stringOf(raw['version']) ?? '', enabled: raw['enabled'] !== false,
24
+ scope: stringOf(raw['scope']), path: stringOf(raw['installPath']) ?? stringOf(raw['installedPath']) ?? stringOf(raw['path']), raw,
25
+ };
26
+ });
27
+ }
28
+ export function agentPluginRepositoryMatches(value) {
29
+ if (typeof value !== 'string')
30
+ return false;
31
+ const source = value.trim().toLowerCase().replace(/^git\+/, '').replace(/^git@github\.com:/, 'https://github.com/').replace(/^ssh:\/\/git@github\.com\//, 'https://github.com/').replace(/\/$/, '').replace(/\.git$/, '');
32
+ return source === AGENT_PLUGIN_GIT_URL.toLowerCase().replace(/\.git$/, '') || source === AGENT_PLUGIN_REPOSITORY.toLowerCase();
33
+ }
34
+ function packageRepositoryOf(value) {
35
+ return typeof value === 'string' ? value : objectOf(value)?.['url'];
36
+ }
37
+ function repositoryOf(record) {
38
+ return record['repo'] ?? objectOf(record['marketplaceSource'])?.['source']
39
+ ?? objectOf(record['source'])?.['url'] ?? (typeof record['source'] === 'string' ? record['source'] : undefined);
40
+ }
41
+ async function marketplaceMatches(runtime, record) {
42
+ if (agentPluginRepositoryMatches(repositoryOf(record)))
43
+ return true;
44
+ const root = stringOf(record['root']) ?? stringOf(record['installLocation']);
45
+ if (!root)
46
+ return false;
47
+ try {
48
+ const { stdout } = await checkedPluginCommand(runtime, 'git', ['-C', root, 'remote', 'get-url', 'origin']);
49
+ return agentPluginRepositoryMatches(stdout.trim());
50
+ }
51
+ catch {
52
+ return false;
53
+ }
54
+ }
55
+ function hasEvolutionHook(value) {
56
+ if (Array.isArray(value))
57
+ return value.some(hasEvolutionHook);
58
+ const object = objectOf(value);
59
+ if (!object)
60
+ return false;
61
+ if (typeof object['command'] === 'string' && /(?:\bevolver\b|cli\.[cm]?js).*?\binject\s+(?:session-start|prompt-recall)\b/.test(object['command']))
62
+ return true;
63
+ return Object.values(object).some(hasEvolutionHook);
64
+ }
65
+ function oldHookConflicts(runtime, options) {
66
+ const { host, root } = options;
67
+ const home = pluginHome(runtime);
68
+ const roots = host.id === 'claude-code'
69
+ ? [runtime.env['CLAUDE_CONFIG_DIR'] ?? join(home, '.claude'), join(root, '.claude')]
70
+ : host.id === 'codex' ? [runtime.env['CODEX_HOME'] ?? join(home, '.codex'), join(root, '.codex')] : [];
71
+ const conflicts = [];
72
+ for (const directory of new Set(roots)) {
73
+ for (const file of ['settings.json', 'settings.local.json', 'hooks.json']) {
74
+ const config = readPluginJson(join(directory, file));
75
+ if (config && config['disableAllHooks'] !== true && hasEvolutionHook(config['hooks'] ?? config)) {
76
+ conflicts.push(`An existing ${host.label} Evolver evolution hook is registered. Review/remove only that old hook before enabling the plugin; product MCP entries and unrelated hooks must remain.`);
77
+ }
78
+ }
79
+ }
80
+ return conflicts;
81
+ }
82
+ function hasForeignInstalledScope(plugin, scope) {
83
+ return Boolean(plugin.scope && plugin.scope !== scope && !(scope === 'user' && plugin.scope === 'global'));
84
+ }
85
+ async function inspectMarketplacePlugin(runtime, options) {
86
+ const { host, scope } = options;
87
+ const management = host.management;
88
+ const pluginResult = await checkedPluginCommand(runtime, host.command, [management, 'list', '--json'], options.root);
89
+ const plugins = installedPluginsFromJson(pluginJson(pluginResult.stdout, `${host.label} plugin list`), host);
90
+ const marketResult = await checkedPluginCommand(runtime, host.command, [management, 'marketplace', 'list', '--json'], options.root);
91
+ const markets = listRecords(pluginJson(marketResult.stdout, `${host.label} marketplace list`), 'marketplaces', `${host.label} marketplace list`);
92
+ const market = markets.find(record => record['name'] === host.marketplace);
93
+ const conflicts = oldHookConflicts(runtime, options);
94
+ if (market && !await marketplaceMatches(runtime, market))
95
+ conflicts.push(`Marketplace ${host.marketplace} belongs to another source. Review its plugins before replacing it with ${AGENT_PLUGIN_REPOSITORY}.`);
96
+ for (const plugin of plugins) {
97
+ if (host.legacyNames.includes(plugin.name) && plugin.enabled)
98
+ conflicts.push(`The standalone ${plugin.name} plugin is enabled. Disable/remove it using ${host.label}, keeping its data, before installing ${AGENT_PLUGIN_NAME}.`);
99
+ if (plugin.name === AGENT_PLUGIN_NAME && plugin.id !== `${AGENT_PLUGIN_NAME}@${host.marketplace}` && !(host.id === 'grok' && plugin.id === AGENT_PLUGIN_NAME))
100
+ conflicts.push('An Evolver plugin from another marketplace is registered; review that installation before continuing.');
101
+ }
102
+ const installed = plugins.find(plugin => (plugin.id === `${AGENT_PLUGIN_NAME}@${host.marketplace}` || (host.id === 'grok' && plugin.id === AGENT_PLUGIN_NAME)) && (host.id !== 'claude-code' || plugin.scope === scope));
103
+ if (installed && host.id !== 'claude-code' && hasForeignInstalledScope(installed, scope))
104
+ conflicts.push('The host registered this plugin in another scope; it cannot confirm the requested installation scope.');
105
+ if (installed && !installed.enabled)
106
+ conflicts.push('The plugin is installed but disabled. Enable it explicitly in the host rather than installing another copy.');
107
+ if (installed && host.id === 'codex' && !agentPluginRepositoryMatches(repositoryOf(installed.raw)))
108
+ conflicts.push('The installed plugin source does not match the unified Evolver plugin repository.');
109
+ return { installed, marketplacePresent: Boolean(market), conflicts };
110
+ }
111
+ export function verifyPluginManifest(runtime, options, plugin, installAnswer) {
112
+ const { host } = options;
113
+ if (!pluginVersionAtLeast(plugin.version, plugin.version))
114
+ throw new PluginInstallError('failed', 'The installed plugin has no verifiable version.');
115
+ const answer = objectOf(installAnswer);
116
+ const path = plugin.path ?? stringOf(answer?.['installedPath']) ?? stringOf(answer?.['installPath'])
117
+ ?? (host.id === 'codex' ? join(runtime.env['CODEX_HOME'] ?? join(pluginHome(runtime), '.codex'), 'plugins', 'cache', host.marketplace, AGENT_PLUGIN_NAME, plugin.version) : undefined);
118
+ if (!path || !host.manifest)
119
+ throw new PluginInstallError('failed', 'The host did not identify a verifiable installed plugin directory.');
120
+ const manifest = readPluginJson(join(path, host.manifest));
121
+ const expectedName = host.id === 'opencode' ? '@evomap/evolver-opencode' : host.id === 'dsh' ? '@evomap/dsh-evolver' : AGENT_PLUGIN_NAME;
122
+ if (!manifest || manifest['name'] !== expectedName || manifest['version'] !== plugin.version) {
123
+ throw new PluginInstallError('failed', 'The host registration and installed plugin manifest do not agree; installation was not confirmed.');
124
+ }
125
+ const repository = packageRepositoryOf(manifest?.['repository']);
126
+ if (!agentPluginRepositoryMatches(repository))
127
+ throw new PluginInstallError('conflict', 'The installed plugin manifest does not identify the unified Evolver plugin source.');
128
+ if (readPluginText(join(path, '.evolver-packed'))?.trim() !== host.id)
129
+ throw new PluginInstallError('failed', 'The installed plugin is not the packed artifact for the selected host.');
130
+ const entries = host.id === 'opencode' ? ['server.mjs', 'tui.mjs'] : host.id === 'dsh' ? ['plugin.mjs'] : host.id === 'antigravity' ? ['hooks.json', 'bin/hook.mjs'] : host.id === 'claude-code' ? ['hooks/hooks.json', 'hooks/register.ts', 'bin/relay.mjs'] : ['hooks/hooks.json', 'bin/hook.mjs'];
131
+ if (entries.some(entry => !existsSync(join(path, entry))))
132
+ throw new PluginInstallError('failed', 'The installed plugin is missing its hook/plugin entry files.');
133
+ return path;
134
+ }
135
+ function pluginEntries(config) {
136
+ const entries = config?.['plugin'] ?? config?.['plugins'] ?? [];
137
+ if (!Array.isArray(entries))
138
+ throw new PluginInstallError('unsupported_capability', 'OpenCode plugin configuration is not a supported array.');
139
+ return entries.map(entry => {
140
+ const value = Array.isArray(entry) ? entry[0] : entry;
141
+ if (typeof value !== 'string')
142
+ throw new PluginInstallError('unsupported_capability', 'OpenCode has an unsupported plugin entry.');
143
+ return value;
144
+ });
145
+ }
146
+ function entryPath(entry, root) {
147
+ try {
148
+ return entry.startsWith('file:') ? fileURLToPath(entry) : resolve(root, entry);
149
+ }
150
+ catch {
151
+ return '';
152
+ }
153
+ }
154
+ export function inspectOpenCodePlugin(runtime, options) {
155
+ if (runtime.env['OPENCODE_CONFIG_CONTENT']?.trim() || (options.scope === 'project' && runtime.env['OPENCODE_DISABLE_PROJECT_CONFIG'] === '1')) {
156
+ throw new PluginInstallError('unsupported_capability', 'OpenCode has an inline/disabled project configuration layer that this plugin installer cannot verify. No host install was attempted.');
157
+ }
158
+ const resolution = resolveOpenCodeConfig({ configRoot: options.root, scope: options.scope, homeDir: pluginHome(runtime), xdgConfigHome: runtime.env['XDG_CONFIG_HOME'], opencodeConfig: runtime.env['OPENCODE_CONFIG'], opencodeConfigDir: runtime.env['OPENCODE_CONFIG_DIR'] });
159
+ const root = dirname(resolution.configPath);
160
+ const serverEntries = pluginEntries(readPluginJson(resolution.configPath));
161
+ const tuiFile = existsSync(join(root, 'tui.jsonc')) ? join(root, 'tui.jsonc') : join(root, 'tui.json');
162
+ const tuiEntries = pluginEntries(readPluginJson(tuiFile));
163
+ const conflicts = [];
164
+ const pairs = [];
165
+ for (const entry of [...serverEntries, ...tuiEntries]) {
166
+ if (options.host.legacyNames.some(name => entry.includes(name)))
167
+ conflicts.push('The standalone OpenCode Evolver package is registered; remove only its entries, keeping its data.');
168
+ }
169
+ if (existsSync(join(options.root, '.opencode', 'plugins', 'evolver.js')))
170
+ conflicts.push('A legacy .opencode/plugins/evolver.js is present; inspect/disable it before continuing.');
171
+ for (const entry of serverEntries) {
172
+ const server = entryPath(entry, root);
173
+ if (!server.endsWith('/server.mjs') && !server.endsWith('\\server.mjs'))
174
+ continue;
175
+ const manifest = readPluginJson(join(dirname(server), 'package.json'));
176
+ if (manifest?.['name'] !== '@evomap/evolver-opencode')
177
+ continue;
178
+ const tui = tuiEntries.map(value => entryPath(value, root)).find(value => value === join(dirname(server), 'tui.mjs'));
179
+ if (!tui)
180
+ conflicts.push('Only the OpenCode server plugin is registered; reconcile its TUI entry before retrying.');
181
+ else
182
+ pairs.push({ server, tui });
183
+ }
184
+ if (pairs.length > 1)
185
+ conflicts.push('Multiple OpenCode Evolver plugin installations are registered.');
186
+ for (const entry of tuiEntries) {
187
+ const tui = entryPath(entry, root);
188
+ if (!tui.endsWith('/tui.mjs') && !tui.endsWith('\\tui.mjs'))
189
+ continue;
190
+ if (readPluginJson(join(dirname(tui), 'package.json'))?.['name'] === '@evomap/evolver-opencode' && !pairs.some(pair => pair.tui === tui)) {
191
+ conflicts.push('Only the OpenCode TUI plugin is registered; reconcile its server entry before retrying.');
192
+ }
193
+ }
194
+ for (const entry of [...serverEntries, ...tuiEntries]) {
195
+ if (entry.includes('@evomap/evolver-opencode'))
196
+ conflicts.push('An OpenCode Evolver package specifier is already registered. Resolve its source/path before installing another copy.');
197
+ }
198
+ const pair = pairs[0];
199
+ const path = pair && dirname(pair.server);
200
+ const manifest = path && readPluginJson(join(path, 'package.json'));
201
+ const installed = manifest && typeof manifest['version'] === 'string' ? { id: AGENT_PLUGIN_NAME, name: AGENT_PLUGIN_NAME, version: manifest['version'], enabled: true, path, raw: manifest } : undefined;
202
+ return { installed, marketplacePresent: false, conflicts };
203
+ }
204
+ function inspectDshPlugin(runtime, options) {
205
+ const profileDir = join(pluginHome(runtime), '.dsh', 'profiles', options.profile);
206
+ const project = readPluginJson(join(profileDir, 'package.json'));
207
+ const dependency = objectOf(project?.['dependencies'])?.['@evomap/dsh-evolver'];
208
+ const path = join(profileDir, 'node_modules', '@evomap', 'dsh-evolver');
209
+ const manifest = readPluginJson(join(path, 'package.json'));
210
+ const conflicts = [];
211
+ if (dependency !== undefined && (typeof dependency !== 'string' || !dependency.includes(`github:${AGENT_PLUGIN_REPOSITORY}#release&path:dist/dsh`))) {
212
+ conflicts.push(`Profile ${options.profile} contains the standalone or differently sourced @evomap/dsh-evolver. Remove that package in this profile first; keep its state.`);
213
+ }
214
+ const repository = packageRepositoryOf(manifest?.['repository']);
215
+ if (manifest && !agentPluginRepositoryMatches(repository))
216
+ conflicts.push('The installed dsh package does not belong to the unified plugin repository.');
217
+ const installed = manifest && dependency !== undefined && typeof manifest['version'] === 'string'
218
+ ? { id: AGENT_PLUGIN_NAME, name: AGENT_PLUGIN_NAME, version: manifest['version'], enabled: true, path, raw: manifest } : undefined;
219
+ return { installed, marketplacePresent: false, conflicts };
220
+ }
221
+ export async function inspectAgentPlugin(runtime, options) {
222
+ if (options.host.kind === 'marketplace')
223
+ return inspectMarketplacePlugin(runtime, options);
224
+ if (options.host.id === 'opencode')
225
+ return inspectOpenCodePlugin(runtime, options);
226
+ if (options.host.id === 'dsh')
227
+ return inspectDshPlugin(runtime, options);
228
+ const result = await checkedPluginCommand(runtime, options.host.command, ['plugin', 'list', '--json'], options.root);
229
+ const plugins = installedPluginsFromJson(pluginJson(result.stdout, 'Antigravity plugin list'), options.host);
230
+ const installed = plugins.find(plugin => plugin.name === AGENT_PLUGIN_NAME);
231
+ const conflicts = plugins.filter(plugin => options.host.legacyNames.includes(plugin.name) && plugin.enabled).map(plugin => `Standalone ${plugin.name} is enabled; disable/remove it and keep its data before continuing.`);
232
+ if (installed && hasForeignInstalledScope(installed, options.scope))
233
+ conflicts.push('The host registered this plugin in another scope; it cannot confirm the requested installation scope.');
234
+ if (installed && !installed.enabled)
235
+ conflicts.push('The plugin is installed but disabled. Enable it explicitly in the host rather than installing another copy.');
236
+ return { marketplacePresent: false, installed, conflicts };
237
+ }
@@ -0,0 +1,19 @@
1
+ import { type PluginCommandStep, type PluginInstallOptions } from './pluginHosts.js';
2
+ import { type PluginInstallStatus, type PluginRuntime } from './pluginRuntime.js';
3
+ export interface AgentPluginInstallResult {
4
+ ok: boolean;
5
+ status: PluginInstallStatus;
6
+ host: string;
7
+ scope: string;
8
+ verified: boolean;
9
+ repository: string;
10
+ commands: PluginCommandStep[];
11
+ completed: string[];
12
+ instructions: string[];
13
+ rollback: string[];
14
+ version?: string;
15
+ installedPath?: string;
16
+ error?: string;
17
+ profile?: string;
18
+ }
19
+ export declare function installAgentPlugin(runtime: PluginRuntime, options: PluginInstallOptions): Promise<AgentPluginInstallResult>;
@@ -0,0 +1,84 @@
1
+ import { ensureAgentPluginBundle } from './pluginBundle.js';
2
+ import { AGENT_PLUGIN_NAME, AGENT_PLUGIN_REPOSITORY, pluginInstallSteps, pluginRollbackInstructions } from './pluginHosts.js';
3
+ import { inspectAgentPlugin, verifyPluginManifest } from './pluginInspection.js';
4
+ import { withPluginInstallLock } from './pluginLock.js';
5
+ import { checkedPluginCommand, checkPluginHostVersion, PluginInstallError } from './pluginRuntime.js';
6
+ export async function installAgentPlugin(runtime, options) {
7
+ const { host } = options;
8
+ const result = {
9
+ ok: false, status: 'failed', host: host.id, scope: options.scope, verified: false, repository: AGENT_PLUGIN_REPOSITORY,
10
+ commands: pluginInstallSteps(options), completed: [], instructions: [...host.instructions], rollback: pluginRollbackInstructions(options),
11
+ ...(host.id === 'dsh' && { profile: options.profile }),
12
+ };
13
+ if (host.kind === 'manual') {
14
+ const instructions = options.scope === 'project' && host.id === 'workbuddy'
15
+ ? result.instructions.map(line => line === '/plugin install evolver-plugin@evomap-workbuddy' ? `${line} --scope project` : line)
16
+ : result.instructions;
17
+ return { ...result, status: 'manual_required', instructions: [...instructions, `Requested scope: ${options.scope}. No client configuration was changed.`] };
18
+ }
19
+ if (options.dryRun)
20
+ return { ...result, ok: true, status: 'dry_run', instructions: [...result.instructions, 'Preview only: host version, registration, download and installation have not been executed.'] };
21
+ try {
22
+ await checkPluginHostVersion(runtime, host);
23
+ let inspection = await inspectAgentPlugin(runtime, options);
24
+ if (inspection.conflicts.length > 0)
25
+ throw new PluginInstallError('conflict', inspection.conflicts.join('\n'));
26
+ if (inspection.installed) {
27
+ const installedPath = verifyPluginManifest(runtime, options, inspection.installed);
28
+ return { ...result, ok: true, status: 'already_installed', verified: true, version: inspection.installed.version, installedPath, commands: [] };
29
+ }
30
+ return await withPluginInstallLock(runtime, options, async () => {
31
+ inspection = await inspectAgentPlugin(runtime, options);
32
+ if (inspection.conflicts.length > 0)
33
+ throw new PluginInstallError('conflict', inspection.conflicts.join('\n'));
34
+ if (inspection.installed) {
35
+ const installedPath = verifyPluginManifest(runtime, options, inspection.installed);
36
+ return { ...result, ok: true, status: 'already_installed', verified: true, version: inspection.installed.version, installedPath, commands: [] };
37
+ }
38
+ let bundle;
39
+ if (host.kind === 'bundle') {
40
+ bundle = await ensureAgentPluginBundle(runtime, host);
41
+ result.completed.push('download');
42
+ result.commands = pluginInstallSteps(options, bundle);
43
+ result.rollback = pluginRollbackInstructions(options, bundle);
44
+ }
45
+ let installAnswer;
46
+ for (const step of result.commands) {
47
+ if (step.name === 'marketplace' && inspection.marketplacePresent)
48
+ continue;
49
+ const executed = await checkedPluginCommand(runtime, step.command, step.args, options.root, 120_000);
50
+ result.completed.push(step.name);
51
+ if (step.name === 'marketplace') {
52
+ inspection = await inspectAgentPlugin(runtime, options);
53
+ if (!inspection.marketplacePresent || inspection.conflicts.length > 0) {
54
+ throw new PluginInstallError('conflict', 'The registered marketplace could not be confirmed as the unified plugin source. No plugin install was attempted.');
55
+ }
56
+ }
57
+ else {
58
+ try {
59
+ installAnswer = JSON.parse(executed.stdout);
60
+ }
61
+ catch { /* Some native installers report human-readable progress; the final inventory is authoritative. */ }
62
+ }
63
+ }
64
+ inspection = await inspectAgentPlugin(runtime, options);
65
+ if (inspection.conflicts.length > 0)
66
+ throw new PluginInstallError('conflict', inspection.conflicts.join('\n'));
67
+ if (!inspection.installed)
68
+ throw new PluginInstallError('failed', `The ${AGENT_PLUGIN_NAME} command completed, but the selected host/scope did not register it. Installation was not confirmed.`);
69
+ const installedPath = verifyPluginManifest(runtime, options, inspection.installed, installAnswer);
70
+ return { ...result, ok: true, status: 'installed', verified: true, version: inspection.installed.version, installedPath };
71
+ });
72
+ }
73
+ catch (error) {
74
+ return {
75
+ ...result,
76
+ status: error instanceof PluginInstallError ? error.status : 'failed',
77
+ error: error instanceof PluginInstallError ? error.message : 'The plugin operation failed; no verified installation was reported.',
78
+ instructions: [...result.instructions, ...(result.completed.length > 0 ? [
79
+ `Commands already completed: ${result.completed.join(', ')}. Inspect the selected host before retrying.`,
80
+ 'No existing plugin, user data or marketplace was automatically removed. Use the rollback instructions only after checking the current host registration.',
81
+ ] : [])],
82
+ };
83
+ }
84
+ }
@@ -0,0 +1,4 @@
1
+ import type { PluginInstallOptions } from './pluginHosts.js';
2
+ import { type PluginRuntime } from './pluginRuntime.js';
3
+ export declare function withOwnedPluginLock<T>(path: string, work: () => Promise<T>): Promise<T>;
4
+ export declare function withPluginInstallLock<T>(runtime: PluginRuntime, options: PluginInstallOptions, work: () => Promise<T>): Promise<T>;
@@ -0,0 +1,52 @@
1
+ import { util } from '@evomap/evolver-core';
2
+ import { createHash } from 'node:crypto';
3
+ import { mkdirSync, realpathSync } from 'node:fs';
4
+ import { join, resolve } from 'node:path';
5
+ import { assertPluginManagedPath, pluginHome, PluginInstallError } from './pluginRuntime.js';
6
+ export async function withOwnedPluginLock(path, work) {
7
+ let owner;
8
+ try {
9
+ owner = util.acquireLock(path, { maxTries: 1, waitMs: 0 });
10
+ }
11
+ catch {
12
+ throw new PluginInstallError('conflict', 'Another installation/download for this target is in progress, or its lock is unsafe. Retry after inspecting that operation.');
13
+ }
14
+ let result;
15
+ let error;
16
+ let failed = false;
17
+ try {
18
+ result = await work();
19
+ }
20
+ catch (caught) {
21
+ error = caught;
22
+ failed = true;
23
+ }
24
+ let released = false;
25
+ try {
26
+ released = util.releaseLock(path, owner).released;
27
+ }
28
+ catch { /* Report cleanup separately without replacing the original operation's evidence. */ }
29
+ if (!released) {
30
+ const prior = error instanceof PluginInstallError ? `${error.message} ` : '';
31
+ throw new PluginInstallError('failed', `${prior}The owned installation/download lock could not be released; inspect it before retrying.`);
32
+ }
33
+ if (failed)
34
+ throw error;
35
+ return result;
36
+ }
37
+ export function withPluginInstallLock(runtime, options, work) {
38
+ let projectRoot = '';
39
+ if (options.scope === 'project') {
40
+ try {
41
+ projectRoot = realpathSync(resolve(runtime.cwd, options.root));
42
+ }
43
+ catch {
44
+ throw new PluginInstallError('invalid_arguments', 'The project root could not be resolved before acquiring an installation lock.');
45
+ }
46
+ }
47
+ const folder = join(realpathSync(pluginHome(runtime)), '.evolver', 'plugins', 'install-locks');
48
+ assertPluginManagedPath(folder);
49
+ mkdirSync(folder, { recursive: true, mode: 0o700 });
50
+ const key = createHash('sha256').update(JSON.stringify([options.host.id, options.scope, projectRoot, options.profile])).digest('hex').slice(0, 24);
51
+ return withOwnedPluginLock(join(folder, `${key}.lock`), work);
52
+ }
@@ -0,0 +1,31 @@
1
+ import { exec } from '@evomap/evolver-core';
2
+ import type { PluginHost } from './pluginHosts.js';
3
+ export type PluginProcessResult = Awaited<ReturnType<typeof exec.spawnCapture>>;
4
+ export type PluginInstallStatus = 'installed' | 'already_installed' | 'dry_run' | 'manual_required' | 'host_missing' | 'unsupported_version' | 'unsupported_capability' | 'conflict' | 'failed' | 'invalid_arguments' | 'selection_required';
5
+ export declare class PluginInstallError extends Error {
6
+ readonly status: PluginInstallStatus;
7
+ constructor(status: PluginInstallStatus, message: string);
8
+ }
9
+ export interface PluginRuntime {
10
+ env: NodeJS.ProcessEnv;
11
+ platform: NodeJS.Platform;
12
+ cwd: string;
13
+ available(command: string): boolean;
14
+ run(command: string, args: readonly string[], cwd?: string, timeoutMs?: number): Promise<PluginProcessResult>;
15
+ }
16
+ export declare function pluginHome(runtime: PluginRuntime): string;
17
+ export declare function pluginExecutableAvailable(command: string, env: NodeJS.ProcessEnv, platform: NodeJS.Platform): boolean;
18
+ export declare function resolvePluginSpawn(command: string, args: readonly string[], env: NodeJS.ProcessEnv, platform: NodeJS.Platform, standalone?: boolean): {
19
+ cmd: string;
20
+ args: string[];
21
+ };
22
+ export declare function createPluginRuntime(overrides?: Partial<PluginRuntime>): PluginRuntime;
23
+ export declare function checkedPluginCommand(runtime: PluginRuntime, command: string, args: readonly string[], cwd?: string, timeoutMs?: number): Promise<PluginProcessResult>;
24
+ export declare function pluginJson(text: string, label: string): unknown;
25
+ export declare function objectOf(value: unknown): Record<string, unknown> | undefined;
26
+ export declare function readPluginText(path: string, maxBytes?: number): string | undefined;
27
+ export declare function readPluginJson(path: string): Record<string, unknown> | undefined;
28
+ export declare function pluginVersionAtLeast(current: string, minimum: string): boolean;
29
+ export declare function checkPluginHostVersion(runtime: PluginRuntime, host: PluginHost): Promise<void>;
30
+ /** Only installer-owned descendants are written; a symlink may not redirect the cache or lock. */
31
+ export declare function assertPluginManagedPath(path: string): void;