Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,57 @@ MIT © 정인권 (developjik)
## Development baseline (DEV-128)

Use Node.js 22.12.0 (`.nvmrc`) for development and CI. Vitest 5.1.1 requires Node 22.12+ on its supported release lines; Node 20.19 is outside its declared development support range. It may execute there, but CI does not treat that as supported test-runner usage. This development requirement does not change the package engine declaration. Runtime compatibility must be checked using the built package, separately from the test runner. TypeScript 7.0.2 is the development compiler baseline.

## Linear tracker (opt-in CLI)

GitHub remains the default. Linear implements the same `IssueAdapter` surface,
including status/next, ball labels, comment records and advisory comment leases.
No hosted service or package publication is needed.

```sh
# Set LINEAR_API_KEY through your local secret manager, not a command-line flag.
agent-ball status --tracker linear --team DEV
agent-ball next --tracker linear --team DEV --agent codex
agent-ball handoff --tracker linear --team DEV --issue 12 \
--from human --to codex --summary "Implementation ready for the next turn"
```

`--team` is an uppercase Linear team key, not its display name or UUID.
`--issue 12` always means `DEV-12` in that configured team. The existing numeric
board/record shape stays unchanged; full identifiers and UUIDs are not accepted
as issue arguments. `AGENT_BALL_TRACKER=linear` and
`AGENT_BALL_LINEAR_TEAM=DEV` can supply defaults. Never combine `--repo` or
`--demo` with Linear. Dashboard `serve` is still GitHub/demo-only.

Before a write, manually create **standalone, ungrouped** Linear labels named
`ball:human`, `ball:blocked`, and `ball:agent:<name>` for your agents. Do not use
Linear label groups, which can enforce single selection. Workspace or team
labels work, but duplicate names fail closed. `agent-ball labels` still creates
GitHub labels only and will refuse Linear. No labels are created automatically.
Ball labels represent ownership; workflow status only maps completed/canceled
to closed and every other state to open. The adapter never changes workflow
status, assignee, team or unrelated labels. Additive/removal label IDs preserve
unrelated labels. A readback verifies that a write stuck; this is not CAS.

Authentication uses a caller-provided `LINEAR_API_KEY` (personal API key value,
or `Bearer ...` for a pre-obtained OAuth token) at the fixed official HTTPS
GraphQL endpoint. Obtain and manage credentials yourself; the tool does not
create keys, request OAuth grants or store tokens. Provide only the permissions
your commands need, including issue label/comment writes and deletion of its
lease comments for handoff. Read-only credentials work for status/next. Errors
omit upstream bodies and credentials. Requests time out after 15 seconds and
responses are bounded to 8 MiB. Writes are not automatically retried: a timeout
may follow a successful write, so inspect the issue before retrying.

Issue lists are bounded to 2,000 results; comment reads paginate up to 2,000
comments and refuse partial lock views. Issues with more than 250 labels or a
label catalog over 250 entries fail closed rather than silently ignoring labels.
The lease is advisory and uses server comment metadata, not an atomic server
lock. Stale reads and work exceeding TTL can overlap, just as with GitHub.
Only comments observed on the configured issue can be removed by this adapter.

Validation covers the real CLI/engine/adapter path against a deterministic local
GraphQL service simulation, including a handoff record and ball-label readback.
It does not claim a live Linear workspace handoff. Existing workspace issues are
not used as test fixtures. API reference:
https://linear.app/developers/graphql
39 changes: 29 additions & 10 deletions src/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { IssueAdapter } from '../core/adapter';
import { createDemoAdapter, DEMO_REPO } from '../core/demo';
import { AgentBallEngine, type TurnOutcome } from '../core/engine';
import { GitHubIssueAdapter, createGhRunner, type GhRunner } from '../core/github-adapter';
import { LinearIssueAdapter, type LinearRequest } from '../core/linear-adapter';
import { isAgentName, isOwnerName } from '../core/labels';
import { startServer } from '../server';
import { formatBoard, formatOutcome, ownerLabel, relativeTime, truncate } from './format';
Expand All @@ -21,6 +22,7 @@ export interface CliDeps {
readonly newId?: () => string;
readonly env?: NodeJS.ProcessEnv;
readonly runGh?: GhRunner;
readonly linearRequest?: LinearRequest;
/** Built dashboard directory; tests pass an empty temp dir or null. */
readonly webDir?: string | null;
/** Serve without blocking (tests). */
Expand Down Expand Up @@ -57,7 +59,7 @@ const KNOWN_FLAGS: Record<string, { value: string[]; bool: string[] }> = {
version: { value: [], bool: [] },
};

export const USAGE = `agent-ball — turn-taking for agents and humans on GitHub Issues
export const USAGE = `agent-ball — turn-taking for agents and humans on GitHub or Linear issues

Usage
agent-ball <command> [options]
Expand All @@ -82,6 +84,8 @@ Commands

Options
--repo <owner/name> Repository (default: $AGENT_BALL_REPO or the current checkout)
--tracker github|linear Tracker (default: $AGENT_BALL_TRACKER or github)
--team KEY Required Linear team key; issue 12 means KEY-12
--json Machine-readable output
--demo Use the built-in demo board, no repo reads
-h, --help
Expand Down Expand Up @@ -220,7 +224,7 @@ function push(map: Map<string, string[]>, key: string, value: string): void {
}

function assertKnownFlags(args: ParsedArgs, allowed: { value: string[]; bool: string[] }): void {
const valueFlags = new Set(allowed.value);
const valueFlags = new Set([...allowed.value, 'tracker', 'team']);
const boolFlags = new Set(allowed.bool);
for (const key of args.values.keys()) {
if (!valueFlags.has(key) && !boolFlags.has(key)) {
Expand Down Expand Up @@ -271,9 +275,10 @@ function integer(args: ParsedArgs, key: string, fallback: number): number {
return value;
}

function issueArg(args: ParsedArgs): number {
function issueArg(args: ParsedArgs, deps: CliDeps): number {
const raw = args.positionals[0] ?? one(args, 'issue');
if (raw === undefined) throw new UsageError('an issue number is required');
if ((one(args, 'tracker') ?? (deps.env ?? process.env).AGENT_BALL_TRACKER) === 'linear' && !/^#?[1-9][0-9]*$/.test(raw)) throw new UsageError('Linear --issue must be a positive numeric team-local number');
const issue = Number.parseInt(raw.replace(/^#/, ''), 10);
if (!Number.isInteger(issue) || issue <= 0) throw new UsageError(`"${raw}" is not an issue number`);
return issue;
Expand All @@ -288,21 +293,35 @@ function requireOwner(name: string, what: string): string {

interface Context {
readonly engine: AgentBallEngine;
readonly source: 'github' | 'demo';
readonly source: 'github' | 'linear' | 'demo';
readonly adapter: IssueAdapter;
}

async function context(args: ParsedArgs, deps: CliDeps): Promise<Context> {
const now = deps.now ?? (() => new Date());
if (deps.adapter) {
const engine = new AgentBallEngine({ adapter: deps.adapter, now, ...(deps.newId ? { newId: deps.newId } : {}) });
return { engine, source: deps.adapter.name === 'github' ? 'github' : 'demo', adapter: deps.adapter };
return { engine, source: deps.adapter.name === 'github' ? 'github' : deps.adapter.name === 'linear' ? 'linear' : 'demo', adapter: deps.adapter };
}
const environment = deps.env ?? process.env;
const tracker = optionalNonEmpty(args, 'tracker') ?? environment.AGENT_BALL_TRACKER ?? 'github';
if (tracker !== 'github' && tracker !== 'linear') throw new UsageError('--tracker must be github or linear');
if (has(args, 'demo') && tracker === 'linear') throw new UsageError('--demo cannot be combined with Linear');
if (has(args, 'demo')) {
const adapter = createDemoAdapter(now());
const engine = new AgentBallEngine({ adapter, now, ...(deps.newId ? { newId: deps.newId } : {}) });
return { engine, source: 'demo', adapter };
}
if (tracker === 'linear') {
if (args.command === 'serve') throw new UsageError('Linear support is CLI-only; dashboard serve remains GitHub or demo');
if (one(args, 'repo')) throw new UsageError('--repo is for GitHub; use --team for Linear');
const team = optionalNonEmpty(args, 'team') ?? environment.AGENT_BALL_LINEAR_TEAM;
if (!team) throw new UsageError('Linear requires --team KEY or AGENT_BALL_LINEAR_TEAM');
const adapter = new LinearIssueAdapter({ team, token: environment.LINEAR_API_KEY, request: deps.linearRequest });
const engine = new AgentBallEngine({ adapter, now, ...(deps.newId ? { newId: deps.newId } : {}) });
return { engine, source: 'linear', adapter };
}
if (one(args, 'team')) throw new UsageError('--team requires --tracker linear');
const repo = await resolveRepo(args, deps);
const runner = deps.runGh ?? createGhRunner(deps.env ?? process.env);
const adapter = new GitHubIssueAdapter({ repo, run: runner });
Expand Down Expand Up @@ -371,7 +390,7 @@ async function commandNext(args: ParsedArgs, deps: CliDeps, io: CliIO): Promise<
}

async function commandClaim(args: ParsedArgs, deps: CliDeps, io: CliIO): Promise<number> {
const issue = issueArg(args);
const issue = issueArg(args, deps);
const agent = required(args, 'agent');
const contextValue = await context(args, deps);
const outcome = await contextValue.engine.claim({
Expand All @@ -383,7 +402,7 @@ async function commandClaim(args: ParsedArgs, deps: CliDeps, io: CliIO): Promise
}

async function commandHandoff(args: ParsedArgs, deps: CliDeps, io: CliIO): Promise<number> {
const issue = issueArg(args);
const issue = issueArg(args, deps);
const to = requireOwner(required(args, 'to'), '--to');
const summary = required(args, 'summary');
const contextValue = await context(args, deps);
Expand All @@ -409,7 +428,7 @@ async function commandHandoff(args: ParsedArgs, deps: CliDeps, io: CliIO): Promi
}

async function commandBlock(args: ParsedArgs, deps: CliDeps, io: CliIO): Promise<number> {
const issue = issueArg(args);
const issue = issueArg(args, deps);
const reason = required(args, 'reason');
const contextValue = await context(args, deps);
const actor = one(args, 'actor')
Expand All @@ -420,7 +439,7 @@ async function commandBlock(args: ParsedArgs, deps: CliDeps, io: CliIO): Promise
}

async function commandResolve(args: ParsedArgs, deps: CliDeps, io: CliIO): Promise<number> {
const issue = issueArg(args);
const issue = issueArg(args, deps);
const to = requireOwner(required(args, 'to'), '--to');
const actor = one(args, 'actor') ?? 'human';
const contextValue = await context(args, deps);
Expand All @@ -441,7 +460,7 @@ async function commandLabels(args: ParsedArgs, deps: CliDeps, io: CliIO): Promis
const invalid = agents.filter((name) => !isAgentName(name));
if (invalid.length > 0) throw new UsageError(`invalid agent names: ${invalid.join(', ')}`);

if (deps.adapter) throw new UsageError('labels can only be created against GitHub');
if (deps.adapter || (one(args, 'tracker') ?? (deps.env ?? process.env).AGENT_BALL_TRACKER ?? 'github') !== 'github' || one(args, 'team')) throw new UsageError('labels creates GitHub labels only; pre-create ungrouped ball labels in Linear');
const repo = await resolveRepo(args, deps);
const runner = deps.runGh ?? createGhRunner(deps.env ?? process.env);
const adapter = new GitHubIssueAdapter({ repo, run: runner });
Expand Down
4 changes: 2 additions & 2 deletions src/core/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export interface IssueQuery {
}

/**
* The narrow surface the engine needs from GitHub. Everything here is
* implemented twice: once against the real API (`GitHubIssueAdapter`) and once
* The narrow surface the engine needs from an issue tracker. Everything here is
* implemented against GitHub and Linear APIs and also
* in memory (`MockAdapter`) so the protocol can be tested deterministically.
*/
export interface IssueAdapter {
Expand Down
4 changes: 2 additions & 2 deletions src/core/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface BoardCounts {

export interface Board {
readonly generatedAt: string;
readonly source: 'github' | 'demo';
readonly source: 'github' | 'linear' | 'demo';
readonly repo: string | null;
readonly issues: DashboardIssue[];
readonly counts: BoardCounts;
Expand All @@ -66,7 +66,7 @@ export interface BoardGroups {

export function buildBoard(
snapshots: readonly IssueSnapshot[],
options: { source: 'github' | 'demo'; repo: string | null; now?: Date },
options: { source: 'github' | 'linear' | 'demo'; repo: string | null; now?: Date },
): Board {
const now = options.now ?? new Date();
const issues = snapshots
Expand Down
2 changes: 1 addition & 1 deletion src/core/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class AgentBallEngine {
});
}

async board(options: { source?: 'github' | 'demo'; limit?: number } = {}): Promise<Board> {
async board(options: { source?: 'github' | 'linear' | 'demo'; limit?: number } = {}): Promise<Board> {
const snapshots = await this.list({ limit: options.limit ?? 100 });
return buildBoard(snapshots, {
source: options.source ?? 'github',
Expand Down
2 changes: 2 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export * from './lock';
export * from './mock-adapter';
export * from './engine';
export * from './demo';

export * from './linear-adapter';
Loading