micro-models-agent 0.59.0 → 0.60.1
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/CHANGELOG.md +584 -564
- package/README.md +358 -358
- package/dist/certification/certifications.json +493 -493
- package/dist/i18n/en.json +746 -718
- package/dist/i18n/ru.json +746 -718
- package/dist/main.js +566 -70
- package/dist/modules/browser/bridge-server.mjs +219 -219
- package/dist/skills/builtin/git.md +36 -36
- package/dist/skills/builtin/typescript.md +35 -35
- package/package.json +51 -51
- package/dist/cli/commands.js +0 -447
- package/dist/cli/completer.js +0 -167
- package/dist/cli/index.js +0 -2
- package/dist/cli/main.js +0 -153
- package/dist/cli/plugin-commands.js +0 -36
- package/dist/cli/repl-commands.js +0 -761
- package/dist/cli/repl.js +0 -702
- package/dist/cli/run-result.js +0 -33
- package/dist/cli/security-commands.js +0 -164
- package/dist/cli/setup.js +0 -237
- package/dist/config/config.js +0 -276
- package/dist/config/defaults.js +0 -141
- package/dist/config/domains.js +0 -179
- package/dist/config/experts.js +0 -15
- package/dist/config/index.js +0 -4
- package/dist/config/security.js +0 -213
- package/dist/config/types.js +0 -1
- package/dist/core/agent-moe.js +0 -102
- package/dist/core/agent.js +0 -1018
- package/dist/core/bootstrap.js +0 -481
- package/dist/core/crash-handler.js +0 -51
- package/dist/core/environment.js +0 -199
- package/dist/core/index.js +0 -2
- package/dist/core/prompt-builder.js +0 -76
- package/dist/core/session-logger.js +0 -251
- package/dist/core/types.js +0 -1
- package/dist/core/version.js +0 -26
- package/dist/core/workspace.js +0 -76
- package/dist/i18n/index.js +0 -46
- 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 -497
- package/dist/llm/orchestrator.js +0 -200
- 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 -189
- 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 -342
- package/dist/modules/browser/snapshot.js +0 -148
- package/dist/modules/browser/types.js +0 -12
- package/dist/modules/certification/cli.js +0 -213
- package/dist/modules/certification/fact-checker.js +0 -82
- package/dist/modules/certification/loader.js +0 -106
- package/dist/modules/certification/manifest.js +0 -58
- package/dist/modules/certification/runner.js +0 -245
- package/dist/modules/certification/scenarios.js +0 -407
- 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 -168
- package/dist/modules/context/history.js +0 -15
- package/dist/modules/context/index.js +0 -1
- package/dist/modules/context/manager.js +0 -440
- package/dist/modules/execution/audit-runners.js +0 -206
- package/dist/modules/execution/auditor.js +0 -218
- package/dist/modules/execution/execution-plugin.js +0 -431
- package/dist/modules/execution/index.js +0 -8
- package/dist/modules/execution/module.js +0 -625
- package/dist/modules/execution/moe-executor.js +0 -304
- 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 -196
- package/dist/modules/execution/plan-tool.js +0 -677
- package/dist/modules/execution/plan-validator.js +0 -153
- package/dist/modules/execution/planner.js +0 -94
- package/dist/modules/execution/stuck-detector.js +0 -746
- package/dist/modules/execution/tracker.js +0 -69
- package/dist/modules/execution/types.js +0 -1
- package/dist/modules/execution/verifier.js +0 -235
- 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 -47
- package/dist/modules/hallucination/factual.js +0 -169
- 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 -246
- 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 -389
- 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 -260
- package/dist/modules/lsp/probe.js +0 -86
- package/dist/modules/lsp/project-root.js +0 -32
- package/dist/modules/lsp/startup-check.js +0 -144
- 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 -334
- 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 -261
- package/dist/modules/plugins/types.js +0 -1
- package/dist/modules/pricing/index.js +0 -61
- package/dist/modules/pricing/prices.js +0 -129
- 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/providers/create.js +0 -22
- package/dist/modules/providers/fallback.js +0 -79
- package/dist/modules/providers/health.js +0 -46
- package/dist/modules/providers/index.js +0 -5
- package/dist/modules/providers/manager.js +0 -161
- package/dist/modules/providers/presets.js +0 -128
- package/dist/modules/providers/registry.js +0 -22
- package/dist/modules/providers/types.js +0 -1
- package/dist/modules/registry.js +0 -48
- 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 -219
- 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 -88
- package/dist/modules/security/path-validator.js +0 -203
- 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 -33
- package/dist/tools/attach-image.js +0 -101
- package/dist/tools/bash.js +0 -519
- package/dist/tools/browser.js +0 -115
- package/dist/tools/chunk-query.js +0 -100
- package/dist/tools/create-dir.js +0 -56
- package/dist/tools/delete-file.js +0 -63
- package/dist/tools/download-file.js +0 -117
- package/dist/tools/edit-file.js +0 -80
- package/dist/tools/enable-tools.js +0 -59
- package/dist/tools/executor.js +0 -154
- package/dist/tools/file-info.js +0 -47
- package/dist/tools/filter-tools.js +0 -17
- package/dist/tools/glob-tool.js +0 -27
- package/dist/tools/grep-tool.js +0 -125
- package/dist/tools/hidden-tools-block.js +0 -37
- package/dist/tools/index.js +0 -78
- package/dist/tools/list-dir.js +0 -49
- package/dist/tools/load-skill.js +0 -43
- package/dist/tools/mcp-call.js +0 -69
- package/dist/tools/move-file.js +0 -86
- package/dist/tools/path-utils.js +0 -101
- package/dist/tools/pipeline-run.js +0 -145
- package/dist/tools/preview.js +0 -2
- package/dist/tools/process-kill.js +0 -40
- package/dist/tools/process-list.js +0 -37
- package/dist/tools/process-log.js +0 -54
- package/dist/tools/question.js +0 -141
- package/dist/tools/read-file.js +0 -179
- package/dist/tools/recall.js +0 -118
- package/dist/tools/registry.js +0 -47
- package/dist/tools/remember.js +0 -68
- package/dist/tools/scope-check.js +0 -32
- package/dist/tools/search-history.js +0 -85
- 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 -87
- package/dist/tools/web-fetch.js +0 -119
- package/dist/tools/web-search.js +0 -105
- package/dist/tools/write-file.js +0 -82
- 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 -822
- package/dist/ui/line-math.js +0 -73
- 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 -259
- package/dist/ui/spinner.js +0 -70
- package/dist/ui/table.js +0 -144
package/dist/cli/run-result.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { t } from "../i18n/index";
|
|
2
|
-
import { pc } from "../ui/colors";
|
|
3
|
-
import { formatCost } from "../modules/pricing/prices";
|
|
4
|
-
/**
|
|
5
|
-
* Render a single-run AgentResult to the terminal (non-JSON mode) and return
|
|
6
|
-
* the process exit code.
|
|
7
|
-
*
|
|
8
|
-
* On failure only the error is printed. The model's `text` (which is the last
|
|
9
|
-
* *accepted* message, i.e. possibly stale after an audit/hallucination error)
|
|
10
|
-
* was already streamed live during the run — re-printing it here misleadingly
|
|
11
|
-
* suggests the task succeeded.
|
|
12
|
-
*/
|
|
13
|
-
export function printRunResult(result, flush) {
|
|
14
|
-
flush();
|
|
15
|
-
if (result.success) {
|
|
16
|
-
if (result.totalCost !== undefined && result.totalCost > 0) {
|
|
17
|
-
console.log(pc.dim(`${t("repl.cost", { cost: formatCost(result.totalCost) })}`));
|
|
18
|
-
if (result.costBreakdown && result.costBreakdown.length > 1) {
|
|
19
|
-
const parts = result.costBreakdown.map((e) => `${e.provider} ${formatCost(e.cost)}`);
|
|
20
|
-
console.log(pc.dim(` ${t("repl.cost_breakdown", { breakdown: parts.join(", ") })}`));
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
else if (result.totalTokens !== undefined && result.totalTokens > 0) {
|
|
24
|
-
console.log(pc.dim(`${t("repl.tokens", { tokens: result.totalTokens })}`));
|
|
25
|
-
}
|
|
26
|
-
if (!result.text) {
|
|
27
|
-
console.log(pc.yellow(t("cli.no_output")));
|
|
28
|
-
}
|
|
29
|
-
return 0;
|
|
30
|
-
}
|
|
31
|
-
console.error(`${t("error.prefix")}${result.error}`);
|
|
32
|
-
return 1;
|
|
33
|
-
}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { bootstrap } from "../core/bootstrap";
|
|
2
|
-
import { saveConfig } from "../config/config";
|
|
3
|
-
import { join, dirname } from "path";
|
|
4
|
-
import { homedir } from "os";
|
|
5
|
-
import { SECURITY_POLICIES, applySecurityPolicy, getSecurityPolicy, } from "../modules/security/security-policies";
|
|
6
|
-
import { globalAuditNotifier } from "../modules/security/audit-notifier";
|
|
7
|
-
import { t } from "../i18n/index";
|
|
8
|
-
/**
|
|
9
|
-
* Create security subcommand
|
|
10
|
-
*/
|
|
11
|
-
export function createSecurityCommand(program) {
|
|
12
|
-
const securityCmd = program.command("security").description(t("cli.security.description"));
|
|
13
|
-
// security status - show current security configuration
|
|
14
|
-
securityCmd
|
|
15
|
-
.command("status")
|
|
16
|
-
.description(t("cli.security.status"))
|
|
17
|
-
.action(async () => {
|
|
18
|
-
const { config } = await bootstrap();
|
|
19
|
-
const security = config.security || {};
|
|
20
|
-
const bash = security.bash || {};
|
|
21
|
-
const paths = security.paths || {};
|
|
22
|
-
const network = security.network || {};
|
|
23
|
-
const contentScan = security.contentScan || {};
|
|
24
|
-
const rateLimits = security.rateLimits || {};
|
|
25
|
-
const sessionEncryption = security.sessionEncryption || {};
|
|
26
|
-
const auditNotifier = security.auditNotifier || {};
|
|
27
|
-
console.log(t("cli.security.current_policy"));
|
|
28
|
-
console.log(` ${t("cli.security.bash_enabled")}: ${bash.blacklist?.length > 0 ? t("cli.yes") : t("cli.no")}`);
|
|
29
|
-
console.log(` ${t("cli.security.path_validation")}: ${paths.denied?.length > 0 ? t("cli.yes") : t("cli.no")}`);
|
|
30
|
-
console.log(` ${t("cli.security.network_validation")}: ${network.deniedDomains?.length > 0 || network.allowedDomains?.length > 0 ? t("cli.yes") : t("cli.no")}`);
|
|
31
|
-
console.log(` ${t("cli.security.content_scanning")}: ${contentScan.enabled ? t("cli.yes") : t("cli.no")}`);
|
|
32
|
-
console.log(` ${t("cli.security.max_recursion")}: ${security.maxRecursionDepth ?? 3}`);
|
|
33
|
-
console.log(` ${t("cli.security.max_file_ops")}: ${security.maxFileOperations ?? 100}`);
|
|
34
|
-
console.log(` ${t("cli.security.rate_limit")}: ${rateLimits.maxRequestsPerMinute ?? 60}/min`);
|
|
35
|
-
console.log(` ${t("cli.security.session_encryption")}: ${sessionEncryption.enabled ? t("cli.yes") : t("cli.no")}`);
|
|
36
|
-
console.log(` ${t("cli.security.audit_notifier")}: ${auditNotifier.enabled ? t("cli.yes") : t("cli.no")}`);
|
|
37
|
-
});
|
|
38
|
-
// security policies - manage security policies
|
|
39
|
-
securityCmd
|
|
40
|
-
.command("policies")
|
|
41
|
-
.description(t("cli.security.policies"))
|
|
42
|
-
.action(async () => {
|
|
43
|
-
console.log(t("cli.security.available_policies"));
|
|
44
|
-
console.log("");
|
|
45
|
-
for (const [preset, policy] of Object.entries(SECURITY_POLICIES)) {
|
|
46
|
-
if (preset === "custom")
|
|
47
|
-
continue;
|
|
48
|
-
const marker = " ";
|
|
49
|
-
console.log(` ${marker}${preset.padEnd(12)} ${policy.name}`);
|
|
50
|
-
console.log(` ${policy.description}`);
|
|
51
|
-
console.log(` ${t("cli.security.recommended_for")}: ${policy.recommendedFor.join(", ")}`);
|
|
52
|
-
console.log("");
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
// security set-policy - apply a security policy
|
|
56
|
-
securityCmd
|
|
57
|
-
.command("set-policy")
|
|
58
|
-
.argument("<preset>", t("cli.security.preset"))
|
|
59
|
-
.description(t("cli.security.set_policy"))
|
|
60
|
-
.action(async (preset) => {
|
|
61
|
-
const configPath = join(homedir(), ".mma", "config.json");
|
|
62
|
-
const { config: appConfig } = await bootstrap();
|
|
63
|
-
const validPresets = ["strict", "balanced", "permissive"];
|
|
64
|
-
if (!validPresets.includes(preset)) {
|
|
65
|
-
console.log(t("cli.security.invalid_preset", { presets: validPresets.join(", ") }));
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const policy = getSecurityPolicy(preset);
|
|
69
|
-
const newSecurityConfig = applySecurityPolicy(preset);
|
|
70
|
-
// Merge with existing config
|
|
71
|
-
appConfig.security = newSecurityConfig;
|
|
72
|
-
saveConfig(appConfig, configPath, dirname(configPath));
|
|
73
|
-
console.log(t("cli.security.policy_applied", { name: policy.name }));
|
|
74
|
-
console.log(t("cli.security.policy_description", { description: policy.description }));
|
|
75
|
-
});
|
|
76
|
-
// security enable-encryption - enable session file encryption
|
|
77
|
-
securityCmd
|
|
78
|
-
.command("enable-encryption")
|
|
79
|
-
.description(t("cli.security.enable_encryption"))
|
|
80
|
-
.action(async () => {
|
|
81
|
-
const configPath = join(homedir(), ".mma", "config.json");
|
|
82
|
-
const { config: appConfig } = await bootstrap();
|
|
83
|
-
appConfig.security = appConfig.security || {};
|
|
84
|
-
appConfig.security.sessionEncryption = {
|
|
85
|
-
enabled: true,
|
|
86
|
-
encryptHistory: true,
|
|
87
|
-
encryptSessionLog: true,
|
|
88
|
-
};
|
|
89
|
-
saveConfig(appConfig, configPath, dirname(configPath));
|
|
90
|
-
console.log(t("cli.security.encryption_enabled"));
|
|
91
|
-
});
|
|
92
|
-
// security disable-encryption - disable session file encryption
|
|
93
|
-
securityCmd
|
|
94
|
-
.command("disable-encryption")
|
|
95
|
-
.description(t("cli.security.disable_encryption"))
|
|
96
|
-
.action(async () => {
|
|
97
|
-
const configPath = join(homedir(), ".mma", "config.json");
|
|
98
|
-
const { config: appConfig } = await bootstrap();
|
|
99
|
-
appConfig.security = appConfig.security || {};
|
|
100
|
-
appConfig.security.sessionEncryption = {
|
|
101
|
-
enabled: false,
|
|
102
|
-
encryptHistory: false,
|
|
103
|
-
encryptSessionLog: false,
|
|
104
|
-
};
|
|
105
|
-
saveConfig(appConfig, configPath, dirname(configPath));
|
|
106
|
-
console.log(t("cli.security.encryption_disabled"));
|
|
107
|
-
});
|
|
108
|
-
// security enable-audit - enable audit notifications
|
|
109
|
-
securityCmd
|
|
110
|
-
.command("enable-audit")
|
|
111
|
-
.description(t("cli.security.enable_audit"))
|
|
112
|
-
.action(async () => {
|
|
113
|
-
const configPath = join(homedir(), ".mma", "config.json");
|
|
114
|
-
const { config: appConfig } = await bootstrap();
|
|
115
|
-
appConfig.security = appConfig.security || {};
|
|
116
|
-
appConfig.security.auditNotifier = {
|
|
117
|
-
enabled: true,
|
|
118
|
-
minSeverity: "medium",
|
|
119
|
-
eventTypes: ["security_block", "bash_command", "file_operation", "network_request"],
|
|
120
|
-
maxRetries: 3,
|
|
121
|
-
webhookTimeout: 5000,
|
|
122
|
-
};
|
|
123
|
-
saveConfig(appConfig, configPath, dirname(configPath));
|
|
124
|
-
console.log(t("cli.security.audit_enabled"));
|
|
125
|
-
});
|
|
126
|
-
// security disable-audit - disable audit notifications
|
|
127
|
-
securityCmd
|
|
128
|
-
.command("disable-audit")
|
|
129
|
-
.description(t("cli.security.disable_audit"))
|
|
130
|
-
.action(async () => {
|
|
131
|
-
const configPath = join(homedir(), ".mma", "config.json");
|
|
132
|
-
const { config: appConfig } = await bootstrap();
|
|
133
|
-
appConfig.security = appConfig.security || {};
|
|
134
|
-
appConfig.security.auditNotifier = {
|
|
135
|
-
enabled: false,
|
|
136
|
-
maxRetries: 3,
|
|
137
|
-
webhookTimeout: 5000,
|
|
138
|
-
};
|
|
139
|
-
saveConfig(appConfig, configPath, dirname(configPath));
|
|
140
|
-
console.log(t("cli.security.audit_disabled"));
|
|
141
|
-
});
|
|
142
|
-
// security audit-stats - show audit notification statistics
|
|
143
|
-
securityCmd
|
|
144
|
-
.command("audit-stats")
|
|
145
|
-
.description(t("cli.security.audit_stats"))
|
|
146
|
-
.action(async () => {
|
|
147
|
-
const stats = globalAuditNotifier.getStats();
|
|
148
|
-
console.log(t("cli.security.audit_stats_title"));
|
|
149
|
-
console.log(` ${t("cli.security.total_notifications")}: ${stats.total}`);
|
|
150
|
-
console.log("");
|
|
151
|
-
console.log(t("cli.security.by_severity"));
|
|
152
|
-
console.log(` ${t("cli.security.low")}: ${stats.bySeverity.low}`);
|
|
153
|
-
console.log(` ${t("cli.security.medium")}: ${stats.bySeverity.medium}`);
|
|
154
|
-
console.log(` ${t("cli.security.high")}: ${stats.bySeverity.high}`);
|
|
155
|
-
console.log(` ${t("cli.security.critical")}: ${stats.bySeverity.critical}`);
|
|
156
|
-
console.log("");
|
|
157
|
-
console.log(t("cli.security.by_type"));
|
|
158
|
-
for (const [type, count] of Object.entries(stats.byType)) {
|
|
159
|
-
if (count > 0) {
|
|
160
|
-
console.log(` ${type}: ${count}`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
package/dist/cli/setup.js
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import * as readline from "readline";
|
|
2
|
-
import { pc } from "../ui/colors";
|
|
3
|
-
import { t, setLocale } from "../i18n/index";
|
|
4
|
-
import { Spinner } from "../ui/spinner";
|
|
5
|
-
import { BUILTIN_PROVIDERS, HOSTED_BASE_URLS } from "../modules/providers/presets";
|
|
6
|
-
import { box } from "../ui/box";
|
|
7
|
-
import { renderTable } from "../ui/table";
|
|
8
|
-
async function withSpinner(message, fn) {
|
|
9
|
-
const spinner = new Spinner();
|
|
10
|
-
spinner.start(message);
|
|
11
|
-
try {
|
|
12
|
-
return await fn();
|
|
13
|
-
}
|
|
14
|
-
finally {
|
|
15
|
-
spinner.stop();
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/** Render a numbered list inside a box. */
|
|
19
|
-
function menuList(items) {
|
|
20
|
-
const lines = items.map((it, i) => ` ${pc.cyan(`[${i + 1}]`)} ${it.label}${it.url ? ` ${pc.dim(it.url)}` : ""}`);
|
|
21
|
-
for (const l of box(lines, { width: 72 }))
|
|
22
|
-
console.log(l);
|
|
23
|
-
}
|
|
24
|
-
function ask(rl, question, defaultValue) {
|
|
25
|
-
return new Promise((resolve) => {
|
|
26
|
-
const prompt = defaultValue ? `${question} [${defaultValue}]: ` : `${question}: `;
|
|
27
|
-
rl.question(prompt, (answer) => {
|
|
28
|
-
resolve(answer.trim() || defaultValue || "");
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
const PROVIDER_TYPES = BUILTIN_PROVIDERS.map((spec) => ({
|
|
33
|
-
value: spec.type,
|
|
34
|
-
label: spec.label,
|
|
35
|
-
}));
|
|
36
|
-
const KNOWN_PORTS = [
|
|
37
|
-
{ port: 1234, label: "LM Studio" },
|
|
38
|
-
{ port: 11434, label: "Ollama" },
|
|
39
|
-
{ port: 8080, label: "vLLM / custom" },
|
|
40
|
-
{ port: 4891, label: "GPT4All" },
|
|
41
|
-
];
|
|
42
|
-
async function scanPorts() {
|
|
43
|
-
const found = [];
|
|
44
|
-
for (const { port, label } of KNOWN_PORTS) {
|
|
45
|
-
try {
|
|
46
|
-
const controller = new AbortController();
|
|
47
|
-
const timeout = setTimeout(() => controller.abort(), 2000);
|
|
48
|
-
const resp = await fetch(`http://localhost:${port}/v1/models`, {
|
|
49
|
-
signal: controller.signal,
|
|
50
|
-
});
|
|
51
|
-
clearTimeout(timeout);
|
|
52
|
-
if (resp.ok) {
|
|
53
|
-
found.push({ label, url: `http://localhost:${port}/v1` });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
/* port not available */
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return found;
|
|
61
|
-
}
|
|
62
|
-
async function fetchModels(apiBase, apiKey) {
|
|
63
|
-
try {
|
|
64
|
-
const url = `${apiBase.replace(/\/+$/, "")}/models`;
|
|
65
|
-
const controller = new AbortController();
|
|
66
|
-
const timeout = setTimeout(() => controller.abort(), 5000);
|
|
67
|
-
const resp = await fetch(url, {
|
|
68
|
-
headers: {
|
|
69
|
-
Authorization: `Bearer ${apiKey}`,
|
|
70
|
-
"Content-Type": "application/json",
|
|
71
|
-
},
|
|
72
|
-
signal: controller.signal,
|
|
73
|
-
});
|
|
74
|
-
clearTimeout(timeout);
|
|
75
|
-
if (!resp.ok)
|
|
76
|
-
return [];
|
|
77
|
-
const data = (await resp.json());
|
|
78
|
-
const models = (data.data || data || [])
|
|
79
|
-
.map((m) => m.id || m.name || m.model || "")
|
|
80
|
-
.filter(Boolean);
|
|
81
|
-
return models;
|
|
82
|
-
}
|
|
83
|
-
catch {
|
|
84
|
-
return [];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
async function testChat(apiBase, apiKey, model) {
|
|
88
|
-
try {
|
|
89
|
-
const url = `${apiBase.replace(/\/+$/, "")}/chat/completions`;
|
|
90
|
-
const controller = new AbortController();
|
|
91
|
-
const timeout = setTimeout(() => controller.abort(), 10000);
|
|
92
|
-
const resp = await fetch(url, {
|
|
93
|
-
method: "POST",
|
|
94
|
-
headers: {
|
|
95
|
-
Authorization: `Bearer ${apiKey}`,
|
|
96
|
-
"Content-Type": "application/json",
|
|
97
|
-
},
|
|
98
|
-
body: JSON.stringify({
|
|
99
|
-
model,
|
|
100
|
-
messages: [{ role: "user", content: 'Say "ok"' }],
|
|
101
|
-
max_tokens: 20,
|
|
102
|
-
}),
|
|
103
|
-
signal: controller.signal,
|
|
104
|
-
});
|
|
105
|
-
clearTimeout(timeout);
|
|
106
|
-
if (!resp.ok)
|
|
107
|
-
return false;
|
|
108
|
-
const data = (await resp.json());
|
|
109
|
-
const msg = data.choices?.[0]?.message;
|
|
110
|
-
const text = msg?.content || msg?.reasoning_content || "";
|
|
111
|
-
return text.length > 0;
|
|
112
|
-
}
|
|
113
|
-
catch {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
export async function runSetup(externalRl) {
|
|
118
|
-
console.log(t("setup.title"));
|
|
119
|
-
const rl = externalRl ||
|
|
120
|
-
readline.createInterface({
|
|
121
|
-
input: process.stdin,
|
|
122
|
-
output: process.stdout,
|
|
123
|
-
});
|
|
124
|
-
const ownRl = !externalRl;
|
|
125
|
-
console.log(t("setup.language"));
|
|
126
|
-
const locale = await ask(rl, t("setup.ui_lang"), "en");
|
|
127
|
-
setLocale(locale);
|
|
128
|
-
console.log(t("setup.select_provider"));
|
|
129
|
-
menuList(PROVIDER_TYPES);
|
|
130
|
-
const providerChoice = await ask(rl, t("setup.select_provider_num", { max: PROVIDER_TYPES.length }), "1");
|
|
131
|
-
const providerIdx = Math.max(0, Math.min(PROVIDER_TYPES.length - 1, (parseInt(providerChoice) || 1) - 1));
|
|
132
|
-
const provider = PROVIDER_TYPES[providerIdx].value;
|
|
133
|
-
let apiBase = "";
|
|
134
|
-
if (provider === "openai-compat") {
|
|
135
|
-
const found = await withSpinner(t("setup.scanning_spinner"), async () => scanPorts());
|
|
136
|
-
if (found.length > 0) {
|
|
137
|
-
console.log(t("setup.found_servers", { count: found.length }));
|
|
138
|
-
menuList([
|
|
139
|
-
...found.map((f) => ({ label: f.label, url: f.url })),
|
|
140
|
-
{ label: t("setup.custom_url") },
|
|
141
|
-
]);
|
|
142
|
-
const choice = await ask(rl, t("setup.select_server", { max: found.length + 1 }), "1");
|
|
143
|
-
const idx = (parseInt(choice) || 1) - 1;
|
|
144
|
-
if (idx >= found.length) {
|
|
145
|
-
apiBase = await ask(rl, t("setup.api_base"), "http://localhost:1234/v1");
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
apiBase = found[Math.max(0, Math.min(found.length - 1, idx))].url;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
console.log(t("setup.no_servers"));
|
|
153
|
-
apiBase = await ask(rl, t("setup.api_base"), "http://localhost:1234/v1");
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
apiBase = HOSTED_BASE_URLS[provider] ?? "";
|
|
158
|
-
}
|
|
159
|
-
const defaultKey = provider === "openai-compat" ? "not-needed" : "";
|
|
160
|
-
const apiKey = await ask(rl, t("setup.api_key"), defaultKey);
|
|
161
|
-
const models = await withSpinner(t("setup.fetching_spinner"), () => fetchModels(apiBase, apiKey));
|
|
162
|
-
let model = "";
|
|
163
|
-
if (models.length > 0) {
|
|
164
|
-
console.log(t("setup.available_models"));
|
|
165
|
-
menuList(models.slice(0, 10).map((m) => ({ label: m })));
|
|
166
|
-
const choice = await ask(rl, t("setup.select_model", { max: Math.min(models.length, 10) }), "1");
|
|
167
|
-
const idx = Math.max(0, Math.min(models.length - 1, (parseInt(choice) || 1) - 1));
|
|
168
|
-
model = models[idx];
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
model = await ask(rl, t("setup.model_name"), "qwen/qwen3.5-9b");
|
|
172
|
-
}
|
|
173
|
-
const connected = await withSpinner(t("setup.testing_spinner", { model }), () => testChat(apiBase, apiKey, model));
|
|
174
|
-
if (connected) {
|
|
175
|
-
console.log(pc.green(t("setup.ok")));
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
console.log(pc.yellow(t("setup.warning")));
|
|
179
|
-
}
|
|
180
|
-
console.log(t("setup.agent_settings"));
|
|
181
|
-
const contextWindow = parseInt(await ask(rl, t("setup.context_window"), "32768"));
|
|
182
|
-
const maxIterations = parseInt(await ask(rl, t("setup.max_iters"), "1000"));
|
|
183
|
-
// Security settings
|
|
184
|
-
console.log(t("setup.security_header"));
|
|
185
|
-
console.log(pc.dim(t("setup.security_status_on")));
|
|
186
|
-
const configureSecurity = await ask(rl, t("setup.security_configure"), "n");
|
|
187
|
-
let securityBashBlock = false;
|
|
188
|
-
let securityFlagsBlock = false;
|
|
189
|
-
let securityPathsDeny = true;
|
|
190
|
-
if (configureSecurity.toLowerCase() === "y" || configureSecurity.toLowerCase() === "yes") {
|
|
191
|
-
securityBashBlock = (await ask(rl, t("setup.security_bash_block"), "n")).toLowerCase() === "y";
|
|
192
|
-
securityFlagsBlock =
|
|
193
|
-
(await ask(rl, t("setup.security_flags_block"), "n")).toLowerCase() === "y";
|
|
194
|
-
securityPathsDeny = (await ask(rl, t("setup.security_paths_deny"), "Y")).toLowerCase() !== "n";
|
|
195
|
-
}
|
|
196
|
-
if (ownRl) {
|
|
197
|
-
rl.close();
|
|
198
|
-
// Bun: closed readline can leave stdin in a state where a later
|
|
199
|
-
// raw-mode LineEditor never receives keypress events. Force-reset:
|
|
200
|
-
process.stdin.removeAllListeners("data");
|
|
201
|
-
process.stdin.removeAllListeners("keypress");
|
|
202
|
-
if (typeof process.stdin.setRawMode === "function") {
|
|
203
|
-
process.stdin.setRawMode(false);
|
|
204
|
-
}
|
|
205
|
-
// Pause + resume forces Bun to flush its internal buffer and
|
|
206
|
-
// release the stream so LineEditor can attach cleanly.
|
|
207
|
-
process.stdin.pause();
|
|
208
|
-
process.stdin.resume();
|
|
209
|
-
}
|
|
210
|
-
const answers = {
|
|
211
|
-
provider,
|
|
212
|
-
apiBase,
|
|
213
|
-
apiKey: apiKey || "not-needed",
|
|
214
|
-
model,
|
|
215
|
-
contextWindow,
|
|
216
|
-
maxToolIterations: maxIterations,
|
|
217
|
-
locale,
|
|
218
|
-
securityBashBlock,
|
|
219
|
-
securityFlagsBlock,
|
|
220
|
-
securityPathsDeny,
|
|
221
|
-
};
|
|
222
|
-
console.log(pc.green(pc.bold(t("setup.complete"))));
|
|
223
|
-
const summary = renderTable([
|
|
224
|
-
t("setup.summary_setting"),
|
|
225
|
-
t("setup.summary_value"),
|
|
226
|
-
t("setup.summary_setting"),
|
|
227
|
-
t("setup.summary_value"),
|
|
228
|
-
], [
|
|
229
|
-
[t("setup.provider_type"), provider, t("setup.model_name"), model],
|
|
230
|
-
["API Base URL", apiBase, t("setup.context_window"), String(contextWindow)],
|
|
231
|
-
[t("setup.api_key"), apiKey || "not-needed", t("setup.max_iters"), String(maxIterations)],
|
|
232
|
-
[t("setup.ui_lang"), locale, "", ""],
|
|
233
|
-
], { maxColumns: 4 });
|
|
234
|
-
for (const l of summary)
|
|
235
|
-
console.log(l);
|
|
236
|
-
return answers;
|
|
237
|
-
}
|