create-principles-disciple 1.156.0 → 1.156.2
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/_release/product-identity.json +1 -1
- package/codex-adapter/dist/ingestion/pain-receipt-fallback.js +3 -2
- package/codex-adapter/dist/worker/workspace-worker.js +52 -17
- package/codex-adapter/package.json +1 -1
- package/core/dist/runtime/adversarial-loop.d.ts.map +1 -1
- package/core/dist/runtime/adversarial-loop.js +12 -0
- package/core/dist/runtime/adversarial-loop.js.map +1 -1
- package/core/dist/runtime/diagnostician-candidate.d.ts.map +1 -1
- package/core/dist/runtime/diagnostician-candidate.js +6 -4
- package/core/dist/runtime/diagnostician-candidate.js.map +1 -1
- package/core/dist/runtime/index.d.ts +9 -2
- package/core/dist/runtime/index.d.ts.map +1 -1
- package/core/dist/runtime/index.js +10 -2
- package/core/dist/runtime/index.js.map +1 -1
- package/core/dist/runtime/intent/intent-doc.d.ts +30 -0
- package/core/dist/runtime/intent/intent-doc.d.ts.map +1 -1
- package/core/dist/runtime/intent/intent-doc.js +47 -0
- package/core/dist/runtime/intent/intent-doc.js.map +1 -1
- package/core/dist/runtime/intent/intent-snapshot.d.ts +12 -0
- package/core/dist/runtime/intent/intent-snapshot.d.ts.map +1 -1
- package/core/dist/runtime/intent/intent-snapshot.js +20 -0
- package/core/dist/runtime/intent/intent-snapshot.js.map +1 -1
- package/core/dist/runtime/internalization/correlation-lineage.d.ts +113 -0
- package/core/dist/runtime/internalization/correlation-lineage.d.ts.map +1 -0
- package/core/dist/runtime/internalization/correlation-lineage.js +431 -0
- package/core/dist/runtime/internalization/correlation-lineage.js.map +1 -0
- package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts +18 -0
- package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/diag-rootcause-runner.js +53 -15
- package/core/dist/runtime/internalization/diag-rootcause-runner.js.map +1 -1
- package/core/dist/runtime/internalization/internalization-orchestrator.d.ts +58 -5
- package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
- package/core/dist/runtime/internalization/internalization-orchestrator.js +370 -100
- package/core/dist/runtime/internalization/internalization-orchestrator.js.map +1 -1
- package/core/dist/runtime/internalization/internalization-state-machine.d.ts +14 -0
- package/core/dist/runtime/internalization/internalization-state-machine.d.ts.map +1 -1
- package/core/dist/runtime/internalization/internalization-state-machine.js +22 -0
- package/core/dist/runtime/internalization/internalization-state-machine.js.map +1 -1
- package/core/dist/runtime/internalization/peer-runner-contracts.d.ts +2 -0
- package/core/dist/runtime/internalization/peer-runner-contracts.d.ts.map +1 -1
- package/core/dist/runtime/internalization/peer-runner-contracts.js.map +1 -1
- package/core/dist/runtime/internalization/pitask-metadata.d.ts +31 -0
- package/core/dist/runtime/internalization/pitask-metadata.d.ts.map +1 -1
- package/core/dist/runtime/internalization/pitask-metadata.js +54 -1
- package/core/dist/runtime/internalization/pitask-metadata.js.map +1 -1
- package/core/dist/runtime/internalization/repair-task-identity.d.ts +43 -0
- package/core/dist/runtime/internalization/repair-task-identity.d.ts.map +1 -0
- package/core/dist/runtime/internalization/repair-task-identity.js +102 -0
- package/core/dist/runtime/internalization/repair-task-identity.js.map +1 -0
- package/core/dist/runtime/internalization/revision-reopen.d.ts +37 -0
- package/core/dist/runtime/internalization/revision-reopen.d.ts.map +1 -1
- package/core/dist/runtime/internalization/revision-reopen.js +144 -7
- package/core/dist/runtime/internalization/revision-reopen.js.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts +8 -2
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.js +2 -2
- package/core/dist/runtime/internalization/rollout-reviewer-runner.js.map +1 -1
- package/core/dist/runtime/internalization/rule-binding-revision.js +3 -3
- package/core/dist/runtime/internalization/rule-binding-revision.js.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.js +4 -0
- package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
- package/core/dist/runtime/pain-admission-disposition.d.ts +8 -4
- package/core/dist/runtime/pain-admission-disposition.d.ts.map +1 -1
- package/core/dist/runtime/pain-admission-disposition.js +8 -4
- package/core/dist/runtime/pain-admission-disposition.js.map +1 -1
- package/core/dist/runtime/pain-receipt-recovery.d.ts +38 -10
- package/core/dist/runtime/pain-receipt-recovery.d.ts.map +1 -1
- package/core/dist/runtime/pain-receipt-recovery.js +266 -30
- package/core/dist/runtime/pain-receipt-recovery.js.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.d.ts +60 -12
- package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.js +200 -142
- package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
- package/core/dist/runtime/pain-submit-capability.d.ts +14 -3
- package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -1
- package/core/dist/runtime/pain-submit-capability.js +21 -9
- package/core/dist/runtime/pain-submit-capability.js.map +1 -1
- package/core/dist/runtime/pain-target-evidence-reconcile.d.ts +48 -13
- package/core/dist/runtime/pain-target-evidence-reconcile.d.ts.map +1 -1
- package/core/dist/runtime/pain-target-evidence-reconcile.js +267 -81
- package/core/dist/runtime/pain-target-evidence-reconcile.js.map +1 -1
- package/core/dist/runtime/pain-to-principle-service.d.ts +2 -5
- package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
- package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
- package/core/dist/runtime/store/runtime-state-manager.d.ts +2 -0
- package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
- package/core/dist/runtime/store/runtime-state-manager.js +18 -0
- package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
- package/core/dist/runtime/store/task/memory-task-store.d.ts.map +1 -1
- package/core/dist/runtime/store/task/memory-task-store.js +20 -0
- package/core/dist/runtime/store/task/memory-task-store.js.map +1 -1
- package/core/dist/runtime/store/task/sqlite-task-store.d.ts.map +1 -1
- package/core/dist/runtime/store/task/sqlite-task-store.js +9 -0
- package/core/dist/runtime/store/task/sqlite-task-store.js.map +1 -1
- package/core/dist/runtime/store/task/task-store.d.ts +10 -0
- package/core/dist/runtime/store/task/task-store.d.ts.map +1 -1
- package/core/package.json +1 -1
- package/host-runtime/dist/diagnostician-auto-run.js +20 -14
- package/host-runtime/dist/index.d.ts +3 -1
- package/host-runtime/dist/index.js +15 -1
- package/host-runtime/dist/intent-doc-reader.js +1 -1
- package/host-runtime/dist/internalization-consumer-cycle.d.ts +102 -1
- package/host-runtime/dist/internalization-consumer-cycle.js +177 -95
- package/host-runtime/dist/internalization-consumer-governance.d.ts +2 -1
- package/host-runtime/dist/internalization-consumer-governance.js +57 -2
- package/host-runtime/dist/workspace-pipeline-host-deps.d.ts +65 -0
- package/host-runtime/dist/workspace-pipeline-host-deps.js +94 -0
- package/host-runtime/dist/workspace-telemetry-emitter.js +14 -0
- package/host-runtime/package.json +1 -1
- package/install-layout/dist/index.d.ts +1 -0
- package/install-layout/dist/index.js +1 -0
- package/install-layout/dist/openclaw-config-path.d.ts +9 -0
- package/install-layout/dist/openclaw-config-path.js +64 -0
- package/install-layout/package.json +1 -1
- package/package.json +3 -3
- package/pd-cli/dist/commands/codex-worker.js +2 -2
- package/pd-cli/dist/commands/codex-worker.js.map +1 -1
- package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
- package/pd-cli/dist/commands/diagnose.js +49 -75
- package/pd-cli/dist/commands/diagnose.js.map +1 -1
- package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-record.js +18 -26
- package/pd-cli/dist/commands/pain-record.js.map +1 -1
- package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-retry.js +50 -66
- package/pd-cli/dist/commands/pain-retry.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js +184 -17
- package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-once.js +209 -127
- package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
- package/pd-cli/dist/commands/workbuddy-worker.js +2 -2
- package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -1
- package/pd-cli/dist/services/config-doctor.d.ts.map +1 -1
- package/pd-cli/dist/services/config-doctor.js +7 -4
- package/pd-cli/dist/services/config-doctor.js.map +1 -1
- package/pd-cli/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
- package/pd-cli/dist/services/rulehost-pipeline-runner.js +53 -4
- package/pd-cli/dist/services/rulehost-pipeline-runner.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/pd-mcp-server/dist/server.d.ts +7 -0
- package/pd-mcp-server/dist/server.js +12 -1
- package/pd-mcp-server/dist/submit-assembly.js +2 -1
- package/pd-mcp-server/dist/version.d.ts +1 -1
- package/pd-mcp-server/dist/version.js +1 -1
- package/pd-mcp-server/package.json +1 -1
- package/plugin/dist/bundle.js +532 -496
- package/plugin/dist/core/config-health.d.ts +6 -0
- package/plugin/dist/core/openclaw-config-loader.d.ts +14 -0
- package/plugin/dist/core/pain-service.d.ts +26 -0
- package/plugin/dist/hooks/openclaw-run-turn-correlation.d.ts +30 -0
- package/plugin/dist/hooks/openclaw-target-turn-capture.d.ts +13 -0
- package/plugin/dist/hooks/pain-receipt-fallback.d.ts +107 -0
- package/plugin/dist/openclaw-sdk.d.ts +15 -0
- package/plugin/dist/openclaw-worker.d.ts +3 -0
- package/plugin/dist/openclaw-worker.js +288 -287
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/release-manager/package.json +1 -1
- package/workbuddy-adapter/dist/ingestion/pain-receipt-fallback.js +3 -2
- package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +3 -0
- package/workbuddy-adapter/dist/worker/workspace-worker.js +48 -15
- package/workbuddy-adapter/package.json +1 -1
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* Hosts inject: a logger, a structured-event sink, their tool catalog, and an
|
|
21
21
|
* env getter. Everything else is the existing production path.
|
|
22
22
|
*/
|
|
23
|
-
import { type ToolSemanticRegistry, type BehaviorEvidencePort, type ArtificerTrustedFactsPort } from '@principles/core/runtime';
|
|
23
|
+
import { type PDRuntimeAdapter, type RuntimeStateManager, type ToolSemanticRegistry, type BehaviorEvidencePort, type ArtificerTrustedFactsPort, type TelemetryEvent, type PIArtifactStore, type EffectivePdConfig, type OutputLanguage, type RefinerRuleHostGateDeps, type RolloutAutoDispatchInput, type RolloutAutoDispatchOutcome, type RolloutRevisionRoutingInput, type SeedArtificerRepairParams, type BehaviorExamplePack, type ArtificerHostSemanticContext, type DreamerRunnerResult, type PhilosopherRunnerResult, type ScribeRunnerResult, type ArtificerRunnerResult, type EvaluatorRunnerResult, type RolloutReviewerRunnerResult } from '@principles/core/runtime';
|
|
24
24
|
import { type ConsumerGovernanceLogger } from './internalization-consumer-governance.js';
|
|
25
25
|
export declare const INTERNALIZATION_AUTO_CONSUMER_FLAG_ID = "internalization_auto_consumer";
|
|
26
26
|
/** Structural logger port — OpenClaw PluginLogger and worker loggers satisfy this. */
|
|
@@ -133,6 +133,107 @@ export declare function orderKindsByOldestReadyStage<T extends string>(runnerKin
|
|
|
133
133
|
export declare function oldestReadyAgeMs(readyTasks: readonly {
|
|
134
134
|
createdAt?: string;
|
|
135
135
|
}[], nowMs: number): number | null;
|
|
136
|
+
/**
|
|
137
|
+
* Runner 遥测窄端口 — 与 core `PeerRunnerTelemetryEmitter` 结构等价
|
|
138
|
+
* (该类型不在 core 冻结 barrel 上,此处按结构声明,零新增导出)。
|
|
139
|
+
* StoreEventEmitter 与 WorkspaceTelemetryEmitter 均满足。
|
|
140
|
+
*/
|
|
141
|
+
export interface SelectedTaskTelemetryEmitter {
|
|
142
|
+
readonly emitTelemetry: (event: TelemetryEvent) => unknown;
|
|
143
|
+
}
|
|
144
|
+
/** 全部 kind 共享的调用方依赖。 */
|
|
145
|
+
export interface SelectedInternalizationTaskBaseDeps {
|
|
146
|
+
/** 要执行的已**选中**任务 — 执行租约由 Runner 在 run() 内自行获取, 调用方不在本层租约。 */
|
|
147
|
+
readonly taskId: string;
|
|
148
|
+
readonly stateManager: RuntimeStateManager;
|
|
149
|
+
/** 入口自建的 runtime adapter (含 L2 / test-double 路由决策)。 */
|
|
150
|
+
readonly runtimeAdapter: PDRuntimeAdapter;
|
|
151
|
+
/** 入口选择的遥测口 (consumer evaluator 用 workspace-scoped emitter)。 */
|
|
152
|
+
readonly eventEmitter: SelectedTaskTelemetryEmitter;
|
|
153
|
+
readonly artifactStore: PIArtifactStore;
|
|
154
|
+
/** Workspace 根 — ledgerIdentity 装配的唯一事实来源。 */
|
|
155
|
+
readonly workspaceDir: string;
|
|
156
|
+
}
|
|
157
|
+
/** Runner 构造/执行选项 — 原样转发 (各入口既有语义保持)。 */
|
|
158
|
+
export interface SelectedInternalizationTaskRunnerOptions {
|
|
159
|
+
readonly owner: string;
|
|
160
|
+
readonly runtimeKind: string;
|
|
161
|
+
readonly timeoutMs: number;
|
|
162
|
+
readonly effectiveConfig?: EffectivePdConfig;
|
|
163
|
+
readonly outputLanguage?: OutputLanguage;
|
|
164
|
+
readonly pollIntervalMs?: number;
|
|
165
|
+
}
|
|
166
|
+
/** Evaluator repair 轮的宿主接线 (来自既有 governance deps 工厂,不造第三套)。 */
|
|
167
|
+
export interface SelectedEvaluatorRepairDeps {
|
|
168
|
+
readonly isRepairLoopEnabled: () => boolean;
|
|
169
|
+
readonly seedArtificerRepairTask: (params: SeedArtificerRepairParams) => Promise<string>;
|
|
170
|
+
}
|
|
171
|
+
/** rollout 治理接线 (来自 createRolloutGovernanceDeps)。 */
|
|
172
|
+
export interface SelectedRolloutGovernanceDeps {
|
|
173
|
+
readonly dispatchActivation: (input: RolloutAutoDispatchInput) => Promise<RolloutAutoDispatchOutcome>;
|
|
174
|
+
readonly reopenRevisionTarget: (input: RolloutRevisionRoutingInput) => Promise<{
|
|
175
|
+
ok: boolean;
|
|
176
|
+
reason: string;
|
|
177
|
+
reopenedTaskId?: string;
|
|
178
|
+
}>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* 按 taskKind 收窄的判别联合输入 — 必需依赖在类型层面不可缺失;
|
|
182
|
+
* optional 仅限两个入口现状真实可选的字段 (artificer 的 evidence pack /
|
|
183
|
+
* trustedFacts / hostSemanticContext、evaluator 的宿主目录与语义投影)。
|
|
184
|
+
*/
|
|
185
|
+
export type ExecuteSelectedInternalizationTaskInput = ({
|
|
186
|
+
readonly taskKind: 'dreamer';
|
|
187
|
+
} & SelectedInternalizationTaskBaseDeps & {
|
|
188
|
+
readonly runnerOptions: SelectedInternalizationTaskRunnerOptions;
|
|
189
|
+
}) | ({
|
|
190
|
+
readonly taskKind: 'philosopher';
|
|
191
|
+
} & SelectedInternalizationTaskBaseDeps & {
|
|
192
|
+
readonly runnerOptions: SelectedInternalizationTaskRunnerOptions;
|
|
193
|
+
}) | ({
|
|
194
|
+
readonly taskKind: 'scribe';
|
|
195
|
+
} & SelectedInternalizationTaskBaseDeps & {
|
|
196
|
+
readonly runnerOptions: SelectedInternalizationTaskRunnerOptions;
|
|
197
|
+
}) | ({
|
|
198
|
+
readonly taskKind: 'artificer';
|
|
199
|
+
/** 仅 preflight 通过的入口传入 (consumer evidence ready);run-once 无此能力则缺省。 */
|
|
200
|
+
readonly behaviorExamplePack?: BehaviorExamplePack;
|
|
201
|
+
/** 仅 consumer 传入 — 与 intent preflight 同源的 trusted-facts 端口。 */
|
|
202
|
+
readonly trustedFacts?: ArtificerTrustedFactsPort;
|
|
203
|
+
readonly hostSemanticContext?: ArtificerHostSemanticContext;
|
|
204
|
+
} & SelectedInternalizationTaskBaseDeps & {
|
|
205
|
+
readonly runnerOptions: SelectedInternalizationTaskRunnerOptions;
|
|
206
|
+
}) | ({
|
|
207
|
+
readonly taskKind: 'evaluator';
|
|
208
|
+
/** repair 轮宿主接线 — 缺失即是装配错误,不允许缺省掩盖。 */
|
|
209
|
+
readonly repairDeps: SelectedEvaluatorRepairDeps;
|
|
210
|
+
/** 对抗重放 gate — 两个入口都必须显式提供各自权威解析结果。 */
|
|
211
|
+
readonly gateDeps: RefinerRuleHostGateDeps;
|
|
212
|
+
readonly hostToolCatalog?: ConsumerHostToolCatalog;
|
|
213
|
+
readonly hostSemanticContext?: ArtificerHostSemanticContext;
|
|
214
|
+
} & SelectedInternalizationTaskBaseDeps & {
|
|
215
|
+
readonly runnerOptions: SelectedInternalizationTaskRunnerOptions;
|
|
216
|
+
}) | ({
|
|
217
|
+
readonly taskKind: 'rollout_reviewer';
|
|
218
|
+
readonly governanceDeps: SelectedRolloutGovernanceDeps;
|
|
219
|
+
} & SelectedInternalizationTaskBaseDeps & {
|
|
220
|
+
readonly runnerOptions: SelectedInternalizationTaskRunnerOptions;
|
|
221
|
+
});
|
|
222
|
+
export type SelectedInternalizationTaskRunResult = DreamerRunnerResult | PhilosopherRunnerResult | ScribeRunnerResult | ArtificerRunnerResult | EvaluatorRunnerResult | RolloutReviewerRunnerResult;
|
|
223
|
+
/**
|
|
224
|
+
* Execute ONE selected internalization task with the kind-selected runner.
|
|
225
|
+
* Constructs the runner from the typed input and returns the raw run result.
|
|
226
|
+
*
|
|
227
|
+
* Lease ownership contract (CodeRabbit review fix): the caller is responsible
|
|
228
|
+
* for SELECTING the task (e.g. a dry-run `wakeOnce` `would_lease` candidate);
|
|
229
|
+
* the runner itself acquires the execution lease inside `run()` — callers must
|
|
230
|
+
* NOT lease at this layer. The doc previously demanded an already-leased task,
|
|
231
|
+
* which would lead new callers to acquire the lease at the wrong layer.
|
|
232
|
+
*
|
|
233
|
+
* Runner crashes propagate to the caller (each entry keeps its own crash
|
|
234
|
+
* semantics: consumer rethrows without state writes; run-once logs + rethrows).
|
|
235
|
+
*/
|
|
236
|
+
export declare function executeSelectedInternalizationTask(input: ExecuteSelectedInternalizationTaskInput): Promise<SelectedInternalizationTaskRunResult>;
|
|
136
237
|
/**
|
|
137
238
|
* Run ONE bounded consumer cycle for a workspace. At most one downstream task
|
|
138
239
|
* is leased and executed per cycle (DEFAULT_CONSUMER_MAX_TASKS_PER_CYCLE=1);
|
|
@@ -158,7 +158,16 @@ async function runReconciliationBudget(workspaceDir, orchestrator, ports) {
|
|
|
158
158
|
cursorStore.set(SUCCEEDED_TRANSITIONS_SCOPE, recon.nextCursor);
|
|
159
159
|
}
|
|
160
160
|
const errors = recon.outcomes.filter((o) => o.decision.startsWith('reconcile_error'));
|
|
161
|
-
|
|
161
|
+
// PRI-1293 R6: fail-closed 错误类别 (血缘拒绝/并发冲突/完整性冲突/
|
|
162
|
+
// repair reopen 失败/元数据损坏) 的完整排障信息必须进遥测 — 不得
|
|
163
|
+
// 只留下 blocked 计数而静默丢弃拒绝原因。
|
|
164
|
+
const REFUSAL_DECISIONS = new Set([
|
|
165
|
+
'lineage_refused', 'concurrent_modification', 'successor_integrity_conflict',
|
|
166
|
+
'successor_id_conflict', 'revision_reopen_failed', 'invalid_task_metadata',
|
|
167
|
+
'source_correction_reopen_failed',
|
|
168
|
+
]);
|
|
169
|
+
const refusals = recon.outcomes.filter((o) => REFUSAL_DECISIONS.has(o.decision));
|
|
170
|
+
if (recon.recovered > 0 || errors.length > 0 || refusals.length > 0) {
|
|
162
171
|
emitEvent('INTERNALIZATION_CONSUMER_RECONCILED', JSON.stringify({
|
|
163
172
|
scanned: recon.scanned,
|
|
164
173
|
recovered: recon.recovered,
|
|
@@ -168,6 +177,7 @@ async function runReconciliationBudget(workspaceDir, orchestrator, ports) {
|
|
|
168
177
|
recoveries: recon.outcomes.filter((o) => o.decision === 'successor_created' || o.decision.includes('reopened')),
|
|
169
178
|
// P1 (最终复核): per-task 错误显式可观测 — 即使 recovered=0
|
|
170
179
|
errors,
|
|
180
|
+
refusals,
|
|
171
181
|
}));
|
|
172
182
|
logger.info(`[PD:${logLabel}] Reconciliation: recovered=${recon.recovered} errors=${errors.length} wrapped=${recon.wrappedAround}`);
|
|
173
183
|
}
|
|
@@ -185,6 +195,101 @@ async function runReconciliationBudget(workspaceDir, orchestrator, ports) {
|
|
|
185
195
|
logger.warn(`[PD:${logLabel}] Succeeded-transition reconciliation failed: ${String(reconErr)}`);
|
|
186
196
|
}
|
|
187
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Scribe/Artificer/Evaluator 共用的 ledger 身份装配 — 与两个入口此前内联的
|
|
200
|
+
* 闭包逐字等价 (每次调用新开 PrincipleTreeLedgerAdapter 读盘,无跨周期缓存)。
|
|
201
|
+
*/
|
|
202
|
+
function buildWorkspaceLedgerIdentity(workspaceDir, stateManager) {
|
|
203
|
+
const ledger = () => new PrincipleTreeLedgerAdapter({ stateDir: `${workspaceDir}/.state` });
|
|
204
|
+
return {
|
|
205
|
+
resolveForCandidate: async (candidateId) => {
|
|
206
|
+
const candidate = await stateManager.getCandidate(candidateId);
|
|
207
|
+
return ledger().resolveCandidatePrincipleIdentity(candidateId, candidate?.rawRecommendationKind);
|
|
208
|
+
},
|
|
209
|
+
// PRI-915: availability first — an unreadable ledger must not read as an
|
|
210
|
+
// unresolved chain.
|
|
211
|
+
isAvailable: () => ledger().isAvailable(),
|
|
212
|
+
listForCandidate: (candidateId) => ledger().listForCandidate(candidateId),
|
|
213
|
+
hasPrinciple: (principleId) => ledger().hasPrinciple(principleId),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Execute ONE selected internalization task with the kind-selected runner.
|
|
218
|
+
* Constructs the runner from the typed input and returns the raw run result.
|
|
219
|
+
*
|
|
220
|
+
* Lease ownership contract (CodeRabbit review fix): the caller is responsible
|
|
221
|
+
* for SELECTING the task (e.g. a dry-run `wakeOnce` `would_lease` candidate);
|
|
222
|
+
* the runner itself acquires the execution lease inside `run()` — callers must
|
|
223
|
+
* NOT lease at this layer. The doc previously demanded an already-leased task,
|
|
224
|
+
* which would lead new callers to acquire the lease at the wrong layer.
|
|
225
|
+
*
|
|
226
|
+
* Runner crashes propagate to the caller (each entry keeps its own crash
|
|
227
|
+
* semantics: consumer rethrows without state writes; run-once logs + rethrows).
|
|
228
|
+
*/
|
|
229
|
+
export async function executeSelectedInternalizationTask(input) {
|
|
230
|
+
const { taskId, stateManager, runtimeAdapter, eventEmitter, artifactStore, workspaceDir } = input;
|
|
231
|
+
const { runnerOptions } = input;
|
|
232
|
+
// Evaluator 的身份装配含 hasPrinciple (PRI-911A writer boundary);
|
|
233
|
+
// Scribe 另需 listForCandidate (chain stamping);Artificer 只读解析。
|
|
234
|
+
// 一次装配、按 kind 结构化满足各自 deps 形状。
|
|
235
|
+
const ledgerIdentity = buildWorkspaceLedgerIdentity(workspaceDir, stateManager);
|
|
236
|
+
switch (input.taskKind) {
|
|
237
|
+
case 'dreamer':
|
|
238
|
+
return new DreamerRunner({ stateManager, runtimeAdapter, eventEmitter, artifactStore, validator: new DefaultDreamerValidator() }, runnerOptions).run(taskId);
|
|
239
|
+
case 'philosopher':
|
|
240
|
+
return new PhilosopherRunner({ stateManager, runtimeAdapter, eventEmitter, artifactStore, validator: new DefaultPhilosopherValidator() }, runnerOptions).run(taskId);
|
|
241
|
+
case 'scribe':
|
|
242
|
+
return new ScribeRunner({
|
|
243
|
+
stateManager, runtimeAdapter, eventEmitter, artifactStore,
|
|
244
|
+
validator: new DefaultScribeValidator({ requireRuleCodeContracts: true }),
|
|
245
|
+
// I2 — CHAIN STAMPING (Owner review of PR #1856, P1): 完整三元身份
|
|
246
|
+
// (resolveForCandidate / isAvailable / listForCandidate)。
|
|
247
|
+
ledgerIdentity,
|
|
248
|
+
}, runnerOptions).run(taskId);
|
|
249
|
+
case 'artificer':
|
|
250
|
+
return new ArtificerRunner({
|
|
251
|
+
stateManager, runtimeAdapter, eventEmitter, artifactStore,
|
|
252
|
+
validator: new DefaultArtificerValidator(),
|
|
253
|
+
ledgerIdentity,
|
|
254
|
+
...(input.behaviorExamplePack !== undefined ? { behaviorExamplePack: input.behaviorExamplePack } : {}),
|
|
255
|
+
...(input.trustedFacts !== undefined ? { trustedFacts: input.trustedFacts } : {}),
|
|
256
|
+
}, {
|
|
257
|
+
...runnerOptions,
|
|
258
|
+
...(input.hostSemanticContext !== undefined ? { hostSemanticContext: input.hostSemanticContext } : {}),
|
|
259
|
+
}).run(taskId);
|
|
260
|
+
case 'evaluator': {
|
|
261
|
+
const evaluatorLedgerIdentity = {
|
|
262
|
+
resolveForCandidate: ledgerIdentity.resolveForCandidate,
|
|
263
|
+
isAvailable: ledgerIdentity.isAvailable,
|
|
264
|
+
hasPrinciple: ledgerIdentity.hasPrinciple,
|
|
265
|
+
};
|
|
266
|
+
return new EvaluatorRunner({
|
|
267
|
+
stateManager,
|
|
268
|
+
runtimeAdapter,
|
|
269
|
+
eventEmitter,
|
|
270
|
+
artifactStore,
|
|
271
|
+
validator: new DefaultEvaluatorValidator(),
|
|
272
|
+
ledgerIdentity: evaluatorLedgerIdentity,
|
|
273
|
+
isRepairLoopEnabled: input.repairDeps.isRepairLoopEnabled,
|
|
274
|
+
seedArtificerRepairTask: input.repairDeps.seedArtificerRepairTask,
|
|
275
|
+
}, {
|
|
276
|
+
...runnerOptions,
|
|
277
|
+
gateDeps: input.gateDeps,
|
|
278
|
+
...(input.hostToolCatalog !== undefined
|
|
279
|
+
? { hostToolCatalog: { readOnlyTools: [...input.hostToolCatalog.readOnlyTools], writeTools: [...input.hostToolCatalog.writeTools] } }
|
|
280
|
+
: {}),
|
|
281
|
+
...(input.hostSemanticContext !== undefined ? { hostSemanticContext: input.hostSemanticContext } : {}),
|
|
282
|
+
}).run(taskId);
|
|
283
|
+
}
|
|
284
|
+
case 'rollout_reviewer':
|
|
285
|
+
return new RolloutReviewerRunner({
|
|
286
|
+
stateManager, runtimeAdapter, eventEmitter, artifactStore,
|
|
287
|
+
validator: new DefaultRolloutReviewerValidator(),
|
|
288
|
+
dispatchActivation: input.governanceDeps.dispatchActivation,
|
|
289
|
+
reopenRevisionTarget: input.governanceDeps.reopenRevisionTarget,
|
|
290
|
+
}, runnerOptions).run(taskId);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
188
293
|
/**
|
|
189
294
|
* Run ONE bounded consumer cycle for a workspace. At most one downstream task
|
|
190
295
|
* is leased and executed per cycle (DEFAULT_CONSUMER_MAX_TASKS_PER_CYCLE=1);
|
|
@@ -735,126 +840,80 @@ async function executeConsumerCycle(workspaceDir, ports, signals) {
|
|
|
735
840
|
// degrade through the host's structured event port, never break the runner.
|
|
736
841
|
// (PRI-795 review P1: the emitter itself is constructed above, before the
|
|
737
842
|
// adapter dispatch, so the ArtificerL2 adapter can share it.)
|
|
843
|
+
// PRI-1293 Phase 2B: 构造执行器输入并交由唯一权威实现执行。逐 kind 的
|
|
844
|
+
// 差异只剩「哪些类型化依赖由本入口提供」(eventEmitter 选择、evidence
|
|
845
|
+
// pack、repair/governance 接线、宿主目录/语义投影) — Runner 构造本体
|
|
846
|
+
// 收编进 executeSelectedInternalizationTask。
|
|
738
847
|
// Dispatch by leased task kind. Only kinds listed in
|
|
739
848
|
// FULL_CHAIN_CONSUMER_RUNNER_KINDS can be leased here; anything else
|
|
740
849
|
// (e.g. diagnostician) hits the default branch — fail loud if it does (EP-03).
|
|
741
|
-
let
|
|
850
|
+
let executionInput = null;
|
|
742
851
|
switch (taskKind) {
|
|
743
852
|
case 'dreamer':
|
|
744
|
-
|
|
853
|
+
executionInput = {
|
|
854
|
+
taskKind, taskId, workspaceDir, stateManager, runtimeAdapter: adapter,
|
|
855
|
+
eventEmitter: storeEmitter, artifactStore: stateManager.piArtifactStore, runnerOptions,
|
|
856
|
+
};
|
|
745
857
|
break;
|
|
746
858
|
case 'philosopher':
|
|
747
|
-
|
|
859
|
+
executionInput = {
|
|
860
|
+
taskKind, taskId, workspaceDir, stateManager, runtimeAdapter: adapter,
|
|
861
|
+
eventEmitter: storeEmitter, artifactStore: stateManager.piArtifactStore, runnerOptions,
|
|
862
|
+
};
|
|
748
863
|
break;
|
|
749
864
|
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);
|
|
865
|
+
executionInput = {
|
|
866
|
+
taskKind, taskId, workspaceDir, stateManager, runtimeAdapter: adapter,
|
|
867
|
+
eventEmitter: storeEmitter, artifactStore: stateManager.piArtifactStore, runnerOptions,
|
|
868
|
+
};
|
|
769
869
|
break;
|
|
770
870
|
case 'artificer':
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
const candidate = await stateManager.getCandidate(candidateId);
|
|
775
|
-
return new PrincipleTreeLedgerAdapter({ stateDir: `${workspaceDir}/.state` }).resolveCandidatePrincipleIdentity(candidateId, candidate?.rawRecommendationKind);
|
|
776
|
-
} },
|
|
871
|
+
executionInput = {
|
|
872
|
+
taskKind, taskId, workspaceDir, stateManager, runtimeAdapter: adapter,
|
|
873
|
+
eventEmitter: storeEmitter, artifactStore: stateManager.piArtifactStore, runnerOptions,
|
|
777
874
|
// PRI-982 (SPEC-PD-IAER-001 FR-02): the preflight-assembled Owner
|
|
778
875
|
// 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).
|
|
876
|
+
// code_tool_hook AND the readiness gate returned ready.
|
|
781
877
|
...(artificerEvidence !== null && artificerEvidence.decision === 'ready'
|
|
782
878
|
? { behaviorExamplePack: artificerEvidence.pack }
|
|
783
879
|
: {}),
|
|
784
880
|
// SPEC-RULECODE-QUALITY-001 A1 (Owner review P2): the SAME
|
|
785
881
|
// 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.
|
|
882
|
+
// runner so the defensive mirror sees the same fact resolutions.
|
|
789
883
|
...(ports.trustedFacts !== undefined ? { trustedFacts: ports.trustedFacts } : {}),
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
884
|
+
// PRI-741: thread the host semantic projection into generation.
|
|
885
|
+
...(artificerHostSemanticContext !== undefined ? { hostSemanticContext: artificerHostSemanticContext } : {}),
|
|
886
|
+
};
|
|
793
887
|
break;
|
|
794
888
|
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.
|
|
889
|
+
// P0-D 生产接线 / PRI-630 / PRI-634 A1+A3 注释语义保持: repair deps
|
|
890
|
+
// 来自既有 governance 工厂; gateDeps 是 evaluator production
|
|
891
|
+
// semantics (options 第二参由执行器装配), 宿主目录/语义投影可选透传。
|
|
892
|
+
executionInput = {
|
|
893
|
+
taskKind, taskId, workspaceDir, stateManager, runtimeAdapter: adapter,
|
|
894
|
+
// PRI-634 A3: workspace-scoped telemetry — evaluator 事件归属本
|
|
895
|
+
// workspace (multi-workspace 隔离), 其余 kind 走全局 storeEmitter。
|
|
896
|
+
eventEmitter: workspaceEmitter,
|
|
897
|
+
artifactStore: stateManager.piArtifactStore,
|
|
898
|
+
runnerOptions,
|
|
899
|
+
repairDeps: createEvaluatorRepairDeps(workspaceDir, stateManager, logger),
|
|
832
900
|
gateDeps: createProductionGateDeps({
|
|
833
901
|
...(toolSemantics ? { toolSemantics } : {}),
|
|
834
902
|
projectDir: workspaceDir,
|
|
835
903
|
}),
|
|
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.
|
|
904
|
+
...(hostToolCatalog ? { hostToolCatalog } : {}),
|
|
841
905
|
...(artificerHostSemanticContext !== undefined ? { hostSemanticContext: artificerHostSemanticContext } : {}),
|
|
842
|
-
}
|
|
906
|
+
};
|
|
843
907
|
break;
|
|
844
908
|
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);
|
|
909
|
+
// Lineage echo reconciliation is built into the runner; P0-E/F 治理接线
|
|
910
|
+
// (approve_rollout → approvals.pending; needs_revision → reopen, INV-04)
|
|
911
|
+
// 来自既有 governance 工厂 — Owner 审批绝不被绕过。
|
|
912
|
+
executionInput = {
|
|
913
|
+
taskKind, taskId, workspaceDir, stateManager, runtimeAdapter: adapter,
|
|
914
|
+
eventEmitter: storeEmitter, artifactStore: stateManager.piArtifactStore, runnerOptions,
|
|
915
|
+
governanceDeps: createRolloutGovernanceDeps(workspaceDir, orchestrator, { logger, ...(toolSemantics ? { toolSemantics } : {}) }),
|
|
916
|
+
};
|
|
858
917
|
break;
|
|
859
918
|
default:
|
|
860
919
|
emitEvent('INTERNALIZATION_CONSUMER_SKIP', JSON.stringify({ decision: 'no_runner_for_kind', taskKind }));
|
|
@@ -876,7 +935,7 @@ async function executeConsumerCycle(workspaceDir, ports, signals) {
|
|
|
876
935
|
}));
|
|
877
936
|
let runResult;
|
|
878
937
|
try {
|
|
879
|
-
runResult = await
|
|
938
|
+
runResult = await executeSelectedInternalizationTask(executionInput);
|
|
880
939
|
}
|
|
881
940
|
catch (runErr) {
|
|
882
941
|
logger.error(`[PD:${logLabel}] Runner crashed for task ${taskId}: ${String(runErr)}`);
|
|
@@ -899,10 +958,33 @@ async function executeConsumerCycle(workspaceDir, ports, signals) {
|
|
|
899
958
|
emitEvent('INTERNALIZATION_CONSUMER_COMMIT_FAILED', JSON.stringify({ taskId, error: String(commitErr).slice(0, 300) }));
|
|
900
959
|
logger.warn(`[PD:${logLabel}] Task ${taskId} succeeded but successor proposal failed: ${String(commitErr).slice(0, 200)}`);
|
|
901
960
|
}
|
|
961
|
+
// PRI-1293 R6: 结构化 successor 事件 — decision 之外的排障字段
|
|
962
|
+
// (reason/detail/冲突 id 集合/reopened 目标) 必须透出, repair reopen
|
|
963
|
+
// 失败不得只留下一个模糊 decision 名。
|
|
964
|
+
const successorTelemetry = {};
|
|
965
|
+
if (commitResult) {
|
|
966
|
+
successorTelemetry.successorDecision = commitResult.decision;
|
|
967
|
+
if ('reason' in commitResult && typeof commitResult.reason === 'string') {
|
|
968
|
+
successorTelemetry.successorReason = commitResult.reason;
|
|
969
|
+
}
|
|
970
|
+
if ('detail' in commitResult && typeof commitResult.detail === 'string') {
|
|
971
|
+
successorTelemetry.successorDetail = commitResult.detail;
|
|
972
|
+
}
|
|
973
|
+
if ('conflictingSuccessorTaskIds' in commitResult && Array.isArray(commitResult.conflictingSuccessorTaskIds)) {
|
|
974
|
+
successorTelemetry.successorConflictingTaskIds = [...commitResult.conflictingSuccessorTaskIds];
|
|
975
|
+
}
|
|
976
|
+
successorTelemetry.sourceTaskId = 'sourceTaskId' in commitResult ? commitResult.sourceTaskId : taskId;
|
|
977
|
+
if ('reopenedTaskId' in commitResult && typeof commitResult.reopenedTaskId === 'string') {
|
|
978
|
+
successorTelemetry.reopenedTaskId = commitResult.reopenedTaskId;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
else {
|
|
982
|
+
successorTelemetry.successorDecision = 'commit_failed';
|
|
983
|
+
}
|
|
902
984
|
emitEvent('INTERNALIZATION_CONSUMER_SUCCESS', JSON.stringify({
|
|
903
985
|
taskId,
|
|
904
986
|
status: runResult.status,
|
|
905
|
-
...
|
|
987
|
+
...successorTelemetry,
|
|
906
988
|
}));
|
|
907
989
|
logger.info(`[PD:${logLabel}] Task ${taskId} succeeded. Successor: ${commitResult ? commitResult.decision : 'commit_failed'}`);
|
|
908
990
|
return { ran: true, taskId, taskKind, runStatus: 'succeeded' };
|
|
@@ -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 { 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;
|
|
@@ -14,7 +14,10 @@
|
|
|
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, createPITaskDiagnosticJson, artificerRepairTaskId, computeFeatureFlagsFromConfig, isFeatureEnabled, } from '@principles/core/runtime';
|
|
17
|
+
import { ActivationDispatcher, PromptWriter, DeferArchiveWriter, RuleHostWriter, SqliteConnection, SqliteActivationStateStore, SqliteApprovalQueueStore, SqlitePIArtifactStore, PrincipleTreeLedgerAdapter, createProductionGateDeps, createPITaskDiagnosticJson, mergePITaskMetadata, hydratePITaskRecord, artificerRepairTaskId, verifyRepairTaskIdentity, computeFeatureFlagsFromConfig, isFeatureEnabled, } from '@principles/core/runtime';
|
|
18
|
+
// PRI-1293 Phase 3: InternalizationOrchestrator.resolveAuthoritativeCorrelationId
|
|
19
|
+
// 静态只读包装 — 跨包访问唯一血缘权威的授权通道 (core 内部模块不进 barrel)。
|
|
20
|
+
import { InternalizationOrchestrator } from '@principles/core/runtime';
|
|
18
21
|
import { loadPdConfigForPlugin } from './pd-config.js';
|
|
19
22
|
function normalizeDecision(decision) {
|
|
20
23
|
if (decision.decision === 'activated') {
|
|
@@ -158,9 +161,59 @@ export function createEvaluatorRepairDeps(workspaceDir, stateManager, logger) {
|
|
|
158
161
|
if (existing.status === 'succeeded' || existing.status === 'failed' || existing.status === 'needs_human_review') {
|
|
159
162
|
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)`);
|
|
160
163
|
}
|
|
164
|
+
// PRI-1293 R7 (P1-1): 复用前完整身份验证 — 共享 core 唯一实现
|
|
165
|
+
// (verifyRepairTaskIdentity), 与 pd-cli seeder / orchestrator 完成
|
|
166
|
+
// 路径同一规则: payload 存在+来源/iteration 一致+taskId 互证+来源
|
|
167
|
+
// evaluator 真实+parent/correlation 一致+channel 一致。缺失亲缘字段
|
|
168
|
+
// 可 CAS 回填, payload 身份不符一律 fail-closed。
|
|
169
|
+
const identity = await verifyRepairTaskIdentity(existing, params.repairPayload.sourceEvaluatorTaskId, params.repairPayload.repairIteration, stateManager);
|
|
170
|
+
if (!identity.ok) {
|
|
171
|
+
throw new Error(`evaluator_repair_seed_lineage_refused:${identity.reason}:${identity.detail}`);
|
|
172
|
+
}
|
|
173
|
+
const existingPi = hydratePITaskRecord(existing);
|
|
174
|
+
if (!existingPi) {
|
|
175
|
+
throw new Error(`evaluator_repair_seed_lineage_refused:invalid_task_metadata:repair task ${repairTaskId} diagnosticJson unreadable`);
|
|
176
|
+
}
|
|
177
|
+
if (identity.needsLineageBackfill) {
|
|
178
|
+
// 旧任务缺亲缘字段 — 按权威来源补齐 ( merge 保持其余 28 字段 ),
|
|
179
|
+
// CAS 断言读取时的完整状态; 并发被触碰则放弃并结构化抛出, 下一轮
|
|
180
|
+
// seed 重试 (播种幂等, 重试安全)。
|
|
181
|
+
const merged = mergePITaskMetadata(existingPi, {
|
|
182
|
+
parentTaskId: params.repairPayload.sourceEvaluatorTaskId,
|
|
183
|
+
correlationId: identity.authoritativeCorrelationId,
|
|
184
|
+
});
|
|
185
|
+
const casResult = await stateManager.updateTaskIfDiagnosticJsonUnchanged(repairTaskId, existing.diagnosticJson ?? null, { diagnosticJson: createPITaskDiagnosticJson(merged) }, {
|
|
186
|
+
expectedStatus: existing.status,
|
|
187
|
+
expectedAttemptCount: existing.attemptCount,
|
|
188
|
+
expectedMaxAttempts: existing.maxAttempts,
|
|
189
|
+
expectedLeaseOwner: existing.leaseOwner ?? null,
|
|
190
|
+
expectedLeaseExpiresAt: existing.leaseExpiresAt ?? null,
|
|
191
|
+
expectedLeaseGeneration: existing.leaseGeneration ?? 0,
|
|
192
|
+
});
|
|
193
|
+
if (casResult === null) {
|
|
194
|
+
throw new Error(`evaluator_repair_seed_concurrent_modification: repair task ${repairTaskId} changed during lineage backfill — seed NOT applied, safe to retry`);
|
|
195
|
+
}
|
|
196
|
+
logger?.info?.(`[PD:Consumer] repair task ${repairTaskId} lineage backfilled (parentTaskId + correlationId ${identity.authoritativeCorrelationId}) before reuse`);
|
|
197
|
+
}
|
|
161
198
|
logger?.info?.(`[PD:Consumer] repair task ${repairTaskId} already exists (in-flight ${existing.status}); reusing (idempotent seed)`);
|
|
162
199
|
return repairTaskId;
|
|
163
200
|
}
|
|
201
|
+
// PRI-1293 Phase 3 (§5.2): repair 任务创建前从来源 evaluator 恢复权威
|
|
202
|
+
// 血缘 — 校验失败结构化抛出 (流入 evaluator 的 repair_task_seed_failed →
|
|
203
|
+
// seed_failed 路径), 绝不创建无血缘后继; 成功则把验证过的 correlationId
|
|
204
|
+
// 与 parentTaskId=sourceEvaluatorTaskId 写入 repair metadata (既有
|
|
205
|
+
// createPITaskDiagnosticJson 机制), 使 repair 链可回溯根 dreamer、
|
|
206
|
+
// 下一轮 evaluator 经 mergePITaskMetadata 天然继承同一 id。不信任
|
|
207
|
+
// runner 调用方传入的任何 candidateId (SeedArtificerRepairParams 本就
|
|
208
|
+
// 无此字段)。
|
|
209
|
+
const sourceEvaluatorTask = await stateManager.getTask(params.repairPayload.sourceEvaluatorTaskId);
|
|
210
|
+
if (!sourceEvaluatorTask) {
|
|
211
|
+
throw new Error(`evaluator_repair_seed_lineage_refused: source evaluator task ${params.repairPayload.sourceEvaluatorTaskId} not found`);
|
|
212
|
+
}
|
|
213
|
+
const lineage = await InternalizationOrchestrator.resolveAuthoritativeCorrelationId(sourceEvaluatorTask, (taskId) => stateManager.getTask(taskId));
|
|
214
|
+
if (!lineage.ok) {
|
|
215
|
+
throw new Error(`evaluator_repair_seed_lineage_refused:${lineage.reason}:${lineage.detail}`);
|
|
216
|
+
}
|
|
164
217
|
await stateManager.createTask({
|
|
165
218
|
taskId: repairTaskId,
|
|
166
219
|
taskKind: 'artificer',
|
|
@@ -174,13 +227,15 @@ export function createEvaluatorRepairDeps(workspaceDir, stateManager, logger) {
|
|
|
174
227
|
timeoutMs: params.inheritedTimeoutMs,
|
|
175
228
|
inputArtifactRefs: [...params.inheritedInputArtifactRefs],
|
|
176
229
|
outputArtifactRefs: [],
|
|
230
|
+
parentTaskId: params.repairPayload.sourceEvaluatorTaskId,
|
|
231
|
+
correlationId: lineage.correlationId,
|
|
177
232
|
...(params.ownerEvidenceSelection !== undefined
|
|
178
233
|
? { ownerEvidenceSelection: params.ownerEvidenceSelection }
|
|
179
234
|
: {}),
|
|
180
235
|
repairPayload: params.repairPayload,
|
|
181
236
|
}),
|
|
182
237
|
});
|
|
183
|
-
logger?.info?.(`[PD:Consumer] seeded artificer repair task ${repairTaskId} (iteration ${params.repairPayload.repairIteration})`);
|
|
238
|
+
logger?.info?.(`[PD:Consumer] seeded artificer repair task ${repairTaskId} (iteration ${params.repairPayload.repairIteration}, correlationId ${lineage.correlationId}${lineage.recoveredFromLegacyRoot ? ', recovered from legacy root' : ''})`);
|
|
184
239
|
return repairTaskId;
|
|
185
240
|
},
|
|
186
241
|
};
|
|
@@ -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;
|