Skip to content

Commit cf4203d

Browse files
committed
feat: show account status badges in auth menu (active/expired/rate-limited)
1 parent 08d128a commit cf4203d

3 files changed

Lines changed: 29 additions & 26 deletions

File tree

README.md

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,22 @@ Rules:
6464
Steps:
6565
1. Validate tools:
6666
- Run: opencode --version
67-
68-
2. Locate OpenCode config:
69-
- Run: CONFIG=$(find "$HOME/.config" -name "opencode.json*" -type f 2>/dev/null | head -1)
70-
- Verify: echo "Found config: $CONFIG"
71-
72-
3. Update OpenCode config:
73-
- Read current config: cat "$CONFIG"
74-
- If "plugin" array doesn't exist, add it after "$schema":
75-
{"$schema": "...", "plugin": []}
67+
2. Update OpenCode config:
68+
- File: ~/.config/opencode/opencode.json or ~/.config/opencode/opencode.jsonc
7669
- Ensure the plugin array includes: "@itssimplereally/opencode-kimicode-auth@latest"
70+
- If no plugin array exists, create it under `$schema` key as `"plugin": ["@itssimplereally/opencode-kimicode-auth@latest"]`
7771
- Preserve all other existing plugin entries.
78-
- Write updated config back to "$CONFIG"
79-
80-
4. Verify OpenCode starts cleanly:
72+
3. Verify OpenCode starts cleanly:
8173
- Run: opencode auth list
8274
- If plugin install/import errors occur, fix the plugin entry first.
83-
84-
5. **Do not attempt interactive auth in this session.**
85-
- Ask the human to run: opencode auth login
86-
- Ask the human to choose provider "Moonshot AI" and method "OAuth (Kimi Code / kimi-cli)".
75+
4. **Do not attempt interactive auth in this session.**
76+
- Ask the human to run, cleanly formatted: `opencode auth login` then select "Moonshot AI" then "OAuth (Kimi Code / kimi-cli)" and they can add multiple accounts for rotation. **Logout in the browser after authorization of each account before adding the next.**
8777
- Wait for the human to confirm they completed authorization.
88-
89-
6. After human confirmation, verify:
78+
5. After human confirmation, verify:
9079
- Run: opencode auth list
9180
- Run: opencode models moonshotai
92-
- Confirm output includes moonshotai/kimicode-kimi-k2.5 and moonshotai/kimicode-kimi-k2.5-thinking.
93-
94-
7. Return a concise report of changes and verification results.
81+
- Confirm output includes `moonshotai/kimicode-kimi-k2.5` and `moonshotai/kimicode-kimi-k2.5-thinking`.
82+
6. Return a concise report of changes and verification results.
9583
```
9684

9785
## License

src/plugin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,17 @@ function toExistingAccountsForMenu(stored: { accounts: AccountMetadataV3[]; acti
341341
index: number;
342342
addedAt?: number;
343343
lastUsed?: number;
344-
status?: "active" | "rate-limited" | "cooling-down" | "disabled" | "verification-required";
344+
status?: "active" | "rate-limited" | "cooling-down" | "disabled" | "expired";
345345
isCurrentAccount?: boolean;
346346
enabled?: boolean;
347347
}> {
348348
if (!stored?.accounts?.length) return [];
349349
const now = Date.now();
350350
return stored.accounts.map((acc, idx) => {
351-
let status: "active" | "rate-limited" | "cooling-down" | "disabled" | "verification-required" = "active";
352-
if (acc.enabled === false) {
351+
let status: "active" | "rate-limited" | "cooling-down" | "disabled" | "expired" = "active";
352+
if (acc.enabled === false && acc.cooldownReason === "auth-failure") {
353+
status = "expired";
354+
} else if (acc.enabled === false) {
353355
status = "disabled";
354356
} else if (acc.coolingDownUntil && acc.coolingDownUntil > now) {
355357
status = "cooling-down";

src/plugin/cli.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { stdin as input, stdout as output } from "node:process";
33
import { updateOpencodeConfig } from "./config/updater";
44

55
// TODO: Add UI module (./ui/auth-menu) — stubbed for now
6-
export type AccountStatus = "active" | "rate-limited" | "cooling-down" | "disabled" | "verification-required";
6+
export type AccountStatus = "active" | "rate-limited" | "cooling-down" | "disabled" | "expired";
77

88
interface AccountInfo {
99
email?: string;
@@ -15,6 +15,17 @@ interface AccountInfo {
1515
enabled?: boolean;
1616
}
1717

18+
function getStatusBadge(status: AccountStatus | undefined): string {
19+
switch (status) {
20+
case "active": return ` \x1b[32m[active]\x1b[0m`;
21+
case "rate-limited": return ` \x1b[33m[rate-limited]\x1b[0m`;
22+
case "cooling-down": return ` \x1b[33m[cooling-down]\x1b[0m`;
23+
case "disabled": return ` \x1b[31m[disabled]\x1b[0m`;
24+
case "expired": return ` \x1b[31m[expired - re-auth required]\x1b[0m`;
25+
default: return "";
26+
}
27+
}
28+
1829
function isTTY(): boolean {
1930
return process.stdout.isTTY === true && process.stdin.isTTY === true;
2031
}
@@ -62,7 +73,9 @@ async function promptLoginModeFallback(existingAccounts: ExistingAccountInfo[]):
6273
console.log(`\n${existingAccounts.length} account(s) saved:`);
6374
for (const acc of existingAccounts) {
6475
const label = acc.email || `Account ${acc.index + 1}`;
65-
console.log(` ${acc.index + 1}. ${label}`);
76+
const badge = getStatusBadge(acc.status);
77+
const currentTag = acc.isCurrentAccount ? " \x1b[36m[current]\x1b[0m" : "";
78+
console.log(` ${acc.index + 1}. ${label}${currentTag}${badge}`);
6679
}
6780
console.log("");
6881

0 commit comments

Comments
 (0)