@nowcrew/daemon 0.6.88-beta.14 → 0.6.88-beta.16

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.
Files changed (38) hide show
  1. package/README.md +15 -0
  2. package/dist/daemon-update-eligibility.js +1 -1
  3. package/dist/local-executor.js +4 -2
  4. package/dist/machine-info.js +16 -4
  5. package/dist/main.js +4 -69
  6. package/dist/project-skills/execution-adapter.js +3 -2
  7. package/dist/project-skills/runtime-launch.js +14 -0
  8. package/dist/provider-env.js +3 -4
  9. package/dist/runtimes/deepseek-harness-profile.js +92 -0
  10. package/dist/runtimes/deepseek-harness-runner.js +224 -0
  11. package/dist/runtimes/deepseek-harness.js +61 -10
  12. package/dist/runtimes/kimi-acp-runner.js +5 -5
  13. package/dist/serve.js +14 -62
  14. package/dist/storage-identity.js +0 -3
  15. package/dist/storage-serve-adapter.js +6 -72
  16. package/dist/supervised-runtime.js +17 -2
  17. package/package.json +1 -1
  18. package/dist/daemon-migration-controller.js +0 -211
  19. package/dist/daemon-migration-wiring.js +0 -22
  20. package/dist/storage-control.js +0 -212
  21. package/dist/storage-copy.js +0 -628
  22. package/dist/storage-credential-guard.js +0 -21
  23. package/dist/storage-doctor.js +0 -228
  24. package/dist/storage-manifest.js +0 -1027
  25. package/dist/storage-migration-controller.js +0 -440
  26. package/dist/storage-migration-manifest.js +0 -105
  27. package/dist/storage-migration-policy.js +0 -100
  28. package/dist/storage-runtime-controller.js +0 -381
  29. package/dist/storage-runtime-readiness.js +0 -240
  30. package/dist/storage-safe-fs.js +0 -302
  31. package/dist/storage-status-delivery.js +0 -224
  32. package/dist/storage-status-replay.js +0 -140
  33. package/dist/storage-target-confirmation.js +0 -129
  34. package/dist/storage-worker-command.js +0 -37
  35. package/dist/storage-worker-executor.js +0 -449
  36. package/dist/storage-worker-handoff.js +0 -151
  37. package/dist/storage-worker-operation.js +0 -294
  38. package/dist/storage-worker-status.js +0 -259
@@ -1,228 +0,0 @@
1
- import { constants } from "node:fs";
2
- import { access, lstat, readdir, realpath, statfs } from "node:fs/promises";
3
- import { dirname, isAbsolute, join, relative, resolve } from "node:path";
4
- import { generateStorageManifest, persistStorageManifestChunks, verifyStorageManifestChunkStore, parseStorageManifest, storageManifestDigest, } from "./storage-manifest.js";
5
- import { validateStorageEnvironment } from "./storage-layout.js";
6
- export class StorageDoctorAbortError extends Error {
7
- code = "preflight_aborted";
8
- scannedEntries;
9
- constructor(scannedEntries, cause) {
10
- super("storage doctor preflight was aborted", { cause });
11
- this.name = "StorageDoctorAbortError";
12
- this.scannedEntries = scannedEntries;
13
- }
14
- }
15
- export function discoverLegacyStorageSources(input) {
16
- if (!isAbsolute(input.legacyRoot))
17
- throw new Error("legacy root must be absolute");
18
- for (const value of [input.daemonDirectory, input.agentsDirectory]) {
19
- if (!/^[a-z0-9][a-z0-9_-]{0,127}$/u.test(value))
20
- throw new Error("legacy directory name is invalid");
21
- }
22
- return Object.freeze([
23
- Object.freeze({ kind: "daemon-home", root: join(input.legacyRoot, input.daemonDirectory), logicalPrefix: "daemon" }),
24
- Object.freeze({ kind: "agents-root", root: join(input.legacyRoot, input.agentsDirectory), logicalPrefix: "agent-items" }),
25
- ]);
26
- }
27
- async function nearestExistingAncestor(path) {
28
- let candidate = path;
29
- for (;;) {
30
- try {
31
- await lstat(candidate);
32
- return candidate;
33
- }
34
- catch (error) {
35
- if (error.code !== "ENOENT")
36
- throw error;
37
- }
38
- const parent = dirname(candidate);
39
- if (parent === candidate)
40
- throw new Error("target storage has no existing ancestor");
41
- candidate = parent;
42
- }
43
- }
44
- async function canonicalPotentialPath(path) {
45
- const absolute = resolve(path);
46
- const ancestor = await nearestExistingAncestor(absolute);
47
- const canonicalAncestor = await realpath(ancestor);
48
- return resolve(canonicalAncestor, relative(ancestor, absolute));
49
- }
50
- async function pathsOverlap(left, right) {
51
- const [canonicalLeft, canonicalRight] = await Promise.all([
52
- canonicalPotentialPath(left),
53
- canonicalPotentialPath(right),
54
- ]);
55
- const leftToRight = relative(canonicalLeft, canonicalRight);
56
- const rightToLeft = relative(canonicalRight, canonicalLeft);
57
- const contained = (value) => value === "" || (!value.startsWith("..") && !isAbsolute(value));
58
- return contained(leftToRight) || contained(rightToLeft);
59
- }
60
- async function defaultProbeTarget(targetWorkspaceRoot) {
61
- try {
62
- const ancestor = await nearestExistingAncestor(targetWorkspaceRoot);
63
- await access(ancestor, constants.R_OK | constants.W_OK);
64
- let targetState = "absent";
65
- try {
66
- const target = await lstat(targetWorkspaceRoot);
67
- targetState = target.isDirectory() && (await readdir(targetWorkspaceRoot)).length === 0 ? "empty" : "non_empty";
68
- }
69
- catch (error) {
70
- if (error.code !== "ENOENT")
71
- throw error;
72
- }
73
- const filesystem = await statfs(ancestor, { bigint: true });
74
- const available = filesystem.bavail * filesystem.bsize;
75
- return Object.freeze({
76
- status: "available",
77
- targetState,
78
- availableBytes: available > BigInt(Number.MAX_SAFE_INTEGER) ? Number.MAX_SAFE_INTEGER : Number(available),
79
- writable: true,
80
- // Staging and final roots are siblings on this filesystem. A destructive rename probe belongs
81
- // to the separately approved write preflight, not this read-only doctor.
82
- atomicRenameSupported: true,
83
- });
84
- }
85
- catch (error) {
86
- const code = error.code;
87
- return Object.freeze({
88
- status: code === "EACCES" || code === "EPERM" ? "permission_denied" : "unavailable",
89
- targetState: "absent",
90
- availableBytes: 0,
91
- writable: false,
92
- atomicRenameSupported: false,
93
- });
94
- }
95
- }
96
- const issue = (code, detail) => Object.freeze({ code, detail });
97
- function inspectManifestLinks(manifest) {
98
- const warnings = [];
99
- const blockers = [];
100
- const credentialLinks = manifest.entries.filter((entry) => entry.link?.classification === "external" && entry.reason === "credential_material").length;
101
- const unapprovedLinks = manifest.entries.filter((entry) => entry.link?.classification === "external" && entry.reason !== "credential_material" && entry.reason !== "local_runtime").length;
102
- const brokenLinks = manifest.entries.filter((entry) => entry.link?.classification === "broken").length;
103
- const unsupportedItems = manifest.entries.filter((entry) => entry.type === "unsupported").length;
104
- if (credentialLinks > 0)
105
- warnings.push(issue("credential_link_excluded", `${credentialLinks} credential link(s) excluded from migration`));
106
- if (unapprovedLinks > 0)
107
- blockers.push(issue("external_symlink_unapproved", `${unapprovedLinks} external link(s) require an explicit exclusion or portable mapping`));
108
- if (brokenLinks > 0)
109
- blockers.push(issue("broken_symlink", `${brokenLinks} broken link(s) cannot be migrated safely`));
110
- if (unsupportedItems > 0)
111
- blockers.push(issue("unsupported_file_type", `${unsupportedItems} unsupported filesystem item(s) found`));
112
- if (manifest.summary.transformations > 0) {
113
- warnings.push(issue("target_transformations_required", `${manifest.summary.transformations} target-only transformation(s) must be verified during apply`));
114
- }
115
- return { warnings, blockers };
116
- }
117
- export async function runStorageDoctor(input, dependencies = {}) {
118
- const environment = validateStorageEnvironment(input.environment);
119
- let scannedEntries = 0;
120
- const onProgress = (progress) => {
121
- scannedEntries = progress.scannedEntries;
122
- input.onProgress?.(progress);
123
- };
124
- if (input.signal?.aborted)
125
- throw new StorageDoctorAbortError(scannedEntries);
126
- const manifest = typeof input.manifest === "string"
127
- ? parseStorageManifest(input.manifest)
128
- : input.manifest === undefined
129
- ? await (input.manifestStoreRoot === undefined
130
- ? generateStorageManifest({
131
- migrationId: input.migrationId,
132
- generatedAt: input.generatedAt,
133
- environment,
134
- workspaceId: input.workspaceId,
135
- targetWorkspaceRoot: input.targetWorkspaceRoot,
136
- sources: input.sources,
137
- policy: input.policy,
138
- ...(input.signal === undefined ? {} : { signal: input.signal }),
139
- onProgress,
140
- ...(input.progressIntervalEntries === undefined ? {} : { progressIntervalEntries: input.progressIntervalEntries }),
141
- })
142
- : persistStorageManifestChunks({
143
- migrationId: input.migrationId,
144
- generatedAt: input.generatedAt,
145
- environment,
146
- workspaceId: input.workspaceId,
147
- targetWorkspaceRoot: input.targetWorkspaceRoot,
148
- sources: input.sources,
149
- policy: input.policy,
150
- ...(input.signal === undefined ? {} : { signal: input.signal }),
151
- onProgress,
152
- ...(input.progressIntervalEntries === undefined ? {} : { progressIntervalEntries: input.progressIntervalEntries }),
153
- }, { root: input.manifestStoreRoot })).catch((error) => {
154
- if (error.code === "preflight_aborted") {
155
- throw new StorageDoctorAbortError(scannedEntries, error);
156
- }
157
- throw error;
158
- })
159
- : parseStorageManifest(JSON.stringify(input.manifest));
160
- const target = await (dependencies.probeTarget ?? defaultProbeTarget)(input.targetWorkspaceRoot);
161
- const warnings = [];
162
- const blockers = [];
163
- try {
164
- await verifyStorageManifestChunkStore(manifest);
165
- }
166
- catch (error) {
167
- blockers.push(issue("manifest_chunk_store_invalid", error instanceof Error ? error.message : "manifest chunk store is invalid"));
168
- }
169
- if (manifest.migrationId !== input.migrationId || manifest.workspaceId !== input.workspaceId.toLowerCase()
170
- || manifest.environment !== environment || manifest.targetWorkspaceRoot !== input.targetWorkspaceRoot) {
171
- blockers.push(issue("manifest_identity_mismatch", "manifest identity does not match the requested migration"));
172
- }
173
- if (!input.state.profileIdentityExact)
174
- blockers.push(issue("profile_identity_drift", "profile, service or managed registry identity drifted"));
175
- if ((await Promise.all(input.sources.map((source) => pathsOverlap(source.root, input.targetWorkspaceRoot))))
176
- .some(Boolean)) {
177
- blockers.push(issue("source_target_overlap", "target workspace and source roots must not contain one another"));
178
- }
179
- if (input.state.duplicateWorkspaceMappings > 0)
180
- blockers.push(issue("duplicate_workspace_mapping", "more than one profile maps to this workspace"));
181
- if (input.state.activeAgentExecutions > 0 || input.state.activeScheduledRuns > 0) {
182
- blockers.push(issue("active_execution", "active agent execution or scheduled run must finish before migration"));
183
- }
184
- if (target.status === "unavailable")
185
- blockers.push(issue("target_unavailable", "target storage is unavailable"));
186
- if (target.status === "permission_denied" || !target.writable)
187
- blockers.push(issue("target_permission_denied", "target storage is not writable by the daemon user"));
188
- if (target.targetState === "non_empty")
189
- blockers.push(issue("target_non_empty", "target workspace root is not empty"));
190
- const multiplier = input.freeSpaceMultiplier ?? 1.2;
191
- if (!Number.isFinite(multiplier) || multiplier < 1)
192
- throw new Error("free space multiplier must be at least 1");
193
- const requiredBytes = Math.ceil(manifest.summary.bytesToCopy * multiplier);
194
- if (target.status === "available" && target.availableBytes < requiredBytes) {
195
- blockers.push(issue("insufficient_space", `target requires at least ${requiredBytes} available bytes`));
196
- }
197
- if (!target.atomicRenameSupported)
198
- blockers.push(issue("atomic_rename_unsupported", "target filesystem rename semantics are not verified"));
199
- const links = inspectManifestLinks(manifest);
200
- warnings.push(...links.warnings);
201
- blockers.push(...links.blockers);
202
- if (manifest.chunkStore !== undefined) {
203
- if (manifest.chunkStore.credentialLinks > 0)
204
- warnings.push(issue("credential_link_excluded", `${manifest.chunkStore.credentialLinks} credential link(s) excluded from migration`));
205
- if (manifest.chunkStore.unapprovedLinks > 0)
206
- blockers.push(issue("external_symlink_unapproved", `${manifest.chunkStore.unapprovedLinks} external link(s) require an explicit exclusion or portable mapping`));
207
- if (manifest.chunkStore.brokenLinks > 0)
208
- blockers.push(issue("broken_symlink", `${manifest.chunkStore.brokenLinks} broken link(s) cannot be migrated safely`));
209
- if (manifest.chunkStore.unsupportedItems > 0)
210
- blockers.push(issue("unsupported_file_type", `${manifest.chunkStore.unsupportedItems} unsupported filesystem item(s) found`));
211
- }
212
- const applyAllowed = blockers.length === 0;
213
- const status = !applyAllowed ? "blocked" : warnings.length > 0 ? "warnings" : "safe";
214
- const exitCode = status === "safe" ? 0 : status === "warnings" ? 2 : 3;
215
- return Object.freeze({
216
- status,
217
- exitCode,
218
- applyAllowed,
219
- environment,
220
- workspaceId: input.workspaceId.toLowerCase(),
221
- profile: input.profile,
222
- manifest,
223
- manifestDigest: storageManifestDigest(manifest),
224
- target,
225
- warnings: Object.freeze(warnings),
226
- blockers: Object.freeze(blockers),
227
- });
228
- }