principles-disciple 1.7.6 → 1.7.8

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 (106) hide show
  1. package/dist/commands/context.js +5 -15
  2. package/dist/commands/evolution-status.js +2 -9
  3. package/dist/commands/export.js +61 -8
  4. package/dist/commands/nocturnal-review.d.ts +24 -0
  5. package/dist/commands/nocturnal-review.js +265 -0
  6. package/dist/commands/nocturnal-rollout.d.ts +27 -0
  7. package/dist/commands/nocturnal-rollout.js +671 -0
  8. package/dist/commands/nocturnal-train.d.ts +25 -0
  9. package/dist/commands/nocturnal-train.js +919 -0
  10. package/dist/commands/pain.js +8 -21
  11. package/dist/constants/tools.d.ts +2 -2
  12. package/dist/constants/tools.js +1 -1
  13. package/dist/core/adaptive-thresholds.d.ts +186 -0
  14. package/dist/core/adaptive-thresholds.js +300 -0
  15. package/dist/core/config.d.ts +2 -38
  16. package/dist/core/config.js +6 -61
  17. package/dist/core/event-log.d.ts +1 -2
  18. package/dist/core/event-log.js +0 -3
  19. package/dist/core/evolution-engine.js +1 -21
  20. package/dist/core/evolution-reducer.d.ts +7 -1
  21. package/dist/core/evolution-reducer.js +56 -4
  22. package/dist/core/evolution-types.d.ts +61 -9
  23. package/dist/core/evolution-types.js +31 -9
  24. package/dist/core/external-training-contract.d.ts +276 -0
  25. package/dist/core/external-training-contract.js +269 -0
  26. package/dist/core/local-worker-routing.d.ts +175 -0
  27. package/dist/core/local-worker-routing.js +525 -0
  28. package/dist/core/model-deployment-registry.d.ts +218 -0
  29. package/dist/core/model-deployment-registry.js +503 -0
  30. package/dist/core/model-training-registry.d.ts +295 -0
  31. package/dist/core/model-training-registry.js +475 -0
  32. package/dist/core/nocturnal-arbiter.d.ts +159 -0
  33. package/dist/core/nocturnal-arbiter.js +534 -0
  34. package/dist/core/nocturnal-candidate-scoring.d.ts +137 -0
  35. package/dist/core/nocturnal-candidate-scoring.js +266 -0
  36. package/dist/core/nocturnal-compliance.d.ts +175 -0
  37. package/dist/core/nocturnal-compliance.js +824 -0
  38. package/dist/core/nocturnal-dataset.d.ts +224 -0
  39. package/dist/core/nocturnal-dataset.js +443 -0
  40. package/dist/core/nocturnal-executability.d.ts +85 -0
  41. package/dist/core/nocturnal-executability.js +331 -0
  42. package/dist/core/nocturnal-export.d.ts +124 -0
  43. package/dist/core/nocturnal-export.js +275 -0
  44. package/dist/core/nocturnal-paths.d.ts +124 -0
  45. package/dist/core/nocturnal-paths.js +214 -0
  46. package/dist/core/nocturnal-trajectory-extractor.d.ts +242 -0
  47. package/dist/core/nocturnal-trajectory-extractor.js +307 -0
  48. package/dist/core/nocturnal-trinity.d.ts +311 -0
  49. package/dist/core/nocturnal-trinity.js +880 -0
  50. package/dist/core/paths.d.ts +6 -0
  51. package/dist/core/paths.js +6 -0
  52. package/dist/core/principle-training-state.d.ts +121 -0
  53. package/dist/core/principle-training-state.js +321 -0
  54. package/dist/core/promotion-gate.d.ts +238 -0
  55. package/dist/core/promotion-gate.js +529 -0
  56. package/dist/core/session-tracker.d.ts +10 -0
  57. package/dist/core/session-tracker.js +14 -0
  58. package/dist/core/shadow-observation-registry.d.ts +217 -0
  59. package/dist/core/shadow-observation-registry.js +308 -0
  60. package/dist/core/training-program.d.ts +233 -0
  61. package/dist/core/training-program.js +433 -0
  62. package/dist/core/trajectory.d.ts +95 -1
  63. package/dist/core/trajectory.js +220 -6
  64. package/dist/core/workspace-context.d.ts +0 -6
  65. package/dist/core/workspace-context.js +0 -12
  66. package/dist/hooks/bash-risk.d.ts +6 -6
  67. package/dist/hooks/bash-risk.js +8 -8
  68. package/dist/hooks/gate-block-helper.js +1 -1
  69. package/dist/hooks/gate.d.ts +1 -1
  70. package/dist/hooks/gate.js +2 -2
  71. package/dist/hooks/gfi-gate.d.ts +3 -3
  72. package/dist/hooks/gfi-gate.js +15 -14
  73. package/dist/hooks/pain.js +6 -9
  74. package/dist/hooks/progressive-trust-gate.d.ts +21 -49
  75. package/dist/hooks/progressive-trust-gate.js +51 -204
  76. package/dist/hooks/prompt.d.ts +11 -11
  77. package/dist/hooks/prompt.js +158 -72
  78. package/dist/hooks/subagent.js +43 -6
  79. package/dist/i18n/commands.js +8 -8
  80. package/dist/index.js +129 -28
  81. package/dist/service/evolution-worker.d.ts +42 -4
  82. package/dist/service/evolution-worker.js +321 -13
  83. package/dist/service/nocturnal-runtime.d.ts +183 -0
  84. package/dist/service/nocturnal-runtime.js +352 -0
  85. package/dist/service/nocturnal-service.d.ts +163 -0
  86. package/dist/service/nocturnal-service.js +787 -0
  87. package/dist/service/nocturnal-target-selector.d.ts +145 -0
  88. package/dist/service/nocturnal-target-selector.js +315 -0
  89. package/dist/service/phase3-input-filter.d.ts +2 -23
  90. package/dist/service/phase3-input-filter.js +3 -27
  91. package/dist/service/runtime-summary-service.d.ts +0 -10
  92. package/dist/service/runtime-summary-service.js +1 -54
  93. package/dist/tools/deep-reflect.js +2 -1
  94. package/dist/types/event-types.d.ts +2 -10
  95. package/dist/types/runtime-summary.d.ts +1 -8
  96. package/dist/types.d.ts +0 -3
  97. package/dist/types.js +0 -2
  98. package/openclaw.plugin.json +1 -1
  99. package/package.json +1 -1
  100. package/templates/langs/en/skills/pd-mentor/SKILL.md +5 -5
  101. package/templates/langs/zh/skills/pd-mentor/SKILL.md +5 -5
  102. package/templates/pain_settings.json +0 -6
  103. package/dist/commands/trust.d.ts +0 -4
  104. package/dist/commands/trust.js +0 -78
  105. package/dist/core/trust-engine.d.ts +0 -96
  106. package/dist/core/trust-engine.js +0 -286
@@ -0,0 +1,266 @@
1
+ /**
2
+ * Nocturnal Candidate Scoring — Deterministic Tournament Selection
3
+ * ============================================================
4
+ *
5
+ * PURPOSE: Score Trinity candidates and run deterministic tournament selection
6
+ * to choose the best candidate for artifact generation.
7
+ *
8
+ * DESIGN CONSTRAINTS:
9
+ * - Scoring is deterministic: same inputs → same winner
10
+ * - Tie-break rules are stable and explicit
11
+ * - No randomness in ranking or selection
12
+ * - Winner is always the highest-scoring candidate
13
+ * - Thresholds provide minimum quality gates
14
+ * - Failed threshold candidates are excluded from tournament
15
+ *
16
+ * SCORING COMPONENTS:
17
+ * - schema completeness: candidate has all required fields
18
+ * - principle alignment: candidate aligns with target principle
19
+ * - executability: candidate describes an actionable next step
20
+ * - boundedness: candidate is specific and bounded
21
+ * - confidence/consistency: candidate's internal consistency
22
+ *
23
+ * PHASE 6 ONLY — No real training, no automatic deployment
24
+ */
25
+ /**
26
+ * Default scoring weights (must sum to 1.0).
27
+ */
28
+ export const DEFAULT_SCORING_WEIGHTS = {
29
+ schemaCompleteness: 0.15,
30
+ principleAlignment: 0.30,
31
+ executability: 0.20,
32
+ boundedness: 0.20,
33
+ confidence: 0.15,
34
+ };
35
+ // ---------------------------------------------------------------------------
36
+ // Scoring Logic
37
+ // ---------------------------------------------------------------------------
38
+ /**
39
+ * Score a single Dreamer candidate + Philosopher judgment pair.
40
+ *
41
+ * @param candidate - Dreamer candidate
42
+ * @param judgment - Philosopher judgment
43
+ * @param weights - Scoring weights
44
+ * @returns Individual scores
45
+ */
46
+ export function scoreCandidate(candidate, judgment, weights = DEFAULT_SCORING_WEIGHTS) {
47
+ // Schema completeness: all required fields present and non-empty
48
+ let schemaCompleteness = 1.0;
49
+ if (!candidate.badDecision || candidate.badDecision.trim().length === 0)
50
+ schemaCompleteness -= 0.2;
51
+ if (!candidate.betterDecision || candidate.betterDecision.trim().length === 0)
52
+ schemaCompleteness -= 0.2;
53
+ if (!candidate.rationale || candidate.rationale.trim().length === 0)
54
+ schemaCompleteness -= 0.2;
55
+ if (typeof candidate.confidence !== 'number' || candidate.confidence < 0 || candidate.confidence > 1)
56
+ schemaCompleteness -= 0.2;
57
+ if (candidate.badDecision && candidate.betterDecision && candidate.badDecision.trim() === candidate.betterDecision.trim())
58
+ schemaCompleteness -= 0.2;
59
+ schemaCompleteness = Math.max(0, schemaCompleteness);
60
+ // Principle alignment: from Philosopher judgment
61
+ const principleAlignment = judgment.principleAligned ? 1.0 : 0.3;
62
+ // Executability: betterDecision contains actionable verb
63
+ const actionableVerbs = ['read', 'check', 'verify', 'edit', 'write', 'search', 'grep', 'review', 'analyze', 'diagnose', 'debug', 'inspect', 'examine', 'test'];
64
+ const hasActionableVerb = candidate.betterDecision
65
+ ? actionableVerbs.some((v) => candidate.betterDecision.toLowerCase().includes(v))
66
+ : false;
67
+ const executability = hasActionableVerb ? 1.0 : 0.4;
68
+ // Boundedness: specific and constrained
69
+ let boundedness = 0.5;
70
+ // Specific: mentions specific targets (files, tools, etc.)
71
+ const betterDecisionStr = candidate.betterDecision ?? '';
72
+ const hasSpecificTarget = /[a-zA-Z0-9_\-]+\.(ts|js|json|md|yml|yaml|sh|py|go|rs)/.test(betterDecisionStr);
73
+ if (hasSpecificTarget)
74
+ boundedness += 0.2;
75
+ // Not too generic
76
+ const genericPatterns = [
77
+ /\bsomething\b/i,
78
+ /\bsomething else\b/i,
79
+ /\bit\b/i,
80
+ /\bthe thing\b/i,
81
+ ];
82
+ const isGeneric = genericPatterns.some((pattern) => pattern.test(betterDecisionStr));
83
+ if (isGeneric)
84
+ boundedness -= 0.3;
85
+ // Not too long (如果 multi-step vagueness)
86
+ if (betterDecisionStr.length > 200)
87
+ boundedness -= 0.1;
88
+ boundedness = Math.max(0, Math.min(1, boundedness));
89
+ // Confidence: from Dreamer's confidence, adjusted by consistency
90
+ const baseConfidence = typeof candidate.confidence === 'number' ? candidate.confidence : 0.5;
91
+ // Slight consistency check: Philosopher score should correlate with confidence
92
+ const consistency = 1.0 - Math.abs(baseConfidence - judgment.score);
93
+ const confidence = baseConfidence * 0.7 + consistency * 0.3;
94
+ // Calculate aggregate
95
+ const aggregate = schemaCompleteness * weights.schemaCompleteness +
96
+ principleAlignment * weights.principleAlignment +
97
+ executability * weights.executability +
98
+ boundedness * weights.boundedness +
99
+ confidence * weights.confidence;
100
+ return {
101
+ schemaCompleteness: Math.round(schemaCompleteness * 100) / 100,
102
+ principleAlignment: Math.round(principleAlignment * 100) / 100,
103
+ executability: Math.round(executability * 100) / 100,
104
+ boundedness: Math.round(boundedness * 100) / 100,
105
+ confidence: Math.round(confidence * 100) / 100,
106
+ aggregate: Math.round(aggregate * 100) / 100,
107
+ };
108
+ }
109
+ /**
110
+ * Check if candidate passes minimum thresholds.
111
+ *
112
+ * @param scores - Candidate scores
113
+ * @param thresholds - Minimum threshold values
114
+ * @returns Tuple of [passed, failedThresholdNames]
115
+ */
116
+ export function checkThresholds(scores, thresholds) {
117
+ const failedThresholds = [];
118
+ if (scores.schemaCompleteness < thresholds.schemaCompletenessMin) {
119
+ failedThresholds.push(`schemaCompleteness (${scores.schemaCompleteness} < ${thresholds.schemaCompletenessMin})`);
120
+ }
121
+ if (scores.principleAlignment < thresholds.principleAlignmentMin) {
122
+ failedThresholds.push(`principleAlignment (${scores.principleAlignment} < ${thresholds.principleAlignmentMin})`);
123
+ }
124
+ if (scores.executability < thresholds.executabilityMin) {
125
+ failedThresholds.push(`executability (${scores.executability} < ${thresholds.executabilityMin})`);
126
+ }
127
+ if (scores.boundedness < thresholds.boundednessMin) {
128
+ failedThresholds.push(`boundedness (${scores.boundedness} < ${thresholds.boundednessMin})`);
129
+ }
130
+ if (scores.confidence < thresholds.confidenceMin) {
131
+ failedThresholds.push(`confidence (${scores.confidence} < ${thresholds.confidenceMin})`);
132
+ }
133
+ if (scores.aggregate < thresholds.aggregateMin) {
134
+ failedThresholds.push(`aggregate (${scores.aggregate} < ${thresholds.aggregateMin})`);
135
+ }
136
+ return [failedThresholds.length === 0, failedThresholds];
137
+ }
138
+ /**
139
+ * Score and rank all candidates deterministically.
140
+ *
141
+ * @param candidates - Dreamer candidates
142
+ * @param judgments - Philosopher judgments (aligned by candidateIndex)
143
+ * @param thresholds - Minimum thresholds
144
+ * @param weights - Scoring weights
145
+ * @returns All scored and ranked candidates
146
+ */
147
+ export function rankCandidates(candidates, judgments, thresholds, weights = DEFAULT_SCORING_WEIGHTS) {
148
+ const trace = [];
149
+ trace.push({
150
+ step: 'Input Validation',
151
+ details: `Received ${candidates.length} candidates and ${judgments.length} judgments`,
152
+ });
153
+ // Score each candidate
154
+ const scored = [];
155
+ for (const candidate of candidates) {
156
+ const judgment = judgments.find((j) => j.candidateIndex === candidate.candidateIndex);
157
+ if (!judgment) {
158
+ trace.push({
159
+ step: `Candidate ${candidate.candidateIndex}`,
160
+ details: 'Skipped - no matching judgment found',
161
+ });
162
+ continue;
163
+ }
164
+ const scores = scoreCandidate(candidate, judgment, weights);
165
+ const [passed, failed] = checkThresholds(scores, thresholds);
166
+ scored.push({
167
+ candidateIndex: candidate.candidateIndex,
168
+ candidate,
169
+ judgment,
170
+ scores,
171
+ rank: 0, // Will be set after sorting
172
+ thresholdPassed: passed,
173
+ failedThresholds: failed,
174
+ });
175
+ trace.push({
176
+ step: `Candidate ${candidate.candidateIndex} Scored`,
177
+ details: `aggregate=${scores.aggregate.toFixed(2)}, thresholdPassed=${passed}`,
178
+ });
179
+ }
180
+ // Sort by: thresholdPassed DESC, aggregate DESC, candidateIndex ASC (for stability)
181
+ scored.sort((a, b) => {
182
+ // Threshold-passed candidates come first
183
+ if (a.thresholdPassed !== b.thresholdPassed) {
184
+ return a.thresholdPassed ? -1 : 1;
185
+ }
186
+ // Higher aggregate score wins
187
+ if (a.scores.aggregate !== b.scores.aggregate) {
188
+ return b.scores.aggregate - a.scores.aggregate;
189
+ }
190
+ // Lower candidateIndex wins ties (stability)
191
+ return a.candidateIndex - b.candidateIndex;
192
+ });
193
+ // Assign ranks
194
+ let currentRank = 1;
195
+ let currentAggregate = -1;
196
+ for (const candidate of scored) {
197
+ if (candidate.scores.aggregate !== currentAggregate) {
198
+ currentRank = scored.indexOf(candidate) + 1;
199
+ currentAggregate = candidate.scores.aggregate;
200
+ }
201
+ candidate.rank = currentRank;
202
+ }
203
+ trace.push({
204
+ step: 'Ranking Complete',
205
+ details: `Final order: ${scored.map((c) => `C${c.candidateIndex}(rank=${c.rank},agg=${c.scores.aggregate.toFixed(2)})`).join(', ')}`,
206
+ });
207
+ return scored;
208
+ }
209
+ /**
210
+ * Run tournament selection to choose the best candidate.
211
+ *
212
+ * @param candidates - Dreamer candidates
213
+ * @param judgments - Philosopher judgments
214
+ * @param thresholds - Minimum thresholds
215
+ * @param weights - Scoring weights
216
+ * @returns Tournament result with winner
217
+ */
218
+ export function runTournament(candidates, judgments, thresholds, weights = DEFAULT_SCORING_WEIGHTS) {
219
+ const trace = [];
220
+ if (candidates.length === 0 || judgments.length === 0) {
221
+ return {
222
+ success: false,
223
+ winner: null,
224
+ rankedCandidates: [],
225
+ trace: [{ step: 'Validation', details: 'No candidates or judgments provided' }],
226
+ failureReason: 'No candidates or judgments provided',
227
+ };
228
+ }
229
+ trace.push({
230
+ step: 'Tournament Start',
231
+ details: `${candidates.length} candidates in tournament`,
232
+ });
233
+ // Rank candidates
234
+ const ranked = rankCandidates(candidates, judgments, thresholds, weights);
235
+ trace.push({
236
+ step: 'Threshold Check',
237
+ details: `${ranked.filter((c) => c.thresholdPassed).length} candidates passed thresholds`,
238
+ });
239
+ // Filter to threshold-passed candidates for winner determination
240
+ const eligible = ranked.filter((c) => c.thresholdPassed);
241
+ if (eligible.length === 0) {
242
+ trace.push({
243
+ step: 'No Winner',
244
+ details: 'All candidates failed threshold check',
245
+ });
246
+ return {
247
+ success: false,
248
+ winner: null,
249
+ rankedCandidates: ranked,
250
+ trace,
251
+ failureReason: 'All candidates failed threshold check',
252
+ };
253
+ }
254
+ // Winner is rank 1
255
+ const winner = eligible[0];
256
+ trace.push({
257
+ step: 'Winner Selected',
258
+ details: `Candidate ${winner.candidateIndex} wins with aggregate score ${winner.scores.aggregate.toFixed(2)}`,
259
+ });
260
+ return {
261
+ success: true,
262
+ winner,
263
+ rankedCandidates: ranked,
264
+ trace,
265
+ };
266
+ }
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Nocturnal Compliance Engine — Opportunity-Based Principle Evaluation
3
+ * =====================================================================
4
+ *
5
+ * Replaces session-average compliance with opportunity-based compliance.
6
+ *
7
+ * CORE CONCEPTS:
8
+ *
9
+ * Opportunity — a session context where a principle COULD have been applied.
10
+ * An opportunity exists when the agent's action (or planned action)
11
+ * falls within the principle's applicability scope.
12
+ *
13
+ * Compliance — the principle was followed in an opportunity.
14
+ * Determined by absence of violation signals, not presence of
15
+ * positive confirmation (avoids LLM scoring).
16
+ *
17
+ * Violation — strong evidence the principle was NOT followed.
18
+ * Detected through deterministic event signals (pain, tool failures,
19
+ * gate blocks) — no LLM involved.
20
+ *
21
+ * Dilution prevention — compliance is computed ONLY over sessions where the
22
+ * principle had an opportunity. Unrelated sessions
23
+ * (where T-05's risky operations never occurred) do NOT
24
+ * dilute the compliance rate.
25
+ *
26
+ * DESIGN CONSTRAINTS (Phase 1):
27
+ * - T-xx principles only (deterministic / weak-heuristic evaluability)
28
+ * - No P_xxx automation (requires detector metadata — Task 1.3 scope)
29
+ * - No LLM-based scoring
30
+ * - No training logic
31
+ *
32
+ * FILE: No file persistence — stateless computation over event stream.
33
+ * Caller is responsible for writing results to principle-training-state.ts.
34
+ */
35
+ /**
36
+ * Session events extracted from the event log.
37
+ * Compatible with EventLogEntry from event-types.ts.
38
+ */
39
+ export interface SessionEvents {
40
+ sessionId: string;
41
+ toolCalls: ToolCallRecord[];
42
+ painSignals: PainSignalRecord[];
43
+ gateBlocks: GateBlockRecord[];
44
+ userCorrections: UserCorrectionRecord[];
45
+ planApprovals: PlanApprovalRecord[];
46
+ }
47
+ export interface ToolCallRecord {
48
+ toolName: string;
49
+ filePath?: string;
50
+ outcome: 'success' | 'failure' | 'blocked';
51
+ errorType?: string;
52
+ errorMessage?: string;
53
+ }
54
+ export interface PainSignalRecord {
55
+ source: string;
56
+ score: number;
57
+ severity?: 'mild' | 'moderate' | 'severe';
58
+ reason?: string;
59
+ }
60
+ export interface GateBlockRecord {
61
+ toolName: string;
62
+ filePath?: string;
63
+ reason: string;
64
+ }
65
+ export interface UserCorrectionRecord {
66
+ correctionCue?: string;
67
+ }
68
+ export interface PlanApprovalRecord {
69
+ toolName: string;
70
+ filePath?: string;
71
+ }
72
+ /**
73
+ * The result of compliance computation for one principle.
74
+ */
75
+ export interface ComplianceResult {
76
+ principleId: string;
77
+ /** Number of sessions/events where this principle had an applicable opportunity */
78
+ applicableOpportunityCount: number;
79
+ /** Number of opportunities where violation signals were detected */
80
+ observedViolationCount: number;
81
+ /** complianceRate = (opportunities - violations) / opportunities; 0 if none */
82
+ complianceRate: number;
83
+ /**
84
+ * Violation trend:
85
+ * +1 = violations increasing (worsening)
86
+ * 0 = stable
87
+ * -1 = violations decreasing (improving)
88
+ */
89
+ violationTrend: number;
90
+ /**
91
+ * Explanation of why the result is what it is.
92
+ * For debugging, observability, and reviewer verification.
93
+ */
94
+ explanation: string;
95
+ }
96
+ /**
97
+ * Opportunity detection result for a single session.
98
+ */
99
+ interface OpportunityMatch {
100
+ applicable: boolean;
101
+ reason: string;
102
+ }
103
+ /**
104
+ * Violation detection result for a session with applicable opportunity.
105
+ */
106
+ interface ViolationMatch {
107
+ violated: boolean;
108
+ reason: string;
109
+ }
110
+ /**
111
+ * Detects whether a given session presents an APPLICABLE OPPORTUNITY
112
+ * for a specific T-xx principle.
113
+ *
114
+ * An opportunity exists when the session context falls within the
115
+ * principle's applicability scope — regardless of whether the agent
116
+ * followed the principle.
117
+ *
118
+ * IMPORTANT: This does NOT assess compliance. It only answers:
119
+ * "Could the principle have applied here?"
120
+ */
121
+ export declare function detectOpportunity(principleId: string, session: SessionEvents): OpportunityMatch;
122
+ /**
123
+ * Detects whether a principle was VIOLATED in a session where an
124
+ * opportunity was applicable.
125
+ *
126
+ * Returns a ViolationMatch with violated=true if violation signals are present.
127
+ */
128
+ export declare function detectViolation(principleId: string, session: SessionEvents): ViolationMatch;
129
+ /**
130
+ * Computes compliance metrics for a single T-xx principle across a batch of sessions.
131
+ *
132
+ * DILUTION PREVENTION:
133
+ * - Sessions where the principle had NO opportunity are EXCLUDED from
134
+ * applicableOpportunityCount and do not affect complianceRate.
135
+ * - Example: T-05 sessions with no risky operations do not dilute
136
+ * the compliance rate computed from T-05 sessions with gate blocks.
137
+ *
138
+ * TREND COMPUTATION:
139
+ * - Sessions are ordered chronologically (most recent first).
140
+ * - Current window: last 3 applicable sessions.
141
+ * - Previous window: sessions 4-6 (if available).
142
+ * - If either window has < 1 applicable session, trend = 0 (insufficient data).
143
+ * - Otherwise: trend = prevViolationRate - currentViolationRate
144
+ * (+1 = improving, 0 = stable, -1 = worsening).
145
+ */
146
+ export declare function computeCompliance(principleId: string, sessions: SessionEvents[], options?: {
147
+ trendWindowSize?: number;
148
+ }): ComplianceResult;
149
+ /**
150
+ * Computes compliance results for all T-01 through T-09 principles
151
+ * across the provided sessions.
152
+ *
153
+ * Sessions are assumed to be ordered most-recent-first.
154
+ */
155
+ export declare function computeAllCompliance(sessions: SessionEvents[], options?: {
156
+ trendWindowSize?: number;
157
+ }): ComplianceResult[];
158
+ /**
159
+ * Converts raw EventLogEntry[] from event-types.ts into SessionEvents.
160
+ *
161
+ * Groups events by sessionId and maps to the SessionEvents interface.
162
+ * Events with no sessionId are grouped under sessionId = 'unknown'.
163
+ */
164
+ export declare function groupEventsIntoSessions(events: RawEventEntry[]): Map<string, SessionEvents>;
165
+ /**
166
+ * Raw event entry from the events.jsonl log.
167
+ * Compatible with EventLogEntry from event-types.ts.
168
+ */
169
+ export interface RawEventEntry {
170
+ ts: string;
171
+ type: string;
172
+ sessionId?: string;
173
+ data: Record<string, unknown>;
174
+ }
175
+ export {};