@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,69 +1,76 @@
|
|
|
1
|
-
import { AGENTS } from '../../core/env/index.mjs';
|
|
2
|
-
import { getAgent, pool, probeEffort, probeModels } from '../../core/pool/index.mjs';
|
|
3
|
-
import { getRole, listRoles, removeRole, saveRole } from '../../core/prompts/index.mjs';
|
|
4
|
-
import { computeMetrics, readAudits, readDaemonLog, readReceipts } from '../../core/records/index.mjs';
|
|
5
|
-
import { EPOCH, RING_MAX, eventsSince, subscribe, unsubscribe } from '../events.mjs';
|
|
6
|
-
|
|
7
|
-
export function systemOps(ctx) {
|
|
8
|
-
return {
|
|
9
|
-
hello: () => ({
|
|
10
|
-
protocol: ctx.protocol,
|
|
11
|
-
epoch: EPOCH,
|
|
12
|
-
pid: process.pid,
|
|
13
|
-
startedAt: ctx.startedAt,
|
|
14
|
-
threads: [...pool.keys()],
|
|
15
|
-
types: Object.keys(AGENTS),
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
'
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
|
|
1
|
+
import { AGENTS, cliAvailability, enrichAuthError } from '../../core/env/index.mjs';
|
|
2
|
+
import { getAgent, pool, probeEffort, probeModels } from '../../core/pool/index.mjs';
|
|
3
|
+
import { getRole, listRoles, removeRole, saveRole } from '../../core/prompts/index.mjs';
|
|
4
|
+
import { computeMetrics, readAudits, readDaemonLog, readReceipts } from '../../core/records/index.mjs';
|
|
5
|
+
import { EPOCH, RING_MAX, eventsSince, subscribe, unsubscribe } from '../events.mjs';
|
|
6
|
+
|
|
7
|
+
export function systemOps(ctx) {
|
|
8
|
+
return {
|
|
9
|
+
hello: () => ({
|
|
10
|
+
protocol: ctx.protocol,
|
|
11
|
+
epoch: EPOCH,
|
|
12
|
+
pid: process.pid,
|
|
13
|
+
startedAt: ctx.startedAt,
|
|
14
|
+
threads: [...pool.keys()],
|
|
15
|
+
types: Object.keys(AGENTS),
|
|
16
|
+
clis: cliAvailability(),
|
|
17
|
+
}),
|
|
18
|
+
|
|
19
|
+
'events.since': ({ afterId, limit } = {}) => eventsSince(afterId, Math.min(Number(limit) || 500, RING_MAX)),
|
|
20
|
+
|
|
21
|
+
receipts: ({ limit, workspace } = {}) => ({ receipts: readReceipts(Math.min(Number(limit) || 50, 500), workspace ?? null) }),
|
|
22
|
+
|
|
23
|
+
audits: ({ limit, workspace } = {}) => ({ audits: readAudits(Math.min(Number(limit) || 50, 500), workspace ?? null) }),
|
|
24
|
+
|
|
25
|
+
metrics: ({ windowSec } = {}) =>
|
|
26
|
+
computeMetrics({
|
|
27
|
+
windowSec,
|
|
28
|
+
queues: [...pool.values()].map((a) => ({ agent: a.name, inflight: a.inflight ?? 0, waiting: a.waitingJobs?.().length ?? 0 })),
|
|
29
|
+
}),
|
|
30
|
+
|
|
31
|
+
health: () => ({
|
|
32
|
+
threads: [...pool.keys()].map((name) => getAgent(name).status()),
|
|
33
|
+
}),
|
|
34
|
+
|
|
35
|
+
logs: ({ lines = 80 } = {}) => readDaemonLog(lines),
|
|
36
|
+
|
|
37
|
+
'cli.models': ({ type, refresh = false }) =>
|
|
38
|
+
probeModels(type, { refresh }).catch((err) => {
|
|
39
|
+
throw enrichAuthError(type, err);
|
|
40
|
+
}),
|
|
41
|
+
|
|
42
|
+
'cli.effort': ({ type, model, refresh = false, provider } = {}) =>
|
|
43
|
+
probeEffort(type, model, { refresh, provider }).catch((err) => {
|
|
44
|
+
throw enrichAuthError(type, err);
|
|
45
|
+
}),
|
|
46
|
+
|
|
47
|
+
'role.list': ({ cwd = null } = {}) => ({ roles: listRoles({ cwd }) }),
|
|
48
|
+
|
|
49
|
+
'role.get': ({ id, cwd = null }) => {
|
|
50
|
+
const role = getRole(id, { cwd });
|
|
51
|
+
if (!role) throw new Error(`unknown role "${id}"`);
|
|
52
|
+
return role;
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
'role.save': (spec) => saveRole(spec),
|
|
56
|
+
|
|
57
|
+
'role.remove': ({ id }) => removeRole(id),
|
|
58
|
+
|
|
59
|
+
subscribe: ({ jobId }, sock) => {
|
|
60
|
+
if (jobId) subscribe(sock, jobId);
|
|
61
|
+
return { subscribed: jobId ?? null };
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
unsubscribe: ({ jobId }, sock) => {
|
|
65
|
+
if (jobId) unsubscribe(sock, jobId);
|
|
66
|
+
return { subscribed: null };
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
'daemon.shutdown': () => {
|
|
70
|
+
const busy = [...pool.values()].filter((a) => a.busy || a.inflight > 0).map((a) => a.name);
|
|
71
|
+
if (busy.length) throw new Error(`not stopping: still working on ${busy.join(', ')}`);
|
|
72
|
+
setTimeout(() => void ctx.shutdown(0), 200);
|
|
73
|
+
return { stopping: true, pid: process.pid };
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -1,153 +1,156 @@
|
|
|
1
|
-
import { AGENTS } from '../../core/env/index.mjs';
|
|
2
|
-
import { aliveCount, getAgent, maxProcesses, pool } from '../../core/pool/index.mjs';
|
|
3
|
-
import { readTranscript } from '../../core/records/index.mjs';
|
|
4
|
-
import * as threads from '../../core/threads/index.mjs';
|
|
5
|
-
import { allocEvent, publish } from '../events.mjs';
|
|
6
|
-
|
|
7
|
-
const keyArg = (args) => args?.thread ?? args?.agent;
|
|
8
|
-
|
|
9
|
-
function resolveKey(args) {
|
|
10
|
-
const direct = keyArg(args);
|
|
11
|
-
if (direct) return direct;
|
|
12
|
-
if (args?.cwd && args?.topic) {
|
|
13
|
-
const found = threads.findThread({ cwd: args.cwd, topic: args.topic });
|
|
14
|
-
if (found) return found.key;
|
|
15
|
-
}
|
|
16
|
-
throw new Error('thread key (or cwd + topic) is required');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function threadOps(ctx) {
|
|
20
|
-
return {
|
|
21
|
-
'thread.list': ({ cwd, onlyBusy } = {}) => {
|
|
22
|
-
const workspaces = threads.listWorkspaces({ cwd });
|
|
23
|
-
const flat = workspaces.flatMap((w) => w.threads);
|
|
24
|
-
const filtered = onlyBusy ? flat.filter((t) => t.busy || t.waiting > 0) : flat;
|
|
25
|
-
return {
|
|
26
|
-
workspaces: onlyBusy ? workspaces.map((w) => ({ ...w, threads: w.threads.filter((t) => t.busy || t.waiting > 0) })).filter((w) => w.threads.length > 0) : workspaces,
|
|
27
|
-
threads: filtered,
|
|
28
|
-
types: Object.keys(AGENTS),
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
a
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
a.useSession(args.sessionId, args.cwd)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
1
|
+
import { AGENTS, cliAvailability } from '../../core/env/index.mjs';
|
|
2
|
+
import { aliveCount, getAgent, maxProcesses, pool } from '../../core/pool/index.mjs';
|
|
3
|
+
import { readTranscript } from '../../core/records/index.mjs';
|
|
4
|
+
import * as threads from '../../core/threads/index.mjs';
|
|
5
|
+
import { allocEvent, publish } from '../events.mjs';
|
|
6
|
+
|
|
7
|
+
const keyArg = (args) => args?.thread ?? args?.agent;
|
|
8
|
+
|
|
9
|
+
function resolveKey(args) {
|
|
10
|
+
const direct = keyArg(args);
|
|
11
|
+
if (direct) return direct;
|
|
12
|
+
if (args?.cwd && args?.topic) {
|
|
13
|
+
const found = threads.findThread({ cwd: args.cwd, topic: args.topic });
|
|
14
|
+
if (found) return found.key;
|
|
15
|
+
}
|
|
16
|
+
throw new Error('thread key (or cwd + topic) is required');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function threadOps(ctx) {
|
|
20
|
+
return {
|
|
21
|
+
'thread.list': ({ cwd, onlyBusy } = {}) => {
|
|
22
|
+
const workspaces = threads.listWorkspaces({ cwd });
|
|
23
|
+
const flat = workspaces.flatMap((w) => w.threads);
|
|
24
|
+
const filtered = onlyBusy ? flat.filter((t) => t.busy || t.waiting > 0) : flat;
|
|
25
|
+
return {
|
|
26
|
+
workspaces: onlyBusy ? workspaces.map((w) => ({ ...w, threads: w.threads.filter((t) => t.busy || t.waiting > 0) })).filter((w) => w.threads.length > 0) : workspaces,
|
|
27
|
+
threads: filtered,
|
|
28
|
+
types: Object.keys(AGENTS),
|
|
29
|
+
clis: cliAvailability(),
|
|
30
|
+
limits: {
|
|
31
|
+
alive: aliveCount(),
|
|
32
|
+
maxProcesses: maxProcesses(),
|
|
33
|
+
idleMinutes: Math.round((ctx?.idleInstanceMs ?? 900_000) / 60_000),
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
'thread.get': (args) => threads.getThreadView(resolveKey(args)),
|
|
39
|
+
|
|
40
|
+
'thread.resolve': async (args) => {
|
|
41
|
+
const isManaged = Boolean(args?.callerAgent) || args?.caller === 'managed';
|
|
42
|
+
const res = await threads.resolveThread({ ...args, allowMutateExisting: !isManaged });
|
|
43
|
+
publish(allocEvent('threads.changed', { workspaceId: res.thread.workspaceId, thread: res.key }));
|
|
44
|
+
return res;
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
'thread.update': async (args) => {
|
|
48
|
+
const key = resolveKey(args);
|
|
49
|
+
const updated = await threads.updateThread(key, args);
|
|
50
|
+
publish(allocEvent('threads.changed', { workspaceId: updated.workspaceId, thread: key }));
|
|
51
|
+
return updated;
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
'thread.remove': async (args) => {
|
|
55
|
+
const key = resolveKey(args);
|
|
56
|
+
const res = await threads.removeThread(key);
|
|
57
|
+
publish(allocEvent('threads.changed', { thread: key, removed: true }));
|
|
58
|
+
return res;
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
'thread.start': async (args) => {
|
|
62
|
+
const a = getAgent(resolveKey(args));
|
|
63
|
+
await a.serialized(() => a.ensureReady());
|
|
64
|
+
return a.status();
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
'thread.probe': (args) => getAgent(resolveKey(args)).probe({ timeoutMs: args?.timeoutMs ?? 45_000 }),
|
|
68
|
+
|
|
69
|
+
'thread.recover': (args) => {
|
|
70
|
+
const a = getAgent(resolveKey(args));
|
|
71
|
+
a.recover();
|
|
72
|
+
publish(allocEvent('agent.recovered', { agent: a.name, thread: a.name }));
|
|
73
|
+
return a.status();
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
'thread.renameSession': (args) => getAgent(resolveKey(args)).renameSession(args.sessionId, args.label),
|
|
77
|
+
|
|
78
|
+
'thread.sessions': async (args) => getAgent(resolveKey(args)).listSessions(),
|
|
79
|
+
|
|
80
|
+
'thread.use': async (args) => {
|
|
81
|
+
const a = getAgent(resolveKey(args));
|
|
82
|
+
if (!a.inUse) return a.useSession(args.sessionId, args.cwd);
|
|
83
|
+
a.useSession(args.sessionId, args.cwd).catch((err) => process.stderr.write(`[${a.name}] queued switch to ${args.sessionId} failed: ${err.message}\n`));
|
|
84
|
+
return { thread: a.name, sessionId: args.sessionId, queued: true };
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
'thread.new': async (args) => {
|
|
88
|
+
const a = getAgent(resolveKey(args));
|
|
89
|
+
const make = async () => {
|
|
90
|
+
const sessionId = await a.newSession(args.cwd);
|
|
91
|
+
if (args.label) a.renameSession(sessionId, args.label);
|
|
92
|
+
const found = threads.findThreadByKey(a.name);
|
|
93
|
+
publish(allocEvent('threads.changed', { workspaceId: found?.ws?.id ?? a.project, thread: a.name, sessionId }));
|
|
94
|
+
return sessionId;
|
|
95
|
+
};
|
|
96
|
+
if (!a.inUse) return { thread: a.name, sessionId: await make(), cwd: a.cwd, label: args.label ?? null };
|
|
97
|
+
make().catch((err) => process.stderr.write(`[${a.name}] queued new session failed: ${err.message}\n`));
|
|
98
|
+
return { thread: a.name, queued: true, label: args.label ?? null };
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
'thread.deleteSession': (args) => getAgent(resolveKey(args)).deleteSession(args.sessionId),
|
|
102
|
+
|
|
103
|
+
'thread.models': async (args) => getAgent(resolveKey(args)).describeModels(args.sessionId),
|
|
104
|
+
|
|
105
|
+
'thread.setModel': async (args) => {
|
|
106
|
+
const a = getAgent(resolveKey(args));
|
|
107
|
+
return a.setConfigOption(args.configId || 'model', args.value, args.sessionId);
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
'thread.transcript': (args) => {
|
|
111
|
+
const a = getAgent(resolveKey(args));
|
|
112
|
+
const sid = args.sessionId || a.sessionId || a.preferSession;
|
|
113
|
+
if (!sid) throw new Error(`${a.name} has no active session; pass sessionId`);
|
|
114
|
+
return readTranscript(a.name, sid, { afterSeq: args.afterSeq, limit: args.limit, tail: args.tail });
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
'thread.cancel': (args) => {
|
|
118
|
+
if (!keyArg(args) && args?.jobId) {
|
|
119
|
+
const jid = String(args.jobId);
|
|
120
|
+
const owner = [...pool.values()].find(
|
|
121
|
+
(a) => a.run?.jobId === jid || a.waitingJobs().some((w) => w.jobId === jid) || a.jobs.has(jid),
|
|
122
|
+
);
|
|
123
|
+
if (!owner) throw new Error(`unknown job "${jid}"`);
|
|
124
|
+
if (args?.callerAgent) {
|
|
125
|
+
const callerWs = threads.findThreadByKey(args.callerAgent)?.ws;
|
|
126
|
+
const ownerWs = threads.findThreadByKey(owner.name)?.ws;
|
|
127
|
+
if (!callerWs || !ownerWs || callerWs.id !== ownerWs.id) {
|
|
128
|
+
throw new Error(`managed child agent "agent:${args.callerAgent}" cannot cancel job outside its workspace`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return owner.cancel(jid);
|
|
132
|
+
}
|
|
133
|
+
const key = resolveKey(args);
|
|
134
|
+
return getAgent(key).cancel(args.jobId);
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
'thread.queue': (args) => {
|
|
138
|
+
const a = getAgent(resolveKey(args));
|
|
139
|
+
return { thread: a.name, running: a.run?.jobId ?? null, waiting: a.waitingJobs() };
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
'thread.queue.clear': (args) => {
|
|
143
|
+
const a = getAgent(resolveKey(args));
|
|
144
|
+
const removed = a.clearQueue();
|
|
145
|
+
if (removed?.cleared > 0) publish(allocEvent('queue.changed', { thread: a.name, agent: a.name, waiting: a.waitingJobs() }));
|
|
146
|
+
return { thread: a.name, removed };
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
'thread.promote': (args) => {
|
|
150
|
+
const a = getAgent(resolveKey(args));
|
|
151
|
+
const ok = a.promote(args.jobId);
|
|
152
|
+
if (ok?.promoted) publish(allocEvent('queue.changed', { thread: a.name, agent: a.name, waiting: a.waitingJobs() }));
|
|
153
|
+
return { thread: a.name, jobId: args.jobId, moved: Boolean(ok?.promoted), detail: ok, waiting: a.waitingJobs() };
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|