@atolis-hq/wake 0.3.30 → 0.3.31

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.
@@ -108,4 +108,4 @@ export function resolveWakeVersion(options = {}) {
108
108
  return `g${headHash.slice(0, 7)}`;
109
109
  return '0.1.0-dev';
110
110
  }
111
- export const wakeVersion = "ga9fe8dd";
111
+ export const wakeVersion = "gd4d5a60";
@@ -3,6 +3,7 @@ import { join } from 'node:path';
3
3
  import { atomicJson, encode } from './file-projection-store.js';
4
4
  export class FileCheckpointStore {
5
5
  root;
6
+ mutations = new Map();
6
7
  constructor(root) {
7
8
  this.root = root;
8
9
  }
@@ -22,12 +23,26 @@ export class FileCheckpointStore {
22
23
  }
23
24
  }
24
25
  async save(consumer, globalPosition) {
25
- if (globalPosition < (await this.load(consumer)))
26
- throw new Error(`Checkpoint regression for ${consumer}`);
27
- await atomicJson(this.path(consumer), { consumer, globalPosition });
26
+ await this.mutate(consumer, async () => {
27
+ if (globalPosition < (await this.load(consumer)))
28
+ throw new Error(`Checkpoint regression for ${consumer}`);
29
+ await atomicJson(this.path(consumer), { consumer, globalPosition });
30
+ });
28
31
  }
29
32
  async reset(consumer) {
30
- await rm(this.path(consumer), { force: true });
33
+ await this.mutate(consumer, () => rm(this.path(consumer), { force: true }));
34
+ }
35
+ async mutate(consumer, operation) {
36
+ const prior = this.mutations.get(consumer) ?? Promise.resolve();
37
+ const current = prior.catch(() => undefined).then(operation);
38
+ this.mutations.set(consumer, current);
39
+ try {
40
+ return await current;
41
+ }
42
+ finally {
43
+ if (this.mutations.get(consumer) === current)
44
+ this.mutations.delete(consumer);
45
+ }
31
46
  }
32
47
  path(consumer) {
33
48
  return join(this.root, 'checkpoints', `${encode(consumer)}.json`);
@@ -1,3 +1,4 @@
1
+ import { randomUUID } from 'node:crypto';
1
2
  import { mkdir, open, readFile, readdir, rename, rm } from 'node:fs/promises';
2
3
  import { dirname, join } from 'node:path';
3
4
  export class FileProjectionStore {
@@ -46,7 +47,7 @@ export function encode(value) {
46
47
  }
47
48
  export async function atomicJson(path, value) {
48
49
  await mkdir(dirname(path), { recursive: true });
49
- const temporary = `${path}.${process.pid}.${Date.now()}.tmp`;
50
+ const temporary = `${path}.${process.pid}.${Date.now()}.${randomUUID()}.tmp`;
50
51
  try {
51
52
  const handle = await open(temporary, 'wx');
52
53
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/wake",
3
- "version": "0.3.30",
3
+ "version": "0.3.31",
4
4
  "description": "Local autonomous agent control plane for software development",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {