@ricsam/r5d-worker 0.0.12 → 0.0.13

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.
package/dist/cjs/main.cjs CHANGED
@@ -31,6 +31,7 @@ var main_exports = {};
31
31
  __export(main_exports, {
32
32
  ensureVisibleGitCheckout: () => ensureVisibleGitCheckout,
33
33
  isArtifactEnvPath: () => isArtifactEnvPath,
34
+ prepareArtifactEnvForShell: () => prepareArtifactEnvForShell,
34
35
  syncSessionArtifacts: () => syncSessionArtifacts
35
36
  });
36
37
  module.exports = __toCommonJS(main_exports);
@@ -410,6 +411,29 @@ function rejectArtifactWritePath(filePath) {
410
411
  throw new Error(`${R5D_ARTIFACTS_DIR_REF} attachments are read-only. Copy them into a project path before editing or creating files.`);
411
412
  }
412
413
  }
414
+ async function prepareArtifactEnvForShell(input) {
415
+ if (!input.sessionId) {
416
+ return {};
417
+ }
418
+ try {
419
+ await syncSessionArtifacts({
420
+ baseUrl: input.baseUrl,
421
+ token: input.token,
422
+ projectId: input.projectId,
423
+ branchName: input.branchName,
424
+ sessionId: input.sessionId,
425
+ artifactRoot: input.artifactRoot
426
+ });
427
+ } catch (error) {
428
+ process.stderr.write(`[r5d-worker] artifact sync skipped for ${input.sessionId}: ${error instanceof Error ? error.message : String(error)}
429
+ `);
430
+ }
431
+ const artifactsDir = sessionArtifactDir(input.artifactRoot, input.sessionId);
432
+ import_node_fs.default.mkdirSync(artifactsDir, { recursive: true });
433
+ return {
434
+ R5D_ARTIFACTS_DIR: artifactsDir
435
+ };
436
+ }
413
437
  async function verifyR5dctlAuth(baseUrl, token) {
414
438
  const statusUrl = new URL("/api/r5dctl/auth/status", baseUrl);
415
439
  let response;
@@ -1486,18 +1510,14 @@ async function executeCommand(input) {
1486
1510
  branchName: input.message.branchName,
1487
1511
  manifest: input.manifest
1488
1512
  });
1489
- let artifactProcessEnv = {};
1490
- if (input.message.sessionId) {
1491
- await syncSessionArtifacts({
1492
- baseUrl: input.baseUrl,
1493
- token: input.token,
1494
- projectId: input.projectId,
1495
- branchName: input.message.branchName,
1496
- sessionId: input.message.sessionId,
1497
- artifactRoot: input.artifactRoot
1498
- });
1499
- artifactProcessEnv = artifactEnv(input.artifactRoot, input.message.sessionId);
1500
- }
1513
+ const artifactProcessEnv = await prepareArtifactEnvForShell({
1514
+ baseUrl: input.baseUrl,
1515
+ token: input.token,
1516
+ projectId: input.projectId,
1517
+ branchName: input.message.branchName,
1518
+ sessionId: input.message.sessionId,
1519
+ artifactRoot: input.artifactRoot
1520
+ });
1501
1521
  const cwd = resolveCommandCwd(workspace.branchPath, input.message.cwd);
1502
1522
  const subprocess = Bun.spawn(input.message.argv, {
1503
1523
  cwd,
@@ -1571,7 +1591,7 @@ async function executeStreamingCommand(input) {
1571
1591
  branchName: input.message.branchName,
1572
1592
  manifest: input.manifest
1573
1593
  });
1574
- await syncSessionArtifacts({
1594
+ const artifactProcessEnv = await prepareArtifactEnvForShell({
1575
1595
  baseUrl: input.baseUrl,
1576
1596
  token: input.token,
1577
1597
  projectId: input.projectId,
@@ -1579,7 +1599,6 @@ async function executeStreamingCommand(input) {
1579
1599
  sessionId: input.message.sessionId,
1580
1600
  artifactRoot: input.artifactRoot
1581
1601
  });
1582
- const artifactProcessEnv = artifactEnv(input.artifactRoot, input.message.sessionId);
1583
1602
  const cwd = resolveCommandCwd(workspace.branchPath, input.message.cwd);
1584
1603
  const subprocess = Bun.spawn(input.message.argv, {
1585
1604
  cwd,
@@ -2218,5 +2237,6 @@ if (isCliEntrypoint()) {
2218
2237
  0 && (module.exports = {
2219
2238
  ensureVisibleGitCheckout,
2220
2239
  isArtifactEnvPath,
2240
+ prepareArtifactEnvForShell,
2221
2241
  syncSessionArtifacts
2222
2242
  });
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "type": "commonjs"
5
5
  }
package/dist/mjs/main.mjs CHANGED
@@ -374,6 +374,29 @@ function rejectArtifactWritePath(filePath) {
374
374
  throw new Error(`${R5D_ARTIFACTS_DIR_REF} attachments are read-only. Copy them into a project path before editing or creating files.`);
375
375
  }
376
376
  }
377
+ async function prepareArtifactEnvForShell(input) {
378
+ if (!input.sessionId) {
379
+ return {};
380
+ }
381
+ try {
382
+ await syncSessionArtifacts({
383
+ baseUrl: input.baseUrl,
384
+ token: input.token,
385
+ projectId: input.projectId,
386
+ branchName: input.branchName,
387
+ sessionId: input.sessionId,
388
+ artifactRoot: input.artifactRoot
389
+ });
390
+ } catch (error) {
391
+ process.stderr.write(`[r5d-worker] artifact sync skipped for ${input.sessionId}: ${error instanceof Error ? error.message : String(error)}
392
+ `);
393
+ }
394
+ const artifactsDir = sessionArtifactDir(input.artifactRoot, input.sessionId);
395
+ fs.mkdirSync(artifactsDir, { recursive: true });
396
+ return {
397
+ R5D_ARTIFACTS_DIR: artifactsDir
398
+ };
399
+ }
377
400
  async function verifyR5dctlAuth(baseUrl, token) {
378
401
  const statusUrl = new URL("/api/r5dctl/auth/status", baseUrl);
379
402
  let response;
@@ -1450,18 +1473,14 @@ async function executeCommand(input) {
1450
1473
  branchName: input.message.branchName,
1451
1474
  manifest: input.manifest
1452
1475
  });
1453
- let artifactProcessEnv = {};
1454
- if (input.message.sessionId) {
1455
- await syncSessionArtifacts({
1456
- baseUrl: input.baseUrl,
1457
- token: input.token,
1458
- projectId: input.projectId,
1459
- branchName: input.message.branchName,
1460
- sessionId: input.message.sessionId,
1461
- artifactRoot: input.artifactRoot
1462
- });
1463
- artifactProcessEnv = artifactEnv(input.artifactRoot, input.message.sessionId);
1464
- }
1476
+ const artifactProcessEnv = await prepareArtifactEnvForShell({
1477
+ baseUrl: input.baseUrl,
1478
+ token: input.token,
1479
+ projectId: input.projectId,
1480
+ branchName: input.message.branchName,
1481
+ sessionId: input.message.sessionId,
1482
+ artifactRoot: input.artifactRoot
1483
+ });
1465
1484
  const cwd = resolveCommandCwd(workspace.branchPath, input.message.cwd);
1466
1485
  const subprocess = Bun.spawn(input.message.argv, {
1467
1486
  cwd,
@@ -1535,7 +1554,7 @@ async function executeStreamingCommand(input) {
1535
1554
  branchName: input.message.branchName,
1536
1555
  manifest: input.manifest
1537
1556
  });
1538
- await syncSessionArtifacts({
1557
+ const artifactProcessEnv = await prepareArtifactEnvForShell({
1539
1558
  baseUrl: input.baseUrl,
1540
1559
  token: input.token,
1541
1560
  projectId: input.projectId,
@@ -1543,7 +1562,6 @@ async function executeStreamingCommand(input) {
1543
1562
  sessionId: input.message.sessionId,
1544
1563
  artifactRoot: input.artifactRoot
1545
1564
  });
1546
- const artifactProcessEnv = artifactEnv(input.artifactRoot, input.message.sessionId);
1547
1565
  const cwd = resolveCommandCwd(workspace.branchPath, input.message.cwd);
1548
1566
  const subprocess = Bun.spawn(input.message.argv, {
1549
1567
  cwd,
@@ -2181,5 +2199,6 @@ if (isCliEntrypoint()) {
2181
2199
  export {
2182
2200
  ensureVisibleGitCheckout,
2183
2201
  isArtifactEnvPath,
2202
+ prepareArtifactEnvForShell,
2184
2203
  syncSessionArtifacts
2185
2204
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "type": "module"
5
5
  }
@@ -8,6 +8,14 @@ export declare function syncSessionArtifacts(input: {
8
8
  sessionId: string;
9
9
  artifactRoot: string;
10
10
  }): Promise<string>;
11
+ export declare function prepareArtifactEnvForShell(input: {
12
+ baseUrl: string;
13
+ token: string;
14
+ projectId: string;
15
+ branchName: string;
16
+ sessionId?: string;
17
+ artifactRoot: string;
18
+ }): Promise<Record<string, string>>;
11
19
  type GitAuth = {
12
20
  extraHeaderUrl: string;
13
21
  header: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "type": "module",
5
5
  "main": "./dist/cjs/main.cjs",
6
6
  "module": "./dist/mjs/main.mjs",