feat: add harness.cancel convenience (cancel active session)

This commit is contained in:
2026-09-01 19:05:40 +08:00
parent b2fb257aaa
commit b892ee3af6
+8
View File
@@ -96,6 +96,7 @@ function apply(ctx, config) {
params = params || {}; params = params || {};
if (method === 'harness.status') return computeStatus(); if (method === 'harness.status') return computeStatus();
if (method === 'harness.prompt') return harnessPrompt(params); if (method === 'harness.prompt') return harnessPrompt(params);
if (method === 'harness.cancel') return harnessCancel();
const dot = method.indexOf('.'); const dot = method.indexOf('.');
if (dot <= 0) throw new Error('unknown method ' + method); if (dot <= 0) throw new Error('unknown method ' + method);
const domain = method.slice(0, dot); const domain = method.slice(0, dot);
@@ -129,6 +130,13 @@ function apply(ctx, config) {
}); });
} }
async function harnessCancel() {
const status = await computeStatus();
const sessionId = status.activeSessionId;
if (!sessionId) throw new Error('no active session to cancel');
return api.sessions.cancel({ sessionId });
}
function handleRequest(msg, respond) { function handleRequest(msg, respond) {
invoke(msg.method || '', msg.params || {}).then((result) => { invoke(msg.method || '', msg.params || {}).then((result) => {
respond({ type: 'response', requestId: msg.requestId, ok: true, result }); respond({ type: 'response', requestId: msg.requestId, ok: true, result });