@moxt-ai/mobius 0.0.49 → 0.0.50
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/cli.js +777 -218
- package/dist/cli.js.map +4 -4
- package/dist/config.d.ts +21 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +32 -2
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +749 -187
- package/dist/index.js.map +4 -4
- package/dist/pairing/pair-local-machine.d.ts +5 -2
- package/dist/pairing/pair-local-machine.d.ts.map +1 -1
- package/dist/pairing/pair-local-machine.js +93 -111
- package/dist/pairing/pair-local-machine.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +4 -5
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.d.ts +2 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +661 -159
- package/dist/runtime.js.map +4 -4
- package/dist/storage/runtime-installation-store.d.ts +53 -0
- package/dist/storage/runtime-installation-store.d.ts.map +1 -0
- package/dist/storage/runtime-installation-store.js +491 -0
- package/dist/storage/runtime-installation-store.js.map +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var createAcpClient = (handler) => client({ name: "mobius" }).onRequest(
|
|
|
32
32
|
})).onNotification("cursor/update_todos", discardExtensionParams, async () => Promise.resolve()).onNotification("cursor/task", discardExtensionParams, async () => Promise.resolve()).onNotification("cursor/generate_image", discardExtensionParams, async () => Promise.resolve());
|
|
33
33
|
|
|
34
34
|
// src/config.ts
|
|
35
|
-
import { join as join3 } from "node:path";
|
|
35
|
+
import { join as join3, resolve as resolve3 } from "node:path";
|
|
36
36
|
import { fileURLToPath } from "node:url";
|
|
37
37
|
|
|
38
38
|
// ../../node_modules/.pnpm/zod@4.6.2/node_modules/zod/v4/classic/external.js
|
|
@@ -5067,7 +5067,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
5067
5067
|
var NONE = 0;
|
|
5068
5068
|
var ASSUMED = 1;
|
|
5069
5069
|
var PROVEN = 2;
|
|
5070
|
-
function isRecursive(inst, stack,
|
|
5070
|
+
function isRecursive(inst, stack, resolve8) {
|
|
5071
5071
|
const cached2 = recursive.get(inst);
|
|
5072
5072
|
if (cached2 !== void 0)
|
|
5073
5073
|
return cached2 ? PROVEN : NONE;
|
|
@@ -5077,7 +5077,7 @@ function isRecursive(inst, stack, resolve6) {
|
|
|
5077
5077
|
let result = NONE;
|
|
5078
5078
|
const check2 = (child) => {
|
|
5079
5079
|
if (result !== PROVEN && child?._zod) {
|
|
5080
|
-
const answer = isRecursive(child, stack,
|
|
5080
|
+
const answer = isRecursive(child, stack, resolve8);
|
|
5081
5081
|
if (answer > result)
|
|
5082
5082
|
result = answer;
|
|
5083
5083
|
}
|
|
@@ -5088,7 +5088,7 @@ function isRecursive(inst, stack, resolve6) {
|
|
|
5088
5088
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
5089
5089
|
if (spread && !desc.enumerable)
|
|
5090
5090
|
continue;
|
|
5091
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
5091
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve8) : NONE;
|
|
5092
5092
|
if (child > answer)
|
|
5093
5093
|
answer = child;
|
|
5094
5094
|
}
|
|
@@ -5155,7 +5155,7 @@ function isRecursive(inst, stack, resolve6) {
|
|
|
5155
5155
|
break;
|
|
5156
5156
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
5157
5157
|
case "lazy": {
|
|
5158
|
-
const inner = def._cachedInner ?? (
|
|
5158
|
+
const inner = def._cachedInner ?? (resolve8 ? inst._zod.innerType : void 0);
|
|
5159
5159
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
5160
5160
|
break;
|
|
5161
5161
|
}
|
|
@@ -22004,7 +22004,35 @@ function loadDefaultWorkspace(environment = process.env) {
|
|
|
22004
22004
|
const { MOBIUS_DEFAULT_WORKSPACE: configuredWorkspace } = environment;
|
|
22005
22005
|
return configuredWorkspace ?? join3(readStateDirectory(environment), "workspace");
|
|
22006
22006
|
}
|
|
22007
|
-
|
|
22007
|
+
var DaemonLocalContext = class {
|
|
22008
|
+
environment;
|
|
22009
|
+
stateDirectory;
|
|
22010
|
+
constructor(stateDirectory, environment = process.env) {
|
|
22011
|
+
this.stateDirectory = resolve3(stateDirectory);
|
|
22012
|
+
this.environment = Object.freeze({ ...environment, MOBIUS_STATE_DIRECTORY: this.stateDirectory });
|
|
22013
|
+
}
|
|
22014
|
+
};
|
|
22015
|
+
var DaemonReconnectTarget = class {
|
|
22016
|
+
};
|
|
22017
|
+
var OpaqueDaemonReconnectTarget = class extends DaemonReconnectTarget {
|
|
22018
|
+
connectionId;
|
|
22019
|
+
commandArgument;
|
|
22020
|
+
constructor(connectionId2) {
|
|
22021
|
+
super();
|
|
22022
|
+
this.connectionId = connectionId2;
|
|
22023
|
+
this.commandArgument = `--connection ${connectionId2}`;
|
|
22024
|
+
}
|
|
22025
|
+
};
|
|
22026
|
+
var ChannelDaemonReconnectTarget = class extends DaemonReconnectTarget {
|
|
22027
|
+
channelId;
|
|
22028
|
+
commandArgument;
|
|
22029
|
+
constructor(channelId) {
|
|
22030
|
+
super();
|
|
22031
|
+
this.channelId = channelId;
|
|
22032
|
+
this.commandArgument = `--channel ${channelId}`;
|
|
22033
|
+
}
|
|
22034
|
+
};
|
|
22035
|
+
function createDaemonConfig(connection, agents = [], installableAgents = [], localContext = new DaemonLocalContext(readStateDirectory(), process.env), reconnectTarget = new ChannelDaemonReconnectTarget(connection.channelId)) {
|
|
22008
22036
|
return {
|
|
22009
22037
|
agents,
|
|
22010
22038
|
defaultWorkspace: connection.defaultWorkspace,
|
|
@@ -22013,6 +22041,8 @@ function createDaemonConfig(connection, agents = [], installableAgents = []) {
|
|
|
22013
22041
|
catalog: new LocalAgentCatalog(agents, installableAgents),
|
|
22014
22042
|
channelId: connection.channelId,
|
|
22015
22043
|
installableAgents,
|
|
22044
|
+
localContext,
|
|
22045
|
+
reconnectTarget,
|
|
22016
22046
|
relayUrl: connection.relayUrl
|
|
22017
22047
|
};
|
|
22018
22048
|
}
|
|
@@ -25451,10 +25481,10 @@ function resolveAll(constructs2, events, context) {
|
|
|
25451
25481
|
const called = [];
|
|
25452
25482
|
let index2 = -1;
|
|
25453
25483
|
while (++index2 < constructs2.length) {
|
|
25454
|
-
const
|
|
25455
|
-
if (
|
|
25456
|
-
events =
|
|
25457
|
-
called.push(
|
|
25484
|
+
const resolve8 = constructs2[index2].resolveAll;
|
|
25485
|
+
if (resolve8 && !called.includes(resolve8)) {
|
|
25486
|
+
events = resolve8(events, context);
|
|
25487
|
+
called.push(resolve8);
|
|
25458
25488
|
}
|
|
25459
25489
|
}
|
|
25460
25490
|
return events;
|
|
@@ -31038,7 +31068,7 @@ function createWritableAcpStream(output2) {
|
|
|
31038
31068
|
if (outputFailure !== void 0) {
|
|
31039
31069
|
return Promise.reject(outputFailure);
|
|
31040
31070
|
}
|
|
31041
|
-
return new Promise((
|
|
31071
|
+
return new Promise((resolve8, reject) => {
|
|
31042
31072
|
pendingWriteFailures.add(reject);
|
|
31043
31073
|
output2.write(chunk, (error62) => {
|
|
31044
31074
|
pendingWriteFailures.delete(reject);
|
|
@@ -31051,7 +31081,7 @@ function createWritableAcpStream(output2) {
|
|
|
31051
31081
|
reject(outputFailure);
|
|
31052
31082
|
return;
|
|
31053
31083
|
}
|
|
31054
|
-
|
|
31084
|
+
resolve8();
|
|
31055
31085
|
});
|
|
31056
31086
|
});
|
|
31057
31087
|
}
|
|
@@ -31464,9 +31494,9 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
31464
31494
|
stderr.on("data", (chunk) => {
|
|
31465
31495
|
process.stderr.write(`[${agent.id}-acp] ${chunk}`);
|
|
31466
31496
|
});
|
|
31467
|
-
this.#processExit = new Promise((
|
|
31468
|
-
this.#child.once("error",
|
|
31469
|
-
this.#child.once("exit",
|
|
31497
|
+
this.#processExit = new Promise((resolve8) => {
|
|
31498
|
+
this.#child.once("error", resolve8);
|
|
31499
|
+
this.#child.once("exit", resolve8);
|
|
31470
31500
|
});
|
|
31471
31501
|
const stream = ndJsonStream(createWritableAcpStream(stdin), readableWebStream(stdout));
|
|
31472
31502
|
this.#connection = createAcpClient(this).connect(stream);
|
|
@@ -33769,10 +33799,9 @@ var LocalAuthorizationError = class extends Error {
|
|
|
33769
33799
|
};
|
|
33770
33800
|
|
|
33771
33801
|
// src/pairing/pair-local-machine.ts
|
|
33772
|
-
import {
|
|
33773
|
-
import { mkdir as mkdir3, open as open5, realpath as realpath7, rename as rename3, stat as stat6, writeFile as writeFile2 } from "node:fs/promises";
|
|
33802
|
+
import { mkdir as mkdir4, realpath as realpath7, stat as stat6 } from "node:fs/promises";
|
|
33774
33803
|
import { hostname as hostname3 } from "node:os";
|
|
33775
|
-
import { basename as basename3,
|
|
33804
|
+
import { basename as basename3, resolve as resolve5 } from "node:path";
|
|
33776
33805
|
import { fetch as fetch2 } from "undici";
|
|
33777
33806
|
|
|
33778
33807
|
// src/agent-catalog/agent-discovery.ts
|
|
@@ -35765,16 +35794,544 @@ async function discoverLocalAgentInventory(options) {
|
|
|
35765
35794
|
return new LocalAgentInventory(discoveries);
|
|
35766
35795
|
}
|
|
35767
35796
|
|
|
35797
|
+
// src/storage/runtime-installation-store.ts
|
|
35798
|
+
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
35799
|
+
import { mkdir as mkdir3, open as open5, rename as rename3, unlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
35800
|
+
import { dirname as dirname5, join as join15, resolve as resolve4 } from "node:path";
|
|
35801
|
+
var APPLICATION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+){1,31}$/;
|
|
35802
|
+
var CONNECTION_ID_PATTERN = /^mcn_[a-f0-9]{32}$/;
|
|
35803
|
+
var INSTALLATION_ID_PATTERN = /^min_[a-f0-9]{32}$/;
|
|
35804
|
+
var IDENTIFIER_PATTERN4 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
35805
|
+
var RUNTIME_CREDENTIAL_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
35806
|
+
var MAX_FILE_LENGTH = 16 * 1024;
|
|
35807
|
+
var INSTALLATION_POINTER_KEYS = ["installationId", "version"];
|
|
35808
|
+
var CHANNEL_INDEX_KEYS = [
|
|
35809
|
+
"applicationId",
|
|
35810
|
+
"channelId",
|
|
35811
|
+
"connectionId",
|
|
35812
|
+
"installationId",
|
|
35813
|
+
"version"
|
|
35814
|
+
];
|
|
35815
|
+
var VERIFIED_CONNECTION_KEYS = [
|
|
35816
|
+
"applicationId",
|
|
35817
|
+
"channelId",
|
|
35818
|
+
"connectionId",
|
|
35819
|
+
"defaultWorkspace",
|
|
35820
|
+
"installationId",
|
|
35821
|
+
"kind",
|
|
35822
|
+
"relayOrigin",
|
|
35823
|
+
"runtimeCredential",
|
|
35824
|
+
"runtimeId",
|
|
35825
|
+
"version"
|
|
35826
|
+
];
|
|
35827
|
+
var IMPORTED_LEGACY_CONNECTION_KEYS = [
|
|
35828
|
+
"applicationId",
|
|
35829
|
+
"channelId",
|
|
35830
|
+
"connectionId",
|
|
35831
|
+
"defaultWorkspace",
|
|
35832
|
+
"installationId",
|
|
35833
|
+
"kind",
|
|
35834
|
+
"relayOrigin",
|
|
35835
|
+
"runtimeCredential",
|
|
35836
|
+
"version"
|
|
35837
|
+
];
|
|
35838
|
+
var CURRENT_CONNECTION_KEYS = [
|
|
35839
|
+
"defaultWorkspace",
|
|
35840
|
+
"channelId",
|
|
35841
|
+
"relayOrigin",
|
|
35842
|
+
"runtimeCredential"
|
|
35843
|
+
];
|
|
35844
|
+
var LEGACY_CONNECTION_KEYS = ["defaultWorkspace", "channelId", "daemonToken", "relayOrigin"];
|
|
35845
|
+
var RuntimeInstallationStoreError = class extends Error {
|
|
35846
|
+
code;
|
|
35847
|
+
constructor(code, message, options = {}) {
|
|
35848
|
+
super(message, options);
|
|
35849
|
+
this.code = code;
|
|
35850
|
+
this.name = "RuntimeInstallationStoreError";
|
|
35851
|
+
}
|
|
35852
|
+
};
|
|
35853
|
+
var StoredRuntimeConnection = class {
|
|
35854
|
+
applicationId;
|
|
35855
|
+
channelId;
|
|
35856
|
+
connectionId;
|
|
35857
|
+
defaultWorkspace;
|
|
35858
|
+
installationId;
|
|
35859
|
+
relayOrigin;
|
|
35860
|
+
runtimeCredential;
|
|
35861
|
+
constructor(applicationId, installationId2, connectionId2, channelId, defaultWorkspace, relayOrigin, runtimeCredential2) {
|
|
35862
|
+
this.applicationId = applicationId;
|
|
35863
|
+
this.channelId = channelId;
|
|
35864
|
+
this.connectionId = connectionId2;
|
|
35865
|
+
this.defaultWorkspace = defaultWorkspace;
|
|
35866
|
+
this.installationId = installationId2;
|
|
35867
|
+
this.relayOrigin = relayOrigin;
|
|
35868
|
+
this.runtimeCredential = runtimeCredential2;
|
|
35869
|
+
}
|
|
35870
|
+
};
|
|
35871
|
+
var VerifiedRuntimeConnection = class extends StoredRuntimeConnection {
|
|
35872
|
+
kind = "verified";
|
|
35873
|
+
runtimeId;
|
|
35874
|
+
constructor(applicationId, installationId2, connectionId2, channelId, defaultWorkspace, relayOrigin, runtimeCredential2, runtimeId) {
|
|
35875
|
+
super(applicationId, installationId2, connectionId2, channelId, defaultWorkspace, relayOrigin, runtimeCredential2);
|
|
35876
|
+
this.runtimeId = runtimeId;
|
|
35877
|
+
}
|
|
35878
|
+
};
|
|
35879
|
+
var ImportedLegacyRuntimeConnection = class extends StoredRuntimeConnection {
|
|
35880
|
+
kind = "legacy_imported";
|
|
35881
|
+
constructor(applicationId, installationId2, connectionId2, channelId, defaultWorkspace, relayOrigin, runtimeCredential2) {
|
|
35882
|
+
super(applicationId, installationId2, connectionId2, channelId, defaultWorkspace, relayOrigin, runtimeCredential2);
|
|
35883
|
+
}
|
|
35884
|
+
};
|
|
35885
|
+
function isRecord8(value) {
|
|
35886
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
35887
|
+
}
|
|
35888
|
+
function hasExactKeys(value, expectedKeys) {
|
|
35889
|
+
const keys = Object.keys(value);
|
|
35890
|
+
return keys.length === expectedKeys.length && expectedKeys.every((key) => Object.hasOwn(value, key));
|
|
35891
|
+
}
|
|
35892
|
+
function isNodeError(error62, code) {
|
|
35893
|
+
return typeof error62 === "object" && error62 !== null && "code" in error62 && error62.code === code;
|
|
35894
|
+
}
|
|
35895
|
+
function validateApplicationId(value) {
|
|
35896
|
+
if (!APPLICATION_ID_PATTERN.test(value)) {
|
|
35897
|
+
throw new RuntimeInstallationStoreError("invalid_application_id", "The application ID is invalid");
|
|
35898
|
+
}
|
|
35899
|
+
return value;
|
|
35900
|
+
}
|
|
35901
|
+
function validateConnectionId(value) {
|
|
35902
|
+
if (!CONNECTION_ID_PATTERN.test(value)) {
|
|
35903
|
+
throw new RuntimeInstallationStoreError("invalid_connection_id", "The local connection ID is invalid");
|
|
35904
|
+
}
|
|
35905
|
+
return value;
|
|
35906
|
+
}
|
|
35907
|
+
function validateInstallationId(value) {
|
|
35908
|
+
if (!INSTALLATION_ID_PATTERN.test(value)) {
|
|
35909
|
+
throw new RuntimeInstallationStoreError("invalid_installation_id", "The installation ID is invalid");
|
|
35910
|
+
}
|
|
35911
|
+
return value;
|
|
35912
|
+
}
|
|
35913
|
+
function validateIdentifier(value, code) {
|
|
35914
|
+
if (!IDENTIFIER_PATTERN4.test(value)) {
|
|
35915
|
+
throw new RuntimeInstallationStoreError(code, "The saved Runtime connection is invalid");
|
|
35916
|
+
}
|
|
35917
|
+
return value;
|
|
35918
|
+
}
|
|
35919
|
+
function validateRuntimeCredential(value) {
|
|
35920
|
+
if (!RUNTIME_CREDENTIAL_PATTERN.test(value)) {
|
|
35921
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
35922
|
+
}
|
|
35923
|
+
return value;
|
|
35924
|
+
}
|
|
35925
|
+
function parseRelayOrigin(value) {
|
|
35926
|
+
let origin;
|
|
35927
|
+
try {
|
|
35928
|
+
origin = new URL(value);
|
|
35929
|
+
} catch (cause) {
|
|
35930
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid", {
|
|
35931
|
+
cause
|
|
35932
|
+
});
|
|
35933
|
+
}
|
|
35934
|
+
if (origin.protocol !== "https:" && origin.protocol !== "http:" || origin.username.length > 0 || origin.password.length > 0 || origin.protocol === "http:" && origin.hostname !== "127.0.0.1" && origin.hostname !== "localhost") {
|
|
35935
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
35936
|
+
}
|
|
35937
|
+
origin.hash = "";
|
|
35938
|
+
origin.pathname = "/";
|
|
35939
|
+
origin.search = "";
|
|
35940
|
+
return origin;
|
|
35941
|
+
}
|
|
35942
|
+
function connectionId() {
|
|
35943
|
+
return `mcn_${randomUUID().replaceAll("-", "")}`;
|
|
35944
|
+
}
|
|
35945
|
+
function installationId() {
|
|
35946
|
+
return `min_${randomUUID().replaceAll("-", "")}`;
|
|
35947
|
+
}
|
|
35948
|
+
function channelIndexFileName(channelId) {
|
|
35949
|
+
return `mci_${createHash2("sha256").update(channelId).digest("hex")}.json`;
|
|
35950
|
+
}
|
|
35951
|
+
function decodeInstallationPointer(value) {
|
|
35952
|
+
if (!isRecord8(value) || !hasExactKeys(value, INSTALLATION_POINTER_KEYS) || value["version"] !== 1) {
|
|
35953
|
+
throw new RuntimeInstallationStoreError("invalid_installation", "The local installation record is invalid");
|
|
35954
|
+
}
|
|
35955
|
+
const storedInstallationId = value["installationId"];
|
|
35956
|
+
if (typeof storedInstallationId !== "string") {
|
|
35957
|
+
throw new RuntimeInstallationStoreError("invalid_installation", "The local installation record is invalid");
|
|
35958
|
+
}
|
|
35959
|
+
return { installationId: validateInstallationId(storedInstallationId) };
|
|
35960
|
+
}
|
|
35961
|
+
function decodeChannelIndex(value) {
|
|
35962
|
+
if (!isRecord8(value) || !hasExactKeys(value, CHANNEL_INDEX_KEYS) || value["version"] !== 1) {
|
|
35963
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
35964
|
+
}
|
|
35965
|
+
const applicationId = value["applicationId"];
|
|
35966
|
+
const channelId = value["channelId"];
|
|
35967
|
+
const connectionId2 = value["connectionId"];
|
|
35968
|
+
const storedInstallationId = value["installationId"];
|
|
35969
|
+
if (typeof applicationId !== "string" || typeof channelId !== "string" || typeof connectionId2 !== "string" || typeof storedInstallationId !== "string") {
|
|
35970
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
35971
|
+
}
|
|
35972
|
+
return {
|
|
35973
|
+
applicationId: validateApplicationId(applicationId),
|
|
35974
|
+
channelId: validateIdentifier(channelId, "invalid_connection"),
|
|
35975
|
+
connectionId: validateConnectionId(connectionId2),
|
|
35976
|
+
installationId: validateInstallationId(storedInstallationId)
|
|
35977
|
+
};
|
|
35978
|
+
}
|
|
35979
|
+
function decodeVerifiedConnection(value) {
|
|
35980
|
+
if (!hasExactKeys(value, VERIFIED_CONNECTION_KEYS) || value["kind"] !== "verified" || value["version"] !== 1) {
|
|
35981
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
35982
|
+
}
|
|
35983
|
+
const applicationId = value["applicationId"];
|
|
35984
|
+
const channelId = value["channelId"];
|
|
35985
|
+
const connectionId2 = value["connectionId"];
|
|
35986
|
+
const defaultWorkspace = value["defaultWorkspace"];
|
|
35987
|
+
const storedInstallationId = value["installationId"];
|
|
35988
|
+
const relayOrigin = value["relayOrigin"];
|
|
35989
|
+
const runtimeCredential2 = value["runtimeCredential"];
|
|
35990
|
+
const runtimeId = value["runtimeId"];
|
|
35991
|
+
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") {
|
|
35992
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
35993
|
+
}
|
|
35994
|
+
return new VerifiedRuntimeConnection(
|
|
35995
|
+
validateApplicationId(applicationId),
|
|
35996
|
+
validateInstallationId(storedInstallationId),
|
|
35997
|
+
validateConnectionId(connectionId2),
|
|
35998
|
+
validateIdentifier(channelId, "invalid_connection"),
|
|
35999
|
+
defaultWorkspace,
|
|
36000
|
+
parseRelayOrigin(relayOrigin),
|
|
36001
|
+
validateRuntimeCredential(runtimeCredential2),
|
|
36002
|
+
validateIdentifier(runtimeId, "invalid_connection")
|
|
36003
|
+
);
|
|
36004
|
+
}
|
|
36005
|
+
function decodeImportedLegacyConnection(value) {
|
|
36006
|
+
if (!hasExactKeys(value, IMPORTED_LEGACY_CONNECTION_KEYS) || value["kind"] !== "legacy_imported" || value["version"] !== 1) {
|
|
36007
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
36008
|
+
}
|
|
36009
|
+
const applicationId = value["applicationId"];
|
|
36010
|
+
const channelId = value["channelId"];
|
|
36011
|
+
const connectionId2 = value["connectionId"];
|
|
36012
|
+
const defaultWorkspace = value["defaultWorkspace"];
|
|
36013
|
+
const storedInstallationId = value["installationId"];
|
|
36014
|
+
const relayOrigin = value["relayOrigin"];
|
|
36015
|
+
const runtimeCredential2 = value["runtimeCredential"];
|
|
36016
|
+
if (typeof applicationId !== "string" || typeof channelId !== "string" || typeof connectionId2 !== "string" || typeof defaultWorkspace !== "string" || typeof storedInstallationId !== "string" || typeof relayOrigin !== "string" || typeof runtimeCredential2 !== "string") {
|
|
36017
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
36018
|
+
}
|
|
36019
|
+
return new ImportedLegacyRuntimeConnection(
|
|
36020
|
+
validateApplicationId(applicationId),
|
|
36021
|
+
validateInstallationId(storedInstallationId),
|
|
36022
|
+
validateConnectionId(connectionId2),
|
|
36023
|
+
validateIdentifier(channelId, "invalid_connection"),
|
|
36024
|
+
defaultWorkspace,
|
|
36025
|
+
parseRelayOrigin(relayOrigin),
|
|
36026
|
+
validateRuntimeCredential(runtimeCredential2)
|
|
36027
|
+
);
|
|
36028
|
+
}
|
|
36029
|
+
function decodeConnection(value) {
|
|
36030
|
+
if (!isRecord8(value)) {
|
|
36031
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
36032
|
+
}
|
|
36033
|
+
if (value["kind"] === "verified") {
|
|
36034
|
+
return decodeVerifiedConnection(value);
|
|
36035
|
+
}
|
|
36036
|
+
if (value["kind"] === "legacy_imported") {
|
|
36037
|
+
return decodeImportedLegacyConnection(value);
|
|
36038
|
+
}
|
|
36039
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
36040
|
+
}
|
|
36041
|
+
function decodeLegacyConnection(value, expectedChannelId) {
|
|
36042
|
+
if (!isRecord8(value) || !hasExactKeys(value, CURRENT_CONNECTION_KEYS) && !hasExactKeys(value, LEGACY_CONNECTION_KEYS)) {
|
|
36043
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
36044
|
+
}
|
|
36045
|
+
const channelId = value["channelId"];
|
|
36046
|
+
const defaultWorkspace = value["defaultWorkspace"];
|
|
36047
|
+
const relayOrigin = value["relayOrigin"];
|
|
36048
|
+
const runtimeCredential2 = value["runtimeCredential"] ?? value["daemonToken"];
|
|
36049
|
+
if (typeof channelId !== "string" || channelId !== expectedChannelId || typeof defaultWorkspace !== "string" || typeof relayOrigin !== "string" || typeof runtimeCredential2 !== "string") {
|
|
36050
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
36051
|
+
}
|
|
36052
|
+
return {
|
|
36053
|
+
channelId: validateIdentifier(channelId, "invalid_connection"),
|
|
36054
|
+
defaultWorkspace,
|
|
36055
|
+
relayOrigin: parseRelayOrigin(relayOrigin),
|
|
36056
|
+
runtimeCredential: validateRuntimeCredential(runtimeCredential2)
|
|
36057
|
+
};
|
|
36058
|
+
}
|
|
36059
|
+
async function readJsonFile(path2, signal, missingCode) {
|
|
36060
|
+
signal.throwIfAborted();
|
|
36061
|
+
let handle;
|
|
36062
|
+
try {
|
|
36063
|
+
handle = await open5(path2, "r");
|
|
36064
|
+
} catch (cause) {
|
|
36065
|
+
if (isNodeError(cause, "ENOENT")) {
|
|
36066
|
+
throw new RuntimeInstallationStoreError(missingCode, "The saved Runtime connection was not found", {
|
|
36067
|
+
cause
|
|
36068
|
+
});
|
|
36069
|
+
}
|
|
36070
|
+
throw new RuntimeInstallationStoreError(
|
|
36071
|
+
"connection_unavailable",
|
|
36072
|
+
"The saved Runtime connection cannot be read",
|
|
36073
|
+
{
|
|
36074
|
+
cause
|
|
36075
|
+
}
|
|
36076
|
+
);
|
|
36077
|
+
}
|
|
36078
|
+
let encoded = "";
|
|
36079
|
+
try {
|
|
36080
|
+
const metadata = await handle.stat();
|
|
36081
|
+
if (!metadata.isFile() || metadata.size > MAX_FILE_LENGTH) {
|
|
36082
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
36083
|
+
}
|
|
36084
|
+
encoded = await handle.readFile({ encoding: "utf8" });
|
|
36085
|
+
} finally {
|
|
36086
|
+
await handle.close();
|
|
36087
|
+
}
|
|
36088
|
+
signal.throwIfAborted();
|
|
36089
|
+
try {
|
|
36090
|
+
return JSON.parse(encoded);
|
|
36091
|
+
} catch (cause) {
|
|
36092
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid", {
|
|
36093
|
+
cause
|
|
36094
|
+
});
|
|
36095
|
+
}
|
|
36096
|
+
}
|
|
36097
|
+
async function writeJsonAtomically(path2, value, signal) {
|
|
36098
|
+
signal.throwIfAborted();
|
|
36099
|
+
const directory = dirname5(path2);
|
|
36100
|
+
const temporaryPath = join15(directory, `.${randomUUID()}.tmp`);
|
|
36101
|
+
try {
|
|
36102
|
+
await mkdir3(directory, { mode: 448, recursive: true });
|
|
36103
|
+
signal.throwIfAborted();
|
|
36104
|
+
await writeFile2(temporaryPath, `${JSON.stringify(value, null, 2)}
|
|
36105
|
+
`, { flag: "wx", mode: 384 });
|
|
36106
|
+
signal.throwIfAborted();
|
|
36107
|
+
await rename3(temporaryPath, path2);
|
|
36108
|
+
} catch (cause) {
|
|
36109
|
+
await unlink(temporaryPath).catch(() => void 0);
|
|
36110
|
+
signal.throwIfAborted();
|
|
36111
|
+
throw new RuntimeInstallationStoreError("connection_unavailable", "The local Runtime state cannot be written", {
|
|
36112
|
+
cause
|
|
36113
|
+
});
|
|
36114
|
+
}
|
|
36115
|
+
}
|
|
36116
|
+
var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
36117
|
+
applicationId;
|
|
36118
|
+
installationId;
|
|
36119
|
+
stateDirectory;
|
|
36120
|
+
#channelDirectory;
|
|
36121
|
+
#connectionDirectory;
|
|
36122
|
+
constructor(applicationId, installationId2, stateDirectory) {
|
|
36123
|
+
this.applicationId = applicationId;
|
|
36124
|
+
this.installationId = installationId2;
|
|
36125
|
+
this.stateDirectory = stateDirectory;
|
|
36126
|
+
this.#channelDirectory = join15(stateDirectory, "channels");
|
|
36127
|
+
this.#connectionDirectory = join15(stateDirectory, "connections");
|
|
36128
|
+
}
|
|
36129
|
+
static open = async (options, signal) => {
|
|
36130
|
+
signal.throwIfAborted();
|
|
36131
|
+
const applicationId = validateApplicationId(options.applicationId);
|
|
36132
|
+
const rootDirectory = resolve4(options.stateDirectory);
|
|
36133
|
+
const applicationDirectory = join15(rootDirectory, "installations", applicationId);
|
|
36134
|
+
try {
|
|
36135
|
+
await mkdir3(applicationDirectory, { mode: 448, recursive: true });
|
|
36136
|
+
} catch (cause) {
|
|
36137
|
+
throw new RuntimeInstallationStoreError(
|
|
36138
|
+
"installation_unavailable",
|
|
36139
|
+
"The local installation cannot be initialized",
|
|
36140
|
+
{
|
|
36141
|
+
cause
|
|
36142
|
+
}
|
|
36143
|
+
);
|
|
36144
|
+
}
|
|
36145
|
+
const storedInstallationId = await readOrCreateInstallationId(applicationDirectory, signal);
|
|
36146
|
+
const stateDirectory = join15(applicationDirectory, storedInstallationId);
|
|
36147
|
+
try {
|
|
36148
|
+
await mkdir3(stateDirectory, { mode: 448, recursive: true });
|
|
36149
|
+
} catch (cause) {
|
|
36150
|
+
throw new RuntimeInstallationStoreError(
|
|
36151
|
+
"installation_unavailable",
|
|
36152
|
+
"The local installation cannot be initialized",
|
|
36153
|
+
{
|
|
36154
|
+
cause
|
|
36155
|
+
}
|
|
36156
|
+
);
|
|
36157
|
+
}
|
|
36158
|
+
signal.throwIfAborted();
|
|
36159
|
+
return new _RuntimeInstallationStore(applicationId, storedInstallationId, stateDirectory);
|
|
36160
|
+
};
|
|
36161
|
+
connectionPath = (connectionId2) => join15(this.#connectionDirectory, `${validateConnectionId(connectionId2)}.json`);
|
|
36162
|
+
auditDatabasePath = (connectionId2) => join15(this.stateDirectory, "audit", `${validateConnectionId(connectionId2)}.sqlite`);
|
|
36163
|
+
channelIndexPath = (channelId) => join15(this.#channelDirectory, channelIndexFileName(validateIdentifier(channelId, "invalid_channel_id")));
|
|
36164
|
+
readConnection = async (connectionId2, signal) => {
|
|
36165
|
+
const stored = decodeConnection(
|
|
36166
|
+
await readJsonFile(this.connectionPath(connectionId2), signal, "connection_not_found")
|
|
36167
|
+
);
|
|
36168
|
+
if (stored.applicationId !== this.applicationId || stored.installationId !== this.installationId) {
|
|
36169
|
+
throw new RuntimeInstallationStoreError(
|
|
36170
|
+
"connection_owner_mismatch",
|
|
36171
|
+
"The saved Runtime connection belongs to another installation"
|
|
36172
|
+
);
|
|
36173
|
+
}
|
|
36174
|
+
return stored;
|
|
36175
|
+
};
|
|
36176
|
+
#readConnectionForChannel = async (channelId, signal) => {
|
|
36177
|
+
const normalizedChannelId = validateIdentifier(channelId, "invalid_channel_id");
|
|
36178
|
+
const index2 = decodeChannelIndex(
|
|
36179
|
+
await readJsonFile(this.channelIndexPath(normalizedChannelId), signal, "connection_not_found")
|
|
36180
|
+
);
|
|
36181
|
+
if (index2.applicationId !== this.applicationId || index2.installationId !== this.installationId || index2.channelId !== normalizedChannelId) {
|
|
36182
|
+
throw new RuntimeInstallationStoreError(
|
|
36183
|
+
"connection_owner_mismatch",
|
|
36184
|
+
"The saved Runtime connection belongs to another installation"
|
|
36185
|
+
);
|
|
36186
|
+
}
|
|
36187
|
+
return await this.readConnection(index2.connectionId, signal);
|
|
36188
|
+
};
|
|
36189
|
+
migrateLegacyConnection = async (legacyStateDirectory, channelId, signal) => {
|
|
36190
|
+
try {
|
|
36191
|
+
return await this.#readConnectionForChannel(channelId, signal);
|
|
36192
|
+
} catch (cause) {
|
|
36193
|
+
if (!(cause instanceof RuntimeInstallationStoreError) || cause.code !== "connection_not_found") {
|
|
36194
|
+
throw cause;
|
|
36195
|
+
}
|
|
36196
|
+
}
|
|
36197
|
+
return await this.importLegacyConnection(legacyStateDirectory, channelId, signal);
|
|
36198
|
+
};
|
|
36199
|
+
saveConnection = async (input2, signal) => {
|
|
36200
|
+
const stored = new VerifiedRuntimeConnection(
|
|
36201
|
+
this.applicationId,
|
|
36202
|
+
this.installationId,
|
|
36203
|
+
connectionId(),
|
|
36204
|
+
validateIdentifier(input2.channelId, "invalid_connection"),
|
|
36205
|
+
input2.defaultWorkspace,
|
|
36206
|
+
parseRelayOrigin(input2.relayOrigin.toString()),
|
|
36207
|
+
validateRuntimeCredential(input2.runtimeCredential),
|
|
36208
|
+
validateIdentifier(input2.runtimeId, "invalid_connection")
|
|
36209
|
+
);
|
|
36210
|
+
await this.writeConnection(stored, signal);
|
|
36211
|
+
return stored;
|
|
36212
|
+
};
|
|
36213
|
+
importLegacyConnection = async (legacyStateDirectory, channelId, signal) => {
|
|
36214
|
+
const normalizedChannelId = validateIdentifier(channelId, "invalid_channel_id");
|
|
36215
|
+
const legacyPath = join15(resolve4(legacyStateDirectory), "connections", `${normalizedChannelId}.json`);
|
|
36216
|
+
const legacy = decodeLegacyConnection(
|
|
36217
|
+
await readJsonFile(legacyPath, signal, "connection_not_found"),
|
|
36218
|
+
normalizedChannelId
|
|
36219
|
+
);
|
|
36220
|
+
const stored = new ImportedLegacyRuntimeConnection(
|
|
36221
|
+
this.applicationId,
|
|
36222
|
+
this.installationId,
|
|
36223
|
+
connectionId(),
|
|
36224
|
+
legacy.channelId,
|
|
36225
|
+
legacy.defaultWorkspace,
|
|
36226
|
+
legacy.relayOrigin,
|
|
36227
|
+
legacy.runtimeCredential
|
|
36228
|
+
);
|
|
36229
|
+
await this.writeConnection(stored, signal);
|
|
36230
|
+
return stored;
|
|
36231
|
+
};
|
|
36232
|
+
writeConnection = async (stored, signal) => {
|
|
36233
|
+
signal.throwIfAborted();
|
|
36234
|
+
try {
|
|
36235
|
+
await this.#readConnectionForChannel(stored.channelId, signal);
|
|
36236
|
+
throw new RuntimeInstallationStoreError(
|
|
36237
|
+
"connection_conflict",
|
|
36238
|
+
"A Runtime connection for this channel already exists in this installation"
|
|
36239
|
+
);
|
|
36240
|
+
} catch (cause) {
|
|
36241
|
+
if (!(cause instanceof RuntimeInstallationStoreError) || cause.code !== "connection_not_found") {
|
|
36242
|
+
throw cause;
|
|
36243
|
+
}
|
|
36244
|
+
}
|
|
36245
|
+
const connectionPath = this.connectionPath(stored.connectionId);
|
|
36246
|
+
if (stored instanceof VerifiedRuntimeConnection) {
|
|
36247
|
+
await writeJsonAtomically(
|
|
36248
|
+
connectionPath,
|
|
36249
|
+
{
|
|
36250
|
+
applicationId: stored.applicationId,
|
|
36251
|
+
channelId: stored.channelId,
|
|
36252
|
+
connectionId: stored.connectionId,
|
|
36253
|
+
defaultWorkspace: stored.defaultWorkspace,
|
|
36254
|
+
installationId: stored.installationId,
|
|
36255
|
+
kind: stored.kind,
|
|
36256
|
+
relayOrigin: stored.relayOrigin.toString(),
|
|
36257
|
+
runtimeCredential: stored.runtimeCredential,
|
|
36258
|
+
runtimeId: stored.runtimeId,
|
|
36259
|
+
version: 1
|
|
36260
|
+
},
|
|
36261
|
+
signal
|
|
36262
|
+
);
|
|
36263
|
+
} else {
|
|
36264
|
+
await writeJsonAtomically(
|
|
36265
|
+
connectionPath,
|
|
36266
|
+
{
|
|
36267
|
+
applicationId: stored.applicationId,
|
|
36268
|
+
channelId: stored.channelId,
|
|
36269
|
+
connectionId: stored.connectionId,
|
|
36270
|
+
defaultWorkspace: stored.defaultWorkspace,
|
|
36271
|
+
installationId: stored.installationId,
|
|
36272
|
+
kind: stored.kind,
|
|
36273
|
+
relayOrigin: stored.relayOrigin.toString(),
|
|
36274
|
+
runtimeCredential: stored.runtimeCredential,
|
|
36275
|
+
version: 1
|
|
36276
|
+
},
|
|
36277
|
+
signal
|
|
36278
|
+
);
|
|
36279
|
+
}
|
|
36280
|
+
await writeJsonAtomically(
|
|
36281
|
+
this.channelIndexPath(stored.channelId),
|
|
36282
|
+
{
|
|
36283
|
+
applicationId: this.applicationId,
|
|
36284
|
+
channelId: stored.channelId,
|
|
36285
|
+
connectionId: stored.connectionId,
|
|
36286
|
+
installationId: this.installationId,
|
|
36287
|
+
version: 1
|
|
36288
|
+
},
|
|
36289
|
+
signal
|
|
36290
|
+
);
|
|
36291
|
+
};
|
|
36292
|
+
};
|
|
36293
|
+
async function readOrCreateInstallationId(applicationDirectory, signal) {
|
|
36294
|
+
const pointerPath = join15(applicationDirectory, "current.json");
|
|
36295
|
+
try {
|
|
36296
|
+
return decodeInstallationPointer(await readJsonFile(pointerPath, signal, "installation_not_found")).installationId;
|
|
36297
|
+
} catch (cause) {
|
|
36298
|
+
if (!(cause instanceof RuntimeInstallationStoreError) || cause.code !== "installation_not_found") {
|
|
36299
|
+
throw cause;
|
|
36300
|
+
}
|
|
36301
|
+
}
|
|
36302
|
+
const candidate = installationId();
|
|
36303
|
+
try {
|
|
36304
|
+
await writeFile2(pointerPath, `${JSON.stringify({ installationId: candidate, version: 1 })}
|
|
36305
|
+
`, {
|
|
36306
|
+
flag: "wx",
|
|
36307
|
+
mode: 384
|
|
36308
|
+
});
|
|
36309
|
+
return candidate;
|
|
36310
|
+
} catch (cause) {
|
|
36311
|
+
if (!isNodeError(cause, "EEXIST")) {
|
|
36312
|
+
throw new RuntimeInstallationStoreError(
|
|
36313
|
+
"installation_unavailable",
|
|
36314
|
+
"The local installation cannot be initialized",
|
|
36315
|
+
{
|
|
36316
|
+
cause
|
|
36317
|
+
}
|
|
36318
|
+
);
|
|
36319
|
+
}
|
|
36320
|
+
return decodeInstallationPointer(await readJsonFile(pointerPath, signal, "installation_not_found")).installationId;
|
|
36321
|
+
}
|
|
36322
|
+
}
|
|
36323
|
+
async function openRuntimeInstallationStore(options, signal) {
|
|
36324
|
+
return await RuntimeInstallationStore.open(options, signal);
|
|
36325
|
+
}
|
|
36326
|
+
|
|
35768
36327
|
// src/pairing/pair-local-machine.ts
|
|
35769
36328
|
var PAIRING_TIMEOUT_MILLISECONDS = 2e4;
|
|
35770
36329
|
var PAIRING_CODE_PATTERN = /^[A-HJ-NP-Z2-9]{4}(?:-[A-HJ-NP-Z2-9]{4}){4}$/;
|
|
35771
|
-
var
|
|
36330
|
+
var IDENTIFIER_PATTERN5 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
35772
36331
|
var TOKEN_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
35773
|
-
var MAX_CONNECTION_FILE_LENGTH = 16 * 1024;
|
|
35774
36332
|
var CLAIM_RESPONSE_KEYS = ["channelId", "daemonToken", "runtimeId"];
|
|
35775
36333
|
var REDEEM_RESPONSE_KEYS = ["channelId", "runtimeCredential", "runtimeId"];
|
|
35776
|
-
var
|
|
35777
|
-
var SAVED_CONNECTION_KEYS = ["defaultWorkspace", "channelId", "relayOrigin", "runtimeCredential"];
|
|
36334
|
+
var MOBIUS_CLI_APPLICATION_ID = "dev.mobius.cli";
|
|
35778
36335
|
var PairingClientError = class extends Error {
|
|
35779
36336
|
code;
|
|
35780
36337
|
constructor(code, message, options = {}) {
|
|
@@ -35783,10 +36340,10 @@ var PairingClientError = class extends Error {
|
|
|
35783
36340
|
this.name = "PairingClientError";
|
|
35784
36341
|
}
|
|
35785
36342
|
};
|
|
35786
|
-
function
|
|
36343
|
+
function isRecord9(value) {
|
|
35787
36344
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
35788
36345
|
}
|
|
35789
|
-
function
|
|
36346
|
+
function hasExactKeys2(value, expectedKeys) {
|
|
35790
36347
|
const keys = Object.keys(value);
|
|
35791
36348
|
return keys.length === expectedKeys.length && expectedKeys.every((key) => Object.hasOwn(value, key));
|
|
35792
36349
|
}
|
|
@@ -35816,7 +36373,7 @@ function assertKnownArguments(arguments_) {
|
|
|
35816
36373
|
}
|
|
35817
36374
|
}
|
|
35818
36375
|
}
|
|
35819
|
-
function
|
|
36376
|
+
function parseRelayOrigin2(value) {
|
|
35820
36377
|
let url2;
|
|
35821
36378
|
try {
|
|
35822
36379
|
url2 = new URL(value);
|
|
@@ -35847,35 +36404,68 @@ function parsePairingCode(value) {
|
|
|
35847
36404
|
}
|
|
35848
36405
|
return code;
|
|
35849
36406
|
}
|
|
35850
|
-
function parsePairCommand(arguments_) {
|
|
36407
|
+
function parsePairCommand(arguments_, defaultWorkspace) {
|
|
35851
36408
|
assertKnownArguments(arguments_);
|
|
35852
36409
|
return {
|
|
35853
36410
|
code: parsePairingCode(readSingleOption(arguments_, "--code")),
|
|
35854
36411
|
pairingId: arguments_.includes("--pairing") ? validatePairingId(readSingleOption(arguments_, "--pairing")) : "",
|
|
35855
|
-
relayOrigin:
|
|
35856
|
-
workspace: arguments_.includes("--workspace") ? readSingleOption(arguments_, "--workspace") :
|
|
36412
|
+
relayOrigin: parseRelayOrigin2(readSingleOption(arguments_, "--url")),
|
|
36413
|
+
workspace: arguments_.includes("--workspace") ? readSingleOption(arguments_, "--workspace") : defaultWorkspace
|
|
35857
36414
|
};
|
|
35858
36415
|
}
|
|
35859
36416
|
function validatePairingId(value) {
|
|
35860
|
-
if (!
|
|
36417
|
+
if (!IDENTIFIER_PATTERN5.test(value)) {
|
|
35861
36418
|
throw new PairingClientError("invalid_pairing_id", "The Runtime pairing ID is invalid");
|
|
35862
36419
|
}
|
|
35863
36420
|
return value;
|
|
35864
36421
|
}
|
|
35865
|
-
|
|
35866
|
-
|
|
35867
|
-
|
|
36422
|
+
var ResumeCommandTarget = class {
|
|
36423
|
+
};
|
|
36424
|
+
var ConnectionResumeCommandTarget = class extends ResumeCommandTarget {
|
|
36425
|
+
connectionId;
|
|
36426
|
+
constructor(connectionId2) {
|
|
36427
|
+
super();
|
|
36428
|
+
this.connectionId = connectionId2;
|
|
36429
|
+
}
|
|
36430
|
+
resume = async (installation, signal, environment) => await resumeMobiusRuntime(installation, this.connectionId, signal, environment);
|
|
36431
|
+
};
|
|
36432
|
+
var LegacyChannelResumeCommandTarget = class extends ResumeCommandTarget {
|
|
36433
|
+
channelId;
|
|
36434
|
+
constructor(channelId) {
|
|
36435
|
+
super();
|
|
36436
|
+
this.channelId = channelId;
|
|
36437
|
+
}
|
|
36438
|
+
resume = async (installation, signal, environment) => await resumeLegacyChannel(installation, this.channelId, signal, environment);
|
|
36439
|
+
};
|
|
36440
|
+
function parseResumeArgument(arguments_) {
|
|
36441
|
+
if (arguments_.length !== 2) {
|
|
36442
|
+
throw new PairingClientError(
|
|
36443
|
+
"invalid_arguments",
|
|
36444
|
+
"Usage: mobius start --connection <connection-id> or mobius start --channel <legacy-channel-id>"
|
|
36445
|
+
);
|
|
36446
|
+
}
|
|
36447
|
+
const value = arguments_[1] ?? "";
|
|
36448
|
+
if (arguments_[0] === "--connection") {
|
|
36449
|
+
if (!/^mcn_[a-f0-9]{32}$/.test(value)) {
|
|
36450
|
+
throw new PairingClientError("invalid_connection_id", "The saved Runtime connection ID is invalid");
|
|
36451
|
+
}
|
|
36452
|
+
return new ConnectionResumeCommandTarget(value);
|
|
35868
36453
|
}
|
|
35869
|
-
|
|
35870
|
-
|
|
35871
|
-
|
|
36454
|
+
if (arguments_[0] === "--channel") {
|
|
36455
|
+
if (!IDENTIFIER_PATTERN5.test(value)) {
|
|
36456
|
+
throw new PairingClientError("invalid_channel_id", "The saved channel ID is invalid");
|
|
36457
|
+
}
|
|
36458
|
+
return new LegacyChannelResumeCommandTarget(value);
|
|
35872
36459
|
}
|
|
35873
|
-
|
|
36460
|
+
throw new PairingClientError(
|
|
36461
|
+
"invalid_arguments",
|
|
36462
|
+
"Usage: mobius start --connection <connection-id> or mobius start --channel <legacy-channel-id>"
|
|
36463
|
+
);
|
|
35874
36464
|
}
|
|
35875
36465
|
async function resolveDefaultWorkspace(path2) {
|
|
35876
|
-
const requestedWorkspace =
|
|
36466
|
+
const requestedWorkspace = resolve5(path2);
|
|
35877
36467
|
try {
|
|
35878
|
-
await
|
|
36468
|
+
await mkdir4(requestedWorkspace, { recursive: true, mode: 448 });
|
|
35879
36469
|
const defaultWorkspace = await realpath7(requestedWorkspace);
|
|
35880
36470
|
const metadata = await stat6(defaultWorkspace);
|
|
35881
36471
|
if (!metadata.isDirectory()) {
|
|
@@ -35906,9 +36496,9 @@ async function readJsonResponse(response) {
|
|
|
35906
36496
|
}
|
|
35907
36497
|
}
|
|
35908
36498
|
function readRelayError(value) {
|
|
35909
|
-
if (
|
|
36499
|
+
if (isRecord9(value)) {
|
|
35910
36500
|
const error62 = value["error"];
|
|
35911
|
-
if (
|
|
36501
|
+
if (isRecord9(error62)) {
|
|
35912
36502
|
const code = error62["code"];
|
|
35913
36503
|
const message = error62["message"];
|
|
35914
36504
|
if (typeof code === "string" && typeof message === "string") {
|
|
@@ -35919,13 +36509,13 @@ function readRelayError(value) {
|
|
|
35919
36509
|
return new PairingClientError("pairing_failed", "The relay could not pair this machine");
|
|
35920
36510
|
}
|
|
35921
36511
|
function decodePairingResponse(value, credentialField, expectedKeys) {
|
|
35922
|
-
if (!
|
|
36512
|
+
if (!isRecord9(value) || !hasExactKeys2(value, expectedKeys)) {
|
|
35923
36513
|
throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
|
|
35924
36514
|
}
|
|
35925
36515
|
const channelId = value["channelId"];
|
|
35926
36516
|
const runtimeCredential2 = value[credentialField];
|
|
35927
36517
|
const runtimeId = value["runtimeId"];
|
|
35928
|
-
if (typeof channelId !== "string" || !
|
|
36518
|
+
if (typeof channelId !== "string" || !IDENTIFIER_PATTERN5.test(channelId) || typeof runtimeCredential2 !== "string" || !TOKEN_PATTERN.test(runtimeCredential2) || typeof runtimeId !== "string" || !IDENTIFIER_PATTERN5.test(runtimeId)) {
|
|
35929
36519
|
throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
|
|
35930
36520
|
}
|
|
35931
36521
|
return { channelId, runtimeCredential: runtimeCredential2, runtimeId };
|
|
@@ -35965,157 +36555,117 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
|
|
|
35965
36555
|
}
|
|
35966
36556
|
return options.pairingId.length > 0 ? decodePairingResponse(value, "runtimeCredential", REDEEM_RESPONSE_KEYS) : decodePairingResponse(value, "daemonToken", CLAIM_RESPONSE_KEYS);
|
|
35967
36557
|
}
|
|
35968
|
-
async function persistConnection(channelId, relayOrigin, runtimeCredential2, defaultWorkspace, environment) {
|
|
35969
|
-
const connectionsDirectory = join15(readStateDirectory(environment), "connections");
|
|
35970
|
-
await mkdir3(connectionsDirectory, { mode: 448, recursive: true });
|
|
35971
|
-
const connectionPath = join15(connectionsDirectory, `${channelId}.json`);
|
|
35972
|
-
const temporaryPath = join15(connectionsDirectory, `.${channelId}.${randomUUID()}.tmp`);
|
|
35973
|
-
await writeFile2(
|
|
35974
|
-
temporaryPath,
|
|
35975
|
-
`${JSON.stringify(
|
|
35976
|
-
{
|
|
35977
|
-
defaultWorkspace,
|
|
35978
|
-
channelId,
|
|
35979
|
-
relayOrigin: relayOrigin.toString(),
|
|
35980
|
-
runtimeCredential: runtimeCredential2
|
|
35981
|
-
},
|
|
35982
|
-
null,
|
|
35983
|
-
2
|
|
35984
|
-
)}
|
|
35985
|
-
`,
|
|
35986
|
-
{ flag: "wx", mode: 384 }
|
|
35987
|
-
);
|
|
35988
|
-
await rename3(temporaryPath, connectionPath);
|
|
35989
|
-
return connectionPath;
|
|
35990
|
-
}
|
|
35991
|
-
function decodeSavedConnection(value, expectedChannelId) {
|
|
35992
|
-
if (!isRecord8(value) || !hasExactKeys(value, SAVED_CONNECTION_KEYS) && !hasExactKeys(value, LEGACY_SAVED_CONNECTION_KEYS)) {
|
|
35993
|
-
throw new PairingClientError("invalid_connection", "The saved connection is invalid");
|
|
35994
|
-
}
|
|
35995
|
-
const defaultWorkspace = value["defaultWorkspace"];
|
|
35996
|
-
const channelId = value["channelId"];
|
|
35997
|
-
const runtimeCredential2 = value["runtimeCredential"] ?? value["daemonToken"];
|
|
35998
|
-
const relayOrigin = value["relayOrigin"];
|
|
35999
|
-
if (typeof defaultWorkspace !== "string" || typeof channelId !== "string" || channelId !== expectedChannelId || !IDENTIFIER_PATTERN4.test(channelId) || typeof runtimeCredential2 !== "string" || !TOKEN_PATTERN.test(runtimeCredential2) || typeof relayOrigin !== "string") {
|
|
36000
|
-
throw new PairingClientError("invalid_connection", "The saved connection is invalid");
|
|
36001
|
-
}
|
|
36002
|
-
return {
|
|
36003
|
-
defaultWorkspace,
|
|
36004
|
-
channelId,
|
|
36005
|
-
relayOrigin: parseRelayOrigin(relayOrigin),
|
|
36006
|
-
runtimeCredential: runtimeCredential2
|
|
36007
|
-
};
|
|
36008
|
-
}
|
|
36009
|
-
async function readSavedConnection(channelId, environment) {
|
|
36010
|
-
const connectionPath = join15(readStateDirectory(environment), "connections", `${channelId}.json`);
|
|
36011
|
-
let encoded = "";
|
|
36012
|
-
const handle = await open5(connectionPath, "r");
|
|
36013
|
-
try {
|
|
36014
|
-
const metadata = await handle.stat();
|
|
36015
|
-
if (!metadata.isFile() || metadata.size > MAX_CONNECTION_FILE_LENGTH) {
|
|
36016
|
-
throw new PairingClientError("invalid_connection", "The saved connection is invalid");
|
|
36017
|
-
}
|
|
36018
|
-
encoded = await handle.readFile({ encoding: "utf8" });
|
|
36019
|
-
} finally {
|
|
36020
|
-
await handle.close();
|
|
36021
|
-
}
|
|
36022
|
-
let value;
|
|
36023
|
-
try {
|
|
36024
|
-
value = JSON.parse(encoded);
|
|
36025
|
-
} catch (error62) {
|
|
36026
|
-
throw new PairingClientError("invalid_connection", "The saved connection is invalid", { cause: error62 });
|
|
36027
|
-
}
|
|
36028
|
-
const connection = decodeSavedConnection(value, channelId);
|
|
36029
|
-
return {
|
|
36030
|
-
defaultWorkspace: await resolveDefaultWorkspace(connection.defaultWorkspace),
|
|
36031
|
-
channelId: connection.channelId,
|
|
36032
|
-
relayOrigin: connection.relayOrigin,
|
|
36033
|
-
runtimeCredential: connection.runtimeCredential
|
|
36034
|
-
};
|
|
36035
|
-
}
|
|
36036
36558
|
function assertInventoryUsable(inventory) {
|
|
36037
36559
|
if (inventory.available.length + inventory.installable.length === 0) {
|
|
36038
36560
|
throw new PairingClientError("no_supported_agent", "No supported Agent is available for local discovery");
|
|
36039
36561
|
}
|
|
36040
36562
|
}
|
|
36041
|
-
function buildPairedDaemon(connection,
|
|
36563
|
+
function buildPairedDaemon(installation, connection, defaultWorkspace, inventory, localContext) {
|
|
36042
36564
|
assertInventoryUsable(inventory);
|
|
36043
36565
|
const relayUrl = mobiusApiUrl(connection.relayOrigin, "/v1/runtimes/connect");
|
|
36044
36566
|
relayUrl.protocol = relayUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
36045
36567
|
relayUrl.searchParams.set("token", connection.runtimeCredential);
|
|
36046
|
-
const auditDatabasePath = join15(readStateDirectory(environment), "audit", `${connection.channelId}.sqlite`);
|
|
36047
36568
|
return {
|
|
36048
36569
|
channelUrl: new URL(`/channels/${encodeURIComponent(connection.channelId)}`, connection.relayOrigin).toString(),
|
|
36570
|
+
connectionId: connection.connectionId,
|
|
36049
36571
|
config: createDaemonConfig(
|
|
36050
36572
|
{
|
|
36051
|
-
defaultWorkspace
|
|
36052
|
-
auditDatabasePath,
|
|
36573
|
+
defaultWorkspace,
|
|
36574
|
+
auditDatabasePath: installation.auditDatabasePath(connection.connectionId),
|
|
36053
36575
|
channelId: connection.channelId,
|
|
36054
36576
|
relayUrl
|
|
36055
36577
|
},
|
|
36056
36578
|
inventory.readyAgents(),
|
|
36057
|
-
inventory.installable
|
|
36579
|
+
inventory.installable,
|
|
36580
|
+
localContext,
|
|
36581
|
+
new OpaqueDaemonReconnectTarget(connection.connectionId)
|
|
36058
36582
|
),
|
|
36059
|
-
connectionPath
|
|
36583
|
+
connectionPath: installation.connectionPath(connection.connectionId)
|
|
36060
36584
|
};
|
|
36061
36585
|
}
|
|
36062
|
-
async function pairRuntime(options, signal, environment) {
|
|
36586
|
+
async function pairRuntime(installation, options, signal, environment) {
|
|
36587
|
+
const localContext = new DaemonLocalContext(installation.stateDirectory, environment);
|
|
36063
36588
|
const defaultWorkspace = await resolveDefaultWorkspace(options.workspace);
|
|
36064
36589
|
const inventory = await discoverLocalAgentInventory({
|
|
36065
36590
|
defaultWorkspace,
|
|
36066
|
-
environment,
|
|
36591
|
+
environment: localContext.environment,
|
|
36067
36592
|
signal
|
|
36068
36593
|
});
|
|
36069
36594
|
assertInventoryUsable(inventory);
|
|
36070
36595
|
const agents = inventory.readyAgents();
|
|
36071
36596
|
const claim2 = await claimPairing(options, defaultWorkspace, agents, inventory.installable, signal);
|
|
36072
|
-
const
|
|
36073
|
-
claim2.channelId,
|
|
36074
|
-
options.relayOrigin,
|
|
36075
|
-
claim2.runtimeCredential,
|
|
36076
|
-
defaultWorkspace,
|
|
36077
|
-
environment
|
|
36078
|
-
);
|
|
36079
|
-
return buildPairedDaemon(
|
|
36597
|
+
const connection = await installation.saveConnection(
|
|
36080
36598
|
{
|
|
36081
|
-
defaultWorkspace,
|
|
36082
36599
|
channelId: claim2.channelId,
|
|
36600
|
+
defaultWorkspace,
|
|
36083
36601
|
relayOrigin: options.relayOrigin,
|
|
36084
|
-
runtimeCredential: claim2.runtimeCredential
|
|
36602
|
+
runtimeCredential: claim2.runtimeCredential,
|
|
36603
|
+
runtimeId: claim2.runtimeId
|
|
36085
36604
|
},
|
|
36086
|
-
|
|
36087
|
-
inventory,
|
|
36088
|
-
environment
|
|
36605
|
+
signal
|
|
36089
36606
|
);
|
|
36607
|
+
return buildPairedDaemon(installation, connection, defaultWorkspace, inventory, localContext);
|
|
36090
36608
|
}
|
|
36091
|
-
async function pairMobiusRuntime(options, signal, environment = process.env) {
|
|
36609
|
+
async function pairMobiusRuntime(installation, options, signal, environment = process.env) {
|
|
36092
36610
|
return await pairRuntime(
|
|
36611
|
+
installation,
|
|
36093
36612
|
{
|
|
36094
36613
|
code: parsePairingCode(options.pairingCode),
|
|
36095
36614
|
pairingId: validatePairingId(options.pairingId),
|
|
36096
|
-
relayOrigin:
|
|
36615
|
+
relayOrigin: parseRelayOrigin2(options.relayOrigin),
|
|
36097
36616
|
workspace: options.defaultWorkspace
|
|
36098
36617
|
},
|
|
36099
36618
|
signal,
|
|
36100
36619
|
environment
|
|
36101
36620
|
);
|
|
36102
36621
|
}
|
|
36103
|
-
async function
|
|
36104
|
-
|
|
36105
|
-
|
|
36106
|
-
async function resumeMobiusRuntime(channelId, signal, environment = process.env) {
|
|
36107
|
-
const normalizedChannelId = validatePairingId(channelId);
|
|
36108
|
-
const connectionPath = join15(readStateDirectory(environment), "connections", `${normalizedChannelId}.json`);
|
|
36109
|
-
const connection = await readSavedConnection(normalizedChannelId, environment);
|
|
36622
|
+
async function resumeRuntimeConnection(installation, connection, signal, environment) {
|
|
36623
|
+
const localContext = new DaemonLocalContext(installation.stateDirectory, environment);
|
|
36624
|
+
const defaultWorkspace = await resolveDefaultWorkspace(connection.defaultWorkspace);
|
|
36110
36625
|
const inventory = await discoverLocalAgentInventory({
|
|
36111
|
-
defaultWorkspace
|
|
36112
|
-
environment,
|
|
36626
|
+
defaultWorkspace,
|
|
36627
|
+
environment: localContext.environment,
|
|
36113
36628
|
signal
|
|
36114
36629
|
});
|
|
36115
|
-
return buildPairedDaemon(connection,
|
|
36630
|
+
return buildPairedDaemon(installation, connection, defaultWorkspace, inventory, localContext);
|
|
36631
|
+
}
|
|
36632
|
+
async function resumeMobiusRuntime(installation, connectionId2, signal, environment = process.env) {
|
|
36633
|
+
const connection = await installation.readConnection(connectionId2, signal);
|
|
36634
|
+
return await resumeRuntimeConnection(installation, connection, signal, environment);
|
|
36635
|
+
}
|
|
36636
|
+
async function resumeLegacyChannel(installation, channelId, signal, environment) {
|
|
36637
|
+
const connection = await installation.migrateLegacyConnection(readStateDirectory(environment), channelId, signal);
|
|
36638
|
+
return await resumeRuntimeConnection(installation, connection, signal, environment);
|
|
36639
|
+
}
|
|
36640
|
+
async function openMobiusCliInstallation(signal, environment) {
|
|
36641
|
+
return await openRuntimeInstallationStore(
|
|
36642
|
+
{
|
|
36643
|
+
applicationId: MOBIUS_CLI_APPLICATION_ID,
|
|
36644
|
+
stateDirectory: readStateDirectory(environment)
|
|
36645
|
+
},
|
|
36646
|
+
signal
|
|
36647
|
+
);
|
|
36648
|
+
}
|
|
36649
|
+
async function pairLocalMachine(arguments_, signal = new AbortController().signal) {
|
|
36650
|
+
const requested = parsePairCommand(arguments_, "");
|
|
36651
|
+
const installation = await openMobiusCliInstallation(signal, process.env);
|
|
36652
|
+
const localContext = new DaemonLocalContext(installation.stateDirectory, process.env);
|
|
36653
|
+
return await pairRuntime(
|
|
36654
|
+
installation,
|
|
36655
|
+
{
|
|
36656
|
+
code: requested.code,
|
|
36657
|
+
pairingId: requested.pairingId,
|
|
36658
|
+
relayOrigin: requested.relayOrigin,
|
|
36659
|
+
workspace: arguments_.includes("--workspace") ? requested.workspace : loadDefaultWorkspace(localContext.environment)
|
|
36660
|
+
},
|
|
36661
|
+
signal,
|
|
36662
|
+
process.env
|
|
36663
|
+
);
|
|
36116
36664
|
}
|
|
36117
36665
|
async function resumeLocalMachine(arguments_, signal = new AbortController().signal) {
|
|
36118
|
-
|
|
36666
|
+
const target = parseResumeArgument(arguments_);
|
|
36667
|
+
const installation = await openMobiusCliInstallation(signal, process.env);
|
|
36668
|
+
return await target.resume(installation, signal, process.env);
|
|
36119
36669
|
}
|
|
36120
36670
|
|
|
36121
36671
|
// src/run-daemon.ts
|
|
@@ -36468,7 +37018,7 @@ var AgentInstallationManager = class {
|
|
|
36468
37018
|
|
|
36469
37019
|
// src/agent-installation/fixed-installation-executor.ts
|
|
36470
37020
|
import { realpathSync as realpathSync2, statSync as statSync2 } from "node:fs";
|
|
36471
|
-
import { resolve as
|
|
37021
|
+
import { resolve as resolve6 } from "node:path";
|
|
36472
37022
|
function findSpecification(specifications, agentId) {
|
|
36473
37023
|
for (const specification of specifications) {
|
|
36474
37024
|
if (specification.id === agentId) {
|
|
@@ -36479,7 +37029,7 @@ function findSpecification(specifications, agentId) {
|
|
|
36479
37029
|
}
|
|
36480
37030
|
function resolveDefaultWorkspace2(path2) {
|
|
36481
37031
|
try {
|
|
36482
|
-
const directory = realpathSync2(
|
|
37032
|
+
const directory = realpathSync2(resolve6(path2));
|
|
36483
37033
|
if (!statSync2(directory).isDirectory()) {
|
|
36484
37034
|
throw new Error("Default workspace is not a directory");
|
|
36485
37035
|
}
|
|
@@ -36494,7 +37044,7 @@ function resolveDefaultWorkspace2(path2) {
|
|
|
36494
37044
|
}
|
|
36495
37045
|
function resolveIntegrationStateDirectory(path2) {
|
|
36496
37046
|
try {
|
|
36497
|
-
const directory = realpathSync2(
|
|
37047
|
+
const directory = realpathSync2(resolve6(path2));
|
|
36498
37048
|
const metadata = statSync2(directory);
|
|
36499
37049
|
if (!metadata.isDirectory() || typeof process.getuid === "function" && metadata.uid !== process.getuid()) {
|
|
36500
37050
|
throw new Error("Installation directory is not user-owned");
|
|
@@ -36749,7 +37299,7 @@ async function streamLocalFile(command, send2, signal) {
|
|
|
36749
37299
|
}
|
|
36750
37300
|
|
|
36751
37301
|
// src/artifacts/runtime-artifact-uploader.ts
|
|
36752
|
-
import { createHash as
|
|
37302
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
36753
37303
|
|
|
36754
37304
|
// ../mobius-sdk/src/errors.ts
|
|
36755
37305
|
var MobiusError = class extends Error {
|
|
@@ -36774,15 +37324,15 @@ var MobiusValidationError = class extends MobiusError {
|
|
|
36774
37324
|
};
|
|
36775
37325
|
|
|
36776
37326
|
// ../mobius-sdk/src/resources.ts
|
|
36777
|
-
var
|
|
37327
|
+
var IDENTIFIER_PATTERN6 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
36778
37328
|
function invalidResponse(message) {
|
|
36779
37329
|
return new MobiusProtocolError(message);
|
|
36780
37330
|
}
|
|
36781
|
-
function
|
|
37331
|
+
function isRecord10(value) {
|
|
36782
37332
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36783
37333
|
}
|
|
36784
37334
|
function record3(value, name) {
|
|
36785
|
-
if (!
|
|
37335
|
+
if (!isRecord10(value)) {
|
|
36786
37336
|
throw invalidResponse(`The service returned an invalid ${name}`);
|
|
36787
37337
|
}
|
|
36788
37338
|
return value;
|
|
@@ -36796,7 +37346,7 @@ function stringField(value, field, maximumLength = 85e5) {
|
|
|
36796
37346
|
}
|
|
36797
37347
|
function identifierField(value, field) {
|
|
36798
37348
|
const candidate = stringField(value, field, 128);
|
|
36799
|
-
if (!
|
|
37349
|
+
if (!IDENTIFIER_PATTERN6.test(candidate)) {
|
|
36800
37350
|
throw invalidResponse(`The service returned an invalid ${field}`);
|
|
36801
37351
|
}
|
|
36802
37352
|
return candidate;
|
|
@@ -37068,7 +37618,7 @@ async function uploadRuntimeArtifact(config2, sessionId, artifact, signal) {
|
|
|
37068
37618
|
artifact.name,
|
|
37069
37619
|
artifact.mimeType,
|
|
37070
37620
|
artifact.bytes.byteLength,
|
|
37071
|
-
|
|
37621
|
+
createHash3("sha256").update(artifact.bytes).digest("hex")
|
|
37072
37622
|
);
|
|
37073
37623
|
} catch (cause) {
|
|
37074
37624
|
translateSdkError(cause);
|
|
@@ -37136,7 +37686,7 @@ async function uploadRuntimeArtifact(config2, sessionId, artifact, signal) {
|
|
|
37136
37686
|
// src/authorization/workspace-directory.ts
|
|
37137
37687
|
import { readdir as readdir2, realpath as realpath9, stat as stat8 } from "node:fs/promises";
|
|
37138
37688
|
import { homedir as homedir2 } from "node:os";
|
|
37139
|
-
import { basename as basename5, dirname as
|
|
37689
|
+
import { basename as basename5, dirname as dirname6, isAbsolute as isAbsolute10, join as join16, normalize as normalize4, relative as relative4 } from "node:path";
|
|
37140
37690
|
var WorkspaceDirectoryListing = class {
|
|
37141
37691
|
directoryId;
|
|
37142
37692
|
directoryLabel;
|
|
@@ -37260,7 +37810,7 @@ var WorkspaceDirectoryService = class {
|
|
|
37260
37810
|
}
|
|
37261
37811
|
}
|
|
37262
37812
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
37263
|
-
const parent =
|
|
37813
|
+
const parent = dirname6(target);
|
|
37264
37814
|
return new WorkspaceDirectoryListing(
|
|
37265
37815
|
id,
|
|
37266
37816
|
this.label(target),
|
|
@@ -37952,13 +38502,13 @@ var NativeSessionService = class {
|
|
|
37952
38502
|
};
|
|
37953
38503
|
|
|
37954
38504
|
// src/prompt-artifact-resolver.ts
|
|
37955
|
-
import { createHash as
|
|
38505
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
37956
38506
|
import { fetch as fetch5 } from "undici";
|
|
37957
38507
|
var ARTIFACT_SCHEME = "mobius-artifact:";
|
|
37958
38508
|
var ARTIFACT_DOWNLOAD_TIMEOUT_MILLISECONDS = 2e4;
|
|
37959
38509
|
var MAX_AGENT_IMAGE_BASE64_LENGTH = 4e6;
|
|
37960
38510
|
var MAX_AGENT_RESOURCE_BYTE_LENGTH = 1e6;
|
|
37961
|
-
var
|
|
38511
|
+
var IDENTIFIER_PATTERN7 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
37962
38512
|
var PromptArtifactError = class extends Error {
|
|
37963
38513
|
code;
|
|
37964
38514
|
constructor(code, message, options = {}) {
|
|
@@ -38001,7 +38551,7 @@ function parseReference(resource) {
|
|
|
38001
38551
|
const encodedByteLength2 = url2.searchParams.get("byteLength") ?? "";
|
|
38002
38552
|
const sha256 = url2.searchParams.get("sha256") ?? "";
|
|
38003
38553
|
const byteLength = Number(encodedByteLength2);
|
|
38004
|
-
if (url2.protocol !== ARTIFACT_SCHEME || url2.hash.length > 0 || resource.type !== "link" || resource.text.length > 0 || !
|
|
38554
|
+
if (url2.protocol !== ARTIFACT_SCHEME || url2.hash.length > 0 || resource.type !== "link" || resource.text.length > 0 || !IDENTIFIER_PATTERN7.test(artifactId) || keys.length !== 2 || keys[0] !== "byteLength" || keys[1] !== "sha256" || !/^[1-9][0-9]*$/.test(encodedByteLength2) || !Number.isSafeInteger(byteLength) || !/^[a-f0-9]{64}$/.test(sha256)) {
|
|
38005
38555
|
throw new PromptArtifactError("artifact_reference_invalid", "The prompt artifact reference is invalid");
|
|
38006
38556
|
}
|
|
38007
38557
|
return new PromptArtifactReference(artifactId, byteLength, sha256, resource);
|
|
@@ -38091,7 +38641,7 @@ async function download(config2, command, reference, signal) {
|
|
|
38091
38641
|
);
|
|
38092
38642
|
}
|
|
38093
38643
|
const bytes = await responseBytes(response, reference.byteLength, requestSignal);
|
|
38094
|
-
if (
|
|
38644
|
+
if (createHash4("sha256").update(bytes).digest("hex") !== reference.sha256) {
|
|
38095
38645
|
throw new PromptArtifactError(
|
|
38096
38646
|
"artifact_integrity_failed",
|
|
38097
38647
|
"The prompt artifact failed integrity validation"
|
|
@@ -38181,7 +38731,7 @@ var RelayConnectionError = class extends Error {
|
|
|
38181
38731
|
};
|
|
38182
38732
|
function connectRelay(url2, signal) {
|
|
38183
38733
|
signal.throwIfAborted();
|
|
38184
|
-
return new Promise((
|
|
38734
|
+
return new Promise((resolve8, reject) => {
|
|
38185
38735
|
const endpoint = new URL(url2);
|
|
38186
38736
|
const headers = runtimeAuthorization(endpoint);
|
|
38187
38737
|
endpoint.searchParams.delete("token");
|
|
@@ -38244,7 +38794,7 @@ function connectRelay(url2, signal) {
|
|
|
38244
38794
|
}
|
|
38245
38795
|
finished = true;
|
|
38246
38796
|
cleanup();
|
|
38247
|
-
|
|
38797
|
+
resolve8(socket);
|
|
38248
38798
|
};
|
|
38249
38799
|
function onTimeout() {
|
|
38250
38800
|
fail(
|
|
@@ -38505,7 +39055,7 @@ var RelayConnectionLiveness = class {
|
|
|
38505
39055
|
|
|
38506
39056
|
// src/relay-connection/session-event-outbox.ts
|
|
38507
39057
|
import { mkdirSync as mkdirSync3 } from "node:fs";
|
|
38508
|
-
import { dirname as
|
|
39058
|
+
import { dirname as dirname7 } from "node:path";
|
|
38509
39059
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
38510
39060
|
var DEFAULT_OUTBOX_LIMITS = {
|
|
38511
39061
|
criticalEventBytes: 136 * 1024 * 1024,
|
|
@@ -38571,7 +39121,7 @@ var SessionEventOutbox = class {
|
|
|
38571
39121
|
constructor(path2, limits = DEFAULT_OUTBOX_LIMITS) {
|
|
38572
39122
|
validateLimits(limits);
|
|
38573
39123
|
this.#limits = limits;
|
|
38574
|
-
mkdirSync3(
|
|
39124
|
+
mkdirSync3(dirname7(path2), { recursive: true });
|
|
38575
39125
|
this.#database = new DatabaseSync3(path2);
|
|
38576
39126
|
this.#database.exec(`
|
|
38577
39127
|
CREATE TABLE IF NOT EXISTS relay_session_event_outbox (
|
|
@@ -40242,12 +40792,12 @@ function waitForRelayRetry(signal, timer) {
|
|
|
40242
40792
|
if (signal.aborted) {
|
|
40243
40793
|
return Promise.resolve();
|
|
40244
40794
|
}
|
|
40245
|
-
return new Promise((
|
|
40795
|
+
return new Promise((resolve8) => {
|
|
40246
40796
|
const retry = timer.schedule(finish, RELAY_RECONNECT_DELAY_MILLISECONDS);
|
|
40247
40797
|
function finish() {
|
|
40248
40798
|
retry.cancel();
|
|
40249
40799
|
signal.removeEventListener("abort", finish);
|
|
40250
|
-
|
|
40800
|
+
resolve8();
|
|
40251
40801
|
}
|
|
40252
40802
|
signal.addEventListener("abort", finish, { once: true });
|
|
40253
40803
|
});
|
|
@@ -40303,7 +40853,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40303
40853
|
installationObserver.connect(socket);
|
|
40304
40854
|
onConnected();
|
|
40305
40855
|
try {
|
|
40306
|
-
await new Promise((
|
|
40856
|
+
await new Promise((resolve8, reject) => {
|
|
40307
40857
|
let finished = false;
|
|
40308
40858
|
const cleanup = () => {
|
|
40309
40859
|
connectionLiveness.close();
|
|
@@ -40321,7 +40871,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40321
40871
|
}
|
|
40322
40872
|
finished = true;
|
|
40323
40873
|
cleanup();
|
|
40324
|
-
|
|
40874
|
+
resolve8();
|
|
40325
40875
|
};
|
|
40326
40876
|
const rejectConnection = (failure2) => {
|
|
40327
40877
|
if (finished) {
|
|
@@ -40768,7 +41318,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40768
41318
|
try {
|
|
40769
41319
|
operationSignal.throwIfAborted();
|
|
40770
41320
|
if (previous2.length > 0) {
|
|
40771
|
-
await new Promise((
|
|
41321
|
+
await new Promise((resolve9, reject2) => {
|
|
40772
41322
|
const cancel = () => reject2(operationSignal.reason);
|
|
40773
41323
|
operationSignal.addEventListener("abort", cancel, {
|
|
40774
41324
|
once: true
|
|
@@ -40776,7 +41326,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40776
41326
|
void Promise.all(previous2.map((request) => request.completion)).then(
|
|
40777
41327
|
() => {
|
|
40778
41328
|
operationSignal.removeEventListener("abort", cancel);
|
|
40779
|
-
|
|
41329
|
+
resolve9();
|
|
40780
41330
|
},
|
|
40781
41331
|
(error62) => {
|
|
40782
41332
|
operationSignal.removeEventListener("abort", cancel);
|
|
@@ -40850,13 +41400,13 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40850
41400
|
try {
|
|
40851
41401
|
operationSignal.throwIfAborted();
|
|
40852
41402
|
if (previous2.length > 0) {
|
|
40853
|
-
await new Promise((
|
|
41403
|
+
await new Promise((resolve9, reject2) => {
|
|
40854
41404
|
const cancel = () => reject2(operationSignal.reason);
|
|
40855
41405
|
operationSignal.addEventListener("abort", cancel, { once: true });
|
|
40856
41406
|
void Promise.all(previous2.map((request) => request.completion)).then(
|
|
40857
41407
|
() => {
|
|
40858
41408
|
operationSignal.removeEventListener("abort", cancel);
|
|
40859
|
-
|
|
41409
|
+
resolve9();
|
|
40860
41410
|
},
|
|
40861
41411
|
(error62) => {
|
|
40862
41412
|
operationSignal.removeEventListener("abort", cancel);
|
|
@@ -41111,13 +41661,13 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41111
41661
|
}
|
|
41112
41662
|
async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
41113
41663
|
const installationAudit = new AuditInstallationEvents(audit);
|
|
41114
|
-
const stateDirectory =
|
|
41664
|
+
const stateDirectory = config2.localContext.stateDirectory;
|
|
41115
41665
|
const specifications = supportedLocalAgentSpecifications();
|
|
41116
41666
|
const installationExecutor = new FixedInstallationExecutor({
|
|
41117
41667
|
defaultWorkspace: config2.defaultWorkspace,
|
|
41118
41668
|
audit: installationAudit,
|
|
41119
41669
|
catalog: config2.catalog,
|
|
41120
|
-
environment:
|
|
41670
|
+
environment: config2.localContext.environment,
|
|
41121
41671
|
publishCatalog: async (installationSignal) => await publishAgentCatalog(config2, installationSignal),
|
|
41122
41672
|
stateDirectory
|
|
41123
41673
|
});
|
|
@@ -41176,10 +41726,10 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
41176
41726
|
return;
|
|
41177
41727
|
}
|
|
41178
41728
|
connectionAnnounced = true;
|
|
41179
|
-
const reconnectCommand = `npx --yes @moxt-ai/mobius start
|
|
41729
|
+
const reconnectCommand = `npx --yes @moxt-ai/mobius start ${config2.reconnectTarget.commandArgument}`;
|
|
41180
41730
|
process.stdout.write("Mobius daemon connected to the relay.\n\n");
|
|
41181
41731
|
process.stdout.write(
|
|
41182
|
-
`${styleText(["bold", "yellow"], `Reconnect this
|
|
41732
|
+
`${styleText(["bold", "yellow"], `Reconnect this local connection later:
|
|
41183
41733
|
${reconnectCommand}`)}
|
|
41184
41734
|
|
|
41185
41735
|
`
|
|
@@ -41261,10 +41811,10 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
41261
41811
|
}
|
|
41262
41812
|
|
|
41263
41813
|
// src/runtime.ts
|
|
41264
|
-
import { mkdir as
|
|
41265
|
-
import { dirname as
|
|
41266
|
-
var
|
|
41267
|
-
var
|
|
41814
|
+
import { mkdir as mkdir5, realpath as realpath10, stat as stat9 } from "node:fs/promises";
|
|
41815
|
+
import { dirname as dirname8, join as join17, resolve as resolve7 } from "node:path";
|
|
41816
|
+
var IDENTIFIER_PATTERN8 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
41817
|
+
var RUNTIME_CREDENTIAL_PATTERN2 = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
41268
41818
|
var MobiusRuntimeConfigurationError = class extends Error {
|
|
41269
41819
|
code = "runtime_configuration_invalid";
|
|
41270
41820
|
constructor(message, options = {}) {
|
|
@@ -41288,7 +41838,7 @@ function validateRuntimeRelay(relayUrl) {
|
|
|
41288
41838
|
if (credential.length === 0) {
|
|
41289
41839
|
throw new MobiusRuntimeConfigurationError("The Runtime relay credential is required");
|
|
41290
41840
|
}
|
|
41291
|
-
if (!
|
|
41841
|
+
if (!RUNTIME_CREDENTIAL_PATTERN2.test(credential)) {
|
|
41292
41842
|
throw new MobiusRuntimeConfigurationError("The Runtime relay credential is invalid");
|
|
41293
41843
|
}
|
|
41294
41844
|
}
|
|
@@ -41315,7 +41865,7 @@ function relayUrlFromConnection(connection) {
|
|
|
41315
41865
|
}
|
|
41316
41866
|
function loadMobiusRuntimeConnection(environment = process.env) {
|
|
41317
41867
|
const channelId = requiredEnvironmentValue(environment, "MOBIUS_CHANNEL_ID");
|
|
41318
|
-
if (!
|
|
41868
|
+
if (!IDENTIFIER_PATTERN8.test(channelId)) {
|
|
41319
41869
|
throw new MobiusRuntimeConfigurationError("MOBIUS_CHANNEL_ID is invalid");
|
|
41320
41870
|
}
|
|
41321
41871
|
return Object.freeze({
|
|
@@ -41327,9 +41877,9 @@ function loadMobiusRuntimeConnection(environment = process.env) {
|
|
|
41327
41877
|
});
|
|
41328
41878
|
}
|
|
41329
41879
|
async function resolveWorkspace(path2) {
|
|
41330
|
-
const requested =
|
|
41880
|
+
const requested = resolve7(path2);
|
|
41331
41881
|
try {
|
|
41332
|
-
await
|
|
41882
|
+
await mkdir5(requested, { recursive: true, mode: 448 });
|
|
41333
41883
|
const resolved = await realpath10(requested);
|
|
41334
41884
|
const metadata = await stat9(resolved);
|
|
41335
41885
|
if (!metadata.isDirectory()) {
|
|
@@ -41345,13 +41895,14 @@ async function resolveWorkspace(path2) {
|
|
|
41345
41895
|
}
|
|
41346
41896
|
async function createMobiusRuntimeEngine(connection, signal, environment = process.env) {
|
|
41347
41897
|
signal.throwIfAborted();
|
|
41898
|
+
const localContext = new DaemonLocalContext(readStateDirectory(environment), environment);
|
|
41348
41899
|
const relayUrl = relayUrlFromConnection(connection);
|
|
41349
41900
|
const defaultWorkspace = await resolveWorkspace(connection.defaultWorkspace);
|
|
41350
|
-
const auditDatabasePath =
|
|
41351
|
-
await
|
|
41901
|
+
const auditDatabasePath = resolve7(connection.auditDatabasePath);
|
|
41902
|
+
await mkdir5(dirname8(auditDatabasePath), { recursive: true, mode: 448 });
|
|
41352
41903
|
const inventory = await discoverLocalAgentInventory({
|
|
41353
41904
|
defaultWorkspace,
|
|
41354
|
-
environment,
|
|
41905
|
+
environment: localContext.environment,
|
|
41355
41906
|
signal
|
|
41356
41907
|
});
|
|
41357
41908
|
if (inventory.available.length + inventory.installable.length === 0) {
|
|
@@ -41366,7 +41917,8 @@ async function createMobiusRuntimeEngine(connection, signal, environment = proce
|
|
|
41366
41917
|
relayUrl
|
|
41367
41918
|
},
|
|
41368
41919
|
inventory.readyAgents(),
|
|
41369
|
-
inventory.installable
|
|
41920
|
+
inventory.installable,
|
|
41921
|
+
localContext
|
|
41370
41922
|
)
|
|
41371
41923
|
);
|
|
41372
41924
|
}
|
|
@@ -41395,14 +41947,24 @@ var MobiusRuntimeEngine = class {
|
|
|
41395
41947
|
export {
|
|
41396
41948
|
AcpExecutionError,
|
|
41397
41949
|
AuditStore,
|
|
41950
|
+
ChannelDaemonReconnectTarget,
|
|
41951
|
+
DaemonLocalContext,
|
|
41952
|
+
DaemonReconnectTarget,
|
|
41953
|
+
ImportedLegacyRuntimeConnection,
|
|
41398
41954
|
LocalAuthorizationError,
|
|
41399
41955
|
MobiusRuntimeConfigurationError,
|
|
41400
41956
|
MobiusRuntimeEngine,
|
|
41957
|
+
OpaqueDaemonReconnectTarget,
|
|
41401
41958
|
PairingClientError,
|
|
41959
|
+
RuntimeInstallationStore,
|
|
41960
|
+
RuntimeInstallationStoreError,
|
|
41961
|
+
StoredRuntimeConnection,
|
|
41962
|
+
VerifiedRuntimeConnection,
|
|
41402
41963
|
createAcpClient,
|
|
41403
41964
|
createMobiusRuntimeEngine,
|
|
41404
41965
|
loadDaemonConfig,
|
|
41405
41966
|
loadMobiusRuntimeConnection,
|
|
41967
|
+
openRuntimeInstallationStore,
|
|
41406
41968
|
pairLocalMachine,
|
|
41407
41969
|
pairMobiusRuntime,
|
|
41408
41970
|
resumeLocalMachine,
|