claude-flow 3.48.0 → 3.49.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 (51) hide show
  1. package/.claude/.proven-config-version +1 -0
  2. package/.claude/helpers/hook-handler.cjs +7 -4
  3. package/.claude/helpers/memory.cjs +1 -1
  4. package/.claude/helpers/router.cjs +1 -1
  5. package/.claude/helpers/session.cjs +1 -1
  6. package/.claude/proven-config.json +42 -0
  7. package/.claude-plugin/marketplace.json +16 -1
  8. package/README.md +1 -53
  9. package/README.zh-CN.md +1 -53
  10. package/node_modules/@claude-flow/codex/package.json +1 -1
  11. package/node_modules/@claude-flow/security/dist/policy/engine.d.ts +2 -6
  12. package/node_modules/@claude-flow/security/dist/policy/engine.d.ts.map +1 -1
  13. package/node_modules/@claude-flow/security/dist/policy/engine.js +35 -1
  14. package/node_modules/@claude-flow/security/dist/policy/engine.js.map +1 -1
  15. package/node_modules/@claude-flow/security/dist/policy/types.d.ts +18 -0
  16. package/node_modules/@claude-flow/security/dist/policy/types.d.ts.map +1 -1
  17. package/node_modules/@claude-flow/security/package.json +1 -1
  18. package/package.json +2 -2
  19. package/v3/@claude-flow/cli/README.md +3 -53
  20. package/v3/@claude-flow/cli/catalog-manifest.json +4 -4
  21. package/v3/@claude-flow/cli/dist/src/commands/doctor.d.ts +19 -1
  22. package/v3/@claude-flow/cli/dist/src/commands/doctor.js +69 -8
  23. package/v3/@claude-flow/cli/dist/src/commands/hooks.js +7 -4
  24. package/v3/@claude-flow/cli/dist/src/commands/memory.js +30 -7
  25. package/v3/@claude-flow/cli/dist/src/commands/plugins.js +44 -7
  26. package/v3/@claude-flow/cli/dist/src/commands/policy.js +5 -2
  27. package/v3/@claude-flow/cli/dist/src/commands/session.js +128 -21
  28. package/v3/@claude-flow/cli/dist/src/commands/swarm.js +11 -11
  29. package/v3/@claude-flow/cli/dist/src/index.js +10 -1
  30. package/v3/@claude-flow/cli/dist/src/init/executor.js +11 -5
  31. package/v3/@claude-flow/cli/dist/src/init/helper-companions.d.ts +3 -0
  32. package/v3/@claude-flow/cli/dist/src/init/helper-companions.js +34 -0
  33. package/v3/@claude-flow/cli/dist/src/init/helper-integrity.d.ts +21 -0
  34. package/v3/@claude-flow/cli/dist/src/init/helper-integrity.js +62 -0
  35. package/v3/@claude-flow/cli/dist/src/init/helper-refresh.d.ts +18 -11
  36. package/v3/@claude-flow/cli/dist/src/init/helper-refresh.js +56 -13
  37. package/v3/@claude-flow/cli/dist/src/init/helpers-generator.js +10 -10
  38. package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.d.ts +16 -3
  39. package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +87 -14
  40. package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.d.ts +7 -0
  41. package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.js +43 -6
  42. package/v3/@claude-flow/cli/dist/src/mcp-tools/session-tools.d.ts +15 -0
  43. package/v3/@claude-flow/cli/dist/src/mcp-tools/session-tools.js +236 -50
  44. package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +6 -3
  45. package/v3/@claude-flow/cli/dist/src/plugins/manager.d.ts +37 -10
  46. package/v3/@claude-flow/cli/dist/src/plugins/manager.js +106 -20
  47. package/v3/@claude-flow/cli/dist/src/plugins/trust-policy.d.ts +61 -0
  48. package/v3/@claude-flow/cli/dist/src/plugins/trust-policy.js +84 -0
  49. package/v3/@claude-flow/cli/dist/src/services/policy-runtime.d.ts +6 -0
  50. package/v3/@claude-flow/cli/dist/src/services/policy-runtime.js +27 -2
  51. package/v3/@claude-flow/cli/package.json +2 -2
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Plugin install trust policy (#3557).
3
+ *
4
+ * `plugins install --verify` used to be parsed and never read, and a plugin's
5
+ * declared `trustLevel`/`permissions` were neither recorded nor enforced.
6
+ * These pure helpers decide what an install may register.
7
+ */
8
+ /**
9
+ * Permissions a plugin may declare and still have its hooks and commands
10
+ * registered without `--trust`. Anything else (filesystem, network, shell,
11
+ * secrets, config, privileged, …) needs an explicit `--trust`.
12
+ */
13
+ export declare const DEFAULT_PLUGIN_PERMISSIONS: readonly string[];
14
+ /** Trust levels that are withheld unless the user passes `--trust`. */
15
+ export declare const UNTRUSTED_TRUST_LEVELS: readonly string[];
16
+ /** Registry trust levels that the registry itself vouches for. */
17
+ export declare const REGISTRY_VOUCHED_TRUST_LEVELS: readonly string[];
18
+ export interface DeclaredTrust {
19
+ trustLevel?: string;
20
+ permissions: string[];
21
+ }
22
+ export interface TrustDecision {
23
+ /** Hooks and commands may be registered. */
24
+ allowed: boolean;
25
+ /** Verification was skipped with `--no-verify`. */
26
+ verificationSkipped: boolean;
27
+ /** Why registration was withheld (empty when allowed). */
28
+ reasons: string[];
29
+ /** Declared permissions outside {@link DEFAULT_PLUGIN_PERMISSIONS}. */
30
+ excessPermissions: string[];
31
+ }
32
+ export interface TrustOptions {
33
+ /** `--verify` (default true). */
34
+ verify: boolean;
35
+ /** `--trust` (default false). */
36
+ trust: boolean;
37
+ /** Trust level from a registry entry, when the plugin was found there. */
38
+ registryTrustLevel?: string;
39
+ }
40
+ /**
41
+ * Read the trust declaration from a plugin's package.json. The `claude-flow`
42
+ * block wins; top-level fields are accepted as a fallback.
43
+ */
44
+ export declare function readDeclaredTrust(pkg: Record<string, unknown>): DeclaredTrust;
45
+ /** Decide whether an install may register the plugin's hooks and commands. */
46
+ export declare function evaluatePluginTrust(declared: DeclaredTrust, opts: TrustOptions): TrustDecision;
47
+ /**
48
+ * Whether npm may run the package's lifecycle scripts (preinstall/install/
49
+ * postinstall, and those of its dependencies). Scripts execute before the
50
+ * package's own trust declaration can be read, so only an explicit `--trust`
51
+ * or a registry-vouched entry allows them; everything else installs with
52
+ * `--ignore-scripts`.
53
+ */
54
+ export declare function shouldRunInstallScripts(opts: {
55
+ trust?: boolean;
56
+ registryTrustLevel?: string;
57
+ }): boolean;
58
+ /** A registry checksum we can actually verify: `sha256:` + 64 hex chars. */
59
+ export declare function parseSha256Checksum(checksum: unknown): string | null;
60
+ export declare function sha256Hex(data: Buffer): string;
61
+ //# sourceMappingURL=trust-policy.d.ts.map
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Plugin install trust policy (#3557).
3
+ *
4
+ * `plugins install --verify` used to be parsed and never read, and a plugin's
5
+ * declared `trustLevel`/`permissions` were neither recorded nor enforced.
6
+ * These pure helpers decide what an install may register.
7
+ */
8
+ import { createHash } from 'crypto';
9
+ /**
10
+ * Permissions a plugin may declare and still have its hooks and commands
11
+ * registered without `--trust`. Anything else (filesystem, network, shell,
12
+ * secrets, config, privileged, …) needs an explicit `--trust`.
13
+ */
14
+ export const DEFAULT_PLUGIN_PERMISSIONS = Object.freeze(['memory:read']);
15
+ /** Trust levels that are withheld unless the user passes `--trust`. */
16
+ export const UNTRUSTED_TRUST_LEVELS = Object.freeze(['untrusted', 'unverified']);
17
+ /** Registry trust levels that the registry itself vouches for. */
18
+ export const REGISTRY_VOUCHED_TRUST_LEVELS = Object.freeze(['official', 'verified']);
19
+ function asStringList(value) {
20
+ if (!Array.isArray(value))
21
+ return [];
22
+ return value.filter((v) => typeof v === 'string' && v.trim() !== '').map((v) => v.trim());
23
+ }
24
+ /**
25
+ * Read the trust declaration from a plugin's package.json. The `claude-flow`
26
+ * block wins; top-level fields are accepted as a fallback.
27
+ */
28
+ export function readDeclaredTrust(pkg) {
29
+ const block = (pkg['claude-flow'] && typeof pkg['claude-flow'] === 'object'
30
+ ? pkg['claude-flow']
31
+ : {});
32
+ const trustLevel = typeof block.trustLevel === 'string'
33
+ ? block.trustLevel
34
+ : typeof pkg.trustLevel === 'string' ? pkg.trustLevel : undefined;
35
+ const permissions = asStringList(block.permissions).length > 0
36
+ ? asStringList(block.permissions)
37
+ : asStringList(pkg.permissions);
38
+ return { trustLevel, permissions };
39
+ }
40
+ /** Decide whether an install may register the plugin's hooks and commands. */
41
+ export function evaluatePluginTrust(declared, opts) {
42
+ const excessPermissions = declared.permissions.filter((p) => !DEFAULT_PLUGIN_PERMISSIONS.includes(p));
43
+ if (!opts.verify) {
44
+ return { allowed: true, verificationSkipped: true, reasons: [], excessPermissions };
45
+ }
46
+ const reasons = [];
47
+ const registryVouched = opts.registryTrustLevel !== undefined
48
+ && REGISTRY_VOUCHED_TRUST_LEVELS.includes(opts.registryTrustLevel);
49
+ if (!registryVouched) {
50
+ if (declared.trustLevel && UNTRUSTED_TRUST_LEVELS.includes(declared.trustLevel)) {
51
+ reasons.push(`declares trustLevel "${declared.trustLevel}"`);
52
+ }
53
+ if (excessPermissions.length > 0) {
54
+ reasons.push(`declares permissions beyond the default set (${DEFAULT_PLUGIN_PERMISSIONS.join(', ')}): ${excessPermissions.join(', ')}`);
55
+ }
56
+ }
57
+ if (reasons.length > 0 && !opts.trust) {
58
+ return { allowed: false, verificationSkipped: false, reasons, excessPermissions };
59
+ }
60
+ return { allowed: true, verificationSkipped: false, reasons: [], excessPermissions };
61
+ }
62
+ /**
63
+ * Whether npm may run the package's lifecycle scripts (preinstall/install/
64
+ * postinstall, and those of its dependencies). Scripts execute before the
65
+ * package's own trust declaration can be read, so only an explicit `--trust`
66
+ * or a registry-vouched entry allows them; everything else installs with
67
+ * `--ignore-scripts`.
68
+ */
69
+ export function shouldRunInstallScripts(opts) {
70
+ if (opts.trust === true)
71
+ return true;
72
+ return opts.registryTrustLevel !== undefined && REGISTRY_VOUCHED_TRUST_LEVELS.includes(opts.registryTrustLevel);
73
+ }
74
+ /** A registry checksum we can actually verify: `sha256:` + 64 hex chars. */
75
+ export function parseSha256Checksum(checksum) {
76
+ if (typeof checksum !== 'string')
77
+ return null;
78
+ const m = /^sha256:([0-9a-f]{64})$/i.exec(checksum.trim());
79
+ return m ? m[1].toLowerCase() : null;
80
+ }
81
+ export function sha256Hex(data) {
82
+ return createHash('sha256').update(data).digest('hex');
83
+ }
84
+ //# sourceMappingURL=trust-policy.js.map
@@ -17,6 +17,12 @@ export declare function issuePolicyApproval(approval: Omit<PolicyApproval, 'uses
17
17
  issuedAt?: number;
18
18
  }, projectRoot?: string, approvalIssuerVerifier?: (issuer: string) => boolean): Promise<PolicyApproval>;
19
19
  export declare function revokePolicyApproval(id: string, projectRoot?: string): Promise<boolean>;
20
+ /**
21
+ * Read-only verification (#3568). It must not run inside
22
+ * `withPolicyTransaction`, whose own post-operation check throws a generic
23
+ * `policy-ledger-verification-failed` and hides which check failed. The only
24
+ * write is persisting an anchor established for a pre-anchor ledger.
25
+ */
20
26
  export declare function verifyPolicyLedger(projectRoot?: string): Promise<ReturnType<AgenticPolicyEngine['verifyLedger']>>;
21
27
  export declare function authorizeMcpTool(toolName: string, input: Record<string, unknown>, context?: Record<string, unknown>, attributes?: Readonly<{
22
28
  actionType?: string;
@@ -338,9 +338,12 @@ export async function withPolicyTransaction(projectRoot, operation, options = {}
338
338
  approvalIssuerVerifier: options.approvalIssuerVerifier,
339
339
  });
340
340
  const result = await operation(engine);
341
- const nextState = engine.exportState();
341
+ // Verify before exporting: verification establishes the ledger anchor
342
+ // (#3568) on state written before the anchor existed, and that anchor
343
+ // must be part of what is persisted.
342
344
  if (!engine.verifyLedger().valid)
343
345
  throw new Error('policy-ledger-verification-failed');
346
+ const nextState = engine.exportState();
344
347
  await writePolicyState(projectRoot, target.state, nextState);
345
348
  return result;
346
349
  }
@@ -393,8 +396,30 @@ export async function issuePolicyApproval(approval, projectRoot = process.cwd(),
393
396
  export async function revokePolicyApproval(id, projectRoot = process.cwd()) {
394
397
  return withPolicyTransaction(projectRoot, (engine) => engine.revokeApproval(id));
395
398
  }
399
+ /**
400
+ * Read-only verification (#3568). It must not run inside
401
+ * `withPolicyTransaction`, whose own post-operation check throws a generic
402
+ * `policy-ledger-verification-failed` and hides which check failed. The only
403
+ * write is persisting an anchor established for a pre-anchor ledger.
404
+ */
396
405
  export async function verifyPolicyLedger(projectRoot = process.cwd()) {
397
- return withPolicyTransaction(projectRoot, (engine) => engine.verifyLedger());
406
+ const target = paths(projectRoot);
407
+ mkdirSync(target.dir, { recursive: true, mode: 0o700 });
408
+ const release = await acquireLock(target.lock);
409
+ try {
410
+ const engine = AgenticPolicyEngine.fromState(loadPolicyState(projectRoot), {
411
+ signingKey: process.env.CLAUDE_FLOW_POLICY_SIGNING_KEY,
412
+ keyId: process.env.CLAUDE_FLOW_POLICY_KEY_ID,
413
+ });
414
+ const result = engine.verifyLedger();
415
+ if (result.anchor === 'established-now') {
416
+ await writePolicyState(projectRoot, target.state, engine.exportState());
417
+ }
418
+ return result;
419
+ }
420
+ finally {
421
+ release();
422
+ }
398
423
  }
399
424
  /**
400
425
  * Resolve the caller identity for `authorizeMcpTool`.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claude-flow/cli",
3
- "version": "3.48.0",
3
+ "version": "3.49.0",
4
4
  "type": "module",
5
5
  "description": "Ruflo CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
6
6
  "main": "dist/src/index.js",
@@ -103,7 +103,7 @@
103
103
  "@claude-flow/mcp": "3.0.0",
104
104
  "@claude-flow/neural": "3.0.0",
105
105
  "@claude-flow/plugin-agent-federation": "1.0.0",
106
- "@claude-flow/security": "3.0.0",
106
+ "@claude-flow/security": "3.0.1",
107
107
  "@claude-flow/shared": "3.0.0",
108
108
  "@iarna/toml": "^2.2.5",
109
109
  "@noble/ed25519": "2.3.0",