singularity-forge/src
Mikael Hugo 8fa9a4b8fa fix(quota): match real API shapes for kimi-coding / minimax / zai
Dogfooded `sf headless usage` against live APIs and discovered three
shape mismatches in the phase-1 fetchers:

- kimi-coding returns numeric fields as STRINGS ("limit": "100") and
  uses camelCase `resetTime`. Added toNum() coercion + reset hint
  extraction. Now reports Weekly + 5h rolling windows correctly.

- minimax response is `{ model_remains: [{ model_name,
  current_interval_total_count, current_interval_usage_count,
  current_weekly_total_count, current_weekly_usage_count, end_time,
  weekly_end_time, ...}] }` — per-model rolling + weekly windows, not
  the flat `remaining_tokens`/`total_tokens` shape I had assumed.
  Rewrote parser to emit one window per model entry.

- zai uses a `{ code, msg, success, data }` envelope. When
  `success: false` (e.g. user lacks an active coding plan), parser
  now surfaces vendor msg as the entry error instead of silently
  emitting no windows.

Tests updated to mirror real shapes; added one for zai's failure
envelope. 12 tests pass (was 11).

Live result from re-running `sf headless usage`:
  - openrouter: 80.7% used, $7.71 remaining (real signal — watch this)
  - kimi-coding: Weekly 32%, 5h 4%
  - minimax: MiniMax-M* 5h 1.4% + coding-plan-vlm/search 1.4%
  - gemini-cli: 0.0-0.4% across all models (clean)
  - zai: surfaces "user does not have a coding plan" — may need a
    different endpoint or scope depending on the user's account setup.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 17:59:53 +02:00
..
resources fix(quota): match real API shapes for kimi-coding / minimax / zai 2026-05-16 17:59:53 +02:00
tests fix(headless): remove legacy v1 fallback path 2026-05-15 20:12:00 +02:00
web feat(notifications): tag remaining auto/loop/register-hooks notices + trace-writer 2026-05-10 20:14:22 +02:00
app-paths.ts sf snapshot: uncommitted changes after 93m inactivity 2026-05-06 11:37:27 +02:00
bundled-extension-paths.ts
bundled-resource-path.ts
claude-cli-check.ts
cli-key.ts feat(cli): add sf key subcommand for auth.json management 2026-05-15 16:37:04 +02:00
cli-logs.ts sf snapshot: uncommitted changes after 93m inactivity 2026-05-06 11:37:27 +02:00
cli-stats.ts
cli-status.ts feat(notifications): NOTICE_KIND enum, schema v2 dedup, sf-db cleanup 2026-05-10 20:13:58 +02:00
cli-web-branch.ts sf snapshot: uncommitted changes after 33m inactivity 2026-05-16 17:00:13 +02:00
cli.ts feat(catalog/quota): global model catalog, benchmark coverage audit, provider quota visibility 2026-05-16 17:37:20 +02:00
env.ts fix(env): align SF_PERMISSION_LEVEL enum with permission-profile values 2026-05-14 21:11:36 +02:00
errors.ts
extension-discovery.ts fix: consolidate extensions into sf, migrate kernel.ts, fix test suite 2026-05-11 02:40:52 +02:00
extension-registry.ts
headless-answers.ts refactor: rename pi-* packages to forge-native names (Phase 1) 2026-05-10 11:28:01 +02:00
headless-context.ts refactor: align agent resource overlays 2026-05-14 19:32:41 +02:00
headless-events.ts fix(headless): do not restart graceful child exits 2026-05-15 07:25:06 +02:00
headless-feedback.ts feat(self-feedback): purpose_anchor on entries (ADR-0000 restoration, v71) 2026-05-15 18:51:52 +02:00
headless-import-backlog.ts sf snapshot: uncommitted changes after 49m inactivity 2026-05-12 16:45:04 +02:00
headless-mark-state.ts feat(memory): add debug logging to memory extraction pipeline 2026-05-15 16:09:36 +02:00
headless-query.ts feat(headless): surface memory auth pause 2026-05-15 18:16:08 +02:00
headless-reflect.ts refactor(reflect): route reflection-pass through loadPrompt in extension 2026-05-14 06:20:38 +02:00
headless-status.ts fix(headless): bypass rpc for status 2026-05-15 17:32:21 +02:00
headless-triage.ts feat(prompts): add v2 migration regression tests + fix template variable drift 2026-05-15 19:46:13 +02:00
headless-types.ts feat(notifications): NOTICE_KIND enum, schema v2 dedup, sf-db cleanup 2026-05-10 20:13:58 +02:00
headless-ui.ts refactor: rename pi-* packages to forge-native names (Phase 1) 2026-05-10 11:28:01 +02:00
headless-uok-status.ts fix(uok-status): surface manualAttention bucket in status uok output 2026-05-14 18:46:28 +02:00
headless-usage.ts feat(catalog/quota): global model catalog, benchmark coverage audit, provider quota visibility 2026-05-16 17:37:20 +02:00
headless.ts fix(headless): remove legacy v1 fallback path 2026-05-15 20:12:00 +02:00
help-text.ts feat(self-feedback): purpose_anchor on entries (ADR-0000 restoration, v71) 2026-05-15 18:51:52 +02:00
interactive-session-lock.ts fix: enforce one interactive sf per repo 2026-05-05 20:55:53 +02:00
loader.ts fix(lint): reformat 6 files touched during web dep upgrade 2026-05-10 12:10:10 +02:00
logger.ts refactor: rename pi-* packages to forge-native names (Phase 1) 2026-05-10 11:28:01 +02:00
logo.ts
models-resolver.ts
onboarding.ts refactor: rename pi-* packages to forge-native names (Phase 1) 2026-05-10 11:28:01 +02:00
pi-migration.ts refactor: rename pi-* packages to forge-native names (Phase 1) 2026-05-10 11:28:01 +02:00
project-sessions.ts
provider-migrations.ts refactor: rename pi-* packages to forge-native names (Phase 1) 2026-05-10 11:28:01 +02:00
remote-questions-config.ts
resource-loader.ts fix: repair headless runtime self-healing 2026-05-15 03:33:29 +02:00
rtk.ts
security-overrides.ts refactor: rename pi-* packages to forge-native names (Phase 1) 2026-05-10 11:28:01 +02:00
startup-model-validation.ts
startup-timings.ts
tool-bootstrap.ts
traces.ts sf snapshot: uncommitted changes after 49m inactivity 2026-05-08 01:07:24 +02:00
update-check.ts
update-cmd.ts
web-mode.ts
welcome-screen.ts fix: update test snapshots for queryInstruction and complete /sf prefix Phase 2 deprecation 2026-05-09 00:17:47 +02:00
wizard.ts refactor: rename pi-* packages to forge-native names (Phase 1) 2026-05-10 11:28:01 +02:00
worktree-cli.ts sf snapshot: uncommitted changes after 43m inactivity 2026-05-05 21:39:56 +02:00
worktree-name-gen.ts