@principles/host-runtime 5.1.0 → 5.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/internalization-consumer-cycle.js +1 -1
- package/dist/pain-inbox.d.ts +28 -0
- package/dist/pain-inbox.js +194 -46
- package/package.json +3 -3
|
@@ -47,7 +47,7 @@ function getNextActionForError(category) {
|
|
|
47
47
|
return 'Retry later or check for concurrent worker processes.';
|
|
48
48
|
}
|
|
49
49
|
if (category === 'timeout') {
|
|
50
|
-
return 'Check model provider service status/latency, or increase timeout settings in
|
|
50
|
+
return 'Check model provider service status/latency, or increase timeout settings in .pd/config.yaml.';
|
|
51
51
|
}
|
|
52
52
|
if (category === 'cancelled') {
|
|
53
53
|
return 'Re-enqueue or restart the task if it was cancelled by mistake.';
|
package/dist/pain-inbox.d.ts
CHANGED
|
@@ -48,11 +48,13 @@ export interface PainInboxItem {
|
|
|
48
48
|
readonly reason: string | null;
|
|
49
49
|
readonly createdAt: string;
|
|
50
50
|
readonly expiresAt: string;
|
|
51
|
+
readonly snoozedUntil?: string | null;
|
|
51
52
|
}
|
|
52
53
|
export interface ListPainInboxResult {
|
|
53
54
|
readonly ok: true;
|
|
54
55
|
readonly items: readonly PainInboxItem[];
|
|
55
56
|
readonly total: number;
|
|
57
|
+
readonly snoozedCount: number;
|
|
56
58
|
readonly byHost: {
|
|
57
59
|
readonly openclaw: number;
|
|
58
60
|
readonly codex: number;
|
|
@@ -97,6 +99,26 @@ export type DismissInboxCandidateResult = {
|
|
|
97
99
|
readonly reason: string;
|
|
98
100
|
readonly nextAction: string;
|
|
99
101
|
};
|
|
102
|
+
interface SetSnoozeInput {
|
|
103
|
+
readonly workspaceDir: string;
|
|
104
|
+
readonly itemId: string;
|
|
105
|
+
readonly nowIso?: string;
|
|
106
|
+
readonly databaseFactory?: ObservationDatabaseFactory;
|
|
107
|
+
}
|
|
108
|
+
type SetSnoozeResult = {
|
|
109
|
+
readonly ok: true;
|
|
110
|
+
readonly disposition: 'snoozed';
|
|
111
|
+
readonly itemId: string;
|
|
112
|
+
readonly snoozedUntil: string;
|
|
113
|
+
} | {
|
|
114
|
+
readonly ok: true;
|
|
115
|
+
readonly disposition: 'unsnoozed' | 'not_found' | 'already_resolved';
|
|
116
|
+
readonly itemId: string;
|
|
117
|
+
} | {
|
|
118
|
+
readonly ok: false;
|
|
119
|
+
readonly reason: 'invalid_snooze_time' | 'inbox_snooze_schema_incompatible' | 'inbox_snooze_write_failed';
|
|
120
|
+
readonly nextAction: string;
|
|
121
|
+
};
|
|
100
122
|
export interface ExpireStalePainInboxResult {
|
|
101
123
|
readonly ok: boolean;
|
|
102
124
|
readonly expiredGsa: number;
|
|
@@ -110,6 +132,10 @@ export declare function executeQueuedDiagnosisWithInboxRecovery(input: {
|
|
|
110
132
|
stateManager: Pick<RuntimeStateManager, 'updateTaskIfDiagnosticJsonUnchanged'>;
|
|
111
133
|
execute: () => Promise<PainSignalBridgeResult>;
|
|
112
134
|
}): Promise<PainSignalBridgeResult>;
|
|
135
|
+
export declare function snoozePainInboxCandidate(input: SetSnoozeInput & {
|
|
136
|
+
readonly snoozedUntilIso: string;
|
|
137
|
+
}): SetSnoozeResult;
|
|
138
|
+
export declare function unsnoozePainInboxCandidate(input: SetSnoozeInput): SetSnoozeResult;
|
|
113
139
|
/**
|
|
114
140
|
* List unified Pain Inbox candidates across Codex, WorkBuddy, and OpenClaw.
|
|
115
141
|
* Strictly excludes `source_revoked`, expired (>7d), terminal rows, and
|
|
@@ -118,6 +144,7 @@ export declare function executeQueuedDiagnosisWithInboxRecovery(input: {
|
|
|
118
144
|
export declare function listPainInboxItems(input: {
|
|
119
145
|
readonly workspaceDir: string;
|
|
120
146
|
readonly hostFilter?: PainInboxHostKind;
|
|
147
|
+
readonly includeSnoozed?: boolean;
|
|
121
148
|
readonly now?: Date;
|
|
122
149
|
readonly databaseFactory?: ObservationDatabaseFactory;
|
|
123
150
|
}): ListPainInboxResult;
|
|
@@ -143,3 +170,4 @@ export declare function expireStalePainInboxItems(input: {
|
|
|
143
170
|
readonly now?: Date;
|
|
144
171
|
readonly databaseFactory?: ObservationDatabaseFactory;
|
|
145
172
|
}): ExpireStalePainInboxResult;
|
|
173
|
+
export {};
|
package/dist/pain-inbox.js
CHANGED
|
@@ -34,11 +34,14 @@ import path from 'node:path';
|
|
|
34
34
|
import { isDeepStrictEqual } from 'node:util';
|
|
35
35
|
import Database from 'better-sqlite3';
|
|
36
36
|
import { resolveTrajectoryDbPath } from '@principles/core/runtime/storage-paths';
|
|
37
|
+
import { convergeTrajectorySchemaVersion } from '@principles/core/runtime/trajectory-schema';
|
|
37
38
|
import { checkIngressTopLevelConsistency, createDiagnosticianTaskId, evaluatePainIngress, parsePainIngressV1Payload, } from '@principles/core/runtime';
|
|
38
39
|
import { isAutomaticPainSubmissionAuthorized } from './auto-pain-authorization.js';
|
|
39
40
|
import { readSourceMaterialAuthorization } from './source-material-authorization.js';
|
|
40
41
|
import { ensureGovernanceDiagnosticianTask } from './governance-signal-admission.js';
|
|
41
42
|
export const PAIN_INBOX_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
43
|
+
const HOUR_MS = 60 * 60 * 1000;
|
|
44
|
+
const SNOOZE_REVIEW_WINDOW_MS = 24 * HOUR_MS;
|
|
42
45
|
export const PAIN_INBOX_APPROVING_TTL_MS = 10 * 60 * 1000;
|
|
43
46
|
function isRecord(value) {
|
|
44
47
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
@@ -390,15 +393,141 @@ function parseItemId(itemId) {
|
|
|
390
393
|
}
|
|
391
394
|
return null;
|
|
392
395
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
+
// signal_confirmations is part of an exact-DDL trajectory baseline: adding
|
|
397
|
+
// columns to it would stop old and current runtime writers opening the DB.
|
|
398
|
+
const SNOOZE_TABLE = 'pain_inbox_snoozes';
|
|
399
|
+
function readSnooze(db, itemId, createdAt) {
|
|
400
|
+
return tableExists(db, SNOOZE_TABLE)
|
|
401
|
+
? db.prepare('SELECT snoozed_until, review_until FROM pain_inbox_snoozes WHERE item_id = ? AND inbox_created_at = ?').get(itemId, createdAt)
|
|
402
|
+
: undefined;
|
|
396
403
|
}
|
|
397
|
-
function
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
404
|
+
function pruneExpiredSnoozes(db, nowIso) {
|
|
405
|
+
if (tableExists(db, SNOOZE_TABLE)) {
|
|
406
|
+
db.prepare('DELETE FROM pain_inbox_snoozes WHERE review_until <= ?').run(nowIso);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function activeSnoozeUntil(row, nowMs) {
|
|
410
|
+
return row.snoozed_until != null && Date.parse(row.snoozed_until) > nowMs ? row.snoozed_until : null;
|
|
411
|
+
}
|
|
412
|
+
function isExpired(createdAt, nowMs, reviewUntil) {
|
|
413
|
+
return Date.parse(createdAt) + PAIN_INBOX_TTL_MS <= nowMs
|
|
414
|
+
&& !(reviewUntil != null && Date.parse(reviewUntil) > nowMs);
|
|
415
|
+
}
|
|
416
|
+
function computeExpiresAt(createdAt, nowMs, reviewUntil) {
|
|
417
|
+
const createdMs = Date.parse(createdAt);
|
|
418
|
+
return new Date(Math.max((Number.isFinite(createdMs) ? createdMs : nowMs) + PAIN_INBOX_TTL_MS, reviewUntil == null ? 0 : (Date.parse(reviewUntil) || 0))).toISOString();
|
|
419
|
+
}
|
|
420
|
+
function isInboxHostAuthorized(workspaceDir, hostKind) {
|
|
421
|
+
const auth = readSourceMaterialAuthorization({ workspaceDir, hostKind });
|
|
422
|
+
return auth.status === 'authorized' || (hostKind === 'openclaw' && auth.reason === 'consent_missing');
|
|
423
|
+
}
|
|
424
|
+
function parseIsoMs(value) {
|
|
425
|
+
const parts = /^(\d{4}-\d{2}-\d{2}T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d)(?:\.(\d{1,3}))?(Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/.exec(value);
|
|
426
|
+
if (!parts)
|
|
427
|
+
return NaN;
|
|
428
|
+
const local = `${parts[1]}.${(parts[2] ?? '').padEnd(3, '0')}Z`;
|
|
429
|
+
const localMs = Date.parse(local);
|
|
430
|
+
if (!Number.isFinite(localMs) || new Date(localMs).toISOString() !== local)
|
|
431
|
+
return NaN;
|
|
432
|
+
return Date.parse(value);
|
|
433
|
+
}
|
|
434
|
+
function setInboxSnooze(input, nowMs, dueMs) {
|
|
435
|
+
const { workspaceDir, itemId, databaseFactory } = input;
|
|
436
|
+
const notFound = { ok: true, disposition: 'not_found', itemId };
|
|
437
|
+
const parsed = parseItemId(itemId);
|
|
438
|
+
if (!parsed)
|
|
439
|
+
return notFound;
|
|
440
|
+
let opened = null;
|
|
441
|
+
try {
|
|
442
|
+
opened = openTrajectoryDb(workspaceDir, false, databaseFactory);
|
|
443
|
+
if (!opened)
|
|
444
|
+
return notFound;
|
|
445
|
+
const { db } = opened;
|
|
446
|
+
// RESERVE the writer lock before reading the authoritative status.
|
|
447
|
+
// Approval, dismissal and expiry cannot interleave with this CAS.
|
|
448
|
+
return db.transaction(() => {
|
|
449
|
+
const isGsa = parsed.source === 'gsa';
|
|
450
|
+
const table = isGsa ? 'governance_signal_admissions' : 'signal_confirmations';
|
|
451
|
+
if (!tableExists(db, table))
|
|
452
|
+
return notFound;
|
|
453
|
+
const row = db.prepare(isGsa
|
|
454
|
+
? "SELECT host_kind AS host, created_at, decision = 'inbox_candidate' AS active FROM governance_signal_admissions WHERE logical_observation_key = ?"
|
|
455
|
+
: "SELECT 'openclaw' AS host, created_at, (status = 'pending' AND resolution = 'inbox_candidate') AS active FROM signal_confirmations WHERE id = ?").get(parsed.rawKey);
|
|
456
|
+
if (!row)
|
|
457
|
+
return notFound;
|
|
458
|
+
if (row.active !== 1)
|
|
459
|
+
return { ok: true, disposition: 'already_resolved', itemId };
|
|
460
|
+
if ((row.host !== 'openclaw' && row.host !== 'codex' && row.host !== 'workbuddy')
|
|
461
|
+
|| !isInboxHostAuthorized(workspaceDir, row.host))
|
|
462
|
+
return notFound;
|
|
463
|
+
const current = readSnooze(db, itemId, row.created_at);
|
|
464
|
+
if (isExpired(row.created_at, nowMs, current?.review_until)) {
|
|
465
|
+
return { ok: true, disposition: 'already_resolved', itemId };
|
|
466
|
+
}
|
|
467
|
+
// v3's explicit migration rejects undeclared tables. Validate the
|
|
468
|
+
// existing trajectory schema inside the writer lock before any DDL
|
|
469
|
+
// or metadata cleanup. List and the existing owner actions are unchanged.
|
|
470
|
+
try {
|
|
471
|
+
convergeTrajectorySchemaVersion(db);
|
|
472
|
+
}
|
|
473
|
+
catch (error) {
|
|
474
|
+
if (!(error instanceof Error) || !error.message.startsWith('trajectory schema baseline incompatible:')) {
|
|
475
|
+
throw error;
|
|
476
|
+
}
|
|
477
|
+
return {
|
|
478
|
+
ok: false, reason: 'inbox_snooze_schema_incompatible',
|
|
479
|
+
nextAction: 'Upgrade or repair the workspace trajectory database before changing Pain Inbox reminders.',
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
pruneExpiredSnoozes(db, new Date(nowMs).toISOString());
|
|
483
|
+
if (dueMs === null) {
|
|
484
|
+
if (current?.snoozed_until) {
|
|
485
|
+
// An already surfaced item keeps its existing review deadline.
|
|
486
|
+
const reviewUntil = Date.parse(current.snoozed_until) > nowMs
|
|
487
|
+
? new Date(nowMs + SNOOZE_REVIEW_WINDOW_MS).toISOString()
|
|
488
|
+
: current.review_until;
|
|
489
|
+
db.prepare(`UPDATE pain_inbox_snoozes SET snoozed_until = NULL, review_until = ?
|
|
490
|
+
WHERE item_id = ? AND inbox_created_at = ?`).run(reviewUntil, itemId, row.created_at);
|
|
491
|
+
}
|
|
492
|
+
return { ok: true, disposition: 'unsnoozed', itemId };
|
|
493
|
+
}
|
|
494
|
+
const snoozedUntil = new Date(dueMs).toISOString();
|
|
495
|
+
db.exec(`CREATE TABLE IF NOT EXISTS pain_inbox_snoozes (
|
|
496
|
+
item_id TEXT PRIMARY KEY NOT NULL,
|
|
497
|
+
inbox_created_at TEXT NOT NULL,
|
|
498
|
+
snoozed_until TEXT,
|
|
499
|
+
review_until TEXT NOT NULL
|
|
500
|
+
)`);
|
|
501
|
+
db.prepare(`INSERT INTO pain_inbox_snoozes (item_id, inbox_created_at, snoozed_until, review_until)
|
|
502
|
+
VALUES (?, ?, ?, ?) ON CONFLICT(item_id) DO UPDATE SET
|
|
503
|
+
inbox_created_at = excluded.inbox_created_at,
|
|
504
|
+
snoozed_until = excluded.snoozed_until, review_until = excluded.review_until`)
|
|
505
|
+
.run(itemId, row.created_at, snoozedUntil, new Date(dueMs + SNOOZE_REVIEW_WINDOW_MS).toISOString());
|
|
506
|
+
return { ok: true, disposition: 'snoozed', itemId, snoozedUntil };
|
|
507
|
+
}).immediate();
|
|
508
|
+
}
|
|
509
|
+
catch {
|
|
510
|
+
return { ok: false, reason: 'inbox_snooze_write_failed', nextAction: 'Retry the Pain Inbox action; if it still fails, check workspace database access.' };
|
|
511
|
+
}
|
|
512
|
+
finally {
|
|
513
|
+
opened?.close();
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
export function snoozePainInboxCandidate(input) {
|
|
517
|
+
const nowMs = input.nowIso === undefined ? Date.now() : parseIsoMs(input.nowIso);
|
|
518
|
+
const dueMs = parseIsoMs(input.snoozedUntilIso);
|
|
519
|
+
if (!Number.isFinite(nowMs) || !Number.isFinite(dueMs)
|
|
520
|
+
|| dueMs - nowMs < HOUR_MS || dueMs - nowMs > 30 * 24 * HOUR_MS) {
|
|
521
|
+
return { ok: false, reason: 'invalid_snooze_time', nextAction: 'Specify a valid ISO timestamp between 1 hour and 30 days from now.' };
|
|
522
|
+
}
|
|
523
|
+
return setInboxSnooze(input, nowMs, dueMs);
|
|
524
|
+
}
|
|
525
|
+
export function unsnoozePainInboxCandidate(input) {
|
|
526
|
+
const nowMs = input.nowIso === undefined ? Date.now() : parseIsoMs(input.nowIso);
|
|
527
|
+
if (!Number.isFinite(nowMs)) {
|
|
528
|
+
return { ok: false, reason: 'invalid_snooze_time', nextAction: 'Specify a valid ISO timestamp for now.' };
|
|
529
|
+
}
|
|
530
|
+
return setInboxSnooze(input, nowMs, null);
|
|
402
531
|
}
|
|
403
532
|
/**
|
|
404
533
|
* List unified Pain Inbox candidates across Codex, WorkBuddy, and OpenClaw.
|
|
@@ -409,25 +538,31 @@ export function listPainInboxItems(input) {
|
|
|
409
538
|
const nowMs = (input.now ?? new Date()).getTime();
|
|
410
539
|
const opened = openTrajectoryDb(input.workspaceDir, true, input.databaseFactory);
|
|
411
540
|
if (!opened) {
|
|
412
|
-
return { ok: true, items: [], total: 0, byHost: { openclaw: 0, codex: 0, workbuddy: 0 } };
|
|
541
|
+
return { ok: true, items: [], total: 0, snoozedCount: 0, byHost: { openclaw: 0, codex: 0, workbuddy: 0 } };
|
|
413
542
|
}
|
|
414
543
|
const { db, close } = opened;
|
|
415
544
|
try {
|
|
416
545
|
const items = [];
|
|
546
|
+
let snoozedCount = 0;
|
|
547
|
+
const hasSnoozes = tableExists(db, SNOOZE_TABLE);
|
|
548
|
+
const projectSnooze = hasSnoozes ? ', s.snoozed_until, s.review_until' : '';
|
|
549
|
+
const joinSnoozes = (idSql) => hasSnoozes
|
|
550
|
+
? `LEFT JOIN pain_inbox_snoozes s ON s.item_id = ${idSql} AND s.inbox_created_at = i.created_at`
|
|
551
|
+
: '';
|
|
552
|
+
const visible = (row) => {
|
|
553
|
+
if (isExpired(row.created_at, nowMs, row.review_until))
|
|
554
|
+
return false;
|
|
555
|
+
const snoozed = activeSnoozeUntil(row, nowMs) !== null;
|
|
556
|
+
if (snoozed)
|
|
557
|
+
snoozedCount++;
|
|
558
|
+
return input.includeSnoozed === true || !snoozed;
|
|
559
|
+
};
|
|
417
560
|
const authCache = new Map();
|
|
418
561
|
const isHostAuthorized = (hostKind) => {
|
|
419
562
|
const cached = authCache.get(hostKind);
|
|
420
563
|
if (cached !== undefined)
|
|
421
564
|
return cached;
|
|
422
|
-
|
|
423
|
-
// consent prerequisite unless explicitly revoked in the ledger.
|
|
424
|
-
const auth = readSourceMaterialAuthorization({
|
|
425
|
-
workspaceDir: input.workspaceDir,
|
|
426
|
-
hostKind,
|
|
427
|
-
});
|
|
428
|
-
const allowed = hostKind === 'openclaw'
|
|
429
|
-
? auth.status === 'authorized' || auth.reason === 'consent_missing'
|
|
430
|
-
: auth.status === 'authorized';
|
|
565
|
+
const allowed = isInboxHostAuthorized(input.workspaceDir, hostKind);
|
|
431
566
|
authCache.set(hostKind, allowed);
|
|
432
567
|
return allowed;
|
|
433
568
|
};
|
|
@@ -435,8 +570,8 @@ export function listPainInboxItems(input) {
|
|
|
435
570
|
if (tableExists(db, 'governance_signal_admissions')) {
|
|
436
571
|
const rows = db
|
|
437
572
|
.prepare(`SELECT logical_observation_key, host_kind, root_session_id, signal_kind,
|
|
438
|
-
decision, reason, task_payload_json, created_at
|
|
439
|
-
FROM governance_signal_admissions
|
|
573
|
+
decision, reason, task_payload_json, i.created_at${projectSnooze}
|
|
574
|
+
FROM governance_signal_admissions i ${joinSnoozes("'gsa:' || i.logical_observation_key")}
|
|
440
575
|
WHERE decision IN ('inbox_candidate', 'inbox_approving')
|
|
441
576
|
ORDER BY created_at DESC`)
|
|
442
577
|
.all()
|
|
@@ -451,7 +586,7 @@ export function listPainInboxItems(input) {
|
|
|
451
586
|
continue;
|
|
452
587
|
if (!isHostAuthorized(hostKind))
|
|
453
588
|
continue;
|
|
454
|
-
if (
|
|
589
|
+
if (!visible(row))
|
|
455
590
|
continue;
|
|
456
591
|
const payload = parseJsonSafe(row.task_payload_json);
|
|
457
592
|
const trigger = payload && isRecord(payload.trigger) ? payload.trigger : null;
|
|
@@ -474,7 +609,8 @@ export function listPainInboxItems(input) {
|
|
|
474
609
|
confidence,
|
|
475
610
|
reason: row.reason,
|
|
476
611
|
createdAt: row.created_at,
|
|
477
|
-
expiresAt: computeExpiresAt(row.created_at),
|
|
612
|
+
expiresAt: computeExpiresAt(row.created_at, nowMs, row.review_until),
|
|
613
|
+
snoozedUntil: activeSnoozeUntil(row, nowMs),
|
|
478
614
|
});
|
|
479
615
|
}
|
|
480
616
|
}
|
|
@@ -483,15 +619,15 @@ export function listPainInboxItems(input) {
|
|
|
483
619
|
isHostAuthorized('openclaw') &&
|
|
484
620
|
tableExists(db, 'signal_confirmations')) {
|
|
485
621
|
const rows = db
|
|
486
|
-
.prepare(`SELECT id, session_id, excerpt, resolution, created_at
|
|
487
|
-
FROM signal_confirmations
|
|
622
|
+
.prepare(`SELECT id, session_id, excerpt, resolution, i.created_at${projectSnooze}
|
|
623
|
+
FROM signal_confirmations i ${joinSnoozes("'oc:' || i.id")}
|
|
488
624
|
WHERE status = 'pending'
|
|
489
625
|
AND resolution IN ('inbox_candidate', 'inbox_approving')
|
|
490
626
|
ORDER BY created_at DESC`)
|
|
491
627
|
.all()
|
|
492
628
|
.filter(isOpenClawInboxRow);
|
|
493
629
|
for (const row of rows) {
|
|
494
|
-
if (
|
|
630
|
+
if (!visible(row))
|
|
495
631
|
continue;
|
|
496
632
|
items.push({
|
|
497
633
|
id: `oc:${row.id}`,
|
|
@@ -504,7 +640,8 @@ export function listPainInboxItems(input) {
|
|
|
504
640
|
confidence: null,
|
|
505
641
|
reason: row.resolution,
|
|
506
642
|
createdAt: row.created_at,
|
|
507
|
-
expiresAt: computeExpiresAt(row.created_at),
|
|
643
|
+
expiresAt: computeExpiresAt(row.created_at, nowMs, row.review_until),
|
|
644
|
+
snoozedUntil: activeSnoozeUntil(row, nowMs),
|
|
508
645
|
});
|
|
509
646
|
}
|
|
510
647
|
}
|
|
@@ -514,7 +651,7 @@ export function listPainInboxItems(input) {
|
|
|
514
651
|
codex: items.filter((i) => i.hostKind === 'codex').length,
|
|
515
652
|
workbuddy: items.filter((i) => i.hostKind === 'workbuddy').length,
|
|
516
653
|
};
|
|
517
|
-
return { ok: true, items, total: items.length, byHost };
|
|
654
|
+
return { ok: true, items, total: items.length, snoozedCount, byHost };
|
|
518
655
|
}
|
|
519
656
|
finally {
|
|
520
657
|
close();
|
|
@@ -596,7 +733,7 @@ export async function admitOwnerApprovedInboxCandidate(input) {
|
|
|
596
733
|
if (hostKind !== 'openclaw' && auth.status !== 'authorized') {
|
|
597
734
|
return { ok: true, disposition: 'source_revoked', itemId: input.itemId, reason: auth.reason };
|
|
598
735
|
}
|
|
599
|
-
if (isExpired(row.created_at, nowMs)) {
|
|
736
|
+
if (isExpired(row.created_at, nowMs, readSnooze(db, input.itemId, row.created_at)?.review_until)) {
|
|
600
737
|
return { ok: true, disposition: 'expired', itemId: input.itemId };
|
|
601
738
|
}
|
|
602
739
|
const payload = parseJsonSafe(row.task_payload_json) ?? {};
|
|
@@ -869,7 +1006,7 @@ export async function admitOwnerApprovedInboxCandidate(input) {
|
|
|
869
1006
|
if (ocAuth.status !== 'authorized' && ocAuth.reason !== 'consent_missing') {
|
|
870
1007
|
return { ok: true, disposition: 'source_revoked', itemId: input.itemId, reason: ocAuth.reason };
|
|
871
1008
|
}
|
|
872
|
-
if (isExpired(ocRow.created_at, nowMs)) {
|
|
1009
|
+
if (isExpired(ocRow.created_at, nowMs, readSnooze(db, input.itemId, ocRow.created_at)?.review_until)) {
|
|
873
1010
|
return { ok: true, disposition: 'expired', itemId: input.itemId };
|
|
874
1011
|
}
|
|
875
1012
|
// P2-1: calm neutral correction -> archive as acknowledged_observation
|
|
@@ -1102,23 +1239,34 @@ export function expireStalePainInboxItems(input) {
|
|
|
1102
1239
|
return { ok: true, expiredGsa: 0, expiredOpenClaw: 0 };
|
|
1103
1240
|
const { db, close } = opened;
|
|
1104
1241
|
try {
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1242
|
+
return db.transaction(() => {
|
|
1243
|
+
const hasSnoozes = tableExists(db, SNOOZE_TABLE);
|
|
1244
|
+
const canExpire = (idSql, table) => hasSnoozes
|
|
1245
|
+
? `AND NOT EXISTS (SELECT 1 FROM pain_inbox_snoozes s
|
|
1246
|
+
WHERE s.item_id = ${idSql} AND s.inbox_created_at = ${table}.created_at
|
|
1247
|
+
AND s.review_until > @now)`
|
|
1248
|
+
: '';
|
|
1249
|
+
let expiredGsa = 0;
|
|
1250
|
+
let expiredOpenClaw = 0;
|
|
1251
|
+
if (tableExists(db, 'governance_signal_admissions')) {
|
|
1252
|
+
expiredGsa = db
|
|
1253
|
+
.prepare(`UPDATE governance_signal_admissions
|
|
1254
|
+
SET decision = 'abandoned', reason = 'inbox_ttl_expired', updated_at = @now
|
|
1255
|
+
WHERE decision = 'inbox_candidate' AND created_at <= @cutoff
|
|
1256
|
+
${canExpire("'gsa:' || governance_signal_admissions.logical_observation_key", 'governance_signal_admissions')}`)
|
|
1257
|
+
.run({ now: nowIso, cutoff: cutoffIso }).changes;
|
|
1258
|
+
}
|
|
1259
|
+
if (tableExists(db, 'signal_confirmations')) {
|
|
1260
|
+
expiredOpenClaw = db
|
|
1261
|
+
.prepare(`UPDATE signal_confirmations
|
|
1262
|
+
SET status = 'abandoned', resolution = 'inbox_ttl_expired', resolved_at = @now
|
|
1263
|
+
WHERE status = 'pending' AND resolution = 'inbox_candidate' AND created_at <= @cutoff
|
|
1264
|
+
${canExpire("'oc:' || signal_confirmations.id", 'signal_confirmations')}`)
|
|
1265
|
+
.run({ now: nowIso, cutoff: cutoffIso }).changes;
|
|
1266
|
+
}
|
|
1267
|
+
pruneExpiredSnoozes(db, nowIso);
|
|
1268
|
+
return { ok: true, expiredGsa, expiredOpenClaw };
|
|
1269
|
+
}).immediate();
|
|
1122
1270
|
}
|
|
1123
1271
|
catch (error) {
|
|
1124
1272
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/host-runtime",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Shared host-neutral orchestration for Principles Disciple MVP-Core hook paths.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"lint": "eslint \"src/**/*.ts\""
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@principles/core": "^
|
|
46
|
+
"@principles/core": "^11.0.0",
|
|
47
47
|
"@principles/install-layout": "^0.12.0",
|
|
48
48
|
"better-sqlite3": "^13.0.3",
|
|
49
49
|
"js-yaml": "^5.4.3"
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"url": "git+https://github.com/csuzngjh/principles.git"
|
|
62
62
|
},
|
|
63
63
|
"license": "Apache-2.0",
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "549a73b98fcbf19100938c24c3163f811bbf50bd"
|
|
65
65
|
}
|