micro-models-agent 0.19.0 → 0.19.2

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 (168) hide show
  1. package/dist/main.js +179 -358
  2. package/package.json +1 -1
  3. package/dist/cli/commands.js +0 -237
  4. package/dist/cli/completer.js +0 -168
  5. package/dist/cli/index.js +0 -2
  6. package/dist/cli/main.js +0 -113
  7. package/dist/cli/repl.js +0 -1010
  8. package/dist/cli/security-commands.js +0 -166
  9. package/dist/cli/setup.js +0 -229
  10. package/dist/config/config.js +0 -186
  11. package/dist/config/defaults.js +0 -91
  12. package/dist/config/experts.js +0 -15
  13. package/dist/config/index.js +0 -3
  14. package/dist/config/security.js +0 -193
  15. package/dist/config/types.js +0 -1
  16. package/dist/core/agent-moe.js +0 -98
  17. package/dist/core/agent.js +0 -471
  18. package/dist/core/bootstrap.js +0 -314
  19. package/dist/core/index.js +0 -2
  20. package/dist/core/prompt-builder.js +0 -55
  21. package/dist/core/session-logger.js +0 -122
  22. package/dist/core/types.js +0 -1
  23. package/dist/i18n/en.json +0 -461
  24. package/dist/i18n/index.js +0 -43
  25. package/dist/i18n/ru.json +0 -461
  26. package/dist/index.js +0 -22
  27. package/dist/llm/image-utils.js +0 -144
  28. package/dist/llm/index.js +0 -4
  29. package/dist/llm/model-loader.js +0 -78
  30. package/dist/llm/openai-compat.js +0 -324
  31. package/dist/llm/orchestrator.js +0 -194
  32. package/dist/llm/provider.js +0 -10
  33. package/dist/llm/response.js +0 -39
  34. package/dist/llm/token-counter.js +0 -39
  35. package/dist/llm/types.js +0 -1
  36. package/dist/logger/app-logger.js +0 -76
  37. package/dist/logger/index.js +0 -1
  38. package/dist/migration/backup.js +0 -45
  39. package/dist/migration/detect.js +0 -50
  40. package/dist/migration/index.js +0 -2
  41. package/dist/modules/browser/actions.js +0 -46
  42. package/dist/modules/browser/cookie-store.js +0 -24
  43. package/dist/modules/browser/index.js +0 -5
  44. package/dist/modules/browser/module.js +0 -28
  45. package/dist/modules/browser/session.js +0 -287
  46. package/dist/modules/browser/snapshot.js +0 -114
  47. package/dist/modules/browser/types.js +0 -9
  48. package/dist/modules/context/index.js +0 -1
  49. package/dist/modules/context/manager.js +0 -240
  50. package/dist/modules/execution/auditor.js +0 -72
  51. package/dist/modules/execution/index.js +0 -6
  52. package/dist/modules/execution/module.js +0 -337
  53. package/dist/modules/execution/moe-executor.js +0 -209
  54. package/dist/modules/execution/plan-validator.js +0 -153
  55. package/dist/modules/execution/planner.js +0 -35
  56. package/dist/modules/execution/stuck-detector.js +0 -134
  57. package/dist/modules/execution/tracker.js +0 -53
  58. package/dist/modules/execution/types.js +0 -1
  59. package/dist/modules/execution/verifier.js +0 -149
  60. package/dist/modules/hallucination/confidence.js +0 -59
  61. package/dist/modules/hallucination/consistency.js +0 -66
  62. package/dist/modules/hallucination/detector.js +0 -33
  63. package/dist/modules/hallucination/factual.js +0 -561
  64. package/dist/modules/hallucination/index.js +0 -3
  65. package/dist/modules/index.js +0 -5
  66. package/dist/modules/indexer/cache.js +0 -38
  67. package/dist/modules/indexer/index.js +0 -3
  68. package/dist/modules/indexer/module.js +0 -192
  69. package/dist/modules/indexer/walker.js +0 -101
  70. package/dist/modules/mcp/client.js +0 -393
  71. package/dist/modules/mcp/index.js +0 -3
  72. package/dist/modules/mcp/module.js +0 -146
  73. package/dist/modules/mcp/registry.js +0 -15
  74. package/dist/modules/memory/index.js +0 -1
  75. package/dist/modules/memory/module.js +0 -48
  76. package/dist/modules/memory/search.js +0 -40
  77. package/dist/modules/memory/store.js +0 -65
  78. package/dist/modules/pipelines/engine.js +0 -60
  79. package/dist/modules/pipelines/index.js +0 -3
  80. package/dist/modules/pipelines/parser.js +0 -53
  81. package/dist/modules/pipelines/template.js +0 -14
  82. package/dist/modules/plugins/builtin/lint-on-write.js +0 -121
  83. package/dist/modules/plugins/builtin/notify.js +0 -8
  84. package/dist/modules/plugins/index.js +0 -1
  85. package/dist/modules/plugins/loader.js +0 -28
  86. package/dist/modules/plugins/manager.js +0 -161
  87. package/dist/modules/plugins/types.js +0 -1
  88. package/dist/modules/processes/detect.js +0 -34
  89. package/dist/modules/processes/index.js +0 -3
  90. package/dist/modules/processes/registry.js +0 -148
  91. package/dist/modules/processes/runner.js +0 -124
  92. package/dist/modules/registry.js +0 -45
  93. package/dist/modules/security/audit-log.js +0 -116
  94. package/dist/modules/security/audit-notifier.js +0 -292
  95. package/dist/modules/security/command-validator.js +0 -185
  96. package/dist/modules/security/content-scanner.js +0 -52
  97. package/dist/modules/security/data-sanitizer.js +0 -97
  98. package/dist/modules/security/encryption.js +0 -240
  99. package/dist/modules/security/index.js +0 -14
  100. package/dist/modules/security/network-validator.js +0 -79
  101. package/dist/modules/security/path-validator.js +0 -155
  102. package/dist/modules/security/rate-limiter.js +0 -119
  103. package/dist/modules/security/security-policies.js +0 -393
  104. package/dist/modules/security/session-encryption.js +0 -193
  105. package/dist/modules/security/session-isolation.js +0 -95
  106. package/dist/modules/session/index.js +0 -3
  107. package/dist/modules/session/manager.js +0 -167
  108. package/dist/modules/session/module.js +0 -24
  109. package/dist/modules/session/store.js +0 -174
  110. package/dist/modules/session/types.js +0 -1
  111. package/dist/modules/skills/index.js +0 -3
  112. package/dist/modules/skills/loader.js +0 -72
  113. package/dist/modules/skills/matcher.js +0 -27
  114. package/dist/modules/skills/module.js +0 -143
  115. package/dist/modules/types.js +0 -1
  116. package/dist/modules/updater/checker.js +0 -32
  117. package/dist/modules/updater/index.js +0 -1
  118. package/dist/modules/user-profile/compressor.js +0 -16
  119. package/dist/modules/user-profile/index.js +0 -1
  120. package/dist/modules/user-profile/profile.js +0 -68
  121. package/dist/skills/builtin/builtin/git.md +0 -36
  122. package/dist/skills/builtin/builtin/typescript.md +0 -35
  123. package/dist/tools/approve.js +0 -32
  124. package/dist/tools/attach-image.js +0 -89
  125. package/dist/tools/bash.js +0 -140
  126. package/dist/tools/browser.js +0 -97
  127. package/dist/tools/create-dir.js +0 -55
  128. package/dist/tools/delete-file.js +0 -62
  129. package/dist/tools/edit-file.js +0 -77
  130. package/dist/tools/executor.js +0 -95
  131. package/dist/tools/file-info.js +0 -45
  132. package/dist/tools/filter-tools.js +0 -10
  133. package/dist/tools/glob-tool.js +0 -26
  134. package/dist/tools/grep-tool.js +0 -64
  135. package/dist/tools/index.js +0 -52
  136. package/dist/tools/list-dir.js +0 -47
  137. package/dist/tools/load-skill.js +0 -48
  138. package/dist/tools/mcp-call.js +0 -68
  139. package/dist/tools/move-file.js +0 -84
  140. package/dist/tools/path-utils.js +0 -51
  141. package/dist/tools/pipeline-run.js +0 -144
  142. package/dist/tools/preview.js +0 -2
  143. package/dist/tools/process-kill.js +0 -29
  144. package/dist/tools/process-list.js +0 -38
  145. package/dist/tools/process-log.js +0 -41
  146. package/dist/tools/question.js +0 -142
  147. package/dist/tools/read-file.js +0 -70
  148. package/dist/tools/recall.js +0 -110
  149. package/dist/tools/registry.js +0 -36
  150. package/dist/tools/remember.js +0 -67
  151. package/dist/tools/scope-check.js +0 -30
  152. package/dist/tools/search-history.js +0 -64
  153. package/dist/tools/subagent.js +0 -142
  154. package/dist/tools/types.js +0 -1
  155. package/dist/tools/user-input.js +0 -123
  156. package/dist/tools/web-browse.js +0 -57
  157. package/dist/tools/web-fetch.js +0 -72
  158. package/dist/tools/web-search.js +0 -59
  159. package/dist/tools/write-file.js +0 -79
  160. package/dist/ui/box.js +0 -81
  161. package/dist/ui/colors.js +0 -4
  162. package/dist/ui/diff.js +0 -185
  163. package/dist/ui/index.js +0 -6
  164. package/dist/ui/md-formatter.js +0 -212
  165. package/dist/ui/output.js +0 -13
  166. package/dist/ui/renderer.js +0 -141
  167. package/dist/ui/spinner.js +0 -70
  168. package/dist/ui/table.js +0 -144
@@ -1,146 +0,0 @@
1
- import { MCPClient } from "./client";
2
- import { MCPRegistry } from "./registry";
3
- function sanitizeToolName(server, tool) {
4
- const safeServer = server.replace(/[^a-zA-Z0-9_-]/g, "_");
5
- const safeTool = tool.replace(/[^a-zA-Z0-9_-]/g, "_");
6
- return `mcp__${safeServer}__${safeTool}`;
7
- }
8
- function convertInputSchema(schema) {
9
- if (schema && typeof schema === "object" && "properties" in schema) {
10
- const required = Array.isArray(schema.required)
11
- ? schema.required
12
- : [];
13
- return {
14
- type: "object",
15
- properties: schema.properties,
16
- required: required.length > 0 ? required : undefined,
17
- };
18
- }
19
- return { type: "object", properties: {} };
20
- }
21
- export class MCPModule {
22
- config;
23
- name = "mcp";
24
- connections = new Map();
25
- discovered = [];
26
- initialized = false;
27
- initError = null;
28
- constructor(config) {
29
- this.config = config;
30
- }
31
- async initialize() {
32
- if (this.initialized)
33
- return;
34
- this.initialized = true;
35
- const servers = this.config.mcpServers || {};
36
- const serverEntries = Object.entries(servers).filter(([, cfg]) => cfg.enabled !== false);
37
- if (serverEntries.length === 0)
38
- return;
39
- const registry = new MCPRegistry();
40
- for (const [key, cfg] of serverEntries) {
41
- const serverConfig = {
42
- name: cfg.name || key,
43
- command: cfg.command,
44
- args: cfg.args,
45
- env: cfg.env,
46
- transport: cfg.transport,
47
- url: cfg.url,
48
- headers: cfg.headers,
49
- timeout: cfg.timeout,
50
- };
51
- registry.register(serverConfig);
52
- }
53
- for (const serverName of registry.list()) {
54
- const serverConfig = registry.get(serverName);
55
- const client = new MCPClient(serverConfig);
56
- try {
57
- await client.connect();
58
- const tools = await client.listTools();
59
- this.connections.set(serverName, client);
60
- for (const tool of tools) {
61
- this.discovered.push({
62
- serverName,
63
- toolName: tool.name,
64
- description: tool.description || `Tool on MCP server "${serverName}"`,
65
- inputSchema: tool.inputSchema || {},
66
- });
67
- }
68
- }
69
- catch (e) {
70
- this.initError = `MCP server "${serverName}" init failed: ${e.message}`;
71
- await client.disconnect().catch(() => { });
72
- }
73
- }
74
- }
75
- getSystemPromptBlock() {
76
- if (this.discovered.length === 0)
77
- return null;
78
- const lines = ["---", "MCP servers available:"];
79
- const byServer = new Map();
80
- for (const d of this.discovered) {
81
- const list = byServer.get(d.serverName) || [];
82
- list.push(d);
83
- byServer.set(d.serverName, list);
84
- }
85
- for (const [server, tools] of byServer) {
86
- lines.push(` [${server}]`);
87
- for (const t of tools) {
88
- const toolRef = sanitizeToolName(server, t.toolName);
89
- lines.push(` - ${toolRef}: ${t.description}`);
90
- }
91
- }
92
- lines.push("---");
93
- return {
94
- content: lines.join("\n"),
95
- priority: "high",
96
- essential: false,
97
- estimatedTokens: this.discovered.length * 20 + 20,
98
- };
99
- }
100
- getToolDefinitions() {
101
- return this.discovered.map((d) => ({
102
- name: sanitizeToolName(d.serverName, d.toolName),
103
- description: `${d.description} [MCP server: ${d.serverName}]`,
104
- parameters: convertInputSchema(d.inputSchema),
105
- tags: ["code", "research"],
106
- handler: async (_ctx, args) => {
107
- const client = this.connections.get(d.serverName);
108
- if (!client) {
109
- return {
110
- success: false,
111
- output: `MCP server "${d.serverName}" not connected`,
112
- };
113
- }
114
- try {
115
- if (!client.isConnected()) {
116
- await client.connect();
117
- }
118
- const result = await client.callTool(d.toolName, args);
119
- return {
120
- success: true,
121
- output: typeof result === "string"
122
- ? result
123
- : JSON.stringify(result, null, 2),
124
- };
125
- }
126
- catch (e) {
127
- return { success: false, output: `MCP call failed: ${e.message}` };
128
- }
129
- },
130
- }));
131
- }
132
- getPlugin() {
133
- return {
134
- name: "mcp_module",
135
- priority: 0,
136
- onSessionEnd: async () => {
137
- for (const client of this.connections.values()) {
138
- try {
139
- await client.disconnect();
140
- }
141
- catch { }
142
- }
143
- },
144
- };
145
- }
146
- }
@@ -1,15 +0,0 @@
1
- export class MCPRegistry {
2
- servers = new Map();
3
- register(config) {
4
- this.servers.set(config.name, config);
5
- }
6
- get(name) {
7
- return this.servers.get(name);
8
- }
9
- list() {
10
- return Array.from(this.servers.keys()).sort();
11
- }
12
- remove(name) {
13
- this.servers.delete(name);
14
- }
15
- }
@@ -1 +0,0 @@
1
- export { MemoryStore } from './store';
@@ -1,48 +0,0 @@
1
- import { homedir } from 'os';
2
- import { join } from 'path';
3
- import { MemoryStore } from './store';
4
- import { rememberTool } from '../../tools/remember';
5
- import { recallTool } from '../../tools/recall';
6
- export class MemoryModule {
7
- name = 'memory';
8
- store;
9
- constructor(memoryDir) {
10
- const dir = memoryDir || join(homedir(), '.mma', 'memory');
11
- this.store = new MemoryStore(dir);
12
- }
13
- getSystemPromptBlock() {
14
- const prefs = this.store.getPreferences();
15
- if (Object.keys(prefs).length === 0)
16
- return null;
17
- const prefStr = Object.entries(prefs)
18
- .map(([k, v]) => `${k}=${v}`)
19
- .join(', ');
20
- return {
21
- content: `User preferences: ${prefStr}`,
22
- priority: 'normal',
23
- essential: false,
24
- estimatedTokens: Math.ceil(prefStr.length / 4) + 10,
25
- };
26
- }
27
- getToolDefinitions() {
28
- return [rememberTool, recallTool];
29
- }
30
- getPlugin() {
31
- return {
32
- name: 'memory',
33
- isBuiltin: true,
34
- onBuildPrompt: () => {
35
- const prefs = this.store.getPreferences();
36
- if (Object.keys(prefs).length === 0)
37
- return null;
38
- const prefStr = Object.entries(prefs)
39
- .map(([k, v]) => `${k}=${v}`)
40
- .join(', ');
41
- return `User preferences: ${prefStr}`;
42
- },
43
- };
44
- }
45
- getStore() {
46
- return this.store;
47
- }
48
- }
@@ -1,40 +0,0 @@
1
- import { readFileSync, existsSync } from 'fs';
2
- import { join } from 'path';
3
- const MEMORY_FILES = ['conventions', 'decisions', 'errors', 'facts'];
4
- export class MemorySearch {
5
- memoryDir;
6
- constructor(memoryDir) {
7
- this.memoryDir = memoryDir;
8
- }
9
- query(query) {
10
- const results = [];
11
- const lowerQuery = query.toLowerCase();
12
- for (const name of MEMORY_FILES) {
13
- const path = join(this.memoryDir, `${name}.md`);
14
- if (!existsSync(path))
15
- continue;
16
- const content = readFileSync(path, 'utf-8');
17
- const lines = content.split('\n');
18
- for (const line of lines) {
19
- if (line.toLowerCase().includes(lowerQuery)) {
20
- results.push({ file: name, match: line.trim() });
21
- }
22
- }
23
- }
24
- // Search preferences.json
25
- const prefsPath = join(this.memoryDir, 'preferences.json');
26
- if (existsSync(prefsPath)) {
27
- try {
28
- const prefs = JSON.parse(readFileSync(prefsPath, 'utf-8'));
29
- for (const [key, value] of Object.entries(prefs)) {
30
- const searchStr = `${key}=${value}`;
31
- if (searchStr.toLowerCase().includes(lowerQuery)) {
32
- results.push({ file: 'preferences', match: `${key} = ${value}` });
33
- }
34
- }
35
- }
36
- catch { /* skip */ }
37
- }
38
- return results;
39
- }
40
- }
@@ -1,65 +0,0 @@
1
- import { readFileSync, writeFileSync, appendFileSync, existsSync, mkdirSync } from 'fs';
2
- import { join } from 'path';
3
- import { MemorySearch } from './search';
4
- const MEMORY_FILES = ['conventions', 'decisions', 'errors', 'facts'];
5
- export class MemoryStore {
6
- memoryDir;
7
- constructor(memoryDir) {
8
- this.memoryDir = memoryDir;
9
- this.ensureDir();
10
- for (const name of MEMORY_FILES) {
11
- const path = join(this.memoryDir, `${name}.md`);
12
- if (!existsSync(path)) {
13
- writeFileSync(path, `# ${name.charAt(0).toUpperCase() + name.slice(1)}\n\n`, 'utf-8');
14
- }
15
- }
16
- }
17
- ensureDir() {
18
- if (!existsSync(this.memoryDir)) {
19
- mkdirSync(this.memoryDir, { recursive: true });
20
- }
21
- }
22
- read(name) {
23
- const path = join(this.memoryDir, `${name}.md`);
24
- if (!existsSync(path))
25
- return '';
26
- return readFileSync(path, 'utf-8');
27
- }
28
- append(name, entry) {
29
- const path = join(this.memoryDir, `${name}.md`);
30
- const timestamp = new Date().toISOString().replace('T', ' ').slice(0, 19);
31
- const formatted = `- **${timestamp}** — ${entry}\n`;
32
- appendFileSync(path, formatted, 'utf-8');
33
- }
34
- search(query) {
35
- const searchModule = new MemorySearch(this.memoryDir);
36
- return searchModule.query(query);
37
- }
38
- prefsPath() {
39
- return join(this.memoryDir, 'preferences.json');
40
- }
41
- getPreferences() {
42
- const path = this.prefsPath();
43
- if (!existsSync(path))
44
- return {};
45
- try {
46
- return JSON.parse(readFileSync(path, 'utf-8'));
47
- }
48
- catch {
49
- return {};
50
- }
51
- }
52
- setPreference(key, value) {
53
- const prefs = this.getPreferences();
54
- prefs[key] = value;
55
- writeFileSync(this.prefsPath(), JSON.stringify(prefs, null, 2), 'utf-8');
56
- }
57
- deletePreference(key) {
58
- const prefs = this.getPreferences();
59
- if (!(key in prefs))
60
- return false;
61
- delete prefs[key];
62
- writeFileSync(this.prefsPath(), JSON.stringify(prefs, null, 2), 'utf-8');
63
- return true;
64
- }
65
- }
@@ -1,60 +0,0 @@
1
- import { t } from '../../i18n/index';
2
- export class PipelineEngine {
3
- stepStatus = new Map();
4
- resolveDependencies(steps) {
5
- const visited = new Set();
6
- const inStack = new Set();
7
- const order = [];
8
- function visit(stepId, stepMap) {
9
- if (inStack.has(stepId))
10
- throw new Error(t('pipeline.circular', { stepId }));
11
- if (visited.has(stepId))
12
- return;
13
- inStack.add(stepId);
14
- const step = stepMap.get(stepId);
15
- if (step?.depends_on) {
16
- for (const dep of step.depends_on) {
17
- visit(dep, stepMap);
18
- }
19
- }
20
- inStack.delete(stepId);
21
- visited.add(stepId);
22
- order.push(stepId);
23
- }
24
- const stepMap = new Map(steps.map(s => [s.id, s]));
25
- for (const step of steps) {
26
- if (!visited.has(step.id)) {
27
- visit(step.id, stepMap);
28
- }
29
- }
30
- return order;
31
- }
32
- getReadySteps(steps, completed) {
33
- return steps.filter(s => {
34
- if (completed.has(s.id))
35
- return false;
36
- if (this.stepStatus.get(s.id) === 'running')
37
- return false;
38
- if (this.stepStatus.get(s.id) === 'failed')
39
- return false;
40
- if (!s.depends_on || s.depends_on.length === 0)
41
- return true;
42
- return s.depends_on.every(d => completed.has(d));
43
- });
44
- }
45
- setStepStatus(stepId, status) {
46
- this.stepStatus.set(stepId, status);
47
- }
48
- getStepStatus(stepId) {
49
- return this.stepStatus.get(stepId) || 'pending';
50
- }
51
- isComplete(stepIds) {
52
- return stepIds.every(id => {
53
- const s = this.stepStatus.get(id);
54
- return s === 'done' || s === 'skipped';
55
- });
56
- }
57
- reset() {
58
- this.stepStatus.clear();
59
- }
60
- }
@@ -1,3 +0,0 @@
1
- export { PipelineParser } from './parser';
2
- export { PipelineEngine } from './engine';
3
- export { TemplateEngine } from './template';
@@ -1,53 +0,0 @@
1
- import { t } from '../../i18n/index';
2
- export class PipelineParser {
3
- static parse(yaml) {
4
- const lines = yaml.split('\n').filter(l => l.trim());
5
- const result = {};
6
- let currentSection = null;
7
- let currentSteps = [];
8
- for (const line of lines) {
9
- if (line.match(/^\w+:/) && !line.startsWith(' ') && !line.startsWith(' -')) {
10
- const [key, ...valParts] = line.split(':');
11
- const val = valParts.join(':').trim();
12
- if (key === 'steps') {
13
- currentSection = 'steps';
14
- }
15
- else {
16
- result[key] = val;
17
- currentSection = null;
18
- }
19
- }
20
- else if (currentSection === 'steps') {
21
- const stepMatch = line.match(/^\s+- id:\s*(\S+)/);
22
- if (stepMatch) {
23
- currentSteps.push({ id: stepMatch[1] });
24
- }
25
- else if (currentSteps.length > 0) {
26
- const lastStep = currentSteps[currentSteps.length - 1];
27
- const kvMatch = line.match(/^\s+(\w+):\s*(.+)$/);
28
- if (kvMatch) {
29
- const key = kvMatch[1];
30
- let val = kvMatch[2].trim();
31
- if (val === 'true')
32
- val = true;
33
- else if (val === 'false')
34
- val = false;
35
- else if (val.startsWith('[') && val.endsWith(']')) {
36
- val = val.slice(1, -1).split(',').map((s) => s.trim().replace(/^['"]|['"]$/g, ''));
37
- }
38
- lastStep[key] = val;
39
- }
40
- }
41
- }
42
- }
43
- if (!result.name || currentSteps.length === 0) {
44
- throw new Error(t('pipeline.invalid'));
45
- }
46
- for (const step of currentSteps) {
47
- if (!step.id || !step.agent || !step.prompt) {
48
- throw new Error(t('pipeline.step_missing_fields', { step: JSON.stringify(step) }));
49
- }
50
- }
51
- return { name: result.name, steps: currentSteps };
52
- }
53
- }
@@ -1,14 +0,0 @@
1
- export class TemplateEngine {
2
- static render(template, params, stepOutputs) {
3
- let result = template;
4
- for (const [key, val] of Object.entries(params)) {
5
- result = result.replace(new RegExp(`\\{${key}\\}`, 'g'), val);
6
- }
7
- if (stepOutputs) {
8
- result = result.replace(/\{\{steps\.(\w+)\.output\}\}/g, (_, stepId) => {
9
- return stepOutputs[stepId]?.output || `{{steps.${stepId}.output}}`;
10
- });
11
- }
12
- return result;
13
- }
14
- }
@@ -1,121 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import { existsSync, readFileSync } from 'fs';
3
- import { resolve, extname, join } from 'path';
4
- let projectTypeCheckPromise = null;
5
- let projectTypeCheckTimestamp = 0;
6
- const TYPE_CHECK_DEBOUNCE_MS = 2000;
7
- export class LintOnWritePlugin {
8
- name = 'lint-on-write';
9
- priority = 10;
10
- async onAfterTool(ctx, call, result) {
11
- if (call.name !== 'write_file' && call.name !== 'edit_file') {
12
- return;
13
- }
14
- if (!result.success) {
15
- return;
16
- }
17
- const path = String(call.arguments.path || '');
18
- if (!path)
19
- return;
20
- const fullPath = resolve(ctx.baseDir, path);
21
- if (!existsSync(fullPath))
22
- return;
23
- const ext = extname(fullPath);
24
- const syntaxError = this.checkSyntax(fullPath, ext, ctx.baseDir);
25
- if (syntaxError) {
26
- result.output += `\n\n[Syntax check failed]: ${syntaxError}`;
27
- return;
28
- }
29
- await this.runProjectLint(ctx, result);
30
- await this.runProjectTypeCheck(ctx, result);
31
- }
32
- checkSyntax(filePath, ext, baseDir) {
33
- if (ext === '.ts' || ext === '.tsx') {
34
- try {
35
- execSync(`npx tsc --noEmit --skipLibCheck "${filePath}"`, { cwd: baseDir, stdio: 'pipe', timeout: 10000 });
36
- return null;
37
- }
38
- catch (err) {
39
- if (err.status === 127 || err.message.includes('not found') || err.message.includes('ENOENT')) {
40
- return null;
41
- }
42
- const stderr = err.stderr?.toString() || err.stdout?.toString() || '';
43
- if (stderr.includes('error TS')) {
44
- const firstError = stderr.split('\n').find((line) => line.includes('error TS')) || 'TypeScript syntax error';
45
- return firstError.trim();
46
- }
47
- return null;
48
- }
49
- }
50
- if (ext === '.js' || ext === '.jsx') {
51
- try {
52
- execSync(`node --check "${filePath}"`, { cwd: baseDir, stdio: 'pipe', timeout: 5000 });
53
- return null;
54
- }
55
- catch (err) {
56
- const stderr = err.stderr?.toString() || '';
57
- const firstError = stderr.split('\n').find((line) => line.trim()) || 'JavaScript syntax error';
58
- return firstError.trim();
59
- }
60
- }
61
- return null;
62
- }
63
- async runProjectLint(ctx, result) {
64
- try {
65
- const packageJsonPath = join(ctx.baseDir, 'package.json');
66
- if (!existsSync(packageJsonPath)) {
67
- return;
68
- }
69
- const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
70
- const lintScript = packageJson.scripts?.lint;
71
- if (!lintScript) {
72
- return;
73
- }
74
- ctx.logger.debug(`Running lint: ${lintScript}`);
75
- execSync(lintScript, { cwd: ctx.baseDir, stdio: 'pipe' });
76
- ctx.logger.debug('Lint passed');
77
- }
78
- catch (err) {
79
- ctx.logger.warn(`Lint failed: ${err.message}`);
80
- result.output += `\n\n[Project lint failed]: ${err.message}`;
81
- }
82
- }
83
- async runProjectTypeCheck(ctx, result) {
84
- const tsconfigPath = join(ctx.baseDir, 'tsconfig.json');
85
- if (!existsSync(tsconfigPath)) {
86
- return;
87
- }
88
- const now = Date.now();
89
- if (projectTypeCheckPromise && now - projectTypeCheckTimestamp < TYPE_CHECK_DEBOUNCE_MS) {
90
- const error = await projectTypeCheckPromise;
91
- if (error) {
92
- result.output += `\n\n[Project typecheck failed]: ${error}`;
93
- }
94
- return;
95
- }
96
- projectTypeCheckTimestamp = now;
97
- projectTypeCheckPromise = this.runTscCheck(ctx.baseDir);
98
- const error = await projectTypeCheckPromise;
99
- if (error) {
100
- result.output += `\n\n[Project typecheck failed]: ${error}`;
101
- }
102
- }
103
- async runTscCheck(baseDir) {
104
- try {
105
- execSync(`npx tsc --noEmit --skipLibCheck`, { cwd: baseDir, stdio: 'pipe', timeout: 30000 });
106
- return null;
107
- }
108
- catch (err) {
109
- if (err.status === 127 || err.message.includes('not found') || err.message.includes('ENOENT')) {
110
- return null;
111
- }
112
- const stderr = err.stderr?.toString() || err.stdout?.toString() || '';
113
- if (stderr.includes('error TS')) {
114
- const firstError = stderr.split('\n').find((line) => line.includes('error TS')) || 'TypeScript type error';
115
- return firstError.trim();
116
- }
117
- return null;
118
- }
119
- }
120
- }
121
- export const plugin = new LintOnWritePlugin();
@@ -1,8 +0,0 @@
1
- export class NotifyPlugin {
2
- name = 'notify';
3
- priority = 5;
4
- onSessionEnd(ctx) {
5
- ctx.logger.info('Session ended');
6
- }
7
- }
8
- export const plugin = new NotifyPlugin();
@@ -1 +0,0 @@
1
- export { PluginManager } from './manager';
@@ -1,28 +0,0 @@
1
- import { readdirSync, existsSync, statSync } from 'fs';
2
- import { join } from 'path';
3
- import { t } from '../../i18n/index';
4
- export class PluginLoader {
5
- loadFromDir(dirPath, pluginManager, logger) {
6
- if (!existsSync(dirPath))
7
- return;
8
- const entries = readdirSync(dirPath);
9
- for (const entry of entries) {
10
- const fullPath = join(dirPath, entry);
11
- if (!statSync(fullPath).isFile())
12
- continue;
13
- if (!entry.endsWith('.ts') && !entry.endsWith('.js'))
14
- continue;
15
- try {
16
- const mod = require(fullPath);
17
- const plugin = mod.default || mod.plugin;
18
- if (plugin && plugin.name) {
19
- pluginManager.register(plugin);
20
- logger?.warn(t('plugin.loaded', { name: plugin.name }));
21
- }
22
- }
23
- catch (e) {
24
- logger?.warn(t('plugin.skipped', { entry, message: e.message }));
25
- }
26
- }
27
- }
28
- }