@kenhkl/agent-moss 0.11.0 → 0.11.3
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/dist/cli.js +157 -72
- package/dist/cli.js.map +1 -1
- package/dist/engine/coordinator.js +125 -40
- package/dist/engine/coordinator.js.map +1 -1
- package/dist/server.js +145 -60
- package/dist/server.js.map +1 -1
- package/dist/static/index.html +21 -5
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -43,6 +43,90 @@ var init_esm_shims = __esm({
|
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
+
// src/infra/paths.ts
|
|
47
|
+
import { join } from "path";
|
|
48
|
+
import { homedir } from "os";
|
|
49
|
+
import { readFileSync } from "fs";
|
|
50
|
+
function isRoot() {
|
|
51
|
+
const getuid = process.getuid;
|
|
52
|
+
return typeof getuid === "function" && getuid() === 0;
|
|
53
|
+
}
|
|
54
|
+
function resolveOwnerHome() {
|
|
55
|
+
for (const name of [process.env.SUDO_USER, process.env.LOGNAME, process.env.USER]) {
|
|
56
|
+
if (name && name !== "root" && name !== "") {
|
|
57
|
+
const home = homeOf(name);
|
|
58
|
+
if (home) return home;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const passwd = readFileSync("/etc/passwd", "utf-8");
|
|
63
|
+
for (const line of passwd.split("\n")) {
|
|
64
|
+
if (!line || line.startsWith("#")) continue;
|
|
65
|
+
const parts = line.split(":");
|
|
66
|
+
if (parts.length < 6) continue;
|
|
67
|
+
const uid = parseInt(parts[2], 10);
|
|
68
|
+
const name = parts[0];
|
|
69
|
+
if (uid >= 1e3 && name && !name.startsWith("_")) {
|
|
70
|
+
return parts[5];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
function homeOf(name) {
|
|
78
|
+
try {
|
|
79
|
+
const passwd = readFileSync("/etc/passwd", "utf-8");
|
|
80
|
+
for (const line of passwd.split("\n")) {
|
|
81
|
+
if (!line || line.startsWith("#")) continue;
|
|
82
|
+
const parts = line.split(":");
|
|
83
|
+
if (parts.length >= 6 && parts[0] === name) {
|
|
84
|
+
return parts[5];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
function getDataRoot() {
|
|
92
|
+
const envPath = process.env[ENV_DATA_ROOT];
|
|
93
|
+
if (envPath) return envPath;
|
|
94
|
+
if (isRoot()) {
|
|
95
|
+
const ownerHome = resolveOwnerHome();
|
|
96
|
+
if (ownerHome) {
|
|
97
|
+
return join(ownerHome, ".config", "agentmoss");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return DEFAULT_DATA_ROOT;
|
|
101
|
+
}
|
|
102
|
+
function getInstance() {
|
|
103
|
+
const v = process.env[ENV_INSTANCE] || "";
|
|
104
|
+
return v.trim().replace(/^[/\\]+|[/\\]+$/g, "");
|
|
105
|
+
}
|
|
106
|
+
function getConfigDir() {
|
|
107
|
+
return getDataRoot();
|
|
108
|
+
}
|
|
109
|
+
function getRuntimeConfigDir() {
|
|
110
|
+
return getDataRoot();
|
|
111
|
+
}
|
|
112
|
+
function getTokenStatsPath() {
|
|
113
|
+
const instance = getInstance();
|
|
114
|
+
if (instance) {
|
|
115
|
+
return join(getDataRoot(), instance, "agent_moss_token_stats.json");
|
|
116
|
+
}
|
|
117
|
+
return join(getDataRoot(), "agent_moss_token_stats.json");
|
|
118
|
+
}
|
|
119
|
+
var ENV_DATA_ROOT, ENV_INSTANCE, DEFAULT_DATA_ROOT;
|
|
120
|
+
var init_paths = __esm({
|
|
121
|
+
"src/infra/paths.ts"() {
|
|
122
|
+
"use strict";
|
|
123
|
+
init_esm_shims();
|
|
124
|
+
ENV_DATA_ROOT = "AGENT_MOSS_DATA_DIR";
|
|
125
|
+
ENV_INSTANCE = "AGENT_MOSS_INSTANCE";
|
|
126
|
+
DEFAULT_DATA_ROOT = join(homedir(), ".config", "agentmoss");
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
46
130
|
// src/config.ts
|
|
47
131
|
var config_exports = {};
|
|
48
132
|
__export(config_exports, {
|
|
@@ -61,7 +145,6 @@ __export(config_exports, {
|
|
|
61
145
|
});
|
|
62
146
|
import fs from "fs";
|
|
63
147
|
import path2 from "path";
|
|
64
|
-
import os from "os";
|
|
65
148
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
66
149
|
function loadConfigFile(filePath) {
|
|
67
150
|
try {
|
|
@@ -74,7 +157,7 @@ function loadConfigFile(filePath) {
|
|
|
74
157
|
function resolveConfigPath() {
|
|
75
158
|
const envPath = process.env.AGENT_MOSS_CONFIG_PATH;
|
|
76
159
|
if (envPath) return envPath;
|
|
77
|
-
const userConfig = path2.join(
|
|
160
|
+
const userConfig = path2.join(getConfigDir(), "config.json");
|
|
78
161
|
if (fs.existsSync(userConfig)) return userConfig;
|
|
79
162
|
const defaultConfig = path2.join(__dirname, "..", "..", "agent_moss", "infra", "config.json.example");
|
|
80
163
|
if (fs.existsSync(defaultConfig)) {
|
|
@@ -243,6 +326,7 @@ var init_config = __esm({
|
|
|
243
326
|
"src/config.ts"() {
|
|
244
327
|
"use strict";
|
|
245
328
|
init_esm_shims();
|
|
329
|
+
init_paths();
|
|
246
330
|
llmConfig = (() => {
|
|
247
331
|
const configPath = resolveConfigPath();
|
|
248
332
|
const fileConfig = fs.existsSync(configPath) ? loadLLMConfigFromFile(configPath) : {};
|
|
@@ -1073,7 +1157,7 @@ var init_logic_rules = __esm({
|
|
|
1073
1157
|
});
|
|
1074
1158
|
|
|
1075
1159
|
// src/engine/skill-loader.ts
|
|
1076
|
-
import { readFileSync, readdirSync as readdirSync2, existsSync as existsSync2 } from "fs";
|
|
1160
|
+
import { readFileSync as readFileSync2, readdirSync as readdirSync2, existsSync as existsSync2 } from "fs";
|
|
1077
1161
|
import { resolve, dirname } from "path";
|
|
1078
1162
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1079
1163
|
function loadAllSkills() {
|
|
@@ -1087,7 +1171,7 @@ function loadAllSkills() {
|
|
|
1087
1171
|
const files = readdirSync2(dir).filter((f) => f.endsWith(".md"));
|
|
1088
1172
|
for (const f of files) {
|
|
1089
1173
|
const name = f.replace(".md", "");
|
|
1090
|
-
cachedSkills[name] =
|
|
1174
|
+
cachedSkills[name] = readFileSync2(resolve(dir, f), "utf-8");
|
|
1091
1175
|
}
|
|
1092
1176
|
console.log(`[AgentMoss] Loaded ${Object.keys(cachedSkills).length} skills from ${dir}`);
|
|
1093
1177
|
return cachedSkills;
|
|
@@ -1218,11 +1302,13 @@ __export(runtime_config_exports, {
|
|
|
1218
1302
|
updateSkillCategoryEnabled: () => updateSkillCategoryEnabled,
|
|
1219
1303
|
updateSkillEnabled: () => updateSkillEnabled
|
|
1220
1304
|
});
|
|
1221
|
-
import { readFileSync as
|
|
1222
|
-
import { join } from "path";
|
|
1223
|
-
import { homedir } from "os";
|
|
1305
|
+
import { readFileSync as readFileSync3, writeFileSync, existsSync as existsSync3, mkdirSync, unlinkSync, readdirSync as readdirSync3 } from "fs";
|
|
1306
|
+
import { join as join2 } from "path";
|
|
1224
1307
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
1225
1308
|
import { dirname as dirname2 } from "path";
|
|
1309
|
+
function runtimeDir() {
|
|
1310
|
+
return getRuntimeConfigDir();
|
|
1311
|
+
}
|
|
1226
1312
|
function getRuntimeConfigPath() {
|
|
1227
1313
|
const envPath = process.env[ENV_RUNTIME_CONFIG_PATH];
|
|
1228
1314
|
if (envPath) return envPath;
|
|
@@ -1255,7 +1341,7 @@ function loadRuntimeConfig() {
|
|
|
1255
1341
|
return seeded;
|
|
1256
1342
|
}
|
|
1257
1343
|
try {
|
|
1258
|
-
const data = JSON.parse(
|
|
1344
|
+
const data = JSON.parse(readFileSync3(p, "utf-8"));
|
|
1259
1345
|
const merged = mergeConfig(data, generateSourceDefaults());
|
|
1260
1346
|
return {
|
|
1261
1347
|
version: data.version || 1,
|
|
@@ -1325,7 +1411,7 @@ function hasRuntimeConfig() {
|
|
|
1325
1411
|
const p = getRuntimeConfigPath();
|
|
1326
1412
|
if (!existsSync3(p)) return false;
|
|
1327
1413
|
try {
|
|
1328
|
-
JSON.parse(
|
|
1414
|
+
JSON.parse(readFileSync3(p, "utf-8"));
|
|
1329
1415
|
return true;
|
|
1330
1416
|
} catch {
|
|
1331
1417
|
return false;
|
|
@@ -1513,11 +1599,11 @@ function _agentRulesToDefaults() {
|
|
|
1513
1599
|
return out;
|
|
1514
1600
|
}
|
|
1515
1601
|
for (const agentId of entries) {
|
|
1516
|
-
const rulesFile =
|
|
1602
|
+
const rulesFile = join2(agentsDir, agentId, "rules.json");
|
|
1517
1603
|
if (!existsSync3(rulesFile)) continue;
|
|
1518
1604
|
let data;
|
|
1519
1605
|
try {
|
|
1520
|
-
data = JSON.parse(
|
|
1606
|
+
data = JSON.parse(readFileSync3(rulesFile, "utf-8"));
|
|
1521
1607
|
} catch {
|
|
1522
1608
|
continue;
|
|
1523
1609
|
}
|
|
@@ -1933,12 +2019,12 @@ function deleteCustomRule(layer, category, ruleId) {
|
|
|
1933
2019
|
function addCustomSkill(skillId, category, keywords, content) {
|
|
1934
2020
|
_validateSkillId(skillId);
|
|
1935
2021
|
const runtime = loadRuntimeConfig();
|
|
1936
|
-
const skillsDir =
|
|
2022
|
+
const skillsDir = join2(RUNTIME_CONFIG_DIR, "agent_moss_skills");
|
|
1937
2023
|
try {
|
|
1938
2024
|
mkdirSync(skillsDir, { recursive: true });
|
|
1939
2025
|
} catch {
|
|
1940
2026
|
}
|
|
1941
|
-
writeFileSync(
|
|
2027
|
+
writeFileSync(join2(skillsDir, `${skillId}.md`), content, "utf-8");
|
|
1942
2028
|
const l3 = runtime.L3_skills || (runtime.L3_skills = {});
|
|
1943
2029
|
const cat = l3[category] || (l3[category] = { category_enabled: true, category_desc: "", skills: [] });
|
|
1944
2030
|
(cat.skills || (cat.skills = [])).push({ id: skillId, keywords, enabled: true, builtin: false });
|
|
@@ -1953,7 +2039,7 @@ function deleteCustomSkill(skillId, category) {
|
|
|
1953
2039
|
if (idx >= 0) {
|
|
1954
2040
|
if (skills[idx].builtin) return null;
|
|
1955
2041
|
skills.splice(idx, 1);
|
|
1956
|
-
const skillPath =
|
|
2042
|
+
const skillPath = join2(RUNTIME_CONFIG_DIR, "agent_moss_skills", `${skillId}.md`);
|
|
1957
2043
|
try {
|
|
1958
2044
|
if (existsSync3(skillPath)) unlinkSync(skillPath);
|
|
1959
2045
|
} catch {
|
|
@@ -2069,18 +2155,19 @@ function updateAgentCategoryEnabled(agentId, category, enabled) {
|
|
|
2069
2155
|
saveRuntimeConfig(runtime);
|
|
2070
2156
|
return runtime;
|
|
2071
2157
|
}
|
|
2072
|
-
var __dirname3, RUNTIME_CONFIG_DIR, RUNTIME_CONFIG_PATH,
|
|
2158
|
+
var __dirname3, ENV_RUNTIME_CONFIG_PATH, RUNTIME_CONFIG_DIR, RUNTIME_CONFIG_PATH, LAYER_DISABLE_ENV, DENY_MODE_LABELS, _AGENTS_DIR_PROD, _AGENTS_DIR_DEV, SKILL_ID_RE;
|
|
2073
2159
|
var init_runtime_config = __esm({
|
|
2074
2160
|
"src/infra/runtime-config.ts"() {
|
|
2075
2161
|
"use strict";
|
|
2076
2162
|
init_esm_shims();
|
|
2163
|
+
init_paths();
|
|
2077
2164
|
init_heuristic();
|
|
2078
2165
|
init_logic_rules();
|
|
2079
2166
|
init_skill_loader();
|
|
2080
2167
|
__dirname3 = dirname2(fileURLToPath4(import.meta.url));
|
|
2081
|
-
RUNTIME_CONFIG_DIR = join(homedir(), ".config", "agentmoss");
|
|
2082
|
-
RUNTIME_CONFIG_PATH = join(RUNTIME_CONFIG_DIR, "agent_moss_runtime.json");
|
|
2083
2168
|
ENV_RUNTIME_CONFIG_PATH = "AGENT_MOSS_RUNTIME_CONFIG_PATH";
|
|
2169
|
+
RUNTIME_CONFIG_DIR = runtimeDir();
|
|
2170
|
+
RUNTIME_CONFIG_PATH = join2(RUNTIME_CONFIG_DIR, "agent_moss_runtime.json");
|
|
2084
2171
|
LAYER_DISABLE_ENV = {
|
|
2085
2172
|
L1_heuristic: "AGENT_MOSS_DISABLE_HEURISTIC",
|
|
2086
2173
|
L2_logic_rules: "AGENT_MOSS_DISABLE_LOGIC_RULES",
|
|
@@ -2091,14 +2178,14 @@ var init_runtime_config = __esm({
|
|
|
2091
2178
|
deny_read: "\u4EC5\u62E6\u622A\u8BFB\u53D6",
|
|
2092
2179
|
deny_both: "\u8BFB\u5199\u5747\u62E6\u622A"
|
|
2093
2180
|
};
|
|
2094
|
-
_AGENTS_DIR_PROD =
|
|
2095
|
-
_AGENTS_DIR_DEV =
|
|
2181
|
+
_AGENTS_DIR_PROD = join2(__dirname3, "agents");
|
|
2182
|
+
_AGENTS_DIR_DEV = join2(__dirname3, "..", "..", "..", "agent_moss", "agents");
|
|
2096
2183
|
SKILL_ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
2097
2184
|
}
|
|
2098
2185
|
});
|
|
2099
2186
|
|
|
2100
2187
|
// src/agents/index.ts
|
|
2101
|
-
import { readFileSync as
|
|
2188
|
+
import { readFileSync as readFileSync4, existsSync as existsSync4 } from "fs";
|
|
2102
2189
|
import { resolve as resolve2, dirname as dirname3 } from "path";
|
|
2103
2190
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
2104
2191
|
function resolveAgentsDir() {
|
|
@@ -2125,7 +2212,7 @@ function getAgentExtensions(agentId) {
|
|
|
2125
2212
|
return null;
|
|
2126
2213
|
}
|
|
2127
2214
|
try {
|
|
2128
|
-
const raw =
|
|
2215
|
+
const raw = readFileSync4(rulesFile, "utf-8");
|
|
2129
2216
|
ext = JSON.parse(raw);
|
|
2130
2217
|
if (!ext.agent_id) {
|
|
2131
2218
|
console.warn(`[AgentMoss agents] rules.json \u7F3A\u5C11 agent_id \u5B57\u6BB5: ${rulesFile}`);
|
|
@@ -2765,7 +2852,7 @@ var init_heuristic = __esm({
|
|
|
2765
2852
|
});
|
|
2766
2853
|
|
|
2767
2854
|
// src/engine/template-loader.ts
|
|
2768
|
-
import { readFileSync as
|
|
2855
|
+
import { readFileSync as readFileSync5, existsSync as existsSync5 } from "fs";
|
|
2769
2856
|
import { resolve as resolve3, dirname as dirname4 } from "path";
|
|
2770
2857
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
2771
2858
|
function loadTemplates() {
|
|
@@ -2780,7 +2867,7 @@ function loadTemplates() {
|
|
|
2780
2867
|
const filePath = resolve3(dir, file);
|
|
2781
2868
|
if (existsSync5(filePath)) {
|
|
2782
2869
|
const key = file.replace(".txt", "").replace("_template", "");
|
|
2783
|
-
cachedTemplates[key] =
|
|
2870
|
+
cachedTemplates[key] = readFileSync5(filePath, "utf-8");
|
|
2784
2871
|
}
|
|
2785
2872
|
}
|
|
2786
2873
|
console.log(`[AgentMoss] Loaded ${Object.keys(cachedTemplates).length} templates from ${dir}`);
|
|
@@ -2801,8 +2888,8 @@ var init_template_loader = __esm({
|
|
|
2801
2888
|
});
|
|
2802
2889
|
|
|
2803
2890
|
// src/engine/script-analyzer.ts
|
|
2804
|
-
import { readFileSync as
|
|
2805
|
-
import { resolve as resolve4, join as
|
|
2891
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
2892
|
+
import { resolve as resolve4, join as join3 } from "path";
|
|
2806
2893
|
function emptyResult() {
|
|
2807
2894
|
return { scriptPath: "", scriptContent: "", matchedKeywords: [], lineCount: 0, isSuspicious: false, error: "", riskLevel: "", riskReason: "" };
|
|
2808
2895
|
}
|
|
@@ -2855,8 +2942,8 @@ function assessKeywordCombinationRisk(matchedKeywords, scriptContent) {
|
|
|
2855
2942
|
}
|
|
2856
2943
|
function readScriptContent(scriptPath, maxLines = 500) {
|
|
2857
2944
|
try {
|
|
2858
|
-
const expandedPath = scriptPath.startsWith("~") ?
|
|
2859
|
-
const raw =
|
|
2945
|
+
const expandedPath = scriptPath.startsWith("~") ? join3(process.env.HOME || "/home/user", scriptPath.slice(2)) : resolve4(scriptPath);
|
|
2946
|
+
const raw = readFileSync6(expandedPath, "utf-8");
|
|
2860
2947
|
const lines = raw.split("\n").slice(0, maxLines);
|
|
2861
2948
|
return { content: lines.join("\n"), lineCount: lines.length, error: "" };
|
|
2862
2949
|
} catch (e) {
|
|
@@ -2994,8 +3081,8 @@ var init_script_analyzer = __esm({
|
|
|
2994
3081
|
});
|
|
2995
3082
|
|
|
2996
3083
|
// src/engine/script-content-analyzer.ts
|
|
2997
|
-
import { readFileSync as
|
|
2998
|
-
import { resolve as resolve5, join as
|
|
3084
|
+
import { readFileSync as readFileSync7, statSync, existsSync as existsSync6 } from "fs";
|
|
3085
|
+
import { resolve as resolve5, join as join4, isAbsolute, dirname as dirname5 } from "path";
|
|
2999
3086
|
import { homedir as homedir2 } from "os";
|
|
3000
3087
|
function emptyChain() {
|
|
3001
3088
|
return {
|
|
@@ -3154,7 +3241,7 @@ function extractInlineScriptPath(actionDetail) {
|
|
|
3154
3241
|
function resolvePath(p) {
|
|
3155
3242
|
let expanded = p;
|
|
3156
3243
|
if (expanded.startsWith("~/") || expanded === "~") {
|
|
3157
|
-
expanded =
|
|
3244
|
+
expanded = join4(homedir2(), expanded.slice(1));
|
|
3158
3245
|
}
|
|
3159
3246
|
return resolve5(expanded);
|
|
3160
3247
|
}
|
|
@@ -3167,7 +3254,7 @@ function readScriptContent2(scriptPath, maxFileSize = 2 * 1024 * 1024) {
|
|
|
3167
3254
|
if (stat.size > maxFileSize) {
|
|
3168
3255
|
return { content: "", lineCount: 0, fileSize: stat.size, error: `\u811A\u672C\u6587\u4EF6\u8FC7\u5927 (${stat.size} bytes)\uFF0C\u8DF3\u8FC7\u8BFB\u53D6` };
|
|
3169
3256
|
}
|
|
3170
|
-
const content =
|
|
3257
|
+
const content = readFileSync7(path3, "utf-8");
|
|
3171
3258
|
const lineCount = content ? content.split("\n").length : 0;
|
|
3172
3259
|
return { content, lineCount, fileSize: stat.size, error: "" };
|
|
3173
3260
|
} catch (e) {
|
|
@@ -3184,7 +3271,7 @@ function extractChildScriptPaths(content, baseDir) {
|
|
|
3184
3271
|
const pathStr = m[1];
|
|
3185
3272
|
if (pathStr.startsWith("-") || pathStr.startsWith("$")) continue;
|
|
3186
3273
|
if (pathStr.includes("/dev/") || pathStr.startsWith("|") || pathStr.startsWith(";")) continue;
|
|
3187
|
-
const full = isAbsolute(pathStr) ? pathStr :
|
|
3274
|
+
const full = isAbsolute(pathStr) ? pathStr : join4(baseDir, pathStr);
|
|
3188
3275
|
const resolved = resolvePath(full);
|
|
3189
3276
|
if (existsSync6(resolved)) {
|
|
3190
3277
|
try {
|
|
@@ -3537,17 +3624,16 @@ __export(token_stats_exports, {
|
|
|
3537
3624
|
recordTokenUsage: () => recordTokenUsage,
|
|
3538
3625
|
resetTokenStats: () => resetTokenStats
|
|
3539
3626
|
});
|
|
3540
|
-
import { readFileSync as
|
|
3541
|
-
import { join as join4 } from "path";
|
|
3542
|
-
import { homedir as homedir3 } from "os";
|
|
3627
|
+
import { readFileSync as readFileSync8, writeFileSync as writeFileSync2, existsSync as existsSync7, mkdirSync as mkdirSync2, unlinkSync as unlinkSync2 } from "fs";
|
|
3543
3628
|
function getStatsPath() {
|
|
3544
3629
|
const envPath = process.env[ENV_STATS_PATH];
|
|
3545
|
-
|
|
3630
|
+
if (envPath) return envPath;
|
|
3631
|
+
return getTokenStatsPath();
|
|
3546
3632
|
}
|
|
3547
3633
|
function loadAllRecords(statsPath) {
|
|
3548
3634
|
if (!existsSync7(statsPath)) return [];
|
|
3549
3635
|
try {
|
|
3550
|
-
const data = JSON.parse(
|
|
3636
|
+
const data = JSON.parse(readFileSync8(statsPath, "utf-8"));
|
|
3551
3637
|
if (Array.isArray(data)) return data;
|
|
3552
3638
|
if (data && Array.isArray(data.records)) return data.records;
|
|
3553
3639
|
return [];
|
|
@@ -3687,13 +3773,12 @@ function resetTokenStats() {
|
|
|
3687
3773
|
}
|
|
3688
3774
|
}
|
|
3689
3775
|
}
|
|
3690
|
-
var
|
|
3776
|
+
var ENV_STATS_PATH, MAX_RECORDS;
|
|
3691
3777
|
var init_token_stats = __esm({
|
|
3692
3778
|
"src/engine/token-stats.ts"() {
|
|
3693
3779
|
"use strict";
|
|
3694
3780
|
init_esm_shims();
|
|
3695
|
-
|
|
3696
|
-
STATS_FILE = join4(STATS_DIR, "agent_moss_token_stats.json");
|
|
3781
|
+
init_paths();
|
|
3697
3782
|
ENV_STATS_PATH = "AGENT_MOSS_TOKEN_STATS_PATH";
|
|
3698
3783
|
MAX_RECORDS = 1e4;
|
|
3699
3784
|
}
|
|
@@ -5285,7 +5370,7 @@ init_esm_shims();
|
|
|
5285
5370
|
init_runtime_config();
|
|
5286
5371
|
init_token_stats();
|
|
5287
5372
|
import { Hono } from "hono";
|
|
5288
|
-
import { readFileSync as
|
|
5373
|
+
import { readFileSync as readFileSync9, existsSync as existsSync9 } from "fs";
|
|
5289
5374
|
import { join as join5, dirname as dirname6 } from "path";
|
|
5290
5375
|
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
5291
5376
|
var __dirname6 = dirname6(fileURLToPath7(import.meta.url));
|
|
@@ -5315,7 +5400,7 @@ function createConsoleRouter() {
|
|
|
5315
5400
|
const serveIndex = (c) => {
|
|
5316
5401
|
const indexFile = join5(STATIC_DIR, "index.html");
|
|
5317
5402
|
if (existsSync9(indexFile)) {
|
|
5318
|
-
return c.html(
|
|
5403
|
+
return c.html(readFileSync9(indexFile, "utf-8"));
|
|
5319
5404
|
}
|
|
5320
5405
|
return c.html("<h1>AgentMoss Policy Console</h1><p>Frontend not built. Use /console/api/* endpoints.</p>");
|
|
5321
5406
|
};
|
|
@@ -5323,12 +5408,12 @@ function createConsoleRouter() {
|
|
|
5323
5408
|
console2.get("", serveIndex);
|
|
5324
5409
|
console2.get("/api/layers", (c) => {
|
|
5325
5410
|
const rc = loadRuntimeConfig();
|
|
5326
|
-
return c.json({ layers: rc.layers });
|
|
5411
|
+
return c.json({ layers: rc.layers, env_overrides: getEnvOverrides() });
|
|
5327
5412
|
});
|
|
5328
5413
|
console2.put("/api/layers", async (c) => {
|
|
5329
5414
|
const body = await c.req.json();
|
|
5330
5415
|
const rc = updateLayerEnabled(body.layer_key, body.enabled);
|
|
5331
|
-
return c.json({ layers: rc.layers });
|
|
5416
|
+
return c.json({ layers: rc.layers, env_overrides: getEnvOverrides() });
|
|
5332
5417
|
});
|
|
5333
5418
|
console2.get("/api/rules", (c) => {
|
|
5334
5419
|
const rc = loadRuntimeConfig();
|
|
@@ -5337,22 +5422,22 @@ function createConsoleRouter() {
|
|
|
5337
5422
|
console2.put("/api/rules/enabled", async (c) => {
|
|
5338
5423
|
const b = await c.req.json();
|
|
5339
5424
|
const rc = updateRuleEnabled(b.layer, b.category, b.rule_id, b.enabled);
|
|
5340
|
-
return c.json(
|
|
5425
|
+
return c.json(rc);
|
|
5341
5426
|
});
|
|
5342
5427
|
console2.put("/api/rules/deny_mode", async (c) => {
|
|
5343
5428
|
const b = await c.req.json();
|
|
5344
5429
|
const rc = updateRuleDenyMode(b.layer, b.category, b.rule_id, b.deny_mode);
|
|
5345
|
-
return c.json(
|
|
5430
|
+
return c.json(rc);
|
|
5346
5431
|
});
|
|
5347
5432
|
console2.put("/api/rules/skip_l3", async (c) => {
|
|
5348
5433
|
const b = await c.req.json();
|
|
5349
5434
|
const rc = updateRuleSkipL3(b.layer, b.category, b.rule_id, b.skip_l3_on_disabled);
|
|
5350
|
-
return c.json(
|
|
5435
|
+
return c.json(rc);
|
|
5351
5436
|
});
|
|
5352
5437
|
console2.put("/api/categories/enabled", async (c) => {
|
|
5353
5438
|
const b = await c.req.json();
|
|
5354
5439
|
const rc = updateCategoryEnabled(b.layer, b.category, b.enabled);
|
|
5355
|
-
return c.json(
|
|
5440
|
+
return c.json(rc);
|
|
5356
5441
|
});
|
|
5357
5442
|
console2.post("/api/rules", async (c) => {
|
|
5358
5443
|
const b = await c.req.json();
|
|
@@ -5368,38 +5453,38 @@ function createConsoleRouter() {
|
|
|
5368
5453
|
credential: b.credential,
|
|
5369
5454
|
deny_mode: b.deny_mode
|
|
5370
5455
|
});
|
|
5371
|
-
return c.json(
|
|
5456
|
+
return c.json(rc);
|
|
5372
5457
|
});
|
|
5373
5458
|
console2.delete("/api/rules", async (c) => {
|
|
5374
5459
|
const b = await c.req.json();
|
|
5375
5460
|
deleteCustomRule(b.layer, b.category, b.rule_id);
|
|
5376
5461
|
const rc = loadRuntimeConfig();
|
|
5377
|
-
return c.json(
|
|
5462
|
+
return c.json(rc);
|
|
5378
5463
|
});
|
|
5379
5464
|
console2.get("/api/skills", (c) => {
|
|
5380
5465
|
const rc = loadRuntimeConfig();
|
|
5381
|
-
return c.json(
|
|
5466
|
+
return c.json(rc.L3_skills);
|
|
5382
5467
|
});
|
|
5383
5468
|
console2.put("/api/skills/enabled", async (c) => {
|
|
5384
5469
|
const b = await c.req.json();
|
|
5385
5470
|
const rc = updateSkillEnabled(b.skill_id, b.enabled);
|
|
5386
|
-
return c.json(
|
|
5471
|
+
return c.json(rc);
|
|
5387
5472
|
});
|
|
5388
5473
|
console2.put("/api/skill-categories/enabled", async (c) => {
|
|
5389
5474
|
const b = await c.req.json();
|
|
5390
5475
|
const rc = updateSkillCategoryEnabled(b.category, b.enabled);
|
|
5391
|
-
return c.json(
|
|
5476
|
+
return c.json(rc);
|
|
5392
5477
|
});
|
|
5393
5478
|
console2.post("/api/skills", async (c) => {
|
|
5394
5479
|
const b = await c.req.json();
|
|
5395
5480
|
const rc = addCustomSkill(b.skill_id, b.category || "user_custom", b.keywords || [], b.content);
|
|
5396
|
-
return c.json(
|
|
5481
|
+
return c.json(rc);
|
|
5397
5482
|
});
|
|
5398
5483
|
console2.delete("/api/skills", async (c) => {
|
|
5399
5484
|
const b = await c.req.json();
|
|
5400
5485
|
deleteCustomSkill(b.skill_id, b.category);
|
|
5401
5486
|
const rc = loadRuntimeConfig();
|
|
5402
|
-
return c.json(
|
|
5487
|
+
return c.json(rc);
|
|
5403
5488
|
});
|
|
5404
5489
|
console2.get("/api/skills/:skill_id/content", async (c) => {
|
|
5405
5490
|
const skillId = c.req.param("skill_id");
|
|
@@ -5409,10 +5494,10 @@ function createConsoleRouter() {
|
|
|
5409
5494
|
const skillPath = join5(dirname6(getRuntimeConfigPath()), "agent_moss_skills", `${skillId}.md`);
|
|
5410
5495
|
if (!existsSync9(skillPath)) {
|
|
5411
5496
|
const builtinPath = join5(__dirname6, "..", "..", "agent_moss", "skills", `${skillId}.md`);
|
|
5412
|
-
if (existsSync9(builtinPath)) return c.text(
|
|
5497
|
+
if (existsSync9(builtinPath)) return c.text(readFileSync9(builtinPath, "utf-8"));
|
|
5413
5498
|
return c.json({ error: "skill not found" }, 404);
|
|
5414
5499
|
}
|
|
5415
|
-
return c.text(
|
|
5500
|
+
return c.text(readFileSync9(skillPath, "utf-8"));
|
|
5416
5501
|
});
|
|
5417
5502
|
console2.get("/api/agents", (c) => {
|
|
5418
5503
|
const rc = loadRuntimeConfig();
|
|
@@ -5454,7 +5539,7 @@ function createConsoleRouter() {
|
|
|
5454
5539
|
});
|
|
5455
5540
|
console2.get("/api/config", (c) => {
|
|
5456
5541
|
const rc = loadRuntimeConfig();
|
|
5457
|
-
return c.json(
|
|
5542
|
+
return c.json(rc);
|
|
5458
5543
|
});
|
|
5459
5544
|
console2.get("/api/env-overrides", (c) => {
|
|
5460
5545
|
return c.json({ overrides: getEnvOverrides() });
|
|
@@ -5462,7 +5547,7 @@ function createConsoleRouter() {
|
|
|
5462
5547
|
console2.post("/api/reset", (c) => {
|
|
5463
5548
|
const defaults = generateSourceDefaults();
|
|
5464
5549
|
saveRuntimeConfig(defaults);
|
|
5465
|
-
return c.json(
|
|
5550
|
+
return c.json(defaults);
|
|
5466
5551
|
});
|
|
5467
5552
|
console2.get("/api/token-stats", (c) => {
|
|
5468
5553
|
const days = parseInt(c.req.query("days") || "7", 10);
|
|
@@ -5470,7 +5555,7 @@ function createConsoleRouter() {
|
|
|
5470
5555
|
});
|
|
5471
5556
|
console2.get("/api/token-stats/recent", (c) => {
|
|
5472
5557
|
const limit = parseInt(c.req.query("limit") || "20", 10);
|
|
5473
|
-
return c.json(
|
|
5558
|
+
return c.json(getRecentRecords(limit));
|
|
5474
5559
|
});
|
|
5475
5560
|
console2.get("/api/token-stats/trend", (c) => {
|
|
5476
5561
|
const days = parseInt(c.req.query("days") || "7", 10);
|
|
@@ -5646,18 +5731,18 @@ async function main() {
|
|
|
5646
5731
|
const binPath = which || `${process.execPath} ${path3.join(__dirname7, "cli.js")}`;
|
|
5647
5732
|
let content = fs4.readFileSync(srcPath, "utf-8");
|
|
5648
5733
|
content = content.replace("__AGENT_MOSS_BIN__", binPath);
|
|
5649
|
-
const dst = "/etc/systemd/system/
|
|
5734
|
+
const dst = "/etc/systemd/system/agent-moss.service";
|
|
5650
5735
|
fs4.writeFileSync(dst, content, "utf-8");
|
|
5651
5736
|
fs4.chmodSync(dst, 420);
|
|
5652
5737
|
console.log(`\u2705 \u5DF2\u5B89\u88C5 systemd service: ${dst}`);
|
|
5653
5738
|
execSync("systemctl daemon-reload", { stdio: "inherit" });
|
|
5654
5739
|
console.log("\u2705 systemctl daemon-reload \u5B8C\u6210");
|
|
5655
5740
|
if (enable) {
|
|
5656
|
-
execSync("systemctl enable
|
|
5657
|
-
console.log("\u2705 systemctl enable
|
|
5741
|
+
execSync("systemctl enable agent-moss", { stdio: "inherit" });
|
|
5742
|
+
console.log("\u2705 systemctl enable agent-moss \u5B8C\u6210");
|
|
5658
5743
|
}
|
|
5659
|
-
console.log("\n\u542F\u52A8\u670D\u52A1\uFF1A sudo systemctl start
|
|
5660
|
-
console.log("\u67E5\u770B\u72B6\u6001\uFF1A sudo systemctl status
|
|
5744
|
+
console.log("\n\u542F\u52A8\u670D\u52A1\uFF1A sudo systemctl start agent-moss");
|
|
5745
|
+
console.log("\u67E5\u770B\u72B6\u6001\uFF1A sudo systemctl status agent-moss");
|
|
5661
5746
|
console.log("\u67E5\u770B\u65E5\u5FD7\uFF1A journalctl -u agent_moss -f");
|
|
5662
5747
|
break;
|
|
5663
5748
|
}
|
|
@@ -5666,9 +5751,9 @@ async function main() {
|
|
|
5666
5751
|
const { execSync } = await import("child_process");
|
|
5667
5752
|
let systemdInfo = "";
|
|
5668
5753
|
try {
|
|
5669
|
-
const out = execSync("systemctl is-active
|
|
5754
|
+
const out = execSync("systemctl is-active agent-moss 2>/dev/null || true", { encoding: "utf-8" }).trim();
|
|
5670
5755
|
if (out === "active") {
|
|
5671
|
-
const show = execSync("systemctl show
|
|
5756
|
+
const show = execSync("systemctl show agent-moss --property=MainPID,ActiveEnterTimestamp,ExecStart 2>/dev/null || true", { encoding: "utf-8" });
|
|
5672
5757
|
for (const line of show.trim().split("\n")) {
|
|
5673
5758
|
const [key, ...vals] = line.split("=");
|
|
5674
5759
|
const val = vals.join("=");
|
|
@@ -5746,10 +5831,10 @@ async function main() {
|
|
|
5746
5831
|
}
|
|
5747
5832
|
console.log();
|
|
5748
5833
|
console.log(" \u542F\u505C\u547D\u4EE4\uFF1A");
|
|
5749
|
-
console.log(" systemctl start
|
|
5750
|
-
console.log(" systemctl stop
|
|
5751
|
-
console.log(" systemctl restart
|
|
5752
|
-
console.log(" systemctl status
|
|
5834
|
+
console.log(" systemctl start agent-moss \u542F\u52A8");
|
|
5835
|
+
console.log(" systemctl stop agent-moss \u505C\u6B62");
|
|
5836
|
+
console.log(" systemctl restart agent-moss \u91CD\u542F");
|
|
5837
|
+
console.log(" systemctl status agent-moss \u72B6\u6001");
|
|
5753
5838
|
console.log(" journalctl -u agent_moss -f \u65E5\u5FD7");
|
|
5754
5839
|
} else {
|
|
5755
5840
|
console.log(`\u274C AgentMoss \u670D\u52A1\u672A\u8FD0\u884C`);
|
|
@@ -5758,7 +5843,7 @@ async function main() {
|
|
|
5758
5843
|
console.log(` \u68C0\u67E5\u65E5\u5FD7\uFF1Ajournalctl -u agent_moss -n 20 --no-pager`);
|
|
5759
5844
|
} else {
|
|
5760
5845
|
console.log(` \u542F\u52A8\u65B9\u5F0F\uFF1A`);
|
|
5761
|
-
console.log(` systemctl start
|
|
5846
|
+
console.log(` systemctl start agent-moss \uFF08systemd\uFF09`);
|
|
5762
5847
|
console.log(` agent-moss server \uFF08\u524D\u53F0\uFF09`);
|
|
5763
5848
|
}
|
|
5764
5849
|
process.exit(1);
|