@gotza02/mathinking 3.1.7 → 3.1.8
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/README.md +7 -1
- package/dist/schemas/brain.schema.d.ts +16 -0
- package/dist/schemas/brain.schema.d.ts.map +1 -1
- package/dist/schemas/brain.schema.js +14 -10
- package/dist/schemas/brain.schema.js.map +1 -1
- package/dist/test-new-features.d.ts +2 -0
- package/dist/test-new-features.d.ts.map +1 -0
- package/dist/test-new-features.js +62 -0
- package/dist/test-new-features.js.map +1 -0
- package/dist/tools/orchestrator.d.ts.map +1 -1
- package/dist/tools/orchestrator.js +93 -26
- package/dist/tools/orchestrator.js.map +1 -1
- package/dist/tools/sequential-thinking.d.ts +2 -0
- package/dist/tools/sequential-thinking.d.ts.map +1 -1
- package/dist/tools/sequential-thinking.js +253 -42
- package/dist/tools/sequential-thinking.js.map +1 -1
- package/dist/types/index.d.ts +17 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/dag.d.ts.map +1 -1
- package/dist/utils/dag.js +4 -7
- package/dist/utils/dag.js.map +1 -1
- package/dist/utils/memory.d.ts +2 -2
- package/dist/utils/memory.d.ts.map +1 -1
- package/dist/utils/memory.js +9 -5
- package/dist/utils/memory.js.map +1 -1
- package/dist/utils/mutex.d.ts.map +1 -1
- package/dist/utils/mutex.js +1 -1
- package/dist/utils/mutex.js.map +1 -1
- package/dist/utils/resilience.d.ts.map +1 -1
- package/dist/utils/resilience.js +5 -8
- package/dist/utils/resilience.js.map +1 -1
- package/dist/utils/tool-cache.d.ts +2 -2
- package/dist/utils/tool-cache.d.ts.map +1 -1
- package/dist/utils/tool-cache.js +2 -0
- package/dist/utils/tool-cache.js.map +1 -1
- package/dist/utils/vector-memory.d.ts +1 -1
- package/dist/utils/vector-memory.d.ts.map +1 -1
- package/dist/utils/vector-memory.js +5 -5
- package/dist/utils/vector-memory.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -241,7 +241,13 @@ You can define tasks that only run if a certain condition is met:
|
|
|
241
241
|
|
|
242
242
|
**Full changelog available in [CHANGELOG.md](CHANGELOG.md)**
|
|
243
243
|
|
|
244
|
-
### v3.1.
|
|
244
|
+
### v3.1.8 (Current) - 🛡️ Type Safety & Stability
|
|
245
|
+
- **Fixed:** Critical syntax errors in Regex parsing within the Orchestrator.
|
|
246
|
+
- **Improved:** Enhanced Type Safety across the codebase, removing unused variables and unsafe `any` types.
|
|
247
|
+
- **Fixed:** Logic bug in `resolvePlaceholder` causing undefined results when accessing string properties (like `.length`).
|
|
248
|
+
- **Improved:** Cleaned up dead code and unused imports for better maintainability.
|
|
249
|
+
|
|
250
|
+
### v3.1.7 - 🛡️ Reliability & Validation
|
|
245
251
|
- **Enhanced Plan Validation:** Added strict structural checks for `ExecutionPlan` (ensures `id`, `toolName`, `toolInput`, and `dependencies` exist).
|
|
246
252
|
- **Self-Healing Bridge:** Improved `execute_conclusion` to automatically detect malformed plans and fallback to a safe default "Auto-Plan" to prevent execution crashes.
|
|
247
253
|
- **Clearer Error Reporting:** Validation errors now provide specific details about missing fields instead of generic `undefined` errors.
|
|
@@ -66,5 +66,21 @@ export declare const BrainInputSchema: z.ZodObject<{
|
|
|
66
66
|
optionId: z.ZodOptional<z.ZodString>;
|
|
67
67
|
sourceThoughtIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
68
68
|
branchIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
69
|
+
thinkingStyle: z.ZodOptional<z.ZodEnum<{
|
|
70
|
+
Synthesis: "Synthesis";
|
|
71
|
+
Analytical: "Analytical";
|
|
72
|
+
Creative: "Creative";
|
|
73
|
+
Critical: "Critical";
|
|
74
|
+
Emotional: "Emotional";
|
|
75
|
+
Optimistic: "Optimistic";
|
|
76
|
+
}>>;
|
|
77
|
+
phase: z.ZodOptional<z.ZodEnum<{
|
|
78
|
+
Definition: "Definition";
|
|
79
|
+
Exploration: "Exploration";
|
|
80
|
+
Analysis: "Analysis";
|
|
81
|
+
Evaluation: "Evaluation";
|
|
82
|
+
Synthesis: "Synthesis";
|
|
83
|
+
Conclusion: "Conclusion";
|
|
84
|
+
}>>;
|
|
69
85
|
}, z.core.$strip>;
|
|
70
86
|
//# sourceMappingURL=brain.schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brain.schema.d.ts","sourceRoot":"","sources":["../../src/schemas/brain.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"brain.schema.d.ts","sourceRoot":"","sources":["../../src/schemas/brain.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuE3B,CAAC"}
|
|
@@ -30,7 +30,8 @@ export const BrainInputSchema = z.object({
|
|
|
30
30
|
sessionId: z.string().optional(),
|
|
31
31
|
problemStatement: z.string().optional(),
|
|
32
32
|
thought: z.string().max(10000).optional(),
|
|
33
|
-
thoughtType: z
|
|
33
|
+
thoughtType: z
|
|
34
|
+
.enum([
|
|
34
35
|
'initial_analysis',
|
|
35
36
|
'decomposition',
|
|
36
37
|
'hypothesis',
|
|
@@ -45,7 +46,8 @@ export const BrainInputSchema = z.object({
|
|
|
45
46
|
'option_evaluation',
|
|
46
47
|
'reflection',
|
|
47
48
|
'plan'
|
|
48
|
-
])
|
|
49
|
+
])
|
|
50
|
+
.optional(),
|
|
49
51
|
totalThoughts: z.number().int().min(1).optional(),
|
|
50
52
|
branchFromThoughtId: z.string().optional(),
|
|
51
53
|
branchLabel: z.string().optional(),
|
|
@@ -53,18 +55,20 @@ export const BrainInputSchema = z.object({
|
|
|
53
55
|
deleteThoughtId: z.string().optional(),
|
|
54
56
|
hypothesis: z.string().optional(),
|
|
55
57
|
verificationEvidence: z.string().optional(),
|
|
56
|
-
verificationStatus: z
|
|
57
|
-
'pending',
|
|
58
|
-
|
|
59
|
-
'refuted',
|
|
60
|
-
'partially_verified',
|
|
61
|
-
'needs_more_evidence'
|
|
62
|
-
]).optional(),
|
|
58
|
+
verificationStatus: z
|
|
59
|
+
.enum(['pending', 'verified', 'refuted', 'partially_verified', 'needs_more_evidence'])
|
|
60
|
+
.optional(),
|
|
63
61
|
confidence: z.number().min(0).max(100).optional(),
|
|
64
62
|
force: z.boolean().optional(),
|
|
65
63
|
executionResult: z.any().optional(),
|
|
66
64
|
optionId: z.string().optional(),
|
|
67
65
|
sourceThoughtIds: z.array(z.string()).optional(),
|
|
68
|
-
branchIds: z.array(z.string()).optional()
|
|
66
|
+
branchIds: z.array(z.string()).optional(),
|
|
67
|
+
thinkingStyle: z
|
|
68
|
+
.enum(['Analytical', 'Creative', 'Critical', 'Emotional', 'Optimistic', 'Synthesis'])
|
|
69
|
+
.optional(),
|
|
70
|
+
phase: z
|
|
71
|
+
.enum(['Definition', 'Exploration', 'Analysis', 'Evaluation', 'Synthesis', 'Conclusion'])
|
|
72
|
+
.optional()
|
|
69
73
|
});
|
|
70
74
|
//# sourceMappingURL=brain.schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brain.schema.js","sourceRoot":"","sources":["../../src/schemas/brain.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC;QACb,eAAe;QACf,aAAa;QACb,eAAe;QACf,gBAAgB;QAChB,gBAAgB;QAChB,mBAAmB;QACnB,uBAAuB;QACvB,UAAU;QACV,YAAY;QACZ,aAAa;QACb,eAAe;QACf,gBAAgB;QAChB,eAAe;QACf,gBAAgB;QAChB,eAAe;QACf,mBAAmB;QACnB,gBAAgB;QAChB,oBAAoB;QACpB,kBAAkB;QAClB,kBAAkB;QAClB,eAAe;QACf,SAAS;QACT,QAAQ;QACR,WAAW;QACX,UAAU;KACX,CAAC;IACF,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACvC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;IACzC,WAAW,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"brain.schema.js","sourceRoot":"","sources":["../../src/schemas/brain.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC;QACb,eAAe;QACf,aAAa;QACb,eAAe;QACf,gBAAgB;QAChB,gBAAgB;QAChB,mBAAmB;QACnB,uBAAuB;QACvB,UAAU;QACV,YAAY;QACZ,aAAa;QACb,eAAe;QACf,gBAAgB;QAChB,eAAe;QACf,gBAAgB;QAChB,eAAe;QACf,mBAAmB;QACnB,gBAAgB;QAChB,oBAAoB;QACpB,kBAAkB;QAClB,kBAAkB;QAClB,eAAe;QACf,SAAS;QACT,QAAQ;QACR,WAAW;QACX,UAAU;KACX,CAAC;IACF,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACvC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;IACzC,WAAW,EAAE,CAAC;SACX,IAAI,CAAC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,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IACzC,aAAa,EAAE,CAAC;SACb,IAAI,CAAC,CAAC,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;SACpF,QAAQ,EAAE;IACb,KAAK,EAAE,CAAC;SACL,IAAI,CAAC,CAAC,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;SACxF,QAAQ,EAAE;CACd,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-new-features.d.ts","sourceRoot":"","sources":["../src/test-new-features.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { thinkingManager } from './tools/sequential-thinking.js';
|
|
2
|
+
import { vectorMemory } from './utils/vector-memory.js';
|
|
3
|
+
async function runTest() {
|
|
4
|
+
console.log('🚀 Starting Test for New Features (Actions 1, 2, 3, 5)..., ');
|
|
5
|
+
// 1. Pre-seed memory for Action 5 (Memory Integration)
|
|
6
|
+
,
|
|
7
|
+
// 1. Pre-seed memory for Action 5 (Memory Integration)
|
|
8
|
+
console.log('--- Step 1: Pre-seeding Memory ---, ');, await vectorMemory.add('How to setup a secure web server with SSL and firewall.', {
|
|
9
|
+
patterns: ['security-best-practices', 'nginx-config'],
|
|
10
|
+
improvements: ['Use Certbot for SSL', 'Enable UFW']
|
|
11
|
+
})));
|
|
12
|
+
console.log('✅ Memory seeded., ');
|
|
13
|
+
// 2. Start Session for Action 1 & 3 (Style, Phase, Complexity)
|
|
14
|
+
,
|
|
15
|
+
// 2. Start Session for Action 1 & 3 (Style, Phase, Complexity)
|
|
16
|
+
console.log('--- Step 2: Starting Session (Complexity & Style) ---, ');));
|
|
17
|
+
const startResult = await thinkingManager.process({
|
|
18
|
+
action: 'start_session',
|
|
19
|
+
problemStatement: 'I need to design a complex cloud architecture for a global e-commerce platform that is highly scalable and secure.',
|
|
20
|
+
thinkingStyle: 'Analytical',
|
|
21
|
+
phase: 'Definition'
|
|
22
|
+
});
|
|
23
|
+
console.log('Message:', startResult.message);
|
|
24
|
+
if (startResult.success) {
|
|
25
|
+
console.log('✅ Session started successfully.');
|
|
26
|
+
}
|
|
27
|
+
console.log('');
|
|
28
|
+
// 3. Add Thought for Action 2, 3, 5 (Routing, Tool Recs, Memory)
|
|
29
|
+
console.log('--- Step 3: Adding Initial Thought (Routing & Tool Recs) ---, '););
|
|
30
|
+
const thought1 = await thinkingManager.process({
|
|
31
|
+
action: 'add_thought',
|
|
32
|
+
sessionId: startResult.sessionId,
|
|
33
|
+
thought: 'I will begin by breaking down the requirements for the cloud architecture.',
|
|
34
|
+
thoughtType: 'decomposition'
|
|
35
|
+
});
|
|
36
|
+
console.log('Thought Result:', thought1.message);
|
|
37
|
+
console.log('Guidance (includes Complexity):', thought1.guidance);
|
|
38
|
+
console.log('Recommended Tools:', thought1.recommendedTools?.map((t) => t.toolName).join(', '));
|
|
39
|
+
if (thought1.metadata?.relatedMemories) {
|
|
40
|
+
console.log('✅ Related Memories Found:', thought1.metadata.relatedMemories.length);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.log('❌ No related memories found (Check vector search if this is unexpected)');
|
|
44
|
+
}
|
|
45
|
+
console.log('');
|
|
46
|
+
// 4. Test Style & Phase Change
|
|
47
|
+
console.log('--- Step 4: Changing Style & Phase ---, '););
|
|
48
|
+
const thought2 = await thinkingManager.process({
|
|
49
|
+
action: 'add_thought',
|
|
50
|
+
sessionId: startResult.sessionId,
|
|
51
|
+
thought: 'What if we use serverless components to reduce cost?',
|
|
52
|
+
thinkingStyle: 'Creative',
|
|
53
|
+
phase: 'Exploration'
|
|
54
|
+
});
|
|
55
|
+
console.log('Thought 2 Message:', thought2.message);
|
|
56
|
+
console.log('New Guidance:', thought2.guidance);
|
|
57
|
+
console.log('Recommended Tools for Exploration:', thought2.recommendedTools?.map((t) => t.toolName).join(', '));
|
|
58
|
+
console.log('');
|
|
59
|
+
console.log('🏁 Test completed.');
|
|
60
|
+
}
|
|
61
|
+
runTest().catch(console.error);
|
|
62
|
+
//# sourceMappingURL=test-new-features.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-new-features.js","sourceRoot":"","sources":["../src/test-new-features.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,KAAK,UAAU,OAAO;IAClB,OAAO,CAAC,GAAG,CAAC,0DAA0D,EAC1E,GAAG;IAEC,uDAAuD;;IAAvD,uDAAuD;IACvD,OAAO,CAAC,GAAG,CAAC,mCAAmC,EACnD,GAAG,EACC,MAAM,YAAY,CAAC,GAAG,CAAC,yDAAyD,EAAE;QAC9E,QAAQ,EAAE,CAAC,yBAAyB,EAAE,cAAc,CAAC;QACrD,YAAY,EAAE,CAAC,qBAAqB,EAAE,YAAY,CAAC;KACtD,CAAC,CAAA,CAAA,CAAC;IACH,OAAO,CAAC,GAAG,CAAC,iBAAiB,EACjC,GAAG;IAEC,+DAA+D;;IAA/D,+DAA+D;IAC/D,OAAO,CAAC,GAAG,CAAC,sDAAsD,EACtE,GAAG,CAAA,CAAA,CAAA;IACC,MAAM,WAAW,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC;QAC9C,MAAM,EAAE,eAAe;QACvB,gBAAgB,EAAE,oHAAoH;QACtI,aAAa,EAAE,YAAY;QAC3B,KAAK,EAAE,YAAY;KACtB,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC7C,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;IACnD,CAAC;I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H,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IACpD,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAChD,OAAO,CAAC,GAAG,CAAC,oCAAoC,EAAG,QAAgB,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9H,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAEhB,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;AACtC,CAAC;AAED,OAAO,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/tools/orchestrator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/tools/orchestrator.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAKV,iBAAiB,EACjB,kBAAkB,EAElB,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAE3B,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,gBAAgB,CAA2C;IACnE,OAAO,CAAC,mBAAmB,CAAa;IAExC,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,OAAO,CAAC,CAAoB;IAGpC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiE;IAG/F,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAM;IAE3C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAM;gBAE/B,MAAM,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,kBAAkB,CAAC,EAAE,MAAM,CAAA;KAAE;IAQzE;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAOnC;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;;OAGG;YACW,2BAA2B;IA4BzC;;;OAGG;IACH,OAAO,CAAC,YAAY;YAwBN,QAAQ;IAoBtB,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,oBAAoB;IA6e5B,YAAY,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IAIxC,kBAAkB,IAAI,MAAM,EAAE;IAIxB,OAAO,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA2BpE,OAAO,CAAC,UAAU;IAuBlB,OAAO,CAAC,YAAY;YA2CN,WAAW;YA6IX,WAAW;YAqMX,iBAAiB;IAqB/B,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,YAAY;IAiCpB,OAAO,CAAC,kBAAkB;YAmDZ,kBAAkB;IAShC,OAAO,CAAC,kBAAkB;IAuB1B,OAAO,CAAC,sBAAsB;CA4B/B;AAED,eAAO,MAAM,mBAAmB,qBAA4B,CAAC"}
|
|
@@ -12,12 +12,10 @@ export class OrchestratorManager {
|
|
|
12
12
|
minDelayMs = 1000; // Default 1s, configurable via setter
|
|
13
13
|
quickJS;
|
|
14
14
|
// 🔒 Security: Allowed directory roots for file operations
|
|
15
|
-
ALLOWED_ROOTS = [
|
|
16
|
-
process.cwd(),
|
|
17
|
-
path.join(os.homedir(), 'tmp', 'mathinking')
|
|
18
|
-
];
|
|
15
|
+
ALLOWED_ROOTS = [process.cwd(), path.join(os.homedir(), 'tmp', 'mathinking')];
|
|
19
16
|
// 🔧 Resource management: Limit concurrent tasks to prevent exhaustion
|
|
20
17
|
MAX_CONCURRENT_TASKS = 10; // Maximum parallel tasks per layer
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
19
|
MAX_TOTAL_CONCURRENT = 20; // Maximum across all layers
|
|
22
20
|
constructor(config) {
|
|
23
21
|
// 🔧 Allow custom configuration
|
|
@@ -49,7 +47,7 @@ export class OrchestratorManager {
|
|
|
49
47
|
const results = [];
|
|
50
48
|
const executing = [];
|
|
51
49
|
for (const task of tasks) {
|
|
52
|
-
const promise = task().then(result => {
|
|
50
|
+
const promise = task().then((result) => {
|
|
53
51
|
// Remove from executing array after completion
|
|
54
52
|
const idx = executing.indexOf(promise);
|
|
55
53
|
if (idx > -1) {
|
|
@@ -75,7 +73,7 @@ export class OrchestratorManager {
|
|
|
75
73
|
// Resolve to absolute path (also normalizes ../ etc)
|
|
76
74
|
const resolvedPath = path.resolve(expandedPath);
|
|
77
75
|
// Check if path is within allowed roots
|
|
78
|
-
const isAllowed = this.ALLOWED_ROOTS.some(root => {
|
|
76
|
+
const isAllowed = this.ALLOWED_ROOTS.some((root) => {
|
|
79
77
|
const resolvedRoot = path.resolve(root);
|
|
80
78
|
return resolvedPath.startsWith(resolvedRoot);
|
|
81
79
|
});
|
|
@@ -85,6 +83,7 @@ export class OrchestratorManager {
|
|
|
85
83
|
}
|
|
86
84
|
return resolvedPath;
|
|
87
85
|
}
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
87
|
async safeEval(code) {
|
|
89
88
|
if (!this.quickJS) {
|
|
90
89
|
this.quickJS = await getQuickJS();
|
|
@@ -357,11 +356,14 @@ export class OrchestratorManager {
|
|
|
357
356
|
const response = await fetch(`https://api.search.brave.com/res/v1/web/search?q=${encodeURIComponent(query)}&count=${numResults}&freshness=${freshParam}`, {
|
|
358
357
|
headers: { Accept: 'application/json', 'X-Subscription-Token': braveApiKey }
|
|
359
358
|
});
|
|
359
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
360
360
|
const data = await response.json();
|
|
361
361
|
return {
|
|
362
362
|
query,
|
|
363
363
|
source: 'Brave API',
|
|
364
|
-
results:
|
|
364
|
+
results:
|
|
365
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
366
|
+
data.web?.results?.map((r) => ({
|
|
365
367
|
title: r.title,
|
|
366
368
|
snippet: r.description,
|
|
367
369
|
url: r.url
|
|
@@ -398,11 +400,13 @@ export class OrchestratorManager {
|
|
|
398
400
|
startPublishedDate: startPublishedDate
|
|
399
401
|
})
|
|
400
402
|
});
|
|
403
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
401
404
|
const data = await response.json();
|
|
402
405
|
if (data.results) {
|
|
403
406
|
return {
|
|
404
407
|
query,
|
|
405
408
|
source: 'Exa.ai',
|
|
409
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
406
410
|
results: data.results.map((r) => ({
|
|
407
411
|
title: r.title || r.url,
|
|
408
412
|
snippet: r.text || r.highlight || '',
|
|
@@ -421,11 +425,13 @@ export class OrchestratorManager {
|
|
|
421
425
|
const dateRestrict = getFreshnessParams('google');
|
|
422
426
|
const searchUrl = `https://www.googleapis.com/customsearch/v1?key=${process.env.GOOGLE_SEARCH_API_KEY}&cx=${process.env.GOOGLE_SEARCH_CX}&q=${encodeURIComponent(query)}&num=${numResults}&dateRestrict=${dateRestrict}`;
|
|
423
427
|
const response = await fetch(searchUrl);
|
|
428
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
424
429
|
const data = await response.json();
|
|
425
430
|
if (data.items) {
|
|
426
431
|
return {
|
|
427
432
|
query,
|
|
428
433
|
source: 'Google Custom Search',
|
|
434
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
429
435
|
results: data.items.map((item) => ({
|
|
430
436
|
title: item.title,
|
|
431
437
|
snippet: item.snippet,
|
|
@@ -444,11 +450,13 @@ export class OrchestratorManager {
|
|
|
444
450
|
return {
|
|
445
451
|
query,
|
|
446
452
|
source: 'System',
|
|
447
|
-
results: [
|
|
453
|
+
results: [
|
|
454
|
+
{
|
|
448
455
|
title: 'Configuration Required',
|
|
449
456
|
snippet: 'Web search scraping is disabled due to reliability issues. Please configure GOOGLE_SEARCH_API_KEY (and CX) or BRAVE_SEARCH_API_KEY in your environment to enable search functionality.',
|
|
450
457
|
url: 'https://console.cloud.google.com/apis/credentials'
|
|
451
|
-
}
|
|
458
|
+
}
|
|
459
|
+
],
|
|
452
460
|
timestamp: new Date().toISOString()
|
|
453
461
|
};
|
|
454
462
|
}
|
|
@@ -496,6 +504,7 @@ export class OrchestratorManager {
|
|
|
496
504
|
execute: async (input) => {
|
|
497
505
|
const { content, metadata } = input;
|
|
498
506
|
const { vectorMemory } = await import('../utils/vector-memory.js');
|
|
507
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
499
508
|
const entry = await vectorMemory.add(content, metadata || {});
|
|
500
509
|
return { success: true, id: entry.id, message: 'Saved to vector memory' };
|
|
501
510
|
}
|
|
@@ -521,7 +530,7 @@ export class OrchestratorManager {
|
|
|
521
530
|
resultExpr = resultExpr.replace(new RegExp(`\\b${key}\\b`, 'g'), String(value));
|
|
522
531
|
}
|
|
523
532
|
try {
|
|
524
|
-
if (/^[\d\s
|
|
533
|
+
if (/^[\d\s+\*/().,MathPIE_a-zA-Z-]+$/.test(resultExpr) &&
|
|
525
534
|
!resultExpr.includes('process') &&
|
|
526
535
|
!resultExpr.includes('require') &&
|
|
527
536
|
!resultExpr.includes('import')) {
|
|
@@ -654,9 +663,9 @@ export class OrchestratorManager {
|
|
|
654
663
|
console.log(` Concurrency limit: ${concurrentLimit}/${this.MAX_CONCURRENT_TASKS}`);
|
|
655
664
|
const layerTaskFunctions = layer.map((taskId) => async () => {
|
|
656
665
|
const task = taskMap.get(taskId);
|
|
657
|
-
const dependencies = task.dependencies.map(d => taskResults.find(r => r.taskId === d));
|
|
658
|
-
const failedDep = dependencies.find(d => d?.status === 'failed');
|
|
659
|
-
const skippedDep = dependencies.find(d => d?.status === 'skipped');
|
|
666
|
+
const dependencies = (task.dependencies || []).map((d) => taskResults.find((r) => r.taskId === d));
|
|
667
|
+
const failedDep = dependencies.find((d) => d?.status === 'failed');
|
|
668
|
+
const skippedDep = dependencies.find((d) => d?.status === 'skipped');
|
|
660
669
|
if (failedDep) {
|
|
661
670
|
console.log(` ○ Skipped: ${task.name} (Dependency "${failedDep.taskName}" failed)`);
|
|
662
671
|
return {
|
|
@@ -762,14 +771,36 @@ export class OrchestratorManager {
|
|
|
762
771
|
const tool = this.toolRegistry[task.toolName];
|
|
763
772
|
if (!tool) {
|
|
764
773
|
const error = `Tool "${task.toolName}" not found`;
|
|
765
|
-
errors.push({
|
|
766
|
-
|
|
774
|
+
errors.push({
|
|
775
|
+
taskId: task.id,
|
|
776
|
+
taskName: task.name,
|
|
777
|
+
error,
|
|
778
|
+
timestamp: new Date().toISOString()
|
|
779
|
+
});
|
|
780
|
+
return {
|
|
781
|
+
taskId: task.id,
|
|
782
|
+
taskName: task.name,
|
|
783
|
+
status: 'failed',
|
|
784
|
+
error,
|
|
785
|
+
startTime: startTime.toISOString(),
|
|
786
|
+
endTime: new Date().toISOString(),
|
|
787
|
+
duration: 0,
|
|
788
|
+
retries: 0
|
|
789
|
+
};
|
|
767
790
|
}
|
|
768
791
|
if (task.runIf) {
|
|
769
792
|
const isConditionMet = await this.evaluateCondition(task.runIf, taskOutputs);
|
|
770
793
|
if (!isConditionMet) {
|
|
771
794
|
console.log(` ○ Skipped: ${task.name} (Condition "${task.runIf}" not met)`);
|
|
772
|
-
return {
|
|
795
|
+
return {
|
|
796
|
+
taskId: task.id,
|
|
797
|
+
taskName: task.name,
|
|
798
|
+
status: 'skipped',
|
|
799
|
+
startTime: startTime.toISOString(),
|
|
800
|
+
endTime: new Date().toISOString(),
|
|
801
|
+
duration: 0,
|
|
802
|
+
retries: 0
|
|
803
|
+
};
|
|
773
804
|
}
|
|
774
805
|
}
|
|
775
806
|
while (retries <= maxRetries) {
|
|
@@ -796,13 +827,18 @@ export class OrchestratorManager {
|
|
|
796
827
|
catch (err) {
|
|
797
828
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
798
829
|
if (repairAttempts < 3) {
|
|
799
|
-
const recovery = await resilienceManager.diagnose(err, {
|
|
830
|
+
const recovery = await resilienceManager.diagnose(err, {
|
|
831
|
+
...task,
|
|
832
|
+
toolInput: currentInput
|
|
833
|
+
});
|
|
800
834
|
if (recovery) {
|
|
801
835
|
console.log(` 🚑 Self-Healing (${recovery.type}): ${recovery.description}`);
|
|
802
836
|
repairAttempts++; // Increment guard
|
|
803
837
|
if (recovery.type === 'run_command' && recovery.payload?.command) {
|
|
804
838
|
try {
|
|
805
|
-
await this.toolRegistry['shell_execute'].execute({
|
|
839
|
+
await this.toolRegistry['shell_execute'].execute({
|
|
840
|
+
command: recovery.payload.command
|
|
841
|
+
});
|
|
806
842
|
// continue; // Let it fall through to retry logic
|
|
807
843
|
}
|
|
808
844
|
catch (fixErr) {
|
|
@@ -834,7 +870,10 @@ export class OrchestratorManager {
|
|
|
834
870
|
const replanResult = await resilienceManager.requestStrategicReplan(errorMessage, task);
|
|
835
871
|
if (replanResult?.success && replanResult.executionPlan) {
|
|
836
872
|
console.log(` ✨ MIRACLE! Brain provided a recovery plan: ${replanResult.executionPlan.name}`);
|
|
837
|
-
const subResult = await this.executePlan({
|
|
873
|
+
const subResult = await this.executePlan({
|
|
874
|
+
action: 'execute_plan',
|
|
875
|
+
plan: replanResult.executionPlan
|
|
876
|
+
});
|
|
838
877
|
if (subResult.success) {
|
|
839
878
|
return {
|
|
840
879
|
taskId: task.id,
|
|
@@ -849,12 +888,35 @@ export class OrchestratorManager {
|
|
|
849
888
|
}
|
|
850
889
|
}
|
|
851
890
|
console.log(` ✗ Failed: ${task.name} - ${errorMessage}`);
|
|
852
|
-
errors.push({
|
|
853
|
-
|
|
891
|
+
errors.push({
|
|
892
|
+
taskId: task.id,
|
|
893
|
+
taskName: task.name,
|
|
894
|
+
error: errorMessage,
|
|
895
|
+
timestamp: new Date().toISOString()
|
|
896
|
+
});
|
|
897
|
+
return {
|
|
898
|
+
taskId: task.id,
|
|
899
|
+
taskName: task.name,
|
|
900
|
+
status: 'failed',
|
|
901
|
+
error: errorMessage,
|
|
902
|
+
startTime: startTime.toISOString(),
|
|
903
|
+
endTime: new Date().toISOString(),
|
|
904
|
+
duration: new Date().getTime() - startTime.getTime(),
|
|
905
|
+
retries: retries - 1
|
|
906
|
+
};
|
|
854
907
|
}
|
|
855
908
|
}
|
|
856
909
|
}
|
|
857
|
-
return {
|
|
910
|
+
return {
|
|
911
|
+
taskId: task.id,
|
|
912
|
+
taskName: task.name,
|
|
913
|
+
status: 'failed',
|
|
914
|
+
error: 'Unknown',
|
|
915
|
+
startTime: startTime.toISOString(),
|
|
916
|
+
endTime: new Date().toISOString(),
|
|
917
|
+
duration: 0,
|
|
918
|
+
retries
|
|
919
|
+
};
|
|
858
920
|
}
|
|
859
921
|
async evaluateCondition(condition, taskOutputs) {
|
|
860
922
|
const resolvedCondition = this.resolveValue(condition, taskOutputs, true);
|
|
@@ -884,14 +946,14 @@ export class OrchestratorManager {
|
|
|
884
946
|
resolveValue(value, taskOutputs, safeForEval = false) {
|
|
885
947
|
if (typeof value === 'string') {
|
|
886
948
|
const placeholderRegex = /\$\{([^}]+)\}/g;
|
|
887
|
-
const singleMatch = value.match(/^\$\{([^}]+)
|
|
949
|
+
const singleMatch = value.match(/^\$\{([^}]+)}$/);
|
|
888
950
|
if (singleMatch) {
|
|
889
951
|
return this.resolvePlaceholder(singleMatch[1], taskOutputs);
|
|
890
952
|
}
|
|
891
953
|
return value.replace(placeholderRegex, (_, placeholder) => {
|
|
892
954
|
const resolved = this.resolvePlaceholder(placeholder, taskOutputs);
|
|
893
955
|
if (safeForEval && typeof resolved === 'string') {
|
|
894
|
-
return resolved.replace(/\\/g, '\\\\').replace(/"/g, '
|
|
956
|
+
return resolved.replace(/\\/g, '\\\\').replace(/"/g, '"');
|
|
895
957
|
}
|
|
896
958
|
return String(resolved);
|
|
897
959
|
});
|
|
@@ -934,8 +996,13 @@ export class OrchestratorManager {
|
|
|
934
996
|
current = current[parts[i]];
|
|
935
997
|
}
|
|
936
998
|
else if (typeof current === 'string') {
|
|
937
|
-
|
|
938
|
-
|
|
999
|
+
if (parts[i] === 'length') {
|
|
1000
|
+
current = current.length;
|
|
1001
|
+
}
|
|
1002
|
+
else {
|
|
1003
|
+
// For string types, try to access as array (for backwards compatibility)
|
|
1004
|
+
current = current[parseInt(parts[i])];
|
|
1005
|
+
}
|
|
939
1006
|
if (current === undefined) {
|
|
940
1007
|
return undefined;
|
|
941
1008
|
}
|