claude-flow 3.75.2 → 3.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/.proven-config-version +1 -0
- package/.claude/proven-config.json +42 -0
- package/node_modules/@claude-flow/plugin-agent-federation/package.json +16 -4
- package/node_modules/@claude-flow/security/README.md +43 -0
- package/node_modules/@claude-flow/security/package.json +23 -0
- package/package.json +2 -2
- package/v3/@claude-flow/cli/catalog-manifest.json +2 -2
- package/v3/@claude-flow/cli/dist/src/commands/hooks.js +1 -1
- package/v3/@claude-flow/cli/dist/src/init/helper-companions.js +64 -2
- package/v3/@claude-flow/cli/dist/src/init/settings-risk-scanner.js +16 -1
- package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +64 -6
- package/v3/@claude-flow/cli/dist/src/mcp-tools/metaharness-tools.js +1 -1
- package/v3/@claude-flow/cli/dist/src/mcp-tools/task-tools.js +9 -2
- package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.d.ts +2 -0
- package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +7 -3
- package/v3/@claude-flow/cli/dist/src/missions/schemas.d.ts +124 -124
- package/v3/@claude-flow/cli/dist/src/mods/command-registry/schema.d.ts +199 -199
- package/v3/@claude-flow/cli/dist/src/ruvector/centroid-router.d.ts +87 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/centroid-router.js +154 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/router-embedder.d.ts +2 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/router-embedder.js +7 -0
- package/v3/@claude-flow/cli/dist/src/services/distill-oracle.d.ts +1 -1
- package/v3/@claude-flow/cli/dist/src/services/distill-oracle.js +2 -2
- package/v3/@claude-flow/cli/dist/src/transfer/store/download.d.ts +10 -3
- package/v3/@claude-flow/cli/dist/src/transfer/store/download.js +33 -16
- package/v3/@claude-flow/cli/package.json +10 -6
- package/v3/@claude-flow/shared/README.md +39 -0
- package/v3/@claude-flow/shared/dist/core/config/schema.d.ts +114 -1516
- package/v3/@claude-flow/shared/dist/core/config/schema.js +4 -4
- package/v3/@claude-flow/shared/dist/core/config/validator.d.ts +2 -2
- package/v3/@claude-flow/shared/dist/core/config/validator.js +17 -3
- package/v3/@claude-flow/shared/package.json +25 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sha256:6141a8ea990c5063b77e090ae8f37f9c539d8aa8f58dcceb30f3a82f97e57319
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"adoptedAt": 1794403105197,
|
|
3
|
+
"championId": "sha256:6141a8ea990c5063b77e090ae8f37f9c539d8aa8f58dcceb30f3a82f97e57319",
|
|
4
|
+
"manifest": {
|
|
5
|
+
"schema": "ruflo.proven-config/v1",
|
|
6
|
+
"policy": {
|
|
7
|
+
"ref": "sha256:6141a8ea990c5063b77e090ae8f37f9c539d8aa8f58dcceb30f3a82f97e57319",
|
|
8
|
+
"value": {
|
|
9
|
+
"alpha": 0.3,
|
|
10
|
+
"subjectWeight": 1,
|
|
11
|
+
"mmrLambda": 0.5,
|
|
12
|
+
"bodyWeight": 1.5,
|
|
13
|
+
"typePenaltyFactor": 0.5
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"layer": "framework/node-cli",
|
|
17
|
+
"compatibility": {
|
|
18
|
+
"ruflo": ">=3.24.0"
|
|
19
|
+
},
|
|
20
|
+
"benchmark": {
|
|
21
|
+
"corpus": "ADR-081-labelled-v1",
|
|
22
|
+
"corpusHash": "sha256:2f700b5c363e20a3bd88ce2bc9b87bbbbaa61732c6177894c6ec37890f888982"
|
|
23
|
+
},
|
|
24
|
+
"receipt": {
|
|
25
|
+
"heldOutDelta": 0.07381404928570845,
|
|
26
|
+
"redblue": "PASS",
|
|
27
|
+
"drift": 0,
|
|
28
|
+
"canary": {
|
|
29
|
+
"rollbackRate": 0,
|
|
30
|
+
"latencyP95": 244.612458000076,
|
|
31
|
+
"costPerTask": 0
|
|
32
|
+
},
|
|
33
|
+
"receiptCoverage": 1
|
|
34
|
+
},
|
|
35
|
+
"platform": [
|
|
36
|
+
"linux",
|
|
37
|
+
"macOS",
|
|
38
|
+
"windows"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"previous": ""
|
|
42
|
+
}
|
|
@@ -2,7 +2,15 @@
|
|
|
2
2
|
"name": "@claude-flow/plugin-agent-federation",
|
|
3
3
|
"version": "1.0.7",
|
|
4
4
|
"description": "Cross-installation agent federation with zero-trust security, PII-gated data flow, and compliance-grade audit trails.",
|
|
5
|
-
"homepage": "https://
|
|
5
|
+
"homepage": "https://ruv.io",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/ruvnet/ruflo.git",
|
|
9
|
+
"directory": "v3/@claude-flow/plugin-agent-federation"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/ruvnet/ruflo/issues"
|
|
13
|
+
},
|
|
6
14
|
"type": "module",
|
|
7
15
|
"main": "dist/index.js",
|
|
8
16
|
"types": "dist/index.d.ts",
|
|
@@ -33,11 +41,15 @@
|
|
|
33
41
|
"keywords": [
|
|
34
42
|
"federation",
|
|
35
43
|
"multi-agent",
|
|
36
|
-
"
|
|
44
|
+
"ai-agents",
|
|
45
|
+
"zero-trust",
|
|
37
46
|
"pii",
|
|
38
47
|
"security",
|
|
39
|
-
"audit",
|
|
40
|
-
"compliance"
|
|
48
|
+
"audit-trail",
|
|
49
|
+
"compliance",
|
|
50
|
+
"claude-flow-plugin",
|
|
51
|
+
"claude-flow",
|
|
52
|
+
"ruflo"
|
|
41
53
|
],
|
|
42
54
|
"author": "Claude Flow Team",
|
|
43
55
|
"license": "MIT",
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/ruvnet/ruflo/main/docs/assets/readme/packages/security-boundary-quickstart.svg" alt="@claude-flow/security quickstart: a valid email passes, an invalid one is rejected with a ZodError, a bcrypt hash verifies, and a 48-character API key is generated." width="100%"></p>
|
|
2
|
+
|
|
1
3
|
# @claude-flow/security
|
|
2
4
|
|
|
5
|
+
**Security primitives for the system boundary of an agent app:** validate input, hash passwords, generate credentials, and block command injection and path traversal.
|
|
6
|
+
|
|
3
7
|
[](https://www.npmjs.com/package/@claude-flow/security)
|
|
4
8
|
[](https://www.npmjs.com/package/@claude-flow/security)
|
|
5
9
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -24,6 +28,45 @@
|
|
|
24
28
|
npm install @claude-flow/security
|
|
25
29
|
```
|
|
26
30
|
|
|
31
|
+
<!-- weaver:seo:quickstart -->
|
|
32
|
+
## Supported environments
|
|
33
|
+
|
|
34
|
+
- Node.js, ESM (`import`). The quickstart below was run on Node 22 (Linux x64).
|
|
35
|
+
- Pure JavaScript dependencies (`bcryptjs`, `zod`, `@noble/ed25519`). No native build step.
|
|
36
|
+
- Works standalone. The Ruflo CLI (`@claude-flow/cli`) isn't required.
|
|
37
|
+
|
|
38
|
+
## Quickstart (verified)
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install @claude-flow/security
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
// quickstart.mjs
|
|
46
|
+
import { InputValidator, EmailSchema, PasswordHasher, createCredentialGenerator } from '@claude-flow/security';
|
|
47
|
+
|
|
48
|
+
console.log('email ok:', InputValidator.validate(EmailSchema, 'user@example.com'));
|
|
49
|
+
try { InputValidator.validate(EmailSchema, 'not-an-email'); } catch (e) { console.log('rejected:', e.constructor.name); }
|
|
50
|
+
|
|
51
|
+
const hasher = new PasswordHasher({ rounds: 12 });
|
|
52
|
+
const hash = await hasher.hash('CorrectHorseBatteryStaple9');
|
|
53
|
+
console.log('hash prefix:', hash.slice(0, 7), 'verify:', await hasher.verify('CorrectHorseBatteryStaple9', hash));
|
|
54
|
+
|
|
55
|
+
const apiKey = createCredentialGenerator().generateApiKey('ck_live_');
|
|
56
|
+
console.log('api key prefix:', apiKey.key.slice(0, 8), 'length:', apiKey.key.length);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Expected output (`node quickstart.mjs`, @claude-flow/security 3.0.7):
|
|
60
|
+
|
|
61
|
+
```text
|
|
62
|
+
email ok: user@example.com
|
|
63
|
+
rejected: ZodError
|
|
64
|
+
hash prefix: $2b$12$ verify: true
|
|
65
|
+
api key prefix: ck_live_ length: 48
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Next:** add prompt-injection and jailbreak detection for LLM input with [`@claude-flow/aidefence`](https://www.npmjs.com/package/@claude-flow/aidefence).
|
|
69
|
+
|
|
27
70
|
## Standalone use (without the Ruflo CLI)
|
|
28
71
|
|
|
29
72
|
This is a plain library — every primitive (`PasswordHasher`,
|
|
@@ -3,6 +3,29 @@
|
|
|
3
3
|
"version": "3.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Security module - CVE fixes, input validation, path security",
|
|
6
|
+
"homepage": "https://ruv.io",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/ruvnet/ruflo.git",
|
|
10
|
+
"directory": "v3/@claude-flow/security"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/ruvnet/ruflo/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"security",
|
|
17
|
+
"input-validation",
|
|
18
|
+
"path-traversal",
|
|
19
|
+
"command-injection",
|
|
20
|
+
"password-hashing",
|
|
21
|
+
"bcrypt",
|
|
22
|
+
"credential-management",
|
|
23
|
+
"zod",
|
|
24
|
+
"ai-agents",
|
|
25
|
+
"claude-flow",
|
|
26
|
+
"ruflo",
|
|
27
|
+
"typescript"
|
|
28
|
+
],
|
|
6
29
|
"main": "dist/index.js",
|
|
7
30
|
"types": "dist/index.d.ts",
|
|
8
31
|
"files": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-flow",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.76.0",
|
|
4
4
|
"workspaces": [
|
|
5
5
|
"v3/@claude-flow/codex",
|
|
6
6
|
"v3/@claude-flow/mcp",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@claude-flow/neural": "3.0.3",
|
|
76
76
|
"@claude-flow/plugin-agent-federation": "1.0.7",
|
|
77
77
|
"@claude-flow/security": "3.0.7",
|
|
78
|
-
"@claude-flow/shared": "3.0.
|
|
78
|
+
"@claude-flow/shared": "3.0.8",
|
|
79
79
|
"@electron/asar": "^4.3.1",
|
|
80
80
|
"@iarna/toml": "^2.2.5",
|
|
81
81
|
"@noble/ed25519": "2.3.0",
|
|
@@ -600,7 +600,7 @@ const routeCommand = {
|
|
|
600
600
|
if (result.routing) {
|
|
601
601
|
output.writeln();
|
|
602
602
|
output.writeln(output.bold('Routing Method'));
|
|
603
|
-
const methodDisplay = result.routing.method.startsWith('semantic')
|
|
603
|
+
const methodDisplay = result.routing.method.startsWith('semantic') || result.routing.method === 'centroid'
|
|
604
604
|
? output.success(`${result.routing.method} (${result.routing.backend || 'semantic'})`)
|
|
605
605
|
: 'keyword';
|
|
606
606
|
output.printList([
|
|
@@ -12,9 +12,40 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import * as fs from 'fs';
|
|
14
14
|
import * as path from 'path';
|
|
15
|
+
import { randomUUID } from 'node:crypto';
|
|
15
16
|
export const COMMONJS_COMPANION_HELPERS = ['session.cjs', 'memory.cjs'];
|
|
17
|
+
/** Missing is distinct from unreadable, a symlink (including dangling), or another file type. */
|
|
18
|
+
function companionState(target) {
|
|
19
|
+
try {
|
|
20
|
+
const stat = fs.lstatSync(target);
|
|
21
|
+
return stat.isFile() && !stat.isSymbolicLink() ? 'regular' : 'unsafe';
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return error.code === 'ENOENT' ? 'missing' : 'unsafe';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** The project/user root can itself be an alias; its helper directories may not be links. */
|
|
28
|
+
function safeHelpersDirectory(helpersDir) {
|
|
29
|
+
try {
|
|
30
|
+
for (const directory of [path.dirname(helpersDir), helpersDir]) {
|
|
31
|
+
const stat = fs.lstatSync(directory);
|
|
32
|
+
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
16
41
|
export async function ensureCommonJsCompanions(helpersDir, force = false) {
|
|
17
|
-
|
|
42
|
+
helpersDir = path.resolve(helpersDir);
|
|
43
|
+
if (!safeHelpersDirectory(helpersDir))
|
|
44
|
+
return [];
|
|
45
|
+
const missing = COMMONJS_COMPANION_HELPERS.filter((name) => {
|
|
46
|
+
const state = companionState(path.join(helpersDir, name));
|
|
47
|
+
return state === 'missing' || (force && state === 'regular');
|
|
48
|
+
});
|
|
18
49
|
if (missing.length === 0)
|
|
19
50
|
return [];
|
|
20
51
|
const gen = await import('./helpers-generator.js');
|
|
@@ -24,11 +55,42 @@ export async function ensureCommonJsCompanions(helpersDir, force = false) {
|
|
|
24
55
|
};
|
|
25
56
|
const written = [];
|
|
26
57
|
for (const name of missing) {
|
|
58
|
+
const target = path.join(helpersDir, name);
|
|
59
|
+
const temporary = path.join(helpersDir, `.${name}.${randomUUID()}.tmp`);
|
|
60
|
+
let created = false;
|
|
27
61
|
try {
|
|
28
|
-
|
|
62
|
+
// The import above yields: recheck before writing, and again before publication.
|
|
63
|
+
if (!safeHelpersDirectory(helpersDir))
|
|
64
|
+
continue;
|
|
65
|
+
const state = companionState(target);
|
|
66
|
+
if (state === 'unsafe' || (!force && state === 'regular'))
|
|
67
|
+
continue;
|
|
68
|
+
const descriptor = fs.openSync(temporary, 'wx', 0o755);
|
|
69
|
+
created = true;
|
|
70
|
+
try {
|
|
71
|
+
fs.writeFileSync(descriptor, content[name](), { encoding: 'utf-8' });
|
|
72
|
+
fs.fchmodSync(descriptor, 0o755);
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
fs.closeSync(descriptor);
|
|
76
|
+
}
|
|
77
|
+
if (!safeHelpersDirectory(helpersDir))
|
|
78
|
+
continue;
|
|
79
|
+
const finalState = companionState(target);
|
|
80
|
+
if (finalState === 'unsafe' || (!force && finalState === 'regular'))
|
|
81
|
+
continue;
|
|
82
|
+
fs.renameSync(temporary, target);
|
|
29
83
|
written.push(name);
|
|
30
84
|
}
|
|
31
85
|
catch { /* best-effort: hook-handler degrades gracefully without it */ }
|
|
86
|
+
finally {
|
|
87
|
+
if (created) {
|
|
88
|
+
try {
|
|
89
|
+
fs.unlinkSync(temporary);
|
|
90
|
+
}
|
|
91
|
+
catch { /* renamed or already removed */ }
|
|
92
|
+
}
|
|
93
|
+
}
|
|
32
94
|
}
|
|
33
95
|
return written;
|
|
34
96
|
}
|
|
@@ -48,11 +48,26 @@ const STANDALONE_RISK_PATTERNS = [
|
|
|
48
48
|
/\bnc\s+-e\b/i,
|
|
49
49
|
/base64\s+(-d|--decode)\b/i,
|
|
50
50
|
];
|
|
51
|
+
// General-purpose scripting interpreters with the same GTFOBins-documented
|
|
52
|
+
// shell-breakout capability as `python`/`ruby`/`perl` (already in
|
|
53
|
+
// SHELL_EXEC_WORDS) — e.g. `node -e "require('child_process').execSync(...)"`
|
|
54
|
+
// — but deliberately NOT merged into SHELL_EXEC_WORDS: that array also
|
|
55
|
+
// drives scanCommandStringForRisk's downloader+shell-exec co-occurrence
|
|
56
|
+
// check on fixed hook *command strings*, where ruflo's own hooks
|
|
57
|
+
// legitimately invoke `node <script>` (see the dedicated "does not flag"
|
|
58
|
+
// cases in settings-risk-scanner.test.ts) and must stay exempt there. This
|
|
59
|
+
// array only ever feeds RISKY_PREAPPROVE_WORDS below, so it tightens
|
|
60
|
+
// scanAllowRuleForRisk's permissions.allow heuristic without touching
|
|
61
|
+
// scanCommandStringForRisk's already-correct behavior. `osascript`/`pwsh`
|
|
62
|
+
// are deliberately excluded: macOS/Windows-only and out of scope for this
|
|
63
|
+
// Linux-focused heuristic; `powershell` already has a dedicated, more
|
|
64
|
+
// precise detector (hasEncodedPowershell) rather than a blunt word match.
|
|
65
|
+
const INTERPRETER_WORDS = ['node', 'deno', 'bun', 'php'];
|
|
51
66
|
// Words a Bash allow-rule should never blanket-preapprove without a
|
|
52
67
|
// specific argument scope, even though they aren't "dangerous" on their
|
|
53
68
|
// own the way `rm`/`chmod` are — pre-approving them removes the human
|
|
54
69
|
// review step for exactly the commands download-and-execute attacks use.
|
|
55
|
-
const RISKY_PREAPPROVE_WORDS = [...DANGEROUS_COMMAND_WORDS, ...SHELL_EXEC_WORDS, ...DOWNLOADER_WORDS];
|
|
70
|
+
const RISKY_PREAPPROVE_WORDS = [...DANGEROUS_COMMAND_WORDS, ...SHELL_EXEC_WORDS, ...DOWNLOADER_WORDS, ...INTERPRETER_WORDS];
|
|
56
71
|
// Encoded PowerShell (`powershell[.exe] ... -e|-enc|-encodedcommand <payload>`),
|
|
57
72
|
// matched on whitespace-separated tokens in ONE linear pass. The earlier regex
|
|
58
73
|
// (`powershell\\s+(?:\\S+\\s+)*?-e...`) is quadratic on repeated "powershell "
|
|
@@ -14,7 +14,8 @@ import { commandRecordingDisabled, redactCommandForStorage } from '../services/c
|
|
|
14
14
|
import { checkCommandLoop, recordCommandOutcome } from './tool-loop-guardrail.js';
|
|
15
15
|
import { buildLearnedRoutingPatterns, } from '../services/learned-routing.js';
|
|
16
16
|
import { applyTypesafeRouting, getTypesafeRouter } from '../ruvector/typesafe-router.js';
|
|
17
|
-
import { DEFAULT_ROUTER_EMBEDDER, embedForRouter, resolveRouterEmbedder, } from '../ruvector/router-embedder.js';
|
|
17
|
+
import { DEFAULT_ROUTER_EMBEDDER, embedForRouter, resolveRouterEmbedder, routerEmbedderModel, } from '../ruvector/router-embedder.js';
|
|
18
|
+
import { ABSTAIN_LABEL, centroidRouterEnabled, classify, loadCentroidArtifact, resolveMargin, } from '../ruvector/centroid-router.js';
|
|
18
19
|
// Real vector search functions - lazy loaded to avoid circular imports
|
|
19
20
|
let searchEntriesFn = null;
|
|
20
21
|
/**
|
|
@@ -1172,6 +1173,7 @@ export const hooksRoute = {
|
|
|
1172
1173
|
complexity,
|
|
1173
1174
|
},
|
|
1174
1175
|
swarmRecommendation: agents.length > 2 ? { topology: 'hierarchical', agents, coordination: 'queen-led' } : null,
|
|
1176
|
+
...centroidBypassed(`AgentDB ${agentdbRoute.controller}`, agents[0]),
|
|
1175
1177
|
};
|
|
1176
1178
|
}
|
|
1177
1179
|
}
|
|
@@ -1220,6 +1222,7 @@ export const hooksRoute = {
|
|
|
1220
1222
|
},
|
|
1221
1223
|
swarmRecommendation: null,
|
|
1222
1224
|
learning: { source: suggestion.source, matchedKeywords: suggestion.matchedKeywords },
|
|
1225
|
+
...centroidBypassed('a persisted SONA pattern', suggestion.agent),
|
|
1223
1226
|
};
|
|
1224
1227
|
}
|
|
1225
1228
|
}
|
|
@@ -1236,6 +1239,37 @@ export const hooksRoute = {
|
|
|
1236
1239
|
* so the benchmark measures this local path. (Body kept at its original
|
|
1237
1240
|
* indentation to keep this refactor's diff small.)
|
|
1238
1241
|
*/
|
|
1242
|
+
/**
|
|
1243
|
+
* ADR-527 centroid routing for one query. Returns null when the flag is off.
|
|
1244
|
+
* Never throws: an unusable artifact or embedder comes back as `unavailable`.
|
|
1245
|
+
*/
|
|
1246
|
+
/**
|
|
1247
|
+
* ADR-527: learned routes (AgentDB, persisted SONA patterns) answer before the
|
|
1248
|
+
* centroid router. Say so under the flag, so a pilot's fallback rate counts them.
|
|
1249
|
+
*/
|
|
1250
|
+
function centroidBypassed(by, agent) {
|
|
1251
|
+
return centroidRouterEnabled()
|
|
1252
|
+
? { centroid: { status: 'bypassed', reason: `${by} answered before the centroid router`, baselineAgent: agent } }
|
|
1253
|
+
: {};
|
|
1254
|
+
}
|
|
1255
|
+
async function centroidRoute(queryText, task, baselineAgent) {
|
|
1256
|
+
if (!centroidRouterEnabled())
|
|
1257
|
+
return null;
|
|
1258
|
+
try {
|
|
1259
|
+
if (!hasRoutableText(task)) {
|
|
1260
|
+
return { status: 'unavailable', reason: 'task has no letters or digits', baselineAgent };
|
|
1261
|
+
}
|
|
1262
|
+
const { artifact, error } = loadCentroidArtifact();
|
|
1263
|
+
if (!artifact)
|
|
1264
|
+
return { status: 'unavailable', reason: error ?? 'centroid artifact unavailable', baselineAgent };
|
|
1265
|
+
const q = await embedForRouter([queryText], 'minilm');
|
|
1266
|
+
const d = classify(artifact, q.vectors[0], q.embedder, routerEmbedderModel(), resolveMargin(artifact));
|
|
1267
|
+
return { ...d, ...(d.status === 'unavailable' && q.reason ? { reason: `${d.reason}; ${q.reason}` } : {}), baselineAgent };
|
|
1268
|
+
}
|
|
1269
|
+
catch (err) {
|
|
1270
|
+
return { status: 'unavailable', reason: `centroid router failed: ${err instanceof Error ? err.message : String(err)}`, baselineAgent };
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1239
1273
|
async function routeTaskLocal(task, context, useSemanticRouter, embedderOverride) {
|
|
1240
1274
|
// Get router (tries native VectorDb first, falls back to pure JS)
|
|
1241
1275
|
let handle = useSemanticRouter
|
|
@@ -1346,6 +1380,27 @@ async function routeTaskLocal(task, context, useSemanticRouter, embedderOverride
|
|
|
1346
1380
|
noMatchDetail = suggestion.note ?? 'No pattern matched.';
|
|
1347
1381
|
}
|
|
1348
1382
|
}
|
|
1383
|
+
// ADR-527: opt-in nearest-centroid router. The current router's pick is
|
|
1384
|
+
// kept as `baselineAgent` so a pilot can compare the two on outcomes.
|
|
1385
|
+
const centroid = await centroidRoute(queryText, task, agents[0]);
|
|
1386
|
+
if (centroid?.status === 'decided') {
|
|
1387
|
+
if (centroid.label === ABSTAIN_LABEL) {
|
|
1388
|
+
noMatchDetail = `Centroid router: no agent fits (closest is "none", score ${centroid.score}).`;
|
|
1389
|
+
matchedPattern = 'centroid-abstain';
|
|
1390
|
+
confidence = NO_MATCH_CONFIDENCE; // #3567: a no-match ranks below every real match
|
|
1391
|
+
}
|
|
1392
|
+
else {
|
|
1393
|
+
agents = [centroid.label, ...agents.filter(a => a !== centroid.label)];
|
|
1394
|
+
// Cosine runs about 0.2-0.6 here, so a raw score could rank a real match
|
|
1395
|
+
// below a no-match (#3567). Rescale monotonically into (NO_MATCH, 1];
|
|
1396
|
+
// the raw cosine stays in `centroid.score`. Not a probability.
|
|
1397
|
+
confidence = Math.round((NO_MATCH_CONFIDENCE + 0.01 + (0.99 - NO_MATCH_CONFIDENCE) * Math.max(0, Math.min(1, centroid.score))) * 100) / 100;
|
|
1398
|
+
matchedPattern = `centroid:${centroid.label}`;
|
|
1399
|
+
noMatchDetail = null;
|
|
1400
|
+
}
|
|
1401
|
+
routingMethod = 'centroid';
|
|
1402
|
+
backendInfo = 'nearest centroid (MiniLM)';
|
|
1403
|
+
}
|
|
1349
1404
|
// Determine complexity
|
|
1350
1405
|
const taskLower = task.toLowerCase();
|
|
1351
1406
|
const complexity = taskLower.includes('complex') || taskLower.includes('architecture') || task.length > 200
|
|
@@ -1372,11 +1427,13 @@ async function routeTaskLocal(task, context, useSemanticRouter, embedderOverride
|
|
|
1372
1427
|
primaryAgent: {
|
|
1373
1428
|
type: agents[0],
|
|
1374
1429
|
confidence: Math.round(confidence * 100) / 100,
|
|
1375
|
-
reason: routingMethod
|
|
1376
|
-
? `
|
|
1377
|
-
:
|
|
1378
|
-
? `
|
|
1379
|
-
:
|
|
1430
|
+
reason: routingMethod === 'centroid' && noMatchDetail === null
|
|
1431
|
+
? `Nearest agent centroid (${Math.round(confidence * 100)}% cosine)`
|
|
1432
|
+
: routingMethod.startsWith('semantic')
|
|
1433
|
+
? `Semantic similarity to "${matchedPattern}" pattern (${Math.round(confidence * 100)}%)`
|
|
1434
|
+
: noMatchDetail !== null
|
|
1435
|
+
? `Nothing matched; default suggestion only. ${noMatchDetail}`
|
|
1436
|
+
: `Task contains keywords matching ${agents[0]} specialization`,
|
|
1380
1437
|
},
|
|
1381
1438
|
alternativeAgents: agents.slice(1).map((agent, i) => ({
|
|
1382
1439
|
type: agent,
|
|
@@ -1396,6 +1453,7 @@ async function routeTaskLocal(task, context, useSemanticRouter, embedderOverride
|
|
|
1396
1453
|
} : null,
|
|
1397
1454
|
// ADR-390: which embedder the semantic index + query used ('hash' when degraded).
|
|
1398
1455
|
embedder: handle.embedder,
|
|
1456
|
+
...(centroid ? { centroid } : {}),
|
|
1399
1457
|
...(handle.embedderReason ? { embedderReason: handle.embedderReason } : {}),
|
|
1400
1458
|
};
|
|
1401
1459
|
}
|
|
@@ -400,7 +400,7 @@ export const metaharnessTools = [
|
|
|
400
400
|
},
|
|
401
401
|
// ───────────────────────────────────────────────────────────────────────
|
|
402
402
|
// ADR-153 — @metaharness/darwin integration (3 tools).
|
|
403
|
-
// Backed by the separate `@metaharness/darwin@~0.
|
|
403
|
+
// Backed by the separate `@metaharness/darwin@~0.14.0` npm package, NOT
|
|
404
404
|
// the umbrella `metaharness`. Plugin scripts shell out via _darwin.mjs.
|
|
405
405
|
// Same {success, data, degraded, exitCode} contract.
|
|
406
406
|
// ───────────────────────────────────────────────────────────────────────
|
|
@@ -323,13 +323,15 @@ export const taskTools = [
|
|
|
323
323
|
task.completedAt = new Date().toISOString();
|
|
324
324
|
task.result = input.result || {};
|
|
325
325
|
saveTaskStore(store);
|
|
326
|
-
// Sync assigned agents back to idle and increment taskCount
|
|
326
|
+
// Sync assigned agents back to idle and increment taskCount. Credited only to a worker
|
|
327
|
+
// still holding this task, as task_update does, so completing a reopened task again
|
|
328
|
+
// (complete -> pending -> complete, no reassignment) never counts the same work twice.
|
|
327
329
|
updateAgents(task.assignedTo, (agent) => {
|
|
328
330
|
if (agent.currentTask === taskId) {
|
|
329
331
|
agent.status = 'idle';
|
|
330
332
|
agent.currentTask = null;
|
|
333
|
+
agent.taskCount = (agent.taskCount || 0) + 1;
|
|
331
334
|
}
|
|
332
|
-
agent.taskCount = (agent.taskCount || 0) + 1;
|
|
333
335
|
});
|
|
334
336
|
return {
|
|
335
337
|
taskId: task.taskId,
|
|
@@ -392,6 +394,11 @@ export const taskTools = [
|
|
|
392
394
|
if (newStatus === 'in_progress' && !task.startedAt) {
|
|
393
395
|
task.startedAt = new Date().toISOString();
|
|
394
396
|
}
|
|
397
|
+
// Reopening a finished task (completed/failed/cancelled -> pending/in_progress) makes it unfinished
|
|
398
|
+
// again, so it must not keep reporting the completedAt of the run that was undone.
|
|
399
|
+
if (newStatus === 'pending' || newStatus === 'in_progress') {
|
|
400
|
+
task.completedAt = null;
|
|
401
|
+
}
|
|
395
402
|
// A finished task frees its workers, as task_complete and task_cancel do; otherwise a worker
|
|
396
403
|
// whose task was finished through task_update stays `busy` forever, and a later task_complete
|
|
397
404
|
// returns early because the status already reads completed.
|
|
@@ -390,6 +390,8 @@ export declare function generateLocalEmbedding(text: string, options?: {
|
|
|
390
390
|
embedding: number[];
|
|
391
391
|
dimensions: number;
|
|
392
392
|
model: string;
|
|
393
|
+
/** Model id behind an onnx vector, when known (ADR-527). */
|
|
394
|
+
modelId?: string;
|
|
393
395
|
backend: 'onnx' | 'mock';
|
|
394
396
|
}>;
|
|
395
397
|
/**
|
|
@@ -2154,7 +2154,8 @@ async function loadLocalEmbeddingChain(verbose = false, startTime = Date.now())
|
|
|
2154
2154
|
loaded: true,
|
|
2155
2155
|
model: embedder,
|
|
2156
2156
|
tokenizer: null,
|
|
2157
|
-
dimensions: embCfg.dimension
|
|
2157
|
+
dimensions: embCfg.dimension,
|
|
2158
|
+
modelId: embCfg.model,
|
|
2158
2159
|
};
|
|
2159
2160
|
return {
|
|
2160
2161
|
success: true,
|
|
@@ -2189,7 +2190,8 @@ async function loadLocalEmbeddingChain(verbose = false, startTime = Date.now())
|
|
|
2189
2190
|
loaded: true,
|
|
2190
2191
|
model: (text) => reasoningBank.computeEmbedding(text),
|
|
2191
2192
|
tokenizer: null,
|
|
2192
|
-
dimensions: 384
|
|
2193
|
+
dimensions: 384,
|
|
2194
|
+
modelId: 'agentic-flow/all-MiniLM-L6-v2',
|
|
2193
2195
|
};
|
|
2194
2196
|
return {
|
|
2195
2197
|
success: true,
|
|
@@ -2219,7 +2221,8 @@ async function loadLocalEmbeddingChain(verbose = false, startTime = Date.now())
|
|
|
2219
2221
|
loaded: true,
|
|
2220
2222
|
model: (text) => onnxEmb.embed(text),
|
|
2221
2223
|
tokenizer: null,
|
|
2222
|
-
dimensions: probe.length || 384
|
|
2224
|
+
dimensions: probe.length || 384,
|
|
2225
|
+
modelId: 'ruvector/all-MiniLM-L6-v2',
|
|
2223
2226
|
};
|
|
2224
2227
|
return {
|
|
2225
2228
|
success: true,
|
|
@@ -2359,6 +2362,7 @@ export async function generateLocalEmbedding(text, options) {
|
|
|
2359
2362
|
embedding,
|
|
2360
2363
|
dimensions: embedding.length,
|
|
2361
2364
|
model: 'onnx',
|
|
2365
|
+
...(state.modelId ? { modelId: state.modelId } : {}),
|
|
2362
2366
|
backend: 'onnx'
|
|
2363
2367
|
};
|
|
2364
2368
|
}
|