opencode-rag-plugin 2.11.1 → 2.11.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/dist/plugin.d.ts +13 -0
- package/dist/plugin.js +77 -8
- package/package.json +1 -1
package/dist/plugin.d.ts
CHANGED
|
@@ -9,6 +9,19 @@ import { type RagConfig } from "./core/config.js";
|
|
|
9
9
|
import { createEmbedder } from "./embedder/factory.js";
|
|
10
10
|
import { StateSync } from "./core/state-sync.js";
|
|
11
11
|
import { retrieve } from "./retriever/retriever.js";
|
|
12
|
+
/**
|
|
13
|
+
* Describe where a workspace's effective config is read from.
|
|
14
|
+
*
|
|
15
|
+
* Slash-command gates (`/doc`, `/wiki`, `/quirk`) report "not enabled" from a
|
|
16
|
+
* config object, and without provenance the report is not actionable: a
|
|
17
|
+
* higher-precedence layer (`.opencode/opencode-rag.json`) silently shadows the
|
|
18
|
+
* root file, and a plugin that booted before an edit keeps serving its startup
|
|
19
|
+
* snapshot. Printed in the command's response and in the plugin log.
|
|
20
|
+
*
|
|
21
|
+
* @param directory - Workspace directory the plugin was loaded for.
|
|
22
|
+
* @returns One line naming the directory and both config layers (`none` when absent).
|
|
23
|
+
*/
|
|
24
|
+
export declare function describeConfigSource(directory: string): string;
|
|
12
25
|
/**
|
|
13
26
|
* Load the RAG configuration for a directory: DEFAULT_CONFIG, then the global
|
|
14
27
|
* layer (`~/.config/opencode/opencode-rag.json`), then the first workspace
|
package/dist/plugin.js
CHANGED
|
@@ -242,6 +242,22 @@ function configStamp(paths) {
|
|
|
242
242
|
paths.workspace ? `${paths.workspace}:${configFileMtime(paths.workspace)}` : "",
|
|
243
243
|
].join("|");
|
|
244
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Describe where a workspace's effective config is read from.
|
|
247
|
+
*
|
|
248
|
+
* Slash-command gates (`/doc`, `/wiki`, `/quirk`) report "not enabled" from a
|
|
249
|
+
* config object, and without provenance the report is not actionable: a
|
|
250
|
+
* higher-precedence layer (`.opencode/opencode-rag.json`) silently shadows the
|
|
251
|
+
* root file, and a plugin that booted before an edit keeps serving its startup
|
|
252
|
+
* snapshot. Printed in the command's response and in the plugin log.
|
|
253
|
+
*
|
|
254
|
+
* @param directory - Workspace directory the plugin was loaded for.
|
|
255
|
+
* @returns One line naming the directory and both config layers (`none` when absent).
|
|
256
|
+
*/
|
|
257
|
+
export function describeConfigSource(directory) {
|
|
258
|
+
const paths = resolveConfigPaths(directory);
|
|
259
|
+
return `directory: ${directory}; workspace: ${paths.workspace ?? "none"}; global: ${paths.global ?? "none"}`;
|
|
260
|
+
}
|
|
245
261
|
/**
|
|
246
262
|
* Load the RAG configuration for a directory: DEFAULT_CONFIG, then the global
|
|
247
263
|
* layer (`~/.config/opencode/opencode-rag.json`), then the first workspace
|
|
@@ -670,6 +686,31 @@ export function createRagHooks(options) {
|
|
|
670
686
|
lastEffectiveCfgTime = Date.now();
|
|
671
687
|
return lastEffectiveCfg;
|
|
672
688
|
}
|
|
689
|
+
/**
|
|
690
|
+
* Config used by the slash-command gates (`/doc`, `/wiki`, `/quirk`).
|
|
691
|
+
*
|
|
692
|
+
* These are cold paths, so read the workspace config straight from disk
|
|
693
|
+
* instead of trusting the cached startup snapshot: the gate must agree with
|
|
694
|
+
* the file the user just edited, even when the plugin started before that
|
|
695
|
+
* edit. This matters because OpenCode V2 runs plugins inside a shared
|
|
696
|
+
* background service that survives TUI restarts, so "restart OpenCode" does
|
|
697
|
+
* not necessarily reload the plugin.
|
|
698
|
+
*
|
|
699
|
+
* Falls back to the effective config when the workspace has no config file
|
|
700
|
+
* or the file cannot be parsed (the last known config keeps serving).
|
|
701
|
+
*/
|
|
702
|
+
function slashCommandConfig() {
|
|
703
|
+
try {
|
|
704
|
+
const paths = resolveConfigPaths(options.worktree);
|
|
705
|
+
if (paths.workspace || paths.global) {
|
|
706
|
+
return applyRuntimeOverrides(loadWorkspaceConfig(options.worktree, false), cachedOverrides);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
catch {
|
|
710
|
+
// Unreadable/malformed config — fall through to the last known config.
|
|
711
|
+
}
|
|
712
|
+
return getEffectiveCfg();
|
|
713
|
+
}
|
|
673
714
|
// The embedder follows the live configuration: when the config file changes
|
|
674
715
|
// (new API key, baseUrl or model) the provider is rebuilt instead of
|
|
675
716
|
// keeping the one built at plugin setup.
|
|
@@ -1592,13 +1633,26 @@ export function createRagHooks(options) {
|
|
|
1592
1633
|
boundedSet(sessionLastMessage, input.sessionID, text, MAX_SESSION_MAP_SIZE);
|
|
1593
1634
|
// Handle /doc slash command
|
|
1594
1635
|
if (text.startsWith("/doc")) {
|
|
1595
|
-
|
|
1636
|
+
// Read the config from disk (cold path): the gate must agree with the
|
|
1637
|
+
// file the user just edited, not with a startup snapshot.
|
|
1638
|
+
const docMode = slashCommandConfig().documentationMode;
|
|
1596
1639
|
if (!docMode?.enabled) {
|
|
1640
|
+
const configSource = describeConfigSource(options.worktree);
|
|
1641
|
+
const configHint = resolveConfigPaths(options.worktree).workspace
|
|
1642
|
+
?? path.join(options.worktree, ".opencode", "opencode-rag.json");
|
|
1643
|
+
appendDebugLog(options.logFilePath, {
|
|
1644
|
+
scope: "chat.message",
|
|
1645
|
+
message: `Slash command /doc blocked: documentationMode.enabled is not true — ${configSource}`,
|
|
1646
|
+
}, options.logLevel);
|
|
1597
1647
|
const parts = output?.parts ?? output?.message?.parts;
|
|
1598
1648
|
if (Array.isArray(parts) && parts.length > 0) {
|
|
1599
1649
|
const first = parts[0];
|
|
1600
1650
|
if (typeof first.text === "string") {
|
|
1601
|
-
parts[0] = { ...first, text: "Documentation mode is not enabled
|
|
1651
|
+
parts[0] = { ...first, text: "Documentation mode is not enabled.\n\n" +
|
|
1652
|
+
`Set \`documentationMode.enabled\` to \`true\` in \`${configHint}\`.\n\n` +
|
|
1653
|
+
`Config resolution — ${configSource}.\n\n` +
|
|
1654
|
+
"If the file already says `true`, the running plugin is using a stale config — " +
|
|
1655
|
+
"restart the OpenCode service (`opencode service restart`) so the plugin reloads." };
|
|
1602
1656
|
}
|
|
1603
1657
|
}
|
|
1604
1658
|
return;
|
|
@@ -1676,13 +1730,13 @@ export function createRagHooks(options) {
|
|
|
1676
1730
|
}
|
|
1677
1731
|
// Handle /wiki slash command
|
|
1678
1732
|
if (text.startsWith("/wiki")) {
|
|
1679
|
-
const wikiMode =
|
|
1733
|
+
const wikiMode = slashCommandConfig().wikiMode;
|
|
1680
1734
|
if (!wikiMode?.enabled) {
|
|
1681
1735
|
const parts = output?.parts ?? output?.message?.parts;
|
|
1682
1736
|
if (Array.isArray(parts) && parts.length > 0) {
|
|
1683
1737
|
const first = parts[0];
|
|
1684
1738
|
if (typeof first.text === "string") {
|
|
1685
|
-
parts[0] = { ...first, text:
|
|
1739
|
+
parts[0] = { ...first, text: `Wiki mode is not enabled. Set \`wikiMode.enabled\` to \`true\` in opencode-rag.json. Config resolution — ${describeConfigSource(options.worktree)}.` };
|
|
1686
1740
|
}
|
|
1687
1741
|
}
|
|
1688
1742
|
return;
|
|
@@ -1734,13 +1788,13 @@ export function createRagHooks(options) {
|
|
|
1734
1788
|
}
|
|
1735
1789
|
// Handle /quirk slash command
|
|
1736
1790
|
if (text.startsWith("/quirk")) {
|
|
1737
|
-
const memoryCfg =
|
|
1791
|
+
const memoryCfg = slashCommandConfig().memory;
|
|
1738
1792
|
if (!memoryCfg?.enabled) {
|
|
1739
1793
|
const parts = output?.parts ?? output?.message?.parts;
|
|
1740
1794
|
if (Array.isArray(parts) && parts.length > 0) {
|
|
1741
1795
|
const first = parts[0];
|
|
1742
1796
|
if (typeof first.text === "string") {
|
|
1743
|
-
parts[0] = { ...first, text:
|
|
1797
|
+
parts[0] = { ...first, text: `Quirk memory is not enabled. Set \`memory.enabled\` to \`true\` in opencode-rag.json. Config resolution — ${describeConfigSource(options.worktree)}.` };
|
|
1744
1798
|
}
|
|
1745
1799
|
}
|
|
1746
1800
|
return;
|
|
@@ -1996,6 +2050,16 @@ export const ragPlugin = async (input, _options) => {
|
|
|
1996
2050
|
if (!cfg.openCode.enabled) {
|
|
1997
2051
|
return {};
|
|
1998
2052
|
}
|
|
2053
|
+
// Record WHICH config file produced this instance. Without it, a report like
|
|
2054
|
+
// "the config says documentationMode.enabled = true but /doc says it is off"
|
|
2055
|
+
// cannot be diagnosed from the log: the answer is either a different file
|
|
2056
|
+
// (layer shadowing) or a stale snapshot (plugin never reloaded).
|
|
2057
|
+
appendDebugLog(logFilePath, {
|
|
2058
|
+
scope: "config",
|
|
2059
|
+
message: `Config: ${describeConfigSource(input.directory)}; ` +
|
|
2060
|
+
`documentationMode.enabled=${cfg.documentationMode?.enabled === true}; ` +
|
|
2061
|
+
`wikiMode.enabled=${cfg.wikiMode?.enabled === true}`,
|
|
2062
|
+
}, logLevel);
|
|
1999
2063
|
const storePath = path.resolve(input.directory, cfg.vectorStore.path);
|
|
2000
2064
|
// Apply runtime overrides before creating services
|
|
2001
2065
|
const overrides = loadRuntimeOverrides(storePath);
|
|
@@ -2048,8 +2112,13 @@ export const ragPlugin = async (input, _options) => {
|
|
|
2048
2112
|
}
|
|
2049
2113
|
ragStores.delete(input.directory);
|
|
2050
2114
|
}
|
|
2051
|
-
// Clean up
|
|
2052
|
-
|
|
2115
|
+
// Clean up pending update info for this directory.
|
|
2116
|
+
//
|
|
2117
|
+
// Do NOT drop the config cache entry here: `getConfig` above just stored it,
|
|
2118
|
+
// and that entry is what makes `refreshConfig` re-read the file on every
|
|
2119
|
+
// later mtime change. Deleting it pinned the whole plugin to its startup
|
|
2120
|
+
// snapshot for the lifetime of the (long-lived, shared) OpenCode service —
|
|
2121
|
+
// a config edit was then never picked up, not even by `getEffectiveCfg()`.
|
|
2053
2122
|
pendingUpdateInfo.delete(input.directory);
|
|
2054
2123
|
pendingRestartNotice.delete(input.directory);
|
|
2055
2124
|
notifiedUpdateDirs.delete(input.directory);
|