@sema-agent/server 7.151.0 → 7.152.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 +266 -0
- package/README.md +15 -3
- package/README.zh-CN.md +10 -2
- package/USAGE.md +93 -64
- package/deploy/sema-up/README.md +5 -4
- package/deploy/sema-up/cluster-up.sh +6 -6
- package/deploy/sema-up/kube-up.sh +5 -5
- package/deploy/sema-up/lib/flagshape.sh +36 -8
- package/deploy/sema-up/machines.example.yaml +3 -1
- package/deploy/sema-up/sema-up.sh +22 -16
- package/dist/approval-ask-audit-store.d.ts +1 -1
- package/dist/approval-ask-machine.d.ts +4 -10
- package/dist/approval-ask-retention.d.ts +1 -1
- package/dist/approval-card.d.ts +10 -12
- package/dist/approval-gate-currency.d.ts +8 -8
- package/dist/approval-gate-currency.js +3 -4
- package/dist/approval-hmac.d.ts +17 -1
- package/dist/approval-hmac.js +7 -1
- package/dist/approval-queue-kind.d.ts +1 -1
- package/dist/approval.d.ts +2 -2
- package/dist/approval.js +2 -2
- package/dist/bind-host.d.ts +1 -3
- package/dist/bind-host.js +2 -3
- package/dist/boot/coordinators.d.ts +1 -1
- package/dist/boot/coordinators.js +9 -10
- package/dist/boot/device-lane.js +2 -0
- package/dist/boot/execution-env.d.ts +1 -0
- package/dist/boot/execution-env.js +31 -5
- package/dist/boot/leader.d.ts +31 -30
- package/dist/boot/leader.js +38 -28
- package/dist/boot/leg-path-adjudication.d.ts +40 -0
- package/dist/boot/leg-path-adjudication.js +18 -0
- package/dist/boot/parked-revive-gate.js +3 -15
- package/dist/boot/reapers.d.ts +1 -1
- package/dist/boot/reapers.js +1 -1
- package/dist/boot/resolve-spec.js +12 -26
- package/dist/boot/runner-deps.d.ts +39 -35
- package/dist/boot/runner-deps.js +92 -89
- package/dist/boot/shutdown.d.ts +6 -0
- package/dist/boot/shutdown.js +10 -4
- package/dist/boot/stage-02-web-admin-pull.js +4 -5
- package/dist/boot/stage-05-execution-env.js +2 -1
- package/dist/boot/stage-06-runners.d.ts +2 -0
- package/dist/boot/stage-06-runners.js +10 -4
- package/dist/boot/stage-07-capability-layer.d.ts +1 -0
- package/dist/boot/stage-07-capability-layer.js +1 -1
- package/dist/boot/stage-08-reapers.d.ts +1 -0
- package/dist/boot/stage-09-leader.d.ts +1 -0
- package/dist/boot/stage-09-leader.js +2 -2
- package/dist/boot/stage-10-http-server.d.ts +8 -0
- package/dist/boot/stage-10-http-server.js +11 -15
- package/dist/boot/stores.js +7 -4
- package/dist/boot/web-admin.js +2 -7
- package/dist/capabilities/approvals-push.d.ts +3 -3
- package/dist/capabilities/scenarios.d.ts +28 -13
- package/dist/capabilities/scenarios.js +2 -2
- package/dist/capability-facts.d.ts +22 -20
- package/dist/capability-facts.js +18 -34
- package/dist/card-rule-offers.d.ts +32 -0
- package/dist/card-rule-offers.js +130 -0
- package/dist/config-catalog.js +12 -11
- package/dist/config-dir-trust.js +4 -2
- package/dist/config-invariants.d.ts +18 -7
- package/dist/config-invariants.js +51 -8
- package/dist/config-lkg.d.ts +5 -19
- package/dist/config-lkg.js +8 -62
- package/dist/config-provider.d.ts +1 -1
- package/dist/config-root-migration.d.ts +2 -2
- package/dist/config-types.d.ts +28 -38
- package/dist/config.d.ts +7 -5
- package/dist/config.js +55 -16
- package/dist/control-socket.d.ts +51 -0
- package/dist/control-socket.js +115 -0
- package/dist/deployment-governance.d.ts +2 -1
- package/dist/device-ws-hub.d.ts +7 -0
- package/dist/device-ws-hub.js +7 -1
- package/dist/elicitation.js +2 -2
- package/dist/entry-problems.d.ts +40 -3
- package/dist/entry-problems.js +3 -1
- package/dist/execution-env-refusal.d.ts +8 -2
- package/dist/execution-env-refusal.js +3 -0
- package/dist/fleet/engine-signal.d.ts +12 -29
- package/dist/fleet/engine-signal.js +1 -7
- package/dist/fleet-client.js +2 -5
- package/dist/gate-settlement.d.ts +1 -8
- package/dist/gate-settlement.js +0 -4
- package/dist/history-anchor.js +1 -1
- package/dist/hitl-delivery.d.ts +2 -3
- package/dist/hitl-delivery.js +0 -2
- package/dist/hooks/hook-llm.js +4 -2
- package/dist/hooks/hook-runner.d.ts +3 -2
- package/dist/hooks/hook-runner.js +16 -1
- package/dist/host-decision.d.ts +11 -11
- package/dist/http/active-run-conflict.d.ts +35 -2
- package/dist/http/active-run-conflict.js +48 -19
- package/dist/http/approval-sweeps.d.ts +1 -1
- package/dist/http/approval-sweeps.js +5 -2
- package/dist/http/checkpoint-ctx.d.ts +2 -0
- package/dist/http/checkpoint-ctx.js +1 -0
- package/dist/http/dispatch.d.ts +6 -2
- package/dist/http/dispatch.js +25 -5
- package/dist/http/durable-run-leg.js +0 -1
- package/dist/http/health-reader.d.ts +16 -9
- package/dist/http/health-reader.js +2 -1
- package/dist/http/health-self-report.js +1 -1
- package/dist/http/owner-access.d.ts +2 -3
- package/dist/http/owner-access.js +3 -4
- package/dist/http/principal-gate.d.ts +49 -21
- package/dist/http/principal-gate.js +61 -11
- package/dist/http/request-channel.d.ts +23 -0
- package/dist/http/request-channel.js +9 -0
- package/dist/http/request-guards.js +17 -2
- package/dist/http/resume-ctx-read.js +20 -3
- package/dist/http/resume-legs.d.ts +2 -2
- package/dist/http/resume-legs.js +111 -41
- package/dist/http/route-ctx.d.ts +73 -7
- package/dist/http/route-ctx.js +17 -0
- package/dist/http/route-table.d.ts +4 -0
- package/dist/http/route-table.js +4 -0
- package/dist/http/routes/admin-config-refresh.js +3 -3
- package/dist/http/routes/admin-drain.d.ts +3 -0
- package/dist/http/routes/admin-drain.js +7 -7
- package/dist/http/routes/admin-memory-optout.js +3 -3
- package/dist/http/routes/adoption.js +3 -5
- package/dist/http/routes/approvals-assistant.d.ts +2 -1
- package/dist/http/routes/approvals-assistant.js +95 -48
- package/dist/http/routes/capabilities.d.ts +4 -0
- package/dist/http/routes/capabilities.js +30 -5
- package/dist/http/routes/config-catalog.js +2 -2
- package/dist/http/routes/devices.js +1 -1
- package/dist/http/routes/diagnostics.d.ts +3 -3
- package/dist/http/routes/diagnostics.js +19 -7
- package/dist/http/routes/images.js +10 -10
- package/dist/http/routes/memory-bundle.js +3 -3
- package/dist/http/routes/memory-compliance.js +3 -3
- package/dist/http/routes/memory-consolidation.js +2 -2
- package/dist/http/routes/memory-origin.js +3 -3
- package/dist/http/routes/memory-policy.js +2 -2
- package/dist/http/routes/observability.js +3 -3
- package/dist/http/routes/retention-ops.js +3 -3
- package/dist/http/routes/rules.js +5 -5
- package/dist/http/routes/run-permission-mode.d.ts +2 -1
- package/dist/http/routes/run-permission-mode.js +2 -2
- package/dist/http/routes/runs.d.ts +4 -9
- package/dist/http/routes/runs.js +73 -33
- package/dist/http/routes/session-sync.d.ts +18 -6
- package/dist/http/routes/session-sync.js +38 -36
- package/dist/http/routes/sessions.js +20 -9
- package/dist/http/routes/tasks.js +28 -37
- package/dist/http/routes/workflows.js +1 -1
- package/dist/http/server.d.ts +9 -3
- package/dist/http/server.js +15 -3
- package/dist/http/submit-ctx.d.ts +1 -1
- package/dist/http/submit-ctx.js +2 -0
- package/dist/human-facing-args.d.ts +33 -0
- package/dist/human-facing-args.js +33 -0
- package/dist/index.d.ts +1 -1
- package/dist/k8s-api-credentials.d.ts +29 -0
- package/dist/k8s-api-credentials.js +25 -0
- package/dist/lane-home-probe.d.ts +1 -1
- package/dist/lane-home-probe.js +2 -1
- package/dist/leader/diffup.d.ts +19 -0
- package/dist/leader/diffup.js +7 -0
- package/dist/leader/leader.d.ts +114 -10
- package/dist/leader/leader.js +69 -5
- package/dist/leader/repair-wire.js +2 -2
- package/dist/leader/run-entry.d.ts +2 -1
- package/dist/leader/run-entry.js +1 -1
- package/dist/leader/wire.d.ts +42 -132
- package/dist/leader/wire.js +81 -67
- package/dist/memory-scope.d.ts +20 -9
- package/dist/memory-scope.js +15 -3
- package/dist/model-entry-headers.d.ts +9 -10
- package/dist/model-entry-headers.js +0 -4
- package/dist/model-entry-refusal.d.ts +7 -4
- package/dist/model-entry-refusal.js +11 -5
- package/dist/model-plane-face.d.ts +1 -1
- package/dist/model-plane-face.js +3 -1
- package/dist/model-route-endpoint.d.ts +13 -7
- package/dist/model-route-endpoint.js +14 -11
- package/dist/model-select.d.ts +22 -0
- package/dist/model-select.js +9 -0
- package/dist/model-unreachable-notice.d.ts +11 -0
- package/dist/model-unreachable-notice.js +4 -4
- package/dist/object-store-buckets.d.ts +640 -6
- package/dist/object-store-buckets.js +166 -0
- package/dist/observability/fail-open.d.ts +20 -16
- package/dist/observability/fail-open.js +20 -16
- package/dist/observability/logger.js +3 -1
- package/dist/operator-roster.d.ts +68 -0
- package/dist/operator-roster.js +32 -0
- package/dist/orchestration/workflow-park-decision.d.ts +1 -1
- package/dist/outbound-dispatcher.d.ts +71 -8
- package/dist/outbound-dispatcher.js +48 -7
- package/dist/owner-faces.d.ts +1 -1
- package/dist/parked-decide.d.ts +2 -2
- package/dist/permission-mode-admission.d.ts +59 -26
- package/dist/permission-mode-admission.js +37 -10
- package/dist/plugins/approval-ask-store-file.d.ts +4 -0
- package/dist/plugins/approval-ask-store-file.js +3 -0
- package/dist/plugins/approval-ask-store-memory.d.ts +4 -0
- package/dist/plugins/approval-ask-store-memory.js +7 -1
- package/dist/plugins/approval-ask-store-sql.d.ts +26 -2
- package/dist/plugins/approval-ask-store-sql.js +12 -1
- package/dist/plugins/blob-backend.d.ts +83 -7
- package/dist/plugins/blob-backend.js +57 -6
- package/dist/plugins/checkpoint-index-columns.d.ts +20 -16
- package/dist/plugins/checkpoint-index-columns.js +3 -6
- package/dist/plugins/checkpoint-store-face.d.ts +119 -61
- package/dist/plugins/checkpoint-store-face.js +134 -55
- package/dist/plugins/landed-attendants.d.ts +2 -2
- package/dist/plugins/local-checkpoint-store.d.ts +13 -3
- package/dist/plugins/local-checkpoint-store.js +38 -49
- package/dist/plugins/one-time-migrations.d.ts +51 -21
- package/dist/plugins/one-time-migrations.js +67 -45
- package/dist/plugins/pg-pool.js +11 -9
- package/dist/plugins/remote-env-host.d.ts +29 -10
- package/dist/plugins/remote-env-host.js +99 -19
- package/dist/plugins/remote-env-k8s.d.ts +68 -2
- package/dist/plugins/remote-env-k8s.js +107 -24
- package/dist/plugins/replica-registration.d.ts +1 -1
- package/dist/plugins/replica-registration.js +1 -1
- package/dist/plugins/s3-presign.d.ts +23 -0
- package/dist/plugins/s3-presign.js +37 -3
- package/dist/plugins/scheduler-support.d.ts +2 -2
- package/dist/plugins/scheduler-support.js +0 -3
- package/dist/plugins/schema-indexes.js +2 -0
- package/dist/plugins/send-file-ledger.d.ts +2 -2
- package/dist/plugins/send-file-ledger.js +2 -2
- package/dist/plugins/send-user-file.d.ts +3 -4
- package/dist/plugins/send-user-file.js +56 -52
- package/dist/plugins/session-blob-claim-token.d.ts +15 -0
- package/dist/plugins/session-blob-claim-token.js +20 -0
- package/dist/plugins/session-blob-namespace.d.ts +46 -0
- package/dist/plugins/session-blob-namespace.js +116 -0
- package/dist/plugins/snapshot-bucket-presence.d.ts +25 -2
- package/dist/plugins/snapshot-bucket-presence.js +8 -2
- package/dist/plugins/sql-json-column.d.ts +1 -1
- package/dist/plugins/store-backend.d.ts +44 -2
- package/dist/plugins/store-backend.js +75 -53
- package/dist/plugins/task-attachment-store.d.ts +2 -1
- package/dist/plugins/task-attachment-store.js +5 -1
- package/dist/plugins/tidb-pool.js +19 -24
- package/dist/plugins/workspace-custody.d.ts +4 -3
- package/dist/question.d.ts +2 -1
- package/dist/question.js +5 -13
- package/dist/request-form.d.ts +6 -1
- package/dist/request-form.js +4 -1
- package/dist/rule-issue-reading.d.ts +1 -1
- package/dist/rules-consent.d.ts +1 -1
- package/dist/run-local.js +8 -9
- package/dist/runs.d.ts +17 -8
- package/dist/runs.js +15 -2
- package/dist/runtime-governance.d.ts +2 -2
- package/dist/sema-config-dir.d.ts +2 -1
- package/dist/session-sync.d.ts +27 -11
- package/dist/session-sync.js +15 -7
- package/dist/stores-sql/blob-index-sql.d.ts +30 -9
- package/dist/stores-sql/blob-index-sql.js +40 -21
- package/dist/stores-sql/checkpoint-store-sql.d.ts +54 -27
- package/dist/stores-sql/checkpoint-store-sql.js +70 -146
- package/dist/stores-sql/file-history-store-sql.d.ts +64 -16
- package/dist/stores-sql/file-history-store-sql.js +100 -28
- package/dist/stores-sql/retention-store-sql.js +3 -9
- package/dist/task-settings.d.ts +6 -5
- package/dist/task-settings.js +3 -3
- package/dist/tool-approval.d.ts +342 -518
- package/dist/tool-approval.js +498 -1207
- package/dist/trace/core-keyset-guard.d.ts +1 -1
- package/dist/trace/ledger-events.d.ts +3 -3
- package/dist/trace/project.d.ts +2 -3
- package/dist/trace/redact.js +3 -2
- package/dist/trace/self-minted-wire.d.ts +287 -157
- package/dist/trace/self-minted-wire.js +93 -48
- package/dist/web-admin-client/apply-effective.js +2 -2
- package/dist/web-admin-client/read-warnings.d.ts +2 -2
- package/dist/web-admin-client/read-warnings.js +1 -1
- package/dist/web-admin-client/types.d.ts +1 -1
- package/dist/workspace-space.d.ts +10 -4
- package/dist/workspace-space.js +4 -1
- package/docs/DEVICE-EXECUTOR-PROTOCOL.md +1 -1
- package/package.json +6 -2
- package/scripts/embed-minimal.mjs +3 -3
- package/wire-changes/server@7.152.0.json +900 -0
- package/dist/config-d-migration.d.ts +0 -37
- package/dist/config-d-migration.js +0 -60
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { captureFileBackupViaEnv, applyFileRestoreViaEnv, fileHistoryModeProvenDifferent, worldStillMatchesMint, annulProofFailure, boundaryPublishVerdict, fileHistoryDescribeTrackKey, fileHistoryTrackKeyOf, fileHistoryResolveTrackKey, fileHistoryExportDigest, validateFileHistoryExport, resolveFileHistoryRetention, fileHistoryBoundariesToKeep, } from "@sema-agent/core";
|
|
3
|
-
import { BlobTooLargeError, SqlBlobIndex } from "./blob-index-sql.js";
|
|
3
|
+
import { BlobTooLargeError, SqlBlobIndex, blobGcCutoffAt, hashBatches } from "./blob-index-sql.js";
|
|
4
4
|
import { mysqlDriver, pgDriver } from "../plugins/sql-driver.js";
|
|
5
5
|
import { isMissingColumnError, retryOnDeadlock, SqlArbitrationLostError } from "../plugins/sql-errors.js";
|
|
6
6
|
import { probedMissingColumnRefusal } from "../plugins/schema-drift-sentence.js";
|
|
7
7
|
import { recordFailOpen } from "../observability/fail-open.js";
|
|
8
8
|
import { foldCaughtFailure } from "../file-history-disclosure.js";
|
|
9
9
|
export const FILE_HISTORY_BLOB_TABLE = "file_history_blob";
|
|
10
|
-
export const
|
|
10
|
+
export const FILE_HISTORY_BLOB_GRANT_TABLE = "file_history_blob_grant";
|
|
11
|
+
export const FILE_HISTORY_SCOPED_TABLES = [
|
|
12
|
+
"file_history_boundary_file",
|
|
13
|
+
"file_history_boundary",
|
|
14
|
+
"file_history_reaped_entry",
|
|
15
|
+
"file_history_version",
|
|
16
|
+
"file_history_tracked",
|
|
17
|
+
FILE_HISTORY_BLOB_GRANT_TABLE,
|
|
18
|
+
"file_history_scope",
|
|
19
|
+
];
|
|
11
20
|
const sha256hex = (s) => createHash("sha256").update(s).digest("hex");
|
|
12
21
|
const truthy = (v) => v === true || v === 1 || v === "1";
|
|
13
22
|
class StagedRefGoneError extends Error {
|
|
14
23
|
}
|
|
15
24
|
class ScopeSentinelVanishedError extends SqlArbitrationLostError {
|
|
16
25
|
}
|
|
17
|
-
const FILE_HISTORY_SCOPED_TABLES = ["file_history_boundary_file", "file_history_boundary", "file_history_reaped_entry", "file_history_version", "file_history_tracked", "file_history_scope"];
|
|
18
26
|
function reapedEntryRefusal(entryId) {
|
|
19
27
|
return {
|
|
20
28
|
ok: false,
|
|
@@ -24,14 +32,89 @@ function reapedEntryRefusal(entryId) {
|
|
|
24
32
|
},
|
|
25
33
|
};
|
|
26
34
|
}
|
|
35
|
+
export class SqlBlobExchange {
|
|
36
|
+
blobs;
|
|
37
|
+
constructor(blobs) {
|
|
38
|
+
this.blobs = blobs;
|
|
39
|
+
}
|
|
40
|
+
async put(hash, bytes) {
|
|
41
|
+
if (sha256hex(bytes) !== hash) {
|
|
42
|
+
return { ok: false, error: { code: "adopt_failed", message: `blob ${hash}: the bytes do not hash to this address — nothing stored`, permanence: "terminal" } };
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
await this.blobs.put(hash, bytes);
|
|
46
|
+
return { ok: true };
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
if (err instanceof BlobTooLargeError)
|
|
50
|
+
return { ok: false, error: { code: "adopt_failed", message: err.message, permanence: "terminal", blobCap: { wallSource: err.cap.source } } };
|
|
51
|
+
const f = foldCaughtFailure(err, "sql-blob-exchange.put");
|
|
52
|
+
return { ok: false, error: { code: "snapshot_failed", message: `blob ${hash} write/upload failed: ${f.text}`, ...f.fault } };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
get(hash) {
|
|
56
|
+
return this.blobs.get(hash);
|
|
57
|
+
}
|
|
58
|
+
has(hashes) {
|
|
59
|
+
return this.blobs.has([...hashes]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export class SqlBlobLanding {
|
|
63
|
+
db;
|
|
64
|
+
exchange;
|
|
65
|
+
constructor(db, exchange) {
|
|
66
|
+
this.db = db;
|
|
67
|
+
this.exchange = exchange;
|
|
68
|
+
}
|
|
69
|
+
q(mysql, pg) {
|
|
70
|
+
return this.db.dialect === "mysql" ? mysql : pg;
|
|
71
|
+
}
|
|
72
|
+
static ownerKey(landing) {
|
|
73
|
+
return landing.owner ?? "";
|
|
74
|
+
}
|
|
75
|
+
async putAt(landing, hash, bytes) {
|
|
76
|
+
const stored = await this.exchange.put(hash, bytes);
|
|
77
|
+
if (!stored.ok)
|
|
78
|
+
return stored;
|
|
79
|
+
try {
|
|
80
|
+
await this.db.query(this.q(`INSERT INTO ${FILE_HISTORY_BLOB_GRANT_TABLE} (scope, landing_owner, blob_hash, granted_at) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE granted_at = GREATEST(granted_at, VALUES(granted_at))`, `INSERT INTO ${FILE_HISTORY_BLOB_GRANT_TABLE} (scope, landing_owner, blob_hash, granted_at) VALUES ($1,$2,$3,$4) ON CONFLICT (scope, landing_owner, blob_hash) DO UPDATE SET granted_at = GREATEST(${FILE_HISTORY_BLOB_GRANT_TABLE}.granted_at, EXCLUDED.granted_at)`), [landing.sessionId, SqlBlobLanding.ownerKey(landing), hash, new Date()]);
|
|
81
|
+
return { ok: true };
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
const f = foldCaughtFailure(err, "sql-blob-landing.putAt");
|
|
85
|
+
return { ok: false, error: { code: "snapshot_failed", message: `blob ${hash} was stored but its upload grant could not be recorded: ${f.text}`, ...f.fault } };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async visibleAt(landing, hashes) {
|
|
89
|
+
const wanted = new Set(hashes);
|
|
90
|
+
if (wanted.size === 0)
|
|
91
|
+
return new Set();
|
|
92
|
+
const candidates = new Set();
|
|
93
|
+
if (landing.occupied) {
|
|
94
|
+
const graph = await this.db.query(this.q("SELECT DISTINCT blob_hash FROM file_history_version WHERE scope = ? AND blob_hash IS NOT NULL", "SELECT DISTINCT blob_hash FROM file_history_version WHERE scope = $1 AND blob_hash IS NOT NULL"), [landing.sessionId]);
|
|
95
|
+
for (const r of graph.rows) {
|
|
96
|
+
const h = String(r.blob_hash);
|
|
97
|
+
if (wanted.has(h))
|
|
98
|
+
candidates.add(h);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const ungranted = [...wanted].filter((h) => !candidates.has(h));
|
|
102
|
+
for (const batch of hashBatches(ungranted)) {
|
|
103
|
+
const ph = batch.map((_, i) => (this.db.dialect === "mysql" ? "?" : `$${i + 3}`)).join(",");
|
|
104
|
+
const granted = await this.db.query(this.q(`SELECT blob_hash FROM ${FILE_HISTORY_BLOB_GRANT_TABLE} WHERE scope = ? AND landing_owner = ? AND blob_hash IN (${ph})`, `SELECT blob_hash FROM ${FILE_HISTORY_BLOB_GRANT_TABLE} WHERE scope = $1 AND landing_owner = $2 AND blob_hash IN (${ph})`), [landing.sessionId, SqlBlobLanding.ownerKey(landing), ...batch]);
|
|
105
|
+
for (const r of granted.rows)
|
|
106
|
+
candidates.add(String(r.blob_hash));
|
|
107
|
+
}
|
|
108
|
+
if (candidates.size === 0)
|
|
109
|
+
return new Set();
|
|
110
|
+
return this.exchange.has([...candidates]);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
27
113
|
export class SqlFileHistoryStore {
|
|
28
114
|
db;
|
|
29
115
|
pool;
|
|
30
|
-
blobExchange
|
|
31
|
-
|
|
32
|
-
get: (hash) => this.blobs.get(hash),
|
|
33
|
-
has: (hashes) => this.blobs.has([...hashes]),
|
|
34
|
-
};
|
|
116
|
+
blobExchange;
|
|
117
|
+
blobLanding;
|
|
35
118
|
blobs;
|
|
36
119
|
spentAttempts = new Set();
|
|
37
120
|
activeAttempts = new Set();
|
|
@@ -45,6 +128,8 @@ export class SqlFileHistoryStore {
|
|
|
45
128
|
...(opts?.blobSqlMaxBytes !== undefined ? { maxBytes: opts.blobSqlMaxBytes } : {}),
|
|
46
129
|
...(opts?.log !== undefined ? { log: opts.log } : {}),
|
|
47
130
|
});
|
|
131
|
+
this.blobExchange = new SqlBlobExchange(this.blobs);
|
|
132
|
+
this.blobLanding = new SqlBlobLanding(this.db, this.blobExchange);
|
|
48
133
|
this.boundaryKeep = resolveFileHistoryRetention(this.db.dialect === "mysql" ? "TiDBFileHistoryStore" : "PgFileHistoryStore", opts?.retention);
|
|
49
134
|
}
|
|
50
135
|
q(mysql, pg) {
|
|
@@ -607,26 +692,12 @@ export class SqlFileHistoryStore {
|
|
|
607
692
|
return total;
|
|
608
693
|
}
|
|
609
694
|
async sweepOrphanBlobs() {
|
|
610
|
-
const
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
async putExchangedBlob(hash, bytes) {
|
|
617
|
-
if (sha256hex(bytes) !== hash) {
|
|
618
|
-
return { ok: false, error: { code: "adopt_failed", message: `blob ${hash}: the bytes do not hash to this address — nothing stored`, permanence: "terminal" } };
|
|
619
|
-
}
|
|
620
|
-
try {
|
|
621
|
-
await this.blobs.put(hash, bytes);
|
|
622
|
-
return { ok: true };
|
|
623
|
-
}
|
|
624
|
-
catch (err) {
|
|
625
|
-
if (err instanceof BlobTooLargeError)
|
|
626
|
-
return { ok: false, error: { code: "adopt_failed", message: err.message, permanence: "terminal", blobCap: { wallSource: err.cap.source } } };
|
|
627
|
-
const f = foldCaughtFailure(err, "sql-file-history-store.putExchangedBlob");
|
|
628
|
-
return { ok: false, error: { code: "snapshot_failed", message: `blob ${hash} write/upload failed: ${f.text}`, ...f.fault } };
|
|
629
|
-
}
|
|
695
|
+
const cutoff = blobGcCutoffAt(Date.now());
|
|
696
|
+
return this.blobs.sweep(async () => {
|
|
697
|
+
await this.db.query(this.q(`DELETE FROM ${FILE_HISTORY_BLOB_GRANT_TABLE} WHERE granted_at < ?`, `DELETE FROM ${FILE_HISTORY_BLOB_GRANT_TABLE} WHERE granted_at < $1`), [cutoff]);
|
|
698
|
+
const { rows } = await this.db.query(`SELECT blob_hash FROM ${FILE_HISTORY_BLOB_TABLE} WHERE blob_hash NOT IN (SELECT blob_hash FROM file_history_version WHERE blob_hash IS NOT NULL) AND blob_hash NOT IN (SELECT blob_hash FROM ${FILE_HISTORY_BLOB_GRANT_TABLE})`);
|
|
699
|
+
return rows.map((r) => String(r.blob_hash));
|
|
700
|
+
}, cutoff);
|
|
630
701
|
}
|
|
631
702
|
async adoptScope(fromScope, toScope) {
|
|
632
703
|
try {
|
|
@@ -874,6 +945,7 @@ export async function assertFileHistorySchema(query, dialect) {
|
|
|
874
945
|
["file_history_scope", "SELECT scope, created_at_ms FROM file_history_scope WHERE 1=0"],
|
|
875
946
|
["file_history_reaped_entry", "SELECT scope, entry_id, reaped_at_ms FROM file_history_reaped_entry WHERE 1=0"],
|
|
876
947
|
[FILE_HISTORY_BLOB_TABLE, `SELECT blob_hash, byte_len, bytes, created_at FROM ${FILE_HISTORY_BLOB_TABLE} WHERE 1=0`],
|
|
948
|
+
[FILE_HISTORY_BLOB_GRANT_TABLE, `SELECT scope, landing_owner, blob_hash, granted_at FROM ${FILE_HISTORY_BLOB_GRANT_TABLE} WHERE 1=0`],
|
|
877
949
|
];
|
|
878
950
|
for (const [table, sql] of probes) {
|
|
879
951
|
try {
|
|
@@ -3,6 +3,7 @@ import { incarnationFromCell } from "../session-incarnation.js";
|
|
|
3
3
|
import { MANAGED_RETENTION } from "../plugins/retention-declaration.js";
|
|
4
4
|
import { retentionDomainWhere, retentionIdSet, sessionLiveReferenceSql } from "../plugins/retention-sql.js";
|
|
5
5
|
import { dropMailboxBoxOn } from "./mailbox-store-sql.js";
|
|
6
|
+
import { FILE_HISTORY_SCOPED_TABLES } from "./file-history-store-sql.js";
|
|
6
7
|
import { SEALED_EVENT, eraseSessionPolicyRowsOn } from "./session-policy-store-sql.js";
|
|
7
8
|
export const RETENTION_TOMBSTONE_TABLE = "retention_tombstone";
|
|
8
9
|
export const TIDB_RETENTION_TOMBSTONE_STATEMENTS = [
|
|
@@ -352,15 +353,8 @@ export class SqlRetentionStore {
|
|
|
352
353
|
});
|
|
353
354
|
}
|
|
354
355
|
}
|
|
355
|
-
for (const
|
|
356
|
-
|
|
357
|
-
["file_history_version", "scope"],
|
|
358
|
-
["file_history_boundary", "scope"],
|
|
359
|
-
["file_history_boundary_file", "scope"],
|
|
360
|
-
["file_history_scope", "scope"],
|
|
361
|
-
["file_history_reaped_entry", "scope"],
|
|
362
|
-
]) {
|
|
363
|
-
const s = set(col, 1);
|
|
356
|
+
for (const table of FILE_HISTORY_SCOPED_TABLES) {
|
|
357
|
+
const s = set("scope", 1);
|
|
364
358
|
await conn.query(`DELETE FROM ${table} WHERE ${s.sql}`, s.params);
|
|
365
359
|
}
|
|
366
360
|
if (this.opts.sessionBoxScope !== undefined) {
|
package/dist/task-settings.d.ts
CHANGED
|
@@ -122,11 +122,12 @@ export declare function planReviewDecisionExitsPlan(decision: "approve" | "edit"
|
|
|
122
122
|
* 新体 `{ ...body, permissionMode: entry.effective }`,调用方的对象不改;bundle 的 `settings.permissions.defaultMode` 不动 —— 顶层赢过它
|
|
123
123
|
* ({@link effectivePermissionMode} 的优先序),再改它就是同一语义的第二个写者。披露这一折的通告(`entry-mode-clamp-notice.ts`)读的也是同一份 `entry`。
|
|
124
124
|
*
|
|
125
|
-
*
|
|
126
|
-
* 值形门全部判完之后、`resolveSpec` 之前 —— 那一份体就是首跑装配读的体,也是 `buildCheckpointCtx`
|
|
127
|
-
* 的 `replayCtxOf
|
|
128
|
-
* run
|
|
129
|
-
*
|
|
125
|
+
* 调用点一个:提交口 `stampSubmissionEntryMode`(`permission-mode-admission.ts`,受理判官的入口一步 `bodyEntry`;`http/admission.ts` 的 `prepareSpec` 调它:
|
|
126
|
+
* 值形门全部判完之后、`resolveSpec` 之前 —— 那一份体就是首跑装配读的体,也是 `buildCheckpointCtx` 持久化的体,写据 `submission` 记下它的顶层原值)。
|
|
127
|
+
* 存储体那一格的其余写者都经同一模块的改写口 `withStoredPermissionMode`(一笔换词、换写据):续跑口(`stampReplayEntryMode`,`http/resume-legs.ts` 的 `replayCtxOf`:
|
|
128
|
+
* 停驻 run 的存储体被重放之前过一次**现**地板 —— 同一只 `bodyEntry`;写据说那一格是地板的出口写下的且仍是它写下的那一格 ⇒ 原样;钳过的体随 CAS 赢点写回)、
|
|
129
|
+
* `plan_review` 写回(`http/resume-legs.ts` `drivePlanReview`,判据 {@link planReviewDecisionExitsPlan};plan 地板的出口)与在飞 run 的切档口写回
|
|
130
|
+
* (`http/routes/run-permission-mode.ts`,写的是同一只判官准入的词)。装配腿不读地板;每一腿读一次地板、写进体,run 的模式词仍只有存储体一个源。
|
|
130
131
|
* 热改 `AUTONOMY` 对之后的提交、切档与停驻 run 的下一次续跑都生效。地板的属主是 `runtime-governance.ts` 的 `autonomyModeFloor`。
|
|
131
132
|
*/
|
|
132
133
|
export declare function stampEntryPermissionMode<B extends {
|
package/dist/task-settings.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { combinePolicies, parseRuleText, resolveReasoningProfile, rankOf, isThinkingLevel, RUN_WORKFLOW_TOOL_NAME, PERMISSION_MODES, isPermissionMode, ruleToolGrammarOf, hostChildEnvProblem, } from "@sema-agent/core";
|
|
2
2
|
import { judgeUnmatchableToolNames } from "./config.js";
|
|
3
3
|
import { NAME_TABLE_BEHAVIOR } from "./namespaced-rule-name.js";
|
|
4
|
-
import { entryProblem } from "./entry-problems.js";
|
|
4
|
+
import { HOME_UNRESOLVABLE, entryProblem } from "./entry-problems.js";
|
|
5
5
|
import { MAX_PERMISSION_RULES_PER_LIST, RULE_ROOTS, allowListEntryOk, createRuleListPolicy, ruleListEntryOk, ruleRootOf, ruleSetsOf, ruleSourceOf, ruleTextOf } from "./permission-rule-list.js";
|
|
6
6
|
import { allowLayerEntryCountIssue, describeAllowLayerOverCap } from "./rule-entry-list.js";
|
|
7
7
|
import { limitRefusal } from "./limit-refusal.js";
|
|
@@ -498,7 +498,7 @@ export function rulePolicyBucketsRefusal(permissions, bases) {
|
|
|
498
498
|
`the engine never guesses one: without a home base the rule resolves to "unreadable" and every matching call stops to ask, so it guards nothing. ` +
|
|
499
499
|
`Spell the path absolutely (${"Edit(//abs/path/**)"} form), declare the lane's home with REMOTE_EXEC_HOME_DIR, or run the task on a lane whose home this worker knows.`,
|
|
500
500
|
};
|
|
501
|
-
problems.push(entryProblem(SETTINGS_RULE_REFUSAL_CODE, `settings.${field}`, name,
|
|
501
|
+
problems.push(entryProblem(SETTINGS_RULE_REFUSAL_CODE, `settings.${field}`, name, HOME_UNRESOLVABLE));
|
|
502
502
|
}
|
|
503
503
|
}
|
|
504
504
|
}
|
|
@@ -513,7 +513,7 @@ export function rulePolicyBucketsRefusal(permissions, bases) {
|
|
|
513
513
|
`it is the SEMA_CONFIG_DIR forwarded into the sandbox, else .sema under the execution environment's home, and this lane's home is unknown; the engine never guesses one. ` +
|
|
514
514
|
`Spell the path absolutely (${"Read(//abs/path/**)"} form), forward SEMA_CONFIG_DIR into the sandbox env, declare the lane's home with REMOTE_EXEC_HOME_DIR, or run the task on a lane whose home this worker knows.`,
|
|
515
515
|
};
|
|
516
|
-
problems.push(entryProblem(SETTINGS_RULE_REFUSAL_CODE, `settings.${field}`, name,
|
|
516
|
+
problems.push(entryProblem(SETTINGS_RULE_REFUSAL_CODE, `settings.${field}`, name, HOME_UNRESOLVABLE));
|
|
517
517
|
}
|
|
518
518
|
}
|
|
519
519
|
}
|