@mininglamp-oss/octo-runtime 1.1.10 → 1.1.11
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/README.md +1 -1
- package/apps/cli/README.md +1 -1
- package/apps/cli/dist/adapters.js +40 -14
- package/apps/cli/dist/build-info.json +2 -2
- package/apps/cli/dist/command-tree.js +2 -3
- package/apps/cli/dist/extras.js +11 -1
- package/apps/cli/dist/index.js +14 -1
- package/apps/cli/dist/main.js +58 -23
- package/apps/cli/dist/module-manifest.js +21 -3
- package/apps/cli/dist/output.d.ts +19 -1
- package/apps/cli/dist/output.js +179 -27
- package/apps/cli/dist/playboard.js +2 -2
- package/apps/cli/dist/state.d.ts +5 -2
- package/apps/cli/dist/state.js +48 -13
- package/dist/public/codex.d.ts +1 -0
- package/dist/public/codex.js +1 -0
- package/dist/public/executor-kernel.d.ts +4 -0
- package/dist/public/executor-kernel.js +2 -0
- package/dist/public/extra.d.ts +1 -1
- package/dist/public/host.d.ts +5 -0
- package/dist/public/host.js +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +20 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.d.ts +6 -6
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.js +68 -253
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.d.ts +11 -6
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.js +198 -52
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/service.d.ts +58 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/service.js +650 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/stdin-writer.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/stdin-writer.js +15 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/execution-scope.d.ts +25 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/execution-scope.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapters.js +40 -14
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.js +2 -3
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extras.js +11 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/index.js +14 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +58 -23
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.js +21 -3
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.d.ts +19 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +179 -27
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/state.d.ts +5 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/state.js +48 -13
- package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +23 -23
- package/node_modules/@mininglamp-oss/octo-runtime-client/build-info.json +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/async-question-reply.d.ts +30 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/async-question-reply.js +199 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/browser.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/browser.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/client.d.ts +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/client.js +465 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/index.d.ts +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/index.js +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/internal.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/internal.js +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/invocation-lifecycle.d.ts +59 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/invocation-lifecycle.js +287 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/notification.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/notification.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/protocol.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/protocol.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/runtime-path.d.ts +21 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/runtime-path.js +138 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-catalog.d.ts +8 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-catalog.js +65 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-diagnostics.d.ts +82 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-diagnostics.js +371 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/submission-error.d.ts +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/submission-error.js +23 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/types.d.ts +72 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/types.js +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/package.json +54 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/context-configuration-fixtures.json +1219 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/context-fixtures.json +5988 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-client.behavior.json +56 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-ipc-fixtures.json +53 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-ipc.schema.json +538 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/native-invoke-fixtures.json +116 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/protocol.schema.json +4525 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/run-protocol-fixtures.json +761 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/runtime-selection-fixtures.json +663 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/session-name-fixtures.json +191 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.d.ts +26 -18
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +151 -11
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/async-question-reply.d.ts +1 -30
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/async-question-reply.js +2 -199
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/client.d.ts +1 -10
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/client.js +2 -446
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/endpoint.js +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/host-run-service.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/host-run-service.js +13 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.d.ts +1 -53
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.js +2 -280
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/lifecycle.d.ts +5 -10
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/lifecycle.js +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runtime-home.d.ts +20 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runtime-home.js +180 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.js +31 -8
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/service.d.ts +5 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/service.js +48 -5
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-catalog.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-catalog.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-diagnostics.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-diagnostics.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-logging.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-logging.js +18 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.d.ts +1 -10
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.js +2 -23
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/types.d.ts +2 -72
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/types.js +2 -10
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +5 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/extra.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/ports.d.ts +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/extra.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/ports.d.ts +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/index.js +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/endpoint.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/endpoint.js +12 -5
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/errors.d.ts +5 -1
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/errors.js +9 -0
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/execution.d.ts +44 -0
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/execution.js +207 -0
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.js +23 -3
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-service.d.ts +27 -4
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-service.js +133 -25
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extras.d.ts +10 -3
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extras.js +18 -4
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.d.ts +5 -6
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.js +33 -45
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/identity.js +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.js +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +5 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/adapter-metadata.d.ts +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/adapter-metadata.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +19 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.d.ts +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/service-processes.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/service-processes.js +65 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
- package/package.json +33 -27
- package/packages/octo-runtime-protocol/schema/protocol.schema.json +42 -0
package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/host-run-service.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export declare class HostRunService implements ExecutionSource {
|
|
|
29
29
|
invokeFrames(input: InvokeInput, environment?: InvokeEnvironment): AsyncGenerator<HostFrame>;
|
|
30
30
|
/** 返回接纳凭据后仍在后台驱动源流;调用方无需保持原请求连接才能让执行继续。 */
|
|
31
31
|
submit(input: InvokeInput, environment?: InvokeEnvironment): Promise<HostRunReceipt>;
|
|
32
|
+
/** 观察指定后台消费的实际结束;终态进入窗口时 finally 可能仍在执行。 */
|
|
33
|
+
settled(receipt: HostRunReceipt): Promise<void>;
|
|
32
34
|
get(runId: string): HostRunReceipt & {
|
|
33
35
|
oldest_seq: number;
|
|
34
36
|
latest_seq: number;
|
|
@@ -154,14 +154,25 @@ export class HostRunService {
|
|
|
154
154
|
/** 返回接纳凭据后仍在后台驱动源流;调用方无需保持原请求连接才能让执行继续。 */
|
|
155
155
|
async submit(input, environment = {}) {
|
|
156
156
|
const run = await this.#begin(identifyInvokeInput(input), environment);
|
|
157
|
-
const
|
|
157
|
+
const execution = (async () => {
|
|
158
158
|
for await (const event of this.#execute(run))
|
|
159
159
|
void event;
|
|
160
|
-
})()
|
|
160
|
+
})();
|
|
161
|
+
run.settled = execution;
|
|
162
|
+
const task = execution.catch(() => undefined);
|
|
161
163
|
this.#tasks.add(task);
|
|
162
164
|
void task.finally(() => this.#tasks.delete(task));
|
|
163
165
|
return { ...run.receipt };
|
|
164
166
|
}
|
|
167
|
+
/** 观察指定后台消费的实际结束;终态进入窗口时 finally 可能仍在执行。 */
|
|
168
|
+
settled(receipt) {
|
|
169
|
+
const run = this.#get(receipt.run_id);
|
|
170
|
+
if (run.streamId !== receipt.stream_id)
|
|
171
|
+
throw new Error("STREAM_EXPIRED");
|
|
172
|
+
if (!run.settled)
|
|
173
|
+
throw new Error("RUN_NOT_SUBMITTED");
|
|
174
|
+
return run.settled;
|
|
175
|
+
}
|
|
165
176
|
#append(run, event) {
|
|
166
177
|
if (run.terminal)
|
|
167
178
|
throw new Error("HOST_FRAME_AFTER_TERMINAL");
|
|
@@ -2,9 +2,12 @@ export { type HostedAdapter, type HostedAdapterMetadata, DEFAULT_RUNTIME_LIMITS,
|
|
|
2
2
|
export { HostRunService } from "./host-run-service.js";
|
|
3
3
|
export { createKernelService, type KernelService, type KernelServiceOptions, type KernelServiceStatus } from "./service.js";
|
|
4
4
|
export * from "./lifecycle.js";
|
|
5
|
+
export { RuntimeHomeError, normalizeRuntimeHome, validateRuntimeHome, assertRuntimePath, assertIpcEndpoint, runtimePathFailure, kernelStartupPaths, prepareHomeDirectory, type StartupPathDiagnostic, type RuntimePath } from "./runtime-home.js";
|
|
6
|
+
export * from "./startup-diagnostics.js";
|
|
5
7
|
export { attachKernel } from "./client.js";
|
|
6
8
|
export { AsyncQuestionReply, type AsyncQuestionReplyResult } from "./async-question-reply.js";
|
|
7
|
-
export { isInvocationNotSubmitted } from "./submission-error.js";
|
|
9
|
+
export { isInvocationNotSubmitted, admissionClosedError } from "./submission-error.js";
|
|
8
10
|
export * from "./types.js";
|
|
9
11
|
export { InvocationManifest, acknowledgeOrphanCleanup, inspectOrphanCleanup, reapOrphanedInvocationManifest } from "./invocation-manifest.js";
|
|
10
12
|
export { acquireEndpoint } from "./endpoint.js";
|
|
13
|
+
export { assertStartupLogging } from "./startup-logging.js";
|
|
@@ -3,9 +3,12 @@ export { DEFAULT_RUNTIME_LIMITS, prepareRunContext } from "@mininglamp-oss/octo-
|
|
|
3
3
|
export { HostRunService } from "./host-run-service.js";
|
|
4
4
|
export { createKernelService } from "./service.js";
|
|
5
5
|
export * from "./lifecycle.js";
|
|
6
|
+
export { RuntimeHomeError, normalizeRuntimeHome, validateRuntimeHome, assertRuntimePath, assertIpcEndpoint, runtimePathFailure, kernelStartupPaths, prepareHomeDirectory } from "./runtime-home.js";
|
|
7
|
+
export * from "./startup-diagnostics.js";
|
|
6
8
|
export { attachKernel } from "./client.js";
|
|
7
9
|
export { AsyncQuestionReply } from "./async-question-reply.js";
|
|
8
|
-
export { isInvocationNotSubmitted } from "./submission-error.js";
|
|
10
|
+
export { isInvocationNotSubmitted, admissionClosedError } from "./submission-error.js";
|
|
9
11
|
export * from "./types.js";
|
|
10
12
|
export { InvocationManifest, acknowledgeOrphanCleanup, inspectOrphanCleanup, reapOrphanedInvocationManifest } from "./invocation-manifest.js";
|
|
11
13
|
export { acquireEndpoint } from "./endpoint.js";
|
|
14
|
+
export { assertStartupLogging } from "./startup-logging.js";
|
package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.d.ts
CHANGED
|
@@ -1,53 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { type KernelInvocationRecord, type KernelInvocationLifecycle, type KernelInvocationDrainResult, type LookupKey, type RunRef, type RunSnapshot } from "./types.js";
|
|
3
|
-
export interface TrackedInvocation {
|
|
4
|
-
key: LookupKey;
|
|
5
|
-
ref?: RunRef;
|
|
6
|
-
instance?: string;
|
|
7
|
-
submitted: boolean;
|
|
8
|
-
phase: KernelInvocationRecord["phase"];
|
|
9
|
-
cancellation: KernelInvocationRecord["cancellation"];
|
|
10
|
-
lastSeq: number;
|
|
11
|
-
observationError?: string;
|
|
12
|
-
reason?: string;
|
|
13
|
-
cancelTask?: Promise<{
|
|
14
|
-
accepted: boolean;
|
|
15
|
-
}>;
|
|
16
|
-
admitted: Promise<void>;
|
|
17
|
-
settleAdmission(): void;
|
|
18
|
-
admissionError?: Error;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* 每个 client 独立保存 invoke 的身份、取消和观察状态;执行与断线恢复由 client.ts 负责。
|
|
22
|
-
* 最多登记 128 项,不缓存正文;未知结果继续占用额度,不能通过删除记录伪造排空成功。
|
|
23
|
-
*/
|
|
24
|
-
export declare class InvocationRegistry implements KernelInvocationLifecycle {
|
|
25
|
-
#private;
|
|
26
|
-
private readonly transport;
|
|
27
|
-
constructor(transport: {
|
|
28
|
-
get(key: LookupKey, instance: string, deadline: number, signal: AbortSignal): Promise<RunSnapshot>;
|
|
29
|
-
cancel(ref: RunRef, reason: string, deadline: number, signal: AbortSignal): Promise<{
|
|
30
|
-
accepted: boolean;
|
|
31
|
-
}>;
|
|
32
|
-
});
|
|
33
|
-
begin(key: LookupKey): TrackedInvocation;
|
|
34
|
-
assertSubmission(): void;
|
|
35
|
-
accepted(record: TrackedInvocation, ref: RunRef, terminal?: HostFrame): void;
|
|
36
|
-
reconcile(ref: RunRef, terminal?: HostFrame): void;
|
|
37
|
-
rejected(record: TrackedInvocation, error: unknown): void;
|
|
38
|
-
observe(ref: RunRef, frame: HostFrame): void;
|
|
39
|
-
interrupted(record: TrackedInvocation, error?: unknown): void;
|
|
40
|
-
active(id: string): TrackedInvocation;
|
|
41
|
-
ref(id: string): RunRef;
|
|
42
|
-
cancel(record: TrackedInvocation, reason?: string): Promise<{
|
|
43
|
-
accepted: boolean;
|
|
44
|
-
}>;
|
|
45
|
-
snapshot(): readonly KernelInvocationRecord[];
|
|
46
|
-
stopAdmission(): void;
|
|
47
|
-
close(): void;
|
|
48
|
-
drain(options: {
|
|
49
|
-
deadline: number;
|
|
50
|
-
reason: string;
|
|
51
|
-
}): Promise<KernelInvocationDrainResult>;
|
|
52
|
-
}
|
|
53
|
-
export declare function errorCode(error: unknown): string;
|
|
1
|
+
export { InvocationRegistry, errorCode, type TrackedInvocation } from "@mininglamp-oss/octo-runtime-client/internal";
|
package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.js
CHANGED
|
@@ -1,280 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { isHostTerminal } from "@mininglamp-oss/octo-runtime-protocol";
|
|
4
|
-
import { KernelError } from "./types.js";
|
|
5
|
-
/**
|
|
6
|
-
* 每个 client 独立保存 invoke 的身份、取消和观察状态;执行与断线恢复由 client.ts 负责。
|
|
7
|
-
* 最多登记 128 项,不缓存正文;未知结果继续占用额度,不能通过删除记录伪造排空成功。
|
|
8
|
-
*/
|
|
9
|
-
export class InvocationRegistry {
|
|
10
|
-
transport;
|
|
11
|
-
#records = new Map();
|
|
12
|
-
#stopped = false;
|
|
13
|
-
#draining;
|
|
14
|
-
#drainDeadline;
|
|
15
|
-
#closed = false;
|
|
16
|
-
#cancelling = 0;
|
|
17
|
-
#cancelQueue = [];
|
|
18
|
-
#cancelControllers = new Set();
|
|
19
|
-
constructor(transport) {
|
|
20
|
-
this.transport = transport;
|
|
21
|
-
}
|
|
22
|
-
begin(key) {
|
|
23
|
-
this.assertSubmission();
|
|
24
|
-
if (this.#records.has(key.invocation_id))
|
|
25
|
-
throw new KernelError("EXECUTION_IDENTITY_CONFLICT");
|
|
26
|
-
if (this.#records.size >= 128)
|
|
27
|
-
throw new KernelError("CLIENT_INVOCATION_CAPACITY_EXHAUSTED");
|
|
28
|
-
let settleAdmission;
|
|
29
|
-
const admitted = new Promise((resolve) => {
|
|
30
|
-
settleAdmission = resolve;
|
|
31
|
-
});
|
|
32
|
-
const record = {
|
|
33
|
-
key,
|
|
34
|
-
submitted: false,
|
|
35
|
-
phase: "admitting",
|
|
36
|
-
cancellation: "none",
|
|
37
|
-
lastSeq: 0,
|
|
38
|
-
admitted,
|
|
39
|
-
settleAdmission
|
|
40
|
-
};
|
|
41
|
-
this.#records.set(key.invocation_id, record);
|
|
42
|
-
return record;
|
|
43
|
-
}
|
|
44
|
-
assertSubmission() {
|
|
45
|
-
if (this.#stopped)
|
|
46
|
-
throw admissionClosedError();
|
|
47
|
-
}
|
|
48
|
-
accepted(record, ref, terminal) {
|
|
49
|
-
record.ref = ref;
|
|
50
|
-
record.instance = ref.kernel_instance_id;
|
|
51
|
-
record.phase = "accepted";
|
|
52
|
-
record.settleAdmission();
|
|
53
|
-
if (terminal)
|
|
54
|
-
this.observe(ref, terminal);
|
|
55
|
-
if (record.reason !== undefined && !terminal && this.#records.get(ref.invocation_id) === record)
|
|
56
|
-
void this.cancel(record, record.reason).catch(() => undefined);
|
|
57
|
-
}
|
|
58
|
-
reconcile(ref, terminal) {
|
|
59
|
-
const record = this.#records.get(ref.invocation_id);
|
|
60
|
-
if (!record ||
|
|
61
|
-
(record.instance && record.instance !== ref.kernel_instance_id) ||
|
|
62
|
-
Object.entries(record.key).some(([field, value]) => Reflect.get(ref, field) !== value))
|
|
63
|
-
return;
|
|
64
|
-
if (record.ref &&
|
|
65
|
-
(record.ref.stream_id !== ref.stream_id || record.ref.protocol !== ref.protocol))
|
|
66
|
-
throw new KernelError("RUN_IDENTITY_MISMATCH");
|
|
67
|
-
if (!record.ref)
|
|
68
|
-
this.accepted(record, ref, terminal);
|
|
69
|
-
else if (terminal)
|
|
70
|
-
this.observe(ref, terminal);
|
|
71
|
-
}
|
|
72
|
-
rejected(record, error) {
|
|
73
|
-
if (record.ref) {
|
|
74
|
-
record.settleAdmission();
|
|
75
|
-
this.interrupted(record, error);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
record.admissionError = error instanceof Error ? error : new KernelError("ACCEPTANCE_UNKNOWN");
|
|
79
|
-
record.observationError = errorCode(error);
|
|
80
|
-
record.phase = "acceptance_unknown";
|
|
81
|
-
record.settleAdmission();
|
|
82
|
-
const rejectedByServer = error instanceof KernelError &&
|
|
83
|
-
error.data !== undefined &&
|
|
84
|
-
!["KERNEL_INSTANCE_CHANGED", "RUN_IDENTITY_MISMATCH"].includes(error.code);
|
|
85
|
-
// 仅未发送或明确拒绝可安全移除;已发送但 ACK 未知时保留身份,后续 drain 只能查询确认。
|
|
86
|
-
if (!record.submitted || rejectedByServer)
|
|
87
|
-
this.#records.delete(record.key.invocation_id);
|
|
88
|
-
}
|
|
89
|
-
observe(ref, frame) {
|
|
90
|
-
const record = this.#records.get(ref.invocation_id);
|
|
91
|
-
if (!record ||
|
|
92
|
-
!record.ref ||
|
|
93
|
-
record.ref.stream_id !== ref.stream_id ||
|
|
94
|
-
record.ref.kernel_instance_id !== ref.kernel_instance_id)
|
|
95
|
-
return;
|
|
96
|
-
record.lastSeq = Math.max(record.lastSeq, frame.seq);
|
|
97
|
-
if (!isHostTerminal(frame))
|
|
98
|
-
return;
|
|
99
|
-
if (frame.kind === "control" &&
|
|
100
|
-
frame.control.type === "state" &&
|
|
101
|
-
frame.control.state === "lost") {
|
|
102
|
-
record.phase = "unobserved";
|
|
103
|
-
record.observationError = "RUN_OUTCOME_UNKNOWN";
|
|
104
|
-
}
|
|
105
|
-
else
|
|
106
|
-
this.#records.delete(ref.invocation_id);
|
|
107
|
-
}
|
|
108
|
-
interrupted(record, error) {
|
|
109
|
-
if (this.#records.get(record.key.invocation_id) !== record || !record.ref)
|
|
110
|
-
return;
|
|
111
|
-
record.phase = "unobserved";
|
|
112
|
-
if (error !== undefined)
|
|
113
|
-
record.observationError = errorCode(error);
|
|
114
|
-
}
|
|
115
|
-
active(id) {
|
|
116
|
-
const record = this.#records.get(id);
|
|
117
|
-
if (!record)
|
|
118
|
-
throw new KernelError("INVOCATION_NOT_TRACKED");
|
|
119
|
-
return record;
|
|
120
|
-
}
|
|
121
|
-
ref(id) {
|
|
122
|
-
const record = this.active(id);
|
|
123
|
-
if (!record.ref)
|
|
124
|
-
throw new KernelError("INVOCATION_NOT_ACCEPTED");
|
|
125
|
-
return record.ref;
|
|
126
|
-
}
|
|
127
|
-
cancel(record, reason = "caller_cancelled") {
|
|
128
|
-
if (record.ref && this.#records.get(record.key.invocation_id) !== record)
|
|
129
|
-
return Promise.resolve({ accepted: false });
|
|
130
|
-
if (record.observationError === "RUN_OUTCOME_UNKNOWN")
|
|
131
|
-
return Promise.reject(new KernelError("RUN_OUTCOME_UNKNOWN"));
|
|
132
|
-
record.reason ??= reason;
|
|
133
|
-
if (record.cancellation === "none")
|
|
134
|
-
record.cancellation = "requested";
|
|
135
|
-
// 取消可能早于接纳 ACK:记住首次原因,等同一执行获得 RunRef 后发出一次控制请求。
|
|
136
|
-
if (!record.ref)
|
|
137
|
-
return record.admitted.then(() => {
|
|
138
|
-
if (!record.ref)
|
|
139
|
-
throw record.admissionError ?? new KernelError("ACCEPTANCE_UNKNOWN");
|
|
140
|
-
return this.cancel(record, reason);
|
|
141
|
-
});
|
|
142
|
-
if (!record.cancelTask) {
|
|
143
|
-
const controller = new AbortController();
|
|
144
|
-
this.#cancelControllers.add(controller);
|
|
145
|
-
record.cancelTask = new Promise((resolve, reject) => {
|
|
146
|
-
this.#cancelQueue.push(async () => {
|
|
147
|
-
try {
|
|
148
|
-
if (this.#closed)
|
|
149
|
-
throw new KernelError("CLIENT_CLOSED");
|
|
150
|
-
if (this.#records.get(record.key.invocation_id) !== record) {
|
|
151
|
-
resolve({ accepted: false });
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (record.observationError === "RUN_OUTCOME_UNKNOWN")
|
|
155
|
-
throw new KernelError("RUN_OUTCOME_UNKNOWN");
|
|
156
|
-
const deadline = Math.min(Date.now() + 5000, this.#drainDeadline ?? Infinity);
|
|
157
|
-
if (deadline <= Date.now())
|
|
158
|
-
throw new KernelError("OPERATION_OUTCOME_UNKNOWN");
|
|
159
|
-
resolve(await this.transport.cancel(record.ref, record.reason, deadline, controller.signal));
|
|
160
|
-
}
|
|
161
|
-
catch (error) {
|
|
162
|
-
reject(error instanceof Error ? error : new KernelError("OPERATION_OUTCOME_UNKNOWN"));
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
this.#pumpCancellations();
|
|
166
|
-
})
|
|
167
|
-
.then((result) => {
|
|
168
|
-
record.cancellation = "acknowledged";
|
|
169
|
-
return result;
|
|
170
|
-
})
|
|
171
|
-
.catch((error) => {
|
|
172
|
-
record.cancellation = "unknown";
|
|
173
|
-
record.observationError = errorCode(error);
|
|
174
|
-
throw error;
|
|
175
|
-
})
|
|
176
|
-
.finally(() => this.#cancelControllers.delete(controller));
|
|
177
|
-
// Automatic signal cancellation may outlive its consumer; always consume rejection.
|
|
178
|
-
void record.cancelTask.catch(() => undefined);
|
|
179
|
-
}
|
|
180
|
-
return record.cancelTask;
|
|
181
|
-
}
|
|
182
|
-
#pumpCancellations() {
|
|
183
|
-
while (this.#cancelling < 4 && this.#cancelQueue.length) {
|
|
184
|
-
this.#cancelling++;
|
|
185
|
-
void this.#cancelQueue.shift()().finally(() => {
|
|
186
|
-
this.#cancelling--;
|
|
187
|
-
this.#pumpCancellations();
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
snapshot() {
|
|
192
|
-
return [...this.#records.values()].map((record) => ({
|
|
193
|
-
key: { ...record.key },
|
|
194
|
-
...(record.ref ? { ref: { ...record.ref } } : {}),
|
|
195
|
-
phase: record.phase,
|
|
196
|
-
cancellation: record.cancellation,
|
|
197
|
-
lastSeq: record.lastSeq,
|
|
198
|
-
...(record.observationError ? { observationError: record.observationError } : {})
|
|
199
|
-
}));
|
|
200
|
-
}
|
|
201
|
-
stopAdmission() {
|
|
202
|
-
this.#stopped = true;
|
|
203
|
-
}
|
|
204
|
-
close() {
|
|
205
|
-
this.#closed = true;
|
|
206
|
-
this.stopAdmission();
|
|
207
|
-
for (const controller of this.#cancelControllers)
|
|
208
|
-
controller.abort();
|
|
209
|
-
}
|
|
210
|
-
drain(options) {
|
|
211
|
-
if (!Number.isSafeInteger(options.deadline) || options.deadline - Date.now() > 2_147_483_647)
|
|
212
|
-
throw new KernelError("INVOCATION_DEADLINE_INVALID");
|
|
213
|
-
// 首次关闭锁定绝对期限;重复调用不能延长预算,也不能启动第二轮取消副作用。
|
|
214
|
-
if (this.#draining)
|
|
215
|
-
return this.#draining;
|
|
216
|
-
this.stopAdmission();
|
|
217
|
-
this.#drainDeadline = options.deadline;
|
|
218
|
-
return (this.#draining = this.#drain(options));
|
|
219
|
-
}
|
|
220
|
-
async #drain({ deadline, reason }) {
|
|
221
|
-
const controller = new AbortController();
|
|
222
|
-
const timer = setTimeout(() => {
|
|
223
|
-
controller.abort();
|
|
224
|
-
for (const cancelController of this.#cancelControllers)
|
|
225
|
-
cancelController.abort();
|
|
226
|
-
}, Math.max(0, deadline - Date.now()));
|
|
227
|
-
try {
|
|
228
|
-
while (this.#records.size && !controller.signal.aborted && Date.now() < deadline) {
|
|
229
|
-
const records = [...this.#records.values()];
|
|
230
|
-
// 最多四路查询/控制 IO;只查终态元数据,不新增正文订阅,避免与业务消费者争夺尾流。
|
|
231
|
-
let index = 0;
|
|
232
|
-
await Promise.all(Array.from({ length: Math.min(4, records.length) }, async () => {
|
|
233
|
-
while (index < records.length && !controller.signal.aborted && Date.now() < deadline) {
|
|
234
|
-
const record = records[index++];
|
|
235
|
-
record.reason ??= reason;
|
|
236
|
-
if (record.cancellation === "none")
|
|
237
|
-
record.cancellation = "requested";
|
|
238
|
-
if (!record.instance)
|
|
239
|
-
continue;
|
|
240
|
-
try {
|
|
241
|
-
const info = await this.transport.get(record.key, record.instance, deadline, controller.signal);
|
|
242
|
-
if (!record.ref)
|
|
243
|
-
this.accepted(record, info.ref);
|
|
244
|
-
if (info.terminal)
|
|
245
|
-
this.observe(info.ref, info.terminal);
|
|
246
|
-
if (!this.#records.has(record.key.invocation_id))
|
|
247
|
-
continue;
|
|
248
|
-
// lost 表示执行结果未知,必须留在 unresolved,不能据此重放可能已有副作用的执行。
|
|
249
|
-
if (record.observationError !== "RUN_OUTCOME_UNKNOWN")
|
|
250
|
-
await this.cancel(record, reason);
|
|
251
|
-
}
|
|
252
|
-
catch (error) {
|
|
253
|
-
if (record.observationError !== "RUN_OUTCOME_UNKNOWN")
|
|
254
|
-
record.observationError = errorCode(error);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}));
|
|
258
|
-
if (this.#records.size && Date.now() < deadline) {
|
|
259
|
-
await delay(Math.min(100, deadline - Date.now()), undefined, {
|
|
260
|
-
signal: controller.signal
|
|
261
|
-
}).catch(() => undefined);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return { complete: this.#records.size === 0, unresolved: this.snapshot() };
|
|
265
|
-
}
|
|
266
|
-
finally {
|
|
267
|
-
clearTimeout(timer);
|
|
268
|
-
controller.abort();
|
|
269
|
-
for (const cancelController of this.#cancelControllers)
|
|
270
|
-
cancelController.abort();
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
export function errorCode(error) {
|
|
275
|
-
return error instanceof KernelError
|
|
276
|
-
? error.code
|
|
277
|
-
: error instanceof Error && /^[A-Z][A-Z0-9_]+$/.test(error.message)
|
|
278
|
-
? error.message
|
|
279
|
-
: "INVOCATION_OBSERVATION_FAILED";
|
|
280
|
-
}
|
|
1
|
+
// 兼容旧入口;客户端状态、错误身份和恢复实现由独立包统一持有。
|
|
2
|
+
export { InvocationRegistry, errorCode } from "@mininglamp-oss/octo-runtime-client/internal";
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
readonly errors: readonly {
|
|
5
|
-
resource: string;
|
|
6
|
-
code: string;
|
|
7
|
-
}[];
|
|
8
|
-
readonly pendingResources: readonly string[];
|
|
9
|
-
}
|
|
1
|
+
import { type StartupDiagnostic, type StartupLocation } from "./startup-diagnostics.js";
|
|
2
|
+
import type { ServiceCleanupResult } from "@mininglamp-oss/octo-runtime-client/internal";
|
|
3
|
+
export type { ServiceCleanupResult, ServicePhase } from "@mininglamp-oss/octo-runtime-client/internal";
|
|
10
4
|
export interface ServiceLifecycle<S> {
|
|
11
5
|
initialize(options?: {
|
|
12
6
|
signal?: AbortSignal;
|
|
@@ -17,7 +11,8 @@ export interface ServiceLifecycle<S> {
|
|
|
17
11
|
}
|
|
18
12
|
export declare class ServiceInitializationError extends Error {
|
|
19
13
|
readonly cleanup: ServiceCleanupResult;
|
|
20
|
-
|
|
14
|
+
readonly diagnostic: StartupDiagnostic;
|
|
15
|
+
constructor(cause: unknown, cleanup: ServiceCleanupResult, location?: StartupLocation);
|
|
21
16
|
}
|
|
22
17
|
/** 所有阶段共用停止起点,超时只结束等待,不代表底层资源已释放。 */
|
|
23
18
|
export declare function beforeDeadline<T>(operation: Promise<T>, until: number): Promise<T>;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { describeStartupError } from "./startup-diagnostics.js";
|
|
1
2
|
export class ServiceInitializationError extends Error {
|
|
2
3
|
cleanup;
|
|
3
|
-
|
|
4
|
+
diagnostic;
|
|
5
|
+
constructor(cause, cleanup, location = { component: "host", phase: "initializing" }) {
|
|
4
6
|
super("SERVICE_INITIALIZATION_FAILED", { cause });
|
|
5
7
|
this.cleanup = cleanup;
|
|
6
8
|
this.name = "ServiceInitializationError";
|
|
9
|
+
this.diagnostic = describeStartupError(this, location);
|
|
7
10
|
}
|
|
8
11
|
}
|
|
9
12
|
/** 所有阶段共用停止起点,超时只结束等待,不代表底层资源已释放。 */
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RuntimeHomeError } from "@mininglamp-oss/octo-runtime-client/internal";
|
|
2
|
+
export { RuntimeHomeError, normalizeRuntimeHome, assertRuntimePath, assertIpcEndpoint, type StartupPathDiagnostic } from "@mininglamp-oss/octo-runtime-client/internal";
|
|
3
|
+
export interface RuntimePath {
|
|
4
|
+
path: string;
|
|
5
|
+
resource: string;
|
|
6
|
+
/** 可选日志只校验名称预算,IO 可用性由既有 best-effort 日志层处理。 */
|
|
7
|
+
optional?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 宿主先准备根目录;SDK 在资源启动前只验证,不 mkdir 根或选择替代目录。
|
|
11
|
+
* access 后用独占短探针确认真实读写权限(Windows access 不能完整判断 ACL),不改变身份/配置。
|
|
12
|
+
* 这是同账号信任边界内的启动检查,不承诺对同账号并发替换目录提供文件系统沙箱。
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateRuntimeHome(input: string, paths?: readonly RuntimePath[]): string;
|
|
15
|
+
/** 只创建已验证 Home 内的子目录,逐级 mkdir;根消失时失败,绝不递归补建根。 */
|
|
16
|
+
export declare function prepareHomeDirectory(home: string, directory: string): void;
|
|
17
|
+
/** 将实际系统 IO 失败投影为启动诊断,保留必要 errno 但不公开系统错误正文。 */
|
|
18
|
+
export declare function runtimePathFailure(error: unknown, path: string, resource: string, operation: string): RuntimeHomeError;
|
|
19
|
+
/** 所有启动资源先列出完整最终文件名,覆盖原子写、恢复归档与轮转锁的额外后缀。 */
|
|
20
|
+
export declare function kernelStartupPaths(endpoint: string, stateDirectory?: string, logDirectory?: string): RuntimePath[];
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { accessSync, closeSync, constants, mkdirSync, opendirSync, openSync, statSync, unlinkSync } from "node:fs";
|
|
4
|
+
import { posix, win32 } from "node:path";
|
|
5
|
+
import { RuntimeHomeError, normalizeRuntimeHome, assertRuntimePath, platformLimits } from "@mininglamp-oss/octo-runtime-client/internal";
|
|
6
|
+
export { RuntimeHomeError, normalizeRuntimeHome, assertRuntimePath, assertIpcEndpoint } from "@mininglamp-oss/octo-runtime-client/internal";
|
|
7
|
+
/**
|
|
8
|
+
* 宿主先准备根目录;SDK 在资源启动前只验证,不 mkdir 根或选择替代目录。
|
|
9
|
+
* access 后用独占短探针确认真实读写权限(Windows access 不能完整判断 ACL),不改变身份/配置。
|
|
10
|
+
* 这是同账号信任边界内的启动检查,不承诺对同账号并发替换目录提供文件系统沙箱。
|
|
11
|
+
*/
|
|
12
|
+
export function validateRuntimeHome(input, paths = []) {
|
|
13
|
+
const home = normalizeRuntimeHome(input);
|
|
14
|
+
let operation = "stat";
|
|
15
|
+
let affected = home;
|
|
16
|
+
let resource = "home";
|
|
17
|
+
try {
|
|
18
|
+
assertRuntimePath(home, "home");
|
|
19
|
+
if (!statSync(home).isDirectory())
|
|
20
|
+
throw new RuntimeHomeError({
|
|
21
|
+
code: "HOME_NOT_DIRECTORY",
|
|
22
|
+
path: home,
|
|
23
|
+
resource: "home",
|
|
24
|
+
operation
|
|
25
|
+
});
|
|
26
|
+
operation = "filesystem-limits";
|
|
27
|
+
const cache = new Map();
|
|
28
|
+
const filesystemLimits = (path) => {
|
|
29
|
+
if (process.platform === "win32")
|
|
30
|
+
return platformLimits(process.platform);
|
|
31
|
+
// 日志/状态可由高级宿主选择在另一文件系统;不能把 Home 所在卷的预算套给它。
|
|
32
|
+
let directory = path;
|
|
33
|
+
for (;;) {
|
|
34
|
+
try {
|
|
35
|
+
if (statSync(directory).isDirectory())
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
const code = error.code;
|
|
40
|
+
// 子路径缺失/被普通文件阻断时仍可查询最近目录;其他 IO 失败由调用方按资源必要性处理。
|
|
41
|
+
if (!["ENOENT", "ENOTDIR"].includes(code ?? ""))
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
const parent = posix.dirname(directory);
|
|
45
|
+
if (parent === directory)
|
|
46
|
+
throw new Error("PATH_LIMIT_UNAVAILABLE");
|
|
47
|
+
directory = parent;
|
|
48
|
+
}
|
|
49
|
+
const cached = cache.get(directory);
|
|
50
|
+
if (cached)
|
|
51
|
+
return cached;
|
|
52
|
+
const query = (name) => {
|
|
53
|
+
operation = "getconf";
|
|
54
|
+
const value = Number(
|
|
55
|
+
// 使用 OS 工具的固定位置;宿主可能为 Provider 注入受限 PATH,不能据此选择查询程序。
|
|
56
|
+
execFileSync("/usr/bin/getconf", [name, directory], {
|
|
57
|
+
encoding: "utf8",
|
|
58
|
+
timeout: 1000,
|
|
59
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
60
|
+
}).trim());
|
|
61
|
+
if (!Number.isSafeInteger(value) || value < 1)
|
|
62
|
+
throw new Error("PATH_LIMIT_UNAVAILABLE");
|
|
63
|
+
return value;
|
|
64
|
+
};
|
|
65
|
+
const limits = { path: query("PATH_MAX") - 1, name: query("NAME_MAX") };
|
|
66
|
+
cache.set(directory, limits);
|
|
67
|
+
return limits;
|
|
68
|
+
};
|
|
69
|
+
const limits = filesystemLimits(home);
|
|
70
|
+
for (const entry of [{ path: home, resource: "home", optional: false }, ...paths]) {
|
|
71
|
+
affected = entry.path;
|
|
72
|
+
resource = entry.resource;
|
|
73
|
+
normalizeRuntimeHome(entry.path, process.platform, entry.resource);
|
|
74
|
+
assertRuntimePath(entry.path, entry.resource);
|
|
75
|
+
operation = "filesystem-limits";
|
|
76
|
+
let observed;
|
|
77
|
+
try {
|
|
78
|
+
observed = filesystemLimits(entry.path);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
// 可选日志的 stat/getconf 失败(循环链接、坏盘等)仍归日志层 best-effort 隔离,不能枚举少数 errno。
|
|
82
|
+
// 前面的输入/静态长度检查不在此隔离范围;Home 和状态等必需资源仍传播原始 IO 失败。
|
|
83
|
+
if (!entry.optional)
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
if (observed)
|
|
87
|
+
assertRuntimePath(entry.path, entry.resource, process.platform, observed);
|
|
88
|
+
}
|
|
89
|
+
affected = home;
|
|
90
|
+
resource = "home";
|
|
91
|
+
operation = "access";
|
|
92
|
+
accessSync(home, constants.R_OK | constants.W_OK | constants.X_OK);
|
|
93
|
+
operation = "read-directory";
|
|
94
|
+
opendirSync(home).closeSync();
|
|
95
|
+
operation = "write-probe";
|
|
96
|
+
const probe = (process.platform === "win32" ? win32 : posix).join(home, `.octo-home-${randomUUID()}`);
|
|
97
|
+
assertRuntimePath(probe, "home-probe", process.platform, limits);
|
|
98
|
+
affected = probe;
|
|
99
|
+
const fd = openSync(probe, "wx", 0o600);
|
|
100
|
+
try {
|
|
101
|
+
closeSync(fd);
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
unlinkSync(probe);
|
|
105
|
+
}
|
|
106
|
+
return home;
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
if (error instanceof RuntimeHomeError)
|
|
110
|
+
throw error;
|
|
111
|
+
throw runtimePathFailure(error, affected, resource, operation);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** 只创建已验证 Home 内的子目录,逐级 mkdir;根消失时失败,绝不递归补建根。 */
|
|
115
|
+
export function prepareHomeDirectory(home, directory) {
|
|
116
|
+
const api = process.platform === "win32" ? win32 : posix;
|
|
117
|
+
const child = api.relative(home, directory);
|
|
118
|
+
if (!child || child.startsWith(`..${api.sep}`) || child === ".." || api.isAbsolute(child))
|
|
119
|
+
return;
|
|
120
|
+
let current = home;
|
|
121
|
+
for (const part of child.split(api.sep)) {
|
|
122
|
+
current = api.join(current, part);
|
|
123
|
+
try {
|
|
124
|
+
mkdirSync(current, { mode: 0o700 });
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
if (error.code === "EEXIST" && statSync(current).isDirectory())
|
|
128
|
+
continue;
|
|
129
|
+
throw runtimePathFailure(error, current, "runtime-directory", "mkdir");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** 将实际系统 IO 失败投影为启动诊断,保留必要 errno 但不公开系统错误正文。 */
|
|
134
|
+
export function runtimePathFailure(error, path, resource, operation) {
|
|
135
|
+
const raw = error instanceof Error && "code" in error ? error.code : undefined;
|
|
136
|
+
const systemCode = typeof raw === "string" && /^[A-Z][A-Z0-9_]+$/.test(raw) ? raw : undefined;
|
|
137
|
+
const code = operation === "getconf"
|
|
138
|
+
? "HOME_LIMIT_UNAVAILABLE"
|
|
139
|
+
: systemCode === "ENOENT"
|
|
140
|
+
? "HOME_NOT_FOUND"
|
|
141
|
+
: systemCode === "ENOTDIR"
|
|
142
|
+
? "HOME_NOT_DIRECTORY"
|
|
143
|
+
: ["EACCES", "EPERM", "EROFS"].includes(systemCode ?? "")
|
|
144
|
+
? "HOME_PERMISSION_DENIED"
|
|
145
|
+
: systemCode === "ENAMETOOLONG"
|
|
146
|
+
? "HOME_PATH_TOO_LONG"
|
|
147
|
+
: operation === "filesystem-limits"
|
|
148
|
+
? "HOME_LIMIT_UNAVAILABLE"
|
|
149
|
+
: "HOME_UNUSABLE";
|
|
150
|
+
return new RuntimeHomeError({
|
|
151
|
+
code,
|
|
152
|
+
path,
|
|
153
|
+
resource,
|
|
154
|
+
operation,
|
|
155
|
+
...(systemCode ? { systemCode } : {})
|
|
156
|
+
}, error);
|
|
157
|
+
}
|
|
158
|
+
/** 所有启动资源先列出完整最终文件名,覆盖原子写、恢复归档与轮转锁的额外后缀。 */
|
|
159
|
+
export function kernelStartupPaths(endpoint, stateDirectory, logDirectory) {
|
|
160
|
+
const paths = [];
|
|
161
|
+
if (process.platform !== "win32")
|
|
162
|
+
paths.push({ path: `${endpoint}.owner.recovery`, resource: "endpoint-ownership" });
|
|
163
|
+
const statePath = stateDirectory
|
|
164
|
+
? (process.platform === "win32" ? win32 : posix).join(stateDirectory, "kernel-invocations.json")
|
|
165
|
+
: process.platform !== "win32"
|
|
166
|
+
? `${endpoint}.runs`
|
|
167
|
+
: undefined;
|
|
168
|
+
if (statePath)
|
|
169
|
+
paths.push({
|
|
170
|
+
path: `${statePath}.acknowledged.${"0".repeat(36)}.json`,
|
|
171
|
+
resource: "kernel-state"
|
|
172
|
+
});
|
|
173
|
+
if (logDirectory)
|
|
174
|
+
paths.push({
|
|
175
|
+
path: (process.platform === "win32" ? win32 : posix).join(logDirectory, "kernel-status-20000101T00.log.lock"),
|
|
176
|
+
resource: "kernel-log",
|
|
177
|
+
optional: true
|
|
178
|
+
});
|
|
179
|
+
return paths;
|
|
180
|
+
}
|