mirror of
https://github.com/Kynde/airc.git
synced 2026-10-20 08:31:38 +02:00
Recognize GitHub Copilot CLI panes alongside Claude Code and Codex, keyed on live `tmux capture-pane -p` captures: the "Working esc cancel" busy footer (its spinner glyph animates, so match the stable text), the boxed "Do you want to run…?" approval prompt, and the "/ commands · ? help" ready footer. Fixtures and tests pin all three states. Order the Copilot detector ahead of Claude: Copilot's "❯ 1. Yes" approval menu also matches CLAUDE_CHROME, so a waiting Copilot pane was being misclassified as Claude. The `copilot` foreground command now routes it first; a regression test asserts this holds even when the command hint is a wrapper. Copilot CLI has no notification/hook mechanism, so it relies on the zero-config screen scan alone (noted in docs/attention.md).
76 lines
3.5 KiB
JavaScript
76 lines
3.5 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-idle", 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: "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);
|
||
});
|
||
|
||
// 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}`);
|
||
}
|
||
});
|