@xtruder/oc-plugin-convergence-engine 0.1.0 → 0.1.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +1 -1
  3. 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.0",
4
+ "version": "0.1.1",
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",
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: { role: "user" | "assistant" }
22
- parts: Array<{ type: string; text?: string; status?: string }>
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 completed normally (went busy then idle)
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
- const [sessionAborted, setSessionAborted] = createSignal(false)
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 completed normally (went busy
504
- // then idle without being aborted). Reset tracking state either way.
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 wasAborted = sessionAborted()
512
+ const wasQuestionRejected = questionRejected()
507
513
  setSessionWentBusy(false)
508
- setSessionAborted(false)
514
+ setQuestionRejected(false)
509
515
 
510
- if (!wasBusy || wasAborted) return
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
- setSessionAborted(false)
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