@kenhkl/agent-moss 0.17.33 → 0.17.34

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.
Files changed (3) hide show
  1. package/dist/cli.js +36 -10
  2. package/dist/server.js +40 -17
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -97,6 +97,13 @@ function getTokenStatsPath() {
97
97
  }
98
98
  return join(getDataRoot(), "agent_moss_token_stats.json");
99
99
  }
100
+ function getInstanceDir() {
101
+ const instance = getInstance();
102
+ return instance ? join(getDataRoot(), instance) : getDataRoot();
103
+ }
104
+ function getPortFilePath() {
105
+ return join(getInstanceDir(), "agent_moss_server.port.json");
106
+ }
100
107
  var ENV_DATA_ROOT, ENV_INSTANCE, DEFAULT_DATA_ROOT, ENV_RULES_ROOT, ID_MAX_LEN, ID_PATTERN;
101
108
  var init_paths = __esm({
102
109
  "src/infra/paths.ts"() {
@@ -12504,9 +12511,24 @@ import * as os3 from "os";
12504
12511
  import * as path6 from "path";
12505
12512
  import { createHash as createHash4 } from "crypto";
12506
12513
  function defaultStateDbPath() {
12507
- const dir = process.env.AGENT_MOSS_STATE_DIR || path6.join(os3.homedir(), ".agentmoss");
12514
+ const base = process.env.AGENT_MOSS_STATE_DIR || path6.join(os3.homedir(), ".agentmoss");
12515
+ const instance = (process.env.AGENT_MOSS_INSTANCE || "").trim().replace(/^[/\\]+|[/\\]+$/g, "");
12516
+ const dir = instance ? path6.join(base, instance) : base;
12508
12517
  const tag = createHash4("sha1").update("agentmoss-stateful").digest("hex").slice(0, 8);
12509
- return path6.join(dir, `stateful_chains_${tag}.json`);
12518
+ const target = path6.join(dir, `stateful_chains_${tag}.json`);
12519
+ if (instance) {
12520
+ const legacy = path6.join(base, `stateful_chains_${tag}.json`);
12521
+ if (!fs5.existsSync(target) && fs5.existsSync(legacy)) {
12522
+ try {
12523
+ fs5.mkdirSync(dir, { recursive: true });
12524
+ fs5.copyFileSync(legacy, target);
12525
+ console.warn(`[AgentMoss] \u94FE\u72B6\u6001\u6587\u4EF6\u6309 instance \u9694\u79BB\uFF1A\u5DF2\u4ECE\u65E7\u5171\u4EAB\u6587\u4EF6\u590D\u5236\u5230 ${target}`);
12526
+ } catch (err) {
12527
+ console.warn("[AgentMoss] \u8FC1\u79FB\u94FE\u72B6\u6001\u6587\u4EF6\u5931\u8D25\uFF08\u5C06\u4F7F\u7528\u65B0\u7A7A\u6587\u4EF6\uFF09:", err);
12528
+ }
12529
+ }
12530
+ }
12531
+ return target;
12510
12532
  }
12511
12533
  function registerExitFlush(store) {
12512
12534
  if (_exitHookRegistered) return;
@@ -15152,8 +15174,8 @@ import { Hono as Hono2 } from "hono";
15152
15174
  import { cors } from "hono/cors";
15153
15175
  import { logger } from "hono/logger";
15154
15176
  import net from "net";
15155
- import { existsSync as existsSync21, writeFileSync as writeFileSync7, renameSync as renameSync3, mkdirSync as mkdirSync9 } from "fs";
15156
- import { dirname as dirname15, join as join22 } from "path";
15177
+ import { existsSync as existsSync21, writeFileSync as writeFileSync7, renameSync as renameSync3, mkdirSync as mkdirSync10 } from "fs";
15178
+ import { dirname as dirname15 } from "path";
15157
15179
  function logDeploymentSelfCheck() {
15158
15180
  try {
15159
15181
  const mode = getRulesMode();
@@ -15396,11 +15418,14 @@ async function warmUpEngine() {
15396
15418
  }
15397
15419
  function writePortFile(port) {
15398
15420
  try {
15399
- const path8 = join22(getDataRoot(), "agent_moss_server.port.json");
15400
- mkdirSync9(dirname15(path8), { recursive: true });
15421
+ const path8 = getPortFilePath();
15422
+ mkdirSync10(dirname15(path8), { recursive: true });
15401
15423
  const payload = JSON.stringify({
15402
15424
  port,
15403
15425
  pid: process.pid,
15426
+ // instance/version 供调用方校验,避免同机多实例端口文件串台
15427
+ instance: getInstance(),
15428
+ version,
15404
15429
  started_at: (/* @__PURE__ */ new Date()).toISOString()
15405
15430
  });
15406
15431
  const tmp = `${path8}.tmp`;
@@ -15447,12 +15472,12 @@ async function startUnixSocketServer(socketPath = "/var/run/agent_moss/agent_mos
15447
15472
  },
15448
15473
  serve: async () => {
15449
15474
  failFastOnAuthError();
15450
- const { mkdirSync: mkdirSync11, existsSync: existsSync23, unlinkSync: unlinkSync6 } = await import("fs");
15475
+ const { mkdirSync: mkdirSync12, existsSync: existsSync23, unlinkSync: unlinkSync6 } = await import("fs");
15451
15476
  const { dirname: dirname17 } = await import("path");
15452
15477
  const dir = dirname17(socketPath);
15453
15478
  if (dir) {
15454
15479
  try {
15455
- mkdirSync11(dir, { recursive: true });
15480
+ mkdirSync12(dir, { recursive: true });
15456
15481
  } catch {
15457
15482
  }
15458
15483
  }
@@ -15513,6 +15538,7 @@ var init_server = __esm({
15513
15538
  init_rules_contract();
15514
15539
  init_security_policy();
15515
15540
  init_paths();
15541
+ init_package_json();
15516
15542
  init_routes();
15517
15543
  init_console();
15518
15544
  init_runtime_config();
@@ -15585,11 +15611,11 @@ __export(rules_tools_exports, {
15585
15611
  rulesStatusText: () => rulesStatusText,
15586
15612
  templateSourceDir: () => templateSourceDir
15587
15613
  });
15588
- import { existsSync as existsSync22, mkdirSync as mkdirSync10, readdirSync as readdirSync7, readFileSync as readFileSync21, writeFileSync as writeFileSync8 } from "fs";
15614
+ import { existsSync as existsSync22, mkdirSync as mkdirSync11, readdirSync as readdirSync7, readFileSync as readFileSync21, writeFileSync as writeFileSync8 } from "fs";
15589
15615
  import { dirname as dirname16, join as join23 } from "path";
15590
15616
  import { fileURLToPath as fileURLToPath12 } from "url";
15591
15617
  function initRulesDir(targetDir, opts = {}) {
15592
- mkdirSync10(targetDir, { recursive: true });
15618
+ mkdirSync11(targetDir, { recursive: true });
15593
15619
  const written = [];
15594
15620
  const extraPath = join23(targetDir, EXTRA_FILENAME);
15595
15621
  if (opts.force || !existsSync22(extraPath)) {
package/dist/server.js CHANGED
@@ -96,6 +96,13 @@ function getTokenStatsPath() {
96
96
  }
97
97
  return join(getDataRoot(), "agent_moss_token_stats.json");
98
98
  }
99
+ function getInstanceDir() {
100
+ const instance = getInstance();
101
+ return instance ? join(getDataRoot(), instance) : getDataRoot();
102
+ }
103
+ function getPortFilePath() {
104
+ return join(getInstanceDir(), "agent_moss_server.port.json");
105
+ }
99
106
  var ENV_DATA_ROOT, ENV_INSTANCE, DEFAULT_DATA_ROOT, ENV_RULES_ROOT, ID_MAX_LEN, ID_PATTERN;
100
107
  var init_paths = __esm({
101
108
  "src/infra/paths.ts"() {
@@ -11915,9 +11922,24 @@ import * as os3 from "os";
11915
11922
  import * as path6 from "path";
11916
11923
  import { createHash as createHash4 } from "crypto";
11917
11924
  function defaultStateDbPath() {
11918
- const dir = process.env.AGENT_MOSS_STATE_DIR || path6.join(os3.homedir(), ".agentmoss");
11925
+ const base = process.env.AGENT_MOSS_STATE_DIR || path6.join(os3.homedir(), ".agentmoss");
11926
+ const instance = (process.env.AGENT_MOSS_INSTANCE || "").trim().replace(/^[/\\]+|[/\\]+$/g, "");
11927
+ const dir = instance ? path6.join(base, instance) : base;
11919
11928
  const tag = createHash4("sha1").update("agentmoss-stateful").digest("hex").slice(0, 8);
11920
- return path6.join(dir, `stateful_chains_${tag}.json`);
11929
+ const target = path6.join(dir, `stateful_chains_${tag}.json`);
11930
+ if (instance) {
11931
+ const legacy = path6.join(base, `stateful_chains_${tag}.json`);
11932
+ if (!fs5.existsSync(target) && fs5.existsSync(legacy)) {
11933
+ try {
11934
+ fs5.mkdirSync(dir, { recursive: true });
11935
+ fs5.copyFileSync(legacy, target);
11936
+ console.warn(`[AgentMoss] \u94FE\u72B6\u6001\u6587\u4EF6\u6309 instance \u9694\u79BB\uFF1A\u5DF2\u4ECE\u65E7\u5171\u4EAB\u6587\u4EF6\u590D\u5236\u5230 ${target}`);
11937
+ } catch (err) {
11938
+ console.warn("[AgentMoss] \u8FC1\u79FB\u94FE\u72B6\u6001\u6587\u4EF6\u5931\u8D25\uFF08\u5C06\u4F7F\u7528\u65B0\u7A7A\u6587\u4EF6\uFF09:", err);
11939
+ }
11940
+ }
11941
+ }
11942
+ return target;
11921
11943
  }
11922
11944
  function registerExitFlush(store) {
11923
11945
  if (_exitHookRegistered) return;
@@ -12802,17 +12824,8 @@ init_paths();
12802
12824
  import { cors } from "hono/cors";
12803
12825
  import { logger } from "hono/logger";
12804
12826
  import net from "net";
12805
- import { existsSync as existsSync21, writeFileSync as writeFileSync6, renameSync as renameSync3, mkdirSync as mkdirSync8 } from "fs";
12806
- import { dirname as dirname15, join as join21 } from "path";
12807
-
12808
- // src/routes.ts
12809
- init_esm_shims();
12810
- init_security_policy();
12811
- import { randomBytes as randomBytes2 } from "crypto";
12812
-
12813
- // src/models.ts
12814
- init_esm_shims();
12815
- import { z } from "zod";
12827
+ import { existsSync as existsSync21, writeFileSync as writeFileSync6, renameSync as renameSync3, mkdirSync as mkdirSync9 } from "fs";
12828
+ import { dirname as dirname15 } from "path";
12816
12829
 
12817
12830
  // src/package-json.ts
12818
12831
  init_esm_shims();
@@ -12821,7 +12834,14 @@ var require2 = createRequire(import.meta.url);
12821
12834
  var pkg = require2("../package.json");
12822
12835
  var version = pkg.version;
12823
12836
 
12837
+ // src/routes.ts
12838
+ init_esm_shims();
12839
+ init_security_policy();
12840
+ import { randomBytes as randomBytes2 } from "crypto";
12841
+
12824
12842
  // src/models.ts
12843
+ init_esm_shims();
12844
+ import { z } from "zod";
12825
12845
  var isNonEmptyNoControl = (v) => v.trim().length > 0 && ![...v].some((c) => {
12826
12846
  const n = c.codePointAt(0) ?? 0;
12827
12847
  return n < 32 || n >= 127 && n <= 159;
@@ -15061,11 +15081,14 @@ async function warmUpEngine() {
15061
15081
  }
15062
15082
  function writePortFile(port) {
15063
15083
  try {
15064
- const path8 = join21(getDataRoot(), "agent_moss_server.port.json");
15065
- mkdirSync8(dirname15(path8), { recursive: true });
15084
+ const path8 = getPortFilePath();
15085
+ mkdirSync9(dirname15(path8), { recursive: true });
15066
15086
  const payload = JSON.stringify({
15067
15087
  port,
15068
15088
  pid: process.pid,
15089
+ // instance/version 供调用方校验,避免同机多实例端口文件串台
15090
+ instance: getInstance(),
15091
+ version,
15069
15092
  started_at: (/* @__PURE__ */ new Date()).toISOString()
15070
15093
  });
15071
15094
  const tmp = `${path8}.tmp`;
@@ -15112,12 +15135,12 @@ async function startUnixSocketServer(socketPath = "/var/run/agent_moss/agent_mos
15112
15135
  },
15113
15136
  serve: async () => {
15114
15137
  failFastOnAuthError();
15115
- const { mkdirSync: mkdirSync9, existsSync: existsSync22, unlinkSync: unlinkSync6 } = await import("fs");
15138
+ const { mkdirSync: mkdirSync10, existsSync: existsSync22, unlinkSync: unlinkSync6 } = await import("fs");
15116
15139
  const { dirname: dirname16 } = await import("path");
15117
15140
  const dir = dirname16(socketPath);
15118
15141
  if (dir) {
15119
15142
  try {
15120
- mkdirSync9(dir, { recursive: true });
15143
+ mkdirSync10(dir, { recursive: true });
15121
15144
  } catch {
15122
15145
  }
15123
15146
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kenhkl/agent-moss",
3
- "version": "0.17.33",
3
+ "version": "0.17.34",
4
4
  "description": "Multi-layer security analysis engine for AI agents (TypeScript)",
5
5
  "type": "module",
6
6
  "main": "dist/server.js",