@standardagents/code 0.11.3 → 0.11.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/dist/index.js CHANGED
@@ -579,14 +579,24 @@ var ApiClient = class {
579
579
  // Backed by the instance's /api/users/me/kv store. This is where the machine
580
580
  // registry lives: which machines (laptops / VPS daemons) belong to this
581
581
  // account, and which projects each machine has.
582
- /** Read one value from the signed-in user's account-wide KV (null if absent). */
583
- async userKvGet(key) {
582
+ /**
583
+ * Read one value from the signed-in user's account-wide KV (null if absent).
584
+ * A missing key is a 200 `{value: null}` from the instance, so any THROWN
585
+ * error is a transport/server failure, never "not found". `strict` rethrows
586
+ * those failures — required by read-modify-write callers (the machine
587
+ * registry), where treating a failed read as "no record yet" would overwrite
588
+ * the real record with a fresh empty one (this wiped a machine's whole
589
+ * project list during a deploy window). Non-strict callers (pollers,
590
+ * display overlays) keep the lenient null.
591
+ */
592
+ async userKvGet(key, opts) {
584
593
  try {
585
594
  const res = await this.json(
586
595
  `/api/users/me/kv?key=${encodeURIComponent(key)}`
587
596
  );
588
597
  return res?.value ?? null;
589
- } catch {
598
+ } catch (error) {
599
+ if (opts?.strict) throw error;
590
600
  return null;
591
601
  }
592
602
  }
@@ -6587,8 +6597,8 @@ function parseMachineRecord(value) {
6587
6597
  updated_at: typeof r.updated_at === "number" ? r.updated_at : 0
6588
6598
  };
6589
6599
  }
6590
- async function loadRawMachine(api, machineId) {
6591
- return parseMachineRecord(await api.userKvGet(machineKey(machineId)));
6600
+ async function loadRawMachine(api, machineId, opts) {
6601
+ return parseMachineRecord(await api.userKvGet(machineKey(machineId), opts));
6592
6602
  }
6593
6603
  async function loadMachines(api) {
6594
6604
  const entries = await api.userKvList(KEY_PREFIX);
@@ -6715,7 +6725,7 @@ function newRecord(identity) {
6715
6725
  };
6716
6726
  }
6717
6727
  async function updateOwnMachineRecord(api, identity, mutate) {
6718
- const existing = await loadRawMachine(api, identity.machine_id);
6728
+ const existing = await loadRawMachine(api, identity.machine_id, { strict: true });
6719
6729
  const record2 = existing ?? newRecord(identity);
6720
6730
  record2.hostname = os8.hostname();
6721
6731
  record2.platform = process.platform;