Skip to content

Add start and a two-step device login - #66

Merged
raghubetina merged 4 commits into
mainfrom
long-run/start-and-login
Nov 21, 2026
Merged

raghubetina merged 4 commits into
mainfrom
long-run/start-and-login

Conversation

@raghubetina

@raghubetina raghubetina commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds firstdraft start, the Skill's first step in place of the --help check, and lets an agent run the device login in two short commands.

  • firstdraft start reads the account once with the saved login (no request without a token) and prints fixed sentences from src/agent-sentences.js on standard output: the CLI version and, when known, the plugin's; the shared update line; whether this computer has a saved login and whether an environment token takes its place; how to log in when it is not logged in; and, only when reports are on, when to send progress and failure reports and with which command. It exits 0 only when First Draft accepted the token. Not logged in or a rejected token is authentication_required; a version or contract refusal wins over a failed account read. Its handled errors carry no problem text from First Draft.
  • firstdraft login --no-wait asks for a device grant, prints the link, the user code, and when they expire, saves the waiting login in device-login.json beside credentials.json (mode 0600), and exits. firstdraft login --finish polls for at most 15 seconds from its start, each request included, never sooner than the grant's interval, and says whether the computer is now logged in, still waiting (authorization_pending), expired, or refused. It removes the spent grant before saving the token. The device code is never printed. The browser login and the one-process login --interactive are unchanged.
  • New handled errors: authorization_pending and login_not_started (both exit 1), and the login_failed reasons device_login_invalid and device_login_unavailable.

The service needed no change: its device endpoints answer a grant's first poll at any time and enforce the interval between later polls, which the saved next-poll time respects.

Docs: updated docs/commands.md, docs/errors.md, the root and login help, and the 0.10.0 entry in CHANGELOG.md.

Review: Codex, approve (4 rounds, 10 findings fixed, 3 deferred). Antigravity, 1 round, approve, 0 findings.

Known limits

  • One waiting device login at a time. Trigger: starting a device login for a second origin replaces the first.
  • A --no-wait run while an older --finish is still polling can be overwritten or removed by that older run. Trigger: running the two steps at the same time instead of one after the other.
  • A --finish interrupted during its request and rerun at once polls early and earns one slow_down, which the CLI absorbs by lengthening its interval. Trigger: killing --finish mid-request and rerunning within the interval.
  • An existing configuration directory wider than 0700 is left as it is; the device login file itself is 0600, as credentials.json is. Trigger: a pre-existing firstdraft configuration directory with a broader mode.
  • The verification link's origin is not compared with the selected origin, as in the existing login --interactive. Trigger: a First Draft answer naming another host for /device.
  • An expired device-login.json is removed only when --finish or --no-wait next runs; start never reads it.
  • The update line's wording stays in src/service-client.js, shared with every command.

Validation

  • npm audit: 0 vulnerabilities
  • npm run check: passes (362 tests, pack check, packed-package smoke)

The Skill's first step was 'firstdraft --help', which told the agent
nothing about versions, the login, or whether the person agreed to
reports, and only the person could log in, by holding a terminal open
while they approved in a browser.

'firstdraft start' reads the account once with the saved login and
prints fixed sentences from src/agent-sentences.js: the versions, the
update line, whether this computer is logged in and how to log in if
not, whether an environment token takes the saved login's place, and,
only when reports are on, when to send them and with which command.
First Draft's answer only chooses among the sentences. It exits 0 only
when First Draft accepted the token; a setup below the minimum fails
with update_required although the account read was its only request.

'login --no-wait' saves a device grant in device-login.json (0600)
and prints the link and the code; 'login --finish' polls for at most
15 seconds and says whether the computer is logged in, still waiting,
expired, or refused. The file keeps the next poll time so a repeated
--finish never polls early and lengthens the grant's interval. The
browser login and the one-process device login are unchanged.
Review found that start gave login steps instead of the update refusal
when a rejected account read also named a newer minimum, and that its
errors repeated the problem text First Draft sent, which can name the
person. A retry it printed for staging dropped --staging.

login --finish could run past its 15 seconds when the last poll was
recent, could call a grant that expired during the request pending,
and reported a failed login when only the spent grant file could not
be removed after the token was saved. It now measures the wait from
its start and bounds each request by it, removes the spent grant
before saving the token, and says a refused or expired attempt saved
no new login rather than that the computer is logged out.
A second review found that a timer waking late could still send a poll
after the 15 seconds, and that the pending and expired lines said the
person had not approved when the CLI had not asked or had asked too
late to redeem the grant. They now say First Draft has not confirmed an
approval, and that the grant expired before this computer finished.
A credentials file that cannot be read now names the login step, with
--staging, instead of a bare 'firstdraft login'.
The error reference still said a pending login meant the person had
not approved and an expired one ended before approval, though the CLI
can stop without asking or redeem too late. It now says First Draft
had not confirmed an approval, or the grant ended before the CLI
received a token, matching what the commands print.
@raghubetina
raghubetina marked this pull request as ready for review November 21, 2026 23:58
@raghubetina
raghubetina merged commit 30ab73f into main Nov 21, 2026
7 checks passed
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.

1 participant