Skip to content

Commit 50df32e

Browse files
author
Prompsit CI
committed
Mirror b6eb8a4 (2026-03-18)
1 parent 87b0319 commit 50df32e

5 files changed

Lines changed: 30 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
99
- `/publish` skill: commit+push only, npm publish handled by CI
1010

1111
### Added
12+
- `--verbose` / `-v` CLI flag — enables debug logging to stderr for troubleshooting
1213
- `fix:all` npm script — ESLint autofix + Prettier in one command
1314
- `/changelog` skill for maintaining CHANGELOG.md
1415
- GitHub Release auto-creation from CHANGELOG.md Unreleased section

docs/reference/guides/logging-policy.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,20 @@ CLI/REPL entry point
154154

155155
---
156156

157-
## 6. Handler Output Formats
157+
## 6. CLI Verbosity Flag
158+
159+
| Flag | Console Level | Use Case |
160+
|------|--------------|----------|
161+
| _(none)_ | config `log_level` (default: `"warn"`) | Normal usage |
162+
| `--verbose` / `-v` | `"debug"` | Troubleshooting |
163+
164+
**Precedence** (highest wins): `--verbose` > `PROMPSIT_CLI__LOG_LEVEL` env var > `config.toml` `[cli] log_level` > `"warn"` default.
165+
166+
The flag is pre-scanned from `process.argv` before `setupLogging()`, so it captures all startup diagnostics. File logging (`~/.prompsit/debug.log`) always captures DEBUG regardless of this flag.
167+
168+
---
169+
170+
## 7. Handler Output Formats
158171

159172
| Handler | Destination | Format | Example |
160173
|---------|------------|--------|---------|
@@ -174,7 +187,7 @@ CLI/REPL entry point
174187

175188
---
176189

177-
## 7. Message Conventions
190+
## 8. Message Conventions
178191

179192
| Rule | Good | Bad |
180193
|------|------|-----|
@@ -185,7 +198,7 @@ CLI/REPL entry point
185198

186199
---
187200

188-
## 8. console.log vs logger
201+
## 9. console.log vs logger
189202

190203
| Output Type | Tool | Destination |
191204
|-------------|------|-------------|
@@ -200,7 +213,7 @@ CLI/REPL entry point
200213

201214
---
202215

203-
## 9. Anti-Patterns & Fixes
216+
## 10. Anti-Patterns & Fixes
204217

205218
| Anti-Pattern | Fix |
206219
|-------------|-----|
@@ -222,7 +235,7 @@ CLI/REPL entry point
222235
- New standard metadata fields
223236
- Logging infrastructure changes (new handlers)
224237

225-
**Last Updated:** 2026-02-15
238+
**Last Updated:** 2026-03-18
226239

227240
## Sources
228241

src/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ const isEntryPoint =
2323
stripExt(fileURLToPath(import.meta.url)) === stripExt(realpathSync(process.argv[1] ?? ""));
2424
if (isEntryPoint) {
2525
setupSignalHandlers();
26-
setupLogging();
26+
27+
// Pre-scan argv for --verbose before logging init (captures ALL startup logs)
28+
const userArgs = process.argv.slice(2);
29+
const isVerbose = userArgs.includes("--verbose") || userArgs.includes("-v");
30+
setupLogging(isVerbose ? "debug" : undefined);
2731
process.on("exit", shutdownLogging);
2832

2933
// Skill sync: deploy AI agent skills on launch (skip --help/--version quick-exit paths)
@@ -40,7 +44,8 @@ if (isEntryPoint) {
4044
}
4145

4246
// See API-503: No-args detection — enter REPL mode when no command specified
43-
const hasCommand = process.argv.length > 2;
47+
// Check for non-flag args (flags like --verbose should not prevent REPL entry)
48+
const hasCommand = userArgs.some((a) => !a.startsWith("-"));
4449

4550
if (hasCommand) {
4651
// Wrap in trace context: single trace_id for entire CLI command execution

src/logging/setup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ export function silenceConsole(): void {
2929
/**
3030
* Initialize logging with pino multistream: console (pretty), file, and optional Loki.
3131
*
32-
* Console level follows cli.log_level from config.
32+
* Console level: consoleOverride (CLI flag) > cli.log_level (config) > "warn" (default).
3333
* File stream always captures DEBUG (full diagnostics).
3434
* Root pino level = "debug" (lowest stream level, required by multistream).
3535
*/
36-
export function setupLogging(): void {
36+
export function setupLogging(consoleOverride?: LogLevel): void {
3737
if (_initialized) return;
3838
_initialized = true;
3939

4040
const settings = getSettings();
4141
const settingsDiagnostics = getSettingsDiagnostics();
42-
const configLevel = settings.cli.log_level as LogLevel;
42+
const configLevel = consoleOverride ?? (settings.cli.log_level as LogLevel);
4343

4444
// 1. Console stream: pino-pretty → gated stderr writable
4545
const gatedStderr = new Writable({

src/program.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ program.configureHelp({
3939

4040
program.helpOption("-h, --help", "Show this help");
4141
program.version(getVersion(), "-V, --version", "Show version number");
42+
program.option("-v, --verbose", "Enable debug logging to stderr");
4243

4344
// --- Grouped commands ---
4445

0 commit comments

Comments
 (0)