@belboy47/brc-agent 2.0.18 → 3.0.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 +21 -36
- package/dist/cli.js +77 -13
- package/dist/cli.js.map +1 -1
- package/dist/core/config-manager.d.ts +2 -0
- package/dist/core/config-manager.js +12 -3
- package/dist/core/config-manager.js.map +1 -1
- package/dist/core/tools/config.d.ts +2 -0
- package/dist/core/tools/config.js +3 -0
- package/dist/core/tools/config.js.map +1 -1
- package/dist/manager.d.ts +56 -0
- package/dist/manager.js +604 -0
- package/dist/manager.js.map +1 -0
- package/dist/runtime/detach.d.ts +5 -0
- package/dist/runtime/detach.js +38 -8
- package/dist/runtime/detach.js.map +1 -1
- package/dist/runtime/directories.d.ts +16 -0
- package/dist/runtime/directories.js +123 -0
- package/dist/runtime/directories.js.map +1 -0
- package/dist/runtime/manager-config.d.ts +35 -0
- package/dist/runtime/manager-config.js +172 -0
- package/dist/runtime/manager-config.js.map +1 -0
- package/dist/runtime/permissions.d.ts +33 -0
- package/dist/runtime/permissions.js +144 -0
- package/dist/runtime/permissions.js.map +1 -0
- package/dist/runtime/updater.d.ts +28 -0
- package/dist/runtime/updater.js +113 -0
- package/dist/runtime/updater.js.map +1 -0
- package/dist/tools/jobs.d.ts +14 -14
- package/package.json +3 -4
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locally controlled permission profiles and scoped capability management.
|
|
3
|
+
*
|
|
4
|
+
* Security invariants:
|
|
5
|
+
* - Permission profiles and authorized capabilities can only be changed locally
|
|
6
|
+
* by the host operator (CLI or local interactive manager), never by remote MCP callers.
|
|
7
|
+
* - Relay authentication, device enrollment, and OS permissions are always preserved.
|
|
8
|
+
* - Starting the agent in any profile performs no host/firewall mutations on its own.
|
|
9
|
+
*/
|
|
10
|
+
import { LAB_NETWORKING_COMMANDS } from './lab-mode.js';
|
|
11
|
+
export const CAPABILITY_GROUPS = Object.freeze([
|
|
12
|
+
{
|
|
13
|
+
id: 'networking-firewall',
|
|
14
|
+
label: 'Laboratory Networking & Firewall',
|
|
15
|
+
description: 'Linux firewall rules (iptables/ip6tables/nft/ufw/firewall-cmd), interfaces, routing, tc, namespaces, tunnels (WireGuard/OpenVPN/IPsec), and network diagnostics.',
|
|
16
|
+
riskLevel: 'moderate',
|
|
17
|
+
requiresRootOnLinux: true,
|
|
18
|
+
commands: LAB_NETWORKING_COMMANDS,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: 'system-services',
|
|
22
|
+
label: 'System Services & Package Management',
|
|
23
|
+
description: 'Manage system daemons, journal logs, and OS packages (systemctl, service, journalctl, apt/apt-get, dpkg, dnf, yum, pacman).',
|
|
24
|
+
riskLevel: 'moderate',
|
|
25
|
+
commands: Object.freeze([
|
|
26
|
+
'systemctl', 'service', 'journalctl', 'apt', 'apt-get', 'dpkg', 'dnf', 'yum', 'pacman', 'snap',
|
|
27
|
+
]),
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: 'storage-mounts',
|
|
31
|
+
label: 'Storage & Filesystem Mounts',
|
|
32
|
+
description: 'Mount/unmount filesystems and manage disk/partition tools (mount, umount, fdisk, parted, dd, mkfs, format). High impact.',
|
|
33
|
+
riskLevel: 'high',
|
|
34
|
+
requiresRootOnLinux: true,
|
|
35
|
+
commands: Object.freeze([
|
|
36
|
+
'mount', 'umount', 'fdisk', 'parted', 'dd', 'mkfs', 'format',
|
|
37
|
+
]),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: 'user-accounts',
|
|
41
|
+
label: 'Local User & Group Administration',
|
|
42
|
+
description: 'Create or modify local OS users and groups (useradd, adduser, usermod, groupadd, chsh, passwd). High impact.',
|
|
43
|
+
riskLevel: 'high',
|
|
44
|
+
requiresRootOnLinux: true,
|
|
45
|
+
commands: Object.freeze([
|
|
46
|
+
'useradd', 'adduser', 'usermod', 'groupadd', 'chsh', 'passwd',
|
|
47
|
+
]),
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: 'power-control',
|
|
51
|
+
label: 'Host Power & Reboot Control',
|
|
52
|
+
description: 'Reboot or shut down the host (reboot, shutdown, halt, poweroff). High impact.',
|
|
53
|
+
riskLevel: 'high',
|
|
54
|
+
requiresRootOnLinux: true,
|
|
55
|
+
commands: Object.freeze([
|
|
56
|
+
'reboot', 'shutdown', 'halt', 'poweroff',
|
|
57
|
+
]),
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: 'windows-admin',
|
|
61
|
+
label: 'Windows System & Network Administration',
|
|
62
|
+
description: 'Windows network, service, and registry utilities (netsh, net, sc, reg, sfc, bcdedit, takeown, cipher).',
|
|
63
|
+
riskLevel: 'high',
|
|
64
|
+
commands: Object.freeze([
|
|
65
|
+
'netsh', 'net', 'sc', 'reg', 'sfc', 'bcdedit', 'takeown', 'cipher',
|
|
66
|
+
]),
|
|
67
|
+
},
|
|
68
|
+
]);
|
|
69
|
+
const GROUP_MAP = new Map(CAPABILITY_GROUPS.map((g) => [g.id, g]));
|
|
70
|
+
export function getCapabilityGroup(id) {
|
|
71
|
+
return GROUP_MAP.get(id);
|
|
72
|
+
}
|
|
73
|
+
export function normalizeCapabilities(ids) {
|
|
74
|
+
if (!Array.isArray(ids))
|
|
75
|
+
return [];
|
|
76
|
+
const out = [];
|
|
77
|
+
for (const raw of ids) {
|
|
78
|
+
if (typeof raw !== 'string')
|
|
79
|
+
continue;
|
|
80
|
+
const id = raw.trim().toLowerCase();
|
|
81
|
+
if (GROUP_MAP.has(id) && !out.includes(id))
|
|
82
|
+
out.push(id);
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
export function normalizeProfile(raw) {
|
|
87
|
+
if (raw === 'standard' || raw === 'lab-networking' || raw === 'custom')
|
|
88
|
+
return raw;
|
|
89
|
+
return 'standard';
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Resolve effective runtime command unblocking and filesystem scope from
|
|
93
|
+
* saved preferences + any active runtime `--lab-mode` session overlay.
|
|
94
|
+
*/
|
|
95
|
+
export function resolveEffectivePermissions(opts) {
|
|
96
|
+
const caps = new Set(normalizeCapabilities(opts.authorizedCapabilities));
|
|
97
|
+
let profile = normalizeProfile(opts.profile);
|
|
98
|
+
if (opts.labSessionActive || profile === 'lab-networking') {
|
|
99
|
+
caps.add('networking-firewall');
|
|
100
|
+
if (opts.labSessionActive)
|
|
101
|
+
profile = 'lab-networking';
|
|
102
|
+
}
|
|
103
|
+
if (profile === 'standard' && !opts.labSessionActive) {
|
|
104
|
+
return {
|
|
105
|
+
profile: 'standard',
|
|
106
|
+
authorizedCapabilities: [],
|
|
107
|
+
unblockedCommands: [],
|
|
108
|
+
filesystemScope: [...opts.savedAllowedDirectories],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const unblocked = new Set();
|
|
112
|
+
for (const id of caps) {
|
|
113
|
+
const g = GROUP_MAP.get(id);
|
|
114
|
+
if (g) {
|
|
115
|
+
for (const cmd of g.commands)
|
|
116
|
+
unblocked.add(cmd.toLowerCase());
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
profile,
|
|
121
|
+
authorizedCapabilities: [...caps],
|
|
122
|
+
unblockedCommands: [...unblocked],
|
|
123
|
+
filesystemScope: opts.labSessionActive ? 'root' : [...opts.savedAllowedDirectories],
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Apply runtime permission overlay to a config snapshot without mutating saved config.
|
|
128
|
+
*/
|
|
129
|
+
export function applyPermissionOverlay(saved, policy) {
|
|
130
|
+
const savedBlocked = Array.isArray(saved.blockedCommands) ? saved.blockedCommands : [];
|
|
131
|
+
const unblockSet = new Set(policy.unblockedCommands.map((c) => c.toLowerCase()));
|
|
132
|
+
const effectiveBlocked = unblockSet.size === 0
|
|
133
|
+
? [...savedBlocked]
|
|
134
|
+
: savedBlocked.filter((entry) => typeof entry !== 'string' || !unblockSet.has(entry.trim().toLowerCase()));
|
|
135
|
+
const effectiveAllowedDirs = policy.filesystemScope === 'root'
|
|
136
|
+
? ['/']
|
|
137
|
+
: Array.isArray(saved.allowedDirectories) ? [...saved.allowedDirectories] : [];
|
|
138
|
+
return {
|
|
139
|
+
...saved,
|
|
140
|
+
allowedDirectories: effectiveAllowedDirs,
|
|
141
|
+
blockedCommands: effectiveBlocked,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../src/runtime/permissions.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAaxD,MAAM,CAAC,MAAM,iBAAiB,GAA+B,MAAM,CAAC,MAAM,CAAC;IACzE;QACE,EAAE,EAAE,qBAAqB;QACzB,KAAK,EAAE,kCAAkC;QACzC,WAAW,EAAE,kKAAkK;QAC/K,SAAS,EAAE,UAAU;QACrB,mBAAmB,EAAE,IAAI;QACzB,QAAQ,EAAE,uBAAuB;KAClC;IACD;QACE,EAAE,EAAE,iBAAiB;QACrB,KAAK,EAAE,sCAAsC;QAC7C,WAAW,EAAE,6HAA6H;QAC1I,SAAS,EAAE,UAAU;QACrB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC;YACtB,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM;SAC/F,CAAC;KACH;IACD;QACE,EAAE,EAAE,gBAAgB;QACpB,KAAK,EAAE,6BAA6B;QACpC,WAAW,EAAE,0HAA0H;QACvI,SAAS,EAAE,MAAM;QACjB,mBAAmB,EAAE,IAAI;QACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC;YACtB,OAAO,EAAE,QAAQ,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AW,EAAE,CAAC,CAAC,CAAC;IAE7G,MAAM,oBAAoB,GAAG,MAAM,CAAC,eAAe,KAAK,MAAM;QAC5D,CAAC,CAAC,CAAC,GAAG,CAAC;QACP,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAEjF,OAAO;QACL,GAAG,KAAK;QACR,kBAAkB,EAAE,oBAAoB;QACxC,eAAe,EAAE,gBAAgB;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const CANONICAL_PACKAGE_NAME = "@belboy47/brc-agent";
|
|
2
|
+
export interface UpdateCheckResult {
|
|
3
|
+
ok: boolean;
|
|
4
|
+
installedVersion: string;
|
|
5
|
+
latestVersion?: string;
|
|
6
|
+
updateAvailable: boolean;
|
|
7
|
+
distTags?: Record<string, string>;
|
|
8
|
+
error?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface UpdateInstallResult {
|
|
11
|
+
ok: boolean;
|
|
12
|
+
installedVersion: string;
|
|
13
|
+
targetVersion?: string;
|
|
14
|
+
output?: string;
|
|
15
|
+
error?: string;
|
|
16
|
+
recoveryCommand: string;
|
|
17
|
+
}
|
|
18
|
+
export interface UpdaterDeps {
|
|
19
|
+
runCommand?: (cmd: string, args: string[], env: NodeJS.ProcessEnv) => Promise<{
|
|
20
|
+
stdout: string;
|
|
21
|
+
stderr: string;
|
|
22
|
+
}>;
|
|
23
|
+
platform?: NodeJS.Platform;
|
|
24
|
+
}
|
|
25
|
+
/** Basic SemVer comparison supporting `major.minor.patch[-prerelease]`. */
|
|
26
|
+
export declare function compareSemver(a: string, b: string): number;
|
|
27
|
+
export declare function checkForUpdates(installedVersion: string, deps?: UpdaterDeps): Promise<UpdateCheckResult>;
|
|
28
|
+
export declare function installLatestUpdate(installedVersion: string, targetVersion?: string, deps?: UpdaterDeps): Promise<UpdateInstallResult>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operator-approved update checking and installation for `@belboy47/brc-agent`.
|
|
3
|
+
*
|
|
4
|
+
* Security & safety invariants:
|
|
5
|
+
* - Never auto-updates without explicit local operator approval.
|
|
6
|
+
* - Stops any running detached agent before installing a new version so no
|
|
7
|
+
* orphaned old-executable process remains active.
|
|
8
|
+
* - Never silently restarts the agent with expanded permissions after update.
|
|
9
|
+
* - Uses `PUPPETEER_SKIP_DOWNLOAD=true` for fast, headless updates.
|
|
10
|
+
*/
|
|
11
|
+
import { execFile } from 'node:child_process';
|
|
12
|
+
import { promisify } from 'node:util';
|
|
13
|
+
const execFileAsync = promisify(execFile);
|
|
14
|
+
export const CANONICAL_PACKAGE_NAME = '@belboy47/brc-agent';
|
|
15
|
+
function npmBin(platform = process.platform) {
|
|
16
|
+
return platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
17
|
+
}
|
|
18
|
+
/** Basic SemVer comparison supporting `major.minor.patch[-prerelease]`. */
|
|
19
|
+
export function compareSemver(a, b) {
|
|
20
|
+
const parse = (v) => {
|
|
21
|
+
const clean = v.trim().replace(/^v/, '');
|
|
22
|
+
const [core, pre] = clean.split('-', 2);
|
|
23
|
+
const nums = core.split('.').map((n) => Number.parseInt(n, 10) || 0);
|
|
24
|
+
return { major: nums[0] ?? 0, minor: nums[1] ?? 0, patch: nums[2] ?? 0, pre: pre ?? '' };
|
|
25
|
+
};
|
|
26
|
+
const pa = parse(a);
|
|
27
|
+
const pb = parse(b);
|
|
28
|
+
if (pa.major !== pb.major)
|
|
29
|
+
return pa.major > pb.major ? 1 : -1;
|
|
30
|
+
if (pa.minor !== pb.minor)
|
|
31
|
+
return pa.minor > pb.minor ? 1 : -1;
|
|
32
|
+
if (pa.patch !== pb.patch)
|
|
33
|
+
return pa.patch > pb.patch ? 1 : -1;
|
|
34
|
+
if (!pa.pre && pb.pre)
|
|
35
|
+
return 1;
|
|
36
|
+
if (pa.pre && !pb.pre)
|
|
37
|
+
return -1;
|
|
38
|
+
return pa.pre.localeCompare(pb.pre);
|
|
39
|
+
}
|
|
40
|
+
async function defaultRun(cmd, args, env) {
|
|
41
|
+
const res = await execFileAsync(cmd, args, {
|
|
42
|
+
env,
|
|
43
|
+
timeout: 120_000,
|
|
44
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
45
|
+
windowsHide: true,
|
|
46
|
+
});
|
|
47
|
+
return { stdout: String(res.stdout ?? ''), stderr: String(res.stderr ?? '') };
|
|
48
|
+
}
|
|
49
|
+
export async function checkForUpdates(installedVersion, deps = {}) {
|
|
50
|
+
const run = deps.runCommand ?? defaultRun;
|
|
51
|
+
const bin = npmBin(deps.platform);
|
|
52
|
+
try {
|
|
53
|
+
const { stdout } = await run(bin, ['view', CANONICAL_PACKAGE_NAME, 'dist-tags', '--json'], process.env);
|
|
54
|
+
const parsed = JSON.parse(stdout.trim());
|
|
55
|
+
const distTags = Array.isArray(parsed) ? (parsed[0]?.['dist-tags'] ?? parsed[0] ?? {}) : (parsed['dist-tags'] ?? parsed);
|
|
56
|
+
const latestVersion = typeof distTags.latest === 'string' ? distTags.latest : undefined;
|
|
57
|
+
if (!latestVersion) {
|
|
58
|
+
return {
|
|
59
|
+
ok: false,
|
|
60
|
+
installedVersion,
|
|
61
|
+
updateAvailable: false,
|
|
62
|
+
error: 'Registry response did not include a latest dist-tag.',
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
ok: true,
|
|
67
|
+
installedVersion,
|
|
68
|
+
latestVersion,
|
|
69
|
+
distTags,
|
|
70
|
+
updateAvailable: compareSemver(latestVersion, installedVersion) > 0,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
return {
|
|
75
|
+
ok: false,
|
|
76
|
+
installedVersion,
|
|
77
|
+
updateAvailable: false,
|
|
78
|
+
error: err instanceof Error ? err.message : String(err),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export async function installLatestUpdate(installedVersion, targetVersion, deps = {}) {
|
|
83
|
+
const run = deps.runCommand ?? defaultRun;
|
|
84
|
+
const plat = deps.platform ?? process.platform;
|
|
85
|
+
const bin = npmBin(plat);
|
|
86
|
+
const recoveryCommand = plat === 'win32'
|
|
87
|
+
? `$env:PUPPETEER_SKIP_DOWNLOAD="true"; npm install -g ${CANONICAL_PACKAGE_NAME}`
|
|
88
|
+
: `PUPPETEER_SKIP_DOWNLOAD=true npm install -g ${CANONICAL_PACKAGE_NAME}`;
|
|
89
|
+
try {
|
|
90
|
+
const env = {
|
|
91
|
+
...process.env,
|
|
92
|
+
PUPPETEER_SKIP_DOWNLOAD: 'true',
|
|
93
|
+
};
|
|
94
|
+
const { stdout, stderr } = await run(bin, ['install', '-g', `${CANONICAL_PACKAGE_NAME}@latest`], env);
|
|
95
|
+
return {
|
|
96
|
+
ok: true,
|
|
97
|
+
installedVersion,
|
|
98
|
+
targetVersion,
|
|
99
|
+
output: [stdout.trim(), stderr.trim()].filter(Boolean).join('\n'),
|
|
100
|
+
recoveryCommand,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
return {
|
|
105
|
+
ok: false,
|
|
106
|
+
installedVersion,
|
|
107
|
+
targetVersion,
|
|
108
|
+
error: err instanceof Error ? err.message : String(err),
|
|
109
|
+
recoveryCommand,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=updater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updater.js","sourceRoot":"","sources":["../../src/runtime/updater.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,aAAa,GAAG,SAAS,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.ZodObject<{
|
|
|
18
18
|
command: string;
|
|
19
19
|
timeout_ms?: number | undefined;
|
|
20
20
|
shell?: string | undefined;
|
|
21
|
+
label?: string | undefined;
|
|
21
22
|
cwd?: string | undefined;
|
|
22
23
|
raw?: boolean | undefined;
|
|
23
|
-
label?: string | undefined;
|
|
24
24
|
}, {
|
|
25
25
|
command: string;
|
|
26
26
|
timeout_ms?: number | undefined;
|
|
27
27
|
shell?: string | undefined;
|
|
28
|
+
label?: string | undefined;
|
|
28
29
|
cwd?: string | undefined;
|
|
29
30
|
raw?: boolean | undefined;
|
|
30
|
-
label?: string | undefined;
|
|
31
31
|
}>, z.ZodObject<{
|
|
32
32
|
tool: z.ZodString;
|
|
33
33
|
args: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
@@ -38,8 +38,8 @@ export declare const SpawnJobArgsSchema: z.ZodObject<{
|
|
|
38
38
|
label?: string | undefined;
|
|
39
39
|
}, {
|
|
40
40
|
tool: string;
|
|
41
|
-
args?: Record<string, unknown> | undefined;
|
|
42
41
|
label?: string | undefined;
|
|
42
|
+
args?: Record<string, unknown> | undefined;
|
|
43
43
|
}>]>, "many">>;
|
|
44
44
|
label: z.ZodOptional<z.ZodString>;
|
|
45
45
|
group: z.ZodOptional<z.ZodString>;
|
|
@@ -49,39 +49,39 @@ export declare const SpawnJobArgsSchema: z.ZodObject<{
|
|
|
49
49
|
timeout_ms: number;
|
|
50
50
|
continue_on_error: boolean;
|
|
51
51
|
command?: string | undefined;
|
|
52
|
+
label?: string | undefined;
|
|
52
53
|
cwd?: string | undefined;
|
|
53
54
|
group?: string | undefined;
|
|
54
55
|
steps?: ({
|
|
55
56
|
command: string;
|
|
56
57
|
timeout_ms?: number | undefined;
|
|
57
58
|
shell?: string | undefined;
|
|
59
|
+
label?: string | undefined;
|
|
58
60
|
cwd?: string | undefined;
|
|
59
61
|
raw?: boolean | undefined;
|
|
60
|
-
label?: string | undefined;
|
|
61
62
|
} | {
|
|
62
63
|
tool: string;
|
|
63
64
|
args: Record<string, unknown>;
|
|
64
65
|
label?: string | undefined;
|
|
65
66
|
})[] | undefined;
|
|
66
|
-
label?: string | undefined;
|
|
67
67
|
}, {
|
|
68
68
|
command?: string | undefined;
|
|
69
69
|
timeout_ms?: number | undefined;
|
|
70
|
+
label?: string | undefined;
|
|
70
71
|
cwd?: string | undefined;
|
|
71
72
|
group?: string | undefined;
|
|
72
73
|
steps?: ({
|
|
73
74
|
command: string;
|
|
74
75
|
timeout_ms?: number | undefined;
|
|
75
76
|
shell?: string | undefined;
|
|
77
|
+
label?: string | undefined;
|
|
76
78
|
cwd?: string | undefined;
|
|
77
79
|
raw?: boolean | undefined;
|
|
78
|
-
label?: string | undefined;
|
|
79
80
|
} | {
|
|
80
81
|
tool: string;
|
|
81
|
-
args?: Record<string, unknown> | undefined;
|
|
82
82
|
label?: string | undefined;
|
|
83
|
+
args?: Record<string, unknown> | undefined;
|
|
83
84
|
})[] | undefined;
|
|
84
|
-
label?: string | undefined;
|
|
85
85
|
continue_on_error?: boolean | undefined;
|
|
86
86
|
}>;
|
|
87
87
|
export declare const WaitJobsArgsSchema: z.ZodObject<{
|
|
@@ -157,16 +157,16 @@ export declare const RunParallelArgsSchema: z.ZodObject<{
|
|
|
157
157
|
command: string;
|
|
158
158
|
timeout_ms?: number | undefined;
|
|
159
159
|
shell?: string | undefined;
|
|
160
|
+
label?: string | undefined;
|
|
160
161
|
cwd?: string | undefined;
|
|
161
162
|
raw?: boolean | undefined;
|
|
162
|
-
label?: string | undefined;
|
|
163
163
|
}, {
|
|
164
164
|
command: string;
|
|
165
165
|
timeout_ms?: number | undefined;
|
|
166
166
|
shell?: string | undefined;
|
|
167
|
+
label?: string | undefined;
|
|
167
168
|
cwd?: string | undefined;
|
|
168
169
|
raw?: boolean | undefined;
|
|
169
|
-
label?: string | undefined;
|
|
170
170
|
}>, z.ZodObject<{
|
|
171
171
|
tool: z.ZodString;
|
|
172
172
|
args: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
@@ -177,8 +177,8 @@ export declare const RunParallelArgsSchema: z.ZodObject<{
|
|
|
177
177
|
label?: string | undefined;
|
|
178
178
|
}, {
|
|
179
179
|
tool: string;
|
|
180
|
-
args?: Record<string, unknown> | undefined;
|
|
181
180
|
label?: string | undefined;
|
|
181
|
+
args?: Record<string, unknown> | undefined;
|
|
182
182
|
}>]>, "many">;
|
|
183
183
|
max_concurrency: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
184
184
|
timeout_ms: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
@@ -189,9 +189,9 @@ export declare const RunParallelArgsSchema: z.ZodObject<{
|
|
|
189
189
|
command: string;
|
|
190
190
|
timeout_ms?: number | undefined;
|
|
191
191
|
shell?: string | undefined;
|
|
192
|
+
label?: string | undefined;
|
|
192
193
|
cwd?: string | undefined;
|
|
193
194
|
raw?: boolean | undefined;
|
|
194
|
-
label?: string | undefined;
|
|
195
195
|
} | {
|
|
196
196
|
tool: string;
|
|
197
197
|
args: Record<string, unknown>;
|
|
@@ -204,13 +204,13 @@ export declare const RunParallelArgsSchema: z.ZodObject<{
|
|
|
204
204
|
command: string;
|
|
205
205
|
timeout_ms?: number | undefined;
|
|
206
206
|
shell?: string | undefined;
|
|
207
|
+
label?: string | undefined;
|
|
207
208
|
cwd?: string | undefined;
|
|
208
209
|
raw?: boolean | undefined;
|
|
209
|
-
label?: string | undefined;
|
|
210
210
|
} | {
|
|
211
211
|
tool: string;
|
|
212
|
-
args?: Record<string, unknown> | undefined;
|
|
213
212
|
label?: string | undefined;
|
|
213
|
+
args?: Record<string, unknown> | undefined;
|
|
214
214
|
})[];
|
|
215
215
|
timeout_ms?: number | undefined;
|
|
216
216
|
output_chars?: number | undefined;
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@belboy47/brc-agent",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Better Remote Commander (BRC)
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Better Remote Commander (BRC) unified CLI and interactive manager for AI-assisted engineering, remote operations, and authorized network administration.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"brc
|
|
9
|
-
"brc-agent": "dist/cli.js"
|
|
8
|
+
"brc": "dist/cli.js"
|
|
10
9
|
},
|
|
11
10
|
"main": "dist/index.js",
|
|
12
11
|
"files": [
|