tr-plugin-meta-harness 0.3.0 → 0.5.27
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/DESIGN.md +86 -0
- package/README.md +257 -11
- package/capability/BRICK.md +1 -1
- package/capability/index.mjs +154 -13
- package/cli.mjs +426 -41
- package/package.json +15 -3
- package/plugin.json +1457 -119
- package/skills/meta-harness/SKILL.md +63 -25
- package/src/adoption.mjs +102 -0
- package/src/agent-user.mjs +194 -0
- package/src/alerts.mjs +220 -14
- package/src/cascade.mjs +185 -0
- package/src/chat.mjs +80 -0
- package/src/codex-models.mjs +54 -0
- package/src/compat-harness.mjs +117 -0
- package/src/control.mjs +145 -0
- package/src/coordinator.mjs +267 -358
- package/src/dispatch-request.mjs +76 -0
- package/src/dispatch.mjs +119 -0
- package/src/documentation-authority.mjs +57 -0
- package/src/documentation.mjs +120 -32
- package/src/executor.mjs +101 -22
- package/src/gate-adapters/agy.mjs +155 -0
- package/src/gate-adapters/claude.mjs +303 -0
- package/src/gate-adapters/cline.mjs +111 -0
- package/src/gate-adapters/codex.mjs +164 -0
- package/src/gate-adapters/cursor.mjs +164 -0
- package/src/gate-adapters/devin.mjs +116 -0
- package/src/gate-adapters/dsh.mjs +284 -0
- package/src/gate-adapters/grok.mjs +112 -0
- package/src/gate-adapters/hermes.mjs +217 -0
- package/src/gate-adapters/hook-files.mjs +156 -0
- package/src/gate-adapters/index.mjs +131 -0
- package/src/gate-adapters/openclaw-plugin/gate-client.js +205 -0
- package/src/gate-adapters/openclaw-plugin/index.js +25 -0
- package/src/gate-adapters/openclaw-plugin/openclaw.plugin.json +9 -0
- package/src/gate-adapters/openclaw-plugin/package.json +15 -0
- package/src/gate-adapters/openclaw.mjs +288 -0
- package/src/gate-adapters/pi.mjs +146 -0
- package/src/gate.mjs +18 -0
- package/src/harness-updates.mjs +170 -0
- package/src/included-usage.mjs +344 -0
- package/src/jobs.mjs +135 -0
- package/src/json-reply.mjs +22 -0
- package/src/learner.mjs +97 -67
- package/src/maintenance.mjs +18 -0
- package/src/mcp-server.mjs +228 -0
- package/src/model-catalog.mjs +195 -0
- package/src/model-selection.mjs +67 -0
- package/src/paths.mjs +23 -0
- package/src/pool.mjs +69 -0
- package/src/process-manager.mjs +246 -0
- package/src/process-worker.mjs +18 -0
- package/src/reasoning.mjs +231 -0
- package/src/remote-operation.mjs +76 -0
- package/src/review.mjs +241 -0
- package/src/reviews.mjs +25 -0
- package/src/router-benchmark-corpus.mjs +16 -0
- package/src/router-benchmark.mjs +208 -0
- package/src/router.mjs +265 -346
- package/src/runtime.mjs +30 -8
- package/src/session/claude.mjs +358 -0
- package/src/session/codex.mjs +501 -0
- package/src/session/result.mjs +90 -0
- package/src/session/resume.mjs +393 -0
- package/src/session/run.mjs +258 -0
- package/src/session-jobs.mjs +77 -0
- package/src/setup.mjs +6 -3
- package/src/ssss-store.mjs +20 -0
- package/src/telemetry.mjs +267 -0
- package/src/termination.mjs +28 -0
- package/src/threads.mjs +150 -0
- package/src/usage-queue.mjs +137 -0
- package/src/verify-ssss.mjs +102 -0
- package/src/worker.mjs +955 -84
- package/src/worktree.mjs +244 -0
- package/ui/chunks/adapter-docs-freshness.md +16 -0
- package/ui/chunks/chat-handoff.md +26 -0
- package/ui/chunks/fleet-maintenance.md +21 -0
- package/ui/chunks/harness-inventory.md +21 -0
- package/ui/chunks/included-access.md +18 -0
- package/ui/chunks/included-usage-verification.md +15 -0
- package/ui/chunks/independent-review.md +17 -0
- package/ui/chunks/managed-execution.md +20 -0
- package/ui/chunks/official-documentation.md +18 -0
- package/ui/chunks/quota-recovery.md +21 -0
- package/ui/chunks/review-routing-decision.md +16 -0
- package/ui/chunks/route-work.md +18 -0
- package/ui/chunks/routing-evidence.md +18 -0
- package/ui/chunks/run-ledger.md +18 -0
- package/ui/chunks/session-controls.md +16 -0
- package/ui/home.js +198 -0
- package/ui/DESIGN.md +0 -32
- package/ui/card.js +0 -845
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/** Compatibility interfaces for native hosts. All execution uses the plugin's common boundary. */
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { getActiveAdapters, findBinary, inspectAgents, agentEnvironment } from './worker.mjs';
|
|
5
|
+
import { getInstalledVersion, getLatestVersion } from './tracker.mjs';
|
|
6
|
+
|
|
7
|
+
export const HARNESS_SPECS = Object.fromEntries(getActiveAdapters().map(adapter => [adapter.id, {
|
|
8
|
+
...adapter, defaultFlags: adapter.args, execType: adapter.input === 'stdin' ? 'pipe_stdin' : 'flag_last',
|
|
9
|
+
enforcement: 'advisory', enforcementEvidence: 'Use the measured preflight adapter report for enforcement evidence',
|
|
10
|
+
}]));
|
|
11
|
+
|
|
12
|
+
export function normalizeToolSelection(tools) {
|
|
13
|
+
if (tools === undefined || tools === null) return null;
|
|
14
|
+
const values = (Array.isArray(tools) ? tools : String(tools).split(',')).map(value => String(value).trim()).filter(Boolean);
|
|
15
|
+
if (!values.length || (values.length === 1 && values[0] === 'none')) return '';
|
|
16
|
+
if (values.length === 1 && ['all', 'default'].includes(values[0])) return null;
|
|
17
|
+
return values.join(',');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function validateHarnessOptions(id, options = {}) {
|
|
21
|
+
const adapter = getActiveAdapters().find(item => item.id === id);
|
|
22
|
+
if (!adapter) throw new Error(`Unknown harness ID "${id}"`);
|
|
23
|
+
if ((normalizeToolSelection(options.tools) !== null || options.settingSources !== undefined) && id !== 'claude') {
|
|
24
|
+
throw new Error(`Harness "${adapter.name}" does not support choosing its tool set or --setting-sources`);
|
|
25
|
+
}
|
|
26
|
+
if (options.settingSources !== undefined && (typeof options.settingSources !== 'string' || !/^(user|project|local)(,(user|project|local))*$/.test(options.settingSources))) throw new Error('Invalid --setting-sources');
|
|
27
|
+
if (options.allowUnknownAuth !== undefined && typeof options.allowUnknownAuth !== 'boolean') throw new Error('allowUnknownAuth must be an explicit boolean');
|
|
28
|
+
return adapter;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Legacy inspection helper only; execution flags are built by worker.mjs. */
|
|
32
|
+
export function buildHarnessArgs(spec, options = {}) {
|
|
33
|
+
const adapter = validateHarnessOptions(spec.id, options);
|
|
34
|
+
const args = [...adapter.args], extra = [];
|
|
35
|
+
const tools = normalizeToolSelection(options.tools);
|
|
36
|
+
if (tools !== null) extra.push('--tools', tools);
|
|
37
|
+
if (options.settingSources !== undefined) extra.push('--setting-sources', options.settingSources);
|
|
38
|
+
const promptFlag = args.at(-1) === '-p' ? args.pop() : null;
|
|
39
|
+
return [...args, ...extra, ...(promptFlag ? [promptFlag] : [])];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const shellQuote = value => "'" + String(value).replaceAll("'", "'\\''") + "'";
|
|
43
|
+
|
|
44
|
+
export function detectHarnesses() {
|
|
45
|
+
return getActiveAdapters().map(adapter => {
|
|
46
|
+
const binaryPath = findBinary(adapter.binary);
|
|
47
|
+
return { id: adapter.id, name: adapter.name, available: Boolean(binaryPath), binaryPath, description: adapter.docs, execType: adapter.input };
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function detectHarnessesWithAuth(options = {}) {
|
|
52
|
+
const result = await (options.inspect || inspectAgents)(options);
|
|
53
|
+
return result.agents.map(agent => ({ ...agent, available: agent.installed, authed: agent.authenticated === true && !agent.blockedBy, authRoute: agent.authenticated === 'unknown' ? 'unknown' : agent.authenticated ? 'measured-login' : 'needs-auth' }));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Kept for callers preparing environments; only an adapter's declared credentials may be resolved. */
|
|
57
|
+
export async function resolveHarnessEnv(spec, baseEnv = process.env, { readSecret } = {}) {
|
|
58
|
+
const adapter = validateHarnessOptions(spec.id);
|
|
59
|
+
const env = agentEnvironment(baseEnv);
|
|
60
|
+
if (!Object.keys(adapter.credentials || {}).length) return env;
|
|
61
|
+
if (!readSecret) {
|
|
62
|
+
const { runProcess } = await import('./worker.mjs');
|
|
63
|
+
const binary = findBinary(baseEnv.TOTAL_RECALL_BIN || 'total-recall', baseEnv);
|
|
64
|
+
if (!binary) throw new Error('Total Recall auth owner is unavailable');
|
|
65
|
+
readSecret = async key => {
|
|
66
|
+
const result = await runProcess(binary, ['auth', 'secret', 'get', key], { env: agentEnvironment(baseEnv) });
|
|
67
|
+
return result.exitCode === 0 ? result.stdout.trim() : null;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
for (const [name, keys] of Object.entries(adapter.credentials)) {
|
|
71
|
+
for (const key of keys) { const value = await readSecret(key); if (value) { env[name] = value; break; } }
|
|
72
|
+
if (!env[name]) throw new Error(`Configure ${name} through auth before dispatch`);
|
|
73
|
+
}
|
|
74
|
+
return env;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function dispatchTask(id, prompt, options = {}, dependencies = {}) {
|
|
78
|
+
validateHarnessOptions(id, options);
|
|
79
|
+
const remote = options.node && options.node !== 'local';
|
|
80
|
+
if (remote && (typeof options.cwd !== 'string' || (!path.posix.isAbsolute(options.cwd) && !path.win32.isAbsolute(options.cwd)))) throw new Error('Choose an explicit absolute workspace on the remote node');
|
|
81
|
+
const { dispatchWithReceipt } = await import('./dispatch.mjs');
|
|
82
|
+
const result = await (dependencies.dispatch || dispatchWithReceipt)({
|
|
83
|
+
agent: id, cwd: remote ? options.cwd : path.resolve(options.cwd || process.cwd()), prompt,
|
|
84
|
+
node: options.node || 'local', permissions: { read: true, write: options.write === true },
|
|
85
|
+
allowUnknownAuth: options.allowUnknownAuth === true, timeoutMs: options.timeoutMs,
|
|
86
|
+
tools: options.tools, settingSources: options.settingSources, model: options.model,
|
|
87
|
+
// Each read-only reasoning call owns a fresh one-turn budget. The parent
|
|
88
|
+
// CLI can itself be running inside a managed job.
|
|
89
|
+
...(options.internalReasoning === true ? { internalReasoning: true, jobId: `session-${randomUUID()}` } : {}),
|
|
90
|
+
...(options.includedPlanOnly === true ? { includedPlanOnly: true } : {}),
|
|
91
|
+
...(options.maxTurns !== undefined ? { maxTurns: options.maxTurns } : {}),
|
|
92
|
+
...(options.maxTokens !== undefined ? { maxTokens: options.maxTokens } : {}),
|
|
93
|
+
}, { node: options.node || 'local', role: options.role || 'Dispatch' });
|
|
94
|
+
return { ...result, harnessId: id, harnessName: HARNESS_SPECS[id]?.name || id, success: result.ok === true };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function runCouncil(prompt, ids, options = {}) {
|
|
98
|
+
const { coordinateTask } = await import('./coordinator.mjs');
|
|
99
|
+
return coordinateTask(prompt, { ...options, mode: 'council', execute: true, ...(ids ? { availableHarnesses: ids } : {}) });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const getInstalledHarnessVersion = id => getInstalledVersion(id) || 'unknown';
|
|
103
|
+
export const getLatestHarnessVersion = (id, installed) => getLatestVersion(id, installed);
|
|
104
|
+
|
|
105
|
+
export async function queryHarnessUsage(options = {}) {
|
|
106
|
+
const { inspectQuotas } = await import('./router.mjs');
|
|
107
|
+
const report = await (options.inspectQuotas || inspectQuotas)(options);
|
|
108
|
+
if (!report.ok) throw new Error(report.error || 'Harness usage is unavailable');
|
|
109
|
+
const remaining = value => typeof value === 'number' ? `${Math.max(0, 100 - value)}%` : '—';
|
|
110
|
+
return Object.entries(report.quotas || {}).filter(([id]) => !['system', 'metered'].includes(id)).map(([id, quota]) => ({
|
|
111
|
+
id, name: HARNESS_SPECS[id]?.name || id, available: quota.installed === true,
|
|
112
|
+
authed: quota.status === 'ready', authRoute: quota.status, status: quota.status,
|
|
113
|
+
version: quota.version || 'unknown', latestVersion: quota.latestVersion || null, isCurrent: quota.latestVersion ? quota.version === quota.latestVersion : null,
|
|
114
|
+
rolling5hRemainingPct: remaining(quota.rolling5hUsedPercent), weeklyRemainingPct: remaining(quota.weeklyUsedPercent),
|
|
115
|
+
quotaRemaining: quota.quotaNote || 'No usage source', enforcement: 'advisory', enforcementEvidence: null,
|
|
116
|
+
}));
|
|
117
|
+
}
|
package/src/control.mjs
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/** Job commands and events. The inbox is append-only; ack events are its cursor. */
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { execFile } from 'node:child_process';
|
|
6
|
+
import { promisify } from 'node:util';
|
|
7
|
+
import { configDir } from './paths.mjs';
|
|
8
|
+
import { resolveJob } from './jobs.mjs';
|
|
9
|
+
|
|
10
|
+
const execute = promisify(execFile);
|
|
11
|
+
export function jobPaths(job) {
|
|
12
|
+
const id = typeof job === 'string' ? job : job?.id || job?.job;
|
|
13
|
+
if (typeof id !== 'string' || !/^[a-z0-9-]+$/.test(id)) throw new Error('Invalid job ID.');
|
|
14
|
+
const base = path.join(configDir(), 'jobs', id);
|
|
15
|
+
return { id, inbox: `${base}.inbox.jsonl`, events: `${base}.events.jsonl` };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function readLines(file) {
|
|
19
|
+
let data;
|
|
20
|
+
try { data = fs.readFileSync(file, 'utf8'); }
|
|
21
|
+
catch (error) { if (error.code === 'ENOENT') return []; throw error; }
|
|
22
|
+
// An append from another process can still be incomplete.
|
|
23
|
+
return data.split('\n').slice(0, -1).filter(Boolean).map(line => JSON.parse(line));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function appendEvent(job, event) {
|
|
27
|
+
const { events } = jobPaths(job);
|
|
28
|
+
fs.mkdirSync(path.dirname(events), { recursive: true, mode: 0o700 });
|
|
29
|
+
const entry = { ...event, t: new Date().toISOString() };
|
|
30
|
+
fs.appendFileSync(events, JSON.stringify(entry) + '\n', { mode: 0o600 });
|
|
31
|
+
return entry;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Read all requests, including requests older than watch's --tail. */
|
|
35
|
+
export function waitingRequests(job) {
|
|
36
|
+
const file = typeof job === 'string' && job.endsWith('.events.jsonl') ? job : jobPaths(job).events;
|
|
37
|
+
const waiting = new Map();
|
|
38
|
+
for (const event of readLines(file)) {
|
|
39
|
+
if (['question', 'approval'].includes(event.kind) && event.requestId) waiting.set(event.requestId, event);
|
|
40
|
+
if (event.kind === 'ack' && event.requestId && event.ok !== false) waiting.delete(event.requestId);
|
|
41
|
+
}
|
|
42
|
+
return [...waiting.values()];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function normalizeCommand(command) {
|
|
46
|
+
if (!command || typeof command !== 'object' || Array.isArray(command)) throw new Error('A job command is required.');
|
|
47
|
+
const type = command.type || command.command || command.kind;
|
|
48
|
+
if (!['reply', 'approve', 'interrupt', 'goal', 'fork'].includes(type)) throw new Error('Unsupported job command.');
|
|
49
|
+
if (['reply', 'goal'].includes(type) && (typeof command.text !== 'string' || !command.text.trim())) throw new Error(`${type} requires text.`);
|
|
50
|
+
if (type === 'approve' && (typeof command.requestId !== 'string' || !command.requestId || !['allow', 'deny'].includes(command.value))) {
|
|
51
|
+
throw new Error('approve requires a request ID and allow or deny.');
|
|
52
|
+
}
|
|
53
|
+
if (command.requestId !== undefined && (typeof command.requestId !== 'string' || !command.requestId)) throw new Error('Invalid request ID.');
|
|
54
|
+
return { ...command, type, command: type, id: command.id || randomUUID(), t: new Date().toISOString() };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const quote = value => `'${String(value).replaceAll("'", "'\\''")}'`;
|
|
58
|
+
|
|
59
|
+
/** Resolve prefixes through the same owner as cancel. Remote delivery never writes a local inbox. */
|
|
60
|
+
export async function appendCommand(target, command, { local = false, execFileFn = execute } = {}) {
|
|
61
|
+
const job = resolveJob(typeof target === 'string' ? target : target?.id || target?.job);
|
|
62
|
+
if (job.result) throw new Error(`Job ${job.id} has finished.`);
|
|
63
|
+
const entry = normalizeCommand(command);
|
|
64
|
+
const node = job.record?.node;
|
|
65
|
+
if (!local && node && node !== 'local') {
|
|
66
|
+
if (typeof node !== 'string' || node.startsWith('-') || /[\0\r\n]/.test(node)) throw new Error('Invalid job node.');
|
|
67
|
+
const args = [entry.type, job.record.remoteJob || job.id];
|
|
68
|
+
if (entry.type === 'approve') args.push(entry.requestId, entry.value);
|
|
69
|
+
else if (!['interrupt', 'fork'].includes(entry.type)) args.push(entry.text);
|
|
70
|
+
if (entry.type === 'fork' && entry.atTurn) args.push('--at', entry.atTurn);
|
|
71
|
+
args.push('--local-delivery', '--json');
|
|
72
|
+
const remote = `total-recall meta-harness ${args.map(quote).join(' ')}`;
|
|
73
|
+
const result = await execFileFn(process.env.TOTAL_RECALL_BIN || 'total-recall', ['mesh', 'exec', node, remote],
|
|
74
|
+
{ encoding: 'utf8', timeout: 60_000, maxBuffer: 1024 * 1024 });
|
|
75
|
+
if (result.exitCode && result.exitCode !== 0) throw new Error(result.stderr || 'Remote command failed.');
|
|
76
|
+
// mesh exec may wrap the remote result. Transport failures must not look like delivery.
|
|
77
|
+
let report;
|
|
78
|
+
try { report = JSON.parse(result.stdout); } catch { /* mesh can return plain command output */ }
|
|
79
|
+
if (report?.ok === false) throw new Error(report.error || 'Remote command failed.');
|
|
80
|
+
return { ok: true, job: job.id, node, remote: true, command: entry, ...(report ? { delivery: report } : {}) };
|
|
81
|
+
}
|
|
82
|
+
const waiting = waitingRequests(job.id);
|
|
83
|
+
const reserved = new Set(readLines(jobPaths(job.id).inbox).map(row => row.requestId).filter(Boolean));
|
|
84
|
+
const request = entry.requestId ? waiting.find(row => row.requestId === entry.requestId)
|
|
85
|
+
: entry.type === 'reply' ? waiting.find(row => row.kind === 'question' && !reserved.has(row.requestId)) : null;
|
|
86
|
+
if (entry.requestId && !request) throw new Error(`No waiting request matches ${entry.requestId}.`);
|
|
87
|
+
if (request && entry.type === 'approve' && request.kind !== 'approval') throw new Error('The request is not an approval.');
|
|
88
|
+
if (request && entry.type === 'reply' && request.kind !== 'question') throw new Error('The request is not a question.');
|
|
89
|
+
if (request) {
|
|
90
|
+
if (reserved.has(request.requestId)) throw new Error('The request already has an answer in the inbox.');
|
|
91
|
+
entry.requestId = request.requestId;
|
|
92
|
+
if (request.source === 'mcp') entry.recipient = 'mcp';
|
|
93
|
+
// A deferred question is answered by the session runner, which starts the next turn with it.
|
|
94
|
+
else if (request.source === 'deferred') entry.recipient = 'deferred';
|
|
95
|
+
}
|
|
96
|
+
const { inbox } = jobPaths(job.id);
|
|
97
|
+
fs.mkdirSync(path.dirname(inbox), { recursive: true, mode: 0o700 });
|
|
98
|
+
fs.appendFileSync(inbox, JSON.stringify(entry) + '\n', { mode: 0o600 });
|
|
99
|
+
return { ok: true, job: job.id, command: entry };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* One consumer handles commands in file order. A false return leaves a command for
|
|
104
|
+
* another consumer. MCP answers have their own recipient so a worker cannot also
|
|
105
|
+
* send them to the driver. Await close() before releasing the driver.
|
|
106
|
+
*/
|
|
107
|
+
export function tailInbox(job, onCommand, { pollMs = 50, recipient = 'driver', onError = () => {} } = {}) {
|
|
108
|
+
const { inbox, events } = jobPaths(job);
|
|
109
|
+
fs.mkdirSync(path.dirname(inbox), { recursive: true, mode: 0o700 });
|
|
110
|
+
fs.closeSync(fs.openSync(inbox, 'a', 0o600));
|
|
111
|
+
let closed = false, running = null;
|
|
112
|
+
const seen = new Set();
|
|
113
|
+
const poll = () => {
|
|
114
|
+
if (closed || running) return running;
|
|
115
|
+
running = (async () => {
|
|
116
|
+
const acknowledged = new Set(readLines(events).filter(row => row.kind === 'ack' && row.commandId).map(row => row.commandId));
|
|
117
|
+
for (const command of readLines(inbox)) {
|
|
118
|
+
if (closed) break;
|
|
119
|
+
if (!command.id || seen.has(command.id) || acknowledged.has(command.id) || (command.recipient || 'driver') !== recipient) continue;
|
|
120
|
+
let result;
|
|
121
|
+
try { result = await onCommand(command); }
|
|
122
|
+
catch (error) {
|
|
123
|
+
// A failed command is reported once; do not repeat an agent side effect.
|
|
124
|
+
seen.add(command.id);
|
|
125
|
+
appendEvent(job, { kind: 'ack', command: command.type || command.command, commandId: command.id,
|
|
126
|
+
requestId: command.requestId, ok: false, text: error.message });
|
|
127
|
+
onError(error);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (result === false || result?.handled === false) continue;
|
|
131
|
+
seen.add(command.id);
|
|
132
|
+
appendEvent(job, { kind: 'ack', command: command.type || command.command, commandId: command.id,
|
|
133
|
+
requestId: command.requestId, ok: true, text: `Handled ${command.type || command.command}`, ...(result?.via ? { via: result.via } : {}) });
|
|
134
|
+
}
|
|
135
|
+
})().catch(onError).finally(() => { running = null; });
|
|
136
|
+
return running;
|
|
137
|
+
};
|
|
138
|
+
const timer = setInterval(poll, pollMs);
|
|
139
|
+
poll();
|
|
140
|
+
const close = async () => { closed = true; clearInterval(timer); await running; };
|
|
141
|
+
// A function is convenient for existing watcher callers; properties support explicit lifecycle use.
|
|
142
|
+
close.close = close;
|
|
143
|
+
close.poll = poll;
|
|
144
|
+
return close;
|
|
145
|
+
}
|