@moxt-ai/mobius 0.0.193 → 0.0.194
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/agent-runtime-manager.js +1 -1
- package/dist/acp/agent-runtime-manager.js.map +1 -1
- package/dist/acp/agent-session.js +2 -2
- package/dist/acp/agent-session.js.map +1 -1
- package/dist/acp/native-session.d.ts +1 -0
- package/dist/acp/native-session.d.ts.map +1 -1
- package/dist/agent-catalog/agents/workbuddy-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/workbuddy-agent.js +5 -19
- package/dist/agent-catalog/agents/workbuddy-agent.js.map +1 -1
- package/dist/agent-catalog/discover-agent-settings.d.ts.map +1 -1
- package/dist/agent-catalog/discover-agent-settings.js +2 -1
- package/dist/agent-catalog/discover-agent-settings.js.map +1 -1
- package/dist/agent-catalog/resolve-catalog-agent.d.ts +15 -0
- package/dist/agent-catalog/resolve-catalog-agent.d.ts.map +1 -0
- package/dist/agent-catalog/resolve-catalog-agent.js +65 -0
- package/dist/agent-catalog/resolve-catalog-agent.js.map +1 -0
- package/dist/agent-installation/grok-managed-package.d.ts.map +1 -1
- package/dist/agent-installation/grok-managed-package.js +5 -16
- package/dist/agent-installation/grok-managed-package.js.map +1 -1
- package/dist/agent-installation/opencode-managed-release.d.ts.map +1 -1
- package/dist/agent-installation/opencode-managed-release.js +9 -16
- package/dist/agent-installation/opencode-managed-release.js.map +1 -1
- package/dist/cli.js +862 -748
- package/dist/cli.js.map +4 -4
- package/dist/config.d.ts +7 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -1
- package/dist/config.js.map +1 -1
- package/dist/daemon-history-commands.d.ts.map +1 -1
- package/dist/daemon-history-commands.js +3 -2
- package/dist/daemon-history-commands.js.map +1 -1
- package/dist/daemon-prompt-executor.d.ts.map +1 -1
- package/dist/daemon-prompt-executor.js +2 -1
- package/dist/daemon-prompt-executor.js.map +1 -1
- package/dist/daemon-session-commands.d.ts +2 -1
- package/dist/daemon-session-commands.d.ts.map +1 -1
- package/dist/daemon-session-commands.js +6 -2
- package/dist/daemon-session-commands.js.map +1 -1
- package/dist/index.js +867 -744
- package/dist/index.js.map +4 -4
- package/dist/native-sessions/service.d.ts.map +1 -1
- package/dist/native-sessions/service.js +5 -2
- package/dist/native-sessions/service.js.map +1 -1
- package/dist/pairing/pair-local-machine.d.ts.map +1 -1
- package/dist/pairing/pair-local-machine.js +12 -5
- package/dist/pairing/pair-local-machine.js.map +1 -1
- package/dist/platform/contracts.d.ts +26 -0
- package/dist/platform/contracts.d.ts.map +1 -0
- package/dist/platform/contracts.js +2 -0
- package/dist/platform/contracts.js.map +1 -0
- package/dist/platform/index.d.ts +3 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/index.js +21 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/platform/linux.d.ts +3 -0
- package/dist/platform/linux.d.ts.map +1 -0
- package/dist/platform/linux.js +146 -0
- package/dist/platform/linux.js.map +1 -0
- package/dist/platform/macos.d.ts +3 -0
- package/dist/platform/macos.d.ts.map +1 -0
- package/dist/platform/macos.js +49 -0
- package/dist/platform/macos.js.map +1 -0
- package/dist/platform/posix.d.ts +4 -0
- package/dist/platform/posix.d.ts.map +1 -0
- package/dist/platform/posix.js +47 -0
- package/dist/platform/posix.js.map +1 -0
- package/dist/process/executable.d.ts +2 -4
- package/dist/process/executable.d.ts.map +1 -1
- package/dist/process/executable.js +11 -166
- package/dist/process/executable.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +885 -762
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
// src/cli.ts
|
|
9
|
-
import { constants as
|
|
9
|
+
import { constants as constants3 } from "node:fs";
|
|
10
10
|
import { mkdir as mkdir7, open as open6 } from "node:fs/promises";
|
|
11
11
|
import { resolve as resolve8 } from "node:path";
|
|
12
12
|
|
|
@@ -3381,7 +3381,7 @@ var program = new Command();
|
|
|
3381
3381
|
// package.json
|
|
3382
3382
|
var package_default = {
|
|
3383
3383
|
name: "@moxt-ai/mobius",
|
|
3384
|
-
version: "0.0.
|
|
3384
|
+
version: "0.0.194",
|
|
3385
3385
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
3386
3386
|
type: "module",
|
|
3387
3387
|
bin: {
|
|
@@ -3505,15 +3505,266 @@ function normalizeAcpCapabilities(initialized) {
|
|
|
3505
3505
|
}
|
|
3506
3506
|
|
|
3507
3507
|
// src/process/executable.ts
|
|
3508
|
-
import {
|
|
3508
|
+
import { spawn } from "node:child_process";
|
|
3509
|
+
import { constants as constants2 } from "node:fs";
|
|
3510
|
+
import { access as access2, realpath as realpath2, stat as stat2 } from "node:fs/promises";
|
|
3511
|
+
import { join as join3, resolve } from "node:path";
|
|
3512
|
+
|
|
3513
|
+
// src/platform/linux.ts
|
|
3509
3514
|
import { constants, readdirSync, readFileSync } from "node:fs";
|
|
3510
3515
|
import { access, readdir, readFile, realpath, stat } from "node:fs/promises";
|
|
3511
|
-
import { join
|
|
3516
|
+
import { join } from "node:path";
|
|
3517
|
+
|
|
3518
|
+
// src/platform/posix.ts
|
|
3519
|
+
import { execFile } from "node:child_process";
|
|
3520
|
+
var PROCESS_TABLE_TIMEOUT_MILLISECONDS = 1e3;
|
|
3521
|
+
var PROCESS_TABLE_OUTPUT_LIMIT_BYTES = 1024 * 1024;
|
|
3522
|
+
function parseProcessTable(output2) {
|
|
3523
|
+
const entries = [];
|
|
3524
|
+
for (const line of output2.split("\n")) {
|
|
3525
|
+
const groups = /^\s*(?<pid>\d+)\s+(?<ppid>\d+)\s+(?<pgid>\d+)\s*$/.exec(line)?.groups;
|
|
3526
|
+
if (groups === void 0) {
|
|
3527
|
+
continue;
|
|
3528
|
+
}
|
|
3529
|
+
const processId = Number(groups["pid"]);
|
|
3530
|
+
const parentProcessId = Number(groups["ppid"]);
|
|
3531
|
+
const processGroupId = Number(groups["pgid"]);
|
|
3532
|
+
if (!Number.isSafeInteger(processId) || processId <= 0 || !Number.isSafeInteger(parentProcessId) || parentProcessId < 0 || !Number.isSafeInteger(processGroupId) || processGroupId <= 0) {
|
|
3533
|
+
continue;
|
|
3534
|
+
}
|
|
3535
|
+
entries.push({ parentProcessId, processGroupId, processId });
|
|
3536
|
+
}
|
|
3537
|
+
return entries;
|
|
3538
|
+
}
|
|
3539
|
+
function readProcessTableWithPs(executable) {
|
|
3540
|
+
return new Promise((resolveTable) => {
|
|
3541
|
+
execFile(
|
|
3542
|
+
executable,
|
|
3543
|
+
["-axo", "pid=,ppid=,pgid="],
|
|
3544
|
+
{
|
|
3545
|
+
encoding: "utf8",
|
|
3546
|
+
maxBuffer: PROCESS_TABLE_OUTPUT_LIMIT_BYTES,
|
|
3547
|
+
signal: AbortSignal.timeout(PROCESS_TABLE_TIMEOUT_MILLISECONDS),
|
|
3548
|
+
timeout: PROCESS_TABLE_TIMEOUT_MILLISECONDS
|
|
3549
|
+
},
|
|
3550
|
+
(error62, stdout) => {
|
|
3551
|
+
resolveTable(error62 === null ? parseProcessTable(stdout) : []);
|
|
3552
|
+
}
|
|
3553
|
+
);
|
|
3554
|
+
});
|
|
3555
|
+
}
|
|
3556
|
+
function processExists(processId) {
|
|
3557
|
+
try {
|
|
3558
|
+
process.kill(processId, 0);
|
|
3559
|
+
return true;
|
|
3560
|
+
} catch {
|
|
3561
|
+
return false;
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
|
|
3565
|
+
// src/platform/linux.ts
|
|
3566
|
+
function appendLinuxProcessTableEntry(entries, processId, encoded) {
|
|
3567
|
+
const closingParenthesis = encoded.lastIndexOf(")");
|
|
3568
|
+
if (!encoded.startsWith(`${processId.toString()} (`) || closingParenthesis < 0) {
|
|
3569
|
+
return;
|
|
3570
|
+
}
|
|
3571
|
+
const fields = encoded.slice(closingParenthesis + 1).trim().split(/\s+/);
|
|
3572
|
+
const parentProcessId = Number(fields[1]);
|
|
3573
|
+
const processGroupId = Number(fields[2]);
|
|
3574
|
+
if (!Number.isSafeInteger(parentProcessId) || parentProcessId < 0 || !Number.isSafeInteger(processGroupId) || processGroupId <= 0) {
|
|
3575
|
+
return;
|
|
3576
|
+
}
|
|
3577
|
+
entries.push({ parentProcessId, processGroupId, processId });
|
|
3578
|
+
}
|
|
3579
|
+
async function readLinuxProcessTable() {
|
|
3580
|
+
const entries = [];
|
|
3581
|
+
try {
|
|
3582
|
+
const directories = await readdir("/proc", { withFileTypes: true });
|
|
3583
|
+
for (const directory of directories) {
|
|
3584
|
+
if (!directory.isDirectory() || !/^\d+$/.test(directory.name)) {
|
|
3585
|
+
continue;
|
|
3586
|
+
}
|
|
3587
|
+
const processId = Number(directory.name);
|
|
3588
|
+
if (!Number.isSafeInteger(processId) || processId <= 0) {
|
|
3589
|
+
continue;
|
|
3590
|
+
}
|
|
3591
|
+
try {
|
|
3592
|
+
appendLinuxProcessTableEntry(
|
|
3593
|
+
entries,
|
|
3594
|
+
processId,
|
|
3595
|
+
await readFile(join("/proc", directory.name, "stat"), "utf8")
|
|
3596
|
+
);
|
|
3597
|
+
} catch {
|
|
3598
|
+
}
|
|
3599
|
+
}
|
|
3600
|
+
} catch {
|
|
3601
|
+
}
|
|
3602
|
+
return entries;
|
|
3603
|
+
}
|
|
3604
|
+
function readLinuxProcessTableSynchronously() {
|
|
3605
|
+
const entries = [];
|
|
3606
|
+
try {
|
|
3607
|
+
const directories = readdirSync("/proc", { withFileTypes: true });
|
|
3608
|
+
for (const directory of directories) {
|
|
3609
|
+
if (!directory.isDirectory() || !/^\d+$/.test(directory.name)) {
|
|
3610
|
+
continue;
|
|
3611
|
+
}
|
|
3612
|
+
const processId = Number(directory.name);
|
|
3613
|
+
if (!Number.isSafeInteger(processId) || processId <= 0) {
|
|
3614
|
+
continue;
|
|
3615
|
+
}
|
|
3616
|
+
try {
|
|
3617
|
+
appendLinuxProcessTableEntry(
|
|
3618
|
+
entries,
|
|
3619
|
+
processId,
|
|
3620
|
+
readFileSync(join("/proc", directory.name, "stat"), "utf8")
|
|
3621
|
+
);
|
|
3622
|
+
} catch {
|
|
3623
|
+
}
|
|
3624
|
+
}
|
|
3625
|
+
} catch {
|
|
3626
|
+
}
|
|
3627
|
+
return entries;
|
|
3628
|
+
}
|
|
3629
|
+
async function readLinuxProcessTableWithFallback() {
|
|
3630
|
+
const procfsEntries = await readLinuxProcessTable();
|
|
3631
|
+
if (procfsEntries.length > 0) {
|
|
3632
|
+
return procfsEntries;
|
|
3633
|
+
}
|
|
3634
|
+
for (const candidate of ["/usr/bin/ps", "/bin/ps", "/run/current-system/sw/bin/ps"]) {
|
|
3635
|
+
try {
|
|
3636
|
+
const resolvedPath = await realpath(candidate);
|
|
3637
|
+
if (!(await stat(resolvedPath)).isFile()) {
|
|
3638
|
+
continue;
|
|
3639
|
+
}
|
|
3640
|
+
await access(resolvedPath, constants.X_OK);
|
|
3641
|
+
} catch {
|
|
3642
|
+
continue;
|
|
3643
|
+
}
|
|
3644
|
+
const entries = await readProcessTableWithPs(candidate);
|
|
3645
|
+
if (entries.length > 0) {
|
|
3646
|
+
return entries;
|
|
3647
|
+
}
|
|
3648
|
+
}
|
|
3649
|
+
return [];
|
|
3650
|
+
}
|
|
3651
|
+
function processExists2(processId) {
|
|
3652
|
+
try {
|
|
3653
|
+
const encoded = readFileSync(join("/proc", processId.toString(), "stat"), "utf8");
|
|
3654
|
+
const closingParenthesis = encoded.lastIndexOf(")");
|
|
3655
|
+
if (closingParenthesis >= 0) {
|
|
3656
|
+
const processState = encoded.slice(closingParenthesis + 1).trimStart().charAt(0);
|
|
3657
|
+
if (processState === "Z" || processState === "X") {
|
|
3658
|
+
return false;
|
|
3659
|
+
}
|
|
3660
|
+
}
|
|
3661
|
+
} catch {
|
|
3662
|
+
}
|
|
3663
|
+
return processExists(processId);
|
|
3664
|
+
}
|
|
3665
|
+
var linuxPlatform = {
|
|
3666
|
+
readProcessTable: readLinuxProcessTableWithFallback,
|
|
3667
|
+
readProcessTableSynchronously: readLinuxProcessTableSynchronously,
|
|
3668
|
+
processExists: processExists2,
|
|
3669
|
+
workBuddyExecutablePaths: () => [],
|
|
3670
|
+
openCodeArchives: {
|
|
3671
|
+
arm64: {
|
|
3672
|
+
asset: "opencode-linux-arm64.tar.gz",
|
|
3673
|
+
sha256: "70baf769395ca4e7a68924026530c390eace194f3b7e4919d4efcb2aa2eed3c0",
|
|
3674
|
+
format: "tar.gz"
|
|
3675
|
+
},
|
|
3676
|
+
x64: {
|
|
3677
|
+
asset: "opencode-linux-x64.tar.gz",
|
|
3678
|
+
sha256: "ea800b7ff56226b70952126c9fc1e2517ca4c4b5682fd9d3f9e87449697a1194",
|
|
3679
|
+
format: "tar.gz"
|
|
3680
|
+
}
|
|
3681
|
+
},
|
|
3682
|
+
grokDependencies: {
|
|
3683
|
+
arm64: {
|
|
3684
|
+
name: "@xai-official/grok-linux-arm64",
|
|
3685
|
+
integrity: "sha512-Jlwz9XtZPNKz/V/ydifC8OVu3hIZz7pmoStt8c4KCqkSWjWiZ/PBIC0iJiq8rvByhx5Z0EdSyq8ZXVwtocceGA==",
|
|
3686
|
+
tarballUrl: "https://registry.npmjs.org/@xai-official/grok-linux-arm64/-/grok-linux-arm64-1.0.21.tgz"
|
|
3687
|
+
},
|
|
3688
|
+
x64: {
|
|
3689
|
+
name: "@xai-official/grok-linux-x64",
|
|
3690
|
+
integrity: "sha512-AjDV5ifEz5LFG2Jt5IlhAeEkJati/wOvCchVbR4eIj2ogjvmXoXlzBrYRXuAJpXBy5q0se/Yuez5FxDU9Ju81w==",
|
|
3691
|
+
tarballUrl: "https://registry.npmjs.org/@xai-official/grok-linux-x64/-/grok-linux-x64-1.0.21.tgz"
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3694
|
+
};
|
|
3695
|
+
|
|
3696
|
+
// src/platform/macos.ts
|
|
3697
|
+
import { isAbsolute, join as join2 } from "node:path";
|
|
3698
|
+
var WORKBUDDY_MACOS_EXECUTABLE_PATH = Object.freeze([
|
|
3699
|
+
"WorkBuddy.app",
|
|
3700
|
+
"Contents",
|
|
3701
|
+
"Resources",
|
|
3702
|
+
"app.asar.unpacked",
|
|
3703
|
+
"cli",
|
|
3704
|
+
"bin",
|
|
3705
|
+
"codebuddy"
|
|
3706
|
+
]);
|
|
3707
|
+
var macosPlatform = {
|
|
3708
|
+
readProcessTable: () => readProcessTableWithPs("/bin/ps"),
|
|
3709
|
+
readProcessTableSynchronously: () => [],
|
|
3710
|
+
processExists,
|
|
3711
|
+
workBuddyExecutablePaths: (environment) => {
|
|
3712
|
+
const paths = [join2("/Applications", ...WORKBUDDY_MACOS_EXECUTABLE_PATH)];
|
|
3713
|
+
const homeDirectory = environment["HOME"];
|
|
3714
|
+
if (homeDirectory !== void 0 && isAbsolute(homeDirectory)) {
|
|
3715
|
+
paths.unshift(join2(homeDirectory, "Applications", ...WORKBUDDY_MACOS_EXECUTABLE_PATH));
|
|
3716
|
+
}
|
|
3717
|
+
return paths;
|
|
3718
|
+
},
|
|
3719
|
+
openCodeArchives: {
|
|
3720
|
+
arm64: {
|
|
3721
|
+
asset: "opencode-darwin-arm64.zip",
|
|
3722
|
+
sha256: "fe764f7f360c584a83e18dd5f23fb1a6b2725f5ee8854b0252fe558f7798e946",
|
|
3723
|
+
format: "zip"
|
|
3724
|
+
},
|
|
3725
|
+
x64: {
|
|
3726
|
+
asset: "opencode-darwin-x64.zip",
|
|
3727
|
+
sha256: "9858853e7bacdbbd22c2d70c377e009dc4b354dd04f5588705411e7afb89fd2d",
|
|
3728
|
+
format: "zip"
|
|
3729
|
+
}
|
|
3730
|
+
},
|
|
3731
|
+
grokDependencies: {
|
|
3732
|
+
arm64: {
|
|
3733
|
+
name: "@xai-official/grok-darwin-arm64",
|
|
3734
|
+
integrity: "sha512-I4pKZGnR6Mv4MJOJsB9B/i2o0ODF4eZtp4jHN5feoTqKIeAUVg38OzBtE8aN/wZa7Xg+qhnf6Jd1tcAFvMoFtQ==",
|
|
3735
|
+
tarballUrl: "https://registry.npmjs.org/@xai-official/grok-darwin-arm64/-/grok-darwin-arm64-1.0.21.tgz"
|
|
3736
|
+
},
|
|
3737
|
+
x64: {
|
|
3738
|
+
name: "@xai-official/grok-darwin-x64",
|
|
3739
|
+
integrity: "sha512-h0nFj3NZ9Kz8w6fQ6UDxxeSIhC1WjwwoRE92iNbG//tZy6YGkppR3s7oRVtt4Xl0CJANKUt0EusyIYnnAvKLzw==",
|
|
3740
|
+
tarballUrl: "https://registry.npmjs.org/@xai-official/grok-darwin-x64/-/grok-darwin-x64-1.0.21.tgz"
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
};
|
|
3744
|
+
|
|
3745
|
+
// src/platform/index.ts
|
|
3746
|
+
var fallbackPlatform = {
|
|
3747
|
+
readProcessTable: () => readProcessTableWithPs("/usr/bin/ps"),
|
|
3748
|
+
readProcessTableSynchronously: () => [],
|
|
3749
|
+
processExists,
|
|
3750
|
+
workBuddyExecutablePaths: () => [],
|
|
3751
|
+
openCodeArchives: {},
|
|
3752
|
+
grokDependencies: {}
|
|
3753
|
+
};
|
|
3754
|
+
var platforms = /* @__PURE__ */ new Map([
|
|
3755
|
+
["linux", linuxPlatform],
|
|
3756
|
+
["darwin", macosPlatform],
|
|
3757
|
+
["win32", { ...fallbackPlatform, readProcessTable: () => Promise.resolve([]) }]
|
|
3758
|
+
]);
|
|
3759
|
+
function platformSupportFor(platform) {
|
|
3760
|
+
return platforms.get(platform) ?? fallbackPlatform;
|
|
3761
|
+
}
|
|
3762
|
+
|
|
3763
|
+
// src/process/executable.ts
|
|
3764
|
+
var hostPlatform = platformSupportFor(process.platform);
|
|
3512
3765
|
var DEFAULT_OUTPUT_LIMIT_BYTES = 16 * 1024;
|
|
3513
3766
|
var PROCESS_GRACEFUL_STOP_TIMEOUT_MILLISECONDS = 1e3;
|
|
3514
3767
|
var PROCESS_FORCED_STOP_TIMEOUT_MILLISECONDS = 5e3;
|
|
3515
|
-
var PROCESS_TABLE_TIMEOUT_MILLISECONDS = 1e3;
|
|
3516
|
-
var PROCESS_TABLE_OUTPUT_LIMIT_BYTES = 1024 * 1024;
|
|
3517
3768
|
var PROCESS_EXIT_CHECK_ATTEMPTS = 16;
|
|
3518
3769
|
var GRACEFUL_STOP_SIGNAL = 15;
|
|
3519
3770
|
var FORCED_STOP_SIGNAL = 9;
|
|
@@ -3572,13 +3823,13 @@ function executableExtensions(executableName, environment, platform) {
|
|
|
3572
3823
|
async function resolveExecutablePath(requestedPath2, platform = process.platform) {
|
|
3573
3824
|
const absoluteRequestedPath = resolve(requestedPath2);
|
|
3574
3825
|
try {
|
|
3575
|
-
const resolvedPath = await
|
|
3576
|
-
const metadata = await
|
|
3826
|
+
const resolvedPath = await realpath2(absoluteRequestedPath);
|
|
3827
|
+
const metadata = await stat2(resolvedPath);
|
|
3577
3828
|
if (!metadata.isFile()) {
|
|
3578
3829
|
return null;
|
|
3579
3830
|
}
|
|
3580
3831
|
if (platform !== "win32") {
|
|
3581
|
-
await
|
|
3832
|
+
await access2(resolvedPath, constants2.X_OK);
|
|
3582
3833
|
}
|
|
3583
3834
|
return new ResolvedExecutable(
|
|
3584
3835
|
new ExecutableIdentity(
|
|
@@ -3603,7 +3854,7 @@ async function findExecutableOnPath(executableName, environment, platform = proc
|
|
|
3603
3854
|
continue;
|
|
3604
3855
|
}
|
|
3605
3856
|
for (const extension of extensions) {
|
|
3606
|
-
const requestedPath2 = resolve(
|
|
3857
|
+
const requestedPath2 = resolve(join3(entry, `${executableName}${extension}`));
|
|
3607
3858
|
const executable = await resolveExecutablePath(requestedPath2, platform);
|
|
3608
3859
|
if (executable !== null) {
|
|
3609
3860
|
return executable;
|
|
@@ -3624,128 +3875,8 @@ function appendBounded(chunks, chunk, currentBytes, limitBytes) {
|
|
|
3624
3875
|
chunks.push(chunk);
|
|
3625
3876
|
return nextBytes;
|
|
3626
3877
|
}
|
|
3627
|
-
function parseProcessTable(output2) {
|
|
3628
|
-
const entries = [];
|
|
3629
|
-
for (const line of output2.split("\n")) {
|
|
3630
|
-
const groups = /^\s*(?<pid>\d+)\s+(?<ppid>\d+)\s+(?<pgid>\d+)\s*$/.exec(line)?.groups;
|
|
3631
|
-
if (groups === void 0) {
|
|
3632
|
-
continue;
|
|
3633
|
-
}
|
|
3634
|
-
const processId = Number(groups["pid"]);
|
|
3635
|
-
const parentProcessId = Number(groups["ppid"]);
|
|
3636
|
-
const processGroupId = Number(groups["pgid"]);
|
|
3637
|
-
if (!Number.isSafeInteger(processId) || processId <= 0 || !Number.isSafeInteger(parentProcessId) || parentProcessId < 0 || !Number.isSafeInteger(processGroupId) || processGroupId <= 0) {
|
|
3638
|
-
continue;
|
|
3639
|
-
}
|
|
3640
|
-
entries.push({ parentProcessId, processGroupId, processId });
|
|
3641
|
-
}
|
|
3642
|
-
return entries;
|
|
3643
|
-
}
|
|
3644
|
-
function appendLinuxProcessTableEntry(entries, processId, encoded) {
|
|
3645
|
-
const closingParenthesis = encoded.lastIndexOf(")");
|
|
3646
|
-
if (!encoded.startsWith(`${processId.toString()} (`) || closingParenthesis < 0) {
|
|
3647
|
-
return;
|
|
3648
|
-
}
|
|
3649
|
-
const fields = encoded.slice(closingParenthesis + 1).trim().split(/\s+/);
|
|
3650
|
-
const parentProcessId = Number(fields[1]);
|
|
3651
|
-
const processGroupId = Number(fields[2]);
|
|
3652
|
-
if (!Number.isSafeInteger(parentProcessId) || parentProcessId < 0 || !Number.isSafeInteger(processGroupId) || processGroupId <= 0) {
|
|
3653
|
-
return;
|
|
3654
|
-
}
|
|
3655
|
-
entries.push({ parentProcessId, processGroupId, processId });
|
|
3656
|
-
}
|
|
3657
|
-
async function readLinuxProcessTable() {
|
|
3658
|
-
const entries = [];
|
|
3659
|
-
try {
|
|
3660
|
-
const directories = await readdir("/proc", { withFileTypes: true });
|
|
3661
|
-
for (const directory of directories) {
|
|
3662
|
-
if (!directory.isDirectory() || !/^\d+$/.test(directory.name)) {
|
|
3663
|
-
continue;
|
|
3664
|
-
}
|
|
3665
|
-
const processId = Number(directory.name);
|
|
3666
|
-
if (!Number.isSafeInteger(processId) || processId <= 0) {
|
|
3667
|
-
continue;
|
|
3668
|
-
}
|
|
3669
|
-
try {
|
|
3670
|
-
appendLinuxProcessTableEntry(
|
|
3671
|
-
entries,
|
|
3672
|
-
processId,
|
|
3673
|
-
await readFile(join("/proc", directory.name, "stat"), "utf8")
|
|
3674
|
-
);
|
|
3675
|
-
} catch {
|
|
3676
|
-
}
|
|
3677
|
-
}
|
|
3678
|
-
} catch {
|
|
3679
|
-
}
|
|
3680
|
-
return entries;
|
|
3681
|
-
}
|
|
3682
|
-
function readLinuxProcessTableSynchronously() {
|
|
3683
|
-
const entries = [];
|
|
3684
|
-
try {
|
|
3685
|
-
const directories = readdirSync("/proc", { withFileTypes: true });
|
|
3686
|
-
for (const directory of directories) {
|
|
3687
|
-
if (!directory.isDirectory() || !/^\d+$/.test(directory.name)) {
|
|
3688
|
-
continue;
|
|
3689
|
-
}
|
|
3690
|
-
const processId = Number(directory.name);
|
|
3691
|
-
if (!Number.isSafeInteger(processId) || processId <= 0) {
|
|
3692
|
-
continue;
|
|
3693
|
-
}
|
|
3694
|
-
try {
|
|
3695
|
-
appendLinuxProcessTableEntry(
|
|
3696
|
-
entries,
|
|
3697
|
-
processId,
|
|
3698
|
-
readFileSync(join("/proc", directory.name, "stat"), "utf8")
|
|
3699
|
-
);
|
|
3700
|
-
} catch {
|
|
3701
|
-
}
|
|
3702
|
-
}
|
|
3703
|
-
} catch {
|
|
3704
|
-
}
|
|
3705
|
-
return entries;
|
|
3706
|
-
}
|
|
3707
|
-
function readProcessTableWithPs(executable) {
|
|
3708
|
-
return new Promise((resolveTable) => {
|
|
3709
|
-
execFile(
|
|
3710
|
-
executable,
|
|
3711
|
-
["-axo", "pid=,ppid=,pgid="],
|
|
3712
|
-
{
|
|
3713
|
-
encoding: "utf8",
|
|
3714
|
-
maxBuffer: PROCESS_TABLE_OUTPUT_LIMIT_BYTES,
|
|
3715
|
-
signal: AbortSignal.timeout(PROCESS_TABLE_TIMEOUT_MILLISECONDS),
|
|
3716
|
-
timeout: PROCESS_TABLE_TIMEOUT_MILLISECONDS
|
|
3717
|
-
},
|
|
3718
|
-
(error62, stdout) => {
|
|
3719
|
-
resolveTable(error62 === null ? parseProcessTable(stdout) : []);
|
|
3720
|
-
}
|
|
3721
|
-
);
|
|
3722
|
-
});
|
|
3723
|
-
}
|
|
3724
|
-
async function readLinuxProcessTableWithFallback() {
|
|
3725
|
-
const procfsEntries = await readLinuxProcessTable();
|
|
3726
|
-
if (procfsEntries.length > 0) {
|
|
3727
|
-
return procfsEntries;
|
|
3728
|
-
}
|
|
3729
|
-
for (const candidate of ["/usr/bin/ps", "/bin/ps", "/run/current-system/sw/bin/ps"]) {
|
|
3730
|
-
const executable = await resolveExecutablePath(candidate);
|
|
3731
|
-
if (executable === null) {
|
|
3732
|
-
continue;
|
|
3733
|
-
}
|
|
3734
|
-
const entries = await readProcessTableWithPs(executable.identity.requestedPath);
|
|
3735
|
-
if (entries.length > 0) {
|
|
3736
|
-
return entries;
|
|
3737
|
-
}
|
|
3738
|
-
}
|
|
3739
|
-
return [];
|
|
3740
|
-
}
|
|
3741
3878
|
function readProcessTable() {
|
|
3742
|
-
|
|
3743
|
-
return Promise.resolve([]);
|
|
3744
|
-
}
|
|
3745
|
-
if (process.platform === "linux") {
|
|
3746
|
-
return readLinuxProcessTableWithFallback();
|
|
3747
|
-
}
|
|
3748
|
-
return readProcessTableWithPs(process.platform === "darwin" ? "/bin/ps" : "/usr/bin/ps");
|
|
3879
|
+
return hostPlatform.readProcessTable();
|
|
3749
3880
|
}
|
|
3750
3881
|
function selectProcessTree(entries, rootProcessId) {
|
|
3751
3882
|
const processIds = /* @__PURE__ */ new Set([rootProcessId]);
|
|
@@ -3782,11 +3913,9 @@ async function captureProcessTree(child2) {
|
|
|
3782
3913
|
if (process.platform === "win32" || child2.pid === void 0) {
|
|
3783
3914
|
return [];
|
|
3784
3915
|
}
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
return selectProcessTree(procfsEntries, child2.pid);
|
|
3789
|
-
}
|
|
3916
|
+
const entries = hostPlatform.readProcessTableSynchronously();
|
|
3917
|
+
if (entries.length > 0) {
|
|
3918
|
+
return selectProcessTree(entries, child2.pid);
|
|
3790
3919
|
}
|
|
3791
3920
|
return selectProcessTree(await readProcessTable(), child2.pid);
|
|
3792
3921
|
}
|
|
@@ -3814,36 +3943,15 @@ function signalCapturedProcessGroups(processes, rootProcessId, signal) {
|
|
|
3814
3943
|
}
|
|
3815
3944
|
}
|
|
3816
3945
|
}
|
|
3817
|
-
function processExists(processId) {
|
|
3818
|
-
if (process.platform === "linux") {
|
|
3819
|
-
try {
|
|
3820
|
-
const encoded = readFileSync(join("/proc", processId.toString(), "stat"), "utf8");
|
|
3821
|
-
const closingParenthesis = encoded.lastIndexOf(")");
|
|
3822
|
-
if (closingParenthesis >= 0) {
|
|
3823
|
-
const processState = encoded.slice(closingParenthesis + 1).trimStart().charAt(0);
|
|
3824
|
-
if (processState === "Z" || processState === "X") {
|
|
3825
|
-
return false;
|
|
3826
|
-
}
|
|
3827
|
-
}
|
|
3828
|
-
} catch {
|
|
3829
|
-
}
|
|
3830
|
-
}
|
|
3831
|
-
try {
|
|
3832
|
-
process.kill(processId, 0);
|
|
3833
|
-
return true;
|
|
3834
|
-
} catch {
|
|
3835
|
-
return false;
|
|
3836
|
-
}
|
|
3837
|
-
}
|
|
3838
3946
|
async function waitForCapturedProcessesExit(processes, rootProcessId) {
|
|
3839
3947
|
const processIds = processes.map((identity2) => identity2.processId).filter((processId) => processId !== rootProcessId);
|
|
3840
3948
|
for (let attempt = 0; attempt < PROCESS_EXIT_CHECK_ATTEMPTS; attempt += 1) {
|
|
3841
|
-
if (processIds.every((processId) => !processExists(processId))) {
|
|
3949
|
+
if (processIds.every((processId) => !hostPlatform.processExists(processId))) {
|
|
3842
3950
|
return true;
|
|
3843
3951
|
}
|
|
3844
3952
|
await readProcessTable();
|
|
3845
3953
|
}
|
|
3846
|
-
return processIds.every((processId) => !processExists(processId));
|
|
3954
|
+
return processIds.every((processId) => !hostPlatform.processExists(processId));
|
|
3847
3955
|
}
|
|
3848
3956
|
function terminateProcess(child2) {
|
|
3849
3957
|
if (child2.exitCode !== null || child2.signalCode !== null || child2.pid === void 0) {
|
|
@@ -4429,8 +4537,8 @@ function formatAgentDiagnostics(inventory, json2, verbose = false) {
|
|
|
4429
4537
|
}
|
|
4430
4538
|
|
|
4431
4539
|
// src/agent-installation/managed-npm-package.ts
|
|
4432
|
-
import { mkdir, mkdtemp, open, realpath as
|
|
4433
|
-
import { delimiter, dirname, isAbsolute, join as
|
|
4540
|
+
import { mkdir, mkdtemp, open, realpath as realpath3, rename, rm, stat as stat3 } from "node:fs/promises";
|
|
4541
|
+
import { delimiter, dirname, isAbsolute as isAbsolute2, join as join4, relative, sep } from "node:path";
|
|
4434
4542
|
var INSTALL_TIMEOUT_MILLISECONDS = 5 * 60 * 1e3;
|
|
4435
4543
|
var PACKAGE_METADATA_LIMIT_BYTES = 64 * 1024;
|
|
4436
4544
|
var PACKAGE_LOCK_LIMIT_BYTES = 8 * 1024 * 1024;
|
|
@@ -4481,11 +4589,11 @@ function isRecord2(value) {
|
|
|
4481
4589
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4482
4590
|
}
|
|
4483
4591
|
function packagePath(root, packageName) {
|
|
4484
|
-
return
|
|
4592
|
+
return join4(root, "node_modules", ...packageName.split("/"));
|
|
4485
4593
|
}
|
|
4486
4594
|
function isContainedPath(root, candidate) {
|
|
4487
4595
|
const difference = relative(root, candidate);
|
|
4488
|
-
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep}`) && !
|
|
4596
|
+
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep}`) && !isAbsolute2(difference);
|
|
4489
4597
|
}
|
|
4490
4598
|
async function readJsonRecord(path3, maximumBytes) {
|
|
4491
4599
|
try {
|
|
@@ -4586,14 +4694,14 @@ function verifyPackageLockEntry(lock, definition, verifyDependencyClosure) {
|
|
|
4586
4694
|
}
|
|
4587
4695
|
}
|
|
4588
4696
|
async function verifyRequiredDependency(rootPath, lock, definition) {
|
|
4589
|
-
const dependencyRoot = await
|
|
4697
|
+
const dependencyRoot = await realpath3(packagePath(rootPath, definition.packageName));
|
|
4590
4698
|
if (!isContainedPath(rootPath, dependencyRoot)) {
|
|
4591
4699
|
throw new ManagedNpmPackageError(
|
|
4592
4700
|
"managed_package_verification_failed",
|
|
4593
4701
|
"The required managed npm dependency escaped its private cache"
|
|
4594
4702
|
);
|
|
4595
4703
|
}
|
|
4596
|
-
const metadata = await readJsonRecord(
|
|
4704
|
+
const metadata = await readJsonRecord(join4(dependencyRoot, "package.json"), PACKAGE_METADATA_LIMIT_BYTES);
|
|
4597
4705
|
if (metadata["name"] !== definition.packageName || metadata["version"] !== definition.version) {
|
|
4598
4706
|
throw new ManagedNpmPackageError(
|
|
4599
4707
|
"managed_package_verification_failed",
|
|
@@ -4615,15 +4723,15 @@ async function validateManagedNpmPackage(root, definition) {
|
|
|
4615
4723
|
}
|
|
4616
4724
|
}
|
|
4617
4725
|
async function validateManagedNpmPackageContents(root, definition) {
|
|
4618
|
-
const rootPath = await
|
|
4619
|
-
const packageRoot = await
|
|
4726
|
+
const rootPath = await realpath3(root);
|
|
4727
|
+
const packageRoot = await realpath3(packagePath(rootPath, definition.packageName));
|
|
4620
4728
|
if (!isContainedPath(rootPath, packageRoot)) {
|
|
4621
4729
|
throw new ManagedNpmPackageError(
|
|
4622
4730
|
"managed_package_verification_failed",
|
|
4623
4731
|
"The managed npm package escaped its private cache"
|
|
4624
4732
|
);
|
|
4625
4733
|
}
|
|
4626
|
-
const metadata = await readJsonRecord(
|
|
4734
|
+
const metadata = await readJsonRecord(join4(packageRoot, "package.json"), PACKAGE_METADATA_LIMIT_BYTES);
|
|
4627
4735
|
if (metadata["name"] !== definition.packageName || metadata["version"] !== definition.version) {
|
|
4628
4736
|
throw new ManagedNpmPackageError(
|
|
4629
4737
|
"managed_package_verification_failed",
|
|
@@ -4631,14 +4739,14 @@ async function validateManagedNpmPackageContents(root, definition) {
|
|
|
4631
4739
|
);
|
|
4632
4740
|
}
|
|
4633
4741
|
if (definition instanceof SriManagedNpmPackageDefinition) {
|
|
4634
|
-
const lock = await readJsonRecord(
|
|
4742
|
+
const lock = await readJsonRecord(join4(rootPath, "package-lock.json"), PACKAGE_LOCK_LIMIT_BYTES);
|
|
4635
4743
|
verifyPackageLockEntry(lock, definition, definition.verifyDependencyClosure);
|
|
4636
4744
|
for (const dependency of definition.requiredDependencies) {
|
|
4637
4745
|
await verifyRequiredDependency(rootPath, lock, dependency);
|
|
4638
4746
|
}
|
|
4639
4747
|
}
|
|
4640
4748
|
const declaredBin = readBinPath(metadata, definition.executableName);
|
|
4641
|
-
const executable = await resolveExecutablePath(
|
|
4749
|
+
const executable = await resolveExecutablePath(join4(packageRoot, declaredBin));
|
|
4642
4750
|
if (executable === null || !isContainedPath(rootPath, executable.path)) {
|
|
4643
4751
|
throw new ManagedNpmPackageError(
|
|
4644
4752
|
"managed_package_verification_failed",
|
|
@@ -4651,7 +4759,7 @@ var ManagedNpmPackageInstaller = class {
|
|
|
4651
4759
|
install = async (root, definition, environment, signal) => {
|
|
4652
4760
|
signal.throwIfAborted();
|
|
4653
4761
|
try {
|
|
4654
|
-
const metadata = await
|
|
4762
|
+
const metadata = await stat3(root);
|
|
4655
4763
|
if (metadata.isDirectory()) {
|
|
4656
4764
|
return await validateManagedNpmPackage(root, definition);
|
|
4657
4765
|
}
|
|
@@ -4662,7 +4770,7 @@ var ManagedNpmPackageInstaller = class {
|
|
|
4662
4770
|
}
|
|
4663
4771
|
const parent = dirname(root);
|
|
4664
4772
|
await mkdir(parent, { mode: 448, recursive: true });
|
|
4665
|
-
const staging = await mkdtemp(
|
|
4773
|
+
const staging = await mkdtemp(join4(parent, `.${definition.version}.staging-`));
|
|
4666
4774
|
try {
|
|
4667
4775
|
const npm = await findExecutableOnPath(process.platform === "win32" ? "npm.cmd" : "npm", environment);
|
|
4668
4776
|
if (npm === null) {
|
|
@@ -4688,9 +4796,9 @@ var ManagedNpmPackageInstaller = class {
|
|
|
4688
4796
|
`${definition.packageName}@${definition.version}`
|
|
4689
4797
|
);
|
|
4690
4798
|
const installEnvironment = {
|
|
4691
|
-
HOME:
|
|
4799
|
+
HOME: join4(staging, "home"),
|
|
4692
4800
|
NPM_CONFIG_AUDIT: "false",
|
|
4693
|
-
NPM_CONFIG_CACHE:
|
|
4801
|
+
NPM_CONFIG_CACHE: join4(staging, ".npm-cache"),
|
|
4694
4802
|
NPM_CONFIG_FUND: "false",
|
|
4695
4803
|
NPM_CONFIG_IGNORE_SCRIPTS: "true",
|
|
4696
4804
|
NPM_CONFIG_PACKAGE_LOCK: "true",
|
|
@@ -4712,8 +4820,8 @@ var ManagedNpmPackageInstaller = class {
|
|
|
4712
4820
|
timeoutMilliseconds: INSTALL_TIMEOUT_MILLISECONDS
|
|
4713
4821
|
});
|
|
4714
4822
|
await Promise.all([
|
|
4715
|
-
rm(
|
|
4716
|
-
rm(
|
|
4823
|
+
rm(join4(staging, ".npm-cache"), { force: true, recursive: true }),
|
|
4824
|
+
rm(join4(staging, "home"), { force: true, recursive: true })
|
|
4717
4825
|
]);
|
|
4718
4826
|
await validateManagedNpmPackage(staging, definition);
|
|
4719
4827
|
try {
|
|
@@ -4749,7 +4857,7 @@ var ManagedNpmPackageInstaller = class {
|
|
|
4749
4857
|
};
|
|
4750
4858
|
|
|
4751
4859
|
// src/agent-catalog/agent-specification.ts
|
|
4752
|
-
import { join as
|
|
4860
|
+
import { join as join5 } from "node:path";
|
|
4753
4861
|
|
|
4754
4862
|
// src/agent-catalog/version-output.ts
|
|
4755
4863
|
function normalizeVersionOutput(output2) {
|
|
@@ -4772,7 +4880,7 @@ var LocalAgentSpecification = class {
|
|
|
4772
4880
|
resolveManagedAgent = async (stateDirectory, platform, signal) => {
|
|
4773
4881
|
signal.throwIfAborted();
|
|
4774
4882
|
const executable = await resolveExecutablePath(
|
|
4775
|
-
|
|
4883
|
+
join5(stateDirectory, ...this.managedAgentExecutablePath),
|
|
4776
4884
|
platform
|
|
4777
4885
|
);
|
|
4778
4886
|
signal.throwIfAborted();
|
|
@@ -4976,7 +5084,7 @@ function sessionFailureMeta(failure2) {
|
|
|
4976
5084
|
import { spawn as spawn2 } from "node:child_process";
|
|
4977
5085
|
|
|
4978
5086
|
// src/acp/codex/app-server-protocol.ts
|
|
4979
|
-
import { isAbsolute as
|
|
5087
|
+
import { isAbsolute as isAbsolute3 } from "node:path";
|
|
4980
5088
|
|
|
4981
5089
|
// ../../node_modules/.pnpm/zod@4.6.5/node_modules/zod/v4/classic/external.js
|
|
4982
5090
|
var external_exports = {};
|
|
@@ -24717,7 +24825,7 @@ var imageGenerationItemSchema = external_exports.object({
|
|
|
24717
24825
|
});
|
|
24718
24826
|
var threadItemSchema = external_exports.discriminatedUnion("type", [
|
|
24719
24827
|
imageGenerationItemSchema,
|
|
24720
|
-
external_exports.object({ type: external_exports.literal("imageView"), id: boundedText(256), path: boundedText(32768).refine(
|
|
24828
|
+
external_exports.object({ type: external_exports.literal("imageView"), id: boundedText(256), path: boundedText(32768).refine(isAbsolute3) }),
|
|
24721
24829
|
external_exports.object({
|
|
24722
24830
|
id: boundedText(256),
|
|
24723
24831
|
text: boundedText(1e6),
|
|
@@ -28652,15 +28760,15 @@ var AgentProbeError = class extends Error {
|
|
|
28652
28760
|
};
|
|
28653
28761
|
|
|
28654
28762
|
// src/agent-catalog/agents/resolve-user-local-executable.ts
|
|
28655
|
-
import { isAbsolute as
|
|
28763
|
+
import { isAbsolute as isAbsolute4, join as join6 } from "node:path";
|
|
28656
28764
|
async function resolveUserLocalExecutable(executableName, context) {
|
|
28657
28765
|
context.signal.throwIfAborted();
|
|
28658
28766
|
const platform = context.platform ?? process.platform;
|
|
28659
28767
|
const homeDirectory = context.environment["HOME"];
|
|
28660
|
-
if (platform === "win32" || homeDirectory === void 0 || !
|
|
28768
|
+
if (platform === "win32" || homeDirectory === void 0 || !isAbsolute4(homeDirectory)) {
|
|
28661
28769
|
return [];
|
|
28662
28770
|
}
|
|
28663
|
-
const executable = await resolveExecutablePath(
|
|
28771
|
+
const executable = await resolveExecutablePath(join6(homeDirectory, ".local", "bin", executableName), platform);
|
|
28664
28772
|
context.signal.throwIfAborted();
|
|
28665
28773
|
return executable === null ? [] : [executable];
|
|
28666
28774
|
}
|
|
@@ -28749,8 +28857,8 @@ var CursorCliAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
28749
28857
|
};
|
|
28750
28858
|
|
|
28751
28859
|
// src/agent-catalog/agents/deepseek-harness-agent.ts
|
|
28752
|
-
import { mkdir as mkdir2, realpath as
|
|
28753
|
-
import { isAbsolute as
|
|
28860
|
+
import { mkdir as mkdir2, realpath as realpath4, stat as stat4, writeFile } from "node:fs/promises";
|
|
28861
|
+
import { isAbsolute as isAbsolute5, join as join8, normalize } from "node:path";
|
|
28754
28862
|
|
|
28755
28863
|
// src/agent-installation/deepseek-managed-package.ts
|
|
28756
28864
|
var DeepSeekHarnessManagedPackage = class extends SriManagedNpmPackageDefinition {
|
|
@@ -28768,13 +28876,13 @@ var DEEPSEEK_HARNESS_PACKAGE = new DeepSeekHarnessManagedPackage(
|
|
|
28768
28876
|
|
|
28769
28877
|
// src/storage/state-directory.ts
|
|
28770
28878
|
import { homedir } from "node:os";
|
|
28771
|
-
import { join as
|
|
28879
|
+
import { join as join7, resolve as resolve2 } from "node:path";
|
|
28772
28880
|
function readStateDirectory(environment = process.env) {
|
|
28773
28881
|
const configured = environment["MOBIUS_STATE_DIRECTORY"]?.trim();
|
|
28774
28882
|
if (configured !== void 0 && configured.length > 0) {
|
|
28775
28883
|
return resolve2(configured);
|
|
28776
28884
|
}
|
|
28777
|
-
return
|
|
28885
|
+
return join7(homedir(), ".mobius");
|
|
28778
28886
|
}
|
|
28779
28887
|
|
|
28780
28888
|
// src/agent-catalog/agents/deepseek-harness-agent.ts
|
|
@@ -28785,20 +28893,20 @@ var DEEPSEEK_HARNESS_IMAGE_PROMPT_PATCH = `# Managed by Mobius: pin the ACP brid
|
|
|
28785
28893
|
model: deepseek-v4-flash-vision-exp
|
|
28786
28894
|
`;
|
|
28787
28895
|
async function prepareAgentHome(path3, imagePrompts) {
|
|
28788
|
-
if (!
|
|
28896
|
+
if (!isAbsolute5(path3) || normalize(path3) !== path3) {
|
|
28789
28897
|
throw new AgentProbeError("agent_environment_invalid", "The configured Agent home is invalid");
|
|
28790
28898
|
}
|
|
28791
28899
|
try {
|
|
28792
28900
|
if (imagePrompts) {
|
|
28793
28901
|
await mkdir2(path3, { mode: 448, recursive: true });
|
|
28794
28902
|
}
|
|
28795
|
-
const resolved = await
|
|
28796
|
-
const metadata = await
|
|
28903
|
+
const resolved = await realpath4(path3);
|
|
28904
|
+
const metadata = await stat4(resolved);
|
|
28797
28905
|
if (!metadata.isDirectory() || typeof process.getuid === "function" && metadata.uid !== process.getuid()) {
|
|
28798
28906
|
throw new Error("Agent home is not a user-owned directory");
|
|
28799
28907
|
}
|
|
28800
28908
|
if (imagePrompts) {
|
|
28801
|
-
await writeFile(
|
|
28909
|
+
await writeFile(join8(resolved, "cordis.patch.yml"), DEEPSEEK_HARNESS_IMAGE_PROMPT_PATCH, {
|
|
28802
28910
|
mode: 384
|
|
28803
28911
|
});
|
|
28804
28912
|
}
|
|
@@ -28846,7 +28954,7 @@ var DeepSeekHarnessAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
28846
28954
|
context.signal
|
|
28847
28955
|
);
|
|
28848
28956
|
if (managed.path === agent.path) {
|
|
28849
|
-
selectedHome =
|
|
28957
|
+
selectedHome = join8(readStateDirectory(context.environment), "agents", this.id, "home");
|
|
28850
28958
|
managedHome = true;
|
|
28851
28959
|
}
|
|
28852
28960
|
} catch {
|
|
@@ -28862,7 +28970,7 @@ var DeepSeekHarnessAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
28862
28970
|
resolveManagedAgent = async (stateDirectory, _platform, signal) => {
|
|
28863
28971
|
signal.throwIfAborted();
|
|
28864
28972
|
const executable = await validateManagedNpmPackage(
|
|
28865
|
-
|
|
28973
|
+
join8(stateDirectory, "agents", this.id, DEEPSEEK_HARNESS_PACKAGE.version),
|
|
28866
28974
|
DEEPSEEK_HARNESS_PACKAGE
|
|
28867
28975
|
);
|
|
28868
28976
|
signal.throwIfAborted();
|
|
@@ -28916,8 +29024,8 @@ var GeminiCliAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
28916
29024
|
};
|
|
28917
29025
|
|
|
28918
29026
|
// src/agent-catalog/agents/grok-build-agent.ts
|
|
28919
|
-
import { realpath as
|
|
28920
|
-
import { isAbsolute as
|
|
29027
|
+
import { realpath as realpath5 } from "node:fs/promises";
|
|
29028
|
+
import { isAbsolute as isAbsolute6, join as join9, relative as relative2, sep as sep2 } from "node:path";
|
|
28921
29029
|
import {
|
|
28922
29030
|
RequestError
|
|
28923
29031
|
} from "@agentclientprotocol/sdk";
|
|
@@ -28940,50 +29048,25 @@ var GrokBuildManagedPackage = class extends SriManagedNpmPackageDefinition {
|
|
|
28940
29048
|
this.requiredDependencies = Object.freeze([requiredDependency]);
|
|
28941
29049
|
}
|
|
28942
29050
|
};
|
|
28943
|
-
var GROK_DARWIN_ARM64_PACKAGE = new SriManagedNpmDependencyDefinition(
|
|
28944
|
-
"@xai-official/grok-darwin-arm64",
|
|
28945
|
-
GROK_BUILD_MANAGED_VERSION,
|
|
28946
|
-
"sha512-I4pKZGnR6Mv4MJOJsB9B/i2o0ODF4eZtp4jHN5feoTqKIeAUVg38OzBtE8aN/wZa7Xg+qhnf6Jd1tcAFvMoFtQ==",
|
|
28947
|
-
"https://registry.npmjs.org/@xai-official/grok-darwin-arm64/-/grok-darwin-arm64-1.0.21.tgz"
|
|
28948
|
-
);
|
|
28949
|
-
var GROK_DARWIN_X64_PACKAGE = new SriManagedNpmDependencyDefinition(
|
|
28950
|
-
"@xai-official/grok-darwin-x64",
|
|
28951
|
-
GROK_BUILD_MANAGED_VERSION,
|
|
28952
|
-
"sha512-h0nFj3NZ9Kz8w6fQ6UDxxeSIhC1WjwwoRE92iNbG//tZy6YGkppR3s7oRVtt4Xl0CJANKUt0EusyIYnnAvKLzw==",
|
|
28953
|
-
"https://registry.npmjs.org/@xai-official/grok-darwin-x64/-/grok-darwin-x64-1.0.21.tgz"
|
|
28954
|
-
);
|
|
28955
|
-
var GROK_LINUX_ARM64_PACKAGE = new SriManagedNpmDependencyDefinition(
|
|
28956
|
-
"@xai-official/grok-linux-arm64",
|
|
28957
|
-
GROK_BUILD_MANAGED_VERSION,
|
|
28958
|
-
"sha512-Jlwz9XtZPNKz/V/ydifC8OVu3hIZz7pmoStt8c4KCqkSWjWiZ/PBIC0iJiq8rvByhx5Z0EdSyq8ZXVwtocceGA==",
|
|
28959
|
-
"https://registry.npmjs.org/@xai-official/grok-linux-arm64/-/grok-linux-arm64-1.0.21.tgz"
|
|
28960
|
-
);
|
|
28961
|
-
var GROK_LINUX_X64_PACKAGE = new SriManagedNpmDependencyDefinition(
|
|
28962
|
-
"@xai-official/grok-linux-x64",
|
|
28963
|
-
GROK_BUILD_MANAGED_VERSION,
|
|
28964
|
-
"sha512-AjDV5ifEz5LFG2Jt5IlhAeEkJati/wOvCchVbR4eIj2ogjvmXoXlzBrYRXuAJpXBy5q0se/Yuez5FxDU9Ju81w==",
|
|
28965
|
-
"https://registry.npmjs.org/@xai-official/grok-linux-x64/-/grok-linux-x64-1.0.21.tgz"
|
|
28966
|
-
);
|
|
28967
29051
|
function grokBuildManagedPackage(platform, architecture) {
|
|
28968
|
-
|
|
28969
|
-
|
|
29052
|
+
const release = platformSupportFor(platform).grokDependencies[architecture];
|
|
29053
|
+
if (release === void 0) {
|
|
29054
|
+
throw new Error("Grok Build does not publish a package for this platform");
|
|
28970
29055
|
}
|
|
28971
|
-
|
|
28972
|
-
|
|
28973
|
-
|
|
28974
|
-
|
|
28975
|
-
|
|
28976
|
-
|
|
28977
|
-
|
|
28978
|
-
|
|
28979
|
-
}
|
|
28980
|
-
throw new Error("Grok Build does not publish a package for this platform");
|
|
29056
|
+
return new GrokBuildManagedPackage(
|
|
29057
|
+
new SriManagedNpmDependencyDefinition(
|
|
29058
|
+
release.name,
|
|
29059
|
+
GROK_BUILD_MANAGED_VERSION,
|
|
29060
|
+
release.integrity,
|
|
29061
|
+
release.tarballUrl
|
|
29062
|
+
)
|
|
29063
|
+
);
|
|
28981
29064
|
}
|
|
28982
29065
|
|
|
28983
29066
|
// src/agent-catalog/agents/grok-build-agent.ts
|
|
28984
29067
|
function isContainedPath2(root, candidate) {
|
|
28985
29068
|
const difference = relative2(root, candidate);
|
|
28986
|
-
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep2}`) && !
|
|
29069
|
+
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep2}`) && !isAbsolute6(difference);
|
|
28987
29070
|
}
|
|
28988
29071
|
var GrokBuildAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
28989
29072
|
adapterVersion = GROK_BUILD_MANAGED_VERSION;
|
|
@@ -29012,8 +29095,8 @@ var GrokBuildAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
29012
29095
|
);
|
|
29013
29096
|
if (managed.path === agent.path) {
|
|
29014
29097
|
return Object.freeze({
|
|
29015
|
-
GROK_HOME: await
|
|
29016
|
-
|
|
29098
|
+
GROK_HOME: await realpath5(
|
|
29099
|
+
join9(stateDirectory, "agents", this.id, GROK_BUILD_MANAGED_VERSION, "home")
|
|
29017
29100
|
)
|
|
29018
29101
|
});
|
|
29019
29102
|
}
|
|
@@ -29024,9 +29107,9 @@ var GrokBuildAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
29024
29107
|
};
|
|
29025
29108
|
resolveManagedAgent = async (stateDirectory, platform, signal) => {
|
|
29026
29109
|
signal.throwIfAborted();
|
|
29027
|
-
const versionRoot = await
|
|
29028
|
-
await validateManagedNpmPackage(
|
|
29029
|
-
const executable = await resolveExecutablePath(
|
|
29110
|
+
const versionRoot = await realpath5(join9(stateDirectory, "agents", this.id, GROK_BUILD_MANAGED_VERSION));
|
|
29111
|
+
await validateManagedNpmPackage(join9(versionRoot, "package"), grokBuildManagedPackage(platform, process.arch));
|
|
29112
|
+
const executable = await resolveExecutablePath(join9(versionRoot, "home", "bin", "grok"), platform);
|
|
29030
29113
|
signal.throwIfAborted();
|
|
29031
29114
|
if (executable === null || !isContainedPath2(versionRoot, executable.path)) {
|
|
29032
29115
|
throw new AgentProbeError("managed_agent_invalid", "The managed Grok Build executable is invalid");
|
|
@@ -29126,13 +29209,13 @@ var OhMyPiAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
29126
29209
|
};
|
|
29127
29210
|
|
|
29128
29211
|
// src/agent-catalog/agents/opencode-agent.ts
|
|
29129
|
-
import { join as
|
|
29212
|
+
import { join as join11 } from "node:path";
|
|
29130
29213
|
|
|
29131
29214
|
// src/agent-installation/managed-agent-archive.ts
|
|
29132
29215
|
import { createHash } from "node:crypto";
|
|
29133
29216
|
import { createReadStream } from "node:fs";
|
|
29134
|
-
import { chmod, copyFile, mkdir as mkdir3, mkdtemp as mkdtemp2, open as open3, realpath as
|
|
29135
|
-
import { delimiter as delimiter2, dirname as dirname2, isAbsolute as
|
|
29217
|
+
import { chmod, copyFile, mkdir as mkdir3, mkdtemp as mkdtemp2, open as open3, realpath as realpath6, rename as rename2, rm as rm2, stat as stat5, writeFile as writeFile2 } from "node:fs/promises";
|
|
29218
|
+
import { delimiter as delimiter2, dirname as dirname2, isAbsolute as isAbsolute7, join as join10, relative as relative3, sep as sep3 } from "node:path";
|
|
29136
29219
|
|
|
29137
29220
|
// src/agent-installation/verified-download.ts
|
|
29138
29221
|
import { fetch } from "undici";
|
|
@@ -29238,7 +29321,7 @@ function isRecord5(value) {
|
|
|
29238
29321
|
}
|
|
29239
29322
|
function isContainedPath3(root, candidate) {
|
|
29240
29323
|
const difference = relative3(root, candidate);
|
|
29241
|
-
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep3}`) && !
|
|
29324
|
+
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep3}`) && !isAbsolute7(difference);
|
|
29242
29325
|
}
|
|
29243
29326
|
async function hashFile(path3, signal) {
|
|
29244
29327
|
signal.throwIfAborted();
|
|
@@ -29312,16 +29395,16 @@ async function readManifest(path3) {
|
|
|
29312
29395
|
}
|
|
29313
29396
|
async function validateManagedAgentArchive(root, definition, signal) {
|
|
29314
29397
|
try {
|
|
29315
|
-
const rootPath = await
|
|
29316
|
-
const rootMetadata = await
|
|
29398
|
+
const rootPath = await realpath6(root);
|
|
29399
|
+
const rootMetadata = await stat5(rootPath);
|
|
29317
29400
|
if (!rootMetadata.isDirectory() || typeof process.getuid === "function" && rootMetadata.uid !== process.getuid()) {
|
|
29318
29401
|
throw new Error("Managed Agent root is not user-owned");
|
|
29319
29402
|
}
|
|
29320
|
-
const manifest = await readManifest(
|
|
29403
|
+
const manifest = await readManifest(join10(rootPath, "archive.json"));
|
|
29321
29404
|
if (manifest["archiveSha256"] !== definition.archiveSha256 || manifest["archiveUrl"] !== definition.archiveUrl.toString() || manifest["version"] !== definition.version || typeof manifest["executableSha256"] !== "string") {
|
|
29322
29405
|
throw new Error("Managed Agent archive identity is invalid");
|
|
29323
29406
|
}
|
|
29324
|
-
const executable = await resolveExecutablePath(
|
|
29407
|
+
const executable = await resolveExecutablePath(join10(rootPath, "bin", definition.executableName));
|
|
29325
29408
|
if (executable === null || !isContainedPath3(rootPath, executable.path) || await hashFile(executable.path, signal) !== manifest["executableSha256"]) {
|
|
29326
29409
|
throw new Error("Managed Agent executable is invalid");
|
|
29327
29410
|
}
|
|
@@ -29347,47 +29430,21 @@ function releaseUrl(asset) {
|
|
|
29347
29430
|
return new URL(`https://github.com/anomalyco/opencode/releases/download/v${OPENCODE_MANAGED_VERSION}/${asset}`);
|
|
29348
29431
|
}
|
|
29349
29432
|
function openCodeManagedArchive(platform, architecture) {
|
|
29350
|
-
|
|
29351
|
-
|
|
29352
|
-
|
|
29353
|
-
|
|
29354
|
-
|
|
29355
|
-
|
|
29356
|
-
|
|
29357
|
-
|
|
29358
|
-
|
|
29359
|
-
|
|
29360
|
-
|
|
29361
|
-
|
|
29362
|
-
|
|
29363
|
-
|
|
29364
|
-
|
|
29365
|
-
releaseUrl(asset),
|
|
29366
|
-
"9858853e7bacdbbd22c2d70c377e009dc4b354dd04f5588705411e7afb89fd2d",
|
|
29367
|
-
"opencode"
|
|
29368
|
-
);
|
|
29369
|
-
}
|
|
29370
|
-
if (platform === "linux" && architecture === "arm64") {
|
|
29371
|
-
const asset = "opencode-linux-arm64.tar.gz";
|
|
29372
|
-
return new TarGzipManagedAgentArchiveDefinition(
|
|
29373
|
-
OPENCODE_MANAGED_VERSION,
|
|
29374
|
-
asset,
|
|
29375
|
-
releaseUrl(asset),
|
|
29376
|
-
"70baf769395ca4e7a68924026530c390eace194f3b7e4919d4efcb2aa2eed3c0",
|
|
29377
|
-
"opencode"
|
|
29378
|
-
);
|
|
29379
|
-
}
|
|
29380
|
-
if (platform === "linux" && architecture === "x64") {
|
|
29381
|
-
const asset = "opencode-linux-x64.tar.gz";
|
|
29382
|
-
return new TarGzipManagedAgentArchiveDefinition(
|
|
29383
|
-
OPENCODE_MANAGED_VERSION,
|
|
29384
|
-
asset,
|
|
29385
|
-
releaseUrl(asset),
|
|
29386
|
-
"ea800b7ff56226b70952126c9fc1e2517ca4c4b5682fd9d3f9e87449697a1194",
|
|
29387
|
-
"opencode"
|
|
29388
|
-
);
|
|
29389
|
-
}
|
|
29390
|
-
throw new Error("OpenCode does not publish an approved archive for this platform");
|
|
29433
|
+
const release = platformSupportFor(platform).openCodeArchives[architecture];
|
|
29434
|
+
if (release === void 0) {
|
|
29435
|
+
throw new Error("OpenCode does not publish an approved archive for this platform");
|
|
29436
|
+
}
|
|
29437
|
+
const Definition = {
|
|
29438
|
+
zip: ZipManagedAgentArchiveDefinition,
|
|
29439
|
+
"tar.gz": TarGzipManagedAgentArchiveDefinition
|
|
29440
|
+
}[release.format];
|
|
29441
|
+
return new Definition(
|
|
29442
|
+
OPENCODE_MANAGED_VERSION,
|
|
29443
|
+
release.asset,
|
|
29444
|
+
releaseUrl(release.asset),
|
|
29445
|
+
release.sha256,
|
|
29446
|
+
"opencode"
|
|
29447
|
+
);
|
|
29391
29448
|
}
|
|
29392
29449
|
|
|
29393
29450
|
// src/agent-catalog/agents/opencode-agent.ts
|
|
@@ -29513,7 +29570,7 @@ var OpenCodeAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
29513
29570
|
return Object.freeze(environment);
|
|
29514
29571
|
};
|
|
29515
29572
|
resolveManagedAgent = async (stateDirectory, platform, signal) => await validateManagedAgentArchive(
|
|
29516
|
-
|
|
29573
|
+
join11(stateDirectory, "agents", this.id, OPENCODE_MANAGED_VERSION),
|
|
29517
29574
|
openCodeManagedArchive(platform, process.arch),
|
|
29518
29575
|
signal
|
|
29519
29576
|
);
|
|
@@ -29531,7 +29588,7 @@ var OpenCodeAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
29531
29588
|
};
|
|
29532
29589
|
|
|
29533
29590
|
// src/agent-catalog/agents/pi-agent.ts
|
|
29534
|
-
import { join as
|
|
29591
|
+
import { join as join12 } from "node:path";
|
|
29535
29592
|
import {
|
|
29536
29593
|
methods as methods4
|
|
29537
29594
|
} from "@agentclientprotocol/sdk";
|
|
@@ -29590,7 +29647,7 @@ var PiAgentSpecification = class extends BridgedAcpAgentDefinition {
|
|
|
29590
29647
|
resolveManagedAgent = async (stateDirectory, _platform, signal) => {
|
|
29591
29648
|
signal.throwIfAborted();
|
|
29592
29649
|
const executable = await validateManagedNpmPackage(
|
|
29593
|
-
|
|
29650
|
+
join12(stateDirectory, "agents", this.id, PI_AGENT_PACKAGE.version),
|
|
29594
29651
|
PI_AGENT_PACKAGE
|
|
29595
29652
|
);
|
|
29596
29653
|
signal.throwIfAborted();
|
|
@@ -29628,7 +29685,7 @@ var PiAgentSpecification = class extends BridgedAcpAgentDefinition {
|
|
|
29628
29685
|
};
|
|
29629
29686
|
|
|
29630
29687
|
// src/agent-catalog/agents/workbuddy-agent.ts
|
|
29631
|
-
import {
|
|
29688
|
+
import { join as join13 } from "node:path";
|
|
29632
29689
|
|
|
29633
29690
|
// src/agent-installation/workbuddy-managed-package.ts
|
|
29634
29691
|
var WORKBUDDY_MANAGED_VERSION = "2.146.0";
|
|
@@ -29646,15 +29703,6 @@ var WORKBUDDY_MANAGED_PACKAGE = new WorkBuddyManagedPackage(
|
|
|
29646
29703
|
);
|
|
29647
29704
|
|
|
29648
29705
|
// src/agent-catalog/agents/workbuddy-agent.ts
|
|
29649
|
-
var WORKBUDDY_MACOS_EXECUTABLE_PATH = Object.freeze([
|
|
29650
|
-
"WorkBuddy.app",
|
|
29651
|
-
"Contents",
|
|
29652
|
-
"Resources",
|
|
29653
|
-
"app.asar.unpacked",
|
|
29654
|
-
"cli",
|
|
29655
|
-
"bin",
|
|
29656
|
-
"codebuddy"
|
|
29657
|
-
]);
|
|
29658
29706
|
var WorkBuddyAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
29659
29707
|
adapterVersion = WORKBUDDY_MANAGED_VERSION;
|
|
29660
29708
|
authenticationCommand = () => "codebuddy";
|
|
@@ -29683,7 +29731,7 @@ var WorkBuddyAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
29683
29731
|
resolveManagedAgent = async (stateDirectory, _platform, signal) => {
|
|
29684
29732
|
signal.throwIfAborted();
|
|
29685
29733
|
const executable = await validateManagedNpmPackage(
|
|
29686
|
-
|
|
29734
|
+
join13(stateDirectory, "agents", this.id, WORKBUDDY_MANAGED_VERSION),
|
|
29687
29735
|
WORKBUDDY_MANAGED_PACKAGE
|
|
29688
29736
|
);
|
|
29689
29737
|
signal.throwIfAborted();
|
|
@@ -29691,17 +29739,11 @@ var WorkBuddyAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
29691
29739
|
};
|
|
29692
29740
|
resolveInstalledAgentExecutables = async (context) => {
|
|
29693
29741
|
context.signal.throwIfAborted();
|
|
29694
|
-
|
|
29695
|
-
|
|
29696
|
-
}
|
|
29697
|
-
const requestedPaths = [join11("/Applications", ...WORKBUDDY_MACOS_EXECUTABLE_PATH)];
|
|
29698
|
-
const homeDirectory = context.environment["HOME"];
|
|
29699
|
-
if (homeDirectory !== void 0 && isAbsolute7(homeDirectory)) {
|
|
29700
|
-
requestedPaths.unshift(join11(homeDirectory, "Applications", ...WORKBUDDY_MACOS_EXECUTABLE_PATH));
|
|
29701
|
-
}
|
|
29742
|
+
const platform = context.platform ?? process.platform;
|
|
29743
|
+
const requestedPaths = platformSupportFor(platform).workBuddyExecutablePaths(context.environment);
|
|
29702
29744
|
const executables = [];
|
|
29703
29745
|
for (const requestedPath2 of requestedPaths) {
|
|
29704
|
-
const executable = await resolveExecutablePath(requestedPath2,
|
|
29746
|
+
const executable = await resolveExecutablePath(requestedPath2, platform);
|
|
29705
29747
|
context.signal.throwIfAborted();
|
|
29706
29748
|
if (executable !== null) {
|
|
29707
29749
|
executables.push(executable);
|
|
@@ -30061,10 +30103,10 @@ function isAgentVersionSupported(reportedVersion, minimumSupportedVersion) {
|
|
|
30061
30103
|
}
|
|
30062
30104
|
|
|
30063
30105
|
// src/agent-catalog/executable-discovery.ts
|
|
30064
|
-
import { isAbsolute as isAbsolute8, join as
|
|
30106
|
+
import { isAbsolute as isAbsolute8, join as join15 } from "node:path";
|
|
30065
30107
|
|
|
30066
30108
|
// src/agent-installation/managed-adapter-installer.ts
|
|
30067
|
-
import { join as
|
|
30109
|
+
import { join as join14 } from "node:path";
|
|
30068
30110
|
var ManagedAdapterInstallError = class extends Error {
|
|
30069
30111
|
code;
|
|
30070
30112
|
constructor(code, message, options = {}) {
|
|
@@ -30121,7 +30163,7 @@ var ManagedAdapterInstaller = class {
|
|
|
30121
30163
|
this.#stateDirectory = options.stateDirectory;
|
|
30122
30164
|
}
|
|
30123
30165
|
install = async (specification, signal) => {
|
|
30124
|
-
const root =
|
|
30166
|
+
const root = join14(this.#stateDirectory, "adapters", specification.id, specification.adapterVersion);
|
|
30125
30167
|
try {
|
|
30126
30168
|
return await this.#npmInstaller.install(
|
|
30127
30169
|
root,
|
|
@@ -30155,7 +30197,7 @@ async function resolveManagedAdapterExecutable(specification, context) {
|
|
|
30155
30197
|
let managed;
|
|
30156
30198
|
try {
|
|
30157
30199
|
managed = await validateManagedAdapter(
|
|
30158
|
-
|
|
30200
|
+
join15(readStateDirectory(context.environment), "adapters", specification.id, specification.adapterVersion),
|
|
30159
30201
|
specification
|
|
30160
30202
|
);
|
|
30161
30203
|
} catch {
|
|
@@ -30469,10 +30511,10 @@ async function discoverLocalAgentInventory(options) {
|
|
|
30469
30511
|
}
|
|
30470
30512
|
|
|
30471
30513
|
// src/config.ts
|
|
30472
|
-
import { join as
|
|
30514
|
+
import { join as join16, resolve as resolve3 } from "node:path";
|
|
30473
30515
|
function loadDefaultWorkspace(environment = process.env) {
|
|
30474
30516
|
const { MOBIUS_DEFAULT_WORKSPACE: configuredWorkspace } = environment;
|
|
30475
|
-
return configuredWorkspace ??
|
|
30517
|
+
return configuredWorkspace ?? join16(readStateDirectory(environment), "workspace");
|
|
30476
30518
|
}
|
|
30477
30519
|
var DaemonLocalContext = class {
|
|
30478
30520
|
environment;
|
|
@@ -30502,7 +30544,7 @@ var OpaqueDaemonReconnectTarget = class extends DaemonReconnectTarget {
|
|
|
30502
30544
|
this.commandArgument = `--connection ${connectionId2}`;
|
|
30503
30545
|
}
|
|
30504
30546
|
};
|
|
30505
|
-
function createDaemonConfig(connection, agents = [], installableAgents = [], localContext = new DaemonLocalContext(readStateDirectory(), process.env), reconnectTarget = null) {
|
|
30547
|
+
function createDaemonConfig(connection, agents = [], installableAgents = [], localContext = new DaemonLocalContext(readStateDirectory(), process.env), reconnectTarget = null, resolveAgent) {
|
|
30506
30548
|
const daemonAgents = agents.map((agent) => withDaemonEnvironment(agent, localContext.environment));
|
|
30507
30549
|
return {
|
|
30508
30550
|
agents: daemonAgents,
|
|
@@ -30513,7 +30555,8 @@ function createDaemonConfig(connection, agents = [], installableAgents = [], loc
|
|
|
30513
30555
|
installableAgents,
|
|
30514
30556
|
localContext,
|
|
30515
30557
|
reconnectTarget,
|
|
30516
|
-
relayUrl: connection.relayUrl
|
|
30558
|
+
relayUrl: connection.relayUrl,
|
|
30559
|
+
...resolveAgent === void 0 ? {} : { resolveAgent }
|
|
30517
30560
|
};
|
|
30518
30561
|
}
|
|
30519
30562
|
|
|
@@ -30523,18 +30566,184 @@ import { createHash as createHash9, randomBytes } from "node:crypto";
|
|
|
30523
30566
|
import { readFile as readFile3, unlink as unlink2, writeFile as writeFile5 } from "node:fs/promises";
|
|
30524
30567
|
import { createConnection, createServer } from "node:net";
|
|
30525
30568
|
import { tmpdir } from "node:os";
|
|
30526
|
-
import { join as
|
|
30569
|
+
import { join as join22 } from "node:path";
|
|
30527
30570
|
|
|
30528
30571
|
// src/pairing/pair-local-machine.ts
|
|
30529
|
-
import { mkdir as mkdir5, realpath as
|
|
30572
|
+
import { mkdir as mkdir5, realpath as realpath7, stat as stat6 } from "node:fs/promises";
|
|
30530
30573
|
import { hostname as hostname3 } from "node:os";
|
|
30531
30574
|
import { basename, resolve as resolve5 } from "node:path";
|
|
30575
|
+
import { fetch as fetch3 } from "undici";
|
|
30576
|
+
|
|
30577
|
+
// src/agent-catalog/publish-agent-catalog.ts
|
|
30532
30578
|
import { fetch as fetch2 } from "undici";
|
|
30533
30579
|
|
|
30580
|
+
// src/relay-connection/runtime-authentication.ts
|
|
30581
|
+
function runtimeCredential(relayUrl) {
|
|
30582
|
+
return relayUrl.searchParams.get("token") ?? "";
|
|
30583
|
+
}
|
|
30584
|
+
function runtimeAuthorization(relayUrl) {
|
|
30585
|
+
const credential = runtimeCredential(relayUrl);
|
|
30586
|
+
return credential.length === 0 ? {} : { authorization: `Bearer ${credential}` };
|
|
30587
|
+
}
|
|
30588
|
+
function relayHttpEndpoint(relayUrl) {
|
|
30589
|
+
const endpoint = new URL(relayUrl);
|
|
30590
|
+
endpoint.protocol = endpoint.protocol === "wss:" ? "https:" : "http:";
|
|
30591
|
+
endpoint.search = "";
|
|
30592
|
+
return endpoint;
|
|
30593
|
+
}
|
|
30594
|
+
|
|
30595
|
+
// src/agent-catalog/publish-agent-catalog.ts
|
|
30596
|
+
var CATALOG_UPDATE_TIMEOUT_MILLISECONDS = 2e4;
|
|
30597
|
+
var AgentCatalogPublishError = class extends Error {
|
|
30598
|
+
code = "agent_catalog_update_failed";
|
|
30599
|
+
diagnosticDetails;
|
|
30600
|
+
constructor(message, options = {}, diagnosticDetails = {}) {
|
|
30601
|
+
super(message, options);
|
|
30602
|
+
this.diagnosticDetails = diagnosticDetails;
|
|
30603
|
+
this.name = "AgentCatalogPublishError";
|
|
30604
|
+
}
|
|
30605
|
+
};
|
|
30606
|
+
function isRecord6(value) {
|
|
30607
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30608
|
+
}
|
|
30609
|
+
function isSafeRelayErrorMessage(value) {
|
|
30610
|
+
return value.length > 0 && value.length <= 512 && Array.from(value).every((character) => character.charCodeAt(0) >= 32 && character.charCodeAt(0) !== 127);
|
|
30611
|
+
}
|
|
30612
|
+
async function rejectedCatalogError(response) {
|
|
30613
|
+
let value;
|
|
30614
|
+
try {
|
|
30615
|
+
value = await response.json();
|
|
30616
|
+
} catch {
|
|
30617
|
+
return new AgentCatalogPublishError("The Relay rejected the Agent catalog update");
|
|
30618
|
+
}
|
|
30619
|
+
if (!isRecord6(value) || !isRecord6(value["error"])) {
|
|
30620
|
+
return new AgentCatalogPublishError("The Relay rejected the Agent catalog update");
|
|
30621
|
+
}
|
|
30622
|
+
const code = value["error"]["code"];
|
|
30623
|
+
const message = value["error"]["message"];
|
|
30624
|
+
if (typeof code !== "string" || !/^[a-z][a-z0-9_]{0,63}$/.test(code) || typeof message !== "string" || !isSafeRelayErrorMessage(message)) {
|
|
30625
|
+
return new AgentCatalogPublishError("The Relay rejected the Agent catalog update");
|
|
30626
|
+
}
|
|
30627
|
+
return new AgentCatalogPublishError(
|
|
30628
|
+
`The Relay rejected the Agent catalog update (${code}): ${message}`,
|
|
30629
|
+
{},
|
|
30630
|
+
{
|
|
30631
|
+
relayErrorCode: code
|
|
30632
|
+
}
|
|
30633
|
+
);
|
|
30634
|
+
}
|
|
30635
|
+
function catalogEndpoint(config2) {
|
|
30636
|
+
const endpoint = relayHttpEndpoint(config2.relayUrl);
|
|
30637
|
+
if (endpoint.pathname.endsWith("/daemon")) {
|
|
30638
|
+
endpoint.pathname = `${endpoint.pathname.slice(0, -"/daemon".length)}/catalog`;
|
|
30639
|
+
return endpoint;
|
|
30640
|
+
}
|
|
30641
|
+
const runtimePath = "/v1/runtimes/connect";
|
|
30642
|
+
if (endpoint.pathname.endsWith(runtimePath)) {
|
|
30643
|
+
endpoint.pathname = `${endpoint.pathname.slice(0, -runtimePath.length)}/channels/${encodeURIComponent(config2.channelId)}/catalog`;
|
|
30644
|
+
return endpoint;
|
|
30645
|
+
}
|
|
30646
|
+
throw new AgentCatalogPublishError("The Relay URL is invalid");
|
|
30647
|
+
}
|
|
30648
|
+
async function publishAgentCatalog(config2, signal) {
|
|
30649
|
+
signal.throwIfAborted();
|
|
30650
|
+
const timeoutSignal = AbortSignal.timeout(CATALOG_UPDATE_TIMEOUT_MILLISECONDS);
|
|
30651
|
+
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
30652
|
+
let response;
|
|
30653
|
+
const catalog = config2.catalog.read();
|
|
30654
|
+
try {
|
|
30655
|
+
response = await fetch2(catalogEndpoint(config2), {
|
|
30656
|
+
body: JSON.stringify({
|
|
30657
|
+
agents: catalog.agents.map((agent) => ({
|
|
30658
|
+
agentPath: agent.agentIdentity.requestedPath,
|
|
30659
|
+
agentVersion: agent.agentVersion,
|
|
30660
|
+
agentSettingsDiscovery: true,
|
|
30661
|
+
capabilities: agent.capabilities,
|
|
30662
|
+
id: agent.id,
|
|
30663
|
+
label: agent.label,
|
|
30664
|
+
sessionTurnConfiguration: true
|
|
30665
|
+
})),
|
|
30666
|
+
installableAgents: catalog.installableAgents
|
|
30667
|
+
}),
|
|
30668
|
+
dispatcher: environmentProxyDispatcher,
|
|
30669
|
+
headers: { ...runtimeAuthorization(config2.relayUrl), "content-type": "application/json" },
|
|
30670
|
+
method: "PUT",
|
|
30671
|
+
signal: requestSignal
|
|
30672
|
+
});
|
|
30673
|
+
} catch (error62) {
|
|
30674
|
+
if (signal.aborted) {
|
|
30675
|
+
signal.throwIfAborted();
|
|
30676
|
+
}
|
|
30677
|
+
throw new AgentCatalogPublishError(
|
|
30678
|
+
timeoutSignal.aborted ? "The Agent catalog update timed out" : "The Agent catalog could not be updated",
|
|
30679
|
+
{ cause: error62 }
|
|
30680
|
+
);
|
|
30681
|
+
}
|
|
30682
|
+
if (!response.ok) {
|
|
30683
|
+
throw await rejectedCatalogError(response);
|
|
30684
|
+
}
|
|
30685
|
+
await response.body?.cancel();
|
|
30686
|
+
}
|
|
30687
|
+
|
|
30688
|
+
// src/agent-catalog/resolve-catalog-agent.ts
|
|
30689
|
+
function createCatalogAgentResolver(discover, readConfig, publish) {
|
|
30690
|
+
const swaps = /* @__PURE__ */ new Map();
|
|
30691
|
+
return async (agent, signal) => {
|
|
30692
|
+
const config2 = readConfig();
|
|
30693
|
+
const pending = swaps.get(agent.id);
|
|
30694
|
+
if (pending !== void 0) {
|
|
30695
|
+
await pending;
|
|
30696
|
+
return config2.catalog.find(agent.id);
|
|
30697
|
+
}
|
|
30698
|
+
let release = () => void 0;
|
|
30699
|
+
const gate = new Promise((resolveGate) => {
|
|
30700
|
+
release = resolveGate;
|
|
30701
|
+
});
|
|
30702
|
+
swaps.set(agent.id, gate);
|
|
30703
|
+
try {
|
|
30704
|
+
if (await unchangedIdentity(agent, signal)) {
|
|
30705
|
+
return agent;
|
|
30706
|
+
}
|
|
30707
|
+
signal.throwIfAborted();
|
|
30708
|
+
const inventory = await discover(signal);
|
|
30709
|
+
signal.throwIfAborted();
|
|
30710
|
+
const previous = config2.catalog.read();
|
|
30711
|
+
const previousAgent = previous.agents.find((entry) => entry.id === agent.id);
|
|
30712
|
+
if (previousAgent === void 0) {
|
|
30713
|
+
throw new Error(`The local Agent ${agent.id} left the catalog before its refresh completed`);
|
|
30714
|
+
}
|
|
30715
|
+
config2.catalog.transition(
|
|
30716
|
+
[
|
|
30717
|
+
...previous.agents.filter((entry) => entry.id !== agent.id),
|
|
30718
|
+
...inventory.readyAgents().map((ready) => withDaemonEnvironment(ready, config2.localContext.environment))
|
|
30719
|
+
],
|
|
30720
|
+
[...previous.installableAgents.filter((entry) => entry.id !== agent.id), ...inventory.installable]
|
|
30721
|
+
);
|
|
30722
|
+
try {
|
|
30723
|
+
await publish(config2, signal);
|
|
30724
|
+
} catch (error62) {
|
|
30725
|
+
config2.catalog.transition(previous.agents, previous.installableAgents);
|
|
30726
|
+
throw error62;
|
|
30727
|
+
}
|
|
30728
|
+
return config2.catalog.find(agent.id);
|
|
30729
|
+
} finally {
|
|
30730
|
+
swaps.delete(agent.id);
|
|
30731
|
+
release();
|
|
30732
|
+
}
|
|
30733
|
+
};
|
|
30734
|
+
}
|
|
30735
|
+
async function unchangedIdentity(agent, signal) {
|
|
30736
|
+
if (!await revalidateExecutable(agent.agentIdentity)) {
|
|
30737
|
+
return false;
|
|
30738
|
+
}
|
|
30739
|
+
signal.throwIfAborted();
|
|
30740
|
+
return agent.kind !== "acp-adapter-process" || await revalidateExecutable(agent.adapterIdentity);
|
|
30741
|
+
}
|
|
30742
|
+
|
|
30534
30743
|
// src/storage/runtime-installation-store.ts
|
|
30535
30744
|
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
30536
30745
|
import { mkdir as mkdir4, open as open4, readdir as readdir2, rename as rename3, unlink, writeFile as writeFile3 } from "node:fs/promises";
|
|
30537
|
-
import { dirname as dirname3, join as
|
|
30746
|
+
import { dirname as dirname3, join as join17, resolve as resolve4 } from "node:path";
|
|
30538
30747
|
var APPLICATION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+){1,31}$/;
|
|
30539
30748
|
var CONNECTION_ID_PATTERN = /^mcn_[a-f0-9]{32}$/;
|
|
30540
30749
|
var INSTALLATION_ID_PATTERN = /^min_[a-f0-9]{32}$/;
|
|
@@ -30598,7 +30807,7 @@ var VerifiedRuntimeConnection = class {
|
|
|
30598
30807
|
this.runtimeId = runtimeId;
|
|
30599
30808
|
}
|
|
30600
30809
|
};
|
|
30601
|
-
function
|
|
30810
|
+
function isRecord7(value) {
|
|
30602
30811
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30603
30812
|
}
|
|
30604
30813
|
function hasExactKeys(value, expectedKeys) {
|
|
@@ -30671,7 +30880,7 @@ function channelIndexFileName(channelId) {
|
|
|
30671
30880
|
return `mci_${createHash2("sha256").update(channelId).digest("hex")}.json`;
|
|
30672
30881
|
}
|
|
30673
30882
|
function decodeInstallationPointer(value) {
|
|
30674
|
-
if (!
|
|
30883
|
+
if (!isRecord7(value) || !hasExactKeys(value, INSTALLATION_POINTER_KEYS) || value["version"] !== 1) {
|
|
30675
30884
|
throw new RuntimeInstallationStoreError("invalid_installation", "The local installation record is invalid");
|
|
30676
30885
|
}
|
|
30677
30886
|
const storedInstallationId = value["installationId"];
|
|
@@ -30681,7 +30890,7 @@ function decodeInstallationPointer(value) {
|
|
|
30681
30890
|
return { installationId: validateInstallationId(storedInstallationId) };
|
|
30682
30891
|
}
|
|
30683
30892
|
function decodeChannelIndex(value) {
|
|
30684
|
-
if (!
|
|
30893
|
+
if (!isRecord7(value) || !hasExactKeys(value, CHANNEL_INDEX_KEYS) || value["version"] !== 1) {
|
|
30685
30894
|
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
30686
30895
|
}
|
|
30687
30896
|
const applicationId = value["applicationId"];
|
|
@@ -30731,7 +30940,7 @@ function decodeVerifiedConnection(value) {
|
|
|
30731
30940
|
);
|
|
30732
30941
|
}
|
|
30733
30942
|
function decodeConnection(value) {
|
|
30734
|
-
if (!
|
|
30943
|
+
if (!isRecord7(value)) {
|
|
30735
30944
|
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
30736
30945
|
}
|
|
30737
30946
|
return decodeVerifiedConnection(value);
|
|
@@ -30777,7 +30986,7 @@ async function readJsonFile(path3, signal, missingCode) {
|
|
|
30777
30986
|
async function writeJsonAtomically(path3, value, signal) {
|
|
30778
30987
|
signal.throwIfAborted();
|
|
30779
30988
|
const directory = dirname3(path3);
|
|
30780
|
-
const temporaryPath =
|
|
30989
|
+
const temporaryPath = join17(directory, `.${randomUUID()}.tmp`);
|
|
30781
30990
|
try {
|
|
30782
30991
|
await mkdir4(directory, { mode: 448, recursive: true });
|
|
30783
30992
|
signal.throwIfAborted();
|
|
@@ -30803,14 +31012,14 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
30803
31012
|
this.applicationId = applicationId;
|
|
30804
31013
|
this.installationId = installationId2;
|
|
30805
31014
|
this.stateDirectory = stateDirectory;
|
|
30806
|
-
this.#channelDirectory =
|
|
30807
|
-
this.#connectionDirectory =
|
|
31015
|
+
this.#channelDirectory = join17(stateDirectory, "channels");
|
|
31016
|
+
this.#connectionDirectory = join17(stateDirectory, "connections");
|
|
30808
31017
|
}
|
|
30809
31018
|
static open = async (options, signal) => {
|
|
30810
31019
|
signal.throwIfAborted();
|
|
30811
31020
|
const applicationId = validateApplicationId(options.applicationId);
|
|
30812
31021
|
const rootDirectory = resolve4(options.stateDirectory);
|
|
30813
|
-
const applicationDirectory =
|
|
31022
|
+
const applicationDirectory = join17(rootDirectory, "installations", applicationId);
|
|
30814
31023
|
try {
|
|
30815
31024
|
await mkdir4(applicationDirectory, { mode: 448, recursive: true });
|
|
30816
31025
|
} catch (cause) {
|
|
@@ -30823,7 +31032,7 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
30823
31032
|
);
|
|
30824
31033
|
}
|
|
30825
31034
|
const storedInstallationId = await readOrCreateInstallationId(applicationDirectory, signal);
|
|
30826
|
-
const stateDirectory =
|
|
31035
|
+
const stateDirectory = join17(applicationDirectory, storedInstallationId);
|
|
30827
31036
|
try {
|
|
30828
31037
|
await mkdir4(stateDirectory, { mode: 448, recursive: true });
|
|
30829
31038
|
} catch (cause) {
|
|
@@ -30838,8 +31047,8 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
30838
31047
|
signal.throwIfAborted();
|
|
30839
31048
|
return new _RuntimeInstallationStore(applicationId, storedInstallationId, stateDirectory);
|
|
30840
31049
|
};
|
|
30841
|
-
connectionPath = (connectionId2) =>
|
|
30842
|
-
channelIndexPath = (channelId) =>
|
|
31050
|
+
connectionPath = (connectionId2) => join17(this.#connectionDirectory, `${validateConnectionId(connectionId2)}.json`);
|
|
31051
|
+
channelIndexPath = (channelId) => join17(this.#channelDirectory, channelIndexFileName(validateIdentifier(channelId, "invalid_channel_id")));
|
|
30843
31052
|
readConnection = async (connectionId2, signal) => {
|
|
30844
31053
|
const stored = decodeConnection(
|
|
30845
31054
|
await readJsonFile(this.connectionPath(connectionId2), signal, "connection_not_found")
|
|
@@ -31001,7 +31210,7 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
31001
31210
|
};
|
|
31002
31211
|
};
|
|
31003
31212
|
async function readOrCreateInstallationId(applicationDirectory, signal) {
|
|
31004
|
-
const pointerPath =
|
|
31213
|
+
const pointerPath = join17(applicationDirectory, "current.json");
|
|
31005
31214
|
try {
|
|
31006
31215
|
return decodeInstallationPointer(await readJsonFile(pointerPath, signal, "installation_not_found")).installationId;
|
|
31007
31216
|
} catch (cause) {
|
|
@@ -31049,7 +31258,7 @@ var PairingClientError = class extends Error {
|
|
|
31049
31258
|
this.name = "PairingClientError";
|
|
31050
31259
|
}
|
|
31051
31260
|
};
|
|
31052
|
-
function
|
|
31261
|
+
function isRecord8(value) {
|
|
31053
31262
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31054
31263
|
}
|
|
31055
31264
|
function hasExactKeys2(value, expectedKeys) {
|
|
@@ -31142,8 +31351,8 @@ async function resolveDefaultWorkspace(path3) {
|
|
|
31142
31351
|
const requestedWorkspace = resolve5(path3);
|
|
31143
31352
|
try {
|
|
31144
31353
|
await mkdir5(requestedWorkspace, { recursive: true, mode: 448 });
|
|
31145
|
-
const defaultWorkspace = await
|
|
31146
|
-
const metadata = await
|
|
31354
|
+
const defaultWorkspace = await realpath7(requestedWorkspace);
|
|
31355
|
+
const metadata = await stat6(defaultWorkspace);
|
|
31147
31356
|
if (!metadata.isDirectory()) {
|
|
31148
31357
|
throw new PairingClientError("invalid_workspace", "The default workspace is not a directory");
|
|
31149
31358
|
}
|
|
@@ -31172,9 +31381,9 @@ async function readJsonResponse(response) {
|
|
|
31172
31381
|
}
|
|
31173
31382
|
}
|
|
31174
31383
|
function readRelayError(value) {
|
|
31175
|
-
if (
|
|
31384
|
+
if (isRecord8(value)) {
|
|
31176
31385
|
const error62 = value["error"];
|
|
31177
|
-
if (
|
|
31386
|
+
if (isRecord8(error62)) {
|
|
31178
31387
|
const code = error62["code"];
|
|
31179
31388
|
const message = error62["message"];
|
|
31180
31389
|
if (typeof code === "string" && typeof message === "string") {
|
|
@@ -31185,7 +31394,7 @@ function readRelayError(value) {
|
|
|
31185
31394
|
return new PairingClientError("pairing_failed", "The relay could not pair this machine");
|
|
31186
31395
|
}
|
|
31187
31396
|
function decodePairingResponse(value, credentialField, expectedKeys) {
|
|
31188
|
-
if (!
|
|
31397
|
+
if (!isRecord8(value) || !hasExactKeys2(value, expectedKeys)) {
|
|
31189
31398
|
throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
|
|
31190
31399
|
}
|
|
31191
31400
|
const appId = value["appId"];
|
|
@@ -31210,7 +31419,7 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
|
|
|
31210
31419
|
const endpoint = options.pairingId.length > 0 ? mobiusApiUrl(options.relayOrigin, `/v1/runtime-pairings/${encodeURIComponent(options.pairingId)}/redeem`) : mobiusApiUrl(options.relayOrigin, "/pairings/claim");
|
|
31211
31420
|
let response;
|
|
31212
31421
|
try {
|
|
31213
|
-
response = await
|
|
31422
|
+
response = await fetch3(endpoint, {
|
|
31214
31423
|
body: JSON.stringify({
|
|
31215
31424
|
agents,
|
|
31216
31425
|
installableAgents,
|
|
@@ -31242,20 +31451,30 @@ function buildPairedDaemon(installation, connection, defaultWorkspace, inventory
|
|
|
31242
31451
|
const relayUrl = mobiusApiUrl(connection.relayOrigin, "/v1/runtimes/connect");
|
|
31243
31452
|
relayUrl.protocol = relayUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
31244
31453
|
relayUrl.searchParams.set("token", connection.runtimeCredential);
|
|
31454
|
+
const config2 = createDaemonConfig(
|
|
31455
|
+
{
|
|
31456
|
+
defaultWorkspace,
|
|
31457
|
+
channelId: connection.channelId,
|
|
31458
|
+
relayUrl
|
|
31459
|
+
},
|
|
31460
|
+
inventory.readyAgents(),
|
|
31461
|
+
inventory.installable,
|
|
31462
|
+
localContext,
|
|
31463
|
+
new OpaqueDaemonReconnectTarget(connection.connectionId),
|
|
31464
|
+
createCatalogAgentResolver(
|
|
31465
|
+
(refreshSignal) => discoverLocalAgentInventory({
|
|
31466
|
+
defaultWorkspace,
|
|
31467
|
+
environment: localContext.environment,
|
|
31468
|
+
signal: refreshSignal
|
|
31469
|
+
}),
|
|
31470
|
+
() => config2,
|
|
31471
|
+
publishAgentCatalog
|
|
31472
|
+
)
|
|
31473
|
+
);
|
|
31245
31474
|
return {
|
|
31246
31475
|
channelUrl: new URL(`/channels/${encodeURIComponent(connection.channelId)}`, connection.relayOrigin).toString(),
|
|
31247
31476
|
connectionId: connection.connectionId,
|
|
31248
|
-
config:
|
|
31249
|
-
{
|
|
31250
|
-
defaultWorkspace,
|
|
31251
|
-
channelId: connection.channelId,
|
|
31252
|
-
relayUrl
|
|
31253
|
-
},
|
|
31254
|
-
inventory.readyAgents(),
|
|
31255
|
-
inventory.installable,
|
|
31256
|
-
localContext,
|
|
31257
|
-
new OpaqueDaemonReconnectTarget(connection.connectionId)
|
|
31258
|
-
),
|
|
31477
|
+
config: config2,
|
|
31259
31478
|
connectionPath: installation.connectionPath(connection.connectionId)
|
|
31260
31479
|
};
|
|
31261
31480
|
}
|
|
@@ -31354,7 +31573,7 @@ var AuditStore = class {
|
|
|
31354
31573
|
|
|
31355
31574
|
// src/run-daemon.ts
|
|
31356
31575
|
import { createHash as createHash8, randomUUID as randomUUID9 } from "node:crypto";
|
|
31357
|
-
import { join as
|
|
31576
|
+
import { join as join21 } from "node:path";
|
|
31358
31577
|
import { styleText } from "node:util";
|
|
31359
31578
|
|
|
31360
31579
|
// src/acp/active-executions.ts
|
|
@@ -31445,7 +31664,7 @@ import {
|
|
|
31445
31664
|
} from "@agentclientprotocol/sdk";
|
|
31446
31665
|
|
|
31447
31666
|
// src/authorization/local-raster.ts
|
|
31448
|
-
import { open as open5, readFile as readFile2, realpath as
|
|
31667
|
+
import { open as open5, readFile as readFile2, realpath as realpath8, stat as stat7 } from "node:fs/promises";
|
|
31449
31668
|
import { basename as basename2, isAbsolute as isAbsolute9, normalize as normalize2 } from "node:path";
|
|
31450
31669
|
import { fileURLToPath } from "node:url";
|
|
31451
31670
|
var MAX_LOCAL_RASTER_BYTES = 128 * 1024 * 1024;
|
|
@@ -31516,7 +31735,7 @@ async function resolveCanonicalPath(requested, signal) {
|
|
|
31516
31735
|
return null;
|
|
31517
31736
|
}
|
|
31518
31737
|
try {
|
|
31519
|
-
const target = await
|
|
31738
|
+
const target = await realpath8(requested);
|
|
31520
31739
|
signal.throwIfAborted();
|
|
31521
31740
|
if (!isAbsolute9(target) || normalize2(target) !== target) {
|
|
31522
31741
|
return null;
|
|
@@ -31564,7 +31783,7 @@ async function readLocalRaster(uri, signal) {
|
|
|
31564
31783
|
if (target === null) {
|
|
31565
31784
|
return null;
|
|
31566
31785
|
}
|
|
31567
|
-
const targetMetadata = await
|
|
31786
|
+
const targetMetadata = await stat7(target);
|
|
31568
31787
|
signal.throwIfAborted();
|
|
31569
31788
|
if (!targetMetadata.isFile() || targetMetadata.size < 1 || targetMetadata.size > MAX_LOCAL_RASTER_BYTES) {
|
|
31570
31789
|
return null;
|
|
@@ -31743,7 +31962,7 @@ async function replaceImageMarkers(text2, replace) {
|
|
|
31743
31962
|
|
|
31744
31963
|
// src/acp/activity-content.ts
|
|
31745
31964
|
var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
|
|
31746
|
-
function
|
|
31965
|
+
function isRecord9(value) {
|
|
31747
31966
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31748
31967
|
}
|
|
31749
31968
|
function truncate3(value, maximumLength) {
|
|
@@ -31927,16 +32146,16 @@ async function normalizeToolContent(content, prepareContent) {
|
|
|
31927
32146
|
return normalized;
|
|
31928
32147
|
}
|
|
31929
32148
|
function rawMcpToolContent(rawOutput) {
|
|
31930
|
-
if (!
|
|
32149
|
+
if (!isRecord9(rawOutput)) {
|
|
31931
32150
|
return [];
|
|
31932
32151
|
}
|
|
31933
|
-
const result =
|
|
32152
|
+
const result = isRecord9(rawOutput["result"]) ? rawOutput["result"] : rawOutput;
|
|
31934
32153
|
const content = result["content"];
|
|
31935
32154
|
if (!Array.isArray(content)) {
|
|
31936
32155
|
return [];
|
|
31937
32156
|
}
|
|
31938
32157
|
return content.flatMap((item) => {
|
|
31939
|
-
if (!
|
|
32158
|
+
if (!isRecord9(item) || item["type"] !== "image" || typeof item["data"] !== "string" || typeof item["mimeType"] !== "string") {
|
|
31940
32159
|
return [];
|
|
31941
32160
|
}
|
|
31942
32161
|
const uri = item["uri"];
|
|
@@ -32013,7 +32232,7 @@ function contentPhase(content) {
|
|
|
32013
32232
|
return "";
|
|
32014
32233
|
}
|
|
32015
32234
|
const codex = metadata["codex"];
|
|
32016
|
-
if (!
|
|
32235
|
+
if (!isRecord9(codex)) {
|
|
32017
32236
|
return "";
|
|
32018
32237
|
}
|
|
32019
32238
|
const phase = codex["phase"];
|
|
@@ -32720,7 +32939,7 @@ var SessionConfigProtocolError = class extends Error {
|
|
|
32720
32939
|
this.name = "SessionConfigProtocolError";
|
|
32721
32940
|
}
|
|
32722
32941
|
};
|
|
32723
|
-
function
|
|
32942
|
+
function isRecord10(value) {
|
|
32724
32943
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32725
32944
|
}
|
|
32726
32945
|
function readString3(value, fallback = "") {
|
|
@@ -32751,7 +32970,7 @@ function normalizeConfigValues(value) {
|
|
|
32751
32970
|
}
|
|
32752
32971
|
const normalized = [];
|
|
32753
32972
|
for (const entry of value) {
|
|
32754
|
-
if (!
|
|
32973
|
+
if (!isRecord10(entry)) {
|
|
32755
32974
|
continue;
|
|
32756
32975
|
}
|
|
32757
32976
|
const groupedOptions = entry["options"];
|
|
@@ -32759,7 +32978,7 @@ function normalizeConfigValues(value) {
|
|
|
32759
32978
|
const groupId = readString3(entry["group"]);
|
|
32760
32979
|
const groupName = readString3(entry["name"]);
|
|
32761
32980
|
for (const groupedOption of groupedOptions) {
|
|
32762
|
-
if (
|
|
32981
|
+
if (isRecord10(groupedOption)) {
|
|
32763
32982
|
const normalizedValue = normalizeConfigValue(groupedOption, groupId, groupName);
|
|
32764
32983
|
if (normalizedValue !== void 0) {
|
|
32765
32984
|
normalized.push(normalizedValue);
|
|
@@ -32779,7 +32998,7 @@ function normalizeConfigOptions(value, modes) {
|
|
|
32779
32998
|
const normalized = [];
|
|
32780
32999
|
if (Array.isArray(value)) {
|
|
32781
33000
|
for (const option of value) {
|
|
32782
|
-
if (!
|
|
33001
|
+
if (!isRecord10(option)) {
|
|
32783
33002
|
continue;
|
|
32784
33003
|
}
|
|
32785
33004
|
const id = truncate4(readString3(option["id"]), 128);
|
|
@@ -32819,12 +33038,12 @@ function normalizeConfigOptions(value, modes) {
|
|
|
32819
33038
|
}
|
|
32820
33039
|
}
|
|
32821
33040
|
}
|
|
32822
|
-
if (
|
|
33041
|
+
if (isRecord10(modes)) {
|
|
32823
33042
|
const values = [];
|
|
32824
33043
|
const availableModes = modes["availableModes"];
|
|
32825
33044
|
if (Array.isArray(availableModes)) {
|
|
32826
33045
|
for (const mode of availableModes) {
|
|
32827
|
-
if (!
|
|
33046
|
+
if (!isRecord10(mode)) {
|
|
32828
33047
|
continue;
|
|
32829
33048
|
}
|
|
32830
33049
|
const id = truncate4(readString3(mode["id"]), 500);
|
|
@@ -32857,7 +33076,7 @@ function normalizeConfigOptions(value, modes) {
|
|
|
32857
33076
|
return normalized.slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
32858
33077
|
}
|
|
32859
33078
|
function normalizeStandardLifecycle(response) {
|
|
32860
|
-
const lifecycle =
|
|
33079
|
+
const lifecycle = isRecord10(response) ? response : {};
|
|
32861
33080
|
return normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
|
|
32862
33081
|
}
|
|
32863
33082
|
function replaceStandardConfigOptions(current, value) {
|
|
@@ -32899,7 +33118,7 @@ var StandardSessionConfigProtocol = class {
|
|
|
32899
33118
|
"ACP agent exited while changing session configuration",
|
|
32900
33119
|
change.signal
|
|
32901
33120
|
);
|
|
32902
|
-
if (!
|
|
33121
|
+
if (!isRecord10(response) || !Array.isArray(response["configOptions"])) {
|
|
32903
33122
|
throw new SessionConfigProtocolError("The Agent returned an invalid session configuration response");
|
|
32904
33123
|
}
|
|
32905
33124
|
return replaceStandardConfigOptions(current, response["configOptions"]);
|
|
@@ -34312,7 +34531,7 @@ function sql(strings, ...params) {
|
|
|
34312
34531
|
return new SQL([new StringChunk(str)]);
|
|
34313
34532
|
}
|
|
34314
34533
|
_sql.raw = raw;
|
|
34315
|
-
function
|
|
34534
|
+
function join23(chunks, separator) {
|
|
34316
34535
|
const result = [];
|
|
34317
34536
|
for (const [i, chunk] of chunks.entries()) {
|
|
34318
34537
|
if (i > 0 && separator !== void 0) result.push(separator);
|
|
@@ -34320,7 +34539,7 @@ function sql(strings, ...params) {
|
|
|
34320
34539
|
}
|
|
34321
34540
|
return new SQL(result);
|
|
34322
34541
|
}
|
|
34323
|
-
_sql.join =
|
|
34542
|
+
_sql.join = join23;
|
|
34324
34543
|
function identifier2(value) {
|
|
34325
34544
|
return new Name(value);
|
|
34326
34545
|
}
|
|
@@ -36465,7 +36684,7 @@ var SQLiteSelectBase = class extends TypedQueryBuilder {
|
|
|
36465
36684
|
const baseTableName = this.tableName;
|
|
36466
36685
|
const tableName = getTableLikeName(table);
|
|
36467
36686
|
for (const item of extractUsedTable(table)) this.usedTables.add(item);
|
|
36468
|
-
if (typeof tableName === "string" && this.config.joins?.some((
|
|
36687
|
+
if (typeof tableName === "string" && this.config.joins?.some((join23) => join23.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
36469
36688
|
if (!this.isPartialSelect) {
|
|
36470
36689
|
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") this.config.fields = { [baseTableName]: this.config.fields };
|
|
36471
36690
|
if (typeof tableName === "string" && !is(table, SQL)) {
|
|
@@ -37304,7 +37523,7 @@ var SQLiteDialect = class {
|
|
|
37304
37523
|
if (!joins2) return;
|
|
37305
37524
|
const withEntries = Object.entries(joins2).filter(([_, v]) => v);
|
|
37306
37525
|
if (!withEntries.length) return;
|
|
37307
|
-
return sql.join(withEntries.map(([k,
|
|
37526
|
+
return sql.join(withEntries.map(([k, join23]) => {
|
|
37308
37527
|
const relation = tableConfig.relations[k];
|
|
37309
37528
|
const isSingle2 = is(relation, One);
|
|
37310
37529
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
|
@@ -37315,7 +37534,7 @@ var SQLiteDialect = class {
|
|
|
37315
37534
|
table: targetTable,
|
|
37316
37535
|
mode: isSingle2 ? "first" : "many",
|
|
37317
37536
|
schema,
|
|
37318
|
-
queryConfig:
|
|
37537
|
+
queryConfig: join23,
|
|
37319
37538
|
tableConfig: schema[relation.targetTableName],
|
|
37320
37539
|
relationWhere: filter,
|
|
37321
37540
|
isNested: true,
|
|
@@ -37329,7 +37548,7 @@ var SQLiteDialect = class {
|
|
|
37329
37548
|
key: k,
|
|
37330
37549
|
selection: innerQuery.selection,
|
|
37331
37550
|
isArray: !isSingle2,
|
|
37332
|
-
isOptional: (relation.optional ?? false) ||
|
|
37551
|
+
isOptional: (relation.optional ?? false) || join23 !== true && !!join23.where
|
|
37333
37552
|
});
|
|
37334
37553
|
const jsonColumns = sql.join(innerQuery.selection.map((s) => {
|
|
37335
37554
|
return sql`${sql.raw(this.escapeString(s.key))}, ${s.selection ? sql`${jsonb}(${sql.identifier(s.key)})` : sql.identifier(s.key)}`;
|
|
@@ -37945,7 +38164,7 @@ var SQLiteUpdateBase = class {
|
|
|
37945
38164
|
createJoin(joinType) {
|
|
37946
38165
|
return ((table, on) => {
|
|
37947
38166
|
const tableName = getTableLikeName(table);
|
|
37948
|
-
if (typeof tableName === "string" && this.config.joins.some((
|
|
38167
|
+
if (typeof tableName === "string" && this.config.joins.some((join23) => join23.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
37949
38168
|
if (typeof on === "function") {
|
|
37950
38169
|
const from = this.config.from ? is(table, SQLiteTable) ? table[Table.Symbol.Columns] : is(table, Subquery) ? table._.selectedFields : is(table, SQLiteViewBase) ? table[ViewBaseConfig].selectedFields : void 0 : void 0;
|
|
37951
38170
|
on = on(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
@@ -39351,7 +39570,7 @@ var AgentSession = class _AgentSession {
|
|
|
39351
39570
|
);
|
|
39352
39571
|
}
|
|
39353
39572
|
initialize = async (signal, recovery, origin) => {
|
|
39354
|
-
if (origin
|
|
39573
|
+
if (origin !== void 0) {
|
|
39355
39574
|
this.#sessionTitle = origin.title;
|
|
39356
39575
|
}
|
|
39357
39576
|
await this.#initializeAgent(signal);
|
|
@@ -39365,7 +39584,7 @@ var AgentSession = class _AgentSession {
|
|
|
39365
39584
|
this.#cwd,
|
|
39366
39585
|
this.#additionalDirectories,
|
|
39367
39586
|
true,
|
|
39368
|
-
|
|
39587
|
+
origin.title
|
|
39369
39588
|
)
|
|
39370
39589
|
) : this.#store.read(this.#mobiusSessionId)
|
|
39371
39590
|
);
|
|
@@ -40393,7 +40612,7 @@ var toolImageSchema = external_exports.union([
|
|
|
40393
40612
|
file: external_exports.object({ base64: external_exports.string(), type: external_exports.string() })
|
|
40394
40613
|
}).transform(({ file: file2 }) => ({ type: "image", data: file2.base64, mimeType: file2.type }))
|
|
40395
40614
|
]);
|
|
40396
|
-
function
|
|
40615
|
+
function isRecord11(value) {
|
|
40397
40616
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
40398
40617
|
}
|
|
40399
40618
|
var AcpContentExternalizer = class {
|
|
@@ -40509,13 +40728,13 @@ var AcpContentExternalizer = class {
|
|
|
40509
40728
|
}
|
|
40510
40729
|
return result2;
|
|
40511
40730
|
}
|
|
40512
|
-
if (!
|
|
40731
|
+
if (!isRecord11(value)) {
|
|
40513
40732
|
return value;
|
|
40514
40733
|
}
|
|
40515
40734
|
const image = toolImageSchema.safeParse(value);
|
|
40516
40735
|
if (image.success && image.data.data.length > 0) {
|
|
40517
40736
|
const prepared = await this.#content(sessionId, image.data, signal);
|
|
40518
|
-
if (
|
|
40737
|
+
if (isRecord11(prepared.event) && typeof prepared.event["imageKey"] === "string") {
|
|
40519
40738
|
images.set(prepared.event["imageKey"], prepared);
|
|
40520
40739
|
} else {
|
|
40521
40740
|
images.set(`unavailable:${images.size}`, prepared);
|
|
@@ -40546,7 +40765,7 @@ var AcpContentExternalizer = class {
|
|
|
40546
40765
|
const prepared = await this.#content(sessionId, content, signal);
|
|
40547
40766
|
agentContent.push({ ...item, content: prepared.agent });
|
|
40548
40767
|
eventContent.push({ ...item, content: prepared.event });
|
|
40549
|
-
if (
|
|
40768
|
+
if (isRecord11(prepared.event) && typeof prepared.event["imageKey"] === "string") {
|
|
40550
40769
|
images.delete(prepared.event["imageKey"]);
|
|
40551
40770
|
}
|
|
40552
40771
|
}
|
|
@@ -40604,8 +40823,8 @@ var AcpContentExternalizer = class {
|
|
|
40604
40823
|
|
|
40605
40824
|
// src/external-content/local-external-content-store.ts
|
|
40606
40825
|
import { createHash as createHash3, randomUUID as randomUUID3 } from "node:crypto";
|
|
40607
|
-
import { lstat, mkdir as mkdir6, readdir as readdir3, realpath as
|
|
40608
|
-
import { dirname as dirname4, join as
|
|
40826
|
+
import { lstat, mkdir as mkdir6, readdir as readdir3, realpath as realpath9, rename as rename4, rm as rm3, stat as stat8, utimes, writeFile as writeFile4 } from "node:fs/promises";
|
|
40827
|
+
import { dirname as dirname4, join as join18 } from "node:path";
|
|
40609
40828
|
var contentRequest = /^mobius-content:(image|audio|resource):([a-f0-9]{64})$/u;
|
|
40610
40829
|
var CONTENT_LIFETIME_MILLISECONDS = 24 * 60 * 60 * 1e3;
|
|
40611
40830
|
var metadataSchema2 = external_exports.strictObject({
|
|
@@ -40641,7 +40860,7 @@ var LocalExternalContentStore = class {
|
|
|
40641
40860
|
#expirationTimer;
|
|
40642
40861
|
#cleanup = Promise.resolve();
|
|
40643
40862
|
constructor(stateDirectory) {
|
|
40644
|
-
this.#root =
|
|
40863
|
+
this.#root = join18(stateDirectory, "tmp", "session-content", randomUUID3());
|
|
40645
40864
|
this.#expirationTimer = setInterval(() => {
|
|
40646
40865
|
void this.#expire().catch(() => void 0);
|
|
40647
40866
|
}, 6e4);
|
|
@@ -40656,11 +40875,11 @@ var LocalExternalContentStore = class {
|
|
|
40656
40875
|
if (!directory.isDirectory() || !/^[a-f0-9-]{36}$/u.test(directory.name)) {
|
|
40657
40876
|
continue;
|
|
40658
40877
|
}
|
|
40659
|
-
const path3 =
|
|
40878
|
+
const path3 = join18(dirname4(this.#root), directory.name);
|
|
40660
40879
|
if (path3 === this.#root) {
|
|
40661
40880
|
continue;
|
|
40662
40881
|
}
|
|
40663
|
-
const modified = await
|
|
40882
|
+
const modified = await stat8(path3).then(
|
|
40664
40883
|
(entry) => entry.mtimeMs,
|
|
40665
40884
|
() => Date.now()
|
|
40666
40885
|
);
|
|
@@ -40706,10 +40925,10 @@ var LocalExternalContentStore = class {
|
|
|
40706
40925
|
}
|
|
40707
40926
|
await this.#expire();
|
|
40708
40927
|
active.throwIfAborted();
|
|
40709
|
-
const directory =
|
|
40928
|
+
const directory = join18(this.#root, kind);
|
|
40710
40929
|
await mkdir6(directory, { mode: 448, recursive: true });
|
|
40711
40930
|
active.throwIfAborted();
|
|
40712
|
-
const path3 =
|
|
40931
|
+
const path3 = join18(directory, key);
|
|
40713
40932
|
const write = atomicWrite(path3, bytes, active);
|
|
40714
40933
|
await write;
|
|
40715
40934
|
active.throwIfAborted();
|
|
@@ -40742,8 +40961,8 @@ var LocalExternalContentStore = class {
|
|
|
40742
40961
|
}
|
|
40743
40962
|
try {
|
|
40744
40963
|
const [resolvedDirectory, resolvedPath, file2] = await Promise.all([
|
|
40745
|
-
|
|
40746
|
-
|
|
40964
|
+
realpath9(dirname4(entry.path)),
|
|
40965
|
+
realpath9(entry.path),
|
|
40747
40966
|
lstat(entry.path)
|
|
40748
40967
|
]);
|
|
40749
40968
|
signal.throwIfAborted();
|
|
@@ -41181,7 +41400,7 @@ var AgentRuntimeManager = class {
|
|
|
41181
41400
|
return await this.#startRetainedSessionProcess(
|
|
41182
41401
|
options,
|
|
41183
41402
|
async () => await AgentSession.start(
|
|
41184
|
-
options.origin === void 0 && this.#sessionIdentity === "native" && isNativeChatSessionId(options.agent.id, options.sessionId) && this.#store.read(options.sessionId) instanceof MissingAcpStoredSession ? { ...options, origin: { kind: "import", nativeSessionId: options.sessionId } } : options,
|
|
41403
|
+
options.origin === void 0 && this.#sessionIdentity === "native" && isNativeChatSessionId(options.agent.id, options.sessionId) && this.#store.read(options.sessionId) instanceof MissingAcpStoredSession ? { ...options, origin: { kind: "import", nativeSessionId: options.sessionId, title: "" } } : options,
|
|
41185
41404
|
recovery,
|
|
41186
41405
|
() => this.#observer,
|
|
41187
41406
|
this.#store,
|
|
@@ -41784,117 +42003,6 @@ var AgentRuntimeManager = class {
|
|
|
41784
42003
|
});
|
|
41785
42004
|
};
|
|
41786
42005
|
|
|
41787
|
-
// src/agent-catalog/publish-agent-catalog.ts
|
|
41788
|
-
import { fetch as fetch3 } from "undici";
|
|
41789
|
-
|
|
41790
|
-
// src/relay-connection/runtime-authentication.ts
|
|
41791
|
-
function runtimeCredential(relayUrl) {
|
|
41792
|
-
return relayUrl.searchParams.get("token") ?? "";
|
|
41793
|
-
}
|
|
41794
|
-
function runtimeAuthorization(relayUrl) {
|
|
41795
|
-
const credential = runtimeCredential(relayUrl);
|
|
41796
|
-
return credential.length === 0 ? {} : { authorization: `Bearer ${credential}` };
|
|
41797
|
-
}
|
|
41798
|
-
function relayHttpEndpoint(relayUrl) {
|
|
41799
|
-
const endpoint = new URL(relayUrl);
|
|
41800
|
-
endpoint.protocol = endpoint.protocol === "wss:" ? "https:" : "http:";
|
|
41801
|
-
endpoint.search = "";
|
|
41802
|
-
return endpoint;
|
|
41803
|
-
}
|
|
41804
|
-
|
|
41805
|
-
// src/agent-catalog/publish-agent-catalog.ts
|
|
41806
|
-
var CATALOG_UPDATE_TIMEOUT_MILLISECONDS = 2e4;
|
|
41807
|
-
var AgentCatalogPublishError = class extends Error {
|
|
41808
|
-
code = "agent_catalog_update_failed";
|
|
41809
|
-
diagnosticDetails;
|
|
41810
|
-
constructor(message, options = {}, diagnosticDetails = {}) {
|
|
41811
|
-
super(message, options);
|
|
41812
|
-
this.diagnosticDetails = diagnosticDetails;
|
|
41813
|
-
this.name = "AgentCatalogPublishError";
|
|
41814
|
-
}
|
|
41815
|
-
};
|
|
41816
|
-
function isRecord11(value) {
|
|
41817
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
41818
|
-
}
|
|
41819
|
-
function isSafeRelayErrorMessage(value) {
|
|
41820
|
-
return value.length > 0 && value.length <= 512 && Array.from(value).every((character) => character.charCodeAt(0) >= 32 && character.charCodeAt(0) !== 127);
|
|
41821
|
-
}
|
|
41822
|
-
async function rejectedCatalogError(response) {
|
|
41823
|
-
let value;
|
|
41824
|
-
try {
|
|
41825
|
-
value = await response.json();
|
|
41826
|
-
} catch {
|
|
41827
|
-
return new AgentCatalogPublishError("The Relay rejected the Agent catalog update");
|
|
41828
|
-
}
|
|
41829
|
-
if (!isRecord11(value) || !isRecord11(value["error"])) {
|
|
41830
|
-
return new AgentCatalogPublishError("The Relay rejected the Agent catalog update");
|
|
41831
|
-
}
|
|
41832
|
-
const code = value["error"]["code"];
|
|
41833
|
-
const message = value["error"]["message"];
|
|
41834
|
-
if (typeof code !== "string" || !/^[a-z][a-z0-9_]{0,63}$/.test(code) || typeof message !== "string" || !isSafeRelayErrorMessage(message)) {
|
|
41835
|
-
return new AgentCatalogPublishError("The Relay rejected the Agent catalog update");
|
|
41836
|
-
}
|
|
41837
|
-
return new AgentCatalogPublishError(
|
|
41838
|
-
`The Relay rejected the Agent catalog update (${code}): ${message}`,
|
|
41839
|
-
{},
|
|
41840
|
-
{
|
|
41841
|
-
relayErrorCode: code
|
|
41842
|
-
}
|
|
41843
|
-
);
|
|
41844
|
-
}
|
|
41845
|
-
function catalogEndpoint(config2) {
|
|
41846
|
-
const endpoint = relayHttpEndpoint(config2.relayUrl);
|
|
41847
|
-
if (endpoint.pathname.endsWith("/daemon")) {
|
|
41848
|
-
endpoint.pathname = `${endpoint.pathname.slice(0, -"/daemon".length)}/catalog`;
|
|
41849
|
-
return endpoint;
|
|
41850
|
-
}
|
|
41851
|
-
const runtimePath = "/v1/runtimes/connect";
|
|
41852
|
-
if (endpoint.pathname.endsWith(runtimePath)) {
|
|
41853
|
-
endpoint.pathname = `${endpoint.pathname.slice(0, -runtimePath.length)}/channels/${encodeURIComponent(config2.channelId)}/catalog`;
|
|
41854
|
-
return endpoint;
|
|
41855
|
-
}
|
|
41856
|
-
throw new AgentCatalogPublishError("The Relay URL is invalid");
|
|
41857
|
-
}
|
|
41858
|
-
async function publishAgentCatalog(config2, signal) {
|
|
41859
|
-
signal.throwIfAborted();
|
|
41860
|
-
const timeoutSignal = AbortSignal.timeout(CATALOG_UPDATE_TIMEOUT_MILLISECONDS);
|
|
41861
|
-
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
41862
|
-
let response;
|
|
41863
|
-
const catalog = config2.catalog.read();
|
|
41864
|
-
try {
|
|
41865
|
-
response = await fetch3(catalogEndpoint(config2), {
|
|
41866
|
-
body: JSON.stringify({
|
|
41867
|
-
agents: catalog.agents.map((agent) => ({
|
|
41868
|
-
agentPath: agent.agentIdentity.requestedPath,
|
|
41869
|
-
agentVersion: agent.agentVersion,
|
|
41870
|
-
agentSettingsDiscovery: true,
|
|
41871
|
-
capabilities: agent.capabilities,
|
|
41872
|
-
id: agent.id,
|
|
41873
|
-
label: agent.label,
|
|
41874
|
-
sessionTurnConfiguration: true
|
|
41875
|
-
})),
|
|
41876
|
-
installableAgents: catalog.installableAgents
|
|
41877
|
-
}),
|
|
41878
|
-
dispatcher: environmentProxyDispatcher,
|
|
41879
|
-
headers: { ...runtimeAuthorization(config2.relayUrl), "content-type": "application/json" },
|
|
41880
|
-
method: "PUT",
|
|
41881
|
-
signal: requestSignal
|
|
41882
|
-
});
|
|
41883
|
-
} catch (error62) {
|
|
41884
|
-
if (signal.aborted) {
|
|
41885
|
-
signal.throwIfAborted();
|
|
41886
|
-
}
|
|
41887
|
-
throw new AgentCatalogPublishError(
|
|
41888
|
-
timeoutSignal.aborted ? "The Agent catalog update timed out" : "The Agent catalog could not be updated",
|
|
41889
|
-
{ cause: error62 }
|
|
41890
|
-
);
|
|
41891
|
-
}
|
|
41892
|
-
if (!response.ok) {
|
|
41893
|
-
throw await rejectedCatalogError(response);
|
|
41894
|
-
}
|
|
41895
|
-
await response.body?.cancel();
|
|
41896
|
-
}
|
|
41897
|
-
|
|
41898
42006
|
// src/agent-installation/agent-installation-manager.ts
|
|
41899
42007
|
var INSTALLATION_DEADLINE_MILLISECONDS = 10 * 60 * 1e3;
|
|
41900
42008
|
var AgentInstallation = class {
|
|
@@ -42357,9 +42465,9 @@ var FixedInstallationExecutor = class {
|
|
|
42357
42465
|
};
|
|
42358
42466
|
|
|
42359
42467
|
// src/authorization/workspace-directory.ts
|
|
42360
|
-
import { readdir as readdir4, realpath as
|
|
42468
|
+
import { readdir as readdir4, realpath as realpath10, stat as stat9 } from "node:fs/promises";
|
|
42361
42469
|
import { homedir as homedir2 } from "node:os";
|
|
42362
|
-
import { basename as basename4, dirname as dirname5, isAbsolute as isAbsolute10, join as
|
|
42470
|
+
import { basename as basename4, dirname as dirname5, isAbsolute as isAbsolute10, join as join19, normalize as normalize3, relative as relative4 } from "node:path";
|
|
42363
42471
|
|
|
42364
42472
|
// src/authorization/local-authorization-error.ts
|
|
42365
42473
|
var LocalAuthorizationError = class extends Error {
|
|
@@ -42438,9 +42546,9 @@ var WorkspaceDirectoryService = class {
|
|
|
42438
42546
|
throw new LocalAuthorizationError("The local directory path is invalid");
|
|
42439
42547
|
}
|
|
42440
42548
|
try {
|
|
42441
|
-
const target = await
|
|
42549
|
+
const target = await realpath10(requested);
|
|
42442
42550
|
signal.throwIfAborted();
|
|
42443
|
-
const metadata = await
|
|
42551
|
+
const metadata = await stat9(target);
|
|
42444
42552
|
signal.throwIfAborted();
|
|
42445
42553
|
if (!isAbsolute10(target) || normalize3(target) !== target || !metadata.isDirectory()) {
|
|
42446
42554
|
throw new LocalAuthorizationError("The selected location is not a directory");
|
|
@@ -42488,7 +42596,7 @@ var WorkspaceDirectoryService = class {
|
|
|
42488
42596
|
continue;
|
|
42489
42597
|
}
|
|
42490
42598
|
try {
|
|
42491
|
-
const path3 = await this.resolvePath(
|
|
42599
|
+
const path3 = await this.resolvePath(join19(target, child2.name), signal);
|
|
42492
42600
|
entries.push({ directoryId: encodePath(path3), name: child2.name });
|
|
42493
42601
|
} catch (cause) {
|
|
42494
42602
|
signal.throwIfAborted();
|
|
@@ -42524,15 +42632,15 @@ var WorkspaceDirectoryService = class {
|
|
|
42524
42632
|
|
|
42525
42633
|
// src/daemon-diagnostic-log.ts
|
|
42526
42634
|
import { appendFileSync, mkdirSync, readFileSync as readFileSync2, renameSync, statSync as statSync3, writeFileSync } from "node:fs";
|
|
42527
|
-
import { join as
|
|
42635
|
+
import { join as join20 } from "node:path";
|
|
42528
42636
|
var MAXIMUM_DAEMON_LOG_BYTES = 1 * 1024 * 1024;
|
|
42529
42637
|
var DaemonDiagnosticLog = class {
|
|
42530
42638
|
#directory;
|
|
42531
42639
|
#path;
|
|
42532
42640
|
#maximumBytes;
|
|
42533
42641
|
constructor(stateDirectory, maximumBytes = MAXIMUM_DAEMON_LOG_BYTES) {
|
|
42534
|
-
this.#directory =
|
|
42535
|
-
this.#path =
|
|
42642
|
+
this.#directory = join20(stateDirectory, "logs");
|
|
42643
|
+
this.#path = join20(this.#directory, "daemon.log");
|
|
42536
42644
|
this.#maximumBytes = maximumBytes;
|
|
42537
42645
|
}
|
|
42538
42646
|
// Export only correlation and failure metadata. Local messages and paths stay local.
|
|
@@ -44477,9 +44585,10 @@ var NativeSessionService = class {
|
|
|
44477
44585
|
signal
|
|
44478
44586
|
);
|
|
44479
44587
|
signal.throwIfAborted();
|
|
44588
|
+
const cataloged = this.#config.catalog.find(command.agentId);
|
|
44480
44589
|
const options = {
|
|
44481
44590
|
additionalDirectories,
|
|
44482
|
-
agent: this.#config.
|
|
44591
|
+
agent: this.#config.resolveAgent === void 0 ? cataloged : await this.#config.resolveAgent(cataloged, signal),
|
|
44483
44592
|
cwd,
|
|
44484
44593
|
sessionId: command.sessionId,
|
|
44485
44594
|
signal
|
|
@@ -44657,7 +44766,7 @@ var NativeSessionService = class {
|
|
|
44657
44766
|
sessionId: command.targetSessionId,
|
|
44658
44767
|
additionalDirectories: target.additionalDirectories
|
|
44659
44768
|
},
|
|
44660
|
-
action === "fork" ? { kind: "fork", nativeSessionId: target.info.sessionId, title: title2 } : { kind: "import", nativeSessionId: target.info.sessionId }
|
|
44769
|
+
action === "fork" ? { kind: "fork", nativeSessionId: target.info.sessionId, title: title2 } : { kind: "import", nativeSessionId: target.info.sessionId, title: title2 }
|
|
44661
44770
|
);
|
|
44662
44771
|
signal.throwIfAborted();
|
|
44663
44772
|
const ready = {
|
|
@@ -45258,7 +45367,8 @@ function unsupportedModelIds(unsupportedModels) {
|
|
|
45258
45367
|
return [...new Set(unsupportedModels.map((item) => item.requestedValue))];
|
|
45259
45368
|
}
|
|
45260
45369
|
async function discoverAgentSettings(command, config2, directories, sessions, signal) {
|
|
45261
|
-
const
|
|
45370
|
+
const cataloged = config2.catalog.find(command.agentId);
|
|
45371
|
+
const agent = config2.resolveAgent === void 0 ? cataloged : await config2.resolveAgent(cataloged, signal);
|
|
45262
45372
|
const cwd = await directories.resolve(config2.bindingId, "default", signal);
|
|
45263
45373
|
const inspectedBaseSnapshot = await sessions.inspectAgentSettings({
|
|
45264
45374
|
additionalDirectories: [],
|
|
@@ -45652,7 +45762,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
|
|
|
45652
45762
|
|
|
45653
45763
|
// src/artifacts/local-file-streamer.ts
|
|
45654
45764
|
import { createReadStream as createReadStream2 } from "node:fs";
|
|
45655
|
-
import { realpath as
|
|
45765
|
+
import { realpath as realpath11, stat as stat10 } from "node:fs/promises";
|
|
45656
45766
|
import { basename as basename5, extname, isAbsolute as isAbsolute11, normalize as normalize4, resolve as resolve7 } from "node:path";
|
|
45657
45767
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
45658
45768
|
var CHUNK_BYTES = 192 * 1024;
|
|
@@ -45680,7 +45790,7 @@ async function resolveFile(value, workingDirectory, signal) {
|
|
|
45680
45790
|
return null;
|
|
45681
45791
|
}
|
|
45682
45792
|
try {
|
|
45683
|
-
const target = await
|
|
45793
|
+
const target = await realpath11(requested);
|
|
45684
45794
|
signal.throwIfAborted();
|
|
45685
45795
|
return isAbsolute11(target) && normalize4(target) === target ? target : null;
|
|
45686
45796
|
} catch {
|
|
@@ -45694,7 +45804,7 @@ async function streamLocalFile(command, send2, signal, workingDirectory, externa
|
|
|
45694
45804
|
if (target === null) {
|
|
45695
45805
|
throw new Error("The local file is unavailable");
|
|
45696
45806
|
}
|
|
45697
|
-
const before = await
|
|
45807
|
+
const before = await stat10(target);
|
|
45698
45808
|
signal.throwIfAborted();
|
|
45699
45809
|
if (!before.isFile() || before.size < 1 || before.size > command.maxBytes) {
|
|
45700
45810
|
throw new Error("The local file is too large to read");
|
|
@@ -45722,7 +45832,7 @@ async function streamLocalFile(command, send2, signal, workingDirectory, externa
|
|
|
45722
45832
|
});
|
|
45723
45833
|
sequence += 1;
|
|
45724
45834
|
}
|
|
45725
|
-
const after = await
|
|
45835
|
+
const after = await stat10(target);
|
|
45726
45836
|
signal.throwIfAborted();
|
|
45727
45837
|
if (after.size !== before.size || after.mtimeMs !== before.mtimeMs) {
|
|
45728
45838
|
throw new Error("The local file changed during transfer");
|
|
@@ -45766,6 +45876,232 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
|
|
|
45766
45876
|
return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
|
|
45767
45877
|
}
|
|
45768
45878
|
|
|
45879
|
+
// src/daemon-session-commands.ts
|
|
45880
|
+
async function resolveCatalogAgent(config2, agentId, signal) {
|
|
45881
|
+
const agent = config2.catalog.find(agentId);
|
|
45882
|
+
return config2.resolveAgent === void 0 ? agent : await config2.resolveAgent(agent, signal);
|
|
45883
|
+
}
|
|
45884
|
+
async function prepareSession(command, recovery, config2, directories, audit, sessions, metrics, signal) {
|
|
45885
|
+
return await metrics.measure("prepare-total", async () => {
|
|
45886
|
+
const resolved = await metrics.measure(
|
|
45887
|
+
"workspace-resolve",
|
|
45888
|
+
async () => await resolveSessionDirectories(
|
|
45889
|
+
directories,
|
|
45890
|
+
config2.bindingId,
|
|
45891
|
+
command.directoryId,
|
|
45892
|
+
command.additionalDirectoryIds,
|
|
45893
|
+
signal
|
|
45894
|
+
)
|
|
45895
|
+
);
|
|
45896
|
+
const agent = await resolveCatalogAgent(config2, command.agentId, signal);
|
|
45897
|
+
const preparation = {
|
|
45898
|
+
additionalDirectories: resolved.additionalDirectories,
|
|
45899
|
+
agent,
|
|
45900
|
+
cwd: resolved.cwd,
|
|
45901
|
+
sessionId: command.sessionId,
|
|
45902
|
+
signal
|
|
45903
|
+
};
|
|
45904
|
+
const prepared = command.transient === true ? await sessions.inspectSession(preparation, metrics) : recovery.kind === "history-required" ? await sessions.restoreSession(preparation, metrics) : await sessions.prepareSession(preparation, metrics);
|
|
45905
|
+
const configuration = command.configuration;
|
|
45906
|
+
const configOptions = configuration === void 0 ? prepared.configOptions : await metrics.measure(
|
|
45907
|
+
"configuration",
|
|
45908
|
+
async () => await sessions.configureSession({
|
|
45909
|
+
...preparation,
|
|
45910
|
+
booleanValue: configuration.booleanValue,
|
|
45911
|
+
configId: configuration.configId,
|
|
45912
|
+
requestId: command.requestId,
|
|
45913
|
+
value: configuration.value,
|
|
45914
|
+
valueType: configuration.valueType
|
|
45915
|
+
})
|
|
45916
|
+
);
|
|
45917
|
+
const listing = await metrics.measure(
|
|
45918
|
+
"workspace-list",
|
|
45919
|
+
async () => await directories.list(config2.bindingId, command.directoryId, signal)
|
|
45920
|
+
);
|
|
45921
|
+
audit.record({
|
|
45922
|
+
commandId: command.requestId,
|
|
45923
|
+
event: "session_prepared",
|
|
45924
|
+
sessionId: command.sessionId
|
|
45925
|
+
});
|
|
45926
|
+
if (command.configuration !== void 0) {
|
|
45927
|
+
audit.record({
|
|
45928
|
+
commandId: command.requestId,
|
|
45929
|
+
event: "session_configured",
|
|
45930
|
+
sessionId: command.sessionId
|
|
45931
|
+
});
|
|
45932
|
+
}
|
|
45933
|
+
return {
|
|
45934
|
+
additionalDirectories: resolved.additionalDirectoryEntries,
|
|
45935
|
+
agentId: command.agentId,
|
|
45936
|
+
agentName: prepared.agentName,
|
|
45937
|
+
agentVersion: prepared.agentVersion,
|
|
45938
|
+
capabilities: prepared.capabilities,
|
|
45939
|
+
commands: prepared.commands,
|
|
45940
|
+
configOptions,
|
|
45941
|
+
directoryId: command.directoryId,
|
|
45942
|
+
directoryLabel: listing.directoryLabel,
|
|
45943
|
+
kind: "session.ready",
|
|
45944
|
+
requestId: command.requestId,
|
|
45945
|
+
restored: prepared.restored,
|
|
45946
|
+
sessionId: command.sessionId
|
|
45947
|
+
};
|
|
45948
|
+
});
|
|
45949
|
+
}
|
|
45950
|
+
async function executeWorkspaceList(socket, command, directories, audit, signal) {
|
|
45951
|
+
try {
|
|
45952
|
+
const listing = await directories.list(command.bindingId, command.directoryId, signal);
|
|
45953
|
+
audit.record({
|
|
45954
|
+
commandId: command.requestId,
|
|
45955
|
+
event: "workspace_list_authorized",
|
|
45956
|
+
sessionId: "workspace-browser"
|
|
45957
|
+
});
|
|
45958
|
+
send(socket, {
|
|
45959
|
+
bindingId: command.bindingId,
|
|
45960
|
+
directoryId: listing.directoryId,
|
|
45961
|
+
directoryLabel: listing.directoryLabel,
|
|
45962
|
+
entries: listing.entries,
|
|
45963
|
+
kind: "workspace.entries",
|
|
45964
|
+
parentDirectoryId: listing.parentDirectoryId,
|
|
45965
|
+
requestId: command.requestId
|
|
45966
|
+
});
|
|
45967
|
+
} catch (error62) {
|
|
45968
|
+
reportOperationFailure(socket, command.requestId, "", error62);
|
|
45969
|
+
}
|
|
45970
|
+
}
|
|
45971
|
+
async function executeSessionPrepare(socket, command, config2, directories, audit, sessions, diagnostics, signal) {
|
|
45972
|
+
const metrics = new AccumulatingOperationMetrics();
|
|
45973
|
+
try {
|
|
45974
|
+
const readyEvent = await prepareSession(
|
|
45975
|
+
command,
|
|
45976
|
+
{ kind: "interactive-only" },
|
|
45977
|
+
config2,
|
|
45978
|
+
directories,
|
|
45979
|
+
audit,
|
|
45980
|
+
sessions,
|
|
45981
|
+
metrics,
|
|
45982
|
+
signal
|
|
45983
|
+
);
|
|
45984
|
+
send(socket, {
|
|
45985
|
+
...readyEvent,
|
|
45986
|
+
runtimeTimings: metrics.snapshot()
|
|
45987
|
+
});
|
|
45988
|
+
} catch (error62) {
|
|
45989
|
+
diagnostics.daemonDiagnostic(
|
|
45990
|
+
"session_prepare_failed",
|
|
45991
|
+
command.requestId,
|
|
45992
|
+
{
|
|
45993
|
+
agentId: command.agentId,
|
|
45994
|
+
code: operationErrorCode(error62),
|
|
45995
|
+
sessionId: command.sessionId
|
|
45996
|
+
},
|
|
45997
|
+
error62
|
|
45998
|
+
);
|
|
45999
|
+
audit.record({
|
|
46000
|
+
commandId: command.requestId,
|
|
46001
|
+
details: {
|
|
46002
|
+
agentId: command.agentId,
|
|
46003
|
+
code: operationErrorCode(error62)
|
|
46004
|
+
},
|
|
46005
|
+
event: "session_prepare_failed",
|
|
46006
|
+
sessionId: command.sessionId
|
|
46007
|
+
});
|
|
46008
|
+
reportOperationFailure(socket, command.requestId, command.sessionId, error62, metrics.snapshot());
|
|
46009
|
+
}
|
|
46010
|
+
}
|
|
46011
|
+
async function executeSessionRestore(socket, command, config2, directories, audit, sessions, nativeSessions, diagnostics, signal) {
|
|
46012
|
+
const metrics = new AccumulatingOperationMetrics();
|
|
46013
|
+
try {
|
|
46014
|
+
const entry = await metrics.measure("session-lookup", async () => {
|
|
46015
|
+
const [found] = await nativeSessions.querySessions([command.sessionId], signal);
|
|
46016
|
+
if (found === void 0) {
|
|
46017
|
+
throw new AcpExecutionError("The Session was not found", {}, "session_not_found");
|
|
46018
|
+
}
|
|
46019
|
+
return found;
|
|
46020
|
+
});
|
|
46021
|
+
const ready = await prepareSession(
|
|
46022
|
+
{
|
|
46023
|
+
additionalDirectoryIds: entry.additionalDirectories.map((directory) => directory.directoryId),
|
|
46024
|
+
agentId: entry.agentId,
|
|
46025
|
+
bindingId: config2.bindingId,
|
|
46026
|
+
directoryId: entry.directoryId,
|
|
46027
|
+
kind: "session.prepare",
|
|
46028
|
+
requestId: command.requestId,
|
|
46029
|
+
sessionId: command.sessionId,
|
|
46030
|
+
sessionState: "provisioned"
|
|
46031
|
+
},
|
|
46032
|
+
{ kind: "history-required" },
|
|
46033
|
+
config2,
|
|
46034
|
+
directories,
|
|
46035
|
+
audit,
|
|
46036
|
+
sessions,
|
|
46037
|
+
metrics,
|
|
46038
|
+
signal
|
|
46039
|
+
);
|
|
46040
|
+
send(socket, {
|
|
46041
|
+
entry,
|
|
46042
|
+
kind: "session.restored",
|
|
46043
|
+
ready: { ...ready, runtimeTimings: metrics.snapshot() },
|
|
46044
|
+
requestId: command.requestId
|
|
46045
|
+
});
|
|
46046
|
+
} catch (error62) {
|
|
46047
|
+
diagnostics.daemonDiagnostic(
|
|
46048
|
+
"session_restore_failed",
|
|
46049
|
+
command.requestId,
|
|
46050
|
+
{
|
|
46051
|
+
code: operationErrorCode(error62),
|
|
46052
|
+
sessionId: command.sessionId
|
|
46053
|
+
},
|
|
46054
|
+
error62
|
|
46055
|
+
);
|
|
46056
|
+
audit.record({
|
|
46057
|
+
commandId: command.requestId,
|
|
46058
|
+
details: { code: operationErrorCode(error62) },
|
|
46059
|
+
event: "session_restore_failed",
|
|
46060
|
+
sessionId: command.sessionId
|
|
46061
|
+
});
|
|
46062
|
+
reportOperationFailure(socket, command.requestId, command.sessionId, error62, metrics.snapshot());
|
|
46063
|
+
}
|
|
46064
|
+
}
|
|
46065
|
+
async function executeSessionConfigure(socket, command, config2, directories, audit, sessions, signal) {
|
|
46066
|
+
try {
|
|
46067
|
+
const resolved = await resolveSessionDirectories(
|
|
46068
|
+
directories,
|
|
46069
|
+
config2.bindingId,
|
|
46070
|
+
command.directoryId,
|
|
46071
|
+
command.additionalDirectoryIds,
|
|
46072
|
+
signal
|
|
46073
|
+
);
|
|
46074
|
+
const configOptions = await sessions.configureSession({
|
|
46075
|
+
additionalDirectories: resolved.additionalDirectories,
|
|
46076
|
+
agent: await resolveCatalogAgent(config2, command.agentId, signal),
|
|
46077
|
+
booleanValue: command.booleanValue,
|
|
46078
|
+
configId: command.configId,
|
|
46079
|
+
cwd: resolved.cwd,
|
|
46080
|
+
requestId: command.requestId,
|
|
46081
|
+
sessionId: command.sessionId,
|
|
46082
|
+
signal,
|
|
46083
|
+
value: command.value,
|
|
46084
|
+
valueType: command.valueType
|
|
46085
|
+
});
|
|
46086
|
+
audit.record({
|
|
46087
|
+
commandId: command.requestId,
|
|
46088
|
+
event: "session_configured",
|
|
46089
|
+
sessionId: command.sessionId
|
|
46090
|
+
});
|
|
46091
|
+
send(socket, {
|
|
46092
|
+
configOptions,
|
|
46093
|
+
kind: "session.config.updated",
|
|
46094
|
+
requestId: command.requestId,
|
|
46095
|
+
sessionId: command.sessionId
|
|
46096
|
+
});
|
|
46097
|
+
} catch (error62) {
|
|
46098
|
+
if (signal.aborted) {
|
|
46099
|
+
signal.throwIfAborted();
|
|
46100
|
+
}
|
|
46101
|
+
reportOperationFailure(socket, command.requestId, command.sessionId, error62);
|
|
46102
|
+
}
|
|
46103
|
+
}
|
|
46104
|
+
|
|
45769
46105
|
// src/daemon-history-commands.ts
|
|
45770
46106
|
async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, directories, audit, diagnostics, sessions, nativeSessions, eventLogV2, signal) {
|
|
45771
46107
|
let agentId;
|
|
@@ -45784,7 +46120,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
45784
46120
|
);
|
|
45785
46121
|
const loadOptions = {
|
|
45786
46122
|
additionalDirectories: resolved.additionalDirectories,
|
|
45787
|
-
agent: config2
|
|
46123
|
+
agent: await resolveCatalogAgent(config2, entry.agentId, signal),
|
|
45788
46124
|
cwd: resolved.cwd,
|
|
45789
46125
|
sessionId: command.sessionId,
|
|
45790
46126
|
signal
|
|
@@ -45860,7 +46196,7 @@ async function executeSessionPreviewHistoryPageLoad(socket, command, config2, di
|
|
|
45860
46196
|
const replay = await sessions.previewNativeSessionEventsV2(
|
|
45861
46197
|
{
|
|
45862
46198
|
additionalDirectories: resolved.additionalDirectories,
|
|
45863
|
-
agent: config2
|
|
46199
|
+
agent: await resolveCatalogAgent(config2, command.agentId, signal),
|
|
45864
46200
|
cwd: resolved.cwd,
|
|
45865
46201
|
sessionId: command.sessionId,
|
|
45866
46202
|
signal
|
|
@@ -46152,7 +46488,7 @@ async function executePrompt({
|
|
|
46152
46488
|
command.additionalDirectoryIds,
|
|
46153
46489
|
signal
|
|
46154
46490
|
);
|
|
46155
|
-
const agent = config2
|
|
46491
|
+
const agent = await resolveCatalogAgent(config2, command.agentId, signal);
|
|
46156
46492
|
const availability = await waitForSessionAvailability(signal);
|
|
46157
46493
|
if (availability.kind === "busy") {
|
|
46158
46494
|
throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
|
|
@@ -46297,228 +46633,6 @@ async function executePrompt({
|
|
|
46297
46633
|
}
|
|
46298
46634
|
}
|
|
46299
46635
|
|
|
46300
|
-
// src/daemon-session-commands.ts
|
|
46301
|
-
async function prepareSession(command, recovery, config2, directories, audit, sessions, metrics, signal) {
|
|
46302
|
-
return await metrics.measure("prepare-total", async () => {
|
|
46303
|
-
const resolved = await metrics.measure(
|
|
46304
|
-
"workspace-resolve",
|
|
46305
|
-
async () => await resolveSessionDirectories(
|
|
46306
|
-
directories,
|
|
46307
|
-
config2.bindingId,
|
|
46308
|
-
command.directoryId,
|
|
46309
|
-
command.additionalDirectoryIds,
|
|
46310
|
-
signal
|
|
46311
|
-
)
|
|
46312
|
-
);
|
|
46313
|
-
const agent = config2.catalog.find(command.agentId);
|
|
46314
|
-
const preparation = {
|
|
46315
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
46316
|
-
agent,
|
|
46317
|
-
cwd: resolved.cwd,
|
|
46318
|
-
sessionId: command.sessionId,
|
|
46319
|
-
signal
|
|
46320
|
-
};
|
|
46321
|
-
const prepared = command.transient === true ? await sessions.inspectSession(preparation, metrics) : recovery.kind === "history-required" ? await sessions.restoreSession(preparation, metrics) : await sessions.prepareSession(preparation, metrics);
|
|
46322
|
-
const configuration = command.configuration;
|
|
46323
|
-
const configOptions = configuration === void 0 ? prepared.configOptions : await metrics.measure(
|
|
46324
|
-
"configuration",
|
|
46325
|
-
async () => await sessions.configureSession({
|
|
46326
|
-
...preparation,
|
|
46327
|
-
booleanValue: configuration.booleanValue,
|
|
46328
|
-
configId: configuration.configId,
|
|
46329
|
-
requestId: command.requestId,
|
|
46330
|
-
value: configuration.value,
|
|
46331
|
-
valueType: configuration.valueType
|
|
46332
|
-
})
|
|
46333
|
-
);
|
|
46334
|
-
const listing = await metrics.measure(
|
|
46335
|
-
"workspace-list",
|
|
46336
|
-
async () => await directories.list(config2.bindingId, command.directoryId, signal)
|
|
46337
|
-
);
|
|
46338
|
-
audit.record({
|
|
46339
|
-
commandId: command.requestId,
|
|
46340
|
-
event: "session_prepared",
|
|
46341
|
-
sessionId: command.sessionId
|
|
46342
|
-
});
|
|
46343
|
-
if (command.configuration !== void 0) {
|
|
46344
|
-
audit.record({
|
|
46345
|
-
commandId: command.requestId,
|
|
46346
|
-
event: "session_configured",
|
|
46347
|
-
sessionId: command.sessionId
|
|
46348
|
-
});
|
|
46349
|
-
}
|
|
46350
|
-
return {
|
|
46351
|
-
additionalDirectories: resolved.additionalDirectoryEntries,
|
|
46352
|
-
agentId: command.agentId,
|
|
46353
|
-
agentName: prepared.agentName,
|
|
46354
|
-
agentVersion: prepared.agentVersion,
|
|
46355
|
-
capabilities: prepared.capabilities,
|
|
46356
|
-
commands: prepared.commands,
|
|
46357
|
-
configOptions,
|
|
46358
|
-
directoryId: command.directoryId,
|
|
46359
|
-
directoryLabel: listing.directoryLabel,
|
|
46360
|
-
kind: "session.ready",
|
|
46361
|
-
requestId: command.requestId,
|
|
46362
|
-
restored: prepared.restored,
|
|
46363
|
-
sessionId: command.sessionId
|
|
46364
|
-
};
|
|
46365
|
-
});
|
|
46366
|
-
}
|
|
46367
|
-
async function executeWorkspaceList(socket, command, directories, audit, signal) {
|
|
46368
|
-
try {
|
|
46369
|
-
const listing = await directories.list(command.bindingId, command.directoryId, signal);
|
|
46370
|
-
audit.record({
|
|
46371
|
-
commandId: command.requestId,
|
|
46372
|
-
event: "workspace_list_authorized",
|
|
46373
|
-
sessionId: "workspace-browser"
|
|
46374
|
-
});
|
|
46375
|
-
send(socket, {
|
|
46376
|
-
bindingId: command.bindingId,
|
|
46377
|
-
directoryId: listing.directoryId,
|
|
46378
|
-
directoryLabel: listing.directoryLabel,
|
|
46379
|
-
entries: listing.entries,
|
|
46380
|
-
kind: "workspace.entries",
|
|
46381
|
-
parentDirectoryId: listing.parentDirectoryId,
|
|
46382
|
-
requestId: command.requestId
|
|
46383
|
-
});
|
|
46384
|
-
} catch (error62) {
|
|
46385
|
-
reportOperationFailure(socket, command.requestId, "", error62);
|
|
46386
|
-
}
|
|
46387
|
-
}
|
|
46388
|
-
async function executeSessionPrepare(socket, command, config2, directories, audit, sessions, diagnostics, signal) {
|
|
46389
|
-
const metrics = new AccumulatingOperationMetrics();
|
|
46390
|
-
try {
|
|
46391
|
-
const readyEvent = await prepareSession(
|
|
46392
|
-
command,
|
|
46393
|
-
{ kind: "interactive-only" },
|
|
46394
|
-
config2,
|
|
46395
|
-
directories,
|
|
46396
|
-
audit,
|
|
46397
|
-
sessions,
|
|
46398
|
-
metrics,
|
|
46399
|
-
signal
|
|
46400
|
-
);
|
|
46401
|
-
send(socket, {
|
|
46402
|
-
...readyEvent,
|
|
46403
|
-
runtimeTimings: metrics.snapshot()
|
|
46404
|
-
});
|
|
46405
|
-
} catch (error62) {
|
|
46406
|
-
diagnostics.daemonDiagnostic(
|
|
46407
|
-
"session_prepare_failed",
|
|
46408
|
-
command.requestId,
|
|
46409
|
-
{
|
|
46410
|
-
agentId: command.agentId,
|
|
46411
|
-
code: operationErrorCode(error62),
|
|
46412
|
-
sessionId: command.sessionId
|
|
46413
|
-
},
|
|
46414
|
-
error62
|
|
46415
|
-
);
|
|
46416
|
-
audit.record({
|
|
46417
|
-
commandId: command.requestId,
|
|
46418
|
-
details: {
|
|
46419
|
-
agentId: command.agentId,
|
|
46420
|
-
code: operationErrorCode(error62)
|
|
46421
|
-
},
|
|
46422
|
-
event: "session_prepare_failed",
|
|
46423
|
-
sessionId: command.sessionId
|
|
46424
|
-
});
|
|
46425
|
-
reportOperationFailure(socket, command.requestId, command.sessionId, error62, metrics.snapshot());
|
|
46426
|
-
}
|
|
46427
|
-
}
|
|
46428
|
-
async function executeSessionRestore(socket, command, config2, directories, audit, sessions, nativeSessions, diagnostics, signal) {
|
|
46429
|
-
const metrics = new AccumulatingOperationMetrics();
|
|
46430
|
-
try {
|
|
46431
|
-
const entry = await metrics.measure("session-lookup", async () => {
|
|
46432
|
-
const [found] = await nativeSessions.querySessions([command.sessionId], signal);
|
|
46433
|
-
if (found === void 0) {
|
|
46434
|
-
throw new AcpExecutionError("The Session was not found", {}, "session_not_found");
|
|
46435
|
-
}
|
|
46436
|
-
return found;
|
|
46437
|
-
});
|
|
46438
|
-
const ready = await prepareSession(
|
|
46439
|
-
{
|
|
46440
|
-
additionalDirectoryIds: entry.additionalDirectories.map((directory) => directory.directoryId),
|
|
46441
|
-
agentId: entry.agentId,
|
|
46442
|
-
bindingId: config2.bindingId,
|
|
46443
|
-
directoryId: entry.directoryId,
|
|
46444
|
-
kind: "session.prepare",
|
|
46445
|
-
requestId: command.requestId,
|
|
46446
|
-
sessionId: command.sessionId,
|
|
46447
|
-
sessionState: "provisioned"
|
|
46448
|
-
},
|
|
46449
|
-
{ kind: "history-required" },
|
|
46450
|
-
config2,
|
|
46451
|
-
directories,
|
|
46452
|
-
audit,
|
|
46453
|
-
sessions,
|
|
46454
|
-
metrics,
|
|
46455
|
-
signal
|
|
46456
|
-
);
|
|
46457
|
-
send(socket, {
|
|
46458
|
-
entry,
|
|
46459
|
-
kind: "session.restored",
|
|
46460
|
-
ready: { ...ready, runtimeTimings: metrics.snapshot() },
|
|
46461
|
-
requestId: command.requestId
|
|
46462
|
-
});
|
|
46463
|
-
} catch (error62) {
|
|
46464
|
-
diagnostics.daemonDiagnostic(
|
|
46465
|
-
"session_restore_failed",
|
|
46466
|
-
command.requestId,
|
|
46467
|
-
{
|
|
46468
|
-
code: operationErrorCode(error62),
|
|
46469
|
-
sessionId: command.sessionId
|
|
46470
|
-
},
|
|
46471
|
-
error62
|
|
46472
|
-
);
|
|
46473
|
-
audit.record({
|
|
46474
|
-
commandId: command.requestId,
|
|
46475
|
-
details: { code: operationErrorCode(error62) },
|
|
46476
|
-
event: "session_restore_failed",
|
|
46477
|
-
sessionId: command.sessionId
|
|
46478
|
-
});
|
|
46479
|
-
reportOperationFailure(socket, command.requestId, command.sessionId, error62, metrics.snapshot());
|
|
46480
|
-
}
|
|
46481
|
-
}
|
|
46482
|
-
async function executeSessionConfigure(socket, command, config2, directories, audit, sessions, signal) {
|
|
46483
|
-
try {
|
|
46484
|
-
const resolved = await resolveSessionDirectories(
|
|
46485
|
-
directories,
|
|
46486
|
-
config2.bindingId,
|
|
46487
|
-
command.directoryId,
|
|
46488
|
-
command.additionalDirectoryIds,
|
|
46489
|
-
signal
|
|
46490
|
-
);
|
|
46491
|
-
const configOptions = await sessions.configureSession({
|
|
46492
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
46493
|
-
agent: config2.catalog.find(command.agentId),
|
|
46494
|
-
booleanValue: command.booleanValue,
|
|
46495
|
-
configId: command.configId,
|
|
46496
|
-
cwd: resolved.cwd,
|
|
46497
|
-
requestId: command.requestId,
|
|
46498
|
-
sessionId: command.sessionId,
|
|
46499
|
-
signal,
|
|
46500
|
-
value: command.value,
|
|
46501
|
-
valueType: command.valueType
|
|
46502
|
-
});
|
|
46503
|
-
audit.record({
|
|
46504
|
-
commandId: command.requestId,
|
|
46505
|
-
event: "session_configured",
|
|
46506
|
-
sessionId: command.sessionId
|
|
46507
|
-
});
|
|
46508
|
-
send(socket, {
|
|
46509
|
-
configOptions,
|
|
46510
|
-
kind: "session.config.updated",
|
|
46511
|
-
requestId: command.requestId,
|
|
46512
|
-
sessionId: command.sessionId
|
|
46513
|
-
});
|
|
46514
|
-
} catch (error62) {
|
|
46515
|
-
if (signal.aborted) {
|
|
46516
|
-
signal.throwIfAborted();
|
|
46517
|
-
}
|
|
46518
|
-
reportOperationFailure(socket, command.requestId, command.sessionId, error62);
|
|
46519
|
-
}
|
|
46520
|
-
}
|
|
46521
|
-
|
|
46522
46636
|
// src/native-sessions/handle-native-requests.ts
|
|
46523
46637
|
import { WebSocket as WebSocket4 } from "undici";
|
|
46524
46638
|
function createNativeSessionRequestHandler(dependencies) {
|
|
@@ -47711,11 +47825,11 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
47711
47825
|
stateDirectory
|
|
47712
47826
|
});
|
|
47713
47827
|
const channelHash = createHash8("sha256").update(config2.channelId).digest("hex");
|
|
47714
|
-
const sessionDatabase = openAcpSessionDatabase(
|
|
47828
|
+
const sessionDatabase = openAcpSessionDatabase(join21(stateDirectory, "sessions", `${channelHash}.sqlite`));
|
|
47715
47829
|
let eventsV2;
|
|
47716
47830
|
try {
|
|
47717
47831
|
eventsV2 = new CachedAcpSessionEventStoreV2(
|
|
47718
|
-
openSessionEventCacheV2Database(
|
|
47832
|
+
openSessionEventCacheV2Database(join21(stateDirectory, "sessions", `${channelHash}.events.sqlite`))
|
|
47719
47833
|
);
|
|
47720
47834
|
} catch (error62) {
|
|
47721
47835
|
sessionDatabase.close();
|
|
@@ -47982,7 +48096,7 @@ var START_TIMEOUT_MILLISECONDS = 12e4;
|
|
|
47982
48096
|
var MAXIMUM_MESSAGE_BYTES = 64 * 1024;
|
|
47983
48097
|
var CONNECTION_ID_PATTERN2 = /^mcn_[a-f0-9]{32}$/;
|
|
47984
48098
|
async function acquireManagerLock(stateDirectory) {
|
|
47985
|
-
const path3 =
|
|
48099
|
+
const path3 = join22(stateDirectory, "manager.lock");
|
|
47986
48100
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
47987
48101
|
try {
|
|
47988
48102
|
await writeFile5(path3, `${process.pid.toString()}
|
|
@@ -48014,10 +48128,10 @@ function isRecord12(value) {
|
|
|
48014
48128
|
}
|
|
48015
48129
|
function controlSocketPath(stateDirectory) {
|
|
48016
48130
|
const installationHash = createHash9("sha256").update(stateDirectory).digest("hex").slice(0, 32);
|
|
48017
|
-
return process.platform === "win32" ? `\\\\.\\pipe\\mobius-${installationHash}` :
|
|
48131
|
+
return process.platform === "win32" ? `\\\\.\\pipe\\mobius-${installationHash}` : join22(tmpdir(), `mobius-${installationHash}.sock`);
|
|
48018
48132
|
}
|
|
48019
48133
|
function controlTokenPath(stateDirectory) {
|
|
48020
|
-
return
|
|
48134
|
+
return join22(stateDirectory, "manager.token");
|
|
48021
48135
|
}
|
|
48022
48136
|
async function readOrCreateControlToken(stateDirectory) {
|
|
48023
48137
|
const path3 = controlTokenPath(stateDirectory);
|
|
@@ -48349,7 +48463,7 @@ async function waitForManagerExit(stateDirectory, signal) {
|
|
|
48349
48463
|
const deadline = AbortSignal.any([signal, AbortSignal.timeout(1e4)]);
|
|
48350
48464
|
while (!deadline.aborted) {
|
|
48351
48465
|
try {
|
|
48352
|
-
await readFile3(
|
|
48466
|
+
await readFile3(join22(stateDirectory, "manager.lock"), "utf8");
|
|
48353
48467
|
} catch (cause) {
|
|
48354
48468
|
if (isNodeError2(cause, "ENOENT")) {
|
|
48355
48469
|
return;
|
|
@@ -48586,7 +48700,7 @@ async function writePairList(path3, pairs) {
|
|
|
48586
48700
|
shutdown.signal.throwIfAborted();
|
|
48587
48701
|
let file2;
|
|
48588
48702
|
try {
|
|
48589
|
-
file2 = await open6(path3,
|
|
48703
|
+
file2 = await open6(path3, constants3.O_WRONLY | constants3.O_NOFOLLOW);
|
|
48590
48704
|
} catch (cause) {
|
|
48591
48705
|
if (typeof cause === "object" && cause !== null && "code" in cause && cause.code === "ENOENT") {
|
|
48592
48706
|
throw new Error("The JSON output file does not exist", { cause });
|