@bf-meishijian/aip 0.0.33 → 0.0.35
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/coding-run-manager.d.ts +6 -1
- package/dist/coding-run-manager.d.ts.map +1 -1
- package/dist/coding-run-manager.js +66 -20
- package/dist/coding-run-manager.js.map +1 -1
- package/dist/command-executor.d.ts +9 -0
- package/dist/command-executor.d.ts.map +1 -0
- package/dist/command-executor.js +222 -0
- package/dist/command-executor.js.map +1 -0
- package/dist/daemon.d.ts +1 -8
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +37 -242
- package/dist/daemon.js.map +1 -1
- package/dist/diagnostic-log.d.ts +1 -0
- package/dist/diagnostic-log.d.ts.map +1 -1
- package/dist/diagnostic-log.js.map +1 -1
- package/dist/diagnostics.d.ts +1 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js +3 -1
- package/dist/diagnostics.js.map +1 -1
- package/dist/execution-process-observer.d.ts +19 -0
- package/dist/execution-process-observer.d.ts.map +1 -0
- package/dist/execution-process-observer.js +35 -0
- package/dist/execution-process-observer.js.map +1 -0
- package/dist/execution-process-tree.d.ts +32 -0
- package/dist/execution-process-tree.d.ts.map +1 -0
- package/dist/execution-process-tree.js +288 -0
- package/dist/execution-process-tree.js.map +1 -0
- package/dist/execution-process.d.ts +59 -0
- package/dist/execution-process.d.ts.map +1 -0
- package/dist/execution-process.js +112 -0
- package/dist/execution-process.js.map +1 -0
- package/dist/execution-receipts.d.ts +12 -0
- package/dist/execution-receipts.d.ts.map +1 -0
- package/dist/execution-receipts.js +89 -0
- package/dist/execution-receipts.js.map +1 -0
- package/dist/execution-supervisor.d.ts +25 -0
- package/dist/execution-supervisor.d.ts.map +1 -0
- package/dist/execution-supervisor.js +480 -0
- package/dist/execution-supervisor.js.map +1 -0
- package/dist/execution-worker.d.ts +42 -0
- package/dist/execution-worker.d.ts.map +1 -0
- package/dist/execution-worker.js +165 -0
- package/dist/execution-worker.js.map +1 -0
- package/dist/general-run-client.d.ts.map +1 -1
- package/dist/general-run-manager.d.ts +13 -0
- package/dist/general-run-manager.d.ts.map +1 -1
- package/dist/general-run-manager.js +35 -7
- package/dist/general-run-manager.js.map +1 -1
- package/dist/general-run-supervisor.d.ts +12 -0
- package/dist/general-run-supervisor.d.ts.map +1 -0
- package/dist/general-run-supervisor.js +150 -0
- package/dist/general-run-supervisor.js.map +1 -0
- package/dist/git-process.d.ts.map +1 -1
- package/dist/git-process.js +30 -124
- package/dist/git-process.js.map +1 -1
- package/dist/host-status.d.ts +12 -8
- package/dist/host-status.d.ts.map +1 -1
- package/dist/host-status.js +98 -60
- package/dist/host-status.js.map +1 -1
- package/dist/host-tools.d.ts +2 -2
- package/dist/host-tools.d.ts.map +1 -1
- package/dist/host-tools.js +14 -7
- package/dist/host-tools.js.map +1 -1
- package/dist/live-employee.d.ts.map +1 -1
- package/dist/live-employee.js +15 -11
- package/dist/live-employee.js.map +1 -1
- package/dist/local-mcp.d.ts +1 -1
- package/dist/local-mcp.d.ts.map +1 -1
- package/dist/local-mcp.js +2 -2
- package/dist/local-mcp.js.map +1 -1
- package/dist/managed-process.d.ts +21 -0
- package/dist/managed-process.d.ts.map +1 -0
- package/dist/managed-process.js +119 -0
- package/dist/managed-process.js.map +1 -0
- package/dist/operation-context.d.ts +31 -0
- package/dist/operation-context.d.ts.map +1 -0
- package/dist/operation-context.js +166 -0
- package/dist/operation-context.js.map +1 -0
- package/dist/pi-model-service.d.ts.map +1 -1
- package/dist/platform-client.d.ts +10 -2
- package/dist/platform-client.d.ts.map +1 -1
- package/dist/platform-client.js +7 -2
- package/dist/platform-client.js.map +1 -1
- package/dist/qa-project-checkout.d.ts.map +1 -1
- package/dist/qa-project-checkout.js +27 -15
- package/dist/qa-project-checkout.js.map +1 -1
- package/dist/qa-session-manager.d.ts +6 -3
- package/dist/qa-session-manager.d.ts.map +1 -1
- package/dist/qa-session-manager.js +58 -14
- package/dist/qa-session-manager.js.map +1 -1
- package/dist/stage-delivery.js +57 -57
- package/dist/state.d.ts +2 -2
- package/dist/state.js +2 -2
- package/dist/test-executor.d.ts +6 -9
- package/dist/test-executor.d.ts.map +1 -1
- package/dist/test-executor.js +56 -52
- package/dist/test-executor.js.map +1 -1
- package/dist/test-run-manager.d.ts +11 -1
- package/dist/test-run-manager.d.ts.map +1 -1
- package/dist/test-run-manager.js +61 -2
- package/dist/test-run-manager.js.map +1 -1
- package/dist/workflow-guidance.d.ts +2 -0
- package/dist/workflow-guidance.d.ts.map +1 -0
- package/dist/workflow-guidance.js +157 -0
- package/dist/workflow-guidance.js.map +1 -0
- package/dist/workspace-gc.d.ts.map +1 -1
- package/dist/workspace-gc.js +86 -1
- package/dist/workspace-gc.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { inspectWorkspaceInitialization, redactHostText, } from "./coding-run-manager.js";
|
|
2
|
+
import { diagnosticErrorFields } from "./diagnostic-log.js";
|
|
3
|
+
import { runDiagnostics } from "./diagnostics.js";
|
|
4
|
+
import { logHostEvent } from "./host-log.js";
|
|
5
|
+
import { HostStatusReporter } from "./host-status.js";
|
|
6
|
+
import { branchMissingFailure, localIntakeFailure } from "./local-handoff-workspace.js";
|
|
7
|
+
import { callLocalMcp, discoverLocalMcp } from "./local-mcp.js";
|
|
8
|
+
import { paths } from "./paths.js";
|
|
9
|
+
import { isDefaultModelValid } from "./pi-model-service.js";
|
|
10
|
+
import { PlatformClientError } from "./platform-client.js";
|
|
11
|
+
export async function executeCommand(client, pi, codingRuns, host, command, testRuns, qaSessions, statusReporter = new HostStatusReporter(client, pi, host), signal) {
|
|
12
|
+
let result = {};
|
|
13
|
+
let reportingSuccess = false;
|
|
14
|
+
const context = {
|
|
15
|
+
hostId: host.hostId,
|
|
16
|
+
commandId: command.id,
|
|
17
|
+
kind: command.kind,
|
|
18
|
+
runId: command.run?.runId,
|
|
19
|
+
};
|
|
20
|
+
const startedAt = Date.now();
|
|
21
|
+
let diagnosticStage = "VERIFY_AND_COLLECT_STATUS";
|
|
22
|
+
logHostEvent("command_started", context);
|
|
23
|
+
try {
|
|
24
|
+
signal?.throwIfAborted();
|
|
25
|
+
if (command.inputRef) {
|
|
26
|
+
const input = await client.commandInput(command.inputRef, {
|
|
27
|
+
hostId: host.hostId,
|
|
28
|
+
generation: host.generation,
|
|
29
|
+
});
|
|
30
|
+
command = { ...command, ...input };
|
|
31
|
+
context.runId = command.run?.runId;
|
|
32
|
+
logHostEvent("command_input_loaded", context);
|
|
33
|
+
}
|
|
34
|
+
signal?.throwIfAborted();
|
|
35
|
+
let resultCode = "COMMAND_SUCCEEDED";
|
|
36
|
+
if (command.kind === "PROVIDER_LOGIN" && command.providerId) {
|
|
37
|
+
resultCode = (await pi.login(command.providerId, "remote")).code;
|
|
38
|
+
await statusReporter.report();
|
|
39
|
+
result = { providerId: command.providerId, phase: "COMPLETED" };
|
|
40
|
+
}
|
|
41
|
+
else if (command.kind === "REFRESH_MODELS") {
|
|
42
|
+
await statusReporter.report();
|
|
43
|
+
resultCode = "MODEL_CATALOG_REFRESHED";
|
|
44
|
+
}
|
|
45
|
+
else if (command.kind === "RUN_DIAGNOSTICS") {
|
|
46
|
+
const { verification, local, toolChecks } = await statusReporter.report(true, command.workspaceId);
|
|
47
|
+
signal?.throwIfAborted();
|
|
48
|
+
if (!verification || !toolChecks)
|
|
49
|
+
throw new Error("HOST_TOOL_CONFIGURATION_UNAVAILABLE");
|
|
50
|
+
diagnosticStage = "REPORT_STATUS";
|
|
51
|
+
resultCode = "DIAGNOSTICS_COMPLETED";
|
|
52
|
+
diagnosticStage = "RUN_CHECKS";
|
|
53
|
+
result = {
|
|
54
|
+
checks: await runDiagnostics({
|
|
55
|
+
platformReachable: true,
|
|
56
|
+
deviceCredentialValid: verification.deviceCredentialValid,
|
|
57
|
+
generationValid: verification.generationValid,
|
|
58
|
+
defaultModelValid: isDefaultModelValid(verification.defaultRunConfig, local.models),
|
|
59
|
+
providerReady: local.providers.some((state) => state.status === "READY"),
|
|
60
|
+
shell: verification.shell,
|
|
61
|
+
toolChecks,
|
|
62
|
+
...(signal ? { signal } : {}),
|
|
63
|
+
runtimeVerification: "installed-package",
|
|
64
|
+
logContext: {
|
|
65
|
+
source: "RUN_DIAGNOSTICS",
|
|
66
|
+
hostId: host.hostId,
|
|
67
|
+
generation: host.generation,
|
|
68
|
+
commandId: command.id,
|
|
69
|
+
...(command.workspaceId ? { workspaceId: command.workspaceId } : {}),
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
else if (command.kind === "MCP_DISCOVER") {
|
|
75
|
+
if (!command.mcp)
|
|
76
|
+
throw new Error("MCP_CONFIGURATION_MISSING");
|
|
77
|
+
result = { mcpTools: await discoverLocalMcp(command.mcp, signal) };
|
|
78
|
+
resultCode = "MCP_TOOLS_DISCOVERED";
|
|
79
|
+
}
|
|
80
|
+
else if (command.kind === "MCP_CALL") {
|
|
81
|
+
if (!command.mcpCall)
|
|
82
|
+
throw new Error("MCP_CONFIGURATION_MISSING");
|
|
83
|
+
const remaining = Date.parse(command.expiresAt) - Date.now();
|
|
84
|
+
if (!Number.isFinite(remaining) || remaining <= 0)
|
|
85
|
+
throw new Error("MCP_COMMAND_EXPIRED");
|
|
86
|
+
result = {
|
|
87
|
+
mcpResult: await callLocalMcp(command.mcpCall, signal
|
|
88
|
+
? AbortSignal.any([signal, AbortSignal.timeout(remaining)])
|
|
89
|
+
: AbortSignal.timeout(remaining)),
|
|
90
|
+
};
|
|
91
|
+
resultCode = "MCP_TOOL_CALLED";
|
|
92
|
+
}
|
|
93
|
+
else if (command.kind.startsWith("TEST_SESSION_")) {
|
|
94
|
+
if (!qaSessions)
|
|
95
|
+
throw new Error("QA_SESSION_UNAVAILABLE");
|
|
96
|
+
await qaSessions.execute(client, { hostId: host.hostId, generation: host.generation }, command);
|
|
97
|
+
result = { phase: "ACCEPTED" };
|
|
98
|
+
resultCode = "QA_SESSION_COMMAND_ACCEPTED";
|
|
99
|
+
}
|
|
100
|
+
else if (command.kind === "TEST_RUN" ||
|
|
101
|
+
command.kind === "TEST_RETRANSMIT" ||
|
|
102
|
+
command.kind === "TEST_CATALOG") {
|
|
103
|
+
if (!testRuns)
|
|
104
|
+
throw new Error("QA_EXECUTOR_UNAVAILABLE");
|
|
105
|
+
await testRuns.execute(client, { hostId: host.hostId, generation: host.generation }, command);
|
|
106
|
+
result = { phase: "ACCEPTED" };
|
|
107
|
+
resultCode = "TEST_COMMAND_ACCEPTED";
|
|
108
|
+
}
|
|
109
|
+
else if (command.kind.startsWith("CODING_RUN_")) {
|
|
110
|
+
const outcome = await codingRuns.execute(client, host, command);
|
|
111
|
+
resultCode = "CODING_RUN_COMMAND_ACCEPTED";
|
|
112
|
+
result =
|
|
113
|
+
command.run?.action === "CHECK_RESOURCES"
|
|
114
|
+
? { ...outcome }
|
|
115
|
+
: { phase: "COMPLETED", ...outcome };
|
|
116
|
+
}
|
|
117
|
+
else
|
|
118
|
+
throw new Error("UNKNOWN_COMMAND");
|
|
119
|
+
signal?.throwIfAborted();
|
|
120
|
+
logHostEvent("command_executed", { ...context, durationMs: Date.now() - startedAt });
|
|
121
|
+
reportingSuccess = true;
|
|
122
|
+
diagnosticStage = "REPORT_RESULT";
|
|
123
|
+
await client.completeCommand(command.id, {
|
|
124
|
+
hostId: host.hostId,
|
|
125
|
+
generation: host.generation,
|
|
126
|
+
status: "SUCCEEDED",
|
|
127
|
+
resultCode,
|
|
128
|
+
result,
|
|
129
|
+
});
|
|
130
|
+
logHostEvent("command_completed", {
|
|
131
|
+
...context,
|
|
132
|
+
resultCode,
|
|
133
|
+
durationMs: Date.now() - startedAt,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
if (command.kind === "RUN_DIAGNOSTICS")
|
|
138
|
+
logHostEvent(reportingSuccess ? "diagnostic_result_report_failed" : "diagnostic_execution_failed", {
|
|
139
|
+
...context,
|
|
140
|
+
stage: diagnosticStage,
|
|
141
|
+
...diagnosticErrorFields(error),
|
|
142
|
+
...(error instanceof PlatformClientError
|
|
143
|
+
? {
|
|
144
|
+
httpStatus: error.status,
|
|
145
|
+
errorCode: /^[A-Z0-9_]{1,100}$/u.test(error.code)
|
|
146
|
+
? error.code
|
|
147
|
+
: "UNKNOWN_API_ERROR",
|
|
148
|
+
}
|
|
149
|
+
: {}),
|
|
150
|
+
durationMs: Date.now() - startedAt,
|
|
151
|
+
});
|
|
152
|
+
// 执行成功、回执失败属于结果未知,不能反写为执行失败或自动重放。
|
|
153
|
+
if (reportingSuccess || signal?.aborted)
|
|
154
|
+
throw error;
|
|
155
|
+
const safeError = redactHostText(error instanceof Error ? error.message : String(error), [
|
|
156
|
+
paths().root,
|
|
157
|
+
]);
|
|
158
|
+
logHostEvent("command_failed", {
|
|
159
|
+
...context,
|
|
160
|
+
error: safeError,
|
|
161
|
+
durationMs: Date.now() - startedAt,
|
|
162
|
+
});
|
|
163
|
+
const imageReadFailed = error instanceof PlatformClientError && error.code === "IMAGE_ATTACHMENT_READ_FAILED";
|
|
164
|
+
const intakeFailure = localIntakeFailure(error);
|
|
165
|
+
const branchMissing = branchMissingFailure(error);
|
|
166
|
+
const resultCode = intakeFailure?.code ??
|
|
167
|
+
(imageReadFailed
|
|
168
|
+
? "IMAGE_ATTACHMENT_READ_FAILED"
|
|
169
|
+
: error instanceof Error && /^[A-Z0-9_]+$/u.test(error.message)
|
|
170
|
+
? error.message
|
|
171
|
+
: (branchMissing?.code ?? "COMMAND_FAILED"));
|
|
172
|
+
const workspaceInitialization = !intakeFailure &&
|
|
173
|
+
command.run?.runInput &&
|
|
174
|
+
["CODING_RUN_START", "CODING_RUN_RESUME"].includes(command.kind)
|
|
175
|
+
? await inspectWorkspaceInitialization(command.run.runId, command.run.runInput)
|
|
176
|
+
: undefined;
|
|
177
|
+
const completeFailure = () => client.completeCommand(command.id, {
|
|
178
|
+
hostId: host.hostId,
|
|
179
|
+
generation: host.generation,
|
|
180
|
+
status: "FAILED",
|
|
181
|
+
resultCode,
|
|
182
|
+
result: workspaceInitialization
|
|
183
|
+
? { workspaceInitialization }
|
|
184
|
+
: intakeFailure
|
|
185
|
+
? { message: intakeFailure.message }
|
|
186
|
+
: command.run?.action === "RECALL_QUEUE"
|
|
187
|
+
? result
|
|
188
|
+
: {},
|
|
189
|
+
});
|
|
190
|
+
// 可恢复图片输入必须先落下失败命令,再让用户看到可恢复的 Run。
|
|
191
|
+
if (imageReadFailed)
|
|
192
|
+
await completeFailure();
|
|
193
|
+
const codingRun = command.kind.startsWith("CODING_RUN_") ? command.run : undefined;
|
|
194
|
+
if (codingRun && !["STOP", "RECALL_QUEUE", "CHECK_RESOURCES"].includes(codingRun.action)) {
|
|
195
|
+
await client
|
|
196
|
+
.reportCodingTerminal(codingRun.runId, {
|
|
197
|
+
hostId: host.hostId,
|
|
198
|
+
generation: host.generation,
|
|
199
|
+
turnId: codingRun.turnId,
|
|
200
|
+
kind: "FAILED",
|
|
201
|
+
summary: intakeFailure?.message ??
|
|
202
|
+
branchMissing?.message ??
|
|
203
|
+
(resultCode === "IMAGE_ATTACHMENT_READ_FAILED"
|
|
204
|
+
? "图片读取失败,未将图片交给模型,请检查附件后重试"
|
|
205
|
+
: resultCode === "MODEL_IMAGES_UNSUPPORTED"
|
|
206
|
+
? "当前模型不支持图片,请选择支持图片的模型"
|
|
207
|
+
: "Local Coding Runtime 无法执行本次命令"),
|
|
208
|
+
knownIssues: "",
|
|
209
|
+
failureCode: resultCode,
|
|
210
|
+
projectFacts: [],
|
|
211
|
+
testFacts: [],
|
|
212
|
+
})
|
|
213
|
+
.catch((error) => logHostEvent("terminal_report_failed", { ...context, error: safeHostError(error) }));
|
|
214
|
+
}
|
|
215
|
+
if (!imageReadFailed)
|
|
216
|
+
await completeFailure();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function safeHostError(error) {
|
|
220
|
+
return redactHostText(error instanceof Error ? error.message : String(error), [paths().root]);
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=command-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-executor.js","sourceRoot":"","sources":["../src/command-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,8BAA8B,EAC9B,cAAc,GACf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAwB,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAkB,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAK3E,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAAsB,EACtB,EAA2C,EAC3C,UAA4B,EAC5B,IAA4D,EAC5D,OAAiF,EACjF,QAAyB,EACzB,UAA6B,EAC7B,iBAAqD,IAAI,kBAAkB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,CAAC,EAC7F,MAAoB;IAEpB,IAAI,MAAM,GAA4B,EAAE,CAAC;IACzC,IAAI,gBAAgB,GAAG,KAAK,CAAC;IAC7B,MAAM,OAAO,GAAG;QACd,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,SAAS,EAAE,OAAO,CAAC,EAAE;QACrB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,KAAK,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK;KAC1B,CAAC;IACF,MAAM,S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;YAAE,MAAM,eAAe,EAAE,CAAC;IAChD,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,cAAc,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AAChG,CAAC"}
|
package/dist/daemon.d.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import "./runtime-environment.js";
|
|
3
|
-
import { CodingRunManager } from "./coding-run-manager.js";
|
|
4
|
-
import { HostStatusReporter } from "./host-status.js";
|
|
5
|
-
import { createPiModelService } from "./pi-model-service.js";
|
|
6
|
-
import { PlatformClient } from "./platform-client.js";
|
|
7
|
-
import { QaSessionManager } from "./qa-session-manager.js";
|
|
8
|
-
import { readHostState } from "./state.js";
|
|
9
|
-
import { TestRunManager } from "./test-run-manager.js";
|
|
10
3
|
export declare function runDaemon(options?: {
|
|
11
4
|
once?: boolean;
|
|
12
5
|
}): Promise<void>;
|
|
13
6
|
export declare function runtimePath(currentPath?: string, nodeExecutable?: string): string;
|
|
14
|
-
export
|
|
7
|
+
export { executeCommand } from "./command-executor.js";
|
|
15
8
|
//# sourceMappingURL=daemon.d.ts.map
|
package/dist/daemon.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"daemon.d.ts","sourceRoot":"","sources":["../src/daemon.ts"],"names":[],"mappings":";AACA,OAAO,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"daemon.d.ts","sourceRoot":"","sources":["../src/daemon.ts"],"names":[],"mappings":";AACA,OAAO,0BAA0B,CAAC;AA0BlC,wBAAsB,SAAS,CAAC,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAO,iBA2N/D;AAED,wBAAgB,WAAW,CAAC,WAAW,SAAK,EAAE,cAAc,SAAmB,UAK9E;AAkBD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/daemon.js
CHANGED
|
@@ -4,27 +4,21 @@ import { randomUUID } from "node:crypto";
|
|
|
4
4
|
import { realpathSync, statSync } from "node:fs";
|
|
5
5
|
import { delimiter, dirname } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
|
-
import {
|
|
7
|
+
import { redactHostText } from "./host-log.js";
|
|
8
8
|
import { CommandWakeup, commandPollMilliseconds, HostCommandNotifications, } from "./command-wakeup.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { GeneralRunClient } from "./general-run-client.js";
|
|
12
|
-
import { GeneralRunManager } from "./general-run-manager.js";
|
|
9
|
+
import { GeneralRunSupervisor } from "./general-run-supervisor.js";
|
|
10
|
+
import { ExecutionSupervisor } from "./execution-supervisor.js";
|
|
13
11
|
import { logHostEvent } from "./host-log.js";
|
|
14
12
|
import { HostStatusReporter } from "./host-status.js";
|
|
15
13
|
import { lockHostExecution } from "./host-update.js";
|
|
16
|
-
import { branchMissingFailure, localIntakeFailure } from "./local-handoff-workspace.js";
|
|
17
|
-
import { callLocalMcp, discoverLocalMcp } from "./local-mcp.js";
|
|
18
14
|
import { activeProfile, aipCommand, paths } from "./paths.js";
|
|
19
|
-
import { createPiModelService
|
|
15
|
+
import { createPiModelService } from "./pi-model-service.js";
|
|
20
16
|
import { PlatformClient, PlatformClientError } from "./platform-client.js";
|
|
21
|
-
import { QaSessionManager } from "./qa-session-manager.js";
|
|
22
17
|
import { cleanupRuntimeVersions } from "./runtime-cleanup.js";
|
|
23
18
|
import { installSearchTools } from "./runtime-search-tools.js";
|
|
24
19
|
import { writeSecureJson } from "./secure-json.js";
|
|
25
20
|
import { hostIdentity, readDeviceAuth, readHostState, writeHostState } from "./state.js";
|
|
26
21
|
import { StorageMaintenance } from "./storage-maintenance.js";
|
|
27
|
-
import { TestRunManager } from "./test-run-manager.js";
|
|
28
22
|
import { collectWorkspaceGarbage } from "./workspace-gc.js";
|
|
29
23
|
export async function runDaemon(options = {}) {
|
|
30
24
|
process.env.AIP_PROFILE = activeProfile();
|
|
@@ -42,11 +36,9 @@ export async function runDaemon(options = {}) {
|
|
|
42
36
|
startedAt: new Date().toISOString(),
|
|
43
37
|
});
|
|
44
38
|
const pi = createPiModelService();
|
|
45
|
-
const codingRuns = new CodingRunManager(pi);
|
|
46
|
-
const testRuns = new TestRunManager();
|
|
47
|
-
const qaSessions = new QaSessionManager(pi);
|
|
48
|
-
const generalRuns = new GeneralRunManager(pi);
|
|
49
39
|
const wakeup = new CommandWakeup();
|
|
40
|
+
const executions = new ExecutionSupervisor(bootId, () => wakeup.notify());
|
|
41
|
+
const generalRuns = new GeneralRunSupervisor(() => wakeup.notify());
|
|
50
42
|
let notifications;
|
|
51
43
|
let notificationIdentity;
|
|
52
44
|
let stopping = false;
|
|
@@ -87,11 +79,7 @@ export async function runDaemon(options = {}) {
|
|
|
87
79
|
const client = new PlatformClient(device.platformUrl, device.deviceToken);
|
|
88
80
|
if (!options.once) {
|
|
89
81
|
// 持 execution.lock 同步扫描;期间不领取命令,manager 的既有执行必须全部结束。
|
|
90
|
-
await storageMaintenance.runIfDue(activeCommands.size > 0 ||
|
|
91
|
-
codingRuns.isBusy() ||
|
|
92
|
-
testRuns.isBusy() ||
|
|
93
|
-
qaSessions.isBusy() ||
|
|
94
|
-
generalRuns.isBusy(), async () => {
|
|
82
|
+
await storageMaintenance.runIfDue(activeCommands.size > 0 || executions.isBusy() || generalRuns.isBusy(), async () => {
|
|
95
83
|
await cleanupRuntimeVersions();
|
|
96
84
|
await collectWorkspaceGarbage(client, host);
|
|
97
85
|
});
|
|
@@ -127,10 +115,21 @@ export async function runDaemon(options = {}) {
|
|
|
127
115
|
generation: host.generation,
|
|
128
116
|
bootId,
|
|
129
117
|
maxConcurrentCommands: 4,
|
|
118
|
+
executionControlVersion: 1,
|
|
130
119
|
});
|
|
120
|
+
for (const control of heartbeat.controlCommands ?? []) {
|
|
121
|
+
// Dispatch without waiting for either a normal slot or the target worker.
|
|
122
|
+
void executions.control(device, host, control).catch((error) => {
|
|
123
|
+
logHostEvent("execution_control_result_unknown", {
|
|
124
|
+
commandId: control.id,
|
|
125
|
+
error: safeHostError(error),
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
executions.reconcile(device, host);
|
|
131
130
|
if (heartbeat.command) {
|
|
132
131
|
const command = heartbeat.command;
|
|
133
|
-
const task =
|
|
132
|
+
const task = executions.execute(device, host, heartbeat.command, statusReporter);
|
|
134
133
|
if (options.once)
|
|
135
134
|
await task;
|
|
136
135
|
else {
|
|
@@ -161,9 +160,18 @@ export async function runDaemon(options = {}) {
|
|
|
161
160
|
}
|
|
162
161
|
const inputs = statusInputs(host);
|
|
163
162
|
const checkTools = statusReporter.toolsDue(heartbeat.toolConfigurationRevision);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
163
|
+
const workspaceChecks = (heartbeat.workspaceToolConfigurationRevisions ?? []).filter(({ workspaceId, toolConfigurationRevision }) => statusReporter.toolsDue(toolConfigurationRevision, workspaceId));
|
|
164
|
+
const reportBase = inputs !== reportedInputs || statusReporter.statusDue() || checkTools || options.once;
|
|
165
|
+
if (!statusReporter.pending && (reportBase || workspaceChecks.length > 0)) {
|
|
166
|
+
const status = (async () => {
|
|
167
|
+
const reports = await Promise.allSettled([
|
|
168
|
+
...(reportBase ? [statusReporter.report(checkTools)] : []),
|
|
169
|
+
...workspaceChecks.map(({ workspaceId }) => statusReporter.report(true, workspaceId)),
|
|
170
|
+
]);
|
|
171
|
+
const failed = reports.find((report) => report.status === "rejected");
|
|
172
|
+
if (failed?.status === "rejected")
|
|
173
|
+
throw failed.reason;
|
|
174
|
+
})();
|
|
167
175
|
if (options.once)
|
|
168
176
|
await status;
|
|
169
177
|
else {
|
|
@@ -182,29 +190,19 @@ export async function runDaemon(options = {}) {
|
|
|
182
190
|
}
|
|
183
191
|
// 新进程的首轮工具就绪状态尚未上报时,不提前领取待执行的通用任务。
|
|
184
192
|
if (!statusReporter.pending)
|
|
185
|
-
await generalRuns
|
|
186
|
-
.poll(new GeneralRunClient(client), host, options.once)
|
|
187
|
-
.catch((error) => {
|
|
193
|
+
await generalRuns.poll(device, host, options.once).catch((error) => {
|
|
188
194
|
logHostEvent("general_run_poll_failed", {
|
|
189
195
|
hostId: host.hostId,
|
|
190
196
|
error: safeHostError(error),
|
|
191
197
|
});
|
|
192
198
|
});
|
|
193
|
-
if (!activeCommands.size &&
|
|
194
|
-
!codingRuns.isBusy() &&
|
|
195
|
-
!testRuns.isBusy() &&
|
|
196
|
-
!qaSessions.isBusy() &&
|
|
197
|
-
!generalRuns.isBusy()) {
|
|
199
|
+
if (!activeCommands.size && !executions.isBusy() && !generalRuns.isBusy()) {
|
|
198
200
|
await releaseExecution();
|
|
199
201
|
releaseExecution = undefined;
|
|
200
202
|
}
|
|
201
203
|
if (options.once)
|
|
202
204
|
return;
|
|
203
|
-
await wakeup.wait(Math.min(storageMaintenance.waitMilliseconds(), commandPollMilliseconds(notifications?.healthy ?? false, activeCommands.size > 0 ||
|
|
204
|
-
codingRuns.isBusy() ||
|
|
205
|
-
testRuns.isBusy() ||
|
|
206
|
-
qaSessions.isBusy() ||
|
|
207
|
-
generalRuns.isBusy(), heartbeat.nextHeartbeatSeconds)));
|
|
205
|
+
await wakeup.wait(Math.min(storageMaintenance.waitMilliseconds(), commandPollMilliseconds(notifications?.healthy ?? false, activeCommands.size > 0 || executions.isBusy() || generalRuns.isBusy(), heartbeat.nextHeartbeatSeconds)));
|
|
208
206
|
}
|
|
209
207
|
catch (error) {
|
|
210
208
|
logHostEvent("heartbeat_failed", { hostId: host.hostId, error: safeHostError(error) });
|
|
@@ -212,11 +210,7 @@ export async function runDaemon(options = {}) {
|
|
|
212
210
|
throw error;
|
|
213
211
|
if (options.once)
|
|
214
212
|
throw error;
|
|
215
|
-
if (!activeCommands.size &&
|
|
216
|
-
!codingRuns.isBusy() &&
|
|
217
|
-
!testRuns.isBusy() &&
|
|
218
|
-
!qaSessions.isBusy() &&
|
|
219
|
-
!generalRuns.isBusy()) {
|
|
213
|
+
if (!activeCommands.size && !executions.isBusy() && !generalRuns.isBusy()) {
|
|
220
214
|
await releaseExecution?.();
|
|
221
215
|
releaseExecution = undefined;
|
|
222
216
|
}
|
|
@@ -226,7 +220,7 @@ export async function runDaemon(options = {}) {
|
|
|
226
220
|
}
|
|
227
221
|
finally {
|
|
228
222
|
await notifications?.stop();
|
|
229
|
-
await generalRuns.stop();
|
|
223
|
+
await Promise.allSettled([generalRuns.stop(), executions.stop()]);
|
|
230
224
|
// 已领取命令仍在执行时保留更新锁;进程退出后由现有锁失效机制回收。
|
|
231
225
|
if (!activeCommands.size)
|
|
232
226
|
await releaseExecution?.();
|
|
@@ -257,206 +251,7 @@ function statusInputs(host) {
|
|
|
257
251
|
}),
|
|
258
252
|
]);
|
|
259
253
|
}
|
|
260
|
-
export
|
|
261
|
-
let result = {};
|
|
262
|
-
let reportingSuccess = false;
|
|
263
|
-
const context = {
|
|
264
|
-
hostId: host.hostId,
|
|
265
|
-
commandId: command.id,
|
|
266
|
-
kind: command.kind,
|
|
267
|
-
runId: command.run?.runId,
|
|
268
|
-
};
|
|
269
|
-
const startedAt = Date.now();
|
|
270
|
-
let diagnosticStage = "VERIFY_AND_COLLECT_STATUS";
|
|
271
|
-
logHostEvent("command_started", context);
|
|
272
|
-
try {
|
|
273
|
-
if (command.inputRef) {
|
|
274
|
-
const input = await client.commandInput(command.inputRef, {
|
|
275
|
-
hostId: host.hostId,
|
|
276
|
-
generation: host.generation,
|
|
277
|
-
});
|
|
278
|
-
command = { ...command, ...input };
|
|
279
|
-
context.runId = command.run?.runId;
|
|
280
|
-
logHostEvent("command_input_loaded", context);
|
|
281
|
-
}
|
|
282
|
-
let resultCode = "COMMAND_SUCCEEDED";
|
|
283
|
-
if (command.kind === "PROVIDER_LOGIN" && command.providerId) {
|
|
284
|
-
resultCode = (await pi.login(command.providerId, "remote")).code;
|
|
285
|
-
await statusReporter.report();
|
|
286
|
-
result = { providerId: command.providerId, phase: "COMPLETED" };
|
|
287
|
-
}
|
|
288
|
-
else if (command.kind === "REFRESH_MODELS") {
|
|
289
|
-
await statusReporter.report();
|
|
290
|
-
resultCode = "MODEL_CATALOG_REFRESHED";
|
|
291
|
-
}
|
|
292
|
-
else if (command.kind === "RUN_DIAGNOSTICS") {
|
|
293
|
-
const { verification, local, toolChecks } = await statusReporter.report(true);
|
|
294
|
-
if (!verification || !toolChecks)
|
|
295
|
-
throw new Error("HOST_TOOL_CONFIGURATION_UNAVAILABLE");
|
|
296
|
-
diagnosticStage = "REPORT_STATUS";
|
|
297
|
-
resultCode = "DIAGNOSTICS_COMPLETED";
|
|
298
|
-
diagnosticStage = "RUN_CHECKS";
|
|
299
|
-
result = {
|
|
300
|
-
checks: await runDiagnostics({
|
|
301
|
-
platformReachable: true,
|
|
302
|
-
deviceCredentialValid: verification.deviceCredentialValid,
|
|
303
|
-
generationValid: verification.generationValid,
|
|
304
|
-
defaultModelValid: isDefaultModelValid(verification.defaultRunConfig, local.models),
|
|
305
|
-
providerReady: local.providers.some((state) => state.status === "READY"),
|
|
306
|
-
shell: verification.shell,
|
|
307
|
-
toolChecks,
|
|
308
|
-
runtimeVerification: "installed-package",
|
|
309
|
-
logContext: {
|
|
310
|
-
source: "RUN_DIAGNOSTICS",
|
|
311
|
-
hostId: host.hostId,
|
|
312
|
-
generation: host.generation,
|
|
313
|
-
commandId: command.id,
|
|
314
|
-
},
|
|
315
|
-
}),
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
else if (command.kind === "MCP_DISCOVER") {
|
|
319
|
-
if (!command.mcp)
|
|
320
|
-
throw new Error("MCP_CONFIGURATION_MISSING");
|
|
321
|
-
result = { mcpTools: await discoverLocalMcp(command.mcp) };
|
|
322
|
-
resultCode = "MCP_TOOLS_DISCOVERED";
|
|
323
|
-
}
|
|
324
|
-
else if (command.kind === "MCP_CALL") {
|
|
325
|
-
if (!command.mcpCall)
|
|
326
|
-
throw new Error("MCP_CONFIGURATION_MISSING");
|
|
327
|
-
const remaining = Date.parse(command.expiresAt) - Date.now();
|
|
328
|
-
if (!Number.isFinite(remaining) || remaining <= 0)
|
|
329
|
-
throw new Error("MCP_COMMAND_EXPIRED");
|
|
330
|
-
result = {
|
|
331
|
-
mcpResult: await callLocalMcp(command.mcpCall, AbortSignal.timeout(remaining)),
|
|
332
|
-
};
|
|
333
|
-
resultCode = "MCP_TOOL_CALLED";
|
|
334
|
-
}
|
|
335
|
-
else if (command.kind.startsWith("TEST_SESSION_")) {
|
|
336
|
-
if (!qaSessions)
|
|
337
|
-
throw new Error("QA_SESSION_UNAVAILABLE");
|
|
338
|
-
await qaSessions.execute(client, { hostId: host.hostId, generation: host.generation }, command);
|
|
339
|
-
result = { phase: "ACCEPTED" };
|
|
340
|
-
resultCode = "QA_SESSION_COMMAND_ACCEPTED";
|
|
341
|
-
}
|
|
342
|
-
else if (command.kind === "TEST_RUN" ||
|
|
343
|
-
command.kind === "TEST_RETRANSMIT" ||
|
|
344
|
-
command.kind === "TEST_CATALOG") {
|
|
345
|
-
if (!testRuns)
|
|
346
|
-
throw new Error("QA_EXECUTOR_UNAVAILABLE");
|
|
347
|
-
await testRuns.execute(client, { hostId: host.hostId, generation: host.generation }, command);
|
|
348
|
-
result = { phase: "ACCEPTED" };
|
|
349
|
-
resultCode = "TEST_COMMAND_ACCEPTED";
|
|
350
|
-
}
|
|
351
|
-
else if (command.kind.startsWith("CODING_RUN_")) {
|
|
352
|
-
const outcome = await codingRuns.execute(client, host, command);
|
|
353
|
-
resultCode = "CODING_RUN_COMMAND_ACCEPTED";
|
|
354
|
-
result =
|
|
355
|
-
command.run?.action === "CHECK_RESOURCES"
|
|
356
|
-
? { ...outcome }
|
|
357
|
-
: { phase: "COMPLETED", ...outcome };
|
|
358
|
-
}
|
|
359
|
-
else
|
|
360
|
-
throw new Error("UNKNOWN_COMMAND");
|
|
361
|
-
logHostEvent("command_executed", { ...context, durationMs: Date.now() - startedAt });
|
|
362
|
-
reportingSuccess = true;
|
|
363
|
-
diagnosticStage = "REPORT_RESULT";
|
|
364
|
-
await client.completeCommand(command.id, {
|
|
365
|
-
hostId: host.hostId,
|
|
366
|
-
generation: host.generation,
|
|
367
|
-
status: "SUCCEEDED",
|
|
368
|
-
resultCode,
|
|
369
|
-
result,
|
|
370
|
-
});
|
|
371
|
-
logHostEvent("command_completed", {
|
|
372
|
-
...context,
|
|
373
|
-
resultCode,
|
|
374
|
-
durationMs: Date.now() - startedAt,
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
catch (error) {
|
|
378
|
-
if (command.kind === "RUN_DIAGNOSTICS")
|
|
379
|
-
logHostEvent(reportingSuccess ? "diagnostic_result_report_failed" : "diagnostic_execution_failed", {
|
|
380
|
-
...context,
|
|
381
|
-
stage: diagnosticStage,
|
|
382
|
-
...diagnosticErrorFields(error),
|
|
383
|
-
...(error instanceof PlatformClientError
|
|
384
|
-
? {
|
|
385
|
-
httpStatus: error.status,
|
|
386
|
-
errorCode: /^[A-Z0-9_]{1,100}$/u.test(error.code)
|
|
387
|
-
? error.code
|
|
388
|
-
: "UNKNOWN_API_ERROR",
|
|
389
|
-
}
|
|
390
|
-
: {}),
|
|
391
|
-
durationMs: Date.now() - startedAt,
|
|
392
|
-
});
|
|
393
|
-
// 执行成功、回执失败属于结果未知,不能反写为执行失败或自动重放。
|
|
394
|
-
if (reportingSuccess)
|
|
395
|
-
throw error;
|
|
396
|
-
const safeError = redactHostText(error instanceof Error ? error.message : String(error), [
|
|
397
|
-
paths().root,
|
|
398
|
-
]);
|
|
399
|
-
logHostEvent("command_failed", {
|
|
400
|
-
...context,
|
|
401
|
-
error: safeError,
|
|
402
|
-
durationMs: Date.now() - startedAt,
|
|
403
|
-
});
|
|
404
|
-
const imageReadFailed = error instanceof PlatformClientError && error.code === "IMAGE_ATTACHMENT_READ_FAILED";
|
|
405
|
-
const intakeFailure = localIntakeFailure(error);
|
|
406
|
-
const branchMissing = branchMissingFailure(error);
|
|
407
|
-
const resultCode = intakeFailure?.code ??
|
|
408
|
-
(imageReadFailed
|
|
409
|
-
? "IMAGE_ATTACHMENT_READ_FAILED"
|
|
410
|
-
: error instanceof Error && /^[A-Z0-9_]+$/u.test(error.message)
|
|
411
|
-
? error.message
|
|
412
|
-
: (branchMissing?.code ?? "COMMAND_FAILED"));
|
|
413
|
-
const workspaceInitialization = !intakeFailure &&
|
|
414
|
-
command.run?.runInput &&
|
|
415
|
-
["CODING_RUN_START", "CODING_RUN_RESUME"].includes(command.kind)
|
|
416
|
-
? await inspectWorkspaceInitialization(command.run.runId, command.run.runInput)
|
|
417
|
-
: undefined;
|
|
418
|
-
const completeFailure = () => client.completeCommand(command.id, {
|
|
419
|
-
hostId: host.hostId,
|
|
420
|
-
generation: host.generation,
|
|
421
|
-
status: "FAILED",
|
|
422
|
-
resultCode,
|
|
423
|
-
result: workspaceInitialization
|
|
424
|
-
? { workspaceInitialization }
|
|
425
|
-
: intakeFailure
|
|
426
|
-
? { message: intakeFailure.message }
|
|
427
|
-
: command.run?.action === "RECALL_QUEUE"
|
|
428
|
-
? result
|
|
429
|
-
: {},
|
|
430
|
-
});
|
|
431
|
-
// 可恢复图片输入必须先落下失败命令,再让用户看到可恢复的 Run。
|
|
432
|
-
if (imageReadFailed)
|
|
433
|
-
await completeFailure();
|
|
434
|
-
const codingRun = command.kind.startsWith("CODING_RUN_") ? command.run : undefined;
|
|
435
|
-
if (codingRun && !["STOP", "RECALL_QUEUE", "CHECK_RESOURCES"].includes(codingRun.action)) {
|
|
436
|
-
await client
|
|
437
|
-
.reportCodingTerminal(codingRun.runId, {
|
|
438
|
-
hostId: host.hostId,
|
|
439
|
-
generation: host.generation,
|
|
440
|
-
turnId: codingRun.turnId,
|
|
441
|
-
kind: "FAILED",
|
|
442
|
-
summary: intakeFailure?.message ??
|
|
443
|
-
branchMissing?.message ??
|
|
444
|
-
(resultCode === "IMAGE_ATTACHMENT_READ_FAILED"
|
|
445
|
-
? "图片读取失败,未将图片交给模型,请检查附件后重试"
|
|
446
|
-
: resultCode === "MODEL_IMAGES_UNSUPPORTED"
|
|
447
|
-
? "当前模型不支持图片,请选择支持图片的模型"
|
|
448
|
-
: "Local Coding Runtime 无法执行本次命令"),
|
|
449
|
-
knownIssues: "",
|
|
450
|
-
failureCode: resultCode,
|
|
451
|
-
projectFacts: [],
|
|
452
|
-
testFacts: [],
|
|
453
|
-
})
|
|
454
|
-
.catch((error) => logHostEvent("terminal_report_failed", { ...context, error: safeHostError(error) }));
|
|
455
|
-
}
|
|
456
|
-
if (!imageReadFailed)
|
|
457
|
-
await completeFailure();
|
|
458
|
-
}
|
|
459
|
-
}
|
|
254
|
+
export { executeCommand } from "./command-executor.js";
|
|
460
255
|
if (isEntrypoint()) {
|
|
461
256
|
runDaemon({ once: process.argv.includes("--once") }).catch((error) => {
|
|
462
257
|
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|