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,311 @@
1
+ /**
2
+ * Nocturnal Trinity — Three-Stage Reflection Chain
3
+ * ================================================
4
+ *
5
+ * PURPOSE: Upgrade single-reflector nocturnal sample generation to a
6
+ * Dreamer -> Philosopher -> Scribe Trinity chain that produces higher quality
7
+ * decision-point samples through structured multi-stage reflection.
8
+ *
9
+ * TRINITY STAGES:
10
+ * 1. Dreamer — Generates multiple candidate corrections/alternatives
11
+ * 2. Philosopher — Provides principle-grounded critique and ranking
12
+ * 3. Scribe — Produces the final structured artifact draft using tournament selection
13
+ *
14
+ * DESIGN CONSTRAINTS:
15
+ * - All stage I/O is structured JSON contracts (not prose)
16
+ * - Any malformed stage output fails the entire chain closed
17
+ * - Single-reflector fallback is preserved via useTrinity flag
18
+ * - Trinity mode is configurable but defaults to enabled
19
+ * - Final artifact still passes arbiter + executability validation
20
+ * - Telemetry records chain mode, stage outcomes, candidate counts
21
+ * - Tournament selection is deterministic (same inputs → same winner)
22
+ *
23
+ * RUNTIME ADAPTER:
24
+ * - useStubs=true: uses synchronous stub implementations (no external calls)
25
+ * - useStubs=false: requires a TrinityRuntimeAdapter for real subagent execution
26
+ * - Adapter uses ONLY public plugin runtime APIs (api.runtime.subagent.*)
27
+ */
28
+ import type { NocturnalSessionSnapshot } from './nocturnal-trajectory-extractor.js';
29
+ import { type ScoringWeights, type TournamentTraceEntry } from './nocturnal-candidate-scoring.js';
30
+ import { type ThresholdValues } from './adaptive-thresholds.js';
31
+ /**
32
+ * Interface for Trinity stage invocation.
33
+ * Implementations can use real subagent runtimes or stubs.
34
+ */
35
+ export interface TrinityRuntimeAdapter {
36
+ /**
37
+ * Invoke the Dreamer stage.
38
+ * @param snapshot Session trajectory snapshot
39
+ * @param principleId Target principle ID
40
+ * @param maxCandidates Maximum number of candidates to generate
41
+ * @returns Dreamer output JSON
42
+ */
43
+ invokeDreamer(snapshot: NocturnalSessionSnapshot, principleId: string, maxCandidates: number): Promise<DreamerOutput>;
44
+ /**
45
+ * Invoke the Philosopher stage.
46
+ * @param dreamerOutput Dreamer's output
47
+ * @param principleId Target principle ID
48
+ * @returns Philosopher output JSON
49
+ */
50
+ invokePhilosopher(dreamerOutput: DreamerOutput, principleId: string): Promise<PhilosopherOutput>;
51
+ /**
52
+ * Invoke the Scribe stage.
53
+ * @param dreamerOutput Dreamer's output
54
+ * @param philosopherOutput Philosopher's output
55
+ * @param snapshot Session snapshot
56
+ * @param principleId Target principle ID
57
+ * @param telemetry Running telemetry
58
+ * @param config Trinity config
59
+ * @returns Scribe draft artifact or null if failed
60
+ */
61
+ invokeScribe(dreamerOutput: DreamerOutput, philosopherOutput: PhilosopherOutput, snapshot: NocturnalSessionSnapshot, principleId: string, telemetry: TrinityTelemetry, config: TrinityConfig): Promise<TrinityDraftArtifact | null>;
62
+ /**
63
+ * Clean up any resources used by the adapter.
64
+ * Called after Trinity chain completes (success or failure).
65
+ */
66
+ close?(): Promise<void>;
67
+ }
68
+ /**
69
+ * OpenClaw-backed Trinity runtime adapter.
70
+ * Uses ONLY public plugin runtime APIs (api.runtime.subagent.*).
71
+ * Does NOT depend on OpenClaw internals.
72
+ */
73
+ export declare class OpenClawTrinityRuntimeAdapter implements TrinityRuntimeAdapter {
74
+ private readonly api;
75
+ private readonly stageTimeoutMs;
76
+ constructor(api: OpenClawTrinityRuntimeAdapter['api'], stageTimeoutMs?: number);
77
+ invokeDreamer(snapshot: NocturnalSessionSnapshot, principleId: string, maxCandidates: number): Promise<DreamerOutput>;
78
+ invokePhilosopher(dreamerOutput: DreamerOutput, principleId: string): Promise<PhilosopherOutput>;
79
+ invokeScribe(dreamerOutput: DreamerOutput, philosopherOutput: PhilosopherOutput, snapshot: NocturnalSessionSnapshot, principleId: string, telemetry: TrinityTelemetry, config: TrinityConfig): Promise<TrinityDraftArtifact | null>;
80
+ close(): Promise<void>;
81
+ private extractAssistantText;
82
+ private buildDreamerPrompt;
83
+ private buildPhilosopherPrompt;
84
+ private buildScribePrompt;
85
+ private parseDreamerOutput;
86
+ private parsePhilosopherOutput;
87
+ private parseScribeOutput;
88
+ /**
89
+ * Extract JSON object from text that may contain markdown code blocks.
90
+ */
91
+ private extractJson;
92
+ }
93
+ /**
94
+ * Configuration for Trinity chain execution.
95
+ */
96
+ export interface TrinityConfig {
97
+ /**
98
+ * Whether to use Trinity chain (true) or single-reflector (false).
99
+ * Default: true
100
+ */
101
+ useTrinity: boolean;
102
+ /**
103
+ * Maximum candidates Dreamer should generate.
104
+ * Default: 3
105
+ */
106
+ maxCandidates: number;
107
+ /**
108
+ * Whether to use stub stage outputs (for testing without real model calls).
109
+ * Default: false (real subagent calls via runtimeAdapter)
110
+ */
111
+ useStubs: boolean;
112
+ /**
113
+ * Runtime adapter for real subagent execution.
114
+ * Required when useStubs is false. Ignored when useStubs is true.
115
+ * Default: undefined
116
+ */
117
+ runtimeAdapter?: TrinityRuntimeAdapter;
118
+ /**
119
+ * Scoring weights for tournament selection.
120
+ * Default: DEFAULT_SCORING_WEIGHTS
121
+ */
122
+ scoringWeights?: ScoringWeights;
123
+ /**
124
+ * Threshold values for tournament eligibility.
125
+ * Default: DEFAULT_THRESHOLDS
126
+ */
127
+ thresholds?: ThresholdValues;
128
+ /**
129
+ * State directory for threshold persistence.
130
+ * If provided, thresholds will be loaded from state.
131
+ */
132
+ stateDir?: string;
133
+ }
134
+ /**
135
+ * Dreamer output — multiple candidate corrections.
136
+ * Each candidate represents an alternative "better decision" approach.
137
+ */
138
+ export interface DreamerCandidate {
139
+ /** Unique index for this candidate within the Dreamer output */
140
+ candidateIndex: number;
141
+ /** The bad decision this candidate addresses */
142
+ badDecision: string;
143
+ /** The alternative/better decision */
144
+ betterDecision: string;
145
+ /** Why this alternative is better (brief) */
146
+ rationale: string;
147
+ /** Confidence that this candidate is valid (0-1) */
148
+ confidence: number;
149
+ }
150
+ export interface DreamerOutput {
151
+ /** Whether Dreamer succeeded */
152
+ valid: boolean;
153
+ /** List of candidate corrections */
154
+ candidates: DreamerCandidate[];
155
+ /** Why Dreamer could not generate (if valid === false) */
156
+ reason?: string;
157
+ /** Timestamp of generation */
158
+ generatedAt: string;
159
+ }
160
+ /**
161
+ * Philosopher output — principle-grounded critique and ranking.
162
+ * Philosopher evaluates Dreamer's candidates and ranks them.
163
+ */
164
+ export interface PhilosopherJudgment {
165
+ /** Index of the judged candidate (references DreamerCandidate.candidateIndex) */
166
+ candidateIndex: number;
167
+ /** Principle-grounded critique of this candidate */
168
+ critique: string;
169
+ /** Whether this candidate aligns with the target principle */
170
+ principleAligned: boolean;
171
+ /** Ranking score (higher = better, 0-1) */
172
+ score: number;
173
+ /** Rank among all candidates (1 = best) */
174
+ rank: number;
175
+ }
176
+ export interface PhilosopherOutput {
177
+ /** Whether Philosopher succeeded */
178
+ valid: boolean;
179
+ /** Judgments for each candidate */
180
+ judgments: PhilosopherJudgment[];
181
+ /** Overall assessment of the candidate set */
182
+ overallAssessment: string;
183
+ /** Why Philosopher could not judge (if valid === false) */
184
+ reason?: string;
185
+ /** Timestamp of generation */
186
+ generatedAt: string;
187
+ }
188
+ /**
189
+ * Scribe output — final structured artifact draft.
190
+ * Scribe synthesizes the best candidate into an approved artifact format.
191
+ */
192
+ export interface TrinityDraftArtifact {
193
+ /** The selected winning candidate index */
194
+ selectedCandidateIndex: number;
195
+ /** The final badDecision */
196
+ badDecision: string;
197
+ /** The final betterDecision */
198
+ betterDecision: string;
199
+ /** The final rationale */
200
+ rationale: string;
201
+ /** Source session from snapshot */
202
+ sessionId: string;
203
+ /** Target principle ID */
204
+ principleId: string;
205
+ /** Reference to snapshot used */
206
+ sourceSnapshotRef: string;
207
+ /** Chain telemetry */
208
+ telemetry: TrinityTelemetry;
209
+ /** Reflection quality: delta in thinking model activation (-1 to 1) */
210
+ thinkingModelDelta?: number;
211
+ /** Reflection quality: gain in planning ratio (-1 to 1) */
212
+ planningRatioGain?: number;
213
+ }
214
+ export interface TrinityTelemetry {
215
+ /** Whether Trinity or single-reflector was used */
216
+ chainMode: 'trinity' | 'single-reflector';
217
+ /** Whether stub implementations were used (always true in Phase 8) */
218
+ usedStubs: boolean;
219
+ /** Whether each stage passed */
220
+ dreamerPassed: boolean;
221
+ philosopherPassed: boolean;
222
+ scribePassed: boolean;
223
+ /** Number of candidates generated */
224
+ candidateCount: number;
225
+ /** Final selected candidate index */
226
+ selectedCandidateIndex: number;
227
+ /** Stage failure reasons (if any) */
228
+ stageFailures: string[];
229
+ /** Tournament trace for explainability (optional) */
230
+ tournamentTrace?: TournamentTraceEntry[];
231
+ /** Winner aggregate score (optional) */
232
+ winnerAggregateScore?: number;
233
+ /** Whether winner passed all thresholds (optional) */
234
+ winnerThresholdPassed?: boolean;
235
+ /** Number of eligible candidates after threshold check (optional) */
236
+ eligibleCandidateCount?: number;
237
+ }
238
+ /**
239
+ * Validation failure for a Trinity stage.
240
+ */
241
+ export interface TrinityStageFailure {
242
+ stage: 'dreamer' | 'philosopher' | 'scribe';
243
+ reason: string;
244
+ }
245
+ /**
246
+ * Result of Trinity chain execution.
247
+ */
248
+ export interface TrinityResult {
249
+ /** Whether Trinity chain completed successfully */
250
+ success: boolean;
251
+ /** The final draft artifact (if success) */
252
+ artifact?: TrinityDraftArtifact;
253
+ /** Telemetry about the chain execution */
254
+ telemetry: TrinityTelemetry;
255
+ /** Stage failures (if any) */
256
+ failures: TrinityStageFailure[];
257
+ /** Whether fallback to single-reflector occurred */
258
+ fallbackOccurred: boolean;
259
+ }
260
+ export interface RunTrinityOptions {
261
+ /** Snapshot to generate candidates from */
262
+ snapshot: NocturnalSessionSnapshot;
263
+ /** Target principle ID */
264
+ principleId: string;
265
+ /** Trinity configuration */
266
+ config: TrinityConfig;
267
+ }
268
+ /**
269
+ * Execute the Trinity chain using stubs (synchronous).
270
+ * Use runTrinityAsync for real subagent execution via runtime adapter.
271
+ *
272
+ * @param options - Trinity execution options
273
+ * @returns TrinityResult with final artifact or failure info
274
+ */
275
+ export declare function runTrinity(options: RunTrinityOptions): TrinityResult;
276
+ /**
277
+ * Execute the Trinity chain with real subagent runtime (asynchronous).
278
+ * Requires config.runtimeAdapter to be set.
279
+ *
280
+ * @param options - Trinity execution options
281
+ * @returns Promise<TrinityResult> with final artifact or failure info
282
+ */
283
+ export declare function runTrinityAsync(options: RunTrinityOptions): Promise<TrinityResult>;
284
+ /**
285
+ * Validate that a Trinity draft artifact can pass final arbiter validation.
286
+ * This checks the draft against the same rules as single-reflector artifacts.
287
+ */
288
+ export interface DraftValidationResult {
289
+ valid: boolean;
290
+ failures: string[];
291
+ }
292
+ /**
293
+ * Validate a TrinityDraftArtifact before passing to arbiter.
294
+ */
295
+ export declare function validateDraftArtifact(draft: TrinityDraftArtifact): DraftValidationResult;
296
+ /**
297
+ * Convert a TrinityDraftArtifact to a NocturnalArtifact-compatible structure.
298
+ */
299
+ export declare function draftToArtifact(draft: TrinityDraftArtifact): {
300
+ artifactId: string;
301
+ sessionId: string;
302
+ principleId: string;
303
+ sourceSnapshotRef: string;
304
+ badDecision: string;
305
+ betterDecision: string;
306
+ rationale: string;
307
+ createdAt: string;
308
+ thinkingModelDelta?: number;
309
+ planningRatioGain?: number;
310
+ };
311
+ export declare const DEFAULT_TRINITY_CONFIG: TrinityConfig;