opencode-rag-plugin 2.9.0 → 2.9.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.
- package/dist/core/config.d.ts +16 -0
- package/dist/core/config.js +2 -0
- package/dist/plugin.js +313 -223
- package/dist/quirks/auto-inject.d.ts +127 -0
- package/dist/quirks/auto-inject.js +240 -0
- package/dist/quirks/error-signals.d.ts +81 -0
- package/dist/quirks/error-signals.js +225 -0
- package/dist/quirks/tool-error-create.js +25 -0
- package/dist/quirks/tool-error-recall.d.ts +6 -0
- package/dist/quirks/tool-error-recall.js +1 -0
- package/dist/v2/v2-adapter.d.ts +17 -0
- package/dist/v2/v2-adapter.js +53 -6
- package/package.json +1 -1
|
@@ -82,6 +82,31 @@ const ERROR_CAUSES = [
|
|
|
82
82
|
pattern: /timed? ?out|timeout|etimedout/i,
|
|
83
83
|
cause: "the operation timed out",
|
|
84
84
|
},
|
|
85
|
+
// The classes below cover failures detected in a tool's OUTPUT rather than
|
|
86
|
+
// reported by the host (see src/quirks/error-signals.ts). They are appended
|
|
87
|
+
// so the pre-existing precedence above is unchanged - a `ENOENT` in a
|
|
88
|
+
// command's output stays `path`, which is more actionable than "the
|
|
89
|
+
// command exited non-zero".
|
|
90
|
+
{
|
|
91
|
+
cls: "runtime",
|
|
92
|
+
pattern: /traceback \(most recent call last\)|^(?:type|reference|syntax|range|uri)error:/im,
|
|
93
|
+
cause: "the program raised an unhandled exception",
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
cls: "tooling",
|
|
97
|
+
pattern: /npm err!|eresolve|peer dep/i,
|
|
98
|
+
cause: "the package manager rejected the operation",
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
cls: "crash",
|
|
102
|
+
pattern: /segmentation fault|core dumped|panic:/i,
|
|
103
|
+
cause: "the process crashed",
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
cls: "exit-code",
|
|
107
|
+
pattern: /exited with code|command failed/i,
|
|
108
|
+
cause: "the command exited with a non-zero status",
|
|
109
|
+
},
|
|
85
110
|
];
|
|
86
111
|
/**
|
|
87
112
|
* Cause classes that are worth surfacing BEFORE the tool is called.
|
|
@@ -63,6 +63,12 @@ export interface ToolErrorQuirkHit {
|
|
|
63
63
|
score: number;
|
|
64
64
|
/** Raw vector similarity (0-1) — the value thresholds are compared against. */
|
|
65
65
|
rawSimilarity: number;
|
|
66
|
+
/**
|
|
67
|
+
* The quirk's tags. Carried so the caller's duplicate check can be EXACT
|
|
68
|
+
* (`tool:<name>` + `cause:<class>`) without a second lookup — the content is
|
|
69
|
+
* embedded error text, not a reliable identity.
|
|
70
|
+
*/
|
|
71
|
+
tags?: string[];
|
|
66
72
|
}
|
|
67
73
|
/** Tunables for the tool-error quirk path. */
|
|
68
74
|
export interface ToolErrorRecallOptions {
|
|
@@ -130,6 +130,7 @@ export async function recallToolErrorQuirks(recall, info, state, options) {
|
|
|
130
130
|
quirkType: hit.chunk.metadata?.quirkType,
|
|
131
131
|
score: hit.score,
|
|
132
132
|
rawSimilarity: hit.rawSimilarity ?? hit.score,
|
|
133
|
+
tags: hit.chunk.metadata?.tags,
|
|
133
134
|
});
|
|
134
135
|
}
|
|
135
136
|
candidates.sort((a, b) => b.rawSimilarity - a.rawSimilarity);
|
package/dist/v2/v2-adapter.d.ts
CHANGED
|
@@ -120,6 +120,23 @@ type V2ToolExecuteAfterEvent = {
|
|
|
120
120
|
error?: unknown;
|
|
121
121
|
message?: unknown;
|
|
122
122
|
};
|
|
123
|
+
/**
|
|
124
|
+
* Join the text parts of a tool result's `content`.
|
|
125
|
+
*
|
|
126
|
+
* V2 delivers a completed tool result as an array of content parts. The
|
|
127
|
+
* shell tool uses one part per output line plus a separate part for the
|
|
128
|
+
* `Exited with code N` marker, so every part matters.
|
|
129
|
+
*/
|
|
130
|
+
export declare function extractContentText(content: unknown): string | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* Extract the raw text from a tool result's structured `output`.
|
|
133
|
+
*
|
|
134
|
+
* The shell tool reports `{ exit, truncated, output, status }` — the `output`
|
|
135
|
+
* field is the command's real stdout+stderr. Returning the whole object
|
|
136
|
+
* would hand the failure detector a JSON blob in which the command's text is
|
|
137
|
+
* escaped, which defeats every text rule.
|
|
138
|
+
*/
|
|
139
|
+
export declare function extractStructuredOutput(output: unknown): string | undefined;
|
|
123
140
|
/** V2 `prompt` hook event. */
|
|
124
141
|
type V2PromptHookEvent = {
|
|
125
142
|
sessionID: string;
|
package/dist/v2/v2-adapter.js
CHANGED
|
@@ -32,6 +32,42 @@
|
|
|
32
32
|
*/
|
|
33
33
|
import { findConfigFile, loadConfig } from "../core/config.js";
|
|
34
34
|
import { ragPlugin, RAG_TOOL_NAMES } from "../plugin.js";
|
|
35
|
+
/**
|
|
36
|
+
* Join the text parts of a tool result's `content`.
|
|
37
|
+
*
|
|
38
|
+
* V2 delivers a completed tool result as an array of content parts. The
|
|
39
|
+
* shell tool uses one part per output line plus a separate part for the
|
|
40
|
+
* `Exited with code N` marker, so every part matters.
|
|
41
|
+
*/
|
|
42
|
+
export function extractContentText(content) {
|
|
43
|
+
if (typeof content === "string")
|
|
44
|
+
return content;
|
|
45
|
+
if (!Array.isArray(content))
|
|
46
|
+
return undefined;
|
|
47
|
+
const texts = [];
|
|
48
|
+
for (const part of content) {
|
|
49
|
+
if (part && typeof part === "object") {
|
|
50
|
+
const text = part.text;
|
|
51
|
+
if (typeof text === "string" && text.length > 0)
|
|
52
|
+
texts.push(text);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return texts.length > 0 ? texts.join("\n") : undefined;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Extract the raw text from a tool result's structured `output`.
|
|
59
|
+
*
|
|
60
|
+
* The shell tool reports `{ exit, truncated, output, status }` — the `output`
|
|
61
|
+
* field is the command's real stdout+stderr. Returning the whole object
|
|
62
|
+
* would hand the failure detector a JSON blob in which the command's text is
|
|
63
|
+
* escaped, which defeats every text rule.
|
|
64
|
+
*/
|
|
65
|
+
export function extractStructuredOutput(output) {
|
|
66
|
+
if (!output || typeof output !== "object")
|
|
67
|
+
return undefined;
|
|
68
|
+
const text = output.output;
|
|
69
|
+
return typeof text === "string" && text.length > 0 ? text : undefined;
|
|
70
|
+
}
|
|
35
71
|
/**
|
|
36
72
|
* Extract a human-readable error string from a V2 `execute.after` error event.
|
|
37
73
|
* The exact error payload differs across OpenCode versions; probe the known
|
|
@@ -291,19 +327,30 @@ export async function registerRagPluginV2(ctx) {
|
|
|
291
327
|
try {
|
|
292
328
|
const isError = event.status === "error";
|
|
293
329
|
const result = event.result;
|
|
330
|
+
// The COMPLETED branch carries its text as an ARRAY of content parts
|
|
331
|
+
// (measured live 2026-10-21: the shell tool returns one text part
|
|
332
|
+
// per line plus a separate `Exited with code N` part). Reading only
|
|
333
|
+
// `content` as a string fell through to `JSON.stringify(result.output)`
|
|
334
|
+
// — a JSON blob that does NOT contain the failure marker, so nothing
|
|
335
|
+
// downstream could see it. Join the text parts instead.
|
|
294
336
|
const outputText = isError
|
|
295
337
|
? extractToolErrorText(event)
|
|
296
|
-
:
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
? JSON.stringify(result.output)
|
|
300
|
-
: "";
|
|
338
|
+
: extractContentText(result?.content) ??
|
|
339
|
+
extractStructuredOutput(result?.output) ??
|
|
340
|
+
(result?.output !== undefined ? JSON.stringify(result.output) : "");
|
|
301
341
|
await toolAfterHook({
|
|
302
342
|
sessionID: event.sessionID,
|
|
303
343
|
tool: event.tool,
|
|
304
344
|
callID: event.id,
|
|
305
345
|
status: isError ? "error" : "completed",
|
|
306
|
-
}, {
|
|
346
|
+
}, {
|
|
347
|
+
output: outputText,
|
|
348
|
+
// The metadata carries the structured exit code
|
|
349
|
+
// (`{ status, truncated, exit }` for the shell tool) — the most
|
|
350
|
+
// reliable failure signal there is, and it is not text.
|
|
351
|
+
metadata: result?.metadata,
|
|
352
|
+
error: isError ? outputText : undefined,
|
|
353
|
+
});
|
|
307
354
|
}
|
|
308
355
|
catch {
|
|
309
356
|
// Non-critical — must never throw
|