Skip to content

feat(cli): --env overlay for usage and orient probes - #656

Closed
creativebastard wants to merge 1 commit into
botiverse:mainfrom
creativebastard:cli-env-overlay
Closed

creativebastard wants to merge 1 commit into
botiverse:mainfrom
creativebastard:cli-env-overlay

Conversation

@creativebastard

Copy link
Copy Markdown

Problem

Hosts that run several agents under one runtime with different accounts (the supported isolated-home pattern — each account in its own KIMI_CODE_HOME) had no way to point the no-code account-usage surfaces at anything but the default home's credential slot:

  • oar usage accepted no environment input at all.
  • oar orient accepted none either.

kimiAccountUsage resolves its token from KIMI_CODE_HOME, and the library already plumbs a session env overlay through orient({ env }) — but with no way to express that overlay from the CLI, the probe always reads ~/.kimi-code/credentials/kimi-code.json. Whichever account lives there decides rateLimited for the whole runtime via usability(), so one capped account stalls every agent on the runtime — including agents whose own account still has quota. (Full diagnosis in #655.)

Change

  • packages/cli/src/env-option.ts (new): parse repeatable --env KEY=VALUE into SessionOptions["env"] (later wins; KEY= sets an empty string), plus a commander collector that appends instead of clobbering.
  • packages/cli/src/usage.ts (new): the usage command factored out of the composition root into a standalone, parser-testable command — mirroring how orient is built — now accepting --env and passing the overlay to runtime.accountUsage().
  • packages/cli/src/orient.ts: orient accepts --env and threads it into orient().
  • Tests: tests/cli-usage.test.ts covers the overlay reaching the reader, the no-flag default, malformed-flag rejection, and the parser table; tests/cli-orient.test.ts gains an env-threading test through the real orient().

Usage

# Probe the account an agent actually runs under, not the default home:
oar usage kimi --env KIMI_CODE_HOME=/home/agent-a
oar orient --depth account --env KIMI_CODE_HOME=/home/agent-a

Hosts keying stall decisions on usage should key per (runtime id, account identity from the snapshot) rather than per runtime id alone; the CLI gap was what made that impossible without re-implementing the readers.

Verification

  • pnpm run typecheck — clean
  • pnpm run lint — 0 warnings, 0 errors
  • New/updated test files: 12 tests pass
  • Full pnpm run test suite: running at PR open; will confirm before merge

Closes #655

Hosts running several agents under one runtime with different accounts
(isolated KIMI_CODE_HOME per account) could not point the no-code usage
surfaces at any account but the default home's: one capped account was
reported rate_limited for the whole runtime and every agent stalled.

Thread a repeatable --env KEY=VALUE option through 'oar usage' and
'oar orient' into the session env overlay the library already plumbs
into the account usage readers, so a host can probe per account. The
usage command moves into its own module, mirroring orient, so the
command is parser-testable.

Closes botiverse#655
@stamp-build

stamp-build Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for this and for the diagnosis in #655. Before reviewing the flag, we are checking whether it is needed: from reading the code, KIMI_CODE_HOME=/home/agent-a oar usage kimi should already reach the reader through the CLI's own environment, but we have not confirmed that on real Kimi yet. We will post the result on #655 and decide on this PR from there, so please hold off on further work on it for now.


Cindy commented through Stamp · server open-agent-runtime · head when posted cb97c9d
View in Stamp →

@creativebastard

Copy link
Copy Markdown
Author

Full-suite verification (local, 2026-11-06): pnpm run test — 3549 passed, 9 failed in 6 files, all in tests/login/* and tests/list-models.test.ts (login/logout timing + pi SDK lister). These failures reproduce identically on a clean main checkout (eb14800) — pre-existing environment issues, unrelated to this change. (The suite also rewrites two login test fixture files in the working tree as part of its fixtures; tree restored after the run.)

@stamp-build

stamp-build Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Closed by Cindy, an agent of open-agent-runtime that did not open it, through Stamp.

Reason:

Closing, with thanks for the diagnosis in #655. The problem is real but the flag is not needed: the CLI already inherits its environment, and a run with real Kimi 2.4.1 and two isolated accounts confirmed that KIMI_CODE_HOME=/path/to/account oar usage kimi and oar orient kimi --depth account switch account (details on #655, docs in #658). A flag would add a second way to do the same thing, and would put values on the command line where ps can read them. If you have a case the process environment cannot serve, please say so on #655 and we will look again.


Cindy commented through Stamp · server open-agent-runtime · head when posted cb97c9d
View in Stamp →

@stamp-build stamp-build Bot closed this Nov 6, 2026
stamp-build Bot added a commit that referenced this pull request Nov 6, 2026
…658)

<!-- stamp:review:v1 -->
<sup><img
src="https://cdn.slock.ai/avatars/6aabf32c-20bc-4cba-b55a-2aa72b60999b/8ba4452ceb890f1930886ef4286fdb99.webp"
width="16" height="16" align="absmiddle" alt=""> <b>Otter</b> from
open-agent-runtime opened this pull request through
Stamp</sup><br><sup><a
href="https://stamp.build/review?receipt=prc_a4567485b0e7894036f51db66c7a17e4"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://stamp.build/assets/brand/stamp-glyph-dark.d907ffcadb44.svg"><img
src="https://stamp.build/assets/brand/stamp-glyph-light.58a2c10ed108.svg"
width="13" height="12" align="absmiddle" alt=""></picture> View in Stamp
→</a></sup>

---
<!-- /stamp:review:v1 -->

The existing CLI already selects another Kimi account through its
inherited process environment. Document this for usage and account-depth
orientation, including PowerShell, and clarify that a rate-limit verdict
applies to the selected account/configuration rather than every account
on that runtime. No environment flag or product behavior changes.

A real Kimi 2.4.1 regression logs into two isolated synthetic accounts
against a local server. Switching A → B → A changes both usage
identity/quota and orientation JSON/table consistently; no login occurs
during reads. The test joins the existing native login CI suite. The
reproducible built-CLI probe and selected results are under
`experiments/orientation/kimi-accounts.md`.

Validation: full check (3,585 unit tests and 18 mock cases), build, and
five native Kimi login/account cases passed on Linux. PowerShell syntax
is documented from Microsoft; Windows execution remains for CI. No real
account or inference was used.

Related: #655, #656, #657.

Co-authored-by: Otter <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI usage/orient probe only the default credential slot — one capped account stalls every agent on the runtime

1 participant