micro-models-agent 0.51.1 → 0.51.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.
- package/README.md +358 -358
- package/dist/main.js +817 -573
- package/dist/modules/browser/bridge-server.mjs +202 -202
- package/dist/skills/builtin/git.md +36 -36
- package/dist/skills/builtin/typescript.md +35 -35
- package/package.json +48 -48
- package/dist/cli/commands.js +0 -323
- package/dist/cli/completer.js +0 -167
- package/dist/cli/index.js +0 -2
- package/dist/cli/main.js +0 -165
- package/dist/cli/plugin-commands.js +0 -36
- package/dist/cli/repl-commands.js +0 -661
- package/dist/cli/repl.js +0 -616
- package/dist/cli/run-result.js +0 -22
- package/dist/cli/security-commands.js +0 -164
- package/dist/cli/setup.js +0 -231
- package/dist/config/config.js +0 -249
- package/dist/config/defaults.js +0 -124
- package/dist/config/experts.js +0 -15
- package/dist/config/index.js +0 -3
- package/dist/config/security.js +0 -193
- package/dist/config/types.js +0 -1
- package/dist/core/agent-moe.js +0 -102
- package/dist/core/agent.js +0 -886
- package/dist/core/bootstrap.js +0 -404
- package/dist/core/index.js +0 -2
- package/dist/core/prompt-builder.js +0 -76
- package/dist/core/session-logger.js +0 -197
- package/dist/core/types.js +0 -1
- package/dist/core/version.js +0 -24
- package/dist/core/workspace.js +0 -76
- package/dist/i18n/en.json +0 -598
- package/dist/i18n/index.js +0 -46
- package/dist/i18n/ru.json +0 -598
- package/dist/index.js +0 -22
- package/dist/llm/image-utils.js +0 -143
- package/dist/llm/index.js +0 -4
- package/dist/llm/model-loader.js +0 -78
- package/dist/llm/openai-compat.js +0 -359
- package/dist/llm/orchestrator.js +0 -198
- package/dist/llm/provider.js +0 -10
- package/dist/llm/response.js +0 -39
- package/dist/llm/token-counter.js +0 -39
- package/dist/llm/types.js +0 -1
- package/dist/logger/app-logger.js +0 -143
- package/dist/logger/file-log.js +0 -151
- package/dist/logger/index.js +0 -1
- package/dist/migration/backup.js +0 -45
- package/dist/migration/detect.js +0 -50
- package/dist/migration/index.js +0 -2
- package/dist/modules/artifacts/store.js +0 -61
- package/dist/modules/browser/actions.js +0 -76
- package/dist/modules/browser/bridge-client.js +0 -199
- package/dist/modules/browser/bridge-path.js +0 -10
- package/dist/modules/browser/cookie-store.js +0 -24
- package/dist/modules/browser/driver.js +0 -136
- package/dist/modules/browser/index.js +0 -7
- package/dist/modules/browser/module.js +0 -29
- package/dist/modules/browser/session.js +0 -338
- package/dist/modules/browser/snapshot.js +0 -148
- package/dist/modules/browser/types.js +0 -12
- package/dist/modules/certification/cli.js +0 -174
- package/dist/modules/certification/fact-checker.js +0 -82
- package/dist/modules/certification/loader.js +0 -105
- package/dist/modules/certification/manifest.js +0 -50
- package/dist/modules/certification/runner.js +0 -159
- package/dist/modules/certification/scenarios.js +0 -124
- package/dist/modules/certification/types.js +0 -1
- package/dist/modules/context/chunk-query.js +0 -100
- package/dist/modules/context/fact-extractor.js +0 -162
- package/dist/modules/context/history.js +0 -15
- package/dist/modules/context/index.js +0 -1
- package/dist/modules/context/manager.js +0 -423
- package/dist/modules/execution/audit-runners.js +0 -152
- package/dist/modules/execution/auditor.js +0 -218
- package/dist/modules/execution/execution-plugin.js +0 -272
- package/dist/modules/execution/index.js +0 -8
- package/dist/modules/execution/module.js +0 -436
- package/dist/modules/execution/moe-executor.js +0 -291
- package/dist/modules/execution/plan-coverage.js +0 -68
- package/dist/modules/execution/plan-persister.js +0 -46
- package/dist/modules/execution/plan-store.js +0 -157
- package/dist/modules/execution/plan-tool.js +0 -508
- package/dist/modules/execution/plan-validator.js +0 -153
- package/dist/modules/execution/planner.js +0 -90
- package/dist/modules/execution/stuck-detector.js +0 -510
- package/dist/modules/execution/tracker.js +0 -67
- package/dist/modules/execution/types.js +0 -1
- package/dist/modules/execution/verifier.js +0 -222
- package/dist/modules/execution/windows-commands.js +0 -41
- package/dist/modules/hallucination/confidence.js +0 -66
- package/dist/modules/hallucination/consistency.js +0 -26
- package/dist/modules/hallucination/detector.js +0 -43
- package/dist/modules/hallucination/factual.js +0 -129
- package/dist/modules/hallucination/index.js +0 -5
- package/dist/modules/hallucination/js-identifiers.js +0 -262
- package/dist/modules/hallucination/llm-judge.js +0 -101
- package/dist/modules/index.js +0 -5
- package/dist/modules/indexer/cache.js +0 -40
- package/dist/modules/indexer/index.js +0 -3
- package/dist/modules/indexer/module.js +0 -245
- package/dist/modules/indexer/project-profile.js +0 -183
- package/dist/modules/indexer/walker.js +0 -101
- package/dist/modules/lsp/check-tool.js +0 -58
- package/dist/modules/lsp/client.js +0 -278
- package/dist/modules/lsp/command.js +0 -60
- package/dist/modules/lsp/config.js +0 -135
- package/dist/modules/lsp/index.js +0 -3
- package/dist/modules/lsp/module.js +0 -232
- package/dist/modules/lsp/probe.js +0 -76
- package/dist/modules/lsp/project-root.js +0 -32
- package/dist/modules/lsp/startup-check.js +0 -141
- package/dist/modules/lsp/types.js +0 -1
- package/dist/modules/mcp/client.js +0 -399
- package/dist/modules/mcp/index.js +0 -3
- package/dist/modules/mcp/module.js +0 -142
- package/dist/modules/mcp/registry.js +0 -15
- package/dist/modules/memory/index.js +0 -1
- package/dist/modules/memory/module.js +0 -96
- package/dist/modules/memory/search.js +0 -42
- package/dist/modules/memory/store.js +0 -69
- package/dist/modules/pipelines/engine.js +0 -60
- package/dist/modules/pipelines/index.js +0 -3
- package/dist/modules/pipelines/parser.js +0 -56
- package/dist/modules/pipelines/template.js +0 -14
- package/dist/modules/plugins/builtin/lint-on-write.js +0 -231
- package/dist/modules/plugins/builtin/notify.js +0 -9
- package/dist/modules/plugins/index.js +0 -1
- package/dist/modules/plugins/loader.js +0 -70
- package/dist/modules/plugins/manager.js +0 -217
- package/dist/modules/plugins/types.js +0 -1
- package/dist/modules/processes/detect.js +0 -34
- package/dist/modules/processes/index.js +0 -2
- package/dist/modules/processes/registry.js +0 -327
- package/dist/modules/processes/runner.js +0 -23
- package/dist/modules/registry.js +0 -47
- package/dist/modules/security/audit-log.js +0 -136
- package/dist/modules/security/audit-notifier.js +0 -292
- package/dist/modules/security/command-validator.js +0 -205
- package/dist/modules/security/content-scanner.js +0 -53
- package/dist/modules/security/data-sanitizer.js +0 -89
- package/dist/modules/security/encryption.js +0 -242
- package/dist/modules/security/index.js +0 -14
- package/dist/modules/security/network-validator.js +0 -71
- package/dist/modules/security/path-validator.js +0 -207
- package/dist/modules/security/rate-limiter.js +0 -119
- package/dist/modules/security/security-policies.js +0 -531
- package/dist/modules/security/session-encryption.js +0 -210
- package/dist/modules/security/session-isolation.js +0 -95
- package/dist/modules/session/index.js +0 -3
- package/dist/modules/session/manager.js +0 -172
- package/dist/modules/session/module.js +0 -24
- package/dist/modules/session/store.js +0 -222
- package/dist/modules/session/types.js +0 -1
- package/dist/modules/skills/index.js +0 -2
- package/dist/modules/skills/loader.js +0 -72
- package/dist/modules/skills/matcher.js +0 -27
- package/dist/modules/skills/module.js +0 -129
- package/dist/modules/types.js +0 -1
- package/dist/modules/updater/checker.js +0 -96
- package/dist/modules/updater/index.js +0 -2
- package/dist/modules/updater/module.js +0 -116
- package/dist/modules/user-profile/compressor.js +0 -16
- package/dist/modules/user-profile/index.js +0 -1
- package/dist/modules/user-profile/profile.js +0 -68
- package/dist/tools/approve.js +0 -32
- package/dist/tools/attach-image.js +0 -89
- package/dist/tools/bash.js +0 -496
- package/dist/tools/browser.js +0 -114
- package/dist/tools/chunk-query.js +0 -99
- package/dist/tools/create-dir.js +0 -55
- package/dist/tools/delete-file.js +0 -62
- package/dist/tools/download-file.js +0 -116
- package/dist/tools/edit-file.js +0 -79
- package/dist/tools/enable-tools.js +0 -58
- package/dist/tools/executor.js +0 -144
- package/dist/tools/file-info.js +0 -46
- package/dist/tools/filter-tools.js +0 -17
- package/dist/tools/glob-tool.js +0 -26
- package/dist/tools/grep-tool.js +0 -84
- package/dist/tools/hidden-tools-block.js +0 -37
- package/dist/tools/index.js +0 -78
- package/dist/tools/list-dir.js +0 -48
- package/dist/tools/load-skill.js +0 -42
- package/dist/tools/mcp-call.js +0 -68
- package/dist/tools/move-file.js +0 -85
- package/dist/tools/path-utils.js +0 -51
- package/dist/tools/pipeline-run.js +0 -144
- package/dist/tools/preview.js +0 -2
- package/dist/tools/process-kill.js +0 -29
- package/dist/tools/process-list.js +0 -36
- package/dist/tools/process-log.js +0 -45
- package/dist/tools/question.js +0 -140
- package/dist/tools/read-file.js +0 -91
- package/dist/tools/recall.js +0 -117
- package/dist/tools/registry.js +0 -47
- package/dist/tools/remember.js +0 -67
- package/dist/tools/scope-check.js +0 -30
- package/dist/tools/search-history.js +0 -84
- package/dist/tools/subagent.js +0 -196
- package/dist/tools/types.js +0 -1
- package/dist/tools/user-input.js +0 -123
- package/dist/tools/web-browse.js +0 -86
- package/dist/tools/web-fetch.js +0 -98
- package/dist/tools/web-search.js +0 -78
- package/dist/tools/write-file.js +0 -81
- package/dist/ui/box.js +0 -77
- package/dist/ui/colors.js +0 -4
- package/dist/ui/diff.js +0 -178
- package/dist/ui/index.js +0 -6
- package/dist/ui/line-editor.js +0 -703
- package/dist/ui/line-math.js +0 -69
- package/dist/ui/md-formatter.js +0 -212
- package/dist/ui/output.js +0 -13
- package/dist/ui/plan-view.js +0 -103
- package/dist/ui/renderer.js +0 -209
- package/dist/ui/spinner.js +0 -70
- package/dist/ui/table.js +0 -144
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { semverGt } from "../updater/checker";
|
|
2
|
-
export class PluginManager {
|
|
3
|
-
plugins = [];
|
|
4
|
-
/**
|
|
5
|
-
* Register a plugin. Plugins with the same `name` are deduplicated — the
|
|
6
|
-
* higher `version` wins (unversioned plugins count as "0.0.0"). The loser is
|
|
7
|
-
* discarded; `skipped_older` lets the caller warn about the dropped copy.
|
|
8
|
-
*/
|
|
9
|
-
register(plugin, source) {
|
|
10
|
-
if (source)
|
|
11
|
-
plugin.source = source;
|
|
12
|
-
const existing = this.plugins.find((p) => p.name === plugin.name);
|
|
13
|
-
if (existing) {
|
|
14
|
-
if (semverGt(plugin.version || "0.0.0", existing.version || "0.0.0")) {
|
|
15
|
-
this.plugins = this.plugins.filter((p) => p.name !== plugin.name);
|
|
16
|
-
this.plugins.push(plugin);
|
|
17
|
-
this.sort();
|
|
18
|
-
return { status: "registered" };
|
|
19
|
-
}
|
|
20
|
-
return { status: "skipped_older", existing };
|
|
21
|
-
}
|
|
22
|
-
this.plugins.push(plugin);
|
|
23
|
-
this.sort();
|
|
24
|
-
return { status: "registered" };
|
|
25
|
-
}
|
|
26
|
-
sort() {
|
|
27
|
-
this.plugins.sort((a, b) => (b.priority || 0) - (a.priority || 0));
|
|
28
|
-
}
|
|
29
|
-
getAllPlugins() {
|
|
30
|
-
return [...this.plugins];
|
|
31
|
-
}
|
|
32
|
-
/** Detailed plugin list (name, version, source) for REPL / CLI display. */
|
|
33
|
-
getPluginInfos() {
|
|
34
|
-
return [...this.plugins].map((plugin) => ({ plugin, source: plugin.source }));
|
|
35
|
-
}
|
|
36
|
-
/** Find a registered plugin by name, or null. */
|
|
37
|
-
getPlugin(name) {
|
|
38
|
-
return this.plugins.find((p) => p.name === name) ?? null;
|
|
39
|
-
}
|
|
40
|
-
runOnBuildPrompt() {
|
|
41
|
-
return this.plugins.map((p) => {
|
|
42
|
-
try {
|
|
43
|
-
return p.onBuildPrompt?.() ?? null;
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
async runOnBeforeTool(ctx, call) {
|
|
51
|
-
for (const plugin of this.plugins) {
|
|
52
|
-
if (plugin.onBeforeTool) {
|
|
53
|
-
try {
|
|
54
|
-
const result = await plugin.onBeforeTool(ctx, call);
|
|
55
|
-
if (result === false)
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
/* error isolation */
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
async runOnAfterTool(ctx, call, result) {
|
|
66
|
-
for (const plugin of this.plugins) {
|
|
67
|
-
if (plugin.onAfterTool) {
|
|
68
|
-
try {
|
|
69
|
-
await plugin.onAfterTool(ctx, call, result);
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
/* error isolation */
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
async runOnError(ctx, error) {
|
|
78
|
-
for (const plugin of this.plugins) {
|
|
79
|
-
if (plugin.onError) {
|
|
80
|
-
try {
|
|
81
|
-
await plugin.onError(ctx, error);
|
|
82
|
-
}
|
|
83
|
-
catch {
|
|
84
|
-
/* error isolation */
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
runOnSessionStart(ctx) {
|
|
90
|
-
for (const plugin of this.plugins) {
|
|
91
|
-
if (plugin.onSessionStart) {
|
|
92
|
-
try {
|
|
93
|
-
plugin.onSessionStart(ctx);
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
/* error isolation */
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
runOnBeforeThink(ctx) {
|
|
102
|
-
for (const plugin of this.plugins) {
|
|
103
|
-
if (plugin.onBeforeThink) {
|
|
104
|
-
try {
|
|
105
|
-
plugin.onBeforeThink(ctx);
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
/* error isolation */
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
runOnAfterThink(ctx, response) {
|
|
114
|
-
for (const plugin of this.plugins) {
|
|
115
|
-
if (plugin.onAfterThink) {
|
|
116
|
-
try {
|
|
117
|
-
plugin.onAfterThink(ctx, response);
|
|
118
|
-
}
|
|
119
|
-
catch {
|
|
120
|
-
/* error isolation */
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
runOnSessionEnd(ctx) {
|
|
126
|
-
for (const plugin of this.plugins) {
|
|
127
|
-
if (plugin.onSessionEnd) {
|
|
128
|
-
try {
|
|
129
|
-
plugin.onSessionEnd(ctx);
|
|
130
|
-
}
|
|
131
|
-
catch {
|
|
132
|
-
/* error isolation */
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
runOnToolCall(ctx) {
|
|
138
|
-
for (const plugin of this.plugins) {
|
|
139
|
-
if (plugin.onToolCall) {
|
|
140
|
-
try {
|
|
141
|
-
plugin.onToolCall(ctx);
|
|
142
|
-
}
|
|
143
|
-
catch {
|
|
144
|
-
/* error isolation */
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
runOnPhase(ctx, phase) {
|
|
150
|
-
for (const plugin of this.plugins) {
|
|
151
|
-
if (plugin.onPhase) {
|
|
152
|
-
try {
|
|
153
|
-
plugin.onPhase(ctx, phase);
|
|
154
|
-
}
|
|
155
|
-
catch {
|
|
156
|
-
/* error isolation */
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
runOnToolStart(ctx, call) {
|
|
162
|
-
for (const plugin of this.plugins) {
|
|
163
|
-
if (plugin.onToolStart) {
|
|
164
|
-
try {
|
|
165
|
-
plugin.onToolStart(ctx, call);
|
|
166
|
-
}
|
|
167
|
-
catch {
|
|
168
|
-
/* error isolation */
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
runOnToolEnd(ctx, call, result, durationMs) {
|
|
174
|
-
for (const plugin of this.plugins) {
|
|
175
|
-
if (plugin.onToolEnd) {
|
|
176
|
-
try {
|
|
177
|
-
plugin.onToolEnd(ctx, call, result, durationMs);
|
|
178
|
-
}
|
|
179
|
-
catch {
|
|
180
|
-
/* error isolation */
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
/** Pipe a text chunk through plugin transforms; returns the (possibly replaced) chunk. */
|
|
186
|
-
runOnText(ctx, chunk) {
|
|
187
|
-
for (const plugin of this.plugins) {
|
|
188
|
-
if (plugin.onText) {
|
|
189
|
-
try {
|
|
190
|
-
const out = plugin.onText(ctx, chunk);
|
|
191
|
-
if (typeof out === "string")
|
|
192
|
-
chunk = out;
|
|
193
|
-
}
|
|
194
|
-
catch {
|
|
195
|
-
/* error isolation */
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return chunk;
|
|
200
|
-
}
|
|
201
|
-
/** Pipe a meta chunk through plugin transforms; returns the (possibly replaced) chunk. */
|
|
202
|
-
runOnMeta(ctx, chunk) {
|
|
203
|
-
for (const plugin of this.plugins) {
|
|
204
|
-
if (plugin.onMeta) {
|
|
205
|
-
try {
|
|
206
|
-
const out = plugin.onMeta(ctx, chunk);
|
|
207
|
-
if (typeof out === "string")
|
|
208
|
-
chunk = out;
|
|
209
|
-
}
|
|
210
|
-
catch {
|
|
211
|
-
/* error isolation */
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return chunk;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Heuristic detection of long-running (server/watch) commands.
|
|
3
|
-
*
|
|
4
|
-
* The explicit `background: true` bash parameter always wins; this list is a
|
|
5
|
-
* convenience so dev servers don't block the agent. It only inspects the raw
|
|
6
|
-
* shell command (a technical process-type decision, not task classification).
|
|
7
|
-
*/
|
|
8
|
-
const LONG_RUNNING_PATTERNS = [
|
|
9
|
-
/\b(npm|pnpm|yarn|bun|npx)\s+(run\s+)?(dev|start|serve|preview|watch|server)\b/i,
|
|
10
|
-
/\b(deno|node)\s+.*\b(run\s+)?(dev|serve|watch|server)\b/i,
|
|
11
|
-
/(^|\s)--watch\b/i,
|
|
12
|
-
/(^|\s)-w\b/i,
|
|
13
|
-
/\bnodemon\b/i,
|
|
14
|
-
/\btsx watch\b/i,
|
|
15
|
-
/\b(ts-node|tsc)\s+.*--watch\b/i,
|
|
16
|
-
/\bvite(?!\s+(build|create))\b/i,
|
|
17
|
-
/\bwebpack(-dev-server|\s+serve)\b/i,
|
|
18
|
-
/\bastro dev\b/i,
|
|
19
|
-
/\bnext (dev|start)\b/i,
|
|
20
|
-
/\bnuxt (dev|start)\b/i,
|
|
21
|
-
/\bsvelte-kit (dev|preview)\b/i,
|
|
22
|
-
/\bgatsby develop\b/i,
|
|
23
|
-
/\bdocker(-compose)?\s+.*\bup\b/i,
|
|
24
|
-
/\buvicorn\b|\bgunicorn\b/i,
|
|
25
|
-
/\bpython\s+-m\s+http\.server\b/i,
|
|
26
|
-
/\bflask run\b/i,
|
|
27
|
-
/\bphp artisan serve\b/i,
|
|
28
|
-
/\brails (server|s)\b/i,
|
|
29
|
-
/\bvitest watch\b/i,
|
|
30
|
-
/\bjest --watch\b/i,
|
|
31
|
-
];
|
|
32
|
-
export function isLongRunningCommand(command) {
|
|
33
|
-
return LONG_RUNNING_PATTERNS.some((pattern) => pattern.test(command));
|
|
34
|
-
}
|
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import { spawn, spawnSync } from "child_process";
|
|
2
|
-
import { platform } from "os";
|
|
3
|
-
const MAX_LOG_LINES = 2000;
|
|
4
|
-
const MAX_KEPT_PROCESSES = 20;
|
|
5
|
-
let seq = 0;
|
|
6
|
-
/** OEM decoder (Russian CP866 / active code page) — cached after first use. */
|
|
7
|
-
let oemDecoder;
|
|
8
|
-
function getOemDecoder() {
|
|
9
|
-
if (oemDecoder !== undefined)
|
|
10
|
-
return oemDecoder;
|
|
11
|
-
oemDecoder = null;
|
|
12
|
-
try {
|
|
13
|
-
const cpOut = spawnSync("chcp.com", {
|
|
14
|
-
encoding: "buffer",
|
|
15
|
-
timeout: 2000,
|
|
16
|
-
windowsHide: true,
|
|
17
|
-
}).stdout;
|
|
18
|
-
const m = cpOut ? cpOut.toString("latin1").match(/(\d+)/) : null;
|
|
19
|
-
if (m) {
|
|
20
|
-
try {
|
|
21
|
-
oemDecoder = new TextDecoder("ibm" + m[1]);
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
oemDecoder = null;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
/* ignore */
|
|
30
|
-
}
|
|
31
|
-
if (!oemDecoder) {
|
|
32
|
-
try {
|
|
33
|
-
oemDecoder = new TextDecoder("ibm866");
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
oemDecoder = null;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return oemDecoder;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Decode one complete line of output to UTF-8.
|
|
43
|
-
*
|
|
44
|
-
* Modern tools (Bun, Node, npm, git) write UTF-8 into the pipe regardless of
|
|
45
|
-
* the console code page, while built-in cmd.exe commands (echo, type, dir)
|
|
46
|
-
* emit the OEM code page (CP866 on Russian Windows). Try strict UTF-8 first;
|
|
47
|
-
* fall back to the OEM decoder when the bytes are not valid UTF-8.
|
|
48
|
-
*/
|
|
49
|
-
function decodeLineToUtf8(buf) {
|
|
50
|
-
try {
|
|
51
|
-
return new TextDecoder("utf-8", { fatal: true }).decode(buf);
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
/* not valid UTF-8 → OEM code page output */
|
|
55
|
-
}
|
|
56
|
-
const oem = getOemDecoder();
|
|
57
|
-
if (oem) {
|
|
58
|
-
try {
|
|
59
|
-
return oem.decode(buf);
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
/* unknown encoding — latin1 fallback */
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return buf.toString("latin1");
|
|
66
|
-
}
|
|
67
|
-
/** Synchronous pause without blocking the event loop (via Atomics.wait). */
|
|
68
|
-
function sleepSync(ms) {
|
|
69
|
-
try {
|
|
70
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
/* ignore */
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function taskkillPid(pid) {
|
|
77
|
-
try {
|
|
78
|
-
spawnSync("taskkill", ["/pid", String(pid), "/T", "/F"], {
|
|
79
|
-
windowsHide: true,
|
|
80
|
-
stdio: "ignore",
|
|
81
|
-
timeout: 5000,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
/* already dead */
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Kill a spawned tree on Windows.
|
|
90
|
-
*
|
|
91
|
-
* `taskkill /T` has a race: when cmd.exe is killed, a child (node) that is
|
|
92
|
-
* still starting up can survive as an orphan because it was never attached to
|
|
93
|
-
* the tree at kill time. A single pass misses it. Running taskkill twice with
|
|
94
|
-
* a settle gap catches those late starters on the second pass — the second
|
|
95
|
-
* tree walk sees the child that was still being created during the first one.
|
|
96
|
-
* This is much cheaper than enumerating processes (wmic/PowerShell), which
|
|
97
|
-
* slows every kill down to seconds under parallel load.
|
|
98
|
-
*/
|
|
99
|
-
export function killTree(child) {
|
|
100
|
-
const pid = child.pid;
|
|
101
|
-
if (!pid)
|
|
102
|
-
return;
|
|
103
|
-
if (platform() === "win32") {
|
|
104
|
-
taskkillPid(pid);
|
|
105
|
-
sleepSync(150);
|
|
106
|
-
taskkillPid(pid);
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
try {
|
|
110
|
-
process.kill(-pid, "SIGTERM");
|
|
111
|
-
}
|
|
112
|
-
catch {
|
|
113
|
-
try {
|
|
114
|
-
child.kill("SIGKILL");
|
|
115
|
-
}
|
|
116
|
-
catch {
|
|
117
|
-
/* already dead */
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
class ProcessRegistry {
|
|
122
|
-
procs = new Map();
|
|
123
|
-
children = new Map();
|
|
124
|
-
exitWaiters = new Map();
|
|
125
|
-
/**
|
|
126
|
-
* Start a command. The returned entry buffers output and reports status; a
|
|
127
|
-
* call may check `waitForExit(id)` to learn when (if ever) it finishes.
|
|
128
|
-
*/
|
|
129
|
-
start(command, cwd, sessionId) {
|
|
130
|
-
const id = `proc_${Date.now()}_${++seq}`;
|
|
131
|
-
const entry = {
|
|
132
|
-
id,
|
|
133
|
-
pid: 0,
|
|
134
|
-
command,
|
|
135
|
-
cwd,
|
|
136
|
-
sessionId,
|
|
137
|
-
status: "running",
|
|
138
|
-
exitCode: null,
|
|
139
|
-
startedAt: new Date().toISOString(),
|
|
140
|
-
log: [],
|
|
141
|
-
};
|
|
142
|
-
this.trimOldEntries();
|
|
143
|
-
this.procs.set(id, entry);
|
|
144
|
-
let child;
|
|
145
|
-
try {
|
|
146
|
-
child = spawn(command, {
|
|
147
|
-
cwd,
|
|
148
|
-
shell: true,
|
|
149
|
-
windowsHide: true,
|
|
150
|
-
detached: platform() !== "win32",
|
|
151
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
catch (e) {
|
|
155
|
-
entry.status = "killed";
|
|
156
|
-
entry.spawnError = e?.message || String(e);
|
|
157
|
-
entry.log.push(`[process error] ${entry.spawnError}`);
|
|
158
|
-
return entry;
|
|
159
|
-
}
|
|
160
|
-
this.children.set(id, child);
|
|
161
|
-
entry.pid = child.pid ?? 0;
|
|
162
|
-
let buf = "";
|
|
163
|
-
let byteBuf = Buffer.alloc(0);
|
|
164
|
-
const isWin = platform() === "win32";
|
|
165
|
-
const unixDecoder = new TextDecoder("utf-8");
|
|
166
|
-
const pushLine = (line) => {
|
|
167
|
-
if (entry.log.length >= MAX_LOG_LINES) {
|
|
168
|
-
entry.log.shift();
|
|
169
|
-
}
|
|
170
|
-
entry.log.push(line);
|
|
171
|
-
};
|
|
172
|
-
const append = (chunk) => {
|
|
173
|
-
if (!isWin) {
|
|
174
|
-
const decoded = unixDecoder.decode(chunk, { stream: true });
|
|
175
|
-
buf += decoded;
|
|
176
|
-
const lines = buf.split(/\r?\n/);
|
|
177
|
-
buf = lines.pop() ?? "";
|
|
178
|
-
for (const line of lines) {
|
|
179
|
-
pushLine(line);
|
|
180
|
-
}
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
// Windows: buffer raw bytes and decode per line. Modern tools (Bun, Node,
|
|
184
|
-
// npm, git) write UTF-8 into the pipe regardless of the console code
|
|
185
|
-
// page; cmd.exe builtins (echo, type, dir) emit the OEM code page. Pick
|
|
186
|
-
// the right decoding per line so Russian text survives either way.
|
|
187
|
-
byteBuf = byteBuf.length ? Buffer.concat([byteBuf, chunk]) : Buffer.from(chunk);
|
|
188
|
-
let nl;
|
|
189
|
-
while ((nl = byteBuf.indexOf(0x0a)) !== -1) {
|
|
190
|
-
const raw = byteBuf.subarray(0, nl);
|
|
191
|
-
byteBuf = byteBuf.subarray(nl + 1);
|
|
192
|
-
pushLine(decodeLineToUtf8(raw).replace(/\r$/, ""));
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
const flush = () => {
|
|
196
|
-
if (!isWin) {
|
|
197
|
-
buf += unixDecoder.decode();
|
|
198
|
-
if (buf) {
|
|
199
|
-
pushLine(buf);
|
|
200
|
-
buf = "";
|
|
201
|
-
}
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
if (byteBuf.length) {
|
|
205
|
-
pushLine(decodeLineToUtf8(byteBuf));
|
|
206
|
-
byteBuf = Buffer.alloc(0);
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
const resolveExit = () => {
|
|
210
|
-
this.exitWaiters.get(id)?.resolve();
|
|
211
|
-
};
|
|
212
|
-
child.stdout?.on("data", append);
|
|
213
|
-
child.stderr?.on("data", append);
|
|
214
|
-
child.on("error", (err) => {
|
|
215
|
-
if (entry.status === "running") {
|
|
216
|
-
entry.status = "killed";
|
|
217
|
-
}
|
|
218
|
-
entry.spawnError = err.message;
|
|
219
|
-
// Write directly to the log, not through `append`: a failed spawn often
|
|
220
|
-
// never emits `close`, so the buffered line would never be flushed and
|
|
221
|
-
// the log would be empty (observed: "records a spawn error" test).
|
|
222
|
-
pushLine(`[process error] ${err.message}`);
|
|
223
|
-
resolveExit();
|
|
224
|
-
});
|
|
225
|
-
child.on("close", (code) => {
|
|
226
|
-
flush();
|
|
227
|
-
if (entry.status === "running") {
|
|
228
|
-
entry.status = "exited";
|
|
229
|
-
}
|
|
230
|
-
entry.exitCode = code;
|
|
231
|
-
this.children.delete(id);
|
|
232
|
-
resolveExit();
|
|
233
|
-
});
|
|
234
|
-
let resolve;
|
|
235
|
-
const promise = new Promise((r) => {
|
|
236
|
-
resolve = r;
|
|
237
|
-
});
|
|
238
|
-
this.exitWaiters.set(id, { promise, resolve });
|
|
239
|
-
return entry;
|
|
240
|
-
}
|
|
241
|
-
list(sessionId) {
|
|
242
|
-
const all = Array.from(this.procs.values());
|
|
243
|
-
if (!sessionId)
|
|
244
|
-
return all;
|
|
245
|
-
return all.filter((p) => p.sessionId === sessionId);
|
|
246
|
-
}
|
|
247
|
-
get(id) {
|
|
248
|
-
return this.procs.get(id);
|
|
249
|
-
}
|
|
250
|
-
getLog(id, tail) {
|
|
251
|
-
const entry = this.procs.get(id);
|
|
252
|
-
if (!entry)
|
|
253
|
-
return "";
|
|
254
|
-
const lines = tail && tail > 0 ? entry.log.slice(-tail) : entry.log;
|
|
255
|
-
return lines.join("\n");
|
|
256
|
-
}
|
|
257
|
-
/** Kill a background process tree. Returns false when not found. */
|
|
258
|
-
kill(id) {
|
|
259
|
-
const entry = this.procs.get(id);
|
|
260
|
-
if (!entry)
|
|
261
|
-
return false;
|
|
262
|
-
if (entry.status === "running") {
|
|
263
|
-
entry.status = "killed";
|
|
264
|
-
const child = this.children.get(id);
|
|
265
|
-
if (child) {
|
|
266
|
-
killTree(child);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return true;
|
|
270
|
-
}
|
|
271
|
-
/** Kill every managed background process (used on agent shutdown). */
|
|
272
|
-
killAll(sessionId) {
|
|
273
|
-
const targets = this.list(sessionId);
|
|
274
|
-
for (const entry of targets) {
|
|
275
|
-
this.kill(entry.id);
|
|
276
|
-
}
|
|
277
|
-
return targets.length;
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Resolve `true` when the process exits (or fails to spawn) within
|
|
281
|
-
* `timeoutMs`, otherwise `false` (still running → a background process).
|
|
282
|
-
*/
|
|
283
|
-
waitForExit(id, timeoutMs) {
|
|
284
|
-
const entry = this.procs.get(id);
|
|
285
|
-
const waiter = this.exitWaiters.get(id);
|
|
286
|
-
if (!entry || entry.status !== "running" || !waiter) {
|
|
287
|
-
return Promise.resolve(true);
|
|
288
|
-
}
|
|
289
|
-
return new Promise((resolve) => {
|
|
290
|
-
const timer = setTimeout(() => resolve(false), timeoutMs);
|
|
291
|
-
waiter.promise.then(() => {
|
|
292
|
-
clearTimeout(timer);
|
|
293
|
-
resolve(true);
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Remove a finished entry (foreground results do not linger). A still-running
|
|
299
|
-
* entry is killed first so nothing is orphaned.
|
|
300
|
-
*/
|
|
301
|
-
remove(id) {
|
|
302
|
-
const entry = this.procs.get(id);
|
|
303
|
-
if (!entry)
|
|
304
|
-
return false;
|
|
305
|
-
if (entry.status === "running") {
|
|
306
|
-
const child = this.children.get(id);
|
|
307
|
-
if (child) {
|
|
308
|
-
killTree(child);
|
|
309
|
-
}
|
|
310
|
-
entry.status = "killed";
|
|
311
|
-
}
|
|
312
|
-
this.procs.delete(id);
|
|
313
|
-
this.children.delete(id);
|
|
314
|
-
this.exitWaiters.delete(id);
|
|
315
|
-
return true;
|
|
316
|
-
}
|
|
317
|
-
trimOldEntries() {
|
|
318
|
-
if (this.procs.size < MAX_KEPT_PROCESSES)
|
|
319
|
-
return;
|
|
320
|
-
const sorted = Array.from(this.procs.values()).sort((a, b) => a.startedAt.localeCompare(b.startedAt));
|
|
321
|
-
const toRemove = sorted.slice(0, sorted.length - MAX_KEPT_PROCESSES + 1);
|
|
322
|
-
for (const entry of toRemove) {
|
|
323
|
-
this.remove(entry.id);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
export const processRegistry = new ProcessRegistry();
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const activeChildren = new Map();
|
|
2
|
-
/** Register a kill callback for a tool call id (executor timeout/abort). */
|
|
3
|
-
export function registerKillable(callId, kill) {
|
|
4
|
-
activeChildren.set(callId, { kill });
|
|
5
|
-
}
|
|
6
|
-
/** Unregister a tool call's kill callback once its handler finished. */
|
|
7
|
-
export function unregisterKillable(callId) {
|
|
8
|
-
activeChildren.delete(callId);
|
|
9
|
-
}
|
|
10
|
-
/** Invoke (and drop) the kill callback registered for `callId`. */
|
|
11
|
-
export function killByCallId(callId) {
|
|
12
|
-
const entry = activeChildren.get(callId);
|
|
13
|
-
if (!entry)
|
|
14
|
-
return false;
|
|
15
|
-
activeChildren.delete(callId);
|
|
16
|
-
try {
|
|
17
|
-
entry.kill();
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
20
|
-
/* already dead */
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
}
|
package/dist/modules/registry.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export class ModuleRegistry {
|
|
2
|
-
modules = new Map();
|
|
3
|
-
register(mod) {
|
|
4
|
-
this.modules.set(mod.name, mod);
|
|
5
|
-
}
|
|
6
|
-
get(name) {
|
|
7
|
-
return this.modules.get(name);
|
|
8
|
-
}
|
|
9
|
-
listModules() {
|
|
10
|
-
return Array.from(this.modules.keys()).sort();
|
|
11
|
-
}
|
|
12
|
-
collectPromptBlocks(exclude = []) {
|
|
13
|
-
const blocks = [];
|
|
14
|
-
for (const [name, mod] of this.modules) {
|
|
15
|
-
if (exclude.includes(name))
|
|
16
|
-
continue;
|
|
17
|
-
if (mod.getSystemPromptBlock) {
|
|
18
|
-
const block = mod.getSystemPromptBlock();
|
|
19
|
-
if (block)
|
|
20
|
-
blocks.push(block);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return blocks;
|
|
24
|
-
}
|
|
25
|
-
collectToolDefinitions() {
|
|
26
|
-
const tools = [];
|
|
27
|
-
for (const mod of this.modules.values()) {
|
|
28
|
-
if (mod.getToolDefinitions) {
|
|
29
|
-
const defs = mod.getToolDefinitions();
|
|
30
|
-
if (defs)
|
|
31
|
-
tools.push(...defs);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return tools;
|
|
35
|
-
}
|
|
36
|
-
collectPlugins() {
|
|
37
|
-
const plugins = [];
|
|
38
|
-
for (const mod of this.modules.values()) {
|
|
39
|
-
if (mod.getPlugin) {
|
|
40
|
-
const plugin = mod.getPlugin();
|
|
41
|
-
if (plugin)
|
|
42
|
-
plugins.push(plugin);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return plugins;
|
|
46
|
-
}
|
|
47
|
-
}
|