create-principles-disciple 1.145.0 → 1.145.3

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.
Files changed (129) hide show
  1. package/LICENSE +73 -21
  2. package/NOTICE +2 -0
  3. package/README.md +1 -1
  4. package/_release/product-identity.json +2 -2
  5. package/codex-adapter/package.json +5 -3
  6. package/console/dist/server/models/ApprovalsGroupedConsoleModel.js +4 -4
  7. package/console/dist/ui/i18n/en.json +17 -16
  8. package/console/dist/ui/i18n/zh-CN.json +17 -16
  9. package/console/dist/ui/pages/focus/FocusPage.js +9 -5
  10. package/console/dist/ui/pages/focus/OwnerDecisionCard.js +1 -1
  11. package/console/dist/ui/pages/principles/PrincipleDetailPage.js +10 -4
  12. package/console/dist/ui/pages/principles/PrinciplesPage.js +1 -1
  13. package/console/dist/ui/utils/reading-layout.d.ts +19 -0
  14. package/console/dist/ui/utils/reading-layout.js +46 -0
  15. package/console/dist/web/assets/app.js +30 -28
  16. package/console/package.json +2 -1
  17. package/core/dist/runtime-v2/index.d.ts +10 -0
  18. package/core/dist/runtime-v2/index.d.ts.map +1 -1
  19. package/core/dist/runtime-v2/index.js +5 -0
  20. package/core/dist/runtime-v2/index.js.map +1 -1
  21. package/core/dist/runtime-v2/internalization/artificer-prompt-builder.d.ts +25 -6
  22. package/core/dist/runtime-v2/internalization/artificer-prompt-builder.d.ts.map +1 -1
  23. package/core/dist/runtime-v2/internalization/artificer-prompt-builder.js +21 -7
  24. package/core/dist/runtime-v2/internalization/artificer-prompt-builder.js.map +1 -1
  25. package/core/dist/runtime-v2/internalization/artificer-run-correlation.d.ts +82 -0
  26. package/core/dist/runtime-v2/internalization/artificer-run-correlation.d.ts.map +1 -0
  27. package/core/dist/runtime-v2/internalization/artificer-run-correlation.js +79 -0
  28. package/core/dist/runtime-v2/internalization/artificer-run-correlation.js.map +1 -0
  29. package/core/dist/runtime-v2/internalization/artificer-runner.d.ts +16 -2
  30. package/core/dist/runtime-v2/internalization/artificer-runner.d.ts.map +1 -1
  31. package/core/dist/runtime-v2/internalization/artificer-runner.js +89 -9
  32. package/core/dist/runtime-v2/internalization/artificer-runner.js.map +1 -1
  33. package/core/dist/runtime-v2/internalization/consumer-evidence-preflight.d.ts +141 -0
  34. package/core/dist/runtime-v2/internalization/consumer-evidence-preflight.d.ts.map +1 -0
  35. package/core/dist/runtime-v2/internalization/consumer-evidence-preflight.js +284 -0
  36. package/core/dist/runtime-v2/internalization/consumer-evidence-preflight.js.map +1 -0
  37. package/core/dist/runtime-v2/internalization/evidence-readiness.d.ts +170 -0
  38. package/core/dist/runtime-v2/internalization/evidence-readiness.d.ts.map +1 -0
  39. package/core/dist/runtime-v2/internalization/evidence-readiness.js +335 -0
  40. package/core/dist/runtime-v2/internalization/evidence-readiness.js.map +1 -0
  41. package/core/dist/runtime-v2/internalization/owner-evidence-recovery.d.ts +190 -0
  42. package/core/dist/runtime-v2/internalization/owner-evidence-recovery.d.ts.map +1 -0
  43. package/core/dist/runtime-v2/internalization/owner-evidence-recovery.js +488 -0
  44. package/core/dist/runtime-v2/internalization/owner-evidence-recovery.js.map +1 -0
  45. package/core/dist/runtime-v2/internalization/owner-retry.d.ts +23 -1
  46. package/core/dist/runtime-v2/internalization/owner-retry.d.ts.map +1 -1
  47. package/core/dist/runtime-v2/internalization/owner-retry.js +19 -3
  48. package/core/dist/runtime-v2/internalization/owner-retry.js.map +1 -1
  49. package/core/dist/runtime-v2/internalization/peer-runner-contracts.d.ts +8 -0
  50. package/core/dist/runtime-v2/internalization/peer-runner-contracts.d.ts.map +1 -1
  51. package/core/dist/runtime-v2/internalization/peer-runner-contracts.js.map +1 -1
  52. package/core/dist/runtime-v2/internalization/pitask-metadata.d.ts +12 -0
  53. package/core/dist/runtime-v2/internalization/pitask-metadata.d.ts.map +1 -1
  54. package/core/dist/runtime-v2/internalization/pitask-metadata.js +24 -0
  55. package/core/dist/runtime-v2/internalization/pitask-metadata.js.map +1 -1
  56. package/core/dist/runtime-v2/recovery-actions-log.d.ts +40 -0
  57. package/core/dist/runtime-v2/recovery-actions-log.d.ts.map +1 -1
  58. package/core/dist/runtime-v2/recovery-actions-log.js +77 -2
  59. package/core/dist/runtime-v2/recovery-actions-log.js.map +1 -1
  60. package/core/dist/runtime-v2/store/runtime-state-manager.d.ts +6 -1
  61. package/core/dist/runtime-v2/store/runtime-state-manager.d.ts.map +1 -1
  62. package/core/dist/runtime-v2/store/runtime-state-manager.js +6 -2
  63. package/core/dist/runtime-v2/store/runtime-state-manager.js.map +1 -1
  64. package/core/dist/runtime-v2/store/task/memory-task-store.d.ts +3 -1
  65. package/core/dist/runtime-v2/store/task/memory-task-store.d.ts.map +1 -1
  66. package/core/dist/runtime-v2/store/task/memory-task-store.js +6 -1
  67. package/core/dist/runtime-v2/store/task/memory-task-store.js.map +1 -1
  68. package/core/dist/runtime-v2/store/task/sqlite-task-store.d.ts +3 -1
  69. package/core/dist/runtime-v2/store/task/sqlite-task-store.d.ts.map +1 -1
  70. package/core/dist/runtime-v2/store/task/sqlite-task-store.js +10 -2
  71. package/core/dist/runtime-v2/store/task/sqlite-task-store.js.map +1 -1
  72. package/core/dist/runtime-v2/store/task/task-store.d.ts +11 -5
  73. package/core/dist/runtime-v2/store/task/task-store.d.ts.map +1 -1
  74. package/core/dist/telemetry-event.d.ts +2 -2
  75. package/core/dist/telemetry-event.d.ts.map +1 -1
  76. package/core/dist/telemetry-event.js +13 -0
  77. package/core/dist/telemetry-event.js.map +1 -1
  78. package/core/package.json +9 -3
  79. package/dist/installers/workbuddy-host-installer.d.ts +16 -3
  80. package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
  81. package/dist/installers/workbuddy-host-installer.js +57 -10
  82. package/dist/installers/workbuddy-host-installer.js.map +1 -1
  83. package/host-runtime/dist/internalization-consumer-cycle.d.ts +12 -1
  84. package/host-runtime/dist/internalization-consumer-cycle.js +141 -16
  85. package/host-runtime/dist/workspace-telemetry-emitter.js +13 -0
  86. package/host-runtime/package.json +5 -3
  87. package/install-layout/package.json +5 -3
  88. package/package.json +6 -5
  89. package/pd-cli/dist/commands/runtime-internalization-audit-artificer-evidence.d.ts +44 -0
  90. package/pd-cli/dist/commands/runtime-internalization-audit-artificer-evidence.d.ts.map +1 -0
  91. package/pd-cli/dist/commands/runtime-internalization-audit-artificer-evidence.js +138 -0
  92. package/pd-cli/dist/commands/runtime-internalization-audit-artificer-evidence.js.map +1 -0
  93. package/pd-cli/dist/commands/runtime-internalization-evidence.d.ts +72 -0
  94. package/pd-cli/dist/commands/runtime-internalization-evidence.d.ts.map +1 -0
  95. package/pd-cli/dist/commands/runtime-internalization-evidence.js +424 -0
  96. package/pd-cli/dist/commands/runtime-internalization-evidence.js.map +1 -0
  97. package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
  98. package/pd-cli/dist/commands/runtime-internalization-run-once.js +22 -1
  99. package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
  100. package/pd-cli/dist/commands/runtime-internalization-run-rulehost.d.ts.map +1 -1
  101. package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js +45 -4
  102. package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js.map +1 -1
  103. package/pd-cli/dist/index.js +8 -0
  104. package/pd-cli/dist/index.js.map +1 -1
  105. package/pd-cli/dist/services/artificer-evidence-audit.d.ts +156 -0
  106. package/pd-cli/dist/services/artificer-evidence-audit.d.ts.map +1 -0
  107. package/pd-cli/dist/services/artificer-evidence-audit.js +321 -0
  108. package/pd-cli/dist/services/artificer-evidence-audit.js.map +1 -0
  109. package/pd-cli/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
  110. package/pd-cli/dist/services/rulehost-pipeline-runner.js +17 -3
  111. package/pd-cli/dist/services/rulehost-pipeline-runner.js.map +1 -1
  112. package/pd-cli/package.json +5 -3
  113. package/plugin/dist/bundle.js +491 -491
  114. package/plugin/dist/openclaw.plugin.json +1 -1
  115. package/plugin/dist/rulehost-evidence.js +26 -26
  116. package/plugin/openclaw.plugin.json +1 -1
  117. package/plugin/package.json +5 -3
  118. package/release-manager/dist/installers/workbuddy-host-installer.d.ts +16 -3
  119. package/release-manager/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
  120. package/release-manager/dist/installers/workbuddy-host-installer.js +57 -10
  121. package/release-manager/dist/installers/workbuddy-host-installer.js.map +1 -1
  122. package/release-manager/package.json +5 -4
  123. package/workbuddy-adapter/package.json +5 -3
  124. package/console/dist/ui/utils/navigation.d.ts +0 -9
  125. package/console/dist/ui/utils/navigation.js +0 -7
  126. package/core/dist/runtime-v2/internalization/dimension-coverage-policy.d.ts +0 -54
  127. package/core/dist/runtime-v2/internalization/dimension-coverage-policy.d.ts.map +0 -1
  128. package/core/dist/runtime-v2/internalization/dimension-coverage-policy.js +0 -70
  129. package/core/dist/runtime-v2/internalization/dimension-coverage-policy.js.map +0 -1
@@ -0,0 +1,335 @@
1
+ /**
2
+ * PRI-981 (SPEC-PD-IAER-001 FR-01) — Evidence Readiness Gate (evidence-readiness.ts)
3
+ *
4
+ * Shared, side-effect-free judgment of whether an Artificer V2 execution has
5
+ * the Owner-labelled evidence it requires. Pure logic: this module imports
6
+ * node:crypto for the evidence content hash only (intent-hash.ts precedent)
7
+ * and performs NO I/O — the caller injects the assembly step.
8
+ *
9
+ * One judgment authority, one validator: the pack check REUSES
10
+ * `validateBehaviorExamplePack` (behavior-example-pack.ts) — this module must
11
+ * never grow a second, divergent pack validation.
12
+ *
13
+ * Err-prevention / contract IDs:
14
+ * - ERR-069: an invalid pack fails the attempt LOUD — the gate reports
15
+ * `invalid_evidence`, it never silently fabricates or drops evidence.
16
+ * - rc-1/rc-2: the Owner selection and assembled pack are treated as
17
+ * untrusted — structural guards only, no `as` bypass.
18
+ * - rc-3: required selection fields fail explicitly (missingFields /
19
+ * structured reason), never skipped silently.
20
+ * - rc-4: `positiveToolCallIds` is validated element-by-element (safe
21
+ * positive integers, uniqueness, 1..3), not just "is array".
22
+ * - rc-5: `Object.hasOwn` over the `in` operator.
23
+ * - rc-8: unknown failure details are serialized with a bounded preview.
24
+ * - rc-9: every non-ready outcome carries a stable reasonCode and a
25
+ * nextAction the Owner can act on.
26
+ *
27
+ * Reason codes (SPEC-PD-IAER-001 FR-04 stable IDs): `owner_behavior_examples_required`,
28
+ * `owner_behavior_examples_invalid`, `owner_behavior_examples_stale`,
29
+ * `owner_behavior_examples_scope_mismatch`. This pure gate reports `required`
30
+ * (nothing provided), `invalid` (provided but rejected), and — since B1
31
+ * (PRI-983) — `stale` / `scope_mismatch` when the assembler fails with the
32
+ * typed `OwnerEvidenceScopeError` (structural classification, never message
33
+ * sniffing): unresolvable pain/row references are `stale` (FR-03: cleaned
34
+ * trajectories must never be silently reused), cross-session selections are
35
+ * `scope_mismatch`. Plain errors stay `invalid` (A2 behavior unchanged).
36
+ * PRI-980 review P2-1 adds the §6.2 storage-fault family: the typed
37
+ * `evidence_source_error` kind → a distinct `evidence_source_error` verdict
38
+ * that is NOT an FR-04 owner-fault code.
39
+ *
40
+ * Channel authority: whether the target channel requires Owner evidence at
41
+ * all is DECLARED by the caller (`channelRequiresOwnerEvidence`) — this module
42
+ * does not guess channels (SPEC §4.2). A2 owns the authoritative wiring; this
43
+ * ticket provides the judgment only.
44
+ *
45
+ * Spec: docs/specs/SPEC-PD-IAER-001-v1.0.md §5 FR-01
46
+ */
47
+ import { createHash } from 'node:crypto';
48
+ import { validateBehaviorExamplePack } from './behavior-example-pack.js';
49
+ // ── typed assembly-failure classification (B1, PRI-983) ────────────────────
50
+ //
51
+ // The plugin assembler previously failed evidence gaps with plain Errors, so
52
+ // every assembly failure could only surface as `invalid_evidence` (A2
53
+ // contract note). B1 adds a STRUCTURAL error classification — never message
54
+ // sniffing — so resume can distinguish "trajectory cleaned/changed" (stale)
55
+ // from "cross pain/session selection" (scope mismatch), the two stable FR-04
56
+ // codes the recovery UX must separate.
57
+ //
58
+ // Cross-bundle note: the plugin bundle INLINES @principles/core (esbuild,
59
+ // core not in `external`), so an `instanceof` check against this module's
60
+ // class would fail across the pd-cli → plugin-bundle boundary. The stable
61
+ // contract is therefore structural: the reserved error `name` plus a
62
+ // validated `ownerEvidenceScopeKind` property (rc-5 hasOwn-style read, rc-1:
63
+ // kind is validated, not trusted).
64
+ /** Reserved error name for Owner evidence scope failures. Do not rename. */
65
+ export const OWNER_EVIDENCE_SCOPE_ERROR_NAME = 'OwnerEvidenceScopeError';
66
+ const SCOPE_MISMATCH_KINDS = new Set([
67
+ 'pain_not_found',
68
+ 'tool_call_not_found',
69
+ 'session_mismatch',
70
+ 'evidence_source_error',
71
+ ]);
72
+ /** Map a structured SCOPE failure to its stable FR-04 reason code.
73
+ * `evidence_source_error` must never enter here — it is not an owner-fault
74
+ * code and is routed by the readiness gate before this helper. */
75
+ function reasonCodeForScopeKind(kind) {
76
+ return kind === 'session_mismatch'
77
+ ? 'owner_behavior_examples_scope_mismatch'
78
+ : 'owner_behavior_examples_stale';
79
+ }
80
+ /** Build the typed error the plugin assembler throws for scope failures. */
81
+ export function createOwnerEvidenceScopeError(kind, message) {
82
+ const error = new Error(message);
83
+ error.name = OWNER_EVIDENCE_SCOPE_ERROR_NAME;
84
+ Object.assign(error, { ownerEvidenceScopeKind: kind });
85
+ return error;
86
+ }
87
+ /** Structural guard (cross-bundle safe — see module comment above). */
88
+ export function isOwnerEvidenceScopeError(value) {
89
+ if (!(value instanceof Error))
90
+ return false;
91
+ if (value.name !== OWNER_EVIDENCE_SCOPE_ERROR_NAME)
92
+ return false;
93
+ const kind = value.ownerEvidenceScopeKind;
94
+ return typeof kind === 'string' && SCOPE_MISMATCH_KINDS.has(kind);
95
+ }
96
+ // ── internal constants ─────────────────────────────────────────────────────
97
+ const SELECTION_FIELD_NAMES = [
98
+ 'sourcePainId',
99
+ 'sourceNegativeToolCallId',
100
+ 'positiveToolCallIds',
101
+ 'ownerDesiredOutcome',
102
+ ];
103
+ const MAX_POSITIVES = 3;
104
+ /** rc-8: bounded previews for unknown failure details. */
105
+ const MAX_DETAIL_LENGTH = 480;
106
+ const MAX_VALIDATION_ERRORS = 8;
107
+ /** `sha256:<64 lowercase hex chars>` — the only accepted contentDigest shape. */
108
+ const CONTENT_DIGEST_PATTERN = /^sha256:[0-9a-f]{64}$/;
109
+ // ── internal helpers ───────────────────────────────────────────────────────
110
+ function isPlainObjectLike(value) {
111
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
112
+ }
113
+ function isNonEmptyString(value) {
114
+ return typeof value === 'string' && value.trim().length > 0;
115
+ }
116
+ function isPositiveSafeInteger(value) {
117
+ return typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
118
+ }
119
+ /** rc-8: bounded, single-line serialization of an unknown error/detail. */
120
+ function boundedDetail(value) {
121
+ let raw;
122
+ if (value instanceof Error) {
123
+ raw = value.message;
124
+ }
125
+ else if (typeof value === 'string') {
126
+ raw = value;
127
+ }
128
+ else {
129
+ try {
130
+ raw = JSON.stringify(value) ?? String(value);
131
+ }
132
+ catch {
133
+ raw = String(value);
134
+ }
135
+ }
136
+ const flat = raw.replace(/\s+/g, ' ').trim();
137
+ return flat.length > MAX_DETAIL_LENGTH
138
+ ? `${flat.slice(0, MAX_DETAIL_LENGTH)}…[truncated]`
139
+ : flat;
140
+ }
141
+ /**
142
+ * Structural validation of the Owner selection (rc-1..rc-5). Returns the list
143
+ * of field-level problems; an empty list means the selection is usable.
144
+ * Semantics deliberately mirror `validateOwnerSelection` in the plugin
145
+ * assembler (positive safe integers, 1..3 unique positives, non-empty text):
146
+ * a present-but-unusable selection is REJECTED, never repaired here.
147
+ *
148
+ * PRI-982: exported as the SINGLE shape authority for the persisted
149
+ * `pi_metadata.ownerEvidenceSelection` field — pitask-metadata parse reuses
150
+ * this validator so the persistence layer and the readiness gate can never
151
+ * diverge on what a usable selection is. Takes `unknown` (rc-1: the metadata
152
+ * parse reads it from a DB row) and rejects non-objects itself.
153
+ */
154
+ export function validateOwnerEvidenceSelectionShape(selection) {
155
+ const problems = [];
156
+ if (!isPlainObjectLike(selection)) {
157
+ return ['ownerSelection must be a plain object'];
158
+ }
159
+ if (!Object.hasOwn(selection, 'sourcePainId') || !isNonEmptyString(selection.sourcePainId)) {
160
+ problems.push('ownerSelection.sourcePainId must be a non-empty string');
161
+ }
162
+ if (!Object.hasOwn(selection, 'sourceNegativeToolCallId')
163
+ || !isPositiveSafeInteger(selection.sourceNegativeToolCallId)) {
164
+ problems.push('ownerSelection.sourceNegativeToolCallId must be a positive safe integer');
165
+ }
166
+ if (!Object.hasOwn(selection, 'positiveToolCallIds') || !Array.isArray(selection.positiveToolCallIds)) {
167
+ problems.push('ownerSelection.positiveToolCallIds must be an array');
168
+ }
169
+ else {
170
+ const ids = selection.positiveToolCallIds;
171
+ if (ids.length === 0 || ids.length > MAX_POSITIVES) {
172
+ problems.push(`ownerSelection.positiveToolCallIds must contain 1 to at most ${MAX_POSITIVES} IDs, got ${ids.length}`);
173
+ }
174
+ for (let i = 0; i < ids.length; i++) {
175
+ if (!isPositiveSafeInteger(ids[i])) {
176
+ problems.push(`ownerSelection.positiveToolCallIds[${i}] must be a positive safe integer`);
177
+ }
178
+ }
179
+ if (new Set(ids).size !== ids.length) {
180
+ problems.push('ownerSelection.positiveToolCallIds must be unique');
181
+ }
182
+ }
183
+ if (!Object.hasOwn(selection, 'ownerDesiredOutcome') || !isNonEmptyString(selection.ownerDesiredOutcome)) {
184
+ problems.push('ownerSelection.ownerDesiredOutcome must be a non-empty string');
185
+ }
186
+ // ── B1 (PRI-983 FR-03) persisted provenance fields — optional (ABSENT =
187
+ // legacy A2 record), but presence MUST be well-formed: a corrupted
188
+ // provenance field fails the whole selection here, which (via the
189
+ // pitask-metadata parse delegation) fails the whole metadata closed.
190
+ if (Object.hasOwn(selection, 'revision') && selection.revision !== undefined) {
191
+ if (typeof selection.revision !== 'number' || !Number.isSafeInteger(selection.revision) || selection.revision < 1) {
192
+ problems.push('ownerSelection.revision must be a positive safe integer when present');
193
+ }
194
+ }
195
+ if (Object.hasOwn(selection, 'contentDigest') && selection.contentDigest !== undefined) {
196
+ if (typeof selection.contentDigest !== 'string' || !CONTENT_DIGEST_PATTERN.test(selection.contentDigest)) {
197
+ problems.push('ownerSelection.contentDigest must match sha256:<64 hex> when present');
198
+ }
199
+ }
200
+ if (Object.hasOwn(selection, 'ownerOperation') && selection.ownerOperation !== undefined) {
201
+ if (!isNonEmptyString(selection.ownerOperation)) {
202
+ problems.push('ownerSelection.ownerOperation must be a non-empty string when present');
203
+ }
204
+ }
205
+ if (Object.hasOwn(selection, 'attachedAt') && selection.attachedAt !== undefined) {
206
+ if (!isNonEmptyString(selection.attachedAt)) {
207
+ problems.push('ownerSelection.attachedAt must be a non-empty ISO string when present');
208
+ }
209
+ }
210
+ return problems;
211
+ }
212
+ /** `sha256:<hex>` content digest over the pack's canonical JSON (rc-6: one hash convention). */
213
+ export function computeBehaviorExamplePackDigest(pack) {
214
+ return `sha256:${createHash('sha256').update(JSON.stringify(pack), 'utf8').digest('hex')}`;
215
+ }
216
+ // ── public entry point ─────────────────────────────────────────────────────
217
+ /**
218
+ * Pure evidence readiness judgment (FR-01). No I/O, no state — the caller
219
+ * injects the assembly step and declares channel applicability.
220
+ *
221
+ * Decision order:
222
+ * 1. channel does not require evidence → `not_applicable`;
223
+ * 2. no Owner selection → `owner_evidence_required` + missingFields;
224
+ * 3. selection present but structurally unusable → `invalid_evidence`
225
+ * (assembler validateOwnerSelection semantics);
226
+ * 4. assembly throws / pre-assembled failure → `invalid_evidence` with the
227
+ * bounded error detail (never swallowed);
228
+ * 5. assembled pack fails `validateBehaviorExamplePack` → `invalid_evidence`
229
+ * (single validator authority);
230
+ * 6. otherwise → `ready` with the pack, its `sha256:<hex>` evidence hash,
231
+ * and the source pain ID.
232
+ */
233
+ export function assessEvidenceReadiness(input) {
234
+ // 1. Caller-declared channel authority. Fail closed: anything but an
235
+ // explicit `false` counts as requiring evidence.
236
+ if (input.channelRequiresOwnerEvidence === false) {
237
+ return { status: 'not_applicable' };
238
+ }
239
+ // 2. Owner selection presence (rc-3: missing fields reported explicitly).
240
+ const selection = input.ownerSelection;
241
+ if (selection === undefined || selection === null) {
242
+ return {
243
+ status: 'owner_evidence_required',
244
+ reasonCode: 'owner_behavior_examples_required',
245
+ missingFields: SELECTION_FIELD_NAMES,
246
+ nextAction: 'Owner must provide the labelled behaviour examples (sourcePainId, sourceNegativeToolCallId, positiveToolCallIds 1..3 unique, ownerDesiredOutcome) via the evidence recovery entry (SPEC-PD-IAER-001 FR-06) before this task can run.',
247
+ };
248
+ }
249
+ // 3. Selection shape (untrusted — rc-1..rc-5; assembler-aligned rejection).
250
+ const selectionProblems = validateOwnerEvidenceSelectionShape(selection);
251
+ if (selectionProblems.length > 0) {
252
+ return {
253
+ status: 'invalid_evidence',
254
+ reasonCode: 'owner_behavior_examples_invalid',
255
+ detail: boundedDetail(selectionProblems.join('; ')),
256
+ nextAction: 'Owner must resubmit a complete, valid evidence selection (positive safe integer tool-call IDs, 1..3 unique positives, non-empty outcome).',
257
+ };
258
+ }
259
+ // 4. Assembly — callback (throws captured) or pre-computed outcome.
260
+ let assemblyError;
261
+ let pack;
262
+ if (input.assemblePack !== undefined) {
263
+ try {
264
+ pack = input.assemblePack();
265
+ }
266
+ catch (error) {
267
+ assemblyError = error;
268
+ }
269
+ }
270
+ else if (input.assemblyResult !== undefined) {
271
+ if (input.assemblyResult.ok) {
272
+ ({ pack } = input.assemblyResult);
273
+ }
274
+ else {
275
+ assemblyError = input.assemblyResult.error;
276
+ }
277
+ }
278
+ if (pack === undefined) {
279
+ // B1: structured scope classification first (typed error, never message
280
+ // sniffing). pain/row unresolvable → stale (FR-03: cleaned trajectory must
281
+ // not be silently reused); cross-session selection → scope mismatch
282
+ // (SPEC FR-04). PRI-980 review P2-1: a typed evidence_source_error (the
283
+ // assembler's trajectory-store I/O failure) is routed to the §6.2
284
+ // storage-fault family — task-side routing must keep the task
285
+ // wake-eligible, never write an owner-fault reason. Plain errors stay
286
+ // `invalid` (A2 behavior unchanged).
287
+ if (isOwnerEvidenceScopeError(assemblyError)) {
288
+ if (assemblyError.ownerEvidenceScopeKind === 'evidence_source_error') {
289
+ return {
290
+ status: 'evidence_source_error',
291
+ reason: 'evidence_source_error',
292
+ detail: boundedDetail(assemblyError.message),
293
+ nextAction: 'The evidence source itself failed (trajectory store I/O); this is NOT an Owner evidence fault. The task stays wake-eligible and the next cycle retries assembly at zero model cost; if it persists, inspect the trajectory store for this workspace (pd runtime internalization integrity --json).',
294
+ };
295
+ }
296
+ const reasonCode = reasonCodeForScopeKind(assemblyError.ownerEvidenceScopeKind);
297
+ return {
298
+ status: 'invalid_evidence',
299
+ reasonCode,
300
+ detail: boundedDetail(`${assemblyError.ownerEvidenceScopeKind}: ${assemblyError.message}`),
301
+ nextAction: reasonCode === 'owner_behavior_examples_stale'
302
+ ? 'Trajectory evidence is missing or has changed; Owner must re-attach fresh examples (pd runtime internalization evidence attach --confirm) before this task can resume.'
303
+ : 'Owner must select tool calls that belong to the referenced pain session (cross pain/session selections are refused), then re-attach.',
304
+ };
305
+ }
306
+ return {
307
+ status: 'invalid_evidence',
308
+ reasonCode: 'owner_behavior_examples_invalid',
309
+ detail: boundedDetail(assemblyError),
310
+ nextAction: 'Evidence assembly failed; Owner must re-select examples that still exist in the pain lineage, then retry (do not blindly retry the task).',
311
+ };
312
+ }
313
+ // 5. Single pack-validation authority (reuse, never a second validator).
314
+ const validation = validateBehaviorExamplePack(pack);
315
+ if (!validation.valid) {
316
+ const errors = validation.errors.slice(0, MAX_VALIDATION_ERRORS);
317
+ const truncated = validation.errors.length > errors.length
318
+ ? ` …[+${validation.errors.length - errors.length} more]`
319
+ : '';
320
+ return {
321
+ status: 'invalid_evidence',
322
+ reasonCode: 'owner_behavior_examples_invalid',
323
+ detail: boundedDetail(`${errors.join('; ')}${truncated}`),
324
+ nextAction: 'Owner-provided evidence failed the BehaviorExamplePack contract; Owner must correct the labelled examples and resubmit.',
325
+ };
326
+ }
327
+ // 6. Ready.
328
+ return {
329
+ status: 'ready',
330
+ pack,
331
+ evidenceHash: computeBehaviorExamplePackDigest(pack),
332
+ sourcePainId: selection.sourcePainId,
333
+ };
334
+ }
335
+ //# sourceMappingURL=evidence-readiness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evidence-readiness.js","sourceRoot":"","sources":["../../../src/runtime-v2/internalization/evidence-readiness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAA4B,MAAM,4BAA4B,CAAC;AAiDnG,8EAA8E;AAC9E,EAAE;AACF,6EAA6E;AAC7E,sEAAsE;AACtE,4EAA4E;AAC5E,4EAA4E;AAC5E,6EAA6E;AAC7E,uCAAuC;AACvC,EAAE;AACF,0EAA0E;AAC1E,0EAA0E;AAC1E,0EAA0E;AAC1E,qEAAqE;AACrE,6EAA6E;AAC7E,mCAAmC;AAEnC,4EAA4E;AAC5E,MAAM,CAAC,MAAM,+BAA+B,GAAG,yBAAyB,CAAC;AA0BzE,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC;IACxD,gBAAgB;IAChB,qBAAqB;IACrB,kBAAkB;IAClB,uBAAuB;CACxB,CAAC,CAAC;AAEH;;mEAEmE;AACnE,SAAS,sBAAsB,CAAC,IAAoC;IAClE,OAAO,IAAI,KAAK,kBAAkB;QAChC,CAAC,CAAC,wCAAwC;QAC1C,CAAC,CAAC,+BAA+B,CAAC;AACtC,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,6BAA6B,CAC3C,IAAoC,EACpC,OAAe;IAEf,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IACjC,KAAK,CAAC,IAAI,GAAG,+BAA+B,CAAC;IAC7C,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,sBAAsB,EAAE,IAAI,EAAE,CAAC,CAAC;IACvD,OAAO,KA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AU,GAAG,2BAA2B,CAAC,IAAI,CAAC,CAAC;IACrD,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACtB,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC;QACjE,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM;YACxD,CAAC,CAAC,OAAO,UAAU,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,QAAQ;YACzD,CAAC,CAAC,EAAE,CAAC;QACP,OAAO;YACL,MAAM,EAAE,kBAAkB;YAC1B,UAAU,EAAE,iCAAiC;YAC7C,MAAM,EAAE,aAAa,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC;YACzD,UAAU,EAAE,yHAAyH;SACtI,CAAC;IACJ,CAAC;IAED,YAAY;IACZ,OAAO;QACL,MAAM,EAAE,OAAO;QACf,IAAI;QACJ,YAAY,EAAE,gCAAgC,CAAC,IAAI,CAAC;QACpD,YAAY,EAAE,SAAS,CAAC,YAAY;KACrC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,190 @@
1
+ /**
2
+ * owner-evidence-recovery.ts — Owner evidence attach/resume (B1, PRI-983).
3
+ *
4
+ * SPEC-PD-IAER-001 FR-03 (persist the Owner's evidence selection with
5
+ * revision/digest/provenance) and FR-06 (query → attach → atomic resume).
6
+ * This module is the ONE recovery sequence for evidence-waiting tasks;
7
+ * both CLI entries (`pd runtime internalization evidence attach|resume|list`)
8
+ * and any future Console face drive it — no logic is duplicated at the
9
+ * callers (same rule owner-retry.ts established for the NHR out-edge).
10
+ *
11
+ * Composition with existing authorities (P2/P4 — nothing new is invented):
12
+ * - selection shape + readiness judgment: evidence-readiness.ts (A2);
13
+ * - persisted location: `pi_metadata.ownerEvidenceSelection` inside
14
+ * diagnosticJson (A2 field; B1 adds the provenance fields INSIDE the
15
+ * selection object — pitask-metadata carries the object opaquely, the
16
+ * shared shape authority validates the extended shape, ABSENT = legacy);
17
+ * - the resume state transition itself: `ownerRetryNeedsHumanReviewTask`
18
+ * (owner-retry.ts), called with the new optional CAS precondition —
19
+ * the single recovery authority is reused, never copied;
20
+ * - digest authority: `computeBehaviorExamplePackDigest` (same bytes the
21
+ * readiness verdict hashes);
22
+ * - audit: `.state/recovery_actions.jsonl` append family
23
+ * (appendOwnerEvidenceAction);
24
+ * - telemetry: `artificer_owner_evidence_attached` /
25
+ * `artificer_owner_evidence_resumed` (FR-08, bounded payloads, rc-8),
26
+ * both carrying the unified FR-08 run-correlation block (PRI-984,
27
+ * artificer-run-correlation.ts); persistentRunId is semantically absent —
28
+ * recovery runs against an NHR task / a pending requeue where no run row
29
+ * exists yet.
30
+ *
31
+ * Contract decisions pinned here:
32
+ * - attach NEVER unblocks: the task stays `needs_human_review`; only the
33
+ * explicit `resume` authority reset returns it to pending (FR-06 6/7).
34
+ * - resume re-assembles and compares digests: a mismatch refuses with
35
+ * `owner_behavior_examples_stale` — a silently stale evidence reference
36
+ * can never re-enter the model (FR-03).
37
+ * - FR-06 budget semantics: the authority reset zeroes attemptCount. That
38
+ * is an EXPLICIT, `--confirm`-gated, digest-verified, audited operator
39
+ * action — not the forbidden "background silently clears history
40
+ * attemptCount": previousAttemptCount is recorded in the audit record
41
+ * and the run history / humanReviewContext stay in place (nothing is
42
+ * deleted; T05 asserts run rows are preserved).
43
+ * - concurrency (T06): the reset runs as ONE conditional UPDATE
44
+ * (`updateTaskIfDiagnosticJsonUnchanged` via the CAS option). Two
45
+ * concurrent resumes → at most one `resumed`; the loser gets a
46
+ * structured `conflict` refusal with zero mutation.
47
+ * - authorization expression (notes §8 reality): confirm-level command +
48
+ * explicit decidedBy label + append-only audit + revision/digest
49
+ * provenance. No new authentication mechanism is invented here.
50
+ *
51
+ * rc-1/rc-2: the stored selection arrives from parsed diagnosticJson and is
52
+ * re-validated by the shared shape authority before any use. rc-3: required
53
+ * preconditions fail loudly with stable reasons + nextAction (rc-9). rc-8:
54
+ * telemetry payloads carry bounded references only.
55
+ *
56
+ * Spec: docs/specs/SPEC-PD-IAER-001-v1.0.md §5 FR-03, FR-06, §6.1-§6.3
57
+ */
58
+ import type { StoreEventEmitter } from '../store/event-emitter.js';
59
+ import type { RuntimeStateManager } from '../store/runtime-state-manager.js';
60
+ import { type OwnerEvidenceReasonCode, type OwnerEvidenceSelection } from './evidence-readiness.js';
61
+ import { type BehaviorEvidencePort } from './consumer-evidence-preflight.js';
62
+ /**
63
+ * FR-04: a task is "waiting for Owner evidence" iff it sits in
64
+ * needs_human_review with one of the four stable reason codes in its
65
+ * humanReviewContext. Other NHR tasks (verdict reviews etc.) are NOT
66
+ * evidence-waiting and are never touched by this module.
67
+ */
68
+ export declare const EVIDENCE_WAIT_REASON_CODES: ReadonlySet<string>;
69
+ export interface EvidenceWaitingTaskSummary {
70
+ readonly taskId: string;
71
+ readonly channel: string;
72
+ /** The attached selection's pain id; null while nothing is attached. */
73
+ readonly painId: string | null;
74
+ readonly reasonCode: string;
75
+ readonly missingFields: readonly string[];
76
+ readonly nextAction: string;
77
+ readonly attemptCount: number;
78
+ readonly maxAttempts: number;
79
+ /** Attach revision of the stored selection; 0 = nothing attached. */
80
+ readonly evidenceRevision: number;
81
+ }
82
+ export declare function listEvidenceWaitingTasks(stateManager: RuntimeStateManager): Promise<EvidenceWaitingTaskSummary[]>;
83
+ export interface AttachOwnerEvidenceInput {
84
+ readonly taskId: string;
85
+ /** The Owner-provided selection (base contract fields only). */
86
+ readonly selection: Pick<OwnerEvidenceSelection, 'sourcePainId' | 'sourceNegativeToolCallId' | 'positiveToolCallIds' | 'ownerDesiredOutcome'>;
87
+ /** Operator label (`--decidedBy`); recorded in provenance + audit. */
88
+ readonly decidedBy?: string;
89
+ readonly mode: 'dry_run' | 'confirm';
90
+ /** Injected assembly (production: BehaviorExamplePackAssembler port). */
91
+ readonly assemble: BehaviorEvidencePort;
92
+ /** Workspace root — audit log location. */
93
+ readonly workspaceDir: string;
94
+ readonly eventEmitter: StoreEventEmitter;
95
+ /** Session label for telemetry (e.g. 'pd-cli:evidence'). */
96
+ readonly owner: string;
97
+ }
98
+ export type OwnerEvidenceAttachOutcome = {
99
+ readonly status: 'dry_run';
100
+ readonly taskId: string;
101
+ /** The selection summary that WOULD be persisted (not written). */
102
+ readonly wouldPersist: {
103
+ readonly revision: number;
104
+ readonly contentDigest: string;
105
+ readonly ownerOperation: string;
106
+ readonly attachedAt: string;
107
+ };
108
+ readonly painId: string;
109
+ readonly nextAction: string;
110
+ } | {
111
+ readonly status: 'attached';
112
+ readonly taskId: string;
113
+ readonly revision: number;
114
+ readonly contentDigest: string;
115
+ readonly ownerOperation: string;
116
+ readonly attachedAt: string;
117
+ /** false = attach landed but the task still blocks (always — attach never unblocks). */
118
+ readonly taskStillNeedsHumanReview: true;
119
+ readonly nextAction: string;
120
+ } | {
121
+ readonly status: 'refused';
122
+ readonly taskId: string;
123
+ /** Stable reason: FR-04 code or a structural refusal id. */
124
+ readonly reason: string;
125
+ readonly detail?: string;
126
+ readonly missingFields?: readonly string[];
127
+ readonly nextAction: string;
128
+ } | {
129
+ readonly status: 'conflict';
130
+ readonly taskId: string;
131
+ readonly nextAction: string;
132
+ };
133
+ /**
134
+ * FR-03/FR-06 3-6: assemble + validate the Owner selection, then persist it
135
+ * (with revision/contentDigest/ownerOperation/attachedAt) into
136
+ * `pi_metadata.ownerEvidenceSelection` via the narrow diagnosticJson CAS.
137
+ * Dry-run assembles and reports without writing ANY state (cli-5); failures
138
+ * refuse with the stable FR-04 reason codes and zero mutation.
139
+ */
140
+ export declare function attachOwnerEvidence(stateManager: RuntimeStateManager, input: AttachOwnerEvidenceInput): Promise<OwnerEvidenceAttachOutcome>;
141
+ export interface ResumeOwnerEvidenceInput {
142
+ readonly taskId: string;
143
+ readonly decidedBy?: string;
144
+ readonly mode: 'dry_run' | 'confirm';
145
+ readonly assemble: BehaviorEvidencePort;
146
+ readonly workspaceDir: string;
147
+ readonly eventEmitter: StoreEventEmitter;
148
+ readonly owner: string;
149
+ }
150
+ export type OwnerEvidenceResumeOutcome = {
151
+ readonly status: 'dry_run';
152
+ readonly taskId: string;
153
+ readonly reasonCode: OwnerEvidenceReasonCode | 'owner_behavior_examples_verified';
154
+ readonly previousAttemptCount: number;
155
+ readonly revision: number;
156
+ readonly contentDigest: string;
157
+ readonly painId: string;
158
+ readonly nextAction: string;
159
+ } | {
160
+ readonly status: 'resumed';
161
+ readonly taskId: string;
162
+ readonly previousStatus: 'needs_human_review';
163
+ readonly newStatus: 'pending';
164
+ readonly previousAttemptCount: number;
165
+ readonly revision: number;
166
+ readonly contentDigest: string;
167
+ readonly nextAction: string;
168
+ } | {
169
+ readonly status: 'refused';
170
+ readonly taskId: string;
171
+ readonly reason: string;
172
+ readonly detail?: string;
173
+ readonly nextAction: string;
174
+ } | {
175
+ readonly status: 'conflict';
176
+ readonly taskId: string;
177
+ readonly nextAction: string;
178
+ };
179
+ /**
180
+ * FR-06 7/8: digest-verified, atomic, single-authority recovery.
181
+ *
182
+ * Sequence: NHR + evidence-code gate → stored selection present → re-assemble
183
+ * through the shared readiness judgment → digest comparison (mismatch ⇒
184
+ * `owner_behavior_examples_stale`, missing digest ⇒ `invalid`) → ONE
185
+ * conditional authority reset via `ownerRetryNeedsHumanReviewTask` (CAS
186
+ * option; loser gets `conflict`). Run history / audit records are never
187
+ * deleted; the attempt budget reset is explicit and audited (see header).
188
+ */
189
+ export declare function resumeOwnerEvidenceTask(stateManager: RuntimeStateManager, input: ResumeOwnerEvidenceInput): Promise<OwnerEvidenceResumeOutcome>;
190
+ //# sourceMappingURL=owner-evidence-recovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"owner-evidence-recovery.d.ts","sourceRoot":"","sources":["../../../src/runtime-v2/internalization/owner-evidence-recovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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