@tangle-network/agent-app 0.60.250 → 0.60.252
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/dist/DesignCanvas-L6J72JQ2.js +15 -0
- package/dist/DesignCanvasEditor-QFQD63MR.js +18 -0
- package/dist/agent-enrollment/drizzle.js +3 -3
- package/dist/agent-enrollment/index.js +3 -3
- package/dist/app-auth/drizzle.d.ts +475 -0
- package/dist/app-auth/drizzle.js +86 -0
- package/dist/app-auth/drizzle.js.map +1 -0
- package/dist/app-auth/index.js +5 -3
- package/dist/app-auth/index.js.map +1 -1
- package/dist/app-oauth/drizzle.d.ts +2080 -0
- package/dist/app-oauth/drizzle.js +161 -0
- package/dist/app-oauth/drizzle.js.map +1 -0
- package/dist/app-oauth/index.d.ts +4 -0
- package/dist/app-oauth/index.js +8 -222
- package/dist/app-oauth/index.js.map +1 -1
- package/dist/app-oauth/issuer.d.ts +133 -0
- package/dist/app-oauth/issuer.js +247 -0
- package/dist/app-oauth/issuer.js.map +1 -0
- package/dist/assistant/index.js +13 -13
- package/dist/chat-react/index.js +4 -4
- package/dist/chat-routes/index.js +37 -67
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-routes/promote-file-part.d.ts +2 -3
- package/dist/chat-store/index.js +4 -4
- package/dist/{chunk-MY3EJJ6Y.js → chunk-4FEH6266.js} +2 -2
- package/dist/{chunk-5Y7Z5G3Y.js → chunk-4GCPADYG.js} +20 -336
- package/dist/chunk-4GCPADYG.js.map +1 -0
- package/dist/{chunk-X556WVBG.js → chunk-4ZSLX3LY.js} +2 -2
- package/dist/chunk-57XPEL7X.js +26 -0
- package/dist/chunk-57XPEL7X.js.map +1 -0
- package/dist/chunk-6Z7TZVKZ.js +26 -0
- package/dist/chunk-6Z7TZVKZ.js.map +1 -0
- package/dist/{chunk-7KKOFMLD.js → chunk-AWIQQEFP.js} +1 -1
- package/dist/chunk-AWIQQEFP.js.map +1 -0
- package/dist/{chunk-VBKP2NLI.js → chunk-BTKI4XMM.js} +2 -2
- package/dist/{chunk-63QAQP7I.js → chunk-CNBVWPQC.js} +7 -7
- package/dist/{chunk-FENBDSIW.js → chunk-CQGEGPY7.js} +75 -3
- package/dist/chunk-CQGEGPY7.js.map +1 -0
- package/dist/chunk-CTREXL3O.js +335 -0
- package/dist/chunk-CTREXL3O.js.map +1 -0
- package/dist/chunk-DLWO3J7D.js +238 -0
- package/dist/chunk-DLWO3J7D.js.map +1 -0
- package/dist/{chunk-LWSJK546.js → chunk-DSMGS4IV.js} +5 -5
- package/dist/{chunk-LWSJK546.js.map → chunk-DSMGS4IV.js.map} +1 -1
- package/dist/{chunk-A3KPDLSF.js → chunk-EFPIHR6F.js} +18 -18
- package/dist/chunk-FRAICFTZ.js +191 -0
- package/dist/chunk-FRAICFTZ.js.map +1 -0
- package/dist/chunk-GS7VWV26.js +61 -0
- package/dist/chunk-GS7VWV26.js.map +1 -0
- package/dist/{chunk-NMSAZFRL.js → chunk-H5GQMLHA.js} +2 -2
- package/dist/{chunk-OQE6WMDP.js → chunk-HN6MZ2XL.js} +5 -5
- package/dist/chunk-HY57QRRW.js +11 -0
- package/dist/chunk-HY57QRRW.js.map +1 -0
- package/dist/{chunk-TCGZFSN5.js → chunk-KH4QSBNI.js} +2 -2
- package/dist/{chunk-JH3CKHF4.js → chunk-KJODHPWM.js} +8 -8
- package/dist/chunk-LSBI5MWS.js +66 -0
- package/dist/chunk-LSBI5MWS.js.map +1 -0
- package/dist/chunk-MDRH3SDA.js +106 -0
- package/dist/chunk-MDRH3SDA.js.map +1 -0
- package/dist/{chunk-VBWYH7UZ.js → chunk-NHYRIM4I.js} +3 -3
- package/dist/{chunk-BYP54FMI.js → chunk-O2RCDK5D.js} +30 -15
- package/dist/{chunk-BYP54FMI.js.map → chunk-O2RCDK5D.js.map} +1 -1
- package/dist/{chunk-EWOJATDS.js → chunk-PDD5A43Y.js} +3 -3
- package/dist/{chunk-23JUSUUB.js → chunk-RZLCBWGG.js} +2 -2
- package/dist/chunk-SFZELD6V.js +52 -0
- package/dist/chunk-SFZELD6V.js.map +1 -0
- package/dist/{chunk-Y4W6GK5X.js → chunk-UGFCLD32.js} +2 -2
- package/dist/{chunk-ZGUXI5SI.js → chunk-VUBJZEZB.js} +2 -2
- package/dist/{chunk-LQYIBL3G.js → chunk-WL7PZK7Q.js} +71 -1
- package/dist/chunk-WL7PZK7Q.js.map +1 -0
- package/dist/{chunk-7HZCFG2A.js → chunk-WP2GYFZ4.js} +38 -1
- package/dist/chunk-WP2GYFZ4.js.map +1 -0
- package/dist/{chunk-JK7R7BZQ.js → chunk-ZWJ3SZ2G.js} +2 -2
- package/dist/crypto/digest.d.ts +2 -0
- package/dist/crypto/index.d.ts +1 -0
- package/dist/crypto/index.js +6 -2
- package/dist/design-canvas/index.js +5 -3
- package/dist/design-canvas/index.js.map +1 -1
- package/dist/design-canvas-react/engine.js +7 -5
- package/dist/design-canvas-react/index.js +14 -12
- package/dist/design-canvas-react/index.js.map +1 -1
- package/dist/design-canvas-react/lazy.js +1 -1
- package/dist/eval/index.d.ts +4 -0
- package/dist/eval/index.js +125 -0
- package/dist/eval/index.js.map +1 -1
- package/dist/eval/persona-driver.d.ts +37 -0
- package/dist/eval/research-plan.d.ts +25 -0
- package/dist/eval/research-plan.js +55 -0
- package/dist/eval/research-plan.js.map +1 -0
- package/dist/eval/scorecard.d.ts +38 -0
- package/dist/forms/blank.d.ts +2 -2
- package/dist/forms/index.js +4 -5
- package/dist/forms/index.js.map +1 -1
- package/dist/hosted-agent/application.js +2 -2
- package/dist/interactions/index.js +3 -3
- package/dist/knowledge/prelaunch-audit.d.ts +17 -0
- package/dist/knowledge/prelaunch-audit.js +67 -0
- package/dist/knowledge/prelaunch-audit.js.map +1 -0
- package/dist/media/drizzle.d.ts +207 -0
- package/dist/media/drizzle.js +26 -0
- package/dist/media/drizzle.js.map +1 -0
- package/dist/media/generate-request.d.ts +53 -0
- package/dist/media/generation-record.d.ts +68 -0
- package/dist/media/index.d.ts +13 -0
- package/dist/media/index.js +653 -0
- package/dist/media/index.js.map +1 -0
- package/dist/media/model-catalog.d.ts +109 -0
- package/dist/media/router-client.d.ts +40 -0
- package/dist/media/router-generation.d.ts +44 -0
- package/dist/media/speech-script.d.ts +20 -0
- package/dist/openui/index.js +1 -1
- package/dist/operator/index.js +4 -5
- package/dist/operator/index.js.map +1 -1
- package/dist/plans/decision.d.ts +48 -0
- package/dist/plans/drizzle.d.ts +25 -0
- package/dist/plans/drizzle.js +97 -0
- package/dist/plans/drizzle.js.map +1 -0
- package/dist/plans/index.d.ts +1 -1
- package/dist/plans/index.js +11 -3
- package/dist/platform/billing-config.d.ts +22 -0
- package/dist/platform/billing-config.js +36 -0
- package/dist/platform/billing-config.js.map +1 -0
- package/dist/platform/index.js +13 -11
- package/dist/platform/index.js.map +1 -1
- package/dist/preset-cloudflare/index.js +2 -1
- package/dist/preset-cloudflare/index.js.map +1 -1
- package/dist/profile/index.js +4 -5
- package/dist/profile/index.js.map +1 -1
- package/dist/public-consultation/index.d.ts +1 -1
- package/dist/public-consultation/index.js +13 -11
- package/dist/public-consultation/index.js.map +1 -1
- package/dist/runtime/telemetry-cap.d.ts +24 -0
- package/dist/runtime/telemetry-cap.js +36 -0
- package/dist/runtime/telemetry-cap.js.map +1 -0
- package/dist/sandbox/index.js +12 -9
- package/dist/sequences/index.js +4 -2
- package/dist/sequences/index.js.map +1 -1
- package/dist/skills-placement/box.d.ts +50 -0
- package/dist/skills-placement/box.js +204 -0
- package/dist/skills-placement/box.js.map +1 -0
- package/dist/skills-placement/index.js +8 -96
- package/dist/skills-placement/index.js.map +1 -1
- package/dist/spend/budget.d.ts +13 -0
- package/dist/spend/drizzle.d.ts +55 -0
- package/dist/spend/drizzle.js +131 -0
- package/dist/spend/drizzle.js.map +1 -0
- package/dist/spend/index.d.ts +2 -1
- package/dist/spend/index.js +77 -58
- package/dist/spend/index.js.map +1 -1
- package/dist/spend/platform-settlements.d.ts +46 -0
- package/dist/stream/index.js +19 -19
- package/dist/studio/generated-media/index.d.ts +6 -0
- package/dist/studio/generated-media/index.js +590 -0
- package/dist/studio/generated-media/index.js.map +1 -0
- package/dist/studio/generated-media/output.d.ts +27 -0
- package/dist/studio/generated-media/store.d.ts +175 -0
- package/dist/studio-react/download-generations.d.ts +7 -0
- package/dist/studio-react/index.d.ts +1 -0
- package/dist/studio-react/index.js +85 -0
- package/dist/studio-react/index.js.map +1 -1
- package/dist/studio-react/use-studio-route.d.ts +44 -0
- package/dist/teams/invitations-api.d.ts +4 -0
- package/dist/teams/invitations-api.js +44 -32
- package/dist/teams/invitations-api.js.map +1 -1
- package/dist/theme/dom.d.ts +22 -0
- package/dist/theme/dom.js +18 -0
- package/dist/theme/dom.js.map +1 -0
- package/dist/vault/collaboration.d.ts +83 -0
- package/dist/vault/collaboration.js +215 -0
- package/dist/vault/collaboration.js.map +1 -0
- package/dist/vault/server.js +6 -53
- package/dist/vault/server.js.map +1 -1
- package/dist/vault/store/coordinator.d.ts +64 -0
- package/dist/vault/store/index.d.ts +12 -0
- package/dist/vault/store/index.js +1202 -0
- package/dist/vault/store/index.js.map +1 -0
- package/dist/vault/store/paths.d.ts +65 -0
- package/dist/vault/store/revisions.d.ts +211 -0
- package/dist/vault/store/sandbox-sync.d.ts +74 -0
- package/dist/vault/store/store.d.ts +161 -0
- package/dist/vault/store/tree.d.ts +11 -0
- package/dist/web/entry-server.d.ts +7 -0
- package/dist/web/entry-server.js +29 -0
- package/dist/web/entry-server.js.map +1 -0
- package/dist/web/fetch-guard.d.ts +6 -0
- package/dist/web/index.d.ts +3 -0
- package/dist/web/index.js +20 -4
- package/dist/web/mime.d.ts +16 -0
- package/dist/web/rate-limit.d.ts +25 -0
- package/dist/web/timeout.d.ts +9 -0
- package/dist/web-react/agent-profile-editor.js +3 -3
- package/dist/web-react/api-access-panel.d.ts +4 -2
- package/dist/web-react/document.d.ts +41 -0
- package/dist/web-react/document.js +103 -0
- package/dist/web-react/document.js.map +1 -0
- package/dist/web-react/index.js +31 -31
- package/dist/workspace-react/index.js +5 -5
- package/package.json +95 -4
- package/dist/DesignCanvas-OW3W2QXW.js +0 -13
- package/dist/DesignCanvasEditor-TCHZF25W.js +0 -16
- package/dist/chunk-5Y7Z5G3Y.js.map +0 -1
- package/dist/chunk-7HZCFG2A.js.map +0 -1
- package/dist/chunk-7KKOFMLD.js.map +0 -1
- package/dist/chunk-FENBDSIW.js.map +0 -1
- package/dist/chunk-LQYIBL3G.js.map +0 -1
- /package/dist/{DesignCanvas-OW3W2QXW.js.map → DesignCanvas-L6J72JQ2.js.map} +0 -0
- /package/dist/{DesignCanvasEditor-TCHZF25W.js.map → DesignCanvasEditor-QFQD63MR.js.map} +0 -0
- /package/dist/{chunk-MY3EJJ6Y.js.map → chunk-4FEH6266.js.map} +0 -0
- /package/dist/{chunk-X556WVBG.js.map → chunk-4ZSLX3LY.js.map} +0 -0
- /package/dist/{chunk-VBKP2NLI.js.map → chunk-BTKI4XMM.js.map} +0 -0
- /package/dist/{chunk-63QAQP7I.js.map → chunk-CNBVWPQC.js.map} +0 -0
- /package/dist/{chunk-A3KPDLSF.js.map → chunk-EFPIHR6F.js.map} +0 -0
- /package/dist/{chunk-NMSAZFRL.js.map → chunk-H5GQMLHA.js.map} +0 -0
- /package/dist/{chunk-OQE6WMDP.js.map → chunk-HN6MZ2XL.js.map} +0 -0
- /package/dist/{chunk-TCGZFSN5.js.map → chunk-KH4QSBNI.js.map} +0 -0
- /package/dist/{chunk-JH3CKHF4.js.map → chunk-KJODHPWM.js.map} +0 -0
- /package/dist/{chunk-VBWYH7UZ.js.map → chunk-NHYRIM4I.js.map} +0 -0
- /package/dist/{chunk-EWOJATDS.js.map → chunk-PDD5A43Y.js.map} +0 -0
- /package/dist/{chunk-23JUSUUB.js.map → chunk-RZLCBWGG.js.map} +0 -0
- /package/dist/{chunk-Y4W6GK5X.js.map → chunk-UGFCLD32.js.map} +0 -0
- /package/dist/{chunk-ZGUXI5SI.js.map → chunk-VUBJZEZB.js.map} +0 -0
- /package/dist/{chunk-JK7R7BZQ.js.map → chunk-ZWJ3SZ2G.js.map} +0 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isWorkspaceFileExportable
|
|
3
|
+
} from "./chunk-TXD5HXLE.js";
|
|
4
|
+
|
|
5
|
+
// src/vault/store/paths.ts
|
|
6
|
+
var VAULT_KV_KEY_MAX_BYTES = 512;
|
|
7
|
+
var VaultPathError = class extends Error {
|
|
8
|
+
code = "vault.invalid_path";
|
|
9
|
+
path;
|
|
10
|
+
constructor(message, path) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "VaultPathError";
|
|
13
|
+
this.path = path;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var VaultPrivateRuntimeFileError = class extends VaultPathError {
|
|
17
|
+
code = "vault.private_runtime_file";
|
|
18
|
+
constructor(path) {
|
|
19
|
+
super("Runtime configuration is not available through workspace files", path);
|
|
20
|
+
this.name = "VaultPrivateRuntimeFileError";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var VAULT_STORAGE_KEY_KINDS = ["head", "revision", "operation", "metadata", "prefix", "erasure"];
|
|
24
|
+
var VaultStorageKeyError = class extends VaultPathError {
|
|
25
|
+
code = "vault.key_too_long";
|
|
26
|
+
actualBytes;
|
|
27
|
+
maxBytes = VAULT_KV_KEY_MAX_BYTES;
|
|
28
|
+
keyKind;
|
|
29
|
+
constructor(input) {
|
|
30
|
+
const subject = input.path ? `Vault path "${input.path}"` : `Vault ${input.keyKind} key`;
|
|
31
|
+
super(`${subject} exceeds the ${VAULT_KV_KEY_MAX_BYTES}-byte storage key limit`, input.path);
|
|
32
|
+
this.name = "VaultStorageKeyError";
|
|
33
|
+
this.actualBytes = input.actualBytes;
|
|
34
|
+
this.keyKind = input.keyKind;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function vaultPathErrorResponseBody(error) {
|
|
38
|
+
return {
|
|
39
|
+
error: {
|
|
40
|
+
code: error.code,
|
|
41
|
+
message: error.message,
|
|
42
|
+
path: error.path,
|
|
43
|
+
...error instanceof VaultStorageKeyError ? {
|
|
44
|
+
actualBytes: error.actualBytes,
|
|
45
|
+
maxBytes: error.maxBytes,
|
|
46
|
+
keyKind: error.keyKind
|
|
47
|
+
} : {}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function parseVaultPathErrorResponse(value) {
|
|
52
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
53
|
+
const detail = value.error;
|
|
54
|
+
if (!detail || typeof detail !== "object" || Array.isArray(detail)) return null;
|
|
55
|
+
const error = detail;
|
|
56
|
+
const path = typeof error.path === "string" ? error.path : void 0;
|
|
57
|
+
if (error.code === "vault.key_too_long" && typeof error.actualBytes === "number" && VAULT_STORAGE_KEY_KINDS.includes(String(error.keyKind))) {
|
|
58
|
+
return new VaultStorageKeyError({
|
|
59
|
+
path,
|
|
60
|
+
actualBytes: error.actualBytes,
|
|
61
|
+
keyKind: error.keyKind
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (error.code === "vault.private_runtime_file" && path) return new VaultPrivateRuntimeFileError(path);
|
|
65
|
+
if (error.code === "vault.invalid_path" && typeof error.message === "string") {
|
|
66
|
+
return new VaultPathError(error.message, path);
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
function validateWorkspaceId(workspaceId) {
|
|
71
|
+
if (!workspaceId) throw new VaultPathError("Workspace ID is required");
|
|
72
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(workspaceId)) {
|
|
73
|
+
throw new VaultPathError(`Invalid workspace ID: ${workspaceId}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function validateVaultFilePath(filePath) {
|
|
77
|
+
if (!filePath) throw new VaultPathError("File path is required", filePath);
|
|
78
|
+
if (filePath.includes("\0")) throw new VaultPathError("File path must not contain null bytes", filePath);
|
|
79
|
+
if (filePath.startsWith("/")) throw new VaultPathError("File path must be relative", filePath);
|
|
80
|
+
if (filePath.includes("\\")) throw new VaultPathError("File path must use forward slashes", filePath);
|
|
81
|
+
for (const segment of filePath.split("/")) {
|
|
82
|
+
if (!segment) throw new VaultPathError("File path must not contain empty segments", filePath);
|
|
83
|
+
if (segment === "." || segment === "..") {
|
|
84
|
+
throw new VaultPathError('File path must not contain "." or ".." segments', filePath);
|
|
85
|
+
}
|
|
86
|
+
if (segment.startsWith(".")) {
|
|
87
|
+
throw new VaultPathError("File path must not contain hidden segments", filePath);
|
|
88
|
+
}
|
|
89
|
+
if (!/^[A-Za-z0-9._-]+$/.test(segment)) {
|
|
90
|
+
throw new VaultPathError('File path contains unsupported characters; use ASCII letters, digits, ".", "_", and "-"', filePath);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (!isWorkspaceFileExportable(filePath)) throw new VaultPrivateRuntimeFileError(filePath);
|
|
94
|
+
}
|
|
95
|
+
function isHiddenVaultFilePath(filePath) {
|
|
96
|
+
return filePath.split("/").some((segment) => segment.startsWith("."));
|
|
97
|
+
}
|
|
98
|
+
function assertVaultKeyLength(key, input) {
|
|
99
|
+
const actualBytes = new TextEncoder().encode(key).byteLength;
|
|
100
|
+
if (actualBytes > VAULT_KV_KEY_MAX_BYTES) {
|
|
101
|
+
throw new VaultStorageKeyError({ ...input, actualBytes });
|
|
102
|
+
}
|
|
103
|
+
return key;
|
|
104
|
+
}
|
|
105
|
+
function vaultHeadKey(workspaceId, path) {
|
|
106
|
+
validateWorkspaceId(workspaceId);
|
|
107
|
+
validateVaultFilePath(path);
|
|
108
|
+
return assertVaultKeyLength(`vault:${workspaceId}:${path}`, { path, keyKind: "head" });
|
|
109
|
+
}
|
|
110
|
+
function vaultHeadPrefix(workspaceId) {
|
|
111
|
+
validateWorkspaceId(workspaceId);
|
|
112
|
+
return assertVaultKeyLength(`vault:${workspaceId}:`, { keyKind: "prefix" });
|
|
113
|
+
}
|
|
114
|
+
function vaultHeadPathPrefix(workspaceId, pathPrefix) {
|
|
115
|
+
const base = vaultHeadPrefix(workspaceId);
|
|
116
|
+
if (!pathPrefix) return base;
|
|
117
|
+
if (pathPrefix.startsWith("/") || pathPrefix.includes("\\") || pathPrefix.includes("\0") || pathPrefix.split("/").some((segment) => segment === "." || segment === "..")) {
|
|
118
|
+
throw new VaultPathError("Vault path prefix must be relative and normalized", pathPrefix);
|
|
119
|
+
}
|
|
120
|
+
return assertVaultKeyLength(`${base}${pathPrefix}`, { path: pathPrefix, keyKind: "prefix" });
|
|
121
|
+
}
|
|
122
|
+
function vaultErasureKey(workspaceId, path, sequence) {
|
|
123
|
+
validateWorkspaceId(workspaceId);
|
|
124
|
+
validateVaultFilePath(path);
|
|
125
|
+
if (!Number.isSafeInteger(sequence) || sequence < 1) {
|
|
126
|
+
throw new VaultPathError("Vault erasure sequence must be a positive integer", path);
|
|
127
|
+
}
|
|
128
|
+
return assertVaultKeyLength(
|
|
129
|
+
`vault-erasure:${workspaceId}:${path}:${String(sequence).padStart(12, "0")}`,
|
|
130
|
+
{ path, keyKind: "erasure" }
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
function vaultErasureJobKey(workspaceId, path, sequence, chunk) {
|
|
134
|
+
const row = vaultErasureKey(workspaceId, path, sequence);
|
|
135
|
+
const key = `vault-erasure-job:${row.slice("vault-erasure:".length)}${chunk === void 0 ? "" : `:${chunk}`}`;
|
|
136
|
+
return assertVaultKeyLength(key, { path, keyKind: "erasure" });
|
|
137
|
+
}
|
|
138
|
+
function vaultErasurePrefix(workspaceId, pathPrefix = "") {
|
|
139
|
+
validateWorkspaceId(workspaceId);
|
|
140
|
+
return assertVaultKeyLength(`vault-erasure:${workspaceId}:${pathPrefix}`, { path: pathPrefix, keyKind: "prefix" });
|
|
141
|
+
}
|
|
142
|
+
function vaultRevisionKey(workspaceId, revision, path) {
|
|
143
|
+
validateWorkspaceId(workspaceId);
|
|
144
|
+
if (!revision) throw new VaultPathError("Vault revision is required", path);
|
|
145
|
+
return assertVaultKeyLength(`vault-revision:${workspaceId}:${revision}`, { path, keyKind: "revision" });
|
|
146
|
+
}
|
|
147
|
+
function vaultRevisionPrefix(workspaceId) {
|
|
148
|
+
validateWorkspaceId(workspaceId);
|
|
149
|
+
return assertVaultKeyLength(`vault-revision:${workspaceId}:`, { keyKind: "prefix" });
|
|
150
|
+
}
|
|
151
|
+
function vaultOperationKey(workspaceId, operationId, path) {
|
|
152
|
+
validateWorkspaceId(workspaceId);
|
|
153
|
+
if (!operationId) throw new VaultPathError("Vault mutation operationId is required", path);
|
|
154
|
+
return assertVaultKeyLength(`vault-operation:${workspaceId}:${operationId}`, { path, keyKind: "operation" });
|
|
155
|
+
}
|
|
156
|
+
function vaultMetaKey(workspaceId, key) {
|
|
157
|
+
validateWorkspaceId(workspaceId);
|
|
158
|
+
if (!key) throw new VaultPathError("Vault metadata key is required");
|
|
159
|
+
return assertVaultKeyLength(`vault-meta:${workspaceId}:${key}`, { keyKind: "metadata" });
|
|
160
|
+
}
|
|
161
|
+
function validateVaultMutationKeys(input) {
|
|
162
|
+
vaultOperationKey(input.workspaceId, input.operationId);
|
|
163
|
+
for (const change of input.changes) {
|
|
164
|
+
vaultHeadKey(input.workspaceId, change.path);
|
|
165
|
+
if (change.revision) vaultRevisionKey(input.workspaceId, change.revision, change.path);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export {
|
|
170
|
+
VAULT_KV_KEY_MAX_BYTES,
|
|
171
|
+
VaultPathError,
|
|
172
|
+
VaultPrivateRuntimeFileError,
|
|
173
|
+
VaultStorageKeyError,
|
|
174
|
+
vaultPathErrorResponseBody,
|
|
175
|
+
parseVaultPathErrorResponse,
|
|
176
|
+
validateWorkspaceId,
|
|
177
|
+
validateVaultFilePath,
|
|
178
|
+
isHiddenVaultFilePath,
|
|
179
|
+
vaultHeadKey,
|
|
180
|
+
vaultHeadPrefix,
|
|
181
|
+
vaultHeadPathPrefix,
|
|
182
|
+
vaultErasureKey,
|
|
183
|
+
vaultErasureJobKey,
|
|
184
|
+
vaultErasurePrefix,
|
|
185
|
+
vaultRevisionKey,
|
|
186
|
+
vaultRevisionPrefix,
|
|
187
|
+
vaultOperationKey,
|
|
188
|
+
vaultMetaKey,
|
|
189
|
+
validateVaultMutationKeys
|
|
190
|
+
};
|
|
191
|
+
//# sourceMappingURL=chunk-FRAICFTZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vault/store/paths.ts"],"sourcesContent":["/**\n * Vault path rules and the KV key layout. Every key the Vault store writes is\n * built here, so a path that passes `validateVaultFilePath` and fits the\n * 512-byte Cloudflare KV key limit is exactly a path the store can hold.\n */\nimport { isWorkspaceFileExportable } from '../../web/file-export'\n\nexport const VAULT_KV_KEY_MAX_BYTES = 512\n\nexport class VaultPathError extends Error {\n readonly code: string = 'vault.invalid_path'\n readonly path?: string\n\n constructor(message: string, path?: string) {\n super(message)\n this.name = 'VaultPathError'\n this.path = path\n }\n}\n\n/** A path the workspace export boundary keeps private (runtime configuration). */\nexport class VaultPrivateRuntimeFileError extends VaultPathError {\n override readonly code = 'vault.private_runtime_file'\n\n constructor(path: string) {\n super('Runtime configuration is not available through workspace files', path)\n this.name = 'VaultPrivateRuntimeFileError'\n }\n}\n\nexport type VaultStorageKeyKind = 'head' | 'revision' | 'operation' | 'metadata' | 'prefix' | 'erasure'\nconst VAULT_STORAGE_KEY_KINDS: readonly string[] = ['head', 'revision', 'operation', 'metadata', 'prefix', 'erasure']\n\nexport class VaultStorageKeyError extends VaultPathError {\n override readonly code = 'vault.key_too_long'\n readonly actualBytes: number\n readonly maxBytes = VAULT_KV_KEY_MAX_BYTES\n readonly keyKind: VaultStorageKeyKind\n\n constructor(input: {\n path?: string\n actualBytes: number\n keyKind: VaultStorageKeyKind\n }) {\n const subject = input.path ? `Vault path \"${input.path}\"` : `Vault ${input.keyKind} key`\n super(`${subject} exceeds the ${VAULT_KV_KEY_MAX_BYTES}-byte storage key limit`, input.path)\n this.name = 'VaultStorageKeyError'\n this.actualBytes = input.actualBytes\n this.keyKind = input.keyKind\n }\n}\n\nexport interface VaultPathErrorResponseBody {\n error: {\n code: string\n message: string\n path?: string\n actualBytes?: number\n maxBytes?: number\n keyKind?: VaultStorageKeyKind\n }\n}\n\nexport function vaultPathErrorResponseBody(error: VaultPathError): VaultPathErrorResponseBody {\n return {\n error: {\n code: error.code,\n message: error.message,\n path: error.path,\n ...(error instanceof VaultStorageKeyError\n ? {\n actualBytes: error.actualBytes,\n maxBytes: error.maxBytes,\n keyKind: error.keyKind,\n }\n : {}),\n },\n }\n}\n\n/** The typed path error a coordinator response carries, or null when it carries none. */\nexport function parseVaultPathErrorResponse(value: unknown): VaultPathError | null {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return null\n const detail = (value as { error?: unknown }).error\n if (!detail || typeof detail !== 'object' || Array.isArray(detail)) return null\n const error = detail as Record<string, unknown>\n const path = typeof error.path === 'string' ? error.path : undefined\n if (error.code === 'vault.key_too_long'\n && typeof error.actualBytes === 'number'\n && VAULT_STORAGE_KEY_KINDS.includes(String(error.keyKind))) {\n return new VaultStorageKeyError({\n path,\n actualBytes: error.actualBytes,\n keyKind: error.keyKind as VaultStorageKeyKind,\n })\n }\n if (error.code === 'vault.private_runtime_file' && path) return new VaultPrivateRuntimeFileError(path)\n if (error.code === 'vault.invalid_path' && typeof error.message === 'string') {\n return new VaultPathError(error.message, path)\n }\n return null\n}\n\nexport function validateWorkspaceId(workspaceId: string): void {\n if (!workspaceId) throw new VaultPathError('Workspace ID is required')\n if (!/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(workspaceId)) {\n throw new VaultPathError(`Invalid workspace ID: ${workspaceId}`)\n }\n}\n\nexport function validateVaultFilePath(filePath: string): void {\n if (!filePath) throw new VaultPathError('File path is required', filePath)\n if (filePath.includes('\\0')) throw new VaultPathError('File path must not contain null bytes', filePath)\n if (filePath.startsWith('/')) throw new VaultPathError('File path must be relative', filePath)\n if (filePath.includes('\\\\')) throw new VaultPathError('File path must use forward slashes', filePath)\n\n for (const segment of filePath.split('/')) {\n if (!segment) throw new VaultPathError('File path must not contain empty segments', filePath)\n if (segment === '.' || segment === '..') {\n throw new VaultPathError('File path must not contain \".\" or \"..\" segments', filePath)\n }\n if (segment.startsWith('.')) {\n throw new VaultPathError('File path must not contain hidden segments', filePath)\n }\n if (!/^[A-Za-z0-9._-]+$/.test(segment)) {\n throw new VaultPathError('File path contains unsupported characters; use ASCII letters, digits, \".\", \"_\", and \"-\"', filePath)\n }\n }\n if (!isWorkspaceFileExportable(filePath)) throw new VaultPrivateRuntimeFileError(filePath)\n}\n\n/** Whether any segment of `filePath` is hidden (starts with a dot). */\nexport function isHiddenVaultFilePath(filePath: string): boolean {\n return filePath.split('/').some((segment) => segment.startsWith('.'))\n}\n\nfunction assertVaultKeyLength(\n key: string,\n input: { path?: string; keyKind: VaultStorageKeyKind },\n): string {\n const actualBytes = new TextEncoder().encode(key).byteLength\n if (actualBytes > VAULT_KV_KEY_MAX_BYTES) {\n throw new VaultStorageKeyError({ ...input, actualBytes })\n }\n return key\n}\n\nexport function vaultHeadKey(workspaceId: string, path: string): string {\n validateWorkspaceId(workspaceId)\n validateVaultFilePath(path)\n return assertVaultKeyLength(`vault:${workspaceId}:${path}`, { path, keyKind: 'head' })\n}\n\nexport function vaultHeadPrefix(workspaceId: string): string {\n validateWorkspaceId(workspaceId)\n return assertVaultKeyLength(`vault:${workspaceId}:`, { keyKind: 'prefix' })\n}\n\n/**\n * Head keys under a path prefix. The prefix may end inside a segment (`notes/me`)\n * or at a separator (`memories/workspace/`); empty means the whole Vault.\n */\nexport function vaultHeadPathPrefix(workspaceId: string, pathPrefix: string): string {\n const base = vaultHeadPrefix(workspaceId)\n if (!pathPrefix) return base\n if (pathPrefix.startsWith('/') || pathPrefix.includes('\\\\') || pathPrefix.includes('\\0')\n || pathPrefix.split('/').some((segment) => segment === '.' || segment === '..')) {\n throw new VaultPathError('Vault path prefix must be relative and normalized', pathPrefix)\n }\n return assertVaultKeyLength(`${base}${pathPrefix}`, { path: pathPrefix, keyKind: 'prefix' })\n}\n\n/** Erasure audit rows of one path sort by its write count, zero-padded to 12 digits. */\nexport function vaultErasureKey(workspaceId: string, path: string, sequence: number): string {\n validateWorkspaceId(workspaceId)\n validateVaultFilePath(path)\n if (!Number.isSafeInteger(sequence) || sequence < 1) {\n throw new VaultPathError('Vault erasure sequence must be a positive integer', path)\n }\n return assertVaultKeyLength(\n `vault-erasure:${workspaceId}:${path}:${String(sequence).padStart(12, '0')}`,\n { path, keyKind: 'erasure' },\n )\n}\n\n/** An unfinished erasure's job record, or one chunk of the revision ids it collected. */\nexport function vaultErasureJobKey(workspaceId: string, path: string, sequence: number, chunk?: number): string {\n const row = vaultErasureKey(workspaceId, path, sequence)\n const key = `vault-erasure-job:${row.slice('vault-erasure:'.length)}${chunk === undefined ? '' : `:${chunk}`}`\n return assertVaultKeyLength(key, { path, keyKind: 'erasure' })\n}\n\nexport function vaultErasurePrefix(workspaceId: string, pathPrefix = ''): string {\n validateWorkspaceId(workspaceId)\n return assertVaultKeyLength(`vault-erasure:${workspaceId}:${pathPrefix}`, { path: pathPrefix, keyKind: 'prefix' })\n}\n\nexport function vaultRevisionKey(workspaceId: string, revision: string, path?: string): string {\n validateWorkspaceId(workspaceId)\n if (!revision) throw new VaultPathError('Vault revision is required', path)\n return assertVaultKeyLength(`vault-revision:${workspaceId}:${revision}`, { path, keyKind: 'revision' })\n}\n\n/** Every revision record of a workspace, committed and conflicting alike. */\nexport function vaultRevisionPrefix(workspaceId: string): string {\n validateWorkspaceId(workspaceId)\n return assertVaultKeyLength(`vault-revision:${workspaceId}:`, { keyKind: 'prefix' })\n}\n\nexport function vaultOperationKey(workspaceId: string, operationId: string, path?: string): string {\n validateWorkspaceId(workspaceId)\n if (!operationId) throw new VaultPathError('Vault mutation operationId is required', path)\n return assertVaultKeyLength(`vault-operation:${workspaceId}:${operationId}`, { path, keyKind: 'operation' })\n}\n\nexport function vaultMetaKey(workspaceId: string, key: string): string {\n validateWorkspaceId(workspaceId)\n if (!key) throw new VaultPathError('Vault metadata key is required')\n return assertVaultKeyLength(`vault-meta:${workspaceId}:${key}`, { keyKind: 'metadata' })\n}\n\nexport function validateVaultMutationKeys(input: {\n workspaceId: string\n operationId: string\n changes: Array<{ path: string; revision?: string }>\n}): void {\n vaultOperationKey(input.workspaceId, input.operationId)\n for (const change of input.changes) {\n vaultHeadKey(input.workspaceId, change.path)\n if (change.revision) vaultRevisionKey(input.workspaceId, change.revision, change.path)\n }\n}\n"],"mappings":";;;;;AAOO,IAAM,yBAAyB;AAE/B,IAAM,iBAAN,cAA6B,MAAM;AAAA,EAC/B,OAAe;AAAA,EACf;AAAA,EAET,YAAY,SAAiB,MAAe;AAC1C,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;AAGO,IAAM,+BAAN,cAA2C,eAAe;AAAA,EAC7C,OAAO;AAAA,EAEzB,YAAY,MAAc;AACxB,UAAM,kEAAkE,IAAI;AAC5E,SAAK,OAAO;AAAA,EACd;AACF;AAGA,IAAM,0BAA6C,CAAC,QAAQ,YAAY,aAAa,YAAY,UAAU,SAAS;AAE7G,IAAM,uBAAN,cAAmC,eAAe;AAAA,EACrC,OAAO;AAAA,EAChB;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EAET,YAAY,OAIT;AACD,UAAM,UAAU,MAAM,OAAO,eAAe,MAAM,IAAI,MAAM,SAAS,MAAM,OAAO;AAClF,UAAM,GAAG,OAAO,gBAAgB,sBAAsB,2BAA2B,MAAM,IAAI;AAC3F,SAAK,OAAO;AACZ,SAAK,cAAc,MAAM;AACzB,SAAK,UAAU,MAAM;AAAA,EACvB;AACF;AAaO,SAAS,2BAA2B,OAAmD;AAC5F,SAAO;AAAA,IACL,OAAO;AAAA,MACL,MAAM,MAAM;AAAA,MACZ,SAAS,MAAM;AAAA,MACf,MAAM,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W,IAAI,QAAQ,IAAI,EAAE,MAAM,SAAS,WAAW,CAAC;AACxG;AAGO,SAAS,oBAAoB,aAA6B;AAC/D,sBAAoB,WAAW;AAC/B,SAAO,qBAAqB,kBAAkB,WAAW,KAAK,EAAE,SAAS,SAAS,CAAC;AACrF;AAEO,SAAS,kBAAkB,aAAqB,aAAqB,MAAuB;AACjG,sBAAoB,WAAW;AAC/B,MAAI,CAAC,YAAa,OAAM,IAAI,eAAe,0CAA0C,IAAI;AACzF,SAAO,qBAAqB,mBAAmB,WAAW,IAAI,WAAW,IAAI,EAAE,MAAM,SAAS,YAAY,CAAC;AAC7G;AAEO,SAAS,aAAa,aAAqB,KAAqB;AACrE,sBAAoB,WAAW;AAC/B,MAAI,CAAC,IAAK,OAAM,IAAI,eAAe,gCAAgC;AACnE,SAAO,qBAAqB,cAAc,WAAW,IAAI,GAAG,IAAI,EAAE,SAAS,WAAW,CAAC;AACzF;AAEO,SAAS,0BAA0B,OAIjC;AACP,oBAAkB,MAAM,aAAa,MAAM,WAAW;AACtD,aAAW,UAAU,MAAM,SAAS;AAClC,iBAAa,MAAM,aAAa,OAAO,IAAI;AAC3C,QAAI,OAAO,SAAU,kBAAiB,MAAM,aAAa,OAAO,UAAU,OAAO,IAAI;AAAA,EACvF;AACF;","names":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/vault/server.ts
|
|
2
|
+
var VAULT_DELETION_REFUSAL_RATIO = 0.75;
|
|
3
|
+
var VAULT_DELETION_REFUSAL_MIN_LIVE_FILES = 10;
|
|
4
|
+
function assessVaultDeletionBatch(input) {
|
|
5
|
+
const refusalRatio = input.policy?.refusalRatio ?? VAULT_DELETION_REFUSAL_RATIO;
|
|
6
|
+
const minLiveFiles = input.policy?.minLiveFiles ?? VAULT_DELETION_REFUSAL_MIN_LIVE_FILES;
|
|
7
|
+
if (!Number.isFinite(refusalRatio) || refusalRatio <= 0 || refusalRatio > 1) {
|
|
8
|
+
throw new RangeError(
|
|
9
|
+
`vault deletion policy refusalRatio must be a finite number in (0, 1], got ${refusalRatio}`
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
if (!Number.isFinite(minLiveFiles) || minLiveFiles < 0) {
|
|
13
|
+
throw new RangeError(
|
|
14
|
+
`vault deletion policy minLiveFiles must be a finite number >= 0, got ${minLiveFiles}`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
const manifestEmpty = input.manifestEmpty ?? false;
|
|
18
|
+
const baselineLive = input.baselinePaths.length;
|
|
19
|
+
const proposedSet = new Set(input.proposedDeletions);
|
|
20
|
+
const wouldDeletePaths = manifestEmpty ? [...input.baselinePaths].sort() : input.baselinePaths.filter((p) => proposedSet.has(p)).sort();
|
|
21
|
+
const wouldDelete = wouldDeletePaths.length;
|
|
22
|
+
const deletionRatio = baselineLive > 0 ? wouldDelete / baselineLive : 0;
|
|
23
|
+
const refusesEmptyManifest = manifestEmpty && baselineLive > 0;
|
|
24
|
+
const refusesAllFiles = wouldDelete > 0 && wouldDelete === baselineLive;
|
|
25
|
+
const refusesBlastRadius = wouldDelete > 0 && baselineLive >= minLiveFiles && deletionRatio >= refusalRatio;
|
|
26
|
+
const reason = refusesEmptyManifest ? "empty-manifest" : refusesAllFiles ? "all-files" : refusesBlastRadius ? "ratio-exceeded" : void 0;
|
|
27
|
+
return {
|
|
28
|
+
allowed: reason === void 0,
|
|
29
|
+
reason,
|
|
30
|
+
deletionRatio,
|
|
31
|
+
wouldDelete,
|
|
32
|
+
wouldDeletePaths,
|
|
33
|
+
baselineLive
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function compareIncarnationBaseline(baselineId, current) {
|
|
37
|
+
const currentId = current.filesystemIncarnationId;
|
|
38
|
+
const provenance = current.filesystemIncarnationProvenance;
|
|
39
|
+
const isValidProvenance = provenance === "fresh" || provenance === "restored" || provenance === "unknown";
|
|
40
|
+
if (typeof currentId !== "string" || currentId.length === 0 || !isValidProvenance) {
|
|
41
|
+
return { verdict: "unidentified" };
|
|
42
|
+
}
|
|
43
|
+
if (current.filesystemIncarnationReadiness !== "ready") {
|
|
44
|
+
return { verdict: "not-ready", readiness: current.filesystemIncarnationReadiness };
|
|
45
|
+
}
|
|
46
|
+
if (baselineId === void 0) {
|
|
47
|
+
return { verdict: "no-baseline" };
|
|
48
|
+
}
|
|
49
|
+
if (baselineId !== currentId) {
|
|
50
|
+
return { verdict: "mismatch", baselineId, currentId };
|
|
51
|
+
}
|
|
52
|
+
return { verdict: "match" };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
VAULT_DELETION_REFUSAL_RATIO,
|
|
57
|
+
VAULT_DELETION_REFUSAL_MIN_LIVE_FILES,
|
|
58
|
+
assessVaultDeletionBatch,
|
|
59
|
+
compareIncarnationBaseline
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=chunk-GS7VWV26.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vault/server.ts"],"sourcesContent":["/**\n * Server-only policy sibling of the React `./vault` client surface. Pure\n * decision logic — no I/O, no logging, ZERO imports — extracted from\n * gtm-agent's local guard (gtm#612) after it lost 48 production vault files:\n * a half-mounted sandbox scanned cleanly and reconciliation derived a\n * mass-deletion batch from an empty manifest. The #265/#332 audit ruled both\n * checks here universal shell mechanism, not gtm-specific, so they live here\n * once instead of being re-forked per product.\n *\n * Two independent checks:\n * - `assessVaultDeletionBatch` — blast-radius refusal. Given the live\n * baseline and what a reconciliation pass proposes to delete, decide\n * whether the batch is safe to apply or must be refused. Refusal is a\n * SUCCESSFUL outcome, not a thrown error: content changes still apply,\n * only the deletions are withheld. What to do with a refusal (log, alert,\n * retry the scan) stays the caller's job.\n * - `compareIncarnationBaseline` — filesystem-incarnation comparison. Given\n * a recorded baseline incarnation id and the sandbox's current identity\n * fields, decide whether the sandbox filesystem is the same one the\n * baseline was captured against, fail-closed on anything not clearly\n * identified and ready.\n *\n * Both are pure functions over caller-supplied data: no manifest reads, no\n * sandbox calls, no console output. The caller pre-filters tombstoned\n * entries (this module only ever sees the LIVE path set) and owns everything\n * that happens after a verdict comes back.\n */\n\n/** Refuse a deletion batch once it would remove at least this fraction of the\n * live baseline (both this and `VAULT_DELETION_REFUSAL_MIN_LIVE_FILES` must\n * hold — a tiny vault can lose all its files without tripping this ratio\n * gate; `refusesAllFiles` catches that case separately). */\nexport const VAULT_DELETION_REFUSAL_RATIO = 0.75\n\n/** The blast-radius ratio gate only engages once the live baseline is at\n * least this large, so a 2-file vault losing 1 file (50%) is not refused on\n * ratio alone. */\nexport const VAULT_DELETION_REFUSAL_MIN_LIVE_FILES = 10\n\n/** Overrides for `assessVaultDeletionBatch`'s two thresholds. Both default to\n * the exported constants above. Values are validated fail-loud:\n * `refusalRatio` must be finite and in (0, 1] — `NaN` (a config parse\n * failure) would make `deletionRatio >= refusalRatio` always false and silently\n * disable the guard, and `0` would refuse a zero-deletion batch; and\n * `minLiveFiles` must be finite and >= 0. Invalid values throw `RangeError`\n * instead of running with a guard that cannot fire (or cannot pass). */\nexport interface VaultDeletionPolicy {\n refusalRatio?: number\n minLiveFiles?: number\n}\n\nexport interface VaultDeletionAssessment {\n /** True when no refusal reason fired. */\n allowed: boolean\n /** Precedence when multiple reasons would fire: `empty-manifest` beats\n * `all-files` beats `ratio-exceeded` (most specific first — an empty scan\n * IS an all-files deletion, but the diagnostic that matters is \"the scan\n * came back empty\", not \"it deleted everything\"). Undefined when allowed. */\n reason?: 'empty-manifest' | 'all-files' | 'ratio-exceeded'\n /** wouldDelete / baselineLive, or 0 when the baseline is itself empty. */\n deletionRatio: number\n wouldDelete: number\n /** The paths that would be deleted, sorted — mirrors gtm's `.sort()` so log\n * output and any snapshot fixture are byte-stable. */\n wouldDeletePaths: string[]\n baselineLive: number\n}\n\n/**\n * Decide whether a reconciliation pass's proposed deletions are safe to\n * apply against the live baseline.\n *\n * `manifestEmpty: true` means the filesystem scan that produced\n * `proposedDeletions` came back with nothing — the caller could not have\n * derived a meaningful proposed-deletions list, so this treats the FULL live\n * baseline as would-delete regardless of what `proposedDeletions` contains.\n * That is what distinguishes `'empty-manifest'` from `'all-files'`: an empty\n * scan structurally implies every baseline path would be deleted, but the\n * diagnostic that matters to a caller is \"the scan was empty\", not merely\n * \"everything would go\".\n */\nexport function assessVaultDeletionBatch(input: {\n /** LIVE (non-tombstoned) baseline path set — the caller pre-filters, as gtm does. */\n baselinePaths: readonly string[]\n /** Paths a reconciliation pass proposes to delete; intersected with `baselinePaths` internally. */\n proposedDeletions: readonly string[]\n manifestEmpty?: boolean\n policy?: VaultDeletionPolicy\n}): VaultDeletionAssessment {\n const refusalRatio = input.policy?.refusalRatio ?? VAULT_DELETION_REFUSAL_RATIO\n const minLiveFiles = input.policy?.minLiveFiles ?? VAULT_DELETION_REFUSAL_MIN_LIVE_FILES\n if (!Number.isFinite(refusalRatio) || refusalRatio <= 0 || refusalRatio > 1) {\n throw new RangeError(\n `vault deletion policy refusalRatio must be a finite number in (0, 1], got ${refusalRatio}`,\n )\n }\n if (!Number.isFinite(minLiveFiles) || minLiveFiles < 0) {\n throw new RangeError(\n `vault deletion policy minLiveFiles must be a finite number >= 0, got ${minLiveFiles}`,\n )\n }\n const manifestEmpty = input.manifestEmpty ?? false\n\n const baselineLive = input.baselinePaths.length\n const proposedSet = new Set(input.proposedDeletions)\n const wouldDeletePaths = manifestEmpty\n ? [...input.baselinePaths].sort()\n : input.baselinePaths.filter((p) => proposedSet.has(p)).sort()\n const wouldDelete = wouldDeletePaths.length\n const deletionRatio = baselineLive > 0 ? wouldDelete / baselineLive : 0\n\n const refusesEmptyManifest = manifestEmpty && baselineLive > 0\n const refusesAllFiles = wouldDelete > 0 && wouldDelete === baselineLive\n // `wouldDelete > 0` is unreachable-false under the validated policy domain\n // (a positive refusalRatio can never be met by a 0 ratio) — it is here so\n // the ratio branch stays safe on its own terms, independent of the\n // validation above ever being relaxed.\n const refusesBlastRadius = wouldDelete > 0\n && baselineLive >= minLiveFiles\n && deletionRatio >= refusalRatio\n\n const reason = refusesEmptyManifest\n ? ('empty-manifest' as const)\n : refusesAllFiles\n ? ('all-files' as const)\n : refusesBlastRadius\n ? ('ratio-exceeded' as const)\n : undefined\n\n return {\n allowed: reason === undefined,\n reason,\n deletionRatio,\n wouldDelete,\n wouldDeletePaths,\n baselineLive,\n }\n}\n\n/** The subset of a sandbox's filesystem-incarnation identity this module\n * needs. A product's real incarnation type is structurally compatible —\n * no import required. */\nexport interface FilesystemIncarnationLike {\n filesystemIncarnationId?: string\n filesystemIncarnationProvenance?: 'fresh' | 'restored' | 'unknown'\n filesystemIncarnationReadiness?: 'transitioning' | 'ready'\n}\n\n/**\n * Result of comparing a recorded baseline incarnation id against the\n * sandbox's current identity. A discriminated union over `verdict` so a\n * caller's `switch` gets compile-time coverage instead of a stringly-typed\n * status it can forget to branch on.\n */\nexport type IncarnationComparison =\n | { verdict: 'match' }\n | { verdict: 'mismatch'; baselineId: string; currentId: string }\n | { verdict: 'not-ready'; readiness: string | undefined }\n | { verdict: 'unidentified' }\n | { verdict: 'no-baseline' }\n\n/**\n * Compare a recorded baseline filesystem-incarnation id against a sandbox's\n * current incarnation fields. Check order mirrors gtm's gate sequence and is\n * itself a tested fail-closed property — each earlier check short-circuits\n * the ones after it, so a box with BOTH bad readiness and a mismatched id\n * resolves `'not-ready'`, never `'mismatch'`:\n *\n * 1. `unidentified` — the current id is missing/empty, or the provenance is\n * not one of `fresh`/`restored`/`unknown`.\n * 2. `not-ready` — readiness is anything other than the literal string\n * `'ready'` (this also catches `undefined`).\n * 3. `no-baseline` — no baseline id was ever recorded to compare against.\n * 4. `mismatch` — the baseline id and current id disagree.\n * 5. `match` — same incarnation.\n */\nexport function compareIncarnationBaseline(\n baselineId: string | undefined,\n current: FilesystemIncarnationLike,\n): IncarnationComparison {\n const currentId = current.filesystemIncarnationId\n const provenance = current.filesystemIncarnationProvenance\n const isValidProvenance = provenance === 'fresh' || provenance === 'restored' || provenance === 'unknown'\n\n if (typeof currentId !== 'string' || currentId.length === 0 || !isValidProvenance) {\n return { verdict: 'unidentified' }\n }\n\n if (current.filesystemIncarnationReadiness !== 'ready') {\n return { verdict: 'not-ready', readiness: current.filesystemIncarnationReadiness }\n }\n\n if (baselineId === undefined) {\n return { verdict: 'no-baseline' }\n }\n\n if (baselineId !== currentId) {\n return { verdict: 'mismatch', baselineId, currentId }\n }\n\n return { verdict: 'match' }\n}\n"],"mappings":";AAgCO,IAAM,+BAA+B;AAKrC,IAAM,wCAAwC;AA4C9C,SAAS,yBAAyB,OAOb;AAC1B,QAAM,eAAe,MAAM,QAAQ,gBAAgB;AACnD,QAAM,eAAe,MAAM,QAAQ,gBAAgB;AACnD,MAAI,CAAC,OAAO,SAAS,YAAY,KAAK,gBAAgB,KAAK,eAAe,GAAG;AAC3E,UAAM,IAAI;AAAA,MACR,6EAA6E,YAAY;AAAA,IAC3F;AAAA,EACF;AACA,MAAI,CAAC,OAAO,SAAS,YAAY,KAAK,eAAe,GAAG;AACtD,UAAM,IAAI;AAAA,MACR,wEAAwE,YAAY;AAAA,IACtF;AAAA,EACF;AACA,QAAM,gBAAgB,MAAM,iBAAiB;AAE7C,QAAM,eAAe,MAAM,cAAc;AACzC,QAAM,cAAc,IAAI,IAAI,MAAM,iBAAiB;AACnD,QAAM,mBAAmB,gBACrB,CAAC,GAAG,MAAM,aAAa,EAAE,KAAK,IAC9B,MAAM,cAAc,OAAO,CAAC,MAAM,YAAY,IAAI,CAAC,CAAC,EAAE,KAAK;AAC/D,QAAM,cAAc,iBAAiB;AACrC,QAAM,gBAAgB,eAAe,IAAI,cAAc,eAAe;AAEtE,QAAM,uBAAuB,iBAAiB,eAAe;AAC7D,QAAM,kBAAkB,cAAc,KAAK,gBAAgB;AAK3D,QAAM,qBAAqB,cAAc,KACpC,gBAAgB,gBAChB,iBAAiB;AAEtB,QAAM,SAAS,uBACV,mBACD,kBACG,cACD,qBACG,mBACD;AAER,SAAO;AAAA,IACL,SAAS,WAAW;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAuCO,SAAS,2BACd,YACA,SACuB;AACvB,QAAM,YAAY,QAAQ;AAC1B,QAAM,aAAa,QAAQ;AAC3B,QAAM,oBAAoB,eAAe,WAAW,eAAe,cAAc,eAAe;AAEhG,MAAI,OAAO,cAAc,YAAY,UAAU,WAAW,KAAK,CAAC,mBAAmB;AACjF,WAAO,EAAE,SAAS,eAAe;AAAA,EACnC;AAEA,MAAI,QAAQ,mCAAmC,SAAS;AACtD,WAAO,EAAE,SAAS,aAAa,WAAW,QAAQ,+BAA+B;AAAA,EACnF;AAEA,MAAI,eAAe,QAAW;AAC5B,WAAO,EAAE,SAAS,cAAc;AAAA,EAClC;AAEA,MAAI,eAAe,WAAW;AAC5B,WAAO,EAAE,SAAS,YAAY,YAAY,UAAU;AAAA,EACtD;AAEA,SAAO,EAAE,SAAS,QAAQ;AAC5B;","names":[]}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
clearCookieHeader,
|
|
6
6
|
readCookieValue,
|
|
7
7
|
serializeCookie
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-WP2GYFZ4.js";
|
|
9
9
|
|
|
10
10
|
// src/platform/sso.ts
|
|
11
11
|
var DEFAULT_STATE_TTL_SECONDS = 600;
|
|
@@ -502,4 +502,4 @@ export {
|
|
|
502
502
|
createAdminGuard,
|
|
503
503
|
assertBillableBalance
|
|
504
504
|
};
|
|
505
|
-
//# sourceMappingURL=chunk-
|
|
505
|
+
//# sourceMappingURL=chunk-H5GQMLHA.js.map
|
|
@@ -10,16 +10,16 @@ import {
|
|
|
10
10
|
PopoverSurface,
|
|
11
11
|
effortLevelsFromIds
|
|
12
12
|
} from "./chunk-R4X5474U.js";
|
|
13
|
-
import {
|
|
14
|
-
isModelCompatibleWithHarness,
|
|
15
|
-
snapModelToHarness
|
|
16
|
-
} from "./chunk-FPNZMIAW.js";
|
|
17
13
|
import {
|
|
18
14
|
isCommitSha,
|
|
19
15
|
parseGitHubLocation,
|
|
20
16
|
publicHttpsUrlProblem,
|
|
21
17
|
readSkillFrontmatter
|
|
22
18
|
} from "./chunk-B7CL7ENS.js";
|
|
19
|
+
import {
|
|
20
|
+
isModelCompatibleWithHarness,
|
|
21
|
+
snapModelToHarness
|
|
22
|
+
} from "./chunk-FPNZMIAW.js";
|
|
23
23
|
|
|
24
24
|
// src/web-react/agent-profile-editor.tsx
|
|
25
25
|
import { useEffect as useEffect4, useId as useId5, useMemo as useMemo3, useState as useState7 } from "react";
|
|
@@ -2212,4 +2212,4 @@ export {
|
|
|
2212
2212
|
AGENT_PROFILE_EDITOR_SECTIONS,
|
|
2213
2213
|
AgentProfileEditor
|
|
2214
2214
|
};
|
|
2215
|
-
//# sourceMappingURL=chunk-
|
|
2215
|
+
//# sourceMappingURL=chunk-HN6MZ2XL.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/crypto/digest.ts
|
|
2
|
+
async function sha256Hex(value) {
|
|
3
|
+
const bytes = typeof value === "string" ? new TextEncoder().encode(value) : value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength);
|
|
4
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
5
|
+
return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
sha256Hex
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=chunk-HY57QRRW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/crypto/digest.ts"],"sourcesContent":["/** Lowercase-hex SHA-256 of a UTF-8 string or a byte range. WebCrypto only. */\nexport async function sha256Hex(value: string | Uint8Array): Promise<string> {\n const bytes = typeof value === 'string'\n ? new TextEncoder().encode(value)\n : value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength) as ArrayBuffer\n const digest = await crypto.subtle.digest('SHA-256', bytes)\n return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('')\n}\n"],"mappings":";AACA,eAAsB,UAAU,OAA6C;AAC3E,QAAM,QAAQ,OAAO,UAAU,WAC3B,IAAI,YAAY,EAAE,OAAO,KAAK,IAC9B,MAAM,OAAO,MAAM,MAAM,YAAY,MAAM,aAAa,MAAM,UAAU;AAC5E,QAAM,SAAS,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK;AAC1D,SAAO,MAAM,KAAK,IAAI,WAAW,MAAM,GAAG,CAAC,SAAS,KAAK,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AACjG;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
parseJsonObjectBody
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WP2GYFZ4.js";
|
|
4
4
|
import {
|
|
5
5
|
interactionFromWireRequest,
|
|
6
6
|
isSafeInteractionFieldKey,
|
|
@@ -378,4 +378,4 @@ export {
|
|
|
378
378
|
mapInteractionRespondFailure,
|
|
379
379
|
createInteractionAnswerRoute
|
|
380
380
|
};
|
|
381
|
-
//# sourceMappingURL=chunk-
|
|
381
|
+
//# sourceMappingURL=chunk-KH4QSBNI.js.map
|
|
@@ -4,10 +4,7 @@ import {
|
|
|
4
4
|
DesignCanvas,
|
|
5
5
|
PlusGlyph,
|
|
6
6
|
ShapesGlyph
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import {
|
|
9
|
-
lightTheme
|
|
10
|
-
} from "./chunk-UTF7H6BK.js";
|
|
7
|
+
} from "./chunk-NHYRIM4I.js";
|
|
11
8
|
import {
|
|
12
9
|
DEFAULT_INSERT_TEMPLATES,
|
|
13
10
|
collectGridTargets,
|
|
@@ -20,7 +17,7 @@ import {
|
|
|
20
17
|
marqueeSelect,
|
|
21
18
|
resolveExportParams,
|
|
22
19
|
resolveNodeCachePixelRatio
|
|
23
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-4ZSLX3LY.js";
|
|
24
21
|
import {
|
|
25
22
|
addElementCommand,
|
|
26
23
|
createSceneCommandStack,
|
|
@@ -29,13 +26,16 @@ import {
|
|
|
29
26
|
multiSetAttrsCommand,
|
|
30
27
|
setAttrsCommand,
|
|
31
28
|
ungroupElementCommand
|
|
32
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-BTKI4XMM.js";
|
|
33
30
|
import {
|
|
34
31
|
SCENE_SCHEMA_VERSION,
|
|
35
32
|
boundsIntersect,
|
|
36
33
|
elementAabb,
|
|
37
34
|
findElement
|
|
38
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-ZWJ3SZ2G.js";
|
|
36
|
+
import {
|
|
37
|
+
lightTheme
|
|
38
|
+
} from "./chunk-UTF7H6BK.js";
|
|
39
39
|
|
|
40
40
|
// src/design-canvas-react/components/Workspace.tsx
|
|
41
41
|
import {
|
|
@@ -1951,4 +1951,4 @@ export {
|
|
|
1951
1951
|
Workspace,
|
|
1952
1952
|
DesignCanvasEditor
|
|
1953
1953
|
};
|
|
1954
|
-
//# sourceMappingURL=chunk-
|
|
1954
|
+
//# sourceMappingURL=chunk-KJODHPWM.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// src/spend/budget.ts
|
|
2
|
+
var DEFAULT_WORKSPACE_SPEND_BUDGET_NANO_USD = 27373261200;
|
|
3
|
+
var ComputeBudgetExceededError = class extends Error {
|
|
4
|
+
workspaceId;
|
|
5
|
+
limitNanoUsd;
|
|
6
|
+
settledNanoUsd;
|
|
7
|
+
overageNanoUsd;
|
|
8
|
+
constructor(refusal) {
|
|
9
|
+
super(
|
|
10
|
+
`Compute budget exceeded for workspace ${refusal.workspaceId}: $${(refusal.settledNanoUsd / 1e9).toFixed(2)} settled against a cap of $${(refusal.limitNanoUsd / 1e9).toFixed(2)} (over by $${(refusal.overageNanoUsd / 1e9).toFixed(2)}). No sandbox was provisioned. Raise the cap or reconcile the spend before retrying.`
|
|
11
|
+
);
|
|
12
|
+
this.name = "ComputeBudgetExceededError";
|
|
13
|
+
this.workspaceId = refusal.workspaceId;
|
|
14
|
+
this.limitNanoUsd = refusal.limitNanoUsd;
|
|
15
|
+
this.settledNanoUsd = refusal.settledNanoUsd;
|
|
16
|
+
this.overageNanoUsd = refusal.overageNanoUsd;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
async function assertComputeBudget(budget, workspaceId) {
|
|
20
|
+
if (!budget) return;
|
|
21
|
+
const settledNanoUsd = await budget.settledNanoUsd(workspaceId);
|
|
22
|
+
if (settledNanoUsd < budget.limitNanoUsd) return;
|
|
23
|
+
const refusal = {
|
|
24
|
+
workspaceId,
|
|
25
|
+
limitNanoUsd: budget.limitNanoUsd,
|
|
26
|
+
settledNanoUsd,
|
|
27
|
+
overageNanoUsd: settledNanoUsd - budget.limitNanoUsd,
|
|
28
|
+
at: (budget.now ?? Date.now)()
|
|
29
|
+
};
|
|
30
|
+
budget.onRefusal?.(refusal);
|
|
31
|
+
throw new ComputeBudgetExceededError(refusal);
|
|
32
|
+
}
|
|
33
|
+
function createSandboxSpendHooks(options) {
|
|
34
|
+
const { ledger, budget, onError } = options;
|
|
35
|
+
return {
|
|
36
|
+
async beforeProvision(input) {
|
|
37
|
+
await assertComputeBudget(budget, input.workspaceId);
|
|
38
|
+
},
|
|
39
|
+
async onProvisioned(observation) {
|
|
40
|
+
if (!ledger) return;
|
|
41
|
+
try {
|
|
42
|
+
await ledger.observeSandbox({
|
|
43
|
+
sandboxId: observation.sandboxId,
|
|
44
|
+
workspaceId: observation.workspaceId,
|
|
45
|
+
idleTimeoutSeconds: observation.idleTimeoutSeconds,
|
|
46
|
+
maxLifetimeSeconds: observation.maxLifetimeSeconds ?? null,
|
|
47
|
+
at: observation.at
|
|
48
|
+
});
|
|
49
|
+
} catch (err) {
|
|
50
|
+
onError?.(err);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
onActivity(input) {
|
|
54
|
+
if (!ledger) return;
|
|
55
|
+
void ledger.recordActivity(input.sandboxId, input.at).catch((err) => onError?.(err));
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
DEFAULT_WORKSPACE_SPEND_BUDGET_NANO_USD,
|
|
62
|
+
ComputeBudgetExceededError,
|
|
63
|
+
assertComputeBudget,
|
|
64
|
+
createSandboxSpendHooks
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=chunk-LSBI5MWS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/spend/budget.ts"],"sourcesContent":["import type { SpendLedger } from './store'\n\n/**\n * Default compute-spend ceiling for a workspace that enables the guard without\n * naming its own limit: ten times the cost of running one 2 vCPU / 4 GB box for\n * a 24-hour max lifetime, at the incident's calibrated price\n * ($0.114055255/hour — reverse-derived in `fixtures/incident-parked-time.ts`\n * so its 23 incident rows sum to the refunded $514.161090533 exactly).\n *\n * 10 x 24h x $0.114055255/h = $27.3732612 -> 27_373_261_200 nanodollars\n *\n * Deliberately generous: there is no spend history to ground a tighter number,\n * and a guard that refuses ordinary usage is itself an incident.\n */\nexport const DEFAULT_WORKSPACE_SPEND_BUDGET_NANO_USD = 27_373_261_200\n\n/** Why provisioning was refused, with every number the decision used. */\nexport interface ComputeBudgetRefusal {\n readonly workspaceId: string\n /** The cap, unsigned nanodollars. */\n readonly limitNanoUsd: number\n /** Cumulative settled compute spend for this workspace, unsigned nanodollars. */\n readonly settledNanoUsd: number\n /** How far past the cap it already is. */\n readonly overageNanoUsd: number\n readonly at: number\n}\n\n/**\n * Provisioning refused because the workspace is already past its compute cap.\n *\n * Correctable by design: every number the decision used is on the error, so a\n * product can render \"this workspace has spent $X of its $Y compute budget\" and\n * an operator can raise the cap or investigate without reading logs.\n *\n * This is the failure mode the module exists to produce. A platform billing\n * defect that used to end in a silent negative balance now ends in provisioning\n * stopping and something loud happening instead.\n */\nexport class ComputeBudgetExceededError extends Error {\n readonly workspaceId: string\n readonly limitNanoUsd: number\n readonly settledNanoUsd: number\n readonly overageNanoUsd: number\n\n constructor(refusal: ComputeBudgetRefusal) {\n super(\n `Compute budget exceeded for workspace ${refusal.workspaceId}: ` +\n `$${(refusal.settledNanoUsd / 1_000_000_000).toFixed(2)} settled against a cap of ` +\n `$${(refusal.limitNanoUsd / 1_000_000_000).toFixed(2)} ` +\n `(over by $${(refusal.overageNanoUsd / 1_000_000_000).toFixed(2)}). ` +\n 'No sandbox was provisioned. Raise the cap or reconcile the spend before retrying.',\n )\n this.name = 'ComputeBudgetExceededError'\n this.workspaceId = refusal.workspaceId\n this.limitNanoUsd = refusal.limitNanoUsd\n this.settledNanoUsd = refusal.settledNanoUsd\n this.overageNanoUsd = refusal.overageNanoUsd\n }\n}\n\n/**\n * A per-workspace cap on sandbox compute.\n *\n * `/billing`'s budget primitive caps MODEL keys, and it works because the\n * platform enforces the cap at the key it minted. Sandbox compute has no such\n * key: a box bills the shared company wallet, so nothing upstream refuses. This\n * carries the same shape to the one place a consumer can still act — the moment\n * before it asks for another box.\n *\n * `settledNanoUsd` is a callback rather than a number because the authority is\n * the platform ledger, not this package: the product reads the same rows it\n * hands the reconciler. Cache it if the read is expensive; a cap is a\n * coarse-grained control and a slightly stale total still refuses.\n */\nexport interface ComputeBudget {\n /** The cap, unsigned nanodollars. */\n readonly limitNanoUsd: number\n /** Cumulative settled compute spend for the workspace, unsigned nanodollars. */\n readonly settledNanoUsd: (workspaceId: string) => Promise<number> | number\n /**\n * Called on every refusal, before the error is thrown. This is the alert\n * seam: a refusal nobody hears is a product that silently stopped working.\n */\n readonly onRefusal?: (refusal: ComputeBudgetRefusal) => void\n /** Injectable clock (epoch ms). Default `Date.now`. */\n readonly now?: () => number\n}\n\n/**\n * Throw {@link ComputeBudgetExceededError} when the workspace is already past\n * its cap. Returns normally — and reads nothing — when no budget is configured.\n *\n * Deliberately a pre-check against spend ALREADY SETTLED, not a reservation\n * against spend about to happen: settlement lags provisioning by design (the\n * platform's durable settlement queue), so there is no instant at which a\n * consumer could hold an accurate running total. The cap therefore overshoots by\n * at most the unsettled tail, which is bounded by the box's own idle timeout.\n * A cap that refuses one box late is worth far more than one that cannot be\n * implemented honestly.\n */\nexport async function assertComputeBudget(\n budget: ComputeBudget | undefined,\n workspaceId: string,\n): Promise<void> {\n if (!budget) return\n const settledNanoUsd = await budget.settledNanoUsd(workspaceId)\n if (settledNanoUsd < budget.limitNanoUsd) return\n\n const refusal: ComputeBudgetRefusal = {\n workspaceId,\n limitNanoUsd: budget.limitNanoUsd,\n settledNanoUsd,\n overageNanoUsd: settledNanoUsd - budget.limitNanoUsd,\n at: (budget.now ?? Date.now)(),\n }\n budget.onRefusal?.(refusal)\n throw new ComputeBudgetExceededError(refusal)\n}\n\n// ── the /sandbox seam ─────────────────────────────────────────────────────────\n\n/**\n * What `/sandbox` reports once a box is provisioned, reused or resumed.\n *\n * Structurally identical to `SandboxProvisionedObservation` in `/sandbox`, and\n * deliberately re-declared rather than imported: `/spend` composes `/sandbox`,\n * so a type import in the other direction would invert the dependency. The two\n * are pinned together by a compile-time assignment in this module's tests.\n */\nexport interface SpendProvisionObservation {\n readonly workspaceId: string\n readonly userId?: string\n readonly sandboxId: string\n readonly boxKey?: string | undefined\n readonly idleTimeoutSeconds: number\n readonly maxLifetimeSeconds?: number | undefined\n readonly at: number\n}\n\n/**\n * The optional seam `EnsureWorkspaceSandboxOptions.spend` and the turn\n * primitives' `spend` option both accept. One object, wired in both places.\n */\nexport interface SandboxSpendSeam {\n beforeProvision?(input: { workspaceId: string; userId?: string }): Promise<void> | void\n onProvisioned?(observation: SpendProvisionObservation): Promise<void> | void\n /** Synchronous by contract — it sits on the turn path. See `createSandboxSpendHooks`. */\n onActivity?(input: { sandboxId: string; at: number }): void\n}\n\nexport interface SandboxSpendHooksOptions {\n /** Records box lifecycle. Omit to run the budget guard alone. */\n readonly ledger?: SpendLedger\n /** Refuses provisioning past a cap. Omit to record alone. */\n readonly budget?: ComputeBudget\n /**\n * Called when RECORDING fails. Recording is best-effort — a bookkeeping\n * failure must never take down the provisioning it is bookkeeping — so this\n * is the only place such a failure is visible. A refusal is NOT routed here;\n * refusals throw, by design.\n */\n readonly onError?: (error: unknown) => void\n}\n\n/**\n * Build the object to hand `ensureWorkspaceSandbox`'s `spend` option.\n *\n * Wiring it is the entire adoption cost: one field, and the product's boxes are\n * both budget-capped and recorded.\n */\nexport function createSandboxSpendHooks(options: SandboxSpendHooksOptions): SandboxSpendSeam {\n const { ledger, budget, onError } = options\n return {\n async beforeProvision(input) {\n await assertComputeBudget(budget, input.workspaceId)\n },\n async onProvisioned(observation) {\n if (!ledger) return\n try {\n await ledger.observeSandbox({\n sandboxId: observation.sandboxId,\n workspaceId: observation.workspaceId,\n idleTimeoutSeconds: observation.idleTimeoutSeconds,\n maxLifetimeSeconds: observation.maxLifetimeSeconds ?? null,\n at: observation.at,\n })\n } catch (err) {\n onError?.(err)\n }\n },\n onActivity(input) {\n if (!ledger) return\n // The turn path calls this synchronously and does not await it, so the\n // promise is settled here rather than escaping as an unhandled rejection.\n // Recording activity is a monotonic max, so a write that lands late — or\n // out of order against another turn's — still converges.\n void ledger.recordActivity(input.sandboxId, input.at).catch((err: unknown) => onError?.(err))\n },\n }\n}\n"],"mappings":";AAcO,IAAM,0CAA0C;AAyBhD,IAAM,6BAAN,cAAyC,MAAM;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,SAA+B;AACzC;AAAA,MACE,yCAAyC,QAAQ,WAAW,OACrD,QAAQ,iBAAiB,KAAe,QAAQ,CAAC,CAAC,+BAClD,QAAQ,eAAe,KAAe,QAAQ,CAAC,CAAC,eACvC,QAAQ,iBAAiB,KAAe,QAAQ,CAAC,CAAC;AAAA,IAEpE;AACA,SAAK,OAAO;AACZ,SAAK,cAAc,QAAQ;AAC3B,SAAK,eAAe,QAAQ;AAC5B,SAAK,iBAAiB,QAAQ;AA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chunk-TXUAGSFR.js";
|
|
8
|
+
|
|
9
|
+
// src/skills-placement/index.ts
|
|
10
|
+
import {
|
|
11
|
+
defineInlineResource
|
|
12
|
+
} from "@tangle-network/agent-interface";
|
|
13
|
+
import { skillDirForHarness } from "@tangle-network/agent-profile-materialize";
|
|
14
|
+
var HARNESS_BRIDGE = {
|
|
15
|
+
opencode: "opencode",
|
|
16
|
+
"claude-code": "claude-code",
|
|
17
|
+
nanoclaw: "nanoclaw",
|
|
18
|
+
"kimi-code": "kimi-code",
|
|
19
|
+
codex: "codex",
|
|
20
|
+
pi: "pi",
|
|
21
|
+
prime: "prime",
|
|
22
|
+
hermes: "hermes",
|
|
23
|
+
openclaw: "openclaw"
|
|
24
|
+
};
|
|
25
|
+
function resolveSkillDir(harness) {
|
|
26
|
+
const bridged = HARNESS_BRIDGE[harness];
|
|
27
|
+
if (!bridged) return null;
|
|
28
|
+
return skillDirForHarness(bridged);
|
|
29
|
+
}
|
|
30
|
+
function unsupportedSkillHarnesses(harnesses) {
|
|
31
|
+
const seen = /* @__PURE__ */ new Set();
|
|
32
|
+
const out = [];
|
|
33
|
+
for (const harness of harnesses) {
|
|
34
|
+
if (resolveSkillDir(harness) !== null) continue;
|
|
35
|
+
if (seen.has(harness)) continue;
|
|
36
|
+
seen.add(harness);
|
|
37
|
+
out.push(harness);
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
function nativeSkillMountHarnesses() {
|
|
42
|
+
return KNOWN_HARNESSES.filter((harness) => resolveSkillDir(harness) !== null);
|
|
43
|
+
}
|
|
44
|
+
function composeSkillsForHarness(input) {
|
|
45
|
+
const { skills, harness, tier, heading, onNoSkillDir = "throw" } = input;
|
|
46
|
+
const skillDir = resolveSkillDir(harness);
|
|
47
|
+
if (skillDir) return composeSkills({ skills, mode: "mounted", skillDir, tier, heading });
|
|
48
|
+
if (onNoSkillDir === "inline") return composeSkills({ skills, mode: "inline", tier, heading });
|
|
49
|
+
const relevant = tier ? skills.filter((s) => s.tier === tier) : skills;
|
|
50
|
+
const promptSection = renderInlineSkills({ skills, tier, heading });
|
|
51
|
+
const bytes = new TextEncoder().encode(promptSection).byteLength;
|
|
52
|
+
const mountable = nativeSkillMountHarnesses();
|
|
53
|
+
throw new Error(
|
|
54
|
+
`composeSkillsForHarness: "${harness}" has no native skill-mount directory. Inlining ${relevant.length} skill(s) (${bytes} bytes) into its system prompt would silently convert mounted skills into prompt text \u2014 a 151,882-byte prompt shipped this way once, and oversized prompts degrade toward empty answers. Mount the skills instead: pick a harness with native skill support (${mountable.join(", ")}), or pass onNoSkillDir: 'inline' to opt in explicitly and accept the inlined bytes.`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
function skillSupportFileMounts(harness, skillId, files, options = {}) {
|
|
58
|
+
const skillDir = resolveSkillDir(harness);
|
|
59
|
+
if (!skillDir || files.length === 0) return [];
|
|
60
|
+
return files.map((file) => ({
|
|
61
|
+
path: `${skillDir}/${skillId}/${file.path}`,
|
|
62
|
+
resource: defineInlineResource(
|
|
63
|
+
options.resourceName ? options.resourceName(file) : `${skillId}/${file.path}`,
|
|
64
|
+
file.content
|
|
65
|
+
)
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
function withSkillSupportFiles(profile, harness, skillId, files, options = {}) {
|
|
69
|
+
const hasSkillDir = resolveSkillDir(harness) !== null;
|
|
70
|
+
const desired = skillSupportFileMounts(harness, skillId, files, options);
|
|
71
|
+
const desiredByPath = new Map(
|
|
72
|
+
desired.map((mount) => [mount.path, mount.resource])
|
|
73
|
+
);
|
|
74
|
+
const byRelPath = new Map(files.map((file) => [file.path, file.content]));
|
|
75
|
+
const suffix = `/${skillId}/`;
|
|
76
|
+
const relUnderSkill = (path) => {
|
|
77
|
+
const at = path.lastIndexOf(suffix);
|
|
78
|
+
return at < 0 ? null : path.slice(at + suffix.length);
|
|
79
|
+
};
|
|
80
|
+
const shouldDropMount = (mount) => {
|
|
81
|
+
if (mount.resource.kind !== "inline") return false;
|
|
82
|
+
const rel = relUnderSkill(mount.path);
|
|
83
|
+
if (rel === null || byRelPath.get(rel) !== mount.resource.content) return false;
|
|
84
|
+
if (options.reconcileExisting === "replace") return true;
|
|
85
|
+
const desiredHere = desiredByPath.get(mount.path);
|
|
86
|
+
return !hasSkillDir || desiredHere === void 0 || desiredHere.kind !== "inline" || desiredHere.content !== mount.resource.content;
|
|
87
|
+
};
|
|
88
|
+
const existing = profile.resources?.files ?? [];
|
|
89
|
+
const retained = existing.filter((mount) => !shouldDropMount(mount));
|
|
90
|
+
const taken = new Set(retained.map((mount) => mount.path));
|
|
91
|
+
const additions = desired.filter((mount) => !taken.has(mount.path));
|
|
92
|
+
if (additions.length === 0 && (retained.length === existing.length || hasSkillDir && options.reconcileExisting === "replace")) return profile;
|
|
93
|
+
return {
|
|
94
|
+
...profile,
|
|
95
|
+
resources: { ...profile.resources ?? {}, files: [...retained, ...additions] }
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
resolveSkillDir,
|
|
101
|
+
unsupportedSkillHarnesses,
|
|
102
|
+
composeSkillsForHarness,
|
|
103
|
+
skillSupportFileMounts,
|
|
104
|
+
withSkillSupportFiles
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=chunk-MDRH3SDA.js.map
|