create-principles-disciple 1.147.8 → 1.147.10
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/_release/product-identity.json +2 -2
- package/core/dist/runtime-v2/activation/adaptive-delivery-record.d.ts +37 -0
- package/core/dist/runtime-v2/activation/adaptive-delivery-record.d.ts.map +1 -0
- package/core/dist/runtime-v2/activation/adaptive-delivery-record.js +126 -0
- package/core/dist/runtime-v2/activation/adaptive-delivery-record.js.map +1 -0
- package/core/dist/runtime-v2/activation/adaptive-principle-intervention.d.ts +46 -0
- package/core/dist/runtime-v2/activation/adaptive-principle-intervention.d.ts.map +1 -0
- package/core/dist/runtime-v2/activation/adaptive-principle-intervention.js +91 -0
- package/core/dist/runtime-v2/activation/adaptive-principle-intervention.js.map +1 -0
- package/core/dist/runtime-v2/activation/prompt-activation-reader-contract.d.ts +2 -0
- package/core/dist/runtime-v2/activation/prompt-activation-reader-contract.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/prompt-activation-reader-contract.js +2 -0
- package/core/dist/runtime-v2/activation/prompt-activation-reader-contract.js.map +1 -1
- package/core/dist/runtime-v2/index.d.ts +4 -0
- package/core/dist/runtime-v2/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/index.js +3 -0
- package/core/dist/runtime-v2/index.js.map +1 -1
- package/core/dist/runtime-v2/store/sqlite-connection.js +1 -1
- package/core/dist/runtime-v2/store/sqlite-connection.js.map +1 -1
- package/core/dist/runtime-v2/store/workspace-leak-guard.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/workspace-leak-guard.js +8 -2
- package/core/dist/runtime-v2/store/workspace-leak-guard.js.map +1 -1
- package/core/dist/runtime-v2/types/event-types.d.ts +6 -3
- package/core/dist/runtime-v2/types/event-types.d.ts.map +1 -1
- package/core/dist/runtime-v2/types/event-types.js +2 -0
- package/core/dist/runtime-v2/types/event-types.js.map +1 -1
- package/core/package.json +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/install-summary.d.ts +3 -0
- package/dist/install-summary.d.ts.map +1 -1
- package/dist/install-summary.js +17 -9
- package/dist/install-summary.js.map +1 -1
- package/dist/installers/workbuddy-host-installer.d.ts +20 -1
- package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
- package/dist/installers/workbuddy-host-installer.js +75 -14
- package/dist/installers/workbuddy-host-installer.js.map +1 -1
- package/host-runtime/dist/active-principle-prompt.d.ts +28 -0
- package/host-runtime/dist/active-principle-prompt.js +163 -50
- package/host-runtime/dist/adaptive-journal-reconciliation.d.ts +205 -0
- package/host-runtime/dist/adaptive-journal-reconciliation.js +1050 -0
- package/host-runtime/dist/adaptive-principle-revalidation.d.ts +8 -0
- package/host-runtime/dist/adaptive-principle-revalidation.js +52 -0
- package/host-runtime/dist/index.d.ts +17 -0
- package/host-runtime/dist/index.js +35 -0
- package/host-runtime/dist/prompt-activation-authority.d.ts +7 -0
- package/host-runtime/dist/prompt-activation-authority.js +16 -0
- package/host-runtime/package.json +1 -1
- package/package.json +3 -3
- package/pd-cli/dist/commands/runtime-activation.d.ts +18 -0
- package/pd-cli/dist/commands/runtime-activation.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-activation.js +73 -1
- package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
- package/pd-cli/dist/index.js +3 -1
- package/pd-cli/dist/index.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/plugin/dist/bundle.js +457 -455
- package/plugin/dist/core/adaptive-config-identity.d.ts +106 -0
- package/plugin/dist/core/event-log.d.ts +3 -0
- package/plugin/dist/governance-audit.js +3 -3
- package/plugin/dist/hooks/adaptive-activation-config.d.ts +8 -0
- package/plugin/dist/hooks/prompt-helpers.d.ts +5 -0
- package/plugin/dist/hooks/prompt-types.d.ts +3 -0
- package/plugin/dist/hooks/prompt.d.ts +8 -1
- package/plugin/dist/host-runtime/openclaw-host-runtime.d.ts +13 -0
- package/plugin/dist/openclaw-sdk.d.ts +4 -0
- package/plugin/dist/openclaw.plugin.json +33 -1
- package/plugin/dist/rulehost-evidence.js +1 -1
- package/plugin/openclaw.plugin.json +33 -1
- package/plugin/package.json +1 -1
- package/release-manager/dist/installers/workbuddy-host-installer.js +75 -14
- package/release-manager/package.json +1 -1
|
@@ -3,6 +3,8 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { escapeXml } from '@principles/core/prompt-builder';
|
|
5
5
|
import { loadPdConfigForPlugin } from './pd-config.js';
|
|
6
|
+
import { readPromptActivationAuthority } from './prompt-activation-authority.js';
|
|
7
|
+
import { revalidateAdaptivePrinciple } from './adaptive-principle-revalidation.js';
|
|
6
8
|
/** PRI-904 SPEC §10: bounded diagnostic id lists (mirrors the core selector's cap of 16). */
|
|
7
9
|
export const MAX_SHARED_DIAGNOSTIC_IDS = 16;
|
|
8
10
|
/**
|
|
@@ -34,7 +36,10 @@ export async function readPromptActivationCandidates(input) {
|
|
|
34
36
|
return { principles, warnings, aborted: true, selfReportEnabled, abstractionLayerEnabled };
|
|
35
37
|
}
|
|
36
38
|
try {
|
|
37
|
-
connection = new SqliteConnection({ workspaceDir: input.workspaceDir, readonly: true, bootstrapIfMissing: false
|
|
39
|
+
connection = new SqliteConnection({ workspaceDir: input.workspaceDir, readonly: true, bootstrapIfMissing: false,
|
|
40
|
+
// Additional adaptive reads must not hold the host behind SQLite's synchronous busy wait.
|
|
41
|
+
...(input.includeAuthority === true ? { busyTimeoutMs: 0 } : {}),
|
|
42
|
+
});
|
|
38
43
|
const activations = filterPromptActivations(await new SqliteActivationStateStore(connection).listPromptActivations());
|
|
39
44
|
const artifactStore = new SqlitePIArtifactStore(connection);
|
|
40
45
|
for (const activation of activations) {
|
|
@@ -61,6 +66,19 @@ export async function readPromptActivationCandidates(input) {
|
|
|
61
66
|
warnings.push(resolved.warning);
|
|
62
67
|
continue;
|
|
63
68
|
}
|
|
69
|
+
if (input.includeAuthority === true) {
|
|
70
|
+
try {
|
|
71
|
+
const authority = readPromptActivationAuthority(connection, artifact.artifactId, 'prompt');
|
|
72
|
+
if (authority.authority)
|
|
73
|
+
resolved.principle.authority = authority.authority;
|
|
74
|
+
if (authority.approvedBy)
|
|
75
|
+
resolved.principle.approvedBy = authority.approvedBy;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Approval lookup failure is unknown, never inferred as owner or policy.
|
|
79
|
+
warnings.push(`prompt_activation_authority_unavailable: artifactId=${artifact.artifactId}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
64
82
|
principles.push(resolved.principle);
|
|
65
83
|
}
|
|
66
84
|
}
|
|
@@ -84,6 +102,11 @@ export async function buildActivePrinciplePromptContext(input) {
|
|
|
84
102
|
additionalContext: '', principleIds: [], activationIds: [], artifactIds: [], warnings,
|
|
85
103
|
budget: budgetChars, truncated: false,
|
|
86
104
|
selectionPolicy: 'legacy_fifo_prefix_v1', eligibleCount: 0,
|
|
105
|
+
...(input.adaptivePriority ? { adaptivePacking: {
|
|
106
|
+
status: 'unavailable', reason: 'reader_aborted',
|
|
107
|
+
targetActivationId: input.adaptivePriority.activationId, targetArtifactId: input.adaptivePriority.artifactId,
|
|
108
|
+
displacedActivationIds: [], ...(input.hookInvocationId ? { hookInvocationId: input.hookInvocationId } : {}),
|
|
109
|
+
} } : {}),
|
|
87
110
|
budgetCapacitySource: promptBudget.capacitySource,
|
|
88
111
|
budgetCapacityStatus: promptBudget.capacityStatus,
|
|
89
112
|
budgetContextWindowTokens: promptBudget.contextWindowTokens,
|
|
@@ -92,9 +115,6 @@ export async function buildActivePrinciplePromptContext(input) {
|
|
|
92
115
|
...(promptBudget.fallbackDetail !== undefined ? { budgetFallbackDetail: promptBudget.fallbackDetail } : {}),
|
|
93
116
|
};
|
|
94
117
|
}
|
|
95
|
-
const included = [];
|
|
96
|
-
let additionalContext = '';
|
|
97
|
-
let truncated = false;
|
|
98
118
|
// PRI-904: same fair-rotation semantics as the plugin route's trimToBudget —
|
|
99
119
|
// deterministic rotating start over the base (ASC) candidate order, circular
|
|
100
120
|
// scan, continue-on-non-fit. Costs are measured with the REAL serializer
|
|
@@ -108,56 +128,149 @@ export async function buildActivePrinciplePromptContext(input) {
|
|
|
108
128
|
const rotationStartIndex = selectionPolicy === 'fair_rotation_v1' && roundKey !== undefined
|
|
109
129
|
? ((roundKey % n) + n) % n
|
|
110
130
|
: undefined;
|
|
111
|
-
const
|
|
112
|
-
const oversizedActivationIds = [];
|
|
113
|
-
const standaloneFits = (principle) => renderPrinciplesToDirectives([principle], new Set([principle.principleId]), { escapeFn: escapeXml, selfReportInstruction: selfReportEnabled }).length
|
|
114
|
-
<= budgetChars;
|
|
115
|
-
const scanOrder = rotationStartIndex === undefined
|
|
131
|
+
const nativeScanOrder = rotationStartIndex === undefined
|
|
116
132
|
? principles
|
|
117
133
|
: principles.slice(rotationStartIndex).concat(principles.slice(0, rotationStartIndex));
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
134
|
+
const pack = (scanOrder) => {
|
|
135
|
+
const included = [];
|
|
136
|
+
let additionalContext = '';
|
|
137
|
+
let truncated = false;
|
|
138
|
+
const dropped = [];
|
|
139
|
+
const oversized = [];
|
|
140
|
+
const standaloneFits = (principle) => renderPrinciplesToDirectives([principle], new Set([principle.principleId]), { escapeFn: escapeXml, selfReportInstruction: selfReportEnabled }).length
|
|
141
|
+
<= budgetChars;
|
|
142
|
+
for (const principle of scanOrder) {
|
|
143
|
+
const candidate = [...included, principle];
|
|
144
|
+
const candidateContext = renderPrinciplesToDirectives(candidate, new Set(candidate.map((entry) => entry.principleId)), { escapeFn: escapeXml, selfReportInstruction: selfReportEnabled });
|
|
145
|
+
if (candidateContext.length > budgetChars) {
|
|
146
|
+
if (standaloneFits(principle)) {
|
|
147
|
+
truncated = true;
|
|
148
|
+
if (dropped.length < MAX_SHARED_DIAGNOSTIC_IDS)
|
|
149
|
+
dropped.push(principle.activationId);
|
|
150
|
+
}
|
|
151
|
+
else if (oversized.length < MAX_SHARED_DIAGNOSTIC_IDS) {
|
|
152
|
+
oversized.push(principle.activationId);
|
|
153
|
+
}
|
|
154
|
+
if (selectionPolicy === 'legacy_fifo_prefix_v1')
|
|
155
|
+
break;
|
|
156
|
+
continue;
|
|
131
157
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
continue;
|
|
158
|
+
included.push(principle);
|
|
159
|
+
additionalContext = candidateContext;
|
|
135
160
|
}
|
|
136
|
-
included
|
|
137
|
-
|
|
161
|
+
return { included, additionalContext, truncated, dropped, oversized };
|
|
162
|
+
};
|
|
163
|
+
const makeResult = (packing, eligiblePrinciples, adaptivePacking) => {
|
|
164
|
+
const resultWarnings = [...warnings];
|
|
165
|
+
if (packing.truncated) {
|
|
166
|
+
resultWarnings.push('prompt_context_truncated: production_prompt_cap; nextAction=reduce_active_prompt_principles');
|
|
167
|
+
}
|
|
168
|
+
const injectedIds = new Set(packing.included.map((principle) => principle.principleId));
|
|
169
|
+
return {
|
|
170
|
+
additionalContext: packing.additionalContext,
|
|
171
|
+
principleIds: [...injectedIds],
|
|
172
|
+
activationIds: packing.included.map((principle) => principle.activationId),
|
|
173
|
+
artifactIds: packing.included.map((principle) => principle.artifactId),
|
|
174
|
+
warnings: resultWarnings,
|
|
175
|
+
budget: budgetChars,
|
|
176
|
+
truncated: packing.truncated,
|
|
177
|
+
selectionPolicy,
|
|
178
|
+
eligibleCount: eligiblePrinciples.length,
|
|
179
|
+
...(rotationStartIndex !== undefined ? { rotationStartIndex } : {}),
|
|
180
|
+
...(packing.dropped.length > 0 ? { droppedActivationIds: packing.dropped } : {}),
|
|
181
|
+
...(packing.oversized.length > 0 ? { oversizedActivationIds: packing.oversized } : {}),
|
|
182
|
+
budgetCapacitySource: promptBudget.capacitySource,
|
|
183
|
+
budgetCapacityStatus: promptBudget.capacityStatus,
|
|
184
|
+
budgetContextWindowTokens: promptBudget.contextWindowTokens,
|
|
185
|
+
budgetPolicyVersion: promptBudget.policyVersion,
|
|
186
|
+
...(promptBudget.fallbackReason !== undefined ? { budgetFallbackReason: promptBudget.fallbackReason } : {}),
|
|
187
|
+
...(promptBudget.fallbackDetail !== undefined ? { budgetFallbackDetail: promptBudget.fallbackDetail } : {}),
|
|
188
|
+
...(adaptivePacking ? { adaptivePacking } : {}),
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
const nativePacking = pack(nativeScanOrder);
|
|
192
|
+
const nativeResult = makeResult(nativePacking, principles);
|
|
193
|
+
const priority = input.adaptivePriority;
|
|
194
|
+
if (priority === undefined)
|
|
195
|
+
return nativeResult;
|
|
196
|
+
const report = (status, reason, displacedActivationIds = []) => ({
|
|
197
|
+
status,
|
|
198
|
+
...(reason ? { reason } : {}),
|
|
199
|
+
targetActivationId: typeof priority.activationId === 'string' ? priority.activationId : '',
|
|
200
|
+
targetArtifactId: typeof priority.artifactId === 'string' ? priority.artifactId : '',
|
|
201
|
+
...(input.hookInvocationId ? { hookInvocationId: input.hookInvocationId } : {}),
|
|
202
|
+
displacedActivationIds,
|
|
203
|
+
});
|
|
204
|
+
const nativeTargetMatches = principles.filter((principle) => principle.artifactId === priority.artifactId && principle.activationId === priority.activationId);
|
|
205
|
+
const [nativeTarget] = nativeTargetMatches;
|
|
206
|
+
const baselineHasTarget = nativePacking.included.some((principle) => principle.artifactId === priority.artifactId && principle.activationId === priority.activationId);
|
|
207
|
+
const withoutTarget = (reason) => {
|
|
208
|
+
if (nativeTargetMatches.length !== 1 || !nativeTarget)
|
|
209
|
+
return { ...nativeResult, adaptivePacking: report('unavailable', reason) };
|
|
210
|
+
const targetPrincipleId = nativeTarget.principleId;
|
|
211
|
+
const safePrinciples = principles.filter((principle) => principle.principleId !== targetPrincipleId);
|
|
212
|
+
const safeScanOrder = nativeScanOrder.filter((principle) => principle.principleId !== targetPrincipleId);
|
|
213
|
+
const safePacking = pack(safeScanOrder);
|
|
214
|
+
return makeResult(safePacking, safePrinciples, report('unavailable', reason, baselineHasTarget ? [nativeTarget.activationId] : []));
|
|
215
|
+
};
|
|
216
|
+
if (typeof priority.artifactId !== 'string' || !priority.artifactId.trim()
|
|
217
|
+
|| typeof priority.activationId !== 'string' || !priority.activationId.trim()) {
|
|
218
|
+
return { ...nativeResult, adaptivePacking: report('unavailable', 'invalid_target') };
|
|
138
219
|
}
|
|
139
|
-
if (
|
|
140
|
-
|
|
220
|
+
if (nativeTargetMatches.length === 0)
|
|
221
|
+
return { ...nativeResult, adaptivePacking: report('unavailable', 'target_unavailable') };
|
|
222
|
+
if (nativeTargetMatches.length !== 1)
|
|
223
|
+
return { ...nativeResult, adaptivePacking: report('unavailable', 'target_ambiguous') };
|
|
224
|
+
if (!nativeTarget)
|
|
225
|
+
return { ...nativeResult, adaptivePacking: report('unavailable', 'target_unavailable') };
|
|
226
|
+
if (principles.filter((principle) => principle.principleId === nativeTarget.principleId).length !== 1) {
|
|
227
|
+
return { ...nativeResult, adaptivePacking: report('unavailable', 'target_ambiguous') };
|
|
141
228
|
}
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
...(
|
|
161
|
-
|
|
162
|
-
|
|
229
|
+
const authorityRead = await readPromptActivationCandidates({ workspaceDir: input.workspaceDir, includeAuthority: true });
|
|
230
|
+
const authorizedMatches = authorityRead.principles.filter((principle) => principle.artifactId === priority.artifactId && principle.activationId === priority.activationId);
|
|
231
|
+
const [authorizedTarget] = authorizedMatches;
|
|
232
|
+
if (authorityRead.aborted || authorityRead.warnings.length > 0 || authorizedMatches.length !== 1 || !authorizedTarget
|
|
233
|
+
|| authorityRead.principles.filter((principle) => principle.principleId === authorizedTarget.principleId).length !== 1) {
|
|
234
|
+
return withoutTarget('authority_unavailable');
|
|
235
|
+
}
|
|
236
|
+
if (!authorizedTarget.authority
|
|
237
|
+
|| authorizedTarget.principleId !== nativeTarget.principleId
|
|
238
|
+
|| authorizedTarget.text !== nativeTarget.text
|
|
239
|
+
|| authorizedTarget.artifactContentSha256 !== nativeTarget.artifactContentSha256) {
|
|
240
|
+
return withoutTarget('target_changed');
|
|
241
|
+
}
|
|
242
|
+
const signal = input.signal ?? new AbortController().signal;
|
|
243
|
+
const targetRendered = renderPrinciplesToDirectives([nativeTarget], new Set([nativeTarget.principleId]), { escapeFn: escapeXml });
|
|
244
|
+
const targetBody = targetRendered.slice(targetRendered.indexOf('<directive '), targetRendered.indexOf('</directive>') + '</directive>'.length);
|
|
245
|
+
const prepared = (status, displaced = []) => ({
|
|
246
|
+
...report(status, undefined, displaced), targetSnapshot: authorizedTarget, targetBody,
|
|
247
|
+
nativeBaseline: nativeResult, ...(input.deadlineAt !== undefined ? { deadlineAt: input.deadlineAt } : {}),
|
|
248
|
+
});
|
|
249
|
+
if (baselineHasTarget) {
|
|
250
|
+
const stillValid = await revalidateAdaptivePrinciple(input.workspaceDir, authorizedTarget, signal);
|
|
251
|
+
if (!stillValid)
|
|
252
|
+
return withoutTarget('target_changed');
|
|
253
|
+
return { ...nativeResult, adaptivePacking: prepared('target_present') };
|
|
254
|
+
}
|
|
255
|
+
const targetIndex = nativeScanOrder.indexOf(nativeTarget);
|
|
256
|
+
const targetFirstScan = [nativeTarget, ...nativeScanOrder.filter((principle, index) => index !== targetIndex && principle.principleId !== nativeTarget.principleId)];
|
|
257
|
+
const prioritizedPacking = pack(targetFirstScan);
|
|
258
|
+
if (!prioritizedPacking.included.some((principle) => principle.principleId === nativeTarget.principleId)) {
|
|
259
|
+
return { ...nativeResult, adaptivePacking: report('unavailable', 'target_does_not_fit') };
|
|
260
|
+
}
|
|
261
|
+
const mandatoryIds = input.mandatoryPrincipleIds ?? [];
|
|
262
|
+
if (!Array.isArray(mandatoryIds) || mandatoryIds.some((id) => typeof id !== 'string')
|
|
263
|
+
|| mandatoryIds.some((id) => !prioritizedPacking.included.some((principle) => principle.principleId === id))) {
|
|
264
|
+
return { ...nativeResult, adaptivePacking: report('unavailable', 'mandatory_constraint_displaced') };
|
|
265
|
+
}
|
|
266
|
+
const stillValid = await revalidateAdaptivePrinciple(input.workspaceDir, authorizedTarget, signal);
|
|
267
|
+
if (!stillValid)
|
|
268
|
+
return { ...nativeResult, adaptivePacking: report('unavailable', 'target_changed') };
|
|
269
|
+
const prioritizedActivationIds = new Set(prioritizedPacking.included.map((principle) => principle.activationId));
|
|
270
|
+
const displacedActivationIds = nativePacking.included
|
|
271
|
+
.filter((principle) => !prioritizedActivationIds.has(principle.activationId))
|
|
272
|
+
.map((principle) => principle.activationId);
|
|
273
|
+
const result = makeResult(prioritizedPacking, principles, prepared('prioritized', displacedActivationIds));
|
|
274
|
+
// Adaptive assembly is deliberately limited to the existing renderer's Native budget cap.
|
|
275
|
+
return result;
|
|
163
276
|
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PRI-1109 — conservative, read-only reconciliation of adaptive-delivery journal
|
|
3
|
+
* records (approved design: docs/specs/PD-AA-PRI-1109-JOURNAL-RECONCILE-DESIGN-v0.2.md).
|
|
4
|
+
*
|
|
5
|
+
* Semantic red lines enforced here:
|
|
6
|
+
* - closed/reconciled is a recorded phase, never success;
|
|
7
|
+
* - payload=confirmed and submission are only transcribed as recorded evidence
|
|
8
|
+
* declarations (never re-verified by this reader);
|
|
9
|
+
* - an absent terminal, absent start, or absent log is "not visible in the
|
|
10
|
+
* scanned range", never a claim about what happened outside it;
|
|
11
|
+
* - non-adaptive events are irrelevant, not invalid;
|
|
12
|
+
* - every truncation / coverage limit is explicit, never silent.
|
|
13
|
+
*/
|
|
14
|
+
export declare const ADAPTIVE_JOURNAL_SCHEMA_VERSION: 'pd-aa-journal-reconciliation/v1';
|
|
15
|
+
export declare const ADAPTIVE_JOURNAL_CANDIDATE_DIRS: readonly ['.pd/logs', '.state/logs'];
|
|
16
|
+
export declare const ADAPTIVE_JOURNAL_MAX_DATE_FILES_PER_DIR = 9;
|
|
17
|
+
export declare const ADAPTIVE_JOURNAL_MAX_FILE_BYTES: number;
|
|
18
|
+
export declare const ADAPTIVE_JOURNAL_MAX_INVOCATIONS = 1000;
|
|
19
|
+
export declare const ADAPTIVE_JOURNAL_MAX_TERMINAL_VARIANTS = 5;
|
|
20
|
+
export declare const ADAPTIVE_JOURNAL_SUPPORTED_HOST = "openclaw";
|
|
21
|
+
export type JournalClassification = 'paired_open_and_terminal' | 'open_only' | 'terminal_only' | 'conflicted' | 'invalid';
|
|
22
|
+
/** Closed reason-code set from design §6. */
|
|
23
|
+
export type JournalReasonCode = 'terminal_not_visible_in_range' | 'window_end_explicit_not_now' | 'start_not_visible_in_range' | 'exact_duplicate_record' | 'multiple_starts_conflict' | 'conflicting_terminal_states' | 'target_identity_mismatch' | 'malformed_json' | 'non_adaptive_event' | 'invalid_envelope' | 'missing_hook_invocation_id' | 'invalid_four_dimension_state' | 'session_identity_mismatch' | 'workspace_identity_unknown' | 'foreign_workspace' | 'host_identity_unknown' | 'record_before_coverage_start' | 'output_truncated' | 'terminal_variants_truncated';
|
|
24
|
+
export type JournalSessionIdSource = 'envelope' | 'data' | 'both' | 'none';
|
|
25
|
+
export type JournalCoverageStatus = 'complete' | 'partial' | 'unavailable';
|
|
26
|
+
export type JournalCountBasis = 'exact' | 'lower_bound' | null;
|
|
27
|
+
export interface AdaptiveJournalRequestWindow {
|
|
28
|
+
start: string;
|
|
29
|
+
end: string;
|
|
30
|
+
inclusiveBounds: '[start,end]';
|
|
31
|
+
endIsNow: boolean;
|
|
32
|
+
requestedStart: string;
|
|
33
|
+
clampedByRetention: boolean;
|
|
34
|
+
retentionDays: number;
|
|
35
|
+
}
|
|
36
|
+
export interface AdaptiveJournalRequest {
|
|
37
|
+
workspaceDir: string;
|
|
38
|
+
host: string;
|
|
39
|
+
window: AdaptiveJournalRequestWindow;
|
|
40
|
+
logDirs: string[];
|
|
41
|
+
pairingKey: string[];
|
|
42
|
+
}
|
|
43
|
+
export interface AdaptiveJournalCoverageError {
|
|
44
|
+
logDir: string;
|
|
45
|
+
file: string | null;
|
|
46
|
+
code: 'read_failed' | 'stat_failed' | 'outside_workspace';
|
|
47
|
+
message: string;
|
|
48
|
+
}
|
|
49
|
+
export interface AdaptiveJournalCoverage {
|
|
50
|
+
status: JournalCoverageStatus;
|
|
51
|
+
sourceDirsFound: number;
|
|
52
|
+
filesRead: number;
|
|
53
|
+
filesSkipped: number;
|
|
54
|
+
bytesRead: number;
|
|
55
|
+
dateFilesIntersecting: number;
|
|
56
|
+
limitCode: 'coverage_file_limit_reached' | null;
|
|
57
|
+
filesOmitted: string[];
|
|
58
|
+
truncatedFiles: string[];
|
|
59
|
+
errors: AdaptiveJournalCoverageError[];
|
|
60
|
+
/**
|
|
61
|
+
* True when at least one record's canonical full content exceeded the identity
|
|
62
|
+
* comparison budget. Those records were conservatively treated as distinct:
|
|
63
|
+
* exact duplication was never asserted for them.
|
|
64
|
+
*/
|
|
65
|
+
identityComparisonLimited: boolean;
|
|
66
|
+
}
|
|
67
|
+
export interface AdaptiveJournalTotals {
|
|
68
|
+
linesRead: number | null;
|
|
69
|
+
adaptiveRecords: number | null;
|
|
70
|
+
nonAdaptiveLines: number | null;
|
|
71
|
+
malformedJsonLines: number | null;
|
|
72
|
+
invalidEnvelopeRecords: number | null;
|
|
73
|
+
invalidRecords: number | null;
|
|
74
|
+
duplicatesExact: number | null;
|
|
75
|
+
uniqueInvocations: number | null;
|
|
76
|
+
rejectedRecords: number | null;
|
|
77
|
+
countsAreLowerBounds: boolean;
|
|
78
|
+
}
|
|
79
|
+
export interface AdaptiveJournalRecordProjection {
|
|
80
|
+
ts: string;
|
|
81
|
+
receiptState: 'open' | 'closed' | 'reconciled';
|
|
82
|
+
execution: string;
|
|
83
|
+
payload: string;
|
|
84
|
+
selection: string;
|
|
85
|
+
submission: string;
|
|
86
|
+
selectionPending: boolean | null;
|
|
87
|
+
reason: string | null;
|
|
88
|
+
artifactId: string | null;
|
|
89
|
+
activationId: string | null;
|
|
90
|
+
requestId: string | null;
|
|
91
|
+
evidenceReferencePresent: boolean;
|
|
92
|
+
/** Transcribed as recorded; never re-verified by this reader. */
|
|
93
|
+
evidenceIndependentlyVerifiedAsRecorded: boolean | null;
|
|
94
|
+
/** Transcribed as recorded; never re-verified by this reader. */
|
|
95
|
+
hostKillConfirmedAsRecorded: boolean | null;
|
|
96
|
+
}
|
|
97
|
+
export interface AdaptiveJournalInvocationIdentity {
|
|
98
|
+
host: string;
|
|
99
|
+
workspaceDir: string | null;
|
|
100
|
+
workspaceVerified: boolean;
|
|
101
|
+
sessionId: string | null;
|
|
102
|
+
sessionIdSource: JournalSessionIdSource;
|
|
103
|
+
runId: string | null;
|
|
104
|
+
}
|
|
105
|
+
export interface AdaptiveJournalInvocation {
|
|
106
|
+
invocationId: string;
|
|
107
|
+
identity: AdaptiveJournalInvocationIdentity;
|
|
108
|
+
targetConsistent: boolean | null;
|
|
109
|
+
classification: JournalClassification;
|
|
110
|
+
reasonCodes: JournalReasonCode[];
|
|
111
|
+
open: AdaptiveJournalRecordProjection | null;
|
|
112
|
+
terminal: AdaptiveJournalRecordProjection | null;
|
|
113
|
+
terminalVariants: AdaptiveJournalRecordProjection[];
|
|
114
|
+
terminalVariantsOmitted: number;
|
|
115
|
+
duplicates: {
|
|
116
|
+
open: number;
|
|
117
|
+
terminal: number;
|
|
118
|
+
};
|
|
119
|
+
window: {
|
|
120
|
+
openInWindow: boolean;
|
|
121
|
+
terminalInWindow: boolean;
|
|
122
|
+
terminalSearchComplete: boolean;
|
|
123
|
+
};
|
|
124
|
+
unknowns: string[];
|
|
125
|
+
}
|
|
126
|
+
export interface AdaptiveJournalRejectedGroup {
|
|
127
|
+
reasonCode: JournalReasonCode;
|
|
128
|
+
count: number;
|
|
129
|
+
samples: {
|
|
130
|
+
logDir: string;
|
|
131
|
+
file: string;
|
|
132
|
+
line: number;
|
|
133
|
+
hookInvocationId: string | null;
|
|
134
|
+
}[];
|
|
135
|
+
}
|
|
136
|
+
export interface AdaptiveJournalAnswer {
|
|
137
|
+
count: number | null;
|
|
138
|
+
countBasis: JournalCountBasis;
|
|
139
|
+
invocationIds: string[];
|
|
140
|
+
reasonCodes?: string[];
|
|
141
|
+
}
|
|
142
|
+
export interface AdaptiveJournalTruncation {
|
|
143
|
+
reason: 'output_truncated';
|
|
144
|
+
limit: number;
|
|
145
|
+
included: number;
|
|
146
|
+
omitted: number;
|
|
147
|
+
omittedByClassification: Record<JournalClassification, number>;
|
|
148
|
+
variantLimitPerInvocation: number;
|
|
149
|
+
terminalVariantsOmitted: number;
|
|
150
|
+
coverageLimitCode: 'coverage_file_limit_reached' | null;
|
|
151
|
+
suggestions: string[];
|
|
152
|
+
}
|
|
153
|
+
export interface AdaptiveJournalReport {
|
|
154
|
+
schemaVersion: typeof ADAPTIVE_JOURNAL_SCHEMA_VERSION;
|
|
155
|
+
generatedAt: string;
|
|
156
|
+
readOnly: true;
|
|
157
|
+
request: AdaptiveJournalRequest;
|
|
158
|
+
coverage: AdaptiveJournalCoverage;
|
|
159
|
+
totals: AdaptiveJournalTotals;
|
|
160
|
+
invocations: AdaptiveJournalInvocation[];
|
|
161
|
+
rejected: AdaptiveJournalRejectedGroup[];
|
|
162
|
+
outputTruncated: boolean;
|
|
163
|
+
truncation: AdaptiveJournalTruncation | null;
|
|
164
|
+
answers: {
|
|
165
|
+
q1_open_and_terminal: AdaptiveJournalAnswer;
|
|
166
|
+
q2_open_without_visible_terminal: AdaptiveJournalAnswer;
|
|
167
|
+
q3_missing_start_or_identity_or_invalid: AdaptiveJournalAnswer;
|
|
168
|
+
q4_duplicate_or_conflicted: AdaptiveJournalAnswer;
|
|
169
|
+
q5: {
|
|
170
|
+
confirmedFacts: string[];
|
|
171
|
+
unknowns: string[];
|
|
172
|
+
notes: string[];
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
nextAction: string[];
|
|
176
|
+
}
|
|
177
|
+
export interface AdaptiveJournalError {
|
|
178
|
+
code: 'invalid_since' | 'invalid_until' | 'until_after_now' | 'since_after_until' | 'invalid_limit' | 'unsupported_host';
|
|
179
|
+
message: string;
|
|
180
|
+
nextAction: string;
|
|
181
|
+
}
|
|
182
|
+
export interface ReconcileAdaptiveJournalInput {
|
|
183
|
+
workspaceDir: string;
|
|
184
|
+
since?: string;
|
|
185
|
+
until?: string;
|
|
186
|
+
host?: string;
|
|
187
|
+
limits?: {
|
|
188
|
+
maxDateFilesPerDir?: number;
|
|
189
|
+
maxFileBytes?: number;
|
|
190
|
+
maxInvocations?: number;
|
|
191
|
+
maxTerminalVariantsPerInvocation?: number;
|
|
192
|
+
};
|
|
193
|
+
now?: Date;
|
|
194
|
+
}
|
|
195
|
+
export type ReconcileAdaptiveJournalResult = {
|
|
196
|
+
ok: true;
|
|
197
|
+
report: AdaptiveJournalReport;
|
|
198
|
+
} | {
|
|
199
|
+
ok: false;
|
|
200
|
+
schemaVersion: typeof ADAPTIVE_JOURNAL_SCHEMA_VERSION;
|
|
201
|
+
generatedAt: string;
|
|
202
|
+
readOnly: true;
|
|
203
|
+
error: AdaptiveJournalError;
|
|
204
|
+
};
|
|
205
|
+
export declare function reconcileAdaptiveJournal(input: ReconcileAdaptiveJournalInput): ReconcileAdaptiveJournalResult;
|