@principles/host-runtime 2.0.2 → 2.2.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/adaptive-behavior-linkage.d.ts +223 -0
- package/dist/adaptive-behavior-linkage.js +990 -0
- package/dist/adaptive-journal-reconciliation.d.ts +215 -0
- package/dist/adaptive-journal-reconciliation.js +1066 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/package.json +3 -3
|
@@ -0,0 +1,215 @@
|
|
|
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 AdaptiveJournalConfigIdentity {
|
|
80
|
+
hostVersion: string | null;
|
|
81
|
+
pluginVersion: string | null;
|
|
82
|
+
effectiveHookSetFingerprint: string | null;
|
|
83
|
+
evidenceCoverage: string | null;
|
|
84
|
+
}
|
|
85
|
+
export interface AdaptiveJournalRecordProjection {
|
|
86
|
+
ts: string;
|
|
87
|
+
receiptState: 'open' | 'closed' | 'reconciled';
|
|
88
|
+
execution: string;
|
|
89
|
+
payload: string;
|
|
90
|
+
selection: string;
|
|
91
|
+
submission: string;
|
|
92
|
+
selectionPending: boolean | null;
|
|
93
|
+
reason: string | null;
|
|
94
|
+
artifactId: string | null;
|
|
95
|
+
activationId: string | null;
|
|
96
|
+
requestId: string | null;
|
|
97
|
+
/** PRI-1114: recorded target body hash; never re-computed by this reader. */
|
|
98
|
+
targetBodySha256: string | null;
|
|
99
|
+
/** PRI-1114: recorded call-configuration identity (PRI-1109 §3.3 contract). */
|
|
100
|
+
configIdentity: AdaptiveJournalConfigIdentity | null;
|
|
101
|
+
evidenceReferencePresent: boolean;
|
|
102
|
+
/** Transcribed as recorded; never re-verified by this reader. */
|
|
103
|
+
evidenceIndependentlyVerifiedAsRecorded: boolean | null;
|
|
104
|
+
/** Transcribed as recorded; never re-verified by this reader. */
|
|
105
|
+
hostKillConfirmedAsRecorded: boolean | null;
|
|
106
|
+
}
|
|
107
|
+
export interface AdaptiveJournalInvocationIdentity {
|
|
108
|
+
host: string;
|
|
109
|
+
workspaceDir: string | null;
|
|
110
|
+
workspaceVerified: boolean;
|
|
111
|
+
sessionId: string | null;
|
|
112
|
+
sessionIdSource: JournalSessionIdSource;
|
|
113
|
+
runId: string | null;
|
|
114
|
+
}
|
|
115
|
+
export interface AdaptiveJournalInvocation {
|
|
116
|
+
invocationId: string;
|
|
117
|
+
identity: AdaptiveJournalInvocationIdentity;
|
|
118
|
+
targetConsistent: boolean | null;
|
|
119
|
+
classification: JournalClassification;
|
|
120
|
+
reasonCodes: JournalReasonCode[];
|
|
121
|
+
open: AdaptiveJournalRecordProjection | null;
|
|
122
|
+
terminal: AdaptiveJournalRecordProjection | null;
|
|
123
|
+
terminalVariants: AdaptiveJournalRecordProjection[];
|
|
124
|
+
terminalVariantsOmitted: number;
|
|
125
|
+
duplicates: {
|
|
126
|
+
open: number;
|
|
127
|
+
terminal: number;
|
|
128
|
+
};
|
|
129
|
+
window: {
|
|
130
|
+
openInWindow: boolean;
|
|
131
|
+
terminalInWindow: boolean;
|
|
132
|
+
terminalSearchComplete: boolean;
|
|
133
|
+
};
|
|
134
|
+
unknowns: string[];
|
|
135
|
+
}
|
|
136
|
+
export interface AdaptiveJournalRejectedGroup {
|
|
137
|
+
reasonCode: JournalReasonCode;
|
|
138
|
+
count: number;
|
|
139
|
+
samples: {
|
|
140
|
+
logDir: string;
|
|
141
|
+
file: string;
|
|
142
|
+
line: number;
|
|
143
|
+
hookInvocationId: string | null;
|
|
144
|
+
}[];
|
|
145
|
+
}
|
|
146
|
+
export interface AdaptiveJournalAnswer {
|
|
147
|
+
count: number | null;
|
|
148
|
+
countBasis: JournalCountBasis;
|
|
149
|
+
invocationIds: string[];
|
|
150
|
+
reasonCodes?: string[];
|
|
151
|
+
}
|
|
152
|
+
export interface AdaptiveJournalTruncation {
|
|
153
|
+
reason: 'output_truncated';
|
|
154
|
+
limit: number;
|
|
155
|
+
included: number;
|
|
156
|
+
omitted: number;
|
|
157
|
+
omittedByClassification: Record<JournalClassification, number>;
|
|
158
|
+
variantLimitPerInvocation: number;
|
|
159
|
+
terminalVariantsOmitted: number;
|
|
160
|
+
coverageLimitCode: 'coverage_file_limit_reached' | null;
|
|
161
|
+
suggestions: string[];
|
|
162
|
+
}
|
|
163
|
+
export interface AdaptiveJournalReport {
|
|
164
|
+
schemaVersion: typeof ADAPTIVE_JOURNAL_SCHEMA_VERSION;
|
|
165
|
+
generatedAt: string;
|
|
166
|
+
readOnly: true;
|
|
167
|
+
request: AdaptiveJournalRequest;
|
|
168
|
+
coverage: AdaptiveJournalCoverage;
|
|
169
|
+
totals: AdaptiveJournalTotals;
|
|
170
|
+
invocations: AdaptiveJournalInvocation[];
|
|
171
|
+
rejected: AdaptiveJournalRejectedGroup[];
|
|
172
|
+
outputTruncated: boolean;
|
|
173
|
+
truncation: AdaptiveJournalTruncation | null;
|
|
174
|
+
answers: {
|
|
175
|
+
q1_open_and_terminal: AdaptiveJournalAnswer;
|
|
176
|
+
q2_open_without_visible_terminal: AdaptiveJournalAnswer;
|
|
177
|
+
q3_missing_start_or_identity_or_invalid: AdaptiveJournalAnswer;
|
|
178
|
+
q4_duplicate_or_conflicted: AdaptiveJournalAnswer;
|
|
179
|
+
q5: {
|
|
180
|
+
confirmedFacts: string[];
|
|
181
|
+
unknowns: string[];
|
|
182
|
+
notes: string[];
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
nextAction: string[];
|
|
186
|
+
}
|
|
187
|
+
export interface AdaptiveJournalError {
|
|
188
|
+
code: 'invalid_since' | 'invalid_until' | 'until_after_now' | 'since_after_until' | 'invalid_limit' | 'unsupported_host';
|
|
189
|
+
message: string;
|
|
190
|
+
nextAction: string;
|
|
191
|
+
}
|
|
192
|
+
export interface ReconcileAdaptiveJournalInput {
|
|
193
|
+
workspaceDir: string;
|
|
194
|
+
since?: string;
|
|
195
|
+
until?: string;
|
|
196
|
+
host?: string;
|
|
197
|
+
limits?: {
|
|
198
|
+
maxDateFilesPerDir?: number;
|
|
199
|
+
maxFileBytes?: number;
|
|
200
|
+
maxInvocations?: number;
|
|
201
|
+
maxTerminalVariantsPerInvocation?: number;
|
|
202
|
+
};
|
|
203
|
+
now?: Date;
|
|
204
|
+
}
|
|
205
|
+
export type ReconcileAdaptiveJournalResult = {
|
|
206
|
+
ok: true;
|
|
207
|
+
report: AdaptiveJournalReport;
|
|
208
|
+
} | {
|
|
209
|
+
ok: false;
|
|
210
|
+
schemaVersion: typeof ADAPTIVE_JOURNAL_SCHEMA_VERSION;
|
|
211
|
+
generatedAt: string;
|
|
212
|
+
readOnly: true;
|
|
213
|
+
error: AdaptiveJournalError;
|
|
214
|
+
};
|
|
215
|
+
export declare function reconcileAdaptiveJournal(input: ReconcileAdaptiveJournalInput): ReconcileAdaptiveJournalResult;
|