@sema-agent/server 7.100.0 → 7.101.1

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 (107) hide show
  1. package/MIGRATION.md +22 -1
  2. package/README.md +12 -1
  3. package/README.zh-CN.md +9 -1
  4. package/USAGE.md +80 -9
  5. package/dist/approval-card.d.ts +24 -12
  6. package/dist/approval-card.js +4 -3
  7. package/dist/approval-policy-settlement.d.ts +31 -0
  8. package/dist/approval-policy-settlement.js +16 -0
  9. package/dist/approval-reconciler.d.ts +8 -1
  10. package/dist/approval-reconciler.js +5 -4
  11. package/dist/boot/config-center.js +86 -20
  12. package/dist/boot/execution-env.js +20 -2
  13. package/dist/boot/parked-revive-gate.js +1 -0
  14. package/dist/boot/reapers.js +1 -0
  15. package/dist/boot/resolve-spec.js +25 -8
  16. package/dist/boot/runner-deps.js +9 -3
  17. package/dist/boot/stage-02-registry-pull.js +9 -0
  18. package/dist/boot/stage-10-http-server.js +2 -0
  19. package/dist/boot/stores.js +4 -0
  20. package/dist/config-catalog.js +5 -3
  21. package/dist/config-center/apply-effective.d.ts +25 -0
  22. package/dist/config-center/apply-effective.js +144 -69
  23. package/dist/config-center/apply-ledger.d.ts +12 -2
  24. package/dist/config-center/apply-ledger.js +4 -1
  25. package/dist/config-center/facade.d.ts +1 -1
  26. package/dist/config-center/facade.js +1 -1
  27. package/dist/config-center/http-client.d.ts +4 -1
  28. package/dist/config-center/http-client.js +15 -10
  29. package/dist/config-center/read-warnings.d.ts +115 -6
  30. package/dist/config-center/read-warnings.js +115 -5
  31. package/dist/config-center/types.d.ts +6 -0
  32. package/dist/config-invariants.d.ts +2 -2
  33. package/dist/config-invariants.js +15 -0
  34. package/dist/config-provider.d.ts +4 -0
  35. package/dist/config-provider.js +64 -9
  36. package/dist/config-types.d.ts +37 -8
  37. package/dist/config.js +87 -22
  38. package/dist/deployment-governance.d.ts +45 -12
  39. package/dist/deployment-governance.js +37 -9
  40. package/dist/env-name-allowlist-knobs.d.ts +37 -0
  41. package/dist/env-name-allowlist-knobs.js +24 -0
  42. package/dist/fleet/fleet-bus.d.ts +30 -4
  43. package/dist/fleet/fleet-bus.js +20 -4
  44. package/dist/fleet/fleet-reconciler.d.ts +29 -6
  45. package/dist/fleet/fleet-reconciler.js +109 -79
  46. package/dist/fleet-client.d.ts +2 -1
  47. package/dist/hooks/hook-llm.js +13 -4
  48. package/dist/host-lsp-manager.d.ts +14 -2
  49. package/dist/host-lsp-manager.js +7 -6
  50. package/dist/http/admission.js +22 -7
  51. package/dist/http/memory-store-refusal-reply.d.ts +24 -0
  52. package/dist/http/memory-store-refusal-reply.js +10 -0
  53. package/dist/http/routes/approvals-assistant.js +1 -0
  54. package/dist/http/routes/capabilities.js +3 -3
  55. package/dist/http/routes/memory-bundle.js +3 -0
  56. package/dist/http/routes/memory-compliance.js +3 -5
  57. package/dist/http/routes/memory-origin.js +3 -5
  58. package/dist/http/routes/sessions.js +7 -6
  59. package/dist/http/routes/side-query.js +10 -4
  60. package/dist/instruction-source-notice.d.ts +97 -0
  61. package/dist/instruction-source-notice.js +78 -0
  62. package/dist/memory-layer-legacy-lock.d.ts +14 -0
  63. package/dist/memory-layer-legacy-lock.js +74 -0
  64. package/dist/memory-operator-faces.js +1 -17
  65. package/dist/memory-store-refusal.d.ts +37 -0
  66. package/dist/memory-store-refusal.js +14 -0
  67. package/dist/model-entry-refusal.d.ts +130 -0
  68. package/dist/model-entry-refusal.js +157 -0
  69. package/dist/model-provider.d.ts +9 -3
  70. package/dist/model-route-endpoint.d.ts +1 -1
  71. package/dist/model-select.d.ts +49 -4
  72. package/dist/model-select.js +48 -17
  73. package/dist/observability/fail-open.d.ts +13 -1
  74. package/dist/observability/fail-open.js +13 -1
  75. package/dist/observability/metrics.js +1 -0
  76. package/dist/observability/secret-env-scrub.d.ts +27 -4
  77. package/dist/observability/secret-env-scrub.js +22 -7
  78. package/dist/plugins/caching-session-store.d.ts +6 -0
  79. package/dist/plugins/caching-session-store.js +6 -0
  80. package/dist/plugins/local-session-store.d.ts +20 -25
  81. package/dist/plugins/local-session-store.js +111 -64
  82. package/dist/plugins/pg-session-storage.d.ts +7 -0
  83. package/dist/plugins/pg-session-storage.js +19 -0
  84. package/dist/plugins/remote-env-host.d.ts +3 -1
  85. package/dist/plugins/remote-env-host.js +3 -6
  86. package/dist/plugins/tidb-pool.js +5 -0
  87. package/dist/plugins/tidb-session-store.d.ts +13 -0
  88. package/dist/plugins/tidb-session-store.js +14 -0
  89. package/dist/plugins/web-search.d.ts +2 -1
  90. package/dist/plugins/web-search.js +43 -24
  91. package/dist/project-memory.d.ts +10 -0
  92. package/dist/project-memory.js +28 -14
  93. package/dist/run-local.d.ts +17 -15
  94. package/dist/run-local.js +115 -15
  95. package/dist/sealed-key.d.ts +5 -2
  96. package/dist/server-secret-env.d.ts +23 -1
  97. package/dist/server-secret-env.js +9 -0
  98. package/dist/tool-approval.d.ts +74 -31
  99. package/dist/tool-approval.js +102 -49
  100. package/dist/trace/core-keyset-guard.d.ts +27 -5
  101. package/dist/trace/engine-notice-wire.d.ts +27 -1
  102. package/dist/trace/engine-notice-wire.js +8 -0
  103. package/dist/trace/wire-projection-faces.d.ts +2 -2
  104. package/dist/trace/wire-projection-faces.js +2 -2
  105. package/package.json +2 -2
  106. package/dist/memory-layer-preflight.d.ts +0 -46
  107. package/dist/memory-layer-preflight.js +0 -121
@@ -161,14 +161,14 @@ export declare const WIRE_PROJECTION_FACES: {
161
161
  readonly wiring_manifest_tenant: {
162
162
  readonly projector: "wiringManifestEventData";
163
163
  readonly coreType: `WiringManifest & ${string}`;
164
- readonly excluded: readonly ["governance", "configFingerprint", "autoConsolidation", "readDeny", "peerPresence"];
164
+ readonly excluded: readonly ["governance", "configFingerprint", "autoConsolidation", "readDeny", "peerPresence", "fileHistory"];
165
165
  readonly unwrapped: readonly ["manifest"];
166
166
  readonly minted: readonly [];
167
167
  };
168
168
  readonly wiring_manifest_operator: {
169
169
  readonly projector: "wiringManifestOperatorEventData";
170
170
  readonly coreType: `WiringManifest & ${string}`;
171
- readonly excluded: readonly ["peerPresence"];
171
+ readonly excluded: readonly ["peerPresence", "fileHistory"];
172
172
  readonly unwrapped: readonly ["manifest"];
173
173
  readonly minted: readonly [];
174
174
  };
@@ -36,14 +36,14 @@ export const WIRE_PROJECTION_FACES = {
36
36
  wiring_manifest_tenant: {
37
37
  projector: "wiringManifestEventData",
38
38
  coreType: `WiringManifest & ${arm("wiring_manifest")}`,
39
- excluded: ["governance", "configFingerprint", "autoConsolidation", "readDeny", "peerPresence"],
39
+ excluded: ["governance", "configFingerprint", "autoConsolidation", "readDeny", "peerPresence", "fileHistory"],
40
40
  unwrapped: ["manifest"],
41
41
  minted: [],
42
42
  },
43
43
  wiring_manifest_operator: {
44
44
  projector: "wiringManifestOperatorEventData",
45
45
  coreType: `WiringManifest & ${arm("wiring_manifest")}`,
46
- excluded: ["peerPresence"],
46
+ excluded: ["peerPresence", "fileHistory"],
47
47
  unwrapped: ["manifest"],
48
48
  minted: [],
49
49
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sema-agent/server",
3
- "version": "7.100.0",
3
+ "version": "7.101.1",
4
4
  "description": "Sema Server — the server/API implementation layer for Sema, wiring core, registry, model providers, and cloud agent execution. Built on @sema-agent/core.",
5
5
  "type": "module",
6
6
  "license": "BUSL-1.1",
@@ -61,7 +61,7 @@
61
61
  "build:binary:run-local:darwin-arm64": "bun build --compile --target=bun-darwin-arm64 src/run-local.ts --outfile dist/run-local-darwin-arm64"
62
62
  },
63
63
  "dependencies": {
64
- "@sema-agent/core": "7.30.1",
64
+ "@sema-agent/core": "7.31.1",
65
65
  "@sema-agent/settings-schema": "6.0.0",
66
66
  "e2b": "^2.28.0",
67
67
  "libsodium-wrappers": "^0.8.4",
@@ -1,46 +0,0 @@
1
- /** 一只挡路的目录。`mode` = 权限位的四位八进制(如 `"0555"`)。 */
2
- export interface UnwritableLayerDir {
3
- readonly dir: string;
4
- readonly mode: string;
5
- }
6
- /**
7
- * 挂载面整棵树里挡路的目录(排序后返回,空数组 = 放行)。判据见文件头「判定集合」,逐目录三步:
8
- * ① 缺**搜索位**(X_OK)⇒ 挡路、不下钻 —— 经过它的任何查找都撞 EACCES(不存在的删除目标也一样,`force` 只吞
9
- * ENOENT),里面空不空都一样(codex 验修轮 V2:0400 / 0600 的空目录 + 账本仍绑定 ⇒ journal 卡盘);
10
- * ② 只缺**写位**(W_OK)⇒ 装着任何非目录项(文件 / 软链)或列不出内容 ⇒ 挡路;空的、只装子目录的不挡
11
- * (core 锁出来的 0555 有 x,「空的锁住 local 不拒」即此臂);
12
- * ③ 下钻:子目录照走;**指向挂载面内目录的软链也顺着走**(codex 验修轮 V1:删除路径可以穿过它),按目标的 `dev:ino` 去重防环;
13
- * 目标在挂载面外 ⇒ 不下钻、抛 {@link MemoryLayerSymlinkEscapeError}(NP-4)。
14
- *
15
- * 挂载面本身不存在 ⇒ 空(店还没建出来,没有可删的东西)。可写可搜索却列不出内容的目录、判不了的软链 ⇒ 抛原错误
16
- * (判不了子树 ⇒ 不放行;不借本码 —— 出路不是 `chmod u+w`)。
17
- */
18
- export declare function unwritableLayerDirs(mountRoot: string): UnwritableLayerDir[];
19
- /**
20
- * NP-4 —— 挂载面里一条指向**树外**目录的软链:预检判不了(树外那棵子树里会不会删到、删不删得掉,本层不下钻去猜),
21
- * 按 P 类 fail-closed 响亮拒 —— 与 ELOOP / EACCES 那一臂同形(原样抛 ⇒ 路由的未分类 500 + `memory_*_failed` warn,
22
- * 文案只进日志)。刻意**不**是 {@link MemoryLayerUnwritableError}:那一码的出路是 `chmod u+w <dir>`,对树外目录开这句出路
23
- * 等于教运维改系统目录的权限位。出路 = 把这条软链移出记忆层(日志点名软链与目标)。没有 `code` 字段:它不是 wire 码。
24
- */
25
- export declare class MemoryLayerSymlinkEscapeError extends Error {
26
- readonly link: string;
27
- readonly target: string;
28
- constructor(link: string, target: string);
29
- }
30
- /**
31
- * 预检拒绝(带结构字段的错误值)。路由按 `instanceof` 判别(不嗅文案、不裸 as-cast);409 文案写在**路由**的
32
- * 内联模板里(文案冻结门只看得见路由站点),本类只供两串排好版的插值。
33
- */
34
- export declare class MemoryLayerUnwritableError extends Error {
35
- readonly dirs: readonly UnwritableLayerDir[];
36
- readonly code = "memory.layer_unwritable";
37
- /** 409 文案的「哪些目录」插值:`"<dir>" (mode 0555), …`,超过上限只报余数。 */
38
- readonly dirList: string;
39
- /** 409 文案的出路插值:`chmod u+w` 的参数串 —— POSIX 单引号转义(照抄进 shell 不执行、不展开;codex R1-F3:
40
- * JSON 双引号挡不住 `$()` / 反引号 / `$VAR`)。目录清单那一串用 JSON 引号只作展示。 */
41
- readonly chmodTargets: string;
42
- constructor(dirs: readonly UnwritableLayerDir[]);
43
- }
44
- /** 两个 seam 的唯一入口:挡路 ⇒ 带码拒绝;放行 ⇒ `undefined`。 */
45
- export declare function memoryLayerWriteRefusal(mountRoot: string): MemoryLayerUnwritableError | undefined;
46
- //# sourceMappingURL=memory-layer-preflight.d.ts.map
@@ -1,121 +0,0 @@
1
- import { accessSync, constants as fsConstants, readdirSync, realpathSync, statSync } from "node:fs";
2
- import { isAbsolute, join, relative, sep } from "node:path";
3
- const NAMED_DIRS_MAX = 8;
4
- function errnoOf(err) {
5
- return err.code;
6
- }
7
- function accessState(dir, bit) {
8
- try {
9
- accessSync(dir, bit);
10
- return "granted";
11
- }
12
- catch (err) {
13
- return errnoOf(err) === "ENOENT" ? "gone" : "denied";
14
- }
15
- }
16
- function symlinkTarget(path) {
17
- let st;
18
- try {
19
- st = statSync(path);
20
- }
21
- catch (err) {
22
- if (errnoOf(err) === "ENOENT")
23
- return "dangling";
24
- throw err;
25
- }
26
- return st.isDirectory() ? "directory" : "other";
27
- }
28
- export function unwritableLayerDirs(mountRoot) {
29
- const out = [];
30
- const seen = new Set();
31
- const stack = [mountRoot];
32
- let mountReal;
33
- const mountRealOnce = () => (mountReal ??= realpathSync(mountRoot));
34
- for (let dir = stack.pop(); dir !== undefined; dir = stack.pop()) {
35
- const search = accessState(dir, fsConstants.X_OK);
36
- if (search === "gone")
37
- continue;
38
- if (search === "denied") {
39
- out.push(...blocker(dir));
40
- continue;
41
- }
42
- const id = statSync(dir, { throwIfNoEntry: false });
43
- if (id === undefined)
44
- continue;
45
- const key = `${id.dev}:${id.ino}`;
46
- if (seen.has(key))
47
- continue;
48
- seen.add(key);
49
- const write = accessState(dir, fsConstants.W_OK);
50
- if (write === "gone")
51
- continue;
52
- let children;
53
- try {
54
- children = readdirSync(dir, { withFileTypes: true });
55
- }
56
- catch (err) {
57
- if (errnoOf(err) === "ENOENT")
58
- continue;
59
- if (write === "granted")
60
- throw err;
61
- out.push(...blocker(dir));
62
- continue;
63
- }
64
- if (write === "denied" && children.some((c) => !c.isDirectory()))
65
- out.push(...blocker(dir));
66
- for (const c of children) {
67
- const child = join(dir, c.name);
68
- if (c.isDirectory())
69
- stack.push(child);
70
- else if (c.isSymbolicLink() && symlinkTarget(child) === "directory") {
71
- assertInsideMount(child, mountRealOnce());
72
- stack.push(child);
73
- }
74
- }
75
- }
76
- return out.sort((a, b) => (a.dir < b.dir ? -1 : a.dir > b.dir ? 1 : 0));
77
- }
78
- function assertInsideMount(link, mountReal) {
79
- const target = realpathSync(link);
80
- const rel = relative(mountReal, target);
81
- if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel))
82
- throw new MemoryLayerSymlinkEscapeError(link, target);
83
- }
84
- export class MemoryLayerSymlinkEscapeError extends Error {
85
- link;
86
- target;
87
- constructor(link, target) {
88
- super(`memory layer preflight cannot judge the mount: ${JSON.stringify(link)} is a symlink to ${JSON.stringify(target)}, outside the memory mount — not followed; move the symlink out of the memory layer and retry`);
89
- this.link = link;
90
- this.target = target;
91
- this.name = "MemoryLayerSymlinkEscapeError";
92
- }
93
- }
94
- function blocker(dir) {
95
- const st = statSync(dir, { throwIfNoEntry: false });
96
- return st === undefined ? [] : [{ dir, mode: (st.mode & 0o7777).toString(8).padStart(4, "0") }];
97
- }
98
- function shellQuote(s) {
99
- return `'${s.replace(/'/g, "'\\''")}'`;
100
- }
101
- export class MemoryLayerUnwritableError extends Error {
102
- dirs;
103
- code = "memory.layer_unwritable";
104
- dirList;
105
- chmodTargets;
106
- constructor(dirs) {
107
- const named = dirs.slice(0, NAMED_DIRS_MAX);
108
- const rest = dirs.length - named.length;
109
- const dirList = named.map((d) => `${JSON.stringify(d.dir)} (mode ${d.mode})`).join(", ") + (rest > 0 ? `, and ${rest} more` : "");
110
- super(`memory layer directories are not writable on disk: ${dirList}`);
111
- this.dirs = dirs;
112
- this.name = "MemoryLayerUnwritableError";
113
- this.dirList = dirList;
114
- this.chmodTargets = named.map((d) => shellQuote(d.dir)).join(" ");
115
- }
116
- }
117
- export function memoryLayerWriteRefusal(mountRoot) {
118
- const dirs = unwritableLayerDirs(mountRoot);
119
- return dirs.length > 0 ? new MemoryLayerUnwritableError(dirs) : undefined;
120
- }
121
- //# sourceMappingURL=memory-layer-preflight.js.map