@moxt-ai/mobius 0.0.82 → 0.0.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp/session-config/session-config-registry.d.ts +1 -1
- package/dist/acp/session-config/session-config-registry.d.ts.map +1 -1
- package/dist/acp/session-config/session-config-registry.js +2 -3
- package/dist/acp/session-config/session-config-registry.js.map +1 -1
- package/dist/agent-catalog/agent-specification.d.ts +2 -0
- package/dist/agent-catalog/agent-specification.d.ts.map +1 -1
- package/dist/agent-catalog/agent-specification.js +2 -0
- package/dist/agent-catalog/agent-specification.js.map +1 -1
- package/dist/agent-catalog/agent-version.d.ts +3 -0
- package/dist/agent-catalog/agent-version.d.ts.map +1 -0
- package/dist/agent-catalog/agent-version.js +54 -0
- package/dist/agent-catalog/agent-version.js.map +1 -0
- package/dist/agent-catalog/agents/claude-code-agent.d.ts +2 -0
- package/dist/agent-catalog/agents/claude-code-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/claude-code-agent.js +2 -0
- package/dist/agent-catalog/agents/claude-code-agent.js.map +1 -1
- package/dist/agent-catalog/agents/codex-agent.d.ts +2 -0
- package/dist/agent-catalog/agents/codex-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/codex-agent.js +2 -0
- package/dist/agent-catalog/agents/codex-agent.js.map +1 -1
- package/dist/agent-catalog/agents/copilot-cli-agent.d.ts +2 -0
- package/dist/agent-catalog/agents/copilot-cli-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/copilot-cli-agent.js +2 -0
- package/dist/agent-catalog/agents/copilot-cli-agent.js.map +1 -1
- package/dist/agent-catalog/agents/cursor-cli-agent.d.ts +2 -0
- package/dist/agent-catalog/agents/cursor-cli-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/cursor-cli-agent.js +2 -0
- package/dist/agent-catalog/agents/cursor-cli-agent.js.map +1 -1
- package/dist/agent-catalog/agents/deepseek-harness-agent.d.ts +2 -0
- package/dist/agent-catalog/agents/deepseek-harness-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/deepseek-harness-agent.js +2 -0
- package/dist/agent-catalog/agents/deepseek-harness-agent.js.map +1 -1
- package/dist/agent-catalog/agents/gemini-cli-agent.d.ts +2 -0
- package/dist/agent-catalog/agents/gemini-cli-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/gemini-cli-agent.js +2 -0
- package/dist/agent-catalog/agents/gemini-cli-agent.js.map +1 -1
- package/dist/agent-catalog/agents/grok-build-agent.d.ts +2 -0
- package/dist/agent-catalog/agents/grok-build-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/grok-build-agent.js +2 -0
- package/dist/agent-catalog/agents/grok-build-agent.js.map +1 -1
- package/dist/agent-catalog/agents/hermes-agent.d.ts +2 -0
- package/dist/agent-catalog/agents/hermes-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/hermes-agent.js +2 -0
- package/dist/agent-catalog/agents/hermes-agent.js.map +1 -1
- package/dist/agent-catalog/agents/oh-my-pi-agent.d.ts +2 -0
- package/dist/agent-catalog/agents/oh-my-pi-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/oh-my-pi-agent.js +2 -0
- package/dist/agent-catalog/agents/oh-my-pi-agent.js.map +1 -1
- package/dist/agent-catalog/agents/opencode-agent.d.ts +2 -0
- package/dist/agent-catalog/agents/opencode-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/opencode-agent.js +2 -0
- package/dist/agent-catalog/agents/opencode-agent.js.map +1 -1
- package/dist/agent-catalog/agents/pi-agent.d.ts +2 -0
- package/dist/agent-catalog/agents/pi-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/pi-agent.js +2 -0
- package/dist/agent-catalog/agents/pi-agent.js.map +1 -1
- package/dist/agent-catalog/agents/workbuddy-agent.d.ts +2 -0
- package/dist/agent-catalog/agents/workbuddy-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/workbuddy-agent.js +2 -0
- package/dist/agent-catalog/agents/workbuddy-agent.js.map +1 -1
- package/dist/agent-catalog/discover-agent.d.ts.map +1 -1
- package/dist/agent-catalog/discover-agent.js +9 -0
- package/dist/agent-catalog/discover-agent.js.map +1 -1
- package/dist/agent-installation/deepseek-managed-package.d.ts.map +1 -1
- package/dist/agent-installation/deepseek-managed-package.js +3 -2
- package/dist/agent-installation/deepseek-managed-package.js.map +1 -1
- package/dist/cli.js +1151 -536
- package/dist/cli.js.map +4 -4
- package/dist/config.d.ts +2 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -10
- package/dist/config.js.map +1 -1
- package/dist/daemon-manager.d.ts +51 -0
- package/dist/daemon-manager.d.ts.map +1 -0
- package/dist/daemon-manager.js +589 -0
- package/dist/daemon-manager.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +336 -431
- package/dist/index.js.map +4 -4
- package/dist/pairing/pair-local-machine.d.ts.map +1 -1
- package/dist/pairing/pair-local-machine.js +26 -40
- package/dist/pairing/pair-local-machine.js.map +1 -1
- package/dist/relay-connection/session-event-outbox.d.ts.map +1 -1
- package/dist/relay-connection/session-event-outbox.js +0 -62
- package/dist/relay-connection/session-event-outbox.js.map +1 -1
- package/dist/run-daemon.d.ts +1 -0
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +16 -4
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.d.ts +3 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +317 -383
- package/dist/runtime.js.map +4 -4
- package/dist/storage/runtime-installation-store.d.ts +14 -5
- package/dist/storage/runtime-installation-store.d.ts.map +1 -1
- package/dist/storage/runtime-installation-store.js +136 -89
- package/dist/storage/runtime-installation-store.js.map +1 -1
- package/package.json +1 -1
- package/dist/acp/session-config/grok-build-session-config.d.ts +0 -10
- package/dist/acp/session-config/grok-build-session-config.d.ts.map +0 -1
- package/dist/acp/session-config/grok-build-session-config.js +0 -197
- package/dist/acp/session-config/grok-build-session-config.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -6,12 +6,14 @@ var __export = (target, all2) => {
|
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
// src/cli.ts
|
|
9
|
-
import {
|
|
9
|
+
import { constants as constants2 } from "node:fs";
|
|
10
|
+
import { mkdir as mkdir6, open as open7 } from "node:fs/promises";
|
|
11
|
+
import { resolve as resolve7 } from "node:path";
|
|
10
12
|
|
|
11
13
|
// package.json
|
|
12
14
|
var package_default = {
|
|
13
15
|
name: "@moxt-ai/mobius",
|
|
14
|
-
version: "0.0.
|
|
16
|
+
version: "0.0.89",
|
|
15
17
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
16
18
|
type: "module",
|
|
17
19
|
bin: {
|
|
@@ -1309,6 +1311,8 @@ function normalizeVersionOutput(output2) {
|
|
|
1309
1311
|
var VERSION_PROBE_TIMEOUT_MILLISECONDS = 3e4;
|
|
1310
1312
|
var ACP_PROBE_TIMEOUT_MILLISECONDS = 6e4;
|
|
1311
1313
|
var LocalAgentSpecification = class {
|
|
1314
|
+
minimumSupportedAgentVersion = "0.0.0";
|
|
1315
|
+
maximumTestedAgentVersion = "0.0.0";
|
|
1312
1316
|
acpProbeTimeoutMilliseconds = ACP_PROBE_TIMEOUT_MILLISECONDS;
|
|
1313
1317
|
authenticationCommand = () => "";
|
|
1314
1318
|
adapterVersionArguments = ["--version"];
|
|
@@ -1391,6 +1395,8 @@ var ClaudeCodeAgentSpecification = class extends BridgedAcpAgentDefinition {
|
|
|
1391
1395
|
agentOverrideVariable = "MOBIUS_CLAUDE_PATH";
|
|
1392
1396
|
id = "claude";
|
|
1393
1397
|
label = "Claude Code";
|
|
1398
|
+
minimumSupportedAgentVersion = "2.1.273";
|
|
1399
|
+
maximumTestedAgentVersion = "2.1.273";
|
|
1394
1400
|
managedAdapterExecutablePath = [
|
|
1395
1401
|
"adapters",
|
|
1396
1402
|
"claude",
|
|
@@ -6478,7 +6484,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
6478
6484
|
var NONE = 0;
|
|
6479
6485
|
var ASSUMED = 1;
|
|
6480
6486
|
var PROVEN = 2;
|
|
6481
|
-
function isRecursive(inst, stack,
|
|
6487
|
+
function isRecursive(inst, stack, resolve8) {
|
|
6482
6488
|
const cached2 = recursive.get(inst);
|
|
6483
6489
|
if (cached2 !== void 0)
|
|
6484
6490
|
return cached2 ? PROVEN : NONE;
|
|
@@ -6488,7 +6494,7 @@ function isRecursive(inst, stack, resolve7) {
|
|
|
6488
6494
|
let result = NONE;
|
|
6489
6495
|
const check2 = (child) => {
|
|
6490
6496
|
if (result !== PROVEN && child?._zod) {
|
|
6491
|
-
const answer = isRecursive(child, stack,
|
|
6497
|
+
const answer = isRecursive(child, stack, resolve8);
|
|
6492
6498
|
if (answer > result)
|
|
6493
6499
|
result = answer;
|
|
6494
6500
|
}
|
|
@@ -6499,7 +6505,7 @@ function isRecursive(inst, stack, resolve7) {
|
|
|
6499
6505
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
6500
6506
|
if (spread && !desc.enumerable)
|
|
6501
6507
|
continue;
|
|
6502
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
6508
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve8) : NONE;
|
|
6503
6509
|
if (child > answer)
|
|
6504
6510
|
answer = child;
|
|
6505
6511
|
}
|
|
@@ -6563,7 +6569,7 @@ function isRecursive(inst, stack, resolve7) {
|
|
|
6563
6569
|
break;
|
|
6564
6570
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
6565
6571
|
case "lazy": {
|
|
6566
|
-
const inner = def._cachedInner ?? (
|
|
6572
|
+
const inner = def._cachedInner ?? (resolve8 ? inst._zod.innerType : void 0);
|
|
6567
6573
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
6568
6574
|
break;
|
|
6569
6575
|
}
|
|
@@ -22623,6 +22629,8 @@ var CodexAgentSpecification = class extends InProcessAcpAgentDefinition2 {
|
|
|
22623
22629
|
createEndpoint = (options) => new CodexAcpAgent(options);
|
|
22624
22630
|
id = "codex";
|
|
22625
22631
|
label = "Codex";
|
|
22632
|
+
minimumSupportedAgentVersion = "0.153.0";
|
|
22633
|
+
maximumTestedAgentVersion = "0.154.0";
|
|
22626
22634
|
constructor() {
|
|
22627
22635
|
super("MOBIUS_CODEX_PATH", ["agents", "codex", "bin", "codex"]);
|
|
22628
22636
|
}
|
|
@@ -22685,6 +22693,8 @@ var CopilotCliAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
22685
22693
|
agentExecutable = "copilot";
|
|
22686
22694
|
id = "github-copilot-cli";
|
|
22687
22695
|
label = "GitHub Copilot CLI";
|
|
22696
|
+
minimumSupportedAgentVersion = COPILOT_CLI_TESTED_VERSION;
|
|
22697
|
+
maximumTestedAgentVersion = COPILOT_CLI_TESTED_VERSION;
|
|
22688
22698
|
versionProbeTimeoutMilliseconds = 1e4;
|
|
22689
22699
|
constructor() {
|
|
22690
22700
|
super(
|
|
@@ -22715,6 +22725,8 @@ var CursorCliAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
22715
22725
|
agentExecutable = "cursor-agent";
|
|
22716
22726
|
id = "cursor";
|
|
22717
22727
|
label = "Cursor CLI";
|
|
22728
|
+
minimumSupportedAgentVersion = CURSOR_CLI_TESTED_VERSION;
|
|
22729
|
+
maximumTestedAgentVersion = CURSOR_CLI_TESTED_VERSION;
|
|
22718
22730
|
constructor() {
|
|
22719
22731
|
super(
|
|
22720
22732
|
"MOBIUS_CURSOR_PATH",
|
|
@@ -22737,16 +22749,16 @@ import { isAbsolute as isAbsolute3, join as join6, normalize } from "node:path";
|
|
|
22737
22749
|
|
|
22738
22750
|
// src/agent-installation/deepseek-managed-package.ts
|
|
22739
22751
|
var DeepSeekHarnessManagedPackage = class extends SriManagedNpmPackageDefinition {
|
|
22740
|
-
dependencyResolutionArguments = Object.freeze(["--before=2026-09-
|
|
22752
|
+
dependencyResolutionArguments = Object.freeze(["--before=2026-09-23T00:00:00.000Z"]);
|
|
22741
22753
|
includeOptionalDependencies = true;
|
|
22742
22754
|
verifyDependencyClosure = true;
|
|
22743
22755
|
};
|
|
22744
22756
|
var DEEPSEEK_HARNESS_PACKAGE = new DeepSeekHarnessManagedPackage(
|
|
22745
22757
|
"@deepseek-ai/dsh",
|
|
22746
|
-
"0.1.5-rc.
|
|
22758
|
+
"0.1.5-rc.3",
|
|
22747
22759
|
"dsh",
|
|
22748
|
-
"sha512-
|
|
22749
|
-
"https://registry.npmjs.org/@deepseek-ai/dsh/-/dsh-0.1.5-rc.
|
|
22760
|
+
"sha512-c0W6Xqc4ChjFcCJkbzPeIxZQdnbKqe+QAcJzWGtogg0ZzsnZRcw3vopMyZ5oZU6E2fmyqGcyDR1sBeiCH4yHcg==",
|
|
22761
|
+
"https://registry.npmjs.org/@deepseek-ai/dsh/-/dsh-0.1.5-rc.3.tgz"
|
|
22750
22762
|
);
|
|
22751
22763
|
|
|
22752
22764
|
// src/storage/state-directory.ts
|
|
@@ -22801,6 +22813,8 @@ var DeepSeekHarnessAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
22801
22813
|
agentExecutable = "dsh";
|
|
22802
22814
|
id = "deepseek-harness";
|
|
22803
22815
|
label = "DeepSeek Harness";
|
|
22816
|
+
minimumSupportedAgentVersion = "0.1.2-rc.1";
|
|
22817
|
+
maximumTestedAgentVersion = DEEPSEEK_HARNESS_PACKAGE.version;
|
|
22804
22818
|
constructor() {
|
|
22805
22819
|
super(
|
|
22806
22820
|
"MOBIUS_DEEPSEEK_HARNESS_PATH",
|
|
@@ -22871,6 +22885,8 @@ var GeminiCliAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
22871
22885
|
agentExecutable = "gemini";
|
|
22872
22886
|
id = "gemini-cli";
|
|
22873
22887
|
label = "Gemini CLI";
|
|
22888
|
+
minimumSupportedAgentVersion = GEMINI_CLI_TESTED_VERSION;
|
|
22889
|
+
maximumTestedAgentVersion = GEMINI_CLI_TESTED_VERSION;
|
|
22874
22890
|
versionProbeTimeoutMilliseconds = 1e4;
|
|
22875
22891
|
constructor() {
|
|
22876
22892
|
super(
|
|
@@ -22972,6 +22988,8 @@ var GrokBuildAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
22972
22988
|
adapterVersionArguments = ["version"];
|
|
22973
22989
|
id = "grok-build";
|
|
22974
22990
|
label = "Grok Build";
|
|
22991
|
+
minimumSupportedAgentVersion = GROK_BUILD_MANAGED_VERSION;
|
|
22992
|
+
maximumTestedAgentVersion = GROK_BUILD_MANAGED_VERSION;
|
|
22975
22993
|
constructor() {
|
|
22976
22994
|
super(
|
|
22977
22995
|
"MOBIUS_GROK_BUILD_PATH",
|
|
@@ -23043,6 +23061,8 @@ var HermesAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
23043
23061
|
agentVersionArguments = ["acp", "--version"];
|
|
23044
23062
|
id = "hermes";
|
|
23045
23063
|
label = "Hermes Agent";
|
|
23064
|
+
minimumSupportedAgentVersion = HERMES_TESTED_VERSION;
|
|
23065
|
+
maximumTestedAgentVersion = HERMES_TESTED_VERSION;
|
|
23046
23066
|
constructor() {
|
|
23047
23067
|
super("MOBIUS_HERMES_PATH", ["acp"], ["agents", "hermes", HERMES_TESTED_VERSION, "bin", "hermes"]);
|
|
23048
23068
|
}
|
|
@@ -23071,6 +23091,8 @@ var OhMyPiAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
23071
23091
|
agentOverrideVariable = "MOBIUS_OH_MY_PI_PATH";
|
|
23072
23092
|
id = "oh-my-pi";
|
|
23073
23093
|
label = "Oh My Pi";
|
|
23094
|
+
minimumSupportedAgentVersion = OH_MY_PI_TESTED_VERSION;
|
|
23095
|
+
maximumTestedAgentVersion = OH_MY_PI_TESTED_VERSION;
|
|
23074
23096
|
constructor() {
|
|
23075
23097
|
super("MOBIUS_OH_MY_PI_PATH", ["acp"], ["agents", "oh-my-pi", OH_MY_PI_TESTED_VERSION, "bin", "omp"]);
|
|
23076
23098
|
}
|
|
@@ -23462,6 +23484,8 @@ var OpenCodeAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
23462
23484
|
agentExecutable = "opencode";
|
|
23463
23485
|
id = "opencode";
|
|
23464
23486
|
label = "OpenCode";
|
|
23487
|
+
minimumSupportedAgentVersion = OPENCODE_MANAGED_VERSION;
|
|
23488
|
+
maximumTestedAgentVersion = OPENCODE_MANAGED_VERSION;
|
|
23465
23489
|
constructor() {
|
|
23466
23490
|
super(
|
|
23467
23491
|
"MOBIUS_OPENCODE_PATH",
|
|
@@ -23536,6 +23560,8 @@ var PiAgentSpecification = class extends BridgedAcpAgentDefinition {
|
|
|
23536
23560
|
agentOverrideVariable = "MOBIUS_PI_PATH";
|
|
23537
23561
|
id = "pi";
|
|
23538
23562
|
label = "Pi";
|
|
23563
|
+
minimumSupportedAgentVersion = PI_AGENT_PACKAGE.version;
|
|
23564
|
+
maximumTestedAgentVersion = PI_AGENT_PACKAGE.version;
|
|
23539
23565
|
managedAdapterExecutablePath = [
|
|
23540
23566
|
"adapters",
|
|
23541
23567
|
"pi",
|
|
@@ -23630,6 +23656,8 @@ var WorkBuddyAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
23630
23656
|
agentExecutable = "codebuddy";
|
|
23631
23657
|
id = "workbuddy";
|
|
23632
23658
|
label = "WorkBuddy";
|
|
23659
|
+
minimumSupportedAgentVersion = "2.115.0";
|
|
23660
|
+
maximumTestedAgentVersion = WORKBUDDY_MANAGED_VERSION;
|
|
23633
23661
|
constructor() {
|
|
23634
23662
|
super(
|
|
23635
23663
|
"MOBIUS_WORKBUDDY_PATH",
|
|
@@ -23757,41 +23785,41 @@ var DiscoveryAcpHandler = class {
|
|
|
23757
23785
|
};
|
|
23758
23786
|
function readableAcpStream(input2) {
|
|
23759
23787
|
let byteLength = 0;
|
|
23760
|
-
let
|
|
23788
|
+
let open8 = true;
|
|
23761
23789
|
return new ReadableStream({
|
|
23762
23790
|
start(controller) {
|
|
23763
23791
|
input2.on("data", (chunk) => {
|
|
23764
|
-
if (!
|
|
23792
|
+
if (!open8) {
|
|
23765
23793
|
return;
|
|
23766
23794
|
}
|
|
23767
23795
|
if (!(chunk instanceof Uint8Array)) {
|
|
23768
|
-
|
|
23796
|
+
open8 = false;
|
|
23769
23797
|
controller.error(new Error("ACP adapter produced invalid output"));
|
|
23770
23798
|
return;
|
|
23771
23799
|
}
|
|
23772
23800
|
byteLength += chunk.byteLength;
|
|
23773
23801
|
if (byteLength > ACP_OUTPUT_LIMIT_BYTES) {
|
|
23774
|
-
|
|
23802
|
+
open8 = false;
|
|
23775
23803
|
controller.error(new Error("ACP adapter output limit exceeded"));
|
|
23776
23804
|
return;
|
|
23777
23805
|
}
|
|
23778
23806
|
controller.enqueue(new Uint8Array(chunk));
|
|
23779
23807
|
});
|
|
23780
23808
|
input2.once("end", () => {
|
|
23781
|
-
if (
|
|
23782
|
-
|
|
23809
|
+
if (open8) {
|
|
23810
|
+
open8 = false;
|
|
23783
23811
|
controller.close();
|
|
23784
23812
|
}
|
|
23785
23813
|
});
|
|
23786
23814
|
input2.once("error", (error62) => {
|
|
23787
|
-
if (
|
|
23788
|
-
|
|
23815
|
+
if (open8) {
|
|
23816
|
+
open8 = false;
|
|
23789
23817
|
controller.error(error62);
|
|
23790
23818
|
}
|
|
23791
23819
|
});
|
|
23792
23820
|
},
|
|
23793
23821
|
cancel() {
|
|
23794
|
-
|
|
23822
|
+
open8 = false;
|
|
23795
23823
|
}
|
|
23796
23824
|
});
|
|
23797
23825
|
}
|
|
@@ -23972,6 +24000,61 @@ async function probeAcpReadiness(specification, agent, environment, defaultWorks
|
|
|
23972
24000
|
}
|
|
23973
24001
|
}
|
|
23974
24002
|
|
|
24003
|
+
// src/agent-catalog/agent-version.ts
|
|
24004
|
+
function parseVersion(value) {
|
|
24005
|
+
const match = /(?:^|[^0-9])v?(\d+(?:\.\d+)+)(?:-([0-9A-Za-z.-]+))?/u.exec(value);
|
|
24006
|
+
if (match?.[1] === void 0) {
|
|
24007
|
+
return null;
|
|
24008
|
+
}
|
|
24009
|
+
return {
|
|
24010
|
+
core: match[1].split(".").map(Number),
|
|
24011
|
+
prerelease: match[2]?.split(".") ?? []
|
|
24012
|
+
};
|
|
24013
|
+
}
|
|
24014
|
+
function comparePrerelease(left, right) {
|
|
24015
|
+
if (left.length === 0 || right.length === 0) {
|
|
24016
|
+
return left.length === right.length ? 0 : left.length === 0 ? 1 : -1;
|
|
24017
|
+
}
|
|
24018
|
+
for (let index2 = 0; index2 < Math.max(left.length, right.length); index2 += 1) {
|
|
24019
|
+
const leftPart = left[index2];
|
|
24020
|
+
const rightPart = right[index2];
|
|
24021
|
+
if (leftPart === void 0 || rightPart === void 0) {
|
|
24022
|
+
return leftPart === rightPart ? 0 : leftPart === void 0 ? -1 : 1;
|
|
24023
|
+
}
|
|
24024
|
+
if (leftPart === rightPart) {
|
|
24025
|
+
continue;
|
|
24026
|
+
}
|
|
24027
|
+
const leftNumber = /^\d+$/u.test(leftPart) ? Number(leftPart) : null;
|
|
24028
|
+
const rightNumber = /^\d+$/u.test(rightPart) ? Number(rightPart) : null;
|
|
24029
|
+
if (leftNumber !== null && rightNumber !== null) {
|
|
24030
|
+
return Math.sign(leftNumber - rightNumber);
|
|
24031
|
+
}
|
|
24032
|
+
if (leftNumber !== null || rightNumber !== null) {
|
|
24033
|
+
return leftNumber !== null ? -1 : 1;
|
|
24034
|
+
}
|
|
24035
|
+
return leftPart.localeCompare(rightPart);
|
|
24036
|
+
}
|
|
24037
|
+
return 0;
|
|
24038
|
+
}
|
|
24039
|
+
function compareAgentVersions(left, right) {
|
|
24040
|
+
const parsedLeft = parseVersion(left);
|
|
24041
|
+
const parsedRight = parseVersion(right);
|
|
24042
|
+
if (parsedLeft === null || parsedRight === null) {
|
|
24043
|
+
return null;
|
|
24044
|
+
}
|
|
24045
|
+
for (let index2 = 0; index2 < Math.max(parsedLeft.core.length, parsedRight.core.length); index2 += 1) {
|
|
24046
|
+
const difference = (parsedLeft.core[index2] ?? 0) - (parsedRight.core[index2] ?? 0);
|
|
24047
|
+
if (difference !== 0) {
|
|
24048
|
+
return Math.sign(difference);
|
|
24049
|
+
}
|
|
24050
|
+
}
|
|
24051
|
+
return comparePrerelease(parsedLeft.prerelease, parsedRight.prerelease);
|
|
24052
|
+
}
|
|
24053
|
+
function isAgentVersionSupported(reportedVersion, minimumSupportedVersion) {
|
|
24054
|
+
const comparison = compareAgentVersions(reportedVersion, minimumSupportedVersion);
|
|
24055
|
+
return comparison === null ? null : comparison >= 0;
|
|
24056
|
+
}
|
|
24057
|
+
|
|
23975
24058
|
// src/agent-catalog/executable-discovery.ts
|
|
23976
24059
|
import { isAbsolute as isAbsolute7, join as join13 } from "node:path";
|
|
23977
24060
|
|
|
@@ -24253,6 +24336,18 @@ async function discoverAgent(specification, context) {
|
|
|
24253
24336
|
lastFailure = agentProbeFailure(specification, error62);
|
|
24254
24337
|
continue;
|
|
24255
24338
|
}
|
|
24339
|
+
const supportedVersion = isAgentVersionSupported(agentVersion, specification.minimumSupportedAgentVersion);
|
|
24340
|
+
if (supportedVersion === null) {
|
|
24341
|
+
lastFailure = new AgentProbeFailed(
|
|
24342
|
+
specification,
|
|
24343
|
+
"agent_probe_failed",
|
|
24344
|
+
"Agent reported an unrecognized version"
|
|
24345
|
+
);
|
|
24346
|
+
continue;
|
|
24347
|
+
}
|
|
24348
|
+
if (!supportedVersion) {
|
|
24349
|
+
continue;
|
|
24350
|
+
}
|
|
24256
24351
|
const installedAgent = new AgentIntegrationDefinition(
|
|
24257
24352
|
specification.id,
|
|
24258
24353
|
specification.label,
|
|
@@ -26256,16 +26351,7 @@ var OpaqueDaemonReconnectTarget = class extends DaemonReconnectTarget {
|
|
|
26256
26351
|
this.commandArgument = `--connection ${connectionId2}`;
|
|
26257
26352
|
}
|
|
26258
26353
|
};
|
|
26259
|
-
|
|
26260
|
-
channelId;
|
|
26261
|
-
commandArgument;
|
|
26262
|
-
constructor(channelId) {
|
|
26263
|
-
super();
|
|
26264
|
-
this.channelId = channelId;
|
|
26265
|
-
this.commandArgument = `--channel ${channelId}`;
|
|
26266
|
-
}
|
|
26267
|
-
};
|
|
26268
|
-
function createDaemonConfig(connection, agents = [], installableAgents = [], localContext = new DaemonLocalContext(readStateDirectory(), process.env), reconnectTarget = new ChannelDaemonReconnectTarget(connection.channelId)) {
|
|
26354
|
+
function createDaemonConfig(connection, agents = [], installableAgents = [], localContext = new DaemonLocalContext(readStateDirectory(), process.env), reconnectTarget = null) {
|
|
26269
26355
|
const daemonAgents = agents.map((agent) => withDaemonEnvironment(agent, localContext.environment));
|
|
26270
26356
|
return {
|
|
26271
26357
|
agents: daemonAgents,
|
|
@@ -26281,6 +26367,14 @@ function createDaemonConfig(connection, agents = [], installableAgents = [], loc
|
|
|
26281
26367
|
};
|
|
26282
26368
|
}
|
|
26283
26369
|
|
|
26370
|
+
// src/daemon-manager.ts
|
|
26371
|
+
import { spawn as spawn6 } from "node:child_process";
|
|
26372
|
+
import { createHash as createHash5, randomBytes } from "node:crypto";
|
|
26373
|
+
import { open as open6, readFile as readFile3, unlink as unlink2, writeFile as writeFile4 } from "node:fs/promises";
|
|
26374
|
+
import { createConnection, createServer } from "node:net";
|
|
26375
|
+
import { tmpdir } from "node:os";
|
|
26376
|
+
import { join as join18 } from "node:path";
|
|
26377
|
+
|
|
26284
26378
|
// src/pairing/pair-local-machine.ts
|
|
26285
26379
|
import { mkdir as mkdir5, realpath as realpath6, stat as stat5 } from "node:fs/promises";
|
|
26286
26380
|
import { hostname as hostname3 } from "node:os";
|
|
@@ -26289,7 +26383,7 @@ import { fetch as fetch2 } from "undici";
|
|
|
26289
26383
|
|
|
26290
26384
|
// src/storage/runtime-installation-store.ts
|
|
26291
26385
|
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
26292
|
-
import { mkdir as mkdir4, open as open4, rename as rename3, unlink, writeFile as writeFile3 } from "node:fs/promises";
|
|
26386
|
+
import { mkdir as mkdir4, open as open4, readdir as readdir2, rename as rename3, unlink, writeFile as writeFile3 } from "node:fs/promises";
|
|
26293
26387
|
import { dirname as dirname3, join as join15, resolve as resolve4 } from "node:path";
|
|
26294
26388
|
var APPLICATION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+){1,31}$/;
|
|
26295
26389
|
var CONNECTION_ID_PATTERN = /^mcn_[a-f0-9]{32}$/;
|
|
@@ -26306,18 +26400,31 @@ var CHANNEL_INDEX_KEYS = [
|
|
|
26306
26400
|
"version"
|
|
26307
26401
|
];
|
|
26308
26402
|
var VERIFIED_CONNECTION_KEYS = [
|
|
26403
|
+
"activation",
|
|
26404
|
+
"appId",
|
|
26309
26405
|
"applicationId",
|
|
26310
26406
|
"channelId",
|
|
26311
26407
|
"connectionId",
|
|
26312
26408
|
"defaultWorkspace",
|
|
26313
26409
|
"installationId",
|
|
26314
26410
|
"kind",
|
|
26411
|
+
"pairingId",
|
|
26315
26412
|
"relayOrigin",
|
|
26316
26413
|
"runtimeCredential",
|
|
26317
26414
|
"runtimeId",
|
|
26318
26415
|
"version"
|
|
26319
26416
|
];
|
|
26417
|
+
var VERSION_THREE_VERIFIED_CONNECTION_KEYS = VERIFIED_CONNECTION_KEYS.filter(
|
|
26418
|
+
(key) => key !== "activation"
|
|
26419
|
+
);
|
|
26420
|
+
var VERSION_TWO_VERIFIED_CONNECTION_KEYS = VERSION_THREE_VERIFIED_CONNECTION_KEYS.filter(
|
|
26421
|
+
(key) => key !== "pairingId"
|
|
26422
|
+
);
|
|
26423
|
+
var LEGACY_VERIFIED_CONNECTION_KEYS = VERSION_TWO_VERIFIED_CONNECTION_KEYS.filter(
|
|
26424
|
+
(key) => key !== "appId"
|
|
26425
|
+
);
|
|
26320
26426
|
var IMPORTED_LEGACY_CONNECTION_KEYS = [
|
|
26427
|
+
"activation",
|
|
26321
26428
|
"applicationId",
|
|
26322
26429
|
"channelId",
|
|
26323
26430
|
"connectionId",
|
|
@@ -26328,13 +26435,9 @@ var IMPORTED_LEGACY_CONNECTION_KEYS = [
|
|
|
26328
26435
|
"runtimeCredential",
|
|
26329
26436
|
"version"
|
|
26330
26437
|
];
|
|
26331
|
-
var
|
|
26332
|
-
"
|
|
26333
|
-
|
|
26334
|
-
"relayOrigin",
|
|
26335
|
-
"runtimeCredential"
|
|
26336
|
-
];
|
|
26337
|
-
var LEGACY_CONNECTION_KEYS = ["defaultWorkspace", "channelId", "daemonToken", "relayOrigin"];
|
|
26438
|
+
var VERSION_ONE_IMPORTED_LEGACY_CONNECTION_KEYS = IMPORTED_LEGACY_CONNECTION_KEYS.filter(
|
|
26439
|
+
(key) => key !== "activation"
|
|
26440
|
+
);
|
|
26338
26441
|
var RuntimeInstallationStoreError = class extends Error {
|
|
26339
26442
|
code;
|
|
26340
26443
|
constructor(code, message, options = {}) {
|
|
@@ -26344,19 +26447,25 @@ var RuntimeInstallationStoreError = class extends Error {
|
|
|
26344
26447
|
}
|
|
26345
26448
|
};
|
|
26346
26449
|
var StoredRuntimeConnection = class {
|
|
26450
|
+
activation;
|
|
26451
|
+
appId;
|
|
26347
26452
|
applicationId;
|
|
26348
26453
|
channelId;
|
|
26349
26454
|
connectionId;
|
|
26350
26455
|
defaultWorkspace;
|
|
26351
26456
|
installationId;
|
|
26457
|
+
pairingId;
|
|
26352
26458
|
relayOrigin;
|
|
26353
26459
|
runtimeCredential;
|
|
26354
|
-
constructor(applicationId, installationId2, connectionId2, channelId, defaultWorkspace, relayOrigin, runtimeCredential2) {
|
|
26460
|
+
constructor(activation, applicationId, appId, installationId2, connectionId2, channelId, defaultWorkspace, pairingId, relayOrigin, runtimeCredential2) {
|
|
26461
|
+
this.activation = activation;
|
|
26355
26462
|
this.applicationId = applicationId;
|
|
26463
|
+
this.appId = appId;
|
|
26356
26464
|
this.channelId = channelId;
|
|
26357
26465
|
this.connectionId = connectionId2;
|
|
26358
26466
|
this.defaultWorkspace = defaultWorkspace;
|
|
26359
26467
|
this.installationId = installationId2;
|
|
26468
|
+
this.pairingId = pairingId;
|
|
26360
26469
|
this.relayOrigin = relayOrigin;
|
|
26361
26470
|
this.runtimeCredential = runtimeCredential2;
|
|
26362
26471
|
}
|
|
@@ -26364,15 +26473,37 @@ var StoredRuntimeConnection = class {
|
|
|
26364
26473
|
var VerifiedRuntimeConnection = class extends StoredRuntimeConnection {
|
|
26365
26474
|
kind = "verified";
|
|
26366
26475
|
runtimeId;
|
|
26367
|
-
constructor(applicationId, installationId2, connectionId2, channelId, defaultWorkspace, relayOrigin, runtimeCredential2, runtimeId) {
|
|
26368
|
-
super(
|
|
26476
|
+
constructor(activation, applicationId, appId, installationId2, connectionId2, channelId, defaultWorkspace, pairingId, relayOrigin, runtimeCredential2, runtimeId) {
|
|
26477
|
+
super(
|
|
26478
|
+
activation,
|
|
26479
|
+
applicationId,
|
|
26480
|
+
appId,
|
|
26481
|
+
installationId2,
|
|
26482
|
+
connectionId2,
|
|
26483
|
+
channelId,
|
|
26484
|
+
defaultWorkspace,
|
|
26485
|
+
pairingId,
|
|
26486
|
+
relayOrigin,
|
|
26487
|
+
runtimeCredential2
|
|
26488
|
+
);
|
|
26369
26489
|
this.runtimeId = runtimeId;
|
|
26370
26490
|
}
|
|
26371
26491
|
};
|
|
26372
26492
|
var ImportedLegacyRuntimeConnection = class extends StoredRuntimeConnection {
|
|
26373
26493
|
kind = "legacy_imported";
|
|
26374
|
-
constructor(applicationId, installationId2, connectionId2, channelId, defaultWorkspace, relayOrigin, runtimeCredential2) {
|
|
26375
|
-
super(
|
|
26494
|
+
constructor(activation, applicationId, installationId2, connectionId2, channelId, defaultWorkspace, relayOrigin, runtimeCredential2) {
|
|
26495
|
+
super(
|
|
26496
|
+
activation,
|
|
26497
|
+
applicationId,
|
|
26498
|
+
"unknown",
|
|
26499
|
+
installationId2,
|
|
26500
|
+
connectionId2,
|
|
26501
|
+
channelId,
|
|
26502
|
+
defaultWorkspace,
|
|
26503
|
+
"",
|
|
26504
|
+
relayOrigin,
|
|
26505
|
+
runtimeCredential2
|
|
26506
|
+
);
|
|
26376
26507
|
}
|
|
26377
26508
|
};
|
|
26378
26509
|
function isRecord5(value) {
|
|
@@ -26391,6 +26522,12 @@ function validateApplicationId(value) {
|
|
|
26391
26522
|
}
|
|
26392
26523
|
return value;
|
|
26393
26524
|
}
|
|
26525
|
+
function validateRemoteAppId(value) {
|
|
26526
|
+
if (!IDENTIFIER_PATTERN4.test(value)) {
|
|
26527
|
+
throw new RuntimeInstallationStoreError("invalid_app_id", "The remote App ID is invalid");
|
|
26528
|
+
}
|
|
26529
|
+
return value;
|
|
26530
|
+
}
|
|
26394
26531
|
function validateConnectionId(value) {
|
|
26395
26532
|
if (!CONNECTION_ID_PATTERN.test(value)) {
|
|
26396
26533
|
throw new RuntimeInstallationStoreError("invalid_connection_id", "The local connection ID is invalid");
|
|
@@ -26470,46 +26607,61 @@ function decodeChannelIndex(value) {
|
|
|
26470
26607
|
};
|
|
26471
26608
|
}
|
|
26472
26609
|
function decodeVerifiedConnection(value) {
|
|
26473
|
-
|
|
26610
|
+
const current = hasExactKeys(value, VERIFIED_CONNECTION_KEYS) && value["version"] === 4;
|
|
26611
|
+
const versionThree = hasExactKeys(value, VERSION_THREE_VERIFIED_CONNECTION_KEYS) && value["version"] === 3;
|
|
26612
|
+
const versionTwo = hasExactKeys(value, VERSION_TWO_VERIFIED_CONNECTION_KEYS) && value["version"] === 2;
|
|
26613
|
+
const legacy = hasExactKeys(value, LEGACY_VERIFIED_CONNECTION_KEYS) && value["version"] === 1;
|
|
26614
|
+
if (!current && !versionThree && !versionTwo && !legacy || value["kind"] !== "verified") {
|
|
26474
26615
|
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
26475
26616
|
}
|
|
26476
26617
|
const applicationId = value["applicationId"];
|
|
26618
|
+
const activation = current ? value["activation"] : "active";
|
|
26619
|
+
const appId = typeof value["appId"] === "string" ? value["appId"] : "unknown";
|
|
26477
26620
|
const channelId = value["channelId"];
|
|
26478
26621
|
const connectionId2 = value["connectionId"];
|
|
26479
26622
|
const defaultWorkspace = value["defaultWorkspace"];
|
|
26480
26623
|
const storedInstallationId = value["installationId"];
|
|
26624
|
+
const pairingId = value["pairingId"];
|
|
26625
|
+
const savedPairingId = typeof pairingId === "string" ? pairingId : "";
|
|
26481
26626
|
const relayOrigin = value["relayOrigin"];
|
|
26482
26627
|
const runtimeCredential2 = value["runtimeCredential"];
|
|
26483
26628
|
const runtimeId = value["runtimeId"];
|
|
26484
|
-
if (typeof applicationId !== "string" || typeof channelId !== "string" || typeof connectionId2 !== "string" || typeof defaultWorkspace !== "string" || typeof storedInstallationId !== "string" || typeof relayOrigin !== "string" || typeof runtimeCredential2 !== "string" || typeof runtimeId !== "string") {
|
|
26629
|
+
if (typeof applicationId !== "string" || activation !== "active" && activation !== "stopped" || (current || versionThree || versionTwo) && typeof value["appId"] !== "string" || typeof channelId !== "string" || typeof connectionId2 !== "string" || typeof defaultWorkspace !== "string" || typeof storedInstallationId !== "string" || (current || versionThree) && typeof pairingId !== "string" || typeof relayOrigin !== "string" || typeof runtimeCredential2 !== "string" || typeof runtimeId !== "string") {
|
|
26485
26630
|
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
26486
26631
|
}
|
|
26487
26632
|
return new VerifiedRuntimeConnection(
|
|
26633
|
+
activation,
|
|
26488
26634
|
validateApplicationId(applicationId),
|
|
26635
|
+
validateRemoteAppId(appId),
|
|
26489
26636
|
validateInstallationId(storedInstallationId),
|
|
26490
26637
|
validateConnectionId(connectionId2),
|
|
26491
26638
|
validateIdentifier(channelId, "invalid_connection"),
|
|
26492
26639
|
defaultWorkspace,
|
|
26640
|
+
(current || versionThree) && savedPairingId.length > 0 ? validateIdentifier(savedPairingId, "invalid_connection") : "",
|
|
26493
26641
|
parseRelayOrigin(relayOrigin),
|
|
26494
26642
|
validateRuntimeCredential(runtimeCredential2),
|
|
26495
26643
|
validateIdentifier(runtimeId, "invalid_connection")
|
|
26496
26644
|
);
|
|
26497
26645
|
}
|
|
26498
26646
|
function decodeImportedLegacyConnection(value) {
|
|
26499
|
-
|
|
26647
|
+
const current = hasExactKeys(value, IMPORTED_LEGACY_CONNECTION_KEYS) && value["version"] === 2;
|
|
26648
|
+
const legacy = hasExactKeys(value, VERSION_ONE_IMPORTED_LEGACY_CONNECTION_KEYS) && value["version"] === 1;
|
|
26649
|
+
if (!current && !legacy || value["kind"] !== "legacy_imported" || value["version"] !== 1 && value["version"] !== 2) {
|
|
26500
26650
|
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
26501
26651
|
}
|
|
26502
26652
|
const applicationId = value["applicationId"];
|
|
26653
|
+
const activation = current ? value["activation"] : "active";
|
|
26503
26654
|
const channelId = value["channelId"];
|
|
26504
26655
|
const connectionId2 = value["connectionId"];
|
|
26505
26656
|
const defaultWorkspace = value["defaultWorkspace"];
|
|
26506
26657
|
const storedInstallationId = value["installationId"];
|
|
26507
26658
|
const relayOrigin = value["relayOrigin"];
|
|
26508
26659
|
const runtimeCredential2 = value["runtimeCredential"];
|
|
26509
|
-
if (typeof applicationId !== "string" || typeof channelId !== "string" || typeof connectionId2 !== "string" || typeof defaultWorkspace !== "string" || typeof storedInstallationId !== "string" || typeof relayOrigin !== "string" || typeof runtimeCredential2 !== "string") {
|
|
26660
|
+
if (typeof applicationId !== "string" || activation !== "active" && activation !== "stopped" || typeof channelId !== "string" || typeof connectionId2 !== "string" || typeof defaultWorkspace !== "string" || typeof storedInstallationId !== "string" || typeof relayOrigin !== "string" || typeof runtimeCredential2 !== "string") {
|
|
26510
26661
|
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
26511
26662
|
}
|
|
26512
26663
|
return new ImportedLegacyRuntimeConnection(
|
|
26664
|
+
activation,
|
|
26513
26665
|
validateApplicationId(applicationId),
|
|
26514
26666
|
validateInstallationId(storedInstallationId),
|
|
26515
26667
|
validateConnectionId(connectionId2),
|
|
@@ -26531,24 +26683,6 @@ function decodeConnection(value) {
|
|
|
26531
26683
|
}
|
|
26532
26684
|
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
26533
26685
|
}
|
|
26534
|
-
function decodeLegacyConnection(value, expectedChannelId) {
|
|
26535
|
-
if (!isRecord5(value) || !hasExactKeys(value, CURRENT_CONNECTION_KEYS) && !hasExactKeys(value, LEGACY_CONNECTION_KEYS)) {
|
|
26536
|
-
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
26537
|
-
}
|
|
26538
|
-
const channelId = value["channelId"];
|
|
26539
|
-
const defaultWorkspace = value["defaultWorkspace"];
|
|
26540
|
-
const relayOrigin = value["relayOrigin"];
|
|
26541
|
-
const runtimeCredential2 = value["runtimeCredential"] ?? value["daemonToken"];
|
|
26542
|
-
if (typeof channelId !== "string" || channelId !== expectedChannelId || typeof defaultWorkspace !== "string" || typeof relayOrigin !== "string" || typeof runtimeCredential2 !== "string") {
|
|
26543
|
-
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
26544
|
-
}
|
|
26545
|
-
return {
|
|
26546
|
-
channelId: validateIdentifier(channelId, "invalid_connection"),
|
|
26547
|
-
defaultWorkspace,
|
|
26548
|
-
relayOrigin: parseRelayOrigin(relayOrigin),
|
|
26549
|
-
runtimeCredential: validateRuntimeCredential(runtimeCredential2)
|
|
26550
|
-
};
|
|
26551
|
-
}
|
|
26552
26686
|
async function readJsonFile(path2, signal, missingCode) {
|
|
26553
26687
|
signal.throwIfAborted();
|
|
26554
26688
|
let handle;
|
|
@@ -26679,23 +26813,16 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
26679
26813
|
}
|
|
26680
26814
|
return await this.readConnection(index2.connectionId, signal);
|
|
26681
26815
|
};
|
|
26682
|
-
migrateLegacyConnection = async (legacyStateDirectory, channelId, signal) => {
|
|
26683
|
-
try {
|
|
26684
|
-
return await this.#readConnectionForChannel(channelId, signal);
|
|
26685
|
-
} catch (cause) {
|
|
26686
|
-
if (!(cause instanceof RuntimeInstallationStoreError) || cause.code !== "connection_not_found") {
|
|
26687
|
-
throw cause;
|
|
26688
|
-
}
|
|
26689
|
-
}
|
|
26690
|
-
return await this.importLegacyConnection(legacyStateDirectory, channelId, signal);
|
|
26691
|
-
};
|
|
26692
26816
|
saveConnection = async (input2, signal) => {
|
|
26693
26817
|
const stored = new VerifiedRuntimeConnection(
|
|
26818
|
+
"active",
|
|
26694
26819
|
this.applicationId,
|
|
26820
|
+
validateRemoteAppId(input2.appId),
|
|
26695
26821
|
this.installationId,
|
|
26696
26822
|
connectionId(),
|
|
26697
26823
|
validateIdentifier(input2.channelId, "invalid_connection"),
|
|
26698
26824
|
input2.defaultWorkspace,
|
|
26825
|
+
input2.pairingId.length === 0 ? "" : validateIdentifier(input2.pairingId, "invalid_pairing_id"),
|
|
26699
26826
|
parseRelayOrigin(input2.relayOrigin.toString()),
|
|
26700
26827
|
validateRuntimeCredential(input2.runtimeCredential),
|
|
26701
26828
|
validateIdentifier(input2.runtimeId, "invalid_connection")
|
|
@@ -26703,25 +26830,6 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
26703
26830
|
await this.writeConnection(stored, signal);
|
|
26704
26831
|
return stored;
|
|
26705
26832
|
};
|
|
26706
|
-
importLegacyConnection = async (legacyStateDirectory, channelId, signal) => {
|
|
26707
|
-
const normalizedChannelId = validateIdentifier(channelId, "invalid_channel_id");
|
|
26708
|
-
const legacyPath = join15(resolve4(legacyStateDirectory), "connections", `${normalizedChannelId}.json`);
|
|
26709
|
-
const legacy = decodeLegacyConnection(
|
|
26710
|
-
await readJsonFile(legacyPath, signal, "connection_not_found"),
|
|
26711
|
-
normalizedChannelId
|
|
26712
|
-
);
|
|
26713
|
-
const stored = new ImportedLegacyRuntimeConnection(
|
|
26714
|
-
this.applicationId,
|
|
26715
|
-
this.installationId,
|
|
26716
|
-
connectionId(),
|
|
26717
|
-
legacy.channelId,
|
|
26718
|
-
legacy.defaultWorkspace,
|
|
26719
|
-
legacy.relayOrigin,
|
|
26720
|
-
legacy.runtimeCredential
|
|
26721
|
-
);
|
|
26722
|
-
await this.writeConnection(stored, signal);
|
|
26723
|
-
return stored;
|
|
26724
|
-
};
|
|
26725
26833
|
writeConnection = async (stored, signal) => {
|
|
26726
26834
|
signal.throwIfAborted();
|
|
26727
26835
|
try {
|
|
@@ -26735,49 +26843,134 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
26735
26843
|
throw cause;
|
|
26736
26844
|
}
|
|
26737
26845
|
}
|
|
26738
|
-
|
|
26739
|
-
|
|
26740
|
-
|
|
26741
|
-
|
|
26846
|
+
await this.overwriteConnection(stored, signal);
|
|
26847
|
+
await writeJsonAtomically(
|
|
26848
|
+
this.channelIndexPath(stored.channelId),
|
|
26849
|
+
{
|
|
26850
|
+
applicationId: this.applicationId,
|
|
26851
|
+
channelId: stored.channelId,
|
|
26852
|
+
connectionId: stored.connectionId,
|
|
26853
|
+
installationId: this.installationId,
|
|
26854
|
+
version: 1
|
|
26855
|
+
},
|
|
26856
|
+
signal
|
|
26857
|
+
);
|
|
26858
|
+
};
|
|
26859
|
+
listConnections = async (signal) => {
|
|
26860
|
+
signal.throwIfAborted();
|
|
26861
|
+
let entries;
|
|
26862
|
+
try {
|
|
26863
|
+
entries = await readdir2(this.#connectionDirectory);
|
|
26864
|
+
} catch (cause) {
|
|
26865
|
+
if (isNodeError(cause, "ENOENT")) {
|
|
26866
|
+
return [];
|
|
26867
|
+
}
|
|
26868
|
+
throw new RuntimeInstallationStoreError(
|
|
26869
|
+
"connection_unavailable",
|
|
26870
|
+
"Saved Runtime connections cannot be listed",
|
|
26742
26871
|
{
|
|
26743
|
-
|
|
26744
|
-
|
|
26745
|
-
connectionId: stored.connectionId,
|
|
26746
|
-
defaultWorkspace: stored.defaultWorkspace,
|
|
26747
|
-
installationId: stored.installationId,
|
|
26748
|
-
kind: stored.kind,
|
|
26749
|
-
relayOrigin: stored.relayOrigin.toString(),
|
|
26750
|
-
runtimeCredential: stored.runtimeCredential,
|
|
26751
|
-
runtimeId: stored.runtimeId,
|
|
26752
|
-
version: 1
|
|
26753
|
-
},
|
|
26754
|
-
signal
|
|
26872
|
+
cause
|
|
26873
|
+
}
|
|
26755
26874
|
);
|
|
26756
|
-
}
|
|
26875
|
+
}
|
|
26876
|
+
const connections = [];
|
|
26877
|
+
for (const entry of [...entries].sort()) {
|
|
26878
|
+
signal.throwIfAborted();
|
|
26879
|
+
const match = /^(mcn_[a-f0-9]{32})\.json$/.exec(entry);
|
|
26880
|
+
if (match?.[1] !== void 0) {
|
|
26881
|
+
connections.push(await this.readConnection(match[1], signal));
|
|
26882
|
+
}
|
|
26883
|
+
}
|
|
26884
|
+
return connections;
|
|
26885
|
+
};
|
|
26886
|
+
readConnectionForPairing = async (pairingId, signal) => {
|
|
26887
|
+
const normalizedPairingId = validateIdentifier(pairingId, "invalid_pairing_id");
|
|
26888
|
+
const connections = await this.listConnections(signal);
|
|
26889
|
+
return connections.find((connection) => connection.pairingId === normalizedPairingId) ?? null;
|
|
26890
|
+
};
|
|
26891
|
+
setConnectionActivation = async (connectionId2, activation, signal) => {
|
|
26892
|
+
const connection = await this.readConnection(connectionId2, signal);
|
|
26893
|
+
const updated = connection instanceof VerifiedRuntimeConnection ? new VerifiedRuntimeConnection(
|
|
26894
|
+
activation,
|
|
26895
|
+
connection.applicationId,
|
|
26896
|
+
connection.appId,
|
|
26897
|
+
connection.installationId,
|
|
26898
|
+
connection.connectionId,
|
|
26899
|
+
connection.channelId,
|
|
26900
|
+
connection.defaultWorkspace,
|
|
26901
|
+
connection.pairingId,
|
|
26902
|
+
connection.relayOrigin,
|
|
26903
|
+
connection.runtimeCredential,
|
|
26904
|
+
connection.runtimeId
|
|
26905
|
+
) : new ImportedLegacyRuntimeConnection(
|
|
26906
|
+
activation,
|
|
26907
|
+
connection.applicationId,
|
|
26908
|
+
connection.installationId,
|
|
26909
|
+
connection.connectionId,
|
|
26910
|
+
connection.channelId,
|
|
26911
|
+
connection.defaultWorkspace,
|
|
26912
|
+
connection.relayOrigin,
|
|
26913
|
+
connection.runtimeCredential
|
|
26914
|
+
);
|
|
26915
|
+
await this.overwriteConnection(updated, signal);
|
|
26916
|
+
return updated;
|
|
26917
|
+
};
|
|
26918
|
+
removeConnection = async (connectionId2, signal) => {
|
|
26919
|
+
const connection = await this.readConnection(connectionId2, signal);
|
|
26920
|
+
signal.throwIfAborted();
|
|
26921
|
+
try {
|
|
26922
|
+
await unlink(this.connectionPath(connection.connectionId));
|
|
26923
|
+
signal.throwIfAborted();
|
|
26924
|
+
await unlink(this.channelIndexPath(connection.channelId));
|
|
26925
|
+
} catch (cause) {
|
|
26926
|
+
signal.throwIfAborted();
|
|
26927
|
+
if (isNodeError(cause, "ENOENT")) {
|
|
26928
|
+
return;
|
|
26929
|
+
}
|
|
26930
|
+
throw new RuntimeInstallationStoreError(
|
|
26931
|
+
"connection_unavailable",
|
|
26932
|
+
"The saved Runtime connection cannot be removed",
|
|
26933
|
+
{ cause }
|
|
26934
|
+
);
|
|
26935
|
+
}
|
|
26936
|
+
};
|
|
26937
|
+
overwriteConnection = async (connection, signal) => {
|
|
26938
|
+
const connectionPath = this.connectionPath(connection.connectionId);
|
|
26939
|
+
if (connection instanceof VerifiedRuntimeConnection) {
|
|
26757
26940
|
await writeJsonAtomically(
|
|
26758
26941
|
connectionPath,
|
|
26759
26942
|
{
|
|
26760
|
-
|
|
26761
|
-
|
|
26762
|
-
|
|
26763
|
-
|
|
26764
|
-
|
|
26765
|
-
|
|
26766
|
-
|
|
26767
|
-
|
|
26768
|
-
|
|
26943
|
+
activation: connection.activation,
|
|
26944
|
+
applicationId: connection.applicationId,
|
|
26945
|
+
appId: connection.appId,
|
|
26946
|
+
channelId: connection.channelId,
|
|
26947
|
+
connectionId: connection.connectionId,
|
|
26948
|
+
defaultWorkspace: connection.defaultWorkspace,
|
|
26949
|
+
installationId: connection.installationId,
|
|
26950
|
+
kind: connection.kind,
|
|
26951
|
+
pairingId: connection.pairingId,
|
|
26952
|
+
relayOrigin: connection.relayOrigin.toString(),
|
|
26953
|
+
runtimeCredential: connection.runtimeCredential,
|
|
26954
|
+
runtimeId: connection.runtimeId,
|
|
26955
|
+
version: 4
|
|
26769
26956
|
},
|
|
26770
26957
|
signal
|
|
26771
26958
|
);
|
|
26959
|
+
return;
|
|
26772
26960
|
}
|
|
26773
26961
|
await writeJsonAtomically(
|
|
26774
|
-
|
|
26962
|
+
connectionPath,
|
|
26775
26963
|
{
|
|
26776
|
-
|
|
26777
|
-
|
|
26778
|
-
|
|
26779
|
-
|
|
26780
|
-
|
|
26964
|
+
activation: connection.activation,
|
|
26965
|
+
applicationId: connection.applicationId,
|
|
26966
|
+
channelId: connection.channelId,
|
|
26967
|
+
connectionId: connection.connectionId,
|
|
26968
|
+
defaultWorkspace: connection.defaultWorkspace,
|
|
26969
|
+
installationId: connection.installationId,
|
|
26970
|
+
kind: connection.kind,
|
|
26971
|
+
relayOrigin: connection.relayOrigin.toString(),
|
|
26972
|
+
runtimeCredential: connection.runtimeCredential,
|
|
26973
|
+
version: 2
|
|
26781
26974
|
},
|
|
26782
26975
|
signal
|
|
26783
26976
|
);
|
|
@@ -26861,7 +27054,7 @@ function readSingleOption(arguments_, option) {
|
|
|
26861
27054
|
function assertKnownArguments(arguments_) {
|
|
26862
27055
|
for (let index2 = 0; index2 < arguments_.length; index2 += 2) {
|
|
26863
27056
|
const option = arguments_[index2];
|
|
26864
|
-
if (option !== "--url" && option !== "--code" && option !== "--pairing" && option !== "--workspace") {
|
|
27057
|
+
if (option !== "--url" && option !== "--code" && option !== "--pairing" && option !== "--workspace" && option !== "--app-id") {
|
|
26865
27058
|
throw new PairingClientError("invalid_arguments", `Unknown pairing option: ${option ?? "missing option"}`);
|
|
26866
27059
|
}
|
|
26867
27060
|
}
|
|
@@ -26900,6 +27093,7 @@ function parsePairingCode(value) {
|
|
|
26900
27093
|
function parsePairCommand(arguments_, defaultWorkspace) {
|
|
26901
27094
|
assertKnownArguments(arguments_);
|
|
26902
27095
|
return {
|
|
27096
|
+
appId: arguments_.includes("--app-id") ? validatePairingId(readSingleOption(arguments_, "--app-id")) : "standalone",
|
|
26903
27097
|
code: parsePairingCode(readSingleOption(arguments_, "--code")),
|
|
26904
27098
|
pairingId: arguments_.includes("--pairing") ? validatePairingId(readSingleOption(arguments_, "--pairing")) : "",
|
|
26905
27099
|
relayOrigin: parseRelayOrigin2(readSingleOption(arguments_, "--url")),
|
|
@@ -26912,48 +27106,15 @@ function validatePairingId(value) {
|
|
|
26912
27106
|
}
|
|
26913
27107
|
return value;
|
|
26914
27108
|
}
|
|
26915
|
-
|
|
26916
|
-
|
|
26917
|
-
|
|
26918
|
-
connectionId;
|
|
26919
|
-
constructor(connectionId2) {
|
|
26920
|
-
super();
|
|
26921
|
-
this.connectionId = connectionId2;
|
|
26922
|
-
}
|
|
26923
|
-
resume = async (installation, signal, environment) => await resumeMobiusRuntime(installation, this.connectionId, signal, environment);
|
|
26924
|
-
};
|
|
26925
|
-
var LegacyChannelResumeCommandTarget = class extends ResumeCommandTarget {
|
|
26926
|
-
channelId;
|
|
26927
|
-
constructor(channelId) {
|
|
26928
|
-
super();
|
|
26929
|
-
this.channelId = channelId;
|
|
26930
|
-
}
|
|
26931
|
-
resume = async (installation, signal, environment) => await resumeLegacyChannel(installation, this.channelId, signal, environment);
|
|
26932
|
-
};
|
|
26933
|
-
function parseResumeArgument(arguments_) {
|
|
26934
|
-
if (arguments_.length !== 2) {
|
|
26935
|
-
throw new PairingClientError(
|
|
26936
|
-
"invalid_arguments",
|
|
26937
|
-
"Usage: mobius start --connection <connection-id> or mobius start --channel <legacy-channel-id>"
|
|
26938
|
-
);
|
|
27109
|
+
function parseResumeConnectionId(arguments_) {
|
|
27110
|
+
if (arguments_.length !== 2 || arguments_[0] !== "--connection") {
|
|
27111
|
+
throw new PairingClientError("invalid_arguments", "Usage: mobius start --connection <connection-id>");
|
|
26939
27112
|
}
|
|
26940
27113
|
const value = arguments_[1] ?? "";
|
|
26941
|
-
if (
|
|
26942
|
-
|
|
26943
|
-
throw new PairingClientError("invalid_connection_id", "The saved Runtime connection ID is invalid");
|
|
26944
|
-
}
|
|
26945
|
-
return new ConnectionResumeCommandTarget(value);
|
|
26946
|
-
}
|
|
26947
|
-
if (arguments_[0] === "--channel") {
|
|
26948
|
-
if (!IDENTIFIER_PATTERN5.test(value)) {
|
|
26949
|
-
throw new PairingClientError("invalid_channel_id", "The saved channel ID is invalid");
|
|
26950
|
-
}
|
|
26951
|
-
return new LegacyChannelResumeCommandTarget(value);
|
|
27114
|
+
if (!/^mcn_[a-f0-9]{32}$/.test(value)) {
|
|
27115
|
+
throw new PairingClientError("invalid_connection_id", "The saved Runtime connection ID is invalid");
|
|
26952
27116
|
}
|
|
26953
|
-
|
|
26954
|
-
"invalid_arguments",
|
|
26955
|
-
"Usage: mobius start --connection <connection-id> or mobius start --channel <legacy-channel-id>"
|
|
26956
|
-
);
|
|
27117
|
+
return value;
|
|
26957
27118
|
}
|
|
26958
27119
|
async function resolveDefaultWorkspace(path2) {
|
|
26959
27120
|
const requestedWorkspace = resolve5(path2);
|
|
@@ -27089,8 +27250,10 @@ async function pairRuntime(installation, options, signal, environment) {
|
|
|
27089
27250
|
const claim2 = await claimPairing(options, defaultWorkspace, agents, inventory.installable, signal);
|
|
27090
27251
|
const connection = await installation.saveConnection(
|
|
27091
27252
|
{
|
|
27253
|
+
appId: options.appId,
|
|
27092
27254
|
channelId: claim2.channelId,
|
|
27093
27255
|
defaultWorkspace,
|
|
27256
|
+
pairingId: options.pairingId,
|
|
27094
27257
|
relayOrigin: options.relayOrigin,
|
|
27095
27258
|
runtimeCredential: claim2.runtimeCredential,
|
|
27096
27259
|
runtimeId: claim2.runtimeId
|
|
@@ -27113,10 +27276,6 @@ async function resumeMobiusRuntime(installation, connectionId2, signal, environm
|
|
|
27113
27276
|
const connection = await installation.readConnection(connectionId2, signal);
|
|
27114
27277
|
return await resumeRuntimeConnection(installation, connection, signal, environment);
|
|
27115
27278
|
}
|
|
27116
|
-
async function resumeLegacyChannel(installation, channelId, signal, environment) {
|
|
27117
|
-
const connection = await installation.migrateLegacyConnection(readStateDirectory(environment), channelId, signal);
|
|
27118
|
-
return await resumeRuntimeConnection(installation, connection, signal, environment);
|
|
27119
|
-
}
|
|
27120
27279
|
async function openMobiusCliInstallation(signal, environment) {
|
|
27121
27280
|
return await openRuntimeInstallationStore(
|
|
27122
27281
|
{
|
|
@@ -27130,9 +27289,16 @@ async function pairLocalMachine(arguments_, signal = new AbortController().signa
|
|
|
27130
27289
|
const requested = parsePairCommand(arguments_, "");
|
|
27131
27290
|
const installation = await openMobiusCliInstallation(signal, process.env);
|
|
27132
27291
|
const localContext = new DaemonLocalContext(installation.stateDirectory, process.env);
|
|
27292
|
+
if (requested.pairingId.length > 0) {
|
|
27293
|
+
const existing = await installation.readConnectionForPairing(requested.pairingId, signal);
|
|
27294
|
+
if (existing !== null) {
|
|
27295
|
+
return await resumeRuntimeConnection(installation, existing, signal, process.env);
|
|
27296
|
+
}
|
|
27297
|
+
}
|
|
27133
27298
|
return await pairRuntime(
|
|
27134
27299
|
installation,
|
|
27135
27300
|
{
|
|
27301
|
+
appId: requested.appId,
|
|
27136
27302
|
code: requested.code,
|
|
27137
27303
|
pairingId: requested.pairingId,
|
|
27138
27304
|
relayOrigin: requested.relayOrigin,
|
|
@@ -27143,9 +27309,9 @@ async function pairLocalMachine(arguments_, signal = new AbortController().signa
|
|
|
27143
27309
|
);
|
|
27144
27310
|
}
|
|
27145
27311
|
async function resumeLocalMachine(arguments_, signal = new AbortController().signal) {
|
|
27146
|
-
const
|
|
27312
|
+
const connectionId2 = parseResumeConnectionId(arguments_);
|
|
27147
27313
|
const installation = await openMobiusCliInstallation(signal, process.env);
|
|
27148
|
-
return await
|
|
27314
|
+
return await resumeMobiusRuntime(installation, connectionId2, signal, process.env);
|
|
27149
27315
|
}
|
|
27150
27316
|
|
|
27151
27317
|
// src/audit/audit-store.ts
|
|
@@ -30664,10 +30830,10 @@ function resolveAll(constructs2, events, context) {
|
|
|
30664
30830
|
const called = [];
|
|
30665
30831
|
let index2 = -1;
|
|
30666
30832
|
while (++index2 < constructs2.length) {
|
|
30667
|
-
const
|
|
30668
|
-
if (
|
|
30669
|
-
events =
|
|
30670
|
-
called.push(
|
|
30833
|
+
const resolve8 = constructs2[index2].resolveAll;
|
|
30834
|
+
if (resolve8 && !called.includes(resolve8)) {
|
|
30835
|
+
events = resolve8(events, context);
|
|
30836
|
+
called.push(resolve8);
|
|
30671
30837
|
}
|
|
30672
30838
|
}
|
|
30673
30839
|
return events;
|
|
@@ -30681,7 +30847,7 @@ var attention = {
|
|
|
30681
30847
|
};
|
|
30682
30848
|
function resolveAllAttention(events, context) {
|
|
30683
30849
|
let index2 = -1;
|
|
30684
|
-
let
|
|
30850
|
+
let open8;
|
|
30685
30851
|
let group;
|
|
30686
30852
|
let text3;
|
|
30687
30853
|
let openingSequence;
|
|
@@ -30691,16 +30857,16 @@ function resolveAllAttention(events, context) {
|
|
|
30691
30857
|
let offset;
|
|
30692
30858
|
while (++index2 < events.length) {
|
|
30693
30859
|
if (events[index2][0] === "enter" && events[index2][1].type === "attentionSequence" && events[index2][1]._close) {
|
|
30694
|
-
|
|
30695
|
-
while (
|
|
30696
|
-
if (events[
|
|
30697
|
-
context.sliceSerialize(events[
|
|
30698
|
-
if ((events[
|
|
30860
|
+
open8 = index2;
|
|
30861
|
+
while (open8--) {
|
|
30862
|
+
if (events[open8][0] === "exit" && events[open8][1].type === "attentionSequence" && events[open8][1]._open && // If the markers are the same:
|
|
30863
|
+
context.sliceSerialize(events[open8][1]).charCodeAt(0) === context.sliceSerialize(events[index2][1]).charCodeAt(0)) {
|
|
30864
|
+
if ((events[open8][1]._close || events[index2][1]._open) && (events[index2][1].end.offset - events[index2][1].start.offset) % 3 && !((events[open8][1].end.offset - events[open8][1].start.offset + events[index2][1].end.offset - events[index2][1].start.offset) % 3)) {
|
|
30699
30865
|
continue;
|
|
30700
30866
|
}
|
|
30701
|
-
use = events[
|
|
30867
|
+
use = events[open8][1].end.offset - events[open8][1].start.offset > 1 && events[index2][1].end.offset - events[index2][1].start.offset > 1 ? 2 : 1;
|
|
30702
30868
|
const start = {
|
|
30703
|
-
...events[
|
|
30869
|
+
...events[open8][1].end
|
|
30704
30870
|
};
|
|
30705
30871
|
const end = {
|
|
30706
30872
|
...events[index2][1].start
|
|
@@ -30711,7 +30877,7 @@ function resolveAllAttention(events, context) {
|
|
|
30711
30877
|
type: use > 1 ? "strongSequence" : "emphasisSequence",
|
|
30712
30878
|
start,
|
|
30713
30879
|
end: {
|
|
30714
|
-
...events[
|
|
30880
|
+
...events[open8][1].end
|
|
30715
30881
|
}
|
|
30716
30882
|
};
|
|
30717
30883
|
closingSequence = {
|
|
@@ -30724,7 +30890,7 @@ function resolveAllAttention(events, context) {
|
|
|
30724
30890
|
text3 = {
|
|
30725
30891
|
type: use > 1 ? "strongText" : "emphasisText",
|
|
30726
30892
|
start: {
|
|
30727
|
-
...events[
|
|
30893
|
+
...events[open8][1].end
|
|
30728
30894
|
},
|
|
30729
30895
|
end: {
|
|
30730
30896
|
...events[index2][1].start
|
|
@@ -30739,18 +30905,18 @@ function resolveAllAttention(events, context) {
|
|
|
30739
30905
|
...closingSequence.end
|
|
30740
30906
|
}
|
|
30741
30907
|
};
|
|
30742
|
-
events[
|
|
30908
|
+
events[open8][1].end = {
|
|
30743
30909
|
...openingSequence.start
|
|
30744
30910
|
};
|
|
30745
30911
|
events[index2][1].start = {
|
|
30746
30912
|
...closingSequence.end
|
|
30747
30913
|
};
|
|
30748
30914
|
nextEvents = [];
|
|
30749
|
-
if (events[
|
|
30750
|
-
nextEvents = push(nextEvents, [["enter", events[
|
|
30915
|
+
if (events[open8][1].end.offset - events[open8][1].start.offset) {
|
|
30916
|
+
nextEvents = push(nextEvents, [["enter", events[open8][1], context], ["exit", events[open8][1], context]]);
|
|
30751
30917
|
}
|
|
30752
30918
|
nextEvents = push(nextEvents, [["enter", group, context], ["enter", openingSequence, context], ["exit", openingSequence, context], ["enter", text3, context]]);
|
|
30753
|
-
nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(
|
|
30919
|
+
nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open8 + 1, index2), context));
|
|
30754
30920
|
nextEvents = push(nextEvents, [["exit", text3, context], ["enter", closingSequence, context], ["exit", closingSequence, context], ["exit", group, context]]);
|
|
30755
30921
|
if (events[index2][1].end.offset - events[index2][1].start.offset) {
|
|
30756
30922
|
offset = 2;
|
|
@@ -30758,8 +30924,8 @@ function resolveAllAttention(events, context) {
|
|
|
30758
30924
|
} else {
|
|
30759
30925
|
offset = 0;
|
|
30760
30926
|
}
|
|
30761
|
-
splice(events,
|
|
30762
|
-
index2 =
|
|
30927
|
+
splice(events, open8 - 1, index2 - open8 + 3, nextEvents);
|
|
30928
|
+
index2 = open8 + nextEvents.length - offset - 2;
|
|
30763
30929
|
break;
|
|
30764
30930
|
}
|
|
30765
30931
|
}
|
|
@@ -30791,10 +30957,10 @@ function tokenizeAttention(effects, ok2) {
|
|
|
30791
30957
|
}
|
|
30792
30958
|
const token = effects.exit("attentionSequence");
|
|
30793
30959
|
const after = classifyCharacter(code);
|
|
30794
|
-
const
|
|
30960
|
+
const open8 = !after || after === 2 && before || attentionMarkers2.includes(code);
|
|
30795
30961
|
const close = !before || before === 2 && after || attentionMarkers2.includes(previous2);
|
|
30796
|
-
token._open = Boolean(marker === 42 ?
|
|
30797
|
-
token._close = Boolean(marker === 42 ? close : close && (after || !
|
|
30962
|
+
token._open = Boolean(marker === 42 ? open8 : open8 && (before || !close));
|
|
30963
|
+
token._close = Boolean(marker === 42 ? close : close && (after || !open8));
|
|
30798
30964
|
return ok2(code);
|
|
30799
30965
|
}
|
|
30800
30966
|
}
|
|
@@ -30818,9 +30984,9 @@ function tokenizeAutolink(effects, ok2, nok) {
|
|
|
30818
30984
|
effects.consume(code);
|
|
30819
30985
|
effects.exit("autolinkMarker");
|
|
30820
30986
|
effects.enter("autolinkProtocol");
|
|
30821
|
-
return
|
|
30987
|
+
return open8;
|
|
30822
30988
|
}
|
|
30823
|
-
function
|
|
30989
|
+
function open8(code) {
|
|
30824
30990
|
if (asciiAlpha(code)) {
|
|
30825
30991
|
effects.consume(code);
|
|
30826
30992
|
return schemeOrEmailAtext;
|
|
@@ -31020,9 +31186,9 @@ function tokenizeCharacterReference(effects, ok2, nok) {
|
|
|
31020
31186
|
effects.enter("characterReferenceMarker");
|
|
31021
31187
|
effects.consume(code);
|
|
31022
31188
|
effects.exit("characterReferenceMarker");
|
|
31023
|
-
return
|
|
31189
|
+
return open8;
|
|
31024
31190
|
}
|
|
31025
|
-
function
|
|
31191
|
+
function open8(code) {
|
|
31026
31192
|
if (code === 35) {
|
|
31027
31193
|
effects.enter("characterReferenceMarkerNumeric");
|
|
31028
31194
|
effects.consume(code);
|
|
@@ -32391,9 +32557,9 @@ function tokenizeHtmlFlow(effects, ok2, nok) {
|
|
|
32391
32557
|
effects.enter("htmlFlow");
|
|
32392
32558
|
effects.enter("htmlFlowData");
|
|
32393
32559
|
effects.consume(code);
|
|
32394
|
-
return
|
|
32560
|
+
return open8;
|
|
32395
32561
|
}
|
|
32396
|
-
function
|
|
32562
|
+
function open8(code) {
|
|
32397
32563
|
if (code === 33) {
|
|
32398
32564
|
effects.consume(code);
|
|
32399
32565
|
return declarationOpen;
|
|
@@ -32741,9 +32907,9 @@ function tokenizeHtmlText(effects, ok2, nok) {
|
|
|
32741
32907
|
effects.enter("htmlText");
|
|
32742
32908
|
effects.enter("htmlTextData");
|
|
32743
32909
|
effects.consume(code);
|
|
32744
|
-
return
|
|
32910
|
+
return open8;
|
|
32745
32911
|
}
|
|
32746
|
-
function
|
|
32912
|
+
function open8(code) {
|
|
32747
32913
|
if (code === 33) {
|
|
32748
32914
|
effects.consume(code);
|
|
32749
32915
|
return declarationOpen;
|
|
@@ -33069,12 +33235,12 @@ function resolveToLabelEnd(events, context) {
|
|
|
33069
33235
|
let index2 = events.length;
|
|
33070
33236
|
let offset = 0;
|
|
33071
33237
|
let token;
|
|
33072
|
-
let
|
|
33238
|
+
let open8;
|
|
33073
33239
|
let close;
|
|
33074
33240
|
let media;
|
|
33075
33241
|
while (index2--) {
|
|
33076
33242
|
token = events[index2][1];
|
|
33077
|
-
if (
|
|
33243
|
+
if (open8) {
|
|
33078
33244
|
if (token.type === "link" || token.type === "labelLink" && token._inactive) {
|
|
33079
33245
|
break;
|
|
33080
33246
|
}
|
|
@@ -33083,7 +33249,7 @@ function resolveToLabelEnd(events, context) {
|
|
|
33083
33249
|
}
|
|
33084
33250
|
} else if (close) {
|
|
33085
33251
|
if (events[index2][0] === "enter" && (token.type === "labelImage" || token.type === "labelLink") && !token._balanced) {
|
|
33086
|
-
|
|
33252
|
+
open8 = index2;
|
|
33087
33253
|
if (token.type !== "labelLink") {
|
|
33088
33254
|
offset = 2;
|
|
33089
33255
|
break;
|
|
@@ -33094,9 +33260,9 @@ function resolveToLabelEnd(events, context) {
|
|
|
33094
33260
|
}
|
|
33095
33261
|
}
|
|
33096
33262
|
const group = {
|
|
33097
|
-
type: events[
|
|
33263
|
+
type: events[open8][1].type === "labelLink" ? "link" : "image",
|
|
33098
33264
|
start: {
|
|
33099
|
-
...events[
|
|
33265
|
+
...events[open8][1].start
|
|
33100
33266
|
},
|
|
33101
33267
|
end: {
|
|
33102
33268
|
...events[events.length - 1][1].end
|
|
@@ -33105,7 +33271,7 @@ function resolveToLabelEnd(events, context) {
|
|
|
33105
33271
|
const label = {
|
|
33106
33272
|
type: "label",
|
|
33107
33273
|
start: {
|
|
33108
|
-
...events[
|
|
33274
|
+
...events[open8][1].start
|
|
33109
33275
|
},
|
|
33110
33276
|
end: {
|
|
33111
33277
|
...events[close][1].end
|
|
@@ -33114,20 +33280,20 @@ function resolveToLabelEnd(events, context) {
|
|
|
33114
33280
|
const text3 = {
|
|
33115
33281
|
type: "labelText",
|
|
33116
33282
|
start: {
|
|
33117
|
-
...events[
|
|
33283
|
+
...events[open8 + offset + 2][1].end
|
|
33118
33284
|
},
|
|
33119
33285
|
end: {
|
|
33120
33286
|
...events[close - 2][1].start
|
|
33121
33287
|
}
|
|
33122
33288
|
};
|
|
33123
33289
|
media = [["enter", group, context], ["enter", label, context]];
|
|
33124
|
-
media = push(media, events.slice(
|
|
33290
|
+
media = push(media, events.slice(open8 + 1, open8 + offset + 3));
|
|
33125
33291
|
media = push(media, [["enter", text3, context]]);
|
|
33126
|
-
media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(
|
|
33292
|
+
media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open8 + offset + 4, close - 3), context));
|
|
33127
33293
|
media = push(media, [["exit", text3, context], events[close - 2], events[close - 1], ["exit", label, context]]);
|
|
33128
33294
|
media = push(media, events.slice(close + 1));
|
|
33129
33295
|
media = push(media, [["exit", group, context]]);
|
|
33130
|
-
splice(events,
|
|
33296
|
+
splice(events, open8, events.length, media);
|
|
33131
33297
|
return events;
|
|
33132
33298
|
}
|
|
33133
33299
|
function tokenizeLabelEnd(effects, ok2, nok) {
|
|
@@ -33272,9 +33438,9 @@ function tokenizeLabelStartImage(effects, ok2, nok) {
|
|
|
33272
33438
|
effects.enter("labelImageMarker");
|
|
33273
33439
|
effects.consume(code);
|
|
33274
33440
|
effects.exit("labelImageMarker");
|
|
33275
|
-
return
|
|
33441
|
+
return open8;
|
|
33276
33442
|
}
|
|
33277
|
-
function
|
|
33443
|
+
function open8(code) {
|
|
33278
33444
|
if (code === 91) {
|
|
33279
33445
|
effects.enter("labelMarker");
|
|
33280
33446
|
effects.consume(code);
|
|
@@ -34578,8 +34744,8 @@ function compiler(options) {
|
|
|
34578
34744
|
return length;
|
|
34579
34745
|
}
|
|
34580
34746
|
function opener(create, and) {
|
|
34581
|
-
return
|
|
34582
|
-
function
|
|
34747
|
+
return open8;
|
|
34748
|
+
function open8(token) {
|
|
34583
34749
|
enter.call(this, create(token), token);
|
|
34584
34750
|
if (and) and.call(this, token);
|
|
34585
34751
|
}
|
|
@@ -34611,18 +34777,18 @@ function compiler(options) {
|
|
|
34611
34777
|
}
|
|
34612
34778
|
function exit2(token, onExitError) {
|
|
34613
34779
|
const node3 = this.stack.pop();
|
|
34614
|
-
const
|
|
34615
|
-
if (!
|
|
34780
|
+
const open8 = this.tokenStack.pop();
|
|
34781
|
+
if (!open8) {
|
|
34616
34782
|
throw new Error("Cannot close `" + token.type + "` (" + stringifyPosition({
|
|
34617
34783
|
start: token.start,
|
|
34618
34784
|
end: token.end
|
|
34619
34785
|
}) + "): it\u2019s not open");
|
|
34620
|
-
} else if (
|
|
34786
|
+
} else if (open8[0].type !== token.type) {
|
|
34621
34787
|
if (onExitError) {
|
|
34622
|
-
onExitError.call(this, token,
|
|
34788
|
+
onExitError.call(this, token, open8[0]);
|
|
34623
34789
|
} else {
|
|
34624
|
-
const handler =
|
|
34625
|
-
handler.call(this, token,
|
|
34790
|
+
const handler = open8[1] || defaultOnError;
|
|
34791
|
+
handler.call(this, token, open8[0]);
|
|
34626
34792
|
}
|
|
34627
34793
|
}
|
|
34628
34794
|
node3.position.end = point2(token.end);
|
|
@@ -35297,7 +35463,6 @@ var nativeSessionPageSchema = external_exports.object({
|
|
|
35297
35463
|
|
|
35298
35464
|
// src/acp/session-config/session-config-protocol.ts
|
|
35299
35465
|
import { methods as methods7 } from "@agentclientprotocol/sdk";
|
|
35300
|
-
var AGENT_DEFAULT_REASONING_EFFORT = "agent_default";
|
|
35301
35466
|
var MAXIMUM_CONFIG_OPTIONS = 100;
|
|
35302
35467
|
var SessionConfigProtocolError = class extends Error {
|
|
35303
35468
|
code = "invalid_session_configuration_response";
|
|
@@ -35495,207 +35660,9 @@ var StandardSessionConfigProtocol = class {
|
|
|
35495
35660
|
};
|
|
35496
35661
|
var standardSessionConfigProtocol = new StandardSessionConfigProtocol();
|
|
35497
35662
|
|
|
35498
|
-
// src/acp/session-config/grok-build-session-config.ts
|
|
35499
|
-
var LEGACY_MODEL_CONFIG_ID = "grok_build_legacy_model";
|
|
35500
|
-
var LEGACY_REASONING_EFFORT_CONFIG_ID = "grok_build_legacy_reasoning_effort";
|
|
35501
|
-
function legacyOptions(response) {
|
|
35502
|
-
if (!isRecord8(response)) {
|
|
35503
|
-
return [];
|
|
35504
|
-
}
|
|
35505
|
-
const metadata = response["_meta"];
|
|
35506
|
-
if (!isRecord8(metadata)) {
|
|
35507
|
-
return [];
|
|
35508
|
-
}
|
|
35509
|
-
const sessionConfig = metadata["x.ai/sessionConfig"];
|
|
35510
|
-
if (!isRecord8(sessionConfig) || !Array.isArray(sessionConfig["options"])) {
|
|
35511
|
-
return [];
|
|
35512
|
-
}
|
|
35513
|
-
return sessionConfig["options"].slice(0, 500).filter(isRecord8);
|
|
35514
|
-
}
|
|
35515
|
-
function legacyValue(option) {
|
|
35516
|
-
const value = readString2(option["id"]);
|
|
35517
|
-
return {
|
|
35518
|
-
description: readString2(option["description"]).slice(0, 500),
|
|
35519
|
-
groupId: "",
|
|
35520
|
-
groupName: "",
|
|
35521
|
-
name: readString2(option["label"], value).slice(0, 255),
|
|
35522
|
-
value: value.slice(0, 500)
|
|
35523
|
-
};
|
|
35524
|
-
}
|
|
35525
|
-
function modelsRecord(response) {
|
|
35526
|
-
if (!isRecord8(response) || !isRecord8(response["models"])) {
|
|
35527
|
-
return {};
|
|
35528
|
-
}
|
|
35529
|
-
return response["models"];
|
|
35530
|
-
}
|
|
35531
|
-
function legacyModelOptions(response) {
|
|
35532
|
-
const options = legacyOptions(response);
|
|
35533
|
-
const models = modelsRecord(response);
|
|
35534
|
-
const values = [];
|
|
35535
|
-
for (const option of options) {
|
|
35536
|
-
if (option["category"] === "model") {
|
|
35537
|
-
const value = legacyValue(option);
|
|
35538
|
-
if (value.value.length > 0 && !values.some((existing) => existing.value === value.value)) {
|
|
35539
|
-
values.push(value);
|
|
35540
|
-
}
|
|
35541
|
-
}
|
|
35542
|
-
}
|
|
35543
|
-
if (values.length === 0 && Array.isArray(models["availableModels"])) {
|
|
35544
|
-
for (const model of models["availableModels"]) {
|
|
35545
|
-
if (!isRecord8(model)) {
|
|
35546
|
-
continue;
|
|
35547
|
-
}
|
|
35548
|
-
const value = readString2(model["modelId"]).slice(0, 500);
|
|
35549
|
-
if (value.length === 0) {
|
|
35550
|
-
continue;
|
|
35551
|
-
}
|
|
35552
|
-
if (!values.some((existing) => existing.value === value)) {
|
|
35553
|
-
values.push({
|
|
35554
|
-
description: "",
|
|
35555
|
-
groupId: "",
|
|
35556
|
-
groupName: "",
|
|
35557
|
-
name: readString2(model["name"], value).slice(0, 255),
|
|
35558
|
-
value
|
|
35559
|
-
});
|
|
35560
|
-
}
|
|
35561
|
-
}
|
|
35562
|
-
}
|
|
35563
|
-
const selected = options.find((option) => option["category"] === "model" && option["selected"] === true);
|
|
35564
|
-
const currentValue = readString2(
|
|
35565
|
-
models["currentModelId"],
|
|
35566
|
-
selected === void 0 ? "" : readString2(selected["id"])
|
|
35567
|
-
).slice(0, 500);
|
|
35568
|
-
if (values.length === 0 || !values.some((value) => value.value === currentValue)) {
|
|
35569
|
-
return [];
|
|
35570
|
-
}
|
|
35571
|
-
const result = {
|
|
35572
|
-
booleanValue: false,
|
|
35573
|
-
category: "model",
|
|
35574
|
-
currentValue,
|
|
35575
|
-
description: "Model used by Grok Build",
|
|
35576
|
-
id: LEGACY_MODEL_CONFIG_ID,
|
|
35577
|
-
name: "Model",
|
|
35578
|
-
type: "select",
|
|
35579
|
-
values: values.slice(0, 500)
|
|
35580
|
-
};
|
|
35581
|
-
return [result];
|
|
35582
|
-
}
|
|
35583
|
-
function legacyReasoningEffortOptions(response) {
|
|
35584
|
-
const options = legacyOptions(response);
|
|
35585
|
-
const values = [];
|
|
35586
|
-
for (const option of options) {
|
|
35587
|
-
if (option["category"] !== "mode") {
|
|
35588
|
-
continue;
|
|
35589
|
-
}
|
|
35590
|
-
const value = legacyValue(option);
|
|
35591
|
-
if (value.value.length > 0 && !values.some((existing) => existing.value === value.value)) {
|
|
35592
|
-
values.push(value);
|
|
35593
|
-
}
|
|
35594
|
-
}
|
|
35595
|
-
if (values.length === 0) {
|
|
35596
|
-
return [];
|
|
35597
|
-
}
|
|
35598
|
-
const selected = options.find((option) => option["category"] === "mode" && option["selected"] === true);
|
|
35599
|
-
if (selected === void 0) {
|
|
35600
|
-
values.unshift({
|
|
35601
|
-
description: "Use the selected model's default reasoning effort",
|
|
35602
|
-
groupId: "",
|
|
35603
|
-
groupName: "",
|
|
35604
|
-
name: "Agent default",
|
|
35605
|
-
value: AGENT_DEFAULT_REASONING_EFFORT
|
|
35606
|
-
});
|
|
35607
|
-
}
|
|
35608
|
-
const currentValue = selected === void 0 ? AGENT_DEFAULT_REASONING_EFFORT : readString2(selected["id"], AGENT_DEFAULT_REASONING_EFFORT);
|
|
35609
|
-
if (!values.some((value) => value.value === currentValue)) {
|
|
35610
|
-
return [];
|
|
35611
|
-
}
|
|
35612
|
-
const result = {
|
|
35613
|
-
booleanValue: false,
|
|
35614
|
-
category: "thought_level",
|
|
35615
|
-
currentValue,
|
|
35616
|
-
description: "Reasoning effort used by Grok Build",
|
|
35617
|
-
id: LEGACY_REASONING_EFFORT_CONFIG_ID,
|
|
35618
|
-
name: "Reasoning effort",
|
|
35619
|
-
type: "select",
|
|
35620
|
-
values: values.slice(0, 500)
|
|
35621
|
-
};
|
|
35622
|
-
return [result];
|
|
35623
|
-
}
|
|
35624
|
-
function normalizeGrokLifecycle(response) {
|
|
35625
|
-
const lifecycle = isRecord8(response) ? response : {};
|
|
35626
|
-
const standard = normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
|
|
35627
|
-
const normalized = [...standard];
|
|
35628
|
-
if (!normalized.some((option) => option.category === "model")) {
|
|
35629
|
-
normalized.push(...legacyModelOptions(response));
|
|
35630
|
-
}
|
|
35631
|
-
if (!normalized.some((option) => option.category === "thought_level")) {
|
|
35632
|
-
const efforts = legacyReasoningEffortOptions(response);
|
|
35633
|
-
if (efforts.length > 0) {
|
|
35634
|
-
const modelIndex = normalized.findIndex((option) => option.category === "model");
|
|
35635
|
-
normalized.splice(modelIndex < 0 ? normalized.length : modelIndex + 1, 0, ...efforts);
|
|
35636
|
-
}
|
|
35637
|
-
}
|
|
35638
|
-
return normalized.slice(0, 100);
|
|
35639
|
-
}
|
|
35640
|
-
function updateCurrentValue2(current, category, value) {
|
|
35641
|
-
return current.map((option) => option.category === category ? { ...option, currentValue: value } : option);
|
|
35642
|
-
}
|
|
35643
|
-
function validateGrokResponse(response, modelId) {
|
|
35644
|
-
if (!isRecord8(response) || !isRecord8(response["_meta"])) {
|
|
35645
|
-
throw new SessionConfigProtocolError("Grok Build returned an invalid session configuration response");
|
|
35646
|
-
}
|
|
35647
|
-
const model = response["_meta"]["model"];
|
|
35648
|
-
const appliedModel = isRecord8(model) ? model["Ok"] : model;
|
|
35649
|
-
if (appliedModel !== modelId) {
|
|
35650
|
-
throw new SessionConfigProtocolError("Grok Build returned an invalid session configuration response");
|
|
35651
|
-
}
|
|
35652
|
-
}
|
|
35653
|
-
var GrokBuildSessionConfigProtocol = class {
|
|
35654
|
-
configure = async (current, change, nativeSessionId, transport) => {
|
|
35655
|
-
const existing = current.find((option) => option.id === change.configId);
|
|
35656
|
-
if (existing === void 0 || existing.id !== LEGACY_MODEL_CONFIG_ID && existing.id !== LEGACY_REASONING_EFFORT_CONFIG_ID) {
|
|
35657
|
-
return await standardSessionConfigProtocol.configure(current, change, nativeSessionId, transport);
|
|
35658
|
-
}
|
|
35659
|
-
const model = current.find((option) => option.category === "model");
|
|
35660
|
-
if (model === void 0) {
|
|
35661
|
-
return current;
|
|
35662
|
-
}
|
|
35663
|
-
if (existing.category === "thought_level" && change.value === AGENT_DEFAULT_REASONING_EFFORT) {
|
|
35664
|
-
return current;
|
|
35665
|
-
}
|
|
35666
|
-
const modelId = existing.category === "model" ? change.value : model.currentValue;
|
|
35667
|
-
const params = {
|
|
35668
|
-
modelId,
|
|
35669
|
-
sessionId: nativeSessionId
|
|
35670
|
-
};
|
|
35671
|
-
if (existing.category === "thought_level") {
|
|
35672
|
-
params["_meta"] = {
|
|
35673
|
-
reasoningEffort: change.value
|
|
35674
|
-
};
|
|
35675
|
-
}
|
|
35676
|
-
const response = await transport.request(
|
|
35677
|
-
"session/set_model",
|
|
35678
|
-
params,
|
|
35679
|
-
existing.category === "model" ? "Grok Build exited while setting the session model" : "Grok Build exited while setting reasoning effort",
|
|
35680
|
-
change.signal
|
|
35681
|
-
);
|
|
35682
|
-
validateGrokResponse(response, modelId);
|
|
35683
|
-
const updated = updateCurrentValue2(current, existing.category, change.value);
|
|
35684
|
-
return existing.category === "thought_level" ? updated.map(
|
|
35685
|
-
(option) => option.category === "thought_level" ? {
|
|
35686
|
-
...option,
|
|
35687
|
-
values: option.values.filter((value) => value.value !== AGENT_DEFAULT_REASONING_EFFORT)
|
|
35688
|
-
} : option
|
|
35689
|
-
) : updated;
|
|
35690
|
-
};
|
|
35691
|
-
normalizeLifecycle = (response) => normalizeGrokLifecycle(response);
|
|
35692
|
-
normalizeUpdate = (current, value) => standardSessionConfigProtocol.normalizeUpdate(current, value);
|
|
35693
|
-
};
|
|
35694
|
-
var grokBuildSessionConfigProtocol = new GrokBuildSessionConfigProtocol();
|
|
35695
|
-
|
|
35696
35663
|
// src/acp/session-config/session-config-registry.ts
|
|
35697
|
-
function sessionConfigProtocolForAgent(
|
|
35698
|
-
return
|
|
35664
|
+
function sessionConfigProtocolForAgent(_agentId) {
|
|
35665
|
+
return standardSessionConfigProtocol;
|
|
35699
35666
|
}
|
|
35700
35667
|
|
|
35701
35668
|
// src/acp/session-history.ts
|
|
@@ -36306,7 +36273,7 @@ function createWritableAcpStream(output2) {
|
|
|
36306
36273
|
if (outputFailure !== void 0) {
|
|
36307
36274
|
return Promise.reject(outputFailure);
|
|
36308
36275
|
}
|
|
36309
|
-
return new Promise((
|
|
36276
|
+
return new Promise((resolve8, reject) => {
|
|
36310
36277
|
pendingWriteFailures.add(reject);
|
|
36311
36278
|
output2.write(chunk, (error62) => {
|
|
36312
36279
|
pendingWriteFailures.delete(reject);
|
|
@@ -36319,7 +36286,7 @@ function createWritableAcpStream(output2) {
|
|
|
36319
36286
|
reject(outputFailure);
|
|
36320
36287
|
return;
|
|
36321
36288
|
}
|
|
36322
|
-
|
|
36289
|
+
resolve8();
|
|
36323
36290
|
});
|
|
36324
36291
|
});
|
|
36325
36292
|
}
|
|
@@ -36736,12 +36703,12 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
36736
36703
|
stderr.on("data", (chunk) => {
|
|
36737
36704
|
process.stderr.write(`[${agent.id}-acp] ${chunk}`);
|
|
36738
36705
|
});
|
|
36739
|
-
this.#termination = new Promise((
|
|
36706
|
+
this.#termination = new Promise((resolve8) => {
|
|
36740
36707
|
child.once("error", (cause) => {
|
|
36741
|
-
|
|
36708
|
+
resolve8({ kind: "failed", error: new AcpExecutionError("The ACP process could not run", { cause }) });
|
|
36742
36709
|
});
|
|
36743
36710
|
child.once("exit", (code, signal) => {
|
|
36744
|
-
|
|
36711
|
+
resolve8({
|
|
36745
36712
|
kind: "failed",
|
|
36746
36713
|
error: new AcpExecutionError("The ACP process stopped", { cause: { code, signal } })
|
|
36747
36714
|
});
|
|
@@ -39859,7 +39826,7 @@ var LocalAuthorizationError = class extends Error {
|
|
|
39859
39826
|
};
|
|
39860
39827
|
|
|
39861
39828
|
// src/authorization/workspace-directory.ts
|
|
39862
|
-
import { readdir as
|
|
39829
|
+
import { readdir as readdir3, realpath as realpath9, stat as stat8 } from "node:fs/promises";
|
|
39863
39830
|
import { homedir as homedir2 } from "node:os";
|
|
39864
39831
|
import { basename as basename5, dirname as dirname6, isAbsolute as isAbsolute10, join as join16, normalize as normalize4, relative as relative4 } from "node:path";
|
|
39865
39832
|
var WorkspaceDirectoryListing = class {
|
|
@@ -39964,7 +39931,7 @@ var WorkspaceDirectoryService = class {
|
|
|
39964
39931
|
list = async (bindingId, id, signal) => {
|
|
39965
39932
|
const target = await this.resolve(bindingId, id, signal);
|
|
39966
39933
|
try {
|
|
39967
|
-
const children = await
|
|
39934
|
+
const children = await readdir3(target, { withFileTypes: true });
|
|
39968
39935
|
signal.throwIfAborted();
|
|
39969
39936
|
const entries = [];
|
|
39970
39937
|
for (const child of children) {
|
|
@@ -41213,7 +41180,7 @@ var RelayConnectionError = class extends Error {
|
|
|
41213
41180
|
};
|
|
41214
41181
|
function connectRelay(url2, signal) {
|
|
41215
41182
|
signal.throwIfAborted();
|
|
41216
|
-
return new Promise((
|
|
41183
|
+
return new Promise((resolve8, reject) => {
|
|
41217
41184
|
const endpoint = new URL(url2);
|
|
41218
41185
|
const headers = runtimeAuthorization(endpoint);
|
|
41219
41186
|
endpoint.searchParams.delete("token");
|
|
@@ -41280,7 +41247,7 @@ function connectRelay(url2, signal) {
|
|
|
41280
41247
|
}
|
|
41281
41248
|
finished = true;
|
|
41282
41249
|
cleanup();
|
|
41283
|
-
|
|
41250
|
+
resolve8(socket);
|
|
41284
41251
|
};
|
|
41285
41252
|
function onTimeout() {
|
|
41286
41253
|
fail(
|
|
@@ -41699,71 +41666,7 @@ var SessionEventOutbox = class {
|
|
|
41699
41666
|
received_at INTEGER NOT NULL
|
|
41700
41667
|
) STRICT;
|
|
41701
41668
|
`);
|
|
41702
|
-
const deadLetterTable = this.#database.prepare(
|
|
41703
|
-
`SELECT sql FROM sqlite_master
|
|
41704
|
-
WHERE type = 'table' AND name = 'relay_session_event_dead_letters'`
|
|
41705
|
-
).get();
|
|
41706
|
-
const deadLetterSql = typeof deadLetterTable === "object" && deadLetterTable !== null ? Reflect.get(deadLetterTable, "sql") : void 0;
|
|
41707
|
-
if (typeof deadLetterSql !== "string" || !deadLetterSql.includes("'session_rejected'")) {
|
|
41708
|
-
this.#database.exec(`
|
|
41709
|
-
BEGIN IMMEDIATE;
|
|
41710
|
-
ALTER TABLE relay_session_event_dead_letters
|
|
41711
|
-
RENAME TO relay_session_event_dead_letters_legacy;
|
|
41712
|
-
CREATE TABLE relay_session_event_dead_letters (
|
|
41713
|
-
ordinal INTEGER PRIMARY KEY,
|
|
41714
|
-
event_id TEXT NOT NULL UNIQUE,
|
|
41715
|
-
session_id TEXT NOT NULL,
|
|
41716
|
-
envelope_json TEXT NOT NULL,
|
|
41717
|
-
rejection_code TEXT NOT NULL CHECK (
|
|
41718
|
-
rejection_code IN ('session_deleted', 'session_not_found', 'session_rejected')
|
|
41719
|
-
)
|
|
41720
|
-
) STRICT;
|
|
41721
|
-
INSERT INTO relay_session_event_dead_letters (
|
|
41722
|
-
ordinal, event_id, session_id, envelope_json, rejection_code
|
|
41723
|
-
)
|
|
41724
|
-
SELECT ordinal, event_id, session_id, envelope_json, rejection_code
|
|
41725
|
-
FROM relay_session_event_dead_letters_legacy;
|
|
41726
|
-
DROP TABLE relay_session_event_dead_letters_legacy;
|
|
41727
|
-
COMMIT;
|
|
41728
|
-
`);
|
|
41729
|
-
}
|
|
41730
|
-
const outboxColumns = this.#database.prepare("PRAGMA table_info(relay_session_event_outbox)").all();
|
|
41731
|
-
const hasSourceKey = outboxColumns.some(
|
|
41732
|
-
(column) => typeof column === "object" && column !== null && Reflect.get(column, "name") === "source_key"
|
|
41733
|
-
);
|
|
41734
|
-
if (!hasSourceKey) {
|
|
41735
|
-
this.#database.exec(`
|
|
41736
|
-
ALTER TABLE relay_session_event_outbox
|
|
41737
|
-
ADD COLUMN source_key TEXT NOT NULL DEFAULT '';
|
|
41738
|
-
`);
|
|
41739
|
-
}
|
|
41740
|
-
const hasByteLength = outboxColumns.some(
|
|
41741
|
-
(column) => typeof column === "object" && column !== null && Reflect.get(column, "name") === "byte_length"
|
|
41742
|
-
);
|
|
41743
|
-
if (!hasByteLength) {
|
|
41744
|
-
this.#database.exec(`
|
|
41745
|
-
ALTER TABLE relay_session_event_outbox
|
|
41746
|
-
ADD COLUMN byte_length INTEGER NOT NULL DEFAULT 0;
|
|
41747
|
-
`);
|
|
41748
|
-
}
|
|
41749
41669
|
this.#database.exec(`
|
|
41750
|
-
UPDATE relay_session_event_outbox
|
|
41751
|
-
SET source_key = CASE json_extract(envelope_json, '$.source.kind')
|
|
41752
|
-
WHEN 'attempt' THEN
|
|
41753
|
-
'attempt:' || session_id || ':' || json_extract(envelope_json, '$.source.attemptId')
|
|
41754
|
-
ELSE 'runtime:' || session_id
|
|
41755
|
-
END
|
|
41756
|
-
WHERE source_key = '';
|
|
41757
|
-
UPDATE relay_session_event_outbox
|
|
41758
|
-
SET byte_length = length(CAST(envelope_json AS BLOB))
|
|
41759
|
-
WHERE byte_length = 0;
|
|
41760
|
-
UPDATE relay_session_event_outbox_state
|
|
41761
|
-
SET event_count = (SELECT COUNT(*) FROM relay_session_event_outbox),
|
|
41762
|
-
total_bytes = (
|
|
41763
|
-
SELECT COALESCE(SUM(byte_length), 0)
|
|
41764
|
-
FROM relay_session_event_outbox
|
|
41765
|
-
)
|
|
41766
|
-
WHERE singleton = 1;
|
|
41767
41670
|
CREATE INDEX IF NOT EXISTS relay_session_event_outbox_source_order
|
|
41768
41671
|
ON relay_session_event_outbox(source_key, ordinal);
|
|
41769
41672
|
`);
|
|
@@ -43823,12 +43726,12 @@ function waitForRelayRetry(signal, timer) {
|
|
|
43823
43726
|
if (signal.aborted) {
|
|
43824
43727
|
return Promise.resolve();
|
|
43825
43728
|
}
|
|
43826
|
-
return new Promise((
|
|
43729
|
+
return new Promise((resolve8) => {
|
|
43827
43730
|
const retry = timer.schedule(finish, RELAY_RECONNECT_DELAY_MILLISECONDS);
|
|
43828
43731
|
function finish() {
|
|
43829
43732
|
retry.cancel();
|
|
43830
43733
|
signal.removeEventListener("abort", finish);
|
|
43831
|
-
|
|
43734
|
+
resolve8();
|
|
43832
43735
|
}
|
|
43833
43736
|
signal.addEventListener("abort", finish, { once: true });
|
|
43834
43737
|
});
|
|
@@ -43924,7 +43827,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
43924
43827
|
installationObserver.connect(socket);
|
|
43925
43828
|
onConnected();
|
|
43926
43829
|
try {
|
|
43927
|
-
await new Promise((
|
|
43830
|
+
await new Promise((resolve8, reject) => {
|
|
43928
43831
|
let finished = false;
|
|
43929
43832
|
const cleanup = () => {
|
|
43930
43833
|
connectionLiveness.close();
|
|
@@ -43942,7 +43845,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
43942
43845
|
}
|
|
43943
43846
|
finished = true;
|
|
43944
43847
|
cleanup();
|
|
43945
|
-
|
|
43848
|
+
resolve8();
|
|
43946
43849
|
};
|
|
43947
43850
|
const rejectConnection = (failure2) => {
|
|
43948
43851
|
if (finished) {
|
|
@@ -44531,7 +44434,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
44531
44434
|
try {
|
|
44532
44435
|
operationSignal.throwIfAborted();
|
|
44533
44436
|
if (previous2.length > 0) {
|
|
44534
|
-
await new Promise((
|
|
44437
|
+
await new Promise((resolve9, reject2) => {
|
|
44535
44438
|
const cancel = () => reject2(operationSignal.reason);
|
|
44536
44439
|
operationSignal.addEventListener("abort", cancel, {
|
|
44537
44440
|
once: true
|
|
@@ -44539,7 +44442,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
44539
44442
|
void Promise.all(previous2.map((request) => request.completion)).then(
|
|
44540
44443
|
() => {
|
|
44541
44444
|
operationSignal.removeEventListener("abort", cancel);
|
|
44542
|
-
|
|
44445
|
+
resolve9();
|
|
44543
44446
|
},
|
|
44544
44447
|
(error62) => {
|
|
44545
44448
|
operationSignal.removeEventListener("abort", cancel);
|
|
@@ -44624,13 +44527,13 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
44624
44527
|
try {
|
|
44625
44528
|
operationSignal.throwIfAborted();
|
|
44626
44529
|
if (previous2.length > 0) {
|
|
44627
|
-
await new Promise((
|
|
44530
|
+
await new Promise((resolve9, reject2) => {
|
|
44628
44531
|
const cancel = () => reject2(operationSignal.reason);
|
|
44629
44532
|
operationSignal.addEventListener("abort", cancel, { once: true });
|
|
44630
44533
|
void Promise.all(previous2.map((request) => request.completion)).then(
|
|
44631
44534
|
() => {
|
|
44632
44535
|
operationSignal.removeEventListener("abort", cancel);
|
|
44633
|
-
|
|
44536
|
+
resolve9();
|
|
44634
44537
|
},
|
|
44635
44538
|
(error62) => {
|
|
44636
44539
|
operationSignal.removeEventListener("abort", cancel);
|
|
@@ -44975,7 +44878,11 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
44975
44878
|
);
|
|
44976
44879
|
};
|
|
44977
44880
|
const announceReadiness = () => {
|
|
44978
|
-
if (!connectionAnnounced || !catalogPublished
|
|
44881
|
+
if (!connectionAnnounced || !catalogPublished) {
|
|
44882
|
+
return;
|
|
44883
|
+
}
|
|
44884
|
+
options.onConnectionStatus?.("online");
|
|
44885
|
+
if (readinessAnnounced) {
|
|
44979
44886
|
return;
|
|
44980
44887
|
}
|
|
44981
44888
|
readinessAnnounced = true;
|
|
@@ -44986,14 +44893,16 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
44986
44893
|
return;
|
|
44987
44894
|
}
|
|
44988
44895
|
connectionAnnounced = true;
|
|
44989
|
-
const reconnectCommand = `npx --yes @moxt-ai/mobius start ${config2.reconnectTarget.commandArgument}`;
|
|
44990
44896
|
process.stdout.write("Mobius daemon connected to the relay.\n\n");
|
|
44991
|
-
|
|
44992
|
-
|
|
44897
|
+
if (config2.reconnectTarget !== null) {
|
|
44898
|
+
const reconnectCommand = `mobius start ${config2.reconnectTarget.commandArgument}`;
|
|
44899
|
+
process.stdout.write(
|
|
44900
|
+
`${styleText(["bold", "yellow"], `Reconnect this local connection later:
|
|
44993
44901
|
${reconnectCommand}`)}
|
|
44994
44902
|
|
|
44995
44903
|
`
|
|
44996
|
-
|
|
44904
|
+
);
|
|
44905
|
+
}
|
|
44997
44906
|
announceReadiness();
|
|
44998
44907
|
startAutomaticIntegrationProvisioning();
|
|
44999
44908
|
};
|
|
@@ -45024,7 +44933,12 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
45024
44933
|
activeAttemptIds,
|
|
45025
44934
|
connectionEpoch,
|
|
45026
44935
|
diagnostics,
|
|
45027
|
-
|
|
44936
|
+
() => {
|
|
44937
|
+
if (catalogPublished) {
|
|
44938
|
+
options.onConnectionStatus?.("online");
|
|
44939
|
+
}
|
|
44940
|
+
announceConnection();
|
|
44941
|
+
},
|
|
45028
44942
|
signal,
|
|
45029
44943
|
timer,
|
|
45030
44944
|
resolveAgentCatalogEnvironment
|
|
@@ -45038,6 +44952,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
45038
44952
|
}
|
|
45039
44953
|
diagnostics.connectionFailed(connectionEpoch, error62, "connection");
|
|
45040
44954
|
}
|
|
44955
|
+
options.onConnectionStatus?.("reconnecting");
|
|
45041
44956
|
await waitForRelayRetry(signal, timer);
|
|
45042
44957
|
}
|
|
45043
44958
|
} finally {
|
|
@@ -45124,6 +45039,7 @@ var MobiusRuntimeEngine = class {
|
|
|
45124
45039
|
const audit = new AuditStore(this.#config.auditDatabasePath);
|
|
45125
45040
|
try {
|
|
45126
45041
|
await runDaemon(this.#config, audit, signal, void 0, {
|
|
45042
|
+
...this.#options.onConnectionStatus === void 0 ? {} : { onConnectionStatus: this.#options.onConnectionStatus },
|
|
45127
45043
|
...this.#options.resolveAgentCatalogEnvironment === void 0 ? {} : { resolveAgentCatalogEnvironment: this.#options.resolveAgentCatalogEnvironment }
|
|
45128
45044
|
});
|
|
45129
45045
|
} finally {
|
|
@@ -45133,6 +45049,567 @@ var MobiusRuntimeEngine = class {
|
|
|
45133
45049
|
};
|
|
45134
45050
|
};
|
|
45135
45051
|
|
|
45052
|
+
// src/daemon-manager.ts
|
|
45053
|
+
var CONTROL_TIMEOUT_MILLISECONDS = 13e4;
|
|
45054
|
+
var START_TIMEOUT_MILLISECONDS = 12e4;
|
|
45055
|
+
var MAXIMUM_MESSAGE_BYTES = 64 * 1024;
|
|
45056
|
+
var CONNECTION_ID_PATTERN2 = /^mcn_[a-f0-9]{32}$/;
|
|
45057
|
+
async function acquireManagerLock(stateDirectory) {
|
|
45058
|
+
const path2 = join18(stateDirectory, "manager.lock");
|
|
45059
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
45060
|
+
try {
|
|
45061
|
+
await writeFile4(path2, `${process.pid.toString()}
|
|
45062
|
+
`, { flag: "wx", mode: 384 });
|
|
45063
|
+
return async () => await unlink2(path2).catch(() => void 0);
|
|
45064
|
+
} catch (cause) {
|
|
45065
|
+
if (!isNodeError2(cause, "EEXIST")) {
|
|
45066
|
+
throw cause;
|
|
45067
|
+
}
|
|
45068
|
+
const encoded = await readFile3(path2, "utf8").catch(() => "");
|
|
45069
|
+
const pid = Number(encoded.trim());
|
|
45070
|
+
if (Number.isSafeInteger(pid) && pid > 1) {
|
|
45071
|
+
try {
|
|
45072
|
+
process.kill(pid, 0);
|
|
45073
|
+
return null;
|
|
45074
|
+
} catch (probeCause) {
|
|
45075
|
+
if (!isNodeError2(probeCause, "ESRCH")) {
|
|
45076
|
+
return null;
|
|
45077
|
+
}
|
|
45078
|
+
}
|
|
45079
|
+
}
|
|
45080
|
+
await unlink2(path2).catch(() => void 0);
|
|
45081
|
+
}
|
|
45082
|
+
}
|
|
45083
|
+
return null;
|
|
45084
|
+
}
|
|
45085
|
+
function isRecord11(value) {
|
|
45086
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45087
|
+
}
|
|
45088
|
+
function controlSocketPath(stateDirectory) {
|
|
45089
|
+
const installationHash = createHash5("sha256").update(stateDirectory).digest("hex").slice(0, 32);
|
|
45090
|
+
return process.platform === "win32" ? `\\\\.\\pipe\\mobius-${installationHash}` : join18(tmpdir(), `mobius-${installationHash}.sock`);
|
|
45091
|
+
}
|
|
45092
|
+
function controlTokenPath(stateDirectory) {
|
|
45093
|
+
return join18(stateDirectory, "manager.token");
|
|
45094
|
+
}
|
|
45095
|
+
async function readOrCreateControlToken(stateDirectory) {
|
|
45096
|
+
const path2 = controlTokenPath(stateDirectory);
|
|
45097
|
+
try {
|
|
45098
|
+
return (await readFile3(path2, "utf8")).trim();
|
|
45099
|
+
} catch (cause) {
|
|
45100
|
+
if (!isNodeError2(cause, "ENOENT")) {
|
|
45101
|
+
throw cause;
|
|
45102
|
+
}
|
|
45103
|
+
}
|
|
45104
|
+
const token = randomBytes(32).toString("base64url");
|
|
45105
|
+
try {
|
|
45106
|
+
await writeFile4(path2, `${token}
|
|
45107
|
+
`, { flag: "wx", mode: 384 });
|
|
45108
|
+
return token;
|
|
45109
|
+
} catch (cause) {
|
|
45110
|
+
if (!isNodeError2(cause, "EEXIST")) {
|
|
45111
|
+
throw cause;
|
|
45112
|
+
}
|
|
45113
|
+
return (await readFile3(path2, "utf8")).trim();
|
|
45114
|
+
}
|
|
45115
|
+
}
|
|
45116
|
+
function isNodeError2(error62, code) {
|
|
45117
|
+
return typeof error62 === "object" && error62 !== null && "code" in error62 && error62.code === code;
|
|
45118
|
+
}
|
|
45119
|
+
function decodeCommand(value, expectedToken) {
|
|
45120
|
+
if (!isRecord11(value) || value["token"] !== expectedToken || typeof value["kind"] !== "string") {
|
|
45121
|
+
throw new Error("The manager request is invalid");
|
|
45122
|
+
}
|
|
45123
|
+
if (value["kind"] === "list" || value["kind"] === "stop") {
|
|
45124
|
+
return { kind: value["kind"] };
|
|
45125
|
+
}
|
|
45126
|
+
if ((value["kind"] === "remove-pair" || value["kind"] === "stop-pair") && typeof value["connectionId"] === "string" && CONNECTION_ID_PATTERN2.test(value["connectionId"])) {
|
|
45127
|
+
return { connectionId: value["connectionId"], kind: value["kind"] };
|
|
45128
|
+
}
|
|
45129
|
+
if (value["kind"] === "pair" || value["kind"] === "start") {
|
|
45130
|
+
const arguments_ = value["arguments"];
|
|
45131
|
+
if (!Array.isArray(arguments_) || arguments_.length > 16 || !arguments_.every((argument) => typeof argument === "string" && argument.length <= 4096)) {
|
|
45132
|
+
throw new Error("The manager command arguments are invalid");
|
|
45133
|
+
}
|
|
45134
|
+
return { arguments: arguments_, kind: value["kind"] };
|
|
45135
|
+
}
|
|
45136
|
+
throw new Error("The manager command is unsupported");
|
|
45137
|
+
}
|
|
45138
|
+
function decodeResponse(value) {
|
|
45139
|
+
if (!isRecord11(value) || typeof value["kind"] !== "string") {
|
|
45140
|
+
throw new Error("The Mobius manager returned an invalid response");
|
|
45141
|
+
}
|
|
45142
|
+
if (value["kind"] === "error" && typeof value["code"] === "string" && typeof value["message"] === "string") {
|
|
45143
|
+
return { code: value["code"], kind: "error", message: value["message"] };
|
|
45144
|
+
}
|
|
45145
|
+
if (value["kind"] === "stopped") {
|
|
45146
|
+
return { kind: "stopped" };
|
|
45147
|
+
}
|
|
45148
|
+
if (value["kind"] === "pair-stopped" && isManagedRuntimeSummary(value["pair"])) {
|
|
45149
|
+
return { kind: "pair-stopped", pair: value["pair"] };
|
|
45150
|
+
}
|
|
45151
|
+
if (value["kind"] === "pair-removed" && typeof value["connectionId"] === "string") {
|
|
45152
|
+
return { connectionId: value["connectionId"], kind: "pair-removed" };
|
|
45153
|
+
}
|
|
45154
|
+
if (value["kind"] === "ready" && typeof value["alreadyOnline"] === "boolean" && isManagedRuntimeSummary(value["pair"])) {
|
|
45155
|
+
return { alreadyOnline: value["alreadyOnline"], kind: "ready", pair: value["pair"] };
|
|
45156
|
+
}
|
|
45157
|
+
if (value["kind"] === "listed" && Array.isArray(value["pairs"]) && value["pairs"].every(isManagedRuntimeSummary)) {
|
|
45158
|
+
const managerVersion = value["managerVersion"];
|
|
45159
|
+
if (managerVersion === void 0) {
|
|
45160
|
+
return { kind: "legacy-listed", pairs: value["pairs"] };
|
|
45161
|
+
}
|
|
45162
|
+
if (typeof managerVersion === "string" && managerVersion.length > 0 && managerVersion.length <= 128) {
|
|
45163
|
+
return { kind: "listed", managerVersion, pairs: value["pairs"] };
|
|
45164
|
+
}
|
|
45165
|
+
}
|
|
45166
|
+
throw new Error("The Mobius manager returned an invalid response");
|
|
45167
|
+
}
|
|
45168
|
+
function isManagedRuntimeSummary(value) {
|
|
45169
|
+
return isRecord11(value) && typeof value["appId"] === "string" && typeof value["connectionId"] === "string" && typeof value["runtimeId"] === "string" && typeof value["workspace"] === "string" && ["starting", "online", "reconnecting", "failed", "stopped"].includes(String(value["status"]));
|
|
45170
|
+
}
|
|
45171
|
+
function summary(connection, status) {
|
|
45172
|
+
return {
|
|
45173
|
+
appId: connection.appId,
|
|
45174
|
+
connectionId: connection.connectionId,
|
|
45175
|
+
runtimeId: connection instanceof VerifiedRuntimeConnection ? connection.runtimeId : "unknown",
|
|
45176
|
+
status,
|
|
45177
|
+
workspace: connection.defaultWorkspace
|
|
45178
|
+
};
|
|
45179
|
+
}
|
|
45180
|
+
var RuntimeSupervisor = class {
|
|
45181
|
+
#failed = /* @__PURE__ */ new Map();
|
|
45182
|
+
#installation;
|
|
45183
|
+
#pairingRequests = /* @__PURE__ */ new Map();
|
|
45184
|
+
#restoring = /* @__PURE__ */ new Map();
|
|
45185
|
+
#runtimes = /* @__PURE__ */ new Map();
|
|
45186
|
+
#stopped = /* @__PURE__ */ new Map();
|
|
45187
|
+
constructor(installation) {
|
|
45188
|
+
this.#installation = installation;
|
|
45189
|
+
}
|
|
45190
|
+
restore = async (signal) => {
|
|
45191
|
+
const connections = await this.#installation.listConnections(signal);
|
|
45192
|
+
for (const connection of connections) {
|
|
45193
|
+
if (connection.activation === "stopped") {
|
|
45194
|
+
this.#stopped.set(connection.connectionId, connection);
|
|
45195
|
+
} else {
|
|
45196
|
+
this.#restoring.set(connection.connectionId, connection);
|
|
45197
|
+
}
|
|
45198
|
+
}
|
|
45199
|
+
await Promise.all(
|
|
45200
|
+
connections.filter((connection) => connection.activation === "active").map(async (connection) => {
|
|
45201
|
+
try {
|
|
45202
|
+
const paired = await resumeLocalMachine(["--connection", connection.connectionId], signal);
|
|
45203
|
+
this.#activate(connection, paired);
|
|
45204
|
+
} catch (cause) {
|
|
45205
|
+
this.#restoring.delete(connection.connectionId);
|
|
45206
|
+
this.#failed.set(connection.connectionId, connection);
|
|
45207
|
+
process.stderr.write(`Could not restore ${connection.connectionId}: ${errorMessage2(cause)}
|
|
45208
|
+
`);
|
|
45209
|
+
}
|
|
45210
|
+
})
|
|
45211
|
+
);
|
|
45212
|
+
};
|
|
45213
|
+
pair = async (arguments_, signal) => {
|
|
45214
|
+
const pairingId = pairingIdentifier(arguments_);
|
|
45215
|
+
if (pairingId === null) {
|
|
45216
|
+
return await this.#pair(arguments_, signal);
|
|
45217
|
+
}
|
|
45218
|
+
const pending = this.#pairingRequests.get(pairingId);
|
|
45219
|
+
if (pending !== void 0) {
|
|
45220
|
+
return await pending;
|
|
45221
|
+
}
|
|
45222
|
+
const request = this.#pair(arguments_, signal);
|
|
45223
|
+
this.#pairingRequests.set(pairingId, request);
|
|
45224
|
+
try {
|
|
45225
|
+
return await request;
|
|
45226
|
+
} finally {
|
|
45227
|
+
if (this.#pairingRequests.get(pairingId) === request) {
|
|
45228
|
+
this.#pairingRequests.delete(pairingId);
|
|
45229
|
+
}
|
|
45230
|
+
}
|
|
45231
|
+
};
|
|
45232
|
+
#pair = async (arguments_, signal) => {
|
|
45233
|
+
const paired = await pairLocalMachine(arguments_, signal);
|
|
45234
|
+
const connection = await this.#installation.setConnectionActivation(paired.connectionId, "active", signal);
|
|
45235
|
+
const alreadyOnline = this.#runtimes.get(connection.connectionId)?.status === "online";
|
|
45236
|
+
const active = this.#activate(connection, paired);
|
|
45237
|
+
await waitForReady(active, signal);
|
|
45238
|
+
return { alreadyOnline, pair: summary(connection, active.status) };
|
|
45239
|
+
};
|
|
45240
|
+
start = async (arguments_, signal) => {
|
|
45241
|
+
const paired = await resumeLocalMachine(arguments_, signal);
|
|
45242
|
+
const connection = await this.#installation.setConnectionActivation(paired.connectionId, "active", signal);
|
|
45243
|
+
const active = this.#activate(connection, paired);
|
|
45244
|
+
await waitForReady(active, signal);
|
|
45245
|
+
return summary(connection, active.status);
|
|
45246
|
+
};
|
|
45247
|
+
stop = async (connectionId2, signal) => {
|
|
45248
|
+
let connection = await this.#installation.readConnection(connectionId2, signal);
|
|
45249
|
+
const active = this.#runtimes.get(connection.connectionId);
|
|
45250
|
+
if (active !== void 0) {
|
|
45251
|
+
active.controller.abort();
|
|
45252
|
+
await active.completion;
|
|
45253
|
+
this.#runtimes.delete(connection.connectionId);
|
|
45254
|
+
}
|
|
45255
|
+
connection = await this.#installation.setConnectionActivation(connection.connectionId, "stopped", signal);
|
|
45256
|
+
this.#failed.delete(connection.connectionId);
|
|
45257
|
+
this.#stopped.set(connection.connectionId, connection);
|
|
45258
|
+
return summary(connection, "stopped");
|
|
45259
|
+
};
|
|
45260
|
+
remove = async (connectionId2, signal) => {
|
|
45261
|
+
const stopped = await this.stop(connectionId2, signal);
|
|
45262
|
+
await this.#installation.removeConnection(stopped.connectionId, signal);
|
|
45263
|
+
this.#stopped.delete(stopped.connectionId);
|
|
45264
|
+
return stopped.connectionId;
|
|
45265
|
+
};
|
|
45266
|
+
list = () => [
|
|
45267
|
+
...[...this.#runtimes.values()].map((active) => summary(active.connection, active.status)),
|
|
45268
|
+
...[...this.#restoring.values()].map((connection) => summary(connection, "starting")),
|
|
45269
|
+
...[...this.#failed.values()].map((connection) => summary(connection, "failed")),
|
|
45270
|
+
...[...this.#stopped.values()].map((connection) => summary(connection, "stopped"))
|
|
45271
|
+
].sort(
|
|
45272
|
+
(left, right) => left.appId.localeCompare(right.appId) || left.connectionId.localeCompare(right.connectionId)
|
|
45273
|
+
);
|
|
45274
|
+
close = async () => {
|
|
45275
|
+
const runtimes = [...this.#runtimes.values()];
|
|
45276
|
+
for (const runtime of runtimes) {
|
|
45277
|
+
runtime.controller.abort();
|
|
45278
|
+
}
|
|
45279
|
+
await Promise.all(runtimes.map(async (runtime) => await runtime.completion));
|
|
45280
|
+
};
|
|
45281
|
+
#activate(connection, paired) {
|
|
45282
|
+
const existing = this.#runtimes.get(connection.connectionId);
|
|
45283
|
+
if (existing !== void 0) {
|
|
45284
|
+
return existing;
|
|
45285
|
+
}
|
|
45286
|
+
const controller = new AbortController();
|
|
45287
|
+
const readiness = Promise.withResolvers();
|
|
45288
|
+
const completion = Promise.withResolvers();
|
|
45289
|
+
const active = {
|
|
45290
|
+
connection,
|
|
45291
|
+
controller,
|
|
45292
|
+
completion: completion.promise,
|
|
45293
|
+
ready: readiness.promise,
|
|
45294
|
+
resolveReady: readiness.resolve,
|
|
45295
|
+
status: "starting"
|
|
45296
|
+
};
|
|
45297
|
+
const engine = new MobiusRuntimeEngine(paired.config, {
|
|
45298
|
+
onConnectionStatus: (status) => {
|
|
45299
|
+
active.status = status;
|
|
45300
|
+
if (status === "online") {
|
|
45301
|
+
active.resolveReady();
|
|
45302
|
+
}
|
|
45303
|
+
}
|
|
45304
|
+
});
|
|
45305
|
+
void engine.run(controller.signal).catch((cause) => {
|
|
45306
|
+
if (!controller.signal.aborted) {
|
|
45307
|
+
active.status = "failed";
|
|
45308
|
+
this.#runtimes.delete(connection.connectionId);
|
|
45309
|
+
this.#failed.set(connection.connectionId, connection);
|
|
45310
|
+
active.resolveReady();
|
|
45311
|
+
process.stderr.write(`Runtime ${connection.connectionId} failed: ${errorMessage2(cause)}
|
|
45312
|
+
`);
|
|
45313
|
+
}
|
|
45314
|
+
}).finally(completion.resolve);
|
|
45315
|
+
this.#runtimes.set(connection.connectionId, active);
|
|
45316
|
+
this.#restoring.delete(connection.connectionId);
|
|
45317
|
+
this.#failed.delete(connection.connectionId);
|
|
45318
|
+
this.#stopped.delete(connection.connectionId);
|
|
45319
|
+
return active;
|
|
45320
|
+
}
|
|
45321
|
+
};
|
|
45322
|
+
function pairingIdentifier(arguments_) {
|
|
45323
|
+
const indexes = arguments_.flatMap((argument, index3) => argument === "--pairing" ? [index3] : []);
|
|
45324
|
+
if (indexes.length !== 1) {
|
|
45325
|
+
return null;
|
|
45326
|
+
}
|
|
45327
|
+
const index2 = indexes[0];
|
|
45328
|
+
return index2 === void 0 ? null : arguments_[index2 + 1] ?? null;
|
|
45329
|
+
}
|
|
45330
|
+
async function waitForReady(active, signal) {
|
|
45331
|
+
if (active.status === "online") {
|
|
45332
|
+
return;
|
|
45333
|
+
}
|
|
45334
|
+
const deadline = AbortSignal.any([signal, AbortSignal.timeout(START_TIMEOUT_MILLISECONDS)]);
|
|
45335
|
+
await new Promise((resolve8, reject) => {
|
|
45336
|
+
const abort = () => reject(deadline.reason);
|
|
45337
|
+
active.ready.then(resolve8, reject).finally(() => deadline.removeEventListener("abort", abort));
|
|
45338
|
+
deadline.addEventListener("abort", abort, { once: true });
|
|
45339
|
+
});
|
|
45340
|
+
if (active.status === "failed") {
|
|
45341
|
+
throw new Error("The Runtime failed before connecting");
|
|
45342
|
+
}
|
|
45343
|
+
}
|
|
45344
|
+
function errorMessage2(error62) {
|
|
45345
|
+
return error62 instanceof Error ? error62.message : "Unknown failure";
|
|
45346
|
+
}
|
|
45347
|
+
async function readSocketMessage(socket, signal) {
|
|
45348
|
+
return await new Promise((resolve8, reject) => {
|
|
45349
|
+
let encoded = "";
|
|
45350
|
+
const finish = (error62, value) => {
|
|
45351
|
+
signal.removeEventListener("abort", abort);
|
|
45352
|
+
socket.removeAllListeners("data");
|
|
45353
|
+
socket.removeAllListeners("error");
|
|
45354
|
+
socket.removeAllListeners("end");
|
|
45355
|
+
if (error62 === void 0) {
|
|
45356
|
+
resolve8(value);
|
|
45357
|
+
} else {
|
|
45358
|
+
reject(error62);
|
|
45359
|
+
}
|
|
45360
|
+
};
|
|
45361
|
+
const abort = () => {
|
|
45362
|
+
socket.destroy();
|
|
45363
|
+
finish(signal.reason);
|
|
45364
|
+
};
|
|
45365
|
+
socket.on("data", (chunk) => {
|
|
45366
|
+
encoded += chunk.toString("utf8");
|
|
45367
|
+
if (encoded.length > MAXIMUM_MESSAGE_BYTES) {
|
|
45368
|
+
finish(new Error("The manager message is too large"));
|
|
45369
|
+
socket.destroy();
|
|
45370
|
+
return;
|
|
45371
|
+
}
|
|
45372
|
+
const newline = encoded.indexOf("\n");
|
|
45373
|
+
if (newline >= 0) {
|
|
45374
|
+
try {
|
|
45375
|
+
finish(void 0, JSON.parse(encoded.slice(0, newline)));
|
|
45376
|
+
} catch (cause) {
|
|
45377
|
+
finish(cause);
|
|
45378
|
+
}
|
|
45379
|
+
}
|
|
45380
|
+
});
|
|
45381
|
+
socket.once("error", finish);
|
|
45382
|
+
socket.once("end", () => finish(new Error("The manager connection closed without a response")));
|
|
45383
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
45384
|
+
});
|
|
45385
|
+
}
|
|
45386
|
+
async function sendControlRequest(stateDirectory, command, signal) {
|
|
45387
|
+
const token = await readOrCreateControlToken(stateDirectory);
|
|
45388
|
+
const deadline = AbortSignal.any([signal, AbortSignal.timeout(CONTROL_TIMEOUT_MILLISECONDS)]);
|
|
45389
|
+
const socket = createConnection(controlSocketPath(stateDirectory));
|
|
45390
|
+
try {
|
|
45391
|
+
await new Promise((resolve8, reject) => {
|
|
45392
|
+
const abort = () => {
|
|
45393
|
+
socket.destroy();
|
|
45394
|
+
reject(deadline.reason);
|
|
45395
|
+
};
|
|
45396
|
+
socket.once("connect", () => {
|
|
45397
|
+
deadline.removeEventListener("abort", abort);
|
|
45398
|
+
resolve8();
|
|
45399
|
+
});
|
|
45400
|
+
socket.once("error", reject);
|
|
45401
|
+
deadline.addEventListener("abort", abort, { once: true });
|
|
45402
|
+
});
|
|
45403
|
+
socket.write(`${JSON.stringify({ ...command, token })}
|
|
45404
|
+
`);
|
|
45405
|
+
return decodeResponse(await readSocketMessage(socket, deadline));
|
|
45406
|
+
} finally {
|
|
45407
|
+
socket.destroy();
|
|
45408
|
+
}
|
|
45409
|
+
}
|
|
45410
|
+
async function spawnManager(stateDirectory) {
|
|
45411
|
+
const log = await open6(join18(stateDirectory, "manager.log"), "a", 384);
|
|
45412
|
+
try {
|
|
45413
|
+
const child = spawn6(process.execPath, [process.argv[1] ?? "", "__manager"], {
|
|
45414
|
+
detached: true,
|
|
45415
|
+
env: process.env,
|
|
45416
|
+
stdio: ["ignore", log.fd, log.fd]
|
|
45417
|
+
});
|
|
45418
|
+
child.unref();
|
|
45419
|
+
return child;
|
|
45420
|
+
} finally {
|
|
45421
|
+
await log.close();
|
|
45422
|
+
}
|
|
45423
|
+
}
|
|
45424
|
+
async function launchManager(stateDirectory, managerVersion) {
|
|
45425
|
+
process.stdout.write(`Starting mobius daemon ${managerVersion}
|
|
45426
|
+
`);
|
|
45427
|
+
await spawnManager(stateDirectory);
|
|
45428
|
+
}
|
|
45429
|
+
async function waitForManagerExit(stateDirectory, signal) {
|
|
45430
|
+
const deadline = AbortSignal.any([signal, AbortSignal.timeout(1e4)]);
|
|
45431
|
+
while (!deadline.aborted) {
|
|
45432
|
+
try {
|
|
45433
|
+
await sendControlRequest(stateDirectory, { kind: "list" }, AbortSignal.timeout(200));
|
|
45434
|
+
} catch (cause) {
|
|
45435
|
+
if (isNodeError2(cause, "ENOENT") || isNodeError2(cause, "ECONNREFUSED")) {
|
|
45436
|
+
return;
|
|
45437
|
+
}
|
|
45438
|
+
}
|
|
45439
|
+
await new Promise((resolve8, reject) => {
|
|
45440
|
+
const timeout = setTimeout(resolve8, 20);
|
|
45441
|
+
deadline.addEventListener(
|
|
45442
|
+
"abort",
|
|
45443
|
+
() => {
|
|
45444
|
+
clearTimeout(timeout);
|
|
45445
|
+
reject(deadline.reason);
|
|
45446
|
+
},
|
|
45447
|
+
{ once: true }
|
|
45448
|
+
);
|
|
45449
|
+
});
|
|
45450
|
+
}
|
|
45451
|
+
throw deadline.reason;
|
|
45452
|
+
}
|
|
45453
|
+
async function requestManager(installation, managerVersion, command, signal) {
|
|
45454
|
+
if (managerVersion.length === 0 || managerVersion.length > 128) {
|
|
45455
|
+
throw new Error("The Mobius manager version is invalid");
|
|
45456
|
+
}
|
|
45457
|
+
const deadline = AbortSignal.any([signal, AbortSignal.timeout(CONTROL_TIMEOUT_MILLISECONDS)]);
|
|
45458
|
+
if (command.kind === "stop") {
|
|
45459
|
+
return await stopManager(installation.stateDirectory, deadline);
|
|
45460
|
+
}
|
|
45461
|
+
const listed = await ensureMatchingManager(installation.stateDirectory, managerVersion, deadline);
|
|
45462
|
+
if (command.kind === "list") {
|
|
45463
|
+
return listed;
|
|
45464
|
+
}
|
|
45465
|
+
const response = await sendControlRequest(installation.stateDirectory, command, deadline);
|
|
45466
|
+
if (response.kind === "legacy-listed") {
|
|
45467
|
+
throw new Error("The Mobius manager returned an unexpected response");
|
|
45468
|
+
}
|
|
45469
|
+
return response;
|
|
45470
|
+
}
|
|
45471
|
+
async function ensureMatchingManager(stateDirectory, managerVersion, signal) {
|
|
45472
|
+
let managerStarted = false;
|
|
45473
|
+
while (!signal.aborted) {
|
|
45474
|
+
try {
|
|
45475
|
+
const response = await sendControlRequest(stateDirectory, { kind: "list" }, signal);
|
|
45476
|
+
if (response.kind === "listed" && response.managerVersion === managerVersion) {
|
|
45477
|
+
if (managerStarted) {
|
|
45478
|
+
process.stdout.write(`Mobius daemon ${managerVersion} started
|
|
45479
|
+
`);
|
|
45480
|
+
}
|
|
45481
|
+
return response;
|
|
45482
|
+
}
|
|
45483
|
+
if (response.kind !== "listed" && response.kind !== "legacy-listed") {
|
|
45484
|
+
if (response.kind === "error") {
|
|
45485
|
+
throw new Error(response.message);
|
|
45486
|
+
}
|
|
45487
|
+
throw new Error("The Mobius manager returned an unexpected response");
|
|
45488
|
+
}
|
|
45489
|
+
await stopManager(stateDirectory, signal);
|
|
45490
|
+
await launchManager(stateDirectory, managerVersion);
|
|
45491
|
+
managerStarted = true;
|
|
45492
|
+
} catch (cause) {
|
|
45493
|
+
if (!isNodeError2(cause, "ENOENT") && !isNodeError2(cause, "ECONNREFUSED")) {
|
|
45494
|
+
throw cause;
|
|
45495
|
+
}
|
|
45496
|
+
if (!managerStarted) {
|
|
45497
|
+
await launchManager(stateDirectory, managerVersion);
|
|
45498
|
+
managerStarted = true;
|
|
45499
|
+
}
|
|
45500
|
+
await new Promise((resolve8, reject) => {
|
|
45501
|
+
const timeout = setTimeout(finish, 50);
|
|
45502
|
+
const abort = () => finish(signal.reason);
|
|
45503
|
+
function finish(cause2) {
|
|
45504
|
+
clearTimeout(timeout);
|
|
45505
|
+
signal.removeEventListener("abort", abort);
|
|
45506
|
+
cause2 === void 0 ? resolve8() : reject(cause2);
|
|
45507
|
+
}
|
|
45508
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
45509
|
+
});
|
|
45510
|
+
}
|
|
45511
|
+
}
|
|
45512
|
+
throw signal.reason;
|
|
45513
|
+
}
|
|
45514
|
+
async function stopManager(stateDirectory, signal) {
|
|
45515
|
+
try {
|
|
45516
|
+
const response = await sendControlRequest(stateDirectory, { kind: "stop" }, signal);
|
|
45517
|
+
if (response.kind === "error") {
|
|
45518
|
+
throw new Error(response.message);
|
|
45519
|
+
}
|
|
45520
|
+
if (response.kind !== "stopped") {
|
|
45521
|
+
throw new Error("The Mobius manager returned an unexpected response");
|
|
45522
|
+
}
|
|
45523
|
+
await waitForManagerExit(stateDirectory, signal);
|
|
45524
|
+
return response;
|
|
45525
|
+
} catch (cause) {
|
|
45526
|
+
if (isNodeError2(cause, "ENOENT") || isNodeError2(cause, "ECONNREFUSED")) {
|
|
45527
|
+
return { kind: "stopped" };
|
|
45528
|
+
}
|
|
45529
|
+
throw cause;
|
|
45530
|
+
}
|
|
45531
|
+
}
|
|
45532
|
+
async function runManager(installation, managerVersion, signal) {
|
|
45533
|
+
const releaseLock = await acquireManagerLock(installation.stateDirectory);
|
|
45534
|
+
if (releaseLock === null) {
|
|
45535
|
+
return;
|
|
45536
|
+
}
|
|
45537
|
+
const token = await readOrCreateControlToken(installation.stateDirectory);
|
|
45538
|
+
const socketPath = controlSocketPath(installation.stateDirectory);
|
|
45539
|
+
const shutdown2 = new AbortController();
|
|
45540
|
+
const combined = AbortSignal.any([signal, shutdown2.signal]);
|
|
45541
|
+
const supervisor = new RuntimeSupervisor(installation);
|
|
45542
|
+
try {
|
|
45543
|
+
await supervisor.restore(combined);
|
|
45544
|
+
} catch (cause) {
|
|
45545
|
+
combined.throwIfAborted();
|
|
45546
|
+
process.stderr.write(`Could not restore saved Runtime connections: ${errorMessage2(cause)}
|
|
45547
|
+
`);
|
|
45548
|
+
}
|
|
45549
|
+
const server = createServer((socket) => {
|
|
45550
|
+
void (async () => {
|
|
45551
|
+
try {
|
|
45552
|
+
const request = decodeCommand(await readSocketMessage(socket, combined), token);
|
|
45553
|
+
let response;
|
|
45554
|
+
if (request.kind === "list") {
|
|
45555
|
+
response = { kind: "listed", managerVersion, pairs: supervisor.list() };
|
|
45556
|
+
} else if (request.kind === "pair") {
|
|
45557
|
+
const paired = await supervisor.pair(request.arguments, combined);
|
|
45558
|
+
response = { alreadyOnline: paired.alreadyOnline, kind: "ready", pair: paired.pair };
|
|
45559
|
+
} else if (request.kind === "start") {
|
|
45560
|
+
response = {
|
|
45561
|
+
alreadyOnline: false,
|
|
45562
|
+
kind: "ready",
|
|
45563
|
+
pair: await supervisor.start(request.arguments, combined)
|
|
45564
|
+
};
|
|
45565
|
+
} else if (request.kind === "stop-pair") {
|
|
45566
|
+
response = { kind: "pair-stopped", pair: await supervisor.stop(request.connectionId, combined) };
|
|
45567
|
+
} else if (request.kind === "remove-pair") {
|
|
45568
|
+
response = {
|
|
45569
|
+
connectionId: await supervisor.remove(request.connectionId, combined),
|
|
45570
|
+
kind: "pair-removed"
|
|
45571
|
+
};
|
|
45572
|
+
} else {
|
|
45573
|
+
response = { kind: "stopped" };
|
|
45574
|
+
shutdown2.abort();
|
|
45575
|
+
}
|
|
45576
|
+
socket.end(`${JSON.stringify(response)}
|
|
45577
|
+
`);
|
|
45578
|
+
} catch (cause) {
|
|
45579
|
+
socket.end(
|
|
45580
|
+
`${JSON.stringify({ kind: "error", code: "manager_command_failed", message: errorMessage2(cause) })}
|
|
45581
|
+
`
|
|
45582
|
+
);
|
|
45583
|
+
}
|
|
45584
|
+
})();
|
|
45585
|
+
});
|
|
45586
|
+
if (process.platform !== "win32") {
|
|
45587
|
+
await unlink2(socketPath).catch((cause) => {
|
|
45588
|
+
if (!isNodeError2(cause, "ENOENT")) {
|
|
45589
|
+
throw cause;
|
|
45590
|
+
}
|
|
45591
|
+
});
|
|
45592
|
+
}
|
|
45593
|
+
server.listen(socketPath);
|
|
45594
|
+
await new Promise((resolve8, reject) => {
|
|
45595
|
+
server.once("listening", resolve8);
|
|
45596
|
+
server.once("error", reject);
|
|
45597
|
+
});
|
|
45598
|
+
if (process.platform !== "win32") {
|
|
45599
|
+
await import("node:fs/promises").then(async ({ chmod: chmod2 }) => await chmod2(socketPath, 384));
|
|
45600
|
+
}
|
|
45601
|
+
try {
|
|
45602
|
+
await new Promise((resolve8) => combined.addEventListener("abort", () => resolve8(), { once: true }));
|
|
45603
|
+
await new Promise((resolve8) => server.close(() => resolve8()));
|
|
45604
|
+
await supervisor.close();
|
|
45605
|
+
} finally {
|
|
45606
|
+
if (process.platform !== "win32") {
|
|
45607
|
+
await unlink2(socketPath).catch(() => void 0);
|
|
45608
|
+
}
|
|
45609
|
+
await releaseLock();
|
|
45610
|
+
}
|
|
45611
|
+
}
|
|
45612
|
+
|
|
45136
45613
|
// src/cli.ts
|
|
45137
45614
|
var shutdown = new AbortController();
|
|
45138
45615
|
process.once("SIGINT", () => shutdown.abort());
|
|
@@ -45141,20 +45618,78 @@ var USAGE = `Mobius CLI
|
|
|
45141
45618
|
|
|
45142
45619
|
Usage:
|
|
45143
45620
|
mobius --version
|
|
45144
|
-
mobius pair --url <relay-url> --pairing <runtime-pairing-id> --code <pairing-code> [--workspace <directory>]
|
|
45621
|
+
mobius pair --url <relay-url> --pairing <runtime-pairing-id> --code <pairing-code> [--app-id <app-id>] [--workspace <directory>]
|
|
45622
|
+
mobius pair list [--output-json=<existing-file.json>]
|
|
45623
|
+
mobius pair stop --connection <connection-id>
|
|
45624
|
+
mobius pair remove --connection <connection-id>
|
|
45145
45625
|
mobius start --connection <connection-id>
|
|
45146
|
-
mobius
|
|
45626
|
+
mobius quit
|
|
45147
45627
|
mobius agents [--json]
|
|
45148
45628
|
|
|
45149
45629
|
Commands:
|
|
45150
45630
|
--version Print the installed Mobius CLI version
|
|
45151
|
-
pair Pair this machine and
|
|
45152
|
-
start Start the
|
|
45631
|
+
pair Pair this machine or list, stop, and remove managed pairings
|
|
45632
|
+
start Start the manager and activate a saved connection
|
|
45633
|
+
quit Stop the manager and every active Runtime
|
|
45153
45634
|
agents Show detected, missing, and integration-ready Agents
|
|
45154
45635
|
|
|
45155
45636
|
Pairing grants this browser access to the machine with your user account's permissions.
|
|
45156
45637
|
New conversations default to this Mobius installation's private workspace; choose other directories in the browser.
|
|
45157
45638
|
`;
|
|
45639
|
+
function formatPairTable(pairs) {
|
|
45640
|
+
const headers = ["connection_id", "app_id", "runtime_id", "workspace", "status"];
|
|
45641
|
+
const rows = pairs.map((pair) => [pair.connectionId, pair.appId, pair.runtimeId, pair.workspace, pair.status]);
|
|
45642
|
+
const widths = headers.map(
|
|
45643
|
+
(header, index2) => Math.max(header.length, ...rows.map((row) => row[index2]?.length ?? 0))
|
|
45644
|
+
);
|
|
45645
|
+
const line = (row) => `| ${row.map((value, index2) => value.padEnd(widths[index2] ?? value.length)).join(" | ")} |`;
|
|
45646
|
+
const divider = `|-${widths.map((width) => "-".repeat(width)).join("-|-")}-|`;
|
|
45647
|
+
return `${line(headers)}
|
|
45648
|
+
${divider}
|
|
45649
|
+
${rows.map(line).join("\n")}${rows.length === 0 ? "" : "\n"}`;
|
|
45650
|
+
}
|
|
45651
|
+
function pairListOutputPath(arguments_) {
|
|
45652
|
+
if (arguments_.length === 0) {
|
|
45653
|
+
return null;
|
|
45654
|
+
}
|
|
45655
|
+
const prefix = "--output-json=";
|
|
45656
|
+
const option = arguments_.length === 1 ? arguments_[0] : void 0;
|
|
45657
|
+
if (option === void 0 || !option.startsWith(prefix) || option.length === prefix.length) {
|
|
45658
|
+
throw new Error("Usage: mobius pair list [--output-json=<existing-file.json>]");
|
|
45659
|
+
}
|
|
45660
|
+
return resolve7(option.slice(prefix.length));
|
|
45661
|
+
}
|
|
45662
|
+
async function writePairList(path2, pairs) {
|
|
45663
|
+
shutdown.signal.throwIfAborted();
|
|
45664
|
+
let file2;
|
|
45665
|
+
try {
|
|
45666
|
+
file2 = await open7(path2, constants2.O_WRONLY | constants2.O_NOFOLLOW);
|
|
45667
|
+
} catch (cause) {
|
|
45668
|
+
if (typeof cause === "object" && cause !== null && "code" in cause && cause.code === "ENOENT") {
|
|
45669
|
+
throw new Error("The JSON output file does not exist", { cause });
|
|
45670
|
+
}
|
|
45671
|
+
throw new Error("The JSON output file cannot be written", { cause });
|
|
45672
|
+
}
|
|
45673
|
+
try {
|
|
45674
|
+
const metadata = await file2.stat();
|
|
45675
|
+
if (!metadata.isFile()) {
|
|
45676
|
+
throw new Error("The JSON output path is not a regular file");
|
|
45677
|
+
}
|
|
45678
|
+
const output2 = pairs.map((pair) => ({
|
|
45679
|
+
app_id: pair.appId,
|
|
45680
|
+
connection_id: pair.connectionId,
|
|
45681
|
+
runtime_id: pair.runtimeId,
|
|
45682
|
+
status: pair.status,
|
|
45683
|
+
workspace: pair.workspace
|
|
45684
|
+
}));
|
|
45685
|
+
shutdown.signal.throwIfAborted();
|
|
45686
|
+
await file2.truncate(0);
|
|
45687
|
+
await file2.writeFile(`${JSON.stringify(output2, null, 2)}
|
|
45688
|
+
`, "utf8");
|
|
45689
|
+
} finally {
|
|
45690
|
+
await file2.close();
|
|
45691
|
+
}
|
|
45692
|
+
}
|
|
45158
45693
|
async function main() {
|
|
45159
45694
|
const command = process.argv[2];
|
|
45160
45695
|
if (command === void 0 || command === "--help" || command === "-h") {
|
|
@@ -45171,8 +45706,8 @@ async function main() {
|
|
|
45171
45706
|
if (arguments_.length > 1 || arguments_.length === 1 && arguments_[0] !== "--json") {
|
|
45172
45707
|
throw new Error("Usage: mobius agents [--json]");
|
|
45173
45708
|
}
|
|
45174
|
-
const
|
|
45175
|
-
const localContext = new DaemonLocalContext(
|
|
45709
|
+
const installation2 = await openMobiusCliInstallation(shutdown.signal, process.env);
|
|
45710
|
+
const localContext = new DaemonLocalContext(installation2.stateDirectory, process.env);
|
|
45176
45711
|
const defaultWorkspace = loadDefaultWorkspace(localContext.environment);
|
|
45177
45712
|
await mkdir6(defaultWorkspace, { recursive: true, mode: 448 });
|
|
45178
45713
|
const inventory = await discoverLocalAgentInventory({
|
|
@@ -45183,38 +45718,118 @@ async function main() {
|
|
|
45183
45718
|
process.stdout.write(formatAgentDiagnostics(inventory, arguments_[0] === "--json"));
|
|
45184
45719
|
return;
|
|
45185
45720
|
}
|
|
45186
|
-
|
|
45721
|
+
const installation = await openMobiusCliInstallation(shutdown.signal, process.env);
|
|
45722
|
+
if (command === "__manager") {
|
|
45723
|
+
await runManager(installation, package_default.version, shutdown.signal);
|
|
45724
|
+
return;
|
|
45725
|
+
}
|
|
45187
45726
|
if (command === "pair") {
|
|
45188
|
-
process.
|
|
45727
|
+
if (process.argv[3] === "list") {
|
|
45728
|
+
const outputPath = pairListOutputPath(process.argv.slice(4));
|
|
45729
|
+
const response2 = await requestManager(
|
|
45730
|
+
installation,
|
|
45731
|
+
package_default.version,
|
|
45732
|
+
{ kind: "list" },
|
|
45733
|
+
shutdown.signal
|
|
45734
|
+
);
|
|
45735
|
+
if (response2.kind === "error") {
|
|
45736
|
+
throw new Error(response2.message);
|
|
45737
|
+
}
|
|
45738
|
+
if (response2.kind !== "listed") {
|
|
45739
|
+
throw new Error("The Mobius manager returned an unexpected response");
|
|
45740
|
+
}
|
|
45741
|
+
if (outputPath === null) {
|
|
45742
|
+
process.stdout.write(formatPairTable(response2.pairs));
|
|
45743
|
+
} else {
|
|
45744
|
+
await writePairList(outputPath, response2.pairs);
|
|
45745
|
+
}
|
|
45746
|
+
return;
|
|
45747
|
+
}
|
|
45748
|
+
const pairAction = process.argv[3];
|
|
45749
|
+
if (pairAction === "stop" || pairAction === "remove") {
|
|
45750
|
+
if (process.argv.length !== 6 || process.argv[4] !== "--connection" || process.argv[5] === void 0) {
|
|
45751
|
+
throw new Error(`Usage: mobius pair ${pairAction} --connection <connection-id>`);
|
|
45752
|
+
}
|
|
45753
|
+
const response2 = await requestManager(
|
|
45754
|
+
installation,
|
|
45755
|
+
package_default.version,
|
|
45756
|
+
{
|
|
45757
|
+
connectionId: process.argv[5],
|
|
45758
|
+
kind: pairAction === "stop" ? "stop-pair" : "remove-pair"
|
|
45759
|
+
},
|
|
45760
|
+
shutdown.signal
|
|
45761
|
+
);
|
|
45762
|
+
if (response2.kind === "error") {
|
|
45763
|
+
throw new Error(response2.message);
|
|
45764
|
+
}
|
|
45765
|
+
if (pairAction === "stop" && response2.kind === "pair-stopped") {
|
|
45766
|
+
process.stdout.write(`Pairing stopped: ${response2.pair.connectionId}
|
|
45189
45767
|
`);
|
|
45190
|
-
|
|
45191
|
-
|
|
45192
|
-
|
|
45193
|
-
|
|
45768
|
+
return;
|
|
45769
|
+
}
|
|
45770
|
+
if (pairAction === "remove" && response2.kind === "pair-removed") {
|
|
45771
|
+
process.stdout.write(`Pairing removed: ${response2.connectionId}
|
|
45194
45772
|
`);
|
|
45195
|
-
|
|
45773
|
+
return;
|
|
45774
|
+
}
|
|
45775
|
+
throw new Error("The Mobius manager returned an unexpected response");
|
|
45776
|
+
}
|
|
45777
|
+
process.stdout.write(`mobius version: ${package_default.version}
|
|
45196
45778
|
`);
|
|
45197
|
-
|
|
45779
|
+
const response = await requestManager(
|
|
45780
|
+
installation,
|
|
45781
|
+
package_default.version,
|
|
45782
|
+
{ arguments: process.argv.slice(3), kind: "pair" },
|
|
45783
|
+
shutdown.signal
|
|
45784
|
+
);
|
|
45785
|
+
if (response.kind === "error") {
|
|
45786
|
+
throw new Error(response.message);
|
|
45787
|
+
}
|
|
45788
|
+
if (response.kind !== "ready") {
|
|
45789
|
+
throw new Error("The Mobius manager returned an unexpected response");
|
|
45790
|
+
}
|
|
45791
|
+
process.stdout.write(
|
|
45792
|
+
response.alreadyOnline ? "\nThis pairing is already online.\n" : "\nLocal machine paired.\n"
|
|
45793
|
+
);
|
|
45794
|
+
process.stdout.write(`App ID: ${response.pair.appId}
|
|
45795
|
+
`);
|
|
45796
|
+
process.stdout.write(`Connection ID: ${response.pair.connectionId}
|
|
45198
45797
|
`);
|
|
45199
|
-
process.stdout.write(
|
|
45200
|
-
process.stdout.write(`Connection saved to ${paired.connectionPath}
|
|
45798
|
+
process.stdout.write(`Status: ${response.pair.status}
|
|
45201
45799
|
`);
|
|
45800
|
+
process.stdout.write("Mobius daemon is ready for Agent requests.\n");
|
|
45202
45801
|
} else if (command === "start") {
|
|
45203
|
-
const
|
|
45204
|
-
|
|
45802
|
+
const response = await requestManager(
|
|
45803
|
+
installation,
|
|
45804
|
+
package_default.version,
|
|
45805
|
+
{ arguments: process.argv.slice(3), kind: "start" },
|
|
45806
|
+
shutdown.signal
|
|
45807
|
+
);
|
|
45808
|
+
if (response.kind === "error") {
|
|
45809
|
+
throw new Error(response.message);
|
|
45810
|
+
}
|
|
45811
|
+
if (response.kind !== "ready") {
|
|
45812
|
+
throw new Error("The Mobius manager returned an unexpected response");
|
|
45813
|
+
}
|
|
45205
45814
|
process.stdout.write("\nSaved local Runtime connection loaded.\n");
|
|
45206
|
-
process.stdout.write(`
|
|
45815
|
+
process.stdout.write(`Connection ID: ${response.pair.connectionId}
|
|
45207
45816
|
`);
|
|
45208
|
-
process.stdout.write(
|
|
45817
|
+
process.stdout.write(`Status: ${response.pair.status}
|
|
45818
|
+
`);
|
|
45819
|
+
process.stdout.write("Mobius daemon is ready for Agent requests.\n");
|
|
45820
|
+
} else if (command === "quit") {
|
|
45821
|
+
if (process.argv.length !== 3) {
|
|
45822
|
+
throw new Error("Usage: mobius quit");
|
|
45823
|
+
}
|
|
45824
|
+
const response = await requestManager(installation, package_default.version, { kind: "stop" }, shutdown.signal);
|
|
45825
|
+
if (response.kind === "error") {
|
|
45826
|
+
throw new Error(response.message);
|
|
45827
|
+
}
|
|
45828
|
+
process.stdout.write("Mobius daemon stopped.\n");
|
|
45829
|
+
return;
|
|
45209
45830
|
} else {
|
|
45210
45831
|
throw new Error(USAGE.trimEnd());
|
|
45211
45832
|
}
|
|
45212
|
-
process.stdout.write("Starting the local daemon. Keep this terminal open.\n\n");
|
|
45213
|
-
process.stdout.write("This paired browser can use the machine with your user account's permissions.\n");
|
|
45214
|
-
process.stdout.write(`Default workspace: ${config2.defaultWorkspace}
|
|
45215
|
-
|
|
45216
|
-
`);
|
|
45217
|
-
await new MobiusRuntimeEngine(config2).run(shutdown.signal);
|
|
45218
45833
|
}
|
|
45219
45834
|
try {
|
|
45220
45835
|
await main();
|