@atolis-hq/wake 0.3.30 → 0.3.32

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.
@@ -56,7 +56,7 @@ export function createSurfaceWorkApplications(root, now) {
56
56
  const context = commandContext(command.idempotencyKey, now);
57
57
  const correlations = await root.resources.correlationsForWork(id);
58
58
  await root.work.delete(id, context);
59
- await Promise.all(correlations.map((entry) => root.resources.retract(entry.resourceId, id, context)));
59
+ await Promise.all(correlations.map((entry) => root.resources.retract(entry.resourceId, id, resourceRetractionContext(context, entry.resourceId))));
60
60
  return accepted(command.idempotencyKey, now());
61
61
  },
62
62
  async retry(key, command) {
@@ -179,6 +179,9 @@ function commandContext(idempotencyKey, now) {
179
179
  actor: { kind: EventActorKind.Operator, id: 'web' },
180
180
  };
181
181
  }
182
+ function resourceRetractionContext(context, resourceId) {
183
+ return { ...context, commandId: `${context.commandId}:resource:${resourceId}` };
184
+ }
182
185
  function accepted(idempotencyKey, acceptedAt) {
183
186
  return {
184
187
  commandId: `work:${idempotencyKey}`,
@@ -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 = "g629cc1e";
@@ -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.32",
4
4
  "description": "Local autonomous agent control plane for software development",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {