create-principles-disciple 1.149.0 → 1.150.2
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/_release/product-identity.json +1 -1
- package/codex-adapter/dist/ingestion/ingestion.d.ts +9 -7
- package/codex-adapter/dist/ingestion/ingestion.js +68 -144
- package/codex-adapter/dist/ingestion/transcript-decoder.d.ts +35 -44
- package/codex-adapter/dist/ingestion/transcript-decoder.js +23 -84
- package/codex-adapter/dist/ingestion/transcript-source.d.ts +29 -0
- package/codex-adapter/dist/ingestion/transcript-source.js +65 -0
- package/codex-adapter/dist/pd-hook.d.ts +27 -1
- package/codex-adapter/dist/pd-hook.js +88 -7
- package/codex-adapter/dist/worker/workspace-worker.d.ts +15 -0
- package/codex-adapter/dist/worker/workspace-worker.js +7 -36
- package/codex-adapter/package.json +1 -1
- package/console/dist/server/index.js +14 -0
- package/console/dist/server/models/ActivationsConsoleModel.d.ts +3 -17
- package/console/dist/server/models/ActivationsConsoleModel.js +5 -44
- package/console/dist/server/routes/diagnostician.d.ts +50 -0
- package/console/dist/server/routes/diagnostician.js +388 -0
- package/console/dist/server/routes/examiner-eligibility.d.ts +73 -0
- package/console/dist/server/routes/examiner-eligibility.js +326 -0
- package/console/dist/server/routes/examiner.js +66 -8
- package/console/dist/web/assets/app.css +40 -0
- package/console/dist/web/assets/app.js +30 -30
- package/core/dist/host/host-installer.d.ts +7 -0
- package/core/dist/host/host-installer.d.ts.map +1 -1
- package/core/dist/host/host-installer.js.map +1 -1
- package/core/dist/runtime/activation/index.d.ts +3 -3
- package/core/dist/runtime/activation/index.d.ts.map +1 -1
- package/core/dist/runtime/activation/index.js +1 -1
- package/core/dist/runtime/activation/index.js.map +1 -1
- package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts +25 -1
- package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts.map +1 -1
- package/core/dist/runtime/activation/promotion-readiness-evaluator.js +58 -1
- package/core/dist/runtime/activation/promotion-readiness-evaluator.js.map +1 -1
- package/core/dist/runtime/activation/promotion-readiness-reader.d.ts.map +1 -1
- package/core/dist/runtime/activation/promotion-readiness-reader.js +4 -2
- package/core/dist/runtime/activation/promotion-readiness-reader.js.map +1 -1
- package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts +28 -0
- package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts.map +1 -1
- package/core/dist/runtime/activation/rulecode-owner-decision-service.js +2 -0
- package/core/dist/runtime/activation/rulecode-owner-decision-service.js.map +1 -1
- package/core/dist/runtime/admission-gate.d.ts +8 -1
- package/core/dist/runtime/admission-gate.d.ts.map +1 -1
- package/core/dist/runtime/admission-gate.js +2 -1
- package/core/dist/runtime/admission-gate.js.map +1 -1
- package/core/dist/runtime/config/pd-config-defaults.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-defaults.js +20 -2
- package/core/dist/runtime/config/pd-config-defaults.js.map +1 -1
- package/core/dist/runtime/config/pd-config-effective.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-effective.js +5 -2
- package/core/dist/runtime/config/pd-config-effective.js.map +1 -1
- package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-validate.js +18 -0
- package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
- package/core/dist/runtime/context-payload.d.ts +48 -3
- package/core/dist/runtime/context-payload.d.ts.map +1 -1
- package/core/dist/runtime/context-payload.js +38 -0
- package/core/dist/runtime/context-payload.js.map +1 -1
- package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts +8 -2
- package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js +28 -2
- package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js.map +1 -1
- package/core/dist/runtime/diagnostician-candidate.d.ts +24 -0
- package/core/dist/runtime/diagnostician-candidate.d.ts.map +1 -0
- package/core/dist/runtime/diagnostician-candidate.js +55 -0
- package/core/dist/runtime/diagnostician-candidate.js.map +1 -0
- package/core/dist/runtime/evidence-guards.d.ts +10 -4
- package/core/dist/runtime/evidence-guards.d.ts.map +1 -1
- package/core/dist/runtime/evidence-guards.js +12 -5
- package/core/dist/runtime/evidence-guards.js.map +1 -1
- package/core/dist/runtime/evolution/evolution-types.d.ts +4 -4
- package/core/dist/runtime/evolution/evolution-types.d.ts.map +1 -1
- package/core/dist/runtime/evolution/evolution-types.js +1 -0
- package/core/dist/runtime/evolution/evolution-types.js.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-contract.js +14 -0
- package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +16 -0
- package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
- package/core/dist/runtime/index.d.ts +5 -2
- package/core/dist/runtime/index.d.ts.map +1 -1
- package/core/dist/runtime/index.js +6 -1
- package/core/dist/runtime/index.js.map +1 -1
- package/core/dist/runtime/internalization/index.d.ts +1 -0
- package/core/dist/runtime/internalization/index.d.ts.map +1 -1
- package/core/dist/runtime/internalization/index.js +2 -0
- package/core/dist/runtime/internalization/index.js.map +1 -1
- package/core/dist/runtime/internalization/rule-host-contracts.d.ts +10 -0
- package/core/dist/runtime/internalization/rule-host-contracts.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rule-host-evaluator.js +10 -10
- package/core/dist/runtime/internalization/rule-host-evaluator.js.map +1 -1
- package/core/dist/runtime/internalization/rule-host-input-builder.d.ts +7 -6
- package/core/dist/runtime/internalization/rule-host-input-builder.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rule-host-input-builder.js +6 -2
- package/core/dist/runtime/internalization/rule-host-input-builder.js.map +1 -1
- package/core/dist/runtime/internalization/rule-host-result-normalizer.d.ts +33 -0
- package/core/dist/runtime/internalization/rule-host-result-normalizer.d.ts.map +1 -0
- package/core/dist/runtime/internalization/rule-host-result-normalizer.js +61 -0
- package/core/dist/runtime/internalization/rule-host-result-normalizer.js.map +1 -0
- package/core/dist/runtime/internalization/rule-host-validator.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rule-host-validator.js +17 -0
- package/core/dist/runtime/internalization/rule-host-validator.js.map +1 -1
- package/core/dist/runtime/pain-ingress-payload.d.ts +27 -2
- package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
- package/core/dist/runtime/pain-ingress-payload.js +45 -3
- package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
- package/core/dist/runtime/pain-ingress.d.ts +4 -2
- package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
- package/core/dist/runtime/pain-ingress.js +23 -3
- package/core/dist/runtime/pain-ingress.js.map +1 -1
- package/core/dist/runtime/pain-severity.d.ts +14 -0
- package/core/dist/runtime/pain-severity.d.ts.map +1 -0
- package/core/dist/runtime/pain-severity.js +14 -0
- package/core/dist/runtime/pain-severity.js.map +1 -0
- package/core/dist/runtime/pain-signal-bridge.d.ts +17 -3
- package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-bridge.js +6 -0
- package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
- package/core/dist/runtime/pain-signal-observability.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-observability.js +3 -2
- package/core/dist/runtime/pain-signal-observability.js.map +1 -1
- package/core/dist/runtime/pain-submit-capability.d.ts +164 -0
- package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -0
- package/core/dist/runtime/pain-submit-capability.js +442 -0
- package/core/dist/runtime/pain-submit-capability.js.map +1 -0
- package/core/dist/runtime/pain-to-principle-service.d.ts +4 -0
- package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
- package/core/dist/runtime/pain-to-principle-service.js +2 -0
- package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
- package/core/dist/runtime/stalled-diagnostician-task-read-model.d.ts +56 -10
- package/core/dist/runtime/stalled-diagnostician-task-read-model.d.ts.map +1 -1
- package/core/dist/runtime/stalled-diagnostician-task-read-model.js +80 -4
- package/core/dist/runtime/stalled-diagnostician-task-read-model.js.map +1 -1
- package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
- package/core/dist/runtime/store/context/sqlite-context-assembler.js +11 -0
- package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
- package/core/dist/runtime/store/run/memory-run-store.d.ts +10 -0
- package/core/dist/runtime/store/run/memory-run-store.d.ts.map +1 -1
- package/core/dist/runtime/store/run/memory-run-store.js +21 -0
- package/core/dist/runtime/store/run/memory-run-store.js.map +1 -1
- package/core/dist/runtime/store/run/run-store.d.ts +12 -0
- package/core/dist/runtime/store/run/run-store.d.ts.map +1 -1
- package/core/dist/runtime/store/run/sqlite-run-store.d.ts +1 -0
- package/core/dist/runtime/store/run/sqlite-run-store.d.ts.map +1 -1
- package/core/dist/runtime/store/run/sqlite-run-store.js +14 -0
- package/core/dist/runtime/store/run/sqlite-run-store.js.map +1 -1
- package/core/dist/runtime/task-status.d.ts +9 -0
- package/core/dist/runtime/task-status.d.ts.map +1 -1
- package/core/dist/runtime/task-status.js +7 -1
- package/core/dist/runtime/task-status.js.map +1 -1
- package/core/dist/runtime/types/evidence-chain-contract.d.ts +18 -0
- package/core/dist/runtime/types/evidence-chain-contract.d.ts.map +1 -1
- package/core/dist/runtime/types/evidence-chain-contract.js +37 -7
- package/core/dist/runtime/types/evidence-chain-contract.js.map +1 -1
- package/core/package.json +5 -1
- package/dist/install-summary.d.ts +7 -0
- package/dist/install-summary.d.ts.map +1 -1
- package/dist/install-summary.js +4 -0
- package/dist/install-summary.js.map +1 -1
- package/dist/installer.d.ts +34 -1
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +84 -4
- package/dist/installer.js.map +1 -1
- package/dist/installers/codex-host-installer.d.ts +88 -1
- package/dist/installers/codex-host-installer.d.ts.map +1 -1
- package/dist/installers/codex-host-installer.js +370 -11
- package/dist/installers/codex-host-installer.js.map +1 -1
- package/dist/installers/index.d.ts +23 -0
- package/dist/installers/index.d.ts.map +1 -1
- package/dist/installers/index.js +38 -1
- package/dist/installers/index.js.map +1 -1
- package/dist/installers/legacy-workbuddy-skill.d.ts +59 -0
- package/dist/installers/legacy-workbuddy-skill.d.ts.map +1 -0
- package/dist/installers/legacy-workbuddy-skill.js +168 -0
- package/dist/installers/legacy-workbuddy-skill.js.map +1 -0
- package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
- package/dist/installers/workbuddy-host-installer.js +7 -0
- package/dist/installers/workbuddy-host-installer.js.map +1 -1
- package/host-runtime/dist/adaptive-priority-provider.d.ts +101 -0
- package/host-runtime/dist/adaptive-priority-provider.js +194 -0
- package/host-runtime/dist/adaptive-selection.d.ts +164 -0
- package/host-runtime/dist/adaptive-selection.js +506 -0
- package/host-runtime/dist/adaptive-skip-decision.d.ts +61 -0
- package/host-runtime/dist/adaptive-skip-decision.js +114 -0
- package/host-runtime/dist/codex-ingestion-consent.d.ts +32 -95
- package/host-runtime/dist/codex-ingestion-consent.js +33 -205
- package/host-runtime/dist/conversation-ingestion/consent.d.ts +124 -0
- package/host-runtime/dist/conversation-ingestion/consent.js +531 -0
- package/host-runtime/dist/conversation-ingestion/index.d.ts +12 -0
- package/host-runtime/dist/conversation-ingestion/index.js +12 -0
- package/host-runtime/dist/conversation-ingestion/pipeline.d.ts +101 -0
- package/host-runtime/dist/conversation-ingestion/pipeline.js +162 -0
- package/host-runtime/dist/conversation-ingestion/source.d.ts +172 -0
- package/host-runtime/dist/conversation-ingestion/source.js +111 -0
- package/host-runtime/dist/conversation-ingestion/text-policy.d.ts +51 -0
- package/host-runtime/dist/conversation-ingestion/text-policy.js +68 -0
- package/host-runtime/dist/diagnostician-auto-run.d.ts +28 -0
- package/host-runtime/dist/diagnostician-auto-run.js +100 -0
- package/host-runtime/dist/governance-observation-store.d.ts +9 -7
- package/host-runtime/dist/governance-observation-store.js +20 -4
- package/host-runtime/dist/host-tool-semantic-resolver.d.ts +42 -1
- package/host-runtime/dist/host-tool-semantic-resolver.js +80 -14
- package/host-runtime/dist/index.d.ts +5 -0
- package/host-runtime/dist/index.js +12 -0
- package/host-runtime/dist/production-rulehost-gate.js +17 -17
- package/host-runtime/dist/rulecode-event-collection.d.ts +31 -0
- package/host-runtime/dist/rulecode-event-collection.js +62 -0
- package/host-runtime/package.json +1 -1
- package/package.json +3 -3
- package/pd-cli/dist/commands/diagnose.d.ts +30 -0
- package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
- package/pd-cli/dist/commands/diagnose.js +75 -0
- package/pd-cli/dist/commands/diagnose.js.map +1 -1
- package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-record.js +5 -4
- package/pd-cli/dist/commands/pain-record.js.map +1 -1
- package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-retry.js +2 -1
- package/pd-cli/dist/commands/pain-retry.js.map +1 -1
- package/pd-cli/dist/commands/runtime-activation.d.ts +6 -17
- package/pd-cli/dist/commands/runtime-activation.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-activation.js +42 -48
- package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
- package/pd-cli/dist/index.js +1 -0
- package/pd-cli/dist/index.js.map +1 -1
- package/pd-cli/dist/services/delivery-surfaces.js +1 -1
- package/pd-cli/dist/services/delivery-surfaces.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/pd-mcp-server/dist/budget.d.ts +1 -1
- package/pd-mcp-server/dist/budget.js +2 -2
- package/pd-mcp-server/dist/envelope.d.ts +15 -0
- package/pd-mcp-server/dist/envelope.js +49 -1
- package/pd-mcp-server/dist/index.d.ts +2 -0
- package/pd-mcp-server/dist/index.js +6 -0
- package/pd-mcp-server/dist/server.d.ts +83 -14
- package/pd-mcp-server/dist/server.js +251 -4
- package/pd-mcp-server/dist/version.d.ts +1 -1
- package/pd-mcp-server/dist/version.js +1 -1
- package/pd-mcp-server/dist/workspace.d.ts +4 -2
- package/pd-mcp-server/dist/workspace.js +5 -2
- package/pd-mcp-server/package.json +1 -1
- package/plugin/dist/bundle.js +449 -437
- package/plugin/dist/core/evolution-reducer.d.ts +2 -2
- package/plugin/dist/hooks/hook-tool-semantics.d.ts +25 -0
- package/plugin/dist/hooks/pain-ingress-adapter.d.ts +1 -1
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/dist/rulehost-evidence.js +1 -1
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/release-manager/dist/installer.js +84 -4
- package/release-manager/dist/installers/codex-host-installer.js +370 -11
- package/release-manager/dist/installers/index.js +38 -1
- package/release-manager/dist/installers/legacy-workbuddy-skill.js +168 -0
- package/release-manager/dist/installers/workbuddy-host-installer.js +7 -0
- package/release-manager/package.json +1 -1
- package/workbuddy-adapter/dist/pd-hook.js +20 -4
- package/workbuddy-adapter/package.json +1 -1
- package/workbuddy-adapter/plugin/skills/pd-pain-signal/SKILL.md +123 -20
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L3 — one bounded automatic-diagnosis round (SPEC-PD-AGENT-PAIN-INGRESS-001
|
|
3
|
+
* §8.4 / TECHNICAL-DESIGN §8.4).
|
|
4
|
+
*
|
|
5
|
+
* The degradation ladder is: L2 Console request-driven, L3 OpenClaw automatic,
|
|
6
|
+
* L4 offline/manual. This module is ONLY the L3 body: it is called from the
|
|
7
|
+
* existing `internalization_auto_consumer` timer (no new timer, no new
|
|
8
|
+
* background process) and serves at most one diagnostician task per call.
|
|
9
|
+
*
|
|
10
|
+
* Three preconditions, each with its own reason so the Owner can tell WHY
|
|
11
|
+
* nothing happened:
|
|
12
|
+
* 1. `serviceStarted` — the tick that calls us is by definition the service;
|
|
13
|
+
* the flag exists so a non-service caller can state it is not running.
|
|
14
|
+
* 2. `openclaw_diagnostician_consumer` flag (quiet, default on).
|
|
15
|
+
* 3. Diagnostician capability (`internalAgents.agents.diagnostician.enabled`).
|
|
16
|
+
*
|
|
17
|
+
* A skip is never a failure: the task keeps its pending state and L2 can still
|
|
18
|
+
* serve it. Nothing is marked, mutated or deleted on any skip path.
|
|
19
|
+
*/
|
|
20
|
+
import * as path from 'node:path';
|
|
21
|
+
import { PrincipleTreeLedgerAdapter, createPainSignalBridge, createRuntimeStateHandle, pickDiagnosticianCandidate, resolveDiagnosticianCapability, } from '@principles/core/runtime';
|
|
22
|
+
import { loadFeatureFlagFromConfig, loadPdConfigForPlugin } from './pd-config.js';
|
|
23
|
+
/** Quiet flag that owns the L3 half of the ladder. */
|
|
24
|
+
export const DIAGNOSTICIAN_AUTO_RUN_FLAG = 'openclaw_diagnostician_consumer';
|
|
25
|
+
/** Owner string used for the diagnostics this module starts. */
|
|
26
|
+
export const DIAGNOSTICIAN_AUTO_RUN_OWNER = 'pd-auto-diagnostician';
|
|
27
|
+
const DEFAULT_CANDIDATE_LIMIT = 1;
|
|
28
|
+
export async function runPendingDiagnosticianOnce(options) {
|
|
29
|
+
if (options.serviceStarted === false) {
|
|
30
|
+
return {
|
|
31
|
+
served: false,
|
|
32
|
+
reason: 'service_not_running',
|
|
33
|
+
message: 'the internalization_auto_consumer service is not running',
|
|
34
|
+
nextAction: 'Start the OpenClaw service, or diagnose from Console (L2) which does not need a timer.',
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const config = loadPdConfigForPlugin(options.workspaceDir);
|
|
38
|
+
const flag = loadFeatureFlagFromConfig(options.workspaceDir, DIAGNOSTICIAN_AUTO_RUN_FLAG);
|
|
39
|
+
if (!flag.enabled) {
|
|
40
|
+
return {
|
|
41
|
+
served: false,
|
|
42
|
+
reason: 'flag_off',
|
|
43
|
+
message: `features.${DIAGNOSTICIAN_AUTO_RUN_FLAG} is off`,
|
|
44
|
+
nextAction: 'Tasks stay pending for the Console request-driven path (L2); set the flag to true to re-enable automatic diagnosis.',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const capability = resolveDiagnosticianCapability(config.effective);
|
|
48
|
+
if (!capability.available) {
|
|
49
|
+
return {
|
|
50
|
+
served: false,
|
|
51
|
+
reason: 'capability_disabled',
|
|
52
|
+
message: capability.message,
|
|
53
|
+
nextAction: capability.nextAction,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const handle = await createRuntimeStateHandle({ workspaceDir: options.workspaceDir, readonly: false });
|
|
57
|
+
try {
|
|
58
|
+
const now = options.now ?? new Date().toISOString();
|
|
59
|
+
const candidate = await pickDiagnosticianCandidate(handle.stateManager, options.limit ?? DEFAULT_CANDIDATE_LIMIT, now);
|
|
60
|
+
if (candidate === null) {
|
|
61
|
+
return { served: false, reason: 'no_candidate' };
|
|
62
|
+
}
|
|
63
|
+
const stateDir = path.join(options.workspaceDir, '.state');
|
|
64
|
+
try {
|
|
65
|
+
const bridge = await createPainSignalBridge({
|
|
66
|
+
workspaceDir: options.workspaceDir,
|
|
67
|
+
stateDir,
|
|
68
|
+
ledgerAdapter: new PrincipleTreeLedgerAdapter({ stateDir }),
|
|
69
|
+
owner: options.owner ?? DIAGNOSTICIAN_AUTO_RUN_OWNER,
|
|
70
|
+
effectiveConfig: config.effective,
|
|
71
|
+
getEnvVar: options.getEnvVar ?? ((name) => process.env[name]),
|
|
72
|
+
});
|
|
73
|
+
const executed = await bridge.executePendingDiagnosis({ taskId: candidate.taskId });
|
|
74
|
+
if (executed.status === 'failed') {
|
|
75
|
+
return {
|
|
76
|
+
served: false,
|
|
77
|
+
taskId: candidate.taskId,
|
|
78
|
+
reason: 'execution_failed',
|
|
79
|
+
...(executed.message !== undefined ? { message: executed.message.slice(0, 200) } : {}),
|
|
80
|
+
nextAction: 'Inspect the workspace runtime profile; the task keeps its pending/retry state for the next tick or Console (L2).',
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return { served: true, taskId: candidate.taskId };
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
// A missing/!invalid runtime profile must not throw out of the timer that
|
|
87
|
+
// hosts us, and must not silently look like "no work" (rc-9).
|
|
88
|
+
return {
|
|
89
|
+
served: false,
|
|
90
|
+
taskId: candidate.taskId,
|
|
91
|
+
reason: 'execution_failed',
|
|
92
|
+
message: error instanceof Error ? error.message.slice(0, 200) : String(error).slice(0, 200),
|
|
93
|
+
nextAction: 'Configure the workspace runtime profile; the task keeps its pending state for the next tick or Console (L2).',
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
await handle.close().catch(() => undefined);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -3,13 +3,15 @@ export declare const GOVERNANCE_RETENTION_MAX_TURNS = 32;
|
|
|
3
3
|
export declare const GOVERNANCE_RETENTION_MAX_AGE_MS: number;
|
|
4
4
|
export declare const GOVERNANCE_PROMOTION_PRECEDING_TURNS = 12;
|
|
5
5
|
export declare const GOVERNANCE_PENDING_TAIL_STALE_MS: number;
|
|
6
|
+
/** Host taxonomy for governance observations (schema v4; PRI-1171 unification). */
|
|
7
|
+
export type GovernanceObservationHostKind = 'codex' | 'workbuddy' | 'openclaw';
|
|
6
8
|
export type GovernanceObservationKind = 'user_turn' | 'assistant_turn' | 'tool_call';
|
|
7
9
|
export type GovernanceObservationSource = 'live_hook' | 'transcript';
|
|
8
10
|
export type GovernanceObservationCompleteness = 'complete' | 'partial';
|
|
9
11
|
/** `quarantined` (Slice D §15): audited, permanently-invalid row; bodies dropped, metadata kept. */
|
|
10
12
|
export type GovernanceRetentionClass = 'operational' | 'promoted' | 'expired' | 'rolled_back' | 'quarantined';
|
|
11
13
|
export interface GovernanceObservationInput {
|
|
12
|
-
readonly hostKind:
|
|
14
|
+
readonly hostKind: GovernanceObservationHostKind;
|
|
13
15
|
readonly rolloutIdentity: string;
|
|
14
16
|
readonly rootSessionId: string;
|
|
15
17
|
readonly parentRolloutIdentity?: string;
|
|
@@ -45,7 +47,7 @@ export interface GovernanceObservationInput {
|
|
|
45
47
|
readonly observedAt: string;
|
|
46
48
|
}
|
|
47
49
|
export interface GovernanceCheckpointInput {
|
|
48
|
-
readonly hostKind:
|
|
50
|
+
readonly hostKind: GovernanceObservationHostKind;
|
|
49
51
|
readonly rolloutIdentity: string;
|
|
50
52
|
readonly byteOffset: number;
|
|
51
53
|
readonly lastOrdinal: number;
|
|
@@ -104,7 +106,7 @@ export interface GovernanceObservationRecord {
|
|
|
104
106
|
}
|
|
105
107
|
export interface PromoteGovernanceEvidenceInput {
|
|
106
108
|
readonly workspaceDir: string;
|
|
107
|
-
readonly hostKind:
|
|
109
|
+
readonly hostKind: GovernanceObservationHostKind;
|
|
108
110
|
readonly rolloutIdentity: string;
|
|
109
111
|
readonly triggerLogicalKey: string;
|
|
110
112
|
/** Caller-provided pain reference. Slice A never mints a pain identity (SPEC §18). */
|
|
@@ -136,7 +138,7 @@ type Degradation = {
|
|
|
136
138
|
nextAction: string;
|
|
137
139
|
};
|
|
138
140
|
export interface GovernanceRolloutDescriptor {
|
|
139
|
-
readonly hostKind:
|
|
141
|
+
readonly hostKind: GovernanceObservationHostKind;
|
|
140
142
|
readonly rolloutIdentity: string;
|
|
141
143
|
readonly rootSessionId: string;
|
|
142
144
|
readonly parentRolloutIdentity?: string;
|
|
@@ -159,14 +161,14 @@ export interface IngestGovernanceObservationsInput {
|
|
|
159
161
|
export declare function ingestGovernanceObservations(input: IngestGovernanceObservationsInput): IngestGovernanceObservationsResult;
|
|
160
162
|
export interface ReadGovernanceCheckpointArgs {
|
|
161
163
|
readonly workspaceDir: string;
|
|
162
|
-
readonly hostKind:
|
|
164
|
+
readonly hostKind: GovernanceObservationHostKind;
|
|
163
165
|
readonly rolloutIdentity: string;
|
|
164
166
|
readonly databaseFactory?: ObservationDatabaseFactory;
|
|
165
167
|
}
|
|
166
168
|
export declare function readGovernanceCheckpoint(args: ReadGovernanceCheckpointArgs): GovernanceCheckpointRecord | null | Degradation;
|
|
167
169
|
export interface ListGovernanceCheckpointsArgs {
|
|
168
170
|
readonly workspaceDir: string;
|
|
169
|
-
readonly hostKind:
|
|
171
|
+
readonly hostKind: GovernanceObservationHostKind;
|
|
170
172
|
readonly databaseFactory?: ObservationDatabaseFactory;
|
|
171
173
|
}
|
|
172
174
|
export type ListGovernanceCheckpointsResult = {
|
|
@@ -196,7 +198,7 @@ export declare function listGovernanceObservations(input: ListGovernanceObservat
|
|
|
196
198
|
export declare function promoteGovernanceEvidence(input: PromoteGovernanceEvidenceInput): PromoteGovernanceEvidenceResult;
|
|
197
199
|
export interface QuarantineGovernanceObservationArgs {
|
|
198
200
|
readonly workspaceDir: string;
|
|
199
|
-
readonly hostKind:
|
|
201
|
+
readonly hostKind: GovernanceObservationHostKind;
|
|
200
202
|
readonly rolloutIdentity: string;
|
|
201
203
|
/** governance_observations.id — `pd codex ingest quarantine --record <id>`. */
|
|
202
204
|
readonly recordId: number;
|
|
@@ -34,7 +34,12 @@ export const GOVERNANCE_RETENTION_MAX_TURNS = 32;
|
|
|
34
34
|
export const GOVERNANCE_RETENTION_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
35
35
|
export const GOVERNANCE_PROMOTION_PRECEDING_TURNS = 12;
|
|
36
36
|
export const GOVERNANCE_PENDING_TAIL_STALE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
37
|
-
|
|
37
|
+
// Schema v4 (PRI-1171): additive contract widening over v3 — host_kind admits
|
|
38
|
+
// 'workbuddy'/'openclaw' (app-layer union; the DDL keeps unconstrained TEXT),
|
|
39
|
+
// and the checkpoint upsert is MAX-monotonic (concurrent Stop × worker
|
|
40
|
+
// catch-up must never drag a committed water mark backwards). No v3 DDL is
|
|
41
|
+
// rewritten; existing stores bump the version row on next open.
|
|
42
|
+
const GOVERNANCE_OBSERVATION_SCHEMA_VERSION = 4;
|
|
38
43
|
const MAX_TEXT_BOUND = 200; // matches MAX_EVIDENCE_VALUE_CHARS; guards stored identity fields
|
|
39
44
|
const MAX_JSON_COLUMN = 8_000;
|
|
40
45
|
function isRecord(value) {
|
|
@@ -426,13 +431,24 @@ export function ingestGovernanceObservations(input) {
|
|
|
426
431
|
: firstDegradation
|
|
427
432
|
? { reason: firstDegradation.reason, ordinal: firstDegradation.ordinal ?? null }
|
|
428
433
|
: null;
|
|
434
|
+
// Monotonic checkpoint (PRI-1171 review): a stale concurrent writer
|
|
435
|
+
// (Stop × worker catch-up) can neither drag the water mark back NOR
|
|
436
|
+
// refresh its companion fields — root_session_id, incomplete_tail,
|
|
437
|
+
// degradation bookkeeping, and updated_at advance only with a
|
|
438
|
+
// non-regressing byte_offset, so health-page state stays consistent
|
|
439
|
+
// with the committed mark.
|
|
429
440
|
db.prepare(`INSERT INTO governance_transcript_checkpoints
|
|
430
441
|
(host_kind, rollout_identity, byte_offset, last_ordinal, cli_version, root_session_id, incomplete_tail, last_degradation_reason, last_degradation_ordinal, updated_at)
|
|
431
442
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
432
443
|
ON CONFLICT(host_kind, rollout_identity) DO UPDATE SET
|
|
433
|
-
byte_offset =
|
|
434
|
-
|
|
435
|
-
|
|
444
|
+
byte_offset = MAX(governance_transcript_checkpoints.byte_offset, excluded.byte_offset),
|
|
445
|
+
last_ordinal = MAX(governance_transcript_checkpoints.last_ordinal, excluded.last_ordinal),
|
|
446
|
+
cli_version = COALESCE(excluded.cli_version, cli_version),
|
|
447
|
+
root_session_id = CASE WHEN excluded.byte_offset >= governance_transcript_checkpoints.byte_offset THEN excluded.root_session_id ELSE governance_transcript_checkpoints.root_session_id END,
|
|
448
|
+
incomplete_tail = CASE WHEN excluded.byte_offset >= governance_transcript_checkpoints.byte_offset THEN excluded.incomplete_tail ELSE governance_transcript_checkpoints.incomplete_tail END,
|
|
449
|
+
last_degradation_reason = CASE WHEN excluded.byte_offset >= governance_transcript_checkpoints.byte_offset THEN excluded.last_degradation_reason ELSE governance_transcript_checkpoints.last_degradation_reason END,
|
|
450
|
+
last_degradation_ordinal = CASE WHEN excluded.byte_offset >= governance_transcript_checkpoints.byte_offset THEN excluded.last_degradation_ordinal ELSE governance_transcript_checkpoints.last_degradation_ordinal END,
|
|
451
|
+
updated_at = CASE WHEN excluded.byte_offset >= governance_transcript_checkpoints.byte_offset THEN excluded.updated_at ELSE governance_transcript_checkpoints.updated_at END`)
|
|
436
452
|
.run(input.checkpoint.hostKind, input.checkpoint.rolloutIdentity, byteOffset, input.checkpoint.lastOrdinal, input.checkpoint.cliVersion ?? null, input.checkpoint.rootSessionId, input.checkpoint.incompleteTail ? 1 : 0, lastDegradation?.reason ?? null, lastDegradation?.ordinal ?? null, now);
|
|
437
453
|
}
|
|
438
454
|
// Marker semantics: compaction replaces logical history (tombstone every
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
* on the Console)
|
|
16
16
|
* - auto-consumer / codex worker (host-threaded registries, already
|
|
17
17
|
* host-exact; the resolver exists for host-neutral entries)
|
|
18
|
+
* - B3: `resolveHostToolSemanticsForHook` — the realtime hook entry point
|
|
19
|
+
* (OpenClaw gate, Codex / WorkBuddy pd-hook) resolves the SAME durable
|
|
20
|
+
* declarations replay reads, instead of only its compiled-in list.
|
|
18
21
|
*
|
|
19
22
|
* Multi-host semantics (R2 P1-2): declarations are PER-HOST files under
|
|
20
23
|
* `.pd/host-tool-semantics/<hostKind>.json` (last-writer-wins on a shared
|
|
@@ -25,7 +28,7 @@
|
|
|
25
28
|
*
|
|
26
29
|
* Pure logic + declared-file I/O only. Merging is order-independent.
|
|
27
30
|
*/
|
|
28
|
-
import { type ToolSemanticRegistry } from '@principles/core/runtime';
|
|
31
|
+
import { type ToolSemanticMappingV1, type ToolSemanticRegistry } from '@principles/core/runtime';
|
|
29
32
|
import { saveHostToolDeclaration, type HostToolDeclaration } from './host-tool-declaration.js';
|
|
30
33
|
export type HostToolSemanticResolution = {
|
|
31
34
|
readonly ok: true;
|
|
@@ -43,5 +46,43 @@ export type HostToolSemanticResolution = {
|
|
|
43
46
|
* against baseline names is a forged proof; ERR-114).
|
|
44
47
|
*/
|
|
45
48
|
export declare function resolveWorkspaceHostToolSemantics(workspaceDir: string): HostToolSemanticResolution;
|
|
49
|
+
/** Where the hook-facing registry got its host layer from. */
|
|
50
|
+
export type HookToolSemanticsSource = 'workspace-declaration' | 'host-static';
|
|
51
|
+
export type HookToolSemanticsResolution = {
|
|
52
|
+
readonly ok: true;
|
|
53
|
+
readonly registry: ToolSemanticRegistry;
|
|
54
|
+
readonly source: HookToolSemanticsSource;
|
|
55
|
+
} | {
|
|
56
|
+
readonly ok: false;
|
|
57
|
+
readonly reason: string;
|
|
58
|
+
readonly nextAction: string;
|
|
59
|
+
};
|
|
60
|
+
export interface HookToolSemanticsOptions {
|
|
61
|
+
readonly workspaceDir: string;
|
|
62
|
+
/** The calling host's identity label (also the declaration filename). */
|
|
63
|
+
readonly hostKind: string;
|
|
64
|
+
/** The host's compiled-in declaration — the fallback data source. */
|
|
65
|
+
readonly staticMappings: readonly ToolSemanticMappingV1[];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* B3 — the ONE entry point the realtime hook uses to resolve tool semantics.
|
|
69
|
+
*
|
|
70
|
+
* Precedence (plan §4.2): workspace declaration → host static declaration →
|
|
71
|
+
* core baseline. Replay/evidence/Console already read the declarations via
|
|
72
|
+
* `resolveWorkspaceHostToolSemantics`; before B3 the hook read the compiled-in
|
|
73
|
+
* static list only, so a workspace declaration could disagree with production
|
|
74
|
+
* on the same event.
|
|
75
|
+
*
|
|
76
|
+
* - no declaration persisted → the host static registry (`source:
|
|
77
|
+
* 'host-static'`): the pre-B3 behavior, and the normal state before a host
|
|
78
|
+
* has started once in this workspace.
|
|
79
|
+
* - declaration persisted → its names win (they are what replay resolves),
|
|
80
|
+
* and static names the declaration does not carry are still filled in so a
|
|
81
|
+
* stale file cannot amputate the host's current surface.
|
|
82
|
+
* - malformed / conflicting declaration → typed refusal, never a silent
|
|
83
|
+
* static fallback and never an empty registry. Consumers must surface the
|
|
84
|
+
* reason (rc-9) and may fall back to their static registry for availability.
|
|
85
|
+
*/
|
|
86
|
+
export declare function resolveHostToolSemanticsForHook(options: HookToolSemanticsOptions): HookToolSemanticsResolution;
|
|
46
87
|
export { saveHostToolDeclaration };
|
|
47
88
|
export type { HostToolDeclaration };
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
* on the Console)
|
|
16
16
|
* - auto-consumer / codex worker (host-threaded registries, already
|
|
17
17
|
* host-exact; the resolver exists for host-neutral entries)
|
|
18
|
+
* - B3: `resolveHostToolSemanticsForHook` — the realtime hook entry point
|
|
19
|
+
* (OpenClaw gate, Codex / WorkBuddy pd-hook) resolves the SAME durable
|
|
20
|
+
* declarations replay reads, instead of only its compiled-in list.
|
|
18
21
|
*
|
|
19
22
|
* Multi-host semantics (R2 P1-2): declarations are PER-HOST files under
|
|
20
23
|
* `.pd/host-tool-semantics/<hostKind>.json` (last-writer-wins on a shared
|
|
@@ -28,22 +31,16 @@
|
|
|
28
31
|
import { buildToolSemanticRegistry, } from '@principles/core/runtime';
|
|
29
32
|
import { loadHostToolDeclarations, saveHostToolDeclaration, } from './host-tool-declaration.js';
|
|
30
33
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
34
|
+
* Union every declared host's mappings, order-independently.
|
|
35
|
+
*
|
|
36
|
+
* Same raw name from two hosts must agree on kind; a conflict means a host
|
|
37
|
+
* declared a name it does not own — fail loud rather than pick a winner by
|
|
38
|
+
* startup order (P4 one-source-of-truth).
|
|
35
39
|
*/
|
|
36
|
-
|
|
37
|
-
const loaded = loadHostToolDeclarations(workspaceDir);
|
|
38
|
-
if (!loaded.ok) {
|
|
39
|
-
return { ok: false, reason: loaded.reason, nextAction: loaded.nextAction };
|
|
40
|
-
}
|
|
40
|
+
function mergeDeclarations(declarations) {
|
|
41
41
|
const mappings = [];
|
|
42
|
-
for (const declaration of
|
|
42
|
+
for (const declaration of declarations) {
|
|
43
43
|
for (const mapping of declaration.mappings) {
|
|
44
|
-
// Same raw name from two hosts must agree on kind; a conflict means a
|
|
45
|
-
// host declared a name it does not own — fail loud rather than pick a
|
|
46
|
-
// winner by startup order (P4 one-source-of-truth).
|
|
47
44
|
const existing = mappings.find((m) => m.rawToolName === mapping.rawToolName);
|
|
48
45
|
if (existing && existing.canonicalKind !== mapping.canonicalKind) {
|
|
49
46
|
return {
|
|
@@ -56,7 +53,23 @@ export function resolveWorkspaceHostToolSemantics(workspaceDir) {
|
|
|
56
53
|
mappings.push(mapping);
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
|
-
|
|
56
|
+
return { ok: true, mappings };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Resolve the merged workspace registry from durable host provenance.
|
|
60
|
+
* Fails loud when no declaration is persisted or any persisted declaration
|
|
61
|
+
* is malformed — never falls back to the core baseline (an existence check
|
|
62
|
+
* against baseline names is a forged proof; ERR-114).
|
|
63
|
+
*/
|
|
64
|
+
export function resolveWorkspaceHostToolSemantics(workspaceDir) {
|
|
65
|
+
const loaded = loadHostToolDeclarations(workspaceDir);
|
|
66
|
+
if (!loaded.ok) {
|
|
67
|
+
return { ok: false, reason: loaded.reason, nextAction: loaded.nextAction };
|
|
68
|
+
}
|
|
69
|
+
const merged = mergeDeclarations(loaded.declarations);
|
|
70
|
+
if (!merged.ok)
|
|
71
|
+
return merged;
|
|
72
|
+
const built = buildToolSemanticRegistry(merged.mappings);
|
|
60
73
|
if (!built.ok) {
|
|
61
74
|
return {
|
|
62
75
|
ok: false,
|
|
@@ -70,4 +83,57 @@ export function resolveWorkspaceHostToolSemantics(workspaceDir) {
|
|
|
70
83
|
hostKinds: loaded.declarations.map((d) => d.hostKind).sort(),
|
|
71
84
|
};
|
|
72
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* B3 — the ONE entry point the realtime hook uses to resolve tool semantics.
|
|
88
|
+
*
|
|
89
|
+
* Precedence (plan §4.2): workspace declaration → host static declaration →
|
|
90
|
+
* core baseline. Replay/evidence/Console already read the declarations via
|
|
91
|
+
* `resolveWorkspaceHostToolSemantics`; before B3 the hook read the compiled-in
|
|
92
|
+
* static list only, so a workspace declaration could disagree with production
|
|
93
|
+
* on the same event.
|
|
94
|
+
*
|
|
95
|
+
* - no declaration persisted → the host static registry (`source:
|
|
96
|
+
* 'host-static'`): the pre-B3 behavior, and the normal state before a host
|
|
97
|
+
* has started once in this workspace.
|
|
98
|
+
* - declaration persisted → its names win (they are what replay resolves),
|
|
99
|
+
* and static names the declaration does not carry are still filled in so a
|
|
100
|
+
* stale file cannot amputate the host's current surface.
|
|
101
|
+
* - malformed / conflicting declaration → typed refusal, never a silent
|
|
102
|
+
* static fallback and never an empty registry. Consumers must surface the
|
|
103
|
+
* reason (rc-9) and may fall back to their static registry for availability.
|
|
104
|
+
*/
|
|
105
|
+
export function resolveHostToolSemanticsForHook(options) {
|
|
106
|
+
const builtStatic = buildToolSemanticRegistry(options.staticMappings);
|
|
107
|
+
if (!builtStatic.ok) {
|
|
108
|
+
return {
|
|
109
|
+
ok: false,
|
|
110
|
+
reason: `host_tool_semantics_static_invalid (${options.hostKind})`,
|
|
111
|
+
nextAction: `fix the '${options.hostKind}' compiled-in tool declaration: ${builtStatic.errors.slice(0, 3).join('; ')}`,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const loaded = loadHostToolDeclarations(options.workspaceDir);
|
|
115
|
+
if (!loaded.ok) {
|
|
116
|
+
if (loaded.reason === 'host_tool_declaration_missing') {
|
|
117
|
+
return { ok: true, registry: builtStatic.registry, source: 'host-static' };
|
|
118
|
+
}
|
|
119
|
+
return { ok: false, reason: loaded.reason, nextAction: loaded.nextAction };
|
|
120
|
+
}
|
|
121
|
+
const merged = mergeDeclarations(loaded.declarations);
|
|
122
|
+
if (!merged.ok)
|
|
123
|
+
return merged;
|
|
124
|
+
const mappings = [...merged.mappings];
|
|
125
|
+
for (const mapping of options.staticMappings) {
|
|
126
|
+
if (!mappings.some((m) => m.rawToolName === mapping.rawToolName))
|
|
127
|
+
mappings.push(mapping);
|
|
128
|
+
}
|
|
129
|
+
const built = buildToolSemanticRegistry(mappings);
|
|
130
|
+
if (!built.ok) {
|
|
131
|
+
return {
|
|
132
|
+
ok: false,
|
|
133
|
+
reason: `host_tool_semantics_static_invalid (${options.hostKind})`,
|
|
134
|
+
nextAction: `merged tool mappings invalid: ${built.errors.slice(0, 3).join('; ')}`,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return { ok: true, registry: built.registry, source: 'workspace-declaration' };
|
|
138
|
+
}
|
|
73
139
|
export { saveHostToolDeclaration };
|
|
@@ -11,17 +11,22 @@ export * from './prompt-activation-deliverability.js';
|
|
|
11
11
|
export * from './prompt-injection-status.js';
|
|
12
12
|
export * from './prompt-injection-event-evidence.js';
|
|
13
13
|
export * from './prompt-injection-budget-observation.js';
|
|
14
|
+
export * from './rulecode-event-collection.js';
|
|
14
15
|
export * from './pd-config.js';
|
|
15
16
|
export * from './production-rulehost-gate.js';
|
|
16
17
|
export * from './rule-implementation-runtime.js';
|
|
17
18
|
export * from './production-pain-evidence.js';
|
|
18
19
|
export * from './governance-observation-store.js';
|
|
20
|
+
export * from './conversation-ingestion/index.js';
|
|
19
21
|
export * from './governance-signal-admission.js';
|
|
20
22
|
export * from './signal-classifier.js';
|
|
23
|
+
export * from './adaptive-selection.js';
|
|
24
|
+
export * from './adaptive-priority-provider.js';
|
|
21
25
|
export * from './signal-stage2-cycle.js';
|
|
22
26
|
export * from './host-liveness-contract.js';
|
|
23
27
|
export * from './internalization-consumer-governance.js';
|
|
24
28
|
export * from './internalization-consumer-cycle.js';
|
|
29
|
+
export * from './diagnostician-auto-run.js';
|
|
25
30
|
export * from './host-tool-declaration.js';
|
|
26
31
|
export * from './host-tool-semantic-resolver.js';
|
|
27
32
|
export * from './evaluator-runtime-context.js';
|
|
@@ -21,19 +21,31 @@ export * from './prompt-injection-event-evidence.js';
|
|
|
21
21
|
// events — console surfaces forecast under the budget the last real
|
|
22
22
|
// injection used (SPEC §6.1), labelled with source + observation time.
|
|
23
23
|
export * from './prompt-injection-budget-observation.js';
|
|
24
|
+
// RuleCode shadow telemetry scan: ONE filesystem reader for CLI promotion
|
|
25
|
+
// review and the Console Owner review (5B deduplication).
|
|
26
|
+
export * from './rulecode-event-collection.js';
|
|
24
27
|
export * from './pd-config.js';
|
|
25
28
|
export * from './production-rulehost-gate.js';
|
|
26
29
|
export * from './rule-implementation-runtime.js';
|
|
27
30
|
export * from './production-pain-evidence.js';
|
|
28
31
|
export * from './governance-observation-store.js';
|
|
32
|
+
// PRI-1171: unified conversation-ingestion seam — the ONE host-neutral entry
|
|
33
|
+
// for transcript trajectory ingestion (source contract + shared pipeline +
|
|
34
|
+
// consent ledger v3 + text policy). Host decoders stay in their adapter
|
|
35
|
+
// packages; a new host implements TranscriptSourceAdapter with zero changes
|
|
36
|
+
// here.
|
|
37
|
+
export * from './conversation-ingestion/index.js';
|
|
29
38
|
export * from './governance-signal-admission.js';
|
|
30
39
|
export * from './signal-classifier.js';
|
|
40
|
+
export * from './adaptive-selection.js';
|
|
41
|
+
export * from './adaptive-priority-provider.js';
|
|
31
42
|
export * from './signal-stage2-cycle.js';
|
|
32
43
|
export * from './host-liveness-contract.js';
|
|
33
44
|
// PRI-624 Slice C: shared internalization consumer execution (OpenClaw
|
|
34
45
|
// auto-consumer + Companion workspace worker call the same cycle).
|
|
35
46
|
export * from './internalization-consumer-governance.js';
|
|
36
47
|
export * from './internalization-consumer-cycle.js';
|
|
48
|
+
export * from './diagnostician-auto-run.js';
|
|
37
49
|
// PRI-634-F R2: durable host-authored tool declaration — hosts persist, host-
|
|
38
50
|
// neutral consumers (pd-cli/pd-console) resolve through the ONE resolver.
|
|
39
51
|
export * from './host-tool-declaration.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { buildRuleHostAction, buildToolSemanticRegistry, deriveToolHintsFromCanonicalKind, estimateLineChanges, mergeDecisions, SqliteConnection, UNAVAILABLE_RULE_CONTEXT, validateRuleContextV2,
|
|
3
|
+
import { buildRuleHostAction, buildToolSemanticRegistry, deriveToolHintsFromCanonicalKind, estimateLineChanges, mergeDecisions, normalizeRuleHostResult, SqliteConnection, UNAVAILABLE_RULE_CONTEXT, validateRuleContextV2, verifyPiArtifactRowDigest, RECOVERY_CONTROL_SURFACES, } from '@principles/core/runtime';
|
|
4
4
|
import { isSensitiveSystemPath } from '@principles/core/runtime/internalization/rule-host-input-builder';
|
|
5
5
|
import { classifyBashRisk } from '@principles/core/runtime/internalization/bash-risk';
|
|
6
6
|
import { scanRetiredContractSymbols } from './legacy-rule-contract-symbols.js';
|
|
@@ -76,9 +76,6 @@ function isRuleMeta(value) {
|
|
|
76
76
|
function isRuleContext(value) {
|
|
77
77
|
return validateRuleContextV2(value).valid;
|
|
78
78
|
}
|
|
79
|
-
function isRuleResult(value) {
|
|
80
|
-
return validateRuleHostResult(value).valid;
|
|
81
|
-
}
|
|
82
79
|
const baselineToolSemanticsResult = buildToolSemanticRegistry();
|
|
83
80
|
// Static baseline input — always builds; throwing here is a programming error.
|
|
84
81
|
if (!baselineToolSemanticsResult.ok) {
|
|
@@ -588,14 +585,14 @@ export function createProductionRuleHostGate(options = {}) {
|
|
|
588
585
|
addWarning(warnings, `implementation_unhealthy: ${batchResult && !batchResult.ok ? batchResult.error ?? 'unknown child error' : 'rule_batch_result_missing'}`, 'fix the shadow RuleCode and reactivate the rule; live enforcement is unaffected');
|
|
589
586
|
continue;
|
|
590
587
|
}
|
|
591
|
-
const
|
|
592
|
-
if (
|
|
593
|
-
addWarning(warnings, `invalid RuleHostResult: ${
|
|
588
|
+
const normalized = normalizeRuleHostResult(batchResult.result);
|
|
589
|
+
if (normalized.degraded !== undefined) {
|
|
590
|
+
addWarning(warnings, `invalid RuleHostResult: ${normalized.degraded.notes ?? 'unknown invalid result'}`, 'fix the shadow RuleCode result and reactivate the rule; live enforcement is unaffected');
|
|
594
591
|
continue;
|
|
595
592
|
}
|
|
596
|
-
const shadowResult =
|
|
597
|
-
? { ...
|
|
598
|
-
:
|
|
593
|
+
const shadowResult = normalized.matched
|
|
594
|
+
? { ...normalized, ruleId: candidate.ruleId, principleId: candidate.principleId }
|
|
595
|
+
: normalized;
|
|
599
596
|
shadowEvaluations.push({
|
|
600
597
|
toolName: input.toolName,
|
|
601
598
|
filePath: action.normalizedPath,
|
|
@@ -623,14 +620,17 @@ export function createProductionRuleHostGate(options = {}) {
|
|
|
623
620
|
addWarning(warnings, `implementation_unhealthy: ${batchResult.error ?? 'unknown child error'}`, 'fix the RuleCode and reactivate the rule');
|
|
624
621
|
continue;
|
|
625
622
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
623
|
+
// B1: one reading of unusable output. Previously this branch warned and
|
|
624
|
+
// `continue`d, so the rule silently stopped participating and another
|
|
625
|
+
// rule's allow could win the merge. Normalization keeps it in the merge
|
|
626
|
+
// as a contract-level fail-closed requireApproval marked `degraded`.
|
|
627
|
+
const normalized = normalizeRuleHostResult(batchResult.result);
|
|
628
|
+
if (normalized.degraded !== undefined) {
|
|
629
|
+
addWarning(warnings, `invalid RuleHostResult: ${normalized.degraded.notes ?? 'unknown invalid result'}`, 'fix the RuleCode result and reactivate the rule; invalid output is normalized to requireApproval (fail-closed in the contract, not enforced as a block by this gate)');
|
|
630
630
|
}
|
|
631
|
-
const validatedResult =
|
|
632
|
-
? { ...
|
|
633
|
-
:
|
|
631
|
+
const validatedResult = normalized.matched
|
|
632
|
+
? { ...normalized, ruleId: candidate.ruleId, principleId: candidate.principleId }
|
|
633
|
+
: normalized;
|
|
634
634
|
implementations.push({ ...candidate, evaluate: () => validatedResult });
|
|
635
635
|
liveEvaluatedResults.push(validatedResult);
|
|
636
636
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface CollectedRuleCodeEventEntries {
|
|
2
|
+
entries: unknown[];
|
|
3
|
+
/** Number of candidate directories that actually exist on disk. */
|
|
4
|
+
sourceDirsFound: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* PRI-577: RuleCode event telemetry candidate directories, in priority order.
|
|
8
|
+
*
|
|
9
|
+
* Runtime convention is `.pd/logs`, but the v1 EventLog writer
|
|
10
|
+
* (openclaw-plugin `src/core/event-log.ts`) still emits `events_*.jsonl` under
|
|
11
|
+
* `.state/logs`. No production code ever created `.pd/logs`, so scanning only
|
|
12
|
+
* that path made every shadow metric report "unavailable" while 2500+ real
|
|
13
|
+
* evaluations sat unread in `.state/logs`. Readers scan both candidates until
|
|
14
|
+
* the writer migrates (ERR-031: every reader derives from the host-runtime
|
|
15
|
+
* constant `RUNTIME_EVENT_LOG_CANDIDATE_DIRS`, so they cannot drift).
|
|
16
|
+
*/
|
|
17
|
+
export declare const RULECODE_EVENT_LOG_CANDIDATE_DIRS: readonly string[];
|
|
18
|
+
/**
|
|
19
|
+
* Collect rulehost telemetry entries from all candidate log directories.
|
|
20
|
+
* Malformed lines are excluded individually. A directory counts as a source
|
|
21
|
+
* only after it can be enumerated, so an unreadable path cannot be mistaken
|
|
22
|
+
* for a healthy channel with zero events (ERR-002).
|
|
23
|
+
*
|
|
24
|
+
* Exact lines copied between candidate directories are deduplicated by
|
|
25
|
+
* priority. Different events in same-named daily files are retained.
|
|
26
|
+
*
|
|
27
|
+
* ONE implementation: this is the host-side filesystem reader the CLI
|
|
28
|
+
* (`runtime activation promote`) and the Console Owner review both consume, so
|
|
29
|
+
* a fix to the scan cannot land in one consumer and silently lag in the other.
|
|
30
|
+
*/
|
|
31
|
+
export declare function collectRuleCodeEventEntries(workspaceDir: string): CollectedRuleCodeEventEntries;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { RUNTIME_EVENT_LOG_CANDIDATE_DIRS } from './prompt-injection-budget-observation.js';
|
|
4
|
+
/**
|
|
5
|
+
* PRI-577: RuleCode event telemetry candidate directories, in priority order.
|
|
6
|
+
*
|
|
7
|
+
* Runtime convention is `.pd/logs`, but the v1 EventLog writer
|
|
8
|
+
* (openclaw-plugin `src/core/event-log.ts`) still emits `events_*.jsonl` under
|
|
9
|
+
* `.state/logs`. No production code ever created `.pd/logs`, so scanning only
|
|
10
|
+
* that path made every shadow metric report "unavailable" while 2500+ real
|
|
11
|
+
* evaluations sat unread in `.state/logs`. Readers scan both candidates until
|
|
12
|
+
* the writer migrates (ERR-031: every reader derives from the host-runtime
|
|
13
|
+
* constant `RUNTIME_EVENT_LOG_CANDIDATE_DIRS`, so they cannot drift).
|
|
14
|
+
*/
|
|
15
|
+
export const RULECODE_EVENT_LOG_CANDIDATE_DIRS = RUNTIME_EVENT_LOG_CANDIDATE_DIRS;
|
|
16
|
+
/**
|
|
17
|
+
* Collect rulehost telemetry entries from all candidate log directories.
|
|
18
|
+
* Malformed lines are excluded individually. A directory counts as a source
|
|
19
|
+
* only after it can be enumerated, so an unreadable path cannot be mistaken
|
|
20
|
+
* for a healthy channel with zero events (ERR-002).
|
|
21
|
+
*
|
|
22
|
+
* Exact lines copied between candidate directories are deduplicated by
|
|
23
|
+
* priority. Different events in same-named daily files are retained.
|
|
24
|
+
*
|
|
25
|
+
* ONE implementation: this is the host-side filesystem reader the CLI
|
|
26
|
+
* (`runtime activation promote`) and the Console Owner review both consume, so
|
|
27
|
+
* a fix to the scan cannot land in one consumer and silently lag in the other.
|
|
28
|
+
*/
|
|
29
|
+
export function collectRuleCodeEventEntries(workspaceDir) {
|
|
30
|
+
const entries = [];
|
|
31
|
+
let sourceDirsFound = 0;
|
|
32
|
+
const higherPriorityLines = new Set();
|
|
33
|
+
for (const candidate of RULECODE_EVENT_LOG_CANDIDATE_DIRS) {
|
|
34
|
+
const logsDir = path.join(workspaceDir, ...candidate.split('/'));
|
|
35
|
+
if (!fs.existsSync(logsDir))
|
|
36
|
+
continue;
|
|
37
|
+
try {
|
|
38
|
+
const files = fs.readdirSync(logsDir)
|
|
39
|
+
.filter(name => /^events_.*\.jsonl$/.test(name))
|
|
40
|
+
.sort()
|
|
41
|
+
.slice(-7);
|
|
42
|
+
sourceDirsFound += 1;
|
|
43
|
+
const currentSourceLines = [];
|
|
44
|
+
for (const file of files) {
|
|
45
|
+
const lines = fs.readFileSync(path.join(logsDir, file), 'utf8').split('\n').filter(Boolean);
|
|
46
|
+
for (const line of lines) {
|
|
47
|
+
currentSourceLines.push(line);
|
|
48
|
+
if (higherPriorityLines.has(line))
|
|
49
|
+
continue;
|
|
50
|
+
try {
|
|
51
|
+
entries.push(JSON.parse(line));
|
|
52
|
+
}
|
|
53
|
+
catch { /* exclude malformed telemetry */ }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const line of currentSourceLines)
|
|
57
|
+
higherPriorityLines.add(line);
|
|
58
|
+
}
|
|
59
|
+
catch { /* unreadable directory contributes no entries */ }
|
|
60
|
+
}
|
|
61
|
+
return { entries, sourceDirsFound };
|
|
62
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-principles-disciple",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.150.2",
|
|
4
4
|
"description": "Interactive CLI installer for Principles Disciple OpenClaw plugin",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"directory": "packages/create-principles-disciple"
|
|
100
100
|
},
|
|
101
101
|
"pd": {
|
|
102
|
-
"bundledPluginVersion": "3.1
|
|
102
|
+
"bundledPluginVersion": "3.2.1"
|
|
103
103
|
},
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "3d6e2af3cf55ad63b7bb388c005adf4b923eb383"
|
|
105
105
|
}
|