Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(memory-plugin): setup wizard first-run path, proxy hint, config source reporting (#4387)

t0saki3b1db2082fa1
diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml
index 9dee52564..f9794f603 100644
--- a/.github/workflows/pr.yml
+++ b/.github/workflows/pr.yml
@@ -42,6 +42,7 @@ jobs:
examples/codex-memory-plugin/scripts/auto-recall.test.mjs \
examples/codex-memory-plugin/scripts/session-start-commit.test.mjs \
examples/claude-code-memory-plugin/scripts/auto-capture.test.mjs \
+ examples/claude-code-memory-plugin/scripts/config.test.mjs \
examples/claude-code-memory-plugin/scripts/marketplace.test.mjs \
examples/claude-code-memory-plugin/scripts/skill-experience.test.mjs \
examples/claude-code-memory-plugin/scripts/uri-guard.test.mjs \
@@ -58,6 +59,7 @@ jobs:
examples/memory-plugin-shared/install-opencode-jsonc.test.mjs \
examples/memory-plugin-shared/install-tui.test.mjs \
examples/memory-plugin-shared/release-marketplace.test.mjs \
+ examples/memory-plugin-shared/setup-wizard.test.mjs \
examples/memory-plugin-shared/sync.test.mjs \
examples/memory-plugin-shared/mcp-proxy-config.test.mjs \
examples/memory-plugin-shared/recall-compress-core.test.mjs \
diff --git a/agent-plugins/servers/shared/credentials.mjs b/agent-plugins/servers/shared/credentials.mjs
index 30d5401f2..ba26a84dc 100644
--- a/agent-plugins/servers/shared/credentials.mjs
+++ b/agent-plugins/servers/shared/credentials.mjs
@@ -192,9 +192,20 @@ export function resolveOpenVikingCredentials(env = process.env) {
const explicitMcpUrl = str(env.OPENVIKING_MCP_URL, "");
const mcpUrl = (mode !== "cli" && explicitMcpUrl) ? explicitMcpUrl : `${baseUrl.replace(/\/+$/, "")}/mcp`;
+ // The file that actually supplied the api_key, following the same chain —
+ // empty when the key came from the environment or was never found.
+ let credentialPath = "";
+ if (apiKey) {
+ if (useCli) credentialPath = files.cliPath;
+ else if (str(env.OPENVIKING_BEARER_TOKEN, str(env.OPENVIKING_API_KEY, ""))) credentialPath = "";
+ else if (str(files.cliFile.api_key, "")) credentialPath = files.cliPath;
+ else credentialPath = files.ovPath;
+ }
+
return {
...files,
credentialSource: useCli ? "ovcli" : ((mode === "env" || envHasCredentials) ? "env" : "auto"),
+ credentialPath,
baseUrl,
mcpUrl,
apiKey,
diff --git a/agent-plugins/servers/shared/mcp-proxy-core.mjs b/agent-plugins/servers/shared/mcp-proxy-core.mjs
index 70b1a4539..93d071da7 100644
--- a/agent-plugins/servers/shared/mcp-proxy-core.mjs
+++ b/agent-plugins/servers/shared/mcp-proxy-core.mjs
@@ -295,7 +295,7 @@ export function createOpenVikingMcpProxy({
return errorResponse(
id,
-32001,
- `OpenViking MCP request failed. Check the configured URL (${proxyConfig.mcpUrl}) and that 'ov serve' is running.`,
+ `OpenViking MCP request failed. Check the configured URL (${proxyConfig.mcpUrl}) and that the OpenViking server (\`openviking-server\`) is reachable.`,
{ cause: msg },
);
}
diff --git a/examples/claude-code-memory-plugin/scripts/config.mjs b/examples/claude-code-memory-plugin/scripts/config.mjs
index 8dc37251a..3960e3a6f 100644
--- a/examples/claude-code-memory-plugin/scripts/config.mjs
+++ b/examples/claude-code-memory-plugin/scripts/config.mjs
@@ -167,12 +167,32 @@ export function loadConfig() {
// apiKey: env → ovcli.api_key → cc.apiKey → server.root_api_key
// Accepts OPENVIKING_BEARER_TOKEN or OPENVIKING_API_KEY (sent as Bearer either way).
- const apiKey = str(process.env.OPENVIKING_BEARER_TOKEN, null)
- || str(process.env.OPENVIKING_API_KEY, null)
+ const envApiKey = str(process.env.OPENVIKING_BEARER_TOKEN, null)
+ || str(process.env.OPENVIKING_API_KEY, null);
+ const apiKey = envApiKey
|| str(cliFile.api_key, null)
|| str(cc.apiKey, null)
|| str(server.root_api_key, "");
+ // Which source actually supplied the api_key. `configPath` only reports the
+ // file that parsed, so debug logs and 401 hints pointed at the wrong file
+ // whenever both configs existed.
+ const ccApiKeyFromCli = hasOwn(pluginSettings, "apiKey");
+ let credentialSource = "none";
+ let credentialPath = null;
+ if (envApiKey) {
+ credentialSource = "env";
+ } else if (str(cliFile.api_key, null)) {
+ credentialSource = "ovcli";
+ credentialPath = cliConf?.configPath || null;
+ } else if (str(cc.apiKey, null)) {
+ credentialSource = ccApiKeyFromCli ? "ovcli" : "ov";
+ credentialPath = (ccApiKeyFromCli ? cliConf?.configPath : ovConf?.configPath) || null;
+ } else if (str(server.root_api_key, null)) {
+ credentialSource = "ov";
+ credentialPath = ovConf?.configPath || null;
+ }
+
// accountId: env → ovcli.account → cc.accountId → ""
const accountId = str(process.env.OPENVIKING_ACCOUNT, null)
|| str(cliFile.account, null)
@@ -225,6 +245,8 @@ export function loadConfig() {
return {
configPath,
+ credentialSource,
+ credentialPath,
baseUrl,
apiKey,
accountId,
diff --git a/examples/claude-code-memory-plugin/scripts/config.test.mjs b/examples/claude-code-memory-plugin/scripts/config.test.mjs
new file mode 100644
index 000000000..fea654c9b
--- /dev/null
+++ b/examples/claude-code-memory-plugin/scripts/config.test.mjs
@@ -0,0 +1,114 @@
+import assert from "node:assert/strict";
+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import test from "node:test";
+import { loadConfig } from "./config.mjs";
+
+const OVERRIDES = [
+ "OPENVIKING_CONFIG_FILE",
+ "OPENVIKING_CLI_CONFIG_FILE",
+ "OPENVIKING_API_KEY",
+ "OPENVIKING_BEARER_TOKEN",
+];
+
+/**
+ * Run loadConfig() against a throwaway ~/.openviking pair, with the env vars
+ * that feed the credential chain reset to exactly what the case needs.
+ */
+function withConfigs({ ov, cli, env = {} }, fn) {
+ const dir = mkdtempSync(join(tmpdir(), "cc-config-"));
+ const ovPath = join(dir, "ov.conf");
+ const cliPath = join(dir, "ovcli.conf");
+ const saved = Object.fromEntries(OVERRIDES.map((key) => [key, process.env[key]]));
+ try {
+ for (const key of OVERRIDES) delete process.env[key];
+ if (ov) writeFileSync(ovPath, JSON.stringify(ov));
+ if (cli) writeFileSync(cliPath, JSON.stringify(cli));
+ process.env.OPENVIKING_CONFIG_FILE = ovPath;
+ process.env.OPENVIKING_CLI_CONFIG_FILE = cliPath;
+ Object.assign(process.env, env);
+ return fn({ ovPath, cliPath });
+ } finally {
+ for (const [key, value] of Object.entries(saved)) {
+ if (value === undefined) delete process.env[key];
+ else process.env[key] = value;
+ }
+ rmSync(dir, { recursive: true, force: true });
+ }
+}
+
+test("an ovcli.conf api_key is reported as the credential source", () => {
+ withConfigs({
+ ov: { server: { host: "127.0.0.1", port: 1933 } },
+ cli: { url: "http://127.0.0.1:1933", api_key: "sk-cli" },
+ }, ({ ovPath, cliPath }) => {
+ const cfg = loadConfig();
+ assert.equal(cfg.apiKey, "sk-cli");
+ assert.equal(cfg.credentialSource, "ovcli");
+ assert.equal(cfg.credentialPath, cliPath);
+ // configPath stays "whichever file parsed" for backward compat.
+ assert.equal(cfg.configPath, ovPath);
+ });
+});
+
+test("an ov.conf root_api_key is reported even when ovcli.conf exists", () => {
+ withConfigs({
+ ov: { server: { root_api_key: "sk-root" } },
+ cli: { url: "http://127.0.0.1:1933" },
+ }, ({ ovPath }) => {
+ const cfg = loadConfig();
+ assert.equal(cfg.apiKey, "sk-root");
+ assert.equal(cfg.credentialSource, "ov");
+ assert.equal(cfg.credentialPath, ovPath);
+ });
+});
+
+test("an ov.conf claude_code.apiKey is reported as ov.conf", () => {
+ withConfigs({
+ ov: { claude_code: { apiKey: "sk-cc" } },
+ cli: { url: "http://127.0.0.1:1933" },
+ }, ({ ovPath }) => {
+ const cfg = loadConfig();
+ assert.equal(cfg.apiKey, "sk-cc");
+ assert.equal(cfg.credentialSource, "ov");
+ assert.equal(cfg.credentialPath, ovPath);
+ });
+});
+
+test("an ovcli.conf plugin.claude_code.apiKey is reported as ovcli.conf", () => {
+ withConfigs({
+ ov: { server: {} },
+ cli: { url: "http://127.0.0.1:1933", plugin: { claude_code: { apiKey: "sk-plugin" } } },
+ }, ({ cliPath }) => {
+ const cfg = loadConfig();
+ assert.equal(cfg.apiKey, "sk-plugin");
+ assert.equal(cfg.credentialSource, "ovcli");
+ assert.equal(cfg.credentialPath, cliPath);
+ });
+});
+
+test("an env api_key wins and carries no path", () => {
+ withConfigs({
+ ov: { server: { root_api_key: "sk-root" } },
+ cli: { url: "http://127.0.0.1:1933", api_key: "sk-cli" },
+ env: { OPENVIKING_API_KEY: "sk-env" },
+ }, () => {
+ const cfg = loadConfig();
+ assert.equal(cfg.apiKey, "sk-env");
+ assert.equal(cfg.credentialSource, "env");
+ assert.equal(cfg.credentialPath, null);
+ });
+});
+
+test("no api_key anywhere reports no source", () => {
+ withConfigs({
+ ov: { server: { host: "127.0.0.1" } },
+ cli: { url: "http://127.0.0.1:1933" },
+ }, () => {
+ const cfg = loadConfig();
+ assert.equal(cfg.apiKey, "");
+ assert.equal(cfg.credentialSource, "none");
+ assert.equal(cfg.credentialPath, null);
+ });
+});
diff --git a/examples/claude-code-memory-plugin/scripts/ov-status.mjs b/examples/claude-code-memory-plugin/scripts/ov-status.mjs
index 6913ff86f..4ba09a231 100644
--- a/examples/claude-code-memory-plugin/scripts/ov-status.mjs
+++ b/examples/claude-code-memory-plugin/scripts/ov-status.mjs
@@ -133,10 +133,10 @@ async function main() {
: (cliConf?.url) ? cliShort
: (ovConf?.server?.url) ? ovShort
: "default";
- const keySrc = (process.env.OPENVIKING_API_KEY || process.env.OPENVIKING_BEARER_TOKEN) ? "env"
- : (cliConf?.api_key) ? cliShort
- : (ovConf?.claude_code?.apiKey) ? ovShort
- : (ovConf?.server?.root_api_key) ? ovShort
+ // Taken from loadConfig() so this line and the MCP proxy always name the
+ // same file.
+ const keySrc = cfg.credentialSource === "env" ? "env"
+ : cfg.credentialPath ? homeShort(cfg.credentialPath)
: "(none)";
console.log(`Auth: url from ${urlSrc}, api_key from ${keySrc}`);
}
diff --git a/examples/claude-code-memory-plugin/scripts/shared/credentials.mjs b/examples/claude-code-memory-plugin/scripts/shared/credentials.mjs
index 30d5401f2..ba26a84dc 100644
--- a/examples/claude-code-memory-plugin/scripts/shared/credentials.mjs
+++ b/examples/claude-code-memory-plugin/scripts/shared/credentials.mjs
@@ -192,9 +192,20 @@ export function resolveOpenVikingCredentials(env = process.env) {
const explicitMcpUrl = str(env.OPENVIKING_MCP_URL, "");
const mcpUrl = (mode !== "cli" && explicitMcpUrl) ? explicitMcpUrl : `${baseUrl.replace(/\/+$/, "")}/mcp`;
+ // The file that actually supplied the api_key, following the same chain —
+ // empty when the key came from the environment or was never found.
+ let credentialPath = "";
+ if (apiKey) {
+ if (useCli) credentialPath = files.cliPath;
+ else if (str(env.OPENVIKING_BEARER_TOKEN, str(env.OPENVIKING_API_KEY, ""))) credentialPath = "";
+ else if (str(files.cliFile.api_key, "")) credentialPath = files.cliPath;
+ else credentialPath = files.ovPath;
+ }
+
return {
...files,
credentialSource: useCli ? "ovcli" : ((mode === "env" || envHasCredentials) ? "env" : "auto"),
+ credentialPath,
baseUrl,
mcpUrl,
apiKey,
diff --git a/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-core.mjs b/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-core.mjs
index 70b1a4539..93d071da7 100644
--- a/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-core.mjs
+++ b/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-core.mjs
@@ -295,7 +295,7 @@ export function createOpenVikingMcpProxy({
return errorResponse(
id,
-32001,
- `OpenViking MCP request failed. Check the configured URL (${proxyConfig.mcpUrl}) and that 'ov serve' is running.`,
+ `OpenViking MCP request failed. Check the configured URL (${proxyConfig.mcpUrl}) and that the OpenViking server (\`openviking-server\`) is reachable.`,
{ cause: msg },
);
}
diff --git a/examples/claude-code-memory-plugin/scripts/shared/setup-wizard.mjs b/examples/claude-code-memory-plugin/scripts/shared/setup-wizard.mjs
index 5108f5f2b..a49dbe7db 100644
--- a/examples/claude-code-memory-plugin/scripts/shared/setup-wizard.mjs
+++ b/examples/claude-code-memory-plugin/scripts/shared/setup-wizard.mjs
@@ -39,14 +39,17 @@ export async function runSetupWizard({
output = process.stdout,
env = process.env,
} = {}) {
- const { cliPath } = loadCredentialFiles(env);
- const current = readJsonSafe(cliPath);
+ // cliPath is empty until the file exists; first-run writes go to the candidate
+ // path (OPENVIKING_CLI_CONFIG_FILE, else ~/.openviking/ovcli.conf).
+ const { cliPath, cliPathCandidate } = loadCredentialFiles(env);
+ const targetPath = cliPath || cliPathCandidate;
+ const current = readJsonSafe(targetPath);
const rl = createInterface({ input, output });
const say = (line = "") => output.write(`${line}\n`);
try {
say("OpenViking memory plugin setup");
- say(`Config file: ${cliPath}`);
+ say(`Config file: ${targetPath}`);
say("");
say("Current values:");
say(` url: ${current.url || "(not set)"}`);
@@ -89,22 +92,22 @@ export async function runSetupWizard({
const confirm = (await rl.question("Write config? [Y/n] ")).trim().toLowerCase();
if (confirm === "n" || confirm === "no") {
say("Aborted; nothing written.");
- return { written: false, path: cliPath };
+ return { written: false, path: targetPath };
}
- mkdirSync(dirname(cliPath), { recursive: true });
- if (existsSync(cliPath)) {
- copyFileSync(cliPath, `${cliPath}.bak.${Date.now()}`);
+ mkdirSync(dirname(targetPath), { recursive: true });
+ if (existsSync(targetPath)) {
+ copyFileSync(targetPath, `${targetPath}.bak.${Date.now()}`);
}
- writeFileSync(cliPath, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
+ writeFileSync(targetPath, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
try {
- chmodSync(cliPath, 0o600);
+ chmodSync(targetPath, 0o600);
} catch {
/* best effort on platforms without chmod semantics */
}
- say(`Written: ${cliPath}`);
+ say(`Written: ${targetPath}`);
say("The stdio MCP proxy and hooks pick this up on the next harness start.");
- return { written: true, path: cliPath };
+ return { written: true, path: targetPath };
} finally {
rl.close();
}
diff --git a/examples/claude-code-memory-plugin/servers/mcp-proxy.mjs b/examples/claude-code-memory-plugin/servers/mcp-proxy.mjs
index 00987a904..bf118267a 100644
--- a/examples/claude-code-memory-plugin/servers/mcp-proxy.mjs
+++ b/examples/claude-code-memory-plugin/servers/mcp-proxy.mjs
@@ -29,9 +29,9 @@ function readProxyConfig() {
timeoutMs: cfg.timeoutMs,
debug: cfg.debug,
debugLogPath: cfg.debugLogPath,
- credentialSource: cfg.configPath?.endsWith("ovcli.conf") ? "ovcli" : "auto",
- credentialPath: cfg.configPath,
- watchedPaths: [cfg.configPath],
+ credentialSource: cfg.credentialSource,
+ credentialPath: cfg.credentialPath || "",
+ watchedPaths: [cfg.credentialPath, cfg.configPath].filter(Boolean),
});
}
diff --git a/examples/codex-memory-plugin/scripts/ov-credentials.test.mjs b/examples/codex-memory-plugin/scripts/ov-credentials.test.mjs
index ef64effec..b45972474 100644
--- a/examples/codex-memory-plugin/scripts/ov-credentials.test.mjs
+++ b/examples/codex-memory-plugin/scripts/ov-credentials.test.mjs
@@ -92,3 +92,29 @@ test("ovcli source can be forced explicitly without inheriting env key", async (
await rm(dir, { recursive: true, force: true });
}
});
+
+test("credentialPath names the file that supplied the api_key", async () => {
+ const dir = await mkdtemp(join(tmpdir(), "ov-creds-path-"));
+ const cliPath = join(dir, "ovcli.conf");
+ const ovPath = join(dir, "ov.conf");
+ await writeFile(cliPath, JSON.stringify({ url: "http://127.0.0.1:1933", api_key: "cli-key" }));
+ await writeFile(ovPath, JSON.stringify({ server: { root_api_key: "root-key" } }));
+ const env = { OPENVIKING_CLI_CONFIG_FILE: cliPath, OPENVIKING_CONFIG_FILE: ovPath };
+ try {
+ assert.equal(resolveOpenVikingCredentials(env).credentialPath, cliPath);
+
+ // env beats both files, so no file is named.
+ assert.equal(
+ resolveOpenVikingCredentials({ ...env, OPENVIKING_API_KEY: "env-key" }).credentialPath,
+ "",
+ );
+
+ // A tuning-only ovcli.conf carries no credentials, so the chain lands on ov.conf.
+ await writeFile(cliPath, JSON.stringify({ plugin: { recallCompress: "off" } }));
+ const creds = resolveOpenVikingCredentials(env);
+ assert.equal(creds.apiKey, "root-key");
+ assert.equal(creds.credentialPath, ovPath);
+ } finally {
+ await rm(dir, { recursive: true, force: true });
+ }
+});
diff --git a/examples/codex-memory-plugin/scripts/shared/credentials.mjs b/examples/codex-memory-plugin/scripts/shared/credentials.mjs
index 30d5401f2..ba26a84dc 100644
--- a/examples/codex-memory-plugin/scripts/shared/credentials.mjs
+++ b/examples/codex-memory-plugin/scripts/shared/credentials.mjs
@@ -192,9 +192,20 @@ export function resolveOpenVikingCredentials(env = process.env) {
const explicitMcpUrl = str(env.OPENVIKING_MCP_URL, "");
const mcpUrl = (mode !== "cli" && explicitMcpUrl) ? explicitMcpUrl : `${baseUrl.replace(/\/+$/, "")}/mcp`;
+ // The file that actually supplied the api_key, following the same chain —
+ // empty when the key came from the environment or was never found.
+ let credentialPath = "";
+ if (apiKey) {
+ if (useCli) credentialPath = files.cliPath;
+ else if (str(env.OPENVIKING_BEARER_TOKEN, str(env.OPENVIKING_API_KEY, ""))) credentialPath = "";
+ else if (str(files.cliFile.api_key, "")) credentialPath = files.cliPath;
+ else credentialPath = files.ovPath;
+ }
+
return {
...files,
credentialSource: useCli ? "ovcli" : ((mode === "env" || envHasCredentials) ? "env" : "auto"),
+ credentialPath,
baseUrl,
mcpUrl,
apiKey,
diff --git a/examples/codex-memory-plugin/scripts/shared/mcp-proxy-core.mjs b/examples/codex-memory-plugin/scripts/shared/mcp-proxy-core.mjs
index 70b1a4539..93d071da7 100644
--- a/examples/codex-memory-plugin/scripts/shared/mcp-proxy-core.mjs
+++ b/examples/codex-memory-plugin/scripts/shared/mcp-proxy-core.mjs
@@ -295,7 +295,7 @@ export function createOpenVikingMcpProxy({
return errorResponse(
id,
-32001,
- `OpenViking MCP request failed. Check the configured URL (${proxyConfig.mcpUrl}) and that 'ov serve' is running.`,
+ `OpenViking MCP request failed. Check the configured URL (${proxyConfig.mcpUrl}) and that the OpenViking server (\`openviking-server\`) is reachable.`,
{ cause: msg },
);
}
diff --git a/examples/codex-memory-plugin/scripts/shared/setup-wizard.mjs b/examples/codex-memory-plugin/scripts/shared/setup-wizard.mjs
index 5108f5f2b..a49dbe7db 100644
--- a/examples/codex-memory-plugin/scripts/shared/setup-wizard.mjs
+++ b/examples/codex-memory-plugin/scripts/shared/setup-wizard.mjs
@@ -39,14 +39,17 @@ export async function runSetupWizard({
output = process.stdout,
env = process.env,
} = {}) {
- const { cliPath } = loadCredentialFiles(env);
- const current = readJsonSafe(cliPath);
+ // cliPath is empty until the file exists; first-run writes go to the candidate
+ // path (OPENVIKING_CLI_CONFIG_FILE, else ~/.openviking/ovcli.conf).
+ const { cliPath, cliPathCandidate } = loadCredentialFiles(env);
+ const targetPath = cliPath || cliPathCandidate;
+ const current = readJsonSafe(targetPath);
const rl = createInterface({ input, output });
const say = (line = "") => output.write(`${line}\n`);
try {
say("OpenViking memory plugin setup");
- say(`Config file: ${cliPath}`);
+ say(`Config file: ${targetPath}`);
say("");
say("Current values:");
say(` url: ${current.url || "(not set)"}`);
@@ -89,22 +92,22 @@ export async function runSetupWizard({
const confirm = (await rl.question("Write config? [Y/n] ")).trim().toLowerCase();
if (confirm === "n" || confirm === "no") {
say("Aborted; nothing written.");
- return { written: false, path: cliPath };
+ return { written: false, path: targetPath };
}
- mkdirSync(dirname(cliPath), { recursive: true });
- if (existsSync(cliPath)) {
- copyFileSync(cliPath, `${cliPath}.bak.${Date.now()}`);
+ mkdirSync(dirname(targetPath), { recursive: true });
+ if (existsSync(targetPath)) {
+ copyFileSync(targetPath, `${targetPath}.bak.${Date.now()}`);
}
- writeFileSync(cliPath, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
+ writeFileSync(targetPath, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
try {
- chmodSync(cliPath, 0o600);
+ chmodSync(targetPath, 0o600);
} catch {
/* best effort on platforms without chmod semantics */
}
- say(`Written: ${cliPath}`);
+ say(`Written: ${targetPath}`);
say("The stdio MCP proxy and hooks pick this up on the next harness start.");
- return { written: true, path: cliPath };
+ return { written: true, path: targetPath };
} finally {
rl.close();
}
diff --git a/examples/codex-memory-plugin/servers/mcp-proxy.mjs b/examples/codex-memory-plugin/servers/mcp-proxy.mjs
index bcd2a6fb3..5354bf603 100644
--- a/examples/codex-memory-plugin/servers/mcp-proxy.mjs
+++ b/examples/codex-memory-plugin/servers/mcp-proxy.mjs
@@ -34,7 +34,7 @@ function readProxyConfig() {
debug: cfg.debug,
debugLogPath: cfg.debugLogPath,
credentialSource: creds.credentialSource,
- credentialPath: creds.cliPath || creds.ovPath,
+ credentialPath: creds.credentialPath,
watchedPaths: [creds.cliPath, creds.ovPath, creds.cliPathCandidate],
});
}
diff --git a/examples/dsh-memory-plugin/shared/credentials.mjs b/examples/dsh-memory-plugin/shared/credentials.mjs
index 30d5401f2..ba26a84dc 100644
--- a/examples/dsh-memory-plugin/shared/credentials.mjs
+++ b/examples/dsh-memory-plugin/shared/credentials.mjs
@@ -192,9 +192,20 @@ export function resolveOpenVikingCredentials(env = process.env) {
const explicitMcpUrl = str(env.OPENVIKING_MCP_URL, "");
const mcpUrl = (mode !== "cli" && explicitMcpUrl) ? explicitMcpUrl : `${baseUrl.replace(/\/+$/, "")}/mcp`;
+ // The file that actually supplied the api_key, following the same chain —
+ // empty when the key came from the environment or was never found.
+ let credentialPath = "";
+ if (apiKey) {
+ if (useCli) credentialPath = files.cliPath;
+ else if (str(env.OPENVIKING_BEARER_TOKEN, str(env.OPENVIKING_API_KEY, ""))) credentialPath = "";
+ else if (str(files.cliFile.api_key, "")) credentialPath = files.cliPath;
+ else credentialPath = files.ovPath;
+ }
+
return {
...files,
credentialSource: useCli ? "ovcli" : ((mode === "env" || envHasCredentials) ? "env" : "auto"),
+ credentialPath,
baseUrl,
mcpUrl,
apiKey,
diff --git a/examples/dsh-memory-plugin/shared/mcp-proxy-core.mjs b/examples/dsh-memory-plugin/shared/mcp-proxy-core.mjs
index 70b1a4539..93d071da7 100644
--- a/examples/dsh-memory-plugin/shared/mcp-proxy-core.mjs
+++ b/examples/dsh-memory-plugin/shared/mcp-proxy-core.mjs
@@ -295,7 +295,7 @@ export function createOpenVikingMcpProxy({
return errorResponse(
id,
-32001,
- `OpenViking MCP request failed. Check the configured URL (${proxyConfig.mcpUrl}) and that 'ov serve' is running.`,
+ `OpenViking MCP request failed. Check the configured URL (${proxyConfig.mcpUrl}) and that the OpenViking server (\`openviking-server\`) is reachable.`,
{ cause: msg },
);
}
diff --git a/examples/dsh-memory-plugin/shared/setup-wizard.mjs b/examples/dsh-memory-plugin/shared/setup-wizard.mjs
index 5108f5f2b..a49dbe7db 100644
--- a/examples/dsh-memory-plugin/shared/setup-wizard.mjs
+++ b/examples/dsh-memory-plugin/shared/setup-wizard.mjs
@@ -39,14 +39,17 @@ export async function runSetupWizard({
output = process.stdout,
env = process.env,
} = {}) {
- const { cliPath } = loadCredentialFiles(env);
- const current = readJsonSafe(cliPath);
+ // cliPath is empty until the file exists; first-run writes go to the candidate
+ // path (OPENVIKING_CLI_CONFIG_FILE, else ~/.openviking/ovcli.conf).
+ const { cliPath, cliPathCandidate } = loadCredentialFiles(env);
+ const targetPath = cliPath || cliPathCandidate;
+ const current = readJsonSafe(targetPath);
const rl = createInterface({ input, output });
const say = (line = "") => output.write(`${line}\n`);
try {
say("OpenViking memory plugin setup");
- say(`Config file: ${cliPath}`);
+ say(`Config file: ${targetPath}`);
say("");
say("Current values:");
say(` url: ${current.url || "(not set)"}`);
@@ -89,22 +92,22 @@ export async function runSetupWizard({
const confirm = (await rl.question("Write config? [Y/n] ")).trim().toLowerCase();
if (confirm === "n" || confirm === "no") {
say("Aborted; nothing written.");
- return { written: false, path: cliPath };
+ return { written: false, path: targetPath };
}
- mkdirSync(dirname(cliPath), { recursive: true });
- if (existsSync(cliPath)) {
- copyFileSync(cliPath, `${cliPath}.bak.${Date.now()}`);
+ mkdirSync(dirname(targetPath), { recursive: true });
+ if (existsSync(targetPath)) {
+ copyFileSync(targetPath, `${targetPath}.bak.${Date.now()}`);
}
- writeFileSync(cliPath, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
+ writeFileSync(targetPath, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
try {
- chmodSync(cliPath, 0o600);
+ chmodSync(targetPath, 0o600);
} catch {
/* best effort on platforms without chmod semantics */
}
- say(`Written: ${cliPath}`);
+ say(`Written: ${targetPath}`);
say("The stdio MCP proxy and hooks pick this up on the next harness start.");
- return { written: true, path: cliPath };
+ return { written: true, path: targetPath };
} finally {
rl.close();
}
diff --git a/examples/memory-plugin-shared/lib/credentials.mjs b/examples/memory-plugin-shared/lib/credentials.mjs
index d7dfa4d3e..7d6000a8b 100644
--- a/examples/memory-plugin-shared/lib/credentials.mjs
+++ b/examples/memory-plugin-shared/lib/credentials.mjs
@@ -191,9 +191,20 @@ export function resolveOpenVikingCredentials(env = process.env) {
const explicitMcpUrl = str(env.OPENVIKING_MCP_URL, "");
const mcpUrl = (mode !== "cli" && explicitMcpUrl) ? explicitMcpUrl : `${baseUrl.replace(/\/+$/, "")}/mcp`;
+ // The file that actually supplied the api_key, following the same chain —
+ // empty when the key came from the environment or was never found.
+ let credentialPath = "";
+ if (apiKey) {
+ if (useCli) credentialPath = files.cliPath;
+ else if (str(env.OPENVIKING_BEARER_TOKEN, str(env.OPENVIKING_API_KEY, ""))) credentialPath = "";
+ else if (str(files.cliFile.api_key, "")) credentialPath = files.cliPath;
+ else credentialPath = files.ovPath;
+ }
+
return {
...files,
credentialSource: useCli ? "ovcli" : ((mode === "env" || envHasCredentials) ? "env" : "auto"),
+ credentialPath,
baseUrl,
mcpUrl,
apiKey,
diff --git a/examples/memory-plugin-shared/lib/mcp-proxy-core.mjs b/examples/memory-plugin-shared/lib/mcp-proxy-core.mjs
index 4e5ed04fe..8c978779c 100644
--- a/examples/memory-plugin-shared/lib/mcp-proxy-core.mjs
+++ b/examples/memory-plugin-shared/lib/mcp-proxy-core.mjs
@@ -294,7 +294,7 @@ export function createOpenVikingMcpProxy({
return errorResponse(
id,
-32001,
- `OpenViking MCP request failed. Check the configured URL (${proxyConfig.mcpUrl}) and that 'ov serve' is running.`,
+ `OpenViking MCP request failed. Check the configured URL (${proxyConfig.mcpUrl}) and that the OpenViking server (\`openviking-server\`) is reachable.`,
{ cause: msg },
);
}
diff --git a/examples/memory-plugin-shared/lib/setup-wizard.mjs b/examples/memory-plugin-shared/lib/setup-wizard.mjs
index 9e594f850..6ce4bd5f2 100644
--- a/examples/memory-plugin-shared/lib/setup-wizard.mjs
+++ b/examples/memory-plugin-shared/lib/setup-wizard.mjs
@@ -38,14 +38,17 @@ export async function runSetupWizard({
output = process.stdout,
env = process.env,
} = {}) {
- const { cliPath } = loadCredentialFiles(env);
- const current = readJsonSafe(cliPath);
+ // cliPath is empty until the file exists; first-run writes go to the candidate
+ // path (OPENVIKING_CLI_CONFIG_FILE, else ~/.openviking/ovcli.conf).
+ const { cliPath, cliPathCandidate } = loadCredentialFiles(env);
+ const targetPath = cliPath || cliPathCandidate;
+ const current = readJsonSafe(targetPath);
const rl = createInterface({ input, output });
const say = (line = "") => output.write(`${line}\n`);
try {
say("OpenViking memory plugin setup");
- say(`Config file: ${cliPath}`);
+ say(`Config file: ${targetPath}`);
say("");
say("Current values:");
say(` url: ${current.url || "(not set)"}`);
@@ -88,22 +91,22 @@ export async function runSetupWizard({
const confirm = (await rl.question("Write config? [Y/n] ")).trim().toLowerCase();
if (confirm === "n" || confirm === "no") {
say("Aborted; nothing written.");
- return { written: false, path: cliPath };
+ return { written: false, path: targetPath };
}
- mkdirSync(dirname(cliPath), { recursive: true });
- if (existsSync(cliPath)) {
- copyFileSync(cliPath, `${cliPath}.bak.${Date.now()}`);
+ mkdirSync(dirname(targetPath), { recursive: true });
+ if (existsSync(targetPath)) {
+ copyFileSync(targetPath, `${targetPath}.bak.${Date.now()}`);
}
- writeFileSync(cliPath, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
+ writeFileSync(targetPath, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
try {
- chmodSync(cliPath, 0o600);
+ chmodSync(targetPath, 0o600);
} catch {
/* best effort on platforms without chmod semantics */
}
- say(`Written: ${cliPath}`);
+ say(`Written: ${targetPath}`);
say("The stdio MCP proxy and hooks pick this up on the next harness start.");
- return { written: true, path: cliPath };
+ return { written: true, path: targetPath };
} finally {
rl.close();
}
diff --git a/examples/memory-plugin-shared/setup-wizard.test.mjs b/examples/memory-plugin-shared/setup-wizard.test.mjs
new file mode 100644
index 000000000..482e80e3a
--- /dev/null
+++ b/examples/memory-plugin-shared/setup-wizard.test.mjs
@@ -0,0 +1,97 @@
+import assert from "node:assert/strict";
+import { mkdtemp, readFile, rm, writeFile, mkdir } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { PassThrough, Writable } from "node:stream";
+import test from "node:test";
+import { runSetupWizard } from "./lib/setup-wizard.mjs";
+
+/**
+ * Drive the wizard with scripted answers: readline writes a prompt without a
+ * trailing newline, so every such chunk gets the next answer fed back.
+ */
+function scriptedIo(answers) {
+ const queue = [...answers];
+ const input = new PassThrough();
+ const written = [];
+ const output = new Writable({
+ write(chunk, _enc, cb) {
+ const text = chunk.toString();
+ written.push(text);
+ if (!text.endsWith("\n")) {
+ setImmediate(() => input.write(`${queue.shift() ?? ""}\n`));
+ }
+ cb();
+ },
+ });
+ return { input, output, transcript: () => written.join("") };
+}
+
+test("a missing config file is created at the candidate path", async () => {
+ const dir = await mkdtemp(join(tmpdir(), "ov-wizard-new-"));
+ const target = join(dir, "nested", "ovcli.conf");
+ try {
+ const io = scriptedIo(["1", "sk-test", "y"]);
+ const result = await runSetupWizard({
+ input: io.input,
+ output: io.output,
+ env: { OPENVIKING_CLI_CONFIG_FILE: target },
+ });
+
+ assert.equal(result.written, true);
+ assert.equal(result.path, target);
+ assert.match(io.transcript(), new RegExp(`Config file: ${target}`));
+ assert.deepEqual(JSON.parse(await readFile(target, "utf-8")), {
+ url: "http://127.0.0.1:1933",
+ api_key: "sk-test",
+ });
+ } finally {
+ await rm(dir, { recursive: true, force: true });
+ }
+});
+
+test("an existing config file keeps unknown fields and its secret", async () => {
+ const dir = await mkdtemp(join(tmpdir(), "ov-wizard-existing-"));
+ const target = join(dir, "ovcli.conf");
+ try {
+ await writeFile(
+ target,
+ JSON.stringify({ url: "https://old.example.com", api_key: "sk-old", account: "acct" }),
+ );
+ const io = scriptedIo(["1", "", "y"]);
+ const result = await runSetupWizard({
+ input: io.input,
+ output: io.output,
+ env: { OPENVIKING_CLI_CONFIG_FILE: target },
+ });
+
+ assert.equal(result.path, target);
+ assert.deepEqual(JSON.parse(await readFile(target, "utf-8")), {
+ url: "http://127.0.0.1:1933",
+ api_key: "sk-old",
+ account: "acct",
+ });
+ } finally {
+ await rm(dir, { recursive: true, force: true });
+ }
+});
+
+test("declining the confirmation writes nothing but still names the target", async () => {
+ const dir = await mkdtemp(join(tmpdir(), "ov-wizard-abort-"));
+ const target = join(dir, "missing", "ovcli.conf");
+ try {
+ await mkdir(join(dir, "missing"), { recursive: true });
+ const io = scriptedIo(["2", "sk-test", "n"]);
+ const result = await runSetupWizard({
+ input: io.input,
+ output: io.output,
+ env: { OPENVIKING_CLI_CONFIG_FILE: target },
+ });
+
+ assert.equal(result.written, false);
+ assert.equal(result.path, target);
+ await assert.rejects(() => readFile(target, "utf-8"));
+ } finally {
+ await rm(dir, { recursive: true, force: true });
+ }
+});
diff --git a/examples/opencode-plugin/lib/shared/credentials.mjs b/examples/opencode-plugin/lib/shared/credentials.mjs
index 30d5401f2..ba26a84dc 100644
--- a/examples/opencode-plugin/lib/shared/credentials.mjs
+++ b/examples/opencode-plugin/lib/shared/credentials.mjs
@@ -192,9 +192,20 @@ export function resolveOpenVikingCredentials(env = process.env) {
const explicitMcpUrl = str(env.OPENVIKING_MCP_URL, "");
const mcpUrl = (mode !== "cli" && explicitMcpUrl) ? explicitMcpUrl : `${baseUrl.replace(/\/+$/, "")}/mcp`;
+ // The file that actually supplied the api_key, following the same chain —
+ // empty when the key came from the environment or was never found.
+ let credentialPath = "";
+ if (apiKey) {
+ if (useCli) credentialPath = files.cliPath;
+ else if (str(env.OPENVIKING_BEARER_TOKEN, str(env.OPENVIKING_API_KEY, ""))) credentialPath = "";
+ else if (str(files.cliFile.api_key, "")) credentialPath = files.cliPath;
+ else credentialPath = files.ovPath;
+ }
+
return {
...files,
credentialSource: useCli ? "ovcli" : ((mode === "env" || envHasCredentials) ? "env" : "auto"),
+ credentialPath,
baseUrl,
mcpUrl,
apiKey,
diff --git a/examples/opencode-plugin/lib/shared/mcp-proxy-core.mjs b/examples/opencode-plugin/lib/shared/mcp-proxy-core.mjs
index 70b1a4539..93d071da7 100644
--- a/examples/opencode-plugin/lib/shared/mcp-proxy-core.mjs
+++ b/examples/opencode-plugin/lib/shared/mcp-proxy-core.mjs
@@ -295,7 +295,7 @@ export function createOpenVikingMcpProxy({
return errorResponse(
id,
-32001,
- `OpenViking MCP request failed. Check the configured URL (${proxyConfig.mcpUrl}) and that 'ov serve' is running.`,
+ `OpenViking MCP request failed. Check the configured URL (${proxyConfig.mcpUrl}) and that the OpenViking server (\`openviking-server\`) is reachable.`,
{ cause: msg },
);
}
diff --git a/examples/opencode-plugin/lib/shared/setup-wizard.mjs b/examples/opencode-plugin/lib/shared/setup-wizard.mjs
index 5108f5f2b..a49dbe7db 100644
--- a/examples/opencode-plugin/lib/shared/setup-wizard.mjs
+++ b/examples/opencode-plugin/lib/shared/setup-wizard.mjs
@@ -39,14 +39,17 @@ export async function runSetupWizard({
output = process.stdout,
env = process.env,
} = {}) {
- const { cliPath } = loadCredentialFiles(env);
- const current = readJsonSafe(cliPath);
+ // cliPath is empty until the file exists; first-run writes go to the candidate
+ // path (OPENVIKING_CLI_CONFIG_FILE, else ~/.openviking/ovcli.conf).
+ const { cliPath, cliPathCandidate } = loadCredentialFiles(env);
+ const targetPath = cliPath || cliPathCandidate;
+ const current = readJsonSafe(targetPath);
const rl = createInterface({ input, output });
const say = (line = "") => output.write(`${line}\n`);
try {
say("OpenViking memory plugin setup");
- say(`Config file: ${cliPath}`);
+ say(`Config file: ${targetPath}`);
say("");
say("Current values:");
say(` url: ${current.url || "(not set)"}`);
@@ -89,22 +92,22 @@ export async function runSetupWizard({
const confirm = (await rl.question("Write config? [Y/n] ")).trim().toLowerCase();
if (confirm === "n" || confirm === "no") {
say("Aborted; nothing written.");
- return { written: false, path: cliPath };
+ return { written: false, path: targetPath };
}
- mkdirSync(dirname(cliPath), { recursive: true });
- if (existsSync(cliPath)) {
- copyFileSync(cliPath, `${cliPath}.bak.${Date.now()}`);
+ mkdirSync(dirname(targetPath), { recursive: true });
+ if (existsSync(targetPath)) {
+ copyFileSync(targetPath, `${targetPath}.bak.${Date.now()}`);
}
- writeFileSync(cliPath, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
+ writeFileSync(targetPath, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
try {
- chmodSync(cliPath, 0o600);
+ chmodSync(targetPath, 0o600);
} catch {
/* best effort on platforms without chmod semantics */
}
- say(`Written: ${cliPath}`);
+ say(`Written: ${targetPath}`);
say("The stdio MCP proxy and hooks pick this up on the next harness start.");
- return { written: true, path: cliPath };
+ return { written: true, path: targetPath };
} finally {
rl.close();
}
diff --git a/examples/pi-coding-agent-extension/shared/credentials.mjs b/examples/pi-coding-agent-extension/shared/credentials.mjs
index 30d5401f2..ba26a84dc 100644
--- a/examples/pi-coding-agent-extension/shared/credentials.mjs
+++ b/examples/pi-coding-agent-extension/shared/credentials.mjs
@@ -192,9 +192,20 @@ export function resolveOpenVikingCredentials(env = process.env) {
const explicitMcpUrl = str(env.OPENVIKING_MCP_URL, "");
const mcpUrl = (mode !== "cli" && explicitMcpUrl) ? explicitMcpUrl : `${baseUrl.replace(/\/+$/, "")}/mcp`;
+ // The file that actually supplied the api_key, following the same chain —
+ // empty when the key came from the environment or was never found.
+ let credentialPath = "";
+ if (apiKey) {
+ if (useCli) credentialPath = files.cliPath;
+ else if (str(env.OPENVIKING_BEARER_TOKEN, str(env.OPENVIKING_API_KEY, ""))) credentialPath = "";
+ else if (str(files.cliFile.api_key, "")) credentialPath = files.cliPath;
+ else credentialPath = files.ovPath;
+ }
+
return {
...files,
credentialSource: useCli ? "ovcli" : ((mode === "env" || envHasCredentials) ? "env" : "auto"),
+ credentialPath,
baseUrl,
mcpUrl,
apiKey,
diff --git a/examples/pi-coding-agent-extension/shared/setup-wizard.mjs b/examples/pi-coding-agent-extension/shared/setup-wizard.mjs
index 5108f5f2b..a49dbe7db 100644
--- a/examples/pi-coding-agent-extension/shared/setup-wizard.mjs
+++ b/examples/pi-coding-agent-extension/shared/setup-wizard.mjs
@@ -39,14 +39,17 @@ export async function runSetupWizard({
output = process.stdout,
env = process.env,
} = {}) {
- const { cliPath } = loadCredentialFiles(env);
- const current = readJsonSafe(cliPath);
+ // cliPath is empty until the file exists; first-run writes go to the candidate
+ // path (OPENVIKING_CLI_CONFIG_FILE, else ~/.openviking/ovcli.conf).
+ const { cliPath, cliPathCandidate } = loadCredentialFiles(env);
+ const targetPath = cliPath || cliPathCandidate;
+ const current = readJsonSafe(targetPath);
const rl = createInterface({ input, output });
const say = (line = "") => output.write(`${line}\n`);
try {
say("OpenViking memory plugin setup");
- say(`Config file: ${cliPath}`);
+ say(`Config file: ${targetPath}`);
say("");
say("Current values:");
say(` url: ${current.url || "(not set)"}`);
@@ -89,22 +92,22 @@ export async function runSetupWizard({
const confirm = (await rl.question("Write config? [Y/n] ")).trim().toLowerCase();
if (confirm === "n" || confirm === "no") {
say("Aborted; nothing written.");
- return { written: false, path: cliPath };
+ return { written: false, path: targetPath };
}
- mkdirSync(dirname(cliPath), { recursive: true });
- if (existsSync(cliPath)) {
- copyFileSync(cliPath, `${cliPath}.bak.${Date.now()}`);
+ mkdirSync(dirname(targetPath), { recursive: true });
+ if (existsSync(targetPath)) {
+ copyFileSync(targetPath, `${targetPath}.bak.${Date.now()}`);
}
- writeFileSync(cliPath, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
+ writeFileSync(targetPath, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
try {
- chmodSync(cliPath, 0o600);
+ chmodSync(targetPath, 0o600);
} catch {
/* best effort on platforms without chmod semantics */
}
- say(`Written: ${cliPath}`);
+ say(`Written: ${targetPath}`);
say("The stdio MCP proxy and hooks pick this up on the next harness start.");
- return { written: true, path: cliPath };
+ return { written: true, path: targetPath };
} finally {
rl.close();
}
diff --git a/examples/zcode-memory-plugin/scripts/shared/credentials.mjs b/examples/zcode-memory-plugin/scripts/shared/credentials.mjs
index 30d5401f2..ba26a84dc 100644
--- a/examples/zcode-memory-plugin/scripts/shared/credentials.mjs
+++ b/examples/zcode-memory-plugin/scripts/shared/credentials.mjs
@@ -192,9 +192,20 @@ export function resolveOpenVikingCredentials(env = process.env) {
const explicitMcpUrl = str(env.OPENVIKING_MCP_URL, "");
const mcpUrl = (mode !== "cli" && explicitMcpUrl) ? explicitMcpUrl : `${baseUrl.replace(/\/+$/, "")}/mcp`;
+ // The file that actually supplied the api_key, following the same chain —
+ // empty when the key came from the environment or was never found.
+ let credentialPath = "";
+ if (apiKey) {
+ if (useCli) credentialPath = files.cliPath;
+ else if (str(env.OPENVIKING_BEARER_TOKEN, str(env.OPENVIKING_API_KEY, ""))) credentialPath = "";
+ else if (str(files.cliFile.api_key, "")) credentialPath = files.cliPath;
+ else credentialPath = files.ovPath;
+ }
+
return {
...files,
credentialSource: useCli ? "ovcli" : ((mode === "env" || envHasCredentials) ? "env" : "auto"),
+ credentialPath,
baseUrl,
mcpUrl,
apiKey,
diff --git a/examples/zcode-memory-plugin/scripts/shared/mcp-proxy-core.mjs b/examples/zcode-memory-plugin/scripts/shared/mcp-proxy-core.mjs
index 70b1a4539..93d071da7 100644
--- a/examples/zcode-memory-plugin/scripts/shared/mcp-proxy-core.mjs
+++ b/examples/zcode-memory-plugin/scripts/shared/mcp-proxy-core.mjs
@@ -295,7 +295,7 @@ export function createOpenVikingMcpProxy({
return errorResponse(
id,
-32001,
- `OpenViking MCP request failed. Check the configured URL (${proxyConfig.mcpUrl}) and that 'ov serve' is running.`,
+ `OpenViking MCP request failed. Check the configured URL (${proxyConfig.mcpUrl}) and that the OpenViking server (\`openviking-server\`) is reachable.`,
{ cause: msg },
);
}
diff --git a/examples/zcode-memory-plugin/scripts/shared/setup-wizard.mjs b/examples/zcode-memory-plugin/scripts/shared/setup-wizard.mjs
index 5108f5f2b..a49dbe7db 100644
--- a/examples/zcode-memory-plugin/scripts/shared/setup-wizard.mjs
+++ b/examples/zcode-memory-plugin/scripts/shared/setup-wizard.mjs
@@ -39,14 +39,17 @@ export async function runSetupWizard({
output = process.stdout,
env = process.env,
} = {}) {
- const { cliPath } = loadCredentialFiles(env);
- const current = readJsonSafe(cliPath);
+ // cliPath is empty until the file exists; first-run writes go to the candidate
+ // path (OPENVIKING_CLI_CONFIG_FILE, else ~/.openviking/ovcli.conf).
+ const { cliPath, cliPathCandidate } = loadCredentialFiles(env);
+ const targetPath = cliPath || cliPathCandidate;
+ const current = readJsonSafe(targetPath);
const rl = createInterface({ input, output });
const say = (line = "") => output.write(`${line}\n`);
try {
say("OpenViking memory plugin setup");
- say(`Config file: ${cliPath}`);
+ say(`Config file: ${targetPath}`);
say("");
say("Current values:");
say(` url: ${current.url || "(not set)"}`);
@@ -89,22 +92,22 @@ export async function runSetupWizard({
const confirm = (await rl.question("Write config? [Y/n] ")).trim().toLowerCase();
if (confirm === "n" || confirm === "no") {
say("Aborted; nothing written.");
- return { written: false, path: cliPath };
+ return { written: false, path: targetPath };
}
- mkdirSync(dirname(cliPath), { recursive: true });
- if (existsSync(cliPath)) {
- copyFileSync(cliPath, `${cliPath}.bak.${Date.now()}`);
+ mkdirSync(dirname(targetPath), { recursive: true });
+ if (existsSync(targetPath)) {
+ copyFileSync(targetPath, `${targetPath}.bak.${Date.now()}`);
}
- writeFileSync(cliPath, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
+ writeFileSync(targetPath, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
try {
- chmodSync(cliPath, 0o600);
+ chmodSync(targetPath, 0o600);
} catch {
/* best effort on platforms without chmod semantics */
}
- say(`Written: ${cliPath}`);
+ say(`Written: ${targetPath}`);
say("The stdio MCP proxy and hooks pick this up on the next harness start.");
- return { written: true, path: cliPath };
+ return { written: true, path: targetPath };
} finally {
rl.close();
}