minimal-forge-work-pack-sync 0.1.16 → 0.1.18
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 +557 -338
- 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, path7) {
|
|
121
|
+
const ctrl = callVisitor(key, node, visitor, path7);
|
|
122
122
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
123
|
-
replaceNode(key,
|
|
124
|
-
return visit_(key, ctrl, visitor,
|
|
123
|
+
replaceNode(key, path7, ctrl);
|
|
124
|
+
return visit_(key, ctrl, visitor, path7);
|
|
125
125
|
}
|
|
126
126
|
if (typeof ctrl !== "symbol") {
|
|
127
127
|
if (identity.isCollection(node)) {
|
|
128
|
-
|
|
128
|
+
path7 = Object.freeze(path7.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, path7);
|
|
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
|
+
path7 = Object.freeze(path7.concat(node));
|
|
142
|
+
const ck = visit_("key", node.key, visitor, path7);
|
|
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, path7);
|
|
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, path7) {
|
|
169
|
+
const ctrl = await callVisitor(key, node, visitor, path7);
|
|
170
170
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
171
|
-
replaceNode(key,
|
|
172
|
-
return visitAsync_(key, ctrl, visitor,
|
|
171
|
+
replaceNode(key, path7, ctrl);
|
|
172
|
+
return visitAsync_(key, ctrl, visitor, path7);
|
|
173
173
|
}
|
|
174
174
|
if (typeof ctrl !== "symbol") {
|
|
175
175
|
if (identity.isCollection(node)) {
|
|
176
|
-
|
|
176
|
+
path7 = Object.freeze(path7.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, path7);
|
|
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
|
+
path7 = Object.freeze(path7.concat(node));
|
|
190
|
+
const ck = await visitAsync_("key", node.key, visitor, path7);
|
|
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, path7);
|
|
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, path7) {
|
|
223
223
|
if (typeof visitor === "function")
|
|
224
|
-
return visitor(key, node,
|
|
224
|
+
return visitor(key, node, path7);
|
|
225
225
|
if (identity.isMap(node))
|
|
226
|
-
return visitor.Map?.(key, node,
|
|
226
|
+
return visitor.Map?.(key, node, path7);
|
|
227
227
|
if (identity.isSeq(node))
|
|
228
|
-
return visitor.Seq?.(key, node,
|
|
228
|
+
return visitor.Seq?.(key, node, path7);
|
|
229
229
|
if (identity.isPair(node))
|
|
230
|
-
return visitor.Pair?.(key, node,
|
|
230
|
+
return visitor.Pair?.(key, node, path7);
|
|
231
231
|
if (identity.isScalar(node))
|
|
232
|
-
return visitor.Scalar?.(key, node,
|
|
232
|
+
return visitor.Scalar?.(key, node, path7);
|
|
233
233
|
if (identity.isAlias(node))
|
|
234
|
-
return visitor.Alias?.(key, node,
|
|
234
|
+
return visitor.Alias?.(key, node, path7);
|
|
235
235
|
return void 0;
|
|
236
236
|
}
|
|
237
|
-
function replaceNode(key,
|
|
238
|
-
const parent =
|
|
237
|
+
function replaceNode(key, path7, node) {
|
|
238
|
+
const parent = path7[path7.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, path7, value) {
|
|
849
849
|
let v2 = value;
|
|
850
|
-
for (let i =
|
|
851
|
-
const k2 =
|
|
850
|
+
for (let i = path7.length - 1; i >= 0; --i) {
|
|
851
|
+
const k2 = path7[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 = (path7) => path7 == null || typeof path7 === "object" && !!path7[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(path7, value) {
|
|
901
|
+
if (isEmptyPath(path7))
|
|
902
902
|
this.add(value);
|
|
903
903
|
else {
|
|
904
|
-
const [key, ...rest] =
|
|
904
|
+
const [key, ...rest] = path7;
|
|
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(path7) {
|
|
919
|
+
const [key, ...rest] = path7;
|
|
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(path7, keepScalar) {
|
|
934
|
+
const [key, ...rest] = path7;
|
|
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(path7) {
|
|
953
|
+
const [key, ...rest] = path7;
|
|
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(path7, value) {
|
|
964
|
+
const [key, ...rest] = path7;
|
|
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(path7, value) {
|
|
3480
3480
|
if (assertCollection(this.contents))
|
|
3481
|
-
this.contents.addIn(
|
|
3481
|
+
this.contents.addIn(path7, 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(path7) {
|
|
3557
|
+
if (Collection.isEmptyPath(path7)) {
|
|
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(path7) : 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(path7, keepScalar) {
|
|
3579
|
+
if (Collection.isEmptyPath(path7))
|
|
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(path7, 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(path7) {
|
|
3593
|
+
if (Collection.isEmptyPath(path7))
|
|
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(path7) : 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(path7, value) {
|
|
3613
|
+
if (Collection.isEmptyPath(path7)) {
|
|
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(path7), value);
|
|
3617
3617
|
} else if (assertCollection(this.contents)) {
|
|
3618
|
-
this.contents.setIn(
|
|
3618
|
+
this.contents.setIn(path7, 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, path7) => {
|
|
5579
5579
|
let item = cst;
|
|
5580
|
-
for (const [field, index] of
|
|
5580
|
+
for (const [field, index] of path7) {
|
|
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, path7) => {
|
|
5590
|
+
const parent = visit.itemAtPath(cst, path7.slice(0, -1));
|
|
5591
|
+
const field = path7[path7.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(path7, item, visitor) {
|
|
5598
|
+
let ctrl = visitor(item, path7);
|
|
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(path7.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, path7);
|
|
5617
5617
|
}
|
|
5618
5618
|
}
|
|
5619
|
-
return typeof ctrl === "function" ? ctrl(item,
|
|
5619
|
+
return typeof ctrl === "function" ? ctrl(item, path7) : ctrl;
|
|
5620
5620
|
}
|
|
5621
5621
|
exports.visit = visit;
|
|
5622
5622
|
}
|
|
@@ -7368,7 +7368,7 @@ var require_dist = __commonJS({
|
|
|
7368
7368
|
});
|
|
7369
7369
|
|
|
7370
7370
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
7371
|
-
import { createHash as
|
|
7371
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
7372
7372
|
import { pathToFileURL } from "node:url";
|
|
7373
7373
|
|
|
7374
7374
|
// packages/cli/src/skillUsageReporter.ts
|
|
@@ -7614,7 +7614,7 @@ var DEFAULT_DEBUG_TRACE_LIMITS = {
|
|
|
7614
7614
|
};
|
|
7615
7615
|
|
|
7616
7616
|
// packages/shared/src/contracts/settings.ts
|
|
7617
|
-
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.
|
|
7617
|
+
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.18";
|
|
7618
7618
|
var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
|
|
7619
7619
|
var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
|
|
7620
7620
|
var FIRECRAWL_KEYLESS_MCP_NAME = "firecrawl";
|
|
@@ -7656,6 +7656,39 @@ function canonicalWorkPackState(state) {
|
|
|
7656
7656
|
commands: [...state.commands].sort((a, b2) => compare(a.filename, b2.filename))
|
|
7657
7657
|
});
|
|
7658
7658
|
}
|
|
7659
|
+
function parseWorkPackFileManifest(value) {
|
|
7660
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
7661
|
+
const state = value;
|
|
7662
|
+
if (state.schemaVersion !== 1 || typeof state.version !== "string" || !state.version || state.version.length > 14 * 1024) return void 0;
|
|
7663
|
+
const validPath = (name, filenameOnly = false) => typeof name === "string" && name.length > 0 && name.length <= 4096 && !/[\\\\\u0000-\u001f\u007f]/.test(name) && !/^[A-Za-z]:/.test(name) && name.split("/").every((part) => part && part !== "." && part !== "..") && (!filenameOnly || !name.includes("/"));
|
|
7664
|
+
const digests = (entries, key) => {
|
|
7665
|
+
if (!Array.isArray(entries) || entries.length > 5e3) return false;
|
|
7666
|
+
const names = /* @__PURE__ */ new Set();
|
|
7667
|
+
return entries.every((entry) => {
|
|
7668
|
+
if (!entry || typeof entry !== "object" || !validPath(entry[key], key === "filename") || typeof entry.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(entry.sha256) || Object.keys(entry).some((field) => field !== key && field !== "sha256") || names.has(entry[key])) return false;
|
|
7669
|
+
names.add(entry[key]);
|
|
7670
|
+
return true;
|
|
7671
|
+
});
|
|
7672
|
+
};
|
|
7673
|
+
if (Object.keys(state).some((key) => !["schemaVersion", "version", "files", "directories", "agents", "commands"].includes(key)) || !digests(state.files, "path") || !digests(state.agents, "filename") || !digests(state.commands, "filename") || !Array.isArray(state.directories) || state.directories.length > 5e3 || !state.directories.every((name) => validPath(name)) || new Set(state.directories).size !== state.directories.length) return void 0;
|
|
7674
|
+
const manifest = state;
|
|
7675
|
+
const directories = new Set(manifest.directories);
|
|
7676
|
+
if (manifest.files.some((file2) => directories.has(file2.path) || file2.path === ".forge-installed-state.json")) return void 0;
|
|
7677
|
+
for (const name of [...manifest.files.map((file2) => file2.path), ...manifest.directories]) {
|
|
7678
|
+
const parts = name.split("/");
|
|
7679
|
+
for (let i = 1; i < parts.length; i++) if (!directories.has(parts.slice(0, i).join("/"))) return void 0;
|
|
7680
|
+
}
|
|
7681
|
+
return manifest;
|
|
7682
|
+
}
|
|
7683
|
+
|
|
7684
|
+
// packages/shared/src/workPackIntegrity.ts
|
|
7685
|
+
function integrityKind(summary) {
|
|
7686
|
+
if (summary.unsafe || summary.unreadable || summary.truncated) return "unsafe-or-unreadable";
|
|
7687
|
+
if (summary.modified || summary.missing) return "source-changes";
|
|
7688
|
+
if (summary.additional) return "unknown-additions";
|
|
7689
|
+
if (summary.runtimeArtifacts) return "runtime-artifacts";
|
|
7690
|
+
return "match";
|
|
7691
|
+
}
|
|
7659
7692
|
|
|
7660
7693
|
// packages/cli/src/pluginWriter.ts
|
|
7661
7694
|
var FORGE_PLUGIN_HEADER = "// Managed by Forge sync. Do not edit.";
|
|
@@ -7824,8 +7857,8 @@ async function replaceFile(filename, contents) {
|
|
|
7824
7857
|
|
|
7825
7858
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
7826
7859
|
var import_yaml = __toESM(require_dist(), 1);
|
|
7827
|
-
import { mkdir as mkdir3, readdir as
|
|
7828
|
-
import
|
|
7860
|
+
import { mkdir as mkdir3, readdir as readdir4, readFile as readFile4, rename as rename4, writeFile as writeFile4 } from "node:fs/promises";
|
|
7861
|
+
import path6 from "node:path";
|
|
7829
7862
|
|
|
7830
7863
|
// node_modules/@opencode-ai/plugin/node_modules/zod/v4/classic/external.js
|
|
7831
7864
|
var external_exports = {};
|
|
@@ -8558,10 +8591,10 @@ function mergeDefs(...defs) {
|
|
|
8558
8591
|
function cloneDef(schema) {
|
|
8559
8592
|
return mergeDefs(schema._zod.def);
|
|
8560
8593
|
}
|
|
8561
|
-
function getElementAtPath(obj,
|
|
8562
|
-
if (!
|
|
8594
|
+
function getElementAtPath(obj, path7) {
|
|
8595
|
+
if (!path7)
|
|
8563
8596
|
return obj;
|
|
8564
|
-
return
|
|
8597
|
+
return path7.reduce((acc, key) => acc?.[key], obj);
|
|
8565
8598
|
}
|
|
8566
8599
|
function promiseAllObject(promisesObj) {
|
|
8567
8600
|
const keys = Object.keys(promisesObj);
|
|
@@ -8922,11 +8955,11 @@ function aborted(x, startIndex = 0) {
|
|
|
8922
8955
|
}
|
|
8923
8956
|
return false;
|
|
8924
8957
|
}
|
|
8925
|
-
function prefixIssues(
|
|
8958
|
+
function prefixIssues(path7, issues) {
|
|
8926
8959
|
return issues.map((iss) => {
|
|
8927
8960
|
var _a;
|
|
8928
8961
|
(_a = iss).path ?? (_a.path = []);
|
|
8929
|
-
iss.path.unshift(
|
|
8962
|
+
iss.path.unshift(path7);
|
|
8930
8963
|
return iss;
|
|
8931
8964
|
});
|
|
8932
8965
|
}
|
|
@@ -9094,7 +9127,7 @@ function treeifyError(error45, _mapper) {
|
|
|
9094
9127
|
return issue2.message;
|
|
9095
9128
|
};
|
|
9096
9129
|
const result = { errors: [] };
|
|
9097
|
-
const processError = (error46,
|
|
9130
|
+
const processError = (error46, path7 = []) => {
|
|
9098
9131
|
var _a, _b;
|
|
9099
9132
|
for (const issue2 of error46.issues) {
|
|
9100
9133
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
@@ -9104,7 +9137,7 @@ function treeifyError(error45, _mapper) {
|
|
|
9104
9137
|
} else if (issue2.code === "invalid_element") {
|
|
9105
9138
|
processError({ issues: issue2.issues }, issue2.path);
|
|
9106
9139
|
} else {
|
|
9107
|
-
const fullpath = [...
|
|
9140
|
+
const fullpath = [...path7, ...issue2.path];
|
|
9108
9141
|
if (fullpath.length === 0) {
|
|
9109
9142
|
result.errors.push(mapper(issue2));
|
|
9110
9143
|
continue;
|
|
@@ -9136,8 +9169,8 @@ function treeifyError(error45, _mapper) {
|
|
|
9136
9169
|
}
|
|
9137
9170
|
function toDotPath(_path) {
|
|
9138
9171
|
const segs = [];
|
|
9139
|
-
const
|
|
9140
|
-
for (const seg of
|
|
9172
|
+
const path7 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
9173
|
+
for (const seg of path7) {
|
|
9141
9174
|
if (typeof seg === "number")
|
|
9142
9175
|
segs.push(`[${seg}]`);
|
|
9143
9176
|
else if (typeof seg === "symbol")
|
|
@@ -20337,12 +20370,329 @@ async function reportWorkPackObservations(credentials, kind, workPacks) {
|
|
|
20337
20370
|
}
|
|
20338
20371
|
}
|
|
20339
20372
|
|
|
20340
|
-
// packages/cli/src/
|
|
20373
|
+
// packages/cli/src/workPackIntegrity.ts
|
|
20341
20374
|
import { createHash as createHash2 } from "node:crypto";
|
|
20342
|
-
import {
|
|
20343
|
-
import
|
|
20375
|
+
import { constants } from "node:fs";
|
|
20376
|
+
import { lstat as lstat3, open, readdir as readdir2 } from "node:fs/promises";
|
|
20344
20377
|
import path4 from "node:path";
|
|
20345
20378
|
|
|
20379
|
+
// packages/cli/src/workPackLocalState.ts
|
|
20380
|
+
import { createHash } from "node:crypto";
|
|
20381
|
+
import { lstat as lstat2, mkdir, readFile as readFile2, readdir, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
|
|
20382
|
+
import path3 from "node:path";
|
|
20383
|
+
var WORK_PACK_LOCAL_STATE_FILENAME = ".forge-installed-state.json";
|
|
20384
|
+
async function writeWorkPackInstalledState(input) {
|
|
20385
|
+
const tree = await digestPackTree(input.packDir);
|
|
20386
|
+
if (!tree) throw new Error("O pacote de trabalho cont\xE9m uma entrada local n\xE3o regular");
|
|
20387
|
+
const state = {
|
|
20388
|
+
schemaVersion: 1,
|
|
20389
|
+
version: input.version,
|
|
20390
|
+
...tree,
|
|
20391
|
+
agents: digestProjectionContents(input.agents),
|
|
20392
|
+
commands: digestProjectionContents(input.commands)
|
|
20393
|
+
};
|
|
20394
|
+
await writeJsonAtomic(path3.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
|
|
20395
|
+
}
|
|
20396
|
+
async function checkWorkPackInstalledState(input) {
|
|
20397
|
+
const state = await readInstalledState(input.packDir);
|
|
20398
|
+
if (!state) return "missing";
|
|
20399
|
+
return await matchesInstalledState(input, state) ? "match" : "changed";
|
|
20400
|
+
}
|
|
20401
|
+
async function checkWorkPackTreeState(packDir) {
|
|
20402
|
+
const state = await readInstalledState(packDir);
|
|
20403
|
+
if (!state) return "missing";
|
|
20404
|
+
const tree = await digestPackTree(packDir).catch(() => void 0);
|
|
20405
|
+
return tree && sameTree(tree, state) ? "match" : "changed";
|
|
20406
|
+
}
|
|
20407
|
+
async function adoptWorkPackInstalledState(input) {
|
|
20408
|
+
const state = await readInstalledState(input.expectedPackDir);
|
|
20409
|
+
if (!state || !await matchesInstalledState(input, state)) return false;
|
|
20410
|
+
await writeJsonAtomic(path3.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
|
|
20411
|
+
return checkWorkPackInstalledState(input).then((result) => result === "match");
|
|
20412
|
+
}
|
|
20413
|
+
async function adoptVerifiedWorkPackState(input) {
|
|
20414
|
+
const tree = await digestPackTree(input.packDir);
|
|
20415
|
+
if (!tree) return false;
|
|
20416
|
+
const projections = async (kind, directory) => {
|
|
20417
|
+
const prefix = `${kind}/`;
|
|
20418
|
+
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("._"));
|
|
20419
|
+
const result = [];
|
|
20420
|
+
for (const file2 of expected) {
|
|
20421
|
+
const filename = file2.path.slice(prefix.length);
|
|
20422
|
+
const absolute = path3.join(directory, filename);
|
|
20423
|
+
const info = await lstat2(absolute);
|
|
20424
|
+
if (!info.isFile() || info.isSymbolicLink()) throw new Error("Unsafe projection");
|
|
20425
|
+
result.push({ filename, sha256: digest(await readFile2(absolute)) });
|
|
20426
|
+
}
|
|
20427
|
+
return result.sort((a, b2) => a.filename.localeCompare(b2.filename));
|
|
20428
|
+
};
|
|
20429
|
+
const state = {
|
|
20430
|
+
schemaVersion: 1,
|
|
20431
|
+
version: input.version,
|
|
20432
|
+
...tree,
|
|
20433
|
+
agents: await projections("agents", input.agentsDir),
|
|
20434
|
+
commands: await projections("commands", input.commandsDir)
|
|
20435
|
+
};
|
|
20436
|
+
if (digest(Buffer.from(canonicalWorkPackState(state))) !== input.fingerprint) return false;
|
|
20437
|
+
if (!await matchesInstalledState(input, state)) return false;
|
|
20438
|
+
await writeJsonAtomic(path3.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
|
|
20439
|
+
return await checkWorkPackInstalledState(input) === "match";
|
|
20440
|
+
}
|
|
20441
|
+
async function readInstalledState(packDir) {
|
|
20442
|
+
const info = await lstat2(path3.join(packDir, WORK_PACK_LOCAL_STATE_FILENAME)).catch(() => void 0);
|
|
20443
|
+
if (!info?.isFile() || info.isSymbolicLink() || info.size > 1024 * 1024) return void 0;
|
|
20444
|
+
const raw = await readFile2(path3.join(packDir, WORK_PACK_LOCAL_STATE_FILENAME), "utf8").catch(() => void 0);
|
|
20445
|
+
if (!raw) return void 0;
|
|
20446
|
+
try {
|
|
20447
|
+
return parseWorkPackFileManifest(JSON.parse(raw));
|
|
20448
|
+
} catch {
|
|
20449
|
+
return void 0;
|
|
20450
|
+
}
|
|
20451
|
+
}
|
|
20452
|
+
async function digestPackTree(root) {
|
|
20453
|
+
const files = [];
|
|
20454
|
+
const directories = [];
|
|
20455
|
+
const visit = async (directory, prefix) => {
|
|
20456
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
20457
|
+
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
20458
|
+
if (!prefix && entry.name === WORK_PACK_LOCAL_STATE_FILENAME) continue;
|
|
20459
|
+
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
20460
|
+
const absolute = path3.join(directory, entry.name);
|
|
20461
|
+
if (entry.isDirectory()) {
|
|
20462
|
+
directories.push(relative);
|
|
20463
|
+
if (!await visit(absolute, relative)) return false;
|
|
20464
|
+
continue;
|
|
20465
|
+
}
|
|
20466
|
+
if (!entry.isFile()) return false;
|
|
20467
|
+
files.push({ path: relative, sha256: digest(await readFile2(absolute)) });
|
|
20468
|
+
}
|
|
20469
|
+
return true;
|
|
20470
|
+
};
|
|
20471
|
+
return await visit(root, "") ? { files, directories } : void 0;
|
|
20472
|
+
}
|
|
20473
|
+
function digestProjectionContents(files) {
|
|
20474
|
+
return files.map((file2) => ({ filename: file2.filename, sha256: digest(Buffer.from(file2.content)) })).sort((left, right) => left.filename.localeCompare(right.filename));
|
|
20475
|
+
}
|
|
20476
|
+
async function projectionsMatch(directory, expected) {
|
|
20477
|
+
for (const projection of expected) {
|
|
20478
|
+
const absolute = path3.join(directory, projection.filename);
|
|
20479
|
+
const info = await lstat2(absolute).catch(() => void 0);
|
|
20480
|
+
if (!info?.isFile() || info.isSymbolicLink()) return false;
|
|
20481
|
+
const bytes = await readFile2(absolute).catch(() => void 0);
|
|
20482
|
+
if (!bytes || digest(bytes) !== projection.sha256) return false;
|
|
20483
|
+
}
|
|
20484
|
+
return true;
|
|
20485
|
+
}
|
|
20486
|
+
async function matchesInstalledState(input, state) {
|
|
20487
|
+
const tree = await digestPackTree(input.packDir).catch(() => void 0);
|
|
20488
|
+
if (!tree || !sameTree(tree, state)) return false;
|
|
20489
|
+
if (!await projectionsMatch(input.agentsDir, state.agents)) return false;
|
|
20490
|
+
return projectionsMatch(input.commandsDir, state.commands);
|
|
20491
|
+
}
|
|
20492
|
+
function sameTree(left, right) {
|
|
20493
|
+
const directories = new Set(right.directories);
|
|
20494
|
+
return sameDigests(left.files, right.files) && left.directories.length === directories.size && left.directories.every((entry) => directories.has(entry));
|
|
20495
|
+
}
|
|
20496
|
+
function sameDigests(left, right) {
|
|
20497
|
+
const expected = new Map(right.map((entry) => [entry.path, entry.sha256]));
|
|
20498
|
+
return left.length === expected.size && left.every((entry) => entry.sha256 === expected.get(entry.path));
|
|
20499
|
+
}
|
|
20500
|
+
function digest(bytes) {
|
|
20501
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
20502
|
+
}
|
|
20503
|
+
async function writeJsonAtomic(filePath, value) {
|
|
20504
|
+
await mkdir(path3.dirname(filePath), { recursive: true });
|
|
20505
|
+
const tempPath = path3.join(path3.dirname(filePath), `.${path3.basename(filePath)}.${process.pid}.tmp`);
|
|
20506
|
+
await writeFile2(tempPath, `${JSON.stringify(value, null, 2)}
|
|
20507
|
+
`);
|
|
20508
|
+
await rename2(tempPath, filePath);
|
|
20509
|
+
}
|
|
20510
|
+
|
|
20511
|
+
// packages/cli/src/workPackIntegrity.ts
|
|
20512
|
+
var MAX_ENTRIES = 1e4;
|
|
20513
|
+
var MAX_DIFFERENCES = 100;
|
|
20514
|
+
var MAX_FILE_BYTES = 64 * 1024 * 1024;
|
|
20515
|
+
function emptySummary() {
|
|
20516
|
+
return {
|
|
20517
|
+
reference: "unavailable",
|
|
20518
|
+
kind: "baseline-unavailable",
|
|
20519
|
+
modified: 0,
|
|
20520
|
+
missing: 0,
|
|
20521
|
+
additional: 0,
|
|
20522
|
+
runtimeArtifacts: 0,
|
|
20523
|
+
unsafe: 0,
|
|
20524
|
+
unreadable: 0,
|
|
20525
|
+
truncated: false
|
|
20526
|
+
};
|
|
20527
|
+
}
|
|
20528
|
+
async function inspectWorkPackIntegrity(input) {
|
|
20529
|
+
assertSlug(input.slug);
|
|
20530
|
+
const packDir = path4.join(input.paths.skillsDir, input.slug);
|
|
20531
|
+
const result = { slug: input.slug, summary: emptySummary(), differences: [], differencesTruncated: false };
|
|
20532
|
+
const add = (kind, area, name) => {
|
|
20533
|
+
if (result.summary[kind] === MAX_ENTRIES) result.summary.truncated = true;
|
|
20534
|
+
result.summary[kind] = Math.min(MAX_ENTRIES, result.summary[kind] + 1);
|
|
20535
|
+
if (result.differences.length < MAX_DIFFERENCES) result.differences.push({ kind, area, path: name });
|
|
20536
|
+
else result.differencesTruncated = true;
|
|
20537
|
+
};
|
|
20538
|
+
const root = await lstat3(packDir).catch(() => void 0);
|
|
20539
|
+
if (!root?.isDirectory() || root.isSymbolicLink()) {
|
|
20540
|
+
add(root ? "unsafe" : "unreadable", "pack", ".");
|
|
20541
|
+
result.summary.kind = "unsafe-or-unreadable";
|
|
20542
|
+
return result;
|
|
20543
|
+
}
|
|
20544
|
+
const expected = input.expected ? parseWorkPackFileManifest(input.expected) : await readInstalledState(packDir);
|
|
20545
|
+
if (!expected) return result;
|
|
20546
|
+
result.version = expected.version;
|
|
20547
|
+
result.summary.reference = input.expected ? input.reference ?? "server" : "installation-receipt";
|
|
20548
|
+
const readBudget = { remaining: 128 * 1024 * 1024, exceeded: false };
|
|
20549
|
+
const original = new Map(expected.files.map((file2) => [file2.path, file2.sha256]));
|
|
20550
|
+
const directories = new Set(expected.directories);
|
|
20551
|
+
const seenFiles = /* @__PURE__ */ new Set(), seenDirectories = /* @__PURE__ */ new Set(), unchanged = /* @__PURE__ */ new Set();
|
|
20552
|
+
const extraFiles = [], extraDirectories = [], blocked = [];
|
|
20553
|
+
let entries = 0;
|
|
20554
|
+
const walk = async (directory, prefix) => {
|
|
20555
|
+
if (result.summary.truncated) return;
|
|
20556
|
+
let children;
|
|
20557
|
+
try {
|
|
20558
|
+
children = await readdir2(directory, { withFileTypes: true });
|
|
20559
|
+
} catch {
|
|
20560
|
+
add("unreadable", "pack", prefix || ".");
|
|
20561
|
+
blocked.push(prefix);
|
|
20562
|
+
return;
|
|
20563
|
+
}
|
|
20564
|
+
for (const entry of children.sort((a, b2) => a.name < b2.name ? -1 : a.name > b2.name ? 1 : 0)) {
|
|
20565
|
+
if (++entries > MAX_ENTRIES) {
|
|
20566
|
+
result.summary.truncated = true;
|
|
20567
|
+
return;
|
|
20568
|
+
}
|
|
20569
|
+
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
20570
|
+
const absolute = path4.join(directory, entry.name);
|
|
20571
|
+
const info = await lstat3(absolute).catch(() => void 0);
|
|
20572
|
+
if (!info) {
|
|
20573
|
+
add("unreadable", "pack", relative);
|
|
20574
|
+
blocked.push(relative);
|
|
20575
|
+
continue;
|
|
20576
|
+
}
|
|
20577
|
+
if (info.isSymbolicLink() || !info.isDirectory() && !info.isFile() || info.isFile() && info.nlink > 1) {
|
|
20578
|
+
add("unsafe", "pack", relative);
|
|
20579
|
+
blocked.push(relative);
|
|
20580
|
+
continue;
|
|
20581
|
+
}
|
|
20582
|
+
if (!prefix && entry.name === WORK_PACK_LOCAL_STATE_FILENAME) {
|
|
20583
|
+
if (!info.isFile()) add("unsafe", "pack", relative);
|
|
20584
|
+
continue;
|
|
20585
|
+
}
|
|
20586
|
+
if (info.isDirectory()) {
|
|
20587
|
+
seenDirectories.add(relative);
|
|
20588
|
+
if (!directories.has(relative)) extraDirectories.push(relative);
|
|
20589
|
+
if (original.has(relative)) add("unsafe", "pack", relative);
|
|
20590
|
+
if (relative.split("/").length > 64) {
|
|
20591
|
+
add("unsafe", "pack", relative);
|
|
20592
|
+
blocked.push(relative);
|
|
20593
|
+
continue;
|
|
20594
|
+
}
|
|
20595
|
+
await walk(absolute, relative);
|
|
20596
|
+
} else {
|
|
20597
|
+
seenFiles.add(relative);
|
|
20598
|
+
const expectedHash = original.get(relative);
|
|
20599
|
+
if (directories.has(relative)) add("unsafe", "pack", relative);
|
|
20600
|
+
if (expectedHash === void 0) extraFiles.push(relative);
|
|
20601
|
+
else {
|
|
20602
|
+
const digest2 = await regularFileDigest(absolute, readBudget);
|
|
20603
|
+
if (!digest2) add("unreadable", "pack", relative);
|
|
20604
|
+
else if (digest2 !== expectedHash) add("modified", "pack", relative);
|
|
20605
|
+
else unchanged.add(relative);
|
|
20606
|
+
}
|
|
20607
|
+
}
|
|
20608
|
+
}
|
|
20609
|
+
};
|
|
20610
|
+
await walk(packDir, "");
|
|
20611
|
+
const inaccessible = (name) => result.summary.truncated || blocked.some((parent) => !parent || name === parent || name.startsWith(`${parent}/`));
|
|
20612
|
+
for (const name of original.keys()) if (!seenFiles.has(name) && !seenDirectories.has(name) && !inaccessible(name)) add("missing", "pack", name);
|
|
20613
|
+
for (const name of directories) if (!seenDirectories.has(name) && !seenFiles.has(name) && !inaccessible(name)) add("missing", "pack", name);
|
|
20614
|
+
const cacheDirectories = /* @__PURE__ */ new Set();
|
|
20615
|
+
for (const name of extraFiles) {
|
|
20616
|
+
const match = /^(.*\/)?__pycache__\/([^/]+)\.cpython-[0-9]+(?:\.opt-[12])?\.pyc$/.exec(name);
|
|
20617
|
+
const source = match ? `${match[1] ?? ""}${match[2]}.py` : void 0;
|
|
20618
|
+
if (source && unchanged.has(source)) {
|
|
20619
|
+
add("runtimeArtifacts", "pack", name);
|
|
20620
|
+
cacheDirectories.add(path4.posix.dirname(name));
|
|
20621
|
+
} else add("additional", "pack", name);
|
|
20622
|
+
}
|
|
20623
|
+
for (const name of extraDirectories) if (!cacheDirectories.has(name)) add("additional", "pack", name);
|
|
20624
|
+
for (const area of ["agents", "commands"]) {
|
|
20625
|
+
const items = expected[area];
|
|
20626
|
+
if (!items.length) continue;
|
|
20627
|
+
const directory = area === "agents" ? input.paths.agentsDir : input.paths.commandsDir;
|
|
20628
|
+
const directoryInfo = await lstat3(directory).catch(() => void 0);
|
|
20629
|
+
if (directoryInfo && (!directoryInfo.isDirectory() || directoryInfo.isSymbolicLink())) {
|
|
20630
|
+
add("unsafe", area, ".");
|
|
20631
|
+
continue;
|
|
20632
|
+
}
|
|
20633
|
+
for (const item of items) {
|
|
20634
|
+
const absolute = path4.join(directory, item.filename);
|
|
20635
|
+
try {
|
|
20636
|
+
const info = await lstat3(absolute);
|
|
20637
|
+
if (!info.isFile() || info.isSymbolicLink() || info.nlink > 1) add("unsafe", area, item.filename);
|
|
20638
|
+
else {
|
|
20639
|
+
const digest2 = await regularFileDigest(absolute, readBudget);
|
|
20640
|
+
if (!digest2) add("unreadable", area, item.filename);
|
|
20641
|
+
else if (digest2 !== item.sha256) add("modified", area, item.filename);
|
|
20642
|
+
}
|
|
20643
|
+
} catch (error45) {
|
|
20644
|
+
add(error45.code === "ENOENT" ? "missing" : "unreadable", area, item.filename);
|
|
20645
|
+
}
|
|
20646
|
+
}
|
|
20647
|
+
}
|
|
20648
|
+
result.summary.truncated ||= readBudget.exceeded;
|
|
20649
|
+
result.summary.kind = integrityKind(result.summary);
|
|
20650
|
+
return result;
|
|
20651
|
+
}
|
|
20652
|
+
async function regularFileDigest(filePath, budget) {
|
|
20653
|
+
try {
|
|
20654
|
+
const handle = await open(filePath, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
20655
|
+
try {
|
|
20656
|
+
const before = await handle.stat();
|
|
20657
|
+
if (!before.isFile() || before.nlink > 1 || before.size > MAX_FILE_BYTES) return void 0;
|
|
20658
|
+
if (before.size > budget.remaining) {
|
|
20659
|
+
budget.exceeded = true;
|
|
20660
|
+
return void 0;
|
|
20661
|
+
}
|
|
20662
|
+
const hash2 = createHash2("sha256");
|
|
20663
|
+
const buffer = Buffer.alloc(64 * 1024);
|
|
20664
|
+
let total = 0;
|
|
20665
|
+
while (true) {
|
|
20666
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, null);
|
|
20667
|
+
if (!bytesRead) break;
|
|
20668
|
+
total += bytesRead;
|
|
20669
|
+
budget.remaining -= bytesRead;
|
|
20670
|
+
if (budget.remaining < 0) {
|
|
20671
|
+
budget.exceeded = true;
|
|
20672
|
+
return void 0;
|
|
20673
|
+
}
|
|
20674
|
+
if (total > MAX_FILE_BYTES) return void 0;
|
|
20675
|
+
hash2.update(buffer.subarray(0, bytesRead));
|
|
20676
|
+
}
|
|
20677
|
+
const after = await handle.stat();
|
|
20678
|
+
return before.size === after.size && before.mtimeMs === after.mtimeMs && total === before.size ? hash2.digest("hex") : void 0;
|
|
20679
|
+
} finally {
|
|
20680
|
+
await handle.close();
|
|
20681
|
+
}
|
|
20682
|
+
} catch {
|
|
20683
|
+
return void 0;
|
|
20684
|
+
}
|
|
20685
|
+
}
|
|
20686
|
+
function assertSlug(slug) {
|
|
20687
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug) || slug.length > 64) throw new Error("Identificador de skill inv\xE1lido");
|
|
20688
|
+
}
|
|
20689
|
+
|
|
20690
|
+
// packages/cli/src/sync.ts
|
|
20691
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
20692
|
+
import { chmod, cp, lstat as lstat4, mkdtemp, mkdir as mkdir2, readdir as readdir3, readFile as readFile3, rm, rename as rename3, writeFile as writeFile3 } from "node:fs/promises";
|
|
20693
|
+
import os4 from "node:os";
|
|
20694
|
+
import path5 from "node:path";
|
|
20695
|
+
|
|
20346
20696
|
// node_modules/tar/dist/esm/index.min.js
|
|
20347
20697
|
import Qr from "events";
|
|
20348
20698
|
import I from "fs";
|
|
@@ -23407,12 +23757,14 @@ async function reconcileWorkPacks(input) {
|
|
|
23407
23757
|
const receiptValue = {
|
|
23408
23758
|
schemaVersion: 1,
|
|
23409
23759
|
completedAt: (input.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
23410
|
-
outcomes: outcomes.map(({ slug, version: version2, action, reason, status }) => ({
|
|
23760
|
+
outcomes: outcomes.map(({ slug, version: version2, action, reason, status, code, integrity }) => ({
|
|
23411
23761
|
slug,
|
|
23412
23762
|
...version2 === void 0 ? {} : { version: version2 },
|
|
23413
23763
|
action,
|
|
23414
23764
|
reason,
|
|
23415
|
-
status
|
|
23765
|
+
status,
|
|
23766
|
+
...code ? { code } : {},
|
|
23767
|
+
...integrity ? { integrity } : {}
|
|
23416
23768
|
})),
|
|
23417
23769
|
omissionPrune
|
|
23418
23770
|
};
|
|
@@ -23453,6 +23805,7 @@ async function runOperation(operation, operate) {
|
|
|
23453
23805
|
...outcomeIdentity(operation),
|
|
23454
23806
|
status: "failed",
|
|
23455
23807
|
code: stableCode(result.code),
|
|
23808
|
+
...result.integrity ? { integrity: result.integrity } : {},
|
|
23456
23809
|
...result.projectionConflict ? { projectionConflict: result.projectionConflict } : {},
|
|
23457
23810
|
message: `O pacote "${operation.pack.slug}" falhou, mas o estado anterior foi restaurado exatamente. Corrija a causa indicada e volte a sincronizar.`
|
|
23458
23811
|
};
|
|
@@ -23496,152 +23849,6 @@ function assertUniqueSlugs(packs, label) {
|
|
|
23496
23849
|
}
|
|
23497
23850
|
}
|
|
23498
23851
|
|
|
23499
|
-
// packages/cli/src/workPackLocalState.ts
|
|
23500
|
-
import { createHash } from "node:crypto";
|
|
23501
|
-
import { lstat as lstat2, mkdir, readFile as readFile2, readdir, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
|
|
23502
|
-
import path3 from "node:path";
|
|
23503
|
-
var WORK_PACK_LOCAL_STATE_FILENAME = ".forge-installed-state.json";
|
|
23504
|
-
async function writeWorkPackInstalledState(input) {
|
|
23505
|
-
const tree = await digestPackTree(input.packDir);
|
|
23506
|
-
if (!tree) throw new Error("O pacote de trabalho cont\xE9m uma entrada local n\xE3o regular");
|
|
23507
|
-
const state = {
|
|
23508
|
-
schemaVersion: 1,
|
|
23509
|
-
version: input.version,
|
|
23510
|
-
...tree,
|
|
23511
|
-
agents: digestProjectionContents(input.agents),
|
|
23512
|
-
commands: digestProjectionContents(input.commands)
|
|
23513
|
-
};
|
|
23514
|
-
await writeJsonAtomic(path3.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
|
|
23515
|
-
}
|
|
23516
|
-
async function checkWorkPackInstalledState(input) {
|
|
23517
|
-
const state = await readInstalledState(input.packDir);
|
|
23518
|
-
if (!state) return "missing";
|
|
23519
|
-
return await matchesInstalledState(input, state) ? "match" : "changed";
|
|
23520
|
-
}
|
|
23521
|
-
async function checkWorkPackTreeState(packDir) {
|
|
23522
|
-
const state = await readInstalledState(packDir);
|
|
23523
|
-
if (!state) return "missing";
|
|
23524
|
-
const tree = await digestPackTree(packDir).catch(() => void 0);
|
|
23525
|
-
return tree && sameTree(tree, state) ? "match" : "changed";
|
|
23526
|
-
}
|
|
23527
|
-
async function adoptWorkPackInstalledState(input) {
|
|
23528
|
-
const state = await readInstalledState(input.expectedPackDir);
|
|
23529
|
-
if (!state || !await matchesInstalledState(input, state)) return false;
|
|
23530
|
-
await writeJsonAtomic(path3.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
|
|
23531
|
-
return checkWorkPackInstalledState(input).then((result) => result === "match");
|
|
23532
|
-
}
|
|
23533
|
-
async function adoptVerifiedWorkPackState(input) {
|
|
23534
|
-
const tree = await digestPackTree(input.packDir);
|
|
23535
|
-
if (!tree) return false;
|
|
23536
|
-
const projections = async (kind, directory) => {
|
|
23537
|
-
const prefix = `${kind}/`;
|
|
23538
|
-
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("._"));
|
|
23539
|
-
const result = [];
|
|
23540
|
-
for (const file2 of expected) {
|
|
23541
|
-
const filename = file2.path.slice(prefix.length);
|
|
23542
|
-
const absolute = path3.join(directory, filename);
|
|
23543
|
-
const info = await lstat2(absolute);
|
|
23544
|
-
if (!info.isFile() || info.isSymbolicLink()) throw new Error("Unsafe projection");
|
|
23545
|
-
result.push({ filename, sha256: digest(await readFile2(absolute)) });
|
|
23546
|
-
}
|
|
23547
|
-
return result.sort((a, b2) => a.filename.localeCompare(b2.filename));
|
|
23548
|
-
};
|
|
23549
|
-
const state = {
|
|
23550
|
-
schemaVersion: 1,
|
|
23551
|
-
version: input.version,
|
|
23552
|
-
...tree,
|
|
23553
|
-
agents: await projections("agents", input.agentsDir),
|
|
23554
|
-
commands: await projections("commands", input.commandsDir)
|
|
23555
|
-
};
|
|
23556
|
-
if (digest(Buffer.from(canonicalWorkPackState(state))) !== input.fingerprint) return false;
|
|
23557
|
-
if (!await matchesInstalledState(input, state)) return false;
|
|
23558
|
-
await writeJsonAtomic(path3.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
|
|
23559
|
-
return await checkWorkPackInstalledState(input) === "match";
|
|
23560
|
-
}
|
|
23561
|
-
async function readInstalledState(packDir) {
|
|
23562
|
-
const raw = await readFile2(path3.join(packDir, WORK_PACK_LOCAL_STATE_FILENAME), "utf8").catch(() => void 0);
|
|
23563
|
-
if (!raw) return void 0;
|
|
23564
|
-
try {
|
|
23565
|
-
const value = JSON.parse(raw);
|
|
23566
|
-
if (value.schemaVersion !== 1 || typeof value.version !== "string") return void 0;
|
|
23567
|
-
if (!validDigests(value.files, "path") || !validDigests(value.agents, "filename") || !validDigests(value.commands, "filename")) {
|
|
23568
|
-
return void 0;
|
|
23569
|
-
}
|
|
23570
|
-
if (!validDirectories(value.directories)) return void 0;
|
|
23571
|
-
return value;
|
|
23572
|
-
} catch {
|
|
23573
|
-
return void 0;
|
|
23574
|
-
}
|
|
23575
|
-
}
|
|
23576
|
-
async function digestPackTree(root) {
|
|
23577
|
-
const files = [];
|
|
23578
|
-
const directories = [];
|
|
23579
|
-
const visit = async (directory, prefix) => {
|
|
23580
|
-
const entries = await readdir(directory, { withFileTypes: true });
|
|
23581
|
-
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
23582
|
-
if (!prefix && entry.name === WORK_PACK_LOCAL_STATE_FILENAME) continue;
|
|
23583
|
-
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
23584
|
-
const absolute = path3.join(directory, entry.name);
|
|
23585
|
-
if (entry.isDirectory()) {
|
|
23586
|
-
directories.push(relative);
|
|
23587
|
-
if (!await visit(absolute, relative)) return false;
|
|
23588
|
-
continue;
|
|
23589
|
-
}
|
|
23590
|
-
if (!entry.isFile()) return false;
|
|
23591
|
-
files.push({ path: relative, sha256: digest(await readFile2(absolute)) });
|
|
23592
|
-
}
|
|
23593
|
-
return true;
|
|
23594
|
-
};
|
|
23595
|
-
return await visit(root, "") ? { files, directories } : void 0;
|
|
23596
|
-
}
|
|
23597
|
-
function digestProjectionContents(files) {
|
|
23598
|
-
return files.map((file2) => ({ filename: file2.filename, sha256: digest(Buffer.from(file2.content)) })).sort((left, right) => left.filename.localeCompare(right.filename));
|
|
23599
|
-
}
|
|
23600
|
-
async function projectionsMatch(directory, expected) {
|
|
23601
|
-
for (const projection of expected) {
|
|
23602
|
-
const absolute = path3.join(directory, projection.filename);
|
|
23603
|
-
const info = await lstat2(absolute).catch(() => void 0);
|
|
23604
|
-
if (!info?.isFile() || info.isSymbolicLink()) return false;
|
|
23605
|
-
const bytes = await readFile2(absolute).catch(() => void 0);
|
|
23606
|
-
if (!bytes || digest(bytes) !== projection.sha256) return false;
|
|
23607
|
-
}
|
|
23608
|
-
return true;
|
|
23609
|
-
}
|
|
23610
|
-
function validDigests(value, pathKey) {
|
|
23611
|
-
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"));
|
|
23612
|
-
}
|
|
23613
|
-
function validDirectories(value) {
|
|
23614
|
-
return Array.isArray(value) && value.every((entry) => typeof entry === "string" && validRelativePath(entry, false));
|
|
23615
|
-
}
|
|
23616
|
-
async function matchesInstalledState(input, state) {
|
|
23617
|
-
const tree = await digestPackTree(input.packDir).catch(() => void 0);
|
|
23618
|
-
if (!tree || !sameTree(tree, state)) return false;
|
|
23619
|
-
if (!await projectionsMatch(input.agentsDir, state.agents)) return false;
|
|
23620
|
-
return projectionsMatch(input.commandsDir, state.commands);
|
|
23621
|
-
}
|
|
23622
|
-
function validRelativePath(value, filenameOnly) {
|
|
23623
|
-
if (!value || path3.isAbsolute(value) || value.includes("\\")) return false;
|
|
23624
|
-
const parts = value.split("/");
|
|
23625
|
-
if (parts.some((part) => !part || part === "." || part === "..")) return false;
|
|
23626
|
-
return !filenameOnly || parts.length === 1;
|
|
23627
|
-
}
|
|
23628
|
-
function sameTree(left, right) {
|
|
23629
|
-
return sameDigests(left.files, right.files) && left.directories.length === right.directories.length && left.directories.every((entry, index) => entry === right.directories[index]);
|
|
23630
|
-
}
|
|
23631
|
-
function sameDigests(left, right) {
|
|
23632
|
-
return left.length === right.length && left.every((entry, index) => entry.path === right[index]?.path && entry.sha256 === right[index]?.sha256);
|
|
23633
|
-
}
|
|
23634
|
-
function digest(bytes) {
|
|
23635
|
-
return createHash("sha256").update(bytes).digest("hex");
|
|
23636
|
-
}
|
|
23637
|
-
async function writeJsonAtomic(filePath, value) {
|
|
23638
|
-
await mkdir(path3.dirname(filePath), { recursive: true });
|
|
23639
|
-
const tempPath = path3.join(path3.dirname(filePath), `.${path3.basename(filePath)}.${process.pid}.tmp`);
|
|
23640
|
-
await writeFile2(tempPath, `${JSON.stringify(value, null, 2)}
|
|
23641
|
-
`);
|
|
23642
|
-
await rename2(tempPath, filePath);
|
|
23643
|
-
}
|
|
23644
|
-
|
|
23645
23852
|
// packages/cli/src/sync.ts
|
|
23646
23853
|
var WORK_PACK_COMMITTED_MARKER = ".forge-replacement-committed";
|
|
23647
23854
|
var WORK_PACK_TRANSACTION_SUFFIX = ".transaction";
|
|
@@ -23690,9 +23897,9 @@ async function applyWorkPackManifest(paths, credentials, manifest, options) {
|
|
|
23690
23897
|
const recovery = await recoverInterruptedWorkPackInstalls(paths, options.cleanupWorkPackBackup, options.workPackProjectionBoundary);
|
|
23691
23898
|
const managed = await Promise.all((await managedWorkPackSlugs(paths.skillsDir)).map(async (slug) => ({
|
|
23692
23899
|
slug,
|
|
23693
|
-
version: (await readFile3(
|
|
23694
|
-
agents: await readAgentRecord(
|
|
23695
|
-
commands: await readCommandRecord(
|
|
23900
|
+
version: (await readFile3(path5.join(paths.skillsDir, slug, ".forge-version"), "utf8")).trim(),
|
|
23901
|
+
agents: await readAgentRecord(path5.join(paths.skillsDir, slug)),
|
|
23902
|
+
commands: await readCommandRecord(path5.join(paths.skillsDir, slug))
|
|
23696
23903
|
})));
|
|
23697
23904
|
const desired = manifest.skills.map((skill) => ({
|
|
23698
23905
|
slug: skill.slug,
|
|
@@ -23705,7 +23912,7 @@ async function applyWorkPackManifest(paths, credentials, manifest, options) {
|
|
|
23705
23912
|
desired,
|
|
23706
23913
|
managed,
|
|
23707
23914
|
desiredIsComplete: manifest.workPacksComplete === true,
|
|
23708
|
-
operate: (operation) => operateWorkPack(
|
|
23915
|
+
operate: async (operation) => enrichIntegrityFailure(paths, operation, await operateWorkPack(
|
|
23709
23916
|
paths,
|
|
23710
23917
|
credentials,
|
|
23711
23918
|
skillBySlug,
|
|
@@ -23714,9 +23921,9 @@ async function applyWorkPackManifest(paths, credentials, manifest, options) {
|
|
|
23714
23921
|
recovery.failures,
|
|
23715
23922
|
operation,
|
|
23716
23923
|
options
|
|
23717
|
-
),
|
|
23924
|
+
)),
|
|
23718
23925
|
recoveryFailures: recovery.failures,
|
|
23719
|
-
writeAtomicReceipt: (receipt) => writeJsonAtomic2(
|
|
23926
|
+
writeAtomicReceipt: (receipt) => writeJsonAtomic2(path5.join(paths.forgeDir, "work-pack-sync-receipt.json"), receipt)
|
|
23720
23927
|
});
|
|
23721
23928
|
const installed = workPacks.outcomes.filter((outcome) => outcome.status === "installed").map((outcome) => `${outcome.slug}@${outcome.version}`);
|
|
23722
23929
|
const removed = workPacks.outcomes.filter((outcome) => outcome.status === "removed").map((outcome) => outcome.slug);
|
|
@@ -23727,7 +23934,7 @@ async function applyWorkPackManifest(paths, credentials, manifest, options) {
|
|
|
23727
23934
|
async function collectWorkPackObservations(paths, reconciliation) {
|
|
23728
23935
|
const installedVersions = /* @__PURE__ */ new Map();
|
|
23729
23936
|
for (const slug of await managedWorkPackSlugs(paths.skillsDir)) {
|
|
23730
|
-
const version2 = (await readFile3(
|
|
23937
|
+
const version2 = (await readFile3(path5.join(paths.skillsDir, slug, ".forge-version"), "utf8")).trim();
|
|
23731
23938
|
if (version2) installedVersions.set(slug, version2);
|
|
23732
23939
|
}
|
|
23733
23940
|
const observations = new Map(
|
|
@@ -23740,13 +23947,25 @@ async function collectWorkPackObservations(paths, reconciliation) {
|
|
|
23740
23947
|
state: "failed",
|
|
23741
23948
|
...outcome.version ? { version: outcome.version } : {},
|
|
23742
23949
|
...installedVersions.get(outcome.slug) ? { installedVersion: installedVersions.get(outcome.slug) } : {},
|
|
23743
|
-
errorCode: outcome.code ?? outcome.status
|
|
23950
|
+
errorCode: outcome.code ?? outcome.status,
|
|
23951
|
+
...outcome.integrity ? { integrity: outcome.integrity } : {}
|
|
23744
23952
|
});
|
|
23745
23953
|
}
|
|
23746
23954
|
return [...observations.values()].sort((a, b2) => a.slug.localeCompare(b2.slug));
|
|
23747
23955
|
}
|
|
23956
|
+
async function enrichIntegrityFailure(paths, operation, result) {
|
|
23957
|
+
if (result.status !== "failed" || !["local-edits-preserved", "local-baseline-missing"].includes(result.code)) return result;
|
|
23958
|
+
try {
|
|
23959
|
+
const { summary } = await inspectWorkPackIntegrity({ paths, slug: operation.pack.slug });
|
|
23960
|
+
if (summary.kind === "match") return result;
|
|
23961
|
+
const code = summary.kind === "runtime-artifacts" ? "local-runtime-artifacts" : summary.kind === "unknown-additions" ? "local-additions-preserved" : summary.kind === "unsafe-or-unreadable" ? "local-state-unreadable" : result.code;
|
|
23962
|
+
return { ...result, code, integrity: summary };
|
|
23963
|
+
} catch {
|
|
23964
|
+
return result;
|
|
23965
|
+
}
|
|
23966
|
+
}
|
|
23748
23967
|
async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds, cleanupPendingSlugs, recoveryFailures, operation, options) {
|
|
23749
|
-
const target =
|
|
23968
|
+
const target = path5.join(paths.skillsDir, operation.pack.slug);
|
|
23750
23969
|
const recoveryFailure = recoveryFailures.get(operation.pack.slug);
|
|
23751
23970
|
if (recoveryFailure) return { status: "failed", restoration: "exact", code: recoveryFailure };
|
|
23752
23971
|
let ownership;
|
|
@@ -23785,7 +24004,7 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
23785
24004
|
let previousManagedPaths;
|
|
23786
24005
|
let archive;
|
|
23787
24006
|
try {
|
|
23788
|
-
const currentVersion = await readFile3(
|
|
24007
|
+
const currentVersion = await readFile3(path5.join(target, ".forge-version"), "utf8").catch(() => "");
|
|
23789
24008
|
const sameVersion = currentVersion.trim() === skill.version;
|
|
23790
24009
|
if (sameVersion) {
|
|
23791
24010
|
let localState = await checkWorkPackInstalledState({
|
|
@@ -23795,7 +24014,7 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
23795
24014
|
});
|
|
23796
24015
|
if (localState === "missing") {
|
|
23797
24016
|
const candidateArchive = await downloadSkill(credentials, skill.url);
|
|
23798
|
-
const candidateSha256 =
|
|
24017
|
+
const candidateSha256 = createHash3("sha256").update(candidateArchive).digest("hex");
|
|
23799
24018
|
if (candidateSha256 !== skill.sha256) {
|
|
23800
24019
|
return { status: "failed", restoration: "exact", code: "local-baseline-missing" };
|
|
23801
24020
|
}
|
|
@@ -23844,7 +24063,7 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
23844
24063
|
}
|
|
23845
24064
|
previousManagedPaths = await managedWorkPackPaths(paths, target);
|
|
23846
24065
|
archive = await downloadSkill(credentials, skill.url);
|
|
23847
|
-
const sha256 =
|
|
24066
|
+
const sha256 = createHash3("sha256").update(archive).digest("hex");
|
|
23848
24067
|
if (sha256 !== skill.sha256) return { status: "failed", restoration: "exact", code: "checksum-mismatch" };
|
|
23849
24068
|
} catch (error45) {
|
|
23850
24069
|
return exactPackFailure(error45);
|
|
@@ -23958,7 +24177,7 @@ var WorkPackLocalEditsError = class extends Error {
|
|
|
23958
24177
|
async function assertWorkPackUnchangedAtBoundary(paths, target) {
|
|
23959
24178
|
const ownership = await workPackOwnership(target);
|
|
23960
24179
|
if (ownership === "absent") return;
|
|
23961
|
-
if (ownership === "foreign") throw foreignWorkPackError(
|
|
24180
|
+
if (ownership === "foreign") throw foreignWorkPackError(path5.basename(target));
|
|
23962
24181
|
const localState = await checkWorkPackInstalledState({
|
|
23963
24182
|
packDir: target,
|
|
23964
24183
|
agentsDir: paths.agentsDir,
|
|
@@ -23982,12 +24201,12 @@ function skillSlugFromUrl(value) {
|
|
|
23982
24201
|
}
|
|
23983
24202
|
}
|
|
23984
24203
|
async function installSkillArchive(paths, slug, version2, archive, options = {}) {
|
|
23985
|
-
const tempRoot = await mkdtemp(
|
|
23986
|
-
const archivePath =
|
|
23987
|
-
const extractPath =
|
|
23988
|
-
const nextPath =
|
|
23989
|
-
const target =
|
|
23990
|
-
const backup =
|
|
24204
|
+
const tempRoot = await mkdtemp(path5.join(os4.tmpdir(), `forge-${slug}-`));
|
|
24205
|
+
const archivePath = path5.join(tempRoot, `${slug}.tar`);
|
|
24206
|
+
const extractPath = path5.join(tempRoot, "extract");
|
|
24207
|
+
const nextPath = path5.join(tempRoot, slug);
|
|
24208
|
+
const target = path5.join(paths.skillsDir, slug);
|
|
24209
|
+
const backup = path5.join(paths.skillsDir, `${slug}.previous`);
|
|
23991
24210
|
let agentFiles;
|
|
23992
24211
|
let commandFiles;
|
|
23993
24212
|
let previousAgents;
|
|
@@ -23996,7 +24215,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
23996
24215
|
await mkdir2(extractPath, { recursive: true });
|
|
23997
24216
|
await writeFile3(archivePath, archive);
|
|
23998
24217
|
await So({ file: archivePath, cwd: extractPath, strict: true });
|
|
23999
|
-
const extractedSkillPath =
|
|
24218
|
+
const extractedSkillPath = path5.join(extractPath, slug);
|
|
24000
24219
|
await assertNoReservedMarkerAliases(extractedSkillPath);
|
|
24001
24220
|
await validateSkillFolder(extractedSkillPath, slug);
|
|
24002
24221
|
agentFiles = await normalizePackAgentModels(
|
|
@@ -24023,15 +24242,15 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24023
24242
|
}
|
|
24024
24243
|
throw error45;
|
|
24025
24244
|
}
|
|
24026
|
-
await rename3(
|
|
24027
|
-
await writeFile3(
|
|
24245
|
+
await rename3(path5.join(extractPath, slug), nextPath);
|
|
24246
|
+
await writeFile3(path5.join(nextPath, ".forge-version"), `${version2}
|
|
24028
24247
|
`);
|
|
24029
24248
|
if (agentFiles.length > 0) {
|
|
24030
|
-
await writeFile3(
|
|
24249
|
+
await writeFile3(path5.join(nextPath, ".forge-agents"), `${agentFiles.map((agent) => agent.filename).join("\n")}
|
|
24031
24250
|
`);
|
|
24032
24251
|
}
|
|
24033
24252
|
if (commandFiles.length > 0) {
|
|
24034
|
-
await writeFile3(
|
|
24253
|
+
await writeFile3(path5.join(nextPath, ".forge-commands"), `${commandFiles.map((command) => command.filename).join("\n")}
|
|
24035
24254
|
`);
|
|
24036
24255
|
}
|
|
24037
24256
|
await writeWorkPackInstalledState({ packDir: nextPath, version: version2, agents: agentFiles, commands: commandFiles });
|
|
@@ -24042,13 +24261,13 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24042
24261
|
const agentTransactionState = new Map(
|
|
24043
24262
|
[...agentSnapshot.keys()].map((filePath) => [
|
|
24044
24263
|
filePath,
|
|
24045
|
-
agentFiles.find((agent) => agent.filename ===
|
|
24264
|
+
agentFiles.find((agent) => agent.filename === path5.basename(filePath))?.content
|
|
24046
24265
|
])
|
|
24047
24266
|
);
|
|
24048
24267
|
const commandTransactionState = new Map(
|
|
24049
24268
|
[...commandSnapshot.keys()].map((filePath) => [
|
|
24050
24269
|
filePath,
|
|
24051
|
-
commandFiles.find((command) => command.filename ===
|
|
24270
|
+
commandFiles.find((command) => command.filename === path5.basename(filePath))?.content
|
|
24052
24271
|
])
|
|
24053
24272
|
);
|
|
24054
24273
|
const previousManagedPaths = await managedWorkPackPaths(paths, target);
|
|
@@ -24060,7 +24279,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24060
24279
|
throw error45;
|
|
24061
24280
|
}
|
|
24062
24281
|
const writeProjection = options.writeWorkPackProjection ?? writeTextAtomic;
|
|
24063
|
-
const claimedBackup =
|
|
24282
|
+
const claimedBackup = path5.join(tempRoot, `${slug}-claimed-previous`);
|
|
24064
24283
|
const transactionPath = `${backup}${WORK_PACK_TRANSACTION_SUFFIX}`;
|
|
24065
24284
|
let targetBackedUp = false;
|
|
24066
24285
|
let targetInstalled = false;
|
|
@@ -24083,7 +24302,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24083
24302
|
await rename3(nextPath, target);
|
|
24084
24303
|
targetInstalled = true;
|
|
24085
24304
|
for (const filename of previousAgents.filter((name) => !nextAgentNames.has(name))) {
|
|
24086
|
-
const filePath =
|
|
24305
|
+
const filePath = path5.join(paths.agentsDir, filename);
|
|
24087
24306
|
await options.workPackProjectionBoundary?.("install", filePath);
|
|
24088
24307
|
await assertProjectionState(filePath, agentSnapshot.get(filePath));
|
|
24089
24308
|
await rm(filePath, { force: true });
|
|
@@ -24091,14 +24310,14 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24091
24310
|
if (agentFiles.length > 0) {
|
|
24092
24311
|
await mkdir2(paths.agentsDir, { recursive: true });
|
|
24093
24312
|
for (const agent of agentFiles) {
|
|
24094
|
-
const filePath =
|
|
24313
|
+
const filePath = path5.join(paths.agentsDir, agent.filename);
|
|
24095
24314
|
await options.workPackProjectionBoundary?.("install", filePath);
|
|
24096
24315
|
await assertProjectionState(filePath, agentSnapshot.get(filePath));
|
|
24097
24316
|
await writeProjection(filePath, agent.content);
|
|
24098
24317
|
}
|
|
24099
24318
|
}
|
|
24100
24319
|
for (const filename of previousCommands.filter((name) => !nextCommandNames.has(name))) {
|
|
24101
|
-
const filePath =
|
|
24320
|
+
const filePath = path5.join(paths.commandsDir, filename);
|
|
24102
24321
|
await options.workPackProjectionBoundary?.("install", filePath);
|
|
24103
24322
|
await assertProjectionState(filePath, commandSnapshot.get(filePath));
|
|
24104
24323
|
await rm(filePath, { force: true });
|
|
@@ -24106,7 +24325,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24106
24325
|
if (commandFiles.length > 0) {
|
|
24107
24326
|
await mkdir2(paths.commandsDir, { recursive: true });
|
|
24108
24327
|
for (const command of commandFiles) {
|
|
24109
|
-
const filePath =
|
|
24328
|
+
const filePath = path5.join(paths.commandsDir, command.filename);
|
|
24110
24329
|
await options.workPackProjectionBoundary?.("install", filePath);
|
|
24111
24330
|
await assertProjectionState(filePath, commandSnapshot.get(filePath));
|
|
24112
24331
|
await writeProjection(filePath, command.content);
|
|
@@ -24118,7 +24337,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24118
24337
|
await rename3(backup, claimedBackup);
|
|
24119
24338
|
backupClaimed = true;
|
|
24120
24339
|
await assertWorkPackTreeUnchangedAtBoundary(claimedBackup);
|
|
24121
|
-
await writeFile3(
|
|
24340
|
+
await writeFile3(path5.join(claimedBackup, WORK_PACK_COMMITTED_MARKER), `${version2}
|
|
24122
24341
|
`);
|
|
24123
24342
|
await writeTextAtomic(transactionPath, "committed\n");
|
|
24124
24343
|
}
|
|
@@ -24129,7 +24348,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24129
24348
|
await restoreProjectionState(commandSnapshot, commandTransactionState);
|
|
24130
24349
|
}
|
|
24131
24350
|
if (targetBackedUp) {
|
|
24132
|
-
const restoredTarget =
|
|
24351
|
+
const restoredTarget = path5.join(tempRoot, `${slug}-restore`);
|
|
24133
24352
|
const rollbackSource = backupClaimed ? claimedBackup : backup;
|
|
24134
24353
|
await cp(rollbackSource, restoredTarget, { recursive: true });
|
|
24135
24354
|
if (targetInstalled) await rm(target, { recursive: true, force: true });
|
|
@@ -24166,19 +24385,19 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24166
24385
|
return { cleanup };
|
|
24167
24386
|
}
|
|
24168
24387
|
async function adoptLegacyWorkPackState(paths, slug, version2, archive, approvedModelIds) {
|
|
24169
|
-
const comparisonRoot = await mkdtemp(
|
|
24388
|
+
const comparisonRoot = await mkdtemp(path5.join(os4.tmpdir(), `forge-${slug}-baseline-`));
|
|
24170
24389
|
const comparisonPaths = {
|
|
24171
24390
|
...paths,
|
|
24172
|
-
skillsDir:
|
|
24173
|
-
agentsDir:
|
|
24174
|
-
commandsDir:
|
|
24391
|
+
skillsDir: path5.join(comparisonRoot, "skills"),
|
|
24392
|
+
agentsDir: path5.join(comparisonRoot, "agents"),
|
|
24393
|
+
commandsDir: path5.join(comparisonRoot, "commands")
|
|
24175
24394
|
};
|
|
24176
24395
|
try {
|
|
24177
24396
|
await mkdir2(comparisonPaths.skillsDir, { recursive: true });
|
|
24178
24397
|
await installSkillArchive(comparisonPaths, slug, version2, archive, { approvedModelIds });
|
|
24179
24398
|
return adoptWorkPackInstalledState({
|
|
24180
|
-
expectedPackDir:
|
|
24181
|
-
packDir:
|
|
24399
|
+
expectedPackDir: path5.join(comparisonPaths.skillsDir, slug),
|
|
24400
|
+
packDir: path5.join(paths.skillsDir, slug),
|
|
24182
24401
|
agentsDir: paths.agentsDir,
|
|
24183
24402
|
commandsDir: paths.commandsDir
|
|
24184
24403
|
});
|
|
@@ -24189,7 +24408,7 @@ async function adoptLegacyWorkPackState(paths, slug, version2, archive, approved
|
|
|
24189
24408
|
async function recoverInterruptedWorkPackInstalls(paths, cleanupWorkPackBackup, workPackProjectionBoundary) {
|
|
24190
24409
|
const cleanupPending = /* @__PURE__ */ new Set();
|
|
24191
24410
|
const failures = /* @__PURE__ */ new Map();
|
|
24192
|
-
const entries = await
|
|
24411
|
+
const entries = await readdir3(paths.skillsDir, { withFileTypes: true }).catch((error45) => {
|
|
24193
24412
|
if (error45.code === "ENOENT") return [];
|
|
24194
24413
|
throw error45;
|
|
24195
24414
|
});
|
|
@@ -24197,7 +24416,7 @@ async function recoverInterruptedWorkPackInstalls(paths, cleanupWorkPackBackup,
|
|
|
24197
24416
|
if (!entry.name.endsWith(".previous")) continue;
|
|
24198
24417
|
const slug = entry.name.slice(0, -".previous".length);
|
|
24199
24418
|
if (!slug) continue;
|
|
24200
|
-
const target =
|
|
24419
|
+
const target = path5.join(paths.skillsDir, slug);
|
|
24201
24420
|
const backup = `${target}.previous`;
|
|
24202
24421
|
const transactionState = await readWorkPackTransactionState(backup);
|
|
24203
24422
|
if (transactionState === "committed") {
|
|
@@ -24230,9 +24449,9 @@ async function recoverInterruptedWorkPackInstall(paths, target, cleanupWorkPackB
|
|
|
24230
24449
|
const backup = `${target}.previous`;
|
|
24231
24450
|
const backupOwnership = await workPackOwnership(backup);
|
|
24232
24451
|
if (backupOwnership === "absent") return "recovered";
|
|
24233
|
-
if (backupOwnership === "foreign") throw foreignWorkPackError(
|
|
24234
|
-
if (await workPackOwnership(target) === "foreign") throw foreignWorkPackError(
|
|
24235
|
-
const committed = await readFile3(
|
|
24452
|
+
if (backupOwnership === "foreign") throw foreignWorkPackError(path5.basename(target));
|
|
24453
|
+
if (await workPackOwnership(target) === "foreign") throw foreignWorkPackError(path5.basename(target));
|
|
24454
|
+
const committed = await readFile3(path5.join(backup, WORK_PACK_COMMITTED_MARKER), "utf8").catch((error45) => {
|
|
24236
24455
|
if (error45.code === "ENOENT") return void 0;
|
|
24237
24456
|
throw error45;
|
|
24238
24457
|
});
|
|
@@ -24274,32 +24493,32 @@ async function recoverInterruptedWorkPackInstall(paths, target, cleanupWorkPackB
|
|
|
24274
24493
|
);
|
|
24275
24494
|
const previousAgentNames = new Set(previousAgents.map((agent) => agent.filename));
|
|
24276
24495
|
const previousCommandNames = new Set(previousCommands.map((command) => command.filename));
|
|
24277
|
-
const recoveryRoot = await mkdtemp(
|
|
24278
|
-
const recoveredTarget =
|
|
24496
|
+
const recoveryRoot = await mkdtemp(path5.join(os4.tmpdir(), "forge-recover-"));
|
|
24497
|
+
const recoveredTarget = path5.join(recoveryRoot, path5.basename(target));
|
|
24279
24498
|
await cp(backup, recoveredTarget, { recursive: true });
|
|
24280
24499
|
try {
|
|
24281
24500
|
for (const filename of currentAgents.filter((name) => !previousAgentNames.has(name))) {
|
|
24282
|
-
const filePath =
|
|
24501
|
+
const filePath = path5.join(paths.agentsDir, filename);
|
|
24283
24502
|
await workPackProjectionBoundary?.("recover", filePath);
|
|
24284
24503
|
await assertProjectionState(filePath, agentRecoveryState.get(filePath));
|
|
24285
24504
|
await rm(filePath, { force: true });
|
|
24286
24505
|
}
|
|
24287
24506
|
await mkdir2(paths.agentsDir, { recursive: true });
|
|
24288
24507
|
for (const agent of previousAgents) {
|
|
24289
|
-
const filePath =
|
|
24508
|
+
const filePath = path5.join(paths.agentsDir, agent.filename);
|
|
24290
24509
|
await workPackProjectionBoundary?.("recover", filePath);
|
|
24291
24510
|
await assertProjectionState(filePath, agentRecoveryState.get(filePath));
|
|
24292
24511
|
await writeTextAtomic(filePath, agent.content);
|
|
24293
24512
|
}
|
|
24294
24513
|
for (const filename of currentCommands.filter((name) => !previousCommandNames.has(name))) {
|
|
24295
|
-
const filePath =
|
|
24514
|
+
const filePath = path5.join(paths.commandsDir, filename);
|
|
24296
24515
|
await workPackProjectionBoundary?.("recover", filePath);
|
|
24297
24516
|
await assertProjectionState(filePath, commandRecoveryState.get(filePath));
|
|
24298
24517
|
await rm(filePath, { force: true });
|
|
24299
24518
|
}
|
|
24300
24519
|
await mkdir2(paths.commandsDir, { recursive: true });
|
|
24301
24520
|
for (const command of previousCommands) {
|
|
24302
|
-
const filePath =
|
|
24521
|
+
const filePath = path5.join(paths.commandsDir, command.filename);
|
|
24303
24522
|
await workPackProjectionBoundary?.("recover", filePath);
|
|
24304
24523
|
await assertProjectionState(filePath, commandRecoveryState.get(filePath));
|
|
24305
24524
|
await writeTextAtomic(filePath, command.content);
|
|
@@ -24356,19 +24575,19 @@ async function readWorkPackRemovedProjections(backup) {
|
|
|
24356
24575
|
return { agents, commands };
|
|
24357
24576
|
}
|
|
24358
24577
|
async function pathExists(filePath) {
|
|
24359
|
-
return
|
|
24578
|
+
return lstat4(filePath).then(() => true, (error45) => {
|
|
24360
24579
|
if (error45.code === "ENOENT") return false;
|
|
24361
24580
|
throw error45;
|
|
24362
24581
|
});
|
|
24363
24582
|
}
|
|
24364
24583
|
async function workPackOwnership(target) {
|
|
24365
|
-
const targetStat = await
|
|
24584
|
+
const targetStat = await lstat4(target).catch((error45) => {
|
|
24366
24585
|
if (error45.code === "ENOENT") return void 0;
|
|
24367
24586
|
throw error45;
|
|
24368
24587
|
});
|
|
24369
24588
|
if (!targetStat) return "absent";
|
|
24370
24589
|
if (!targetStat.isDirectory()) return "foreign";
|
|
24371
|
-
const marker = await readFile3(
|
|
24590
|
+
const marker = await readFile3(path5.join(target, ".forge-version"), "utf8").catch((error45) => {
|
|
24372
24591
|
if (error45.code === "ENOENT") return void 0;
|
|
24373
24592
|
throw error45;
|
|
24374
24593
|
});
|
|
@@ -24394,11 +24613,11 @@ async function assertProjectionRecoveryIsSafe(directory, currentFiles, previousF
|
|
|
24394
24613
|
expected.set(file2.filename, contents);
|
|
24395
24614
|
}
|
|
24396
24615
|
for (const [filename, contents] of expected) {
|
|
24397
|
-
const projected = await readFile3(
|
|
24616
|
+
const projected = await readFile3(path5.join(directory, filename), "utf8").catch((error45) => {
|
|
24398
24617
|
if (error45.code === "ENOENT") return void 0;
|
|
24399
24618
|
throw error45;
|
|
24400
24619
|
});
|
|
24401
|
-
validated.set(
|
|
24620
|
+
validated.set(path5.join(directory, filename), projected);
|
|
24402
24621
|
const missingPreviousProjection = missingPreviousProjectionIsLocalDeletion(
|
|
24403
24622
|
filename,
|
|
24404
24623
|
projected,
|
|
@@ -24421,13 +24640,13 @@ async function assertProjectionState(filePath, expected) {
|
|
|
24421
24640
|
throw error45;
|
|
24422
24641
|
});
|
|
24423
24642
|
if (current !== expected) {
|
|
24424
|
-
throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${
|
|
24643
|
+
throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${path5.basename(filePath)} foi alterada durante a opera\xE7\xE3o`);
|
|
24425
24644
|
}
|
|
24426
24645
|
}
|
|
24427
24646
|
async function captureProjectionState(directory, filenames) {
|
|
24428
24647
|
const snapshot = /* @__PURE__ */ new Map();
|
|
24429
24648
|
for (const filename of filenames) {
|
|
24430
|
-
const filePath =
|
|
24649
|
+
const filePath = path5.join(directory, filename);
|
|
24431
24650
|
const content = await readFile3(filePath, "utf8").catch((error45) => {
|
|
24432
24651
|
if (error45.code === "ENOENT") return void 0;
|
|
24433
24652
|
throw error45;
|
|
@@ -24450,8 +24669,8 @@ async function restoreProjectionState(snapshot, transactionState) {
|
|
|
24450
24669
|
}
|
|
24451
24670
|
}
|
|
24452
24671
|
async function readPackAgentFiles(skillFolder) {
|
|
24453
|
-
const agentsFolder =
|
|
24454
|
-
const entries = await
|
|
24672
|
+
const agentsFolder = path5.join(skillFolder, "agents");
|
|
24673
|
+
const entries = await readdir3(agentsFolder, { withFileTypes: true }).catch((error45) => {
|
|
24455
24674
|
if (error45.code === "ENOENT") return [];
|
|
24456
24675
|
throw error45;
|
|
24457
24676
|
});
|
|
@@ -24459,7 +24678,7 @@ async function readPackAgentFiles(skillFolder) {
|
|
|
24459
24678
|
for (const entry of entries) {
|
|
24460
24679
|
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
24461
24680
|
if (entry.name.startsWith("._")) continue;
|
|
24462
|
-
const content = await readFile3(
|
|
24681
|
+
const content = await readFile3(path5.join(agentsFolder, entry.name), "utf8");
|
|
24463
24682
|
validateAgentFile(entry.name, content);
|
|
24464
24683
|
files.push({ filename: entry.name, content });
|
|
24465
24684
|
}
|
|
@@ -24470,7 +24689,7 @@ async function normalizePackAgentModels(skillFolder, agentFiles, approvedModelId
|
|
|
24470
24689
|
for (const agent of agentFiles) {
|
|
24471
24690
|
const content = normalizePackAgentModel(agent.filename, agent.content, approvedModelIds, slug);
|
|
24472
24691
|
if (content !== agent.content) {
|
|
24473
|
-
await writeFile3(
|
|
24692
|
+
await writeFile3(path5.join(skillFolder, "agents", agent.filename), content);
|
|
24474
24693
|
}
|
|
24475
24694
|
normalized.push({ ...agent, content });
|
|
24476
24695
|
}
|
|
@@ -24490,8 +24709,8 @@ function normalizePackAgentModel(filename, content, approvedModelIds, slug) {
|
|
|
24490
24709
|
return normalizePackExtensionModel(`agents/${filename}`, content, approvedModelIds, slug);
|
|
24491
24710
|
}
|
|
24492
24711
|
async function readPackCommandFiles(skillFolder) {
|
|
24493
|
-
const commandsFolder =
|
|
24494
|
-
const entries = await
|
|
24712
|
+
const commandsFolder = path5.join(skillFolder, "commands");
|
|
24713
|
+
const entries = await readdir3(commandsFolder, { withFileTypes: true }).catch((error45) => {
|
|
24495
24714
|
if (error45.code === "ENOENT") return [];
|
|
24496
24715
|
throw error45;
|
|
24497
24716
|
});
|
|
@@ -24499,7 +24718,7 @@ async function readPackCommandFiles(skillFolder) {
|
|
|
24499
24718
|
for (const entry of entries) {
|
|
24500
24719
|
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
24501
24720
|
if (entry.name.startsWith("._")) continue;
|
|
24502
|
-
const content = await readFile3(
|
|
24721
|
+
const content = await readFile3(path5.join(commandsFolder, entry.name), "utf8");
|
|
24503
24722
|
validateCommandFile(entry.name, content);
|
|
24504
24723
|
files.push({ filename: entry.name, content });
|
|
24505
24724
|
}
|
|
@@ -24510,7 +24729,7 @@ async function normalizePackCommandModels(skillFolder, commandFiles, approvedMod
|
|
|
24510
24729
|
for (const command of commandFiles) {
|
|
24511
24730
|
const content = normalizePackExtensionModel(`commands/${command.filename}`, command.content, approvedModelIds, slug);
|
|
24512
24731
|
if (content !== command.content) {
|
|
24513
|
-
await writeFile3(
|
|
24732
|
+
await writeFile3(path5.join(skillFolder, "commands", command.filename), content);
|
|
24514
24733
|
}
|
|
24515
24734
|
normalized.push({ ...command, content });
|
|
24516
24735
|
}
|
|
@@ -24532,7 +24751,7 @@ async function assertNoForeignAgentConflicts(agentsDir, agentFiles, ownedFilenam
|
|
|
24532
24751
|
const owned = new Set(ownedFilenames);
|
|
24533
24752
|
for (const agent of agentFiles) {
|
|
24534
24753
|
if (owned.has(agent.filename)) continue;
|
|
24535
|
-
const existing = await readFile3(
|
|
24754
|
+
const existing = await readFile3(path5.join(agentsDir, agent.filename), "utf8").catch((error45) => {
|
|
24536
24755
|
if (error45.code === "ENOENT") return void 0;
|
|
24537
24756
|
throw error45;
|
|
24538
24757
|
});
|
|
@@ -24545,7 +24764,7 @@ async function assertNoForeignCommandConflicts(commandsDir, commandFiles, ownedF
|
|
|
24545
24764
|
const owned = new Set(ownedFilenames);
|
|
24546
24765
|
for (const command of commandFiles) {
|
|
24547
24766
|
if (owned.has(command.filename)) continue;
|
|
24548
|
-
const existing = await readFile3(
|
|
24767
|
+
const existing = await readFile3(path5.join(commandsDir, command.filename), "utf8").catch((error45) => {
|
|
24549
24768
|
if (error45.code === "ENOENT") return void 0;
|
|
24550
24769
|
throw error45;
|
|
24551
24770
|
});
|
|
@@ -24555,28 +24774,28 @@ async function assertNoForeignCommandConflicts(commandsDir, commandFiles, ownedF
|
|
|
24555
24774
|
}
|
|
24556
24775
|
}
|
|
24557
24776
|
async function readAgentRecord(skillFolder) {
|
|
24558
|
-
const raw = await readFile3(
|
|
24777
|
+
const raw = await readFile3(path5.join(skillFolder, ".forge-agents"), "utf8").catch(() => "");
|
|
24559
24778
|
return raw.split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.includes("/") && !line.includes("\\") && line !== "..");
|
|
24560
24779
|
}
|
|
24561
24780
|
async function readCommandRecord(skillFolder) {
|
|
24562
|
-
const raw = await readFile3(
|
|
24781
|
+
const raw = await readFile3(path5.join(skillFolder, ".forge-commands"), "utf8").catch(() => "");
|
|
24563
24782
|
return raw.split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.includes("/") && !line.includes("\\") && line !== "..");
|
|
24564
24783
|
}
|
|
24565
24784
|
async function managedWorkPackPaths(paths, skillFolder) {
|
|
24566
24785
|
const files = await listFilesRecursively(skillFolder);
|
|
24567
|
-
const agents = (await readAgentRecord(skillFolder)).map((filename) =>
|
|
24568
|
-
const commands = (await readCommandRecord(skillFolder)).map((filename) =>
|
|
24786
|
+
const agents = (await readAgentRecord(skillFolder)).map((filename) => path5.join(paths.agentsDir, filename));
|
|
24787
|
+
const commands = (await readCommandRecord(skillFolder)).map((filename) => path5.join(paths.commandsDir, filename));
|
|
24569
24788
|
return [.../* @__PURE__ */ new Set([...files, ...agents, ...commands])];
|
|
24570
24789
|
}
|
|
24571
24790
|
async function managedWorkPackSlugs(skillsDir) {
|
|
24572
|
-
const entries = await
|
|
24791
|
+
const entries = await readdir3(skillsDir, { withFileTypes: true }).catch((error45) => {
|
|
24573
24792
|
if (error45.code === "ENOENT") return [];
|
|
24574
24793
|
throw error45;
|
|
24575
24794
|
});
|
|
24576
24795
|
const slugs = [];
|
|
24577
24796
|
for (const entry of entries) {
|
|
24578
24797
|
if (!entry.isDirectory() || entry.name.endsWith(".previous")) continue;
|
|
24579
|
-
if (await workPackOwnership(
|
|
24798
|
+
if (await workPackOwnership(path5.join(skillsDir, entry.name)) === "managed") slugs.push(entry.name);
|
|
24580
24799
|
}
|
|
24581
24800
|
return slugs.sort((left, right) => left.localeCompare(right));
|
|
24582
24801
|
}
|
|
@@ -24586,14 +24805,14 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
|
|
|
24586
24805
|
const agents = await readAgentRecord(target);
|
|
24587
24806
|
const commands = await readCommandRecord(target);
|
|
24588
24807
|
const snapshots = await Promise.all([
|
|
24589
|
-
...agents.map((filename) => captureExactFile(
|
|
24590
|
-
...commands.map((filename) => captureExactFile(
|
|
24808
|
+
...agents.map((filename) => captureExactFile(path5.join(paths.agentsDir, filename))),
|
|
24809
|
+
...commands.map((filename) => captureExactFile(path5.join(paths.commandsDir, filename)))
|
|
24591
24810
|
]);
|
|
24592
24811
|
await assertWorkPackUnchangedAtBoundary(paths, target);
|
|
24593
24812
|
const backup = `${target}.previous`;
|
|
24594
24813
|
const transactionPath = `${backup}${WORK_PACK_TRANSACTION_SUFFIX}`;
|
|
24595
|
-
const transactionRoot = await mkdtemp(
|
|
24596
|
-
const claimedBackup =
|
|
24814
|
+
const transactionRoot = await mkdtemp(path5.join(os4.tmpdir(), "forge-remove-"));
|
|
24815
|
+
const claimedBackup = path5.join(transactionRoot, path5.basename(target));
|
|
24597
24816
|
let projectionsRemoved = false;
|
|
24598
24817
|
let backupClaimed = false;
|
|
24599
24818
|
try {
|
|
@@ -24611,7 +24830,7 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
|
|
|
24611
24830
|
await assertWorkPackUnchangedAtBoundary(paths, backup);
|
|
24612
24831
|
projectionsRemoved = agents.length > 0;
|
|
24613
24832
|
for (const filename of agents) {
|
|
24614
|
-
const filePath =
|
|
24833
|
+
const filePath = path5.join(paths.agentsDir, filename);
|
|
24615
24834
|
await options.workPackProjectionBoundary?.("remove", filePath);
|
|
24616
24835
|
await assertExactFileState(snapshots, filePath);
|
|
24617
24836
|
await recordRemovedProjection(transactionPath, "agent", filename);
|
|
@@ -24620,7 +24839,7 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
|
|
|
24620
24839
|
await options.removeWorkPackBoundary?.("after-agents");
|
|
24621
24840
|
projectionsRemoved ||= commands.length > 0;
|
|
24622
24841
|
for (const filename of commands) {
|
|
24623
|
-
const filePath =
|
|
24842
|
+
const filePath = path5.join(paths.commandsDir, filename);
|
|
24624
24843
|
await options.workPackProjectionBoundary?.("remove", filePath);
|
|
24625
24844
|
await assertExactFileState(snapshots, filePath);
|
|
24626
24845
|
await recordRemovedProjection(transactionPath, "command", filename);
|
|
@@ -24646,7 +24865,7 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
|
|
|
24646
24865
|
if (await workPackOwnership(target) !== "managed") throw new Error("restored Work Pack marker missing");
|
|
24647
24866
|
await rm(transactionRoot, { recursive: true, force: true }).catch(() => void 0);
|
|
24648
24867
|
} catch (restoreError) {
|
|
24649
|
-
throw new WorkPackRecoveryUncertainError(`Falha ao remover e restaurar o pacote de trabalho ${
|
|
24868
|
+
throw new WorkPackRecoveryUncertainError(`Falha ao remover e restaurar o pacote de trabalho ${path5.basename(target)}`, {
|
|
24650
24869
|
cause: new AggregateError([error45, restoreError])
|
|
24651
24870
|
});
|
|
24652
24871
|
}
|
|
@@ -24655,7 +24874,7 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
|
|
|
24655
24874
|
}
|
|
24656
24875
|
async function captureExactFile(filePath) {
|
|
24657
24876
|
try {
|
|
24658
|
-
const info = await
|
|
24877
|
+
const info = await lstat4(filePath);
|
|
24659
24878
|
if (!info.isFile()) throw new Error(`A proje\xE7\xE3o gerida n\xE3o \xE9 um ficheiro regular: ${filePath}`);
|
|
24660
24879
|
return { path: filePath, exists: true, bytes: await readFile3(filePath), mode: info.mode & 4095 };
|
|
24661
24880
|
} catch (error45) {
|
|
@@ -24667,17 +24886,17 @@ async function assertExactFileState(snapshots, filePath) {
|
|
|
24667
24886
|
const expected = snapshots.find((snapshot) => snapshot.path === filePath);
|
|
24668
24887
|
const current = await captureExactFile(filePath);
|
|
24669
24888
|
if (!expected || current.exists !== expected.exists) {
|
|
24670
|
-
throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${
|
|
24889
|
+
throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${path5.basename(filePath)} foi alterada durante a opera\xE7\xE3o`);
|
|
24671
24890
|
}
|
|
24672
24891
|
if (current.exists && (!current.bytes?.equals(expected.bytes) || current.mode !== expected.mode)) {
|
|
24673
|
-
throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${
|
|
24892
|
+
throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${path5.basename(filePath)} foi alterada durante a opera\xE7\xE3o`);
|
|
24674
24893
|
}
|
|
24675
24894
|
}
|
|
24676
24895
|
async function restoreRemovedExactFiles(snapshots) {
|
|
24677
24896
|
for (const snapshot of snapshots) {
|
|
24678
24897
|
if ((await captureExactFile(snapshot.path)).exists) continue;
|
|
24679
24898
|
if (!snapshot.exists) continue;
|
|
24680
|
-
await mkdir2(
|
|
24899
|
+
await mkdir2(path5.dirname(snapshot.path), { recursive: true });
|
|
24681
24900
|
await writeFile3(snapshot.path, snapshot.bytes);
|
|
24682
24901
|
await chmod(snapshot.path, snapshot.mode);
|
|
24683
24902
|
}
|
|
@@ -24689,20 +24908,20 @@ async function verifyRestoredOrLocallyChangedFiles(snapshots) {
|
|
|
24689
24908
|
}
|
|
24690
24909
|
}
|
|
24691
24910
|
async function listFilesRecursively(root) {
|
|
24692
|
-
const entries = await
|
|
24911
|
+
const entries = await readdir3(root, { withFileTypes: true }).catch((error45) => {
|
|
24693
24912
|
if (error45.code === "ENOENT") return [];
|
|
24694
24913
|
throw error45;
|
|
24695
24914
|
});
|
|
24696
24915
|
const files = [];
|
|
24697
24916
|
for (const entry of entries) {
|
|
24698
|
-
const absolute =
|
|
24917
|
+
const absolute = path5.join(root, entry.name);
|
|
24699
24918
|
if (entry.isDirectory()) files.push(...await listFilesRecursively(absolute));
|
|
24700
24919
|
else if (entry.isFile()) files.push(absolute);
|
|
24701
24920
|
}
|
|
24702
24921
|
return files;
|
|
24703
24922
|
}
|
|
24704
24923
|
async function validateSkillFolder(folder, slug) {
|
|
24705
|
-
const skillMd = await readFile3(
|
|
24924
|
+
const skillMd = await readFile3(path5.join(folder, "SKILL.md"), "utf8");
|
|
24706
24925
|
const frontmatter = /^---\n([\s\S]+?)\n---/.exec(skillMd)?.[1] ?? "";
|
|
24707
24926
|
if (!frontmatter.includes(`name: ${slug}`) && !frontmatter.includes(`name: "${slug}"`)) {
|
|
24708
24927
|
throw new Error(`O campo name no frontmatter de SKILL.md tem de corresponder a ${slug}`);
|
|
@@ -24713,7 +24932,7 @@ async function validateSkillFolder(folder, slug) {
|
|
|
24713
24932
|
}
|
|
24714
24933
|
async function assertNoReservedMarkerAliases(skillFolder) {
|
|
24715
24934
|
const reserved = /* @__PURE__ */ new Set([".forge-version", ".forge-agents", ".forge-commands", WORK_PACK_LOCAL_STATE_FILENAME]);
|
|
24716
|
-
const entries = await
|
|
24935
|
+
const entries = await readdir3(skillFolder);
|
|
24717
24936
|
const marker = entries.find((entry) => reserved.has(entry.toLowerCase()));
|
|
24718
24937
|
if (marker) throw new Error(`O pacote de trabalho cont\xE9m o marcador Forge reservado ${marker}`);
|
|
24719
24938
|
}
|
|
@@ -24723,15 +24942,15 @@ async function writeJsonAtomic2(filePath, value) {
|
|
|
24723
24942
|
await writeTextAtomic(filePath, content);
|
|
24724
24943
|
}
|
|
24725
24944
|
async function writeTextAtomic(filePath, content) {
|
|
24726
|
-
const dir =
|
|
24945
|
+
const dir = path5.dirname(filePath);
|
|
24727
24946
|
await mkdir2(dir, { recursive: true });
|
|
24728
|
-
const tempPath =
|
|
24947
|
+
const tempPath = path5.join(dir, `.${path5.basename(filePath)}.${process.pid}.tmp`);
|
|
24729
24948
|
await writeFile3(tempPath, content);
|
|
24730
24949
|
await rename3(tempPath, filePath);
|
|
24731
24950
|
}
|
|
24732
24951
|
|
|
24733
24952
|
// packages/cli/src/workerPrompt.ts
|
|
24734
|
-
import { createHash as
|
|
24953
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
24735
24954
|
var STOCK_OPENWORK_PROMPT_SHA256 = "b84527bf738ab37c726ccd43c3161df30fbddd5384aadbe7abf3cfeb3fced497";
|
|
24736
24955
|
var FORGE_WORKER_PROMPT = `\xC9s o assistente de trabalho do Forge no OpenWork. Ajudas a pessoa a concluir
|
|
24737
24956
|
tarefas com os ficheiros, fontes e ferramentas a que tem acesso. N\xE3o pressuponhas
|
|
@@ -24812,7 +25031,7 @@ function applySharedWorkerPrompt(config2) {
|
|
|
24812
25031
|
const agent = config2.agent.openwork;
|
|
24813
25032
|
if (!isRecord(agent) || agent.mode !== "primary" || typeof agent.prompt !== "string") return false;
|
|
24814
25033
|
if (agent.prompt === FORGE_WORKER_PROMPT) return true;
|
|
24815
|
-
const hash2 =
|
|
25034
|
+
const hash2 = createHash4("sha256").update(agent.prompt.replace(/\r\n/g, "\n").trim()).digest("hex");
|
|
24816
25035
|
if (hash2 !== STOCK_OPENWORK_PROMPT_SHA256) return false;
|
|
24817
25036
|
config2.agent = { ...config2.agent, openwork: { ...agent, prompt: FORGE_WORKER_PROMPT } };
|
|
24818
25037
|
return true;
|
|
@@ -24822,7 +25041,7 @@ function isRecord(value) {
|
|
|
24822
25041
|
}
|
|
24823
25042
|
|
|
24824
25043
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
24825
|
-
var PLUGIN_VERSION = "0.1.
|
|
25044
|
+
var PLUGIN_VERSION = "0.1.18";
|
|
24826
25045
|
var STATUS_FILENAME = "work-pack-startup-status.json";
|
|
24827
25046
|
var activeSync = /* @__PURE__ */ new Map();
|
|
24828
25047
|
var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
@@ -24833,7 +25052,7 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
|
24833
25052
|
activeSync.set(forgeBaseUrl, sync);
|
|
24834
25053
|
}
|
|
24835
25054
|
const state = await sync;
|
|
24836
|
-
const legacyPath =
|
|
25055
|
+
const legacyPath = path6.join(state.paths.pluginDir, FORGE_EVIDENCE_PLUGIN_FILENAME);
|
|
24837
25056
|
const ownershipSymbol = /* @__PURE__ */ Symbol.for("minimal-forge.legacy-evidence-owners.v1");
|
|
24838
25057
|
const shared = globalThis;
|
|
24839
25058
|
const legacyOwners = shared[ownershipSymbol] ??= /* @__PURE__ */ new Set();
|
|
@@ -24844,13 +25063,13 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
|
24844
25063
|
const slug = typeof input.args?.name === "string" ? input.args.name.trim().toLowerCase() : "";
|
|
24845
25064
|
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug)) return;
|
|
24846
25065
|
try {
|
|
24847
|
-
await readFile4(
|
|
25066
|
+
await readFile4(path6.join(state.paths.skillsDir, slug, ".forge-version"), "utf8");
|
|
24848
25067
|
} catch {
|
|
24849
25068
|
return;
|
|
24850
25069
|
}
|
|
24851
25070
|
try {
|
|
24852
25071
|
const { forgeApiKey } = await readWellKnownForgeCredentials(state.paths.opencodeAuthPath, forgeBaseUrl);
|
|
24853
|
-
const credentialId =
|
|
25072
|
+
const credentialId = createHash5("sha256").update(forgeApiKey).digest("hex");
|
|
24854
25073
|
const reportUsage = skillUsageReporter(forgeBaseUrl, credentialId, (events) => fetch(`${forgeBaseUrl}/sync/evidence`, {
|
|
24855
25074
|
method: "POST",
|
|
24856
25075
|
redirect: "error",
|
|
@@ -24993,17 +25212,17 @@ function parseForgeBaseUrl(options) {
|
|
|
24993
25212
|
async function managedProjectionNames(paths) {
|
|
24994
25213
|
const agents = /* @__PURE__ */ new Set();
|
|
24995
25214
|
const commands = /* @__PURE__ */ new Set();
|
|
24996
|
-
const entries = await
|
|
25215
|
+
const entries = await readdir4(paths.skillsDir, { withFileTypes: true }).catch((error45) => {
|
|
24997
25216
|
if (error45.code === "ENOENT") return [];
|
|
24998
25217
|
throw error45;
|
|
24999
25218
|
});
|
|
25000
25219
|
for (const entry of entries) {
|
|
25001
25220
|
if (!entry.isDirectory()) continue;
|
|
25002
|
-
const folder =
|
|
25003
|
-
const marker = await readFile4(
|
|
25221
|
+
const folder = path6.join(paths.skillsDir, entry.name);
|
|
25222
|
+
const marker = await readFile4(path6.join(folder, ".forge-version"), "utf8").catch(() => "");
|
|
25004
25223
|
if (!marker.trim()) continue;
|
|
25005
|
-
for (const name of await readProjectionRecord(
|
|
25006
|
-
for (const name of await readProjectionRecord(
|
|
25224
|
+
for (const name of await readProjectionRecord(path6.join(folder, ".forge-agents"))) agents.add(stripMarkdownExtension(name));
|
|
25225
|
+
for (const name of await readProjectionRecord(path6.join(folder, ".forge-commands"))) commands.add(stripMarkdownExtension(name));
|
|
25007
25226
|
}
|
|
25008
25227
|
return { agents, commands };
|
|
25009
25228
|
}
|
|
@@ -25019,10 +25238,10 @@ async function projectCurrentExtensions(config2, state) {
|
|
|
25019
25238
|
for (const name of state.before.agents) if (!state.after.agents.has(name)) delete agents[name];
|
|
25020
25239
|
for (const name of state.before.commands) if (!state.after.commands.has(name)) delete commands[name];
|
|
25021
25240
|
for (const name of state.after.agents) {
|
|
25022
|
-
agents[name] = await parseMarkdownConfig(
|
|
25241
|
+
agents[name] = await parseMarkdownConfig(path6.join(state.paths.agentsDir, `${name}.md`), "prompt");
|
|
25023
25242
|
}
|
|
25024
25243
|
for (const name of state.after.commands) {
|
|
25025
|
-
commands[name] = await parseMarkdownConfig(
|
|
25244
|
+
commands[name] = await parseMarkdownConfig(path6.join(state.paths.commandsDir, `${name}.md`), "template");
|
|
25026
25245
|
}
|
|
25027
25246
|
config2.agent = agents;
|
|
25028
25247
|
config2.command = commands;
|
|
@@ -25030,10 +25249,10 @@ async function projectCurrentExtensions(config2, state) {
|
|
|
25030
25249
|
async function parseMarkdownConfig(filePath, bodyField) {
|
|
25031
25250
|
const raw = await readFile4(filePath, "utf8");
|
|
25032
25251
|
const match = /^---\r?\n([\s\S]+?)\r?\n---\r?\n?([\s\S]*)$/.exec(raw);
|
|
25033
|
-
if (!match) throw new Error(`A extens\xE3o Forge ${
|
|
25252
|
+
if (!match) throw new Error(`A extens\xE3o Forge ${path6.basename(filePath)} n\xE3o tem frontmatter v\xE1lido`);
|
|
25034
25253
|
const data = (0, import_yaml.parse)(match[1]);
|
|
25035
25254
|
if (!data || typeof data !== "object" || Array.isArray(data)) {
|
|
25036
|
-
throw new Error(`A extens\xE3o Forge ${
|
|
25255
|
+
throw new Error(`A extens\xE3o Forge ${path6.basename(filePath)} n\xE3o tem frontmatter v\xE1lido`);
|
|
25037
25256
|
}
|
|
25038
25257
|
const config2 = { ...data, [bodyField]: match[2].trim() };
|
|
25039
25258
|
if (bodyField === "prompt" && typeof config2.permission === "string" && ["allow", "ask", "deny"].includes(config2.permission)) {
|
|
@@ -25049,8 +25268,8 @@ function stripMarkdownExtension(filename) {
|
|
|
25049
25268
|
}
|
|
25050
25269
|
async function writeStatus(paths, value) {
|
|
25051
25270
|
await mkdir3(paths.forgeDir, { recursive: true });
|
|
25052
|
-
const target =
|
|
25053
|
-
const temporary =
|
|
25271
|
+
const target = path6.join(paths.forgeDir, STATUS_FILENAME);
|
|
25272
|
+
const temporary = path6.join(paths.forgeDir, `.${STATUS_FILENAME}.${process.pid}.tmp`);
|
|
25054
25273
|
await writeFile4(temporary, `${JSON.stringify(value, null, 2)}
|
|
25055
25274
|
`, { mode: 384 });
|
|
25056
25275
|
await rename4(temporary, target);
|