entroly-wasm 1.0.11 → 1.0.12
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/LICENSE +88 -0
- package/NOTICE +17 -0
- package/js/auto_index.js +24 -5
- package/js/cogops.js +20 -4
- package/js/repo_map.js +15 -1
- package/js/server.js +56 -11
- package/js/skills.js +31 -5
- package/js/vault.js +44 -10
- package/js/workspace.js +18 -4
- package/package.json +3 -1
- package/pkg/entroly_wasm_bg.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
26
|
+
|
|
27
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
28
|
+
|
|
29
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
30
|
+
|
|
31
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
32
|
+
|
|
33
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
34
|
+
|
|
35
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
36
|
+
|
|
37
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
38
|
+
|
|
39
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
40
|
+
|
|
41
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
42
|
+
|
|
43
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
|
56
|
+
|
|
57
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
58
|
+
|
|
59
|
+
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
|
60
|
+
|
|
61
|
+
Copyright [yyyy] [name of copyright owner]
|
|
62
|
+
|
|
63
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
64
|
+
you may not use this file except in compliance with the License.
|
|
65
|
+
You may obtain a copy of the License at
|
|
66
|
+
|
|
67
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
68
|
+
|
|
69
|
+
Unless required by applicable law or agreed to in writing, software
|
|
70
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
71
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
72
|
+
See the License for the specific language governing permissions and
|
|
73
|
+
limitations under the License.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
Copyright 2026 Entroly
|
|
77
|
+
|
|
78
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
79
|
+
you may not use this file except in compliance with the License.
|
|
80
|
+
You may obtain a copy of the License at
|
|
81
|
+
|
|
82
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
83
|
+
|
|
84
|
+
Unless required by applicable law or agreed to in writing, software
|
|
85
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
86
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
87
|
+
See the License for the specific language governing permissions and
|
|
88
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Entroly — Context Engineering Engine
|
|
2
|
+
Copyright 2026 Entroly
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Entroly
|
|
5
|
+
(https://github.com/juyterman1000/entroly).
|
|
6
|
+
|
|
7
|
+
This software implements original algorithms for context optimization,
|
|
8
|
+
including but not limited to:
|
|
9
|
+
- PRISM 5D Reinforcement Learning Engine
|
|
10
|
+
- Differentiable Soft Bisection Knapsack Optimizer
|
|
11
|
+
- SimHash LSH Deduplication Index
|
|
12
|
+
- Hierarchical Bayesian Context Compression
|
|
13
|
+
- Adaptive Dual Gap Temperature (ADGT) Scheduling
|
|
14
|
+
|
|
15
|
+
If you use, modify, or redistribute this software (in whole or in part),
|
|
16
|
+
you must retain this NOTICE file and all copyright attributions as required
|
|
17
|
+
by the Apache License, Version 2.0.
|
package/js/auto_index.js
CHANGED
|
@@ -102,7 +102,8 @@ function walkFallback(projectDir) {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
function loadEntrolyIgnore(projectDir) {
|
|
105
|
-
const ignorePath =
|
|
105
|
+
const ignorePath = resolveProjectFile(projectDir, '.entrolyignore');
|
|
106
|
+
if (!ignorePath) return [];
|
|
106
107
|
try {
|
|
107
108
|
const content = fs.readFileSync(ignorePath, 'utf-8');
|
|
108
109
|
return content.split('\n').map(l => l.trim()).filter(l => l && !l.startsWith('#'));
|
|
@@ -139,6 +140,20 @@ function estimateTokens(content) {
|
|
|
139
140
|
return Math.max(1, Math.floor(content.length / 4));
|
|
140
141
|
}
|
|
141
142
|
|
|
143
|
+
function resolveProjectFile(projectDir, relPath) {
|
|
144
|
+
try {
|
|
145
|
+
const root = fs.realpathSync(projectDir);
|
|
146
|
+
const candidate = fs.realpathSync(path.join(root, relPath));
|
|
147
|
+
const relative = path.relative(root, candidate);
|
|
148
|
+
if (relative === '' || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
return candidate;
|
|
152
|
+
} catch {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
142
157
|
/**
|
|
143
158
|
* Auto-index a project's codebase into the Entroly wasm engine.
|
|
144
159
|
* @param {WasmEntrolyEngine} engine
|
|
@@ -171,7 +186,8 @@ function autoIndex(engine, projectDir, force = false) {
|
|
|
171
186
|
let indexed = 0, totalTokens = 0, skippedSize = 0, skippedRead = 0;
|
|
172
187
|
|
|
173
188
|
for (const relPath of indexable) {
|
|
174
|
-
const absPath =
|
|
189
|
+
const absPath = resolveProjectFile(projectDir, relPath);
|
|
190
|
+
if (!absPath) { skippedRead++; continue; }
|
|
175
191
|
let stat;
|
|
176
192
|
try { stat = fs.statSync(absPath); } catch { continue; }
|
|
177
193
|
|
|
@@ -227,7 +243,9 @@ function startIncrementalWatcher(engine, projectDir, intervalMs = 120000) {
|
|
|
227
243
|
// Initial snapshot
|
|
228
244
|
const files = gitLsFiles(projectDir);
|
|
229
245
|
for (const rel of files) {
|
|
230
|
-
|
|
246
|
+
const abs = resolveProjectFile(projectDir, rel);
|
|
247
|
+
if (!abs) continue;
|
|
248
|
+
try { indexedMtimes[rel] = fs.statSync(abs).mtimeMs; } catch {}
|
|
231
249
|
}
|
|
232
250
|
|
|
233
251
|
return setInterval(() => {
|
|
@@ -236,7 +254,8 @@ function startIncrementalWatcher(engine, projectDir, intervalMs = 120000) {
|
|
|
236
254
|
let count = 0;
|
|
237
255
|
for (const rel of files) {
|
|
238
256
|
if (!shouldIndex(rel)) continue;
|
|
239
|
-
const abs =
|
|
257
|
+
const abs = resolveProjectFile(projectDir, rel);
|
|
258
|
+
if (!abs) continue;
|
|
240
259
|
let mtime;
|
|
241
260
|
try { mtime = fs.statSync(abs).mtimeMs; } catch { continue; }
|
|
242
261
|
if (indexedMtimes[rel] === undefined || mtime > indexedMtimes[rel]) {
|
|
@@ -259,4 +278,4 @@ function startIncrementalWatcher(engine, projectDir, intervalMs = 120000) {
|
|
|
259
278
|
}, intervalMs);
|
|
260
279
|
}
|
|
261
280
|
|
|
262
|
-
module.exports = { autoIndex, startIncrementalWatcher, estimateTokens };
|
|
281
|
+
module.exports = { autoIndex, startIncrementalWatcher, estimateTokens, resolveProjectFile };
|
package/js/cogops.js
CHANGED
|
@@ -190,6 +190,18 @@ function extractEntities(content, ext) {
|
|
|
190
190
|
return entities;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
+
function resolveFileWithin(root, candidate) {
|
|
194
|
+
try {
|
|
195
|
+
const realRoot = fs.realpathSync(root);
|
|
196
|
+
const resolved = fs.realpathSync(candidate);
|
|
197
|
+
const relative = path.relative(realRoot, resolved);
|
|
198
|
+
if (relative === '' || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) return null;
|
|
199
|
+
return resolved;
|
|
200
|
+
} catch {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
193
205
|
class BeliefCompiler {
|
|
194
206
|
constructor(vault) { this._vault = vault; }
|
|
195
207
|
|
|
@@ -199,7 +211,9 @@ class BeliefCompiler {
|
|
|
199
211
|
const errors = [];
|
|
200
212
|
for (const fp of sourceFiles) {
|
|
201
213
|
try {
|
|
202
|
-
const
|
|
214
|
+
const safePath = resolveFileWithin(directory, fp);
|
|
215
|
+
if (!safePath) continue;
|
|
216
|
+
const content = fs.readFileSync(safePath, 'utf-8');
|
|
203
217
|
const ext = path.extname(fp).slice(1);
|
|
204
218
|
const entities = extractEntities(content, ext);
|
|
205
219
|
const relPath = path.relative(directory, fp).replace(/\\/g, '/');
|
|
@@ -235,7 +249,7 @@ class BeliefCompiler {
|
|
|
235
249
|
if (e.name.startsWith('.') || e.name === 'node_modules' || e.name === '__pycache__' || e.name === 'target' || e.name === '.git') continue;
|
|
236
250
|
const full = path.join(d, e.name);
|
|
237
251
|
if (e.isDirectory()) walk(full);
|
|
238
|
-
else if (SOURCE_EXTS.has(path.extname(e.name))) results.push(full);
|
|
252
|
+
else if (SOURCE_EXTS.has(path.extname(e.name)) && resolveFileWithin(dir, full)) results.push(full);
|
|
239
253
|
}
|
|
240
254
|
};
|
|
241
255
|
walk(dir);
|
|
@@ -462,7 +476,9 @@ function compileDocs(vault, directory, maxFiles = 50) {
|
|
|
462
476
|
const stem = e.name.replace(/\.md$/i, '').toUpperCase();
|
|
463
477
|
if (!docPatterns.some(p => stem.startsWith(p)) && dir === root) continue;
|
|
464
478
|
try {
|
|
465
|
-
const
|
|
479
|
+
const safePath = resolveFileWithin(root, full);
|
|
480
|
+
if (!safePath) continue;
|
|
481
|
+
const content = fs.readFileSync(safePath, 'utf-8');
|
|
466
482
|
const entity = `doc/${e.name.replace(/\.md$/i, '').toLowerCase()}`;
|
|
467
483
|
vault.writeBelief({
|
|
468
484
|
claim_id: randomUUID(),
|
|
@@ -508,6 +524,6 @@ function exportTrainingData(vault, outputPath = 'training_data.jsonl') {
|
|
|
508
524
|
module.exports = {
|
|
509
525
|
EpistemicRouter, BeliefCompiler, VerificationEngine, ChangePipeline, FlowOrchestrator,
|
|
510
526
|
classifyIntent, assessRisk, extractEntityKey, parseDiff, classifyDiffIntent, reviewDiff,
|
|
511
|
-
compileDocs, exportTrainingData,
|
|
527
|
+
compileDocs, exportTrainingData, resolveFileWithin,
|
|
512
528
|
INTENTS, FLOWS,
|
|
513
529
|
};
|
package/js/repo_map.js
CHANGED
|
@@ -10,6 +10,18 @@ const path = require('path');
|
|
|
10
10
|
|
|
11
11
|
const SKIP_DIRS = new Set(['.git', '.venv', '__pycache__', '.pytest_cache', '.ruff_cache', 'target', 'node_modules', '.tmp']);
|
|
12
12
|
|
|
13
|
+
function resolveFileWithin(root, candidate) {
|
|
14
|
+
try {
|
|
15
|
+
const realRoot = fs.realpathSync(root);
|
|
16
|
+
const resolved = fs.realpathSync(candidate);
|
|
17
|
+
const relative = path.relative(realRoot, resolved);
|
|
18
|
+
if (relative === '' || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) return null;
|
|
19
|
+
return fs.statSync(resolved).isFile() ? resolved : null;
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
13
25
|
const PY_ROLES = {
|
|
14
26
|
'server.py': ['primary Python MCP server and product shell', 'python-runtime'],
|
|
15
27
|
'cli.py': ['primary CLI and operator surface', 'python-runtime'],
|
|
@@ -62,7 +74,9 @@ function buildRepoMap(rootDir) {
|
|
|
62
74
|
if (SKIP_DIRS.has(e.name)) continue;
|
|
63
75
|
const full = path.join(dir, e.name);
|
|
64
76
|
if (e.isDirectory()) { walk(full); continue; }
|
|
65
|
-
const
|
|
77
|
+
const safePath = resolveFileWithin(root, full);
|
|
78
|
+
if (!safePath) continue;
|
|
79
|
+
const rel = path.relative(root, safePath).replace(/\\/g, '/');
|
|
66
80
|
const parts = rel.split('/');
|
|
67
81
|
const name = path.basename(rel);
|
|
68
82
|
let repo = 'other', role = 'support file', category = 'support';
|
package/js/server.js
CHANGED
|
@@ -19,6 +19,35 @@ const { ingestDiff, ingestDiagram, ingestVoice } = require('./multimodal');
|
|
|
19
19
|
const path = require('path');
|
|
20
20
|
const fs = require('fs');
|
|
21
21
|
|
|
22
|
+
function resolveProjectDirectory(root, candidate = '.') {
|
|
23
|
+
try {
|
|
24
|
+
const realRoot = fs.realpathSync(root);
|
|
25
|
+
const resolved = fs.realpathSync(path.isAbsolute(candidate) ? candidate : path.join(realRoot, candidate));
|
|
26
|
+
const relative = path.relative(realRoot, resolved);
|
|
27
|
+
if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) return null;
|
|
28
|
+
return fs.statSync(resolved).isDirectory() ? resolved : null;
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function resolveProjectOutput(root, candidate) {
|
|
35
|
+
try {
|
|
36
|
+
const realRoot = fs.realpathSync(root);
|
|
37
|
+
const output = path.isAbsolute(candidate) ? candidate : path.join(realRoot, candidate);
|
|
38
|
+
const parent = fs.realpathSync(path.dirname(output));
|
|
39
|
+
const relative = path.relative(realRoot, parent);
|
|
40
|
+
if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) return null;
|
|
41
|
+
if (!fs.existsSync(output)) return output;
|
|
42
|
+
const resolved = fs.realpathSync(output);
|
|
43
|
+
const outputRelative = path.relative(realRoot, resolved);
|
|
44
|
+
if (outputRelative === '..' || outputRelative.startsWith(`..${path.sep}`) || path.isAbsolute(outputRelative)) return null;
|
|
45
|
+
return fs.statSync(resolved).isFile() ? resolved : null;
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
22
51
|
// ── MCP Protocol Implementation (stdio JSON-RPC 2.0) ──
|
|
23
52
|
|
|
24
53
|
class EntrolyMCPServer {
|
|
@@ -56,7 +85,7 @@ class EntrolyMCPServer {
|
|
|
56
85
|
this.verifier = new VerificationEngine(this.vault, { freshnessHours: 24, minConfidence: 0.5 });
|
|
57
86
|
this.changePipe = new ChangePipeline(this.vault, this.verifier);
|
|
58
87
|
this.skillEngine = new SkillEngine(this.vault);
|
|
59
|
-
this.sourceDir = process.env.ENTROLY_SOURCE || process.cwd();
|
|
88
|
+
this.sourceDir = fs.realpathSync(process.env.ENTROLY_SOURCE || process.cwd());
|
|
60
89
|
this.flowOrchestrator = new FlowOrchestrator(this.vault, this.epistemicRouter, this.beliefCompiler, this.verifier, this.changePipe, this.sourceDir);
|
|
61
90
|
this.workspaceListener = new WorkspaceChangeListener(this.vault, this.beliefCompiler, this.verifier, this.changePipe, this.sourceDir);
|
|
62
91
|
|
|
@@ -72,6 +101,18 @@ class EntrolyMCPServer {
|
|
|
72
101
|
|
|
73
102
|
_log(msg) { process.stderr.write(`${new Date().toISOString()} [entroly] ${msg}\n`); }
|
|
74
103
|
|
|
104
|
+
_projectDir(candidate = '') {
|
|
105
|
+
const resolved = resolveProjectDirectory(this.sourceDir, candidate || '.');
|
|
106
|
+
if (!resolved) throw new Error(`Path must remain within project root: ${candidate}`);
|
|
107
|
+
return resolved;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
_projectOutput(candidate) {
|
|
111
|
+
const resolved = resolveProjectOutput(this.sourceDir, candidate);
|
|
112
|
+
if (!resolved) throw new Error(`Path must remain within project root: ${candidate}`);
|
|
113
|
+
return resolved;
|
|
114
|
+
}
|
|
115
|
+
|
|
75
116
|
// ── MCP Tool Definitions (36 tools — full parity with pip) ──
|
|
76
117
|
get tools() {
|
|
77
118
|
return [
|
|
@@ -274,7 +315,7 @@ class EntrolyMCPServer {
|
|
|
274
315
|
}
|
|
275
316
|
|
|
276
317
|
case 'compile_beliefs':
|
|
277
|
-
return this.beliefCompiler.compileDirectory(args.directory
|
|
318
|
+
return this.beliefCompiler.compileDirectory(this._projectDir(args.directory), args.max_files || 200);
|
|
278
319
|
|
|
279
320
|
case 'verify_beliefs':
|
|
280
321
|
return this.verifier.fullVerificationPass();
|
|
@@ -286,7 +327,7 @@ class EntrolyMCPServer {
|
|
|
286
327
|
}
|
|
287
328
|
|
|
288
329
|
case 'coverage_gaps':
|
|
289
|
-
return this.verifier.coverageGaps(args.directory
|
|
330
|
+
return this.verifier.coverageGaps(this._projectDir(args.directory));
|
|
290
331
|
|
|
291
332
|
case 'process_change':
|
|
292
333
|
return this.changePipe.processDiff(args.diff_text, args.commit_message || '', args.pr_title || '');
|
|
@@ -300,10 +341,13 @@ class EntrolyMCPServer {
|
|
|
300
341
|
}
|
|
301
342
|
|
|
302
343
|
case 'compile_docs':
|
|
303
|
-
return compileDocs(this.vault, args.directory
|
|
344
|
+
return compileDocs(this.vault, this._projectDir(args.directory), args.max_files || 50);
|
|
304
345
|
|
|
305
|
-
case 'export_training_data':
|
|
306
|
-
|
|
346
|
+
case 'export_training_data': {
|
|
347
|
+
const format = args.format || 'jsonl';
|
|
348
|
+
if (format !== 'jsonl') return { error: `Unsupported export format: ${format}` };
|
|
349
|
+
return exportTrainingData(this.vault, this._projectOutput(args.output_path || 'training_data.jsonl'));
|
|
350
|
+
}
|
|
307
351
|
|
|
308
352
|
// ── Ingestion Tools ──
|
|
309
353
|
case 'ingest_diff': {
|
|
@@ -320,12 +364,14 @@ class EntrolyMCPServer {
|
|
|
320
364
|
|
|
321
365
|
// ── Workspace Tools ──
|
|
322
366
|
case 'sync_workspace_changes': {
|
|
323
|
-
const
|
|
367
|
+
const target = this._projectDir(args.directory);
|
|
368
|
+
const listener = target === this.sourceDir ? this.workspaceListener : new WorkspaceChangeListener(this.vault, this.beliefCompiler, this.verifier, this.changePipe, target);
|
|
324
369
|
return listener.scanOnce(args.force || false, args.max_files || 100);
|
|
325
370
|
}
|
|
326
371
|
|
|
327
372
|
case 'start_workspace_listener': {
|
|
328
|
-
const
|
|
373
|
+
const target = this._projectDir(args.directory);
|
|
374
|
+
const listener = target === this.sourceDir ? this.workspaceListener : new WorkspaceChangeListener(this.vault, this.beliefCompiler, this.verifier, this.changePipe, target);
|
|
329
375
|
return listener.start(args.interval_s || 120, args.max_files || 100, args.force_initial || false);
|
|
330
376
|
}
|
|
331
377
|
|
|
@@ -346,8 +392,7 @@ class EntrolyMCPServer {
|
|
|
346
392
|
|
|
347
393
|
// ── Analysis Tools ──
|
|
348
394
|
case 'repo_file_map': {
|
|
349
|
-
const
|
|
350
|
-
const grouped = buildRepoMap(rootDir);
|
|
395
|
+
const grouped = buildRepoMap(this.sourceDir);
|
|
351
396
|
if ((args.format || '').toLowerCase() === 'json') return grouped;
|
|
352
397
|
return renderRepoMapMarkdown(grouped);
|
|
353
398
|
}
|
|
@@ -563,4 +608,4 @@ if (require.main === module) {
|
|
|
563
608
|
server.run();
|
|
564
609
|
}
|
|
565
610
|
|
|
566
|
-
module.exports = { EntrolyMCPServer };
|
|
611
|
+
module.exports = { EntrolyMCPServer, resolveProjectDirectory, resolveProjectOutput };
|
package/js/skills.js
CHANGED
|
@@ -10,6 +10,10 @@ const path = require('path');
|
|
|
10
10
|
const { randomUUID } = require('crypto');
|
|
11
11
|
const { nowISO, safeFilename } = require('./vault');
|
|
12
12
|
|
|
13
|
+
function isValidSkillId(skillId) {
|
|
14
|
+
return typeof skillId === 'string' && /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/.test(skillId);
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
class SkillEngine {
|
|
14
18
|
constructor(vault) {
|
|
15
19
|
this._vault = vault;
|
|
@@ -19,6 +23,7 @@ class SkillEngine {
|
|
|
19
23
|
createSkill(entityKey, failingQueries, intent = '') {
|
|
20
24
|
this._vault.ensureStructure();
|
|
21
25
|
const skillId = `skill_${safeFilename(entityKey)}_${Date.now().toString(36)}`;
|
|
26
|
+
if (!isValidSkillId(skillId)) return { status: 'invalid_skill_id', skill_id: skillId };
|
|
22
27
|
const skillDir = path.join(this._skillsDir, skillId);
|
|
23
28
|
fs.mkdirSync(skillDir, { recursive: true });
|
|
24
29
|
fs.mkdirSync(path.join(skillDir, 'tests'), { recursive: true });
|
|
@@ -74,7 +79,9 @@ class SkillEngine {
|
|
|
74
79
|
if (!fs.existsSync(this._skillsDir)) return [];
|
|
75
80
|
const skills = [];
|
|
76
81
|
for (const name of fs.readdirSync(this._skillsDir)) {
|
|
77
|
-
const
|
|
82
|
+
const skillDir = this._skillDir(name);
|
|
83
|
+
if (!skillDir) continue;
|
|
84
|
+
const metricsPath = path.join(skillDir, 'metrics.json');
|
|
78
85
|
if (!fs.existsSync(metricsPath)) continue;
|
|
79
86
|
try {
|
|
80
87
|
const m = JSON.parse(fs.readFileSync(metricsPath, 'utf-8'));
|
|
@@ -85,8 +92,11 @@ class SkillEngine {
|
|
|
85
92
|
}
|
|
86
93
|
|
|
87
94
|
benchmarkSkill(skillId) {
|
|
88
|
-
|
|
89
|
-
const
|
|
95
|
+
if (!isValidSkillId(skillId)) return { status: 'invalid_skill_id', skill_id: skillId };
|
|
96
|
+
const skillDir = this._skillDir(skillId);
|
|
97
|
+
if (!skillDir) return { error: `Skill '${skillId}' not found` };
|
|
98
|
+
const metricsPath = path.join(skillDir, 'metrics.json');
|
|
99
|
+
const testsPath = path.join(skillDir, 'tests', 'test_cases.json');
|
|
90
100
|
if (!fs.existsSync(metricsPath)) return { error: `Skill '${skillId}' not found` };
|
|
91
101
|
const metrics = JSON.parse(fs.readFileSync(metricsPath, 'utf-8'));
|
|
92
102
|
let cases = [];
|
|
@@ -103,7 +113,10 @@ class SkillEngine {
|
|
|
103
113
|
}
|
|
104
114
|
|
|
105
115
|
promoteOrPrune(skillId) {
|
|
106
|
-
|
|
116
|
+
if (!isValidSkillId(skillId)) return { status: 'invalid_skill_id', skill_id: skillId };
|
|
117
|
+
const skillDir = this._skillDir(skillId);
|
|
118
|
+
if (!skillDir) return { error: `Skill '${skillId}' not found` };
|
|
119
|
+
const metricsPath = path.join(skillDir, 'metrics.json');
|
|
107
120
|
if (!fs.existsSync(metricsPath)) return { error: `Skill '${skillId}' not found` };
|
|
108
121
|
const metrics = JSON.parse(fs.readFileSync(metricsPath, 'utf-8'));
|
|
109
122
|
let action;
|
|
@@ -119,6 +132,19 @@ class SkillEngine {
|
|
|
119
132
|
fs.writeFileSync(metricsPath, JSON.stringify(metrics, null, 2), 'utf-8');
|
|
120
133
|
return { skill_id: skillId, action, fitness: metrics.fitness, new_status: metrics.status, engine: 'javascript' };
|
|
121
134
|
}
|
|
135
|
+
|
|
136
|
+
_skillDir(skillId) {
|
|
137
|
+
if (!isValidSkillId(skillId)) return null;
|
|
138
|
+
try {
|
|
139
|
+
const root = fs.realpathSync(this._skillsDir);
|
|
140
|
+
const candidate = fs.realpathSync(path.join(root, skillId));
|
|
141
|
+
const relative = path.relative(root, candidate);
|
|
142
|
+
if (!relative || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) return null;
|
|
143
|
+
return fs.statSync(candidate).isDirectory() ? candidate : null;
|
|
144
|
+
} catch {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
122
148
|
}
|
|
123
149
|
|
|
124
|
-
module.exports = { SkillEngine };
|
|
150
|
+
module.exports = { SkillEngine, isValidSkillId };
|
package/js/vault.js
CHANGED
|
@@ -24,6 +24,31 @@ function safeFilename(s) {
|
|
|
24
24
|
function nowISO() { return new Date().toISOString(); }
|
|
25
25
|
function timestamp() { return new Date().toISOString().replace(/[-:]/g, '').replace(/\.\d+Z/, ''); }
|
|
26
26
|
|
|
27
|
+
function resolveFileWithin(root, candidate) {
|
|
28
|
+
try {
|
|
29
|
+
const realRoot = fs.realpathSync(root);
|
|
30
|
+
const resolved = fs.realpathSync(candidate);
|
|
31
|
+
const relative = path.relative(realRoot, resolved);
|
|
32
|
+
if (relative === '' || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) return null;
|
|
33
|
+
return fs.statSync(resolved).isFile() ? resolved : null;
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function resolveOutputWithin(root, candidate) {
|
|
40
|
+
try {
|
|
41
|
+
const realRoot = fs.realpathSync(root);
|
|
42
|
+
const parent = fs.realpathSync(path.dirname(candidate));
|
|
43
|
+
const relative = path.relative(realRoot, parent);
|
|
44
|
+
if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) return null;
|
|
45
|
+
if (!fs.existsSync(candidate)) return candidate;
|
|
46
|
+
return resolveFileWithin(realRoot, candidate);
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
27
52
|
function parseFrontmatter(content) {
|
|
28
53
|
if (!content.startsWith('---')) return null;
|
|
29
54
|
const end = content.indexOf('---', 3);
|
|
@@ -99,8 +124,10 @@ class VaultManager {
|
|
|
99
124
|
this.ensureStructure();
|
|
100
125
|
const safe = safeFilename(artifact.entity || artifact.claim_id);
|
|
101
126
|
const fp = path.join(this._base, 'beliefs', `${safe}.md`);
|
|
102
|
-
|
|
103
|
-
|
|
127
|
+
const output = resolveOutputWithin(this._base, fp);
|
|
128
|
+
if (!output) throw new Error(`Refusing to write outside vault: ${fp}`);
|
|
129
|
+
fs.writeFileSync(output, beliefToMarkdown(artifact), 'utf-8');
|
|
130
|
+
return { status: 'written', directory: 'beliefs', path: output, claim_id: artifact.claim_id, entity: artifact.entity };
|
|
104
131
|
}
|
|
105
132
|
|
|
106
133
|
readBelief(entity) {
|
|
@@ -114,8 +141,10 @@ class VaultManager {
|
|
|
114
141
|
if (!match) return null;
|
|
115
142
|
fp = match;
|
|
116
143
|
}
|
|
117
|
-
const
|
|
118
|
-
|
|
144
|
+
const safePath = resolveFileWithin(beliefsDir, fp);
|
|
145
|
+
if (!safePath) return null;
|
|
146
|
+
const content = fs.readFileSync(safePath, 'utf-8');
|
|
147
|
+
return { path: safePath, frontmatter: parseFrontmatter(content) || {}, body: extractBody(content) };
|
|
119
148
|
}
|
|
120
149
|
|
|
121
150
|
listBeliefs() {
|
|
@@ -152,12 +181,14 @@ class VaultManager {
|
|
|
152
181
|
const ts = timestamp();
|
|
153
182
|
const safe = safeFilename(artifact.title || artifact.challenges || 'check');
|
|
154
183
|
const fp = path.join(this._base, 'verification', `${ts}_${safe}.md`);
|
|
184
|
+
const output = resolveOutputWithin(this._base, fp);
|
|
185
|
+
if (!output) throw new Error(`Refusing to write outside vault: ${fp}`);
|
|
155
186
|
const md = `---\nchallenges: ${artifact.challenges}\nresult: ${artifact.result}\nconfidence_delta: ${artifact.confidence_delta >= 0 ? '+' : ''}${artifact.confidence_delta.toFixed(2)}\nchecked_at: ${artifact.checked_at || nowISO()}\nmethod: ${artifact.method || ''}\n---\n\n# ${artifact.title || ''}\n\n${artifact.body || ''}\n`;
|
|
156
|
-
fs.writeFileSync(
|
|
187
|
+
fs.writeFileSync(output, md, 'utf-8');
|
|
157
188
|
if (artifact.result === 'confirmed' && artifact.challenges) {
|
|
158
189
|
this._updateBeliefConfidence(artifact.challenges, artifact.confidence_delta);
|
|
159
190
|
}
|
|
160
|
-
return { status: 'written', directory: 'verification', path:
|
|
191
|
+
return { status: 'written', directory: 'verification', path: output, challenges: artifact.challenges, result: artifact.result };
|
|
161
192
|
}
|
|
162
193
|
|
|
163
194
|
writeAction(title, content, actionType = 'report') {
|
|
@@ -165,8 +196,10 @@ class VaultManager {
|
|
|
165
196
|
const ts = timestamp();
|
|
166
197
|
const safe = safeFilename(title);
|
|
167
198
|
const fp = path.join(this._base, 'actions', `${ts}_${safe}.md`);
|
|
168
|
-
|
|
169
|
-
|
|
199
|
+
const output = resolveOutputWithin(this._base, fp);
|
|
200
|
+
if (!output) throw new Error(`Refusing to write outside vault: ${fp}`);
|
|
201
|
+
fs.writeFileSync(output, `---\ntype: ${actionType}\ntimestamp: ${ts}\n---\n\n# ${title}\n\n${content}\n`, 'utf-8');
|
|
202
|
+
return { status: 'written', directory: 'actions', path: output, type: actionType };
|
|
170
203
|
}
|
|
171
204
|
|
|
172
205
|
markBeliefsStaleForFiles(changedFiles) {
|
|
@@ -224,8 +257,9 @@ class VaultManager {
|
|
|
224
257
|
const results = [];
|
|
225
258
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
226
259
|
const full = path.join(dir, entry.name);
|
|
260
|
+
if (entry.isSymbolicLink()) continue;
|
|
227
261
|
if (entry.isDirectory()) results.push(...this._rglob(full, ext));
|
|
228
|
-
else if (entry.name.endsWith(ext)) results.push(full);
|
|
262
|
+
else if (entry.name.endsWith(ext) && resolveFileWithin(dir, full)) results.push(full);
|
|
229
263
|
}
|
|
230
264
|
return results.sort();
|
|
231
265
|
}
|
|
@@ -233,5 +267,5 @@ class VaultManager {
|
|
|
233
267
|
|
|
234
268
|
module.exports = {
|
|
235
269
|
VaultManager, safeFilename, parseFrontmatter, extractSources, extractBody,
|
|
236
|
-
beliefToMarkdown, nowISO, timestamp, SOURCE_EXTS,
|
|
270
|
+
beliefToMarkdown, nowISO, timestamp, SOURCE_EXTS, resolveFileWithin, resolveOutputWithin,
|
|
237
271
|
};
|
package/js/workspace.js
CHANGED
|
@@ -9,6 +9,18 @@ const fs = require('fs');
|
|
|
9
9
|
const path = require('path');
|
|
10
10
|
const { SOURCE_EXTS } = require('./vault');
|
|
11
11
|
|
|
12
|
+
function resolveFileWithin(root, candidate) {
|
|
13
|
+
try {
|
|
14
|
+
const realRoot = fs.realpathSync(root);
|
|
15
|
+
const resolved = fs.realpathSync(candidate);
|
|
16
|
+
const relative = path.relative(realRoot, resolved);
|
|
17
|
+
if (relative === '' || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) return null;
|
|
18
|
+
return resolved;
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
12
24
|
class WorkspaceChangeListener {
|
|
13
25
|
constructor(vault, compiler, verifier, changePipe, projectDir) {
|
|
14
26
|
this._vault = vault;
|
|
@@ -34,7 +46,9 @@ class WorkspaceChangeListener {
|
|
|
34
46
|
if (e.isDirectory()) { walk(full, depth + 1); continue; }
|
|
35
47
|
if (!SOURCE_EXTS.has(path.extname(e.name))) continue;
|
|
36
48
|
try {
|
|
37
|
-
const
|
|
49
|
+
const safePath = resolveFileWithin(this._projectDir, full);
|
|
50
|
+
if (!safePath) continue;
|
|
51
|
+
const stat = fs.statSync(safePath);
|
|
38
52
|
const mtime = stat.mtimeMs;
|
|
39
53
|
const rel = path.relative(this._projectDir, full).replace(/\\/g, '/');
|
|
40
54
|
currentFiles[rel] = mtime;
|
|
@@ -61,8 +75,8 @@ class WorkspaceChangeListener {
|
|
|
61
75
|
// Recompile changed files
|
|
62
76
|
for (const rel of allChanged.slice(0, 20)) {
|
|
63
77
|
try {
|
|
64
|
-
const fp = path.join(this._projectDir, rel);
|
|
65
|
-
if (
|
|
78
|
+
const fp = resolveFileWithin(this._projectDir, path.join(this._projectDir, rel));
|
|
79
|
+
if (fp) {
|
|
66
80
|
const dir = path.dirname(fp);
|
|
67
81
|
const result = this._compiler.compileDirectory(dir, 1);
|
|
68
82
|
beliefsRecompiled += result.beliefs_written;
|
|
@@ -113,4 +127,4 @@ class WorkspaceChangeListener {
|
|
|
113
127
|
}
|
|
114
128
|
}
|
|
115
129
|
|
|
116
|
-
module.exports = { WorkspaceChangeListener };
|
|
130
|
+
module.exports = { WorkspaceChangeListener, resolveFileWithin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "entroly-wasm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "Local proxy that cuts your Claude / OpenAI / Gemini bill 70%+. Drop-in for Cursor, Claude Code, Codex, Aider — 30 seconds, no code changes. Pure WebAssembly, no Python dependency.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "pkg/entroly_wasm.d.ts",
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
"entroly-wasm": "./bin/entroly-wasm.js"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
|
+
"LICENSE",
|
|
12
|
+
"NOTICE",
|
|
11
13
|
"index.js",
|
|
12
14
|
"pkg/entroly_wasm_bg.wasm",
|
|
13
15
|
"pkg/entroly_wasm.js",
|
package/pkg/entroly_wasm_bg.wasm
CHANGED
|
Binary file
|