@kenhkl/agent-gate 0.9.2 → 0.9.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/v1/cli.js +90 -41
- package/dist/v1/server.js +138 -89
- package/dist/v3/cli.js +118 -69
- package/package.json +1 -1
package/dist/v1/cli.js
CHANGED
|
@@ -177,8 +177,8 @@ function readFdToken() {
|
|
|
177
177
|
if (!raw) return "";
|
|
178
178
|
const fd = parseInt(raw, 10);
|
|
179
179
|
if (!Number.isFinite(fd)) return "";
|
|
180
|
-
const
|
|
181
|
-
if (
|
|
180
|
+
const cached2 = fdTokenCache.get(fd);
|
|
181
|
+
if (cached2 !== void 0) return cached2;
|
|
182
182
|
try {
|
|
183
183
|
const buf = Buffer.alloc(8192);
|
|
184
184
|
const n = (0, import_node_fs.readSync)(fd, buf, 0, buf.length, null);
|
|
@@ -1006,15 +1006,15 @@ var init_json_storage = __esm({
|
|
|
1006
1006
|
const archiveCount = total - keep;
|
|
1007
1007
|
const toArchive = flat.slice(0, archiveCount);
|
|
1008
1008
|
const archiveIds = new Set(toArchive.map((x) => String(x.rec.id)));
|
|
1009
|
-
const { mkdirSync:
|
|
1010
|
-
const { join:
|
|
1009
|
+
const { mkdirSync: mkdirSync5, writeFileSync: writeFileSync4 } = require("fs");
|
|
1010
|
+
const { join: join5 } = require("path");
|
|
1011
1011
|
const { gzipSync } = require("zlib");
|
|
1012
|
-
const archiveDir =
|
|
1013
|
-
if (!(0, import_fs2.existsSync)(archiveDir))
|
|
1012
|
+
const archiveDir = join5(this.dataDir, "archive");
|
|
1013
|
+
if (!(0, import_fs2.existsSync)(archiveDir)) mkdirSync5(archiveDir, { recursive: true, mode: 448 });
|
|
1014
1014
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
1015
|
-
const file =
|
|
1015
|
+
const file = join5(archiveDir, `tool_calls-${stamp}.jsonl.gz`);
|
|
1016
1016
|
const payload = toArchive.map((x) => JSON.stringify(x.rec)).join("\n") + "\n";
|
|
1017
|
-
|
|
1017
|
+
writeFileSync4(file, gzipSync(Buffer.from(payload, "utf-8")), { mode: 384 });
|
|
1018
1018
|
for (const [sid, recs] of bySession) {
|
|
1019
1019
|
const remain = recs.filter((r) => !archiveIds.has(String(r.id)));
|
|
1020
1020
|
if (remain.length !== recs.length) this.saveToolCalls(sid, remain);
|
|
@@ -1335,11 +1335,11 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1335
1335
|
const row = this.db.prepare("SELECT COUNT(*) as total FROM tool_calls").get();
|
|
1336
1336
|
let dbBytes = 0;
|
|
1337
1337
|
try {
|
|
1338
|
-
const { statSync: statSync3, existsSync:
|
|
1338
|
+
const { statSync: statSync3, existsSync: existsSync4 } = require("fs");
|
|
1339
1339
|
dbBytes = statSync3(this.dbPath).size;
|
|
1340
1340
|
for (const suffix of ["-wal", "-shm"]) {
|
|
1341
1341
|
const p = this.dbPath + suffix;
|
|
1342
|
-
if (
|
|
1342
|
+
if (existsSync4(p)) dbBytes += statSync3(p).size;
|
|
1343
1343
|
}
|
|
1344
1344
|
} catch {
|
|
1345
1345
|
}
|
|
@@ -1372,15 +1372,15 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1372
1372
|
"SELECT * FROM tool_calls WHERE id <= ? ORDER BY id"
|
|
1373
1373
|
).all(cutoff.id);
|
|
1374
1374
|
if (rows.length === 0) return { archived: 0, file: "" };
|
|
1375
|
-
const { writeFileSync:
|
|
1376
|
-
const { dirname:
|
|
1375
|
+
const { writeFileSync: writeFileSync4, mkdirSync: mkdirSync5, existsSync: existsSync4 } = require("fs");
|
|
1376
|
+
const { dirname: dirname5, join: join5 } = require("path");
|
|
1377
1377
|
const { gzipSync } = require("zlib");
|
|
1378
|
-
const archiveDir =
|
|
1379
|
-
if (!
|
|
1378
|
+
const archiveDir = join5(dirname5(this.dbPath), "archive");
|
|
1379
|
+
if (!existsSync4(archiveDir)) mkdirSync5(archiveDir, { recursive: true, mode: 448 });
|
|
1380
1380
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
1381
|
-
const file =
|
|
1381
|
+
const file = join5(archiveDir, `tool_calls-${stamp}.jsonl.gz`);
|
|
1382
1382
|
const payload = rows.map((r) => JSON.stringify(r)).join("\n") + "\n";
|
|
1383
|
-
|
|
1383
|
+
writeFileSync4(file, gzipSync(Buffer.from(payload, "utf-8")), { mode: 384 });
|
|
1384
1384
|
const deleted = this.db.transaction(() => {
|
|
1385
1385
|
const res = this.db.prepare("DELETE FROM tool_calls WHERE id <= ?").run(cutoff.id);
|
|
1386
1386
|
this.db.prepare(`
|
|
@@ -1486,14 +1486,14 @@ function getDb(dbPath) {
|
|
|
1486
1486
|
if (rawDb) return rawDb;
|
|
1487
1487
|
try {
|
|
1488
1488
|
const Database = require("better-sqlite3");
|
|
1489
|
-
const { existsSync:
|
|
1490
|
-
const { join:
|
|
1489
|
+
const { existsSync: existsSync4, mkdirSync: mkdirSync5 } = require("fs");
|
|
1490
|
+
const { join: join5, dirname: dirname5 } = require("path");
|
|
1491
1491
|
const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
1492
|
-
const xdgData = process.env.XDG_DATA_HOME ||
|
|
1493
|
-
const defaultPath =
|
|
1492
|
+
const xdgData = process.env.XDG_DATA_HOME || join5(home, ".local", "share");
|
|
1493
|
+
const defaultPath = join5(xdgData, "agent_gate", "agent_gate_ts.db");
|
|
1494
1494
|
const path = dbPath || defaultPath;
|
|
1495
|
-
const dir =
|
|
1496
|
-
if (!
|
|
1495
|
+
const dir = dirname5(path);
|
|
1496
|
+
if (!existsSync4(dir)) mkdirSync5(dir, { recursive: true });
|
|
1497
1497
|
rawDb = new Database(path);
|
|
1498
1498
|
rawDb.pragma("journal_mode = WAL");
|
|
1499
1499
|
return rawDb;
|
|
@@ -1536,6 +1536,46 @@ var init_db = __esm({
|
|
|
1536
1536
|
}
|
|
1537
1537
|
});
|
|
1538
1538
|
|
|
1539
|
+
// src/shared/instance-id.ts
|
|
1540
|
+
function getInstanceId() {
|
|
1541
|
+
if (cached) return cached;
|
|
1542
|
+
const env2 = (process.env.AGENT_GATE_INSTANCE_ID || "").trim();
|
|
1543
|
+
if (env2) {
|
|
1544
|
+
cached = env2;
|
|
1545
|
+
return cached;
|
|
1546
|
+
}
|
|
1547
|
+
const filePath = process.env.AGENT_GATE_INSTANCE_ID_PATH || (0, import_path4.join)((0, import_os.homedir)(), ".config", "agentgate", "instance_id");
|
|
1548
|
+
try {
|
|
1549
|
+
if ((0, import_fs4.existsSync)(filePath)) {
|
|
1550
|
+
const v2 = (0, import_fs4.readFileSync)(filePath, "utf-8").trim();
|
|
1551
|
+
if (v2) {
|
|
1552
|
+
cached = v2;
|
|
1553
|
+
return cached;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
const v = (0, import_crypto2.randomUUID)();
|
|
1557
|
+
(0, import_fs4.mkdirSync)((0, import_path4.dirname)(filePath), { recursive: true });
|
|
1558
|
+
(0, import_fs4.writeFileSync)(filePath, v + "\n", { mode: 384 });
|
|
1559
|
+
cached = v;
|
|
1560
|
+
return cached;
|
|
1561
|
+
} catch {
|
|
1562
|
+
cached = `ephemeral-${(0, import_crypto2.randomUUID)()}`;
|
|
1563
|
+
return cached;
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
var import_fs4, import_os, import_path4, import_crypto2, cached;
|
|
1567
|
+
var init_instance_id = __esm({
|
|
1568
|
+
"src/shared/instance-id.ts"() {
|
|
1569
|
+
"use strict";
|
|
1570
|
+
init_cjs_shims();
|
|
1571
|
+
import_fs4 = require("fs");
|
|
1572
|
+
import_os = require("os");
|
|
1573
|
+
import_path4 = require("path");
|
|
1574
|
+
import_crypto2 = require("crypto");
|
|
1575
|
+
cached = "";
|
|
1576
|
+
}
|
|
1577
|
+
});
|
|
1578
|
+
|
|
1539
1579
|
// src/shared/multi-session.ts
|
|
1540
1580
|
function isMultiSessionEnabled() {
|
|
1541
1581
|
const raw = (process.env.AGENT_GATE_MULTI_SESSION ?? "").trim().toLowerCase();
|
|
@@ -1582,6 +1622,9 @@ function buildSessionHistory(queryToolCalls2, sessionId, listAgentTypes) {
|
|
|
1582
1622
|
return [...bySession.entries()].slice(0, maxSessions).map(([sid, actions]) => ({
|
|
1583
1623
|
session_id: sid,
|
|
1584
1624
|
...sessionAgent.get(sid) ? { agent_id: sessionAgent.get(sid) } : {},
|
|
1625
|
+
// AgentGate 自己的存储属于本安装实例;带上实例 ID 让 AgentMoss 在
|
|
1626
|
+
// 展示层按「同实例不隐藏」处理(否则用户自己的历史会话也会被脱敏)。
|
|
1627
|
+
instance_id: getInstanceId(),
|
|
1585
1628
|
action_history: actions.slice(0, DEFAULT_ACTIONS_PER_SESSION)
|
|
1586
1629
|
}));
|
|
1587
1630
|
} catch {
|
|
@@ -1596,6 +1639,7 @@ var init_multi_session = __esm({
|
|
|
1596
1639
|
"src/shared/multi-session.ts"() {
|
|
1597
1640
|
"use strict";
|
|
1598
1641
|
init_cjs_shims();
|
|
1642
|
+
init_instance_id();
|
|
1599
1643
|
DEFAULT_HISTORY_LIMIT = 500;
|
|
1600
1644
|
DEFAULT_MAX_SESSIONS = 5;
|
|
1601
1645
|
DEFAULT_ACTIONS_PER_SESSION = 100;
|
|
@@ -1723,7 +1767,7 @@ var init_version = __esm({
|
|
|
1723
1767
|
"src/version.ts"() {
|
|
1724
1768
|
"use strict";
|
|
1725
1769
|
init_cjs_shims();
|
|
1726
|
-
_version = true ? "0.9.
|
|
1770
|
+
_version = true ? "0.9.3" : (() => {
|
|
1727
1771
|
try {
|
|
1728
1772
|
const require2 = createRequire(importMetaUrl);
|
|
1729
1773
|
const pkg = require2("../package.json");
|
|
@@ -1748,6 +1792,8 @@ var init_models = __esm({
|
|
|
1748
1792
|
agent_type: import_zod.z.string().describe("Agent identifier, e.g. opendesk, claude-code"),
|
|
1749
1793
|
agent_version: import_zod.z.string().default("0.1.0"),
|
|
1750
1794
|
session_id: import_zod.z.string().describe("Session unique identifier"),
|
|
1795
|
+
/** 安装级实例 ID(仅展示层脱敏用;缺省由 AgentGate 自动生成)。 */
|
|
1796
|
+
instance_id: import_zod.z.string().optional(),
|
|
1751
1797
|
tool_name: import_zod.z.string().optional().describe("Tool name, e.g. bash, file_write"),
|
|
1752
1798
|
command: import_zod.z.string().optional().describe("Tool command or description"),
|
|
1753
1799
|
a_next: import_zod.z.object({
|
|
@@ -1864,6 +1910,8 @@ function normalize(input, systemContext) {
|
|
|
1864
1910
|
// 历史上只在 metadata.agent_type 里带,AgentMoss 读顶层 req.agent_id → 空 →
|
|
1865
1911
|
// 定制规则从未生效(OpenDesk memory-* 操作走 L3 耗时 1~137s)。
|
|
1866
1912
|
agent_id: input.agent_type || "",
|
|
1913
|
+
// 实例 ID:仅用于 AgentMoss 展示层脱敏(同实例不隐藏),不参与判定。
|
|
1914
|
+
instance_id: input.instance_id || getInstanceId(),
|
|
1867
1915
|
metadata: {
|
|
1868
1916
|
...input.metadata,
|
|
1869
1917
|
agent_type: input.agent_type,
|
|
@@ -1882,6 +1930,7 @@ var init_normalizer = __esm({
|
|
|
1882
1930
|
"use strict";
|
|
1883
1931
|
init_cjs_shims();
|
|
1884
1932
|
init_multi_session();
|
|
1933
|
+
init_instance_id();
|
|
1885
1934
|
}
|
|
1886
1935
|
});
|
|
1887
1936
|
|
|
@@ -1890,22 +1939,22 @@ async function collectSystemInfo() {
|
|
|
1890
1939
|
try {
|
|
1891
1940
|
return {
|
|
1892
1941
|
system: process.platform,
|
|
1893
|
-
distribution: `${
|
|
1894
|
-
hostname:
|
|
1895
|
-
arch:
|
|
1896
|
-
cpu_count:
|
|
1897
|
-
memory_total_mb: Math.round(
|
|
1942
|
+
distribution: `${import_os2.default.type()} ${import_os2.default.release()}`,
|
|
1943
|
+
hostname: import_os2.default.hostname(),
|
|
1944
|
+
arch: import_os2.default.arch(),
|
|
1945
|
+
cpu_count: import_os2.default.cpus().length,
|
|
1946
|
+
memory_total_mb: Math.round(import_os2.default.totalmem() / (1024 * 1024))
|
|
1898
1947
|
};
|
|
1899
1948
|
} catch {
|
|
1900
1949
|
return { system: "unknown" };
|
|
1901
1950
|
}
|
|
1902
1951
|
}
|
|
1903
|
-
var
|
|
1952
|
+
var import_os2;
|
|
1904
1953
|
var init_system_info = __esm({
|
|
1905
1954
|
"src/shared/collector/system-info.ts"() {
|
|
1906
1955
|
"use strict";
|
|
1907
1956
|
init_cjs_shims();
|
|
1908
|
-
|
|
1957
|
+
import_os2 = __toESM(require("os"));
|
|
1909
1958
|
}
|
|
1910
1959
|
});
|
|
1911
1960
|
|
|
@@ -1932,7 +1981,7 @@ var init_process_info = __esm({
|
|
|
1932
1981
|
// src/shared/collector/user-info.ts
|
|
1933
1982
|
async function collectUserInfo() {
|
|
1934
1983
|
try {
|
|
1935
|
-
const userInfo =
|
|
1984
|
+
const userInfo = import_os3.default.userInfo();
|
|
1936
1985
|
return {
|
|
1937
1986
|
uid: userInfo.uid,
|
|
1938
1987
|
gid: userInfo.gid,
|
|
@@ -1943,12 +1992,12 @@ async function collectUserInfo() {
|
|
|
1943
1992
|
return { uid: -1 };
|
|
1944
1993
|
}
|
|
1945
1994
|
}
|
|
1946
|
-
var
|
|
1995
|
+
var import_os3;
|
|
1947
1996
|
var init_user_info = __esm({
|
|
1948
1997
|
"src/shared/collector/user-info.ts"() {
|
|
1949
1998
|
"use strict";
|
|
1950
1999
|
init_cjs_shims();
|
|
1951
|
-
|
|
2000
|
+
import_os3 = __toESM(require("os"));
|
|
1952
2001
|
}
|
|
1953
2002
|
});
|
|
1954
2003
|
|
|
@@ -2101,10 +2150,10 @@ async function analyzeRoute(c) {
|
|
|
2101
2150
|
const toolName = input.tool_name || input.a_next?.action_type || "unknown";
|
|
2102
2151
|
const command = input.command || input.a_next?.action_detail || "";
|
|
2103
2152
|
const key = cacheKey(input.session_id, input.cwd, command);
|
|
2104
|
-
const
|
|
2105
|
-
if (
|
|
2153
|
+
const cached2 = getCached(key);
|
|
2154
|
+
if (cached2) {
|
|
2106
2155
|
return c.json({
|
|
2107
|
-
...
|
|
2156
|
+
...cached2,
|
|
2108
2157
|
analysis_duration_ms: 0,
|
|
2109
2158
|
collected_context: {},
|
|
2110
2159
|
...storageOversizeInfo()
|
|
@@ -2406,17 +2455,17 @@ async function dashboardRoute(c) {
|
|
|
2406
2455
|
return c.html(UNAUTHORIZED_HTML, 401, DASHBOARD_SECURITY_HEADERS);
|
|
2407
2456
|
}
|
|
2408
2457
|
}
|
|
2409
|
-
const { readFileSync:
|
|
2410
|
-
const { resolve, dirname:
|
|
2458
|
+
const { readFileSync: readFileSync4, existsSync: existsSync4 } = await import("fs");
|
|
2459
|
+
const { resolve, dirname: dirname5 } = await import("path");
|
|
2411
2460
|
const { fileURLToPath } = await import("url");
|
|
2412
|
-
const __dirname =
|
|
2461
|
+
const __dirname = dirname5(fileURLToPath(importMetaUrl));
|
|
2413
2462
|
const paths = [
|
|
2414
2463
|
resolve(__dirname, "dashboard.html"),
|
|
2415
2464
|
resolve(__dirname, "../dashboard.html"),
|
|
2416
2465
|
resolve(__dirname, "../src/v1/dashboard.html")
|
|
2417
2466
|
];
|
|
2418
|
-
const htmlPath = paths.find((p) =>
|
|
2419
|
-
const html =
|
|
2467
|
+
const htmlPath = paths.find((p) => existsSync4(p)) || paths[0];
|
|
2468
|
+
const html = readFileSync4(htmlPath, "utf-8");
|
|
2420
2469
|
return c.html(html, 200, DASHBOARD_SECURITY_HEADERS);
|
|
2421
2470
|
}
|
|
2422
2471
|
var import_hono, import_cors, import_logger, import_cookie, PUBLIC_PAGE_PATHS, UNAUTHORIZED_HTML, AGENT_FORBIDDEN_HTML;
|
package/dist/v1/server.js
CHANGED
|
@@ -40,6 +40,46 @@ var init_cjs_shims = __esm({
|
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
+
// src/shared/instance-id.ts
|
|
44
|
+
function getInstanceId() {
|
|
45
|
+
if (cached) return cached;
|
|
46
|
+
const env2 = (process.env.AGENT_GATE_INSTANCE_ID || "").trim();
|
|
47
|
+
if (env2) {
|
|
48
|
+
cached = env2;
|
|
49
|
+
return cached;
|
|
50
|
+
}
|
|
51
|
+
const filePath = process.env.AGENT_GATE_INSTANCE_ID_PATH || (0, import_path.join)((0, import_os.homedir)(), ".config", "agentgate", "instance_id");
|
|
52
|
+
try {
|
|
53
|
+
if ((0, import_fs.existsSync)(filePath)) {
|
|
54
|
+
const v2 = (0, import_fs.readFileSync)(filePath, "utf-8").trim();
|
|
55
|
+
if (v2) {
|
|
56
|
+
cached = v2;
|
|
57
|
+
return cached;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const v = (0, import_crypto.randomUUID)();
|
|
61
|
+
(0, import_fs.mkdirSync)((0, import_path.dirname)(filePath), { recursive: true });
|
|
62
|
+
(0, import_fs.writeFileSync)(filePath, v + "\n", { mode: 384 });
|
|
63
|
+
cached = v;
|
|
64
|
+
return cached;
|
|
65
|
+
} catch {
|
|
66
|
+
cached = `ephemeral-${(0, import_crypto.randomUUID)()}`;
|
|
67
|
+
return cached;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
var import_fs, import_os, import_path, import_crypto, cached;
|
|
71
|
+
var init_instance_id = __esm({
|
|
72
|
+
"src/shared/instance-id.ts"() {
|
|
73
|
+
"use strict";
|
|
74
|
+
init_cjs_shims();
|
|
75
|
+
import_fs = require("fs");
|
|
76
|
+
import_os = require("os");
|
|
77
|
+
import_path = require("path");
|
|
78
|
+
import_crypto = require("crypto");
|
|
79
|
+
cached = "";
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
43
83
|
// src/shared/multi-session.ts
|
|
44
84
|
function isMultiSessionEnabled() {
|
|
45
85
|
const raw = (process.env.AGENT_GATE_MULTI_SESSION ?? "").trim().toLowerCase();
|
|
@@ -86,6 +126,9 @@ function buildSessionHistory(queryToolCalls2, sessionId, listAgentTypes) {
|
|
|
86
126
|
return [...bySession.entries()].slice(0, maxSessions).map(([sid, actions]) => ({
|
|
87
127
|
session_id: sid,
|
|
88
128
|
...sessionAgent.get(sid) ? { agent_id: sessionAgent.get(sid) } : {},
|
|
129
|
+
// AgentGate 自己的存储属于本安装实例;带上实例 ID 让 AgentMoss 在
|
|
130
|
+
// 展示层按「同实例不隐藏」处理(否则用户自己的历史会话也会被脱敏)。
|
|
131
|
+
instance_id: getInstanceId(),
|
|
89
132
|
action_history: actions.slice(0, DEFAULT_ACTIONS_PER_SESSION)
|
|
90
133
|
}));
|
|
91
134
|
} catch {
|
|
@@ -100,6 +143,7 @@ var init_multi_session = __esm({
|
|
|
100
143
|
"src/shared/multi-session.ts"() {
|
|
101
144
|
"use strict";
|
|
102
145
|
init_cjs_shims();
|
|
146
|
+
init_instance_id();
|
|
103
147
|
DEFAULT_HISTORY_LIMIT = 500;
|
|
104
148
|
DEFAULT_MAX_SESSIONS = 5;
|
|
105
149
|
DEFAULT_ACTIONS_PER_SESSION = 100;
|
|
@@ -186,8 +230,8 @@ function readFdToken() {
|
|
|
186
230
|
if (!raw) return "";
|
|
187
231
|
const fd = parseInt(raw, 10);
|
|
188
232
|
if (!Number.isFinite(fd)) return "";
|
|
189
|
-
const
|
|
190
|
-
if (
|
|
233
|
+
const cached2 = fdTokenCache.get(fd);
|
|
234
|
+
if (cached2 !== void 0) return cached2;
|
|
191
235
|
try {
|
|
192
236
|
const buf = Buffer.alloc(8192);
|
|
193
237
|
const n = (0, import_node_fs.readSync)(fd, buf, 0, buf.length, null);
|
|
@@ -648,12 +692,12 @@ function clipText(value, limit = maxRecordBytes()) {
|
|
|
648
692
|
const s = String(value ?? "");
|
|
649
693
|
if (limit <= 0 || s.length <= limit) return s;
|
|
650
694
|
const head = s.slice(0, limit);
|
|
651
|
-
const digest = (0,
|
|
695
|
+
const digest = (0, import_crypto2.createHash)("sha256").update(s).digest("hex").slice(0, 16);
|
|
652
696
|
return `${head}\u2026[truncated ${s.length - limit}B sha256:${digest}]`;
|
|
653
697
|
}
|
|
654
698
|
function diskFreePercent(targetPath) {
|
|
655
699
|
try {
|
|
656
|
-
const st = (0,
|
|
700
|
+
const st = (0, import_fs2.statfsSync)((0, import_path2.dirname)(targetPath));
|
|
657
701
|
const total = Number(st.blocks) || 0;
|
|
658
702
|
const avail = Number(st.bavail) || 0;
|
|
659
703
|
if (!total) return 100;
|
|
@@ -690,14 +734,14 @@ function prepareRecordForStorage(rec, targetPath) {
|
|
|
690
734
|
if (degraded) out = degradeRecord(out);
|
|
691
735
|
return { record: out, degraded };
|
|
692
736
|
}
|
|
693
|
-
var
|
|
737
|
+
var import_crypto2, import_fs2, import_path2, DEGRADE_COMMAND_BYTES;
|
|
694
738
|
var init_record_guard = __esm({
|
|
695
739
|
"src/shared/storage/record-guard.ts"() {
|
|
696
740
|
"use strict";
|
|
697
741
|
init_cjs_shims();
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
742
|
+
import_crypto2 = require("crypto");
|
|
743
|
+
import_fs2 = require("fs");
|
|
744
|
+
import_path2 = require("path");
|
|
701
745
|
init_security();
|
|
702
746
|
DEGRADE_COMMAND_BYTES = 512;
|
|
703
747
|
}
|
|
@@ -713,16 +757,16 @@ function nowISO() {
|
|
|
713
757
|
}
|
|
714
758
|
function getDefaultDataDir() {
|
|
715
759
|
const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
716
|
-
const xdgData = process.env.XDG_DATA_HOME || (0,
|
|
717
|
-
return (0,
|
|
760
|
+
const xdgData = process.env.XDG_DATA_HOME || (0, import_path3.join)(home, ".local", "share");
|
|
761
|
+
return (0, import_path3.join)(xdgData, "agent_gate", "storage");
|
|
718
762
|
}
|
|
719
|
-
var
|
|
763
|
+
var import_fs3, import_path3, JsonStorage;
|
|
720
764
|
var init_json_storage = __esm({
|
|
721
765
|
"src/shared/storage/json-storage.ts"() {
|
|
722
766
|
"use strict";
|
|
723
767
|
init_cjs_shims();
|
|
724
|
-
|
|
725
|
-
|
|
768
|
+
import_fs3 = require("fs");
|
|
769
|
+
import_path3 = require("path");
|
|
726
770
|
init_security();
|
|
727
771
|
init_record_guard();
|
|
728
772
|
JsonStorage = class {
|
|
@@ -737,11 +781,11 @@ var init_json_storage = __esm({
|
|
|
737
781
|
sessionLocks = /* @__PURE__ */ new Map();
|
|
738
782
|
constructor(dataDir) {
|
|
739
783
|
this.dataDir = dataDir || process.env.AGENT_GATE_DATA_DIR || getDefaultDataDir();
|
|
740
|
-
this.agentsPath = (0,
|
|
741
|
-
this.sessionsPath = (0,
|
|
742
|
-
this.toolCallsDir = (0,
|
|
743
|
-
if (!(0,
|
|
744
|
-
if (!(0,
|
|
784
|
+
this.agentsPath = (0, import_path3.join)(this.dataDir, "agents.json");
|
|
785
|
+
this.sessionsPath = (0, import_path3.join)(this.dataDir, "sessions.json");
|
|
786
|
+
this.toolCallsDir = (0, import_path3.join)(this.dataDir, "tool_calls");
|
|
787
|
+
if (!(0, import_fs3.existsSync)(this.dataDir)) (0, import_fs3.mkdirSync)(this.dataDir, { recursive: true, mode: 448 });
|
|
788
|
+
if (!(0, import_fs3.existsSync)(this.toolCallsDir)) (0, import_fs3.mkdirSync)(this.toolCallsDir, { recursive: true, mode: 448 });
|
|
745
789
|
this.hardenStoragePermissions();
|
|
746
790
|
this.nextId = this.recoverNextId();
|
|
747
791
|
}
|
|
@@ -753,10 +797,10 @@ var init_json_storage = __esm({
|
|
|
753
797
|
const uid = process.getuid?.();
|
|
754
798
|
const tighten = (p, mode) => {
|
|
755
799
|
try {
|
|
756
|
-
const st = (0,
|
|
800
|
+
const st = (0, import_fs3.statSync)(p);
|
|
757
801
|
if (st.isSymbolicLink()) return;
|
|
758
802
|
if (uid !== void 0 && st.uid !== uid) return;
|
|
759
|
-
if ((st.mode & 511) !== mode) (0,
|
|
803
|
+
if ((st.mode & 511) !== mode) (0, import_fs3.chmodSync)(p, mode);
|
|
760
804
|
} catch {
|
|
761
805
|
}
|
|
762
806
|
};
|
|
@@ -765,9 +809,9 @@ var init_json_storage = __esm({
|
|
|
765
809
|
tighten(this.agentsPath, 384);
|
|
766
810
|
tighten(this.sessionsPath, 384);
|
|
767
811
|
try {
|
|
768
|
-
for (const f of (0,
|
|
812
|
+
for (const f of (0, import_fs3.readdirSync)(this.toolCallsDir)) {
|
|
769
813
|
if (f.endsWith(".json") || f.endsWith(".tmp")) {
|
|
770
|
-
tighten((0,
|
|
814
|
+
tighten((0, import_path3.join)(this.toolCallsDir, f), 384);
|
|
771
815
|
}
|
|
772
816
|
}
|
|
773
817
|
} catch {
|
|
@@ -777,9 +821,9 @@ var init_json_storage = __esm({
|
|
|
777
821
|
recoverNextId() {
|
|
778
822
|
let maxId = 0;
|
|
779
823
|
try {
|
|
780
|
-
const files = (0,
|
|
824
|
+
const files = (0, import_fs3.readdirSync)(this.toolCallsDir).filter((f) => f.endsWith(".json"));
|
|
781
825
|
for (const file of files) {
|
|
782
|
-
const records = this.readJsonFile((0,
|
|
826
|
+
const records = this.readJsonFile((0, import_path3.join)(this.toolCallsDir, file), []);
|
|
783
827
|
for (const r of records) {
|
|
784
828
|
if (r.id > maxId) maxId = r.id;
|
|
785
829
|
}
|
|
@@ -790,19 +834,19 @@ var init_json_storage = __esm({
|
|
|
790
834
|
}
|
|
791
835
|
readJsonFile(path, fallback) {
|
|
792
836
|
try {
|
|
793
|
-
if (!(0,
|
|
794
|
-
return JSON.parse((0,
|
|
837
|
+
if (!(0, import_fs3.existsSync)(path)) return fallback;
|
|
838
|
+
return JSON.parse((0, import_fs3.readFileSync)(path, "utf-8"));
|
|
795
839
|
} catch {
|
|
796
840
|
return fallback;
|
|
797
841
|
}
|
|
798
842
|
}
|
|
799
843
|
/** 原子写入:先写 .tmp 再 rename(rename 保留 tmp 的 0600 权限) */
|
|
800
844
|
writeJsonFile(path, data) {
|
|
801
|
-
const dir = (0,
|
|
802
|
-
if (!(0,
|
|
845
|
+
const dir = (0, import_path3.dirname)(path);
|
|
846
|
+
if (!(0, import_fs3.existsSync)(dir)) (0, import_fs3.mkdirSync)(dir, { recursive: true, mode: 448 });
|
|
803
847
|
const tmp = path + ".tmp";
|
|
804
|
-
(0,
|
|
805
|
-
(0,
|
|
848
|
+
(0, import_fs3.writeFileSync)(tmp, JSON.stringify(data, null, 2), { encoding: "utf-8", mode: 384 });
|
|
849
|
+
(0, import_fs3.renameSync)(tmp, path);
|
|
806
850
|
}
|
|
807
851
|
loadAgents() {
|
|
808
852
|
const raw = this.readJsonFile(this.agentsPath, {});
|
|
@@ -820,12 +864,12 @@ var init_json_storage = __esm({
|
|
|
820
864
|
}
|
|
821
865
|
loadToolCalls(sessionId) {
|
|
822
866
|
return this.readJsonFile(
|
|
823
|
-
(0,
|
|
867
|
+
(0, import_path3.join)(this.toolCallsDir, `${sessionId}.json`),
|
|
824
868
|
[]
|
|
825
869
|
);
|
|
826
870
|
}
|
|
827
871
|
saveToolCalls(sessionId, records) {
|
|
828
|
-
this.writeJsonFile((0,
|
|
872
|
+
this.writeJsonFile((0, import_path3.join)(this.toolCallsDir, `${sessionId}.json`), records);
|
|
829
873
|
}
|
|
830
874
|
getOrCreateAgent(agentType, hostname, version2 = "") {
|
|
831
875
|
const agents = this.loadAgents();
|
|
@@ -911,9 +955,9 @@ var init_json_storage = __esm({
|
|
|
911
955
|
allRecords = records.map((r) => this.enrichRecord(r, sessions, agents));
|
|
912
956
|
} else {
|
|
913
957
|
try {
|
|
914
|
-
const files = (0,
|
|
958
|
+
const files = (0, import_fs3.readdirSync)(this.toolCallsDir).filter((f) => f.endsWith(".json"));
|
|
915
959
|
for (const file of files) {
|
|
916
|
-
const records = this.readJsonFile((0,
|
|
960
|
+
const records = this.readJsonFile((0, import_path3.join)(this.toolCallsDir, file), []);
|
|
917
961
|
allRecords.push(...records.map((r) => this.enrichRecord(r, sessions, agents)));
|
|
918
962
|
}
|
|
919
963
|
} catch {
|
|
@@ -947,9 +991,9 @@ var init_json_storage = __esm({
|
|
|
947
991
|
const agents = this.loadAgents();
|
|
948
992
|
let allRecords = [];
|
|
949
993
|
try {
|
|
950
|
-
const files = (0,
|
|
994
|
+
const files = (0, import_fs3.readdirSync)(this.toolCallsDir).filter((f) => f.endsWith(".json"));
|
|
951
995
|
for (const file of files) {
|
|
952
|
-
const records = this.readJsonFile((0,
|
|
996
|
+
const records = this.readJsonFile((0, import_path3.join)(this.toolCallsDir, file), []);
|
|
953
997
|
allRecords.push(...records);
|
|
954
998
|
}
|
|
955
999
|
} catch {
|
|
@@ -988,12 +1032,12 @@ var init_json_storage = __esm({
|
|
|
988
1032
|
let jsonFiles = 0;
|
|
989
1033
|
let jsonBytes = 0;
|
|
990
1034
|
try {
|
|
991
|
-
const files = (0,
|
|
1035
|
+
const files = (0, import_fs3.readdirSync)(this.toolCallsDir).filter((f) => f.endsWith(".json"));
|
|
992
1036
|
for (const file of files) {
|
|
993
|
-
const stat = (0,
|
|
1037
|
+
const stat = (0, import_fs3.statSync)((0, import_path3.join)(this.toolCallsDir, file));
|
|
994
1038
|
jsonFiles++;
|
|
995
1039
|
jsonBytes += stat.size;
|
|
996
|
-
const records = this.readJsonFile((0,
|
|
1040
|
+
const records = this.readJsonFile((0, import_path3.join)(this.toolCallsDir, file), []);
|
|
997
1041
|
toolCalls += records.length;
|
|
998
1042
|
}
|
|
999
1043
|
} catch {
|
|
@@ -1003,9 +1047,9 @@ var init_json_storage = __esm({
|
|
|
1003
1047
|
clearToolCalls() {
|
|
1004
1048
|
let removed = 0;
|
|
1005
1049
|
try {
|
|
1006
|
-
const files = (0,
|
|
1050
|
+
const files = (0, import_fs3.readdirSync)(this.toolCallsDir).filter((f) => f.endsWith(".json"));
|
|
1007
1051
|
for (const file of files) {
|
|
1008
|
-
(0,
|
|
1052
|
+
(0, import_fs3.unlinkSync)((0, import_path3.join)(this.toolCallsDir, file));
|
|
1009
1053
|
removed++;
|
|
1010
1054
|
}
|
|
1011
1055
|
} catch {
|
|
@@ -1029,10 +1073,10 @@ var init_json_storage = __esm({
|
|
|
1029
1073
|
* 再从各自的 session 文件里移除。数据不丢,只是不在主目录了。
|
|
1030
1074
|
*/
|
|
1031
1075
|
archiveOldRecords(keep) {
|
|
1032
|
-
if (keep <= 0 || !(0,
|
|
1076
|
+
if (keep <= 0 || !(0, import_fs3.existsSync)(this.toolCallsDir)) return { archived: 0, file: "" };
|
|
1033
1077
|
const bySession = /* @__PURE__ */ new Map();
|
|
1034
1078
|
let total = 0;
|
|
1035
|
-
for (const f of (0,
|
|
1079
|
+
for (const f of (0, import_fs3.readdirSync)(this.toolCallsDir)) {
|
|
1036
1080
|
if (!f.endsWith(".json")) continue;
|
|
1037
1081
|
const sid = f.slice(0, -".json".length);
|
|
1038
1082
|
const recs = this.loadToolCalls(sid);
|
|
@@ -1048,15 +1092,15 @@ var init_json_storage = __esm({
|
|
|
1048
1092
|
const archiveCount = total - keep;
|
|
1049
1093
|
const toArchive = flat.slice(0, archiveCount);
|
|
1050
1094
|
const archiveIds = new Set(toArchive.map((x) => String(x.rec.id)));
|
|
1051
|
-
const { mkdirSync:
|
|
1052
|
-
const { join:
|
|
1095
|
+
const { mkdirSync: mkdirSync5, writeFileSync: writeFileSync4 } = require("fs");
|
|
1096
|
+
const { join: join5 } = require("path");
|
|
1053
1097
|
const { gzipSync } = require("zlib");
|
|
1054
|
-
const archiveDir =
|
|
1055
|
-
if (!(0,
|
|
1098
|
+
const archiveDir = join5(this.dataDir, "archive");
|
|
1099
|
+
if (!(0, import_fs3.existsSync)(archiveDir)) mkdirSync5(archiveDir, { recursive: true, mode: 448 });
|
|
1056
1100
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
1057
|
-
const file =
|
|
1101
|
+
const file = join5(archiveDir, `tool_calls-${stamp}.jsonl.gz`);
|
|
1058
1102
|
const payload = toArchive.map((x) => JSON.stringify(x.rec)).join("\n") + "\n";
|
|
1059
|
-
|
|
1103
|
+
writeFileSync4(file, gzipSync(Buffer.from(payload, "utf-8")), { mode: 384 });
|
|
1060
1104
|
for (const [sid, recs] of bySession) {
|
|
1061
1105
|
const remain = recs.filter((r) => !archiveIds.has(String(r.id)));
|
|
1062
1106
|
if (remain.length !== recs.length) this.saveToolCalls(sid, remain);
|
|
@@ -1100,9 +1144,9 @@ var init_json_storage = __esm({
|
|
|
1100
1144
|
getTimeline(limit = 100) {
|
|
1101
1145
|
const buckets = /* @__PURE__ */ new Map();
|
|
1102
1146
|
try {
|
|
1103
|
-
const files = (0,
|
|
1147
|
+
const files = (0, import_fs3.readdirSync)(this.toolCallsDir).filter((f) => f.endsWith(".json"));
|
|
1104
1148
|
for (const file of files) {
|
|
1105
|
-
const records = this.readJsonFile((0,
|
|
1149
|
+
const records = this.readJsonFile((0, import_path3.join)(this.toolCallsDir, file), []);
|
|
1106
1150
|
for (const r of records) {
|
|
1107
1151
|
const minute = r.called_at.replace(/(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}):\d{2}/, "$1T$2");
|
|
1108
1152
|
const bucket = buckets.get(minute) || { allow: 0, deny: 0 };
|
|
@@ -1133,16 +1177,16 @@ __export(sqlite_storage_exports, {
|
|
|
1133
1177
|
});
|
|
1134
1178
|
function getDefaultDbPath() {
|
|
1135
1179
|
const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
1136
|
-
const xdgData = process.env.XDG_DATA_HOME || (0,
|
|
1137
|
-
return (0,
|
|
1180
|
+
const xdgData = process.env.XDG_DATA_HOME || (0, import_path4.join)(home, ".local", "share");
|
|
1181
|
+
return (0, import_path4.join)(xdgData, "agent_gate", "agent_gate_ts.db");
|
|
1138
1182
|
}
|
|
1139
|
-
var
|
|
1183
|
+
var import_fs4, import_path4, SCHEMA, SqliteStorage;
|
|
1140
1184
|
var init_sqlite_storage = __esm({
|
|
1141
1185
|
"src/shared/storage/sqlite-storage.ts"() {
|
|
1142
1186
|
"use strict";
|
|
1143
1187
|
init_cjs_shims();
|
|
1144
|
-
|
|
1145
|
-
|
|
1188
|
+
import_fs4 = require("fs");
|
|
1189
|
+
import_path4 = require("path");
|
|
1146
1190
|
init_record_guard();
|
|
1147
1191
|
SCHEMA = `
|
|
1148
1192
|
CREATE TABLE IF NOT EXISTS agents (
|
|
@@ -1204,8 +1248,8 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1204
1248
|
);
|
|
1205
1249
|
}
|
|
1206
1250
|
const path = dbPath || getDefaultDbPath();
|
|
1207
|
-
const dir = (0,
|
|
1208
|
-
if (!(0,
|
|
1251
|
+
const dir = (0, import_path4.dirname)(path);
|
|
1252
|
+
if (!(0, import_fs4.existsSync)(dir)) (0, import_fs4.mkdirSync)(dir, { recursive: true });
|
|
1209
1253
|
this.dbPath = path;
|
|
1210
1254
|
this.db = new Database(path);
|
|
1211
1255
|
this.db.pragma("journal_mode = WAL");
|
|
@@ -1377,11 +1421,11 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1377
1421
|
const row = this.db.prepare("SELECT COUNT(*) as total FROM tool_calls").get();
|
|
1378
1422
|
let dbBytes = 0;
|
|
1379
1423
|
try {
|
|
1380
|
-
const { statSync: statSync3, existsSync:
|
|
1424
|
+
const { statSync: statSync3, existsSync: existsSync4 } = require("fs");
|
|
1381
1425
|
dbBytes = statSync3(this.dbPath).size;
|
|
1382
1426
|
for (const suffix of ["-wal", "-shm"]) {
|
|
1383
1427
|
const p = this.dbPath + suffix;
|
|
1384
|
-
if (
|
|
1428
|
+
if (existsSync4(p)) dbBytes += statSync3(p).size;
|
|
1385
1429
|
}
|
|
1386
1430
|
} catch {
|
|
1387
1431
|
}
|
|
@@ -1414,15 +1458,15 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1414
1458
|
"SELECT * FROM tool_calls WHERE id <= ? ORDER BY id"
|
|
1415
1459
|
).all(cutoff.id);
|
|
1416
1460
|
if (rows.length === 0) return { archived: 0, file: "" };
|
|
1417
|
-
const { writeFileSync:
|
|
1418
|
-
const { dirname:
|
|
1461
|
+
const { writeFileSync: writeFileSync4, mkdirSync: mkdirSync5, existsSync: existsSync4 } = require("fs");
|
|
1462
|
+
const { dirname: dirname5, join: join5 } = require("path");
|
|
1419
1463
|
const { gzipSync } = require("zlib");
|
|
1420
|
-
const archiveDir =
|
|
1421
|
-
if (!
|
|
1464
|
+
const archiveDir = join5(dirname5(this.dbPath), "archive");
|
|
1465
|
+
if (!existsSync4(archiveDir)) mkdirSync5(archiveDir, { recursive: true, mode: 448 });
|
|
1422
1466
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
1423
|
-
const file =
|
|
1467
|
+
const file = join5(archiveDir, `tool_calls-${stamp}.jsonl.gz`);
|
|
1424
1468
|
const payload = rows.map((r) => JSON.stringify(r)).join("\n") + "\n";
|
|
1425
|
-
|
|
1469
|
+
writeFileSync4(file, gzipSync(Buffer.from(payload, "utf-8")), { mode: 384 });
|
|
1426
1470
|
const deleted = this.db.transaction(() => {
|
|
1427
1471
|
const res = this.db.prepare("DELETE FROM tool_calls WHERE id <= ?").run(cutoff.id);
|
|
1428
1472
|
this.db.prepare(`
|
|
@@ -1528,14 +1572,14 @@ function getDb(dbPath) {
|
|
|
1528
1572
|
if (rawDb) return rawDb;
|
|
1529
1573
|
try {
|
|
1530
1574
|
const Database = require("better-sqlite3");
|
|
1531
|
-
const { existsSync:
|
|
1532
|
-
const { join:
|
|
1575
|
+
const { existsSync: existsSync4, mkdirSync: mkdirSync5 } = require("fs");
|
|
1576
|
+
const { join: join5, dirname: dirname5 } = require("path");
|
|
1533
1577
|
const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
1534
|
-
const xdgData = process.env.XDG_DATA_HOME ||
|
|
1535
|
-
const defaultPath =
|
|
1578
|
+
const xdgData = process.env.XDG_DATA_HOME || join5(home, ".local", "share");
|
|
1579
|
+
const defaultPath = join5(xdgData, "agent_gate", "agent_gate_ts.db");
|
|
1536
1580
|
const path = dbPath || defaultPath;
|
|
1537
|
-
const dir =
|
|
1538
|
-
if (!
|
|
1581
|
+
const dir = dirname5(path);
|
|
1582
|
+
if (!existsSync4(dir)) mkdirSync5(dir, { recursive: true });
|
|
1539
1583
|
rawDb = new Database(path);
|
|
1540
1584
|
rawDb.pragma("journal_mode = WAL");
|
|
1541
1585
|
return rawDb;
|
|
@@ -1599,7 +1643,7 @@ var import_zod = require("zod");
|
|
|
1599
1643
|
|
|
1600
1644
|
// src/version.ts
|
|
1601
1645
|
init_cjs_shims();
|
|
1602
|
-
var _version = true ? "0.9.
|
|
1646
|
+
var _version = true ? "0.9.3" : (() => {
|
|
1603
1647
|
try {
|
|
1604
1648
|
const require2 = createRequire(importMetaUrl);
|
|
1605
1649
|
const pkg = require2("../package.json");
|
|
@@ -1615,6 +1659,8 @@ var AgentGateInputSchema = import_zod.z.object({
|
|
|
1615
1659
|
agent_type: import_zod.z.string().describe("Agent identifier, e.g. opendesk, claude-code"),
|
|
1616
1660
|
agent_version: import_zod.z.string().default("0.1.0"),
|
|
1617
1661
|
session_id: import_zod.z.string().describe("Session unique identifier"),
|
|
1662
|
+
/** 安装级实例 ID(仅展示层脱敏用;缺省由 AgentGate 自动生成)。 */
|
|
1663
|
+
instance_id: import_zod.z.string().optional(),
|
|
1618
1664
|
tool_name: import_zod.z.string().optional().describe("Tool name, e.g. bash, file_write"),
|
|
1619
1665
|
command: import_zod.z.string().optional().describe("Tool command or description"),
|
|
1620
1666
|
a_next: import_zod.z.object({
|
|
@@ -1688,6 +1734,7 @@ var HealthResponseSchema = import_zod.z.object({
|
|
|
1688
1734
|
// src/shared/normalizer.ts
|
|
1689
1735
|
init_cjs_shims();
|
|
1690
1736
|
init_multi_session();
|
|
1737
|
+
init_instance_id();
|
|
1691
1738
|
function normalize(input, systemContext) {
|
|
1692
1739
|
const actionHistory = input.action_history.map((h) => ({
|
|
1693
1740
|
action_type: h.action_type,
|
|
@@ -1731,6 +1778,8 @@ function normalize(input, systemContext) {
|
|
|
1731
1778
|
// 历史上只在 metadata.agent_type 里带,AgentMoss 读顶层 req.agent_id → 空 →
|
|
1732
1779
|
// 定制规则从未生效(OpenDesk memory-* 操作走 L3 耗时 1~137s)。
|
|
1733
1780
|
agent_id: input.agent_type || "",
|
|
1781
|
+
// 实例 ID:仅用于 AgentMoss 展示层脱敏(同实例不隐藏),不参与判定。
|
|
1782
|
+
instance_id: input.instance_id || getInstanceId(),
|
|
1734
1783
|
metadata: {
|
|
1735
1784
|
...input.metadata,
|
|
1736
1785
|
agent_type: input.agent_type,
|
|
@@ -1750,16 +1799,16 @@ init_cjs_shims();
|
|
|
1750
1799
|
|
|
1751
1800
|
// src/shared/collector/system-info.ts
|
|
1752
1801
|
init_cjs_shims();
|
|
1753
|
-
var
|
|
1802
|
+
var import_os2 = __toESM(require("os"));
|
|
1754
1803
|
async function collectSystemInfo() {
|
|
1755
1804
|
try {
|
|
1756
1805
|
return {
|
|
1757
1806
|
system: process.platform,
|
|
1758
|
-
distribution: `${
|
|
1759
|
-
hostname:
|
|
1760
|
-
arch:
|
|
1761
|
-
cpu_count:
|
|
1762
|
-
memory_total_mb: Math.round(
|
|
1807
|
+
distribution: `${import_os2.default.type()} ${import_os2.default.release()}`,
|
|
1808
|
+
hostname: import_os2.default.hostname(),
|
|
1809
|
+
arch: import_os2.default.arch(),
|
|
1810
|
+
cpu_count: import_os2.default.cpus().length,
|
|
1811
|
+
memory_total_mb: Math.round(import_os2.default.totalmem() / (1024 * 1024))
|
|
1763
1812
|
};
|
|
1764
1813
|
} catch {
|
|
1765
1814
|
return { system: "unknown" };
|
|
@@ -1783,10 +1832,10 @@ async function collectProcessInfo() {
|
|
|
1783
1832
|
|
|
1784
1833
|
// src/shared/collector/user-info.ts
|
|
1785
1834
|
init_cjs_shims();
|
|
1786
|
-
var
|
|
1835
|
+
var import_os3 = __toESM(require("os"));
|
|
1787
1836
|
async function collectUserInfo() {
|
|
1788
1837
|
try {
|
|
1789
|
-
const userInfo =
|
|
1838
|
+
const userInfo = import_os3.default.userInfo();
|
|
1790
1839
|
return {
|
|
1791
1840
|
uid: userInfo.uid,
|
|
1792
1841
|
gid: userInfo.gid,
|
|
@@ -1924,10 +1973,10 @@ async function analyzeRoute(c) {
|
|
|
1924
1973
|
const toolName = input.tool_name || input.a_next?.action_type || "unknown";
|
|
1925
1974
|
const command = input.command || input.a_next?.action_detail || "";
|
|
1926
1975
|
const key = cacheKey(input.session_id, input.cwd, command);
|
|
1927
|
-
const
|
|
1928
|
-
if (
|
|
1976
|
+
const cached2 = getCached(key);
|
|
1977
|
+
if (cached2) {
|
|
1929
1978
|
return c.json({
|
|
1930
|
-
...
|
|
1979
|
+
...cached2,
|
|
1931
1980
|
analysis_duration_ms: 0,
|
|
1932
1981
|
collected_context: {},
|
|
1933
1982
|
...storageOversizeInfo()
|
|
@@ -2239,17 +2288,17 @@ async function dashboardRoute(c) {
|
|
|
2239
2288
|
return c.html(UNAUTHORIZED_HTML, 401, DASHBOARD_SECURITY_HEADERS);
|
|
2240
2289
|
}
|
|
2241
2290
|
}
|
|
2242
|
-
const { readFileSync:
|
|
2243
|
-
const { resolve, dirname:
|
|
2291
|
+
const { readFileSync: readFileSync4, existsSync: existsSync4 } = await import("fs");
|
|
2292
|
+
const { resolve, dirname: dirname5 } = await import("path");
|
|
2244
2293
|
const { fileURLToPath } = await import("url");
|
|
2245
|
-
const __dirname =
|
|
2294
|
+
const __dirname = dirname5(fileURLToPath(importMetaUrl));
|
|
2246
2295
|
const paths = [
|
|
2247
2296
|
resolve(__dirname, "dashboard.html"),
|
|
2248
2297
|
resolve(__dirname, "../dashboard.html"),
|
|
2249
2298
|
resolve(__dirname, "../src/v1/dashboard.html")
|
|
2250
2299
|
];
|
|
2251
|
-
const htmlPath = paths.find((p) =>
|
|
2252
|
-
const html =
|
|
2300
|
+
const htmlPath = paths.find((p) => existsSync4(p)) || paths[0];
|
|
2301
|
+
const html = readFileSync4(htmlPath, "utf-8");
|
|
2253
2302
|
return c.html(html, 200, DASHBOARD_SECURITY_HEADERS);
|
|
2254
2303
|
}
|
|
2255
2304
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/v3/cli.js
CHANGED
|
@@ -50,7 +50,7 @@ var init_version = __esm({
|
|
|
50
50
|
"src/version.ts"() {
|
|
51
51
|
"use strict";
|
|
52
52
|
init_cjs_shims();
|
|
53
|
-
_version = true ? "0.9.
|
|
53
|
+
_version = true ? "0.9.3" : (() => {
|
|
54
54
|
try {
|
|
55
55
|
const require2 = createRequire(importMetaUrl);
|
|
56
56
|
const pkg = require2("../package.json");
|
|
@@ -199,8 +199,8 @@ function readFdToken() {
|
|
|
199
199
|
if (!raw) return "";
|
|
200
200
|
const fd = parseInt(raw, 10);
|
|
201
201
|
if (!Number.isFinite(fd)) return "";
|
|
202
|
-
const
|
|
203
|
-
if (
|
|
202
|
+
const cached2 = fdTokenCache.get(fd);
|
|
203
|
+
if (cached2 !== void 0) return cached2;
|
|
204
204
|
try {
|
|
205
205
|
const buf = Buffer.alloc(8192);
|
|
206
206
|
const n = (0, import_node_fs.readSync)(fd, buf, 0, buf.length, null);
|
|
@@ -1028,15 +1028,15 @@ var init_json_storage = __esm({
|
|
|
1028
1028
|
const archiveCount = total - keep;
|
|
1029
1029
|
const toArchive = flat.slice(0, archiveCount);
|
|
1030
1030
|
const archiveIds = new Set(toArchive.map((x) => String(x.rec.id)));
|
|
1031
|
-
const { mkdirSync:
|
|
1032
|
-
const { join:
|
|
1031
|
+
const { mkdirSync: mkdirSync6, writeFileSync: writeFileSync5 } = require("fs");
|
|
1032
|
+
const { join: join13 } = require("path");
|
|
1033
1033
|
const { gzipSync } = require("zlib");
|
|
1034
|
-
const archiveDir =
|
|
1035
|
-
if (!(0, import_fs2.existsSync)(archiveDir))
|
|
1034
|
+
const archiveDir = join13(this.dataDir, "archive");
|
|
1035
|
+
if (!(0, import_fs2.existsSync)(archiveDir)) mkdirSync6(archiveDir, { recursive: true, mode: 448 });
|
|
1036
1036
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
1037
|
-
const file =
|
|
1037
|
+
const file = join13(archiveDir, `tool_calls-${stamp}.jsonl.gz`);
|
|
1038
1038
|
const payload = toArchive.map((x) => JSON.stringify(x.rec)).join("\n") + "\n";
|
|
1039
|
-
|
|
1039
|
+
writeFileSync5(file, gzipSync(Buffer.from(payload, "utf-8")), { mode: 384 });
|
|
1040
1040
|
for (const [sid, recs] of bySession) {
|
|
1041
1041
|
const remain = recs.filter((r) => !archiveIds.has(String(r.id)));
|
|
1042
1042
|
if (remain.length !== recs.length) this.saveToolCalls(sid, remain);
|
|
@@ -1357,11 +1357,11 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1357
1357
|
const row = this.db.prepare("SELECT COUNT(*) as total FROM tool_calls").get();
|
|
1358
1358
|
let dbBytes = 0;
|
|
1359
1359
|
try {
|
|
1360
|
-
const { statSync: statSync10, existsSync:
|
|
1360
|
+
const { statSync: statSync10, existsSync: existsSync13 } = require("fs");
|
|
1361
1361
|
dbBytes = statSync10(this.dbPath).size;
|
|
1362
1362
|
for (const suffix of ["-wal", "-shm"]) {
|
|
1363
1363
|
const p = this.dbPath + suffix;
|
|
1364
|
-
if (
|
|
1364
|
+
if (existsSync13(p)) dbBytes += statSync10(p).size;
|
|
1365
1365
|
}
|
|
1366
1366
|
} catch {
|
|
1367
1367
|
}
|
|
@@ -1394,15 +1394,15 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1394
1394
|
"SELECT * FROM tool_calls WHERE id <= ? ORDER BY id"
|
|
1395
1395
|
).all(cutoff.id);
|
|
1396
1396
|
if (rows.length === 0) return { archived: 0, file: "" };
|
|
1397
|
-
const { writeFileSync:
|
|
1398
|
-
const { dirname:
|
|
1397
|
+
const { writeFileSync: writeFileSync5, mkdirSync: mkdirSync6, existsSync: existsSync13 } = require("fs");
|
|
1398
|
+
const { dirname: dirname7, join: join13 } = require("path");
|
|
1399
1399
|
const { gzipSync } = require("zlib");
|
|
1400
|
-
const archiveDir =
|
|
1401
|
-
if (!
|
|
1400
|
+
const archiveDir = join13(dirname7(this.dbPath), "archive");
|
|
1401
|
+
if (!existsSync13(archiveDir)) mkdirSync6(archiveDir, { recursive: true, mode: 448 });
|
|
1402
1402
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
1403
|
-
const file =
|
|
1403
|
+
const file = join13(archiveDir, `tool_calls-${stamp}.jsonl.gz`);
|
|
1404
1404
|
const payload = rows.map((r) => JSON.stringify(r)).join("\n") + "\n";
|
|
1405
|
-
|
|
1405
|
+
writeFileSync5(file, gzipSync(Buffer.from(payload, "utf-8")), { mode: 384 });
|
|
1406
1406
|
const deleted = this.db.transaction(() => {
|
|
1407
1407
|
const res = this.db.prepare("DELETE FROM tool_calls WHERE id <= ?").run(cutoff.id);
|
|
1408
1408
|
this.db.prepare(`
|
|
@@ -1508,14 +1508,14 @@ function getDb(dbPath) {
|
|
|
1508
1508
|
if (rawDb) return rawDb;
|
|
1509
1509
|
try {
|
|
1510
1510
|
const Database = require("better-sqlite3");
|
|
1511
|
-
const { existsSync:
|
|
1512
|
-
const { join:
|
|
1511
|
+
const { existsSync: existsSync13, mkdirSync: mkdirSync6 } = require("fs");
|
|
1512
|
+
const { join: join13, dirname: dirname7 } = require("path");
|
|
1513
1513
|
const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
1514
|
-
const xdgData = process.env.XDG_DATA_HOME ||
|
|
1515
|
-
const defaultPath =
|
|
1514
|
+
const xdgData = process.env.XDG_DATA_HOME || join13(home, ".local", "share");
|
|
1515
|
+
const defaultPath = join13(xdgData, "agent_gate", "agent_gate_ts.db");
|
|
1516
1516
|
const path11 = dbPath || defaultPath;
|
|
1517
|
-
const dir2 =
|
|
1518
|
-
if (!
|
|
1517
|
+
const dir2 = dirname7(path11);
|
|
1518
|
+
if (!existsSync13(dir2)) mkdirSync6(dir2, { recursive: true });
|
|
1519
1519
|
rawDb = new Database(path11);
|
|
1520
1520
|
rawDb.pragma("journal_mode = WAL");
|
|
1521
1521
|
return rawDb;
|
|
@@ -1558,6 +1558,46 @@ var init_db = __esm({
|
|
|
1558
1558
|
}
|
|
1559
1559
|
});
|
|
1560
1560
|
|
|
1561
|
+
// src/shared/instance-id.ts
|
|
1562
|
+
function getInstanceId() {
|
|
1563
|
+
if (cached) return cached;
|
|
1564
|
+
const env2 = (process.env.AGENT_GATE_INSTANCE_ID || "").trim();
|
|
1565
|
+
if (env2) {
|
|
1566
|
+
cached = env2;
|
|
1567
|
+
return cached;
|
|
1568
|
+
}
|
|
1569
|
+
const filePath = process.env.AGENT_GATE_INSTANCE_ID_PATH || (0, import_path4.join)((0, import_os.homedir)(), ".config", "agentgate", "instance_id");
|
|
1570
|
+
try {
|
|
1571
|
+
if ((0, import_fs4.existsSync)(filePath)) {
|
|
1572
|
+
const v2 = (0, import_fs4.readFileSync)(filePath, "utf-8").trim();
|
|
1573
|
+
if (v2) {
|
|
1574
|
+
cached = v2;
|
|
1575
|
+
return cached;
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
const v = (0, import_crypto2.randomUUID)();
|
|
1579
|
+
(0, import_fs4.mkdirSync)((0, import_path4.dirname)(filePath), { recursive: true });
|
|
1580
|
+
(0, import_fs4.writeFileSync)(filePath, v + "\n", { mode: 384 });
|
|
1581
|
+
cached = v;
|
|
1582
|
+
return cached;
|
|
1583
|
+
} catch {
|
|
1584
|
+
cached = `ephemeral-${(0, import_crypto2.randomUUID)()}`;
|
|
1585
|
+
return cached;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
var import_fs4, import_os, import_path4, import_crypto2, cached;
|
|
1589
|
+
var init_instance_id = __esm({
|
|
1590
|
+
"src/shared/instance-id.ts"() {
|
|
1591
|
+
"use strict";
|
|
1592
|
+
init_cjs_shims();
|
|
1593
|
+
import_fs4 = require("fs");
|
|
1594
|
+
import_os = require("os");
|
|
1595
|
+
import_path4 = require("path");
|
|
1596
|
+
import_crypto2 = require("crypto");
|
|
1597
|
+
cached = "";
|
|
1598
|
+
}
|
|
1599
|
+
});
|
|
1600
|
+
|
|
1561
1601
|
// src/shared/multi-session.ts
|
|
1562
1602
|
function isMultiSessionEnabled() {
|
|
1563
1603
|
const raw = (process.env.AGENT_GATE_MULTI_SESSION ?? "").trim().toLowerCase();
|
|
@@ -1604,6 +1644,9 @@ function buildSessionHistory(queryToolCalls2, sessionId, listAgentTypes) {
|
|
|
1604
1644
|
return [...bySession.entries()].slice(0, maxSessions).map(([sid, actions]) => ({
|
|
1605
1645
|
session_id: sid,
|
|
1606
1646
|
...sessionAgent.get(sid) ? { agent_id: sessionAgent.get(sid) } : {},
|
|
1647
|
+
// AgentGate 自己的存储属于本安装实例;带上实例 ID 让 AgentMoss 在
|
|
1648
|
+
// 展示层按「同实例不隐藏」处理(否则用户自己的历史会话也会被脱敏)。
|
|
1649
|
+
instance_id: getInstanceId(),
|
|
1607
1650
|
action_history: actions.slice(0, DEFAULT_ACTIONS_PER_SESSION)
|
|
1608
1651
|
}));
|
|
1609
1652
|
} catch {
|
|
@@ -1618,6 +1661,7 @@ var init_multi_session = __esm({
|
|
|
1618
1661
|
"src/shared/multi-session.ts"() {
|
|
1619
1662
|
"use strict";
|
|
1620
1663
|
init_cjs_shims();
|
|
1664
|
+
init_instance_id();
|
|
1621
1665
|
DEFAULT_HISTORY_LIMIT = 500;
|
|
1622
1666
|
DEFAULT_MAX_SESSIONS = 5;
|
|
1623
1667
|
DEFAULT_ACTIONS_PER_SESSION = 100;
|
|
@@ -1751,6 +1795,8 @@ var init_models = __esm({
|
|
|
1751
1795
|
agent_type: import_zod.z.string().describe("Agent identifier, e.g. opendesk, claude-code"),
|
|
1752
1796
|
agent_version: import_zod.z.string().default("0.1.0"),
|
|
1753
1797
|
session_id: import_zod.z.string().describe("Session unique identifier"),
|
|
1798
|
+
/** 安装级实例 ID(仅展示层脱敏用;缺省由 AgentGate 自动生成)。 */
|
|
1799
|
+
instance_id: import_zod.z.string().optional(),
|
|
1754
1800
|
tool_name: import_zod.z.string().optional().describe("Tool name, e.g. bash, file_write"),
|
|
1755
1801
|
command: import_zod.z.string().optional().describe("Tool command or description"),
|
|
1756
1802
|
a_next: import_zod.z.object({
|
|
@@ -1867,6 +1913,8 @@ function normalize(input, systemContext) {
|
|
|
1867
1913
|
// 历史上只在 metadata.agent_type 里带,AgentMoss 读顶层 req.agent_id → 空 →
|
|
1868
1914
|
// 定制规则从未生效(OpenDesk memory-* 操作走 L3 耗时 1~137s)。
|
|
1869
1915
|
agent_id: input.agent_type || "",
|
|
1916
|
+
// 实例 ID:仅用于 AgentMoss 展示层脱敏(同实例不隐藏),不参与判定。
|
|
1917
|
+
instance_id: input.instance_id || getInstanceId(),
|
|
1870
1918
|
metadata: {
|
|
1871
1919
|
...input.metadata,
|
|
1872
1920
|
agent_type: input.agent_type,
|
|
@@ -1885,6 +1933,7 @@ var init_normalizer = __esm({
|
|
|
1885
1933
|
"use strict";
|
|
1886
1934
|
init_cjs_shims();
|
|
1887
1935
|
init_multi_session();
|
|
1936
|
+
init_instance_id();
|
|
1888
1937
|
}
|
|
1889
1938
|
});
|
|
1890
1939
|
|
|
@@ -1893,22 +1942,22 @@ async function collectSystemInfo() {
|
|
|
1893
1942
|
try {
|
|
1894
1943
|
return {
|
|
1895
1944
|
system: process.platform,
|
|
1896
|
-
distribution: `${
|
|
1897
|
-
hostname:
|
|
1898
|
-
arch:
|
|
1899
|
-
cpu_count:
|
|
1900
|
-
memory_total_mb: Math.round(
|
|
1945
|
+
distribution: `${import_os2.default.type()} ${import_os2.default.release()}`,
|
|
1946
|
+
hostname: import_os2.default.hostname(),
|
|
1947
|
+
arch: import_os2.default.arch(),
|
|
1948
|
+
cpu_count: import_os2.default.cpus().length,
|
|
1949
|
+
memory_total_mb: Math.round(import_os2.default.totalmem() / (1024 * 1024))
|
|
1901
1950
|
};
|
|
1902
1951
|
} catch {
|
|
1903
1952
|
return { system: "unknown" };
|
|
1904
1953
|
}
|
|
1905
1954
|
}
|
|
1906
|
-
var
|
|
1955
|
+
var import_os2;
|
|
1907
1956
|
var init_system_info = __esm({
|
|
1908
1957
|
"src/shared/collector/system-info.ts"() {
|
|
1909
1958
|
"use strict";
|
|
1910
1959
|
init_cjs_shims();
|
|
1911
|
-
|
|
1960
|
+
import_os2 = __toESM(require("os"));
|
|
1912
1961
|
}
|
|
1913
1962
|
});
|
|
1914
1963
|
|
|
@@ -1935,7 +1984,7 @@ var init_process_info = __esm({
|
|
|
1935
1984
|
// src/shared/collector/user-info.ts
|
|
1936
1985
|
async function collectUserInfo() {
|
|
1937
1986
|
try {
|
|
1938
|
-
const userInfo =
|
|
1987
|
+
const userInfo = import_os3.default.userInfo();
|
|
1939
1988
|
return {
|
|
1940
1989
|
uid: userInfo.uid,
|
|
1941
1990
|
gid: userInfo.gid,
|
|
@@ -1946,12 +1995,12 @@ async function collectUserInfo() {
|
|
|
1946
1995
|
return { uid: -1 };
|
|
1947
1996
|
}
|
|
1948
1997
|
}
|
|
1949
|
-
var
|
|
1998
|
+
var import_os3;
|
|
1950
1999
|
var init_user_info = __esm({
|
|
1951
2000
|
"src/shared/collector/user-info.ts"() {
|
|
1952
2001
|
"use strict";
|
|
1953
2002
|
init_cjs_shims();
|
|
1954
|
-
|
|
2003
|
+
import_os3 = __toESM(require("os"));
|
|
1955
2004
|
}
|
|
1956
2005
|
});
|
|
1957
2006
|
|
|
@@ -2098,10 +2147,10 @@ async function analyzeRoute(c) {
|
|
|
2098
2147
|
const toolName = input.tool_name || input.a_next?.action_type || "unknown";
|
|
2099
2148
|
const command = input.command || input.a_next?.action_detail || "";
|
|
2100
2149
|
const key = cacheKey(input.session_id, input.cwd, command);
|
|
2101
|
-
const
|
|
2102
|
-
if (
|
|
2150
|
+
const cached2 = getCached(key);
|
|
2151
|
+
if (cached2) {
|
|
2103
2152
|
return c.json({
|
|
2104
|
-
...
|
|
2153
|
+
...cached2,
|
|
2105
2154
|
analysis_duration_ms: 0,
|
|
2106
2155
|
collected_context: {},
|
|
2107
2156
|
...storageOversizeInfo()
|
|
@@ -2403,17 +2452,17 @@ async function dashboardRoute(c) {
|
|
|
2403
2452
|
return c.html(UNAUTHORIZED_HTML, 401, DASHBOARD_SECURITY_HEADERS);
|
|
2404
2453
|
}
|
|
2405
2454
|
}
|
|
2406
|
-
const { readFileSync:
|
|
2407
|
-
const { resolve: resolve4, dirname:
|
|
2455
|
+
const { readFileSync: readFileSync15, existsSync: existsSync13 } = await import("fs");
|
|
2456
|
+
const { resolve: resolve4, dirname: dirname7 } = await import("path");
|
|
2408
2457
|
const { fileURLToPath } = await import("url");
|
|
2409
|
-
const __dirname2 =
|
|
2458
|
+
const __dirname2 = dirname7(fileURLToPath(importMetaUrl));
|
|
2410
2459
|
const paths = [
|
|
2411
2460
|
resolve4(__dirname2, "dashboard.html"),
|
|
2412
2461
|
resolve4(__dirname2, "../dashboard.html"),
|
|
2413
2462
|
resolve4(__dirname2, "../src/v1/dashboard.html")
|
|
2414
2463
|
];
|
|
2415
|
-
const htmlPath = paths.find((p) =>
|
|
2416
|
-
const html =
|
|
2464
|
+
const htmlPath = paths.find((p) => existsSync13(p)) || paths[0];
|
|
2465
|
+
const html = readFileSync15(htmlPath, "utf-8");
|
|
2417
2466
|
return c.html(html, 200, DASHBOARD_SECURITY_HEADERS);
|
|
2418
2467
|
}
|
|
2419
2468
|
var import_hono, import_cors, import_logger, import_cookie, PUBLIC_PAGE_PATHS, UNAUTHORIZED_HTML, AGENT_FORBIDDEN_HTML;
|
|
@@ -26105,14 +26154,14 @@ var require_find_made = __commonJS({
|
|
|
26105
26154
|
"../node_modules/mkdirp/lib/find-made.js"(exports2, module2) {
|
|
26106
26155
|
"use strict";
|
|
26107
26156
|
init_cjs_shims();
|
|
26108
|
-
var { dirname:
|
|
26157
|
+
var { dirname: dirname7 } = require("path");
|
|
26109
26158
|
var findMade = (opts, parent2, path11 = void 0) => {
|
|
26110
26159
|
if (path11 === parent2)
|
|
26111
26160
|
return Promise.resolve();
|
|
26112
26161
|
return opts.statAsync(parent2).then(
|
|
26113
26162
|
(st) => st.isDirectory() ? path11 : void 0,
|
|
26114
26163
|
// will fail later
|
|
26115
|
-
(er) => er.code === "ENOENT" ? findMade(opts,
|
|
26164
|
+
(er) => er.code === "ENOENT" ? findMade(opts, dirname7(parent2), parent2) : void 0
|
|
26116
26165
|
);
|
|
26117
26166
|
};
|
|
26118
26167
|
var findMadeSync = (opts, parent2, path11 = void 0) => {
|
|
@@ -26121,7 +26170,7 @@ var require_find_made = __commonJS({
|
|
|
26121
26170
|
try {
|
|
26122
26171
|
return opts.statSync(parent2).isDirectory() ? path11 : void 0;
|
|
26123
26172
|
} catch (er) {
|
|
26124
|
-
return er.code === "ENOENT" ? findMadeSync(opts,
|
|
26173
|
+
return er.code === "ENOENT" ? findMadeSync(opts, dirname7(parent2), parent2) : void 0;
|
|
26125
26174
|
}
|
|
26126
26175
|
};
|
|
26127
26176
|
module2.exports = { findMade, findMadeSync };
|
|
@@ -26133,10 +26182,10 @@ var require_mkdirp_manual = __commonJS({
|
|
|
26133
26182
|
"../node_modules/mkdirp/lib/mkdirp-manual.js"(exports2, module2) {
|
|
26134
26183
|
"use strict";
|
|
26135
26184
|
init_cjs_shims();
|
|
26136
|
-
var { dirname:
|
|
26185
|
+
var { dirname: dirname7 } = require("path");
|
|
26137
26186
|
var mkdirpManual = (path11, opts, made) => {
|
|
26138
26187
|
opts.recursive = false;
|
|
26139
|
-
const parent2 =
|
|
26188
|
+
const parent2 = dirname7(path11);
|
|
26140
26189
|
if (parent2 === path11) {
|
|
26141
26190
|
return opts.mkdirAsync(path11, opts).catch((er) => {
|
|
26142
26191
|
if (er.code !== "EISDIR")
|
|
@@ -26159,7 +26208,7 @@ var require_mkdirp_manual = __commonJS({
|
|
|
26159
26208
|
});
|
|
26160
26209
|
};
|
|
26161
26210
|
var mkdirpManualSync = (path11, opts, made) => {
|
|
26162
|
-
const parent2 =
|
|
26211
|
+
const parent2 = dirname7(path11);
|
|
26163
26212
|
opts.recursive = false;
|
|
26164
26213
|
if (parent2 === path11) {
|
|
26165
26214
|
try {
|
|
@@ -26196,12 +26245,12 @@ var require_mkdirp_native = __commonJS({
|
|
|
26196
26245
|
"../node_modules/mkdirp/lib/mkdirp-native.js"(exports2, module2) {
|
|
26197
26246
|
"use strict";
|
|
26198
26247
|
init_cjs_shims();
|
|
26199
|
-
var { dirname:
|
|
26248
|
+
var { dirname: dirname7 } = require("path");
|
|
26200
26249
|
var { findMade, findMadeSync } = require_find_made();
|
|
26201
26250
|
var { mkdirpManual, mkdirpManualSync } = require_mkdirp_manual();
|
|
26202
26251
|
var mkdirpNative = (path11, opts) => {
|
|
26203
26252
|
opts.recursive = true;
|
|
26204
|
-
const parent2 =
|
|
26253
|
+
const parent2 = dirname7(path11);
|
|
26205
26254
|
if (parent2 === path11)
|
|
26206
26255
|
return opts.mkdirAsync(path11, opts);
|
|
26207
26256
|
return findMade(opts, path11).then((made) => opts.mkdirAsync(path11, opts).then(() => made).catch((er) => {
|
|
@@ -26213,7 +26262,7 @@ var require_mkdirp_native = __commonJS({
|
|
|
26213
26262
|
};
|
|
26214
26263
|
var mkdirpNativeSync = (path11, opts) => {
|
|
26215
26264
|
opts.recursive = true;
|
|
26216
|
-
const parent2 =
|
|
26265
|
+
const parent2 = dirname7(path11);
|
|
26217
26266
|
if (parent2 === path11)
|
|
26218
26267
|
return opts.mkdirSync(path11, opts);
|
|
26219
26268
|
const made = findMadeSync(opts, path11);
|
|
@@ -26669,17 +26718,17 @@ var require_ProxyFinalRequestFilter = __commonJS({
|
|
|
26669
26718
|
// ../node_modules/uuid/dist/esm-node/rng.js
|
|
26670
26719
|
function rng() {
|
|
26671
26720
|
if (poolPtr > rnds8Pool.length - 16) {
|
|
26672
|
-
|
|
26721
|
+
import_crypto3.default.randomFillSync(rnds8Pool);
|
|
26673
26722
|
poolPtr = 0;
|
|
26674
26723
|
}
|
|
26675
26724
|
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
26676
26725
|
}
|
|
26677
|
-
var
|
|
26726
|
+
var import_crypto3, rnds8Pool, poolPtr;
|
|
26678
26727
|
var init_rng = __esm({
|
|
26679
26728
|
"../node_modules/uuid/dist/esm-node/rng.js"() {
|
|
26680
26729
|
"use strict";
|
|
26681
26730
|
init_cjs_shims();
|
|
26682
|
-
|
|
26731
|
+
import_crypto3 = __toESM(require("crypto"));
|
|
26683
26732
|
rnds8Pool = new Uint8Array(256);
|
|
26684
26733
|
poolPtr = rnds8Pool.length;
|
|
26685
26734
|
}
|
|
@@ -26894,14 +26943,14 @@ function md5(bytes) {
|
|
|
26894
26943
|
} else if (typeof bytes === "string") {
|
|
26895
26944
|
bytes = Buffer.from(bytes, "utf8");
|
|
26896
26945
|
}
|
|
26897
|
-
return
|
|
26946
|
+
return import_crypto4.default.createHash("md5").update(bytes).digest();
|
|
26898
26947
|
}
|
|
26899
|
-
var
|
|
26948
|
+
var import_crypto4, md5_default;
|
|
26900
26949
|
var init_md5 = __esm({
|
|
26901
26950
|
"../node_modules/uuid/dist/esm-node/md5.js"() {
|
|
26902
26951
|
"use strict";
|
|
26903
26952
|
init_cjs_shims();
|
|
26904
|
-
|
|
26953
|
+
import_crypto4 = __toESM(require("crypto"));
|
|
26905
26954
|
md5_default = md5;
|
|
26906
26955
|
}
|
|
26907
26956
|
});
|
|
@@ -26920,14 +26969,14 @@ var init_v3 = __esm({
|
|
|
26920
26969
|
});
|
|
26921
26970
|
|
|
26922
26971
|
// ../node_modules/uuid/dist/esm-node/native.js
|
|
26923
|
-
var
|
|
26972
|
+
var import_crypto5, native_default;
|
|
26924
26973
|
var init_native = __esm({
|
|
26925
26974
|
"../node_modules/uuid/dist/esm-node/native.js"() {
|
|
26926
26975
|
"use strict";
|
|
26927
26976
|
init_cjs_shims();
|
|
26928
|
-
|
|
26977
|
+
import_crypto5 = __toESM(require("crypto"));
|
|
26929
26978
|
native_default = {
|
|
26930
|
-
randomUUID:
|
|
26979
|
+
randomUUID: import_crypto5.default.randomUUID
|
|
26931
26980
|
};
|
|
26932
26981
|
}
|
|
26933
26982
|
});
|
|
@@ -26969,14 +27018,14 @@ function sha1(bytes) {
|
|
|
26969
27018
|
} else if (typeof bytes === "string") {
|
|
26970
27019
|
bytes = Buffer.from(bytes, "utf8");
|
|
26971
27020
|
}
|
|
26972
|
-
return
|
|
27021
|
+
return import_crypto6.default.createHash("sha1").update(bytes).digest();
|
|
26973
27022
|
}
|
|
26974
|
-
var
|
|
27023
|
+
var import_crypto6, sha1_default;
|
|
26975
27024
|
var init_sha1 = __esm({
|
|
26976
27025
|
"../node_modules/uuid/dist/esm-node/sha1.js"() {
|
|
26977
27026
|
"use strict";
|
|
26978
27027
|
init_cjs_shims();
|
|
26979
|
-
|
|
27028
|
+
import_crypto6 = __toESM(require("crypto"));
|
|
26980
27029
|
sha1_default = sha1;
|
|
26981
27030
|
}
|
|
26982
27031
|
});
|
|
@@ -28640,10 +28689,10 @@ var init_interceptor = __esm({
|
|
|
28640
28689
|
* @param awaitDecision when true, await AgentMoss instead of fire-and-forget.
|
|
28641
28690
|
*/
|
|
28642
28691
|
async _processResponse(flowId, respHeaders, respBody, awaitDecision) {
|
|
28643
|
-
const
|
|
28644
|
-
if (!
|
|
28692
|
+
const cached2 = this._requestCache.get(flowId);
|
|
28693
|
+
if (!cached2) return { events: [], deny: { deny: false } };
|
|
28645
28694
|
this._requestCache.delete(flowId);
|
|
28646
|
-
const { parser, meta, headers, url } =
|
|
28695
|
+
const { parser, meta, headers, url } = cached2;
|
|
28647
28696
|
const toolCalls = parser.parseResponse(url, respHeaders, respBody, meta);
|
|
28648
28697
|
if (toolCalls.length === 0) return { events: [], deny: { deny: false } };
|
|
28649
28698
|
const agentType = parser.detectAgentType(headers, meta);
|
|
@@ -29650,12 +29699,12 @@ var init_coordinator = __esm({
|
|
|
29650
29699
|
`[PhaseCoordinator][L1]: tool=${toolName} id=${toolCallId} session=${sessionId.slice(0, 8)} level=${this.level}`
|
|
29651
29700
|
);
|
|
29652
29701
|
if (this.decisionCache) {
|
|
29653
|
-
const
|
|
29654
|
-
if (
|
|
29702
|
+
const cached2 = this.decisionCache.get(sessionId, "", this._eventCommand(event));
|
|
29703
|
+
if (cached2) {
|
|
29655
29704
|
console.log(
|
|
29656
|
-
`[PhaseCoordinator]: decision cache HIT (tool=${toolName}) \u2192 ${String(
|
|
29705
|
+
`[PhaseCoordinator]: decision cache HIT (tool=${toolName}) \u2192 ${String(cached2.decision ?? "Allow")}`
|
|
29657
29706
|
);
|
|
29658
|
-
return String(
|
|
29707
|
+
return String(cached2.decision ?? "Allow");
|
|
29659
29708
|
}
|
|
29660
29709
|
}
|
|
29661
29710
|
if (this.whitelistEngine?.isWhitelisted(event)) {
|