ruvector 0.2.31 → 0.2.33

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 (42) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2303 -2270
  3. package/bin/cli.js +10245 -10106
  4. package/bin/mcp-policy.js +95 -0
  5. package/bin/mcp-server.js +4054 -4035
  6. package/dist/core/onnx/bundled-parallel.mjs +169 -169
  7. package/dist/core/onnx/embed-worker.mjs +67 -67
  8. package/dist/core/onnx/loader.js +485 -461
  9. package/dist/core/onnx/package.json +3 -3
  10. package/dist/core/onnx/pkg/LICENSE +21 -21
  11. package/dist/core/onnx/pkg/loader.js +348 -348
  12. package/dist/core/onnx/pkg/package.json +3 -3
  13. package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm.d.ts +112 -112
  14. package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm.js +5 -5
  15. package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm_bg.js +638 -638
  16. package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm_bg.wasm.d.ts +29 -29
  17. package/dist/core/parallel-workers.js +439 -439
  18. package/dist/workers/benchmark.js +15 -15
  19. package/package.json +124 -123
  20. package/src/decompiler/api-prober.js +302 -302
  21. package/src/decompiler/index.js +463 -463
  22. package/src/decompiler/metrics.js +86 -86
  23. package/src/decompiler/model-decompiler.js +423 -423
  24. package/src/decompiler/module-splitter.js +498 -498
  25. package/src/decompiler/module-tree.js +142 -142
  26. package/src/decompiler/name-predictor.js +400 -400
  27. package/src/decompiler/npm-fetch.js +176 -176
  28. package/src/decompiler/reconstructor.js +499 -499
  29. package/src/decompiler/reference-tracker.js +285 -285
  30. package/src/decompiler/statement-parser.js +285 -285
  31. package/src/decompiler/style-improver.js +438 -438
  32. package/src/decompiler/subcategories.js +339 -339
  33. package/src/decompiler/validator.js +379 -379
  34. package/src/decompiler/witness.js +140 -140
  35. package/src/optimizer/context.js +149 -0
  36. package/src/optimizer/index.js +177 -0
  37. package/src/optimizer/settings-generator.js +176 -0
  38. package/src/optimizer/tool-schemas.js +190 -0
  39. package/wasm/package.json +26 -26
  40. package/wasm/ruvector_decompiler_wasm.d.ts +27 -27
  41. package/wasm/ruvector_decompiler_wasm.js +220 -220
  42. package/wasm/ruvector_decompiler_wasm_bg.wasm.d.ts +16 -16
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Settings generator — produces optimal .claude/settings.json for a
3
+ * given task profile. Based on decompiled Claude Code v2.1.91 schema.
4
+ *
5
+ * The generated settings include:
6
+ * - Permission mode matching the task type
7
+ * - Hooks for RVAgent integration (pre-task optimise, post-session learn)
8
+ * - Feature flags (thinking, fast mode, auto-compact, checkpointing)
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ /**
14
+ * Generate a complete settings.json object for a given profile.
15
+ *
16
+ * @param {object} profile
17
+ * @param {string} profile.taskType - one of the known task types
18
+ * @param {string} profile.permissionMode - permission mode for this task
19
+ * @param {string} [profile.description] - human-readable description
20
+ * @param {object} [profile.env] - environment variables
21
+ * @returns {object} A settings.json-compatible object
22
+ */
23
+ function generateSettings(profile) {
24
+ if (!profile || !profile.taskType) {
25
+ throw new Error('profile.taskType is required');
26
+ }
27
+
28
+ const isInteractive = !['ci', 'background'].includes(profile.taskType);
29
+ const needsThinking = ['planning', 'research', 'coding'].includes(profile.taskType);
30
+ const isFast = ['quickfix', 'ci'].includes(profile.taskType);
31
+
32
+ const settings = {
33
+ permissions: {
34
+ defaultMode: profile.permissionMode || 'default',
35
+ },
36
+ autoCompactEnabled: true,
37
+ fileCheckpointingEnabled: true,
38
+ promptSuggestionEnabled: isInteractive,
39
+ };
40
+
41
+ if (needsThinking) {
42
+ settings.alwaysThinkingEnabled = true;
43
+ }
44
+
45
+ if (isFast) {
46
+ settings.fastMode = true;
47
+ }
48
+
49
+ // Hooks for RVAgent integration
50
+ settings.hooks = buildHooks(profile.taskType);
51
+
52
+ return settings;
53
+ }
54
+
55
+ /**
56
+ * Build the hooks section for a given task type.
57
+ *
58
+ * @param {string} taskType
59
+ * @returns {object}
60
+ */
61
+ function buildHooks(taskType) {
62
+ const hooks = {};
63
+
64
+ // Pre-tool-use hook: optimise before file-mutating tools
65
+ hooks.PreToolUse = [
66
+ {
67
+ matcher: 'Bash|Edit|Write',
68
+ hooks: [
69
+ {
70
+ type: 'command',
71
+ command: 'npx @claude-flow/cli@latest hooks pre-task --optimize',
72
+ },
73
+ ],
74
+ },
75
+ ];
76
+
77
+ // Post-session hook: persist learnings
78
+ hooks.Stop = [
79
+ {
80
+ matcher: '',
81
+ hooks: [
82
+ {
83
+ type: 'command',
84
+ command: 'npx @claude-flow/cli@latest hooks session-end --learn',
85
+ },
86
+ ],
87
+ },
88
+ ];
89
+
90
+ // Swarm tasks get an additional session-start hook for team discovery
91
+ if (taskType === 'swarm') {
92
+ hooks.SessionStart = [
93
+ {
94
+ matcher: '',
95
+ hooks: [
96
+ {
97
+ type: 'command',
98
+ command: 'npx @claude-flow/cli@latest hooks session-start --optimize --team',
99
+ },
100
+ ],
101
+ },
102
+ ];
103
+ }
104
+
105
+ return hooks;
106
+ }
107
+
108
+ /**
109
+ * Merge generated settings into an existing settings object, preserving
110
+ * user customisations that do not conflict.
111
+ *
112
+ * @param {object} existing - the current settings.json content
113
+ * @param {object} generated - output from generateSettings()
114
+ * @returns {object} merged settings
115
+ */
116
+ function mergeSettings(existing, generated) {
117
+ if (!existing) return generated;
118
+
119
+ const merged = { ...existing };
120
+
121
+ // Merge permissions
122
+ merged.permissions = {
123
+ ...(existing.permissions || {}),
124
+ ...(generated.permissions || {}),
125
+ };
126
+
127
+ // Merge hooks (append, do not replace)
128
+ if (generated.hooks) {
129
+ merged.hooks = merged.hooks || {};
130
+ for (const [event, hookList] of Object.entries(generated.hooks)) {
131
+ const existingHooks = merged.hooks[event] || [];
132
+ // Avoid duplicates by checking command strings
133
+ const existingCmds = new Set(
134
+ existingHooks.flatMap((h) =>
135
+ (h.hooks || []).map((inner) => inner.command)
136
+ )
137
+ );
138
+ const newHooks = hookList.filter((h) =>
139
+ (h.hooks || []).some((inner) => !existingCmds.has(inner.command))
140
+ );
141
+ merged.hooks[event] = [...existingHooks, ...newHooks];
142
+ }
143
+ }
144
+
145
+ // Copy feature flags (generated wins)
146
+ for (const key of [
147
+ 'autoCompactEnabled',
148
+ 'fileCheckpointingEnabled',
149
+ 'promptSuggestionEnabled',
150
+ 'alwaysThinkingEnabled',
151
+ 'fastMode',
152
+ ]) {
153
+ if (generated[key] !== undefined) {
154
+ merged[key] = generated[key];
155
+ }
156
+ }
157
+
158
+ return merged;
159
+ }
160
+
161
+ /**
162
+ * Serialise settings to a formatted JSON string.
163
+ *
164
+ * @param {object} settings
165
+ * @returns {string}
166
+ */
167
+ function formatSettings(settings) {
168
+ return JSON.stringify(settings, null, 2);
169
+ }
170
+
171
+ module.exports = {
172
+ generateSettings,
173
+ buildHooks,
174
+ mergeSettings,
175
+ formatSettings,
176
+ };
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Decompiled tool schemas from Claude Code v2.1.91.
3
+ *
4
+ * These schemas mirror the exact inputSchema definitions found in the
5
+ * decompiled binary. They enable Tier-1 (WASM booster) validation of
6
+ * tool calls without invoking the LLM, and provide a known-pattern
7
+ * cache for deterministic tool responses.
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ /**
13
+ * Tool input schemas extracted from decompiled Claude Code v2.1.91.
14
+ * A trailing '?' on the type string means the field is optional.
15
+ */
16
+ const TOOL_SCHEMAS = {
17
+ Bash: {
18
+ command: 'string',
19
+ description: 'string?',
20
+ timeout: 'number?',
21
+ run_in_background: 'boolean?',
22
+ },
23
+ Read: {
24
+ file_path: 'string',
25
+ offset: 'number?',
26
+ limit: 'number?',
27
+ pages: 'string?',
28
+ },
29
+ Edit: {
30
+ file_path: 'string',
31
+ old_string: 'string',
32
+ new_string: 'string',
33
+ replace_all: 'boolean?',
34
+ },
35
+ Write: {
36
+ file_path: 'string',
37
+ content: 'string',
38
+ },
39
+ Glob: {
40
+ pattern: 'string',
41
+ path: 'string?',
42
+ },
43
+ Grep: {
44
+ pattern: 'string',
45
+ path: 'string?',
46
+ glob: 'string?',
47
+ type: 'string?',
48
+ output_mode: 'string?',
49
+ '-i': 'boolean?',
50
+ '-n': 'boolean?',
51
+ '-A': 'number?',
52
+ '-B': 'number?',
53
+ '-C': 'number?',
54
+ context: 'number?',
55
+ head_limit: 'number?',
56
+ offset: 'number?',
57
+ multiline: 'boolean?',
58
+ },
59
+ Agent: {
60
+ prompt: 'string',
61
+ description: 'string?',
62
+ },
63
+ WebFetch: {
64
+ url: 'string',
65
+ },
66
+ WebSearch: {
67
+ query: 'string',
68
+ },
69
+ TodoWrite: {
70
+ todos: 'array',
71
+ },
72
+ NotebookEdit: {
73
+ notebook_path: 'string',
74
+ cell_number: 'number',
75
+ new_source: 'string',
76
+ cell_type: 'string?',
77
+ },
78
+ ToolSearch: {
79
+ query: 'string',
80
+ max_results: 'number?',
81
+ },
82
+ Skill: {
83
+ skill: 'string',
84
+ args: 'string?',
85
+ },
86
+ EnterWorktree: {
87
+ name: 'string?',
88
+ branch: 'string?',
89
+ path: 'string?',
90
+ },
91
+ ExitWorktree: {
92
+ name: 'string?',
93
+ },
94
+ };
95
+
96
+ /** All known tool names. */
97
+ const TOOL_NAMES = Object.keys(TOOL_SCHEMAS);
98
+
99
+ /** Base type checkers for schema validation. */
100
+ const TYPE_CHECKS = {
101
+ string: (v) => typeof v === 'string',
102
+ number: (v) => typeof v === 'number' && !Number.isNaN(v),
103
+ boolean: (v) => typeof v === 'boolean',
104
+ array: (v) => Array.isArray(v),
105
+ object: (v) => v !== null && typeof v === 'object' && !Array.isArray(v),
106
+ };
107
+
108
+ /**
109
+ * Validate a tool call's arguments against the known schema.
110
+ * Returns { valid: true } or { valid: false, errors: string[] }.
111
+ *
112
+ * This is intended as a fast Tier-1 check — it validates structure
113
+ * without calling any LLM. Unknown tool names pass validation
114
+ * (we assume they are custom MCP tools).
115
+ *
116
+ * @param {string} toolName
117
+ * @param {object} args
118
+ * @returns {{ valid: boolean, errors?: string[] }}
119
+ */
120
+ function validateToolCall(toolName, args) {
121
+ const schema = TOOL_SCHEMAS[toolName];
122
+ if (!schema) {
123
+ // Unknown tool — let it through (may be an MCP extension)
124
+ return { valid: true };
125
+ }
126
+
127
+ if (!args || typeof args !== 'object') {
128
+ return { valid: false, errors: ['args must be a non-null object'] };
129
+ }
130
+
131
+ const errors = [];
132
+
133
+ for (const [field, typeSpec] of Object.entries(schema)) {
134
+ const isOptional = typeSpec.endsWith('?');
135
+ const baseType = isOptional ? typeSpec.slice(0, -1) : typeSpec;
136
+ const value = args[field];
137
+
138
+ if (value === undefined || value === null) {
139
+ if (!isOptional) {
140
+ errors.push(`Missing required field: ${field}`);
141
+ }
142
+ continue;
143
+ }
144
+
145
+ const checker = TYPE_CHECKS[baseType];
146
+ if (checker && !checker(value)) {
147
+ errors.push(`Field '${field}' expected ${baseType}, got ${typeof value}`);
148
+ }
149
+ }
150
+
151
+ return errors.length === 0
152
+ ? { valid: true }
153
+ : { valid: false, errors };
154
+ }
155
+
156
+ /**
157
+ * Cached patterns for common tool calls that produce deterministic
158
+ * or near-deterministic results. The booster can skip LLM calls
159
+ * entirely for these patterns.
160
+ */
161
+ const CACHED_PATTERNS = {
162
+ 'Glob:**/*.ts': { pattern: '**/*.ts' },
163
+ 'Glob:**/*.js': { pattern: '**/*.js' },
164
+ 'Glob:**/*.py': { pattern: '**/*.py' },
165
+ 'Glob:**/*.rs': { pattern: '**/*.rs' },
166
+ 'Glob:**/*.json': { pattern: '**/*.json' },
167
+ 'Glob:package.json': { pattern: '**/package.json' },
168
+ 'Glob:Cargo.toml': { pattern: '**/Cargo.toml' },
169
+ 'Grep:import.*from': { pattern: 'import.*from', type: 'js' },
170
+ 'Grep:use ': { pattern: '^use ', type: 'rust' },
171
+ 'Grep:TODO|FIXME': { pattern: 'TODO|FIXME' },
172
+ };
173
+
174
+ /**
175
+ * Look up a cached pattern. Returns the pattern args or null.
176
+ * @param {string} toolName
177
+ * @param {string} shortKey - a short identifier for the pattern
178
+ * @returns {object|null}
179
+ */
180
+ function getCachedPattern(toolName, shortKey) {
181
+ return CACHED_PATTERNS[`${toolName}:${shortKey}`] || null;
182
+ }
183
+
184
+ module.exports = {
185
+ TOOL_SCHEMAS,
186
+ TOOL_NAMES,
187
+ validateToolCall,
188
+ CACHED_PATTERNS,
189
+ getCachedPattern,
190
+ };
package/wasm/package.json CHANGED
@@ -1,27 +1,27 @@
1
- {
2
- "name": "ruvector-decompiler-wasm",
3
- "collaborators": [
4
- "Ruvector Team"
5
- ],
6
- "description": "WASM bindings for the RuVector JavaScript bundle decompiler (Louvain pipeline)",
7
- "version": "2.1.0",
8
- "license": "MIT",
9
- "repository": {
10
- "type": "git",
11
- "url": "https://github.com/ruvnet/ruvector"
12
- },
13
- "files": [
14
- "ruvector_decompiler_wasm_bg.wasm",
15
- "ruvector_decompiler_wasm.js",
16
- "ruvector_decompiler_wasm.d.ts"
17
- ],
18
- "main": "ruvector_decompiler_wasm.js",
19
- "types": "ruvector_decompiler_wasm.d.ts",
20
- "keywords": [
21
- "decompiler",
22
- "javascript",
23
- "wasm",
24
- "mincut",
25
- "louvain"
26
- ]
1
+ {
2
+ "name": "ruvector-decompiler-wasm",
3
+ "collaborators": [
4
+ "Ruvector Team"
5
+ ],
6
+ "description": "WASM bindings for the RuVector JavaScript bundle decompiler (Louvain pipeline)",
7
+ "version": "2.1.0",
8
+ "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/ruvnet/ruvector"
12
+ },
13
+ "files": [
14
+ "ruvector_decompiler_wasm_bg.wasm",
15
+ "ruvector_decompiler_wasm.js",
16
+ "ruvector_decompiler_wasm.d.ts"
17
+ ],
18
+ "main": "ruvector_decompiler_wasm.js",
19
+ "types": "ruvector_decompiler_wasm.d.ts",
20
+ "keywords": [
21
+ "decompiler",
22
+ "javascript",
23
+ "wasm",
24
+ "mincut",
25
+ "louvain"
26
+ ]
27
27
  }
@@ -1,27 +1,27 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
-
4
- /**
5
- * Decompile a minified JavaScript bundle using the full Louvain pipeline.
6
- *
7
- * # Arguments
8
- *
9
- * * `source` - The minified JavaScript source code.
10
- * * `config_json` - JSON string of `DecompileConfig` fields. Pass `"{}"` for defaults.
11
- *
12
- * # Returns
13
- *
14
- * A JSON string containing the `DecompileResult` (modules, witness, inferred names, etc.)
15
- * or a JSON object with an `"error"` field on failure.
16
- */
17
- export function decompile(source: string, config_json: string): string;
18
-
19
- /**
20
- * Initialize the WASM module (sets up panic hook for better error messages).
21
- */
22
- export function init(): void;
23
-
24
- /**
25
- * Return the version of the decompiler WASM module.
26
- */
27
- export function version(): string;
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Decompile a minified JavaScript bundle using the full Louvain pipeline.
6
+ *
7
+ * # Arguments
8
+ *
9
+ * * `source` - The minified JavaScript source code.
10
+ * * `config_json` - JSON string of `DecompileConfig` fields. Pass `"{}"` for defaults.
11
+ *
12
+ * # Returns
13
+ *
14
+ * A JSON string containing the `DecompileResult` (modules, witness, inferred names, etc.)
15
+ * or a JSON object with an `"error"` field on failure.
16
+ */
17
+ export function decompile(source: string, config_json: string): string;
18
+
19
+ /**
20
+ * Initialize the WASM module (sets up panic hook for better error messages).
21
+ */
22
+ export function init(): void;
23
+
24
+ /**
25
+ * Return the version of the decompiler WASM module.
26
+ */
27
+ export function version(): string;