principles-disciple 1.201.1 → 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/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,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evolution Queue Deduplication Utilities
|
|
3
|
+
*
|
|
4
|
+
* Dedup logic for preventing duplicate pain tasks and redundant reflections.
|
|
5
|
+
* Extracted from evolution-worker.ts.
|
|
6
|
+
*/
|
|
7
|
+
import type { EvolutionQueueItem } from '../core/evolution-types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Dedup window for pain queue tasks (30 minutes).
|
|
10
|
+
*/
|
|
11
|
+
export declare const PAIN_QUEUE_DEDUP_WINDOW_MS: number;
|
|
12
|
+
export declare function findRecentDuplicateTask(queue: EvolutionQueueItem[], source: string, preview: string, now: number, reason?: string): EvolutionQueueItem | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Check if a similar pain task was enqueued recently.
|
|
15
|
+
*/
|
|
16
|
+
export declare function hasRecentDuplicateTask(queue: EvolutionQueueItem[], source: string, preview: string, now: number, reason?: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Check if a phrase matches an active promoted rule.
|
|
19
|
+
*/
|
|
20
|
+
export declare function hasEquivalentPromotedRule(dictionary: {
|
|
21
|
+
getAllRules(): Record<string, {
|
|
22
|
+
type: string;
|
|
23
|
+
phrases?: string[];
|
|
24
|
+
pattern?: string;
|
|
25
|
+
status: string;
|
|
26
|
+
}>;
|
|
27
|
+
}, phrase: string): boolean;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { OpenClawPluginServiceContext, OpenClawPluginApi, PluginLogger } from '../openclaw-sdk.js';
|
|
2
|
+
import { WorkspaceContext } from '../core/workspace-context.js';
|
|
3
|
+
export type { TaskKind, TaskPriority } from '../core/trajectory-types.js';
|
|
4
|
+
export { loadEvolutionQueue, saveEvolutionQueue, withQueueLock, acquireQueueLock, requireQueueLock } from './queue-io.js';
|
|
5
|
+
export { EVOLUTION_QUEUE_LOCK_SUFFIX, LOCK_MAX_RETRIES, LOCK_RETRY_DELAY_MS, LOCK_STALE_MS } from './queue-io.js';
|
|
6
|
+
/**
|
|
7
|
+
* Validates a queue event payload string before JSON.parse.
|
|
8
|
+
* Checks:
|
|
9
|
+
* 1. typeof payload === 'string'
|
|
10
|
+
* 2. Parsed object has required fields: 'type' and 'workspaceId'
|
|
11
|
+
* Returns the parsed object only if validation passes.
|
|
12
|
+
* Returns empty object {} if payload is falsy.
|
|
13
|
+
* Throws Error if payload is a non-empty string that fails validation.
|
|
14
|
+
*/
|
|
15
|
+
declare function validateQueueEventPayload(payload: string | null | undefined): Record<string, unknown>;
|
|
16
|
+
export { validateQueueEventPayload };
|
|
17
|
+
import { runWorkflowWatchdog, type WatchdogResult } from './workflow-watchdog.js';
|
|
18
|
+
export { runWorkflowWatchdog };
|
|
19
|
+
export type { WatchdogResult };
|
|
20
|
+
/**
|
|
21
|
+
* Queue V2 Schema - Supports background evolution task kinds.
|
|
22
|
+
*
|
|
23
|
+
* Pain diagnosis is Runtime v2 only: after_tool_call / pd pain record ->
|
|
24
|
+
* PainSignalBridge -> SplitDiagnosticianRunner. EvolutionWorker does not read
|
|
25
|
+
* .pain_flag or process pain_diagnosis queue items.
|
|
26
|
+
*
|
|
27
|
+
* Types (QueueStatus / TaskResolution / EvolutionQueueItem) are re-exported
|
|
28
|
+
* from queue-migration.ts, which sources them from evolution-types.ts
|
|
29
|
+
* (canonical single source of truth).
|
|
30
|
+
*/
|
|
31
|
+
export type { QueueStatus, TaskResolution, EvolutionQueueItem } from './queue-migration.js';
|
|
32
|
+
import { migrateToV2, isLegacyQueueItem, migrateQueueToV2, LegacyEvolutionQueueItem, DEFAULT_TASK_KIND, DEFAULT_PRIORITY, DEFAULT_MAX_RETRIES, validateQueueItem, VALID_TASK_KINDS, isValidQueueItem, type RawQueueItem, type EvolutionQueueItem } from './queue-migration.js';
|
|
33
|
+
export { migrateToV2, isLegacyQueueItem, migrateQueueToV2, LegacyEvolutionQueueItem, DEFAULT_TASK_KIND, DEFAULT_PRIORITY, DEFAULT_MAX_RETRIES, validateQueueItem, VALID_TASK_KINDS, isValidQueueItem };
|
|
34
|
+
export type { RawQueueItem };
|
|
35
|
+
export declare function extractEvolutionTaskId(task: string): string | null;
|
|
36
|
+
export declare function purgeStaleFailedTasks(queue: EvolutionQueueItem[], logger: PluginLogger): {
|
|
37
|
+
purged: number;
|
|
38
|
+
remaining: number;
|
|
39
|
+
byReason: Record<string, number>;
|
|
40
|
+
};
|
|
41
|
+
export declare function hasRecentDuplicateTask(queue: EvolutionQueueItem[], source: string, preview: string, now: number, reason?: string): boolean;
|
|
42
|
+
export declare function hasEquivalentPromotedRule(dictionary: {
|
|
43
|
+
getAllRules(): Record<string, {
|
|
44
|
+
type: string;
|
|
45
|
+
phrases?: string[];
|
|
46
|
+
pattern?: string;
|
|
47
|
+
status: string;
|
|
48
|
+
}>;
|
|
49
|
+
}, phrase: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Process compilation backfill and retry loop.
|
|
52
|
+
* Phase 1 — Backfill: on first call, scan for old principles (compilationRetryCount === undefined)
|
|
53
|
+
* with evaluability !== 'manual_only' and no active implementation, queue them (set to 0).
|
|
54
|
+
* Phase 2 — Retry: compile all principles with compilationRetryCount >= 0.
|
|
55
|
+
* After 5 consecutive failures, downgrades to manual_only and logs COMPILE_EXHAUSTED.
|
|
56
|
+
*/
|
|
57
|
+
export declare function processCompilationBackfill(wctx: WorkspaceContext, logger: PluginLogger, workerStatus?: WorkerStatusReport): Promise<void>;
|
|
58
|
+
export declare function registerEvolutionTaskSession(workspaceResolve: (key: string) => string, taskId: string, sessionKey: string, logger?: {
|
|
59
|
+
warn?: (message: string) => void;
|
|
60
|
+
info?: (message: string) => void;
|
|
61
|
+
}): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Evolution Worker - Background service for pain processing and evolution task management.
|
|
64
|
+
*
|
|
65
|
+
* IMPORTANT: evolution_directive.json is a COMPATIBILITY-ONLY DISPLAY ARTIFACT.
|
|
66
|
+
* This service does NOT read or use directive for Phase 3 eligibility or any decisions.
|
|
67
|
+
* Queue (EVOLUTION_QUEUE) is the only authoritative execution truth source.
|
|
68
|
+
*
|
|
69
|
+
* Directive exists solely for UI/backwards compatibility display purposes.
|
|
70
|
+
* Production evidence shows directive stopped updating on 2026-03-22 and is stale.
|
|
71
|
+
*/
|
|
72
|
+
export interface ExtendedEvolutionWorkerService {
|
|
73
|
+
id: string;
|
|
74
|
+
api: OpenClawPluginApi | null;
|
|
75
|
+
_startedWorkspaces: Set<string>;
|
|
76
|
+
start: (ctx: OpenClawPluginServiceContext) => void | Promise<void>;
|
|
77
|
+
stop?: (ctx: OpenClawPluginServiceContext) => void | Promise<void>;
|
|
78
|
+
}
|
|
79
|
+
export interface WorkerStatusErrorEntry {
|
|
80
|
+
at: string;
|
|
81
|
+
kind: 'retry_count_update_failed' | 'principle_update_failed';
|
|
82
|
+
principleId: string;
|
|
83
|
+
error: string;
|
|
84
|
+
}
|
|
85
|
+
export interface WorkerStatusReport {
|
|
86
|
+
timestamp: string;
|
|
87
|
+
cycle_start_ms: number;
|
|
88
|
+
duration_ms: number;
|
|
89
|
+
pain_flag: {
|
|
90
|
+
exists: boolean;
|
|
91
|
+
score: number | null;
|
|
92
|
+
source: string | null;
|
|
93
|
+
enqueued: boolean;
|
|
94
|
+
skipped_reason: string | null;
|
|
95
|
+
};
|
|
96
|
+
queue: {
|
|
97
|
+
total: number;
|
|
98
|
+
pending: number;
|
|
99
|
+
in_progress: number;
|
|
100
|
+
completed_this_cycle: number;
|
|
101
|
+
failed_this_cycle: number;
|
|
102
|
+
};
|
|
103
|
+
errors: (string | WorkerStatusErrorEntry)[];
|
|
104
|
+
}
|
|
105
|
+
export declare const EvolutionWorkerService: ExtendedEvolutionWorkerService;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { OpenClawPluginServiceContext, PluginLogger } from '../openclaw-sdk.js';
|
|
2
|
+
export interface InternalizationAutoConsumerServiceShape {
|
|
3
|
+
id: string;
|
|
4
|
+
start: (ctx: OpenClawPluginServiceContext) => void;
|
|
5
|
+
stop?: (ctx: OpenClawPluginServiceContext) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function runConsumerCycle(workspaceDir: string, logger: PluginLogger): Promise<void>;
|
|
8
|
+
export declare const InternalizationAutoConsumerService: InternalizationAutoConsumerServiceShape;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyword Optimization Service
|
|
3
|
+
*
|
|
4
|
+
* Applies LLM optimization results (ADD/UPDATE/REMOVE mutations) to the
|
|
5
|
+
* correction keyword store. Called by evolution-worker.ts after the
|
|
6
|
+
* keyword_optimization workflow completes.
|
|
7
|
+
*/
|
|
8
|
+
import type { CorrectionObserverOutputV1 as CorrectionObserverResult } from '@principles/core/runtime-v2';
|
|
9
|
+
import type { PluginLogger } from '../openclaw-sdk.js';
|
|
10
|
+
/**
|
|
11
|
+
* Applies CorrectionObserverResult mutations to the keyword store.
|
|
12
|
+
* - ADD: calls learner.add() with new keyword
|
|
13
|
+
* - UPDATE: updates weight on existing keyword
|
|
14
|
+
* - REMOVE: removes keyword from store
|
|
15
|
+
*/
|
|
16
|
+
export declare class KeywordOptimizationService {
|
|
17
|
+
private readonly stateDir;
|
|
18
|
+
private readonly workspaceDir;
|
|
19
|
+
private readonly logger;
|
|
20
|
+
constructor(stateDir: string, workspaceDir: string, logger: PluginLogger);
|
|
21
|
+
applyResult(result: CorrectionObserverResult): void;
|
|
22
|
+
/**
|
|
23
|
+
* Builds trajectory history for payload:
|
|
24
|
+
* - Calls TrajectoryDatabase.listUserTurnsForSession() for recent sessions
|
|
25
|
+
* - Filters to turns where correctionDetected=true
|
|
26
|
+
* - Returns last 50 correction events
|
|
27
|
+
*/
|
|
28
|
+
buildTrajectoryHistory(sessionIds: string[]): Promise<TrajectoryHistoryEntry[]>;
|
|
29
|
+
private static _instances;
|
|
30
|
+
static get(stateDir: string, workspaceDir: string, logger: PluginLogger): KeywordOptimizationService;
|
|
31
|
+
static reset(): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Internal type mirroring the trajectoryHistory field in CorrectionObserverPayload.
|
|
35
|
+
* Exported here so buildTrajectoryHistory can reference it without a circular import.
|
|
36
|
+
*/
|
|
37
|
+
export type TrajectoryHistoryEntry = {
|
|
38
|
+
sessionId: string;
|
|
39
|
+
timestamp: string;
|
|
40
|
+
term: string;
|
|
41
|
+
userMessage: string;
|
|
42
|
+
};
|
|
43
|
+
/** Re-export CorrectionObserverPayload for convenience */
|
|
44
|
+
export type { CorrectionObserverPayload } from '@principles/core/runtime-v2';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 3 Input Filter
|
|
3
|
+
*
|
|
4
|
+
* CRITICAL: evaluatePhase3Inputs() does NOT read or use evolution_directive.json
|
|
5
|
+
* Directive is a compatibility-only display artifact, not a truth source.
|
|
6
|
+
*
|
|
7
|
+
* Phase 3 eligibility depends ONLY on:
|
|
8
|
+
* - Queue truth (valid evolution samples from queue)
|
|
9
|
+
*
|
|
10
|
+
* Any directive file is ignored for eligibility decisions.
|
|
11
|
+
*
|
|
12
|
+
* THREE-LANE CLASSIFICATION:
|
|
13
|
+
* - authoritative: Valid inputs that can be used for Phase 3 eligibility decisions
|
|
14
|
+
* - reference_only: Valid evidence that must NOT be used as positive eligibility input
|
|
15
|
+
* (e.g., timeout-only outcomes - they indicate completion but not success)
|
|
16
|
+
* - rejected: Invalid, corrupt, or policy-prohibited input
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Classification for Phase 3 inputs.
|
|
20
|
+
* - authoritative: Can be used for Phase 3 eligibility decisions
|
|
21
|
+
* - reference_only: Valid data but not for eligibility (e.g., timeout outcomes)
|
|
22
|
+
* - rejected: Invalid or corrupt data
|
|
23
|
+
*/
|
|
24
|
+
export type Phase3Classification = 'authoritative' | 'reference_only' | 'rejected';
|
|
25
|
+
export interface Phase3EvolutionInput {
|
|
26
|
+
id?: string | null;
|
|
27
|
+
status?: string | null;
|
|
28
|
+
started_at?: string | null;
|
|
29
|
+
completed_at?: string | null;
|
|
30
|
+
resolution?: string | null;
|
|
31
|
+
}
|
|
32
|
+
export interface Phase3EvolutionSample {
|
|
33
|
+
taskId: string;
|
|
34
|
+
status: 'pending' | 'in_progress' | 'completed';
|
|
35
|
+
startedAt: string | null;
|
|
36
|
+
completedAt: string | null;
|
|
37
|
+
}
|
|
38
|
+
export interface Phase3ReferenceOnlySample {
|
|
39
|
+
taskId: string;
|
|
40
|
+
status: string;
|
|
41
|
+
classification: 'timeout_only' | 'other_reference';
|
|
42
|
+
reason: string;
|
|
43
|
+
}
|
|
44
|
+
export interface Phase3RejectedEvolutionSample {
|
|
45
|
+
taskId: string | null;
|
|
46
|
+
status: string | null;
|
|
47
|
+
reasons: string[];
|
|
48
|
+
}
|
|
49
|
+
export interface Phase3InputFilterResult {
|
|
50
|
+
queueTruthReady: boolean;
|
|
51
|
+
phase3ShadowEligible: boolean;
|
|
52
|
+
evolution: {
|
|
53
|
+
eligible: Phase3EvolutionSample[];
|
|
54
|
+
referenceOnly: Phase3ReferenceOnlySample[];
|
|
55
|
+
rejected: Phase3RejectedEvolutionSample[];
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Evaluates Phase 3 readiness based on queue inputs.
|
|
60
|
+
*
|
|
61
|
+
* IMPORTANT: Does NOT use evolution_directive.json.
|
|
62
|
+
* Directive is compatibility-only display artifact, not a truth source.
|
|
63
|
+
* Queue is the only authoritative execution truth source for Phase 3.
|
|
64
|
+
*
|
|
65
|
+
* THREE-LANE CLASSIFICATION:
|
|
66
|
+
* - authoritative: Valid inputs for Phase 3 eligibility
|
|
67
|
+
* - reference_only: Valid evidence but not for eligibility (e.g., timeout outcomes)
|
|
68
|
+
* - rejected: Invalid, corrupt, or policy-prohibited input
|
|
69
|
+
*
|
|
70
|
+
* @param queue - Evolution queue items to validate
|
|
71
|
+
* @returns Phase 3 eligibility results
|
|
72
|
+
*/
|
|
73
|
+
export declare function evaluatePhase3Inputs(queue: Phase3EvolutionInput[]): Phase3InputFilterResult;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Queue I/O + Enqueue — extracted from evolution-worker.ts
|
|
3
|
+
*
|
|
4
|
+
* Full persistence layer encapsulating queue file locking, atomic writes,
|
|
5
|
+
* queue format, and enqueue orchestration. Depends on file-lock.ts, io.ts,
|
|
6
|
+
* queue-migration.ts, and pain.ts.
|
|
7
|
+
* Zero imports from evolution-worker.ts.
|
|
8
|
+
*/
|
|
9
|
+
import type { EvolutionQueueItem } from '../core/evolution-types.js';
|
|
10
|
+
import type { PluginLogger } from '../openclaw-sdk.js';
|
|
11
|
+
export declare const EVOLUTION_QUEUE_LOCK_SUFFIX = ".lock";
|
|
12
|
+
export declare const LOCK_MAX_RETRIES = 50;
|
|
13
|
+
export declare const LOCK_RETRY_DELAY_MS = 50;
|
|
14
|
+
export declare const LOCK_STALE_MS = 30000;
|
|
15
|
+
export declare function requireQueueLock(resourcePath: string, logger: PluginLogger | {
|
|
16
|
+
warn?: (message: string) => void;
|
|
17
|
+
info?: (message: string) => void;
|
|
18
|
+
} | undefined, scope: string, lockSuffix?: string): Promise<() => void>;
|
|
19
|
+
export declare function createEvolutionTaskId(source: string, score: number, preview: string, reason: string, now: number): string;
|
|
20
|
+
export declare function hasPendingTask(queue: EvolutionQueueItem[], taskKind: string): boolean;
|
|
21
|
+
export declare function acquireQueueLock(resourcePath: string, logger: PluginLogger | {
|
|
22
|
+
warn?: (message: string) => void;
|
|
23
|
+
info?: (message: string) => void;
|
|
24
|
+
} | undefined, lockSuffix?: string): Promise<() => void>;
|
|
25
|
+
export declare function withQueueLock<T>(resourcePath: string, logger: PluginLogger | {
|
|
26
|
+
warn?: (message: string) => void;
|
|
27
|
+
info?: (message: string) => void;
|
|
28
|
+
} | undefined, scope: string, fn: () => Promise<T>): Promise<T>;
|
|
29
|
+
export declare function loadEvolutionQueue(queuePath: string): EvolutionQueueItem[];
|
|
30
|
+
export declare function saveEvolutionQueue(queuePath: string, queue: EvolutionQueueItem[]): void;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Queue Migration — extracted from evolution-worker.ts (lines 297-379)
|
|
3
|
+
*
|
|
4
|
+
* Pure data transformation functions for migrating legacy queue items
|
|
5
|
+
* to the V2 schema. Zero I/O, zero imports from evolution-worker.ts.
|
|
6
|
+
*/
|
|
7
|
+
import type { TaskKind, TaskPriority } from '../core/trajectory-types.js';
|
|
8
|
+
import type { EvolutionQueueItem } from '../core/evolution-types.js';
|
|
9
|
+
export type { QueueStatus, TaskResolution, EvolutionQueueItem } from '../core/evolution-types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Legacy queue item shape (pre-V2) for migration compatibility.
|
|
12
|
+
* These items lack taskKind, priority, retryCount, maxRetries, lastError fields.
|
|
13
|
+
*/
|
|
14
|
+
export interface LegacyEvolutionQueueItem {
|
|
15
|
+
id: string;
|
|
16
|
+
task?: string;
|
|
17
|
+
score: number;
|
|
18
|
+
source: string;
|
|
19
|
+
reason: string;
|
|
20
|
+
timestamp: string;
|
|
21
|
+
enqueued_at?: string;
|
|
22
|
+
started_at?: string;
|
|
23
|
+
completed_at?: string;
|
|
24
|
+
assigned_session_key?: string;
|
|
25
|
+
trigger_text_preview?: string;
|
|
26
|
+
status?: string;
|
|
27
|
+
resolution?: string;
|
|
28
|
+
session_id?: string;
|
|
29
|
+
agent_id?: string;
|
|
30
|
+
traceId?: string;
|
|
31
|
+
taskKind?: string;
|
|
32
|
+
priority?: string;
|
|
33
|
+
retryCount?: number;
|
|
34
|
+
maxRetries?: number;
|
|
35
|
+
lastError?: string;
|
|
36
|
+
resultRef?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Default values for new V2 fields when migrating legacy items.
|
|
40
|
+
*/
|
|
41
|
+
declare const DEFAULT_TASK_KIND: TaskKind;
|
|
42
|
+
declare const DEFAULT_PRIORITY: TaskPriority;
|
|
43
|
+
declare const DEFAULT_MAX_RETRIES = 3;
|
|
44
|
+
export { DEFAULT_TASK_KIND, DEFAULT_PRIORITY, DEFAULT_MAX_RETRIES };
|
|
45
|
+
export type RawQueueItem = Record<string, unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* Migrate a legacy queue item to V2 schema.
|
|
48
|
+
* Old items without taskKind are assumed to be pain_diagnosis for backward compatibility.
|
|
49
|
+
*/
|
|
50
|
+
export declare function migrateToV2(item: LegacyEvolutionQueueItem): EvolutionQueueItem;
|
|
51
|
+
/**
|
|
52
|
+
* Check if an item is a legacy (pre-V2) queue item.
|
|
53
|
+
*/
|
|
54
|
+
export declare function isLegacyQueueItem(item: RawQueueItem): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Migrate entire queue to V2 schema if needed.
|
|
57
|
+
* Returns a new array with all items migrated to V2 format.
|
|
58
|
+
*/
|
|
59
|
+
export declare function migrateQueueToV2(queue: RawQueueItem[]): EvolutionQueueItem[];
|
|
60
|
+
/**
|
|
61
|
+
* Canonical set of valid taskKind values. Single source of truth — mirrors
|
|
62
|
+
* TaskKind in trajectory-types.ts. Previously the inline validator in
|
|
63
|
+
* evolution-worker.ts hard-coded `['model_eval']`, which silently rejected
|
|
64
|
+
* three legitimate taskKind values (pain_diagnosis / sleep_reflection /
|
|
65
|
+
* keyword_optimization). Keep this in sync with TaskKind.
|
|
66
|
+
*/
|
|
67
|
+
export declare const VALID_TASK_KINDS: readonly TaskKind[];
|
|
68
|
+
/**
|
|
69
|
+
* Validate a single queue item loaded from untrusted disk JSON.
|
|
70
|
+
*
|
|
71
|
+
* Returns an array of human-readable error reasons; an empty array means the
|
|
72
|
+
* item is valid. Use {@link isValidQueueItem} for a type-guard form.
|
|
73
|
+
*
|
|
74
|
+
* This consolidates the inline validation that lived in processEvolutionQueue
|
|
75
|
+
* (evolution-worker.ts) so every queue load path (loadEvolutionQueue,
|
|
76
|
+
* registerEvolutionTaskSession) applies the same filter. rc-4 (ERR-007):
|
|
77
|
+
* array elements from parsed JSON must be element-wise validated.
|
|
78
|
+
*/
|
|
79
|
+
export declare function validateQueueItem(item: unknown): string[];
|
|
80
|
+
/**
|
|
81
|
+
* Type-guard convenience over {@link validateQueueItem}.
|
|
82
|
+
* Drops the reason strings (callers that need them should call validateQueueItem).
|
|
83
|
+
*/
|
|
84
|
+
export declare function isValidQueueItem(item: unknown): item is EvolutionQueueItem;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { WorkflowStage } from '../core/workflow-funnel-loader.js';
|
|
2
|
+
import type { RuntimeTruth, AnalyticsTruth } from '../types/runtime-summary.js';
|
|
3
|
+
import type { GfiWorkspaceSnapshot } from '@principles/core/runtime-v2';
|
|
4
|
+
export type RuntimeDataQuality = 'authoritative' | 'partial';
|
|
5
|
+
export type RuntimeRewardPolicy = 'frozen_all_positive' | 'frozen_atomic_positive_keep_plan_ready';
|
|
6
|
+
interface RuntimeSummarySource {
|
|
7
|
+
source: string;
|
|
8
|
+
score?: number;
|
|
9
|
+
ts?: string;
|
|
10
|
+
confidence?: number;
|
|
11
|
+
origin?: string;
|
|
12
|
+
}
|
|
13
|
+
interface RuntimePainSignal {
|
|
14
|
+
source: string;
|
|
15
|
+
ts: string | null;
|
|
16
|
+
reason: string | null;
|
|
17
|
+
}
|
|
18
|
+
export interface RuntimeSummary {
|
|
19
|
+
/**
|
|
20
|
+
* Runtime truth represents the current state of the system.
|
|
21
|
+
* Used for control decisions, Phase 3 eligibility, and real-time operations.
|
|
22
|
+
*/
|
|
23
|
+
runtime: RuntimeTruth;
|
|
24
|
+
/**
|
|
25
|
+
* Analytics truth represents historical data and aggregated metrics.
|
|
26
|
+
* Used for insights, trends, and supporting evidence (where explicitly allowed).
|
|
27
|
+
* NOT used for control decisions or Phase 3 eligibility.
|
|
28
|
+
*/
|
|
29
|
+
analytics: AnalyticsTruth;
|
|
30
|
+
gfi: {
|
|
31
|
+
current: number | null;
|
|
32
|
+
peak: number | null;
|
|
33
|
+
sources: RuntimeSummarySource[];
|
|
34
|
+
dataQuality: RuntimeDataQuality;
|
|
35
|
+
workspaceSnapshot?: GfiWorkspaceSnapshot;
|
|
36
|
+
};
|
|
37
|
+
evolution: {
|
|
38
|
+
queue: {
|
|
39
|
+
pending: number;
|
|
40
|
+
inProgress: number;
|
|
41
|
+
completed: number;
|
|
42
|
+
};
|
|
43
|
+
directive: {
|
|
44
|
+
exists: boolean;
|
|
45
|
+
active: boolean | null;
|
|
46
|
+
ageSeconds: number | null;
|
|
47
|
+
taskPreview: string | null;
|
|
48
|
+
};
|
|
49
|
+
dataQuality: RuntimeDataQuality;
|
|
50
|
+
};
|
|
51
|
+
runtimeDiagnosis: {
|
|
52
|
+
/** Tasks pending in diagnostician_tasks.json (not yet processed by heartbeat) */
|
|
53
|
+
pendingTasks: number;
|
|
54
|
+
/** Total diagnosis tasks written by evolution worker (today from event log) */
|
|
55
|
+
tasksWrittenToday: number;
|
|
56
|
+
/** Total diagnostician reports written (today from event log) */
|
|
57
|
+
reportsWrittenToday: number;
|
|
58
|
+
/** Total diagnostician reports that were missing JSON (category=missing_json) */
|
|
59
|
+
reportsMissingJsonToday: number;
|
|
60
|
+
/** Total diagnostician reports with incomplete fields (category=incomplete_fields) */
|
|
61
|
+
reportsIncompleteFieldsToday: number;
|
|
62
|
+
/** Total principle candidates created from heartbeat chain (today from event log) */
|
|
63
|
+
candidatesCreatedToday: number;
|
|
64
|
+
/** Heartbeats that injected diagnostician tasks (today from event log) */
|
|
65
|
+
heartbeatsInjectedToday: number;
|
|
66
|
+
};
|
|
67
|
+
phase3: {
|
|
68
|
+
queueTruthReady: boolean;
|
|
69
|
+
phase3ShadowEligible: boolean;
|
|
70
|
+
evolutionEligible: number;
|
|
71
|
+
evolutionReferenceOnly: number;
|
|
72
|
+
evolutionReferenceOnlyReasons: string[];
|
|
73
|
+
evolutionRejected: number;
|
|
74
|
+
evolutionRejectedReasons: string[];
|
|
75
|
+
legacyDirectiveFilePresent: boolean;
|
|
76
|
+
directiveStatus: 'compatibility-only' | 'missing' | 'present';
|
|
77
|
+
directiveIgnoredReason: string;
|
|
78
|
+
/**
|
|
79
|
+
* Source of Phase 3 eligibility calculation.
|
|
80
|
+
* Should always be 'runtime_truth' - analytics not used for control decisions.
|
|
81
|
+
*/
|
|
82
|
+
eligibilitySource: 'runtime_truth';
|
|
83
|
+
};
|
|
84
|
+
pain: {
|
|
85
|
+
candidates: number | null;
|
|
86
|
+
lastSignal: RuntimePainSignal | null;
|
|
87
|
+
};
|
|
88
|
+
gate: {
|
|
89
|
+
recentBlocks: number | null;
|
|
90
|
+
recentBypasses: number | null;
|
|
91
|
+
dataQuality: RuntimeDataQuality;
|
|
92
|
+
};
|
|
93
|
+
/** YAML-driven funnel counts — only present when funnels param is provided (YAML-SSOT-01) */
|
|
94
|
+
workflowFunnels?: WorkflowFunnelOutput[];
|
|
95
|
+
metadata: {
|
|
96
|
+
generatedAt: string;
|
|
97
|
+
workspaceDir: string;
|
|
98
|
+
sessionId: string | null;
|
|
99
|
+
selectedSessionReason: 'explicit' | 'latest_active' | 'none';
|
|
100
|
+
/** 'degraded' when YAML load errors or unresolved statsField paths exist; 'ok' otherwise */
|
|
101
|
+
status: 'ok' | 'degraded';
|
|
102
|
+
warnings: string[];
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export interface WorkflowFunnelStageOutput {
|
|
106
|
+
key: string;
|
|
107
|
+
label: string;
|
|
108
|
+
statsField: string;
|
|
109
|
+
count: number;
|
|
110
|
+
}
|
|
111
|
+
export interface WorkflowFunnelOutput {
|
|
112
|
+
funnelKey: string;
|
|
113
|
+
funnelLabel: string;
|
|
114
|
+
stages: WorkflowFunnelStageOutput[];
|
|
115
|
+
}
|
|
116
|
+
export declare class RuntimeSummaryService {
|
|
117
|
+
static getSummary(workspaceDir: string, options?: {
|
|
118
|
+
sessionId?: string | null;
|
|
119
|
+
loaderWarnings?: string[];
|
|
120
|
+
funnels?: Map<string, WorkflowStage[]>;
|
|
121
|
+
}): RuntimeSummary;
|
|
122
|
+
private static readSessions;
|
|
123
|
+
private static selectSession;
|
|
124
|
+
private static mergeSessionSnapshots;
|
|
125
|
+
private static buildQueueStats;
|
|
126
|
+
/**
|
|
127
|
+
* Builds directive summary for compatibility display only.
|
|
128
|
+
* NOT a truth source for Phase 3 eligibility or decisions.
|
|
129
|
+
* Queue is the only authoritative execution truth source.
|
|
130
|
+
*/
|
|
131
|
+
private static buildDirectiveSummary;
|
|
132
|
+
private static readEvents;
|
|
133
|
+
private static buildGfiSources;
|
|
134
|
+
private static findLastPainSignal;
|
|
135
|
+
private static buildGateStats;
|
|
136
|
+
private static resolveSessionSortTime;
|
|
137
|
+
private static mergeEvents;
|
|
138
|
+
private static getEventDedupKey;
|
|
139
|
+
private static resolveEvolutionDataQuality;
|
|
140
|
+
private static selectInProgressTask;
|
|
141
|
+
private static getQueuePriority;
|
|
142
|
+
private static isResolvableEvolutionTask;
|
|
143
|
+
private static resolveDirectiveTimestamp;
|
|
144
|
+
private static buildDirectiveTaskPreview;
|
|
145
|
+
private static warnOnLegacyDirectiveMismatch;
|
|
146
|
+
private static readJsonFile;
|
|
147
|
+
private static asFiniteNumber;
|
|
148
|
+
/**
|
|
149
|
+
* Read trajectory analytics data from trajectory database.
|
|
150
|
+
*
|
|
151
|
+
* Returns: Analytics data (historical metrics) aggregated from trajectory database.
|
|
152
|
+
* Not: Runtime truth or real-time queue state.
|
|
153
|
+
*/
|
|
154
|
+
private static readTrajectoryStats;
|
|
155
|
+
}
|
|
156
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utility for detecting expected subagent unavailability errors.
|
|
3
|
+
* These occur during cron jobs, boot sessions, daemon mode, or isolated sessions
|
|
4
|
+
* where the gateway request context is not available.
|
|
5
|
+
*
|
|
6
|
+
* Callers should suppress warnings for these errors — they are not real failures.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isExpectedSubagentError(err: unknown): boolean;
|