micro-models-agent 0.28.9 → 0.29.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 (167) hide show
  1. package/dist/cli/commands.js +220 -0
  2. package/dist/cli/completer.js +168 -0
  3. package/dist/cli/index.js +2 -0
  4. package/dist/cli/main.js +113 -0
  5. package/dist/cli/repl.js +987 -0
  6. package/dist/cli/security-commands.js +166 -0
  7. package/dist/cli/setup.js +229 -0
  8. package/dist/config/config.js +186 -0
  9. package/dist/config/defaults.js +91 -0
  10. package/dist/config/experts.js +15 -0
  11. package/dist/config/index.js +3 -0
  12. package/dist/config/security.js +193 -0
  13. package/dist/config/types.js +1 -0
  14. package/dist/core/agent-moe.js +98 -0
  15. package/dist/core/agent.js +461 -0
  16. package/dist/core/bootstrap.js +321 -0
  17. package/dist/core/index.js +2 -0
  18. package/dist/core/prompt-builder.js +55 -0
  19. package/dist/core/session-logger.js +122 -0
  20. package/dist/core/types.js +1 -0
  21. package/dist/i18n/en.json +461 -0
  22. package/dist/i18n/index.js +43 -0
  23. package/dist/i18n/ru.json +461 -0
  24. package/dist/index.js +22 -0
  25. package/dist/llm/image-utils.js +144 -0
  26. package/dist/llm/index.js +4 -0
  27. package/dist/llm/model-loader.js +78 -0
  28. package/dist/llm/openai-compat.js +324 -0
  29. package/dist/llm/orchestrator.js +194 -0
  30. package/dist/llm/provider.js +10 -0
  31. package/dist/llm/response.js +39 -0
  32. package/dist/llm/token-counter.js +39 -0
  33. package/dist/llm/types.js +1 -0
  34. package/dist/logger/app-logger.js +76 -0
  35. package/dist/logger/index.js +1 -0
  36. package/dist/main.js +2251 -724
  37. package/dist/migration/backup.js +45 -0
  38. package/dist/migration/detect.js +50 -0
  39. package/dist/migration/index.js +2 -0
  40. package/dist/modules/browser/actions.js +46 -0
  41. package/dist/modules/browser/cookie-store.js +24 -0
  42. package/dist/modules/browser/index.js +5 -0
  43. package/dist/modules/browser/module.js +28 -0
  44. package/dist/modules/browser/session.js +287 -0
  45. package/dist/modules/browser/snapshot.js +114 -0
  46. package/dist/modules/browser/types.js +9 -0
  47. package/dist/modules/context/history.js +15 -0
  48. package/dist/modules/context/index.js +1 -0
  49. package/dist/modules/context/manager.js +240 -0
  50. package/dist/modules/execution/auditor.js +72 -0
  51. package/dist/modules/execution/index.js +6 -0
  52. package/dist/modules/execution/module.js +337 -0
  53. package/dist/modules/execution/moe-executor.js +209 -0
  54. package/dist/modules/execution/plan-validator.js +153 -0
  55. package/dist/modules/execution/planner.js +35 -0
  56. package/dist/modules/execution/stuck-detector.js +134 -0
  57. package/dist/modules/execution/tracker.js +53 -0
  58. package/dist/modules/execution/types.js +1 -0
  59. package/dist/modules/execution/verifier.js +149 -0
  60. package/dist/modules/hallucination/confidence.js +54 -0
  61. package/dist/modules/hallucination/consistency.js +60 -0
  62. package/dist/modules/hallucination/detector.js +41 -0
  63. package/dist/modules/hallucination/factual.js +170 -0
  64. package/dist/modules/hallucination/index.js +4 -0
  65. package/dist/modules/index.js +5 -0
  66. package/dist/modules/indexer/cache.js +38 -0
  67. package/dist/modules/indexer/index.js +3 -0
  68. package/dist/modules/indexer/module.js +192 -0
  69. package/dist/modules/indexer/walker.js +101 -0
  70. package/dist/modules/mcp/client.js +393 -0
  71. package/dist/modules/mcp/index.js +3 -0
  72. package/dist/modules/mcp/module.js +146 -0
  73. package/dist/modules/mcp/registry.js +15 -0
  74. package/dist/modules/memory/index.js +1 -0
  75. package/dist/modules/memory/module.js +48 -0
  76. package/dist/modules/memory/search.js +40 -0
  77. package/dist/modules/memory/store.js +65 -0
  78. package/dist/modules/pipelines/engine.js +60 -0
  79. package/dist/modules/pipelines/index.js +3 -0
  80. package/dist/modules/pipelines/parser.js +53 -0
  81. package/dist/modules/pipelines/template.js +14 -0
  82. package/dist/modules/plugins/builtin/lint-on-write.js +121 -0
  83. package/dist/modules/plugins/builtin/notify.js +8 -0
  84. package/dist/modules/plugins/index.js +1 -0
  85. package/dist/modules/plugins/loader.js +28 -0
  86. package/dist/modules/plugins/manager.js +161 -0
  87. package/dist/modules/plugins/types.js +1 -0
  88. package/dist/modules/processes/detect.js +34 -0
  89. package/dist/modules/processes/index.js +3 -0
  90. package/dist/modules/processes/registry.js +148 -0
  91. package/dist/modules/processes/runner.js +124 -0
  92. package/dist/modules/registry.js +45 -0
  93. package/dist/modules/security/audit-log.js +116 -0
  94. package/dist/modules/security/audit-notifier.js +292 -0
  95. package/dist/modules/security/command-validator.js +185 -0
  96. package/dist/modules/security/content-scanner.js +52 -0
  97. package/dist/modules/security/data-sanitizer.js +97 -0
  98. package/dist/modules/security/encryption.js +240 -0
  99. package/dist/modules/security/index.js +14 -0
  100. package/dist/modules/security/network-validator.js +79 -0
  101. package/dist/modules/security/path-validator.js +155 -0
  102. package/dist/modules/security/rate-limiter.js +119 -0
  103. package/dist/modules/security/security-policies.js +393 -0
  104. package/dist/modules/security/session-encryption.js +193 -0
  105. package/dist/modules/security/session-isolation.js +95 -0
  106. package/dist/modules/session/index.js +3 -0
  107. package/dist/modules/session/manager.js +167 -0
  108. package/dist/modules/session/module.js +24 -0
  109. package/dist/modules/session/store.js +174 -0
  110. package/dist/modules/session/types.js +1 -0
  111. package/dist/modules/skills/index.js +3 -0
  112. package/dist/modules/skills/loader.js +72 -0
  113. package/dist/modules/skills/matcher.js +27 -0
  114. package/dist/modules/skills/module.js +143 -0
  115. package/dist/modules/types.js +1 -0
  116. package/dist/modules/updater/checker.js +32 -0
  117. package/dist/modules/updater/index.js +1 -0
  118. package/dist/modules/user-profile/compressor.js +16 -0
  119. package/dist/modules/user-profile/index.js +1 -0
  120. package/dist/modules/user-profile/profile.js +68 -0
  121. package/dist/tools/approve.js +32 -0
  122. package/dist/tools/attach-image.js +89 -0
  123. package/dist/tools/bash.js +140 -0
  124. package/dist/tools/browser.js +97 -0
  125. package/dist/tools/create-dir.js +56 -0
  126. package/dist/tools/delete-file.js +63 -0
  127. package/dist/tools/edit-file.js +77 -0
  128. package/dist/tools/executor.js +95 -0
  129. package/dist/tools/file-info.js +45 -0
  130. package/dist/tools/filter-tools.js +10 -0
  131. package/dist/tools/glob-tool.js +26 -0
  132. package/dist/tools/grep-tool.js +64 -0
  133. package/dist/tools/index.js +52 -0
  134. package/dist/tools/list-dir.js +47 -0
  135. package/dist/tools/load-skill.js +48 -0
  136. package/dist/tools/mcp-call.js +68 -0
  137. package/dist/tools/move-file.js +84 -0
  138. package/dist/tools/path-utils.js +51 -0
  139. package/dist/tools/pipeline-run.js +144 -0
  140. package/dist/tools/preview.js +2 -0
  141. package/dist/tools/process-kill.js +29 -0
  142. package/dist/tools/process-list.js +38 -0
  143. package/dist/tools/process-log.js +41 -0
  144. package/dist/tools/question.js +142 -0
  145. package/dist/tools/read-file.js +73 -0
  146. package/dist/tools/recall.js +110 -0
  147. package/dist/tools/registry.js +36 -0
  148. package/dist/tools/remember.js +67 -0
  149. package/dist/tools/scope-check.js +30 -0
  150. package/dist/tools/search-history.js +64 -0
  151. package/dist/tools/subagent.js +142 -0
  152. package/dist/tools/types.js +1 -0
  153. package/dist/tools/user-input.js +123 -0
  154. package/dist/tools/web-browse.js +57 -0
  155. package/dist/tools/web-fetch.js +72 -0
  156. package/dist/tools/web-search.js +59 -0
  157. package/dist/tools/write-file.js +80 -0
  158. package/dist/ui/box.js +81 -0
  159. package/dist/ui/colors.js +4 -0
  160. package/dist/ui/diff.js +185 -0
  161. package/dist/ui/index.js +6 -0
  162. package/dist/ui/md-formatter.js +212 -0
  163. package/dist/ui/output.js +13 -0
  164. package/dist/ui/renderer.js +141 -0
  165. package/dist/ui/spinner.js +70 -0
  166. package/dist/ui/table.js +144 -0
  167. package/package.json +4 -4
@@ -0,0 +1,167 @@
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
+ }
@@ -0,0 +1,24 @@
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
+ }
@@ -0,0 +1,174 @@
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export { SkillsLoader } from './loader';
2
+ export { SkillsMatcher } from './matcher';
3
+ export { SkillsModule } from './module';
@@ -0,0 +1,72 @@
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
+ }
@@ -0,0 +1,27 @@
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
+ }
@@ -0,0 +1,143 @@
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
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
+ }
@@ -0,0 +1 @@
1
+ export { Updater } from './checker';
@@ -0,0 +1,16 @@
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
+ }
@@ -0,0 +1 @@
1
+ export { UserProfile } from './profile';