create-principles-disciple 1.79.0 → 1.81.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/console/package.json +1 -0
- package/core/dist/runtime-v2/__tests__/admission-gate.test.js +6 -6
- package/core/dist/runtime-v2/__tests__/admission-gate.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +39 -0
- package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/artificer-runner-vslice.test.js +52 -0
- package/core/dist/runtime-v2/__tests__/artificer-runner-vslice.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/evaluator-runner-vslice.test.js +245 -1
- package/core/dist/runtime-v2/__tests__/evaluator-runner-vslice.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/feedback/redact-sensitive.test.js +131 -1
- package/core/dist/runtime-v2/__tests__/feedback/redact-sensitive.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/fixtures/llm-e2e-config.d.ts.map +1 -1
- package/core/dist/runtime-v2/__tests__/fixtures/llm-e2e-config.js +4 -2
- package/core/dist/runtime-v2/__tests__/fixtures/llm-e2e-config.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/scribe-runner-vslice.test.js +425 -2
- package/core/dist/runtime-v2/__tests__/scribe-runner-vslice.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/telemetry-event.test.d.ts +2 -0
- package/core/dist/runtime-v2/__tests__/telemetry-event.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/__tests__/telemetry-event.test.js +69 -0
- package/core/dist/runtime-v2/__tests__/telemetry-event.test.js.map +1 -0
- package/core/dist/runtime-v2/admission-gate.d.ts.map +1 -1
- package/core/dist/runtime-v2/admission-gate.js +0 -8
- package/core/dist/runtime-v2/admission-gate.js.map +1 -1
- package/core/dist/runtime-v2/config/__tests__/pd-config-contract.test.d.ts +15 -0
- package/core/dist/runtime-v2/config/__tests__/pd-config-contract.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/config/__tests__/pd-config-contract.test.js +685 -0
- package/core/dist/runtime-v2/config/__tests__/pd-config-contract.test.js.map +1 -0
- package/core/dist/runtime-v2/config/index.d.ts +14 -0
- package/core/dist/runtime-v2/config/index.d.ts.map +1 -0
- package/core/dist/runtime-v2/config/index.js +16 -0
- package/core/dist/runtime-v2/config/index.js.map +1 -0
- package/core/dist/runtime-v2/config/pd-config-defaults.d.ts +14 -0
- package/core/dist/runtime-v2/config/pd-config-defaults.d.ts.map +1 -0
- package/core/dist/runtime-v2/config/pd-config-defaults.js +74 -0
- package/core/dist/runtime-v2/config/pd-config-defaults.js.map +1 -0
- package/core/dist/runtime-v2/config/pd-config-effective.d.ts +14 -0
- package/core/dist/runtime-v2/config/pd-config-effective.d.ts.map +1 -0
- package/core/dist/runtime-v2/config/pd-config-effective.js +118 -0
- package/core/dist/runtime-v2/config/pd-config-effective.js.map +1 -0
- package/core/dist/runtime-v2/config/pd-config-feature-flags.d.ts +35 -0
- package/core/dist/runtime-v2/config/pd-config-feature-flags.d.ts.map +1 -0
- package/core/dist/runtime-v2/config/pd-config-feature-flags.js +99 -0
- package/core/dist/runtime-v2/config/pd-config-feature-flags.js.map +1 -0
- package/core/dist/runtime-v2/config/pd-config-redaction.d.ts +22 -0
- package/core/dist/runtime-v2/config/pd-config-redaction.d.ts.map +1 -0
- package/core/dist/runtime-v2/config/pd-config-redaction.js +179 -0
- package/core/dist/runtime-v2/config/pd-config-redaction.js.map +1 -0
- package/core/dist/runtime-v2/config/pd-config-types.d.ts +124 -0
- package/core/dist/runtime-v2/config/pd-config-types.d.ts.map +1 -0
- package/core/dist/runtime-v2/config/pd-config-types.js +35 -0
- package/core/dist/runtime-v2/config/pd-config-types.js.map +1 -0
- package/core/dist/runtime-v2/config/pd-config-validate.d.ts +16 -0
- package/core/dist/runtime-v2/config/pd-config-validate.d.ts.map +1 -0
- package/core/dist/runtime-v2/config/pd-config-validate.js +443 -0
- package/core/dist/runtime-v2/config/pd-config-validate.js.map +1 -0
- package/core/dist/runtime-v2/feature-flags/plugin-surface-registry.js +10 -10
- package/core/dist/runtime-v2/feature-flags/plugin-surface-registry.js.map +1 -1
- package/core/dist/runtime-v2/feedback/index.d.ts +1 -1
- package/core/dist/runtime-v2/feedback/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/feedback/index.js +1 -1
- package/core/dist/runtime-v2/feedback/index.js.map +1 -1
- package/core/dist/runtime-v2/feedback/redact-sensitive.d.ts +2 -0
- package/core/dist/runtime-v2/feedback/redact-sensitive.d.ts.map +1 -1
- package/core/dist/runtime-v2/feedback/redact-sensitive.js +32 -3
- package/core/dist/runtime-v2/feedback/redact-sensitive.js.map +1 -1
- package/core/dist/runtime-v2/index.d.ts +5 -1
- package/core/dist/runtime-v2/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/index.js +9 -1
- package/core/dist/runtime-v2/index.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/peer-runner-lineage-injection.test.d.ts +2 -0
- package/core/dist/runtime-v2/internalization/__tests__/peer-runner-lineage-injection.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/peer-runner-lineage-injection.test.js +95 -0
- package/core/dist/runtime-v2/internalization/__tests__/peer-runner-lineage-injection.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/philosopher-runner-trust-boundary.test.d.ts +2 -0
- package/core/dist/runtime-v2/internalization/__tests__/philosopher-runner-trust-boundary.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/__tests__/philosopher-runner-trust-boundary.test.js +398 -0
- package/core/dist/runtime-v2/internalization/__tests__/philosopher-runner-trust-boundary.test.js.map +1 -0
- package/core/dist/runtime-v2/internalization/artificer-output.d.ts +3 -2
- package/core/dist/runtime-v2/internalization/artificer-output.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/artificer-output.js +40 -31
- package/core/dist/runtime-v2/internalization/artificer-output.js.map +1 -1
- package/core/dist/runtime-v2/internalization/artificer-runner.d.ts +59 -38
- package/core/dist/runtime-v2/internalization/artificer-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/artificer-runner.js +122 -394
- package/core/dist/runtime-v2/internalization/artificer-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/dreamer-output.d.ts +4 -3
- package/core/dist/runtime-v2/internalization/dreamer-output.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/dreamer-output.js +11 -9
- package/core/dist/runtime-v2/internalization/dreamer-output.js.map +1 -1
- package/core/dist/runtime-v2/internalization/dreamer-runner.d.ts +31 -92
- package/core/dist/runtime-v2/internalization/dreamer-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/dreamer-runner.js +80 -492
- package/core/dist/runtime-v2/internalization/dreamer-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/evaluator-output.d.ts +2 -2
- package/core/dist/runtime-v2/internalization/evaluator-output.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/evaluator-output.js +29 -23
- package/core/dist/runtime-v2/internalization/evaluator-output.js.map +1 -1
- package/core/dist/runtime-v2/internalization/evaluator-runner.d.ts +74 -48
- package/core/dist/runtime-v2/internalization/evaluator-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/evaluator-runner.js +165 -443
- package/core/dist/runtime-v2/internalization/evaluator-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/peer-runner-contracts.d.ts +14 -0
- package/core/dist/runtime-v2/internalization/peer-runner-contracts.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/peer-runner-contracts.js +21 -0
- package/core/dist/runtime-v2/internalization/peer-runner-contracts.js.map +1 -1
- package/core/dist/runtime-v2/internalization/philosopher-output.d.ts +8 -2
- package/core/dist/runtime-v2/internalization/philosopher-output.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/philosopher-output.js +16 -11
- package/core/dist/runtime-v2/internalization/philosopher-output.js.map +1 -1
- package/core/dist/runtime-v2/internalization/philosopher-runner.d.ts +36 -55
- package/core/dist/runtime-v2/internalization/philosopher-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/philosopher-runner.js +118 -400
- package/core/dist/runtime-v2/internalization/philosopher-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/rollout-reviewer-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/rollout-reviewer-runner.js +3 -1
- package/core/dist/runtime-v2/internalization/rollout-reviewer-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/scribe-output.d.ts +8 -2
- package/core/dist/runtime-v2/internalization/scribe-output.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/scribe-output.js +33 -17
- package/core/dist/runtime-v2/internalization/scribe-output.js.map +1 -1
- package/core/dist/runtime-v2/internalization/scribe-runner.d.ts +56 -49
- package/core/dist/runtime-v2/internalization/scribe-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/scribe-runner.js +117 -397
- package/core/dist/runtime-v2/internalization/scribe-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/trainer-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/trainer-runner.js +3 -1
- package/core/dist/runtime-v2/internalization/trainer-runner.js.map +1 -1
- package/core/dist/runtime-v2/runner/__tests__/base-peer-runner-trust-boundary.test.d.ts +2 -0
- package/core/dist/runtime-v2/runner/__tests__/base-peer-runner-trust-boundary.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/runner/__tests__/base-peer-runner-trust-boundary.test.js +379 -0
- package/core/dist/runtime-v2/runner/__tests__/base-peer-runner-trust-boundary.test.js.map +1 -0
- package/core/dist/runtime-v2/runner/base-peer-runner.d.ts +122 -0
- package/core/dist/runtime-v2/runner/base-peer-runner.d.ts.map +1 -0
- package/core/dist/runtime-v2/runner/base-peer-runner.js +528 -0
- package/core/dist/runtime-v2/runner/base-peer-runner.js.map +1 -0
- package/core/dist/runtime-v2/runner/peer-runner-types.d.ts +107 -0
- package/core/dist/runtime-v2/runner/peer-runner-types.d.ts.map +1 -0
- package/core/dist/runtime-v2/runner/peer-runner-types.js +13 -0
- package/core/dist/runtime-v2/runner/peer-runner-types.js.map +1 -0
- package/core/dist/telemetry-event.d.ts +2 -2
- package/core/dist/telemetry-event.d.ts.map +1 -1
- package/core/dist/telemetry-event.js +89 -0
- package/core/dist/telemetry-event.js.map +1 -1
- package/dist/installer.d.ts +1 -1
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +39 -10
- package/dist/installer.js.map +1 -1
- package/dist/mvp-config.d.ts +33 -0
- package/dist/mvp-config.d.ts.map +1 -1
- package/dist/mvp-config.js +174 -0
- package/dist/mvp-config.js.map +1 -1
- package/package.json +3 -3
- package/pd-cli/dist/commands/config-doctor.d.ts +17 -0
- package/pd-cli/dist/commands/config-doctor.d.ts.map +1 -0
- package/pd-cli/dist/commands/config-doctor.js +143 -0
- package/pd-cli/dist/commands/config-doctor.js.map +1 -0
- package/pd-cli/dist/commands/console.d.ts +18 -0
- package/pd-cli/dist/commands/console.d.ts.map +1 -1
- package/pd-cli/dist/commands/console.js +439 -0
- package/pd-cli/dist/commands/console.js.map +1 -1
- package/pd-cli/dist/commands/runtime-features.d.ts +23 -8
- package/pd-cli/dist/commands/runtime-features.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-features.js +72 -31
- package/pd-cli/dist/commands/runtime-features.js.map +1 -1
- package/pd-cli/dist/index.d.ts +1 -1
- package/pd-cli/dist/index.js +83 -31
- package/pd-cli/dist/index.js.map +1 -1
- package/pd-cli/dist/services/config-doctor.d.ts +102 -0
- package/pd-cli/dist/services/config-doctor.d.ts.map +1 -0
- package/pd-cli/dist/services/config-doctor.js +426 -0
- package/pd-cli/dist/services/config-doctor.js.map +1 -0
- package/pd-cli/dist/services/console-launcher.d.ts +110 -0
- package/pd-cli/dist/services/console-launcher.d.ts.map +1 -0
- package/pd-cli/dist/services/console-launcher.js +282 -0
- package/pd-cli/dist/services/console-launcher.js.map +1 -0
- package/pd-cli/dist/services/pd-config-loader.d.ts +64 -0
- package/pd-cli/dist/services/pd-config-loader.d.ts.map +1 -0
- package/pd-cli/dist/services/pd-config-loader.js +156 -0
- package/pd-cli/dist/services/pd-config-loader.js.map +1 -0
- package/pd-cli/package.json +3 -1
- package/plugin/dist/core/event-log.d.ts +10 -0
- package/plugin/dist/core/event-log.js +85 -1
- package/plugin/dist/core/pd-config-loader.d.ts +96 -0
- package/plugin/dist/core/pd-config-loader.js +307 -0
- package/plugin/dist/core/runtime-v2-prompt-activation-reader.d.ts +4 -0
- package/plugin/dist/core/runtime-v2-prompt-activation-reader.js +12 -56
- package/plugin/dist/core/surface-guard.d.ts +12 -8
- package/plugin/dist/core/surface-guard.js +51 -2
- package/plugin/dist/hooks/gate.js +3 -0
- package/plugin/dist/hooks/prompt.js +4 -5
- package/plugin/dist/index.d.ts +4 -0
- package/plugin/dist/index.js +70 -94
- package/plugin/dist/service/correction-observer-service.d.ts +8 -0
- package/plugin/dist/service/correction-observer-service.js +48 -29
- package/plugin/dist/utils/workspace-resolver.d.ts +33 -1
- package/plugin/dist/utils/workspace-resolver.js +182 -3
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PD Config Loader — PRI-305
|
|
3
|
+
*
|
|
4
|
+
* I/O boundary: reads `.pd/config.yaml`, validates via core, computes effective config.
|
|
5
|
+
* This replaces the old `feature-flag-loader.ts` and `workflows.yaml` reading
|
|
6
|
+
* for CLI production paths.
|
|
7
|
+
*
|
|
8
|
+
* ADR-0016: PD owns exactly one user config file.
|
|
9
|
+
* - Missing config → defaults with nextAction
|
|
10
|
+
* - Malformed config → fail loud with errors and nextAction
|
|
11
|
+
* - No secrets in output
|
|
12
|
+
*/
|
|
13
|
+
import * as fs from 'fs';
|
|
14
|
+
import * as path from 'path';
|
|
15
|
+
import yaml from 'js-yaml';
|
|
16
|
+
import { validatePdConfig, computeEffectivePdConfig, computeFeatureFlagsFromConfig, redactPdConfig, } from '@principles/core/runtime-v2';
|
|
17
|
+
// ── Constants ────────────────────────────────────────────────────────────────
|
|
18
|
+
export const PD_CONFIG_DIR = '.pd';
|
|
19
|
+
export const PD_CONFIG_FILENAME = 'config.yaml';
|
|
20
|
+
// ── Config Path ──────────────────────────────────────────────────────────────
|
|
21
|
+
export function getPdConfigPath(workspaceDir) {
|
|
22
|
+
return path.join(workspaceDir, PD_CONFIG_DIR, PD_CONFIG_FILENAME);
|
|
23
|
+
}
|
|
24
|
+
// ── Legacy File Detection ────────────────────────────────────────────────────
|
|
25
|
+
function detectLegacyFiles(workspaceDir) {
|
|
26
|
+
const detected = [];
|
|
27
|
+
const legacyPaths = [
|
|
28
|
+
path.join(workspaceDir, PD_CONFIG_DIR, 'feature-flags.yaml'),
|
|
29
|
+
path.join(workspaceDir, '.state', 'workflows.yaml'),
|
|
30
|
+
];
|
|
31
|
+
for (const p of legacyPaths) {
|
|
32
|
+
if (fs.existsSync(p)) {
|
|
33
|
+
detected.push(p);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return detected;
|
|
37
|
+
}
|
|
38
|
+
// ── Load PD Config ───────────────────────────────────────────────────────────
|
|
39
|
+
/**
|
|
40
|
+
* Load and validate `.pd/config.yaml` from the workspace.
|
|
41
|
+
*
|
|
42
|
+
* - Missing file → returns defaults with source='defaults'
|
|
43
|
+
* - Malformed file → returns error result with defaults fallback
|
|
44
|
+
* - Valid file → returns effective config with source='user_config'
|
|
45
|
+
*
|
|
46
|
+
* Never throws on malformed input. Always provides a usable fallback.
|
|
47
|
+
*/
|
|
48
|
+
export function loadPdConfig(workspaceDir) {
|
|
49
|
+
const configPath = getPdConfigPath(workspaceDir);
|
|
50
|
+
const legacyFilesDetected = detectLegacyFiles(workspaceDir);
|
|
51
|
+
// 1) Config file missing → use defaults
|
|
52
|
+
if (!fs.existsSync(configPath)) {
|
|
53
|
+
const effective = computeEffectivePdConfig(null);
|
|
54
|
+
return {
|
|
55
|
+
ok: true,
|
|
56
|
+
effective,
|
|
57
|
+
source: 'defaults',
|
|
58
|
+
configPath,
|
|
59
|
+
warnings: [
|
|
60
|
+
...effective.warnings,
|
|
61
|
+
...(legacyFilesDetected.length > 0
|
|
62
|
+
? [`Legacy config files detected (${legacyFilesDetected.length}): ${legacyFilesDetected.join(', ')}. PD now uses .pd/config.yaml.`]
|
|
63
|
+
: []),
|
|
64
|
+
],
|
|
65
|
+
legacyFilesDetected,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// 2) Read the file
|
|
69
|
+
let raw;
|
|
70
|
+
try {
|
|
71
|
+
raw = fs.readFileSync(configPath, 'utf8');
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
75
|
+
const effective = computeEffectivePdConfig(null);
|
|
76
|
+
return {
|
|
77
|
+
ok: false,
|
|
78
|
+
source: 'malformed',
|
|
79
|
+
configPath,
|
|
80
|
+
errors: [{ path: '', reason: `Failed to read .pd/config.yaml: ${message}`, nextAction: 'Check file permissions for .pd/config.yaml' }],
|
|
81
|
+
warnings: [],
|
|
82
|
+
defaults: effective,
|
|
83
|
+
legacyFilesDetected,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// 3) Parse YAML — treat as unknown (ERR-001)
|
|
87
|
+
let parsed;
|
|
88
|
+
try {
|
|
89
|
+
parsed = yaml.load(raw, { schema: yaml.JSON_SCHEMA });
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
93
|
+
const effective = computeEffectivePdConfig(null);
|
|
94
|
+
return {
|
|
95
|
+
ok: false,
|
|
96
|
+
source: 'malformed',
|
|
97
|
+
configPath,
|
|
98
|
+
errors: [{ path: '', reason: `YAML parse error in .pd/config.yaml: ${message}`, nextAction: 'Fix YAML syntax in .pd/config.yaml' }],
|
|
99
|
+
warnings: [],
|
|
100
|
+
defaults: effective,
|
|
101
|
+
legacyFilesDetected,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
// 4) Validate via core (ERR-001, ERR-005: no `as` bypasses)
|
|
105
|
+
const validationResult = validatePdConfig(parsed);
|
|
106
|
+
if (!validationResult.ok) {
|
|
107
|
+
const effective = computeEffectivePdConfig(null);
|
|
108
|
+
return {
|
|
109
|
+
ok: false,
|
|
110
|
+
source: 'malformed',
|
|
111
|
+
configPath,
|
|
112
|
+
errors: validationResult.errors.map(e => ({
|
|
113
|
+
path: e.path,
|
|
114
|
+
reason: e.reason,
|
|
115
|
+
nextAction: e.nextAction,
|
|
116
|
+
})),
|
|
117
|
+
warnings: [],
|
|
118
|
+
defaults: effective,
|
|
119
|
+
legacyFilesDetected,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
// 5) Compute effective config
|
|
123
|
+
const effective = computeEffectivePdConfig(validationResult.value);
|
|
124
|
+
return {
|
|
125
|
+
ok: true,
|
|
126
|
+
effective,
|
|
127
|
+
source: 'user_config',
|
|
128
|
+
configPath,
|
|
129
|
+
warnings: [
|
|
130
|
+
...effective.warnings,
|
|
131
|
+
...(legacyFilesDetected.length > 0
|
|
132
|
+
? [`Legacy config files detected (${legacyFilesDetected.length}): ${legacyFilesDetected.join(', ')}. PD now uses .pd/config.yaml.`]
|
|
133
|
+
: []),
|
|
134
|
+
],
|
|
135
|
+
legacyFilesDetected,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
// ── Feature Flags from Config ────────────────────────────────────────────────
|
|
139
|
+
/**
|
|
140
|
+
* Compute feature flags from the loaded PD config.
|
|
141
|
+
* Works with both ok and error results (uses defaults for errors).
|
|
142
|
+
*/
|
|
143
|
+
export function computeFlagsFromLoadResult(result) {
|
|
144
|
+
const effective = result.ok ? result.effective : result.defaults;
|
|
145
|
+
return computeFeatureFlagsFromConfig(effective);
|
|
146
|
+
}
|
|
147
|
+
// ── Redacted Summary from Config ─────────────────────────────────────────────
|
|
148
|
+
/**
|
|
149
|
+
* Produce a redacted summary of the PD config for CLI/Console display.
|
|
150
|
+
* Never includes token/API key values or raw provider objects.
|
|
151
|
+
*/
|
|
152
|
+
export function redactLoadResult(result) {
|
|
153
|
+
const effective = result.ok ? result.effective : result.defaults;
|
|
154
|
+
return redactPdConfig(effective);
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=pd-config-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pd-config-loader.js","sourceRoot":"","sources":["../../src/services/pd-config-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,6BAA6B,EAC7B,cAAc,GACf,MAAM,6BAA6B,CAAC;AAQrC,gFAAgF;AAEhF,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC;AACnC,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAC;AA+BhD,gFAAgF;AAEhF,MAAM,UAAU,eAAe,CAAC,YAAoB;IAClD,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,aAAa,EAAE,kBAAkB,CAAC,CAAC;AACpE,CAAC;AAED,gFAAgF;AAEhF,SAAS,iBAAiB,CAAC,YAAoB;IAC7C,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,WAAW,GAAG;QAClB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,aAAa,EAAE,oBAAoB,CAAC;QAC5D,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,EAAE,gBAAgB,CAAC;KACpD,CAAC;IACF,KAAK,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC;QAC5B,IAAI,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;YACrB,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC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|
-
"js-yaml": "^4.1.1"
|
|
18
|
+
"js-yaml": "^4.1.1",
|
|
19
|
+
"better-sqlite3": "^12.9.0"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
22
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
21
23
|
"@types/js-yaml": "^4.0.9",
|
|
22
24
|
"@types/node": "^25.6.2",
|
|
23
25
|
"typescript": "^6.0.3",
|
|
@@ -43,6 +43,16 @@ export declare class EventLog {
|
|
|
43
43
|
recordRuleHostAutoCorrectProposed(data: RuleHostAutoCorrectProposedEventData): void;
|
|
44
44
|
recordRuleHostAutoCorrectApplied(data: RuleHostAutoCorrectAppliedEventData): void;
|
|
45
45
|
recordRuntimeV2ActivationsInjected(data: RuntimeV2PromptActivationsInjectedEventData): void;
|
|
46
|
+
/**
|
|
47
|
+
* Redact telemetry-sensitive string values in event data before persistence.
|
|
48
|
+
* Applies redactTelemetryString to known high-risk fields (filePath, command,
|
|
49
|
+
* reason, args, new_string, old_string, text, paramsSummary values) and to all
|
|
50
|
+
* string values in tool_call/rulehost_* data as a safety net.
|
|
51
|
+
*
|
|
52
|
+
* ERR-002: never throws; returns data unchanged on error.
|
|
53
|
+
* ERR-045/046: covers composite command strings, Authorization headers, env vars.
|
|
54
|
+
*/
|
|
55
|
+
private redactEventData;
|
|
46
56
|
private record;
|
|
47
57
|
private formatDate;
|
|
48
58
|
private loadStats;
|
|
@@ -2,6 +2,7 @@ import * as fs from 'fs';
|
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import { createEmptyDailyStats } from '../types/event-types.js';
|
|
4
4
|
import { atomicWriteFileSync } from '../utils/io.js';
|
|
5
|
+
import { redactTelemetryString } from '@principles/core/runtime-v2';
|
|
5
6
|
const EVENT_LOG_RETENTION_DAYS = 7;
|
|
6
7
|
export class EventLog {
|
|
7
8
|
logsDir;
|
|
@@ -142,16 +143,99 @@ export class EventLog {
|
|
|
142
143
|
recordRuntimeV2ActivationsInjected(data) {
|
|
143
144
|
this.record('runtime_v2_prompt_activations_injected', 'injected', data.sessionId, data);
|
|
144
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Redact telemetry-sensitive string values in event data before persistence.
|
|
148
|
+
* Applies redactTelemetryString to known high-risk fields (filePath, command,
|
|
149
|
+
* reason, args, new_string, old_string, text, paramsSummary values) and to all
|
|
150
|
+
* string values in tool_call/rulehost_* data as a safety net.
|
|
151
|
+
*
|
|
152
|
+
* ERR-002: never throws; returns data unchanged on error.
|
|
153
|
+
* ERR-045/046: covers composite command strings, Authorization headers, env vars.
|
|
154
|
+
*/
|
|
155
|
+
redactEventData(type, data) {
|
|
156
|
+
try {
|
|
157
|
+
// Known high-risk event types — telemetry that carries tool commands / paths
|
|
158
|
+
const telemetryTypes = new Set([
|
|
159
|
+
'tool_call',
|
|
160
|
+
'rulehost_evaluated',
|
|
161
|
+
'rulehost_blocked',
|
|
162
|
+
'rulehost_requireApproval',
|
|
163
|
+
'rulehost_auto_correct_proposed',
|
|
164
|
+
'rulehost_auto_correct_applied',
|
|
165
|
+
'rule_enforced',
|
|
166
|
+
'hook_execution',
|
|
167
|
+
'gate_block',
|
|
168
|
+
'gate_bypass',
|
|
169
|
+
]);
|
|
170
|
+
if (!telemetryTypes.has(type))
|
|
171
|
+
return data;
|
|
172
|
+
const redacted = {};
|
|
173
|
+
for (const [key, value] of Object.entries(data)) {
|
|
174
|
+
if (typeof value === 'string') {
|
|
175
|
+
redacted[key] = redactTelemetryString(value);
|
|
176
|
+
}
|
|
177
|
+
else if (Array.isArray(value)) {
|
|
178
|
+
// Recurse into arrays (e.g. correctedFields with original/applied)
|
|
179
|
+
redacted[key] = value.map((item) => {
|
|
180
|
+
if (typeof item === 'string') {
|
|
181
|
+
return redactTelemetryString(item);
|
|
182
|
+
}
|
|
183
|
+
if (typeof item === 'object' && item !== null) {
|
|
184
|
+
const nested = {};
|
|
185
|
+
for (const [nk, nv] of Object.entries(item)) {
|
|
186
|
+
nested[nk] = typeof nv === 'string' ? redactTelemetryString(nv) : nv;
|
|
187
|
+
}
|
|
188
|
+
return nested;
|
|
189
|
+
}
|
|
190
|
+
return item;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
else if (typeof value === 'object' && value !== null) {
|
|
194
|
+
// Recurse one level for nested objects (e.g. paramsSummary)
|
|
195
|
+
const nested = {};
|
|
196
|
+
for (const [nk, nv] of Object.entries(value)) {
|
|
197
|
+
if (typeof nv === 'string') {
|
|
198
|
+
nested[nk] = redactTelemetryString(nv);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
nested[nk] = nv;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
redacted[key] = nested;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
redacted[key] = value;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return redacted;
|
|
211
|
+
}
|
|
212
|
+
catch (e) {
|
|
213
|
+
// ERR-002: fail safe — never write raw payload on redaction failure.
|
|
214
|
+
// Return a masked payload with context so downstream knows what happened.
|
|
215
|
+
const errStr = e instanceof Error ? e.message.slice(0, 200) : String(e).slice(0, 200);
|
|
216
|
+
const masked = {
|
|
217
|
+
redactionFailure: true,
|
|
218
|
+
redactionStatus: 'failed',
|
|
219
|
+
'redaction.status': 'failed',
|
|
220
|
+
redactionReason: errStr || 'unknown error',
|
|
221
|
+
redactionDataDropped: true,
|
|
222
|
+
originalType: type,
|
|
223
|
+
originalSessionId: data.sessionId ?? null,
|
|
224
|
+
};
|
|
225
|
+
return masked;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
145
228
|
record(type, category, sessionId, data) {
|
|
146
229
|
const now = new Date();
|
|
147
230
|
const date = this.formatDate(now);
|
|
231
|
+
const redactedData = this.redactEventData(type, data);
|
|
148
232
|
const entry = {
|
|
149
233
|
ts: now.toISOString(),
|
|
150
234
|
date,
|
|
151
235
|
type,
|
|
152
236
|
category,
|
|
153
237
|
sessionId,
|
|
154
|
-
data:
|
|
238
|
+
data: redactedData,
|
|
155
239
|
};
|
|
156
240
|
this.eventBuffer.push(entry);
|
|
157
241
|
this.updateStats(entry);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PD Config Loader (Plugin I/O boundary) — PRI-307
|
|
3
|
+
*
|
|
4
|
+
* Reads `.pd/config.yaml`, validates via core, computes effective config.
|
|
5
|
+
* Replaces the old `.pd/feature-flags.yaml` and `.state/workflows.yaml` reading
|
|
6
|
+
* for plugin production paths.
|
|
7
|
+
*
|
|
8
|
+
* ADR-0016: PD owns exactly one user config file.
|
|
9
|
+
* - Missing config → defaults with nextAction
|
|
10
|
+
* - Malformed config → fail loud with errors and nextAction
|
|
11
|
+
* - No secrets in output
|
|
12
|
+
* - Observer disabled → no start / no noisy log cycling
|
|
13
|
+
* - Observer enabled + missing setup → structured needs_setup + nextAction
|
|
14
|
+
*/
|
|
15
|
+
import type { EffectivePdConfig } from '@principles/core/runtime-v2';
|
|
16
|
+
export declare const PD_CONFIG_DIR = ".pd";
|
|
17
|
+
export declare const PD_CONFIG_FILENAME = "config.yaml";
|
|
18
|
+
export type ObserverReadiness = 'disabled' | 'needs_setup' | 'ready' | 'not_ready' | 'config_malformed';
|
|
19
|
+
export interface ObserverConfigResult {
|
|
20
|
+
/** Whether the observer feature is enabled in config */
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
/** Observer readiness state */
|
|
23
|
+
readiness: ObserverReadiness;
|
|
24
|
+
/** Config source: 'defaults' | 'user_config' | 'malformed' */
|
|
25
|
+
source: string;
|
|
26
|
+
/** Reason for current state */
|
|
27
|
+
reason: string;
|
|
28
|
+
/** What the user should do next */
|
|
29
|
+
nextAction: string;
|
|
30
|
+
/** The runtime profile ID for this observer, if configured */
|
|
31
|
+
runtimeProfileId: string | null;
|
|
32
|
+
/** The runtime profile type, if configured */
|
|
33
|
+
runtimeProfileType: string | null;
|
|
34
|
+
/** The apiKeyEnv for the runtime profile, if applicable */
|
|
35
|
+
apiKeyEnv: string | null;
|
|
36
|
+
/** Whether the apiKeyEnv is present in process.env */
|
|
37
|
+
apiKeyPresent: boolean;
|
|
38
|
+
/** Provider name from runtime profile */
|
|
39
|
+
provider: string | null;
|
|
40
|
+
/** Model name from runtime profile */
|
|
41
|
+
model: string | null;
|
|
42
|
+
/** Timeout from runtime profile */
|
|
43
|
+
timeoutMs: number | null;
|
|
44
|
+
/** Base URL from runtime profile */
|
|
45
|
+
baseUrl: string | null;
|
|
46
|
+
/** Config validation errors (only present when readiness=config_malformed) */
|
|
47
|
+
configErrors?: Array<{
|
|
48
|
+
path: string;
|
|
49
|
+
reason: string;
|
|
50
|
+
nextAction: string;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
export interface PluginConfigLoadResult {
|
|
54
|
+
ok: boolean;
|
|
55
|
+
effective: EffectivePdConfig;
|
|
56
|
+
source: 'defaults' | 'user_config' | 'malformed';
|
|
57
|
+
configPath: string;
|
|
58
|
+
warnings: string[];
|
|
59
|
+
errors: Array<{
|
|
60
|
+
path: string;
|
|
61
|
+
reason: string;
|
|
62
|
+
nextAction: string;
|
|
63
|
+
}>;
|
|
64
|
+
}
|
|
65
|
+
export declare function getPdConfigPath(workspaceDir: string): string;
|
|
66
|
+
/**
|
|
67
|
+
* Load and validate `.pd/config.yaml` from the workspace.
|
|
68
|
+
* Never throws on malformed input. Always provides a usable fallback.
|
|
69
|
+
*/
|
|
70
|
+
export declare function loadPdConfigForPlugin(workspaceDir: string): PluginConfigLoadResult;
|
|
71
|
+
/**
|
|
72
|
+
* Get a single feature flag's enabled state from .pd/config.yaml.
|
|
73
|
+
* Replaces the old `loadFeatureFlagFromWorkspace` which read .pd/feature-flags.yaml.
|
|
74
|
+
*/
|
|
75
|
+
export declare function loadFeatureFlagFromConfig(workspaceDir: string, flagId: string, logger?: {
|
|
76
|
+
warn?: (msg: string) => void;
|
|
77
|
+
info?: (msg: string) => void;
|
|
78
|
+
}): {
|
|
79
|
+
enabled: boolean;
|
|
80
|
+
source: string;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Resolve observer configuration from .pd/config.yaml.
|
|
84
|
+
*
|
|
85
|
+
* Returns structured state:
|
|
86
|
+
* - config_malformed: config file is invalid — no guessing, fail loud
|
|
87
|
+
* - disabled: observer feature flag is off OR agent.enabled=false → no start, no noisy logs
|
|
88
|
+
* - needs_setup: observer enabled but runtime profile missing, API key not set, or unsupported profile type
|
|
89
|
+
* - ready: observer enabled and fully configured (pi-ai with key present)
|
|
90
|
+
* - not_ready: observer enabled, API key present, but runtime availability unknown
|
|
91
|
+
*/
|
|
92
|
+
export declare function resolveObserverConfig(workspaceDir: string, observerFlagId: string, observerAgentName: string, _logger?: {
|
|
93
|
+
warn?: (msg: string) => void;
|
|
94
|
+
info?: (msg: string) => void;
|
|
95
|
+
debug?: (msg: string) => void;
|
|
96
|
+
}): ObserverConfigResult;
|