principles-disciple 1.147.0 → 1.149.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/core/principle-tree-ledger.d.ts +27 -79
- package/dist/core/principle-tree-ledger.js +39 -524
- package/dist/core/reflection/reflection-context.d.ts +2 -2
- package/dist/core/workspace-context.d.ts +2 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -5
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/dist/core/principle-tree-ledger-adapter.d.ts +0 -32
- package/dist/core/principle-tree-ledger-adapter.js +0 -125
- package/dist/service/central-database.d.ts +0 -138
- package/dist/service/central-database.js +0 -731
- package/dist/service/central-sync-service.d.ts +0 -8
- package/dist/service/central-sync-service.js +0 -71
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { type LedgerPrinciple } from '../principle-tree-ledger.js';
|
|
1
2
|
import type { TrajectoryDatabase } from '../trajectory.js';
|
|
2
|
-
import type { Principle } from '../../types/principle-tree-schema.js';
|
|
3
3
|
export interface ReflectionContext {
|
|
4
|
-
principle:
|
|
4
|
+
principle: LedgerPrinciple;
|
|
5
5
|
painEvents: Array<{
|
|
6
6
|
source: string;
|
|
7
7
|
score: number;
|
|
@@ -6,12 +6,11 @@ import { HygieneTracker } from './hygiene/tracker.js';
|
|
|
6
6
|
import { EvolutionReducerImpl } from './evolution-reducer.js';
|
|
7
7
|
import type { TrajectoryDatabase } from './trajectory.js';
|
|
8
8
|
import { PrincipleLifecycleService } from './principle-internalization/principle-lifecycle-service.js';
|
|
9
|
-
import { type PrincipleSubtree } from './principle-tree-ledger.js';
|
|
10
|
-
import type { Principle, PrincipleValueMetrics } from '../types/principle-tree-schema.js';
|
|
9
|
+
import { type PrincipleSubtree, type LedgerPrinciple, type PrincipleValueMetrics } from './principle-tree-ledger.js';
|
|
11
10
|
import type { Principle as ActivePrinciple } from './evolution-types.js';
|
|
12
11
|
interface PrincipleTreeLedgerAccessor {
|
|
13
12
|
getPrincipleSubtree(_principleId: string): PrincipleSubtree | undefined;
|
|
14
|
-
updatePrinciple(_principleId: string, updates: Partial<
|
|
13
|
+
updatePrinciple(_principleId: string, updates: Partial<LedgerPrinciple>): LedgerPrinciple;
|
|
15
14
|
updatePrincipleValueMetrics(principleId: string, _metrics: PrincipleValueMetrics): PrincipleValueMetrics;
|
|
16
15
|
}
|
|
17
16
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -45,6 +45,6 @@ declare const plugin: {
|
|
|
45
45
|
description: string;
|
|
46
46
|
register(api: OpenClawPluginApi): void;
|
|
47
47
|
};
|
|
48
|
-
export { PrincipleTreeLedgerAdapter } from '
|
|
48
|
+
export { PrincipleTreeLedgerAdapter } from '@principles/core/runtime-v2';
|
|
49
49
|
export { loadFeatureFlagFromWorkspace, isRecord };
|
|
50
50
|
export default plugin;
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,6 @@ import { CorrectionObserverService } from './service/correction-observer-service
|
|
|
31
31
|
import { InternalizationAutoConsumerService } from './service/internalization-auto-consumer-service.js';
|
|
32
32
|
import { TrajectoryService } from './service/trajectory-service.js';
|
|
33
33
|
import { PDTaskService } from './core/pd-task-service.js';
|
|
34
|
-
import { CentralSyncService } from './service/central-sync-service.js';
|
|
35
34
|
import { ensureWorkspaceTemplates } from './core/init.js';
|
|
36
35
|
import { migrateDirectoryStructure } from './core/migration.js';
|
|
37
36
|
import { migrateStaleWorkspaceGuidance } from './core/workspace-guidance-migrator.js';
|
|
@@ -408,9 +407,6 @@ const plugin = {
|
|
|
408
407
|
const guardedPdTask = guardService('service:pd-task', PDTaskService, api.logger);
|
|
409
408
|
if (guardedPdTask)
|
|
410
409
|
api.registerService(guardedPdTask);
|
|
411
|
-
const guardedCentralSync = guardService('service:central-sync', CentralSyncService, api.logger);
|
|
412
|
-
if (guardedCentralSync)
|
|
413
|
-
api.registerService(guardedCentralSync);
|
|
414
410
|
const guardedAutoConsumer = guardService('service:internalization-auto-consumer', InternalizationAutoConsumerService, api.logger);
|
|
415
411
|
if (guardedAutoConsumer)
|
|
416
412
|
api.registerService(guardedAutoConsumer);
|
|
@@ -745,7 +741,10 @@ const plugin = {
|
|
|
745
741
|
});
|
|
746
742
|
}
|
|
747
743
|
};
|
|
748
|
-
|
|
744
|
+
// PrincipleTreeLedgerAdapter is exported from @principles/core/runtime-v2 (canonical,
|
|
745
|
+
// consolidated in PRI-459). The plugin-local duplicate was removed; re-export the core
|
|
746
|
+
// symbol so any external consumer importing from the plugin still resolves it.
|
|
747
|
+
export { PrincipleTreeLedgerAdapter } from '@principles/core/runtime-v2';
|
|
749
748
|
/* istanbul ignore next — test exports for evolution worker gate */
|
|
750
749
|
export { loadFeatureFlagFromWorkspace, isRecord };
|
|
751
750
|
export default plugin;
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "principles-disciple",
|
|
3
3
|
"name": "Principles Disciple",
|
|
4
4
|
"description": "Evolutionary programming agent framework with strategic guardrails and reflection loops.",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.149.0",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onCapabilities": [
|
|
8
8
|
"hook"
|
package/package.json
CHANGED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { LedgerAdapter, LedgerPrincipleEntry } from '@principles/core/runtime-v2';
|
|
2
|
-
/**
|
|
3
|
-
* PrincipleTreeLedgerAdapter — bridges 11-field LedgerPrincipleEntry to 18+ field LedgerPrinciple.
|
|
4
|
-
*
|
|
5
|
-
* This adapter maintains an in-memory idempotency map. Create once and reuse
|
|
6
|
-
* across calls within the same process lifetime. Do not create a new instance
|
|
7
|
-
* per intake call.
|
|
8
|
-
*/
|
|
9
|
-
export declare class PrincipleTreeLedgerAdapter implements LedgerAdapter {
|
|
10
|
-
#private;
|
|
11
|
-
constructor(opts: {
|
|
12
|
-
stateDir: string;
|
|
13
|
-
});
|
|
14
|
-
/**
|
|
15
|
-
* Write a probation entry to the ledger.
|
|
16
|
-
*
|
|
17
|
-
* Idempotency: if the same candidateId was already written, returns the
|
|
18
|
-
* existing entry without writing again.
|
|
19
|
-
*
|
|
20
|
-
* @throws CandidateIntakeError with code LEDGER_WRITE_FAILED on write failure.
|
|
21
|
-
*/
|
|
22
|
-
writeProbationEntry(entry: LedgerPrincipleEntry): LedgerPrincipleEntry;
|
|
23
|
-
/**
|
|
24
|
-
* Check if a ledger entry already exists for a given candidate.
|
|
25
|
-
*
|
|
26
|
-
* Queries both the in-memory Map (fast path for same-process repeat calls)
|
|
27
|
-
* and the ledger file (for cross-process idempotency across CLI invocations).
|
|
28
|
-
*
|
|
29
|
-
* @returns The existing LedgerPrincipleEntry if found, null otherwise.
|
|
30
|
-
*/
|
|
31
|
-
existsForCandidate(candidateId: string): LedgerPrincipleEntry | null;
|
|
32
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { CandidateIntakeError, INTAKE_ERROR_CODES } from '@principles/core/runtime-v2';
|
|
2
|
-
import { addPrincipleToLedger, loadLedger } from './principle-tree-ledger.js';
|
|
3
|
-
const VALID_EVALUABILITIES = ['deterministic', 'weak_heuristic', 'manual_only'];
|
|
4
|
-
/**
|
|
5
|
-
* PrincipleTreeLedgerAdapter — bridges 11-field LedgerPrincipleEntry to 18+ field LedgerPrinciple.
|
|
6
|
-
*
|
|
7
|
-
* This adapter maintains an in-memory idempotency map. Create once and reuse
|
|
8
|
-
* across calls within the same process lifetime. Do not create a new instance
|
|
9
|
-
* per intake call.
|
|
10
|
-
*/
|
|
11
|
-
export class PrincipleTreeLedgerAdapter {
|
|
12
|
-
#stateDir;
|
|
13
|
-
#entryMap = new Map();
|
|
14
|
-
constructor(opts) {
|
|
15
|
-
this.#stateDir = opts.stateDir;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Write a probation entry to the ledger.
|
|
19
|
-
*
|
|
20
|
-
* Idempotency: if the same candidateId was already written, returns the
|
|
21
|
-
* existing entry without writing again.
|
|
22
|
-
*
|
|
23
|
-
* @throws CandidateIntakeError with code LEDGER_WRITE_FAILED on write failure.
|
|
24
|
-
*/
|
|
25
|
-
writeProbationEntry(entry) {
|
|
26
|
-
const candidateId = this.#extractCandidateId(entry.sourceRef);
|
|
27
|
-
const existing = this.#entryMap.get(candidateId);
|
|
28
|
-
if (existing)
|
|
29
|
-
return existing;
|
|
30
|
-
const ledgerPrinciple = this.#expandToLedgerPrinciple(entry, candidateId);
|
|
31
|
-
try {
|
|
32
|
-
addPrincipleToLedger(this.#stateDir, ledgerPrinciple);
|
|
33
|
-
}
|
|
34
|
-
catch (err) {
|
|
35
|
-
throw new CandidateIntakeError(INTAKE_ERROR_CODES.LEDGER_WRITE_FAILED, `Failed to write principle ${entry.id} to ledger: ${String(err)}`, { cause: err });
|
|
36
|
-
}
|
|
37
|
-
this.#entryMap.set(candidateId, entry);
|
|
38
|
-
return entry;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Check if a ledger entry already exists for a given candidate.
|
|
42
|
-
*
|
|
43
|
-
* Queries both the in-memory Map (fast path for same-process repeat calls)
|
|
44
|
-
* and the ledger file (for cross-process idempotency across CLI invocations).
|
|
45
|
-
*
|
|
46
|
-
* @returns The existing LedgerPrincipleEntry if found, null otherwise.
|
|
47
|
-
*/
|
|
48
|
-
existsForCandidate(candidateId) {
|
|
49
|
-
// Fast path: check in-memory Map (covers same-process repeat calls)
|
|
50
|
-
const cached = this.#entryMap.get(candidateId);
|
|
51
|
-
if (cached)
|
|
52
|
-
return cached;
|
|
53
|
-
// Cross-process path: check ledger file by derivedFromPainIds
|
|
54
|
-
const ledger = loadLedger(this.#stateDir);
|
|
55
|
-
const found = Object.values(ledger.tree.principles).find((p) => p.derivedFromPainIds.includes(candidateId));
|
|
56
|
-
if (!found)
|
|
57
|
-
return null;
|
|
58
|
-
// Reconstruct LedgerPrincipleEntry from LedgerPrinciple fields
|
|
59
|
-
// Note: sourceRef, artifactRef, taskRef are not stored in LedgerPrinciple,
|
|
60
|
-
// so we cannot fully reconstruct the original LedgerPrincipleEntry.
|
|
61
|
-
// Return minimal entry sufficient for idempotency signaling.
|
|
62
|
-
return {
|
|
63
|
-
id: found.id,
|
|
64
|
-
title: '',
|
|
65
|
-
status: 'probation',
|
|
66
|
-
sourceRef: `candidate://${candidateId}`,
|
|
67
|
-
artifactRef: '',
|
|
68
|
-
taskRef: '',
|
|
69
|
-
text: found.text,
|
|
70
|
-
triggerPattern: found.triggerPattern,
|
|
71
|
-
action: found.action,
|
|
72
|
-
evaluability: 'weak_heuristic',
|
|
73
|
-
createdAt: found.createdAt,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Extract candidateId from sourceRef by stripping the 'candidate://' prefix.
|
|
78
|
-
*
|
|
79
|
-
* @internal
|
|
80
|
-
*/
|
|
81
|
-
#extractCandidateId(sourceRef) {
|
|
82
|
-
if (sourceRef.startsWith('candidate://')) {
|
|
83
|
-
return sourceRef.slice('candidate://'.length);
|
|
84
|
-
}
|
|
85
|
-
return sourceRef;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Expand an 11-field LedgerPrincipleEntry to an 18+ field LedgerPrinciple.
|
|
89
|
-
*
|
|
90
|
-
* Applies the field expansion table from CONTEXT.md:
|
|
91
|
-
* - status: 'probation' → 'candidate'
|
|
92
|
-
* - triggerPattern/action: pass through (empty string if absent)
|
|
93
|
-
* - All defaults applied per CONTEXT.md expansion table
|
|
94
|
-
* - sourceRef/artifactRef/taskRef are NOT written to LedgerPrinciple (not stored)
|
|
95
|
-
* - title is NOT written to LedgerPrinciple — intentionally excluded; title
|
|
96
|
-
* is available in LedgerPrincipleEntry but LedgerPrinciple has no title field
|
|
97
|
-
*
|
|
98
|
-
* @internal
|
|
99
|
-
*/
|
|
100
|
-
#expandToLedgerPrinciple(entry, candidateId) {
|
|
101
|
-
if (!VALID_EVALUABILITIES.includes(entry.evaluability)) {
|
|
102
|
-
throw new CandidateIntakeError(INTAKE_ERROR_CODES.INPUT_INVALID, `Invalid evaluability value: ${entry.evaluability}. Must be one of: ${VALID_EVALUABILITIES.join(', ')}`);
|
|
103
|
-
}
|
|
104
|
-
const result = {
|
|
105
|
-
id: entry.id,
|
|
106
|
-
version: 1,
|
|
107
|
-
text: entry.text,
|
|
108
|
-
triggerPattern: entry.triggerPattern ?? '',
|
|
109
|
-
action: entry.action ?? '',
|
|
110
|
-
status: 'candidate',
|
|
111
|
-
evaluability: entry.evaluability,
|
|
112
|
-
priority: 'P1',
|
|
113
|
-
scope: 'general',
|
|
114
|
-
valueScore: 0,
|
|
115
|
-
adherenceRate: 0,
|
|
116
|
-
painPreventedCount: 0,
|
|
117
|
-
derivedFromPainIds: [candidateId],
|
|
118
|
-
ruleIds: [],
|
|
119
|
-
conflictsWithPrincipleIds: [],
|
|
120
|
-
createdAt: entry.createdAt,
|
|
121
|
-
updatedAt: entry.createdAt,
|
|
122
|
-
};
|
|
123
|
-
return result;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
export interface WorkspaceInfo {
|
|
2
|
-
name: string;
|
|
3
|
-
path: string;
|
|
4
|
-
lastSync: string | null;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Central database that aggregates data from all agent workspaces.
|
|
8
|
-
* Stored in ~/.openclaw/.central/ (NOT in memory/ which is for embeddings)
|
|
9
|
-
*/
|
|
10
|
-
export declare class CentralDatabase {
|
|
11
|
-
private readonly dbPath;
|
|
12
|
-
private readonly db;
|
|
13
|
-
private readonly workspaces;
|
|
14
|
-
private _closed;
|
|
15
|
-
/** Whether this connection has been closed. Used by the singleton to auto-reopen. */
|
|
16
|
-
get isClosed(): boolean;
|
|
17
|
-
constructor(dbPath?: string);
|
|
18
|
-
dispose(): void;
|
|
19
|
-
private static tableExists;
|
|
20
|
-
private initSchema;
|
|
21
|
-
private discoverWorkspaces;
|
|
22
|
-
/**
|
|
23
|
-
* Sync data from a single workspace into the central database
|
|
24
|
-
*/
|
|
25
|
-
syncWorkspace(workspaceName: string): number;
|
|
26
|
-
syncEnabled(): Map<string, number>;
|
|
27
|
-
/**
|
|
28
|
-
* Sync all workspaces (legacy method - syncs all regardless of config)
|
|
29
|
-
*/
|
|
30
|
-
syncAll(): Map<string, number>;
|
|
31
|
-
private getEnabledWorkspaceFilter;
|
|
32
|
-
/**
|
|
33
|
-
* Get aggregated overview stats (only from enabled workspaces)
|
|
34
|
-
*/
|
|
35
|
-
getOverviewStats(): {
|
|
36
|
-
totalSessions: number;
|
|
37
|
-
totalToolCalls: number;
|
|
38
|
-
totalFailures: number;
|
|
39
|
-
totalPainEvents: number;
|
|
40
|
-
totalCorrections: number;
|
|
41
|
-
totalThinkingEvents: number;
|
|
42
|
-
totalSamples: number;
|
|
43
|
-
pendingSamples: number;
|
|
44
|
-
approvedSamples: number;
|
|
45
|
-
rejectedSamples: number;
|
|
46
|
-
workspaceCount: number;
|
|
47
|
-
enabledWorkspaceCount: number;
|
|
48
|
-
workspaceNames: string[];
|
|
49
|
-
enabledWorkspaceNames: string[];
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Get daily trend data
|
|
53
|
-
*/
|
|
54
|
-
getDailyTrend(days?: number): {
|
|
55
|
-
day: string;
|
|
56
|
-
toolCalls: number;
|
|
57
|
-
failures: number;
|
|
58
|
-
userCorrections: number;
|
|
59
|
-
thinkingTurns: number;
|
|
60
|
-
}[];
|
|
61
|
-
/**
|
|
62
|
-
* Get top regressions
|
|
63
|
-
*/
|
|
64
|
-
getTopRegressions(limit?: number): {
|
|
65
|
-
toolName: string;
|
|
66
|
-
errorType: string;
|
|
67
|
-
occurrences: number;
|
|
68
|
-
}[];
|
|
69
|
-
/**
|
|
70
|
-
* Get thinking model stats
|
|
71
|
-
*/
|
|
72
|
-
getThinkingModelStats(): {
|
|
73
|
-
totalModels: number;
|
|
74
|
-
activeModels: number;
|
|
75
|
-
models: {
|
|
76
|
-
modelId: string;
|
|
77
|
-
hits: number;
|
|
78
|
-
coverageRate: number;
|
|
79
|
-
}[];
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Get workspace list
|
|
83
|
-
*/
|
|
84
|
-
getWorkspaces(): WorkspaceInfo[];
|
|
85
|
-
getWorkspaceConfigs(): {
|
|
86
|
-
workspaceName: string;
|
|
87
|
-
enabled: boolean;
|
|
88
|
-
displayName: string | null;
|
|
89
|
-
syncEnabled: boolean;
|
|
90
|
-
}[];
|
|
91
|
-
updateWorkspaceConfig(workspaceName: string, updates: {
|
|
92
|
-
enabled?: boolean;
|
|
93
|
-
displayName?: string | null;
|
|
94
|
-
syncEnabled?: boolean;
|
|
95
|
-
}): void;
|
|
96
|
-
isWorkspaceEnabled(workspaceName: string): boolean;
|
|
97
|
-
getEnabledWorkspaces(): WorkspaceInfo[];
|
|
98
|
-
addCustomWorkspace(name: string, workspacePath: string): void;
|
|
99
|
-
removeWorkspace(workspaceName: string): void;
|
|
100
|
-
getGlobalConfig(key: string): string | null;
|
|
101
|
-
setGlobalConfig(key: string, value: string): void;
|
|
102
|
-
/**
|
|
103
|
-
* Clear all aggregated data (for testing/reset)
|
|
104
|
-
*/
|
|
105
|
-
clearAll(): void;
|
|
106
|
-
/**
|
|
107
|
-
* Get total task outcomes count across enabled workspaces (D-02)
|
|
108
|
-
*/
|
|
109
|
-
getTaskOutcomes(): number;
|
|
110
|
-
/**
|
|
111
|
-
* Get total principle events count across enabled workspaces (D-03)
|
|
112
|
-
*/
|
|
113
|
-
getPrincipleEventCount(): number;
|
|
114
|
-
/**
|
|
115
|
-
* Get sample counts grouped by review_status across enabled workspaces (D-06)
|
|
116
|
-
*/
|
|
117
|
-
getSampleCountersByStatus(): Record<string, number>;
|
|
118
|
-
/**
|
|
119
|
-
* Get top N most recent pending/approved samples across all enabled workspaces (D-04)
|
|
120
|
-
*/
|
|
121
|
-
getSamplePreview(limit?: number): {
|
|
122
|
-
sampleId: string;
|
|
123
|
-
sessionId: string;
|
|
124
|
-
workspace: string;
|
|
125
|
-
qualityScore: number;
|
|
126
|
-
reviewStatus: string;
|
|
127
|
-
createdAt: string;
|
|
128
|
-
}[];
|
|
129
|
-
/**
|
|
130
|
-
* Get the most recent lastSync timestamp across all workspaces (D-05)
|
|
131
|
-
*/
|
|
132
|
-
getMostRecentSync(): string | null;
|
|
133
|
-
}
|
|
134
|
-
export declare function getCentralDatabase(): CentralDatabase;
|
|
135
|
-
/**
|
|
136
|
-
* Reset the singleton instance. Used for testing.
|
|
137
|
-
*/
|
|
138
|
-
export declare function resetCentralDatabase(): void;
|