@sema-agent/server 4.3.0 → 5.0.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.
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/USAGE.md +16 -16
- package/dist/approval-hmac.js +1 -1
- package/dist/approval.d.ts +17 -37
- package/dist/approval.js +26 -112
- package/dist/auth-bridge.d.ts +0 -1
- package/dist/auth-bridge.js +0 -1
- package/dist/auth-keys.d.ts +1 -1
- package/dist/auth-keys.js +1 -1
- package/dist/bench/s1/run-firm.js +1 -1
- package/dist/boot/config-center.d.ts +1 -1
- package/dist/boot/config-center.js +4 -3
- package/dist/boot/reapers.d.ts +1 -2
- package/dist/boot/reapers.js +4 -5
- package/dist/boot/resolve-spec.d.ts +1 -3
- package/dist/boot/resolve-spec.js +21 -35
- package/dist/boot/stores.js +1 -1
- package/dist/brain.js +3 -1
- package/dist/capabilities/center-prompts.d.ts +2 -3
- package/dist/capabilities/center-prompts.js +2 -3
- package/dist/capabilities/sandbox-file-send.d.ts +0 -2
- package/dist/capabilities/sandbox-file-send.js +2 -5
- package/dist/capabilities/scenarios.d.ts +2 -13
- package/dist/capabilities/scenarios.js +3 -22
- package/dist/capabilities/send-user-file-tool.js +3 -3
- package/dist/config-center/apply-effective.js +51 -13
- package/dist/config-center/types.d.ts +10 -3
- package/dist/config-provider.d.ts +1 -1
- package/dist/config-provider.js +6 -11
- package/dist/config-types.d.ts +15 -29
- package/dist/config.d.ts +28 -0
- package/dist/config.js +122 -68
- package/dist/fleet/fleet-bus.d.ts +1 -1
- package/dist/fleet/fleet-bus.js +25 -33
- package/dist/fleet-client.js +1 -1
- package/dist/http/active-run-conflict.d.ts +2 -0
- package/dist/http/active-run-conflict.js +1 -0
- package/dist/http/routes/approvals-assistant.d.ts +2 -1
- package/dist/http/routes/approvals-assistant.js +10 -96
- package/dist/http/routes/capabilities.js +6 -5
- package/dist/http/routes/fleet.js +7 -2
- package/dist/http/routes/images.js +10 -4
- package/dist/http/routes/runs.js +42 -65
- package/dist/http/routes/session-sync.d.ts +1 -1
- package/dist/http/routes/session-sync.js +2 -1
- package/dist/http/routes/tasks.js +7 -7
- package/dist/http/routes/trace-usage.js +1 -1
- package/dist/http/routes/workflows.js +3 -1
- package/dist/http/server.d.ts +1 -6
- package/dist/http/server.js +15 -10
- package/dist/http/verify-rounds.d.ts +2 -2
- package/dist/http/wire-types.d.ts +1 -1
- package/dist/images/bake-validate.d.ts +0 -22
- package/dist/images/bake-validate.js +0 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -5
- package/dist/main.js +9 -10
- package/dist/memory-scope.d.ts +1 -2
- package/dist/memory-scope.js +8 -4
- package/dist/orchestration/workflow-completion-inbox.d.ts +6 -4
- package/dist/orchestration/workflow-completion-inbox.js +6 -4
- package/dist/plugins/breaker-state-sql.d.ts +2 -3
- package/dist/plugins/file-run-store.d.ts +1 -1
- package/dist/plugins/file-run-store.js +1 -1
- package/dist/plugins/image-index-sql.d.ts +0 -1
- package/dist/plugins/image-index-sql.js +0 -1
- package/dist/plugins/local-checkpoint-store.d.ts +1 -1
- package/dist/plugins/local-checkpoint-store.js +1 -1
- package/dist/plugins/memory-engine-pg.js +2 -1
- package/dist/plugins/memory-engine-tidb.js +1 -1
- package/dist/plugins/memory-engine-vector-util.d.ts +2 -3
- package/dist/plugins/memory-engine-vector-util.js +2 -3
- package/dist/plugins/memory-run-store.d.ts +2 -2
- package/dist/plugins/memory-run-store.js +1 -1
- package/dist/plugins/memory-session-policy-store.d.ts +1 -1
- package/dist/plugins/memory-session-policy-store.js +1 -1
- package/dist/plugins/memory-sync-store-pg.js +1 -1
- package/dist/plugins/pg-pool.js +8 -10
- package/dist/plugins/pg-rate-limiter.d.ts +1 -4
- package/dist/plugins/pg-rate-limiter.js +0 -1
- package/dist/plugins/roster-store-sql.d.ts +1 -3
- package/dist/plugins/roster-store-sql.js +3 -5
- package/dist/plugins/store-backend.d.ts +7 -17
- package/dist/plugins/store-backend.js +14 -30
- package/dist/plugins/tidb-pool.js +6 -30
- package/dist/plugins/workflow-journal-store-sql.d.ts +1 -1
- package/dist/plugins/workflow-journal-store-sql.js +1 -1
- package/dist/principal-jwt.js +2 -2
- package/dist/prompts-domain-validate.d.ts +4 -3
- package/dist/prompts-domain-validate.js +7 -8
- package/dist/router/route-orchestration.js +3 -3
- package/dist/run-local.js +13 -10
- package/dist/runs.js +8 -6
- package/dist/runtime-caps-resolver.d.ts +3 -2
- package/dist/runtime-caps-resolver.js +4 -4
- package/dist/runtime-governance.d.ts +4 -7
- package/dist/runtime-governance.js +12 -17
- package/dist/sealed-key.d.ts +1 -1
- package/dist/sealed-key.js +1 -1
- package/dist/security.d.ts +0 -5
- package/dist/security.js +8 -12
- package/dist/session-sync.d.ts +0 -2
- package/dist/session-sync.js +10 -17
- package/dist/spec-fields.js +6 -6
- package/dist/task-settings.d.ts +0 -27
- package/dist/task-settings.js +42 -11
- package/dist/tool-approval.d.ts +3 -3
- package/dist/tool-approval.js +10 -10
- package/dist/trace/artifacts.d.ts +11 -0
- package/dist/trace/artifacts.js +8 -19
- package/dist/trace/ledger-sink.js +7 -1
- package/dist/trace/project.d.ts +17 -0
- package/dist/trace/project.js +58 -5
- package/package.json +3 -3
- package/dist/capabilities/oa-tools.d.ts +0 -15
- package/dist/capabilities/oa-tools.js +0 -54
- package/dist/plugins/approval-store-sql.d.ts +0 -116
- package/dist/plugins/approval-store-sql.js +0 -150
- package/dist/plugins/file-workflow-journal-store.d.ts +0 -12
- package/dist/plugins/file-workflow-journal-store.js +0 -12
- package/dist/plugins/pg-approval-store.d.ts +0 -9
- package/dist/plugins/pg-approval-store.js +0 -9
- package/dist/plugins/pg-breaker-state.d.ts +0 -8
- package/dist/plugins/pg-breaker-state.js +0 -8
- package/dist/plugins/pg-checkpoint-store.d.ts +0 -10
- package/dist/plugins/pg-checkpoint-store.js +0 -10
- package/dist/plugins/pg-file-snapshot-store.d.ts +0 -8
- package/dist/plugins/pg-file-snapshot-store.js +0 -8
- package/dist/plugins/pg-image-bake.d.ts +0 -12
- package/dist/plugins/pg-image-bake.js +0 -11
- package/dist/plugins/pg-image-index.d.ts +0 -12
- package/dist/plugins/pg-image-index.js +0 -11
- package/dist/plugins/pg-outcome-ledger.d.ts +0 -12
- package/dist/plugins/pg-outcome-ledger.js +0 -11
- package/dist/plugins/pg-resume-anchor-store.d.ts +0 -7
- package/dist/plugins/pg-resume-anchor-store.js +0 -7
- package/dist/plugins/pg-run-store.d.ts +0 -9
- package/dist/plugins/pg-run-store.js +0 -9
- package/dist/plugins/pg-session-policy-store.d.ts +0 -7
- package/dist/plugins/pg-session-policy-store.js +0 -7
- package/dist/plugins/pg-session-store.d.ts +0 -12
- package/dist/plugins/pg-session-store.js +0 -12
- package/dist/plugins/pg-tool-result-store.d.ts +0 -9
- package/dist/plugins/pg-tool-result-store.js +0 -9
- package/dist/plugins/pg-workflow-journal-store.d.ts +0 -9
- package/dist/plugins/pg-workflow-journal-store.js +0 -9
- package/dist/plugins/pg-workflow-run-store.d.ts +0 -9
- package/dist/plugins/pg-workflow-run-store.js +0 -9
- package/dist/plugins/tidb-approval-store.d.ts +0 -8
- package/dist/plugins/tidb-approval-store.js +0 -8
- package/dist/plugins/tidb-breaker-state.d.ts +0 -7
- package/dist/plugins/tidb-breaker-state.js +0 -7
- package/dist/plugins/tidb-checkpoint-store.d.ts +0 -9
- package/dist/plugins/tidb-checkpoint-store.js +0 -9
- package/dist/plugins/tidb-file-snapshot-store.d.ts +0 -8
- package/dist/plugins/tidb-file-snapshot-store.js +0 -8
- package/dist/plugins/tidb-image-bake.d.ts +0 -12
- package/dist/plugins/tidb-image-bake.js +0 -11
- package/dist/plugins/tidb-image-index.d.ts +0 -12
- package/dist/plugins/tidb-image-index.js +0 -11
- package/dist/plugins/tidb-outcome-ledger.d.ts +0 -12
- package/dist/plugins/tidb-outcome-ledger.js +0 -12
- package/dist/plugins/tidb-resume-anchor-store.d.ts +0 -7
- package/dist/plugins/tidb-resume-anchor-store.js +0 -7
- package/dist/plugins/tidb-run-store.d.ts +0 -10
- package/dist/plugins/tidb-run-store.js +0 -9
- package/dist/plugins/tidb-session-policy-store.d.ts +0 -7
- package/dist/plugins/tidb-session-policy-store.js +0 -7
- package/dist/plugins/tidb-tool-result-store.d.ts +0 -8
- package/dist/plugins/tidb-tool-result-store.js +0 -10
- package/dist/plugins/tidb-workflow-journal-store.d.ts +0 -9
- package/dist/plugins/tidb-workflow-journal-store.js +0 -9
- package/dist/plugins/tidb-workflow-run-store.d.ts +0 -10
- package/dist/plugins/tidb-workflow-run-store.js +0 -10
- package/dist/plugins/workflow-journal-limits.d.ts +0 -12
- package/dist/plugins/workflow-journal-limits.js +0 -12
package/dist/plugins/pg-pool.js
CHANGED
|
@@ -28,14 +28,13 @@ import pg from "pg";
|
|
|
28
28
|
// Each PG store owns its own (disjoint) tables' DDL via a standalone idempotent ensureSchema; the central apply
|
|
29
29
|
// composes them so production wires ONE ensurePgSchema (the PG twin of tidb-pool's single ensureSchema).
|
|
30
30
|
import { ensureSchema as ensureSessionSchema } from "./pg-session-storage.js";
|
|
31
|
-
import { ensureSchema as ensureToolResultSchema } from "./
|
|
31
|
+
import { ensureSchema as ensureToolResultSchema } from "./tool-result-store-sql.js";
|
|
32
32
|
import { ensureSchema as ensureCostQuotaSchema } from "./pg-cost-quota.js";
|
|
33
33
|
import { ensureSchema as ensureRateLimitSchema } from "./pg-rate-limiter.js";
|
|
34
|
-
import { ensureSchema as ensureBreakerStateSchema } from "./
|
|
35
|
-
import {
|
|
36
|
-
import { ensureSchema as
|
|
37
|
-
import {
|
|
38
|
-
import { ensureSchema as ensureImageBakeSchema } from "./pg-image-bake.js";
|
|
34
|
+
import { ensureSchema as ensureBreakerStateSchema } from "./breaker-state-sql.js";
|
|
35
|
+
import { ensurePgOutcomeLedgerSchema as ensureOutcomeLedgerSchema } from "./outcome-ledger-sql.js";
|
|
36
|
+
import { ensureSchema as ensureImageIndexSchema } from "./image-index-sql.js";
|
|
37
|
+
import { ensurePgImageBakeSchema as ensureImageBakeSchema } from "./image-bake-store-sql.js";
|
|
39
38
|
export const PG_SCHEMA_STATEMENTS = [
|
|
40
39
|
`CREATE TABLE IF NOT EXISTS task_run (
|
|
41
40
|
task_id VARCHAR(64) NOT NULL,
|
|
@@ -145,7 +144,7 @@ export const PG_SCHEMA_STATEMENTS = [
|
|
|
145
144
|
`CREATE INDEX IF NOT EXISTS idx_sendfile_link_scope ON sendfile_link (scope, id)`,
|
|
146
145
|
// E6 durable SessionPolicyStore (the PG twin of the TiDB session_policy table; policy_key = sha256(JSON.stringify(
|
|
147
146
|
// [sessionId, principal ?? null])) = a fixed 64-char hash PK; rules JSONB; CAS-versioned tighten-only — see
|
|
148
|
-
// tidb-pool.ts /
|
|
147
|
+
// tidb-pool.ts / session-policy-store-sql.ts).
|
|
149
148
|
`CREATE TABLE IF NOT EXISTS session_policy (
|
|
150
149
|
policy_key CHAR(64) NOT NULL,
|
|
151
150
|
session_id VARCHAR(64) NOT NULL,
|
|
@@ -186,7 +185,7 @@ export const PG_SCHEMA_STATEMENTS = [
|
|
|
186
185
|
// SVC-2 (core CORE-7) durable WorkflowJournalStore — the PG twin of the TiDB workflow_journal table (cross-replica
|
|
187
186
|
// resume journal; (run_id, ordinal) PK = idempotent OVERWRITE upsert; `result` = JSON.stringify(TaskResult)). `result`
|
|
188
187
|
// is TEXT, NOT JSONB — the byte-match contract is "string in, string out" (the store JSON.parses on load); JSONB would
|
|
189
|
-
// make `pg` auto-parse the row back to an object and break the twin's String()→JSON.parse path. See
|
|
188
|
+
// make `pg` auto-parse the row back to an object and break the twin's String()→JSON.parse path. See workflow-journal-store-sql.ts.
|
|
190
189
|
`CREATE TABLE IF NOT EXISTS workflow_journal (
|
|
191
190
|
run_id VARCHAR(191) NOT NULL,
|
|
192
191
|
ordinal INT NOT NULL,
|
|
@@ -210,7 +209,7 @@ export const PG_SCHEMA_STATEMENTS = [
|
|
|
210
209
|
claimed_at BIGINT NOT NULL,
|
|
211
210
|
PRIMARY KEY (source_run_id, scope)
|
|
212
211
|
)`,
|
|
213
|
-
// P1 (fleet failover): WorkflowRunStore + completion-inbox PG twins (design doc in
|
|
212
|
+
// P1 (fleet failover): WorkflowRunStore + completion-inbox PG twins (design doc in workflow-run-store-sql.ts).
|
|
214
213
|
// `run` is TEXT not jsonb (node-pg auto-parse would break the shared String()→JSON.parse path).
|
|
215
214
|
`CREATE TABLE IF NOT EXISTS workflow_run (
|
|
216
215
|
id VARCHAR(191) NOT NULL,
|
|
@@ -332,7 +331,6 @@ export async function ensurePgSchema(pool) {
|
|
|
332
331
|
await ensureCostQuotaSchema(client);
|
|
333
332
|
await ensureRateLimitSchema(client);
|
|
334
333
|
await ensureBreakerStateSchema(client);
|
|
335
|
-
await ensureApprovalSchema(client);
|
|
336
334
|
await ensureOutcomeLedgerSchema(client);
|
|
337
335
|
await ensureImageIndexSchema(client);
|
|
338
336
|
await ensureImageBakeSchema(client);
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* design/158 A12 C1b: the `PgWriteBehindCounter` this file used to define inline now lives in
|
|
10
10
|
* write-behind-counter.ts as the PG binding of ONE dialect-parameterized counter (the mysql2 twin is
|
|
11
|
-
* `WriteBehindCounter`); the SQL-dialect deltas are documented and branched there.
|
|
12
|
-
* so the historical import path keeps working.
|
|
11
|
+
* `WriteBehindCounter`); the SQL-dialect deltas are documented and branched there.
|
|
13
12
|
*
|
|
14
13
|
* Schema: this store's `rate_limit` table is DISJOINT from the other PG stores' tables, so a
|
|
15
14
|
* self-contained {@link PG_RATE_LIMITER_SCHEMA} + {@link ensureSchema} is safe (no shadowing).
|
|
@@ -17,8 +16,6 @@
|
|
|
17
16
|
import type { Pool, PoolClient } from "pg";
|
|
18
17
|
import type { RateDecision, RateGate } from "../observability/rate-limit.js";
|
|
19
18
|
import { type CounterDegradeHook } from "./write-behind-counter.js";
|
|
20
|
-
export { PgWriteBehindCounter } from "./write-behind-counter.js";
|
|
21
|
-
export type { CounterTable } from "./write-behind-counter.js";
|
|
22
19
|
export declare class PgRateLimiter implements RateGate {
|
|
23
20
|
private readonly limit;
|
|
24
21
|
private readonly counter;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { PgWriteBehindCounter } from "./write-behind-counter.js";
|
|
2
|
-
export { PgWriteBehindCounter } from "./write-behind-counter.js";
|
|
3
2
|
/** The counter's table binding for the per-key request rate limit (mirror of the TiDB twin's binding). */
|
|
4
3
|
const RATE_LIMIT_TABLE = { table: "rate_limit", keyCol: "limit_key", valCol: "n" };
|
|
5
4
|
export class PgRateLimiter {
|
|
@@ -21,11 +21,9 @@
|
|
|
21
21
|
* 是「core 变语义必须先过迁移裁量」的告警钉)。
|
|
22
22
|
*/
|
|
23
23
|
import type { Pool } from "mysql2/promise";
|
|
24
|
-
import {
|
|
24
|
+
import { type RosterStore, type RosterEntry } from "@sema-agent/core";
|
|
25
25
|
type RosterAccess = Parameters<RosterStore["resolve"]>[1];
|
|
26
26
|
import type { PgQueryFn } from "./pg-query.js";
|
|
27
|
-
/** 兼容名保留(测试/历史引用),现=core 导出直引(私拷已删)。 */
|
|
28
|
-
export declare const normalizeAgentNameLocal: typeof normalizeAgentName;
|
|
29
27
|
export declare const ROSTER_TABLE = "agent_roster";
|
|
30
28
|
export declare function ensureTiDBRosterSchema(pool: Pool): Promise<void>;
|
|
31
29
|
export declare function ensurePgRosterSchema(q: PgQueryFn): Promise<void>;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { normalizeAgentName } from "@sema-agent/core";
|
|
2
|
-
/** 兼容名保留(测试/历史引用),现=core 导出直引(私拷已删)。 */
|
|
3
|
-
export const normalizeAgentNameLocal = normalizeAgentName;
|
|
4
2
|
export const ROSTER_TABLE = "agent_roster";
|
|
5
3
|
/** 行 → RosterEntry(缺席键省略,core 形逐字;session_scoped 数值/布尔双方言归一)。
|
|
6
4
|
* core 1.365 BREAKING:owner/scope 升类型必填——两方言 CREATE 直接建成 NOT NULL(当年的「清死行 +
|
|
@@ -114,7 +112,7 @@ export async function ensurePgRosterSchema(q) {
|
|
|
114
112
|
/** upsert 参数序(两方言共用;core 1.365 起 owner/scope 类型必填——键列直取,与 core upsertKey 同键)。 */
|
|
115
113
|
function upsertParams(entry, now) {
|
|
116
114
|
return [
|
|
117
|
-
|
|
115
|
+
normalizeAgentName(entry.name),
|
|
118
116
|
entry.owner,
|
|
119
117
|
entry.scope,
|
|
120
118
|
entry.name,
|
|
@@ -148,7 +146,7 @@ export class TiDBRosterStore {
|
|
|
148
146
|
session_scoped = VALUES(session_scoped), root_session_id = VALUES(root_session_id), model = VALUES(model), created_at_ms = VALUES(created_at_ms), recorded_at_ms = VALUES(recorded_at_ms)`, p.map((v) => (typeof v === "boolean" ? (v ? 1 : 0) : v)));
|
|
149
147
|
}
|
|
150
148
|
async resolve(name, access) {
|
|
151
|
-
const key =
|
|
149
|
+
const key = normalizeAgentName(name);
|
|
152
150
|
if (key === "")
|
|
153
151
|
return undefined;
|
|
154
152
|
const [rows] = (await this.pool.query(`SELECT ${COLS} FROM ${ROSTER_TABLE} WHERE ${RESOLVE_WHERE_TIDB} ORDER BY created_at_ms DESC, recorded_at_ms DESC, agent_id DESC LIMIT 1`, [key, access.scope ?? null, access.owner ?? null, access.sessionId ?? null, access.sessionId ?? null]));
|
|
@@ -185,7 +183,7 @@ export class PgRosterStore {
|
|
|
185
183
|
recorded_at_ms = EXCLUDED.recorded_at_ms`, upsertParams(entry, this.clock()));
|
|
186
184
|
}
|
|
187
185
|
async resolve(name, access) {
|
|
188
|
-
const key =
|
|
186
|
+
const key = normalizeAgentName(name);
|
|
189
187
|
if (key === "")
|
|
190
188
|
return undefined;
|
|
191
189
|
const { rows } = await this.q(`SELECT ${COLS} FROM ${ROSTER_TABLE} WHERE ${RESOLVE_WHERE_PG} ORDER BY created_at_ms DESC, recorded_at_ms DESC, agent_id DESC LIMIT 1`, [key, access.scope ?? null, access.owner ?? null, access.sessionId ?? null, access.sessionId ?? null]);
|
|
@@ -3,27 +3,19 @@ import type { Pool as PgPool } from "pg";
|
|
|
3
3
|
import type { SessionStore, SessionPolicyStore, FileSnapshotStore, WorkflowJournalStore, ToolResultStore } from "@sema-agent/core";
|
|
4
4
|
import { type FileSnapshotBounds } from "@sema-agent/core";
|
|
5
5
|
import { type OutcomeSink } from "./file-outcome-sink.js";
|
|
6
|
-
import { type InboxWarn } from "./
|
|
6
|
+
import { type InboxWarn } from "./workflow-run-store-sql.js";
|
|
7
7
|
import { FileRunStore } from "./file-run-store.js";
|
|
8
8
|
import { LocalCheckpointStore } from "./local-checkpoint-store.js";
|
|
9
9
|
import { FileResumeAnchorStore } from "./file-resume-anchor-store.js";
|
|
10
10
|
import { type ApprovalExemptionStore } from "./approval-exemption-store.js";
|
|
11
11
|
import { type SendFileLedger } from "./send-file-ledger.js";
|
|
12
|
-
import { TiDBResumeAnchorStore } from "./
|
|
13
|
-
import { PgResumeAnchorStore } from "./pg-resume-anchor-store.js";
|
|
12
|
+
import { TiDBResumeAnchorStore, PgResumeAnchorStore } from "./resume-anchor-store-sql.js";
|
|
14
13
|
import type { ServiceConfig } from "../config-types.js";
|
|
15
|
-
import { TiDBRunStore } from "./
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import { PgApprovalStore } from "./pg-approval-store.js";
|
|
21
|
-
import { TiDBImageIndex } from "./tidb-image-index.js";
|
|
22
|
-
import { PgImageIndex } from "./pg-image-index.js";
|
|
23
|
-
import { TiDBImageBake } from "./tidb-image-bake.js";
|
|
24
|
-
import { PgImageBake } from "./pg-image-bake.js";
|
|
25
|
-
import { TiDBBreakerState } from "./tidb-breaker-state.js";
|
|
26
|
-
import { PgBreakerState } from "./pg-breaker-state.js";
|
|
14
|
+
import { TiDBRunStore, PgRunStore } from "./run-store-sql.js";
|
|
15
|
+
import { TiDBCheckpointStore, PgCheckpointStore } from "./checkpoint-store-sql.js";
|
|
16
|
+
import { TiDBImageIndex, PgImageIndex } from "./image-index-sql.js";
|
|
17
|
+
import { TiDBImageBake, PgImageBake } from "./image-bake-store-sql.js";
|
|
18
|
+
import { TiDBBreakerState, PgBreakerState } from "./breaker-state-sql.js";
|
|
27
19
|
import { TiDBCostQuota } from "./tidb-cost-quota.js";
|
|
28
20
|
import { PgCostQuota } from "./pg-cost-quota.js";
|
|
29
21
|
import { TiDBRateLimiter } from "./tidb-rate-limiter.js";
|
|
@@ -79,7 +71,6 @@ export type ServiceWorkflowJournalStore = WorkflowJournalStore & {
|
|
|
79
71
|
* TaskResult-bearing table (the per-run deleteByRun has no run-store reap hook). Local InMemory omits it. */
|
|
80
72
|
reapExpired?(now: number, maxAgeMs: number): Promise<number>;
|
|
81
73
|
};
|
|
82
|
-
export type ApprovalStore = TiDBApprovalStore | PgApprovalStore;
|
|
83
74
|
export type ImageIndex = TiDBImageIndex | PgImageIndex;
|
|
84
75
|
export type ImageBake = TiDBImageBake | PgImageBake;
|
|
85
76
|
/** The FULL checkpoint store (core CheckpointStore + the service operator-queue/ctx methods listPending/
|
|
@@ -155,7 +146,6 @@ export interface StoreBackend {
|
|
|
155
146
|
checkpoint?(logger?: {
|
|
156
147
|
info?(msg: string, meta?: unknown): void;
|
|
157
148
|
}): CheckpointStoreFull;
|
|
158
|
-
approval?(): ApprovalStore;
|
|
159
149
|
toolResult?(): ToolResultStoreFull;
|
|
160
150
|
imageIndex?(): ImageIndex;
|
|
161
151
|
imageBake?(): ImageBake;
|
|
@@ -4,48 +4,34 @@
|
|
|
4
4
|
* subsystem. main.ts wires through this instead of `new TiDB*(pool)` so `DB_BACKEND=pg` boots the whole service on
|
|
5
5
|
* PG with zero call-site churn. The twins are interchangeable behaviourally (one shared real-DB integration suite
|
|
6
6
|
* keeps them in lock-step); the unions below exist only because TS private fields make the concrete classes
|
|
7
|
-
* nominally distinct (run/
|
|
7
|
+
* nominally distinct (run/imageIndex/imageBake have no core interface — the rest implement one).
|
|
8
8
|
*/
|
|
9
9
|
import { homedir } from "node:os";
|
|
10
10
|
import { join } from "node:path";
|
|
11
11
|
import { FileStorageBackend, FileSessionRepo, DEFAULT_SNAPSHOT_BOUNDS } from "@sema-agent/core";
|
|
12
|
-
import { FileWorkflowJournalStore } from "
|
|
13
|
-
import { TiDBOutcomeLedger } from "./
|
|
14
|
-
import { PgOutcomeLedger } from "./pg-outcome-ledger.js";
|
|
12
|
+
import { FileWorkflowJournalStore } from "@sema-agent/core";
|
|
13
|
+
import { TiDBOutcomeLedger, PgOutcomeLedger } from "./outcome-ledger-sql.js";
|
|
15
14
|
import { FileOutcomeSink } from "./file-outcome-sink.js";
|
|
16
|
-
import { TiDBWorkflowRunStore, TiDBWorkflowCompletionInbox, TiDBWorkflowNotifyJournalStore } from "./
|
|
17
|
-
import { PgWorkflowRunStore, PgWorkflowCompletionInbox, PgWorkflowNotifyJournalStore } from "./pg-workflow-run-store.js";
|
|
15
|
+
import { TiDBWorkflowRunStore, TiDBWorkflowCompletionInbox, TiDBWorkflowNotifyJournalStore, PgWorkflowRunStore, PgWorkflowCompletionInbox, PgWorkflowNotifyJournalStore } from "./workflow-run-store-sql.js";
|
|
18
16
|
import { FileRunStore } from "./file-run-store.js";
|
|
19
17
|
import { LocalSessionStore } from "./local-session-store.js";
|
|
20
18
|
import { LocalCheckpointStore } from "./local-checkpoint-store.js";
|
|
21
19
|
import { FileResumeAnchorStore } from "./file-resume-anchor-store.js";
|
|
22
20
|
import { TiDBApprovalExemptionStore, PgApprovalExemptionStore, FileApprovalExemptionStore } from "./approval-exemption-store.js";
|
|
23
21
|
import { TiDBSendFileLedger, PgSendFileLedger, FileSendFileLedger } from "./send-file-ledger.js";
|
|
24
|
-
import { TiDBResumeAnchorStore } from "./
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import { TiDBWorkflowJournalStore } from "./tidb-workflow-journal-store.js";
|
|
29
|
-
import { PgWorkflowJournalStore } from "./pg-workflow-journal-store.js";
|
|
30
|
-
import { TiDBFileSnapshotStore } from "./tidb-file-snapshot-store.js";
|
|
31
|
-
import { PgFileSnapshotStore } from "./pg-file-snapshot-store.js";
|
|
22
|
+
import { TiDBResumeAnchorStore, PgResumeAnchorStore } from "./resume-anchor-store-sql.js";
|
|
23
|
+
import { TiDBSessionPolicyStore, PgSessionPolicyStore } from "./session-policy-store-sql.js";
|
|
24
|
+
import { TiDBWorkflowJournalStore, PgWorkflowJournalStore } from "./workflow-journal-store-sql.js";
|
|
25
|
+
import { TiDBFileSnapshotStore, PgFileSnapshotStore } from "./file-snapshot-store-sql.js";
|
|
32
26
|
import { MinioBlobBackend, SqlBlobBackend } from "./blob-backend.js";
|
|
33
27
|
import { createTidbPool, ensureSchema as ensureTidbSchema } from "./tidb-pool.js";
|
|
34
28
|
import { createPgPool, ensurePgSchema, pgPoolOptions } from "./pg-pool.js";
|
|
35
|
-
import { TiDBRunStore } from "./
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
import { TiDBToolResultStore } from "./tidb-tool-result-store.js";
|
|
42
|
-
import { PgToolResultStore } from "./pg-tool-result-store.js";
|
|
43
|
-
import { TiDBImageIndex } from "./tidb-image-index.js";
|
|
44
|
-
import { PgImageIndex } from "./pg-image-index.js";
|
|
45
|
-
import { TiDBImageBake } from "./tidb-image-bake.js";
|
|
46
|
-
import { PgImageBake } from "./pg-image-bake.js";
|
|
47
|
-
import { TiDBBreakerState } from "./tidb-breaker-state.js";
|
|
48
|
-
import { PgBreakerState } from "./pg-breaker-state.js";
|
|
29
|
+
import { TiDBRunStore, PgRunStore } from "./run-store-sql.js";
|
|
30
|
+
import { TiDBCheckpointStore, PgCheckpointStore } from "./checkpoint-store-sql.js";
|
|
31
|
+
import { TiDBToolResultStore, PgToolResultStore } from "./tool-result-store-sql.js";
|
|
32
|
+
import { TiDBImageIndex, PgImageIndex } from "./image-index-sql.js";
|
|
33
|
+
import { TiDBImageBake, PgImageBake } from "./image-bake-store-sql.js";
|
|
34
|
+
import { TiDBBreakerState, PgBreakerState } from "./breaker-state-sql.js";
|
|
49
35
|
import { TiDBCostQuota } from "./tidb-cost-quota.js";
|
|
50
36
|
import { PgCostQuota } from "./pg-cost-quota.js";
|
|
51
37
|
import { TiDBRateLimiter } from "./tidb-rate-limiter.js";
|
|
@@ -117,7 +103,6 @@ class TiDBBackend {
|
|
|
117
103
|
completionInbox(onWarn) { return new TiDBWorkflowCompletionInbox(this.pool, onWarn); } // P1: cross-replica push half
|
|
118
104
|
notifyJournal() { return new TiDBWorkflowNotifyJournalStore(this.pool); } // 1.108: cross-replica at-least-once notify
|
|
119
105
|
checkpoint(logger) { return new TiDBCheckpointStore(this.pool, logger); }
|
|
120
|
-
approval() { return new TiDBApprovalStore(this.pool); }
|
|
121
106
|
toolResult() { return new TiDBToolResultStore(this.pool); }
|
|
122
107
|
imageIndex() { return new TiDBImageIndex(this.pool); }
|
|
123
108
|
imageBake() { return new TiDBImageBake(this.pool); }
|
|
@@ -151,7 +136,6 @@ class PgBackend {
|
|
|
151
136
|
completionInbox(onWarn) { return new PgWorkflowCompletionInbox(this.pool, onWarn); } // P1: cross-replica push half
|
|
152
137
|
notifyJournal() { return new PgWorkflowNotifyJournalStore(this.pool); } // 1.108: cross-replica at-least-once notify
|
|
153
138
|
checkpoint(logger) { return new PgCheckpointStore(this.pool, logger); }
|
|
154
|
-
approval() { return new PgApprovalStore(this.pool); }
|
|
155
139
|
toolResult() { return new PgToolResultStore(this.pool); }
|
|
156
140
|
imageIndex() { return new PgImageIndex(this.pool); }
|
|
157
141
|
imageBake() { return new PgImageBake(this.pool); }
|
|
@@ -36,8 +36,8 @@ export function tidbPoolOptions(tidb) {
|
|
|
36
36
|
}
|
|
37
37
|
export function createTidbPool(config) {
|
|
38
38
|
if (!config.tidb) {
|
|
39
|
-
throw new Error("TiDB config missing. Set
|
|
40
|
-
"when SESSION_BACKEND=
|
|
39
|
+
throw new Error("TiDB config missing. Set MYSQL_HOST / MYSQL_USER / MYSQL_DATABASE (and MYSQL_PASSWORD/PORT) " +
|
|
40
|
+
"when SESSION_BACKEND=mysql.");
|
|
41
41
|
}
|
|
42
42
|
return mysql.createPool(tidbPoolOptions(config.tidb));
|
|
43
43
|
}
|
|
@@ -198,32 +198,8 @@ export const SCHEMA_STATEMENTS = [
|
|
|
198
198
|
PRIMARY KEY (session_id),
|
|
199
199
|
KEY idx_task (task_id)
|
|
200
200
|
)`,
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
`CREATE TABLE IF NOT EXISTS approval (
|
|
204
|
-
id VARCHAR(64) NOT NULL,
|
|
205
|
-
task_id VARCHAR(64) NULL,
|
|
206
|
-
session_id VARCHAR(64) NULL,
|
|
207
|
-
owner VARCHAR(190) NULL,
|
|
208
|
-
-- scope — single-DB fleet scope guard (defense-in-depth): the run's tenant identity (owner-sourced), so the
|
|
209
|
-
-- approval READ paths (getStatus / get / listPending / decide) can null-safe-filter on it. A NULL scope row
|
|
210
|
-
-- (an untenanted run — and, on the pre-folding schema, any PRE-MIGRATION row) is matched by a NULL scope arg
|
|
211
|
-
-- via MySQL <=> / PG IS NOT DISTINCT FROM — see tidb-approval-store.ts / pg-approval-store.ts.
|
|
212
|
-
-- expireStale deliberately stays GLOBAL (fleet maintenance, not a tenant read).
|
|
213
|
-
scope VARCHAR(190) NULL,
|
|
214
|
-
tool_name VARCHAR(190) NOT NULL,
|
|
215
|
-
args JSON NULL,
|
|
216
|
-
status VARCHAR(16) NOT NULL,
|
|
217
|
-
reason TEXT NULL,
|
|
218
|
-
decided_by VARCHAR(190) NULL,
|
|
219
|
-
created_at DATETIME(3) NOT NULL,
|
|
220
|
-
decided_at DATETIME(3) NULL,
|
|
221
|
-
PRIMARY KEY (id),
|
|
222
|
-
KEY idx_owner_status (owner, status),
|
|
223
|
-
-- idx_scope_status: the scope-filtered READ paths (listPending WHERE scope <=> ?) would full-scan without it.
|
|
224
|
-
KEY idx_scope_status (scope, status),
|
|
225
|
-
KEY idx_status (status)
|
|
226
|
-
)`,
|
|
201
|
+
// ([2354]/[2356] A-5,5.0.0:F4 轮询车道的 `approval` 表 DDL 已随车道退役——存量库里的旧表留置不动,
|
|
202
|
+
// 代码零读写;durable 门只用下面的 checkpoint 表。)
|
|
227
203
|
// Durable-checkpoint (core 1.67 / design/45): a policy `ask` persisted as a suspended task so an operator
|
|
228
204
|
// can `resume` it from any replica. `checkpoint` = core's blob + CAS status; `outcome` persisted on resolve
|
|
229
205
|
// (R20 #1). Timestamps are epoch-ms BIGINT (the core Checkpoint uses ms numbers, not DATETIME).
|
|
@@ -396,7 +372,7 @@ export const SCHEMA_STATEMENTS = [
|
|
|
396
372
|
// = JSON.stringify(TaskResult). The (run_id, ordinal) PK makes append IDEMPOTENT (ON DUPLICATE KEY = OVERWRITE /
|
|
397
373
|
// last-write-wins) so a resumed run re-appending its replayed prefix verbatim leaves no dup — the byte-match of
|
|
398
374
|
// core's InMemoryWorkflowJournalStore (byOrdinal.set). LOAD-BEARING (a resume replays it), unlike the best-effort
|
|
399
|
-
// task_event observation log. GC'd by the run reaper (deleteByRun). See
|
|
375
|
+
// task_event observation log. GC'd by the run reaper (deleteByRun). See workflow-journal-store-sql.ts.
|
|
400
376
|
`CREATE TABLE IF NOT EXISTS workflow_journal (
|
|
401
377
|
run_id VARCHAR(191) NOT NULL,
|
|
402
378
|
ordinal INT NOT NULL,
|
|
@@ -621,7 +597,7 @@ export const SCHEMA_STATEMENTS = [
|
|
|
621
597
|
// Admission sentinel: ONE always-present row per builder pool, `SELECT … FOR UPDATE`-locked to SERIALIZE the
|
|
622
598
|
// createBakeIfIdle busy-check+insert. A bare conditional INSERT…SELECT WHERE NOT EXISTS does NOT serialize two
|
|
623
599
|
// concurrent admissions under TiDB's REPEATABLE READ (nor PG's READ COMMITTED), so without this lock two keyless
|
|
624
|
-
// POSTs can both admit a non-dryRun bake. Dialect-uniform with the PG twin (
|
|
600
|
+
// POSTs can both admit a non-dryRun bake. Dialect-uniform with the PG twin (image-bake-store-sql.ts).
|
|
625
601
|
`CREATE TABLE IF NOT EXISTS image_bake_admit (
|
|
626
602
|
pool VARCHAR(32) NOT NULL,
|
|
627
603
|
PRIMARY KEY (pool)
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* {@link import("@sema-agent/core").InMemoryWorkflowJournalStore} (single-replica, lost on crash); this is the
|
|
9
9
|
* byte-match durable twin so a workflow survives a replica crash and RESUMES (replay the longest unchanged
|
|
10
10
|
* PREFIX of recorded `ctx.agent` results, run only the first changed/new call + everything after it live). The
|
|
11
|
-
* journal is LOAD-BEARING (unlike the best-effort {@link import("./
|
|
11
|
+
* journal is LOAD-BEARING (unlike the best-effort {@link import("./run-store-sql.js")} observation layer):
|
|
12
12
|
* append/load failures MUST throw — a silently-dropped entry would silently re-run already-done work.
|
|
13
13
|
*
|
|
14
14
|
* Schema = `workflow_journal (run_id, ordinal) PK` (DDL in tidb-pool.ts / pg-pool.ts ensureSchema). `ordinal`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { callKeyOrdinal } from "@sema-agent/core";
|
|
2
|
-
import { oversizeJournalResult } from "
|
|
2
|
+
import { oversizeJournalResult } from "@sema-agent/core";
|
|
3
3
|
import { mysqlDriver, pgDriver } from "./sql-driver.js";
|
|
4
4
|
const DEFAULT_RESUME_CLAIM_TTL_MS = 60 * 60 * 1000;
|
|
5
5
|
export class SqlWorkflowJournalStore {
|
package/dist/principal-jwt.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* design/80 D-G: principal crypto-binding (the direct-door IDENTITY gate) + the combined direct-door proof
|
|
3
|
-
* verifier. Split out of `security.ts` (design/158 A13
|
|
4
|
-
*
|
|
3
|
+
* verifier. Split out of `security.ts` (design/158 A13; consumers import from HERE — [2354] cleared the security.ts compat re-exports;
|
|
4
|
+
* `verifyDirectDoorProof` imports {@link verifyApprovalHmac} from `./approval-hmac.js` for the
|
|
5
5
|
* integrity half of the combined proof; `security.ts`'s own `verifiedPrincipal` imports {@link verifyPrincipalJwt}
|
|
6
6
|
* from here for the direct-door identity branch).
|
|
7
7
|
*
|
|
@@ -41,9 +41,10 @@ export interface PromptsDomainFaces {
|
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* prompts 域候选门 v2(validateCenterPrompts 的双轴升级;整拒语义不变=任一在场轴坏形 ⇒ 整个 prompts
|
|
44
|
-
* 面拒绝采用,LKG/内置继续服务)
|
|
45
|
-
*
|
|
46
|
-
*
|
|
44
|
+
* 面拒绝采用,LKG/内置继续服务)。唯一认可形=`{schemaVersion:1, declarations?, catalog?}`
|
|
45
|
+
* (registry-core `EffectivePromptsWire`)至少一轴。[2373]B-9(5.0.0):legacy 平铺兼容窗到期删——
|
|
46
|
+
* 0.13.0 起 EffectivePromptsWire 首字段是 `schemaVersion: z.ZodLiteral<1>`,与 server 共用 ^0.13.0 的
|
|
47
|
+
* 合规 center 不可能再发平铺;非合规体=响亮拒绝(整拒落 LKG/内置),不再静默吸收。
|
|
47
48
|
* catalog 轴的语义权威=core `verifyPromptArtifact`(形/digest 逐位复算/ARTIFACT_LIMITS/compatibleCore
|
|
48
49
|
* range 全在 core 一处——[1242]③ a 解,上限单真源永不漂)。
|
|
49
50
|
*/
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* lens2 §G:`config-lkg.ts → capabilities/center-prompts.ts` 是全仓唯一一条显式分层反向边,config 层
|
|
4
4
|
* 值 import capabilities 层)。本模块只依赖 node 内置 + `@sema-agent/core`,不依赖 capabilities/
|
|
5
5
|
* config 任何东西,config-lkg(LKG 读侧复判)与 capabilities(候选门)同引即无反向边。
|
|
6
|
-
* center-prompts.ts
|
|
6
|
+
* 消费者直引本模块([2354] 兼容面全清:center-prompts.ts 的原位兼容 re-export 已删);语义/文案零改动——逐字搬运。
|
|
7
7
|
*
|
|
8
8
|
* ─── 以下为原 center-prompts.ts 的判形半场,注释原样保留 ───
|
|
9
9
|
*
|
|
@@ -107,9 +107,10 @@ export const CORE_ENGINE_VERSION = (() => {
|
|
|
107
107
|
})();
|
|
108
108
|
/**
|
|
109
109
|
* prompts 域候选门 v2(validateCenterPrompts 的双轴升级;整拒语义不变=任一在场轴坏形 ⇒ 整个 prompts
|
|
110
|
-
* 面拒绝采用,LKG/内置继续服务)
|
|
111
|
-
*
|
|
112
|
-
*
|
|
110
|
+
* 面拒绝采用,LKG/内置继续服务)。唯一认可形=`{schemaVersion:1, declarations?, catalog?}`
|
|
111
|
+
* (registry-core `EffectivePromptsWire`)至少一轴。[2373]B-9(5.0.0):legacy 平铺兼容窗到期删——
|
|
112
|
+
* 0.13.0 起 EffectivePromptsWire 首字段是 `schemaVersion: z.ZodLiteral<1>`,与 server 共用 ^0.13.0 的
|
|
113
|
+
* 合规 center 不可能再发平铺;非合规体=响亮拒绝(整拒落 LKG/内置),不再静默吸收。
|
|
113
114
|
* catalog 轴的语义权威=core `verifyPromptArtifact`(形/digest 逐位复算/ARTIFACT_LIMITS/compatibleCore
|
|
114
115
|
* range 全在 core 一处——[1242]③ a 解,上限单真源永不漂)。
|
|
115
116
|
*/
|
|
@@ -118,10 +119,8 @@ export function validatePromptsDomain(raw) {
|
|
|
118
119
|
return { ok: false, error: "prompts is not an object" };
|
|
119
120
|
const w = raw;
|
|
120
121
|
if (w.schemaVersion === undefined) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return legacy;
|
|
124
|
-
return { ok: true, value: { declarations: legacy.value, identity: `${legacy.value.contentDigest}+-`, axes: ["declarations"] } };
|
|
122
|
+
// [2373]B-9:平铺形拒绝(兼容窗 5.0.0 到期)。文案带指引=下游冒烟立刻可自修,不是哑谜。
|
|
123
|
+
return { ok: false, error: "prompts payload has no schemaVersion — the legacy flat shape was retired in 5.0.0; wrap as {schemaVersion:1, declarations:{...}} (registry-core EffectivePromptsWire)" };
|
|
125
124
|
}
|
|
126
125
|
if (w.schemaVersion !== 1)
|
|
127
126
|
return { ok: false, error: `unsupported prompts schemaVersion ${String(w.schemaVersion)}` };
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* router's chosen arm per trap; the objective hidden-test oracle confirms danger→SUP prevents + competent→single
|
|
20
20
|
* is not-worse) BEFORE it is wired into the live task path — never ship an unvalidated router.
|
|
21
21
|
*/
|
|
22
|
-
import {
|
|
22
|
+
import {} from "@sema-agent/core";
|
|
23
23
|
/**
|
|
24
24
|
* The routing decision (pure). Order matters: explicit caller choice first, then (a) danger, then (b) structural,
|
|
25
25
|
* else the single default. `team` is NEVER produced here — it only ever appears via {@link RoutingSignals.explicitMode}.
|
|
@@ -105,7 +105,7 @@ export function isIsolatedExecEnv(provider, runtimeClass) {
|
|
|
105
105
|
* a notebook ungated (the exact "write tool bypasses the SUP gate" hole the review-HIGH closed for Edit/Write).
|
|
106
106
|
* Curated, NOT derived from HAND_TOOL_EFFECTS: that taxonomy is replay-safety (Write="idempotent"; Bash="write" but
|
|
107
107
|
* shell-gated), not "is an fs mutation". CANONICAL names only (core 1.202 retired MultiEdit into an Edit alias —
|
|
108
|
-
*
|
|
108
|
+
* (5.0.0:折叠面退役——重放的旧名调用由 core roster 层响亮 miss,不再折到 "Edit";raw 直比)
|
|
109
109
|
* gated without a stale alias entry here). */
|
|
110
110
|
const WRITE_HAND_TOOLS = new Set(["Edit", "Write", "NotebookEdit"]);
|
|
111
111
|
/**
|
|
@@ -119,7 +119,7 @@ const WRITE_HAND_TOOLS = new Set(["Edit", "Write", "NotebookEdit"]);
|
|
|
119
119
|
export function supPostureOverrides() {
|
|
120
120
|
const ask = (toolName) => ({ action: "ask", message: `${toolName} gated by supervisor routing (capability-danger task)`, decisionReason: "rule" });
|
|
121
121
|
const writeGate = {
|
|
122
|
-
check: (req) => (WRITE_HAND_TOOLS.has(
|
|
122
|
+
check: (req) => (WRITE_HAND_TOOLS.has(req.toolName) ? ask(req.toolName) : { action: "allow" }),
|
|
123
123
|
};
|
|
124
124
|
return { shellGate: "always", toolPolicy: writeGate };
|
|
125
125
|
}
|
package/dist/run-local.js
CHANGED
|
@@ -30,7 +30,8 @@ import { Runner, uuidv7, parseModelMention, FileStorageBackend, NodeLspManager,
|
|
|
30
30
|
import { createBrain } from "./brain.js";
|
|
31
31
|
import { ForkRoutingSessionStore } from "./plugins/fork-routing-session-store.js";
|
|
32
32
|
import { taskWallClockSec } from "./task-workflow.js";
|
|
33
|
-
import {
|
|
33
|
+
import { applyCatalogToSource } from "./capabilities/center-prompts.js";
|
|
34
|
+
import { validatePromptsDomain, CORE_ENGINE_VERSION } from "./prompts-domain-validate.js";
|
|
34
35
|
import { loadConfig, logConfigDiagnostics, numEnv } from "./config.js";
|
|
35
36
|
import { createConfigProvider } from "./config-provider.js";
|
|
36
37
|
import { applyEffective, resolveMcpServers, mcpForScenario } from "./config-center/facade.js";
|
|
@@ -40,7 +41,8 @@ import { loadSkills } from "./capabilities/skills.js";
|
|
|
40
41
|
import { GiteaClient } from "./capabilities/repo-tools.js";
|
|
41
42
|
import { webSearchConfigFromEnv, createWebSearchBackend } from "./plugins/web-search.js";
|
|
42
43
|
import { buildScenarios, selectScenario, centerScenarios } from "./capabilities/scenarios.js";
|
|
43
|
-
import { HttpError
|
|
44
|
+
import { HttpError } from "./security.js";
|
|
45
|
+
import { memoryEngineBackendFor, memorySpecForRequest } from "./memory-scope.js";
|
|
44
46
|
import { createMemorySyncRunner, createMemorySyncTransport } from "./memory-sync-client.js";
|
|
45
47
|
import { buildPricing } from "./budget.js";
|
|
46
48
|
import { createKeyResolver } from "./key-resolver.js";
|
|
@@ -172,12 +174,14 @@ export async function runLocal(argv, deps = {}) {
|
|
|
172
174
|
process.env.CONFIG_PROVIDER = "local";
|
|
173
175
|
// FORCE the durable backends OFF: a one-shot, single-machine CLI has nothing durable to persist
|
|
174
176
|
// and deliberately does NOT assemble the server-only StoreBackend. A shared .env that carries
|
|
175
|
-
// SESSION_BACKEND
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
//
|
|
179
|
-
//
|
|
180
|
-
//
|
|
177
|
+
// SESSION_BACKEND set to anything but the enum's "memory"/"mysql"/"auto" would otherwise boot-reject
|
|
178
|
+
// outright (SESSION_BACKEND is an enum env, validated at load — an old value like the retired public
|
|
179
|
+
// name "tidb" is rejected, not silently coerced), and even a legit "mysql" value would pull in a
|
|
180
|
+
// server-only SQL session store this one-shot CLI has no business assembling. Unlike CONFIG_PROVIDER/
|
|
181
|
+
// REMOTE_EXEC (where an explicit operator choice can be HONORED), a DB session store cannot work here
|
|
182
|
+
// at all, so we FORCE — never honor — this knob to in-memory so the CLI just works regardless of the
|
|
183
|
+
// shared config. Long-term memory needs no forcing: the design/138 memory ENGINE is file-based and
|
|
184
|
+
// default-ON here (single-user; MEMORY_ENGINE=off and MEMORY_ENGINE_DIR pass through loadConfig as-is).
|
|
181
185
|
process.env.SESSION_BACKEND = "memory";
|
|
182
186
|
// 🔴 REQUIRE_PRINCIPAL is the same shared-config footgun class: run-local IS the single
|
|
183
187
|
// user at their own terminal — there is no untrusted caller to gate — but a server .env carrying
|
|
@@ -395,7 +399,6 @@ export async function runLocal(argv, deps = {}) {
|
|
|
395
399
|
const webSearch = webSearchCfg ? createWebSearchBackend(webSearchCfg) : undefined;
|
|
396
400
|
const scenarioDeps = {
|
|
397
401
|
runner, subRunner, model: "default", skills, repoClient, metrics, logger,
|
|
398
|
-
oaApiBaseUrl: config.oaApiBaseUrl, oaServiceToken: config.oaServiceToken, oaIssue: config.oaIssue,
|
|
399
402
|
...(webSearch ? { webSearch } : {}),
|
|
400
403
|
brandIdentity: true, // run-local is always a local/TOC deployment → brand the default scenario as Sema.
|
|
401
404
|
};
|
|
@@ -411,7 +414,7 @@ export async function runLocal(argv, deps = {}) {
|
|
|
411
414
|
const requested = args.scenario ?? config.defaultScenario;
|
|
412
415
|
const scenarioName = scenarios[requested] ? requested : "default";
|
|
413
416
|
// A scenario may THROW HttpError synchronously when a prerequisite is unmet (e.g. `scan` needs
|
|
414
|
-
// GIT_API_BASEURL + a repo
|
|
417
|
+
// GIT_API_BASEURL + a repo — which a one-shot CLI may not
|
|
415
418
|
// supplies). The server catches this in resolveSpec/prepareSpec and returns a clean 4xx; here we mirror that
|
|
416
419
|
// with the doctor-style UX (message to stderr + exit 2) instead of letting it bubble to the fatal exit-1 path.
|
|
417
420
|
let cap;
|
package/dist/runs.js
CHANGED
|
@@ -65,10 +65,12 @@ export async function backgroundAgentOutput(registry, handle, access, agentStore
|
|
|
65
65
|
* onServedTerminal (ack the completion as served) and suppress the workflow completion push. Refusals
|
|
66
66
|
* return the registry's own not_found shape, indistinguishable from an unknown handle (the route 404s it). */
|
|
67
67
|
const TASK_HANDLE_KINDS = new Set(["background_bash", "monitor", "background_agent"]);
|
|
68
|
-
/** 1.250 复审 F1(HIGH):durable 回落的**形判门**——`getAccessibleTask` 是精确键(不 trim、不查
|
|
69
|
-
* 别名),而 core `pollTask/stopTask` 是通用解析面(先 trim
|
|
70
|
-
*
|
|
71
|
-
*
|
|
68
|
+
/** 1.250 复审 F1(HIGH):durable 回落的**形判门**——`getAccessibleTask` 是精确键(不 trim、不查
|
|
69
|
+
* 别名),而 core `pollTask/stopTask` 是通用解析面(先 trim;[2380] RB-479-A②:`legacyToTaskId`
|
|
70
|
+
* shellId 索引已随 5.0.0 整族删,b* task_id 是唯一 registry 地址——本门防的「legacy shellId 穿缝」
|
|
71
|
+
* 一臂如今在 core 层就响亮 not_found;stopTask 仍有 byName 臂)。裸 `!row` 回落会让垫充空白句柄
|
|
72
|
+
* (" "+wfId)/agent 名字从回落缝穿进 live 分支——kind 门要防的 onServedTerminal/游标消费/按名 stop
|
|
73
|
+
* 全部复活(复审实测复现)。
|
|
72
74
|
* 只有 **a\* 精确形**才回落:`DURABLE_AGENT_HANDLE_RE` = core 公共导出(core 1.369,[1518] ask 即答
|
|
73
75
|
* ——两边判词同源,镜像私拷已删)。残余(documented):恰为 a\* 形的 agent **名字**
|
|
74
76
|
* 在无 durable 行时仍会进 core stopTask 的 byName 臂——同 access 元组内、名字域与句柄域同形的病态窄面,
|
|
@@ -526,8 +528,8 @@ promptManifests) {
|
|
|
526
528
|
// the top stream NEVER carries it), so this sink is the ONLY path a tick reaches the top-run consumers. 1.78
|
|
527
529
|
// (review HIGH): fan it out to the DURABLE event log too (via the shared whitelist+redact builder, fire-and-
|
|
528
530
|
// forget — `++seq` is a sync increment so sink-vs-loop appends get unique seqs), not just the fleet bus —
|
|
529
|
-
// previously no fleet bus wired ⇒ ticks dropped entirely, and the stream-switch task_progress case below
|
|
530
|
-
// forward-compat
|
|
531
|
+
// previously no fleet bus wired ⇒ ticks dropped entirely, and the stream-switch task_progress case below was
|
|
532
|
+
// forward-compat then — [2373]B-4:floor ^4.0.0 下它是热路径(腐注方向已翻转,勿按旧注当死支)。core swallow-guards a throwing sink.
|
|
531
533
|
const fwdInternals = {
|
|
532
534
|
onForwardEvent: (e) => {
|
|
533
535
|
fleetPublisher?.onForwardEvent(e);
|
|
@@ -68,8 +68,9 @@ export interface EntitlementsResolverOpts {
|
|
|
68
68
|
*
|
|
69
69
|
* `autoMode`(core 1.276.0 `RuntimeCaps.autoMode`):auto-mode 分类器 per-principal
|
|
70
70
|
* 开闸线,极性同 allowObservers(`=== true` 显式 opt-in,默认 OFF;真执行还要 deployment 装配
|
|
71
|
-
* `RunnerDeps.autoMode` 分类器面=信任门,center 键只是 entitlement 半场)。registry-core
|
|
72
|
-
*
|
|
71
|
+
* `RunnerDeps.autoMode` 分类器面=信任门,center 键只是 entitlement 半场)。[2373]B-6a:registry-core
|
|
72
|
+
* 0.13.0 已把 autoMode 收进 EntitlementRuntimeCaps(types.d.ts:1786)——宽读逃逸期结束,现为类型直读
|
|
73
|
+
* (allowObservers 同款收编先例)。 */
|
|
73
74
|
export declare function toCoreRuntimeCaps(ent: EntitlementRuntimeCaps | null | undefined): RuntimeCaps | undefined;
|
|
74
75
|
/** A MISCONFIG diagnostic (review MEDIUM): a worker-scoped `wpt_<self>` pull token REQUIRES `?worker=<self>` to
|
|
75
76
|
* resolve per-principal caps — so a `wpt_` token with NO `SEMA_REGISTRY_WORKER` set will 403
|
|
@@ -20,13 +20,13 @@ const defaultLogger = createLogger();
|
|
|
20
20
|
*
|
|
21
21
|
* `autoMode`(core 1.276.0 `RuntimeCaps.autoMode`):auto-mode 分类器 per-principal
|
|
22
22
|
* 开闸线,极性同 allowObservers(`=== true` 显式 opt-in,默认 OFF;真执行还要 deployment 装配
|
|
23
|
-
* `RunnerDeps.autoMode` 分类器面=信任门,center 键只是 entitlement 半场)。registry-core
|
|
24
|
-
*
|
|
23
|
+
* `RunnerDeps.autoMode` 分类器面=信任门,center 键只是 entitlement 半场)。[2373]B-6a:registry-core
|
|
24
|
+
* 0.13.0 已把 autoMode 收进 EntitlementRuntimeCaps(types.d.ts:1786)——宽读逃逸期结束,现为类型直读
|
|
25
|
+
* (allowObservers 同款收编先例)。 */
|
|
25
26
|
export function toCoreRuntimeCaps(ent) {
|
|
26
27
|
if (!ent)
|
|
27
28
|
return undefined;
|
|
28
|
-
//
|
|
29
|
-
const autoMode = ent.autoMode;
|
|
29
|
+
const autoMode = ent.autoMode; // [2373]B-6a:0.13.0 类型直读(宽读逃逸已收编)
|
|
30
30
|
const badCap = (v) => v !== undefined && typeof v !== "boolean";
|
|
31
31
|
if (badCap(ent.allowWorkflows) || badCap(ent.forceDurableGate) || badCap(ent.allowFork) || badCap(ent.allowObservers) || badCap(autoMode)) {
|
|
32
32
|
throw new Error("runtimeCaps from center carries a non-boolean cap (contract breach — fail closed)");
|
|
@@ -29,13 +29,10 @@ export type CommandRule = {
|
|
|
29
29
|
command: string;
|
|
30
30
|
decision: "allow" | "ask" | "deny";
|
|
31
31
|
};
|
|
32
|
-
/** True when `name` names a DELEGATION tool — the subagent tool
|
|
33
|
-
* `DEFAULT_SUBAGENT_TOOL_NAME
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* WRITABLE-hands child, because core does not propagate handsReadOnly to a delegated child).
|
|
37
|
-
* core 1.257 (design/136 BREAKING): the standalone `Fork` tool is retired — a fork is now
|
|
38
|
-
* `Agent(subagent_type:"fork")`, i.e. an Agent call, already matched by DEFAULT_SUBAGENT_TOOL_NAME. */
|
|
32
|
+
/** True when `name` names a DELEGATION tool — the subagent tool(CC-187 canonical `"Agent"`,core
|
|
33
|
+
* `DEFAULT_SUBAGENT_TOOL_NAME`)。5.0.0 RB-476:折叠面退役,RAW 比对 core 单源常量——旧名("Task")
|
|
34
|
+
* 在 core roster 层响亮 miss,不再需要归一;单源常量本身就防了当年 1.202 改名时裸字符串失配的
|
|
35
|
+
* fail-open(那个教训的解=引用常量,不是折叠)。 */
|
|
39
36
|
export declare function isDelegationToolName(name: string): boolean;
|
|
40
37
|
/** The hands-read-only DELEGATION STRIP (the main.ts governed-spec site, extracted here so the actual filter —
|
|
41
38
|
* not just the name predicate — is pinned by tests): core does not propagate `handsReadOnly` to a delegated
|