@principles/host-runtime 4.7.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 +20 -14
- 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. */
|
|
@@ -105,6 +103,18 @@ export async function runPendingDiagnosticianOnce(options) {
|
|
|
105
103
|
try {
|
|
106
104
|
let releaseBridge;
|
|
107
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
|
+
});
|
|
108
118
|
const bridge = await createPainSignalBridge({
|
|
109
119
|
workspaceDir: options.workspaceDir,
|
|
110
120
|
stateDir,
|
|
@@ -112,19 +122,15 @@ export async function runPendingDiagnosticianOnce(options) {
|
|
|
112
122
|
owner: options.owner ?? DIAGNOSTICIAN_AUTO_RUN_OWNER,
|
|
113
123
|
effectiveConfig: config.effective,
|
|
114
124
|
getEnvVar: options.getEnvVar ?? ((name) => process.env[name]),
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// like every other diagnosis entry.
|
|
122
|
-
trajectoryTurnReader: createGovernanceTrajectoryTurnReader({ workspaceDir: options.workspaceDir, sourceMaterialAuthorization: createConsentLedgerSourceMaterialAuthorization(options.workspaceDir) }),
|
|
123
|
-
// PRI-1283 R2: latest-consent gate consulted per assembly / model call.
|
|
124
|
-
sourceMaterialAuthorization: createConsentLedgerSourceMaterialAuthorization(options.workspaceDir),
|
|
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,
|
|
125
131
|
// SPEC §9.6: lazy probe — a flag revoked between candidate pick and
|
|
126
132
|
// execution still stops the run at the bridge boundary.
|
|
127
|
-
isAutoPainSubmissionAuthorized:
|
|
133
|
+
isAutoPainSubmissionAuthorized: hostDeps.isAutoPainSubmissionAuthorized,
|
|
128
134
|
}, (release) => { releaseBridge = release; });
|
|
129
135
|
const executed = await bridge.executePendingDiagnosis({ taskId: candidate.taskId });
|
|
130
136
|
if (executed.status === 'failed') {
|
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.7.
|
|
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.11.
|
|
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
|
}
|