@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,786 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Idle Turn Lightweight Audit — SPEC-PD-PAIN-DETECTION-UPGRADE-001 R5 (W6).
|
|
3
|
+
*
|
|
4
|
+
* Performs a bounded, budget-protected post-turn review of idle sessions
|
|
5
|
+
* (`>= 5` turns and idle `>= 5` minutes after true turn completion) and routes
|
|
6
|
+
* verified principle deviations strictly to Pain Inbox
|
|
7
|
+
* (`governance_signal_admissions`, `signal_kind = 'idle_audit_deviation'`,
|
|
8
|
+
* `decision = 'inbox_candidate'`). Never writes directly to `pain_events`.
|
|
9
|
+
*
|
|
10
|
+
* Architectural invariants (TD-PD-PAIN-DETECTION-UPGRADE-001 §2.6 / W6):
|
|
11
|
+
* 1. Accurate turn-end trigger (zero new background services):
|
|
12
|
+
* - Codex / WorkBuddy update `idle_audit_session_activity` on `Stop`.
|
|
13
|
+
* - OpenClaw registers native `agent_end` (never relying solely on
|
|
14
|
+
* `llm_output`). Legacy hosts without `agent_end` require `has_active_run = 0`.
|
|
15
|
+
* 2. Real prompt injection evidence + immutable artifact version + lifecycle:
|
|
16
|
+
* - Visibility is proved ONLY from `runtime_v2_prompt_activations_injected`
|
|
17
|
+
* events (`principleIds`, `activationIds`, `artifactIds`, `runId`,
|
|
18
|
+
* `hostKind`, `eventId`) — never from `environment_snapshots`.
|
|
19
|
+
* - `principleVersion` is resolved strictly from immutable `pi_artifacts`
|
|
20
|
+
* via `artifactIds`.
|
|
21
|
+
* - Because `activations` uses `INSERT OR REPLACE` and `PRI-932`
|
|
22
|
+
* (`activation_lifecycle_events`) is still DRAFT, if `activations` shows
|
|
23
|
+
* reactivation overwrite (`activated_at > observedAt`), missing lifecycle
|
|
24
|
+
* bounds, or missing immutable `principleVersion`, MUST return
|
|
25
|
+
* `verdict: 'INCONCLUSIVE'` — never infer historical state from current
|
|
26
|
+
* state and never fabricate a `deviationAnchor`.
|
|
27
|
+
* 3. Atomic daily budget persistence (`idle_audit_daily_budgets`):
|
|
28
|
+
* - Stored inside existing `trajectory.db`.
|
|
29
|
+
* - Reserved via `BEGIN IMMEDIATE` transaction BEFORE calling the LLM
|
|
30
|
+
* (default 10 calls / workspace / UTC day). Timeouts (`<= 25s`) keep the
|
|
31
|
+
* 1 consumed unit (never refunded or double-charged).
|
|
32
|
+
*/
|
|
33
|
+
import fs from 'node:fs';
|
|
34
|
+
import path from 'node:path';
|
|
35
|
+
import Database from 'better-sqlite3';
|
|
36
|
+
import { resolveTrajectoryDbPath } from '@principles/core/runtime/storage-paths';
|
|
37
|
+
import { readSourceMaterialAuthorization } from './source-material-authorization.js';
|
|
38
|
+
export const DEFAULT_IDLE_AUDIT_MIN_TURNS = 5;
|
|
39
|
+
export const DEFAULT_IDLE_AUDIT_IDLE_MS = 5 * 60 * 1000;
|
|
40
|
+
export const DEFAULT_IDLE_AUDIT_DAILY_LIMIT = 10;
|
|
41
|
+
export const DEFAULT_IDLE_AUDIT_TIMEOUT_MS = 25_000;
|
|
42
|
+
const IDLE_AUDIT_SCHEMA_STATEMENTS = [
|
|
43
|
+
`CREATE TABLE IF NOT EXISTS idle_audit_daily_budgets (
|
|
44
|
+
workspace_key TEXT NOT NULL,
|
|
45
|
+
utc_day TEXT NOT NULL,
|
|
46
|
+
used_count INTEGER NOT NULL DEFAULT 0,
|
|
47
|
+
updated_at TEXT NOT NULL,
|
|
48
|
+
PRIMARY KEY (workspace_key, utc_day)
|
|
49
|
+
)`,
|
|
50
|
+
`CREATE TABLE IF NOT EXISTS idle_audit_session_activity (
|
|
51
|
+
host_kind TEXT NOT NULL,
|
|
52
|
+
root_session_id TEXT NOT NULL,
|
|
53
|
+
last_turn_completed_at TEXT NOT NULL,
|
|
54
|
+
turn_end_source TEXT NOT NULL,
|
|
55
|
+
has_active_run INTEGER NOT NULL DEFAULT 0,
|
|
56
|
+
updated_at TEXT NOT NULL,
|
|
57
|
+
PRIMARY KEY (host_kind, root_session_id)
|
|
58
|
+
)`,
|
|
59
|
+
`CREATE TABLE IF NOT EXISTS idle_audit_outcomes (
|
|
60
|
+
idempotency_key TEXT PRIMARY KEY,
|
|
61
|
+
outcome TEXT NOT NULL,
|
|
62
|
+
audited_at TEXT NOT NULL
|
|
63
|
+
)`,
|
|
64
|
+
];
|
|
65
|
+
function isRecord(value) {
|
|
66
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
67
|
+
}
|
|
68
|
+
function nonEmptyString(value) {
|
|
69
|
+
if (typeof value !== 'string')
|
|
70
|
+
return null;
|
|
71
|
+
const trimmed = value.trim();
|
|
72
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
73
|
+
}
|
|
74
|
+
function tableExists(db, name) {
|
|
75
|
+
return (db
|
|
76
|
+
.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ? LIMIT 1")
|
|
77
|
+
.get(name) !== undefined);
|
|
78
|
+
}
|
|
79
|
+
export function ensureIdleAuditSchema(db) {
|
|
80
|
+
for (const stmt of IDLE_AUDIT_SCHEMA_STATEMENTS) {
|
|
81
|
+
db.exec(stmt);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function recordIdleAuditOutcome(args) {
|
|
85
|
+
ensureIdleAuditSchema(args.db);
|
|
86
|
+
args.db.prepare('INSERT OR IGNORE INTO idle_audit_outcomes (idempotency_key, outcome, audited_at) VALUES (?, ?, ?)').run(args.key, args.outcome, args.now.toISOString());
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Record an accurate turn-end timestamp (`agent_end` for OpenClaw, `stop_hook`
|
|
90
|
+
* for Codex/WorkBuddy) into `idle_audit_session_activity`.
|
|
91
|
+
*/
|
|
92
|
+
export function recordIdleAuditTurnCompleted(input) {
|
|
93
|
+
const dbPath = resolveTrajectoryDbPath(input.workspaceDir);
|
|
94
|
+
const nowIso = (input.completedAt ?? new Date()).toISOString();
|
|
95
|
+
let db = null;
|
|
96
|
+
try {
|
|
97
|
+
if (!input.databaseFactory) {
|
|
98
|
+
fs.mkdirSync(path.dirname(dbPath), { recursive: true });
|
|
99
|
+
}
|
|
100
|
+
db = input.databaseFactory ? input.databaseFactory(dbPath) : new Database(dbPath);
|
|
101
|
+
db.pragma('busy_timeout = 5000');
|
|
102
|
+
ensureIdleAuditSchema(db);
|
|
103
|
+
db.prepare(`INSERT INTO idle_audit_session_activity (
|
|
104
|
+
host_kind, root_session_id, last_turn_completed_at, turn_end_source, has_active_run, updated_at
|
|
105
|
+
) VALUES (?, ?, ?, ?, ?, ?)
|
|
106
|
+
ON CONFLICT(host_kind, root_session_id) DO UPDATE SET
|
|
107
|
+
last_turn_completed_at = excluded.last_turn_completed_at,
|
|
108
|
+
turn_end_source = excluded.turn_end_source,
|
|
109
|
+
has_active_run = excluded.has_active_run,
|
|
110
|
+
updated_at = excluded.updated_at`).run(input.hostKind, input.sessionId, nowIso, input.turnEndSource, input.hasActiveRun === true ? 1 : 0, nowIso);
|
|
111
|
+
return { ok: true };
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
return { ok: false, reason: err instanceof Error ? err.message : String(err) };
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
if (db !== null) {
|
|
118
|
+
try {
|
|
119
|
+
db.close();
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// ignore close errors
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Atomically reserve 1 daily LLM audit slot for `(workspace_key, utc_day)`
|
|
129
|
+
* using a SQLite `BEGIN IMMEDIATE` transaction (W6).
|
|
130
|
+
*/
|
|
131
|
+
export function reserveIdleAuditDailyBudget(input) {
|
|
132
|
+
const now = input.now ?? new Date();
|
|
133
|
+
const utcDay = now.toISOString().slice(0, 10);
|
|
134
|
+
const updatedAt = now.toISOString();
|
|
135
|
+
const workspaceKey = path.resolve(input.workspaceDir);
|
|
136
|
+
const dailyLimit = Math.max(1, input.dailyLimit ?? DEFAULT_IDLE_AUDIT_DAILY_LIMIT);
|
|
137
|
+
const dbPath = resolveTrajectoryDbPath(input.workspaceDir);
|
|
138
|
+
let db = null;
|
|
139
|
+
try {
|
|
140
|
+
if (!input.databaseFactory) {
|
|
141
|
+
fs.mkdirSync(path.dirname(dbPath), { recursive: true });
|
|
142
|
+
}
|
|
143
|
+
const conn = input.databaseFactory ? input.databaseFactory(dbPath) : new Database(dbPath);
|
|
144
|
+
db = conn;
|
|
145
|
+
conn.pragma('busy_timeout = 5000');
|
|
146
|
+
ensureIdleAuditSchema(conn);
|
|
147
|
+
const tx = conn.transaction(() => {
|
|
148
|
+
const row = conn
|
|
149
|
+
.prepare('SELECT used_count FROM idle_audit_daily_budgets WHERE workspace_key = ? AND utc_day = ? LIMIT 1')
|
|
150
|
+
.get(workspaceKey, utcDay);
|
|
151
|
+
const current = isRecord(row) && typeof row.used_count === 'number' ? row.used_count : 0;
|
|
152
|
+
if (current >= dailyLimit) {
|
|
153
|
+
return {
|
|
154
|
+
reserved: false,
|
|
155
|
+
workspaceKey,
|
|
156
|
+
utcDay,
|
|
157
|
+
usedCount: current,
|
|
158
|
+
dailyLimit,
|
|
159
|
+
reason: 'daily_budget_exhausted',
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const nextCount = current + 1;
|
|
163
|
+
conn
|
|
164
|
+
.prepare(`INSERT INTO idle_audit_daily_budgets (workspace_key, utc_day, used_count, updated_at)
|
|
165
|
+
VALUES (?, ?, ?, ?)
|
|
166
|
+
ON CONFLICT(workspace_key, utc_day) DO UPDATE SET
|
|
167
|
+
used_count = excluded.used_count,
|
|
168
|
+
updated_at = excluded.updated_at`)
|
|
169
|
+
.run(workspaceKey, utcDay, nextCount, updatedAt);
|
|
170
|
+
return {
|
|
171
|
+
reserved: true,
|
|
172
|
+
workspaceKey,
|
|
173
|
+
utcDay,
|
|
174
|
+
usedCount: nextCount,
|
|
175
|
+
dailyLimit,
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
return tx.immediate();
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
return {
|
|
182
|
+
reserved: false,
|
|
183
|
+
workspaceKey,
|
|
184
|
+
utcDay,
|
|
185
|
+
usedCount: 0,
|
|
186
|
+
dailyLimit,
|
|
187
|
+
reason: 'db_error',
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
if (db !== null) {
|
|
192
|
+
try {
|
|
193
|
+
db.close();
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
// ignore close errors
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function isStringArray(value) {
|
|
202
|
+
return Array.isArray(value) && value.every((x) => typeof x === 'string');
|
|
203
|
+
}
|
|
204
|
+
function findMatchingInjectionEvent(params) {
|
|
205
|
+
const logsRoot = path.resolve(params.stateDir, 'logs');
|
|
206
|
+
if (!fs.existsSync(logsRoot)) {
|
|
207
|
+
return { found: null, hasLogs: false };
|
|
208
|
+
}
|
|
209
|
+
const files = fs
|
|
210
|
+
.readdirSync(logsRoot)
|
|
211
|
+
.filter((name) => name.startsWith('events_') && name.endsWith('.jsonl'))
|
|
212
|
+
.sort()
|
|
213
|
+
.reverse();
|
|
214
|
+
const resolvedWs = path.resolve(params.workspaceDir);
|
|
215
|
+
for (const name of files) {
|
|
216
|
+
const filePath = path.resolve(logsRoot, name);
|
|
217
|
+
if (!filePath.startsWith(logsRoot + path.sep) || path.basename(name) !== name)
|
|
218
|
+
continue;
|
|
219
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
220
|
+
const lines = raw.split('\n').reverse();
|
|
221
|
+
for (const line of lines) {
|
|
222
|
+
if (line.trim().length === 0)
|
|
223
|
+
continue;
|
|
224
|
+
let parsed;
|
|
225
|
+
try {
|
|
226
|
+
parsed = JSON.parse(line);
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (!isRecord(parsed) || parsed.type !== 'runtime_v2_prompt_activations_injected')
|
|
232
|
+
continue;
|
|
233
|
+
const { data } = parsed;
|
|
234
|
+
if (!isRecord(data))
|
|
235
|
+
continue;
|
|
236
|
+
const evWorkspace = nonEmptyString(data.workspaceDir);
|
|
237
|
+
const evSession = nonEmptyString(data.sessionId) ?? nonEmptyString(parsed.sessionId);
|
|
238
|
+
const evHost = nonEmptyString(data.hostKind);
|
|
239
|
+
const evRunId = nonEmptyString(data.runId);
|
|
240
|
+
const evId = nonEmptyString(data.eventId);
|
|
241
|
+
if (evWorkspace === null || path.resolve(evWorkspace) !== resolvedWs)
|
|
242
|
+
continue;
|
|
243
|
+
if (evSession !== params.sessionId)
|
|
244
|
+
continue;
|
|
245
|
+
if (evHost !== null && evHost !== params.hostKind)
|
|
246
|
+
continue;
|
|
247
|
+
if (params.runId !== undefined && evRunId !== null && evRunId !== params.runId)
|
|
248
|
+
continue;
|
|
249
|
+
if (!isStringArray(data.principleIds) ||
|
|
250
|
+
!isStringArray(data.activationIds) ||
|
|
251
|
+
!isStringArray(data.artifactIds)) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const eventTs = nonEmptyString(parsed.ts);
|
|
255
|
+
const eventMs = eventTs === null ? Number.NaN : Date.parse(eventTs);
|
|
256
|
+
const observedMs = Date.parse(params.observedAt);
|
|
257
|
+
if (!Number.isFinite(eventMs) || !Number.isFinite(observedMs) || eventMs > observedMs)
|
|
258
|
+
continue;
|
|
259
|
+
if (!data.principleIds.includes(params.principleId))
|
|
260
|
+
continue;
|
|
261
|
+
return {
|
|
262
|
+
hasLogs: true,
|
|
263
|
+
found: {
|
|
264
|
+
principleIds: data.principleIds,
|
|
265
|
+
activationIds: data.activationIds,
|
|
266
|
+
artifactIds: data.artifactIds,
|
|
267
|
+
eventId: evId,
|
|
268
|
+
runId: evRunId,
|
|
269
|
+
ts: nonEmptyString(parsed.ts),
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return { found: null, hasLogs: true };
|
|
275
|
+
}
|
|
276
|
+
function extractPrincipleVersionFromArtifactContent(contentJson) {
|
|
277
|
+
try {
|
|
278
|
+
const parsed = JSON.parse(contentJson);
|
|
279
|
+
if (!isRecord(parsed))
|
|
280
|
+
return null;
|
|
281
|
+
for (const key of ['principleVersion', 'version', 'revision']) {
|
|
282
|
+
const val = parsed[key];
|
|
283
|
+
if (typeof val === 'string' && val.trim().length > 0)
|
|
284
|
+
return val.trim();
|
|
285
|
+
if (typeof val === 'number' && Number.isFinite(val))
|
|
286
|
+
return String(val);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Verify that `principleId` was genuinely injected into the turn, resolve its
|
|
296
|
+
* immutable `principleVersion` via `artifactIds`, and verify `activations`
|
|
297
|
+
* lifecycle contains `observedAt` without overwrite (W6).
|
|
298
|
+
*/
|
|
299
|
+
export function verifyPrincipleVisibilityForAudit(input) {
|
|
300
|
+
const stateDir = input.stateDir ?? path.join(path.resolve(input.workspaceDir), '.pd');
|
|
301
|
+
const eventLogStateDir = input.eventLogStateDir ?? path.join(path.resolve(input.workspaceDir), '.state');
|
|
302
|
+
const injection = findMatchingInjectionEvent({
|
|
303
|
+
stateDir: eventLogStateDir,
|
|
304
|
+
workspaceDir: input.workspaceDir,
|
|
305
|
+
hostKind: input.hostKind,
|
|
306
|
+
sessionId: input.sessionId,
|
|
307
|
+
principleId: input.principleId,
|
|
308
|
+
observedAt: input.observedAt,
|
|
309
|
+
...(input.runId !== undefined ? { runId: input.runId } : {}),
|
|
310
|
+
});
|
|
311
|
+
if (!injection.hasLogs) {
|
|
312
|
+
return { verdict: 'INCONCLUSIVE', reason: 'no_logs' };
|
|
313
|
+
}
|
|
314
|
+
if (injection.found === null) {
|
|
315
|
+
return { verdict: 'INCONCLUSIVE', reason: 'missing_injection_event' };
|
|
316
|
+
}
|
|
317
|
+
const idx = injection.found.principleIds.indexOf(input.principleId);
|
|
318
|
+
const activationId = idx >= 0 ? injection.found.activationIds[idx] : undefined;
|
|
319
|
+
const artifactId = idx >= 0 ? injection.found.artifactIds[idx] : undefined;
|
|
320
|
+
if (!activationId || !artifactId) {
|
|
321
|
+
return { verdict: 'INCONCLUSIVE', reason: 'missing_immutable_principle_version' };
|
|
322
|
+
}
|
|
323
|
+
const stateDbPath = path.join(stateDir, 'state.db');
|
|
324
|
+
if (!input.stateDbFactory && !fs.existsSync(stateDbPath)) {
|
|
325
|
+
return { verdict: 'INCONCLUSIVE', reason: 'missing_state_db' };
|
|
326
|
+
}
|
|
327
|
+
let db = null;
|
|
328
|
+
try {
|
|
329
|
+
db = input.stateDbFactory
|
|
330
|
+
? input.stateDbFactory(stateDbPath)
|
|
331
|
+
: new Database(stateDbPath, { readonly: true, fileMustExist: true });
|
|
332
|
+
// 1. Resolve immutable `principleVersion` via `artifactIds` from `pi_artifacts`
|
|
333
|
+
let principleVersion = null;
|
|
334
|
+
if (tableExists(db, 'pi_artifacts')) {
|
|
335
|
+
const artRow = db
|
|
336
|
+
.prepare('SELECT content_json FROM pi_artifacts WHERE artifact_id = ? LIMIT 1')
|
|
337
|
+
.get(artifactId);
|
|
338
|
+
if (isRecord(artRow) && typeof artRow.content_json === 'string') {
|
|
339
|
+
principleVersion = extractPrincipleVersionFromArtifactContent(artRow.content_json);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (principleVersion === null) {
|
|
343
|
+
return { verdict: 'INCONCLUSIVE', reason: 'missing_immutable_principle_version' };
|
|
344
|
+
}
|
|
345
|
+
// 2. Verify `activations` lifecycle covers `observedAt` without reactivation overwrite
|
|
346
|
+
if (!tableExists(db, 'activations')) {
|
|
347
|
+
return { verdict: 'INCONCLUSIVE', reason: 'activation_lifecycle_overwritten_or_out_of_window' };
|
|
348
|
+
}
|
|
349
|
+
const actRow = db
|
|
350
|
+
.prepare('SELECT artifact_id, activated_at, deactivated_at FROM activations WHERE activation_id = ? LIMIT 1')
|
|
351
|
+
.get(activationId);
|
|
352
|
+
if (!isRecord(actRow) || typeof actRow.activated_at !== 'string') {
|
|
353
|
+
return { verdict: 'INCONCLUSIVE', reason: 'activation_lifecycle_overwritten_or_out_of_window' };
|
|
354
|
+
}
|
|
355
|
+
// If `activations` was overwritten by a later reactivation for a different artifact
|
|
356
|
+
// or with activated_at > observedAt, historical lifecycle cannot be proven (PRI-932 is DRAFT).
|
|
357
|
+
if (typeof actRow.artifact_id === 'string' && actRow.artifact_id !== artifactId) {
|
|
358
|
+
return { verdict: 'INCONCLUSIVE', reason: 'activation_lifecycle_overwritten_or_out_of_window' };
|
|
359
|
+
}
|
|
360
|
+
const observedMs = Date.parse(input.observedAt);
|
|
361
|
+
const activatedMs = Date.parse(actRow.activated_at);
|
|
362
|
+
if (!Number.isFinite(observedMs) || !Number.isFinite(activatedMs) || activatedMs > observedMs) {
|
|
363
|
+
return { verdict: 'INCONCLUSIVE', reason: 'activation_lifecycle_overwritten_or_out_of_window' };
|
|
364
|
+
}
|
|
365
|
+
if (typeof actRow.deactivated_at === 'string') {
|
|
366
|
+
const deactivatedMs = Date.parse(actRow.deactivated_at);
|
|
367
|
+
if (!Number.isFinite(deactivatedMs) || observedMs > deactivatedMs) {
|
|
368
|
+
return { verdict: 'INCONCLUSIVE', reason: 'activation_lifecycle_overwritten_or_out_of_window' };
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
verdict: 'PROVEN',
|
|
373
|
+
deviationAnchor: {
|
|
374
|
+
principleId: input.principleId,
|
|
375
|
+
principleVersion,
|
|
376
|
+
activationId,
|
|
377
|
+
artifactId,
|
|
378
|
+
eventId: injection.found.eventId,
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
catch {
|
|
383
|
+
return { verdict: 'INCONCLUSIVE', reason: 'verification_error' };
|
|
384
|
+
}
|
|
385
|
+
finally {
|
|
386
|
+
if (db !== null) {
|
|
387
|
+
try {
|
|
388
|
+
db.close();
|
|
389
|
+
}
|
|
390
|
+
catch {
|
|
391
|
+
// ignore close errors
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
function isActivityRow(value) {
|
|
397
|
+
if (!isRecord(value))
|
|
398
|
+
return false;
|
|
399
|
+
return (typeof value.host_kind === 'string' &&
|
|
400
|
+
typeof value.root_session_id === 'string' &&
|
|
401
|
+
typeof value.last_turn_completed_at === 'string' &&
|
|
402
|
+
typeof value.turn_end_source === 'string' &&
|
|
403
|
+
typeof value.has_active_run === 'number');
|
|
404
|
+
}
|
|
405
|
+
function isIdleHostKind(value) {
|
|
406
|
+
return value === 'codex' || value === 'workbuddy' || value === 'openclaw';
|
|
407
|
+
}
|
|
408
|
+
function withTimeout(promise, timeoutMs) {
|
|
409
|
+
return new Promise((resolve, reject) => {
|
|
410
|
+
const timer = setTimeout(() => resolve({ timedOut: true }), timeoutMs);
|
|
411
|
+
promise.then((value) => {
|
|
412
|
+
clearTimeout(timer);
|
|
413
|
+
resolve({ timedOut: false, value });
|
|
414
|
+
}, (err) => {
|
|
415
|
+
clearTimeout(timer);
|
|
416
|
+
reject(err);
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
function findNextEligibleIdleSession(params) {
|
|
421
|
+
if (!tableExists(params.db, 'idle_audit_session_activity'))
|
|
422
|
+
return null;
|
|
423
|
+
const eligibleRows = [];
|
|
424
|
+
const batchSize = 20;
|
|
425
|
+
const maxScannedRows = 200;
|
|
426
|
+
let offset = 0;
|
|
427
|
+
while (offset < maxScannedRows) {
|
|
428
|
+
const rawRows = params.db
|
|
429
|
+
.prepare(`SELECT host_kind, root_session_id, last_turn_completed_at, turn_end_source, has_active_run
|
|
430
|
+
FROM idle_audit_session_activity
|
|
431
|
+
WHERE has_active_run = 0
|
|
432
|
+
AND last_turn_completed_at <= ?
|
|
433
|
+
ORDER BY last_turn_completed_at DESC
|
|
434
|
+
LIMIT ? OFFSET ?`)
|
|
435
|
+
.all(params.idleCutoffIso, batchSize, offset);
|
|
436
|
+
const batch = Array.isArray(rawRows) ? rawRows.filter(isActivityRow) : [];
|
|
437
|
+
eligibleRows.push(...batch);
|
|
438
|
+
if (batch.length < batchSize)
|
|
439
|
+
break;
|
|
440
|
+
offset += batchSize;
|
|
441
|
+
}
|
|
442
|
+
for (const row of eligibleRows) {
|
|
443
|
+
if (!isIdleHostKind(row.host_kind))
|
|
444
|
+
continue;
|
|
445
|
+
const authz = readSourceMaterialAuthorization({
|
|
446
|
+
workspaceDir: params.workspaceDir,
|
|
447
|
+
hostKind: row.host_kind,
|
|
448
|
+
});
|
|
449
|
+
if (authz.status !== 'authorized')
|
|
450
|
+
continue;
|
|
451
|
+
// Count total turns & latest observation id for this (host_kind, session_id)
|
|
452
|
+
let turnCount = 0;
|
|
453
|
+
let lastObservationId = '';
|
|
454
|
+
let rolloutIdentity = `${row.host_kind}:${row.root_session_id}`;
|
|
455
|
+
let latestObservedAt = '';
|
|
456
|
+
if (row.host_kind === 'openclaw' && tableExists(params.db, 'user_turns')) {
|
|
457
|
+
const stat = params.db
|
|
458
|
+
.prepare('SELECT COUNT(*) AS n, MAX(id) AS max_id, MAX(created_at) AS latest_at FROM user_turns WHERE session_id = ?')
|
|
459
|
+
.get(row.root_session_id);
|
|
460
|
+
if (isRecord(stat) && typeof stat.n === 'number') {
|
|
461
|
+
turnCount = stat.n;
|
|
462
|
+
lastObservationId = typeof stat.max_id === 'number' ? `ut:${stat.max_id}` : '';
|
|
463
|
+
latestObservedAt = typeof stat.latest_at === 'string' ? stat.latest_at : '';
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
else if (tableExists(params.db, 'governance_observations')) {
|
|
467
|
+
const stat = params.db
|
|
468
|
+
.prepare(`SELECT COUNT(*) AS n, MAX(id) AS max_id, MAX(rollout_identity) AS rollout_id, MAX(observed_at) AS latest_at
|
|
469
|
+
FROM governance_observations
|
|
470
|
+
WHERE host_kind = ?
|
|
471
|
+
AND root_session_id = ?
|
|
472
|
+
AND kind IN ('user_turn', 'assistant_turn')
|
|
473
|
+
AND retention_class IN ('operational', 'promoted')`)
|
|
474
|
+
.get(row.host_kind, row.root_session_id);
|
|
475
|
+
if (isRecord(stat) && typeof stat.n === 'number') {
|
|
476
|
+
turnCount = stat.n;
|
|
477
|
+
lastObservationId = typeof stat.max_id === 'number' ? `go:${stat.max_id}` : '';
|
|
478
|
+
latestObservedAt = typeof stat.latest_at === 'string' ? stat.latest_at : '';
|
|
479
|
+
if (typeof stat.rollout_id === 'string' && stat.rollout_id.length > 0) {
|
|
480
|
+
rolloutIdentity = stat.rollout_id;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (turnCount < params.minTurns || lastObservationId.length === 0)
|
|
485
|
+
continue;
|
|
486
|
+
// A newer source-material observation after the recorded turn completion
|
|
487
|
+
// means the session became active again; the stale agent_end/stop fact must
|
|
488
|
+
// not make it audit-eligible.
|
|
489
|
+
if (latestObservedAt.length > 0 && latestObservedAt > row.last_turn_completed_at)
|
|
490
|
+
continue;
|
|
491
|
+
const idempotencyKey = `idle_audit:${row.host_kind}:${row.root_session_id}:${lastObservationId}`;
|
|
492
|
+
if (tableExists(params.db, 'governance_signal_admissions')) {
|
|
493
|
+
const exists = params.db
|
|
494
|
+
.prepare('SELECT 1 FROM governance_signal_admissions WHERE logical_observation_key = ? LIMIT 1')
|
|
495
|
+
.get(idempotencyKey);
|
|
496
|
+
if (exists !== undefined)
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
if (tableExists(params.db, 'idle_audit_outcomes')) {
|
|
500
|
+
const audited = params.db.prepare('SELECT 1 FROM idle_audit_outcomes WHERE idempotency_key = ? LIMIT 1').get(idempotencyKey);
|
|
501
|
+
if (audited !== undefined)
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
return {
|
|
505
|
+
hostKind: row.host_kind,
|
|
506
|
+
sessionId: row.root_session_id,
|
|
507
|
+
rolloutIdentity,
|
|
508
|
+
turnCount,
|
|
509
|
+
lastObservationId,
|
|
510
|
+
lastTurnCompletedAt: row.last_turn_completed_at,
|
|
511
|
+
turnEndSource: row.turn_end_source,
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Run one bounded Idle Turn Audit cycle (at most 1 eligible idle session per
|
|
518
|
+
* worker tick, zero new background daemons).
|
|
519
|
+
*/
|
|
520
|
+
export async function runIdleTurnAuditCycle(input) {
|
|
521
|
+
if (input.auditor === null) {
|
|
522
|
+
return {
|
|
523
|
+
ok: true,
|
|
524
|
+
auditedSessions: 0,
|
|
525
|
+
admittedInboxCandidates: 0,
|
|
526
|
+
inconclusiveCount: 0,
|
|
527
|
+
timedOutCount: 0,
|
|
528
|
+
budgetReserved: false,
|
|
529
|
+
skippedReason: 'llm_not_configured',
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
const now = input.now ?? new Date();
|
|
533
|
+
const minTurns = Math.max(1, input.minTurns ?? DEFAULT_IDLE_AUDIT_MIN_TURNS);
|
|
534
|
+
const idleThresholdMs = Math.max(0, input.idleThresholdMs ?? DEFAULT_IDLE_AUDIT_IDLE_MS);
|
|
535
|
+
const idleCutoffIso = new Date(now.getTime() - idleThresholdMs).toISOString();
|
|
536
|
+
const timeoutMs = Math.max(100, input.auditTimeoutMs ?? DEFAULT_IDLE_AUDIT_TIMEOUT_MS);
|
|
537
|
+
const dbPath = resolveTrajectoryDbPath(input.workspaceDir);
|
|
538
|
+
if (!input.databaseFactory && !fs.existsSync(dbPath)) {
|
|
539
|
+
return {
|
|
540
|
+
ok: true,
|
|
541
|
+
auditedSessions: 0,
|
|
542
|
+
admittedInboxCandidates: 0,
|
|
543
|
+
inconclusiveCount: 0,
|
|
544
|
+
timedOutCount: 0,
|
|
545
|
+
budgetReserved: false,
|
|
546
|
+
skippedReason: 'trajectory_db_absent',
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
let candidate;
|
|
550
|
+
let readDb = null;
|
|
551
|
+
try {
|
|
552
|
+
readDb = input.databaseFactory
|
|
553
|
+
? input.databaseFactory(dbPath)
|
|
554
|
+
: new Database(dbPath, { readonly: true, fileMustExist: true });
|
|
555
|
+
candidate = findNextEligibleIdleSession({
|
|
556
|
+
db: readDb,
|
|
557
|
+
workspaceDir: input.workspaceDir,
|
|
558
|
+
minTurns,
|
|
559
|
+
idleCutoffIso,
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
catch {
|
|
563
|
+
return {
|
|
564
|
+
ok: false,
|
|
565
|
+
auditedSessions: 0,
|
|
566
|
+
admittedInboxCandidates: 0,
|
|
567
|
+
inconclusiveCount: 0,
|
|
568
|
+
timedOutCount: 0,
|
|
569
|
+
budgetReserved: false,
|
|
570
|
+
skippedReason: 'trajectory_read_error',
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
finally {
|
|
574
|
+
if (readDb !== null) {
|
|
575
|
+
try {
|
|
576
|
+
readDb.close();
|
|
577
|
+
}
|
|
578
|
+
catch {
|
|
579
|
+
// ignore close errors
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
if (candidate === null) {
|
|
584
|
+
return {
|
|
585
|
+
ok: true,
|
|
586
|
+
auditedSessions: 0,
|
|
587
|
+
admittedInboxCandidates: 0,
|
|
588
|
+
inconclusiveCount: 0,
|
|
589
|
+
timedOutCount: 0,
|
|
590
|
+
budgetReserved: false,
|
|
591
|
+
skippedReason: 'no_eligible_idle_session',
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
// Reserve 1 atomic daily budget slot BEFORE calling the LLM (W6: timeouts still bill 1 unit)
|
|
595
|
+
const reservation = reserveIdleAuditDailyBudget({
|
|
596
|
+
workspaceDir: input.workspaceDir,
|
|
597
|
+
...(input.dailyLimit !== undefined ? { dailyLimit: input.dailyLimit } : {}),
|
|
598
|
+
now,
|
|
599
|
+
...(input.databaseFactory ? { databaseFactory: input.databaseFactory } : {}),
|
|
600
|
+
});
|
|
601
|
+
if (!reservation.reserved) {
|
|
602
|
+
return {
|
|
603
|
+
ok: true,
|
|
604
|
+
auditedSessions: 0,
|
|
605
|
+
admittedInboxCandidates: 0,
|
|
606
|
+
inconclusiveCount: 0,
|
|
607
|
+
timedOutCount: 0,
|
|
608
|
+
budgetReserved: false,
|
|
609
|
+
skippedReason: reservation.reason ?? 'daily_budget_exhausted',
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
const idempotencyKey = `idle_audit:${candidate.hostKind}:${candidate.sessionId}:${candidate.lastObservationId}`;
|
|
613
|
+
const persistOutcome = (outcome) => {
|
|
614
|
+
let outcomeDb = null;
|
|
615
|
+
try {
|
|
616
|
+
outcomeDb = input.databaseFactory ? input.databaseFactory(dbPath) : new Database(dbPath);
|
|
617
|
+
outcomeDb.pragma('busy_timeout = 5000');
|
|
618
|
+
recordIdleAuditOutcome({ db: outcomeDb, key: idempotencyKey, outcome, now });
|
|
619
|
+
}
|
|
620
|
+
catch {
|
|
621
|
+
// Best-effort outcome persistence; the hard budget row is already durable.
|
|
622
|
+
}
|
|
623
|
+
finally {
|
|
624
|
+
if (outcomeDb !== null) {
|
|
625
|
+
try {
|
|
626
|
+
outcomeDb.close();
|
|
627
|
+
}
|
|
628
|
+
catch { /* ignore close errors */ }
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
let finding;
|
|
633
|
+
try {
|
|
634
|
+
const raced = await withTimeout(input.auditor(candidate), timeoutMs);
|
|
635
|
+
if (raced.timedOut) {
|
|
636
|
+
// Budget unit remains consumed (timeout billing invariant)
|
|
637
|
+
persistOutcome('timeout');
|
|
638
|
+
return {
|
|
639
|
+
ok: true,
|
|
640
|
+
auditedSessions: 1,
|
|
641
|
+
admittedInboxCandidates: 0,
|
|
642
|
+
inconclusiveCount: 0,
|
|
643
|
+
timedOutCount: 1,
|
|
644
|
+
budgetReserved: true,
|
|
645
|
+
skippedReason: 'audit_timeout',
|
|
646
|
+
idempotencyKey,
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
finding = raced.value;
|
|
650
|
+
}
|
|
651
|
+
catch {
|
|
652
|
+
persistOutcome('auditor_error');
|
|
653
|
+
return {
|
|
654
|
+
ok: false,
|
|
655
|
+
auditedSessions: 1,
|
|
656
|
+
admittedInboxCandidates: 0,
|
|
657
|
+
inconclusiveCount: 0,
|
|
658
|
+
timedOutCount: 0,
|
|
659
|
+
budgetReserved: true,
|
|
660
|
+
skippedReason: 'auditor_error',
|
|
661
|
+
idempotencyKey,
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
if (!finding || !finding.detected || !finding.principleId || !finding.observedAt) {
|
|
665
|
+
persistOutcome('no_finding');
|
|
666
|
+
return {
|
|
667
|
+
ok: true,
|
|
668
|
+
auditedSessions: 1,
|
|
669
|
+
admittedInboxCandidates: 0,
|
|
670
|
+
inconclusiveCount: 0,
|
|
671
|
+
timedOutCount: 0,
|
|
672
|
+
budgetReserved: true,
|
|
673
|
+
idempotencyKey,
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
// W6: Verify real prompt injection + immutable principleVersion + activation lifecycle
|
|
677
|
+
const visibility = verifyPrincipleVisibilityForAudit({
|
|
678
|
+
workspaceDir: input.workspaceDir,
|
|
679
|
+
...(input.stateDir !== undefined ? { stateDir: input.stateDir } : {}),
|
|
680
|
+
...(input.eventLogStateDir !== undefined ? { eventLogStateDir: input.eventLogStateDir } : {}),
|
|
681
|
+
hostKind: candidate.hostKind,
|
|
682
|
+
sessionId: candidate.sessionId,
|
|
683
|
+
principleId: finding.principleId,
|
|
684
|
+
observedAt: finding.observedAt,
|
|
685
|
+
...(finding.runId !== undefined ? { runId: finding.runId } : {}),
|
|
686
|
+
...(input.stateDbFactory ? { stateDbFactory: input.stateDbFactory } : {}),
|
|
687
|
+
});
|
|
688
|
+
if (visibility.verdict !== 'PROVEN') {
|
|
689
|
+
persistOutcome(`inconclusive:${visibility.reason ?? 'unknown'}`);
|
|
690
|
+
return {
|
|
691
|
+
ok: true,
|
|
692
|
+
auditedSessions: 1,
|
|
693
|
+
admittedInboxCandidates: 0,
|
|
694
|
+
inconclusiveCount: 1,
|
|
695
|
+
timedOutCount: 0,
|
|
696
|
+
budgetReserved: true,
|
|
697
|
+
skippedReason: `inconclusive:${visibility.reason}`,
|
|
698
|
+
idempotencyKey,
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
// Re-check source-material authorization immediately before persisting the
|
|
702
|
+
// audit result. Consent may have been revoked while the LLM audit was in
|
|
703
|
+
// flight; the last pre-audit check is not a write-time authorization proof.
|
|
704
|
+
const authorizationAtWrite = readSourceMaterialAuthorization({
|
|
705
|
+
workspaceDir: input.workspaceDir,
|
|
706
|
+
hostKind: candidate.hostKind,
|
|
707
|
+
});
|
|
708
|
+
if (authorizationAtWrite.status !== 'authorized') {
|
|
709
|
+
persistOutcome(`authorization_blocked:${authorizationAtWrite.reason}`);
|
|
710
|
+
return {
|
|
711
|
+
ok: true,
|
|
712
|
+
auditedSessions: 1,
|
|
713
|
+
admittedInboxCandidates: 0,
|
|
714
|
+
inconclusiveCount: 0,
|
|
715
|
+
timedOutCount: 0,
|
|
716
|
+
budgetReserved: true,
|
|
717
|
+
skippedReason: `authorization_blocked:${authorizationAtWrite.reason}`,
|
|
718
|
+
idempotencyKey,
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
// Write Inbox-only candidate into governance_signal_admissions (never pain_events)
|
|
722
|
+
let writeDb = null;
|
|
723
|
+
try {
|
|
724
|
+
writeDb = input.databaseFactory ? input.databaseFactory(dbPath) : new Database(dbPath);
|
|
725
|
+
writeDb.pragma('busy_timeout = 5000');
|
|
726
|
+
if (!tableExists(writeDb, 'governance_signal_admissions')) {
|
|
727
|
+
return {
|
|
728
|
+
ok: false,
|
|
729
|
+
auditedSessions: 1,
|
|
730
|
+
admittedInboxCandidates: 0,
|
|
731
|
+
inconclusiveCount: 0,
|
|
732
|
+
timedOutCount: 0,
|
|
733
|
+
budgetReserved: true,
|
|
734
|
+
skippedReason: 'gsa_table_absent',
|
|
735
|
+
idempotencyKey,
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
const nowIso = now.toISOString();
|
|
739
|
+
const payload = {
|
|
740
|
+
signalKind: 'idle_audit_deviation',
|
|
741
|
+
excerpt: finding.excerpt ?? `Suspected deviation from principle ${finding.principleId}`,
|
|
742
|
+
confidence: typeof finding.confidence === 'number' ? finding.confidence : 0.65,
|
|
743
|
+
reasoning: finding.reasoning ?? null,
|
|
744
|
+
deviationAnchor: visibility.deviationAnchor,
|
|
745
|
+
observedAt: finding.observedAt,
|
|
746
|
+
auditedAt: nowIso,
|
|
747
|
+
};
|
|
748
|
+
writeDb
|
|
749
|
+
.prepare(`INSERT OR IGNORE INTO governance_signal_admissions (
|
|
750
|
+
host_kind,
|
|
751
|
+
logical_observation_key,
|
|
752
|
+
rollout_identity,
|
|
753
|
+
root_session_id,
|
|
754
|
+
signal_kind,
|
|
755
|
+
decision,
|
|
756
|
+
canonical_pain_id,
|
|
757
|
+
diagnostician_task_id,
|
|
758
|
+
rule_version,
|
|
759
|
+
reason,
|
|
760
|
+
task_payload_json,
|
|
761
|
+
created_at,
|
|
762
|
+
updated_at
|
|
763
|
+
) VALUES (?, ?, ?, ?, 'idle_audit_deviation', 'inbox_candidate', NULL, NULL, NULL, 'idle_turn_audit_deviation', ?, ?, ?)`)
|
|
764
|
+
.run(candidate.hostKind, idempotencyKey, candidate.rolloutIdentity, candidate.sessionId, JSON.stringify(payload), nowIso, nowIso);
|
|
765
|
+
persistOutcome('inbox_candidate');
|
|
766
|
+
return {
|
|
767
|
+
ok: true,
|
|
768
|
+
auditedSessions: 1,
|
|
769
|
+
admittedInboxCandidates: 1,
|
|
770
|
+
inconclusiveCount: 0,
|
|
771
|
+
timedOutCount: 0,
|
|
772
|
+
budgetReserved: true,
|
|
773
|
+
idempotencyKey,
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
finally {
|
|
777
|
+
if (writeDb !== null) {
|
|
778
|
+
try {
|
|
779
|
+
writeDb.close();
|
|
780
|
+
}
|
|
781
|
+
catch {
|
|
782
|
+
// ignore close errors
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|