homeagent-runner 0.0.0-stage → 0.4.4
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/CHANGELOG.md +124 -0
- package/CONTRIBUTING.md +65 -0
- package/LICENSE +21 -0
- package/README.en.md +300 -0
- package/README.md +217 -2
- package/SECURITY.md +59 -0
- package/THIRD_PARTY_NOTICES.md +45 -0
- package/bin/runner.mjs +2 -0
- package/dist/runner/agent.js +254 -0
- package/dist/runner/cli.js +66 -0
- package/dist/runner/config-location.js +67 -0
- package/dist/runner/config.js +43 -0
- package/dist/runner/context.js +86 -0
- package/dist/runner/credentials.js +68 -0
- package/dist/runner/editor.js +262 -0
- package/dist/runner/files.js +298 -0
- package/dist/runner/git.js +333 -0
- package/dist/runner/lock.js +28 -0
- package/dist/runner/output-log.js +59 -0
- package/dist/runner/patch.js +103 -0
- package/dist/runner/permissions.js +93 -0
- package/dist/runner/policy.js +87 -0
- package/dist/runner/process-tree.js +28 -0
- package/dist/runner/processes.js +367 -0
- package/dist/runner/service.js +53 -0
- package/dist/runner/setup.js +79 -0
- package/dist/runner/tools.js +118 -0
- package/dist/shared/permissions.js +40 -0
- package/dist/shared/protocol.js +98 -0
- package/dist/shared/tools.js +108 -0
- package/docs/ARCHITECTURE.md +92 -0
- package/docs/CLIENTS.md +130 -0
- package/docs/COMPARISON.md +36 -0
- package/docs/DEPLOYMENT.md +295 -0
- package/docs/DEVELOPMENT_WORKFLOW.md +126 -0
- package/docs/OPEN_SOURCE.md +127 -0
- package/docs/README.md +26 -0
- package/docs/TOOLS.md +105 -0
- package/docs/VALIDATION.md +172 -0
- package/docs/WEBCODEX_CODE_AUDIT.md +107 -0
- package/docs/webcodex-parity-map.json +75 -0
- package/docs/webcodex-source-inventory.json +2254 -0
- package/licenses/npm-runtime.txt +3673 -0
- package/package.json +44 -4
- package/runtime/windows-process-tree.cs +105 -0
- package/runtime/windows-process-tree.ps1 +19 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { closeSync, openSync, readSync, writeSync } from 'node:fs';
|
|
2
|
+
export const TAIL_BYTES = 65536;
|
|
3
|
+
/** Preserve the original bounded prefix API and a separate fixed-size rolling tail. */
|
|
4
|
+
export class OutputLog {
|
|
5
|
+
capacity;
|
|
6
|
+
prefix;
|
|
7
|
+
tail;
|
|
8
|
+
total = 0;
|
|
9
|
+
retained = 0;
|
|
10
|
+
constructor(prefixFile, capacity) {
|
|
11
|
+
this.capacity = capacity;
|
|
12
|
+
this.prefix = openSync(prefixFile, 'wx', 0o600);
|
|
13
|
+
try {
|
|
14
|
+
this.tail = openSync(`${prefixFile}.tail`, 'wx', 0o600);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
closeSync(this.prefix);
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
append(bytes) {
|
|
22
|
+
const accepted = bytes.subarray(0, Math.max(0, this.capacity - this.retained));
|
|
23
|
+
if (accepted.length) {
|
|
24
|
+
writeSync(this.prefix, accepted);
|
|
25
|
+
this.retained += accepted.length;
|
|
26
|
+
}
|
|
27
|
+
// Only the last TAIL_BYTES of an oversized producer chunk can remain in the ring.
|
|
28
|
+
const tail = bytes.subarray(Math.max(0, bytes.length - TAIL_BYTES));
|
|
29
|
+
const position = (this.total + bytes.length - tail.length) % TAIL_BYTES;
|
|
30
|
+
const first = Math.min(tail.length, TAIL_BYTES - position);
|
|
31
|
+
if (first)
|
|
32
|
+
writeSync(this.tail, tail, 0, first, position);
|
|
33
|
+
if (first < tail.length)
|
|
34
|
+
writeSync(this.tail, tail, first, tail.length - first, 0);
|
|
35
|
+
this.total += bytes.length;
|
|
36
|
+
}
|
|
37
|
+
close() { closeSync(this.prefix); closeSync(this.tail); }
|
|
38
|
+
static read(prefixFile, total, length, cursor) {
|
|
39
|
+
const oldest = Math.max(0, total - TAIL_BYTES);
|
|
40
|
+
const requested = cursor ?? Math.max(oldest, total - length);
|
|
41
|
+
const start = Math.min(total, Math.max(oldest, requested));
|
|
42
|
+
const count = Math.min(length, total - start);
|
|
43
|
+
const bytes = Buffer.alloc(count);
|
|
44
|
+
if (count) {
|
|
45
|
+
const fd = openSync(`${prefixFile}.tail`, 'r');
|
|
46
|
+
try {
|
|
47
|
+
const position = start % TAIL_BYTES, first = Math.min(count, TAIL_BYTES - position);
|
|
48
|
+
readSync(fd, bytes, 0, first, position);
|
|
49
|
+
if (first < count)
|
|
50
|
+
readSync(fd, bytes, first, count - first, 0);
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
closeSync(fd);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { output: bytes.toString('utf8'), cursor: start, nextCursor: start + count, oldestCursor: oldest, totalOutputBytes: total, skippedBytes: Math.max(0, oldest - requested), eof: start + count >= total };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=output-log.js.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { AppError } from '../shared/protocol.js';
|
|
2
|
+
/** Deliberately strict unified diff parser: line-numbered context must match, with no fuzzy relocation. */
|
|
3
|
+
export async function parseUnifiedDiff(files, project, diff, expected) {
|
|
4
|
+
const lines = diff.replace(/\r\n/g, '\n').split('\n');
|
|
5
|
+
const changes = [];
|
|
6
|
+
let index = 0;
|
|
7
|
+
const filename = (line, prefix) => {
|
|
8
|
+
const name = line.slice(prefix.length).split('\t')[0];
|
|
9
|
+
if (!name || name.startsWith('"'))
|
|
10
|
+
throw new AppError('invalid_patch', 'Quoted/empty diff paths are not supported');
|
|
11
|
+
return name === '/dev/null' ? null : name.replace(/^[ab]\//, '');
|
|
12
|
+
};
|
|
13
|
+
while (index < lines.length) {
|
|
14
|
+
if (!lines[index] || /^(diff --git |index |new file mode |deleted file mode )/.test(lines[index])) {
|
|
15
|
+
index++;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (!lines[index].startsWith('--- '))
|
|
19
|
+
throw new AppError('invalid_patch', 'Expected --- file header; binary/mode-only/rename patches are not supported');
|
|
20
|
+
const beforePath = filename(lines[index++], '--- ');
|
|
21
|
+
if (!lines[index]?.startsWith('+++ '))
|
|
22
|
+
throw new AppError('invalid_patch', 'Missing +++ file header');
|
|
23
|
+
const afterPath = filename(lines[index++], '+++ ');
|
|
24
|
+
if ((!beforePath && !afterPath) || (beforePath && afterPath && beforePath !== afterPath))
|
|
25
|
+
throw new AppError('invalid_patch', 'Rename patches are not supported');
|
|
26
|
+
const name = afterPath ?? beforePath;
|
|
27
|
+
if (!Object.hasOwn(expected, name))
|
|
28
|
+
throw new AppError('missing_revision', `Supply expectedSha256 for ${name}`);
|
|
29
|
+
const snapshot = await files.snapshot(project, name, true);
|
|
30
|
+
if (snapshot.sha256 !== expected[name] || (!beforePath && snapshot.bytes !== null) || (beforePath && snapshot.bytes === null))
|
|
31
|
+
throw new AppError('conflict', `Patch file changed: ${name}`);
|
|
32
|
+
const originalText = snapshot.bytes ? new TextDecoder('utf-8', { fatal: true }).decode(snapshot.bytes) : '';
|
|
33
|
+
const crlf = originalText.includes('\r\n'), original = originalText.replace(/\r\n/g, '\n').match(/[^\n]*\n|[^\n]+$/g) ?? [];
|
|
34
|
+
const output = [];
|
|
35
|
+
let consumed = 0, hunks = 0;
|
|
36
|
+
while (index < lines.length && lines[index].startsWith('@@ ')) {
|
|
37
|
+
const header = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?:.*)$/.exec(lines[index++]);
|
|
38
|
+
if (!header)
|
|
39
|
+
throw new AppError('invalid_patch', 'Invalid hunk header');
|
|
40
|
+
const oldCount = Number(header[2] ?? 1), newCount = Number(header[4] ?? 1);
|
|
41
|
+
const oldStart = oldCount === 0 ? Number(header[1]) : Number(header[1]) - 1;
|
|
42
|
+
if (oldStart < consumed || oldStart > original.length)
|
|
43
|
+
throw new AppError('invalid_patch', 'Overlapping or out-of-range hunks');
|
|
44
|
+
output.push(...original.slice(consumed, oldStart));
|
|
45
|
+
consumed = oldStart;
|
|
46
|
+
const newStart = newCount === 0 ? Number(header[3]) : Number(header[3]) - 1;
|
|
47
|
+
if (newStart !== output.length)
|
|
48
|
+
throw new AppError('invalid_patch', 'New hunk line position does not match preceding changes');
|
|
49
|
+
const removed = [], added = [];
|
|
50
|
+
let oldLines = 0, newLines = 0, previous;
|
|
51
|
+
while (oldLines < oldCount || newLines < newCount) {
|
|
52
|
+
const line = lines[index++];
|
|
53
|
+
if (line === undefined || ![' ', '+', '-'].includes(line[0] ?? ''))
|
|
54
|
+
throw new AppError('invalid_patch', 'Unexpected end or invalid hunk body');
|
|
55
|
+
const value = `${line.slice(1)}\n`;
|
|
56
|
+
previous = {};
|
|
57
|
+
if (line[0] !== '+') {
|
|
58
|
+
previous.old = removed.length;
|
|
59
|
+
removed.push(value);
|
|
60
|
+
oldLines++;
|
|
61
|
+
}
|
|
62
|
+
if (line[0] !== '-') {
|
|
63
|
+
previous.next = added.length;
|
|
64
|
+
added.push(value);
|
|
65
|
+
newLines++;
|
|
66
|
+
}
|
|
67
|
+
if (lines[index] === '\') {
|
|
68
|
+
if (previous.old !== undefined)
|
|
69
|
+
removed[previous.old] = removed[previous.old].slice(0, -1);
|
|
70
|
+
if (previous.next !== undefined)
|
|
71
|
+
added[previous.next] = added[previous.next].slice(0, -1);
|
|
72
|
+
index++;
|
|
73
|
+
}
|
|
74
|
+
if (oldLines > oldCount || newLines > newCount)
|
|
75
|
+
throw new AppError('invalid_patch', 'Hunk line counts do not match header');
|
|
76
|
+
}
|
|
77
|
+
if (original.slice(consumed, consumed + oldCount).join('') !== removed.join(''))
|
|
78
|
+
throw new AppError('patch_context', `Hunk context does not match ${name}`);
|
|
79
|
+
output.push(...added);
|
|
80
|
+
consumed += oldCount;
|
|
81
|
+
hunks++;
|
|
82
|
+
}
|
|
83
|
+
if (!hunks)
|
|
84
|
+
throw new AppError('invalid_patch', 'A file patch must contain at least one hunk');
|
|
85
|
+
output.push(...original.slice(consumed));
|
|
86
|
+
let content = output.join('');
|
|
87
|
+
if (crlf)
|
|
88
|
+
content = content.replace(/\n/g, '\r\n');
|
|
89
|
+
if (!afterPath) {
|
|
90
|
+
if (content !== '')
|
|
91
|
+
throw new AppError('invalid_patch', 'Deletion must remove the complete file');
|
|
92
|
+
changes.push({ operation: 'delete', path: name, expectedSha256: snapshot.sha256 });
|
|
93
|
+
}
|
|
94
|
+
else if (!beforePath)
|
|
95
|
+
changes.push({ operation: 'create', path: name, content });
|
|
96
|
+
else
|
|
97
|
+
changes.push({ operation: 'replace', path: name, expectedSha256: snapshot.sha256, content });
|
|
98
|
+
}
|
|
99
|
+
if (!changes.length || changes.length > 32)
|
|
100
|
+
throw new AppError('invalid_patch', 'Expected 1 to 32 file changes');
|
|
101
|
+
return changes;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=patch.js.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { realpath, stat } from 'node:fs/promises';
|
|
3
|
+
import { remotePermissionsSchema } from '../shared/permissions.js';
|
|
4
|
+
import { AppError } from '../shared/protocol.js';
|
|
5
|
+
import { inside, projectConfigSchema } from './config.js';
|
|
6
|
+
export class RunnerPermissions {
|
|
7
|
+
config;
|
|
8
|
+
tools;
|
|
9
|
+
invalidate;
|
|
10
|
+
changed;
|
|
11
|
+
revision = -1;
|
|
12
|
+
current;
|
|
13
|
+
timer;
|
|
14
|
+
queue = Promise.resolve();
|
|
15
|
+
constructor(config, tools, invalidate, changed) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.tools = tools;
|
|
18
|
+
this.invalidate = invalidate;
|
|
19
|
+
this.changed = changed;
|
|
20
|
+
this.config.projects = [];
|
|
21
|
+
}
|
|
22
|
+
apply(input) {
|
|
23
|
+
const next = this.queue.catch(() => { }).then(() => this.applyNow(input));
|
|
24
|
+
this.queue = next;
|
|
25
|
+
return next;
|
|
26
|
+
}
|
|
27
|
+
async applyNow(input) {
|
|
28
|
+
const policy = remotePermissionsSchema.parse(input);
|
|
29
|
+
if (policy.revision < this.revision)
|
|
30
|
+
throw new AppError('stale_permissions', 'Refusing an older device permission revision');
|
|
31
|
+
const expired = !!policy.expiresAt && policy.expiresAt <= Date.now();
|
|
32
|
+
const selected = expired ? policy.fallbackProjects : policy.projects;
|
|
33
|
+
// A policy that fails validation must still stop the previous authority.
|
|
34
|
+
await this.invalidate();
|
|
35
|
+
await this.tools.processes.stopAllAndWait();
|
|
36
|
+
this.config.projects = [];
|
|
37
|
+
this.tools.policy.expiresAt = undefined;
|
|
38
|
+
this.current = undefined;
|
|
39
|
+
const projects = [];
|
|
40
|
+
for (const project of selected) {
|
|
41
|
+
if (!path.isAbsolute(project.root))
|
|
42
|
+
throw new AppError('invalid_root', 'Web project roots must be absolute paths');
|
|
43
|
+
const root = await realpath(project.root);
|
|
44
|
+
if (!(await stat(root)).isDirectory())
|
|
45
|
+
throw new AppError('invalid_root', 'Project root must be an existing directory');
|
|
46
|
+
if (inside(this.config.stateDir, root) || (project.filesystemScope !== 'device' && inside(root, this.config.stateDir)))
|
|
47
|
+
throw new AppError('private_state', 'Runner state cannot be exposed as a project');
|
|
48
|
+
if (project.filesystemScope !== 'device' && this.config.protectedPaths?.some(privatePath => inside(root, privatePath)))
|
|
49
|
+
throw new AppError('private_state', 'Project roots must exclude the Runner configuration and private state');
|
|
50
|
+
projects.push(projectConfigSchema.parse({ ...project, root, ...(project.gitCommonDir ? { gitCommonDir: await realpath(project.gitCommonDir) } : {}) }));
|
|
51
|
+
}
|
|
52
|
+
if (new Set(projects.map(project => project.id)).size !== projects.length)
|
|
53
|
+
throw new AppError('duplicate_project', 'Project IDs must be unique');
|
|
54
|
+
if (this.timer)
|
|
55
|
+
clearTimeout(this.timer);
|
|
56
|
+
this.revision = policy.revision;
|
|
57
|
+
this.current = policy;
|
|
58
|
+
this.config.projects = projects;
|
|
59
|
+
this.tools.policy.expiresAt = !expired ? policy.expiresAt ?? undefined : undefined;
|
|
60
|
+
try {
|
|
61
|
+
await this.tools.editor.reconcileProjects();
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
this.config.projects = [];
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
if (!expired && policy.expiresAt)
|
|
68
|
+
this.timer = setTimeout(() => {
|
|
69
|
+
if (this.current !== policy)
|
|
70
|
+
return;
|
|
71
|
+
// Revoke access before attempting a possibly moved permanent root.
|
|
72
|
+
void this.reset().then(() => this.apply({ revision: policy.revision, projects: policy.fallbackProjects, expiresAt: null, fallbackProjects: policy.fallbackProjects })).then(() => this.changed(policy.revision)).catch(error => this.changed(policy.revision, error instanceof Error ? error.message : 'Permission expiration failed'));
|
|
73
|
+
}, Math.max(1, policy.expiresAt - Date.now())).unref();
|
|
74
|
+
}
|
|
75
|
+
reset() {
|
|
76
|
+
const next = this.queue.catch(() => { }).then(() => this.resetNow());
|
|
77
|
+
this.queue = next;
|
|
78
|
+
return next;
|
|
79
|
+
}
|
|
80
|
+
async resetNow() {
|
|
81
|
+
if (this.timer)
|
|
82
|
+
clearTimeout(this.timer);
|
|
83
|
+
this.timer = undefined;
|
|
84
|
+
await this.invalidate();
|
|
85
|
+
await this.tools.processes.stopAllAndWait();
|
|
86
|
+
this.config.projects = [];
|
|
87
|
+
this.tools.policy.expiresAt = undefined;
|
|
88
|
+
this.current = undefined;
|
|
89
|
+
}
|
|
90
|
+
close() { if (this.timer)
|
|
91
|
+
clearTimeout(this.timer); this.config.projects = []; this.tools.policy.expiresAt = undefined; }
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { lstat, realpath } from 'node:fs/promises';
|
|
3
|
+
import { AppError, projectGranted } from '../shared/protocol.js';
|
|
4
|
+
import { inside } from './config.js';
|
|
5
|
+
export class Policy {
|
|
6
|
+
config;
|
|
7
|
+
expiresAt;
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.config = config;
|
|
10
|
+
}
|
|
11
|
+
project(id, principal, scope, deviceId) {
|
|
12
|
+
if ((this.expiresAt && this.expiresAt <= Date.now()) || (principal.authorizationExpiresAt && principal.authorizationExpiresAt <= Date.now()))
|
|
13
|
+
throw new AppError('permissions_expired', 'Temporary permission has expired');
|
|
14
|
+
const project = this.config.projects.find(item => item.id === id);
|
|
15
|
+
if (!project)
|
|
16
|
+
throw new AppError('unknown_project', 'Project not allowed');
|
|
17
|
+
if (!principal.scopes.includes(scope) || (principal.projects && !principal.projects.includes(id)))
|
|
18
|
+
throw new AppError('forbidden', 'Project or tool scope not granted');
|
|
19
|
+
if (principal.projectGrants && (!deviceId || !projectGranted(principal, deviceId, id)))
|
|
20
|
+
throw new AppError('forbidden', 'Device/project pair is outside the credential grant');
|
|
21
|
+
if (project.readOnly && scope !== 'read')
|
|
22
|
+
throw new AppError('read_only', 'Project is read-only');
|
|
23
|
+
if (scope === 'git' && !project.allowGitWrite)
|
|
24
|
+
throw new AppError('git_write_disabled', 'Git writes are disabled in the device policy');
|
|
25
|
+
return {
|
|
26
|
+
...project,
|
|
27
|
+
filesystemScope: project.filesystemScope === 'device' && principal.machineAccess ? 'device' : 'project',
|
|
28
|
+
commandMode: project.commandMode === 'unrestricted' && principal.unrestrictedExecution ? 'unrestricted' : 'allowlist',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Reject symlinks/junctions at every component, including existing parents of a new path. */
|
|
32
|
+
async resolve(project, input, allowMissing = false) {
|
|
33
|
+
if (this.expiresAt && this.expiresAt <= Date.now())
|
|
34
|
+
throw new AppError('permissions_expired', 'Temporary device permissions have expired');
|
|
35
|
+
if (input.includes('\0'))
|
|
36
|
+
throw new AppError('invalid_path', 'Invalid path');
|
|
37
|
+
const target = path.resolve(project.root, input);
|
|
38
|
+
if (project.filesystemScope !== 'device' && !inside(project.root, target))
|
|
39
|
+
throw new AppError('path_escape', 'Path is outside the project');
|
|
40
|
+
const protectedPaths = [this.config.stateDir, ...(this.config.protectedPaths ?? [])];
|
|
41
|
+
if (protectedPaths.some(privatePath => inside(privatePath, target)))
|
|
42
|
+
throw new AppError('private_state', 'Runner configuration and private state are not exposed through file tools');
|
|
43
|
+
const boundary = project.filesystemScope === 'device' ? path.parse(target).root : project.root;
|
|
44
|
+
const parts = path.relative(boundary, target).split(path.sep).filter(Boolean);
|
|
45
|
+
let current = boundary, missing = false;
|
|
46
|
+
for (const part of parts) {
|
|
47
|
+
// Prevent NTFS alternate data streams and trailing-dot/space aliases.
|
|
48
|
+
if (project.deniedNames.some(name => name.toLowerCase() === part.toLowerCase()) || (process.platform === 'win32' && (/[<>:"|?*]/.test(part) || /[. ]$/.test(part) || /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(part))))
|
|
49
|
+
throw new AppError('denied_path', 'Path is excluded by the device policy');
|
|
50
|
+
current = path.join(current, part);
|
|
51
|
+
if (missing)
|
|
52
|
+
continue;
|
|
53
|
+
try {
|
|
54
|
+
const stat = await lstat(current);
|
|
55
|
+
if (stat.isSymbolicLink())
|
|
56
|
+
throw new AppError('symlink', 'Symbolic links and junctions are not allowed');
|
|
57
|
+
if (!stat.isFile() && !stat.isDirectory())
|
|
58
|
+
throw new AppError('special_file', 'Special files, sockets and devices are not allowed');
|
|
59
|
+
if (stat.isFile() && stat.nlink > 1)
|
|
60
|
+
throw new AppError('hardlink', 'Hard-linked files are not allowed');
|
|
61
|
+
const actual = await realpath(current);
|
|
62
|
+
if (project.filesystemScope !== 'device' && !inside(project.root, actual))
|
|
63
|
+
throw new AppError('path_escape', 'Resolved path escaped the project');
|
|
64
|
+
if (protectedPaths.some(privatePath => inside(privatePath, actual)))
|
|
65
|
+
throw new AppError('private_state', 'Runner private state is not exposed');
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (allowMissing && error.code === 'ENOENT')
|
|
69
|
+
missing = true;
|
|
70
|
+
else
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (await realpath(project.root) !== project.root)
|
|
75
|
+
throw new AppError('root_changed', 'Project root changed; restart the runner');
|
|
76
|
+
return target;
|
|
77
|
+
}
|
|
78
|
+
command(project, executable) {
|
|
79
|
+
const equal = (a, b) => process.platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
80
|
+
if (project.commandMode !== 'unrestricted' && !project.commands.some(command => equal(command, executable)))
|
|
81
|
+
throw new AppError('command_denied', 'Executable is not in the project command allowlist; the owner can change execution permissions in the Dashboard');
|
|
82
|
+
// Shells, runtimes and build tools remain powerful if explicitly allowed.
|
|
83
|
+
if (process.platform === 'win32' && /\.(cmd|bat)$/i.test(executable))
|
|
84
|
+
throw new AppError('command_denied', 'Use an executable, not a .cmd/.bat wrapper; shell execution is never implicit');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
export function spawnOwnedProcess(executable, args, options) {
|
|
4
|
+
if (process.platform !== 'win32')
|
|
5
|
+
return spawn(executable, args, { ...options, detached: true, stdio: 'pipe' });
|
|
6
|
+
const helper = fileURLToPath(new URL('../../runtime/windows-process-tree.ps1', import.meta.url));
|
|
7
|
+
return spawn('powershell.exe', ['-NoProfile', '-NonInteractive', '-WindowStyle', 'Hidden', '-File', helper, '-Executable', executable, '-ArgumentsBase64', Buffer.from(JSON.stringify(args)).toString('base64'), '-ParentPid', String(process.pid)], { ...options, windowsHide: true, stdio: 'pipe' });
|
|
8
|
+
}
|
|
9
|
+
export async function stopOwnedProcess(child) {
|
|
10
|
+
if (!child.pid || child.exitCode !== null)
|
|
11
|
+
return;
|
|
12
|
+
if (process.platform !== 'win32') {
|
|
13
|
+
try {
|
|
14
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error.code !== 'ESRCH')
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
await new Promise((resolve, reject) => {
|
|
23
|
+
const killer = spawn('taskkill.exe', ['/PID', String(child.pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' });
|
|
24
|
+
killer.once('error', reject);
|
|
25
|
+
killer.once('close', () => resolve());
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=process-tree.js.map
|