@claude-flow/cli 3.32.0 → 3.32.2
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/helpers/.helpers-version +1 -1
- package/.claude/helpers/helpers.manifest.json +3 -3
- package/.claude/helpers/statusline.cjs +38 -31
- package/.claude/helpers/statusline.js +19 -31
- package/catalog-manifest.json +2 -2
- package/dist/src/commands/hooks.js +20 -9
- package/dist/src/commands/init.d.ts +5 -0
- package/dist/src/commands/init.js +30 -1
- package/dist/src/commands/security.js +16 -11
- package/dist/src/funnel/insights.d.ts +1 -0
- package/dist/src/funnel/insights.js +4 -4
- package/dist/src/funnel/local-signals.d.ts +6 -1
- package/dist/src/funnel/local-signals.js +29 -20
- package/dist/src/init/executor.js +2 -2
- package/dist/src/mcp-tools/hooks-tools.js +13 -1
- package/dist/src/security/builtin-aidefence.d.ts +34 -0
- package/dist/src/security/builtin-aidefence.js +86 -0
- package/dist/src/services/fable-harness.d.ts +1 -0
- package/package.json +9 -8
- package/plugins/ruflo-metaharness/.claude-plugin/plugin.json +1 -1
- package/plugins/ruflo-metaharness/scripts/smoke.sh +15 -12
- package/plugins/ruflo-metaharness/skills/harness-similarity/SKILL.md +1 -1
- package/.claude/.proven-config-version +0 -1
- package/.claude/proven-config.json +0 -42
- package/dist/src/ruvector/flash-attention.d.ts +0 -195
- package/dist/src/ruvector/flash-attention.js +0 -643
- package/dist/src/ruvector/moe-router.d.ts +0 -206
- package/dist/src/ruvector/moe-router.js +0 -626
- package/dist/src/services/event-stream.d.ts +0 -25
- package/dist/src/services/event-stream.js +0 -27
- package/dist/src/services/loop-worker-runner.d.ts +0 -16
- package/dist/src/services/loop-worker-runner.js +0 -34
- package/dist/src/services/runtime-capabilities.d.ts +0 -22
- package/dist/src/services/runtime-capabilities.js +0 -45
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
const THREAT_PATTERNS = [
|
|
3
|
+
{
|
|
4
|
+
type: 'prompt-injection',
|
|
5
|
+
severity: 'high',
|
|
6
|
+
confidence: 0.96,
|
|
7
|
+
description: 'Attempts to override or discard trusted instructions',
|
|
8
|
+
pattern: /\b(?:ignore|disregard|forget|override)\b[\s\S]{0,40}\b(?:previous|prior|system|developer|trusted)\b[\s\S]{0,24}\b(?:instructions?|prompts?|rules?|messages?)\b/i,
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
type: 'system-prompt-extraction',
|
|
12
|
+
severity: 'high',
|
|
13
|
+
confidence: 0.94,
|
|
14
|
+
description: 'Attempts to reveal hidden system or developer instructions',
|
|
15
|
+
pattern: /\b(?:reveal|show|print|repeat|dump|expose)\b[\s\S]{0,32}\b(?:system|developer|hidden|initial)\b[\s\S]{0,20}\b(?:prompt|message|instructions?)\b/i,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
type: 'jailbreak',
|
|
19
|
+
severity: 'high',
|
|
20
|
+
confidence: 0.91,
|
|
21
|
+
description: 'Attempts to bypass model safeguards or enter an unrestricted mode',
|
|
22
|
+
pattern: /\b(?:developer mode|DAN mode|jailbreak|bypass (?:all )?(?:safeguards|restrictions|filters)|unrestricted mode)\b/i,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
type: 'data-exfiltration',
|
|
26
|
+
severity: 'critical',
|
|
27
|
+
confidence: 0.93,
|
|
28
|
+
description: 'Attempts to transmit secrets or credentials to an external destination',
|
|
29
|
+
pattern: /\b(?:send|upload|post|exfiltrate|transmit)\b[\s\S]{0,48}\b(?:secret|credential|password|api key|token|private key)\b/i,
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
const PII_PATTERNS = [
|
|
33
|
+
/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i,
|
|
34
|
+
/\b\d{3}-\d{2}-\d{4}\b/,
|
|
35
|
+
/\b(?:sk-|ghp_|xox[baprs]-)[A-Za-z0-9_-]{16,}\b/,
|
|
36
|
+
/\bAKIA[A-Z0-9]{16}\b/,
|
|
37
|
+
];
|
|
38
|
+
export function createBuiltinAIDefence() {
|
|
39
|
+
let detectionCount = 0;
|
|
40
|
+
let totalDetectionTimeMs = 0;
|
|
41
|
+
const scan = (input) => THREAT_PATTERNS
|
|
42
|
+
.filter(({ pattern }) => pattern.test(input))
|
|
43
|
+
.map(({ pattern: _pattern, ...threat }) => threat);
|
|
44
|
+
return {
|
|
45
|
+
async detect(input) {
|
|
46
|
+
const startedAt = performance.now();
|
|
47
|
+
const threats = scan(input);
|
|
48
|
+
const piiFound = PII_PATTERNS.some((pattern) => pattern.test(input));
|
|
49
|
+
const detectionTimeMs = performance.now() - startedAt;
|
|
50
|
+
detectionCount++;
|
|
51
|
+
totalDetectionTimeMs += detectionTimeMs;
|
|
52
|
+
return {
|
|
53
|
+
safe: threats.length === 0 && !piiFound,
|
|
54
|
+
threats,
|
|
55
|
+
piiFound,
|
|
56
|
+
detectionTimeMs,
|
|
57
|
+
inputHash: createHash('sha256').update(input).digest('hex'),
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
quickScan(input) {
|
|
61
|
+
const threat = scan(input)[0];
|
|
62
|
+
return threat
|
|
63
|
+
? { threat: true, confidence: threat.confidence, type: threat.type }
|
|
64
|
+
: { threat: false, confidence: 0 };
|
|
65
|
+
},
|
|
66
|
+
async getStats() {
|
|
67
|
+
return {
|
|
68
|
+
detectionCount,
|
|
69
|
+
avgDetectionTimeMs: detectionCount === 0 ? 0 : totalDetectionTimeMs / detectionCount,
|
|
70
|
+
learnedPatterns: 0,
|
|
71
|
+
mitigationStrategies: 4,
|
|
72
|
+
avgMitigationEffectiveness: 0.9,
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
async getBestMitigation(type) {
|
|
76
|
+
const strategies = {
|
|
77
|
+
'prompt-injection': 'Keep trusted instructions immutable and reject instruction overrides',
|
|
78
|
+
'system-prompt-extraction': 'Do not disclose system or developer messages',
|
|
79
|
+
jailbreak: 'Apply the configured policy without adopting alternate personas',
|
|
80
|
+
'data-exfiltration': 'Block external transmission and rotate exposed credentials',
|
|
81
|
+
};
|
|
82
|
+
return strategies[type] ? { strategy: strategies[type], effectiveness: 0.9 } : null;
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=builtin-aidefence.js.map
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claude-flow/cli",
|
|
3
|
-
"version": "3.32.
|
|
3
|
+
"version": "3.32.2",
|
|
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",
|
|
7
7
|
"types": "dist/src/index.d.ts",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"bin": {
|
|
10
|
-
"cli": "
|
|
11
|
-
"claude-flow": "
|
|
12
|
-
"claude-flow-mcp": "
|
|
10
|
+
"cli": "bin/cli.js",
|
|
11
|
+
"claude-flow": "bin/cli.js",
|
|
12
|
+
"claude-flow-mcp": "bin/mcp-server.js"
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://github.com/ruvnet/claude-flow#readme",
|
|
15
15
|
"bugs": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "https://github.com/ruvnet/claude-flow.git",
|
|
20
|
+
"url": "git+https://github.com/ruvnet/claude-flow.git",
|
|
21
21
|
"directory": "v3/@claude-flow/cli"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [
|
|
@@ -90,8 +90,9 @@
|
|
|
90
90
|
"test:plugin-store": "npx tsx src/plugins/tests/standalone-test.ts",
|
|
91
91
|
"test:pattern-store": "npx tsx src/transfer/store/tests/standalone-test.ts",
|
|
92
92
|
"postinstall": "node ./scripts/postinstall.cjs",
|
|
93
|
-
"prepublishOnly": "
|
|
94
|
-
"release": "npm
|
|
93
|
+
"prepublishOnly": "node scripts/prepare-publish.mjs",
|
|
94
|
+
"release": "npm publish --access public --tag latest",
|
|
95
|
+
"release:alpha": "npm version prerelease --preid=alpha && npm run publish:all",
|
|
95
96
|
"publish:all": "./scripts/publish.sh"
|
|
96
97
|
},
|
|
97
98
|
"devDependencies": {
|
|
@@ -110,7 +111,7 @@
|
|
|
110
111
|
"yaml": "^2.8.0"
|
|
111
112
|
},
|
|
112
113
|
"optionalDependencies": {
|
|
113
|
-
"@claude-flow/memory": "^3.0.0-alpha.21",
|
|
114
|
+
"@claude-flow/memory": "^3.0.0-alpha.21",
|
|
114
115
|
"@claude-flow/security": "^3.0.0-alpha.10",
|
|
115
116
|
"agentdb": "^3.0.0-alpha.17",
|
|
116
117
|
"agentic-flow": "^3.0.0-alpha.1",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ruflo-metaharness",
|
|
3
3
|
"description": "MetaHarness integration for ruflo — surfaces score/genome/mint/mcp-scan/threat-model via skills; pairs with @metaharness/router (ADR-148/149) for cost-optimal model routing; honors ADR-150's architectural constraint that MetaHarness remains an optional augmentation, never a required runtime dependency",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "ruvnet",
|
|
7
7
|
"url": "https://github.com/ruvnet"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# Structural smoke test for ruflo-metaharness v0.1.
|
|
2
|
+
# Structural smoke test for ruflo-metaharness v0.1.1 (ADR-150 Phase 1).
|
|
3
3
|
set -u
|
|
4
4
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
5
5
|
PASS=0
|
|
@@ -31,10 +31,10 @@ else
|
|
|
31
31
|
bad "extraction-regex-rot: EXPECTED_TOOLS=$EXPECTED_TOOLS EXPECTED_SUBS=$EXPECTED_SUBS"
|
|
32
32
|
fi
|
|
33
33
|
|
|
34
|
-
step "1. plugin.json declares 0.1.
|
|
34
|
+
step "1. plugin.json declares 0.1.1 with adr-150 keywords"
|
|
35
35
|
v=$(grep -E '"version"' "$ROOT/.claude-plugin/plugin.json" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
|
|
36
|
-
if [[ "$v" != "0.1.
|
|
37
|
-
bad "expected 0.1.
|
|
36
|
+
if [[ "$v" != "0.1.1" ]]; then
|
|
37
|
+
bad "expected 0.1.1, got '$v'"
|
|
38
38
|
else
|
|
39
39
|
miss=""
|
|
40
40
|
for k in ruflo metaharness harness scorecard genome mcp-scan threat-model router adr-150 adr-148 adr-149 optional-dependency graceful-degradation subprocess phase-1-mvp; do
|
|
@@ -799,8 +799,8 @@ TOOLS=$(grep -oE "name: 'metaharness_[a-z_]+'" "$WRAPPER" 2>/dev/null \
|
|
|
799
799
|
COUNT=0
|
|
800
800
|
for t in $TOOLS; do
|
|
801
801
|
COUNT=$((COUNT + 1))
|
|
802
|
-
#
|
|
803
|
-
grep -q "mcp__claude-flow__${t}" "$CMD" 2>/dev/null \
|
|
802
|
+
# audit-allow: standalone-mcp-prefix — this checks the repository CLAUDE.md, not a plugin skill.
|
|
803
|
+
grep -q "mcp__claude-flow__${t}" "$CMD" 2>/dev/null \
|
|
804
804
|
|| miss="$miss ${t}-not-in-claude-md"
|
|
805
805
|
done
|
|
806
806
|
# Count derived from the wrapper source (mint deliberately excluded — see
|
|
@@ -1520,8 +1520,9 @@ grep -q "name: 'metaharness_drift_from_history'" "$WRAPPER" 2>/dev/null || miss=
|
|
|
1520
1520
|
grep -q "drift-from-history.mjs" "$WRAPPER" 2>/dev/null || miss="$miss no-script-dispatch"
|
|
1521
1521
|
grep -q "baselineSince" "$WRAPPER" 2>/dev/null || miss="$miss no-baseline-since-input"
|
|
1522
1522
|
# CLAUDE.md mentions both surfaces
|
|
1523
|
-
CMD="$ROOT/../../CLAUDE.md"
|
|
1524
|
-
|
|
1523
|
+
CMD="$ROOT/../../CLAUDE.md"
|
|
1524
|
+
# audit-allow: standalone-mcp-prefix — this checks the repository CLAUDE.md, not a plugin skill.
|
|
1525
|
+
grep -q "mcp__claude-flow__metaharness_drift_from_history" "$CMD" 2>/dev/null || miss="$miss claude-md-no-mcp"
|
|
1525
1526
|
grep -q "ruflo metaharness drift-from-history" "$CMD" 2>/dev/null || miss="$miss claude-md-no-subcommand"
|
|
1526
1527
|
# Phase 4 includes the new positive-case assertions
|
|
1527
1528
|
T="$ROOT/scripts/test-mcp-tools.mjs"
|
|
@@ -1805,8 +1806,9 @@ grep -q "audit-trend structural-distance integration" "$F" 2>/dev/null || miss="
|
|
|
1805
1806
|
grep -q "Graceful fallback when fingerprint missing" "$F" 2>/dev/null || miss="$miss no-fallback-step"
|
|
1806
1807
|
grep -q "Distance alert gate exits 1" "$F" 2>/dev/null || miss="$miss no-alert-step"
|
|
1807
1808
|
# CLAUDE.md documents the new MCP tool + subcommand
|
|
1808
|
-
CMD="$ROOT/../../CLAUDE.md"
|
|
1809
|
-
|
|
1809
|
+
CMD="$ROOT/../../CLAUDE.md"
|
|
1810
|
+
# audit-allow: standalone-mcp-prefix — this checks the repository CLAUDE.md, not a plugin skill.
|
|
1811
|
+
grep -q "mcp__claude-flow__metaharness_similarity" "$CMD" 2>/dev/null || miss="$miss claude-md-no-mcp-tool"
|
|
1810
1812
|
grep -q "ruflo metaharness similarity" "$CMD" 2>/dev/null || miss="$miss claude-md-no-subcommand"
|
|
1811
1813
|
grep -q -- "--alert-on-distance-below" "$CMD" 2>/dev/null || miss="$miss claude-md-no-distance-flag"
|
|
1812
1814
|
[[ -z "$miss" ]] && ok || bad "$miss"
|
|
@@ -2122,8 +2124,9 @@ grep -q "Ruflo remains operational if every MetaHarness package is removed" "$F"
|
|
|
2122
2124
|
# All 4 rules documented
|
|
2123
2125
|
grep -q "no-metaharness-smoke.yml" "$F" || miss="$miss no-ci-gate-ref"
|
|
2124
2126
|
# Command surface + tool surface enumerated
|
|
2125
|
-
grep -q "npx ruflo metaharness score" "$F" || miss="$miss no-cli-example"
|
|
2126
|
-
|
|
2127
|
+
grep -q "npx ruflo metaharness score" "$F" || miss="$miss no-cli-example"
|
|
2128
|
+
# audit-allow: standalone-mcp-prefix — this checks the repository CLAUDE.md, not a plugin skill.
|
|
2129
|
+
grep -q "mcp__claude-flow__metaharness_" "$F" || miss="$miss no-mcp-tool-list"
|
|
2127
2130
|
# Routing + parallel-log integration both mentioned
|
|
2128
2131
|
grep -q "CLAUDE_FLOW_ROUTER_NEURAL\|CLAUDE_FLOW_ROUTER_PARALLEL_LOG" "$F" || miss="$miss no-routing-flags"
|
|
2129
2132
|
# 3-criteria gate
|
|
@@ -63,5 +63,5 @@ npx ruflo metaharness similarity --a a.json --b b.json --alert-below 0.5
|
|
|
63
63
|
|
|
64
64
|
Production module: [`scripts/_similarity.mjs`](../../scripts/_similarity.mjs)
|
|
65
65
|
CLI skill: [`scripts/similarity.mjs`](../../scripts/similarity.mjs)
|
|
66
|
-
MCP tool: `
|
|
66
|
+
MCP tool: `mcp__plugin_ruflo-core_ruflo__metaharness_similarity` (registered in `v3/@claude-flow/cli/src/mcp-tools/metaharness-tools.ts`)
|
|
67
67
|
Spike anchor: [`scripts/_spike-similarity.mjs`](../../scripts/_spike-similarity.mjs) (regression suite — invariants locked here)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
sha256:6141a8ea990c5063b77e090ae8f37f9c539d8aa8f58dcceb30f3a82f97e57319
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"adoptedAt": 1784038945014,
|
|
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
|
-
}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flash Attention Implementation for RuVector Intelligence System
|
|
3
|
-
*
|
|
4
|
-
* Implements block-wise attention computation for faster similarity calculations.
|
|
5
|
-
* Achieves O(N) memory instead of O(N^2) through tiling strategy.
|
|
6
|
-
*
|
|
7
|
-
* Key optimizations:
|
|
8
|
-
* - Block-wise computation to fit in L1 cache
|
|
9
|
-
* - Fused softmax-matmul operations
|
|
10
|
-
* - Float32Array for all operations
|
|
11
|
-
* - Online softmax for numerical stability
|
|
12
|
-
*
|
|
13
|
-
* Target: 2-5x speedup on CPU vs naive attention
|
|
14
|
-
*
|
|
15
|
-
* Created with love by ruv.io
|
|
16
|
-
*/
|
|
17
|
-
export interface FlashAttentionConfig {
|
|
18
|
-
/** Block size for tiling (32-64 optimal for CPU L1 cache) */
|
|
19
|
-
blockSize: number;
|
|
20
|
-
/** Number of dimensions in embedding vectors */
|
|
21
|
-
dimensions: number;
|
|
22
|
-
/** Temperature for softmax scaling */
|
|
23
|
-
temperature: number;
|
|
24
|
-
/** Enable numerical stability optimizations */
|
|
25
|
-
useStableMode: boolean;
|
|
26
|
-
/** Use optimized CPU path (default: true) */
|
|
27
|
-
useCPUOptimizations: boolean;
|
|
28
|
-
}
|
|
29
|
-
export interface AttentionResult {
|
|
30
|
-
/** Output vectors after attention */
|
|
31
|
-
output: Float32Array[];
|
|
32
|
-
/** Attention weights (optional, for debugging) */
|
|
33
|
-
weights?: Float32Array[];
|
|
34
|
-
/** Computation time in milliseconds */
|
|
35
|
-
computeTimeMs: number;
|
|
36
|
-
}
|
|
37
|
-
export interface BenchmarkResult {
|
|
38
|
-
/** Naive attention time in milliseconds */
|
|
39
|
-
naiveTimeMs: number;
|
|
40
|
-
/** Flash attention time in milliseconds */
|
|
41
|
-
flashTimeMs: number;
|
|
42
|
-
/** Speedup factor (naive / flash) */
|
|
43
|
-
speedup: number;
|
|
44
|
-
/** Number of vectors benchmarked */
|
|
45
|
-
numVectors: number;
|
|
46
|
-
/** Dimensions of vectors */
|
|
47
|
-
dimensions: number;
|
|
48
|
-
/** Memory usage estimate for naive (bytes) */
|
|
49
|
-
naiveMemoryBytes: number;
|
|
50
|
-
/** Memory usage estimate for flash (bytes) */
|
|
51
|
-
flashMemoryBytes: number;
|
|
52
|
-
/** Memory reduction factor */
|
|
53
|
-
memoryReduction: number;
|
|
54
|
-
}
|
|
55
|
-
export declare class FlashAttention {
|
|
56
|
-
private config;
|
|
57
|
-
private lastSpeedup;
|
|
58
|
-
private benchmarkHistory;
|
|
59
|
-
private scoreBuffer;
|
|
60
|
-
private expBuffer;
|
|
61
|
-
private accumBuffer;
|
|
62
|
-
constructor(config?: Partial<FlashAttentionConfig>);
|
|
63
|
-
/**
|
|
64
|
-
* Main attention computation using Flash Attention algorithm
|
|
65
|
-
*
|
|
66
|
-
* @param queries - Query vectors [N x D]
|
|
67
|
-
* @param keys - Key vectors [M x D]
|
|
68
|
-
* @param values - Value vectors [M x D]
|
|
69
|
-
* @returns Attention output [N x D]
|
|
70
|
-
*/
|
|
71
|
-
attention(queries: Float32Array[], keys: Float32Array[], values: Float32Array[]): AttentionResult;
|
|
72
|
-
/**
|
|
73
|
-
* CPU-optimized attention with aggressive optimizations
|
|
74
|
-
*
|
|
75
|
-
* Key optimizations:
|
|
76
|
-
* - Blocked score computation (better cache utilization)
|
|
77
|
-
* - Top-K sparse attention (only use most relevant keys)
|
|
78
|
-
* - Pre-allocated buffers to avoid GC pressure
|
|
79
|
-
* - 8x loop unrolling for dot products
|
|
80
|
-
* - Fused max-finding during score computation
|
|
81
|
-
*/
|
|
82
|
-
private cpuOptimizedAttention;
|
|
83
|
-
/**
|
|
84
|
-
* Partial dot product using only first N dimensions (for screening)
|
|
85
|
-
*/
|
|
86
|
-
private partialDotProduct;
|
|
87
|
-
/**
|
|
88
|
-
* Partial sort to get top-K elements (QuickSelect-like)
|
|
89
|
-
* Only ensures first K elements are the largest, not sorted
|
|
90
|
-
*/
|
|
91
|
-
private partialSort;
|
|
92
|
-
/**
|
|
93
|
-
* Swap two indices in array
|
|
94
|
-
*/
|
|
95
|
-
private swapIndices;
|
|
96
|
-
/**
|
|
97
|
-
* Fast dot product with 8x unrolling
|
|
98
|
-
*/
|
|
99
|
-
private fastDotProduct;
|
|
100
|
-
/**
|
|
101
|
-
* Block-wise attention computation (Flash Attention core algorithm)
|
|
102
|
-
*
|
|
103
|
-
* Algorithm:
|
|
104
|
-
* For each block of queries Q_b:
|
|
105
|
-
* For each block of keys K_b:
|
|
106
|
-
* S_b = Q_b @ K_b.T / sqrt(d) // Block scores
|
|
107
|
-
* P_b = softmax(S_b) // Block attention
|
|
108
|
-
* O_b += P_b @ V_b // Accumulate output
|
|
109
|
-
*
|
|
110
|
-
* @param Q - Query vectors
|
|
111
|
-
* @param K - Key vectors
|
|
112
|
-
* @param V - Value vectors
|
|
113
|
-
* @param blockSize - Block size for tiling
|
|
114
|
-
*/
|
|
115
|
-
blockAttention(Q: Float32Array[], K: Float32Array[], V: Float32Array[], blockSize: number): Float32Array[];
|
|
116
|
-
/**
|
|
117
|
-
* Get the speedup factor from the last benchmark
|
|
118
|
-
*/
|
|
119
|
-
getSpeedup(): number;
|
|
120
|
-
/**
|
|
121
|
-
* Run benchmark comparing naive vs CPU-optimized attention
|
|
122
|
-
*
|
|
123
|
-
* @param numVectors - Number of vectors to test
|
|
124
|
-
* @param dimensions - Dimensions per vector
|
|
125
|
-
* @param iterations - Number of iterations for averaging
|
|
126
|
-
*/
|
|
127
|
-
benchmark(numVectors?: number, dimensions?: number, iterations?: number): BenchmarkResult;
|
|
128
|
-
/**
|
|
129
|
-
* Get benchmark history
|
|
130
|
-
*/
|
|
131
|
-
getBenchmarkHistory(): BenchmarkResult[];
|
|
132
|
-
/**
|
|
133
|
-
* Get configuration
|
|
134
|
-
*/
|
|
135
|
-
getConfig(): FlashAttentionConfig;
|
|
136
|
-
/**
|
|
137
|
-
* Update configuration
|
|
138
|
-
*/
|
|
139
|
-
setConfig(config: Partial<FlashAttentionConfig>): void;
|
|
140
|
-
/**
|
|
141
|
-
* Naive O(N^2) attention implementation for comparison
|
|
142
|
-
*/
|
|
143
|
-
private naiveAttention;
|
|
144
|
-
/**
|
|
145
|
-
* Compute block of attention scores
|
|
146
|
-
*/
|
|
147
|
-
private computeBlockScores;
|
|
148
|
-
/**
|
|
149
|
-
* Online softmax with output accumulation (key to Flash Attention)
|
|
150
|
-
*
|
|
151
|
-
* Uses the online softmax trick to maintain numerical stability
|
|
152
|
-
* while processing blocks incrementally.
|
|
153
|
-
*/
|
|
154
|
-
private onlineSoftmaxAccumulate;
|
|
155
|
-
/**
|
|
156
|
-
* Compute dot product of two vectors
|
|
157
|
-
*/
|
|
158
|
-
private dotProduct;
|
|
159
|
-
/**
|
|
160
|
-
* Stable softmax implementation
|
|
161
|
-
*/
|
|
162
|
-
private softmax;
|
|
163
|
-
/**
|
|
164
|
-
* Generate random vectors for benchmarking
|
|
165
|
-
*/
|
|
166
|
-
private generateRandomVectors;
|
|
167
|
-
/**
|
|
168
|
-
* Validate input arrays
|
|
169
|
-
*/
|
|
170
|
-
private validateInputs;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Get singleton FlashAttention instance
|
|
174
|
-
*
|
|
175
|
-
* @param config - Optional configuration (only used on first call)
|
|
176
|
-
* @returns FlashAttention instance
|
|
177
|
-
*/
|
|
178
|
-
export declare function getFlashAttention(config?: Partial<FlashAttentionConfig>): FlashAttention;
|
|
179
|
-
/**
|
|
180
|
-
* Reset singleton (for testing)
|
|
181
|
-
*/
|
|
182
|
-
export declare function resetFlashAttention(): void;
|
|
183
|
-
/**
|
|
184
|
-
* Compute attention using Flash Attention
|
|
185
|
-
*/
|
|
186
|
-
export declare function computeAttention(queries: Float32Array[], keys: Float32Array[], values: Float32Array[], config?: Partial<FlashAttentionConfig>): AttentionResult;
|
|
187
|
-
/**
|
|
188
|
-
* Run Flash Attention benchmark
|
|
189
|
-
*/
|
|
190
|
-
export declare function benchmarkFlashAttention(numVectors?: number, dimensions?: number, iterations?: number): BenchmarkResult;
|
|
191
|
-
/**
|
|
192
|
-
* Get current speedup from last benchmark
|
|
193
|
-
*/
|
|
194
|
-
export declare function getFlashAttentionSpeedup(): number;
|
|
195
|
-
//# sourceMappingURL=flash-attention.d.ts.map
|