create-principles-disciple 1.135.2 → 1.136.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.
Files changed (51) hide show
  1. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +5 -3
  2. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
  3. package/core/package.json +1 -1
  4. package/package.json +2 -2
  5. package/pd-cli/dist/commands/errors-list.d.ts.map +1 -1
  6. package/pd-cli/dist/commands/errors-list.js +9 -10
  7. package/pd-cli/dist/commands/errors-list.js.map +1 -1
  8. package/pd-cli/dist/commands/pain-list.d.ts +14 -0
  9. package/pd-cli/dist/commands/pain-list.d.ts.map +1 -1
  10. package/pd-cli/dist/commands/pain-list.js +28 -1
  11. package/pd-cli/dist/commands/pain-list.js.map +1 -1
  12. package/pd-cli/dist/commands/pain-record.d.ts +2 -0
  13. package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
  14. package/pd-cli/dist/commands/pain-record.js +71 -4
  15. package/pd-cli/dist/commands/pain-record.js.map +1 -1
  16. package/pd-cli/dist/commands/runtime-init.d.ts +3 -1
  17. package/pd-cli/dist/commands/runtime-init.d.ts.map +1 -1
  18. package/pd-cli/dist/commands/runtime-init.js +7 -47
  19. package/pd-cli/dist/commands/runtime-init.js.map +1 -1
  20. package/pd-cli/dist/index.js +2 -1
  21. package/pd-cli/dist/index.js.map +1 -1
  22. package/pd-cli/package.json +1 -1
  23. package/plugin/dist/bundle.js +562 -682
  24. package/plugin/dist/config/defaults/runtime.d.ts +0 -10
  25. package/plugin/dist/core/config.d.ts +0 -9
  26. package/plugin/dist/core/detection-funnel.d.ts +1 -1
  27. package/plugin/dist/core/paths.d.ts +0 -2
  28. package/plugin/dist/core/principle-tree-ledger.d.ts +1 -1
  29. package/plugin/dist/core/system-logger.d.ts +1 -3
  30. package/plugin/dist/index.d.ts +0 -10
  31. package/plugin/dist/rulehost-evidence.js +28 -28
  32. package/plugin/dist/service/keyword-optimization-service.d.ts +2 -2
  33. package/plugin/dist/templates/pain_settings.json +0 -5
  34. package/plugin/dist/utils/trace-id.d.ts +9 -0
  35. package/plugin/docs/COMMAND_REFERENCE.md +2 -3
  36. package/plugin/docs/COMMAND_REFERENCE_EN.md +1 -2
  37. package/plugin/openclaw.plugin.json +1 -1
  38. package/plugin/package.json +1 -1
  39. package/plugin/templates/pain_settings.json +0 -5
  40. package/release-manager/package.json +2 -2
  41. package/plugin/dist/commands/workflow-debug.d.ts +0 -4
  42. package/plugin/dist/core/evolution-engine.d.ts +0 -119
  43. package/plugin/dist/core/evolution-logger.d.ts +0 -137
  44. package/plugin/dist/service/evolution-dedup.d.ts +0 -27
  45. package/plugin/dist/service/evolution-worker.d.ts +0 -105
  46. package/plugin/dist/service/queue-io.d.ts +0 -30
  47. package/plugin/dist/service/queue-migration.d.ts +0 -84
  48. package/plugin/dist/service/subagent-workflow/subagent-error-utils.d.ts +0 -8
  49. package/plugin/dist/service/subagent-workflow/types.d.ts +0 -264
  50. package/plugin/dist/service/subagent-workflow/workflow-store.d.ts +0 -44
  51. package/plugin/dist/service/workflow-watchdog.d.ts +0 -23
@@ -1,264 +0,0 @@
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, 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) 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';
@@ -1,44 +0,0 @@
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
- };
@@ -1,23 +0,0 @@
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>;