pi-web-ui 0.116.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 +38 -4
- package/bin/device-hub-cli.mjs +26 -3
- package/bin/pi-web-ui.mjs +138 -70
- package/dist/server/agent-service-daemon.js +52 -6
- package/dist/server/agent-service.js +495 -141
- package/dist/server/canvas/canvas-workspace.js +18 -86
- package/dist/server/client-state.js +35 -6
- package/dist/server/compaction-markers.js +43 -24
- package/dist/server/dangling-tools.js +172 -16
- package/dist/server/device-center/bot-execution.js +48 -1
- package/dist/server/device-center/collab-service.js +26 -8
- package/dist/server/device-center/collab-tool.js +394 -18
- 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 +15 -5
- package/dist/server/device-center/executor.js +47 -5
- package/dist/server/device-center/hub-conversations.js +14 -4
- 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-page.js +5 -4
- 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.js +772 -354
- package/dist/server/device-center/integration-verification.js +113 -0
- package/dist/server/device-center/local-hub.js +6 -2
- 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 +107 -12
- package/dist/server/device-center/main.js +4 -1
- package/dist/server/device-center/partition-log.js +62 -25
- 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 +426 -42
- package/dist/server/device-center/store.js +225 -47
- 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-settlement.js +353 -0
- package/dist/server/device-center/task-workspace.js +443 -0
- 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 +15 -0
- package/dist/server/dsh/dsh-agent-service.js +9 -2
- package/dist/server/index.js +26 -1
- package/dist/server/patch-node-pty.js +3 -2
- package/dist/server/patch-remote-catalog.js +3 -2
- package/dist/server/preset-fields.js +17 -1
- package/dist/server/preset-share.js +1 -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/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/transcript-prepare.js +73 -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 +18 -5
- package/docs/device-center.md +30 -22
- package/package.json +3 -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-BDoOpj-F.js → BgTasksModal-BjNRIUIc.js} +1 -1
- package/web/dist/assets/{BgTasksModal-C0i3O1FT.js → BgTasksModal-C0zuU8FE.js} +1 -1
- package/web/dist/assets/{CanvasStudio-B8thymBN.js → CanvasStudio-BWvdmJ0M.js} +3 -3
- package/web/dist/assets/{CanvasStudio-zSxyIx1R.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-q5Ik8oXg.js → DeviceExecutionSettings-BLP1Su5G.js} +1 -1
- package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +1 -0
- package/web/dist/assets/DeviceGroups-CP7CcyPD.js +1 -0
- package/web/dist/assets/{Dropdown-C4LIhshN.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-BWgU8yPd.js → GlobalSearchModal-BM5wxiqU.js} +1 -1
- package/web/dist/assets/{GlobalSearchModal-F7fNimKk.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-c6d0TJoh.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-BmMrrgB9.js → PiSetupModal-BX5rUuoI.js} +1 -1
- package/web/dist/assets/{ProviderOAuthControls-BGSBIKD7.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-DDavKvFr.js → TerminalPanel-D4By_RVc.js} +2 -2
- package/web/dist/assets/{TerminalPanel-0CYvD72B.js → TerminalPanel-lZw8-i3j.js} +2 -2
- package/web/dist/assets/{TuiOverlayModal-BsA-QTvN.js → TuiOverlayModal-C3pAVuC8.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-DzoVQBuG.js → TuiOverlayModal-D7_rEXcJ.js} +1 -1
- package/web/dist/assets/app-globals-KqOVtmp1.js +123 -0
- package/web/dist/assets/{canvas-client-CUnXlQYX.js → canvas-client-BY6ojmle.js} +1 -1
- package/web/dist/assets/{desktop-aAKpvKJV.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-BRWib9DF.js → plugin-host-Dn8Dd6SC.js} +1 -1
- package/web/dist/assets/{remote-ssh-client-CfYSMEZg.js → remote-ssh-client-Dzi-eEyE.js} +1 -1
- package/web/dist/assets/{theme-D2l_mLNo.js → theme-D_bihpdN.js} +1 -1
- package/web/dist/index.html +11 -11
- package/web/dist/sw.js +1 -1
- package/dist/gh-comment-781.md +0 -5
- package/dist/server/device-center/local-page.js +0 -17
- package/dist/server/device-center/smoke-preview.js +0 -3
- package/dist/server/durable/durable-capabilities.js +0 -11
- package/dist/server/markers/builtins/services.js +0 -123
- package/dist/server/markers/builtins/todo.js +0 -189
- package/dist/server/markers-list-tool.js +0 -34
- package/dist/server/orchestrator.js +0 -109
- package/dist/server/patch-turn-end-boundary.js +0 -77
- package/dist/server/system-prompt-soul.js +0 -41
- package/dist/server/univer-service.js +0 -448
- package/dist/server/universal/drivers/dsh-driver.js +0 -379
- package/dist/test-artifact.md +0 -9
- package/dist/test-preview-modal.md +0 -11
- package/dist/test-report.html +0 -20
- package/web/dist/assets/DeviceCenter-DfAHKcid.js +0 -3
- package/web/dist/assets/DeviceCenter-ydvOTlzE.js +0 -3
- package/web/dist/assets/DeviceGroups-CI14_SRb.js +0 -1
- package/web/dist/assets/DeviceGroups-DvsB5IEU.js +0 -1
- package/web/dist/assets/FilePreview-BgGongmv.js +0 -2
- package/web/dist/assets/FilePreview-D4NrhF-U.js +0 -2
- package/web/dist/assets/GroupConversation-Dh71Pdb-.js +0 -17
- package/web/dist/assets/GroupConversation-ZK3nRmNm.js +0 -17
- package/web/dist/assets/ModelConfigModal-YVEgyy34.js +0 -2
- package/web/dist/assets/ModelConfigModal-vWtg3srp.js +0 -2
- package/web/dist/assets/SCMPanel-B8_EDxNr.js +0 -2
- package/web/dist/assets/SCMPanel-BU58qk3T.js +0 -2
- package/web/dist/assets/SettingsModal-CMUybq3J.js +0 -32
- package/web/dist/assets/SettingsModal-OBmGTh-5.js +0 -32
- package/web/dist/assets/app-globals-CZxzGvIo.js +0 -123
- package/web/dist/assets/index-C6DwztqE.css +0 -1
- package/web/dist/assets/index-CuN802Sj.js +0 -93
- package/web/dist/assets/index-EH5Fw9fa.js +0 -93
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Locally owned procedure text. Never interpolate task, history, configuration or remote content. */
|
|
2
|
-
export const EXECUTION_GUIDE_TOPICS = ["coordination", "delivery", "review"];
|
|
2
|
+
export const EXECUTION_GUIDE_TOPICS = ["coordination", "code", "delivery", "review"];
|
|
3
3
|
export const EXECUTION_GUIDE_MAX_BYTES = 8192;
|
|
4
4
|
export const LOCAL_EXECUTION_GUIDES = Object.freeze({
|
|
5
5
|
coordination: [
|
|
@@ -11,14 +11,24 @@ export const LOCAL_EXECUTION_GUIDES = Object.freeze({
|
|
|
11
11
|
"When a worker result returns, assess its evidence against the user's request and report the useful outcome or remaining blocker. Distinguish reported checks from checks you observed. Keep delivery and independent review tied to the exact commit; do not approve your own delivery or claim completion from a worker's execution status alone. Record established architectural conclusions and shared schemas to the group blackboard via device_collab blackboard_update. Report dispatch as dispatch, not completed work. Keep group updates brief and actionable.",
|
|
12
12
|
"Do not create duplicate assignments for a task already in progress or autonomously retry an unchanged blocker; all delegation remains within the existing task-chain budget. This guide grants no additional tool, workspace or approval permissions.",
|
|
13
13
|
].join("\n\n"),
|
|
14
|
+
code: [
|
|
15
|
+
"Use explicit executionMode=code only for authorized repository changes. Delegate with send_task, conversation_create or conversation_send and a contract containing baseline.repositoryId, the full baseline.commit SHA, goal, constraints and acceptanceCriteria. Obtain the target repository identity and baseline from authoritative repository metadata or the supplied contract; never guess a remote directory or repository label.",
|
|
16
|
+
"Keep the same idempotencyKey and contract on retries. Reuse a business contract id with a higher revision only for changed requirements; a running older revision must finish before a replacement starts. Each code turn uses a fresh isolated session and cannot resume a transcript from another workspace. Ordinary discussion remains in chat mode.",
|
|
17
|
+
"The Hub freezes selected context and inputs in a ContextManifest. Use task_evidence with evidenceKind=artifact, taskId, expectedDigest and byte offset/limit to retrieve captured outputs in bounded base64 pages. Reassemble the full patch and verify its SHA-256 before passing the exact metadata and content as inputArtifacts; never edit their content or digests. Cumulative patches include their ancestors, so pass a descendant once rather than combining it with a redundant ancestor. Conflicting inputs fail explicitly.",
|
|
18
|
+
"The executor captures a bounded binary patch and Git trees after confirmed stop. Read artifact and execution facts as evidence: execution completion, artifact production, independent verification and delivery acceptance are separate. Capture failure is a failed delivery even if execution ended; preserve the workspace for inspection. Do not claim verification, acceptance or publication from completed status alone.",
|
|
19
|
+
"An isolated worktree controls the location of changes and grants no additional filesystem, network, tool or approval permissions. A captured artifact does not authorize applying a patch, merging a branch or publishing a commit.",
|
|
20
|
+
].join("\n\n"),
|
|
14
21
|
delivery: [
|
|
15
|
-
"
|
|
22
|
+
"For requested development handoffs, use conversation_deliver from your current running task. For a captured code artifact in your own conversation, pass artifactTaskId and summary; omit repository, baseCommit, commit and branch. The Hub derives its immutable subject. For a commit delivery, supply repository, full base and delivered commit SHAs (baseCommit and commit), summary, actual checks and limitations.",
|
|
16
23
|
"Checks are Bot-reported, not host verification. Record actual commands and observed results, with exit codes when available; record checks not performed as not_run. Never invent evidence. The action records evidence and never runs declared commands.",
|
|
17
|
-
"
|
|
24
|
+
"Publication uses a durable intent and independent receipt. A timeout or failed transport can leave the effect unknown; never infer unpublished from an old target SHA, retry an uncertain CAS, or claim cancellation erased a past effect. Reconciliation only observes evidence. Only the account owner can explicitly resume the same intent when the device proves CAS did not start or was rejected and stopped.",
|
|
25
|
+
"Bind the delivery to its exact artifact or commit and your current task and conversation. Use current_task for authoritative routing identifiers. Reuse idempotencyKey on retries; do not claim acceptance from execution completion alone. An artifact remains a tree and patch subject; do not invent a commit SHA for it. Independent review must match this exact subject and cannot come from its author.",
|
|
18
26
|
].join("\n\n"),
|
|
19
27
|
review: [
|
|
20
|
-
"When asked to review another Bot's delivery,
|
|
21
|
-
"Use
|
|
28
|
+
"When asked to review another Bot's delivery, inspect its exact commit or artifact against the user's requirements, evidence and limitations. Distinguish Bot-reported checks from actual Integration verification. Do not claim checks you did not perform or approve from execution status alone.",
|
|
29
|
+
"Use conversation_review with the target conversationId, deliveryId, verdict and findings. Commit reviews require the full delivered commit SHA. Artifact reviews require artifactDigest; acceptance also requires the current integrationId, verificationDigest and criteriaResults covering every sealed acceptanceCriteria index with verdict met and specific evidence. Read these identities from conversation_read; never fabricate verification. A changes_requested review may precede verification. Never review your own delivery. A new version needs a new review tied to its exact subject; never reuse another version's acceptance. Reuse idempotencyKey on retries.",
|
|
30
|
+
"If acceptanceCriteriaTruncated is true, read the complete sealed array with task_evidence evidenceKind=acceptance, deliveryId, expectedDigest=artifactRef.contractDigest and byte offset/limit. Reassemble base64 pages, verify criteriaDigest, then parse the JSON. Never review shortened conditions as complete requirements.",
|
|
31
|
+
"The account owner must explicitly authorize the initial verification command plan in the integration UI. Bot calls cannot create or change that plan; an authorized plan may only be reused unchanged. Neither delivery checks nor package scripts grant command permission. If no successful verification exists, report the missing prerequisite instead of inventing a receipt.",
|
|
22
32
|
"These actions record requested development handoffs, not ordinary discussion. This guide does not authorize command execution, merge, workspace changes or additional permissions.",
|
|
23
33
|
].join("\n\n"),
|
|
24
34
|
});
|
|
@@ -35,11 +35,26 @@ function samePath(a, b) {
|
|
|
35
35
|
}
|
|
36
36
|
export function taskPrompt(task) {
|
|
37
37
|
const context = task.taskState ? selectTaskContext(task.taskState) : undefined;
|
|
38
|
+
const isCode = (task.executionMode ?? task.contract?.executionMode) === "code";
|
|
39
|
+
// In code mode, contract.goal is the authoritative executable instruction binding
|
|
40
|
+
const effectiveText = isCode && task.contract?.goal ? task.contract.goal : task.text;
|
|
41
|
+
const contractInfo = task.contract
|
|
42
|
+
? {
|
|
43
|
+
contractId: task.contract.id,
|
|
44
|
+
contractRevision: task.contract.revision,
|
|
45
|
+
contractDigest: task.contract.digest,
|
|
46
|
+
executionMode: task.contract.executionMode,
|
|
47
|
+
goal: task.contract.goal,
|
|
48
|
+
constraints: task.contract.constraints,
|
|
49
|
+
acceptanceCriteria: task.contract.acceptanceCriteria,
|
|
50
|
+
baseline: task.contract.baseline,
|
|
51
|
+
}
|
|
52
|
+
: undefined;
|
|
38
53
|
return [
|
|
39
54
|
`Device task ${JSON.stringify(task.id)}, attempt ${JSON.stringify(task.attemptId)}.`,
|
|
40
55
|
`Local system (measured by this bridge): ${os.platform()} / ${os.arch()}.`,
|
|
41
56
|
JSON.stringify({
|
|
42
|
-
text:
|
|
57
|
+
text: effectiveText,
|
|
43
58
|
taskState: context?.state,
|
|
44
59
|
taskStateSelection: context?.selection,
|
|
45
60
|
roomId: task.roomId ?? null,
|
|
@@ -50,7 +65,9 @@ export function taskPrompt(task) {
|
|
|
50
65
|
requestId: task.requestId,
|
|
51
66
|
parentTaskId: task.parentTaskId,
|
|
52
67
|
resultOfTaskId: task.resultOfTaskId,
|
|
53
|
-
handoff: task.handoff ?? null,
|
|
68
|
+
handoff: isCode ? null : (task.handoff ?? null),
|
|
69
|
+
contract: contractInfo,
|
|
70
|
+
executionMode: isCode ? "code" : "chat",
|
|
54
71
|
...(task.attenuatedTools && task.attenuatedTools.length ? { attenuatedTools: task.attenuatedTools } : {}),
|
|
55
72
|
}),
|
|
56
73
|
].join("\n\n");
|
|
@@ -65,10 +82,15 @@ export function createDeviceTaskExecutor(options) {
|
|
|
65
82
|
const origin = originUrl(options.localOrigin);
|
|
66
83
|
if (!isAbsolute(options.cwd))
|
|
67
84
|
throw new Error("cwd must be an absolute local path");
|
|
85
|
+
if (options.executionCwd !== undefined && !isAbsolute(options.executionCwd)) {
|
|
86
|
+
throw new Error("executionCwd must be an absolute local path");
|
|
87
|
+
}
|
|
68
88
|
const cwd = resolve(options.cwd);
|
|
89
|
+
const effectiveCwd = options.executionCwd ? resolve(options.executionCwd) : cwd;
|
|
69
90
|
const root = executionRoot(cwd);
|
|
70
91
|
let closed = false;
|
|
71
92
|
let cancel;
|
|
93
|
+
let activeSend;
|
|
72
94
|
let stopped = Promise.resolve();
|
|
73
95
|
return {
|
|
74
96
|
run(task) {
|
|
@@ -78,6 +100,10 @@ export function createDeviceTaskExecutor(options) {
|
|
|
78
100
|
return Promise.reject(new DeviceTaskError("目标设备未开启群任务执行权限。请在该设备的设备中心 → 连接设置中开启“允许智能体任务与文件导入”。 / Local task execution is disabled.", "Local task execution is disabled"));
|
|
79
101
|
if (!task.id || !task.attemptId || !task.text?.trim())
|
|
80
102
|
return Promise.reject(new Error("Invalid task"));
|
|
103
|
+
const isCodeMode = (task.executionMode ?? options.executionMode ?? task.contract?.executionMode) === "code";
|
|
104
|
+
if (isCodeMode && task.resume) {
|
|
105
|
+
return Promise.reject(new DeviceTaskError("Code execution mode refuses resuming old sessions in first slice"));
|
|
106
|
+
}
|
|
81
107
|
if ([...busyExecutions].some((entry) => entry.origin === origin.origin && (entry.botId === task.botId || executionRootsOverlap(entry.root, root))))
|
|
82
108
|
return Promise.reject(new DeviceTaskError("目标设备正在执行另一个群任务,请稍后再试。 / Local task executor busy.", "Local task executor busy"));
|
|
83
109
|
const key = JSON.stringify([origin.origin, task.id]);
|
|
@@ -107,6 +133,13 @@ export function createDeviceTaskExecutor(options) {
|
|
|
107
133
|
planOnly: Boolean(task.planOnly),
|
|
108
134
|
attenuatedTools: task.attenuatedTools,
|
|
109
135
|
sourceBotId: task.sourceBotId,
|
|
136
|
+
executionCwd: effectiveCwd,
|
|
137
|
+
executionMode: isCodeMode ? "code" : "chat",
|
|
138
|
+
workspaceHandleId: options.workspaceHandleId,
|
|
139
|
+
workspaceCapability: options.workspaceCapability,
|
|
140
|
+
deviceId: task.deviceId,
|
|
141
|
+
taskId: task.id,
|
|
142
|
+
attemptId: task.attemptId,
|
|
110
143
|
});
|
|
111
144
|
attempted.add(key);
|
|
112
145
|
const lock = { origin: origin.origin, botId: task.botId, root };
|
|
@@ -194,6 +227,7 @@ export function createDeviceTaskExecutor(options) {
|
|
|
194
227
|
if (ws.readyState === WebSocket.OPEN)
|
|
195
228
|
ws.send(JSON.stringify(message));
|
|
196
229
|
};
|
|
230
|
+
activeSend = send;
|
|
197
231
|
const context = () => `Task: ${task.id}\nAttempt: ${task.attemptId}\nLocal system: ${os.platform()} / ${os.arch()}\nLocal UI: ${origin.origin}/\nClient: ${clientId}\nConversation: ${conversationId ?? "not created"}`;
|
|
198
232
|
const finish = (error, body = "", failurePhase) => {
|
|
199
233
|
if (settled)
|
|
@@ -201,6 +235,7 @@ export function createDeviceTaskExecutor(options) {
|
|
|
201
235
|
settled = true;
|
|
202
236
|
interactions?.close();
|
|
203
237
|
options.registerInteractionAnswer?.(undefined);
|
|
238
|
+
activeSend = undefined;
|
|
204
239
|
capability.revoke();
|
|
205
240
|
// 锁的语义是「这个 bot/root 上还有一条任务在跑」,而 run 一旦 settle(capability
|
|
206
241
|
// 已撤销、不再有任何写入路径),它就不再是在跑。旧实现只在连接 close 时才放锁:
|
|
@@ -478,7 +513,7 @@ export function createDeviceTaskExecutor(options) {
|
|
|
478
513
|
return;
|
|
479
514
|
}
|
|
480
515
|
if (phase === "initial" || (phase === "cwd" && cwdDone)) {
|
|
481
|
-
if (resolve(state.cwd) !==
|
|
516
|
+
if (resolve(state.cwd) !== effectiveCwd) {
|
|
482
517
|
if (phase === "cwd") {
|
|
483
518
|
finish("Workspace switch did not reach requested cwd");
|
|
484
519
|
return;
|
|
@@ -504,7 +539,7 @@ export function createDeviceTaskExecutor(options) {
|
|
|
504
539
|
}
|
|
505
540
|
else if (state.messages.length || state.historyTotal)
|
|
506
541
|
return;
|
|
507
|
-
if (state.isEphemeral || resolve(state.cwd) !==
|
|
542
|
+
if (state.isEphemeral || resolve(state.cwd) !== effectiveCwd) {
|
|
508
543
|
finish("Task session is not persistent in requested cwd");
|
|
509
544
|
return;
|
|
510
545
|
}
|
|
@@ -575,7 +610,7 @@ export function createDeviceTaskExecutor(options) {
|
|
|
575
610
|
finish("Task SDK session ownership changed");
|
|
576
611
|
return;
|
|
577
612
|
}
|
|
578
|
-
if (resolve(state.cwd) !==
|
|
613
|
+
if (resolve(state.cwd) !== effectiveCwd ||
|
|
579
614
|
state.isEphemeral ||
|
|
580
615
|
(options.resumePath && !samePath(state.sessionFile, options.resumePath))) {
|
|
581
616
|
finish("Task transcript or fixed workspace ownership changed");
|
|
@@ -714,8 +749,15 @@ export function createDeviceTaskExecutor(options) {
|
|
|
714
749
|
});
|
|
715
750
|
});
|
|
716
751
|
},
|
|
752
|
+
steer(text) {
|
|
753
|
+
if (closed || !activeSend)
|
|
754
|
+
return false;
|
|
755
|
+
activeSend({ type: "prompt", text, steer: true });
|
|
756
|
+
return true;
|
|
757
|
+
},
|
|
717
758
|
close() {
|
|
718
759
|
closed = true;
|
|
760
|
+
activeSend = undefined;
|
|
719
761
|
cancel?.();
|
|
720
762
|
return stopped;
|
|
721
763
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { isTerminal, taskPending } from "./store.js";
|
|
2
|
+
import { isTerminal, taskPending, taskHasImmutableEvidence, } from "./store.js";
|
|
3
3
|
/** Closed conversations kept per room for reading history; open ones are capacity, closed ones are archive. */
|
|
4
4
|
export const CLOSED_CONVERSATION_RETENTION = 200;
|
|
5
5
|
/** Idempotency receipts outlive message retention; replay must never re-dispatch evicted messages. */
|
|
@@ -17,7 +17,8 @@ export function conversationStale(state, conversation) {
|
|
|
17
17
|
export function conversationHasAuditRecords(state, conversationId) {
|
|
18
18
|
return (state.deliveries.some((delivery) => delivery.conversationId === conversationId) ||
|
|
19
19
|
state.reviews.some((review) => review.conversationId === conversationId) ||
|
|
20
|
-
state.integrations.some((integration) => integration.conversationId === conversationId)
|
|
20
|
+
state.integrations.some((integration) => integration.conversationId === conversationId) ||
|
|
21
|
+
state.tasks.some((task) => task.conversationId === conversationId && taskHasImmutableEvidence(task)));
|
|
21
22
|
}
|
|
22
23
|
/** Delete every record scoped to one conversation. Never called for conversations with audit records. */
|
|
23
24
|
export function dropConversationRecords(state, conversationId) {
|
|
@@ -56,7 +57,7 @@ export function trimRoomReceipts(state, roomId, limit = ROOM_RECEIPT_RETENTION)
|
|
|
56
57
|
}
|
|
57
58
|
export function trimConversationHistory(state, roomId, limit = 500) {
|
|
58
59
|
const protectedIds = new Set();
|
|
59
|
-
for (const task of state.tasks.filter((t) => t.roomId === roomId && taskPending(t))) {
|
|
60
|
+
for (const task of state.tasks.filter((t) => t.roomId === roomId && (taskPending(t) || taskHasImmutableEvidence(t)))) {
|
|
60
61
|
protectedIds.add(task.id);
|
|
61
62
|
if (task.rootTaskId)
|
|
62
63
|
protectedIds.add(task.rootTaskId);
|
|
@@ -89,7 +90,16 @@ export function conversationPage(state, conversationId, before) {
|
|
|
89
90
|
if (!messages.length && size > 60 * 1024) {
|
|
90
91
|
message = { ...message, text: message.text.slice(0, 1024) };
|
|
91
92
|
if (task)
|
|
92
|
-
task = {
|
|
93
|
+
task = {
|
|
94
|
+
...task,
|
|
95
|
+
text: task.text.slice(0, 1024),
|
|
96
|
+
report: task.report?.slice(0, 1024),
|
|
97
|
+
handoff: undefined,
|
|
98
|
+
// Full immutable payloads remain on the task; history pages are bounded projections.
|
|
99
|
+
contract: undefined,
|
|
100
|
+
contextManifest: undefined,
|
|
101
|
+
artifact: undefined,
|
|
102
|
+
};
|
|
93
103
|
truncated = true;
|
|
94
104
|
size = Buffer.byteLength(JSON.stringify({ message, task: includeTask ? task : undefined }));
|
|
95
105
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { hashSecret } from "./store.js";
|
|
3
|
+
import { assertDeliveryAuthority, assertNoApplyingIntegration, deriveArtifactSubject } from "./delivery-authority.js";
|
|
4
|
+
import { artifactRefsMatch, deliveryReviewMatches } from "./delivery-subject.js";
|
|
5
|
+
import { hasVerifiedIntegration } from "./integration-verification.js";
|
|
3
6
|
function fail(status, message) {
|
|
4
7
|
throw Object.assign(new Error(message), { status });
|
|
5
8
|
}
|
|
@@ -102,6 +105,7 @@ function append(state, kind, conversationId, key, actor, payload, create) {
|
|
|
102
105
|
t.status === "running" &&
|
|
103
106
|
!t.cancelRequested))
|
|
104
107
|
fail(409, "New records require a running Bot task");
|
|
108
|
+
assertNoApplyingIntegration(state, actor.accountId, state.conversations.find((c) => c.id === conversationId).roomId, conversationId);
|
|
105
109
|
const record = create();
|
|
106
110
|
const history = [...state.deliveries, ...state.reviews].filter((r) => r.conversationId === conversationId);
|
|
107
111
|
if (history.length >= 200 ||
|
|
@@ -117,6 +121,7 @@ export function addDelivery(state, roomId, conversationId, actor, input) {
|
|
|
117
121
|
"sourceBotId",
|
|
118
122
|
"parentTaskId",
|
|
119
123
|
"idempotencyKey",
|
|
124
|
+
"artifactTaskId",
|
|
120
125
|
"repository",
|
|
121
126
|
"baseCommit",
|
|
122
127
|
"commit",
|
|
@@ -156,17 +161,41 @@ export function addDelivery(state, roomId, conversationId, actor, input) {
|
|
|
156
161
|
const limits = body.limitations ?? [];
|
|
157
162
|
if (!Array.isArray(limits) || limits.length > 32)
|
|
158
163
|
fail(400, "Invalid limitations");
|
|
164
|
+
let subject;
|
|
165
|
+
if (body.artifactTaskId !== undefined) {
|
|
166
|
+
if (body.repository !== undefined || body.baseCommit !== undefined || body.commit !== undefined)
|
|
167
|
+
fail(400, "Artifact delivery derives repository and baseline; commit is not an artifact tree");
|
|
168
|
+
const artifactTaskId = text(body.artifactTaskId, 128, "artifactTaskId");
|
|
169
|
+
const task = state.tasks.find((t) => t.id === artifactTaskId &&
|
|
170
|
+
t.accountId === actor.accountId &&
|
|
171
|
+
t.roomId === roomId &&
|
|
172
|
+
t.conversationId === conversationId &&
|
|
173
|
+
t.botId === actor.bot.id &&
|
|
174
|
+
t.deviceId === actor.bot.deviceId &&
|
|
175
|
+
t.botRevision === actor.bot.revision);
|
|
176
|
+
if (!task)
|
|
177
|
+
fail(409, "Artifact task must belong to the same author, device, revision and conversation");
|
|
178
|
+
const artifactRef = deriveArtifactSubject(state, task);
|
|
179
|
+
subject = {
|
|
180
|
+
artifactRef,
|
|
181
|
+
repository: artifactRef.repositoryId,
|
|
182
|
+
baseCommit: artifactRef.baselineCommit,
|
|
183
|
+
acceptanceCriteria: [...(task.contract.acceptanceCriteria ?? [])],
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
else
|
|
187
|
+
subject = { repository: repository(body.repository), baseCommit: sha(body.baseCommit), commit: sha(body.commit) };
|
|
159
188
|
const payload = {
|
|
160
189
|
taskId: text(body.parentTaskId, 128, "parentTaskId"),
|
|
161
|
-
|
|
162
|
-
baseCommit: sha(body.baseCommit),
|
|
163
|
-
commit: sha(body.commit),
|
|
190
|
+
...subject,
|
|
164
191
|
...(body.branch === undefined ? {} : { branch: text(body.branch, 256, "branch") }),
|
|
165
192
|
summary: text(body.summary, 8192, "summary"),
|
|
166
193
|
checks,
|
|
167
194
|
limitations: limits.map((s) => text(s, 2048, "limitation")),
|
|
168
195
|
};
|
|
169
|
-
|
|
196
|
+
// The request budget covers author input; sealed Hub-derived criteria use the existing history budget.
|
|
197
|
+
const { acceptanceCriteria: _criteria, artifactRef: _artifactRef, ...requestPayload } = payload;
|
|
198
|
+
if (Buffer.byteLength(JSON.stringify(requestPayload)) > 24 * 1024)
|
|
170
199
|
fail(413, "Delivery budget exceeded");
|
|
171
200
|
return append(state, "delivery", conversationId, key, actor, payload, () => ({
|
|
172
201
|
...payload,
|
|
@@ -185,6 +214,10 @@ export function addReview(state, roomId, conversationId, actor, input) {
|
|
|
185
214
|
"idempotencyKey",
|
|
186
215
|
"deliveryId",
|
|
187
216
|
"commit",
|
|
217
|
+
"artifactDigest",
|
|
218
|
+
"integrationId",
|
|
219
|
+
"verificationDigest",
|
|
220
|
+
"criteriaResults",
|
|
188
221
|
"verdict",
|
|
189
222
|
"summary",
|
|
190
223
|
]);
|
|
@@ -193,22 +226,93 @@ export function addReview(state, roomId, conversationId, actor, input) {
|
|
|
193
226
|
fail(400, "Human review cannot claim Bot identity");
|
|
194
227
|
const key = text(body.idempotencyKey, 128, "idempotencyKey");
|
|
195
228
|
const deliveryId = text(body.deliveryId, 128, "deliveryId");
|
|
196
|
-
const commit = sha(body.commit);
|
|
197
229
|
if (!["accepted", "changes_requested"].includes(body.verdict))
|
|
198
230
|
fail(400, "Invalid verdict");
|
|
231
|
+
const delivery = state.deliveries.find((d) => d.id === deliveryId &&
|
|
232
|
+
d.conversationId === conversationId &&
|
|
233
|
+
d.roomId === roomId &&
|
|
234
|
+
d.accountId === actor.accountId);
|
|
235
|
+
if (!delivery)
|
|
236
|
+
fail(400, "Delivery missing");
|
|
237
|
+
const task = assertDeliveryAuthority(state, delivery);
|
|
238
|
+
let subject;
|
|
239
|
+
if (delivery.artifactRef) {
|
|
240
|
+
if (body.commit !== undefined || body.artifactDigest !== delivery.artifactRef.artifactDigest)
|
|
241
|
+
fail(400, "Review artifact digest must match delivery");
|
|
242
|
+
let criteriaResults;
|
|
243
|
+
if (body.criteriaResults !== undefined) {
|
|
244
|
+
if (!Array.isArray(body.criteriaResults) || body.criteriaResults.length > 64)
|
|
245
|
+
fail(400, "Invalid criteria results");
|
|
246
|
+
criteriaResults = body.criteriaResults.map((value) => {
|
|
247
|
+
const item = object(value, ["criterionIndex", "verdict", "evidence"]);
|
|
248
|
+
if (!Number.isSafeInteger(item.criterionIndex) ||
|
|
249
|
+
item.criterionIndex < 0 ||
|
|
250
|
+
item.criterionIndex >= (task.contract.acceptanceCriteria ?? []).length ||
|
|
251
|
+
!["met", "not_met"].includes(item.verdict))
|
|
252
|
+
fail(400, "Invalid criterion result");
|
|
253
|
+
return {
|
|
254
|
+
criterionIndex: item.criterionIndex,
|
|
255
|
+
verdict: item.verdict,
|
|
256
|
+
evidence: text(item.evidence, 2000, "criterion evidence"),
|
|
257
|
+
};
|
|
258
|
+
});
|
|
259
|
+
if (new Set(criteriaResults.map((c) => c.criterionIndex)).size !== criteriaResults.length)
|
|
260
|
+
fail(400, "Duplicate criterion result");
|
|
261
|
+
}
|
|
262
|
+
const integrationId = body.integrationId === undefined ? undefined : text(body.integrationId, 128, "integrationId");
|
|
263
|
+
const verificationDigest = body.verificationDigest === undefined ? undefined : text(body.verificationDigest, 64, "verificationDigest");
|
|
264
|
+
if (body.verdict === "accepted") {
|
|
265
|
+
const integration = state.integrations.find((i) => i.id === integrationId &&
|
|
266
|
+
i.accountId === actor.accountId &&
|
|
267
|
+
i.roomId === roomId &&
|
|
268
|
+
i.conversationId === conversationId &&
|
|
269
|
+
i.deliveryId === deliveryId);
|
|
270
|
+
const target = integration &&
|
|
271
|
+
state.bots.find((b) => b.id === integration.targetBotId &&
|
|
272
|
+
b.accountId === actor.accountId &&
|
|
273
|
+
b.deviceId === integration.targetDeviceId &&
|
|
274
|
+
b.revision === integration.targetBotRevision &&
|
|
275
|
+
b.enabled);
|
|
276
|
+
if (!integration ||
|
|
277
|
+
!target ||
|
|
278
|
+
!state.rooms.some((r) => r.id === roomId && r.accountId === actor.accountId && r.botIds.includes(target.id)) ||
|
|
279
|
+
!state.devices.some((d) => d.id === target.deviceId && d.accountId === actor.accountId) ||
|
|
280
|
+
!["verified", "applying", "applied"].includes(integration.status) ||
|
|
281
|
+
!hasVerifiedIntegration(integration) ||
|
|
282
|
+
!artifactRefsMatch(delivery.artifactRef, integration.artifactRef) ||
|
|
283
|
+
integration.verification.digest !== verificationDigest)
|
|
284
|
+
fail(409, "Accepted artifact review requires matching successful verification");
|
|
285
|
+
if (!criteriaResults ||
|
|
286
|
+
criteriaResults.length !== (task.contract.acceptanceCriteria ?? []).length ||
|
|
287
|
+
criteriaResults.some((c) => c.verdict !== "met"))
|
|
288
|
+
fail(400, "Accepted review must cover every sealed criterion");
|
|
289
|
+
}
|
|
290
|
+
subject = {
|
|
291
|
+
artifactRef: delivery.artifactRef,
|
|
292
|
+
artifactDigest: delivery.artifactRef.artifactDigest,
|
|
293
|
+
integrationId,
|
|
294
|
+
verificationDigest,
|
|
295
|
+
criteriaResults,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
if (body.artifactDigest !== undefined ||
|
|
300
|
+
body.integrationId !== undefined ||
|
|
301
|
+
body.verificationDigest !== undefined ||
|
|
302
|
+
body.criteriaResults !== undefined)
|
|
303
|
+
fail(400, "Legacy review requires commit only");
|
|
304
|
+
const commit = sha(body.commit);
|
|
305
|
+
if (delivery.commit !== commit)
|
|
306
|
+
fail(400, "Delivery and commit must match");
|
|
307
|
+
subject = { commit };
|
|
308
|
+
}
|
|
199
309
|
const payload = {
|
|
200
310
|
deliveryId,
|
|
201
|
-
|
|
311
|
+
...subject,
|
|
202
312
|
verdict: body.verdict,
|
|
203
313
|
summary: text(body.summary, 8192, "summary"),
|
|
204
314
|
...(actor.bot ? { taskId: text(body.parentTaskId, 128, "parentTaskId") } : {}),
|
|
205
315
|
};
|
|
206
|
-
const delivery = state.deliveries.find((d) => d.id === deliveryId &&
|
|
207
|
-
d.conversationId === conversationId &&
|
|
208
|
-
d.roomId === roomId &&
|
|
209
|
-
d.accountId === actor.accountId);
|
|
210
|
-
if (!delivery || delivery.commit !== commit)
|
|
211
|
-
fail(400, "Delivery and commit must match");
|
|
212
316
|
if (actor.bot?.id === delivery.botId)
|
|
213
317
|
fail(403, "Self review is forbidden");
|
|
214
318
|
return append(state, "review", conversationId, key, actor, payload, () => {
|
|
@@ -220,7 +324,7 @@ export function addReview(state, roomId, conversationId, actor, input) {
|
|
|
220
324
|
roomId,
|
|
221
325
|
conversationId,
|
|
222
326
|
deliveryId,
|
|
223
|
-
|
|
327
|
+
...subject,
|
|
224
328
|
verdict: payload.verdict,
|
|
225
329
|
summary: payload.summary,
|
|
226
330
|
reviewer: actor.bot ? { type: "bot", id: actor.bot.id } : { type: "human", id: actor.accountId },
|
|
@@ -270,8 +374,9 @@ export function getAcceptedDeliveryForIntegration(state, conversationId, deliver
|
|
|
270
374
|
}
|
|
271
375
|
const reviews = state.reviews.filter((r) => r.deliveryId === deliveryId);
|
|
272
376
|
const latestReview = reviews.at(-1);
|
|
273
|
-
|
|
274
|
-
|
|
377
|
+
assertDeliveryAuthority(state, latest);
|
|
378
|
+
if (!latestReview || latestReview.verdict !== "accepted" || !deliveryReviewMatches(latest, latestReview)) {
|
|
379
|
+
fail(400, "Delivery has no accepted review for its subject");
|
|
275
380
|
}
|
|
276
381
|
return { delivery: latest, review: latestReview };
|
|
277
382
|
}
|