@principles/host-runtime 4.5.0 → 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.
- package/dist/auto-pain-authorization.d.ts +29 -0
- package/dist/auto-pain-authorization.js +32 -0
- package/dist/diagnostician-auto-run.d.ts +1 -1
- package/dist/diagnostician-auto-run.js +45 -1
- package/dist/governance-observation-store.d.ts +7 -0
- package/dist/governance-observation-store.js +15 -4
- package/dist/governance-signal-admission.d.ts +49 -0
- package/dist/governance-signal-admission.js +371 -94
- package/dist/governance-trajectory-turn-reader.d.ts +20 -4
- package/dist/governance-trajectory-turn-reader.js +77 -5
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -0
- package/dist/internalization-consumer-cycle.js +4 -1
- package/dist/pd-config.d.ts +10 -0
- package/dist/pd-config.js +37 -0
- package/dist/signal-stage2-cycle.js +28 -1
- package/dist/source-material-authorization.d.ts +53 -0
- package/dist/source-material-authorization.js +67 -0
- package/dist/source-revocation-sweep.d.ts +172 -0
- package/dist/source-revocation-sweep.js +928 -0
- package/package.json +8 -4
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* B-class automatic Pain submission authorization (Pain Ingress SPEC §9.6).
|
|
3
|
+
*
|
|
4
|
+
* One flat feature flag in the Workspace's `.pd/config.yaml` `features:`
|
|
5
|
+
* block is the ONLY authority that turns an `automatic_hook` observation
|
|
6
|
+
* into a Pain submission:
|
|
7
|
+
*
|
|
8
|
+
* features:
|
|
9
|
+
* automatic_pain_submission: {category: quiet, enabled: true}
|
|
10
|
+
*
|
|
11
|
+
* It is deliberately distinct from every neighboring switch:
|
|
12
|
+
* - `signal_collector` = signal DETECTION capability (LLM
|
|
13
|
+
* classifier for ambiguous cues);
|
|
14
|
+
* - `internalization_auto_consumer` = task EXECUTION scheduler;
|
|
15
|
+
* - trusted `origin.source` = provenance integrity.
|
|
16
|
+
*
|
|
17
|
+
* None of those is an Owner authorization to submit Pains. Missing config,
|
|
18
|
+
* a missing flag, `enabled: false`, or a malformed config all resolve to
|
|
19
|
+
* NOT authorized (fail-closed default). The flag lives in the Workspace's
|
|
20
|
+
* own `.pd/config.yaml`, so it is per-Workspace and Owner-authored — a
|
|
21
|
+
* global install cannot grant it.
|
|
22
|
+
*/
|
|
23
|
+
export declare const AUTO_PAIN_SUBMISSION_FLAG = "automatic_pain_submission";
|
|
24
|
+
/**
|
|
25
|
+
* Whether THIS workspace's Owner explicitly authorized B-class automatic
|
|
26
|
+
* Pain submissions. Fail-closed: any unreadable/missing/absent config
|
|
27
|
+
* resolves false.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isAutomaticPainSubmissionAuthorized(workspaceDir: string): boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* B-class automatic Pain submission authorization (Pain Ingress SPEC §9.6).
|
|
3
|
+
*
|
|
4
|
+
* One flat feature flag in the Workspace's `.pd/config.yaml` `features:`
|
|
5
|
+
* block is the ONLY authority that turns an `automatic_hook` observation
|
|
6
|
+
* into a Pain submission:
|
|
7
|
+
*
|
|
8
|
+
* features:
|
|
9
|
+
* automatic_pain_submission: {category: quiet, enabled: true}
|
|
10
|
+
*
|
|
11
|
+
* It is deliberately distinct from every neighboring switch:
|
|
12
|
+
* - `signal_collector` = signal DETECTION capability (LLM
|
|
13
|
+
* classifier for ambiguous cues);
|
|
14
|
+
* - `internalization_auto_consumer` = task EXECUTION scheduler;
|
|
15
|
+
* - trusted `origin.source` = provenance integrity.
|
|
16
|
+
*
|
|
17
|
+
* None of those is an Owner authorization to submit Pains. Missing config,
|
|
18
|
+
* a missing flag, `enabled: false`, or a malformed config all resolve to
|
|
19
|
+
* NOT authorized (fail-closed default). The flag lives in the Workspace's
|
|
20
|
+
* own `.pd/config.yaml`, so it is per-Workspace and Owner-authored — a
|
|
21
|
+
* global install cannot grant it.
|
|
22
|
+
*/
|
|
23
|
+
import { loadFeatureFlagFromConfig } from './pd-config.js';
|
|
24
|
+
export const AUTO_PAIN_SUBMISSION_FLAG = 'automatic_pain_submission';
|
|
25
|
+
/**
|
|
26
|
+
* Whether THIS workspace's Owner explicitly authorized B-class automatic
|
|
27
|
+
* Pain submissions. Fail-closed: any unreadable/missing/absent config
|
|
28
|
+
* resolves false.
|
|
29
|
+
*/
|
|
30
|
+
export function isAutomaticPainSubmissionAuthorized(workspaceDir) {
|
|
31
|
+
return loadFeatureFlagFromConfig(workspaceDir, AUTO_PAIN_SUBMISSION_FLAG).enabled;
|
|
32
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export declare const DIAGNOSTICIAN_AUTO_RUN_FLAG = "openclaw_diagnostician_consumer";
|
|
3
3
|
/** Owner string used for the diagnostics this module starts. */
|
|
4
4
|
export declare const DIAGNOSTICIAN_AUTO_RUN_OWNER = "pd-auto-diagnostician";
|
|
5
|
-
export type PendingDiagnosticianSkipReason = 'flag_off' | 'capability_disabled' | 'service_not_running' | 'no_candidate';
|
|
5
|
+
export type PendingDiagnosticianSkipReason = 'flag_off' | 'capability_disabled' | 'service_not_running' | 'no_candidate' | 'auto_pain_unauthorized';
|
|
6
6
|
export interface PendingDiagnosticianRunResult {
|
|
7
7
|
readonly served: boolean;
|
|
8
8
|
readonly taskId?: string;
|
|
@@ -20,13 +20,36 @@
|
|
|
20
20
|
import * as path from 'node:path';
|
|
21
21
|
import { PrincipleTreeLedgerAdapter, createPainSignalBridge, createRuntimeStateHandle, pickDiagnosticianCandidate, resolveDiagnosticianCapability, } from '@principles/core/runtime';
|
|
22
22
|
import { loadFeatureFlagFromConfig, loadPdConfigForPlugin } from './pd-config.js';
|
|
23
|
+
import { isAutomaticPainSubmissionAuthorized } from './auto-pain-authorization.js';
|
|
23
24
|
import { createHostIntentDocReader } from './intent-doc-reader.js';
|
|
24
25
|
import { createGovernanceTrajectoryTurnReader } from './governance-trajectory-turn-reader.js';
|
|
26
|
+
import { createConsentLedgerSourceMaterialAuthorization } from './source-material-authorization.js';
|
|
25
27
|
/** Quiet flag that owns the L3 half of the ladder. */
|
|
26
28
|
export const DIAGNOSTICIAN_AUTO_RUN_FLAG = 'openclaw_diagnostician_consumer';
|
|
27
29
|
/** Owner string used for the diagnostics this module starts. */
|
|
28
30
|
export const DIAGNOSTICIAN_AUTO_RUN_OWNER = 'pd-auto-diagnostician';
|
|
29
31
|
const DEFAULT_CANDIDATE_LIMIT = 1;
|
|
32
|
+
/**
|
|
33
|
+
* The persisted top-level provenance is the admission authority for both
|
|
34
|
+
* legacy and v1 payloads (pain-signal-bridge's persisted-facts validator
|
|
35
|
+
* requires the two namespaces to agree). A malformed/missing payload is not
|
|
36
|
+
* an automatic submission — it is left for the normal execution path, which
|
|
37
|
+
* owns its own payload validation.
|
|
38
|
+
*/
|
|
39
|
+
function persistedCandidateProvenance(diagnosticJson) {
|
|
40
|
+
if (typeof diagnosticJson !== 'string' || diagnosticJson.length === 0)
|
|
41
|
+
return null;
|
|
42
|
+
try {
|
|
43
|
+
const parsed = JSON.parse(diagnosticJson);
|
|
44
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
45
|
+
return null;
|
|
46
|
+
const provenance = Reflect.get(parsed, 'provenance');
|
|
47
|
+
return typeof provenance === 'string' ? provenance : null;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
30
53
|
export async function runPendingDiagnosticianOnce(options) {
|
|
31
54
|
if (options.serviceStarted === false) {
|
|
32
55
|
return {
|
|
@@ -62,6 +85,22 @@ export async function runPendingDiagnosticianOnce(options) {
|
|
|
62
85
|
if (candidate === null) {
|
|
63
86
|
return { served: false, reason: 'no_candidate' };
|
|
64
87
|
}
|
|
88
|
+
// B-class authorization (Pain Ingress SPEC §9.6): a persisted automatic
|
|
89
|
+
// submission may not execute after the Owner revoked (or never granted)
|
|
90
|
+
// the Workspace flag — background recovery cannot bypass the gate. The
|
|
91
|
+
// task stays pending, retryable once the flag is enabled. owner_manual /
|
|
92
|
+
// host_context_bound / agent_reported_owner_approved tasks are exempt:
|
|
93
|
+
// their Owner authorization is intrinsic.
|
|
94
|
+
if (persistedCandidateProvenance(candidate.diagnosticJson) === 'automatic_hook'
|
|
95
|
+
&& !isAutomaticPainSubmissionAuthorized(options.workspaceDir)) {
|
|
96
|
+
return {
|
|
97
|
+
served: false,
|
|
98
|
+
reason: 'auto_pain_unauthorized',
|
|
99
|
+
taskId: candidate.taskId,
|
|
100
|
+
message: 'candidate is an automatic_hook submission and features.automatic_pain_submission is off',
|
|
101
|
+
nextAction: 'The task stays pending; enable features.automatic_pain_submission in .pd/config.yaml to allow automatic-Pain diagnosis.',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
65
104
|
const stateDir = path.join(options.workspaceDir, '.state');
|
|
66
105
|
try {
|
|
67
106
|
const bridge = await createPainSignalBridge({
|
|
@@ -78,7 +117,12 @@ export async function runPendingDiagnosticianOnce(options) {
|
|
|
78
117
|
intentDocReader: createHostIntentDocReader({ workspaceDir: options.workspaceDir, effectiveConfig: config.effective }),
|
|
79
118
|
// PRI-1265: the auto-run path sees the bound session's ORIGINAL turns
|
|
80
119
|
// like every other diagnosis entry.
|
|
81
|
-
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),
|
|
123
|
+
// SPEC §9.6: lazy probe — a flag revoked between candidate pick and
|
|
124
|
+
// execution still stops the run at the bridge boundary.
|
|
125
|
+
isAutoPainSubmissionAuthorized: () => isAutomaticPainSubmissionAuthorized(options.workspaceDir),
|
|
82
126
|
});
|
|
83
127
|
const executed = await bridge.executePendingDiagnosis({ taskId: candidate.taskId });
|
|
84
128
|
if (executed.status === 'failed') {
|
|
@@ -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
|
-
+ `${
|
|
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(
|
|
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;
|