@leavewhite9088/harness-bus 0.2.0 → 0.2.1
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/ARCHITECTURE.md +81 -81
- package/LICENSE +21 -21
- package/README.md +86 -86
- package/SETUP_FOR_AI.md +79 -79
- package/package.json +4 -2
- package/packages/agentd/agentd.config.json +3 -1
- package/packages/agentd/cli/commands.mjs +854 -810
- package/packages/agentd/cli/format.mjs +294 -238
- package/packages/agentd/cli/hbus.mjs +14 -14
- package/packages/agentd/cli/index.mjs +4 -4
- package/packages/agentd/cli/skill/SKILL.md +66 -61
- package/packages/agentd/cli/skill/references/custom.md +12 -0
- package/packages/agentd/cli/skill/references/playbooks.md +89 -86
- package/packages/agentd/cli/skill/references/routing.md +43 -35
- package/packages/agentd/cli/skill-install.mjs +157 -140
- package/packages/agentd/cli/update.mjs +221 -221
- package/packages/agentd/client/index.mjs +3 -3
- package/packages/agentd/contexts/executor.md +13 -12
- package/packages/agentd/contexts/templates/architect.md +12 -12
- package/packages/agentd/contexts/templates/coder.md +12 -12
- package/packages/agentd/contexts/templates/debugger.md +12 -12
- package/packages/agentd/contexts/templates/researcher.md +12 -12
- package/packages/agentd/contexts/templates/reviewer.md +12 -12
- package/packages/agentd/contexts/templates/tester.md +12 -12
- package/packages/agentd/core/base/data-dir.mjs +39 -39
- package/packages/agentd/core/base/index.mjs +5 -5
- package/packages/agentd/core/base/protocol.mjs +13 -13
- package/packages/agentd/core/env/config.mjs +52 -1
- package/packages/agentd/core/env/index.mjs +6 -1
- package/packages/agentd/core/env/install.mjs +82 -4
- package/packages/agentd/core/pi/index.mjs +1 -1
- package/packages/agentd/core/pi/rpc.mjs +206 -206
- package/packages/agentd/core/pool/acp/client.mjs +7 -9
- package/packages/agentd/core/pool/acp/process.mjs +27 -18
- package/packages/agentd/core/pool/acp/run-tracker.mjs +293 -293
- package/packages/agentd/core/pool/acp/sessions.mjs +465 -465
- package/packages/agentd/core/pool/acp/turn-runner.mjs +5 -3
- package/packages/agentd/core/pool/index.mjs +2 -2
- package/packages/agentd/core/pool/instances.mjs +3 -5
- package/packages/agentd/core/pool/probe.mjs +91 -85
- package/packages/agentd/core/pool/registry.mjs +45 -1
- package/packages/agentd/core/pool/support/compaction.mjs +2 -43
- package/packages/agentd/core/pool/support/index.mjs +1 -1
- package/packages/agentd/core/prompts/index.mjs +12 -12
- package/packages/agentd/core/prompts/rules.mjs +22 -22
- package/packages/agentd/core/prompts/templates.mjs +172 -172
- package/packages/agentd/core/providers/index.mjs +14 -14
- package/packages/agentd/core/providers/store.mjs +206 -206
- package/packages/agentd/core/records/cleanup.mjs +51 -51
- package/packages/agentd/core/records/index.mjs +8 -8
- package/packages/agentd/core/records/metrics.mjs +73 -73
- package/packages/agentd/core/records/recovery.mjs +39 -39
- package/packages/agentd/core/records/transcripts.mjs +122 -122
- package/packages/agentd/core/threads/index.mjs +18 -17
- package/packages/agentd/core/threads/manager.mjs +498 -476
- package/packages/agentd/core/threads/paths.mjs +78 -78
- package/packages/agentd/core/threads/store.mjs +146 -125
- package/packages/agentd/daemon/agentd.mjs +58 -58
- package/packages/agentd/daemon/events.mjs +126 -126
- package/packages/agentd/daemon/guard.mjs +127 -127
- package/packages/agentd/daemon/lifecycle.mjs +61 -61
- package/packages/agentd/daemon/ops/index.mjs +15 -15
- package/packages/agentd/daemon/ops/providers.mjs +46 -46
- package/packages/agentd/daemon/ops/run.mjs +413 -400
- package/packages/agentd/daemon/ops/system.mjs +76 -69
- package/packages/agentd/daemon/ops/threads.mjs +156 -153
- package/packages/agentd/daemon/server.mjs +130 -130
- package/packages/agentd/package.json +1 -1
- package/packages/agentd/pi-adapter/acp-adapter.mjs +501 -501
- package/packages/agentd/scripts/restart-daemon.mjs +74 -74
- package/packages/agentd/scripts/run-isolated.mjs +42 -42
- package/packages/agentd/scripts/run-unit.mjs +28 -28
- package/packages/backend/src/daemon.mjs +69 -69
- package/packages/backend/src/server.mjs +270 -270
- package/packages/drivers/{agy.mjs → agy/index.mjs} +2 -1
- package/packages/drivers/{claude.mjs → claude/index.mjs} +23 -1
- package/packages/drivers/{codex.mjs → codex/index.mjs} +2 -1
- package/packages/drivers/{dsh.mjs → dsh/index.mjs} +3 -2
- package/packages/drivers/grok/index.mjs +96 -0
- package/packages/drivers/index.mjs +25 -12
- package/packages/drivers/{kimi.mjs → kimi/index.mjs} +2 -1
- package/packages/drivers/{mcode.mjs → mcode/index.mjs} +2 -1
- package/packages/drivers/{opencode.mjs → opencode/index.mjs} +2 -1
- package/packages/drivers/{pi.mjs → pi/index.mjs} +3 -2
- package/packages/drivers/probes/acp.mjs +109 -109
- package/packages/drivers/probes/index.mjs +131 -129
- package/packages/drivers/probes/provider.mjs +222 -222
- package/packages/drivers/qoder/index.mjs +32 -0
- package/packages/drivers/{bin.mjs → shared/bin.mjs} +2 -0
- package/packages/drivers/shared/index.mjs +2 -0
- package/packages/preflight/bin/preflight.mjs +116 -116
- package/packages/preflight/src/index.mjs +5 -5
- package/packages/preflight/src/report.mjs +18 -1
- package/packages/web/dist/apple-touch-icon.png +0 -0
- package/packages/web/dist/assets/index-CT8dIwav.css +2 -0
- package/packages/web/dist/assets/index-CypTUMFB.js +79 -0
- package/packages/web/dist/favicon-32.png +0 -0
- package/packages/web/dist/favicon.svg +19 -15
- package/packages/web/dist/index.html +5 -5
- package/packages/web/dist/assets/index-B2kdkHNw.js +0 -79
- package/packages/web/dist/assets/index-DQTyjC4x.css +0 -2
- /package/packages/drivers/{dsh-sessions.mjs → dsh/sessions.mjs} +0 -0
- /package/packages/drivers/{pi-catalog.mjs → pi/catalog.mjs} +0 -0
- /package/packages/drivers/{lib.mjs → shared/lib.mjs} +0 -0
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import { connect, ENDPOINT_FILE } from '../client/index.mjs';
|
|
2
|
-
|
|
3
|
-
const USAGE = `Usage (works from the repo root or packages/agentd):
|
|
4
|
-
npm run restart-daemon
|
|
5
|
-
npm run restart-daemon -- --stop-only
|
|
6
|
-
npm run restart-daemon -- --help
|
|
7
|
-
|
|
8
|
-
Direct equivalents:
|
|
9
|
-
repo root: node packages/agentd/scripts/restart-daemon.mjs
|
|
10
|
-
packages/agentd: node scripts/restart-daemon.mjs
|
|
11
|
-
|
|
12
|
-
Exit codes: 0 = success, 1 = refused because tasks are running/waiting (nothing changed), 2 = did not stop or bad usage.`;
|
|
13
|
-
|
|
14
|
-
const args = process.argv.slice(2);
|
|
15
|
-
if (args.includes('--help') || args.includes('-h')) {
|
|
16
|
-
console.log(USAGE);
|
|
17
|
-
process.exit(0);
|
|
18
|
-
}
|
|
19
|
-
const unknown = args.filter((arg) => arg !== '--stop-only');
|
|
20
|
-
if (unknown.length) {
|
|
21
|
-
console.error(`unknown argument${unknown.length > 1 ? 's' : ''}: ${unknown.join(', ')}\n\n${USAGE}`);
|
|
22
|
-
process.exit(2);
|
|
23
|
-
}
|
|
24
|
-
const stopOnly = args.includes('--stop-only');
|
|
25
|
-
|
|
26
|
-
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
27
|
-
const alive = (pid) => {
|
|
28
|
-
try {
|
|
29
|
-
process.kill(pid, 0);
|
|
30
|
-
return true;
|
|
31
|
-
} catch {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
let c = null;
|
|
37
|
-
try {
|
|
38
|
-
c = await connect({ spawnOnDemand: false });
|
|
39
|
-
} catch {
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (c) {
|
|
43
|
-
const callerAgent = process.env.HARNESS_BUS_MANAGED_AGENT || undefined;
|
|
44
|
-
const { pid } = await c.call('hello');
|
|
45
|
-
try {
|
|
46
|
-
await c.call('daemon.shutdown', callerAgent ? { callerAgent } : {});
|
|
47
|
-
} catch (err) {
|
|
48
|
-
const action = stopOnly ? 'stopped' : 'restarted';
|
|
49
|
-
console.log(`not ${action}: ${err.message}; nothing was changed`);
|
|
50
|
-
c.close();
|
|
51
|
-
process.exit(1);
|
|
52
|
-
}
|
|
53
|
-
c.close();
|
|
54
|
-
const until = Date.now() + 30_000;
|
|
55
|
-
while (alive(pid) && Date.now() < until) await sleep(200);
|
|
56
|
-
if (alive(pid)) {
|
|
57
|
-
console.log(`the daemon (pid ${pid}) was asked to stop but is still running`);
|
|
58
|
-
process.exit(2);
|
|
59
|
-
}
|
|
60
|
-
console.log(`stopped the daemon (pid ${pid})`);
|
|
61
|
-
} else {
|
|
62
|
-
console.log('no daemon was running');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (stopOnly) {
|
|
66
|
-
console.log('not starting a new daemon (--stop-only)');
|
|
67
|
-
process.exit(0);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const fresh = await connect({ spawnOnDemand: true });
|
|
71
|
-
const hello = await fresh.call('hello');
|
|
72
|
-
console.log(`started a daemon (pid ${hello.pid}, ${hello.startedAt}); endpoint file: ${ENDPOINT_FILE}`);
|
|
73
|
-
fresh.close();
|
|
74
|
-
process.exit(0);
|
|
1
|
+
import { connect, ENDPOINT_FILE } from '../client/index.mjs';
|
|
2
|
+
|
|
3
|
+
const USAGE = `Usage (works from the repo root or packages/agentd):
|
|
4
|
+
npm run restart-daemon
|
|
5
|
+
npm run restart-daemon -- --stop-only
|
|
6
|
+
npm run restart-daemon -- --help
|
|
7
|
+
|
|
8
|
+
Direct equivalents:
|
|
9
|
+
repo root: node packages/agentd/scripts/restart-daemon.mjs
|
|
10
|
+
packages/agentd: node scripts/restart-daemon.mjs
|
|
11
|
+
|
|
12
|
+
Exit codes: 0 = success, 1 = refused because tasks are running/waiting (nothing changed), 2 = did not stop or bad usage.`;
|
|
13
|
+
|
|
14
|
+
const args = process.argv.slice(2);
|
|
15
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
16
|
+
console.log(USAGE);
|
|
17
|
+
process.exit(0);
|
|
18
|
+
}
|
|
19
|
+
const unknown = args.filter((arg) => arg !== '--stop-only');
|
|
20
|
+
if (unknown.length) {
|
|
21
|
+
console.error(`unknown argument${unknown.length > 1 ? 's' : ''}: ${unknown.join(', ')}\n\n${USAGE}`);
|
|
22
|
+
process.exit(2);
|
|
23
|
+
}
|
|
24
|
+
const stopOnly = args.includes('--stop-only');
|
|
25
|
+
|
|
26
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
27
|
+
const alive = (pid) => {
|
|
28
|
+
try {
|
|
29
|
+
process.kill(pid, 0);
|
|
30
|
+
return true;
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
let c = null;
|
|
37
|
+
try {
|
|
38
|
+
c = await connect({ spawnOnDemand: false });
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (c) {
|
|
43
|
+
const callerAgent = process.env.HARNESS_BUS_MANAGED_AGENT || undefined;
|
|
44
|
+
const { pid } = await c.call('hello');
|
|
45
|
+
try {
|
|
46
|
+
await c.call('daemon.shutdown', callerAgent ? { callerAgent } : {});
|
|
47
|
+
} catch (err) {
|
|
48
|
+
const action = stopOnly ? 'stopped' : 'restarted';
|
|
49
|
+
console.log(`not ${action}: ${err.message}; nothing was changed`);
|
|
50
|
+
c.close();
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
c.close();
|
|
54
|
+
const until = Date.now() + 30_000;
|
|
55
|
+
while (alive(pid) && Date.now() < until) await sleep(200);
|
|
56
|
+
if (alive(pid)) {
|
|
57
|
+
console.log(`the daemon (pid ${pid}) was asked to stop but is still running`);
|
|
58
|
+
process.exit(2);
|
|
59
|
+
}
|
|
60
|
+
console.log(`stopped the daemon (pid ${pid})`);
|
|
61
|
+
} else {
|
|
62
|
+
console.log('no daemon was running');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (stopOnly) {
|
|
66
|
+
console.log('not starting a new daemon (--stop-only)');
|
|
67
|
+
process.exit(0);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const fresh = await connect({ spawnOnDemand: true });
|
|
71
|
+
const hello = await fresh.call('hello');
|
|
72
|
+
console.log(`started a daemon (pid ${hello.pid}, ${hello.startedAt}); endpoint file: ${ENDPOINT_FILE}`);
|
|
73
|
+
fresh.close();
|
|
74
|
+
process.exit(0);
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { dirname, join } from 'node:path';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import { killTree } from '../core/base/index.mjs';
|
|
7
|
-
|
|
8
|
-
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
9
|
-
const root = mkdtempSync(join(tmpdir(), 'agentd-iso-'));
|
|
10
|
-
const dataDir = join(root, 'data');
|
|
11
|
-
const tmpDir = join(root, 'tmp');
|
|
12
|
-
mkdirSync(dataDir);
|
|
13
|
-
mkdirSync(tmpDir);
|
|
14
|
-
const tag = Date.now().toString(36);
|
|
15
|
-
const pipe = process.platform === 'win32' ? `\\\\.\\pipe\\agentd-iso-${tag}` : join(root, 'agentd.sock');
|
|
16
|
-
const env = { ...process.env, TEMP: tmpDir, TMP: tmpDir, TMPDIR: tmpDir, AGENTD_DATA_DIR: dataDir, AGENTD_PIPE: pipe, AGENTD_PORT: '', AGENTD_STOP_WAIT_MS: '5000' };
|
|
17
|
-
delete env.AGENTD_PORT;
|
|
18
|
-
const scripts = process.argv.slice(2).length ? process.argv.slice(2) : ['test:unit'];
|
|
19
|
-
console.log(`private daemon: data ${dataDir}, pipe ${pipe}`);
|
|
20
|
-
|
|
21
|
-
let code = 0;
|
|
22
|
-
for (const script of scripts) {
|
|
23
|
-
code = await new Promise((resolve) => {
|
|
24
|
-
const child = spawn(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['run', script], { cwd: ROOT, env, stdio: 'inherit', shell: process.platform === 'win32' });
|
|
25
|
-
child.on('close', (c) => resolve(c ?? 1));
|
|
26
|
-
});
|
|
27
|
-
if (code) break;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
const pid = Number(JSON.parse(readFileSync(join(dataDir, 'agentd.endpoint.json'), 'utf8')).pid);
|
|
32
|
-
if (pid > 0 && pid !== process.pid) {
|
|
33
|
-
killTree({ pid, kill: (sig) => process.kill(pid, sig) });
|
|
34
|
-
}
|
|
35
|
-
} catch {
|
|
36
|
-
}
|
|
37
|
-
await new Promise((r) => setTimeout(r, 800));
|
|
38
|
-
try {
|
|
39
|
-
rmSync(root, { recursive: true, force: true });
|
|
40
|
-
} catch {
|
|
41
|
-
}
|
|
42
|
-
process.exit(code);
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { killTree } from '../core/base/index.mjs';
|
|
7
|
+
|
|
8
|
+
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
9
|
+
const root = mkdtempSync(join(tmpdir(), 'agentd-iso-'));
|
|
10
|
+
const dataDir = join(root, 'data');
|
|
11
|
+
const tmpDir = join(root, 'tmp');
|
|
12
|
+
mkdirSync(dataDir);
|
|
13
|
+
mkdirSync(tmpDir);
|
|
14
|
+
const tag = Date.now().toString(36);
|
|
15
|
+
const pipe = process.platform === 'win32' ? `\\\\.\\pipe\\agentd-iso-${tag}` : join(root, 'agentd.sock');
|
|
16
|
+
const env = { ...process.env, TEMP: tmpDir, TMP: tmpDir, TMPDIR: tmpDir, AGENTD_DATA_DIR: dataDir, AGENTD_PIPE: pipe, AGENTD_PORT: '', AGENTD_STOP_WAIT_MS: '5000' };
|
|
17
|
+
delete env.AGENTD_PORT;
|
|
18
|
+
const scripts = process.argv.slice(2).length ? process.argv.slice(2) : ['test:unit'];
|
|
19
|
+
console.log(`private daemon: data ${dataDir}, pipe ${pipe}`);
|
|
20
|
+
|
|
21
|
+
let code = 0;
|
|
22
|
+
for (const script of scripts) {
|
|
23
|
+
code = await new Promise((resolve) => {
|
|
24
|
+
const child = spawn(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['run', script], { cwd: ROOT, env, stdio: 'inherit', shell: process.platform === 'win32' });
|
|
25
|
+
child.on('close', (c) => resolve(c ?? 1));
|
|
26
|
+
});
|
|
27
|
+
if (code) break;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const pid = Number(JSON.parse(readFileSync(join(dataDir, 'agentd.endpoint.json'), 'utf8')).pid);
|
|
32
|
+
if (pid > 0 && pid !== process.pid) {
|
|
33
|
+
killTree({ pid, kill: (sig) => process.kill(pid, sig) });
|
|
34
|
+
}
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
await new Promise((r) => setTimeout(r, 800));
|
|
38
|
+
try {
|
|
39
|
+
rmSync(root, { recursive: true, force: true });
|
|
40
|
+
} catch {
|
|
41
|
+
}
|
|
42
|
+
process.exit(code);
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import { readdirSync } from 'node:fs';
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
|
|
6
|
-
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
7
|
-
const UNIT_DIR = join(ROOT, 'test', 'unit');
|
|
8
|
-
const PRIORITY = ['layers-test.mjs', 'ops-test.mjs', 'security-audit-test.mjs'];
|
|
9
|
-
|
|
10
|
-
const all = readdirSync(UNIT_DIR)
|
|
11
|
-
.filter((f) => f.endsWith('-test.mjs'))
|
|
12
|
-
.sort();
|
|
13
|
-
const ordered = [
|
|
14
|
-
...PRIORITY.filter((f) => all.includes(f)),
|
|
15
|
-
...all.filter((f) => !PRIORITY.includes(f)),
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
let passed = 0;
|
|
19
|
-
for (const file of ordered) {
|
|
20
|
-
const r = spawnSync(process.execPath, [join(UNIT_DIR, file)], { cwd: ROOT, stdio: 'inherit' });
|
|
21
|
-
if (r.status !== 0) {
|
|
22
|
-
console.error(`\n=> ✗ UNIT SUITE FAILED at ${file} (${passed}/${ordered.length} passed)`);
|
|
23
|
-
process.exit(r.status ?? 1);
|
|
24
|
-
}
|
|
25
|
-
passed += 1;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
console.log(`\n=> ✓ ALL ${passed}/${ordered.length} UNIT SUITES PASSED`);
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { readdirSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
7
|
+
const UNIT_DIR = join(ROOT, 'test', 'unit');
|
|
8
|
+
const PRIORITY = ['layers-test.mjs', 'ops-test.mjs', 'security-audit-test.mjs'];
|
|
9
|
+
|
|
10
|
+
const all = readdirSync(UNIT_DIR)
|
|
11
|
+
.filter((f) => f.endsWith('-test.mjs'))
|
|
12
|
+
.sort();
|
|
13
|
+
const ordered = [
|
|
14
|
+
...PRIORITY.filter((f) => all.includes(f)),
|
|
15
|
+
...all.filter((f) => !PRIORITY.includes(f)),
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
let passed = 0;
|
|
19
|
+
for (const file of ordered) {
|
|
20
|
+
const r = spawnSync(process.execPath, [join(UNIT_DIR, file)], { cwd: ROOT, stdio: 'inherit' });
|
|
21
|
+
if (r.status !== 0) {
|
|
22
|
+
console.error(`\n=> ✗ UNIT SUITE FAILED at ${file} (${passed}/${ordered.length} passed)`);
|
|
23
|
+
process.exit(r.status ?? 1);
|
|
24
|
+
}
|
|
25
|
+
passed += 1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
console.log(`\n=> ✓ ALL ${passed}/${ordered.length} UNIT SUITES PASSED`);
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import { connect } from '../../agentd/client/index.mjs';
|
|
2
|
-
|
|
3
|
-
const LIVE_EVENTS = [
|
|
4
|
-
'threads.changed',
|
|
5
|
-
'queue.changed',
|
|
6
|
-
'progress',
|
|
7
|
-
'job.done',
|
|
8
|
-
'job.started',
|
|
9
|
-
'job.running',
|
|
10
|
-
'job.interrupted',
|
|
11
|
-
'agent.exit',
|
|
12
|
-
'agent.forced-stop',
|
|
13
|
-
'agent.recovered',
|
|
14
|
-
'agent.compacted',
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
let client = null;
|
|
18
|
-
let opening = null;
|
|
19
|
-
let reconnectTimer = null;
|
|
20
|
-
const listeners = new Set();
|
|
21
|
-
|
|
22
|
-
export function onLive(fn) {
|
|
23
|
-
listeners.add(fn);
|
|
24
|
-
return () => listeners.delete(fn);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function scheduleReconnect() {
|
|
28
|
-
if (reconnectTimer || listeners.size === 0) return;
|
|
29
|
-
reconnectTimer = setTimeout(() => {
|
|
30
|
-
reconnectTimer = null;
|
|
31
|
-
if (listeners.size === 0) return;
|
|
32
|
-
daemon().catch(() => scheduleReconnect());
|
|
33
|
-
}, 1500);
|
|
34
|
-
reconnectTimer.unref?.();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function open() {
|
|
38
|
-
const c = await connect();
|
|
39
|
-
for (const name of LIVE_EVENTS) {
|
|
40
|
-
c.on(name, (ev) => {
|
|
41
|
-
for (const fn of listeners) fn(name, ev);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
c.socket.once('close', () => {
|
|
45
|
-
if (client === c) client = null;
|
|
46
|
-
scheduleReconnect();
|
|
47
|
-
});
|
|
48
|
-
await c.call('subscribe', { jobId: '*' });
|
|
49
|
-
client = c;
|
|
50
|
-
return c;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function daemon() {
|
|
54
|
-
if (client && !client.closed) return client;
|
|
55
|
-
opening ??= open().finally(() => {
|
|
56
|
-
opening = null;
|
|
57
|
-
});
|
|
58
|
-
return opening;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export async function call(op, args = {}, opts) {
|
|
62
|
-
const c = await daemon();
|
|
63
|
-
return c.call(op, args, opts);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function close() {
|
|
67
|
-
client?.close();
|
|
68
|
-
client = null;
|
|
69
|
-
}
|
|
1
|
+
import { connect } from '../../agentd/client/index.mjs';
|
|
2
|
+
|
|
3
|
+
const LIVE_EVENTS = [
|
|
4
|
+
'threads.changed',
|
|
5
|
+
'queue.changed',
|
|
6
|
+
'progress',
|
|
7
|
+
'job.done',
|
|
8
|
+
'job.started',
|
|
9
|
+
'job.running',
|
|
10
|
+
'job.interrupted',
|
|
11
|
+
'agent.exit',
|
|
12
|
+
'agent.forced-stop',
|
|
13
|
+
'agent.recovered',
|
|
14
|
+
'agent.compacted',
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
let client = null;
|
|
18
|
+
let opening = null;
|
|
19
|
+
let reconnectTimer = null;
|
|
20
|
+
const listeners = new Set();
|
|
21
|
+
|
|
22
|
+
export function onLive(fn) {
|
|
23
|
+
listeners.add(fn);
|
|
24
|
+
return () => listeners.delete(fn);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function scheduleReconnect() {
|
|
28
|
+
if (reconnectTimer || listeners.size === 0) return;
|
|
29
|
+
reconnectTimer = setTimeout(() => {
|
|
30
|
+
reconnectTimer = null;
|
|
31
|
+
if (listeners.size === 0) return;
|
|
32
|
+
daemon().catch(() => scheduleReconnect());
|
|
33
|
+
}, 1500);
|
|
34
|
+
reconnectTimer.unref?.();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function open() {
|
|
38
|
+
const c = await connect();
|
|
39
|
+
for (const name of LIVE_EVENTS) {
|
|
40
|
+
c.on(name, (ev) => {
|
|
41
|
+
for (const fn of listeners) fn(name, ev);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
c.socket.once('close', () => {
|
|
45
|
+
if (client === c) client = null;
|
|
46
|
+
scheduleReconnect();
|
|
47
|
+
});
|
|
48
|
+
await c.call('subscribe', { jobId: '*' });
|
|
49
|
+
client = c;
|
|
50
|
+
return c;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function daemon() {
|
|
54
|
+
if (client && !client.closed) return client;
|
|
55
|
+
opening ??= open().finally(() => {
|
|
56
|
+
opening = null;
|
|
57
|
+
});
|
|
58
|
+
return opening;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function call(op, args = {}, opts) {
|
|
62
|
+
const c = await daemon();
|
|
63
|
+
return c.call(op, args, opts);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function close() {
|
|
67
|
+
client?.close();
|
|
68
|
+
client = null;
|
|
69
|
+
}
|