@gotza02/seq-thinking 1.1.0

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 (106) hide show
  1. package/README.md +149 -0
  2. package/SYSTEM_INSTRUCTIONS.md +50 -0
  3. package/agents_test.log +15 -0
  4. package/dist/__tests__/agents.test.d.ts +2 -0
  5. package/dist/__tests__/agents.test.d.ts.map +1 -0
  6. package/dist/__tests__/agents.test.js +673 -0
  7. package/dist/__tests__/agents.test.js.map +1 -0
  8. package/dist/__tests__/mcp-server.test.d.ts +2 -0
  9. package/dist/__tests__/mcp-server.test.d.ts.map +1 -0
  10. package/dist/__tests__/mcp-server.test.js +315 -0
  11. package/dist/__tests__/mcp-server.test.js.map +1 -0
  12. package/dist/__tests__/sequential-thinking.test.d.ts +2 -0
  13. package/dist/__tests__/sequential-thinking.test.d.ts.map +1 -0
  14. package/dist/__tests__/sequential-thinking.test.js +545 -0
  15. package/dist/__tests__/sequential-thinking.test.js.map +1 -0
  16. package/dist/__tests__/swarm-coordinator.test.d.ts +2 -0
  17. package/dist/__tests__/swarm-coordinator.test.d.ts.map +1 -0
  18. package/dist/__tests__/swarm-coordinator.test.js +606 -0
  19. package/dist/__tests__/swarm-coordinator.test.js.map +1 -0
  20. package/dist/__tests__/types.test.d.ts +2 -0
  21. package/dist/__tests__/types.test.d.ts.map +1 -0
  22. package/dist/__tests__/types.test.js +741 -0
  23. package/dist/__tests__/types.test.js.map +1 -0
  24. package/dist/__tests__/utils.test.d.ts +2 -0
  25. package/dist/__tests__/utils.test.d.ts.map +1 -0
  26. package/dist/__tests__/utils.test.js +264 -0
  27. package/dist/__tests__/utils.test.js.map +1 -0
  28. package/dist/agents/base-agent.d.ts +126 -0
  29. package/dist/agents/base-agent.d.ts.map +1 -0
  30. package/dist/agents/base-agent.js +214 -0
  31. package/dist/agents/base-agent.js.map +1 -0
  32. package/dist/agents/critic-agent.d.ts +134 -0
  33. package/dist/agents/critic-agent.d.ts.map +1 -0
  34. package/dist/agents/critic-agent.js +484 -0
  35. package/dist/agents/critic-agent.js.map +1 -0
  36. package/dist/agents/index.d.ts +11 -0
  37. package/dist/agents/index.d.ts.map +1 -0
  38. package/dist/agents/index.js +11 -0
  39. package/dist/agents/index.js.map +1 -0
  40. package/dist/agents/meta-reasoning-agent.d.ts +143 -0
  41. package/dist/agents/meta-reasoning-agent.d.ts.map +1 -0
  42. package/dist/agents/meta-reasoning-agent.js +532 -0
  43. package/dist/agents/meta-reasoning-agent.js.map +1 -0
  44. package/dist/agents/reasoner-agent.d.ts +75 -0
  45. package/dist/agents/reasoner-agent.d.ts.map +1 -0
  46. package/dist/agents/reasoner-agent.js +226 -0
  47. package/dist/agents/reasoner-agent.js.map +1 -0
  48. package/dist/agents/synthesizer-agent.d.ts +174 -0
  49. package/dist/agents/synthesizer-agent.d.ts.map +1 -0
  50. package/dist/agents/synthesizer-agent.js +583 -0
  51. package/dist/agents/synthesizer-agent.js.map +1 -0
  52. package/dist/index.d.ts +21 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +27 -0
  55. package/dist/index.js.map +1 -0
  56. package/dist/mcp-server.d.ts +823 -0
  57. package/dist/mcp-server.d.ts.map +1 -0
  58. package/dist/mcp-server.js +377 -0
  59. package/dist/mcp-server.js.map +1 -0
  60. package/dist/sequential-thinking.d.ts +91 -0
  61. package/dist/sequential-thinking.d.ts.map +1 -0
  62. package/dist/sequential-thinking.js +540 -0
  63. package/dist/sequential-thinking.js.map +1 -0
  64. package/dist/swarm-coordinator.d.ts +188 -0
  65. package/dist/swarm-coordinator.d.ts.map +1 -0
  66. package/dist/swarm-coordinator.js +627 -0
  67. package/dist/swarm-coordinator.js.map +1 -0
  68. package/dist/types/index.d.ts +806 -0
  69. package/dist/types/index.d.ts.map +1 -0
  70. package/dist/types/index.js +279 -0
  71. package/dist/types/index.js.map +1 -0
  72. package/dist/utils/index.d.ts +421 -0
  73. package/dist/utils/index.d.ts.map +1 -0
  74. package/dist/utils/index.js +864 -0
  75. package/dist/utils/index.js.map +1 -0
  76. package/dist/utils/llm-adapter.d.ts +23 -0
  77. package/dist/utils/llm-adapter.d.ts.map +1 -0
  78. package/dist/utils/llm-adapter.js +68 -0
  79. package/dist/utils/llm-adapter.js.map +1 -0
  80. package/dist/utils/persistence.d.ts +33 -0
  81. package/dist/utils/persistence.d.ts.map +1 -0
  82. package/dist/utils/persistence.js +108 -0
  83. package/dist/utils/persistence.js.map +1 -0
  84. package/package.json +41 -0
  85. package/src/__tests__/agents.test.ts +858 -0
  86. package/src/__tests__/mcp-server.test.ts +380 -0
  87. package/src/__tests__/sequential-thinking.test.ts +687 -0
  88. package/src/__tests__/swarm-coordinator.test.ts +903 -0
  89. package/src/__tests__/types.test.ts +839 -0
  90. package/src/__tests__/utils.test.ts +322 -0
  91. package/src/agents/base-agent.ts +285 -0
  92. package/src/agents/critic-agent.ts +582 -0
  93. package/src/agents/index.ts +11 -0
  94. package/src/agents/meta-reasoning-agent.ts +672 -0
  95. package/src/agents/reasoner-agent.ts +312 -0
  96. package/src/agents/synthesizer-agent.ts +758 -0
  97. package/src/index.ts +118 -0
  98. package/src/mcp-server.ts +387 -0
  99. package/src/sequential-thinking.ts +560 -0
  100. package/src/swarm-coordinator.ts +744 -0
  101. package/src/types/index.ts +915 -0
  102. package/src/utils/index.ts +1004 -0
  103. package/src/utils/llm-adapter.ts +76 -0
  104. package/src/utils/persistence.ts +108 -0
  105. package/test_output.log +0 -0
  106. package/tsconfig.json +21 -0
@@ -0,0 +1,76 @@
1
+ /**
2
+ * LLM Adapter to call external CLI tools via child_process
3
+ * @module utils/llm-adapter
4
+ */
5
+
6
+ import { execSync } from 'child_process';
7
+
8
+ export interface LLMResponse {
9
+ content: string;
10
+ error?: string;
11
+ }
12
+
13
+ export class LLMAdapter {
14
+ /**
15
+ * Main entry point to call an LLM based on provider
16
+ */
17
+ static async call(prompt: string, systemPrompt?: string): Promise<LLMResponse> {
18
+ const provider = process.env.provider || 'gemini';
19
+ const combinedPrompt = systemPrompt ? `${systemPrompt}\n\nUser: ${prompt}` : prompt;
20
+
21
+ // For testing/development: If MOCK_LLM is set, return mock data
22
+ if (process.env.MOCK_LLM === 'true') {
23
+ return { content: `[MOCK RESPONSE from ${provider}] I have analyzed your request: ${prompt.substring(0, 50)}...` };
24
+ }
25
+
26
+ try {
27
+ switch (provider.toLowerCase()) {
28
+ case 'gemini':
29
+ return this.safeExec(`gemini ask ${this.escapeShell(combinedPrompt)}`);
30
+ case 'claude':
31
+ return this.safeExec(`claude ${this.escapeShell(combinedPrompt)} --non-interactive`);
32
+ case 'kimi':
33
+ return this.safeExec(`kimi chat ${this.escapeShell(combinedPrompt)}`);
34
+ case 'opencode':
35
+ return this.safeExec(`opencode ask ${this.escapeShell(combinedPrompt)}`);
36
+ default:
37
+ return { content: '', error: `Unsupported provider: ${provider}` };
38
+ }
39
+ } catch (error: any) {
40
+ console.error(`LLM Call Error (${provider}):`, error.message);
41
+ return { content: '', error: error.message };
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Safely execute CLI command with timeout and existence check
47
+ */
48
+ private static safeExec(cmd: string): LLMResponse {
49
+ try {
50
+ // Check if command base exists (first word)
51
+ const baseCmd = cmd.split(' ')[0];
52
+ try {
53
+ execSync(`command -v ${baseCmd}`, { stdio: 'ignore' });
54
+ } catch {
55
+ return { content: '', error: `CLI tool '${baseCmd}' not found or not in PATH. Please install and login.` };
56
+ }
57
+
58
+ const output = execSync(cmd, {
59
+ encoding: 'utf8',
60
+ stdio: ['ignore', 'pipe', 'pipe'],
61
+ timeout: 30000 // 30 second timeout
62
+ });
63
+ return { content: output.trim() };
64
+ } catch (error: any) {
65
+ return { content: '', error: error.message };
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Securely escape string for shell execution
71
+ */
72
+ private static escapeShell(cmd: string): string {
73
+ // For Unix-like systems, wrapping in single quotes and escaping existing single quotes
74
+ return "'" + cmd.replace(/'/g, "'\'" ) + "'";
75
+ }
76
+ }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Persistence Manager for JSON-based file storage
3
+ * @module utils/persistence
4
+ */
5
+
6
+ import * as fs from 'fs/promises';
7
+ import * as path from 'path';
8
+
9
+ export class PersistenceManager {
10
+ private baseDir: string;
11
+
12
+ constructor(baseDir: string = './data') {
13
+ this.baseDir = baseDir;
14
+ }
15
+
16
+ /**
17
+ * Ensure storage directories exist
18
+ */
19
+ async initialize(subDirs: string[] = ['sessions', 'agents', 'tasks']) {
20
+ try {
21
+ await fs.mkdir(this.baseDir, { recursive: true });
22
+ for (const dir of subDirs) {
23
+ await fs.mkdir(path.join(this.baseDir, dir), { recursive: true });
24
+ }
25
+ } catch (error) {
26
+ console.error('Failed to initialize persistence directory:', error);
27
+ throw error;
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Save an object to a JSON file
33
+ */
34
+ async save(collection: string, id: string, data: any) {
35
+ const filePath = path.join(this.baseDir, collection, `${id}.json`);
36
+ try {
37
+ // Handle Maps by converting them to objects/arrays for JSON serialization
38
+ const serializedData = this.serialize(data);
39
+ await fs.writeFile(filePath, JSON.stringify(serializedData, null, 2), 'utf8');
40
+ } catch (error) {
41
+ console.error(`Failed to save ${collection}/${id}:`, error);
42
+ throw error;
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Load an object from a JSON file
48
+ */
49
+ async load<T>(collection: string, id: string): Promise<T | null> {
50
+ const filePath = path.join(this.baseDir, collection, `${id}.json`);
51
+ try {
52
+ const content = await fs.readFile(filePath, 'utf8');
53
+ return JSON.parse(content) as T;
54
+ } catch (error: any) {
55
+ if (error.code === 'ENOENT') return null;
56
+ console.error(`Failed to load ${collection}/${id}:`, error);
57
+ throw error;
58
+ }
59
+ }
60
+
61
+ /**
62
+ * List all IDs in a collection
63
+ */
64
+ async list(collection: string): Promise<string[]> {
65
+ const dirPath = path.join(this.baseDir, collection);
66
+ try {
67
+ const files = await fs.readdir(dirPath);
68
+ return files
69
+ .filter(f => f.endsWith('.json'))
70
+ .map(f => f.replace('.json', ''));
71
+ } catch (error: any) {
72
+ if (error.code === 'ENOENT') return [];
73
+ throw error;
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Delete an object
79
+ */
80
+ async delete(collection: string, id: string) {
81
+ const filePath = path.join(this.baseDir, collection, `${id}.json`);
82
+ try {
83
+ await fs.unlink(filePath);
84
+ } catch (error: any) {
85
+ if (error.code !== 'ENOENT') throw error;
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Helper to serialize complex objects (like Maps)
91
+ */
92
+ private serialize(obj: any): any {
93
+ if (obj instanceof Map) {
94
+ return { _type: 'Map', data: Array.from(obj.entries()) };
95
+ }
96
+ if (Array.isArray(obj)) {
97
+ return obj.map(item => this.serialize(item));
98
+ }
99
+ if (obj !== null && typeof obj === 'object' && !(obj instanceof Date)) {
100
+ const result: any = {};
101
+ for (const key in obj) {
102
+ result[key] = this.serialize(obj[key]);
103
+ }
104
+ return result;
105
+ }
106
+ return obj;
107
+ }
108
+ }
File without changes
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "node",
6
+ "lib": ["ES2022"],
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true,
16
+ "resolveJsonModule": true,
17
+ "allowSyntheticDefaultImports": true
18
+ },
19
+ "include": ["src/**/*"],
20
+ "exclude": ["node_modules", "dist"]
21
+ }