stigmergy 1.2.11 → 1.2.13
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/package.json +1 -1
- package/src/cli/router.js +97 -1
package/package.json
CHANGED
package/src/cli/router.js
CHANGED
|
@@ -45,6 +45,56 @@ function formatBytes(bytes) {
|
|
|
45
45
|
return Math.round(bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i];
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
// Helper function to get appropriate working directory for CLI tools
|
|
49
|
+
function getWorkingDirectoryForTool(toolName) {
|
|
50
|
+
switch (toolName) {
|
|
51
|
+
case 'qwen':
|
|
52
|
+
// For Qwen CLI, use user home directory to avoid module resolution issues
|
|
53
|
+
return os.homedir();
|
|
54
|
+
case 'claude':
|
|
55
|
+
// For Claude CLI, use user home directory
|
|
56
|
+
return os.homedir();
|
|
57
|
+
case 'gemini':
|
|
58
|
+
// For Gemini CLI, use user home directory
|
|
59
|
+
return os.homedir();
|
|
60
|
+
case 'iflow':
|
|
61
|
+
// For iFlow CLI, use user home directory
|
|
62
|
+
return os.homedir();
|
|
63
|
+
case 'qodercli':
|
|
64
|
+
// For Qoder CLI, use user home directory
|
|
65
|
+
return os.homedir();
|
|
66
|
+
default:
|
|
67
|
+
// For other tools, use current directory
|
|
68
|
+
return process.cwd();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Helper function to add OAuth authentication for CLI tools that support it
|
|
73
|
+
function addOAuthAuthArgs(toolName, existingArgs) {
|
|
74
|
+
const args = [...existingArgs];
|
|
75
|
+
|
|
76
|
+
switch (toolName) {
|
|
77
|
+
case 'qwen':
|
|
78
|
+
// Add OAuth authentication for Qwen CLI to avoid API key errors
|
|
79
|
+
args.unshift('--auth-type', 'qwen-oauth');
|
|
80
|
+
break;
|
|
81
|
+
case 'claude':
|
|
82
|
+
// Claude uses token-based auth, no special args needed
|
|
83
|
+
break;
|
|
84
|
+
case 'gemini':
|
|
85
|
+
// Gemini might support OAuth in future versions
|
|
86
|
+
break;
|
|
87
|
+
case 'iflow':
|
|
88
|
+
// Add web authentication for iFlow if supported
|
|
89
|
+
break;
|
|
90
|
+
default:
|
|
91
|
+
// No special authentication for other tools
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return args;
|
|
96
|
+
}
|
|
97
|
+
|
|
48
98
|
async function main() {
|
|
49
99
|
const args = process.argv.slice(2);
|
|
50
100
|
|
|
@@ -617,6 +667,9 @@ async function main() {
|
|
|
617
667
|
}
|
|
618
668
|
}
|
|
619
669
|
|
|
670
|
+
// Add OAuth authentication for tools that support it
|
|
671
|
+
toolArgs = addOAuthAuthArgs(route.tool, toolArgs);
|
|
672
|
+
|
|
620
673
|
// Use the reliable cross-platform execution function
|
|
621
674
|
try {
|
|
622
675
|
// Validate that the tool exists before attempting to execute
|
|
@@ -757,9 +810,21 @@ async function main() {
|
|
|
757
810
|
console.log(`[DEBUG] Windows unified command: ${execCommand}`);
|
|
758
811
|
}
|
|
759
812
|
|
|
813
|
+
// Set environment for tools that need specific working directories
|
|
814
|
+
const env = { ...process.env };
|
|
815
|
+
if (route.tool === 'qwen') {
|
|
816
|
+
// For Qwen CLI, clear Node.js environment variables to avoid import conflicts
|
|
817
|
+
delete env.NODE_PATH;
|
|
818
|
+
delete env.NODE_OPTIONS;
|
|
819
|
+
// Ensure clean environment
|
|
820
|
+
env.PWD = getWorkingDirectoryForTool(route.tool);
|
|
821
|
+
}
|
|
822
|
+
|
|
760
823
|
const result = await executeCommand(execCommand, execArgs, {
|
|
761
824
|
stdio: 'inherit',
|
|
762
825
|
shell: true,
|
|
826
|
+
cwd: getWorkingDirectoryForTool(route.tool),
|
|
827
|
+
env,
|
|
763
828
|
});
|
|
764
829
|
|
|
765
830
|
if (!result.success) {
|
|
@@ -809,9 +874,21 @@ async function main() {
|
|
|
809
874
|
// For other execution errors, try to execute the command directly
|
|
810
875
|
// which handles cases where the tool executed successfully but returned an error object
|
|
811
876
|
console.log(`[EXEC] Running: ${toolPath} ${toolArgs.join(' ')}`);
|
|
877
|
+
// Set environment for tools that need specific working directories
|
|
878
|
+
const env = { ...process.env };
|
|
879
|
+
if (route.tool === 'qwen') {
|
|
880
|
+
// For Qwen CLI, clear Node.js environment variables to avoid import conflicts
|
|
881
|
+
delete env.NODE_PATH;
|
|
882
|
+
delete env.NODE_OPTIONS;
|
|
883
|
+
// Ensure clean environment
|
|
884
|
+
env.PWD = getWorkingDirectoryForTool(route.tool);
|
|
885
|
+
}
|
|
886
|
+
|
|
812
887
|
const result = await executeCommand(toolPath, toolArgs, {
|
|
813
888
|
stdio: 'inherit',
|
|
814
889
|
shell: true,
|
|
890
|
+
cwd: getWorkingDirectoryForTool(route.tool),
|
|
891
|
+
env,
|
|
815
892
|
});
|
|
816
893
|
|
|
817
894
|
if (!result.success) {
|
|
@@ -1452,6 +1529,9 @@ async function main() {
|
|
|
1452
1529
|
cliPattern,
|
|
1453
1530
|
);
|
|
1454
1531
|
|
|
1532
|
+
// Add OAuth authentication for tools that support it
|
|
1533
|
+
toolArgs = addOAuthAuthArgs(route.tool, toolArgs);
|
|
1534
|
+
|
|
1455
1535
|
// Add debug logging for the final arguments
|
|
1456
1536
|
console.log(`[DEBUG] Final toolArgs: ${JSON.stringify(toolArgs)}`);
|
|
1457
1537
|
} catch (patternError) {
|
|
@@ -1470,7 +1550,10 @@ async function main() {
|
|
|
1470
1550
|
// For other tools, pass the prompt with -p flag
|
|
1471
1551
|
toolArgs = ['-p', `"${route.prompt}"`];
|
|
1472
1552
|
}
|
|
1473
|
-
|
|
1553
|
+
|
|
1554
|
+
// Add OAuth authentication for tools that support it
|
|
1555
|
+
toolArgs = addOAuthAuthArgs(route.tool, toolArgs);
|
|
1556
|
+
|
|
1474
1557
|
// Add debug logging for the fallback arguments
|
|
1475
1558
|
console.log(`[DEBUG] Fallback toolArgs: ${JSON.stringify(toolArgs)}`);
|
|
1476
1559
|
}
|
|
@@ -1651,9 +1734,22 @@ async function main() {
|
|
|
1651
1734
|
// For other execution errors, try to execute the command directly
|
|
1652
1735
|
// which handles cases where the tool executed successfully but returned an error object
|
|
1653
1736
|
console.log(`[EXEC] Running: ${toolPath} ${toolArgs.join(' ')}`);
|
|
1737
|
+
|
|
1738
|
+
// Set environment for tools that need specific working directories
|
|
1739
|
+
const env = { ...process.env };
|
|
1740
|
+
if (route.tool === 'qwen') {
|
|
1741
|
+
// For Qwen CLI, clear Node.js environment variables to avoid import conflicts
|
|
1742
|
+
delete env.NODE_PATH;
|
|
1743
|
+
delete env.NODE_OPTIONS;
|
|
1744
|
+
// Ensure clean environment
|
|
1745
|
+
env.PWD = getWorkingDirectoryForTool(route.tool);
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1654
1748
|
const result = await executeCommand(toolPath, toolArgs, {
|
|
1655
1749
|
stdio: 'inherit',
|
|
1656
1750
|
shell: true,
|
|
1751
|
+
cwd: getWorkingDirectoryForTool(route.tool),
|
|
1752
|
+
env,
|
|
1657
1753
|
});
|
|
1658
1754
|
|
|
1659
1755
|
if (!result.success) {
|