opencode-usage-coach 0.10.1 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +21 -14
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -377,6 +377,22 @@ function writeHarness(sessionID, h) {
377
377
  } catch {
378
378
  }
379
379
  }
380
+ var harnessQueue = /* @__PURE__ */ new Map();
381
+ function mutateHarness(sessionID, fn) {
382
+ const prev = harnessQueue.get(sessionID) ?? Promise.resolve();
383
+ const next = prev.then(() => {
384
+ const h = readHarness(sessionID);
385
+ if (!h) return;
386
+ const result = fn(h);
387
+ writeHarness(sessionID, result ?? h);
388
+ }).catch(() => {
389
+ });
390
+ harnessQueue.set(sessionID, next);
391
+ next.finally(() => {
392
+ if (harnessQueue.get(sessionID) === next) harnessQueue.delete(sessionID);
393
+ });
394
+ return next;
395
+ }
380
396
  function interviewFile(sessionID) {
381
397
  return join2(STATE_DIR, sessionID || "_default", "interview.json");
382
398
  }
@@ -508,29 +524,20 @@ Output JSON ONLY (no markdown fences, no prose):
508
524
  return formatCompleteOutput(state);
509
525
  }
510
526
  function updateSubSession(sessionID, taskId, fields) {
511
- try {
512
- const h = readHarness(sessionID);
513
- if (!h) return;
527
+ return mutateHarness(sessionID, (h) => {
514
528
  const t = h.tasks.find((x) => x.id === taskId);
515
- if (!t) return;
516
- Object.assign(t, fields);
517
- writeHarness(sessionID, h);
518
- } catch {
519
- }
529
+ if (t) Object.assign(t, fields);
530
+ });
520
531
  }
521
532
  function clearSubSession(sessionID, taskId) {
522
- try {
523
- const h = readHarness(sessionID);
524
- if (!h) return;
533
+ return mutateHarness(sessionID, (h) => {
525
534
  const t = h.tasks.find((x) => x.id === taskId);
526
535
  if (!t) return;
527
536
  t.subSessionId = void 0;
528
537
  t.subStep = void 0;
529
538
  t.lastActivity = void 0;
530
539
  t.subElapsed = void 0;
531
- writeHarness(sessionID, h);
532
- } catch {
533
- }
540
+ });
534
541
  }
535
542
  function findActiveTaskId(sessionID, status) {
536
543
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-usage-coach",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "opencode closed-loop usage coach — quota SENSE -> coaching DECIDE -> loop ACT + TUI integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",