create-principles-disciple 1.122.0 → 1.122.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.
Files changed (82) hide show
  1. package/console/package.json +1 -1
  2. package/core/dist/runtime-v2/__tests__/admission-gate.test.js +23 -6
  3. package/core/dist/runtime-v2/__tests__/admission-gate.test.js.map +1 -1
  4. package/core/dist/runtime-v2/__tests__/context-payload-validation.test.js +1 -1
  5. package/core/dist/runtime-v2/__tests__/context-payload-validation.test.js.map +1 -1
  6. package/core/dist/runtime-v2/__tests__/evidence-guards.test.js +2 -2
  7. package/core/dist/runtime-v2/__tests__/evidence-guards.test.js.map +1 -1
  8. package/core/dist/runtime-v2/__tests__/golden-path-diagnostician-e2e.test.js +1 -1
  9. package/core/dist/runtime-v2/__tests__/golden-path-diagnostician-e2e.test.js.map +1 -1
  10. package/core/dist/runtime-v2/__tests__/pain-evidence-contract.test.js +3 -3
  11. package/core/dist/runtime-v2/__tests__/pain-evidence-contract.test.js.map +1 -1
  12. package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.js +1 -1
  13. package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.js.map +1 -1
  14. package/core/dist/runtime-v2/admission-gate.d.ts +8 -1
  15. package/core/dist/runtime-v2/admission-gate.d.ts.map +1 -1
  16. package/core/dist/runtime-v2/admission-gate.js +14 -0
  17. package/core/dist/runtime-v2/admission-gate.js.map +1 -1
  18. package/core/dist/runtime-v2/context-payload.d.ts +9 -3
  19. package/core/dist/runtime-v2/context-payload.d.ts.map +1 -1
  20. package/core/dist/runtime-v2/context-payload.js +3 -1
  21. package/core/dist/runtime-v2/context-payload.js.map +1 -1
  22. package/core/dist/runtime-v2/evidence-triage/__tests__/observation-resolver.test.js +2 -2
  23. package/core/dist/runtime-v2/evidence-triage/__tests__/observation-resolver.test.js.map +1 -1
  24. package/core/dist/runtime-v2/evidence-triage/observation-resolver.d.ts +1 -1
  25. package/core/dist/runtime-v2/evidence-triage/observation-resolver.d.ts.map +1 -1
  26. package/core/dist/runtime-v2/evidence-triage/observation-resolver.js +2 -2
  27. package/core/dist/runtime-v2/evidence-triage/observation-resolver.js.map +1 -1
  28. package/core/dist/runtime-v2/evidence-triage/types.d.ts +1 -1
  29. package/core/dist/runtime-v2/evidence-triage/types.d.ts.map +1 -1
  30. package/core/dist/runtime-v2/evolution/evolution-types.d.ts +8 -4
  31. package/core/dist/runtime-v2/evolution/evolution-types.d.ts.map +1 -1
  32. package/core/dist/runtime-v2/evolution/evolution-types.js +3 -1
  33. package/core/dist/runtime-v2/evolution/evolution-types.js.map +1 -1
  34. package/core/dist/runtime-v2/index.d.ts +2 -0
  35. package/core/dist/runtime-v2/index.d.ts.map +1 -1
  36. package/core/dist/runtime-v2/index.js +2 -0
  37. package/core/dist/runtime-v2/index.js.map +1 -1
  38. package/core/dist/runtime-v2/pain-signal-bridge.d.ts +2 -0
  39. package/core/dist/runtime-v2/pain-signal-bridge.d.ts.map +1 -1
  40. package/core/dist/runtime-v2/pain-signal-bridge.js +4 -3
  41. package/core/dist/runtime-v2/pain-signal-bridge.js.map +1 -1
  42. package/core/dist/runtime-v2/pain-to-principle-service.d.ts +1 -0
  43. package/core/dist/runtime-v2/pain-to-principle-service.d.ts.map +1 -1
  44. package/core/dist/runtime-v2/pain-to-principle-service.js +1 -0
  45. package/core/dist/runtime-v2/pain-to-principle-service.js.map +1 -1
  46. package/core/dist/runtime-v2/runner/__tests__/pain-signal-bridge-admission.test.js +6 -6
  47. package/core/dist/runtime-v2/runner/__tests__/pain-signal-bridge-admission.test.js.map +1 -1
  48. package/core/dist/runtime-v2/store/context/sqlite-context-assembler.d.ts.map +1 -1
  49. package/core/dist/runtime-v2/store/context/sqlite-context-assembler.js +25 -5
  50. package/core/dist/runtime-v2/store/context/sqlite-context-assembler.js.map +1 -1
  51. package/core/dist/runtime-v2/store/context/sqlite-context-assembler.test.js +38 -9
  52. package/core/dist/runtime-v2/store/context/sqlite-context-assembler.test.js.map +1 -1
  53. package/core/dist/runtime-v2/task-status.d.ts +2 -1
  54. package/core/dist/runtime-v2/task-status.d.ts.map +1 -1
  55. package/core/dist/runtime-v2/task-status.js +5 -1
  56. package/core/dist/runtime-v2/task-status.js.map +1 -1
  57. package/host-runtime/dist/governance-observation-store.d.ts +7 -0
  58. package/host-runtime/dist/governance-observation-store.js +9 -0
  59. package/host-runtime/dist/governance-signal-admission.d.ts +228 -0
  60. package/host-runtime/dist/governance-signal-admission.js +841 -0
  61. package/host-runtime/dist/index.d.ts +1 -0
  62. package/host-runtime/dist/index.js +1 -0
  63. package/host-runtime/dist/production-pain-evidence.d.ts +60 -0
  64. package/host-runtime/dist/production-pain-evidence.js +73 -10
  65. package/package.json +2 -2
  66. package/pd-cli/dist/commands/codex-reconcile.d.ts +22 -0
  67. package/pd-cli/dist/commands/codex-reconcile.d.ts.map +1 -0
  68. package/pd-cli/dist/commands/codex-reconcile.js +61 -0
  69. package/pd-cli/dist/commands/codex-reconcile.js.map +1 -0
  70. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  71. package/pd-cli/dist/commands/pain-retry.js +4 -2
  72. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  73. package/pd-cli/dist/index.js +23 -0
  74. package/pd-cli/dist/index.js.map +1 -1
  75. package/plugin/dist/bundle.js +505 -505
  76. package/plugin/dist/core/signal-collector-host.d.ts +11 -0
  77. package/plugin/dist/core/signal-keyword-store.d.ts +12 -35
  78. package/plugin/dist/governance-audit.js +106 -106
  79. package/plugin/dist/hooks/triage-adapter.d.ts +1 -1
  80. package/plugin/dist/rulehost-evidence.js +112 -112
  81. package/plugin/openclaw.plugin.json +1 -1
  82. package/plugin/package.json +2 -2
@@ -122,6 +122,13 @@ export type PromoteGovernanceEvidenceResult = {
122
122
  nextAction: string;
123
123
  };
124
124
  export type ObservationDatabaseFactory = (databasePath: string) => Database.Database;
125
+ /**
126
+ * Shared with the sibling governance-signal-admission module (Slice B): both
127
+ * modules own separate governance_* tables in the same trajectory.db, and the
128
+ * admission/reconciliation paths read observation-owned tables (promotion
129
+ * tails). One open must make the whole governance schema ready.
130
+ */
131
+ export declare function ensureGovernanceSchema(db: Database.Database): void;
125
132
  type Degradation = {
126
133
  ok: false;
127
134
  reason: string;
@@ -178,6 +178,15 @@ function ensureGovernanceObservationSchema(db) {
178
178
  }
179
179
  })();
180
180
  }
181
+ /**
182
+ * Shared with the sibling governance-signal-admission module (Slice B): both
183
+ * modules own separate governance_* tables in the same trajectory.db, and the
184
+ * admission/reconciliation paths read observation-owned tables (promotion
185
+ * tails). One open must make the whole governance schema ready.
186
+ */
187
+ export function ensureGovernanceSchema(db) {
188
+ ensureGovernanceObservationSchema(db);
189
+ }
181
190
  function openStore(workspaceDir, factory) {
182
191
  const dbPath = path.join(workspaceDir, '.state', 'trajectory.db');
183
192
  if (!fs.existsSync(dbPath)) {
@@ -0,0 +1,228 @@
1
+ import { type SignalCollectorOutput, type UnifiedKeywordStore } from '@principles/core/runtime-v2';
2
+ import { type ObservationDatabaseFactory } from './governance-observation-store.js';
3
+ export declare const GOVERNANCE_STRONG_PAIN_SCORE = 70;
4
+ export declare const GOVERNANCE_STRONG_RATE_LIMIT_PER_HOUR = 5;
5
+ export declare const GOVERNANCE_RATE_LIMIT_WINDOW_MS: number;
6
+ type Degradation = {
7
+ ok: false;
8
+ reason: string;
9
+ nextAction: string;
10
+ };
11
+ /** learned 词进入高精度 deterministic path 的权重阈值(仅 seed/owner_promoted; llm_learned 恒 ambiguous) */
12
+ export declare const HIGH_PRECISION_LEARNED_WEIGHT = 0.7;
13
+ /** 高精度纠正短语 overlay(已验证的确定性 STRONG 路径,不属于 learner seed 集) */
14
+ export declare const HIGH_PRECISION_CORRECTION_OVERLAY: readonly (readonly [string, number])[];
15
+ /** empathy seed overlay(检测行为不变) */
16
+ export declare const EMPATHY_SEED_OVERLAY: readonly (readonly [string, number])[];
17
+ export declare function buildSharedSeedKeywordStore(): UnifiedKeywordStore;
18
+ export interface SharedCorrectionKeywordStore {
19
+ resolve(): UnifiedKeywordStore;
20
+ stats(): {
21
+ totalTerms: number;
22
+ learnedTerms: number;
23
+ lastReloadedAt: string | null;
24
+ };
25
+ }
26
+ export interface SharedKeywordStoreOptions {
27
+ readonly workspaceDir: string;
28
+ /** Bounded degradation sink (rc-9); defaults to silent-with-stats. */
29
+ readonly onDegradation?: (code: string, message: string) => void;
30
+ readonly logger?: {
31
+ debug?: (msg: string) => void;
32
+ };
33
+ }
34
+ /**
35
+ * Host-neutral live keyword store (extracted from the OpenClaw-only wrapper,
36
+ * SPEC §12): reads the per-workspace `<workspace>/.state/correction_keywords.json`
37
+ * learner projection with mtime-based refresh, falling back to the seed store.
38
+ * OpenClaw and Codex resolve detection through this SAME store. The store file
39
+ * must stay a direct child of the workspace state directory (boundary guard).
40
+ */
41
+ export declare function createSharedCorrectionKeywordStore(options: SharedKeywordStoreOptions): SharedCorrectionKeywordStore;
42
+ export interface CorrectionDetectionResult {
43
+ readonly output: SignalCollectorOutput;
44
+ readonly ruleVersion: number;
45
+ }
46
+ /**
47
+ * The shared synchronous high-precision correction detection (SPEC §12):
48
+ * one keyword store, one rule version, one STRONG classification for both
49
+ * hosts. Codex consumes only the deterministic high-precision path — ambiguous
50
+ * candidates are not signals in a bounded hook (LLM confirmation belongs to
51
+ * hosts that own an async stage).
52
+ */
53
+ export declare function evaluateCorrectionSignal(input: {
54
+ workspaceDir: string;
55
+ text: string;
56
+ sessionId: string;
57
+ detectedAt: string;
58
+ store?: UnifiedKeywordStore;
59
+ onDegradation?: (code: string, message: string) => void;
60
+ }): CorrectionDetectionResult;
61
+ export type GovernanceSignalKind = 'user_correction' | 'tool_failure';
62
+ export interface GovernanceCorrectionCandidate {
63
+ readonly kind: 'user_correction';
64
+ readonly hostKind: 'codex';
65
+ readonly logicalObservationKey: string;
66
+ readonly rolloutIdentity: string;
67
+ readonly rootSessionId: string;
68
+ readonly hostTurnId: string;
69
+ readonly text: string;
70
+ readonly observedAt: string;
71
+ }
72
+ export interface GovernanceToolFailureCandidate {
73
+ readonly kind: 'tool_failure';
74
+ readonly hostKind: 'codex';
75
+ readonly logicalObservationKey: string;
76
+ readonly rolloutIdentity: string;
77
+ readonly rootSessionId: string;
78
+ readonly hostTurnId: string;
79
+ readonly toolName: string;
80
+ /** Host event source (e.g. `codex:post_tool_use`) — identity parity with the live handler. */
81
+ readonly source: string;
82
+ readonly toolInput?: unknown;
83
+ readonly toolOutput?: unknown;
84
+ readonly observedAt: string;
85
+ }
86
+ export type GovernanceSignalCandidate = GovernanceCorrectionCandidate | GovernanceToolFailureCandidate;
87
+ export type GovernanceAdmissionOutcome = {
88
+ disposition: 'admitted';
89
+ kind: GovernanceSignalKind;
90
+ logicalObservationKey: string;
91
+ canonicalPainId: string;
92
+ duplicate: boolean;
93
+ ruleVersion: number | null;
94
+ } | {
95
+ disposition: 'already_admitted';
96
+ kind: GovernanceSignalKind;
97
+ logicalObservationKey: string;
98
+ canonicalPainId: string;
99
+ diagnosticianTaskId: string | null;
100
+ } | {
101
+ disposition: 'not_a_signal';
102
+ kind: 'user_correction';
103
+ logicalObservationKey: string;
104
+ } | {
105
+ disposition: 'not_admitted';
106
+ kind: 'tool_failure';
107
+ logicalObservationKey: string;
108
+ reason: string;
109
+ } | {
110
+ disposition: 'rate_limited';
111
+ kind: 'user_correction';
112
+ logicalObservationKey: string;
113
+ } | Degradation;
114
+ export interface AdmitGovernanceSignalsInput {
115
+ readonly workspaceDir: string;
116
+ readonly candidates: readonly GovernanceSignalCandidate[];
117
+ readonly now?: Date;
118
+ readonly databaseFactory?: ObservationDatabaseFactory;
119
+ readonly keywordStore?: UnifiedKeywordStore;
120
+ readonly onDegradation?: (code: string, message: string) => void;
121
+ }
122
+ export type AdmitGovernanceSignalsResult = {
123
+ ok: true;
124
+ outcomes: readonly GovernanceAdmissionOutcome[];
125
+ } | Degradation;
126
+ /**
127
+ * Admit governance signal candidates. Each candidate commits in its own
128
+ * trajectory.db transaction (marker + pain row + quota together), so one
129
+ * failing candidate never rolls back another's admission.
130
+ */
131
+ export declare function admitGovernanceSignals(input: AdmitGovernanceSignalsInput): AdmitGovernanceSignalsResult;
132
+ export interface EnsureGovernanceTaskInput {
133
+ readonly workspaceDir: string;
134
+ readonly logicalObservationKey: string;
135
+ readonly canonicalPainId: string;
136
+ readonly databaseFactory?: ObservationDatabaseFactory;
137
+ }
138
+ export type EnsureGovernanceTaskResult = {
139
+ ok: true;
140
+ taskId: string;
141
+ created: boolean;
142
+ duplicate: boolean;
143
+ linkRepaired: boolean;
144
+ } | Degradation;
145
+ /**
146
+ * Ensure exactly one pending Diagnostician task exists for an admitted
147
+ * canonical pain (SPEC §13). Idempotent across hook retries, reconciliation,
148
+ * and crash restarts: deterministic task id + task-store PK + marker link.
149
+ * Never awaits an LLM — PainToPrincipleService async mode only enqueues.
150
+ *
151
+ * `linkRepaired` is true ONLY when this call actually wrote the marker task
152
+ * link because the task already existed (Case B recovery). A marker that
153
+ * already carried the link reports linkRepaired=false — no fake repair.
154
+ */
155
+ export declare function ensureGovernanceDiagnosticianTask(input: EnsureGovernanceTaskInput): Promise<EnsureGovernanceTaskResult>;
156
+ export type PromoteAdmittedEvidenceResult = {
157
+ ok: true;
158
+ promoted: number;
159
+ tailState: 'completed' | 'pending';
160
+ } | Degradation;
161
+ /**
162
+ * Promote the bounded evidence window (≤12 preceding turns + trigger + next
163
+ * completed assistant turn) for an admitted pain, using Slice A's promotion
164
+ * substrate with the canonical pain id as the caller-provided pain reference.
165
+ */
166
+ export declare function promoteAdmittedGovernanceEvidence(input: {
167
+ workspaceDir: string;
168
+ rolloutIdentity: string;
169
+ triggerLogicalKey: string;
170
+ canonicalPainId: string;
171
+ databaseFactory?: ObservationDatabaseFactory;
172
+ }): PromoteAdmittedEvidenceResult;
173
+ export interface EnsureGovernanceContinuationInput {
174
+ readonly workspaceDir: string;
175
+ readonly logicalObservationKey: string;
176
+ readonly canonicalPainId: string;
177
+ readonly databaseFactory?: ObservationDatabaseFactory;
178
+ }
179
+ export type EnsureGovernanceContinuationResult = {
180
+ ok: true;
181
+ taskId: string;
182
+ taskCreated: boolean;
183
+ linkRepaired: boolean;
184
+ promoted: number;
185
+ tailState: 'completed' | 'pending';
186
+ } | {
187
+ ok: false;
188
+ reason: string;
189
+ nextAction: string;
190
+ };
191
+ /**
192
+ * Given an admitted canonical pain (identified by its marker), ensure both
193
+ * the Diagnostician task AND the evidence promotion exist idempotently.
194
+ * Single ensure path for both fresh admits and crash recovery (already_admitted
195
+ * redelivery). The marker row carries rollout_identity so the function is
196
+ * self-contained (caller only needs workspaceDir, logicalObservationKey, painId).
197
+ */
198
+ export declare function ensureGovernanceContinuation(input: EnsureGovernanceContinuationInput): Promise<EnsureGovernanceContinuationResult>;
199
+ export interface ReconcileGovernanceContinuationInput {
200
+ readonly workspaceDir: string;
201
+ /** Bounded work per pass (default 50 admitted pains). */
202
+ readonly limit?: number;
203
+ readonly databaseFactory?: ObservationDatabaseFactory;
204
+ }
205
+ export interface ReconcileGovernanceContinuationResult {
206
+ readonly ok: boolean;
207
+ readonly reason?: string;
208
+ readonly nextAction?: string;
209
+ readonly tasksEnsured: number;
210
+ readonly linksRepaired: number;
211
+ readonly pendingTails: number;
212
+ readonly completedTails: number;
213
+ readonly staleTails: number;
214
+ readonly degradations: readonly string[];
215
+ }
216
+ /**
217
+ * Narrow idempotent reconciliation between the trajectory admission markers
218
+ * and the Runtime V2 task store (separate SQLite databases — no cross-store
219
+ * transaction exists, SPEC §13). Recovers:
220
+ * - Case A: pain admitted, crash before task creation → create the task now;
221
+ * - Case B: task exists, crash before the link write → repair the link;
222
+ * - Case C: pain+task, crash before promotion → promote evidence now;
223
+ * - Case D: promotion started → pending tail → retry completion once; stale
224
+ * tails are reported (never silently dropped).
225
+ * Not a background worker — Slice C's Companion worker and the CLI call this.
226
+ */
227
+ export declare function reconcileGovernanceContinuation(input: ReconcileGovernanceContinuationInput): Promise<ReconcileGovernanceContinuationResult>;
228
+ export {};