maka-agent 0.2.0-dev.23.20260906 → 0.2.0-dev.25.20260908
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 +38 -19
- package/README.zh-CN.md +34 -19
- package/dist/acp/maka-acp-agent.js +2 -1
- package/dist/acp/session-configuration.js +143 -0
- package/dist/acp/session-registry.js +90 -4
- package/dist/cli-core.js +2 -0
- package/dist/pi-transcript-tools.js +6 -0
- package/dist/pi-transcript.js +5 -12
- package/dist/pi-tui-layout.js +56 -10
- package/dist/pi-tui-pickers.js +102 -1
- package/dist/pi-tui-runner.js +230 -46
- package/dist/pi-tui-todo.js +221 -0
- package/dist/pi-tui-transcript-viewer.js +134 -7
- package/dist/runtime-host-cli-context.js +224 -78
- package/dist/runtime-host-cli-installation.js +8 -2
- package/dist/runtime-host-cli.js +31 -1
- package/dist/runtime-host-handoff-surface.js +106 -0
- package/dist/runtime-host-installed-update-bootstrap.js +13 -0
- package/dist/runtime-host-installed-update-coordinator.js +33 -0
- package/dist/runtime-host-lifecycle-transaction.js +9 -1
- package/dist/runtime-host-local-handoff.js +48 -5
- package/dist/runtime-host-local-managed-activation.js +84 -0
- package/dist/runtime-host-local-source-retirement.js +18 -2
- package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
- package/dist/runtime-host-operator-retirement.js +50 -0
- package/dist/runtime-host-service-manager.js +3 -3
- package/dist/runtime-host-session-channel.js +13 -0
- package/dist/runtime-host-session-driver.js +46 -26
- package/dist/runtime-host-session-update.js +62 -0
- package/dist/runtime-host-tui-command.js +38 -73
- package/dist/runtime-host-tui-context.js +1 -0
- package/dist/runtime-host-tui-owner.js +226 -0
- package/dist/tui-copy-catalog.js +219 -6
- package/dist/tui-host-owner-copy.js +24 -0
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/agent-run.js +1 -0
- package/node_modules/@maka/core/dist/attachments.js +3 -0
- package/node_modules/@maka/core/dist/canonical-json.js +27 -0
- package/node_modules/@maka/core/dist/canonical-runtime-event.js +3 -1
- package/node_modules/@maka/core/dist/capabilities.js +35 -0
- package/node_modules/@maka/core/dist/computer-use.js +0 -1
- package/node_modules/@maka/core/dist/display-redaction.js +18 -0
- package/node_modules/@maka/core/dist/llm-connections.js +13 -0
- package/node_modules/@maka/core/dist/model-call-attempt.js +2 -0
- package/node_modules/@maka/core/dist/model-failure.js +40 -0
- package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -4
- package/node_modules/@maka/core/dist/model-metadata.js +7 -3
- package/node_modules/@maka/core/dist/model-web-search.js +5 -4
- package/node_modules/@maka/core/dist/provider-registry.js +45 -4
- package/node_modules/@maka/core/dist/record-schema.js +9 -2
- package/node_modules/@maka/core/dist/redaction.js +35 -0
- package/node_modules/@maka/core/dist/run-composition.js +77 -2
- package/node_modules/@maka/core/dist/runtime-boundary.js +31 -11
- package/node_modules/@maka/core/dist/runtime-event.js +37 -6
- package/node_modules/@maka/core/dist/runtime-handoff.js +98 -0
- package/node_modules/@maka/core/dist/runtime-invocation.js +1 -1
- package/node_modules/@maka/core/dist/runtime-logical-execution.js +112 -0
- package/node_modules/@maka/core/dist/session.js +84 -56
- package/node_modules/@maka/core/dist/slash-command-catalog.js +3 -0
- package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +20 -0
- package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
- package/node_modules/@maka/core/dist/usage-record-schema.js +26 -35
- package/node_modules/@maka/core/package.json +5 -0
- package/node_modules/@maka/eval/dist/experiment-directory.js +4 -13
- package/node_modules/@maka/mcp/dist/index.js +131 -1
- package/node_modules/@maka/runtime/dist/agent-run-inspect.js +0 -13
- package/node_modules/@maka/runtime/dist/agent-run.js +351 -105
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +29 -13
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +109 -34
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +184 -183
- package/node_modules/@maka/runtime/dist/archive-read-tool.js +2 -2
- package/node_modules/@maka/runtime/dist/context-budget-helpers.js +0 -16
- package/node_modules/@maka/runtime/dist/context-budget.js +14 -9
- package/node_modules/@maka/runtime/dist/conversation-copy.js +158 -15
- package/node_modules/@maka/runtime/dist/github-copilot-oauth-enrollment.js +3 -3
- package/node_modules/@maka/runtime/dist/goal-continuation.js +36 -4
- package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +18 -9
- package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +30 -22
- package/node_modules/@maka/runtime/dist/history-compaction.js +29 -4
- package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +174 -0
- package/node_modules/@maka/runtime/dist/mcp-tools.js +7 -2
- package/node_modules/@maka/runtime/dist/message-authority.js +9 -0
- package/node_modules/@maka/runtime/dist/model-adapter.js +19 -98
- package/node_modules/@maka/runtime/dist/model-factory.js +19 -81
- package/node_modules/@maka/runtime/dist/model-fetcher.js +49 -2
- package/node_modules/@maka/runtime/dist/model-history.js +0 -112
- package/node_modules/@maka/runtime/dist/model-runtime.js +85 -111
- package/node_modules/@maka/runtime/dist/native-web-search-tool.js +2 -1
- package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +2 -2
- package/node_modules/@maka/runtime/dist/opencode-session-header.js +4 -2
- package/node_modules/@maka/runtime/dist/plugin-runtime.js +20 -10
- package/node_modules/@maka/runtime/dist/plugin-tool-service.js +205 -0
- package/node_modules/@maka/runtime/dist/provider-error-classification.js +84 -123
- package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +76 -109
- package/node_modules/@maka/runtime/dist/request-shape.js +23 -0
- package/node_modules/@maka/runtime/dist/run-handoff-gate.js +97 -0
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +83 -55
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +121 -159
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +157 -112
- package/node_modules/@maka/runtime/dist/runtime-ledger-repair.js +160 -79
- package/node_modules/@maka/runtime/dist/runtime-read-model.js +30 -89
- package/node_modules/@maka/runtime/dist/runtime-resume.js +80 -4
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +5 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +171 -288
- package/node_modules/@maka/runtime/dist/session-projection-helpers.js +0 -27
- package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +21 -0
- package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +0 -5
- package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +3 -4
- package/node_modules/@maka/runtime/dist/test-connection.js +16 -17
- package/node_modules/@maka/runtime/dist/tool-activation-identity.js +41 -0
- package/node_modules/@maka/runtime/dist/tool-availability.js +11 -1
- package/node_modules/@maka/runtime/dist/tool-result-archive-encoding.js +38 -0
- package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +63 -1
- package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +42 -12
- package/node_modules/@maka/runtime/dist/tool-result-archive.js +27 -4
- package/node_modules/@maka/runtime/dist/tool-runtime.js +3 -61
- package/node_modules/@maka/runtime/package.json +2 -0
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +35 -0
- package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +9 -1
- package/node_modules/@maka/runtime-host/dist/client/connection.js +3 -0
- package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +179 -0
- package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +275 -0
- package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +26 -5
- package/node_modules/@maka/runtime-host/dist/client/index.js +2 -0
- package/node_modules/@maka/runtime-host/dist/client/launcher.js +3 -0
- package/node_modules/@maka/runtime-host/dist/client/remote-compatibility-error.js +2 -0
- package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +46 -5
- package/node_modules/@maka/runtime-host/dist/control/endpoint.js +1 -3
- package/node_modules/@maka/runtime-host/dist/node-error.js +22 -0
- package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
- package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +1 -3
- package/node_modules/@maka/runtime-host/dist/operator/retirement-cancellation.js +20 -0
- package/node_modules/@maka/runtime-host/dist/peer-mesh/limits.js +0 -1
- package/node_modules/@maka/runtime-host/dist/peer-mesh/model.js +1 -1
- package/node_modules/@maka/runtime-host/dist/peer-reachability/publisher.js +1 -3
- package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +21 -12
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +29 -1
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/plan.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +27 -5
- package/node_modules/@maka/runtime-host/dist/protocol/project-catalog.js +2 -2
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +40 -20
- package/node_modules/@maka/runtime-host/dist/protocol/session-transcript.js +0 -5
- package/node_modules/@maka/runtime-host/dist/protocol/session-turns.js +29 -58
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +11 -1
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +31 -2
- package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/agent-graph-coordinator.js +0 -3
- package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +19 -4
- package/node_modules/@maka/runtime-host/dist/server/connection-session.js +7 -6
- package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +32 -32
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +144 -33
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +5 -5
- package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +45 -16
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +40 -1
- package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +96 -17
- package/node_modules/@maka/runtime-host/dist/server/host-residency-registry.js +13 -7
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-admission-registry.js +3 -1
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +124 -62
- package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +47 -22
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +76 -6
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +6 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +6 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +325 -73
- package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +37 -2
- package/node_modules/@maka/runtime-host/dist/server/serial-outbound-writer.js +45 -3
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +50 -7
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +87 -25
- package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +5 -2
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +12 -55
- package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +1 -16
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +0 -1
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +460 -70
- package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/storage-maintenance.js +109 -0
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +20 -2
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +13 -4
- package/node_modules/@maka/runtime-host/dist/server/workhub-message-attachments.js +46 -0
- package/node_modules/@maka/storage/dist/artifact-store.js +21 -10
- package/node_modules/@maka/storage/dist/artifact-stores.js +1 -1
- package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +0 -5
- package/node_modules/@maka/storage/dist/codex-session-adapter.js +284 -198
- package/node_modules/@maka/storage/dist/context-offload-snapshot.js +325 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +9 -7
- package/node_modules/@maka/storage/dist/file-session-repository.js +1012 -0
- package/node_modules/@maka/storage/dist/git-exec.js +61 -0
- package/node_modules/@maka/storage/dist/git-worktree-child-executor.js +8 -35
- package/node_modules/@maka/storage/dist/goal-authority.js +2 -2
- package/node_modules/@maka/storage/dist/interaction-store.js +2 -2
- package/node_modules/@maka/storage/dist/opencode-session-adapter.js +0 -4
- package/node_modules/@maka/storage/dist/operational-state-backup.js +9 -5
- package/node_modules/@maka/storage/dist/project-catalog.js +2 -23
- package/node_modules/@maka/storage/dist/runtime-event-invariants.js +2 -2
- package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
- package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +8 -3
- package/node_modules/@maka/storage/dist/runtime-transcript-query.js +308 -0
- package/node_modules/@maka/storage/dist/scheduled-task-store.js +249 -283
- package/node_modules/@maka/storage/dist/session-bundle-manifest.js +5 -17
- package/node_modules/@maka/storage/dist/session-bundle-policy.js +26 -5
- package/node_modules/@maka/storage/dist/session-copy-cleanup.js +2 -1
- package/node_modules/@maka/storage/dist/session-message-projection.js +15 -0
- package/node_modules/@maka/storage/dist/session-repository.js +767 -0
- package/node_modules/@maka/storage/dist/session-store.js +25 -99
- package/node_modules/@maka/storage/dist/sqlite-artifact-metadata.js +10 -3
- package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +24 -8
- package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +7 -1
- package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +44 -1
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +130 -27
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +109 -892
- package/node_modules/@maka/storage/dist/storage-id.js +28 -0
- package/node_modules/@maka/storage/dist/tool-result-archive-evidence.js +138 -0
- package/node_modules/@maka/storage/dist/workspace-identity.js +2 -15
- package/node_modules/@maka/storage/dist/workspace-version-authority-internal.js +1 -8
- package/node_modules/@maka/storage/package.json +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { randomUUID } from 'node:crypto';
|
|
20
|
+
import { isHostActivityIdle } from '../protocol/host-status.js';
|
|
21
|
+
import { RuntimeHostPermanentReconnectError } from './reconnect-lifecycle.js';
|
|
22
|
+
import { formatHostHandoff } from './host-handoff-copy.js';
|
|
23
|
+
import { redactSecrets } from '@maka/core/redaction';
|
|
24
|
+
export class HostHandoffCancelledError extends RuntimeHostPermanentReconnectError {
|
|
25
|
+
code = 'runtime_host_handoff_cancelled';
|
|
26
|
+
constructor() {
|
|
27
|
+
super('Runtime Host handoff was cancelled');
|
|
28
|
+
this.name = 'HostHandoffCancelledError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Noninteractive callers receive the same decision instead of prompting or silently stopping work. */
|
|
32
|
+
export class HostHandoffRequiredError extends RuntimeHostPermanentReconnectError {
|
|
33
|
+
view;
|
|
34
|
+
code = 'runtime_host_handoff_required';
|
|
35
|
+
constructor(view) {
|
|
36
|
+
const copy = formatHostHandoff(view, 'en');
|
|
37
|
+
super([copy.title, copy.description, copy.detail, view.diagnostic].filter(Boolean).join('\n'));
|
|
38
|
+
this.view = view;
|
|
39
|
+
this.name = 'HostHandoffRequiredError';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** One live attempt; persisted deployment transactions remain the sole recovery authority. */
|
|
43
|
+
export async function runHostHandoff(input) {
|
|
44
|
+
const interval = input.pollIntervalMs ?? 1_000;
|
|
45
|
+
if (!Number.isFinite(interval) || interval <= 0)
|
|
46
|
+
throw new RangeError('Invalid handoff observation interval');
|
|
47
|
+
let surface;
|
|
48
|
+
let view;
|
|
49
|
+
let signature;
|
|
50
|
+
let choice;
|
|
51
|
+
let wake;
|
|
52
|
+
let attemptAbort;
|
|
53
|
+
let cancelled = false;
|
|
54
|
+
// Admission can refuse an apparently idle snapshot. Do not turn that race
|
|
55
|
+
// (or a broken successor) into an automatic replacement storm.
|
|
56
|
+
const attempted = new Set();
|
|
57
|
+
let automaticAttempts = 0;
|
|
58
|
+
let recovery;
|
|
59
|
+
const publish = (next) => {
|
|
60
|
+
view = next;
|
|
61
|
+
surface?.update(next);
|
|
62
|
+
};
|
|
63
|
+
const submit = (revision, action) => {
|
|
64
|
+
if (!view || revision !== view.revision || !view.actions.includes(action))
|
|
65
|
+
return;
|
|
66
|
+
if (view.state === 'progress') {
|
|
67
|
+
if (action !== 'cancel' || cancelled)
|
|
68
|
+
return;
|
|
69
|
+
cancelled = true;
|
|
70
|
+
attemptAbort?.abort(new HostHandoffCancelledError());
|
|
71
|
+
publish({ ...view, revision: randomUUID(), actions: [] });
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (choice)
|
|
75
|
+
return;
|
|
76
|
+
choice = { revision, action };
|
|
77
|
+
wake?.();
|
|
78
|
+
};
|
|
79
|
+
try {
|
|
80
|
+
for (;;) {
|
|
81
|
+
input.signal?.throwIfAborted();
|
|
82
|
+
if (cancelled)
|
|
83
|
+
throw new HostHandoffCancelledError();
|
|
84
|
+
if (choice?.action === 'cancel')
|
|
85
|
+
throw new HostHandoffCancelledError();
|
|
86
|
+
// Every action, including an explicit interruption, gets a fresh observation.
|
|
87
|
+
// Final identity/admission fencing is still the mutation adapter's responsibility.
|
|
88
|
+
let observed;
|
|
89
|
+
try {
|
|
90
|
+
observed = await input.observe(input.signal);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
input.signal?.throwIfAborted();
|
|
94
|
+
if (!view)
|
|
95
|
+
throw error;
|
|
96
|
+
// Lost observation is not permission to reuse the last mutation capability.
|
|
97
|
+
// Keep this journey visible and retry without chaining a fatal dialog.
|
|
98
|
+
observed = {
|
|
99
|
+
kind: 'blocked',
|
|
100
|
+
blocker: {
|
|
101
|
+
identity: JSON.stringify(['unavailable', view.target]),
|
|
102
|
+
target: view.target,
|
|
103
|
+
reason: 'unavailable',
|
|
104
|
+
mayExitNaturally: false,
|
|
105
|
+
diagnostic: boundedDiagnostic(error),
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (observed.kind === 'ready') {
|
|
110
|
+
if (input.signal?.aborted ||
|
|
111
|
+
choice?.action === 'cancel') {
|
|
112
|
+
await observed.value.close();
|
|
113
|
+
input.signal?.throwIfAborted();
|
|
114
|
+
throw new HostHandoffCancelledError();
|
|
115
|
+
}
|
|
116
|
+
return observed.value;
|
|
117
|
+
}
|
|
118
|
+
input.signal?.throwIfAborted();
|
|
119
|
+
// Cancellation belongs to the attempt, not to the observed Host. A new
|
|
120
|
+
// epoch or newly idle snapshot must not erase a click made during observe.
|
|
121
|
+
if (choice?.action === 'cancel') {
|
|
122
|
+
throw new HostHandoffCancelledError();
|
|
123
|
+
}
|
|
124
|
+
const blocker = observed.blocker;
|
|
125
|
+
if (recovery?.identity !== blocker.identity)
|
|
126
|
+
recovery = undefined;
|
|
127
|
+
const nextSignature = blockerSignature(blocker);
|
|
128
|
+
if (signature !== nextSignature) {
|
|
129
|
+
signature = nextSignature;
|
|
130
|
+
choice = undefined;
|
|
131
|
+
publish(projectBlocker(blocker, randomUUID(), recovery?.diagnostic));
|
|
132
|
+
}
|
|
133
|
+
const current = view;
|
|
134
|
+
const selected = choice;
|
|
135
|
+
choice = undefined;
|
|
136
|
+
if (selected?.action === 'cancel')
|
|
137
|
+
throw new HostHandoffCancelledError();
|
|
138
|
+
const cooperative = blocker.target.location === 'local' &&
|
|
139
|
+
blocker.activity?.cooperativeHandoff === true &&
|
|
140
|
+
blocker.activity.connections === 0 &&
|
|
141
|
+
blocker.activity.activeOperations === 0;
|
|
142
|
+
const automatic = !recovery &&
|
|
143
|
+
automaticAttempts < 3 &&
|
|
144
|
+
!attempted.has(nextSignature) &&
|
|
145
|
+
blocker.replacement?.canReplaceIdle &&
|
|
146
|
+
blocker.activity &&
|
|
147
|
+
(isHostActivityIdle(blocker.activity) || cooperative);
|
|
148
|
+
const interrupt = selected?.revision === current.revision && selected.action === 'interrupt';
|
|
149
|
+
const retry = selected?.revision === current.revision && selected.action === 'retry';
|
|
150
|
+
if ((automatic || interrupt || (retry && blocker.replacement?.canReplaceIdle)) &&
|
|
151
|
+
blocker.replacement) {
|
|
152
|
+
if (automatic) {
|
|
153
|
+
attempted.add(nextSignature);
|
|
154
|
+
automaticAttempts += 1;
|
|
155
|
+
}
|
|
156
|
+
attemptAbort = new AbortController();
|
|
157
|
+
const operationSignal = input.signal
|
|
158
|
+
? AbortSignal.any([input.signal, attemptAbort.signal])
|
|
159
|
+
: attemptAbort.signal;
|
|
160
|
+
const progress = (phase) => publish({
|
|
161
|
+
...current,
|
|
162
|
+
revision: randomUUID(),
|
|
163
|
+
state: 'progress',
|
|
164
|
+
phase: cooperative && !interrupt && phase === 'retiring' ? 'pausing' : phase,
|
|
165
|
+
actions: cancelled ? [] : ['cancel'],
|
|
166
|
+
});
|
|
167
|
+
if (input.openSurface)
|
|
168
|
+
surface ??= input.openSurface(submit);
|
|
169
|
+
progress(cooperative && !interrupt ? 'pausing' : 'checking');
|
|
170
|
+
// Do not abandon an irreversible cutover when the Surface closes. Its
|
|
171
|
+
// transaction settles (or persists recovery) before cancellation is observed.
|
|
172
|
+
let result;
|
|
173
|
+
try {
|
|
174
|
+
result = await blocker.replacement.execute(interrupt ? 'interrupt_active_work' : 'refuse_active_work', progress, automatic && !retry && !interrupt ? 'automatic' : 'explicit', operationSignal);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
result = { kind: 'recovery_required', diagnostic: boundedDiagnostic(error) };
|
|
178
|
+
}
|
|
179
|
+
finally {
|
|
180
|
+
attemptAbort = undefined;
|
|
181
|
+
}
|
|
182
|
+
recovery =
|
|
183
|
+
result.kind === 'recovery_required'
|
|
184
|
+
? { identity: blocker.identity, diagnostic: result.diagnostic.slice(0, 8_192) }
|
|
185
|
+
: undefined;
|
|
186
|
+
// A completed attempt is not proof of readiness; observe the successor.
|
|
187
|
+
signature = undefined;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (selected?.action === 'retry') {
|
|
191
|
+
// Explicit retry permits another safe probe, never an implicit interruption.
|
|
192
|
+
attempted.delete(nextSignature);
|
|
193
|
+
automaticAttempts = 0;
|
|
194
|
+
recovery = undefined;
|
|
195
|
+
signature = undefined;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const attention = projectBlocker(blocker, current.revision, recovery?.diagnostic);
|
|
199
|
+
if (!input.openSurface)
|
|
200
|
+
throw new HostHandoffRequiredError(attention);
|
|
201
|
+
surface ??= input.openSurface(submit);
|
|
202
|
+
publish(attention);
|
|
203
|
+
await new Promise((resolve, reject) => {
|
|
204
|
+
const finish = (error) => {
|
|
205
|
+
clearTimeout(timer);
|
|
206
|
+
input.signal?.removeEventListener('abort', abort);
|
|
207
|
+
wake = undefined;
|
|
208
|
+
if (error !== undefined)
|
|
209
|
+
reject(error);
|
|
210
|
+
else
|
|
211
|
+
resolve();
|
|
212
|
+
};
|
|
213
|
+
const abort = () => finish(input.signal?.reason);
|
|
214
|
+
const timer = setTimeout(finish, interval);
|
|
215
|
+
wake = () => finish();
|
|
216
|
+
input.signal?.addEventListener('abort', abort, { once: true });
|
|
217
|
+
if (input.signal?.aborted)
|
|
218
|
+
abort();
|
|
219
|
+
else if (choice)
|
|
220
|
+
finish();
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
finally {
|
|
225
|
+
surface?.close();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function projectBlocker(blocker, revision, recovery) {
|
|
229
|
+
const replacement = blocker.replacement;
|
|
230
|
+
return {
|
|
231
|
+
revision,
|
|
232
|
+
target: blocker.target,
|
|
233
|
+
state: 'attention',
|
|
234
|
+
reason: blocker.reason === 'unavailable'
|
|
235
|
+
? 'retry_required'
|
|
236
|
+
: recovery || blocker.reason === 'repair'
|
|
237
|
+
? 'repair_required'
|
|
238
|
+
: !replacement
|
|
239
|
+
? 'operator_required'
|
|
240
|
+
: !blocker.activity
|
|
241
|
+
? 'activity_unknown'
|
|
242
|
+
: isHostActivityIdle(blocker.activity)
|
|
243
|
+
? 'retry_required'
|
|
244
|
+
: 'busy',
|
|
245
|
+
...(blocker.activity ? { activity: blocker.activity } : {}),
|
|
246
|
+
mayExitNaturally: blocker.mayExitNaturally,
|
|
247
|
+
...(replacement ? { operation: replacement.kind } : {}),
|
|
248
|
+
actions: replacement?.canInterrupt ? ['cancel', 'retry', 'interrupt'] : ['cancel', 'retry'],
|
|
249
|
+
defaultAction: 'cancel',
|
|
250
|
+
...(blocker.recoveryBlocker ? { recoveryBlocker: blocker.recoveryBlocker } : {}),
|
|
251
|
+
...(blocker.operatorStep ? { operatorStep: blocker.operatorStep } : {}),
|
|
252
|
+
...((recovery ?? blocker.diagnostic)
|
|
253
|
+
? { diagnostic: redactSecrets((recovery ?? blocker.diagnostic)).slice(0, 8_192) }
|
|
254
|
+
: {}),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
function blockerSignature(blocker) {
|
|
258
|
+
const { processUptimeSeconds: _uptime, ...activity } = blocker.activity ?? {};
|
|
259
|
+
return JSON.stringify([
|
|
260
|
+
blocker.identity,
|
|
261
|
+
blocker.target,
|
|
262
|
+
blocker.reason,
|
|
263
|
+
activity,
|
|
264
|
+
blocker.mayExitNaturally,
|
|
265
|
+
blocker.replacement?.kind,
|
|
266
|
+
blocker.replacement?.canReplaceIdle,
|
|
267
|
+
blocker.replacement?.canInterrupt,
|
|
268
|
+
blocker.operatorStep,
|
|
269
|
+
blocker.recoveryBlocker,
|
|
270
|
+
blocker.diagnostic,
|
|
271
|
+
]);
|
|
272
|
+
}
|
|
273
|
+
function boundedDiagnostic(error) {
|
|
274
|
+
return redactSecrets(error instanceof Error ? error.message : String(error)).slice(0, 8_192);
|
|
275
|
+
}
|
|
@@ -23,9 +23,30 @@
|
|
|
23
23
|
* transport detail here so lifecycle owners can model the operation as
|
|
24
24
|
* retirement instead of spreading update-specific authority.
|
|
25
25
|
*/
|
|
26
|
-
export function prepareConnectedRuntimeHostRetirement(connection, mode, timeoutMs) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
export async function prepareConnectedRuntimeHostRetirement(connection, mode, timeoutMs, signal) {
|
|
27
|
+
signal?.throwIfAborted();
|
|
28
|
+
// Retirement uses a dedicated lifecycle connection. Closing it cancels the
|
|
29
|
+
// Host's reversible preparation; a committed retirement remains committed.
|
|
30
|
+
const cancel = () => {
|
|
31
|
+
void connection.close().catch(() => undefined);
|
|
32
|
+
};
|
|
33
|
+
signal?.addEventListener('abort', cancel, { once: true });
|
|
34
|
+
try {
|
|
35
|
+
return await connection.request('host.upgrade.prepare', {
|
|
36
|
+
expectedHostEpoch: connection.hostEpoch,
|
|
37
|
+
allowInterruptActiveTasks: mode === 'interrupt_active_work',
|
|
38
|
+
...(mode === 'refuse_active_work' && connection.cooperativeHandoff
|
|
39
|
+
? { allowCooperativeHandoff: true }
|
|
40
|
+
: {}),
|
|
41
|
+
}, timeoutMs);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
// Cancellation is not an unavailable protocol: lifecycle fallback must
|
|
45
|
+
// never turn this deliberate disconnect into supervisor interruption.
|
|
46
|
+
signal?.throwIfAborted();
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
signal?.removeEventListener('abort', cancel);
|
|
51
|
+
}
|
|
31
52
|
}
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
export * from './host-handoff.js';
|
|
20
|
+
export { formatHostHandoff } from './host-handoff-copy.js';
|
|
19
21
|
export { RuntimeHostManagedActivationError, activateRuntimeHostManagedDeployment, } from './managed-activation.js';
|
|
20
22
|
export { decodeRuntimeHostWebRtcStunPolicy, resolveRuntimeHostWebRtcStunUrls, } from '../webrtc-stun-policy.js';
|
|
21
23
|
export { openRuntimeHostManagedStdioBridge } from './managed-stdio-bridge.js';
|
|
@@ -32,6 +32,9 @@ export function launchDetachedRuntimeHostCandidate(input) {
|
|
|
32
32
|
const startupFailure = readStartupFailure(exited, startupAttemptId);
|
|
33
33
|
const spawned = spawnedPid(child).then(({ pid }) => {
|
|
34
34
|
child.unref();
|
|
35
|
+
// The guard observes launcher death; its IPC channel must not prevent
|
|
36
|
+
// that launcher from exiting naturally after its own work has finished.
|
|
37
|
+
child.channel?.unref();
|
|
35
38
|
return { pid, startupAttemptId, exited, startupFailure };
|
|
36
39
|
});
|
|
37
40
|
return { spawned };
|
|
@@ -23,6 +23,7 @@ export class RuntimeHostRemoteCompatibilityError extends RuntimeHostPermanentRec
|
|
|
23
23
|
name = 'RuntimeHostRemoteCompatibilityError';
|
|
24
24
|
code = RUNTIME_HOST_REMOTE_INCOMPATIBLE_CODE;
|
|
25
25
|
details;
|
|
26
|
+
hostEpoch;
|
|
26
27
|
constructor(profileId, handshake) {
|
|
27
28
|
const details = Object.freeze({
|
|
28
29
|
profileId,
|
|
@@ -42,6 +43,7 @@ export class RuntimeHostRemoteCompatibilityError extends RuntimeHostPermanentRec
|
|
|
42
43
|
});
|
|
43
44
|
super(formatRuntimeHostRemoteCompatibilityMessage(details));
|
|
44
45
|
this.details = details;
|
|
46
|
+
this.hostEpoch = handshake.hostEpoch;
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
function formatRuntimeHostRemoteCompatibilityMessage(details) {
|
|
@@ -42,6 +42,8 @@ export class ClientSessionSubscription {
|
|
|
42
42
|
#releaseTranscriptOverlay;
|
|
43
43
|
#expectedSessionId;
|
|
44
44
|
#queue = [];
|
|
45
|
+
#ptyListeners = new Set();
|
|
46
|
+
#sessionDomainListeners = new Set();
|
|
45
47
|
#queuedBytes = 0;
|
|
46
48
|
#expectedSequence;
|
|
47
49
|
#latestProjectionRevision;
|
|
@@ -72,6 +74,18 @@ export class ClientSessionSubscription {
|
|
|
72
74
|
[Symbol.asyncIterator]() {
|
|
73
75
|
return this;
|
|
74
76
|
}
|
|
77
|
+
subscribePtyData(listener) {
|
|
78
|
+
if (this.#done || this.#terminalError || this.#closing)
|
|
79
|
+
return () => undefined;
|
|
80
|
+
this.#ptyListeners.add(listener);
|
|
81
|
+
return () => this.#ptyListeners.delete(listener);
|
|
82
|
+
}
|
|
83
|
+
subscribeSessionDomainChanges(listener) {
|
|
84
|
+
if (this.#done || this.#terminalError || this.#closing)
|
|
85
|
+
return () => undefined;
|
|
86
|
+
this.#sessionDomainListeners.add(listener);
|
|
87
|
+
return () => this.#sessionDomainListeners.delete(listener);
|
|
88
|
+
}
|
|
75
89
|
next() {
|
|
76
90
|
const queued = this.#queue.shift();
|
|
77
91
|
if (queued) {
|
|
@@ -101,6 +115,7 @@ export class ClientSessionSubscription {
|
|
|
101
115
|
if (this.#done || this.#terminalError)
|
|
102
116
|
return Promise.resolve();
|
|
103
117
|
this.#closing = true;
|
|
118
|
+
this.#ptyListeners.clear();
|
|
104
119
|
if (!this.#closeTask)
|
|
105
120
|
this.#closeTask = this.#requestClose();
|
|
106
121
|
return this.#closeTask;
|
|
@@ -208,9 +223,6 @@ export class ClientSessionSubscription {
|
|
|
208
223
|
}
|
|
209
224
|
const overlay = await this.#consumeTranscriptOverlay(bootstrap);
|
|
210
225
|
const durable = await this.#loadTranscriptSource(bootstrap.durable);
|
|
211
|
-
if (bootstrap.durableCoverage === 'complete') {
|
|
212
|
-
assertCompleteIdentities(durable, bootstrap.throughSequence);
|
|
213
|
-
}
|
|
214
226
|
const messages = durable.map((entry) => entry.value);
|
|
215
227
|
const indexById = new Map();
|
|
216
228
|
for (const [index, message] of messages.entries()) {
|
|
@@ -317,6 +329,22 @@ export class ClientSessionSubscription {
|
|
|
317
329
|
if (frame.subscriptionId !== this.subscriptionId) {
|
|
318
330
|
throw new RuntimeHostSubscriptionError('correlation_changed', 'Session subscription correlation changed');
|
|
319
331
|
}
|
|
332
|
+
if (frame.kind === 'subscription.runtime_resource_pty_data') {
|
|
333
|
+
if (frame.sessionId !== this.#expectedSessionId) {
|
|
334
|
+
throw new RuntimeHostSubscriptionError('correlation_changed', 'PTY Session identity changed');
|
|
335
|
+
}
|
|
336
|
+
// No iterator backlog when nobody is displaying a terminal. Attaching
|
|
337
|
+
// consumers hydrate from a snapshot, including bytes before attachment.
|
|
338
|
+
for (const listener of this.#ptyListeners) {
|
|
339
|
+
try {
|
|
340
|
+
listener(frame);
|
|
341
|
+
}
|
|
342
|
+
catch {
|
|
343
|
+
/* A display consumer cannot terminate Session state. */
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
320
348
|
if (frame.sequence !== this.#expectedSequence) {
|
|
321
349
|
throw new RuntimeHostSubscriptionError('sequence_gap', `Session subscription expected sequence ${this.#expectedSequence} but received ${frame.sequence}`);
|
|
322
350
|
}
|
|
@@ -333,8 +361,7 @@ export class ClientSessionSubscription {
|
|
|
333
361
|
else if ((frame.kind === 'subscription.session_delta' ||
|
|
334
362
|
frame.kind === 'subscription.session_event' ||
|
|
335
363
|
frame.kind === 'subscription.transcript_advanced' ||
|
|
336
|
-
frame.kind === 'subscription.session_domain_changed'
|
|
337
|
-
frame.kind === 'subscription.runtime_resource_pty_data') &&
|
|
364
|
+
frame.kind === 'subscription.session_domain_changed') &&
|
|
338
365
|
frame.sessionId !== this.#expectedSessionId) {
|
|
339
366
|
throw new RuntimeHostSubscriptionError('correlation_changed', 'Session subscription frame identity changed');
|
|
340
367
|
}
|
|
@@ -349,11 +376,23 @@ export class ClientSessionSubscription {
|
|
|
349
376
|
}
|
|
350
377
|
this.#latestTranscriptThroughSequence = frame.throughSequence;
|
|
351
378
|
}
|
|
379
|
+
if (frame.kind === 'subscription.session_domain_changed') {
|
|
380
|
+
for (const listener of this.#sessionDomainListeners) {
|
|
381
|
+
try {
|
|
382
|
+
listener(frame);
|
|
383
|
+
}
|
|
384
|
+
catch {
|
|
385
|
+
/* An invalidation consumer cannot terminate Session state. */
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
352
389
|
this.#offer(frame);
|
|
353
390
|
if (frame.kind === 'subscription.closed')
|
|
354
391
|
this.#doneAfterQueue = true;
|
|
355
392
|
}
|
|
356
393
|
finish() {
|
|
394
|
+
this.#ptyListeners.clear();
|
|
395
|
+
this.#sessionDomainListeners.clear();
|
|
357
396
|
if (this.#done || this.#terminalError)
|
|
358
397
|
return;
|
|
359
398
|
this.#doneAfterQueue = true;
|
|
@@ -364,6 +403,8 @@ export class ClientSessionSubscription {
|
|
|
364
403
|
}
|
|
365
404
|
}
|
|
366
405
|
fail(error) {
|
|
406
|
+
this.#ptyListeners.clear();
|
|
407
|
+
this.#sessionDomainListeners.clear();
|
|
367
408
|
if (this.#done || this.#terminalError)
|
|
368
409
|
return;
|
|
369
410
|
this.#terminalError = error;
|
|
@@ -21,6 +21,7 @@ import { chmod, lstat, mkdtemp, readdir, rm, rmdir, unlink } from 'node:fs/promi
|
|
|
21
21
|
import { tmpdir } from 'node:os';
|
|
22
22
|
import { join } from 'node:path';
|
|
23
23
|
import { truncateUtf8 } from '@maka/core/diagnostic-log';
|
|
24
|
+
import { isNodeError } from '../node-error.js';
|
|
24
25
|
const FALLBACK_ENDPOINT_ROOT = '/tmp';
|
|
25
26
|
const PORTABLE_UNIX_SOCKET_PATH_LIMIT = 100;
|
|
26
27
|
const ENDPOINT_SOCKET_NAME = 'h.sock';
|
|
@@ -302,6 +303,3 @@ function currentUid() {
|
|
|
302
303
|
}
|
|
303
304
|
return process.getuid();
|
|
304
305
|
}
|
|
305
|
-
function isNodeError(error, code) {
|
|
306
|
-
return (error instanceof Error && 'code' in error && error.code === code);
|
|
307
|
-
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
/** Narrows a caught value to a Node errno error with one exact error code. */
|
|
20
|
+
export function isNodeError(error, code) {
|
|
21
|
+
return error instanceof Error && 'code' in error && error.code === code;
|
|
22
|
+
}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
export { RUNTIME_HOST_OPERATOR_RETIREMENT_CANCELLATION_ENV } from './retirement-cancellation.js';
|
|
19
20
|
export { RUNTIME_HOST_ACTIVATION_ERROR_CODE_MAX_BYTES, RUNTIME_HOST_ACTIVATION_ERROR_MESSAGE_MAX_BYTES, RUNTIME_HOST_ACTIVATION_FRAME_MAX_BYTES, RUNTIME_HOST_ACTIVATION_FRAME_PREFIX, decodeRuntimeHostActivationFrame, encodeRuntimeHostActivationFrame, } from './activation-frame.js';
|
|
20
21
|
export { RUNTIME_HOST_ACCESS_MANAGEMENT_ERROR_CODE_MAX_BYTES, RUNTIME_HOST_ACCESS_MANAGEMENT_ERROR_MESSAGE_MAX_BYTES, RUNTIME_HOST_ACCESS_MANAGEMENT_FRAME_PREFIX, decodeRuntimeHostAccessManagementFrame, encodeRuntimeHostAccessManagementFrame, } from './access-management-frame.js';
|
|
21
22
|
export { runtimeHostAccessCredentialFingerprint } from '../access-credential-identity.js';
|
|
@@ -27,6 +28,6 @@ export { RUNTIME_HOST_OPERATOR_ACCESS_MANAGEMENT_CAPABILITY, RUNTIME_HOST_OPERAT
|
|
|
27
28
|
export { RUNTIME_HOST_SETUP_ERROR_CODE_MAX_BYTES, RUNTIME_HOST_SETUP_ERROR_MESSAGE_MAX_BYTES, RUNTIME_HOST_SETUP_FRAME_PREFIX, decodeRuntimeHostSetupFrame, encodeRuntimeHostSetupFrame, parseRuntimeHostSetupEndpoint, } from './setup-frame.js';
|
|
28
29
|
export { createRuntimeHostOperatorCommand, createRuntimeHostLegacyPosixOperatorCommand, decodeRuntimeHostOperatorCommand, decodeRuntimeHostPosixOperatorCommand, runtimeHostManagedOperatorCommand, runtimeHostManagedOperatorModulePath, runtimeHostOperatorInvocation, } from './operator-command.js';
|
|
29
30
|
export { RUNTIME_HOST_SETUP_SOURCE_PACKAGE_INTEGRITY_ENV, compareProductReleaseVersions, isProductReleaseVersion, isRuntimeHostNpmDeploymentIdentity, isSha512PackageIntegrity, resolveRuntimeHostNpmDeploymentLayout, } from './update-package-evidence.js';
|
|
30
|
-
export { applyLocalHostDeploymentTransition, LocalHostDeploymentAuthorityError, readLocalHostDeploymentRecord, resolveLocalHostDeploymentAuthorityRoot, } from './local-deployment-owner.js';
|
|
31
|
+
export { applyLocalHostDeploymentTransition, LocalHostDeploymentAuthorityError, readLocalHostDeploymentRecord, withLocalHostDeploymentAuthority, resolveLocalHostDeploymentAuthorityRoot, } from './local-deployment-owner.js';
|
|
31
32
|
export { claimLocalHostProcessDeployment, handoffLocalHostProcessDeployment, } from './local-process-deployment-handoff.js';
|
|
32
33
|
export { RUNTIME_HOST_MANAGED_DEPLOYMENT_CONFIG_FILE, RuntimeHostManagedDeploymentError, beginRuntimeHostManagedDeploymentTransition, blockRuntimeHostManagedDeploymentTransition, claimRuntimeHostManagedDeployment, commitRuntimeHostManagedDeploymentTransition, commitRuntimeHostManagedDeployment, decodeRuntimeHostManagedDeploymentAuthorityRecord, decodeRuntimeHostManagedDeploymentConfig, readRuntimeHostManagedDeploymentAuthorityRecord, assertRuntimeHostManagedDeploymentAuthorityDurablyAbsent, readRuntimeHostManagedDeploymentConfig, resolveRuntimeHostManagedDeployment, resolveRuntimeHostManagedDeploymentAuthority, resolveRuntimeHostManagedDeploymentAuthorityRoot, resolveRuntimeHostManagedDeploymentConfigPath, rollbackRuntimeHostManagedDeploymentTransition, runtimeHostManagedLaunchClaim, } from './managed-deployment.js';
|
|
@@ -27,6 +27,7 @@ import { z } from 'zod';
|
|
|
27
27
|
import { isCanonicalRuntimeHostWebSocketPath } from '../protocol/websocket-path.js';
|
|
28
28
|
import { runtimeHostWebRtcStunPolicySchema } from '../webrtc-stun-policy.js';
|
|
29
29
|
import { isProductReleaseVersion, isSha512PackageIntegrity, resolveRuntimeHostNpmDeploymentLayout, } from './update-package-evidence.js';
|
|
30
|
+
import { isNodeError } from '../node-error.js';
|
|
30
31
|
export const RUNTIME_HOST_MANAGED_DEPLOYMENT_CONFIG_FILE = 'runtime-host-deployment.json';
|
|
31
32
|
const SCHEMA_VERSION = 1;
|
|
32
33
|
const MAX_DOCUMENT_BYTES = 256 * 1024;
|
|
@@ -824,6 +825,3 @@ function deploymentIo(message, cause) {
|
|
|
824
825
|
cause,
|
|
825
826
|
});
|
|
826
827
|
}
|
|
827
|
-
function isNodeError(error, code) {
|
|
828
|
-
return error instanceof Error && 'code' in error && error.code === code;
|
|
829
|
-
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
/** EOF on inherited stdin cancels only the first retirement, never its transaction or rollback. */
|
|
20
|
+
export const RUNTIME_HOST_OPERATOR_RETIREMENT_CANCELLATION_ENV = 'MAKA_RUNTIME_HOST_OPERATOR_RETIREMENT_CANCELLATION_STDIN';
|
|
@@ -20,7 +20,6 @@ export const PEER_MESH_MAX_MEMBERS = 64;
|
|
|
20
20
|
export const PEER_MESH_MAX_MESHES = 16;
|
|
21
21
|
export const PEER_MESH_MAX_PENDING_INVITATIONS = 32;
|
|
22
22
|
export const PEER_MESH_MAX_INVITATION_RECORDS = PEER_MESH_MAX_PENDING_INVITATIONS * 3;
|
|
23
|
-
export const PEER_MESH_MAX_ROUTE_HINTS = 16;
|
|
24
23
|
export const PEER_MESH_MAX_TRANSIT_RELAY_ADDRESSES = 256;
|
|
25
24
|
export const PEER_MESH_MAX_TRANSIT_ADDRESSES_PER_RELAY = 4;
|
|
26
25
|
export const PEER_MESH_MEMBER_ADVERTISEMENT_MAX_BYTES = 2 * 1024;
|
|
@@ -20,7 +20,7 @@ import { createHash, createPrivateKey, createPublicKey, generateKeyPairSync, ran
|
|
|
20
20
|
import { decodePeerMeshInvitation as decodePeerMeshInvitationWire, } from '../protocol/peer-mesh.js';
|
|
21
21
|
import { PEER_MESH_MEMBER_ADVERTISEMENT_MAX_BYTES, PEER_MESH_MAX_MEMBERS } from './limits.js';
|
|
22
22
|
import { canonicalPeerMeshDisplayName } from './display-name.js';
|
|
23
|
-
export { PEER_MESH_MAX_INVITATION_RECORDS, PEER_MESH_MAX_MEMBERS, PEER_MESH_MAX_MESHES, PEER_MESH_MAX_PENDING_INVITATIONS,
|
|
23
|
+
export { PEER_MESH_MAX_INVITATION_RECORDS, PEER_MESH_MAX_MEMBERS, PEER_MESH_MAX_MESHES, PEER_MESH_MAX_PENDING_INVITATIONS, PEER_MESH_MAX_TRANSIT_ADDRESSES_PER_RELAY, PEER_MESH_MAX_TRANSIT_RELAY_ADDRESSES, } from './limits.js';
|
|
24
24
|
export function generatePeerMeshAuthorityKeyPair() {
|
|
25
25
|
const { publicKey, privateKey } = generateKeyPairSync('ed25519');
|
|
26
26
|
return Object.freeze({
|
|
@@ -20,6 +20,7 @@ import { chmod, lstat, mkdir, open, readFile, rename, unlink } from 'node:fs/pro
|
|
|
20
20
|
import { dirname, join } from 'node:path';
|
|
21
21
|
import { performance } from 'node:perf_hooks';
|
|
22
22
|
import { authenticateSignedPeerReachabilityLease, canonicalPeerReachabilityLease, decodeSignedPeerReachabilityLease, isPeerReachabilityLeaseCurrent, PEER_REACHABILITY_LEASE_TTL_MS, PEER_REACHABILITY_REFRESH_LEAD_MS, peerReachabilityLeaseReceipt, peerReachabilityLeaseSigningBytes, samePeerReachabilityRoutes, verifySignedPeerReachabilityLease, } from './model.js';
|
|
23
|
+
import { isNodeError } from '../node-error.js';
|
|
23
24
|
const STATE_FILE = 'peer-reachability.json';
|
|
24
25
|
const MAX_STATE_BYTES = 64 * 1_024;
|
|
25
26
|
export async function openPeerReachabilityPublisher(input) {
|
|
@@ -240,6 +241,3 @@ async function syncDirectory(path) {
|
|
|
240
241
|
await handle.close();
|
|
241
242
|
}
|
|
242
243
|
}
|
|
243
|
-
function isNodeError(error, code) {
|
|
244
|
-
return error instanceof Error && 'code' in error && error.code === code;
|
|
245
|
-
}
|
|
@@ -17,13 +17,15 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { invalidProtocolFrame } from './errors.js';
|
|
20
|
-
import { requireCount, requireEncodedByteLimit, requireExactRecord, requireId, requireRecord, requireString, requireUtf8String, } from './codec.js';
|
|
20
|
+
import { requireCount, requireEncodedByteLimit, requireExactRecord, requireId, requireRecord, requireShapedRecord, requireString, requireUtf8String, } from './codec.js';
|
|
21
21
|
import { defineOperation } from './operation-spec.js';
|
|
22
22
|
import { decodeSignedPeerReachabilityLease, } from '../peer-reachability/model.js';
|
|
23
23
|
export function isHostActivityIdle(activity) {
|
|
24
24
|
return (activity.connections === 0 &&
|
|
25
25
|
activity.activeOperations === 0 &&
|
|
26
|
-
activity.
|
|
26
|
+
(activity.drainResidencies === undefined
|
|
27
|
+
? activity.residencies.length === 0
|
|
28
|
+
: activity.drainResidencies === 0));
|
|
27
29
|
}
|
|
28
30
|
export const HOST_DIAGNOSTICS_RESULT_MAX_BYTES = 72 * 1024;
|
|
29
31
|
export const HOST_DIAGNOSTIC_LOG_MAX_ENTRIES = 256;
|
|
@@ -132,16 +134,21 @@ function requireUpgradeBlockingActivity(value) {
|
|
|
132
134
|
return value;
|
|
133
135
|
}
|
|
134
136
|
export function decodeHostActivitySnapshot(value) {
|
|
135
|
-
const record =
|
|
136
|
-
'connections',
|
|
137
|
-
'activeOperations',
|
|
138
|
-
'processUptimeSeconds',
|
|
139
|
-
'residencies',
|
|
140
|
-
]);
|
|
137
|
+
const record = requireShapedRecord(value, 'Runtime Host activity', ['connections', 'activeOperations', 'processUptimeSeconds', 'residencies'], ['drainResidencies', 'cooperativeHandoff']);
|
|
141
138
|
if (!Array.isArray(record.residencies) || record.residencies.length > 128) {
|
|
142
139
|
throw invalidProtocolFrame('Invalid Runtime Host activity residencies');
|
|
143
140
|
}
|
|
144
141
|
return {
|
|
142
|
+
...(record.cooperativeHandoff === undefined
|
|
143
|
+
? {}
|
|
144
|
+
: {
|
|
145
|
+
cooperativeHandoff: requireBoolean(record.cooperativeHandoff, 'Runtime Host cooperative handoff capability'),
|
|
146
|
+
}),
|
|
147
|
+
...(record.drainResidencies === undefined
|
|
148
|
+
? {}
|
|
149
|
+
: {
|
|
150
|
+
drainResidencies: requireCount(record.drainResidencies, 'Runtime Host drain residencies'),
|
|
151
|
+
}),
|
|
145
152
|
connections: requireCount(record.connections, 'Runtime Host activity connections'),
|
|
146
153
|
activeOperations: requireCount(record.activeOperations, 'Runtime Host activity active operations'),
|
|
147
154
|
processUptimeSeconds: requireCount(record.processUptimeSeconds, 'Runtime Host activity process uptime'),
|
|
@@ -158,13 +165,15 @@ export function decodeHostActivitySnapshot(value) {
|
|
|
158
165
|
};
|
|
159
166
|
}
|
|
160
167
|
function decodeHostUpgradePrepareInput(value) {
|
|
161
|
-
const record =
|
|
162
|
-
'expectedHostEpoch',
|
|
163
|
-
'allowInterruptActiveTasks',
|
|
164
|
-
]);
|
|
168
|
+
const record = requireShapedRecord(value, 'Runtime Host upgrade prepare input', ['expectedHostEpoch', 'allowInterruptActiveTasks'], ['allowCooperativeHandoff']);
|
|
165
169
|
return {
|
|
166
170
|
expectedHostEpoch: requireId(record.expectedHostEpoch, 'Runtime Host expected Host Epoch'),
|
|
167
171
|
allowInterruptActiveTasks: requireBoolean(record.allowInterruptActiveTasks, 'Runtime Host upgrade interrupt authority'),
|
|
172
|
+
...(record.allowCooperativeHandoff === undefined
|
|
173
|
+
? {}
|
|
174
|
+
: {
|
|
175
|
+
allowCooperativeHandoff: requireBoolean(record.allowCooperativeHandoff, 'Runtime Host cooperative handoff authority'),
|
|
176
|
+
}),
|
|
168
177
|
};
|
|
169
178
|
}
|
|
170
179
|
function requireBoolean(value, label) {
|