create-principles-disciple 1.150.6 → 1.152.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/_release/product-identity.json +1 -1
- package/codex-adapter/dist/ingestion/codex-version.d.ts +14 -12
- package/codex-adapter/dist/ingestion/codex-version.js +19 -20
- package/codex-adapter/package.json +1 -1
- package/console/dist/server/bind-guard.d.ts +6 -13
- package/console/dist/server/bind-guard.js +8 -17
- package/console/dist/server/index.d.ts +9 -3
- package/console/dist/server/index.js +55 -53
- package/console/dist/server/models/ActivationsConsoleModel.js +2 -1
- package/console/dist/server/models/OwnerDecisionConsoleModel.js +58 -19
- package/console/dist/server/routes/activations.js +2 -2
- package/console/dist/server/routes/diagnostician.js +1 -1
- package/console/dist/server/routes/evidence-outcomes.d.ts +3 -2
- package/console/dist/server/routes/evidence-outcomes.js +1 -1
- package/console/dist/server/routes/failed-tasks.js +85 -2
- package/console/dist/server/routes/governance.d.ts +9 -6
- package/console/dist/server/routes/governance.js +10 -6
- package/console/dist/server/routes/owner-decisions.d.ts +3 -3
- package/console/dist/server/routes/owner-decisions.js +1 -1
- package/console/dist/server/routes/owner-identity.d.ts +4 -5
- package/console/dist/server/routes/owner-identity.js +4 -4
- package/console/dist/server/routes/rule-candidate-bindings.js +1 -1
- package/console/dist/server/routes/update.js +24 -6
- package/console/dist/server/utils/request-guard.d.ts +35 -0
- package/console/dist/server/utils/request-guard.js +81 -0
- package/console/dist/server/utils/response.d.ts +0 -1
- package/console/dist/server/utils/response.js +0 -3
- package/console/dist/web/assets/app.css +95 -167
- package/console/dist/web/assets/app.js +32 -37
- package/core/dist/runtime/activation/activation-control-types.d.ts +3 -0
- package/core/dist/runtime/activation/activation-control-types.d.ts.map +1 -1
- package/core/dist/runtime/activation/ledger-identity.d.ts.map +1 -1
- package/core/dist/runtime/activation/ledger-identity.js +5 -0
- package/core/dist/runtime/activation/ledger-identity.js.map +1 -1
- package/core/dist/runtime/activation/prompt-activation-reader-contract.d.ts +6 -0
- package/core/dist/runtime/activation/prompt-activation-reader-contract.d.ts.map +1 -1
- package/core/dist/runtime/activation/prompt-activation-reader-contract.js +105 -7
- package/core/dist/runtime/activation/prompt-activation-reader-contract.js.map +1 -1
- package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts.map +1 -1
- package/core/dist/runtime/activation/rulecode-owner-decision-service.js +3 -2
- package/core/dist/runtime/activation/rulecode-owner-decision-service.js.map +1 -1
- package/core/dist/runtime/activation/sqlite-activation-safety-store.d.ts.map +1 -1
- package/core/dist/runtime/activation/sqlite-activation-safety-store.js +26 -13
- package/core/dist/runtime/activation/sqlite-activation-safety-store.js.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js +22 -8
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js.map +1 -1
- package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js +10 -1
- package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js.map +1 -1
- package/core/dist/runtime/adapter/structured-output-repair.d.ts +17 -2
- package/core/dist/runtime/adapter/structured-output-repair.d.ts.map +1 -1
- package/core/dist/runtime/adapter/structured-output-repair.js +26 -5
- package/core/dist/runtime/adapter/structured-output-repair.js.map +1 -1
- package/core/dist/runtime/governance-experience-contract.d.ts +12 -12
- package/core/dist/runtime/governance-experience-contract.d.ts.map +1 -1
- package/core/dist/runtime/governance-experience-contract.js +0 -2
- package/core/dist/runtime/governance-experience-contract.js.map +1 -1
- package/core/dist/runtime/governance-experience.d.ts.map +1 -1
- package/core/dist/runtime/governance-experience.js +8 -16
- package/core/dist/runtime/governance-experience.js.map +1 -1
- package/core/dist/runtime/internalization/approved-rule-revision.d.ts.map +1 -1
- package/core/dist/runtime/internalization/approved-rule-revision.js +2 -1
- package/core/dist/runtime/internalization/approved-rule-revision.js.map +1 -1
- package/core/dist/runtime/internalization/pitask-metadata.d.ts +1 -1
- package/core/dist/runtime/internalization/pitask-metadata.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts +13 -0
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.js +28 -4
- package/core/dist/runtime/internalization/rollout-reviewer-runner.js.map +1 -1
- package/core/dist/runtime/internalization/scribe-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/scribe-runner.js +25 -3
- package/core/dist/runtime/internalization/scribe-runner.js.map +1 -1
- package/core/dist/runtime/recovery-sweep-service.d.ts +7 -0
- package/core/dist/runtime/recovery-sweep-service.d.ts.map +1 -1
- package/core/dist/runtime/recovery-sweep-service.js +1 -0
- package/core/dist/runtime/recovery-sweep-service.js.map +1 -1
- package/core/dist/runtime/signal-collector/types.d.ts +6 -0
- package/core/dist/runtime/signal-collector/types.d.ts.map +1 -1
- package/core/dist/runtime/signal-collector/types.js.map +1 -1
- package/core/dist/runtime/store/context/promoted-evidence-reader.d.ts +59 -0
- package/core/dist/runtime/store/context/promoted-evidence-reader.d.ts.map +1 -0
- package/core/dist/runtime/store/context/promoted-evidence-reader.js +201 -0
- package/core/dist/runtime/store/context/promoted-evidence-reader.js.map +1 -0
- package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
- package/core/dist/runtime/store/context/sqlite-context-assembler.js +43 -2
- package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
- package/core/dist/runtime/store/sqlite-connection.d.ts.map +1 -1
- package/core/dist/runtime/store/sqlite-connection.js +96 -37
- package/core/dist/runtime/store/sqlite-connection.js.map +1 -1
- package/core/dist/runtime/types/rule-candidate-binding.d.ts +1 -1
- package/core/dist/runtime/types/rule-candidate-binding.d.ts.map +1 -1
- package/core/package.json +1 -1
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -1
- package/dist/installer.d.ts +49 -0
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +118 -78
- package/dist/installer.js.map +1 -1
- package/dist/installers/index.d.ts +31 -0
- package/dist/installers/index.d.ts.map +1 -1
- package/dist/installers/index.js +76 -3
- package/dist/installers/index.js.map +1 -1
- package/dist/mvp-config.js +1 -1
- package/dist/mvp-config.js.map +1 -1
- package/dist/update/data-compatibility.d.ts.map +1 -1
- package/dist/update/data-compatibility.js +3 -1
- package/dist/update/data-compatibility.js.map +1 -1
- package/dist/update/release-manager.d.ts +6 -1
- package/dist/update/release-manager.d.ts.map +1 -1
- package/dist/update/release-manager.js +56 -3
- package/dist/update/release-manager.js.map +1 -1
- package/host-runtime/dist/active-principle-prompt.js +1 -0
- package/host-runtime/dist/adaptive-decision-protocol.d.ts +36 -8
- package/host-runtime/dist/adaptive-decision-protocol.js +79 -20
- package/host-runtime/dist/adaptive-selection.js +6 -1
- package/host-runtime/dist/cli-recovery-probe.d.ts +42 -1
- package/host-runtime/dist/cli-recovery-probe.js +16 -3
- package/host-runtime/dist/conversation-ingestion/pipeline.d.ts +0 -29
- package/host-runtime/dist/conversation-ingestion/pipeline.js +39 -2
- package/host-runtime/dist/governance-signal-admission.js +12 -0
- package/host-runtime/dist/prompt-activation-deliverability.d.ts +2 -0
- package/host-runtime/dist/prompt-activation-deliverability.js +2 -0
- package/host-runtime/dist/prompt-injection-status.js +1 -0
- package/host-runtime/package.json +1 -1
- package/install-layout/dist/mcp-binding-contract.js +5 -0
- package/install-layout/package.json +1 -1
- package/package.json +3 -3
- package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
- package/pd-cli/dist/commands/candidate.js +117 -3
- package/pd-cli/dist/commands/candidate.js.map +1 -1
- package/pd-cli/dist/commands/console.d.ts +0 -4
- package/pd-cli/dist/commands/console.d.ts.map +1 -1
- package/pd-cli/dist/commands/console.js +8 -63
- package/pd-cli/dist/commands/console.js.map +1 -1
- package/pd-cli/dist/commands/runtime-activation.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-activation.js +4 -8
- package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
- package/pd-cli/dist/commands/runtime-recovery-failed-tasks.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-recovery-failed-tasks.js +114 -63
- package/pd-cli/dist/commands/runtime-recovery-failed-tasks.js.map +1 -1
- package/pd-cli/dist/program.d.ts.map +1 -1
- package/pd-cli/dist/program.js +0 -8
- package/pd-cli/dist/program.js.map +1 -1
- package/pd-cli/dist/services/console-launcher.d.ts +13 -15
- package/pd-cli/dist/services/console-launcher.d.ts.map +1 -1
- package/pd-cli/dist/services/console-launcher.js +3 -85
- package/pd-cli/dist/services/console-launcher.js.map +1 -1
- package/pd-cli/package.json +1 -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 +469 -452
- package/plugin/dist/core/mcp-binding.d.ts +3 -1
- package/plugin/dist/core/signal-collector-host.d.ts +19 -1
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/mcp/launcher.cjs +85 -0
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/release-manager/dist/installer.js +118 -78
- package/release-manager/dist/installers/index.js +76 -3
- package/release-manager/dist/mvp-config.js +1 -1
- package/release-manager/dist/update/release-manager.js +56 -3
- package/release-manager/package.json +1 -1
- package/workbuddy-adapter/package.json +1 -1
- package/workbuddy-adapter/plugin/mcp/launcher.cjs +85 -0
- package/console/dist/server/config/AuthConfig.d.ts +0 -14
- package/console/dist/server/config/AuthConfig.js +0 -42
|
@@ -8,19 +8,30 @@
|
|
|
8
8
|
* The difference from the lab experiment is the QUESTION SET: the lab asked
|
|
9
9
|
* four task-level questions, while production asks one independent
|
|
10
10
|
* applicability condition per candidate plus one "insufficient context"
|
|
11
|
-
* condition.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* condition. A candidate that would replace an activation answers TWO
|
|
12
|
+
* independent conditions instead (incoming value, outgoing safety), because a
|
|
13
|
+
* single blended score cannot tell "this principle does not fit" apart from
|
|
14
|
+
* "dropping the other principle is unsafe". Each answer is an independent
|
|
15
|
+
* `noul` score in [0, 1] — not a distribution — so PD adjudicates locally
|
|
16
|
+
* instead of trusting the model to emit a decision.
|
|
14
17
|
*
|
|
15
18
|
* Everything here is pure: no I/O, no clock, no transport. The caller owns
|
|
16
19
|
* scheduling, cancellation and diagnostics.
|
|
17
20
|
*/
|
|
18
21
|
export const ADAPTIVE_DECISION_MAX_CANDIDATE_CHARS = 600;
|
|
19
22
|
export const ADAPTIVE_DECISION_INSUFFICIENT_QUESTION = 'insufficient_context';
|
|
20
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Preset applicability and context guards. Scores are model judgments, not
|
|
25
|
+
* calibrated probabilities.
|
|
26
|
+
*
|
|
27
|
+
* v3: a replaceable candidate is scored by TWO independent conditions
|
|
28
|
+
* (incoming value, outgoing safety). The append path keeps the single
|
|
29
|
+
* condition of v2 unchanged, which is why the version bump is required to
|
|
30
|
+
* tell the two evidence generations apart.
|
|
31
|
+
*/
|
|
21
32
|
export const ADAPTIVE_DECISION_CRITERIA = {
|
|
22
|
-
version: '
|
|
23
|
-
/** A candidate must reach this
|
|
33
|
+
version: 'v3-20261112',
|
|
34
|
+
/** A candidate (and, when it replaces something, its safety condition) must reach this score. */
|
|
24
35
|
selectThreshold: 0.7,
|
|
25
36
|
/** Above this "information is insufficient" score, PD refuses to select. */
|
|
26
37
|
insufficientThreshold: 0.6,
|
|
@@ -28,19 +39,46 @@ export const ADAPTIVE_DECISION_CRITERIA = {
|
|
|
28
39
|
export function candidateQuestionId(ref) {
|
|
29
40
|
return `candidate_${ref}`;
|
|
30
41
|
}
|
|
42
|
+
/** Replaceable candidates answer the incoming-value question under this id. */
|
|
43
|
+
export function candidateValueQuestionId(ref) {
|
|
44
|
+
return `candidate_${ref}_value`;
|
|
45
|
+
}
|
|
46
|
+
/** Replaceable candidates answer the outgoing-safety question under this id. */
|
|
47
|
+
export function candidateSafetyQuestionId(ref) {
|
|
48
|
+
return `candidate_${ref}_safety`;
|
|
49
|
+
}
|
|
31
50
|
/**
|
|
32
51
|
* One question per candidate (its applicability condition) plus one
|
|
33
52
|
* "insufficient context" question. Instructions refer to the snapshot by ref;
|
|
34
53
|
* the candidate text itself travels once, in `state`.
|
|
54
|
+
*
|
|
55
|
+
* A candidate that would REPLACE an activation answers two independent
|
|
56
|
+
* conditions instead of one: whether the incoming principle helps the user's
|
|
57
|
+
* next required step, and whether this turn can afford to drop the outgoing
|
|
58
|
+
* principle. Both must clear the same threshold. The append path is untouched.
|
|
35
59
|
*/
|
|
36
60
|
export function buildDecisionQuestions(candidates) {
|
|
37
61
|
const questions = {};
|
|
38
62
|
for (const candidate of candidates) {
|
|
39
|
-
|
|
63
|
+
if (candidate.replaces === undefined) {
|
|
64
|
+
questions[candidateQuestionId(candidate.ref)] = {
|
|
65
|
+
type: 'noul',
|
|
66
|
+
instructions: `依据 currentInstruction 判断用户现在要做什么,并比较 state.candidates。候选 ${candidate.ref} 是否直接适用于这项任务,且最能改善下一步具体行动?`
|
|
67
|
+
+ '能避免当前任务的具体失误或补上关键步骤时给高分。仅主题相近、重复用户已明确的要求、或对下一步没有实质帮助时给低分。没有合适候选时全部给低分。',
|
|
68
|
+
};
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
questions[candidateValueQuestionId(candidate.ref)] = {
|
|
40
72
|
type: 'noul',
|
|
41
|
-
instructions: `依据 currentInstruction
|
|
42
|
-
+ '
|
|
43
|
-
+
|
|
73
|
+
instructions: `依据 currentInstruction 判断用户现在要求完成的下一步,并比较 state.candidates。候选 ${candidate.ref} 是否直接帮助完成这一步?`
|
|
74
|
+
+ '为完成这一步所需的核对、验证和证据整理也算直接帮助,即使用户没有逐字说出这些动作。'
|
|
75
|
+
+ '仅主题相近、重复用户已明确的要求、或对下一步没有实质帮助时给低分。没有合适候选时全部给低分。',
|
|
76
|
+
};
|
|
77
|
+
questions[candidateSafetyQuestionId(candidate.ref)] = {
|
|
78
|
+
type: 'noul',
|
|
79
|
+
instructions: `只判断本轮:state.candidates 中候选 ${candidate.ref} 的 replaces 记录了启用它将让位的原原则。`
|
|
80
|
+
+ '若启用该候选,本轮能否在保留任务所需约束的前提下省掉这条原原则?'
|
|
81
|
+
+ '原原则对本轮仍可能有用、或无法确认可以省掉时给低分;确认本轮不需要它时才给高分。只判断当前轮,不考虑以后。',
|
|
44
82
|
};
|
|
45
83
|
}
|
|
46
84
|
questions[ADAPTIVE_DECISION_INSUFFICIENT_QUESTION] = {
|
|
@@ -152,24 +190,45 @@ export function validateDecisionResponse(value, expected) {
|
|
|
152
190
|
/**
|
|
153
191
|
* Local adjudication of the INDEPENDENT condition scores. Order matters:
|
|
154
192
|
* insufficient information first (it invalidates any candidate ranking), then
|
|
155
|
-
* the applicability
|
|
193
|
+
* eligibility, then the applicability ranking.
|
|
194
|
+
*
|
|
195
|
+
* A candidate that replaces something is eligible only when BOTH its value and
|
|
196
|
+
* its safety condition clear the threshold. PD never lets a high incoming
|
|
197
|
+
* score override an unsafe removal, and `replacement_unsafe` keeps that
|
|
198
|
+
* failure distinguishable from "the candidate itself did not fit".
|
|
156
199
|
*/
|
|
157
200
|
export function adjudicateDecision(scores, candidates, criteria = ADAPTIVE_DECISION_CRITERIA) {
|
|
158
201
|
const insufficient = scores[ADAPTIVE_DECISION_INSUFFICIENT_QUESTION];
|
|
159
202
|
if (insufficient !== undefined && insufficient >= criteria.insufficientThreshold) {
|
|
160
203
|
return { status: 'uncertain', ref: null, reason: 'information_insufficient', scores };
|
|
161
204
|
}
|
|
162
|
-
const
|
|
163
|
-
.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
205
|
+
const evaluated = candidates.map((candidate) => {
|
|
206
|
+
const replaceable = candidate.replaces !== undefined;
|
|
207
|
+
const value = scores[replaceable
|
|
208
|
+
? candidateValueQuestionId(candidate.ref)
|
|
209
|
+
: candidateQuestionId(candidate.ref)] ?? 0;
|
|
210
|
+
const safety = replaceable ? scores[candidateSafetyQuestionId(candidate.ref)] ?? 0 : null;
|
|
211
|
+
return {
|
|
212
|
+
ref: candidate.ref,
|
|
213
|
+
value,
|
|
214
|
+
eligible: value >= criteria.selectThreshold
|
|
215
|
+
&& (safety === null || safety >= criteria.selectThreshold),
|
|
216
|
+
};
|
|
217
|
+
});
|
|
218
|
+
const ranked = evaluated
|
|
219
|
+
.filter((candidate) => candidate.eligible)
|
|
220
|
+
.sort((left, right) => right.value - left.value);
|
|
168
221
|
const [top, runnerUp] = ranked;
|
|
169
|
-
if (!top
|
|
170
|
-
|
|
222
|
+
if (!top) {
|
|
223
|
+
const applicable = evaluated.some((candidate) => candidate.value >= criteria.selectThreshold);
|
|
224
|
+
return {
|
|
225
|
+
status: 'none_applicable',
|
|
226
|
+
ref: null,
|
|
227
|
+
reason: applicable ? 'replacement_unsafe' : 'below_selection_threshold',
|
|
228
|
+
scores,
|
|
229
|
+
};
|
|
171
230
|
}
|
|
172
|
-
if (runnerUp && top.
|
|
231
|
+
if (runnerUp && top.value === runnerUp.value) {
|
|
173
232
|
return { status: 'uncertain', ref: null, reason: 'candidate_tied', scores };
|
|
174
233
|
}
|
|
175
234
|
return { status: 'selected', ref: top.ref, reason: 'selected', scores };
|
|
@@ -386,7 +386,12 @@ export async function runAdaptiveSelection(options) {
|
|
|
386
386
|
return {
|
|
387
387
|
status: 'none',
|
|
388
388
|
target: null,
|
|
389
|
-
|
|
389
|
+
// Keep "the candidate fits but dropping the outgoing principle was not
|
|
390
|
+
// shown safe" separate from an ordinary no-gain abstention; the bounded
|
|
391
|
+
// diagnostics must be able to tell them apart (rc-9).
|
|
392
|
+
reason: decision.status === 'uncertain'
|
|
393
|
+
? 'uncertain'
|
|
394
|
+
: decision.reason === 'replacement_unsafe' ? 'replacement_unsafe' : 'no_increment',
|
|
390
395
|
sends,
|
|
391
396
|
diagnostics,
|
|
392
397
|
};
|
|
@@ -1,4 +1,40 @@
|
|
|
1
1
|
import type { RecoveryCapabilityEvidence } from '@principles/core/runtime';
|
|
2
|
+
/**
|
|
3
|
+
* SPEC-RULECODE-HOST-PROMOTION-001 review round 4 (P1): per-capability
|
|
4
|
+
* CLI-channel reachability probes, shared by the pd-cli readiness path and
|
|
5
|
+
* the pd-console readiness assembly (both packages depend on host-runtime).
|
|
6
|
+
*
|
|
7
|
+
* Every probe executes the REAL pd CLI as a bounded subprocess against the
|
|
8
|
+
* TARGET workspace — static command lists, no shell, output capped, timeout
|
|
9
|
+
* enforced. Evidence is produced fresh on every call; nothing is cached and
|
|
10
|
+
* nothing destructive runs:
|
|
11
|
+
* - `pd_status`: `pd activation list --json` (read-only status surface);
|
|
12
|
+
* - `rulecode_deactivate`: `pd activation deactivate --activation-id
|
|
13
|
+
* recovery-probe-nonexistent --dry-run --json` — the REAL deactivate entry
|
|
14
|
+
* through real parsing, workspace binding, and target-resolution
|
|
15
|
+
* preconditions, with the dry-run guard returning BEFORE any governance
|
|
16
|
+
* audit write or store mutation. A nonexistent probe id keeps the
|
|
17
|
+
* precondition honest without touching any real activation.
|
|
18
|
+
*
|
|
19
|
+
* Console-channel capabilities (`rulecode_global_pause`,
|
|
20
|
+
* `owner_review_access`) can never be verified from a CLI subprocess — the
|
|
21
|
+
* caller receives explicit NOT-VERIFIED entries for them instead of
|
|
22
|
+
* fabricated ok flags (fail closed; SPEC R4 §2.4.7).
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* PRI-1202 — single budget authority.
|
|
26
|
+
*
|
|
27
|
+
* The CLI recovery probes run INSIDE one Owner Console HTTP request. The
|
|
28
|
+
* console wrapper (`asyncHandler`) answers 504 once its request budget
|
|
29
|
+
* expires, so two independent literals (probe 15s, request 10s) let a single
|
|
30
|
+
* probe outlive the request it belongs to. The console request budget is the
|
|
31
|
+
* authority; the probe budget is DERIVED from it and must stay strictly
|
|
32
|
+
* smaller, leaving fixed headroom for the console to serialize the response.
|
|
33
|
+
*/
|
|
34
|
+
export declare const CONSOLE_REQUEST_BUDGET_MS = 10000;
|
|
35
|
+
/** Headroom reserved inside the console request budget for response assembly. */
|
|
36
|
+
export declare const CLI_RECOVERY_PROBE_HEADROOM_MS = 2000;
|
|
37
|
+
export declare const CLI_RECOVERY_PROBE_TIMEOUT_MS: number;
|
|
2
38
|
export declare const DEACTIVATE_DRY_RUN_PROBE_ACTIVATION_ID = "recovery-probe-nonexistent";
|
|
3
39
|
/**
|
|
4
40
|
* Resolve the built pd CLI entry for the CURRENT environment. Both layouts
|
|
@@ -14,7 +50,12 @@ export interface CliRecoveryProbeOptions {
|
|
|
14
50
|
workspaceDir: string;
|
|
15
51
|
/** When supplied, the status listing must include this activation (workspace-targeting proof). */
|
|
16
52
|
expectedActivationId?: string;
|
|
17
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Probe budget in ms (default `CLI_RECOVERY_PROBE_TIMEOUT_MS`, derived from
|
|
55
|
+
* the console request budget). A timeout fails the capability closed —
|
|
56
|
+
* tests on loaded machines may raise it, but the default must stay strictly
|
|
57
|
+
* inside one console request.
|
|
58
|
+
*/
|
|
18
59
|
timeoutMs?: number;
|
|
19
60
|
}
|
|
20
61
|
/** `pd activation list --json` — the pd_status status surface, read-only. */
|
|
@@ -24,7 +24,20 @@ import { fileURLToPath } from 'node:url';
|
|
|
24
24
|
* caller receives explicit NOT-VERIFIED entries for them instead of
|
|
25
25
|
* fabricated ok flags (fail closed; SPEC R4 §2.4.7).
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* PRI-1202 — single budget authority.
|
|
29
|
+
*
|
|
30
|
+
* The CLI recovery probes run INSIDE one Owner Console HTTP request. The
|
|
31
|
+
* console wrapper (`asyncHandler`) answers 504 once its request budget
|
|
32
|
+
* expires, so two independent literals (probe 15s, request 10s) let a single
|
|
33
|
+
* probe outlive the request it belongs to. The console request budget is the
|
|
34
|
+
* authority; the probe budget is DERIVED from it and must stay strictly
|
|
35
|
+
* smaller, leaving fixed headroom for the console to serialize the response.
|
|
36
|
+
*/
|
|
37
|
+
export const CONSOLE_REQUEST_BUDGET_MS = 10_000;
|
|
38
|
+
/** Headroom reserved inside the console request budget for response assembly. */
|
|
39
|
+
export const CLI_RECOVERY_PROBE_HEADROOM_MS = 2_000;
|
|
40
|
+
export const CLI_RECOVERY_PROBE_TIMEOUT_MS = CONSOLE_REQUEST_BUDGET_MS - CLI_RECOVERY_PROBE_HEADROOM_MS;
|
|
28
41
|
const MAX_STDOUT_BYTES = 1024 * 1024;
|
|
29
42
|
export const DEACTIVATE_DRY_RUN_PROBE_ACTIVATION_ID = 'recovery-probe-nonexistent';
|
|
30
43
|
/**
|
|
@@ -109,7 +122,7 @@ function capability(capabilityId, evidence) {
|
|
|
109
122
|
const CONSOLE_UNVERIFIABLE_DETAIL = 'console-channel control: verifying the HTTP-only recovery entry requires the Owner Console process; a CLI subprocess cannot produce this evidence';
|
|
110
123
|
/** `pd activation list --json` — the pd_status status surface, read-only. */
|
|
111
124
|
export async function probeCliActivationStatus(options) {
|
|
112
|
-
const run = await runCli(options.cliEntry, ['activation', 'list', '--json', '--workspace', options.workspaceDir], options.timeoutMs ??
|
|
125
|
+
const run = await runCli(options.cliEntry, ['activation', 'list', '--json', '--workspace', options.workspaceDir], options.timeoutMs ?? CLI_RECOVERY_PROBE_TIMEOUT_MS);
|
|
113
126
|
if (!run.ok)
|
|
114
127
|
return capability('pd_status', { channel: 'cli', ok: false, workspaceMatched: false, detail: `pd activation list: ${run.detail}` });
|
|
115
128
|
let parsed;
|
|
@@ -138,7 +151,7 @@ export async function probeCliActivationStatus(options) {
|
|
|
138
151
|
* an honest not-found while the entry itself is proven executable.
|
|
139
152
|
*/
|
|
140
153
|
export async function probeCliDeactivateDryRun(options) {
|
|
141
|
-
const run = await runCli(options.cliEntry, ['activation', 'deactivate', '--activation-id', DEACTIVATE_DRY_RUN_PROBE_ACTIVATION_ID, '--dry-run', '--json', '--workspace', options.workspaceDir], options.timeoutMs ??
|
|
154
|
+
const run = await runCli(options.cliEntry, ['activation', 'deactivate', '--activation-id', DEACTIVATE_DRY_RUN_PROBE_ACTIVATION_ID, '--dry-run', '--json', '--workspace', options.workspaceDir], options.timeoutMs ?? CLI_RECOVERY_PROBE_TIMEOUT_MS);
|
|
142
155
|
if (!run.ok)
|
|
143
156
|
return capability('rulecode_deactivate', { channel: 'cli', ok: false, workspaceMatched: false, detail: `pd activation deactivate --dry-run: ${run.detail}` });
|
|
144
157
|
let parsed;
|
|
@@ -1,32 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Conversation-ingestion pipeline — the single orchestration entry for
|
|
3
|
-
* unified host trajectory ingestion (PRI-1171; SPEC v0.2 §4.1).
|
|
4
|
-
*
|
|
5
|
-
* Five segments, host-neutral:
|
|
6
|
-
*
|
|
7
|
-
* gate (flag short-circuit, ZERO port calls) → consent gate → locate →
|
|
8
|
-
* bounded window read (TOCTOU-mapped) → host decode → host contract guard →
|
|
9
|
-
* pre-ingest host side-writes → sanitize-at-store ingest with checkpoint →
|
|
10
|
-
* stop-classified outcome.
|
|
11
|
-
*
|
|
12
|
-
* Ordering invariants carried over verbatim from the Codex path (behavior
|
|
13
|
-
* lock, fixtures in codex-adapter/tests/ingestion/ingestion.test.ts):
|
|
14
|
-
* - flag-off / consent-not-granted short-circuit BEFORE locate — the
|
|
15
|
-
* transcript filesystem boundary receives zero calls (SPEC §10 hard
|
|
16
|
-
* privacy invariant, proven by a port spy);
|
|
17
|
-
* - a host contract guard refusal (e.g. unsupported host version) ingests
|
|
18
|
-
* NOTHING and holds the checkpoint — the next trigger retries;
|
|
19
|
-
* - pre-ingest side-write failure (e.g. verified tool outcomes) holds the
|
|
20
|
-
* checkpoint so the delta retries instead of silently losing facts;
|
|
21
|
-
* - a stable malformed record commits the records BEFORE it, holds the
|
|
22
|
-
* checkpoint at it, and degrades loudly;
|
|
23
|
-
* - an incomplete tail commits what precedes it, parks the checkpoint at
|
|
24
|
-
* the tail start, and reports a warning (transient by design).
|
|
25
|
-
*
|
|
26
|
-
* The pipeline never learns host formats: the source adapter supplies locate
|
|
27
|
-
* + decode + rollout lineage; `degradeTexts` carries host-CLI vocabulary
|
|
28
|
-
* (quarantine commands etc.) so Operator-facing nextActions stay exact.
|
|
29
|
-
*/
|
|
30
1
|
import { type GovernanceObservationInput } from '../governance-observation-store.js';
|
|
31
2
|
import { type HookHints, type SessionRef, type TranscriptDelta, type TranscriptPort, type TranscriptSourceAdapter } from './source.js';
|
|
32
3
|
import type { ConversationIngestionConsentDecision } from './consent.js';
|
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
* + decode + rollout lineage; `degradeTexts` carries host-CLI vocabulary
|
|
28
28
|
* (quarantine commands etc.) so Operator-facing nextActions stay exact.
|
|
29
29
|
*/
|
|
30
|
+
import * as nodePath from 'node:path';
|
|
31
|
+
import { appendEventLogLine } from '@principles/core/runtime';
|
|
30
32
|
import { ingestGovernanceObservations, readGovernanceCheckpoint, } from '../governance-observation-store.js';
|
|
31
33
|
import { CONVERSATION_INGESTION_MAX_BATCH_BYTES, TranscriptReplacedError, createNodeTranscriptPort, } from './source.js';
|
|
32
34
|
import { TEXT_POLICY_BOUNDED_MAX_CHARS } from './text-policy.js';
|
|
@@ -38,7 +40,43 @@ export function runConversationIngestion(args) {
|
|
|
38
40
|
oversizedNextAction: 'a single transcript record exceeds the bounded-read window; inspect the transcript file.',
|
|
39
41
|
...args.degradeTexts,
|
|
40
42
|
};
|
|
41
|
-
const
|
|
43
|
+
const now = args.now ?? new Date();
|
|
44
|
+
const eventLogStateDir = nodePath.join(args.workspaceDir, '.state');
|
|
45
|
+
const boundedText = (value) => {
|
|
46
|
+
// Code-point bounded: a log line may be rendered by an Owner-facing
|
|
47
|
+
// surface, so never split a surrogate pair (EP-11).
|
|
48
|
+
const points = Array.from(value);
|
|
49
|
+
return points.length > 300 ? `${points.slice(0, 300).join('')}…` : value;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* rc-9: every refused ingest leaves a durable fact in the existing
|
|
53
|
+
* `events_<date>.jsonl` channel. The hook's stderr is the only other
|
|
54
|
+
* surface, and it is per-process — "0 rows" was previously unattributable
|
|
55
|
+
* after the fact. Best-effort: a failed write must not break the hook, but
|
|
56
|
+
* it must stay observable on the returned warnings.
|
|
57
|
+
*/
|
|
58
|
+
const degraded = (reason, nextAction, warnings) => {
|
|
59
|
+
const observableWarnings = [...warnings];
|
|
60
|
+
try {
|
|
61
|
+
appendEventLogLine(eventLogStateDir, {
|
|
62
|
+
ts: now.toISOString(),
|
|
63
|
+
type: 'conversation_ingestion',
|
|
64
|
+
category: 'degraded',
|
|
65
|
+
sessionId: args.session.sessionId,
|
|
66
|
+
data: {
|
|
67
|
+
hostKind: args.source.hostKind,
|
|
68
|
+
reason: boundedText(reason),
|
|
69
|
+
nextAction: boundedText(nextAction),
|
|
70
|
+
warningCount: warnings.length,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
const detail = boundedText(error instanceof Error ? error.message : String(error));
|
|
76
|
+
observableWarnings.push(`degradation_event_log_failed:${detail}`);
|
|
77
|
+
}
|
|
78
|
+
return { status: 'degraded', reason, nextAction, warnings: observableWarnings };
|
|
79
|
+
};
|
|
42
80
|
// 1. Flag short-circuit — before locate, before ANY port call (SPEC §10).
|
|
43
81
|
if (!args.flags.ingestionEnabled) {
|
|
44
82
|
return degraded('ingestion_disabled', 'enable the conversation-ingestion flag for this host in the workspace .pd/config.yaml to ingest transcripts.', []);
|
|
@@ -47,7 +85,6 @@ export function runConversationIngestion(args) {
|
|
|
47
85
|
if (args.consent.decision !== 'granted') {
|
|
48
86
|
return degraded(`consent_not_granted:${args.consent.decision}`, 'record a granted consent decision for this host (setup flow or Owner directive) before transcript ingestion runs.', []);
|
|
49
87
|
}
|
|
50
|
-
const now = args.now ?? new Date();
|
|
51
88
|
const port = args.port ?? createNodeTranscriptPort();
|
|
52
89
|
// 3. Locate (deterministic, host rules).
|
|
53
90
|
const locator = args.source.locate(args.session, args.hints, args.env ?? {});
|
|
@@ -85,6 +85,18 @@ export const HIGH_PRECISION_CORRECTION_OVERLAY = [
|
|
|
85
85
|
export const AMBIGUOUS_CORRECTION_OVERLAY = [
|
|
86
86
|
['我说的是', 0.9],
|
|
87
87
|
['都说了', 0.8],
|
|
88
|
+
// 2026-11-13 真实宿主回归(P1-1):Owner「这种没有数据支撑的激进改动我不
|
|
89
|
+
// 接受。以后改配置参数前,先说明依据和影响,等我确认后再动手。」在零命中
|
|
90
|
+
// 预算下被漏检。以下只作候选(precision=ambiguous),必须经 Stage2 LLM 确认,
|
|
91
|
+
// 不得直达 STRONG;普通否定句仍可能被 LLM 判为 none。
|
|
92
|
+
['不接受', 0.6],
|
|
93
|
+
['我不同意', 0.6],
|
|
94
|
+
['我没让你', 0.6],
|
|
95
|
+
['没有让你', 0.6],
|
|
96
|
+
['未经确认', 0.5],
|
|
97
|
+
['先别执行', 0.6],
|
|
98
|
+
['没有依据', 0.5],
|
|
99
|
+
['这不是我要求的', 0.7],
|
|
88
100
|
];
|
|
89
101
|
function isValidLearnedKeyword(v) {
|
|
90
102
|
if (typeof v !== 'object' || v === null)
|
|
@@ -19,6 +19,8 @@ export interface PromptDeliverabilityCandidateArtifact {
|
|
|
19
19
|
artifactKind: string;
|
|
20
20
|
contentJson: string;
|
|
21
21
|
validationStatus: string;
|
|
22
|
+
/** Formal ledger identity column; identity never comes from content titles. */
|
|
23
|
+
sourcePrincipleId?: string;
|
|
22
24
|
}
|
|
23
25
|
export type PromptArtifactDeliverability = {
|
|
24
26
|
status: 'deliverable';
|
|
@@ -24,6 +24,7 @@ export function resolvePromptCandidatePrinciple(artifact) {
|
|
|
24
24
|
artifact_kind: artifact.artifactKind,
|
|
25
25
|
content_json: artifact.contentJson,
|
|
26
26
|
validation_status: artifact.validationStatus,
|
|
27
|
+
source_principle_id: artifact.sourcePrincipleId,
|
|
27
28
|
}, syntheticPendingActivation(artifact.artifactId));
|
|
28
29
|
}
|
|
29
30
|
function selfReportEnabledFor(workspaceDir) {
|
|
@@ -195,6 +196,7 @@ export async function loadPromptArtifactById(workspaceDir, artifactId) {
|
|
|
195
196
|
artifactKind: record.artifactKind,
|
|
196
197
|
contentJson: record.contentJson,
|
|
197
198
|
validationStatus: record.validationStatus,
|
|
199
|
+
sourcePrincipleId: record.sourcePrincipleId,
|
|
198
200
|
},
|
|
199
201
|
};
|
|
200
202
|
}
|
|
@@ -56,6 +56,7 @@ export async function readPromptActivationInjectionStatuses(input) {
|
|
|
56
56
|
artifact_kind: artifact.artifactKind,
|
|
57
57
|
content_json: artifact.contentJson,
|
|
58
58
|
validation_status: artifact.validationStatus,
|
|
59
|
+
source_principle_id: artifact.sourcePrincipleId,
|
|
59
60
|
}, activation);
|
|
60
61
|
if (!resolved.ok) {
|
|
61
62
|
rows.push({ activationId: activation.activationId, failure: resolved.warning });
|
|
@@ -168,6 +168,11 @@ export const MCP_BINDING_LAUNCHER_ONLY_REASONS = [
|
|
|
168
168
|
{ code: 'workspace_declaration_invalid', why: 'OpenClaw declaration sources produced a value that is not a usable absolute workspace directory (dynamic reason from the declaration resolver).' },
|
|
169
169
|
{ code: 'server_entry_invalid', why: 'The entry module must actually export main().' },
|
|
170
170
|
{ code: 'server_startup_failed', why: 'The server process itself failed to start.' },
|
|
171
|
+
{ code: 'experiment_root_not_absolute', why: 'PD_EXPERIMENT_ROOT must be absolute or the experiment boundary is ambiguous.' },
|
|
172
|
+
{ code: 'experiment_root_missing', why: 'PD_EXPERIMENT_ROOT must resolve to an existing directory before the launcher writes anything.' },
|
|
173
|
+
{ code: 'experiment_mcp_log_dir_missing', why: 'An experiment must pin PD_MCP_LOG_DIR; the default is the production log directory.' },
|
|
174
|
+
{ code: 'experiment_mcp_log_dir_outside_root', why: 'An experiment MCP log directory must stay inside PD_EXPERIMENT_ROOT.' },
|
|
175
|
+
{ code: 'experiment_binding_workspace_outside_root', why: 'An experiment must never serve a binding workspace outside its own root.' },
|
|
171
176
|
];
|
|
172
177
|
/**
|
|
173
178
|
* Table-driven matrix shared by the contract test, the launcher parity test and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-principles-disciple",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.152.0",
|
|
4
4
|
"description": "Interactive CLI installer for Principles Disciple OpenClaw plugin",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@earendil-works/pi-agent-core": "1.2.0",
|
|
65
65
|
"@earendil-works/pi-ai": "1.4.0",
|
|
66
|
-
"@principles/install-layout": "^0.8.
|
|
66
|
+
"@principles/install-layout": "^0.8.1",
|
|
67
67
|
"@sinclair/typebox": "^0.34.52",
|
|
68
68
|
"@tufjs/models": "3.0.1",
|
|
69
69
|
"@inquirer/prompts": "^8.7.2",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"pd": {
|
|
102
102
|
"bundledPluginVersion": "2.2.13"
|
|
103
103
|
},
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "8582e5dde27a582c63f3ad6804675a84c0d0c11e"
|
|
105
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"candidate.d.ts","sourceRoot":"","sources":["../../src/commands/candidate.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,mBAAmB,EA0BpB,MAAM,0BAA0B,CAAC;AAelC,UAAU,oBAAoB;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,UAAU,oBAAoB;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;C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E,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CA+CrF"}
|
|
@@ -585,7 +585,7 @@ async function evaluateReuseProposal(workspaceDir, claim, entries) {
|
|
|
585
585
|
* intake chain with the §11 verdict injected. No CLI-side persistence.
|
|
586
586
|
*/
|
|
587
587
|
async function executeOwnerDecision(deps) {
|
|
588
|
-
const { opts, stateManager, ledgerAdapter, stateDir } = deps;
|
|
588
|
+
const { opts, stateManager, ledgerAdapter, stateDir, workspaceDir } = deps;
|
|
589
589
|
const failCli = (message, nextAction) => {
|
|
590
590
|
if (opts.json) {
|
|
591
591
|
console.log(JSON.stringify({ candidateId: opts.candidateId, status: 'refused', decision: opts.decide, error: message, nextAction }, null, 2));
|
|
@@ -657,15 +657,35 @@ async function executeOwnerDecision(deps) {
|
|
|
657
657
|
// create verdict (or gate absent shapes) — same durable outcome as intake.
|
|
658
658
|
const { entry } = intakeResult;
|
|
659
659
|
const consumedState = await markCandidateConsumed(stateManager, opts.candidateId, entry.id);
|
|
660
|
+
// PRI-1193: consuming the candidate is not the end of the create decision.
|
|
661
|
+
// `run-rulehost --pain-id` resolves the dreamer by pain; without a task
|
|
662
|
+
// bound to THIS principle candidate it silently picks the rule candidate's
|
|
663
|
+
// dreamer (no ledgerEntryId) and skips approval enqueue. Seed the principle
|
|
664
|
+
// dreamer here, exactly like `candidate internalize` does.
|
|
665
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define -- helper is defined beside this command for readability
|
|
666
|
+
const dreamer = await seedDreamerForConsumedCandidate({
|
|
667
|
+
stateManager,
|
|
668
|
+
workspaceDir,
|
|
669
|
+
candidateId: opts.candidateId,
|
|
670
|
+
});
|
|
660
671
|
if (consumedState === 'already_consumed') {
|
|
661
672
|
// Consumed before this call — the ledger entry is identical by intake
|
|
662
673
|
// idempotency; report it like `pd candidate intake` does.
|
|
663
674
|
const infoMessage = `Candidate ${opts.candidateId} was already consumed. Ledger entry: ${entry.id}`;
|
|
664
675
|
if (opts.json) {
|
|
665
|
-
console.log(JSON.stringify({
|
|
676
|
+
console.log(JSON.stringify({
|
|
677
|
+
candidateId: opts.candidateId,
|
|
678
|
+
ledgerEntryId: entry.id,
|
|
679
|
+
status: 'already_consumed',
|
|
680
|
+
message: infoMessage,
|
|
681
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
682
|
+
...dreamerReport(dreamer),
|
|
683
|
+
}, null, 2));
|
|
666
684
|
}
|
|
667
685
|
else {
|
|
668
686
|
console.log(infoMessage);
|
|
687
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
688
|
+
printDreamerReport(dreamer);
|
|
669
689
|
}
|
|
670
690
|
return;
|
|
671
691
|
}
|
|
@@ -674,6 +694,8 @@ async function executeOwnerDecision(deps) {
|
|
|
674
694
|
decision: opts.decide,
|
|
675
695
|
ledgerEntryId: entry.id,
|
|
676
696
|
status: 'consumed',
|
|
697
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
698
|
+
...dreamerReport(dreamer),
|
|
677
699
|
};
|
|
678
700
|
if (opts.json) {
|
|
679
701
|
console.log(JSON.stringify(result, null, 2));
|
|
@@ -684,8 +706,100 @@ async function executeOwnerDecision(deps) {
|
|
|
684
706
|
console.log(` Candidate: ${opts.candidateId}`);
|
|
685
707
|
console.log(` Ledger Entry: ${entry.id}`);
|
|
686
708
|
console.log(` Status: consumed\n`);
|
|
709
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
710
|
+
printDreamerReport(dreamer);
|
|
687
711
|
console.log('Decision complete.\n');
|
|
688
712
|
}
|
|
713
|
+
/**
|
|
714
|
+
* PRI-1193: seed the dreamer task bound to the just-consumed PRINCIPLE
|
|
715
|
+
* candidate. Mirrors `handleCandidateInternalize` (PRI-435/PRI-720 C6) so the
|
|
716
|
+
* subsequent `run-rulehost --pain-id` can select the correct dreamer.
|
|
717
|
+
*/
|
|
718
|
+
async function seedDreamerForConsumedCandidate(deps) {
|
|
719
|
+
const candidate = await deps.stateManager.getCandidate(deps.candidateId);
|
|
720
|
+
if (!candidate) {
|
|
721
|
+
return {
|
|
722
|
+
status: 'not_seeded',
|
|
723
|
+
reason: `Cannot seed dreamer: candidate ${deps.candidateId} not found`,
|
|
724
|
+
nextAction: 'Run `pd candidate internalization backfill --include-pending --confirm` after restoring the candidate row.',
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
const recommendation = resolveCandidateRecommendation(candidate, deps.stateManager, deps.candidateId);
|
|
728
|
+
// The create decision already admitted this principle into the ledger, so
|
|
729
|
+
// its text is ledger-eligible even when the diagnostician used `description`
|
|
730
|
+
// rather than `abstractedPrinciple`. Normalize before the route decision;
|
|
731
|
+
// otherwise the dreamer seed would be refused as "missing abstractedPrinciple"
|
|
732
|
+
// after the ledger write already succeeded.
|
|
733
|
+
const decision = decideInternalizationRoute({
|
|
734
|
+
...recommendation,
|
|
735
|
+
abstractedPrinciple: recommendation.abstractedPrinciple ?? recommendation.description,
|
|
736
|
+
});
|
|
737
|
+
const sourcePainId = await resolveSourcePainIdFromDiagnostician(deps.stateManager, candidate);
|
|
738
|
+
if (sourcePainId === null) {
|
|
739
|
+
return {
|
|
740
|
+
status: 'not_seeded',
|
|
741
|
+
reason: `Cannot resolve sourcePainId from diagnostician task chain for candidate ${deps.candidateId}`,
|
|
742
|
+
nextAction: 'Verify the diagnostician task diagnosticJson contains a valid top-level sourcePainId; re-run diagnosis if missing.',
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
const seed = buildDreamerSeedFromCandidate(candidate, {
|
|
746
|
+
route: decision.route,
|
|
747
|
+
ready: decision.ready,
|
|
748
|
+
sourcePainId,
|
|
749
|
+
pipelineMode: resolvePromptFullPipelineSeedMode(deps.workspaceDir),
|
|
750
|
+
});
|
|
751
|
+
// eslint-disable-next-line no-restricted-syntax -- 'in' required for discriminated union narrowing (BridgeTaskSeed | BridgeDecision)
|
|
752
|
+
if ('decision' in seed) {
|
|
753
|
+
if (seed.decision === 'already_exists') {
|
|
754
|
+
return { status: 'existing', taskId: seed.taskId };
|
|
755
|
+
}
|
|
756
|
+
if (seed.decision === 'not_internalizable' || seed.decision === 'invalid_candidate') {
|
|
757
|
+
return {
|
|
758
|
+
status: 'not_seeded',
|
|
759
|
+
reason: seed.reason,
|
|
760
|
+
nextAction: 'Verify internalization route configuration and candidate readiness.',
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
return {
|
|
764
|
+
status: 'not_seeded',
|
|
765
|
+
reason: 'Seed not created',
|
|
766
|
+
nextAction: 'Verify internalization route configuration and candidate readiness.',
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
// PRI-720 C6: candidate-level dedup (any channel variant).
|
|
770
|
+
const existingTask = await findExistingDreamerTask((id) => deps.stateManager.getTask(id), deps.candidateId);
|
|
771
|
+
if (existingTask) {
|
|
772
|
+
return { status: 'existing', taskId: existingTask.taskId };
|
|
773
|
+
}
|
|
774
|
+
const task = await deps.stateManager.createTask({
|
|
775
|
+
taskId: seed.taskId,
|
|
776
|
+
taskKind: seed.taskKind,
|
|
777
|
+
status: seed.status,
|
|
778
|
+
attemptCount: seed.attemptCount,
|
|
779
|
+
maxAttempts: seed.maxAttempts,
|
|
780
|
+
diagnosticJson: seed.diagnosticJson,
|
|
781
|
+
});
|
|
782
|
+
return { status: 'created', taskId: task.taskId };
|
|
783
|
+
}
|
|
784
|
+
function dreamerReport(report) {
|
|
785
|
+
return {
|
|
786
|
+
dreamerStatus: report.status,
|
|
787
|
+
...(report.taskId ? { dreamerTaskId: report.taskId } : {}),
|
|
788
|
+
...(report.reason ? { dreamerReason: report.reason } : {}),
|
|
789
|
+
...(report.nextAction ? { nextAction: report.nextAction } : {}),
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
function printDreamerReport(report) {
|
|
793
|
+
if (report.taskId) {
|
|
794
|
+
console.log(` Dreamer Task: ${report.taskId} (${report.status})`);
|
|
795
|
+
}
|
|
796
|
+
else {
|
|
797
|
+
console.log(` Dreamer Task: not seeded — ${report.reason ?? 'unknown reason'}`);
|
|
798
|
+
}
|
|
799
|
+
if (report.nextAction) {
|
|
800
|
+
console.log(` Next Action: ${report.nextAction}`);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
689
803
|
/**
|
|
690
804
|
* pd candidate intake --candidate-id <id> [--workspace <path>] [--json] [--dry-run]
|
|
691
805
|
*
|
|
@@ -945,7 +1059,7 @@ export async function handleCandidateReview(opts) {
|
|
|
945
1059
|
}
|
|
946
1060
|
}
|
|
947
1061
|
// opts.decide is narrowed here — no cast needed to build the decision-mode shape.
|
|
948
|
-
await executeOwnerDecision({ opts: { ...opts, decide: opts.decide }, stateManager, ledgerAdapter, stateDir });
|
|
1062
|
+
await executeOwnerDecision({ opts: { ...opts, decide: opts.decide }, stateManager, ledgerAdapter, stateDir, workspaceDir });
|
|
949
1063
|
return;
|
|
950
1064
|
}
|
|
951
1065
|
// ── Read-only proposal view ──
|