mirror of
https://github.com/Kynde/airc.git
synced 2026-10-20 08:31:38 +02:00
CLAUDE_BUSY keyed on the token counter in the spinner's parenthetical, but Claude Code 2.1.263 only draws that parenthetical once it has something to report. Before the first token of a turn there is no counter at all — the pane shows a bare "✽ Cooking…", then "✶ Flambéing… (5s · thinking with high effort)" — so the busy match failed, the screen fell through to the empty-"❯" check, and a thinking agent was published as FINISHED. On a high-effort turn that is minutes of a running agent showing up grey, which is exactly backwards for the one state the HUD exists to surface. The one part every build renders is the spinner word itself, so that is what is matched now: a line whose FIRST token is a word ending in "…". The old time+token parenthetical and "esc to interrupt" stay as alternatives — a narrow pane can wrap the line and split the word from its ellipsis, and the counter survives that. WHERE it matches turned out to be half the signature. Scanning the whole screen, any pane whose transcript merely quotes a spinner line reads as busy forever after its turn ends: a pasted log, or — the case that caught this — an agent working on this very file, printing "· Moseying… (6m 28s · ↓ 27.3k tokens)" into its own answer and pinning its window orange. The shipped regex had the same hole; the ellipsis rule only widened it. So CLAUDE_BUSY is now handed claudeStatusArea() — the 12 lines above the last "❯" line — and must match at column 0. Across 583 live busy captures the real spinner sat 3-9 lines above the composer, every one of them at column 0, while everything the agent said is indented under its "●" bullet and scrolls away from there. Three fixtures, all captured from throwaway panes: claude-busy-spinner (bare spinner, no parenthetical), claude-busy-effort (timer and effort clause, still no tokens), and claude-idle-quoting-spinner (finished, transcript quoting all four spinner shapes) — the last one reads busy under both the old regex and an unscoped ellipsis rule, so it pins the scoping rather than the wording. Verified beyond the fixtures by replaying 616 captures collected from live panes during a working session: 598 busy stay busy, the 8 pre-token thinking screens flip to busy, and every idle/waiting/none is unchanged. Then end to end through GET /api/attention on a restarted server, where a probe pane held busy for a full 20s thinking phase and flipped the instant the answer landed. The obvious simplification is a trap worth naming: a finished turn leaves "✻ Sautéed for 53s · done 4:03 PM" in the transcript, same glyph family as the spinner. Keying on the glyph alone would read every completed turn as running. The ellipsis is what separates them. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YZC651gHvqw2C7qCVXpUu5
112 lines
5.8 KiB
JavaScript
112 lines
5.8 KiB
JavaScript
"use strict";
|
||
|
||
const assert = require("node:assert");
|
||
const fs = require("node:fs");
|
||
const path = require("node:path");
|
||
const { test } = require("node:test");
|
||
|
||
const { detectPaneState, STATE } = require("../src/detect");
|
||
|
||
const fixture = (name) => fs.readFileSync(path.join(__dirname, "fixtures", `${name}.txt`), "utf8");
|
||
|
||
// Each case pairs a real `tmux capture-pane -p` fixture with the foreground
|
||
// command tmux would report, so detection is exercised exactly as the scanner
|
||
// drives it.
|
||
const CASES = [
|
||
{ name: "claude-waiting", command: "claude", agent: "claude", state: STATE.WAITING },
|
||
{ name: "claude-busy", command: "claude", agent: "claude", state: STATE.BUSY },
|
||
{ name: "claude-busy-thinking", command: "claude", agent: "claude", state: STATE.BUSY },
|
||
// The first seconds of a turn: the spinner is up but there is no token
|
||
// counter yet — bare ("✽ Cooking…"), then with an effort clause but still no
|
||
// count. Matching the counter read both of these as a FINISHED agent.
|
||
{ name: "claude-busy-spinner", command: "claude", agent: "claude", state: STATE.BUSY },
|
||
{ name: "claude-busy-effort", command: "claude", agent: "claude", state: STATE.BUSY },
|
||
{ name: "claude-idle", command: "claude", agent: "claude", state: STATE.IDLE_INPUT },
|
||
// Finished, but with a half-typed prompt left in the composer: still idle,
|
||
// still awaiting instruction. Anchoring idle on an *empty* "❯" line dropped
|
||
// these panes out of the attention HUD entirely.
|
||
{ name: "claude-idle-draft", command: "claude", agent: "claude", state: STATE.IDLE_INPUT },
|
||
// Finished, but the transcript QUOTES spinner lines (an agent that pasted a
|
||
// log, or that works on this very file). Scanning the whole screen read those
|
||
// words as work and pinned the pane orange long after the turn ended, so this
|
||
// capture keeps the busy match bounded to the status area above the composer.
|
||
{ name: "claude-idle-quoting-spinner", command: "claude", agent: "claude", state: STATE.IDLE_INPUT },
|
||
{ name: "codex-waiting", command: "codex", agent: "codex", state: STATE.WAITING },
|
||
{ name: "codex-busy", command: "codex", agent: "codex", state: STATE.BUSY },
|
||
{ name: "codex-idle", command: "codex", agent: "codex", state: STATE.IDLE_INPUT },
|
||
{ name: "omp-waiting", command: "omp", agent: "omp", state: STATE.WAITING },
|
||
{ name: "omp-busy", command: "omp", agent: "omp", state: STATE.BUSY },
|
||
{ name: "omp-idle", command: "omp", agent: "omp", state: STATE.IDLE_INPUT },
|
||
{ name: "copilot-waiting", command: "copilot", agent: "copilot", state: STATE.WAITING },
|
||
{ name: "copilot-busy", command: "copilot", agent: "copilot", state: STATE.BUSY },
|
||
{ name: "copilot-idle", command: "copilot", agent: "copilot", state: STATE.IDLE_INPUT },
|
||
];
|
||
|
||
for (const c of CASES) {
|
||
test(`${c.name} → ${c.agent}/${c.state}`, () => {
|
||
const result = detectPaneState({ text: fixture(c.name), command: c.command });
|
||
assert.strictEqual(result.agent, c.agent, `agent for ${c.name}`);
|
||
assert.strictEqual(result.state, c.state, `state for ${c.name}`);
|
||
});
|
||
}
|
||
|
||
// Negatives: a plain shell and a pager must never be flagged, by command and by
|
||
// content (a shell whose foreground command is momentarily something else still
|
||
// must not trip an agent signature).
|
||
for (const name of ["shell", "pager"]) {
|
||
test(`${name} → not an agent`, () => {
|
||
const byCommand = detectPaneState({ text: fixture(name), command: "zsh" });
|
||
assert.strictEqual(byCommand.state, STATE.NONE, `${name} state`);
|
||
assert.strictEqual(byCommand.agent, "", `${name} agent`);
|
||
});
|
||
}
|
||
|
||
// Identification must work even when the foreground command is a wrapper (the
|
||
// real-world `node`/`python` launcher case), via on-screen chrome alone.
|
||
test("claude recognized without command hint", () => {
|
||
const result = detectPaneState({ text: fixture("claude-waiting"), command: "node" });
|
||
assert.strictEqual(result.agent, "claude");
|
||
assert.strictEqual(result.state, STATE.WAITING);
|
||
});
|
||
|
||
test("codex recognized without command hint", () => {
|
||
const result = detectPaneState({ text: fixture("codex-busy"), command: "node" });
|
||
assert.strictEqual(result.agent, "codex");
|
||
assert.strictEqual(result.state, STATE.BUSY);
|
||
});
|
||
|
||
test("copilot recognized without command hint", () => {
|
||
const result = detectPaneState({ text: fixture("copilot-busy"), command: "node" });
|
||
assert.strictEqual(result.agent, "copilot");
|
||
assert.strictEqual(result.state, STATE.BUSY);
|
||
});
|
||
|
||
test("omp recognized without command hint", () => {
|
||
const result = detectPaneState({ text: fixture("omp-busy"), command: "node" });
|
||
assert.strictEqual(result.agent, "omp");
|
||
assert.strictEqual(result.state, STATE.BUSY);
|
||
});
|
||
|
||
// Regression: omp's approval box lists "❯ Approve" / " Deny", and that first
|
||
// line is exactly Claude's idle-composer signature, so a waiting omp pane must
|
||
// still be claimed by the omp detector (which sits ahead of claude) — including
|
||
// when the command hint is a wrapper and can't disambiguate.
|
||
test("omp waiting not misattributed to claude", () => {
|
||
for (const command of ["omp", "node"]) {
|
||
const result = detectPaneState({ text: fixture("omp-waiting"), command });
|
||
assert.strictEqual(result.agent, "omp", `agent with command=${command}`);
|
||
assert.strictEqual(result.state, STATE.WAITING, `state with command=${command}`);
|
||
}
|
||
});
|
||
|
||
// Regression: Copilot's "❯ 1. Yes" approval menu also matches Claude's chrome,
|
||
// so a waiting Copilot pane must still be claimed by the copilot detector
|
||
// (which sits ahead of claude) even when the command hint can't disambiguate.
|
||
test("copilot waiting not misattributed to claude", () => {
|
||
for (const command of ["copilot", "node"]) {
|
||
const result = detectPaneState({ text: fixture("copilot-waiting"), command });
|
||
assert.strictEqual(result.agent, "copilot", `agent with command=${command}`);
|
||
assert.strictEqual(result.state, STATE.WAITING, `state with command=${command}`);
|
||
}
|
||
});
|