@principles/host-runtime 4.6.0 → 4.7.1
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/diagnostician-auto-run.js +46 -34
- package/dist/governance-observation-store.d.ts +38 -0
- package/dist/governance-observation-store.js +41 -0
- package/dist/governance-trajectory-turn-reader.js +26 -33
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/intent-doc-reader.js +1 -1
- package/dist/workspace-pipeline-host-deps.d.ts +65 -0
- package/dist/workspace-pipeline-host-deps.js +94 -0
- package/dist/workspace-telemetry-emitter.js +14 -0
- package/package.json +4 -4
|
@@ -21,9 +21,7 @@ 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
23
|
import { isAutomaticPainSubmissionAuthorized } from './auto-pain-authorization.js';
|
|
24
|
-
import {
|
|
25
|
-
import { createGovernanceTrajectoryTurnReader } from './governance-trajectory-turn-reader.js';
|
|
26
|
-
import { createConsentLedgerSourceMaterialAuthorization } from './source-material-authorization.js';
|
|
24
|
+
import { resolveWorkspacePipelineHostDeps } from './workspace-pipeline-host-deps.js';
|
|
27
25
|
/** Quiet flag that owns the L3 half of the ladder. */
|
|
28
26
|
export const DIAGNOSTICIAN_AUTO_RUN_FLAG = 'openclaw_diagnostician_consumer';
|
|
29
27
|
/** Owner string used for the diagnostics this module starts. */
|
|
@@ -103,38 +101,52 @@ export async function runPendingDiagnosticianOnce(options) {
|
|
|
103
101
|
}
|
|
104
102
|
const stateDir = path.join(options.workspaceDir, '.state');
|
|
105
103
|
try {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
104
|
+
let releaseBridge;
|
|
105
|
+
try {
|
|
106
|
+
// SPEC-PD-PIPELINE-SPINE-001 §4.2 (PRI-1292 Phase 2A): ONE assembly
|
|
107
|
+
// point for the five host collaborators. The trajectory reader and the
|
|
108
|
+
// source-material gate now share the SAME consent-ledger authorization
|
|
109
|
+
// instance (previously two separate instances were created per call).
|
|
110
|
+
// PRI-1233 / SPEC §9.2: this path executes Stage A for
|
|
111
|
+
// governance-admitted pains, so the neutral host reader must ride
|
|
112
|
+
// along (flag-off keeps zero filesystem access); PRI-1265: the
|
|
113
|
+
// auto-run path sees the bound session's ORIGINAL turns.
|
|
114
|
+
const hostDeps = resolveWorkspacePipelineHostDeps({
|
|
115
|
+
workspaceDir: options.workspaceDir,
|
|
116
|
+
effectiveConfig: config.effective,
|
|
117
|
+
});
|
|
118
|
+
const bridge = await createPainSignalBridge({
|
|
119
|
+
workspaceDir: options.workspaceDir,
|
|
120
|
+
stateDir,
|
|
121
|
+
ledgerAdapter: new PrincipleTreeLedgerAdapter({ stateDir }),
|
|
122
|
+
owner: options.owner ?? DIAGNOSTICIAN_AUTO_RUN_OWNER,
|
|
123
|
+
effectiveConfig: config.effective,
|
|
124
|
+
getEnvVar: options.getEnvVar ?? ((name) => process.env[name]),
|
|
125
|
+
intentDocReader: hostDeps.intentDocReader,
|
|
126
|
+
trajectoryTurnReader: hostDeps.trajectoryTurnReader,
|
|
127
|
+
sourceMaterialAuthorization: hostDeps.sourceMaterialAuthorization,
|
|
128
|
+
// PRI-939 Option A: allowlisted runner/bridge events persist to the
|
|
129
|
+
// workspace sink instead of vanishing in the unsubscribed singleton.
|
|
130
|
+
telemetrySink: hostDeps.telemetrySink,
|
|
131
|
+
// SPEC §9.6: lazy probe — a flag revoked between candidate pick and
|
|
132
|
+
// execution still stops the run at the bridge boundary.
|
|
133
|
+
isAutoPainSubmissionAuthorized: hostDeps.isAutoPainSubmissionAuthorized,
|
|
134
|
+
}, (release) => { releaseBridge = release; });
|
|
135
|
+
const executed = await bridge.executePendingDiagnosis({ taskId: candidate.taskId });
|
|
136
|
+
if (executed.status === 'failed') {
|
|
137
|
+
return {
|
|
138
|
+
served: false,
|
|
139
|
+
taskId: candidate.taskId,
|
|
140
|
+
reason: 'execution_failed',
|
|
141
|
+
...(executed.message !== undefined ? { message: executed.message.slice(0, 200) } : {}),
|
|
142
|
+
nextAction: 'Inspect the workspace runtime profile; the task keeps its pending/retry state for the next tick or Console (L2).',
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return { served: true, taskId: candidate.taskId };
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
await releaseBridge?.();
|
|
136
149
|
}
|
|
137
|
-
return { served: true, taskId: candidate.taskId };
|
|
138
150
|
}
|
|
139
151
|
catch (error) {
|
|
140
152
|
// A missing/!invalid runtime profile must not throw out of the timer that
|
|
@@ -318,6 +318,44 @@ export type ListGovernanceObservationsResult = {
|
|
|
318
318
|
observations: readonly GovernanceObservationRecord[];
|
|
319
319
|
} | Degradation;
|
|
320
320
|
export declare function listGovernanceObservations(input: ListGovernanceObservationsInput): ListGovernanceObservationsResult;
|
|
321
|
+
/** A retained conversational row for an exact (host, rollout, turn). */
|
|
322
|
+
export interface GovernanceConversationTextRow {
|
|
323
|
+
readonly id: number;
|
|
324
|
+
readonly kind: 'user_turn' | 'assistant_turn';
|
|
325
|
+
readonly logicalKey: string;
|
|
326
|
+
readonly visibleText: string;
|
|
327
|
+
readonly observedAt: string;
|
|
328
|
+
}
|
|
329
|
+
export interface ListGovernanceConversationTextsInput {
|
|
330
|
+
readonly workspaceDir: string;
|
|
331
|
+
readonly hostKind: GovernanceObservationInput['hostKind'];
|
|
332
|
+
readonly rolloutIdentity: string;
|
|
333
|
+
readonly hostTurnId: string;
|
|
334
|
+
/**
|
|
335
|
+
* The turn's LAST N readable conversational rows (a long turn whose final
|
|
336
|
+
* answer sits behind dozens of tool/reasoning observations must still
|
|
337
|
+
* surface it — the generic list's `ORDER BY id LIMIT` window would cut it).
|
|
338
|
+
*/
|
|
339
|
+
readonly limit?: number;
|
|
340
|
+
readonly databaseFactory?: ObservationDatabaseFactory;
|
|
341
|
+
}
|
|
342
|
+
export type ListGovernanceConversationTextsResult = {
|
|
343
|
+
readonly ok: true;
|
|
344
|
+
readonly rows: readonly GovernanceConversationTextRow[];
|
|
345
|
+
} | {
|
|
346
|
+
readonly ok: false;
|
|
347
|
+
readonly reason: string;
|
|
348
|
+
readonly nextAction: string;
|
|
349
|
+
};
|
|
350
|
+
/**
|
|
351
|
+
* The ONE selection rule for an exact target turn's readable text, shared by
|
|
352
|
+
* the worker's evidence backfill, the diagnosis-time exact-turn reader and
|
|
353
|
+
* the submit path's opportunistic enrichment (devin BUG_0002): filter
|
|
354
|
+
* host/session/turn + conversational kind + retained readable text INSIDE
|
|
355
|
+
* the SQL, then take the LAST N by id (reversed back to capture order) —
|
|
356
|
+
* never a generic early window over all observation kinds.
|
|
357
|
+
*/
|
|
358
|
+
export declare function listGovernanceConversationTextsForHostTurn(input: ListGovernanceConversationTextsInput): ListGovernanceConversationTextsResult;
|
|
321
359
|
export declare function promoteGovernanceEvidence(input: PromoteGovernanceEvidenceInput): PromoteGovernanceEvidenceResult;
|
|
322
360
|
export interface QuarantineGovernanceObservationArgs {
|
|
323
361
|
readonly workspaceDir: string;
|
|
@@ -952,6 +952,47 @@ class PromotionMissingError extends Error {
|
|
|
952
952
|
this.name = 'PromotionMissingError';
|
|
953
953
|
}
|
|
954
954
|
}
|
|
955
|
+
/**
|
|
956
|
+
* The ONE selection rule for an exact target turn's readable text, shared by
|
|
957
|
+
* the worker's evidence backfill, the diagnosis-time exact-turn reader and
|
|
958
|
+
* the submit path's opportunistic enrichment (devin BUG_0002): filter
|
|
959
|
+
* host/session/turn + conversational kind + retained readable text INSIDE
|
|
960
|
+
* the SQL, then take the LAST N by id (reversed back to capture order) —
|
|
961
|
+
* never a generic early window over all observation kinds.
|
|
962
|
+
*/
|
|
963
|
+
export function listGovernanceConversationTextsForHostTurn(input) {
|
|
964
|
+
const opened = openStore(input.workspaceDir, input.databaseFactory);
|
|
965
|
+
if (!('db' in opened))
|
|
966
|
+
return opened;
|
|
967
|
+
const { db, close } = opened;
|
|
968
|
+
try {
|
|
969
|
+
const limit = Math.min(Math.max(input.limit ?? 12, 1), 64);
|
|
970
|
+
const rows = db.prepare([
|
|
971
|
+
'SELECT id, kind, logical_key, visible_text, observed_at FROM governance_observations',
|
|
972
|
+
'WHERE host_kind = ? AND rollout_identity = ? AND host_turn_id = ?',
|
|
973
|
+
"AND kind IN ('user_turn','assistant_turn')",
|
|
974
|
+
"AND completeness = 'complete'",
|
|
975
|
+
"AND retention_class IN ('operational','promoted')",
|
|
976
|
+
"AND visible_text IS NOT NULL AND TRIM(visible_text) <> ''",
|
|
977
|
+
'ORDER BY id DESC LIMIT ?',
|
|
978
|
+
].join(' ')).all(input.hostKind, input.rolloutIdentity, input.hostTurnId, limit);
|
|
979
|
+
const mapped = rows.map((row) => {
|
|
980
|
+
const kind = rowField(row, 'kind');
|
|
981
|
+
return {
|
|
982
|
+
id: Number(rowField(row, 'id')),
|
|
983
|
+
kind: kind === 'assistant_turn' ? 'assistant_turn' : 'user_turn',
|
|
984
|
+
logicalKey: String(rowField(row, 'logical_key')),
|
|
985
|
+
visibleText: String(rowField(row, 'visible_text')),
|
|
986
|
+
observedAt: String(rowField(row, 'observed_at')),
|
|
987
|
+
};
|
|
988
|
+
});
|
|
989
|
+
mapped.reverse();
|
|
990
|
+
return { ok: true, rows: mapped };
|
|
991
|
+
}
|
|
992
|
+
finally {
|
|
993
|
+
close();
|
|
994
|
+
}
|
|
995
|
+
}
|
|
955
996
|
export function promoteGovernanceEvidence(input) {
|
|
956
997
|
const opened = openStore(input.workspaceDir, input.databaseFactory);
|
|
957
998
|
if (!('db' in opened))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { denyAllSourceMaterialAuthorization, } from '@principles/core/runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { listGovernanceConversationTextsForHostTurn, listGovernanceTurnTexts } from './governance-observation-store.js';
|
|
3
3
|
/** Bound on turns per list call — the assembler bounds the window again. */
|
|
4
4
|
const MAX_TURNS_PER_SESSION = 200;
|
|
5
5
|
/** The governance-observation hosts whose turns this reader can serve. */
|
|
@@ -74,45 +74,38 @@ export function createGovernanceTrajectoryTurnReader(args) {
|
|
|
74
74
|
|| !port.isHostSourceMaterialAuthorized(authorizedHostKind).authorized) {
|
|
75
75
|
return { userTurns: [], assistantTurns: [] };
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
// PRI-1273 (devin BUG_0002): the shared exact-turn selection rule —
|
|
78
|
+
// conversational kind + retained readable text filtered INSIDE the SQL
|
|
79
|
+
// and the turn's LAST rows kept, so a final answer sitting behind
|
|
80
|
+
// dozens of tool/reasoning observations still enters the window (the
|
|
81
|
+
// old generic `ORDER BY id LIMIT 64` window cut it).
|
|
82
|
+
const result = listGovernanceConversationTextsForHostTurn({
|
|
78
83
|
workspaceDir: args.workspaceDir,
|
|
79
|
-
rolloutIdentity: sessionId,
|
|
80
84
|
hostKind: authorizedHostKind,
|
|
85
|
+
rolloutIdentity: sessionId,
|
|
81
86
|
hostTurnId,
|
|
82
|
-
limit:
|
|
87
|
+
limit: 32,
|
|
83
88
|
});
|
|
84
89
|
if (!result.ok)
|
|
85
90
|
return { userTurns: [], assistantTurns: [] };
|
|
86
|
-
const retainedText = (row) => (row.retentionClass === 'operational' || row.retentionClass === 'promoted')
|
|
87
|
-
&& typeof row.visibleText === 'string'
|
|
88
|
-
&& row.visibleText.trim() !== ''
|
|
89
|
-
? row.visibleText
|
|
90
|
-
: null;
|
|
91
|
-
const userRows = result.observations.filter((row) => row.kind === 'user_turn');
|
|
92
91
|
return {
|
|
93
|
-
userTurns:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
provider: '',
|
|
111
|
-
model: '',
|
|
112
|
-
sanitizedText: text,
|
|
113
|
-
createdAt: row.observedAt,
|
|
114
|
-
}];
|
|
115
|
-
}),
|
|
92
|
+
userTurns: result.rows.flatMap((row, index) => row.kind === 'user_turn' ? [{
|
|
93
|
+
id: row.id,
|
|
94
|
+
turnIndex: index,
|
|
95
|
+
rawExcerpt: row.visibleText,
|
|
96
|
+
correctionDetected: false,
|
|
97
|
+
correctionCue: null,
|
|
98
|
+
createdAt: row.observedAt,
|
|
99
|
+
}] : []),
|
|
100
|
+
assistantTurns: result.rows.flatMap((row) => row.kind === 'assistant_turn' ? [{
|
|
101
|
+
id: row.id,
|
|
102
|
+
sessionId,
|
|
103
|
+
runId: '',
|
|
104
|
+
provider: '',
|
|
105
|
+
model: '',
|
|
106
|
+
sanitizedText: row.visibleText,
|
|
107
|
+
createdAt: row.observedAt,
|
|
108
|
+
}] : []),
|
|
116
109
|
};
|
|
117
110
|
},
|
|
118
111
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export * from './internalization-consumer-governance.js';
|
|
|
35
35
|
export * from './internalization-consumer-cycle.js';
|
|
36
36
|
export * from './adaptive-consumer-schedule.js';
|
|
37
37
|
export * from './diagnostician-auto-run.js';
|
|
38
|
+
export * from './workspace-pipeline-host-deps.js';
|
|
38
39
|
export * from './host-tool-declaration.js';
|
|
39
40
|
export * from './host-tool-semantic-resolver.js';
|
|
40
41
|
export * from './evaluator-runtime-context.js';
|
package/dist/index.js
CHANGED
|
@@ -69,6 +69,10 @@ export * from './internalization-consumer-cycle.js';
|
|
|
69
69
|
// policy for the existing consumer timer chain (no new background service).
|
|
70
70
|
export * from './adaptive-consumer-schedule.js';
|
|
71
71
|
export * from './diagnostician-auto-run.js';
|
|
72
|
+
// SPEC-PD-PIPELINE-SPINE-001 §4.2 (PRI-1292 Phase 2A): the single workspace
|
|
73
|
+
// pipeline host collaborator assembly point — all five collaborators required,
|
|
74
|
+
// one shared consent-ledger authorization instance.
|
|
75
|
+
export * from './workspace-pipeline-host-deps.js';
|
|
72
76
|
// PRI-634-F R2: durable host-authored tool declaration — hosts persist, host-
|
|
73
77
|
// neutral consumers (pd-cli/pd-console) resolve through the ONE resolver.
|
|
74
78
|
export * from './host-tool-declaration.js';
|
|
@@ -170,7 +170,7 @@ export function createHostIntentDocReader(options) {
|
|
|
170
170
|
found: false,
|
|
171
171
|
flagEnabled: true,
|
|
172
172
|
reason: 'not_found',
|
|
173
|
-
nextAction: `
|
|
173
|
+
nextAction: `From workspace directory ${workspaceDir}, create .principles/${getIntentFilename(lang)} using "pd intent init --confirm --lang ${lang} --workspace .".`,
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
176
|
try {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPEC-PD-PIPELINE-SPINE-001 §4.2 — the single workspace pipeline host
|
|
3
|
+
* collaborator assembly point (PRI-1292 Phase 2A).
|
|
4
|
+
*
|
|
5
|
+
* Before this module, eight entry points each assembled the five host
|
|
6
|
+
* collaborators by hand, and the diagnostician entries created TWO separate
|
|
7
|
+
* `createConsentLedgerSourceMaterialAuthorization` instances per call — one
|
|
8
|
+
* inside the governance trajectory reader, one passed to the bridge — so the
|
|
9
|
+
* trajectory read and the source-material gate could observe different consent
|
|
10
|
+
* states within a single assembly. This resolver guarantees:
|
|
11
|
+
*
|
|
12
|
+
* 1. All five collaborators are REQUIRED on the returned object (no `?`),
|
|
13
|
+
* so a new entry cannot compile with a silently missing sink or probe.
|
|
14
|
+
* 2. The default `trajectoryTurnReader` and the returned
|
|
15
|
+
* `sourceMaterialAuthorization` share ONE consent-ledger authorization
|
|
16
|
+
* instance — trajectory reads and gate decisions are always consistent.
|
|
17
|
+
* 3. A host that already holds an in-process trajectory reader (OpenClaw
|
|
18
|
+
* Gateway `WorkspaceContext.trajectory`) passes it as
|
|
19
|
+
* `trajectoryTurnReaderOverride` instead of rebuilding one; the resolver
|
|
20
|
+
* wraps that reader in a live authorization probe rather than returning
|
|
21
|
+
* it as an unguarded pass-through.
|
|
22
|
+
*
|
|
23
|
+
* The resolver performs NO I/O beyond the collaborators' own lazy probes —
|
|
24
|
+
* the authorization, the intent reader (flag-first) and the auto-submission
|
|
25
|
+
* probe all consult the workspace consent ledger / config per call, so a
|
|
26
|
+
* long-lived host keeps observing the latest Owner decisions.
|
|
27
|
+
*/
|
|
28
|
+
import { type EffectivePdConfig, type IntentDocReader, type SourceMaterialAuthorizationPort, type SourceMaterialHostKind, type TelemetryEvent, type TrajectoryTurnReader } from '@principles/core/runtime';
|
|
29
|
+
/** The five host collaborators a workspace pipeline entry must carry. */
|
|
30
|
+
export interface WorkspacePipelineHostDeps {
|
|
31
|
+
/** PRI-1230 / SPEC §9.2: neutral INTENT.md reader, flag-first on the entry-provided config. */
|
|
32
|
+
readonly intentDocReader: IntentDocReader;
|
|
33
|
+
/** PRI-1265: consent-tiered trajectory turns (default governance reader or the host override). */
|
|
34
|
+
readonly trajectoryTurnReader: TrajectoryTurnReader;
|
|
35
|
+
/** PRI-1283 R2: the SAME authorization instance the default trajectory reader was built with. */
|
|
36
|
+
readonly sourceMaterialAuthorization: SourceMaterialAuthorizationPort;
|
|
37
|
+
/** PRI-939 Option A: workspace-scoped sink (allowlist persistence + singleton forwarding). */
|
|
38
|
+
readonly telemetrySink: {
|
|
39
|
+
emitTelemetry: (event: TelemetryEvent) => void;
|
|
40
|
+
};
|
|
41
|
+
/** Pain Ingress SPEC §9.6: lazy `automatic_pain_submission` probe (revocation-safe). */
|
|
42
|
+
readonly isAutoPainSubmissionAuthorized: () => boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface ResolveWorkspacePipelineHostDepsInput {
|
|
45
|
+
readonly workspaceDir: string;
|
|
46
|
+
/** The CURRENT entry's effective config — the intent reader's flag authority (SPEC §13.1). */
|
|
47
|
+
readonly effectiveConfig: EffectivePdConfig;
|
|
48
|
+
/**
|
|
49
|
+
* OpenClaw Gateway hook / command processes already hold
|
|
50
|
+
* `WorkspaceContext.trajectory`; pass it here to replace the default
|
|
51
|
+
* governance reader. The resolver wraps it in live authorization checks;
|
|
52
|
+
* the authorization instance is still created and returned for gate consumers.
|
|
53
|
+
*/
|
|
54
|
+
readonly trajectoryTurnReaderOverride?: TrajectoryTurnReader;
|
|
55
|
+
/** Host whose consent governs the override's conversation material. Required with an override. */
|
|
56
|
+
readonly trajectoryTurnReaderOverrideHostKind?: SourceMaterialHostKind;
|
|
57
|
+
/**
|
|
58
|
+
* Host-specific LIVE access probe for a legacy/in-process reader. Called on
|
|
59
|
+
* every read; omitting it uses the consent-ledger port for hostKind.
|
|
60
|
+
*/
|
|
61
|
+
readonly trajectoryTurnReaderOverrideAuthorization?: () => boolean;
|
|
62
|
+
/** Optional host-specific observable channel for critical-event persistence failures. */
|
|
63
|
+
readonly telemetryPersistenceFailureHandler?: (detail: string) => void;
|
|
64
|
+
}
|
|
65
|
+
export declare function resolveWorkspacePipelineHostDeps(input: ResolveWorkspacePipelineHostDepsInput): WorkspacePipelineHostDeps;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPEC-PD-PIPELINE-SPINE-001 §4.2 — the single workspace pipeline host
|
|
3
|
+
* collaborator assembly point (PRI-1292 Phase 2A).
|
|
4
|
+
*
|
|
5
|
+
* Before this module, eight entry points each assembled the five host
|
|
6
|
+
* collaborators by hand, and the diagnostician entries created TWO separate
|
|
7
|
+
* `createConsentLedgerSourceMaterialAuthorization` instances per call — one
|
|
8
|
+
* inside the governance trajectory reader, one passed to the bridge — so the
|
|
9
|
+
* trajectory read and the source-material gate could observe different consent
|
|
10
|
+
* states within a single assembly. This resolver guarantees:
|
|
11
|
+
*
|
|
12
|
+
* 1. All five collaborators are REQUIRED on the returned object (no `?`),
|
|
13
|
+
* so a new entry cannot compile with a silently missing sink or probe.
|
|
14
|
+
* 2. The default `trajectoryTurnReader` and the returned
|
|
15
|
+
* `sourceMaterialAuthorization` share ONE consent-ledger authorization
|
|
16
|
+
* instance — trajectory reads and gate decisions are always consistent.
|
|
17
|
+
* 3. A host that already holds an in-process trajectory reader (OpenClaw
|
|
18
|
+
* Gateway `WorkspaceContext.trajectory`) passes it as
|
|
19
|
+
* `trajectoryTurnReaderOverride` instead of rebuilding one; the resolver
|
|
20
|
+
* wraps that reader in a live authorization probe rather than returning
|
|
21
|
+
* it as an unguarded pass-through.
|
|
22
|
+
*
|
|
23
|
+
* The resolver performs NO I/O beyond the collaborators' own lazy probes —
|
|
24
|
+
* the authorization, the intent reader (flag-first) and the auto-submission
|
|
25
|
+
* probe all consult the workspace consent ledger / config per call, so a
|
|
26
|
+
* long-lived host keeps observing the latest Owner decisions.
|
|
27
|
+
*/
|
|
28
|
+
import { storeEmitter, } from '@principles/core/runtime';
|
|
29
|
+
import { isAutomaticPainSubmissionAuthorized } from './auto-pain-authorization.js';
|
|
30
|
+
import { createGovernanceTrajectoryTurnReader } from './governance-trajectory-turn-reader.js';
|
|
31
|
+
import { createHostIntentDocReader } from './intent-doc-reader.js';
|
|
32
|
+
import { createConsentLedgerSourceMaterialAuthorization } from './source-material-authorization.js';
|
|
33
|
+
import { WorkspaceTelemetryEmitter } from './workspace-telemetry-emitter.js';
|
|
34
|
+
function emptyExactTurns() {
|
|
35
|
+
return { userTurns: [], assistantTurns: [] };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A host-provided reader is still conversation-material access. Wrap it in
|
|
39
|
+
* the same live consent decision as the default governance reader; every
|
|
40
|
+
* method re-checks the ledger per call, so revocation takes effect immediately.
|
|
41
|
+
*/
|
|
42
|
+
function authorizeTrajectoryTurnReaderOverride(input) {
|
|
43
|
+
const authorized = () => input.overrideAuthorization?.() ?? input.authorization.isHostSourceMaterialAuthorized(input.hostKind).authorized;
|
|
44
|
+
const wrapped = {
|
|
45
|
+
listUserTurnsForSession: (sessionId) => authorized() ? input.reader.listUserTurnsForSession(sessionId) : [],
|
|
46
|
+
listAssistantTurns: (sessionId) => authorized() ? input.reader.listAssistantTurns(sessionId) : [],
|
|
47
|
+
};
|
|
48
|
+
if (input.reader.listTurnTextsForHostTurnId !== undefined) {
|
|
49
|
+
wrapped.listTurnTextsForHostTurnId = (sessionId, hostTurnId, hostKindArg) => authorized()
|
|
50
|
+
? input.reader.listTurnTextsForHostTurnId?.(sessionId, hostTurnId, hostKindArg) ?? emptyExactTurns()
|
|
51
|
+
: emptyExactTurns();
|
|
52
|
+
}
|
|
53
|
+
return wrapped;
|
|
54
|
+
}
|
|
55
|
+
export function resolveWorkspacePipelineHostDeps(input) {
|
|
56
|
+
// ONE authorization instance per assembly: the default governance
|
|
57
|
+
// trajectory reader and every gate consumer returned to the caller observe
|
|
58
|
+
// the SAME latest-consent state (the double-instance defect this module
|
|
59
|
+
// exists to remove).
|
|
60
|
+
const sourceMaterialAuthorization = createConsentLedgerSourceMaterialAuthorization(input.workspaceDir);
|
|
61
|
+
const overrideHostKind = input.trajectoryTurnReaderOverrideHostKind;
|
|
62
|
+
if (input.trajectoryTurnReaderOverride !== undefined && overrideHostKind === undefined) {
|
|
63
|
+
throw new Error('trajectoryTurnReaderOverrideHostKind is required when trajectoryTurnReaderOverride is provided');
|
|
64
|
+
}
|
|
65
|
+
const trajectoryTurnReader = input.trajectoryTurnReaderOverride !== undefined && overrideHostKind !== undefined
|
|
66
|
+
? authorizeTrajectoryTurnReaderOverride({
|
|
67
|
+
reader: input.trajectoryTurnReaderOverride,
|
|
68
|
+
authorization: sourceMaterialAuthorization,
|
|
69
|
+
hostKind: overrideHostKind,
|
|
70
|
+
...(input.trajectoryTurnReaderOverrideAuthorization === undefined
|
|
71
|
+
? {}
|
|
72
|
+
: { overrideAuthorization: input.trajectoryTurnReaderOverrideAuthorization }),
|
|
73
|
+
})
|
|
74
|
+
: createGovernanceTrajectoryTurnReader({
|
|
75
|
+
workspaceDir: input.workspaceDir,
|
|
76
|
+
sourceMaterialAuthorization,
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
intentDocReader: createHostIntentDocReader({
|
|
80
|
+
workspaceDir: input.workspaceDir,
|
|
81
|
+
effectiveConfig: input.effectiveConfig,
|
|
82
|
+
}),
|
|
83
|
+
trajectoryTurnReader,
|
|
84
|
+
sourceMaterialAuthorization,
|
|
85
|
+
// Same workspace-scoped semantics as the CLI wrapper: allowlisted critical
|
|
86
|
+
// events persist to <workspace>/.pd/telemetry/critical-events.jsonl and
|
|
87
|
+
// every event still forwards to the storeEmitter singleton. Persist
|
|
88
|
+
// failures degrade to stderr — never break the caller (PRI-634 contract).
|
|
89
|
+
telemetrySink: new WorkspaceTelemetryEmitter(storeEmitter, input.workspaceDir, input.telemetryPersistenceFailureHandler ?? ((detail) => {
|
|
90
|
+
process.stderr.write(`[PD:telemetry] WARNING: critical event persistence failed: ${detail}\n`);
|
|
91
|
+
})),
|
|
92
|
+
isAutoPainSubmissionAuthorized: () => isAutomaticPainSubmissionAuthorized(input.workspaceDir),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -43,6 +43,10 @@ import { StoreEventEmitter } from '@principles/core/runtime';
|
|
|
43
43
|
* (PRI-1146 P1-01:低频 skip/degradation 取证 — 前者记录 ledger 不可证明
|
|
44
44
|
* 时 canonical association 为何保持 unresolved,后者是 replay review skip
|
|
45
45
|
* 的唯一持久记录;见 Set 内注释)
|
|
46
|
+
* - diag_rootcause_intent_doc_template_only / diag_rootcause_intent_doc_read_failed
|
|
47
|
+
* (PRI-1287:Intent 链降级到 not_configured 的唯一可取证记录 — 无快照时
|
|
48
|
+
* relevance 恒为 not_configured;reason 区分「标题从未被识别」与「模板未
|
|
49
|
+
* 填写」,两者需要完全相反的 Owner 动作)
|
|
46
50
|
*
|
|
47
51
|
* 落点 `<workspaceDir>/.pd/telemetry/critical-events.jsonl`(JSONL,一行一
|
|
48
52
|
* 事件,含完整 TelemetryEvent)。同步 append:事件量小(allowlist 限流),
|
|
@@ -72,6 +76,16 @@ const CRITICAL_EVENT_ALLOWLIST = new Set([
|
|
|
72
76
|
// (its only durable record — the candidate row itself carries no skip reason).
|
|
73
77
|
'diag_router_trusted_context_unavailable',
|
|
74
78
|
'replay_review_source_invalid',
|
|
79
|
+
// PRI-1287 (rc-9): the Intent chain's degradation evidence. Stage A has been
|
|
80
|
+
// emitting these since #2663, but production runners ride the unsubscribed
|
|
81
|
+
// storeEmitter singleton and the events were absent from this allowlist — an
|
|
82
|
+
// emitted degradation and a silent one looked identical to the Owner. That is
|
|
83
|
+
// how an entire Intent chain could degrade to `not_configured` for weeks
|
|
84
|
+
// (found by PRI-1284) with nothing to inspect afterwards. Low frequency: at
|
|
85
|
+
// most one line per diagnosis that could not anchor, plus its reason
|
|
86
|
+
// (`no_parsed_section` vs `placeholder_only`) and nextAction.
|
|
87
|
+
'diag_rootcause_intent_doc_template_only',
|
|
88
|
+
'diag_rootcause_intent_doc_read_failed',
|
|
75
89
|
]);
|
|
76
90
|
export class WorkspaceTelemetryEmitter extends StoreEventEmitter {
|
|
77
91
|
upstream;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/host-runtime",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.1",
|
|
4
4
|
"description": "Shared host-neutral orchestration for Principles Disciple MVP-Core hook paths.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"lint": "eslint \"src/**/*.ts\""
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@principles/core": "^8.
|
|
43
|
-
"@principles/install-layout": "^0.
|
|
42
|
+
"@principles/core": "^8.3.0",
|
|
43
|
+
"@principles/install-layout": "^0.11.1",
|
|
44
44
|
"better-sqlite3": "^13.0.3",
|
|
45
45
|
"js-yaml": "^5.4.3"
|
|
46
46
|
},
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"url": "git+https://github.com/csuzngjh/principles.git"
|
|
58
58
|
},
|
|
59
59
|
"license": "Apache-2.0",
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "16f7e15c5832284db3836b8babed2b7980bca8c9"
|
|
61
61
|
}
|