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,167 +0,0 @@
1
- import { t } from '../../i18n/index';
2
- import { createSessionContext, DEFAULT_SESSION_ISOLATION } from '../../modules/security/session-isolation';
3
- export class SessionManager {
4
- store;
5
- activeId = null;
6
- options;
7
- /**
8
- * Map of session ID to session context (for isolation)
9
- */
10
- sessionContexts = new Map();
11
- constructor(store, options) {
12
- this.store = store;
13
- this.options = options;
14
- // Initialize encryption if configured
15
- if (options.encryption) {
16
- this.store.updateEncryption(options.encryption);
17
- }
18
- }
19
- /**
20
- * Check if session file encryption is enabled
21
- */
22
- isEncryptionEnabled() {
23
- return this.store.isEncryptionEnabled();
24
- }
25
- /**
26
- * Update encryption configuration
27
- */
28
- updateEncryption(config) {
29
- this.store.updateEncryption(config);
30
- this.options.encryption = config;
31
- }
32
- create(name, securityOverrides) {
33
- const now = new Date().toISOString();
34
- const id = `ses_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
35
- const sessionName = name || t('session.default_name', { date: now.slice(0, 10) });
36
- const meta = {
37
- id,
38
- name: sessionName,
39
- createdAt: now,
40
- updatedAt: now,
41
- messageCount: 0,
42
- model: this.options.model,
43
- contextWindow: this.options.contextWindow,
44
- projectDir: this.options.projectDir,
45
- securityOverrides,
46
- };
47
- this.store.saveMeta(id, meta);
48
- this.activeId = id;
49
- this.enforceMaxSessions();
50
- // Create session context
51
- const context = createSessionContext(id, this.options.projectDir, this.options.isolation, this.normalizeSecurityOverrides(securityOverrides));
52
- this.sessionContexts.set(id, context);
53
- return meta;
54
- }
55
- list() {
56
- return this.store.listSessions();
57
- }
58
- get(id) {
59
- return this.store.loadMeta(id);
60
- }
61
- delete(id) {
62
- // Clean up session context
63
- const context = this.sessionContexts.get(id);
64
- if (context) {
65
- // In a real implementation, we would clean up temp files here
66
- this.sessionContexts.delete(id);
67
- }
68
- this.store.deleteSession(id);
69
- if (this.activeId === id) {
70
- this.activeId = null;
71
- }
72
- }
73
- rename(id, name) {
74
- const meta = this.store.loadMeta(id);
75
- if (!meta)
76
- throw new Error(t('session.not_found', { id }));
77
- meta.name = name;
78
- this.store.saveMeta(id, meta);
79
- }
80
- getActive() {
81
- return this.activeId;
82
- }
83
- getActiveMeta() {
84
- if (!this.activeId)
85
- return null;
86
- return this.store.loadMeta(this.activeId);
87
- }
88
- setActive(id) {
89
- if (!this.store.sessionExists(id)) {
90
- throw new Error(t('session.not_found', { id }));
91
- }
92
- this.activeId = id;
93
- }
94
- appendMessage(msg) {
95
- if (!this.activeId)
96
- throw new Error(t('session.no_active'));
97
- this.store.appendMessage(this.activeId, msg);
98
- }
99
- appendLog(entry) {
100
- if (!this.activeId)
101
- return;
102
- this.store.appendSessionLog(this.activeId, entry);
103
- }
104
- loadHistory() {
105
- if (!this.activeId)
106
- return [];
107
- return this.store.loadHistory(this.activeId);
108
- }
109
- /**
110
- * Get the session context for the active session
111
- */
112
- getSessionContext() {
113
- if (!this.activeId)
114
- return undefined;
115
- return this.getSessionContextById(this.activeId);
116
- }
117
- /**
118
- * Get the session context for a specific session
119
- */
120
- getSessionContextById(sessionId) {
121
- if (!this.sessionContexts.has(sessionId)) {
122
- const meta = this.store.loadMeta(sessionId);
123
- if (!meta)
124
- return undefined;
125
- const context = createSessionContext(sessionId, meta.projectDir, this.options.isolation, this.normalizeSecurityOverrides(meta.securityOverrides));
126
- this.sessionContexts.set(sessionId, context);
127
- }
128
- return this.sessionContexts.get(sessionId);
129
- }
130
- /**
131
- * Get session isolation configuration
132
- */
133
- getIsolationConfig() {
134
- return this.options.isolation ?? DEFAULT_SESSION_ISOLATION;
135
- }
136
- /**
137
- * Check if session isolation is enabled
138
- */
139
- isIsolationEnabled() {
140
- return this.getIsolationConfig().enabled;
141
- }
142
- /**
143
- * Normalize security overrides to match SecurityConfig structure
144
- */
145
- normalizeSecurityOverrides(overrides) {
146
- if (!overrides)
147
- return undefined;
148
- return {
149
- maxFileOperations: overrides.maxFileOperations,
150
- maxRecursionDepth: overrides.maxRecursionDepth,
151
- rateLimits: overrides.rateLimits ? {
152
- maxRequestsPerMinute: overrides.rateLimits.maxRequestsPerMinute ?? 60,
153
- maxParallelTasks: overrides.rateLimits.maxParallelTasks ?? 5,
154
- } : undefined,
155
- };
156
- }
157
- enforceMaxSessions() {
158
- const max = this.options.maxSessions ?? 50;
159
- const sessions = this.store.listSessions();
160
- if (sessions.length > max) {
161
- const toDelete = sessions.slice(max);
162
- for (const s of toDelete) {
163
- this.delete(s.id);
164
- }
165
- }
166
- }
167
- }
@@ -1,24 +0,0 @@
1
- import { t } from '../../i18n/index';
2
- export class SessionModule {
3
- name = 'session';
4
- manager;
5
- constructor(manager) {
6
- this.manager = manager;
7
- }
8
- getSystemPromptBlock() {
9
- const meta = this.manager.getActiveMeta();
10
- if (!meta || meta.messageCount === 0)
11
- return null;
12
- return {
13
- content: t('session.info', { name: meta.name, id: meta.id, count: meta.messageCount }),
14
- priority: 'low',
15
- essential: false,
16
- estimatedTokens: 20,
17
- };
18
- }
19
- getPlugin() {
20
- return {
21
- name: 'session',
22
- };
23
- }
24
- }
@@ -1,174 +0,0 @@
1
- import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync, appendFileSync, } from "fs";
2
- import { join } from "path";
3
- import { gzipSync } from "zlib";
4
- import { SessionFileEncryptor } from "../security/session-encryption";
5
- export class SessionStore {
6
- baseDir;
7
- encryptor = null;
8
- constructor(baseDir, encryptionConfig) {
9
- this.baseDir = baseDir;
10
- if (encryptionConfig?.enabled) {
11
- this.encryptor = new SessionFileEncryptor(encryptionConfig);
12
- }
13
- }
14
- /**
15
- * Update encryption configuration
16
- */
17
- updateEncryption(config) {
18
- if (config?.enabled) {
19
- this.encryptor = new SessionFileEncryptor(config);
20
- }
21
- else {
22
- this.encryptor = null;
23
- }
24
- }
25
- /**
26
- * Check if encryption is enabled
27
- */
28
- isEncryptionEnabled() {
29
- return this.encryptor?.isEnabled() ?? false;
30
- }
31
- init() {
32
- mkdirSync(this.baseDir, { recursive: true });
33
- }
34
- sessionDir(id) {
35
- return join(this.baseDir, id);
36
- }
37
- metaPath(id) {
38
- return join(this.sessionDir(id), "meta.json");
39
- }
40
- historyPath(id) {
41
- return join(this.sessionDir(id), "history.jsonl");
42
- }
43
- sessionLogPath(id) {
44
- return join(this.sessionDir(id), "session.jsonl");
45
- }
46
- sessionExists(id) {
47
- return existsSync(this.metaPath(id));
48
- }
49
- saveMeta(id, meta) {
50
- const dir = this.sessionDir(id);
51
- mkdirSync(dir, { recursive: true });
52
- const content = JSON.stringify(meta, null, 2);
53
- if (this.encryptor) {
54
- writeFileSync(this.metaPath(id), this.encryptor.encryptFileContent(content), "utf-8");
55
- }
56
- else {
57
- writeFileSync(this.metaPath(id), content, "utf-8");
58
- }
59
- }
60
- loadMeta(id) {
61
- const path = this.metaPath(id);
62
- if (!existsSync(path))
63
- return null;
64
- try {
65
- const raw = readFileSync(path, "utf-8");
66
- const content = this.encryptor ? this.encryptor.decryptFileContent(raw) : raw;
67
- return JSON.parse(content);
68
- }
69
- catch {
70
- return null;
71
- }
72
- }
73
- appendMessage(id, msg) {
74
- const dir = this.sessionDir(id);
75
- mkdirSync(dir, { recursive: true });
76
- const line = JSON.stringify(msg);
77
- if (this.encryptor?.isEnabled()) {
78
- appendFileSync(this.historyPath(id), this.encryptor.encryptFileContent(line) + "\n", "utf-8");
79
- }
80
- else {
81
- appendFileSync(this.historyPath(id), line + "\n", "utf-8");
82
- }
83
- const meta = this.loadMeta(id);
84
- if (meta) {
85
- meta.messageCount = (meta.messageCount || 0) + 1;
86
- meta.updatedAt = msg.timestamp || new Date().toISOString();
87
- this.saveMeta(id, meta);
88
- }
89
- }
90
- loadHistory(id) {
91
- const path = this.historyPath(id);
92
- if (!existsSync(path))
93
- return [];
94
- try {
95
- const raw = readFileSync(path, "utf-8");
96
- const lines = raw.split("\n").filter(Boolean);
97
- if (this.encryptor?.isEnabled()) {
98
- const decryptedLines = lines.map(line => this.encryptor.decryptFileContent(line));
99
- return decryptedLines.map((line) => JSON.parse(line));
100
- }
101
- return lines.map((line) => JSON.parse(line));
102
- }
103
- catch {
104
- return [];
105
- }
106
- }
107
- appendSessionLog(id, entry) {
108
- const dir = this.sessionDir(id);
109
- mkdirSync(dir, { recursive: true });
110
- const line = JSON.stringify(entry);
111
- if (this.encryptor?.isEnabled()) {
112
- appendFileSync(this.sessionLogPath(id), this.encryptor.encryptFileContent(line) + "\n", "utf-8");
113
- }
114
- else {
115
- appendFileSync(this.sessionLogPath(id), line + "\n", "utf-8");
116
- }
117
- }
118
- loadSessionLog(id) {
119
- const path = this.sessionLogPath(id);
120
- if (!existsSync(path))
121
- return [];
122
- try {
123
- const raw = readFileSync(path, "utf-8");
124
- const lines = raw.split("\n").filter(Boolean);
125
- if (this.encryptor?.isEnabled()) {
126
- const decryptedLines = lines.map(line => this.encryptor.decryptFileContent(line));
127
- return decryptedLines.map((line) => JSON.parse(line));
128
- }
129
- return lines.map((line) => JSON.parse(line));
130
- }
131
- catch {
132
- return [];
133
- }
134
- }
135
- listSessions() {
136
- if (!existsSync(this.baseDir))
137
- return [];
138
- const entries = readdirSync(this.baseDir, { withFileTypes: true });
139
- const sessions = [];
140
- for (const entry of entries) {
141
- if (entry.isDirectory()) {
142
- const meta = this.loadMeta(entry.name);
143
- if (meta)
144
- sessions.push(meta);
145
- }
146
- }
147
- sessions.sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());
148
- return sessions;
149
- }
150
- deleteSession(id) {
151
- const dir = this.sessionDir(id);
152
- if (existsSync(dir)) {
153
- rmSync(dir, { recursive: true, force: true });
154
- }
155
- }
156
- rotateOldSessions() {
157
- const thirtyDaysAgo = new Date();
158
- thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
159
- const sessions = this.listSessions();
160
- for (const session of sessions) {
161
- const updatedAt = new Date(session.updatedAt);
162
- if (updatedAt < thirtyDaysAgo) {
163
- const historyPath = this.historyPath(session.id);
164
- if (existsSync(historyPath)) {
165
- const content = readFileSync(historyPath, "utf-8");
166
- const compressed = gzipSync(content);
167
- const gzPath = join(this.baseDir, `${session.id}.jsonl.gz`);
168
- writeFileSync(gzPath, compressed);
169
- rmSync(historyPath);
170
- }
171
- }
172
- }
173
- }
174
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- export { SkillsLoader } from './loader';
2
- export { SkillsMatcher } from './matcher';
3
- export { SkillsModule } from './module';
@@ -1,72 +0,0 @@
1
- import { readdirSync, readFileSync, existsSync, statSync } from "fs";
2
- import { join } from "path";
3
- export class SkillsLoader {
4
- loadFromDir(dirPath) {
5
- if (!existsSync(dirPath))
6
- return [];
7
- const skills = [];
8
- this.scanDir(dirPath, skills);
9
- return skills;
10
- }
11
- scanDir(dirPath, skills) {
12
- const entries = readdirSync(dirPath);
13
- for (const entry of entries) {
14
- const fullPath = join(dirPath, entry);
15
- const stat = statSync(fullPath);
16
- if (stat.isDirectory()) {
17
- this.scanDir(fullPath, skills);
18
- continue;
19
- }
20
- if (!entry.endsWith(".md") && !entry.endsWith(".skill.md"))
21
- continue;
22
- const content = readFileSync(fullPath, "utf-8");
23
- const parsed = this.parseSkillFile(content, fullPath);
24
- if (parsed)
25
- skills.push(parsed);
26
- }
27
- }
28
- parseSkillFile(content, sourcePath) {
29
- const match = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
30
- if (!match)
31
- return null;
32
- const frontmatter = this.parseFrontmatter(match[1]);
33
- if (!frontmatter.name)
34
- return null;
35
- if (frontmatter.mma_version && String(frontmatter.mma_version) !== "2") {
36
- return null;
37
- }
38
- return {
39
- name: frontmatter.name,
40
- description: frontmatter.description || "",
41
- keywords: frontmatter.keywords || [],
42
- content: match[2].trim(),
43
- sourcePath,
44
- };
45
- }
46
- parseFrontmatter(yaml) {
47
- const result = {};
48
- for (const line of yaml.split("\n")) {
49
- const kvMatch = line.match(/^(\w+):\s*(.+)$/);
50
- if (kvMatch) {
51
- const val = kvMatch[2].trim();
52
- if (val.startsWith("[") && val.endsWith("]")) {
53
- result[kvMatch[1]] = val
54
- .slice(1, -1)
55
- .split(",")
56
- .map((s) => s.trim().replace(/^['"]|['"]$/g, ""));
57
- }
58
- else {
59
- result[kvMatch[1]] = val.replace(/^['"]|['"]$/g, "");
60
- }
61
- }
62
- }
63
- return result;
64
- }
65
- loadFromAllSources(builtinDir, globalDir, projectDir) {
66
- return [
67
- ...this.loadFromDir(builtinDir),
68
- ...this.loadFromDir(globalDir),
69
- ...this.loadFromDir(projectDir),
70
- ];
71
- }
72
- }
@@ -1,27 +0,0 @@
1
- const MIN_WORD_LENGTH = 4;
2
- export class SkillsMatcher {
3
- match(taskDescription, skills, maxResults = 3) {
4
- const taskWords = taskDescription.toLowerCase().split(/\W+/).filter(w => w.length >= MIN_WORD_LENGTH);
5
- const scored = skills.map(skill => {
6
- const allKeywords = [
7
- skill.name.toLowerCase(),
8
- skill.description.toLowerCase(),
9
- ...skill.keywords.map(k => k.toLowerCase()),
10
- ];
11
- let score = 0;
12
- for (const word of taskWords) {
13
- for (const kw of allKeywords) {
14
- if (kw === word || (kw.length >= MIN_WORD_LENGTH && kw.includes(word))) {
15
- score++;
16
- }
17
- }
18
- }
19
- return { skill, score };
20
- });
21
- return scored
22
- .filter(s => s.score > 0)
23
- .sort((a, b) => b.score - a.score)
24
- .slice(0, maxResults)
25
- .map(s => s.skill);
26
- }
27
- }
@@ -1,143 +0,0 @@
1
- import { t } from "../../i18n/index";
2
- export class SkillsModule {
3
- name = "skills";
4
- availableSkills;
5
- loadedSkills = new Map();
6
- matcher;
7
- budget;
8
- currentTokens = 0;
9
- constructor(availableSkills, matcher, budget) {
10
- this.availableSkills = availableSkills;
11
- this.matcher = matcher;
12
- this.budget = budget;
13
- }
14
- loadByName(name) {
15
- if (this.loadedSkills.has(name)) {
16
- return { success: false, message: t("skill.already_loaded", { name }) };
17
- }
18
- const skill = this.availableSkills.find((s) => s.name === name);
19
- if (!skill) {
20
- const fuzzyMatches = this.matcher.match(name, this.availableSkills, 1);
21
- if (fuzzyMatches.length > 0) {
22
- return this.tryLoad(fuzzyMatches[0]);
23
- }
24
- return { success: false, message: t("skill.not_found", { name }) };
25
- }
26
- return this.tryLoad(skill);
27
- }
28
- loadByMatch(taskDescription) {
29
- const matches = this.matcher.match(taskDescription, this.availableSkills, 1);
30
- if (matches.length === 0) {
31
- return {
32
- success: false,
33
- message: t("skill.no_match", { task: taskDescription }),
34
- };
35
- }
36
- return this.tryLoad(matches[0]);
37
- }
38
- unload(name) {
39
- const skill = this.loadedSkills.get(name);
40
- if (!skill)
41
- return false;
42
- this.loadedSkills.delete(name);
43
- this.currentTokens -= this.estimateTokens(skill.content);
44
- return true;
45
- }
46
- getLoaded() {
47
- return Array.from(this.loadedSkills.values());
48
- }
49
- getAvailable() {
50
- return this.availableSkills;
51
- }
52
- findByName(name) {
53
- return this.availableSkills.find((s) => s.name === name);
54
- }
55
- search(query) {
56
- return this.matcher.match(query, this.availableSkills, 10);
57
- }
58
- getBudget() {
59
- return {
60
- used: this.currentTokens,
61
- total: this.budget,
62
- remaining: this.budget - this.currentTokens,
63
- };
64
- }
65
- getSkillContent(name) {
66
- const skill = this.loadedSkills.get(name);
67
- return skill ? skill.content : null;
68
- }
69
- getSystemPromptBlock() {
70
- const lines = [];
71
- if (this.availableSkills.length > 0) {
72
- lines.push("[Available Skills]");
73
- lines.push(t("skill.prompt_hint"));
74
- for (const skill of this.availableSkills) {
75
- const desc = skill.description.slice(0, 60);
76
- lines.push(`- ${skill.name}: ${desc}`);
77
- }
78
- lines.push(t("skill.prompt_fallback"));
79
- }
80
- if (this.loadedSkills.size > 0) {
81
- lines.push("[Loaded Skills]");
82
- for (const skill of this.loadedSkills.values()) {
83
- const desc = skill.description.slice(0, 80);
84
- lines.push(`- ${skill.name}: ${desc}`);
85
- }
86
- }
87
- if (lines.length === 0)
88
- return null;
89
- const content = lines.join("\n");
90
- const tokens = this.estimateTokens(content);
91
- return {
92
- content,
93
- priority: "normal",
94
- essential: false,
95
- estimatedTokens: tokens,
96
- };
97
- }
98
- getPlugin() {
99
- return {
100
- name: "skills",
101
- onSessionStart: (_ctx) => { },
102
- onBeforeThink: (_ctx) => { },
103
- };
104
- }
105
- tryLoad(skill) {
106
- const tokens = this.estimateTokens(skill.content);
107
- if (tokens > this.budget) {
108
- return {
109
- success: false,
110
- message: t("skill.too_large", {
111
- name: skill.name,
112
- tokens,
113
- budget: this.budget,
114
- }),
115
- };
116
- }
117
- if (this.currentTokens + tokens > this.budget) {
118
- const remaining = this.budget - this.currentTokens;
119
- return {
120
- success: false,
121
- message: t("skill.exceeds_budget", {
122
- name: skill.name,
123
- tokens,
124
- remaining,
125
- }),
126
- };
127
- }
128
- this.loadedSkills.set(skill.name, skill);
129
- this.currentTokens += tokens;
130
- return {
131
- success: true,
132
- message: t("skill.loaded", {
133
- name: skill.name,
134
- tokens,
135
- remaining: this.budget - this.currentTokens,
136
- }),
137
- skill,
138
- };
139
- }
140
- estimateTokens(text) {
141
- return Math.ceil(text.length / 4);
142
- }
143
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,32 +0,0 @@
1
- export class Updater {
2
- currentVersion;
3
- packageName;
4
- constructor(currentVersion, packageName) {
5
- this.currentVersion = currentVersion;
6
- this.packageName = packageName;
7
- }
8
- getCurrentVersion() {
9
- return this.currentVersion;
10
- }
11
- async check() {
12
- try {
13
- const response = await fetch(`https://registry.npmjs.org/${this.packageName}`, {
14
- headers: { Accept: 'application/vnd.npm.install-v1+json' },
15
- signal: AbortSignal.timeout(5000),
16
- });
17
- if (!response.ok) {
18
- return { updateAvailable: false, current: this.currentVersion, error: `HTTP ${response.status}` };
19
- }
20
- const data = await response.json();
21
- const latest = data['dist-tags']?.latest;
22
- if (!latest) {
23
- return { updateAvailable: false, current: this.currentVersion, error: 'No latest tag' };
24
- }
25
- const updateAvailable = latest !== this.currentVersion;
26
- return { updateAvailable, current: this.currentVersion, latest };
27
- }
28
- catch (e) {
29
- return { updateAvailable: false, current: this.currentVersion, error: e.message };
30
- }
31
- }
32
- }
@@ -1 +0,0 @@
1
- export { Updater } from './checker';
@@ -1,16 +0,0 @@
1
- export class ProfileCompressor {
2
- compress(info) {
3
- const parts = [
4
- `OS: ${info.os}`,
5
- `Shell: ${info.shell}`,
6
- `Platform: ${info.platform}`,
7
- ];
8
- if (Object.keys(info.preferences).length > 0) {
9
- const prefs = Object.entries(info.preferences)
10
- .map(([k, v]) => `${k}=${v}`)
11
- .join(',');
12
- parts.push(`Prefs: ${prefs}`);
13
- }
14
- return parts.join(', ');
15
- }
16
- }
@@ -1 +0,0 @@
1
- export { UserProfile } from './profile';