Skip to content

Commit ae66286

Browse files
committed
feat: Task 1: Add a CLI flag to display metrics summary and exit without starting the loop
1 parent f0a4231 commit ae66286

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/cli.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
* CLI argument parsing and program setup
33
*/
44

5+
import { resolve } from "node:path"
56
import { Command } from "commander"
67
import { loadConfig } from "./config.ts"
8+
import { initializePaths } from "./fs.ts"
79
import { runLoop } from "./loop.ts"
10+
import { formatMetricsSummary, loadMetrics } from "./metrics.ts"
811
import type { CliOptions } from "./types.ts"
912

1013
const VERSION = "1.0.0"
@@ -39,6 +42,7 @@ function createProgram(): Command {
3942
.option("--no-auto-commit", "Disable automatic commits after tasks")
4043
.option("--no-auto-push", "Disable automatic push after cycles")
4144
.option("-s, --signoff", "Add Signed-off-by line to commits")
45+
.option("--status", "Display metrics summary and exit")
4246

4347
// Add examples to help
4448
program.addHelpText(
@@ -63,6 +67,12 @@ Examples:
6367
$ opencoder -m anthropic/claude-sonnet-4 -s
6468
Run with commit signoff enabled
6569
70+
$ opencoder --status
71+
Display metrics summary without starting the loop
72+
73+
$ opencoder --status -p ./myproject
74+
Display metrics for a specific project
75+
6676
Options:
6777
-p, --project <dir> Project directory (default: current directory)
6878
-m, --model <model> Model for both plan and build
@@ -72,6 +82,7 @@ Options:
7282
--no-auto-commit Disable automatic commits after tasks
7383
--no-auto-push Disable automatic push after cycles
7484
-s, --signoff Add Signed-off-by line to commits
85+
--status Display metrics summary and exit
7586
7687
Environment variables:
7788
OPENCODER_PLAN_MODEL Default plan model
@@ -133,6 +144,7 @@ export function parseCli(argv: string[] = process.argv): ParsedCli {
133144
autoCommit: opts.autoCommit as boolean | undefined,
134145
autoPush: opts.autoPush as boolean | undefined,
135146
commitSignoff: opts.signoff as boolean | undefined,
147+
status: opts.status as boolean | undefined,
136148
},
137149
hint: args[0],
138150
}
@@ -169,6 +181,21 @@ export async function run(): Promise<void> {
169181
autoCommit: opts.autoCommit as boolean | undefined,
170182
autoPush: opts.autoPush as boolean | undefined,
171183
commitSignoff: opts.signoff as boolean | undefined,
184+
status: opts.status as boolean | undefined,
185+
}
186+
187+
// Handle --status flag: display metrics and exit
188+
if (cliOptions.status) {
189+
const projectDir = cliOptions.project ? resolve(cliOptions.project) : process.cwd()
190+
const paths = initializePaths(projectDir)
191+
const metrics = await loadMetrics(paths.metricsFile)
192+
193+
console.log("\nOpenCoder Metrics")
194+
console.log("=================\n")
195+
console.log(formatMetricsSummary(metrics))
196+
console.log(`\nLast activity: ${metrics.lastActivityTime}`)
197+
console.log("")
198+
return
172199
}
173200

174201
const config = await loadConfig(cliOptions, hint)

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,5 @@ export interface CliOptions {
180180
autoCommit?: boolean
181181
autoPush?: boolean
182182
commitSignoff?: boolean
183+
status?: boolean
183184
}

0 commit comments

Comments
 (0)