@xtruder/oc-plugin-convergence-engine 0.1.0 → 0.1.2
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/LICENSE +21 -0
- package/package.json +2 -2
- package/tui.tsx +54 -12
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 xtruder
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@xtruder/oc-plugin-convergence-engine",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"description": "Convergence engine for OpenCode - automatically verifies and continues LLM work until tasks are truly complete",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"types.ts"
|
|
31
31
|
],
|
|
32
32
|
"engines": {
|
|
33
|
-
"opencode": ">=1.3.
|
|
33
|
+
"opencode": ">=1.3.13"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@opencode-ai/plugin": "*",
|
package/tui.tsx
CHANGED
|
@@ -18,8 +18,11 @@ const KV_PREFIX = "convergence:"
|
|
|
18
18
|
|
|
19
19
|
/** Minimal type for message objects returned by the SDK. */
|
|
20
20
|
interface SessionMessage {
|
|
21
|
-
info: {
|
|
22
|
-
|
|
21
|
+
info: {
|
|
22
|
+
role: "user" | "assistant"
|
|
23
|
+
error?: { name?: string } | null
|
|
24
|
+
}
|
|
25
|
+
parts: Array<{ type: string; text?: string; status?: string; state?: { status?: string; error?: string } }>
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
interface ConvergenceDisplayState {
|
|
@@ -70,10 +73,11 @@ const tui: TuiPlugin = async (api, options) => {
|
|
|
70
73
|
// Abort controller for the current verification run
|
|
71
74
|
const [currentAbort, setCurrentAbort] = createSignal<AbortController | null>(null)
|
|
72
75
|
|
|
73
|
-
// Track whether the coding session
|
|
74
|
-
// vs was aborted. We only trigger verification after normal completion.
|
|
76
|
+
// Track whether the coding session went busy (user sent a prompt)
|
|
75
77
|
const [sessionWentBusy, setSessionWentBusy] = createSignal(false)
|
|
76
|
-
|
|
78
|
+
|
|
79
|
+
// Track whether a question was dismissed/rejected during the current message
|
|
80
|
+
const [questionRejected, setQuestionRejected] = createSignal(false)
|
|
77
81
|
|
|
78
82
|
// Idle event resolvers for promptAndWait
|
|
79
83
|
const idleResolvers = new Map<string, () => void>()
|
|
@@ -500,18 +504,49 @@ const tui: TuiPlugin = async (api, options) => {
|
|
|
500
504
|
// Trigger verification for the current session
|
|
501
505
|
if (sessionID !== currentSessionID()) return
|
|
502
506
|
|
|
503
|
-
// Only trigger verification if the session
|
|
504
|
-
//
|
|
507
|
+
// Only trigger verification if the session went busy (user sent a prompt)
|
|
508
|
+
// and the last assistant message completed without errors. This handles
|
|
509
|
+
// all abort scenarios including the race condition where aborting during
|
|
510
|
+
// a question/permission ask may not produce a MessageAbortedError.
|
|
505
511
|
const wasBusy = sessionWentBusy()
|
|
506
|
-
const
|
|
512
|
+
const wasQuestionRejected = questionRejected()
|
|
507
513
|
setSessionWentBusy(false)
|
|
508
|
-
|
|
514
|
+
setQuestionRejected(false)
|
|
509
515
|
|
|
510
|
-
if (!wasBusy ||
|
|
516
|
+
if (!wasBusy || wasQuestionRejected) return
|
|
511
517
|
|
|
512
518
|
const s = state()
|
|
513
519
|
if (!s || !s.active || s.processing) return
|
|
514
520
|
|
|
521
|
+
// Check the last assistant message to decide if verification is warranted.
|
|
522
|
+
// Skip if: the message was aborted, any tools were aborted, or no
|
|
523
|
+
// substantive tool calls were made (e.g. only text responses after a
|
|
524
|
+
// dismissed question or permission rejection).
|
|
525
|
+
try {
|
|
526
|
+
const messagesResp = await api.client.session.messages({ sessionID, limit: 3 })
|
|
527
|
+
const messages = (messagesResp.data ?? []) as Array<SessionMessage>
|
|
528
|
+
const lastAssistant = [...messages]
|
|
529
|
+
.reverse()
|
|
530
|
+
.find((m) => m.info?.role === "assistant")
|
|
531
|
+
|
|
532
|
+
if (!lastAssistant) return
|
|
533
|
+
|
|
534
|
+
// Skip if the message has an error (MessageAbortedError, etc.)
|
|
535
|
+
if (lastAssistant.info.error) return
|
|
536
|
+
|
|
537
|
+
// Skip if any tool was aborted
|
|
538
|
+
const hasAbortedTool = lastAssistant.parts.some(
|
|
539
|
+
(p) => p.type === "tool" && (
|
|
540
|
+
p.state?.error === "Tool execution aborted" ||
|
|
541
|
+
p.status === "error"
|
|
542
|
+
),
|
|
543
|
+
)
|
|
544
|
+
if (hasAbortedTool) return
|
|
545
|
+
} catch {
|
|
546
|
+
// If we can't read messages, skip verification
|
|
547
|
+
return
|
|
548
|
+
}
|
|
549
|
+
|
|
515
550
|
await runVerification(sessionID)
|
|
516
551
|
})
|
|
517
552
|
api.lifecycle.onDispose(offIdle)
|
|
@@ -524,7 +559,7 @@ const tui: TuiPlugin = async (api, options) => {
|
|
|
524
559
|
|
|
525
560
|
if (props?.status?.type === "busy") {
|
|
526
561
|
setSessionWentBusy(true)
|
|
527
|
-
|
|
562
|
+
setQuestionRejected(false)
|
|
528
563
|
hideVerifierDialog()
|
|
529
564
|
|
|
530
565
|
const s = state()
|
|
@@ -542,12 +577,19 @@ const tui: TuiPlugin = async (api, options) => {
|
|
|
542
577
|
|
|
543
578
|
const errorName = props.error?.name ?? props.error?.type
|
|
544
579
|
if (errorName === "MessageAbortedError" || errorName === "message_aborted") {
|
|
545
|
-
setSessionAborted(true)
|
|
546
580
|
abortVerification()
|
|
547
581
|
}
|
|
548
582
|
})
|
|
549
583
|
api.lifecycle.onDispose(offError)
|
|
550
584
|
|
|
585
|
+
// question.rejected: track when user dismisses a question so we skip verification
|
|
586
|
+
const offQuestion = api.event.on("question.rejected", (event) => {
|
|
587
|
+
const props = (event as { properties?: { sessionID?: string } }).properties
|
|
588
|
+
if (props?.sessionID !== currentSessionID()) return
|
|
589
|
+
setQuestionRejected(true)
|
|
590
|
+
})
|
|
591
|
+
api.lifecycle.onDispose(offQuestion)
|
|
592
|
+
|
|
551
593
|
// todo.updated: track todos from managed sessions (fork/verifier)
|
|
552
594
|
const offTodo = api.event.on("todo.updated", (event) => {
|
|
553
595
|
const props = (event as { properties?: { sessionID?: string; todos?: SessionTodo[] } }).properties
|