@bf-meishijian/aip 0.0.34 → 0.0.36
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 +25 -240
- package/dist/daemon.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 +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 +159 -0
- package/dist/general-run-supervisor.js.map +1 -0
- package/dist/general-run-tools.d.ts.map +1 -1
- package/dist/general-run-tools.js +1 -0
- package/dist/general-run-tools.js.map +1 -1
- 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 +8 -3
- package/dist/host-status.d.ts.map +1 -1
- package/dist/host-status.js +58 -32
- 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 +16 -12
- package/dist/live-employee.js.map +1 -1
- package/dist/local-employee-runtime.d.ts +2 -1
- package/dist/local-employee-runtime.d.ts.map +1 -1
- package/dist/local-employee-runtime.js +39 -9
- package/dist/local-employee-runtime.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 +9 -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/skill-bundle-cache.d.ts +11 -0
- package/dist/skill-bundle-cache.d.ts.map +1 -0
- package/dist/skill-bundle-cache.js +76 -0
- package/dist/skill-bundle-cache.js.map +1 -0
- package/dist/skill-storage.d.ts +18 -0
- package/dist/skill-storage.d.ts.map +1 -0
- package/dist/skill-storage.js +287 -0
- package/dist/skill-storage.js.map +1 -0
- 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 +98 -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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;4BACzC,CAAC,CAAC,sBAAsB;4BACxB,CAAC,CAAC,+BAA+B,CAAC;gBACxC,WAAW,EAAE,EAAE;gBACf,WAAW,EAAE,UAAU;gBACvB,YAAY,EAAE,EAAE;gBAChB,SAAS,EAAE,EAAE;aACd,CAAC;iBACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CACf,YAAY,CAAC,wBAAwB,EAAE,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,CACpF,CAAC;QACN,CAAC;QACD,IAAI,CAAC,eAAe;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 {
|
|
@@ -191,29 +190,19 @@ export async function runDaemon(options = {}) {
|
|
|
191
190
|
}
|
|
192
191
|
// 新进程的首轮工具就绪状态尚未上报时,不提前领取待执行的通用任务。
|
|
193
192
|
if (!statusReporter.pending)
|
|
194
|
-
await generalRuns
|
|
195
|
-
.poll(new GeneralRunClient(client), host, options.once)
|
|
196
|
-
.catch((error) => {
|
|
193
|
+
await generalRuns.poll(device, host, options.once).catch((error) => {
|
|
197
194
|
logHostEvent("general_run_poll_failed", {
|
|
198
195
|
hostId: host.hostId,
|
|
199
196
|
error: safeHostError(error),
|
|
200
197
|
});
|
|
201
198
|
});
|
|
202
|
-
if (!activeCommands.size &&
|
|
203
|
-
!codingRuns.isBusy() &&
|
|
204
|
-
!testRuns.isBusy() &&
|
|
205
|
-
!qaSessions.isBusy() &&
|
|
206
|
-
!generalRuns.isBusy()) {
|
|
199
|
+
if (!activeCommands.size && !executions.isBusy() && !generalRuns.isBusy()) {
|
|
207
200
|
await releaseExecution();
|
|
208
201
|
releaseExecution = undefined;
|
|
209
202
|
}
|
|
210
203
|
if (options.once)
|
|
211
204
|
return;
|
|
212
|
-
await wakeup.wait(Math.min(storageMaintenance.waitMilliseconds(), commandPollMilliseconds(notifications?.healthy ?? false, activeCommands.size > 0 ||
|
|
213
|
-
codingRuns.isBusy() ||
|
|
214
|
-
testRuns.isBusy() ||
|
|
215
|
-
qaSessions.isBusy() ||
|
|
216
|
-
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)));
|
|
217
206
|
}
|
|
218
207
|
catch (error) {
|
|
219
208
|
logHostEvent("heartbeat_failed", { hostId: host.hostId, error: safeHostError(error) });
|
|
@@ -221,11 +210,7 @@ export async function runDaemon(options = {}) {
|
|
|
221
210
|
throw error;
|
|
222
211
|
if (options.once)
|
|
223
212
|
throw error;
|
|
224
|
-
if (!activeCommands.size &&
|
|
225
|
-
!codingRuns.isBusy() &&
|
|
226
|
-
!testRuns.isBusy() &&
|
|
227
|
-
!qaSessions.isBusy() &&
|
|
228
|
-
!generalRuns.isBusy()) {
|
|
213
|
+
if (!activeCommands.size && !executions.isBusy() && !generalRuns.isBusy()) {
|
|
229
214
|
await releaseExecution?.();
|
|
230
215
|
releaseExecution = undefined;
|
|
231
216
|
}
|
|
@@ -235,7 +220,7 @@ export async function runDaemon(options = {}) {
|
|
|
235
220
|
}
|
|
236
221
|
finally {
|
|
237
222
|
await notifications?.stop();
|
|
238
|
-
await generalRuns.stop();
|
|
223
|
+
await Promise.allSettled([generalRuns.stop(), executions.stop()]);
|
|
239
224
|
// 已领取命令仍在执行时保留更新锁;进程退出后由现有锁失效机制回收。
|
|
240
225
|
if (!activeCommands.size)
|
|
241
226
|
await releaseExecution?.();
|
|
@@ -266,207 +251,7 @@ function statusInputs(host) {
|
|
|
266
251
|
}),
|
|
267
252
|
]);
|
|
268
253
|
}
|
|
269
|
-
export
|
|
270
|
-
let result = {};
|
|
271
|
-
let reportingSuccess = false;
|
|
272
|
-
const context = {
|
|
273
|
-
hostId: host.hostId,
|
|
274
|
-
commandId: command.id,
|
|
275
|
-
kind: command.kind,
|
|
276
|
-
runId: command.run?.runId,
|
|
277
|
-
};
|
|
278
|
-
const startedAt = Date.now();
|
|
279
|
-
let diagnosticStage = "VERIFY_AND_COLLECT_STATUS";
|
|
280
|
-
logHostEvent("command_started", context);
|
|
281
|
-
try {
|
|
282
|
-
if (command.inputRef) {
|
|
283
|
-
const input = await client.commandInput(command.inputRef, {
|
|
284
|
-
hostId: host.hostId,
|
|
285
|
-
generation: host.generation,
|
|
286
|
-
});
|
|
287
|
-
command = { ...command, ...input };
|
|
288
|
-
context.runId = command.run?.runId;
|
|
289
|
-
logHostEvent("command_input_loaded", context);
|
|
290
|
-
}
|
|
291
|
-
let resultCode = "COMMAND_SUCCEEDED";
|
|
292
|
-
if (command.kind === "PROVIDER_LOGIN" && command.providerId) {
|
|
293
|
-
resultCode = (await pi.login(command.providerId, "remote")).code;
|
|
294
|
-
await statusReporter.report();
|
|
295
|
-
result = { providerId: command.providerId, phase: "COMPLETED" };
|
|
296
|
-
}
|
|
297
|
-
else if (command.kind === "REFRESH_MODELS") {
|
|
298
|
-
await statusReporter.report();
|
|
299
|
-
resultCode = "MODEL_CATALOG_REFRESHED";
|
|
300
|
-
}
|
|
301
|
-
else if (command.kind === "RUN_DIAGNOSTICS") {
|
|
302
|
-
const { verification, local, toolChecks } = await statusReporter.report(true, command.workspaceId);
|
|
303
|
-
if (!verification || !toolChecks)
|
|
304
|
-
throw new Error("HOST_TOOL_CONFIGURATION_UNAVAILABLE");
|
|
305
|
-
diagnosticStage = "REPORT_STATUS";
|
|
306
|
-
resultCode = "DIAGNOSTICS_COMPLETED";
|
|
307
|
-
diagnosticStage = "RUN_CHECKS";
|
|
308
|
-
result = {
|
|
309
|
-
checks: await runDiagnostics({
|
|
310
|
-
platformReachable: true,
|
|
311
|
-
deviceCredentialValid: verification.deviceCredentialValid,
|
|
312
|
-
generationValid: verification.generationValid,
|
|
313
|
-
defaultModelValid: isDefaultModelValid(verification.defaultRunConfig, local.models),
|
|
314
|
-
providerReady: local.providers.some((state) => state.status === "READY"),
|
|
315
|
-
shell: verification.shell,
|
|
316
|
-
toolChecks,
|
|
317
|
-
runtimeVerification: "installed-package",
|
|
318
|
-
logContext: {
|
|
319
|
-
source: "RUN_DIAGNOSTICS",
|
|
320
|
-
hostId: host.hostId,
|
|
321
|
-
generation: host.generation,
|
|
322
|
-
commandId: command.id,
|
|
323
|
-
...(command.workspaceId ? { workspaceId: command.workspaceId } : {}),
|
|
324
|
-
},
|
|
325
|
-
}),
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
else if (command.kind === "MCP_DISCOVER") {
|
|
329
|
-
if (!command.mcp)
|
|
330
|
-
throw new Error("MCP_CONFIGURATION_MISSING");
|
|
331
|
-
result = { mcpTools: await discoverLocalMcp(command.mcp) };
|
|
332
|
-
resultCode = "MCP_TOOLS_DISCOVERED";
|
|
333
|
-
}
|
|
334
|
-
else if (command.kind === "MCP_CALL") {
|
|
335
|
-
if (!command.mcpCall)
|
|
336
|
-
throw new Error("MCP_CONFIGURATION_MISSING");
|
|
337
|
-
const remaining = Date.parse(command.expiresAt) - Date.now();
|
|
338
|
-
if (!Number.isFinite(remaining) || remaining <= 0)
|
|
339
|
-
throw new Error("MCP_COMMAND_EXPIRED");
|
|
340
|
-
result = {
|
|
341
|
-
mcpResult: await callLocalMcp(command.mcpCall, AbortSignal.timeout(remaining)),
|
|
342
|
-
};
|
|
343
|
-
resultCode = "MCP_TOOL_CALLED";
|
|
344
|
-
}
|
|
345
|
-
else if (command.kind.startsWith("TEST_SESSION_")) {
|
|
346
|
-
if (!qaSessions)
|
|
347
|
-
throw new Error("QA_SESSION_UNAVAILABLE");
|
|
348
|
-
await qaSessions.execute(client, { hostId: host.hostId, generation: host.generation }, command);
|
|
349
|
-
result = { phase: "ACCEPTED" };
|
|
350
|
-
resultCode = "QA_SESSION_COMMAND_ACCEPTED";
|
|
351
|
-
}
|
|
352
|
-
else if (command.kind === "TEST_RUN" ||
|
|
353
|
-
command.kind === "TEST_RETRANSMIT" ||
|
|
354
|
-
command.kind === "TEST_CATALOG") {
|
|
355
|
-
if (!testRuns)
|
|
356
|
-
throw new Error("QA_EXECUTOR_UNAVAILABLE");
|
|
357
|
-
await testRuns.execute(client, { hostId: host.hostId, generation: host.generation }, command);
|
|
358
|
-
result = { phase: "ACCEPTED" };
|
|
359
|
-
resultCode = "TEST_COMMAND_ACCEPTED";
|
|
360
|
-
}
|
|
361
|
-
else if (command.kind.startsWith("CODING_RUN_")) {
|
|
362
|
-
const outcome = await codingRuns.execute(client, host, command);
|
|
363
|
-
resultCode = "CODING_RUN_COMMAND_ACCEPTED";
|
|
364
|
-
result =
|
|
365
|
-
command.run?.action === "CHECK_RESOURCES"
|
|
366
|
-
? { ...outcome }
|
|
367
|
-
: { phase: "COMPLETED", ...outcome };
|
|
368
|
-
}
|
|
369
|
-
else
|
|
370
|
-
throw new Error("UNKNOWN_COMMAND");
|
|
371
|
-
logHostEvent("command_executed", { ...context, durationMs: Date.now() - startedAt });
|
|
372
|
-
reportingSuccess = true;
|
|
373
|
-
diagnosticStage = "REPORT_RESULT";
|
|
374
|
-
await client.completeCommand(command.id, {
|
|
375
|
-
hostId: host.hostId,
|
|
376
|
-
generation: host.generation,
|
|
377
|
-
status: "SUCCEEDED",
|
|
378
|
-
resultCode,
|
|
379
|
-
result,
|
|
380
|
-
});
|
|
381
|
-
logHostEvent("command_completed", {
|
|
382
|
-
...context,
|
|
383
|
-
resultCode,
|
|
384
|
-
durationMs: Date.now() - startedAt,
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
catch (error) {
|
|
388
|
-
if (command.kind === "RUN_DIAGNOSTICS")
|
|
389
|
-
logHostEvent(reportingSuccess ? "diagnostic_result_report_failed" : "diagnostic_execution_failed", {
|
|
390
|
-
...context,
|
|
391
|
-
stage: diagnosticStage,
|
|
392
|
-
...diagnosticErrorFields(error),
|
|
393
|
-
...(error instanceof PlatformClientError
|
|
394
|
-
? {
|
|
395
|
-
httpStatus: error.status,
|
|
396
|
-
errorCode: /^[A-Z0-9_]{1,100}$/u.test(error.code)
|
|
397
|
-
? error.code
|
|
398
|
-
: "UNKNOWN_API_ERROR",
|
|
399
|
-
}
|
|
400
|
-
: {}),
|
|
401
|
-
durationMs: Date.now() - startedAt,
|
|
402
|
-
});
|
|
403
|
-
// 执行成功、回执失败属于结果未知,不能反写为执行失败或自动重放。
|
|
404
|
-
if (reportingSuccess)
|
|
405
|
-
throw error;
|
|
406
|
-
const safeError = redactHostText(error instanceof Error ? error.message : String(error), [
|
|
407
|
-
paths().root,
|
|
408
|
-
]);
|
|
409
|
-
logHostEvent("command_failed", {
|
|
410
|
-
...context,
|
|
411
|
-
error: safeError,
|
|
412
|
-
durationMs: Date.now() - startedAt,
|
|
413
|
-
});
|
|
414
|
-
const imageReadFailed = error instanceof PlatformClientError && error.code === "IMAGE_ATTACHMENT_READ_FAILED";
|
|
415
|
-
const intakeFailure = localIntakeFailure(error);
|
|
416
|
-
const branchMissing = branchMissingFailure(error);
|
|
417
|
-
const resultCode = intakeFailure?.code ??
|
|
418
|
-
(imageReadFailed
|
|
419
|
-
? "IMAGE_ATTACHMENT_READ_FAILED"
|
|
420
|
-
: error instanceof Error && /^[A-Z0-9_]+$/u.test(error.message)
|
|
421
|
-
? error.message
|
|
422
|
-
: (branchMissing?.code ?? "COMMAND_FAILED"));
|
|
423
|
-
const workspaceInitialization = !intakeFailure &&
|
|
424
|
-
command.run?.runInput &&
|
|
425
|
-
["CODING_RUN_START", "CODING_RUN_RESUME"].includes(command.kind)
|
|
426
|
-
? await inspectWorkspaceInitialization(command.run.runId, command.run.runInput)
|
|
427
|
-
: undefined;
|
|
428
|
-
const completeFailure = () => client.completeCommand(command.id, {
|
|
429
|
-
hostId: host.hostId,
|
|
430
|
-
generation: host.generation,
|
|
431
|
-
status: "FAILED",
|
|
432
|
-
resultCode,
|
|
433
|
-
result: workspaceInitialization
|
|
434
|
-
? { workspaceInitialization }
|
|
435
|
-
: intakeFailure
|
|
436
|
-
? { message: intakeFailure.message }
|
|
437
|
-
: command.run?.action === "RECALL_QUEUE"
|
|
438
|
-
? result
|
|
439
|
-
: {},
|
|
440
|
-
});
|
|
441
|
-
// 可恢复图片输入必须先落下失败命令,再让用户看到可恢复的 Run。
|
|
442
|
-
if (imageReadFailed)
|
|
443
|
-
await completeFailure();
|
|
444
|
-
const codingRun = command.kind.startsWith("CODING_RUN_") ? command.run : undefined;
|
|
445
|
-
if (codingRun && !["STOP", "RECALL_QUEUE", "CHECK_RESOURCES"].includes(codingRun.action)) {
|
|
446
|
-
await client
|
|
447
|
-
.reportCodingTerminal(codingRun.runId, {
|
|
448
|
-
hostId: host.hostId,
|
|
449
|
-
generation: host.generation,
|
|
450
|
-
turnId: codingRun.turnId,
|
|
451
|
-
kind: "FAILED",
|
|
452
|
-
summary: intakeFailure?.message ??
|
|
453
|
-
branchMissing?.message ??
|
|
454
|
-
(resultCode === "IMAGE_ATTACHMENT_READ_FAILED"
|
|
455
|
-
? "图片读取失败,未将图片交给模型,请检查附件后重试"
|
|
456
|
-
: resultCode === "MODEL_IMAGES_UNSUPPORTED"
|
|
457
|
-
? "当前模型不支持图片,请选择支持图片的模型"
|
|
458
|
-
: "Local Coding Runtime 无法执行本次命令"),
|
|
459
|
-
knownIssues: "",
|
|
460
|
-
failureCode: resultCode,
|
|
461
|
-
projectFacts: [],
|
|
462
|
-
testFacts: [],
|
|
463
|
-
})
|
|
464
|
-
.catch((error) => logHostEvent("terminal_report_failed", { ...context, error: safeHostError(error) }));
|
|
465
|
-
}
|
|
466
|
-
if (!imageReadFailed)
|
|
467
|
-
await completeFailure();
|
|
468
|
-
}
|
|
469
|
-
}
|
|
254
|
+
export { executeCommand } from "./command-executor.js";
|
|
470
255
|
if (isEntrypoint()) {
|
|
471
256
|
runDaemon({ once: process.argv.includes("--once") }).catch((error) => {
|
|
472
257
|
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|