{"ref":"main","files":[{"name":"include","kind":"directory","size":0,"lastCommitHash":"333f8ab4c645ff06291ada42831416db26dcb9fc","lastCommitWhen":"2026-09-28T07:36:35+03:00","lastCommitMessage":"feat(core): give limits an id, windowSeconds and scope, and read advance from stdin\n\nA host tracking quota over time needs to key a limit, know its window, and know which usage\ncounts against it; `label` is display text and says none of that reliably. ABI 4 adds three\nfields to every limit:\n\n- `id`, a stable machine key within the provider: anthropic's `kind`, codex's\n  `primary`/`secondary` and `<metered_feature>.<window>`, antigravity's family, opencode's\n  window key, zai's `<type>:<unit>:<number>` (one type can repeat with another period),\n  alibaba's `five_hour`/`weekly`, hyper's `hypercredits`.\n- `windowSeconds`, when the provider states it (codex's `limit_window_seconds`, hyper's refresh\n  endpoints) or the plan fixes it; absent when unknown, as for zai's units other than hours.\n- `scope`, the model family or feature a limit is restricted to: anthropic's body `scope`, or\n  the kind's suffix (`weekly_opus` -> `opus`), codex's additional limit name, antigravity's\n  family. Absent means the limit counts all usage.\n\n`advance -` takes the whole call as one JSON envelope on stdin,\n`{provider, credential, responses: [round...], nowMs?}`, so a credential never lands in argv\nwhere other local processes can read it. It stays stateless: the host keeps every round's\nresponses and the CLI replays them through one fresh state, as the argument form does.\n\nMirrored in the TypeScript reference in prime-agent.\n"},{"name":"src","kind":"directory","size":0,"lastCommitHash":"4d3aaca676265ee8f9000508b1b15d94d4edd240","lastCommitWhen":"2026-10-25T03:16:56+03:00","lastCommitMessage":"feat(opencode-go): accept oauth credentials and sendable pipe buffer\n"},{"name":"swift","kind":"directory","size":0,"lastCommitHash":"4d3aaca676265ee8f9000508b1b15d94d4edd240","lastCommitWhen":"2026-10-25T03:16:56+03:00","lastCommitMessage":"feat(opencode-go): accept oauth credentials and sendable pipe buffer\n"},{"name":"tests","kind":"directory","size":0,"lastCommitHash":"4d3aaca676265ee8f9000508b1b15d94d4edd240","lastCommitWhen":"2026-10-25T03:16:56+03:00","lastCommitMessage":"feat(opencode-go): accept oauth credentials and sendable pipe buffer\n"},{"name":".gitignore","kind":"file","size":99,"lastCommitHash":"e7764b5c89556f3ba170283e367a5c3da6f09adf","lastCommitWhen":"2026-09-16T04:07:58+03:00","lastCommitMessage":"docs: stand as its own project\n\nThe core moved out of prime-agent's native/usage into its own repository: same\ntoolchain, same fixtures, same ABI. The README now describes this repo on its own terms,\nrecords how the TypeScript reference and the parity suite stay in prime-agent, and replaces\nthe stale status with what the eight providers actually answer from (including the `cli`\ncredential kind and the command request the host runs).\n\nHistory is preserved: the commits below are the core's own, extracted with `git subtree\nsplit --prefix=native/usage`.\n"},{"name":"build.zig","kind":"file","size":3417,"lastCommitHash":"cf47adbb8c8df59a09ee16eaee83864030f9a088","lastCommitWhen":"2026-09-16T04:25:16+03:00","lastCommitMessage":"fix(core): bump to ABI 3 with host-owned state, safe float casts, and pipe draining\n"},{"name":"build.zig.zon","kind":"file","size":266,"lastCommitHash":"6bb9da4709e28779906bf8409b569bbe6bb09765","lastCommitWhen":"2026-09-16T02:33:00+03:00","lastCommitMessage":"feat(native): implement the usage query core in Zig for native hosts\n\ndawn wants the usage query from a macOS app, and JavaScript will not run there. This is\nthe query alone — the rules that turn a provider body into limits — as a C ABI library\nin Zig, with the TypeScript implementation left in place as the reference.\n\nThe core is pure on purpose: it never opens a socket, reads a clock, or touches the\nfilesystem.\n\n- `usage_parse(provider, body, now_ms)`, `usage_build_request(provider, token,\n  account_id)`, `usage_credentials_from_access_token(jwt)`, `usage_supported_providers()`,\n  `usage_abi_version()`, `usage_free()`. JSON in, JSON out, so the shapes are the contract\n  already documented in packages/ai/docs/usage-query.md. Failures come back as\n  `{\"error\":\"...\"}` and NULL only ever means allocation failed; a host with its own token\n  needs no auth store.\n- Host owns the socket. A usage query is one GET, and doing it here would mean shipping\n  TLS with its own trust store and proxy behaviour; a host with NSURLSession already has\n  that, so it asks for the request, sends it, and hands back the body.\n- `native/usage/tests/c_smoke.c` is compiled by the toolchain and linked against the\n  installed static library, so `zig build test` exercises the ABI the way a native caller\n  does — including a NULL argument and a provider without a feed.\n- `packages/ai/test/usage-zig-parity.test.ts` computes both implementations from the same\n  recorded bodies at test time (one captured live, redacted of user_id/account_id/email),\n  so neither can drift from the other quietly.\n- Zig is pinned to 0.16.0 with a verified checksum: 0.16 moved args, stdio, fs, and clock\n  APIs, and the pure core compiled unchanged through that while only the debug CLI needed\n  edits, which is the boundary doing its job. `npm run check` now includes `check:zig`,\n  and CI installs the pinned toolchain.\n\nVerified: zig unit tests plus the C ABI smoke test, byte-identical output against the\nTypeScript reference on both fixtures, `npm run check` clean.\n"},{"name":"README.md","kind":"file","size":7103,"lastCommitHash":"1a4bff9779f13103dd2e4bc81d62b501fe6421d7","lastCommitWhen":"2026-09-28T07:48:31+03:00","lastCommitMessage":"fix(cli): end the stdin envelope at its first newline\n\nAn Erlang port cannot close stdin without closing the port, so a host there never sends the EOF\n`advance -` waited for. The envelope is one JSON line; reading to the first newline (or EOF)\nlets such a host write the line and read the answer.\n"}],"branches":[{"name":"main","hash":"4d3aaca676265ee8f9000508b1b15d94d4edd240","when":"2026-10-25T03:16:56+03:00","isDefault":true,"message":"feat(opencode-go): accept oauth credentials and sendable pipe buffer\n"}],"totalBranches":1,"tags":[],"totalTags":0,"languages":[{"name":"Zig","size":160562,"share":80.91863887432972,"percentage":81},{"name":"Swift","size":29721,"share":14.978530822884329,"percentage":15},{"name":"C","size":8141,"share":4.102830302785954,"percentage":4}],"failed":{"files":false,"refs":false,"languages":false},"compact":{}}