principles-disciple 1.201.0 → 1.202.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +166 -166
- package/dist/commands/archive-impl.d.ts +18 -0
- package/dist/commands/capabilities.d.ts +3 -0
- package/dist/commands/context.d.ts +5 -0
- package/dist/commands/disable-impl.d.ts +22 -0
- package/dist/commands/evolution-status.d.ts +4 -0
- package/dist/commands/export.d.ts +2 -0
- package/dist/commands/focus.d.ts +14 -0
- package/dist/commands/pain.d.ts +6 -0
- package/dist/commands/principle-rollback.d.ts +4 -0
- package/dist/commands/promote-impl.d.ts +22 -0
- package/dist/commands/rollback-impl.d.ts +32 -0
- package/dist/commands/rollback.d.ts +19 -0
- package/dist/commands/samples.d.ts +2 -0
- package/dist/commands/strategy.d.ts +2 -0
- package/dist/commands/thinking-os.d.ts +2 -0
- package/dist/commands/workflow-debug.d.ts +4 -0
- package/dist/config/defaults/runtime.d.ts +58 -0
- package/dist/config/errors.d.ts +86 -0
- package/dist/config/index.d.ts +7 -0
- package/dist/constants/tools.d.ts +17 -0
- package/dist/core/__tests__/focus-history.test.d.ts +1 -0
- package/dist/core/behavior-example-pack-assembler.d.ts +38 -0
- package/dist/core/bootstrap-rules.d.ts +50 -0
- package/dist/core/code-implementation-storage.d.ts +71 -0
- package/dist/core/config-health.d.ts +17 -0
- package/dist/core/config-service.d.ts +15 -0
- package/dist/core/config.d.ts +111 -0
- package/dist/core/control-ui-db.d.ts +117 -0
- package/dist/core/correction-cue-learner.d.ts +33 -0
- package/dist/core/correction-types.d.ts +3 -0
- package/dist/core/detection-funnel.d.ts +47 -0
- package/dist/core/detection-service.d.ts +15 -0
- package/dist/core/dictionary-service.d.ts +15 -0
- package/dist/core/dictionary.d.ts +38 -0
- package/dist/core/empathy-keyword-matcher.d.ts +5 -0
- package/dist/core/empathy-types.d.ts +2 -0
- package/dist/core/event-log.d.ts +98 -0
- package/dist/core/evolution-engine.d.ts +119 -0
- package/dist/core/evolution-logger.d.ts +137 -0
- package/dist/core/evolution-reducer.d.ts +116 -0
- package/dist/core/evolution-types.d.ts +50 -0
- package/dist/core/file-store.d.ts +41 -0
- package/dist/core/focus-history.d.ts +50 -0
- package/dist/core/hygiene/tracker.d.ts +22 -0
- package/dist/core/init.d.ts +30 -0
- package/dist/core/intent-doc-reader-adapter.d.ts +36 -0
- package/dist/core/intent-doc-reader.d.ts +89 -0
- package/dist/core/migration.d.ts +6 -0
- package/dist/core/pain-diagnostic-gate.d.ts +45 -0
- package/dist/core/pain.d.ts +24 -0
- package/dist/core/path-resolver.d.ts +60 -0
- package/dist/core/paths.d.ts +59 -0
- package/dist/core/pd-config-loader.d.ts +96 -0
- package/dist/core/pd-task-reconciler.d.ts +89 -0
- package/dist/core/pd-task-service.d.ts +2 -0
- package/dist/core/pd-task-store.d.ts +5 -0
- package/dist/core/pd-task-types.d.ts +8 -0
- package/dist/core/principle-compiler/__tests__/compiler-replay-gate.test.d.ts +1 -0
- package/dist/core/principle-compiler/code-validator.d.ts +14 -0
- package/dist/core/principle-compiler/compiler.d.ts +45 -0
- package/dist/core/principle-compiler/index.d.ts +12 -0
- package/dist/core/principle-compiler/ledger-registrar.d.ts +28 -0
- package/dist/core/principle-compiler/template-generator.d.ts +7 -0
- package/dist/core/principle-injection.d.ts +10 -0
- package/dist/core/principle-internalization/filesystem-lifecycle-datasource.d.ts +15 -0
- package/dist/core/principle-internalization/lifecycle-read-model.d.ts +17 -0
- package/dist/core/principle-internalization/lifecycle-refresh.d.ts +2 -0
- package/dist/core/principle-internalization/principle-lifecycle-service.d.ts +28 -0
- package/dist/core/principle-training-state.d.ts +47 -0
- package/dist/core/principle-tree-ledger.d.ts +30 -0
- package/dist/core/profile.d.ts +62 -0
- package/dist/core/reflection/reflection-context.d.ts +31 -0
- package/dist/core/replay-engine.d.ts +12 -0
- package/dist/core/rule-context-assembler.d.ts +45 -0
- package/dist/core/rule-host.d.ts +178 -0
- package/dist/core/rule-implementation-runtime.d.ts +18 -0
- package/dist/core/runtime-v2-prompt-activation-reader.d.ts +22 -0
- package/dist/core/session-tracker.d.ts +119 -0
- package/dist/core/signal-collector-host.d.ts +113 -0
- package/dist/core/system-logger.d.ts +24 -0
- package/dist/core/thinking-models.d.ts +25 -0
- package/dist/core/thinking-os-parser.d.ts +35 -0
- package/dist/core/trajectory-types.d.ts +247 -0
- package/dist/core/trajectory.d.ts +279 -0
- package/dist/core/workflow-funnel-loader.d.ts +72 -0
- package/dist/core/workspace-context.d.ts +114 -0
- package/dist/core/workspace-dir-validation.d.ts +11 -0
- package/dist/core/workspace-guidance-migrator.d.ts +12 -0
- package/dist/hooks/after-tool-call-helpers.d.ts +97 -0
- package/dist/hooks/after-tool-call-types.d.ts +86 -0
- package/dist/hooks/gate-block-helper.d.ts +44 -0
- package/dist/hooks/gate.d.ts +16 -0
- package/dist/hooks/lifecycle.d.ts +5 -0
- package/dist/hooks/llm.d.ts +21 -0
- package/dist/hooks/message-sanitize.d.ts +24 -0
- package/dist/hooks/pain.d.ts +35 -0
- package/dist/hooks/prompt-helpers.d.ts +105 -0
- package/dist/hooks/prompt-types.d.ts +74 -0
- package/dist/hooks/prompt.d.ts +22 -0
- package/dist/hooks/raw-observation-adapter.d.ts +16 -0
- package/dist/hooks/raw-observation-types.d.ts +11 -0
- package/dist/hooks/trajectory-collector.d.ts +41 -0
- package/dist/hooks/trajectory-evidence.d.ts +11 -0
- package/dist/hooks/triage-adapter.d.ts +58 -0
- package/dist/hooks/trigger-cooldown-tracker.d.ts +42 -0
- package/dist/i18n/commands.d.ts +26 -0
- package/dist/index.d.ts +52 -0
- package/dist/openclaw-sdk.d.ts +338 -0
- package/dist/openclaw.plugin.json +1 -1
- package/dist/rulehost-evidence.d.ts +4 -0
- package/dist/service/correction-observer-service.d.ts +19 -0
- package/dist/service/evolution-dedup.d.ts +27 -0
- package/dist/service/evolution-worker.d.ts +105 -0
- package/dist/service/internalization-auto-consumer-service.d.ts +8 -0
- package/dist/service/keyword-optimization-service.d.ts +44 -0
- package/dist/service/phase3-input-filter.d.ts +73 -0
- package/dist/service/queue-io.d.ts +30 -0
- package/dist/service/queue-migration.d.ts +84 -0
- package/dist/service/runtime-summary-service.d.ts +156 -0
- package/dist/service/subagent-workflow/subagent-error-utils.d.ts +8 -0
- package/dist/service/subagent-workflow/types.d.ts +264 -0
- package/dist/service/subagent-workflow/workflow-store.d.ts +44 -0
- package/dist/service/trajectory-service.d.ts +2 -0
- package/dist/service/workflow-watchdog.d.ts +23 -0
- package/dist/types/event-types.d.ts +2 -0
- package/dist/types/hygiene-types.d.ts +2 -0
- package/dist/types/principle-tree-schema.d.ts +29 -0
- package/dist/types/queue.d.ts +2 -0
- package/dist/types/runtime-summary.d.ts +1 -0
- package/dist/types.d.ts +13 -0
- package/dist/utils/file-lock.d.ts +68 -0
- package/dist/utils/hashing.d.ts +9 -0
- package/dist/utils/io.d.ts +11 -0
- package/dist/utils/node-vm-polyfill.d.ts +9 -0
- package/dist/utils/retry.d.ts +210 -0
- package/dist/utils/session-key.d.ts +10 -0
- package/dist/utils/workspace-resolver.d.ts +82 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trajectory database type definitions.
|
|
3
|
+
*
|
|
4
|
+
* PURPOSE: Track task outcomes, trust changes, and evolution progress over time.
|
|
5
|
+
* USAGE: Insights, trends, and Phase 3 supporting evidence (where explicitly allowed).
|
|
6
|
+
* NOT FOR: Control decisions, Phase 3 eligibility, or real-time operations.
|
|
7
|
+
*/
|
|
8
|
+
export type CorrectionSampleReviewStatus = 'pending' | 'approved' | 'rejected';
|
|
9
|
+
export type CorrectionExportMode = 'raw' | 'redacted';
|
|
10
|
+
export interface TrajectoryDataStats {
|
|
11
|
+
dbPath: string;
|
|
12
|
+
dbSizeBytes: number;
|
|
13
|
+
assistantTurns: number;
|
|
14
|
+
userTurns: number;
|
|
15
|
+
toolCalls: number;
|
|
16
|
+
painEvents: number;
|
|
17
|
+
pendingSamples: number;
|
|
18
|
+
approvedSamples: number;
|
|
19
|
+
blobBytes: number;
|
|
20
|
+
lastIngestAt: string | null;
|
|
21
|
+
}
|
|
22
|
+
export interface TrajectoryAssistantTurnInput {
|
|
23
|
+
sessionId: string;
|
|
24
|
+
runId: string;
|
|
25
|
+
provider: string;
|
|
26
|
+
model: string;
|
|
27
|
+
rawText: string;
|
|
28
|
+
sanitizedText: string;
|
|
29
|
+
usageJson: unknown;
|
|
30
|
+
empathySignalJson: unknown;
|
|
31
|
+
stopReason?: string | null;
|
|
32
|
+
thinkingBlocksCount?: number | null;
|
|
33
|
+
createdAt?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface TrajectoryUserTurnInput {
|
|
36
|
+
sessionId: string;
|
|
37
|
+
turnIndex: number;
|
|
38
|
+
rawText: string;
|
|
39
|
+
correctionDetected: boolean;
|
|
40
|
+
correctionCue?: string | null;
|
|
41
|
+
referencesAssistantTurnId?: number | null;
|
|
42
|
+
createdAt?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface TrajectoryToolCallInput {
|
|
45
|
+
sessionId: string;
|
|
46
|
+
toolName: string;
|
|
47
|
+
outcome: 'success' | 'failure' | 'blocked';
|
|
48
|
+
durationMs?: number | null;
|
|
49
|
+
exitCode?: number | null;
|
|
50
|
+
errorType?: string | null;
|
|
51
|
+
errorMessage?: string | null;
|
|
52
|
+
gfiBefore?: number | null;
|
|
53
|
+
gfiAfter?: number | null;
|
|
54
|
+
paramsJson?: unknown;
|
|
55
|
+
resultPreview?: string | null;
|
|
56
|
+
createdAt?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface TrajectoryPainEventInput {
|
|
59
|
+
sessionId: string;
|
|
60
|
+
source: string;
|
|
61
|
+
score: number;
|
|
62
|
+
reason?: string | null;
|
|
63
|
+
severity?: string | null;
|
|
64
|
+
origin?: string | null;
|
|
65
|
+
confidence?: number | null;
|
|
66
|
+
text?: string;
|
|
67
|
+
createdAt?: string;
|
|
68
|
+
/** PRI-406: Canonical pain identity (e.g. manual_<ts>_<hash> or pain_<ts>_<hash>). */
|
|
69
|
+
canonicalPainId?: string;
|
|
70
|
+
/** PRI-406: Runtime V2 diagnostician task ID linked to this pain event. */
|
|
71
|
+
runtimeTaskId?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface TrajectoryGateBlockInput {
|
|
74
|
+
sessionId?: string | null;
|
|
75
|
+
toolName: string;
|
|
76
|
+
filePath?: string | null;
|
|
77
|
+
reason: string;
|
|
78
|
+
planStatus?: string | null;
|
|
79
|
+
createdAt?: string;
|
|
80
|
+
}
|
|
81
|
+
type DailyMetricRow = {
|
|
82
|
+
day: string;
|
|
83
|
+
tool_calls: number;
|
|
84
|
+
failures: number;
|
|
85
|
+
user_corrections: number;
|
|
86
|
+
};
|
|
87
|
+
export interface TrajectoryTrustChangeInput {
|
|
88
|
+
sessionId?: string | null;
|
|
89
|
+
previousScore: number;
|
|
90
|
+
newScore: number;
|
|
91
|
+
delta: number;
|
|
92
|
+
reason: string;
|
|
93
|
+
createdAt?: string;
|
|
94
|
+
}
|
|
95
|
+
export interface TrajectoryPrincipleEventInput {
|
|
96
|
+
principleId?: string | null;
|
|
97
|
+
eventType: string;
|
|
98
|
+
payload: unknown;
|
|
99
|
+
createdAt?: string;
|
|
100
|
+
}
|
|
101
|
+
export interface TrajectoryTaskOutcomeInput {
|
|
102
|
+
sessionId: string;
|
|
103
|
+
taskId?: string | null;
|
|
104
|
+
outcome: string;
|
|
105
|
+
summary?: string | null;
|
|
106
|
+
principleIdsJson?: unknown;
|
|
107
|
+
createdAt?: string;
|
|
108
|
+
}
|
|
109
|
+
export interface TrajectorySessionInput {
|
|
110
|
+
sessionId: string;
|
|
111
|
+
startedAt?: string;
|
|
112
|
+
}
|
|
113
|
+
export type TaskKind = 'pain_diagnosis' | 'sleep_reflection' | 'model_eval' | 'keyword_optimization';
|
|
114
|
+
export type TaskPriority = 'high' | 'medium' | 'low';
|
|
115
|
+
interface EvolutionTaskInputBase {
|
|
116
|
+
taskId: string;
|
|
117
|
+
traceId: string;
|
|
118
|
+
source: string;
|
|
119
|
+
reason?: string | null;
|
|
120
|
+
score?: number;
|
|
121
|
+
status?: string;
|
|
122
|
+
enqueuedAt?: string | null;
|
|
123
|
+
startedAt?: string | null;
|
|
124
|
+
completedAt?: string | null;
|
|
125
|
+
resolution?: string | null;
|
|
126
|
+
createdAt?: string;
|
|
127
|
+
updatedAt?: string;
|
|
128
|
+
}
|
|
129
|
+
export interface EvolutionTaskInputV2 extends EvolutionTaskInputBase {
|
|
130
|
+
taskKind?: TaskKind;
|
|
131
|
+
priority?: TaskPriority;
|
|
132
|
+
retryCount?: number;
|
|
133
|
+
maxRetries?: number;
|
|
134
|
+
lastError?: string | null;
|
|
135
|
+
resultRef?: string | null;
|
|
136
|
+
}
|
|
137
|
+
export type EvolutionTaskInput = EvolutionTaskInputV2;
|
|
138
|
+
export interface EvolutionEventInput {
|
|
139
|
+
traceId: string;
|
|
140
|
+
taskId?: string | null;
|
|
141
|
+
stage: string;
|
|
142
|
+
level?: string;
|
|
143
|
+
message: string;
|
|
144
|
+
summary?: string | null;
|
|
145
|
+
metadata?: unknown;
|
|
146
|
+
createdAt?: string;
|
|
147
|
+
}
|
|
148
|
+
export interface EvolutionTaskRecord {
|
|
149
|
+
id: number;
|
|
150
|
+
taskId: string;
|
|
151
|
+
traceId: string;
|
|
152
|
+
source: string;
|
|
153
|
+
reason: string | null;
|
|
154
|
+
score: number;
|
|
155
|
+
status: string;
|
|
156
|
+
enqueuedAt: string | null;
|
|
157
|
+
startedAt: string | null;
|
|
158
|
+
completedAt: string | null;
|
|
159
|
+
resolution: string | null;
|
|
160
|
+
createdAt: string;
|
|
161
|
+
updatedAt: string;
|
|
162
|
+
taskKind: TaskKind | null;
|
|
163
|
+
priority: TaskPriority | null;
|
|
164
|
+
retryCount: number | null;
|
|
165
|
+
maxRetries: number | null;
|
|
166
|
+
lastError: string | null;
|
|
167
|
+
resultRef: string | null;
|
|
168
|
+
}
|
|
169
|
+
export interface EvolutionEventRecord {
|
|
170
|
+
id: number;
|
|
171
|
+
traceId: string;
|
|
172
|
+
taskId: string | null;
|
|
173
|
+
stage: string;
|
|
174
|
+
level: string;
|
|
175
|
+
message: string;
|
|
176
|
+
summary: string | null;
|
|
177
|
+
metadata: Record<string, unknown>;
|
|
178
|
+
createdAt: string;
|
|
179
|
+
}
|
|
180
|
+
export interface EvolutionTaskFilters {
|
|
181
|
+
status?: string;
|
|
182
|
+
dateFrom?: string;
|
|
183
|
+
dateTo?: string;
|
|
184
|
+
limit?: number;
|
|
185
|
+
offset?: number;
|
|
186
|
+
}
|
|
187
|
+
export interface AssistantTurnRecord {
|
|
188
|
+
id: number;
|
|
189
|
+
sessionId: string;
|
|
190
|
+
runId: string;
|
|
191
|
+
provider: string;
|
|
192
|
+
model: string;
|
|
193
|
+
rawText: string;
|
|
194
|
+
sanitizedText: string;
|
|
195
|
+
blobRef: string | null;
|
|
196
|
+
stopReason: string | null;
|
|
197
|
+
thinkingBlocksCount: number | null;
|
|
198
|
+
createdAt: string;
|
|
199
|
+
}
|
|
200
|
+
export interface CorrectionSampleRecord {
|
|
201
|
+
sampleId: string;
|
|
202
|
+
sessionId: string;
|
|
203
|
+
badAssistantTurnId: number;
|
|
204
|
+
userCorrectionTurnId: number;
|
|
205
|
+
recoveryToolSpanJson: string;
|
|
206
|
+
diffExcerpt: string;
|
|
207
|
+
principleIdsJson: string;
|
|
208
|
+
qualityScore: number;
|
|
209
|
+
reviewStatus: CorrectionSampleReviewStatus;
|
|
210
|
+
exportMode: CorrectionExportMode;
|
|
211
|
+
createdAt: string;
|
|
212
|
+
updatedAt: string;
|
|
213
|
+
}
|
|
214
|
+
export interface TrajectoryExportResult {
|
|
215
|
+
filePath: string;
|
|
216
|
+
count: number;
|
|
217
|
+
mode?: CorrectionExportMode;
|
|
218
|
+
}
|
|
219
|
+
export interface TrajectoryDatabaseOptions {
|
|
220
|
+
workspaceDir: string;
|
|
221
|
+
blobInlineThresholdBytes?: number;
|
|
222
|
+
busyTimeoutMs?: number;
|
|
223
|
+
orphanBlobGraceDays?: number;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Raw row from tool_calls for RuleContext v2 history assembly.
|
|
227
|
+
* Fields are raw strings from SQLite — the assembler validates them as unknown.
|
|
228
|
+
*/
|
|
229
|
+
export interface RuleHostContextRow {
|
|
230
|
+
readonly id: number;
|
|
231
|
+
readonly toolName: string;
|
|
232
|
+
readonly outcome: string;
|
|
233
|
+
readonly paramsJson: string;
|
|
234
|
+
}
|
|
235
|
+
/** A single tool call selected by an Owner as labelled RuleHost evidence. */
|
|
236
|
+
export interface RuleHostEvidenceRow extends RuleHostContextRow {
|
|
237
|
+
readonly sessionId: string;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Result of getRuleHostContextRows: FIFO-ordered rows + truncated flag.
|
|
241
|
+
* truncated=true when more than `limit` rows existed (limit+1 read trick).
|
|
242
|
+
*/
|
|
243
|
+
export interface RuleHostContextResult {
|
|
244
|
+
readonly rows: readonly RuleHostContextRow[];
|
|
245
|
+
readonly truncated: boolean;
|
|
246
|
+
}
|
|
247
|
+
export type { DailyMetricRow };
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import type { CorrectionSampleReviewStatus, CorrectionExportMode, TrajectoryDataStats, TrajectoryAssistantTurnInput, TrajectoryUserTurnInput, TrajectoryToolCallInput, TrajectoryPainEventInput, TrajectoryGateBlockInput, TrajectoryTrustChangeInput, TrajectoryPrincipleEventInput, TrajectoryTaskOutcomeInput, TrajectorySessionInput, EvolutionTaskInput, EvolutionEventInput, EvolutionTaskRecord, EvolutionEventRecord, EvolutionTaskFilters, AssistantTurnRecord, CorrectionSampleRecord, TrajectoryExportResult, TrajectoryDatabaseOptions, RuleHostContextResult, RuleHostEvidenceRow } from './trajectory-types.js';
|
|
2
|
+
export type { CorrectionSampleReviewStatus, CorrectionExportMode, TrajectoryDataStats, TrajectoryAssistantTurnInput, TrajectoryUserTurnInput, TrajectoryToolCallInput, TrajectoryPainEventInput, TrajectoryGateBlockInput, DailyMetricRow, TrajectoryTrustChangeInput, TrajectoryPrincipleEventInput, TrajectoryTaskOutcomeInput, TrajectorySessionInput, TaskKind, TaskPriority, EvolutionTaskInput, EvolutionEventInput, EvolutionTaskRecord, EvolutionEventRecord, EvolutionTaskFilters, AssistantTurnRecord, CorrectionSampleRecord, TrajectoryExportResult, TrajectoryDatabaseOptions, RuleHostContextRow, RuleHostContextResult, RuleHostEvidenceRow, } from './trajectory-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Initialize trajectory.db schema at the given workspace directory.
|
|
5
|
+
*
|
|
6
|
+
* Opens trajectory.db in write mode, applies the full schema (tables + indexes + views +
|
|
7
|
+
* migrations), then closes the DB. Does NOT run importLegacyArtifacts() or
|
|
8
|
+
* pruneUnreferencedBlobs() — those are runtime side-effects of TrajectoryDatabase
|
|
9
|
+
* construction and are not needed for pure initialization.
|
|
10
|
+
*
|
|
11
|
+
* Idempotent: safe to call on an existing DB; all CREATE statements use IF NOT EXISTS.
|
|
12
|
+
*
|
|
13
|
+
* @returns list of created/verified table names and any warnings
|
|
14
|
+
*/
|
|
15
|
+
export declare function initTrajectorySchema(workspaceDir: string): {
|
|
16
|
+
tables: string[];
|
|
17
|
+
warnings: string[];
|
|
18
|
+
};
|
|
19
|
+
export declare class TrajectoryDatabase {
|
|
20
|
+
private readonly workspaceDir;
|
|
21
|
+
private readonly stateDir;
|
|
22
|
+
private readonly dbPath;
|
|
23
|
+
private readonly blobDir;
|
|
24
|
+
private readonly exportDir;
|
|
25
|
+
private readonly blobInlineThresholdBytes;
|
|
26
|
+
private readonly orphanBlobGraceMs;
|
|
27
|
+
private readonly db;
|
|
28
|
+
constructor(opts: TrajectoryDatabaseOptions);
|
|
29
|
+
dispose(): void;
|
|
30
|
+
recordSession(input: TrajectorySessionInput): void;
|
|
31
|
+
recordAssistantTurn(input: TrajectoryAssistantTurnInput): number;
|
|
32
|
+
recordUserTurn(input: TrajectoryUserTurnInput): number;
|
|
33
|
+
recordToolCall(input: TrajectoryToolCallInput): number;
|
|
34
|
+
recordPainEvent(input: TrajectoryPainEventInput): number;
|
|
35
|
+
recordGateBlock(input: TrajectoryGateBlockInput): void;
|
|
36
|
+
recordTrustChange(input: TrajectoryTrustChangeInput): void;
|
|
37
|
+
recordPrincipleEvent(input: TrajectoryPrincipleEventInput): void;
|
|
38
|
+
recordTaskOutcome(input: TrajectoryTaskOutcomeInput): void;
|
|
39
|
+
recordEvolutionTask(input: EvolutionTaskInput): void;
|
|
40
|
+
updateEvolutionTask(taskId: string, updates: Partial<Omit<EvolutionTaskInput, 'taskId' | 'traceId' | 'source'>>): void;
|
|
41
|
+
recordEvolutionEvent(input: EvolutionEventInput): void;
|
|
42
|
+
/**
|
|
43
|
+
* List evolution tasks with optional filtering.
|
|
44
|
+
*
|
|
45
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
46
|
+
* Not: Runtime truth or real-time queue state.
|
|
47
|
+
*/
|
|
48
|
+
listEvolutionTasks(filters?: EvolutionTaskFilters): EvolutionTaskRecord[];
|
|
49
|
+
/**
|
|
50
|
+
* List evolution events for a trace or globally.
|
|
51
|
+
*
|
|
52
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
53
|
+
* Not: Runtime truth or real-time queue state.
|
|
54
|
+
*/
|
|
55
|
+
listEvolutionEvents(traceId?: string, filters?: {
|
|
56
|
+
limit?: number;
|
|
57
|
+
offset?: number;
|
|
58
|
+
}): EvolutionEventRecord[];
|
|
59
|
+
/**
|
|
60
|
+
* Get evolution task by trace ID.
|
|
61
|
+
*
|
|
62
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
63
|
+
* Not: Runtime truth or real-time queue state.
|
|
64
|
+
*/
|
|
65
|
+
getEvolutionTaskByTraceId(traceId: string): EvolutionTaskRecord | null;
|
|
66
|
+
/**
|
|
67
|
+
* Get evolution task statistics.
|
|
68
|
+
*
|
|
69
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
70
|
+
* Not: Runtime truth or real-time queue state.
|
|
71
|
+
*/
|
|
72
|
+
getEvolutionStats(): {
|
|
73
|
+
total: number;
|
|
74
|
+
pending: number;
|
|
75
|
+
inProgress: number;
|
|
76
|
+
completed: number;
|
|
77
|
+
failed: number;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* List recent sessions from the trajectory database.
|
|
81
|
+
*
|
|
82
|
+
* Returns: Recent session records ordered by most recently updated.
|
|
83
|
+
*
|
|
84
|
+
* @param options.limit - Maximum number of sessions to return (default: 20)
|
|
85
|
+
* @param options.dateFrom - Only return sessions updated after this date
|
|
86
|
+
* @param options.dateTo - Only return sessions updated before this date
|
|
87
|
+
*/
|
|
88
|
+
listRecentSessions(options?: {
|
|
89
|
+
limit?: number;
|
|
90
|
+
dateFrom?: string;
|
|
91
|
+
dateTo?: string;
|
|
92
|
+
}): {
|
|
93
|
+
sessionId: string;
|
|
94
|
+
startedAt: string;
|
|
95
|
+
updatedAt: string;
|
|
96
|
+
}[];
|
|
97
|
+
/**
|
|
98
|
+
* List assistant turns for a session.
|
|
99
|
+
*
|
|
100
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
101
|
+
* Not: Runtime truth or real-time queue state.
|
|
102
|
+
*/
|
|
103
|
+
listAssistantTurns(sessionId: string): AssistantTurnRecord[];
|
|
104
|
+
/**
|
|
105
|
+
* List tool calls for a session.
|
|
106
|
+
*
|
|
107
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
108
|
+
* Not: Runtime truth or real-time queue state.
|
|
109
|
+
*/
|
|
110
|
+
listToolCallsForSession(sessionId: string): {
|
|
111
|
+
id: number;
|
|
112
|
+
toolName: string;
|
|
113
|
+
outcome: string;
|
|
114
|
+
filePath: string | null;
|
|
115
|
+
durationMs: number | null;
|
|
116
|
+
exitCode: number | null;
|
|
117
|
+
errorType: string | null;
|
|
118
|
+
errorMessage: string | null;
|
|
119
|
+
gfiBefore: number | null;
|
|
120
|
+
gfiAfter: number | null;
|
|
121
|
+
resultPreview: string | null;
|
|
122
|
+
createdAt: string;
|
|
123
|
+
}[];
|
|
124
|
+
/**
|
|
125
|
+
* PRI-482 Phase 3: Query tool_calls for RuleContext v2 history assembly.
|
|
126
|
+
*
|
|
127
|
+
* Reads limit+1 rows (DESC by id) to compute truncated, then reverses to FIFO.
|
|
128
|
+
* Returns raw rows — the assembler (rule-context-assembler.ts) validates them.
|
|
129
|
+
*
|
|
130
|
+
* Spec: §5.1, §5.2. ERR-026: reuses production schema (no hand-written DDL).
|
|
131
|
+
*/
|
|
132
|
+
getRuleHostContextRows(sessionId: string, limit?: number): RuleHostContextResult;
|
|
133
|
+
/** Resolve one Owner-selected tool call without inferring its desired label. */
|
|
134
|
+
getRuleHostEvidenceRow(id: number): RuleHostEvidenceRow | null;
|
|
135
|
+
/** Return FIFO history strictly before an Owner-selected tool call. */
|
|
136
|
+
getRuleHostContextRowsBefore(sessionId: string, beforeId: number, limit?: number): RuleHostContextResult;
|
|
137
|
+
/**
|
|
138
|
+
* List pain events for a session.
|
|
139
|
+
*
|
|
140
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
141
|
+
* Not: Runtime truth or real-time queue state.
|
|
142
|
+
*/
|
|
143
|
+
listPainEventsForSession(sessionId: string): {
|
|
144
|
+
id: number;
|
|
145
|
+
source: string;
|
|
146
|
+
score: number;
|
|
147
|
+
reason: string | null;
|
|
148
|
+
severity: string | null;
|
|
149
|
+
origin: string | null;
|
|
150
|
+
confidence: number | null;
|
|
151
|
+
createdAt: string;
|
|
152
|
+
}[];
|
|
153
|
+
/**
|
|
154
|
+
* PRI-484 Phase 5 — Look up a single pain event by canonical_pain_id.
|
|
155
|
+
*
|
|
156
|
+
* Used by BehaviorExamplePackAssembler to anchor a pain lineage without
|
|
157
|
+
* already knowing the session_id. Returns null when not found.
|
|
158
|
+
*
|
|
159
|
+
* ERR-001 (rc-1, rc-2): row fields validated as unknown — no `as` bypass.
|
|
160
|
+
* Uses a type-guard predicate to narrow the DB row structurally.
|
|
161
|
+
*/
|
|
162
|
+
getPainEventByCanonicalId(canonicalPainId: string): {
|
|
163
|
+
id: number;
|
|
164
|
+
sessionId: string;
|
|
165
|
+
source: string;
|
|
166
|
+
score: number;
|
|
167
|
+
reason: string | null;
|
|
168
|
+
severity: string | null;
|
|
169
|
+
origin: string | null;
|
|
170
|
+
confidence: number | null;
|
|
171
|
+
text: string | null;
|
|
172
|
+
canonicalPainId: string;
|
|
173
|
+
runtimeTaskId: string | null;
|
|
174
|
+
createdAt: string;
|
|
175
|
+
} | null;
|
|
176
|
+
/**
|
|
177
|
+
* List user turns for a session.
|
|
178
|
+
* Returns sanitized/reduced fields for nocturnal use — NO raw text.
|
|
179
|
+
*/
|
|
180
|
+
listUserTurnsForSession(sessionId: string): {
|
|
181
|
+
id: number;
|
|
182
|
+
turnIndex: number;
|
|
183
|
+
rawExcerpt: string;
|
|
184
|
+
correctionDetected: boolean;
|
|
185
|
+
correctionCue: string | null;
|
|
186
|
+
createdAt: string;
|
|
187
|
+
}[];
|
|
188
|
+
/**
|
|
189
|
+
* List correction samples with optional review status filter.
|
|
190
|
+
*
|
|
191
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
192
|
+
* Not: Runtime truth or real-time queue state.
|
|
193
|
+
*/
|
|
194
|
+
listCorrectionSamples(status?: CorrectionSampleReviewStatus): CorrectionSampleRecord[];
|
|
195
|
+
/**
|
|
196
|
+
* List gate blocks for a session.
|
|
197
|
+
* Returns minimal fields for nocturnal use — no raw text.
|
|
198
|
+
*/
|
|
199
|
+
listGateBlocksForSession(sessionId: string): {
|
|
200
|
+
id: number;
|
|
201
|
+
toolName: string;
|
|
202
|
+
filePath: string | null;
|
|
203
|
+
reason: string;
|
|
204
|
+
planStatus: string | null;
|
|
205
|
+
createdAt: string;
|
|
206
|
+
}[];
|
|
207
|
+
/**
|
|
208
|
+
* List correction samples for a specific session.
|
|
209
|
+
* Returns minimal fields for nocturnal use — correction cue only.
|
|
210
|
+
* #268: Wire correction_samples into nocturnal pipeline.
|
|
211
|
+
*/
|
|
212
|
+
listCorrectionSamplesForSession(sessionId: string): {
|
|
213
|
+
correctionCue: string | null;
|
|
214
|
+
}[];
|
|
215
|
+
reviewCorrectionSample(sampleId: string, status: Exclude<CorrectionSampleReviewStatus, 'pending'>, note?: string): CorrectionSampleRecord;
|
|
216
|
+
/**
|
|
217
|
+
* When a correction sample is rejected, emit a pain event to the trajectory.
|
|
218
|
+
* This feeds rejected corrections into the nocturnal pipeline as a high-fidelity
|
|
219
|
+
* violation signal (human-verified, unlike heuristic pain detection).
|
|
220
|
+
*/
|
|
221
|
+
private recordCorrectionRejectedPain;
|
|
222
|
+
/**
|
|
223
|
+
* Export correction samples to JSONL file.
|
|
224
|
+
*
|
|
225
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
226
|
+
* Not: Runtime truth or real-time queue state.
|
|
227
|
+
*/
|
|
228
|
+
exportCorrections(opts: {
|
|
229
|
+
mode: CorrectionExportMode;
|
|
230
|
+
approvedOnly: boolean;
|
|
231
|
+
}): TrajectoryExportResult;
|
|
232
|
+
/**
|
|
233
|
+
* Export analytics data to JSON file.
|
|
234
|
+
*
|
|
235
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
236
|
+
* Not: Runtime truth or real-time queue state.
|
|
237
|
+
*/
|
|
238
|
+
exportAnalytics(): TrajectoryExportResult;
|
|
239
|
+
/**
|
|
240
|
+
* Get trajectory database statistics.
|
|
241
|
+
*
|
|
242
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
243
|
+
* Not: Runtime truth or real-time queue state.
|
|
244
|
+
*/
|
|
245
|
+
getDataStats(): TrajectoryDataStats;
|
|
246
|
+
cleanupBlobStorage(): {
|
|
247
|
+
removedFiles: number;
|
|
248
|
+
reclaimedBytes: number;
|
|
249
|
+
};
|
|
250
|
+
private initSchema;
|
|
251
|
+
private importLegacyArtifacts;
|
|
252
|
+
private migrateSchema;
|
|
253
|
+
/**
|
|
254
|
+
* Get daily metrics for analytics.
|
|
255
|
+
*
|
|
256
|
+
* Returns: Analytics data aggregated from trajectory database.
|
|
257
|
+
* Not: Runtime truth or real-time queue state.
|
|
258
|
+
*/
|
|
259
|
+
private dailyMetrics;
|
|
260
|
+
private importLegacySessions;
|
|
261
|
+
private importLegacyEvents;
|
|
262
|
+
private importLegacyEvolution;
|
|
263
|
+
private markImported;
|
|
264
|
+
private isImported;
|
|
265
|
+
private maybeCreateCorrectionSample;
|
|
266
|
+
private recordExportAudit;
|
|
267
|
+
private storeRawText;
|
|
268
|
+
private restoreRawText;
|
|
269
|
+
private computeBlobBytes;
|
|
270
|
+
private pruneUnreferencedBlobs;
|
|
271
|
+
private withWrite;
|
|
272
|
+
}
|
|
273
|
+
export declare class TrajectoryRegistry {
|
|
274
|
+
private static readonly instances;
|
|
275
|
+
static get(workspaceDir: string, opts?: Omit<TrajectoryDatabaseOptions, 'workspaceDir'>): TrajectoryDatabase;
|
|
276
|
+
static dispose(workspaceDir: string): void;
|
|
277
|
+
static clear(): void;
|
|
278
|
+
static use<T>(workspaceDir: string, fn: (_db: TrajectoryDatabase) => T, opts?: Omit<TrajectoryDatabaseOptions, 'workspaceDir'>): T;
|
|
279
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WorkflowFunnelLoader — Loads and watches workflows.yaml as the SSOT
|
|
3
|
+
* for WORKFLOW_FUNNELS definition table.
|
|
4
|
+
*
|
|
5
|
+
* D-01: workflows.yaml is the single source of truth (SSOT).
|
|
6
|
+
* D-02: workflows.yaml lives in .state/ directory per workspace.
|
|
7
|
+
* D-03: Developers manually maintain workflows.yaml (no auto-registration).
|
|
8
|
+
* D-04: Code only reads YAML, never writes it.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* A single stage in a workflow funnel.
|
|
12
|
+
* Policy fields are optional — existing stages without policy fields remain valid.
|
|
13
|
+
*/
|
|
14
|
+
export interface WorkflowStage {
|
|
15
|
+
name: string;
|
|
16
|
+
eventType: string;
|
|
17
|
+
eventCategory: string;
|
|
18
|
+
statsField: string;
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
successCriteria?: string;
|
|
21
|
+
legacyDisabled?: boolean;
|
|
22
|
+
observability?: {
|
|
23
|
+
enabled?: boolean;
|
|
24
|
+
emitEvents?: string[];
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Funnel-level policy that applies to all stages unless overridden per-stage.
|
|
29
|
+
*/
|
|
30
|
+
export interface FunnelPolicy {
|
|
31
|
+
timeoutMs?: number;
|
|
32
|
+
stageOrder?: 'strict' | 'relaxed';
|
|
33
|
+
legacyDisabled?: boolean;
|
|
34
|
+
observability?: {
|
|
35
|
+
enabled?: boolean;
|
|
36
|
+
emitEvents?: string[];
|
|
37
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A workflow funnel definition.
|
|
42
|
+
*/
|
|
43
|
+
export interface WorkflowFunnel {
|
|
44
|
+
workflowId: string;
|
|
45
|
+
stages: WorkflowStage[];
|
|
46
|
+
policy?: FunnelPolicy;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Root of workflows.yaml schema.
|
|
50
|
+
*/
|
|
51
|
+
export interface WorkflowFunnelConfig {
|
|
52
|
+
version: string;
|
|
53
|
+
funnels: WorkflowFunnel[];
|
|
54
|
+
}
|
|
55
|
+
export declare class WorkflowFunnelLoader {
|
|
56
|
+
private readonly funnels;
|
|
57
|
+
private readonly fullFunnels;
|
|
58
|
+
private readonly configPath;
|
|
59
|
+
private watchHandle?;
|
|
60
|
+
private readonly warnings;
|
|
61
|
+
constructor(stateDir: string);
|
|
62
|
+
load(): void;
|
|
63
|
+
watch(): void;
|
|
64
|
+
dispose(): void;
|
|
65
|
+
getStages(workflowId: string): WorkflowStage[];
|
|
66
|
+
getFunnel(workflowId: string): WorkflowFunnel | undefined;
|
|
67
|
+
getAllFunnels(): Map<string, WorkflowStage[]>;
|
|
68
|
+
getAllFunnelsWithPolicy(): Map<string, WorkflowFunnel>;
|
|
69
|
+
getWarnings(): string[];
|
|
70
|
+
getConfigPath(): string;
|
|
71
|
+
private cloneFunnel;
|
|
72
|
+
}
|