@principles/host-runtime 4.5.1 → 4.6.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.
@@ -23,6 +23,7 @@ import { loadFeatureFlagFromConfig, loadPdConfigForPlugin } from './pd-config.js
23
23
  import { isAutomaticPainSubmissionAuthorized } from './auto-pain-authorization.js';
24
24
  import { createHostIntentDocReader } from './intent-doc-reader.js';
25
25
  import { createGovernanceTrajectoryTurnReader } from './governance-trajectory-turn-reader.js';
26
+ import { createConsentLedgerSourceMaterialAuthorization } from './source-material-authorization.js';
26
27
  /** Quiet flag that owns the L3 half of the ladder. */
27
28
  export const DIAGNOSTICIAN_AUTO_RUN_FLAG = 'openclaw_diagnostician_consumer';
28
29
  /** Owner string used for the diagnostics this module starts. */
@@ -116,7 +117,9 @@ export async function runPendingDiagnosticianOnce(options) {
116
117
  intentDocReader: createHostIntentDocReader({ workspaceDir: options.workspaceDir, effectiveConfig: config.effective }),
117
118
  // PRI-1265: the auto-run path sees the bound session's ORIGINAL turns
118
119
  // like every other diagnosis entry.
119
- trajectoryTurnReader: createGovernanceTrajectoryTurnReader({ workspaceDir: options.workspaceDir }),
120
+ trajectoryTurnReader: createGovernanceTrajectoryTurnReader({ workspaceDir: options.workspaceDir, sourceMaterialAuthorization: createConsentLedgerSourceMaterialAuthorization(options.workspaceDir) }),
121
+ // PRI-1283 R2: latest-consent gate consulted per assembly / model call.
122
+ sourceMaterialAuthorization: createConsentLedgerSourceMaterialAuthorization(options.workspaceDir),
120
123
  // SPEC §9.6: lazy probe — a flag revoked between candidate pick and
121
124
  // execution still stops the run at the bridge boundary.
122
125
  isAutoPainSubmissionAuthorized: () => isAutomaticPainSubmissionAuthorized(options.workspaceDir),
@@ -282,6 +282,13 @@ export interface ListGovernanceTurnTextsInput {
282
282
  readonly sessionId: string;
283
283
  /** Restrict to ONE host's observations — session ids are only unique per `(host_kind, rollout_identity)`. */
284
284
  readonly hostKind?: 'codex' | 'openclaw' | 'workbuddy';
285
+ /**
286
+ * PRI-1283 R2: restrict to this SET of hosts' observations (empty = no
287
+ * rows). Mutually exclusive with `hostKind`; used by the turn-reader gate to
288
+ * exclude hosts whose conversation-ingestion consent is no longer granted
289
+ * AT THE QUERY BOUNDARY.
290
+ */
291
+ readonly authorizedHostKinds?: readonly ('codex' | 'openclaw' | 'workbuddy')[];
285
292
  readonly limit?: number;
286
293
  readonly databaseFactory?: ObservationDatabaseFactory;
287
294
  }
@@ -836,15 +836,26 @@ export function listGovernanceTurnTexts(input) {
836
836
  const { db, close } = opened;
837
837
  try {
838
838
  const limit = Math.min(Math.max(input.limit ?? 200, 1), 2000);
839
+ // PRI-1283 R2: host predicate — one host (hostKind) or an authorized SET
840
+ // (authorizedHostKinds; an explicitly EMPTY set matches nothing, which is
841
+ // the correct "every host revoked" outcome, not invalid SQL).
842
+ if (input.hostKind !== undefined && input.authorizedHostKinds !== undefined) {
843
+ return { ok: false, reason: 'governance_turn_texts_invalid_input:host_kind_and_authorized_host_kinds_exclusive', nextAction: 'Pass exactly one of hostKind / authorizedHostKinds.' };
844
+ }
845
+ const hostPredicate = input.hostKind !== undefined
846
+ ? { sql: ' AND host_kind = ?', params: [input.hostKind] }
847
+ : input.authorizedHostKinds !== undefined
848
+ ? input.authorizedHostKinds.length === 0
849
+ ? { sql: ' AND 1 = 0', params: [] }
850
+ : { sql: ` AND host_kind IN (${input.authorizedHostKinds.map(() => '?').join(',')})`, params: [...input.authorizedHostKinds] }
851
+ : { sql: '', params: [] };
839
852
  const newestThenAsc = (identityColumn) => db.prepare('SELECT id, source_ordinal, visible_text, observed_at FROM ('
840
853
  + `SELECT id, source_ordinal, visible_text, observed_at, source_order FROM governance_observations `
841
854
  + `WHERE kind = ? AND ${identityColumn} = ? AND visible_text IS NOT NULL `
842
855
  + `AND retention_class IN ('operational', 'promoted')`
843
- + `${input.hostKind !== undefined ? ' AND host_kind = ?' : ''} `
856
+ + `${hostPredicate.sql} `
844
857
  + 'ORDER BY observed_at DESC, source_order DESC, id DESC LIMIT ?'
845
- + ') ORDER BY observed_at ASC, source_order ASC, id ASC').all(...(input.hostKind !== undefined
846
- ? [input.kind, input.sessionId, input.hostKind, limit]
847
- : [input.kind, input.sessionId, limit]));
858
+ + ') ORDER BY observed_at ASC, source_order ASC, id ASC').all(input.kind, input.sessionId, ...hostPredicate.params, limit);
848
859
  // Exact session rows first; the root_session_id fallback keeps historical
849
860
  // (pre-rollout-identity) rows readable but can no longer drag another
850
861
  // rollout's turns (e.g. a subagent's) into this session's context.
@@ -87,6 +87,16 @@ export interface GovernanceCorrectionCandidate {
87
87
  * admission, rate limit and idempotency are identical either way.
88
88
  */
89
89
  readonly explicitChannel?: 'codex_explicit_prefix' | 'codex_explicit_agent' | 'workbuddy_explicit_prefix';
90
+ /**
91
+ * PRI-1283 round 3 (owner_manual ruling): set ONLY by the registration
92
+ * path after the submitted statement was verified VERBATIM against the
93
+ * current turn's host transcript — the trusted Owner interaction record.
94
+ * Never accepted from a submission payload: an agent cannot self-declare
95
+ * Owner confirmation (a payload claim is not a confirmation record).
96
+ * Agent-assisted statements without this flag persist as Agent-derived
97
+ * (no `owner_statement` classification, no ownerConfirmation block).
98
+ */
99
+ readonly ownerVerbatimConfirmed?: boolean;
90
100
  }
91
101
  export type GovernanceSignalCandidate = GovernanceCorrectionCandidate;
92
102
  export type GovernanceAdmissionOutcome = {
@@ -184,14 +194,53 @@ export type ClaimPendingCandidatesResult = {
184
194
  ok: true;
185
195
  candidates: readonly PendingCorrectionCandidate[];
186
196
  expired: number;
197
+ revoked: number;
187
198
  } | Degradation;
188
199
  /**
189
200
  * Claim bounded pending candidates with an optimistic CAS on the exact payload
190
201
  * text. Rows whose claim is younger than PENDING_REVIEW_CLAIM_TTL_MS are
191
202
  * skipped (another worker is reviewing them); TTL-expired rows become
192
203
  * `abandoned(ttl_expired)` here, before any LLM work.
204
+ *
205
+ * PRI-1283 review round 2 (directive A4): every claim re-reads the LATEST
206
+ * conversation-ingestion consent for the row's host. A host whose consent is
207
+ * no longer granted never yields a claimable candidate — the pending row is
208
+ * terminated as `abandoned('source_revoked')` right here (CAS on the exact
209
+ * payload text; the D6 terminal field set drops trigger.text /
210
+ * trigger.matchedTerms / hostTurnId / task_payload), so the revoked excerpt
211
+ * can neither be claimed nor keep living in the payload. Revocation is the
212
+ * linearization point: claims after it see the terminal row, and an
213
+ * in-flight claim is fenced by `recordPendingCorrectionReview` /
214
+ * `settlePendingCorrection` (both CAS on `decision='pending_llm_review'`).
193
215
  */
194
216
  export declare function claimPendingCorrectionCandidates(input: ClaimPendingCandidatesInput): ClaimPendingCandidatesResult;
217
+ export interface VerifyPendingClaimInput {
218
+ readonly workspaceDir: string;
219
+ readonly logicalObservationKey: string;
220
+ /** The fencing token this worker received from the claim. */
221
+ readonly claimToken: string;
222
+ readonly databaseFactory?: ObservationDatabaseFactory;
223
+ }
224
+ export type VerifyPendingClaimResult = {
225
+ ok: true;
226
+ allowed: true;
227
+ } | {
228
+ ok: true;
229
+ allowed: false;
230
+ reason: 'source_revoked' | 'consent_not_granted' | 'claim_not_owned' | 'not_pending' | 'payload_invalid';
231
+ } | Degradation;
232
+ /**
233
+ * PRI-1283 review round 2 (directive A5): the LAST authorization gate before
234
+ * `classifier(candidate.text, …)` starts a model request. Verifies, in one
235
+ * fresh read, that (a) the row is STILL `pending_llm_review`, (b) this
236
+ * worker's fencing token still owns the claim, and (c) the row's host still
237
+ * has granted consent. This is the revocation linearization boundary for NEW
238
+ * model requests: after a revocation completes (ledger decision or sweep
239
+ * termination), no fresh classifier call may start on the old source's text.
240
+ * A request already in flight cannot be recalled — its RESULT is fenced
241
+ * instead by `recordPendingCorrectionReview` (decision + claimToken CAS).
242
+ */
243
+ export declare function verifyPendingClaimForClassification(input: VerifyPendingClaimInput): VerifyPendingClaimResult;
195
244
  export interface ReleasePendingClaimInput {
196
245
  readonly workspaceDir: string;
197
246
  readonly logicalObservationKey: string;