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,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subagent Workflow Helper - Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* This file defines the TypeScript interfaces for the workflow helper system
|
|
5
|
+
* that manages subagent lifecycle (empathy observer, deep-reflect, etc.).
|
|
6
|
+
*
|
|
7
|
+
* Design reference: docs/design/2026-03-31-subagent-workflow-helper-design.md
|
|
8
|
+
*
|
|
9
|
+
* @module subagent-workflow/types
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* First-phase helper transport.
|
|
13
|
+
* This helper currently models only plugin-owned runtime_direct workflows.
|
|
14
|
+
*/
|
|
15
|
+
export type WorkflowTransport = 'runtime_direct';
|
|
16
|
+
/**
|
|
17
|
+
* States in the workflow state machine.
|
|
18
|
+
*
|
|
19
|
+
* State transitions:
|
|
20
|
+
*
|
|
21
|
+
* PENDING ──→ ACTIVE ──→ WAIT_RESULT ──→ FINALIZING ──→ COMPLETED
|
|
22
|
+
* │ │ │
|
|
23
|
+
* │ ├──────────────────────────────┤
|
|
24
|
+
* │ │ (on timeout/error) │
|
|
25
|
+
* │ ▼ ▼
|
|
26
|
+
* │ TERMINAL_ERROR ◄─────────────────┘
|
|
27
|
+
* │ │
|
|
28
|
+
* │ │ (cleanup_pending if deleteSession fails)
|
|
29
|
+
* │ ▼
|
|
30
|
+
* └──────── CLEANUP_PENDING
|
|
31
|
+
*
|
|
32
|
+
* States marked with (*) are terminal states.
|
|
33
|
+
*/
|
|
34
|
+
export type WorkflowState = 'pending' | 'active' | 'wait_result' | 'finalizing' | 'completed' | 'terminal_error' | 'cleanup_pending' | 'expired';
|
|
35
|
+
/**
|
|
36
|
+
* Metadata stored with each workflow for auditing and debugging.
|
|
37
|
+
*/
|
|
38
|
+
export interface WorkflowMetadata {
|
|
39
|
+
parentSessionId: string;
|
|
40
|
+
workspaceDir?: string;
|
|
41
|
+
taskInput: unknown;
|
|
42
|
+
startedAt: number;
|
|
43
|
+
/** Human-readable workflow type for debugging */
|
|
44
|
+
workflowType: string;
|
|
45
|
+
/** Extra custom metadata specific to workflow type */
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Context passed to parseResult() when reading subagent output.
|
|
50
|
+
*/
|
|
51
|
+
export interface WorkflowResultContext {
|
|
52
|
+
/** Raw messages from getSessionMessages() */
|
|
53
|
+
messages: unknown[];
|
|
54
|
+
/** Convenience: pre-extracted assistant texts */
|
|
55
|
+
assistantTexts?: string[];
|
|
56
|
+
/** The workflow run metadata */
|
|
57
|
+
metadata: WorkflowMetadata;
|
|
58
|
+
/** The subagent run result status (only for runtime_direct) */
|
|
59
|
+
waitStatus?: 'ok' | 'error' | 'timeout';
|
|
60
|
+
/** Error message if waitStatus is 'error' */
|
|
61
|
+
waitError?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Context passed to persistResult() after successful parsing.
|
|
65
|
+
*/
|
|
66
|
+
export interface WorkflowPersistContext<TResult> {
|
|
67
|
+
/** Parsed result from parseResult() */
|
|
68
|
+
result: TResult;
|
|
69
|
+
/** The workflow run metadata */
|
|
70
|
+
metadata: WorkflowMetadata;
|
|
71
|
+
/** Workspace context directory */
|
|
72
|
+
workspaceDir: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Result of calling startWorkflow().
|
|
76
|
+
* Returned to caller so they can track the workflow.
|
|
77
|
+
*/
|
|
78
|
+
export interface WorkflowHandle {
|
|
79
|
+
/** Unique workflow ID */
|
|
80
|
+
workflowId: string;
|
|
81
|
+
/** Child session key for the subagent */
|
|
82
|
+
childSessionKey: string;
|
|
83
|
+
/** Run ID (only for runtime_direct transport) */
|
|
84
|
+
runId?: string;
|
|
85
|
+
/** The workflow state at creation */
|
|
86
|
+
state: WorkflowState;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Specification for a subagent workflow.
|
|
90
|
+
* Each workflow type (empathy observer, deep-reflect) implements this spec.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* const empathySpec: SubagentWorkflowSpec<EmpathyResult> = {
|
|
95
|
+
* workflowType: 'empathy-observer',
|
|
96
|
+
* transport: 'runtime_direct',
|
|
97
|
+
* timeoutMs: 30_000,
|
|
98
|
+
* ttlMs: 5 * 60 * 1000,
|
|
99
|
+
* shouldDeleteSessionAfterFinalize: true,
|
|
100
|
+
* parseResult: async (ctx) => parseEmpathyResult(ctx),
|
|
101
|
+
* persistResult: async (ctx) => { /* persist to trajectory *\/ },
|
|
102
|
+
* shouldFinalizeOnWaitStatus: (status) => status === 'ok',
|
|
103
|
+
* };
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export interface SubagentWorkflowSpec<TResult> {
|
|
107
|
+
/** Unique identifier for this workflow type */
|
|
108
|
+
workflowType: string;
|
|
109
|
+
/** Which transport mechanism to use */
|
|
110
|
+
transport: WorkflowTransport;
|
|
111
|
+
/** Build the prompt / input payload for the child subagent */
|
|
112
|
+
buildPrompt: (taskInput: unknown, metadata: WorkflowMetadata) => string;
|
|
113
|
+
/** Max time to wait for subagent completion */
|
|
114
|
+
timeoutMs: number;
|
|
115
|
+
/** Time-to-live for orphan cleanup (e.g., 5 minutes) */
|
|
116
|
+
ttlMs: number;
|
|
117
|
+
/** Whether to delete session after successful finalize */
|
|
118
|
+
shouldDeleteSessionAfterFinalize: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Parse subagent output into structured result.
|
|
121
|
+
* Return null if parsing fails or result is invalid.
|
|
122
|
+
*/
|
|
123
|
+
parseResult: (ctx: WorkflowResultContext) => Promise<TResult | null>;
|
|
124
|
+
/**
|
|
125
|
+
* Persist the parsed result to storage (trajectory, pain signal, etc.)
|
|
126
|
+
*/
|
|
127
|
+
persistResult: (ctx: WorkflowPersistContext<TResult>) => Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Determine if workflow should finalize given wait status.
|
|
130
|
+
* For runtime_direct: typically finalize only on 'ok', skip on 'timeout'/'error'.
|
|
131
|
+
*/
|
|
132
|
+
shouldFinalizeOnWaitStatus: (status: 'ok' | 'error' | 'timeout') => boolean;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Payload returned by empathy observer subagent.
|
|
136
|
+
*/
|
|
137
|
+
export type EmpathyObserverPayload = {
|
|
138
|
+
damageDetected?: boolean;
|
|
139
|
+
severity?: 'mild' | 'moderate' | 'severe' | string;
|
|
140
|
+
confidence?: number;
|
|
141
|
+
reason?: string;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Empathy observer workflow result.
|
|
145
|
+
*/
|
|
146
|
+
export interface EmpathyResult {
|
|
147
|
+
damageDetected: boolean;
|
|
148
|
+
severity: 'mild' | 'moderate' | 'severe';
|
|
149
|
+
confidence: number;
|
|
150
|
+
reason: string;
|
|
151
|
+
/** Derived pain score based on severity */
|
|
152
|
+
painScore: number;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Empathy observer workflow specification.
|
|
156
|
+
* This is the concrete spec for PR2 migration.
|
|
157
|
+
*/
|
|
158
|
+
export interface EmpathyObserverWorkflowSpec extends SubagentWorkflowSpec<EmpathyResult> {
|
|
159
|
+
workflowType: 'empathy-observer';
|
|
160
|
+
transport: 'runtime_direct';
|
|
161
|
+
timeoutMs: 30_000;
|
|
162
|
+
ttlMs: 300_000;
|
|
163
|
+
shouldDeleteSessionAfterFinalize: true;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The main workflow manager interface.
|
|
167
|
+
* This is what the helper exposes to business modules.
|
|
168
|
+
*/
|
|
169
|
+
export interface WorkflowManager {
|
|
170
|
+
/**
|
|
171
|
+
* Start a new workflow.
|
|
172
|
+
* Creates workflow state, spawns subagent, and returns handle.
|
|
173
|
+
*/
|
|
174
|
+
startWorkflow: <TResult>(spec: SubagentWorkflowSpec<TResult>, options: {
|
|
175
|
+
parentSessionId: string;
|
|
176
|
+
workspaceDir?: string;
|
|
177
|
+
taskInput: unknown;
|
|
178
|
+
metadata?: Record<string, unknown>;
|
|
179
|
+
}) => Promise<WorkflowHandle>;
|
|
180
|
+
/**
|
|
181
|
+
* Notify workflow of wait result (runtime_direct path).
|
|
182
|
+
* Called by the wait polling logic after waitForRun completes.
|
|
183
|
+
*/
|
|
184
|
+
notifyWaitResult: (workflowId: string, status: 'ok' | 'error' | 'timeout', error?: string) => Promise<void>;
|
|
185
|
+
/**
|
|
186
|
+
* Optional fallback observation path.
|
|
187
|
+
* This is not the primary completion contract for runtime_direct workflows.
|
|
188
|
+
* Use it only for recovery / compatibility if a lifecycle event is observed later.
|
|
189
|
+
*/
|
|
190
|
+
notifyLifecycleEvent: (workflowId: string, event: 'subagent_spawned' | 'subagent_ended', data?: {
|
|
191
|
+
outcome?: 'ok' | 'error' | 'timeout' | 'killed' | 'reset' | 'deleted';
|
|
192
|
+
error?: string;
|
|
193
|
+
}) => Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* Finalize a workflow exactly once (idempotent).
|
|
196
|
+
* Reads result, parses, persists, and cleans up.
|
|
197
|
+
*/
|
|
198
|
+
finalizeOnce: (workflowId: string) => Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* Sweep expired workflows (orphan cleanup).
|
|
201
|
+
* Should be called periodically by the evolution worker.
|
|
202
|
+
*/
|
|
203
|
+
sweepExpiredWorkflows: (maxAgeMs?: number) => Promise<number>;
|
|
204
|
+
/**
|
|
205
|
+
* Return a compact workflow-centric debug view for operators.
|
|
206
|
+
*/
|
|
207
|
+
getWorkflowDebugSummary: (workflowId: string, eventLimit?: number) => Promise<WorkflowDebugSummary | null>;
|
|
208
|
+
/**
|
|
209
|
+
* Release resources (DB connections, timers).
|
|
210
|
+
*/
|
|
211
|
+
dispose: () => void;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Database row for subagent_workflows table.
|
|
215
|
+
*/
|
|
216
|
+
export interface WorkflowRow {
|
|
217
|
+
workflow_id: string;
|
|
218
|
+
workflow_type: string;
|
|
219
|
+
transport: WorkflowTransport;
|
|
220
|
+
parent_session_id: string;
|
|
221
|
+
child_session_key: string;
|
|
222
|
+
run_id: string | null;
|
|
223
|
+
state: WorkflowState;
|
|
224
|
+
cleanup_state: 'none' | 'pending' | 'failed' | 'completed';
|
|
225
|
+
created_at: number;
|
|
226
|
+
updated_at: number;
|
|
227
|
+
last_observed_at?: number | null;
|
|
228
|
+
duration_ms: number | null;
|
|
229
|
+
metadata_json: string;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Database row for subagent_workflow_events table.
|
|
233
|
+
*/
|
|
234
|
+
export interface WorkflowEventRow {
|
|
235
|
+
workflow_id: string;
|
|
236
|
+
event_type: string;
|
|
237
|
+
from_state: WorkflowState | null;
|
|
238
|
+
to_state: WorkflowState;
|
|
239
|
+
reason: string;
|
|
240
|
+
payload_json: string;
|
|
241
|
+
created_at: number;
|
|
242
|
+
}
|
|
243
|
+
export interface WorkflowDebugSummary {
|
|
244
|
+
workflowId: string;
|
|
245
|
+
workflowType: string;
|
|
246
|
+
transport: WorkflowTransport;
|
|
247
|
+
parentSessionId: string;
|
|
248
|
+
childSessionKey: string;
|
|
249
|
+
runId: string | null;
|
|
250
|
+
state: WorkflowState;
|
|
251
|
+
cleanupState: 'none' | 'pending' | 'failed' | 'completed';
|
|
252
|
+
lastObservedAt: number | null;
|
|
253
|
+
metadata: WorkflowMetadata;
|
|
254
|
+
recentEvents: {
|
|
255
|
+
eventType: string;
|
|
256
|
+
fromState: WorkflowState | null;
|
|
257
|
+
toState: WorkflowState;
|
|
258
|
+
reason: string;
|
|
259
|
+
createdAt: number;
|
|
260
|
+
payload: Record<string, unknown>;
|
|
261
|
+
}[];
|
|
262
|
+
}
|
|
263
|
+
export type { SubagentRunResult, SubagentWaitResult, SubagentGetSessionMessagesResult, } from '../../openclaw-sdk.js';
|
|
264
|
+
export type { PluginLogger } from '../../openclaw-sdk.js';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { WorkflowRow, WorkflowEventRow, WorkflowState } from './types.js';
|
|
2
|
+
export interface WorkflowStoreOptions {
|
|
3
|
+
workspaceDir: string;
|
|
4
|
+
busyTimeoutMs?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class WorkflowStore {
|
|
7
|
+
private readonly workspaceDir;
|
|
8
|
+
private readonly dbPath;
|
|
9
|
+
private readonly db;
|
|
10
|
+
constructor(opts: WorkflowStoreOptions);
|
|
11
|
+
dispose(): void;
|
|
12
|
+
private initSchema;
|
|
13
|
+
private runMigrations;
|
|
14
|
+
createWorkflow(row: Omit<WorkflowRow, 'cleanup_state'>): void;
|
|
15
|
+
updateWorkflowState(workflowId: string, state: WorkflowState, reason?: string): void;
|
|
16
|
+
updateWorkflowRunId(workflowId: string, runId: string): void;
|
|
17
|
+
updateCleanupState(workflowId: string, cleanupState: 'none' | 'pending' | 'failed' | 'completed'): void;
|
|
18
|
+
touchWorkflow(workflowId: string): void;
|
|
19
|
+
getWorkflow(workflowId: string): WorkflowRow | null;
|
|
20
|
+
getWorkflowByChildSession(childSessionKey: string): WorkflowRow | null;
|
|
21
|
+
getWorkflowByParentSession(parentSessionId: string, workflowType?: string): WorkflowRow | null;
|
|
22
|
+
getActiveWorkflows(workflowType?: string): WorkflowRow[];
|
|
23
|
+
getExpiredWorkflows(maxAgeMs: number): WorkflowRow[];
|
|
24
|
+
listWorkflows(state?: string): WorkflowRow[];
|
|
25
|
+
recordEvent(workflowId: string, eventType: string, fromState: WorkflowState | null, toState: WorkflowState, reason: string, payload: Record<string, unknown>): void;
|
|
26
|
+
getEvents(workflowId: string): WorkflowEventRow[];
|
|
27
|
+
deleteWorkflow(workflowId: string): void;
|
|
28
|
+
recordDuration(workflowId: string, durationMs: number): void;
|
|
29
|
+
getCompletionDurations(workflowType: string, limit?: number): number[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Initialize subagent_workflows.db schema at the given workspace directory.
|
|
33
|
+
*
|
|
34
|
+
* Opens the DB in write mode, applies the full schema (tables + indexes + migrations),
|
|
35
|
+
* then closes the DB. Used by `pd runtime init` for unified DB initialization.
|
|
36
|
+
*
|
|
37
|
+
* Idempotent: safe to call on an existing DB; all CREATE statements use IF NOT EXISTS.
|
|
38
|
+
*
|
|
39
|
+
* @returns list of created/verified table names and any warnings
|
|
40
|
+
*/
|
|
41
|
+
export declare function initWorkflowSchema(workspaceDir: string): {
|
|
42
|
+
tables: string[];
|
|
43
|
+
warnings: string[];
|
|
44
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow Watchdog - Extracted from evolution-worker.ts (lines 79-223)
|
|
3
|
+
*
|
|
4
|
+
* Detects stale/orphaned workflows, invalid results, and cleanup failures.
|
|
5
|
+
* Runs every heartbeat cycle, catching bugs like:
|
|
6
|
+
* #185 — orphaned active workflows
|
|
7
|
+
* #181 — structurally invalid results (all zeros)
|
|
8
|
+
* #180/#183 — expired workflows not swept
|
|
9
|
+
* #182 — unhandled rejections leaving workflows in limbo
|
|
10
|
+
*
|
|
11
|
+
* BUG-01: isExpectedSubagentError guard prevents marking daemon-mode stale
|
|
12
|
+
* workflows as terminal_error (line 122)
|
|
13
|
+
* BUG-02: Gateway fallback cleans up child sessions via agentSession when
|
|
14
|
+
* subagentRuntime unavailable (lines 148-156)
|
|
15
|
+
*/
|
|
16
|
+
import type { WorkspaceContext } from '../core/workspace-context.js';
|
|
17
|
+
import type { OpenClawPluginApi, PluginLogger } from '../openclaw-sdk.js';
|
|
18
|
+
export interface WatchdogResult {
|
|
19
|
+
anomalies: number;
|
|
20
|
+
details: string[];
|
|
21
|
+
scanError?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function runWorkflowWatchdog(wctx: WorkspaceContext, api: OpenClawPluginApi | null, logger?: PluginLogger): Promise<WatchdogResult>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type { EventType, EventCategory, EventLogEntry, ToolCallEventData, PainSignalEventData, RulePromotionEventData, HookExecutionEventData, GateBlockEventData, GateBypassEventData, PlanApprovalEventData, EvolutionTaskEventData, EmpathyRollbackEventData, HeartbeatDiagnosisEventData, DiagnosisTaskEventData, DiagnosticianReportEventData, PrincipleCandidateEventData, RuleEnforcedEventData, RuleHostEvaluatedEventData, RuleHostBlockedEventData, RuleHostRequireApprovalEventData, RuleHostAutoCorrectProposedEventData, RuleHostAutoCorrectAppliedEventData, RuntimeV2PromptActivationsInjectedEventData, RuleHostUnhealthyEventData, RuleHostSkippedEventData, ToolCallStats, ErrorStats, EmpathyEventStats, GfiStats, EvolutionStats as EventEvolutionStats, HookStats, DailyStats, } from '@principles/core/runtime-v2';
|
|
2
|
+
export { createEmptyDailyStats, } from '@principles/core/runtime-v2';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Principle-Tree Schema Design
|
|
3
|
+
*
|
|
4
|
+
* Concept: Principles are the root of a tree that branches into Rules
|
|
5
|
+
* and eventually into concrete Implementations (code, skills, LoRA weights).
|
|
6
|
+
*
|
|
7
|
+
* A principle without supporting rules is an empty concept — LLM may ignore it.
|
|
8
|
+
* A rule without a parent principle lacks strategic direction.
|
|
9
|
+
*
|
|
10
|
+
* Lifecycle:
|
|
11
|
+
* Pain Signal → Diagnosis → Principle (root)
|
|
12
|
+
* ↓
|
|
13
|
+
* Rule (trunk)
|
|
14
|
+
* ↓
|
|
15
|
+
* Implementation (leaf)
|
|
16
|
+
* ↓
|
|
17
|
+
* Rule 100% covered → Principle deprecated
|
|
18
|
+
*
|
|
19
|
+
* User Focus:
|
|
20
|
+
* - Monitor new principles added by diagnostician
|
|
21
|
+
* - Monitor principles deprecated (solidified into code/weights)
|
|
22
|
+
* - Track principle value ranking (pain prevented, adherence rate)
|
|
23
|
+
*/
|
|
24
|
+
import type { Principle as CorePrinciple } from '@principles/core/runtime-v2';
|
|
25
|
+
import type { PrincipleDetectorSpec } from '../core/evolution-types.js';
|
|
26
|
+
export type { PrinciplePriority, PrincipleScope, PrincipleEvaluability, RuleStatus, RuleType, ImplementationLifecycleState, ImplementationType, Rule, Implementation, PrincipleDependency, PrincipleValueMetrics, PrincipleEventType, PrincipleLifecycleEvent, PrincipleTreeStore, } from '@principles/core/runtime-v2';
|
|
27
|
+
export interface Principle extends CorePrinciple {
|
|
28
|
+
detectorMetadata?: PrincipleDetectorSpec;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { RuntimeTruth, AnalyticsTruth, TrendMetrics, } from '@principles/core/runtime-v2';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type { PluginCommandContext, PluginCommandResult } from './openclaw-sdk.js';
|
|
2
|
+
export type { ContextInjectionConfig, EvolutionContextConfig, ProjectFocusMode, } from '@principles/core';
|
|
3
|
+
/**
|
|
4
|
+
* Default context injection configuration
|
|
5
|
+
* Based on MVP-first strategy (ADR-0014):
|
|
6
|
+
* - principles: always on (not configurable)
|
|
7
|
+
* - thinkingOs: false by default (MVP-Quiet, user can opt-in via /pd-context)
|
|
8
|
+
* - projectFocus: 'off' (default closed, user can enable)
|
|
9
|
+
*
|
|
10
|
+
* Migrated to DEFAULT_CONTEXT_INJECTION in @principles/core.
|
|
11
|
+
* Re-exported for backward compatibility.
|
|
12
|
+
*/
|
|
13
|
+
export { DEFAULT_CONTEXT_INJECTION as defaultContextConfig } from '@principles/core';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export interface LockOptions {
|
|
2
|
+
/** 最大重试次数,默认 50 */
|
|
3
|
+
maxRetries?: number;
|
|
4
|
+
/** 基础重试延迟(ms),默认 10 */
|
|
5
|
+
baseRetryDelayMs?: number;
|
|
6
|
+
/** 最大重试延迟(ms),默认 500 */
|
|
7
|
+
maxRetryDelayMs?: number;
|
|
8
|
+
/** 锁过期时间(ms),默认 10000 (10秒) */
|
|
9
|
+
lockStaleMs?: number;
|
|
10
|
+
/** 锁文件后缀,默认 '.lock' */
|
|
11
|
+
lockSuffix?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface LockContext {
|
|
14
|
+
/** 锁文件路径 */
|
|
15
|
+
lockPath: string;
|
|
16
|
+
/** 持有锁的 PID */
|
|
17
|
+
pid: number;
|
|
18
|
+
/** 获取锁的时间 */
|
|
19
|
+
acquiredAt: number;
|
|
20
|
+
}
|
|
21
|
+
export declare class LockAcquisitionError extends Error {
|
|
22
|
+
readonly filePath: string;
|
|
23
|
+
readonly lockPath: string;
|
|
24
|
+
constructor(message: string, filePath: string, lockPath: string);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 获取文件锁
|
|
28
|
+
*
|
|
29
|
+
* @param filePath 要锁定的文件路径
|
|
30
|
+
* @param options 锁选项
|
|
31
|
+
* @returns 锁上下文(用于后续释放)
|
|
32
|
+
* @throws Error 如果无法获取锁
|
|
33
|
+
*/
|
|
34
|
+
export declare function acquireLock(filePath: string, options?: LockOptions): LockContext;
|
|
35
|
+
export declare function acquireLockAsync(filePath: string, options?: LockOptions): Promise<LockContext>;
|
|
36
|
+
/**
|
|
37
|
+
* 释放文件锁
|
|
38
|
+
*
|
|
39
|
+
* @param ctx 锁上下文(由 acquireLock 返回)
|
|
40
|
+
*/
|
|
41
|
+
export declare function releaseLock(ctx: LockContext): void;
|
|
42
|
+
/**
|
|
43
|
+
* 使用锁执行操作(自动获取和释放)
|
|
44
|
+
*
|
|
45
|
+
* @param filePath 要锁定的文件路径
|
|
46
|
+
* @param fn 要执行的操作
|
|
47
|
+
* @param options 锁选项
|
|
48
|
+
* @returns 操作的返回值
|
|
49
|
+
*/
|
|
50
|
+
export declare function withLock<T>(filePath: string, fn: () => T, options?: LockOptions): T;
|
|
51
|
+
export declare function withLockAsync<T>(filePath: string, fn: () => Promise<T>, options?: LockOptions): Promise<T>;
|
|
52
|
+
/**
|
|
53
|
+
* 异步版本的文件锁(使用 Promise 链)
|
|
54
|
+
*
|
|
55
|
+
* 注意:这是一个简化的实现,适用于单进程内的异步并发控制
|
|
56
|
+
* 对于多进程场景,应使用同步版本的 acquireLock
|
|
57
|
+
*/
|
|
58
|
+
export declare const asyncLockQueues: Map<string, Promise<void>>;
|
|
59
|
+
export declare function withAsyncLock<T>(filePath: string, fn: () => Promise<T>): Promise<T>;
|
|
60
|
+
/**
|
|
61
|
+
* 检查锁状态(用于调试)
|
|
62
|
+
*/
|
|
63
|
+
export declare function getLockStatus(filePath: string, options?: LockOptions): {
|
|
64
|
+
locked: boolean;
|
|
65
|
+
holderPid: number | null;
|
|
66
|
+
holderAlive: boolean;
|
|
67
|
+
lockAge: number | null;
|
|
68
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strips timestamps, UUIDs, and hex memory addresses from error messages
|
|
3
|
+
* to allow for consistent loop detection even if the raw text varies slightly.
|
|
4
|
+
*/
|
|
5
|
+
export declare function denoiseError(text: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Computes a simple SHA-256 hash of the given string.
|
|
8
|
+
*/
|
|
9
|
+
export declare function computeHash(text: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function atomicWriteFileSync(filePath: string, data: string): void;
|
|
2
|
+
export declare function normalizePath(filePath: string, projectDir: string): string;
|
|
3
|
+
export declare function normalizeRiskPath(p: string): string;
|
|
4
|
+
export declare function isRisky(relPath: string, riskPaths: string[]): boolean;
|
|
5
|
+
export declare function parseKvLines(text: string): Record<string, string>;
|
|
6
|
+
export declare function serializeKvLines(data: Record<string, any>): string;
|
|
7
|
+
/**
|
|
8
|
+
* Normalize command arguments from PluginCommandContext.args.
|
|
9
|
+
* Handles string | string[] | undefined union by joining arrays with spaces.
|
|
10
|
+
*/
|
|
11
|
+
export declare function normalizeCommandArgs(args: string | string[] | undefined): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node VM Polyfill — Thin wrapper around node:vm module
|
|
3
|
+
*
|
|
4
|
+
* PURPOSE: Provide a single import point for vm compilation functionality
|
|
5
|
+
* used by the Rule Host. Isolates the node:vm dependency so it can be
|
|
6
|
+
* easily mocked in tests.
|
|
7
|
+
*/
|
|
8
|
+
import * as vm from 'node:vm';
|
|
9
|
+
export declare const nodeVm: typeof vm;
|