Skip to content

Commit 1cf8025

Browse files
suryaiyer95claude
andcommitted
fix: show built-in commands immediately without waiting for MCP
Extract `defaults()` so `/init`, `/discover`, `/review` are available in the command list before MCP servers and skills finish loading. Uses `Promise.race` in `get()` and `list()` to return defaults as a fallback while the full state resolves asynchronously. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 80f08d6 commit 1cf8025

File tree

1 file changed

+25
-6
lines changed
  • packages/altimate-code/src/command

1 file changed

+25
-6
lines changed

packages/altimate-code/src/command/index.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ export namespace Command {
5959
REVIEW: "review",
6060
} as const
6161

62-
const state = Instance.state(async () => {
63-
const cfg = await Config.get()
64-
65-
const result: Record<string, Info> = {
62+
// Default commands are available immediately; MCP prompts and skills are merged asynchronously
63+
// so that /init, /discover, /review show up in the command list without waiting for MCP connections.
64+
function defaults(): Record<string, Info> {
65+
return {
6666
[Default.INIT]: {
6767
name: Default.INIT,
6868
description: "create/update AGENTS.md",
@@ -92,6 +92,12 @@ export namespace Command {
9292
hints: hints(PROMPT_REVIEW),
9393
},
9494
}
95+
}
96+
97+
const state = Instance.state(async () => {
98+
const result: Record<string, Info> = defaults()
99+
100+
const cfg = await Config.get()
95101

96102
for (const [name, command] of Object.entries(cfg.command ?? {})) {
97103
result[name] = {
@@ -165,10 +171,23 @@ export namespace Command {
165171
})
166172

167173
export async function get(name: string) {
168-
return state().then((x) => x[name])
174+
// If the full state hasn't resolved yet, check defaults first so built-in
175+
// commands like /discover are usable before MCP servers connect.
176+
const full = state()
177+
const resolved = await Promise.race([full, Promise.resolve(undefined)])
178+
if (resolved) return resolved[name]
179+
// Full state still loading — fall back to defaults
180+
const fallback = defaults()[name]
181+
if (fallback) return fallback
182+
// Not a default command — wait for full resolution
183+
return full.then((x) => x[name])
169184
}
170185

171186
export async function list() {
172-
return state().then((x) => Object.values(x))
187+
const full = state()
188+
const resolved = await Promise.race([full, Promise.resolve(undefined)])
189+
if (resolved) return Object.values(resolved)
190+
// Full state still loading — return defaults immediately
191+
return Object.values(defaults())
173192
}
174193
}

0 commit comments

Comments
 (0)