@principles/pd-cli 2.5.2 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/commands/health-codex.d.ts.map +1 -1
  2. package/dist/commands/health-codex.js +26 -1
  3. package/dist/commands/health-codex.js.map +1 -1
  4. package/dist/commands/health.d.ts.map +1 -1
  5. package/dist/commands/health.js +32 -2
  6. package/dist/commands/health.js.map +1 -1
  7. package/dist/commands/runtime-init.d.ts.map +1 -1
  8. package/dist/commands/runtime-init.js +29 -1
  9. package/dist/commands/runtime-init.js.map +1 -1
  10. package/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
  11. package/dist/commands/runtime-internalization-run-once.js +8 -13
  12. package/dist/commands/runtime-internalization-run-once.js.map +1 -1
  13. package/dist/commands/runtime-usage.d.ts +62 -0
  14. package/dist/commands/runtime-usage.d.ts.map +1 -0
  15. package/dist/commands/runtime-usage.js +315 -0
  16. package/dist/commands/runtime-usage.js.map +1 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +51 -17
  19. package/dist/index.js.map +1 -1
  20. package/dist/program.d.ts.map +1 -1
  21. package/dist/program.js +4 -0
  22. package/dist/program.js.map +1 -1
  23. package/dist/services/cli-invocation-log.d.ts +66 -0
  24. package/dist/services/cli-invocation-log.d.ts.map +1 -0
  25. package/dist/services/cli-invocation-log.js +139 -0
  26. package/dist/services/cli-invocation-log.js.map +1 -0
  27. package/dist/services/demo-story-a-runner.d.ts.map +1 -1
  28. package/dist/services/demo-story-a-runner.js +6 -2
  29. package/dist/services/demo-story-a-runner.js.map +1 -1
  30. package/dist/services/pd-config-loader.d.ts +3 -1
  31. package/dist/services/pd-config-loader.d.ts.map +1 -1
  32. package/dist/services/pd-config-loader.js +20 -8
  33. package/dist/services/pd-config-loader.js.map +1 -1
  34. package/package.json +7 -7
@@ -0,0 +1,62 @@
1
+ import type { Command } from 'commander';
2
+ export declare const DEFAULT_DAYS = 7;
3
+ export declare const MAX_DAYS = 365;
4
+ export interface RuntimeUsageReportOptions {
5
+ workspace?: string;
6
+ days?: number;
7
+ json?: boolean;
8
+ }
9
+ export interface ExitCodeBucket {
10
+ exitCode: string;
11
+ count: number;
12
+ }
13
+ export interface UsageGroup {
14
+ name: string;
15
+ count: number;
16
+ exitCodes: ExitCodeBucket[];
17
+ }
18
+ export interface RuntimeUsageReport {
19
+ ok: true;
20
+ status: 'ok' | 'empty' | 'degraded';
21
+ command: 'runtime usage report';
22
+ workspace: string;
23
+ days: number;
24
+ window: {
25
+ from: string;
26
+ to: string;
27
+ };
28
+ sinkFile: string;
29
+ coverage: {
30
+ /** Lines in the sink that were NOT cli_invocation records (other event types). */
31
+ otherEventLines: number;
32
+ /** Damaged records PLUS valid records outside the window (kept for compatibility). */
33
+ unreadableLines: number;
34
+ /** Subset of unreadableLines: bad JSON, non-object line, or unusable timestamp. */
35
+ malformedLines: number;
36
+ /** Subset of unreadableLines: well-formed records outside the requested window. */
37
+ outOfWindowLines: number;
38
+ /** Records inside the window that were missing a field (counted as UNKNOWN). */
39
+ missingCommand: number;
40
+ missingSource: number;
41
+ missingExitCode: number;
42
+ };
43
+ totals: {
44
+ invocations: number;
45
+ };
46
+ byCommand: UsageGroup[];
47
+ bySource: UsageGroup[];
48
+ notes: string[];
49
+ reason?: string;
50
+ nextAction?: string;
51
+ }
52
+ /**
53
+ * Aggregate the sink for the window. Pure read; returns the report object.
54
+ * Throws only when the workspace itself cannot be read — callers translate that
55
+ * into the documented error shape.
56
+ */
57
+ export declare function buildRuntimeUsageReport(workspaceDir: string, days: number, now?: Date): RuntimeUsageReport;
58
+ export declare function formatRuntimeUsageReport(report: RuntimeUsageReport): string;
59
+ export declare function handleRuntimeUsageReport(options: RuntimeUsageReportOptions): Promise<void>;
60
+ /** `pd runtime usage report` registration (cli-7: real tree, tested). */
61
+ export declare function registerRuntimeUsageCommand(runtimeCmd: Command): void;
62
+ //# sourceMappingURL=runtime-usage.d.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MAAM,EAAE;QACN,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,SAAS,EAAE,UAAU,EAAE,CAAC;IACxB,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAmCD;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,EACZ,GAAG,GAAE,IAAiB,GACrB,kBAAkB,CA4JpB;AAMD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAoC3E;AAED,wBAAsB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBhG;AAED,yEAAyE;AACzE,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAmBrE"}
@@ -0,0 +1,315 @@
1
+ /**
2
+ * `pd runtime usage report` — "which pd commands actually run here?"
3
+ *
4
+ * Read-only aggregation over the CLI invocation lines written by the process
5
+ * entry (`cli_invocation`, see services/cli-invocation-log.ts) into the
6
+ * workspace's non-rotated telemetry sink.
7
+ *
8
+ * What it can and cannot answer (stated in the output, rc-9):
9
+ * - CAN: per-command count, per-source count, and the exit-code distribution
10
+ * of each, inside the requested window.
11
+ * - CANNOT: reconstruct an invocation that was never recorded. Lines written
12
+ * before the recorder existed simply are not there — an empty result means
13
+ * "no records", never "the command was never used".
14
+ *
15
+ * CLI gate compliance:
16
+ * - cli-1-strict-json: --json stdout is exactly one parseable JSON object.
17
+ * - cli-2-exit-stops: invalid arguments set process.exitCode = 1 then return.
18
+ * - cli-4-dry-run-confirm-mutex: N/A (read-only, no mutation flags).
19
+ * - cli-5-failure-no-mutation: read-only; no file is created by this command.
20
+ * - cli-6-output-next-action: empty/degraded results carry reason + nextAction.
21
+ *
22
+ * Runtime contract compliance:
23
+ * - rc-1-treat-as-unknown: every parsed line starts as unknown.
24
+ * - rc-2-no-as-bypass: runtime guards only (typeof/isRecord), no casts.
25
+ * - rc-3-fail-loud-missing: malformed lines are COUNTED, not skipped silently.
26
+ * - rc-4-validate-array-elements: aggregation input is validated per record.
27
+ * - rc-5-object-hasown-not-in: Object.hasOwn for untrusted key checks.
28
+ * - rc-8-safe-serialization: output is built from validated primitives only.
29
+ * - rc-9-no-silent-fallback: every degraded source carries reason/notes.
30
+ */
31
+ import * as fs from 'fs';
32
+ import * as path from 'path';
33
+ import { resolveWorkspaceDir } from '../resolve-workspace.js';
34
+ import { emitError, emitResult } from '../services/cli-output.js';
35
+ import { CLI_INVOCATION_EVENT_TYPE, UNKNOWN, invocationLogPath } from '../services/cli-invocation-log.js';
36
+ export const DEFAULT_DAYS = 7;
37
+ export const MAX_DAYS = 365;
38
+ const DAY_MS = 24 * 3600 * 1000;
39
+ function isRecord(value) {
40
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
41
+ }
42
+ /** Read one untrusted string field, or UNKNOWN when absent/blank/wrong type. */
43
+ function readString(record, key) {
44
+ if (!Object.hasOwn(record, key))
45
+ return null;
46
+ const value = record[key];
47
+ if (typeof value !== 'string')
48
+ return null;
49
+ const trimmed = value.trim();
50
+ return trimmed === '' ? null : trimmed;
51
+ }
52
+ function bump(map, key) {
53
+ map.set(key, (map.get(key) ?? 0) + 1);
54
+ }
55
+ /** Group counts into a deterministic, count-descending list. */
56
+ function toGroups(counts, exitCodes) {
57
+ return [...counts.entries()]
58
+ .map(([name, count]) => {
59
+ const buckets = [...(exitCodes.get(name) ?? new Map()).entries()]
60
+ .map(([exitCode, bucketCount]) => ({ exitCode, count: bucketCount }))
61
+ .sort((a, b) => {
62
+ if (a.exitCode === UNKNOWN)
63
+ return 1;
64
+ if (b.exitCode === UNKNOWN)
65
+ return -1;
66
+ return Number(a.exitCode) - Number(b.exitCode);
67
+ });
68
+ return { name, count, exitCodes: buckets };
69
+ })
70
+ .sort((a, b) => (b.count !== a.count ? b.count - a.count : a.name.localeCompare(b.name)));
71
+ }
72
+ /**
73
+ * Aggregate the sink for the window. Pure read; returns the report object.
74
+ * Throws only when the workspace itself cannot be read — callers translate that
75
+ * into the documented error shape.
76
+ */
77
+ export function buildRuntimeUsageReport(workspaceDir, days, now = new Date()) {
78
+ const sinkFile = invocationLogPath(workspaceDir);
79
+ const from = new Date(now.getTime() - days * DAY_MS);
80
+ const base = {
81
+ ok: true,
82
+ status: 'ok',
83
+ command: 'runtime usage report',
84
+ workspace: workspaceDir,
85
+ days,
86
+ window: { from: from.toISOString(), to: now.toISOString() },
87
+ sinkFile,
88
+ coverage: {
89
+ otherEventLines: 0,
90
+ unreadableLines: 0,
91
+ malformedLines: 0,
92
+ outOfWindowLines: 0,
93
+ missingCommand: 0,
94
+ missingSource: 0,
95
+ missingExitCode: 0,
96
+ },
97
+ totals: { invocations: 0 },
98
+ byCommand: [],
99
+ bySource: [],
100
+ notes: [
101
+ 'Only recorded invocations are counted: a command that ran before this recorder existed leaves no line.',
102
+ 'Exit code UNKNOWN means the field was absent or unreadable in the record, not that the command succeeded.',
103
+ ],
104
+ };
105
+ if (!fs.existsSync(sinkFile)) {
106
+ // The recorder only appends to an existing sink (it must not create one for
107
+ // a read-only command), so "run any command" would never produce a record
108
+ // here. Point at the one-time bootstrap instead.
109
+ return {
110
+ ...base,
111
+ status: 'empty',
112
+ reason: 'sink_not_initialized',
113
+ nextAction: `Run 'pd runtime init --confirm --workspace "${workspaceDir}"' once to create the telemetry sink, then retry.`,
114
+ };
115
+ }
116
+ let raw;
117
+ try {
118
+ raw = fs.readFileSync(sinkFile, 'utf8');
119
+ }
120
+ catch {
121
+ // EP-08/ERR-198: a closed reason code only — a filesystem message can embed
122
+ // absolute paths or config fragments and must not be copied into the report.
123
+ return {
124
+ ...base,
125
+ status: 'degraded',
126
+ reason: 'sink_unreadable',
127
+ notes: [
128
+ ...base.notes,
129
+ 'Reading the telemetry sink failed (permissions or corruption); no counts are derived from it.',
130
+ ],
131
+ nextAction: 'Check file permissions/ownership on the telemetry sink, then retry.',
132
+ };
133
+ }
134
+ const commandCounts = new Map();
135
+ const sourceCounts = new Map();
136
+ const commandExitCodes = new Map();
137
+ const sourceExitCodes = new Map();
138
+ const coverage = { ...base.coverage };
139
+ for (const line of raw.split(/\r?\n/)) {
140
+ if (line.trim() === '')
141
+ continue;
142
+ let parsed;
143
+ try {
144
+ parsed = JSON.parse(line);
145
+ }
146
+ catch {
147
+ coverage.malformedLines += 1;
148
+ coverage.unreadableLines += 1;
149
+ continue;
150
+ }
151
+ if (!isRecord(parsed)) {
152
+ coverage.malformedLines += 1;
153
+ coverage.unreadableLines += 1;
154
+ continue;
155
+ }
156
+ if (readString(parsed, 'eventType') !== CLI_INVOCATION_EVENT_TYPE) {
157
+ coverage.otherEventLines += 1;
158
+ continue;
159
+ }
160
+ const timestamp = readString(parsed, 'timestamp');
161
+ const at = timestamp === null ? Number.NaN : Date.parse(timestamp);
162
+ if (!Number.isFinite(at)) {
163
+ coverage.malformedLines += 1;
164
+ coverage.unreadableLines += 1;
165
+ continue;
166
+ }
167
+ // A valid record outside the window is NOT damage — counting it as such
168
+ // would make every short window look like a corrupt sink (EP-03).
169
+ if (at < from.getTime() || at > now.getTime()) {
170
+ coverage.outOfWindowLines += 1;
171
+ coverage.unreadableLines += 1;
172
+ continue;
173
+ }
174
+ const payload = isRecord(parsed.payload) ? parsed.payload : {};
175
+ const command = readString(payload, 'command');
176
+ const source = readString(payload, 'source');
177
+ const exitCodeRaw = Object.hasOwn(payload, 'exitCode') ? payload.exitCode : undefined;
178
+ const exitCode = typeof exitCodeRaw === 'number' && Number.isInteger(exitCodeRaw) ? String(exitCodeRaw) : UNKNOWN;
179
+ if (command === null)
180
+ coverage.missingCommand += 1;
181
+ if (source === null)
182
+ coverage.missingSource += 1;
183
+ if (exitCode === UNKNOWN)
184
+ coverage.missingExitCode += 1;
185
+ const commandKey = command ?? UNKNOWN;
186
+ const sourceKey = source ?? UNKNOWN;
187
+ bump(commandCounts, commandKey);
188
+ bump(sourceCounts, sourceKey);
189
+ const commandBuckets = commandExitCodes.get(commandKey) ?? new Map();
190
+ commandExitCodes.set(commandKey, commandBuckets);
191
+ bump(commandBuckets, exitCode);
192
+ const sourceBuckets = sourceExitCodes.get(sourceKey) ?? new Map();
193
+ sourceExitCodes.set(sourceKey, sourceBuckets);
194
+ bump(sourceBuckets, exitCode);
195
+ }
196
+ const report = {
197
+ ...base,
198
+ coverage,
199
+ totals: { invocations: [...commandCounts.values()].reduce((sum, n) => sum + n, 0) },
200
+ byCommand: toGroups(commandCounts, commandExitCodes),
201
+ bySource: toGroups(sourceCounts, sourceExitCodes),
202
+ };
203
+ if (report.totals.invocations === 0) {
204
+ return {
205
+ ...report,
206
+ status: 'empty',
207
+ reason: 'no_records_in_window',
208
+ nextAction: `Widen the window (--days ${Math.min(days * 4, MAX_DAYS)}) or run a pd command to start recording.`,
209
+ };
210
+ }
211
+ // rc-9 / EP-03: an incomplete aggregation must say so. `unreadableLines`
212
+ // alone cannot drive this — it also counts perfectly valid out-of-window
213
+ // records, which would flag every short window as corrupt.
214
+ const missingFields = coverage.missingCommand + coverage.missingSource + coverage.missingExitCode;
215
+ if (coverage.malformedLines > 0 || missingFields > 0) {
216
+ return {
217
+ ...report,
218
+ status: 'degraded',
219
+ reason: 'incomplete_sink_records',
220
+ notes: [
221
+ ...report.notes,
222
+ `Coverage is partial: ${coverage.malformedLines} malformed line(s) and ${missingFields} missing field(s) were excluded or bucketed as UNKNOWN.`,
223
+ ],
224
+ nextAction: 'Inspect the telemetry sink for truncated/corrupt lines and records with missing fields, then retry; the counts above cover only usable records.',
225
+ };
226
+ }
227
+ return report;
228
+ }
229
+ function formatExitCodes(buckets) {
230
+ return buckets.map((bucket) => `${bucket.exitCode}:${bucket.count}`).join(' ');
231
+ }
232
+ export function formatRuntimeUsageReport(report) {
233
+ const lines = [];
234
+ lines.push('PD CLI usage report (recorded invocations only)');
235
+ lines.push(` workspace: ${report.workspace}`);
236
+ lines.push(` window: ${report.window.from} → ${report.window.to} (${report.days} day(s))`);
237
+ lines.push(` sink: ${report.sinkFile}`);
238
+ lines.push(` status: ${report.status}`);
239
+ lines.push(` totals: ${report.totals.invocations} invocation(s)`);
240
+ lines.push('');
241
+ lines.push('By command (count, exit codes)');
242
+ if (report.byCommand.length === 0)
243
+ lines.push(' (none)');
244
+ for (const group of report.byCommand) {
245
+ lines.push(` ${String(group.count).padStart(4)} pd ${group.name} [${formatExitCodes(group.exitCodes)}]`);
246
+ }
247
+ lines.push('');
248
+ lines.push('By source (count, exit codes)');
249
+ if (report.bySource.length === 0)
250
+ lines.push(' (none)');
251
+ for (const group of report.bySource) {
252
+ lines.push(` ${String(group.count).padStart(4)} ${group.name} [${formatExitCodes(group.exitCodes)}]`);
253
+ }
254
+ lines.push('');
255
+ lines.push('Coverage');
256
+ lines.push(` other event lines in sink: ${report.coverage.otherEventLines}`);
257
+ lines.push(` unreadable/out-of-window: ${report.coverage.unreadableLines}`);
258
+ lines.push(` malformed lines: ${report.coverage.malformedLines}`);
259
+ lines.push(` out-of-window records: ${report.coverage.outOfWindowLines}`);
260
+ lines.push(` records missing command: ${report.coverage.missingCommand}`);
261
+ lines.push(` records missing source: ${report.coverage.missingSource}`);
262
+ lines.push(` records missing exitCode: ${report.coverage.missingExitCode}`);
263
+ for (const note of report.notes)
264
+ lines.push(` note: ${note}`);
265
+ if (report.reason !== undefined)
266
+ lines.push(` reason: ${report.reason}`);
267
+ if (report.nextAction !== undefined) {
268
+ lines.push('');
269
+ lines.push(`Next action: ${report.nextAction}`);
270
+ }
271
+ return lines.join('\n');
272
+ }
273
+ export async function handleRuntimeUsageReport(options) {
274
+ const json = options.json === true;
275
+ const days = options.days ?? DEFAULT_DAYS;
276
+ if (!Number.isInteger(days) || days < 1 || days > MAX_DAYS) {
277
+ process.exitCode = emitError(new Error(`--days must be an integer between 1 and ${MAX_DAYS}, got ${days}`), {
278
+ json,
279
+ nextAction: `Pass --days as an integer in [1, ${MAX_DAYS}] (e.g. --days 30). Omit for the default (${DEFAULT_DAYS}).`,
280
+ });
281
+ return; // cli-2-exit-stops
282
+ }
283
+ try {
284
+ const workspaceDir = options.workspace ? path.resolve(options.workspace) : resolveWorkspaceDir();
285
+ const report = buildRuntimeUsageReport(workspaceDir, days);
286
+ emitResult(report, { json, formatText: formatRuntimeUsageReport });
287
+ }
288
+ catch (err) {
289
+ process.exitCode = emitError(err, {
290
+ json,
291
+ nextAction: 'Check the workspace path (-w) and that .pd/telemetry is readable, then retry.',
292
+ });
293
+ }
294
+ }
295
+ /** `pd runtime usage report` registration (cli-7: real tree, tested). */
296
+ export function registerRuntimeUsageCommand(runtimeCmd) {
297
+ const usageCmd = runtimeCmd
298
+ .command('usage')
299
+ .description('Inspect recorded pd CLI usage for this workspace (read-only)');
300
+ usageCmd
301
+ .command('report')
302
+ .description('Count recorded pd invocations by command and source, with exit-code distribution')
303
+ .option('--days <n>', `Window in days (1-${MAX_DAYS})`, String(DEFAULT_DAYS))
304
+ .option('-w, --workspace <path>', 'Workspace directory')
305
+ .option('--json', 'Emit a single machine-readable JSON object')
306
+ .action(async (opts) => {
307
+ const parsed = Number(opts.days);
308
+ await handleRuntimeUsageReport({
309
+ workspace: opts.workspace,
310
+ days: Number.isFinite(parsed) ? parsed : Number.NaN,
311
+ json: opts.json === true,
312
+ });
313
+ });
314
+ }
315
+ //# sourceMappingURL=runtime-usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-usage.js","sourceRoot":"","sources":["../../src/commands/runtime-usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MA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IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG;YACnD,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,IAAI;SACzB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAmBA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AA6BA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,23 +1,57 @@
1
1
  #!/usr/bin/env node
2
- /**
3
- * Process entry for the `pd` command.
4
- *
5
- * The command tree lives in `./program.js` so that tests and other library
6
- * consumers can import it WITHOUT executing the CLI. This file is the only
7
- * place that parses argv, and it does so unconditionally.
8
- *
9
- * Why unconditional (regression introduced by #2555): every real entry reaches
10
- * the CLI through this file — `package.json#bin`, the installer's
11
- * `pd` / `pd.cmd` / `pd.ps1` shims, and any loader shim that wraps it
12
- * (`import 'file://…/dist/index.js'`). An `argv[1] === import.meta.url` guard
13
- * cannot see the loader-shim shape, because argv[1] is then the wrapper: the
14
- * process exits 0 having done nothing. Import safety is guaranteed by the
15
- * module boundary instead — import `./program.js` for the tree, never this
16
- * file.
17
- */
18
2
  import { handleVersionFlag, program } from './program.js';
3
+ import { INVOCATION_SOURCE_ENV, recordCliInvocation, resolveRecordedWorkspace, } from './services/cli-invocation-log.js';
19
4
  export { buildPdProgram } from './program.js';
20
- if (!handleVersionFlag(process.argv.slice(2))) {
5
+ /** Full command path of the command whose action is about to run. */
6
+ function commandPath(action) {
7
+ const parts = [];
8
+ let current = action;
9
+ while (current !== null && current.parent !== null) {
10
+ parts.unshift(current.name());
11
+ current = current.parent;
12
+ }
13
+ return parts.join(' ');
14
+ }
15
+ let invokedCommand = null;
16
+ let recordedWorkspace = null;
17
+ program.hook('preAction', (_thisCommand, actionCommand) => {
18
+ try {
19
+ invokedCommand = commandPath(actionCommand);
20
+ const rawOpts = actionCommand.opts();
21
+ let workspace;
22
+ if (typeof rawOpts === 'object' && rawOpts !== null) {
23
+ const value = Reflect.get(rawOpts, 'workspace');
24
+ if (typeof value === 'string')
25
+ workspace = value;
26
+ }
27
+ recordedWorkspace = resolveRecordedWorkspace(workspace);
28
+ }
29
+ catch {
30
+ // Recording must never break dispatch; unresolved fields stay UNKNOWN.
31
+ }
32
+ });
33
+ const argv = process.argv.slice(2);
34
+ const versionFlagOnly = argv.includes('--version') || argv.includes('-V');
35
+ process.on('exit', (code) => {
36
+ try {
37
+ const command = invokedCommand ?? (versionFlagOnly ? 'version' : null);
38
+ // Help/no-argument exits (code 0, no action) are not command usage: skip
39
+ // them instead of padding the report with UNKNOWN rows. A non-zero exit is
40
+ // always recorded — that is exactly the failed invocation worth seeing.
41
+ if (command === null && code === 0)
42
+ return;
43
+ recordCliInvocation({
44
+ workspaceDir: recordedWorkspace ?? resolveRecordedWorkspace(undefined),
45
+ command,
46
+ exitCode: typeof code === 'number' ? code : null,
47
+ rawSource: process.env[INVOCATION_SOURCE_ENV],
48
+ });
49
+ }
50
+ catch {
51
+ // Never let usage recording alter the process result.
52
+ }
53
+ });
54
+ if (!handleVersionFlag(argv)) {
21
55
  program.parse();
22
56
  }
23
57
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,KAA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M,WAAW,CAAC;AAkF5C,eAAO,MAAM,OAAO,SAAgB,CAAC;AAMrC,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAkBlE;AAoxCD;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAExC"}
1
+ {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,CAAC;AAmF5C,eAAO,MAAM,OAAO,SAAgB,CAAC;AAMrC,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAkBlE;AAwxCD;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAExC"}
package/dist/program.js CHANGED
@@ -31,6 +31,7 @@ import { registerRuntimeProbeCommand } from './commands/runtime.js';
31
31
  import { handleFlowShow } from './commands/flow.js';
32
32
  import { handleTraceShow } from './commands/trace.js';
33
33
  import { handlePruningReport, handlePruningExplain, handlePruningOrphans } from './commands/runtime-pruning.js';
34
+ import { registerRuntimeUsageCommand } from './commands/runtime-usage.js';
34
35
  import { handleRuntimeHealthSnapshot } from './commands/runtime-health-snapshot.js';
35
36
  import { handleRuntimeUat } from './commands/runtime-uat.js';
36
37
  import { handleRuntimeInternalizationQueue } from './commands/runtime-internalization-queue.js';
@@ -973,6 +974,9 @@ pruningCmd
973
974
  json: opts.json,
974
975
  });
975
976
  });
977
+ // Owner-facing observability: which pd commands actually run in this workspace,
978
+ // from which caller, and how they exit (read-only; see runtime-usage.ts).
979
+ registerRuntimeUsageCommand(runtimeCmd);
976
980
  // ── Candidate inspection commands ─────────────────────────────────────────────
977
981
  const candidateCmd = program
978
982
  .command('candidate')