@kenhkl/agent-moss 0.17.42 → 0.17.43
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 +265 -191
- package/dist/engine/coordinator.js +147 -92
- package/dist/server.js +228 -154
- package/package.json +1 -1
|
@@ -2616,8 +2616,8 @@ function loadRuntimeConfig() {
|
|
|
2616
2616
|
}
|
|
2617
2617
|
try {
|
|
2618
2618
|
const st = statSync3(p);
|
|
2619
|
-
const
|
|
2620
|
-
if (runtimeConfigCache && runtimeConfigCache.key ===
|
|
2619
|
+
const cacheKey2 = `${p}|${st.mtimeMs}|${st.size}`;
|
|
2620
|
+
if (runtimeConfigCache && runtimeConfigCache.key === cacheKey2) {
|
|
2621
2621
|
return runtimeConfigCache.value;
|
|
2622
2622
|
}
|
|
2623
2623
|
const data = JSON.parse(readFileSync4(p, "utf-8"));
|
|
@@ -2642,7 +2642,7 @@ function loadRuntimeConfig() {
|
|
|
2642
2642
|
agent_rules: merged.agent_rules || {},
|
|
2643
2643
|
scenario_rules: merged.scenario_rules || {}
|
|
2644
2644
|
};
|
|
2645
|
-
runtimeConfigCache = { key:
|
|
2645
|
+
runtimeConfigCache = { key: cacheKey2, value: result };
|
|
2646
2646
|
return result;
|
|
2647
2647
|
} catch {
|
|
2648
2648
|
return emptyRuntimeConfig();
|
|
@@ -4282,15 +4282,66 @@ var init_config = __esm({
|
|
|
4282
4282
|
}
|
|
4283
4283
|
});
|
|
4284
4284
|
|
|
4285
|
-
// src/
|
|
4286
|
-
import { readFileSync as readFileSync5,
|
|
4287
|
-
import {
|
|
4285
|
+
// src/infra/edition-scope.ts
|
|
4286
|
+
import { existsSync as existsSync6, readFileSync as readFileSync5, statSync as statSync4 } from "fs";
|
|
4287
|
+
import { dirname as dirname5, join as join6, resolve as resolve4 } from "path";
|
|
4288
4288
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
4289
|
+
function scopePath(moduleDir) {
|
|
4290
|
+
const root = getRulesRoot();
|
|
4291
|
+
if (root) return join6(root, "edition_scope.json");
|
|
4292
|
+
const prod = resolve4(moduleDir, "..", "edition_scope.json");
|
|
4293
|
+
if (existsSync6(prod)) return prod;
|
|
4294
|
+
const dev = resolve4(moduleDir, "../../..", "agent_moss", "edition_scope.json");
|
|
4295
|
+
if (existsSync6(dev)) return dev;
|
|
4296
|
+
return prod;
|
|
4297
|
+
}
|
|
4298
|
+
function loadScope(moduleDir) {
|
|
4299
|
+
const file = scopePath(moduleDir);
|
|
4300
|
+
try {
|
|
4301
|
+
const st = statSync4(file);
|
|
4302
|
+
const key = `${file}:${st.mtimeMs}:${st.size}`;
|
|
4303
|
+
if (key === cacheKey) return cacheData;
|
|
4304
|
+
const parsed = JSON.parse(readFileSync5(file, "utf-8"));
|
|
4305
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
4306
|
+
throw new Error("\u6839\u8282\u70B9\u4E0D\u662F\u5BF9\u8C61");
|
|
4307
|
+
}
|
|
4308
|
+
cacheKey = key;
|
|
4309
|
+
cacheData = parsed;
|
|
4310
|
+
return cacheData;
|
|
4311
|
+
} catch {
|
|
4312
|
+
cacheKey = "";
|
|
4313
|
+
cacheData = null;
|
|
4314
|
+
return null;
|
|
4315
|
+
}
|
|
4316
|
+
}
|
|
4317
|
+
function isAllowed(kind, id, moduleDir = MODULE_DIR) {
|
|
4318
|
+
const scope = loadScope(moduleDir);
|
|
4319
|
+
if (!scope) return true;
|
|
4320
|
+
const allowed = scope[kind];
|
|
4321
|
+
if (!Array.isArray(allowed)) return true;
|
|
4322
|
+
return allowed.includes(id);
|
|
4323
|
+
}
|
|
4324
|
+
var MODULE_DIR, cacheKey, cacheData;
|
|
4325
|
+
var init_edition_scope = __esm({
|
|
4326
|
+
"src/infra/edition-scope.ts"() {
|
|
4327
|
+
"use strict";
|
|
4328
|
+
init_esm_shims();
|
|
4329
|
+
init_paths();
|
|
4330
|
+
MODULE_DIR = dirname5(fileURLToPath6(import.meta.url));
|
|
4331
|
+
cacheKey = "";
|
|
4332
|
+
cacheData = null;
|
|
4333
|
+
}
|
|
4334
|
+
});
|
|
4335
|
+
|
|
4336
|
+
// src/agents/index.ts
|
|
4337
|
+
import { readFileSync as readFileSync6, existsSync as existsSync7 } from "fs";
|
|
4338
|
+
import { resolve as resolve5, dirname as dirname6, join as join7 } from "path";
|
|
4339
|
+
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
4289
4340
|
function resolveAgentsDir() {
|
|
4290
4341
|
const root = getRulesRoot();
|
|
4291
|
-
if (root) return
|
|
4292
|
-
if (
|
|
4293
|
-
if (
|
|
4342
|
+
if (root) return join7(root, "agents");
|
|
4343
|
+
if (existsSync7(AGENTS_DIR_PROD)) return AGENTS_DIR_PROD;
|
|
4344
|
+
if (existsSync7(AGENTS_DIR_DEV_FALLBACK)) return AGENTS_DIR_DEV_FALLBACK;
|
|
4294
4345
|
return AGENTS_DIR_PROD;
|
|
4295
4346
|
}
|
|
4296
4347
|
function getAgentExtensions(agentId) {
|
|
@@ -4299,6 +4350,7 @@ function getAgentExtensions(agentId) {
|
|
|
4299
4350
|
console.warn(`[AgentMoss agents] \u975E\u6CD5 agent_id \u5DF2\u5FFD\u7565\uFF08\u542B\u8DEF\u5F84\u5B57\u7B26\u6216\u8D85\u957F\uFF09: ${agentId.slice(0, 120)}`);
|
|
4300
4351
|
return null;
|
|
4301
4352
|
}
|
|
4353
|
+
if (!isAllowed("agents", agentId)) return null;
|
|
4302
4354
|
if (cache.size >= CACHE_MAX) cache.clear();
|
|
4303
4355
|
const fp = getRuleSourceFingerprint();
|
|
4304
4356
|
const cached2 = cache.get(agentId);
|
|
@@ -4312,13 +4364,13 @@ function getAgentExtensions(agentId) {
|
|
|
4312
4364
|
}
|
|
4313
4365
|
if (ext === null) {
|
|
4314
4366
|
const agentsDir = resolveAgentsDir();
|
|
4315
|
-
const rulesFile =
|
|
4316
|
-
if (!
|
|
4367
|
+
const rulesFile = resolve5(agentsDir, agentId, "rules.json");
|
|
4368
|
+
if (!existsSync7(rulesFile)) {
|
|
4317
4369
|
cache.set(agentId, { fp, ext: null });
|
|
4318
4370
|
return null;
|
|
4319
4371
|
}
|
|
4320
4372
|
try {
|
|
4321
|
-
const raw =
|
|
4373
|
+
const raw = readFileSync6(rulesFile, "utf-8");
|
|
4322
4374
|
ext = JSON.parse(raw);
|
|
4323
4375
|
if (!ext.agent_id) {
|
|
4324
4376
|
console.warn(`[AgentMoss agents] rules.json \u7F3A\u5C11 agent_id \u5B57\u6BB5: ${rulesFile}`);
|
|
@@ -4359,25 +4411,26 @@ var init_agents = __esm({
|
|
|
4359
4411
|
"use strict";
|
|
4360
4412
|
init_esm_shims();
|
|
4361
4413
|
init_paths();
|
|
4414
|
+
init_edition_scope();
|
|
4362
4415
|
init_runtime_config();
|
|
4363
|
-
__filename4 =
|
|
4364
|
-
__dirname5 =
|
|
4365
|
-
AGENTS_DIR_PROD =
|
|
4366
|
-
AGENTS_DIR_DEV_FALLBACK =
|
|
4416
|
+
__filename4 = fileURLToPath7(import.meta.url);
|
|
4417
|
+
__dirname5 = dirname6(__filename4);
|
|
4418
|
+
AGENTS_DIR_PROD = resolve5(__dirname5, "agents");
|
|
4419
|
+
AGENTS_DIR_DEV_FALLBACK = resolve5(__dirname5, "../../../agent_moss/agents");
|
|
4367
4420
|
cache = /* @__PURE__ */ new Map();
|
|
4368
4421
|
CACHE_MAX = 512;
|
|
4369
4422
|
}
|
|
4370
4423
|
});
|
|
4371
4424
|
|
|
4372
4425
|
// src/scenarios/index.ts
|
|
4373
|
-
import { readFileSync as
|
|
4374
|
-
import { resolve as
|
|
4375
|
-
import { fileURLToPath as
|
|
4426
|
+
import { readFileSync as readFileSync7, existsSync as existsSync8 } from "fs";
|
|
4427
|
+
import { resolve as resolve6, dirname as dirname7, join as join8 } from "path";
|
|
4428
|
+
import { fileURLToPath as fileURLToPath8 } from "url";
|
|
4376
4429
|
function resolveScenariosDir() {
|
|
4377
4430
|
const root = getRulesRoot();
|
|
4378
|
-
if (root) return
|
|
4379
|
-
if (
|
|
4380
|
-
if (
|
|
4431
|
+
if (root) return join8(root, "scenarios");
|
|
4432
|
+
if (existsSync8(SCENARIOS_DIR_PROD)) return SCENARIOS_DIR_PROD;
|
|
4433
|
+
if (existsSync8(SCENARIOS_DIR_DEV_FALLBACK)) return SCENARIOS_DIR_DEV_FALLBACK;
|
|
4381
4434
|
return SCENARIOS_DIR_PROD;
|
|
4382
4435
|
}
|
|
4383
4436
|
function getScenarioExtensions(scenarioId) {
|
|
@@ -4386,6 +4439,7 @@ function getScenarioExtensions(scenarioId) {
|
|
|
4386
4439
|
console.warn(`[AgentMoss scenarios] \u975E\u6CD5 scenario_id \u5DF2\u5FFD\u7565\uFF08\u542B\u8DEF\u5F84\u5B57\u7B26\u6216\u8D85\u957F\uFF09: ${scenarioId.slice(0, 120)}`);
|
|
4387
4440
|
return null;
|
|
4388
4441
|
}
|
|
4442
|
+
if (!isAllowed("scenarios", scenarioId)) return null;
|
|
4389
4443
|
if (cache2.size >= CACHE_MAX2) cache2.clear();
|
|
4390
4444
|
const fp = getRuleSourceFingerprint();
|
|
4391
4445
|
const cached2 = cache2.get(scenarioId);
|
|
@@ -4405,19 +4459,19 @@ function getScenarioExtensions(scenarioId) {
|
|
|
4405
4459
|
}
|
|
4406
4460
|
}
|
|
4407
4461
|
if (ext === null) {
|
|
4408
|
-
const builtinFile =
|
|
4462
|
+
const builtinFile = resolve6(resolveScenariosDir(), scenarioId, "rules.json");
|
|
4409
4463
|
const rulesFile = overrideHit ?? builtinFile;
|
|
4410
4464
|
if (overrideHit) {
|
|
4411
4465
|
console.warn(
|
|
4412
4466
|
`[AgentMoss] \u26A0\uFE0F \u573A\u666F ${scenarioId} \u89C4\u5219\u88AB\u8986\u76D6\u76EE\u5F55\u8986\u76D6: ${overrideHit}\uFF08\u5185\u7F6E\u9ED8\u8BA4 ${builtinFile} \u88AB\u5FFD\u7565\uFF09\u3002\u8BE5\u6587\u4EF6\u7531\u90E8\u7F72\u4FA7\u81EA\u884C\u7EF4\u62A4\uFF0C\u5185\u7F6E\u573A\u666F\u89C4\u5219\u66F4\u65B0\u4E0D\u4F1A\u53CD\u6620\u5230\u5B83\u4E0A\u9762\u3002`
|
|
4413
4467
|
);
|
|
4414
4468
|
}
|
|
4415
|
-
if (!
|
|
4469
|
+
if (!existsSync8(rulesFile)) {
|
|
4416
4470
|
cache2.set(scenarioId, { fp, ext: null });
|
|
4417
4471
|
return null;
|
|
4418
4472
|
}
|
|
4419
4473
|
try {
|
|
4420
|
-
const raw =
|
|
4474
|
+
const raw = readFileSync7(rulesFile, "utf-8");
|
|
4421
4475
|
const data = JSON.parse(raw);
|
|
4422
4476
|
const id = data.scenario_id || data.agent_id || "";
|
|
4423
4477
|
if (!id) {
|
|
@@ -4463,13 +4517,14 @@ var init_scenarios = __esm({
|
|
|
4463
4517
|
"use strict";
|
|
4464
4518
|
init_esm_shims();
|
|
4465
4519
|
init_paths();
|
|
4520
|
+
init_edition_scope();
|
|
4466
4521
|
init_agents();
|
|
4467
4522
|
init_runtime_config();
|
|
4468
4523
|
init_rules_loader();
|
|
4469
|
-
__filename5 =
|
|
4470
|
-
__dirname6 =
|
|
4471
|
-
SCENARIOS_DIR_PROD =
|
|
4472
|
-
SCENARIOS_DIR_DEV_FALLBACK =
|
|
4524
|
+
__filename5 = fileURLToPath8(import.meta.url);
|
|
4525
|
+
__dirname6 = dirname7(__filename5);
|
|
4526
|
+
SCENARIOS_DIR_PROD = resolve6(__dirname6, "scenarios");
|
|
4527
|
+
SCENARIOS_DIR_DEV_FALLBACK = resolve6(__dirname6, "../../../agent_moss/scenarios");
|
|
4473
4528
|
cache2 = /* @__PURE__ */ new Map();
|
|
4474
4529
|
CACHE_MAX2 = 512;
|
|
4475
4530
|
}
|
|
@@ -5930,17 +5985,17 @@ __export(token_stats_exports, {
|
|
|
5930
5985
|
resetTokenStats: () => resetTokenStats,
|
|
5931
5986
|
resetTokenStatsCacheForTests: () => resetTokenStatsCacheForTests
|
|
5932
5987
|
});
|
|
5933
|
-
import { readFileSync as
|
|
5988
|
+
import { readFileSync as readFileSync13, writeFileSync as writeFileSync2, existsSync as existsSync13, mkdirSync as mkdirSync3, renameSync, unlinkSync as unlinkSync2, statSync as statSync7 } from "fs";
|
|
5934
5989
|
function getStatsPath() {
|
|
5935
5990
|
const envPath = process.env[ENV_STATS_PATH];
|
|
5936
5991
|
if (envPath) return envPath;
|
|
5937
5992
|
return getTokenStatsPath();
|
|
5938
5993
|
}
|
|
5939
5994
|
function loadAllRecords(statsPath) {
|
|
5940
|
-
if (!
|
|
5995
|
+
if (!existsSync13(statsPath)) return [];
|
|
5941
5996
|
let sig = "";
|
|
5942
5997
|
try {
|
|
5943
|
-
const st =
|
|
5998
|
+
const st = statSync7(statsPath);
|
|
5944
5999
|
sig = `${st.mtimeMs}:${st.size}`;
|
|
5945
6000
|
} catch {
|
|
5946
6001
|
return [];
|
|
@@ -5949,7 +6004,7 @@ function loadAllRecords(statsPath) {
|
|
|
5949
6004
|
return _recordsCache.records.slice();
|
|
5950
6005
|
}
|
|
5951
6006
|
try {
|
|
5952
|
-
const data = JSON.parse(
|
|
6007
|
+
const data = JSON.parse(readFileSync13(statsPath, "utf-8"));
|
|
5953
6008
|
let records;
|
|
5954
6009
|
if (Array.isArray(data)) records = data;
|
|
5955
6010
|
else if (data && Array.isArray(data.records)) records = data.records;
|
|
@@ -5963,7 +6018,7 @@ function loadAllRecords(statsPath) {
|
|
|
5963
6018
|
function saveRecords(statsPath, records) {
|
|
5964
6019
|
try {
|
|
5965
6020
|
const dir = statsPath.substring(0, statsPath.lastIndexOf("/"));
|
|
5966
|
-
if (dir && !
|
|
6021
|
+
if (dir && !existsSync13(dir)) mkdirSync3(dir, { recursive: true });
|
|
5967
6022
|
const tmp = `${statsPath}.${process.pid}.${Date.now()}.tmp`;
|
|
5968
6023
|
try {
|
|
5969
6024
|
writeFileSync2(tmp, JSON.stringify(records, null, 2), "utf-8");
|
|
@@ -5975,7 +6030,7 @@ function saveRecords(statsPath, records) {
|
|
|
5975
6030
|
}
|
|
5976
6031
|
}
|
|
5977
6032
|
try {
|
|
5978
|
-
const st =
|
|
6033
|
+
const st = statSync7(statsPath);
|
|
5979
6034
|
_recordsCache = {
|
|
5980
6035
|
path: statsPath,
|
|
5981
6036
|
sig: `${st.mtimeMs}:${st.size}`,
|
|
@@ -6112,7 +6167,7 @@ function getTokenTrend(days = 0, startDate, endDate) {
|
|
|
6112
6167
|
}
|
|
6113
6168
|
function resetTokenStats() {
|
|
6114
6169
|
const statsPath = getStatsPath();
|
|
6115
|
-
if (
|
|
6170
|
+
if (existsSync13(statsPath)) {
|
|
6116
6171
|
try {
|
|
6117
6172
|
unlinkSync2(statsPath);
|
|
6118
6173
|
} catch {
|
|
@@ -6147,9 +6202,9 @@ import { createHash } from "crypto";
|
|
|
6147
6202
|
// src/infra/security-policy.ts
|
|
6148
6203
|
init_esm_shims();
|
|
6149
6204
|
init_paths();
|
|
6150
|
-
import { chmodSync, closeSync as closeSync2, constants as fsConstants, existsSync as
|
|
6205
|
+
import { chmodSync, closeSync as closeSync2, constants as fsConstants, existsSync as existsSync9, lstatSync, mkdirSync as mkdirSync2, openSync as openSync2, readFileSync as readFileSync8, readSync as readSync2, realpathSync, writeSync } from "fs";
|
|
6151
6206
|
import { homedir as homedir3, tmpdir } from "os";
|
|
6152
|
-
import { basename as basename2, isAbsolute as isAbsolute2, join as
|
|
6207
|
+
import { basename as basename2, isAbsolute as isAbsolute2, join as join9, relative, resolve as resolve7, dirname as dirname8 } from "path";
|
|
6153
6208
|
var TRUTHY2 = ["1", "true", "yes", "on"];
|
|
6154
6209
|
function env(name, dflt = "") {
|
|
6155
6210
|
return (process.env[name] ?? dflt).trim();
|
|
@@ -6177,7 +6232,7 @@ function logRoots() {
|
|
|
6177
6232
|
return [.../* @__PURE__ */ new Set([homeDir(), "/tmp", tmpdir()])];
|
|
6178
6233
|
}
|
|
6179
6234
|
function realpathLoose(p) {
|
|
6180
|
-
const abs =
|
|
6235
|
+
const abs = resolve7(p.replace(/^~(?=$|\/)/, homeDir()));
|
|
6181
6236
|
try {
|
|
6182
6237
|
return realpathSync(abs);
|
|
6183
6238
|
} catch {
|
|
@@ -6185,12 +6240,12 @@ function realpathLoose(p) {
|
|
|
6185
6240
|
const parts = [];
|
|
6186
6241
|
let cur = abs;
|
|
6187
6242
|
for (; ; ) {
|
|
6188
|
-
const parent =
|
|
6243
|
+
const parent = dirname8(cur);
|
|
6189
6244
|
if (parent === cur) return null;
|
|
6190
6245
|
parts.unshift(basename2(cur));
|
|
6191
6246
|
cur = parent;
|
|
6192
6247
|
try {
|
|
6193
|
-
return
|
|
6248
|
+
return join9(realpathSync(cur), ...parts);
|
|
6194
6249
|
} catch {
|
|
6195
6250
|
}
|
|
6196
6251
|
}
|
|
@@ -6252,11 +6307,11 @@ init_skill_loader();
|
|
|
6252
6307
|
// src/engine/template-loader.ts
|
|
6253
6308
|
init_esm_shims();
|
|
6254
6309
|
init_asset_dir();
|
|
6255
|
-
import { readFileSync as
|
|
6256
|
-
import { resolve as
|
|
6257
|
-
import { fileURLToPath as
|
|
6258
|
-
var __filename6 =
|
|
6259
|
-
var __dirname7 =
|
|
6310
|
+
import { readFileSync as readFileSync9, existsSync as existsSync10 } from "fs";
|
|
6311
|
+
import { resolve as resolve8, dirname as dirname9 } from "path";
|
|
6312
|
+
import { fileURLToPath as fileURLToPath9 } from "url";
|
|
6313
|
+
var __filename6 = fileURLToPath9(import.meta.url);
|
|
6314
|
+
var __dirname7 = dirname9(__filename6);
|
|
6260
6315
|
var TEMPLATE_FILES = ["prompt1_template.txt", "prompt2_template.txt", "security_judge_template.txt"];
|
|
6261
6316
|
var cachedTemplates = null;
|
|
6262
6317
|
function loadTemplates() {
|
|
@@ -6269,10 +6324,10 @@ function loadTemplates() {
|
|
|
6269
6324
|
return cachedTemplates;
|
|
6270
6325
|
}
|
|
6271
6326
|
for (const file of TEMPLATE_FILES) {
|
|
6272
|
-
const filePath =
|
|
6273
|
-
if (
|
|
6327
|
+
const filePath = resolve8(dir, file);
|
|
6328
|
+
if (existsSync10(filePath)) {
|
|
6274
6329
|
const key = file.replace(".txt", "").replace("_template", "");
|
|
6275
|
-
cachedTemplates[key] =
|
|
6330
|
+
cachedTemplates[key] = readFileSync9(filePath, "utf-8");
|
|
6276
6331
|
}
|
|
6277
6332
|
}
|
|
6278
6333
|
console.log(`[AgentMoss] Loaded ${Object.keys(cachedTemplates).length} templates from ${dir}`);
|
|
@@ -6282,8 +6337,8 @@ function loadTemplates() {
|
|
|
6282
6337
|
// src/engine/script-analyzer.ts
|
|
6283
6338
|
init_esm_shims();
|
|
6284
6339
|
init_rules_loader();
|
|
6285
|
-
import { readFileSync as
|
|
6286
|
-
import { resolve as
|
|
6340
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
6341
|
+
import { resolve as resolve9, join as join10 } from "path";
|
|
6287
6342
|
var SCRIPT_RULES = loadScriptRules();
|
|
6288
6343
|
if (!SCRIPT_RULES || Object.keys(SCRIPT_RULES).length === 0) {
|
|
6289
6344
|
console.error(
|
|
@@ -6353,8 +6408,8 @@ function assessKeywordCombinationRisk(matchedKeywords, scriptContent) {
|
|
|
6353
6408
|
}
|
|
6354
6409
|
function readScriptContent(scriptPath, maxLines = 500) {
|
|
6355
6410
|
try {
|
|
6356
|
-
const expandedPath = scriptPath === "~" || scriptPath.startsWith("~/") ?
|
|
6357
|
-
const raw =
|
|
6411
|
+
const expandedPath = scriptPath === "~" || scriptPath.startsWith("~/") ? join10(process.env.HOME || "/home/user", scriptPath.slice(1)) : resolve9(scriptPath);
|
|
6412
|
+
const raw = readFileSync10(expandedPath, "utf-8");
|
|
6358
6413
|
const lines = raw.split("\n").slice(0, maxLines);
|
|
6359
6414
|
return { content: lines.join("\n"), lineCount: lines.length, error: "" };
|
|
6360
6415
|
} catch (e) {
|
|
@@ -6410,8 +6465,8 @@ init_heuristic();
|
|
|
6410
6465
|
init_config();
|
|
6411
6466
|
init_logic_rules();
|
|
6412
6467
|
init_inline_analyzer();
|
|
6413
|
-
import { statSync as
|
|
6414
|
-
import { resolve as
|
|
6468
|
+
import { statSync as statSync6, existsSync as existsSync12 } from "fs";
|
|
6469
|
+
import { resolve as resolve11, join as join12, isAbsolute as isAbsolute4 } from "path";
|
|
6415
6470
|
import { homedir as homedir5 } from "os";
|
|
6416
6471
|
|
|
6417
6472
|
// src/engine/script-engine/tracker.ts
|
|
@@ -7617,7 +7672,7 @@ function evalIfCondition(cond, args) {
|
|
|
7617
7672
|
const op = m[2];
|
|
7618
7673
|
let left = m[1].trim();
|
|
7619
7674
|
let right = m[3].trim();
|
|
7620
|
-
const
|
|
7675
|
+
const resolve12 = (tok) => {
|
|
7621
7676
|
const rm = tok.match(/^\$(\d+)$/);
|
|
7622
7677
|
if (rm) {
|
|
7623
7678
|
const idx = parseInt(rm[1], 10);
|
|
@@ -7625,8 +7680,8 @@ function evalIfCondition(cond, args) {
|
|
|
7625
7680
|
}
|
|
7626
7681
|
return tok.startsWith("$") ? null : tok;
|
|
7627
7682
|
};
|
|
7628
|
-
const lv =
|
|
7629
|
-
const rv =
|
|
7683
|
+
const lv = resolve12(left);
|
|
7684
|
+
const rv = resolve12(right);
|
|
7630
7685
|
if (lv === null || rv === null) return null;
|
|
7631
7686
|
if (op === "=~") {
|
|
7632
7687
|
let re = rv;
|
|
@@ -8065,8 +8120,8 @@ function extractInlineScriptPath(actionDetail) {
|
|
|
8065
8120
|
if (looksLikeScriptPath(tok)) {
|
|
8066
8121
|
try {
|
|
8067
8122
|
const resolved = resolvePath2(tok.replace(/^['"]|['"]$/g, ""));
|
|
8068
|
-
if (
|
|
8069
|
-
const stat =
|
|
8123
|
+
if (existsSync12(resolved)) {
|
|
8124
|
+
const stat = statSync6(resolved);
|
|
8070
8125
|
if (stat.isFile()) return resolved;
|
|
8071
8126
|
}
|
|
8072
8127
|
} catch {
|
|
@@ -8079,8 +8134,8 @@ function extractInlineScriptPath(actionDetail) {
|
|
|
8079
8134
|
const p = m[1];
|
|
8080
8135
|
try {
|
|
8081
8136
|
const resolved = resolvePath2(p);
|
|
8082
|
-
if (
|
|
8083
|
-
const stat =
|
|
8137
|
+
if (existsSync12(resolved)) {
|
|
8138
|
+
const stat = statSync6(resolved);
|
|
8084
8139
|
if (stat.isFile()) return resolved;
|
|
8085
8140
|
}
|
|
8086
8141
|
} catch {
|
|
@@ -8095,8 +8150,8 @@ function extractInlineScriptPath(actionDetail) {
|
|
|
8095
8150
|
let resolved;
|
|
8096
8151
|
try {
|
|
8097
8152
|
resolved = resolvePath2(p);
|
|
8098
|
-
if (
|
|
8099
|
-
const stat =
|
|
8153
|
+
if (existsSync12(resolved)) {
|
|
8154
|
+
const stat = statSync6(resolved);
|
|
8100
8155
|
if (stat.isFile()) return resolved;
|
|
8101
8156
|
}
|
|
8102
8157
|
} catch {
|
|
@@ -8136,9 +8191,9 @@ function shlexSplit(s) {
|
|
|
8136
8191
|
function resolvePath2(p) {
|
|
8137
8192
|
let expanded = p;
|
|
8138
8193
|
if (expanded.startsWith("~/") || expanded === "~") {
|
|
8139
|
-
expanded =
|
|
8194
|
+
expanded = join12(homedir5(), expanded.slice(1));
|
|
8140
8195
|
}
|
|
8141
|
-
return
|
|
8196
|
+
return resolve11(expanded);
|
|
8142
8197
|
}
|
|
8143
8198
|
function scanExtensionPatterns(ext, content) {
|
|
8144
8199
|
const pats = ext?.extra_command_patterns;
|
|
@@ -8225,7 +8280,7 @@ function analyzeScriptContent2(input, ext, stopOnCritical = true) {
|
|
|
8225
8280
|
isInline = true;
|
|
8226
8281
|
}
|
|
8227
8282
|
if (resolvedPath && !isAbsolute4(resolvedPath) && !resolvedPath.startsWith("~/")) {
|
|
8228
|
-
resolvedPath =
|
|
8283
|
+
resolvedPath = join12(input.cwd || process.cwd(), resolvedPath);
|
|
8229
8284
|
}
|
|
8230
8285
|
const l1Adapter = (content) => {
|
|
8231
8286
|
const extHit = scanExtensionPatterns(ext, content);
|
|
@@ -8821,8 +8876,8 @@ async function runLLMAnalysis(input, previous) {
|
|
|
8821
8876
|
}
|
|
8822
8877
|
const config = perRequest?.apiKey ? { ...globalConfig, ...perRequest } : globalConfig;
|
|
8823
8878
|
const rawDetail = input.aNext.actionDetail.replace(/^terminal-\w+:\s*command=([^,]+).*/, "$1").trim();
|
|
8824
|
-
const
|
|
8825
|
-
const cached2 = llmCache.get(
|
|
8879
|
+
const cacheKey2 = `${input.aNext.actionType}:${createHash("sha256").update(rawDetail || input.aNext.actionDetail).digest("hex")}`;
|
|
8880
|
+
const cached2 = llmCache.get(cacheKey2);
|
|
8826
8881
|
if (cached2) {
|
|
8827
8882
|
console.log("[AgentMoss] LLM cache hit");
|
|
8828
8883
|
return cached2;
|
|
@@ -8911,7 +8966,7 @@ async function runLLMAnalysis(input, previous) {
|
|
|
8911
8966
|
const firstKey = llmCache.keys().next().value;
|
|
8912
8967
|
if (firstKey) llmCache.delete(firstKey);
|
|
8913
8968
|
}
|
|
8914
|
-
llmCache.set(
|
|
8969
|
+
llmCache.set(cacheKey2, result);
|
|
8915
8970
|
return result;
|
|
8916
8971
|
}
|
|
8917
8972
|
function logPrompt(prompt, aNext, logPath) {
|
|
@@ -9259,7 +9314,7 @@ async function analyzeWithLLM(prompt, config) {
|
|
|
9259
9314
|
)}`;
|
|
9260
9315
|
if (attempt < maxRetries) {
|
|
9261
9316
|
console.error(`[AgentMoss] LLM call failed (attempt ${attempt + 1}/${maxRetries + 1}), retrying in ${retryCfg.retryInterval}s: ${detail}`);
|
|
9262
|
-
await new Promise((
|
|
9317
|
+
await new Promise((resolve12) => setTimeout(resolve12, retryCfg.retryInterval * 1e3));
|
|
9263
9318
|
} else {
|
|
9264
9319
|
clearTimeout(totalTimeoutTimer);
|
|
9265
9320
|
console.error(`[AgentMoss] LLM call failed after all retries: ${detail}`);
|
|
@@ -9282,10 +9337,10 @@ init_esm_shims();
|
|
|
9282
9337
|
|
|
9283
9338
|
// src/brain/rule-store.ts
|
|
9284
9339
|
init_esm_shims();
|
|
9285
|
-
import { existsSync as
|
|
9286
|
-
import { join as
|
|
9340
|
+
import { existsSync as existsSync14, readFileSync as readFileSync14, writeFileSync as writeFileSync3, mkdirSync as mkdirSync4 } from "fs";
|
|
9341
|
+
import { join as join13 } from "path";
|
|
9287
9342
|
import { homedir as homedir6 } from "os";
|
|
9288
|
-
var DEFAULT_RULES_PATH =
|
|
9343
|
+
var DEFAULT_RULES_PATH = join13(homedir6(), ".agentmoss", "brain", "rules.json");
|
|
9289
9344
|
var ENV_RULES_PATH = "AGENT_MOSS_BRAIN_RULES_PATH";
|
|
9290
9345
|
var STATUS_DRAFT = "draft";
|
|
9291
9346
|
var STATUS_APPROVED = "approved";
|
|
@@ -9314,11 +9369,11 @@ var BrainRuleStore = class {
|
|
|
9314
9369
|
this.data = this.load();
|
|
9315
9370
|
}
|
|
9316
9371
|
load() {
|
|
9317
|
-
if (!
|
|
9372
|
+
if (!existsSync14(this.path)) {
|
|
9318
9373
|
return { version: 1, rules: [], pattern_candidates: [] };
|
|
9319
9374
|
}
|
|
9320
9375
|
try {
|
|
9321
|
-
const raw = JSON.parse(
|
|
9376
|
+
const raw = JSON.parse(readFileSync14(this.path, "utf-8"));
|
|
9322
9377
|
return {
|
|
9323
9378
|
version: raw.version || 1,
|
|
9324
9379
|
rules: raw.rules || [],
|
|
@@ -9898,11 +9953,11 @@ function parseReview(content) {
|
|
|
9898
9953
|
|
|
9899
9954
|
// src/brain/skill-manager.ts
|
|
9900
9955
|
init_esm_shims();
|
|
9901
|
-
import { existsSync as
|
|
9956
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync5, readFileSync as readFileSync15, renameSync as renameSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
9902
9957
|
import { homedir as homedir7 } from "os";
|
|
9903
|
-
import { join as
|
|
9958
|
+
import { join as join14 } from "path";
|
|
9904
9959
|
import { randomUUID } from "crypto";
|
|
9905
|
-
var DEFAULT_SKILL_META_PATH =
|
|
9960
|
+
var DEFAULT_SKILL_META_PATH = join14(homedir7(), ".agentmoss", "brain", "skill_meta.json");
|
|
9906
9961
|
var ENV_SKILL_META_PATH = "AGENT_MOSS_BRAIN_SKILL_META_PATH";
|
|
9907
9962
|
function getMetaPath(override) {
|
|
9908
9963
|
return override || process.env[ENV_SKILL_META_PATH] || DEFAULT_SKILL_META_PATH;
|
|
@@ -9912,7 +9967,7 @@ var BrainSkillManager = class {
|
|
|
9912
9967
|
this.skillsDir = skillsDir;
|
|
9913
9968
|
this.metaPath = getMetaPath(metaPath);
|
|
9914
9969
|
try {
|
|
9915
|
-
mkdirSync5(
|
|
9970
|
+
mkdirSync5(join14(this.metaPath, ".."), { recursive: true });
|
|
9916
9971
|
} catch {
|
|
9917
9972
|
}
|
|
9918
9973
|
this.load();
|
|
@@ -9922,9 +9977,9 @@ var BrainSkillManager = class {
|
|
|
9922
9977
|
skills = [];
|
|
9923
9978
|
metaPath;
|
|
9924
9979
|
load() {
|
|
9925
|
-
if (!
|
|
9980
|
+
if (!existsSync15(this.metaPath)) return;
|
|
9926
9981
|
try {
|
|
9927
|
-
const data = JSON.parse(
|
|
9982
|
+
const data = JSON.parse(readFileSync15(this.metaPath, "utf-8"));
|
|
9928
9983
|
this.skills = data.skills || [];
|
|
9929
9984
|
} catch {
|
|
9930
9985
|
this.skills = [];
|
|
@@ -9947,7 +10002,7 @@ var BrainSkillManager = class {
|
|
|
9947
10002
|
let changed = false;
|
|
9948
10003
|
for (const sk of this.skills) {
|
|
9949
10004
|
if (sk.status !== "active") continue;
|
|
9950
|
-
if (!
|
|
10005
|
+
if (!existsSync15(join14(this.skillsDir, `${sk.name}.md`))) {
|
|
9951
10006
|
sk.status = "stale";
|
|
9952
10007
|
changed = true;
|
|
9953
10008
|
}
|
|
@@ -9958,9 +10013,9 @@ var BrainSkillManager = class {
|
|
|
9958
10013
|
addSkill(skill) {
|
|
9959
10014
|
const id = skill.id || randomUUID();
|
|
9960
10015
|
const name = skill.name || `brain_${id.slice(0, 8)}`;
|
|
9961
|
-
if (!
|
|
9962
|
-
const mdPath =
|
|
9963
|
-
if (
|
|
10016
|
+
if (!existsSync15(this.skillsDir)) return "";
|
|
10017
|
+
const mdPath = join14(this.skillsDir, `${name}.md`);
|
|
10018
|
+
if (existsSync15(mdPath)) return "";
|
|
9964
10019
|
try {
|
|
9965
10020
|
writeFileSync4(mdPath, skill.content, "utf-8");
|
|
9966
10021
|
} catch {
|
|
@@ -10009,12 +10064,12 @@ var BrainSkillManager = class {
|
|
|
10009
10064
|
const out = [];
|
|
10010
10065
|
for (const sk of this.skills) {
|
|
10011
10066
|
if (sk.origin_node !== "local" || sk.status !== "active") continue;
|
|
10012
|
-
const mdPath =
|
|
10013
|
-
if (!
|
|
10067
|
+
const mdPath = join14(this.skillsDir, `${sk.name}.md`);
|
|
10068
|
+
if (!existsSync15(mdPath)) continue;
|
|
10014
10069
|
out.push({
|
|
10015
10070
|
name: sk.name,
|
|
10016
10071
|
category: sk.category || "",
|
|
10017
|
-
content:
|
|
10072
|
+
content: readFileSync15(mdPath, "utf-8"),
|
|
10018
10073
|
keywords: sk.keywords || []
|
|
10019
10074
|
});
|
|
10020
10075
|
}
|
|
@@ -10095,9 +10150,9 @@ var BrainCurator = class {
|
|
|
10095
10150
|
// src/brain/contributor.ts
|
|
10096
10151
|
init_esm_shims();
|
|
10097
10152
|
init_asset_dir();
|
|
10098
|
-
import { dirname as
|
|
10099
|
-
import { fileURLToPath as
|
|
10100
|
-
var __dirname8 =
|
|
10153
|
+
import { dirname as dirname12 } from "path";
|
|
10154
|
+
import { fileURLToPath as fileURLToPath10 } from "url";
|
|
10155
|
+
var __dirname8 = dirname12(fileURLToPath10(import.meta.url));
|
|
10101
10156
|
|
|
10102
10157
|
// src/brain/index.ts
|
|
10103
10158
|
function checkBrainRules(store, opts) {
|