@principles/host-runtime 2.1.0 → 2.2.1
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 +1014 -0
- package/dist/adaptive-journal-reconciliation.d.ts +10 -0
- package/dist/adaptive-journal-reconciliation.js +16 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/prompt-injection-budget-observation.js +31 -2
- package/package.json +2 -2
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PRI-1114 — read-only behavior evidence linkage.
|
|
3
|
+
*
|
|
4
|
+
* Design: docs/specs/PD-AA-PRI-1114-BEHAVIOR-EVIDENCE-LINK-DESIGN-v0.2.md
|
|
5
|
+
*
|
|
6
|
+
* This module answers a deliberately narrow question: which recorded actions,
|
|
7
|
+
* corrections and task outcomes belong to the same *run* as a recorded
|
|
8
|
+
* principle intervention. It never claims a request-level link, never claims
|
|
9
|
+
* the intervention was delivered before an action, and never upgrades a
|
|
10
|
+
* model-completion record into task success.
|
|
11
|
+
*
|
|
12
|
+
* No writes, no model calls, no migrations. Every read is bounded.
|
|
13
|
+
*/
|
|
14
|
+
import { type AdaptiveJournalConfigIdentity, type AdaptiveJournalError, type AdaptiveJournalReport } from './adaptive-journal-reconciliation.js';
|
|
15
|
+
export declare const ADAPTIVE_BEHAVIOR_LINKAGE_SCHEMA_VERSION: 'pd-aa-behavior-linkage/v1';
|
|
16
|
+
export declare const BEHAVIOR_LINKAGE_MAX_EVENT_LOG_LINES = 20000;
|
|
17
|
+
export declare const BEHAVIOR_LINKAGE_MAX_TOOL_CALLS = 5000;
|
|
18
|
+
export declare const BEHAVIOR_LINKAGE_MAX_TRAJECTORY_ROWS = 5000;
|
|
19
|
+
export declare const BEHAVIOR_LINKAGE_MAX_ACTIONS_PER_INVOCATION = 200;
|
|
20
|
+
export declare const BEHAVIOR_LINKAGE_MAX_CORRECTIONS_PER_INVOCATION = 50;
|
|
21
|
+
export declare const BEHAVIOR_LINKAGE_MAX_OUTCOMES_PER_INVOCATION = 20;
|
|
22
|
+
export declare const BEHAVIOR_LINKAGE_MAX_WEAK_CANDIDATES_PER_INVOCATION = 20;
|
|
23
|
+
export declare const BEHAVIOR_LINKAGE_MAX_SESSION_QUERIES = 100;
|
|
24
|
+
export declare const BEHAVIOR_LINKAGE_ROWS_PER_SESSION = 200;
|
|
25
|
+
export interface LinkAdaptiveBehaviorEvidenceLimits {
|
|
26
|
+
maxDateFilesPerDir?: number;
|
|
27
|
+
maxFileBytes?: number;
|
|
28
|
+
maxInvocations?: number;
|
|
29
|
+
maxTerminalVariantsPerInvocation?: number;
|
|
30
|
+
maxEventLogLines?: number;
|
|
31
|
+
maxToolCalls?: number;
|
|
32
|
+
maxTrajectoryRows?: number;
|
|
33
|
+
maxActionsPerInvocation?: number;
|
|
34
|
+
maxCorrectionsPerInvocation?: number;
|
|
35
|
+
maxOutcomesPerInvocation?: number;
|
|
36
|
+
maxWeakCandidatesPerInvocation?: number;
|
|
37
|
+
maxSessionQueries?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface LinkAdaptiveBehaviorEvidenceInput {
|
|
40
|
+
workspaceDir: string;
|
|
41
|
+
since?: string;
|
|
42
|
+
until?: string;
|
|
43
|
+
host?: string;
|
|
44
|
+
now?: Date;
|
|
45
|
+
limits?: LinkAdaptiveBehaviorEvidenceLimits;
|
|
46
|
+
}
|
|
47
|
+
export type BehaviorAssociation = 'strong_run' | 'weak' | 'ambiguous' | 'unknown' | 'conflict';
|
|
48
|
+
export type BehaviorAssociationReason = 'run_identity_proven' | 'run_identity_missing' | 'workspace_identity_unknown' | 'journal_range_incomplete' | 'run_has_multiple_invocations' | 'duplicate_records' | 'target_identity_unproven' | 'terminal_conflicted' | 'config_changed' | 'open_not_visible_in_range' | 'terminal_not_visible_in_range' | 'action_before_open';
|
|
49
|
+
export type BehaviorUnknownReason = 'delivery_time_unavailable' | 'task_success_not_observable' | 'model_completion_only' | 'artifact_effect_not_observable' | 'principle_ids_not_comparable' | 'journal_range_incomplete' | 'run_has_multiple_invocations' | 'duplicate_records' | 'terminal_not_visible_in_range' | 'open_not_visible_in_range' | 'config_changed' | 'trajectory_db_unavailable' | 'trajectory_schema_incomplete' | 'trajectory_query_failed' | 'event_log_unavailable' | 'event_log_parse_limit_reached' | 'event_log_files_omitted' | 'event_log_parse_errors' | 'event_log_read_error' | 'action_limit_reached' | 'correction_limit_reached' | 'outcome_limit_reached' | 'weak_candidate_limit_reached' | 'trajectory_row_limit_reached' | 'session_query_limit_reached' | 'session_rows_truncated';
|
|
50
|
+
export interface BehaviorLinkageActionFact {
|
|
51
|
+
source: 'event_log.tool_call';
|
|
52
|
+
toolName: string;
|
|
53
|
+
toolCallIdRef: string | null;
|
|
54
|
+
outcome: 'success' | 'failure' | 'unknown';
|
|
55
|
+
exitCode: number | null;
|
|
56
|
+
errorType: string | null;
|
|
57
|
+
errorPresent: boolean;
|
|
58
|
+
ts: string;
|
|
59
|
+
/** Owner correction 2: no delivery timestamp exists, so ordering is always unknown. */
|
|
60
|
+
ordering: 'unknown';
|
|
61
|
+
relativeToRecordedOpen: 'before_open' | 'after_open' | 'no_open_timestamp';
|
|
62
|
+
strength: 'run_strong' | 'run_ambiguous';
|
|
63
|
+
verified: boolean;
|
|
64
|
+
logRef: string;
|
|
65
|
+
}
|
|
66
|
+
export interface BehaviorLinkageCorrectionFact {
|
|
67
|
+
source: 'trajectory.user_turns';
|
|
68
|
+
userTurnId: number;
|
|
69
|
+
turnIndex: number;
|
|
70
|
+
referencedAssistantTurnId: number | null;
|
|
71
|
+
referencedRunId: string | null;
|
|
72
|
+
createdAt: string;
|
|
73
|
+
ordering: 'unknown';
|
|
74
|
+
strength: 'run_strong' | 'run_ambiguous' | 'weak';
|
|
75
|
+
verified: boolean;
|
|
76
|
+
}
|
|
77
|
+
export interface BehaviorLinkageOutcomeFact {
|
|
78
|
+
source: 'trajectory.task_outcomes';
|
|
79
|
+
outcomeId: number;
|
|
80
|
+
/** Raw recorded token; `completed` is a model-output record, never task success. */
|
|
81
|
+
recordedOutcome: string | null;
|
|
82
|
+
modelCompletionRecorded: boolean;
|
|
83
|
+
semantics: 'model_completion_only';
|
|
84
|
+
taskSuccess: 'unknown';
|
|
85
|
+
principleBinding: 'session_level_unknown' | 'absent';
|
|
86
|
+
principleIdCount: number;
|
|
87
|
+
createdAt: string;
|
|
88
|
+
strength: 'run_strong' | 'run_ambiguous';
|
|
89
|
+
verified: boolean;
|
|
90
|
+
}
|
|
91
|
+
export interface BehaviorLinkageArtifacts {
|
|
92
|
+
declaredTargetCount: number;
|
|
93
|
+
declaredByToolNames: string[];
|
|
94
|
+
confirmedCount: 0;
|
|
95
|
+
confirmation: 'unknown';
|
|
96
|
+
}
|
|
97
|
+
export interface BehaviorLinkageWeakCandidate {
|
|
98
|
+
source: 'trajectory.tool_calls';
|
|
99
|
+
rowId: number;
|
|
100
|
+
toolName: string;
|
|
101
|
+
outcome: string | null;
|
|
102
|
+
createdAt: string;
|
|
103
|
+
reason: 'session_tool_time_only';
|
|
104
|
+
verified: false;
|
|
105
|
+
}
|
|
106
|
+
export interface BehaviorLinkageInvocation {
|
|
107
|
+
intervention: {
|
|
108
|
+
hookInvocationId: string;
|
|
109
|
+
runId: string | null;
|
|
110
|
+
sessionId: string | null;
|
|
111
|
+
host: string;
|
|
112
|
+
workspaceVerified: boolean;
|
|
113
|
+
artifactId: string | null;
|
|
114
|
+
activationId: string | null;
|
|
115
|
+
targetBodySha256: string | null;
|
|
116
|
+
configIdentity: AdaptiveJournalConfigIdentity | null;
|
|
117
|
+
terminal: {
|
|
118
|
+
receiptState: 'open' | 'closed' | 'reconciled' | null;
|
|
119
|
+
variants: number;
|
|
120
|
+
classification: string;
|
|
121
|
+
};
|
|
122
|
+
openTs: string | null;
|
|
123
|
+
terminalTs: string | null;
|
|
124
|
+
};
|
|
125
|
+
association: BehaviorAssociation;
|
|
126
|
+
associationReasons: BehaviorAssociationReason[];
|
|
127
|
+
/**
|
|
128
|
+
* Explicit four-layer claim boundary. Only `runAssociation` is ever derived
|
|
129
|
+
* from recorded facts; request-level attribution, principle adherence and
|
|
130
|
+
* causal improvement are not observable with the current evidence.
|
|
131
|
+
*/
|
|
132
|
+
evidenceLayers: {
|
|
133
|
+
runAssociation: BehaviorAssociation;
|
|
134
|
+
requestAssociation: 'unknown';
|
|
135
|
+
principleAdherence: 'unknown';
|
|
136
|
+
behaviorImprovement: 'unknown';
|
|
137
|
+
};
|
|
138
|
+
facts: {
|
|
139
|
+
actions: BehaviorLinkageActionFact[];
|
|
140
|
+
corrections: BehaviorLinkageCorrectionFact[];
|
|
141
|
+
outcomes: BehaviorLinkageOutcomeFact[];
|
|
142
|
+
artifacts: BehaviorLinkageArtifacts;
|
|
143
|
+
};
|
|
144
|
+
weakCandidates: BehaviorLinkageWeakCandidate[];
|
|
145
|
+
unknowns: {
|
|
146
|
+
fact: string;
|
|
147
|
+
reasonCode: BehaviorUnknownReason;
|
|
148
|
+
}[];
|
|
149
|
+
conflicts: {
|
|
150
|
+
kind: 'journal' | 'config_identity';
|
|
151
|
+
reasonCodes: string[];
|
|
152
|
+
duplicateCount?: number;
|
|
153
|
+
}[];
|
|
154
|
+
}
|
|
155
|
+
export interface BehaviorLinkageReport {
|
|
156
|
+
schemaVersion: typeof ADAPTIVE_BEHAVIOR_LINKAGE_SCHEMA_VERSION;
|
|
157
|
+
generatedAt: string;
|
|
158
|
+
readOnly: true;
|
|
159
|
+
request: {
|
|
160
|
+
workspaceDir: string;
|
|
161
|
+
host: string;
|
|
162
|
+
window: AdaptiveJournalReport['request']['window'];
|
|
163
|
+
};
|
|
164
|
+
coverage: {
|
|
165
|
+
complete: boolean;
|
|
166
|
+
window: AdaptiveJournalReport['request']['window'];
|
|
167
|
+
journal: {
|
|
168
|
+
status: AdaptiveJournalReport['coverage']['status'];
|
|
169
|
+
complete: boolean;
|
|
170
|
+
filesRead: number;
|
|
171
|
+
filesSkipped: number;
|
|
172
|
+
limitCode: AdaptiveJournalReport['coverage']['limitCode'];
|
|
173
|
+
truncatedFiles: number;
|
|
174
|
+
errors: number;
|
|
175
|
+
malformedLines: number;
|
|
176
|
+
invalidRecords: number;
|
|
177
|
+
};
|
|
178
|
+
eventLog: {
|
|
179
|
+
dirsFound: number;
|
|
180
|
+
filesRead: number;
|
|
181
|
+
linesRead: number;
|
|
182
|
+
toolCalls: number;
|
|
183
|
+
truncated: boolean;
|
|
184
|
+
omittedFiles: number;
|
|
185
|
+
parseErrors: number;
|
|
186
|
+
errors: number;
|
|
187
|
+
unattributedToolCalls: number;
|
|
188
|
+
};
|
|
189
|
+
trajectory: {
|
|
190
|
+
status: 'read' | 'unavailable';
|
|
191
|
+
rowsRead: number;
|
|
192
|
+
truncated: boolean;
|
|
193
|
+
reasons: string[];
|
|
194
|
+
};
|
|
195
|
+
incompleteReasons: BehaviorUnknownReason[];
|
|
196
|
+
};
|
|
197
|
+
totals: {
|
|
198
|
+
invocations: number;
|
|
199
|
+
byAssociation: Record<BehaviorAssociation, number>;
|
|
200
|
+
actions: number;
|
|
201
|
+
corrections: number;
|
|
202
|
+
outcomes: number;
|
|
203
|
+
weakCandidates: number;
|
|
204
|
+
};
|
|
205
|
+
invocations: BehaviorLinkageInvocation[];
|
|
206
|
+
nextAction: string[];
|
|
207
|
+
}
|
|
208
|
+
export interface BehaviorLinkageError {
|
|
209
|
+
code: AdaptiveJournalError['code'] | 'invalid_limit' | 'workspace_unavailable';
|
|
210
|
+
message: string;
|
|
211
|
+
nextAction: string;
|
|
212
|
+
}
|
|
213
|
+
export type BehaviorLinkageResult = {
|
|
214
|
+
ok: true;
|
|
215
|
+
report: BehaviorLinkageReport;
|
|
216
|
+
} | {
|
|
217
|
+
ok: false;
|
|
218
|
+
schemaVersion: typeof ADAPTIVE_BEHAVIOR_LINKAGE_SCHEMA_VERSION;
|
|
219
|
+
generatedAt: string;
|
|
220
|
+
readOnly: true;
|
|
221
|
+
error: BehaviorLinkageError;
|
|
222
|
+
};
|
|
223
|
+
export declare function linkAdaptiveBehaviorEvidence(input: LinkAdaptiveBehaviorEvidenceInput): BehaviorLinkageResult;
|