create-principles-disciple 1.155.3 → 1.156.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_release/product-identity.json +2 -2
- package/codex-adapter/dist/ingestion/pain-receipt-fallback.d.ts +28 -1
- package/codex-adapter/dist/ingestion/pain-receipt-fallback.js +55 -18
- package/codex-adapter/dist/worker/workspace-worker.js +122 -67
- package/codex-adapter/package.json +1 -1
- package/console/dist/server/index.d.ts +11 -1
- package/console/dist/server/index.js +84 -19
- package/console/dist/server/release-handover.d.ts +256 -0
- package/console/dist/server/release-handover.js +402 -0
- package/console/dist/server/routes/onboarding.js +1 -0
- package/console/dist/server/routes/update-transaction.js +37 -3
- package/console/dist/server/routes/update.js +21 -1
- package/console/dist/server/successor.d.ts +46 -0
- package/console/dist/server/successor.js +128 -0
- package/console/dist/web/assets/app.css +18 -0
- package/console/dist/web/assets/app.js +32 -31
- package/console/package.json +1 -1
- package/core/dist/runtime/candidate-intake-service.d.ts +1 -1
- package/core/dist/runtime/candidate-intake-service.d.ts.map +1 -1
- package/core/dist/runtime/candidate-intake-service.js +89 -12
- package/core/dist/runtime/candidate-intake-service.js.map +1 -1
- package/core/dist/runtime/context-payload.d.ts +11 -0
- package/core/dist/runtime/context-payload.d.ts.map +1 -1
- package/core/dist/runtime/context-payload.js +27 -0
- package/core/dist/runtime/context-payload.js.map +1 -1
- package/core/dist/runtime/diagnostician-candidate.d.ts.map +1 -1
- package/core/dist/runtime/diagnostician-candidate.js +6 -4
- package/core/dist/runtime/diagnostician-candidate.js.map +1 -1
- package/core/dist/runtime/host-submission-context.d.ts +13 -6
- package/core/dist/runtime/host-submission-context.d.ts.map +1 -1
- package/core/dist/runtime/host-submission-context.js +77 -8
- package/core/dist/runtime/host-submission-context.js.map +1 -1
- package/core/dist/runtime/index.d.ts +4 -2
- package/core/dist/runtime/index.d.ts.map +1 -1
- package/core/dist/runtime/index.js +10 -1
- package/core/dist/runtime/index.js.map +1 -1
- package/core/dist/runtime/intent/intent-doc.d.ts +30 -0
- package/core/dist/runtime/intent/intent-doc.d.ts.map +1 -1
- package/core/dist/runtime/intent/intent-doc.js +47 -0
- package/core/dist/runtime/intent/intent-doc.js.map +1 -1
- package/core/dist/runtime/intent/intent-snapshot.d.ts +12 -0
- package/core/dist/runtime/intent/intent-snapshot.d.ts.map +1 -1
- package/core/dist/runtime/intent/intent-snapshot.js +20 -0
- package/core/dist/runtime/intent/intent-snapshot.js.map +1 -1
- package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts +18 -0
- package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/diag-rootcause-runner.js +53 -15
- package/core/dist/runtime/internalization/diag-rootcause-runner.js.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.js +4 -0
- package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
- package/core/dist/runtime/pain-admission-disposition.d.ts +8 -4
- package/core/dist/runtime/pain-admission-disposition.d.ts.map +1 -1
- package/core/dist/runtime/pain-admission-disposition.js +8 -4
- package/core/dist/runtime/pain-admission-disposition.js.map +1 -1
- package/core/dist/runtime/pain-ingress.d.ts +8 -0
- package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
- package/core/dist/runtime/pain-ingress.js +8 -1
- package/core/dist/runtime/pain-ingress.js.map +1 -1
- package/core/dist/runtime/pain-recall-read-model.d.ts +72 -0
- package/core/dist/runtime/pain-recall-read-model.d.ts.map +1 -1
- package/core/dist/runtime/pain-recall-read-model.js +46 -21
- package/core/dist/runtime/pain-recall-read-model.js.map +1 -1
- package/core/dist/runtime/pain-receipt-recovery.d.ts +39 -8
- package/core/dist/runtime/pain-receipt-recovery.d.ts.map +1 -1
- package/core/dist/runtime/pain-receipt-recovery.js +290 -36
- package/core/dist/runtime/pain-receipt-recovery.js.map +1 -1
- package/core/dist/runtime/pain-signal-bridge.d.ts +38 -23
- package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-bridge.js +533 -182
- package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.d.ts +68 -13
- package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.js +396 -167
- package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
- package/core/dist/runtime/pain-submit-capability.d.ts +14 -3
- package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -1
- package/core/dist/runtime/pain-submit-capability.js +21 -9
- package/core/dist/runtime/pain-submit-capability.js.map +1 -1
- package/core/dist/runtime/pain-target-evidence-reconcile.d.ts +115 -6
- package/core/dist/runtime/pain-target-evidence-reconcile.d.ts.map +1 -1
- package/core/dist/runtime/pain-target-evidence-reconcile.js +446 -49
- package/core/dist/runtime/pain-target-evidence-reconcile.js.map +1 -1
- package/core/dist/runtime/pain-to-principle-service.d.ts +28 -10
- package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
- package/core/dist/runtime/pain-to-principle-service.js +63 -52
- package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
- package/core/dist/runtime/store/candidate/admission-document.d.ts +43 -0
- package/core/dist/runtime/store/candidate/admission-document.d.ts.map +1 -1
- package/core/dist/runtime/store/candidate/admission-document.js +130 -0
- package/core/dist/runtime/store/candidate/admission-document.js.map +1 -1
- package/core/dist/runtime/store/candidate/candidate-store.d.ts +3 -1
- package/core/dist/runtime/store/candidate/candidate-store.d.ts.map +1 -1
- package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts +2 -1
- package/core/dist/runtime/store/candidate/memory-candidate-store.d.ts.map +1 -1
- package/core/dist/runtime/store/candidate/memory-candidate-store.js +27 -1
- package/core/dist/runtime/store/candidate/memory-candidate-store.js.map +1 -1
- package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts +2 -1
- package/core/dist/runtime/store/candidate/sqlite-candidate-store.d.ts.map +1 -1
- package/core/dist/runtime/store/candidate/sqlite-candidate-store.js +59 -2
- package/core/dist/runtime/store/candidate/sqlite-candidate-store.js.map +1 -1
- package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
- package/core/dist/runtime/store/context/sqlite-context-assembler.js +18 -3
- package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
- package/core/dist/runtime/store/runtime-state-manager.d.ts +4 -1
- package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
- package/core/dist/runtime/store/runtime-state-manager.js +22 -0
- package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
- package/core/dist/runtime/store/task/memory-task-store.d.ts.map +1 -1
- package/core/dist/runtime/store/task/memory-task-store.js +20 -0
- package/core/dist/runtime/store/task/memory-task-store.js.map +1 -1
- package/core/dist/runtime/store/task/sqlite-task-store.d.ts.map +1 -1
- package/core/dist/runtime/store/task/sqlite-task-store.js +9 -0
- package/core/dist/runtime/store/task/sqlite-task-store.js.map +1 -1
- package/core/dist/runtime/store/task/task-store.d.ts +10 -0
- package/core/dist/runtime/store/task/task-store.d.ts.map +1 -1
- package/core/dist/telemetry-event.d.ts +2 -2
- package/core/dist/telemetry-event.d.ts.map +1 -1
- package/core/dist/telemetry-event.js +5 -0
- package/core/dist/telemetry-event.js.map +1 -1
- package/core/package.json +1 -1
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +72 -0
- package/dist/i18n.js.map +1 -1
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +145 -35
- package/dist/index.js.map +1 -1
- package/dist/installer.d.ts +149 -9
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +542 -31
- package/dist/installer.js.map +1 -1
- package/dist/installers/codex-host-installer.js +1 -1
- package/dist/installers/codex-host-installer.js.map +1 -1
- package/dist/installers/index.d.ts +10 -0
- package/dist/installers/index.d.ts.map +1 -1
- package/dist/installers/index.js +4 -0
- 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/prompts.d.ts +36 -12
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +102 -30
- package/dist/prompts.js.map +1 -1
- package/dist/service-host-bridge.d.ts +71 -12
- package/dist/service-host-bridge.d.ts.map +1 -1
- package/dist/service-host-bridge.js +228 -48
- package/dist/service-host-bridge.js.map +1 -1
- package/dist/service-host-provisioning.d.ts +102 -0
- package/dist/service-host-provisioning.d.ts.map +1 -0
- package/dist/service-host-provisioning.js +595 -0
- package/dist/service-host-provisioning.js.map +1 -0
- package/dist/uninstaller.js +1 -1
- package/dist/uninstaller.js.map +1 -1
- package/dist/update/apply-payload.d.ts +9 -0
- package/dist/update/apply-payload.d.ts.map +1 -1
- package/dist/update/apply-payload.js +44 -2
- package/dist/update/apply-payload.js.map +1 -1
- package/dist/update/console-surface.d.ts +2 -1
- package/dist/update/console-surface.d.ts.map +1 -1
- package/dist/update/console-surface.js +6 -1
- package/dist/update/console-surface.js.map +1 -1
- package/dist/update/install-layout.d.ts +12 -0
- package/dist/update/install-layout.d.ts.map +1 -1
- package/dist/update/install-layout.js +49 -7
- package/dist/update/install-layout.js.map +1 -1
- package/dist/update/release-manager-authority.d.ts +16 -0
- package/dist/update/release-manager-authority.d.ts.map +1 -1
- package/dist/update/release-manager-authority.js +45 -3
- package/dist/update/release-manager-authority.js.map +1 -1
- package/dist/update/release-manager.d.ts +8 -3
- package/dist/update/release-manager.d.ts.map +1 -1
- package/dist/update/release-manager.js +29 -1
- package/dist/update/release-manager.js.map +1 -1
- package/dist/update/transaction-progress.d.ts +63 -0
- package/dist/update/transaction-progress.d.ts.map +1 -0
- package/dist/update/transaction-progress.js +207 -0
- package/dist/update/transaction-progress.js.map +1 -0
- package/dist/utils/env.d.ts +16 -1
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +55 -43
- package/dist/utils/env.js.map +1 -1
- package/host-runtime/dist/diagnostician-auto-run.js +46 -34
- package/host-runtime/dist/governance-observation-store.d.ts +38 -0
- package/host-runtime/dist/governance-observation-store.js +41 -0
- package/host-runtime/dist/governance-trajectory-turn-reader.js +26 -33
- package/host-runtime/dist/index.d.ts +1 -0
- package/host-runtime/dist/index.js +4 -0
- package/host-runtime/dist/intent-doc-reader.js +1 -1
- package/host-runtime/dist/workspace-pipeline-host-deps.d.ts +65 -0
- package/host-runtime/dist/workspace-pipeline-host-deps.js +94 -0
- package/host-runtime/dist/workspace-telemetry-emitter.js +14 -0
- package/host-runtime/package.json +1 -1
- package/install-layout/dist/background-execution-transition.d.ts +11 -1
- package/install-layout/dist/background-execution-transition.js +45 -1
- package/install-layout/dist/index.d.ts +4 -3
- package/install-layout/dist/index.js +11 -4
- package/install-layout/dist/openclaw-config-path.d.ts +9 -0
- package/install-layout/dist/openclaw-config-path.js +64 -0
- package/install-layout/dist/pd-home.d.ts +12 -0
- package/install-layout/dist/pd-home.js +6 -1
- package/install-layout/package.json +1 -1
- package/package.json +7 -7
- package/pd-cli/dist/commands/candidate.d.ts +15 -0
- package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
- package/pd-cli/dist/commands/candidate.js +449 -93
- package/pd-cli/dist/commands/candidate.js.map +1 -1
- package/pd-cli/dist/commands/codex-worker.js +2 -2
- package/pd-cli/dist/commands/codex-worker.js.map +1 -1
- package/pd-cli/dist/commands/console.d.ts.map +1 -1
- package/pd-cli/dist/commands/console.js +10 -0
- package/pd-cli/dist/commands/console.js.map +1 -1
- package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
- package/pd-cli/dist/commands/diagnose.js +301 -233
- package/pd-cli/dist/commands/diagnose.js.map +1 -1
- package/pd-cli/dist/commands/intake-outcome-guidance.d.ts +57 -0
- package/pd-cli/dist/commands/intake-outcome-guidance.d.ts.map +1 -0
- package/pd-cli/dist/commands/intake-outcome-guidance.js +206 -0
- package/pd-cli/dist/commands/intake-outcome-guidance.js.map +1 -0
- package/pd-cli/dist/commands/mcp-probe.d.ts.map +1 -1
- package/pd-cli/dist/commands/mcp-probe.js +1 -0
- package/pd-cli/dist/commands/mcp-probe.js.map +1 -1
- package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-record.js +22 -16
- package/pd-cli/dist/commands/pain-record.js.map +1 -1
- package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-retry.js +139 -85
- package/pd-cli/dist/commands/pain-retry.js.map +1 -1
- package/pd-cli/dist/commands/runtime-uat.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-uat.js +1 -0
- package/pd-cli/dist/commands/runtime-uat.js.map +1 -1
- package/pd-cli/dist/commands/service-lifecycle.js +1 -1
- package/pd-cli/dist/commands/service-lifecycle.js.map +1 -1
- package/pd-cli/dist/commands/service-run-once.d.ts +1 -1
- package/pd-cli/dist/commands/service-run-once.d.ts.map +1 -1
- package/pd-cli/dist/commands/service-run-once.js +9 -5
- package/pd-cli/dist/commands/service-run-once.js.map +1 -1
- package/pd-cli/dist/commands/workbuddy-worker.js +2 -2
- package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -1
- package/pd-cli/dist/program.d.ts.map +1 -1
- package/pd-cli/dist/program.js +14 -3
- package/pd-cli/dist/program.js.map +1 -1
- package/pd-cli/dist/services/admission-write-gate.d.ts +4 -0
- package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
- package/pd-cli/dist/services/admission-write-gate.js +50 -48
- package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
- package/pd-cli/dist/services/config-doctor.d.ts.map +1 -1
- package/pd-cli/dist/services/config-doctor.js +7 -4
- package/pd-cli/dist/services/config-doctor.js.map +1 -1
- package/pd-cli/dist/services/console-launcher.js +3 -3
- package/pd-cli/dist/services/console-launcher.js.map +1 -1
- package/pd-cli/dist/services/service-host/managed-run.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/managed-run.js +25 -8
- package/pd-cli/dist/services/service-host/managed-run.js.map +1 -1
- package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts +12 -0
- package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/scheduler/service-status.js +16 -7
- package/pd-cli/dist/services/service-host/scheduler/service-status.js.map +1 -1
- package/pd-cli/dist/services/service-host/status/service-run-status.d.ts +7 -5
- package/pd-cli/dist/services/service-host/status/service-run-status.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/status/service-run-status.js +1 -1
- package/pd-cli/dist/services/service-host/status/service-run-status.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/pd-mcp-server/dist/server.d.ts +7 -0
- package/pd-mcp-server/dist/server.js +12 -1
- package/pd-mcp-server/dist/submit-assembly.js +63 -19
- 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 +539 -503
- package/plugin/dist/core/config-health.d.ts +6 -0
- package/plugin/dist/core/openclaw-config-loader.d.ts +14 -0
- package/plugin/dist/core/pain-service.d.ts +26 -0
- package/plugin/dist/hooks/openclaw-run-turn-correlation.d.ts +30 -0
- package/plugin/dist/hooks/openclaw-target-turn-capture.d.ts +13 -0
- package/plugin/dist/hooks/pain-receipt-fallback.d.ts +107 -0
- package/plugin/dist/openclaw-sdk.d.ts +15 -0
- package/plugin/dist/openclaw-worker.d.ts +3 -0
- package/plugin/dist/openclaw-worker.js +288 -287
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/release-manager/dist/i18n.js +72 -0
- package/release-manager/dist/installer.js +542 -31
- package/release-manager/dist/installers/codex-host-installer.js +1 -1
- package/release-manager/dist/installers/index.js +4 -0
- package/release-manager/dist/mvp-config.js +1 -1
- package/release-manager/dist/service-host-bridge.js +228 -48
- package/release-manager/dist/service-host-provisioning.js +595 -0
- package/release-manager/dist/update/apply-payload.js +44 -2
- package/release-manager/dist/update/console-surface.js +6 -1
- package/release-manager/dist/update/install-layout.js +49 -7
- package/release-manager/dist/update/release-manager-authority.js +45 -3
- package/release-manager/dist/update/release-manager.js +29 -1
- package/release-manager/dist/update/transaction-progress.js +207 -0
- package/release-manager/dist/utils/env.js +55 -43
- package/release-manager/package.json +5 -5
- package/workbuddy-adapter/dist/codec/input-decoder.d.ts +21 -0
- package/workbuddy-adapter/dist/codec/input-decoder.js +50 -1
- package/workbuddy-adapter/dist/ingestion/pain-receipt-fallback.d.ts +68 -0
- package/workbuddy-adapter/dist/ingestion/pain-receipt-fallback.js +226 -0
- package/workbuddy-adapter/dist/pd-hook.js +60 -0
- package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +3 -0
- package/workbuddy-adapter/dist/worker/workspace-worker.js +82 -47
- package/workbuddy-adapter/package.json +1 -1
- package/console/dist/server/utils/gateway.d.ts +0 -29
- package/console/dist/server/utils/gateway.js +0 -175
|
@@ -131,6 +131,40 @@ function resolveRedirectTarget(location, from) {
|
|
|
131
131
|
function isRedirectStatus(status) {
|
|
132
132
|
return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
|
|
133
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Reads a response body while counting it, so a download that takes minutes
|
|
136
|
+
* can be narrated instead of sitting on an unexplained wait. The bytes are
|
|
137
|
+
* still returned whole — verification below wants the complete asset — and a
|
|
138
|
+
* body the transport does not expose as a stream is read the plain way.
|
|
139
|
+
*/
|
|
140
|
+
async function readResponseBody(response, onBytes) {
|
|
141
|
+
const { body } = response;
|
|
142
|
+
if (!body || typeof body.getReader !== 'function') {
|
|
143
|
+
const whole = Buffer.from(await response.arrayBuffer());
|
|
144
|
+
onBytes(whole.length);
|
|
145
|
+
return whole;
|
|
146
|
+
}
|
|
147
|
+
const reader = body.getReader();
|
|
148
|
+
const chunks = [];
|
|
149
|
+
let received = 0;
|
|
150
|
+
try {
|
|
151
|
+
for (;;) {
|
|
152
|
+
const { done, value } = await reader.read();
|
|
153
|
+
if (done)
|
|
154
|
+
break;
|
|
155
|
+
// Copy: the stream may reuse its buffer for the next chunk, and these
|
|
156
|
+
// bytes are hashed and written to disk afterwards.
|
|
157
|
+
const chunk = Buffer.from(value);
|
|
158
|
+
chunks.push(chunk);
|
|
159
|
+
received += chunk.length;
|
|
160
|
+
onBytes(received);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
reader.releaseLock();
|
|
165
|
+
}
|
|
166
|
+
return Buffer.concat(chunks, received);
|
|
167
|
+
}
|
|
134
168
|
export async function downloadAndVerifyAssetFile(input) {
|
|
135
169
|
// PRI-927 (Owner decision): HTTPS-only, no warning mode and no insecure
|
|
136
170
|
// override. The signed sha256+size below is the trust anchor, so a plaintext
|
|
@@ -191,7 +225,7 @@ export async function downloadAndVerifyAssetFile(input) {
|
|
|
191
225
|
}
|
|
192
226
|
}
|
|
193
227
|
else {
|
|
194
|
-
bytes =
|
|
228
|
+
bytes = await readResponseBody(response, (receivedBytes) => input.onProgress?.(receivedBytes));
|
|
195
229
|
}
|
|
196
230
|
break;
|
|
197
231
|
}
|
|
@@ -263,7 +297,7 @@ export async function downloadAndVerifyAssetFile(input) {
|
|
|
263
297
|
* Zero deployment writes happen before every identity check has passed.
|
|
264
298
|
*/
|
|
265
299
|
export async function downloadReleaseAsset(options) {
|
|
266
|
-
const { paths, metadataBaseUrl, fetcher, assetFetcher, releaseMetadata, channel, transactionId } = options;
|
|
300
|
+
const { paths, metadataBaseUrl, fetcher, assetFetcher, releaseMetadata, channel, transactionId, onProgress } = options;
|
|
267
301
|
const asset = selectReleaseAsset(releaseMetadata);
|
|
268
302
|
// PRI-854 (option A): the signed metadata carries the asset's delivery URL —
|
|
269
303
|
// fetch it directly and enforce the signed sha256+size. The digest check is
|
|
@@ -278,6 +312,9 @@ export async function downloadReleaseAsset(options) {
|
|
|
278
312
|
expectedSizeBytes: asset.archiveSizeBytes,
|
|
279
313
|
releaseId: releaseMetadata.releaseId,
|
|
280
314
|
fetcher: assetFetcher,
|
|
315
|
+
onProgress: onProgress === undefined
|
|
316
|
+
? undefined
|
|
317
|
+
: (receivedBytes) => onProgress(receivedBytes, asset.archiveSizeBytes),
|
|
281
318
|
});
|
|
282
319
|
const syntheticTarget = {
|
|
283
320
|
artifactSha256: asset.archiveSha256,
|
|
@@ -358,6 +395,9 @@ function extractReleaseAssetArchive(transactionDir, payloadDir) {
|
|
|
358
395
|
execFileSync('tar', ['xzf', 'release-asset.tar.gz', '-C', 'payload'], {
|
|
359
396
|
cwd: transactionDir,
|
|
360
397
|
stdio: 'pipe',
|
|
398
|
+
// This runs inside the detached update executor, which has no console on
|
|
399
|
+
// Windows: without it tar opens a visible terminal window mid-update.
|
|
400
|
+
windowsHide: true,
|
|
361
401
|
});
|
|
362
402
|
if (!fs.existsSync(path.join(payloadDir, '_release', 'manifest.json'))) {
|
|
363
403
|
throw new Error('the artifact tarball does not contain a self-contained release asset at its root (missing _release/manifest.json)');
|
|
@@ -377,11 +417,13 @@ export async function extractAndVerifyReleaseAsset(options) {
|
|
|
377
417
|
const payloadDir = path.join(transactionDir, 'payload');
|
|
378
418
|
try {
|
|
379
419
|
fs.mkdirSync(payloadDir, { recursive: true });
|
|
420
|
+
options.onStep?.('Extracting the release asset…');
|
|
380
421
|
extractReleaseAssetArchive(transactionDir, payloadDir);
|
|
381
422
|
// Dynamic import: keeps installer.js (and its CLI dependency graph) out
|
|
382
423
|
// of the module graph until a real acquisition needs it — the governed
|
|
383
424
|
// check path never pays for it.
|
|
384
425
|
const { preflightSelfContainedReleaseAsset } = await import('../installer.js');
|
|
426
|
+
options.onStep?.('Verifying the release asset…');
|
|
385
427
|
await preflightSelfContainedReleaseAsset(payloadDir);
|
|
386
428
|
}
|
|
387
429
|
catch (error) {
|
|
@@ -12,8 +12,13 @@
|
|
|
12
12
|
* tests consume are re-exported here. Adding a symbol to this surface is a
|
|
13
13
|
* cross-package contract decision — check the consumers first.
|
|
14
14
|
*/
|
|
15
|
-
export { createReleaseManagerAuthority, mapReleaseManagerError, } from './release-manager-authority.js';
|
|
15
|
+
export { createReleaseManagerAuthority, createReleaseManagerAuthorityAsync, mapReleaseManagerError, } from './release-manager-authority.js';
|
|
16
16
|
export { readTransactionJournalForRecovery, recoverUnfinishedTransaction, isTerminalTransactionState, readActiveRecord, hasRecoveryResolution, RESTORE_INCONSISTENCY_MARKER, } from './transaction-journal.js';
|
|
17
17
|
export { resolvePdHomePaths, } from './install-layout.js';
|
|
18
18
|
export { isReleaseManagerTransactionId, ReleaseManagerError, } from './release-manager.js';
|
|
19
|
+
// Observational companion to the journal above: how far along the stage the
|
|
20
|
+
// journal last announced. Derived and best-effort — a deployed release-manager
|
|
21
|
+
// built before it existed simply has no such export, which the Console treats
|
|
22
|
+
// as "no progress known" (ERR-207: components are replaced one at a time).
|
|
23
|
+
export { readTransactionProgress, } from './transaction-progress.js';
|
|
19
24
|
//# sourceMappingURL=console-surface.js.map
|
|
@@ -58,18 +58,30 @@ export class InstallLayoutError extends Error {
|
|
|
58
58
|
this.field = field;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
function missingExecutorDirectory(directory) {
|
|
62
|
+
return new InstallLayoutError('bootstrap_executor', `executor directory is missing: ${directory}`);
|
|
63
|
+
}
|
|
64
|
+
/** Per-directory name order is part of the persisted digest format: both walkers sort with this. */
|
|
65
|
+
function compareEntryNames(a, b) {
|
|
66
|
+
return a.name.localeCompare(b.name);
|
|
67
|
+
}
|
|
68
|
+
/** One file's record in the digest — the single definition of the per-file format. */
|
|
69
|
+
function foldIntoDigest(hash, relative, contents) {
|
|
70
|
+
hash.update(`${relative}:`);
|
|
71
|
+
hash.update(contents);
|
|
72
|
+
hash.update('\n');
|
|
73
|
+
}
|
|
61
74
|
/**
|
|
62
75
|
* PRI-850: deterministic digest over every file of a directory tree (relative
|
|
63
76
|
* POSIX-style paths sorted, contents hashed). This is how a bootstrap
|
|
64
77
|
* registration is re-verified against the deployed executor bytes.
|
|
65
78
|
*/
|
|
66
79
|
export function digestDirectory(directory) {
|
|
67
|
-
if (!fs.existsSync(directory))
|
|
68
|
-
throw
|
|
69
|
-
}
|
|
80
|
+
if (!fs.existsSync(directory))
|
|
81
|
+
throw missingExecutorDirectory(directory);
|
|
70
82
|
const hash = crypto.createHash('sha256');
|
|
71
83
|
const walk = (current, prefix) => {
|
|
72
|
-
for (const entry of fs.readdirSync(current, { withFileTypes: true }).sort(
|
|
84
|
+
for (const entry of fs.readdirSync(current, { withFileTypes: true }).sort(compareEntryNames)) {
|
|
73
85
|
const relative = prefix === '' ? entry.name : `${prefix}/${entry.name}`;
|
|
74
86
|
if (entry.isDirectory()) {
|
|
75
87
|
walk(path.join(current, entry.name), relative);
|
|
@@ -77,14 +89,44 @@ export function digestDirectory(directory) {
|
|
|
77
89
|
}
|
|
78
90
|
if (!entry.isFile())
|
|
79
91
|
continue;
|
|
80
|
-
hash.
|
|
81
|
-
hash.update(fs.readFileSync(path.join(current, entry.name)));
|
|
82
|
-
hash.update('\n');
|
|
92
|
+
foldIntoDigest(hash, relative, fs.readFileSync(path.join(current, entry.name)));
|
|
83
93
|
}
|
|
84
94
|
};
|
|
85
95
|
walk(directory, '');
|
|
86
96
|
return hash.digest('hex');
|
|
87
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* `digestDirectory` without holding the event loop: every directory listing
|
|
100
|
+
* and file read is awaited, so a request-serving thread that verifies the
|
|
101
|
+
* registration keeps answering while the executor tree is read. Same tree,
|
|
102
|
+
* same order, same per-file record — the result IS the sync digest.
|
|
103
|
+
*
|
|
104
|
+
* The sync form is for batch callers (the installer). A caller that serves
|
|
105
|
+
* requests must use this one: measured 2026-11-23 on a real install (~17k
|
|
106
|
+
* executor files), the sync form held its calling thread for ~0.6-0.7 s per
|
|
107
|
+
* call, and nothing else ran on that thread meanwhile.
|
|
108
|
+
*/
|
|
109
|
+
export async function digestDirectoryAsync(directory) {
|
|
110
|
+
if (!fs.existsSync(directory))
|
|
111
|
+
throw missingExecutorDirectory(directory);
|
|
112
|
+
const hash = crypto.createHash('sha256');
|
|
113
|
+
const walk = async (current, prefix) => {
|
|
114
|
+
const entries = await fs.promises.readdir(current, { withFileTypes: true });
|
|
115
|
+
entries.sort(compareEntryNames);
|
|
116
|
+
for (const entry of entries) {
|
|
117
|
+
const relative = prefix === '' ? entry.name : `${prefix}/${entry.name}`;
|
|
118
|
+
if (entry.isDirectory()) {
|
|
119
|
+
await walk(path.join(current, entry.name), relative);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (!entry.isFile())
|
|
123
|
+
continue;
|
|
124
|
+
foldIntoDigest(hash, relative, await fs.promises.readFile(path.join(current, entry.name)));
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
await walk(directory, '');
|
|
128
|
+
return hash.digest('hex');
|
|
129
|
+
}
|
|
88
130
|
function readJsonFileIfExists(filePath, label) {
|
|
89
131
|
if (!fs.existsSync(filePath))
|
|
90
132
|
return undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** ReleaseManager readiness and failure mapping for the Console. No alternate updater exists. */
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
3
|
import { ReleaseManager, ReleaseManagerError, } from './release-manager.js';
|
|
4
|
-
import { InstallLayoutError, digestDirectory, readBootstrapManifest, readInstallConfig, resolvePdHomePaths } from './install-layout.js';
|
|
4
|
+
import { InstallLayoutError, digestDirectory, digestDirectoryAsync, readBootstrapManifest, readInstallConfig, resolvePdHomePaths } from './install-layout.js';
|
|
5
5
|
import { resolveReleaseMetadataSource } from './release-metadata-source.js';
|
|
6
6
|
/** The two Console update operations. */
|
|
7
7
|
export const RELEASE_MANAGER_AUTHORITY_KINDS = ['check', 'apply-full'];
|
|
@@ -21,7 +21,13 @@ function probeTransactionJournalDir(pdHome) {
|
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The readiness decision, shared by both factories below. `executorDigest`
|
|
26
|
+
* supplies the deployed executor tree's digest where the decision needs one
|
|
27
|
+
* (a dual-slot install with a registered digest); whatever it throws is the
|
|
28
|
+
* `bootstrap_identity_mismatch` verdict.
|
|
29
|
+
*/
|
|
30
|
+
function assessReadiness(options, executorDigest) {
|
|
25
31
|
const reasons = new Set();
|
|
26
32
|
// PRI-709 P0-1: resolve the metadata source BEFORE constructing the manager.
|
|
27
33
|
// `install_config` is the durable tier — an install that was installed with
|
|
@@ -92,7 +98,7 @@ export function createReleaseManagerAuthority(options) {
|
|
|
92
98
|
}
|
|
93
99
|
else {
|
|
94
100
|
try {
|
|
95
|
-
const actual =
|
|
101
|
+
const actual = executorDigest();
|
|
96
102
|
if (actual !== manifest.executorDigest) {
|
|
97
103
|
reasons.add('bootstrap_identity_mismatch');
|
|
98
104
|
}
|
|
@@ -119,6 +125,42 @@ export function createReleaseManagerAuthority(options) {
|
|
|
119
125
|
};
|
|
120
126
|
return { manager, installStatus, kinds, metadataSource };
|
|
121
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Synchronous assessment, for batch callers. It re-hashes the whole deployed
|
|
130
|
+
* executor tree on the calling thread: a caller that serves requests must use
|
|
131
|
+
* `createReleaseManagerAuthorityAsync`, or every other request waits for the
|
|
132
|
+
* length of that read.
|
|
133
|
+
*/
|
|
134
|
+
export function createReleaseManagerAuthority(options) {
|
|
135
|
+
return assessReadiness(options, () => digestDirectory(resolvePdHomePaths(options.pdHome).bootstrapExecutorDir));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The same assessment with the executor tree re-hashed without holding the
|
|
139
|
+
* event loop. The Console server builds the authority inside `/api/update/check`
|
|
140
|
+
* and `/api/update/apply-full`.
|
|
141
|
+
*
|
|
142
|
+
* The digest is read up front and handed to the decision as a value (or as the
|
|
143
|
+
* error it would have thrown at the same point), so both factories run ONE
|
|
144
|
+
* readiness rule.
|
|
145
|
+
*/
|
|
146
|
+
export async function createReleaseManagerAuthorityAsync(options) {
|
|
147
|
+
const executorDir = resolvePdHomePaths(options.pdHome).bootstrapExecutorDir;
|
|
148
|
+
let digest;
|
|
149
|
+
let readFailure;
|
|
150
|
+
try {
|
|
151
|
+
digest = await digestDirectoryAsync(executorDir);
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
readFailure = error instanceof Error ? error : new Error(String(error));
|
|
155
|
+
}
|
|
156
|
+
return assessReadiness(options, () => {
|
|
157
|
+
if (readFailure !== undefined)
|
|
158
|
+
throw readFailure;
|
|
159
|
+
if (digest === undefined)
|
|
160
|
+
throw new InstallLayoutError('bootstrap_executor', `executor directory is missing: ${executorDir}`);
|
|
161
|
+
return digest;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
122
164
|
/** Preserve explicit failure details; never dispatch another writer. */
|
|
123
165
|
export function mapReleaseManagerError(error) {
|
|
124
166
|
if (error instanceof ReleaseManagerError) {
|
|
@@ -18,6 +18,7 @@ import { evaluateReleaseAdvancement, } from './release-policy.js';
|
|
|
18
18
|
import { readBootstrapManifest, readInstallConfig, resolvePdHomePaths, } from './install-layout.js';
|
|
19
19
|
import { appendJournalTransition, readActiveRecord, TransactionJournalError, } from './transaction-journal.js';
|
|
20
20
|
import { downloadReleaseAsset, extractAndVerifyReleaseAsset, ApplyPayloadError } from './apply-payload.js';
|
|
21
|
+
import { createTransactionProgressReporter } from './transaction-progress.js';
|
|
21
22
|
import { compareProductVersions, parseProductVersion } from './product-identity.js';
|
|
22
23
|
import { installManifestHostsForPersist, parseInstallManifest } from '@principles/install-layout';
|
|
23
24
|
export class ReleaseManagerError extends Error {
|
|
@@ -165,6 +166,12 @@ function toReleaseManagerError(error) {
|
|
|
165
166
|
*
|
|
166
167
|
* A legacy install.json without the manifest fields keeps the historical
|
|
167
168
|
* default — there is no record to contradict it.
|
|
169
|
+
*
|
|
170
|
+
* PRI-1278 Phase 5: a VALID manifest with `hosts: []` is a Service-Host-only
|
|
171
|
+
* installation, not a legacy one. Falling back to OpenClaw there deployed an
|
|
172
|
+
* adapter the operator never selected (and rewrote `hosts`). The empty record
|
|
173
|
+
* is the recorded truth: resolve `none` and let the installer deploy no host
|
|
174
|
+
* installer at all.
|
|
168
175
|
*/
|
|
169
176
|
function resolveDeploymentHost(installConfigPath) {
|
|
170
177
|
let value;
|
|
@@ -178,6 +185,8 @@ function resolveDeploymentHost(installConfigPath) {
|
|
|
178
185
|
if (!parsed.manifest)
|
|
179
186
|
return 'openclaw';
|
|
180
187
|
const recorded = installManifestHostsForPersist(parsed.manifest);
|
|
188
|
+
if (recorded.length === 0)
|
|
189
|
+
return 'none';
|
|
181
190
|
if (recorded.includes('openclaw'))
|
|
182
191
|
return 'openclaw';
|
|
183
192
|
if (recorded.includes('workbuddy'))
|
|
@@ -436,8 +445,12 @@ export class ReleaseManager {
|
|
|
436
445
|
}
|
|
437
446
|
throw new ReleaseManagerError('journal_unavailable', `The transaction journal could not be written — refusing to update unjournaled (ADR-0024 D-2): ${error instanceof Error ? error.message : String(error)}`, 'Resolve write access to ~/.pd/transactions (disk space / permissions), then retry. No changes were made.');
|
|
438
447
|
}
|
|
448
|
+
// Observational only (see transaction-progress.ts): narrates the stages
|
|
449
|
+
// the journal cannot see inside of, and is removed once they are over.
|
|
450
|
+
const progress = createTransactionProgressReporter(this.paths.transactionsDir, transactionId);
|
|
439
451
|
try {
|
|
440
452
|
const { install } = await import('../installer.js');
|
|
453
|
+
progress.step('Downloading the release asset…');
|
|
441
454
|
const downloaded = await downloadReleaseAsset({
|
|
442
455
|
paths: this.paths,
|
|
443
456
|
metadataBaseUrl: this.options.metadataBaseUrl,
|
|
@@ -445,11 +458,13 @@ export class ReleaseManager {
|
|
|
445
458
|
releaseMetadata,
|
|
446
459
|
channel: status.channel,
|
|
447
460
|
transactionId,
|
|
461
|
+
onProgress: (receivedBytes, totalBytes) => progress.bytes(receivedBytes, totalBytes),
|
|
448
462
|
});
|
|
449
463
|
appendApplyTransition(journal, 'downloaded', `artifact sha256=${downloaded.trustedTarget.artifactSha256} target=${downloaded.trustedTarget.targetPath}`);
|
|
450
464
|
const { payloadDir } = await extractAndVerifyReleaseAsset({
|
|
451
465
|
transactionDir: downloaded.transactionDir,
|
|
452
466
|
archivePath: downloaded.archivePath,
|
|
467
|
+
onStep: (message) => progress.step(message),
|
|
453
468
|
});
|
|
454
469
|
appendApplyTransition(journal, 'verified', 'release-asset preflight passed (identity + whole-payload digest)');
|
|
455
470
|
// Deployment is the installer's job, byte for byte the same cycle a
|
|
@@ -466,7 +481,16 @@ export class ReleaseManager {
|
|
|
466
481
|
overwriteConfig: false,
|
|
467
482
|
host: deploymentHost,
|
|
468
483
|
stopGateway: true,
|
|
469
|
-
}, payloadDir, {
|
|
484
|
+
}, payloadDir, {
|
|
485
|
+
quiet: true,
|
|
486
|
+
nonInteractive: true,
|
|
487
|
+
// An update starts no console. One is usually serving already — the
|
|
488
|
+
// one the update was asked from — and it becomes the new release by
|
|
489
|
+
// handing itself over; `pd console open` beside it only adds a second
|
|
490
|
+
// console, with the first still on the old version.
|
|
491
|
+
launchConsole: false,
|
|
492
|
+
onProgress: ({ message, percent }) => progress.step(message, percent),
|
|
493
|
+
}, journal);
|
|
470
494
|
if (!installResult.success) {
|
|
471
495
|
ensureTerminalFailed(journal, `installer reported failure before deploying (no runtime mutation): ${installResult.error ?? installResult.reason ?? 'unknown'}`);
|
|
472
496
|
throw new ReleaseManagerError('apply_failed', `The installer refused or failed the update: ${installResult.error ?? installResult.reason ?? 'unknown'}`, installResult.nextAction ?? 'The runtime is unchanged. Resolve the reported cause and retry.');
|
|
@@ -505,6 +529,10 @@ export class ReleaseManager {
|
|
|
505
529
|
? mapped
|
|
506
530
|
: new ReleaseManagerError(mapped.reason, mapped.message, mapped.nextAction, true);
|
|
507
531
|
}
|
|
532
|
+
finally {
|
|
533
|
+
// The transaction is over either way; progress has no further meaning.
|
|
534
|
+
progress.close();
|
|
535
|
+
}
|
|
508
536
|
}
|
|
509
537
|
/**
|
|
510
538
|
* Resolve + digest-verify + cache the signed channel document (shared by
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction progress sidecar — what the journal deliberately is not.
|
|
3
|
+
*
|
|
4
|
+
* The transaction journal (`<id>.jsonl`) is the authoritative state machine:
|
|
5
|
+
* append-only, fsynced, one validated transition per line. It records WHEN a
|
|
6
|
+
* stage begins, never how far along that stage is — and it must stay that way.
|
|
7
|
+
* A download that takes minutes and a deploy that takes half a minute are, to
|
|
8
|
+
* the Owner watching the Console, the difference between "it is working" and
|
|
9
|
+
* "it hung". This module is the observational channel for that difference.
|
|
10
|
+
*
|
|
11
|
+
* Contract:
|
|
12
|
+
* - `<transactionsDir>/<id>.progress.json`, replaced atomically, throttled.
|
|
13
|
+
* - DERIVED and best-effort, never authoritative: nothing may branch on it.
|
|
14
|
+
* Absence is normal (an executor built before this file never writes one;
|
|
15
|
+
* the reporter removes it when the transaction ends) and a failed write is
|
|
16
|
+
* swallowed — reporting progress can never fail an update.
|
|
17
|
+
* - The reader validates every field: on the Console side this file is
|
|
18
|
+
* untrusted runtime input, and anything it cannot vouch for is dropped.
|
|
19
|
+
*/
|
|
20
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
21
|
+
import { randomUUID } from 'node:crypto';
|
|
22
|
+
import { basename, dirname, join } from 'node:path';
|
|
23
|
+
export const TRANSACTION_PROGRESS_SCHEMA_VERSION = 1;
|
|
24
|
+
/** Same shape the journal enforces for a transaction id; doubles as the path guard. */
|
|
25
|
+
const TRANSACTION_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
|
|
26
|
+
const DEFAULT_MIN_WRITE_INTERVAL_MS = 400;
|
|
27
|
+
const MAX_STEP_LENGTH = 200;
|
|
28
|
+
/**
|
|
29
|
+
* Replaces the sidecar in one step: write beside it, rename over it. A reader
|
|
30
|
+
* sees the whole previous observation or the whole new one.
|
|
31
|
+
*
|
|
32
|
+
* Deliberately NOT the journal's `writeRecordAtomically`: that adapter is
|
|
33
|
+
* built for records a recovery depends on — fsync, verified reread, and a
|
|
34
|
+
* blocking multi-second rename retry. None of that is worth stalling the
|
|
35
|
+
* update for a file that is rewritten twice a second and may simply be
|
|
36
|
+
* missing. If the rename is refused (antivirus holding the file, a directory
|
|
37
|
+
* in the way), this observation is dropped; the next one is 400ms away.
|
|
38
|
+
*/
|
|
39
|
+
function replaceSidecar(progressPath, text) {
|
|
40
|
+
const temporaryPath = join(dirname(progressPath), `.${basename(progressPath)}.${randomUUID()}.tmp`);
|
|
41
|
+
try {
|
|
42
|
+
writeFileSync(temporaryPath, text);
|
|
43
|
+
renameSync(temporaryPath, progressPath);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
try {
|
|
47
|
+
rmSync(temporaryPath, { force: true });
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// The write itself failed; there is nothing of ours to clean up.
|
|
51
|
+
}
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function transactionProgressPath(transactionsDir, transactionId) {
|
|
56
|
+
return join(transactionsDir, `${transactionId}.progress.json`);
|
|
57
|
+
}
|
|
58
|
+
function isPlainObject(value) {
|
|
59
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
60
|
+
}
|
|
61
|
+
function isNonNegativeSafeInteger(value) {
|
|
62
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Reads and validates one transaction's progress. Null for anything that is
|
|
66
|
+
* not a fully trustworthy observation: absent, unreadable, a different
|
|
67
|
+
* transaction, an unknown schema, or a field of the wrong shape.
|
|
68
|
+
*/
|
|
69
|
+
export function readTransactionProgress(transactionsDir, transactionId) {
|
|
70
|
+
if (!TRANSACTION_ID_PATTERN.test(transactionId))
|
|
71
|
+
return null;
|
|
72
|
+
const progressPath = transactionProgressPath(transactionsDir, transactionId);
|
|
73
|
+
if (!existsSync(progressPath))
|
|
74
|
+
return null;
|
|
75
|
+
let parsed;
|
|
76
|
+
try {
|
|
77
|
+
parsed = JSON.parse(readFileSync(progressPath, 'utf8'));
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// A torn or half-replaced read is "no observation", not an error: the
|
|
81
|
+
// atomic writer guarantees the next read sees a whole record.
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
if (!isPlainObject(parsed))
|
|
85
|
+
return null;
|
|
86
|
+
if (parsed.schemaVersion !== TRANSACTION_PROGRESS_SCHEMA_VERSION || parsed.transactionId !== transactionId)
|
|
87
|
+
return null;
|
|
88
|
+
if (typeof parsed.at !== 'string' || Number.isNaN(Date.parse(parsed.at)))
|
|
89
|
+
return null;
|
|
90
|
+
const step = typeof parsed.step === 'string' && parsed.step.length > 0 ? parsed.step.slice(0, MAX_STEP_LENGTH) : undefined;
|
|
91
|
+
const rawPercent = parsed.percent;
|
|
92
|
+
const percent = typeof rawPercent === 'number' && Number.isFinite(rawPercent) && rawPercent >= 0 && rawPercent <= 100
|
|
93
|
+
? rawPercent
|
|
94
|
+
: undefined;
|
|
95
|
+
// Byte counts are only meaningful as a pair that adds up; one without the
|
|
96
|
+
// other, or a count past its total, is dropped rather than shown wrong.
|
|
97
|
+
const { bytesReceived, bytesTotal } = parsed;
|
|
98
|
+
const hasBytes = isNonNegativeSafeInteger(bytesReceived) && isNonNegativeSafeInteger(bytesTotal)
|
|
99
|
+
&& bytesTotal > 0 && bytesReceived <= bytesTotal;
|
|
100
|
+
return {
|
|
101
|
+
schemaVersion: TRANSACTION_PROGRESS_SCHEMA_VERSION,
|
|
102
|
+
transactionId,
|
|
103
|
+
at: parsed.at,
|
|
104
|
+
...(step !== undefined ? { step } : {}),
|
|
105
|
+
...(percent !== undefined ? { percent } : {}),
|
|
106
|
+
...(hasBytes ? { bytesReceived, bytesTotal } : {}),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Reporter handed to the code that performs the transaction. Every method is
|
|
111
|
+
* total: no input and no filesystem state can make it throw.
|
|
112
|
+
*/
|
|
113
|
+
export function createTransactionProgressReporter(transactionsDir, transactionId, options = {}) {
|
|
114
|
+
const noOp = { step: () => undefined, bytes: () => undefined, close: () => undefined };
|
|
115
|
+
if (!TRANSACTION_ID_PATTERN.test(transactionId))
|
|
116
|
+
return noOp;
|
|
117
|
+
const minWriteIntervalMs = options.minWriteIntervalMs ?? DEFAULT_MIN_WRITE_INTERVAL_MS;
|
|
118
|
+
const now = options.now ?? Date.now;
|
|
119
|
+
const progressPath = transactionProgressPath(transactionsDir, transactionId);
|
|
120
|
+
let observation = {};
|
|
121
|
+
let lastWriteAt = Number.NEGATIVE_INFINITY;
|
|
122
|
+
let trailingTimer;
|
|
123
|
+
let closed = false;
|
|
124
|
+
const write = () => {
|
|
125
|
+
if (trailingTimer !== undefined) {
|
|
126
|
+
clearTimeout(trailingTimer);
|
|
127
|
+
trailingTimer = undefined;
|
|
128
|
+
}
|
|
129
|
+
lastWriteAt = now();
|
|
130
|
+
try {
|
|
131
|
+
mkdirSync(transactionsDir, { recursive: true });
|
|
132
|
+
replaceSidecar(progressPath, `${JSON.stringify({
|
|
133
|
+
schemaVersion: TRANSACTION_PROGRESS_SCHEMA_VERSION,
|
|
134
|
+
transactionId,
|
|
135
|
+
at: new Date(now()).toISOString(),
|
|
136
|
+
...observation,
|
|
137
|
+
})}\n`);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// Progress is an observability nicety. A disk that refuses it has to be
|
|
141
|
+
// reported by the transaction itself, on its own authority.
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
/** Write now, or soon: never more often than the interval, never lose the last value. */
|
|
145
|
+
const schedule = () => {
|
|
146
|
+
if (closed)
|
|
147
|
+
return;
|
|
148
|
+
const elapsed = now() - lastWriteAt;
|
|
149
|
+
if (elapsed >= minWriteIntervalMs) {
|
|
150
|
+
write();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (trailingTimer === undefined) {
|
|
154
|
+
trailingTimer = setTimeout(() => {
|
|
155
|
+
trailingTimer = undefined;
|
|
156
|
+
if (!closed)
|
|
157
|
+
write();
|
|
158
|
+
}, minWriteIntervalMs - elapsed);
|
|
159
|
+
// A pending progress write must not keep a dying executor alive.
|
|
160
|
+
trailingTimer.unref?.();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
return {
|
|
164
|
+
step(message, percent) {
|
|
165
|
+
if (closed)
|
|
166
|
+
return;
|
|
167
|
+
observation = {
|
|
168
|
+
...(message.length > 0 ? { step: message.slice(0, MAX_STEP_LENGTH) } : {}),
|
|
169
|
+
...(typeof percent === 'number' && Number.isFinite(percent) && percent >= 0 && percent <= 100
|
|
170
|
+
? { percent: Math.round(percent) }
|
|
171
|
+
: {}),
|
|
172
|
+
};
|
|
173
|
+
write();
|
|
174
|
+
},
|
|
175
|
+
bytes(received, total) {
|
|
176
|
+
if (closed)
|
|
177
|
+
return;
|
|
178
|
+
if (!isNonNegativeSafeInteger(received))
|
|
179
|
+
return;
|
|
180
|
+
observation = {
|
|
181
|
+
...observation,
|
|
182
|
+
bytesReceived: received,
|
|
183
|
+
...(isNonNegativeSafeInteger(total) && total > 0 ? { bytesTotal: total } : {}),
|
|
184
|
+
};
|
|
185
|
+
if (observation.bytesTotal !== undefined && observation.bytesTotal < received)
|
|
186
|
+
delete observation.bytesTotal;
|
|
187
|
+
schedule();
|
|
188
|
+
},
|
|
189
|
+
close() {
|
|
190
|
+
if (closed)
|
|
191
|
+
return;
|
|
192
|
+
closed = true;
|
|
193
|
+
if (trailingTimer !== undefined) {
|
|
194
|
+
clearTimeout(trailingTimer);
|
|
195
|
+
trailingTimer = undefined;
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
rmSync(progressPath, { force: true });
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
// A sidecar that cannot be removed is ignored by readers the moment it
|
|
202
|
+
// goes stale; it must not turn a finished transaction into a failure.
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=transaction-progress.js.map
|