@h-rig/runtime 0.0.6-alpha.34 → 0.0.6-alpha.35

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.
@@ -344,11 +344,62 @@ async function materializeSkills(projectRoot, entries) {
344
344
  var MARKER_FILENAME = ".rig-plugin";
345
345
  var init_skill_materializer = () => {};
346
346
 
347
+ // packages/runtime/src/control-plane/pi-settings-materializer.ts
348
+ import { existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
349
+ import { dirname as dirname2, resolve as resolve3 } from "path";
350
+ function readJson(path, fallback) {
351
+ if (!existsSync4(path))
352
+ return fallback;
353
+ try {
354
+ return JSON.parse(readFileSync3(path, "utf-8"));
355
+ } catch {
356
+ return fallback;
357
+ }
358
+ }
359
+ function packageKey(entry) {
360
+ if (typeof entry === "string")
361
+ return entry;
362
+ if (entry && typeof entry === "object" && typeof entry.source === "string") {
363
+ return entry.source;
364
+ }
365
+ return JSON.stringify(entry);
366
+ }
367
+ function materializePiPackages(projectRoot, declaredPackages) {
368
+ const settingsPath = resolve3(projectRoot, SETTINGS_RELATIVE_PATH);
369
+ const managedRecordPath = resolve3(projectRoot, MANAGED_RECORD_RELATIVE_PATH);
370
+ const settings = readJson(settingsPath, {});
371
+ const previouslyManaged = new Set(readJson(managedRecordPath, []));
372
+ const existing = Array.isArray(settings.packages) ? settings.packages : [];
373
+ const operatorEntries = existing.filter((entry) => !previouslyManaged.has(packageKey(entry)));
374
+ const operatorKeys = new Set(operatorEntries.map(packageKey));
375
+ const managedToAdd = declaredPackages.filter((pkg) => !operatorKeys.has(pkg));
376
+ const nextPackages = [...operatorEntries, ...managedToAdd];
377
+ if (nextPackages.length > 0 || existsSync4(settingsPath)) {
378
+ const nextSettings = { ...settings };
379
+ if (nextPackages.length > 0) {
380
+ nextSettings.packages = nextPackages;
381
+ } else {
382
+ delete nextSettings.packages;
383
+ }
384
+ mkdirSync3(dirname2(settingsPath), { recursive: true });
385
+ writeFileSync3(settingsPath, `${JSON.stringify(nextSettings, null, 2)}
386
+ `, "utf-8");
387
+ }
388
+ mkdirSync3(dirname2(managedRecordPath), { recursive: true });
389
+ writeFileSync3(managedRecordPath, `${JSON.stringify(managedToAdd, null, 2)}
390
+ `, "utf-8");
391
+ return { settingsPath, packages: managedToAdd };
392
+ }
393
+ var SETTINGS_RELATIVE_PATH = ".pi/settings.json", MANAGED_RECORD_RELATIVE_PATH = ".rig/state/pi-managed-packages.json";
394
+ var init_pi_settings_materializer = () => {};
395
+
347
396
  // packages/runtime/src/control-plane/plugin-host-context.ts
348
397
  var exports_plugin_host_context = {};
349
398
  __export(exports_plugin_host_context, {
350
399
  buildPluginHostContext: () => buildPluginHostContext
351
400
  });
401
+ import { existsSync as existsSync5 } from "fs";
402
+ import { resolve as resolvePath } from "path";
352
403
  import { createPluginHost } from "@rig/core";
353
404
  import { loadConfig } from "@rig/core/load-config";
354
405
  async function buildPluginHostContext(projectRoot) {
@@ -397,6 +448,14 @@ async function buildPluginHostContext(projectRoot) {
397
448
  } catch (err) {
398
449
  console.warn(`[plugin-host] skill materialization failed: ${err instanceof Error ? err.message : err}`);
399
450
  }
451
+ try {
452
+ const piPackages = config.runtime?.pi?.packages ?? [];
453
+ if (piPackages.length > 0 || existsSync5(resolvePath(projectRoot, ".rig/state/pi-managed-packages.json"))) {
454
+ materializePiPackages(projectRoot, piPackages);
455
+ }
456
+ } catch (err) {
457
+ console.warn(`[plugin-host] Pi package materialization failed: ${err instanceof Error ? err.message : err}`);
458
+ }
400
459
  return {
401
460
  config,
402
461
  pluginHost,
@@ -413,13 +472,14 @@ var init_plugin_host_context = __esm(() => {
413
472
  init_runtime_registration();
414
473
  init_hook_materializer();
415
474
  init_skill_materializer();
475
+ init_pi_settings_materializer();
416
476
  });
417
477
 
418
478
  // packages/runtime/src/control-plane/materialize-task-config.ts
419
- import { existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
420
- import { dirname as dirname2, resolve as resolve3 } from "path";
479
+ import { existsSync as existsSync6, mkdirSync as mkdirSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync4 } from "fs";
480
+ import { dirname as dirname3, resolve as resolve4 } from "path";
421
481
  async function materializePluginHostTaskConfig(projectRoot) {
422
- const hasConfig = existsSync4(resolve3(projectRoot, "rig.config.ts")) || existsSync4(resolve3(projectRoot, "rig.config.json"));
482
+ const hasConfig = existsSync6(resolve4(projectRoot, "rig.config.ts")) || existsSync6(resolve4(projectRoot, "rig.config.json"));
423
483
  if (!hasConfig)
424
484
  return null;
425
485
  const { buildPluginHostContext: buildPluginHostContext2 } = await Promise.resolve().then(() => (init_plugin_host_context(), exports_plugin_host_context));
@@ -439,8 +499,8 @@ async function materializePluginHostTaskConfig(projectRoot) {
439
499
  const tasks = await source.list();
440
500
  if (tasks.length === 0)
441
501
  return null;
442
- const configPath = resolve3(projectRoot, ".rig", "task-config.json");
443
- const existing = existsSync4(configPath) ? safeJsonRead(configPath) : {};
502
+ const configPath = resolve4(projectRoot, ".rig", "task-config.json");
503
+ const existing = existsSync6(configPath) ? safeJsonRead(configPath) : {};
444
504
  const merged = { ...existing };
445
505
  let syncedCount = 0;
446
506
  for (const task of tasks) {
@@ -456,8 +516,8 @@ async function materializePluginHostTaskConfig(projectRoot) {
456
516
  merged[id] = synthesizeEntry(t, ctx.config.taskSource);
457
517
  syncedCount += 1;
458
518
  }
459
- mkdirSync3(dirname2(configPath), { recursive: true });
460
- writeFileSync3(configPath, `${JSON.stringify(merged, null, 2)}
519
+ mkdirSync4(dirname3(configPath), { recursive: true });
520
+ writeFileSync4(configPath, `${JSON.stringify(merged, null, 2)}
461
521
  `, "utf-8");
462
522
  return { configPath, syncedCount };
463
523
  }
@@ -498,7 +558,7 @@ function materializedTaskSource(taskSource) {
498
558
  }
499
559
  function safeJsonRead(path) {
500
560
  try {
501
- const parsed = JSON.parse(readFileSync3(path, "utf-8"));
561
+ const parsed = JSON.parse(readFileSync4(path, "utf-8"));
502
562
  return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
503
563
  } catch {
504
564
  return {};
@@ -1404,6 +1404,16 @@ function resolveTaskMonorepoRoot(projectRoot) {
1404
1404
  return resolveHarnessPaths(projectRoot).monorepoRoot;
1405
1405
  }
1406
1406
  function collectCommittedMonorepoFiles(projectRoot, repo) {
1407
+ const defaultRef = runCapture(["git", "-C", repo, "rev-parse", "--abbrev-ref", "origin/HEAD"], projectRoot);
1408
+ if (defaultRef.exitCode === 0 && defaultRef.stdout.trim()) {
1409
+ const mergeBase = runCapture(["git", "-C", repo, "merge-base", "HEAD", defaultRef.stdout.trim()], projectRoot);
1410
+ if (mergeBase.exitCode === 0 && mergeBase.stdout.trim()) {
1411
+ const result = runCapture(["git", "-C", repo, "diff", "--name-only", `${mergeBase.stdout.trim()}..HEAD`], projectRoot);
1412
+ if (result.exitCode === 0) {
1413
+ return result.stdout.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
1414
+ }
1415
+ }
1416
+ }
1407
1417
  const initialHeadCommit = resolveRuntimeInitialHeadCommit(projectRoot, repo);
1408
1418
  if (initialHeadCommit) {
1409
1419
  const result = runCapture(["git", "-C", repo, "diff", "--name-only", `${initialHeadCommit}..HEAD`], projectRoot);