Skip to content

Commit 587f79c

Browse files
anandgupta42claude
andcommitted
fix: point the warehouse_list no-connections hint at the real config locations
The hint told users to create `connections.json` in `.opencode/`, which the registry never reads. It now names the global and project `.altimate-code/connections.json` paths and the `ALTIMATE_CODE_CONN_*` variables, mentions `warehouse_add`, and keeps the example JSON. The paths come from `globalConfigPath()`, `localConfigPath()` and `CONN_ENV_PREFIX`, now exported from the registry, so the hint cannot drift. A repo sweep found no other reference to the old location. Closes #1558 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3d5a704 commit 587f79c

3 files changed

Lines changed: 85 additions & 4 deletions

File tree

‎packages/opencode/src/altimate/native/connections/registry.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const SCRATCH_NAME_CONFLICT =
5858
// Config file paths
5959
// ---------------------------------------------------------------------------
6060

61-
function globalConfigPath(): string {
61+
export function globalConfigPath(): string {
6262
// altimate_change start — the same home Global.Path uses, so the test preload's OPENCODE_TEST_HOME keeps the
6363
// suite out of the developer's real connections (Bun caches os.homedir(), so changing HOME does not).
6464
return path.join(Global.Path.home, ".altimate-code", "connections.json")
@@ -93,7 +93,7 @@ function projectRoot(): string {
9393
}
9494
// altimate_change end
9595

96-
function localConfigPath(): string {
96+
export function localConfigPath(): string {
9797
// altimate_change start — resolve against the project, not the launch cwd
9898
return path.join(projectRoot(), ".altimate-code", "connections.json")
9999
// altimate_change end
@@ -172,9 +172,13 @@ function loadFromFile(filePath: string): Record<string, ConnectionConfig> {
172172
}
173173
}
174174

175+
// altimate_change start — exported so user-facing hints name the variable the loader reads
176+
export const CONN_ENV_PREFIX = "ALTIMATE_CODE_CONN_"
177+
// altimate_change end
178+
175179
function loadFromEnv(): Record<string, ConnectionConfig> {
176180
const result: Record<string, ConnectionConfig> = {}
177-
const prefix = "ALTIMATE_CODE_CONN_"
181+
const prefix = CONN_ENV_PREFIX
178182

179183
for (const [key, value] of Object.entries(process.env)) {
180184
if (!key.startsWith(prefix) || !value) continue

‎packages/opencode/src/altimate/tools/warehouse-list.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@ import { Dispatcher } from "../native"
55
import * as Precedence from "../workspace/precedence"
66
// altimate_change end
77

8+
// altimate_change start — point at the locations the registry actually reads
9+
import { CONN_ENV_PREFIX, globalConfigPath, localConfigPath } from "../native/connections/registry"
10+
11+
/** The no-connections hint. Paths come from the registry's own helpers so it cannot drift from what is loaded. */
12+
export function noConnectionsMessage(): string {
13+
return [
14+
"No warehouse connections configured.",
15+
"",
16+
"Connections are read from these sources (later ones override earlier ones):",
17+
` 1. ${globalConfigPath()} (global)`,
18+
` 2. ${localConfigPath()} (this project)`,
19+
` 3. ${CONN_ENV_PREFIX}<NAME> environment variables, each holding one connection's config as JSON`,
20+
"",
21+
"Use the warehouse_add tool to add one, or create a connections.json at one of the paths above with:",
22+
"{",
23+
' "my-db": { "type": "postgres", "host": "localhost", "port": 5432, "database": "mydb", "user": "user", "password": "pass" }',
24+
"}",
25+
"",
26+
"Do not put connections.json in .opencode/; it is not read from there.",
27+
].join("\n")
28+
}
29+
// altimate_change end
30+
831
export const WarehouseListTool = Tool.define("warehouse_list", {
932
description: "List all configured warehouse connections. Shows connection name, type, and database.",
1033
parameters: z.object({}),
@@ -17,7 +40,7 @@ export const WarehouseListTool = Tool.define("warehouse_list", {
1740
return {
1841
title: "Warehouses: none configured",
1942
metadata: { count: 0 },
20-
output: "No warehouse connections configured.\n\nTo add a connection, create a connections.json file in .opencode/ with:\n{\n \"my-db\": { \"type\": \"postgres\", \"host\": \"localhost\", \"port\": 5432, \"database\": \"mydb\", \"user\": \"user\", \"password\": \"pass\" }\n}",
43+
output: noConnectionsMessage(),
2144
}
2245
}
2346

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { describe, test, expect, beforeEach, afterEach } from "bun:test"
2+
import * as fs from "fs"
3+
import * as os from "os"
4+
import * as path from "path"
5+
import * as Registry from "../../src/altimate/native/connections/registry"
6+
import { noConnectionsMessage } from "../../src/altimate/tools/warehouse-list"
7+
8+
let project: string
9+
let prevCwd: string
10+
11+
beforeEach(() => {
12+
prevCwd = process.cwd()
13+
project = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "whl-hint-")))
14+
process.chdir(project)
15+
Registry.reset()
16+
})
17+
18+
afterEach(() => {
19+
process.chdir(prevCwd)
20+
Registry.reset()
21+
fs.rmSync(project, { recursive: true, force: true })
22+
})
23+
24+
describe("warehouse_list no-connections hint", () => {
25+
test("names the paths and env prefix the registry reads, not .opencode", () => {
26+
const msg = noConnectionsMessage()
27+
expect(msg).toContain(Registry.globalConfigPath())
28+
expect(msg).toContain(Registry.localConfigPath())
29+
expect(msg).toContain(Registry.CONN_ENV_PREFIX)
30+
expect(msg).toContain("warehouse_add")
31+
expect(msg).toContain('"type": "postgres"')
32+
expect(msg).not.toContain(".opencode/connections.json")
33+
expect(Registry.localConfigPath()).toBe(path.join(project, ".altimate-code", "connections.json"))
34+
})
35+
36+
test("a connections.json written to the project path named by the hint is loaded", () => {
37+
const named = Registry.localConfigPath()
38+
expect(noConnectionsMessage()).toContain(named)
39+
fs.mkdirSync(path.dirname(named), { recursive: true })
40+
fs.writeFileSync(named, JSON.stringify({ "hint-db": { type: "postgres", host: "localhost", database: "d" } }))
41+
Registry.load()
42+
expect(Registry.names()).toContain("hint-db")
43+
})
44+
45+
test("a connections.json at the legacy .opencode location is not loaded", () => {
46+
fs.mkdirSync(path.join(project, ".opencode"))
47+
fs.writeFileSync(
48+
path.join(project, ".opencode", "connections.json"),
49+
JSON.stringify({ "wrong-db": { type: "postgres", host: "localhost" } }),
50+
)
51+
Registry.load()
52+
expect(Registry.names()).not.toContain("wrong-db")
53+
})
54+
})

0 commit comments

Comments
 (0)