minimal-forge-work-pack-sync 0.1.5 → 0.1.6

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 (2) hide show
  1. package/dist/index.js +67 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10582,7 +10582,7 @@ var DEFAULT_DEBUG_TRACE_LIMITS = {
10582
10582
  };
10583
10583
 
10584
10584
  // packages/shared/src/contracts/settings.ts
10585
- var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.5";
10585
+ var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.6";
10586
10586
  var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
10587
10587
  var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
10588
10588
 
@@ -10593,13 +10593,12 @@ async function reconcileWorkPacks(input) {
10593
10593
  const outcomes = [];
10594
10594
  let desiredFailed = false;
10595
10595
  let uncertain = false;
10596
- const orderedDesired = [
10597
- ...input.desired.filter((pack) => !pack.enabled),
10598
- ...input.desired.filter((pack) => pack.enabled)
10599
- ];
10600
- for (const pack of orderedDesired) {
10596
+ const desiredSlugs = new Set(input.desired.map((pack) => pack.slug));
10597
+ const omittedManaged = input.managed.filter((pack) => !desiredSlugs.has(pack.slug));
10598
+ const earlyPrunedSlugs = /* @__PURE__ */ new Set();
10599
+ for (const pack of input.desired.filter((candidate) => !candidate.enabled)) {
10601
10600
  const operation = {
10602
- action: pack.enabled ? "install" : "remove",
10601
+ action: "remove",
10603
10602
  reason: "desired",
10604
10603
  pack
10605
10604
  };
@@ -10611,6 +10610,36 @@ async function reconcileWorkPacks(input) {
10611
10610
  break;
10612
10611
  }
10613
10612
  }
10613
+ for (const pack of input.desired.filter((candidate) => candidate.enabled)) {
10614
+ if (uncertain) break;
10615
+ const operation = { action: "install", reason: "desired", pack };
10616
+ let outcome = await runOperation(operation, input.operate);
10617
+ if (input.desiredIsComplete && outcome.status === "failed" && outcome.code === "projection-conflict") {
10618
+ const blockers = omittedProjectionOwners(omittedManaged, outcome.projectionConflict).filter((managed) => !earlyPrunedSlugs.has(managed.slug));
10619
+ let blockersRemoved = blockers.length === 1;
10620
+ for (const managed of blockersRemoved ? blockers : []) {
10621
+ const removal = await runOperation(
10622
+ { action: "remove", reason: "omitted", pack: { ...managed, enabled: false } },
10623
+ input.operate
10624
+ );
10625
+ outcomes.push(removal);
10626
+ if (removal.status === "failed") {
10627
+ blockersRemoved = false;
10628
+ continue;
10629
+ }
10630
+ if (removal.status === "recovery-uncertain") {
10631
+ uncertain = true;
10632
+ blockersRemoved = false;
10633
+ break;
10634
+ }
10635
+ earlyPrunedSlugs.add(managed.slug);
10636
+ }
10637
+ if (blockersRemoved) outcome = await runOperation(operation, input.operate);
10638
+ }
10639
+ outcomes.push(outcome);
10640
+ if (outcome.status === "failed") desiredFailed = true;
10641
+ if (outcome.status === "recovery-uncertain") uncertain = true;
10642
+ }
10614
10643
  let omissionPrune = "not-requested";
10615
10644
  if (input.desiredIsComplete) {
10616
10645
  if (uncertain) {
@@ -10619,9 +10648,8 @@ async function reconcileWorkPacks(input) {
10619
10648
  omissionPrune = "suppressed-after-desired-failure";
10620
10649
  } else {
10621
10650
  omissionPrune = "completed";
10622
- const desiredSlugs = new Set(input.desired.map((pack) => pack.slug));
10623
10651
  for (const managed of input.managed) {
10624
- if (desiredSlugs.has(managed.slug)) continue;
10652
+ if (desiredSlugs.has(managed.slug) || earlyPrunedSlugs.has(managed.slug)) continue;
10625
10653
  const outcome = await runOperation(
10626
10654
  {
10627
10655
  action: "remove",
@@ -10670,6 +10698,11 @@ async function reconcileWorkPacks(input) {
10670
10698
  receipt
10671
10699
  };
10672
10700
  }
10701
+ function omittedProjectionOwners(omitted, conflict) {
10702
+ if (!conflict) return [];
10703
+ const field = conflict.kind === "agent" ? "agents" : "commands";
10704
+ return omitted.filter((pack) => pack[field]?.includes(conflict.filename));
10705
+ }
10673
10706
  async function runOperation(operation, operate) {
10674
10707
  let result;
10675
10708
  try {
@@ -10683,6 +10716,7 @@ async function runOperation(operation, operate) {
10683
10716
  ...outcomeIdentity(operation),
10684
10717
  status: "failed",
10685
10718
  code: stableCode(result.code),
10719
+ ...result.projectionConflict ? { projectionConflict: result.projectionConflict } : {},
10686
10720
  message: `O pacote "${operation.pack.slug}" falhou, mas o estado anterior foi restaurado exatamente. Corrija a causa indicada e volte a sincronizar.`
10687
10721
  };
10688
10722
  }
@@ -10772,7 +10806,9 @@ async function applyWorkPackManifest(paths, credentials, manifest, options) {
10772
10806
  const cleanupPendingSlugs = await recoverInterruptedWorkPackInstalls(paths, options.cleanupWorkPackBackup);
10773
10807
  const managed = await Promise.all((await managedWorkPackSlugs(paths.skillsDir)).map(async (slug) => ({
10774
10808
  slug,
10775
- version: (await readFile(path2.join(paths.skillsDir, slug, ".forge-version"), "utf8")).trim()
10809
+ version: (await readFile(path2.join(paths.skillsDir, slug, ".forge-version"), "utf8")).trim(),
10810
+ agents: await readAgentRecord(path2.join(paths.skillsDir, slug)),
10811
+ commands: await readCommandRecord(path2.join(paths.skillsDir, slug))
10776
10812
  })));
10777
10813
  const desired = manifest.skills.map((skill) => ({
10778
10814
  slug: skill.slug,
@@ -10864,10 +10900,28 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
10864
10900
  }
10865
10901
  }
10866
10902
  function exactPackFailure(error) {
10903
+ if (error instanceof WorkPackProjectionConflictError) {
10904
+ return {
10905
+ status: "failed",
10906
+ restoration: "exact",
10907
+ code: "projection-conflict",
10908
+ projectionConflict: { kind: error.kind, filename: error.filename }
10909
+ };
10910
+ }
10867
10911
  const message = error instanceof Error ? error.message : "";
10868
10912
  const code = /Checksum/i.test(message) ? "checksum-mismatch" : /redirecionamento|mesmo servidor|outro servidor|\bURL\b/i.test(message) ? "archive-origin-rejected" : /transferência/i.test(message) ? "download-failed" : /modelo que não está aprovado/i.test(message) ? "model-not-approved" : /conflito/i.test(message) ? "projection-conflict" : /frontmatter|arquivo|marcador Forge reservado/i.test(message) ? "invalid-archive" : "operation-failed";
10869
10913
  return { status: "failed", restoration: "exact", code };
10870
10914
  }
10915
+ var WorkPackProjectionConflictError = class extends Error {
10916
+ constructor(kind, filename, slug) {
10917
+ super(`A proje\xE7\xE3o ${filename} do pacote de trabalho ${slug} entra em conflito com uma proje\xE7\xE3o existente`);
10918
+ this.kind = kind;
10919
+ this.filename = filename;
10920
+ this.name = "WorkPackProjectionConflictError";
10921
+ }
10922
+ kind;
10923
+ filename;
10924
+ };
10871
10925
  async function downloadSkill(credentials, url) {
10872
10926
  const forgeUrl = new URL(credentials.forgeBaseUrl);
10873
10927
  const archiveUrl = new URL(url, forgeUrl);
@@ -11275,7 +11329,7 @@ async function assertNoForeignAgentConflicts(agentsDir, agentFiles, ownedFilenam
11275
11329
  throw error;
11276
11330
  });
11277
11331
  if (existing !== void 0) {
11278
- throw new Error(`O agente ${agent.filename} do pacote de trabalho ${slug} entra em conflito com um ficheiro de agente existente que n\xE3o \xE9 gerido pelo Forge`);
11332
+ throw new WorkPackProjectionConflictError("agent", agent.filename, slug);
11279
11333
  }
11280
11334
  }
11281
11335
  }
@@ -11288,7 +11342,7 @@ async function assertNoForeignCommandConflicts(commandsDir, commandFiles, ownedF
11288
11342
  throw error;
11289
11343
  });
11290
11344
  if (existing !== void 0) {
11291
- throw new Error(`O comando ${command.filename} do pacote de trabalho ${slug} entra em conflito com um ficheiro de comando existente que n\xE3o \xE9 gerido pelo Forge`);
11345
+ throw new WorkPackProjectionConflictError("command", command.filename, slug);
11292
11346
  }
11293
11347
  }
11294
11348
  }
@@ -11436,7 +11490,7 @@ async function writeTextAtomic(filePath, content) {
11436
11490
  }
11437
11491
 
11438
11492
  // packages/cli/src/workPackSyncPlugin.ts
11439
- var PLUGIN_VERSION = "0.1.5";
11493
+ var PLUGIN_VERSION = "0.1.6";
11440
11494
  var STATUS_FILENAME = "work-pack-startup-status.json";
11441
11495
  var activeSync = /* @__PURE__ */ new Map();
11442
11496
  var ForgeWorkPackSyncServer = async (_input, options) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minimal-forge-work-pack-sync",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Minimal Forge Work Pack startup synchronization for OpenCode and OpenWork.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {