engineering-memory 1.11.3 → 1.11.5

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.
@@ -92,7 +92,7 @@ export class TaskBranchStore {
92
92
  assertSame(current, requested) {
93
93
  if (current.projectId !== requested.projectId ||
94
94
  current.externalTaskId !== requested.externalTaskId) {
95
- throw new BridgeRecoveryError(`This worktree belongs to task ${current.externalTaskId}. Resume that task, or call task.branch with worktreePath and a branch name for the new task.`, 'task.branch');
95
+ throw new BridgeRecoveryError(`This worktree belongs to task ${current.externalTaskId}. Resume that task, or call task.branch with a new task branch name to allocate a separate worktree.`, 'task.branch');
96
96
  }
97
97
  if (current.branch !== requested.branch) {
98
98
  throw new BridgeRecoveryError(`This task selected ${current.branch ?? 'detached HEAD'}. Return to that branch before continuing.`, 'task.branch');
@@ -0,0 +1,37 @@
1
+ import { join } from 'node:path';
2
+ import { readJson, writeJson } from '../utilities/files.js';
3
+ import { BridgeRecoveryError } from './recovery-error.js';
4
+ export function validWorktreePolicy(value) {
5
+ const p = value;
6
+ return Boolean(p &&
7
+ Number.isSafeInteger(p.version) &&
8
+ p.version >= 1 &&
9
+ Number.isSafeInteger(p.maxWorktrees) &&
10
+ p.maxWorktrees >= 1 &&
11
+ p.maxWorktrees <= 500 &&
12
+ Number.isSafeInteger(p.heartbeatSeconds) &&
13
+ p.heartbeatSeconds >= 5 &&
14
+ p.heartbeatSeconds <= 300 &&
15
+ Number.isSafeInteger(p.inactivitySeconds) &&
16
+ p.inactivitySeconds >= 60 &&
17
+ p.inactivitySeconds <= 86400 &&
18
+ p.inactivitySeconds >= p.heartbeatSeconds * 2);
19
+ }
20
+ export class WorktreePolicyCache {
21
+ stateRoot;
22
+ constructor(stateRoot) {
23
+ this.stateRoot = stateRoot;
24
+ }
25
+ async save(policy) {
26
+ if (!validWorktreePolicy(policy))
27
+ throw new BridgeRecoveryError('The backend returned an invalid worktree policy.', 'worktree.policy');
28
+ await writeJson(join(this.stateRoot, 'worktree-policy.json'), policy, this.stateRoot);
29
+ }
30
+ async read() {
31
+ const value = await readJson(join(this.stateRoot, 'worktree-policy.json'), this.stateRoot);
32
+ if (!validWorktreePolicy(value))
33
+ throw new BridgeRecoveryError('No valid cached worktree policy exists. Read worktree.policy while connected before allocating a worktree.', 'worktree.policy');
34
+ return value;
35
+ }
36
+ }
37
+ //# sourceMappingURL=worktree-policy.js.map