Skip to content

Commit c2a5541

Browse files
author
saravmajestic
committed
chore: strip altimate_change markers from altimate/ subtree, inline DATAMATE_KEY
1 parent 0fbdc9b commit c2a5541

3 files changed

Lines changed: 17 additions & 34 deletions

File tree

packages/opencode/src/altimate/datamate-transport.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import type { Config } from "../config/config"
99

1010
const log = Log.create({ service: "datamate-transport" })
1111

12-
// altimate_change start — shared constant used in datamate.ts, serve.ts, and server.ts
1312
export const DATAMATE_KEY = "datamate"
14-
// altimate_change end
1513

1614
/**
1715
* Top-level keys that MCP config files use to map server name → entry.

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

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import {
1212
import { Instance } from "../../project/instance"
1313
import { Global } from "../../global"
1414
import { Log } from "../../util/log"
15-
// altimate_change start — shared datamate transport helpers (IDE scan, sync, constants)
1615
import { DATAMATE_KEY, readDatamateTransportFromIde } from "../datamate-transport"
17-
// altimate_change end
1816

1917
const log = Log.create({ service: "datamate" })
2018

@@ -31,12 +29,10 @@ export function slugify(name: string): string {
3129
.replace(/^-|-$/g, "")
3230
}
3331

34-
// altimate_change start — readDatamateTransportFromIde (imported from altimate/datamate-transport.ts)
3532
// Scans .vscode/mcp.json, .cursor/mcp.json, .github/copilot/mcp.json in projectRootDir
3633
// so this works in Cursor, Copilot, and other IDEs that write their own MCP config file.
3734
// Returns the exact command from the IDE config so altimate-code reuses the same process
3835
// the extension already manages rather than spawning a second one.
39-
// altimate_change end
4036

4137
export const DatamateManagerTool = Tool.define("datamate_manager", {
4238
description:
@@ -169,10 +165,7 @@ async function handleListIntegrations() {
169165
}
170166
}
171167

172-
// altimate_change start — server name used by IDEs (VS Code, Cursor, etc) in their MCP config
173168
// DATAMATE_KEY is imported from altimate/datamate-transport.ts (shared constant).
174-
const EXTENSION_DATAMATE_SERVER = DATAMATE_KEY
175-
// altimate_change end
176169

177170
async function handleAdd(args: { datamate_id?: string; name?: string; scope?: "project" | "global" }) {
178171
if (!args.datamate_id) {
@@ -184,31 +177,28 @@ async function handleAdd(args: { datamate_id?: string; name?: string; scope?: "p
184177
}
185178
try {
186179
const datamate = await AltimateApi.getDatamate(args.datamate_id)
187-
// altimate_change start — scan all IDE config locations (VS Code, Cursor, Copilot, etc.)
188180
// readDatamateTransportFromIde returns the exact command from the IDE config so we
189181
// reuse the same process the extension already manages, not a second one.
190182
const transport = await readDatamateTransportFromIde(projectRoot())
191183

192184
if (transport !== null) {
193185
log.info("handleAdd: IDE transport detected, entering single-gateway mode", {
194-
serverName: EXTENSION_DATAMATE_SERVER,
186+
serverName: DATAMATE_KEY,
195187
transportType: transport.type,
196188
})
197189
} else {
198190
log.info("handleAdd: no IDE transport found, using standalone cloud config")
199191
}
200-
// altimate_change end
201192

202-
// altimate_change start — single-gateway mode when IDE extension is present
203193
// If an IDE MCP config has a "datamate" entry (written by VS Code, Cursor, etc.),
204-
// always use EXTENSION_DATAMATE_SERVER ("datamate") as the server name regardless
194+
// always use DATAMATE_KEY ("datamate") as the server name regardless
205195
// of which specific datamate the user selected. This prevents duplicate tool sets
206196
// — the extension's gateway already serves all datamate tools through a single
207197
// MCP connection.
208198
// In standalone/CLI mode (no IDE datamate entry), fall back to per-datamate naming
209199
// with cloud URL.
210200
const serverName = transport !== null
211-
? EXTENSION_DATAMATE_SERVER
201+
? DATAMATE_KEY
212202
: (args.name ?? `datamate-${slugify(datamate.name)}`)
213203

214204
const creds = transport ? undefined : await AltimateApi.getCredentials()
@@ -227,54 +217,54 @@ async function handleAdd(args: { datamate_id?: string; name?: string; scope?: "p
227217
const configPath = await resolveConfigPath(isGlobal ? Global.Path.config : projectRoot(), isGlobal)
228218

229219
if (transport !== null) {
230-
// IDE/extension mode: check if EXTENSION_DATAMATE_SERVER is already wired up
220+
// IDE/extension mode: check if DATAMATE_KEY is already wired up
231221
const existingNames = await listMcpInConfig(configPath)
232222
const staleEntries = existingNames.filter(
233-
(n) => n !== EXTENSION_DATAMATE_SERVER && n.startsWith("datamate-"),
223+
(n) => n !== DATAMATE_KEY && n.startsWith("datamate-"),
234224
)
235225
if (staleEntries.length > 0) {
236226
log.info("handleAdd: stale per-datamate entries detected alongside extension gateway", {
237227
staleEntries,
238228
})
239229
}
240230

241-
if (existingNames.includes(EXTENSION_DATAMATE_SERVER)) {
231+
if (existingNames.includes(DATAMATE_KEY)) {
242232
// Already in config — just ensure it is connected in this session
243233
const allStatus = await MCP.status()
244-
if (allStatus[EXTENSION_DATAMATE_SERVER]?.status === "connected") {
234+
if (allStatus[DATAMATE_KEY]?.status === "connected") {
245235
log.info("handleAdd: already connected, skipping add", {
246-
serverName: EXTENSION_DATAMATE_SERVER,
236+
serverName: DATAMATE_KEY,
247237
})
248238
const mcpTools = await MCP.tools()
249239
const toolCount = Object.keys(mcpTools).filter((k) =>
250-
k.startsWith(EXTENSION_DATAMATE_SERVER + "_"),
240+
k.startsWith(DATAMATE_KEY + "_"),
251241
).length
252242
const staleNote =
253243
staleEntries.length > 0
254244
? `\n\nNote: stale per-datamate entries found in config: ${staleEntries.join(", ")} — use operation 'remove' to clean them up.`
255245
: ""
256246
return {
257-
title: `Datamate '${datamate.name}': already connected via '${EXTENSION_DATAMATE_SERVER}'`,
258-
metadata: { serverName: EXTENSION_DATAMATE_SERVER, datamateId: args.datamate_id, toolCount },
259-
output: `Datamate tools are already available via the '${EXTENSION_DATAMATE_SERVER}' MCP server (${toolCount} tools active).${staleNote}`,
247+
title: `Datamate '${datamate.name}': already connected via '${DATAMATE_KEY}'`,
248+
metadata: { serverName: DATAMATE_KEY, datamateId: args.datamate_id, toolCount },
249+
output: `Datamate tools are already available via the '${DATAMATE_KEY}' MCP server (${toolCount} tools active).${staleNote}`,
260250
}
261251
}
262252
// In config but not connected — reconnect via MCP.connect() so persistMcpEnabled
263253
// is called and the enabled:true state survives the next session restart.
264254
// Bug-fix: was previously MCP.add() which skips persistMcpEnabled, so a session
265255
// that had the server disabled would not re-enable it on the next restart.
266256
log.info("handleAdd: reconnecting existing datamate entry", {
267-
serverName: EXTENSION_DATAMATE_SERVER,
257+
serverName: DATAMATE_KEY,
268258
})
269-
await MCP.connect(EXTENSION_DATAMATE_SERVER)
259+
await MCP.connect(DATAMATE_KEY)
270260
} else {
271261
// Not in config yet — write to disk then connect
272262
log.info("handleAdd: adding new datamate entry", {
273-
serverName: EXTENSION_DATAMATE_SERVER,
263+
serverName: DATAMATE_KEY,
274264
type: mcpConfig.type,
275265
})
276-
await addMcpToConfig(EXTENSION_DATAMATE_SERVER, { ...mcpConfig, enabled: true }, configPath)
277-
await MCP.add(EXTENSION_DATAMATE_SERVER, mcpConfig)
266+
await addMcpToConfig(DATAMATE_KEY, { ...mcpConfig, enabled: true }, configPath)
267+
await MCP.add(DATAMATE_KEY, mcpConfig)
278268
}
279269
} else {
280270
// Standalone/CLI mode — original behaviour: per-datamate name + cloud URL
@@ -285,7 +275,6 @@ async function handleAdd(args: { datamate_id?: string; name?: string; scope?: "p
285275
await addMcpToConfig(serverName, { ...mcpConfig, enabled: true }, configPath)
286276
await MCP.add(serverName, mcpConfig)
287277
}
288-
// altimate_change end
289278

290279
// Check connection status
291280
const allStatus = await MCP.status()

packages/opencode/src/altimate/tools/mcp-discover.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ function safeDetail(server: { type: string } & Record<string, any>): string {
3636
return `(${server.type})`
3737
}
3838

39-
// altimate_change start — strip session-specific env vars before persisting
4039
// discovered servers. ALTIMATE_EXTENSION_RPC is a Unix socket path that is
4140
// unique to the current VS Code extension host process. Writing it to disk
4241
// causes altimate-code on a future session (or a different VS Code window) to
@@ -50,7 +49,6 @@ function stripSessionEnv(cfg: import("../../config/config").Config.Mcp): import(
5049
const { ALTIMATE_EXTENSION_RPC: _rpc, ...rest } = cfg.environment
5150
return { ...cfg, environment: Object.keys(rest).length > 0 ? rest : undefined }
5251
}
53-
// altimate_change end
5452

5553
export const McpDiscoverTool = Tool.define("mcp_discover", {
5654
description:
@@ -127,7 +125,6 @@ export const McpDiscoverTool = Tool.define("mcp_discover", {
127125
)
128126

129127
for (const name of toAdd) {
130-
// altimate_change start — strip session-specific ALTIMATE_EXTENSION_RPC and
131128
// strip the discovery-time flag. Project-scoped discovery sets
132129
// as a security default (no auto-connect until user approves).
133130
// When the user explicitly adds a server via this tool, it should be enabled.
@@ -136,7 +133,6 @@ export const McpDiscoverTool = Tool.define("mcp_discover", {
136133
// Connect immediately so /mcps reflects the server status in the current session
137134
// without requiring a restart.
138135
await MCP.connect(name)
139-
// altimate_change end
140136
}
141137

142138
lines.push(`\nAdded ${toAdd.length} server(s) to ${configPath}: ${toAdd.join(", ")}`)

0 commit comments

Comments
 (0)