@kenhkl/agent-gate 0.9.10 → 0.9.12

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 CHANGED
@@ -483,8 +483,7 @@ function hardenDbFiles(dbPath) {
483
483
  function mossTokenPath() {
484
484
  const root = env("AGENT_MOSS_DATA_DIR");
485
485
  if (root) return (0, import_node_path.join)(root, "auth_token");
486
- const home = process.env.SUDO_USER && existsDir(`/home/${process.env.SUDO_USER}`) ? `/home/${process.env.SUDO_USER}` : (0, import_node_os.homedir)();
487
- return (0, import_node_path.join)(home, ".config", "agentmoss", "auth_token");
486
+ return (0, import_node_path.join)((0, import_node_os.homedir)(), ".config", "agentmoss", "auth_token");
488
487
  }
489
488
  function resolveMossToken(force = false) {
490
489
  const now = performance.now() / 1e3;
@@ -502,9 +501,13 @@ function resolveMossToken(force = false) {
502
501
  }
503
502
  }
504
503
  if (!tok) {
504
+ const tokenPath = mossTokenPath();
505
505
  try {
506
- tok = (0, import_node_fs.readFileSync)(mossTokenPath(), "utf-8").trim();
506
+ tok = (0, import_node_fs.readFileSync)(tokenPath, "utf-8").trim();
507
507
  } catch {
508
+ console.warn(
509
+ `[AgentGate] AgentMoss \u9274\u6743 token \u672A\u627E\u5230\uFF08\u5C1D\u8BD5\u8DEF\u5F84: ${tokenPath}\uFF09\uFF1B\u8DE8\u7528\u6237/\u8DE8\u673A\u90E8\u7F72\u8BF7\u7528 AGENT_GATE_MOSS_TOKEN \u6216 AGENT_MOSS_AUTH_TOKEN_FILE \u663E\u5F0F\u6307\u5B9A`
510
+ );
508
511
  tok = "";
509
512
  }
510
513
  }
@@ -1690,6 +1693,8 @@ __export(moss_client_exports, {
1690
1693
  callAgentMoss: () => callAgentMoss,
1691
1694
  callAgentMossReview: () => callAgentMossReview,
1692
1695
  fetchMossHealth: () => fetchMossHealth,
1696
+ logDegraded: () => logDegraded,
1697
+ resetDegradedThrottleForTests: () => resetDegradedThrottleForTests,
1693
1698
  setMossUrl: () => setMossUrl
1694
1699
  });
1695
1700
  function authHeaders() {
@@ -1698,6 +1703,19 @@ function authHeaders() {
1698
1703
  if (tok) h["Authorization"] = `Bearer ${tok}`;
1699
1704
  return h;
1700
1705
  }
1706
+ function logDegraded(notes) {
1707
+ const now = Date.now();
1708
+ for (const note of notes) {
1709
+ const key = String(note).replace(/\d+/g, "#");
1710
+ const last = DEGRADED_LAST_LOGGED.get(key);
1711
+ if (last !== void 0 && now - last < DEGRADED_LOG_INTERVAL_MS) continue;
1712
+ DEGRADED_LAST_LOGGED.set(key, now);
1713
+ console.warn(`[AgentGate] AgentMoss \u80FD\u529B\u964D\u7EA7: ${note}`);
1714
+ }
1715
+ }
1716
+ function resetDegradedThrottleForTests() {
1717
+ DEGRADED_LAST_LOGGED.clear();
1718
+ }
1701
1719
  function setMossUrl(url) {
1702
1720
  mossUrl = url;
1703
1721
  }
@@ -1728,7 +1746,12 @@ async function callAgentMoss(request) {
1728
1746
  console.error(`[AgentGate] AgentMoss HTTP ${resp.status}: ${resp.statusText}`);
1729
1747
  return failClosedResponse(`AgentMoss returned ${resp.status}`);
1730
1748
  }
1731
- return await resp.json();
1749
+ const result = await resp.json();
1750
+ const degraded = result?.degraded ?? [];
1751
+ if (degraded.length) {
1752
+ logDegraded(degraded);
1753
+ }
1754
+ return result;
1732
1755
  } catch (err) {
1733
1756
  const errType = err?.type || "";
1734
1757
  const errMsg = String(err?.message || err);
@@ -1784,7 +1807,7 @@ function failClosedResponse(reason, riskType = "service_unavailable") {
1784
1807
  confidence: 100
1785
1808
  };
1786
1809
  }
1787
- var import_node_fetch, DEFAULT_MOSS_URL, mossUrl;
1810
+ var import_node_fetch, DEFAULT_MOSS_URL, DEGRADED_LAST_LOGGED, DEGRADED_LOG_INTERVAL_MS, mossUrl;
1788
1811
  var init_moss_client = __esm({
1789
1812
  "src/shared/moss-client.ts"() {
1790
1813
  "use strict";
@@ -1793,6 +1816,8 @@ var init_moss_client = __esm({
1793
1816
  init_multi_session();
1794
1817
  init_security();
1795
1818
  DEFAULT_MOSS_URL = "http://127.0.0.1:9090";
1819
+ DEGRADED_LAST_LOGGED = /* @__PURE__ */ new Map();
1820
+ DEGRADED_LOG_INTERVAL_MS = 3e5;
1796
1821
  mossUrl = process.env.AGENT_MOSS_URL || process.env.MOSS_URL || DEFAULT_MOSS_URL;
1797
1822
  }
1798
1823
  });
@@ -1803,7 +1828,7 @@ var init_version = __esm({
1803
1828
  "src/version.ts"() {
1804
1829
  "use strict";
1805
1830
  init_cjs_shims();
1806
- _version = true ? "0.9.10" : (() => {
1831
+ _version = true ? "0.9.12" : (() => {
1807
1832
  try {
1808
1833
  const require2 = createRequire(importMetaUrl);
1809
1834
  const pkg = require2("../package.json");
@@ -1882,6 +1907,11 @@ var init_models = __esm({
1882
1907
  violation_graph: import_zod.z.any().nullable().optional(),
1883
1908
  /** 命中的策略/性质描述(与 Python 版响应字段对齐) */
1884
1909
  policy: import_zod.z.string().default(""),
1910
+ /**
1911
+ * 能力降级/预警说明(2026-11):**透传**自 AgentMoss。空数组 = 全部检测层
1912
+ * 完整完成;非空 = 某层没跑全或即将失效,调用方应记录/展示/上报。
1913
+ */
1914
+ degraded: import_zod.z.array(import_zod.z.string()).default([]),
1885
1915
  /** 判定来源:agent_moss / cache(与 Python 版对齐) */
1886
1916
  source: import_zod.z.string().default("agent_moss"),
1887
1917
  oversize: import_zod.z.boolean().optional().describe("\u672C\u5730\u5B58\u50A8\u662F\u5426\u8D85\u8FC7\u6E05\u7406\u9608\u503C\uFF08agg \u7528\uFF09"),
@@ -2870,6 +2900,8 @@ async function analyzeRoute(c) {
2870
2900
  violation_graph: mossResult.violation_graph ?? null,
2871
2901
  // 与 Python 版响应字段对齐(policy / source)
2872
2902
  policy: mossResult.policy ?? "",
2903
+ // 能力降级/预警:**透传**给调用方(客户的 agent),不要吞掉
2904
+ degraded: mossResult.degraded ?? [],
2873
2905
  source: "agent_moss",
2874
2906
  ...storageOversizeInfo(),
2875
2907
  collected_context: {
package/dist/v1/server.js CHANGED
@@ -478,8 +478,7 @@ function hardenFilesEnabled() {
478
478
  function mossTokenPath() {
479
479
  const root = env("AGENT_MOSS_DATA_DIR");
480
480
  if (root) return (0, import_node_path.join)(root, "auth_token");
481
- const home = process.env.SUDO_USER && existsDir(`/home/${process.env.SUDO_USER}`) ? `/home/${process.env.SUDO_USER}` : (0, import_node_os.homedir)();
482
- return (0, import_node_path.join)(home, ".config", "agentmoss", "auth_token");
481
+ return (0, import_node_path.join)((0, import_node_os.homedir)(), ".config", "agentmoss", "auth_token");
483
482
  }
484
483
  function resolveMossToken(force = false) {
485
484
  const now = performance.now() / 1e3;
@@ -497,9 +496,13 @@ function resolveMossToken(force = false) {
497
496
  }
498
497
  }
499
498
  if (!tok) {
499
+ const tokenPath = mossTokenPath();
500
500
  try {
501
- tok = (0, import_node_fs.readFileSync)(mossTokenPath(), "utf-8").trim();
501
+ tok = (0, import_node_fs.readFileSync)(tokenPath, "utf-8").trim();
502
502
  } catch {
503
+ console.warn(
504
+ `[AgentGate] AgentMoss \u9274\u6743 token \u672A\u627E\u5230\uFF08\u5C1D\u8BD5\u8DEF\u5F84: ${tokenPath}\uFF09\uFF1B\u8DE8\u7528\u6237/\u8DE8\u673A\u90E8\u7F72\u8BF7\u7528 AGENT_GATE_MOSS_TOKEN \u6216 AGENT_MOSS_AUTH_TOKEN_FILE \u663E\u5F0F\u6307\u5B9A`
505
+ );
503
506
  tok = "";
504
507
  }
505
508
  }
@@ -580,6 +583,8 @@ __export(moss_client_exports, {
580
583
  callAgentMoss: () => callAgentMoss,
581
584
  callAgentMossReview: () => callAgentMossReview,
582
585
  fetchMossHealth: () => fetchMossHealth,
586
+ logDegraded: () => logDegraded,
587
+ resetDegradedThrottleForTests: () => resetDegradedThrottleForTests,
583
588
  setMossUrl: () => setMossUrl
584
589
  });
585
590
  function authHeaders() {
@@ -588,6 +593,19 @@ function authHeaders() {
588
593
  if (tok) h["Authorization"] = `Bearer ${tok}`;
589
594
  return h;
590
595
  }
596
+ function logDegraded(notes) {
597
+ const now = Date.now();
598
+ for (const note of notes) {
599
+ const key = String(note).replace(/\d+/g, "#");
600
+ const last = DEGRADED_LAST_LOGGED.get(key);
601
+ if (last !== void 0 && now - last < DEGRADED_LOG_INTERVAL_MS) continue;
602
+ DEGRADED_LAST_LOGGED.set(key, now);
603
+ console.warn(`[AgentGate] AgentMoss \u80FD\u529B\u964D\u7EA7: ${note}`);
604
+ }
605
+ }
606
+ function resetDegradedThrottleForTests() {
607
+ DEGRADED_LAST_LOGGED.clear();
608
+ }
591
609
  function setMossUrl(url) {
592
610
  mossUrl = url;
593
611
  }
@@ -618,7 +636,12 @@ async function callAgentMoss(request) {
618
636
  console.error(`[AgentGate] AgentMoss HTTP ${resp.status}: ${resp.statusText}`);
619
637
  return failClosedResponse(`AgentMoss returned ${resp.status}`);
620
638
  }
621
- return await resp.json();
639
+ const result = await resp.json();
640
+ const degraded = result?.degraded ?? [];
641
+ if (degraded.length) {
642
+ logDegraded(degraded);
643
+ }
644
+ return result;
622
645
  } catch (err) {
623
646
  const errType = err?.type || "";
624
647
  const errMsg = String(err?.message || err);
@@ -674,7 +697,7 @@ function failClosedResponse(reason, riskType = "service_unavailable") {
674
697
  confidence: 100
675
698
  };
676
699
  }
677
- var import_node_fetch, DEFAULT_MOSS_URL, mossUrl;
700
+ var import_node_fetch, DEFAULT_MOSS_URL, DEGRADED_LAST_LOGGED, DEGRADED_LOG_INTERVAL_MS, mossUrl;
678
701
  var init_moss_client = __esm({
679
702
  "src/shared/moss-client.ts"() {
680
703
  "use strict";
@@ -683,6 +706,8 @@ var init_moss_client = __esm({
683
706
  init_multi_session();
684
707
  init_security();
685
708
  DEFAULT_MOSS_URL = "http://127.0.0.1:9090";
709
+ DEGRADED_LAST_LOGGED = /* @__PURE__ */ new Map();
710
+ DEGRADED_LOG_INTERVAL_MS = 3e5;
686
711
  mossUrl = process.env.AGENT_MOSS_URL || process.env.MOSS_URL || DEFAULT_MOSS_URL;
687
712
  }
688
713
  });
@@ -2271,7 +2296,7 @@ var import_zod = require("zod");
2271
2296
 
2272
2297
  // src/version.ts
2273
2298
  init_cjs_shims();
2274
- var _version = true ? "0.9.10" : (() => {
2299
+ var _version = true ? "0.9.12" : (() => {
2275
2300
  try {
2276
2301
  const require2 = createRequire(importMetaUrl);
2277
2302
  const pkg = require2("../package.json");
@@ -2341,6 +2366,11 @@ var AgentGateResponseSchema = import_zod.z.object({
2341
2366
  violation_graph: import_zod.z.any().nullable().optional(),
2342
2367
  /** 命中的策略/性质描述(与 Python 版响应字段对齐) */
2343
2368
  policy: import_zod.z.string().default(""),
2369
+ /**
2370
+ * 能力降级/预警说明(2026-11):**透传**自 AgentMoss。空数组 = 全部检测层
2371
+ * 完整完成;非空 = 某层没跑全或即将失效,调用方应记录/展示/上报。
2372
+ */
2373
+ degraded: import_zod.z.array(import_zod.z.string()).default([]),
2344
2374
  /** 判定来源:agent_moss / cache(与 Python 版对齐) */
2345
2375
  source: import_zod.z.string().default("agent_moss"),
2346
2376
  oversize: import_zod.z.boolean().optional().describe("\u672C\u5730\u5B58\u50A8\u662F\u5426\u8D85\u8FC7\u6E05\u7406\u9608\u503C\uFF08agg \u7528\uFF09"),
@@ -2693,6 +2723,8 @@ async function analyzeRoute(c) {
2693
2723
  violation_graph: mossResult.violation_graph ?? null,
2694
2724
  // 与 Python 版响应字段对齐(policy / source)
2695
2725
  policy: mossResult.policy ?? "",
2726
+ // 能力降级/预警:**透传**给调用方(客户的 agent),不要吞掉
2727
+ degraded: mossResult.degraded ?? [],
2696
2728
  source: "agent_moss",
2697
2729
  ...storageOversizeInfo(),
2698
2730
  collected_context: {
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.10" : (() => {
53
+ _version = true ? "0.9.12" : (() => {
54
54
  try {
55
55
  const require2 = createRequire(importMetaUrl);
56
56
  const pkg = require2("../package.json");
@@ -505,8 +505,7 @@ function hardenDbFiles(dbPath) {
505
505
  function mossTokenPath() {
506
506
  const root = env("AGENT_MOSS_DATA_DIR");
507
507
  if (root) return (0, import_node_path.join)(root, "auth_token");
508
- const home = process.env.SUDO_USER && existsDir(`/home/${process.env.SUDO_USER}`) ? `/home/${process.env.SUDO_USER}` : (0, import_node_os.homedir)();
509
- return (0, import_node_path.join)(home, ".config", "agentmoss", "auth_token");
508
+ return (0, import_node_path.join)((0, import_node_os.homedir)(), ".config", "agentmoss", "auth_token");
510
509
  }
511
510
  function resolveMossToken(force = false) {
512
511
  const now = performance.now() / 1e3;
@@ -524,9 +523,13 @@ function resolveMossToken(force = false) {
524
523
  }
525
524
  }
526
525
  if (!tok) {
526
+ const tokenPath = mossTokenPath();
527
527
  try {
528
- tok = (0, import_node_fs.readFileSync)(mossTokenPath(), "utf-8").trim();
528
+ tok = (0, import_node_fs.readFileSync)(tokenPath, "utf-8").trim();
529
529
  } catch {
530
+ console.warn(
531
+ `[AgentGate] AgentMoss \u9274\u6743 token \u672A\u627E\u5230\uFF08\u5C1D\u8BD5\u8DEF\u5F84: ${tokenPath}\uFF09\uFF1B\u8DE8\u7528\u6237/\u8DE8\u673A\u90E8\u7F72\u8BF7\u7528 AGENT_GATE_MOSS_TOKEN \u6216 AGENT_MOSS_AUTH_TOKEN_FILE \u663E\u5F0F\u6307\u5B9A`
532
+ );
530
533
  tok = "";
531
534
  }
532
535
  }
@@ -1712,6 +1715,8 @@ __export(moss_client_exports, {
1712
1715
  callAgentMoss: () => callAgentMoss,
1713
1716
  callAgentMossReview: () => callAgentMossReview,
1714
1717
  fetchMossHealth: () => fetchMossHealth,
1718
+ logDegraded: () => logDegraded,
1719
+ resetDegradedThrottleForTests: () => resetDegradedThrottleForTests,
1715
1720
  setMossUrl: () => setMossUrl
1716
1721
  });
1717
1722
  function authHeaders() {
@@ -1720,6 +1725,19 @@ function authHeaders() {
1720
1725
  if (tok) h["Authorization"] = `Bearer ${tok}`;
1721
1726
  return h;
1722
1727
  }
1728
+ function logDegraded(notes) {
1729
+ const now = Date.now();
1730
+ for (const note of notes) {
1731
+ const key = String(note).replace(/\d+/g, "#");
1732
+ const last = DEGRADED_LAST_LOGGED.get(key);
1733
+ if (last !== void 0 && now - last < DEGRADED_LOG_INTERVAL_MS) continue;
1734
+ DEGRADED_LAST_LOGGED.set(key, now);
1735
+ console.warn(`[AgentGate] AgentMoss \u80FD\u529B\u964D\u7EA7: ${note}`);
1736
+ }
1737
+ }
1738
+ function resetDegradedThrottleForTests() {
1739
+ DEGRADED_LAST_LOGGED.clear();
1740
+ }
1723
1741
  function setMossUrl(url) {
1724
1742
  mossUrl = url;
1725
1743
  }
@@ -1750,7 +1768,12 @@ async function callAgentMoss(request3) {
1750
1768
  console.error(`[AgentGate] AgentMoss HTTP ${resp.status}: ${resp.statusText}`);
1751
1769
  return failClosedResponse(`AgentMoss returned ${resp.status}`);
1752
1770
  }
1753
- return await resp.json();
1771
+ const result = await resp.json();
1772
+ const degraded = result?.degraded ?? [];
1773
+ if (degraded.length) {
1774
+ logDegraded(degraded);
1775
+ }
1776
+ return result;
1754
1777
  } catch (err) {
1755
1778
  const errType = err?.type || "";
1756
1779
  const errMsg = String(err?.message || err);
@@ -1806,7 +1829,7 @@ function failClosedResponse(reason, riskType = "service_unavailable") {
1806
1829
  confidence: 100
1807
1830
  };
1808
1831
  }
1809
- var import_node_fetch, DEFAULT_MOSS_URL, mossUrl;
1832
+ var import_node_fetch, DEFAULT_MOSS_URL, DEGRADED_LAST_LOGGED, DEGRADED_LOG_INTERVAL_MS, mossUrl;
1810
1833
  var init_moss_client = __esm({
1811
1834
  "src/shared/moss-client.ts"() {
1812
1835
  "use strict";
@@ -1815,6 +1838,8 @@ var init_moss_client = __esm({
1815
1838
  init_multi_session();
1816
1839
  init_security();
1817
1840
  DEFAULT_MOSS_URL = "http://127.0.0.1:9090";
1841
+ DEGRADED_LAST_LOGGED = /* @__PURE__ */ new Map();
1842
+ DEGRADED_LOG_INTERVAL_MS = 3e5;
1818
1843
  mossUrl = process.env.AGENT_MOSS_URL || process.env.MOSS_URL || DEFAULT_MOSS_URL;
1819
1844
  }
1820
1845
  });
@@ -1885,6 +1910,11 @@ var init_models = __esm({
1885
1910
  violation_graph: import_zod.z.any().nullable().optional(),
1886
1911
  /** 命中的策略/性质描述(与 Python 版响应字段对齐) */
1887
1912
  policy: import_zod.z.string().default(""),
1913
+ /**
1914
+ * 能力降级/预警说明(2026-11):**透传**自 AgentMoss。空数组 = 全部检测层
1915
+ * 完整完成;非空 = 某层没跑全或即将失效,调用方应记录/展示/上报。
1916
+ */
1917
+ degraded: import_zod.z.array(import_zod.z.string()).default([]),
1888
1918
  /** 判定来源:agent_moss / cache(与 Python 版对齐) */
1889
1919
  source: import_zod.z.string().default("agent_moss"),
1890
1920
  oversize: import_zod.z.boolean().optional().describe("\u672C\u5730\u5B58\u50A8\u662F\u5426\u8D85\u8FC7\u6E05\u7406\u9608\u503C\uFF08agg \u7528\uFF09"),
@@ -2874,6 +2904,8 @@ async function analyzeRoute(c) {
2874
2904
  violation_graph: mossResult.violation_graph ?? null,
2875
2905
  // 与 Python 版响应字段对齐(policy / source)
2876
2906
  policy: mossResult.policy ?? "",
2907
+ // 能力降级/预警:**透传**给调用方(客户的 agent),不要吞掉
2908
+ degraded: mossResult.degraded ?? [],
2877
2909
  source: "agent_moss",
2878
2910
  ...storageOversizeInfo(),
2879
2911
  collected_context: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kenhkl/agent-gate",
3
- "version": "0.9.10",
3
+ "version": "0.9.12",
4
4
  "description": "AI Agent data collection & security analysis gateway (TypeScript)",
5
5
  "main": "dist/v1/server.js",
6
6
  "bin": {