@dvmkit/dvm-cli 0.15.1 → 0.15.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.
@@ -10,13 +10,15 @@ import {
10
10
  formatAmount,
11
11
  formatPaymentAmount,
12
12
  formatSats,
13
+ hasUnsavedJobState,
13
14
  info,
15
+ jobPersistence,
14
16
  json,
15
17
  progress,
16
18
  resolveBtcUsdRate,
17
19
  tryResolveBtcUsdRate,
18
20
  tryX402Payment
19
- } from "./chunk-5SHB3MZ7.js";
21
+ } from "./chunk-F45ETHDP.js";
20
22
  import {
21
23
  loadX402Wallet,
22
24
  x402NetworkLabel
@@ -2041,13 +2043,18 @@ function saveJob(job) {
2041
2043
  jobs.push(job);
2042
2044
  });
2043
2045
  }
2046
+ function saveAcceptedJob(job) {
2047
+ mutateJobs((jobs) => {
2048
+ jobs.push(job);
2049
+ }, true);
2050
+ }
2044
2051
  function saveSubmittedJob(job) {
2045
2052
  mutateJobs((jobs) => {
2046
2053
  const existing = jobs.find((entry) => entry.id === job.id);
2047
2054
  if (!existing) jobs.push(job);
2048
2055
  else if (existing.endpoint !== job.endpoint || existing.requestId && existing.requestId !== job.requestId)
2049
2056
  throw new Error("Submitted job conflicts with an existing local job.");
2050
- });
2057
+ }, true);
2051
2058
  }
2052
2059
  function recordUpfrontCreditPayment(jobId, value, paidOnRail = false) {
2053
2060
  const payment = parseUpfrontPayment(value);
@@ -2077,7 +2084,7 @@ function recordUpfrontCreditPayment(jobId, value, paidOnRail = false) {
2077
2084
  job.totalPaidMsats = (job.totalPaidMsats ?? 0) + payment.amount_msats;
2078
2085
  job.paymentsHonoured = (job.paymentsHonoured ?? 0) + (payment.amount_msats > 0 ? 1 : 0);
2079
2086
  job.upfrontCreditBooked = true;
2080
- });
2087
+ }, true);
2081
2088
  }
2082
2089
  function hasUnknownUpfrontCredit(job) {
2083
2090
  return job.upfrontCreditConflict === true || job.paymentMethod === "credit" && (!job.upfrontCreditBooked || !parseUpfrontPayment(job.upfrontPayment));
@@ -2105,7 +2112,7 @@ function recordUpfrontRailPayment(jobId, value, freshSubmit = false) {
2105
2112
  job.paymentsHonoured = (job.paymentsHonoured ?? 0) + (payment.amountMsats > 0 ? 1 : 0);
2106
2113
  job.paymentMethod = payment.method;
2107
2114
  job.upfrontRailPayment = payment;
2108
- });
2115
+ }, true);
2109
2116
  }
2110
2117
  function hasUnknownUpfrontRail(job) {
2111
2118
  return job.upfrontRailPayment === "unknown" || job.upfrontRailConflict === true;
@@ -2116,16 +2123,22 @@ function updateJob(id, update) {
2116
2123
  if (idx !== -1) jobs[idx] = { ...jobs[idx], ...update };
2117
2124
  });
2118
2125
  }
2126
+ function updateObservedJob(id, update) {
2127
+ mutateJobs((jobs) => {
2128
+ const idx = jobs.findIndex((j) => j.id === id);
2129
+ if (idx !== -1) jobs[idx] = { ...jobs[idx], ...update };
2130
+ }, true);
2131
+ }
2119
2132
  function recordCallerMessageHash(jobId, endpoint, hash) {
2120
2133
  mutateJobs((jobs) => {
2121
2134
  const job = jobs.find((entry) => entry.id === jobId && sameEndpoint(entry.endpoint, endpoint));
2122
2135
  if (job) job.callerMessageHashes = [.../* @__PURE__ */ new Set([...job.callerMessageHashes ?? [], hash])];
2123
- });
2136
+ }, true);
2124
2137
  }
2125
2138
  function markJobTerminal(id, status, completion, extra) {
2126
2139
  const existing = loadJob(id);
2127
2140
  if (!existing) return;
2128
- updateJob(id, {
2141
+ updateObservedJob(id, {
2129
2142
  ...extra,
2130
2143
  status,
2131
2144
  completedAt: existing.completedAt ?? Date.now(),
@@ -2137,6 +2150,8 @@ function loadJob(id) {
2137
2150
  return jobs.find((j) => j.id === id) ?? null;
2138
2151
  }
2139
2152
  function loadAllJobs() {
2153
+ const unsaved = jobPersistence.getStore()?.unsaved;
2154
+ if (unsaved) return structuredClone(unsaved);
2140
2155
  if (!existsSync2(JOBS_FILE)) return [];
2141
2156
  try {
2142
2157
  return JSON.parse(readFileSync2(JOBS_FILE, "utf-8"));
@@ -2148,7 +2163,7 @@ function addPayment(jobId, amountMsats, approval) {
2148
2163
  mutateJobs((jobs) => {
2149
2164
  const job = jobs.find((entry) => entry.id === jobId);
2150
2165
  if (job) bookPayment(job, amountMsats, approval);
2151
- });
2166
+ }, true);
2152
2167
  }
2153
2168
  function bookPayment(job, amountMsats, approval) {
2154
2169
  job.totalPaidMsats = (job.totalPaidMsats ?? 0) + amountMsats;
@@ -2184,7 +2199,7 @@ function clearUnconfirmedSubmission(job, requestSeq) {
2184
2199
  if (!Object.keys(job.unconfirmedPaymentSubmissions).length) delete job.unconfirmedPaymentSubmissions;
2185
2200
  }
2186
2201
  function markPaymentRequestPaid(jobId, requestSeq) {
2187
- return mutateJobs((jobs) => {
2202
+ const booked2 = mutateJobs((jobs) => {
2188
2203
  const job = jobs.find((entry) => entry.id === jobId);
2189
2204
  if (!job) return void 0;
2190
2205
  if (!job.paidPaymentRequestSeqs?.includes(requestSeq))
@@ -2194,15 +2209,16 @@ function markPaymentRequestPaid(jobId, requestSeq) {
2194
2209
  if (!job.inFlightPaymentRequestSeqs.length) delete job.inFlightPaymentRequestSeqs;
2195
2210
  }
2196
2211
  clearPaymentRequestStartTime(job, requestSeq);
2197
- const booked2 = job.unconfirmedPaymentSubmissions?.[requestSeq];
2212
+ const booked3 = job.unconfirmedPaymentSubmissions?.[requestSeq];
2198
2213
  clearUnconfirmedSubmission(job, requestSeq);
2199
- if (booked2) bookPayment(job, booked2.amountMsats, booked2.approval ? { requestSeq, approval: booked2.approval } : void 0);
2200
- if (booked2 && !booked2.blocked && job.askPaymentBlocks?.[requestSeq]) {
2214
+ if (booked3) bookPayment(job, booked3.amountMsats, booked3.approval ? { requestSeq, approval: booked3.approval } : void 0);
2215
+ if (booked3 && !booked3.blocked && job.askPaymentBlocks?.[requestSeq]) {
2201
2216
  delete job.askPaymentBlocks[requestSeq];
2202
2217
  if (!Object.keys(job.askPaymentBlocks).length) delete job.askPaymentBlocks;
2203
2218
  }
2204
- return booked2;
2205
- });
2219
+ return booked3;
2220
+ }, true);
2221
+ return hasUnsavedJobState() ? void 0 : booked2;
2206
2222
  }
2207
2223
  function markPaymentRequestAnswered(jobId, requestSeq) {
2208
2224
  mutateJobs((jobs) => {
@@ -2213,7 +2229,7 @@ function markPaymentRequestAnswered(jobId, requestSeq) {
2213
2229
  job.inFlightPaymentRequestSeqs = job.inFlightPaymentRequestSeqs?.filter((seq) => seq !== requestSeq);
2214
2230
  if (!job.inFlightPaymentRequestSeqs?.length) delete job.inFlightPaymentRequestSeqs;
2215
2231
  clearPaymentRequestStartTime(job, requestSeq);
2216
- });
2232
+ }, true);
2217
2233
  }
2218
2234
  function blockHeldPayment(jobId, requestSeq, blocked) {
2219
2235
  mutateJobs((jobs) => {
@@ -2231,7 +2247,7 @@ function clearAskPaymentBlocks(jobId) {
2231
2247
  mutateJobs((jobs) => {
2232
2248
  const job = jobs.find((entry) => entry.id === jobId);
2233
2249
  if (job) delete job.askPaymentBlocks;
2234
- });
2250
+ }, true);
2235
2251
  }
2236
2252
  function releaseReclaimedSubmissions(cashuRequestIds) {
2237
2253
  if (cashuRequestIds.size === 0) return;
@@ -2280,25 +2296,75 @@ function writeJobs(jobs) {
2280
2296
  }
2281
2297
  }
2282
2298
  }
2283
- function mutateJobs(change) {
2284
- ensureConfigDir();
2285
- const release = import_proper_lockfile.default.lockSync(JOBS_FILE, { realpath: false });
2299
+ var lockWait = new Int32Array(new SharedArrayBuffer(4));
2300
+ function acquireJobsLock() {
2301
+ const deadline = performance.now() + 1e3;
2302
+ for (let attempt = 0; ; attempt++) {
2303
+ try {
2304
+ return import_proper_lockfile.default.lockSync(JOBS_FILE, { realpath: false });
2305
+ } catch (error) {
2306
+ if (error.code !== "ELOCKED" || attempt >= 40 || performance.now() >= deadline) throw error;
2307
+ Atomics.wait(lockWait, 0, 0, Math.min(25, Math.max(0, deadline - performance.now())));
2308
+ }
2309
+ }
2310
+ }
2311
+ function mutateJobs(change, observed = false) {
2312
+ const session = jobPersistence.getStore();
2313
+ const retain = (jobs2) => {
2314
+ if (!session) throw new Error("Job persistence session unavailable.");
2315
+ session.unsaved = structuredClone(jobs2);
2316
+ session.warn();
2317
+ };
2318
+ if (hasUnsavedJobState()) {
2319
+ if (!observed) throw new DvmError(
2320
+ "local_job_state_unsaved",
2321
+ "Local job state must be saved before another payment can be sent.",
2322
+ "Refresh the job once local storage is available; do not submit a replacement."
2323
+ );
2324
+ const jobs2 = loadAllJobs();
2325
+ const result = change(jobs2);
2326
+ retain(jobs2);
2327
+ return result;
2328
+ }
2329
+ let release;
2330
+ try {
2331
+ ensureConfigDir();
2332
+ release = acquireJobsLock();
2333
+ } catch (error) {
2334
+ if (!observed || !session) throw error;
2335
+ const jobs2 = loadAllJobs();
2336
+ const result = change(jobs2);
2337
+ retain(jobs2);
2338
+ return result;
2339
+ }
2340
+ const jobs = loadAllJobs();
2341
+ let mutationCompleted = false;
2286
2342
  try {
2287
- const jobs = loadAllJobs();
2288
2343
  const before = JSON.stringify(jobs);
2289
2344
  const result = change(jobs);
2290
- if (JSON.stringify(jobs) !== before) writeJobs(jobs);
2345
+ mutationCompleted = true;
2346
+ try {
2347
+ if (JSON.stringify(jobs) !== before) writeJobs(jobs);
2348
+ } catch (error) {
2349
+ if (!observed || !session) throw error;
2350
+ retain(jobs);
2351
+ }
2291
2352
  return result;
2292
2353
  } finally {
2293
- release();
2354
+ try {
2355
+ release();
2356
+ } catch (error) {
2357
+ if (!mutationCompleted || !observed || !session) throw error;
2358
+ retain(jobs);
2359
+ }
2294
2360
  }
2295
2361
  }
2296
- function mutateCreditPayment(jobId, change) {
2362
+ function mutateCreditPayment(jobId, change, observed = false) {
2297
2363
  return mutateJobs((jobs) => {
2298
2364
  const job = jobs.find((entry) => entry.id === jobId);
2299
2365
  if (!job) throw new Error("Cannot persist a balance payment for an unknown job.");
2300
2366
  return change(job);
2301
- });
2367
+ }, observed);
2302
2368
  }
2303
2369
  function bookCreditPayment(jobId, intent) {
2304
2370
  mutateCreditPayment(jobId, (job) => {
@@ -2313,7 +2379,7 @@ function bookCreditPayment(jobId, intent) {
2313
2379
  }
2314
2380
  if (job.pendingCreditPayment?.authorization.payment_id === intent.authorization.payment_id)
2315
2381
  delete job.pendingCreditPayment;
2316
- });
2382
+ }, true);
2317
2383
  }
2318
2384
 
2319
2385
  // src/lib/messages/store.ts
@@ -3359,49 +3425,80 @@ async function settleTakenPayment(jobId, requestSeq) {
3359
3425
  return booked2;
3360
3426
  }
3361
3427
 
3362
- // src/lib/wallet-agent/submission-verdicts.ts
3428
+ // src/lib/wallet-agent/journal-file.ts
3363
3429
  var import_proper_lockfile2 = __toESM(require_proper_lockfile(), 1);
3364
3430
  import { closeSync as closeSync4, existsSync as existsSync4, fsyncSync as fsyncSync3, openSync as openSync4, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync3 } from "fs";
3365
3431
  import { dirname as dirname2, join as join3 } from "path";
3366
- var verdictsFile = () => join3(dirname2(JOBS_FILE), "submission-verdicts.json");
3367
- function readVerdicts() {
3368
- if (!existsSync4(verdictsFile())) return [];
3369
- try {
3370
- const parsed = JSON.parse(readFileSync4(verdictsFile(), "utf8"));
3371
- return Array.isArray(parsed) ? parsed : [];
3372
- } catch {
3373
- return [];
3432
+ function journalFile(name) {
3433
+ const file = () => join3(dirname2(JOBS_FILE), name);
3434
+ function read() {
3435
+ if (!existsSync4(file())) return [];
3436
+ try {
3437
+ const parsed = JSON.parse(readFileSync4(file(), "utf8"));
3438
+ return Array.isArray(parsed) ? parsed : [];
3439
+ } catch {
3440
+ return [];
3441
+ }
3374
3442
  }
3375
- }
3376
- function withVerdictsLock(change) {
3377
- ensureConfigDir();
3378
- if (!existsSync4(verdictsFile())) writeFileSync3(verdictsFile(), "[]\n", { mode: 384, flag: "a" });
3379
- let release;
3380
- for (let attempt = 0; !release; attempt++) {
3443
+ function withLock(change) {
3444
+ ensureConfigDir();
3445
+ if (!existsSync4(file())) writeFileSync3(file(), "[]\n", { mode: 384, flag: "a" });
3446
+ let release;
3447
+ for (let attempt = 0; !release; attempt++) {
3448
+ try {
3449
+ release = import_proper_lockfile2.default.lockSync(file(), { realpath: false });
3450
+ } catch (error) {
3451
+ if (attempt >= 40) throw error;
3452
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25);
3453
+ }
3454
+ }
3381
3455
  try {
3382
- release = import_proper_lockfile2.default.lockSync(verdictsFile(), { realpath: false });
3383
- } catch (error) {
3384
- if (attempt >= 40) throw error;
3385
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25);
3456
+ return change();
3457
+ } finally {
3458
+ release();
3386
3459
  }
3387
3460
  }
3388
- try {
3389
- return change();
3390
- } finally {
3391
- release();
3461
+ function write(entries) {
3462
+ const temporary = `${file()}.${process.pid}.tmp`;
3463
+ const fd = openSync4(temporary, "w", 384);
3464
+ try {
3465
+ writeFileSync3(fd, JSON.stringify(entries, null, 2) + "\n");
3466
+ fsyncSync3(fd);
3467
+ } finally {
3468
+ closeSync4(fd);
3469
+ }
3470
+ renameSync2(temporary, file());
3392
3471
  }
3472
+ return { read, withLock, write };
3393
3473
  }
3394
- function writeVerdicts(verdicts) {
3395
- const temporary = `${verdictsFile()}.${process.pid}.tmp`;
3396
- const fd = openSync4(temporary, "w", 384);
3397
- try {
3398
- writeFileSync3(fd, JSON.stringify(verdicts, null, 2) + "\n");
3399
- fsyncSync3(fd);
3400
- } finally {
3401
- closeSync4(fd);
3402
- }
3403
- renameSync2(temporary, verdictsFile());
3474
+
3475
+ // src/lib/wallet-agent/reclaim-intents.ts
3476
+ var intents = journalFile("reclaim-intents.json");
3477
+ function recordReclaimIntent(intent) {
3478
+ intents.withLock(() => {
3479
+ intents.write([...intents.read().filter((held) => held.requestId !== intent.requestId), intent]);
3480
+ });
3481
+ }
3482
+ function loadReclaimIntent(requestId) {
3483
+ return intents.read().find((intent) => intent.requestId === requestId);
3404
3484
  }
3485
+ function allReclaimIntents() {
3486
+ return intents.read();
3487
+ }
3488
+ function clearReclaimIntent(requestId, createdAt) {
3489
+ const matches = (held) => held.requestId === requestId && (createdAt === void 0 || held.createdAt === createdAt);
3490
+ if (!intents.read().some(matches)) return;
3491
+ intents.withLock(() => intents.write(intents.read().filter((held) => !matches(held))));
3492
+ }
3493
+ function reclaimIntentIds() {
3494
+ return new Set(intents.read().map((intent) => intent.requestId));
3495
+ }
3496
+
3497
+ // src/lib/wallet-agent/submission-verdicts.ts
3498
+ var verdictJournal = journalFile("submission-verdicts.json");
3499
+ var readVerdicts = verdictJournal.read;
3500
+ var withVerdictsLock = verdictJournal.withLock;
3501
+ var writeVerdicts = verdictJournal.write;
3405
3502
  function recordSubmissionVerdicts(verdicts) {
3406
3503
  if (verdicts.length === 0) return;
3407
3504
  withVerdictsLock(() => {
@@ -3413,10 +3510,24 @@ function recordSubmissionVerdicts(verdicts) {
3413
3510
  });
3414
3511
  }
3415
3512
  async function applySubmissionVerdicts() {
3416
- const verdicts = readVerdicts();
3417
- if (verdicts.length === 0) return;
3513
+ let failure;
3514
+ try {
3515
+ finalizeLandedReclaims();
3516
+ } catch (error) {
3517
+ failure = { error };
3518
+ }
3519
+ try {
3520
+ await applyJournalledVerdicts();
3521
+ } catch (error) {
3522
+ failure ??= { error };
3523
+ }
3524
+ if (failure) throw failure.error;
3525
+ }
3526
+ async function applyJournalledVerdicts() {
3527
+ const journalled = readVerdicts();
3528
+ if (journalled.length === 0) return;
3418
3529
  const held = new Set(loadAgentWallet()?.pending_submissions.map((entry) => entry.request_id) ?? []);
3419
- const landed = verdicts.filter((verdict) => !held.has(verdict.requestId));
3530
+ const landed = journalled.filter((verdict) => !held.has(verdict.requestId));
3420
3531
  if (landed.length === 0) return;
3421
3532
  releaseReclaimedSubmissions(new Set(landed.filter((verdict) => verdict.verdict === "reclaimed").map((verdict) => verdict.requestId)));
3422
3533
  for (const verdict of landed) {
@@ -3430,9 +3541,22 @@ async function applySubmissionVerdicts() {
3430
3541
  });
3431
3542
  }
3432
3543
  }
3544
+ if (hasUnsavedJobState()) return;
3433
3545
  const applied = new Set(landed.map((verdict) => verdict.requestId));
3434
3546
  withVerdictsLock(() => writeVerdicts(readVerdicts().filter((verdict) => !applied.has(verdict.requestId))));
3435
3547
  }
3548
+ function finalizeLandedReclaims() {
3549
+ const intents2 = allReclaimIntents();
3550
+ if (intents2.length === 0) return;
3551
+ const wallet = loadAgentWallet();
3552
+ if (!wallet) return;
3553
+ const held = new Set(wallet.pending_submissions.map((entry) => entry.request_id));
3554
+ for (const intent of intents2) {
3555
+ if (held.has(intent.requestId)) continue;
3556
+ recordSubmissionVerdicts([intent.verdict]);
3557
+ clearReclaimIntent(intent.requestId, intent.createdAt);
3558
+ }
3559
+ }
3436
3560
 
3437
3561
  // src/lib/yield-state.ts
3438
3562
  var JOB_READ_TIMEOUT_MS = 6e4;
@@ -3590,10 +3714,17 @@ function pollNextAction(jobId, hint) {
3590
3714
  };
3591
3715
  }
3592
3716
  function heldPaymentResendable(job, requestSeq) {
3717
+ return heldPaymentResendability(job, requestSeq) === "resendable";
3718
+ }
3719
+ function heldPaymentResendability(job, requestSeq) {
3593
3720
  const submission = job?.unconfirmedPaymentSubmissions?.[requestSeq];
3594
- if (!submission || submission.blocked) return false;
3595
- if (submission.rail !== "cashu_p2pk") return true;
3596
- return loadAgentWallet()?.pending_submissions.some((entry) => entry.request_id === submission.cashuRequestId) === true;
3721
+ if (!submission || submission.blocked) return "unavailable";
3722
+ if (submission.rail !== "cashu_p2pk") return "resendable";
3723
+ try {
3724
+ return loadAgentWallet()?.pending_submissions.some((entry) => entry.request_id === submission.cashuRequestId) ? "resendable" : "unavailable";
3725
+ } catch {
3726
+ return "unreadable";
3727
+ }
3597
3728
  }
3598
3729
  function paymentInFlightHint(jobId, job, requestSeq) {
3599
3730
  const arg = guidanceJobArg(jobId);
@@ -3601,8 +3732,12 @@ function paymentInFlightHint(jobId, job, requestSeq) {
3601
3732
  if (!job || requestSeq === void 0) return resend;
3602
3733
  const submission = job.unconfirmedPaymentSubmissions?.[requestSeq];
3603
3734
  const stop = `To stop instead, \`dvm decline ${arg}\` ends the job and keeps the finished work, or \`dvm cancel ${arg}\` halts the work now and charges the work in progress.`;
3604
- if (submission && !submission.blocked)
3605
- return heldPaymentResendable(job, requestSeq) ? resend : `The wallet no longer holds the earlier Cashu payment for this request, so it cannot be re-sent. ${unresendablePaymentHint(jobId)}`;
3735
+ if (submission && !submission.blocked) {
3736
+ const resendability = heldPaymentResendability(job, requestSeq);
3737
+ if (resendability === "unreadable")
3738
+ return "The wallet is unreadable, so the earlier Cashu payment cannot be checked or re-sent. Preserve the wallet file; consult `dvm wallet recover --help` for recovery from your backed-up secret. " + unresendablePaymentHint(jobId);
3739
+ return resendability === "resendable" ? resend : `The wallet no longer holds the earlier Cashu payment for this request, so it cannot be re-sent. ${unresendablePaymentHint(jobId)}`;
3740
+ }
3606
3741
  if (submission?.blocked?.reason === "not_resendable")
3607
3742
  return `${submission.blocked.detail} ${unresendablePaymentHint(jobId)}`;
3608
3743
  const askBlock = job.askPaymentBlocks?.[requestSeq];
@@ -4930,7 +5065,7 @@ function captureDrawFundingReceipts(jobId, receipts, opts) {
4930
5065
  job.drawFundingReceipts = held;
4931
5066
  }
4932
5067
  }
4933
- });
5068
+ }, true);
4934
5069
  } catch (error) {
4935
5070
  info(`Warning: could not store mid-job funding evidence: ${error instanceof Error ? error.message : String(error)}`);
4936
5071
  }
@@ -5151,7 +5286,7 @@ async function backfillTrustAnchor(jobId, transport, ref) {
5151
5286
  try {
5152
5287
  const provider = await transport.describe(ref);
5153
5288
  const fields = receiptTrustFields(provider);
5154
- if (Object.keys(fields).length > 0) updateJob(jobId, fields);
5289
+ if (Object.keys(fields).length > 0) updateObservedJob(jobId, fields);
5155
5290
  return fields.builderAnchor;
5156
5291
  } catch {
5157
5292
  return void 0;
@@ -5195,7 +5330,7 @@ function toCapture(receipt, result, context = receiptPieceContext(receipt), endp
5195
5330
  }
5196
5331
  function persist(jobId, receipt, verification, job) {
5197
5332
  try {
5198
- updateJob(jobId, { receipt });
5333
+ updateObservedJob(jobId, { receipt });
5199
5334
  appendReceipt({
5200
5335
  receipt,
5201
5336
  endpoint: job?.endpoint ?? "",
@@ -5211,7 +5346,7 @@ function persist(jobId, receipt, verification, job) {
5211
5346
  }
5212
5347
  function persistParseError(jobId, receiptParseError) {
5213
5348
  try {
5214
- updateJob(jobId, { receiptParseError });
5349
+ updateObservedJob(jobId, { receiptParseError });
5215
5350
  } catch (err) {
5216
5351
  info(
5217
5352
  `Warning: could not store job receipt diagnostic: ${err instanceof Error ? err.message : String(err)}`
@@ -8715,12 +8850,14 @@ export {
8715
8850
  parseUpfrontRailPayment,
8716
8851
  parseUpfrontPayment,
8717
8852
  saveJob,
8853
+ saveAcceptedJob,
8718
8854
  saveSubmittedJob,
8719
8855
  recordUpfrontCreditPayment,
8720
8856
  hasUnknownUpfrontCredit,
8721
8857
  recordUpfrontRailPayment,
8722
8858
  hasUnknownUpfrontRail,
8723
8859
  updateJob,
8860
+ updateObservedJob,
8724
8861
  recordCallerMessageHash,
8725
8862
  markJobTerminal,
8726
8863
  loadJob,
@@ -8792,8 +8929,14 @@ export {
8792
8929
  withAcceptedUnresolved,
8793
8930
  midJobSpendLabel,
8794
8931
  finishBookedSubmission,
8932
+ journalFile,
8933
+ recordReclaimIntent,
8934
+ loadReclaimIntent,
8935
+ clearReclaimIntent,
8936
+ reclaimIntentIds,
8795
8937
  recordSubmissionVerdicts,
8796
8938
  applySubmissionVerdicts,
8939
+ finalizeLandedReclaims,
8797
8940
  JOB_READ_TIMEOUT_MS,
8798
8941
  answeredYieldSeqs,
8799
8942
  settleAnsweredAsk,
@@ -36,13 +36,33 @@ import {
36
36
  import { randomBytes } from "crypto";
37
37
 
38
38
  // src/lib/output.ts
39
- import { AsyncLocalStorage } from "async_hooks";
39
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
40
40
  import { writeSync } from "fs";
41
- var warnings = new AsyncLocalStorage();
42
- function withOutputWarnings(run) {
43
- return warnings.run([], run);
41
+
42
+ // src/lib/job-persistence.ts
43
+ import { AsyncLocalStorage } from "async_hooks";
44
+ var jobPersistence = new AsyncLocalStorage();
45
+ function hasUnsavedJobState() {
46
+ return jobPersistence.getStore()?.unsaved !== void 0;
47
+ }
48
+ function withJobPersistence(run, warn) {
49
+ if (jobPersistence.getStore()) return run();
50
+ return jobPersistence.run({ warn }, run);
51
+ }
52
+
53
+ // src/lib/output.ts
54
+ var warnings = new AsyncLocalStorage2();
55
+ function withOutputWarnings(run, human) {
56
+ return warnings.run([], () => withJobPersistence(run, () => {
57
+ addOutputWarnings([{
58
+ code: "local_job_state_unsaved",
59
+ display: "The provider's outcome is unchanged, but local job state could not be saved and may lag. Automatic payments are paused for this command.",
60
+ hint: "Once local storage is available, refresh the job with dvm status <job_id> --messages before paying or submitting a replacement."
61
+ }], human);
62
+ }));
44
63
  }
45
64
  function sameWarning(prior, entry) {
65
+ if (prior.code === "local_job_state_unsaved" && entry.code === "local_job_state_unsaved") return true;
46
66
  if (prior.code === "auto_pay_bound_exceeded" && entry.code === "auto_pay_bound_exceeded") {
47
67
  return prior.auto_pay_below === entry.auto_pay_below && prior.source === entry.source;
48
68
  }
@@ -419,6 +439,8 @@ async function priceableRate(btcRate) {
419
439
  }
420
440
 
421
441
  export {
442
+ jobPersistence,
443
+ hasUnsavedJobState,
422
444
  withOutputWarnings,
423
445
  addOutputWarnings,
424
446
  setOutputTraceId,
@@ -3,7 +3,7 @@ import { createRequire as __dvmCreateRequire } from "node:module";
3
3
  const require = __dvmCreateRequire(import.meta.url);
4
4
  import {
5
5
  tryX402Payment
6
- } from "./chunk-5SHB3MZ7.js";
6
+ } from "./chunk-F45ETHDP.js";
7
7
  import "./chunk-YQJRKWNT.js";
8
8
  import "./chunk-JBU7RKQ3.js";
9
9
  import "./chunk-KDNFUDOG.js";