pi-web-ui 0.115.0 → 0.117.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/CHANGELOG.md +65 -2
- package/bin/device-hub-cli.mjs +26 -3
- package/bin/pi-web-ui.mjs +159 -71
- package/dist/server/agent-service-daemon.js +136 -8
- package/dist/server/agent-service.js +594 -159
- package/dist/server/canvas/canvas-workspace.js +18 -86
- package/dist/server/client-state.js +52 -8
- package/dist/server/compaction-markers.js +43 -24
- package/dist/server/dangling-tools.js +172 -16
- package/dist/server/device-center/bot-execution.js +77 -2
- package/dist/server/device-center/collab-service.js +61 -12
- package/dist/server/device-center/collab-tool.js +482 -21
- package/dist/server/device-center/connector.js +107 -37
- package/dist/server/device-center/delivery-authority.js +98 -0
- package/dist/server/device-center/delivery-subject.js +30 -0
- package/dist/server/device-center/device-integration.js +453 -183
- package/dist/server/device-center/execution-guides.js +17 -7
- package/dist/server/device-center/execution-instructions.js +2 -1
- package/dist/server/device-center/execution-settings.js +138 -25
- package/dist/server/device-center/executor.js +51 -6
- package/dist/server/device-center/file-sync.js +14 -13
- package/dist/server/device-center/group-context-message.js +3 -1
- package/dist/server/device-center/group-context.js +73 -3
- package/dist/server/device-center/hub-conversations.js +71 -6
- package/dist/server/device-center/hub-deliveries.js +120 -15
- package/dist/server/device-center/hub-integration.js +655 -334
- package/dist/server/device-center/hub-locks.js +320 -0
- package/dist/server/device-center/hub-page.js +16 -35
- package/dist/server/device-center/hub-setup.js +23 -1
- package/dist/server/device-center/hub-transaction-log.js +197 -0
- package/dist/server/device-center/hub-webhooks.js +165 -0
- package/dist/server/device-center/hub.js +1531 -305
- package/dist/server/device-center/integration-verification.js +113 -0
- package/dist/server/device-center/local-hub.js +8 -3
- package/dist/server/device-center/local-publication.js +423 -0
- package/dist/server/device-center/local-verification-job.js +97 -0
- package/dist/server/device-center/local-verification.js +274 -0
- package/dist/server/device-center/local.js +181 -13
- package/dist/server/device-center/main.js +4 -1
- package/dist/server/device-center/partition-log.js +330 -0
- package/dist/server/device-center/publication-journal.js +312 -0
- package/dist/server/device-center/publish-intent.js +379 -0
- package/dist/server/device-center/relay.js +134 -24
- package/dist/server/device-center/runtime.js +475 -42
- package/dist/server/device-center/store.js +366 -89
- package/dist/server/device-center/task-outcome.js +81 -0
- package/dist/server/device-center/task-recovery.js +603 -178
- package/dist/server/device-center/task-scheduler.js +48 -3
- package/dist/server/device-center/task-settlement.js +353 -0
- package/dist/server/device-center/task-workspace.js +443 -0
- package/dist/server/device-center/transfers.js +41 -15
- package/dist/server/device-center/verification-limits.js +10 -0
- package/dist/server/device-center/work-contract.js +995 -0
- package/dist/server/dispatch-domain-handlers.js +29 -3
- package/dist/server/dsh/dsh-agent-service.js +9 -2
- package/dist/server/engine-probe.js +112 -1
- package/dist/server/global-loader.js +119 -19
- package/dist/server/index.js +159 -17
- package/dist/server/managed.js +2 -0
- package/dist/server/model-admin.js +48 -6
- package/dist/server/model-enrich.js +10 -1
- package/dist/server/patch-node-pty.js +3 -2
- package/dist/server/patch-remote-catalog.js +3 -2
- package/dist/server/plugins.js +64 -7
- package/dist/server/preset-fields.js +17 -1
- package/dist/server/preset-share.js +1 -0
- package/dist/server/prompt-composer.js +39 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/quick-ask-settings.js +28 -0
- package/dist/server/quick-ask.js +164 -0
- package/dist/server/reasoning-registry.js +207 -0
- package/dist/server/resolve-global-sdk.js +61 -11
- package/dist/server/scheduler-tasks.js +35 -8
- package/dist/server/session-list-scan.js +223 -0
- package/dist/server/session-open.js +93 -0
- package/dist/server/session-parser.js +4 -0
- package/dist/server/session-scan.js +90 -38
- package/dist/server/settings-service.js +9 -1
- package/dist/server/soft-cap.js +5 -0
- package/dist/server/startup-banner.js +35 -0
- package/dist/server/subagents.js +2 -1
- package/dist/server/tool-manager.js +17 -9
- package/dist/server/transcript-prepare.js +73 -0
- package/dist/server/unauthorized-page.js +319 -0
- package/dist/server/universal/drivers/claude-code.js +98 -34
- package/dist/server/universal/universal-session.js +4 -0
- package/dist/server/workspace-handle.js +428 -0
- package/docs/architecture-plugins.md +959 -0
- package/docs/device-center.md +34 -20
- package/package.json +4 -4
- package/plugin-sdk/README.md +16 -8
- package/plugin-sdk/client.d.ts +27 -0
- package/plugin-sdk/client.mjs +82 -0
- package/plugin-sdk/index.d.ts +10 -0
- package/plugin-sdk/index.mjs +4 -683
- package/plugin-sdk/package.json +15 -4
- package/plugin-sdk/testing.d.ts +10 -0
- package/plugin-sdk/testing.mjs +566 -0
- package/themes/flow-cristallo.css +168 -0
- package/themes/flow-ink.css +169 -0
- package/themes/flow-obsidian.css +169 -0
- package/themes/flow-zurich.css +169 -0
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-BYzPgmoq.js → BgTasksModal-BjNRIUIc.js} +1 -1
- package/web/dist/assets/{BgTasksModal-ni0VTmAQ.js → BgTasksModal-C0zuU8FE.js} +1 -1
- package/web/dist/assets/{CanvasStudio-DNmDNBod.js → CanvasStudio-BWvdmJ0M.js} +3 -3
- package/web/dist/assets/{CanvasStudio-BCUeEf25.js → CanvasStudio-VQFjmTGq.js} +3 -3
- package/web/dist/assets/DeviceCenter-DI9_0aBB.js +3 -0
- package/web/dist/assets/DeviceCenter-DsNtXqzY.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-BLP1Su5G.js +1 -0
- package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +1 -0
- package/web/dist/assets/DeviceGroups-CP7CcyPD.js +1 -0
- package/web/dist/assets/{Dropdown-CGXD0DfT.js → Dropdown-CQtstPGv.js} +1 -1
- package/web/dist/assets/FilePreview-BMB2tNyT.js +2 -0
- package/web/dist/assets/FilePreview-RGFQUbJo.js +2 -0
- package/web/dist/assets/{GlobalSearchModal-mevF-ySi.js → GlobalSearchModal-BM5wxiqU.js} +1 -1
- package/web/dist/assets/{GlobalSearchModal-qL99FN_F.js → GlobalSearchModal-DGv_WINq.js} +1 -1
- package/web/dist/assets/GroupConversation-B7SnuXj1.js +61 -0
- package/web/dist/assets/GroupConversation-Dda69q-2.js +61 -0
- package/web/dist/assets/{HintTip-LHwkS2jV.js → HintTip-ChTW8o1m.js} +1 -1
- package/web/dist/assets/ModelConfigModal-C-0Z4hUZ.js +2 -0
- package/web/dist/assets/ModelConfigModal-yqeadyab.js +2 -0
- package/web/dist/assets/{PiSetupModal-DE5-gEtI.js → PiSetupModal-BX5rUuoI.js} +1 -1
- package/web/dist/assets/{ProviderOAuthControls-6UMARucA.js → ProviderOAuthControls-DY4SCfXg.js} +1 -1
- package/web/dist/assets/SCMPanel-C4KbQvvK.js +2 -0
- package/web/dist/assets/SCMPanel-DPAyY2sW.js +2 -0
- package/web/dist/assets/SettingsModal-DxZp6D_g.js +32 -0
- package/web/dist/assets/SettingsModal-WhQzaOPt.js +32 -0
- package/web/dist/assets/{TerminalPanel-CTp_BZ4S.js → TerminalPanel-D4By_RVc.js} +2 -2
- package/web/dist/assets/{TerminalPanel-CkYxC-Gh.js → TerminalPanel-lZw8-i3j.js} +2 -2
- package/web/dist/assets/{TuiOverlayModal-1cRLP8IF.js → TuiOverlayModal-C3pAVuC8.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-2xlptqWX.js → TuiOverlayModal-D7_rEXcJ.js} +1 -1
- package/web/dist/assets/app-globals-KqOVtmp1.js +123 -0
- package/web/dist/assets/{canvas-client-Bye9nSFO.js → canvas-client-BY6ojmle.js} +1 -1
- package/web/dist/assets/{desktop-kjBoE3Nu.js → desktop-CV6KKp9R.js} +1 -1
- package/web/dist/assets/index-BawF7ZP5.js +397 -0
- package/web/dist/assets/index-BoGCoq5X.js +397 -0
- package/web/dist/assets/index-CVW9FoY2.css +1 -0
- package/web/dist/assets/{plugin-host-C8mNgghx.js → plugin-host-Dn8Dd6SC.js} +1 -1
- package/web/dist/assets/{remote-ssh-client-CeP3CLUW.js → remote-ssh-client-Dzi-eEyE.js} +1 -1
- package/web/dist/assets/{theme-BXGpyTMh.js → theme-D_bihpdN.js} +1 -1
- package/web/dist/index.html +11 -11
- package/web/dist/sw.js +1 -1
- package/dist/server/patch-turn-end-boundary.js +0 -77
- package/web/dist/assets/DeviceCenter-BcBhRgL6.js +0 -3
- package/web/dist/assets/DeviceCenter-CmL5FZmt.js +0 -3
- package/web/dist/assets/DeviceGroups-CLdpdnI7.js +0 -1
- package/web/dist/assets/DeviceGroups-CgBaDPrD.js +0 -1
- package/web/dist/assets/FilePreview-B8iqnBjy.js +0 -2
- package/web/dist/assets/FilePreview-BqviZKCN.js +0 -2
- package/web/dist/assets/GroupConversation-B88Yy-lt.js +0 -3
- package/web/dist/assets/GroupConversation-BwP5NVOE.js +0 -3
- package/web/dist/assets/ModelConfigModal-Do3Fe3jH.js +0 -2
- package/web/dist/assets/SCMPanel-Hi6QqC1Q.js +0 -2
- package/web/dist/assets/SCMPanel-ezY_ZtCu.js +0 -2
- package/web/dist/assets/SettingsModal-6HgeEsJ8.js +0 -20
- package/web/dist/assets/SettingsModal-CF-7MwqS.js +0 -20
- package/web/dist/assets/app-globals-DZNa9v8u.js +0 -325
- package/web/dist/assets/index-CsFs_HMb.css +0 -1
- package/web/dist/assets/index-DHeeHS_l.js +0 -85
- package/web/dist/assets/index-DTZch8uz.js +0 -85
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { canonicalizeJson } from "./work-contract.js";
|
|
3
|
+
import { artifactRefsMatch } from "./delivery-subject.js";
|
|
4
|
+
import { computeVerificationPlanDigest, hasVerifiedIntegration } from "./integration-verification.js";
|
|
5
|
+
/** Leaves room for RPC envelope, original repository identity and relay metadata (512 KiB frame). */
|
|
6
|
+
export const MAX_PUBLISH_INTENT_BYTES = 384 * 1024;
|
|
7
|
+
/** Node-only. UTF-8, LF, controlled author/committer and stable parent order. */
|
|
8
|
+
export function buildPublishCommit(intent) {
|
|
9
|
+
if (intent.version !== 1 || (intent.objectFormat !== "sha1" && intent.objectFormat !== "sha256"))
|
|
10
|
+
invalid("commit builder version or format");
|
|
11
|
+
const length = intent.objectFormat === "sha1" ? 40 : 64;
|
|
12
|
+
for (const value of [intent.expectedOld, intent.preparedTree, intent.materializedCommit])
|
|
13
|
+
hash(value, length);
|
|
14
|
+
hash(intent.digest, 64);
|
|
15
|
+
bounded(intent.id, 1024);
|
|
16
|
+
bounded(intent.integrationId, 1024);
|
|
17
|
+
time(intent.createdAt);
|
|
18
|
+
const timestamp = Math.floor(intent.createdAt / 1000);
|
|
19
|
+
const raw = Buffer.from(`tree ${intent.preparedTree}\nparent ${intent.expectedOld}\nparent ${intent.materializedCommit}\nauthor Pi Publication <publication@pi.invalid> ${timestamp} +0000\ncommitter Pi Publication <publication@pi.invalid> ${timestamp} +0000\n\nPublish integration ${intent.integrationId}\n\nIntent: ${intent.id}\nIntent-Digest: ${intent.digest}\n`, "utf8");
|
|
20
|
+
const candidateSha = createHash(intent.objectFormat)
|
|
21
|
+
.update(Buffer.from(`commit ${raw.length}\0`, "utf8"))
|
|
22
|
+
.update(raw)
|
|
23
|
+
.digest("hex");
|
|
24
|
+
return { raw, candidateSha };
|
|
25
|
+
}
|
|
26
|
+
export function sealPublishIntent(facts) {
|
|
27
|
+
const copy = structuredClone(facts);
|
|
28
|
+
const digest = createHash("sha256").update(canonicalizeJson(copy)).digest("hex");
|
|
29
|
+
const intent = { ...copy, digest, candidateSha: "" };
|
|
30
|
+
intent.candidateSha = buildPublishCommit(intent).candidateSha;
|
|
31
|
+
return validatePublishIntent(intent);
|
|
32
|
+
}
|
|
33
|
+
/** Returns an independently cloned, validated immutable value; throws on invalid wire data. */
|
|
34
|
+
export function validatePublishIntent(value) {
|
|
35
|
+
return validateIntent(value);
|
|
36
|
+
}
|
|
37
|
+
/** Scope is the original authenticated operation identity, never a caller-provided cwd. */
|
|
38
|
+
export function assertPublishIntentScope(intent, scope) {
|
|
39
|
+
for (const [key, expected] of Object.entries(scope)) {
|
|
40
|
+
if (expected !== undefined && intent[key] !== expected)
|
|
41
|
+
throw new Error(`Publication intent ${key} mismatch`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function validatePublicationResult(value, intent) {
|
|
45
|
+
return validateResult(value, intent);
|
|
46
|
+
}
|
|
47
|
+
function invalid(message) {
|
|
48
|
+
throw new Error(`Invalid publication ${message}`);
|
|
49
|
+
}
|
|
50
|
+
function object(value, name) {
|
|
51
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype)
|
|
52
|
+
invalid(name);
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
function keys(value, required, optional = []) {
|
|
56
|
+
if (required.some((k) => value[k] === undefined) ||
|
|
57
|
+
Object.keys(value).some((k) => !required.includes(k) && !optional.includes(k)))
|
|
58
|
+
invalid("fields");
|
|
59
|
+
}
|
|
60
|
+
function bounded(value, max = 256) {
|
|
61
|
+
if (typeof value !== "string" || !value.trim() || value.length > max || /[\x00-\x1f\x7f]/.test(value))
|
|
62
|
+
invalid("text");
|
|
63
|
+
}
|
|
64
|
+
function time(value) {
|
|
65
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > 8_640_000_000_000_000)
|
|
66
|
+
invalid("timestamp");
|
|
67
|
+
}
|
|
68
|
+
function hash(value, length) {
|
|
69
|
+
if (typeof value !== "string" || !new RegExp(`^[a-f0-9]{${length}}$`).test(value))
|
|
70
|
+
invalid("hash");
|
|
71
|
+
}
|
|
72
|
+
function validateIntent(value) {
|
|
73
|
+
const obj = object(value, "intent");
|
|
74
|
+
if (Buffer.byteLength(JSON.stringify(obj), "utf8") > MAX_PUBLISH_INTENT_BYTES)
|
|
75
|
+
throw Object.assign(new Error("Publication aggregate proof exceeds transport budget (384 KiB)"), { status: 413 });
|
|
76
|
+
const required = [
|
|
77
|
+
"version",
|
|
78
|
+
"id",
|
|
79
|
+
"accountId",
|
|
80
|
+
"roomId",
|
|
81
|
+
"conversationId",
|
|
82
|
+
"integrationId",
|
|
83
|
+
"targetDeviceId",
|
|
84
|
+
"targetBotId",
|
|
85
|
+
"targetBotRevision",
|
|
86
|
+
"actor",
|
|
87
|
+
"repositoryId",
|
|
88
|
+
"objectFormat",
|
|
89
|
+
"targetRef",
|
|
90
|
+
"expectedOld",
|
|
91
|
+
"preparedTree",
|
|
92
|
+
"materializedCommit",
|
|
93
|
+
"createdAt",
|
|
94
|
+
"delivery",
|
|
95
|
+
"review",
|
|
96
|
+
"verificationPlan",
|
|
97
|
+
"verification",
|
|
98
|
+
"digest",
|
|
99
|
+
"candidateSha",
|
|
100
|
+
];
|
|
101
|
+
keys(obj, required);
|
|
102
|
+
if (obj.version !== 1 || (obj.objectFormat !== "sha1" && obj.objectFormat !== "sha256"))
|
|
103
|
+
invalid("version or object format");
|
|
104
|
+
for (const key of [
|
|
105
|
+
"id",
|
|
106
|
+
"accountId",
|
|
107
|
+
"roomId",
|
|
108
|
+
"conversationId",
|
|
109
|
+
"integrationId",
|
|
110
|
+
"targetDeviceId",
|
|
111
|
+
"targetBotId",
|
|
112
|
+
"repositoryId",
|
|
113
|
+
])
|
|
114
|
+
bounded(obj[key], 1024);
|
|
115
|
+
if (!Number.isSafeInteger(obj.targetBotRevision) || obj.targetBotRevision < 0)
|
|
116
|
+
invalid("Bot revision");
|
|
117
|
+
time(obj.createdAt);
|
|
118
|
+
bounded(obj.targetRef);
|
|
119
|
+
if (!obj.targetRef.startsWith("refs/heads/") ||
|
|
120
|
+
obj.targetRef.length <= 11 ||
|
|
121
|
+
/[\s~^:?*[\\\]]/.test(obj.targetRef) ||
|
|
122
|
+
obj.targetRef.includes("..") ||
|
|
123
|
+
obj.targetRef.includes("@{") ||
|
|
124
|
+
obj.targetRef.includes("//") ||
|
|
125
|
+
obj.targetRef.split("/").some((p) => !p || p.startsWith(".") || p.endsWith(".") || p.endsWith(".lock")))
|
|
126
|
+
invalid("branch ref");
|
|
127
|
+
const length = obj.objectFormat === "sha1" ? 40 : 64;
|
|
128
|
+
for (const key of ["expectedOld", "preparedTree", "materializedCommit", "candidateSha"])
|
|
129
|
+
hash(obj[key], length);
|
|
130
|
+
hash(obj.digest, 64);
|
|
131
|
+
const actor = object(obj.actor, "actor");
|
|
132
|
+
keys(actor, ["accountId"], ["botId", "botRevision", "botDeviceId", "taskId"]);
|
|
133
|
+
if (actor.accountId !== obj.accountId)
|
|
134
|
+
invalid("actor account");
|
|
135
|
+
if (actor.botId !== undefined) {
|
|
136
|
+
bounded(actor.botId);
|
|
137
|
+
bounded(actor.taskId);
|
|
138
|
+
bounded(actor.botDeviceId);
|
|
139
|
+
if (!Number.isSafeInteger(actor.botRevision) || actor.botRevision < 0)
|
|
140
|
+
invalid("actor revision");
|
|
141
|
+
}
|
|
142
|
+
else if (actor.taskId !== undefined || actor.botRevision !== undefined || actor.botDeviceId !== undefined)
|
|
143
|
+
invalid("actor audit");
|
|
144
|
+
const delivery = object(obj.delivery, "delivery");
|
|
145
|
+
keys(delivery, ["id"], ["commit", "artifactRef"]);
|
|
146
|
+
bounded(delivery.id);
|
|
147
|
+
if (delivery.commit !== undefined)
|
|
148
|
+
hash(delivery.commit, length);
|
|
149
|
+
const review = object(obj.review, "review");
|
|
150
|
+
keys(review, ["id", "accountId", "roomId", "conversationId", "deliveryId", "reviewer", "verdict", "summary", "createdAt"], ["commit", "artifactDigest", "integrationId", "verificationDigest", "criteriaResults", "artifactRef"]);
|
|
151
|
+
bounded(review.id);
|
|
152
|
+
if (review.accountId !== obj.accountId ||
|
|
153
|
+
review.roomId !== obj.roomId ||
|
|
154
|
+
review.conversationId !== obj.conversationId ||
|
|
155
|
+
review.deliveryId !== delivery.id ||
|
|
156
|
+
review.verdict !== "accepted" ||
|
|
157
|
+
typeof review.summary !== "string" ||
|
|
158
|
+
review.summary.length > 32768)
|
|
159
|
+
invalid("accepted review scope");
|
|
160
|
+
time(review.createdAt);
|
|
161
|
+
const reviewer = object(review.reviewer, "reviewer");
|
|
162
|
+
keys(reviewer, ["type", "id"]);
|
|
163
|
+
if (reviewer.type !== "human" && reviewer.type !== "bot")
|
|
164
|
+
invalid("reviewer");
|
|
165
|
+
bounded(reviewer.id);
|
|
166
|
+
if (delivery.artifactRef !== undefined) {
|
|
167
|
+
if (obj.objectFormat !== "sha1")
|
|
168
|
+
invalid("SHA-256 artifact baseline unsupported");
|
|
169
|
+
const artifact = object(delivery.artifactRef, "artifactRef");
|
|
170
|
+
const reviewArtifact = object(review.artifactRef, "review artifactRef");
|
|
171
|
+
keys(reviewArtifact, [
|
|
172
|
+
"artifactTaskId",
|
|
173
|
+
"attemptId",
|
|
174
|
+
"artifactId",
|
|
175
|
+
"artifactDigest",
|
|
176
|
+
"contractId",
|
|
177
|
+
"contractRevision",
|
|
178
|
+
"contractDigest",
|
|
179
|
+
"manifestDigest",
|
|
180
|
+
"baselineCommit",
|
|
181
|
+
"repositoryId",
|
|
182
|
+
"inputTree",
|
|
183
|
+
"outputTree",
|
|
184
|
+
]);
|
|
185
|
+
if (review.commit !== undefined)
|
|
186
|
+
invalid("artifact review commit");
|
|
187
|
+
keys(artifact, [
|
|
188
|
+
"artifactTaskId",
|
|
189
|
+
"attemptId",
|
|
190
|
+
"artifactId",
|
|
191
|
+
"artifactDigest",
|
|
192
|
+
"contractId",
|
|
193
|
+
"contractRevision",
|
|
194
|
+
"contractDigest",
|
|
195
|
+
"manifestDigest",
|
|
196
|
+
"baselineCommit",
|
|
197
|
+
"repositoryId",
|
|
198
|
+
"inputTree",
|
|
199
|
+
"outputTree",
|
|
200
|
+
]);
|
|
201
|
+
for (const key of ["artifactTaskId", "attemptId", "artifactId", "contractId", "repositoryId"])
|
|
202
|
+
bounded(artifact[key], 1024);
|
|
203
|
+
for (const key of ["artifactDigest", "contractDigest", "manifestDigest"])
|
|
204
|
+
hash(artifact[key], 64);
|
|
205
|
+
for (const key of ["baselineCommit", "inputTree", "outputTree"])
|
|
206
|
+
hash(artifact[key], 40);
|
|
207
|
+
if (!Number.isSafeInteger(artifact.contractRevision) ||
|
|
208
|
+
artifact.contractRevision < 1 ||
|
|
209
|
+
artifact.repositoryId !== obj.repositoryId ||
|
|
210
|
+
artifact.baselineCommit !== obj.expectedOld ||
|
|
211
|
+
artifact.outputTree !== obj.preparedTree ||
|
|
212
|
+
!artifactRefsMatch(delivery.artifactRef, review.artifactRef) ||
|
|
213
|
+
review.artifactDigest !== artifact.artifactDigest ||
|
|
214
|
+
review.integrationId !== obj.integrationId)
|
|
215
|
+
invalid("artifact review");
|
|
216
|
+
const criteria = review.criteriaResults;
|
|
217
|
+
if (!Array.isArray(criteria) ||
|
|
218
|
+
criteria.length > 64 ||
|
|
219
|
+
criteria.some((v, index) => {
|
|
220
|
+
const criterion = object(v, "review criterion");
|
|
221
|
+
keys(criterion, ["criterionIndex", "verdict", "evidence"]);
|
|
222
|
+
return (!Number.isSafeInteger(criterion.criterionIndex) ||
|
|
223
|
+
criterion.criterionIndex < 0 ||
|
|
224
|
+
criterion.criterionIndex > 63 ||
|
|
225
|
+
criterion.verdict !== "met" ||
|
|
226
|
+
typeof criterion.evidence !== "string" ||
|
|
227
|
+
!criterion.evidence.trim() ||
|
|
228
|
+
criterion.evidence.length > 2000 ||
|
|
229
|
+
criteria.slice(0, index).some((p) => p.criterionIndex === criterion.criterionIndex));
|
|
230
|
+
}))
|
|
231
|
+
invalid("review criteria");
|
|
232
|
+
}
|
|
233
|
+
else if (!delivery.commit ||
|
|
234
|
+
review.commit !== delivery.commit ||
|
|
235
|
+
review.artifactRef !== undefined ||
|
|
236
|
+
review.artifactDigest !== undefined ||
|
|
237
|
+
review.integrationId !== undefined ||
|
|
238
|
+
review.verificationDigest !== undefined ||
|
|
239
|
+
review.criteriaResults !== undefined)
|
|
240
|
+
invalid("legacy review subject");
|
|
241
|
+
const plan = object(obj.verificationPlan, "verification plan");
|
|
242
|
+
keys(plan, ["commands", "digest", "authorizedByAccountId", "authorizedAt"]);
|
|
243
|
+
if (!Array.isArray(plan.commands) ||
|
|
244
|
+
plan.commands.length < 1 ||
|
|
245
|
+
plan.commands.length > 8 ||
|
|
246
|
+
plan.commands.some((c) => typeof c !== "string" || !c.trim() || c.length > 4096 || /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/.test(c)) ||
|
|
247
|
+
plan.digest !== computeVerificationPlanDigest(plan.commands) ||
|
|
248
|
+
plan.authorizedByAccountId !== obj.accountId)
|
|
249
|
+
invalid("verification plan");
|
|
250
|
+
time(plan.authorizedAt);
|
|
251
|
+
const verification = object(obj.verification, "verification");
|
|
252
|
+
keys(verification, ["planDigest", "materializedCommit", "treeBefore", "treeAfter", "results", "digest", "verifiedAt"], ["artifactDigest"]);
|
|
253
|
+
time(verification.verifiedAt);
|
|
254
|
+
hash(verification.digest, 64);
|
|
255
|
+
if (!Array.isArray(verification.results))
|
|
256
|
+
invalid("verification results");
|
|
257
|
+
for (const item of verification.results)
|
|
258
|
+
keys(object(item, "verification result"), ["command", "status", "exitCode", "outputDigest", "outputPreview"]);
|
|
259
|
+
if (delivery.artifactRef && review.verificationDigest !== verification.digest)
|
|
260
|
+
invalid("review verification");
|
|
261
|
+
const intent = obj;
|
|
262
|
+
const integration = {
|
|
263
|
+
id: intent.integrationId,
|
|
264
|
+
accountId: intent.accountId,
|
|
265
|
+
roomId: intent.roomId,
|
|
266
|
+
conversationId: intent.conversationId,
|
|
267
|
+
deliveryId: intent.delivery.id,
|
|
268
|
+
commit: intent.delivery.commit,
|
|
269
|
+
artifactRef: intent.delivery.artifactRef,
|
|
270
|
+
targetBotId: intent.targetBotId,
|
|
271
|
+
targetBotRevision: intent.targetBotRevision,
|
|
272
|
+
targetDeviceId: intent.targetDeviceId,
|
|
273
|
+
expectedTargetSha: intent.expectedOld,
|
|
274
|
+
preparedTree: intent.preparedTree,
|
|
275
|
+
materializedCommit: intent.materializedCommit,
|
|
276
|
+
objectFormat: intent.objectFormat,
|
|
277
|
+
verificationPlan: intent.verificationPlan,
|
|
278
|
+
verification: intent.verification,
|
|
279
|
+
};
|
|
280
|
+
// Older verified integrations recorded the short branch; accept either original spelling.
|
|
281
|
+
if (![intent.targetRef, intent.targetRef.slice(11)].some((targetBranch) => hasVerifiedIntegration({ ...integration, targetBranch })))
|
|
282
|
+
invalid("verification proof");
|
|
283
|
+
const { digest, candidateSha, ...facts } = intent;
|
|
284
|
+
if (digest !== createHash("sha256").update(canonicalizeJson(facts)).digest("hex") ||
|
|
285
|
+
candidateSha !== buildPublishCommit(intent).candidateSha)
|
|
286
|
+
invalid("intent digest or candidate");
|
|
287
|
+
return structuredClone(intent);
|
|
288
|
+
}
|
|
289
|
+
function validateResult(value, intent) {
|
|
290
|
+
const obj = object(value, "result");
|
|
291
|
+
keys(obj, ["status"], ["publishReceipt", "publishObservation", "publishStop", "cleanupPending", "newCommitSha"]);
|
|
292
|
+
if (obj.cleanupPending !== undefined && typeof obj.cleanupPending !== "boolean")
|
|
293
|
+
invalid("cleanup status");
|
|
294
|
+
if (obj.newCommitSha !== undefined && obj.newCommitSha !== intent.candidateSha)
|
|
295
|
+
invalid("result candidate");
|
|
296
|
+
if (!["applied", "pending", "cancelled"].includes(obj.status))
|
|
297
|
+
invalid("result status");
|
|
298
|
+
for (const key of ["publishReceipt", "publishObservation", "publishStop"]) {
|
|
299
|
+
if (obj[key] === undefined)
|
|
300
|
+
continue;
|
|
301
|
+
const evidence = object(obj[key], key);
|
|
302
|
+
if (evidence.intentId !== intent.id ||
|
|
303
|
+
evidence.intentDigest !== intent.digest ||
|
|
304
|
+
evidence.candidateSha !== intent.candidateSha)
|
|
305
|
+
invalid("evidence identity");
|
|
306
|
+
if (key === "publishReceipt") {
|
|
307
|
+
keys(evidence, ["intentId", "intentDigest", "candidateSha", "outcome", "proof", "observedAt"], ["targetSha"]);
|
|
308
|
+
time(evidence.observedAt);
|
|
309
|
+
if (evidence.outcome !== "applied" ||
|
|
310
|
+
!["cas_exit", "target_exact", "target_descendant"].includes(evidence.proof) ||
|
|
311
|
+
(evidence.proof === "target_exact" && evidence.targetSha !== intent.candidateSha) ||
|
|
312
|
+
(evidence.proof === "target_descendant" && !evidence.targetSha))
|
|
313
|
+
invalid("receipt proof");
|
|
314
|
+
}
|
|
315
|
+
else if (key === "publishObservation") {
|
|
316
|
+
keys(evidence, ["intentId", "intentDigest", "candidateSha", "observedAt", "target", "phase", "retryable"], ["targetSha", "error"]);
|
|
317
|
+
time(evidence.observedAt);
|
|
318
|
+
if (!["candidate", "descendant", "expected_old", "other", "missing", "unknown"].includes(evidence.target) ||
|
|
319
|
+
!["absent", "prepared", "cas_started", "cas_rejected", "applied", "closed", "unknown"].includes(evidence.phase) ||
|
|
320
|
+
typeof evidence.retryable !== "boolean" ||
|
|
321
|
+
(evidence.retryable &&
|
|
322
|
+
(!["prepared", "cas_rejected"].includes(evidence.phase) || evidence.target !== "expected_old")))
|
|
323
|
+
invalid("observation");
|
|
324
|
+
if ((evidence.target === "candidate" && evidence.targetSha !== intent.candidateSha) ||
|
|
325
|
+
(["descendant", "other"].includes(evidence.target) && !evidence.targetSha) ||
|
|
326
|
+
(evidence.target === "expected_old" && evidence.targetSha !== intent.expectedOld) ||
|
|
327
|
+
(evidence.error !== undefined && (typeof evidence.error !== "string" || evidence.error.length > 2048)))
|
|
328
|
+
invalid("target observation");
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
keys(evidence, ["intentId", "intentDigest", "candidateSha", "closed", "stopConfirmed", "pastEffect", "fencedAt"], ["stoppedAt"]);
|
|
332
|
+
time(evidence.fencedAt);
|
|
333
|
+
if (typeof evidence.closed !== "boolean" ||
|
|
334
|
+
typeof evidence.stopConfirmed !== "boolean" ||
|
|
335
|
+
!["applied", "not_applied", "unknown"].includes(evidence.pastEffect))
|
|
336
|
+
invalid("stop");
|
|
337
|
+
if (evidence.stopConfirmed)
|
|
338
|
+
time(evidence.stoppedAt);
|
|
339
|
+
else if (evidence.stoppedAt !== undefined || evidence.pastEffect === "not_applied")
|
|
340
|
+
invalid("unconfirmed stop");
|
|
341
|
+
}
|
|
342
|
+
if (evidence.targetSha !== undefined)
|
|
343
|
+
hash(evidence.targetSha, intent.objectFormat === "sha1" ? 40 : 64);
|
|
344
|
+
}
|
|
345
|
+
const observation = obj.publishObservation;
|
|
346
|
+
const stoppedWithoutEffect = obj.publishStop?.closed &&
|
|
347
|
+
obj.publishStop?.stopConfirmed &&
|
|
348
|
+
obj.publishStop?.pastEffect === "not_applied";
|
|
349
|
+
if (observation &&
|
|
350
|
+
((["candidate", "descendant"].includes(observation.target) &&
|
|
351
|
+
!obj.publishReceipt &&
|
|
352
|
+
!stoppedWithoutEffect) ||
|
|
353
|
+
(observation.phase === "applied" && !obj.publishReceipt) ||
|
|
354
|
+
(observation.phase === "closed" && !obj.publishStop)))
|
|
355
|
+
invalid("observation proof");
|
|
356
|
+
if (obj.status === "applied" && !obj.publishReceipt)
|
|
357
|
+
invalid("missing applied receipt");
|
|
358
|
+
if (obj.publishReceipt && obj.status !== "applied")
|
|
359
|
+
invalid("applied receipt status");
|
|
360
|
+
if (obj.status === "cancelled" &&
|
|
361
|
+
(!obj.publishStop?.closed ||
|
|
362
|
+
!obj.publishStop?.stopConfirmed ||
|
|
363
|
+
obj.publishStop?.pastEffect !== "not_applied" ||
|
|
364
|
+
obj.publishReceipt))
|
|
365
|
+
invalid("unproven cancellation");
|
|
366
|
+
if (obj.publishStop?.pastEffect === "applied" && !obj.publishReceipt)
|
|
367
|
+
invalid("stop without applied proof");
|
|
368
|
+
if (obj.publishObservation?.retryable && (obj.publishReceipt || obj.publishStop?.closed))
|
|
369
|
+
invalid("retry of closed publication");
|
|
370
|
+
if (obj.publishReceipt && obj.publishStop?.pastEffect === "not_applied")
|
|
371
|
+
invalid("contradictory receipt");
|
|
372
|
+
return structuredClone({
|
|
373
|
+
status: obj.status,
|
|
374
|
+
...(obj.publishReceipt ? { publishReceipt: obj.publishReceipt } : {}),
|
|
375
|
+
...(obj.publishObservation ? { publishObservation: obj.publishObservation } : {}),
|
|
376
|
+
...(obj.publishStop ? { publishStop: obj.publishStop } : {}),
|
|
377
|
+
...(obj.cleanupPending !== undefined ? { cleanupPending: obj.cleanupPending } : {}),
|
|
378
|
+
});
|
|
379
|
+
}
|