conbridge-agent 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/conbridge-agent-keychain +0 -0
- package/conbridge-agent.cjs +370 -124
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# conbridge-agent
|
|
2
2
|
|
|
3
|
-
ConBridge Desktop Agent 0.
|
|
3
|
+
ConBridge Desktop Agent 0.2.0: connects a computer or server to ConBridge so the AI apps you approve (ChatGPT,
|
|
4
4
|
Claude) can use the folders you share, or, with full access, its terminal. macOS, Linux (servers too), Raspberry Pi and
|
|
5
5
|
Windows; Node.js 22 or later.
|
|
6
6
|
|
package/conbridge-agent-keychain
CHANGED
|
Binary file
|
package/conbridge-agent.cjs
CHANGED
|
@@ -28,14 +28,14 @@ __export(cli_exports, {
|
|
|
28
28
|
module.exports = __toCommonJS(cli_exports);
|
|
29
29
|
|
|
30
30
|
// <define:__CONBRIDGE_BUILD__>
|
|
31
|
-
var define_CONBRIDGE_BUILD_default = { version: "0.
|
|
31
|
+
var define_CONBRIDGE_BUILD_default = { version: "0.2.0", commit: "d90329e5f24e", built_at: "2026-10-23T11:28:00.961Z", keychain_helper_sha256: "359d0b3f3fedc26561d0e0b27a93df624fa55c1519c120e23fae46e9f2c2dc6a", distribution: "npm" };
|
|
32
32
|
|
|
33
33
|
// dist/cli.js
|
|
34
34
|
var import_node_child_process9 = require("node:child_process");
|
|
35
35
|
var import_node_crypto10 = require("node:crypto");
|
|
36
36
|
var import_node_fs3 = require("node:fs");
|
|
37
|
-
var
|
|
38
|
-
var
|
|
37
|
+
var import_promises14 = require("node:fs/promises");
|
|
38
|
+
var import_node_os7 = require("node:os");
|
|
39
39
|
var import_node_path17 = require("node:path");
|
|
40
40
|
var import_node_url3 = require("node:url");
|
|
41
41
|
var import_node_util2 = require("node:util");
|
|
@@ -1254,16 +1254,16 @@ function cleanEnum(obj) {
|
|
|
1254
1254
|
}
|
|
1255
1255
|
function base64ToUint8Array(base644) {
|
|
1256
1256
|
const binaryString = atob(base644);
|
|
1257
|
-
const
|
|
1257
|
+
const bytes2 = new Uint8Array(binaryString.length);
|
|
1258
1258
|
for (let i = 0; i < binaryString.length; i++) {
|
|
1259
|
-
|
|
1259
|
+
bytes2[i] = binaryString.charCodeAt(i);
|
|
1260
1260
|
}
|
|
1261
|
-
return
|
|
1261
|
+
return bytes2;
|
|
1262
1262
|
}
|
|
1263
|
-
function uint8ArrayToBase64(
|
|
1263
|
+
function uint8ArrayToBase64(bytes2) {
|
|
1264
1264
|
let binaryString = "";
|
|
1265
|
-
for (let i = 0; i <
|
|
1266
|
-
binaryString += String.fromCharCode(
|
|
1265
|
+
for (let i = 0; i < bytes2.length; i++) {
|
|
1266
|
+
binaryString += String.fromCharCode(bytes2[i]);
|
|
1267
1267
|
}
|
|
1268
1268
|
return btoa(binaryString);
|
|
1269
1269
|
}
|
|
@@ -1272,22 +1272,22 @@ function base64urlToUint8Array(base64url3) {
|
|
|
1272
1272
|
const padding = "=".repeat((4 - base644.length % 4) % 4);
|
|
1273
1273
|
return base64ToUint8Array(base644 + padding);
|
|
1274
1274
|
}
|
|
1275
|
-
function uint8ArrayToBase64url(
|
|
1276
|
-
return uint8ArrayToBase64(
|
|
1275
|
+
function uint8ArrayToBase64url(bytes2) {
|
|
1276
|
+
return uint8ArrayToBase64(bytes2).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
1277
1277
|
}
|
|
1278
1278
|
function hexToUint8Array(hex3) {
|
|
1279
1279
|
const cleanHex = hex3.replace(/^0x/, "");
|
|
1280
1280
|
if (cleanHex.length % 2 !== 0) {
|
|
1281
1281
|
throw new Error("Invalid hex string length");
|
|
1282
1282
|
}
|
|
1283
|
-
const
|
|
1283
|
+
const bytes2 = new Uint8Array(cleanHex.length / 2);
|
|
1284
1284
|
for (let i = 0; i < cleanHex.length; i += 2) {
|
|
1285
|
-
|
|
1285
|
+
bytes2[i / 2] = Number.parseInt(cleanHex.slice(i, i + 2), 16);
|
|
1286
1286
|
}
|
|
1287
|
-
return
|
|
1287
|
+
return bytes2;
|
|
1288
1288
|
}
|
|
1289
|
-
function uint8ArrayToHex(
|
|
1290
|
-
return Array.from(
|
|
1289
|
+
function uint8ArrayToHex(bytes2) {
|
|
1290
|
+
return Array.from(bytes2).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1291
1291
|
}
|
|
1292
1292
|
var Class = class {
|
|
1293
1293
|
constructor(..._args) {
|
|
@@ -12642,6 +12642,20 @@ function date4(params) {
|
|
|
12642
12642
|
// ../../node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/external.js
|
|
12643
12643
|
config(en_default());
|
|
12644
12644
|
|
|
12645
|
+
// ../../packages/protocol/dist/monitoring.js
|
|
12646
|
+
var MONITOR_INTERVALS_S = [60, 300, 900, 1800, 3600];
|
|
12647
|
+
var MONITOR_RETENTION_DAYS = [1, 7, 30, 90];
|
|
12648
|
+
var MONITOR_DEFAULTS = Object.freeze({ enabled: false, interval_s: 300, retention_days: 7 });
|
|
12649
|
+
var MONITOR_RANGES = ["1h", "24h", "7d", "30d", "90d"];
|
|
12650
|
+
var monitorIntervalSchema = external_exports.literal([...MONITOR_INTERVALS_S]);
|
|
12651
|
+
var monitorRetentionDaysSchema = external_exports.literal([...MONITOR_RETENTION_DAYS]);
|
|
12652
|
+
var monitorRangeSchema = external_exports.enum(MONITOR_RANGES);
|
|
12653
|
+
var monitorSettingsSchema = external_exports.strictObject({
|
|
12654
|
+
enabled: external_exports.boolean(),
|
|
12655
|
+
interval_s: monitorIntervalSchema,
|
|
12656
|
+
retention_days: monitorRetentionDaysSchema
|
|
12657
|
+
});
|
|
12658
|
+
|
|
12645
12659
|
// ../../packages/protocol/dist/wire.js
|
|
12646
12660
|
var WIRE_VERSION = 1;
|
|
12647
12661
|
var MAX_ENVELOPE_BYTES = 65536;
|
|
@@ -12782,6 +12796,22 @@ var error46 = base.extend({
|
|
|
12782
12796
|
retryable: external_exports.boolean(),
|
|
12783
12797
|
safe_message: external_exports.string().min(1).max(256)
|
|
12784
12798
|
});
|
|
12799
|
+
var bytes = external_exports.number().int().nonnegative();
|
|
12800
|
+
var monitorConfig = base.extend({
|
|
12801
|
+
kind: external_exports.literal("MONITOR_CONFIG"),
|
|
12802
|
+
enabled: external_exports.boolean(),
|
|
12803
|
+
interval_s: external_exports.literal([...MONITOR_INTERVALS_S])
|
|
12804
|
+
});
|
|
12805
|
+
var metrics = base.extend({
|
|
12806
|
+
kind: external_exports.literal("METRICS"),
|
|
12807
|
+
cpu_pct: external_exports.number().min(0).max(100),
|
|
12808
|
+
load_1: external_exports.number().min(0).max(1e5).nullable(),
|
|
12809
|
+
mem_used_bytes: bytes,
|
|
12810
|
+
mem_total_bytes: bytes,
|
|
12811
|
+
disk_used_bytes: bytes,
|
|
12812
|
+
disk_total_bytes: bytes,
|
|
12813
|
+
uptime_s: external_exports.number().int().nonnegative()
|
|
12814
|
+
});
|
|
12785
12815
|
var envelopeSchema = external_exports.discriminatedUnion("kind", [
|
|
12786
12816
|
hello,
|
|
12787
12817
|
enroll,
|
|
@@ -12793,7 +12823,9 @@ var envelopeSchema = external_exports.discriminatedUnion("kind", [
|
|
|
12793
12823
|
result,
|
|
12794
12824
|
chunk,
|
|
12795
12825
|
cancel,
|
|
12796
|
-
error46
|
|
12826
|
+
error46,
|
|
12827
|
+
monitorConfig,
|
|
12828
|
+
metrics
|
|
12797
12829
|
]);
|
|
12798
12830
|
var SUPPORTED_VERSIONS = Object.freeze([WIRE_VERSION]);
|
|
12799
12831
|
var ProtocolDecodeError = class extends Error {
|
|
@@ -12819,7 +12851,7 @@ function sizedJson(value) {
|
|
|
12819
12851
|
return text;
|
|
12820
12852
|
}
|
|
12821
12853
|
function requireSemanticConstraints(message) {
|
|
12822
|
-
if (message.kind === "HELLO" || message.kind === "ENROLL" || message.kind === "HEARTBEAT" || message.kind === "NEGOTIATE" || message.kind === "INVENTORY") {
|
|
12854
|
+
if (message.kind === "HELLO" || message.kind === "ENROLL" || message.kind === "HEARTBEAT" || message.kind === "NEGOTIATE" || message.kind === "INVENTORY" || message.kind === "MONITOR_CONFIG" || message.kind === "METRICS") {
|
|
12823
12855
|
if (message.task_id !== null)
|
|
12824
12856
|
throw new ProtocolDecodeError("INVALID_MESSAGE", "Control message must not include a task");
|
|
12825
12857
|
} else if (message.kind !== "ERROR" && message.task_id === null) {
|
|
@@ -12833,6 +12865,9 @@ function requireSemanticConstraints(message) {
|
|
|
12833
12865
|
throw new ProtocolDecodeError("INVALID_MESSAGE", "on_behalf_of must name a user other than the device owner");
|
|
12834
12866
|
}
|
|
12835
12867
|
}
|
|
12868
|
+
if (message.kind === "METRICS" && (message.mem_total_bytes === 0 || message.disk_total_bytes === 0 || message.mem_used_bytes > message.mem_total_bytes || message.disk_used_bytes > message.disk_total_bytes)) {
|
|
12869
|
+
throw new ProtocolDecodeError("INVALID_MESSAGE", "METRICS totals must be positive and cover the used bytes");
|
|
12870
|
+
}
|
|
12836
12871
|
if (message.kind === "RESULT" && message.state === "UNKNOWN" && (message.executed !== void 0 || message.exit_code !== void 0)) {
|
|
12837
12872
|
throw new ProtocolDecodeError("INVALID_MESSAGE", "UNKNOWN cannot claim execution or exit status");
|
|
12838
12873
|
}
|
|
@@ -13355,8 +13390,8 @@ var editApply = external_exports.strictObject({
|
|
|
13355
13390
|
if (value.expected_sha256 === void 0 && value.expected_version === void 0) {
|
|
13356
13391
|
ctx.addIssue({ code: "custom", message: "expected_sha256 or expected_version is required" });
|
|
13357
13392
|
}
|
|
13358
|
-
const
|
|
13359
|
-
if (
|
|
13393
|
+
const bytes2 = value.content !== void 0 ? utf82.encode(value.content).byteLength : (value.replacements ?? []).reduce((total, entry) => total + utf82.encode(entry.text).byteLength, 0);
|
|
13394
|
+
if (bytes2 > MAX_VSCODE_EDIT_BYTES)
|
|
13360
13395
|
ctx.addIssue({ code: "custom", message: `New text exceeds ${MAX_VSCODE_EDIT_BYTES} bytes` });
|
|
13361
13396
|
const problem = value.replacements ? replacementsProblem(value.replacements) : null;
|
|
13362
13397
|
if (problem)
|
|
@@ -13562,8 +13597,8 @@ function canonicalJson(value) {
|
|
|
13562
13597
|
return "{" + entries.join(",") + "}";
|
|
13563
13598
|
}
|
|
13564
13599
|
async function sha256Hex(input) {
|
|
13565
|
-
const
|
|
13566
|
-
const digest = await crypto.subtle.digest("SHA-256",
|
|
13600
|
+
const bytes2 = typeof input === "string" ? new TextEncoder().encode(input) : new Uint8Array(input);
|
|
13601
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes2);
|
|
13567
13602
|
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
13568
13603
|
}
|
|
13569
13604
|
async function grantSigningMessage(dispatch2) {
|
|
@@ -13609,9 +13644,9 @@ var relayAuthOkSchema = external_exports.strictObject({
|
|
|
13609
13644
|
device_uuid: external_exports.uuid(),
|
|
13610
13645
|
connection_epoch: external_exports.number().int().nonnegative()
|
|
13611
13646
|
});
|
|
13612
|
-
function toBase64Url(
|
|
13647
|
+
function toBase64Url(bytes2) {
|
|
13613
13648
|
let binary = "";
|
|
13614
|
-
for (const byte of
|
|
13649
|
+
for (const byte of bytes2)
|
|
13615
13650
|
binary += String.fromCharCode(byte);
|
|
13616
13651
|
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
13617
13652
|
}
|
|
@@ -13686,7 +13721,7 @@ var import_node_fs = require("node:fs");
|
|
|
13686
13721
|
var import_node_path2 = require("node:path");
|
|
13687
13722
|
var import_node_sea = require("node:sea");
|
|
13688
13723
|
var import_node_url = require("node:url");
|
|
13689
|
-
var SOURCE_VERSION = "0.
|
|
13724
|
+
var SOURCE_VERSION = "0.2.0";
|
|
13690
13725
|
var BUILD_INFO = typeof define_CONBRIDGE_BUILD_default === "object" && define_CONBRIDGE_BUILD_default !== null ? define_CONBRIDGE_BUILD_default : null;
|
|
13691
13726
|
var AGENT_VERSION = BUILD_INFO?.version ?? SOURCE_VERSION;
|
|
13692
13727
|
function runningAsSea() {
|
|
@@ -13729,8 +13764,8 @@ function createLogger(stream = process.stderr) {
|
|
|
13729
13764
|
};
|
|
13730
13765
|
}
|
|
13731
13766
|
var silentLogger = { info: () => void 0, warn: () => void 0, error: () => void 0 };
|
|
13732
|
-
function randomToken(
|
|
13733
|
-
return (0, import_node_crypto.randomBytes)(
|
|
13767
|
+
function randomToken(bytes2 = 16) {
|
|
13768
|
+
return (0, import_node_crypto.randomBytes)(bytes2).toString("base64url");
|
|
13734
13769
|
}
|
|
13735
13770
|
async function fsyncDirectory(path) {
|
|
13736
13771
|
let handle;
|
|
@@ -14586,7 +14621,7 @@ var macConnectDialogs = {
|
|
|
14586
14621
|
async confirmConnect(host, name2, replacing) {
|
|
14587
14622
|
const text = (replacing ? "This Mac is already connected. Connecting again replaces that connection.\n\n" : "") + `Connect this Mac to ConBridge?
|
|
14588
14623
|
|
|
14589
|
-
Your AI apps can use only the folders you choose,
|
|
14624
|
+
Your AI apps can use only the folders you choose, with the permissions you set in ConBridge.
|
|
14590
14625
|
|
|
14591
14626
|
Address: ${host}
|
|
14592
14627
|
Name: ${name2}`;
|
|
@@ -15241,7 +15276,7 @@ async function acquireLock(path) {
|
|
|
15241
15276
|
}
|
|
15242
15277
|
|
|
15243
15278
|
// dist/runner.js
|
|
15244
|
-
var
|
|
15279
|
+
var import_node_os6 = require("node:os");
|
|
15245
15280
|
|
|
15246
15281
|
// dist/dispatcher.js
|
|
15247
15282
|
var import_node_crypto7 = require("node:crypto");
|
|
@@ -15415,26 +15450,26 @@ function mapFsError(error47, path) {
|
|
|
15415
15450
|
return new FileOpError("IO_ERROR", "Permission denied by the local file system", { path });
|
|
15416
15451
|
return new FileOpError("IO_ERROR", "Local file system error", { path });
|
|
15417
15452
|
}
|
|
15418
|
-
function trimUtf8Tail(
|
|
15419
|
-
const end =
|
|
15453
|
+
function trimUtf8Tail(bytes2) {
|
|
15454
|
+
const end = bytes2.length;
|
|
15420
15455
|
let index = end - 1;
|
|
15421
15456
|
let continuation = 0;
|
|
15422
|
-
while (index >= 0 && continuation < 3 && (
|
|
15457
|
+
while (index >= 0 && continuation < 3 && (bytes2[index] & 192) === 128) {
|
|
15423
15458
|
index -= 1;
|
|
15424
15459
|
continuation += 1;
|
|
15425
15460
|
}
|
|
15426
15461
|
if (index < 0)
|
|
15427
|
-
return
|
|
15428
|
-
const lead =
|
|
15462
|
+
return bytes2;
|
|
15463
|
+
const lead = bytes2[index];
|
|
15429
15464
|
const expected = lead >= 240 ? 4 : lead >= 224 ? 3 : lead >= 192 ? 2 : 1;
|
|
15430
|
-
return index + expected > end ?
|
|
15465
|
+
return index + expected > end ? bytes2.subarray(0, index) : bytes2;
|
|
15431
15466
|
}
|
|
15432
15467
|
var strictDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
15433
|
-
function decodeText(
|
|
15434
|
-
if (
|
|
15468
|
+
function decodeText(bytes2) {
|
|
15469
|
+
if (bytes2.includes(0))
|
|
15435
15470
|
return null;
|
|
15436
15471
|
try {
|
|
15437
|
-
return strictDecoder.decode(
|
|
15472
|
+
return strictDecoder.decode(bytes2);
|
|
15438
15473
|
} catch {
|
|
15439
15474
|
return null;
|
|
15440
15475
|
}
|
|
@@ -15452,8 +15487,8 @@ async function hashHandle(handle) {
|
|
|
15452
15487
|
}
|
|
15453
15488
|
return hash2.digest("hex");
|
|
15454
15489
|
}
|
|
15455
|
-
function sha256OfBytes(
|
|
15456
|
-
return (0, import_node_crypto6.createHash)("sha256").update(
|
|
15490
|
+
function sha256OfBytes(bytes2) {
|
|
15491
|
+
return (0, import_node_crypto6.createHash)("sha256").update(bytes2).digest("hex");
|
|
15457
15492
|
}
|
|
15458
15493
|
var RootedFs = class {
|
|
15459
15494
|
#root;
|
|
@@ -15795,7 +15830,7 @@ var RootedFs = class {
|
|
|
15795
15830
|
return { rel, rootReal, parentReal, name: name2, target };
|
|
15796
15831
|
}
|
|
15797
15832
|
/** Temp file in the same directory, fsync, re-check the version, rename over the target. */
|
|
15798
|
-
async #replaceAtomic(rel, rootReal, parentReal, name2, target, before,
|
|
15833
|
+
async #replaceAtomic(rel, rootReal, parentReal, name2, target, before, bytes2) {
|
|
15799
15834
|
const temp = (0, import_node_path11.join)(parentReal, `.${name2}.conbridge-${randomToken(8)}.tmp`);
|
|
15800
15835
|
let handle;
|
|
15801
15836
|
try {
|
|
@@ -15808,7 +15843,7 @@ var RootedFs = class {
|
|
|
15808
15843
|
try {
|
|
15809
15844
|
if (before.mode !== null)
|
|
15810
15845
|
await handle.chmod(before.mode);
|
|
15811
|
-
await handle.writeFile(
|
|
15846
|
+
await handle.writeFile(bytes2);
|
|
15812
15847
|
await handle.sync();
|
|
15813
15848
|
} finally {
|
|
15814
15849
|
await handle.close();
|
|
@@ -15845,9 +15880,9 @@ var RootedFs = class {
|
|
|
15845
15880
|
if (before.sha256 !== expectedSha256) {
|
|
15846
15881
|
throw new FileOpError("WORKSPACE_VERSION_CONFLICT", "File changed since it was read", { path: rel, current_sha256: before.sha256 });
|
|
15847
15882
|
}
|
|
15848
|
-
const
|
|
15849
|
-
await this.#replaceAtomic(rel, rootReal, parentReal, name2, target, before,
|
|
15850
|
-
return { path: rel, sha256_after: sha256OfBytes(
|
|
15883
|
+
const bytes2 = Buffer.from(content2, "utf8");
|
|
15884
|
+
await this.#replaceAtomic(rel, rootReal, parentReal, name2, target, before, bytes2);
|
|
15885
|
+
return { path: rel, sha256_after: sha256OfBytes(bytes2), bytes: bytes2.length, created: before.sha256 === null };
|
|
15851
15886
|
}
|
|
15852
15887
|
/** Size, dates and type of a file or directory; files up to 8 MiB also get their sha256 (for edit and delete). */
|
|
15853
15888
|
async info(input) {
|
|
@@ -15912,9 +15947,9 @@ var RootedFs = class {
|
|
|
15912
15947
|
if (found !== expectedReplacements) {
|
|
15913
15948
|
throw new FileOpError("EDIT_MISMATCH", `old_text was found ${found} times, expected ${expectedReplacements}`, { path: rel, found });
|
|
15914
15949
|
}
|
|
15915
|
-
const
|
|
15916
|
-
await this.#replaceAtomic(rel, rootReal, parentReal, name2, target, before,
|
|
15917
|
-
return { path: rel, sha256_after: sha256OfBytes(
|
|
15950
|
+
const bytes2 = Buffer.from(parts.join(newText), "utf8");
|
|
15951
|
+
await this.#replaceAtomic(rel, rootReal, parentReal, name2, target, before, bytes2);
|
|
15952
|
+
return { path: rel, sha256_after: sha256OfBytes(bytes2), bytes: bytes2.length, replacements: found };
|
|
15918
15953
|
}
|
|
15919
15954
|
/** Create a directory and its missing parents, each checked against the root and the deny rules. */
|
|
15920
15955
|
async mkdir(input) {
|
|
@@ -16116,6 +16151,17 @@ var CANCELLED_BEFORE_START = Object.freeze({
|
|
|
16116
16151
|
safe_message: "Task was cancelled before it started",
|
|
16117
16152
|
output_excerpt: excerpt2({ error: "POLICY_DENIED", reason: "CANCELLED_BEFORE_START" })
|
|
16118
16153
|
});
|
|
16154
|
+
var GRANT_EXPIRED = Object.freeze({
|
|
16155
|
+
state: "EXPIRED",
|
|
16156
|
+
executed: false,
|
|
16157
|
+
safe_message: "Grant expired before execution",
|
|
16158
|
+
output_excerpt: excerpt2({ error: "CONTEXT_EXPIRED", reason: "GRANT_EXPIRED" })
|
|
16159
|
+
});
|
|
16160
|
+
var CONFIG_UNREADABLE = Object.freeze({
|
|
16161
|
+
code: "POLICY_DENIED",
|
|
16162
|
+
reason: "CONFIG_UNREADABLE",
|
|
16163
|
+
message: "The agent configuration could not be read; task not executed"
|
|
16164
|
+
});
|
|
16119
16165
|
function grantExpiryMs(dispatch2) {
|
|
16120
16166
|
const value = Date.parse(dispatch2.grant.expires_at);
|
|
16121
16167
|
return Number.isFinite(value) ? value : void 0;
|
|
@@ -16218,11 +16264,9 @@ var Dispatcher = class {
|
|
|
16218
16264
|
this.#sendResult(dispatch2, denialResult(denial));
|
|
16219
16265
|
return;
|
|
16220
16266
|
}
|
|
16221
|
-
|
|
16222
|
-
|
|
16223
|
-
|
|
16224
|
-
} catch {
|
|
16225
|
-
this.#sendResult(dispatch2, denialResult({ code: "POLICY_DENIED", reason: "CONFIG_UNREADABLE", message: "The agent configuration could not be read; task not executed" }));
|
|
16267
|
+
const config2 = await this.#readConfig();
|
|
16268
|
+
if (!config2) {
|
|
16269
|
+
this.#sendResult(dispatch2, denialResult(CONFIG_UNREADABLE));
|
|
16226
16270
|
return;
|
|
16227
16271
|
}
|
|
16228
16272
|
const nonceOwner = journal.taskForNonce(dispatch2.grant.nonce);
|
|
@@ -16254,12 +16298,7 @@ var Dispatcher = class {
|
|
|
16254
16298
|
this.#sendUnknown(dispatch2, "JOURNAL_COMPACTED");
|
|
16255
16299
|
return;
|
|
16256
16300
|
}
|
|
16257
|
-
this.#sendResult(dispatch2,
|
|
16258
|
-
state: "EXPIRED",
|
|
16259
|
-
executed: false,
|
|
16260
|
-
safe_message: "Grant expired before execution",
|
|
16261
|
-
output_excerpt: excerpt2({ error: "CONTEXT_EXPIRED", reason: "GRANT_EXPIRED" })
|
|
16262
|
-
});
|
|
16301
|
+
this.#sendResult(dispatch2, GRANT_EXPIRED);
|
|
16263
16302
|
return;
|
|
16264
16303
|
}
|
|
16265
16304
|
const authorized = checkLocalPolicy(dispatch2, config2, this.#options.sshHosts?.() ?? []);
|
|
@@ -16285,8 +16324,8 @@ var Dispatcher = class {
|
|
|
16285
16324
|
try {
|
|
16286
16325
|
const executionNonce = (0, import_node_crypto7.randomUUID)();
|
|
16287
16326
|
this.#sendAck(dispatch2, "RECEIVED", executionNonce);
|
|
16288
|
-
|
|
16289
|
-
|
|
16327
|
+
let fileTask = isSshTask(authorized) || isShellTask(authorized) ? null : authorized;
|
|
16328
|
+
let fs = fileTask ? new RootedFs(fileTask.root, effectiveDenyGlobs(config2), { protectedPaths: this.#protectedPaths }) : null;
|
|
16290
16329
|
if (fileTask && fileTask.capability === "files.write" && config2.confirm_writes) {
|
|
16291
16330
|
const payload = fileTask.payload;
|
|
16292
16331
|
const confirm = this.#options.confirmWrite;
|
|
@@ -16309,6 +16348,17 @@ var Dispatcher = class {
|
|
|
16309
16348
|
this.#sendResult(dispatch2, cancelled);
|
|
16310
16349
|
return;
|
|
16311
16350
|
}
|
|
16351
|
+
const fresh = await this.#recheckAfterConfirm(dispatch2, now);
|
|
16352
|
+
if (state2.cancelled)
|
|
16353
|
+
return;
|
|
16354
|
+
if ("refused" in fresh) {
|
|
16355
|
+
this.#logger.warn("write refused after local confirmation", { task_id: taskId2, reason: fresh.reason });
|
|
16356
|
+
await journal.done(taskId2, meta, fresh.refused).catch(() => void 0);
|
|
16357
|
+
this.#sendResult(dispatch2, fresh.refused);
|
|
16358
|
+
return;
|
|
16359
|
+
}
|
|
16360
|
+
fileTask = fresh.task;
|
|
16361
|
+
fs = new RootedFs(fresh.task.root, effectiveDenyGlobs(fresh.config), { protectedPaths: this.#protectedPaths });
|
|
16312
16362
|
}
|
|
16313
16363
|
if (state2.cancelled)
|
|
16314
16364
|
return;
|
|
@@ -16361,6 +16411,29 @@ var Dispatcher = class {
|
|
|
16361
16411
|
this.#inFlight.delete(taskId2);
|
|
16362
16412
|
}
|
|
16363
16413
|
}
|
|
16414
|
+
/** The current config (from disk when `loadConfig` is set); null when it cannot be read. */
|
|
16415
|
+
async #readConfig() {
|
|
16416
|
+
try {
|
|
16417
|
+
return this.#options.loadConfig ? await this.#options.loadConfig() : this.#options.config();
|
|
16418
|
+
} catch {
|
|
16419
|
+
return null;
|
|
16420
|
+
}
|
|
16421
|
+
}
|
|
16422
|
+
/** Grant deadline and local policy once more, after the local write confirmation was accepted. */
|
|
16423
|
+
async #recheckAfterConfirm(dispatch2, now) {
|
|
16424
|
+
const config2 = await this.#readConfig();
|
|
16425
|
+
if (isExpired(dispatch2, now()))
|
|
16426
|
+
return { refused: GRANT_EXPIRED, reason: "GRANT_EXPIRED" };
|
|
16427
|
+
if (!config2)
|
|
16428
|
+
return { refused: denialResult(CONFIG_UNREADABLE), reason: CONFIG_UNREADABLE.reason };
|
|
16429
|
+
const authorized = checkLocalPolicy(dispatch2, config2, this.#options.sshHosts?.() ?? []);
|
|
16430
|
+
if (isDenial(authorized))
|
|
16431
|
+
return { refused: denialResult(authorized), reason: authorized.reason };
|
|
16432
|
+
if (isSshTask(authorized) || isShellTask(authorized)) {
|
|
16433
|
+
return { refused: denialResult({ code: "POLICY_DENIED", reason: "CAPABILITY", message: "Task is not a file task" }), reason: "CAPABILITY" };
|
|
16434
|
+
}
|
|
16435
|
+
return { task: authorized, config: config2 };
|
|
16436
|
+
}
|
|
16364
16437
|
/**
|
|
16365
16438
|
* Handle a CANCEL for a task. Before journal STARTED: journal DONE
|
|
16366
16439
|
* CANCELLED and answer RESULT CANCELLED, also for a task whose DISPATCH has
|
|
@@ -16487,6 +16560,144 @@ var Dispatcher = class {
|
|
|
16487
16560
|
}
|
|
16488
16561
|
};
|
|
16489
16562
|
|
|
16563
|
+
// dist/monitor.js
|
|
16564
|
+
var import_promises10 = require("node:fs/promises");
|
|
16565
|
+
var import_node_os3 = require("node:os");
|
|
16566
|
+
var defaultMonitorSystem = {
|
|
16567
|
+
platform: process.platform,
|
|
16568
|
+
cpus: import_node_os3.cpus,
|
|
16569
|
+
loadavg: import_node_os3.loadavg,
|
|
16570
|
+
totalmem: import_node_os3.totalmem,
|
|
16571
|
+
freemem: import_node_os3.freemem,
|
|
16572
|
+
uptime: import_node_os3.uptime,
|
|
16573
|
+
statfs: (path) => (0, import_promises10.statfs)(path),
|
|
16574
|
+
env: process.env
|
|
16575
|
+
};
|
|
16576
|
+
var MONITOR_FIRST_SAMPLE_MS = 1e3;
|
|
16577
|
+
function cpuSnapshot(system = defaultMonitorSystem) {
|
|
16578
|
+
let idle = 0;
|
|
16579
|
+
let total = 0;
|
|
16580
|
+
for (const { times } of system.cpus()) {
|
|
16581
|
+
idle += times.idle;
|
|
16582
|
+
total += times.user + times.nice + times.sys + times.idle + times.irq;
|
|
16583
|
+
}
|
|
16584
|
+
return { idle, total };
|
|
16585
|
+
}
|
|
16586
|
+
function cpuBusyPct(prev, next) {
|
|
16587
|
+
const total = next.total - prev.total;
|
|
16588
|
+
if (!(total > 0))
|
|
16589
|
+
return 0;
|
|
16590
|
+
const busy = 100 * (1 - (next.idle - prev.idle) / total);
|
|
16591
|
+
if (!Number.isFinite(busy))
|
|
16592
|
+
return 0;
|
|
16593
|
+
return Math.round(Math.min(100, Math.max(0, busy)) * 10) / 10;
|
|
16594
|
+
}
|
|
16595
|
+
var MetricsUnavailableError = class extends Error {
|
|
16596
|
+
constructor(message) {
|
|
16597
|
+
super(message);
|
|
16598
|
+
this.name = "MetricsUnavailableError";
|
|
16599
|
+
}
|
|
16600
|
+
};
|
|
16601
|
+
function wholeBytes(value, label) {
|
|
16602
|
+
const bytes2 = Math.floor(value);
|
|
16603
|
+
if (!Number.isSafeInteger(bytes2) || bytes2 < 0)
|
|
16604
|
+
throw new MetricsUnavailableError(`${label} is not a byte count`);
|
|
16605
|
+
return bytes2;
|
|
16606
|
+
}
|
|
16607
|
+
function systemVolume(system = defaultMonitorSystem) {
|
|
16608
|
+
return system.platform === "win32" ? `${system.env.SystemDrive ?? "C:"}\\` : "/";
|
|
16609
|
+
}
|
|
16610
|
+
async function collectMetrics(prevCpu, system = defaultMonitorSystem) {
|
|
16611
|
+
const cpu = cpuSnapshot(system);
|
|
16612
|
+
const memTotal = wholeBytes(system.totalmem(), "memory total");
|
|
16613
|
+
const memUsed = Math.min(memTotal, Math.max(0, memTotal - wholeBytes(system.freemem(), "memory free")));
|
|
16614
|
+
const disk = await system.statfs(systemVolume(system));
|
|
16615
|
+
const diskTotal = wholeBytes(disk.blocks * disk.bsize, "disk total");
|
|
16616
|
+
const diskUsed = Math.min(diskTotal, wholeBytes(Math.max(0, disk.blocks - disk.bavail) * disk.bsize, "disk used"));
|
|
16617
|
+
if (memTotal === 0 || diskTotal === 0)
|
|
16618
|
+
throw new MetricsUnavailableError("memory or disk total is zero");
|
|
16619
|
+
let load = null;
|
|
16620
|
+
if (system.platform !== "win32") {
|
|
16621
|
+
const raw = system.loadavg()[0];
|
|
16622
|
+
load = typeof raw === "number" && Number.isFinite(raw) ? Math.round(Math.min(1e5, Math.max(0, raw)) * 100) / 100 : null;
|
|
16623
|
+
}
|
|
16624
|
+
const up = Math.floor(system.uptime());
|
|
16625
|
+
return {
|
|
16626
|
+
body: {
|
|
16627
|
+
cpu_pct: cpuBusyPct(prevCpu, cpu),
|
|
16628
|
+
load_1: load,
|
|
16629
|
+
mem_used_bytes: memUsed,
|
|
16630
|
+
mem_total_bytes: memTotal,
|
|
16631
|
+
disk_used_bytes: diskUsed,
|
|
16632
|
+
disk_total_bytes: diskTotal,
|
|
16633
|
+
uptime_s: Number.isSafeInteger(up) && up > 0 ? up : 0
|
|
16634
|
+
},
|
|
16635
|
+
cpu
|
|
16636
|
+
};
|
|
16637
|
+
}
|
|
16638
|
+
var MonitorLoop = class {
|
|
16639
|
+
#options;
|
|
16640
|
+
#logger;
|
|
16641
|
+
#intervalS = null;
|
|
16642
|
+
#timer = null;
|
|
16643
|
+
#cpu = { idle: 0, total: 0 };
|
|
16644
|
+
/** Bumped on every (re)start and stop so an in-flight sample from an older schedule is discarded. */
|
|
16645
|
+
#generation = 0;
|
|
16646
|
+
constructor(options) {
|
|
16647
|
+
this.#options = options;
|
|
16648
|
+
this.#logger = options.logger ?? silentLogger;
|
|
16649
|
+
}
|
|
16650
|
+
/** The sampling interval in seconds, or null when idle. */
|
|
16651
|
+
get intervalS() {
|
|
16652
|
+
return this.#intervalS;
|
|
16653
|
+
}
|
|
16654
|
+
apply(config2) {
|
|
16655
|
+
if (!config2.enabled) {
|
|
16656
|
+
if (this.#intervalS !== null)
|
|
16657
|
+
this.#logger.info("monitoring stopped");
|
|
16658
|
+
this.stop();
|
|
16659
|
+
return;
|
|
16660
|
+
}
|
|
16661
|
+
if (this.#intervalS === config2.interval_s)
|
|
16662
|
+
return;
|
|
16663
|
+
this.stop();
|
|
16664
|
+
this.#intervalS = config2.interval_s;
|
|
16665
|
+
this.#cpu = (this.#options.snapshot ?? (() => cpuSnapshot()))();
|
|
16666
|
+
this.#logger.info("monitoring started", { interval_s: config2.interval_s });
|
|
16667
|
+
this.#schedule(this.#options.firstSampleMs ?? MONITOR_FIRST_SAMPLE_MS);
|
|
16668
|
+
}
|
|
16669
|
+
stop() {
|
|
16670
|
+
this.#generation += 1;
|
|
16671
|
+
this.#intervalS = null;
|
|
16672
|
+
if (this.#timer !== null)
|
|
16673
|
+
clearTimeout(this.#timer);
|
|
16674
|
+
this.#timer = null;
|
|
16675
|
+
}
|
|
16676
|
+
#schedule(delayMs) {
|
|
16677
|
+
const generation = this.#generation;
|
|
16678
|
+
this.#timer = setTimeout(() => {
|
|
16679
|
+
this.#timer = null;
|
|
16680
|
+
void this.#sample(generation);
|
|
16681
|
+
}, delayMs);
|
|
16682
|
+
this.#timer.unref?.();
|
|
16683
|
+
}
|
|
16684
|
+
async #sample(generation) {
|
|
16685
|
+
try {
|
|
16686
|
+
const { body, cpu } = await (this.#options.collect ?? collectMetrics)(this.#cpu);
|
|
16687
|
+
if (generation !== this.#generation)
|
|
16688
|
+
return;
|
|
16689
|
+
this.#cpu = cpu;
|
|
16690
|
+
this.#options.send(body);
|
|
16691
|
+
} catch (error47) {
|
|
16692
|
+
if (generation === this.#generation)
|
|
16693
|
+
this.#logger.warn("monitor sample failed", { error: error47 instanceof Error ? error47.name : "unknown" });
|
|
16694
|
+
} finally {
|
|
16695
|
+
if (generation === this.#generation && this.#intervalS !== null)
|
|
16696
|
+
this.#schedule(this.#intervalS * 1e3);
|
|
16697
|
+
}
|
|
16698
|
+
}
|
|
16699
|
+
};
|
|
16700
|
+
|
|
16490
16701
|
// dist/relay.js
|
|
16491
16702
|
var HEARTBEAT_INTERVAL_MS = 2e4;
|
|
16492
16703
|
var AUTH_TIMEOUT_MS = 2e4;
|
|
@@ -16571,6 +16782,9 @@ var RelaySession = class {
|
|
|
16571
16782
|
case "ERROR":
|
|
16572
16783
|
this.#logger.warn("relay error", { code: envelope.code, message: envelope.safe_message });
|
|
16573
16784
|
return;
|
|
16785
|
+
case "MONITOR_CONFIG":
|
|
16786
|
+
this.#options.onMonitorConfig?.({ enabled: envelope.enabled, interval_s: envelope.interval_s });
|
|
16787
|
+
return;
|
|
16574
16788
|
default:
|
|
16575
16789
|
return;
|
|
16576
16790
|
}
|
|
@@ -16618,6 +16832,12 @@ var RelaySession = class {
|
|
|
16618
16832
|
sendHeartbeat() {
|
|
16619
16833
|
this.#sendEnvelope(buildEnvelope(this.identity, "HEARTBEAT", null, { connection_epoch: this.#connectionEpoch, status: "ONLINE" }));
|
|
16620
16834
|
}
|
|
16835
|
+
/** One resource sample (telemetry, never a task); dropped silently unless authenticated. */
|
|
16836
|
+
sendMetrics(body) {
|
|
16837
|
+
if (this.#state !== "ready")
|
|
16838
|
+
return;
|
|
16839
|
+
this.#sendEnvelope(buildEnvelope(this.identity, "METRICS", null, body));
|
|
16840
|
+
}
|
|
16621
16841
|
/** Forward a pre-encoded task frame (ACK/CHUNK/RESULT) if authenticated. */
|
|
16622
16842
|
sendFrame(frame) {
|
|
16623
16843
|
if (this.#state !== "ready")
|
|
@@ -16636,7 +16856,7 @@ var import_node_path13 = require("node:path");
|
|
|
16636
16856
|
|
|
16637
16857
|
// dist/ssh/hosts.js
|
|
16638
16858
|
var import_node_crypto8 = require("node:crypto");
|
|
16639
|
-
var
|
|
16859
|
+
var import_promises11 = require("node:fs/promises");
|
|
16640
16860
|
var import_node_path12 = require("node:path");
|
|
16641
16861
|
var MAX_SSH_HOSTS = 64;
|
|
16642
16862
|
var SSH_ALIAS = /^[a-z0-9][a-z0-9_-]{0,62}$/;
|
|
@@ -16712,7 +16932,7 @@ function preferredKey(keys) {
|
|
|
16712
16932
|
async function loadSshHosts(paths) {
|
|
16713
16933
|
let text;
|
|
16714
16934
|
try {
|
|
16715
|
-
text = await (0,
|
|
16935
|
+
text = await (0, import_promises11.readFile)(paths.hosts, "utf8");
|
|
16716
16936
|
} catch (error47) {
|
|
16717
16937
|
if (errorCode2(error47) === "ENOENT")
|
|
16718
16938
|
return [];
|
|
@@ -16722,8 +16942,8 @@ async function loadSshHosts(paths) {
|
|
|
16722
16942
|
}
|
|
16723
16943
|
async function ensureSshDirs(paths) {
|
|
16724
16944
|
for (const dir of [paths.dir, paths.knownHostsDir]) {
|
|
16725
|
-
await (0,
|
|
16726
|
-
await (0,
|
|
16945
|
+
await (0, import_promises11.mkdir)(dir, { recursive: true, mode: 448 });
|
|
16946
|
+
await (0, import_promises11.chmod)(dir, 448);
|
|
16727
16947
|
}
|
|
16728
16948
|
}
|
|
16729
16949
|
async function saveSshHosts(paths, hosts) {
|
|
@@ -16747,7 +16967,7 @@ async function validateNewHost(input) {
|
|
|
16747
16967
|
if (input.identity !== void 0) {
|
|
16748
16968
|
if (!isValidIdentityPath(input.identity))
|
|
16749
16969
|
throw new Error("Identity must be an absolute path without quotes, % or control characters");
|
|
16750
|
-
const info = await (0,
|
|
16970
|
+
const info = await (0, import_promises11.stat)(input.identity).catch(() => null);
|
|
16751
16971
|
if (!info?.isFile())
|
|
16752
16972
|
throw new Error("Identity file not found");
|
|
16753
16973
|
}
|
|
@@ -16804,7 +17024,7 @@ async function removeSshHost(paths, alias) {
|
|
|
16804
17024
|
if (!host)
|
|
16805
17025
|
return false;
|
|
16806
17026
|
await saveSshHosts(paths, hosts.filter((entry) => entry !== host));
|
|
16807
|
-
await (0,
|
|
17027
|
+
await (0, import_promises11.unlink)(knownHostsPath(paths, host.resource_id)).catch(() => void 0);
|
|
16808
17028
|
return true;
|
|
16809
17029
|
}
|
|
16810
17030
|
function hostAddress(host) {
|
|
@@ -17097,8 +17317,8 @@ var SshExecutor = class {
|
|
|
17097
17317
|
|
|
17098
17318
|
// dist/shell/executor.js
|
|
17099
17319
|
var import_node_child_process8 = require("node:child_process");
|
|
17100
|
-
var
|
|
17101
|
-
var
|
|
17320
|
+
var import_promises13 = require("node:fs/promises");
|
|
17321
|
+
var import_node_os5 = require("node:os");
|
|
17102
17322
|
var import_node_path15 = require("node:path");
|
|
17103
17323
|
|
|
17104
17324
|
// dist/shell/output.js
|
|
@@ -17148,13 +17368,13 @@ var OutputBuffer = class {
|
|
|
17148
17368
|
read(offset, maxBytes) {
|
|
17149
17369
|
const from = Math.min(Math.max(offset, this.start), this.#total);
|
|
17150
17370
|
const skipped = offset < this.start ? this.start - offset : 0;
|
|
17151
|
-
let
|
|
17152
|
-
|
|
17371
|
+
let bytes2 = Buffer.concat(this.#chunks).subarray(from - this.start, Math.min(from - this.start + maxBytes, this.#kept));
|
|
17372
|
+
bytes2 = trimIncompleteUtf8(bytes2);
|
|
17153
17373
|
let lead = 0;
|
|
17154
|
-
while (lead <
|
|
17374
|
+
while (lead < bytes2.length && lead < 3 && (bytes2[lead] & 192) === 128)
|
|
17155
17375
|
lead += 1;
|
|
17156
|
-
|
|
17157
|
-
return { text:
|
|
17376
|
+
bytes2 = bytes2.subarray(lead);
|
|
17377
|
+
return { text: bytes2.toString("utf8"), offset: from + lead, next_offset: from + lead + bytes2.length, skipped_bytes: skipped + lead };
|
|
17158
17378
|
}
|
|
17159
17379
|
/** The last `maxBytes` (or fewer) of the output. */
|
|
17160
17380
|
tail(maxBytes) {
|
|
@@ -17163,25 +17383,25 @@ var OutputBuffer = class {
|
|
|
17163
17383
|
return { ...read, skipped_bytes: read.offset };
|
|
17164
17384
|
}
|
|
17165
17385
|
};
|
|
17166
|
-
function trimIncompleteUtf8(
|
|
17167
|
-
const end =
|
|
17386
|
+
function trimIncompleteUtf8(bytes2) {
|
|
17387
|
+
const end = bytes2.length;
|
|
17168
17388
|
let index = end - 1;
|
|
17169
17389
|
let continuation = 0;
|
|
17170
|
-
while (index >= 0 && continuation < 3 && (
|
|
17390
|
+
while (index >= 0 && continuation < 3 && (bytes2[index] & 192) === 128) {
|
|
17171
17391
|
index -= 1;
|
|
17172
17392
|
continuation += 1;
|
|
17173
17393
|
}
|
|
17174
17394
|
if (index < 0)
|
|
17175
|
-
return
|
|
17176
|
-
const lead =
|
|
17395
|
+
return bytes2;
|
|
17396
|
+
const lead = bytes2[index];
|
|
17177
17397
|
const expected = lead >= 240 ? 4 : lead >= 224 ? 3 : lead >= 192 ? 2 : 1;
|
|
17178
|
-
return index + expected > end ?
|
|
17398
|
+
return index + expected > end ? bytes2.subarray(0, index) : bytes2;
|
|
17179
17399
|
}
|
|
17180
17400
|
|
|
17181
17401
|
// dist/shell/system.js
|
|
17182
17402
|
var import_node_child_process7 = require("node:child_process");
|
|
17183
|
-
var
|
|
17184
|
-
var
|
|
17403
|
+
var import_promises12 = require("node:fs/promises");
|
|
17404
|
+
var import_node_os4 = require("node:os");
|
|
17185
17405
|
var import_node_path14 = require("node:path");
|
|
17186
17406
|
function windowsTool(env, ...parts) {
|
|
17187
17407
|
return import_node_path14.win32.join(env.SystemRoot ?? env.windir ?? "C:\\Windows", "System32", ...parts);
|
|
@@ -17190,7 +17410,7 @@ var POWERSHELL_PREFIX = "[Console]::OutputEncoding = [System.Text.Encoding]::UTF
|
|
|
17190
17410
|
function userShell(env = process.env) {
|
|
17191
17411
|
let shell = null;
|
|
17192
17412
|
try {
|
|
17193
|
-
shell = (0,
|
|
17413
|
+
shell = (0, import_node_os4.userInfo)().shell;
|
|
17194
17414
|
} catch {
|
|
17195
17415
|
shell = null;
|
|
17196
17416
|
}
|
|
@@ -17265,6 +17485,12 @@ function parseWindowsProcesses(text) {
|
|
|
17265
17485
|
command: String(item.CommandLine ?? item.Name ?? "").slice(0, 512)
|
|
17266
17486
|
}]);
|
|
17267
17487
|
}
|
|
17488
|
+
var ProcessListError = class extends Error {
|
|
17489
|
+
constructor(message) {
|
|
17490
|
+
super(message);
|
|
17491
|
+
this.name = "ProcessListError";
|
|
17492
|
+
}
|
|
17493
|
+
};
|
|
17268
17494
|
async function listProcesses(options) {
|
|
17269
17495
|
const os = options.os ?? process.platform;
|
|
17270
17496
|
const exec = options.run ?? run;
|
|
@@ -17276,9 +17502,18 @@ async function listProcesses(options) {
|
|
|
17276
17502
|
"-Command",
|
|
17277
17503
|
"Get-CimInstance Win32_Process | Select-Object ProcessId,ParentProcessId,Name,CommandLine,WorkingSetSize | ConvertTo-Json -Compress"
|
|
17278
17504
|
]);
|
|
17505
|
+
if (!result2.ok)
|
|
17506
|
+
throw new ProcessListError("PowerShell could not list the processes");
|
|
17507
|
+
try {
|
|
17508
|
+
JSON.parse(result2.stdout);
|
|
17509
|
+
} catch {
|
|
17510
|
+
throw new ProcessListError("PowerShell returned an unreadable process list");
|
|
17511
|
+
}
|
|
17279
17512
|
all = parseWindowsProcesses(result2.stdout);
|
|
17280
17513
|
} else {
|
|
17281
17514
|
const result2 = await exec("ps", ["-A", "-o", "pid=,ppid=,user=,pcpu=,pmem=,etime=,args="]);
|
|
17515
|
+
if (!result2.ok)
|
|
17516
|
+
throw new ProcessListError("ps could not list the processes");
|
|
17282
17517
|
all = parsePs(result2.stdout);
|
|
17283
17518
|
}
|
|
17284
17519
|
const needle = options.filter?.toLowerCase();
|
|
@@ -17287,39 +17522,39 @@ async function listProcesses(options) {
|
|
|
17287
17522
|
return { processes: matching.slice(0, options.limit), total: matching.length, truncated: matching.length > options.limit };
|
|
17288
17523
|
}
|
|
17289
17524
|
async function systemInfo() {
|
|
17290
|
-
const cores = (0,
|
|
17525
|
+
const cores = (0, import_node_os4.cpus)();
|
|
17291
17526
|
const disk = async (path) => {
|
|
17292
17527
|
try {
|
|
17293
|
-
const info = await (0,
|
|
17528
|
+
const info = await (0, import_promises12.statfs)(path);
|
|
17294
17529
|
return { path, total_bytes: info.blocks * info.bsize, free_bytes: info.bavail * info.bsize };
|
|
17295
17530
|
} catch {
|
|
17296
17531
|
return null;
|
|
17297
17532
|
}
|
|
17298
17533
|
};
|
|
17299
|
-
const home = (0,
|
|
17300
|
-
const disks = (await Promise.all([disk((0,
|
|
17534
|
+
const home = (0, import_node_os4.homedir)();
|
|
17535
|
+
const disks = (await Promise.all([disk((0, import_node_os4.platform)() === "win32" ? home.slice(0, 3) || "C:\\" : "/"), disk(home)])).filter((entry) => entry !== null);
|
|
17301
17536
|
let user = null;
|
|
17302
17537
|
try {
|
|
17303
|
-
user = (0,
|
|
17538
|
+
user = (0, import_node_os4.userInfo)().username;
|
|
17304
17539
|
} catch {
|
|
17305
17540
|
user = null;
|
|
17306
17541
|
}
|
|
17307
17542
|
return {
|
|
17308
|
-
hostname: (0,
|
|
17309
|
-
platform: (0,
|
|
17310
|
-
os_version: (0,
|
|
17311
|
-
release: (0,
|
|
17312
|
-
arch: (0,
|
|
17313
|
-
uptime_s: Math.round((0,
|
|
17543
|
+
hostname: (0, import_node_os4.hostname)(),
|
|
17544
|
+
platform: (0, import_node_os4.platform)(),
|
|
17545
|
+
os_version: (0, import_node_os4.version)(),
|
|
17546
|
+
release: (0, import_node_os4.release)(),
|
|
17547
|
+
arch: (0, import_node_os4.arch)(),
|
|
17548
|
+
uptime_s: Math.round((0, import_node_os4.uptime)()),
|
|
17314
17549
|
cpu_model: cores[0]?.model ?? null,
|
|
17315
17550
|
cpu_count: cores.length,
|
|
17316
|
-
load_average: (0,
|
|
17317
|
-
memory_total_bytes: (0,
|
|
17318
|
-
memory_free_bytes: (0,
|
|
17551
|
+
load_average: (0, import_node_os4.platform)() === "win32" ? null : (0, import_node_os4.loadavg)().map((value) => Math.round(value * 100) / 100),
|
|
17552
|
+
memory_total_bytes: (0, import_node_os4.totalmem)(),
|
|
17553
|
+
memory_free_bytes: (0, import_node_os4.freemem)(),
|
|
17319
17554
|
disks,
|
|
17320
17555
|
user,
|
|
17321
17556
|
home,
|
|
17322
|
-
shell: (0,
|
|
17557
|
+
shell: (0, import_node_os4.platform)() === "win32" ? "powershell" : userShell(),
|
|
17323
17558
|
node_version: process.versions.node,
|
|
17324
17559
|
agent_version: AGENT_VERSION
|
|
17325
17560
|
};
|
|
@@ -17335,7 +17570,7 @@ var KILL_GRACE_MS = 3e3;
|
|
|
17335
17570
|
function failure2(code, reason, message, executed = false, extra = {}) {
|
|
17336
17571
|
return { result: { state: "FAILED", executed, safe_message: message.slice(0, 256), output_excerpt: excerpt2({ error: code, reason, message, ...extra }) } };
|
|
17337
17572
|
}
|
|
17338
|
-
function resolveCwd(input, home = (0,
|
|
17573
|
+
function resolveCwd(input, home = (0, import_node_os5.homedir)()) {
|
|
17339
17574
|
if (input === void 0 || input === "~")
|
|
17340
17575
|
return home;
|
|
17341
17576
|
if (input.startsWith("~/") || input.startsWith("~\\"))
|
|
@@ -17410,11 +17645,19 @@ var ShellExecutor = class {
|
|
|
17410
17645
|
}
|
|
17411
17646
|
case "process.list": {
|
|
17412
17647
|
const payload = task.payload;
|
|
17413
|
-
|
|
17414
|
-
|
|
17415
|
-
|
|
17416
|
-
|
|
17417
|
-
|
|
17648
|
+
let listed;
|
|
17649
|
+
try {
|
|
17650
|
+
listed = await listProcesses({
|
|
17651
|
+
limit: payload.limit ?? 100,
|
|
17652
|
+
...payload.filter !== void 0 ? { filter: payload.filter } : {},
|
|
17653
|
+
...this.#options.platform ? { os: this.#options.platform } : {},
|
|
17654
|
+
...this.#options.runTool ? { run: this.#options.runTool } : {},
|
|
17655
|
+
...this.#options.env ? { env: this.#options.env } : {}
|
|
17656
|
+
});
|
|
17657
|
+
} catch (error47) {
|
|
17658
|
+
this.#logger.warn("process list failed", { error: error47 instanceof ProcessListError ? error47.message : "unknown" });
|
|
17659
|
+
return failure2("INVALID_MESSAGE", "PROCESS_LIST_FAILED", "The process list could not be read on the device");
|
|
17660
|
+
}
|
|
17418
17661
|
return { result: { state: "SUCCEEDED", executed: true, output_excerpt: excerpt2({ count: listed.processes.length, total: listed.total }) }, data: JSON.stringify(listed) };
|
|
17419
17662
|
}
|
|
17420
17663
|
case "process.kill": {
|
|
@@ -17445,7 +17688,7 @@ var ShellExecutor = class {
|
|
|
17445
17688
|
const cwd = resolveCwd(payload.cwd);
|
|
17446
17689
|
if (cwd === null)
|
|
17447
17690
|
return failure2("INVALID_MESSAGE", "CWD_INVALID", "cwd must be an absolute directory or start with ~");
|
|
17448
|
-
const isDirectory = await (0,
|
|
17691
|
+
const isDirectory = await (0, import_promises13.stat)(cwd).then((info) => info.isDirectory(), () => false);
|
|
17449
17692
|
if (!isDirectory)
|
|
17450
17693
|
return failure2("NOT_FOUND", "CWD_NOT_FOUND", `Directory not found: ${cwd}`);
|
|
17451
17694
|
if (this.runningCount >= MAX_RUNNING_COMMANDS) {
|
|
@@ -17616,13 +17859,13 @@ var ShellExecutor = class {
|
|
|
17616
17859
|
function shellResource(config2, platform2 = process.platform) {
|
|
17617
17860
|
if (config2.full_access !== true)
|
|
17618
17861
|
return null;
|
|
17619
|
-
return { resource_id: SHELL_RESOURCE_ID, kind: SHELL_RESOURCE_KIND, label: `Terminal on ${(0,
|
|
17862
|
+
return { resource_id: SHELL_RESOURCE_ID, kind: SHELL_RESOURCE_KIND, label: `Terminal on ${(0, import_node_os6.hostname)().slice(0, 100)}`, attrs: { platform: platform2, arch: (0, import_node_os6.arch)() } };
|
|
17620
17863
|
}
|
|
17621
17864
|
var WATCH_INTERVAL_MS = 5e3;
|
|
17622
17865
|
var RESUME_GAP_MS = 3e4;
|
|
17623
17866
|
function networkFingerprint() {
|
|
17624
17867
|
const parts = [];
|
|
17625
|
-
for (const [name2, addresses] of Object.entries((0,
|
|
17868
|
+
for (const [name2, addresses] of Object.entries((0, import_node_os6.networkInterfaces)())) {
|
|
17626
17869
|
for (const address of addresses ?? [])
|
|
17627
17870
|
if (!address.internal)
|
|
17628
17871
|
parts.push(`${name2}/${address.address}`);
|
|
@@ -17836,6 +18079,7 @@ var AgentRunner = class {
|
|
|
17836
18079
|
this.#socket = socket;
|
|
17837
18080
|
let ready = false;
|
|
17838
18081
|
let heartbeat2;
|
|
18082
|
+
const monitor = new MonitorLoop({ ...this.#options.monitor, send: (body) => session.sendMetrics(body), logger: this.#logger });
|
|
17839
18083
|
const session = new RelaySession({
|
|
17840
18084
|
identity,
|
|
17841
18085
|
key,
|
|
@@ -17862,7 +18106,8 @@ var AgentRunner = class {
|
|
|
17862
18106
|
session.sendInventory();
|
|
17863
18107
|
}, (error47) => this.#logger.warn("config reload failed", { error: errorMessage(error47) })).finally(() => session.sendHeartbeat());
|
|
17864
18108
|
}, this.#options.heartbeatMs ?? HEARTBEAT_INTERVAL_MS);
|
|
17865
|
-
}
|
|
18109
|
+
},
|
|
18110
|
+
onMonitorConfig: (config2) => monitor.apply(config2)
|
|
17866
18111
|
});
|
|
17867
18112
|
this.#session = session;
|
|
17868
18113
|
return new Promise((resolve8) => {
|
|
@@ -17874,6 +18119,7 @@ var AgentRunner = class {
|
|
|
17874
18119
|
clearTimeout(authTimer);
|
|
17875
18120
|
if (heartbeat2)
|
|
17876
18121
|
clearInterval(heartbeat2);
|
|
18122
|
+
monitor.stop();
|
|
17877
18123
|
session.markClosed();
|
|
17878
18124
|
if (this.#session === session)
|
|
17879
18125
|
this.#session = null;
|
|
@@ -18049,7 +18295,7 @@ async function cmdSsh(stateDir, args, io) {
|
|
|
18049
18295
|
}
|
|
18050
18296
|
|
|
18051
18297
|
// dist/cli.js
|
|
18052
|
-
var
|
|
18298
|
+
var import_promises15 = require("node:fs/promises");
|
|
18053
18299
|
var USAGE = `conbridge-agent ${AGENT_VERSION}
|
|
18054
18300
|
|
|
18055
18301
|
Usage:
|
|
@@ -18091,7 +18337,7 @@ function lockPath(paths) {
|
|
|
18091
18337
|
return (0, import_node_path17.join)(paths.dir, "agent.lock");
|
|
18092
18338
|
}
|
|
18093
18339
|
async function exists(path) {
|
|
18094
|
-
return (0,
|
|
18340
|
+
return (0, import_promises14.access)(path).then(() => true, () => false);
|
|
18095
18341
|
}
|
|
18096
18342
|
async function runInstalledCopy(paths, argv, io) {
|
|
18097
18343
|
if (!runningFromNpm() || await runningFromRuntime(paths.dir))
|
|
@@ -18152,13 +18398,13 @@ async function cmdPair(paths, args, io) {
|
|
|
18152
18398
|
if (installed !== null)
|
|
18153
18399
|
return installed;
|
|
18154
18400
|
const gateway = values.gateway ?? DEFAULT_GATEWAY_URL;
|
|
18155
|
-
const name2 = (values.name ?? (0,
|
|
18401
|
+
const name2 = (values.name ?? (0, import_node_os7.hostname)()).trim().slice(0, 64) || "My computer";
|
|
18156
18402
|
const keyStore = await newKeyStore(paths, values, io.env);
|
|
18157
18403
|
const previous = await loadIdentity(paths);
|
|
18158
18404
|
if (previous) {
|
|
18159
18405
|
if (!values.force)
|
|
18160
18406
|
throw new UsageError("This agent is already paired; use --force to pair again (the old identity is discarded)");
|
|
18161
|
-
await (0,
|
|
18407
|
+
await (0, import_promises15.unlink)(paths.identity).catch(() => void 0);
|
|
18162
18408
|
await discardOldKey(paths, previous, io.env);
|
|
18163
18409
|
}
|
|
18164
18410
|
await ensureStateDir(paths.dir);
|
|
@@ -18471,14 +18717,14 @@ function supervisorPidPath(paths) {
|
|
|
18471
18717
|
}
|
|
18472
18718
|
function startSupervisorNow(command2, logPath, env) {
|
|
18473
18719
|
const [file2, ...args] = programArguments(command2);
|
|
18474
|
-
void (0,
|
|
18720
|
+
void (0, import_promises14.open)(logPath, "a", 384).then((log) => {
|
|
18475
18721
|
const child = (0, import_node_child_process9.spawn)(file2, [...args.slice(0, -1), "supervise"], { detached: true, stdio: ["ignore", log.fd, log.fd], env });
|
|
18476
18722
|
child.unref();
|
|
18477
18723
|
void log.close();
|
|
18478
18724
|
});
|
|
18479
18725
|
}
|
|
18480
18726
|
async function stopSupervisor(paths) {
|
|
18481
|
-
const pid = Number.parseInt(await (0,
|
|
18727
|
+
const pid = Number.parseInt(await (0, import_promises14.readFile)(supervisorPidPath(paths), "utf8").catch(() => ""), 10);
|
|
18482
18728
|
if (Number.isInteger(pid) && pid > 1 && pid !== process.pid) {
|
|
18483
18729
|
try {
|
|
18484
18730
|
process.kill(pid, "SIGTERM");
|
|
@@ -18488,7 +18734,7 @@ async function stopSupervisor(paths) {
|
|
|
18488
18734
|
}
|
|
18489
18735
|
async function cmdSupervise(paths, io) {
|
|
18490
18736
|
await ensureStateDir(paths.dir);
|
|
18491
|
-
await (0,
|
|
18737
|
+
await (0, import_promises14.writeFile)(supervisorPidPath(paths), `${process.pid}
|
|
18492
18738
|
`, { mode: 384 });
|
|
18493
18739
|
const command2 = await agentLaunchCommand({ sea: runningAsSea(), cliPath: cliPath() });
|
|
18494
18740
|
const [file2, ...args] = programArguments(command2);
|
|
@@ -18513,7 +18759,7 @@ async function cmdSupervise(paths, io) {
|
|
|
18513
18759
|
await new Promise((resolve8) => setTimeout(resolve8, 1e4));
|
|
18514
18760
|
}
|
|
18515
18761
|
} finally {
|
|
18516
|
-
await (0,
|
|
18762
|
+
await (0, import_promises14.unlink)(supervisorPidPath(paths)).catch(() => void 0);
|
|
18517
18763
|
}
|
|
18518
18764
|
return 0;
|
|
18519
18765
|
}
|
|
@@ -18535,8 +18781,8 @@ async function cmdAccess(paths, args, io) {
|
|
|
18535
18781
|
const { values } = (0, import_node_util2.parseArgs)({ args: rest, allowPositionals: false, options: { "no-home": { type: "boolean" } } });
|
|
18536
18782
|
await saveConfig(paths, { ...config2, full_access: true });
|
|
18537
18783
|
if (!values["no-home"]) {
|
|
18538
|
-
const home = io.env.HOME ?? (0,
|
|
18539
|
-
const real = await (0,
|
|
18784
|
+
const home = io.env.HOME ?? (0, import_node_os7.homedir)();
|
|
18785
|
+
const real = await (0, import_promises14.realpath)(home).catch(() => null);
|
|
18540
18786
|
const covered = config2.roots.some((root) => root.path === real);
|
|
18541
18787
|
if (real && !covered) {
|
|
18542
18788
|
const root = await addRoot(paths, { path: real, label: "Home", writable: true, allowBroadRoot: true, home });
|
|
@@ -18569,7 +18815,7 @@ async function cmdDoctor(paths, io) {
|
|
|
18569
18815
|
const pid = await readLockPid(lockPath(paths));
|
|
18570
18816
|
checks.push({ ok: pid !== null, label: "Agent running", detail: pid !== null ? `pid ${pid}` : "not running" });
|
|
18571
18817
|
const config2 = await loadConfig(paths);
|
|
18572
|
-
const roots = await Promise.all(config2.roots.map(async (root) => ({ root, ok: await (0,
|
|
18818
|
+
const roots = await Promise.all(config2.roots.map(async (root) => ({ root, ok: await (0, import_promises14.stat)(root.path).then((info) => info.isDirectory(), () => false) })));
|
|
18573
18819
|
checks.push({
|
|
18574
18820
|
ok: roots.every((entry) => entry.ok) ? roots.length > 0 ? true : null : false,
|
|
18575
18821
|
label: "Shared folders",
|
|
@@ -18591,7 +18837,7 @@ async function cmdLogs(paths, args, io) {
|
|
|
18591
18837
|
return child.status ?? 1;
|
|
18592
18838
|
}
|
|
18593
18839
|
const logPath = serviceLogPath(io.env);
|
|
18594
|
-
const text = await (0,
|
|
18840
|
+
const text = await (0, import_promises14.readFile)(logPath, "utf8").catch(() => null);
|
|
18595
18841
|
if (text === null) {
|
|
18596
18842
|
io.err(`No log at ${logPath} yet.`);
|
|
18597
18843
|
return 1;
|
|
@@ -18601,14 +18847,14 @@ async function cmdLogs(paths, args, io) {
|
|
|
18601
18847
|
io.out(line);
|
|
18602
18848
|
if (!values.follow)
|
|
18603
18849
|
return 0;
|
|
18604
|
-
let size = (await (0,
|
|
18850
|
+
let size = (await (0, import_promises14.stat)(logPath)).size;
|
|
18605
18851
|
for (; ; ) {
|
|
18606
18852
|
await new Promise((resolve8) => setTimeout(resolve8, 1e3));
|
|
18607
|
-
const now = (await (0,
|
|
18853
|
+
const now = (await (0, import_promises14.stat)(logPath).catch(() => null))?.size ?? 0;
|
|
18608
18854
|
if (now < size)
|
|
18609
18855
|
size = 0;
|
|
18610
18856
|
if (now > size) {
|
|
18611
|
-
const handle = await (0,
|
|
18857
|
+
const handle = await (0, import_promises14.open)(logPath, "r");
|
|
18612
18858
|
const buffer = Buffer.alloc(now - size);
|
|
18613
18859
|
await handle.read(buffer, 0, buffer.length, size);
|
|
18614
18860
|
await handle.close();
|
|
@@ -18624,7 +18870,7 @@ async function cmdUnpair(paths, io) {
|
|
|
18624
18870
|
await stopAgentProcess(paths);
|
|
18625
18871
|
if (identity)
|
|
18626
18872
|
await discardOldKey(paths, identity, io.env);
|
|
18627
|
-
await (0,
|
|
18873
|
+
await (0, import_promises14.unlink)(paths.identity).catch(() => void 0);
|
|
18628
18874
|
io.out(identity ? `Removed the identity of "${identity.display_name}". Remove it in the ConBridge Console (Devices) as well; its key no longer exists here.` : "This computer was not paired.");
|
|
18629
18875
|
return 0;
|
|
18630
18876
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "conbridge-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "ConBridge Desktop Agent: connect this computer to ConBridge so approved AI apps can use the folders you share.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"homepage": "https://conbridge.app",
|