fix(audit): expand home paths across phase0 CLI scripts

Apply HOME-based ~ expansion to summarize/drift/prune audit scripts for input/output path flags to match capture behavior and avoid literal ~/ path bugs. Architecture/protocol diagrams reviewed; no updates needed for this path-resolution change.
This commit is contained in:
William Valentin
2026-02-27 13:30:08 -08:00
parent c91262ac30
commit 576b11106f
4 changed files with 57 additions and 9 deletions
+15 -2
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env node
import { writeFile } from 'node:fs/promises';
import { resolve } from 'node:path';
import { parseArgs } from 'node:util';
import { queryAuditLogs } from '../src/audit/export.js';
import {
@@ -59,6 +60,17 @@ function parseCsv(value: string | undefined): string[] | undefined {
return values.length > 0 ? values : undefined;
}
function expandHomePath(pathValue: string): string {
if (!pathValue.startsWith('~')) {
return pathValue;
}
const home = process.env.HOME;
if (!home) {
return pathValue;
}
return resolve(home, pathValue.slice(1));
}
function parseOptionalNumber(raw: string | undefined, flag: string): number | undefined {
if (!raw) {
return undefined;
@@ -148,7 +160,8 @@ async function main(): Promise<void> {
const startTime = parseTime(values.since, '--since');
const endTime = parseTime(values.until, '--until');
const events = await queryAuditLogs(values.audit, {
const auditPath = expandHomePath(values.audit);
const events = await queryAuditLogs(auditPath, {
start_time: startTime,
end_time: endTime,
event_types: [...DEFAULT_EVENT_TYPES],
@@ -170,7 +183,7 @@ async function main(): Promise<void> {
: renderPhase0BaselineMarkdown(summary, summaryOptions);
if (values.out) {
await writeFile(values.out, `${output}\n`, 'utf-8');
await writeFile(expandHomePath(values.out), `${output}\n`, 'utf-8');
} else {
process.stdout.write(`${output}\n`);
}