Skip to content

Commit 28a2264

Browse files
suryaiyer95claude
andcommitted
fix: use cwd fallback for project config path when no git repo detected
`Instance.worktree` returns `/` for non-git projects, causing config writes to `/.altimate-code/`. Now falls back to `Instance.directory` (the actual cwd) via `projectRoot()` helper. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2ef944f commit 28a2264

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

packages/opencode/src/altimate/tools/datamate.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import {
1212
import { Instance } from "../../project/instance"
1313
import { Global } from "../../global"
1414

15+
/** Project root for config resolution — falls back to cwd when no git repo is detected. */
16+
function projectRoot() {
17+
const wt = Instance.worktree
18+
return wt === "/" ? Instance.directory : wt
19+
}
20+
1521
export function slugify(name: string): string {
1622
return name
1723
.toLowerCase()
@@ -169,7 +175,7 @@ async function handleAdd(args: { datamate_id?: string; name?: string; scope?: "p
169175

170176
// Always save to config first so it persists for future sessions
171177
const isGlobal = args.scope === "global"
172-
const configPath = await resolveConfigPath(isGlobal ? Global.Path.config : Instance.worktree, isGlobal)
178+
const configPath = await resolveConfigPath(isGlobal ? Global.Path.config : projectRoot(), isGlobal)
173179
await addMcpToConfig(serverName, mcpConfig, configPath)
174180

175181
await MCP.add(serverName, mcpConfig)
@@ -307,7 +313,7 @@ async function handleDelete(args: { datamate_id?: string }) {
307313
}
308314

309315
// Remove from all config files
310-
const configPaths = await findAllConfigPaths(Instance.worktree, Global.Path.config)
316+
const configPaths = await findAllConfigPaths(projectRoot(), Global.Path.config)
311317
const removedFrom: string[] = []
312318
const serverName = `datamate-${slugify(datamate.name)}`
313319
for (const configPath of configPaths) {
@@ -393,7 +399,7 @@ async function handleRemove(args: { server_name?: string; scope?: "project" | "g
393399
}
394400
}
395401
if (scope === "project") {
396-
const projectPath = await resolveConfigPath(Instance.worktree)
402+
const projectPath = await resolveConfigPath(projectRoot())
397403
if (await removeMcpFromConfig(args.server_name, projectPath)) {
398404
removed.push(projectPath)
399405
}
@@ -420,12 +426,12 @@ async function handleRemove(args: { server_name?: string; scope?: "project" | "g
420426

421427
async function handleListConfig() {
422428
try {
423-
const configPaths = await findAllConfigPaths(Instance.worktree, Global.Path.config)
429+
const configPaths = await findAllConfigPaths(projectRoot(), Global.Path.config)
424430
if (configPaths.length === 0) {
425431
return {
426432
title: "Datamate config: no config files found",
427433
metadata: {},
428-
output: `No config files found.\n\nProject config would be at: ${Instance.worktree}/altimate-code.json\nGlobal config would be at: ${Global.Path.config}/altimate-code.json`,
434+
output: `No config files found.\n\nProject config would be at: ${projectRoot()}/altimate-code.json\nGlobal config would be at: ${Global.Path.config}/altimate-code.json`,
429435
}
430436
}
431437

0 commit comments

Comments
 (0)