@nowcrew/daemon 0.6.2 → 0.6.3
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.
|
@@ -8,7 +8,7 @@ import { abilityWorkspaceProjectionPath, DaemonAbilityLockSchema, DaemonAbilityM
|
|
|
8
8
|
import { loadAgentAbilityRuntimeContext } from "./runtime-context.js";
|
|
9
9
|
import { parseSkillFrontmatter } from "../skill-frontmatter.js";
|
|
10
10
|
import { isProjectSkillName, MAX_PROJECT_SKILL_DESCRIPTION_LENGTH, MAX_PROJECT_SKILL_FILE_BYTES, } from "../project-skills/types.js";
|
|
11
|
-
import { createAgentProjectionCoordinator, } from "../project-skills/agent-projection-coordinator.js";
|
|
11
|
+
import { createAgentProjectionCoordinator, runtimeProjectionLifetime, } from "../project-skills/agent-projection-coordinator.js";
|
|
12
12
|
const exists = (path) => lstat(path).then(() => true, () => false);
|
|
13
13
|
const repositoryKey = (url) => createHash("sha256").update(url).digest("hex");
|
|
14
14
|
const posixPath = (value) => value.split(sep).join("/");
|
|
@@ -372,8 +372,10 @@ export function createAgentAbilityMaterializer(expectedAgentsRoot, coordinator =
|
|
|
372
372
|
}
|
|
373
373
|
});
|
|
374
374
|
},
|
|
375
|
-
|
|
376
|
-
|
|
375
|
+
prepareAndLaunch(agentsRoot, handle, ability, launch) {
|
|
376
|
+
if (agentsRoot !== expectedAgentsRoot)
|
|
377
|
+
return Promise.reject(new Error("ability_agents_root_mismatch"));
|
|
378
|
+
return coordinator.runExclusiveUntil(expectedAgentsRoot, handle, async () => {
|
|
377
379
|
const started = Date.now();
|
|
378
380
|
try {
|
|
379
381
|
const trainingRoot = await apply(agentsRoot, handle, ability).then(() => join(agentsRoot, handle, "training"));
|
|
@@ -392,7 +394,7 @@ export function createAgentAbilityMaterializer(expectedAgentsRoot, coordinator =
|
|
|
392
394
|
});
|
|
393
395
|
throw error;
|
|
394
396
|
}
|
|
395
|
-
});
|
|
397
|
+
}, runtimeProjectionLifetime);
|
|
396
398
|
},
|
|
397
399
|
};
|
|
398
400
|
}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
2
|
import { createKeyedPromiseTail } from "../promise-tail.js";
|
|
3
|
+
export const runtimeProjectionLifetime = (value) => {
|
|
4
|
+
if (typeof value !== "object" || value === null || !("exit" in value))
|
|
5
|
+
return Promise.resolve();
|
|
6
|
+
const exit = value.exit;
|
|
7
|
+
return exit instanceof Promise ? exit.catch(() => undefined) : Promise.resolve();
|
|
8
|
+
};
|
|
3
9
|
export function createAgentProjectionCoordinator() {
|
|
4
10
|
const tails = createKeyedPromiseTail();
|
|
5
11
|
const heldKeys = new AsyncLocalStorage();
|
|
@@ -11,5 +17,30 @@ export function createAgentProjectionCoordinator() {
|
|
|
11
17
|
return operation();
|
|
12
18
|
return tails.enqueue(key, () => heldKeys.run(new Set([...(held ?? []), key]), operation));
|
|
13
19
|
},
|
|
20
|
+
runExclusiveUntil(agentsRoot, handle, operation, releaseWhen) {
|
|
21
|
+
const key = JSON.stringify([agentsRoot, handle]);
|
|
22
|
+
const held = heldKeys.getStore();
|
|
23
|
+
if (held?.has(key))
|
|
24
|
+
return operation();
|
|
25
|
+
let resolveStarted;
|
|
26
|
+
let rejectStarted;
|
|
27
|
+
const started = new Promise((resolve, reject) => {
|
|
28
|
+
resolveStarted = resolve;
|
|
29
|
+
rejectStarted = reject;
|
|
30
|
+
});
|
|
31
|
+
void tails.enqueue(key, () => heldKeys.run(new Set([...(held ?? []), key]), async () => {
|
|
32
|
+
let value;
|
|
33
|
+
try {
|
|
34
|
+
value = await operation();
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
rejectStarted(error);
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
resolveStarted(value);
|
|
41
|
+
await releaseWhen(value);
|
|
42
|
+
})).catch(() => { });
|
|
43
|
+
return started;
|
|
44
|
+
},
|
|
14
45
|
};
|
|
15
46
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { cp, lstat, mkdir, readdir, readlink, rename, rm, stat, symlink, writeFile } from "node:fs/promises";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { dirname, join, resolve, sep } from "node:path";
|
|
4
|
+
import { runtimeProjectionLifetime, } from "./agent-projection-coordinator.js";
|
|
4
5
|
export class ProjectProjectionError extends Error {
|
|
5
6
|
code;
|
|
6
7
|
constructor(code) {
|
|
@@ -135,10 +136,10 @@ export function createProjectSkillsReconciler(deps) {
|
|
|
135
136
|
if (agentsRoot !== deps.agentsRoot) {
|
|
136
137
|
return Promise.reject(new ProjectProjectionError("skill_projection_failed"));
|
|
137
138
|
}
|
|
138
|
-
return deps.coordinator.
|
|
139
|
+
return deps.coordinator.runExclusiveUntil(deps.agentsRoot, handle, async () => {
|
|
139
140
|
await reconcileUnlocked(handle, bindings);
|
|
140
141
|
return launch();
|
|
141
|
-
});
|
|
142
|
+
}, runtimeProjectionLifetime);
|
|
142
143
|
},
|
|
143
144
|
};
|
|
144
145
|
}
|