@principles/host-runtime 4.10.0 → 4.12.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/auto-pain-authorization.js +6 -1
- package/dist/conversation-ingestion/consent.d.ts +33 -7
- package/dist/conversation-ingestion/consent.js +240 -42
- package/dist/conversation-ingestion/disclosure.d.ts +21 -0
- package/dist/conversation-ingestion/disclosure.js +74 -0
- package/dist/conversation-ingestion/index.d.ts +1 -0
- package/dist/conversation-ingestion/index.js +1 -0
- package/dist/forward-observation.d.ts +29 -0
- package/dist/forward-observation.js +279 -0
- package/dist/governance-signal-admission.d.ts +6 -1
- package/dist/governance-signal-admission.js +77 -11
- package/dist/idle-turn-audit.d.ts +155 -0
- package/dist/idle-turn-audit.js +786 -0
- package/dist/idle-turn-auditor.d.ts +20 -0
- package/dist/idle-turn-auditor.js +249 -0
- package/dist/index.d.ts +11 -5
- package/dist/index.js +38 -8
- package/dist/pain-inbox.d.ts +137 -0
- package/dist/pain-inbox.js +1020 -0
- package/dist/production-pain-evidence.d.ts +2 -2
- package/dist/production-pain-evidence.js +301 -55
- package/dist/signal-stage2-cycle.d.ts +2 -0
- package/dist/signal-stage2-cycle.js +30 -1
- package/dist/source-revocation-sweep.js +38 -0
- package/dist/stage2-context-hydrator.d.ts +46 -0
- package/dist/stage2-context-hydrator.js +221 -0
- package/dist/trajectory-stall-detector.d.ts +124 -0
- package/dist/trajectory-stall-detector.js +583 -0
- package/package.json +3 -3
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stage-2 Conversation Context Hydrator — SPEC-PD-PAIN-DETECTION-UPGRADE-001 R1-2.
|
|
3
|
+
*
|
|
4
|
+
* Hydrates bounded, host-owned `Stage2ConversationContext` for Codex and
|
|
5
|
+
* WorkBuddy pending correction candidates before Stage-2 LLM classification
|
|
6
|
+
* and Gate 3 confidence gating.
|
|
7
|
+
*
|
|
8
|
+
* Architectural invariants (TD-PD-PAIN-DETECTION-UPGRADE-001 §2.2):
|
|
9
|
+
* - Consent fail-closed: checks `readSourceMaterialAuthorization` before
|
|
10
|
+
* reading any observation row. Unauthorized hosts receive
|
|
11
|
+
* `priorAssistantTurnCount: null` (unknown), never fabricated `0`.
|
|
12
|
+
* - Anchor resolution by `(host_kind, rollout_identity, logical_key)` on
|
|
13
|
+
* `governance_observations` — never GSA `created_at`.
|
|
14
|
+
* - Ordering strictly uses `source_order` (byte offset within the rollout).
|
|
15
|
+
* If `source_order` is missing on the anchor or mixed (some rows NULL, some
|
|
16
|
+
* non-NULL) within the same rollout, returns `priorAssistantTurnCount: null`
|
|
17
|
+
* honestly rather than fabricating `0` or guessing insertion order.
|
|
18
|
+
* - Filters strictly to `kind IN ('assistant_turn', 'tool_call')` and
|
|
19
|
+
* `retention_class IN ('operational', 'promoted')` within the same
|
|
20
|
+
* `rollout_row_id`.
|
|
21
|
+
*/
|
|
22
|
+
import type { Stage2ConversationContext } from '@principles/core/runtime';
|
|
23
|
+
import type { ObservationDatabaseFactory } from './governance-observation-store.js';
|
|
24
|
+
export interface Stage2HydrationCandidate {
|
|
25
|
+
readonly logicalObservationKey: string;
|
|
26
|
+
readonly hostKind: 'codex' | 'workbuddy';
|
|
27
|
+
readonly rolloutIdentity: string;
|
|
28
|
+
readonly rootSessionId: string;
|
|
29
|
+
readonly hostTurnId: string;
|
|
30
|
+
}
|
|
31
|
+
export interface HydrateStage2ContextInput {
|
|
32
|
+
readonly workspaceDir: string;
|
|
33
|
+
readonly candidate: Stage2HydrationCandidate;
|
|
34
|
+
readonly maxRecentAssistantTurns?: number;
|
|
35
|
+
readonly maxSummaryChars?: number;
|
|
36
|
+
readonly now?: Date;
|
|
37
|
+
readonly databaseFactory?: ObservationDatabaseFactory;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Hydrate bounded conversation facts (`Stage2ConversationContext`) from
|
|
41
|
+
* `governance_observations` for a Codex or WorkBuddy pending correction
|
|
42
|
+
* candidate. Never throws; degrades honestly to `priorAssistantTurnCount: null`
|
|
43
|
+
* when consent is missing/revoked, the trajectory DB or anchor row is absent,
|
|
44
|
+
* or `source_order` is missing/mixed.
|
|
45
|
+
*/
|
|
46
|
+
export declare function hydrateStage2ContextForCandidate(input: HydrateStage2ContextInput): Stage2ConversationContext;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stage-2 Conversation Context Hydrator — SPEC-PD-PAIN-DETECTION-UPGRADE-001 R1-2.
|
|
3
|
+
*
|
|
4
|
+
* Hydrates bounded, host-owned `Stage2ConversationContext` for Codex and
|
|
5
|
+
* WorkBuddy pending correction candidates before Stage-2 LLM classification
|
|
6
|
+
* and Gate 3 confidence gating.
|
|
7
|
+
*
|
|
8
|
+
* Architectural invariants (TD-PD-PAIN-DETECTION-UPGRADE-001 §2.2):
|
|
9
|
+
* - Consent fail-closed: checks `readSourceMaterialAuthorization` before
|
|
10
|
+
* reading any observation row. Unauthorized hosts receive
|
|
11
|
+
* `priorAssistantTurnCount: null` (unknown), never fabricated `0`.
|
|
12
|
+
* - Anchor resolution by `(host_kind, rollout_identity, logical_key)` on
|
|
13
|
+
* `governance_observations` — never GSA `created_at`.
|
|
14
|
+
* - Ordering strictly uses `source_order` (byte offset within the rollout).
|
|
15
|
+
* If `source_order` is missing on the anchor or mixed (some rows NULL, some
|
|
16
|
+
* non-NULL) within the same rollout, returns `priorAssistantTurnCount: null`
|
|
17
|
+
* honestly rather than fabricating `0` or guessing insertion order.
|
|
18
|
+
* - Filters strictly to `kind IN ('assistant_turn', 'tool_call')` and
|
|
19
|
+
* `retention_class IN ('operational', 'promoted')` within the same
|
|
20
|
+
* `rollout_row_id`.
|
|
21
|
+
*/
|
|
22
|
+
import fs from 'node:fs';
|
|
23
|
+
import Database from 'better-sqlite3';
|
|
24
|
+
import { resolveTrajectoryDbPath } from '@principles/core/runtime/storage-paths';
|
|
25
|
+
import { readSourceMaterialAuthorization } from './source-material-authorization.js';
|
|
26
|
+
const DEFAULT_MAX_RECENT_ASSISTANT_TURNS = 4;
|
|
27
|
+
const DEFAULT_MAX_SUMMARY_CHARS = 240;
|
|
28
|
+
function isRecord(value) {
|
|
29
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
30
|
+
}
|
|
31
|
+
function isAnchorRow(value) {
|
|
32
|
+
if (!isRecord(value))
|
|
33
|
+
return false;
|
|
34
|
+
return (typeof value.id === 'number' &&
|
|
35
|
+
typeof value.rollout_row_id === 'number' &&
|
|
36
|
+
(value.source_order === null || typeof value.source_order === 'number') &&
|
|
37
|
+
typeof value.observed_at === 'string');
|
|
38
|
+
}
|
|
39
|
+
function isPriorObservationRow(value) {
|
|
40
|
+
if (!isRecord(value))
|
|
41
|
+
return false;
|
|
42
|
+
return (typeof value.id === 'number' &&
|
|
43
|
+
typeof value.kind === 'string' &&
|
|
44
|
+
(value.visible_text === null || typeof value.visible_text === 'string') &&
|
|
45
|
+
(value.sanitized_tool_facts_json === null || typeof value.sanitized_tool_facts_json === 'string') &&
|
|
46
|
+
(value.source_order === null || typeof value.source_order === 'number'));
|
|
47
|
+
}
|
|
48
|
+
function unknownContext(snapshotCapturedAt) {
|
|
49
|
+
return {
|
|
50
|
+
priorAssistantTurnCount: null,
|
|
51
|
+
recentAssistantTurns: [],
|
|
52
|
+
snapshotCapturedAt,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function truncateText(text, maxChars) {
|
|
56
|
+
const collapsed = text.replace(/\s+/g, ' ').trim();
|
|
57
|
+
if (collapsed.length <= maxChars)
|
|
58
|
+
return collapsed;
|
|
59
|
+
return `${collapsed.slice(0, Math.max(1, maxChars - 1))}…`;
|
|
60
|
+
}
|
|
61
|
+
function formatToolFactsSummary(rawJson, maxChars) {
|
|
62
|
+
if (!rawJson)
|
|
63
|
+
return '[tool_call]';
|
|
64
|
+
try {
|
|
65
|
+
const parsed = JSON.parse(rawJson);
|
|
66
|
+
if (isRecord(parsed)) {
|
|
67
|
+
const obj = isRecord(parsed.facts) ? parsed.facts : parsed;
|
|
68
|
+
const toolName = typeof obj.toolName === 'string'
|
|
69
|
+
? obj.toolName
|
|
70
|
+
: typeof obj.tool === 'string'
|
|
71
|
+
? obj.tool
|
|
72
|
+
: typeof obj.name === 'string'
|
|
73
|
+
? obj.name
|
|
74
|
+
: 'tool';
|
|
75
|
+
const outcome = typeof obj.outcome === 'string'
|
|
76
|
+
? obj.outcome
|
|
77
|
+
: typeof obj.status === 'string'
|
|
78
|
+
? obj.status
|
|
79
|
+
: undefined;
|
|
80
|
+
const detail = typeof obj.error === 'string'
|
|
81
|
+
? obj.error
|
|
82
|
+
: typeof obj.summary === 'string'
|
|
83
|
+
? obj.summary
|
|
84
|
+
: undefined;
|
|
85
|
+
const parts = [`[tool:${toolName}]`];
|
|
86
|
+
if (outcome)
|
|
87
|
+
parts.push(`outcome=${outcome}`);
|
|
88
|
+
if (detail)
|
|
89
|
+
parts.push(detail);
|
|
90
|
+
return truncateText(parts.join(' '), maxChars);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// Fall back to bounded raw string preview if JSON is malformed.
|
|
95
|
+
}
|
|
96
|
+
return truncateText(`[tool_call] ${rawJson}`, maxChars);
|
|
97
|
+
}
|
|
98
|
+
function summarizeObservationRow(row, maxChars) {
|
|
99
|
+
if (row.kind === 'assistant_turn') {
|
|
100
|
+
const text = row.visible_text?.trim();
|
|
101
|
+
if (!text)
|
|
102
|
+
return null;
|
|
103
|
+
return { summary: truncateText(text, maxChars), referenced: false };
|
|
104
|
+
}
|
|
105
|
+
if (row.kind === 'tool_call') {
|
|
106
|
+
const summary = row.visible_text?.trim()
|
|
107
|
+
? truncateText(`[tool_call] ${row.visible_text}`, maxChars)
|
|
108
|
+
: formatToolFactsSummary(row.sanitized_tool_facts_json, maxChars);
|
|
109
|
+
return { summary, referenced: false };
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Hydrate bounded conversation facts (`Stage2ConversationContext`) from
|
|
115
|
+
* `governance_observations` for a Codex or WorkBuddy pending correction
|
|
116
|
+
* candidate. Never throws; degrades honestly to `priorAssistantTurnCount: null`
|
|
117
|
+
* when consent is missing/revoked, the trajectory DB or anchor row is absent,
|
|
118
|
+
* or `source_order` is missing/mixed.
|
|
119
|
+
*/
|
|
120
|
+
export function hydrateStage2ContextForCandidate(input) {
|
|
121
|
+
const snapshotCapturedAt = (input.now ?? new Date()).toISOString();
|
|
122
|
+
const maxRecent = Math.max(1, input.maxRecentAssistantTurns ?? DEFAULT_MAX_RECENT_ASSISTANT_TURNS);
|
|
123
|
+
const maxChars = Math.max(32, input.maxSummaryChars ?? DEFAULT_MAX_SUMMARY_CHARS);
|
|
124
|
+
// Fail-closed consent gate: never read observations from an unauthorized host.
|
|
125
|
+
const authz = readSourceMaterialAuthorization({
|
|
126
|
+
workspaceDir: input.workspaceDir,
|
|
127
|
+
hostKind: input.candidate.hostKind,
|
|
128
|
+
});
|
|
129
|
+
if (authz.status !== 'authorized') {
|
|
130
|
+
return unknownContext(snapshotCapturedAt);
|
|
131
|
+
}
|
|
132
|
+
const dbPath = resolveTrajectoryDbPath(input.workspaceDir);
|
|
133
|
+
if (!input.databaseFactory && !fs.existsSync(dbPath)) {
|
|
134
|
+
return unknownContext(snapshotCapturedAt);
|
|
135
|
+
}
|
|
136
|
+
let db = null;
|
|
137
|
+
try {
|
|
138
|
+
db = input.databaseFactory
|
|
139
|
+
? input.databaseFactory(dbPath)
|
|
140
|
+
: new Database(dbPath, { readonly: true, fileMustExist: true });
|
|
141
|
+
const tableExists = db
|
|
142
|
+
.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'governance_observations' LIMIT 1")
|
|
143
|
+
.get();
|
|
144
|
+
if (!tableExists) {
|
|
145
|
+
return unknownContext(snapshotCapturedAt);
|
|
146
|
+
}
|
|
147
|
+
const rawAnchor = db
|
|
148
|
+
.prepare(`SELECT id, rollout_row_id, source_order, observed_at
|
|
149
|
+
FROM governance_observations
|
|
150
|
+
WHERE host_kind = ? AND rollout_identity = ? AND logical_key = ?
|
|
151
|
+
LIMIT 1`)
|
|
152
|
+
.get(input.candidate.hostKind, input.candidate.rolloutIdentity, input.candidate.logicalObservationKey);
|
|
153
|
+
if (!isAnchorRow(rawAnchor)) {
|
|
154
|
+
return unknownContext(snapshotCapturedAt);
|
|
155
|
+
}
|
|
156
|
+
// Ordering safety: if the anchor lacks `source_order` (e.g., live-hook row
|
|
157
|
+
// before transcript convergence), we cannot prove whether earlier backfilled
|
|
158
|
+
// rows preceded it without risking a fabricated 0. Degrade honestly to null.
|
|
159
|
+
if (rawAnchor.source_order === null) {
|
|
160
|
+
return unknownContext(snapshotCapturedAt);
|
|
161
|
+
}
|
|
162
|
+
// Check for mixed ordering within the same rollout: if any active
|
|
163
|
+
// assistant_turn/tool_call row lacks `source_order`, total order is
|
|
164
|
+
// unprovable — degrade honestly to null rather than fabricating 0.
|
|
165
|
+
const rawUnordered = db
|
|
166
|
+
.prepare(`SELECT COUNT(*) AS n
|
|
167
|
+
FROM governance_observations
|
|
168
|
+
WHERE rollout_row_id = ?
|
|
169
|
+
AND kind IN ('assistant_turn', 'tool_call')
|
|
170
|
+
AND retention_class IN ('operational', 'promoted')
|
|
171
|
+
AND source_order IS NULL`)
|
|
172
|
+
.get(rawAnchor.rollout_row_id);
|
|
173
|
+
const unorderedCount = isRecord(rawUnordered) && typeof rawUnordered.n === 'number' ? rawUnordered.n : 0;
|
|
174
|
+
if (unorderedCount > 0) {
|
|
175
|
+
return unknownContext(snapshotCapturedAt);
|
|
176
|
+
}
|
|
177
|
+
const rawPriorRows = db
|
|
178
|
+
.prepare(`SELECT id, kind, visible_text, sanitized_tool_facts_json, source_order
|
|
179
|
+
FROM governance_observations
|
|
180
|
+
WHERE rollout_row_id = ?
|
|
181
|
+
AND kind IN ('assistant_turn', 'tool_call')
|
|
182
|
+
AND retention_class IN ('operational', 'promoted')
|
|
183
|
+
AND (source_order < ? OR (source_order = ? AND id < ?))
|
|
184
|
+
ORDER BY source_order ASC, id ASC`)
|
|
185
|
+
.all(rawAnchor.rollout_row_id, rawAnchor.source_order, rawAnchor.source_order, rawAnchor.id);
|
|
186
|
+
const priorRows = Array.isArray(rawPriorRows)
|
|
187
|
+
? rawPriorRows.filter(isPriorObservationRow)
|
|
188
|
+
: [];
|
|
189
|
+
let priorAssistantTurnCount = 0;
|
|
190
|
+
const summaries = [];
|
|
191
|
+
for (const row of priorRows) {
|
|
192
|
+
if (row.kind === 'assistant_turn') {
|
|
193
|
+
priorAssistantTurnCount += 1;
|
|
194
|
+
}
|
|
195
|
+
const summary = summarizeObservationRow(row, maxChars);
|
|
196
|
+
if (summary !== null) {
|
|
197
|
+
summaries.push(summary);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// Keep the most recent bounded window in chronological (old -> new) order.
|
|
201
|
+
const recentAssistantTurns = summaries.length > maxRecent ? summaries.slice(summaries.length - maxRecent) : summaries;
|
|
202
|
+
return {
|
|
203
|
+
priorAssistantTurnCount,
|
|
204
|
+
recentAssistantTurns,
|
|
205
|
+
snapshotCapturedAt,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
return unknownContext(snapshotCapturedAt);
|
|
210
|
+
}
|
|
211
|
+
finally {
|
|
212
|
+
if (db !== null) {
|
|
213
|
+
try {
|
|
214
|
+
db.close();
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
// Ignore close errors on readonly handle.
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trajectory Stall Detector — SPEC-PD-PAIN-DETECTION-UPGRADE-001 R4 (W5).
|
|
3
|
+
*
|
|
4
|
+
* Detects repeated tool-failure loops ("spinning in place") and routes them
|
|
5
|
+
* strictly to the Owner-confirmable Pain Inbox (`governance_signal_admissions`
|
|
6
|
+
* with `signal_kind = 'trajectory_stall'`, `decision = 'inbox_candidate'`).
|
|
7
|
+
* Never writes directly to `pain_events`.
|
|
8
|
+
*
|
|
9
|
+
* Architectural invariants (TD-PD-PAIN-DETECTION-UPGRADE-001 §2.5 / W5):
|
|
10
|
+
* 1. Cross-table deterministic ordering for Codex & WorkBuddy:
|
|
11
|
+
* `tool_calls` is joined to `governance_observations` via
|
|
12
|
+
* `(host_kind, root_session_id = session_id, tool_use_id)` with
|
|
13
|
+
* `kind = 'tool_call'` and `retention_class IN ('operational', 'promoted')`.
|
|
14
|
+
* If ANY tool call in the candidate window matches 0 or >1 observation rows,
|
|
15
|
+
* lacks `tool_use_id`, or has `source_order IS NULL`, returns
|
|
16
|
+
* `status: 'unknown_incomplete'` and skips — NEVER falls back to
|
|
17
|
+
* `tool_calls.created_at`.
|
|
18
|
+
* OpenClaw real-time in-process detection may use `orderMode: 'openclaw_realtime'`
|
|
19
|
+
* which orders directly by monotonic `tc.id DESC` (+ `tc.turn_id`).
|
|
20
|
+
* 2. Structured infrastructure failure classification & null-error degradation:
|
|
21
|
+
* `classifyToolFailureOrigin()` distinguishes `'infrastructure'`,
|
|
22
|
+
* `'actionable_failure'`, and `'unknown'`. Backfilled rows whose
|
|
23
|
+
* `error_type` and `error_message` are both NULL and whose structured
|
|
24
|
+
* facts / preview do not prove a non-infrastructure failure degrade to
|
|
25
|
+
* `'unknown'` and break the streak.
|
|
26
|
+
* 3. Isolation & target path requirement:
|
|
27
|
+
* Strictly isolated by `(host_kind, session_id)`. Both `'success'` and
|
|
28
|
+
* `'unknown'` outcomes, `'infrastructure'` / `'unknown'` failure origins,
|
|
29
|
+
* and missing `normalizedTargetPath` break the consecutive streak.
|
|
30
|
+
* Requires `>= 3` consecutive actionable failures with the same
|
|
31
|
+
* `(toolName, normalizedTargetPath)` fingerprint.
|
|
32
|
+
*/
|
|
33
|
+
import type { ObservationDatabaseFactory } from './governance-observation-store.js';
|
|
34
|
+
export declare const DEFAULT_STALL_WINDOW_SIZE = 8;
|
|
35
|
+
export declare const DEFAULT_STALL_MIN_CONSECUTIVE = 3;
|
|
36
|
+
export declare const MAX_STALL_INBOX_PER_SESSION = 2;
|
|
37
|
+
export type StallHostKind = 'codex' | 'workbuddy' | 'openclaw';
|
|
38
|
+
export type ToolFailureOrigin = 'infrastructure' | 'actionable_failure' | 'unknown';
|
|
39
|
+
export interface ClassifyToolFailureOriginInput {
|
|
40
|
+
readonly outcome?: string | null;
|
|
41
|
+
readonly errorType?: string | null;
|
|
42
|
+
readonly errorMessage?: string | null;
|
|
43
|
+
readonly resultPreview?: string | null;
|
|
44
|
+
readonly sanitizedToolFactsJson?: string | null;
|
|
45
|
+
}
|
|
46
|
+
export interface DetectTrajectoryStallInput {
|
|
47
|
+
readonly workspaceDir: string;
|
|
48
|
+
readonly hostKind: StallHostKind;
|
|
49
|
+
readonly sessionId: string;
|
|
50
|
+
/**
|
|
51
|
+
* 'cross_table' (default for Codex/WorkBuddy): requires unique join to
|
|
52
|
+
* `governance_observations` with non-null `source_order`.
|
|
53
|
+
* 'openclaw_realtime': uses monotonic `tool_calls.id DESC` for OpenClaw.
|
|
54
|
+
*/
|
|
55
|
+
readonly orderMode?: 'cross_table' | 'openclaw_realtime';
|
|
56
|
+
readonly minConsecutive?: number;
|
|
57
|
+
readonly windowSize?: number;
|
|
58
|
+
readonly now?: Date;
|
|
59
|
+
readonly databaseFactory?: ObservationDatabaseFactory;
|
|
60
|
+
}
|
|
61
|
+
export type DetectTrajectoryStallResult = {
|
|
62
|
+
readonly status: 'stall_detected';
|
|
63
|
+
readonly hostKind: StallHostKind;
|
|
64
|
+
readonly sessionId: string;
|
|
65
|
+
readonly fingerprint: string;
|
|
66
|
+
readonly toolName: string;
|
|
67
|
+
readonly targetPath: string;
|
|
68
|
+
readonly consecutiveFailures: number;
|
|
69
|
+
readonly toolCallIds: readonly number[];
|
|
70
|
+
readonly latestToolCallId: number;
|
|
71
|
+
readonly rolloutIdentity: string;
|
|
72
|
+
} | {
|
|
73
|
+
readonly status: 'no_stall';
|
|
74
|
+
readonly reason: string;
|
|
75
|
+
} | {
|
|
76
|
+
readonly status: 'unknown_incomplete';
|
|
77
|
+
readonly reason: string;
|
|
78
|
+
};
|
|
79
|
+
export interface AdmitTrajectoryStallResult {
|
|
80
|
+
readonly ok: boolean;
|
|
81
|
+
readonly disposition: 'inbox_candidate' | 'already_exists' | 'session_cap_reached' | 'no_stall' | 'unknown_incomplete' | 'unauthorized' | 'db_unavailable';
|
|
82
|
+
readonly logicalObservationKey?: string;
|
|
83
|
+
readonly reason?: string;
|
|
84
|
+
}
|
|
85
|
+
export interface ScanWorkspaceStallsInput {
|
|
86
|
+
readonly workspaceDir: string;
|
|
87
|
+
readonly maxSessionsPerHost?: number;
|
|
88
|
+
readonly now?: Date;
|
|
89
|
+
readonly databaseFactory?: ObservationDatabaseFactory;
|
|
90
|
+
}
|
|
91
|
+
export interface ScanWorkspaceStallsReport {
|
|
92
|
+
readonly scannedSessions: number;
|
|
93
|
+
readonly admittedInboxCandidates: number;
|
|
94
|
+
readonly skippedUnknownIncomplete: number;
|
|
95
|
+
readonly skippedUnauthorized: number;
|
|
96
|
+
readonly scanError?: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Pure failure origin classifier (TD §2.5 / W5).
|
|
100
|
+
*
|
|
101
|
+
* - Infrastructure/network/provider/rate-limit/auth errors -> 'infrastructure'
|
|
102
|
+
* - Backfilled rows with NULL errorType & errorMessage and no concrete failure
|
|
103
|
+
* evidence in sanitizedToolFactsJson or resultPreview -> 'unknown'
|
|
104
|
+
* - Concrete non-infrastructure failure evidence -> 'actionable_failure'
|
|
105
|
+
*/
|
|
106
|
+
export declare function classifyToolFailureOrigin(input: ClassifyToolFailureOriginInput): ToolFailureOrigin;
|
|
107
|
+
export declare function extractNormalizedTargetPath(paramsJson: string): string | null;
|
|
108
|
+
/**
|
|
109
|
+
* Evaluate whether `(hostKind, sessionId)` is currently in a repeated-failure
|
|
110
|
+
* trajectory stall. Pure read; never mutates the DB.
|
|
111
|
+
*/
|
|
112
|
+
export declare function detectTrajectoryStallForSession(input: DetectTrajectoryStallInput): DetectTrajectoryStallResult;
|
|
113
|
+
/**
|
|
114
|
+
* Detect a trajectory stall for `(hostKind, sessionId)` and, if confirmed and
|
|
115
|
+
* authorized, write an Inbox-only candidate (`decision = 'inbox_candidate'`)
|
|
116
|
+
* into `governance_signal_admissions`.
|
|
117
|
+
*/
|
|
118
|
+
export declare function detectAndAdmitTrajectoryStall(input: DetectTrajectoryStallInput): AdmitTrajectoryStallResult;
|
|
119
|
+
/**
|
|
120
|
+
* Bounded workspace-wide scan intended to run inside the existing worker cycle
|
|
121
|
+
* (zero new background services). Scans recent `(host_kind, session_id)` pairs
|
|
122
|
+
* with failures in `tool_calls` and admits confirmed stalls into Pain Inbox.
|
|
123
|
+
*/
|
|
124
|
+
export declare function scanWorkspaceTrajectoryStalls(input: ScanWorkspaceStallsInput): ScanWorkspaceStallsReport;
|