minimal-forge-work-pack-sync 0.1.16 → 0.1.17
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 +556 -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.17";
|
|
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) && 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,328 @@ 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
|
+
return result;
|
|
20542
|
+
}
|
|
20543
|
+
const expected = input.expected ? parseWorkPackFileManifest(input.expected) : await readInstalledState(packDir);
|
|
20544
|
+
if (!expected) return result;
|
|
20545
|
+
result.version = expected.version;
|
|
20546
|
+
result.summary.reference = input.expected ? input.reference ?? "server" : "installation-receipt";
|
|
20547
|
+
const readBudget = { remaining: 128 * 1024 * 1024, exceeded: false };
|
|
20548
|
+
const original = new Map(expected.files.map((file2) => [file2.path, file2.sha256]));
|
|
20549
|
+
const directories = new Set(expected.directories);
|
|
20550
|
+
const seenFiles = /* @__PURE__ */ new Set(), seenDirectories = /* @__PURE__ */ new Set(), unchanged = /* @__PURE__ */ new Set();
|
|
20551
|
+
const extraFiles = [], extraDirectories = [], blocked = [];
|
|
20552
|
+
let entries = 0;
|
|
20553
|
+
const walk = async (directory, prefix) => {
|
|
20554
|
+
if (result.summary.truncated) return;
|
|
20555
|
+
let children;
|
|
20556
|
+
try {
|
|
20557
|
+
children = await readdir2(directory, { withFileTypes: true });
|
|
20558
|
+
} catch {
|
|
20559
|
+
add("unreadable", "pack", prefix || ".");
|
|
20560
|
+
blocked.push(prefix);
|
|
20561
|
+
return;
|
|
20562
|
+
}
|
|
20563
|
+
for (const entry of children.sort((a, b2) => a.name < b2.name ? -1 : a.name > b2.name ? 1 : 0)) {
|
|
20564
|
+
if (++entries > MAX_ENTRIES) {
|
|
20565
|
+
result.summary.truncated = true;
|
|
20566
|
+
return;
|
|
20567
|
+
}
|
|
20568
|
+
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
20569
|
+
const absolute = path4.join(directory, entry.name);
|
|
20570
|
+
const info = await lstat3(absolute).catch(() => void 0);
|
|
20571
|
+
if (!info) {
|
|
20572
|
+
add("unreadable", "pack", relative);
|
|
20573
|
+
blocked.push(relative);
|
|
20574
|
+
continue;
|
|
20575
|
+
}
|
|
20576
|
+
if (info.isSymbolicLink() || !info.isDirectory() && !info.isFile() || info.isFile() && info.nlink > 1) {
|
|
20577
|
+
add("unsafe", "pack", relative);
|
|
20578
|
+
blocked.push(relative);
|
|
20579
|
+
continue;
|
|
20580
|
+
}
|
|
20581
|
+
if (!prefix && entry.name === WORK_PACK_LOCAL_STATE_FILENAME) {
|
|
20582
|
+
if (!info.isFile()) add("unsafe", "pack", relative);
|
|
20583
|
+
continue;
|
|
20584
|
+
}
|
|
20585
|
+
if (info.isDirectory()) {
|
|
20586
|
+
seenDirectories.add(relative);
|
|
20587
|
+
if (!directories.has(relative)) extraDirectories.push(relative);
|
|
20588
|
+
if (original.has(relative)) add("unsafe", "pack", relative);
|
|
20589
|
+
if (relative.split("/").length > 64) {
|
|
20590
|
+
add("unsafe", "pack", relative);
|
|
20591
|
+
blocked.push(relative);
|
|
20592
|
+
continue;
|
|
20593
|
+
}
|
|
20594
|
+
await walk(absolute, relative);
|
|
20595
|
+
} else {
|
|
20596
|
+
seenFiles.add(relative);
|
|
20597
|
+
const expectedHash = original.get(relative);
|
|
20598
|
+
if (directories.has(relative)) add("unsafe", "pack", relative);
|
|
20599
|
+
if (expectedHash === void 0) extraFiles.push(relative);
|
|
20600
|
+
else {
|
|
20601
|
+
const digest2 = await regularFileDigest(absolute, readBudget);
|
|
20602
|
+
if (!digest2) add("unreadable", "pack", relative);
|
|
20603
|
+
else if (digest2 !== expectedHash) add("modified", "pack", relative);
|
|
20604
|
+
else unchanged.add(relative);
|
|
20605
|
+
}
|
|
20606
|
+
}
|
|
20607
|
+
}
|
|
20608
|
+
};
|
|
20609
|
+
await walk(packDir, "");
|
|
20610
|
+
const inaccessible = (name) => result.summary.truncated || blocked.some((parent) => !parent || name === parent || name.startsWith(`${parent}/`));
|
|
20611
|
+
for (const name of original.keys()) if (!seenFiles.has(name) && !seenDirectories.has(name) && !inaccessible(name)) add("missing", "pack", name);
|
|
20612
|
+
for (const name of directories) if (!seenDirectories.has(name) && !seenFiles.has(name) && !inaccessible(name)) add("missing", "pack", name);
|
|
20613
|
+
const cacheDirectories = /* @__PURE__ */ new Set();
|
|
20614
|
+
for (const name of extraFiles) {
|
|
20615
|
+
const match = /^(.*\/)?__pycache__\/([^/]+)\.cpython-[0-9]+(?:\.opt-[12])?\.pyc$/.exec(name);
|
|
20616
|
+
const source = match ? `${match[1] ?? ""}${match[2]}.py` : void 0;
|
|
20617
|
+
if (source && unchanged.has(source)) {
|
|
20618
|
+
add("runtimeArtifacts", "pack", name);
|
|
20619
|
+
cacheDirectories.add(path4.posix.dirname(name));
|
|
20620
|
+
} else add("additional", "pack", name);
|
|
20621
|
+
}
|
|
20622
|
+
for (const name of extraDirectories) if (!cacheDirectories.has(name)) add("additional", "pack", name);
|
|
20623
|
+
for (const area of ["agents", "commands"]) {
|
|
20624
|
+
const items = expected[area];
|
|
20625
|
+
if (!items.length) continue;
|
|
20626
|
+
const directory = area === "agents" ? input.paths.agentsDir : input.paths.commandsDir;
|
|
20627
|
+
const directoryInfo = await lstat3(directory).catch(() => void 0);
|
|
20628
|
+
if (directoryInfo && (!directoryInfo.isDirectory() || directoryInfo.isSymbolicLink())) {
|
|
20629
|
+
add("unsafe", area, ".");
|
|
20630
|
+
continue;
|
|
20631
|
+
}
|
|
20632
|
+
for (const item of items) {
|
|
20633
|
+
const absolute = path4.join(directory, item.filename);
|
|
20634
|
+
try {
|
|
20635
|
+
const info = await lstat3(absolute);
|
|
20636
|
+
if (!info.isFile() || info.isSymbolicLink() || info.nlink > 1) add("unsafe", area, item.filename);
|
|
20637
|
+
else {
|
|
20638
|
+
const digest2 = await regularFileDigest(absolute, readBudget);
|
|
20639
|
+
if (!digest2) add("unreadable", area, item.filename);
|
|
20640
|
+
else if (digest2 !== item.sha256) add("modified", area, item.filename);
|
|
20641
|
+
}
|
|
20642
|
+
} catch (error45) {
|
|
20643
|
+
add(error45.code === "ENOENT" ? "missing" : "unreadable", area, item.filename);
|
|
20644
|
+
}
|
|
20645
|
+
}
|
|
20646
|
+
}
|
|
20647
|
+
result.summary.truncated ||= readBudget.exceeded;
|
|
20648
|
+
result.summary.kind = integrityKind(result.summary);
|
|
20649
|
+
return result;
|
|
20650
|
+
}
|
|
20651
|
+
async function regularFileDigest(filePath, budget) {
|
|
20652
|
+
try {
|
|
20653
|
+
const handle = await open(filePath, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
20654
|
+
try {
|
|
20655
|
+
const before = await handle.stat();
|
|
20656
|
+
if (!before.isFile() || before.nlink > 1 || before.size > MAX_FILE_BYTES) return void 0;
|
|
20657
|
+
if (before.size > budget.remaining) {
|
|
20658
|
+
budget.exceeded = true;
|
|
20659
|
+
return void 0;
|
|
20660
|
+
}
|
|
20661
|
+
const hash2 = createHash2("sha256");
|
|
20662
|
+
const buffer = Buffer.alloc(64 * 1024);
|
|
20663
|
+
let total = 0;
|
|
20664
|
+
while (true) {
|
|
20665
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, null);
|
|
20666
|
+
if (!bytesRead) break;
|
|
20667
|
+
total += bytesRead;
|
|
20668
|
+
budget.remaining -= bytesRead;
|
|
20669
|
+
if (budget.remaining < 0) {
|
|
20670
|
+
budget.exceeded = true;
|
|
20671
|
+
return void 0;
|
|
20672
|
+
}
|
|
20673
|
+
if (total > MAX_FILE_BYTES) return void 0;
|
|
20674
|
+
hash2.update(buffer.subarray(0, bytesRead));
|
|
20675
|
+
}
|
|
20676
|
+
const after = await handle.stat();
|
|
20677
|
+
return before.size === after.size && before.mtimeMs === after.mtimeMs && total === before.size ? hash2.digest("hex") : void 0;
|
|
20678
|
+
} finally {
|
|
20679
|
+
await handle.close();
|
|
20680
|
+
}
|
|
20681
|
+
} catch {
|
|
20682
|
+
return void 0;
|
|
20683
|
+
}
|
|
20684
|
+
}
|
|
20685
|
+
function assertSlug(slug) {
|
|
20686
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug) || slug.length > 64) throw new Error("Identificador de skill inv\xE1lido");
|
|
20687
|
+
}
|
|
20688
|
+
|
|
20689
|
+
// packages/cli/src/sync.ts
|
|
20690
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
20691
|
+
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";
|
|
20692
|
+
import os4 from "node:os";
|
|
20693
|
+
import path5 from "node:path";
|
|
20694
|
+
|
|
20346
20695
|
// node_modules/tar/dist/esm/index.min.js
|
|
20347
20696
|
import Qr from "events";
|
|
20348
20697
|
import I from "fs";
|
|
@@ -23407,12 +23756,14 @@ async function reconcileWorkPacks(input) {
|
|
|
23407
23756
|
const receiptValue = {
|
|
23408
23757
|
schemaVersion: 1,
|
|
23409
23758
|
completedAt: (input.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
23410
|
-
outcomes: outcomes.map(({ slug, version: version2, action, reason, status }) => ({
|
|
23759
|
+
outcomes: outcomes.map(({ slug, version: version2, action, reason, status, code, integrity }) => ({
|
|
23411
23760
|
slug,
|
|
23412
23761
|
...version2 === void 0 ? {} : { version: version2 },
|
|
23413
23762
|
action,
|
|
23414
23763
|
reason,
|
|
23415
|
-
status
|
|
23764
|
+
status,
|
|
23765
|
+
...code ? { code } : {},
|
|
23766
|
+
...integrity ? { integrity } : {}
|
|
23416
23767
|
})),
|
|
23417
23768
|
omissionPrune
|
|
23418
23769
|
};
|
|
@@ -23453,6 +23804,7 @@ async function runOperation(operation, operate) {
|
|
|
23453
23804
|
...outcomeIdentity(operation),
|
|
23454
23805
|
status: "failed",
|
|
23455
23806
|
code: stableCode(result.code),
|
|
23807
|
+
...result.integrity ? { integrity: result.integrity } : {},
|
|
23456
23808
|
...result.projectionConflict ? { projectionConflict: result.projectionConflict } : {},
|
|
23457
23809
|
message: `O pacote "${operation.pack.slug}" falhou, mas o estado anterior foi restaurado exatamente. Corrija a causa indicada e volte a sincronizar.`
|
|
23458
23810
|
};
|
|
@@ -23496,152 +23848,6 @@ function assertUniqueSlugs(packs, label) {
|
|
|
23496
23848
|
}
|
|
23497
23849
|
}
|
|
23498
23850
|
|
|
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
23851
|
// packages/cli/src/sync.ts
|
|
23646
23852
|
var WORK_PACK_COMMITTED_MARKER = ".forge-replacement-committed";
|
|
23647
23853
|
var WORK_PACK_TRANSACTION_SUFFIX = ".transaction";
|
|
@@ -23690,9 +23896,9 @@ async function applyWorkPackManifest(paths, credentials, manifest, options) {
|
|
|
23690
23896
|
const recovery = await recoverInterruptedWorkPackInstalls(paths, options.cleanupWorkPackBackup, options.workPackProjectionBoundary);
|
|
23691
23897
|
const managed = await Promise.all((await managedWorkPackSlugs(paths.skillsDir)).map(async (slug) => ({
|
|
23692
23898
|
slug,
|
|
23693
|
-
version: (await readFile3(
|
|
23694
|
-
agents: await readAgentRecord(
|
|
23695
|
-
commands: await readCommandRecord(
|
|
23899
|
+
version: (await readFile3(path5.join(paths.skillsDir, slug, ".forge-version"), "utf8")).trim(),
|
|
23900
|
+
agents: await readAgentRecord(path5.join(paths.skillsDir, slug)),
|
|
23901
|
+
commands: await readCommandRecord(path5.join(paths.skillsDir, slug))
|
|
23696
23902
|
})));
|
|
23697
23903
|
const desired = manifest.skills.map((skill) => ({
|
|
23698
23904
|
slug: skill.slug,
|
|
@@ -23705,7 +23911,7 @@ async function applyWorkPackManifest(paths, credentials, manifest, options) {
|
|
|
23705
23911
|
desired,
|
|
23706
23912
|
managed,
|
|
23707
23913
|
desiredIsComplete: manifest.workPacksComplete === true,
|
|
23708
|
-
operate: (operation) => operateWorkPack(
|
|
23914
|
+
operate: async (operation) => enrichIntegrityFailure(paths, operation, await operateWorkPack(
|
|
23709
23915
|
paths,
|
|
23710
23916
|
credentials,
|
|
23711
23917
|
skillBySlug,
|
|
@@ -23714,9 +23920,9 @@ async function applyWorkPackManifest(paths, credentials, manifest, options) {
|
|
|
23714
23920
|
recovery.failures,
|
|
23715
23921
|
operation,
|
|
23716
23922
|
options
|
|
23717
|
-
),
|
|
23923
|
+
)),
|
|
23718
23924
|
recoveryFailures: recovery.failures,
|
|
23719
|
-
writeAtomicReceipt: (receipt) => writeJsonAtomic2(
|
|
23925
|
+
writeAtomicReceipt: (receipt) => writeJsonAtomic2(path5.join(paths.forgeDir, "work-pack-sync-receipt.json"), receipt)
|
|
23720
23926
|
});
|
|
23721
23927
|
const installed = workPacks.outcomes.filter((outcome) => outcome.status === "installed").map((outcome) => `${outcome.slug}@${outcome.version}`);
|
|
23722
23928
|
const removed = workPacks.outcomes.filter((outcome) => outcome.status === "removed").map((outcome) => outcome.slug);
|
|
@@ -23727,7 +23933,7 @@ async function applyWorkPackManifest(paths, credentials, manifest, options) {
|
|
|
23727
23933
|
async function collectWorkPackObservations(paths, reconciliation) {
|
|
23728
23934
|
const installedVersions = /* @__PURE__ */ new Map();
|
|
23729
23935
|
for (const slug of await managedWorkPackSlugs(paths.skillsDir)) {
|
|
23730
|
-
const version2 = (await readFile3(
|
|
23936
|
+
const version2 = (await readFile3(path5.join(paths.skillsDir, slug, ".forge-version"), "utf8")).trim();
|
|
23731
23937
|
if (version2) installedVersions.set(slug, version2);
|
|
23732
23938
|
}
|
|
23733
23939
|
const observations = new Map(
|
|
@@ -23740,13 +23946,25 @@ async function collectWorkPackObservations(paths, reconciliation) {
|
|
|
23740
23946
|
state: "failed",
|
|
23741
23947
|
...outcome.version ? { version: outcome.version } : {},
|
|
23742
23948
|
...installedVersions.get(outcome.slug) ? { installedVersion: installedVersions.get(outcome.slug) } : {},
|
|
23743
|
-
errorCode: outcome.code ?? outcome.status
|
|
23949
|
+
errorCode: outcome.code ?? outcome.status,
|
|
23950
|
+
...outcome.integrity ? { integrity: outcome.integrity } : {}
|
|
23744
23951
|
});
|
|
23745
23952
|
}
|
|
23746
23953
|
return [...observations.values()].sort((a, b2) => a.slug.localeCompare(b2.slug));
|
|
23747
23954
|
}
|
|
23955
|
+
async function enrichIntegrityFailure(paths, operation, result) {
|
|
23956
|
+
if (result.status !== "failed" || !["local-edits-preserved", "local-baseline-missing"].includes(result.code)) return result;
|
|
23957
|
+
try {
|
|
23958
|
+
const { summary } = await inspectWorkPackIntegrity({ paths, slug: operation.pack.slug });
|
|
23959
|
+
if (summary.kind === "match") return result;
|
|
23960
|
+
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;
|
|
23961
|
+
return { ...result, code, integrity: summary };
|
|
23962
|
+
} catch {
|
|
23963
|
+
return result;
|
|
23964
|
+
}
|
|
23965
|
+
}
|
|
23748
23966
|
async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds, cleanupPendingSlugs, recoveryFailures, operation, options) {
|
|
23749
|
-
const target =
|
|
23967
|
+
const target = path5.join(paths.skillsDir, operation.pack.slug);
|
|
23750
23968
|
const recoveryFailure = recoveryFailures.get(operation.pack.slug);
|
|
23751
23969
|
if (recoveryFailure) return { status: "failed", restoration: "exact", code: recoveryFailure };
|
|
23752
23970
|
let ownership;
|
|
@@ -23785,7 +24003,7 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
23785
24003
|
let previousManagedPaths;
|
|
23786
24004
|
let archive;
|
|
23787
24005
|
try {
|
|
23788
|
-
const currentVersion = await readFile3(
|
|
24006
|
+
const currentVersion = await readFile3(path5.join(target, ".forge-version"), "utf8").catch(() => "");
|
|
23789
24007
|
const sameVersion = currentVersion.trim() === skill.version;
|
|
23790
24008
|
if (sameVersion) {
|
|
23791
24009
|
let localState = await checkWorkPackInstalledState({
|
|
@@ -23795,7 +24013,7 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
23795
24013
|
});
|
|
23796
24014
|
if (localState === "missing") {
|
|
23797
24015
|
const candidateArchive = await downloadSkill(credentials, skill.url);
|
|
23798
|
-
const candidateSha256 =
|
|
24016
|
+
const candidateSha256 = createHash3("sha256").update(candidateArchive).digest("hex");
|
|
23799
24017
|
if (candidateSha256 !== skill.sha256) {
|
|
23800
24018
|
return { status: "failed", restoration: "exact", code: "local-baseline-missing" };
|
|
23801
24019
|
}
|
|
@@ -23844,7 +24062,7 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
23844
24062
|
}
|
|
23845
24063
|
previousManagedPaths = await managedWorkPackPaths(paths, target);
|
|
23846
24064
|
archive = await downloadSkill(credentials, skill.url);
|
|
23847
|
-
const sha256 =
|
|
24065
|
+
const sha256 = createHash3("sha256").update(archive).digest("hex");
|
|
23848
24066
|
if (sha256 !== skill.sha256) return { status: "failed", restoration: "exact", code: "checksum-mismatch" };
|
|
23849
24067
|
} catch (error45) {
|
|
23850
24068
|
return exactPackFailure(error45);
|
|
@@ -23958,7 +24176,7 @@ var WorkPackLocalEditsError = class extends Error {
|
|
|
23958
24176
|
async function assertWorkPackUnchangedAtBoundary(paths, target) {
|
|
23959
24177
|
const ownership = await workPackOwnership(target);
|
|
23960
24178
|
if (ownership === "absent") return;
|
|
23961
|
-
if (ownership === "foreign") throw foreignWorkPackError(
|
|
24179
|
+
if (ownership === "foreign") throw foreignWorkPackError(path5.basename(target));
|
|
23962
24180
|
const localState = await checkWorkPackInstalledState({
|
|
23963
24181
|
packDir: target,
|
|
23964
24182
|
agentsDir: paths.agentsDir,
|
|
@@ -23982,12 +24200,12 @@ function skillSlugFromUrl(value) {
|
|
|
23982
24200
|
}
|
|
23983
24201
|
}
|
|
23984
24202
|
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 =
|
|
24203
|
+
const tempRoot = await mkdtemp(path5.join(os4.tmpdir(), `forge-${slug}-`));
|
|
24204
|
+
const archivePath = path5.join(tempRoot, `${slug}.tar`);
|
|
24205
|
+
const extractPath = path5.join(tempRoot, "extract");
|
|
24206
|
+
const nextPath = path5.join(tempRoot, slug);
|
|
24207
|
+
const target = path5.join(paths.skillsDir, slug);
|
|
24208
|
+
const backup = path5.join(paths.skillsDir, `${slug}.previous`);
|
|
23991
24209
|
let agentFiles;
|
|
23992
24210
|
let commandFiles;
|
|
23993
24211
|
let previousAgents;
|
|
@@ -23996,7 +24214,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
23996
24214
|
await mkdir2(extractPath, { recursive: true });
|
|
23997
24215
|
await writeFile3(archivePath, archive);
|
|
23998
24216
|
await So({ file: archivePath, cwd: extractPath, strict: true });
|
|
23999
|
-
const extractedSkillPath =
|
|
24217
|
+
const extractedSkillPath = path5.join(extractPath, slug);
|
|
24000
24218
|
await assertNoReservedMarkerAliases(extractedSkillPath);
|
|
24001
24219
|
await validateSkillFolder(extractedSkillPath, slug);
|
|
24002
24220
|
agentFiles = await normalizePackAgentModels(
|
|
@@ -24023,15 +24241,15 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24023
24241
|
}
|
|
24024
24242
|
throw error45;
|
|
24025
24243
|
}
|
|
24026
|
-
await rename3(
|
|
24027
|
-
await writeFile3(
|
|
24244
|
+
await rename3(path5.join(extractPath, slug), nextPath);
|
|
24245
|
+
await writeFile3(path5.join(nextPath, ".forge-version"), `${version2}
|
|
24028
24246
|
`);
|
|
24029
24247
|
if (agentFiles.length > 0) {
|
|
24030
|
-
await writeFile3(
|
|
24248
|
+
await writeFile3(path5.join(nextPath, ".forge-agents"), `${agentFiles.map((agent) => agent.filename).join("\n")}
|
|
24031
24249
|
`);
|
|
24032
24250
|
}
|
|
24033
24251
|
if (commandFiles.length > 0) {
|
|
24034
|
-
await writeFile3(
|
|
24252
|
+
await writeFile3(path5.join(nextPath, ".forge-commands"), `${commandFiles.map((command) => command.filename).join("\n")}
|
|
24035
24253
|
`);
|
|
24036
24254
|
}
|
|
24037
24255
|
await writeWorkPackInstalledState({ packDir: nextPath, version: version2, agents: agentFiles, commands: commandFiles });
|
|
@@ -24042,13 +24260,13 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24042
24260
|
const agentTransactionState = new Map(
|
|
24043
24261
|
[...agentSnapshot.keys()].map((filePath) => [
|
|
24044
24262
|
filePath,
|
|
24045
|
-
agentFiles.find((agent) => agent.filename ===
|
|
24263
|
+
agentFiles.find((agent) => agent.filename === path5.basename(filePath))?.content
|
|
24046
24264
|
])
|
|
24047
24265
|
);
|
|
24048
24266
|
const commandTransactionState = new Map(
|
|
24049
24267
|
[...commandSnapshot.keys()].map((filePath) => [
|
|
24050
24268
|
filePath,
|
|
24051
|
-
commandFiles.find((command) => command.filename ===
|
|
24269
|
+
commandFiles.find((command) => command.filename === path5.basename(filePath))?.content
|
|
24052
24270
|
])
|
|
24053
24271
|
);
|
|
24054
24272
|
const previousManagedPaths = await managedWorkPackPaths(paths, target);
|
|
@@ -24060,7 +24278,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24060
24278
|
throw error45;
|
|
24061
24279
|
}
|
|
24062
24280
|
const writeProjection = options.writeWorkPackProjection ?? writeTextAtomic;
|
|
24063
|
-
const claimedBackup =
|
|
24281
|
+
const claimedBackup = path5.join(tempRoot, `${slug}-claimed-previous`);
|
|
24064
24282
|
const transactionPath = `${backup}${WORK_PACK_TRANSACTION_SUFFIX}`;
|
|
24065
24283
|
let targetBackedUp = false;
|
|
24066
24284
|
let targetInstalled = false;
|
|
@@ -24083,7 +24301,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24083
24301
|
await rename3(nextPath, target);
|
|
24084
24302
|
targetInstalled = true;
|
|
24085
24303
|
for (const filename of previousAgents.filter((name) => !nextAgentNames.has(name))) {
|
|
24086
|
-
const filePath =
|
|
24304
|
+
const filePath = path5.join(paths.agentsDir, filename);
|
|
24087
24305
|
await options.workPackProjectionBoundary?.("install", filePath);
|
|
24088
24306
|
await assertProjectionState(filePath, agentSnapshot.get(filePath));
|
|
24089
24307
|
await rm(filePath, { force: true });
|
|
@@ -24091,14 +24309,14 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24091
24309
|
if (agentFiles.length > 0) {
|
|
24092
24310
|
await mkdir2(paths.agentsDir, { recursive: true });
|
|
24093
24311
|
for (const agent of agentFiles) {
|
|
24094
|
-
const filePath =
|
|
24312
|
+
const filePath = path5.join(paths.agentsDir, agent.filename);
|
|
24095
24313
|
await options.workPackProjectionBoundary?.("install", filePath);
|
|
24096
24314
|
await assertProjectionState(filePath, agentSnapshot.get(filePath));
|
|
24097
24315
|
await writeProjection(filePath, agent.content);
|
|
24098
24316
|
}
|
|
24099
24317
|
}
|
|
24100
24318
|
for (const filename of previousCommands.filter((name) => !nextCommandNames.has(name))) {
|
|
24101
|
-
const filePath =
|
|
24319
|
+
const filePath = path5.join(paths.commandsDir, filename);
|
|
24102
24320
|
await options.workPackProjectionBoundary?.("install", filePath);
|
|
24103
24321
|
await assertProjectionState(filePath, commandSnapshot.get(filePath));
|
|
24104
24322
|
await rm(filePath, { force: true });
|
|
@@ -24106,7 +24324,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24106
24324
|
if (commandFiles.length > 0) {
|
|
24107
24325
|
await mkdir2(paths.commandsDir, { recursive: true });
|
|
24108
24326
|
for (const command of commandFiles) {
|
|
24109
|
-
const filePath =
|
|
24327
|
+
const filePath = path5.join(paths.commandsDir, command.filename);
|
|
24110
24328
|
await options.workPackProjectionBoundary?.("install", filePath);
|
|
24111
24329
|
await assertProjectionState(filePath, commandSnapshot.get(filePath));
|
|
24112
24330
|
await writeProjection(filePath, command.content);
|
|
@@ -24118,7 +24336,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24118
24336
|
await rename3(backup, claimedBackup);
|
|
24119
24337
|
backupClaimed = true;
|
|
24120
24338
|
await assertWorkPackTreeUnchangedAtBoundary(claimedBackup);
|
|
24121
|
-
await writeFile3(
|
|
24339
|
+
await writeFile3(path5.join(claimedBackup, WORK_PACK_COMMITTED_MARKER), `${version2}
|
|
24122
24340
|
`);
|
|
24123
24341
|
await writeTextAtomic(transactionPath, "committed\n");
|
|
24124
24342
|
}
|
|
@@ -24129,7 +24347,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24129
24347
|
await restoreProjectionState(commandSnapshot, commandTransactionState);
|
|
24130
24348
|
}
|
|
24131
24349
|
if (targetBackedUp) {
|
|
24132
|
-
const restoredTarget =
|
|
24350
|
+
const restoredTarget = path5.join(tempRoot, `${slug}-restore`);
|
|
24133
24351
|
const rollbackSource = backupClaimed ? claimedBackup : backup;
|
|
24134
24352
|
await cp(rollbackSource, restoredTarget, { recursive: true });
|
|
24135
24353
|
if (targetInstalled) await rm(target, { recursive: true, force: true });
|
|
@@ -24166,19 +24384,19 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24166
24384
|
return { cleanup };
|
|
24167
24385
|
}
|
|
24168
24386
|
async function adoptLegacyWorkPackState(paths, slug, version2, archive, approvedModelIds) {
|
|
24169
|
-
const comparisonRoot = await mkdtemp(
|
|
24387
|
+
const comparisonRoot = await mkdtemp(path5.join(os4.tmpdir(), `forge-${slug}-baseline-`));
|
|
24170
24388
|
const comparisonPaths = {
|
|
24171
24389
|
...paths,
|
|
24172
|
-
skillsDir:
|
|
24173
|
-
agentsDir:
|
|
24174
|
-
commandsDir:
|
|
24390
|
+
skillsDir: path5.join(comparisonRoot, "skills"),
|
|
24391
|
+
agentsDir: path5.join(comparisonRoot, "agents"),
|
|
24392
|
+
commandsDir: path5.join(comparisonRoot, "commands")
|
|
24175
24393
|
};
|
|
24176
24394
|
try {
|
|
24177
24395
|
await mkdir2(comparisonPaths.skillsDir, { recursive: true });
|
|
24178
24396
|
await installSkillArchive(comparisonPaths, slug, version2, archive, { approvedModelIds });
|
|
24179
24397
|
return adoptWorkPackInstalledState({
|
|
24180
|
-
expectedPackDir:
|
|
24181
|
-
packDir:
|
|
24398
|
+
expectedPackDir: path5.join(comparisonPaths.skillsDir, slug),
|
|
24399
|
+
packDir: path5.join(paths.skillsDir, slug),
|
|
24182
24400
|
agentsDir: paths.agentsDir,
|
|
24183
24401
|
commandsDir: paths.commandsDir
|
|
24184
24402
|
});
|
|
@@ -24189,7 +24407,7 @@ async function adoptLegacyWorkPackState(paths, slug, version2, archive, approved
|
|
|
24189
24407
|
async function recoverInterruptedWorkPackInstalls(paths, cleanupWorkPackBackup, workPackProjectionBoundary) {
|
|
24190
24408
|
const cleanupPending = /* @__PURE__ */ new Set();
|
|
24191
24409
|
const failures = /* @__PURE__ */ new Map();
|
|
24192
|
-
const entries = await
|
|
24410
|
+
const entries = await readdir3(paths.skillsDir, { withFileTypes: true }).catch((error45) => {
|
|
24193
24411
|
if (error45.code === "ENOENT") return [];
|
|
24194
24412
|
throw error45;
|
|
24195
24413
|
});
|
|
@@ -24197,7 +24415,7 @@ async function recoverInterruptedWorkPackInstalls(paths, cleanupWorkPackBackup,
|
|
|
24197
24415
|
if (!entry.name.endsWith(".previous")) continue;
|
|
24198
24416
|
const slug = entry.name.slice(0, -".previous".length);
|
|
24199
24417
|
if (!slug) continue;
|
|
24200
|
-
const target =
|
|
24418
|
+
const target = path5.join(paths.skillsDir, slug);
|
|
24201
24419
|
const backup = `${target}.previous`;
|
|
24202
24420
|
const transactionState = await readWorkPackTransactionState(backup);
|
|
24203
24421
|
if (transactionState === "committed") {
|
|
@@ -24230,9 +24448,9 @@ async function recoverInterruptedWorkPackInstall(paths, target, cleanupWorkPackB
|
|
|
24230
24448
|
const backup = `${target}.previous`;
|
|
24231
24449
|
const backupOwnership = await workPackOwnership(backup);
|
|
24232
24450
|
if (backupOwnership === "absent") return "recovered";
|
|
24233
|
-
if (backupOwnership === "foreign") throw foreignWorkPackError(
|
|
24234
|
-
if (await workPackOwnership(target) === "foreign") throw foreignWorkPackError(
|
|
24235
|
-
const committed = await readFile3(
|
|
24451
|
+
if (backupOwnership === "foreign") throw foreignWorkPackError(path5.basename(target));
|
|
24452
|
+
if (await workPackOwnership(target) === "foreign") throw foreignWorkPackError(path5.basename(target));
|
|
24453
|
+
const committed = await readFile3(path5.join(backup, WORK_PACK_COMMITTED_MARKER), "utf8").catch((error45) => {
|
|
24236
24454
|
if (error45.code === "ENOENT") return void 0;
|
|
24237
24455
|
throw error45;
|
|
24238
24456
|
});
|
|
@@ -24274,32 +24492,32 @@ async function recoverInterruptedWorkPackInstall(paths, target, cleanupWorkPackB
|
|
|
24274
24492
|
);
|
|
24275
24493
|
const previousAgentNames = new Set(previousAgents.map((agent) => agent.filename));
|
|
24276
24494
|
const previousCommandNames = new Set(previousCommands.map((command) => command.filename));
|
|
24277
|
-
const recoveryRoot = await mkdtemp(
|
|
24278
|
-
const recoveredTarget =
|
|
24495
|
+
const recoveryRoot = await mkdtemp(path5.join(os4.tmpdir(), "forge-recover-"));
|
|
24496
|
+
const recoveredTarget = path5.join(recoveryRoot, path5.basename(target));
|
|
24279
24497
|
await cp(backup, recoveredTarget, { recursive: true });
|
|
24280
24498
|
try {
|
|
24281
24499
|
for (const filename of currentAgents.filter((name) => !previousAgentNames.has(name))) {
|
|
24282
|
-
const filePath =
|
|
24500
|
+
const filePath = path5.join(paths.agentsDir, filename);
|
|
24283
24501
|
await workPackProjectionBoundary?.("recover", filePath);
|
|
24284
24502
|
await assertProjectionState(filePath, agentRecoveryState.get(filePath));
|
|
24285
24503
|
await rm(filePath, { force: true });
|
|
24286
24504
|
}
|
|
24287
24505
|
await mkdir2(paths.agentsDir, { recursive: true });
|
|
24288
24506
|
for (const agent of previousAgents) {
|
|
24289
|
-
const filePath =
|
|
24507
|
+
const filePath = path5.join(paths.agentsDir, agent.filename);
|
|
24290
24508
|
await workPackProjectionBoundary?.("recover", filePath);
|
|
24291
24509
|
await assertProjectionState(filePath, agentRecoveryState.get(filePath));
|
|
24292
24510
|
await writeTextAtomic(filePath, agent.content);
|
|
24293
24511
|
}
|
|
24294
24512
|
for (const filename of currentCommands.filter((name) => !previousCommandNames.has(name))) {
|
|
24295
|
-
const filePath =
|
|
24513
|
+
const filePath = path5.join(paths.commandsDir, filename);
|
|
24296
24514
|
await workPackProjectionBoundary?.("recover", filePath);
|
|
24297
24515
|
await assertProjectionState(filePath, commandRecoveryState.get(filePath));
|
|
24298
24516
|
await rm(filePath, { force: true });
|
|
24299
24517
|
}
|
|
24300
24518
|
await mkdir2(paths.commandsDir, { recursive: true });
|
|
24301
24519
|
for (const command of previousCommands) {
|
|
24302
|
-
const filePath =
|
|
24520
|
+
const filePath = path5.join(paths.commandsDir, command.filename);
|
|
24303
24521
|
await workPackProjectionBoundary?.("recover", filePath);
|
|
24304
24522
|
await assertProjectionState(filePath, commandRecoveryState.get(filePath));
|
|
24305
24523
|
await writeTextAtomic(filePath, command.content);
|
|
@@ -24356,19 +24574,19 @@ async function readWorkPackRemovedProjections(backup) {
|
|
|
24356
24574
|
return { agents, commands };
|
|
24357
24575
|
}
|
|
24358
24576
|
async function pathExists(filePath) {
|
|
24359
|
-
return
|
|
24577
|
+
return lstat4(filePath).then(() => true, (error45) => {
|
|
24360
24578
|
if (error45.code === "ENOENT") return false;
|
|
24361
24579
|
throw error45;
|
|
24362
24580
|
});
|
|
24363
24581
|
}
|
|
24364
24582
|
async function workPackOwnership(target) {
|
|
24365
|
-
const targetStat = await
|
|
24583
|
+
const targetStat = await lstat4(target).catch((error45) => {
|
|
24366
24584
|
if (error45.code === "ENOENT") return void 0;
|
|
24367
24585
|
throw error45;
|
|
24368
24586
|
});
|
|
24369
24587
|
if (!targetStat) return "absent";
|
|
24370
24588
|
if (!targetStat.isDirectory()) return "foreign";
|
|
24371
|
-
const marker = await readFile3(
|
|
24589
|
+
const marker = await readFile3(path5.join(target, ".forge-version"), "utf8").catch((error45) => {
|
|
24372
24590
|
if (error45.code === "ENOENT") return void 0;
|
|
24373
24591
|
throw error45;
|
|
24374
24592
|
});
|
|
@@ -24394,11 +24612,11 @@ async function assertProjectionRecoveryIsSafe(directory, currentFiles, previousF
|
|
|
24394
24612
|
expected.set(file2.filename, contents);
|
|
24395
24613
|
}
|
|
24396
24614
|
for (const [filename, contents] of expected) {
|
|
24397
|
-
const projected = await readFile3(
|
|
24615
|
+
const projected = await readFile3(path5.join(directory, filename), "utf8").catch((error45) => {
|
|
24398
24616
|
if (error45.code === "ENOENT") return void 0;
|
|
24399
24617
|
throw error45;
|
|
24400
24618
|
});
|
|
24401
|
-
validated.set(
|
|
24619
|
+
validated.set(path5.join(directory, filename), projected);
|
|
24402
24620
|
const missingPreviousProjection = missingPreviousProjectionIsLocalDeletion(
|
|
24403
24621
|
filename,
|
|
24404
24622
|
projected,
|
|
@@ -24421,13 +24639,13 @@ async function assertProjectionState(filePath, expected) {
|
|
|
24421
24639
|
throw error45;
|
|
24422
24640
|
});
|
|
24423
24641
|
if (current !== expected) {
|
|
24424
|
-
throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${
|
|
24642
|
+
throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${path5.basename(filePath)} foi alterada durante a opera\xE7\xE3o`);
|
|
24425
24643
|
}
|
|
24426
24644
|
}
|
|
24427
24645
|
async function captureProjectionState(directory, filenames) {
|
|
24428
24646
|
const snapshot = /* @__PURE__ */ new Map();
|
|
24429
24647
|
for (const filename of filenames) {
|
|
24430
|
-
const filePath =
|
|
24648
|
+
const filePath = path5.join(directory, filename);
|
|
24431
24649
|
const content = await readFile3(filePath, "utf8").catch((error45) => {
|
|
24432
24650
|
if (error45.code === "ENOENT") return void 0;
|
|
24433
24651
|
throw error45;
|
|
@@ -24450,8 +24668,8 @@ async function restoreProjectionState(snapshot, transactionState) {
|
|
|
24450
24668
|
}
|
|
24451
24669
|
}
|
|
24452
24670
|
async function readPackAgentFiles(skillFolder) {
|
|
24453
|
-
const agentsFolder =
|
|
24454
|
-
const entries = await
|
|
24671
|
+
const agentsFolder = path5.join(skillFolder, "agents");
|
|
24672
|
+
const entries = await readdir3(agentsFolder, { withFileTypes: true }).catch((error45) => {
|
|
24455
24673
|
if (error45.code === "ENOENT") return [];
|
|
24456
24674
|
throw error45;
|
|
24457
24675
|
});
|
|
@@ -24459,7 +24677,7 @@ async function readPackAgentFiles(skillFolder) {
|
|
|
24459
24677
|
for (const entry of entries) {
|
|
24460
24678
|
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
24461
24679
|
if (entry.name.startsWith("._")) continue;
|
|
24462
|
-
const content = await readFile3(
|
|
24680
|
+
const content = await readFile3(path5.join(agentsFolder, entry.name), "utf8");
|
|
24463
24681
|
validateAgentFile(entry.name, content);
|
|
24464
24682
|
files.push({ filename: entry.name, content });
|
|
24465
24683
|
}
|
|
@@ -24470,7 +24688,7 @@ async function normalizePackAgentModels(skillFolder, agentFiles, approvedModelId
|
|
|
24470
24688
|
for (const agent of agentFiles) {
|
|
24471
24689
|
const content = normalizePackAgentModel(agent.filename, agent.content, approvedModelIds, slug);
|
|
24472
24690
|
if (content !== agent.content) {
|
|
24473
|
-
await writeFile3(
|
|
24691
|
+
await writeFile3(path5.join(skillFolder, "agents", agent.filename), content);
|
|
24474
24692
|
}
|
|
24475
24693
|
normalized.push({ ...agent, content });
|
|
24476
24694
|
}
|
|
@@ -24490,8 +24708,8 @@ function normalizePackAgentModel(filename, content, approvedModelIds, slug) {
|
|
|
24490
24708
|
return normalizePackExtensionModel(`agents/${filename}`, content, approvedModelIds, slug);
|
|
24491
24709
|
}
|
|
24492
24710
|
async function readPackCommandFiles(skillFolder) {
|
|
24493
|
-
const commandsFolder =
|
|
24494
|
-
const entries = await
|
|
24711
|
+
const commandsFolder = path5.join(skillFolder, "commands");
|
|
24712
|
+
const entries = await readdir3(commandsFolder, { withFileTypes: true }).catch((error45) => {
|
|
24495
24713
|
if (error45.code === "ENOENT") return [];
|
|
24496
24714
|
throw error45;
|
|
24497
24715
|
});
|
|
@@ -24499,7 +24717,7 @@ async function readPackCommandFiles(skillFolder) {
|
|
|
24499
24717
|
for (const entry of entries) {
|
|
24500
24718
|
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
24501
24719
|
if (entry.name.startsWith("._")) continue;
|
|
24502
|
-
const content = await readFile3(
|
|
24720
|
+
const content = await readFile3(path5.join(commandsFolder, entry.name), "utf8");
|
|
24503
24721
|
validateCommandFile(entry.name, content);
|
|
24504
24722
|
files.push({ filename: entry.name, content });
|
|
24505
24723
|
}
|
|
@@ -24510,7 +24728,7 @@ async function normalizePackCommandModels(skillFolder, commandFiles, approvedMod
|
|
|
24510
24728
|
for (const command of commandFiles) {
|
|
24511
24729
|
const content = normalizePackExtensionModel(`commands/${command.filename}`, command.content, approvedModelIds, slug);
|
|
24512
24730
|
if (content !== command.content) {
|
|
24513
|
-
await writeFile3(
|
|
24731
|
+
await writeFile3(path5.join(skillFolder, "commands", command.filename), content);
|
|
24514
24732
|
}
|
|
24515
24733
|
normalized.push({ ...command, content });
|
|
24516
24734
|
}
|
|
@@ -24532,7 +24750,7 @@ async function assertNoForeignAgentConflicts(agentsDir, agentFiles, ownedFilenam
|
|
|
24532
24750
|
const owned = new Set(ownedFilenames);
|
|
24533
24751
|
for (const agent of agentFiles) {
|
|
24534
24752
|
if (owned.has(agent.filename)) continue;
|
|
24535
|
-
const existing = await readFile3(
|
|
24753
|
+
const existing = await readFile3(path5.join(agentsDir, agent.filename), "utf8").catch((error45) => {
|
|
24536
24754
|
if (error45.code === "ENOENT") return void 0;
|
|
24537
24755
|
throw error45;
|
|
24538
24756
|
});
|
|
@@ -24545,7 +24763,7 @@ async function assertNoForeignCommandConflicts(commandsDir, commandFiles, ownedF
|
|
|
24545
24763
|
const owned = new Set(ownedFilenames);
|
|
24546
24764
|
for (const command of commandFiles) {
|
|
24547
24765
|
if (owned.has(command.filename)) continue;
|
|
24548
|
-
const existing = await readFile3(
|
|
24766
|
+
const existing = await readFile3(path5.join(commandsDir, command.filename), "utf8").catch((error45) => {
|
|
24549
24767
|
if (error45.code === "ENOENT") return void 0;
|
|
24550
24768
|
throw error45;
|
|
24551
24769
|
});
|
|
@@ -24555,28 +24773,28 @@ async function assertNoForeignCommandConflicts(commandsDir, commandFiles, ownedF
|
|
|
24555
24773
|
}
|
|
24556
24774
|
}
|
|
24557
24775
|
async function readAgentRecord(skillFolder) {
|
|
24558
|
-
const raw = await readFile3(
|
|
24776
|
+
const raw = await readFile3(path5.join(skillFolder, ".forge-agents"), "utf8").catch(() => "");
|
|
24559
24777
|
return raw.split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.includes("/") && !line.includes("\\") && line !== "..");
|
|
24560
24778
|
}
|
|
24561
24779
|
async function readCommandRecord(skillFolder) {
|
|
24562
|
-
const raw = await readFile3(
|
|
24780
|
+
const raw = await readFile3(path5.join(skillFolder, ".forge-commands"), "utf8").catch(() => "");
|
|
24563
24781
|
return raw.split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.includes("/") && !line.includes("\\") && line !== "..");
|
|
24564
24782
|
}
|
|
24565
24783
|
async function managedWorkPackPaths(paths, skillFolder) {
|
|
24566
24784
|
const files = await listFilesRecursively(skillFolder);
|
|
24567
|
-
const agents = (await readAgentRecord(skillFolder)).map((filename) =>
|
|
24568
|
-
const commands = (await readCommandRecord(skillFolder)).map((filename) =>
|
|
24785
|
+
const agents = (await readAgentRecord(skillFolder)).map((filename) => path5.join(paths.agentsDir, filename));
|
|
24786
|
+
const commands = (await readCommandRecord(skillFolder)).map((filename) => path5.join(paths.commandsDir, filename));
|
|
24569
24787
|
return [.../* @__PURE__ */ new Set([...files, ...agents, ...commands])];
|
|
24570
24788
|
}
|
|
24571
24789
|
async function managedWorkPackSlugs(skillsDir) {
|
|
24572
|
-
const entries = await
|
|
24790
|
+
const entries = await readdir3(skillsDir, { withFileTypes: true }).catch((error45) => {
|
|
24573
24791
|
if (error45.code === "ENOENT") return [];
|
|
24574
24792
|
throw error45;
|
|
24575
24793
|
});
|
|
24576
24794
|
const slugs = [];
|
|
24577
24795
|
for (const entry of entries) {
|
|
24578
24796
|
if (!entry.isDirectory() || entry.name.endsWith(".previous")) continue;
|
|
24579
|
-
if (await workPackOwnership(
|
|
24797
|
+
if (await workPackOwnership(path5.join(skillsDir, entry.name)) === "managed") slugs.push(entry.name);
|
|
24580
24798
|
}
|
|
24581
24799
|
return slugs.sort((left, right) => left.localeCompare(right));
|
|
24582
24800
|
}
|
|
@@ -24586,14 +24804,14 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
|
|
|
24586
24804
|
const agents = await readAgentRecord(target);
|
|
24587
24805
|
const commands = await readCommandRecord(target);
|
|
24588
24806
|
const snapshots = await Promise.all([
|
|
24589
|
-
...agents.map((filename) => captureExactFile(
|
|
24590
|
-
...commands.map((filename) => captureExactFile(
|
|
24807
|
+
...agents.map((filename) => captureExactFile(path5.join(paths.agentsDir, filename))),
|
|
24808
|
+
...commands.map((filename) => captureExactFile(path5.join(paths.commandsDir, filename)))
|
|
24591
24809
|
]);
|
|
24592
24810
|
await assertWorkPackUnchangedAtBoundary(paths, target);
|
|
24593
24811
|
const backup = `${target}.previous`;
|
|
24594
24812
|
const transactionPath = `${backup}${WORK_PACK_TRANSACTION_SUFFIX}`;
|
|
24595
|
-
const transactionRoot = await mkdtemp(
|
|
24596
|
-
const claimedBackup =
|
|
24813
|
+
const transactionRoot = await mkdtemp(path5.join(os4.tmpdir(), "forge-remove-"));
|
|
24814
|
+
const claimedBackup = path5.join(transactionRoot, path5.basename(target));
|
|
24597
24815
|
let projectionsRemoved = false;
|
|
24598
24816
|
let backupClaimed = false;
|
|
24599
24817
|
try {
|
|
@@ -24611,7 +24829,7 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
|
|
|
24611
24829
|
await assertWorkPackUnchangedAtBoundary(paths, backup);
|
|
24612
24830
|
projectionsRemoved = agents.length > 0;
|
|
24613
24831
|
for (const filename of agents) {
|
|
24614
|
-
const filePath =
|
|
24832
|
+
const filePath = path5.join(paths.agentsDir, filename);
|
|
24615
24833
|
await options.workPackProjectionBoundary?.("remove", filePath);
|
|
24616
24834
|
await assertExactFileState(snapshots, filePath);
|
|
24617
24835
|
await recordRemovedProjection(transactionPath, "agent", filename);
|
|
@@ -24620,7 +24838,7 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
|
|
|
24620
24838
|
await options.removeWorkPackBoundary?.("after-agents");
|
|
24621
24839
|
projectionsRemoved ||= commands.length > 0;
|
|
24622
24840
|
for (const filename of commands) {
|
|
24623
|
-
const filePath =
|
|
24841
|
+
const filePath = path5.join(paths.commandsDir, filename);
|
|
24624
24842
|
await options.workPackProjectionBoundary?.("remove", filePath);
|
|
24625
24843
|
await assertExactFileState(snapshots, filePath);
|
|
24626
24844
|
await recordRemovedProjection(transactionPath, "command", filename);
|
|
@@ -24646,7 +24864,7 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
|
|
|
24646
24864
|
if (await workPackOwnership(target) !== "managed") throw new Error("restored Work Pack marker missing");
|
|
24647
24865
|
await rm(transactionRoot, { recursive: true, force: true }).catch(() => void 0);
|
|
24648
24866
|
} catch (restoreError) {
|
|
24649
|
-
throw new WorkPackRecoveryUncertainError(`Falha ao remover e restaurar o pacote de trabalho ${
|
|
24867
|
+
throw new WorkPackRecoveryUncertainError(`Falha ao remover e restaurar o pacote de trabalho ${path5.basename(target)}`, {
|
|
24650
24868
|
cause: new AggregateError([error45, restoreError])
|
|
24651
24869
|
});
|
|
24652
24870
|
}
|
|
@@ -24655,7 +24873,7 @@ async function removeManagedWorkPackTransaction(paths, target, options) {
|
|
|
24655
24873
|
}
|
|
24656
24874
|
async function captureExactFile(filePath) {
|
|
24657
24875
|
try {
|
|
24658
|
-
const info = await
|
|
24876
|
+
const info = await lstat4(filePath);
|
|
24659
24877
|
if (!info.isFile()) throw new Error(`A proje\xE7\xE3o gerida n\xE3o \xE9 um ficheiro regular: ${filePath}`);
|
|
24660
24878
|
return { path: filePath, exists: true, bytes: await readFile3(filePath), mode: info.mode & 4095 };
|
|
24661
24879
|
} catch (error45) {
|
|
@@ -24667,17 +24885,17 @@ async function assertExactFileState(snapshots, filePath) {
|
|
|
24667
24885
|
const expected = snapshots.find((snapshot) => snapshot.path === filePath);
|
|
24668
24886
|
const current = await captureExactFile(filePath);
|
|
24669
24887
|
if (!expected || current.exists !== expected.exists) {
|
|
24670
|
-
throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${
|
|
24888
|
+
throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${path5.basename(filePath)} foi alterada durante a opera\xE7\xE3o`);
|
|
24671
24889
|
}
|
|
24672
24890
|
if (current.exists && (!current.bytes?.equals(expected.bytes) || current.mode !== expected.mode)) {
|
|
24673
|
-
throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${
|
|
24891
|
+
throw new WorkPackLocalEditsError("local-edits-preserved", `A proje\xE7\xE3o ${path5.basename(filePath)} foi alterada durante a opera\xE7\xE3o`);
|
|
24674
24892
|
}
|
|
24675
24893
|
}
|
|
24676
24894
|
async function restoreRemovedExactFiles(snapshots) {
|
|
24677
24895
|
for (const snapshot of snapshots) {
|
|
24678
24896
|
if ((await captureExactFile(snapshot.path)).exists) continue;
|
|
24679
24897
|
if (!snapshot.exists) continue;
|
|
24680
|
-
await mkdir2(
|
|
24898
|
+
await mkdir2(path5.dirname(snapshot.path), { recursive: true });
|
|
24681
24899
|
await writeFile3(snapshot.path, snapshot.bytes);
|
|
24682
24900
|
await chmod(snapshot.path, snapshot.mode);
|
|
24683
24901
|
}
|
|
@@ -24689,20 +24907,20 @@ async function verifyRestoredOrLocallyChangedFiles(snapshots) {
|
|
|
24689
24907
|
}
|
|
24690
24908
|
}
|
|
24691
24909
|
async function listFilesRecursively(root) {
|
|
24692
|
-
const entries = await
|
|
24910
|
+
const entries = await readdir3(root, { withFileTypes: true }).catch((error45) => {
|
|
24693
24911
|
if (error45.code === "ENOENT") return [];
|
|
24694
24912
|
throw error45;
|
|
24695
24913
|
});
|
|
24696
24914
|
const files = [];
|
|
24697
24915
|
for (const entry of entries) {
|
|
24698
|
-
const absolute =
|
|
24916
|
+
const absolute = path5.join(root, entry.name);
|
|
24699
24917
|
if (entry.isDirectory()) files.push(...await listFilesRecursively(absolute));
|
|
24700
24918
|
else if (entry.isFile()) files.push(absolute);
|
|
24701
24919
|
}
|
|
24702
24920
|
return files;
|
|
24703
24921
|
}
|
|
24704
24922
|
async function validateSkillFolder(folder, slug) {
|
|
24705
|
-
const skillMd = await readFile3(
|
|
24923
|
+
const skillMd = await readFile3(path5.join(folder, "SKILL.md"), "utf8");
|
|
24706
24924
|
const frontmatter = /^---\n([\s\S]+?)\n---/.exec(skillMd)?.[1] ?? "";
|
|
24707
24925
|
if (!frontmatter.includes(`name: ${slug}`) && !frontmatter.includes(`name: "${slug}"`)) {
|
|
24708
24926
|
throw new Error(`O campo name no frontmatter de SKILL.md tem de corresponder a ${slug}`);
|
|
@@ -24713,7 +24931,7 @@ async function validateSkillFolder(folder, slug) {
|
|
|
24713
24931
|
}
|
|
24714
24932
|
async function assertNoReservedMarkerAliases(skillFolder) {
|
|
24715
24933
|
const reserved = /* @__PURE__ */ new Set([".forge-version", ".forge-agents", ".forge-commands", WORK_PACK_LOCAL_STATE_FILENAME]);
|
|
24716
|
-
const entries = await
|
|
24934
|
+
const entries = await readdir3(skillFolder);
|
|
24717
24935
|
const marker = entries.find((entry) => reserved.has(entry.toLowerCase()));
|
|
24718
24936
|
if (marker) throw new Error(`O pacote de trabalho cont\xE9m o marcador Forge reservado ${marker}`);
|
|
24719
24937
|
}
|
|
@@ -24723,15 +24941,15 @@ async function writeJsonAtomic2(filePath, value) {
|
|
|
24723
24941
|
await writeTextAtomic(filePath, content);
|
|
24724
24942
|
}
|
|
24725
24943
|
async function writeTextAtomic(filePath, content) {
|
|
24726
|
-
const dir =
|
|
24944
|
+
const dir = path5.dirname(filePath);
|
|
24727
24945
|
await mkdir2(dir, { recursive: true });
|
|
24728
|
-
const tempPath =
|
|
24946
|
+
const tempPath = path5.join(dir, `.${path5.basename(filePath)}.${process.pid}.tmp`);
|
|
24729
24947
|
await writeFile3(tempPath, content);
|
|
24730
24948
|
await rename3(tempPath, filePath);
|
|
24731
24949
|
}
|
|
24732
24950
|
|
|
24733
24951
|
// packages/cli/src/workerPrompt.ts
|
|
24734
|
-
import { createHash as
|
|
24952
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
24735
24953
|
var STOCK_OPENWORK_PROMPT_SHA256 = "b84527bf738ab37c726ccd43c3161df30fbddd5384aadbe7abf3cfeb3fced497";
|
|
24736
24954
|
var FORGE_WORKER_PROMPT = `\xC9s o assistente de trabalho do Forge no OpenWork. Ajudas a pessoa a concluir
|
|
24737
24955
|
tarefas com os ficheiros, fontes e ferramentas a que tem acesso. N\xE3o pressuponhas
|
|
@@ -24812,7 +25030,7 @@ function applySharedWorkerPrompt(config2) {
|
|
|
24812
25030
|
const agent = config2.agent.openwork;
|
|
24813
25031
|
if (!isRecord(agent) || agent.mode !== "primary" || typeof agent.prompt !== "string") return false;
|
|
24814
25032
|
if (agent.prompt === FORGE_WORKER_PROMPT) return true;
|
|
24815
|
-
const hash2 =
|
|
25033
|
+
const hash2 = createHash4("sha256").update(agent.prompt.replace(/\r\n/g, "\n").trim()).digest("hex");
|
|
24816
25034
|
if (hash2 !== STOCK_OPENWORK_PROMPT_SHA256) return false;
|
|
24817
25035
|
config2.agent = { ...config2.agent, openwork: { ...agent, prompt: FORGE_WORKER_PROMPT } };
|
|
24818
25036
|
return true;
|
|
@@ -24822,7 +25040,7 @@ function isRecord(value) {
|
|
|
24822
25040
|
}
|
|
24823
25041
|
|
|
24824
25042
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
24825
|
-
var PLUGIN_VERSION = "0.1.
|
|
25043
|
+
var PLUGIN_VERSION = "0.1.17";
|
|
24826
25044
|
var STATUS_FILENAME = "work-pack-startup-status.json";
|
|
24827
25045
|
var activeSync = /* @__PURE__ */ new Map();
|
|
24828
25046
|
var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
@@ -24833,7 +25051,7 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
|
24833
25051
|
activeSync.set(forgeBaseUrl, sync);
|
|
24834
25052
|
}
|
|
24835
25053
|
const state = await sync;
|
|
24836
|
-
const legacyPath =
|
|
25054
|
+
const legacyPath = path6.join(state.paths.pluginDir, FORGE_EVIDENCE_PLUGIN_FILENAME);
|
|
24837
25055
|
const ownershipSymbol = /* @__PURE__ */ Symbol.for("minimal-forge.legacy-evidence-owners.v1");
|
|
24838
25056
|
const shared = globalThis;
|
|
24839
25057
|
const legacyOwners = shared[ownershipSymbol] ??= /* @__PURE__ */ new Set();
|
|
@@ -24844,13 +25062,13 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
|
24844
25062
|
const slug = typeof input.args?.name === "string" ? input.args.name.trim().toLowerCase() : "";
|
|
24845
25063
|
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug)) return;
|
|
24846
25064
|
try {
|
|
24847
|
-
await readFile4(
|
|
25065
|
+
await readFile4(path6.join(state.paths.skillsDir, slug, ".forge-version"), "utf8");
|
|
24848
25066
|
} catch {
|
|
24849
25067
|
return;
|
|
24850
25068
|
}
|
|
24851
25069
|
try {
|
|
24852
25070
|
const { forgeApiKey } = await readWellKnownForgeCredentials(state.paths.opencodeAuthPath, forgeBaseUrl);
|
|
24853
|
-
const credentialId =
|
|
25071
|
+
const credentialId = createHash5("sha256").update(forgeApiKey).digest("hex");
|
|
24854
25072
|
const reportUsage = skillUsageReporter(forgeBaseUrl, credentialId, (events) => fetch(`${forgeBaseUrl}/sync/evidence`, {
|
|
24855
25073
|
method: "POST",
|
|
24856
25074
|
redirect: "error",
|
|
@@ -24993,17 +25211,17 @@ function parseForgeBaseUrl(options) {
|
|
|
24993
25211
|
async function managedProjectionNames(paths) {
|
|
24994
25212
|
const agents = /* @__PURE__ */ new Set();
|
|
24995
25213
|
const commands = /* @__PURE__ */ new Set();
|
|
24996
|
-
const entries = await
|
|
25214
|
+
const entries = await readdir4(paths.skillsDir, { withFileTypes: true }).catch((error45) => {
|
|
24997
25215
|
if (error45.code === "ENOENT") return [];
|
|
24998
25216
|
throw error45;
|
|
24999
25217
|
});
|
|
25000
25218
|
for (const entry of entries) {
|
|
25001
25219
|
if (!entry.isDirectory()) continue;
|
|
25002
|
-
const folder =
|
|
25003
|
-
const marker = await readFile4(
|
|
25220
|
+
const folder = path6.join(paths.skillsDir, entry.name);
|
|
25221
|
+
const marker = await readFile4(path6.join(folder, ".forge-version"), "utf8").catch(() => "");
|
|
25004
25222
|
if (!marker.trim()) continue;
|
|
25005
|
-
for (const name of await readProjectionRecord(
|
|
25006
|
-
for (const name of await readProjectionRecord(
|
|
25223
|
+
for (const name of await readProjectionRecord(path6.join(folder, ".forge-agents"))) agents.add(stripMarkdownExtension(name));
|
|
25224
|
+
for (const name of await readProjectionRecord(path6.join(folder, ".forge-commands"))) commands.add(stripMarkdownExtension(name));
|
|
25007
25225
|
}
|
|
25008
25226
|
return { agents, commands };
|
|
25009
25227
|
}
|
|
@@ -25019,10 +25237,10 @@ async function projectCurrentExtensions(config2, state) {
|
|
|
25019
25237
|
for (const name of state.before.agents) if (!state.after.agents.has(name)) delete agents[name];
|
|
25020
25238
|
for (const name of state.before.commands) if (!state.after.commands.has(name)) delete commands[name];
|
|
25021
25239
|
for (const name of state.after.agents) {
|
|
25022
|
-
agents[name] = await parseMarkdownConfig(
|
|
25240
|
+
agents[name] = await parseMarkdownConfig(path6.join(state.paths.agentsDir, `${name}.md`), "prompt");
|
|
25023
25241
|
}
|
|
25024
25242
|
for (const name of state.after.commands) {
|
|
25025
|
-
commands[name] = await parseMarkdownConfig(
|
|
25243
|
+
commands[name] = await parseMarkdownConfig(path6.join(state.paths.commandsDir, `${name}.md`), "template");
|
|
25026
25244
|
}
|
|
25027
25245
|
config2.agent = agents;
|
|
25028
25246
|
config2.command = commands;
|
|
@@ -25030,10 +25248,10 @@ async function projectCurrentExtensions(config2, state) {
|
|
|
25030
25248
|
async function parseMarkdownConfig(filePath, bodyField) {
|
|
25031
25249
|
const raw = await readFile4(filePath, "utf8");
|
|
25032
25250
|
const match = /^---\r?\n([\s\S]+?)\r?\n---\r?\n?([\s\S]*)$/.exec(raw);
|
|
25033
|
-
if (!match) throw new Error(`A extens\xE3o Forge ${
|
|
25251
|
+
if (!match) throw new Error(`A extens\xE3o Forge ${path6.basename(filePath)} n\xE3o tem frontmatter v\xE1lido`);
|
|
25034
25252
|
const data = (0, import_yaml.parse)(match[1]);
|
|
25035
25253
|
if (!data || typeof data !== "object" || Array.isArray(data)) {
|
|
25036
|
-
throw new Error(`A extens\xE3o Forge ${
|
|
25254
|
+
throw new Error(`A extens\xE3o Forge ${path6.basename(filePath)} n\xE3o tem frontmatter v\xE1lido`);
|
|
25037
25255
|
}
|
|
25038
25256
|
const config2 = { ...data, [bodyField]: match[2].trim() };
|
|
25039
25257
|
if (bodyField === "prompt" && typeof config2.permission === "string" && ["allow", "ask", "deny"].includes(config2.permission)) {
|
|
@@ -25049,8 +25267,8 @@ function stripMarkdownExtension(filename) {
|
|
|
25049
25267
|
}
|
|
25050
25268
|
async function writeStatus(paths, value) {
|
|
25051
25269
|
await mkdir3(paths.forgeDir, { recursive: true });
|
|
25052
|
-
const target =
|
|
25053
|
-
const temporary =
|
|
25270
|
+
const target = path6.join(paths.forgeDir, STATUS_FILENAME);
|
|
25271
|
+
const temporary = path6.join(paths.forgeDir, `.${STATUS_FILENAME}.${process.pid}.tmp`);
|
|
25054
25272
|
await writeFile4(temporary, `${JSON.stringify(value, null, 2)}
|
|
25055
25273
|
`, { mode: 384 });
|
|
25056
25274
|
await rename4(temporary, target);
|