Skip to content

feat: ak usage last known reading, ak ps, and native orchestration (ak run --pick, ak fanout) - #59

Merged
xergioalex merged 13 commits into
mainfrom
integration/usage-ps-orchestration
Nov 28, 2026
Merged

xergioalex merged 13 commits into
mainfrom
integration/usage-ps-orchestration

Conversation

@xergioalex

Copy link
Copy Markdown
Member

What this brings

Three additions, developed on three branches and merged here (they conflict only in shared text files: the changelog, the docs index, the command list). Interface stays 1; every change to an existing surface is additive.

1. ak usage keeps showing an account it cannot read now

A row that is expired, no_scope, no_login or error used to be a status and a hint. When the usage cache still holds an earlier reading of that account, at most seven days old, the table now lists its windows under the status line, dated (last read 3h 0m ago), and --json carries it as the additive last_known block. A window whose reset time has passed is marked reset and carries no number. The row is still a problem row, and ak pick and ak capacity never read a reading that old.

This makes the account legible. It does not renew a login.

2. ak ps [--json] — the sessions that are running

Every interactive ak <kind> [@profile] leaves one record (best effort; a failed write never changes a launch). ak ps lists the sessions still running — kind, profile, posture, Herdr pane — joined to the account's capacity from the usage cache alone, with the reading's age. New schema sessions-v1. A record is live only while its process id is alive with the recorded start time, and belongs to the host that wrote it.

3. Native orchestration

  • ak run <kind> --pick runs on the account ak pick names. With --failover N it moves to another account, and with --fallback KIND,KIND to another kind, on two triggers only: the attempt never started, or it failed or timed out and a fresh reading shows the account spent. After an attempt that started, it moves only when --cwd is a git work tree left exactly as it was; it never cleans a workspace. --owner leases the account per attempt; --exclude @profile leaves one out. The envelope gains attempts and failover with --pick only.
  • ak fanout run --tasks FILE runs each task as its own lane: a new git worktree on a new branch, one ak run --pick per lane, in parallel, one fanout-v1 result. A lane survives a spent account by starting over from a clean worktree. It never merges, pushes or rebases.
  • ak fanout clean <run-id> [--discard] removes a run's worktrees, branches and record. It keeps uncommitted work and unmerged commits unless --discard, and removes a worktree only when it is provably that run's.
  • The agentkit-orchestrate skill and docs/orchestration.md teach these commands in place of the loop run by hand.

How it was checked

  • Full suite on this branch: 3279 passed, 0 failed, 1 skipped; public hygiene clean.
  • New scopes: sessions, fanout; new bash-free checks tests/py/sessions_checks.py, tests/py/fanout_checks.py; the run, usage and orchestrate-skill scopes extended.
  • Each new check was shown to fail on a seeded defect. A few seeds were not discriminating; each is recorded with the reason.

What was not verified

  • No real agent CLI was launched and no real account was read. Every agent was a fake and every quota reading came from the loopback server. How real CLIs behave when they hit a limit is untested.
  • Windows was not exercised for any of the three, beyond what this repository's CI covers.
  • The reviews were self-reviews by the agent that wrote the change. No independent reviewer read this diff.
  • One fanout check asserts an upper bound on elapsed time (three 3-second lanes under 8 seconds) and could fail on a very slow runner.

Not in this PR

The version bump, the dated changelog section, the tag and the release. A command that renews an expired login through the account's own CLI.

🤖 Generated with Claude Code

xergioalex and others added 13 commits November 28, 2026 00:27
A row that is expired, no_scope, no_login or error kept only a status and a
hint. When the usage cache still holds an earlier reading of that account, at
most seven days old, ak usage now lists its windows under the status line,
dated, and --json carries it as the additive last_known block. A window whose
reset time has passed is marked reset and carries no number. The row is still
a problem row; ak pick and ak capacity never read a reading that old.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The last known reading comes from a file on disk. A window with a reset time
that is not a time, a percentage that is not a number or a missing key made
ak usage fail instead of reporting the row. Such a reading is now not shown.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Every interactive ak <kind> [@Profile] now leaves one record in the kit's
state directory (sessions/, one 0600 file per launch): the process id and
its start time, kind, CLI, provider, profile, working directory, launch
time, posture and the Herdr pane id. Best effort: a failed write never
changes a launch. A record is live only while its process id is alive with
the recorded start time. Nothing reads the records yet; ak ps follows.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ak ps [--json] lists the interactive sessions ak launched that are still
running, oldest first: kind, CLI, provider, profile, directory, launch time,
posture, Herdr pane and the account's capacity. Capacity comes from the usage
cache alone, with the reading's age: no vendor is queried and no login is
touched. Ended records are removed as it reads; of several live sessions
naming one Herdr pane only the newest is listed. --json is the new
sessions-v1 schema. Interface stays 1.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A process id means nothing on another machine or in another container. With
a state directory shared between a host and its containers, ak ps on one
side judged the other side's records by its own process table, listed wrong
sessions and removed the records of sessions that were alive. Records now
name their host, and each side lists, ends and removes only its own.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ak run <kind> --pick runs on the account ak pick names (one shared choice,
pick.select). With --failover N it moves to another account, then to the
next --fallback kind, on two triggers only: the attempt never started
(exit 3), or it ended with exit 1 or 4 and a fresh usage reading shows the
account spent. After a started attempt it moves only when --cwd is a git
work tree left exactly as it was; ak run never cleans a workspace. --owner
holds a lease for each attempt. The JSON envelope gains attempts and
failover with --pick only; without it nothing changes. Interface stays 1.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ak fanout run takes a task list and runs each task as its own lane: a new
git worktree on a new branch (ak/<run-id>/<task-id>) from --base, one
ak run --pick child process per lane, in parallel. Lanes start one at a
time once the previous lease shows, so ak pick spreads them; an exclusive
account carries one lane at a time and a lane that finds every account busy
waits its turn. The task list is validated before anything is created. The
result is the new fanout-v1 schema; a 0600 run record lists every worktree
the run created. It never merges, pushes or rebases. ak fanout ls lists the
runs on record. Interface stays 1.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A lane survives a spent account also when the agent had already written:
its own worktree is removed and created again from the base and the task
runs once more on another account, within --failover; a branch that holds
commits is never reset. An account found spent is left out for the rest of
the run (ak run gains --exclude @Profile). SIGTERM or SIGINT stops every
lane, releases the leases and exits 5. ak fanout clean <run-id> removes a
run's worktrees, branches and record: it keeps uncommitted work and branches
with commits unless --force, and removes a worktree only when it is in the
run's record, where the run puts a lane, a linked worktree of the recorded
repository and its own git top level.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…-discard

The agentkit-orchestrate skill, its patterns reference and
docs/orchestration.md teach ak fanout run for parallel tasks and
ak run --pick --failover for one delegate, in place of the loop run by hand.
The rules the commands do not enforce stay with the lead: the gate in each
worktree, merging only what passes, never an account the user did not
offer. The scenarios run the taught commands against fake accounts.

ak fanout clean's option to remove uncommitted work and unmerged commits is
--discard: the earlier spelling was a CLI's autonomy flag, which no skill
may spell (E006).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review fixes. A lane's place is <run-id>/<id> or <run-id>/wt/<id> and
nothing else under the run id. After a clean, only the run's own
--worktrees directory is removed when empty, never the parent of whatever
path an edited record names. A run id that is already on record is not
reused. A lane that fails inside the kit ends with exit 70 instead of
leaving the run without a result. docs/run.md names exit 3 for --pick with
no account.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
git worktree remove was called with git's long switch for discarding
uncommitted files, which is spelled like a vendor CLI's autonomy flag; no
such word may appear in the kit's code. Use git's short switch through a
named constant.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
# Conflicts:
#	CHANGELOG.md
#	docs/SECURITY.md
…chestration

# Conflicts:
#	AGENTS.md
#	CHANGELOG.md
#	docs/SECURITY.md
#	lib/ak.py
#	tests/run.sh
@xergioalex xergioalex added the Ready Ready for review label Nov 28, 2026
@xergioalex
xergioalex merged commit 5f48b57 into main Nov 28, 2026
6 checks passed
@xergioalex
xergioalex deleted the integration/usage-ps-orchestration branch November 28, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready Ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant