@sema-agent/server 7.105.0 → 7.107.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.
Files changed (175) hide show
  1. package/MIGRATION.md +105 -0
  2. package/README.md +2 -2
  3. package/USAGE.md +135 -43
  4. package/deploy/sema-up/chart/templates/server-v4pro.yaml +2 -0
  5. package/deploy/sema-up/cluster-up.sh +15 -2
  6. package/deploy/sema-up/kube-up.sh +8 -3
  7. package/deploy/sema-up/lib/flagshape.sh +29 -0
  8. package/deploy/sema-up/lib/parse-machines.py +4 -1
  9. package/deploy/sema-up/sema-up.sh +11 -9
  10. package/deploy/sema-up/stack/sema-stack-cluster.yaml +3 -1
  11. package/dist/approval-card.d.ts +1 -1
  12. package/dist/approval.d.ts +6 -1
  13. package/dist/approval.js +4 -4
  14. package/dist/auth-bridge.d.ts +14 -0
  15. package/dist/auth-bridge.js +7 -0
  16. package/dist/auto-mode-face.d.ts +49 -40
  17. package/dist/auto-mode-face.js +6 -68
  18. package/dist/bench/s1/live-deps.d.ts +9 -2
  19. package/dist/bench/s1/live-deps.js +13 -8
  20. package/dist/boot/budget-tracing.js +3 -2
  21. package/dist/boot/config-center.d.ts +4 -0
  22. package/dist/boot/config-center.js +95 -37
  23. package/dist/boot/coordinators.d.ts +1 -0
  24. package/dist/boot/coordinators.js +3 -1
  25. package/dist/boot/device-lane.d.ts +2 -1
  26. package/dist/boot/execution-env.d.ts +11 -0
  27. package/dist/boot/execution-env.js +30 -6
  28. package/dist/boot/execution-lane.js +2 -3
  29. package/dist/boot/leader.d.ts +2 -1
  30. package/dist/boot/leader.js +2 -0
  31. package/dist/boot/parked-revive-gate.d.ts +10 -7
  32. package/dist/boot/parked-revive-gate.js +4 -11
  33. package/dist/boot/resolve-spec.d.ts +1 -4
  34. package/dist/boot/resolve-spec.js +44 -21
  35. package/dist/boot/runner-deps.d.ts +5 -8
  36. package/dist/boot/runner-deps.js +3 -9
  37. package/dist/boot/side-query-lane.d.ts +2 -2
  38. package/dist/boot/stage-03-store-backend.d.ts +1 -1
  39. package/dist/boot/stage-03-store-backend.js +2 -2
  40. package/dist/boot/stage-04-stores.d.ts +1 -1
  41. package/dist/boot/stage-05-execution-env.d.ts +2 -1
  42. package/dist/boot/stage-05-execution-env.js +2 -2
  43. package/dist/boot/stage-06-runners.d.ts +3 -2
  44. package/dist/boot/stage-06-runners.js +2 -5
  45. package/dist/boot/stage-07-capability-layer.d.ts +2 -2
  46. package/dist/boot/stage-07-capability-layer.js +1 -2
  47. package/dist/boot/stage-08-reapers.d.ts +2 -2
  48. package/dist/boot/stage-09-leader.d.ts +2 -2
  49. package/dist/boot/stage-09-leader.js +2 -2
  50. package/dist/boot/stage-10-http-server.d.ts +2 -2
  51. package/dist/boot/stage-10-http-server.js +11 -7
  52. package/dist/boot/stores.d.ts +1 -1
  53. package/dist/boot/stores.js +6 -4
  54. package/dist/brain.d.ts +24 -2
  55. package/dist/brain.js +29 -10
  56. package/dist/budget.js +3 -0
  57. package/dist/capabilities/center-wiring.d.ts +64 -0
  58. package/dist/capabilities/center-wiring.js +24 -0
  59. package/dist/capabilities/composite-members.d.ts +89 -0
  60. package/dist/capabilities/composite-members.js +20 -0
  61. package/dist/capabilities/execution-lane.d.ts +3 -0
  62. package/dist/capabilities/execution-lane.js +5 -2
  63. package/dist/config-catalog.d.ts +35 -5
  64. package/dist/config-catalog.js +92 -26
  65. package/dist/config-center/apply-effective.d.ts +1 -1
  66. package/dist/config-center/apply-effective.js +7 -8
  67. package/dist/config-center/apply-ledger.d.ts +17 -0
  68. package/dist/config-center/apply-ledger.js +5 -0
  69. package/dist/config-center/center-request.d.ts +17 -0
  70. package/dist/config-center/center-request.js +4 -0
  71. package/dist/config-center/pull-state.d.ts +29 -0
  72. package/dist/config-center/pull-state.js +2 -0
  73. package/dist/config-types.d.ts +41 -14
  74. package/dist/config-types.js +1 -0
  75. package/dist/config.d.ts +35 -0
  76. package/dist/config.js +69 -16
  77. package/dist/cross-session-settings.d.ts +1 -1
  78. package/dist/deployment-governance.d.ts +12 -1
  79. package/dist/deployment-governance.js +2 -0
  80. package/dist/execution-lane-caps.d.ts +30 -2
  81. package/dist/execution-lane-caps.js +12 -0
  82. package/dist/fleet-client.d.ts +18 -13
  83. package/dist/fleet-client.js +32 -22
  84. package/dist/fleet-lease.d.ts +72 -47
  85. package/dist/fleet-lease.js +66 -14
  86. package/dist/governance-http-status.d.ts +0 -1
  87. package/dist/governance-http-status.js +0 -1
  88. package/dist/hosted-posture.d.ts +6 -17
  89. package/dist/hosted-posture.js +11 -6
  90. package/dist/http/admission.js +14 -9
  91. package/dist/http/approval-sweeps.js +13 -1
  92. package/dist/http/dispatch.js +1 -1
  93. package/dist/http/durable-run-leg.js +2 -0
  94. package/dist/http/request-guards.d.ts +25 -0
  95. package/dist/http/request-guards.js +25 -5
  96. package/dist/http/resume-legs.js +19 -11
  97. package/dist/http/route-ctx.d.ts +9 -0
  98. package/dist/http/routes/approvals-assistant.js +0 -1
  99. package/dist/http/routes/capabilities.js +11 -12
  100. package/dist/http/routes/config-catalog.js +2 -1
  101. package/dist/http/routes/diagnostics.js +2 -0
  102. package/dist/http/routes/tasks.js +4 -1
  103. package/dist/http/server.d.ts +20 -4
  104. package/dist/http/session-inherit-env.d.ts +37 -0
  105. package/dist/http/session-inherit-env.js +6 -0
  106. package/dist/http/wire-types.d.ts +19 -28
  107. package/dist/index.d.ts +2 -1
  108. package/dist/index.js +2 -1
  109. package/dist/key-resolver.d.ts +74 -19
  110. package/dist/key-resolver.js +65 -7
  111. package/dist/leader/leader.d.ts +6 -0
  112. package/dist/leader/leader.js +2 -1
  113. package/dist/leader/repair-wire.js +2 -1
  114. package/dist/leader/wire.d.ts +9 -1
  115. package/dist/leader/wire.js +10 -6
  116. package/dist/observability/fail-open.d.ts +5 -1
  117. package/dist/observability/fail-open.js +5 -1
  118. package/dist/observability/metrics.js +2 -0
  119. package/dist/observability/permission-rule-events.d.ts +1 -1
  120. package/dist/observability/permission-rule-events.js +1 -1
  121. package/dist/observability/run-terminal.d.ts +40 -1
  122. package/dist/observability/run-terminal.js +2 -5
  123. package/dist/observability/secret-env-scrub.js +1 -1
  124. package/dist/observability/tool-trace.d.ts +2 -0
  125. package/dist/operator-ask.d.ts +29 -1
  126. package/dist/operator-ask.js +6 -0
  127. package/dist/parked-decide.d.ts +14 -1
  128. package/dist/parked-decide.js +8 -1
  129. package/dist/plugins/session-policy-store-sql.d.ts +38 -7
  130. package/dist/plugins/session-policy-store-sql.js +64 -22
  131. package/dist/plugins/sql-driver.d.ts +1 -1
  132. package/dist/plugins/store-backend.d.ts +12 -3
  133. package/dist/plugins/store-backend.js +16 -5
  134. package/dist/plugins/tidb-pool.js +1 -1
  135. package/dist/read-face-posture.d.ts +4 -4
  136. package/dist/request-key-closure.js +2 -2
  137. package/dist/request-value-closure.d.ts +17 -5
  138. package/dist/request-value-closure.js +12 -0
  139. package/dist/router/route-orchestration.d.ts +11 -0
  140. package/dist/router/route-orchestration.js +7 -6
  141. package/dist/run-local.js +4 -2
  142. package/dist/runs.d.ts +2 -1
  143. package/dist/runs.js +4 -4
  144. package/dist/runtime-caps-resolver.d.ts +4 -10
  145. package/dist/runtime-governance.d.ts +8 -11
  146. package/dist/runtime-governance.js +10 -41
  147. package/dist/sealed-key.d.ts +0 -40
  148. package/dist/sealed-key.js +0 -20
  149. package/dist/server-secret-env.d.ts +11 -12
  150. package/dist/session-policy-wire.d.ts +5 -3
  151. package/dist/session-titler.d.ts +11 -0
  152. package/dist/session-titler.js +6 -2
  153. package/dist/sql-engine-posture.d.ts +2 -2
  154. package/dist/store-posture.d.ts +53 -0
  155. package/dist/store-posture.js +32 -0
  156. package/dist/task-settings.d.ts +64 -62
  157. package/dist/task-settings.js +57 -27
  158. package/dist/tool-approval.d.ts +51 -22
  159. package/dist/tool-approval.js +44 -8
  160. package/dist/tool-declaration-http-status.d.ts +12 -0
  161. package/dist/tool-declaration-http-status.js +12 -0
  162. package/dist/trace/core-keyset-guard.d.ts +7 -7
  163. package/dist/trace/engine-notice-wire.d.ts +1 -1
  164. package/dist/trace/engine-notice-wire.js +5 -0
  165. package/dist/trace/project.d.ts +7 -5
  166. package/dist/trace/project.js +51 -3
  167. package/dist/trace/wire-projection-faces.d.ts +1 -1
  168. package/dist/trace/wire-projection-faces.js +1 -1
  169. package/dist/unattended-permission-mode.d.ts +110 -0
  170. package/dist/unattended-permission-mode.js +65 -0
  171. package/package.json +3 -3
  172. package/dist/boot/session-shell-gate-registry.d.ts +0 -39
  173. package/dist/boot/session-shell-gate-registry.js +0 -21
  174. package/dist/roster-bound-http-status.d.ts +0 -6
  175. package/dist/roster-bound-http-status.js +0 -6
package/dist/runs.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { runWithVerification, runCascade, defaultTaskRegistry, taskNotificationDedupKey, DURABLE_AGENT_HANDLE_RE } from "@sema-agent/core";
2
2
  import { failureCodeOf, sealResultForExit, outwardPlane } from "./terminal.js";
3
3
  import { GOVERNANCE_HTTP_STATUS } from "./governance-http-status.js";
4
- import { ROSTER_BOUND_HTTP_STATUS } from "./roster-bound-http-status.js";
4
+ import { TOOL_DECLARATION_HTTP_STATUS } from "./tool-declaration-http-status.js";
5
5
  import { isSessionErrorCode, sessionErrorHttp } from "./session-error-wire.js";
6
6
  import { redactErrorMessage } from "./observability/run-terminal.js";
7
7
  import { withPrincipal } from "./observability/principal-context.js";
@@ -76,8 +76,8 @@ export function resumeAtHttpStatus(result) {
76
76
  if (Object.hasOwn(GOVERNANCE_HTTP_STATUS, code)) {
77
77
  return GOVERNANCE_HTTP_STATUS[code] ?? undefined;
78
78
  }
79
- if (Object.hasOwn(ROSTER_BOUND_HTTP_STATUS, code)) {
80
- return ROSTER_BOUND_HTTP_STATUS[code];
79
+ if (Object.hasOwn(TOOL_DECLARATION_HTTP_STATUS, code)) {
80
+ return TOOL_DECLARATION_HTTP_STATUS[code] ?? undefined;
81
81
  }
82
82
  if (isSessionErrorCode(code)) {
83
83
  const wire = sessionErrorHttp(code, "open");
@@ -208,7 +208,7 @@ export async function runInBackground(runner, spec, runStore, taskId, metrics, p
208
208
  if (approval) {
209
209
  const coordinator = approval.coordinator;
210
210
  spec.onAsk = approvalLeg.windowZero
211
- ? (askReq) => Promise.resolve(coordinator.unattendedAskOutcome({ taskId, owner: elicitOwner ?? owner, toolName: askReq.toolName }))
211
+ ? coordinator.boundUnattendedAsk({ owner: elicitOwner ?? owner, taskId, ...(spec.sessionId ? { sessionId: spec.sessionId } : {}) })
212
212
  : coordinator.boundAsk({
213
213
  owner: elicitOwner ?? owner,
214
214
  taskId,
@@ -113,18 +113,12 @@ export interface EntitlementsResolverOpts {
113
113
  *
114
114
  * `autoMode`(core 1.276.0 `RuntimeCaps.autoMode`;**[ref] / core [ref] 起三态**,黑板 [ref]/[ref]):
115
115
  * `undefined`(center 缺席/未答)= 不阻;`true` = 不阻;`false` = **org deny**(CC `permissions.disableAutoMode`
116
- * 镜像)。core 武装式 = `spec.autoModeRequested === true ∧ deps.autoMode !== undefined ∧ runtimeCaps?.autoMode !== false`
116
+ * 镜像)。core 武装式 = `spec.permissionMode === "auto" ∧ deps.autoMode !== undefined ∧ runtimeCaps?.autoMode !== false`(core 7.34.0 起;此前意图座是退役的 `autoModeRequested`)
117
117
  * ——「用户开 + org 拒」极性(此前是 `=== true` 的「org 授予」极性,无 center 的本地部署零授予路径 ⇒ auto 永不
118
118
  * 武装,真实用户诊断的病根)。
119
- * 🔴 **上面那条武装式是 [ref] 的目标形,不是「本仓现在装的那版 core 的形」——引用它之前先看装的是哪版**
120
- * ([ref]① 随 codex r2-[high] 补:我方在 WIRE 附录 F 照抄这一句,写成了「7.2.0 的行为」,而 npm **7.2.0
121
- * 不含 [ref]** —— 它的 `dist/core/runner/prepare-task.js` 逐字仍是 `runtimeCaps?.autoMode === true &&
122
- * deps.autoMode !== undefined`,即旧「org 授予」极性、**缺键 ⇒ 不武装**)。判「现在是哪套极性」的唯一判据 =
123
- * 安装包探针 `CORE_ARMS_AUTO_ON_INTENT`(`src/auto-mode-face.ts`;实测本树 7.2.0 ⇒ **false** = 旧式臂),
124
- * 代码侧已按它分臂,失实的只是散落各处的散文。⚠️ 同形措辞在本文件 :209 / :362-364 / :548 与
125
- * `src/boot/runtime-caps.ts:182` 还各有一处(均 [ref] 既有文字,本批未逐条改 —— 登记在 handoff 未闭环项)。
126
- * 所以**缺键=不写键**在这条轴上是行为承重的(在新式 core 上):补一个 false 就是替 org 说了一句
127
- * 它没说的 deny;在旧式 core 上两者同为「不武装」,差别不显形。[ref]B-6a:registry-core 0.13.0 已把 autoMode 收进 EntitlementRuntimeCaps——类型直读。 */
119
+ * ([ref]① 的历史:npm 7.2.0 不含 [ref]、是旧「org 授予」极性,本仓曾用安装包探针分臂;S-877 / core 7.34.0 起引擎只剩
120
+ * 上面这一种极性,探针随 7.106.0 退役 —— 本仓精确钉的 core 恒是它。)
121
+ * 所以**缺键=不写键**在这条轴上是行为承重的:补一个 false 就是替 org 说了一句它没说的 deny。[ref]B-6a:registry-core 0.13.0 已把 autoMode 收进 EntitlementRuntimeCaps——类型直读。 */
128
122
  export declare function toCoreRuntimeCaps(ent: EntitlementRuntimeCaps | null | undefined): RuntimeCaps | undefined;
129
123
  /**
130
124
  * #A5([ref] 件2)—— 「这台 worker 上**存在** per-principal entitlement 源吗」的**单一谓词**。
@@ -150,12 +150,12 @@ export declare function autonomyOverrides(autonomy: Autonomy | undefined): Parti
150
150
  */
151
151
  export declare function governanceMandatesShellGateAlways(governance: {
152
152
  autonomy?: Autonomy;
153
- manualModeShellGate?: "always" | "classify";
153
+ manualModeShellGate?: ShellGateDoctrine;
154
154
  }): boolean;
155
155
  /** [ref] 归因的部署侧入参(两个治理旋钮;判据属主见 {@link governanceMandatesShellGateAlways})。 */
156
156
  export interface GovernancePosture {
157
157
  autonomy?: Autonomy;
158
- manualModeShellGate?: "always" | "classify";
158
+ manualModeShellGate?: ShellGateDoctrine;
159
159
  }
160
160
  /**
161
161
  * [ref]:推「这道门是运维治理层下的吗」。判据是**合取**,两半各管一件事:
@@ -172,8 +172,9 @@ export interface GovernancePosture {
172
172
  * ⚠️ 残留(双向失真的窄在场向 + 根治路径)与「只收窄」的那一个裁决读者,都登记在
173
173
  * {@link governanceMandatesShellGateAlways} 的顶注,别在这里复述。
174
174
  *
175
- * 🔴 `"classify"` 档**刻意不标**:那一档由 core 的分类器逐调用裁决,一次 shell ask 可能出自分类器(治理)
176
- * 也可能出自 `APPROVAL_REQUIRE` 这类别的门,行上无从分辨 —— 与活卡腿同一条「宁缺毋假」纪律。
175
+ * 🔴 **形状档的 ask 刻意不标**(S-877 起它不再是一个档位词:core 7.34.0 把形状档装在**每一种模式**的全权 shell 上,
176
+ * 行上的 `shellGateDoctrine` 只在运维地板 `"always"` 铸门时出现):形状档的一次 shell ask 出自引擎自己的判断,
177
+ * 也可能叠着 `APPROVAL_REQUIRE` 这类别的门,行上无从分辨 —— 与活卡腿同一条「宁缺毋假」纪律。
177
178
  *
178
179
  * 🔴 **单一属主,四个读者**(不在任何读面另写一份判据 —— 这一位恰恰是靠「行上取证 ∧ 部署姿态」的合取才不
179
180
  * 谎报的,两份必漂):409 体的待批门材料(`http/active-run-conflict.ts`)、两条 durable 读面
@@ -196,10 +197,6 @@ export declare function governanceOriginOf(gate: {
196
197
  shellGateDoctrine?: ShellGateDoctrine;
197
198
  };
198
199
  } | undefined, governance: GovernancePosture | undefined): true | undefined;
199
- /** spec 序里的秩(0 起,越大越严)。入参收 `string`(fail-loud 边界:schema `trustRank` 同款姿势)——词表外 ⇒
200
- * RangeError,绝不 undefined/NaN 让比较静默成 false。导出只为对表钉(test/safety-merge-spec-consumption.test.ts,
201
- * [ref] 件4)——运行时消费仍走上表(键类型闭集)。 */
202
- export declare function shellGateRank(word: string): number;
203
200
  /**
204
201
  * Apply the operator's runtime governance (autonomy + commandPolicy + manualModeShellGate) onto a base
205
202
  * `TaskSpec`, TIGHTEN-ONLY, in a SINGLE {@link tightenTaskSpec} call: commandPolicy compiles to a `toolPolicy`
@@ -212,8 +209,8 @@ export declare function shellGateRank(word: string): number;
212
209
  * (task-settings deriveSettingsPolicy 的 default/auto/acceptEdits 三臂)让一个**部署级 tighten-only 旋钮
213
210
  * 的生死由客户端表态在场性决定**:body 无 settings/permissionMode(cli print/headless 腿按设计不 stamp)
214
211
  * ⇒ 旋钮静默失效(clay 实机 Monitor 案「门根本没铸」);bypassPermissions 一句话掀掉部署闸;非 host lane
215
- * fsWriteGate wiring 不建 ⇒ 沙箱 lane 全失效。governance 层与 autonomy 同拍施加后三者全闭。rank 合成:
216
- * autonomy 派生值与旋钮取大(ask→"always" 压过 "classify"),再对 base 只升不降(防 tightenTaskSpec throw)。
212
+ * fsWriteGate wiring 不建 ⇒ 沙箱 lane 全失效。governance 层与 autonomy 同拍施加后三者全闭。S-877 起地板只有
213
+ * `"always"` 一个词,合成退化成在场性(两个来源同词),不再有秩比较。
217
214
  *
218
215
  * [ref]([ref] issue #29,**邻仓 test AI 的 46 格真机矩阵**实证——不是本仓的钉,别到本仓文件里数 46;
219
216
  * 本仓的类级门是 test/operator-knob-client-posture-matrix.test.ts 的 旋钮×表态×lane 矩阵):
@@ -231,7 +228,7 @@ export declare function shellGateRank(word: string): number;
231
228
  export declare function applyRuntimeGovernance(base: TaskSpec, governance: {
232
229
  autonomy?: Autonomy;
233
230
  commandPolicy?: CommandRule[];
234
- manualModeShellGate?: "always" | "classify";
231
+ manualModeShellGate?: ShellGateDoctrine;
235
232
  sensitivePathPolicy?: ToolPolicy;
236
233
  /** [ref]/[ref] `governanceForced` 的标记表(缺省 = **当前 run 腿的 ALS 表**,见
237
234
  * `governance-ask-marks.ts` 顶注「作用域」段)。注入口只为测试与将来的多实例形。 */
@@ -1,7 +1,7 @@
1
- import { combinePolicies, COARSE_SHELL_TOOLS as CORE_COARSE_SHELL_TOOLS, createCoarseCommandNamePolicy, DEFAULT_SUBAGENT_TOOL_NAME, parseLeadingCommandName, tightenTaskSpec, } from "@sema-agent/core";
2
- import { GovernanceConfig, SAFETY_MERGE_SPEC } from "@sema-agent/settings-schema";
1
+ import { combinePolicies, COARSE_SHELL_TOOLS as CORE_COARSE_SHELL_TOOLS, createCoarseCommandNamePolicy, DEFAULT_SUBAGENT_TOOL_NAME, parseLeadingCommandName, tightenTaskSpec, wrapToolPolicy, } from "@sema-agent/core";
2
+ import { GovernanceConfig } from "@sema-agent/settings-schema";
3
3
  import { currentGovernanceAskMarks } from "./governance-ask-marks.js";
4
- import { operatorAsk } from "./operator-ask.js";
4
+ import { operatorAsk, withDeploymentAuthorship } from "./operator-ask.js";
5
5
  const COMMAND_RULE_SHAPE = GovernanceConfig.shape.commandPolicy.unwrap().element.shape;
6
6
  const COMMAND_DECISIONS = COMMAND_RULE_SHAPE.decision.options;
7
7
  export const AUTONOMY_MODES = GovernanceConfig.shape.autonomy.unwrap().options;
@@ -124,14 +124,12 @@ export function governanceOriginOf(gate, governance) {
124
124
  function createGovernanceAskMarkingPolicy(inner, marksOf) {
125
125
  const note = (d, req) => {
126
126
  marksOf()?.setMarked(req.toolCallId, d.action === "ask");
127
- return d;
128
- };
129
- return {
130
- check(req, signal) {
131
- const decision = inner.check(req, signal);
132
- return decision instanceof Promise ? decision.then((d) => note(d, req)) : note(decision, req);
133
- },
127
+ return d.action === "ask" ? withDeploymentAuthorship(d) : d;
134
128
  };
129
+ return wrapToolPolicy(inner, (req, signal) => {
130
+ const decision = inner.check(req, signal);
131
+ return decision instanceof Promise ? decision.then((d) => note(d, req)) : note(decision, req);
132
+ });
135
133
  }
136
134
  function createGovernanceShellGateMarkPolicy(marksOf, tools = COARSE_SHELL_TOOLS) {
137
135
  const shellTools = new Set(tools);
@@ -143,28 +141,6 @@ function createGovernanceShellGateMarkPolicy(marksOf, tools = COARSE_SHELL_TOOLS
143
141
  },
144
142
  };
145
143
  }
146
- const SHELL_GATE_RANK = (() => {
147
- const tighten = SAFETY_MERGE_SPEC.shellGate.tighten;
148
- const rule = tighten.rule;
149
- if (tighten.rule !== "enumRank")
150
- throw new Error(`SAFETY_MERGE_SPEC.shellGate.tighten.rule=${rule} — 不是 enumRank,shellGate 秩无从派生`);
151
- const table = { off: -1, classify: -1, always: -1 };
152
- for (const [i, w] of tighten.order.entries()) {
153
- if (!(w in table))
154
- throw new Error(`SAFETY_MERGE_SPEC.shellGate 序里有本仓词表外的词:${w}`);
155
- table[w] = i;
156
- }
157
- for (const [w, r] of Object.entries(table))
158
- if (r < 0)
159
- throw new Error(`SAFETY_MERGE_SPEC.shellGate 序缺词:${w}`);
160
- return table;
161
- })();
162
- export function shellGateRank(word) {
163
- const r = SHELL_GATE_RANK[word];
164
- if (r === undefined)
165
- throw new RangeError(`unknown shellGate word: ${word}`);
166
- return r;
167
- }
168
144
  export function applyRuntimeGovernance(base, governance) {
169
145
  const marksOf = () => governance.askMarks ?? currentGovernanceAskMarks();
170
146
  const overrides = { ...autonomyOverrides(governance.autonomy) };
@@ -175,15 +151,8 @@ export function applyRuntimeGovernance(base, governance) {
175
151
  : undefined;
176
152
  if (governancePolicy !== undefined)
177
153
  overrides.toolPolicy = governancePolicy;
178
- if (governance.manualModeShellGate !== undefined) {
179
- const candidate = overrides.shellGate !== undefined && SHELL_GATE_RANK[overrides.shellGate] >= SHELL_GATE_RANK[governance.manualModeShellGate]
180
- ? overrides.shellGate
181
- : governance.manualModeShellGate;
182
- if (SHELL_GATE_RANK[candidate] >= SHELL_GATE_RANK[base.shellGate ?? "off"])
183
- overrides.shellGate = candidate;
184
- else
185
- delete overrides.shellGate;
186
- }
154
+ if (governance.manualModeShellGate === "always")
155
+ overrides.shellGate = "always";
187
156
  if (overrides.shellGate === "always") {
188
157
  const shellObserver = createGovernanceShellGateMarkPolicy(marksOf);
189
158
  overrides.toolPolicy = governancePolicy === undefined ? shellObserver : combinePolicies(governancePolicy, shellObserver);
@@ -50,46 +50,6 @@ export interface SealedKeyCapability {
50
50
  * omits the key entirely (present-iff this process built its custody store — see the route for the two meanings
51
51
  * of absence). */
52
52
  export declare function projectSealedKeyCapability(face: SealedKeyPublicFace | undefined): SealedKeyCapability | undefined;
53
- /** Why a model's sealed key could not be unsealed (the poison-pill diagnosis, see SealedKeyPoison). CUSTODY failures only:
54
- * a sealedApiKey that is malformed (alg other than the pinned v1 SEALED_KEY_ALG, non-base64 ciphertext) makes the whole
55
- * catalog entry unavailable instead (S-704 `config.model_entry_invalid`, settings-schema `SealedApiKey` is the shape
56
- * owner) — the former `unsupported_alg` reason was retired with that move (it could no longer be reached). */
57
- export type SealedKeyPoisonReason = "sealed_decrypt_failed" | "stale_ciphertext" | "no_key_store";
58
- /**
59
- * Poison-pill entry for the per-model key map (`config.modelApiKeys`): planted by applyEffective when
60
- * a model CARRIES `sealedApiKey` but the ciphertext cannot be unsealed. We deliberately do NOT drop
61
- * the model from the map — dropping made "sealed key broken" indistinguishable from "no per-model key
62
- * configured", and when the deployment also has a gateway MODEL_API_KEY the model's tasks silently
63
- * fell back onto the shared account (the exact hole the no-apiKeyEnv-fallback contract exists to
64
- * close). createKeyResolver turns this marker into a task-level `SealedKeyPoisonedError` — never
65
- * `undefined`, because undefined IS the "use the gateway key" semantic. Carries DIAGNOSIS only:
66
- * never the ciphertext, never any plaintext.
67
- */
68
- export interface SealedKeyPoison {
69
- readonly sealedKeyPoison: true;
70
- readonly publicKeyId: string;
71
- readonly reason: SealedKeyPoisonReason;
72
- /** Error CLASS of the unseal failure (e.g. "Error") — never the message (message text is logged
73
- * at plant time; keeping the object minimal keeps every serialization face trivially secret-free). */
74
- readonly errKind?: string;
75
- /** ISO timestamp of the apply that detected the failure. */
76
- readonly at: string;
77
- }
78
- export declare function sealedKeyPoison(publicKeyId: string, reason: SealedKeyPoisonReason, errKind?: string): SealedKeyPoison;
79
- export declare function isSealedKeyPoison(v: unknown): v is SealedKeyPoison;
80
- /**
81
- * The task-level fail-loud face of a poison pill: thrown by the key resolver on EVERY brain call that
82
- * would otherwise authenticate this model, so a broken sealed key fails the task visibly (same family
83
- * as a rotation-leg auth failure) instead of silently burning the gateway account. Message carries the
84
- * sealed-failure marker (reason + publicKeyId + detection time) plus the operator fix — and nothing
85
- * secret (no ciphertext, no plaintext, by construction of SealedKeyPoison).
86
- */
87
- export declare class SealedKeyPoisonedError extends Error {
88
- readonly publicKeyId: string;
89
- readonly reason: SealedKeyPoisonReason;
90
- readonly at: string;
91
- constructor(modelName: string, poison: SealedKeyPoison);
92
- }
93
53
  /** Default id = fingerprint of the RAW public-key bytes: `exec-<sha256(pk)[0..12) hex>`.
94
54
  * Deterministic → regenerating the id from the same key file is stable across boots. */
95
55
  export declare function deriveKeyId(publicKeyRaw: Uint8Array): string;
@@ -17,26 +17,6 @@ export function projectSealedKeyCapability(face) {
17
17
  return undefined;
18
18
  return { alg: SEALED_KEY_ALG, publicKeyId: face.latest.publicKeyId, publicKey: face.latest.publicKey };
19
19
  }
20
- export function sealedKeyPoison(publicKeyId, reason, errKind) {
21
- return { sealedKeyPoison: true, publicKeyId, reason, ...(errKind ? { errKind } : {}), at: new Date().toISOString() };
22
- }
23
- export function isSealedKeyPoison(v) {
24
- return typeof v === "object" && v !== null && v.sealedKeyPoison === true;
25
- }
26
- export class SealedKeyPoisonedError extends Error {
27
- publicKeyId;
28
- reason;
29
- at;
30
- constructor(modelName, poison) {
31
- super(`sealed api key for model "${modelName}" is unusable (${poison.reason}; publicKeyId "${poison.publicKeyId}"; detected ${poison.at}) — ` +
32
- `refusing the gateway-key fallback. Fix custody: re-paste the key in the web UI (it seals against the newest registered public key), ` +
33
- `or restore this host's private key for that id / complete the rotation so the ciphertext targets a held key.`);
34
- this.name = "SealedKeyPoisonedError";
35
- this.publicKeyId = poison.publicKeyId;
36
- this.reason = poison.reason;
37
- this.at = poison.at;
38
- }
39
- }
40
20
  export function deriveKeyId(publicKeyRaw) {
41
21
  return `exec-${createHash("sha256").update(publicKeyRaw).digest("hex").slice(0, 12)}`;
42
22
  }
@@ -69,9 +69,9 @@ export declare const CATALOG_SECRET_ENV_NAMES: ReadonlySet<string>;
69
69
  * 目录臂的计数恰好就是 core 形状规则的缺口读数;名单型旋钮臂只记前两臂都漏下的(今天 = 不在服务目录里的 `BAKE_ENV_ALLOW`)。
70
70
  * 各腿不直接调它 —— 经 {@link hostSubprocessEnv}(剥 + 放回 + 留痕一只口)。
71
71
  *
72
- * **只为宿主子进程组合**:子进程与本进程同平台 ⇒ core `scrubSecretEnv` 的平台尾参(core 7.33.6 #1159:git 的 env 配置记录按子进程的平台读 ——
73
- * POSIX 只认大写名,win32 大小写折叠)取缺省 `process.platform` 即对。本包跑在别的平台上的子进程(ssh / k8s / adb / e2b / docker 车道)的 env
74
- * 不经本函数:那些车道不继承本进程 env,只交调用方显式给的 env 与部署方点名的键(`E2B_SANDBOX_ENV` / `DOCKER_SANDBOX_ENV`,经 {@link allowlistedEnv})。
72
+ * **只为宿主子进程组合**。本包跑在别的平台上的子进程(ssh / k8s / adb / e2b / docker 车道)的 env 不经本函数:那些车道不继承本进程 env,只交
73
+ * 调用方显式给的 env 与部署方点名的键(`E2B_SANDBOX_ENV` / `DOCKER_SANDBOX_ENV`,经 {@link allowlistedEnv})。(core 7.33.6 #1159 的平台尾参随
74
+ * core 7.35.0 #1201 删除 —— git 的 env 配置族成了豁免族,不再有「按子进程平台读记录」这件事,S-877。)
75
75
  */
76
76
  export declare function scrubServerSecrets(env: NodeJS.ProcessEnv, findings: ServerSecretEnvFinding[]): NodeJS.ProcessEnv;
77
77
  /**
@@ -87,15 +87,14 @@ export declare function scrubServerSecrets(env: NodeJS.ProcessEnv, findings: Ser
87
87
  * 返回 `NodeJS.ProcessEnv` 形(值可能是 `undefined` 的键本来就不会进子进程);调用方显式要交的键(`LC_ALL`、`cfg.env` …)叠在它之上。
88
88
  * 调用时机 = 每次要交 env 时现算一次(`process.env` 在本仓是 boot 期输入,各次同值;计数因此是「每组合一次」)。
89
89
  *
90
- * 🔴 **git 的 env 配置组(`GIT_CONFIG_COUNT` + `GIT_CONFIG_KEY_<i>` / `GIT_CONFIG_VALUE_<i>`)只有 core 一只写手**(7.103.1:车PG 退役本层,车PK 提 core 7.33.6):
91
- * 一条配置(KEY + VALUE)一次判定;COUNT 以内被扣的一条**原位**换占位(`GIT_CONFIG_KEY_<i>=sema.withheld` / `GIT_CONFIG_VALUE_<i>=""`,git 读成一条没人用的
92
- * 配置)、不重排、COUNT 原样(#1160);COUNT 之外 / 没有 COUNT 的被扣条目整条不交;COUNT 按 git 的 `strtoul` 读(#1162);记录按子进程的平台读(#1159,见
93
- * {@link scrubServerSecrets})。本层 7.103.0 的「整组扣」与 7.103.1 中间态的「按 pair 扣留 + 重编号」(D-7)都已退役,本层不重判(同一语义面上不留第二只写手)。
94
- * 本仓按名两臂(目录 secret 名 / 名单型旋钮)不含这一族的名字(钉:`test/secret-env-git-config-pair.test.ts`「一只写手」格)。
95
- * 点名放回按名叠在 scrub 结果之上 ⇒ 放回一条被扣配置要把 KEY 与 VALUE 两只一并点名(只点一只 = 与另一只的占位半条配成一对)。
96
- * 🔴 **披露谓词 = 「这个名字没有按原样交给子进程」**(输入值 vs 输出值;core 7.33.6 pickup 注:「not handed on as written」)。被扣的记录成员在输出里
97
- * **仍在**(装着占位半条)⇒「组合结果里有没有这个名字」恒为有;点名放回的名字取回源值 ⇒ 与输入同值 ⇒ 不是剥除;占位半条恰与输入同值的成员(KEY 里
98
- * 带凭据、VALUE 本就是空串)子进程拿到的正是原值 ⇒ 也不披露。一只谓词盖住「剥掉」「换占位」「点名放回」三形,不按形分臂。
90
+ * 🔴 **git 的 env 配置族与代理变量一族只有 core 一只写手**:core 7.35.0 #1201(S-877,CC 2.1.280 形)起它们是 core 的**豁免族** ——
91
+ * `GIT_CONFIG_COUNT` / `GIT_CONFIG_PARAMETERS` / `GIT_CONFIG_KEY_<数字>` / `GIT_CONFIG_VALUE_<数字>`(大写)与 `http(s)_proxy` / `all_proxy` / `no_proxy` /
92
+ * `npm_config_*proxy` …(任意大小写),名与值都不读、**原样交出,凭据在内**(7.33.2–7.33.8 的逐条扣 / 原位占位 `sema.withheld` / 整只扣全部退役;
93
+ * 部署面:凭据不放本进程 env —— `docs/DEPLOY-PREREQS.md`)。本层 7.103.0 的「整组扣」与 7.103.1 中间态的「按 pair 扣留 + 重编号」(D-7)更早退役,
94
+ * 本层不重判(同一语义面上不留第二只写手;在下游把 core 的豁免改回扣 = 源头修复宪法禁止的改写)。本仓按名两臂(目录 secret 名 / 名单型旋钮)不含
95
+ * `GIT_CONFIG_` 这一族的名字(钉:`test/secret-env-git-config-pair.test.ts`「一只写手」格)。
96
+ * 🔴 **披露谓词 = 「这个名字没有按原样交给子进程」**(输入值 vs 输出值)。core 对一个变量的动作恒为「整只删」(从不改写值,#1201),点名放回的名字
97
+ * 取回源值 ⇒ 与输入同值 ⇒ 不是剥除。一只谓词盖住「剥掉」「点名放回」两形,不按形分臂(7.33.6–7.33.8 还有第三形「换占位」,随 #1201 消失)。
99
98
  */
100
99
  export declare function hostSubprocessEnv(o: {
101
100
  site: SecretEnvScrubSite;
@@ -61,15 +61,17 @@ export type ToolNameRuleField = {
61
61
  * ⚠️ **比准备阶段严一格**(方向安全,与 client-core 0.83.6 的 KL-157 同向):准备阶段对**本 run 名册里挂着**的
62
62
  * 同名工具放行(部署自己挂了一只叫 `Task` 的工具就不审计它),写口看不到将来哪一跑的名册 ⇒ 一律拒。
63
63
  * 受伤的是「部署自带与退役名同名的工具、又要在会话规则里点它」的形;出路 = 部署级工具策略(不经会话规则店)。
64
- * ⚠️ **过渡形**:core 已表态(#1156,7.34.1)把这两臂抽成一只导出纯函数并在会话规则店写口即拒 —— 到货后本函数
65
- * 换成调 core 那只(拒因原样透传),三份判定收成一份。
64
+ * ⚠️ **过渡形**:core 已表态(#1156)把这两臂抽成一只导出纯函数并在会话规则店写口即拒 —— 到货后本函数
65
+ * 换成调 core 那只(拒因原样透传),三份判定收成一份。**S-877 提货复核(core 7.35.0)**:#1156 **未随版**(发车帖 [ref] 逐字
66
+ * 「照 #1156 未随本版」);同版新导出的 `rosterToolName` / `ruleNamesOf`(#1194)是**别名归一**(一个名字在名册上落到哪只行的线名 /
67
+ * 一次调用可被规则拼成的名字集),不回答「这个名字会不会让准备阶段拒启」,不能替本函数 ⇒ 本函数照留,等 #1156。
66
68
  *
67
69
  * 🔴 **为什么不复用 `config.ts` 的 `findUnmatchableToolNames`**(本仓另一只按名字判的单点;读过实现后裁):两只回答的
68
70
  * 不是同一个问题。那一只问「部署名单里这条名字会不会**永远匹配不上**活工具」—— 它刻意豁免 `allow`(白名单匹配不上 =
69
71
  * fail-closed 且当场可见),并且拒两段 MCP 名 `mcp__srv`(一名两义)与 core 文法编不出的串。本函数问的是「引擎见到这条
70
72
  * 会话规则会不会**拒启**」:引擎准备阶段的名审计对 `allow` 桶照样抛(豁免它 = 放过一条砖化路径),对 `mcp__srv` 却
71
73
  * **不**抛(会话层自 core 5.55 / 5.56 起把它当整对端覆盖形真命中)。判据只能逐字跟 core 那两臂走,不能借另一只的口径。
72
- * 两只在「退役名」「无前缀 `__` 名」两臂上同源(都读 core 导出的同两件),7.34.1 提货时一并换调 core 的导出函数。
74
+ * 两只在「退役名」「无前缀 `__` 名」两臂上同源(都读 core 导出的同两件),#1156 到货的那一批一并换调 core 的导出函数。
73
75
  */
74
76
  export type LegacyToolName = {
75
77
  why: "retired";
@@ -54,6 +54,17 @@ export interface SessionTitler {
54
54
  export declare const TITLE_MAX_CHARS = 80;
55
55
  /** Single line, control chars stripped, hard cap; surrounding quotes (a common LLM tic) trimmed. */
56
56
  export declare function sanitizeTitle(raw: string): string;
57
+ /**
58
+ * S-236 ②(7.106.0,cli L-687)—— objective 里**用户自己写的**那部分:剥掉全部 `<system-reminder>…</system-reminder>` 块(跨行、
59
+ * 多块、夹在正文中间都剥;**未闭合**的块剥到末尾 —— 被截断的附件同样不是用户写的)后 trim。
60
+ *
61
+ * 为什么:壳把附件(技能清单一类的 `<system-reminder>` 块)拼在正文**之前**提交,标题器取前 {@link OBJECTIVE_SNIPPET_CHARS} 字
62
+ * 去起名 ⇒ 标题成了技能清单。判据只认这一个**字面标签**(CC 的附件信封),不按内容猜「像不像用户写的」——
63
+ * 正文里提到这个词的普通文字不是块,原样保留。剥完是空串 ⇒ 调用方走「空 objective 不起名」的既有臂。
64
+ * ⚠️ 只治这一类:S-236 原件(fresh `/decide` 腿把指路文本当 objective 提交)是另一类非用户文本,没有信封可剥,本函数刻意不加
65
+ * 按内容猜的第二臂(要么 fresh 腿传席,要么另立一臂 —— 候裁,见车RA 收车档)。
66
+ */
67
+ export declare function userAuthoredObjectiveText(objective: string): string;
57
68
  export declare function buildTitlePrompt(objective: string): string;
58
69
  export declare function createSessionTitler(deps: SessionTitlerDeps): SessionTitler;
59
70
  //# sourceMappingURL=session-titler.d.ts.map
@@ -12,8 +12,12 @@ export function sanitizeTitle(raw) {
12
12
  const unquoted = oneLine.replace(/^["'「『]+/, "").replace(/["'」』]+$/, "").trim();
13
13
  return unquoted.length > TITLE_MAX_CHARS ? `${unquoted.slice(0, TITLE_MAX_CHARS - 1)}…` : unquoted;
14
14
  }
15
+ export function userAuthoredObjectiveText(objective) {
16
+ return objective.replace(/<system-reminder>[\s\S]*?(?:<\/system-reminder>|$)/g, "").trim();
17
+ }
15
18
  export function buildTitlePrompt(objective) {
16
- const snippet = objective.length > OBJECTIVE_SNIPPET_CHARS ? `${objective.slice(0, OBJECTIVE_SNIPPET_CHARS)}…` : objective;
19
+ const text = userAuthoredObjectiveText(objective);
20
+ const snippet = text.length > OBJECTIVE_SNIPPET_CHARS ? `${text.slice(0, OBJECTIVE_SNIPPET_CHARS)}…` : text;
17
21
  const fenced = snippet.replace(/<(\/?)request>/gi, "<\u200b$1request>");
18
22
  return ("Write a short title (at most 8 words) summarizing the user request below. " +
19
23
  "Reply with ONLY the title on a single line — no quotes, no preamble. " +
@@ -34,7 +38,7 @@ export function createSessionTitler(deps) {
34
38
  .catch(() => ({ state: continueWord, unreadable: true }));
35
39
  return {
36
40
  maybeTitle(sessionId, objective, model) {
37
- if (!sessionId || !objective.trim())
41
+ if (!sessionId || !userAuthoredObjectiveText(objective))
38
42
  return;
39
43
  if (seen.has(sessionId))
40
44
  return;
@@ -11,7 +11,7 @@
11
11
  *
12
12
  * `sql-driver.ts` 的连接初始化在**每条池连接**上钉死这两件事并**回读复核**(`@contract txn.read-semantics`)。
13
13
  * 本模块把那份读数拿出来,一次推导两个读面:operator 面(`GET /v1/diagnostics/wiring` 的 `sqlEngine` 段,
14
- * 全量)与消费端面(`GET /v1/capabilities` 的 `sql` 位,窄投影)。两面同源 —— 「诊断页说悲观、能力位说
14
+ * 全量)与消费端面(`GET /v1/capabilities` 的 `store.sql` 位(7.106.0 起;此前顶层 `sql`,S-866 ①),窄投影)。两面同源 —— 「诊断页说悲观、能力位说
15
15
  * 乐观」在结构上不可能。
16
16
  *
17
17
  * ## 两条诚实纪律(与 memory-posture 同源)
@@ -27,7 +27,7 @@
27
27
  import { type SqlEngineFacts } from "./plugins/sql-driver.js";
28
28
  import type { Pool as MySqlPool } from "mysql2/promise";
29
29
  import type { Pool as PgPool } from "pg";
30
- /** 消费端窄投影(`GET /v1/capabilities` 的 `sql` 位)。`null` = 本部署没有 SQL 后端。 */
30
+ /** 消费端窄投影(`GET /v1/capabilities` 的 `store.sql` 位;7.106.0 前是顶层 `sql`,S-866 ①)。`null` = 驱动此刻给不出事实 ⇒ `store.sql` 缺席。 */
31
31
  export interface SqlEngineCapability {
32
32
  engine: SqlEngineFacts["engine"];
33
33
  isolation: string;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * S-866 ①(设计稿 v1.1 §2①)—— 「这台副本**真的在持久化吗**」的单一推导点:caps `store`、`/health.storeDegraded` / `durable:false`、
3
+ * gauge `store_backend_degraded` 三面读**同一只装配值**({@link StorePosture},`boot/stores.ts` 铸一次)。
4
+ *
5
+ * ## 病
6
+ * 7.105.0 及以前,店降级的痕迹是 gauge + `/health` 两位 + caps `sql:null` —— 而 `sql:null` 同时是「本来就没配 SQL」「local 文件店」
7
+ * 「降级到内存」「最近一次连接初始化被拒」四件事;调用方分不清「以为在持久化,其实在内存」这最坏的一形。
8
+ *
9
+ * ## 形
10
+ * `declared` = 运维的声明(`DB_BACKEND` 词,含缺省推导);`backend` = **装配出的**后端 kind(没装出后端 = `memory`);两者不等是合法的
11
+ * 形(`DB_BACKEND=pg` + `SESSION_BACKEND=memory` = 声明 pg、刻意不持久;auto 降级;缺省推导 local 起不来)—— 两位都上 wire,
12
+ * 由调用方自己读出落差。`degradedReason` present-iff 降级臂走过(按后端族定词,{@link storeDegradedReasonFor})。
13
+ * 顶层 `sql` 并入 `store.sql`(硬 breaking,零别名;对象逐字同形)。
14
+ */
15
+ import { type DbBackendWord } from "./config-types.js";
16
+ import type { StoreBackend } from "./plugins/store-backend.js";
17
+ import type { SqlEngineFacts } from "./plugins/sql-driver.js";
18
+ import { type SqlEngineCapability } from "./sql-engine-posture.js";
19
+ /**
20
+ * 降级词闭集(**按后端族**,不按失败发生在哪一步 —— SQL 池懒连,连接失败第一次就出现在 `ensureSchema` 里,与 DDL 失败同一个调用,
21
+ * 按调用位置分不出「连不上」与「建表失败」):
22
+ * · `db_unreachable` —— SQL 族(`mysql` / `pg`)在 `SESSION_BACKEND=auto` 下打不开(连接或建表);
23
+ * · `local_unwritable` —— **缺省推导**的 local 文件店构造期失败(mkdir / 数据根锁 / 权限 / 只读挂载 / 磁盘满)。
24
+ */
25
+ export declare const STORE_DEGRADED_REASONS: readonly ["db_unreachable", "local_unwritable"];
26
+ export type StoreDegradedReason = (typeof STORE_DEGRADED_REASONS)[number];
27
+ /** 降级臂按后端族定词(穷举 switch:词表加员 ⇒ 编译红)。`memory` 从不尝试打开后端,走不到降级臂 —— 到了就是装配缺陷,响亮抛。 */
28
+ export declare function storeDegradedReasonFor(declared: DbBackendWord): StoreDegradedReason;
29
+ /** 装配值(纯数据;`boot/stores.ts` 铸一次,gauge / `/health` / caps 三面同读)。 */
30
+ export interface StorePosture {
31
+ readonly declared: DbBackendWord;
32
+ readonly backend: DbBackendWord;
33
+ readonly degradedReason?: StoreDegradedReason;
34
+ }
35
+ /** `build*`(纯数据)。`assembled` = 装配出的 `StoreBackend.kind`;缺席 = 没装出后端 ⇒ `memory`。 */
36
+ export declare function buildStorePosture(a: {
37
+ readonly declared: DbBackendWord;
38
+ readonly assembled: StoreBackend["kind"] | undefined;
39
+ readonly degradedReason: StoreDegradedReason | undefined;
40
+ }): StorePosture;
41
+ /** caps `store` 的形。 */
42
+ export interface StoreCapability {
43
+ readonly declared: DbBackendWord;
44
+ readonly backend: DbBackendWord;
45
+ readonly durable: boolean;
46
+ readonly degradedReason?: StoreDegradedReason;
47
+ /** 7.105.0 及以前的顶层 `sql` 对象,原样搬入(`{engine, isolation, txnMode}`)。present-iff `backend ∈ {mysql, pg}` ∧ 驱动此刻给得出
48
+ * 回读复核过的事实 —— 最近一次连接初始化被拒(S-137 ④)时驱动交 `null`,本键随之缺席(此前是顶层 `sql:null`)。 */
49
+ readonly sql?: SqlEngineCapability;
50
+ }
51
+ /** 装配值 → caps 投影(纯函数)。 */
52
+ export declare function projectStoreCapability(posture: StorePosture, sqlFacts: SqlEngineFacts | null | undefined): StoreCapability;
53
+ //# sourceMappingURL=store-posture.d.ts.map
@@ -0,0 +1,32 @@
1
+ import {} from "./config-types.js";
2
+ import { projectSqlEngineCapability } from "./sql-engine-posture.js";
3
+ export const STORE_DEGRADED_REASONS = ["db_unreachable", "local_unwritable"];
4
+ export function storeDegradedReasonFor(declared) {
5
+ switch (declared) {
6
+ case "mysql":
7
+ case "pg":
8
+ return "db_unreachable";
9
+ case "local":
10
+ return "local_unwritable";
11
+ case "memory":
12
+ throw new Error("store posture: DB_BACKEND=memory never opens a backend, so it cannot degrade — this is a wiring defect");
13
+ default: {
14
+ const unhandled = declared;
15
+ throw new Error(`store posture: unknown DB_BACKEND word ${String(unhandled)}`);
16
+ }
17
+ }
18
+ }
19
+ export function buildStorePosture(a) {
20
+ return { declared: a.declared, backend: a.assembled ?? "memory", ...(a.degradedReason !== undefined ? { degradedReason: a.degradedReason } : {}) };
21
+ }
22
+ export function projectStoreCapability(posture, sqlFacts) {
23
+ const sql = posture.backend === "mysql" || posture.backend === "pg" ? projectSqlEngineCapability(sqlFacts) : null;
24
+ return {
25
+ declared: posture.declared,
26
+ backend: posture.backend,
27
+ durable: posture.backend !== "memory",
28
+ ...(posture.degradedReason !== undefined ? { degradedReason: posture.degradedReason } : {}),
29
+ ...(sql !== null ? { sql } : {}),
30
+ };
31
+ }
32
+ //# sourceMappingURL=store-posture.js.map