@getrouter/getrouter-cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/.github/workflows/ci.yml +19 -0
  2. package/AGENTS.md +78 -0
  3. package/README.ja.md +116 -0
  4. package/README.md +116 -0
  5. package/README.zh-cn.md +116 -0
  6. package/biome.json +10 -0
  7. package/bun.lock +397 -0
  8. package/dist/bin.mjs +1422 -0
  9. package/docs/plans/2026-01-01-getrouter-cli-config-command-plan.md +231 -0
  10. package/docs/plans/2026-01-01-getrouter-cli-config-core-plan.md +307 -0
  11. package/docs/plans/2026-01-01-getrouter-cli-design.md +106 -0
  12. package/docs/plans/2026-01-01-getrouter-cli-scaffold-plan.md +327 -0
  13. package/docs/plans/2026-01-02-getrouter-cli-auth-design.md +68 -0
  14. package/docs/plans/2026-01-02-getrouter-cli-auth-device-design.md +73 -0
  15. package/docs/plans/2026-01-02-getrouter-cli-auth-device-plan.md +411 -0
  16. package/docs/plans/2026-01-02-getrouter-cli-auth-plan.md +435 -0
  17. package/docs/plans/2026-01-02-getrouter-cli-http-client-plan.md +235 -0
  18. package/docs/plans/2026-01-02-getrouter-cli-keys-create-update-output-design.md +24 -0
  19. package/docs/plans/2026-01-02-getrouter-cli-keys-create-update-output-plan.md +141 -0
  20. package/docs/plans/2026-01-02-getrouter-cli-keys-delete-output-design.md +22 -0
  21. package/docs/plans/2026-01-02-getrouter-cli-keys-delete-output-plan.md +122 -0
  22. package/docs/plans/2026-01-02-getrouter-cli-keys-get-output-design.md +23 -0
  23. package/docs/plans/2026-01-02-getrouter-cli-keys-get-output-plan.md +141 -0
  24. package/docs/plans/2026-01-02-getrouter-cli-keys-interactive-design.md +28 -0
  25. package/docs/plans/2026-01-02-getrouter-cli-keys-interactive-plan.md +247 -0
  26. package/docs/plans/2026-01-02-getrouter-cli-keys-output-design.md +31 -0
  27. package/docs/plans/2026-01-02-getrouter-cli-keys-output-plan.md +187 -0
  28. package/docs/plans/2026-01-02-getrouter-cli-keys-subscription-design.md +52 -0
  29. package/docs/plans/2026-01-02-getrouter-cli-keys-subscription-plan.md +306 -0
  30. package/docs/plans/2026-01-02-getrouter-cli-setup-env-design.md +67 -0
  31. package/docs/plans/2026-01-02-getrouter-cli-setup-env-plan.md +441 -0
  32. package/docs/plans/2026-01-02-getrouter-cli-subscription-output-design.md +34 -0
  33. package/docs/plans/2026-01-02-getrouter-cli-subscription-output-plan.md +157 -0
  34. package/docs/plans/2026-01-03-bun-migration-plan.md +103 -0
  35. package/docs/plans/2026-01-03-cli-emoji-output.md +45 -0
  36. package/docs/plans/2026-01-03-cli-english-output.md +123 -0
  37. package/docs/plans/2026-01-03-cli-simplify-design.md +62 -0
  38. package/docs/plans/2026-01-03-cli-simplify-implementation.md +468 -0
  39. package/docs/plans/2026-01-03-readme-command-descriptions.md +116 -0
  40. package/docs/plans/2026-01-03-tsdown-migration-plan.md +75 -0
  41. package/docs/plans/2026-01-04-cli-docs-cleanup-design.md +49 -0
  42. package/docs/plans/2026-01-04-cli-docs-cleanup-plan.md +126 -0
  43. package/docs/plans/2026-01-04-codex-multistep-design.md +76 -0
  44. package/docs/plans/2026-01-04-codex-multistep-plan.md +240 -0
  45. package/docs/plans/2026-01-04-env-hook-design.md +48 -0
  46. package/docs/plans/2026-01-04-env-hook-plan.md +173 -0
  47. package/docs/plans/2026-01-04-models-keys-fuzzy-design.md +75 -0
  48. package/docs/plans/2026-01-04-models-keys-fuzzy-implementation.md +704 -0
  49. package/package.json +37 -0
  50. package/src/.gitkeep +0 -0
  51. package/src/bin.ts +4 -0
  52. package/src/cli.ts +12 -0
  53. package/src/cmd/auth.ts +44 -0
  54. package/src/cmd/claude.ts +10 -0
  55. package/src/cmd/codex.ts +119 -0
  56. package/src/cmd/config-helpers.ts +16 -0
  57. package/src/cmd/config.ts +31 -0
  58. package/src/cmd/env.ts +103 -0
  59. package/src/cmd/index.ts +20 -0
  60. package/src/cmd/keys.ts +207 -0
  61. package/src/cmd/models.ts +48 -0
  62. package/src/cmd/status.ts +106 -0
  63. package/src/cmd/usages.ts +29 -0
  64. package/src/core/api/client.ts +79 -0
  65. package/src/core/auth/device.ts +105 -0
  66. package/src/core/auth/index.ts +37 -0
  67. package/src/core/config/fs.ts +13 -0
  68. package/src/core/config/index.ts +37 -0
  69. package/src/core/config/paths.ts +5 -0
  70. package/src/core/config/redact.ts +18 -0
  71. package/src/core/config/types.ts +23 -0
  72. package/src/core/http/errors.ts +32 -0
  73. package/src/core/http/request.ts +41 -0
  74. package/src/core/http/url.ts +12 -0
  75. package/src/core/interactive/clipboard.ts +61 -0
  76. package/src/core/interactive/codex.ts +75 -0
  77. package/src/core/interactive/fuzzy.ts +64 -0
  78. package/src/core/interactive/keys.ts +164 -0
  79. package/src/core/output/table.ts +34 -0
  80. package/src/core/output/usages.ts +75 -0
  81. package/src/core/paths.ts +4 -0
  82. package/src/core/setup/codex.ts +129 -0
  83. package/src/core/setup/env.ts +220 -0
  84. package/src/core/usages/aggregate.ts +69 -0
  85. package/src/generated/router/dashboard/v1/index.ts +1104 -0
  86. package/src/index.ts +1 -0
  87. package/tests/.gitkeep +0 -0
  88. package/tests/auth/device.test.ts +75 -0
  89. package/tests/auth/status.test.ts +64 -0
  90. package/tests/cli.test.ts +31 -0
  91. package/tests/cmd/auth.test.ts +90 -0
  92. package/tests/cmd/claude.test.ts +132 -0
  93. package/tests/cmd/codex.test.ts +147 -0
  94. package/tests/cmd/config-helpers.test.ts +18 -0
  95. package/tests/cmd/config.test.ts +56 -0
  96. package/tests/cmd/keys.test.ts +163 -0
  97. package/tests/cmd/models.test.ts +63 -0
  98. package/tests/cmd/status.test.ts +82 -0
  99. package/tests/cmd/usages.test.ts +42 -0
  100. package/tests/config/fs.test.ts +14 -0
  101. package/tests/config/index.test.ts +63 -0
  102. package/tests/config/paths.test.ts +10 -0
  103. package/tests/config/redact.test.ts +17 -0
  104. package/tests/config/types.test.ts +10 -0
  105. package/tests/core/api/client.test.ts +92 -0
  106. package/tests/core/interactive/clipboard.test.ts +44 -0
  107. package/tests/core/interactive/codex.test.ts +17 -0
  108. package/tests/core/interactive/fuzzy.test.ts +30 -0
  109. package/tests/core/setup/codex.test.ts +38 -0
  110. package/tests/core/setup/env.test.ts +84 -0
  111. package/tests/core/usages/aggregate.test.ts +55 -0
  112. package/tests/http/errors.test.ts +15 -0
  113. package/tests/http/request.test.ts +82 -0
  114. package/tests/http/url.test.ts +17 -0
  115. package/tests/output/table.test.ts +29 -0
  116. package/tests/output/usages.test.ts +71 -0
  117. package/tests/paths.test.ts +9 -0
  118. package/tsconfig.json +13 -0
  119. package/tsdown.config.ts +5 -0
  120. package/vitest.config.ts +7 -0
@@ -0,0 +1,103 @@
1
+ # Bun Migration Implementation Plan
2
+
3
+ > **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
4
+
5
+ **Goal:** Make Bun the default package manager/tooling for the repo, remove npm lockfile, and add Bun-based CI.
6
+
7
+ **Architecture:** Replace npm usage with Bun in docs and CI, generate `bun.lock`, add `packageManager` in `package.json`, and delete `package-lock.json`.
8
+
9
+ **Tech Stack:** Bun, GitHub Actions, TypeScript.
10
+
11
+ ### Task 1: Switch lockfile + package metadata
12
+
13
+ **Files:**
14
+ - Modify: `package.json`
15
+ - Delete: `package-lock.json`
16
+ - Create: `bun.lock`
17
+
18
+ **Step 1: Add Bun packageManager field**
19
+
20
+ Edit `package.json`:
21
+ ```json
22
+ "packageManager": "bun@1.3.5"
23
+ ```
24
+
25
+ **Step 2: Remove npm lockfile**
26
+
27
+ Delete `package-lock.json`.
28
+
29
+ **Step 3: Generate Bun lockfile**
30
+
31
+ Run:
32
+ ```bash
33
+ bun install
34
+ ```
35
+ Expected: `bun.lock` created.
36
+
37
+ ### Task 2: Update contributor docs to Bun
38
+
39
+ **Files:**
40
+ - Modify: `README.md`
41
+ - Modify: `AGENTS.md`
42
+
43
+ **Step 1: Update README install/dev/test commands (English + Chinese)**
44
+
45
+ Examples:
46
+ ```md
47
+ bun install
48
+ bun run build
49
+ bun run dev -- --help
50
+ bun run test
51
+ bun run typecheck
52
+ ```
53
+
54
+ **Step 2: Update AGENTS build/test commands to Bun**
55
+
56
+ Replace `npm` commands with `bun run` equivalents.
57
+
58
+ ### Task 3: Add Bun-based GitHub Actions
59
+
60
+ **Files:**
61
+ - Create: `.github/workflows/ci.yml`
62
+
63
+ **Step 1: Add CI workflow**
64
+
65
+ ```yaml
66
+ name: CI
67
+ on:
68
+ push:
69
+ branches: [main]
70
+ pull_request:
71
+
72
+ jobs:
73
+ ci:
74
+ runs-on: ubuntu-latest
75
+ steps:
76
+ - uses: actions/checkout@v4
77
+ - uses: oven-sh/setup-bun@v1
78
+ with:
79
+ bun-version: "1.3.5"
80
+ - run: bun install --frozen-lockfile
81
+ - run: bun run typecheck
82
+ - run: bun run test
83
+ - run: bun run build
84
+ ```
85
+
86
+ ### Task 4: Verify and commit
87
+
88
+ **Step 1: Run Bun checks locally**
89
+
90
+ Run:
91
+ ```bash
92
+ bun run typecheck
93
+ bun run test
94
+ ```
95
+ Expected: PASS.
96
+
97
+ **Step 2: Commit**
98
+
99
+ ```bash
100
+ git add package.json bun.lock README.md AGENTS.md .github/workflows/ci.yml
101
+ git rm package-lock.json
102
+ git commit -m "chore: migrate tooling to bun"
103
+ ```
@@ -0,0 +1,45 @@
1
+ # CLI Emoji Output Implementation Plan
2
+
3
+ > **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
4
+
5
+ **Goal:** Add minimal emoji to interactive prompts and key status messages (login + confirmation) while keeping errors plain.
6
+
7
+ **Architecture:** Update user-facing string literals in auth flow and interactive key prompts; adjust tests to match new output.
8
+
9
+ **Tech Stack:** TypeScript, Vitest.
10
+
11
+ ### Task 1: Add emoji to interactive/auth output strings
12
+
13
+ **Files:**
14
+ - Modify: `src/cmd/auth.ts`
15
+ - Modify: `src/core/interactive/keys.ts`
16
+
17
+ **Step 1: Update auth login output**
18
+
19
+ ```ts
20
+ console.log("🔐 To authenticate, visit:");
21
+ console.log("⏳ Waiting for confirmation...");
22
+ console.log("✅ Login successful.");
23
+ ```
24
+
25
+ **Step 2: Update key selection/delete prompts**
26
+
27
+ ```ts
28
+ throw new Error("No available API keys");
29
+ message: "🔎 Select an API key",
30
+ message: `⚠️ Confirm delete ${name} (${id})?`,
31
+ ```
32
+
33
+ ### Task 2: Verify and commit
34
+
35
+ **Step 1: Run targeted tests**
36
+
37
+ Run: `npm test -- tests/cmd/auth.test.ts tests/cmd/keys.test.ts`
38
+ Expected: PASS. (No test updates expected; update assertions only if failures mention output strings.)
39
+
40
+ **Step 2: Commit**
41
+
42
+ ```bash
43
+ git add src tests
44
+ git commit -m "feat: add emoji to interactive cli output"
45
+ ```
@@ -0,0 +1,123 @@
1
+ # CLI English Output Implementation Plan
2
+
3
+ > **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
4
+
5
+ **Goal:** Replace all Chinese CLI user-facing strings with English equivalents and update tests.
6
+
7
+ **Architecture:** Update string literals in command handlers and interactive prompts, then update test expectations to match.
8
+
9
+ **Tech Stack:** TypeScript, Vitest.
10
+
11
+ ### Task 1: Update CLI output strings in source
12
+
13
+ **Files:**
14
+ - Modify: `src/cmd/auth.ts`
15
+ - Modify: `src/core/auth/device.ts`
16
+ - Modify: `src/cmd/keys.ts`
17
+ - Modify: `src/cmd/subscription.ts`
18
+ - Modify: `src/cmd/setup.ts`
19
+ - Modify: `src/core/interactive/keys.ts`
20
+
21
+ **Step 1: Update auth command output**
22
+
23
+ ```ts
24
+ console.log("Login successful.");
25
+ console.log("Cleared local auth data.");
26
+ ```
27
+
28
+ **Step 2: Update device auth error messages**
29
+
30
+ ```ts
31
+ throw new Error("Auth code already used. Please log in again.");
32
+ throw new Error("Auth code expired. Please log in again.");
33
+ throw new Error("Login timed out. Please run getrouter auth login again.");
34
+ ```
35
+
36
+ **Step 3: Update keys command errors and success message**
37
+
38
+ ```ts
39
+ throw new Error("Missing key id.");
40
+ console.log("Please store this API key securely.");
41
+ ```
42
+
43
+ **Step 4: Update subscription status message**
44
+
45
+ ```ts
46
+ console.log("No active subscription");
47
+ ```
48
+
49
+ **Step 5: Update setup errors**
50
+
51
+ ```ts
52
+ throw new Error("Missing key id.");
53
+ throw new Error("API key not found. Please create one or choose another.");
54
+ ```
55
+
56
+ **Step 6: Update interactive prompts**
57
+
58
+ ```ts
59
+ throw new Error("No available API keys");
60
+ message: "Select an API key",
61
+ message: `Confirm delete ${name} (${id})?`,
62
+ ```
63
+
64
+ ### Task 2: Update test expectations
65
+
66
+ **Files:**
67
+ - Modify: `tests/auth/device.test.ts`
68
+ - Modify: `tests/cmd/setup.test.ts`
69
+ - Modify: `tests/cmd/subscription.test.ts`
70
+ - Modify: `tests/cmd/auth.test.ts`
71
+ - Modify: `tests/cmd/keys.test.ts`
72
+
73
+ **Step 1: Update device auth error assertions**
74
+
75
+ ```ts
76
+ ).rejects.toThrow("Auth code already used");
77
+ ).rejects.toThrow("Auth code expired");
78
+ ).rejects.toThrow("Login timed out");
79
+ ```
80
+
81
+ **Step 2: Update setup error assertion**
82
+
83
+ ```ts
84
+ ).rejects.toThrow("Missing key id");
85
+ ```
86
+
87
+ **Step 3: Update subscription output assertion**
88
+
89
+ ```ts
90
+ expect(output).toContain("No active subscription");
91
+ ```
92
+
93
+ **Step 4: Update auth logout output assertion**
94
+
95
+ ```ts
96
+ expect(log.mock.calls[0][0]).toContain("Cleared local auth data");
97
+ ```
98
+
99
+ **Step 5: Update keys output/error assertions**
100
+
101
+ ```ts
102
+ expect(output).toContain("Please store this API key securely.");
103
+ ).rejects.toThrow("Missing key id");
104
+ ```
105
+
106
+ ### Task 3: Verify and commit
107
+
108
+ **Step 1: Confirm no Chinese text remains in src/tests**
109
+
110
+ Run: `rg -n "[\u4e00-\u9fff]" src tests`
111
+ Expected: no matches.
112
+
113
+ **Step 2: Run targeted tests**
114
+
115
+ Run: `npm test -- tests/auth/device.test.ts tests/cmd/auth.test.ts tests/cmd/keys.test.ts tests/cmd/setup.test.ts tests/cmd/subscription.test.ts`
116
+ Expected: PASS.
117
+
118
+ **Step 3: Commit**
119
+
120
+ ```bash
121
+ git add src tests
122
+ git commit -m "refactor: switch cli output to English"
123
+ ```
@@ -0,0 +1,62 @@
1
+ # CLI 简化方案设计
2
+
3
+ ## 目标
4
+ - 将 CLI 命令体系简化为一级命令,替换原有二级命令(auth/keys/subscription/setup 等)。
5
+ - 输出美化,必要时使用 emoji,保留一致性与可读性。
6
+ - 兼容新的 usages API,并提供最近 7 天聚合可视化。
7
+
8
+ ## 命令体系
9
+ - `getrouter login` / `getrouter logout`
10
+ - 替代 `getrouter auth login/logout`。
11
+ - `getrouter keys`
12
+ - 进入交互菜单,支持:列表 / 查看 / 创建 / 更新 / 删除 / 退出。
13
+ - 删除需 y/N 二次确认;完成某操作后回到菜单。
14
+ - `getrouter usages`
15
+ - 默认展示最近 7 天按天聚合使用量,堆叠柱状图 + 表格。
16
+ - `getrouter status`
17
+ - 统一展示登录状态 + 订阅状态。
18
+ - 登录仅显示状态与过期时间,不展示 token。
19
+ - `getrouter codex` / `getrouter claude`
20
+ - 取代 `setup env`,仅保留 `--install`。
21
+ - codex 只写 OpenAI 变量,claude 只写 Anthropic 变量。
22
+ - 多 key 时进入交互选择。
23
+ - `getrouter config`
24
+ - 简化为:`getrouter config` 显示全部;`getrouter config <key> <value>` 设置。
25
+ - 去掉 `--json`。
26
+
27
+ 移除:`models/plans/providers/user/setup` 以及旧的二级命令入口。
28
+
29
+ ## 输出与交互
30
+ ### status
31
+ - 以“状态卡片”风格输出两块:登录状态 + 订阅状态。
32
+ - 登录块:status + expiresAt(不显示 token)。
33
+ - 订阅块:plan / status / startAt / endAt / requestPerMinute / tokenPerMinute。
34
+ - 无订阅时提示“无有效订阅”。
35
+
36
+ ### usages
37
+ - 接口:`GET v1/dashboard/usages`(pageSize/pageToken)。
38
+ - 拉取策略:逐页拉取,按本地时区聚合日期,直到 7 天或数据耗尽。
39
+ - 输出包含:
40
+ 1) 堆叠柱状图(默认显示,input/output 分段)
41
+ 2) 表格(日、input/output/total tokens、请求数若可得)
42
+ - 不区分 TTY/管道,默认都显示图 + 表。
43
+
44
+ ### keys
45
+ - 交互菜单:列表 / 查看 / 创建 / 更新 / 删除 / 退出。
46
+ - 查看/删除:无 id 时进入选择列表。
47
+ - 更新仅支持 `name` 和 `enabled`。
48
+ - 删除需 y/N 确认。
49
+
50
+ ## 环境配置(codex/claude)
51
+ - 仅保留 `--install`。
52
+ - 写入 `~/.getrouter/env.sh` 或 `env.ps1`,Base URL 固定 `https://api.getrouter.dev/v1`。
53
+ - `--install` 时:
54
+ - 自动判断 shell(zsh/bash/fish/pwsh)写入 rc。
55
+ - **立即生效策略**:
56
+ 1) 更新当前 CLI 进程的 `process.env`;
57
+ 2) best‑effort 执行一次 `source` / `. <path>`(PowerShell 使用 `. <path>`)。
58
+ - 若 source 失败,提示用户手动执行。
59
+
60
+ ## 实现注意
61
+ - `usages` 需要更新 CLI 的生成代码以引入 `UsageService`。
62
+ - 新命令与输出均移除 `--json` 选项,仅保留美化输出。