claude-flow 3.74.0 → 3.75.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/.claude/helpers/auto-memory-hook.mjs +262 -81
  2. package/node_modules/@claude-flow/codex/README.md +38 -0
  3. package/node_modules/@claude-flow/codex/dist/generators/agents-md.d.ts +1 -0
  4. package/node_modules/@claude-flow/codex/dist/generators/agents-md.d.ts.map +1 -1
  5. package/node_modules/@claude-flow/codex/dist/generators/agents-md.js +4 -4
  6. package/node_modules/@claude-flow/codex/dist/generators/agents-md.js.map +1 -1
  7. package/node_modules/@claude-flow/codex/dist/generators/dual-instructions.d.ts +20 -0
  8. package/node_modules/@claude-flow/codex/dist/generators/dual-instructions.d.ts.map +1 -0
  9. package/node_modules/@claude-flow/codex/dist/generators/dual-instructions.js +104 -0
  10. package/node_modules/@claude-flow/codex/dist/generators/dual-instructions.js.map +1 -0
  11. package/node_modules/@claude-flow/codex/dist/generators/index.d.ts +2 -0
  12. package/node_modules/@claude-flow/codex/dist/generators/index.d.ts.map +1 -1
  13. package/node_modules/@claude-flow/codex/dist/generators/index.js +2 -0
  14. package/node_modules/@claude-flow/codex/dist/generators/index.js.map +1 -1
  15. package/node_modules/@claude-flow/codex/dist/generators/shared-instructions.d.ts +46 -0
  16. package/node_modules/@claude-flow/codex/dist/generators/shared-instructions.d.ts.map +1 -0
  17. package/node_modules/@claude-flow/codex/dist/generators/shared-instructions.js +162 -0
  18. package/node_modules/@claude-flow/codex/dist/generators/shared-instructions.js.map +1 -0
  19. package/node_modules/@claude-flow/codex/dist/index.d.ts +3 -3
  20. package/node_modules/@claude-flow/codex/dist/index.js +1 -1
  21. package/node_modules/@claude-flow/codex/dist/initializer.d.ts.map +1 -1
  22. package/node_modules/@claude-flow/codex/dist/initializer.js +16 -93
  23. package/node_modules/@claude-flow/codex/dist/initializer.js.map +1 -1
  24. package/node_modules/@claude-flow/codex/package.json +8 -6
  25. package/node_modules/@claude-flow/mcp/README.md +44 -0
  26. package/node_modules/@claude-flow/mcp/package.json +16 -4
  27. package/package.json +4 -4
  28. package/v3/@claude-flow/cli/catalog-manifest.json +3 -3
  29. package/v3/@claude-flow/cli/dist/src/autopilot-state.js +17 -8
  30. package/v3/@claude-flow/cli/dist/src/commands/agent.js +2 -1
  31. package/v3/@claude-flow/cli/dist/src/commands/init.js +28 -6
  32. package/v3/@claude-flow/cli/dist/src/commands/memory-backup.js +2 -1
  33. package/v3/@claude-flow/cli/dist/src/commands/memory-distill.js +2 -1
  34. package/v3/@claude-flow/cli/dist/src/commands/memory.js +47 -3
  35. package/v3/@claude-flow/cli/dist/src/commands/neural.js +6 -5
  36. package/v3/@claude-flow/cli/dist/src/commands/plugins-host.d.ts +13 -0
  37. package/v3/@claude-flow/cli/dist/src/commands/plugins-host.js +161 -0
  38. package/v3/@claude-flow/cli/dist/src/commands/plugins.js +3 -1
  39. package/v3/@claude-flow/cli/dist/src/commands/start-all.d.ts +28 -0
  40. package/v3/@claude-flow/cli/dist/src/commands/start-all.js +99 -0
  41. package/v3/@claude-flow/cli/dist/src/commands/start.d.ts +5 -1
  42. package/v3/@claude-flow/cli/dist/src/commands/start.js +17 -10
  43. package/v3/@claude-flow/cli/dist/src/commands/swarm.js +2 -1
  44. package/v3/@claude-flow/cli/dist/src/fs-secure.js +9 -2
  45. package/v3/@claude-flow/cli/dist/src/init/claudemd-generator.d.ts +15 -0
  46. package/v3/@claude-flow/cli/dist/src/init/claudemd-generator.js +64 -114
  47. package/v3/@claude-flow/cli/dist/src/init/dual-instructions.d.ts +29 -0
  48. package/v3/@claude-flow/cli/dist/src/init/dual-instructions.js +87 -0
  49. package/v3/@claude-flow/cli/dist/src/init/executor.js +96 -13
  50. package/v3/@claude-flow/cli/dist/src/init/index.d.ts +3 -1
  51. package/v3/@claude-flow/cli/dist/src/init/index.js +5 -1
  52. package/v3/@claude-flow/cli/dist/src/init/plugin-dedup.d.ts +61 -0
  53. package/v3/@claude-flow/cli/dist/src/init/plugin-dedup.js +130 -0
  54. package/v3/@claude-flow/cli/dist/src/init/shared-instructions.d.ts +46 -0
  55. package/v3/@claude-flow/cli/dist/src/init/shared-instructions.js +162 -0
  56. package/v3/@claude-flow/cli/dist/src/init/types.d.ts +33 -0
  57. package/v3/@claude-flow/cli/dist/src/init/types.js +3 -0
  58. package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.d.ts +14 -0
  59. package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.js +48 -5
  60. package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-hierarchical-inventory-tools.d.ts +15 -0
  61. package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-hierarchical-inventory-tools.js +115 -0
  62. package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-inventory-tools.d.ts +21 -0
  63. package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-inventory-tools.js +152 -0
  64. package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-tools.js +56 -7
  65. package/v3/@claude-flow/cli/dist/src/mcp-tools/aidefence-known-misses.d.ts +6 -0
  66. package/v3/@claude-flow/cli/dist/src/mcp-tools/aidefence-known-misses.js +23 -5
  67. package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +21 -3
  68. package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.d.ts +29 -0
  69. package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.js +239 -19
  70. package/v3/@claude-flow/cli/dist/src/mcp-tools/security-tools.js +53 -5
  71. package/v3/@claude-flow/cli/dist/src/memory/embedding-config.d.ts +79 -0
  72. package/v3/@claude-flow/cli/dist/src/memory/embedding-config.js +250 -0
  73. package/v3/@claude-flow/cli/dist/src/memory/ewc-consolidation.js +2 -1
  74. package/v3/@claude-flow/cli/dist/src/memory/intelligence.d.ts +28 -2
  75. package/v3/@claude-flow/cli/dist/src/memory/intelligence.js +37 -7
  76. package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.d.ts +42 -0
  77. package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.js +267 -28
  78. package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.d.ts +1 -1
  79. package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +47 -22
  80. package/v3/@claude-flow/cli/dist/src/ruvector/lora-adapter.js +3 -2
  81. package/v3/@claude-flow/cli/dist/src/ruvector/task-embedder.d.ts +2 -1
  82. package/v3/@claude-flow/cli/dist/src/ruvector/task-embedder.js +7 -3
  83. package/v3/@claude-flow/cli/dist/src/services/daemon-autostart.d.ts +4 -6
  84. package/v3/@claude-flow/cli/dist/src/services/daemon-autostart.js +6 -46
  85. package/v3/@claude-flow/cli/dist/src/services/host-executable.d.ts +68 -0
  86. package/v3/@claude-flow/cli/dist/src/services/host-executable.js +175 -0
  87. package/v3/@claude-flow/cli/dist/src/services/host-plugin-manager.d.ts +137 -0
  88. package/v3/@claude-flow/cli/dist/src/services/host-plugin-manager.js +374 -0
  89. package/v3/@claude-flow/cli/dist/src/services/project-root.d.ts +37 -0
  90. package/v3/@claude-flow/cli/dist/src/services/project-root.js +122 -0
  91. package/v3/@claude-flow/cli/package.json +7 -7
  92. package/.claude/.proven-config-version +0 -1
  93. package/.claude/proven-config.json +0 -42
@@ -21,6 +21,7 @@
21
21
  */
22
22
  import * as fs from 'node:fs';
23
23
  import { resolveModelCacheDir } from '../memory/model-cache-dir.js';
24
+ import { resolveEmbeddingConfig } from '../memory/embedding-config.js';
24
25
  // ============================================================================
25
26
  // FNV-1a-32 hash (matches scripts/gen-seed-corpus.mjs + router-trajectory.ts)
26
27
  // ============================================================================
@@ -76,7 +77,9 @@ function loadExtractor() {
76
77
  const env = mod.env;
77
78
  if (env)
78
79
  env.cacheDir = cacheDir;
79
- const extractor = await mod.pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2', { quantized: true });
80
+ // #2305: honour `.claude-flow/embeddings.json` (default MiniLM/384).
81
+ const { model } = resolveEmbeddingConfig(process.cwd());
82
+ const extractor = await mod.pipeline('feature-extraction', model, { quantized: true });
80
83
  _extractorDegradedReason = null;
81
84
  return extractor;
82
85
  }
@@ -109,7 +112,7 @@ async function loadEmbedderBatch() {
109
112
  return null;
110
113
  return async (texts) => {
111
114
  const out = await ex(texts, { pooling: 'mean', normalize: true });
112
- const dims = out.dims ?? [texts.length, 384];
115
+ const dims = out.dims ?? [texts.length, resolveEmbeddingConfig(process.cwd()).dimension];
113
116
  const N = dims[0] ?? texts.length;
114
117
  const dim = dims[1] ?? Math.floor(out.data.length / N);
115
118
  const data = out.data;
@@ -156,7 +159,8 @@ function lruSet(key, value) {
156
159
  // Public API
157
160
  // ============================================================================
158
161
  /**
159
- * Compute (or fetch from cache) the 384-dim MiniLM embedding for `task`.
162
+ * Compute (or fetch from cache) the embedding for `task` with the configured
163
+ * model (`.claude-flow/embeddings.json`; default 384-dim MiniLM).
160
164
  * Returns `undefined` on any failure (missing @xenova/transformers, ONNX
161
165
  * runtime error, etc.) so callers can gracefully fall back to the
162
166
  * heuristic+bandit path. Best-effort and never throws.
@@ -1,3 +1,4 @@
1
+ import { isRufloProject } from './project-root.js';
1
2
  /** True if a live daemon already holds the project's pidfile. */
2
3
  export declare function isDaemonAlive(projectRoot: string): boolean;
3
4
  /**
@@ -26,13 +27,10 @@ export declare function writeDaemonStopMarker(projectRoot: string): boolean;
26
27
  export declare function clearDaemonStopMarker(projectRoot: string): void;
27
28
  /**
28
29
  * Return true only when the directory contains a durable Ruflo project marker.
29
- *
30
- * A bare `.claude/` is owned by Claude Code, and a bare `.claude-flow/` is not
31
- * sufficient either: startup-time policy/champion migration can create it
32
- * before this function runs. Treating that mutation as authorization caused a
33
- * read-only command in any Claude project to spawn a detached daemon (#2852).
30
+ * Implementation lives in ./project-root.ts (shared with #2633 state anchoring);
31
+ * re-exported here for existing importers.
34
32
  */
35
- export declare function isRufloProject(projectRoot: string): boolean;
33
+ export { isRufloProject };
36
34
  /**
37
35
  * #2877: Normalize a working directory to the project root that owns the
38
36
  * daemon lock/PID key.
@@ -31,6 +31,7 @@
31
31
  import * as fs from 'fs';
32
32
  import * as path from 'path';
33
33
  import { spawn } from 'child_process';
34
+ import { isRufloProject, resolveProjectRoot } from './project-root.js';
34
35
  /** True if a live daemon already holds the project's pidfile. */
35
36
  export function isDaemonAlive(projectRoot) {
36
37
  const pidFile = path.join(projectRoot, '.claude-flow', 'daemon.pid');
@@ -139,41 +140,10 @@ function autostartDisabled(projectRoot) {
139
140
  }
140
141
  /**
141
142
  * Return true only when the directory contains a durable Ruflo project marker.
142
- *
143
- * A bare `.claude/` is owned by Claude Code, and a bare `.claude-flow/` is not
144
- * sufficient either: startup-time policy/champion migration can create it
145
- * before this function runs. Treating that mutation as authorization caused a
146
- * read-only command in any Claude project to spawn a detached daemon (#2852).
143
+ * Implementation lives in ./project-root.ts (shared with #2633 state anchoring);
144
+ * re-exported here for existing importers.
147
145
  */
148
- export function isRufloProject(projectRoot) {
149
- const root = path.resolve(projectRoot);
150
- const directMarkers = [
151
- path.join(root, '.claude-flow', 'config.yaml'),
152
- path.join(root, '.claude-flow', 'config.yml'),
153
- path.join(root, '.claude-flow', 'config.json'),
154
- path.join(root, 'claude-flow.config.json'),
155
- path.join(root, '.swarm', 'memory.db'),
156
- ];
157
- if (directMarkers.some((marker) => fs.existsSync(marker)))
158
- return true;
159
- try {
160
- const settings = JSON.parse(fs.readFileSync(path.join(root, '.claude', 'settings.json'), 'utf-8'));
161
- if (settings && typeof settings === 'object' && 'claudeFlow' in settings) {
162
- return true;
163
- }
164
- }
165
- catch { /* absent/malformed/non-Ruflo settings */ }
166
- try {
167
- const mcp = JSON.parse(fs.readFileSync(path.join(root, '.mcp.json'), 'utf-8'));
168
- const servers = mcp?.mcpServers;
169
- if (servers && typeof servers === 'object'
170
- && ('ruflo' in servers || 'claude-flow' in servers)) {
171
- return true;
172
- }
173
- }
174
- catch { /* absent/malformed/non-Ruflo MCP config */ }
175
- return false;
176
- }
146
+ export { isRufloProject };
177
147
  /**
178
148
  * #2877: Normalize a working directory to the project root that owns the
179
149
  * daemon lock/PID key.
@@ -198,18 +168,8 @@ export function isRufloProject(projectRoot) {
198
168
  * non-Ruflo directory still fails `isRufloProject` and declines autostart.
199
169
  */
200
170
  export function resolveDaemonProjectRoot(startDir) {
201
- const start = path.resolve(startDir);
202
- let dir = start;
203
- for (;;) {
204
- if (isRufloProject(dir))
205
- return dir;
206
- if (fs.existsSync(path.join(dir, '.git')))
207
- return start;
208
- const parent = path.dirname(dir);
209
- if (parent === dir)
210
- return start;
211
- dir = parent;
212
- }
171
+ // #2633: the walk is shared with durable-state anchoring (./project-root.ts).
172
+ return resolveProjectRoot(startDir);
213
173
  }
214
174
  const defaultSpawn = (projectRoot) => {
215
175
  const cliBin = process.argv[1]; // the running bin/cli.js
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Host executable resolution + literal-argv runner (#2854).
3
+ *
4
+ * Finds the `claude` / `codex` CLI without a shell: no `which`, no
5
+ * `execSync` strings. PATH is scanned with fs.access(X_OK); on Windows each
6
+ * PATHEXT extension is tried. A resolved `.exe`/`.com` is spawned directly.
7
+ * An npm `.cmd`/`.bat` shim is never handed to cmd.exe: it is accepted only
8
+ * when the owning npm package sits next to it and declares the expected
9
+ * `bin`, and then the package's JavaScript entry is run with Node.
10
+ *
11
+ * Exported so `@claude-flow/codex`'s initializer can adopt the same
12
+ * resolver instead of `execSync('which codex')` (follow-up, not done here).
13
+ */
14
+ export type HostId = 'claude' | 'codex';
15
+ export declare const HOST_IDS: readonly HostId[];
16
+ /** npm package that owns each host's launcher, and the bin name it declares. */
17
+ export declare const HOST_PACKAGES: Readonly<Record<HostId, {
18
+ pkg: string;
19
+ bin: string;
20
+ }>>;
21
+ /** Absolute-path override, for layouts PATH does not cover. */
22
+ export declare const HOST_OVERRIDE_ENV: Readonly<Record<HostId, string>>;
23
+ export interface ExecFileResult {
24
+ stdout: string;
25
+ stderr: string;
26
+ }
27
+ /** Injectable process + fs boundary. Tests replace every member. */
28
+ export interface HostSystemDeps {
29
+ execFile(file: string, args: readonly string[], options: {
30
+ env: NodeJS.ProcessEnv;
31
+ timeout: number;
32
+ }): Promise<ExecFileResult>;
33
+ access(path: string, mode: number): Promise<void>;
34
+ readFile(path: string): Promise<string>;
35
+ env: NodeJS.ProcessEnv;
36
+ platform: NodeJS.Platform;
37
+ execPath: string;
38
+ }
39
+ /** The exact invocation carried through an operation: `file ...prefixArgs ...argv`. */
40
+ export interface HostInvocation {
41
+ host: HostId;
42
+ file: string;
43
+ prefixArgs: string[];
44
+ /** The launcher found on disk (the shim, for a validated npm .cmd). */
45
+ resolvedFrom: string;
46
+ }
47
+ export type HostResolution = {
48
+ ok: true;
49
+ invocation: HostInvocation;
50
+ } | {
51
+ ok: false;
52
+ host: HostId;
53
+ reason: string;
54
+ };
55
+ export declare function defaultHostSystemDeps(): HostSystemDeps;
56
+ /** Resolve a host CLI once, before any mutation. Never runs a shell. */
57
+ export declare function resolveHostExecutable(host: HostId, deps?: HostSystemDeps): Promise<HostResolution>;
58
+ export interface HostRunResult {
59
+ ok: boolean;
60
+ stdout: string;
61
+ stderr: string;
62
+ error?: string;
63
+ }
64
+ /** Run `invocation` with a literal argv. No shell, no string concatenation. */
65
+ export declare function runHostArgv(invocation: HostInvocation, argv: readonly string[], deps?: HostSystemDeps, timeoutMs?: number): Promise<HostRunResult>;
66
+ /** Human-readable form of an argv for dry-run output (display only, never executed). */
67
+ export declare function formatArgv(host: HostId, argv: readonly string[]): string;
68
+ //# sourceMappingURL=host-executable.d.ts.map
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Host executable resolution + literal-argv runner (#2854).
3
+ *
4
+ * Finds the `claude` / `codex` CLI without a shell: no `which`, no
5
+ * `execSync` strings. PATH is scanned with fs.access(X_OK); on Windows each
6
+ * PATHEXT extension is tried. A resolved `.exe`/`.com` is spawned directly.
7
+ * An npm `.cmd`/`.bat` shim is never handed to cmd.exe: it is accepted only
8
+ * when the owning npm package sits next to it and declares the expected
9
+ * `bin`, and then the package's JavaScript entry is run with Node.
10
+ *
11
+ * Exported so `@claude-flow/codex`'s initializer can adopt the same
12
+ * resolver instead of `execSync('which codex')` (follow-up, not done here).
13
+ */
14
+ import { execFile as execFileCb } from 'node:child_process';
15
+ import { constants as fsConstants, promises as fsp } from 'node:fs';
16
+ import * as nodePath from 'node:path';
17
+ import { promisify } from 'node:util';
18
+ export const HOST_IDS = ['claude', 'codex'];
19
+ /** npm package that owns each host's launcher, and the bin name it declares. */
20
+ export const HOST_PACKAGES = {
21
+ claude: { pkg: '@anthropic-ai/claude-code', bin: 'claude' },
22
+ codex: { pkg: '@openai/codex', bin: 'codex' },
23
+ };
24
+ /** Absolute-path override, for layouts PATH does not cover. */
25
+ export const HOST_OVERRIDE_ENV = {
26
+ claude: 'RUFLO_CLAUDE_BIN',
27
+ codex: 'RUFLO_CODEX_BIN',
28
+ };
29
+ const execFileAsync = promisify(execFileCb);
30
+ export function defaultHostSystemDeps() {
31
+ return {
32
+ async execFile(file, args, options) {
33
+ const { stdout, stderr } = await execFileAsync(file, [...args], {
34
+ env: options.env,
35
+ timeout: options.timeout,
36
+ shell: false,
37
+ windowsHide: true,
38
+ maxBuffer: 16 * 1024 * 1024,
39
+ encoding: 'utf8',
40
+ });
41
+ return { stdout: String(stdout), stderr: String(stderr) };
42
+ },
43
+ access: (p, mode) => fsp.access(p, mode),
44
+ readFile: (p) => fsp.readFile(p, 'utf8'),
45
+ env: process.env,
46
+ platform: process.platform,
47
+ execPath: process.execPath,
48
+ };
49
+ }
50
+ function pathApi(platform) {
51
+ return platform === 'win32' ? nodePath.win32 : nodePath.posix;
52
+ }
53
+ function envValue(env, key, platform) {
54
+ if (platform !== 'win32')
55
+ return env[key];
56
+ // Windows env keys are case-insensitive (Path vs PATH).
57
+ const hit = Object.keys(env).find((k) => k.toUpperCase() === key.toUpperCase());
58
+ return hit ? env[hit] : undefined;
59
+ }
60
+ async function isExecutable(deps, p) {
61
+ try {
62
+ await deps.access(p, fsConstants.X_OK);
63
+ return true;
64
+ }
65
+ catch {
66
+ return false;
67
+ }
68
+ }
69
+ /**
70
+ * Prove an npm `.cmd`/`.bat` shim belongs to the expected package and map it
71
+ * to `node <bin.js>`. Returns null for an unprovable or forged wrapper.
72
+ */
73
+ async function resolveNpmShim(host, shimPath, deps) {
74
+ const p = pathApi(deps.platform);
75
+ const { pkg, bin } = HOST_PACKAGES[host];
76
+ const pkgDir = p.join(p.dirname(shimPath), 'node_modules', ...pkg.split('/'));
77
+ let manifest;
78
+ try {
79
+ manifest = JSON.parse(await deps.readFile(p.join(pkgDir, 'package.json')));
80
+ }
81
+ catch {
82
+ return null;
83
+ }
84
+ if (manifest.name !== pkg)
85
+ return null;
86
+ const binField = manifest.bin;
87
+ const rel = typeof binField === 'string' ? binField
88
+ : binField && typeof binField === 'object' ? binField[bin] : undefined;
89
+ if (typeof rel !== 'string' || rel.length === 0)
90
+ return null;
91
+ const entry = p.resolve(pkgDir, rel);
92
+ const relToPkg = p.relative(pkgDir, entry);
93
+ if (relToPkg.startsWith('..') || p.isAbsolute(relToPkg))
94
+ return null; // bin escapes its package
95
+ if (!/\.(c|m)?js$/i.test(entry))
96
+ return null; // only a JS entry can run under Node
97
+ try {
98
+ await deps.access(entry, fsConstants.R_OK);
99
+ }
100
+ catch {
101
+ return null;
102
+ }
103
+ return { host, file: deps.execPath, prefixArgs: [entry], resolvedFrom: shimPath };
104
+ }
105
+ async function invocationFor(host, candidate, deps) {
106
+ if (deps.platform === 'win32' && /\.(cmd|bat)$/i.test(candidate)) {
107
+ return resolveNpmShim(host, candidate, deps);
108
+ }
109
+ return { host, file: candidate, prefixArgs: [], resolvedFrom: candidate };
110
+ }
111
+ /** Resolve a host CLI once, before any mutation. Never runs a shell. */
112
+ export async function resolveHostExecutable(host, deps = defaultHostSystemDeps()) {
113
+ const p = pathApi(deps.platform);
114
+ const rejected = [];
115
+ const override = envValue(deps.env, HOST_OVERRIDE_ENV[host], deps.platform);
116
+ if (override) {
117
+ if (!p.isAbsolute(override)) {
118
+ return { ok: false, host, reason: `${HOST_OVERRIDE_ENV[host]} must be an absolute path` };
119
+ }
120
+ if (!(await isExecutable(deps, override))) {
121
+ return { ok: false, host, reason: `${HOST_OVERRIDE_ENV[host]}=${override} is not executable` };
122
+ }
123
+ const inv = await invocationFor(host, override, deps);
124
+ return inv ? { ok: true, invocation: inv }
125
+ : { ok: false, host, reason: `${override} is not a verifiable ${HOST_PACKAGES[host].pkg} launcher` };
126
+ }
127
+ const dirs = (envValue(deps.env, 'PATH', deps.platform) ?? '')
128
+ .split(p.delimiter)
129
+ .map((d) => d.replace(/^"(.*)"$/, '$1'))
130
+ .filter((d) => d.length > 0 && p.isAbsolute(d)); // a relative PATH entry resolves against cwd: skip it
131
+ const exts = deps.platform === 'win32'
132
+ ? (envValue(deps.env, 'PATHEXT', deps.platform) ?? '.COM;.EXE;.BAT;.CMD')
133
+ .split(';').map((e) => e.trim().toLowerCase()).filter((e) => /^\.[a-z0-9]+$/.test(e))
134
+ : [''];
135
+ for (const dir of dirs) {
136
+ for (const ext of exts) {
137
+ const candidate = p.join(dir, host + ext);
138
+ if (!(await isExecutable(deps, candidate)))
139
+ continue;
140
+ const inv = await invocationFor(host, candidate, deps);
141
+ if (inv)
142
+ return { ok: true, invocation: inv };
143
+ rejected.push(candidate);
144
+ }
145
+ }
146
+ const why = rejected.length > 0
147
+ ? `rejected unverifiable launcher(s): ${rejected.join(', ')}`
148
+ : `\`${host}\` not found on PATH`;
149
+ return { ok: false, host, reason: `${why} (set ${HOST_OVERRIDE_ENV[host]} to an absolute path to override)` };
150
+ }
151
+ /** Run `invocation` with a literal argv. No shell, no string concatenation. */
152
+ export async function runHostArgv(invocation, argv, deps = defaultHostSystemDeps(), timeoutMs = 180_000) {
153
+ try {
154
+ const { stdout, stderr } = await deps.execFile(invocation.file, [...invocation.prefixArgs, ...argv], {
155
+ env: deps.env,
156
+ timeout: timeoutMs,
157
+ });
158
+ return { ok: true, stdout, stderr };
159
+ }
160
+ catch (err) {
161
+ const e = err;
162
+ return {
163
+ ok: false,
164
+ stdout: typeof e.stdout === 'string' ? e.stdout : '',
165
+ stderr: typeof e.stderr === 'string' ? e.stderr : '',
166
+ error: e.message ?? String(err),
167
+ };
168
+ }
169
+ }
170
+ /** Human-readable form of an argv for dry-run output (display only, never executed). */
171
+ export function formatArgv(host, argv) {
172
+ const q = (a) => (/^[A-Za-z0-9@%+=:,./_-]+$/.test(a) ? a : JSON.stringify(a));
173
+ return [host, ...argv].map(q).join(' ');
174
+ }
175
+ //# sourceMappingURL=host-executable.js.map
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Dual-host marketplace plugin manager (#2854).
3
+ *
4
+ * Claude Code and Codex keep separate plugin registries. This service drives
5
+ * each host's own plugin CLI (never its caches) with a literal argv, so one
6
+ * `ruflo plugins host ...` call can apply the same state to both.
7
+ *
8
+ * Results are reported per host and per plugin. A failure on one host never
9
+ * hides the other's outcome, and `ok` is false if any requested host failed.
10
+ *
11
+ * `sync` policy (documented choice): the target enabled set is the UNION of
12
+ * the plugins enabled in either host. It is additive: a plugin missing from a
13
+ * host is installed there; nothing is ever removed; a plugin a host has
14
+ * installed but explicitly disabled is left disabled and reported.
15
+ */
16
+ import { type HostId, type HostInvocation, type HostSystemDeps } from './host-executable.js';
17
+ export * from './host-executable.js';
18
+ export type HostAction = 'install' | 'update' | 'uninstall' | 'enable' | 'disable';
19
+ export type HostScope = 'user' | 'project' | 'local';
20
+ export declare const DEFAULT_MARKETPLACE_SOURCE = "ruvnet/ruflo";
21
+ export declare const DEFAULT_MARKETPLACE_NAME = "ruflo";
22
+ export declare class HostPluginInputError extends Error {
23
+ }
24
+ /** Validate a plugin name (or `name@<marketplace>`) before it can reach an argv. */
25
+ export declare function validatePluginName(raw: string, marketplaceName?: string): string;
26
+ export declare function validateMarketplace(source: string, name: string): void;
27
+ export interface MarketplaceRef {
28
+ source: string;
29
+ name: string;
30
+ }
31
+ /** One argv to run against one host. */
32
+ export interface HostStep {
33
+ argv: string[];
34
+ purpose: string;
35
+ }
36
+ export type HostArgvPlan = {
37
+ supported: true;
38
+ steps: HostStep[];
39
+ } | {
40
+ supported: false;
41
+ reason: string;
42
+ manual: string;
43
+ };
44
+ /** Pure argv builder for a plugin action on one host. */
45
+ export declare function buildActionArgv(host: HostId, action: HostAction, plugin: string, scope: HostScope, mp: MarketplaceRef): HostArgvPlan;
46
+ export declare function buildMarketplaceArgv(host: HostId, op: 'add' | 'update', mp: MarketplaceRef): string[];
47
+ export declare function buildListArgv(kind: 'plugins' | 'marketplaces'): string[];
48
+ export interface HostPluginState {
49
+ version: string;
50
+ enabled: boolean;
51
+ }
52
+ export interface HostState {
53
+ plugins: Map<string, HostPluginState>;
54
+ /** null: no marketplace with our name. Otherwise its normalized source. */
55
+ marketplaceSource: string | null;
56
+ }
57
+ /** github repo / git URL / local path → comparable form (`owner/repo` or `dir:<path>`). */
58
+ export declare function normalizeMarketplaceSource(raw: string): string;
59
+ /** Parse `<host> plugin list --json` + `<host> plugin marketplace list --json`. */
60
+ export declare function parseHostState(host: HostId, pluginsJson: string, marketplacesJson: string, mp: MarketplaceRef, scope: HostScope, cwd: string): HostState;
61
+ export type HostOutcome = 'ok' | 'unchanged' | 'planned' | 'failed' | 'unsupported' | 'refused' | 'not-detected';
62
+ export interface HostStepResult {
63
+ argv: string[];
64
+ display: string;
65
+ purpose: string;
66
+ ok?: boolean;
67
+ stderr?: string;
68
+ error?: string;
69
+ }
70
+ export interface HostTargetResult {
71
+ host: HostId;
72
+ /** Plugin name, or `(marketplace)` for a marketplace step. */
73
+ target: string;
74
+ outcome: HostOutcome;
75
+ steps: HostStepResult[];
76
+ message?: string;
77
+ manual?: string;
78
+ }
79
+ export interface HostOperationReport {
80
+ action: HostAction | 'sync';
81
+ dryRun: boolean;
82
+ ok: boolean;
83
+ results: HostTargetResult[];
84
+ }
85
+ export type HostSelection = 'claude' | 'codex' | 'both' | 'auto';
86
+ export interface HostOperationOptions {
87
+ hosts?: HostSelection;
88
+ scope?: HostScope;
89
+ marketplace?: Partial<MarketplaceRef>;
90
+ dryRun?: boolean;
91
+ cwd?: string;
92
+ }
93
+ export interface SyncPlanEntry {
94
+ host: HostId;
95
+ target: string;
96
+ argv: string[] | null;
97
+ note: string;
98
+ }
99
+ /**
100
+ * Pure sync planner. Marketplace first (add when absent, refresh when it is
101
+ * the canonical source, refuse a foreign source), then union-of-enabled installs.
102
+ */
103
+ export declare function planSync(states: Record<HostId, HostState>, mp: MarketplaceRef): SyncPlanEntry[];
104
+ export interface StatusRow {
105
+ plugin: string;
106
+ claude: HostPluginState | null;
107
+ codex: HostPluginState | null;
108
+ drift: string[];
109
+ }
110
+ export declare function computeStatus(states: Partial<Record<HostId, HostState>>): StatusRow[];
111
+ export declare class HostPluginManager {
112
+ private readonly deps;
113
+ constructor(deps?: HostSystemDeps);
114
+ private marketplace;
115
+ /** Resolve every requested host before anything mutates. */
116
+ resolveHosts(selection?: HostSelection): Promise<{
117
+ present: HostInvocation[];
118
+ missing: HostTargetResult[];
119
+ required: Set<HostId>;
120
+ }>;
121
+ private readState;
122
+ private execSteps;
123
+ /** install | update | uninstall | enable | disable on every selected host. */
124
+ apply(action: HostAction, rawPlugins: string[], opts?: HostOperationOptions): Promise<HostOperationReport>;
125
+ /** Make both hosts match: same marketplace, union of enabled plugins (additive). */
126
+ sync(opts?: HostOperationOptions): Promise<HostOperationReport & {
127
+ plan: SyncPlanEntry[];
128
+ }>;
129
+ /** Installed version per plugin per host, with drift flags. Read-only. */
130
+ status(opts?: HostOperationOptions): Promise<{
131
+ ok: boolean;
132
+ rows: StatusRow[];
133
+ hosts: HostTargetResult[];
134
+ marketplaces: Partial<Record<HostId, string | null>>;
135
+ }>;
136
+ }
137
+ //# sourceMappingURL=host-plugin-manager.d.ts.map