@nowcrew/daemon 0.6.65 → 0.6.66

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 (57) hide show
  1. package/dist/agent-ability/materializer.js +1 -20
  2. package/dist/agent-ability/resolver.js +10 -7
  3. package/dist/agent-ability/runtime.js +0 -3
  4. package/dist/automatic-install-target.js +10 -15
  5. package/dist/computer-cli.js +1 -10
  6. package/dist/computer-service.js +1 -41
  7. package/dist/config.js +0 -44
  8. package/dist/daemon-migration-controller.js +18 -16
  9. package/dist/execution-runner.js +1 -3
  10. package/dist/local-execution-prompt.js +9 -14
  11. package/dist/local-executor.js +3 -56
  12. package/dist/machine-info.js +2 -3
  13. package/dist/main.js +0 -83
  14. package/dist/managed-service-lifecycle.js +2 -47
  15. package/dist/managed-service-startup.js +0 -2
  16. package/dist/profile-layout.js +4 -10
  17. package/dist/project-skills/controller.js +0 -2
  18. package/dist/prompt.js +1 -19
  19. package/dist/runner.js +0 -3
  20. package/dist/runtimes/codex-app-server-runner.js +14 -54
  21. package/dist/runtimes/codex-contract.js +5 -20
  22. package/dist/runtimes/codex.js +0 -4
  23. package/dist/serve.js +3 -68
  24. package/dist/supervised-runtime.js +0 -3
  25. package/dist/workspace.js +1 -24
  26. package/package.json +9 -10
  27. package/dist/local-memory/index-budget.js +0 -74
  28. package/dist/local-memory/pending.js +0 -111
  29. package/dist/local-memory/runtime.js +0 -87
  30. package/dist/local-memory/types.js +0 -1
  31. package/dist/local-memory/write.js +0 -448
  32. package/dist/runtimes/codex-command-safety.js +0 -75
  33. package/dist/runtimes/codex-turn-retry.js +0 -69
  34. package/dist/storage-config.js +0 -175
  35. package/dist/storage-control.js +0 -193
  36. package/dist/storage-copy.js +0 -609
  37. package/dist/storage-credential-guard.js +0 -21
  38. package/dist/storage-doctor.js +0 -228
  39. package/dist/storage-identity.js +0 -29
  40. package/dist/storage-layout.js +0 -143
  41. package/dist/storage-manifest.js +0 -855
  42. package/dist/storage-migration-controller.js +0 -417
  43. package/dist/storage-migration-manifest.js +0 -105
  44. package/dist/storage-migration-policy.js +0 -100
  45. package/dist/storage-runtime-controller.js +0 -339
  46. package/dist/storage-runtime-readiness.js +0 -184
  47. package/dist/storage-runtime.js +0 -39
  48. package/dist/storage-safe-fs.js +0 -302
  49. package/dist/storage-serve-adapter.js +0 -65
  50. package/dist/storage-status-delivery.js +0 -209
  51. package/dist/storage-status-replay.js +0 -125
  52. package/dist/storage-target-confirmation.js +0 -129
  53. package/dist/storage-worker-command.js +0 -27
  54. package/dist/storage-worker-executor.js +0 -384
  55. package/dist/storage-worker-handoff.js +0 -151
  56. package/dist/storage-worker-operation.js +0 -284
  57. package/dist/storage-worker-status.js +0 -105
@@ -1,339 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { dirname, join } from "node:path";
3
- import { z } from "zod";
4
- import { buildServiceSpec } from "./computer-service.js";
5
- import { buildManagedServiceRecord } from "./managed-service-lifecycle.js";
6
- import { createStorageControlController } from "./storage-control.js";
7
- import { runStorageDoctor } from "./storage-doctor.js";
8
- import { storageHelloIdentity } from "./storage-identity.js";
9
- import { storageLayout, validateStorageEnvironment } from "./storage-layout.js";
10
- import { StorageMigrationFailure } from "./storage-migration-controller.js";
11
- import { launchStorageMigrationWorker, writeStorageWorkerHandoff } from "./storage-worker-handoff.js";
12
- import { writeStorageWorkerOperation } from "./storage-worker-operation.js";
13
- import { latestSourceStorageMigrationReceipt, monitorStorageMigrationStatus, storageMigrationStatusReplay, } from "./storage-status-replay.js";
14
- const UUID = z.string().uuid();
15
- function fingerprint(value) {
16
- return `sha256:${createHash("sha256").update(value).digest("hex")}`;
17
- }
18
- function deterministicUuid(value) {
19
- const chars = createHash("sha256").update(value).digest("hex").slice(0, 32).split("");
20
- chars[12] = "4";
21
- chars[16] = ((Number.parseInt(chars[16], 16) & 0x3) | 0x8).toString(16);
22
- const hex = chars.join("");
23
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
24
- }
25
- function storageId(input, workspaceId) {
26
- return `storage_${createHash("sha256").update([
27
- input.serverUrl.replace(/\/+$/u, ""), input.profile, workspaceId, input.nowworkHome,
28
- ].join("\0")).digest("hex").slice(0, 32)}`;
29
- }
30
- function installationBase(input, workspaceId, migrationId, createdAt) {
31
- const layout = storageLayout({
32
- nowworkHome: input.nowworkHome,
33
- environment: input.environment,
34
- workspaceId,
35
- runtimeBase: input.local.runtimeBase,
36
- platform: input.platform,
37
- });
38
- return {
39
- version: 1,
40
- installationId: deterministicUuid(`installation\0${input.serverUrl}\0${input.profile}\0${workspaceId}\0${input.nowworkHome}`),
41
- profile: input.profile,
42
- serverUrl: input.serverUrl,
43
- environment: input.environment,
44
- workspaceId,
45
- storageId: storageId(input, workspaceId),
46
- nowworkHome: input.nowworkHome,
47
- runtimeRoot: layout.runtimeRoot,
48
- credentialRef: `profile:${input.profile}`,
49
- ...(migrationId === undefined ? {} : { storageMigrationId: migrationId }),
50
- createdAt,
51
- updatedAt: createdAt,
52
- };
53
- }
54
- function targetRecord(input, workspaceId, createdAt) {
55
- const layout = storageLayout({
56
- nowworkHome: input.nowworkHome,
57
- environment: input.environment,
58
- workspaceId,
59
- runtimeBase: input.local.runtimeBase,
60
- platform: input.platform,
61
- });
62
- const spec = buildServiceSpec({
63
- platform: input.platform,
64
- profile: input.profile,
65
- userHome: input.userHome,
66
- uid: input.uid,
67
- nodePath: input.sourceRecord.nodePath,
68
- entryPath: input.sourceRecord.entryPath,
69
- profileHome: input.local.configRoot,
70
- ...(input.serviceEnvironment === undefined ? {} : { environment: input.serviceEnvironment }),
71
- });
72
- return buildManagedServiceRecord({
73
- spec,
74
- daemonHome: input.local.configRoot,
75
- agentsRoot: layout.agentItemsRoot,
76
- nodePath: input.sourceRecord.nodePath,
77
- entryPath: input.sourceRecord.entryPath,
78
- packageRoot: input.sourceRecord.packageRoot,
79
- npmPrefix: input.sourceRecord.npmPrefix,
80
- generation: () => deterministicUuid(`service\0${spec.id}\0${workspaceId}`),
81
- now: () => new Date(createdAt),
82
- });
83
- }
84
- export function createStorageMigrationRuntimeController(rawInput, injected = {}) {
85
- const input = {
86
- ...rawInput,
87
- profile: z.string().regex(/^[a-z0-9][a-z0-9_-]{0,47}$/u).parse(rawInput.profile),
88
- serverUrl: z.string().url().parse(rawInput.serverUrl),
89
- environment: validateStorageEnvironment(rawInput.environment),
90
- };
91
- if (input.sourceRecord.profile !== input.profile || input.sourceRecord.platform !== input.platform) {
92
- throw new Error("Storage runtime source service identity does not match profile");
93
- }
94
- const dependencies = {
95
- assertSourceIdentity: async () => undefined,
96
- runDoctor: (doctorInput) => runStorageDoctor(doctorInput),
97
- writeOperation: writeStorageWorkerOperation,
98
- writeHandoff: writeStorageWorkerHandoff,
99
- launchWorker: launchStorageMigrationWorker,
100
- monitorWorker: monitorStorageMigrationStatus,
101
- now: () => new Date(),
102
- ...injected,
103
- };
104
- let workspaceId = null;
105
- let identity;
106
- let gate = null;
107
- let sendStatus = null;
108
- let control = null;
109
- const pendingControlMessages = [];
110
- let drainingPendingControlMessages = false;
111
- const drainPendingControlMessages = () => {
112
- if (control === null || drainingPendingControlMessages || pendingControlMessages.length === 0)
113
- return;
114
- drainingPendingControlMessages = true;
115
- const pending = pendingControlMessages.splice(0);
116
- void (async () => {
117
- for (const message of pending)
118
- await control?.handle(message);
119
- })().catch(() => undefined).finally(() => {
120
- drainingPendingControlMessages = false;
121
- drainPendingControlMessages();
122
- });
123
- };
124
- const doctorInput = async (migrationId) => {
125
- if (workspaceId === null || gate === null)
126
- throw new Error("Storage migration runtime is not attached");
127
- let profileIdentityExact = true;
128
- await dependencies.assertSourceIdentity().catch(() => { profileIdentityExact = false; });
129
- const target = storageLayout({
130
- nowworkHome: input.nowworkHome,
131
- environment: input.environment,
132
- workspaceId,
133
- runtimeBase: input.local.runtimeBase,
134
- platform: input.platform,
135
- });
136
- return {
137
- migrationId,
138
- generatedAt: dependencies.now().toISOString(),
139
- environment: input.environment,
140
- workspaceId,
141
- profile: input.profile,
142
- targetWorkspaceRoot: target.workspaceRoot,
143
- sources: [
144
- { kind: "daemon-home", root: input.sourceRecord.daemonHome, logicalPrefix: "daemon" },
145
- { kind: "agents-root", root: input.sourceRecord.agentsRoot, logicalPrefix: "agent-items" },
146
- ],
147
- policy: input.policy,
148
- manifestStoreRoot: input.local.stateRoot,
149
- state: {
150
- profileIdentityExact,
151
- duplicateWorkspaceMappings: input.duplicateWorkspaceMappings ?? 0,
152
- activeAgentExecutions: gate.isBusy() ? 1 : 0,
153
- activeScheduledRuns: 0,
154
- },
155
- freeSpaceMultiplier: 1.2,
156
- };
157
- };
158
- const buildOperation = (doctor, freshInput) => {
159
- if (workspaceId === null)
160
- throw new Error("Storage migration workspace identity is missing");
161
- const createdAt = freshInput.generatedAt;
162
- const target = storageLayout({
163
- nowworkHome: input.nowworkHome,
164
- environment: input.environment,
165
- workspaceId,
166
- runtimeBase: input.local.runtimeBase,
167
- platform: input.platform,
168
- });
169
- const { freeSpaceMultiplier, ...doctorBase } = freshInput;
170
- const operationDoctorInput = {
171
- ...doctorBase,
172
- sources: freshInput.sources.map((source) => ({ ...source })),
173
- policy: {
174
- exclusions: freshInput.policy.exclusions.map((exclusion) => ({ ...exclusion })),
175
- transformations: freshInput.policy.transformations.map((transformation) => ({ ...transformation })),
176
- },
177
- ...(freeSpaceMultiplier === undefined ? {} : { freeSpaceMultiplier }),
178
- };
179
- return {
180
- version: 1,
181
- migrationId: doctor.manifest.migrationId,
182
- createdAt,
183
- environment: input.environment,
184
- workspaceId,
185
- profile: input.profile,
186
- expectedManifestDigest: doctor.manifestDigest,
187
- doctorInput: operationDoctorInput,
188
- migration: {
189
- sourceRoots: {
190
- "daemon-home": input.sourceRecord.daemonHome,
191
- "agents-root": input.sourceRecord.agentsRoot,
192
- },
193
- stagingWorkspaceRoot: join(dirname(target.workspaceRoot), `.nowwork-staging-${doctor.manifest.migrationId}`),
194
- targetWorkspaceRoot: target.workspaceRoot,
195
- backupsRoot: input.local.backupsRoot,
196
- backupArtifacts: input.backupArtifacts.map((artifact) => ({ ...artifact })),
197
- acceptedWarnings: [...input.policy.acceptedWarnings],
198
- },
199
- service: {
200
- platform: input.platform,
201
- userHome: input.userHome,
202
- ...(input.uid === undefined ? {} : { uid: input.uid }),
203
- ...(input.serviceEnvironment === undefined ? {} : { serviceEnvironment: input.serviceEnvironment }),
204
- sourceWasRunning: true,
205
- sourceRecord: input.sourceRecord,
206
- targetRecord: targetRecord(input, workspaceId, createdAt),
207
- },
208
- installation: {
209
- configRoot: input.local.configRoot,
210
- target: {
211
- ...installationBase(input, workspaceId, doctor.manifest.migrationId, createdAt),
212
- storageMigrationId: doctor.manifest.migrationId,
213
- },
214
- },
215
- };
216
- };
217
- const ensureControl = () => {
218
- if (control !== null || workspaceId === null || gate === null || sendStatus === null || identity === undefined)
219
- return;
220
- const sourceStorageFingerprint = fingerprint(JSON.stringify({
221
- profile: input.profile,
222
- daemonHome: input.sourceRecord.daemonHome,
223
- agentsRoot: input.sourceRecord.agentsRoot,
224
- serviceId: input.sourceRecord.serviceId,
225
- }));
226
- control = createStorageControlController({
227
- environment: input.environment,
228
- workspaceId,
229
- profile: input.profile,
230
- sourceStorageFingerprint,
231
- targetStorageFingerprint: identity.storageIdFingerprint,
232
- runDoctor: async (migrationId) => dependencies.runDoctor(await doctorInput(migrationId)),
233
- runMigration: async (doctor) => {
234
- await gate.closeAndFlush();
235
- let workerLaunched = false;
236
- try {
237
- const freshInput = await doctorInput(doctor.manifest.migrationId);
238
- const freshDoctor = await dependencies.runDoctor(freshInput);
239
- if (!freshDoctor.applyAllowed || freshDoctor.manifestDigest !== doctor.manifestDigest) {
240
- throw new StorageMigrationFailure("source_changed_after_preflight", "source data or doctor gates changed after server preflight");
241
- }
242
- const operation = buildOperation(freshDoctor, freshInput);
243
- const written = await dependencies.writeOperation(operation, { stateRoot: input.local.stateRoot });
244
- const handoffPath = await dependencies.writeHandoff({
245
- version: 1,
246
- migrationId: operation.migrationId,
247
- profile: operation.profile,
248
- operationPath: written.path,
249
- operationSha256: written.sha256,
250
- }, { stateRoot: input.local.stateRoot });
251
- await dependencies.launchWorker({
252
- entryPath: input.sourceRecord.entryPath,
253
- handoffPath,
254
- migrationId: operation.migrationId,
255
- platform: input.platform,
256
- userHome: input.userHome,
257
- ...(input.uid === undefined ? {} : { uid: input.uid }),
258
- });
259
- workerLaunched = true;
260
- const outcome = await dependencies.monitorWorker({
261
- stateRoot: input.local.stateRoot,
262
- backupsRoot: input.local.backupsRoot,
263
- migrationId: operation.migrationId,
264
- environment: operation.environment,
265
- workspaceId: operation.workspaceId,
266
- profile: operation.profile,
267
- }, sendStatus);
268
- if (outcome.reopenAdmission)
269
- gate.reopen();
270
- }
271
- catch (error) {
272
- if (!workerLaunched) {
273
- gate.reopen();
274
- const failure = error instanceof Error ? error : new Error(String(error));
275
- throw Object.assign(new Error(failure.message, { cause: failure }), {
276
- code: error.code,
277
- reopenAdmission: true,
278
- });
279
- }
280
- throw error;
281
- }
282
- },
283
- sendStatus,
284
- });
285
- };
286
- const bindServerIdentity = (server) => {
287
- const nextWorkspaceId = UUID.parse(server.workspaceId).toLowerCase();
288
- if (workspaceId !== null && workspaceId !== nextWorkspaceId) {
289
- throw new Error("Storage migration server workspace identity changed");
290
- }
291
- workspaceId = nextWorkspaceId;
292
- const createdAt = dependencies.now().toISOString();
293
- const installation = installationBase(input, workspaceId, undefined, createdAt);
294
- const layout = storageLayout({
295
- nowworkHome: input.nowworkHome,
296
- environment: input.environment,
297
- workspaceId,
298
- runtimeBase: input.local.runtimeBase,
299
- platform: input.platform,
300
- });
301
- identity = storageHelloIdentity({ installation, layout });
302
- ensureControl();
303
- drainPendingControlMessages();
304
- };
305
- const attach = (runtime) => {
306
- gate = runtime.gate;
307
- sendStatus = runtime.sendStatus;
308
- ensureControl();
309
- drainPendingControlMessages();
310
- };
311
- const replayStatus = async (send) => {
312
- const receipt = await latestSourceStorageMigrationReceipt(input.local.backupsRoot, {
313
- environment: input.environment,
314
- profile: input.profile,
315
- });
316
- if (receipt === null)
317
- return;
318
- for (const frame of storageMigrationStatusReplay(receipt))
319
- send(frame);
320
- };
321
- return Object.freeze({
322
- statusOutboxPath: join(input.local.stateRoot, "storage-status-outbox.json"),
323
- identity: () => identity,
324
- bindServerIdentity,
325
- attach,
326
- replayStatus,
327
- controller: Object.freeze({
328
- handle: (raw) => {
329
- if (control !== null && !drainingPendingControlMessages)
330
- return control.handle(raw);
331
- if (pendingControlMessages.length >= 16)
332
- return Promise.resolve(false);
333
- pendingControlMessages.push(raw);
334
- drainPendingControlMessages();
335
- return Promise.resolve(true);
336
- },
337
- }),
338
- });
339
- }
@@ -1,184 +0,0 @@
1
- import { realpathSync } from "node:fs";
2
- import { isAbsolute, resolve } from "node:path";
3
- import { z } from "zod";
4
- import { buildServiceSpec } from "./computer-service.js";
5
- import { profilePath } from "./computer-profile.js";
6
- import { assertManagedServiceIdentity } from "./managed-service-lifecycle.js";
7
- import { managedServiceRegistryPath, readManagedServiceRegistry, } from "./managed-service-registry.js";
8
- import { resolveLocalStorageRoots } from "./storage-config.js";
9
- import { readStorageMigrationPolicy } from "./storage-migration-policy.js";
10
- import { createStorageMigrationRuntimeController, } from "./storage-runtime-controller.js";
11
- import { resolveEnvTag, resolveNowworkHome } from "./storage-layout.js";
12
- const notReady = (reason) => Object.freeze({ ready: false, reason });
13
- function canonicalPath(value) {
14
- const absolute = resolve(value);
15
- try {
16
- return realpathSync.native(absolute);
17
- }
18
- catch (error) {
19
- const code = error.code;
20
- if (code === "ENOTDIR")
21
- return absolute;
22
- if (code !== "ENOENT")
23
- throw error;
24
- }
25
- const missing = [];
26
- let ancestor = absolute;
27
- for (;;) {
28
- const parent = resolve(ancestor, "..");
29
- if (parent === ancestor)
30
- return absolute;
31
- missing.unshift(ancestor.slice(parent.length + (parent.endsWith("/") ? 0 : 1)));
32
- ancestor = parent;
33
- try {
34
- return resolve(realpathSync.native(ancestor), ...missing);
35
- }
36
- catch (error) {
37
- const code = error.code;
38
- if (code === "ENOTDIR")
39
- return absolute;
40
- if (code !== "ENOENT")
41
- throw error;
42
- }
43
- }
44
- }
45
- const samePath = (left, right) => canonicalPath(left) === canonicalPath(right);
46
- function environmentMatchesServer(serverUrl, environment) {
47
- const hostname = new URL(serverUrl).hostname.toLowerCase();
48
- if (hostname === "nowwork-dev.nowcoder.com")
49
- return environment === "dev";
50
- if (hostname === "nowwork-in.nowcoder.com")
51
- return environment === "production";
52
- return true;
53
- }
54
- function findSourceRecord(records, input) {
55
- const matches = records.filter((record) => record.profile === input.profile
56
- && samePath(record.daemonHome, input.currentDaemonHome)
57
- && samePath(record.agentsRoot, input.currentAgentsRoot));
58
- return matches.length === 1 ? matches[0] : null;
59
- }
60
- export async function probeStorageMigrationRuntime(rawInput, injected = {}) {
61
- if (rawInput.platform !== "darwin" && rawInput.platform !== "linux") {
62
- return notReady("platform_not_supported");
63
- }
64
- if (rawInput.platform === "darwin" && rawInput.uid === undefined) {
65
- return notReady("platform_identity_missing");
66
- }
67
- const configuredNowworkHome = rawInput.environment.NOWWORK_HOME;
68
- if (configuredNowworkHome === undefined)
69
- return notReady("nowwork_home_missing");
70
- const input = {
71
- ...rawInput,
72
- profile: z.string().regex(/^[a-z0-9][a-z0-9_-]{0,47}$/u).parse(rawInput.profile),
73
- serverUrl: z.string().url().parse(rawInput.serverUrl),
74
- platform: rawInput.platform,
75
- };
76
- let nowworkHome;
77
- let environment;
78
- try {
79
- const home = resolveNowworkHome({
80
- environment: configuredNowworkHome,
81
- userHome: input.userHome,
82
- platform: input.platform,
83
- });
84
- if (home.mode !== "standard")
85
- return notReady("nowwork_home_missing");
86
- nowworkHome = home.root;
87
- environment = resolveEnvTag({
88
- ...(input.environment.NOWWORK_ENV_TAG === undefined
89
- ? {}
90
- : { environment: input.environment.NOWWORK_ENV_TAG }),
91
- }).environment;
92
- }
93
- catch {
94
- return notReady("storage_environment_invalid");
95
- }
96
- if (!environmentMatchesServer(input.serverUrl, environment)) {
97
- return notReady("environment_server_mismatch");
98
- }
99
- const policyPath = input.environment.NOWWORK_STORAGE_POLICY_PATH;
100
- if (policyPath === undefined)
101
- return notReady("migration_policy_missing");
102
- if (!isAbsolute(policyPath) || /[\0\r\n]/u.test(policyPath))
103
- return notReady("migration_policy_invalid");
104
- const dependencies = {
105
- readManagedServices: readManagedServiceRegistry,
106
- assertManagedServiceIdentity,
107
- readPolicy: readStorageMigrationPolicy,
108
- createController: createStorageMigrationRuntimeController,
109
- ...injected,
110
- };
111
- let sourceRecord;
112
- try {
113
- const records = await dependencies.readManagedServices({ userHome: input.userHome });
114
- const found = findSourceRecord(records, input);
115
- if (found === null)
116
- return notReady("source_service_record_missing");
117
- sourceRecord = found;
118
- }
119
- catch {
120
- return notReady("source_service_registry_invalid");
121
- }
122
- const sourceSpec = buildServiceSpec({
123
- platform: input.platform,
124
- profile: input.profile,
125
- userHome: input.userHome,
126
- uid: input.uid,
127
- nodePath: sourceRecord.nodePath,
128
- entryPath: sourceRecord.entryPath,
129
- profileHome: input.currentDaemonHome,
130
- environment: input.environment,
131
- });
132
- const assertSourceIdentity = () => dependencies.assertManagedServiceIdentity({
133
- spec: sourceSpec,
134
- record: sourceRecord,
135
- registry: { userHome: input.userHome },
136
- });
137
- try {
138
- await assertSourceIdentity();
139
- }
140
- catch {
141
- return notReady("source_service_identity_drift");
142
- }
143
- let policy;
144
- try {
145
- policy = await dependencies.readPolicy(policyPath, {
146
- profile: input.profile,
147
- environment,
148
- nowworkHome,
149
- sourceDaemonHome: sourceRecord.daemonHome,
150
- sourceAgentsRoot: sourceRecord.agentsRoot,
151
- });
152
- }
153
- catch {
154
- return notReady("migration_policy_invalid");
155
- }
156
- const local = resolveLocalStorageRoots({
157
- platform: input.platform,
158
- userHome: input.userHome,
159
- environment: input.environment,
160
- });
161
- const runtime = dependencies.createController({
162
- profile: input.profile,
163
- serverUrl: input.serverUrl,
164
- environment,
165
- nowworkHome,
166
- userHome: input.userHome,
167
- platform: input.platform,
168
- ...(input.uid === undefined ? {} : { uid: input.uid }),
169
- sourceRecord,
170
- local,
171
- policy,
172
- serviceEnvironment: {
173
- NOWWORK_HOME: nowworkHome,
174
- NOWWORK_ENV_TAG: environment,
175
- NOWWORK_STORAGE_POLICY_PATH: policyPath,
176
- },
177
- backupArtifacts: [
178
- { name: "profile.json", path: profilePath(input.profile, input.currentDaemonHome) },
179
- { name: "service-descriptor", path: sourceRecord.descriptorPath },
180
- { name: "managed-service-registry.json", path: managedServiceRegistryPath(input.userHome) },
181
- ],
182
- }, { assertSourceIdentity });
183
- return Object.freeze({ ready: true, runtime });
184
- }
@@ -1,39 +0,0 @@
1
- import { findInstallationForProfile, readInstallations, resolveLocalStorageRoots, } from "./storage-config.js";
2
- import { storageHelloIdentity } from "./storage-identity.js";
3
- import { storageLayout } from "./storage-layout.js";
4
- const canonicalServerUrl = (value) => value.replace(/\/+$/u, "");
5
- export function resolveStorageRuntime(input) {
6
- const installation = findInstallationForProfile(input.records, input.profile);
7
- if (installation === null)
8
- return null;
9
- if (canonicalServerUrl(installation.serverUrl) !== canonicalServerUrl(input.serverUrl)) {
10
- throw new Error("installation server identity does not match the active profile");
11
- }
12
- const local = resolveLocalStorageRoots({
13
- platform: input.platform,
14
- userHome: input.userHome,
15
- environment: input.environment,
16
- });
17
- const layout = storageLayout({
18
- nowworkHome: installation.nowworkHome,
19
- environment: installation.environment,
20
- workspaceId: installation.workspaceId,
21
- runtimeBase: local.runtimeBase,
22
- platform: input.platform,
23
- });
24
- return Object.freeze({
25
- installation,
26
- layout,
27
- identity: storageHelloIdentity({ installation, layout }),
28
- local,
29
- });
30
- }
31
- export async function loadStorageRuntime(input) {
32
- const local = resolveLocalStorageRoots({
33
- platform: input.platform,
34
- userHome: input.userHome,
35
- environment: input.environment,
36
- });
37
- const records = await readInstallations({ configRoot: local.configRoot });
38
- return resolveStorageRuntime({ ...input, records });
39
- }