@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,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pd central sync command implementation.
|
|
3
|
+
*
|
|
4
|
+
* Usage: pd central sync
|
|
5
|
+
*
|
|
6
|
+
* Triggers a sync cycle via CentralDatabase.syncAll() and reports
|
|
7
|
+
* per-workspace sync results with exit code 0 on success, non-zero on failure.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
async function loadCentralDatabase(): Promise<{ CentralDatabase: new () => {
|
|
11
|
+
syncAll(): Map<string, number>;
|
|
12
|
+
dispose(): void;
|
|
13
|
+
} }> {
|
|
14
|
+
const importModule = Function('specifier', 'return import(specifier)') as (specifier: string) => Promise<{
|
|
15
|
+
CentralDatabase: new () => {
|
|
16
|
+
syncAll(): Map<string, number>;
|
|
17
|
+
dispose(): void;
|
|
18
|
+
};
|
|
19
|
+
}>;
|
|
20
|
+
return importModule('../../../openclaw-plugin/src/service/central-database.js');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function handleCentralSync(): Promise<void> {
|
|
24
|
+
try {
|
|
25
|
+
const { CentralDatabase } = await loadCentralDatabase();
|
|
26
|
+
const centralDb = new CentralDatabase();
|
|
27
|
+
const results = centralDb.syncAll();
|
|
28
|
+
|
|
29
|
+
const totalRecords = Array.from(results.values()).reduce((sum, count) => sum + count, 0);
|
|
30
|
+
const workspaceCount = results.size;
|
|
31
|
+
|
|
32
|
+
console.log(`Sync complete — ${totalRecords} records across ${workspaceCount} workspace(s).`);
|
|
33
|
+
|
|
34
|
+
for (const [workspaceName, count] of results.entries()) {
|
|
35
|
+
console.log(` ${workspaceName}: ${count} records`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
centralDb.dispose();
|
|
39
|
+
} catch (err) {
|
|
40
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
41
|
+
console.error(`Error: Sync failed — ${message}`);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { spawn } from 'child_process';
|
|
4
|
+
import { resolveWorkspaceDir } from '../resolve-workspace.js';
|
|
5
|
+
|
|
6
|
+
interface ConsoleOptions {
|
|
7
|
+
workspace?: string;
|
|
8
|
+
port?: string;
|
|
9
|
+
noAuth?: boolean;
|
|
10
|
+
json?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getConsoleDir(): string | null {
|
|
14
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE;
|
|
15
|
+
if (!homeDir) return null;
|
|
16
|
+
const consoleDir = path.join(homeDir, '.openclaw', 'extensions', 'principles-disciple', 'console');
|
|
17
|
+
return fs.existsSync(consoleDir) ? consoleDir : null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function handleConsole(opts: ConsoleOptions = {}): Promise<void> {
|
|
21
|
+
const workspaceDir = opts.workspace
|
|
22
|
+
? path.resolve(opts.workspace)
|
|
23
|
+
: resolveWorkspaceDir();
|
|
24
|
+
|
|
25
|
+
const consoleDir = getConsoleDir();
|
|
26
|
+
if (!consoleDir) {
|
|
27
|
+
const msg = 'pd-console is not installed. Run: npx create-principles-disciple to install.';
|
|
28
|
+
if (opts.json) {
|
|
29
|
+
console.log(JSON.stringify({ success: false, reason: msg, nextAction: 'npx create-principles-disciple' }));
|
|
30
|
+
} else {
|
|
31
|
+
console.error(msg);
|
|
32
|
+
}
|
|
33
|
+
process.exit(1);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const serverEntry = path.join(consoleDir, 'dist', 'server.js');
|
|
38
|
+
if (!fs.existsSync(serverEntry)) {
|
|
39
|
+
const msg = `Console server entry not found at ${serverEntry}. Re-run installer.`;
|
|
40
|
+
if (opts.json) {
|
|
41
|
+
console.log(JSON.stringify({ success: false, reason: msg, nextAction: 'npx create-principles-disciple' }));
|
|
42
|
+
} else {
|
|
43
|
+
console.error(msg);
|
|
44
|
+
}
|
|
45
|
+
process.exit(1);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const port = opts.port || '3100';
|
|
50
|
+
const host = '127.0.0.1';
|
|
51
|
+
const args = [serverEntry, '--workspace', workspaceDir, '--port', port, '--host', host];
|
|
52
|
+
if (opts.noAuth) args.push('--no-auth');
|
|
53
|
+
|
|
54
|
+
const child = spawn(process.execPath, args, {
|
|
55
|
+
stdio: opts.json ? 'pipe' : 'inherit',
|
|
56
|
+
env: { ...process.env },
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
let startupConfirmed = false;
|
|
60
|
+
|
|
61
|
+
child.on('error', (err) => {
|
|
62
|
+
if (opts.json) {
|
|
63
|
+
if (!startupConfirmed) {
|
|
64
|
+
console.log(JSON.stringify({
|
|
65
|
+
success: false,
|
|
66
|
+
reason: `Console spawn failed: ${err.message}`,
|
|
67
|
+
nextAction: 'Check Node.js installation and console server entry. Re-run: npx create-principles-disciple',
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
console.error(`Console spawn failed: ${err.message}`);
|
|
72
|
+
}
|
|
73
|
+
process.exit(1);
|
|
74
|
+
return;
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
child.on('exit', (code) => {
|
|
78
|
+
if (code !== 0 && code !== null) {
|
|
79
|
+
if (opts.json) {
|
|
80
|
+
if (!startupConfirmed) {
|
|
81
|
+
console.log(JSON.stringify({
|
|
82
|
+
success: false,
|
|
83
|
+
reason: `Console exited with code ${code}`,
|
|
84
|
+
nextAction: 'Check console logs above. Re-run: npx create-principles-disciple',
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
console.error(`Console exited with code ${code}`);
|
|
89
|
+
}
|
|
90
|
+
process.exit(typeof code === 'number' ? code : 1);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
process.exit(0);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
if (child.exitCode === null) {
|
|
98
|
+
startupConfirmed = true;
|
|
99
|
+
if (opts.json) {
|
|
100
|
+
console.log(JSON.stringify({
|
|
101
|
+
success: true,
|
|
102
|
+
status: 'running',
|
|
103
|
+
url: `http://${host}:${port}`,
|
|
104
|
+
workspace: workspaceDir,
|
|
105
|
+
nextAction: `Open http://${host}:${port} in your browser`,
|
|
106
|
+
}));
|
|
107
|
+
} else {
|
|
108
|
+
console.log(`Starting pd-console on http://${host}:${port}`);
|
|
109
|
+
console.log(`Workspace: ${workspaceDir}`);
|
|
110
|
+
console.log('Press Ctrl+C to stop');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}, 2000);
|
|
114
|
+
|
|
115
|
+
const cleanup = () => {
|
|
116
|
+
try { child.kill('SIGTERM'); } catch { /* ignore */ }
|
|
117
|
+
process.exit(0);
|
|
118
|
+
};
|
|
119
|
+
process.on('SIGINT', cleanup);
|
|
120
|
+
process.on('SIGTERM', cleanup);
|
|
121
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pd context build — Assemble diagnostician context payload for a task.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* pd context build <taskId>
|
|
6
|
+
*/
|
|
7
|
+
import {
|
|
8
|
+
SqliteConnection,
|
|
9
|
+
SqliteTaskStore,
|
|
10
|
+
SqliteRunStore,
|
|
11
|
+
SqliteHistoryQuery,
|
|
12
|
+
SqliteContextAssembler,
|
|
13
|
+
SqliteTrajectoryLocator,
|
|
14
|
+
SqliteSourceTraceLocator,
|
|
15
|
+
} from '@principles/core';
|
|
16
|
+
import { resolveWorkspaceDir } from '../resolve-workspace.js';
|
|
17
|
+
|
|
18
|
+
interface ContextBuildOptions {
|
|
19
|
+
json?: boolean;
|
|
20
|
+
workspace?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function handleContextBuild(taskId: string, opts: ContextBuildOptions): Promise<void> {
|
|
24
|
+
const workspaceDir = resolveWorkspaceDir(opts.workspace);
|
|
25
|
+
const connection = new SqliteConnection(workspaceDir);
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const taskStore = new SqliteTaskStore(connection);
|
|
29
|
+
const runStore = new SqliteRunStore(connection);
|
|
30
|
+
const historyQuery = new SqliteHistoryQuery(connection);
|
|
31
|
+
const trajectoryLocator = new SqliteTrajectoryLocator(connection);
|
|
32
|
+
const sourceTraceLocator = new SqliteSourceTraceLocator(taskStore, trajectoryLocator);
|
|
33
|
+
const assembler = new SqliteContextAssembler(taskStore, historyQuery, runStore, { sourceTraceLocator });
|
|
34
|
+
|
|
35
|
+
const payload = await assembler.assemble(taskId);
|
|
36
|
+
|
|
37
|
+
if (opts.json) {
|
|
38
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log(`\nContext for ${taskId}:\n`);
|
|
43
|
+
console.log(` contextId: ${payload.contextId}`);
|
|
44
|
+
console.log(` contextHash: ${payload.contextHash.substring(0, 16)}...`);
|
|
45
|
+
console.log(` workspaceDir: ${payload.workspaceDir}`);
|
|
46
|
+
console.log(` sourceRefs: ${payload.sourceRefs.join(', ')}`);
|
|
47
|
+
console.log(` entries: ${payload.conversationWindow.length}`);
|
|
48
|
+
|
|
49
|
+
if (payload.ambiguityNotes && payload.ambiguityNotes.length > 0) {
|
|
50
|
+
console.log(` ambiguityNotes:`);
|
|
51
|
+
for (const note of payload.ambiguityNotes) {
|
|
52
|
+
console.log(` - ${note}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const target = payload.diagnosisTarget;
|
|
57
|
+
const targetFields = Object.entries(target).filter(([, v]) => v !== undefined);
|
|
58
|
+
if (targetFields.length > 0) {
|
|
59
|
+
console.log(` diagnosisTarget:`);
|
|
60
|
+
for (const [key, value] of targetFields) {
|
|
61
|
+
console.log(` ${key}: ${value}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
console.log('');
|
|
65
|
+
} catch (error) {
|
|
66
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
67
|
+
console.error(`Error: ${message}`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
} finally {
|
|
70
|
+
connection.close();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as os from 'os';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import { runStoryADemo } from '../services/demo-story-a-runner.js';
|
|
5
|
+
import type { MvpChannel } from '@principles/core/runtime-v2';
|
|
6
|
+
|
|
7
|
+
interface DemoStoryAOptions {
|
|
8
|
+
workspace?: string;
|
|
9
|
+
json?: boolean;
|
|
10
|
+
channels?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function formatStage(stage: { name: string; status: string; reason?: string; evidenceRef?: string }): string {
|
|
14
|
+
const icon = stage.status === 'passed' ? '✓' : stage.status === 'degraded' ? '⚠' : '✗';
|
|
15
|
+
let line = ` ${icon} ${stage.name}: ${stage.status}`;
|
|
16
|
+
if (stage.evidenceRef) line += ` (ref: ${stage.evidenceRef})`;
|
|
17
|
+
if (stage.reason) line += `\n reason: ${stage.reason}`;
|
|
18
|
+
return line;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function formatChannelOutcome(ch: { channel: string; status: string; failureReason?: string; evidenceSource: string }): string {
|
|
22
|
+
const icon = ch.status === 'passed' ? '✓' : ch.status === 'degraded' ? '⚠' : '✗';
|
|
23
|
+
const lines: string[] = [];
|
|
24
|
+
lines.push(` ${icon} ${ch.channel}: ${ch.status}`);
|
|
25
|
+
lines.push(` source: ${ch.evidenceSource}`);
|
|
26
|
+
if (ch.failureReason) {
|
|
27
|
+
lines.push(` reason: ${ch.failureReason}`);
|
|
28
|
+
}
|
|
29
|
+
return lines.join('\n');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function formatTextOutput(result: Record<string, unknown>): string {
|
|
33
|
+
const lines: string[] = [];
|
|
34
|
+
const status = result.status as string;
|
|
35
|
+
const icon = status === 'passed' ? '✓' : status === 'degraded' ? '⚠' : '✗';
|
|
36
|
+
|
|
37
|
+
lines.push('PD Story A\' Demo (PRI-246)');
|
|
38
|
+
lines.push(`generatedAt: ${result.generatedAt as string}`);
|
|
39
|
+
lines.push(`OVERALL: ${icon} ${status.toUpperCase()}`);
|
|
40
|
+
lines.push('');
|
|
41
|
+
|
|
42
|
+
if (result.inputValidationFailure) {
|
|
43
|
+
const ivf = result.inputValidationFailure as Record<string, unknown>;
|
|
44
|
+
lines.push('Input Validation Failure:');
|
|
45
|
+
lines.push(` reason: ${ivf.reason as string}`);
|
|
46
|
+
lines.push(` message: ${ivf.message as string}`);
|
|
47
|
+
lines.push(` nextAction: ${ivf.nextAction as string}`);
|
|
48
|
+
lines.push('');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
lines.push('Stages:');
|
|
52
|
+
for (const stage of result.stages as Record<string, unknown>[]) {
|
|
53
|
+
lines.push(formatStage(stage as { name: string; status: string; reason?: string; evidenceRef?: string }));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
lines.push('');
|
|
57
|
+
lines.push('Channel Outcomes:');
|
|
58
|
+
for (const ch of result.channelOutcomes as Record<string, unknown>[]) {
|
|
59
|
+
lines.push(formatChannelOutcome(ch as { channel: string; status: string; failureReason?: string; evidenceSource: string }));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
lines.push('');
|
|
63
|
+
lines.push(`Runtime V2 Exclusive: ${result.isRuntimeV2Exclusive ? 'Yes' : 'No'}`);
|
|
64
|
+
|
|
65
|
+
lines.push('');
|
|
66
|
+
lines.push('--- Narrative ---');
|
|
67
|
+
lines.push(result.narrative as string);
|
|
68
|
+
|
|
69
|
+
return lines.join('\n');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function cleanupTempWorkspace(workspaceDir: string, rmSyncImpl: (dir: string, opts: { recursive: boolean; force: boolean }) => void = fs.rmSync.bind(fs)): void {
|
|
73
|
+
try {
|
|
74
|
+
rmSyncImpl(workspaceDir, { recursive: true, force: true });
|
|
75
|
+
} catch (cleanupErr) {
|
|
76
|
+
const cleanupMsg = cleanupErr instanceof Error ? cleanupErr.message : String(cleanupErr);
|
|
77
|
+
console.error(`[pd-cli] cleanup warning: failed to remove temp workspace ${workspaceDir}: ${cleanupMsg}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface ParseChannelResult {
|
|
82
|
+
channels: MvpChannel[] | undefined;
|
|
83
|
+
unknowns: string[];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function parseChannelList(raw: string | undefined): ParseChannelResult {
|
|
87
|
+
if (!raw || raw.trim().length === 0) {
|
|
88
|
+
// Empty string means user explicitly passed --channels "" → treat as empty request
|
|
89
|
+
if (raw !== undefined) return { channels: [], unknowns: [] };
|
|
90
|
+
return { channels: undefined, unknowns: [] };
|
|
91
|
+
}
|
|
92
|
+
const parts = raw.split(',').map(p => p.trim()).filter(p => p.length > 0);
|
|
93
|
+
if (parts.length === 0) return { channels: [], unknowns: [] };
|
|
94
|
+
const valid: MvpChannel[] = [];
|
|
95
|
+
const unknowns: string[] = [];
|
|
96
|
+
const mvpSet = new Set<string>(['prompt', 'code_tool_hook', 'defer_archive']);
|
|
97
|
+
for (const part of parts) {
|
|
98
|
+
if (mvpSet.has(part)) {
|
|
99
|
+
valid.push(part as MvpChannel);
|
|
100
|
+
} else {
|
|
101
|
+
unknowns.push(part);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return { channels: valid.length > 0 ? valid : undefined, unknowns };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export async function handleDemoStoryA(opts: DemoStoryAOptions): Promise<void> {
|
|
108
|
+
const workspaceDir = opts.workspace
|
|
109
|
+
? path.resolve(opts.workspace)
|
|
110
|
+
: fs.mkdtempSync(path.join(os.tmpdir(), 'pd-story-a-'));
|
|
111
|
+
|
|
112
|
+
const parsed = parseChannelList(opts.channels);
|
|
113
|
+
|
|
114
|
+
// Fail loud on empty channels before workspace creation (ERR-029)
|
|
115
|
+
if (parsed.channels?.length === 0) {
|
|
116
|
+
const errorResult = {
|
|
117
|
+
status: 'failed' as const,
|
|
118
|
+
generatedAt: new Date().toISOString(),
|
|
119
|
+
narrative: 'No channels specified.',
|
|
120
|
+
storyDescription: 'Input validation failed',
|
|
121
|
+
stages: [],
|
|
122
|
+
channelOutcomes: [],
|
|
123
|
+
isRuntimeV2Exclusive: true,
|
|
124
|
+
inputValidationFailure: {
|
|
125
|
+
reason: 'empty_channels',
|
|
126
|
+
message: 'No channels specified. At least one MVP channel required.',
|
|
127
|
+
nextAction: 'Provide channels: prompt, code_tool_hook, defer_archive',
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
if (opts.json) {
|
|
131
|
+
console.log(JSON.stringify(errorResult, null, 2));
|
|
132
|
+
} else {
|
|
133
|
+
console.error('Error: No channels specified. At least one MVP channel required.');
|
|
134
|
+
console.error('Valid channels: prompt, code_tool_hook, defer_archive');
|
|
135
|
+
}
|
|
136
|
+
process.exitCode = 1;
|
|
137
|
+
if (!opts.workspace) {
|
|
138
|
+
cleanupTempWorkspace(workspaceDir);
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Fail loud on unknown channels (ERR-029)
|
|
144
|
+
if (parsed.unknowns.length > 0) {
|
|
145
|
+
const errorResult = {
|
|
146
|
+
status: 'failed' as const,
|
|
147
|
+
generatedAt: new Date().toISOString(),
|
|
148
|
+
narrative: `Unknown channels: ${parsed.unknowns.join(', ')}`,
|
|
149
|
+
storyDescription: 'Input validation failed',
|
|
150
|
+
stages: [],
|
|
151
|
+
channelOutcomes: [],
|
|
152
|
+
isRuntimeV2Exclusive: true,
|
|
153
|
+
inputValidationFailure: {
|
|
154
|
+
reason: 'unknown_channels',
|
|
155
|
+
message: `Unknown channels: ${parsed.unknowns.join(', ')}. Valid: prompt, code_tool_hook, defer_archive`,
|
|
156
|
+
nextAction: 'Use only valid MVP channels: prompt, code_tool_hook, defer_archive',
|
|
157
|
+
unknownChannels: parsed.unknowns,
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
if (opts.json) {
|
|
161
|
+
console.log(JSON.stringify(errorResult, null, 2));
|
|
162
|
+
} else {
|
|
163
|
+
console.error(`Error: Unknown channels: ${parsed.unknowns.join(', ')}`);
|
|
164
|
+
console.error('Valid channels: prompt, code_tool_hook, defer_archive');
|
|
165
|
+
}
|
|
166
|
+
process.exitCode = 1;
|
|
167
|
+
if (!opts.workspace) {
|
|
168
|
+
cleanupTempWorkspace(workspaceDir);
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
const result = await runStoryADemo({
|
|
175
|
+
channels: parsed.channels,
|
|
176
|
+
workspaceDir,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
if (opts.json) {
|
|
180
|
+
console.log(JSON.stringify(result, null, 2));
|
|
181
|
+
} else {
|
|
182
|
+
console.log(formatTextOutput(result as unknown as Record<string, unknown>));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (result.status !== 'passed') {
|
|
186
|
+
console.error('');
|
|
187
|
+
console.error(`FAIL: status=${result.status}`);
|
|
188
|
+
process.exitCode = 1;
|
|
189
|
+
}
|
|
190
|
+
} finally {
|
|
191
|
+
if (!opts.workspace) {
|
|
192
|
+
cleanupTempWorkspace(workspaceDir);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|