Skip to content

Commit 7c8a913

Browse files
authored
fix(cli-precheck): probe ~/.kimi/credentials/kimi-code.json for moonshot auth (#109)
The native Kimi Code build (code.kimi.com — the one #98/#99 taught detection about) never writes ~/.kimi/auth.json. It stores its OAuth tokens in ~/.kimi/credentials/kimi-code.json, so the cred gate reported auth_missing for a user who had just logged in successfully, and the voice was blocked before it ever spawned. Additive: the existing auth.json + opencode candidates are unchanged, so the kimi-via-opencode transport is unaffected. The same candidate list backs getMostRecentCredMtime, so this also restores auto-heal after a re-login for kimi (a sticky auth_invalid had no mtime to compare against before). Reproduced locally: a logged-in kimi install has ~/.kimi/credentials/kimi-code.json (OAuth access_token + refresh_token) and no ~/.kimi/auth.json at all. Reported by @Ikkimel in the #107 thread. Co-authored-by: chorus-codes <280607145+chorus-codes@users.noreply.github.com>
1 parent f34e435 commit 7c8a913

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/lib/cli-precheck.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ const CRED_PATHS: Record<CliLineage, () => string[]> = {
8888
opencode: () => CRED_PATHS_OPENCODE(),
8989
moonshot: () => [
9090
path.join(os.homedir(), '.kimi', 'auth.json'),
91+
// The native Kimi Code build (code.kimi.com — the one #98/#99 taught
92+
// detection about) does NOT write ~/.kimi/auth.json. Its OAuth tokens
93+
// land in ~/.kimi/credentials/kimi-code.json, so a freshly logged-in
94+
// user was still gated as auth_missing on the auth.json probe alone.
95+
// This path also feeds getMostRecentCredMtime, so it restores the
96+
// auto-heal-after-relogin signal for kimi. (#107 follow-up.)
97+
path.join(os.homedir(), '.kimi', 'credentials', 'kimi-code.json'),
9198
// The kimi shim delegates to `opencode --model opencode-go/kimi-k2.6`
9299
// when the requested model carries the opencode-go/ prefix, so a
93100
// moonshot voice routed via opencode is actually authed by opencode's

tests/cli-precheck.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,20 @@ describe('precheckLineage', () => {
282282
expect(result.ok).toBe(true);
283283
});
284284

285+
it('passes for a native Kimi Code login (~/.kimi/credentials/kimi-code.json)', async () => {
286+
// The code.kimi.com build never writes ~/.kimi/auth.json — probing
287+
// that path alone gated a logged-in user as auth_missing (#107 thread).
288+
writeFakeCred('.kimi/credentials/kimi-code.json');
289+
const result = await precheckLineage('moonshot');
290+
expect(result.ok).toBe(true);
291+
});
292+
293+
it('still blocks moonshot when no kimi or opencode credential exists', async () => {
294+
const result = await precheckLineage('moonshot');
295+
expect(result.ok).toBe(false);
296+
if (!result.ok) expect(result.reason).toBe('auth_missing');
297+
});
298+
285299
it('per-lineage CTA mentions the right login command', async () => {
286300
const cases: Array<{ lineage: 'anthropic' | 'openai' | 'google' | 'opencode' | 'moonshot'; needle: RegExp }> = [
287301
{ lineage: 'anthropic', needle: /claude login/i },

0 commit comments

Comments
 (0)