minimal-forge-work-pack-sync 0.1.13 → 0.1.14

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 +261 -216
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -117,17 +117,17 @@ var require_visit = __commonJS({
117
117
  visit.BREAK = BREAK;
118
118
  visit.SKIP = SKIP;
119
119
  visit.REMOVE = REMOVE;
120
- function visit_(key, node, visitor, path5) {
121
- const ctrl = callVisitor(key, node, visitor, path5);
120
+ function visit_(key, node, visitor, path6) {
121
+ const ctrl = callVisitor(key, node, visitor, path6);
122
122
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
123
- replaceNode(key, path5, ctrl);
124
- return visit_(key, ctrl, visitor, path5);
123
+ replaceNode(key, path6, ctrl);
124
+ return visit_(key, ctrl, visitor, path6);
125
125
  }
126
126
  if (typeof ctrl !== "symbol") {
127
127
  if (identity.isCollection(node)) {
128
- path5 = Object.freeze(path5.concat(node));
128
+ path6 = Object.freeze(path6.concat(node));
129
129
  for (let i = 0; i < node.items.length; ++i) {
130
- const ci2 = visit_(i, node.items[i], visitor, path5);
130
+ const ci2 = visit_(i, node.items[i], visitor, path6);
131
131
  if (typeof ci2 === "number")
132
132
  i = ci2 - 1;
133
133
  else if (ci2 === BREAK)
@@ -138,13 +138,13 @@ var require_visit = __commonJS({
138
138
  }
139
139
  }
140
140
  } else if (identity.isPair(node)) {
141
- path5 = Object.freeze(path5.concat(node));
142
- const ck = visit_("key", node.key, visitor, path5);
141
+ path6 = Object.freeze(path6.concat(node));
142
+ const ck = visit_("key", node.key, visitor, path6);
143
143
  if (ck === BREAK)
144
144
  return BREAK;
145
145
  else if (ck === REMOVE)
146
146
  node.key = null;
147
- const cv = visit_("value", node.value, visitor, path5);
147
+ const cv = visit_("value", node.value, visitor, path6);
148
148
  if (cv === BREAK)
149
149
  return BREAK;
150
150
  else if (cv === REMOVE)
@@ -165,17 +165,17 @@ var require_visit = __commonJS({
165
165
  visitAsync.BREAK = BREAK;
166
166
  visitAsync.SKIP = SKIP;
167
167
  visitAsync.REMOVE = REMOVE;
168
- async function visitAsync_(key, node, visitor, path5) {
169
- const ctrl = await callVisitor(key, node, visitor, path5);
168
+ async function visitAsync_(key, node, visitor, path6) {
169
+ const ctrl = await callVisitor(key, node, visitor, path6);
170
170
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
171
- replaceNode(key, path5, ctrl);
172
- return visitAsync_(key, ctrl, visitor, path5);
171
+ replaceNode(key, path6, ctrl);
172
+ return visitAsync_(key, ctrl, visitor, path6);
173
173
  }
174
174
  if (typeof ctrl !== "symbol") {
175
175
  if (identity.isCollection(node)) {
176
- path5 = Object.freeze(path5.concat(node));
176
+ path6 = Object.freeze(path6.concat(node));
177
177
  for (let i = 0; i < node.items.length; ++i) {
178
- const ci2 = await visitAsync_(i, node.items[i], visitor, path5);
178
+ const ci2 = await visitAsync_(i, node.items[i], visitor, path6);
179
179
  if (typeof ci2 === "number")
180
180
  i = ci2 - 1;
181
181
  else if (ci2 === BREAK)
@@ -186,13 +186,13 @@ var require_visit = __commonJS({
186
186
  }
187
187
  }
188
188
  } else if (identity.isPair(node)) {
189
- path5 = Object.freeze(path5.concat(node));
190
- const ck = await visitAsync_("key", node.key, visitor, path5);
189
+ path6 = Object.freeze(path6.concat(node));
190
+ const ck = await visitAsync_("key", node.key, visitor, path6);
191
191
  if (ck === BREAK)
192
192
  return BREAK;
193
193
  else if (ck === REMOVE)
194
194
  node.key = null;
195
- const cv = await visitAsync_("value", node.value, visitor, path5);
195
+ const cv = await visitAsync_("value", node.value, visitor, path6);
196
196
  if (cv === BREAK)
197
197
  return BREAK;
198
198
  else if (cv === REMOVE)
@@ -219,23 +219,23 @@ var require_visit = __commonJS({
219
219
  }
220
220
  return visitor;
221
221
  }
222
- function callVisitor(key, node, visitor, path5) {
222
+ function callVisitor(key, node, visitor, path6) {
223
223
  if (typeof visitor === "function")
224
- return visitor(key, node, path5);
224
+ return visitor(key, node, path6);
225
225
  if (identity.isMap(node))
226
- return visitor.Map?.(key, node, path5);
226
+ return visitor.Map?.(key, node, path6);
227
227
  if (identity.isSeq(node))
228
- return visitor.Seq?.(key, node, path5);
228
+ return visitor.Seq?.(key, node, path6);
229
229
  if (identity.isPair(node))
230
- return visitor.Pair?.(key, node, path5);
230
+ return visitor.Pair?.(key, node, path6);
231
231
  if (identity.isScalar(node))
232
- return visitor.Scalar?.(key, node, path5);
232
+ return visitor.Scalar?.(key, node, path6);
233
233
  if (identity.isAlias(node))
234
- return visitor.Alias?.(key, node, path5);
234
+ return visitor.Alias?.(key, node, path6);
235
235
  return void 0;
236
236
  }
237
- function replaceNode(key, path5, node) {
238
- const parent = path5[path5.length - 1];
237
+ function replaceNode(key, path6, node) {
238
+ const parent = path6[path6.length - 1];
239
239
  if (identity.isCollection(parent)) {
240
240
  parent.items[key] = node;
241
241
  } else if (identity.isPair(parent)) {
@@ -845,10 +845,10 @@ var require_Collection = __commonJS({
845
845
  var createNode = require_createNode();
846
846
  var identity = require_identity();
847
847
  var Node = require_Node();
848
- function collectionFromPath(schema, path5, value) {
848
+ function collectionFromPath(schema, path6, value) {
849
849
  let v2 = value;
850
- for (let i = path5.length - 1; i >= 0; --i) {
851
- const k2 = path5[i];
850
+ for (let i = path6.length - 1; i >= 0; --i) {
851
+ const k2 = path6[i];
852
852
  if (typeof k2 === "number" && Number.isInteger(k2) && k2 >= 0) {
853
853
  const a = [];
854
854
  a[k2] = v2;
@@ -867,7 +867,7 @@ var require_Collection = __commonJS({
867
867
  sourceObjects: /* @__PURE__ */ new Map()
868
868
  });
869
869
  }
870
- var isEmptyPath = (path5) => path5 == null || typeof path5 === "object" && !!path5[Symbol.iterator]().next().done;
870
+ var isEmptyPath = (path6) => path6 == null || typeof path6 === "object" && !!path6[Symbol.iterator]().next().done;
871
871
  var Collection = class extends Node.NodeBase {
872
872
  constructor(type, schema) {
873
873
  super(type);
@@ -897,11 +897,11 @@ var require_Collection = __commonJS({
897
897
  * be a Pair instance or a `{ key, value }` object, which may not have a key
898
898
  * that already exists in the map.
899
899
  */
900
- addIn(path5, value) {
901
- if (isEmptyPath(path5))
900
+ addIn(path6, value) {
901
+ if (isEmptyPath(path6))
902
902
  this.add(value);
903
903
  else {
904
- const [key, ...rest] = path5;
904
+ const [key, ...rest] = path6;
905
905
  const node = this.get(key, true);
906
906
  if (identity.isCollection(node))
907
907
  node.addIn(rest, value);
@@ -915,8 +915,8 @@ var require_Collection = __commonJS({
915
915
  * Removes a value from the collection.
916
916
  * @returns `true` if the item was found and removed.
917
917
  */
918
- deleteIn(path5) {
919
- const [key, ...rest] = path5;
918
+ deleteIn(path6) {
919
+ const [key, ...rest] = path6;
920
920
  if (rest.length === 0)
921
921
  return this.delete(key);
922
922
  const node = this.get(key, true);
@@ -930,8 +930,8 @@ var require_Collection = __commonJS({
930
930
  * scalar values from their surrounding node; to disable set `keepScalar` to
931
931
  * `true` (collections are always returned intact).
932
932
  */
933
- getIn(path5, keepScalar) {
934
- const [key, ...rest] = path5;
933
+ getIn(path6, keepScalar) {
934
+ const [key, ...rest] = path6;
935
935
  const node = this.get(key, true);
936
936
  if (rest.length === 0)
937
937
  return !keepScalar && identity.isScalar(node) ? node.value : node;
@@ -949,8 +949,8 @@ var require_Collection = __commonJS({
949
949
  /**
950
950
  * Checks if the collection includes a value with the key `key`.
951
951
  */
952
- hasIn(path5) {
953
- const [key, ...rest] = path5;
952
+ hasIn(path6) {
953
+ const [key, ...rest] = path6;
954
954
  if (rest.length === 0)
955
955
  return this.has(key);
956
956
  const node = this.get(key, true);
@@ -960,8 +960,8 @@ var require_Collection = __commonJS({
960
960
  * Sets a value in this collection. For `!!set`, `value` needs to be a
961
961
  * boolean to add/remove the item from the set.
962
962
  */
963
- setIn(path5, value) {
964
- const [key, ...rest] = path5;
963
+ setIn(path6, value) {
964
+ const [key, ...rest] = path6;
965
965
  if (rest.length === 0) {
966
966
  this.set(key, value);
967
967
  } else {
@@ -3476,9 +3476,9 @@ var require_Document = __commonJS({
3476
3476
  this.contents.add(value);
3477
3477
  }
3478
3478
  /** Adds a value to the document. */
3479
- addIn(path5, value) {
3479
+ addIn(path6, value) {
3480
3480
  if (assertCollection(this.contents))
3481
- this.contents.addIn(path5, value);
3481
+ this.contents.addIn(path6, value);
3482
3482
  }
3483
3483
  /**
3484
3484
  * Create a new `Alias` node, ensuring that the target `node` has the required anchor.
@@ -3553,14 +3553,14 @@ var require_Document = __commonJS({
3553
3553
  * Removes a value from the document.
3554
3554
  * @returns `true` if the item was found and removed.
3555
3555
  */
3556
- deleteIn(path5) {
3557
- if (Collection.isEmptyPath(path5)) {
3556
+ deleteIn(path6) {
3557
+ if (Collection.isEmptyPath(path6)) {
3558
3558
  if (this.contents == null)
3559
3559
  return false;
3560
3560
  this.contents = null;
3561
3561
  return true;
3562
3562
  }
3563
- return assertCollection(this.contents) ? this.contents.deleteIn(path5) : false;
3563
+ return assertCollection(this.contents) ? this.contents.deleteIn(path6) : false;
3564
3564
  }
3565
3565
  /**
3566
3566
  * Returns item at `key`, or `undefined` if not found. By default unwraps
@@ -3575,10 +3575,10 @@ var require_Document = __commonJS({
3575
3575
  * scalar values from their surrounding node; to disable set `keepScalar` to
3576
3576
  * `true` (collections are always returned intact).
3577
3577
  */
3578
- getIn(path5, keepScalar) {
3579
- if (Collection.isEmptyPath(path5))
3578
+ getIn(path6, keepScalar) {
3579
+ if (Collection.isEmptyPath(path6))
3580
3580
  return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
3581
- return identity.isCollection(this.contents) ? this.contents.getIn(path5, keepScalar) : void 0;
3581
+ return identity.isCollection(this.contents) ? this.contents.getIn(path6, keepScalar) : void 0;
3582
3582
  }
3583
3583
  /**
3584
3584
  * Checks if the document includes a value with the key `key`.
@@ -3589,10 +3589,10 @@ var require_Document = __commonJS({
3589
3589
  /**
3590
3590
  * Checks if the document includes a value at `path`.
3591
3591
  */
3592
- hasIn(path5) {
3593
- if (Collection.isEmptyPath(path5))
3592
+ hasIn(path6) {
3593
+ if (Collection.isEmptyPath(path6))
3594
3594
  return this.contents !== void 0;
3595
- return identity.isCollection(this.contents) ? this.contents.hasIn(path5) : false;
3595
+ return identity.isCollection(this.contents) ? this.contents.hasIn(path6) : false;
3596
3596
  }
3597
3597
  /**
3598
3598
  * Sets a value in this document. For `!!set`, `value` needs to be a
@@ -3609,13 +3609,13 @@ var require_Document = __commonJS({
3609
3609
  * Sets a value in this document. For `!!set`, `value` needs to be a
3610
3610
  * boolean to add/remove the item from the set.
3611
3611
  */
3612
- setIn(path5, value) {
3613
- if (Collection.isEmptyPath(path5)) {
3612
+ setIn(path6, value) {
3613
+ if (Collection.isEmptyPath(path6)) {
3614
3614
  this.contents = value;
3615
3615
  } else if (this.contents == null) {
3616
- this.contents = Collection.collectionFromPath(this.schema, Array.from(path5), value);
3616
+ this.contents = Collection.collectionFromPath(this.schema, Array.from(path6), value);
3617
3617
  } else if (assertCollection(this.contents)) {
3618
- this.contents.setIn(path5, value);
3618
+ this.contents.setIn(path6, value);
3619
3619
  }
3620
3620
  }
3621
3621
  /**
@@ -5575,9 +5575,9 @@ var require_cst_visit = __commonJS({
5575
5575
  visit.BREAK = BREAK;
5576
5576
  visit.SKIP = SKIP;
5577
5577
  visit.REMOVE = REMOVE;
5578
- visit.itemAtPath = (cst, path5) => {
5578
+ visit.itemAtPath = (cst, path6) => {
5579
5579
  let item = cst;
5580
- for (const [field, index] of path5) {
5580
+ for (const [field, index] of path6) {
5581
5581
  const tok = item?.[field];
5582
5582
  if (tok && "items" in tok) {
5583
5583
  item = tok.items[index];
@@ -5586,23 +5586,23 @@ var require_cst_visit = __commonJS({
5586
5586
  }
5587
5587
  return item;
5588
5588
  };
5589
- visit.parentCollection = (cst, path5) => {
5590
- const parent = visit.itemAtPath(cst, path5.slice(0, -1));
5591
- const field = path5[path5.length - 1][0];
5589
+ visit.parentCollection = (cst, path6) => {
5590
+ const parent = visit.itemAtPath(cst, path6.slice(0, -1));
5591
+ const field = path6[path6.length - 1][0];
5592
5592
  const coll = parent?.[field];
5593
5593
  if (coll && "items" in coll)
5594
5594
  return coll;
5595
5595
  throw new Error("Parent collection not found");
5596
5596
  };
5597
- function _visit(path5, item, visitor) {
5598
- let ctrl = visitor(item, path5);
5597
+ function _visit(path6, item, visitor) {
5598
+ let ctrl = visitor(item, path6);
5599
5599
  if (typeof ctrl === "symbol")
5600
5600
  return ctrl;
5601
5601
  for (const field of ["key", "value"]) {
5602
5602
  const token = item[field];
5603
5603
  if (token && "items" in token) {
5604
5604
  for (let i = 0; i < token.items.length; ++i) {
5605
- const ci2 = _visit(Object.freeze(path5.concat([[field, i]])), token.items[i], visitor);
5605
+ const ci2 = _visit(Object.freeze(path6.concat([[field, i]])), token.items[i], visitor);
5606
5606
  if (typeof ci2 === "number")
5607
5607
  i = ci2 - 1;
5608
5608
  else if (ci2 === BREAK)
@@ -5613,10 +5613,10 @@ var require_cst_visit = __commonJS({
5613
5613
  }
5614
5614
  }
5615
5615
  if (typeof ctrl === "function" && field === "key")
5616
- ctrl = ctrl(item, path5);
5616
+ ctrl = ctrl(item, path6);
5617
5617
  }
5618
5618
  }
5619
- return typeof ctrl === "function" ? ctrl(item, path5) : ctrl;
5619
+ return typeof ctrl === "function" ? ctrl(item, path6) : ctrl;
5620
5620
  }
5621
5621
  exports.visit = visit;
5622
5622
  }
@@ -7367,10 +7367,54 @@ var require_dist = __commonJS({
7367
7367
  }
7368
7368
  });
7369
7369
 
7370
+ // packages/cli/src/retireDebugCapture.ts
7371
+ import { lstat, readFile, rename, writeFile } from "node:fs/promises";
7372
+ import { randomUUID } from "node:crypto";
7373
+ import path from "node:path";
7374
+ var MANAGED_HEADER = "// Managed by Forge sync. Do not edit.";
7375
+ var RETIRED_DEBUG_PLUGIN = `${MANAGED_HEADER}
7376
+ // Detailed capture retired. Keep this module loadable for old OpenCode configs.
7377
+ export const ForgeDebugTrace = async () => ({})
7378
+ `;
7379
+ async function retireDebugCapture(paths) {
7380
+ const configPath = path.join(paths.forgeDir, "debug-trace.json");
7381
+ const raw = await readRegularFile(configPath);
7382
+ if (raw !== void 0) {
7383
+ const config2 = JSON.parse(raw);
7384
+ if (config2?.managedBy === "minimal-forge" && config2.enabled !== false) {
7385
+ await replaceFile(configPath, `${JSON.stringify({ ...config2, enabled: false }, null, 2)}
7386
+ `);
7387
+ }
7388
+ }
7389
+ const pluginPath = path.join(paths.pluginDir, "forge-debug-trace.js");
7390
+ const plugin = await readRegularFile(pluginPath);
7391
+ if (plugin?.startsWith(MANAGED_HEADER) && plugin !== RETIRED_DEBUG_PLUGIN) {
7392
+ await replaceFile(pluginPath, RETIRED_DEBUG_PLUGIN);
7393
+ }
7394
+ }
7395
+ async function readRegularFile(filename) {
7396
+ try {
7397
+ const directory = await lstat(path.dirname(filename));
7398
+ const info = await lstat(filename);
7399
+ if (!directory.isDirectory() || !info.isFile() || info.isSymbolicLink()) {
7400
+ throw new Error("Legacy debug capture path must be a regular file in a real directory");
7401
+ }
7402
+ return await readFile(filename, "utf8");
7403
+ } catch (error45) {
7404
+ if (error45.code === "ENOENT") return void 0;
7405
+ throw error45;
7406
+ }
7407
+ }
7408
+ async function replaceFile(filename, contents) {
7409
+ const temporary = `${filename}.retired-${randomUUID()}`;
7410
+ await writeFile(temporary, contents, { flag: "wx", mode: 384 });
7411
+ await rename(temporary, filename);
7412
+ }
7413
+
7370
7414
  // packages/cli/src/workPackSyncPlugin.ts
7371
7415
  var import_yaml = __toESM(require_dist(), 1);
7372
- import { mkdir as mkdir3, readdir as readdir3, readFile as readFile3, rename as rename3, writeFile as writeFile3 } from "node:fs/promises";
7373
- import path4 from "node:path";
7416
+ import { mkdir as mkdir3, readdir as readdir3, readFile as readFile4, rename as rename4, writeFile as writeFile4 } from "node:fs/promises";
7417
+ import path5 from "node:path";
7374
7418
 
7375
7419
  // node_modules/@opencode-ai/plugin/node_modules/zod/v4/classic/external.js
7376
7420
  var external_exports = {};
@@ -8103,10 +8147,10 @@ function mergeDefs(...defs) {
8103
8147
  function cloneDef(schema) {
8104
8148
  return mergeDefs(schema._zod.def);
8105
8149
  }
8106
- function getElementAtPath(obj, path5) {
8107
- if (!path5)
8150
+ function getElementAtPath(obj, path6) {
8151
+ if (!path6)
8108
8152
  return obj;
8109
- return path5.reduce((acc, key) => acc?.[key], obj);
8153
+ return path6.reduce((acc, key) => acc?.[key], obj);
8110
8154
  }
8111
8155
  function promiseAllObject(promisesObj) {
8112
8156
  const keys = Object.keys(promisesObj);
@@ -8467,11 +8511,11 @@ function aborted(x, startIndex = 0) {
8467
8511
  }
8468
8512
  return false;
8469
8513
  }
8470
- function prefixIssues(path5, issues) {
8514
+ function prefixIssues(path6, issues) {
8471
8515
  return issues.map((iss) => {
8472
8516
  var _a;
8473
8517
  (_a = iss).path ?? (_a.path = []);
8474
- iss.path.unshift(path5);
8518
+ iss.path.unshift(path6);
8475
8519
  return iss;
8476
8520
  });
8477
8521
  }
@@ -8639,7 +8683,7 @@ function treeifyError(error45, _mapper) {
8639
8683
  return issue2.message;
8640
8684
  };
8641
8685
  const result = { errors: [] };
8642
- const processError = (error46, path5 = []) => {
8686
+ const processError = (error46, path6 = []) => {
8643
8687
  var _a, _b;
8644
8688
  for (const issue2 of error46.issues) {
8645
8689
  if (issue2.code === "invalid_union" && issue2.errors.length) {
@@ -8649,7 +8693,7 @@ function treeifyError(error45, _mapper) {
8649
8693
  } else if (issue2.code === "invalid_element") {
8650
8694
  processError({ issues: issue2.issues }, issue2.path);
8651
8695
  } else {
8652
- const fullpath = [...path5, ...issue2.path];
8696
+ const fullpath = [...path6, ...issue2.path];
8653
8697
  if (fullpath.length === 0) {
8654
8698
  result.errors.push(mapper(issue2));
8655
8699
  continue;
@@ -8681,8 +8725,8 @@ function treeifyError(error45, _mapper) {
8681
8725
  }
8682
8726
  function toDotPath(_path) {
8683
8727
  const segs = [];
8684
- const path5 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
8685
- for (const seg of path5) {
8728
+ const path6 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
8729
+ for (const seg of path6) {
8686
8730
  if (typeof seg === "number")
8687
8731
  segs.push(`[${seg}]`);
8688
8732
  else if (typeof seg === "symbol")
@@ -19796,10 +19840,10 @@ tool.schema = external_exports;
19796
19840
 
19797
19841
  // packages/cli/src/paths.ts
19798
19842
  import os from "node:os";
19799
- import path from "node:path";
19843
+ import path2 from "node:path";
19800
19844
  import { existsSync } from "node:fs";
19801
19845
  function resolvePaths(home = os.homedir(), platform = process.platform, env = process.env, exists = existsSync) {
19802
- const pathApi = platform === "win32" ? path.win32 : path.posix;
19846
+ const pathApi = platform === "win32" ? path2.win32 : path2.posix;
19803
19847
  const userHome = platform === "win32" ? env.USERPROFILE ?? home : home;
19804
19848
  const forgeConfigRoot = env.XDG_CONFIG_HOME ?? pathApi.join(userHome, ".config");
19805
19849
  const forgeDir = pathApi.join(forgeConfigRoot, "forge");
@@ -20058,7 +20102,7 @@ var DEFAULT_DEBUG_TRACE_LIMITS = {
20058
20102
  };
20059
20103
 
20060
20104
  // packages/shared/src/contracts/settings.ts
20061
- var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.13";
20105
+ var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.14";
20062
20106
  var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
20063
20107
  var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
20064
20108
  var FIRECRAWL_KEYLESS_MCP_NAME = "firecrawl";
@@ -20103,9 +20147,9 @@ function canonicalWorkPackState(state) {
20103
20147
 
20104
20148
  // packages/cli/src/sync.ts
20105
20149
  import { createHash as createHash2 } from "node:crypto";
20106
- import { chmod, cp, lstat as lstat2, mkdtemp, mkdir as mkdir2, readdir as readdir2, readFile as readFile2, rm, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
20150
+ import { chmod, cp, lstat as lstat3, mkdtemp, mkdir as mkdir2, readdir as readdir2, readFile as readFile3, rm, rename as rename3, writeFile as writeFile3 } from "node:fs/promises";
20107
20151
  import os4 from "node:os";
20108
- import path3 from "node:path";
20152
+ import path4 from "node:path";
20109
20153
 
20110
20154
  // node_modules/tar/dist/esm/index.min.js
20111
20155
  import Qr from "events";
@@ -23262,8 +23306,8 @@ function assertUniqueSlugs(packs, label) {
23262
23306
 
23263
23307
  // packages/cli/src/workPackLocalState.ts
23264
23308
  import { createHash } from "node:crypto";
23265
- import { lstat, mkdir, readFile, readdir, rename, writeFile } from "node:fs/promises";
23266
- import path2 from "node:path";
23309
+ import { lstat as lstat2, mkdir, readFile as readFile2, readdir, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
23310
+ import path3 from "node:path";
23267
23311
  var WORK_PACK_LOCAL_STATE_FILENAME = ".forge-installed-state.json";
23268
23312
  async function writeWorkPackInstalledState(input) {
23269
23313
  const tree = await digestPackTree(input.packDir);
@@ -23275,7 +23319,7 @@ async function writeWorkPackInstalledState(input) {
23275
23319
  agents: digestProjectionContents(input.agents),
23276
23320
  commands: digestProjectionContents(input.commands)
23277
23321
  };
23278
- await writeJsonAtomic(path2.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
23322
+ await writeJsonAtomic(path3.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
23279
23323
  }
23280
23324
  async function checkWorkPackInstalledState(input) {
23281
23325
  const state = await readInstalledState(input.packDir);
@@ -23291,7 +23335,7 @@ async function checkWorkPackTreeState(packDir) {
23291
23335
  async function adoptWorkPackInstalledState(input) {
23292
23336
  const state = await readInstalledState(input.expectedPackDir);
23293
23337
  if (!state || !await matchesInstalledState(input, state)) return false;
23294
- await writeJsonAtomic(path2.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
23338
+ await writeJsonAtomic(path3.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
23295
23339
  return checkWorkPackInstalledState(input).then((result) => result === "match");
23296
23340
  }
23297
23341
  async function adoptVerifiedWorkPackState(input) {
@@ -23303,10 +23347,10 @@ async function adoptVerifiedWorkPackState(input) {
23303
23347
  const result = [];
23304
23348
  for (const file2 of expected) {
23305
23349
  const filename = file2.path.slice(prefix.length);
23306
- const absolute = path2.join(directory, filename);
23307
- const info = await lstat(absolute);
23350
+ const absolute = path3.join(directory, filename);
23351
+ const info = await lstat2(absolute);
23308
23352
  if (!info.isFile() || info.isSymbolicLink()) throw new Error("Unsafe projection");
23309
- result.push({ filename, sha256: digest(await readFile(absolute)) });
23353
+ result.push({ filename, sha256: digest(await readFile2(absolute)) });
23310
23354
  }
23311
23355
  return result.sort((a, b2) => a.filename.localeCompare(b2.filename));
23312
23356
  };
@@ -23319,11 +23363,11 @@ async function adoptVerifiedWorkPackState(input) {
23319
23363
  };
23320
23364
  if (digest(Buffer.from(canonicalWorkPackState(state))) !== input.fingerprint) return false;
23321
23365
  if (!await matchesInstalledState(input, state)) return false;
23322
- await writeJsonAtomic(path2.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
23366
+ await writeJsonAtomic(path3.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
23323
23367
  return await checkWorkPackInstalledState(input) === "match";
23324
23368
  }
23325
23369
  async function readInstalledState(packDir) {
23326
- const raw = await readFile(path2.join(packDir, WORK_PACK_LOCAL_STATE_FILENAME), "utf8").catch(() => void 0);
23370
+ const raw = await readFile2(path3.join(packDir, WORK_PACK_LOCAL_STATE_FILENAME), "utf8").catch(() => void 0);
23327
23371
  if (!raw) return void 0;
23328
23372
  try {
23329
23373
  const value = JSON.parse(raw);
@@ -23345,14 +23389,14 @@ async function digestPackTree(root) {
23345
23389
  for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
23346
23390
  if (!prefix && entry.name === WORK_PACK_LOCAL_STATE_FILENAME) continue;
23347
23391
  const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
23348
- const absolute = path2.join(directory, entry.name);
23392
+ const absolute = path3.join(directory, entry.name);
23349
23393
  if (entry.isDirectory()) {
23350
23394
  directories.push(relative);
23351
23395
  if (!await visit(absolute, relative)) return false;
23352
23396
  continue;
23353
23397
  }
23354
23398
  if (!entry.isFile()) return false;
23355
- files.push({ path: relative, sha256: digest(await readFile(absolute)) });
23399
+ files.push({ path: relative, sha256: digest(await readFile2(absolute)) });
23356
23400
  }
23357
23401
  return true;
23358
23402
  };
@@ -23363,10 +23407,10 @@ function digestProjectionContents(files) {
23363
23407
  }
23364
23408
  async function projectionsMatch(directory, expected) {
23365
23409
  for (const projection of expected) {
23366
- const absolute = path2.join(directory, projection.filename);
23367
- const info = await lstat(absolute).catch(() => void 0);
23410
+ const absolute = path3.join(directory, projection.filename);
23411
+ const info = await lstat2(absolute).catch(() => void 0);
23368
23412
  if (!info?.isFile() || info.isSymbolicLink()) return false;
23369
- const bytes = await readFile(absolute).catch(() => void 0);
23413
+ const bytes = await readFile2(absolute).catch(() => void 0);
23370
23414
  if (!bytes || digest(bytes) !== projection.sha256) return false;
23371
23415
  }
23372
23416
  return true;
@@ -23384,7 +23428,7 @@ async function matchesInstalledState(input, state) {
23384
23428
  return projectionsMatch(input.commandsDir, state.commands);
23385
23429
  }
23386
23430
  function validRelativePath(value, filenameOnly) {
23387
- if (!value || path2.isAbsolute(value) || value.includes("\\")) return false;
23431
+ if (!value || path3.isAbsolute(value) || value.includes("\\")) return false;
23388
23432
  const parts = value.split("/");
23389
23433
  if (parts.some((part) => !part || part === "." || part === "..")) return false;
23390
23434
  return !filenameOnly || parts.length === 1;
@@ -23399,11 +23443,11 @@ function digest(bytes) {
23399
23443
  return createHash("sha256").update(bytes).digest("hex");
23400
23444
  }
23401
23445
  async function writeJsonAtomic(filePath, value) {
23402
- await mkdir(path2.dirname(filePath), { recursive: true });
23403
- const tempPath = path2.join(path2.dirname(filePath), `.${path2.basename(filePath)}.${process.pid}.tmp`);
23404
- await writeFile(tempPath, `${JSON.stringify(value, null, 2)}
23446
+ await mkdir(path3.dirname(filePath), { recursive: true });
23447
+ const tempPath = path3.join(path3.dirname(filePath), `.${path3.basename(filePath)}.${process.pid}.tmp`);
23448
+ await writeFile2(tempPath, `${JSON.stringify(value, null, 2)}
23405
23449
  `);
23406
- await rename(tempPath, filePath);
23450
+ await rename2(tempPath, filePath);
23407
23451
  }
23408
23452
 
23409
23453
  // packages/cli/src/sync.ts
@@ -23454,9 +23498,9 @@ async function applyWorkPackManifest(paths, credentials, manifest, options) {
23454
23498
  const recovery = await recoverInterruptedWorkPackInstalls(paths, options.cleanupWorkPackBackup, options.workPackProjectionBoundary);
23455
23499
  const managed = await Promise.all((await managedWorkPackSlugs(paths.skillsDir)).map(async (slug) => ({
23456
23500
  slug,
23457
- version: (await readFile2(path3.join(paths.skillsDir, slug, ".forge-version"), "utf8")).trim(),
23458
- agents: await readAgentRecord(path3.join(paths.skillsDir, slug)),
23459
- commands: await readCommandRecord(path3.join(paths.skillsDir, slug))
23501
+ version: (await readFile3(path4.join(paths.skillsDir, slug, ".forge-version"), "utf8")).trim(),
23502
+ agents: await readAgentRecord(path4.join(paths.skillsDir, slug)),
23503
+ commands: await readCommandRecord(path4.join(paths.skillsDir, slug))
23460
23504
  })));
23461
23505
  const desired = manifest.skills.map((skill) => ({
23462
23506
  slug: skill.slug,
@@ -23480,7 +23524,7 @@ async function applyWorkPackManifest(paths, credentials, manifest, options) {
23480
23524
  options
23481
23525
  ),
23482
23526
  recoveryFailures: recovery.failures,
23483
- writeAtomicReceipt: (receipt) => writeJsonAtomic2(path3.join(paths.forgeDir, "work-pack-sync-receipt.json"), receipt)
23527
+ writeAtomicReceipt: (receipt) => writeJsonAtomic2(path4.join(paths.forgeDir, "work-pack-sync-receipt.json"), receipt)
23484
23528
  });
23485
23529
  const installed = workPacks.outcomes.filter((outcome) => outcome.status === "installed").map((outcome) => `${outcome.slug}@${outcome.version}`);
23486
23530
  const removed = workPacks.outcomes.filter((outcome) => outcome.status === "removed").map((outcome) => outcome.slug);
@@ -23491,7 +23535,7 @@ async function applyWorkPackManifest(paths, credentials, manifest, options) {
23491
23535
  async function collectWorkPackObservations(paths, reconciliation) {
23492
23536
  const installedVersions = /* @__PURE__ */ new Map();
23493
23537
  for (const slug of await managedWorkPackSlugs(paths.skillsDir)) {
23494
- const version2 = (await readFile2(path3.join(paths.skillsDir, slug, ".forge-version"), "utf8")).trim();
23538
+ const version2 = (await readFile3(path4.join(paths.skillsDir, slug, ".forge-version"), "utf8")).trim();
23495
23539
  if (version2) installedVersions.set(slug, version2);
23496
23540
  }
23497
23541
  const observations = new Map(
@@ -23510,7 +23554,7 @@ async function collectWorkPackObservations(paths, reconciliation) {
23510
23554
  return [...observations.values()].sort((a, b2) => a.slug.localeCompare(b2.slug));
23511
23555
  }
23512
23556
  async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds, cleanupPendingSlugs, recoveryFailures, operation, options) {
23513
- const target = path3.join(paths.skillsDir, operation.pack.slug);
23557
+ const target = path4.join(paths.skillsDir, operation.pack.slug);
23514
23558
  const recoveryFailure = recoveryFailures.get(operation.pack.slug);
23515
23559
  if (recoveryFailure) return { status: "failed", restoration: "exact", code: recoveryFailure };
23516
23560
  let ownership;
@@ -23549,7 +23593,7 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
23549
23593
  let previousManagedPaths;
23550
23594
  let archive;
23551
23595
  try {
23552
- const currentVersion = await readFile2(path3.join(target, ".forge-version"), "utf8").catch(() => "");
23596
+ const currentVersion = await readFile3(path4.join(target, ".forge-version"), "utf8").catch(() => "");
23553
23597
  const sameVersion = currentVersion.trim() === skill.version;
23554
23598
  if (sameVersion) {
23555
23599
  let localState = await checkWorkPackInstalledState({
@@ -23722,7 +23766,7 @@ var WorkPackLocalEditsError = class extends Error {
23722
23766
  async function assertWorkPackUnchangedAtBoundary(paths, target) {
23723
23767
  const ownership = await workPackOwnership(target);
23724
23768
  if (ownership === "absent") return;
23725
- if (ownership === "foreign") throw foreignWorkPackError(path3.basename(target));
23769
+ if (ownership === "foreign") throw foreignWorkPackError(path4.basename(target));
23726
23770
  const localState = await checkWorkPackInstalledState({
23727
23771
  packDir: target,
23728
23772
  agentsDir: paths.agentsDir,
@@ -23746,21 +23790,21 @@ function skillSlugFromUrl(value) {
23746
23790
  }
23747
23791
  }
23748
23792
  async function installSkillArchive(paths, slug, version2, archive, options = {}) {
23749
- const tempRoot = await mkdtemp(path3.join(os4.tmpdir(), `forge-${slug}-`));
23750
- const archivePath = path3.join(tempRoot, `${slug}.tar`);
23751
- const extractPath = path3.join(tempRoot, "extract");
23752
- const nextPath = path3.join(tempRoot, slug);
23753
- const target = path3.join(paths.skillsDir, slug);
23754
- const backup = path3.join(paths.skillsDir, `${slug}.previous`);
23793
+ const tempRoot = await mkdtemp(path4.join(os4.tmpdir(), `forge-${slug}-`));
23794
+ const archivePath = path4.join(tempRoot, `${slug}.tar`);
23795
+ const extractPath = path4.join(tempRoot, "extract");
23796
+ const nextPath = path4.join(tempRoot, slug);
23797
+ const target = path4.join(paths.skillsDir, slug);
23798
+ const backup = path4.join(paths.skillsDir, `${slug}.previous`);
23755
23799
  let agentFiles;
23756
23800
  let commandFiles;
23757
23801
  let previousAgents;
23758
23802
  let previousCommands;
23759
23803
  try {
23760
23804
  await mkdir2(extractPath, { recursive: true });
23761
- await writeFile2(archivePath, archive);
23805
+ await writeFile3(archivePath, archive);
23762
23806
  await So({ file: archivePath, cwd: extractPath, strict: true });
23763
- const extractedSkillPath = path3.join(extractPath, slug);
23807
+ const extractedSkillPath = path4.join(extractPath, slug);
23764
23808
  await assertNoReservedMarkerAliases(extractedSkillPath);
23765
23809
  await validateSkillFolder(extractedSkillPath, slug);
23766
23810
  agentFiles = await normalizePackAgentModels(
@@ -23787,15 +23831,15 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
23787
23831
  }
23788
23832
  throw error45;
23789
23833
  }
23790
- await rename2(path3.join(extractPath, slug), nextPath);
23791
- await writeFile2(path3.join(nextPath, ".forge-version"), `${version2}
23834
+ await rename3(path4.join(extractPath, slug), nextPath);
23835
+ await writeFile3(path4.join(nextPath, ".forge-version"), `${version2}
23792
23836
  `);
23793
23837
  if (agentFiles.length > 0) {
23794
- await writeFile2(path3.join(nextPath, ".forge-agents"), `${agentFiles.map((agent) => agent.filename).join("\n")}
23838
+ await writeFile3(path4.join(nextPath, ".forge-agents"), `${agentFiles.map((agent) => agent.filename).join("\n")}
23795
23839
  `);
23796
23840
  }
23797
23841
  if (commandFiles.length > 0) {
23798
- await writeFile2(path3.join(nextPath, ".forge-commands"), `${commandFiles.map((command) => command.filename).join("\n")}
23842
+ await writeFile3(path4.join(nextPath, ".forge-commands"), `${commandFiles.map((command) => command.filename).join("\n")}
23799
23843
  `);
23800
23844
  }
23801
23845
  await writeWorkPackInstalledState({ packDir: nextPath, version: version2, agents: agentFiles, commands: commandFiles });
@@ -23806,13 +23850,13 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
23806
23850
  const agentTransactionState = new Map(
23807
23851
  [...agentSnapshot.keys()].map((filePath) => [
23808
23852
  filePath,
23809
- agentFiles.find((agent) => agent.filename === path3.basename(filePath))?.content
23853
+ agentFiles.find((agent) => agent.filename === path4.basename(filePath))?.content
23810
23854
  ])
23811
23855
  );
23812
23856
  const commandTransactionState = new Map(
23813
23857
  [...commandSnapshot.keys()].map((filePath) => [
23814
23858
  filePath,
23815
- commandFiles.find((command) => command.filename === path3.basename(filePath))?.content
23859
+ commandFiles.find((command) => command.filename === path4.basename(filePath))?.content
23816
23860
  ])
23817
23861
  );
23818
23862
  const previousManagedPaths = await managedWorkPackPaths(paths, target);
@@ -23824,7 +23868,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
23824
23868
  throw error45;
23825
23869
  }
23826
23870
  const writeProjection = options.writeWorkPackProjection ?? writeTextAtomic;
23827
- const claimedBackup = path3.join(tempRoot, `${slug}-claimed-previous`);
23871
+ const claimedBackup = path4.join(tempRoot, `${slug}-claimed-previous`);
23828
23872
  const transactionPath = `${backup}${WORK_PACK_TRANSACTION_SUFFIX}`;
23829
23873
  let targetBackedUp = false;
23830
23874
  let targetInstalled = false;
@@ -23834,7 +23878,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
23834
23878
  await rm(transactionPath, { force: true });
23835
23879
  await writeTextAtomic(transactionPath, "install\n");
23836
23880
  try {
23837
- await rename2(target, backup);
23881
+ await rename3(target, backup);
23838
23882
  targetBackedUp = true;
23839
23883
  } catch (error45) {
23840
23884
  if (error45.code !== "ENOENT") throw error45;
@@ -23844,10 +23888,10 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
23844
23888
  await options.installWorkPackBoundary?.("after-backup");
23845
23889
  await assertWorkPackUnchangedAtBoundary(paths, backup);
23846
23890
  }
23847
- await rename2(nextPath, target);
23891
+ await rename3(nextPath, target);
23848
23892
  targetInstalled = true;
23849
23893
  for (const filename of previousAgents.filter((name) => !nextAgentNames.has(name))) {
23850
- const filePath = path3.join(paths.agentsDir, filename);
23894
+ const filePath = path4.join(paths.agentsDir, filename);
23851
23895
  await options.workPackProjectionBoundary?.("install", filePath);
23852
23896
  await assertProjectionState(filePath, agentSnapshot.get(filePath));
23853
23897
  await rm(filePath, { force: true });
@@ -23855,14 +23899,14 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
23855
23899
  if (agentFiles.length > 0) {
23856
23900
  await mkdir2(paths.agentsDir, { recursive: true });
23857
23901
  for (const agent of agentFiles) {
23858
- const filePath = path3.join(paths.agentsDir, agent.filename);
23902
+ const filePath = path4.join(paths.agentsDir, agent.filename);
23859
23903
  await options.workPackProjectionBoundary?.("install", filePath);
23860
23904
  await assertProjectionState(filePath, agentSnapshot.get(filePath));
23861
23905
  await writeProjection(filePath, agent.content);
23862
23906
  }
23863
23907
  }
23864
23908
  for (const filename of previousCommands.filter((name) => !nextCommandNames.has(name))) {
23865
- const filePath = path3.join(paths.commandsDir, filename);
23909
+ const filePath = path4.join(paths.commandsDir, filename);
23866
23910
  await options.workPackProjectionBoundary?.("install", filePath);
23867
23911
  await assertProjectionState(filePath, commandSnapshot.get(filePath));
23868
23912
  await rm(filePath, { force: true });
@@ -23870,7 +23914,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
23870
23914
  if (commandFiles.length > 0) {
23871
23915
  await mkdir2(paths.commandsDir, { recursive: true });
23872
23916
  for (const command of commandFiles) {
23873
- const filePath = path3.join(paths.commandsDir, command.filename);
23917
+ const filePath = path4.join(paths.commandsDir, command.filename);
23874
23918
  await options.workPackProjectionBoundary?.("install", filePath);
23875
23919
  await assertProjectionState(filePath, commandSnapshot.get(filePath));
23876
23920
  await writeProjection(filePath, command.content);
@@ -23879,10 +23923,10 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
23879
23923
  if (targetBackedUp) await assertWorkPackTreeUnchangedAtBoundary(backup);
23880
23924
  if (targetBackedUp) await options.installWorkPackBoundary?.("before-commit");
23881
23925
  if (targetBackedUp) {
23882
- await rename2(backup, claimedBackup);
23926
+ await rename3(backup, claimedBackup);
23883
23927
  backupClaimed = true;
23884
23928
  await assertWorkPackTreeUnchangedAtBoundary(claimedBackup);
23885
- await writeFile2(path3.join(claimedBackup, WORK_PACK_COMMITTED_MARKER), `${version2}
23929
+ await writeFile3(path4.join(claimedBackup, WORK_PACK_COMMITTED_MARKER), `${version2}
23886
23930
  `);
23887
23931
  await writeTextAtomic(transactionPath, "committed\n");
23888
23932
  }
@@ -23893,11 +23937,11 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
23893
23937
  await restoreProjectionState(commandSnapshot, commandTransactionState);
23894
23938
  }
23895
23939
  if (targetBackedUp) {
23896
- const restoredTarget = path3.join(tempRoot, `${slug}-restore`);
23940
+ const restoredTarget = path4.join(tempRoot, `${slug}-restore`);
23897
23941
  const rollbackSource = backupClaimed ? claimedBackup : backup;
23898
23942
  await cp(rollbackSource, restoredTarget, { recursive: true });
23899
23943
  if (targetInstalled) await rm(target, { recursive: true, force: true });
23900
- await rename2(restoredTarget, target);
23944
+ await rename3(restoredTarget, target);
23901
23945
  await rm(rollbackSource, { recursive: true, force: true });
23902
23946
  await rm(transactionPath, { force: true });
23903
23947
  } else if (targetInstalled) {
@@ -23923,26 +23967,26 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
23923
23967
  await rm(transactionPath, { force: true });
23924
23968
  } else {
23925
23969
  cleanup = "pending";
23926
- if (backupClaimed) await rename2(claimedBackup, backup);
23970
+ if (backupClaimed) await rename3(claimedBackup, backup);
23927
23971
  }
23928
23972
  }
23929
23973
  await rm(tempRoot, { recursive: true, force: true }).catch(() => void 0);
23930
23974
  return { cleanup };
23931
23975
  }
23932
23976
  async function adoptLegacyWorkPackState(paths, slug, version2, archive, approvedModelIds) {
23933
- const comparisonRoot = await mkdtemp(path3.join(os4.tmpdir(), `forge-${slug}-baseline-`));
23977
+ const comparisonRoot = await mkdtemp(path4.join(os4.tmpdir(), `forge-${slug}-baseline-`));
23934
23978
  const comparisonPaths = {
23935
23979
  ...paths,
23936
- skillsDir: path3.join(comparisonRoot, "skills"),
23937
- agentsDir: path3.join(comparisonRoot, "agents"),
23938
- commandsDir: path3.join(comparisonRoot, "commands")
23980
+ skillsDir: path4.join(comparisonRoot, "skills"),
23981
+ agentsDir: path4.join(comparisonRoot, "agents"),
23982
+ commandsDir: path4.join(comparisonRoot, "commands")
23939
23983
  };
23940
23984
  try {
23941
23985
  await mkdir2(comparisonPaths.skillsDir, { recursive: true });
23942
23986
  await installSkillArchive(comparisonPaths, slug, version2, archive, { approvedModelIds });
23943
23987
  return adoptWorkPackInstalledState({
23944
- expectedPackDir: path3.join(comparisonPaths.skillsDir, slug),
23945
- packDir: path3.join(paths.skillsDir, slug),
23988
+ expectedPackDir: path4.join(comparisonPaths.skillsDir, slug),
23989
+ packDir: path4.join(paths.skillsDir, slug),
23946
23990
  agentsDir: paths.agentsDir,
23947
23991
  commandsDir: paths.commandsDir
23948
23992
  });
@@ -23961,7 +24005,7 @@ async function recoverInterruptedWorkPackInstalls(paths, cleanupWorkPackBackup,
23961
24005
  if (!entry.name.endsWith(".previous")) continue;
23962
24006
  const slug = entry.name.slice(0, -".previous".length);
23963
24007
  if (!slug) continue;
23964
- const target = path3.join(paths.skillsDir, slug);
24008
+ const target = path4.join(paths.skillsDir, slug);
23965
24009
  const backup = `${target}.previous`;
23966
24010
  const transactionState = await readWorkPackTransactionState(backup);
23967
24011
  if (transactionState === "committed") {
@@ -23994,9 +24038,9 @@ async function recoverInterruptedWorkPackInstall(paths, target, cleanupWorkPackB
23994
24038
  const backup = `${target}.previous`;
23995
24039
  const backupOwnership = await workPackOwnership(backup);
23996
24040
  if (backupOwnership === "absent") return "recovered";
23997
- if (backupOwnership === "foreign") throw foreignWorkPackError(path3.basename(target));
23998
- if (await workPackOwnership(target) === "foreign") throw foreignWorkPackError(path3.basename(target));
23999
- const committed = await readFile2(path3.join(backup, WORK_PACK_COMMITTED_MARKER), "utf8").catch((error45) => {
24041
+ if (backupOwnership === "foreign") throw foreignWorkPackError(path4.basename(target));
24042
+ if (await workPackOwnership(target) === "foreign") throw foreignWorkPackError(path4.basename(target));
24043
+ const committed = await readFile3(path4.join(backup, WORK_PACK_COMMITTED_MARKER), "utf8").catch((error45) => {
24000
24044
  if (error45.code === "ENOENT") return void 0;
24001
24045
  throw error45;
24002
24046
  });
@@ -24038,38 +24082,38 @@ async function recoverInterruptedWorkPackInstall(paths, target, cleanupWorkPackB
24038
24082
  );
24039
24083
  const previousAgentNames = new Set(previousAgents.map((agent) => agent.filename));
24040
24084
  const previousCommandNames = new Set(previousCommands.map((command) => command.filename));
24041
- const recoveryRoot = await mkdtemp(path3.join(os4.tmpdir(), "forge-recover-"));
24042
- const recoveredTarget = path3.join(recoveryRoot, path3.basename(target));
24085
+ const recoveryRoot = await mkdtemp(path4.join(os4.tmpdir(), "forge-recover-"));
24086
+ const recoveredTarget = path4.join(recoveryRoot, path4.basename(target));
24043
24087
  await cp(backup, recoveredTarget, { recursive: true });
24044
24088
  try {
24045
24089
  for (const filename of currentAgents.filter((name) => !previousAgentNames.has(name))) {
24046
- const filePath = path3.join(paths.agentsDir, filename);
24090
+ const filePath = path4.join(paths.agentsDir, filename);
24047
24091
  await workPackProjectionBoundary?.("recover", filePath);
24048
24092
  await assertProjectionState(filePath, agentRecoveryState.get(filePath));
24049
24093
  await rm(filePath, { force: true });
24050
24094
  }
24051
24095
  await mkdir2(paths.agentsDir, { recursive: true });
24052
24096
  for (const agent of previousAgents) {
24053
- const filePath = path3.join(paths.agentsDir, agent.filename);
24097
+ const filePath = path4.join(paths.agentsDir, agent.filename);
24054
24098
  await workPackProjectionBoundary?.("recover", filePath);
24055
24099
  await assertProjectionState(filePath, agentRecoveryState.get(filePath));
24056
24100
  await writeTextAtomic(filePath, agent.content);
24057
24101
  }
24058
24102
  for (const filename of currentCommands.filter((name) => !previousCommandNames.has(name))) {
24059
- const filePath = path3.join(paths.commandsDir, filename);
24103
+ const filePath = path4.join(paths.commandsDir, filename);
24060
24104
  await workPackProjectionBoundary?.("recover", filePath);
24061
24105
  await assertProjectionState(filePath, commandRecoveryState.get(filePath));
24062
24106
  await rm(filePath, { force: true });
24063
24107
  }
24064
24108
  await mkdir2(paths.commandsDir, { recursive: true });
24065
24109
  for (const command of previousCommands) {
24066
- const filePath = path3.join(paths.commandsDir, command.filename);
24110
+ const filePath = path4.join(paths.commandsDir, command.filename);
24067
24111
  await workPackProjectionBoundary?.("recover", filePath);
24068
24112
  await assertProjectionState(filePath, commandRecoveryState.get(filePath));
24069
24113
  await writeTextAtomic(filePath, command.content);
24070
24114
  }
24071
24115
  await rm(target, { recursive: true, force: true });
24072
- await rename2(recoveredTarget, target);
24116
+ await rename3(recoveredTarget, target);
24073
24117
  await rm(backup, { recursive: true, force: true });
24074
24118
  await rm(`${backup}${WORK_PACK_TRANSACTION_SUFFIX}`, { force: true });
24075
24119
  } finally {
@@ -24081,7 +24125,7 @@ async function removeWorkPackBackup(backupPath) {
24081
24125
  await rm(backupPath, { recursive: true, force: true });
24082
24126
  }
24083
24127
  async function readWorkPackTransactionFile(backup) {
24084
- return readFile2(`${backup}${WORK_PACK_TRANSACTION_SUFFIX}`, "utf8").catch((error45) => {
24128
+ return readFile3(`${backup}${WORK_PACK_TRANSACTION_SUFFIX}`, "utf8").catch((error45) => {
24085
24129
  if (error45.code === "ENOENT") return void 0;
24086
24130
  throw error45;
24087
24131
  });
@@ -24095,7 +24139,7 @@ function isManagedProjectionName(filename) {
24095
24139
  return filename.length > 0 && !filename.includes("/") && !filename.includes("\\") && filename !== "..";
24096
24140
  }
24097
24141
  async function recordRemovedProjection(transactionPath, kind, filename) {
24098
- const current = await readFile2(transactionPath, "utf8");
24142
+ const current = await readFile3(transactionPath, "utf8");
24099
24143
  await writeTextAtomic(transactionPath, `${current.trimEnd()}
24100
24144
  ${kind}:${filename}
24101
24145
  `);
@@ -24120,19 +24164,19 @@ async function readWorkPackRemovedProjections(backup) {
24120
24164
  return { agents, commands };
24121
24165
  }
24122
24166
  async function pathExists(filePath) {
24123
- return lstat2(filePath).then(() => true, (error45) => {
24167
+ return lstat3(filePath).then(() => true, (error45) => {
24124
24168
  if (error45.code === "ENOENT") return false;
24125
24169
  throw error45;
24126
24170
  });
24127
24171
  }
24128
24172
  async function workPackOwnership(target) {
24129
- const targetStat = await lstat2(target).catch((error45) => {
24173
+ const targetStat = await lstat3(target).catch((error45) => {
24130
24174
  if (error45.code === "ENOENT") return void 0;
24131
24175
  throw error45;
24132
24176
  });
24133
24177
  if (!targetStat) return "absent";
24134
24178
  if (!targetStat.isDirectory()) return "foreign";
24135
- const marker = await readFile2(path3.join(target, ".forge-version"), "utf8").catch((error45) => {
24179
+ const marker = await readFile3(path4.join(target, ".forge-version"), "utf8").catch((error45) => {
24136
24180
  if (error45.code === "ENOENT") return void 0;
24137
24181
  throw error45;
24138
24182
  });
@@ -24158,11 +24202,11 @@ async function assertProjectionRecoveryIsSafe(directory, currentFiles, previousF
24158
24202
  expected.set(file2.filename, contents);
24159
24203
  }
24160
24204
  for (const [filename, contents] of expected) {
24161
- const projected = await readFile2(path3.join(directory, filename), "utf8").catch((error45) => {
24205
+ const projected = await readFile3(path4.join(directory, filename), "utf8").catch((error45) => {
24162
24206
  if (error45.code === "ENOENT") return void 0;
24163
24207
  throw error45;
24164
24208
  });
24165
- validated.set(path3.join(directory, filename), projected);
24209
+ validated.set(path4.join(directory, filename), projected);
24166
24210
  const missingPreviousProjection = missingPreviousProjectionIsLocalDeletion(
24167
24211
  filename,
24168
24212
  projected,
@@ -24180,19 +24224,19 @@ async function assertProjectionRecoveryIsSafe(directory, currentFiles, previousF
24180
24224
  return validated;
24181
24225
  }
24182
24226
  async function assertProjectionState(filePath, expected) {
24183
- const current = await readFile2(filePath, "utf8").catch((error45) => {
24227
+ const current = await readFile3(filePath, "utf8").catch((error45) => {
24184
24228
  if (error45.code === "ENOENT") return void 0;
24185
24229
  throw error45;
24186
24230
  });
24187
24231
  if (current !== expected) {
24188
- throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${path3.basename(filePath)} foi alterada durante a opera\xE7\xE3o`);
24232
+ throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${path4.basename(filePath)} foi alterada durante a opera\xE7\xE3o`);
24189
24233
  }
24190
24234
  }
24191
24235
  async function captureProjectionState(directory, filenames) {
24192
24236
  const snapshot = /* @__PURE__ */ new Map();
24193
24237
  for (const filename of filenames) {
24194
- const filePath = path3.join(directory, filename);
24195
- const content = await readFile2(filePath, "utf8").catch((error45) => {
24238
+ const filePath = path4.join(directory, filename);
24239
+ const content = await readFile3(filePath, "utf8").catch((error45) => {
24196
24240
  if (error45.code === "ENOENT") return void 0;
24197
24241
  throw error45;
24198
24242
  });
@@ -24203,7 +24247,7 @@ async function captureProjectionState(directory, filenames) {
24203
24247
  async function restoreProjectionState(snapshot, transactionState) {
24204
24248
  for (const [filePath, content] of snapshot) {
24205
24249
  if (transactionState) {
24206
- const current = await readFile2(filePath, "utf8").catch((error45) => {
24250
+ const current = await readFile3(filePath, "utf8").catch((error45) => {
24207
24251
  if (error45.code === "ENOENT") return void 0;
24208
24252
  throw error45;
24209
24253
  });
@@ -24214,7 +24258,7 @@ async function restoreProjectionState(snapshot, transactionState) {
24214
24258
  }
24215
24259
  }
24216
24260
  async function readPackAgentFiles(skillFolder) {
24217
- const agentsFolder = path3.join(skillFolder, "agents");
24261
+ const agentsFolder = path4.join(skillFolder, "agents");
24218
24262
  const entries = await readdir2(agentsFolder, { withFileTypes: true }).catch((error45) => {
24219
24263
  if (error45.code === "ENOENT") return [];
24220
24264
  throw error45;
@@ -24223,7 +24267,7 @@ async function readPackAgentFiles(skillFolder) {
24223
24267
  for (const entry of entries) {
24224
24268
  if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
24225
24269
  if (entry.name.startsWith("._")) continue;
24226
- const content = await readFile2(path3.join(agentsFolder, entry.name), "utf8");
24270
+ const content = await readFile3(path4.join(agentsFolder, entry.name), "utf8");
24227
24271
  validateAgentFile(entry.name, content);
24228
24272
  files.push({ filename: entry.name, content });
24229
24273
  }
@@ -24234,7 +24278,7 @@ async function normalizePackAgentModels(skillFolder, agentFiles, approvedModelId
24234
24278
  for (const agent of agentFiles) {
24235
24279
  const content = normalizePackAgentModel(agent.filename, agent.content, approvedModelIds, slug);
24236
24280
  if (content !== agent.content) {
24237
- await writeFile2(path3.join(skillFolder, "agents", agent.filename), content);
24281
+ await writeFile3(path4.join(skillFolder, "agents", agent.filename), content);
24238
24282
  }
24239
24283
  normalized.push({ ...agent, content });
24240
24284
  }
@@ -24254,7 +24298,7 @@ function normalizePackAgentModel(filename, content, approvedModelIds, slug) {
24254
24298
  return normalizePackExtensionModel(`agents/${filename}`, content, approvedModelIds, slug);
24255
24299
  }
24256
24300
  async function readPackCommandFiles(skillFolder) {
24257
- const commandsFolder = path3.join(skillFolder, "commands");
24301
+ const commandsFolder = path4.join(skillFolder, "commands");
24258
24302
  const entries = await readdir2(commandsFolder, { withFileTypes: true }).catch((error45) => {
24259
24303
  if (error45.code === "ENOENT") return [];
24260
24304
  throw error45;
@@ -24263,7 +24307,7 @@ async function readPackCommandFiles(skillFolder) {
24263
24307
  for (const entry of entries) {
24264
24308
  if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
24265
24309
  if (entry.name.startsWith("._")) continue;
24266
- const content = await readFile2(path3.join(commandsFolder, entry.name), "utf8");
24310
+ const content = await readFile3(path4.join(commandsFolder, entry.name), "utf8");
24267
24311
  validateCommandFile(entry.name, content);
24268
24312
  files.push({ filename: entry.name, content });
24269
24313
  }
@@ -24274,7 +24318,7 @@ async function normalizePackCommandModels(skillFolder, commandFiles, approvedMod
24274
24318
  for (const command of commandFiles) {
24275
24319
  const content = normalizePackExtensionModel(`commands/${command.filename}`, command.content, approvedModelIds, slug);
24276
24320
  if (content !== command.content) {
24277
- await writeFile2(path3.join(skillFolder, "commands", command.filename), content);
24321
+ await writeFile3(path4.join(skillFolder, "commands", command.filename), content);
24278
24322
  }
24279
24323
  normalized.push({ ...command, content });
24280
24324
  }
@@ -24296,7 +24340,7 @@ async function assertNoForeignAgentConflicts(agentsDir, agentFiles, ownedFilenam
24296
24340
  const owned = new Set(ownedFilenames);
24297
24341
  for (const agent of agentFiles) {
24298
24342
  if (owned.has(agent.filename)) continue;
24299
- const existing = await readFile2(path3.join(agentsDir, agent.filename), "utf8").catch((error45) => {
24343
+ const existing = await readFile3(path4.join(agentsDir, agent.filename), "utf8").catch((error45) => {
24300
24344
  if (error45.code === "ENOENT") return void 0;
24301
24345
  throw error45;
24302
24346
  });
@@ -24309,7 +24353,7 @@ async function assertNoForeignCommandConflicts(commandsDir, commandFiles, ownedF
24309
24353
  const owned = new Set(ownedFilenames);
24310
24354
  for (const command of commandFiles) {
24311
24355
  if (owned.has(command.filename)) continue;
24312
- const existing = await readFile2(path3.join(commandsDir, command.filename), "utf8").catch((error45) => {
24356
+ const existing = await readFile3(path4.join(commandsDir, command.filename), "utf8").catch((error45) => {
24313
24357
  if (error45.code === "ENOENT") return void 0;
24314
24358
  throw error45;
24315
24359
  });
@@ -24319,17 +24363,17 @@ async function assertNoForeignCommandConflicts(commandsDir, commandFiles, ownedF
24319
24363
  }
24320
24364
  }
24321
24365
  async function readAgentRecord(skillFolder) {
24322
- const raw = await readFile2(path3.join(skillFolder, ".forge-agents"), "utf8").catch(() => "");
24366
+ const raw = await readFile3(path4.join(skillFolder, ".forge-agents"), "utf8").catch(() => "");
24323
24367
  return raw.split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.includes("/") && !line.includes("\\") && line !== "..");
24324
24368
  }
24325
24369
  async function readCommandRecord(skillFolder) {
24326
- const raw = await readFile2(path3.join(skillFolder, ".forge-commands"), "utf8").catch(() => "");
24370
+ const raw = await readFile3(path4.join(skillFolder, ".forge-commands"), "utf8").catch(() => "");
24327
24371
  return raw.split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.includes("/") && !line.includes("\\") && line !== "..");
24328
24372
  }
24329
24373
  async function managedWorkPackPaths(paths, skillFolder) {
24330
24374
  const files = await listFilesRecursively(skillFolder);
24331
- const agents = (await readAgentRecord(skillFolder)).map((filename) => path3.join(paths.agentsDir, filename));
24332
- const commands = (await readCommandRecord(skillFolder)).map((filename) => path3.join(paths.commandsDir, filename));
24375
+ const agents = (await readAgentRecord(skillFolder)).map((filename) => path4.join(paths.agentsDir, filename));
24376
+ const commands = (await readCommandRecord(skillFolder)).map((filename) => path4.join(paths.commandsDir, filename));
24333
24377
  return [.../* @__PURE__ */ new Set([...files, ...agents, ...commands])];
24334
24378
  }
24335
24379
  async function managedWorkPackSlugs(skillsDir) {
@@ -24340,7 +24384,7 @@ async function managedWorkPackSlugs(skillsDir) {
24340
24384
  const slugs = [];
24341
24385
  for (const entry of entries) {
24342
24386
  if (!entry.isDirectory() || entry.name.endsWith(".previous")) continue;
24343
- if (await workPackOwnership(path3.join(skillsDir, entry.name)) === "managed") slugs.push(entry.name);
24387
+ if (await workPackOwnership(path4.join(skillsDir, entry.name)) === "managed") slugs.push(entry.name);
24344
24388
  }
24345
24389
  return slugs.sort((left, right) => left.localeCompare(right));
24346
24390
  }
@@ -24350,21 +24394,21 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
24350
24394
  const agents = await readAgentRecord(target);
24351
24395
  const commands = await readCommandRecord(target);
24352
24396
  const snapshots = await Promise.all([
24353
- ...agents.map((filename) => captureExactFile(path3.join(paths.agentsDir, filename))),
24354
- ...commands.map((filename) => captureExactFile(path3.join(paths.commandsDir, filename)))
24397
+ ...agents.map((filename) => captureExactFile(path4.join(paths.agentsDir, filename))),
24398
+ ...commands.map((filename) => captureExactFile(path4.join(paths.commandsDir, filename)))
24355
24399
  ]);
24356
24400
  await assertWorkPackUnchangedAtBoundary(paths, target);
24357
24401
  const backup = `${target}.previous`;
24358
24402
  const transactionPath = `${backup}${WORK_PACK_TRANSACTION_SUFFIX}`;
24359
- const transactionRoot = await mkdtemp(path3.join(os4.tmpdir(), "forge-remove-"));
24360
- const claimedBackup = path3.join(transactionRoot, path3.basename(target));
24403
+ const transactionRoot = await mkdtemp(path4.join(os4.tmpdir(), "forge-remove-"));
24404
+ const claimedBackup = path4.join(transactionRoot, path4.basename(target));
24361
24405
  let projectionsRemoved = false;
24362
24406
  let backupClaimed = false;
24363
24407
  try {
24364
24408
  await rm(backup, { recursive: true, force: true });
24365
24409
  await rm(transactionPath, { force: true });
24366
24410
  await writeTextAtomic(transactionPath, "remove\n");
24367
- await rename2(target, backup);
24411
+ await rename3(target, backup);
24368
24412
  } catch (error45) {
24369
24413
  await rm(transactionPath, { force: true }).catch(() => void 0);
24370
24414
  await rm(transactionRoot, { recursive: true, force: true }).catch(() => void 0);
@@ -24375,7 +24419,7 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
24375
24419
  await assertWorkPackUnchangedAtBoundary(paths, backup);
24376
24420
  projectionsRemoved = agents.length > 0;
24377
24421
  for (const filename of agents) {
24378
- const filePath = path3.join(paths.agentsDir, filename);
24422
+ const filePath = path4.join(paths.agentsDir, filename);
24379
24423
  await options.workPackProjectionBoundary?.("remove", filePath);
24380
24424
  await assertExactFileState(snapshots, filePath);
24381
24425
  await recordRemovedProjection(transactionPath, "agent", filename);
@@ -24384,7 +24428,7 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
24384
24428
  await options.removeWorkPackBoundary?.("after-agents");
24385
24429
  projectionsRemoved ||= commands.length > 0;
24386
24430
  for (const filename of commands) {
24387
- const filePath = path3.join(paths.commandsDir, filename);
24431
+ const filePath = path4.join(paths.commandsDir, filename);
24388
24432
  await options.workPackProjectionBoundary?.("remove", filePath);
24389
24433
  await assertExactFileState(snapshots, filePath);
24390
24434
  await recordRemovedProjection(transactionPath, "command", filename);
@@ -24393,7 +24437,7 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
24393
24437
  await options.removeWorkPackBoundary?.("after-commands");
24394
24438
  await assertWorkPackTreeUnchangedAtBoundary(backup);
24395
24439
  await options.removeWorkPackBoundary?.("before-commit");
24396
- await rename2(backup, claimedBackup);
24440
+ await rename3(backup, claimedBackup);
24397
24441
  backupClaimed = true;
24398
24442
  await assertWorkPackTreeUnchangedAtBoundary(claimedBackup);
24399
24443
  await writeTextAtomic(transactionPath, "committed\n");
@@ -24404,13 +24448,13 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
24404
24448
  } catch (error45) {
24405
24449
  try {
24406
24450
  if (projectionsRemoved) await restoreRemovedExactFiles(snapshots);
24407
- await rename2(backupClaimed ? claimedBackup : backup, target);
24451
+ await rename3(backupClaimed ? claimedBackup : backup, target);
24408
24452
  await rm(transactionPath, { force: true });
24409
24453
  if (projectionsRemoved) await verifyRestoredOrLocallyChangedFiles(snapshots);
24410
24454
  if (await workPackOwnership(target) !== "managed") throw new Error("restored Work Pack marker missing");
24411
24455
  await rm(transactionRoot, { recursive: true, force: true }).catch(() => void 0);
24412
24456
  } catch (restoreError) {
24413
- throw new WorkPackRecoveryUncertainError(`Falha ao remover e restaurar o pacote de trabalho ${path3.basename(target)}`, {
24457
+ throw new WorkPackRecoveryUncertainError(`Falha ao remover e restaurar o pacote de trabalho ${path4.basename(target)}`, {
24414
24458
  cause: new AggregateError([error45, restoreError])
24415
24459
  });
24416
24460
  }
@@ -24419,9 +24463,9 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
24419
24463
  }
24420
24464
  async function captureExactFile(filePath) {
24421
24465
  try {
24422
- const info = await lstat2(filePath);
24466
+ const info = await lstat3(filePath);
24423
24467
  if (!info.isFile()) throw new Error(`A proje\xE7\xE3o gerida n\xE3o \xE9 um ficheiro regular: ${filePath}`);
24424
- return { path: filePath, exists: true, bytes: await readFile2(filePath), mode: info.mode & 4095 };
24468
+ return { path: filePath, exists: true, bytes: await readFile3(filePath), mode: info.mode & 4095 };
24425
24469
  } catch (error45) {
24426
24470
  if (error45.code === "ENOENT") return { path: filePath, exists: false };
24427
24471
  throw error45;
@@ -24431,18 +24475,18 @@ async function assertExactFileState(snapshots, filePath) {
24431
24475
  const expected = snapshots.find((snapshot) => snapshot.path === filePath);
24432
24476
  const current = await captureExactFile(filePath);
24433
24477
  if (!expected || current.exists !== expected.exists) {
24434
- throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${path3.basename(filePath)} foi alterada durante a opera\xE7\xE3o`);
24478
+ throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${path4.basename(filePath)} foi alterada durante a opera\xE7\xE3o`);
24435
24479
  }
24436
24480
  if (current.exists && (!current.bytes?.equals(expected.bytes) || current.mode !== expected.mode)) {
24437
- throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${path3.basename(filePath)} foi alterada durante a opera\xE7\xE3o`);
24481
+ throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${path4.basename(filePath)} foi alterada durante a opera\xE7\xE3o`);
24438
24482
  }
24439
24483
  }
24440
24484
  async function restoreRemovedExactFiles(snapshots) {
24441
24485
  for (const snapshot of snapshots) {
24442
24486
  if ((await captureExactFile(snapshot.path)).exists) continue;
24443
24487
  if (!snapshot.exists) continue;
24444
- await mkdir2(path3.dirname(snapshot.path), { recursive: true });
24445
- await writeFile2(snapshot.path, snapshot.bytes);
24488
+ await mkdir2(path4.dirname(snapshot.path), { recursive: true });
24489
+ await writeFile3(snapshot.path, snapshot.bytes);
24446
24490
  await chmod(snapshot.path, snapshot.mode);
24447
24491
  }
24448
24492
  }
@@ -24459,14 +24503,14 @@ async function listFilesRecursively(root) {
24459
24503
  });
24460
24504
  const files = [];
24461
24505
  for (const entry of entries) {
24462
- const absolute = path3.join(root, entry.name);
24506
+ const absolute = path4.join(root, entry.name);
24463
24507
  if (entry.isDirectory()) files.push(...await listFilesRecursively(absolute));
24464
24508
  else if (entry.isFile()) files.push(absolute);
24465
24509
  }
24466
24510
  return files;
24467
24511
  }
24468
24512
  async function validateSkillFolder(folder, slug) {
24469
- const skillMd = await readFile2(path3.join(folder, "SKILL.md"), "utf8");
24513
+ const skillMd = await readFile3(path4.join(folder, "SKILL.md"), "utf8");
24470
24514
  const frontmatter = /^---\n([\s\S]+?)\n---/.exec(skillMd)?.[1] ?? "";
24471
24515
  if (!frontmatter.includes(`name: ${slug}`) && !frontmatter.includes(`name: "${slug}"`)) {
24472
24516
  throw new Error(`O campo name no frontmatter de SKILL.md tem de corresponder a ${slug}`);
@@ -24487,15 +24531,15 @@ async function writeJsonAtomic2(filePath, value) {
24487
24531
  await writeTextAtomic(filePath, content);
24488
24532
  }
24489
24533
  async function writeTextAtomic(filePath, content) {
24490
- const dir = path3.dirname(filePath);
24534
+ const dir = path4.dirname(filePath);
24491
24535
  await mkdir2(dir, { recursive: true });
24492
- const tempPath = path3.join(dir, `.${path3.basename(filePath)}.${process.pid}.tmp`);
24493
- await writeFile2(tempPath, content);
24494
- await rename2(tempPath, filePath);
24536
+ const tempPath = path4.join(dir, `.${path4.basename(filePath)}.${process.pid}.tmp`);
24537
+ await writeFile3(tempPath, content);
24538
+ await rename3(tempPath, filePath);
24495
24539
  }
24496
24540
 
24497
24541
  // packages/cli/src/workPackSyncPlugin.ts
24498
- var PLUGIN_VERSION = "0.1.13";
24542
+ var PLUGIN_VERSION = "0.1.14";
24499
24543
  var STATUS_FILENAME = "work-pack-startup-status.json";
24500
24544
  var activeSync = /* @__PURE__ */ new Map();
24501
24545
  var ForgeWorkPackSyncServer = async (_input, options) => {
@@ -24548,6 +24592,7 @@ async function synchronizeAtStartup(forgeBaseUrl) {
24548
24592
  const before = await managedProjectionNames(paths);
24549
24593
  let credentials;
24550
24594
  try {
24595
+ await retireDebugCapture(paths);
24551
24596
  credentials = await readWellKnownForgeCredentials(paths.opencodeAuthPath, forgeBaseUrl);
24552
24597
  const manifest = await fetchManifest(credentials);
24553
24598
  const result = await applyWorkPackManifest(paths, credentials, manifest, {});
@@ -24591,7 +24636,7 @@ function resolveStartupPaths() {
24591
24636
  return resolvePaths(void 0, void 0, env);
24592
24637
  }
24593
24638
  async function readWellKnownForgeCredentials(authPath, forgeBaseUrl) {
24594
- const raw = await readFile3(authPath, "utf8");
24639
+ const raw = await readFile4(authPath, "utf8");
24595
24640
  const parsed = JSON.parse(raw.startsWith("\uFEFF") ? raw.slice(1) : raw);
24596
24641
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
24597
24642
  throw new Error("A autentica\xE7\xE3o do OpenCode n\xE3o \xE9 um objeto JSON v\xE1lido");
@@ -24628,16 +24673,16 @@ async function managedProjectionNames(paths) {
24628
24673
  });
24629
24674
  for (const entry of entries) {
24630
24675
  if (!entry.isDirectory()) continue;
24631
- const folder = path4.join(paths.skillsDir, entry.name);
24632
- const marker = await readFile3(path4.join(folder, ".forge-version"), "utf8").catch(() => "");
24676
+ const folder = path5.join(paths.skillsDir, entry.name);
24677
+ const marker = await readFile4(path5.join(folder, ".forge-version"), "utf8").catch(() => "");
24633
24678
  if (!marker.trim()) continue;
24634
- for (const name of await readProjectionRecord(path4.join(folder, ".forge-agents"))) agents.add(stripMarkdownExtension(name));
24635
- for (const name of await readProjectionRecord(path4.join(folder, ".forge-commands"))) commands.add(stripMarkdownExtension(name));
24679
+ for (const name of await readProjectionRecord(path5.join(folder, ".forge-agents"))) agents.add(stripMarkdownExtension(name));
24680
+ for (const name of await readProjectionRecord(path5.join(folder, ".forge-commands"))) commands.add(stripMarkdownExtension(name));
24636
24681
  }
24637
24682
  return { agents, commands };
24638
24683
  }
24639
24684
  async function readProjectionRecord(filePath) {
24640
- const raw = await readFile3(filePath, "utf8").catch(() => "");
24685
+ const raw = await readFile4(filePath, "utf8").catch(() => "");
24641
24686
  return raw.split("\n").map((line) => line.trim()).filter(
24642
24687
  (line) => line.endsWith(".md") && !line.includes("/") && !line.includes("\\") && line !== ".."
24643
24688
  );
@@ -24648,21 +24693,21 @@ async function projectCurrentExtensions(config2, state) {
24648
24693
  for (const name of state.before.agents) if (!state.after.agents.has(name)) delete agents[name];
24649
24694
  for (const name of state.before.commands) if (!state.after.commands.has(name)) delete commands[name];
24650
24695
  for (const name of state.after.agents) {
24651
- agents[name] = await parseMarkdownConfig(path4.join(state.paths.agentsDir, `${name}.md`), "prompt");
24696
+ agents[name] = await parseMarkdownConfig(path5.join(state.paths.agentsDir, `${name}.md`), "prompt");
24652
24697
  }
24653
24698
  for (const name of state.after.commands) {
24654
- commands[name] = await parseMarkdownConfig(path4.join(state.paths.commandsDir, `${name}.md`), "template");
24699
+ commands[name] = await parseMarkdownConfig(path5.join(state.paths.commandsDir, `${name}.md`), "template");
24655
24700
  }
24656
24701
  config2.agent = agents;
24657
24702
  config2.command = commands;
24658
24703
  }
24659
24704
  async function parseMarkdownConfig(filePath, bodyField) {
24660
- const raw = await readFile3(filePath, "utf8");
24705
+ const raw = await readFile4(filePath, "utf8");
24661
24706
  const match = /^---\r?\n([\s\S]+?)\r?\n---\r?\n?([\s\S]*)$/.exec(raw);
24662
- if (!match) throw new Error(`A extens\xE3o Forge ${path4.basename(filePath)} n\xE3o tem frontmatter v\xE1lido`);
24707
+ if (!match) throw new Error(`A extens\xE3o Forge ${path5.basename(filePath)} n\xE3o tem frontmatter v\xE1lido`);
24663
24708
  const data = (0, import_yaml.parse)(match[1]);
24664
24709
  if (!data || typeof data !== "object" || Array.isArray(data)) {
24665
- throw new Error(`A extens\xE3o Forge ${path4.basename(filePath)} n\xE3o tem frontmatter v\xE1lido`);
24710
+ throw new Error(`A extens\xE3o Forge ${path5.basename(filePath)} n\xE3o tem frontmatter v\xE1lido`);
24666
24711
  }
24667
24712
  const config2 = { ...data, [bodyField]: match[2].trim() };
24668
24713
  if (bodyField === "prompt" && typeof config2.permission === "string" && ["allow", "ask", "deny"].includes(config2.permission)) {
@@ -24678,11 +24723,11 @@ function stripMarkdownExtension(filename) {
24678
24723
  }
24679
24724
  async function writeStatus(paths, value) {
24680
24725
  await mkdir3(paths.forgeDir, { recursive: true });
24681
- const target = path4.join(paths.forgeDir, STATUS_FILENAME);
24682
- const temporary = path4.join(paths.forgeDir, `.${STATUS_FILENAME}.${process.pid}.tmp`);
24683
- await writeFile3(temporary, `${JSON.stringify(value, null, 2)}
24726
+ const target = path5.join(paths.forgeDir, STATUS_FILENAME);
24727
+ const temporary = path5.join(paths.forgeDir, `.${STATUS_FILENAME}.${process.pid}.tmp`);
24728
+ await writeFile4(temporary, `${JSON.stringify(value, null, 2)}
24684
24729
  `, { mode: 384 });
24685
- await rename3(temporary, target);
24730
+ await rename4(temporary, target);
24686
24731
  }
24687
24732
  function safeErrorMessage(error45) {
24688
24733
  const message = error45 instanceof Error ? error45.message : "erro desconhecido";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minimal-forge-work-pack-sync",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "Minimal Forge Work Pack startup synchronization for OpenCode and OpenWork.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {