@afokapu/atdd-flow 0.3.13 → 0.3.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afokapu/atdd-flow",
3
- "version": "0.3.13",
3
+ "version": "0.3.14",
4
4
  "description": "Filesystem-first Desk registry for projects, seats, tasks, threads, and handoffs.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/core.ts CHANGED
@@ -2,6 +2,7 @@ import { mkdir, readFile, rename, stat, writeFile } from "node:fs/promises";
2
2
  import { existsSync } from "node:fs";
3
3
  import { basename, dirname, join, resolve } from "node:path";
4
4
  import { randomUUID } from "node:crypto";
5
+ import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
5
6
 
6
7
  export type Role = { address: string; branch: string; agent?: string; purpose?: string; worktree?: string; base?: string };
7
8
  export type Group = { role?: string; members?: string[] };
@@ -129,8 +130,8 @@ export const required = <T>(value: T | undefined, label: string) => {
129
130
  return value;
130
131
  };
131
132
  export const yaml = {
132
- parse: <T>(text: string) => Bun.YAML.parse(text) as T,
133
- print: (value: unknown) => Bun.YAML.stringify(value),
133
+ parse: <T>(text: string) => parseYaml(text) as T,
134
+ print: (value: unknown) => stringifyYaml(value, { collectionStyle: "flow", flowCollectionPadding: false }),
134
135
  };
135
136
 
136
137
  export function addressParts(address: string) {
package/src/threads.ts CHANGED
@@ -84,12 +84,16 @@ function inboxDirectory(root: string, address: string) {
84
84
  }
85
85
 
86
86
  const pause = (milliseconds: number) => new Promise((resolve) => setTimeout(resolve, milliseconds));
87
+ const inboxLockStaleMs = 30_000;
88
+ const inboxLockAcquireTimeoutMs = 5_000;
89
+ const inboxLockRetryMs = 5;
87
90
 
88
91
  /** mkdir is atomic across CLI processes; stale locks are recoverable after a crashed writer. */
89
92
  async function withInboxLock<T>(directory: string, action: () => Promise<T>) {
90
93
  await mkdir(directory, { recursive: true });
91
94
  const lock = join(directory, "queue.lock");
92
- for (let attempt = 0; attempt < 200; attempt += 1) {
95
+ const deadline = Date.now() + inboxLockAcquireTimeoutMs;
96
+ while (Date.now() < deadline) {
93
97
  try {
94
98
  await mkdir(lock, { recursive: false });
95
99
  try { return await action(); }
@@ -97,9 +101,10 @@ async function withInboxLock<T>(directory: string, action: () => Promise<T>) {
97
101
  } catch (error) {
98
102
  if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
99
103
  try {
100
- if (Date.now() - (await stat(lock)).mtimeMs > 30_000) await rm(lock, { recursive: true, force: true });
101
- else await pause(5);
102
- } catch { await pause(5); }
104
+ if (Date.now() - (await stat(lock)).mtimeMs > inboxLockStaleMs) await rm(lock, { recursive: true, force: true });
105
+ } catch { /* A competing release or recovery is retried below. */ }
106
+ const remaining = deadline - Date.now();
107
+ if (remaining > 0) await pause(Math.min(inboxLockRetryMs, remaining));
103
108
  }
104
109
  }
105
110
  throw new Error(`Timed out waiting for inbox queue lock ${directory}`);