@principles/pd-cli 1.73.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.
- package/README.md +90 -0
- package/dist/commands/artifact.d.ts +14 -0
- package/dist/commands/artifact.d.ts.map +1 -0
- package/dist/commands/artifact.js +67 -0
- package/dist/commands/artifact.js.map +1 -0
- package/dist/commands/candidate.d.ts +83 -0
- package/dist/commands/candidate.d.ts.map +1 -0
- package/dist/commands/candidate.js +891 -0
- package/dist/commands/candidate.js.map +1 -0
- package/dist/commands/central-sync.d.ts +10 -0
- package/dist/commands/central-sync.d.ts.map +1 -0
- package/dist/commands/central-sync.js +32 -0
- package/dist/commands/central-sync.js.map +1 -0
- package/dist/commands/console.d.ts +9 -0
- package/dist/commands/console.d.ts.map +1 -0
- package/dist/commands/console.js +114 -0
- package/dist/commands/console.js.map +1 -0
- package/dist/commands/context.d.ts +7 -0
- package/dist/commands/context.d.ts.map +1 -0
- package/dist/commands/context.js +55 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/demo-story-a.d.ts +12 -0
- package/dist/commands/demo-story-a.d.ts.map +1 -0
- package/dist/commands/demo-story-a.js +175 -0
- package/dist/commands/demo-story-a.js.map +1 -0
- package/dist/commands/diagnose.d.ts +35 -0
- package/dist/commands/diagnose.d.ts.map +1 -0
- package/dist/commands/diagnose.js +390 -0
- package/dist/commands/diagnose.js.map +1 -0
- package/dist/commands/evolution-tasks-list.d.ts +15 -0
- package/dist/commands/evolution-tasks-list.d.ts.map +1 -0
- package/dist/commands/evolution-tasks-list.js +34 -0
- package/dist/commands/evolution-tasks-list.js.map +1 -0
- package/dist/commands/evolution-tasks-show.d.ts +14 -0
- package/dist/commands/evolution-tasks-show.d.ts.map +1 -0
- package/dist/commands/evolution-tasks-show.js +52 -0
- package/dist/commands/evolution-tasks-show.js.map +1 -0
- package/dist/commands/flow.d.ts +7 -0
- package/dist/commands/flow.d.ts.map +1 -0
- package/dist/commands/flow.js +57 -0
- package/dist/commands/flow.js.map +1 -0
- package/dist/commands/health.d.ts +16 -0
- package/dist/commands/health.d.ts.map +1 -0
- package/dist/commands/health.js +150 -0
- package/dist/commands/health.js.map +1 -0
- package/dist/commands/history.d.ts +11 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +50 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/legacy-cleanup.d.ts +27 -0
- package/dist/commands/legacy-cleanup.d.ts.map +1 -0
- package/dist/commands/legacy-cleanup.js +171 -0
- package/dist/commands/legacy-cleanup.js.map +1 -0
- package/dist/commands/legacy-import.d.ts +7 -0
- package/dist/commands/legacy-import.d.ts.map +1 -0
- package/dist/commands/legacy-import.js +86 -0
- package/dist/commands/legacy-import.js.map +1 -0
- package/dist/commands/pain-record.d.ts +10 -0
- package/dist/commands/pain-record.d.ts.map +1 -0
- package/dist/commands/pain-record.js +162 -0
- package/dist/commands/pain-record.js.map +1 -0
- package/dist/commands/proven-channel-baseline.d.ts +12 -0
- package/dist/commands/proven-channel-baseline.d.ts.map +1 -0
- package/dist/commands/proven-channel-baseline.js +97 -0
- package/dist/commands/proven-channel-baseline.js.map +1 -0
- package/dist/commands/remediation-output.d.ts +40 -0
- package/dist/commands/remediation-output.d.ts.map +1 -0
- package/dist/commands/remediation-output.js +23 -0
- package/dist/commands/remediation-output.js.map +1 -0
- package/dist/commands/run.d.ts +10 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +68 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/runtime-activation.d.ts +11 -0
- package/dist/commands/runtime-activation.d.ts.map +1 -0
- package/dist/commands/runtime-activation.js +150 -0
- package/dist/commands/runtime-activation.js.map +1 -0
- package/dist/commands/runtime-canary.d.ts +30 -0
- package/dist/commands/runtime-canary.d.ts.map +1 -0
- package/dist/commands/runtime-canary.js +343 -0
- package/dist/commands/runtime-canary.js.map +1 -0
- package/dist/commands/runtime-diagnostics-export.d.ts +20 -0
- package/dist/commands/runtime-diagnostics-export.d.ts.map +1 -0
- package/dist/commands/runtime-diagnostics-export.js +177 -0
- package/dist/commands/runtime-diagnostics-export.js.map +1 -0
- package/dist/commands/runtime-features.d.ts +26 -0
- package/dist/commands/runtime-features.d.ts.map +1 -0
- package/dist/commands/runtime-features.js +70 -0
- package/dist/commands/runtime-features.js.map +1 -0
- package/dist/commands/runtime-gfi-snapshot.d.ts +7 -0
- package/dist/commands/runtime-gfi-snapshot.d.ts.map +1 -0
- package/dist/commands/runtime-gfi-snapshot.js +101 -0
- package/dist/commands/runtime-gfi-snapshot.js.map +1 -0
- package/dist/commands/runtime-health-snapshot.d.ts +7 -0
- package/dist/commands/runtime-health-snapshot.d.ts.map +1 -0
- package/dist/commands/runtime-health-snapshot.js +93 -0
- package/dist/commands/runtime-health-snapshot.js.map +1 -0
- package/dist/commands/runtime-idle-trigger.d.ts +12 -0
- package/dist/commands/runtime-idle-trigger.d.ts.map +1 -0
- package/dist/commands/runtime-idle-trigger.js +102 -0
- package/dist/commands/runtime-idle-trigger.js.map +1 -0
- package/dist/commands/runtime-internalization-enqueue-successors.d.ts +9 -0
- package/dist/commands/runtime-internalization-enqueue-successors.d.ts.map +1 -0
- package/dist/commands/runtime-internalization-enqueue-successors.js +393 -0
- package/dist/commands/runtime-internalization-enqueue-successors.js.map +1 -0
- package/dist/commands/runtime-internalization-integrity-repair.d.ts +9 -0
- package/dist/commands/runtime-internalization-integrity-repair.d.ts.map +1 -0
- package/dist/commands/runtime-internalization-integrity-repair.js +54 -0
- package/dist/commands/runtime-internalization-integrity-repair.js.map +1 -0
- package/dist/commands/runtime-internalization-integrity.d.ts +7 -0
- package/dist/commands/runtime-internalization-integrity.d.ts.map +1 -0
- package/dist/commands/runtime-internalization-integrity.js +53 -0
- package/dist/commands/runtime-internalization-integrity.js.map +1 -0
- package/dist/commands/runtime-internalization-queue.d.ts +7 -0
- package/dist/commands/runtime-internalization-queue.d.ts.map +1 -0
- package/dist/commands/runtime-internalization-queue.js +85 -0
- package/dist/commands/runtime-internalization-queue.js.map +1 -0
- package/dist/commands/runtime-internalization-run-once.d.ts +12 -0
- package/dist/commands/runtime-internalization-run-once.d.ts.map +1 -0
- package/dist/commands/runtime-internalization-run-once.js +546 -0
- package/dist/commands/runtime-internalization-run-once.js.map +1 -0
- package/dist/commands/runtime-internalization-wake-once.d.ts +8 -0
- package/dist/commands/runtime-internalization-wake-once.d.ts.map +1 -0
- package/dist/commands/runtime-internalization-wake-once.js +72 -0
- package/dist/commands/runtime-internalization-wake-once.js.map +1 -0
- package/dist/commands/runtime-pain-flood-simulation.d.ts +10 -0
- package/dist/commands/runtime-pain-flood-simulation.d.ts.map +1 -0
- package/dist/commands/runtime-pain-flood-simulation.js +104 -0
- package/dist/commands/runtime-pain-flood-simulation.js.map +1 -0
- package/dist/commands/runtime-pruning.d.ts +45 -0
- package/dist/commands/runtime-pruning.d.ts.map +1 -0
- package/dist/commands/runtime-pruning.js +355 -0
- package/dist/commands/runtime-pruning.js.map +1 -0
- package/dist/commands/runtime-recovery.d.ts +9 -0
- package/dist/commands/runtime-recovery.d.ts.map +1 -0
- package/dist/commands/runtime-recovery.js +94 -0
- package/dist/commands/runtime-recovery.js.map +1 -0
- package/dist/commands/runtime-synthetic-baseline.d.ts +7 -0
- package/dist/commands/runtime-synthetic-baseline.d.ts.map +1 -0
- package/dist/commands/runtime-synthetic-baseline.js +59 -0
- package/dist/commands/runtime-synthetic-baseline.js.map +1 -0
- package/dist/commands/runtime-uat.d.ts +52 -0
- package/dist/commands/runtime-uat.d.ts.map +1 -0
- package/dist/commands/runtime-uat.js +274 -0
- package/dist/commands/runtime-uat.js.map +1 -0
- package/dist/commands/runtime.d.ts +20 -0
- package/dist/commands/runtime.d.ts.map +1 -0
- package/dist/commands/runtime.js +256 -0
- package/dist/commands/runtime.js.map +1 -0
- package/dist/commands/samples-list.d.ts +11 -0
- package/dist/commands/samples-list.d.ts.map +1 -0
- package/dist/commands/samples-list.js +37 -0
- package/dist/commands/samples-list.js.map +1 -0
- package/dist/commands/samples-review.d.ts +14 -0
- package/dist/commands/samples-review.d.ts.map +1 -0
- package/dist/commands/samples-review.js +22 -0
- package/dist/commands/samples-review.js.map +1 -0
- package/dist/commands/task.d.ts +14 -0
- package/dist/commands/task.d.ts.map +1 -0
- package/dist/commands/task.js +92 -0
- package/dist/commands/task.js.map +1 -0
- package/dist/commands/trace.d.ts +19 -0
- package/dist/commands/trace.d.ts.map +1 -0
- package/dist/commands/trace.js +154 -0
- package/dist/commands/trace.js.map +1 -0
- package/dist/commands/trajectory.d.ts +11 -0
- package/dist/commands/trajectory.d.ts.map +1 -0
- package/dist/commands/trajectory.js +47 -0
- package/dist/commands/trajectory.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +736 -0
- package/dist/index.js.map +1 -0
- package/dist/legacy/legacy-import.d.ts +15 -0
- package/dist/legacy/legacy-import.d.ts.map +1 -0
- package/dist/legacy/legacy-import.js +141 -0
- package/dist/legacy/legacy-import.js.map +1 -0
- package/dist/legacy/session-history-import.d.ts +26 -0
- package/dist/legacy/session-history-import.d.ts.map +1 -0
- package/dist/legacy/session-history-import.js +151 -0
- package/dist/legacy/session-history-import.js.map +1 -0
- package/dist/principle-tree-ledger-adapter.d.ts +12 -0
- package/dist/principle-tree-ledger-adapter.d.ts.map +1 -0
- package/dist/principle-tree-ledger-adapter.js +12 -0
- package/dist/principle-tree-ledger-adapter.js.map +1 -0
- package/dist/resolve-workspace.d.ts +12 -0
- package/dist/resolve-workspace.d.ts.map +1 -0
- package/dist/resolve-workspace.js +20 -0
- package/dist/resolve-workspace.js.map +1 -0
- package/dist/services/demo-story-a-runner.d.ts +8 -0
- package/dist/services/demo-story-a-runner.d.ts.map +1 -0
- package/dist/services/demo-story-a-runner.js +369 -0
- package/dist/services/demo-story-a-runner.js.map +1 -0
- package/dist/services/feature-flag-loader.d.ts +6 -0
- package/dist/services/feature-flag-loader.d.ts.map +1 -0
- package/dist/services/feature-flag-loader.js +54 -0
- package/dist/services/feature-flag-loader.js.map +1 -0
- package/dist/services/pain-flood-simulation-runner.d.ts +10 -0
- package/dist/services/pain-flood-simulation-runner.d.ts.map +1 -0
- package/dist/services/pain-flood-simulation-runner.js +289 -0
- package/dist/services/pain-flood-simulation-runner.js.map +1 -0
- package/dist/services/proven-channel-baseline-runner.d.ts +12 -0
- package/dist/services/proven-channel-baseline-runner.d.ts.map +1 -0
- package/dist/services/proven-channel-baseline-runner.js +114 -0
- package/dist/services/proven-channel-baseline-runner.js.map +1 -0
- package/dist/services/synthetic-baseline-runner.d.ts +8 -0
- package/dist/services/synthetic-baseline-runner.d.ts.map +1 -0
- package/dist/services/synthetic-baseline-runner.js +251 -0
- package/dist/services/synthetic-baseline-runner.js.map +1 -0
- package/package.json +35 -0
- package/src/commands/artifact.ts +82 -0
- package/src/commands/candidate.ts +1117 -0
- package/src/commands/central-sync.ts +44 -0
- package/src/commands/console.ts +121 -0
- package/src/commands/context.ts +72 -0
- package/src/commands/demo-story-a.ts +195 -0
- package/src/commands/diagnose.ts +452 -0
- package/src/commands/evolution-tasks-list.ts +44 -0
- package/src/commands/evolution-tasks-show.ts +60 -0
- package/src/commands/flow.ts +60 -0
- package/src/commands/health.ts +189 -0
- package/src/commands/history.ts +63 -0
- package/src/commands/legacy-cleanup.ts +206 -0
- package/src/commands/legacy-import.ts +104 -0
- package/src/commands/pain-record.ts +167 -0
- package/src/commands/proven-channel-baseline.ts +113 -0
- package/src/commands/remediation-output.ts +66 -0
- package/src/commands/run.ts +89 -0
- package/src/commands/runtime-activation.ts +176 -0
- package/src/commands/runtime-canary.ts +371 -0
- package/src/commands/runtime-diagnostics-export.ts +229 -0
- package/src/commands/runtime-features.ts +103 -0
- package/src/commands/runtime-gfi-snapshot.ts +135 -0
- package/src/commands/runtime-health-snapshot.ts +106 -0
- package/src/commands/runtime-internalization-enqueue-successors.ts +479 -0
- package/src/commands/runtime-internalization-integrity-repair.ts +69 -0
- package/src/commands/runtime-internalization-integrity.ts +63 -0
- package/src/commands/runtime-internalization-queue.ts +106 -0
- package/src/commands/runtime-internalization-run-once.ts +658 -0
- package/src/commands/runtime-internalization-wake-once.ts +87 -0
- package/src/commands/runtime-pain-flood-simulation.ts +121 -0
- package/src/commands/runtime-pruning.ts +438 -0
- package/src/commands/runtime-recovery.ts +107 -0
- package/src/commands/runtime-synthetic-baseline.ts +70 -0
- package/src/commands/runtime-uat.ts +339 -0
- package/src/commands/runtime.ts +281 -0
- package/src/commands/samples-list.ts +43 -0
- package/src/commands/samples-review.ts +32 -0
- package/src/commands/task.ts +130 -0
- package/src/commands/trace.ts +174 -0
- package/src/commands/trajectory.ts +64 -0
- package/src/index.ts +829 -0
- package/src/legacy/legacy-import.ts +179 -0
- package/src/legacy/session-history-import.ts +231 -0
- package/src/principle-tree-ledger-adapter.ts +13 -0
- package/src/resolve-workspace.ts +20 -0
- package/src/services/demo-story-a-runner.ts +472 -0
- package/src/services/feature-flag-loader.ts +73 -0
- package/src/services/pain-flood-simulation-runner.ts +354 -0
- package/src/services/proven-channel-baseline-runner.ts +150 -0
- package/src/services/synthetic-baseline-runner.ts +291 -0
- package/tests/commands/candidate-audit-repair.test.ts +338 -0
- package/tests/commands/candidate-intake.test.ts +589 -0
- package/tests/commands/candidate-internalization-backfill.test.ts +480 -0
- package/tests/commands/candidate-internalize.test.ts +272 -0
- package/tests/commands/candidate-route.test.ts +328 -0
- package/tests/commands/candidate-show.test.ts +95 -0
- package/tests/commands/cli-command-tree.test.ts +64 -0
- package/tests/commands/context.test.ts +114 -0
- package/tests/commands/demo-story-a.test.ts +255 -0
- package/tests/commands/diagnose.test.ts +792 -0
- package/tests/commands/health.test.ts +330 -0
- package/tests/commands/pain-record.test.ts +316 -0
- package/tests/commands/plugin-config-resolution-cutover.test.ts +220 -0
- package/tests/commands/proven-channel-baseline.test.ts +441 -0
- package/tests/commands/runtime-activation.test.ts +168 -0
- package/tests/commands/runtime-canary.test.ts +369 -0
- package/tests/commands/runtime-diagnostics-export.test.ts +170 -0
- package/tests/commands/runtime-features.test.ts +114 -0
- package/tests/commands/runtime-health-snapshot.test.ts +357 -0
- package/tests/commands/runtime-internalization-enqueue-successors.test.ts +803 -0
- package/tests/commands/runtime-internalization-integrity-repair.test.ts +169 -0
- package/tests/commands/runtime-internalization-integrity.test.ts +102 -0
- package/tests/commands/runtime-internalization-queue.test.ts +252 -0
- package/tests/commands/runtime-internalization-run-once.test.ts +1318 -0
- package/tests/commands/runtime-internalization-wake-once.test.ts +170 -0
- package/tests/commands/runtime-internalization.test.ts +52 -0
- package/tests/commands/runtime-pain-flood-simulation.test.ts +418 -0
- package/tests/commands/runtime-pruning.test.ts +693 -0
- package/tests/commands/runtime-recovery.test.ts +96 -0
- package/tests/commands/runtime-synthetic-baseline.test.ts +249 -0
- package/tests/commands/runtime-uat.test.ts +397 -0
- package/tests/commands/runtime.test.ts +262 -0
- package/tests/commands/trace.test.ts +314 -0
- package/tests/e2e/candidate-intake-e2e.test.ts +316 -0
- package/tests/services/feature-flag-loader.test.ts +207 -0
- package/tests/services/proven-channel-baseline-runner.test.ts +30 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { loadEffectiveFeatureFlags } from '../services/feature-flag-loader.js';
|
|
3
|
+
import { resolveWorkspaceDir } from '../resolve-workspace.js';
|
|
4
|
+
|
|
5
|
+
export interface FeatureFlagsStatusOutput {
|
|
6
|
+
status: 'ok' | 'degraded';
|
|
7
|
+
source: string;
|
|
8
|
+
configPath: string;
|
|
9
|
+
flags: {
|
|
10
|
+
id: string;
|
|
11
|
+
category: string;
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
since: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
}[];
|
|
16
|
+
warnings: string[];
|
|
17
|
+
totalFlags: number;
|
|
18
|
+
enabledCount: number;
|
|
19
|
+
disabledCount: number;
|
|
20
|
+
reason?: string;
|
|
21
|
+
nextAction?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface FeaturesOptions {
|
|
25
|
+
workspace?: string;
|
|
26
|
+
json?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function buildFeatureFlagsStatus(workspaceDir: string): FeatureFlagsStatusOutput {
|
|
30
|
+
const effective = loadEffectiveFeatureFlags(workspaceDir);
|
|
31
|
+
const flags = Object.values(effective.flags);
|
|
32
|
+
const enabledCount = flags.filter(f => f.enabled).length;
|
|
33
|
+
const hasWarnings = effective.warnings.length > 0;
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
status: hasWarnings ? 'degraded' : 'ok',
|
|
37
|
+
source: effective.source,
|
|
38
|
+
configPath: effective.configPath,
|
|
39
|
+
flags: flags.map(f => ({
|
|
40
|
+
id: f.id,
|
|
41
|
+
category: f.category,
|
|
42
|
+
enabled: f.enabled,
|
|
43
|
+
since: f.since,
|
|
44
|
+
...(f.description ? { description: f.description } : {}),
|
|
45
|
+
})),
|
|
46
|
+
warnings: effective.warnings,
|
|
47
|
+
totalFlags: flags.length,
|
|
48
|
+
enabledCount,
|
|
49
|
+
disabledCount: flags.length - enabledCount,
|
|
50
|
+
...(hasWarnings ? {
|
|
51
|
+
reason: `Config warnings: ${effective.warnings.join('; ')}`,
|
|
52
|
+
nextAction: 'Review feature-flags.yaml for malformed overrides or unknown flags',
|
|
53
|
+
} : {}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function formatTextOutput(output: FeatureFlagsStatusOutput): string {
|
|
58
|
+
const lines: string[] = [];
|
|
59
|
+
|
|
60
|
+
lines.push('PD Feature Flags Status');
|
|
61
|
+
lines.push(`source: ${output.source}`);
|
|
62
|
+
lines.push(`config: ${output.configPath}`);
|
|
63
|
+
lines.push('');
|
|
64
|
+
|
|
65
|
+
const categoryOrder = ['core', 'quiet', 'gone', 'legacy_retire'] as const;
|
|
66
|
+
for (const category of categoryOrder) {
|
|
67
|
+
const categoryFlags = output.flags.filter(f => f.category === category);
|
|
68
|
+
if (categoryFlags.length === 0) continue;
|
|
69
|
+
|
|
70
|
+
lines.push(` ${category.toUpperCase()} (${categoryFlags.length})`);
|
|
71
|
+
for (const flag of categoryFlags) {
|
|
72
|
+
const icon = flag.enabled ? '+' : '-';
|
|
73
|
+
lines.push(` [${icon}] ${flag.id} (since ${flag.since})${flag.description ? ` — ${flag.description}` : ''}`);
|
|
74
|
+
}
|
|
75
|
+
lines.push('');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
lines.push(`Total: ${output.totalFlags} flags, ${output.enabledCount} enabled, ${output.disabledCount} disabled`);
|
|
79
|
+
|
|
80
|
+
if (output.warnings.length > 0) {
|
|
81
|
+
lines.push('');
|
|
82
|
+
lines.push('Warnings:');
|
|
83
|
+
for (const warning of output.warnings) {
|
|
84
|
+
lines.push(` [!] ${warning}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return lines.join('\n');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function handleRuntimeFeaturesStatus(opts: FeaturesOptions): Promise<void> {
|
|
92
|
+
const workspaceDir = opts.workspace
|
|
93
|
+
? path.resolve(opts.workspace)
|
|
94
|
+
: resolveWorkspaceDir();
|
|
95
|
+
|
|
96
|
+
const output = buildFeatureFlagsStatus(workspaceDir);
|
|
97
|
+
|
|
98
|
+
if (opts.json) {
|
|
99
|
+
console.log(JSON.stringify(output, null, 2));
|
|
100
|
+
} else {
|
|
101
|
+
console.log(formatTextOutput(output));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pd runtime gfi snapshot command — GFI workspace snapshot for Runtime V2.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* pd runtime gfi snapshot --workspace <path> --json
|
|
6
|
+
* pd runtime health gfi --workspace <path> --json (alias)
|
|
7
|
+
*
|
|
8
|
+
* Shows active vs stale session breakdown for GFI visibility.
|
|
9
|
+
* Stale sessions (>2h inactive) do NOT influence the active snapshot.
|
|
10
|
+
*
|
|
11
|
+
* PRI-78/PRI-82: GFI Observability
|
|
12
|
+
*/
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
import * as fs from 'fs';
|
|
15
|
+
import { buildGfiWorkspaceSnapshot } from '@principles/core/runtime-v2';
|
|
16
|
+
import type { GfiWorkspaceSnapshot } from '@principles/core/runtime-v2';
|
|
17
|
+
import { resolveWorkspaceDir } from '../resolve-workspace.js';
|
|
18
|
+
|
|
19
|
+
interface GfiSnapshotOptions {
|
|
20
|
+
workspace?: string;
|
|
21
|
+
json?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function formatTextOutput(snapshot: GfiWorkspaceSnapshot): string {
|
|
25
|
+
const lines: string[] = [];
|
|
26
|
+
|
|
27
|
+
lines.push('GFI Workspace Snapshot');
|
|
28
|
+
lines.push(`generatedAt: ${snapshot.generatedAt}`);
|
|
29
|
+
lines.push('');
|
|
30
|
+
|
|
31
|
+
if (snapshot.active) {
|
|
32
|
+
const a = snapshot.active;
|
|
33
|
+
lines.push('ACTIVE SESSION');
|
|
34
|
+
lines.push(` currentGfi: ${a.currentGfi} stage: ${a.stage}`);
|
|
35
|
+
lines.push(` dominantSource: ${a.dominantSource ?? '(none)'}`);
|
|
36
|
+
lines.push(` consecutiveErrors: ${a.consecutiveErrors}`);
|
|
37
|
+
lines.push(` dailyGfiPeak: ${a.dailyGfiPeak ?? '(none)'}`);
|
|
38
|
+
lines.push(` attitudeMode: ${a.consumers.attitudeMode}`);
|
|
39
|
+
lines.push(` painDiagnosticReason: ${a.consumers.painDiagnosticReason}`);
|
|
40
|
+
} else {
|
|
41
|
+
lines.push('ACTIVE SESSION: (none)');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
lines.push('');
|
|
45
|
+
|
|
46
|
+
if (snapshot.staleSessionCount > 0 && snapshot.staleGfiRange) {
|
|
47
|
+
lines.push(`STALE SESSIONS: ${snapshot.staleSessionCount} session(s)` +
|
|
48
|
+
` (GFI range: ${snapshot.staleGfiRange.min}-${snapshot.staleGfiRange.max})`);
|
|
49
|
+
} else {
|
|
50
|
+
lines.push('STALE SESSIONS: 0');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
lines.push('');
|
|
54
|
+
lines.push(`TOTAL: ${snapshot.totalSessionCount} session(s) (${snapshot.activeSessionCount} active)`);
|
|
55
|
+
|
|
56
|
+
return lines.join('\n');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function readPersistedSessions(workspaceDir: string): {
|
|
60
|
+
sessionId: string;
|
|
61
|
+
currentGfi: number;
|
|
62
|
+
gfiBySource?: Record<string, number>;
|
|
63
|
+
lastErrorSource?: string;
|
|
64
|
+
consecutiveErrors: number;
|
|
65
|
+
lastGfiDecayAt?: number;
|
|
66
|
+
dailyGfiPeak?: number;
|
|
67
|
+
lastActivityAt: number;
|
|
68
|
+
}[] {
|
|
69
|
+
const sessionDir = path.join(workspaceDir, '.state', 'sessions');
|
|
70
|
+
|
|
71
|
+
if (!fs.existsSync(sessionDir)) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const sessions: {
|
|
76
|
+
sessionId: string;
|
|
77
|
+
currentGfi: number;
|
|
78
|
+
gfiBySource?: Record<string, number>;
|
|
79
|
+
lastErrorSource?: string;
|
|
80
|
+
consecutiveErrors: number;
|
|
81
|
+
lastGfiDecayAt?: number;
|
|
82
|
+
dailyGfiPeak?: number;
|
|
83
|
+
lastActivityAt: number;
|
|
84
|
+
}[] = [];
|
|
85
|
+
let skippedCount = 0;
|
|
86
|
+
|
|
87
|
+
for (const file of fs.readdirSync(sessionDir)) {
|
|
88
|
+
if (!file.endsWith('.json')) continue;
|
|
89
|
+
try {
|
|
90
|
+
const raw = fs.readFileSync(path.join(sessionDir, file), 'utf8');
|
|
91
|
+
const parsed = JSON.parse(raw);
|
|
92
|
+
if (parsed?.sessionId) {
|
|
93
|
+
sessions.push({
|
|
94
|
+
sessionId: parsed.sessionId ?? file.replace('.json', ''),
|
|
95
|
+
currentGfi: parsed.currentGfi ?? 0,
|
|
96
|
+
gfiBySource: parsed.gfiBySource,
|
|
97
|
+
lastErrorSource: parsed.lastErrorSource,
|
|
98
|
+
consecutiveErrors: parsed.consecutiveErrors ?? 0,
|
|
99
|
+
lastGfiDecayAt: parsed.lastGfiDecayAt,
|
|
100
|
+
dailyGfiPeak: parsed.dailyGfiPeak,
|
|
101
|
+
lastActivityAt: parsed.lastActivityAt ?? parsed.lastControlActivityAt ?? 0,
|
|
102
|
+
});
|
|
103
|
+
} else {
|
|
104
|
+
skippedCount++;
|
|
105
|
+
}
|
|
106
|
+
} catch {
|
|
107
|
+
skippedCount++;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (skippedCount > 0) {
|
|
112
|
+
console.warn(`[runtime-gfi-snapshot] Skipped ${skippedCount} malformed session file(s)`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return sessions;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export async function handleRuntimeGfiSnapshot(opts: GfiSnapshotOptions): Promise<void> {
|
|
119
|
+
const workspaceDir = opts.workspace
|
|
120
|
+
? path.resolve(opts.workspace)
|
|
121
|
+
: resolveWorkspaceDir();
|
|
122
|
+
|
|
123
|
+
const sessions = readPersistedSessions(workspaceDir);
|
|
124
|
+
|
|
125
|
+
const snapshot = buildGfiWorkspaceSnapshot({
|
|
126
|
+
sessions,
|
|
127
|
+
nowMs: Date.now(),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
if (opts.json) {
|
|
131
|
+
console.log(JSON.stringify(snapshot, null, 2));
|
|
132
|
+
} else {
|
|
133
|
+
console.log(formatTextOutput(snapshot));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pd runtime health snapshot command — Operator health snapshot for Runtime V2.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* pd runtime health snapshot --workspace <path> --json
|
|
6
|
+
*
|
|
7
|
+
* Aggregates chain reliability, candidate/ledger consistency, and pruning
|
|
8
|
+
* lifecycle signals into a single operator-facing read-only snapshot.
|
|
9
|
+
*
|
|
10
|
+
* PRI-28: Operator health snapshot.
|
|
11
|
+
*/
|
|
12
|
+
import * as path from 'path';
|
|
13
|
+
import { OperatorHealthReadModel } from '@principles/core/runtime-v2';
|
|
14
|
+
import type { OperatorHealthSnapshot } from '@principles/core/runtime-v2';
|
|
15
|
+
import { resolveWorkspaceDir } from '../resolve-workspace.js';
|
|
16
|
+
|
|
17
|
+
interface HealthSnapshotOptions {
|
|
18
|
+
workspace?: string;
|
|
19
|
+
json?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function formatTextOutput(snapshot: OperatorHealthSnapshot): string {
|
|
23
|
+
const lines: string[] = [];
|
|
24
|
+
const statusIcon = snapshot.overallStatus === 'healthy' ? '✓' : '✗';
|
|
25
|
+
|
|
26
|
+
lines.push(`Operator Health Snapshot`);
|
|
27
|
+
lines.push(`generatedAt: ${snapshot.generatedAt}`);
|
|
28
|
+
lines.push(`workspace: ${snapshot.workspace}`);
|
|
29
|
+
lines.push('');
|
|
30
|
+
lines.push(`OVERALL: ${statusIcon} ${snapshot.overallStatus.toUpperCase()}`);
|
|
31
|
+
lines.push('');
|
|
32
|
+
|
|
33
|
+
// Pain chain
|
|
34
|
+
lines.push('painChain:');
|
|
35
|
+
if (snapshot.painChain.lastSuccessfulChain) {
|
|
36
|
+
const c = snapshot.painChain.lastSuccessfulChain;
|
|
37
|
+
lines.push(` lastChain: ${c.painId} → ${c.taskId} → ${c.runId ?? '-'} → ${c.artifactId ?? '-'}`);
|
|
38
|
+
lines.push(` candidates: ${c.candidateIds.length}, ledgerEntries: ${c.ledgerEntryIds.length}`);
|
|
39
|
+
} else {
|
|
40
|
+
lines.push(' lastChain: (none)');
|
|
41
|
+
}
|
|
42
|
+
lines.push('');
|
|
43
|
+
|
|
44
|
+
// Candidate/ledger
|
|
45
|
+
lines.push('candidateLedger:');
|
|
46
|
+
lines.push(` status: ${snapshot.candidateLedger.auditStatus}`);
|
|
47
|
+
if (snapshot.candidateLedger.missingLedgerCount > 0) {
|
|
48
|
+
lines.push(` missingLedger: ${snapshot.candidateLedger.missingLedgerCount}`);
|
|
49
|
+
}
|
|
50
|
+
lines.push('');
|
|
51
|
+
|
|
52
|
+
// Pruning
|
|
53
|
+
lines.push('pruning:');
|
|
54
|
+
lines.push(` watchCount: ${snapshot.pruning.watchCount}, reviewCount: ${snapshot.pruning.reviewCount}`);
|
|
55
|
+
if (snapshot.pruning.orphanDerivedCandidateCount > 0) {
|
|
56
|
+
lines.push(` orphanDerivedCandidates: ${snapshot.pruning.orphanDerivedCandidateCount}`);
|
|
57
|
+
}
|
|
58
|
+
lines.push('');
|
|
59
|
+
|
|
60
|
+
// GFI
|
|
61
|
+
if (snapshot.gfi.active) {
|
|
62
|
+
const g = snapshot.gfi.active;
|
|
63
|
+
lines.push(`gfi: stage=${g.stage} currentGfi=${g.currentGfi} dominantSource=${g.dominantSource ?? '-'} sessions=${snapshot.gfi.activeSessionCount}active/${snapshot.gfi.staleSessionCount}stale`);
|
|
64
|
+
} else {
|
|
65
|
+
lines.push('gfi: (no active sessions)');
|
|
66
|
+
}
|
|
67
|
+
lines.push('');
|
|
68
|
+
|
|
69
|
+
// Actions
|
|
70
|
+
if (snapshot.recommendedActions.length === 0) {
|
|
71
|
+
lines.push('No actions recommended.');
|
|
72
|
+
} else {
|
|
73
|
+
lines.push('Recommended actions:');
|
|
74
|
+
for (const action of snapshot.recommendedActions) {
|
|
75
|
+
lines.push(` [!] ${action}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return lines.join('\n');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function handleRuntimeHealthSnapshot(opts: HealthSnapshotOptions): Promise<void> {
|
|
83
|
+
const workspaceDir = opts.workspace
|
|
84
|
+
? path.resolve(opts.workspace)
|
|
85
|
+
: resolveWorkspaceDir();
|
|
86
|
+
|
|
87
|
+
const model = new OperatorHealthReadModel({ workspaceDir });
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const snapshot = await model.getSnapshot();
|
|
91
|
+
|
|
92
|
+
if (opts.json) {
|
|
93
|
+
console.log(JSON.stringify(snapshot, null, 2));
|
|
94
|
+
} else {
|
|
95
|
+
console.log(formatTextOutput(snapshot));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (snapshot.overallStatus !== 'healthy') {
|
|
99
|
+
console.error('');
|
|
100
|
+
console.error(`FAIL: overallStatus=${snapshot.overallStatus}`);
|
|
101
|
+
process.exitCode = 1;
|
|
102
|
+
}
|
|
103
|
+
} finally {
|
|
104
|
+
await model.close();
|
|
105
|
+
}
|
|
106
|
+
}
|