create-principles-disciple 1.145.18 → 1.145.20
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/README.md +15 -0
- package/_release/product-identity.json +1 -1
- package/codex-adapter/package.json +1 -1
- package/console/dist/ui/i18n/en.json +1 -1
- package/console/dist/ui/i18n/zh-CN.json +1 -1
- package/console/dist/ui/pages/control-center/ControlCenterPage.js +11 -1
- package/console/dist/web/assets/app.js +13 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/installers/openclaw-host-installer.d.ts +4 -8
- package/dist/installers/openclaw-host-installer.d.ts.map +1 -1
- package/dist/installers/openclaw-host-installer.js +10 -84
- package/dist/installers/openclaw-host-installer.js.map +1 -1
- package/package.json +2 -2
- package/pd-cli/dist/commands/pain-recall.d.ts +30 -0
- package/pd-cli/dist/commands/pain-recall.d.ts.map +1 -0
- package/pd-cli/dist/commands/pain-recall.js +155 -0
- package/pd-cli/dist/commands/pain-recall.js.map +1 -0
- package/pd-cli/dist/index.js +21 -0
- package/pd-cli/dist/index.js.map +1 -1
- package/pd-cli/dist/services/pain-recall.d.ts +113 -0
- package/pd-cli/dist/services/pain-recall.d.ts.map +1 -0
- package/pd-cli/dist/services/pain-recall.js +444 -0
- package/pd-cli/dist/services/pain-recall.js.map +1 -0
- package/pd-cli/package.json +1 -1
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/dist/templates/langs/en/skills/pd-cli-operator/SKILL.md +16 -0
- package/plugin/dist/templates/langs/zh/skills/pd-cli-operator/SKILL.md +16 -0
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/plugin/templates/langs/en/skills/pd-cli-operator/SKILL.md +16 -0
- package/plugin/templates/langs/zh/skills/pd-cli-operator/SKILL.md +16 -0
- package/release-manager/dist/index.d.ts.map +1 -1
- package/release-manager/dist/index.js +5 -1
- package/release-manager/dist/index.js.map +1 -1
- package/release-manager/dist/installers/openclaw-host-installer.d.ts +4 -8
- package/release-manager/dist/installers/openclaw-host-installer.d.ts.map +1 -1
- package/release-manager/dist/installers/openclaw-host-installer.js +10 -84
- package/release-manager/dist/installers/openclaw-host-installer.js.map +1 -1
- package/release-manager/package.json +2 -2
- package/workbuddy-adapter/package.json +1 -1
- package/workbuddy-adapter/plugin/skills/pd-cli-operator/SKILL.md +14 -0
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pain Recall read model — SPEC-PD-PAIN-RECALL-CLI-001.
|
|
3
|
+
*
|
|
4
|
+
* Resolves a canonical ledger principle to its verifiably-associated
|
|
5
|
+
* historical pains through the two authoritative edges only:
|
|
6
|
+
*
|
|
7
|
+
* 1. `Principle.reuseEvidence[]` — carries a REAL `painId` (validated at
|
|
8
|
+
* the ledger write boundary, appendReuseEvidence);
|
|
9
|
+
* 2. `Principle.derivedFromPainIds[]` — stores CANDIDATE ids despite its
|
|
10
|
+
* legacy pain-oriented name (see PainChainReadModel's linkage note);
|
|
11
|
+
* the pain resolves through candidate → task → `tasks.input_ref`
|
|
12
|
+
* (fallback: the `diagnosis_<painId>` task-id spelling).
|
|
13
|
+
*
|
|
14
|
+
* Anything not reachable through those edges is excluded and REPORTED
|
|
15
|
+
* (unresolvedAssociations) — never guessed from text similarity, never
|
|
16
|
+
* resolved through candidateId/taskId/artifactId masquerading as pain ids.
|
|
17
|
+
*
|
|
18
|
+
* Strictly read-only: the ledger through readLedgerFileState, trajectory.db
|
|
19
|
+
* through openTrajectoryDbReadonly, state.db through RuntimeStateManager with
|
|
20
|
+
* readonly:true + bootstrapIfMissing:false. Missing stays missing; unreadable
|
|
21
|
+
* stays unreadable; neither is ever reported as an empty result.
|
|
22
|
+
*/
|
|
23
|
+
import * as fs from 'fs';
|
|
24
|
+
import * as path from 'path';
|
|
25
|
+
import { readLedgerFileState } from '@principles/core/principle-tree-ledger';
|
|
26
|
+
import { openTrajectoryDbReadonly } from '@principles/core/trajectory-store';
|
|
27
|
+
import { RuntimeStateManager } from '@principles/core/runtime-v2';
|
|
28
|
+
export const PAIN_RECALL_SCHEMA_VERSION = 'pd.pain-recall.v1';
|
|
29
|
+
export const PAIN_RECALL_DEFAULT_LIMIT = 3;
|
|
30
|
+
export const PAIN_RECALL_MIN_LIMIT = 1;
|
|
31
|
+
export const PAIN_RECALL_MAX_LIMIT = 10;
|
|
32
|
+
function emptyResult(input) {
|
|
33
|
+
const { query, status } = input;
|
|
34
|
+
return {
|
|
35
|
+
schemaVersion: PAIN_RECALL_SCHEMA_VERSION,
|
|
36
|
+
status,
|
|
37
|
+
principle: { requestedId: query.requestedPrincipleId, canonicalId: null, identityStatus: 'not_found' },
|
|
38
|
+
query: {
|
|
39
|
+
limit: query.limit,
|
|
40
|
+
...(query.painId !== undefined ? { painId: query.painId } : {}),
|
|
41
|
+
contextUsedForRanking: false,
|
|
42
|
+
truncated: false,
|
|
43
|
+
},
|
|
44
|
+
results: [],
|
|
45
|
+
summary: { returned: 0, availableCandidates: 0, truncated: false },
|
|
46
|
+
sources: input.sources,
|
|
47
|
+
unresolvedAssociations: [],
|
|
48
|
+
...input.overwrites,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// ── Deterministic local ranking (no model, no network) ───────────────────────
|
|
52
|
+
/** Latin/digit runs plus individual Han characters — deterministic, locale-free. */
|
|
53
|
+
function tokenize(text) {
|
|
54
|
+
const tokens = text.toLowerCase().match(/[a-z0-9]+/g) ?? [];
|
|
55
|
+
const han = text.match(/\p{Script=Han}/gu) ?? [];
|
|
56
|
+
return [...tokens, ...han];
|
|
57
|
+
}
|
|
58
|
+
function contextOverlapScore(contextTokens, doc) {
|
|
59
|
+
if (contextTokens.size === 0)
|
|
60
|
+
return 0;
|
|
61
|
+
const docTokens = new Set(tokenize(doc));
|
|
62
|
+
let score = 0;
|
|
63
|
+
for (const token of contextTokens) {
|
|
64
|
+
if (docTokens.has(token))
|
|
65
|
+
score += 1;
|
|
66
|
+
}
|
|
67
|
+
return score;
|
|
68
|
+
}
|
|
69
|
+
// ── Row guards (rc-1/rc-4: every DB/ledger value is guarded before use) ──────
|
|
70
|
+
function isRecord(value) {
|
|
71
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
72
|
+
}
|
|
73
|
+
function ownString(row, key) {
|
|
74
|
+
const value = row[key];
|
|
75
|
+
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
76
|
+
}
|
|
77
|
+
function safeParseRecord(json) {
|
|
78
|
+
try {
|
|
79
|
+
const parsed = JSON.parse(json);
|
|
80
|
+
return isRecord(parsed) ? parsed : null;
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// ── Main entry ───────────────────────────────────────────────────────────────
|
|
87
|
+
export async function recallPains(workspaceDir, query) {
|
|
88
|
+
// 1. Ledger — the identity authority. Missing/unreadable is a source-level
|
|
89
|
+
// failure, never a silent empty ledger.
|
|
90
|
+
const ledgerState = readLedgerFileState(path.join(workspaceDir, '.state'));
|
|
91
|
+
const ledgerAvailability = ledgerState.availability.status === 'ok'
|
|
92
|
+
? 'ok'
|
|
93
|
+
: ledgerState.availability.status === 'empty'
|
|
94
|
+
? 'missing'
|
|
95
|
+
: 'unreadable';
|
|
96
|
+
if (ledgerAvailability !== 'ok') {
|
|
97
|
+
return emptyResult({
|
|
98
|
+
query,
|
|
99
|
+
status: ledgerAvailability === 'missing' ? 'source_missing' : 'source_unreadable',
|
|
100
|
+
sources: { ledger: ledgerAvailability, trajectoryDb: 'not_checked', stateDb: 'not_checked' },
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// 2. Canonical identity: exact ledger-key match only. Display titles and
|
|
104
|
+
// draft ids never resolve (there is no title lookup at all).
|
|
105
|
+
const principleEntry = ledgerState.ledger.tree.principles[query.requestedPrincipleId];
|
|
106
|
+
if (!isRecord(principleEntry) || ownString(principleEntry, 'id') === null) {
|
|
107
|
+
return emptyResult({
|
|
108
|
+
query,
|
|
109
|
+
status: 'principle_not_found',
|
|
110
|
+
sources: { ledger: 'ok', trajectoryDb: 'not_checked', stateDb: 'not_checked' },
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const canonicalId = query.requestedPrincipleId;
|
|
114
|
+
const principleText = ownString(principleEntry, 'text');
|
|
115
|
+
// 3. state.db — strict readonly, no bootstrap. Missing/unreadable keeps the
|
|
116
|
+
// reuse-evidence edges alive and only degrades lineage + diagnoses.
|
|
117
|
+
const stateDbPath = path.join(workspaceDir, '.pd', 'state.db');
|
|
118
|
+
let stateDb = 'ok';
|
|
119
|
+
let manager = null;
|
|
120
|
+
if (!fs.existsSync(stateDbPath)) {
|
|
121
|
+
stateDb = 'missing';
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
try {
|
|
125
|
+
manager = new RuntimeStateManager({ workspaceDir, readonly: true, bootstrapIfMissing: false });
|
|
126
|
+
await manager.initialize();
|
|
127
|
+
// getDb() is lazy — force the readonly open NOW so a present-but-corrupt
|
|
128
|
+
// file is classified unreadable instead of surfacing per-query later.
|
|
129
|
+
// SQLite defers the header check to the first statement, hence the
|
|
130
|
+
// read-only liveness probe (SELECT 1 writes nothing).
|
|
131
|
+
manager.connection.getDb().prepare('SELECT 1 AS probe').get();
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
manager = null;
|
|
135
|
+
stateDb = 'unreadable';
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
// 4. trajectory.db — the pain-event authority. Missing/unreadable is a
|
|
140
|
+
// source-level failure (recall's subject is the pain history itself).
|
|
141
|
+
let trajectoryDb;
|
|
142
|
+
try {
|
|
143
|
+
trajectoryDb = openTrajectoryDbReadonly(workspaceDir);
|
|
144
|
+
// SQLite defers the file-header check to the first statement (same as
|
|
145
|
+
// state.db above): probe pain_events NOW so a corrupt file or a
|
|
146
|
+
// schema-less database falls into the source_unreadable classification
|
|
147
|
+
// instead of escaping as a raw query error. Close before rethrowing so
|
|
148
|
+
// no handle leaks into the failure path.
|
|
149
|
+
try {
|
|
150
|
+
trajectoryDb.prepare('SELECT 1 FROM pain_events LIMIT 1').get();
|
|
151
|
+
}
|
|
152
|
+
catch (probeErr) {
|
|
153
|
+
trajectoryDb.close();
|
|
154
|
+
throw probeErr;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
const missing = !fs.existsSync(path.join(workspaceDir, '.state', 'trajectory.db'));
|
|
159
|
+
return emptyResult({
|
|
160
|
+
query,
|
|
161
|
+
status: missing ? 'source_missing' : 'source_unreadable',
|
|
162
|
+
sources: { ledger: 'ok', trajectoryDb: missing ? 'missing' : 'unreadable', stateDb },
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
// 5. Association edges from the two authoritative sources.
|
|
167
|
+
const unresolved = [];
|
|
168
|
+
const edges = [];
|
|
169
|
+
const { reuseEvidence } = principleEntry;
|
|
170
|
+
if (Array.isArray(reuseEvidence)) {
|
|
171
|
+
for (const entry of reuseEvidence) {
|
|
172
|
+
if (!isRecord(entry))
|
|
173
|
+
continue;
|
|
174
|
+
const painId = ownString(entry, 'painId');
|
|
175
|
+
const candidateId = ownString(entry, 'candidateId');
|
|
176
|
+
if (painId === null || candidateId === null)
|
|
177
|
+
continue; // malformed row: not a verifiable edge
|
|
178
|
+
edges.push({
|
|
179
|
+
painId,
|
|
180
|
+
explicit: true,
|
|
181
|
+
ref: {
|
|
182
|
+
kind: 'reuse_evidence',
|
|
183
|
+
candidateId,
|
|
184
|
+
...(ownString(entry, 'decidedAt') !== null ? { decidedAt: ownString(entry, 'decidedAt') ?? undefined } : {}),
|
|
185
|
+
...(ownString(entry, 'decisionId') !== null ? { decisionId: ownString(entry, 'decisionId') ?? undefined } : {}),
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const derivedIds = principleEntry.derivedFromPainIds;
|
|
191
|
+
if (Array.isArray(derivedIds)) {
|
|
192
|
+
for (const value of derivedIds) {
|
|
193
|
+
if (typeof value !== 'string' || value.length === 0)
|
|
194
|
+
continue;
|
|
195
|
+
const candidateId = value; // candidate id by production contract, despite the field name
|
|
196
|
+
if (manager === null) {
|
|
197
|
+
unresolved.push({ candidateId, reason: 'state_db_unavailable' });
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
let candidateTaskId = null;
|
|
201
|
+
try {
|
|
202
|
+
const candidate = await manager.getCandidate(candidateId);
|
|
203
|
+
candidateTaskId = candidate !== null && typeof candidate.taskId === 'string' && candidate.taskId.length > 0
|
|
204
|
+
? candidate.taskId
|
|
205
|
+
: null;
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
unresolved.push({ candidateId, reason: 'candidate_query_failed' });
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (candidateTaskId === null) {
|
|
212
|
+
unresolved.push({ candidateId, reason: 'candidate_not_found' });
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
let painId = null;
|
|
216
|
+
try {
|
|
217
|
+
const task = await manager.getTask(candidateTaskId);
|
|
218
|
+
const inputRef = task !== null && typeof task.inputRef === 'string' && task.inputRef.length > 0
|
|
219
|
+
? task.inputRef
|
|
220
|
+
: null;
|
|
221
|
+
painId = inputRef;
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
painId = null;
|
|
225
|
+
}
|
|
226
|
+
if (painId === null && candidateTaskId.startsWith('diagnosis_') && candidateTaskId.length > 'diagnosis_'.length) {
|
|
227
|
+
painId = candidateTaskId.slice('diagnosis_'.length); // authoritative task-id spelling fallback
|
|
228
|
+
}
|
|
229
|
+
if (painId === null) {
|
|
230
|
+
unresolved.push({ candidateId, reason: 'pain_unresolvable_from_candidate' });
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
edges.push({
|
|
234
|
+
painId,
|
|
235
|
+
explicit: false,
|
|
236
|
+
ref: { kind: 'candidate_lineage', candidateId, taskId: candidateTaskId },
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// 6. Merge by real pain id — all evidence refs survive the merge.
|
|
241
|
+
const merged = new Map();
|
|
242
|
+
for (const edge of edges) {
|
|
243
|
+
const existing = merged.get(edge.painId);
|
|
244
|
+
if (existing) {
|
|
245
|
+
existing.refs.push(edge.ref);
|
|
246
|
+
existing.explicit = existing.explicit || edge.explicit;
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
merged.set(edge.painId, { painId: edge.painId, refs: [edge.ref], explicit: edge.explicit });
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// 7. Pain events: an edge whose pain has no persisted event is reported,
|
|
253
|
+
// not returned, and not silently dropped.
|
|
254
|
+
const painRows = new Map();
|
|
255
|
+
const selectPain = trajectoryDb.prepare('SELECT id, source, score, severity, text, reason, canonical_pain_id, runtime_task_id, host_kind, created_at FROM pain_events WHERE canonical_pain_id = ? ORDER BY created_at DESC, id DESC LIMIT 1');
|
|
256
|
+
for (const painId of [...merged.keys()]) {
|
|
257
|
+
const row = selectPain.get(painId);
|
|
258
|
+
if (!isRecord(row)) {
|
|
259
|
+
unresolved.push({ painId, reason: 'pain_event_not_found' });
|
|
260
|
+
merged.delete(painId);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
painRows.set(painId, row);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// 8. --pain-id: filters WITHIN the verified association set only.
|
|
267
|
+
if (query.painId !== undefined) {
|
|
268
|
+
if (!merged.has(query.painId)) {
|
|
269
|
+
const exists = isRecord(selectPain.get(query.painId) ?? null);
|
|
270
|
+
return emptyResult({
|
|
271
|
+
query,
|
|
272
|
+
status: 'pain_not_found',
|
|
273
|
+
sources: { ledger: 'ok', trajectoryDb: 'ok', stateDb },
|
|
274
|
+
overwrites: { statusDetail: exists ? 'not_associated' : 'pain_event_not_found' },
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
for (const painId of [...merged.keys()]) {
|
|
278
|
+
if (painId !== query.painId)
|
|
279
|
+
merged.delete(painId);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
// 9. Per-pain enrichment (diagnoses + persisted correction evidence).
|
|
283
|
+
const entries = [];
|
|
284
|
+
for (const [painId, edge] of merged) {
|
|
285
|
+
const row = painRows.get(painId);
|
|
286
|
+
if (!isRecord(row))
|
|
287
|
+
continue; // step 7 guaranteed presence; guard anyway (rc-1)
|
|
288
|
+
const pain = {
|
|
289
|
+
occurredAt: ownString(row, 'created_at'),
|
|
290
|
+
source: ownString(row, 'source'),
|
|
291
|
+
host: ownString(row, 'host_kind') ?? 'unknown',
|
|
292
|
+
score: typeof row.score === 'number' ? row.score : null,
|
|
293
|
+
severity: ownString(row, 'severity'),
|
|
294
|
+
reason: ownString(row, 'reason'),
|
|
295
|
+
text: ownString(row, 'text'),
|
|
296
|
+
rawStatement: null,
|
|
297
|
+
};
|
|
298
|
+
let diagnoses = [];
|
|
299
|
+
// Every branch below assigns this before use (CodeQL useless-init).
|
|
300
|
+
let diagnosesAvailability;
|
|
301
|
+
let correction = null;
|
|
302
|
+
// Initializer is meaningful: a successful read with no persisted
|
|
303
|
+
// correction evidence keeps this 'not_recorded'.
|
|
304
|
+
let correctionAvailability = 'not_recorded';
|
|
305
|
+
if (manager === null) {
|
|
306
|
+
diagnosesAvailability = 'unreadable';
|
|
307
|
+
correctionAvailability = 'unreadable';
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
try {
|
|
311
|
+
const records = await manager.getDiagnosesByPainId(painId);
|
|
312
|
+
diagnoses = records.map((record) => ({
|
|
313
|
+
diagnosisId: record.diagnosisId,
|
|
314
|
+
taskId: record.taskId,
|
|
315
|
+
category: record.category,
|
|
316
|
+
rootCause: record.rootCause,
|
|
317
|
+
supportingEvidence: record.evidence.map((e) => ({ sourceRef: e.sourceRef, note: e.note })),
|
|
318
|
+
confidence: record.confidence,
|
|
319
|
+
isOriginalOwnerStatement: false,
|
|
320
|
+
}));
|
|
321
|
+
diagnosesAvailability = diagnoses.length > 0 ? 'available' : 'not_recorded';
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
diagnosesAvailability = 'unreadable';
|
|
325
|
+
}
|
|
326
|
+
try {
|
|
327
|
+
const diagnosisTask = await manager.getTask(`diagnosis_${painId}`);
|
|
328
|
+
const payload = diagnosisTask !== null && typeof diagnosisTask.diagnosticJson === 'string'
|
|
329
|
+
? safeParseRecord(diagnosisTask.diagnosticJson)
|
|
330
|
+
: null;
|
|
331
|
+
const persisted = payload !== null ? payload.correctionEvidence : undefined;
|
|
332
|
+
if (isRecord(persisted) && typeof persisted.text === 'string' && persisted.text.length > 0) {
|
|
333
|
+
correction = {
|
|
334
|
+
text: persisted.text,
|
|
335
|
+
...(ownString(persisted, 'classification') !== null ? { classification: ownString(persisted, 'classification') ?? undefined } : {}),
|
|
336
|
+
...(ownString(persisted, 'channel') !== null ? { channel: ownString(persisted, 'channel') ?? undefined } : {}),
|
|
337
|
+
...(ownString(persisted, 'sessionId') !== null ? { sessionId: ownString(persisted, 'sessionId') ?? undefined } : {}),
|
|
338
|
+
...(ownString(persisted, 'occurredAt') !== null ? { occurredAt: ownString(persisted, 'occurredAt') ?? undefined } : {}),
|
|
339
|
+
};
|
|
340
|
+
correctionAvailability = 'available';
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
catch {
|
|
344
|
+
correctionAvailability = 'unreadable';
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const type = edge.refs.length > 1
|
|
348
|
+
? 'multiple_paths'
|
|
349
|
+
: edge.explicit
|
|
350
|
+
? 'explicit_reuse'
|
|
351
|
+
: 'derived_from';
|
|
352
|
+
const lineage = [];
|
|
353
|
+
for (const ref of edge.refs) {
|
|
354
|
+
if (ref.kind === 'candidate_lineage') {
|
|
355
|
+
lineage.push({ from: `principle:${canonicalId}`, to: ref.candidateId, relation: 'derived_from_pain_ids' });
|
|
356
|
+
lineage.push({ from: ref.candidateId, to: painId, relation: 'task_input_ref' });
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
lineage.push({ from: `principle:${canonicalId}`, to: painId, relation: 'reuse_evidence_pain_id' });
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
entries.push({
|
|
363
|
+
painId,
|
|
364
|
+
association: {
|
|
365
|
+
type,
|
|
366
|
+
confidence: edge.explicit ? 'explicit' : 'lineage_verified',
|
|
367
|
+
evidenceRefs: edge.refs,
|
|
368
|
+
},
|
|
369
|
+
pain,
|
|
370
|
+
diagnoses,
|
|
371
|
+
correctionEvidence: correction,
|
|
372
|
+
availability: { painEvent: 'available', diagnoses: diagnosesAvailability, correctionEvidence: correctionAvailability },
|
|
373
|
+
lineage,
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
// 10. Deterministic ranking. Default: explicit evidence first, then
|
|
377
|
+
// newest pain first, then pain id. --context only re-orders this
|
|
378
|
+
// list by local token overlap — it never adds associations.
|
|
379
|
+
const contextTokens = new Set(typeof query.context === 'string' ? tokenize(query.context) : []);
|
|
380
|
+
const contextUsed = contextTokens.size > 0;
|
|
381
|
+
const rankOf = (entry) => (entry.association.confidence === 'explicit' ? 0 : 1);
|
|
382
|
+
const scored = entries.map((entry) => ({
|
|
383
|
+
entry,
|
|
384
|
+
score: contextUsed
|
|
385
|
+
? contextOverlapScore(contextTokens, [entry.pain.reason ?? '', entry.pain.text ?? '', ...entry.diagnoses.map((d) => d.rootCause)].join(' '))
|
|
386
|
+
: 0,
|
|
387
|
+
}));
|
|
388
|
+
scored.sort((a, b) => {
|
|
389
|
+
if (b.score !== a.score)
|
|
390
|
+
return b.score - a.score;
|
|
391
|
+
const rankDelta = rankOf(a.entry) - rankOf(b.entry);
|
|
392
|
+
if (rankDelta !== 0)
|
|
393
|
+
return rankDelta;
|
|
394
|
+
const aTime = a.entry.pain.occurredAt ?? '';
|
|
395
|
+
const bTime = b.entry.pain.occurredAt ?? '';
|
|
396
|
+
if (aTime !== bTime)
|
|
397
|
+
return aTime < bTime ? 1 : -1; // newest first
|
|
398
|
+
return a.entry.painId < b.entry.painId ? -1 : 1;
|
|
399
|
+
});
|
|
400
|
+
const ranked = scored.map((s) => s.entry);
|
|
401
|
+
// 11. Limit + truncation.
|
|
402
|
+
const truncated = ranked.length > query.limit;
|
|
403
|
+
const results = ranked.slice(0, query.limit);
|
|
404
|
+
// 12. Top-level status: distinguish "nothing recorded" from "cannot read".
|
|
405
|
+
let status;
|
|
406
|
+
if (results.length === 0) {
|
|
407
|
+
status = unresolved.length > 0 ? 'partial' : 'no_matches';
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
const degraded = results.some((r) => r.availability.diagnoses === 'unreadable' || r.availability.correctionEvidence === 'unreadable');
|
|
411
|
+
status = degraded ? 'partial' : 'ok';
|
|
412
|
+
}
|
|
413
|
+
return {
|
|
414
|
+
schemaVersion: PAIN_RECALL_SCHEMA_VERSION,
|
|
415
|
+
status,
|
|
416
|
+
principle: {
|
|
417
|
+
requestedId: query.requestedPrincipleId,
|
|
418
|
+
canonicalId,
|
|
419
|
+
identityStatus: 'resolved',
|
|
420
|
+
...(principleText !== null ? { text: principleText } : {}),
|
|
421
|
+
},
|
|
422
|
+
query: {
|
|
423
|
+
limit: query.limit,
|
|
424
|
+
...(query.painId !== undefined ? { painId: query.painId } : {}),
|
|
425
|
+
contextUsedForRanking: contextUsed,
|
|
426
|
+
truncated,
|
|
427
|
+
},
|
|
428
|
+
results,
|
|
429
|
+
summary: { returned: results.length, availableCandidates: ranked.length, truncated },
|
|
430
|
+
sources: { ledger: 'ok', trajectoryDb: 'ok', stateDb },
|
|
431
|
+
unresolvedAssociations: unresolved,
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
finally {
|
|
435
|
+
trajectoryDb.close();
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
finally {
|
|
439
|
+
if (manager !== null) {
|
|
440
|
+
await manager.close().catch(() => undefined);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
//# sourceMappingURL=pain-recall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pain-recall.js","sourceRoot":"","sources":["../../src/services/pain-recall.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,MAAM,CAAC,MAAM,0BAA0B,GAAG,mBAAmB,CAAC;AAE9D,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAC3C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AACvC,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AA6HxC,SAAS,WAAW,CAAC,KAKpB;IACC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAChC,OAAO;QACL,aAAa,EAAE,0BAA0B;QACzC,MAAM;QACN,SAAS,EAAE,EAAE,WAAW,EAAE,KAAK,CAAC,oBAAoB,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE;QACtG,KAAK,EAAE;YACL,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC/D,qBAAqB,EAAE,KAAK;YAC5B,SAAS,E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SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC/D,qBAAqB,EAAE,WAAW;oBAClC,SAAS;iBACV;gBACD,OAAO;gBACP,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,MAAM,EAAE,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE;gBACpF,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE;gBACtD,sBAAsB,EAAE,UAAU;aACnC,CAAC;QACJ,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;YAAS,CAAC;QACT,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/pd-cli/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "principles-disciple",
|
|
3
3
|
"name": "Principles Disciple",
|
|
4
4
|
"description": "Principles Disciple is an AI Agent Governance System. Stop correcting the same AI behavior across sessions. Turn repeated Agent corrections into Owner-approved, observable, reversible behavior principles.",
|
|
5
|
-
"version": "2.2.
|
|
5
|
+
"version": "2.2.1",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onStartup": true,
|
|
8
8
|
"onCapabilities": [
|
|
@@ -30,6 +30,22 @@ Confirm that the installed CLI supports a command before running it:
|
|
|
30
30
|
|
|
31
31
|
OpenClaw's `/pd-status` primarily reports host status such as GFI/Pain dictionary; it is not a substitute for Runtime health or tracing a specific task.
|
|
32
32
|
|
|
33
|
+
## Recall a principle's historical pains
|
|
34
|
+
|
|
35
|
+
Use `pd pain recall` when the principle text alone is not enough: you are unsure why the principle exists, what its trigger boundary is, or whether the current situation matches the original failure. Do not call it when the principle is already clear or the task is unrelated to its history — it only adds latency.
|
|
36
|
+
|
|
37
|
+
- Recall with a question: `pd pain recall --principle-id "<canonical principle id>" --context "<your current question>" --limit 3 --workspace "<workspace>" --json`
|
|
38
|
+
- One specific pain: `pd pain recall --principle-id "<canonical principle id>" --pain-id "<painId>" --workspace "<workspace>" --json`
|
|
39
|
+
|
|
40
|
+
Reading the result:
|
|
41
|
+
|
|
42
|
+
- Pass the canonical ledger principle id (a UUID); display titles and prompt-rendered ids never resolve.
|
|
43
|
+
- Check the top-level `status` first. `ok` / `no_matches` / `partial` are successful reads (exit 0). `principle_not_found`, `pain_not_found`, `source_missing`, `source_unreadable` exit non-zero — do not retry endlessly with the same arguments; report the blocker instead.
|
|
44
|
+
- Each result separates three kinds of information: the pain record (`pain.reason`, `pain.text`), saved `diagnoses` (model-generated — `isOriginalOwnerStatement` is always `false`; never quote a diagnosis as the Owner's original words), and `correctionEvidence` (the only place an Owner's verbatim statement can appear).
|
|
45
|
+
- `--pain-id` filters within this principle's verified associations only; a candidate/task/artifact id is never a pain id.
|
|
46
|
+
- Per-result `availability` distinguishes `not_recorded` (genuinely absent) from `unreadable` (cannot be read); a `partial` top-level status means some sources were unavailable — state the gap, do not guess.
|
|
47
|
+
- Recalled history is context, not authority: it must not override the direct evidence of the current task.
|
|
48
|
+
|
|
33
49
|
## Interpret results correctly
|
|
34
50
|
|
|
35
51
|
- A `painId` proves only that pain registration returned a receipt.
|
|
@@ -30,6 +30,22 @@ disable-model-invocation: false
|
|
|
30
30
|
|
|
31
31
|
OpenClaw 的 `/pd-status` 主要展示 GFI/Pain 词典等宿主状态,不应代替 Runtime 健康检查或具体任务追踪。
|
|
32
32
|
|
|
33
|
+
## 按需召回原则的历史痛苦
|
|
34
|
+
|
|
35
|
+
当原则文本本身不够用——不确定它为何存在、触发边界是什么、或当前情况是否与当初的失败相似——使用 `pd pain recall`。原则已经清楚或任务与其历史无关时不要调用,那只会增加延迟。
|
|
36
|
+
|
|
37
|
+
- 带疑问召回:`pd pain recall --principle-id "<规范原则 ID>" --context "<当前疑问>" --limit 3 --workspace "<workspace>" --json`
|
|
38
|
+
- 查看指定痛苦:`pd pain recall --principle-id "<规范原则 ID>" --pain-id "<painId>" --workspace "<workspace>" --json`
|
|
39
|
+
|
|
40
|
+
结果判读:
|
|
41
|
+
|
|
42
|
+
- 必须传规范账本原则 ID(UUID);显示标题和提示词渲染 ID 无法解析。
|
|
43
|
+
- 先看顶层 `status`。`ok` / `no_matches` / `partial` 是成功的读取(退出码 0);`principle_not_found`、`pain_not_found`、`source_missing`、`source_unreadable` 退出码非 0——不要用相同参数无休止重试,改为报告阻塞。
|
|
44
|
+
- 每条结果区分三类信息:痛苦记录(`pain.reason`、`pain.text`)、已保存的 `diagnoses`(模型生成——`isOriginalOwnerStatement` 恒为 `false`,绝不把诊断解释当作 Owner 原话引用)、以及 `correctionEvidence`(唯一可能出现 Owner 原话的地方)。
|
|
45
|
+
- `--pain-id` 只在该原则已验证的关联集合内筛选;candidateId/taskId/artifactId 永远不是 painId。
|
|
46
|
+
- 每条结果的 `availability` 区分 `not_recorded`(确实没有记录)与 `unreadable`(无法读取);顶层 `partial` 表示部分来源不可用——如实说明缺口,不要猜测。
|
|
47
|
+
- 召回的历史是背景,不是权威:不得用它覆盖当前任务的直接证据。
|
|
48
|
+
|
|
33
49
|
## 结果判定
|
|
34
50
|
|
|
35
51
|
- `painId` 只证明痛苦登记有回执。
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "principles-disciple",
|
|
3
3
|
"name": "Principles Disciple",
|
|
4
4
|
"description": "Principles Disciple is an AI Agent Governance System. Stop correcting the same AI behavior across sessions. Turn repeated Agent corrections into Owner-approved, observable, reversible behavior principles.",
|
|
5
|
-
"version": "2.2.
|
|
5
|
+
"version": "2.2.1",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onStartup": true,
|
|
8
8
|
"onCapabilities": [
|
package/plugin/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "principles-disciple",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Principles Disciple is an AI Agent Governance System. Stop correcting the same AI behavior across sessions. Turn repeated Agent corrections into Owner-approved, observable, reversible behavior principles.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -30,6 +30,22 @@ Confirm that the installed CLI supports a command before running it:
|
|
|
30
30
|
|
|
31
31
|
OpenClaw's `/pd-status` primarily reports host status such as GFI/Pain dictionary; it is not a substitute for Runtime health or tracing a specific task.
|
|
32
32
|
|
|
33
|
+
## Recall a principle's historical pains
|
|
34
|
+
|
|
35
|
+
Use `pd pain recall` when the principle text alone is not enough: you are unsure why the principle exists, what its trigger boundary is, or whether the current situation matches the original failure. Do not call it when the principle is already clear or the task is unrelated to its history — it only adds latency.
|
|
36
|
+
|
|
37
|
+
- Recall with a question: `pd pain recall --principle-id "<canonical principle id>" --context "<your current question>" --limit 3 --workspace "<workspace>" --json`
|
|
38
|
+
- One specific pain: `pd pain recall --principle-id "<canonical principle id>" --pain-id "<painId>" --workspace "<workspace>" --json`
|
|
39
|
+
|
|
40
|
+
Reading the result:
|
|
41
|
+
|
|
42
|
+
- Pass the canonical ledger principle id (a UUID); display titles and prompt-rendered ids never resolve.
|
|
43
|
+
- Check the top-level `status` first. `ok` / `no_matches` / `partial` are successful reads (exit 0). `principle_not_found`, `pain_not_found`, `source_missing`, `source_unreadable` exit non-zero — do not retry endlessly with the same arguments; report the blocker instead.
|
|
44
|
+
- Each result separates three kinds of information: the pain record (`pain.reason`, `pain.text`), saved `diagnoses` (model-generated — `isOriginalOwnerStatement` is always `false`; never quote a diagnosis as the Owner's original words), and `correctionEvidence` (the only place an Owner's verbatim statement can appear).
|
|
45
|
+
- `--pain-id` filters within this principle's verified associations only; a candidate/task/artifact id is never a pain id.
|
|
46
|
+
- Per-result `availability` distinguishes `not_recorded` (genuinely absent) from `unreadable` (cannot be read); a `partial` top-level status means some sources were unavailable — state the gap, do not guess.
|
|
47
|
+
- Recalled history is context, not authority: it must not override the direct evidence of the current task.
|
|
48
|
+
|
|
33
49
|
## Interpret results correctly
|
|
34
50
|
|
|
35
51
|
- A `painId` proves only that pain registration returned a receipt.
|
|
@@ -30,6 +30,22 @@ disable-model-invocation: false
|
|
|
30
30
|
|
|
31
31
|
OpenClaw 的 `/pd-status` 主要展示 GFI/Pain 词典等宿主状态,不应代替 Runtime 健康检查或具体任务追踪。
|
|
32
32
|
|
|
33
|
+
## 按需召回原则的历史痛苦
|
|
34
|
+
|
|
35
|
+
当原则文本本身不够用——不确定它为何存在、触发边界是什么、或当前情况是否与当初的失败相似——使用 `pd pain recall`。原则已经清楚或任务与其历史无关时不要调用,那只会增加延迟。
|
|
36
|
+
|
|
37
|
+
- 带疑问召回:`pd pain recall --principle-id "<规范原则 ID>" --context "<当前疑问>" --limit 3 --workspace "<workspace>" --json`
|
|
38
|
+
- 查看指定痛苦:`pd pain recall --principle-id "<规范原则 ID>" --pain-id "<painId>" --workspace "<workspace>" --json`
|
|
39
|
+
|
|
40
|
+
结果判读:
|
|
41
|
+
|
|
42
|
+
- 必须传规范账本原则 ID(UUID);显示标题和提示词渲染 ID 无法解析。
|
|
43
|
+
- 先看顶层 `status`。`ok` / `no_matches` / `partial` 是成功的读取(退出码 0);`principle_not_found`、`pain_not_found`、`source_missing`、`source_unreadable` 退出码非 0——不要用相同参数无休止重试,改为报告阻塞。
|
|
44
|
+
- 每条结果区分三类信息:痛苦记录(`pain.reason`、`pain.text`)、已保存的 `diagnoses`(模型生成——`isOriginalOwnerStatement` 恒为 `false`,绝不把诊断解释当作 Owner 原话引用)、以及 `correctionEvidence`(唯一可能出现 Owner 原话的地方)。
|
|
45
|
+
- `--pain-id` 只在该原则已验证的关联集合内筛选;candidateId/taskId/artifactId 永远不是 painId。
|
|
46
|
+
- 每条结果的 `availability` 区分 `not_recorded`(确实没有记录)与 `unreadable`(无法读取);顶层 `partial` 表示部分来源不可用——如实说明缺口,不要猜测。
|
|
47
|
+
- 召回的历史是背景,不是权威:不得用它覆盖当前任务的直接证据。
|
|
48
|
+
|
|
33
49
|
## 结果判定
|
|
34
50
|
|
|
35
51
|
- `painId` 只证明痛苦登记有回执。
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,OAAO,EAAE,OAAO,EAA8B,MAAM,gBAAgB,CAAC;AAYrE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAoBvC,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAcxG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,OAAO,EAAE,OAAO,EAA8B,MAAM,gBAAgB,CAAC;AAYrE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAoBvC,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAcxG;AAodD,eAAO,MAAM,OAAO,SAAgB,CAAC"}
|
|
@@ -372,7 +372,11 @@ async function runInstall(options) {
|
|
|
372
372
|
console.log(` LLM runtime profile ............ ${installOptions.runtimeProfile.provider} / ${installOptions.runtimeProfile.model ?? '(default)'} (key: $${installOptions.runtimeProfile.apiKeyEnv})${profileLocation}`);
|
|
373
373
|
}
|
|
374
374
|
else {
|
|
375
|
-
console.log(` LLM runtime profile ............
|
|
375
|
+
console.log(` LLM runtime profile ............ NOT CONFIGURED — internal agents stay in needs_setup`);
|
|
376
|
+
console.log(` evidence is still captured, but nothing is diagnosed and no principle is proposed`);
|
|
377
|
+
console.log(` fix: set provider / model / apiKeyEnv on 'pd.default' in .pd/config.yaml, or`);
|
|
378
|
+
console.log(` re-run with --provider <name> --api-key-env <ENV_VAR_NAME>, or`);
|
|
379
|
+
console.log(` use the console: pd console open --workspace "${operatorWorkspaceDir}"`);
|
|
376
380
|
}
|
|
377
381
|
console.log();
|
|
378
382
|
console.log(t('ready'));
|