maka-agent 0.2.0-dev.10.20260831 → 0.2.0-dev.12.20260901
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/LICENSE +49 -2
- package/RUNTIME_HOST_PEER_DEPENDENCIES.rust.tsv +70 -0
- package/RUNTIME_HOST_PEER_THIRD_PARTY_NOTICES.txt +1839 -140
- package/dist/cli-core.js +25 -1
- package/dist/mcp-capability-provider.js +1 -1
- package/dist/onboarding-catalog.js +3 -5
- package/dist/pi-transcript.js +21 -17
- package/dist/pi-tui-layout.js +4 -2
- package/dist/pi-tui-mcp-status.js +115 -122
- package/dist/pi-tui-pickers.js +11 -5
- package/dist/pi-tui-runner.js +133 -102
- package/dist/runtime-host-cli-context.js +4 -0
- package/dist/runtime-host-cli.js +150 -4
- package/dist/runtime-host-lifecycle-transaction.js +5 -2
- package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
- package/dist/runtime-host-onboarding.js +12 -16
- package/dist/runtime-host-peer-management-command.js +16 -4
- package/dist/runtime-host-plugin-command.js +101 -0
- package/dist/runtime-host-run-command.js +5 -1
- package/dist/runtime-host-service-management-command.js +2 -1
- package/dist/runtime-host-setup-command.js +1 -0
- package/dist/runtime-host-task-readiness.js +2 -3
- package/dist/runtime-host-tui-command.js +1 -1
- package/dist/runtime-host-tui-context.js +34 -6
- package/dist/runtime-host-update-command.js +13 -5
- package/dist/runtime-host-update-discovery.js +1 -0
- package/dist/tui-clipboard.js +86 -0
- package/dist/tui-copy-catalog.js +256 -0
- package/dist/tui-copy-command.js +103 -0
- package/dist/tui-mcp-control.js +46 -4
- package/dist/tui-mcp-remote-publication.js +395 -0
- package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
- package/node_modules/@maka/core/dist/agent-run.js +5 -0
- package/node_modules/@maka/core/dist/attachments.js +80 -1
- package/node_modules/@maka/core/dist/bounded-response.js +71 -0
- package/node_modules/@maka/core/dist/chat-model-choice.js +8 -31
- package/node_modules/@maka/core/dist/client-capability-grant.js +149 -0
- package/node_modules/@maka/core/dist/connection-readiness.js +3 -31
- package/node_modules/@maka/core/dist/deep-research.js +1 -20
- package/node_modules/@maka/core/dist/events.js +22 -1
- package/node_modules/@maka/core/dist/execution-inspect.js +3 -1
- package/node_modules/@maka/core/dist/foreign-session.js +2 -2
- package/node_modules/@maka/core/dist/interaction.js +49 -2
- package/node_modules/@maka/core/dist/llm-connections.js +74 -82
- package/node_modules/@maka/core/dist/model-call-attempt.js +66 -0
- package/node_modules/@maka/core/dist/model-catalog.js +238 -313
- package/node_modules/@maka/core/dist/model-facts.js +280 -0
- package/node_modules/@maka/core/dist/model-metadata.generated.js +1907 -1872
- package/node_modules/@maka/core/dist/model-metadata.js +184 -199
- package/node_modules/@maka/core/dist/model-projection-transition.js +145 -0
- package/node_modules/@maka/core/dist/model-thinking.js +1 -1
- package/node_modules/@maka/core/dist/models-dev-projection.js +302 -0
- package/node_modules/@maka/core/dist/models-dev-refresh.js +55 -0
- package/node_modules/@maka/core/dist/onboarding.js +2 -1
- package/node_modules/@maka/core/dist/provider-auth.js +47 -291
- package/node_modules/@maka/core/dist/provider-registry.js +68 -357
- package/node_modules/@maka/core/dist/runtime-boundary.js +2 -2
- package/node_modules/@maka/core/dist/runtime-event.js +5 -1
- package/node_modules/@maka/core/dist/runtime-policy/connection-catalog-codec.js +82 -5
- package/node_modules/@maka/core/dist/runtime-policy/model-catalog-entry-codec.js +75 -0
- package/node_modules/@maka/core/dist/runtime-policy.js +2 -1
- package/node_modules/@maka/core/dist/session-send-projection.js +2 -1
- package/node_modules/@maka/core/dist/session-start-mode.js +42 -0
- package/node_modules/@maka/core/dist/session-todo.js +101 -0
- package/node_modules/@maka/core/dist/session.js +119 -5
- package/node_modules/@maka/core/dist/slash-command-catalog.js +1 -0
- package/node_modules/@maka/core/dist/task-submission-readiness.js +2 -1
- package/node_modules/@maka/core/dist/tool-activity-args.js +4 -0
- package/node_modules/@maka/core/dist/tool-quiet-preview.js +5 -5
- package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
- package/node_modules/@maka/core/dist/workhub-creation-intent.js +896 -0
- package/node_modules/@maka/core/package.json +9 -1
- package/node_modules/@maka/runtime/dist/active-tool-result-prune.js +45 -131
- package/node_modules/@maka/runtime/dist/agent-run.js +58 -44
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +146 -201
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +235 -69
- package/node_modules/@maka/runtime/dist/context-budget-helpers.js +4 -41
- package/node_modules/@maka/runtime/dist/context-budget-policy.js +8 -1
- package/node_modules/@maka/runtime/dist/context-budget.js +9 -81
- package/node_modules/@maka/runtime/dist/context-diagnostics.js +63 -27
- package/node_modules/@maka/runtime/dist/continuation-replay.js +19 -11
- package/node_modules/@maka/runtime/dist/conversation-copy.js +179 -16
- package/node_modules/@maka/runtime/dist/deep-research-tools.js +2 -3
- package/node_modules/@maka/runtime/dist/durable-tool-result-projection.js +21 -0
- package/node_modules/@maka/runtime/dist/execution-inspect.js +13 -3
- package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +58 -7
- package/node_modules/@maka/runtime/dist/history-compact-ledger.js +9 -1
- package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +2 -2
- package/node_modules/@maka/runtime/dist/history-compact-summary-validation.js +2 -1
- package/node_modules/@maka/runtime/dist/history-compaction.js +2 -1
- package/node_modules/@maka/runtime/dist/image-file.js +5 -20
- package/node_modules/@maka/runtime/dist/latest-context-snapshot.js +114 -20
- package/node_modules/@maka/runtime/dist/local-web-fetch.js +2 -43
- package/node_modules/@maka/runtime/dist/mcp-tools.js +28 -0
- package/node_modules/@maka/runtime/dist/model-adapter.js +47 -15
- package/node_modules/@maka/runtime/dist/model-factory.js +7 -1
- package/node_modules/@maka/runtime/dist/model-fetcher.js +15 -8
- package/node_modules/@maka/runtime/dist/model-history.js +125 -3
- package/node_modules/@maka/runtime/dist/model-projection-transition-ledger.js +207 -0
- package/node_modules/@maka/runtime/dist/model-runtime.js +7 -4
- package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +12 -14
- package/node_modules/@maka/runtime/dist/plugin-composition-loader.js +173 -20
- package/node_modules/@maka/runtime/dist/plugin-runtime.js +219 -0
- package/node_modules/@maka/runtime/dist/prompt-composition.js +33 -21
- package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +35 -74
- package/node_modules/@maka/runtime/dist/quiescent-session-snapshot.js +78 -0
- package/node_modules/@maka/runtime/dist/request-shape.js +256 -343
- package/node_modules/@maka/runtime/dist/run-trace.js +2 -24
- package/node_modules/@maka/runtime/dist/runtime-continuation-admission.js +1 -1
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +3 -0
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +1 -0
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +77 -23
- package/node_modules/@maka/runtime/dist/runtime-resume.js +20 -11
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +8 -4
- package/node_modules/@maka/runtime/dist/session-manager.js +45 -9
- package/node_modules/@maka/runtime/dist/session-recap.js +2 -1
- package/node_modules/@maka/runtime/dist/session-todo-tools.js +67 -0
- package/node_modules/@maka/runtime/dist/subagent-tools.js +2 -77
- package/node_modules/@maka/runtime/dist/system-prompt/main-session-prompt.js +1 -1
- package/node_modules/@maka/runtime/dist/telemetry/model-pricing.generated.js +93 -83
- package/node_modules/@maka/runtime/dist/test-connection.js +6 -6
- package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +227 -0
- package/node_modules/@maka/runtime/dist/tool-result-archive.js +40 -168
- package/node_modules/@maka/runtime/dist/tool-runtime.js +50 -6
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +39 -16
- package/node_modules/@maka/runtime/package.json +2 -1
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +10 -0
- package/node_modules/@maka/runtime-host/dist/client/catalog-reader.js +19 -5
- package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +3 -2
- package/node_modules/@maka/runtime-host/dist/client/connection.js +22 -0
- package/node_modules/@maka/runtime-host/dist/client/host-profile.js +222 -19
- package/node_modules/@maka/runtime-host/dist/client/index.js +2 -1
- package/node_modules/@maka/runtime-host/dist/client/oauth-presentation.js +1 -1
- package/node_modules/@maka/runtime-host/dist/client/peer-client.js +4 -0
- package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +8 -0
- package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
- package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +2 -0
- package/node_modules/@maka/runtime-host/dist/operator/peer-management-frame.js +2 -0
- package/node_modules/@maka/runtime-host/dist/operator/service-management-frame.js +2 -0
- package/node_modules/@maka/runtime-host/dist/peer-mesh/owner.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +22 -1
- package/node_modules/@maka/{storage/dist/task-ledger-store-internal.js → runtime-host/dist/protocol/connection-catalog-change.js} +7 -13
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +43 -2
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +7 -3
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +512 -0
- package/node_modules/@maka/runtime-host/dist/protocol/runtime-policy.js +24 -12
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +1 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +1 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-retirement.js +30 -3
- package/node_modules/@maka/runtime-host/dist/protocol/session-todo.js +53 -0
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +4 -1
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +92 -4
- package/node_modules/@maka/runtime-host/dist/server/access-authority.js +15 -13
- package/node_modules/@maka/runtime-host/dist/server/access-credential-metadata.js +4 -2
- package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +119 -47
- package/node_modules/@maka/runtime-host/dist/server/bootstrap-runtime-policy.js +10 -4
- package/node_modules/@maka/runtime-host/dist/server/child-agent-composition.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +192 -18
- package/node_modules/@maka/runtime-host/dist/server/client-capability-invocation-broker.js +122 -48
- package/node_modules/@maka/runtime-host/dist/server/client-capability-provider-id.js +31 -0
- package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +6 -5
- package/node_modules/@maka/runtime-host/dist/server/connection-session.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/deep-research-coordinator.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +163 -66
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +27 -9
- package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +38 -43
- package/node_modules/@maka/runtime-host/dist/server/extension-bundle.js +249 -0
- package/node_modules/@maka/runtime-host/dist/server/extension-package-manifest.js +262 -0
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +0 -23
- package/node_modules/@maka/runtime-host/dist/server/host-change-feed.js +11 -0
- package/node_modules/@maka/runtime-host/dist/server/index.js +5 -0
- package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +181 -13
- package/node_modules/@maka/runtime-host/dist/server/interaction-projection.js +6 -0
- package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +7 -9
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +88 -22
- package/node_modules/@maka/runtime-host/dist/server/model-metadata-refresh.js +96 -0
- package/node_modules/@maka/runtime-host/dist/server/operation-dispatcher.js +43 -118
- package/node_modules/@maka/runtime-host/dist/server/plugin-composition-patch.js +58 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-composition-store.js +141 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-package-loader.js +130 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-package-store.js +528 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +249 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +1130 -0
- package/node_modules/@maka/runtime-host/dist/server/root-admission-owner.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +24 -5
- package/node_modules/@maka/runtime-host/dist/server/runtime-policy-coordinator.js +31 -2
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +2 -1
- package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +58 -9
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +30 -13
- package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/session-todo-coordinator.js +77 -0
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +10 -2
- package/node_modules/@maka/runtime-host/dist/server/web-fetch-tool.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +276 -3
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +101 -1
- package/node_modules/@maka/runtime-host/dist/transport/peer-native.js +1 -0
- package/node_modules/@maka/runtime-host/dist/webrtc-stun-policy.js +114 -0
- package/node_modules/@maka/runtime-host/package.json +2 -0
- package/node_modules/@maka/storage/dist/agent-run-store.js +80 -15
- package/node_modules/@maka/storage/dist/artifact-attachments.js +29 -6
- package/node_modules/@maka/storage/dist/artifact-store.js +7 -23
- package/node_modules/@maka/storage/dist/artifact-stores.js +13 -2
- package/node_modules/@maka/storage/dist/conversation-operational-state.js +3 -0
- package/node_modules/@maka/storage/dist/credential-store.js +3 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +4 -0
- package/node_modules/@maka/storage/dist/file-lifetime-owner.js +30 -2
- package/node_modules/@maka/storage/dist/interaction-store-public.js +1 -1
- package/node_modules/@maka/storage/dist/interaction-store.js +173 -0
- package/node_modules/@maka/storage/dist/model-facts-store.js +79 -0
- package/node_modules/@maka/storage/dist/production-session-snapshot.js +761 -0
- package/node_modules/@maka/storage/dist/quiescent-session-snapshot.js +1 -1
- package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +26 -26
- package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +114 -56
- package/node_modules/@maka/storage/dist/runtime-policy/document-io.js +22 -16
- package/node_modules/@maka/storage/dist/runtime-policy/onboarding-transaction.js +2 -2
- package/node_modules/@maka/storage/dist/runtime-policy-stores.js +1 -1
- package/node_modules/@maka/storage/dist/session-message-projection.js +1 -1
- package/node_modules/@maka/storage/dist/session-store.js +32 -6
- package/node_modules/@maka/storage/dist/{task-ledger-authority.js → session-todo-authority.js} +13 -28
- package/node_modules/@maka/storage/dist/session-todo-store.js +169 -0
- package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +19 -0
- package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +42 -1
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +10 -1
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +73 -3
- package/node_modules/@maka/storage/dist/sqlite-workflow-schema.js +5 -8
- package/node_modules/@maka/storage/dist/storage-writer-composition.js +3 -3
- package/node_modules/@maka/storage/package.json +3 -1
- package/package.json +1 -1
- package/node_modules/@maka/core/dist/task-ledger.js +0 -669
- package/node_modules/@maka/runtime/dist/task-ledger-tools.js +0 -244
- package/node_modules/@maka/runtime/dist/test-helpers.js +0 -61
- package/node_modules/@maka/runtime-host/dist/protocol/task-ledger.js +0 -321
- package/node_modules/@maka/runtime-host/dist/server/task-ledger-coordinator.js +0 -154
- package/node_modules/@maka/storage/dist/task-ledger-store.js +0 -663
|
@@ -1622,15 +1622,46 @@ var MAX_MODEL_IMAGE_EDGE = 2e3;
|
|
|
1622
1622
|
var READ_IMAGE_TOO_LARGE_MESSAGE = `Image exceeds the ${MAX_READ_IMAGE_BYTES / 1024 / 1024}MB model input limit; downscale it and try again.`;
|
|
1623
1623
|
var MAX_PROVIDER_IMAGE_REQUEST_BYTES = 12 * 1024 * 1024;
|
|
1624
1624
|
var PROVIDER_IMAGE_BUDGET_EXCEEDED_MESSAGE = `Image was read, but the per-request image budget (${MAX_PROVIDER_IMAGE_REQUEST_BYTES / 1024 / 1024}MB across all images this turn) was exceeded; earlier images were sent and this one was omitted. Read fewer or smaller images.`;
|
|
1625
|
+
var ATTACHMENT_MIME_SNIFF_BYTES = 16;
|
|
1626
|
+
var PDF_HEADER_SCAN_BYTES = 1024;
|
|
1627
|
+
function sniffAttachmentMimeType(bytes) {
|
|
1628
|
+
const prefix = bytes.subarray(0, ATTACHMENT_MIME_SNIFF_BYTES);
|
|
1629
|
+
if (startsWithBytes(prefix, [137, 80, 78, 71, 13, 10, 26, 10])) {
|
|
1630
|
+
return "image/png";
|
|
1631
|
+
}
|
|
1632
|
+
if (startsWithBytes(prefix, [255, 216, 255]))
|
|
1633
|
+
return "image/jpeg";
|
|
1634
|
+
if (startsWithAscii(prefix, "GIF87a") || startsWithAscii(prefix, "GIF89a"))
|
|
1635
|
+
return "image/gif";
|
|
1636
|
+
if (startsWithAscii(prefix, "RIFF") && startsWithAscii(prefix, "WEBP", 8))
|
|
1637
|
+
return "image/webp";
|
|
1638
|
+
if (containsAscii(bytes.subarray(0, PDF_HEADER_SCAN_BYTES), "%PDF-"))
|
|
1639
|
+
return "application/pdf";
|
|
1640
|
+
return void 0;
|
|
1641
|
+
}
|
|
1642
|
+
function startsWithBytes(bytes, signature, offset = 0) {
|
|
1643
|
+
return bytes.length >= offset + signature.length && signature.every((value, index) => bytes[offset + index] === value);
|
|
1644
|
+
}
|
|
1645
|
+
function startsWithAscii(bytes, signature, offset = 0) {
|
|
1646
|
+
if (bytes.length < offset + signature.length)
|
|
1647
|
+
return false;
|
|
1648
|
+
for (let index = 0; index < signature.length; index += 1) {
|
|
1649
|
+
if (bytes[offset + index] !== signature.charCodeAt(index))
|
|
1650
|
+
return false;
|
|
1651
|
+
}
|
|
1652
|
+
return true;
|
|
1653
|
+
}
|
|
1654
|
+
function containsAscii(bytes, signature) {
|
|
1655
|
+
const lastOffset = bytes.length - signature.length;
|
|
1656
|
+
for (let offset = 0; offset <= lastOffset; offset += 1) {
|
|
1657
|
+
if (startsWithAscii(bytes, signature, offset))
|
|
1658
|
+
return true;
|
|
1659
|
+
}
|
|
1660
|
+
return false;
|
|
1661
|
+
}
|
|
1625
1662
|
|
|
1626
1663
|
// src/image-file.ts
|
|
1627
1664
|
var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".gif", ".webp"]);
|
|
1628
|
-
var PNG_SIGNATURE = Buffer.from("\x89PNG\r\n\n", "latin1");
|
|
1629
|
-
var JPEG_SIGNATURE = Buffer.from("\xFF\xD8\xFF", "latin1");
|
|
1630
|
-
var GIF87A_SIGNATURE = Buffer.from("GIF87a");
|
|
1631
|
-
var GIF89A_SIGNATURE = Buffer.from("GIF89a");
|
|
1632
|
-
var RIFF_SIGNATURE = Buffer.from("RIFF");
|
|
1633
|
-
var WEBP_SIGNATURE = Buffer.from("WEBP");
|
|
1634
1665
|
function isSupportedImagePath(path2) {
|
|
1635
1666
|
return IMAGE_EXTENSIONS.has(extname(path2).toLowerCase());
|
|
1636
1667
|
}
|
|
@@ -1664,16 +1695,8 @@ function imageTooLargeError() {
|
|
|
1664
1695
|
return new Error(READ_IMAGE_TOO_LARGE_MESSAGE);
|
|
1665
1696
|
}
|
|
1666
1697
|
function sniffImageMime(bytes) {
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
if (startsWith(bytes, GIF87A_SIGNATURE) || startsWith(bytes, GIF89A_SIGNATURE))
|
|
1670
|
-
return "image/gif";
|
|
1671
|
-
if (startsWith(bytes, RIFF_SIGNATURE) && startsWith(bytes, WEBP_SIGNATURE, 8))
|
|
1672
|
-
return "image/webp";
|
|
1673
|
-
return void 0;
|
|
1674
|
-
}
|
|
1675
|
-
function startsWith(bytes, prefix, offset = 0) {
|
|
1676
|
-
return bytes.length >= offset + prefix.length && prefix.every((value, index) => bytes[offset + index] === value);
|
|
1698
|
+
const sniffed = sniffAttachmentMimeType(bytes);
|
|
1699
|
+
return sniffed && sniffed !== "application/pdf" ? sniffed : void 0;
|
|
1677
1700
|
}
|
|
1678
1701
|
|
|
1679
1702
|
// ../../node_modules/zod/v4/classic/external.js
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"./test-connection": "./dist/test-connection.js",
|
|
21
21
|
"./model-fetcher": "./dist/model-fetcher.js",
|
|
22
22
|
"./session-manager": "./dist/session-manager.js",
|
|
23
|
+
"./session-todo-tools": "./dist/session-todo-tools.js",
|
|
23
24
|
"./filesystem-worker": "./dist/filesystem-worker/index.js",
|
|
24
25
|
"./sandbox": "./dist/sandbox/index.js",
|
|
25
26
|
"./network/proxy-test": "./dist/network/proxy-test.js",
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
"./runtime-event-read-model": "./dist/runtime-event-read-model.js",
|
|
29
30
|
"./runtime-resume": "./dist/runtime-resume.js",
|
|
30
31
|
"./runtime-kernel": "./dist/runtime-kernel.js",
|
|
32
|
+
"./quiescent-session-snapshot": "./dist/quiescent-session-snapshot.js",
|
|
31
33
|
"./session-event-runtime-mapper": "./dist/session-event-runtime-mapper.js",
|
|
32
34
|
"./stream-graph-readiness": "./dist/stream-graph-readiness.js",
|
|
33
35
|
"./stream-graph-admission": "./dist/stream-graph-admission.js",
|
|
@@ -98,7 +100,6 @@
|
|
|
98
100
|
"./system-prompt/personalization-prompt": "./dist/system-prompt/personalization-prompt.js",
|
|
99
101
|
"./system-prompt/project-context": "./dist/system-prompt/project-context.js",
|
|
100
102
|
"./system-prompt/workspace-instructions": "./dist/system-prompt/workspace-instructions.js",
|
|
101
|
-
"./task-ledger-tools": "./dist/task-ledger-tools.js",
|
|
102
103
|
"./tavily-search": "./dist/tavily-search.js",
|
|
103
104
|
"./terminal-run-commit": "./dist/terminal-run-commit.js",
|
|
104
105
|
"./tool-availability": "./dist/tool-availability.js",
|
|
@@ -488,6 +488,16 @@ export function projectRuntimeHostInteractionRequest(interaction, now) {
|
|
|
488
488
|
},
|
|
489
489
|
];
|
|
490
490
|
}
|
|
491
|
+
if (interaction.request.kind === 'client_capability') {
|
|
492
|
+
return [
|
|
493
|
+
{
|
|
494
|
+
type: 'client_capability_request',
|
|
495
|
+
...base,
|
|
496
|
+
capability: interaction.request.target.capability,
|
|
497
|
+
scope: structuredClone(interaction.request.target.scope),
|
|
498
|
+
},
|
|
499
|
+
];
|
|
500
|
+
}
|
|
491
501
|
return [];
|
|
492
502
|
}
|
|
493
503
|
function projectSessionEvent(frame) {
|
|
@@ -277,6 +277,7 @@ function assembleConnectionCatalog(first, items) {
|
|
|
277
277
|
header: item,
|
|
278
278
|
enabledModelIds: new Map(),
|
|
279
279
|
models: new Map(),
|
|
280
|
+
catalogEntries: new Map(),
|
|
280
281
|
relayProfiles: new Map(),
|
|
281
282
|
});
|
|
282
283
|
}
|
|
@@ -286,8 +287,16 @@ function assembleConnectionCatalog(first, items) {
|
|
|
286
287
|
const entry = entries.get(item.connectionIndex);
|
|
287
288
|
if (!entry)
|
|
288
289
|
throw new RuntimeHostCatalogReadError('connection', 'invalid_projection');
|
|
289
|
-
const values = item.kind === 'enabled_model_id'
|
|
290
|
-
|
|
290
|
+
const values = item.kind === 'enabled_model_id'
|
|
291
|
+
? entry.enabledModelIds
|
|
292
|
+
: item.kind === 'model'
|
|
293
|
+
? entry.models
|
|
294
|
+
: entry.catalogEntries;
|
|
295
|
+
const expectedCount = item.kind === 'enabled_model_id'
|
|
296
|
+
? entry.header.enabledModelIdCount
|
|
297
|
+
: item.kind === 'model'
|
|
298
|
+
? entry.header.modelCount
|
|
299
|
+
: entry.header.catalogEntryCount;
|
|
291
300
|
if (item.itemIndex >= expectedCount || values.has(item.itemIndex)) {
|
|
292
301
|
throw new RuntimeHostCatalogReadError('connection', 'invalid_projection');
|
|
293
302
|
}
|
|
@@ -298,9 +307,12 @@ function assembleConnectionCatalog(first, items) {
|
|
|
298
307
|
if (item.relayProfile !== undefined)
|
|
299
308
|
entry.relayProfiles.set(item.modelId, item.relayProfile);
|
|
300
309
|
}
|
|
301
|
-
else {
|
|
310
|
+
else if (item.kind === 'model') {
|
|
302
311
|
entry.models.set(item.itemIndex, item.model);
|
|
303
312
|
}
|
|
313
|
+
else {
|
|
314
|
+
entry.catalogEntries.set(item.itemIndex, item.entry);
|
|
315
|
+
}
|
|
304
316
|
}
|
|
305
317
|
if (entries.size !== first.connectionCount) {
|
|
306
318
|
throw new RuntimeHostCatalogReadError('connection', 'invalid_projection');
|
|
@@ -309,14 +321,16 @@ function assembleConnectionCatalog(first, items) {
|
|
|
309
321
|
.sort(([left], [right]) => left - right)
|
|
310
322
|
.map(([, entry]) => {
|
|
311
323
|
if (entry.enabledModelIds.size !== entry.header.enabledModelIdCount ||
|
|
312
|
-
entry.models.size !== entry.header.modelCount
|
|
324
|
+
entry.models.size !== entry.header.modelCount ||
|
|
325
|
+
entry.catalogEntries.size !== entry.header.catalogEntryCount) {
|
|
313
326
|
throw new RuntimeHostCatalogReadError('connection', 'invalid_projection');
|
|
314
327
|
}
|
|
315
|
-
const { kind: _kind, connectionIndex: _index, enabledModelIdCount: _enabledCount, modelCount: _modelCount, ...header } = entry.header;
|
|
328
|
+
const { kind: _kind, connectionIndex: _index, enabledModelIdCount: _enabledCount, modelCount: _modelCount, catalogEntryCount: _catalogEntryCount, ...header } = entry.header;
|
|
316
329
|
return {
|
|
317
330
|
...header,
|
|
318
331
|
enabledModelIds: orderedValues(entry.enabledModelIds),
|
|
319
332
|
models: orderedValues(entry.models),
|
|
333
|
+
catalogEntries: orderedValues(entry.catalogEntries),
|
|
320
334
|
...(entry.relayProfiles.size === 0
|
|
321
335
|
? {}
|
|
322
336
|
: { relayModelProfiles: Object.fromEntries(entry.relayProfiles) }),
|
|
@@ -215,7 +215,7 @@ export class ClientCapabilityChannel {
|
|
|
215
215
|
async #runInvocation(invocationId, invocation, execute) {
|
|
216
216
|
let accepted = false;
|
|
217
217
|
let accepting;
|
|
218
|
-
const accept = () => {
|
|
218
|
+
const accept = (evidence) => {
|
|
219
219
|
if (invocation.released) {
|
|
220
220
|
return Promise.reject(capabilityInvocationAbortReason(invocation));
|
|
221
221
|
}
|
|
@@ -224,6 +224,7 @@ export class ClientCapabilityChannel {
|
|
|
224
224
|
this.#options.write({
|
|
225
225
|
kind: 'client.capability.accepted',
|
|
226
226
|
invocationId,
|
|
227
|
+
admissionEvidence: evidence,
|
|
227
228
|
}),
|
|
228
229
|
admission.promise,
|
|
229
230
|
]).then(() => {
|
|
@@ -260,7 +261,7 @@ export class ClientCapabilityChannel {
|
|
|
260
261
|
}));
|
|
261
262
|
if (invocation.released)
|
|
262
263
|
return;
|
|
263
|
-
await accept();
|
|
264
|
+
await accept({ kind: 'none' });
|
|
264
265
|
await this.#sendResult(invocationId, result, invocation);
|
|
265
266
|
}
|
|
266
267
|
catch (error) {
|
|
@@ -79,6 +79,7 @@ class RuntimeHostConnectionImpl {
|
|
|
79
79
|
selectedProtocol;
|
|
80
80
|
compositionId;
|
|
81
81
|
compositionRevision;
|
|
82
|
+
peerPath;
|
|
82
83
|
closed;
|
|
83
84
|
#transport;
|
|
84
85
|
#pendingRequests = new Map();
|
|
@@ -88,6 +89,7 @@ class RuntimeHostConnectionImpl {
|
|
|
88
89
|
#retiredSubscriptionIds = new Set();
|
|
89
90
|
#clientCapabilities;
|
|
90
91
|
#configurationChangeListeners = new Set();
|
|
92
|
+
#connectionCatalogChangeListeners = new Set();
|
|
91
93
|
#projectCatalogChangeListeners = new Set();
|
|
92
94
|
#sessionCatalogChangeListeners = new Set();
|
|
93
95
|
#scheduledTaskChangeListeners = new Set();
|
|
@@ -110,6 +112,7 @@ class RuntimeHostConnectionImpl {
|
|
|
110
112
|
this.selectedProtocol = accepted.selectedProtocol;
|
|
111
113
|
this.compositionId = accepted.compositionId;
|
|
112
114
|
this.compositionRevision = accepted.compositionRevision;
|
|
115
|
+
this.peerPath = options?.peerPath;
|
|
113
116
|
const connectionResource = options?.connectionResource;
|
|
114
117
|
if (connectionResource) {
|
|
115
118
|
const abortForResourceClosure = (cause) => this.#transport.abort(new RuntimeHostTransportError('closed', 'Runtime Host connection resource closed', {
|
|
@@ -260,6 +263,10 @@ class RuntimeHostConnectionImpl {
|
|
|
260
263
|
this.#configurationChangeListeners.add(listener);
|
|
261
264
|
return () => this.#configurationChangeListeners.delete(listener);
|
|
262
265
|
}
|
|
266
|
+
subscribeConnectionCatalogChanges(listener) {
|
|
267
|
+
this.#connectionCatalogChangeListeners.add(listener);
|
|
268
|
+
return () => this.#connectionCatalogChangeListeners.delete(listener);
|
|
269
|
+
}
|
|
263
270
|
subscribeProjectCatalogChanges(listener) {
|
|
264
271
|
this.#projectCatalogChangeListeners.add(listener);
|
|
265
272
|
return () => this.#projectCatalogChangeListeners.delete(listener);
|
|
@@ -286,6 +293,9 @@ class RuntimeHostConnectionImpl {
|
|
|
286
293
|
case 'configuration.changed':
|
|
287
294
|
this.#acceptConfigurationChanged(frame);
|
|
288
295
|
continue;
|
|
296
|
+
case 'connection.catalog.changed':
|
|
297
|
+
this.#acceptConnectionCatalogChanged(frame);
|
|
298
|
+
continue;
|
|
289
299
|
case 'project.catalog.changed':
|
|
290
300
|
this.#acceptProjectCatalogChanged(frame);
|
|
291
301
|
continue;
|
|
@@ -363,6 +373,16 @@ class RuntimeHostConnectionImpl {
|
|
|
363
373
|
}
|
|
364
374
|
}
|
|
365
375
|
}
|
|
376
|
+
#acceptConnectionCatalogChanged(frame) {
|
|
377
|
+
for (const listener of this.#connectionCatalogChangeListeners) {
|
|
378
|
+
try {
|
|
379
|
+
listener(frame.revision);
|
|
380
|
+
}
|
|
381
|
+
catch {
|
|
382
|
+
// A presentation listener cannot invalidate the Host connection.
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
366
386
|
#acceptProjectCatalogChanged(frame) {
|
|
367
387
|
for (const listener of this.#projectCatalogChangeListeners) {
|
|
368
388
|
try {
|
|
@@ -635,6 +655,7 @@ export async function connectRuntimeHostMessageTransport(input) {
|
|
|
635
655
|
livenessIntervalMs: normalized.livenessIntervalMs,
|
|
636
656
|
onLivenessProbe: input.onLivenessProbe,
|
|
637
657
|
connectionResource: input.connectionResource,
|
|
658
|
+
...(input.peerPath ? { peerPath: input.peerPath } : {}),
|
|
638
659
|
});
|
|
639
660
|
if (result.kind === 'connected') {
|
|
640
661
|
resourceTransferred = true;
|
|
@@ -934,6 +955,7 @@ async function exchangeRuntimeHostHandshake(input) {
|
|
|
934
955
|
livenessIntervalMs: input.livenessIntervalMs,
|
|
935
956
|
onLivenessProbe: input.onLivenessProbe,
|
|
936
957
|
connectionResource: input.connectionResource,
|
|
958
|
+
...(input.peerPath ? { peerPath: input.peerPath } : {}),
|
|
937
959
|
}),
|
|
938
960
|
};
|
|
939
961
|
}
|
|
@@ -17,11 +17,12 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { createHash, randomUUID } from 'node:crypto';
|
|
20
|
+
import { watch } from 'node:fs';
|
|
20
21
|
import { chmod, mkdir, open, readFile, rename, rm } from 'node:fs/promises';
|
|
21
22
|
import { dirname, join, posix } from 'node:path';
|
|
22
23
|
import { createFileCredentialStore } from '@maka/storage/credential-store';
|
|
23
24
|
import { withFileUpdateLock } from '@maka/storage/file-update-lock';
|
|
24
|
-
import { INTERACTIVE_RUNTIME_HOST_COMPOSITION_ID, isCanonicalRuntimeHostWebSocketPath, RUNTIME_HOST_PROTOCOL_VERSION, requireHostRootId, } from '../protocol/index.js';
|
|
25
|
+
import { INTERACTIVE_RUNTIME_HOST_COMPOSITION_ID, isCanonicalRuntimeHostWebSocketPath, RUNTIME_HOST_PROTOCOL_VERSION, requireClientInstanceId, requireHostRootId, } from '../protocol/index.js';
|
|
25
26
|
import { connectRemoteRuntimeHost, connectRuntimeHostMessageTransport, normalizeRemoteRuntimeHostUrl, } from './connection.js';
|
|
26
27
|
import { FramedByteStreamTransport } from '../transport/framed-byte-stream-transport.js';
|
|
27
28
|
import { RuntimeHostPeerByteStream, RuntimeHostPeerError, readRuntimeHostPeerAuthenticationResult, writeRuntimeHostPeerAuthentication, } from '../transport/peer-native.js';
|
|
@@ -32,6 +33,7 @@ import { activateRuntimeHostSshOperator } from './ssh-operator-activation.js';
|
|
|
32
33
|
import { waitForRuntimeHostReady } from './wait-for-ready.js';
|
|
33
34
|
import { connectRuntimeHostWslEnvironment, normalizeRuntimeHostWslDistribution, normalizeRuntimeHostWslOperatorPath, } from './wsl-environment.js';
|
|
34
35
|
const PROFILE_SCHEMA_VERSION = 3;
|
|
36
|
+
const CLIENT_PROFILE_DOCUMENT_NAME = 'runtime-host-profiles.json';
|
|
35
37
|
const PROFILE_DOCUMENT_MAX_BYTES = 64 * 1024;
|
|
36
38
|
const PROFILE_COUNT_MAX = 32;
|
|
37
39
|
const PROFILE_NAME_MAX_BYTES = 128;
|
|
@@ -39,6 +41,8 @@ const PROFILE_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
|
39
41
|
const PEER_ID_MAX_BYTES = 160;
|
|
40
42
|
const PEER_ADDRESS_MAX_BYTES = 2 * 1024;
|
|
41
43
|
const PEER_ROUTE_MAX = 16;
|
|
44
|
+
const PROFILE_CREDENTIAL_RECORD_PREFIX = 'maka-runtime-host-profile-credential-v1:';
|
|
45
|
+
const PROFILE_INCARNATION_ID_MAX_BYTES = 128;
|
|
42
46
|
export const RUNTIME_HOST_ACCESS_CREDENTIAL_MAX_BYTES = 8 * 1024;
|
|
43
47
|
export const RUNTIME_HOST_PLAINTEXT_ACKNOWLEDGEMENT = 'plaintext-bearer-v1';
|
|
44
48
|
export const LOCAL_RUNTIME_HOST_PROFILE = Object.freeze({
|
|
@@ -65,11 +69,27 @@ export function sameRemoteRuntimeHostProfileTarget(left, right) {
|
|
|
65
69
|
return (runtimeHostProfileAccess(left) === runtimeHostProfileAccess(right) &&
|
|
66
70
|
profileCredentialBinding(left) === profileCredentialBinding(right));
|
|
67
71
|
}
|
|
72
|
+
export class RuntimeHostProfileConnectionError extends RuntimeHostPermanentReconnectError {
|
|
73
|
+
reason;
|
|
74
|
+
constructor(reason, message) {
|
|
75
|
+
super(message);
|
|
76
|
+
this.reason = reason;
|
|
77
|
+
this.name = 'RuntimeHostProfileConnectionError';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
68
80
|
export function createFileRuntimeHostProfileCatalog(path, credentials) {
|
|
69
81
|
return new FileRuntimeHostProfileCatalog(path, credentials);
|
|
70
82
|
}
|
|
71
83
|
export function createClientRuntimeHostProfileCatalog(clientDataRoot, credentialStore = createClientRuntimeHostCredentialStore(clientDataRoot)) {
|
|
72
|
-
return createFileRuntimeHostProfileCatalog(join(clientDataRoot,
|
|
84
|
+
return createFileRuntimeHostProfileCatalog(join(clientDataRoot, CLIENT_PROFILE_DOCUMENT_NAME), createRuntimeHostProfileCredentialStore(credentialStore));
|
|
85
|
+
}
|
|
86
|
+
export function subscribeClientRuntimeHostProfileCatalogChanges(clientDataRoot, listener) {
|
|
87
|
+
const watcher = watch(clientDataRoot, (_eventType, filename) => {
|
|
88
|
+
if (filename === null || filename.toString() === CLIENT_PROFILE_DOCUMENT_NAME)
|
|
89
|
+
listener();
|
|
90
|
+
});
|
|
91
|
+
watcher.on('error', (error) => listener(error));
|
|
92
|
+
return () => watcher.close();
|
|
73
93
|
}
|
|
74
94
|
export function createClientRuntimeHostCredentialStore(clientDataRoot) {
|
|
75
95
|
return createFileCredentialStore(join(clientDataRoot, 'runtime-host-client'));
|
|
@@ -77,19 +97,47 @@ export function createClientRuntimeHostCredentialStore(clientDataRoot) {
|
|
|
77
97
|
export function createRuntimeHostProfileCredentialStore(credentials) {
|
|
78
98
|
return {
|
|
79
99
|
get: async (profile) => {
|
|
80
|
-
|
|
100
|
+
const stored = await credentials.getSecret(profileCredentialSlot(profile), 'runtime_host_access');
|
|
101
|
+
return stored === null ? null : decodeProfileCredential(profile, stored);
|
|
81
102
|
},
|
|
82
103
|
set: (profile, credential) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
104
|
+
try {
|
|
105
|
+
const encoded = encodeProfileCredential(credential);
|
|
106
|
+
return credentials.setSecret(profileCredentialSlot(profile), 'runtime_host_access', encoded);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
return Promise.reject(error);
|
|
87
110
|
}
|
|
88
|
-
return credentials.setSecret(profileCredentialSlot(profile), 'runtime_host_access', credential);
|
|
89
111
|
},
|
|
90
|
-
delete: (profile) => credentials.deleteSecret(profileCredentialSlot(profile)
|
|
112
|
+
delete: (profile) => credentials.deleteSecret(profileCredentialSlot(profile)),
|
|
91
113
|
};
|
|
92
114
|
}
|
|
115
|
+
export function createRuntimeHostCapabilityProviderCredentialStore(credentials) {
|
|
116
|
+
return {
|
|
117
|
+
get: async (target, ownerClientInstanceId) => {
|
|
118
|
+
const stored = await credentials.getSecret(profileCredentialSlot(target.profile), 'runtime_host_capability_provider');
|
|
119
|
+
if (stored === null)
|
|
120
|
+
return null;
|
|
121
|
+
const decoded = decodeCapabilityProviderCredential(stored);
|
|
122
|
+
return decoded.ownerClientInstanceId === requireClientInstanceId(ownerClientInstanceId) &&
|
|
123
|
+
decoded.profileIncarnationId === requireProfileIncarnationId(target.profileIncarnationId)
|
|
124
|
+
? decoded.credential
|
|
125
|
+
: null;
|
|
126
|
+
},
|
|
127
|
+
set: async (target, ownerClientInstanceId, credential) => {
|
|
128
|
+
await credentials.setSecret(profileCredentialSlot(target.profile), 'runtime_host_capability_provider', JSON.stringify({
|
|
129
|
+
schemaVersion: 1,
|
|
130
|
+
profileIncarnationId: requireProfileIncarnationId(target.profileIncarnationId),
|
|
131
|
+
ownerClientInstanceId: requireClientInstanceId(ownerClientInstanceId),
|
|
132
|
+
credential: requireRuntimeHostAccessCredential(credential),
|
|
133
|
+
}));
|
|
134
|
+
},
|
|
135
|
+
delete: (target, ownerClientInstanceId) => deleteCapabilityProviderCredential(credentials, target, ownerClientInstanceId),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
export function runtimeHostProfileTargetFingerprint(profile) {
|
|
139
|
+
return profileCredentialBinding(profile);
|
|
140
|
+
}
|
|
93
141
|
export async function connectRuntimeHostProfile(input, overrides = {}) {
|
|
94
142
|
if (input.profile.kind === 'environment') {
|
|
95
143
|
return (overrides.connectWsl ?? connectRuntimeHostWslEnvironment)({
|
|
@@ -109,7 +157,7 @@ export async function connectRuntimeHostProfile(input, overrides = {}) {
|
|
|
109
157
|
});
|
|
110
158
|
}
|
|
111
159
|
if (!input.credential) {
|
|
112
|
-
throw new
|
|
160
|
+
throw new RuntimeHostProfileConnectionError('credential_required', `Runtime Host profile ${input.profile.id} has no access credential`);
|
|
113
161
|
}
|
|
114
162
|
return connectRemoteRuntimeHostProfile({ ...input, profile: input.profile, credential: input.credential }, overrides);
|
|
115
163
|
}
|
|
@@ -193,6 +241,14 @@ export async function connectRemoteRuntimeHostProfile(input, overrides = {}) {
|
|
|
193
241
|
if (connected.kind === 'draining') {
|
|
194
242
|
throw new Error(`Runtime Host profile ${input.profile.id} is draining`);
|
|
195
243
|
}
|
|
244
|
+
if (connected.reason === 'authentication_failed') {
|
|
245
|
+
throw new RuntimeHostProfileConnectionError('credential_rejected', `Runtime Host profile ${input.profile.id} rejected its access credential`);
|
|
246
|
+
}
|
|
247
|
+
if (connected.reason === 'root_mismatch' || connected.reason === 'composition_mismatch') {
|
|
248
|
+
throw new RuntimeHostProfileConnectionError('target_mismatch', connected.reason === 'root_mismatch'
|
|
249
|
+
? `Runtime Host profile ${input.profile.id} connected to an unexpected State Root`
|
|
250
|
+
: `Runtime Host profile ${input.profile.id} has an incompatible Host composition`);
|
|
251
|
+
}
|
|
196
252
|
throw remoteRuntimeHostUnavailableError(`Runtime Host profile ${input.profile.id}`, connected.reason);
|
|
197
253
|
}
|
|
198
254
|
connection = connected.connection;
|
|
@@ -233,7 +289,7 @@ export async function connectPeerRuntimeHost(input) {
|
|
|
233
289
|
await writeRuntimeHostPeerAuthentication(stream, input.credential);
|
|
234
290
|
const authentication = await readRuntimeHostPeerAuthenticationResult(stream, input.handshakeTimeoutMs);
|
|
235
291
|
if (!authentication.accepted) {
|
|
236
|
-
throw new
|
|
292
|
+
throw new RuntimeHostProfileConnectionError('credential_rejected', `Runtime Host profile ${input.profileId} rejected its access credential`);
|
|
237
293
|
}
|
|
238
294
|
notifyConnectionPhase(input.onConnectionPhase, 'handshaking');
|
|
239
295
|
const result = await connectRuntimeHostMessageTransport({
|
|
@@ -248,6 +304,7 @@ export async function connectPeerRuntimeHost(input) {
|
|
|
248
304
|
...(input.handshakeTimeoutMs === undefined
|
|
249
305
|
? {}
|
|
250
306
|
: { handshakeTimeoutMs: input.handshakeTimeoutMs }),
|
|
307
|
+
...(stream.path ? { peerPath: stream.path } : {}),
|
|
251
308
|
});
|
|
252
309
|
input.signal?.throwIfAborted();
|
|
253
310
|
if (result.kind === 'incompatible') {
|
|
@@ -256,6 +313,11 @@ export async function connectPeerRuntimeHost(input) {
|
|
|
256
313
|
if (result.kind === 'draining')
|
|
257
314
|
throw new Error('Runtime Host direct peer is draining');
|
|
258
315
|
if (result.kind === 'unavailable') {
|
|
316
|
+
if (result.reason === 'root_mismatch' || result.reason === 'composition_mismatch') {
|
|
317
|
+
throw new RuntimeHostProfileConnectionError('target_mismatch', result.reason === 'root_mismatch'
|
|
318
|
+
? `Runtime Host profile ${input.profileId} connected to an unexpected State Root`
|
|
319
|
+
: `Runtime Host profile ${input.profileId} has an incompatible Host composition`);
|
|
320
|
+
}
|
|
259
321
|
throw remoteRuntimeHostUnavailableError('Runtime Host direct peer', result.reason);
|
|
260
322
|
}
|
|
261
323
|
transferred = true;
|
|
@@ -382,11 +444,15 @@ class FileRuntimeHostProfileCatalog {
|
|
|
382
444
|
}
|
|
383
445
|
if (profile.kind === 'environment')
|
|
384
446
|
return { profile };
|
|
385
|
-
const
|
|
386
|
-
if (!
|
|
447
|
+
const storedCredential = await this.credentials.get(profile);
|
|
448
|
+
if (!storedCredential) {
|
|
387
449
|
throw new RuntimeHostPermanentReconnectError(`Runtime Host profile ${profile.id} has no access credential`);
|
|
388
450
|
}
|
|
389
|
-
return {
|
|
451
|
+
return {
|
|
452
|
+
profile,
|
|
453
|
+
credential: storedCredential.credential,
|
|
454
|
+
profileIncarnationId: storedCredential.profileIncarnationId,
|
|
455
|
+
};
|
|
390
456
|
}
|
|
391
457
|
save(value, suppliedCredential) {
|
|
392
458
|
return this.#save(value, suppliedCredential, false);
|
|
@@ -426,7 +492,10 @@ class FileRuntimeHostProfileCatalog {
|
|
|
426
492
|
: [...current.profiles, profile],
|
|
427
493
|
});
|
|
428
494
|
if (profile.kind === 'remote' && suppliedCredential !== undefined) {
|
|
429
|
-
await this.credentials.set(profile,
|
|
495
|
+
await this.credentials.set(profile, {
|
|
496
|
+
credential: suppliedCredential,
|
|
497
|
+
profileIncarnationId: previousCredential?.profileIncarnationId ?? randomUUID(),
|
|
498
|
+
});
|
|
430
499
|
}
|
|
431
500
|
try {
|
|
432
501
|
await writeProfileDocument(this.path, next);
|
|
@@ -470,7 +539,7 @@ class FileRuntimeHostProfileCatalog {
|
|
|
470
539
|
!samePersistedRuntimeHostProfile(profile, expectedProfile) ||
|
|
471
540
|
(profile.kind === 'remote' &&
|
|
472
541
|
(target.credential === undefined ||
|
|
473
|
-
(await this.credentials.get(profile)
|
|
542
|
+
!sameProfileCredential(await this.credentials.get(profile), target)))) {
|
|
474
543
|
return { removed: false, document: current };
|
|
475
544
|
}
|
|
476
545
|
return { removed: true, document: await this.#removeProfile(current, profile) };
|
|
@@ -492,22 +561,27 @@ class FileRuntimeHostProfileCatalog {
|
|
|
492
561
|
return this.#exclusive(async () => {
|
|
493
562
|
const current = await this.#readSnapshot();
|
|
494
563
|
const stored = current.profiles.find((candidate) => candidate.id === expectedProfile.id);
|
|
564
|
+
const storedCredential = stored?.kind === 'remote' ? await this.credentials.get(stored) : null;
|
|
495
565
|
if (!stored ||
|
|
496
566
|
stored.kind !== 'remote' ||
|
|
497
567
|
!sameRemoteRuntimeHostProfile(stored, expectedProfile) ||
|
|
498
|
-
|
|
568
|
+
!storedCredential ||
|
|
569
|
+
!sameProfileCredential(storedCredential, target)) {
|
|
499
570
|
return { rebound: false, document: current };
|
|
500
571
|
}
|
|
501
572
|
const next = decodeRuntimeHostProfileDocument({
|
|
502
573
|
schemaVersion: PROFILE_SCHEMA_VERSION,
|
|
503
574
|
profiles: current.profiles.map((candidate) => candidate.id === profile.id ? profile : candidate),
|
|
504
575
|
});
|
|
505
|
-
await this.credentials.set(profile,
|
|
576
|
+
await this.credentials.set(profile, {
|
|
577
|
+
credential,
|
|
578
|
+
profileIncarnationId: storedCredential.profileIncarnationId,
|
|
579
|
+
});
|
|
506
580
|
try {
|
|
507
581
|
await writeProfileDocument(this.path, next);
|
|
508
582
|
}
|
|
509
583
|
catch (error) {
|
|
510
|
-
await restoreCredential(this.credentials, profile,
|
|
584
|
+
await restoreCredential(this.credentials, profile, storedCredential).catch((rollbackError) => {
|
|
511
585
|
throw new AggregateError([error, rollbackError], 'Runtime Host profile rebind failed and its credential could not be restored');
|
|
512
586
|
});
|
|
513
587
|
throw error;
|
|
@@ -515,6 +589,35 @@ class FileRuntimeHostProfileCatalog {
|
|
|
515
589
|
return { rebound: true, document: next };
|
|
516
590
|
});
|
|
517
591
|
}
|
|
592
|
+
mutateRemoteProfileIfCurrent(target, mutation) {
|
|
593
|
+
const expectedProfile = decodeRemoteRuntimeHostProfile(target.profile);
|
|
594
|
+
const expectedIncarnationId = requireProfileIncarnationId(target.profileIncarnationId);
|
|
595
|
+
return this.#exclusive(async () => {
|
|
596
|
+
const current = await this.#readSnapshot();
|
|
597
|
+
const profile = current.profiles.find((candidate) => candidate.id === expectedProfile.id && candidate.kind === 'remote');
|
|
598
|
+
if (!profile || !sameRemoteRuntimeHostProfileTarget(profile, expectedProfile))
|
|
599
|
+
return false;
|
|
600
|
+
const credential = await this.credentials.get(profile);
|
|
601
|
+
if (credential?.profileIncarnationId !== expectedIncarnationId)
|
|
602
|
+
return false;
|
|
603
|
+
await mutation(profile);
|
|
604
|
+
return true;
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
async readRemoteProfileIfCurrent(target) {
|
|
608
|
+
const expectedProfile = decodeRemoteRuntimeHostProfile(target.profile);
|
|
609
|
+
const expectedIncarnationId = requireProfileIncarnationId(target.profileIncarnationId);
|
|
610
|
+
return this.#exclusive(async () => {
|
|
611
|
+
const current = await this.#readSnapshot();
|
|
612
|
+
const profile = current.profiles.find((candidate) => candidate.id === expectedProfile.id && candidate.kind === 'remote');
|
|
613
|
+
if (!profile || !sameRemoteRuntimeHostProfileTarget(profile, expectedProfile)) {
|
|
614
|
+
return undefined;
|
|
615
|
+
}
|
|
616
|
+
return (await this.credentials.get(profile))?.profileIncarnationId === expectedIncarnationId
|
|
617
|
+
? profile
|
|
618
|
+
: undefined;
|
|
619
|
+
});
|
|
620
|
+
}
|
|
518
621
|
async #removeProfile(current, profile) {
|
|
519
622
|
const next = decodeRuntimeHostProfileDocument({
|
|
520
623
|
schemaVersion: PROFILE_SCHEMA_VERSION,
|
|
@@ -702,6 +805,100 @@ function requireProfileId(value) {
|
|
|
702
805
|
function profileCredentialSlot(profile) {
|
|
703
806
|
return `runtime-host-profile:${requireProfileId(profile.id)}:${profileCredentialBinding(profile)}`;
|
|
704
807
|
}
|
|
808
|
+
async function deleteCapabilityProviderCredential(credentials, target, ownerClientInstanceId) {
|
|
809
|
+
const slot = profileCredentialSlot(target.profile);
|
|
810
|
+
const stored = await credentials.getSecret(slot, 'runtime_host_capability_provider');
|
|
811
|
+
if (stored === null)
|
|
812
|
+
return;
|
|
813
|
+
const decoded = decodeCapabilityProviderCredential(stored);
|
|
814
|
+
if (decoded.ownerClientInstanceId !== requireClientInstanceId(ownerClientInstanceId) ||
|
|
815
|
+
decoded.profileIncarnationId !== requireProfileIncarnationId(target.profileIncarnationId)) {
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
await credentials.deleteSecret(slot, 'runtime_host_capability_provider');
|
|
819
|
+
}
|
|
820
|
+
function decodeCapabilityProviderCredential(value) {
|
|
821
|
+
try {
|
|
822
|
+
const parsed = JSON.parse(value);
|
|
823
|
+
const record = requireExactRecord(parsed, 'Runtime Host capability-provider credential', [
|
|
824
|
+
'schemaVersion',
|
|
825
|
+
'profileIncarnationId',
|
|
826
|
+
'ownerClientInstanceId',
|
|
827
|
+
'credential',
|
|
828
|
+
]);
|
|
829
|
+
if (record.schemaVersion !== 1) {
|
|
830
|
+
throw new Error('Runtime Host capability-provider credential schema is unsupported');
|
|
831
|
+
}
|
|
832
|
+
return {
|
|
833
|
+
ownerClientInstanceId: requireClientInstanceId(record.ownerClientInstanceId),
|
|
834
|
+
credential: requireRuntimeHostAccessCredential(record.credential),
|
|
835
|
+
profileIncarnationId: requireProfileIncarnationId(record.profileIncarnationId),
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
catch (error) {
|
|
839
|
+
throw new Error('Runtime Host capability-provider credential is invalid', { cause: error });
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
function encodeProfileCredential(credential) {
|
|
843
|
+
return `${PROFILE_CREDENTIAL_RECORD_PREFIX}${JSON.stringify({
|
|
844
|
+
schemaVersion: 1,
|
|
845
|
+
profileIncarnationId: requireProfileIncarnationId(credential.profileIncarnationId),
|
|
846
|
+
credential: requireRuntimeHostAccessCredential(credential.credential),
|
|
847
|
+
})}`;
|
|
848
|
+
}
|
|
849
|
+
function decodeProfileCredential(profile, value) {
|
|
850
|
+
if (!value.startsWith(PROFILE_CREDENTIAL_RECORD_PREFIX)) {
|
|
851
|
+
const credential = requireRuntimeHostAccessCredential(value);
|
|
852
|
+
return {
|
|
853
|
+
credential,
|
|
854
|
+
profileIncarnationId: legacyProfileIncarnationId(profile),
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
try {
|
|
858
|
+
const parsed = JSON.parse(value.slice(PROFILE_CREDENTIAL_RECORD_PREFIX.length));
|
|
859
|
+
const record = requireExactRecord(parsed, 'Runtime Host profile credential', [
|
|
860
|
+
'schemaVersion',
|
|
861
|
+
'profileIncarnationId',
|
|
862
|
+
'credential',
|
|
863
|
+
]);
|
|
864
|
+
if (record.schemaVersion !== 1) {
|
|
865
|
+
throw new Error('Runtime Host profile credential schema is unsupported');
|
|
866
|
+
}
|
|
867
|
+
return {
|
|
868
|
+
credential: requireRuntimeHostAccessCredential(record.credential),
|
|
869
|
+
profileIncarnationId: requireProfileIncarnationId(record.profileIncarnationId),
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
catch (error) {
|
|
873
|
+
throw new Error('Runtime Host profile credential is invalid', { cause: error });
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
function legacyProfileIncarnationId(profile) {
|
|
877
|
+
// Existing plaintext records predate incarnations. Their target-bound value
|
|
878
|
+
// remains stable until the next catalog write migrates the credential record.
|
|
879
|
+
return createHash('sha256')
|
|
880
|
+
.update('legacy-runtime-host-profile-incarnation')
|
|
881
|
+
.update('\0')
|
|
882
|
+
.update(profileCredentialSlot(profile))
|
|
883
|
+
.digest('hex');
|
|
884
|
+
}
|
|
885
|
+
function requireProfileIncarnationId(value) {
|
|
886
|
+
if (typeof value !== 'string' ||
|
|
887
|
+
value.length === 0 ||
|
|
888
|
+
Buffer.byteLength(value, 'utf8') > PROFILE_INCARNATION_ID_MAX_BYTES ||
|
|
889
|
+
!/^[A-Za-z0-9._-]+$/u.test(value)) {
|
|
890
|
+
throw new Error('Runtime Host profile incarnation is invalid');
|
|
891
|
+
}
|
|
892
|
+
return value;
|
|
893
|
+
}
|
|
894
|
+
function requireRuntimeHostAccessCredential(credential) {
|
|
895
|
+
if (!credential ||
|
|
896
|
+
/\s/u.test(credential) ||
|
|
897
|
+
Buffer.byteLength(credential, 'utf8') > RUNTIME_HOST_ACCESS_CREDENTIAL_MAX_BYTES) {
|
|
898
|
+
throw new Error('Runtime Host access credential is invalid');
|
|
899
|
+
}
|
|
900
|
+
return credential;
|
|
901
|
+
}
|
|
705
902
|
function profileTargetBinding(profile) {
|
|
706
903
|
if (profile.kind === 'remote')
|
|
707
904
|
return `remote\0${profileCredentialBinding(profile)}`;
|
|
@@ -782,6 +979,12 @@ function restoreCredential(credentials, profile, previousCredential) {
|
|
|
782
979
|
? credentials.delete(profile)
|
|
783
980
|
: credentials.set(profile, previousCredential);
|
|
784
981
|
}
|
|
982
|
+
function sameProfileCredential(stored, expected) {
|
|
983
|
+
return (stored !== null &&
|
|
984
|
+
stored.credential === expected.credential &&
|
|
985
|
+
(expected.profileIncarnationId === undefined ||
|
|
986
|
+
stored.profileIncarnationId === expected.profileIncarnationId));
|
|
987
|
+
}
|
|
785
988
|
function requireProfileName(value) {
|
|
786
989
|
const name = requireString(value, 'Runtime Host profile name').trim();
|
|
787
990
|
if (name.length === 0 ||
|