Skip to content
Open
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ It finds the agent sessions that actually ran in your repo, reads
what happened in them, and proposes evidence-backed edits to your memory surface - the
memory file and project skills - under a token budget, gated by you.

- **Local-first** - Reads the transcript stores of seven agent harnesses directly from disk,
- **Local-first** - Reads the transcript stores of eight agent harnesses directly from disk,
locally or over SSH to your own machines. No API, no upload; transcripts never leave your
machines except into an agent you already authenticated, and obvious secrets are redacted
before they do.
Expand Down Expand Up @@ -220,7 +220,7 @@ It cannot be combined with

### 1. Collect samples - which sessions belong to this repo

backpass reads the local transcript stores of seven harnesses directly. No API, no upload.
backpass reads the local transcript stores of eight harnesses directly. No API, no upload.

| Harness | Store | Repo tie |
| -------------- | ----------------------------------------------- | --------------------------------------------------- |
Expand All @@ -231,6 +231,7 @@ backpass reads the local transcript stores of seven harnesses directly. No API,
| **grok** | `~/.grok/sessions/<encoded-cwd>/<uuid>/` | `summary.json` `cwd` + `git_remotes` |
| **cursor CLI** | `~/.cursor/chats/<md5(cwd)>/<uuid>/` | `meta.json` `cwd` |
| **hermes** | `~/.hermes/state.db` (sqlite) | session cwd, with CLI prompt / ACP config fallbacks |
| **copilot** | `~/.copilot/session-state/<uuid>/events.jsonl` | `session.start` `cwd` + `gitRoot` (no remote) |

Claude collection covers `$CLAUDE_CONFIG_DIR/projects` alongside the default store, so a
relocated config dir does not hide its sessions. The variable is read from backpass's own
Expand Down Expand Up @@ -888,7 +889,7 @@ CLI flags on top:
]
},
"discovery": {
"harnesses": ["claude", "codex", "pi", "opencode", "grok", "cursor", "hermes"],
"harnesses": ["claude", "codex", "pi", "opencode", "grok", "cursor", "hermes", "copilot"],
"since": "30d",
"worktreeGlobs": [],
"cloneRoots": [],
Expand Down
1 change: 1 addition & 0 deletions src/agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const VERDICT_LABELS = {

const LOGIN_HINTS = {
codex: "codex login",
copilot: "copilot login",
claude: "claude auth login",
grok: "grok login",
opencode: "opencode auth login",
Expand Down
2 changes: 1 addition & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ COMMANDS
COLLECT SAMPLES
--since <dur> only sessions newer than this (30d, 12h, 2w, all) [30d]
--harness <a,b> limit to these harnesses
(claude, codex, pi, opencode, grok, cursor, hermes)
(claude, codex, pi, opencode, grok, cursor, hermes, copilot)
--strict deterministic associations only (tiers 1, 1.5, and 2)
--host <dest> also collect from this SSH host this run (repeatable;
"none" collects locally only). Configure hosts once in
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { normalizeSkillsDir } from "./skills.js";
export const CONFIG_FILENAME = ".backpassrc.json";
export const STATE_DIRNAME = ".backpass";

export const ALL_HARNESSES = ["claude", "codex", "pi", "opencode", "grok", "cursor", "hermes"];
export const ALL_HARNESSES = ["claude", "codex", "pi", "opencode", "grok", "cursor", "hermes", "copilot"];
/** Cursor IDE is deferred to v1.1 and only ever runs behind --include-cursor-ide. */
export const OPT_IN_HARNESSES = ["cursor-ide"];

Expand Down
116 changes: 116 additions & 0 deletions src/discovery/adapters/copilot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import path from "node:path";

import { emptyInteractionSignals } from "../../interaction.js";
import { attachToolResults, home, listDirs, parseJsonLine, readHeadLines, readJsonl, statOrNull } from "./shared.js";

/**
* GitHub Copilot CLI: ~/.copilot/session-state/<session-uuid>/events.jsonl
*
* Every line is an event `{ type, data, id, timestamp, parentId }`. The first is
* `session.start`, whose `data.context` carries `cwd`, `gitRoot` and `branch`. The recorded
* `repository` is a host-specific label (`owner/name`, or `org/project/repo` on Azure
* DevOps), not a git remote URL, so no remote is reported and association relies on the
* cwd tiers, as for Claude Code.
*
* `COPILOT_HOME` relocates the whole config dir.
*
* Sub-agent work (`parentToolCallId`) is a sidechain and is skipped. `user.message` events
* the harness injected itself (instruction discovery, skills, system notices, prompts
* delegated to sub-agents) carry a non-user `source` and are skipped too.
*/

const HEADER_LINES = 5;
const EVENTS_FILE = "events.jsonl";
const USER_SOURCES = new Set(["user", "autopilot-objective"]);

export const name = "copilot";

export function storeRoot() {
return process.env.COPILOT_HOME
? path.join(process.env.COPILOT_HOME, "session-state")
: home(".copilot", "session-state");
}

export function enumerate() {
const out = [];
for (const dir of listDirs(storeRoot())) {
const file = path.join(dir, EVENTS_FILE);
const stat = statOrNull(file);
if (!stat) continue;
out.push({ key: file, path: file, mtimeMs: stat.mtimeMs, bytes: stat.size });
}
return out;
}

export function classify(candidate) {
for (const line of readHeadLines(candidate.path, HEADER_LINES)) {
const entry = parseJsonLine(line);
if (!entry || entry.type !== "session.start") continue;
const data = entry.data || {};
const context = data.context || {};
if (!context.cwd) return null;
return {
id: data.sessionId || path.basename(path.dirname(candidate.path)),
cwd: context.cwd,
gitRoot: context.gitRoot || null,
gitBranch: context.branch || null,
remotes: [],
startedAt: data.startTime ? Date.parse(data.startTime) : candidate.mtimeMs,
model: data.selectedModel || null,
interactionSignals: emptyInteractionSignals(),
};
}
return null;
}

export function read(ref) {
const entries = readJsonl(ref.path);
const events = [];
let model = null;

for (const entry of entries) {
const data = entry.data || {};
switch (entry.type) {
case "session.start":
model = model || data.selectedModel || null;
break;
case "user.message": {
if (data.source && !USER_SOURCES.has(data.source)) break;
if (typeof data.content === "string" && data.content.trim()) {
events.push({ kind: "message", role: "user", text: data.content });
}
break;
}
case "assistant.message": {
if (data.parentToolCallId) break;
model = model || data.model || null;
if (typeof data.content === "string" && data.content.trim()) {
events.push({ kind: "message", role: "assistant", text: data.content });
}
for (const request of data.toolRequests || []) {
events.push({
kind: "tool",
name: request.name,
input: request.arguments,
pendingId: request.toolCallId,
});
}
break;
}
case "tool.execution_complete": {
if (data.parentToolCallId) break;
events.push({
kind: "tool-result",
id: data.toolCallId,
result: data.result?.content ?? data.error?.message ?? data.error,
status: data.success === false ? "error" : "completed",
});
break;
}
default:
break;
}
}

return { events: attachToolResults(events), model };
}
2 changes: 2 additions & 0 deletions src/discovery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as pi from "./adapters/pi.js";
import * as grok from "./adapters/grok.js";
import * as opencode from "./adapters/opencode.js";
import * as hermes from "./adapters/hermes.js";
import * as copilot from "./adapters/copilot.js";
import * as cursorCli from "./adapters/cursor-cli.js";
import * as cursorIde from "./adapters/cursor-ide.js";

Expand All @@ -27,6 +28,7 @@ export const ADAPTERS = Object.assign(Object.create(null), {
grok,
opencode,
hermes,
copilot,
cursor: cursorCli,
"cursor-ide": cursorIde,
});
Expand Down
2 changes: 2 additions & 0 deletions src/discovery/remote/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const PROBE_MANIFEST = [
"discovery/adapters/grok.js",
"discovery/adapters/opencode.js",
"discovery/adapters/hermes.js",
"discovery/adapters/copilot.js",
"discovery/adapters/cursor-cli.js",
"discovery/adapters/cursor-ide.js",
"discovery/remote/frames.js",
Expand All @@ -51,6 +52,7 @@ export const REMOTE_ENV_ALLOWLIST = [
"CLAUDE_CONFIG_DIR",
"CODEX_HOME",
"HERMES_HOME",
"COPILOT_HOME",
"PI_CODING_AGENT_DIR",
"PI_CODING_AGENT_SESSION_DIR",
"BB_DATA_DIR",
Expand Down
2 changes: 2 additions & 0 deletions src/discovery/remote/probe.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as pi from "../adapters/pi.js";
import * as grok from "../adapters/grok.js";
import * as opencode from "../adapters/opencode.js";
import * as hermes from "../adapters/hermes.js";
import * as copilot from "../adapters/copilot.js";
import * as cursorCli from "../adapters/cursor-cli.js";
import * as cursorIde from "../adapters/cursor-ide.js";

Expand Down Expand Up @@ -49,6 +50,7 @@ const ADAPTERS = Object.assign(Object.create(null), {
grok,
opencode,
hermes,
copilot,
cursor: cursorCli,
"cursor-ide": cursorIde,
});
Expand Down
32 changes: 31 additions & 1 deletion src/harness-invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ export function prepareHarnessInvocation({ agent, model = null, effort = null, w
: baseInvocation({ notes, dispose });
} else if (agent === "grok") {
invocation = grokInvocation({ requestedModel, requestedEffort, writeAccess, notes, cleanups, dispose });
} else if (agent === "copilot") {
invocation = overlay
? copilotInvocation({ requestedModel, requestedEffort, notes, cleanups, dispose })
: baseInvocation({ notes, dispose });
} else if (agent === "claude" || agent === "codex" || agent === "opencode") {
invocation = {
...baseInvocation({ notes, dispose }),
Expand All @@ -94,7 +98,7 @@ export function prepareHarnessInvocation({ agent, model = null, effort = null, w
} else if (overlay) {
throw new UserError(
`${agent} has no proven invocation-scoped way to apply ${describeOverride(requestedModel, requestedEffort)} without writing persistent harness defaults`,
"pin pi, claude, codex, grok, or opencode, or omit the model and effort override",
"pin pi, claude, codex, copilot, grok, or opencode, or omit the model and effort override",
);
} else {
invocation = baseInvocation({ notes, dispose });
Expand Down Expand Up @@ -160,6 +164,32 @@ function piInvocation({ requestedModel, requestedEffort, notes, cleanups, dispos
};
}

function copilotInvocation({ requestedModel, requestedEffort, notes, cleanups, dispose }) {
if (process.platform === "win32") {
throw new UserError(
`cannot apply ${describeOverride(requestedModel, requestedEffort)} through acpx --agent on Windows`,
"pin pi, claude, codex, or opencode, or omit the model and effort override",
);
}
const extra = [];
if (requestedModel) extra.push("--model", requestedModel);
if (requestedEffort) extra.push("--reasoning-effort", requestedEffort);
extra.push("--acp", "--stdio");
const real = resolveOnPath("copilot");
if (!real) {
throw new UserError(
`cannot apply ${describeOverride(requestedModel, requestedEffort)} as copilot process flags because copilot was not found on PATH`,
"install the Copilot CLI, or pin a different agent / omit the model and effort override",
);
}
const { nodeCommand, dir } = writeArgvWrapper({ realCommand: real, extraArgs: extra, binName: "copilot" });
cleanups.push(() => fs.rmSync(dir, { recursive: true, force: true }));
return {
...baseInvocation({ notes, dispose }),
acpxAgentCommand: nodeCommand,
};
}

function grokInvocation({ requestedModel, requestedEffort, writeAccess = false, notes, cleanups, dispose }) {
if (process.platform === "win32") {
throw new UserError(
Expand Down
1 change: 1 addition & 0 deletions src/tui/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const HARNESS_HUES = {
cursor: "blue",
"cursor-ide": "blue",
hermes: "yellow",
copilot: "blue",
};

/**
Expand Down
55 changes: 55 additions & 0 deletions test/adapters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { execFileSync } from "node:child_process";

import * as claude from "../src/discovery/adapters/claude.js";
import * as codex from "../src/discovery/adapters/codex.js";
import * as copilot from "../src/discovery/adapters/copilot.js";
import * as pi from "../src/discovery/adapters/pi.js";
import * as grok from "../src/discovery/adapters/grok.js";
import * as cursorCli from "../src/discovery/adapters/cursor-cli.js";
Expand Down Expand Up @@ -103,6 +104,60 @@ test("claude adapter enumerates the default store and CLAUDE_CONFIG_DIR, without
assert.deepEqual(enumerateClaude(fakeHome, defaultRoot), ["personal.jsonl"]);
});

test("copilot adapter classifies a session from its session.start context", () => {
const file = path.join(FIXTURES, "copilot-session.jsonl");
const descriptor = copilot.classify(candidateFor(file));

assert.equal(descriptor.id, "11111111-2222-4333-8444-555555555555");
assert.equal(descriptor.cwd, "/work/demo");
assert.equal(descriptor.gitRoot, "/work/demo");
assert.equal(descriptor.gitBranch, "main");
assert.equal(descriptor.model, "claude-sonnet-5.5");
// The recorded repository is a host label, not a remote URL.
assert.deepEqual(descriptor.remotes, []);
});

test("copilot adapter keeps user turns, folds tool results, and drops injected and sub-agent events", () => {
const file = path.join(FIXTURES, "copilot-session.jsonl");
const { events, model } = copilot.read({ path: file });

assert.equal(model, "claude-sonnet-5.5");
assert.deepEqual(
messages(events).map((m) => `${m.role}: ${m.text}`),
[
"user: Fix the failing build",
"assistant: Looking at the build output.",
"user: Use pnpm, not npm",
"assistant: Switching to pnpm.",
],
);

const [toolCall] = tools(events);
assert.equal(toolCall.name, "bash");
assert.equal(toolCall.input.command, "npm test");
assert.equal(toolCall.result, "1 failing");
assert.equal(toolCall.status, "error");
});

test("copilot adapter enumerates events.jsonl per session and honors COPILOT_HOME", () => {
const previous = process.env.COPILOT_HOME;
const relocated = fs.mkdtempSync(path.join(os.tmpdir(), "backpass-copilot-home-"));
const sessionDir = path.join(relocated, "session-state", "abc");
fs.mkdirSync(sessionDir, { recursive: true });
fs.mkdirSync(path.join(relocated, "session-state", "empty"), { recursive: true });
fs.copyFileSync(path.join(FIXTURES, "copilot-session.jsonl"), path.join(sessionDir, "events.jsonl"));
process.env.COPILOT_HOME = relocated;
try {
assert.deepEqual(
copilot.enumerate().map((c) => path.relative(relocated, c.path)),
[path.join("session-state", "abc", "events.jsonl")],
);
} finally {
if (previous === undefined) delete process.env.COPILOT_HOME;
else process.env.COPILOT_HOME = previous;
}
});

test("codex adapter honors CODEX_HOME", () => {
const previous = process.env.CODEX_HOME;
const relocated = fs.mkdtempSync(path.join(os.tmpdir(), "backpass-codex-home-"));
Expand Down
11 changes: 10 additions & 1 deletion test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ test("the defaults match the approved design", () => {
assert.equal(config.minGapEvidence, 2);
assert.equal(config.jobs, 4);
assert.equal(config.discovery.since, "30d");
assert.deepEqual(config.discovery.harnesses, ["claude", "codex", "pi", "opencode", "grok", "cursor", "hermes"]);
assert.deepEqual(config.discovery.harnesses, [
"claude",
"codex",
"pi",
"opencode",
"grok",
"cursor",
"hermes",
"copilot",
]);
assert.ok(!config.discovery.harnesses.includes("cursor-ide"), "Cursor IDE is deferred to v1.1");
assert.deepEqual(config.analysis, { agent: null, model: null, effort: null }, "agents are auto-picked by default");
assert.deepEqual(config.synthesis, { agent: null, model: null, effort: null });
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/copilot-session.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{"type":"session.start","data":{"sessionId":"11111111-2222-4333-8444-555555555555","version":1,"producer":"copilot-agent","copilotVersion":"1.0.106","startTime":"2026-11-01T09:00:00.000Z","selectedModel":"claude-sonnet-5.5","context":{"cwd":"/work/demo","gitRoot":"/work/demo","repository":"acme/demo","hostType":"github","branch":"main"}},"id":"e1","timestamp":"2026-11-01T09:00:00.100Z","parentId":null}
{"type":"user.message","data":{"content":"Instructions loaded from AGENTS.md","source":"instruction-discovery","turnId":"0"},"id":"e2","timestamp":"2026-11-01T09:00:01.000Z","parentId":"e1"}
{"type":"user.message","data":{"content":"Fix the failing build","transformedContent":"<current_datetime>x</current_datetime>Fix the failing build","turnId":"0"},"id":"e3","timestamp":"2026-11-01T09:00:02.000Z","parentId":"e2"}
{"type":"assistant.message","data":{"messageId":"m1","model":"claude-sonnet-5.5","content":"Looking at the build output.","toolRequests":[{"toolCallId":"call_1","name":"bash","arguments":{"command":"npm test"}}],"turnId":"0"},"id":"e4","timestamp":"2026-11-01T09:00:03.000Z","parentId":"e3"}
{"type":"tool.execution_start","data":{"toolCallId":"call_1","toolName":"bash","arguments":{"command":"npm test"},"turnId":"0"},"id":"e5","timestamp":"2026-11-01T09:00:04.000Z","parentId":"e4"}
{"type":"tool.execution_complete","data":{"toolCallId":"call_1","success":false,"result":{"content":"1 failing"},"turnId":"0"},"id":"e6","timestamp":"2026-11-01T09:00:05.000Z","parentId":"e5"}
{"type":"user.message","data":{"content":"Delegated prompt for a sub-agent","source":"agent-abc","turnId":"1"},"id":"e7","timestamp":"2026-11-01T09:00:06.000Z","parentId":"e6"}
{"type":"assistant.message","data":{"messageId":"m2","model":"claude-haiku-4.5","content":"Sub-agent chatter","parentToolCallId":"call_task","toolRequests":[],"turnId":"1"},"id":"e8","timestamp":"2026-11-01T09:00:07.000Z","parentId":"e7"}
{"type":"user.message","data":{"content":"Use pnpm, not npm","source":"user","turnId":"2"},"id":"e9","timestamp":"2026-11-01T09:00:08.000Z","parentId":"e8"}
{"type":"assistant.message","data":{"messageId":"m3","model":"claude-sonnet-5.5","content":"Switching to pnpm.","toolRequests":[],"turnId":"2"},"id":"e10","timestamp":"2026-11-01T09:00:09.000Z","parentId":"e9"}
Loading
Loading