Skip to content

Commit 2365f00

Browse files
that-github-userunknownclaude
authored
Add --preview flag to apply command for reviewing changes (#47)
- `thinktank apply --preview` shows the diff with syntax highlighting (green for additions, red for removals, cyan for hunk headers) - Shows file list and change summary - Suggests the apply command to run after review - Does not modify the working tree Closes #33 Co-authored-by: unknown <that-github-user@github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2419a20 commit 2365f00

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ program
5757
.command("apply")
5858
.description("Apply the recommended (or selected) agent's changes to your repo")
5959
.option("-a, --agent <number>", "Apply a specific agent's changes instead of the recommended one")
60+
.option("-p, --preview", "Show the diff without applying")
6061
.action(async (opts) => {
6162
await apply({
6263
agent: opts.agent ? parseInt(opts.agent, 10) : undefined,
64+
preview: opts.preview ?? false,
6365
});
6466
});
6567

src/commands/apply.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { execFile } from "node:child_process";
22
import { readFile } from "node:fs/promises";
33
import { join } from "node:path";
44
import { promisify } from "node:util";
5+
import pc from "picocolors";
56
import type { EnsembleResult } from "../types.js";
67
import { cleanupBranches, getRepoRoot, removeWorktree } from "../utils/git.js";
78

89
const exec = promisify(execFile);
910

1011
export interface ApplyOptions {
1112
agent?: number;
13+
preview?: boolean;
1214
}
1315

1416
export async function apply(opts: ApplyOptions): Promise<void> {
@@ -41,6 +43,34 @@ export async function apply(opts: ApplyOptions): Promise<void> {
4143
process.exit(1);
4244
}
4345

46+
// Preview mode: show diff and exit
47+
if (opts.preview) {
48+
console.log();
49+
console.log(pc.bold(` Agent #${agentId} diff:`));
50+
console.log(pc.dim(" " + "─".repeat(58)));
51+
console.log();
52+
for (const line of agent.diff.split("\n")) {
53+
if (line.startsWith("+") && !line.startsWith("+++")) {
54+
console.log(pc.green(` ${line}`));
55+
} else if (line.startsWith("-") && !line.startsWith("---")) {
56+
console.log(pc.red(` ${line}`));
57+
} else if (line.startsWith("@@")) {
58+
console.log(pc.cyan(` ${line}`));
59+
} else {
60+
console.log(pc.dim(` ${line}`));
61+
}
62+
}
63+
console.log();
64+
console.log(` Files: ${agent.filesChanged.join(", ")}`);
65+
console.log(` Changes: +${agent.linesAdded}/-${agent.linesRemoved}`);
66+
console.log();
67+
console.log(
68+
pc.dim(" To apply: thinktank apply" + (opts.agent ? ` --agent ${opts.agent}` : "")),
69+
);
70+
console.log();
71+
return;
72+
}
73+
4474
// Apply the diff
4575
const repoRoot = await getRepoRoot();
4676
console.log(` Applying changes from Agent #${agentId}...`);

0 commit comments

Comments
 (0)