@hearsay-tools/squawk 0.18.0-pr3778.7014 → 0.18.0-pr3780.7017
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/dist/ci-wait/controller.d.ts +42 -42
- package/dist/core/agent-runner.d.ts +13 -1
- package/dist/core/agent-runner.js +1 -0
- package/dist/core/agent-runner.js.map +1 -1
- package/dist/core/claude-cli-runner.d.ts +3 -0
- package/dist/core/claude-cli-runner.js +13 -6
- package/dist/core/claude-cli-runner.js.map +1 -1
- package/dist/core/codex-app-server-runner.d.ts +4 -18
- package/dist/core/codex-app-server-runner.js +43 -45
- package/dist/core/codex-app-server-runner.js.map +1 -1
- package/dist/core/codex-turn-config.d.ts +19 -0
- package/dist/core/codex-turn-config.js +30 -0
- package/dist/core/codex-turn-config.js.map +1 -0
- package/dist/core/managed-session.js +0 -1
- package/dist/core/managed-session.js.map +1 -1
- package/dist/core/omp-runner.d.ts +3 -0
- package/dist/core/omp-runner.js +32 -16
- package/dist/core/omp-runner.js.map +1 -1
- package/dist/core/omp-ui-mapper.d.ts +2 -2
- package/dist/core/omp-ui-mapper.js +21 -2
- package/dist/core/omp-ui-mapper.js.map +1 -1
- package/dist/core/opencode-http.d.ts +2 -0
- package/dist/core/opencode-http.js +25 -0
- package/dist/core/opencode-http.js.map +1 -0
- package/dist/core/opencode-questions.d.ts +3 -0
- package/dist/core/opencode-questions.js +66 -0
- package/dist/core/opencode-questions.js.map +1 -0
- package/dist/core/opencode-server-runner.d.ts +3 -0
- package/dist/core/opencode-server-runner.js +89 -98
- package/dist/core/opencode-server-runner.js.map +1 -1
- package/dist/core/pi-rpc-turn.d.ts +21 -6
- package/dist/core/pi-rpc-turn.js +42 -17
- package/dist/core/pi-rpc-turn.js.map +1 -1
- package/dist/core/pi-rpc-wire.d.ts +5 -0
- package/dist/core/pi-rpc-wire.js +27 -2
- package/dist/core/pi-rpc-wire.js.map +1 -1
- package/dist/core/pi-runner.d.ts +3 -0
- package/dist/core/pi-runner.js +21 -15
- package/dist/core/pi-runner.js.map +1 -1
- package/dist/core/runner-facts.d.ts +21 -0
- package/dist/core/runner-facts.js +5 -0
- package/dist/core/runner-facts.js.map +1 -1
- package/dist/core/skill-trigger.d.ts +10 -0
- package/dist/core/skill-trigger.js +32 -0
- package/dist/core/skill-trigger.js.map +1 -0
- package/dist/core/ui-events.d.ts +7 -0
- package/dist/delegation/routes.d.ts +75 -75
- package/dist/delegation/transport.d.ts +82 -82
- package/dist/runs/outcome-commit.d.ts +1 -1
- package/dist/server/reports-api.d.ts +2 -2
- package/dist/server/server.d.ts +1630 -1630
- package/dist/workflows/run/continuation-session.js +1 -1
- package/dist/workflows/run/continuation-session.js.map +1 -1
- package/dist/workflows/run/session-events.js +1 -1
- package/dist/workflows/run/session-events.js.map +1 -1
- package/dist/workflows/run/squawk-tools.js +1 -1
- package/dist/workflows/run/squawk-tools.js.map +1 -1
- package/dist/workflows/run/worker-executions.js +1 -1
- package/dist/workflows/run/worker-executions.js.map +1 -1
- package/dist/workflows/run.js +2 -2
- package/dist/workflows/run.js.map +1 -1
- package/dist/worktree-manifest.d.ts +1 -1
- package/dist/worktree-manifest.js +1 -1
- package/package.json +4 -4
- package/scripts/mock-claude.mjs +18 -3
- package/scripts/mock-codex-app-server.mjs +14 -0
- package/scripts/mock-omp-rpc.mjs +10 -2
- package/scripts/mock-opencode-serve.mjs +37 -0
- package/scripts/mock-pi-rpc.mjs +16 -4
- package/scripts/mock-skill-trigger-data.mjs +168 -0
- package/scripts/mock-skill-trigger.mjs +34 -0
- package/web/dist/assets/{activity-motion-CXY7UQb8.js → activity-motion-DAjCyDzm.js} +1 -1
- package/web/dist/assets/{activity-route-CWdkKOcU.js → activity-route-6spKzFa-.js} +1 -1
- package/web/dist/assets/{commit-diff-panel-CilF4ucO.js → commit-diff-panel-uoyOydBG.js} +1 -1
- package/web/dist/assets/{diff-wu8MI0pe.js → diff-BefwAEc1.js} +2 -2
- package/web/dist/assets/{diff-view-BOeIj6fq.js → diff-view-CXtKy-02.js} +1 -1
- package/web/dist/assets/{file-preview-DDISrpoK.js → file-preview-TYTU1SBo.js} +1 -1
- package/web/dist/assets/{git-toolbar-DSFDBGUd.js → git-toolbar-BwD-ShUL.js} +1 -1
- package/web/dist/assets/{github-DBRyp_7V.js → github-DKC9GSOG.js} +1 -1
- package/web/dist/assets/{global-activity-route-8gXrkEI5.js → global-activity-route-BnUvjKgI.js} +1 -1
- package/web/dist/assets/{index-1Zw2w-1r.js → index-C6UoXbYK.js} +3 -3
- package/web/dist/assets/{preview-pane-connected-B_yXVXFs.js → preview-pane-connected-ZAr18goj.js} +3 -3
- package/web/dist/assets/{repo-git-cpVcsnni.js → repo-git-Y7MKcjLs.js} +1 -1
- package/web/dist/assets/{report-reader-BRw4X5KH.js → report-reader-CIcjK2_U.js} +1 -1
- package/web/dist/assets/{reports-BK0543bM.js → reports-SBr0VYKU.js} +1 -1
- package/web/dist/assets/{run-header-CZhtodUg.js → run-header-BSohU_tW.js} +1 -1
- package/web/dist/assets/{skills-0Az8jsnI.js → skills-B_NKCTPq.js} +1 -1
- package/web/dist/assets/{task-changes-jjPRV2ul.js → task-changes-Ozgv3HxN.js} +1 -1
- package/web/dist/assets/{task-commits-CxJKFd3j.js → task-commits-BxAERDIz.js} +1 -1
- package/web/dist/assets/{task-files-Ddk24Oe-.js → task-files-V84lmxj2.js} +1 -1
- package/web/dist/assets/{task-github-item-D49mwA5b.js → task-github-item-CByJ7mYg.js} +1 -1
- package/web/dist/assets/{task-thread-BlVvC3Mo.js → task-thread-C6v4ddX-.js} +9 -9
- package/web/dist/assets/thread-state-ni3Us7DE.js +4 -0
- package/web/dist/assets/{use-hand-to-agent-state-Cgc4s3aK.js → use-hand-to-agent-state-W5nhKd6-.js} +1 -1
- package/web/dist/assets/{workflows-BW6W8C0F.js → workflows-Cb0BDqy5.js} +1 -1
- package/web/dist/index.html +1 -1
- package/web/dist/assets/thread-state-DfIi2HR7.js +0 -4
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { parseAskRequest } from './ask.js';
|
|
2
|
+
export function toSquawkQuestions(value) {
|
|
3
|
+
if (!isRecord(value) || !Array.isArray(value.questions))
|
|
4
|
+
return null;
|
|
5
|
+
if (value.questions.length < 1 || value.questions.length > 4)
|
|
6
|
+
return null;
|
|
7
|
+
const questions = [];
|
|
8
|
+
for (const rawQuestion of value.questions) {
|
|
9
|
+
if (!isRecord(rawQuestion))
|
|
10
|
+
return null;
|
|
11
|
+
const header = clippedString(rawQuestion.header, 12);
|
|
12
|
+
const question = clippedString(rawQuestion.question, 400);
|
|
13
|
+
if (!header || !question || !Array.isArray(rawQuestion.options))
|
|
14
|
+
return null;
|
|
15
|
+
const options = [];
|
|
16
|
+
for (const rawOption of rawQuestion.options) {
|
|
17
|
+
if (options.length === 4)
|
|
18
|
+
break;
|
|
19
|
+
if (!isRecord(rawOption))
|
|
20
|
+
continue;
|
|
21
|
+
const label = clippedString(rawOption.label, 60);
|
|
22
|
+
if (!label)
|
|
23
|
+
continue;
|
|
24
|
+
const description = clippedString(rawOption.description, 280);
|
|
25
|
+
options.push({ label, ...(description ? { description } : {}) });
|
|
26
|
+
}
|
|
27
|
+
if (options.length < 2)
|
|
28
|
+
return null;
|
|
29
|
+
questions.push({
|
|
30
|
+
header,
|
|
31
|
+
question,
|
|
32
|
+
options,
|
|
33
|
+
...(rawQuestion.multiple === true ? { multiSelect: true } : {}),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return parseAskRequest({ questions })?.questions ?? null;
|
|
37
|
+
}
|
|
38
|
+
export function questionAnswers(questions, text) {
|
|
39
|
+
const answers = questions.map(() => []);
|
|
40
|
+
const matched = new Set();
|
|
41
|
+
for (const line of text.split('\n')) {
|
|
42
|
+
const trimmed = line.trim();
|
|
43
|
+
const index = questions.findIndex((question, questionIndex) => !matched.has(questionIndex) && trimmed.startsWith(`${question.header}:`));
|
|
44
|
+
if (index < 0)
|
|
45
|
+
continue;
|
|
46
|
+
matched.add(index);
|
|
47
|
+
answers[index] = trimmed
|
|
48
|
+
.slice(questions[index].header.length + 1)
|
|
49
|
+
.split(',')
|
|
50
|
+
.map((answer) => answer.trim())
|
|
51
|
+
.filter(Boolean);
|
|
52
|
+
}
|
|
53
|
+
if (matched.size === 0 && answers[0])
|
|
54
|
+
answers[0] = [text.trim()];
|
|
55
|
+
return answers;
|
|
56
|
+
}
|
|
57
|
+
function clippedString(value, max) {
|
|
58
|
+
if (typeof value !== 'string')
|
|
59
|
+
return undefined;
|
|
60
|
+
const trimmed = value.trim();
|
|
61
|
+
return trimmed ? trimmed.slice(0, max) : undefined;
|
|
62
|
+
}
|
|
63
|
+
function isRecord(value) {
|
|
64
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=opencode-questions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode-questions.js","sourceRoot":"","sources":["../../src/core/opencode-questions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAoB,MAAM,UAAU,CAAC;AAE7D,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAC;IACrE,IAAI,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1E,MAAM,SAAS,GAAkB,EAAE,CAAC;IACpC,KAAK,MAAM,WAAW,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;QAC1C,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;YAAE,OAAO,IAAI,CAAC;QACxC,MAAM,MAAM,GAAG,aAAa,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC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EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACrD,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -49,6 +49,9 @@ export declare class OpencodeServerRunner implements AgentRunner {
|
|
|
49
49
|
readonly specSupport: Readonly<Record<keyof AgentRunSpec, import("./agent-runner.ts").SpecFieldSupport>>;
|
|
50
50
|
readonly systemPromptOnResume: "in-thread";
|
|
51
51
|
readonly facts: {
|
|
52
|
+
readonly skillTriggerMidTurn: false;
|
|
53
|
+
readonly skillUnknownName: 'error';
|
|
54
|
+
readonly skillsSeenBySession: 'at-start';
|
|
52
55
|
readonly childWork: 'nested';
|
|
53
56
|
readonly hookEvents: 'none';
|
|
54
57
|
readonly nativePermission: 'after-turn';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { opencodeHttp } from './opencode-http.js';
|
|
2
|
+
import { skillOf, validSkillMessage } from './skill-trigger.js';
|
|
1
3
|
import { productEnv } from './product-env.js';
|
|
2
4
|
import { uiAskQuestions } from './ask.js';
|
|
3
5
|
import { opencodeSkillWarning, sessionErrorDetail, sessionErrorText } from './opencode-session-error.js';
|
|
@@ -16,7 +18,7 @@ import { signalSession, spawnSessionLeader } from './session-process.js';
|
|
|
16
18
|
import { buildChildEnv } from './agent-env.js';
|
|
17
19
|
import { opencodeTaskScopeEnv } from './opencode-task-scope.js';
|
|
18
20
|
import { ciOpenCodeEnv } from '../ci-wait/injection.js';
|
|
19
|
-
import {
|
|
21
|
+
import { toSquawkQuestions, questionAnswers } from './opencode-questions.js';
|
|
20
22
|
import { boundOutputDrainAfterExit, AUTO_END_DELAY_MS, DEFAULT_RUNNER_TIMINGS } from './runner-runtime.js';
|
|
21
23
|
import { formatModelIdentity, parseModelIdentity } from './model-identity.js';
|
|
22
24
|
import { V1TextCoalescer } from './v1-text-coalescer.js';
|
|
@@ -66,6 +68,7 @@ export const OPENCODE_SPEC_SUPPORT = {
|
|
|
66
68
|
squawkTools: { honored: true, via: 'merged OPENCODE_CONFIG_CONTENT local mcp entry' },
|
|
67
69
|
...SQUAWK_SIDE_SPEC_SUPPORT,
|
|
68
70
|
systemPrompt: { honored: true, via: 'prepended to the opening prompt_async text through prependSystemPrompt' },
|
|
71
|
+
skill: { honored: true, via: 'POST session command; acknowledgement on SSE' },
|
|
69
72
|
userPrompt: { honored: true, via: 'prompt_async text part' },
|
|
70
73
|
images: { honored: false, reason: 'the adapter posts text parts only; image blocks are dropped' },
|
|
71
74
|
cwd: { honored: true, via: 'opencode serve spawn cwd; the session is bound to it' },
|
|
@@ -337,7 +340,13 @@ class OpencodeSession {
|
|
|
337
340
|
get pid() {
|
|
338
341
|
return this.serve.child.pid;
|
|
339
342
|
}
|
|
343
|
+
skillCommand;
|
|
344
|
+
refusesSkill(content) {
|
|
345
|
+
return !validSkillMessage(content) || Boolean(skillOf(content) && (!this.sessionId || this.turnActive || this.pendingPromptRequests || this.skillCommand));
|
|
346
|
+
}
|
|
340
347
|
sendAgentMessage(content, inputIds = []) {
|
|
348
|
+
if (this.refusesSkill(content))
|
|
349
|
+
return false;
|
|
341
350
|
// #505: a busy session is steered with prompt_async; only a pending native question or
|
|
342
351
|
// permission ask, a queued human prompt or an in-flight agent POST refuses.
|
|
343
352
|
// Nothing may run ahead of the task: refuse until the opening prompt has started,
|
|
@@ -364,7 +373,7 @@ class OpencodeSession {
|
|
|
364
373
|
this.submissions.accept(submissionId, inputIds, text);
|
|
365
374
|
if (!steering && inputIds.length)
|
|
366
375
|
this.turnOpeners.add(submissionId);
|
|
367
|
-
const post = steering ? this.steerPrompt(text, request.signal) : this.prompt(text, 'agent', request.signal);
|
|
376
|
+
const post = steering ? this.steerPrompt(text, request.signal) : this.prompt(text, 'agent', request.signal, this.queuedPromptGeneration, skillOf(content));
|
|
368
377
|
const acknowledgement = post.catch((err) => {
|
|
369
378
|
this.submissions.consume(submissionId);
|
|
370
379
|
this.turnOpeners.delete(submissionId);
|
|
@@ -383,12 +392,14 @@ class OpencodeSession {
|
|
|
383
392
|
return acknowledgement;
|
|
384
393
|
}
|
|
385
394
|
sendMessage(content) {
|
|
395
|
+
if (this.refusesSkill(content))
|
|
396
|
+
return false;
|
|
386
397
|
this.agentInputReady = false;
|
|
387
398
|
if (!this.open)
|
|
388
399
|
return false;
|
|
389
400
|
this.cancelAutoEnd();
|
|
390
401
|
const text = textOf(content);
|
|
391
|
-
if (!text)
|
|
402
|
+
if (!text && !skillOf(content))
|
|
392
403
|
return true;
|
|
393
404
|
if (this.questionReply) {
|
|
394
405
|
this.queuedQuestionMessages.push(text);
|
|
@@ -409,7 +420,7 @@ class OpencodeSession {
|
|
|
409
420
|
// `prompt` already emitted the note and closed the turn before rethrowing,
|
|
410
421
|
// and a rejected `ready` already failed the session on the result path —
|
|
411
422
|
// there is nothing left to report here.
|
|
412
|
-
this.deliverPrompt(text);
|
|
423
|
+
this.deliverPrompt(text, skillOf(content));
|
|
413
424
|
return true;
|
|
414
425
|
}
|
|
415
426
|
discardQueuedMessages() {
|
|
@@ -423,13 +434,13 @@ class OpencodeSession {
|
|
|
423
434
|
heldHumanInputCount() {
|
|
424
435
|
return this.humanPromptWaiters + this.queuedQuestionMessages.length;
|
|
425
436
|
}
|
|
426
|
-
deliverPrompt(text) {
|
|
437
|
+
deliverPrompt(text, skill) {
|
|
427
438
|
this.pendingPromptRequests += 1;
|
|
428
439
|
// Held from admission, not from `ready`; a start that fails releases it (hearsay-tools/cezarion#2991).
|
|
429
440
|
const generation = this.queuedPromptGeneration;
|
|
430
441
|
this.humanPromptWaiters += 1;
|
|
431
442
|
let posting = false;
|
|
432
|
-
void this.ready.then(() => { posting = true; return this.prompt(text, 'human', undefined, generation); }).then(() => {
|
|
443
|
+
void this.ready.then(() => { posting = true; return this.prompt(text, 'human', undefined, generation, skill); }).then(() => {
|
|
433
444
|
this.pendingPromptRequests -= 1;
|
|
434
445
|
this.notifyAgentInputReady();
|
|
435
446
|
}, () => {
|
|
@@ -483,6 +494,7 @@ class OpencodeSession {
|
|
|
483
494
|
if (!this.serverOpen)
|
|
484
495
|
return;
|
|
485
496
|
this.serverOpen = false;
|
|
497
|
+
this.settleSkillCommand(new SessionEndedBeforeAcknowledgement());
|
|
486
498
|
this.clearLostWakeTimer();
|
|
487
499
|
this.endedAgentRequest = this.agentRequest;
|
|
488
500
|
this.agentRequest?.abort();
|
|
@@ -492,6 +504,7 @@ class OpencodeSession {
|
|
|
492
504
|
}
|
|
493
505
|
interrupt() {
|
|
494
506
|
this.serverOpen = false;
|
|
507
|
+
this.settleSkillCommand(new SessionEndedBeforeAcknowledgement());
|
|
495
508
|
this.clearLostWakeTimer();
|
|
496
509
|
this.agentRequest?.abort();
|
|
497
510
|
this.expirePermissions('session ended');
|
|
@@ -561,7 +574,7 @@ class OpencodeSession {
|
|
|
561
574
|
// bound prevents an inherited descendant pipe from retaining this session.
|
|
562
575
|
const outputDrained = Promise.all([child.stdout, child.stderr].map(stream => finished(stream, { cleanup: true }).catch(() => undefined)));
|
|
563
576
|
const exited = new Promise((resolve) => {
|
|
564
|
-
child.once('exit', () => resolve());
|
|
577
|
+
child.once('exit', () => { this.settleSkillCommand(new SessionEndedBeforeAcknowledgement()); resolve(); });
|
|
565
578
|
child.once('close', () => resolve());
|
|
566
579
|
});
|
|
567
580
|
const serve = {
|
|
@@ -690,9 +703,9 @@ class OpencodeSession {
|
|
|
690
703
|
return { id };
|
|
691
704
|
}
|
|
692
705
|
}
|
|
693
|
-
attachSession(id) {
|
|
706
|
+
attachSession(id, resumed) {
|
|
694
707
|
this.sessionId = id;
|
|
695
|
-
this.emit({ type: 'session', sessionId: id });
|
|
708
|
+
this.emit({ type: 'session', sessionId: id, resumed });
|
|
696
709
|
this.emitUi((state) => opencodeSessionStarted(id, state));
|
|
697
710
|
}
|
|
698
711
|
async bootstrap() {
|
|
@@ -709,7 +722,7 @@ class OpencodeSession {
|
|
|
709
722
|
else {
|
|
710
723
|
// A `task` deny an older Squawk added stays on the session: OpenCode appends permission
|
|
711
724
|
// rules and has no remove (hearsay-tools/cezarion#2279).
|
|
712
|
-
this.attachSession(stringField(existing, 'id') ?? requested);
|
|
725
|
+
this.attachSession(stringField(existing, 'id') ?? requested, true);
|
|
713
726
|
resumed = true;
|
|
714
727
|
}
|
|
715
728
|
}
|
|
@@ -721,7 +734,7 @@ class OpencodeSession {
|
|
|
721
734
|
const sessionId = stringField(created, 'id');
|
|
722
735
|
if (!sessionId)
|
|
723
736
|
throw new Error('opencode did not return a session id');
|
|
724
|
-
this.attachSession(sessionId);
|
|
737
|
+
this.attachSession(sessionId, false);
|
|
725
738
|
}
|
|
726
739
|
// The SSE subscription must be LIVE before the first prompt posts —
|
|
727
740
|
// events the server emits while the POST is in flight would otherwise be
|
|
@@ -734,7 +747,7 @@ class OpencodeSession {
|
|
|
734
747
|
? (this.spec.resumeFallbackSystemPrompt ?? this.spec.systemPrompt)
|
|
735
748
|
: this.spec.systemPrompt;
|
|
736
749
|
const first = prependSystemPrompt(systemPrompt, this.spec.userPrompt);
|
|
737
|
-
await this.prompt(first, 'opening');
|
|
750
|
+
await this.prompt(first, 'opening', undefined, this.queuedPromptGeneration, this.spec.skill);
|
|
738
751
|
if (this.refusedBeforeOpening)
|
|
739
752
|
queueMicrotask(() => {
|
|
740
753
|
this.refusedBeforeOpening = false;
|
|
@@ -743,7 +756,7 @@ class OpencodeSession {
|
|
|
743
756
|
}
|
|
744
757
|
});
|
|
745
758
|
}
|
|
746
|
-
async prompt(text, origin = 'human', signal, generation = this.queuedPromptGeneration) {
|
|
759
|
+
async prompt(text, origin = 'human', signal, generation = this.queuedPromptGeneration, skill) {
|
|
747
760
|
// One turn at a time. `prompt_async` acknowledges before the turn runs,
|
|
748
761
|
// so `ready` no longer serializes prompts the way the long-poll did — a
|
|
749
762
|
// follow-up posted mid-turn would share the turnActive/turnEnded pair
|
|
@@ -773,6 +786,10 @@ class OpencodeSession {
|
|
|
773
786
|
// and undici's default 300s headers timeout ended it as `prompt failed:
|
|
774
787
|
// fetch failed` (#4, upstream #897); `prompt_async` returns immediately.
|
|
775
788
|
this.emitUi(opencodeTurnStarted);
|
|
789
|
+
if (skill) {
|
|
790
|
+
await this.command(skill, text, signal);
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
776
793
|
const body = this.promptBody(text);
|
|
777
794
|
try {
|
|
778
795
|
await this.http('POST', `/session/${this.sessionId}/prompt_async`, body, signal);
|
|
@@ -782,6 +799,45 @@ class OpencodeSession {
|
|
|
782
799
|
throw err;
|
|
783
800
|
}
|
|
784
801
|
}
|
|
802
|
+
/** The command response long-polls the whole turn. SSE user text acknowledges expansion.
|
|
803
|
+
* Read HTTP errors, but a disconnected request (including fetch's 300s limit) leaves SSE in charge. */
|
|
804
|
+
command(skill, context, signal) {
|
|
805
|
+
const controller = new AbortController();
|
|
806
|
+
let resolve;
|
|
807
|
+
let reject;
|
|
808
|
+
const acknowledged = new Promise((yes, no) => { resolve = yes; reject = no; });
|
|
809
|
+
const command = { controller, resolve, reject };
|
|
810
|
+
const abort = () => { reject(new SessionEndedBeforeAcknowledgement()); controller.abort(); };
|
|
811
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
812
|
+
void acknowledged.finally(() => signal?.removeEventListener('abort', abort)).catch(() => undefined);
|
|
813
|
+
this.skillCommand = command;
|
|
814
|
+
const body = {
|
|
815
|
+
command: skill.id,
|
|
816
|
+
arguments: [skill.args, context].filter(Boolean).join('\n\n'),
|
|
817
|
+
...(this.spec.model ? { model: this.spec.model } : {}),
|
|
818
|
+
...(parseEffort(this.spec.effort) ? { variant: parseEffort(this.spec.effort) } : {}),
|
|
819
|
+
};
|
|
820
|
+
void fetch(`${this.baseUrl}/session/${this.sessionId}/command`, {
|
|
821
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
822
|
+
body: JSON.stringify(body), signal: controller.signal,
|
|
823
|
+
}).then(async (response) => {
|
|
824
|
+
if (!response.ok && this.skillCommand === command) {
|
|
825
|
+
const detail = await response.text().catch(() => '');
|
|
826
|
+
if (this.skillCommand !== command)
|
|
827
|
+
return;
|
|
828
|
+
this.turnErrored = true;
|
|
829
|
+
const message = `opencode: command failed: HTTP ${response.status} ${detail.slice(0, 200)}`;
|
|
830
|
+
command.reject(new Error(message));
|
|
831
|
+
this.emit({ type: 'error', message });
|
|
832
|
+
this.emitUi(state => mapOpencodeEvent({ type: 'session.error', properties: { sessionID: this.sessionId, error: { message } } }, state));
|
|
833
|
+
this.finishTurn();
|
|
834
|
+
}
|
|
835
|
+
else {
|
|
836
|
+
await response.body?.cancel();
|
|
837
|
+
}
|
|
838
|
+
}).catch(() => { });
|
|
839
|
+
return acknowledged;
|
|
840
|
+
}
|
|
785
841
|
reportPromptFailure(origin, err) {
|
|
786
842
|
// No turn started server-side, so no `session.idle` will ever close it —
|
|
787
843
|
// surface the failure and end the turn here instead of parking the run.
|
|
@@ -878,11 +934,24 @@ class OpencodeSession {
|
|
|
878
934
|
return;
|
|
879
935
|
queueMicrotask(() => this.notifyAgentInputReady());
|
|
880
936
|
}
|
|
937
|
+
settleSkillCommand(error) {
|
|
938
|
+
const command = this.skillCommand;
|
|
939
|
+
this.skillCommand = undefined;
|
|
940
|
+
if (error)
|
|
941
|
+
command?.reject(error);
|
|
942
|
+
else
|
|
943
|
+
command?.resolve();
|
|
944
|
+
command?.controller.abort();
|
|
945
|
+
}
|
|
881
946
|
finishTurn() {
|
|
882
947
|
if (!this.turnActive || this.turnEnded)
|
|
883
948
|
return;
|
|
884
949
|
this.turnEnded = true;
|
|
885
950
|
this.turnActive = false;
|
|
951
|
+
const wasSkill = this.skillCommand !== undefined;
|
|
952
|
+
this.settleSkillCommand();
|
|
953
|
+
if (wasSkill && this.uiState.currentTurnId !== null)
|
|
954
|
+
this.emitUi(state => mapOpencodeEvent({ type: 'session.idle', properties: { sessionID: this.sessionId } }, state));
|
|
886
955
|
this.questionCapture = undefined;
|
|
887
956
|
// SSE idle can beat the independent reply HTTP response. The active reply
|
|
888
957
|
// owns pending-question cleanup; without one, the pending ask is stale.
|
|
@@ -1028,6 +1097,8 @@ class OpencodeSession {
|
|
|
1028
1097
|
const failure = { message: this.sessionErrorMessage(evt.properties?.error), reported: false };
|
|
1029
1098
|
this.providerErrorPending = failure;
|
|
1030
1099
|
const request = this.agentRequest;
|
|
1100
|
+
// A command has no separate HTTP ACK: the error can be its first SSE frame.
|
|
1101
|
+
this.skillCommand?.reject(new Error(failure.message));
|
|
1031
1102
|
const timer = setTimeout(() => request.abort(), KILL_GRACE_MS);
|
|
1032
1103
|
try {
|
|
1033
1104
|
await this.agentAcknowledgement?.catch(() => undefined);
|
|
@@ -1131,6 +1202,8 @@ class OpencodeSession {
|
|
|
1131
1202
|
if (sid === undefined || sid === this.sessionId) {
|
|
1132
1203
|
this.turnErrored = true;
|
|
1133
1204
|
this.emit({ type: 'error', message: this.sessionErrorMessage(props.error) });
|
|
1205
|
+
if (this.skillCommand)
|
|
1206
|
+
this.finishTurn();
|
|
1134
1207
|
}
|
|
1135
1208
|
}
|
|
1136
1209
|
handlePart(part) {
|
|
@@ -1170,6 +1243,7 @@ class OpencodeSession {
|
|
|
1170
1243
|
if (messageID && this.msgRole.get(messageID) !== 'assistant') {
|
|
1171
1244
|
// A user message carrying submitted agent text: remember which submission it is.
|
|
1172
1245
|
if (this.msgRole.get(messageID) === 'user' && stringField(part, 'type') === 'text' && !this.userMessageSubmission.has(messageID)) {
|
|
1246
|
+
this.skillCommand?.resolve();
|
|
1173
1247
|
const submission = this.submissions.findByText(stringField(part, 'text') ?? '');
|
|
1174
1248
|
if (submission && ![...this.userMessageSubmission.values()].includes(submission))
|
|
1175
1249
|
this.userMessageSubmission.set(messageID, submission);
|
|
@@ -1521,30 +1595,8 @@ class OpencodeSession {
|
|
|
1521
1595
|
catch { /* A failed consumer must not strand other pending requests. */ }
|
|
1522
1596
|
}
|
|
1523
1597
|
// ---- http ---------------------------------------------------------------
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
throw new Error('opencode server not ready');
|
|
1527
|
-
// Plain fetch is fine here: every call is a short round-trip now that
|
|
1528
|
-
// prompts go through `prompt_async` — nothing long-polls anymore.
|
|
1529
|
-
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
1530
|
-
method,
|
|
1531
|
-
...(signal !== undefined ? { signal } : {}),
|
|
1532
|
-
headers: body !== undefined ? { 'content-type': 'application/json' } : {},
|
|
1533
|
-
...(body !== undefined ? { body: JSON.stringify(body) } : {}),
|
|
1534
|
-
});
|
|
1535
|
-
if (!res.ok) {
|
|
1536
|
-
const detail = await res.text().catch(() => '');
|
|
1537
|
-
throw new Error(`${method} ${path} → ${res.status} ${detail.slice(0, 200)}`);
|
|
1538
|
-
}
|
|
1539
|
-
const text = await res.text();
|
|
1540
|
-
if (!text)
|
|
1541
|
-
return {};
|
|
1542
|
-
try {
|
|
1543
|
-
return JSON.parse(text);
|
|
1544
|
-
}
|
|
1545
|
-
catch {
|
|
1546
|
-
return {};
|
|
1547
|
-
}
|
|
1598
|
+
http(method, path, body, signal) {
|
|
1599
|
+
return opencodeHttp(this.baseUrl, method, path, body, signal);
|
|
1548
1600
|
}
|
|
1549
1601
|
emit(event) {
|
|
1550
1602
|
this.onEvent?.(event);
|
|
@@ -1572,67 +1624,6 @@ function textOf(content) {
|
|
|
1572
1624
|
.join('\n')
|
|
1573
1625
|
.trim();
|
|
1574
1626
|
}
|
|
1575
|
-
function toSquawkQuestions(value) {
|
|
1576
|
-
if (!isRecord(value) || !Array.isArray(value.questions))
|
|
1577
|
-
return null;
|
|
1578
|
-
if (value.questions.length < 1 || value.questions.length > 4)
|
|
1579
|
-
return null;
|
|
1580
|
-
const questions = [];
|
|
1581
|
-
for (const rawQuestion of value.questions) {
|
|
1582
|
-
if (!isRecord(rawQuestion))
|
|
1583
|
-
return null;
|
|
1584
|
-
const header = clippedString(rawQuestion.header, 12);
|
|
1585
|
-
const question = clippedString(rawQuestion.question, 400);
|
|
1586
|
-
if (!header || !question || !Array.isArray(rawQuestion.options))
|
|
1587
|
-
return null;
|
|
1588
|
-
const options = [];
|
|
1589
|
-
for (const rawOption of rawQuestion.options) {
|
|
1590
|
-
if (options.length === 4)
|
|
1591
|
-
break;
|
|
1592
|
-
if (!isRecord(rawOption))
|
|
1593
|
-
continue;
|
|
1594
|
-
const label = clippedString(rawOption.label, 60);
|
|
1595
|
-
if (!label)
|
|
1596
|
-
continue;
|
|
1597
|
-
const description = clippedString(rawOption.description, 280);
|
|
1598
|
-
options.push({ label, ...(description ? { description } : {}) });
|
|
1599
|
-
}
|
|
1600
|
-
if (options.length < 2)
|
|
1601
|
-
return null;
|
|
1602
|
-
questions.push({
|
|
1603
|
-
header,
|
|
1604
|
-
question,
|
|
1605
|
-
options,
|
|
1606
|
-
...(rawQuestion.multiple === true ? { multiSelect: true } : {}),
|
|
1607
|
-
});
|
|
1608
|
-
}
|
|
1609
|
-
return parseAskRequest({ questions })?.questions ?? null;
|
|
1610
|
-
}
|
|
1611
|
-
function questionAnswers(questions, text) {
|
|
1612
|
-
const answers = questions.map(() => []);
|
|
1613
|
-
const matched = new Set();
|
|
1614
|
-
for (const line of text.split('\n')) {
|
|
1615
|
-
const trimmed = line.trim();
|
|
1616
|
-
const index = questions.findIndex((question, questionIndex) => !matched.has(questionIndex) && trimmed.startsWith(`${question.header}:`));
|
|
1617
|
-
if (index < 0)
|
|
1618
|
-
continue;
|
|
1619
|
-
matched.add(index);
|
|
1620
|
-
answers[index] = trimmed
|
|
1621
|
-
.slice(questions[index].header.length + 1)
|
|
1622
|
-
.split(',')
|
|
1623
|
-
.map((answer) => answer.trim())
|
|
1624
|
-
.filter(Boolean);
|
|
1625
|
-
}
|
|
1626
|
-
if (matched.size === 0 && answers[0])
|
|
1627
|
-
answers[0] = [text.trim()];
|
|
1628
|
-
return answers;
|
|
1629
|
-
}
|
|
1630
|
-
function clippedString(value, max) {
|
|
1631
|
-
if (typeof value !== 'string')
|
|
1632
|
-
return undefined;
|
|
1633
|
-
const trimmed = value.trim();
|
|
1634
|
-
return trimmed ? trimmed.slice(0, max) : undefined;
|
|
1635
|
-
}
|
|
1636
1627
|
function isRecord(value) {
|
|
1637
1628
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
1638
1629
|
}
|