minimal-forge-work-pack-sync 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1016 -486
- 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,
|
|
121
|
-
const ctrl = callVisitor(key, node, visitor,
|
|
120
|
+
function visit_(key, node, visitor, path5) {
|
|
121
|
+
const ctrl = callVisitor(key, node, visitor, path5);
|
|
122
122
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
123
|
-
replaceNode(key,
|
|
124
|
-
return visit_(key, ctrl, visitor,
|
|
123
|
+
replaceNode(key, path5, ctrl);
|
|
124
|
+
return visit_(key, ctrl, visitor, path5);
|
|
125
125
|
}
|
|
126
126
|
if (typeof ctrl !== "symbol") {
|
|
127
127
|
if (identity.isCollection(node)) {
|
|
128
|
-
|
|
128
|
+
path5 = Object.freeze(path5.concat(node));
|
|
129
129
|
for (let i = 0; i < node.items.length; ++i) {
|
|
130
|
-
const ci2 = visit_(i, node.items[i], visitor,
|
|
130
|
+
const ci2 = visit_(i, node.items[i], visitor, path5);
|
|
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
|
-
|
|
142
|
-
const ck = visit_("key", node.key, visitor,
|
|
141
|
+
path5 = Object.freeze(path5.concat(node));
|
|
142
|
+
const ck = visit_("key", node.key, visitor, path5);
|
|
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,
|
|
147
|
+
const cv = visit_("value", node.value, visitor, path5);
|
|
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,
|
|
169
|
-
const ctrl = await callVisitor(key, node, visitor,
|
|
168
|
+
async function visitAsync_(key, node, visitor, path5) {
|
|
169
|
+
const ctrl = await callVisitor(key, node, visitor, path5);
|
|
170
170
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
171
|
-
replaceNode(key,
|
|
172
|
-
return visitAsync_(key, ctrl, visitor,
|
|
171
|
+
replaceNode(key, path5, ctrl);
|
|
172
|
+
return visitAsync_(key, ctrl, visitor, path5);
|
|
173
173
|
}
|
|
174
174
|
if (typeof ctrl !== "symbol") {
|
|
175
175
|
if (identity.isCollection(node)) {
|
|
176
|
-
|
|
176
|
+
path5 = Object.freeze(path5.concat(node));
|
|
177
177
|
for (let i = 0; i < node.items.length; ++i) {
|
|
178
|
-
const ci2 = await visitAsync_(i, node.items[i], visitor,
|
|
178
|
+
const ci2 = await visitAsync_(i, node.items[i], visitor, path5);
|
|
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
|
-
|
|
190
|
-
const ck = await visitAsync_("key", node.key, visitor,
|
|
189
|
+
path5 = Object.freeze(path5.concat(node));
|
|
190
|
+
const ck = await visitAsync_("key", node.key, visitor, path5);
|
|
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,
|
|
195
|
+
const cv = await visitAsync_("value", node.value, visitor, path5);
|
|
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,
|
|
222
|
+
function callVisitor(key, node, visitor, path5) {
|
|
223
223
|
if (typeof visitor === "function")
|
|
224
|
-
return visitor(key, node,
|
|
224
|
+
return visitor(key, node, path5);
|
|
225
225
|
if (identity.isMap(node))
|
|
226
|
-
return visitor.Map?.(key, node,
|
|
226
|
+
return visitor.Map?.(key, node, path5);
|
|
227
227
|
if (identity.isSeq(node))
|
|
228
|
-
return visitor.Seq?.(key, node,
|
|
228
|
+
return visitor.Seq?.(key, node, path5);
|
|
229
229
|
if (identity.isPair(node))
|
|
230
|
-
return visitor.Pair?.(key, node,
|
|
230
|
+
return visitor.Pair?.(key, node, path5);
|
|
231
231
|
if (identity.isScalar(node))
|
|
232
|
-
return visitor.Scalar?.(key, node,
|
|
232
|
+
return visitor.Scalar?.(key, node, path5);
|
|
233
233
|
if (identity.isAlias(node))
|
|
234
|
-
return visitor.Alias?.(key, node,
|
|
234
|
+
return visitor.Alias?.(key, node, path5);
|
|
235
235
|
return void 0;
|
|
236
236
|
}
|
|
237
|
-
function replaceNode(key,
|
|
238
|
-
const parent =
|
|
237
|
+
function replaceNode(key, path5, node) {
|
|
238
|
+
const parent = path5[path5.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,
|
|
848
|
+
function collectionFromPath(schema, path5, value) {
|
|
849
849
|
let v2 = value;
|
|
850
|
-
for (let i =
|
|
851
|
-
const k2 =
|
|
850
|
+
for (let i = path5.length - 1; i >= 0; --i) {
|
|
851
|
+
const k2 = path5[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 = (
|
|
870
|
+
var isEmptyPath = (path5) => path5 == null || typeof path5 === "object" && !!path5[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(
|
|
901
|
-
if (isEmptyPath(
|
|
900
|
+
addIn(path5, value) {
|
|
901
|
+
if (isEmptyPath(path5))
|
|
902
902
|
this.add(value);
|
|
903
903
|
else {
|
|
904
|
-
const [key, ...rest] =
|
|
904
|
+
const [key, ...rest] = path5;
|
|
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(
|
|
919
|
-
const [key, ...rest] =
|
|
918
|
+
deleteIn(path5) {
|
|
919
|
+
const [key, ...rest] = path5;
|
|
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(
|
|
934
|
-
const [key, ...rest] =
|
|
933
|
+
getIn(path5, keepScalar) {
|
|
934
|
+
const [key, ...rest] = path5;
|
|
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(
|
|
953
|
-
const [key, ...rest] =
|
|
952
|
+
hasIn(path5) {
|
|
953
|
+
const [key, ...rest] = path5;
|
|
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(
|
|
964
|
-
const [key, ...rest] =
|
|
963
|
+
setIn(path5, value) {
|
|
964
|
+
const [key, ...rest] = path5;
|
|
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(
|
|
3479
|
+
addIn(path5, value) {
|
|
3480
3480
|
if (assertCollection(this.contents))
|
|
3481
|
-
this.contents.addIn(
|
|
3481
|
+
this.contents.addIn(path5, 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(
|
|
3557
|
-
if (Collection.isEmptyPath(
|
|
3556
|
+
deleteIn(path5) {
|
|
3557
|
+
if (Collection.isEmptyPath(path5)) {
|
|
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(
|
|
3563
|
+
return assertCollection(this.contents) ? this.contents.deleteIn(path5) : 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(
|
|
3579
|
-
if (Collection.isEmptyPath(
|
|
3578
|
+
getIn(path5, keepScalar) {
|
|
3579
|
+
if (Collection.isEmptyPath(path5))
|
|
3580
3580
|
return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
|
|
3581
|
-
return identity.isCollection(this.contents) ? this.contents.getIn(
|
|
3581
|
+
return identity.isCollection(this.contents) ? this.contents.getIn(path5, 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(
|
|
3593
|
-
if (Collection.isEmptyPath(
|
|
3592
|
+
hasIn(path5) {
|
|
3593
|
+
if (Collection.isEmptyPath(path5))
|
|
3594
3594
|
return this.contents !== void 0;
|
|
3595
|
-
return identity.isCollection(this.contents) ? this.contents.hasIn(
|
|
3595
|
+
return identity.isCollection(this.contents) ? this.contents.hasIn(path5) : 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(
|
|
3613
|
-
if (Collection.isEmptyPath(
|
|
3612
|
+
setIn(path5, value) {
|
|
3613
|
+
if (Collection.isEmptyPath(path5)) {
|
|
3614
3614
|
this.contents = value;
|
|
3615
3615
|
} else if (this.contents == null) {
|
|
3616
|
-
this.contents = Collection.collectionFromPath(this.schema, Array.from(
|
|
3616
|
+
this.contents = Collection.collectionFromPath(this.schema, Array.from(path5), value);
|
|
3617
3617
|
} else if (assertCollection(this.contents)) {
|
|
3618
|
-
this.contents.setIn(
|
|
3618
|
+
this.contents.setIn(path5, 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,
|
|
5578
|
+
visit.itemAtPath = (cst, path5) => {
|
|
5579
5579
|
let item = cst;
|
|
5580
|
-
for (const [field, index] of
|
|
5580
|
+
for (const [field, index] of path5) {
|
|
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,
|
|
5590
|
-
const parent = visit.itemAtPath(cst,
|
|
5591
|
-
const field =
|
|
5589
|
+
visit.parentCollection = (cst, path5) => {
|
|
5590
|
+
const parent = visit.itemAtPath(cst, path5.slice(0, -1));
|
|
5591
|
+
const field = path5[path5.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(
|
|
5598
|
-
let ctrl = visitor(item,
|
|
5597
|
+
function _visit(path5, item, visitor) {
|
|
5598
|
+
let ctrl = visitor(item, path5);
|
|
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(
|
|
5605
|
+
const ci2 = _visit(Object.freeze(path5.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,
|
|
5616
|
+
ctrl = ctrl(item, path5);
|
|
5617
5617
|
}
|
|
5618
5618
|
}
|
|
5619
|
-
return typeof ctrl === "function" ? ctrl(item,
|
|
5619
|
+
return typeof ctrl === "function" ? ctrl(item, path5) : ctrl;
|
|
5620
5620
|
}
|
|
5621
5621
|
exports.visit = visit;
|
|
5622
5622
|
}
|
|
@@ -7369,8 +7369,8 @@ var require_dist = __commonJS({
|
|
|
7369
7369
|
|
|
7370
7370
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
7371
7371
|
var import_yaml = __toESM(require_dist(), 1);
|
|
7372
|
-
import { mkdir as
|
|
7373
|
-
import
|
|
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";
|
|
7374
7374
|
|
|
7375
7375
|
// node_modules/@opencode-ai/plugin/node_modules/zod/v4/classic/external.js
|
|
7376
7376
|
var external_exports = {};
|
|
@@ -8103,10 +8103,10 @@ function mergeDefs(...defs) {
|
|
|
8103
8103
|
function cloneDef(schema) {
|
|
8104
8104
|
return mergeDefs(schema._zod.def);
|
|
8105
8105
|
}
|
|
8106
|
-
function getElementAtPath(obj,
|
|
8107
|
-
if (!
|
|
8106
|
+
function getElementAtPath(obj, path5) {
|
|
8107
|
+
if (!path5)
|
|
8108
8108
|
return obj;
|
|
8109
|
-
return
|
|
8109
|
+
return path5.reduce((acc, key) => acc?.[key], obj);
|
|
8110
8110
|
}
|
|
8111
8111
|
function promiseAllObject(promisesObj) {
|
|
8112
8112
|
const keys = Object.keys(promisesObj);
|
|
@@ -8467,11 +8467,11 @@ function aborted(x, startIndex = 0) {
|
|
|
8467
8467
|
}
|
|
8468
8468
|
return false;
|
|
8469
8469
|
}
|
|
8470
|
-
function prefixIssues(
|
|
8470
|
+
function prefixIssues(path5, issues) {
|
|
8471
8471
|
return issues.map((iss) => {
|
|
8472
8472
|
var _a;
|
|
8473
8473
|
(_a = iss).path ?? (_a.path = []);
|
|
8474
|
-
iss.path.unshift(
|
|
8474
|
+
iss.path.unshift(path5);
|
|
8475
8475
|
return iss;
|
|
8476
8476
|
});
|
|
8477
8477
|
}
|
|
@@ -8639,7 +8639,7 @@ function treeifyError(error45, _mapper) {
|
|
|
8639
8639
|
return issue2.message;
|
|
8640
8640
|
};
|
|
8641
8641
|
const result = { errors: [] };
|
|
8642
|
-
const processError = (error46,
|
|
8642
|
+
const processError = (error46, path5 = []) => {
|
|
8643
8643
|
var _a, _b;
|
|
8644
8644
|
for (const issue2 of error46.issues) {
|
|
8645
8645
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
@@ -8649,7 +8649,7 @@ function treeifyError(error45, _mapper) {
|
|
|
8649
8649
|
} else if (issue2.code === "invalid_element") {
|
|
8650
8650
|
processError({ issues: issue2.issues }, issue2.path);
|
|
8651
8651
|
} else {
|
|
8652
|
-
const fullpath = [...
|
|
8652
|
+
const fullpath = [...path5, ...issue2.path];
|
|
8653
8653
|
if (fullpath.length === 0) {
|
|
8654
8654
|
result.errors.push(mapper(issue2));
|
|
8655
8655
|
continue;
|
|
@@ -8681,8 +8681,8 @@ function treeifyError(error45, _mapper) {
|
|
|
8681
8681
|
}
|
|
8682
8682
|
function toDotPath(_path) {
|
|
8683
8683
|
const segs = [];
|
|
8684
|
-
const
|
|
8685
|
-
for (const seg of
|
|
8684
|
+
const path5 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
8685
|
+
for (const seg of path5) {
|
|
8686
8686
|
if (typeof seg === "number")
|
|
8687
8687
|
segs.push(`[${seg}]`);
|
|
8688
8688
|
else if (typeof seg === "symbol")
|
|
@@ -19882,11 +19882,230 @@ async function reportWorkPackObservations(credentials, kind, workPacks) {
|
|
|
19882
19882
|
}
|
|
19883
19883
|
}
|
|
19884
19884
|
|
|
19885
|
+
// packages/shared/src/contracts/models.ts
|
|
19886
|
+
var BUILT_IN_OPENROUTER_MODELS = [
|
|
19887
|
+
{
|
|
19888
|
+
id: "anthropic/claude-sonnet-4-6",
|
|
19889
|
+
name: "Assistente de trabalho profundo",
|
|
19890
|
+
approvedByDefault: true,
|
|
19891
|
+
requiredInConfig: false,
|
|
19892
|
+
upstreamModel: "anthropic/claude-sonnet-4.6",
|
|
19893
|
+
metadata: {
|
|
19894
|
+
family: "anthropic",
|
|
19895
|
+
release_date: "2026-02-17",
|
|
19896
|
+
attachment: true,
|
|
19897
|
+
reasoning: true,
|
|
19898
|
+
temperature: true,
|
|
19899
|
+
tool_call: true,
|
|
19900
|
+
limit: { context: 1e6, output: 128e3 },
|
|
19901
|
+
modalities: { input: ["text", "image", "pdf"], output: ["text"] }
|
|
19902
|
+
}
|
|
19903
|
+
},
|
|
19904
|
+
{
|
|
19905
|
+
id: "anthropic/claude-haiku-4-5",
|
|
19906
|
+
name: "Assistente r\xE1pido",
|
|
19907
|
+
approvedByDefault: true,
|
|
19908
|
+
requiredInConfig: false,
|
|
19909
|
+
upstreamModel: "anthropic/claude-haiku-4.5",
|
|
19910
|
+
metadata: {
|
|
19911
|
+
family: "anthropic",
|
|
19912
|
+
release_date: "2025-10-15",
|
|
19913
|
+
attachment: true,
|
|
19914
|
+
reasoning: true,
|
|
19915
|
+
temperature: true,
|
|
19916
|
+
tool_call: true,
|
|
19917
|
+
limit: { context: 2e5, output: 64e3 },
|
|
19918
|
+
modalities: { input: ["text", "image", "pdf"], output: ["text"] }
|
|
19919
|
+
}
|
|
19920
|
+
},
|
|
19921
|
+
{
|
|
19922
|
+
id: "openai/gpt-5.4-mini",
|
|
19923
|
+
name: "Assistente de ficheiros e ecr\xE3",
|
|
19924
|
+
approvedByDefault: true,
|
|
19925
|
+
requiredInConfig: false,
|
|
19926
|
+
metadata: {
|
|
19927
|
+
family: "gpt-mini",
|
|
19928
|
+
release_date: "2026-03-17",
|
|
19929
|
+
attachment: true,
|
|
19930
|
+
reasoning: true,
|
|
19931
|
+
temperature: false,
|
|
19932
|
+
tool_call: true,
|
|
19933
|
+
limit: { context: 4e5, input: 272e3, output: 128e3 },
|
|
19934
|
+
modalities: { input: ["text", "image", "pdf"], output: ["text"] },
|
|
19935
|
+
variants: openRouterReasoningVariants(["none", "xhigh"])
|
|
19936
|
+
}
|
|
19937
|
+
},
|
|
19938
|
+
{
|
|
19939
|
+
id: "minimax/minimax-m3",
|
|
19940
|
+
name: "Assistente de pesquisa",
|
|
19941
|
+
approvedByDefault: true,
|
|
19942
|
+
requiredInConfig: false,
|
|
19943
|
+
metadata: {
|
|
19944
|
+
family: "minimax",
|
|
19945
|
+
release_date: "2026-04-07",
|
|
19946
|
+
attachment: true,
|
|
19947
|
+
reasoning: true,
|
|
19948
|
+
temperature: true,
|
|
19949
|
+
tool_call: true,
|
|
19950
|
+
limit: { context: 524288, output: 512e3 },
|
|
19951
|
+
modalities: { input: ["text", "image", "video"], output: ["text"] }
|
|
19952
|
+
}
|
|
19953
|
+
},
|
|
19954
|
+
{
|
|
19955
|
+
id: "minimax/minimax-m2.7",
|
|
19956
|
+
name: "Assistente de reda\xE7\xE3o",
|
|
19957
|
+
approvedByDefault: true,
|
|
19958
|
+
requiredInConfig: false,
|
|
19959
|
+
metadata: {
|
|
19960
|
+
family: "minimax",
|
|
19961
|
+
release_date: "2026-03-18",
|
|
19962
|
+
attachment: false,
|
|
19963
|
+
reasoning: true,
|
|
19964
|
+
temperature: true,
|
|
19965
|
+
tool_call: true,
|
|
19966
|
+
limit: { context: 196608, output: 196608 },
|
|
19967
|
+
modalities: { input: ["text"], output: ["text"] }
|
|
19968
|
+
}
|
|
19969
|
+
},
|
|
19970
|
+
{
|
|
19971
|
+
id: "xiaomi/mimo-v2.5",
|
|
19972
|
+
name: "Assistente de revis\xE3o multim\xE9dia",
|
|
19973
|
+
approvedByDefault: true,
|
|
19974
|
+
requiredInConfig: false,
|
|
19975
|
+
metadata: {
|
|
19976
|
+
family: "mimo",
|
|
19977
|
+
release_date: "2026-04-22",
|
|
19978
|
+
attachment: true,
|
|
19979
|
+
reasoning: true,
|
|
19980
|
+
temperature: true,
|
|
19981
|
+
tool_call: true,
|
|
19982
|
+
interleaved: { field: "reasoning_details" },
|
|
19983
|
+
limit: { context: 32e3, output: 131072 },
|
|
19984
|
+
modalities: { input: ["text", "audio", "image", "video"], output: ["text"] }
|
|
19985
|
+
}
|
|
19986
|
+
},
|
|
19987
|
+
{
|
|
19988
|
+
id: "xiaomi/mimo-v2.5-pro",
|
|
19989
|
+
name: "Assistente de contexto longo",
|
|
19990
|
+
approvedByDefault: true,
|
|
19991
|
+
requiredInConfig: false,
|
|
19992
|
+
metadata: {
|
|
19993
|
+
family: "mimo",
|
|
19994
|
+
release_date: "2026-04-22",
|
|
19995
|
+
attachment: false,
|
|
19996
|
+
reasoning: true,
|
|
19997
|
+
temperature: true,
|
|
19998
|
+
tool_call: true,
|
|
19999
|
+
interleaved: { field: "reasoning_content" },
|
|
20000
|
+
limit: { context: 1048576, output: 131072 },
|
|
20001
|
+
modalities: { input: ["text"], output: ["text"] }
|
|
20002
|
+
}
|
|
20003
|
+
},
|
|
20004
|
+
{
|
|
20005
|
+
id: "z-ai/glm-5.2",
|
|
20006
|
+
name: "Assistente de an\xE1lise",
|
|
20007
|
+
approvedByDefault: false,
|
|
20008
|
+
requiredInConfig: false,
|
|
20009
|
+
metadata: {
|
|
20010
|
+
family: "glm",
|
|
20011
|
+
release_date: "2026-02-12",
|
|
20012
|
+
attachment: false,
|
|
20013
|
+
reasoning: true,
|
|
20014
|
+
temperature: true,
|
|
20015
|
+
tool_call: true,
|
|
20016
|
+
interleaved: { field: "reasoning_content" },
|
|
20017
|
+
limit: { context: 1048576, output: 32768 },
|
|
20018
|
+
modalities: { input: ["text"], output: ["text"] }
|
|
20019
|
+
}
|
|
20020
|
+
}
|
|
20021
|
+
];
|
|
20022
|
+
var APPROVED_MODELS = BUILT_IN_OPENROUTER_MODELS.filter((model) => model.approvedByDefault).map(stripCatalogFlags);
|
|
20023
|
+
function cloneModel(model) {
|
|
20024
|
+
return {
|
|
20025
|
+
id: model.id,
|
|
20026
|
+
name: model.name,
|
|
20027
|
+
...model.provider ? { provider: model.provider } : {},
|
|
20028
|
+
...model.upstreamModel ? { upstreamModel: model.upstreamModel } : {},
|
|
20029
|
+
...model.billingMode ? { billingMode: model.billingMode } : {},
|
|
20030
|
+
...model.metadata ? { metadata: structuredClone(model.metadata) } : {}
|
|
20031
|
+
};
|
|
20032
|
+
}
|
|
20033
|
+
function stripCatalogFlags(model) {
|
|
20034
|
+
const { approvedByDefault: _approvedByDefault, requiredInConfig: _requiredInConfig, ...approved } = model;
|
|
20035
|
+
return cloneModel(approved);
|
|
20036
|
+
}
|
|
20037
|
+
function openRouterReasoningVariants(efforts) {
|
|
20038
|
+
return Object.fromEntries(efforts.map((effort) => [effort, { reasoning: { effort } }]));
|
|
20039
|
+
}
|
|
20040
|
+
|
|
20041
|
+
// packages/shared/src/contracts/debugTrace.ts
|
|
20042
|
+
var DEFAULT_DEBUG_TRACE_LIMITS = {
|
|
20043
|
+
eventEnvelopeBytes: 256 * 1024,
|
|
20044
|
+
artifactChunkBytes: 2 * 1024 * 1024,
|
|
20045
|
+
// Serialized request bodies must remain comfortably below Vercel's 4.5 MB
|
|
20046
|
+
// function request limit after JSON and base64 overhead.
|
|
20047
|
+
uploadBatchBytes: 3 * 1024 * 1024,
|
|
20048
|
+
uploadBatchRecords: 100,
|
|
20049
|
+
fileSnapshotBytes: 1024 * 1024,
|
|
20050
|
+
serverTraceBudgetBytes: 250 * 1024 * 1024,
|
|
20051
|
+
workerTraceQuotaPer24h: 100,
|
|
20052
|
+
workerBytesQuotaPer24h: 1024 * 1024 * 1024,
|
|
20053
|
+
localQueueBytes: 1024 * 1024 * 1024,
|
|
20054
|
+
retryBackoffMinMs: 5e3,
|
|
20055
|
+
retryBackoffMaxMs: 5 * 60 * 1e3,
|
|
20056
|
+
queueMaxAgeDays: 7,
|
|
20057
|
+
rawTempExposureSeconds: 15 * 60
|
|
20058
|
+
};
|
|
20059
|
+
|
|
20060
|
+
// packages/shared/src/contracts/settings.ts
|
|
20061
|
+
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.13";
|
|
20062
|
+
var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
|
|
20063
|
+
var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
|
|
20064
|
+
var FIRECRAWL_KEYLESS_MCP_NAME = "firecrawl";
|
|
20065
|
+
var FIRECRAWL_KEYLESS_PERMISSION = `${FIRECRAWL_KEYLESS_MCP_NAME}_*`;
|
|
20066
|
+
|
|
20067
|
+
// packages/shared/src/workPackBaseline.ts
|
|
20068
|
+
function normalizePackExtensionModel(pathLabel, content, approvedModelIds, slug) {
|
|
20069
|
+
const match = /^---\n([\s\S]+?)\n---/.exec(content);
|
|
20070
|
+
const frontmatter = match?.[1];
|
|
20071
|
+
if (!match || frontmatter === void 0) return content;
|
|
20072
|
+
const modelLines = [...frontmatter.matchAll(/^model:\s*(.*?)\s*$/gm)];
|
|
20073
|
+
if (modelLines.length === 0) return content;
|
|
20074
|
+
if (modelLines.length > 1) {
|
|
20075
|
+
throw new Error(`A extens\xE3o ${pathLabel} do pacote de trabalho ${slug} define model mais do que uma vez`);
|
|
20076
|
+
}
|
|
20077
|
+
const rawModel = modelLines[0][1].replace(/^(['"])(.*)\1$/, "$2");
|
|
20078
|
+
const separator = rawModel.indexOf("/");
|
|
20079
|
+
const provider = separator > 0 ? rawModel.slice(0, separator) : "";
|
|
20080
|
+
const modelId = separator > 0 ? rawModel.slice(separator + 1) : "";
|
|
20081
|
+
if (provider !== "forge" && provider !== "openrouter" || !approvedModelIds.has(modelId)) {
|
|
20082
|
+
throw new Error(
|
|
20083
|
+
`A extens\xE3o ${pathLabel} do pacote de trabalho ${slug} usa um modelo que n\xE3o est\xE1 aprovado no Forge`
|
|
20084
|
+
);
|
|
20085
|
+
}
|
|
20086
|
+
if (provider === "forge") return content;
|
|
20087
|
+
const normalizedFrontmatter = frontmatter.replace(/^model:\s*.*?$/m, `model: forge/${modelId}`);
|
|
20088
|
+
return `${content.slice(0, match.index)}---
|
|
20089
|
+
${normalizedFrontmatter}
|
|
20090
|
+
---${content.slice(match.index + match[0].length)}`;
|
|
20091
|
+
}
|
|
20092
|
+
function canonicalWorkPackState(state) {
|
|
20093
|
+
const compare = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
20094
|
+
return JSON.stringify({
|
|
20095
|
+
schemaVersion: 1,
|
|
20096
|
+
version: state.version,
|
|
20097
|
+
files: [...state.files].sort((a, b2) => compare(a.path, b2.path)),
|
|
20098
|
+
directories: [...state.directories].sort(compare),
|
|
20099
|
+
agents: [...state.agents].sort((a, b2) => compare(a.filename, b2.filename)),
|
|
20100
|
+
commands: [...state.commands].sort((a, b2) => compare(a.filename, b2.filename))
|
|
20101
|
+
});
|
|
20102
|
+
}
|
|
20103
|
+
|
|
19885
20104
|
// packages/cli/src/sync.ts
|
|
19886
|
-
import { createHash } from "node:crypto";
|
|
19887
|
-
import { chmod, cp, lstat, mkdtemp, mkdir, readdir, readFile, rm, rename, writeFile } from "node:fs/promises";
|
|
20105
|
+
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";
|
|
19888
20107
|
import os4 from "node:os";
|
|
19889
|
-
import
|
|
20108
|
+
import path3 from "node:path";
|
|
19890
20109
|
|
|
19891
20110
|
// node_modules/tar/dist/esm/index.min.js
|
|
19892
20111
|
import Qr from "events";
|
|
@@ -22857,210 +23076,28 @@ var To = (s3) => {
|
|
|
22857
23076
|
s3.mtimeCache || (s3.mtimeCache = /* @__PURE__ */ new Map()), s3.filter = t ? (e, i) => t(e, i) && !((s3.mtimeCache?.get(e) ?? i.mtime ?? 0) > (i.mtime ?? 0)) : (e, i) => !((s3.mtimeCache?.get(e) ?? i.mtime ?? 0) > (i.mtime ?? 0));
|
|
22858
23077
|
};
|
|
22859
23078
|
|
|
22860
|
-
// packages/
|
|
22861
|
-
|
|
22862
|
-
|
|
22863
|
-
|
|
22864
|
-
|
|
22865
|
-
|
|
22866
|
-
|
|
22867
|
-
|
|
22868
|
-
|
|
22869
|
-
|
|
22870
|
-
|
|
22871
|
-
|
|
22872
|
-
|
|
22873
|
-
|
|
22874
|
-
|
|
22875
|
-
|
|
22876
|
-
|
|
22877
|
-
|
|
22878
|
-
|
|
22879
|
-
|
|
22880
|
-
|
|
22881
|
-
|
|
22882
|
-
approvedByDefault: true,
|
|
22883
|
-
requiredInConfig: false,
|
|
22884
|
-
upstreamModel: "anthropic/claude-haiku-4.5",
|
|
22885
|
-
metadata: {
|
|
22886
|
-
family: "anthropic",
|
|
22887
|
-
release_date: "2025-10-15",
|
|
22888
|
-
attachment: true,
|
|
22889
|
-
reasoning: true,
|
|
22890
|
-
temperature: true,
|
|
22891
|
-
tool_call: true,
|
|
22892
|
-
limit: { context: 2e5, output: 64e3 },
|
|
22893
|
-
modalities: { input: ["text", "image", "pdf"], output: ["text"] }
|
|
22894
|
-
}
|
|
22895
|
-
},
|
|
22896
|
-
{
|
|
22897
|
-
id: "openai/gpt-5.4-mini",
|
|
22898
|
-
name: "Assistente de ficheiros e ecr\xE3",
|
|
22899
|
-
approvedByDefault: true,
|
|
22900
|
-
requiredInConfig: false,
|
|
22901
|
-
metadata: {
|
|
22902
|
-
family: "gpt-mini",
|
|
22903
|
-
release_date: "2026-03-17",
|
|
22904
|
-
attachment: true,
|
|
22905
|
-
reasoning: true,
|
|
22906
|
-
temperature: false,
|
|
22907
|
-
tool_call: true,
|
|
22908
|
-
limit: { context: 4e5, input: 272e3, output: 128e3 },
|
|
22909
|
-
modalities: { input: ["text", "image", "pdf"], output: ["text"] },
|
|
22910
|
-
variants: openRouterReasoningVariants(["none", "xhigh"])
|
|
22911
|
-
}
|
|
22912
|
-
},
|
|
22913
|
-
{
|
|
22914
|
-
id: "minimax/minimax-m3",
|
|
22915
|
-
name: "Assistente de pesquisa",
|
|
22916
|
-
approvedByDefault: true,
|
|
22917
|
-
requiredInConfig: false,
|
|
22918
|
-
metadata: {
|
|
22919
|
-
family: "minimax",
|
|
22920
|
-
release_date: "2026-04-07",
|
|
22921
|
-
attachment: true,
|
|
22922
|
-
reasoning: true,
|
|
22923
|
-
temperature: true,
|
|
22924
|
-
tool_call: true,
|
|
22925
|
-
limit: { context: 524288, output: 512e3 },
|
|
22926
|
-
modalities: { input: ["text", "image", "video"], output: ["text"] }
|
|
22927
|
-
}
|
|
22928
|
-
},
|
|
22929
|
-
{
|
|
22930
|
-
id: "minimax/minimax-m2.7",
|
|
22931
|
-
name: "Assistente de reda\xE7\xE3o",
|
|
22932
|
-
approvedByDefault: true,
|
|
22933
|
-
requiredInConfig: false,
|
|
22934
|
-
metadata: {
|
|
22935
|
-
family: "minimax",
|
|
22936
|
-
release_date: "2026-03-18",
|
|
22937
|
-
attachment: false,
|
|
22938
|
-
reasoning: true,
|
|
22939
|
-
temperature: true,
|
|
22940
|
-
tool_call: true,
|
|
22941
|
-
limit: { context: 196608, output: 196608 },
|
|
22942
|
-
modalities: { input: ["text"], output: ["text"] }
|
|
22943
|
-
}
|
|
22944
|
-
},
|
|
22945
|
-
{
|
|
22946
|
-
id: "xiaomi/mimo-v2.5",
|
|
22947
|
-
name: "Assistente de revis\xE3o multim\xE9dia",
|
|
22948
|
-
approvedByDefault: true,
|
|
22949
|
-
requiredInConfig: false,
|
|
22950
|
-
metadata: {
|
|
22951
|
-
family: "mimo",
|
|
22952
|
-
release_date: "2026-04-22",
|
|
22953
|
-
attachment: true,
|
|
22954
|
-
reasoning: true,
|
|
22955
|
-
temperature: true,
|
|
22956
|
-
tool_call: true,
|
|
22957
|
-
interleaved: { field: "reasoning_details" },
|
|
22958
|
-
limit: { context: 32e3, output: 131072 },
|
|
22959
|
-
modalities: { input: ["text", "audio", "image", "video"], output: ["text"] }
|
|
22960
|
-
}
|
|
22961
|
-
},
|
|
22962
|
-
{
|
|
22963
|
-
id: "xiaomi/mimo-v2.5-pro",
|
|
22964
|
-
name: "Assistente de contexto longo",
|
|
22965
|
-
approvedByDefault: true,
|
|
22966
|
-
requiredInConfig: false,
|
|
22967
|
-
metadata: {
|
|
22968
|
-
family: "mimo",
|
|
22969
|
-
release_date: "2026-04-22",
|
|
22970
|
-
attachment: false,
|
|
22971
|
-
reasoning: true,
|
|
22972
|
-
temperature: true,
|
|
22973
|
-
tool_call: true,
|
|
22974
|
-
interleaved: { field: "reasoning_content" },
|
|
22975
|
-
limit: { context: 1048576, output: 131072 },
|
|
22976
|
-
modalities: { input: ["text"], output: ["text"] }
|
|
22977
|
-
}
|
|
22978
|
-
},
|
|
22979
|
-
{
|
|
22980
|
-
id: "z-ai/glm-5.2",
|
|
22981
|
-
name: "Assistente de an\xE1lise",
|
|
22982
|
-
approvedByDefault: false,
|
|
22983
|
-
requiredInConfig: false,
|
|
22984
|
-
metadata: {
|
|
22985
|
-
family: "glm",
|
|
22986
|
-
release_date: "2026-02-12",
|
|
22987
|
-
attachment: false,
|
|
22988
|
-
reasoning: true,
|
|
22989
|
-
temperature: true,
|
|
22990
|
-
tool_call: true,
|
|
22991
|
-
interleaved: { field: "reasoning_content" },
|
|
22992
|
-
limit: { context: 1048576, output: 32768 },
|
|
22993
|
-
modalities: { input: ["text"], output: ["text"] }
|
|
22994
|
-
}
|
|
22995
|
-
}
|
|
22996
|
-
];
|
|
22997
|
-
var APPROVED_MODELS = BUILT_IN_OPENROUTER_MODELS.filter((model) => model.approvedByDefault).map(stripCatalogFlags);
|
|
22998
|
-
function cloneModel(model) {
|
|
22999
|
-
return {
|
|
23000
|
-
id: model.id,
|
|
23001
|
-
name: model.name,
|
|
23002
|
-
...model.provider ? { provider: model.provider } : {},
|
|
23003
|
-
...model.upstreamModel ? { upstreamModel: model.upstreamModel } : {},
|
|
23004
|
-
...model.billingMode ? { billingMode: model.billingMode } : {},
|
|
23005
|
-
...model.metadata ? { metadata: structuredClone(model.metadata) } : {}
|
|
23006
|
-
};
|
|
23007
|
-
}
|
|
23008
|
-
function stripCatalogFlags(model) {
|
|
23009
|
-
const { approvedByDefault: _approvedByDefault, requiredInConfig: _requiredInConfig, ...approved } = model;
|
|
23010
|
-
return cloneModel(approved);
|
|
23011
|
-
}
|
|
23012
|
-
function openRouterReasoningVariants(efforts) {
|
|
23013
|
-
return Object.fromEntries(efforts.map((effort) => [effort, { reasoning: { effort } }]));
|
|
23014
|
-
}
|
|
23015
|
-
|
|
23016
|
-
// packages/shared/src/contracts/debugTrace.ts
|
|
23017
|
-
var DEFAULT_DEBUG_TRACE_LIMITS = {
|
|
23018
|
-
eventEnvelopeBytes: 256 * 1024,
|
|
23019
|
-
artifactChunkBytes: 2 * 1024 * 1024,
|
|
23020
|
-
// Serialized request bodies must remain comfortably below Vercel's 4.5 MB
|
|
23021
|
-
// function request limit after JSON and base64 overhead.
|
|
23022
|
-
uploadBatchBytes: 3 * 1024 * 1024,
|
|
23023
|
-
uploadBatchRecords: 100,
|
|
23024
|
-
fileSnapshotBytes: 1024 * 1024,
|
|
23025
|
-
serverTraceBudgetBytes: 250 * 1024 * 1024,
|
|
23026
|
-
workerTraceQuotaPer24h: 100,
|
|
23027
|
-
workerBytesQuotaPer24h: 1024 * 1024 * 1024,
|
|
23028
|
-
localQueueBytes: 1024 * 1024 * 1024,
|
|
23029
|
-
retryBackoffMinMs: 5e3,
|
|
23030
|
-
retryBackoffMaxMs: 5 * 60 * 1e3,
|
|
23031
|
-
queueMaxAgeDays: 7,
|
|
23032
|
-
rawTempExposureSeconds: 15 * 60
|
|
23033
|
-
};
|
|
23034
|
-
|
|
23035
|
-
// packages/shared/src/contracts/settings.ts
|
|
23036
|
-
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.11";
|
|
23037
|
-
var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
|
|
23038
|
-
var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
|
|
23039
|
-
var FIRECRAWL_KEYLESS_MCP_NAME = "firecrawl";
|
|
23040
|
-
var FIRECRAWL_KEYLESS_PERMISSION = `${FIRECRAWL_KEYLESS_MCP_NAME}_*`;
|
|
23041
|
-
|
|
23042
|
-
// packages/cli/src/workPackReconciler.ts
|
|
23043
|
-
async function reconcileWorkPacks(input) {
|
|
23044
|
-
assertUniqueSlugs(input.desired, "desired");
|
|
23045
|
-
assertUniqueSlugs(input.managed, "managed");
|
|
23046
|
-
const outcomes = [];
|
|
23047
|
-
let desiredFailed = false;
|
|
23048
|
-
let uncertain = false;
|
|
23049
|
-
const desiredSlugs = new Set(input.desired.map((pack) => pack.slug));
|
|
23050
|
-
const omittedManaged = input.managed.filter((pack) => !desiredSlugs.has(pack.slug));
|
|
23051
|
-
const earlyPrunedSlugs = /* @__PURE__ */ new Set();
|
|
23052
|
-
for (const pack of input.desired.filter((candidate) => !candidate.enabled)) {
|
|
23053
|
-
const operation = {
|
|
23054
|
-
action: "remove",
|
|
23055
|
-
reason: "desired",
|
|
23056
|
-
pack
|
|
23057
|
-
};
|
|
23058
|
-
const outcome = await runOperation(operation, input.operate);
|
|
23059
|
-
outcomes.push(outcome);
|
|
23060
|
-
if (outcome.status === "failed") desiredFailed = true;
|
|
23061
|
-
if (outcome.status === "recovery-uncertain") {
|
|
23062
|
-
uncertain = true;
|
|
23063
|
-
break;
|
|
23079
|
+
// packages/cli/src/workPackReconciler.ts
|
|
23080
|
+
async function reconcileWorkPacks(input) {
|
|
23081
|
+
assertUniqueSlugs(input.desired, "desired");
|
|
23082
|
+
assertUniqueSlugs(input.managed, "managed");
|
|
23083
|
+
const outcomes = [];
|
|
23084
|
+
let desiredFailed = false;
|
|
23085
|
+
let uncertain = false;
|
|
23086
|
+
const desiredSlugs = new Set(input.desired.map((pack) => pack.slug));
|
|
23087
|
+
const omittedManaged = input.managed.filter((pack) => !desiredSlugs.has(pack.slug));
|
|
23088
|
+
const earlyPrunedSlugs = /* @__PURE__ */ new Set();
|
|
23089
|
+
for (const pack of input.desired.filter((candidate) => !candidate.enabled)) {
|
|
23090
|
+
const operation = {
|
|
23091
|
+
action: "remove",
|
|
23092
|
+
reason: "desired",
|
|
23093
|
+
pack
|
|
23094
|
+
};
|
|
23095
|
+
const outcome = await runOperation(operation, input.operate);
|
|
23096
|
+
outcomes.push(outcome);
|
|
23097
|
+
if (outcome.status === "failed") desiredFailed = true;
|
|
23098
|
+
if (outcome.status === "recovery-uncertain") {
|
|
23099
|
+
uncertain = true;
|
|
23100
|
+
break;
|
|
23064
23101
|
}
|
|
23065
23102
|
}
|
|
23066
23103
|
for (const pack of input.desired.filter((candidate) => candidate.enabled)) {
|
|
@@ -23120,6 +23157,17 @@ async function reconcileWorkPacks(input) {
|
|
|
23120
23157
|
}
|
|
23121
23158
|
}
|
|
23122
23159
|
}
|
|
23160
|
+
for (const [slug, code] of input.recoveryFailures ?? []) {
|
|
23161
|
+
if (outcomes.some((outcome) => outcome.slug === slug)) continue;
|
|
23162
|
+
outcomes.push({
|
|
23163
|
+
slug,
|
|
23164
|
+
action: "install",
|
|
23165
|
+
reason: "omitted",
|
|
23166
|
+
status: "failed",
|
|
23167
|
+
code: stableCode(code),
|
|
23168
|
+
message: `O pacote "${slug}" tem uma instala\xE7\xE3o interrompida que n\xE3o foi recuperada para preservar ficheiros locais. Corrija a causa indicada e volte a sincronizar.`
|
|
23169
|
+
});
|
|
23170
|
+
}
|
|
23123
23171
|
const receiptValue = {
|
|
23124
23172
|
schemaVersion: 1,
|
|
23125
23173
|
completedAt: (input.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
@@ -23212,8 +23260,155 @@ function assertUniqueSlugs(packs, label) {
|
|
|
23212
23260
|
}
|
|
23213
23261
|
}
|
|
23214
23262
|
|
|
23263
|
+
// packages/cli/src/workPackLocalState.ts
|
|
23264
|
+
import { createHash } from "node:crypto";
|
|
23265
|
+
import { lstat, mkdir, readFile, readdir, rename, writeFile } from "node:fs/promises";
|
|
23266
|
+
import path2 from "node:path";
|
|
23267
|
+
var WORK_PACK_LOCAL_STATE_FILENAME = ".forge-installed-state.json";
|
|
23268
|
+
async function writeWorkPackInstalledState(input) {
|
|
23269
|
+
const tree = await digestPackTree(input.packDir);
|
|
23270
|
+
if (!tree) throw new Error("O pacote de trabalho cont\xE9m uma entrada local n\xE3o regular");
|
|
23271
|
+
const state = {
|
|
23272
|
+
schemaVersion: 1,
|
|
23273
|
+
version: input.version,
|
|
23274
|
+
...tree,
|
|
23275
|
+
agents: digestProjectionContents(input.agents),
|
|
23276
|
+
commands: digestProjectionContents(input.commands)
|
|
23277
|
+
};
|
|
23278
|
+
await writeJsonAtomic(path2.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
|
|
23279
|
+
}
|
|
23280
|
+
async function checkWorkPackInstalledState(input) {
|
|
23281
|
+
const state = await readInstalledState(input.packDir);
|
|
23282
|
+
if (!state) return "missing";
|
|
23283
|
+
return await matchesInstalledState(input, state) ? "match" : "changed";
|
|
23284
|
+
}
|
|
23285
|
+
async function checkWorkPackTreeState(packDir) {
|
|
23286
|
+
const state = await readInstalledState(packDir);
|
|
23287
|
+
if (!state) return "missing";
|
|
23288
|
+
const tree = await digestPackTree(packDir).catch(() => void 0);
|
|
23289
|
+
return tree && sameTree(tree, state) ? "match" : "changed";
|
|
23290
|
+
}
|
|
23291
|
+
async function adoptWorkPackInstalledState(input) {
|
|
23292
|
+
const state = await readInstalledState(input.expectedPackDir);
|
|
23293
|
+
if (!state || !await matchesInstalledState(input, state)) return false;
|
|
23294
|
+
await writeJsonAtomic(path2.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
|
|
23295
|
+
return checkWorkPackInstalledState(input).then((result) => result === "match");
|
|
23296
|
+
}
|
|
23297
|
+
async function adoptVerifiedWorkPackState(input) {
|
|
23298
|
+
const tree = await digestPackTree(input.packDir);
|
|
23299
|
+
if (!tree) return false;
|
|
23300
|
+
const projections = async (kind, directory) => {
|
|
23301
|
+
const prefix = `${kind}/`;
|
|
23302
|
+
const expected = tree.files.filter((file2) => file2.path.startsWith(prefix) && !file2.path.slice(prefix.length).includes("/") && file2.path.endsWith(".md") && !file2.path.slice(prefix.length).startsWith("._"));
|
|
23303
|
+
const result = [];
|
|
23304
|
+
for (const file2 of expected) {
|
|
23305
|
+
const filename = file2.path.slice(prefix.length);
|
|
23306
|
+
const absolute = path2.join(directory, filename);
|
|
23307
|
+
const info = await lstat(absolute);
|
|
23308
|
+
if (!info.isFile() || info.isSymbolicLink()) throw new Error("Unsafe projection");
|
|
23309
|
+
result.push({ filename, sha256: digest(await readFile(absolute)) });
|
|
23310
|
+
}
|
|
23311
|
+
return result.sort((a, b2) => a.filename.localeCompare(b2.filename));
|
|
23312
|
+
};
|
|
23313
|
+
const state = {
|
|
23314
|
+
schemaVersion: 1,
|
|
23315
|
+
version: input.version,
|
|
23316
|
+
...tree,
|
|
23317
|
+
agents: await projections("agents", input.agentsDir),
|
|
23318
|
+
commands: await projections("commands", input.commandsDir)
|
|
23319
|
+
};
|
|
23320
|
+
if (digest(Buffer.from(canonicalWorkPackState(state))) !== input.fingerprint) return false;
|
|
23321
|
+
if (!await matchesInstalledState(input, state)) return false;
|
|
23322
|
+
await writeJsonAtomic(path2.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
|
|
23323
|
+
return await checkWorkPackInstalledState(input) === "match";
|
|
23324
|
+
}
|
|
23325
|
+
async function readInstalledState(packDir) {
|
|
23326
|
+
const raw = await readFile(path2.join(packDir, WORK_PACK_LOCAL_STATE_FILENAME), "utf8").catch(() => void 0);
|
|
23327
|
+
if (!raw) return void 0;
|
|
23328
|
+
try {
|
|
23329
|
+
const value = JSON.parse(raw);
|
|
23330
|
+
if (value.schemaVersion !== 1 || typeof value.version !== "string") return void 0;
|
|
23331
|
+
if (!validDigests(value.files, "path") || !validDigests(value.agents, "filename") || !validDigests(value.commands, "filename")) {
|
|
23332
|
+
return void 0;
|
|
23333
|
+
}
|
|
23334
|
+
if (!validDirectories(value.directories)) return void 0;
|
|
23335
|
+
return value;
|
|
23336
|
+
} catch {
|
|
23337
|
+
return void 0;
|
|
23338
|
+
}
|
|
23339
|
+
}
|
|
23340
|
+
async function digestPackTree(root) {
|
|
23341
|
+
const files = [];
|
|
23342
|
+
const directories = [];
|
|
23343
|
+
const visit = async (directory, prefix) => {
|
|
23344
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
23345
|
+
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
23346
|
+
if (!prefix && entry.name === WORK_PACK_LOCAL_STATE_FILENAME) continue;
|
|
23347
|
+
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
23348
|
+
const absolute = path2.join(directory, entry.name);
|
|
23349
|
+
if (entry.isDirectory()) {
|
|
23350
|
+
directories.push(relative);
|
|
23351
|
+
if (!await visit(absolute, relative)) return false;
|
|
23352
|
+
continue;
|
|
23353
|
+
}
|
|
23354
|
+
if (!entry.isFile()) return false;
|
|
23355
|
+
files.push({ path: relative, sha256: digest(await readFile(absolute)) });
|
|
23356
|
+
}
|
|
23357
|
+
return true;
|
|
23358
|
+
};
|
|
23359
|
+
return await visit(root, "") ? { files, directories } : void 0;
|
|
23360
|
+
}
|
|
23361
|
+
function digestProjectionContents(files) {
|
|
23362
|
+
return files.map((file2) => ({ filename: file2.filename, sha256: digest(Buffer.from(file2.content)) })).sort((left, right) => left.filename.localeCompare(right.filename));
|
|
23363
|
+
}
|
|
23364
|
+
async function projectionsMatch(directory, expected) {
|
|
23365
|
+
for (const projection of expected) {
|
|
23366
|
+
const absolute = path2.join(directory, projection.filename);
|
|
23367
|
+
const info = await lstat(absolute).catch(() => void 0);
|
|
23368
|
+
if (!info?.isFile() || info.isSymbolicLink()) return false;
|
|
23369
|
+
const bytes = await readFile(absolute).catch(() => void 0);
|
|
23370
|
+
if (!bytes || digest(bytes) !== projection.sha256) return false;
|
|
23371
|
+
}
|
|
23372
|
+
return true;
|
|
23373
|
+
}
|
|
23374
|
+
function validDigests(value, pathKey) {
|
|
23375
|
+
return Array.isArray(value) && value.every((entry) => typeof entry === "object" && entry !== null && typeof entry[pathKey] === "string" && typeof entry.sha256 === "string" && /^[a-f0-9]{64}$/.test(entry.sha256) && validRelativePath(entry[pathKey], pathKey === "filename"));
|
|
23376
|
+
}
|
|
23377
|
+
function validDirectories(value) {
|
|
23378
|
+
return Array.isArray(value) && value.every((entry) => typeof entry === "string" && validRelativePath(entry, false));
|
|
23379
|
+
}
|
|
23380
|
+
async function matchesInstalledState(input, state) {
|
|
23381
|
+
const tree = await digestPackTree(input.packDir).catch(() => void 0);
|
|
23382
|
+
if (!tree || !sameTree(tree, state)) return false;
|
|
23383
|
+
if (!await projectionsMatch(input.agentsDir, state.agents)) return false;
|
|
23384
|
+
return projectionsMatch(input.commandsDir, state.commands);
|
|
23385
|
+
}
|
|
23386
|
+
function validRelativePath(value, filenameOnly) {
|
|
23387
|
+
if (!value || path2.isAbsolute(value) || value.includes("\\")) return false;
|
|
23388
|
+
const parts = value.split("/");
|
|
23389
|
+
if (parts.some((part) => !part || part === "." || part === "..")) return false;
|
|
23390
|
+
return !filenameOnly || parts.length === 1;
|
|
23391
|
+
}
|
|
23392
|
+
function sameTree(left, right) {
|
|
23393
|
+
return sameDigests(left.files, right.files) && left.directories.length === right.directories.length && left.directories.every((entry, index) => entry === right.directories[index]);
|
|
23394
|
+
}
|
|
23395
|
+
function sameDigests(left, right) {
|
|
23396
|
+
return left.length === right.length && left.every((entry, index) => entry.path === right[index]?.path && entry.sha256 === right[index]?.sha256);
|
|
23397
|
+
}
|
|
23398
|
+
function digest(bytes) {
|
|
23399
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
23400
|
+
}
|
|
23401
|
+
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)}
|
|
23405
|
+
`);
|
|
23406
|
+
await rename(tempPath, filePath);
|
|
23407
|
+
}
|
|
23408
|
+
|
|
23215
23409
|
// packages/cli/src/sync.ts
|
|
23216
23410
|
var WORK_PACK_COMMITTED_MARKER = ".forge-replacement-committed";
|
|
23411
|
+
var WORK_PACK_TRANSACTION_SUFFIX = ".transaction";
|
|
23217
23412
|
var MAX_SYNC_ERROR_BODY_BYTES = 1536;
|
|
23218
23413
|
function extractErrorBody(response) {
|
|
23219
23414
|
return response.text().then((text) => text.slice(0, MAX_SYNC_ERROR_BODY_BYTES)).catch(() => "");
|
|
@@ -23254,14 +23449,14 @@ async function fetchManifest(credentials) {
|
|
|
23254
23449
|
return await response.json();
|
|
23255
23450
|
}
|
|
23256
23451
|
async function applyWorkPackManifest(paths, credentials, manifest, options) {
|
|
23257
|
-
await
|
|
23258
|
-
await
|
|
23259
|
-
const
|
|
23452
|
+
await mkdir2(paths.skillsDir, { recursive: true });
|
|
23453
|
+
await mkdir2(paths.commandsDir, { recursive: true });
|
|
23454
|
+
const recovery = await recoverInterruptedWorkPackInstalls(paths, options.cleanupWorkPackBackup, options.workPackProjectionBoundary);
|
|
23260
23455
|
const managed = await Promise.all((await managedWorkPackSlugs(paths.skillsDir)).map(async (slug) => ({
|
|
23261
23456
|
slug,
|
|
23262
|
-
version: (await
|
|
23263
|
-
agents: await readAgentRecord(
|
|
23264
|
-
commands: await readCommandRecord(
|
|
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))
|
|
23265
23460
|
})));
|
|
23266
23461
|
const desired = manifest.skills.map((skill) => ({
|
|
23267
23462
|
slug: skill.slug,
|
|
@@ -23274,8 +23469,18 @@ async function applyWorkPackManifest(paths, credentials, manifest, options) {
|
|
|
23274
23469
|
desired,
|
|
23275
23470
|
managed,
|
|
23276
23471
|
desiredIsComplete: manifest.workPacksComplete === true,
|
|
23277
|
-
operate: (operation) => operateWorkPack(
|
|
23278
|
-
|
|
23472
|
+
operate: (operation) => operateWorkPack(
|
|
23473
|
+
paths,
|
|
23474
|
+
credentials,
|
|
23475
|
+
skillBySlug,
|
|
23476
|
+
approvedModelIds,
|
|
23477
|
+
recovery.cleanupPendingSlugs,
|
|
23478
|
+
recovery.failures,
|
|
23479
|
+
operation,
|
|
23480
|
+
options
|
|
23481
|
+
),
|
|
23482
|
+
recoveryFailures: recovery.failures,
|
|
23483
|
+
writeAtomicReceipt: (receipt) => writeJsonAtomic2(path3.join(paths.forgeDir, "work-pack-sync-receipt.json"), receipt)
|
|
23279
23484
|
});
|
|
23280
23485
|
const installed = workPacks.outcomes.filter((outcome) => outcome.status === "installed").map((outcome) => `${outcome.slug}@${outcome.version}`);
|
|
23281
23486
|
const removed = workPacks.outcomes.filter((outcome) => outcome.status === "removed").map((outcome) => outcome.slug);
|
|
@@ -23286,7 +23491,7 @@ async function applyWorkPackManifest(paths, credentials, manifest, options) {
|
|
|
23286
23491
|
async function collectWorkPackObservations(paths, reconciliation) {
|
|
23287
23492
|
const installedVersions = /* @__PURE__ */ new Map();
|
|
23288
23493
|
for (const slug of await managedWorkPackSlugs(paths.skillsDir)) {
|
|
23289
|
-
const version2 = (await
|
|
23494
|
+
const version2 = (await readFile2(path3.join(paths.skillsDir, slug, ".forge-version"), "utf8")).trim();
|
|
23290
23495
|
if (version2) installedVersions.set(slug, version2);
|
|
23291
23496
|
}
|
|
23292
23497
|
const observations = new Map(
|
|
@@ -23304,8 +23509,10 @@ async function collectWorkPackObservations(paths, reconciliation) {
|
|
|
23304
23509
|
}
|
|
23305
23510
|
return [...observations.values()].sort((a, b2) => a.slug.localeCompare(b2.slug));
|
|
23306
23511
|
}
|
|
23307
|
-
async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds, cleanupPendingSlugs, operation, options) {
|
|
23308
|
-
const target =
|
|
23512
|
+
async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds, cleanupPendingSlugs, recoveryFailures, operation, options) {
|
|
23513
|
+
const target = path3.join(paths.skillsDir, operation.pack.slug);
|
|
23514
|
+
const recoveryFailure = recoveryFailures.get(operation.pack.slug);
|
|
23515
|
+
if (recoveryFailure) return { status: "failed", restoration: "exact", code: recoveryFailure };
|
|
23309
23516
|
let ownership;
|
|
23310
23517
|
try {
|
|
23311
23518
|
ownership = await workPackOwnership(target);
|
|
@@ -23316,6 +23523,18 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
23316
23523
|
if (operation.action === "remove") {
|
|
23317
23524
|
if (ownership === "absent") return { status: "unchanged" };
|
|
23318
23525
|
try {
|
|
23526
|
+
const localState = await checkWorkPackInstalledState({
|
|
23527
|
+
packDir: target,
|
|
23528
|
+
agentsDir: paths.agentsDir,
|
|
23529
|
+
commandsDir: paths.commandsDir
|
|
23530
|
+
});
|
|
23531
|
+
if (localState !== "match") {
|
|
23532
|
+
return {
|
|
23533
|
+
status: "failed",
|
|
23534
|
+
restoration: "exact",
|
|
23535
|
+
code: localState === "missing" ? "local-baseline-missing" : "local-edits-preserved"
|
|
23536
|
+
};
|
|
23537
|
+
}
|
|
23319
23538
|
const removedManagedPaths = await removeManagedWorkPackTransaction(paths, target, options);
|
|
23320
23539
|
return { status: "removed", removedManagedPaths };
|
|
23321
23540
|
} catch (error45) {
|
|
@@ -23330,17 +23549,66 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
23330
23549
|
let previousManagedPaths;
|
|
23331
23550
|
let archive;
|
|
23332
23551
|
try {
|
|
23333
|
-
const currentVersion = await
|
|
23334
|
-
|
|
23335
|
-
|
|
23336
|
-
|
|
23337
|
-
|
|
23338
|
-
|
|
23339
|
-
|
|
23552
|
+
const currentVersion = await readFile2(path3.join(target, ".forge-version"), "utf8").catch(() => "");
|
|
23553
|
+
const sameVersion = currentVersion.trim() === skill.version;
|
|
23554
|
+
if (sameVersion) {
|
|
23555
|
+
let localState = await checkWorkPackInstalledState({
|
|
23556
|
+
packDir: target,
|
|
23557
|
+
agentsDir: paths.agentsDir,
|
|
23558
|
+
commandsDir: paths.commandsDir
|
|
23559
|
+
});
|
|
23560
|
+
if (localState === "missing") {
|
|
23561
|
+
const candidateArchive = await downloadSkill(credentials, skill.url);
|
|
23562
|
+
const candidateSha256 = createHash2("sha256").update(candidateArchive).digest("hex");
|
|
23563
|
+
if (candidateSha256 !== skill.sha256) {
|
|
23564
|
+
return { status: "failed", restoration: "exact", code: "local-baseline-missing" };
|
|
23565
|
+
}
|
|
23566
|
+
localState = await adoptLegacyWorkPackState(paths, skill.slug, skill.version, candidateArchive, approvedModelIds) ? "match" : "changed";
|
|
23567
|
+
}
|
|
23568
|
+
if (localState !== "match") {
|
|
23569
|
+
return { status: "failed", restoration: "exact", code: "local-edits-preserved" };
|
|
23570
|
+
}
|
|
23571
|
+
if (!await workPackNeedsModelNormalization(target, approvedModelIds, skill.slug)) {
|
|
23572
|
+
return cleanupPendingSlugs.has(skill.slug) ? {
|
|
23573
|
+
status: "unchanged",
|
|
23574
|
+
warningCode: "cleanup-pending",
|
|
23575
|
+
message: `O pacote "${skill.slug}" est\xE1 instalado, mas o backup anterior continua bloqueado. Feche o OpenWork e volte a sincronizar para concluir a limpeza.`
|
|
23576
|
+
} : { status: "unchanged" };
|
|
23577
|
+
}
|
|
23578
|
+
}
|
|
23579
|
+
if (ownership === "managed" && !sameVersion) {
|
|
23580
|
+
let localState = await checkWorkPackInstalledState({
|
|
23581
|
+
packDir: target,
|
|
23582
|
+
agentsDir: paths.agentsDir,
|
|
23583
|
+
commandsDir: paths.commandsDir
|
|
23584
|
+
});
|
|
23585
|
+
if (localState === "missing") {
|
|
23586
|
+
try {
|
|
23587
|
+
const baselineUrl = `/sync/skills/${encodeURIComponent(skill.slug)}/baseline/${encodeURIComponent(currentVersion.trim())}`;
|
|
23588
|
+
const baseline = JSON.parse(new TextDecoder().decode(await downloadSkill(credentials, baselineUrl)));
|
|
23589
|
+
if (typeof baseline.fingerprint === "string" && /^[a-f0-9]{64}$/.test(baseline.fingerprint)) {
|
|
23590
|
+
localState = await adoptVerifiedWorkPackState({
|
|
23591
|
+
packDir: target,
|
|
23592
|
+
agentsDir: paths.agentsDir,
|
|
23593
|
+
commandsDir: paths.commandsDir,
|
|
23594
|
+
version: currentVersion.trim(),
|
|
23595
|
+
fingerprint: baseline.fingerprint
|
|
23596
|
+
}) ? "match" : "missing";
|
|
23597
|
+
}
|
|
23598
|
+
} catch {
|
|
23599
|
+
}
|
|
23600
|
+
}
|
|
23601
|
+
if (localState !== "match") {
|
|
23602
|
+
return {
|
|
23603
|
+
status: "failed",
|
|
23604
|
+
restoration: "exact",
|
|
23605
|
+
code: localState === "missing" ? "local-baseline-missing" : "local-edits-preserved"
|
|
23606
|
+
};
|
|
23607
|
+
}
|
|
23340
23608
|
}
|
|
23341
23609
|
previousManagedPaths = await managedWorkPackPaths(paths, target);
|
|
23342
23610
|
archive = await downloadSkill(credentials, skill.url);
|
|
23343
|
-
const sha256 =
|
|
23611
|
+
const sha256 = createHash2("sha256").update(archive).digest("hex");
|
|
23344
23612
|
if (sha256 !== skill.sha256) return { status: "failed", restoration: "exact", code: "checksum-mismatch" };
|
|
23345
23613
|
} catch (error45) {
|
|
23346
23614
|
return exactPackFailure(error45);
|
|
@@ -23350,6 +23618,8 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
23350
23618
|
const install = await installSkillArchive(paths, skill.slug, skill.version, archive, {
|
|
23351
23619
|
beforeManagedPathsRemoved: options.beforeManagedPathsRemoved,
|
|
23352
23620
|
writeWorkPackProjection: options.writeWorkPackProjection,
|
|
23621
|
+
installWorkPackBoundary: options.installWorkPackBoundary,
|
|
23622
|
+
workPackProjectionBoundary: options.workPackProjectionBoundary,
|
|
23353
23623
|
cleanupWorkPackBackup: options.cleanupWorkPackBackup,
|
|
23354
23624
|
approvedModelIds
|
|
23355
23625
|
});
|
|
@@ -23375,6 +23645,9 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
23375
23645
|
}
|
|
23376
23646
|
}
|
|
23377
23647
|
function exactPackFailure(error45) {
|
|
23648
|
+
if (error45 instanceof WorkPackLocalEditsError) {
|
|
23649
|
+
return { status: "failed", restoration: "exact", code: error45.code };
|
|
23650
|
+
}
|
|
23378
23651
|
if (error45 instanceof WorkPackProjectionConflictError) {
|
|
23379
23652
|
return {
|
|
23380
23653
|
status: "failed",
|
|
@@ -23438,6 +23711,33 @@ async function downloadSkill(credentials, url2) {
|
|
|
23438
23711
|
}
|
|
23439
23712
|
var WorkPackRecoveryUncertainError = class extends Error {
|
|
23440
23713
|
};
|
|
23714
|
+
var WorkPackLocalEditsError = class extends Error {
|
|
23715
|
+
constructor(code, message) {
|
|
23716
|
+
super(message ?? `O pacote de trabalho tem altera\xE7\xF5es locais e n\xE3o foi alterado (${code})`);
|
|
23717
|
+
this.code = code;
|
|
23718
|
+
this.name = "WorkPackLocalEditsError";
|
|
23719
|
+
}
|
|
23720
|
+
code;
|
|
23721
|
+
};
|
|
23722
|
+
async function assertWorkPackUnchangedAtBoundary(paths, target) {
|
|
23723
|
+
const ownership = await workPackOwnership(target);
|
|
23724
|
+
if (ownership === "absent") return;
|
|
23725
|
+
if (ownership === "foreign") throw foreignWorkPackError(path3.basename(target));
|
|
23726
|
+
const localState = await checkWorkPackInstalledState({
|
|
23727
|
+
packDir: target,
|
|
23728
|
+
agentsDir: paths.agentsDir,
|
|
23729
|
+
commandsDir: paths.commandsDir
|
|
23730
|
+
});
|
|
23731
|
+
if (localState !== "match") {
|
|
23732
|
+
throw new WorkPackLocalEditsError(localState === "missing" ? "local-baseline-missing" : "local-edits-preserved");
|
|
23733
|
+
}
|
|
23734
|
+
}
|
|
23735
|
+
async function assertWorkPackTreeUnchangedAtBoundary(target) {
|
|
23736
|
+
const localState = await checkWorkPackTreeState(target);
|
|
23737
|
+
if (localState !== "match") {
|
|
23738
|
+
throw new WorkPackLocalEditsError(localState === "missing" ? "local-baseline-missing" : "local-edits-preserved");
|
|
23739
|
+
}
|
|
23740
|
+
}
|
|
23441
23741
|
function skillSlugFromUrl(value) {
|
|
23442
23742
|
try {
|
|
23443
23743
|
return new URL(value).pathname.split("/").slice(-2, -1)[0] ?? value;
|
|
@@ -23446,21 +23746,21 @@ function skillSlugFromUrl(value) {
|
|
|
23446
23746
|
}
|
|
23447
23747
|
}
|
|
23448
23748
|
async function installSkillArchive(paths, slug, version2, archive, options = {}) {
|
|
23449
|
-
const tempRoot = await mkdtemp(
|
|
23450
|
-
const archivePath =
|
|
23451
|
-
const extractPath =
|
|
23452
|
-
const nextPath =
|
|
23453
|
-
const target =
|
|
23454
|
-
const backup =
|
|
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`);
|
|
23455
23755
|
let agentFiles;
|
|
23456
23756
|
let commandFiles;
|
|
23457
23757
|
let previousAgents;
|
|
23458
23758
|
let previousCommands;
|
|
23459
23759
|
try {
|
|
23460
|
-
await
|
|
23461
|
-
await
|
|
23760
|
+
await mkdir2(extractPath, { recursive: true });
|
|
23761
|
+
await writeFile2(archivePath, archive);
|
|
23462
23762
|
await So({ file: archivePath, cwd: extractPath, strict: true });
|
|
23463
|
-
const extractedSkillPath =
|
|
23763
|
+
const extractedSkillPath = path3.join(extractPath, slug);
|
|
23464
23764
|
await assertNoReservedMarkerAliases(extractedSkillPath);
|
|
23465
23765
|
await validateSkillFolder(extractedSkillPath, slug);
|
|
23466
23766
|
agentFiles = await normalizePackAgentModels(
|
|
@@ -23487,78 +23787,123 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
23487
23787
|
}
|
|
23488
23788
|
throw error45;
|
|
23489
23789
|
}
|
|
23490
|
-
await
|
|
23491
|
-
await
|
|
23790
|
+
await rename2(path3.join(extractPath, slug), nextPath);
|
|
23791
|
+
await writeFile2(path3.join(nextPath, ".forge-version"), `${version2}
|
|
23492
23792
|
`);
|
|
23493
23793
|
if (agentFiles.length > 0) {
|
|
23494
|
-
await
|
|
23794
|
+
await writeFile2(path3.join(nextPath, ".forge-agents"), `${agentFiles.map((agent) => agent.filename).join("\n")}
|
|
23495
23795
|
`);
|
|
23496
23796
|
}
|
|
23497
23797
|
if (commandFiles.length > 0) {
|
|
23498
|
-
await
|
|
23798
|
+
await writeFile2(path3.join(nextPath, ".forge-commands"), `${commandFiles.map((command) => command.filename).join("\n")}
|
|
23499
23799
|
`);
|
|
23500
23800
|
}
|
|
23801
|
+
await writeWorkPackInstalledState({ packDir: nextPath, version: version2, agents: agentFiles, commands: commandFiles });
|
|
23501
23802
|
const nextAgentNames = new Set(agentFiles.map((agent) => agent.filename));
|
|
23502
23803
|
const nextCommandNames = new Set(commandFiles.map((command) => command.filename));
|
|
23503
23804
|
const agentSnapshot = await captureProjectionState(paths.agentsDir, [.../* @__PURE__ */ new Set([...previousAgents, ...nextAgentNames])]);
|
|
23504
23805
|
const commandSnapshot = await captureProjectionState(paths.commandsDir, [.../* @__PURE__ */ new Set([...previousCommands, ...nextCommandNames])]);
|
|
23806
|
+
const agentTransactionState = new Map(
|
|
23807
|
+
[...agentSnapshot.keys()].map((filePath) => [
|
|
23808
|
+
filePath,
|
|
23809
|
+
agentFiles.find((agent) => agent.filename === path3.basename(filePath))?.content
|
|
23810
|
+
])
|
|
23811
|
+
);
|
|
23812
|
+
const commandTransactionState = new Map(
|
|
23813
|
+
[...commandSnapshot.keys()].map((filePath) => [
|
|
23814
|
+
filePath,
|
|
23815
|
+
commandFiles.find((command) => command.filename === path3.basename(filePath))?.content
|
|
23816
|
+
])
|
|
23817
|
+
);
|
|
23505
23818
|
const previousManagedPaths = await managedWorkPackPaths(paths, target);
|
|
23506
|
-
|
|
23507
|
-
|
|
23508
|
-
|
|
23509
|
-
|
|
23510
|
-
|
|
23511
|
-
|
|
23512
|
-
}
|
|
23819
|
+
try {
|
|
23820
|
+
if (previousManagedPaths.length > 0) await options.beforeManagedPathsRemoved?.(previousManagedPaths);
|
|
23821
|
+
await assertWorkPackUnchangedAtBoundary(paths, target);
|
|
23822
|
+
} catch (error45) {
|
|
23823
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
23824
|
+
throw error45;
|
|
23513
23825
|
}
|
|
23514
23826
|
const writeProjection = options.writeWorkPackProjection ?? writeTextAtomic;
|
|
23827
|
+
const claimedBackup = path3.join(tempRoot, `${slug}-claimed-previous`);
|
|
23828
|
+
const transactionPath = `${backup}${WORK_PACK_TRANSACTION_SUFFIX}`;
|
|
23515
23829
|
let targetBackedUp = false;
|
|
23516
23830
|
let targetInstalled = false;
|
|
23831
|
+
let backupClaimed = false;
|
|
23517
23832
|
try {
|
|
23518
23833
|
await rm(backup, { recursive: true, force: true });
|
|
23834
|
+
await rm(transactionPath, { force: true });
|
|
23835
|
+
await writeTextAtomic(transactionPath, "install\n");
|
|
23519
23836
|
try {
|
|
23520
|
-
await
|
|
23837
|
+
await rename2(target, backup);
|
|
23521
23838
|
targetBackedUp = true;
|
|
23522
23839
|
} catch (error45) {
|
|
23523
23840
|
if (error45.code !== "ENOENT") throw error45;
|
|
23841
|
+
await rm(transactionPath, { force: true });
|
|
23842
|
+
}
|
|
23843
|
+
if (targetBackedUp) {
|
|
23844
|
+
await options.installWorkPackBoundary?.("after-backup");
|
|
23845
|
+
await assertWorkPackUnchangedAtBoundary(paths, backup);
|
|
23524
23846
|
}
|
|
23525
|
-
await
|
|
23847
|
+
await rename2(nextPath, target);
|
|
23526
23848
|
targetInstalled = true;
|
|
23527
|
-
|
|
23528
|
-
paths.agentsDir,
|
|
23529
|
-
|
|
23530
|
-
|
|
23849
|
+
for (const filename of previousAgents.filter((name) => !nextAgentNames.has(name))) {
|
|
23850
|
+
const filePath = path3.join(paths.agentsDir, filename);
|
|
23851
|
+
await options.workPackProjectionBoundary?.("install", filePath);
|
|
23852
|
+
await assertProjectionState(filePath, agentSnapshot.get(filePath));
|
|
23853
|
+
await rm(filePath, { force: true });
|
|
23854
|
+
}
|
|
23531
23855
|
if (agentFiles.length > 0) {
|
|
23532
|
-
await
|
|
23856
|
+
await mkdir2(paths.agentsDir, { recursive: true });
|
|
23533
23857
|
for (const agent of agentFiles) {
|
|
23534
|
-
|
|
23858
|
+
const filePath = path3.join(paths.agentsDir, agent.filename);
|
|
23859
|
+
await options.workPackProjectionBoundary?.("install", filePath);
|
|
23860
|
+
await assertProjectionState(filePath, agentSnapshot.get(filePath));
|
|
23861
|
+
await writeProjection(filePath, agent.content);
|
|
23535
23862
|
}
|
|
23536
23863
|
}
|
|
23537
|
-
|
|
23538
|
-
paths.commandsDir,
|
|
23539
|
-
|
|
23540
|
-
|
|
23864
|
+
for (const filename of previousCommands.filter((name) => !nextCommandNames.has(name))) {
|
|
23865
|
+
const filePath = path3.join(paths.commandsDir, filename);
|
|
23866
|
+
await options.workPackProjectionBoundary?.("install", filePath);
|
|
23867
|
+
await assertProjectionState(filePath, commandSnapshot.get(filePath));
|
|
23868
|
+
await rm(filePath, { force: true });
|
|
23869
|
+
}
|
|
23541
23870
|
if (commandFiles.length > 0) {
|
|
23542
|
-
await
|
|
23871
|
+
await mkdir2(paths.commandsDir, { recursive: true });
|
|
23543
23872
|
for (const command of commandFiles) {
|
|
23544
|
-
|
|
23545
|
-
|
|
23546
|
-
|
|
23547
|
-
|
|
23873
|
+
const filePath = path3.join(paths.commandsDir, command.filename);
|
|
23874
|
+
await options.workPackProjectionBoundary?.("install", filePath);
|
|
23875
|
+
await assertProjectionState(filePath, commandSnapshot.get(filePath));
|
|
23876
|
+
await writeProjection(filePath, command.content);
|
|
23877
|
+
}
|
|
23878
|
+
}
|
|
23879
|
+
if (targetBackedUp) await assertWorkPackTreeUnchangedAtBoundary(backup);
|
|
23880
|
+
if (targetBackedUp) await options.installWorkPackBoundary?.("before-commit");
|
|
23881
|
+
if (targetBackedUp) {
|
|
23882
|
+
await rename2(backup, claimedBackup);
|
|
23883
|
+
backupClaimed = true;
|
|
23884
|
+
await assertWorkPackTreeUnchangedAtBoundary(claimedBackup);
|
|
23885
|
+
await writeFile2(path3.join(claimedBackup, WORK_PACK_COMMITTED_MARKER), `${version2}
|
|
23548
23886
|
`);
|
|
23887
|
+
await writeTextAtomic(transactionPath, "committed\n");
|
|
23888
|
+
}
|
|
23549
23889
|
} catch (error45) {
|
|
23550
23890
|
try {
|
|
23551
|
-
|
|
23552
|
-
|
|
23891
|
+
if (targetInstalled) {
|
|
23892
|
+
await restoreProjectionState(agentSnapshot, agentTransactionState);
|
|
23893
|
+
await restoreProjectionState(commandSnapshot, commandTransactionState);
|
|
23894
|
+
}
|
|
23553
23895
|
if (targetBackedUp) {
|
|
23554
|
-
const restoredTarget =
|
|
23555
|
-
|
|
23896
|
+
const restoredTarget = path3.join(tempRoot, `${slug}-restore`);
|
|
23897
|
+
const rollbackSource = backupClaimed ? claimedBackup : backup;
|
|
23898
|
+
await cp(rollbackSource, restoredTarget, { recursive: true });
|
|
23556
23899
|
if (targetInstalled) await rm(target, { recursive: true, force: true });
|
|
23557
|
-
await
|
|
23558
|
-
await rm(
|
|
23900
|
+
await rename2(restoredTarget, target);
|
|
23901
|
+
await rm(rollbackSource, { recursive: true, force: true });
|
|
23902
|
+
await rm(transactionPath, { force: true });
|
|
23559
23903
|
} else if (targetInstalled) {
|
|
23560
23904
|
await rm(target, { recursive: true, force: true });
|
|
23561
23905
|
}
|
|
23906
|
+
await rm(transactionPath, { force: true });
|
|
23562
23907
|
await rm(tempRoot, { recursive: true, force: true });
|
|
23563
23908
|
} catch (restoreError) {
|
|
23564
23909
|
throw new WorkPackRecoveryUncertainError(`Falha ao instalar e restaurar o pacote de trabalho ${slug}`, {
|
|
@@ -23568,37 +23913,90 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
23568
23913
|
throw error45;
|
|
23569
23914
|
}
|
|
23570
23915
|
let cleanup = "complete";
|
|
23916
|
+
const cleanupTarget = backupClaimed ? claimedBackup : backup;
|
|
23571
23917
|
try {
|
|
23572
|
-
await (options.cleanupWorkPackBackup ?? removeWorkPackBackup)(
|
|
23918
|
+
await (options.cleanupWorkPackBackup ?? removeWorkPackBackup)(cleanupTarget);
|
|
23919
|
+
await rm(transactionPath, { force: true });
|
|
23573
23920
|
} catch {
|
|
23574
|
-
|
|
23921
|
+
if (!await pathExists(cleanupTarget)) {
|
|
23922
|
+
cleanup = "complete";
|
|
23923
|
+
await rm(transactionPath, { force: true });
|
|
23924
|
+
} else {
|
|
23925
|
+
cleanup = "pending";
|
|
23926
|
+
if (backupClaimed) await rename2(claimedBackup, backup);
|
|
23927
|
+
}
|
|
23575
23928
|
}
|
|
23576
23929
|
await rm(tempRoot, { recursive: true, force: true }).catch(() => void 0);
|
|
23577
23930
|
return { cleanup };
|
|
23578
23931
|
}
|
|
23579
|
-
async function
|
|
23932
|
+
async function adoptLegacyWorkPackState(paths, slug, version2, archive, approvedModelIds) {
|
|
23933
|
+
const comparisonRoot = await mkdtemp(path3.join(os4.tmpdir(), `forge-${slug}-baseline-`));
|
|
23934
|
+
const comparisonPaths = {
|
|
23935
|
+
...paths,
|
|
23936
|
+
skillsDir: path3.join(comparisonRoot, "skills"),
|
|
23937
|
+
agentsDir: path3.join(comparisonRoot, "agents"),
|
|
23938
|
+
commandsDir: path3.join(comparisonRoot, "commands")
|
|
23939
|
+
};
|
|
23940
|
+
try {
|
|
23941
|
+
await mkdir2(comparisonPaths.skillsDir, { recursive: true });
|
|
23942
|
+
await installSkillArchive(comparisonPaths, slug, version2, archive, { approvedModelIds });
|
|
23943
|
+
return adoptWorkPackInstalledState({
|
|
23944
|
+
expectedPackDir: path3.join(comparisonPaths.skillsDir, slug),
|
|
23945
|
+
packDir: path3.join(paths.skillsDir, slug),
|
|
23946
|
+
agentsDir: paths.agentsDir,
|
|
23947
|
+
commandsDir: paths.commandsDir
|
|
23948
|
+
});
|
|
23949
|
+
} finally {
|
|
23950
|
+
await rm(comparisonRoot, { recursive: true, force: true }).catch(() => void 0);
|
|
23951
|
+
}
|
|
23952
|
+
}
|
|
23953
|
+
async function recoverInterruptedWorkPackInstalls(paths, cleanupWorkPackBackup, workPackProjectionBoundary) {
|
|
23580
23954
|
const cleanupPending = /* @__PURE__ */ new Set();
|
|
23581
|
-
const
|
|
23955
|
+
const failures = /* @__PURE__ */ new Map();
|
|
23956
|
+
const entries = await readdir2(paths.skillsDir, { withFileTypes: true }).catch((error45) => {
|
|
23582
23957
|
if (error45.code === "ENOENT") return [];
|
|
23583
23958
|
throw error45;
|
|
23584
23959
|
});
|
|
23585
23960
|
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
23586
|
-
if (!entry.
|
|
23961
|
+
if (!entry.name.endsWith(".previous")) continue;
|
|
23587
23962
|
const slug = entry.name.slice(0, -".previous".length);
|
|
23588
23963
|
if (!slug) continue;
|
|
23589
|
-
const target =
|
|
23590
|
-
|
|
23591
|
-
|
|
23964
|
+
const target = path3.join(paths.skillsDir, slug);
|
|
23965
|
+
const backup = `${target}.previous`;
|
|
23966
|
+
const transactionState = await readWorkPackTransactionState(backup);
|
|
23967
|
+
if (transactionState === "committed") {
|
|
23968
|
+
try {
|
|
23969
|
+
await (cleanupWorkPackBackup ?? removeWorkPackBackup)(backup);
|
|
23970
|
+
await rm(`${backup}${WORK_PACK_TRANSACTION_SUFFIX}`, { force: true });
|
|
23971
|
+
} catch {
|
|
23972
|
+
if (await pathExists(backup)) cleanupPending.add(slug);
|
|
23973
|
+
else await rm(`${backup}${WORK_PACK_TRANSACTION_SUFFIX}`, { force: true });
|
|
23974
|
+
}
|
|
23975
|
+
continue;
|
|
23976
|
+
}
|
|
23977
|
+
if (!entry.isDirectory() || await workPackOwnership(backup) !== "managed") continue;
|
|
23978
|
+
const recovery = await recoverInterruptedWorkPackInstall(
|
|
23979
|
+
paths,
|
|
23980
|
+
target,
|
|
23981
|
+
cleanupWorkPackBackup,
|
|
23982
|
+
workPackProjectionBoundary,
|
|
23983
|
+
transactionState
|
|
23984
|
+
).catch((error45) => {
|
|
23985
|
+
if (error45 instanceof WorkPackLocalEditsError) return error45.code;
|
|
23986
|
+
throw error45;
|
|
23987
|
+
});
|
|
23988
|
+
if (recovery === "cleanup-pending") cleanupPending.add(slug);
|
|
23989
|
+
if (recovery === "local-edits-preserved" || recovery === "local-baseline-missing") failures.set(slug, recovery);
|
|
23592
23990
|
}
|
|
23593
|
-
return cleanupPending;
|
|
23991
|
+
return { cleanupPendingSlugs: cleanupPending, failures };
|
|
23594
23992
|
}
|
|
23595
|
-
async function recoverInterruptedWorkPackInstall(paths, target, cleanupWorkPackBackup) {
|
|
23993
|
+
async function recoverInterruptedWorkPackInstall(paths, target, cleanupWorkPackBackup, workPackProjectionBoundary, transactionState) {
|
|
23596
23994
|
const backup = `${target}.previous`;
|
|
23597
23995
|
const backupOwnership = await workPackOwnership(backup);
|
|
23598
23996
|
if (backupOwnership === "absent") return "recovered";
|
|
23599
|
-
if (backupOwnership === "foreign") throw foreignWorkPackError(
|
|
23600
|
-
if (await workPackOwnership(target) === "foreign") throw foreignWorkPackError(
|
|
23601
|
-
const committed = await
|
|
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) => {
|
|
23602
24000
|
if (error45.code === "ENOENT") return void 0;
|
|
23603
24001
|
throw error45;
|
|
23604
24002
|
});
|
|
@@ -23610,29 +24008,70 @@ async function recoverInterruptedWorkPackInstall(paths, target, cleanupWorkPackB
|
|
|
23610
24008
|
return "cleanup-pending";
|
|
23611
24009
|
}
|
|
23612
24010
|
}
|
|
24011
|
+
const targetOwnership = await workPackOwnership(target);
|
|
24012
|
+
if (targetOwnership === "managed") {
|
|
24013
|
+
const localState = await checkWorkPackTreeState(target);
|
|
24014
|
+
if (localState !== "match") {
|
|
24015
|
+
return localState === "missing" ? "local-baseline-missing" : "local-edits-preserved";
|
|
24016
|
+
}
|
|
24017
|
+
}
|
|
23613
24018
|
const currentAgents = await readAgentRecord(target);
|
|
23614
24019
|
const currentCommands = await readCommandRecord(target);
|
|
23615
24020
|
const currentAgentFiles = await readPackAgentFiles(target);
|
|
23616
24021
|
const currentCommandFiles = await readPackCommandFiles(target);
|
|
23617
24022
|
const previousAgents = await readPackAgentFiles(backup);
|
|
23618
24023
|
const previousCommands = await readPackCommandFiles(backup);
|
|
23619
|
-
await
|
|
23620
|
-
|
|
24024
|
+
const removedProjections = transactionState === "remove" ? await readWorkPackRemovedProjections(backup) : { agents: /* @__PURE__ */ new Set(), commands: /* @__PURE__ */ new Set() };
|
|
24025
|
+
const missingPreviousAgentPolicy = targetOwnership === "absent" ? transactionState === "remove" ? removedProjections.agents : true : false;
|
|
24026
|
+
const missingPreviousCommandPolicy = targetOwnership === "absent" ? transactionState === "remove" ? removedProjections.commands : true : false;
|
|
24027
|
+
const agentRecoveryState = await assertProjectionRecoveryIsSafe(
|
|
24028
|
+
paths.agentsDir,
|
|
24029
|
+
currentAgentFiles,
|
|
24030
|
+
previousAgents,
|
|
24031
|
+
missingPreviousAgentPolicy
|
|
24032
|
+
);
|
|
24033
|
+
const commandRecoveryState = await assertProjectionRecoveryIsSafe(
|
|
24034
|
+
paths.commandsDir,
|
|
24035
|
+
currentCommandFiles,
|
|
24036
|
+
previousCommands,
|
|
24037
|
+
missingPreviousCommandPolicy
|
|
24038
|
+
);
|
|
23621
24039
|
const previousAgentNames = new Set(previousAgents.map((agent) => agent.filename));
|
|
23622
24040
|
const previousCommandNames = new Set(previousCommands.map((command) => command.filename));
|
|
23623
|
-
const recoveryRoot = await mkdtemp(
|
|
23624
|
-
const recoveredTarget =
|
|
24041
|
+
const recoveryRoot = await mkdtemp(path3.join(os4.tmpdir(), "forge-recover-"));
|
|
24042
|
+
const recoveredTarget = path3.join(recoveryRoot, path3.basename(target));
|
|
23625
24043
|
await cp(backup, recoveredTarget, { recursive: true });
|
|
23626
24044
|
try {
|
|
23627
|
-
|
|
23628
|
-
|
|
23629
|
-
|
|
23630
|
-
|
|
23631
|
-
|
|
23632
|
-
|
|
24045
|
+
for (const filename of currentAgents.filter((name) => !previousAgentNames.has(name))) {
|
|
24046
|
+
const filePath = path3.join(paths.agentsDir, filename);
|
|
24047
|
+
await workPackProjectionBoundary?.("recover", filePath);
|
|
24048
|
+
await assertProjectionState(filePath, agentRecoveryState.get(filePath));
|
|
24049
|
+
await rm(filePath, { force: true });
|
|
24050
|
+
}
|
|
24051
|
+
await mkdir2(paths.agentsDir, { recursive: true });
|
|
24052
|
+
for (const agent of previousAgents) {
|
|
24053
|
+
const filePath = path3.join(paths.agentsDir, agent.filename);
|
|
24054
|
+
await workPackProjectionBoundary?.("recover", filePath);
|
|
24055
|
+
await assertProjectionState(filePath, agentRecoveryState.get(filePath));
|
|
24056
|
+
await writeTextAtomic(filePath, agent.content);
|
|
24057
|
+
}
|
|
24058
|
+
for (const filename of currentCommands.filter((name) => !previousCommandNames.has(name))) {
|
|
24059
|
+
const filePath = path3.join(paths.commandsDir, filename);
|
|
24060
|
+
await workPackProjectionBoundary?.("recover", filePath);
|
|
24061
|
+
await assertProjectionState(filePath, commandRecoveryState.get(filePath));
|
|
24062
|
+
await rm(filePath, { force: true });
|
|
24063
|
+
}
|
|
24064
|
+
await mkdir2(paths.commandsDir, { recursive: true });
|
|
24065
|
+
for (const command of previousCommands) {
|
|
24066
|
+
const filePath = path3.join(paths.commandsDir, command.filename);
|
|
24067
|
+
await workPackProjectionBoundary?.("recover", filePath);
|
|
24068
|
+
await assertProjectionState(filePath, commandRecoveryState.get(filePath));
|
|
24069
|
+
await writeTextAtomic(filePath, command.content);
|
|
24070
|
+
}
|
|
23633
24071
|
await rm(target, { recursive: true, force: true });
|
|
23634
|
-
await
|
|
24072
|
+
await rename2(recoveredTarget, target);
|
|
23635
24073
|
await rm(backup, { recursive: true, force: true });
|
|
24074
|
+
await rm(`${backup}${WORK_PACK_TRANSACTION_SUFFIX}`, { force: true });
|
|
23636
24075
|
} finally {
|
|
23637
24076
|
await rm(recoveryRoot, { recursive: true, force: true }).catch(() => void 0);
|
|
23638
24077
|
}
|
|
@@ -23641,14 +24080,59 @@ async function recoverInterruptedWorkPackInstall(paths, target, cleanupWorkPackB
|
|
|
23641
24080
|
async function removeWorkPackBackup(backupPath) {
|
|
23642
24081
|
await rm(backupPath, { recursive: true, force: true });
|
|
23643
24082
|
}
|
|
24083
|
+
async function readWorkPackTransactionFile(backup) {
|
|
24084
|
+
return readFile2(`${backup}${WORK_PACK_TRANSACTION_SUFFIX}`, "utf8").catch((error45) => {
|
|
24085
|
+
if (error45.code === "ENOENT") return void 0;
|
|
24086
|
+
throw error45;
|
|
24087
|
+
});
|
|
24088
|
+
}
|
|
24089
|
+
async function readWorkPackTransactionState(backup) {
|
|
24090
|
+
const value = await readWorkPackTransactionFile(backup);
|
|
24091
|
+
const state = value?.split("\n", 1)[0]?.trim();
|
|
24092
|
+
return state === "install" || state === "remove" || state === "committed" ? state : void 0;
|
|
24093
|
+
}
|
|
24094
|
+
function isManagedProjectionName(filename) {
|
|
24095
|
+
return filename.length > 0 && !filename.includes("/") && !filename.includes("\\") && filename !== "..";
|
|
24096
|
+
}
|
|
24097
|
+
async function recordRemovedProjection(transactionPath, kind, filename) {
|
|
24098
|
+
const current = await readFile2(transactionPath, "utf8");
|
|
24099
|
+
await writeTextAtomic(transactionPath, `${current.trimEnd()}
|
|
24100
|
+
${kind}:${filename}
|
|
24101
|
+
`);
|
|
24102
|
+
}
|
|
24103
|
+
async function readWorkPackRemovedProjections(backup) {
|
|
24104
|
+
const agents = /* @__PURE__ */ new Set();
|
|
24105
|
+
const commands = /* @__PURE__ */ new Set();
|
|
24106
|
+
const value = await readWorkPackTransactionFile(backup);
|
|
24107
|
+
if (!value) return { agents, commands };
|
|
24108
|
+
const lines = value.split("\n");
|
|
24109
|
+
if (lines[0]?.trim() !== "remove") return { agents, commands };
|
|
24110
|
+
for (const line of lines.slice(1)) {
|
|
24111
|
+
const trimmed = line.trim();
|
|
24112
|
+
const separator = trimmed.indexOf(":");
|
|
24113
|
+
if (separator <= 0) continue;
|
|
24114
|
+
const kind = trimmed.slice(0, separator);
|
|
24115
|
+
const filename = trimmed.slice(separator + 1);
|
|
24116
|
+
if (!isManagedProjectionName(filename)) continue;
|
|
24117
|
+
if (kind === "agent") agents.add(filename);
|
|
24118
|
+
else if (kind === "command") commands.add(filename);
|
|
24119
|
+
}
|
|
24120
|
+
return { agents, commands };
|
|
24121
|
+
}
|
|
24122
|
+
async function pathExists(filePath) {
|
|
24123
|
+
return lstat2(filePath).then(() => true, (error45) => {
|
|
24124
|
+
if (error45.code === "ENOENT") return false;
|
|
24125
|
+
throw error45;
|
|
24126
|
+
});
|
|
24127
|
+
}
|
|
23644
24128
|
async function workPackOwnership(target) {
|
|
23645
|
-
const targetStat = await
|
|
24129
|
+
const targetStat = await lstat2(target).catch((error45) => {
|
|
23646
24130
|
if (error45.code === "ENOENT") return void 0;
|
|
23647
24131
|
throw error45;
|
|
23648
24132
|
});
|
|
23649
24133
|
if (!targetStat) return "absent";
|
|
23650
24134
|
if (!targetStat.isDirectory()) return "foreign";
|
|
23651
|
-
const marker = await
|
|
24135
|
+
const marker = await readFile2(path3.join(target, ".forge-version"), "utf8").catch((error45) => {
|
|
23652
24136
|
if (error45.code === "ENOENT") return void 0;
|
|
23653
24137
|
throw error45;
|
|
23654
24138
|
});
|
|
@@ -23657,28 +24141,58 @@ async function workPackOwnership(target) {
|
|
|
23657
24141
|
function foreignWorkPackError(slug) {
|
|
23658
24142
|
return new Error(`O diret\xF3rio do pacote de trabalho ${slug} j\xE1 existe e n\xE3o \xE9 gerido pelo Forge; n\xE3o foi alterado`);
|
|
23659
24143
|
}
|
|
23660
|
-
|
|
24144
|
+
function missingPreviousProjectionIsLocalDeletion(filename, projected, previousNames, currentNames, missingPreviousPolicy) {
|
|
24145
|
+
if (projected !== void 0 || !previousNames.has(filename)) return false;
|
|
24146
|
+
if (missingPreviousPolicy === true) return true;
|
|
24147
|
+
if (missingPreviousPolicy instanceof Set) return !missingPreviousPolicy.has(filename);
|
|
24148
|
+
return currentNames.has(filename);
|
|
24149
|
+
}
|
|
24150
|
+
async function assertProjectionRecoveryIsSafe(directory, currentFiles, previousFiles, missingPreviousPolicy = false) {
|
|
23661
24151
|
const expected = /* @__PURE__ */ new Map();
|
|
24152
|
+
const validated = /* @__PURE__ */ new Map();
|
|
24153
|
+
const currentNames = new Set(currentFiles.map((file2) => file2.filename));
|
|
24154
|
+
const previousNames = new Set(previousFiles.map((file2) => file2.filename));
|
|
23662
24155
|
for (const file2 of [...currentFiles, ...previousFiles]) {
|
|
23663
24156
|
const contents = expected.get(file2.filename) ?? /* @__PURE__ */ new Set();
|
|
23664
24157
|
contents.add(file2.content);
|
|
23665
24158
|
expected.set(file2.filename, contents);
|
|
23666
24159
|
}
|
|
23667
24160
|
for (const [filename, contents] of expected) {
|
|
23668
|
-
const projected = await
|
|
24161
|
+
const projected = await readFile2(path3.join(directory, filename), "utf8").catch((error45) => {
|
|
23669
24162
|
if (error45.code === "ENOENT") return void 0;
|
|
23670
24163
|
throw error45;
|
|
23671
24164
|
});
|
|
23672
|
-
|
|
23673
|
-
|
|
24165
|
+
validated.set(path3.join(directory, filename), projected);
|
|
24166
|
+
const missingPreviousProjection = missingPreviousProjectionIsLocalDeletion(
|
|
24167
|
+
filename,
|
|
24168
|
+
projected,
|
|
24169
|
+
previousNames,
|
|
24170
|
+
currentNames,
|
|
24171
|
+
missingPreviousPolicy
|
|
24172
|
+
);
|
|
24173
|
+
if (missingPreviousProjection || projected !== void 0 && !contents.has(projected)) {
|
|
24174
|
+
throw new WorkPackLocalEditsError(
|
|
24175
|
+
"local-edits-preserved",
|
|
24176
|
+
`A proje\xE7\xE3o ${filename} foi alterada durante a recupera\xE7\xE3o do pacote de trabalho`
|
|
24177
|
+
);
|
|
23674
24178
|
}
|
|
23675
24179
|
}
|
|
24180
|
+
return validated;
|
|
24181
|
+
}
|
|
24182
|
+
async function assertProjectionState(filePath, expected) {
|
|
24183
|
+
const current = await readFile2(filePath, "utf8").catch((error45) => {
|
|
24184
|
+
if (error45.code === "ENOENT") return void 0;
|
|
24185
|
+
throw error45;
|
|
24186
|
+
});
|
|
24187
|
+
if (current !== expected) {
|
|
24188
|
+
throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${path3.basename(filePath)} foi alterada durante a opera\xE7\xE3o`);
|
|
24189
|
+
}
|
|
23676
24190
|
}
|
|
23677
24191
|
async function captureProjectionState(directory, filenames) {
|
|
23678
24192
|
const snapshot = /* @__PURE__ */ new Map();
|
|
23679
24193
|
for (const filename of filenames) {
|
|
23680
|
-
const filePath =
|
|
23681
|
-
const content = await
|
|
24194
|
+
const filePath = path3.join(directory, filename);
|
|
24195
|
+
const content = await readFile2(filePath, "utf8").catch((error45) => {
|
|
23682
24196
|
if (error45.code === "ENOENT") return void 0;
|
|
23683
24197
|
throw error45;
|
|
23684
24198
|
});
|
|
@@ -23686,15 +24200,22 @@ async function captureProjectionState(directory, filenames) {
|
|
|
23686
24200
|
}
|
|
23687
24201
|
return snapshot;
|
|
23688
24202
|
}
|
|
23689
|
-
async function restoreProjectionState(snapshot) {
|
|
24203
|
+
async function restoreProjectionState(snapshot, transactionState) {
|
|
23690
24204
|
for (const [filePath, content] of snapshot) {
|
|
24205
|
+
if (transactionState) {
|
|
24206
|
+
const current = await readFile2(filePath, "utf8").catch((error45) => {
|
|
24207
|
+
if (error45.code === "ENOENT") return void 0;
|
|
24208
|
+
throw error45;
|
|
24209
|
+
});
|
|
24210
|
+
if (current !== transactionState.get(filePath)) continue;
|
|
24211
|
+
}
|
|
23691
24212
|
if (content === void 0) await rm(filePath, { force: true });
|
|
23692
24213
|
else await writeTextAtomic(filePath, content);
|
|
23693
24214
|
}
|
|
23694
24215
|
}
|
|
23695
24216
|
async function readPackAgentFiles(skillFolder) {
|
|
23696
|
-
const agentsFolder =
|
|
23697
|
-
const entries = await
|
|
24217
|
+
const agentsFolder = path3.join(skillFolder, "agents");
|
|
24218
|
+
const entries = await readdir2(agentsFolder, { withFileTypes: true }).catch((error45) => {
|
|
23698
24219
|
if (error45.code === "ENOENT") return [];
|
|
23699
24220
|
throw error45;
|
|
23700
24221
|
});
|
|
@@ -23702,7 +24223,7 @@ async function readPackAgentFiles(skillFolder) {
|
|
|
23702
24223
|
for (const entry of entries) {
|
|
23703
24224
|
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
23704
24225
|
if (entry.name.startsWith("._")) continue;
|
|
23705
|
-
const content = await
|
|
24226
|
+
const content = await readFile2(path3.join(agentsFolder, entry.name), "utf8");
|
|
23706
24227
|
validateAgentFile(entry.name, content);
|
|
23707
24228
|
files.push({ filename: entry.name, content });
|
|
23708
24229
|
}
|
|
@@ -23713,7 +24234,7 @@ async function normalizePackAgentModels(skillFolder, agentFiles, approvedModelId
|
|
|
23713
24234
|
for (const agent of agentFiles) {
|
|
23714
24235
|
const content = normalizePackAgentModel(agent.filename, agent.content, approvedModelIds, slug);
|
|
23715
24236
|
if (content !== agent.content) {
|
|
23716
|
-
await
|
|
24237
|
+
await writeFile2(path3.join(skillFolder, "agents", agent.filename), content);
|
|
23717
24238
|
}
|
|
23718
24239
|
normalized.push({ ...agent, content });
|
|
23719
24240
|
}
|
|
@@ -23732,33 +24253,9 @@ async function workPackNeedsModelNormalization(target, approvedModelIds, slug) {
|
|
|
23732
24253
|
function normalizePackAgentModel(filename, content, approvedModelIds, slug) {
|
|
23733
24254
|
return normalizePackExtensionModel(`agents/${filename}`, content, approvedModelIds, slug);
|
|
23734
24255
|
}
|
|
23735
|
-
function normalizePackExtensionModel(pathLabel, content, approvedModelIds, slug) {
|
|
23736
|
-
const match = /^---\n([\s\S]+?)\n---/.exec(content);
|
|
23737
|
-
const frontmatter = match?.[1];
|
|
23738
|
-
if (!match || frontmatter === void 0) return content;
|
|
23739
|
-
const modelLines = [...frontmatter.matchAll(/^model:\s*(.*?)\s*$/gm)];
|
|
23740
|
-
if (modelLines.length === 0) return content;
|
|
23741
|
-
if (modelLines.length > 1) {
|
|
23742
|
-
throw new Error(`A extens\xE3o ${pathLabel} do pacote de trabalho ${slug} define model mais do que uma vez`);
|
|
23743
|
-
}
|
|
23744
|
-
const rawModel = modelLines[0][1].replace(/^(['"])(.*)\1$/, "$2");
|
|
23745
|
-
const separator = rawModel.indexOf("/");
|
|
23746
|
-
const provider = separator > 0 ? rawModel.slice(0, separator) : "";
|
|
23747
|
-
const modelId = separator > 0 ? rawModel.slice(separator + 1) : "";
|
|
23748
|
-
if (provider !== "forge" && provider !== "openrouter" || !approvedModelIds.has(modelId)) {
|
|
23749
|
-
throw new Error(
|
|
23750
|
-
`A extens\xE3o ${pathLabel} do pacote de trabalho ${slug} usa um modelo que n\xE3o est\xE1 aprovado no Forge`
|
|
23751
|
-
);
|
|
23752
|
-
}
|
|
23753
|
-
if (provider === "forge") return content;
|
|
23754
|
-
const normalizedFrontmatter = frontmatter.replace(/^model:\s*.*?$/m, `model: forge/${modelId}`);
|
|
23755
|
-
return `${content.slice(0, match.index)}---
|
|
23756
|
-
${normalizedFrontmatter}
|
|
23757
|
-
---${content.slice(match.index + match[0].length)}`;
|
|
23758
|
-
}
|
|
23759
24256
|
async function readPackCommandFiles(skillFolder) {
|
|
23760
|
-
const commandsFolder =
|
|
23761
|
-
const entries = await
|
|
24257
|
+
const commandsFolder = path3.join(skillFolder, "commands");
|
|
24258
|
+
const entries = await readdir2(commandsFolder, { withFileTypes: true }).catch((error45) => {
|
|
23762
24259
|
if (error45.code === "ENOENT") return [];
|
|
23763
24260
|
throw error45;
|
|
23764
24261
|
});
|
|
@@ -23766,7 +24263,7 @@ async function readPackCommandFiles(skillFolder) {
|
|
|
23766
24263
|
for (const entry of entries) {
|
|
23767
24264
|
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
23768
24265
|
if (entry.name.startsWith("._")) continue;
|
|
23769
|
-
const content = await
|
|
24266
|
+
const content = await readFile2(path3.join(commandsFolder, entry.name), "utf8");
|
|
23770
24267
|
validateCommandFile(entry.name, content);
|
|
23771
24268
|
files.push({ filename: entry.name, content });
|
|
23772
24269
|
}
|
|
@@ -23777,7 +24274,7 @@ async function normalizePackCommandModels(skillFolder, commandFiles, approvedMod
|
|
|
23777
24274
|
for (const command of commandFiles) {
|
|
23778
24275
|
const content = normalizePackExtensionModel(`commands/${command.filename}`, command.content, approvedModelIds, slug);
|
|
23779
24276
|
if (content !== command.content) {
|
|
23780
|
-
await
|
|
24277
|
+
await writeFile2(path3.join(skillFolder, "commands", command.filename), content);
|
|
23781
24278
|
}
|
|
23782
24279
|
normalized.push({ ...command, content });
|
|
23783
24280
|
}
|
|
@@ -23799,7 +24296,7 @@ async function assertNoForeignAgentConflicts(agentsDir, agentFiles, ownedFilenam
|
|
|
23799
24296
|
const owned = new Set(ownedFilenames);
|
|
23800
24297
|
for (const agent of agentFiles) {
|
|
23801
24298
|
if (owned.has(agent.filename)) continue;
|
|
23802
|
-
const existing = await
|
|
24299
|
+
const existing = await readFile2(path3.join(agentsDir, agent.filename), "utf8").catch((error45) => {
|
|
23803
24300
|
if (error45.code === "ENOENT") return void 0;
|
|
23804
24301
|
throw error45;
|
|
23805
24302
|
});
|
|
@@ -23812,7 +24309,7 @@ async function assertNoForeignCommandConflicts(commandsDir, commandFiles, ownedF
|
|
|
23812
24309
|
const owned = new Set(ownedFilenames);
|
|
23813
24310
|
for (const command of commandFiles) {
|
|
23814
24311
|
if (owned.has(command.filename)) continue;
|
|
23815
|
-
const existing = await
|
|
24312
|
+
const existing = await readFile2(path3.join(commandsDir, command.filename), "utf8").catch((error45) => {
|
|
23816
24313
|
if (error45.code === "ENOENT") return void 0;
|
|
23817
24314
|
throw error45;
|
|
23818
24315
|
});
|
|
@@ -23822,28 +24319,28 @@ async function assertNoForeignCommandConflicts(commandsDir, commandFiles, ownedF
|
|
|
23822
24319
|
}
|
|
23823
24320
|
}
|
|
23824
24321
|
async function readAgentRecord(skillFolder) {
|
|
23825
|
-
const raw = await
|
|
24322
|
+
const raw = await readFile2(path3.join(skillFolder, ".forge-agents"), "utf8").catch(() => "");
|
|
23826
24323
|
return raw.split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.includes("/") && !line.includes("\\") && line !== "..");
|
|
23827
24324
|
}
|
|
23828
24325
|
async function readCommandRecord(skillFolder) {
|
|
23829
|
-
const raw = await
|
|
24326
|
+
const raw = await readFile2(path3.join(skillFolder, ".forge-commands"), "utf8").catch(() => "");
|
|
23830
24327
|
return raw.split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.includes("/") && !line.includes("\\") && line !== "..");
|
|
23831
24328
|
}
|
|
23832
24329
|
async function managedWorkPackPaths(paths, skillFolder) {
|
|
23833
24330
|
const files = await listFilesRecursively(skillFolder);
|
|
23834
|
-
const agents = (await readAgentRecord(skillFolder)).map((filename) =>
|
|
23835
|
-
const commands = (await readCommandRecord(skillFolder)).map((filename) =>
|
|
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));
|
|
23836
24333
|
return [.../* @__PURE__ */ new Set([...files, ...agents, ...commands])];
|
|
23837
24334
|
}
|
|
23838
24335
|
async function managedWorkPackSlugs(skillsDir) {
|
|
23839
|
-
const entries = await
|
|
24336
|
+
const entries = await readdir2(skillsDir, { withFileTypes: true }).catch((error45) => {
|
|
23840
24337
|
if (error45.code === "ENOENT") return [];
|
|
23841
24338
|
throw error45;
|
|
23842
24339
|
});
|
|
23843
24340
|
const slugs = [];
|
|
23844
24341
|
for (const entry of entries) {
|
|
23845
24342
|
if (!entry.isDirectory() || entry.name.endsWith(".previous")) continue;
|
|
23846
|
-
if (await workPackOwnership(
|
|
24343
|
+
if (await workPackOwnership(path3.join(skillsDir, entry.name)) === "managed") slugs.push(entry.name);
|
|
23847
24344
|
}
|
|
23848
24345
|
return slugs.sort((left, right) => left.localeCompare(right));
|
|
23849
24346
|
}
|
|
@@ -23853,28 +24350,67 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
|
|
|
23853
24350
|
const agents = await readAgentRecord(target);
|
|
23854
24351
|
const commands = await readCommandRecord(target);
|
|
23855
24352
|
const snapshots = await Promise.all([
|
|
23856
|
-
...agents.map((filename) => captureExactFile(
|
|
23857
|
-
...commands.map((filename) => captureExactFile(
|
|
24353
|
+
...agents.map((filename) => captureExactFile(path3.join(paths.agentsDir, filename))),
|
|
24354
|
+
...commands.map((filename) => captureExactFile(path3.join(paths.commandsDir, filename)))
|
|
23858
24355
|
]);
|
|
24356
|
+
await assertWorkPackUnchangedAtBoundary(paths, target);
|
|
23859
24357
|
const backup = `${target}.previous`;
|
|
23860
|
-
|
|
23861
|
-
await
|
|
24358
|
+
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));
|
|
24361
|
+
let projectionsRemoved = false;
|
|
24362
|
+
let backupClaimed = false;
|
|
24363
|
+
try {
|
|
24364
|
+
await rm(backup, { recursive: true, force: true });
|
|
24365
|
+
await rm(transactionPath, { force: true });
|
|
24366
|
+
await writeTextAtomic(transactionPath, "remove\n");
|
|
24367
|
+
await rename2(target, backup);
|
|
24368
|
+
} catch (error45) {
|
|
24369
|
+
await rm(transactionPath, { force: true }).catch(() => void 0);
|
|
24370
|
+
await rm(transactionRoot, { recursive: true, force: true }).catch(() => void 0);
|
|
24371
|
+
throw error45;
|
|
24372
|
+
}
|
|
23862
24373
|
try {
|
|
23863
24374
|
await options.removeWorkPackBoundary?.("after-backup");
|
|
23864
|
-
await
|
|
24375
|
+
await assertWorkPackUnchangedAtBoundary(paths, backup);
|
|
24376
|
+
projectionsRemoved = agents.length > 0;
|
|
24377
|
+
for (const filename of agents) {
|
|
24378
|
+
const filePath = path3.join(paths.agentsDir, filename);
|
|
24379
|
+
await options.workPackProjectionBoundary?.("remove", filePath);
|
|
24380
|
+
await assertExactFileState(snapshots, filePath);
|
|
24381
|
+
await recordRemovedProjection(transactionPath, "agent", filename);
|
|
24382
|
+
await rm(filePath, { force: true });
|
|
24383
|
+
}
|
|
23865
24384
|
await options.removeWorkPackBoundary?.("after-agents");
|
|
23866
|
-
|
|
24385
|
+
projectionsRemoved ||= commands.length > 0;
|
|
24386
|
+
for (const filename of commands) {
|
|
24387
|
+
const filePath = path3.join(paths.commandsDir, filename);
|
|
24388
|
+
await options.workPackProjectionBoundary?.("remove", filePath);
|
|
24389
|
+
await assertExactFileState(snapshots, filePath);
|
|
24390
|
+
await recordRemovedProjection(transactionPath, "command", filename);
|
|
24391
|
+
await rm(filePath, { force: true });
|
|
24392
|
+
}
|
|
23867
24393
|
await options.removeWorkPackBoundary?.("after-commands");
|
|
23868
|
-
await
|
|
24394
|
+
await assertWorkPackTreeUnchangedAtBoundary(backup);
|
|
24395
|
+
await options.removeWorkPackBoundary?.("before-commit");
|
|
24396
|
+
await rename2(backup, claimedBackup);
|
|
24397
|
+
backupClaimed = true;
|
|
24398
|
+
await assertWorkPackTreeUnchangedAtBoundary(claimedBackup);
|
|
24399
|
+
await writeTextAtomic(transactionPath, "committed\n");
|
|
24400
|
+
await rm(claimedBackup, { recursive: true, force: true });
|
|
24401
|
+
await rm(transactionPath, { force: true });
|
|
24402
|
+
await rm(transactionRoot, { recursive: true, force: true }).catch(() => void 0);
|
|
23869
24403
|
return pathsToRemove;
|
|
23870
24404
|
} catch (error45) {
|
|
23871
24405
|
try {
|
|
23872
|
-
await
|
|
23873
|
-
await
|
|
23874
|
-
await
|
|
24406
|
+
if (projectionsRemoved) await restoreRemovedExactFiles(snapshots);
|
|
24407
|
+
await rename2(backupClaimed ? claimedBackup : backup, target);
|
|
24408
|
+
await rm(transactionPath, { force: true });
|
|
24409
|
+
if (projectionsRemoved) await verifyRestoredOrLocallyChangedFiles(snapshots);
|
|
23875
24410
|
if (await workPackOwnership(target) !== "managed") throw new Error("restored Work Pack marker missing");
|
|
24411
|
+
await rm(transactionRoot, { recursive: true, force: true }).catch(() => void 0);
|
|
23876
24412
|
} catch (restoreError) {
|
|
23877
|
-
throw new WorkPackRecoveryUncertainError(`Falha ao remover e restaurar o pacote de trabalho ${
|
|
24413
|
+
throw new WorkPackRecoveryUncertainError(`Falha ao remover e restaurar o pacote de trabalho ${path3.basename(target)}`, {
|
|
23878
24414
|
cause: new AggregateError([error45, restoreError])
|
|
23879
24415
|
});
|
|
23880
24416
|
}
|
|
@@ -23883,60 +24419,54 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
|
|
|
23883
24419
|
}
|
|
23884
24420
|
async function captureExactFile(filePath) {
|
|
23885
24421
|
try {
|
|
23886
|
-
const info = await
|
|
24422
|
+
const info = await lstat2(filePath);
|
|
23887
24423
|
if (!info.isFile()) throw new Error(`A proje\xE7\xE3o gerida n\xE3o \xE9 um ficheiro regular: ${filePath}`);
|
|
23888
|
-
return { path: filePath, exists: true, bytes: await
|
|
24424
|
+
return { path: filePath, exists: true, bytes: await readFile2(filePath), mode: info.mode & 4095 };
|
|
23889
24425
|
} catch (error45) {
|
|
23890
24426
|
if (error45.code === "ENOENT") return { path: filePath, exists: false };
|
|
23891
24427
|
throw error45;
|
|
23892
24428
|
}
|
|
23893
24429
|
}
|
|
23894
|
-
async function
|
|
24430
|
+
async function assertExactFileState(snapshots, filePath) {
|
|
24431
|
+
const expected = snapshots.find((snapshot) => snapshot.path === filePath);
|
|
24432
|
+
const current = await captureExactFile(filePath);
|
|
24433
|
+
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`);
|
|
24435
|
+
}
|
|
24436
|
+
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`);
|
|
24438
|
+
}
|
|
24439
|
+
}
|
|
24440
|
+
async function restoreRemovedExactFiles(snapshots) {
|
|
23895
24441
|
for (const snapshot of snapshots) {
|
|
23896
|
-
if (
|
|
23897
|
-
|
|
23898
|
-
|
|
23899
|
-
|
|
23900
|
-
await mkdir(path2.dirname(snapshot.path), { recursive: true });
|
|
23901
|
-
await writeFile(snapshot.path, snapshot.bytes);
|
|
24442
|
+
if ((await captureExactFile(snapshot.path)).exists) continue;
|
|
24443
|
+
if (!snapshot.exists) continue;
|
|
24444
|
+
await mkdir2(path3.dirname(snapshot.path), { recursive: true });
|
|
24445
|
+
await writeFile2(snapshot.path, snapshot.bytes);
|
|
23902
24446
|
await chmod(snapshot.path, snapshot.mode);
|
|
23903
24447
|
}
|
|
23904
24448
|
}
|
|
23905
|
-
async function
|
|
24449
|
+
async function verifyRestoredOrLocallyChangedFiles(snapshots) {
|
|
23906
24450
|
for (const snapshot of snapshots) {
|
|
23907
|
-
const
|
|
23908
|
-
if (
|
|
23909
|
-
if (!snapshot.exists) continue;
|
|
23910
|
-
if (!restored.bytes?.equals(snapshot.bytes) || restored.mode !== snapshot.mode) {
|
|
23911
|
-
throw new Error(`O restauro exato de ${snapshot.path} n\xE3o foi confirmado`);
|
|
23912
|
-
}
|
|
24451
|
+
const current = await captureExactFile(snapshot.path);
|
|
24452
|
+
if (snapshot.exists && !current.exists) throw new Error(`N\xE3o foi poss\xEDvel verificar ${snapshot.path}`);
|
|
23913
24453
|
}
|
|
23914
24454
|
}
|
|
23915
24455
|
async function listFilesRecursively(root) {
|
|
23916
|
-
const entries = await
|
|
24456
|
+
const entries = await readdir2(root, { withFileTypes: true }).catch((error45) => {
|
|
23917
24457
|
if (error45.code === "ENOENT") return [];
|
|
23918
24458
|
throw error45;
|
|
23919
24459
|
});
|
|
23920
24460
|
const files = [];
|
|
23921
24461
|
for (const entry of entries) {
|
|
23922
|
-
const absolute =
|
|
24462
|
+
const absolute = path3.join(root, entry.name);
|
|
23923
24463
|
if (entry.isDirectory()) files.push(...await listFilesRecursively(absolute));
|
|
23924
24464
|
else if (entry.isFile()) files.push(absolute);
|
|
23925
24465
|
}
|
|
23926
24466
|
return files;
|
|
23927
24467
|
}
|
|
23928
|
-
async function removeRecordedAgents(agentsDir, filenames) {
|
|
23929
|
-
for (const filename of filenames) {
|
|
23930
|
-
await rm(path2.join(agentsDir, filename), { force: true });
|
|
23931
|
-
}
|
|
23932
|
-
}
|
|
23933
|
-
async function removeRecordedCommands(commandsDir, filenames) {
|
|
23934
|
-
for (const filename of filenames) {
|
|
23935
|
-
await rm(path2.join(commandsDir, filename), { force: true });
|
|
23936
|
-
}
|
|
23937
|
-
}
|
|
23938
24468
|
async function validateSkillFolder(folder, slug) {
|
|
23939
|
-
const skillMd = await
|
|
24469
|
+
const skillMd = await readFile2(path3.join(folder, "SKILL.md"), "utf8");
|
|
23940
24470
|
const frontmatter = /^---\n([\s\S]+?)\n---/.exec(skillMd)?.[1] ?? "";
|
|
23941
24471
|
if (!frontmatter.includes(`name: ${slug}`) && !frontmatter.includes(`name: "${slug}"`)) {
|
|
23942
24472
|
throw new Error(`O campo name no frontmatter de SKILL.md tem de corresponder a ${slug}`);
|
|
@@ -23946,26 +24476,26 @@ async function validateSkillFolder(folder, slug) {
|
|
|
23946
24476
|
}
|
|
23947
24477
|
}
|
|
23948
24478
|
async function assertNoReservedMarkerAliases(skillFolder) {
|
|
23949
|
-
const reserved = /* @__PURE__ */ new Set([".forge-version", ".forge-agents", ".forge-commands"]);
|
|
23950
|
-
const entries = await
|
|
24479
|
+
const reserved = /* @__PURE__ */ new Set([".forge-version", ".forge-agents", ".forge-commands", WORK_PACK_LOCAL_STATE_FILENAME]);
|
|
24480
|
+
const entries = await readdir2(skillFolder);
|
|
23951
24481
|
const marker = entries.find((entry) => reserved.has(entry.toLowerCase()));
|
|
23952
24482
|
if (marker) throw new Error(`O pacote de trabalho cont\xE9m o marcador Forge reservado ${marker}`);
|
|
23953
24483
|
}
|
|
23954
|
-
async function
|
|
24484
|
+
async function writeJsonAtomic2(filePath, value) {
|
|
23955
24485
|
const content = `${JSON.stringify(value, null, 2)}
|
|
23956
24486
|
`;
|
|
23957
24487
|
await writeTextAtomic(filePath, content);
|
|
23958
24488
|
}
|
|
23959
24489
|
async function writeTextAtomic(filePath, content) {
|
|
23960
|
-
const dir =
|
|
23961
|
-
await
|
|
23962
|
-
const tempPath =
|
|
23963
|
-
await
|
|
23964
|
-
await
|
|
24490
|
+
const dir = path3.dirname(filePath);
|
|
24491
|
+
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);
|
|
23965
24495
|
}
|
|
23966
24496
|
|
|
23967
24497
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
23968
|
-
var PLUGIN_VERSION = "0.1.
|
|
24498
|
+
var PLUGIN_VERSION = "0.1.13";
|
|
23969
24499
|
var STATUS_FILENAME = "work-pack-startup-status.json";
|
|
23970
24500
|
var activeSync = /* @__PURE__ */ new Map();
|
|
23971
24501
|
var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
@@ -24061,7 +24591,7 @@ function resolveStartupPaths() {
|
|
|
24061
24591
|
return resolvePaths(void 0, void 0, env);
|
|
24062
24592
|
}
|
|
24063
24593
|
async function readWellKnownForgeCredentials(authPath, forgeBaseUrl) {
|
|
24064
|
-
const raw = await
|
|
24594
|
+
const raw = await readFile3(authPath, "utf8");
|
|
24065
24595
|
const parsed = JSON.parse(raw.startsWith("\uFEFF") ? raw.slice(1) : raw);
|
|
24066
24596
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
24067
24597
|
throw new Error("A autentica\xE7\xE3o do OpenCode n\xE3o \xE9 um objeto JSON v\xE1lido");
|
|
@@ -24092,22 +24622,22 @@ function parseForgeBaseUrl(options) {
|
|
|
24092
24622
|
async function managedProjectionNames(paths) {
|
|
24093
24623
|
const agents = /* @__PURE__ */ new Set();
|
|
24094
24624
|
const commands = /* @__PURE__ */ new Set();
|
|
24095
|
-
const entries = await
|
|
24625
|
+
const entries = await readdir3(paths.skillsDir, { withFileTypes: true }).catch((error45) => {
|
|
24096
24626
|
if (error45.code === "ENOENT") return [];
|
|
24097
24627
|
throw error45;
|
|
24098
24628
|
});
|
|
24099
24629
|
for (const entry of entries) {
|
|
24100
24630
|
if (!entry.isDirectory()) continue;
|
|
24101
|
-
const folder =
|
|
24102
|
-
const marker = await
|
|
24631
|
+
const folder = path4.join(paths.skillsDir, entry.name);
|
|
24632
|
+
const marker = await readFile3(path4.join(folder, ".forge-version"), "utf8").catch(() => "");
|
|
24103
24633
|
if (!marker.trim()) continue;
|
|
24104
|
-
for (const name of await readProjectionRecord(
|
|
24105
|
-
for (const name of await readProjectionRecord(
|
|
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));
|
|
24106
24636
|
}
|
|
24107
24637
|
return { agents, commands };
|
|
24108
24638
|
}
|
|
24109
24639
|
async function readProjectionRecord(filePath) {
|
|
24110
|
-
const raw = await
|
|
24640
|
+
const raw = await readFile3(filePath, "utf8").catch(() => "");
|
|
24111
24641
|
return raw.split("\n").map((line) => line.trim()).filter(
|
|
24112
24642
|
(line) => line.endsWith(".md") && !line.includes("/") && !line.includes("\\") && line !== ".."
|
|
24113
24643
|
);
|
|
@@ -24118,21 +24648,21 @@ async function projectCurrentExtensions(config2, state) {
|
|
|
24118
24648
|
for (const name of state.before.agents) if (!state.after.agents.has(name)) delete agents[name];
|
|
24119
24649
|
for (const name of state.before.commands) if (!state.after.commands.has(name)) delete commands[name];
|
|
24120
24650
|
for (const name of state.after.agents) {
|
|
24121
|
-
agents[name] = await parseMarkdownConfig(
|
|
24651
|
+
agents[name] = await parseMarkdownConfig(path4.join(state.paths.agentsDir, `${name}.md`), "prompt");
|
|
24122
24652
|
}
|
|
24123
24653
|
for (const name of state.after.commands) {
|
|
24124
|
-
commands[name] = await parseMarkdownConfig(
|
|
24654
|
+
commands[name] = await parseMarkdownConfig(path4.join(state.paths.commandsDir, `${name}.md`), "template");
|
|
24125
24655
|
}
|
|
24126
24656
|
config2.agent = agents;
|
|
24127
24657
|
config2.command = commands;
|
|
24128
24658
|
}
|
|
24129
24659
|
async function parseMarkdownConfig(filePath, bodyField) {
|
|
24130
|
-
const raw = await
|
|
24660
|
+
const raw = await readFile3(filePath, "utf8");
|
|
24131
24661
|
const match = /^---\r?\n([\s\S]+?)\r?\n---\r?\n?([\s\S]*)$/.exec(raw);
|
|
24132
|
-
if (!match) throw new Error(`A extens\xE3o Forge ${
|
|
24662
|
+
if (!match) throw new Error(`A extens\xE3o Forge ${path4.basename(filePath)} n\xE3o tem frontmatter v\xE1lido`);
|
|
24133
24663
|
const data = (0, import_yaml.parse)(match[1]);
|
|
24134
24664
|
if (!data || typeof data !== "object" || Array.isArray(data)) {
|
|
24135
|
-
throw new Error(`A extens\xE3o Forge ${
|
|
24665
|
+
throw new Error(`A extens\xE3o Forge ${path4.basename(filePath)} n\xE3o tem frontmatter v\xE1lido`);
|
|
24136
24666
|
}
|
|
24137
24667
|
const config2 = { ...data, [bodyField]: match[2].trim() };
|
|
24138
24668
|
if (bodyField === "prompt" && typeof config2.permission === "string" && ["allow", "ask", "deny"].includes(config2.permission)) {
|
|
@@ -24147,12 +24677,12 @@ function stripMarkdownExtension(filename) {
|
|
|
24147
24677
|
return filename.slice(0, -3);
|
|
24148
24678
|
}
|
|
24149
24679
|
async function writeStatus(paths, value) {
|
|
24150
|
-
await
|
|
24151
|
-
const target =
|
|
24152
|
-
const temporary =
|
|
24153
|
-
await
|
|
24680
|
+
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)}
|
|
24154
24684
|
`, { mode: 384 });
|
|
24155
|
-
await
|
|
24685
|
+
await rename3(temporary, target);
|
|
24156
24686
|
}
|
|
24157
24687
|
function safeErrorMessage(error45) {
|
|
24158
24688
|
const message = error45 instanceof Error ? error45.message : "erro desconhecido";
|