opencode-rag-plugin 2.3.1 → 2.4.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/ReadMe.md +71 -8
- package/dist/chunker/skeleton.js +1 -1
- package/dist/cli/commands/decide.d.ts +25 -0
- package/dist/cli/commands/decide.js +160 -0
- package/dist/cli/commands/eval.d.ts +23 -0
- package/dist/cli/commands/eval.js +331 -1
- package/dist/cli/commands/index-command.js +28 -10
- package/dist/cli/commands/index.d.ts +2 -1
- package/dist/cli/commands/index.js +2 -1
- package/dist/cli/commands/init-helpers.d.ts +16 -1
- package/dist/cli/commands/init-helpers.js +84 -2
- package/dist/cli/commands/init.js +29 -4
- package/dist/cli/commands/status.js +14 -8
- package/dist/cli/format.d.ts +50 -0
- package/dist/cli/format.js +122 -0
- package/dist/cli/index.js +4 -1
- package/dist/cli/types.d.ts +2 -0
- package/dist/core/bootstrap.js +1 -0
- package/dist/core/config.d.ts +47 -0
- package/dist/core/config.js +34 -1
- package/dist/core/interfaces.d.ts +69 -0
- package/dist/decision/factory.d.ts +17 -0
- package/dist/decision/factory.js +17 -0
- package/dist/decision/format.d.ts +14 -0
- package/dist/decision/format.js +53 -0
- package/dist/decision/systemone.d.ts +76 -0
- package/dist/decision/systemone.js +234 -0
- package/dist/decision/validate.d.ts +26 -0
- package/dist/decision/validate.js +74 -0
- package/dist/eval/decide-calibration.d.ts +112 -0
- package/dist/eval/decide-calibration.js +185 -0
- package/dist/eval/golden-gate.d.ts +65 -0
- package/dist/eval/golden-gate.js +61 -0
- package/dist/eval/golden-set.d.ts +81 -0
- package/dist/eval/golden-set.js +155 -0
- package/dist/eval/rerank-eval.js +10 -125
- package/dist/index.d.ts +6 -2
- package/dist/index.js +4 -0
- package/dist/indexer/pipeline.d.ts +0 -10
- package/dist/indexer/pipeline.js +1 -0
- package/dist/mcp/handlers.d.ts +17 -1
- package/dist/mcp/handlers.js +30 -0
- package/dist/mcp/server.d.ts +9 -1
- package/dist/mcp/server.js +47 -3
- package/dist/opencode/system-guidance.d.ts +11 -0
- package/dist/opencode/system-guidance.js +53 -0
- package/dist/opencode/tools.d.ts +24 -1
- package/dist/opencode/tools.js +101 -0
- package/dist/plugin.js +21 -3
- package/dist/quirks/quirk-store.d.ts +2 -0
- package/dist/quirks/quirk-store.js +33 -4
- package/dist/tui.js +21 -2
- package/dist/v2/v2-adapter.d.ts +20 -0
- package/dist/v2/v2-adapter.js +36 -8
- package/dist/vectorstore/lancedb.js +54 -5
- package/dist/watcher.d.ts +26 -1
- package/dist/watcher.js +71 -9
- package/dist/web/ui/assets/index-CWcp0jNf.css +2 -0
- package/dist/web/ui/index.html +2 -2
- package/package.json +5 -2
- package/dist/web/ui/assets/index-Dp009QCQ.css +0 -1
- /package/dist/web/ui/assets/{index-C0QXKA-b.js → index-DbXFrn53.js} +0 -0
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import os from "node:os";
|
|
9
9
|
import fs from "node:fs";
|
|
10
|
-
import { c, resolveCliContext, logCliError, logCliInfo, formatTimestamp } from "../format.js";
|
|
10
|
+
import { c, resolveCliContext, logCliError, logCliInfo, formatTimestamp, formatRelativeAge } from "../format.js";
|
|
11
11
|
import { getIndexStatusSummary } from "../../indexer.js";
|
|
12
|
+
import { deriveWatcherHealth } from "../../watcher.js";
|
|
12
13
|
import { getPackageMetadata } from "../helpers.js";
|
|
13
14
|
import { checkForUpdate } from "../../core/version-check.js";
|
|
14
15
|
/**
|
|
@@ -107,19 +108,21 @@ export function registerStatusCommand(program) {
|
|
|
107
108
|
// Read watcher status from the background auto-indexer
|
|
108
109
|
const watcherStatusPath = path.join(storePath, "watcher-status.json");
|
|
109
110
|
let watchModeDisplay;
|
|
111
|
+
let watcherWarning;
|
|
110
112
|
if (fs.existsSync(watcherStatusPath)) {
|
|
111
113
|
try {
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
if (
|
|
115
|
-
const
|
|
116
|
-
watchModeDisplay = ws.running
|
|
117
|
-
? c.enabled("active") + c.dim(" (last run: " + lastRun + ")")
|
|
118
|
-
: c.enabled("on") + c.dim(" (last run: " + lastRun + ")");
|
|
114
|
+
const ws = JSON.parse(fs.readFileSync(watcherStatusPath, "utf-8"));
|
|
115
|
+
const lastRun = ws.lastSuccessAt ?? ws.lastRunAt;
|
|
116
|
+
if (lastRun) {
|
|
117
|
+
const runLabel = ws.lastSuccessAt ? "last successful run" : "last run";
|
|
118
|
+
watchModeDisplay = `${ws.running ? c.enabled("active") : c.enabled("on")} ${c.dim(`(${runLabel}: ${formatTimestamp(lastRun)}, ${formatRelativeAge(lastRun)})`)}`;
|
|
119
119
|
}
|
|
120
120
|
else {
|
|
121
121
|
watchModeDisplay = c.enabled("on");
|
|
122
122
|
}
|
|
123
|
+
const health = deriveWatcherHealth(ws);
|
|
124
|
+
if (health.stale)
|
|
125
|
+
watcherWarning = health.reason;
|
|
123
126
|
}
|
|
124
127
|
catch {
|
|
125
128
|
watchModeDisplay = c.enabled("on") + c.dim(" (status unknown)");
|
|
@@ -132,6 +135,9 @@ export function registerStatusCommand(program) {
|
|
|
132
135
|
watchModeDisplay = c.dim("off");
|
|
133
136
|
}
|
|
134
137
|
logCliInfo(logFilePath, "status", `${c.label("Watch mode:")} ${watchModeDisplay}`);
|
|
138
|
+
if (watcherWarning) {
|
|
139
|
+
logCliInfo(logFilePath, "status", `${c.label("Watcher health:")} ${c.warn(`stale — ${watcherWarning}`)} ${c.dim("(run 'opencode-rag index' or check .opencode/opencode-rag.log)")}`);
|
|
140
|
+
}
|
|
135
141
|
const kiCount = config.retrieval.hybridSearch?.enabled
|
|
136
142
|
? keywordIndex?.count() ?? 0
|
|
137
143
|
: 0;
|
package/dist/cli/format.d.ts
CHANGED
|
@@ -95,6 +95,56 @@ export declare function cleanupContext(ctx: RagContext): Promise<void>;
|
|
|
95
95
|
* @returns A localized date string, or `"never"` if the timestamp is falsy.
|
|
96
96
|
*/
|
|
97
97
|
export declare function formatTimestamp(timestamp?: number): string;
|
|
98
|
+
/**
|
|
99
|
+
* Format a Unix timestamp as a compact "time since" label (e.g. `"5m ago"`).
|
|
100
|
+
*
|
|
101
|
+
* @param timestamp - Unix timestamp in milliseconds, or `undefined` for "never".
|
|
102
|
+
* @param now - Reference time in ms (defaults to `Date.now()`, injectable for tests).
|
|
103
|
+
* @returns A human-readable age such as `"just now"`, `"2h ago"`, or `"3d ago"`.
|
|
104
|
+
*/
|
|
105
|
+
export declare function formatRelativeAge(timestamp?: number, now?: number): string;
|
|
106
|
+
/**
|
|
107
|
+
* Overall outcome of an index pass — drives the CLI exit code and the machine-readable
|
|
108
|
+
* summary. `"ok"` = everything that was found got indexed; `"partial"` = the pass did real
|
|
109
|
+
* work but some files/chunks failed and will be retried; `"incomplete"` = nothing usable
|
|
110
|
+
* was stored (embedding provider down or zero chunks).
|
|
111
|
+
*/
|
|
112
|
+
export type IndexRunStatus = "ok" | "partial" | "incomplete";
|
|
113
|
+
/**
|
|
114
|
+
* Classify an index pass from its stats. Mirrors the messages printed by the `index`
|
|
115
|
+
* command and the exit-code mapping: 0 = ok, 3 = partial, 1 = incomplete/interrupted.
|
|
116
|
+
*
|
|
117
|
+
* @param stats - Statistics from a single indexing pass.
|
|
118
|
+
* @returns The pass status.
|
|
119
|
+
*/
|
|
120
|
+
export declare function classifyIndexRun(stats: IndexRunStats): IndexRunStatus;
|
|
121
|
+
/**
|
|
122
|
+
* Build short human-readable descriptions of a partial pass's problems.
|
|
123
|
+
*
|
|
124
|
+
* @param stats - Statistics from a single indexing pass.
|
|
125
|
+
* @returns One string per problem category; empty when the pass was clean.
|
|
126
|
+
*/
|
|
127
|
+
export declare function describeIndexProblems(stats: IndexRunStats): string[];
|
|
128
|
+
/** Options for {@link buildIndexSummaryJson}. */
|
|
129
|
+
export interface IndexSummaryJsonOptions {
|
|
130
|
+
/** Workspace root used to relativize extraction error paths. */
|
|
131
|
+
cwd: string;
|
|
132
|
+
/** Pass start time (ms since epoch). */
|
|
133
|
+
startedAt: number;
|
|
134
|
+
/** Pass duration in milliseconds. */
|
|
135
|
+
durationMs: number;
|
|
136
|
+
/** True when the run was interrupted (Ctrl+C) — reported instead of the pass status. */
|
|
137
|
+
interrupted?: boolean;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Build the machine-readable `index --json` summary. The CLI prints this object as a
|
|
141
|
+
* single line of JSON so agents can parse the outcome without scraping log text.
|
|
142
|
+
*
|
|
143
|
+
* @param stats - Statistics from a single indexing pass.
|
|
144
|
+
* @param opts - Workspace, timing, and interrupt information.
|
|
145
|
+
* @returns A plain JSON-serializable object (schema version 1).
|
|
146
|
+
*/
|
|
147
|
+
export declare function buildIndexSummaryJson(stats: IndexRunStats, opts: IndexSummaryJsonOptions): Record<string, unknown>;
|
|
98
148
|
/**
|
|
99
149
|
* Print an indexing pass summary to stdout.
|
|
100
150
|
*
|
package/dist/cli/format.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* and result formatting functions shared across all CLI command modules.
|
|
7
7
|
*/
|
|
8
8
|
import pc from "picocolors";
|
|
9
|
+
import path from "node:path";
|
|
9
10
|
import { resolveRagContext } from "../core/bootstrap.js";
|
|
10
11
|
import { destroyAllPooledConnections } from "../embedder/http.js";
|
|
11
12
|
import { appendDebugLog } from "../core/fileLogger.js";
|
|
@@ -139,6 +140,118 @@ export function formatTimestamp(timestamp) {
|
|
|
139
140
|
return "never";
|
|
140
141
|
return new Date(timestamp).toLocaleString();
|
|
141
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Format a Unix timestamp as a compact "time since" label (e.g. `"5m ago"`).
|
|
145
|
+
*
|
|
146
|
+
* @param timestamp - Unix timestamp in milliseconds, or `undefined` for "never".
|
|
147
|
+
* @param now - Reference time in ms (defaults to `Date.now()`, injectable for tests).
|
|
148
|
+
* @returns A human-readable age such as `"just now"`, `"2h ago"`, or `"3d ago"`.
|
|
149
|
+
*/
|
|
150
|
+
export function formatRelativeAge(timestamp, now = Date.now()) {
|
|
151
|
+
if (!timestamp)
|
|
152
|
+
return "never";
|
|
153
|
+
const diffMinutes = Math.floor(Math.max(0, now - timestamp) / 60_000);
|
|
154
|
+
if (diffMinutes < 1)
|
|
155
|
+
return "just now";
|
|
156
|
+
if (diffMinutes < 60)
|
|
157
|
+
return `${diffMinutes}m ago`;
|
|
158
|
+
const diffHours = Math.floor(diffMinutes / 60);
|
|
159
|
+
if (diffHours < 48)
|
|
160
|
+
return `${diffHours}h ago`;
|
|
161
|
+
return `${Math.floor(diffHours / 24)}d ago`;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Classify an index pass from its stats. Mirrors the messages printed by the `index`
|
|
165
|
+
* command and the exit-code mapping: 0 = ok, 3 = partial, 1 = incomplete/interrupted.
|
|
166
|
+
*
|
|
167
|
+
* @param stats - Statistics from a single indexing pass.
|
|
168
|
+
* @returns The pass status.
|
|
169
|
+
*/
|
|
170
|
+
export function classifyIndexRun(stats) {
|
|
171
|
+
if (stats.embeddingUnavailable)
|
|
172
|
+
return "incomplete";
|
|
173
|
+
if (stats.totalChunks === 0 && stats.newFiles + stats.modifiedFiles > 0)
|
|
174
|
+
return "incomplete";
|
|
175
|
+
if (stats.extractionFailures > 0 || stats.descriptionFailedFiles > 0 || stats.embeddingFailures > 0) {
|
|
176
|
+
return "partial";
|
|
177
|
+
}
|
|
178
|
+
return "ok";
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Build short human-readable descriptions of a partial pass's problems.
|
|
182
|
+
*
|
|
183
|
+
* @param stats - Statistics from a single indexing pass.
|
|
184
|
+
* @returns One string per problem category; empty when the pass was clean.
|
|
185
|
+
*/
|
|
186
|
+
export function describeIndexProblems(stats) {
|
|
187
|
+
const parts = [];
|
|
188
|
+
if (stats.extractionFailures > 0)
|
|
189
|
+
parts.push(`${stats.extractionFailures} file(s) failed content extraction`);
|
|
190
|
+
if (stats.descriptionFailedFiles > 0)
|
|
191
|
+
parts.push(`${stats.descriptionFailedFiles} file(s) had description failures`);
|
|
192
|
+
if (stats.embeddingFailures > 0)
|
|
193
|
+
parts.push(`${stats.embeddingFailures} chunk(s) had no vectors`);
|
|
194
|
+
return parts;
|
|
195
|
+
}
|
|
196
|
+
/** Extraction error paths shown in the human summary before truncating. */
|
|
197
|
+
const MAX_SHOWN_EXTRACTION_ERRORS = 5;
|
|
198
|
+
/** Extraction errors included in the JSON summary before truncating. */
|
|
199
|
+
const MAX_JSON_EXTRACTION_ERRORS = 20;
|
|
200
|
+
/** Longest error text rendered before truncation. */
|
|
201
|
+
const MAX_ERROR_CHARS = 160;
|
|
202
|
+
/** Collapse whitespace and truncate an error message for one-line display. */
|
|
203
|
+
function truncateError(error) {
|
|
204
|
+
const oneLine = error.replace(/\s+/g, " ").trim();
|
|
205
|
+
return oneLine.length > MAX_ERROR_CHARS ? `${oneLine.slice(0, MAX_ERROR_CHARS - 1)}…` : oneLine;
|
|
206
|
+
}
|
|
207
|
+
/** Make a path workspace-relative when it is inside the workspace; keep it otherwise. */
|
|
208
|
+
function toWorkspaceRelative(cwd, filePath) {
|
|
209
|
+
try {
|
|
210
|
+
const rel = path.relative(cwd, filePath);
|
|
211
|
+
return rel && !rel.startsWith("..") && !path.isAbsolute(rel) ? rel : filePath;
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
return filePath;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Build the machine-readable `index --json` summary. The CLI prints this object as a
|
|
219
|
+
* single line of JSON so agents can parse the outcome without scraping log text.
|
|
220
|
+
*
|
|
221
|
+
* @param stats - Statistics from a single indexing pass.
|
|
222
|
+
* @param opts - Workspace, timing, and interrupt information.
|
|
223
|
+
* @returns A plain JSON-serializable object (schema version 1).
|
|
224
|
+
*/
|
|
225
|
+
export function buildIndexSummaryJson(stats, opts) {
|
|
226
|
+
const extractionErrors = stats.extractionErrors
|
|
227
|
+
.slice(0, MAX_JSON_EXTRACTION_ERRORS)
|
|
228
|
+
.map((entry) => ({
|
|
229
|
+
file: toWorkspaceRelative(opts.cwd, entry.filePath),
|
|
230
|
+
error: truncateError(entry.error),
|
|
231
|
+
}));
|
|
232
|
+
return {
|
|
233
|
+
schema: 1,
|
|
234
|
+
status: opts.interrupted ? "interrupted" : classifyIndexRun(stats),
|
|
235
|
+
startedAt: new Date(opts.startedAt).toISOString(),
|
|
236
|
+
durationMs: opts.durationMs,
|
|
237
|
+
totalFiles: stats.totalFiles,
|
|
238
|
+
newFiles: stats.newFiles,
|
|
239
|
+
modifiedFiles: stats.modifiedFiles,
|
|
240
|
+
unchangedFiles: stats.unchangedFiles,
|
|
241
|
+
deletedFiles: stats.deletedFiles,
|
|
242
|
+
removedFiles: stats.removedFiles,
|
|
243
|
+
skippedEmptyFiles: stats.skippedEmptyFiles,
|
|
244
|
+
skippedSmallFiles: stats.skippedSmallFiles,
|
|
245
|
+
totalChunks: stats.totalChunks,
|
|
246
|
+
finalCount: stats.finalCount,
|
|
247
|
+
extractionFailures: stats.extractionFailures,
|
|
248
|
+
descriptionFailedFiles: stats.descriptionFailedFiles,
|
|
249
|
+
embeddingFailures: stats.embeddingFailures,
|
|
250
|
+
embeddingUnavailable: stats.embeddingUnavailable,
|
|
251
|
+
extractionErrors,
|
|
252
|
+
extractionErrorsTruncated: stats.extractionErrors.length > extractionErrors.length,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
142
255
|
/**
|
|
143
256
|
* Print an indexing pass summary to stdout.
|
|
144
257
|
*
|
|
@@ -153,6 +266,15 @@ export function logIndexSummary(logFilePath, stats) {
|
|
|
153
266
|
logCliInfo(logFilePath, "index", ` ${c.label("Removed:")} ${c.num(stats.removedFiles)}`);
|
|
154
267
|
logCliInfo(logFilePath, "index", ` ${c.label("Empty skipped:")} ${c.num(stats.skippedEmptyFiles)}`);
|
|
155
268
|
logCliInfo(logFilePath, "index", ` ${c.label("Small skipped:")} ${c.num(stats.skippedSmallFiles)}`);
|
|
269
|
+
if (stats.extractionFailures > 0) {
|
|
270
|
+
logCliInfo(logFilePath, "index", ` ${c.label("Extract failed:")} ${c.num(stats.extractionFailures)} file(s)`);
|
|
271
|
+
for (const entry of stats.extractionErrors.slice(0, MAX_SHOWN_EXTRACTION_ERRORS)) {
|
|
272
|
+
logCliInfo(logFilePath, "index", ` ${c.file(entry.filePath)} — ${c.dim(truncateError(entry.error))}`);
|
|
273
|
+
}
|
|
274
|
+
if (stats.extractionErrors.length > MAX_SHOWN_EXTRACTION_ERRORS) {
|
|
275
|
+
logCliInfo(logFilePath, "index", ` ${c.dim(`… and ${stats.extractionErrors.length - MAX_SHOWN_EXTRACTION_ERRORS} more (see log)`)}`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
156
278
|
if (stats.descriptionFailedFiles > 0) {
|
|
157
279
|
logCliInfo(logFilePath, "index", ` ${c.label("Desc failed:")} ${c.num(stats.descriptionFailedFiles)}`);
|
|
158
280
|
}
|
package/dist/cli/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { realpathSync } from "node:fs";
|
|
|
15
15
|
import { basename, dirname } from "node:path";
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
17
17
|
import { getPackageMetadata } from "./helpers.js";
|
|
18
|
-
import { registerIndexCommand, registerQueryCommand, registerClearCommand, registerStatusCommand, registerListCommand, registerShowCommand, registerDumpCommand, registerInitCommand, registerUiCommand, registerMcpCommand, registerSetupCommand, registerUpdateCommand, registerEvalSessionsCommand, registerEvalAnalyzeCommand, registerEvalCompareCommand, registerDescribeImageCommand, registerQuirkCommand, } from "./commands/index.js";
|
|
18
|
+
import { registerIndexCommand, registerQueryCommand, registerClearCommand, registerStatusCommand, registerListCommand, registerShowCommand, registerDumpCommand, registerInitCommand, registerUiCommand, registerMcpCommand, registerSetupCommand, registerUpdateCommand, registerEvalSessionsCommand, registerEvalAnalyzeCommand, registerEvalCompareCommand, registerEvalGateCommand, registerEvalDecideCommand, registerDescribeImageCommand, registerDecideCommand, registerQuirkCommand, } from "./commands/index.js";
|
|
19
19
|
/**
|
|
20
20
|
* The top-level Commander program instance that defines the `opencode-rag` CLI.
|
|
21
21
|
*
|
|
@@ -37,6 +37,7 @@ registerListCommand(program);
|
|
|
37
37
|
registerShowCommand(program);
|
|
38
38
|
registerDumpCommand(program);
|
|
39
39
|
registerDescribeImageCommand(program);
|
|
40
|
+
registerDecideCommand(program);
|
|
40
41
|
registerUiCommand(program);
|
|
41
42
|
registerMcpCommand(program);
|
|
42
43
|
registerSetupCommand(program);
|
|
@@ -44,6 +45,8 @@ registerUpdateCommand(program);
|
|
|
44
45
|
registerEvalSessionsCommand(program);
|
|
45
46
|
registerEvalAnalyzeCommand(program);
|
|
46
47
|
registerEvalCompareCommand(program);
|
|
48
|
+
registerEvalGateCommand(program);
|
|
49
|
+
registerEvalDecideCommand(program);
|
|
47
50
|
registerInitCommand(program);
|
|
48
51
|
registerQuirkCommand(program);
|
|
49
52
|
// ── Auto-run detection ──────────────────────────────────────────
|
package/dist/cli/types.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export interface CliOptions {
|
|
|
20
20
|
explain?: boolean;
|
|
21
21
|
/** Skip confirmation prompts for destructive operations. */
|
|
22
22
|
yes?: boolean;
|
|
23
|
+
/** Print a machine-readable JSON summary as the last line of the `index` command. */
|
|
24
|
+
json?: boolean;
|
|
23
25
|
/** Optional system prompt to steer an image description toward specific features. */
|
|
24
26
|
systemPrompt?: string;
|
|
25
27
|
}
|
package/dist/core/bootstrap.js
CHANGED
|
@@ -109,6 +109,7 @@ export async function resolveRagContext(opts = {}) {
|
|
|
109
109
|
// Surface only store-level drift (the split-brain symptom). Keyword-index
|
|
110
110
|
// healing is routine (addQuirk never persisted the index) and stays silent.
|
|
111
111
|
console.warn(`[bootstrap] Quirk reconcile: restored ${rec.restoredToStore} to store, ` +
|
|
112
|
+
`deduplicated ${rec.deduplicated}, ` +
|
|
112
113
|
`removed ${rec.removedOrphans} orphans (keyword index: +${rec.addedToKeywordIndex})`);
|
|
113
114
|
}
|
|
114
115
|
}
|
package/dist/core/config.d.ts
CHANGED
|
@@ -154,6 +154,51 @@ export interface ImageDescriptionConfig {
|
|
|
154
154
|
*/
|
|
155
155
|
onDemand?: ImageDescriptionOnDemandConfig;
|
|
156
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Configuration for decision-model (tev1) calls via Ollama's
|
|
159
|
+
* `/v1/systemone` endpoint — classification, routing, policy checks, and
|
|
160
|
+
* rubrics.
|
|
161
|
+
*/
|
|
162
|
+
export interface DecisionConfig {
|
|
163
|
+
/**
|
|
164
|
+
* Whether the `make_decision` tool is available. Default false: tev1
|
|
165
|
+
* requires Ollama >= 0.35 and an explicitly pulled model (`ollama pull tev1`).
|
|
166
|
+
*/
|
|
167
|
+
enabled: boolean;
|
|
168
|
+
/** Decision provider name. Only "ollama" is supported for now. */
|
|
169
|
+
provider: string;
|
|
170
|
+
/**
|
|
171
|
+
* Base URL of the Ollama server. Both root URLs (`http://127.0.0.1:11434`)
|
|
172
|
+
* and the `/api`-suffixed convention used by the other sections are
|
|
173
|
+
* accepted — `/api` is stripped because decision models are served at
|
|
174
|
+
* `/v1/systemone`.
|
|
175
|
+
*/
|
|
176
|
+
baseUrl: string;
|
|
177
|
+
/** Decision model name (`tev1`/`tev1:4b` or `tev1:0.8b`). */
|
|
178
|
+
model: string;
|
|
179
|
+
/** Request timeout in milliseconds. The first call may load the model. */
|
|
180
|
+
timeoutMs: number;
|
|
181
|
+
/** Ollama keep_alive value (e.g. "30m", "-1" for keep-in-memory). */
|
|
182
|
+
keepAlive?: string;
|
|
183
|
+
/** Proxy configuration. */
|
|
184
|
+
proxy?: ProxyConfig;
|
|
185
|
+
/**
|
|
186
|
+
* When enabled, agent guidance instructs the agent to route choices through
|
|
187
|
+
* `make_decision` before asking the user (proceed on a confident answer;
|
|
188
|
+
* ask only when the model is undecided or the choice is preference-based).
|
|
189
|
+
* Default false — asking the user stays the default behavior.
|
|
190
|
+
*/
|
|
191
|
+
routeBeforeAsking?: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Maximum characters accepted for `state`. The decision context is small
|
|
194
|
+
* (~2k tokens), so oversized states are rejected instead of truncated.
|
|
195
|
+
*/
|
|
196
|
+
maxStateChars?: number;
|
|
197
|
+
/** Maximum retry attempts on retryable failures. */
|
|
198
|
+
retryMax?: number;
|
|
199
|
+
/** Base delay in ms between retries (exponential backoff). */
|
|
200
|
+
retryBaseDelayMs?: number;
|
|
201
|
+
}
|
|
157
202
|
export interface UiConfig {
|
|
158
203
|
/** HTTP port for the UI server. */
|
|
159
204
|
port: number;
|
|
@@ -521,6 +566,8 @@ export interface RagConfig {
|
|
|
521
566
|
description?: DescriptionConfig;
|
|
522
567
|
/** Vision-model-based image description config. */
|
|
523
568
|
imageDescription?: ImageDescriptionConfig;
|
|
569
|
+
/** Decision-model (tev1) config for the `make_decision` tool. */
|
|
570
|
+
decision?: DecisionConfig;
|
|
524
571
|
/** Automated documentation mode config. */
|
|
525
572
|
documentationMode?: DocumentationModeConfig;
|
|
526
573
|
/** Wiki mode config that instructs the AI agent to maintain a persistent knowledge wiki. */
|
package/dist/core/config.js
CHANGED
|
@@ -182,6 +182,18 @@ export const DEFAULT_CONFIG = {
|
|
|
182
182
|
numCtx: 2048,
|
|
183
183
|
resizeMaxDimension: 1024,
|
|
184
184
|
},
|
|
185
|
+
decision: {
|
|
186
|
+
enabled: false,
|
|
187
|
+
provider: "ollama",
|
|
188
|
+
baseUrl: "http://127.0.0.1:11434/api",
|
|
189
|
+
model: "tev1:4b",
|
|
190
|
+
timeoutMs: 120000,
|
|
191
|
+
keepAlive: "30m",
|
|
192
|
+
maxStateChars: 8000,
|
|
193
|
+
routeBeforeAsking: false,
|
|
194
|
+
retryMax: 2,
|
|
195
|
+
retryBaseDelayMs: 500,
|
|
196
|
+
},
|
|
185
197
|
description: {
|
|
186
198
|
enabled: true,
|
|
187
199
|
provider: "ollama",
|
|
@@ -341,7 +353,7 @@ export function validateConfig(config) {
|
|
|
341
353
|
const KNOWN_TOP_KEYS = new Set([
|
|
342
354
|
"embedding", "indexing", "vectorStore", "retrieval", "reranking",
|
|
343
355
|
"openCode", "chunkers", "chunking", "description",
|
|
344
|
-
"imageDescription", "documentationMode", "wikiMode", "mcp", "autoUpdate", "memory", "ui", "tui", "logging",
|
|
356
|
+
"imageDescription", "decision", "documentationMode", "wikiMode", "mcp", "autoUpdate", "memory", "ui", "tui", "logging",
|
|
345
357
|
]);
|
|
346
358
|
const topKeys = new Set(Object.keys(config));
|
|
347
359
|
for (const key of topKeys) {
|
|
@@ -508,6 +520,23 @@ export function validateConfig(config) {
|
|
|
508
520
|
warnings.push("imageDescription.onDemand.timeoutMs must be > 0");
|
|
509
521
|
}
|
|
510
522
|
}
|
|
523
|
+
if (config.decision) {
|
|
524
|
+
if (config.decision.provider !== "ollama") {
|
|
525
|
+
warnings.push(`decision.provider "${config.decision.provider}" is not supported yet — only "ollama" (tev1 via /v1/systemone)`);
|
|
526
|
+
}
|
|
527
|
+
if (config.decision.timeoutMs != null && config.decision.timeoutMs <= 0) {
|
|
528
|
+
warnings.push("decision.timeoutMs must be > 0");
|
|
529
|
+
}
|
|
530
|
+
if (config.decision.maxStateChars != null && config.decision.maxStateChars <= 0) {
|
|
531
|
+
warnings.push("decision.maxStateChars must be > 0");
|
|
532
|
+
}
|
|
533
|
+
try {
|
|
534
|
+
new URL(config.decision.baseUrl);
|
|
535
|
+
}
|
|
536
|
+
catch {
|
|
537
|
+
warnings.push(`decision.baseUrl "${config.decision.baseUrl}" is not a valid URL`);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
511
540
|
if (config.reranking?.enabled) {
|
|
512
541
|
const rr = config.reranking;
|
|
513
542
|
if (!rr.baseUrl)
|
|
@@ -632,6 +661,10 @@ export function loadConfig(filePath, validate = true) {
|
|
|
632
661
|
...DEFAULT_CONFIG.imageDescription,
|
|
633
662
|
...(safeObj(parsed.imageDescription) ?? {}),
|
|
634
663
|
},
|
|
664
|
+
decision: {
|
|
665
|
+
...DEFAULT_CONFIG.decision,
|
|
666
|
+
...(safeObj(parsed.decision) ?? {}),
|
|
667
|
+
},
|
|
635
668
|
documentationMode: {
|
|
636
669
|
...DEFAULT_CONFIG.documentationMode,
|
|
637
670
|
...(safeObj(parsed.documentationMode) ?? {}),
|
|
@@ -63,6 +63,75 @@ export interface DescriptionProvider {
|
|
|
63
63
|
timeoutMs?: number;
|
|
64
64
|
}): Promise<string>;
|
|
65
65
|
}
|
|
66
|
+
/** Question types supported by the decision model. */
|
|
67
|
+
export type DecisionQuestionType = "choice" | "noul" | "score";
|
|
68
|
+
/**
|
|
69
|
+
* A single question asked of the decision model.
|
|
70
|
+
*
|
|
71
|
+
* - `choice`: `criteria` maps option name → description (2-24 options);
|
|
72
|
+
* add a `none` option when no listed option may fit.
|
|
73
|
+
* - `noul`: true/false probability; optional `criteria` describes each side.
|
|
74
|
+
* - `score`: `criteria` is an ordered array of level descriptions, lowest first.
|
|
75
|
+
*/
|
|
76
|
+
export interface DecisionQuestion {
|
|
77
|
+
/** Unique name for the question; answers are keyed by it. */
|
|
78
|
+
id: string;
|
|
79
|
+
/** Question type. */
|
|
80
|
+
type: DecisionQuestionType;
|
|
81
|
+
/** Natural-language instruction describing what to decide. */
|
|
82
|
+
instructions: string;
|
|
83
|
+
/** Answer criteria — shape depends on `type` (see interface docs). */
|
|
84
|
+
criteria?: Record<string, string> | string[] | {
|
|
85
|
+
true?: string;
|
|
86
|
+
false?: string;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** The model's answer to a single question. */
|
|
90
|
+
export interface DecisionAnswer {
|
|
91
|
+
/** Question id this answer belongs to. */
|
|
92
|
+
id: string;
|
|
93
|
+
/** Question type this answer belongs to. */
|
|
94
|
+
type: DecisionQuestionType;
|
|
95
|
+
/** Chosen option for `choice` questions. */
|
|
96
|
+
choice?: string;
|
|
97
|
+
/** Probability that a `noul` question is true (0-1). */
|
|
98
|
+
noul?: number;
|
|
99
|
+
/** Probability-weighted level for `score` questions (0-based). */
|
|
100
|
+
score?: number;
|
|
101
|
+
/** Level labels for `score` answers, lowest first. */
|
|
102
|
+
legend?: string[];
|
|
103
|
+
/** Probability distribution over options (choice) or levels (score). */
|
|
104
|
+
probabilities?: Record<string, number> | number[];
|
|
105
|
+
/**
|
|
106
|
+
* How concentrated the probability mass is (0-1). This is NOT the chance
|
|
107
|
+
* the answer is correct — use it to detect an undecided model.
|
|
108
|
+
*/
|
|
109
|
+
confidence?: number;
|
|
110
|
+
}
|
|
111
|
+
/** Request payload for a decision-model call. */
|
|
112
|
+
export interface DecisionRequest {
|
|
113
|
+
/** Text (or JSON string) the questions are judged against. Keep it short. */
|
|
114
|
+
state: string;
|
|
115
|
+
/** 1-64 named questions. */
|
|
116
|
+
questions: DecisionQuestion[];
|
|
117
|
+
}
|
|
118
|
+
/** Result of a decision-model call. */
|
|
119
|
+
export interface DecisionResult {
|
|
120
|
+
/** One answer per requested question, in request order. */
|
|
121
|
+
answers: DecisionAnswer[];
|
|
122
|
+
/** Raw provider response, retained for diagnostics. */
|
|
123
|
+
raw?: unknown;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Answers classification/decision questions against a text using a decision
|
|
127
|
+
* model (tev1 via Ollama's `/v1/systemone`).
|
|
128
|
+
*/
|
|
129
|
+
export interface DecisionProvider {
|
|
130
|
+
/** Provider name (e.g. "ollama"). */
|
|
131
|
+
readonly name: string;
|
|
132
|
+
/** Run a decision request; one answer is returned per question. */
|
|
133
|
+
decide(request: DecisionRequest, abort?: AbortSignal): Promise<DecisionResult>;
|
|
134
|
+
}
|
|
66
135
|
/** Explains how a search result score was computed, including vector and keyword contributions. */
|
|
67
136
|
export interface SearchExplanation {
|
|
68
137
|
/** Breakdown of the fused score components. */
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Factory for decision-model providers.
|
|
3
|
+
*
|
|
4
|
+
* Only Ollama's `/v1/systemone` (tev1) is implemented for now; the factory
|
|
5
|
+
* keeps the provider name dispatch so future backends (e.g. TypeSafe/Jev
|
|
6
|
+
* hosted APIs) can be added without touching call sites.
|
|
7
|
+
*/
|
|
8
|
+
import type { DecisionProvider } from "../core/interfaces.js";
|
|
9
|
+
import type { DecisionConfig } from "../core/config.js";
|
|
10
|
+
/**
|
|
11
|
+
* Create a decision provider instance based on configuration.
|
|
12
|
+
*
|
|
13
|
+
* @param config - Decision configuration including provider, endpoint, and model.
|
|
14
|
+
* @returns An initialized {@link DecisionProvider} instance.
|
|
15
|
+
* @throws If `provider` is not `"ollama"` (not supported yet).
|
|
16
|
+
*/
|
|
17
|
+
export declare function createDecisionProvider(config: DecisionConfig): DecisionProvider;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { OllamaDecisionProvider } from "./systemone.js";
|
|
2
|
+
/**
|
|
3
|
+
* Create a decision provider instance based on configuration.
|
|
4
|
+
*
|
|
5
|
+
* @param config - Decision configuration including provider, endpoint, and model.
|
|
6
|
+
* @returns An initialized {@link DecisionProvider} instance.
|
|
7
|
+
* @throws If `provider` is not `"ollama"` (not supported yet).
|
|
8
|
+
*/
|
|
9
|
+
export function createDecisionProvider(config) {
|
|
10
|
+
const provider = (config.provider || "ollama").toLowerCase();
|
|
11
|
+
if (provider === "ollama") {
|
|
12
|
+
return new OllamaDecisionProvider(config);
|
|
13
|
+
}
|
|
14
|
+
throw new Error(`Decision provider "${config.provider}" is not supported yet — only "ollama" ` +
|
|
15
|
+
"(tev1 via /v1/systemone) is implemented.");
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Markdown formatting for decision answers, shared by the
|
|
3
|
+
* OpenCode plugin tool, the MCP handler, and the CLI command.
|
|
4
|
+
*/
|
|
5
|
+
import type { DecisionAnswer } from "../core/interfaces.js";
|
|
6
|
+
/** Optional provenance header fields. */
|
|
7
|
+
export interface DecisionFormatOptions {
|
|
8
|
+
/** Provider name (e.g. "ollama"). */
|
|
9
|
+
provider?: string;
|
|
10
|
+
/** Model name (e.g. "tev1:0.8b"). */
|
|
11
|
+
model?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Render an ordered list of decision answers as compact markdown. */
|
|
14
|
+
export declare function formatDecisionAnswers(answers: DecisionAnswer[], opts?: DecisionFormatOptions): string;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Render an ordered list of decision answers as compact markdown. */
|
|
2
|
+
export function formatDecisionAnswers(answers, opts = {}) {
|
|
3
|
+
const header = opts.provider && opts.model
|
|
4
|
+
? `**Decision** — ${opts.provider}/${opts.model}`
|
|
5
|
+
: "**Decision**";
|
|
6
|
+
const lines = [header, ""];
|
|
7
|
+
for (const answer of answers) {
|
|
8
|
+
lines.push(formatAnswer(answer));
|
|
9
|
+
}
|
|
10
|
+
return lines.join("\n");
|
|
11
|
+
}
|
|
12
|
+
function formatAnswer(answer) {
|
|
13
|
+
if (answer.type === "choice") {
|
|
14
|
+
const confidence = answer.confidence !== undefined ? ` (confidence ${answer.confidence.toFixed(2)})` : "";
|
|
15
|
+
const lines = [
|
|
16
|
+
`- **${answer.id}** = \`${answer.choice ?? "(no choice returned)"}\`${confidence}`,
|
|
17
|
+
];
|
|
18
|
+
const probabilities = formatProbabilities(answer.probabilities);
|
|
19
|
+
if (probabilities)
|
|
20
|
+
lines.push(` - probabilities: ${probabilities}`);
|
|
21
|
+
return lines.join("\n");
|
|
22
|
+
}
|
|
23
|
+
if (answer.type === "noul") {
|
|
24
|
+
if (answer.noul === undefined) {
|
|
25
|
+
return `- **${answer.id}** = (no probability returned)`;
|
|
26
|
+
}
|
|
27
|
+
const verdict = answer.noul >= 0.5 ? "true" : "false";
|
|
28
|
+
return `- **${answer.id}** = ${verdict} (p=${answer.noul.toFixed(2)})`;
|
|
29
|
+
}
|
|
30
|
+
const score = answer.score !== undefined ? answer.score.toFixed(2) : "(no score returned)";
|
|
31
|
+
const scale = answer.legend && answer.legend.length > 1 ? ` / ${answer.legend.length - 1}` : "";
|
|
32
|
+
const confidence = answer.confidence !== undefined ? ` (confidence ${answer.confidence.toFixed(2)})` : "";
|
|
33
|
+
const lines = [`- **${answer.id}** = ${score}${scale}${confidence}`];
|
|
34
|
+
if (answer.legend && answer.legend.length > 0) {
|
|
35
|
+
lines.push(` - legend: ${answer.legend.map((label, i) => `${i}=${label}`).join(", ")}`);
|
|
36
|
+
}
|
|
37
|
+
const probabilities = formatProbabilities(answer.probabilities);
|
|
38
|
+
if (probabilities)
|
|
39
|
+
lines.push(` - probabilities: ${probabilities}`);
|
|
40
|
+
return lines.join("\n");
|
|
41
|
+
}
|
|
42
|
+
function formatProbabilities(probabilities) {
|
|
43
|
+
if (!probabilities)
|
|
44
|
+
return undefined;
|
|
45
|
+
if (Array.isArray(probabilities)) {
|
|
46
|
+
return probabilities.map((p, i) => `${i}=${p.toFixed(2)}`).join(", ");
|
|
47
|
+
}
|
|
48
|
+
return Object.entries(probabilities)
|
|
49
|
+
.sort((a, b) => b[1] - a[1])
|
|
50
|
+
.map(([label, p]) => `${label}=${p.toFixed(2)}`)
|
|
51
|
+
.join(", ");
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=format.js.map
|