@sema-agent/server 7.113.0 → 7.115.0
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/MIGRATION.md +109 -2
- package/USAGE.md +36 -3
- package/deploy/sema-up/cluster-up.sh +13 -1
- package/deploy/sema-up/kube-up.sh +13 -1
- package/deploy/sema-up/preflight.sh +13 -1
- package/deploy/sema-up/sema-up.sh +13 -1
- package/deploy/sema-up/smoke.sh +13 -1
- package/dist/adoption/wire.d.ts +0 -3
- package/dist/approval-card.d.ts +21 -24
- package/dist/approval-card.js +12 -0
- package/dist/approval.js +5 -2
- package/dist/boot/exit-boundary.d.ts +3 -2
- package/dist/boot/exit-boundary.js +3 -0
- package/dist/boot/memory-boundary.d.ts +2 -1
- package/dist/boot/memory-consolidation.d.ts +1 -1
- package/dist/boot/resolve-spec.js +6 -3
- package/dist/boot/shutdown.d.ts +19 -0
- package/dist/boot/shutdown.js +12 -1
- package/dist/capabilities/composite-members.d.ts +1 -0
- package/dist/capabilities/composite-members.js +1 -0
- package/dist/config-catalog.js +8 -6
- package/dist/config-center/apply-effective.js +11 -11
- package/dist/config-invariants.d.ts +27 -0
- package/dist/config-invariants.js +54 -39
- package/dist/config-provider.d.ts +16 -0
- package/dist/config-provider.js +11 -2
- package/dist/config-types.d.ts +24 -11
- package/dist/config-types.js +0 -1
- package/dist/config.d.ts +41 -34
- package/dist/config.js +78 -81
- package/dist/deployment-governance.d.ts +15 -4
- package/dist/deployment-governance.js +20 -2
- package/dist/env-facts.d.ts +3 -1
- package/dist/env-facts.js +5 -1
- package/dist/execution-lane-caps.d.ts +54 -30
- package/dist/execution-lane-caps.js +48 -20
- package/dist/fleet/fleet-bus.d.ts +1 -22
- package/dist/hooks/hook-runner.d.ts +112 -6
- package/dist/hooks/hook-runner.js +138 -32
- package/dist/hosted-posture.d.ts +2 -2
- package/dist/http/admission.js +9 -4
- package/dist/http/approval-sweeps.js +20 -0
- package/dist/http/checkpoint-ctx.d.ts +68 -0
- package/dist/http/checkpoint-ctx.js +36 -0
- package/dist/http/durable-run-leg.js +2 -1
- package/dist/http/resume-legs.js +9 -0
- package/dist/http/route-ctx.d.ts +7 -0
- package/dist/http/routes/a2a-serve.d.ts +1 -3
- package/dist/http/routes/a2a-serve.js +0 -2
- package/dist/http/routes/admin-memory-optout.d.ts +0 -2
- package/dist/http/routes/admin-memory-optout.js +0 -1
- package/dist/http/routes/capabilities.js +3 -2
- package/dist/http/routes/diagnostics.d.ts +5 -0
- package/dist/http/routes/diagnostics.js +2 -0
- package/dist/http/routes/sessions.js +1 -1
- package/dist/http/routes/tasks.js +3 -2
- package/dist/index.d.ts +1 -1
- package/dist/leader/wire.js +2 -1
- package/dist/local-data-root.d.ts +1 -1
- package/dist/mcp-content-origin.d.ts +0 -8
- package/dist/model-entry-refusal.d.ts +10 -2
- package/dist/model-entry-refusal.js +19 -3
- package/dist/observability/corrupt-read-seat.d.ts +3 -3
- package/dist/observability/corrupt-read-seat.js +5 -4
- package/dist/observability/fail-open.d.ts +10 -9
- package/dist/observability/fail-open.js +5 -1
- package/dist/permission-rule-list.d.ts +81 -0
- package/dist/permission-rule-list.js +17 -0
- package/dist/plugins/remote-env-host.d.ts +0 -35
- package/dist/plugins/remote-env-host.js +0 -8
- package/dist/plugins/remote-env-local-docker.d.ts +5 -13
- package/dist/plugins/remote-env-local-docker.js +2 -4
- package/dist/run-local.js +4 -1
- package/dist/runtime-governance.d.ts +21 -1
- package/dist/runtime-governance.js +6 -1
- package/dist/security.js +2 -2
- package/dist/session-policy-wire.d.ts +5 -4
- package/dist/store-posture.d.ts +7 -7
- package/dist/store-posture.js +0 -1
- package/dist/task-settings.d.ts +19 -5
- package/dist/task-settings.js +19 -30
- package/dist/tool-approval.d.ts +16 -4
- package/dist/tool-approval.js +2 -1
- package/dist/trace/core-keyset-guard.d.ts +9 -4
- package/dist/trace/project.js +9 -0
- package/package.json +4 -4
- package/scripts/{retired-mode-seed-drain-local.mjs → drain-check-local.mjs} +147 -26
|
@@ -97,6 +97,19 @@ export declare function validateCommandRules(rules: CommandRule[]): string[];
|
|
|
97
97
|
* 闭集本身则由契约 zod 派生 ⇒ 契约加一个判词,`RANK` 与桶分配的穷尽 switch 双双**编译红**。
|
|
98
98
|
*/
|
|
99
99
|
export declare function compileCommandPolicyLayers(rules: CommandRule[] | undefined): ToolPolicy[];
|
|
100
|
+
/** 运维 allow 规则表的出处名 = 它的 env 名(盖进每条规则;编不出来 / 不合文法时拒启句的主语)。 */
|
|
101
|
+
export declare const APPROVAL_GRANT_SOURCE = "APPROVAL_GRANT";
|
|
102
|
+
/**
|
|
103
|
+
* 7.115.0 —— 运维的 allow 规则(`APPROVAL_GRANT`)编成治理层的**叶**(空 / 缺席 ⇒ `[]`,本层一片叶都不铸,折叠逐字与修前同)。
|
|
104
|
+
*
|
|
105
|
+
* 编译口是**请求腿 `settings.permissions.allow` 的同一只**(`permission-rule-list.ts` `createRuleListPolicy`,`behavior: "allow"`):命中 = core 带
|
|
106
|
+
* `decisionReason: "rule"` 的放行(折叠把这句表态带到终局,引擎据此不再为没人表态的服务器工具调用出 `unstated` 卡);未命中 = 裸 allow =
|
|
107
|
+
* 不表态。它是一片**不收紧**的叶 —— 与 commandPolicy / 守卫集同住一个折叠点,只因为三者是同一个「部署说的话」:折叠 deny > ask > allow,
|
|
108
|
+
* 同折叠里任何一片叶的 deny / ask、`tightenTaskSpec` 之下的审批基线、之上的请求 settings 与会话规则,照旧压过它。
|
|
109
|
+
*
|
|
110
|
+
* 启动校验(`config.ts` `approvalGrantRefusal`)试编的也是本函数 —— 拒启判据与运行期编译是同一只,不会出现「启动收下、任务里编不出来」。
|
|
111
|
+
*/
|
|
112
|
+
export declare function compileApprovalGrantLayers(grant: readonly string[] | undefined): ToolPolicy[];
|
|
100
113
|
/**
|
|
101
114
|
* Expand an autonomy mode into TIGHTEN-ONLY `TaskSpec` safety overrides (the primitives — TRAP #2):
|
|
102
115
|
* - `read-only` / `plan` → `handsReadOnly: true` **+ `writeFace: "roots"`** (read + propose, never mutate; the
|
|
@@ -203,13 +216,18 @@ export declare function governanceOriginOf(gate: {
|
|
|
203
216
|
};
|
|
204
217
|
} | undefined, governance: GovernancePosture | undefined): true | undefined;
|
|
205
218
|
/**
|
|
206
|
-
* Apply the operator's runtime governance (autonomy + commandPolicy + manualModeShellGate
|
|
219
|
+
* Apply the operator's runtime governance (autonomy + commandPolicy + manualModeShellGate + the guard set + the
|
|
220
|
+
* `APPROVAL_GRANT` allow rules) onto a base
|
|
207
221
|
* `TaskSpec`, TIGHTEN-ONLY, in a SINGLE {@link tightenTaskSpec} call: commandPolicy compiles to a `toolPolicy`
|
|
208
222
|
* override (combined onto the baseline by `tightenTaskSpec` — TRAP #1), and autonomy expands to
|
|
209
223
|
* `handsReadOnly` / `shellGate` overrides (TRAP #2). `tightenTaskSpec` THROWS `TaskSpecTightenError` if any
|
|
210
224
|
* override would LOOSEN a stricter base safety field — surfacing a misconfiguration loudly instead of silently
|
|
211
225
|
* weakening the gate. Returns `base` untouched when there is nothing to apply.
|
|
212
226
|
*
|
|
227
|
+
* 7.115.0:`APPROVAL_GRANT` 是这里唯一一片**不收紧**的叶 —— 它只给出 allow 的那句表态(core 7.40.0 起没人表态的服务器工具调用要问,
|
|
228
|
+
* 运维的规则就是那句答),从不清掉任何 deny / ask:折叠 deny > ask > allow,所以「部署 ⊇ 操作员 ⊇ 客户端只能收窄」的不变量逐字成立。
|
|
229
|
+
* 编译口与请求腿的 allow 桶同一只({@link compileApprovalGrantLayers})。
|
|
230
|
+
*
|
|
213
231
|
* [ref]([ref] server 分单②):`MANUAL_MODE_SHELL_GATE` 从 settings 折叠搬到这里**无条件施加**。旧家
|
|
214
232
|
* (task-settings deriveSettingsPolicy 的 default/auto/acceptEdits 三臂)让一个**部署级 tighten-only 旋钮
|
|
215
233
|
* 的生死由客户端表态在场性决定**:body 无 settings/permissionMode(cli print/headless 腿按设计不 stamp)
|
|
@@ -242,6 +260,8 @@ export declare function applyRuntimeGovernance(base: TaskSpec, governance: {
|
|
|
242
260
|
/** 守卫集的**叶**(`deployment-governance.ts` `createDeploymentGovernanceInputs` 预铸;S-958 起是叶的列表,不是一只预折的策略)。
|
|
243
261
|
* 空列表与缺席同义。 */
|
|
244
262
|
sensitivePathLayers?: readonly ToolPolicy[];
|
|
263
|
+
/** 7.115.0:运维的 allow 规则(`APPROVAL_GRANT` 原串;本函数经 {@link compileApprovalGrantLayers} 编成叶)。空列表与缺席同义。 */
|
|
264
|
+
approvalGrant?: readonly string[];
|
|
245
265
|
/** [ref]/[ref] `governanceForced` 的标记表(缺省 = **当前 run 腿的 ALS 表**,见
|
|
246
266
|
* `governance-ask-marks.ts` 顶注「作用域」段)。注入口只为测试与将来的多实例形。 */
|
|
247
267
|
askMarks?: GovernanceAskMarks;
|
|
@@ -2,6 +2,7 @@ import { combinePolicies, COARSE_SHELL_TOOLS as CORE_COARSE_SHELL_TOOLS, createC
|
|
|
2
2
|
import { GovernanceConfig } from "@sema-agent/settings-schema";
|
|
3
3
|
import { currentGovernanceAskMarks } from "./governance-ask-marks.js";
|
|
4
4
|
import { createDeploymentAuthoredPolicy, operatorAsk } from "./operator-ask.js";
|
|
5
|
+
import { createRuleListPolicy } from "./permission-rule-list.js";
|
|
5
6
|
import { heldRuleName } from "./tool-rule-names.js";
|
|
6
7
|
const COMMAND_RULE_SHAPE = GovernanceConfig.shape.commandPolicy.unwrap().element.shape;
|
|
7
8
|
const COMMAND_DECISIONS = COMMAND_RULE_SHAPE.decision.options;
|
|
@@ -100,6 +101,10 @@ export function compileCommandPolicyLayers(rules) {
|
|
|
100
101
|
}
|
|
101
102
|
return policies;
|
|
102
103
|
}
|
|
104
|
+
export const APPROVAL_GRANT_SOURCE = "APPROVAL_GRANT";
|
|
105
|
+
export function compileApprovalGrantLayers(grant) {
|
|
106
|
+
return grant !== undefined && grant.length > 0 ? [createRuleListPolicy(grant, "allow", APPROVAL_GRANT_SOURCE, undefined)] : [];
|
|
107
|
+
}
|
|
103
108
|
export function autonomyOverrides(autonomy) {
|
|
104
109
|
switch (autonomy) {
|
|
105
110
|
case "read-only":
|
|
@@ -143,7 +148,7 @@ function createGovernanceShellGateMarkPolicy(marksOf, tools = COARSE_SHELL_TOOLS
|
|
|
143
148
|
export function applyRuntimeGovernance(base, governance) {
|
|
144
149
|
const marksOf = () => governance.askMarks ?? currentGovernanceAskMarks();
|
|
145
150
|
const overrides = { ...autonomyOverrides(governance.autonomy) };
|
|
146
|
-
const layers = [...compileCommandPolicyLayers(governance.commandPolicy), ...(governance.sensitivePathLayers ?? [])];
|
|
151
|
+
const layers = [...compileCommandPolicyLayers(governance.commandPolicy), ...(governance.sensitivePathLayers ?? []), ...compileApprovalGrantLayers(governance.approvalGrant)];
|
|
147
152
|
const governancePolicy = layers.length > 0 ? createGovernanceAskMarkingPolicy(combinePolicies(...layers.map(createDeploymentAuthoredPolicy)), marksOf) : undefined;
|
|
148
153
|
if (governancePolicy !== undefined)
|
|
149
154
|
overrides.toolPolicy = governancePolicy;
|
package/dist/security.js
CHANGED
|
@@ -65,7 +65,7 @@ export function createAuthorizer(config, sessionStore) {
|
|
|
65
65
|
let owner = await ownerOf(requested);
|
|
66
66
|
if (owner === undefined) {
|
|
67
67
|
if (requireExisting) {
|
|
68
|
-
throw
|
|
68
|
+
throw createCodedHttpError(404, "resume.session_not_found", "requireExistingSession: session does not exist (resume.session_not_found)");
|
|
69
69
|
}
|
|
70
70
|
if (register) {
|
|
71
71
|
await register(requested, principal ?? null);
|
|
@@ -89,7 +89,7 @@ export function createAuthorizer(config, sessionStore) {
|
|
|
89
89
|
}
|
|
90
90
|
else {
|
|
91
91
|
if (requireExisting) {
|
|
92
|
-
throw
|
|
92
|
+
throw createCodedHttpError(422, "request.field_conflict", "requireExistingSession requires a sessionId — there is no existing session to resume");
|
|
93
93
|
}
|
|
94
94
|
sessionId = uuidv7();
|
|
95
95
|
if (register)
|
|
@@ -66,10 +66,11 @@ export type ToolNameRuleField = {
|
|
|
66
66
|
* 「照 #1156 未随本版」);同版新导出的 `rosterToolName` / `ruleNamesOf`(#1194)是**别名归一**(一个名字在名册上落到哪只行的线名 /
|
|
67
67
|
* 一次调用可被规则拼成的名字集),不回答「这个名字会不会让准备阶段拒启」,不能替本函数 ⇒ 本函数照留,等 #1156。
|
|
68
68
|
*
|
|
69
|
-
* 🔴 **为什么不复用 `config.ts` 的 `
|
|
70
|
-
*
|
|
71
|
-
* fail-closed
|
|
72
|
-
*
|
|
69
|
+
* 🔴 **为什么不复用 `config.ts` 的 `unmatchableToolNamesRefusal`**(本仓另一只按名字判的单点;读过实现后裁):两只回答的
|
|
70
|
+
* 不是同一个问题。那一只问「这张表里这条条目会不会**永远不生效**」(匹配不上活工具,或编不成一条规则)—— 7.115.0 起它对 `allow` 也照判
|
|
71
|
+
* (修前豁免 `allow`:那时 allow 是白名单,匹配不上 = fail-closed 且当场可见;allow 改成 allow 规则后豁免臂已删),并且拒两段 MCP 名
|
|
72
|
+
* `mcp__srv`(一名两义)与 core 文法编不出的串。本函数问的是「引擎见到这条会话规则会不会**拒启**」:引擎准备阶段的名审计对会话规则的
|
|
73
|
+
* `allow` 桶照样抛,对 `mcp__srv` 却
|
|
73
74
|
* **不**抛(会话层自 core 5.55 / 5.56 起把它当整对端覆盖形真命中)。判据只能逐字跟 core 那两臂走,不能借另一只的口径。
|
|
74
75
|
* 两只在「退役名」「无前缀 `__` 名」两臂上同源(都读 core 导出的同两件),#1156 到货的那一批一并换调 core 的导出函数。
|
|
75
76
|
*/
|
package/dist/store-posture.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* 由调用方自己读出落差。`degradedReason` present-iff 降级臂走过(按后端族定词,{@link storeDegradedReasonFor})。
|
|
13
13
|
* 顶层 `sql` 并入 `store.sql`(硬 breaking,零别名;对象逐字同形)。
|
|
14
14
|
*/
|
|
15
|
-
import {
|
|
15
|
+
import type { StoreBackend as StoreBackendWord } from "@sema-agent/settings-schema/execution-lanes";
|
|
16
16
|
import type { StoreBackend } from "./plugins/store-backend.js";
|
|
17
17
|
import type { SqlEngineFacts } from "./plugins/sql-driver.js";
|
|
18
18
|
import { type SqlEngineCapability } from "./sql-engine-posture.js";
|
|
@@ -25,23 +25,23 @@ import { type SqlEngineCapability } from "./sql-engine-posture.js";
|
|
|
25
25
|
export declare const STORE_DEGRADED_REASONS: readonly ["db_unreachable", "local_unwritable"];
|
|
26
26
|
export type StoreDegradedReason = (typeof STORE_DEGRADED_REASONS)[number];
|
|
27
27
|
/** 降级臂按后端族定词(穷举 switch:词表加员 ⇒ 编译红)。`memory` 从不尝试打开后端,走不到降级臂 —— 到了就是装配缺陷,响亮抛。 */
|
|
28
|
-
export declare function storeDegradedReasonFor(declared:
|
|
28
|
+
export declare function storeDegradedReasonFor(declared: StoreBackendWord): StoreDegradedReason;
|
|
29
29
|
/** 装配值(纯数据;`boot/stores.ts` 铸一次,gauge / `/health` / caps 三面同读)。 */
|
|
30
30
|
export interface StorePosture {
|
|
31
|
-
readonly declared:
|
|
32
|
-
readonly backend:
|
|
31
|
+
readonly declared: StoreBackendWord;
|
|
32
|
+
readonly backend: StoreBackendWord;
|
|
33
33
|
readonly degradedReason?: StoreDegradedReason;
|
|
34
34
|
}
|
|
35
35
|
/** `build*`(纯数据)。`assembled` = 装配出的 `StoreBackend.kind`;缺席 = 没装出后端 ⇒ `memory`。 */
|
|
36
36
|
export declare function buildStorePosture(a: {
|
|
37
|
-
readonly declared:
|
|
37
|
+
readonly declared: StoreBackendWord;
|
|
38
38
|
readonly assembled: StoreBackend["kind"] | undefined;
|
|
39
39
|
readonly degradedReason: StoreDegradedReason | undefined;
|
|
40
40
|
}): StorePosture;
|
|
41
41
|
/** caps `store` 的形。 */
|
|
42
42
|
export interface StoreCapability {
|
|
43
|
-
readonly declared:
|
|
44
|
-
readonly backend:
|
|
43
|
+
readonly declared: StoreBackendWord;
|
|
44
|
+
readonly backend: StoreBackendWord;
|
|
45
45
|
readonly durable: boolean;
|
|
46
46
|
readonly degradedReason?: StoreDegradedReason;
|
|
47
47
|
/** 7.105.0 及以前的顶层 `sql` 对象,原样搬入(`{engine, isolation, txnMode}`)。present-iff `backend ∈ {mysql, pg}` ∧ 驱动此刻给得出
|
package/dist/store-posture.js
CHANGED
package/dist/task-settings.d.ts
CHANGED
|
@@ -12,9 +12,12 @@
|
|
|
12
12
|
* idempotent (the same tighten), so no special resume handling is needed (mirrors runtime-governance).
|
|
13
13
|
*
|
|
14
14
|
* 🔒 SECURITY INVARIANTS (SDK settings.ts §3.3):
|
|
15
|
-
* - permissions are
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* - permissions are folded via `tightenTaskSpec` (deny-wins `combinePolicies`); it THROWS on any override that would
|
|
16
|
+
* LOOSEN a stricter base safety field. The client can ADD denies/asks/handsReadOnly on top of the deployment +
|
|
17
|
+
* operator baseline, never widen it. Its `allow` rules (S-654 (c), 7.115.0) STATE an allow for the tools they name —
|
|
18
|
+
* the answer core 7.40.0 wants before it runs an MCP / A2A call nobody stated — and never override a deny or an ask
|
|
19
|
+
* from any layer (deny > ask > allow); a miss has no opinion. They release no ask a layer raises itself: on built-in
|
|
20
|
+
* tools the engine's own write gate and shell checks still ask (unlike the reference implementation's `permissions.allow`).
|
|
18
21
|
* - permissionMode(轴B #2 注释保鲜,1.254——[ref]/[ref] 后的真实现):`defaultMode` 收**五**模式
|
|
19
22
|
* (default | acceptEdits | plan | bypassPermissions | auto),bypass/auto 被 HONOR 为 gate-shape 选择
|
|
20
23
|
* ——但深层不变量未变:bypass=「不加 ask 门」,恒不越部署基线(tightenTaskSpec deny-wins,基线 deny/
|
|
@@ -224,8 +227,6 @@ export interface ParseTaskSettingsResult {
|
|
|
224
227
|
* posture (an uncapped prompt body is a per-turn token-cost hole; cross review). Exported so the HTTP layer
|
|
225
228
|
* (prepareSpec) can 400 fail-loud on submit with the SAME bound this defensive parse enforces on every path. */
|
|
226
229
|
export declare const MAX_SETTINGS_OUTPUT_STYLE_CHARS = 16384;
|
|
227
|
-
/** Cap on the element count of each permission list (allow/deny/ask) — bounds a pathological rule blast. */
|
|
228
|
-
export declare const MAX_SETTINGS_PERMISSION_RULES = 1000;
|
|
229
230
|
/** Caps on `settings.env` — bound a pathological env blast (count + per-value length; values land in the shell env). */
|
|
230
231
|
export declare const MAX_SETTINGS_ENV_VARS = 256;
|
|
231
232
|
export declare const MAX_SETTINGS_ENV_VALUE_CHARS = 32768;
|
|
@@ -298,6 +299,19 @@ export declare const TASK_SETTINGS_UNSUPPORTED_PERMISSION_KEYS: readonly ["addit
|
|
|
298
299
|
* · `permissions: null` 是既有钉住的「容器缺席」形,照旧不咬。
|
|
299
300
|
*/
|
|
300
301
|
export declare function taskSettingsKeyIssue(raw: unknown): KeyClosureIssue | null;
|
|
302
|
+
/**
|
|
303
|
+
* 🔒 **`settings.hooks` 会不会被采纳** —— 全仓**唯一**的车道谓词(S-995,主会话裁):hook 命令跑在 WORKER HOST([ref] class ② 能力授予),所以只有单用户车道
|
|
304
|
+
* (`requirePrincipal !== true`,与 scheduler / backgroundShell / lspHost / MCP 注入同一姿势)采纳;多租户车道收到 hooks **整只忽略**(`task_hooks_ignored`),绝不执行。
|
|
305
|
+
* 三处读它,谁也不许内联 `requirePrincipal`(各写各的 = 迟早漂):
|
|
306
|
+
* · `boot/resolve-spec.ts` —— 装配:不采纳 ⇒ 不装 `TaskSpec.hooks` + 一条 `task_hooks_ignored`;
|
|
307
|
+
* · `http/routes/capabilities.ts` —— 能力位 `taskSettings.hooks`(「says yes ⟺ route works」);
|
|
308
|
+
* · `http/admission.ts` —— fresh 受理面的「别名 matcher 永不命中」判据的**求值深度**:采纳 ⇒ `"regex"`(运行期同一只匹配函数,带资源闸);不采纳 ⇒ `"literal"`
|
|
309
|
+
* (7.112.0 的字面判:零调用方正则执行 —— 受理面是所有车道,租户不能借一只灾难回溯的 matcher 占满事件循环)。
|
|
310
|
+
* `test/hooks-alias-matcher-s995.test.ts` R5g 钉「三处都调它、没有内联判据」。
|
|
311
|
+
*/
|
|
312
|
+
export declare function taskHooksHonored(config: {
|
|
313
|
+
readonly requirePrincipal?: boolean;
|
|
314
|
+
}): boolean;
|
|
301
315
|
/**
|
|
302
316
|
* Validate an untrusted `body.settings` (raw `unknown` off the wire) into the service-trusted {@link
|
|
303
317
|
* ParsedTaskSettings}. NEVER trusts the wire type — every field is shape-checked. `defaultMode` accepts the FIVE
|
package/dist/task-settings.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { combinePolicies,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { combinePolicies, createFsWriteGatePolicy, parseRuleText, tightenTaskSpec, resolveReasoningProfile, rankOf, isThinkingLevel, CYBER_RISK, URL_SAFETY, HARNESS_SECTION_ANCHOR, RUN_WORKFLOW_TOOL_NAME, PERMISSION_MODES, ruleToolGrammarOf, } from "@sema-agent/core";
|
|
2
|
+
import { unmatchableToolNamesRefusal } from "./config.js";
|
|
3
|
+
import { MAX_PERMISSION_RULES_PER_LIST, createRuleListPolicy } from "./permission-rule-list.js";
|
|
4
4
|
import { MAX_KEY_ECHO, keyClosureClause, scanKeyClosure } from "./request-key-closure.js";
|
|
5
5
|
import { parseHooksConfig } from "./hooks/hook-runner.js";
|
|
6
6
|
import { heldRuleName } from "./tool-rule-names.js";
|
|
@@ -61,7 +61,6 @@ export function skillListingMaxDescOk(v) {
|
|
|
61
61
|
return typeof v === "number" && Number.isSafeInteger(v) && v > 0;
|
|
62
62
|
}
|
|
63
63
|
export const MAX_SETTINGS_OUTPUT_STYLE_CHARS = 16_384;
|
|
64
|
-
export const MAX_SETTINGS_PERMISSION_RULES = 1_000;
|
|
65
64
|
export const MAX_SETTINGS_ENV_VARS = 256;
|
|
66
65
|
export const MAX_SETTINGS_ENV_VALUE_CHARS = 32_768;
|
|
67
66
|
export const MAX_SETTINGS_ENV_KEY_CHARS = 256;
|
|
@@ -106,8 +105,8 @@ export function settingsPermissionBucketIssue(perms) {
|
|
|
106
105
|
let fields;
|
|
107
106
|
if (!Array.isArray(v))
|
|
108
107
|
fields = { field, reason: "bad_entry" };
|
|
109
|
-
else if (v.length >
|
|
110
|
-
fields = { field, reason: "over_cap", count: v.length, cap:
|
|
108
|
+
else if (v.length > MAX_PERMISSION_RULES_PER_LIST)
|
|
109
|
+
fields = { field, reason: "over_cap", count: v.length, cap: MAX_PERMISSION_RULES_PER_LIST };
|
|
111
110
|
else {
|
|
112
111
|
const index = v.findIndex((x) => typeof x !== "string" || x.length === 0);
|
|
113
112
|
if (index >= 0)
|
|
@@ -158,6 +157,9 @@ export function taskSettingsKeyIssue(raw) {
|
|
|
158
157
|
unsupportedKeys: unsupported.slice(0, MAX_KEY_ECHO),
|
|
159
158
|
};
|
|
160
159
|
}
|
|
160
|
+
export function taskHooksHonored(config) {
|
|
161
|
+
return config.requirePrincipal !== true;
|
|
162
|
+
}
|
|
161
163
|
export function parseTaskSettings(raw) {
|
|
162
164
|
if (raw === null || raw === undefined || typeof raw !== "object")
|
|
163
165
|
return { deferred: [] };
|
|
@@ -263,20 +265,7 @@ export function acceptAppendSystemPrompt(v, warn, packDropsAppend) {
|
|
|
263
265
|
}
|
|
264
266
|
return v;
|
|
265
267
|
}
|
|
266
|
-
const RULE_SOURCE_BY_BEHAVIOR = { ask: "settings.permissions.ask", deny: "settings.permissions.deny" };
|
|
267
|
-
function createRuleListPolicy(names, behavior, pathBases) {
|
|
268
|
-
try {
|
|
269
|
-
return createPermissionRulePolicy(names.map((name) => ({ rule: name, behavior, source: RULE_SOURCE_BY_BEHAVIOR[behavior] })), {
|
|
270
|
-
defaultAction: "allow",
|
|
271
|
-
caps: { maxRules: MAX_SETTINGS_PERMISSION_RULES },
|
|
272
|
-
...(pathBases !== undefined ? { pathBases } : {}),
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
catch (e) {
|
|
276
|
-
const coreMsg = (e instanceof Error ? e.message : String(e)).replace(CONTROL_AND_BIDI_STRIP_RE, "");
|
|
277
|
-
throw new Error(`${RULE_SOURCE_BY_BEHAVIOR[behavior].replace("settings.", "")} has rule(s) core cannot compile — ${coreMsg}`, { cause: e });
|
|
278
|
-
}
|
|
279
|
-
}
|
|
268
|
+
const RULE_SOURCE_BY_BEHAVIOR = { allow: "settings.permissions.allow", ask: "settings.permissions.ask", deny: "settings.permissions.deny" };
|
|
280
269
|
const WORKFLOW_ASK_NAMES = [RUN_WORKFLOW_TOOL_NAME];
|
|
281
270
|
const isWorkflowName = (name) => name === RUN_WORKFLOW_TOOL_NAME;
|
|
282
271
|
function createWorkflowAskPolicy(isExempt) {
|
|
@@ -324,16 +313,16 @@ function rejectUnmatchableSettingsNames(perms, pathBases) {
|
|
|
324
313
|
}
|
|
325
314
|
}
|
|
326
315
|
}
|
|
327
|
-
for (const [field, names, behavior
|
|
328
|
-
["permissions.ask", perms.ask, "ask"
|
|
329
|
-
["permissions.deny", perms.deny, "deny"
|
|
330
|
-
["permissions.allow", perms.allow, "allow"
|
|
316
|
+
for (const [field, names, behavior] of [
|
|
317
|
+
["permissions.ask", perms.ask, "ask"],
|
|
318
|
+
["permissions.deny", perms.deny, "deny"],
|
|
319
|
+
["permissions.allow", perms.allow, "allow"],
|
|
331
320
|
]) {
|
|
332
321
|
if (!names)
|
|
333
322
|
continue;
|
|
334
|
-
const
|
|
335
|
-
if (
|
|
336
|
-
throw new Error(
|
|
323
|
+
const unmatchable = unmatchableToolNamesRefusal(field, names, { consumer: "rule-policy", behavior, ...(pathBases !== undefined ? { pathBases } : {}) });
|
|
324
|
+
if (unmatchable !== undefined)
|
|
325
|
+
throw new Error(unmatchable.message);
|
|
337
326
|
}
|
|
338
327
|
}
|
|
339
328
|
export function deriveSettingsPolicy(settings, gate, workflowGate) {
|
|
@@ -347,11 +336,11 @@ export function deriveSettingsPolicy(settings, gate, workflowGate) {
|
|
|
347
336
|
rejectUnmatchableSettingsNames(perms, pathBases);
|
|
348
337
|
const policies = [];
|
|
349
338
|
if (allow)
|
|
350
|
-
policies.push(
|
|
339
|
+
policies.push(createRuleListPolicy(allow, "allow", RULE_SOURCE_BY_BEHAVIOR.allow, pathBases));
|
|
351
340
|
if (deny)
|
|
352
|
-
policies.push(createRuleListPolicy(deny, "deny", pathBases));
|
|
341
|
+
policies.push(createRuleListPolicy(deny, "deny", RULE_SOURCE_BY_BEHAVIOR.deny, pathBases));
|
|
353
342
|
if (ask)
|
|
354
|
-
policies.push(createRuleListPolicy(ask, "ask", pathBases));
|
|
343
|
+
policies.push(createRuleListPolicy(ask, "ask", RULE_SOURCE_BY_BEHAVIOR.ask, pathBases));
|
|
355
344
|
const fsWriteGate = (acceptCwd) => {
|
|
356
345
|
if (!gate)
|
|
357
346
|
return undefined;
|
package/dist/tool-approval.d.ts
CHANGED
|
@@ -452,10 +452,7 @@ export interface ToolApprovalFrame {
|
|
|
452
452
|
* 耐久路的对偶 = `gate.riskDescriptor.probeCause`(同值,core `buildRiskDescriptor` 铸),走 checkpoint
|
|
453
453
|
* 行的**整体透传**到 `GET /v1/approvals` —— 键集零施工,钉在同一个文件的 §4。
|
|
454
454
|
*
|
|
455
|
-
* 姊妹键 `
|
|
456
|
-
* 拼法,而 core 的边界哲学(交 code + 数组、不交句子)与「一张卡上不放两份同义解释」都指向只投结构化
|
|
457
|
-
* 那一份;散文那份还无法被消费端本地化。照 `preview` / `requiresRealApproval` 先例 = 候消费端(cli)
|
|
458
|
-
* 提渲染需求再翻(登记在 `trace/core-keyset-guard.ts` 的 EXCLUDED 栏)。
|
|
455
|
+
* 姊妹键 `probeReason`(同一件事的**散文**兄弟)见下一键 —— 7.115.0 起投影(S-733),与本键**并列不替代**。
|
|
459
456
|
*/
|
|
460
457
|
probeCause?: {
|
|
461
458
|
code: string;
|
|
@@ -468,6 +465,21 @@ export interface ToolApprovalFrame {
|
|
|
468
465
|
total: number;
|
|
469
466
|
};
|
|
470
467
|
};
|
|
468
|
+
/**
|
|
469
|
+
* S-733(7.115.0;**ADDITIVE**,`"tool_approval"` only)—— 这次 ask 被收紧时探针给出的那一句**散文**因由
|
|
470
|
+
* (`AskRequest.probeReason`:core 在 maybe 档收紧点 `inlineUntrusted(…, 200)` 过的一句话)。与
|
|
471
|
+
* {@link probeCause}(结构化因由)**并列、不替代**:引擎自己铸的因由走结构位,**部署自写的探针**只会写这一句
|
|
472
|
+
* —— 一只只给 reason 不给 cause 的探针,此前其审批人在活卡上读不到任何因由(耐久面
|
|
473
|
+
* `gate.riskDescriptor.probeReason` 早就带着这同一句,两张脸只有一张有话说)。
|
|
474
|
+
*
|
|
475
|
+
* 🔴 **在场才带**(缺席绝不编空串;缺席 ≠「没有原因」);窄读单点 = `approval-card.ts` 的 `readProbeReason`
|
|
476
|
+
* (非串 / 空白 ⇒ 缺席;超信封 ⇒ **整只丢不截**;内容族 ⇒ 脱敏,与耐久面同一规则 ⇒ 对同一句话两面同值)。
|
|
477
|
+
* 🔴 **只在本帧上**:呈卡帧 / `card_json` 不携它(`ApprovalCardSchema` 是 `.strict()` 的耐久信封,加键要另行裁定)。
|
|
478
|
+
* 🔴 **展示 / 分诊元数据,永不是裁决输入**;永不进 `message`(那是分类器 / 模型的输入面)。
|
|
479
|
+
* `\p{Cf}` 展示重排类字符(方向 / 零宽标记):core 在这个座上**不剥**(同值契约下 core 自己披露的残余,[ref]);本仓脱敏器
|
|
480
|
+
* (`redactSecrets`)入口剥全部 `\p{Cf}`(7.70.0 起),活卡帧与耐久面**都过它** ⇒ 两面同值、且都是剥后字节(`test/approval-probe-reason-wire.test.ts` 钉)。
|
|
481
|
+
*/
|
|
482
|
+
probeReason?: string;
|
|
471
483
|
/**
|
|
472
484
|
* [ref] 件 G2(core 5.35.0 [ref] G-2;**ADDITIVE**,`"tool_approval"` only)—— 这只 ask 背后的
|
|
473
485
|
* **规则出处证据**(`AskRequest.ruleEvidence`,引擎在 gate 内盖章):org 快照 `orgRevision` / 命中的
|
package/dist/tool-approval.js
CHANGED
|
@@ -8,7 +8,7 @@ import { approvalPayloadFingerprint } from "./plugins/approval-payload-fingerpri
|
|
|
8
8
|
import { createLogger } from "./observability/logger.js";
|
|
9
9
|
import { recordFailOpen } from "./observability/fail-open.js";
|
|
10
10
|
import { deriveAskId, deriveAskScopedBatchId, deriveBatchId, MAX_DECISION_NOTE_CHARS } from "./approval-ask-machine.js";
|
|
11
|
-
import { ApprovalCardEnvelopeSchema, MAX_RULE_OFFERS, buildApprovalCard, buildApprovalCardEnvelope, buildApprovalRequestFrame, buildRevokeFrame, readDenialLimitFallback, readProbeCause, readReadRootCandidate, readRuleEvidence, readRuleOffersAbsence, readRuleOffersAbsenceSeat, readParkRowTrueSeat, readAskClassPair, readClosedWordSeat, RuleOfferRawSchema, backfillLegacyBatchMemberKind, screenUncoveredDetailSeat, } from "./approval-card.js";
|
|
11
|
+
import { ApprovalCardEnvelopeSchema, MAX_RULE_OFFERS, buildApprovalCard, buildApprovalCardEnvelope, buildApprovalRequestFrame, buildRevokeFrame, readDenialLimitFallback, readProbeCause, readProbeReason, readReadRootCandidate, readRuleEvidence, readRuleOffersAbsence, readRuleOffersAbsenceSeat, readParkRowTrueSeat, readAskClassPair, readClosedWordSeat, RuleOfferRawSchema, backfillLegacyBatchMemberKind, screenUncoveredDetailSeat, } from "./approval-card.js";
|
|
12
12
|
import { MAX_SETTLED_BY_CHARS, POLICY_REFUSAL_DECISION, projectAskTerminalClaimTruth, settledByFitsColumn } from "./plugins/approval-ask-store-sql.js";
|
|
13
13
|
import { settleByPolicy } from "./approval-policy-settlement.js";
|
|
14
14
|
import { governanceAskMarksFor, runWithGovernanceAskScope } from "./governance-ask-marks.js";
|
|
@@ -1099,6 +1099,7 @@ export class ToolApprovalCoordinator {
|
|
|
1099
1099
|
...((f) => (f !== undefined ? { denialLimitFallback: f } : {}))(readDenialLimitFallback(req)),
|
|
1100
1100
|
...((g) => (g !== undefined ? { readRootCandidate: g } : {}))(readReadRootCandidate(req)),
|
|
1101
1101
|
...((c) => (c !== undefined ? { probeCause: c } : {}))(readProbeCause(req)),
|
|
1102
|
+
...((r) => (r !== undefined ? { probeReason: r } : {}))(readProbeReason(req)),
|
|
1102
1103
|
...((c) => (c !== undefined ? { ruleEvidence: c } : {}))(readRuleEvidence(req)),
|
|
1103
1104
|
...(bounded.omitted ? { argsOmitted: true } : { args: bounded.args }),
|
|
1104
1105
|
...(bounded.hasBidi || req.hasBidiControls === true ? { inputHasBidi: true } : {}),
|
|
@@ -43,8 +43,8 @@ type _GuardBgNotifReverse = AssertAllKeysHandled<Exclude<BgNotifProjected | BgNo
|
|
|
43
43
|
type RosterProjected = "name" | "agentId" | "sessionId" | "toolUseId" | "owner" | "scope" | "sessionScoped" | "rootSessionId" | "model" | "modelFallback" | "createdAt";
|
|
44
44
|
type _GuardRoster = AssertAllKeysHandled<Exclude<keyof RosterEntry, RosterProjected>>;
|
|
45
45
|
type _GuardRosterReverse = AssertAllKeysHandled<Exclude<RosterProjected, keyof RosterEntry>>;
|
|
46
|
-
type AskProjected = "toolName" | "toolCallId" | "args" | "message" | "sourceTaskId" | "fromSubagent" | "sourceAgentName" | "delegation" | "ruleOffers" | "ruleOffersAbsence" | "persistedRuleShadowed" | "probeCause" | "ruleEvidence" | "requiresRealApproval" | "denialLimitFallback" | "origin" | "readRootCandidate" | "mandated" | "mandate" | "askClass" | "classes";
|
|
47
|
-
type AskExcluded = "preview" | "principal" | "riskAxes" | "boundInputHash" | "isDelegatedChild" | "
|
|
46
|
+
type AskProjected = "toolName" | "toolCallId" | "args" | "message" | "sourceTaskId" | "fromSubagent" | "sourceAgentName" | "delegation" | "ruleOffers" | "ruleOffersAbsence" | "persistedRuleShadowed" | "probeCause" | "probeReason" | "ruleEvidence" | "requiresRealApproval" | "denialLimitFallback" | "origin" | "readRootCandidate" | "mandated" | "mandate" | "askClass" | "classes";
|
|
47
|
+
type AskExcluded = "preview" | "principal" | "riskAxes" | "boundInputHash" | "isDelegatedChild" | "hasBidiControls" | "previewWithheld" | "execCwd" | "authoredBy";
|
|
48
48
|
type _GuardAsk = AssertAllKeysHandled<Exclude<keyof AskRequest, AskProjected | AskExcluded>>;
|
|
49
49
|
type _GuardAskReverse = AssertAllKeysHandled<Exclude<AskProjected | AskExcluded, keyof AskRequest>>;
|
|
50
50
|
type AskFrameServerMinted = "type" | "approvalId" | "argsOmitted" | "outcome" | "governanceForced" | "expiresAtMs" | "expiresInMs" | "serverNowMs" | "parked" | "inputHasBidi";
|
|
@@ -88,10 +88,13 @@ type _GuardWiringSessionReverse = AssertAllKeysHandled<Exclude<WiringSessionHand
|
|
|
88
88
|
type WiringToolsHandled = "schemaVersion" | "count" | "entries" | "digest";
|
|
89
89
|
type _GuardWiringTools = AssertAllKeysHandled<Exclude<keyof WiringSection<"tools">, WiringToolsHandled>>;
|
|
90
90
|
type _GuardWiringToolsReverse = AssertAllKeysHandled<Exclude<WiringToolsHandled, keyof WiringSection<"tools">>>;
|
|
91
|
-
type
|
|
92
|
-
type WiringFleetHandled = "backgroundAgentStore" | "hostChildEventSink" | FleetExcluded;
|
|
91
|
+
type WiringFleetHandled = "backgroundAgentStore" | "hostChildEventSink" | "subagentTranscripts";
|
|
93
92
|
type _GuardWiringFleet = AssertAllKeysHandled<Exclude<keyof WiringSection<"fleet">, WiringFleetHandled>>;
|
|
94
93
|
type _GuardWiringFleetReverse = AssertAllKeysHandled<Exclude<WiringFleetHandled, keyof WiringSection<"fleet">>>;
|
|
94
|
+
type SubagentTranscriptTier = WiringSection<"fleet">["subagentTranscripts"];
|
|
95
|
+
type SubagentTranscriptTierWords = "none" | "rows" | "full";
|
|
96
|
+
type _GuardSubagentTranscriptTierWords = AssertAllKeysHandled<Exclude<SubagentTranscriptTier, SubagentTranscriptTierWords>>;
|
|
97
|
+
type _GuardSubagentTranscriptTierWordsReverse = AssertAllKeysHandled<Exclude<SubagentTranscriptTierWords, SubagentTranscriptTier>>;
|
|
95
98
|
type WiringMcpEntry = WiringSection<"mcp">[number];
|
|
96
99
|
type WiringMcpExcluded = "error";
|
|
97
100
|
type WiringMcpHandled = "name" | "source" | "status" | "errorCode" | "delivered" | "httpStatus" | "toolCount" | "liveness" | WiringMcpExcluded;
|
|
@@ -288,6 +291,8 @@ export type CoreKeysetGuards = [
|
|
|
288
291
|
_GuardWiringToolsReverse,
|
|
289
292
|
_GuardWiringFleet,
|
|
290
293
|
_GuardWiringFleetReverse,
|
|
294
|
+
_GuardSubagentTranscriptTierWords,
|
|
295
|
+
_GuardSubagentTranscriptTierWordsReverse,
|
|
291
296
|
_GuardWiringMcp,
|
|
292
297
|
_GuardWiringMcpReverse,
|
|
293
298
|
_GuardWiringRules,
|
package/dist/trace/project.js
CHANGED
|
@@ -499,9 +499,18 @@ export function wiringManifestEventData(ev, instructions) {
|
|
|
499
499
|
...(Array.isArray(parkIn.reasons) ? { reasons: parkIn.reasons.filter((r) => typeof r === "string") } : {}),
|
|
500
500
|
...(str(parkIn.checkpointDurability) !== undefined ? { checkpointDurability: parkIn.checkpointDurability } : {}),
|
|
501
501
|
});
|
|
502
|
+
const subagentTranscripts = (() => {
|
|
503
|
+
if (fleetIn.subagentTranscripts === undefined)
|
|
504
|
+
return undefined;
|
|
505
|
+
const word = str(fleetIn.subagentTranscripts);
|
|
506
|
+
if (word === undefined)
|
|
507
|
+
return dropProjectedFace("wiring_manifest.fleet.subagentTranscripts is not a non-empty string");
|
|
508
|
+
return word;
|
|
509
|
+
})();
|
|
502
510
|
const fleet = nonEmpty({
|
|
503
511
|
...(bool(fleetIn.backgroundAgentStore) !== undefined ? { backgroundAgentStore: fleetIn.backgroundAgentStore } : {}),
|
|
504
512
|
...(bool(fleetIn.hostChildEventSink) !== undefined ? { hostChildEventSink: fleetIn.hostChildEventSink } : {}),
|
|
513
|
+
...(subagentTranscripts !== undefined ? { subagentTranscripts } : {}),
|
|
505
514
|
});
|
|
506
515
|
const permissionRules = nonEmpty({
|
|
507
516
|
...(bool(rulesIn.storeWired) !== undefined ? { storeWired: rulesIn.storeWired } : {}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sema-agent/server",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.115.0",
|
|
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",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"!dist/run-local-linux-x64",
|
|
29
29
|
"!dist/run-local-darwin-arm64",
|
|
30
30
|
"skills",
|
|
31
|
-
"scripts/
|
|
31
|
+
"scripts/drain-check-local.mjs",
|
|
32
32
|
"deploy/sema-up",
|
|
33
33
|
"docs/DEVICE-EXECUTOR-PROTOCOL.md",
|
|
34
34
|
"USAGE.md",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"build:binary:run-local:darwin-arm64": "bun build --compile --target=bun-darwin-arm64 src/run-local.ts --outfile dist/run-local-darwin-arm64"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@sema-agent/core": "7.
|
|
66
|
-
"@sema-agent/settings-schema": "
|
|
65
|
+
"@sema-agent/core": "7.40.1",
|
|
66
|
+
"@sema-agent/settings-schema": "8.0.0",
|
|
67
67
|
"e2b": "^2.28.0",
|
|
68
68
|
"libsodium-wrappers": "^0.8.4",
|
|
69
69
|
"mysql2": "^3.22.4",
|