create-principles-disciple 1.145.1 → 1.145.4
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 +2 -2
- package/codex-adapter/dist/worker/workspace-worker.js +2 -1
- package/codex-adapter/package.json +1 -1
- package/console/dist/server/config/pd-config-store.js +3 -0
- package/console/dist/server/models/ApprovalsGroupedConsoleModel.js +4 -4
- package/console/dist/ui/i18n/en.json +17 -16
- package/console/dist/ui/i18n/zh-CN.json +17 -16
- package/console/dist/ui/pages/focus/FocusPage.js +9 -5
- package/console/dist/ui/pages/focus/OwnerDecisionCard.js +1 -1
- package/console/dist/ui/pages/principles/PrincipleDetailPage.js +10 -4
- package/console/dist/ui/pages/principles/PrinciplesPage.js +1 -1
- package/console/dist/ui/utils/reading-layout.d.ts +19 -0
- package/console/dist/ui/utils/reading-layout.js +46 -0
- package/console/dist/web/assets/app.js +30 -28
- package/core/dist/runtime-v2/index.d.ts +13 -3
- package/core/dist/runtime-v2/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/index.js +6 -1
- package/core/dist/runtime-v2/index.js.map +1 -1
- package/core/dist/runtime-v2/internalization/artificer-prompt-builder.d.ts +25 -6
- package/core/dist/runtime-v2/internalization/artificer-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/artificer-prompt-builder.js +21 -7
- package/core/dist/runtime-v2/internalization/artificer-prompt-builder.js.map +1 -1
- package/core/dist/runtime-v2/internalization/artificer-run-correlation.d.ts +82 -0
- package/core/dist/runtime-v2/internalization/artificer-run-correlation.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/artificer-run-correlation.js +79 -0
- package/core/dist/runtime-v2/internalization/artificer-run-correlation.js.map +1 -0
- package/core/dist/runtime-v2/internalization/artificer-runner.d.ts +16 -2
- package/core/dist/runtime-v2/internalization/artificer-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/artificer-runner.js +89 -9
- package/core/dist/runtime-v2/internalization/artificer-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/consumer-evidence-preflight.d.ts +141 -0
- package/core/dist/runtime-v2/internalization/consumer-evidence-preflight.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/consumer-evidence-preflight.js +284 -0
- package/core/dist/runtime-v2/internalization/consumer-evidence-preflight.js.map +1 -0
- package/core/dist/runtime-v2/internalization/evidence-readiness.d.ts +170 -0
- package/core/dist/runtime-v2/internalization/evidence-readiness.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/evidence-readiness.js +335 -0
- package/core/dist/runtime-v2/internalization/evidence-readiness.js.map +1 -0
- package/core/dist/runtime-v2/internalization/owner-evidence-recovery.d.ts +190 -0
- package/core/dist/runtime-v2/internalization/owner-evidence-recovery.d.ts.map +1 -0
- package/core/dist/runtime-v2/internalization/owner-evidence-recovery.js +488 -0
- package/core/dist/runtime-v2/internalization/owner-evidence-recovery.js.map +1 -0
- package/core/dist/runtime-v2/internalization/owner-retry.d.ts +23 -1
- package/core/dist/runtime-v2/internalization/owner-retry.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/owner-retry.js +19 -3
- package/core/dist/runtime-v2/internalization/owner-retry.js.map +1 -1
- package/core/dist/runtime-v2/internalization/peer-runner-contracts.d.ts +16 -1
- package/core/dist/runtime-v2/internalization/peer-runner-contracts.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/peer-runner-contracts.js.map +1 -1
- package/core/dist/runtime-v2/internalization/pitask-metadata.d.ts +44 -0
- package/core/dist/runtime-v2/internalization/pitask-metadata.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/pitask-metadata.js +75 -0
- package/core/dist/runtime-v2/internalization/pitask-metadata.js.map +1 -1
- package/core/dist/runtime-v2/recovery-actions-log.d.ts +55 -0
- package/core/dist/runtime-v2/recovery-actions-log.d.ts.map +1 -1
- package/core/dist/runtime-v2/recovery-actions-log.js +84 -3
- package/core/dist/runtime-v2/recovery-actions-log.js.map +1 -1
- package/core/dist/runtime-v2/recovery-sweep-service.d.ts +116 -1
- package/core/dist/runtime-v2/recovery-sweep-service.d.ts.map +1 -1
- package/core/dist/runtime-v2/recovery-sweep-service.js +252 -13
- package/core/dist/runtime-v2/recovery-sweep-service.js.map +1 -1
- package/core/dist/runtime-v2/runtime-state-handle.d.ts +8 -0
- package/core/dist/runtime-v2/runtime-state-handle.d.ts.map +1 -1
- package/core/dist/runtime-v2/runtime-state-handle.js +1 -0
- package/core/dist/runtime-v2/runtime-state-handle.js.map +1 -1
- package/core/dist/runtime-v2/store/runtime-state-manager.d.ts +16 -1
- package/core/dist/runtime-v2/store/runtime-state-manager.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/runtime-state-manager.js +7 -2
- package/core/dist/runtime-v2/store/runtime-state-manager.js.map +1 -1
- package/core/dist/runtime-v2/store/task/memory-task-store.d.ts +7 -1
- package/core/dist/runtime-v2/store/task/memory-task-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/task/memory-task-store.js +16 -1
- package/core/dist/runtime-v2/store/task/memory-task-store.js.map +1 -1
- package/core/dist/runtime-v2/store/task/sqlite-task-store.d.ts +7 -1
- package/core/dist/runtime-v2/store/task/sqlite-task-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/task/sqlite-task-store.js +31 -2
- package/core/dist/runtime-v2/store/task/sqlite-task-store.js.map +1 -1
- package/core/dist/runtime-v2/store/task/task-store.d.ts +19 -5
- package/core/dist/runtime-v2/store/task/task-store.d.ts.map +1 -1
- package/core/dist/telemetry-event.d.ts +2 -2
- package/core/dist/telemetry-event.d.ts.map +1 -1
- package/core/dist/telemetry-event.js +13 -0
- package/core/dist/telemetry-event.js.map +1 -1
- package/core/package.json +5 -1
- package/dist/installer.d.ts +1 -1
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +5 -1
- package/dist/installer.js.map +1 -1
- package/dist/installers/workbuddy-host-installer.d.ts +16 -3
- package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
- package/dist/installers/workbuddy-host-installer.js +62 -11
- package/dist/installers/workbuddy-host-installer.js.map +1 -1
- package/dist/manifest-host-union.d.ts +23 -0
- package/dist/manifest-host-union.d.ts.map +1 -0
- package/dist/manifest-host-union.js +22 -0
- package/dist/manifest-host-union.js.map +1 -0
- package/dist/uninstaller.d.ts +2 -1
- package/dist/uninstaller.d.ts.map +1 -1
- package/dist/uninstaller.js +7 -1
- package/dist/uninstaller.js.map +1 -1
- package/host-runtime/dist/behavior-example-pack-assembler.d.ts +41 -0
- package/host-runtime/dist/behavior-example-pack-assembler.js +243 -0
- package/host-runtime/dist/behavior-history.d.ts +6 -0
- package/host-runtime/dist/behavior-history.js +76 -0
- package/host-runtime/dist/index.d.ts +3 -0
- package/host-runtime/dist/index.js +3 -0
- package/host-runtime/dist/internalization-consumer-cycle.d.ts +12 -1
- package/host-runtime/dist/internalization-consumer-cycle.js +141 -16
- package/host-runtime/dist/workspace-behavior-evidence.d.ts +3 -0
- package/host-runtime/dist/workspace-behavior-evidence.js +74 -0
- package/host-runtime/dist/workspace-telemetry-emitter.js +13 -0
- package/host-runtime/package.json +10 -2
- package/install-layout/dist/index.d.ts +40 -1
- package/install-layout/dist/index.js +88 -6
- package/install-layout/package.json +1 -1
- package/package.json +3 -3
- package/pd-cli/dist/commands/runtime-internalization-audit-artificer-evidence.d.ts +44 -0
- package/pd-cli/dist/commands/runtime-internalization-audit-artificer-evidence.d.ts.map +1 -0
- package/pd-cli/dist/commands/runtime-internalization-audit-artificer-evidence.js +138 -0
- package/pd-cli/dist/commands/runtime-internalization-audit-artificer-evidence.js.map +1 -0
- package/pd-cli/dist/commands/runtime-internalization-evidence.d.ts +71 -0
- package/pd-cli/dist/commands/runtime-internalization-evidence.d.ts.map +1 -0
- package/pd-cli/dist/commands/runtime-internalization-evidence.js +405 -0
- package/pd-cli/dist/commands/runtime-internalization-evidence.js.map +1 -0
- package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-once.js +22 -1
- package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-rulehost.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js +45 -4
- package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js.map +1 -1
- package/pd-cli/dist/commands/runtime-recovery-failed-task.d.ts +22 -0
- package/pd-cli/dist/commands/runtime-recovery-failed-task.d.ts.map +1 -0
- package/pd-cli/dist/commands/runtime-recovery-failed-task.js +470 -0
- package/pd-cli/dist/commands/runtime-recovery-failed-task.js.map +1 -0
- package/pd-cli/dist/commands/runtime-recovery-failed-tasks.d.ts +24 -0
- package/pd-cli/dist/commands/runtime-recovery-failed-tasks.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-recovery-failed-tasks.js +4 -1
- package/pd-cli/dist/commands/runtime-recovery-failed-tasks.js.map +1 -1
- package/pd-cli/dist/index.js +13 -0
- package/pd-cli/dist/index.js.map +1 -1
- package/pd-cli/dist/services/artificer-evidence-audit.d.ts +156 -0
- package/pd-cli/dist/services/artificer-evidence-audit.d.ts.map +1 -0
- package/pd-cli/dist/services/artificer-evidence-audit.js +321 -0
- package/pd-cli/dist/services/artificer-evidence-audit.js.map +1 -0
- package/pd-cli/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
- package/pd-cli/dist/services/rulehost-pipeline-runner.js +17 -3
- package/pd-cli/dist/services/rulehost-pipeline-runner.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/plugin/dist/bundle.js +545 -541
- package/plugin/dist/core/behavior-example-pack-assembler.d.ts +4 -32
- package/plugin/dist/core/rule-context-assembler.d.ts +0 -9
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/dist/rulehost-evidence.js +27 -27
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/release-manager/dist/installer.d.ts +1 -1
- package/release-manager/dist/installer.d.ts.map +1 -1
- package/release-manager/dist/installer.js +5 -1
- package/release-manager/dist/installer.js.map +1 -1
- package/release-manager/dist/installers/workbuddy-host-installer.d.ts +16 -3
- package/release-manager/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
- package/release-manager/dist/installers/workbuddy-host-installer.js +62 -11
- package/release-manager/dist/installers/workbuddy-host-installer.js.map +1 -1
- package/release-manager/dist/manifest-host-union.d.ts +23 -0
- package/release-manager/dist/manifest-host-union.d.ts.map +1 -0
- package/release-manager/dist/manifest-host-union.js +22 -0
- package/release-manager/dist/manifest-host-union.js.map +1 -0
- package/release-manager/dist/uninstaller.d.ts +2 -1
- package/release-manager/dist/uninstaller.d.ts.map +1 -1
- package/release-manager/dist/uninstaller.js +7 -1
- package/release-manager/dist/uninstaller.js.map +1 -1
- package/release-manager/package.json +2 -2
- package/workbuddy-adapter/package.json +1 -1
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { assessEvidenceReadiness, } from './evidence-readiness.js';
|
|
2
|
+
import { buildArtificerRunCorrelation } from './artificer-run-correlation.js';
|
|
3
|
+
import { PDRuntimeError } from '../error-categories.js';
|
|
4
|
+
import { createPITaskDiagnosticJson, mergePITaskMetadata, hydratePITaskRecord, parseSeedSourcePainId } from './pitask-metadata.js';
|
|
5
|
+
/**
|
|
6
|
+
* Resolve the canonical Pain from the trusted seed along the persisted
|
|
7
|
+
* predecessor graph. Never infer Pain from model output or the Owner's
|
|
8
|
+
* selection. Multiple conflicting seeds and unresolvable ancestry fail closed.
|
|
9
|
+
*/
|
|
10
|
+
export async function resolveArtificerCanonicalPainId(taskId, getTask) {
|
|
11
|
+
const pending = [taskId];
|
|
12
|
+
const seen = new Set();
|
|
13
|
+
const pains = new Set();
|
|
14
|
+
while (pending.length > 0 && seen.size < 64) {
|
|
15
|
+
const id = pending.shift();
|
|
16
|
+
if (id === undefined || seen.has(id))
|
|
17
|
+
continue;
|
|
18
|
+
seen.add(id);
|
|
19
|
+
const task = await getTask(id);
|
|
20
|
+
if (task === null)
|
|
21
|
+
return null;
|
|
22
|
+
const sourcePainId = parseSeedSourcePainId(task.diagnosticJson);
|
|
23
|
+
if (sourcePainId !== null)
|
|
24
|
+
pains.add(sourcePainId);
|
|
25
|
+
const piTask = hydratePITaskRecord(task);
|
|
26
|
+
if (piTask) {
|
|
27
|
+
for (const parentId of [piTask.parentTaskId, ...piTask.dependencyTaskIds]) {
|
|
28
|
+
if (typeof parentId === 'string' && parentId.length > 0 && !seen.has(parentId)) {
|
|
29
|
+
pending.push(parentId);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return pending.length === 0 && pains.size === 1 ? [...pains][0] ?? null : null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Lineage marker for preflight NHR transitions. Honest by construction: this
|
|
38
|
+
* is NOT a persisted run id (`run_<taskId>_<attempt>` spelling is reserved
|
|
39
|
+
* for lease-minted runs — there is no run for a pure preflight block), and
|
|
40
|
+
* consumer-side recovery classification treats unknown reasonCodes as
|
|
41
|
+
* recovery-type review, which never resolves artifacts through sourceRunId.
|
|
42
|
+
*/
|
|
43
|
+
export const ARTIFICER_EVIDENCE_NHR_SOURCE_RUN_ID = 'evidence-preflight';
|
|
44
|
+
/** rc-8: bounded single-line detail for metadata payloads. */
|
|
45
|
+
function boundedDetail(value, max = 480) {
|
|
46
|
+
const flat = value.replace(/\s+/g, ' ').trim();
|
|
47
|
+
return flat.length > max ? `${flat.slice(0, max)}…[truncated]` : flat;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* FR-04: the persisted NHR diagnostics must name the concrete out-edge — the
|
|
51
|
+
* `pd runtime internalization retry --confirm` recovery authority
|
|
52
|
+
* (ownerRetryNeedsHumanReviewTask) and the B1 evidence-attach entry.
|
|
53
|
+
*/
|
|
54
|
+
function withNhrOutEdge(nextAction) {
|
|
55
|
+
return `${nextAction} Out-edge once evidence is attached (or to abandon this review): pd runtime internalization retry --confirm.`;
|
|
56
|
+
}
|
|
57
|
+
function readDiagnosticJson(task) {
|
|
58
|
+
const raw = task.diagnosticJson;
|
|
59
|
+
return typeof raw === 'string' && raw.trim() !== '' ? raw : null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* SPEC-PD-IAER-001 §6.3: the exact set of statuses a task may sit in when the
|
|
63
|
+
* consumer preflight reaches it — `InternalizationOrchestrator.findCandidates`
|
|
64
|
+
* scans pending AND retry_wait, and the preflight runs on the dry-run wake of
|
|
65
|
+
* those candidates. The NHR transition may only land from a WAKE-ELIGIBLE
|
|
66
|
+
* status: `acquireLease` moves a task to `leased` WITHOUT touching
|
|
67
|
+
* diagnostic_json, so a consumer that read the task before another consumer
|
|
68
|
+
* leased it must LOSE this write (rc-9: observable lost race) instead of
|
|
69
|
+
* writing needs_human_review over an actively leased task.
|
|
70
|
+
*/
|
|
71
|
+
const WAKE_ELIGIBLE_NHR_SOURCES = ['pending', 'retry_wait'];
|
|
72
|
+
/**
|
|
73
|
+
* Atomic needs_human_review transition (evaluator-runner NHR precedent):
|
|
74
|
+
* status + humanReviewContext in ONE CAS-guarded metadata write, then the
|
|
75
|
+
* read-back invariant (INV-2 class: only a durable effect may be reported).
|
|
76
|
+
*
|
|
77
|
+
* §6.3 status precondition: the store CAS takes a single expected-status
|
|
78
|
+
* literal, so the two wake-eligible sources are tried as two individually
|
|
79
|
+
* atomic conditional UPDATEs over the same read-time diagnosticJson snapshot.
|
|
80
|
+
* A task concurrently leased/moved by another consumer matches neither
|
|
81
|
+
* precondition → the write loses and `false` is reported — never a partial
|
|
82
|
+
* or clobbering effect.
|
|
83
|
+
*/
|
|
84
|
+
async function transitionToNeedsHumanReview(params, context) {
|
|
85
|
+
const { taskId, piTask, stateManager } = params;
|
|
86
|
+
const merged = mergePITaskMetadata(piTask, { humanReviewContext: context });
|
|
87
|
+
const patch = {
|
|
88
|
+
status: 'needs_human_review',
|
|
89
|
+
diagnosticJson: createPITaskDiagnosticJson(merged),
|
|
90
|
+
};
|
|
91
|
+
const expectedDiagnosticJson = readDiagnosticJson(piTask);
|
|
92
|
+
let updated = null;
|
|
93
|
+
for (const expectedStatus of WAKE_ELIGIBLE_NHR_SOURCES) {
|
|
94
|
+
updated = await stateManager.updateTaskIfDiagnosticJsonUnchanged(taskId, expectedDiagnosticJson, patch, { expectedStatus });
|
|
95
|
+
if (updated !== null) {
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (!updated) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
const current = await stateManager.getTask(taskId);
|
|
103
|
+
if (!current || current.status !== 'needs_human_review') {
|
|
104
|
+
throw new PDRuntimeError('storage_unavailable', `needs_human_review effect not durable for task ${taskId} (read-back status: ${current?.status ?? 'task_missing'})`);
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Run the evidence readiness preflight for one code_tool_hook Artificer task.
|
|
110
|
+
* The caller owns channel resolution (pi_metadata.channel ===
|
|
111
|
+
* 'code_tool_hook'); this module never re-guesses channels.
|
|
112
|
+
*/
|
|
113
|
+
export async function preflightArtificerOwnerEvidence(params) {
|
|
114
|
+
const { taskId, piTask, owner, workspaceDir, eventEmitter, behaviorEvidence } = params;
|
|
115
|
+
// 1. Host assembly gap — never misread as "Owner has not labeled" (§6.2).
|
|
116
|
+
if (behaviorEvidence === undefined) {
|
|
117
|
+
return { decision: 'evidence_source_unavailable' };
|
|
118
|
+
}
|
|
119
|
+
const selection = piTask.ownerEvidenceSelection;
|
|
120
|
+
let readiness = assessEvidenceReadiness({
|
|
121
|
+
channelRequiresOwnerEvidence: true,
|
|
122
|
+
ownerSelection: selection ?? null,
|
|
123
|
+
assemblePack: selection !== undefined ? () => behaviorEvidence.assemble(selection) : undefined,
|
|
124
|
+
});
|
|
125
|
+
// The persisted digest is an Owner confirmation, not just a syntactic field.
|
|
126
|
+
// The trajectory may change AFTER resume and BEFORE the next consumer wake.
|
|
127
|
+
// An assembled but changed pack must never enter the model (TOCTOU guard).
|
|
128
|
+
if (readiness.status === 'ready'
|
|
129
|
+
&& selection?.contentDigest !== undefined
|
|
130
|
+
&& readiness.evidenceHash !== selection.contentDigest) {
|
|
131
|
+
readiness = {
|
|
132
|
+
status: 'invalid_evidence',
|
|
133
|
+
reasonCode: 'owner_behavior_examples_stale',
|
|
134
|
+
detail: 'assembled evidence digest differs from the Owner-confirmed digest',
|
|
135
|
+
nextAction: 'Evidence changed after Owner confirmation; re-attach fresh examples, verify and resume.',
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
if (readiness.status === 'ready') {
|
|
139
|
+
const canonicalPainId = await resolveArtificerCanonicalPainId(taskId, (id) => params.stateManager.getTask(id));
|
|
140
|
+
if (canonicalPainId === null || canonicalPainId !== readiness.sourcePainId) {
|
|
141
|
+
readiness = {
|
|
142
|
+
status: 'invalid_evidence',
|
|
143
|
+
reasonCode: 'owner_behavior_examples_scope_mismatch',
|
|
144
|
+
detail: 'Owner evidence Pain does not match a unique canonical task seed Pain',
|
|
145
|
+
nextAction: 'Inspect the task lineage and reselect evidence for its canonical source Pain.',
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Telemetry (FR-08): the gate ran — record the verdict with the unified
|
|
150
|
+
// run-correlation block (PRI-984; persistentRunId/adapterRunId are
|
|
151
|
+
// semantically absent pre-lease, see artificer-run-correlation.ts) + stable
|
|
152
|
+
// reasonCode + bounded references, never raw trajectories. reasonCode is
|
|
153
|
+
// the FR-04 code where one exists, otherwise the gate status itself
|
|
154
|
+
// ('ready'; 'not_applicable' cannot occur for this hard-coded channel gate
|
|
155
|
+
// and throws below).
|
|
156
|
+
eventEmitter.emitTelemetry({
|
|
157
|
+
eventType: 'artificer_evidence_readiness_checked',
|
|
158
|
+
traceId: taskId,
|
|
159
|
+
timestamp: new Date().toISOString(),
|
|
160
|
+
sessionId: owner,
|
|
161
|
+
agentId: 'artificer',
|
|
162
|
+
payload: {
|
|
163
|
+
...buildArtificerRunCorrelation({
|
|
164
|
+
taskId,
|
|
165
|
+
attemptNumber: piTask.attemptCount,
|
|
166
|
+
executionMode: 'preflight',
|
|
167
|
+
reasonCode: readiness.status === 'owner_evidence_required' || readiness.status === 'invalid_evidence'
|
|
168
|
+
? readiness.reasonCode
|
|
169
|
+
: readiness.status,
|
|
170
|
+
workspaceDir,
|
|
171
|
+
evidenceDigest: readiness.status === 'ready' ? readiness.evidenceHash : undefined,
|
|
172
|
+
}),
|
|
173
|
+
channel: 'code_tool_hook',
|
|
174
|
+
gateStatus: readiness.status,
|
|
175
|
+
...(readiness.status === 'owner_evidence_required' ? { missingFields: [...readiness.missingFields] } : {}),
|
|
176
|
+
...(readiness.status === 'invalid_evidence' ? { detail: boundedDetail(readiness.detail) } : {}),
|
|
177
|
+
...(readiness.status === 'ready' ? { evidenceHash: readiness.evidenceHash, sourcePainId: readiness.sourcePainId } : {}),
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
if (readiness.status === 'ready') {
|
|
181
|
+
return {
|
|
182
|
+
decision: 'ready',
|
|
183
|
+
pack: readiness.pack,
|
|
184
|
+
evidenceHash: readiness.evidenceHash,
|
|
185
|
+
sourcePainId: readiness.sourcePainId,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
if (readiness.status === 'not_applicable') {
|
|
189
|
+
// Unreachable by construction (channelRequiresOwnerEvidence is hard-coded
|
|
190
|
+
// true) — fail loud rather than silently proceeding evidence-less.
|
|
191
|
+
throw new PDRuntimeError('input_invalid', 'evidence preflight returned not_applicable for a code_tool_hook task — channel gate caller bug');
|
|
192
|
+
}
|
|
193
|
+
if (readiness.status === 'evidence_source_error') {
|
|
194
|
+
// PRI-980 review P2-1 — SPEC §6.2 case 3: a storage/I-O failure of the
|
|
195
|
+
// evidence source is preserved AS a storage fault. Same family as the
|
|
196
|
+
// absent port: the task stays wake-eligible (pending/retry_wait — the
|
|
197
|
+
// next cycle retries the assembly at zero model cost), NO NHR write, NO
|
|
198
|
+
// owner-fault reasonCode ever reaches the task. rc-9: the degradation is
|
|
199
|
+
// observable through the registered crash-durable blocked event carrying
|
|
200
|
+
// the storage reasonCode (never an FR-04 code) + nextAction; a concurrent
|
|
201
|
+
// write race is moot here because nothing is written.
|
|
202
|
+
eventEmitter.emitTelemetry({
|
|
203
|
+
eventType: 'artificer_blocked_on_owner_evidence',
|
|
204
|
+
traceId: taskId,
|
|
205
|
+
timestamp: new Date().toISOString(),
|
|
206
|
+
sessionId: owner,
|
|
207
|
+
agentId: 'artificer',
|
|
208
|
+
payload: {
|
|
209
|
+
...buildArtificerRunCorrelation({
|
|
210
|
+
taskId,
|
|
211
|
+
attemptNumber: piTask.attemptCount,
|
|
212
|
+
executionMode: 'preflight',
|
|
213
|
+
reasonCode: 'evidence_source_error',
|
|
214
|
+
workspaceDir,
|
|
215
|
+
}),
|
|
216
|
+
nextAction: readiness.nextAction,
|
|
217
|
+
detail: boundedDetail(readiness.detail),
|
|
218
|
+
reviewPersisted: false,
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
return {
|
|
222
|
+
decision: 'evidence_source_error',
|
|
223
|
+
reason: 'evidence_source_error',
|
|
224
|
+
nextAction: readiness.nextAction,
|
|
225
|
+
detail: boundedDetail(readiness.detail),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
const blocked = readiness.status === 'owner_evidence_required'
|
|
229
|
+
? {
|
|
230
|
+
reasonCode: readiness.reasonCode,
|
|
231
|
+
nextAction: withNhrOutEdge(readiness.nextAction),
|
|
232
|
+
missingFields: readiness.missingFields,
|
|
233
|
+
}
|
|
234
|
+
: {
|
|
235
|
+
reasonCode: readiness.reasonCode,
|
|
236
|
+
nextAction: withNhrOutEdge(readiness.nextAction),
|
|
237
|
+
detail: boundedDetail(readiness.detail),
|
|
238
|
+
};
|
|
239
|
+
const reviewContext = {
|
|
240
|
+
reasonCode: blocked.reasonCode,
|
|
241
|
+
sourceRunId: ARTIFICER_EVIDENCE_NHR_SOURCE_RUN_ID,
|
|
242
|
+
revisionEpoch: piTask.revisionCount ?? 0,
|
|
243
|
+
detail: boundedDetail(JSON.stringify({
|
|
244
|
+
missingFields: blocked.missingFields,
|
|
245
|
+
...(blocked.detail !== undefined ? { detail: blocked.detail } : {}),
|
|
246
|
+
nextAction: blocked.nextAction,
|
|
247
|
+
})),
|
|
248
|
+
createdAt: new Date().toISOString(),
|
|
249
|
+
};
|
|
250
|
+
const reviewPersisted = await transitionToNeedsHumanReview(params, reviewContext);
|
|
251
|
+
// Owner-recovery evidence: must be durably observable even if the process
|
|
252
|
+
// dies right after the state transition. Carries the FR-08 correlation
|
|
253
|
+
// block (persistentRunId stays absent: the block happened pre-lease — no
|
|
254
|
+
// run row exists and none may be fabricated).
|
|
255
|
+
eventEmitter.emitTelemetry({
|
|
256
|
+
eventType: 'artificer_blocked_on_owner_evidence',
|
|
257
|
+
traceId: taskId,
|
|
258
|
+
timestamp: new Date().toISOString(),
|
|
259
|
+
sessionId: owner,
|
|
260
|
+
agentId: 'artificer',
|
|
261
|
+
payload: {
|
|
262
|
+
...buildArtificerRunCorrelation({
|
|
263
|
+
taskId,
|
|
264
|
+
attemptNumber: piTask.attemptCount,
|
|
265
|
+
executionMode: 'preflight',
|
|
266
|
+
reasonCode: blocked.reasonCode,
|
|
267
|
+
workspaceDir,
|
|
268
|
+
}),
|
|
269
|
+
nextAction: blocked.nextAction,
|
|
270
|
+
...(blocked.missingFields !== undefined ? { missingFields: [...blocked.missingFields] } : {}),
|
|
271
|
+
...(blocked.detail !== undefined ? { detail: blocked.detail } : {}),
|
|
272
|
+
reviewPersisted,
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
return {
|
|
276
|
+
decision: 'blocked',
|
|
277
|
+
reasonCode: blocked.reasonCode,
|
|
278
|
+
nextAction: blocked.nextAction,
|
|
279
|
+
...(blocked.missingFields !== undefined ? { missingFields: blocked.missingFields } : {}),
|
|
280
|
+
...(blocked.detail !== undefined ? { detail: blocked.detail } : {}),
|
|
281
|
+
reviewPersisted,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
//# sourceMappingURL=consumer-evidence-preflight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumer-evidence-preflight.js","sourceRoot":"","sources":["../../../src/runtime-v2/internalization/consumer-evidence-preflight.ts"],"names":[],"mappings":"AAkDA,OAAO,EACL,uBAAuB,GAGxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAKxD,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAGnI;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,+BAA+B,CACnD,MAAc,EACd,OAAuD;IAEvD,MAAM,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC;IACzB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC;QAC5C,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;QAC3B,IAAI,EAAE,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,SAAS;QAC/C,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACb,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,EAAE,CAAC,CAAC;QAC/B,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QAC/B,MAAM,YAAY,GAAG,qBAAqB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAChE,IAAI,YAAY,KAAK,IAAI;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|
|
1
|
+
import { type BehaviorExamplePack } from './behavior-example-pack.js';
|
|
2
|
+
/**
|
|
3
|
+
* Owner-labelled evidence selection (FR-03 contract fields). Provided by an
|
|
4
|
+
* authorized Owner operation — never fabricated by an internal agent.
|
|
5
|
+
* Shape mirrors the host-side `BehaviorExamplePackAssemblerInput` minus
|
|
6
|
+
* I/O-only fields, so an assembler can be driven straight from a selection.
|
|
7
|
+
*/
|
|
8
|
+
export interface OwnerEvidenceSelection {
|
|
9
|
+
/** Canonical pain ID the evidence belongs to (pain lineage root). */
|
|
10
|
+
readonly sourcePainId: string;
|
|
11
|
+
/** Owner-selected tool call demonstrating the behaviour to block. */
|
|
12
|
+
readonly sourceNegativeToolCallId: number;
|
|
13
|
+
/** Owner-selected tool calls demonstrating the behaviour to allow (1..3, unique). */
|
|
14
|
+
readonly positiveToolCallIds: readonly number[];
|
|
15
|
+
/** Owner's natural-language desired outcome — non-empty. */
|
|
16
|
+
readonly ownerDesiredOutcome: string;
|
|
17
|
+
/**
|
|
18
|
+
* B1 (PRI-983, SPEC FR-03): attach revision — 1 on first attach, +1 on every
|
|
19
|
+
* re-attach. ABSENT = legacy record written before revision tracking.
|
|
20
|
+
*/
|
|
21
|
+
readonly revision?: number;
|
|
22
|
+
/**
|
|
23
|
+
* B1 (FR-03): `sha256:<hex>` content digest over the successfully assembled
|
|
24
|
+
* pack (canonical JSON, same convention as the readiness verdict hash).
|
|
25
|
+
* Resume re-assembles and refuses on mismatch — a silently stale reference
|
|
26
|
+
* can never re-enter the model (FR-03 "拒绝无声复用旧引用").
|
|
27
|
+
* ABSENT = legacy record; resume refuses un-digested selections.
|
|
28
|
+
*/
|
|
29
|
+
readonly contentDigest?: string;
|
|
30
|
+
/**
|
|
31
|
+
* B1 (FR-03): authorized Owner operation label that wrote this selection
|
|
32
|
+
* (e.g. `cli:attach` / `cli:attach:<decidedBy>`). Evidence is only written
|
|
33
|
+
* by an explicit Owner operation — never by an internal agent (C-04).
|
|
34
|
+
*/
|
|
35
|
+
readonly ownerOperation?: string;
|
|
36
|
+
/** B1 (FR-03): ISO timestamp of the attach. ABSENT = legacy. */
|
|
37
|
+
readonly attachedAt?: string;
|
|
38
|
+
}
|
|
39
|
+
/** Stable reason codes (SPEC-PD-IAER-001 FR-04). Do not rename. */
|
|
40
|
+
export type OwnerEvidenceReasonCode = 'owner_behavior_examples_required' | 'owner_behavior_examples_invalid' | 'owner_behavior_examples_stale' | 'owner_behavior_examples_scope_mismatch';
|
|
41
|
+
/** Reserved error name for Owner evidence scope failures. Do not rename. */
|
|
42
|
+
export declare const OWNER_EVIDENCE_SCOPE_ERROR_NAME = "OwnerEvidenceScopeError";
|
|
43
|
+
/**
|
|
44
|
+
* Structured kinds of a typed evidence-assembly failure:
|
|
45
|
+
* - `pain_not_found` / `tool_call_not_found`: the trajectory the selection
|
|
46
|
+
* references does not resolve (cleaned or wrong workspace) → the stable
|
|
47
|
+
* STALE code (FR-03: a cleaned trajectory must never be silently reused);
|
|
48
|
+
* - `session_mismatch`: a selected row belongs to another session → the
|
|
49
|
+
* stable SCOPE code (SPEC FR-04 cross pain/session);
|
|
50
|
+
* - `evidence_source_error`: the evidence SOURCE itself failed (trajectory
|
|
51
|
+
* store I/O: unavailable / locked / read error) → the §6.2 storage-fault
|
|
52
|
+
* family, deliberately NOT an FR-04 Owner-fault code. Owner-reviewer
|
|
53
|
+
* vocabulary: a PRI-980 review fix separates "Owner labelled bad
|
|
54
|
+
* evidence" from "the evidence source could not be read" (§6.2: 保留明确
|
|
55
|
+
* 的存储故障,不误判为 Owner 尚未标注).
|
|
56
|
+
*
|
|
57
|
+
* (The type name predates the storage kind — it is the reserved typed-error
|
|
58
|
+
* family's stable name; do not rename, the plugin bundle relies on the
|
|
59
|
+
* structural `name` + kind contract.)
|
|
60
|
+
*/
|
|
61
|
+
export type OwnerEvidenceScopeMismatchKind = 'pain_not_found' | 'tool_call_not_found' | 'session_mismatch' | 'evidence_source_error';
|
|
62
|
+
/** Build the typed error the plugin assembler throws for scope failures. */
|
|
63
|
+
export declare function createOwnerEvidenceScopeError(kind: OwnerEvidenceScopeMismatchKind, message: string): Error;
|
|
64
|
+
export type OwnerEvidenceScopeError = Error & {
|
|
65
|
+
readonly ownerEvidenceScopeKind: OwnerEvidenceScopeMismatchKind;
|
|
66
|
+
};
|
|
67
|
+
/** Structural guard (cross-bundle safe — see module comment above). */
|
|
68
|
+
export declare function isOwnerEvidenceScopeError(value: unknown): value is OwnerEvidenceScopeError;
|
|
69
|
+
/** Pre-computed assembly outcome, for callers that already ran the assembler. */
|
|
70
|
+
export type EvidenceAssemblyOutcome = {
|
|
71
|
+
readonly ok: true;
|
|
72
|
+
readonly pack: BehaviorExamplePack;
|
|
73
|
+
} | {
|
|
74
|
+
readonly ok: false;
|
|
75
|
+
readonly error: unknown;
|
|
76
|
+
};
|
|
77
|
+
export interface EvidenceReadinessInput {
|
|
78
|
+
/**
|
|
79
|
+
* Caller-declared target-channel applicability (the channel authority lives
|
|
80
|
+
* in the A2 wiring, not here). `false` → `not_applicable`. Anything other
|
|
81
|
+
* than an explicit `false` fails closed toward REQUIRING evidence.
|
|
82
|
+
*/
|
|
83
|
+
readonly channelRequiresOwnerEvidence: boolean;
|
|
84
|
+
/** Owner selection; `undefined`/`null` = the Owner has not provided evidence. */
|
|
85
|
+
readonly ownerSelection?: OwnerEvidenceSelection | null;
|
|
86
|
+
/**
|
|
87
|
+
* Injected assembly step. Throws on failure (assembler ERR-069 fail-loud
|
|
88
|
+
* convention); the gate captures the throw and classifies it: typed scope
|
|
89
|
+
* kinds → the stable FR-04 codes, the typed `evidence_source_error` kind →
|
|
90
|
+
* the §6.2 storage-fault verdict, everything else → `invalid_evidence` with
|
|
91
|
+
* the bounded error detail — exception details are never swallowed.
|
|
92
|
+
* Takes precedence over `assemblyResult` when both are provided.
|
|
93
|
+
*/
|
|
94
|
+
readonly assemblePack?: () => BehaviorExamplePack;
|
|
95
|
+
/** Pre-assembled result, alternative to `assemblePack`. */
|
|
96
|
+
readonly assemblyResult?: EvidenceAssemblyOutcome;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Evidence readiness verdict (FR-01 discriminant union). Field naming follows
|
|
100
|
+
* the house style for structured refusals (reasonCode / nextAction / detail).
|
|
101
|
+
*/
|
|
102
|
+
export type EvidenceReadiness = {
|
|
103
|
+
readonly status: 'ready';
|
|
104
|
+
readonly pack: BehaviorExamplePack;
|
|
105
|
+
/** `sha256:<hex>` content digest of the pack (intent-hash.ts convention). */
|
|
106
|
+
readonly evidenceHash: string;
|
|
107
|
+
readonly sourcePainId: string;
|
|
108
|
+
} | {
|
|
109
|
+
readonly status: 'owner_evidence_required';
|
|
110
|
+
readonly reasonCode: Extract<OwnerEvidenceReasonCode, 'owner_behavior_examples_required'>;
|
|
111
|
+
readonly missingFields: readonly string[];
|
|
112
|
+
readonly nextAction: string;
|
|
113
|
+
} | {
|
|
114
|
+
readonly status: 'invalid_evidence';
|
|
115
|
+
readonly reasonCode: OwnerEvidenceReasonCode;
|
|
116
|
+
/** Bounded structured reason (rc-8) — why the evidence was rejected. */
|
|
117
|
+
readonly detail: string;
|
|
118
|
+
readonly nextAction: string;
|
|
119
|
+
} | {
|
|
120
|
+
/**
|
|
121
|
+
* The evidence SOURCE failed (trajectory store I/O — PRI-980 review
|
|
122
|
+
* P2-1, SPEC §6.2 case 3). Deliberately NOT `invalid_evidence`: a
|
|
123
|
+
* storage fault must never read as "Owner labelled bad evidence".
|
|
124
|
+
* `reason` (not `reasonCode`) marks it as outside the FR-04
|
|
125
|
+
* Owner-fault vocabulary — callers must keep the task wake-eligible /
|
|
126
|
+
* untouched and degrade observably, never write an owner-fault NHR
|
|
127
|
+
* reason.
|
|
128
|
+
*/
|
|
129
|
+
readonly status: 'evidence_source_error';
|
|
130
|
+
readonly reason: 'evidence_source_error';
|
|
131
|
+
/** Bounded structured reason (rc-8) — the underlying failure message. */
|
|
132
|
+
readonly detail: string;
|
|
133
|
+
readonly nextAction: string;
|
|
134
|
+
} | {
|
|
135
|
+
readonly status: 'not_applicable';
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Structural validation of the Owner selection (rc-1..rc-5). Returns the list
|
|
139
|
+
* of field-level problems; an empty list means the selection is usable.
|
|
140
|
+
* Semantics deliberately mirror `validateOwnerSelection` in the plugin
|
|
141
|
+
* assembler (positive safe integers, 1..3 unique positives, non-empty text):
|
|
142
|
+
* a present-but-unusable selection is REJECTED, never repaired here.
|
|
143
|
+
*
|
|
144
|
+
* PRI-982: exported as the SINGLE shape authority for the persisted
|
|
145
|
+
* `pi_metadata.ownerEvidenceSelection` field — pitask-metadata parse reuses
|
|
146
|
+
* this validator so the persistence layer and the readiness gate can never
|
|
147
|
+
* diverge on what a usable selection is. Takes `unknown` (rc-1: the metadata
|
|
148
|
+
* parse reads it from a DB row) and rejects non-objects itself.
|
|
149
|
+
*/
|
|
150
|
+
export declare function validateOwnerEvidenceSelectionShape(selection: unknown): string[];
|
|
151
|
+
/** `sha256:<hex>` content digest over the pack's canonical JSON (rc-6: one hash convention). */
|
|
152
|
+
export declare function computeBehaviorExamplePackDigest(pack: BehaviorExamplePack): string;
|
|
153
|
+
/**
|
|
154
|
+
* Pure evidence readiness judgment (FR-01). No I/O, no state — the caller
|
|
155
|
+
* injects the assembly step and declares channel applicability.
|
|
156
|
+
*
|
|
157
|
+
* Decision order:
|
|
158
|
+
* 1. channel does not require evidence → `not_applicable`;
|
|
159
|
+
* 2. no Owner selection → `owner_evidence_required` + missingFields;
|
|
160
|
+
* 3. selection present but structurally unusable → `invalid_evidence`
|
|
161
|
+
* (assembler validateOwnerSelection semantics);
|
|
162
|
+
* 4. assembly throws / pre-assembled failure → `invalid_evidence` with the
|
|
163
|
+
* bounded error detail (never swallowed);
|
|
164
|
+
* 5. assembled pack fails `validateBehaviorExamplePack` → `invalid_evidence`
|
|
165
|
+
* (single validator authority);
|
|
166
|
+
* 6. otherwise → `ready` with the pack, its `sha256:<hex>` evidence hash,
|
|
167
|
+
* and the source pain ID.
|
|
168
|
+
*/
|
|
169
|
+
export declare function assessEvidenceReadiness(input: EvidenceReadinessInput): EvidenceReadiness;
|
|
170
|
+
//# sourceMappingURL=evidence-readiness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evidence-readiness.d.ts","sourceRoot":"","sources":["../../../src/runtime-v2/internalization/evidence-readiness.ts"],"names":[],"mappings":"AA+CA,OAAO,EAA+B,KAAK,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAInG;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,qEAAqE;IACrE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,qEAAqE;IACrE,QAAQ,CAAC,wBAAwB,EAAE,MAAM,CAAC;IAC1C,qFAAqF;IACrF,QAAQ,CAAC,mBAAmB,EAAE,SAAS,MAAM,EAAE,CAAC;IAChD,4DAA4D;IAC5D,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;;OAMG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,gEAAgE;IAChE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,mEAAmE;AACnE,MAAM,MAAM,uBAAuB,GAC/B,kCAAkC,GAClC,iCAAiC,GACjC,+BAA+B,GAC/B,wCAAwC,CAAC;AAkB7C,4EAA4E;AAC5E,eAAO,MAAM,+BAA+B,4BAA4B,CAAC;AAEzE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,8BAA8B,GACtC,gBAAgB,GAChB,qBAAqB,GACrB,kBAAkB,GAClB,uBAAuB,CAAC;AAkB5B,4EAA4E;AAC5E,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,8BAA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