@principles/host-runtime 4.7.1 → 4.8.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/codex-worker-status.d.ts +6 -4
- package/dist/codex-worker-status.js +7 -5
- package/dist/diagnostician-auto-run.js +2 -2
- package/dist/governance-signal-admission.d.ts +2 -1
- package/dist/governance-signal-admission.js +2 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +16 -2
- package/dist/internalization-consumer-cycle.d.ts +12 -4
- package/dist/internalization-consumer-cycle.js +103 -99
- package/dist/internalization-consumer-governance.d.ts +4 -3
- package/dist/internalization-consumer-governance.js +17 -41
- package/dist/internalization-task-executor.d.ts +127 -0
- package/dist/internalization-task-executor.js +121 -0
- package/dist/workbuddy-worker-status.d.ts +6 -3
- package/dist/workbuddy-worker-status.js +7 -4
- package/dist/workspace-telemetry-emitter.js +1 -1
- package/package.json +4 -4
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
* manifest registration). codex-adapter re-exports it for compatibility.
|
|
7
7
|
*
|
|
8
8
|
* SPEC §15 worker mode, evaluated WITHOUT executing anything (no lease, no
|
|
9
|
-
* LLM, no transcript I/O). `manual_action_required` means
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* LLM, no transcript I/O). `manual_action_required` means this workspace is
|
|
10
|
+
* not registered in the canonical install manifest, so the PD Service Host —
|
|
11
|
+
* the only background runtime, triggered by the OS scheduler — never
|
|
12
|
+
* discovers it and no automatic worker cycles run for it. The manual CLI
|
|
13
|
+
* path (catch-up / diagnose / run-once) is the recovery route. 'ready' here
|
|
14
|
+
* means "an automatic worker would run and hold the workspace task leases";
|
|
13
15
|
* live-worker liveness surfacing belongs to the Slice D health surface.
|
|
14
16
|
*/
|
|
15
17
|
export type CodexWorkerMode = 'ready' | 'manual_action_required' | 'paused' | 'degraded';
|
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
* manifest registration). codex-adapter re-exports it for compatibility.
|
|
7
7
|
*
|
|
8
8
|
* SPEC §15 worker mode, evaluated WITHOUT executing anything (no lease, no
|
|
9
|
-
* LLM, no transcript I/O). `manual_action_required` means
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* LLM, no transcript I/O). `manual_action_required` means this workspace is
|
|
10
|
+
* not registered in the canonical install manifest, so the PD Service Host —
|
|
11
|
+
* the only background runtime, triggered by the OS scheduler — never
|
|
12
|
+
* discovers it and no automatic worker cycles run for it. The manual CLI
|
|
13
|
+
* path (catch-up / diagnose / run-once) is the recovery route. 'ready' here
|
|
14
|
+
* means "an automatic worker would run and hold the workspace task leases";
|
|
13
15
|
* live-worker liveness surfacing belongs to the Slice D health surface.
|
|
14
16
|
*/
|
|
15
17
|
import * as fs from 'node:fs';
|
|
@@ -45,7 +47,7 @@ export function computeCodexWorkerStatusMode(input) {
|
|
|
45
47
|
return {
|
|
46
48
|
mode: 'manual_action_required',
|
|
47
49
|
reason: 'workspace_not_in_install_manifest',
|
|
48
|
-
nextAction: `
|
|
50
|
+
nextAction: `This workspace is not registered in the canonical install manifest, so the PD Service Host does not manage automatic worker cycles for it. Re-run the Codex setup flow to register it. Manual path: pd codex ingest catch-up --workspace "${workspaceDir}", then pd diagnose / pd runtime internalization run-once.`,
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
53
|
return { mode: 'ready' };
|
|
@@ -53,8 +53,8 @@ export async function runPendingDiagnosticianOnce(options) {
|
|
|
53
53
|
return {
|
|
54
54
|
served: false,
|
|
55
55
|
reason: 'service_not_running',
|
|
56
|
-
message: 'the
|
|
57
|
-
nextAction: '
|
|
56
|
+
message: 'the internalization consumer cycle is not running in this workspace',
|
|
57
|
+
nextAction: 'Verify the PD Service Host is enabled (pd service status), or diagnose from Console (L2) which does not need a worker cycle.',
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
const config = loadPdConfigForPlugin(options.workspaceDir);
|
|
@@ -463,7 +463,8 @@ export interface ReconcileGovernanceContinuationResult {
|
|
|
463
463
|
* while conversation-ingestion consent is enabled;
|
|
464
464
|
* - Case D: promotion started → pending tail → retry completion once; stale
|
|
465
465
|
* tails are reported (never silently dropped).
|
|
466
|
-
* Not a background worker —
|
|
466
|
+
* Not a background worker — the Service-Host-spawned workspace workers and
|
|
467
|
+
* the CLI call this.
|
|
467
468
|
*/
|
|
468
469
|
export declare function reconcileGovernanceContinuation(input: ReconcileGovernanceContinuationInput): Promise<ReconcileGovernanceContinuationResult>;
|
|
469
470
|
export interface GovernanceAdmissionCounts {
|
|
@@ -2278,7 +2278,8 @@ export async function ensureGovernanceContinuation(input) {
|
|
|
2278
2278
|
* while conversation-ingestion consent is enabled;
|
|
2279
2279
|
* - Case D: promotion started → pending tail → retry completion once; stale
|
|
2280
2280
|
* tails are reported (never silently dropped).
|
|
2281
|
-
* Not a background worker —
|
|
2281
|
+
* Not a background worker — the Service-Host-spawned workspace workers and
|
|
2282
|
+
* the CLI call this.
|
|
2282
2283
|
*/
|
|
2283
2284
|
export async function reconcileGovernanceContinuation(input) {
|
|
2284
2285
|
const workspaceDir = path.resolve(input.workspaceDir);
|
package/dist/index.d.ts
CHANGED
|
@@ -32,7 +32,10 @@ export * from './adaptive-background-append.js';
|
|
|
32
32
|
export * from './signal-stage2-cycle.js';
|
|
33
33
|
export * from './host-liveness-contract.js';
|
|
34
34
|
export * from './internalization-consumer-governance.js';
|
|
35
|
-
export
|
|
35
|
+
export { INTERNALIZATION_AUTO_CONSUMER_FLAG_ID, orderKindsByOldestReadyStage, oldestReadyAgeMs, runInternalizationConsumerCycle, } from './internalization-consumer-cycle.js';
|
|
36
|
+
export type { ConsumerCycleLogger, ConsumerHostToolCatalog, InternalizationConsumerCyclePorts, InternalizationConsumerCycleOutcome, InternalizationConsumerCycleSignals, } from './internalization-consumer-cycle.js';
|
|
37
|
+
export { executeSelectedInternalizationTask, } from './internalization-task-executor.js';
|
|
38
|
+
export type { ExecuteSelectedInternalizationTaskInput, SelectedInternalizationTaskRunResult, SelectedInternalizationTaskRunnerOptions, } from './internalization-task-executor.js';
|
|
36
39
|
export * from './adaptive-consumer-schedule.js';
|
|
37
40
|
export * from './diagnostician-auto-run.js';
|
|
38
41
|
export * from './workspace-pipeline-host-deps.js';
|
package/dist/index.js
CHANGED
|
@@ -62,9 +62,23 @@ export * from './adaptive-background-append.js';
|
|
|
62
62
|
export * from './signal-stage2-cycle.js';
|
|
63
63
|
export * from './host-liveness-contract.js';
|
|
64
64
|
// PRI-624 Slice C: shared internalization consumer execution (OpenClaw
|
|
65
|
-
// auto-consumer +
|
|
65
|
+
// auto-consumer + Service-Host-spawned workspace workers call the same cycle).
|
|
66
66
|
export * from './internalization-consumer-governance.js';
|
|
67
|
-
export
|
|
67
|
+
// PRI-1293 R3 (export surface tightening): explicit whitelist instead of
|
|
68
|
+
// `export *` — the public API is the consumer cycle entry, the selected-task
|
|
69
|
+
// executor entry, and their necessary input/output types. The internal
|
|
70
|
+
// assembly helper types (SelectedTaskTelemetryEmitter /
|
|
71
|
+
// SelectedInternalizationTaskBaseDeps / SelectedEvaluatorRepairDeps /
|
|
72
|
+
// SelectedRolloutGovernanceDeps) stay module-exported for in-package wiring
|
|
73
|
+
// but are NOT part of the package public API: they are composition details
|
|
74
|
+
// of the input union, and callers construct them structurally.
|
|
75
|
+
// SelectedInternalizationTaskRunnerOptions IS public — pd-cli run-once
|
|
76
|
+
// constructs it directly (verified cross-package consumer).
|
|
77
|
+
// PRI-1301: the executor entries re-export from the executor module
|
|
78
|
+
// (pure move — identical symbol names/types; the cycle entries stay
|
|
79
|
+
// sourced from the consumer cycle module).
|
|
80
|
+
export { INTERNALIZATION_AUTO_CONSUMER_FLAG_ID, orderKindsByOldestReadyStage, oldestReadyAgeMs, runInternalizationConsumerCycle, } from './internalization-consumer-cycle.js';
|
|
81
|
+
export { executeSelectedInternalizationTask, } from './internalization-task-executor.js';
|
|
68
82
|
// SPEC-PD-PIPELINE-RELIABILITY-AND-EFFICIENCY-001 §4: pure adaptive schedule
|
|
69
83
|
// policy for the existing consumer timer chain (no new background service).
|
|
70
84
|
export * from './adaptive-consumer-schedule.js';
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Extracted verbatim from openclaw-plugin's
|
|
5
5
|
* `internalization-auto-consumer-service.ts` `runConsumerCycle` so that the
|
|
6
|
-
* OpenClaw auto-consumer scheduler and the
|
|
6
|
+
* OpenClaw auto-consumer scheduler and the Service-Host-spawned workspace
|
|
7
|
+
* workers call
|
|
7
8
|
* ONE downstream execution implementation (SPEC §13: "reusing existing
|
|
8
|
-
* downstream consumer logic" —
|
|
9
|
+
* downstream consumer logic" — no host worker may copy it):
|
|
9
10
|
*
|
|
10
11
|
* flag gate → config/runtime config → state handle → orchestrator(dryRun)
|
|
11
12
|
* → queue read model → consumer decision → wakeOnce loop → adapter
|
|
@@ -14,7 +15,8 @@
|
|
|
14
15
|
*
|
|
15
16
|
* The lease is acquired INSIDE runner.run by the Runtime lease manager
|
|
16
17
|
* (persisted in `<workspace>/.pd/state.db`, cross-process safe) — this cycle
|
|
17
|
-
* never leases by itself, so two schedulers (OpenClaw +
|
|
18
|
+
* never leases by itself, so two schedulers (OpenClaw + Service Host worker)
|
|
19
|
+
* racing on
|
|
18
20
|
* one workspace converge to exactly-once execution via lease_conflict.
|
|
19
21
|
*
|
|
20
22
|
* Hosts inject: a logger, a structured-event sink, their tool catalog, and an
|
|
@@ -34,7 +36,13 @@ export interface ConsumerHostToolCatalog {
|
|
|
34
36
|
readonly writeTools: readonly string[];
|
|
35
37
|
}
|
|
36
38
|
export interface InternalizationConsumerCyclePorts {
|
|
37
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Runner-owner label recorded on leases ('auto-consumer' |
|
|
41
|
+
* 'service-host-worker' | …). PRI-1278 Phase 5: 'service-host-worker' is
|
|
42
|
+
* the current workspace-worker identity; leases persisted before the
|
|
43
|
+
* Companion-runtime removal may still carry the retired 'companion-worker'
|
|
44
|
+
* label — historical records are never migrated.
|
|
45
|
+
*/
|
|
38
46
|
readonly owner: string;
|
|
39
47
|
readonly logger: ConsumerCycleLogger;
|
|
40
48
|
/** Structured event sink (OpenClaw: SystemLogger.log; worker: its own log). */
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Extracted verbatim from openclaw-plugin's
|
|
5
5
|
* `internalization-auto-consumer-service.ts` `runConsumerCycle` so that the
|
|
6
|
-
* OpenClaw auto-consumer scheduler and the
|
|
6
|
+
* OpenClaw auto-consumer scheduler and the Service-Host-spawned workspace
|
|
7
|
+
* workers call
|
|
7
8
|
* ONE downstream execution implementation (SPEC §13: "reusing existing
|
|
8
|
-
* downstream consumer logic" —
|
|
9
|
+
* downstream consumer logic" — no host worker may copy it):
|
|
9
10
|
*
|
|
10
11
|
* flag gate → config/runtime config → state handle → orchestrator(dryRun)
|
|
11
12
|
* → queue read model → consumer decision → wakeOnce loop → adapter
|
|
@@ -14,19 +15,27 @@
|
|
|
14
15
|
*
|
|
15
16
|
* The lease is acquired INSIDE runner.run by the Runtime lease manager
|
|
16
17
|
* (persisted in `<workspace>/.pd/state.db`, cross-process safe) — this cycle
|
|
17
|
-
* never leases by itself, so two schedulers (OpenClaw +
|
|
18
|
+
* never leases by itself, so two schedulers (OpenClaw + Service Host worker)
|
|
19
|
+
* racing on
|
|
18
20
|
* one workspace converge to exactly-once execution via lease_conflict.
|
|
19
21
|
*
|
|
20
22
|
* Hosts inject: a logger, a structured-event sink, their tool catalog, and an
|
|
21
23
|
* env getter. Everything else is the existing production path.
|
|
22
24
|
*/
|
|
23
|
-
import { createRuntimeStateHandle, InternalizationOrchestrator,
|
|
25
|
+
import { createRuntimeStateHandle, InternalizationOrchestrator, buildArtificerHostSemanticContext,
|
|
26
|
+
// PRI-1301: 六种 Peer Runner 与 Default<X>Validator 的 executor 专用导入
|
|
27
|
+
// 已随执行器本体迁往 ./internalization-task-executor.js — 本文件只保留
|
|
28
|
+
// ArtificerL2Adapter 装配自用的 DefaultArtificerValidator。
|
|
29
|
+
DefaultArtificerValidator, PiAiRuntimeAdapter, L2AgentLoopAdapter, ArtificerL2Adapter, buildL2PrincipleReaderFromLedger, storeEmitter, createProductionGateDeps, resolveRuntimeConfigFromPdConfig, resolveRuntimeConfigForAgent, AGENT_NAME_FOR_TASK_KIND, isRuntimeConfigError, computeConsumerDecision, FULL_CHAIN_CONSUMER_RUNNER_KINDS, DEFAULT_CONSUMER_RUNNER_KINDS, InternalizationQueueReadModel, MVP_CORE_TASK_KINDS, SqliteConnection, SqliteReconciliationCursorStore, SUCCEEDED_TRANSITIONS_SCOPE,
|
|
24
30
|
// PRI-714: resolve outputLanguage from the same effective config the
|
|
25
31
|
// runners already receive (EP-07: canonical resolved value, not raw input).
|
|
26
32
|
resolveOutputLanguage, hydratePITaskRecord, preflightArtificerOwnerEvidence, preflightArtificerIntentBasis, consumeSourceFaultBackoffSkip, advanceSourceFaultBackoff, } from '@principles/core/runtime';
|
|
27
33
|
import { loadLedger } from '@principles/core/principle-tree-ledger';
|
|
28
34
|
import { loadPdConfigForPlugin, loadFeatureFlagFromConfig } from './pd-config.js';
|
|
29
35
|
import { createEvaluatorRepairDeps, createRolloutGovernanceDeps } from './internalization-consumer-governance.js';
|
|
36
|
+
// PRI-1301: 单步 Runner 执行器唯一权威实现 (PRI-1293 Phase 2B 收编本体)
|
|
37
|
+
// 独立成模块 — 本 cycle 只做选择/调度/装配, 构造执行经同一入口。
|
|
38
|
+
import { executeSelectedInternalizationTask } from './internalization-task-executor.js';
|
|
30
39
|
import { WorkspaceTelemetryEmitter } from './workspace-telemetry-emitter.js';
|
|
31
40
|
import { createConsentLedgerSourceMaterialAuthorization } from './source-material-authorization.js';
|
|
32
41
|
export const INTERNALIZATION_AUTO_CONSUMER_FLAG_ID = 'internalization_auto_consumer';
|
|
@@ -158,7 +167,16 @@ async function runReconciliationBudget(workspaceDir, orchestrator, ports) {
|
|
|
158
167
|
cursorStore.set(SUCCEEDED_TRANSITIONS_SCOPE, recon.nextCursor);
|
|
159
168
|
}
|
|
160
169
|
const errors = recon.outcomes.filter((o) => o.decision.startsWith('reconcile_error'));
|
|
161
|
-
|
|
170
|
+
// PRI-1293 R6: fail-closed 错误类别 (血缘拒绝/并发冲突/完整性冲突/
|
|
171
|
+
// repair reopen 失败/元数据损坏) 的完整排障信息必须进遥测 — 不得
|
|
172
|
+
// 只留下 blocked 计数而静默丢弃拒绝原因。
|
|
173
|
+
const REFUSAL_DECISIONS = new Set([
|
|
174
|
+
'lineage_refused', 'concurrent_modification', 'successor_integrity_conflict',
|
|
175
|
+
'successor_id_conflict', 'revision_reopen_failed', 'invalid_task_metadata',
|
|
176
|
+
'source_correction_reopen_failed',
|
|
177
|
+
]);
|
|
178
|
+
const refusals = recon.outcomes.filter((o) => REFUSAL_DECISIONS.has(o.decision));
|
|
179
|
+
if (recon.recovered > 0 || errors.length > 0 || refusals.length > 0) {
|
|
162
180
|
emitEvent('INTERNALIZATION_CONSUMER_RECONCILED', JSON.stringify({
|
|
163
181
|
scanned: recon.scanned,
|
|
164
182
|
recovered: recon.recovered,
|
|
@@ -168,6 +186,7 @@ async function runReconciliationBudget(workspaceDir, orchestrator, ports) {
|
|
|
168
186
|
recoveries: recon.outcomes.filter((o) => o.decision === 'successor_created' || o.decision.includes('reopened')),
|
|
169
187
|
// P1 (最终复核): per-task 错误显式可观测 — 即使 recovered=0
|
|
170
188
|
errors,
|
|
189
|
+
refusals,
|
|
171
190
|
}));
|
|
172
191
|
logger.info(`[PD:${logLabel}] Reconciliation: recovered=${recon.recovered} errors=${errors.length} wrapped=${recon.wrappedAround}`);
|
|
173
192
|
}
|
|
@@ -185,6 +204,14 @@ async function runReconciliationBudget(workspaceDir, orchestrator, ports) {
|
|
|
185
204
|
logger.warn(`[PD:${logLabel}] Succeeded-transition reconciliation failed: ${String(reconErr)}`);
|
|
186
205
|
}
|
|
187
206
|
}
|
|
207
|
+
// ════════════════════════════════════════════════════════════════════════════
|
|
208
|
+
// PRI-1293 Phase 2B / PRI-1301 — 共享单步 Runner 执行器已独立成模块
|
|
209
|
+
// (SPEC-PD-PIPELINE-SPINE-001 §3.5): 六种 Peer Runner 构造+执行的唯一权威
|
|
210
|
+
// 实现见 `./internalization-task-executor.js` (纯移动, 逐字等价)。
|
|
211
|
+
// 本文件保留 consumer cycle 职责 — 任务发现/选择/调度、per-kind runtime
|
|
212
|
+
// profile 解析、adapter/L2 路由、preflight、输入装配、后继提交、恢复
|
|
213
|
+
// sweep 与 reconciliation 预算; Runner 构造本体不在这里。
|
|
214
|
+
// ════════════════════════════════════════════════════════════════════════════
|
|
188
215
|
/**
|
|
189
216
|
* Run ONE bounded consumer cycle for a workspace. At most one downstream task
|
|
190
217
|
* is leased and executed per cycle (DEFAULT_CONSUMER_MAX_TASKS_PER_CYCLE=1);
|
|
@@ -735,126 +762,80 @@ async function executeConsumerCycle(workspaceDir, ports, signals) {
|
|
|
735
762
|
// degrade through the host's structured event port, never break the runner.
|
|
736
763
|
// (PRI-795 review P1: the emitter itself is constructed above, before the
|
|
737
764
|
// adapter dispatch, so the ArtificerL2 adapter can share it.)
|
|
765
|
+
// PRI-1293 Phase 2B: 构造执行器输入并交由唯一权威实现执行。逐 kind 的
|
|
766
|
+
// 差异只剩「哪些类型化依赖由本入口提供」(eventEmitter 选择、evidence
|
|
767
|
+
// pack、repair/governance 接线、宿主目录/语义投影) — Runner 构造本体
|
|
768
|
+
// 收编进 executeSelectedInternalizationTask。
|
|
738
769
|
// Dispatch by leased task kind. Only kinds listed in
|
|
739
770
|
// FULL_CHAIN_CONSUMER_RUNNER_KINDS can be leased here; anything else
|
|
740
771
|
// (e.g. diagnostician) hits the default branch — fail loud if it does (EP-03).
|
|
741
|
-
let
|
|
772
|
+
let executionInput = null;
|
|
742
773
|
switch (taskKind) {
|
|
743
774
|
case 'dreamer':
|
|
744
|
-
|
|
775
|
+
executionInput = {
|
|
776
|
+
taskKind, taskId, workspaceDir, stateManager, runtimeAdapter: adapter,
|
|
777
|
+
eventEmitter: storeEmitter, artifactStore: stateManager.piArtifactStore, runnerOptions,
|
|
778
|
+
};
|
|
745
779
|
break;
|
|
746
780
|
case 'philosopher':
|
|
747
|
-
|
|
781
|
+
executionInput = {
|
|
782
|
+
taskKind, taskId, workspaceDir, stateManager, runtimeAdapter: adapter,
|
|
783
|
+
eventEmitter: storeEmitter, artifactStore: stateManager.piArtifactStore, runnerOptions,
|
|
784
|
+
};
|
|
748
785
|
break;
|
|
749
786
|
case 'scribe':
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
// dreamer task seed's candidateId) onto the artifact it writes, so
|
|
755
|
-
// the dispatcher's ledger identity gate sees a resolvable
|
|
756
|
-
// identity on the live production chain. listForCandidate reads
|
|
757
|
-
// the ledger from disk per call — no cross-cycle staleness.
|
|
758
|
-
ledgerIdentity: {
|
|
759
|
-
resolveForCandidate: async (candidateId) => {
|
|
760
|
-
const candidate = await stateManager.getCandidate(candidateId);
|
|
761
|
-
return new PrincipleTreeLedgerAdapter({ stateDir: `${workspaceDir}/.state` }).resolveCandidatePrincipleIdentity(candidateId, candidate?.rawRecommendationKind);
|
|
762
|
-
},
|
|
763
|
-
// PRI-915: availability first — an unreadable ledger must not
|
|
764
|
-
// read as an unresolved chain.
|
|
765
|
-
isAvailable: () => new PrincipleTreeLedgerAdapter({ stateDir: `${workspaceDir}/.state` }).isAvailable(),
|
|
766
|
-
listForCandidate: (candidateId) => new PrincipleTreeLedgerAdapter({ stateDir: `${workspaceDir}/.state` }).listForCandidate(candidateId),
|
|
767
|
-
},
|
|
768
|
-
}, runnerOptions);
|
|
787
|
+
executionInput = {
|
|
788
|
+
taskKind, taskId, workspaceDir, stateManager, runtimeAdapter: adapter,
|
|
789
|
+
eventEmitter: storeEmitter, artifactStore: stateManager.piArtifactStore, runnerOptions,
|
|
790
|
+
};
|
|
769
791
|
break;
|
|
770
792
|
case 'artificer':
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
const candidate = await stateManager.getCandidate(candidateId);
|
|
775
|
-
return new PrincipleTreeLedgerAdapter({ stateDir: `${workspaceDir}/.state` }).resolveCandidatePrincipleIdentity(candidateId, candidate?.rawRecommendationKind);
|
|
776
|
-
} },
|
|
793
|
+
executionInput = {
|
|
794
|
+
taskKind, taskId, workspaceDir, stateManager, runtimeAdapter: adapter,
|
|
795
|
+
eventEmitter: storeEmitter, artifactStore: stateManager.piArtifactStore, runnerOptions,
|
|
777
796
|
// PRI-982 (SPEC-PD-IAER-001 FR-02): the preflight-assembled Owner
|
|
778
797
|
// evidence pack — present only when the authoritative channel is
|
|
779
|
-
// code_tool_hook AND the readiness gate returned ready
|
|
780
|
-
// ArtificerRunnerDeps shape as the run-rulehost CLI pipeline).
|
|
798
|
+
// code_tool_hook AND the readiness gate returned ready.
|
|
781
799
|
...(artificerEvidence !== null && artificerEvidence.decision === 'ready'
|
|
782
800
|
? { behaviorExamplePack: artificerEvidence.pack }
|
|
783
801
|
: {}),
|
|
784
802
|
// SPEC-RULECODE-QUALITY-001 A1 (Owner review P2): the SAME
|
|
785
803
|
// trusted-facts port the intent preflight used must ride into the
|
|
786
|
-
// runner so the defensive mirror sees the same fact resolutions
|
|
787
|
-
// without this, a port-resolved task would pass the entry gate and
|
|
788
|
-
// then be refused by the runner's "provider absent" guard.
|
|
804
|
+
// runner so the defensive mirror sees the same fact resolutions.
|
|
789
805
|
...(ports.trustedFacts !== undefined ? { trustedFacts: ports.trustedFacts } : {}),
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
806
|
+
// PRI-741: thread the host semantic projection into generation.
|
|
807
|
+
...(artificerHostSemanticContext !== undefined ? { hostSemanticContext: artificerHostSemanticContext } : {}),
|
|
808
|
+
};
|
|
793
809
|
break;
|
|
794
810
|
case 'evaluator':
|
|
795
|
-
// P0-D
|
|
796
|
-
//
|
|
797
|
-
//
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
// 无论 OpenClaw 还是 Codex worker 执行, deterministic gate wiring
|
|
807
|
-
// 必须存在 (第二个 options 参数, 绝不放第一个 deps 参数)。
|
|
808
|
-
runner = new EvaluatorRunner({
|
|
809
|
-
stateManager, runtimeAdapter: adapter, eventEmitter: workspaceEmitter,
|
|
810
|
-
artifactStore: stateManager.piArtifactStore, validator: new DefaultEvaluatorValidator(),
|
|
811
|
-
// PRI-911A (I1 writer boundary): the rule artifact's identity is a
|
|
812
|
-
// ledger UUID or nothing. hasPrinciple turns "UUID-shaped" into
|
|
813
|
-
// "UUID the ledger actually mints", so a shaped-but-unknown id is
|
|
814
|
-
// refused as invalid_identity instead of being carried forward.
|
|
815
|
-
// Same per-call disk read as the scribe wiring above.
|
|
816
|
-
// PRI-915: availability first — an unreadable ledger must surface
|
|
817
|
-
// as identity_source_unavailable, not as invalid_identity drift.
|
|
818
|
-
ledgerIdentity: {
|
|
819
|
-
resolveForCandidate: async (candidateId) => {
|
|
820
|
-
const candidate = await stateManager.getCandidate(candidateId);
|
|
821
|
-
return new PrincipleTreeLedgerAdapter({ stateDir: `${workspaceDir}/.state` }).resolveCandidatePrincipleIdentity(candidateId, candidate?.rawRecommendationKind);
|
|
822
|
-
},
|
|
823
|
-
isAvailable: () => new PrincipleTreeLedgerAdapter({ stateDir: `${workspaceDir}/.state` }).isAvailable(),
|
|
824
|
-
hasPrinciple: (principleId) => new PrincipleTreeLedgerAdapter({ stateDir: `${workspaceDir}/.state` }).hasPrinciple(principleId),
|
|
825
|
-
},
|
|
826
|
-
...createEvaluatorRepairDeps(workspaceDir, stateManager, logger),
|
|
827
|
-
}, {
|
|
828
|
-
...runnerOptions,
|
|
829
|
-
// PRI-634-F: host registry + workspace root (when declared) make
|
|
830
|
-
// the evaluator's adversarial replay resolve tool semantics and
|
|
831
|
-
// normalizedPath identically to the host production gate.
|
|
811
|
+
// P0-D 生产接线 / PRI-630 / PRI-634 A1+A3 注释语义保持: repair deps
|
|
812
|
+
// 来自既有 governance 工厂; gateDeps 是 evaluator production
|
|
813
|
+
// semantics (options 第二参由执行器装配), 宿主目录/语义投影可选透传。
|
|
814
|
+
executionInput = {
|
|
815
|
+
taskKind, taskId, workspaceDir, stateManager, runtimeAdapter: adapter,
|
|
816
|
+
// PRI-634 A3: workspace-scoped telemetry — evaluator 事件归属本
|
|
817
|
+
// workspace (multi-workspace 隔离), 其余 kind 走全局 storeEmitter。
|
|
818
|
+
eventEmitter: workspaceEmitter,
|
|
819
|
+
artifactStore: stateManager.piArtifactStore,
|
|
820
|
+
runnerOptions,
|
|
821
|
+
repairDeps: createEvaluatorRepairDeps(workspaceDir, stateManager, logger),
|
|
832
822
|
gateDeps: createProductionGateDeps({
|
|
833
823
|
...(toolSemantics ? { toolSemantics } : {}),
|
|
834
824
|
projectDir: workspaceDir,
|
|
835
825
|
}),
|
|
836
|
-
...(hostToolCatalog
|
|
837
|
-
? { hostToolCatalog: { readOnlyTools: [...hostToolCatalog.readOnlyTools], writeTools: [...hostToolCatalog.writeTools] } }
|
|
838
|
-
: {}),
|
|
839
|
-
// PRI-741: host-name parity replay case from the SAME registry
|
|
840
|
-
// provenance as the gateDeps above.
|
|
826
|
+
...(hostToolCatalog ? { hostToolCatalog } : {}),
|
|
841
827
|
...(artificerHostSemanticContext !== undefined ? { hostSemanticContext: artificerHostSemanticContext } : {}),
|
|
842
|
-
}
|
|
828
|
+
};
|
|
843
829
|
break;
|
|
844
830
|
case 'rollout_reviewer':
|
|
845
|
-
// Lineage echo reconciliation is built into the runner
|
|
846
|
-
//
|
|
847
|
-
//
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
runner = new RolloutReviewerRunner({
|
|
854
|
-
stateManager, runtimeAdapter: adapter, eventEmitter: storeEmitter,
|
|
855
|
-
artifactStore: stateManager.piArtifactStore, validator: new DefaultRolloutReviewerValidator(),
|
|
856
|
-
...createRolloutGovernanceDeps(workspaceDir, orchestrator, { logger, ...(toolSemantics ? { toolSemantics } : {}) }),
|
|
857
|
-
}, runnerOptions);
|
|
831
|
+
// Lineage echo reconciliation is built into the runner; P0-E/F 治理接线
|
|
832
|
+
// (approve_rollout → approvals.pending; needs_revision → reopen, INV-04)
|
|
833
|
+
// 来自既有 governance 工厂 — Owner 审批绝不被绕过。
|
|
834
|
+
executionInput = {
|
|
835
|
+
taskKind, taskId, workspaceDir, stateManager, runtimeAdapter: adapter,
|
|
836
|
+
eventEmitter: storeEmitter, artifactStore: stateManager.piArtifactStore, runnerOptions,
|
|
837
|
+
governanceDeps: createRolloutGovernanceDeps(workspaceDir, orchestrator, { logger, ...(toolSemantics ? { toolSemantics } : {}) }),
|
|
838
|
+
};
|
|
858
839
|
break;
|
|
859
840
|
default:
|
|
860
841
|
emitEvent('INTERNALIZATION_CONSUMER_SKIP', JSON.stringify({ decision: 'no_runner_for_kind', taskKind }));
|
|
@@ -876,7 +857,7 @@ async function executeConsumerCycle(workspaceDir, ports, signals) {
|
|
|
876
857
|
}));
|
|
877
858
|
let runResult;
|
|
878
859
|
try {
|
|
879
|
-
runResult = await
|
|
860
|
+
runResult = await executeSelectedInternalizationTask(executionInput);
|
|
880
861
|
}
|
|
881
862
|
catch (runErr) {
|
|
882
863
|
logger.error(`[PD:${logLabel}] Runner crashed for task ${taskId}: ${String(runErr)}`);
|
|
@@ -899,10 +880,33 @@ async function executeConsumerCycle(workspaceDir, ports, signals) {
|
|
|
899
880
|
emitEvent('INTERNALIZATION_CONSUMER_COMMIT_FAILED', JSON.stringify({ taskId, error: String(commitErr).slice(0, 300) }));
|
|
900
881
|
logger.warn(`[PD:${logLabel}] Task ${taskId} succeeded but successor proposal failed: ${String(commitErr).slice(0, 200)}`);
|
|
901
882
|
}
|
|
883
|
+
// PRI-1293 R6: 结构化 successor 事件 — decision 之外的排障字段
|
|
884
|
+
// (reason/detail/冲突 id 集合/reopened 目标) 必须透出, repair reopen
|
|
885
|
+
// 失败不得只留下一个模糊 decision 名。
|
|
886
|
+
const successorTelemetry = {};
|
|
887
|
+
if (commitResult) {
|
|
888
|
+
successorTelemetry.successorDecision = commitResult.decision;
|
|
889
|
+
if ('reason' in commitResult && typeof commitResult.reason === 'string') {
|
|
890
|
+
successorTelemetry.successorReason = commitResult.reason;
|
|
891
|
+
}
|
|
892
|
+
if ('detail' in commitResult && typeof commitResult.detail === 'string') {
|
|
893
|
+
successorTelemetry.successorDetail = commitResult.detail;
|
|
894
|
+
}
|
|
895
|
+
if ('conflictingSuccessorTaskIds' in commitResult && Array.isArray(commitResult.conflictingSuccessorTaskIds)) {
|
|
896
|
+
successorTelemetry.successorConflictingTaskIds = [...commitResult.conflictingSuccessorTaskIds];
|
|
897
|
+
}
|
|
898
|
+
successorTelemetry.sourceTaskId = 'sourceTaskId' in commitResult ? commitResult.sourceTaskId : taskId;
|
|
899
|
+
if ('reopenedTaskId' in commitResult && typeof commitResult.reopenedTaskId === 'string') {
|
|
900
|
+
successorTelemetry.reopenedTaskId = commitResult.reopenedTaskId;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
else {
|
|
904
|
+
successorTelemetry.successorDecision = 'commit_failed';
|
|
905
|
+
}
|
|
902
906
|
emitEvent('INTERNALIZATION_CONSUMER_SUCCESS', JSON.stringify({
|
|
903
907
|
taskId,
|
|
904
908
|
status: runResult.status,
|
|
905
|
-
...
|
|
909
|
+
...successorTelemetry,
|
|
906
910
|
}));
|
|
907
911
|
logger.info(`[PD:${logLabel}] Task ${taskId} succeeded. Successor: ${commitResult ? commitResult.decision : 'commit_failed'}`);
|
|
908
912
|
return { ran: true, taskId, taskKind, runStatus: 'succeeded' };
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Internalization consumer governance wiring (host-neutral, PRI-624).
|
|
3
3
|
*
|
|
4
4
|
* Ported verbatim from openclaw-plugin `auto-consumer-governance-wiring.ts`
|
|
5
|
-
* (P0-D/E/F 生产接线) so the OpenClaw auto-consumer and the
|
|
6
|
-
* workspace
|
|
5
|
+
* (P0-D/E/F 生产接线) so the OpenClaw auto-consumer and the Service-Host-spawned
|
|
6
|
+
* workspace workers share ONE wiring implementation instead of copying it:
|
|
7
7
|
* - evaluator: isRepairLoopEnabled + seedArtificerRepairTask (bounded repair)
|
|
8
8
|
* - rollout_reviewer: dispatchActivation (approve_rollout → ActivationDispatcher;
|
|
9
9
|
* PRI-811 Phase B: 一律入 approvals.pending,Owner 批准后才激活) +
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
* dedupes by `${artifactId}::${channel}`; reopen idempotency is owned by
|
|
15
15
|
* orchestrator.reopenTaskForRevision.
|
|
16
16
|
*/
|
|
17
|
-
import { type RolloutAutoDispatchInput, type RolloutAutoDispatchOutcome, type RolloutRevisionRoutingInput, type SeedArtificerRepairParams, type RuntimeStateManager, type
|
|
17
|
+
import { type RolloutAutoDispatchInput, type RolloutAutoDispatchOutcome, type RolloutRevisionRoutingInput, type SeedArtificerRepairParams, type RuntimeStateManager, type ToolSemanticRegistry } from '@principles/core/runtime';
|
|
18
|
+
import type { InternalizationOrchestrator } from '@principles/core/runtime';
|
|
18
19
|
/** Structural logger port — PluginLogger satisfies this without adaptation. */
|
|
19
20
|
export interface ConsumerGovernanceLogger {
|
|
20
21
|
info?: (msg: string) => void;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Internalization consumer governance wiring (host-neutral, PRI-624).
|
|
3
3
|
*
|
|
4
4
|
* Ported verbatim from openclaw-plugin `auto-consumer-governance-wiring.ts`
|
|
5
|
-
* (P0-D/E/F 生产接线) so the OpenClaw auto-consumer and the
|
|
6
|
-
* workspace
|
|
5
|
+
* (P0-D/E/F 生产接线) so the OpenClaw auto-consumer and the Service-Host-spawned
|
|
6
|
+
* workspace workers share ONE wiring implementation instead of copying it:
|
|
7
7
|
* - evaluator: isRepairLoopEnabled + seedArtificerRepairTask (bounded repair)
|
|
8
8
|
* - rollout_reviewer: dispatchActivation (approve_rollout → ActivationDispatcher;
|
|
9
9
|
* PRI-811 Phase B: 一律入 approvals.pending,Owner 批准后才激活) +
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* dedupes by `${artifactId}::${channel}`; reopen idempotency is owned by
|
|
15
15
|
* orchestrator.reopenTaskForRevision.
|
|
16
16
|
*/
|
|
17
|
-
import { ActivationDispatcher, PromptWriter, DeferArchiveWriter, RuleHostWriter, SqliteConnection, SqliteActivationStateStore, SqliteApprovalQueueStore, SqlitePIArtifactStore, PrincipleTreeLedgerAdapter, createProductionGateDeps,
|
|
17
|
+
import { ActivationDispatcher, PromptWriter, DeferArchiveWriter, RuleHostWriter, SqliteConnection, SqliteActivationStateStore, SqliteApprovalQueueStore, SqlitePIArtifactStore, PrincipleTreeLedgerAdapter, createProductionGateDeps, createRepairTask, repairSeedErrorMessage, computeFeatureFlagsFromConfig, isFeatureEnabled, } from '@principles/core/runtime';
|
|
18
18
|
import { loadPdConfigForPlugin } from './pd-config.js';
|
|
19
19
|
function normalizeDecision(decision) {
|
|
20
20
|
if (decision.decision === 'activated') {
|
|
@@ -142,46 +142,22 @@ export function createEvaluatorRepairDeps(workspaceDir, stateManager, logger) {
|
|
|
142
142
|
return isFeatureEnabled(flags, 'evaluator_artificer_repair_loop');
|
|
143
143
|
},
|
|
144
144
|
seedArtificerRepairTask: async (params) => {
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
// (Owner revise_once) — surface as a seed failure so the evaluator
|
|
157
|
-
// degrades to needs_human_review instead of looping.
|
|
158
|
-
if (existing.status === 'succeeded' || existing.status === 'failed' || existing.status === 'needs_human_review') {
|
|
159
|
-
throw new Error(`repair task ${repairTaskId} already reached terminal status ${existing.status}; refusing to reuse it as new corrective work (PRI-718 revise-ne-resume)`);
|
|
145
|
+
// PRI-1299 Phase 1: 宿主层只做参数转发与既有错误语义映射; identity、
|
|
146
|
+
// reuse、payload/channel adjudication、lineage proof、insert 与 UNIQUE
|
|
147
|
+
// race re-arbitration 全部由 principles-core 的唯一 RepairCreationAuthority 执行。
|
|
148
|
+
const result = await createRepairTask(stateManager, params);
|
|
149
|
+
if (result.outcome === 'created') {
|
|
150
|
+
logger?.info?.(`[PD:Consumer] seeded artificer repair task ${result.task.taskId} (iteration ${params.repairPayload.repairIteration})`);
|
|
151
|
+
return result.task.taskId;
|
|
152
|
+
}
|
|
153
|
+
if (result.outcome === 'adopted_existing') {
|
|
154
|
+
if (result.backfilled) {
|
|
155
|
+
logger?.info?.(`[PD:Consumer] repair task ${result.task.taskId} lineage backfilled before reuse`);
|
|
160
156
|
}
|
|
161
|
-
logger?.info?.(`[PD:Consumer] repair task ${
|
|
162
|
-
return
|
|
157
|
+
logger?.info?.(`[PD:Consumer] repair task ${result.task.taskId} already exists (in-flight ${result.task.status}); reusing (idempotent seed)`);
|
|
158
|
+
return result.task.taskId;
|
|
163
159
|
}
|
|
164
|
-
|
|
165
|
-
taskId: repairTaskId,
|
|
166
|
-
taskKind: 'artificer',
|
|
167
|
-
status: 'pending',
|
|
168
|
-
attemptCount: 0,
|
|
169
|
-
maxAttempts: 3,
|
|
170
|
-
diagnosticJson: createPITaskDiagnosticJson({
|
|
171
|
-
dependencyTaskIds: [...params.inheritedDependencyTaskIds],
|
|
172
|
-
channel: params.inheritedChannel,
|
|
173
|
-
pipelineMode: params.inheritedPipelineMode,
|
|
174
|
-
timeoutMs: params.inheritedTimeoutMs,
|
|
175
|
-
inputArtifactRefs: [...params.inheritedInputArtifactRefs],
|
|
176
|
-
outputArtifactRefs: [],
|
|
177
|
-
...(params.ownerEvidenceSelection !== undefined
|
|
178
|
-
? { ownerEvidenceSelection: params.ownerEvidenceSelection }
|
|
179
|
-
: {}),
|
|
180
|
-
repairPayload: params.repairPayload,
|
|
181
|
-
}),
|
|
182
|
-
});
|
|
183
|
-
logger?.info?.(`[PD:Consumer] seeded artificer repair task ${repairTaskId} (iteration ${params.repairPayload.repairIteration})`);
|
|
184
|
-
return repairTaskId;
|
|
160
|
+
throw new Error(repairSeedErrorMessage(result));
|
|
185
161
|
},
|
|
186
162
|
};
|
|
187
163
|
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PRI-1301 / PRI-1293 Phase 2B — 共享单步 Runner 执行器 (SPEC-PD-PIPELINE-SPINE-001 §3.5)
|
|
3
|
+
* (PRI-1301: 从 internalization-consumer-cycle.ts 独立成模块 — 纯移动,
|
|
4
|
+
* 执行器本体逐字等价; 周期调度/选择/lease/恢复/reconciliation 留在 cycle)。
|
|
5
|
+
*
|
|
6
|
+
* `executeSelectedInternalizationTask` 是六种 Peer Runner 构造+执行的唯一权威
|
|
7
|
+
* 实现。收编对象:consumer cycle 分支 + pd-cli
|
|
8
|
+
* `runtime-internalization-run-once` 的 6 分支手搓构造。`rulehost-pipeline-
|
|
9
|
+
* runner` 是显式同步对抗算子 (非租约编排),按 SPEC §3.5.2 白名单保留独立构造。
|
|
10
|
+
*
|
|
11
|
+
* 职责边界 (统一 Runner 执行,不统一所有宿主行为):
|
|
12
|
+
* 只负责 — kind→Runner 映射、按判别联合的类型化依赖装配、执行指定 taskId、
|
|
13
|
+
* 返回原始执行结果。
|
|
14
|
+
* 不进入 — 任务发现/选择/wake/lease (orchestrator)、Runtime Profile 解析、
|
|
15
|
+
* Adapter/L2 路由 (各入口自建 adapter 传入)、Owner Evidence Preflight
|
|
16
|
+
* (auto consumer)、repair 任务创建 (两个 governance deps 工厂)、后继提交、
|
|
17
|
+
* 周期调度、Workspace Telemetry 归属 (eventEmitter 由入口选择)。
|
|
18
|
+
*
|
|
19
|
+
* Scribe/Artificer/Evaluator 的 ledgerIdentity 从 (workspaceDir, stateManager)
|
|
20
|
+
* 以同一装配导出 — 此前 consumer 与 run-once 各自内联同一段闭包 (重复实现)。
|
|
21
|
+
* 两个入口的有意差异 (§2.5) 由输入类型表达:artificer 的 evidence pack /
|
|
22
|
+
* trustedFacts 仅由具备 preflight 能力的入口传入;evaluator 的 repair deps /
|
|
23
|
+
* gateDeps / hostToolCatalog / hostSemanticContext 必需显式提供,不存在缺省
|
|
24
|
+
* 掩盖 (类型层面不可缺失)。
|
|
25
|
+
*/
|
|
26
|
+
import { type PDRuntimeAdapter, type RuntimeStateManager, type TelemetryEvent, type PIArtifactStore, type EffectivePdConfig, type OutputLanguage, type RefinerRuleHostGateDeps, type RolloutAutoDispatchInput, type RolloutAutoDispatchOutcome, type RolloutRevisionRoutingInput, type SeedArtificerRepairParams, type BehaviorExamplePack, type ArtificerTrustedFactsPort, type ArtificerHostSemanticContext, type DreamerRunnerResult, type PhilosopherRunnerResult, type ScribeRunnerResult, type ArtificerRunnerResult, type EvaluatorRunnerResult, type EvaluatorRunnerOptions, type RolloutReviewerRunnerResult } from '@principles/core/runtime';
|
|
27
|
+
/**
|
|
28
|
+
* Runner 遥测窄端口 — 与 core `PeerRunnerTelemetryEmitter` 结构等价
|
|
29
|
+
* (该类型不在 core 冻结 barrel 上,此处按结构声明,零新增导出)。
|
|
30
|
+
* StoreEventEmitter 与 WorkspaceTelemetryEmitter 均满足。
|
|
31
|
+
*/
|
|
32
|
+
export interface SelectedTaskTelemetryEmitter {
|
|
33
|
+
readonly emitTelemetry: (event: TelemetryEvent) => unknown;
|
|
34
|
+
}
|
|
35
|
+
/** 全部 kind 共享的调用方依赖。 */
|
|
36
|
+
export interface SelectedInternalizationTaskBaseDeps {
|
|
37
|
+
/** 要执行的已**选中**任务 — 执行租约由 Runner 在 run() 内自行获取, 调用方不在本层租约。 */
|
|
38
|
+
readonly taskId: string;
|
|
39
|
+
readonly stateManager: RuntimeStateManager;
|
|
40
|
+
/** 入口自建的 runtime adapter (含 L2 / test-double 路由决策)。 */
|
|
41
|
+
readonly runtimeAdapter: PDRuntimeAdapter;
|
|
42
|
+
/** 入口选择的遥测口 (consumer evaluator 用 workspace-scoped emitter)。 */
|
|
43
|
+
readonly eventEmitter: SelectedTaskTelemetryEmitter;
|
|
44
|
+
readonly artifactStore: PIArtifactStore;
|
|
45
|
+
/** Workspace 根 — ledgerIdentity 装配的唯一事实来源。 */
|
|
46
|
+
readonly workspaceDir: string;
|
|
47
|
+
}
|
|
48
|
+
/** Runner 构造/执行选项 — 原样转发 (各入口既有语义保持)。 */
|
|
49
|
+
export interface SelectedInternalizationTaskRunnerOptions {
|
|
50
|
+
readonly owner: string;
|
|
51
|
+
readonly runtimeKind: string;
|
|
52
|
+
readonly timeoutMs: number;
|
|
53
|
+
readonly effectiveConfig?: EffectivePdConfig;
|
|
54
|
+
readonly outputLanguage?: OutputLanguage;
|
|
55
|
+
readonly pollIntervalMs?: number;
|
|
56
|
+
}
|
|
57
|
+
/** Evaluator repair 轮的宿主接线 (来自既有 governance deps 工厂,不造第三套)。 */
|
|
58
|
+
export interface SelectedEvaluatorRepairDeps {
|
|
59
|
+
readonly isRepairLoopEnabled: () => boolean;
|
|
60
|
+
readonly seedArtificerRepairTask: (params: SeedArtificerRepairParams) => Promise<string>;
|
|
61
|
+
}
|
|
62
|
+
/** rollout 治理接线 (来自 createRolloutGovernanceDeps)。 */
|
|
63
|
+
export interface SelectedRolloutGovernanceDeps {
|
|
64
|
+
readonly dispatchActivation: (input: RolloutAutoDispatchInput) => Promise<RolloutAutoDispatchOutcome>;
|
|
65
|
+
readonly reopenRevisionTarget: (input: RolloutRevisionRoutingInput) => Promise<{
|
|
66
|
+
ok: boolean;
|
|
67
|
+
reason: string;
|
|
68
|
+
reopenedTaskId?: string;
|
|
69
|
+
}>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 按 taskKind 收窄的判别联合输入 — 必需依赖在类型层面不可缺失;
|
|
73
|
+
* optional 仅限两个入口现状真实可选的字段 (artificer 的 evidence pack /
|
|
74
|
+
* trustedFacts / hostSemanticContext、evaluator 的宿主目录与语义投影)。
|
|
75
|
+
*/
|
|
76
|
+
export type ExecuteSelectedInternalizationTaskInput = ({
|
|
77
|
+
readonly taskKind: 'dreamer';
|
|
78
|
+
} & SelectedInternalizationTaskBaseDeps & {
|
|
79
|
+
readonly runnerOptions: SelectedInternalizationTaskRunnerOptions;
|
|
80
|
+
}) | ({
|
|
81
|
+
readonly taskKind: 'philosopher';
|
|
82
|
+
} & SelectedInternalizationTaskBaseDeps & {
|
|
83
|
+
readonly runnerOptions: SelectedInternalizationTaskRunnerOptions;
|
|
84
|
+
}) | ({
|
|
85
|
+
readonly taskKind: 'scribe';
|
|
86
|
+
} & SelectedInternalizationTaskBaseDeps & {
|
|
87
|
+
readonly runnerOptions: SelectedInternalizationTaskRunnerOptions;
|
|
88
|
+
}) | ({
|
|
89
|
+
readonly taskKind: 'artificer';
|
|
90
|
+
/** 仅 preflight 通过的入口传入 (consumer evidence ready);run-once 无此能力则缺省。 */
|
|
91
|
+
readonly behaviorExamplePack?: BehaviorExamplePack;
|
|
92
|
+
/** 仅 consumer 传入 — 与 intent preflight 同源的 trusted-facts 端口。 */
|
|
93
|
+
readonly trustedFacts?: ArtificerTrustedFactsPort;
|
|
94
|
+
readonly hostSemanticContext?: ArtificerHostSemanticContext;
|
|
95
|
+
} & SelectedInternalizationTaskBaseDeps & {
|
|
96
|
+
readonly runnerOptions: SelectedInternalizationTaskRunnerOptions;
|
|
97
|
+
}) | ({
|
|
98
|
+
readonly taskKind: 'evaluator';
|
|
99
|
+
/** repair 轮宿主接线 — 缺失即是装配错误,不允许缺省掩盖。 */
|
|
100
|
+
readonly repairDeps: SelectedEvaluatorRepairDeps;
|
|
101
|
+
/** 对抗重放 gate — 两个入口都必须显式提供各自权威解析结果。 */
|
|
102
|
+
readonly gateDeps: RefinerRuleHostGateDeps;
|
|
103
|
+
readonly hostToolCatalog?: EvaluatorRunnerOptions['hostToolCatalog'];
|
|
104
|
+
readonly hostSemanticContext?: ArtificerHostSemanticContext;
|
|
105
|
+
} & SelectedInternalizationTaskBaseDeps & {
|
|
106
|
+
readonly runnerOptions: SelectedInternalizationTaskRunnerOptions;
|
|
107
|
+
}) | ({
|
|
108
|
+
readonly taskKind: 'rollout_reviewer';
|
|
109
|
+
readonly governanceDeps: SelectedRolloutGovernanceDeps;
|
|
110
|
+
} & SelectedInternalizationTaskBaseDeps & {
|
|
111
|
+
readonly runnerOptions: SelectedInternalizationTaskRunnerOptions;
|
|
112
|
+
});
|
|
113
|
+
export type SelectedInternalizationTaskRunResult = DreamerRunnerResult | PhilosopherRunnerResult | ScribeRunnerResult | ArtificerRunnerResult | EvaluatorRunnerResult | RolloutReviewerRunnerResult;
|
|
114
|
+
/**
|
|
115
|
+
* Execute ONE selected internalization task with the kind-selected runner.
|
|
116
|
+
* Constructs the runner from the typed input and returns the raw run result.
|
|
117
|
+
*
|
|
118
|
+
* Lease ownership contract (CodeRabbit review fix): the caller is responsible
|
|
119
|
+
* for SELECTING the task (e.g. a dry-run `wakeOnce` `would_lease` candidate);
|
|
120
|
+
* the runner itself acquires the execution lease inside `run()` — callers must
|
|
121
|
+
* NOT lease at this layer. The doc previously demanded an already-leased task,
|
|
122
|
+
* which would lead new callers to acquire the lease at the wrong layer.
|
|
123
|
+
*
|
|
124
|
+
* Runner crashes propagate to the caller (each entry keeps its own crash
|
|
125
|
+
* semantics: consumer rethrows without state writes; run-once logs + rethrows).
|
|
126
|
+
*/
|
|
127
|
+
export declare function executeSelectedInternalizationTask(input: ExecuteSelectedInternalizationTaskInput): Promise<SelectedInternalizationTaskRunResult>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PRI-1301 / PRI-1293 Phase 2B — 共享单步 Runner 执行器 (SPEC-PD-PIPELINE-SPINE-001 §3.5)
|
|
3
|
+
* (PRI-1301: 从 internalization-consumer-cycle.ts 独立成模块 — 纯移动,
|
|
4
|
+
* 执行器本体逐字等价; 周期调度/选择/lease/恢复/reconciliation 留在 cycle)。
|
|
5
|
+
*
|
|
6
|
+
* `executeSelectedInternalizationTask` 是六种 Peer Runner 构造+执行的唯一权威
|
|
7
|
+
* 实现。收编对象:consumer cycle 分支 + pd-cli
|
|
8
|
+
* `runtime-internalization-run-once` 的 6 分支手搓构造。`rulehost-pipeline-
|
|
9
|
+
* runner` 是显式同步对抗算子 (非租约编排),按 SPEC §3.5.2 白名单保留独立构造。
|
|
10
|
+
*
|
|
11
|
+
* 职责边界 (统一 Runner 执行,不统一所有宿主行为):
|
|
12
|
+
* 只负责 — kind→Runner 映射、按判别联合的类型化依赖装配、执行指定 taskId、
|
|
13
|
+
* 返回原始执行结果。
|
|
14
|
+
* 不进入 — 任务发现/选择/wake/lease (orchestrator)、Runtime Profile 解析、
|
|
15
|
+
* Adapter/L2 路由 (各入口自建 adapter 传入)、Owner Evidence Preflight
|
|
16
|
+
* (auto consumer)、repair 任务创建 (两个 governance deps 工厂)、后继提交、
|
|
17
|
+
* 周期调度、Workspace Telemetry 归属 (eventEmitter 由入口选择)。
|
|
18
|
+
*
|
|
19
|
+
* Scribe/Artificer/Evaluator 的 ledgerIdentity 从 (workspaceDir, stateManager)
|
|
20
|
+
* 以同一装配导出 — 此前 consumer 与 run-once 各自内联同一段闭包 (重复实现)。
|
|
21
|
+
* 两个入口的有意差异 (§2.5) 由输入类型表达:artificer 的 evidence pack /
|
|
22
|
+
* trustedFacts 仅由具备 preflight 能力的入口传入;evaluator 的 repair deps /
|
|
23
|
+
* gateDeps / hostToolCatalog / hostSemanticContext 必需显式提供,不存在缺省
|
|
24
|
+
* 掩盖 (类型层面不可缺失)。
|
|
25
|
+
*/
|
|
26
|
+
import { DreamerRunner, PhilosopherRunner, ScribeRunner, ArtificerRunner, EvaluatorRunner, RolloutReviewerRunner, DefaultDreamerValidator, DefaultPhilosopherValidator, DefaultScribeValidator, DefaultArtificerValidator, DefaultEvaluatorValidator, DefaultRolloutReviewerValidator, PrincipleTreeLedgerAdapter, } from '@principles/core/runtime';
|
|
27
|
+
/**
|
|
28
|
+
* Scribe/Artificer/Evaluator 共用的 ledger 身份装配 — 与两个入口此前内联的
|
|
29
|
+
* 闭包逐字等价 (每次调用新开 PrincipleTreeLedgerAdapter 读盘,无跨周期缓存)。
|
|
30
|
+
*/
|
|
31
|
+
function buildWorkspaceLedgerIdentity(workspaceDir, stateManager) {
|
|
32
|
+
const ledger = () => new PrincipleTreeLedgerAdapter({ stateDir: `${workspaceDir}/.state` });
|
|
33
|
+
return {
|
|
34
|
+
resolveForCandidate: async (candidateId) => {
|
|
35
|
+
const candidate = await stateManager.getCandidate(candidateId);
|
|
36
|
+
return ledger().resolveCandidatePrincipleIdentity(candidateId, candidate?.rawRecommendationKind);
|
|
37
|
+
},
|
|
38
|
+
// PRI-915: availability first — an unreadable ledger must not read as an
|
|
39
|
+
// unresolved chain.
|
|
40
|
+
isAvailable: () => ledger().isAvailable(),
|
|
41
|
+
listForCandidate: (candidateId) => ledger().listForCandidate(candidateId),
|
|
42
|
+
hasPrinciple: (principleId) => ledger().hasPrinciple(principleId),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Execute ONE selected internalization task with the kind-selected runner.
|
|
47
|
+
* Constructs the runner from the typed input and returns the raw run result.
|
|
48
|
+
*
|
|
49
|
+
* Lease ownership contract (CodeRabbit review fix): the caller is responsible
|
|
50
|
+
* for SELECTING the task (e.g. a dry-run `wakeOnce` `would_lease` candidate);
|
|
51
|
+
* the runner itself acquires the execution lease inside `run()` — callers must
|
|
52
|
+
* NOT lease at this layer. The doc previously demanded an already-leased task,
|
|
53
|
+
* which would lead new callers to acquire the lease at the wrong layer.
|
|
54
|
+
*
|
|
55
|
+
* Runner crashes propagate to the caller (each entry keeps its own crash
|
|
56
|
+
* semantics: consumer rethrows without state writes; run-once logs + rethrows).
|
|
57
|
+
*/
|
|
58
|
+
export async function executeSelectedInternalizationTask(input) {
|
|
59
|
+
const { taskId, stateManager, runtimeAdapter, eventEmitter, artifactStore, workspaceDir } = input;
|
|
60
|
+
const { runnerOptions } = input;
|
|
61
|
+
// Evaluator 的身份装配含 hasPrinciple (PRI-911A writer boundary);
|
|
62
|
+
// Scribe 另需 listForCandidate (chain stamping);Artificer 只读解析。
|
|
63
|
+
// 一次装配、按 kind 结构化满足各自 deps 形状。
|
|
64
|
+
const ledgerIdentity = buildWorkspaceLedgerIdentity(workspaceDir, stateManager);
|
|
65
|
+
switch (input.taskKind) {
|
|
66
|
+
case 'dreamer':
|
|
67
|
+
return new DreamerRunner({ stateManager, runtimeAdapter, eventEmitter, artifactStore, validator: new DefaultDreamerValidator() }, runnerOptions).run(taskId);
|
|
68
|
+
case 'philosopher':
|
|
69
|
+
return new PhilosopherRunner({ stateManager, runtimeAdapter, eventEmitter, artifactStore, validator: new DefaultPhilosopherValidator() }, runnerOptions).run(taskId);
|
|
70
|
+
case 'scribe':
|
|
71
|
+
return new ScribeRunner({
|
|
72
|
+
stateManager, runtimeAdapter, eventEmitter, artifactStore,
|
|
73
|
+
validator: new DefaultScribeValidator({ requireRuleCodeContracts: true }),
|
|
74
|
+
// I2 — CHAIN STAMPING (Owner review of PR #1856, P1): 完整三元身份
|
|
75
|
+
// (resolveForCandidate / isAvailable / listForCandidate)。
|
|
76
|
+
ledgerIdentity,
|
|
77
|
+
}, runnerOptions).run(taskId);
|
|
78
|
+
case 'artificer':
|
|
79
|
+
return new ArtificerRunner({
|
|
80
|
+
stateManager, runtimeAdapter, eventEmitter, artifactStore,
|
|
81
|
+
validator: new DefaultArtificerValidator(),
|
|
82
|
+
ledgerIdentity,
|
|
83
|
+
...(input.behaviorExamplePack !== undefined ? { behaviorExamplePack: input.behaviorExamplePack } : {}),
|
|
84
|
+
...(input.trustedFacts !== undefined ? { trustedFacts: input.trustedFacts } : {}),
|
|
85
|
+
}, {
|
|
86
|
+
...runnerOptions,
|
|
87
|
+
...(input.hostSemanticContext !== undefined ? { hostSemanticContext: input.hostSemanticContext } : {}),
|
|
88
|
+
}).run(taskId);
|
|
89
|
+
case 'evaluator': {
|
|
90
|
+
const evaluatorLedgerIdentity = {
|
|
91
|
+
resolveForCandidate: ledgerIdentity.resolveForCandidate,
|
|
92
|
+
isAvailable: ledgerIdentity.isAvailable,
|
|
93
|
+
hasPrinciple: ledgerIdentity.hasPrinciple,
|
|
94
|
+
};
|
|
95
|
+
return new EvaluatorRunner({
|
|
96
|
+
stateManager,
|
|
97
|
+
runtimeAdapter,
|
|
98
|
+
eventEmitter,
|
|
99
|
+
artifactStore,
|
|
100
|
+
validator: new DefaultEvaluatorValidator(),
|
|
101
|
+
ledgerIdentity: evaluatorLedgerIdentity,
|
|
102
|
+
isRepairLoopEnabled: input.repairDeps.isRepairLoopEnabled,
|
|
103
|
+
seedArtificerRepairTask: input.repairDeps.seedArtificerRepairTask,
|
|
104
|
+
}, {
|
|
105
|
+
...runnerOptions,
|
|
106
|
+
gateDeps: input.gateDeps,
|
|
107
|
+
...(input.hostToolCatalog !== undefined
|
|
108
|
+
? { hostToolCatalog: { readOnlyTools: [...input.hostToolCatalog.readOnlyTools], writeTools: [...input.hostToolCatalog.writeTools] } }
|
|
109
|
+
: {}),
|
|
110
|
+
...(input.hostSemanticContext !== undefined ? { hostSemanticContext: input.hostSemanticContext } : {}),
|
|
111
|
+
}).run(taskId);
|
|
112
|
+
}
|
|
113
|
+
case 'rollout_reviewer':
|
|
114
|
+
return new RolloutReviewerRunner({
|
|
115
|
+
stateManager, runtimeAdapter, eventEmitter, artifactStore,
|
|
116
|
+
validator: new DefaultRolloutReviewerValidator(),
|
|
117
|
+
dispatchActivation: input.governanceDeps.dispatchActivation,
|
|
118
|
+
reopenRevisionTarget: input.governanceDeps.reopenRevisionTarget,
|
|
119
|
+
}, runnerOptions).run(taskId);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -8,9 +8,12 @@
|
|
|
8
8
|
* (SPEC workbuddy-host-adapter §1 Excluded: no transcript reads).
|
|
9
9
|
*
|
|
10
10
|
* SPEC §15 worker mode, evaluated WITHOUT executing anything (no lease, no
|
|
11
|
-
* LLM). `manual_action_required` means
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* LLM). `manual_action_required` means this governance workspace is not
|
|
12
|
+
* registered in the canonical install manifest, so the PD Service Host —
|
|
13
|
+
* the only background runtime, triggered by the OS scheduler — never
|
|
14
|
+
* discovers it and no automatic worker cycles run for it. Manual
|
|
15
|
+
* `pd diagnose` / `pd runtime internalization run-once` is the recovery
|
|
16
|
+
* route.
|
|
14
17
|
*/
|
|
15
18
|
export type WorkbuddyWorkerMode = 'ready' | 'manual_action_required' | 'paused' | 'degraded';
|
|
16
19
|
export interface WorkbuddyWorkerStatusEvaluation {
|
|
@@ -8,9 +8,12 @@
|
|
|
8
8
|
* (SPEC workbuddy-host-adapter §1 Excluded: no transcript reads).
|
|
9
9
|
*
|
|
10
10
|
* SPEC §15 worker mode, evaluated WITHOUT executing anything (no lease, no
|
|
11
|
-
* LLM). `manual_action_required` means
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* LLM). `manual_action_required` means this governance workspace is not
|
|
12
|
+
* registered in the canonical install manifest, so the PD Service Host —
|
|
13
|
+
* the only background runtime, triggered by the OS scheduler — never
|
|
14
|
+
* discovers it and no automatic worker cycles run for it. Manual
|
|
15
|
+
* `pd diagnose` / `pd runtime internalization run-once` is the recovery
|
|
16
|
+
* route.
|
|
14
17
|
*/
|
|
15
18
|
import * as fs from 'node:fs';
|
|
16
19
|
import * as path from 'node:path';
|
|
@@ -48,7 +51,7 @@ export function computeWorkbuddyWorkerStatusMode(input) {
|
|
|
48
51
|
return {
|
|
49
52
|
mode: 'manual_action_required',
|
|
50
53
|
reason: 'workspace_not_in_install_manifest',
|
|
51
|
-
nextAction: `
|
|
54
|
+
nextAction: `This governance workspace is not registered in the canonical install manifest, so the PD Service Host does not manage automatic worker cycles for it. Repair the registration with the PD installer (npx create-principles-disciple). Manual path: pd diagnose --workspace "${workspaceDir}", then pd runtime internalization run-once.`,
|
|
52
55
|
};
|
|
53
56
|
}
|
|
54
57
|
return { mode: 'ready' };
|
|
@@ -52,7 +52,7 @@ import { StoreEventEmitter } from '@principles/core/runtime';
|
|
|
52
52
|
* 事件,含完整 TelemetryEvent)。同步 append:事件量小(allowlist 限流),
|
|
53
53
|
* 换取 crash 前落盘的 durable 语义。写失败绝不影响 runner —— 降级为
|
|
54
54
|
* `onPersistFailure` 回调(宿主注入的结构化告警口;OpenClaw 是
|
|
55
|
-
* SystemLogger,
|
|
55
|
+
* SystemLogger,Service-Host 派生的 workspace worker 是自己的事件口)。
|
|
56
56
|
*/
|
|
57
57
|
const CRITICAL_EVENT_ALLOWLIST = new Set([
|
|
58
58
|
'evaluator_adversarial_replay_skipped',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/host-runtime",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.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.4.1",
|
|
43
|
+
"@principles/install-layout": "^0.12.0",
|
|
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": "ff62137821c993773cc7df104a01625310776c51"
|
|
61
61
|
}
|