minimal-forge-work-pack-sync 0.1.56 → 0.1.58
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 +932 -416
- package/dist/python.js +771 -0
- package/dist/repair.js +26 -3
- package/package.json +4 -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, path18) {
|
|
121
|
+
const ctrl = callVisitor(key, node, visitor, path18);
|
|
122
122
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
123
|
-
replaceNode(key,
|
|
124
|
-
return visit_(key, ctrl, visitor,
|
|
123
|
+
replaceNode(key, path18, ctrl);
|
|
124
|
+
return visit_(key, ctrl, visitor, path18);
|
|
125
125
|
}
|
|
126
126
|
if (typeof ctrl !== "symbol") {
|
|
127
127
|
if (identity.isCollection(node)) {
|
|
128
|
-
|
|
128
|
+
path18 = Object.freeze(path18.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, path18);
|
|
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
|
+
path18 = Object.freeze(path18.concat(node));
|
|
142
|
+
const ck = visit_("key", node.key, visitor, path18);
|
|
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, path18);
|
|
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, path18) {
|
|
169
|
+
const ctrl = await callVisitor(key, node, visitor, path18);
|
|
170
170
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
171
|
-
replaceNode(key,
|
|
172
|
-
return visitAsync_(key, ctrl, visitor,
|
|
171
|
+
replaceNode(key, path18, ctrl);
|
|
172
|
+
return visitAsync_(key, ctrl, visitor, path18);
|
|
173
173
|
}
|
|
174
174
|
if (typeof ctrl !== "symbol") {
|
|
175
175
|
if (identity.isCollection(node)) {
|
|
176
|
-
|
|
176
|
+
path18 = Object.freeze(path18.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, path18);
|
|
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
|
+
path18 = Object.freeze(path18.concat(node));
|
|
190
|
+
const ck = await visitAsync_("key", node.key, visitor, path18);
|
|
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, path18);
|
|
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, path18) {
|
|
223
223
|
if (typeof visitor === "function")
|
|
224
|
-
return visitor(key, node,
|
|
224
|
+
return visitor(key, node, path18);
|
|
225
225
|
if (identity.isMap(node))
|
|
226
|
-
return visitor.Map?.(key, node,
|
|
226
|
+
return visitor.Map?.(key, node, path18);
|
|
227
227
|
if (identity.isSeq(node))
|
|
228
|
-
return visitor.Seq?.(key, node,
|
|
228
|
+
return visitor.Seq?.(key, node, path18);
|
|
229
229
|
if (identity.isPair(node))
|
|
230
|
-
return visitor.Pair?.(key, node,
|
|
230
|
+
return visitor.Pair?.(key, node, path18);
|
|
231
231
|
if (identity.isScalar(node))
|
|
232
|
-
return visitor.Scalar?.(key, node,
|
|
232
|
+
return visitor.Scalar?.(key, node, path18);
|
|
233
233
|
if (identity.isAlias(node))
|
|
234
|
-
return visitor.Alias?.(key, node,
|
|
234
|
+
return visitor.Alias?.(key, node, path18);
|
|
235
235
|
return void 0;
|
|
236
236
|
}
|
|
237
|
-
function replaceNode(key,
|
|
238
|
-
const parent =
|
|
237
|
+
function replaceNode(key, path18, node) {
|
|
238
|
+
const parent = path18[path18.length - 1];
|
|
239
239
|
if (identity.isCollection(parent)) {
|
|
240
240
|
parent.items[key] = node;
|
|
241
241
|
} else if (identity.isPair(parent)) {
|
|
@@ -847,10 +847,10 @@ var require_Collection = __commonJS({
|
|
|
847
847
|
var createNode = require_createNode();
|
|
848
848
|
var identity = require_identity();
|
|
849
849
|
var Node = require_Node();
|
|
850
|
-
function collectionFromPath(schema,
|
|
850
|
+
function collectionFromPath(schema, path18, value) {
|
|
851
851
|
let v2 = value;
|
|
852
|
-
for (let i =
|
|
853
|
-
const k2 =
|
|
852
|
+
for (let i = path18.length - 1; i >= 0; --i) {
|
|
853
|
+
const k2 = path18[i];
|
|
854
854
|
if (typeof k2 === "number" && Number.isInteger(k2) && k2 >= 0) {
|
|
855
855
|
const a = [];
|
|
856
856
|
a[k2] = v2;
|
|
@@ -869,7 +869,7 @@ var require_Collection = __commonJS({
|
|
|
869
869
|
sourceObjects: /* @__PURE__ */ new Map()
|
|
870
870
|
});
|
|
871
871
|
}
|
|
872
|
-
var isEmptyPath = (
|
|
872
|
+
var isEmptyPath = (path18) => path18 == null || typeof path18 === "object" && !!path18[Symbol.iterator]().next().done;
|
|
873
873
|
var Collection = class extends Node.NodeBase {
|
|
874
874
|
constructor(type, schema) {
|
|
875
875
|
super(type);
|
|
@@ -899,11 +899,11 @@ var require_Collection = __commonJS({
|
|
|
899
899
|
* be a Pair instance or a `{ key, value }` object, which may not have a key
|
|
900
900
|
* that already exists in the map.
|
|
901
901
|
*/
|
|
902
|
-
addIn(
|
|
903
|
-
if (isEmptyPath(
|
|
902
|
+
addIn(path18, value) {
|
|
903
|
+
if (isEmptyPath(path18))
|
|
904
904
|
this.add(value);
|
|
905
905
|
else {
|
|
906
|
-
const [key, ...rest] =
|
|
906
|
+
const [key, ...rest] = path18;
|
|
907
907
|
const node = this.get(key, true);
|
|
908
908
|
if (identity.isCollection(node))
|
|
909
909
|
node.addIn(rest, value);
|
|
@@ -917,8 +917,8 @@ var require_Collection = __commonJS({
|
|
|
917
917
|
* Removes a value from the collection.
|
|
918
918
|
* @returns `true` if the item was found and removed.
|
|
919
919
|
*/
|
|
920
|
-
deleteIn(
|
|
921
|
-
const [key, ...rest] =
|
|
920
|
+
deleteIn(path18) {
|
|
921
|
+
const [key, ...rest] = path18;
|
|
922
922
|
if (rest.length === 0)
|
|
923
923
|
return this.delete(key);
|
|
924
924
|
const node = this.get(key, true);
|
|
@@ -932,8 +932,8 @@ var require_Collection = __commonJS({
|
|
|
932
932
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
933
933
|
* `true` (collections are always returned intact).
|
|
934
934
|
*/
|
|
935
|
-
getIn(
|
|
936
|
-
const [key, ...rest] =
|
|
935
|
+
getIn(path18, keepScalar) {
|
|
936
|
+
const [key, ...rest] = path18;
|
|
937
937
|
const node = this.get(key, true);
|
|
938
938
|
if (rest.length === 0)
|
|
939
939
|
return !keepScalar && identity.isScalar(node) ? node.value : node;
|
|
@@ -951,8 +951,8 @@ var require_Collection = __commonJS({
|
|
|
951
951
|
/**
|
|
952
952
|
* Checks if the collection includes a value with the key `key`.
|
|
953
953
|
*/
|
|
954
|
-
hasIn(
|
|
955
|
-
const [key, ...rest] =
|
|
954
|
+
hasIn(path18) {
|
|
955
|
+
const [key, ...rest] = path18;
|
|
956
956
|
if (rest.length === 0)
|
|
957
957
|
return this.has(key);
|
|
958
958
|
const node = this.get(key, true);
|
|
@@ -962,8 +962,8 @@ var require_Collection = __commonJS({
|
|
|
962
962
|
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
963
963
|
* boolean to add/remove the item from the set.
|
|
964
964
|
*/
|
|
965
|
-
setIn(
|
|
966
|
-
const [key, ...rest] =
|
|
965
|
+
setIn(path18, value) {
|
|
966
|
+
const [key, ...rest] = path18;
|
|
967
967
|
if (rest.length === 0) {
|
|
968
968
|
this.set(key, value);
|
|
969
969
|
} else {
|
|
@@ -3478,9 +3478,9 @@ var require_Document = __commonJS({
|
|
|
3478
3478
|
this.contents.add(value);
|
|
3479
3479
|
}
|
|
3480
3480
|
/** Adds a value to the document. */
|
|
3481
|
-
addIn(
|
|
3481
|
+
addIn(path18, value) {
|
|
3482
3482
|
if (assertCollection(this.contents))
|
|
3483
|
-
this.contents.addIn(
|
|
3483
|
+
this.contents.addIn(path18, value);
|
|
3484
3484
|
}
|
|
3485
3485
|
/**
|
|
3486
3486
|
* Create a new `Alias` node, ensuring that the target `node` has the required anchor.
|
|
@@ -3555,14 +3555,14 @@ var require_Document = __commonJS({
|
|
|
3555
3555
|
* Removes a value from the document.
|
|
3556
3556
|
* @returns `true` if the item was found and removed.
|
|
3557
3557
|
*/
|
|
3558
|
-
deleteIn(
|
|
3559
|
-
if (Collection.isEmptyPath(
|
|
3558
|
+
deleteIn(path18) {
|
|
3559
|
+
if (Collection.isEmptyPath(path18)) {
|
|
3560
3560
|
if (this.contents == null)
|
|
3561
3561
|
return false;
|
|
3562
3562
|
this.contents = null;
|
|
3563
3563
|
return true;
|
|
3564
3564
|
}
|
|
3565
|
-
return assertCollection(this.contents) ? this.contents.deleteIn(
|
|
3565
|
+
return assertCollection(this.contents) ? this.contents.deleteIn(path18) : false;
|
|
3566
3566
|
}
|
|
3567
3567
|
/**
|
|
3568
3568
|
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
@@ -3577,10 +3577,10 @@ var require_Document = __commonJS({
|
|
|
3577
3577
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
3578
3578
|
* `true` (collections are always returned intact).
|
|
3579
3579
|
*/
|
|
3580
|
-
getIn(
|
|
3581
|
-
if (Collection.isEmptyPath(
|
|
3580
|
+
getIn(path18, keepScalar) {
|
|
3581
|
+
if (Collection.isEmptyPath(path18))
|
|
3582
3582
|
return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
|
|
3583
|
-
return identity.isCollection(this.contents) ? this.contents.getIn(
|
|
3583
|
+
return identity.isCollection(this.contents) ? this.contents.getIn(path18, keepScalar) : void 0;
|
|
3584
3584
|
}
|
|
3585
3585
|
/**
|
|
3586
3586
|
* Checks if the document includes a value with the key `key`.
|
|
@@ -3591,10 +3591,10 @@ var require_Document = __commonJS({
|
|
|
3591
3591
|
/**
|
|
3592
3592
|
* Checks if the document includes a value at `path`.
|
|
3593
3593
|
*/
|
|
3594
|
-
hasIn(
|
|
3595
|
-
if (Collection.isEmptyPath(
|
|
3594
|
+
hasIn(path18) {
|
|
3595
|
+
if (Collection.isEmptyPath(path18))
|
|
3596
3596
|
return this.contents !== void 0;
|
|
3597
|
-
return identity.isCollection(this.contents) ? this.contents.hasIn(
|
|
3597
|
+
return identity.isCollection(this.contents) ? this.contents.hasIn(path18) : false;
|
|
3598
3598
|
}
|
|
3599
3599
|
/**
|
|
3600
3600
|
* Sets a value in this document. For `!!set`, `value` needs to be a
|
|
@@ -3611,13 +3611,13 @@ var require_Document = __commonJS({
|
|
|
3611
3611
|
* Sets a value in this document. For `!!set`, `value` needs to be a
|
|
3612
3612
|
* boolean to add/remove the item from the set.
|
|
3613
3613
|
*/
|
|
3614
|
-
setIn(
|
|
3615
|
-
if (Collection.isEmptyPath(
|
|
3614
|
+
setIn(path18, value) {
|
|
3615
|
+
if (Collection.isEmptyPath(path18)) {
|
|
3616
3616
|
this.contents = value;
|
|
3617
3617
|
} else if (this.contents == null) {
|
|
3618
|
-
this.contents = Collection.collectionFromPath(this.schema, Array.from(
|
|
3618
|
+
this.contents = Collection.collectionFromPath(this.schema, Array.from(path18), value);
|
|
3619
3619
|
} else if (assertCollection(this.contents)) {
|
|
3620
|
-
this.contents.setIn(
|
|
3620
|
+
this.contents.setIn(path18, value);
|
|
3621
3621
|
}
|
|
3622
3622
|
}
|
|
3623
3623
|
/**
|
|
@@ -5578,9 +5578,9 @@ var require_cst_visit = __commonJS({
|
|
|
5578
5578
|
visit.BREAK = BREAK;
|
|
5579
5579
|
visit.SKIP = SKIP;
|
|
5580
5580
|
visit.REMOVE = REMOVE;
|
|
5581
|
-
visit.itemAtPath = (cst,
|
|
5581
|
+
visit.itemAtPath = (cst, path18) => {
|
|
5582
5582
|
let item = cst;
|
|
5583
|
-
for (const [field, index] of
|
|
5583
|
+
for (const [field, index] of path18) {
|
|
5584
5584
|
const tok = item?.[field];
|
|
5585
5585
|
if (tok && "items" in tok) {
|
|
5586
5586
|
item = tok.items[index];
|
|
@@ -5589,23 +5589,23 @@ var require_cst_visit = __commonJS({
|
|
|
5589
5589
|
}
|
|
5590
5590
|
return item;
|
|
5591
5591
|
};
|
|
5592
|
-
visit.parentCollection = (cst,
|
|
5593
|
-
const parent = visit.itemAtPath(cst,
|
|
5594
|
-
const field =
|
|
5592
|
+
visit.parentCollection = (cst, path18) => {
|
|
5593
|
+
const parent = visit.itemAtPath(cst, path18.slice(0, -1));
|
|
5594
|
+
const field = path18[path18.length - 1][0];
|
|
5595
5595
|
const coll = parent?.[field];
|
|
5596
5596
|
if (coll && "items" in coll)
|
|
5597
5597
|
return coll;
|
|
5598
5598
|
throw new Error("Parent collection not found");
|
|
5599
5599
|
};
|
|
5600
|
-
function _visit(
|
|
5601
|
-
let ctrl = visitor(item,
|
|
5600
|
+
function _visit(path18, item, visitor) {
|
|
5601
|
+
let ctrl = visitor(item, path18);
|
|
5602
5602
|
if (typeof ctrl === "symbol")
|
|
5603
5603
|
return ctrl;
|
|
5604
5604
|
for (const field of ["key", "value"]) {
|
|
5605
5605
|
const token = item[field];
|
|
5606
5606
|
if (token && "items" in token) {
|
|
5607
5607
|
for (let i = 0; i < token.items.length; ++i) {
|
|
5608
|
-
const ci2 = _visit(Object.freeze(
|
|
5608
|
+
const ci2 = _visit(Object.freeze(path18.concat([[field, i]])), token.items[i], visitor);
|
|
5609
5609
|
if (typeof ci2 === "number")
|
|
5610
5610
|
i = ci2 - 1;
|
|
5611
5611
|
else if (ci2 === BREAK)
|
|
@@ -5616,10 +5616,10 @@ var require_cst_visit = __commonJS({
|
|
|
5616
5616
|
}
|
|
5617
5617
|
}
|
|
5618
5618
|
if (typeof ctrl === "function" && field === "key")
|
|
5619
|
-
ctrl = ctrl(item,
|
|
5619
|
+
ctrl = ctrl(item, path18);
|
|
5620
5620
|
}
|
|
5621
5621
|
}
|
|
5622
|
-
return typeof ctrl === "function" ? ctrl(item,
|
|
5622
|
+
return typeof ctrl === "function" ? ctrl(item, path18) : ctrl;
|
|
5623
5623
|
}
|
|
5624
5624
|
exports.visit = visit;
|
|
5625
5625
|
}
|
|
@@ -7615,12 +7615,14 @@ var WORKER_FEEDBACK_MAX_MESSAGE_LENGTH = 24e3;
|
|
|
7615
7615
|
// packages/shared/src/contracts/settings.ts
|
|
7616
7616
|
var DOCUMENT_READER_AGENT = "document-reader";
|
|
7617
7617
|
var OPENROUTER_ALIAS_PROVIDER_NAME = "OpenRouter (via Forge)";
|
|
7618
|
-
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.
|
|
7618
|
+
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.58";
|
|
7619
7619
|
var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
|
|
7620
7620
|
var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
|
|
7621
7621
|
var FIRECRAWL_KEYLESS_MCP_NAME = "firecrawl";
|
|
7622
7622
|
var FIRECRAWL_KEYLESS_MCP_URL = "https://mcp.firecrawl.dev/v2/mcp";
|
|
7623
7623
|
var FIRECRAWL_KEYLESS_PERMISSION = `${FIRECRAWL_KEYLESS_MCP_NAME}_*`;
|
|
7624
|
+
var COMPUTER_USE_NATIVE_PERMISSION = "computer_*";
|
|
7625
|
+
var COMPUTER_USE_MCP_PERMISSION = "computer-use_*";
|
|
7624
7626
|
function mergeWorkerOpenCodeConfig(existing, manifest, forgeBaseUrl, forgeApiKey = "{env:FORGE_API_KEY}", options = {}) {
|
|
7625
7627
|
const existingProvider = withoutLegacyForgeProviders(isRecord(existing.provider) ? existing.provider : {});
|
|
7626
7628
|
const nextConfig = {
|
|
@@ -7715,11 +7717,32 @@ function targetWorkPackSyncPluginVersion(manifest, existing) {
|
|
|
7715
7717
|
}
|
|
7716
7718
|
return configuredWorkPackSyncPluginVersion(existing) ?? WORK_PACK_SYNC_PLUGIN_VERSION;
|
|
7717
7719
|
}
|
|
7720
|
+
function managedComputerUseRule(rule) {
|
|
7721
|
+
if (rule === "deny") return "deny";
|
|
7722
|
+
if (isRecord(rule)) {
|
|
7723
|
+
const normalized = {};
|
|
7724
|
+
for (const [pattern, action] of Object.entries(rule)) {
|
|
7725
|
+
normalized[pattern] = action === "allow" ? "ask" : action;
|
|
7726
|
+
}
|
|
7727
|
+
return "*" in normalized ? normalized : { "*": "ask", ...normalized };
|
|
7728
|
+
}
|
|
7729
|
+
return "ask";
|
|
7730
|
+
}
|
|
7718
7731
|
function managedPermission(value) {
|
|
7719
7732
|
const existing = typeof value === "string" && ["allow", "ask", "deny"].includes(value) ? { "*": value } : isRecord(value) ? value : {};
|
|
7733
|
+
const denyAll = existing["*"] === "deny";
|
|
7734
|
+
const rest = {};
|
|
7735
|
+
for (const [key, entry] of Object.entries(existing)) {
|
|
7736
|
+
if (!denyAll && (key === COMPUTER_USE_NATIVE_PERMISSION || key === COMPUTER_USE_MCP_PERMISSION)) continue;
|
|
7737
|
+
rest[key] = entry;
|
|
7738
|
+
}
|
|
7720
7739
|
return {
|
|
7721
|
-
...
|
|
7722
|
-
...
|
|
7740
|
+
...denyAll ? {} : { [FIRECRAWL_KEYLESS_PERMISSION]: "ask" },
|
|
7741
|
+
...rest,
|
|
7742
|
+
...denyAll ? {} : {
|
|
7743
|
+
[COMPUTER_USE_NATIVE_PERMISSION]: managedComputerUseRule(existing[COMPUTER_USE_NATIVE_PERMISSION]),
|
|
7744
|
+
[COMPUTER_USE_MCP_PERMISSION]: managedComputerUseRule(existing[COMPUTER_USE_MCP_PERMISSION])
|
|
7745
|
+
},
|
|
7723
7746
|
forge_decide: "allow",
|
|
7724
7747
|
forge_decide_run: "allow",
|
|
7725
7748
|
forge_generate_codebook: "allow",
|
|
@@ -7770,6 +7793,20 @@ function normalizeGatewayBaseUrl(value) {
|
|
|
7770
7793
|
return url2.origin;
|
|
7771
7794
|
}
|
|
7772
7795
|
|
|
7796
|
+
// packages/shared/src/pythonRequirements.ts
|
|
7797
|
+
var PYTHON_REQUIREMENTS = [
|
|
7798
|
+
{ name: "pandas", importName: "pandas", requirement: "pandas>=2.1,<3" },
|
|
7799
|
+
{ name: "numpy", importName: "numpy", requirement: "numpy>=1.26,<3" },
|
|
7800
|
+
{ name: "scipy", importName: "scipy", requirement: "scipy>=1.11,<2" },
|
|
7801
|
+
{ name: "openpyxl", importName: "openpyxl", requirement: "openpyxl>=3.1,<4" },
|
|
7802
|
+
{ name: "pyreadstat", importName: "pyreadstat", requirement: "pyreadstat>=1.2,<2" },
|
|
7803
|
+
{ name: "python-docx", importName: "docx", requirement: "python-docx>=1.1,<2" },
|
|
7804
|
+
{ name: "python-pptx", importName: "pptx", requirement: "python-pptx>=1,<2" },
|
|
7805
|
+
{ name: "pypdf", importName: "pypdf", requirement: "pypdf>=5,<8" },
|
|
7806
|
+
{ name: "PyYAML", importName: "yaml", requirement: "PyYAML>=6,<7" },
|
|
7807
|
+
{ name: "Pillow", importName: "PIL", requirement: "Pillow>=10,<13" }
|
|
7808
|
+
];
|
|
7809
|
+
|
|
7773
7810
|
// packages/shared/src/workPackBaseline.ts
|
|
7774
7811
|
function normalizePackExtensionModel(pathLabel, content, approvedModelIds, slug) {
|
|
7775
7812
|
return normalizeExtensionModel(pathLabel, content, slug, (modelId) => approvedModelIds.has(modelId));
|
|
@@ -7882,12 +7919,12 @@ async function projectCurrentExtensions(config2, state) {
|
|
|
7882
7919
|
config2.agent = agents;
|
|
7883
7920
|
config2.command = commands;
|
|
7884
7921
|
}
|
|
7885
|
-
async function refreshPartialProjections(config2, previous, paths, before,
|
|
7922
|
+
async function refreshPartialProjections(config2, previous, paths, before, result2) {
|
|
7886
7923
|
const existing = objectRecord(previous);
|
|
7887
7924
|
const agents = objectRecord(existing.agent);
|
|
7888
7925
|
const commands = objectRecord(existing.command);
|
|
7889
7926
|
if (!before.agents.has(DOCUMENT_READER_AGENT)) delete agents[DOCUMENT_READER_AGENT];
|
|
7890
|
-
for (const file2 of
|
|
7927
|
+
for (const file2 of result2.removedManagedPaths) {
|
|
7891
7928
|
if (path.extname(file2) !== ".md") continue;
|
|
7892
7929
|
const directory = path.dirname(file2);
|
|
7893
7930
|
const name = path.basename(file2, ".md");
|
|
@@ -7896,7 +7933,7 @@ async function refreshPartialProjections(config2, previous, paths, before, resul
|
|
|
7896
7933
|
}
|
|
7897
7934
|
config2.agent = { ...objectRecord(config2.agent), ...agents };
|
|
7898
7935
|
config2.command = commands;
|
|
7899
|
-
const confirmed = new Set(
|
|
7936
|
+
const confirmed = new Set(result2.workPacks.outcomes.filter(
|
|
7900
7937
|
({ action, status }) => action === "install" && (status === "installed" || status === "unchanged")
|
|
7901
7938
|
).map(({ slug }) => slug));
|
|
7902
7939
|
await projectInstalledExtensions(config2, paths, confirmed);
|
|
@@ -7997,12 +8034,12 @@ async function protectOwnerOnlyPath(filePath, kind, options = {}) {
|
|
|
7997
8034
|
}
|
|
7998
8035
|
const spawn = options.spawnSync ?? nodeSpawnSync;
|
|
7999
8036
|
const command = kind === "directory" ? "$ErrorActionPreference = 'Stop'; $path = [Console]::In.ReadToEnd(); $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().User; $acl = [System.Security.AccessControl.DirectorySecurity]::new(); $acl.SetAccessRuleProtection($true, $false); $inheritance = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit; $rule = [System.Security.AccessControl.FileSystemAccessRule]::new($identity, [System.Security.AccessControl.FileSystemRights]::FullControl, $inheritance, [System.Security.AccessControl.PropagationFlags]::None, [System.Security.AccessControl.AccessControlType]::Allow); [void]$acl.AddAccessRule($rule); [System.IO.Directory]::SetAccessControl($path, $acl)" : "$ErrorActionPreference = 'Stop'; $path = [Console]::In.ReadToEnd(); $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().User; $acl = [System.Security.AccessControl.FileSecurity]::new(); $acl.SetAccessRuleProtection($true, $false); $rule = [System.Security.AccessControl.FileSystemAccessRule]::new($identity, [System.Security.AccessControl.FileSystemRights]::FullControl, [System.Security.AccessControl.AccessControlType]::Allow); [void]$acl.AddAccessRule($rule); [System.IO.File]::SetAccessControl($path, $acl)";
|
|
8000
|
-
const
|
|
8037
|
+
const result2 = spawn("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", command], {
|
|
8001
8038
|
encoding: "utf8",
|
|
8002
8039
|
input: filePath
|
|
8003
8040
|
});
|
|
8004
|
-
if (
|
|
8005
|
-
const detail = typeof
|
|
8041
|
+
if (result2.status !== 0) {
|
|
8042
|
+
const detail = typeof result2.stderr === "string" ? result2.stderr.trim().replace(/\s+/g, " ").slice(0, 500) : "";
|
|
8006
8043
|
const context = options.failureContext ?? (kind === "directory" ? "o diret\xF3rio" : "o ficheiro");
|
|
8007
8044
|
throw new Error(`N\xE3o foi poss\xEDvel proteger ${context} em ${filePath}${detail ? `: ${detail}` : ""}`);
|
|
8008
8045
|
}
|
|
@@ -8020,12 +8057,12 @@ async function assertExistingDirectoryIsSafe(directory, options) {
|
|
|
8020
8057
|
}
|
|
8021
8058
|
const spawn = options.spawnSync ?? nodeSpawnSync;
|
|
8022
8059
|
const command = "$ErrorActionPreference = 'Stop'; $path = [Console]::In.ReadToEnd(); $current = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value; $trusted = @($current, 'S-1-5-18', 'S-1-5-32-544'); $dangerous = [System.Security.AccessControl.FileSystemRights]::Write -bor [System.Security.AccessControl.FileSystemRights]::Delete -bor [System.Security.AccessControl.FileSystemRights]::DeleteSubdirectoriesAndFiles -bor [System.Security.AccessControl.FileSystemRights]::ChangePermissions -bor [System.Security.AccessControl.FileSystemRights]::TakeOwnership; $acl = [System.IO.Directory]::GetAccessControl($path); $rules = $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier]); foreach ($rule in $rules) { if ($rule.AccessControlType -eq [System.Security.AccessControl.AccessControlType]::Allow -and $rule.PropagationFlags -ne [System.Security.AccessControl.PropagationFlags]::InheritOnly -and ($rule.FileSystemRights -band $dangerous) -ne 0 -and $trusted -notcontains $rule.IdentityReference.Value) { throw ('O diret\xF3rio permite escrita por ' + $rule.IdentityReference.Value) } }";
|
|
8023
|
-
const
|
|
8060
|
+
const result2 = spawn("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", command], {
|
|
8024
8061
|
encoding: "utf8",
|
|
8025
8062
|
input: directory
|
|
8026
8063
|
});
|
|
8027
|
-
if (
|
|
8028
|
-
const detail = typeof
|
|
8064
|
+
if (result2.status !== 0) {
|
|
8065
|
+
const detail = typeof result2.stderr === "string" ? result2.stderr.trim().replace(/\s+/g, " ").slice(0, 500) : "";
|
|
8029
8066
|
throw new Error(`O diret\xF3rio existente ${directory} n\xE3o \xE9 controlado apenas pelo utilizador atual${detail ? `: ${detail}` : ""}`);
|
|
8030
8067
|
}
|
|
8031
8068
|
}
|
|
@@ -8069,7 +8106,7 @@ async function writeOwnerOnlyTextAtomic(filePath, content, options = {}) {
|
|
|
8069
8106
|
}
|
|
8070
8107
|
|
|
8071
8108
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
8072
|
-
import { createHash as
|
|
8109
|
+
import { createHash as createHash10, randomUUID as randomUUID6 } from "node:crypto";
|
|
8073
8110
|
import { pathToFileURL } from "node:url";
|
|
8074
8111
|
|
|
8075
8112
|
// packages/cli/src/skillUsageReporter.ts
|
|
@@ -9310,10 +9347,10 @@ function mergeDefs(...defs) {
|
|
|
9310
9347
|
function cloneDef(schema) {
|
|
9311
9348
|
return mergeDefs(schema._zod.def);
|
|
9312
9349
|
}
|
|
9313
|
-
function getElementAtPath(obj,
|
|
9314
|
-
if (!
|
|
9350
|
+
function getElementAtPath(obj, path18) {
|
|
9351
|
+
if (!path18)
|
|
9315
9352
|
return obj;
|
|
9316
|
-
return
|
|
9353
|
+
return path18.reduce((acc, key) => acc?.[key], obj);
|
|
9317
9354
|
}
|
|
9318
9355
|
function promiseAllObject(promisesObj) {
|
|
9319
9356
|
const keys = Object.keys(promisesObj);
|
|
@@ -9674,11 +9711,11 @@ function aborted(x, startIndex = 0) {
|
|
|
9674
9711
|
}
|
|
9675
9712
|
return false;
|
|
9676
9713
|
}
|
|
9677
|
-
function prefixIssues(
|
|
9714
|
+
function prefixIssues(path18, issues) {
|
|
9678
9715
|
return issues.map((iss) => {
|
|
9679
9716
|
var _a;
|
|
9680
9717
|
(_a = iss).path ?? (_a.path = []);
|
|
9681
|
-
iss.path.unshift(
|
|
9718
|
+
iss.path.unshift(path18);
|
|
9682
9719
|
return iss;
|
|
9683
9720
|
});
|
|
9684
9721
|
}
|
|
@@ -9845,8 +9882,8 @@ function treeifyError(error45, _mapper) {
|
|
|
9845
9882
|
const mapper = _mapper || function(issue2) {
|
|
9846
9883
|
return issue2.message;
|
|
9847
9884
|
};
|
|
9848
|
-
const
|
|
9849
|
-
const processError = (error46,
|
|
9885
|
+
const result2 = { errors: [] };
|
|
9886
|
+
const processError = (error46, path18 = []) => {
|
|
9850
9887
|
var _a, _b;
|
|
9851
9888
|
for (const issue2 of error46.issues) {
|
|
9852
9889
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
@@ -9856,12 +9893,12 @@ function treeifyError(error45, _mapper) {
|
|
|
9856
9893
|
} else if (issue2.code === "invalid_element") {
|
|
9857
9894
|
processError({ issues: issue2.issues }, issue2.path);
|
|
9858
9895
|
} else {
|
|
9859
|
-
const fullpath = [...
|
|
9896
|
+
const fullpath = [...path18, ...issue2.path];
|
|
9860
9897
|
if (fullpath.length === 0) {
|
|
9861
|
-
|
|
9898
|
+
result2.errors.push(mapper(issue2));
|
|
9862
9899
|
continue;
|
|
9863
9900
|
}
|
|
9864
|
-
let curr =
|
|
9901
|
+
let curr = result2;
|
|
9865
9902
|
let i = 0;
|
|
9866
9903
|
while (i < fullpath.length) {
|
|
9867
9904
|
const el = fullpath[i];
|
|
@@ -9884,12 +9921,12 @@ function treeifyError(error45, _mapper) {
|
|
|
9884
9921
|
}
|
|
9885
9922
|
};
|
|
9886
9923
|
processError(error45);
|
|
9887
|
-
return
|
|
9924
|
+
return result2;
|
|
9888
9925
|
}
|
|
9889
9926
|
function toDotPath(_path) {
|
|
9890
9927
|
const segs = [];
|
|
9891
|
-
const
|
|
9892
|
-
for (const seg of
|
|
9928
|
+
const path18 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
9929
|
+
for (const seg of path18) {
|
|
9893
9930
|
if (typeof seg === "number")
|
|
9894
9931
|
segs.push(`[${seg}]`);
|
|
9895
9932
|
else if (typeof seg === "symbol")
|
|
@@ -9918,52 +9955,52 @@ function prettifyError(error45) {
|
|
|
9918
9955
|
// node_modules/@opencode-ai/plugin/node_modules/zod/v4/core/parse.js
|
|
9919
9956
|
var _parse = (_Err) => (schema, value, _ctx, _params) => {
|
|
9920
9957
|
const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
|
|
9921
|
-
const
|
|
9922
|
-
if (
|
|
9958
|
+
const result2 = schema._zod.run({ value, issues: [] }, ctx);
|
|
9959
|
+
if (result2 instanceof Promise) {
|
|
9923
9960
|
throw new $ZodAsyncError();
|
|
9924
9961
|
}
|
|
9925
|
-
if (
|
|
9926
|
-
const e = new (_params?.Err ?? _Err)(
|
|
9962
|
+
if (result2.issues.length) {
|
|
9963
|
+
const e = new (_params?.Err ?? _Err)(result2.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
9927
9964
|
captureStackTrace(e, _params?.callee);
|
|
9928
9965
|
throw e;
|
|
9929
9966
|
}
|
|
9930
|
-
return
|
|
9967
|
+
return result2.value;
|
|
9931
9968
|
};
|
|
9932
9969
|
var parse = /* @__PURE__ */ _parse($ZodRealError);
|
|
9933
9970
|
var _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
|
|
9934
9971
|
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
9935
|
-
let
|
|
9936
|
-
if (
|
|
9937
|
-
|
|
9938
|
-
if (
|
|
9939
|
-
const e = new (params?.Err ?? _Err)(
|
|
9972
|
+
let result2 = schema._zod.run({ value, issues: [] }, ctx);
|
|
9973
|
+
if (result2 instanceof Promise)
|
|
9974
|
+
result2 = await result2;
|
|
9975
|
+
if (result2.issues.length) {
|
|
9976
|
+
const e = new (params?.Err ?? _Err)(result2.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
9940
9977
|
captureStackTrace(e, params?.callee);
|
|
9941
9978
|
throw e;
|
|
9942
9979
|
}
|
|
9943
|
-
return
|
|
9980
|
+
return result2.value;
|
|
9944
9981
|
};
|
|
9945
9982
|
var parseAsync = /* @__PURE__ */ _parseAsync($ZodRealError);
|
|
9946
9983
|
var _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
9947
9984
|
const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
|
|
9948
|
-
const
|
|
9949
|
-
if (
|
|
9985
|
+
const result2 = schema._zod.run({ value, issues: [] }, ctx);
|
|
9986
|
+
if (result2 instanceof Promise) {
|
|
9950
9987
|
throw new $ZodAsyncError();
|
|
9951
9988
|
}
|
|
9952
|
-
return
|
|
9989
|
+
return result2.issues.length ? {
|
|
9953
9990
|
success: false,
|
|
9954
|
-
error: new (_Err ?? $ZodError)(
|
|
9955
|
-
} : { success: true, data:
|
|
9991
|
+
error: new (_Err ?? $ZodError)(result2.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
9992
|
+
} : { success: true, data: result2.value };
|
|
9956
9993
|
};
|
|
9957
9994
|
var safeParse = /* @__PURE__ */ _safeParse($ZodRealError);
|
|
9958
9995
|
var _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
9959
9996
|
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
9960
|
-
let
|
|
9961
|
-
if (
|
|
9962
|
-
|
|
9963
|
-
return
|
|
9997
|
+
let result2 = schema._zod.run({ value, issues: [] }, ctx);
|
|
9998
|
+
if (result2 instanceof Promise)
|
|
9999
|
+
result2 = await result2;
|
|
10000
|
+
return result2.issues.length ? {
|
|
9964
10001
|
success: false,
|
|
9965
|
-
error: new _Err(
|
|
9966
|
-
} : { success: true, data:
|
|
10002
|
+
error: new _Err(result2.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
10003
|
+
} : { success: true, data: result2.value };
|
|
9967
10004
|
};
|
|
9968
10005
|
var safeParseAsync = /* @__PURE__ */ _safeParseAsync($ZodRealError);
|
|
9969
10006
|
var _encode = (_Err) => (schema, value, _ctx) => {
|
|
@@ -10653,22 +10690,22 @@ var $ZodCheckEndsWith = /* @__PURE__ */ $constructor("$ZodCheckEndsWith", (inst,
|
|
|
10653
10690
|
});
|
|
10654
10691
|
};
|
|
10655
10692
|
});
|
|
10656
|
-
function handleCheckPropertyResult(
|
|
10657
|
-
if (
|
|
10658
|
-
payload.issues.push(...prefixIssues(property,
|
|
10693
|
+
function handleCheckPropertyResult(result2, payload, property) {
|
|
10694
|
+
if (result2.issues.length) {
|
|
10695
|
+
payload.issues.push(...prefixIssues(property, result2.issues));
|
|
10659
10696
|
}
|
|
10660
10697
|
}
|
|
10661
10698
|
var $ZodCheckProperty = /* @__PURE__ */ $constructor("$ZodCheckProperty", (inst, def) => {
|
|
10662
10699
|
$ZodCheck.init(inst, def);
|
|
10663
10700
|
inst._zod.check = (payload) => {
|
|
10664
|
-
const
|
|
10701
|
+
const result2 = def.schema._zod.run({
|
|
10665
10702
|
value: payload.value[def.property],
|
|
10666
10703
|
issues: []
|
|
10667
10704
|
}, {});
|
|
10668
|
-
if (
|
|
10669
|
-
return
|
|
10705
|
+
if (result2 instanceof Promise) {
|
|
10706
|
+
return result2.then((result3) => handleCheckPropertyResult(result3, payload, def.property));
|
|
10670
10707
|
}
|
|
10671
|
-
handleCheckPropertyResult(
|
|
10708
|
+
handleCheckPropertyResult(result2, payload, def.property);
|
|
10672
10709
|
return;
|
|
10673
10710
|
};
|
|
10674
10711
|
});
|
|
@@ -10828,13 +10865,13 @@ var $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
|
10828
10865
|
}
|
|
10829
10866
|
return handleCanaryResult(canary, payload, ctx);
|
|
10830
10867
|
}
|
|
10831
|
-
const
|
|
10832
|
-
if (
|
|
10868
|
+
const result2 = inst._zod.parse(payload, ctx);
|
|
10869
|
+
if (result2 instanceof Promise) {
|
|
10833
10870
|
if (ctx.async === false)
|
|
10834
10871
|
throw new $ZodAsyncError();
|
|
10835
|
-
return
|
|
10872
|
+
return result2.then((result3) => runChecks(result3, checks, ctx));
|
|
10836
10873
|
}
|
|
10837
|
-
return runChecks(
|
|
10874
|
+
return runChecks(result2, checks, ctx);
|
|
10838
10875
|
};
|
|
10839
10876
|
}
|
|
10840
10877
|
inst["~standard"] = {
|
|
@@ -11348,11 +11385,11 @@ var $ZodDate = /* @__PURE__ */ $constructor("$ZodDate", (inst, def) => {
|
|
|
11348
11385
|
return payload;
|
|
11349
11386
|
};
|
|
11350
11387
|
});
|
|
11351
|
-
function handleArrayResult(
|
|
11352
|
-
if (
|
|
11353
|
-
final.issues.push(...prefixIssues(index,
|
|
11388
|
+
function handleArrayResult(result2, final, index) {
|
|
11389
|
+
if (result2.issues.length) {
|
|
11390
|
+
final.issues.push(...prefixIssues(index, result2.issues));
|
|
11354
11391
|
}
|
|
11355
|
-
final.value[index] =
|
|
11392
|
+
final.value[index] = result2.value;
|
|
11356
11393
|
}
|
|
11357
11394
|
var $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
11358
11395
|
$ZodType.init(inst, def);
|
|
@@ -11371,14 +11408,14 @@ var $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
|
11371
11408
|
const proms = [];
|
|
11372
11409
|
for (let i = 0; i < input.length; i++) {
|
|
11373
11410
|
const item = input[i];
|
|
11374
|
-
const
|
|
11411
|
+
const result2 = def.element._zod.run({
|
|
11375
11412
|
value: item,
|
|
11376
11413
|
issues: []
|
|
11377
11414
|
}, ctx);
|
|
11378
|
-
if (
|
|
11379
|
-
proms.push(
|
|
11415
|
+
if (result2 instanceof Promise) {
|
|
11416
|
+
proms.push(result2.then((result3) => handleArrayResult(result3, payload, i)));
|
|
11380
11417
|
} else {
|
|
11381
|
-
handleArrayResult(
|
|
11418
|
+
handleArrayResult(result2, payload, i);
|
|
11382
11419
|
}
|
|
11383
11420
|
}
|
|
11384
11421
|
if (proms.length) {
|
|
@@ -11387,16 +11424,16 @@ var $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
|
11387
11424
|
return payload;
|
|
11388
11425
|
};
|
|
11389
11426
|
});
|
|
11390
|
-
function handlePropertyResult(
|
|
11391
|
-
if (
|
|
11392
|
-
final.issues.push(...prefixIssues(key,
|
|
11427
|
+
function handlePropertyResult(result2, final, key, input) {
|
|
11428
|
+
if (result2.issues.length) {
|
|
11429
|
+
final.issues.push(...prefixIssues(key, result2.issues));
|
|
11393
11430
|
}
|
|
11394
|
-
if (
|
|
11431
|
+
if (result2.value === void 0) {
|
|
11395
11432
|
if (key in input) {
|
|
11396
11433
|
final.value[key] = void 0;
|
|
11397
11434
|
}
|
|
11398
11435
|
} else {
|
|
11399
|
-
final.value[key] =
|
|
11436
|
+
final.value[key] = result2.value;
|
|
11400
11437
|
}
|
|
11401
11438
|
}
|
|
11402
11439
|
function normalizeDef(def) {
|
|
@@ -11574,9 +11611,9 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
11574
11611
|
};
|
|
11575
11612
|
});
|
|
11576
11613
|
function handleUnionResults(results, final, inst, ctx) {
|
|
11577
|
-
for (const
|
|
11578
|
-
if (
|
|
11579
|
-
final.value =
|
|
11614
|
+
for (const result2 of results) {
|
|
11615
|
+
if (result2.issues.length === 0) {
|
|
11616
|
+
final.value = result2.value;
|
|
11580
11617
|
return final;
|
|
11581
11618
|
}
|
|
11582
11619
|
}
|
|
@@ -11589,7 +11626,7 @@ function handleUnionResults(results, final, inst, ctx) {
|
|
|
11589
11626
|
code: "invalid_union",
|
|
11590
11627
|
input: final.value,
|
|
11591
11628
|
inst,
|
|
11592
|
-
errors: results.map((
|
|
11629
|
+
errors: results.map((result2) => result2.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
11593
11630
|
});
|
|
11594
11631
|
return final;
|
|
11595
11632
|
}
|
|
@@ -11619,17 +11656,17 @@ var $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
|
11619
11656
|
let async = false;
|
|
11620
11657
|
const results = [];
|
|
11621
11658
|
for (const option of def.options) {
|
|
11622
|
-
const
|
|
11659
|
+
const result2 = option._zod.run({
|
|
11623
11660
|
value: payload.value,
|
|
11624
11661
|
issues: []
|
|
11625
11662
|
}, ctx);
|
|
11626
|
-
if (
|
|
11627
|
-
results.push(
|
|
11663
|
+
if (result2 instanceof Promise) {
|
|
11664
|
+
results.push(result2);
|
|
11628
11665
|
async = true;
|
|
11629
11666
|
} else {
|
|
11630
|
-
if (
|
|
11631
|
-
return
|
|
11632
|
-
results.push(
|
|
11667
|
+
if (result2.issues.length === 0)
|
|
11668
|
+
return result2;
|
|
11669
|
+
results.push(result2);
|
|
11633
11670
|
}
|
|
11634
11671
|
}
|
|
11635
11672
|
if (!async)
|
|
@@ -11763,21 +11800,21 @@ function mergeValues(a, b2) {
|
|
|
11763
11800
|
}
|
|
11764
11801
|
return { valid: false, mergeErrorPath: [] };
|
|
11765
11802
|
}
|
|
11766
|
-
function handleIntersectionResults(
|
|
11803
|
+
function handleIntersectionResults(result2, left, right) {
|
|
11767
11804
|
if (left.issues.length) {
|
|
11768
|
-
|
|
11805
|
+
result2.issues.push(...left.issues);
|
|
11769
11806
|
}
|
|
11770
11807
|
if (right.issues.length) {
|
|
11771
|
-
|
|
11808
|
+
result2.issues.push(...right.issues);
|
|
11772
11809
|
}
|
|
11773
|
-
if (aborted(
|
|
11774
|
-
return
|
|
11810
|
+
if (aborted(result2))
|
|
11811
|
+
return result2;
|
|
11775
11812
|
const merged = mergeValues(left.value, right.value);
|
|
11776
11813
|
if (!merged.valid) {
|
|
11777
11814
|
throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
|
|
11778
11815
|
}
|
|
11779
|
-
|
|
11780
|
-
return
|
|
11816
|
+
result2.value = merged.data;
|
|
11817
|
+
return result2;
|
|
11781
11818
|
}
|
|
11782
11819
|
var $ZodTuple = /* @__PURE__ */ $constructor("$ZodTuple", (inst, def) => {
|
|
11783
11820
|
$ZodType.init(inst, def);
|
|
@@ -11816,28 +11853,28 @@ var $ZodTuple = /* @__PURE__ */ $constructor("$ZodTuple", (inst, def) => {
|
|
|
11816
11853
|
if (i >= optStart)
|
|
11817
11854
|
continue;
|
|
11818
11855
|
}
|
|
11819
|
-
const
|
|
11856
|
+
const result2 = item._zod.run({
|
|
11820
11857
|
value: input[i],
|
|
11821
11858
|
issues: []
|
|
11822
11859
|
}, ctx);
|
|
11823
|
-
if (
|
|
11824
|
-
proms.push(
|
|
11860
|
+
if (result2 instanceof Promise) {
|
|
11861
|
+
proms.push(result2.then((result3) => handleTupleResult(result3, payload, i)));
|
|
11825
11862
|
} else {
|
|
11826
|
-
handleTupleResult(
|
|
11863
|
+
handleTupleResult(result2, payload, i);
|
|
11827
11864
|
}
|
|
11828
11865
|
}
|
|
11829
11866
|
if (def.rest) {
|
|
11830
11867
|
const rest = input.slice(items.length);
|
|
11831
11868
|
for (const el of rest) {
|
|
11832
11869
|
i++;
|
|
11833
|
-
const
|
|
11870
|
+
const result2 = def.rest._zod.run({
|
|
11834
11871
|
value: el,
|
|
11835
11872
|
issues: []
|
|
11836
11873
|
}, ctx);
|
|
11837
|
-
if (
|
|
11838
|
-
proms.push(
|
|
11874
|
+
if (result2 instanceof Promise) {
|
|
11875
|
+
proms.push(result2.then((result3) => handleTupleResult(result3, payload, i)));
|
|
11839
11876
|
} else {
|
|
11840
|
-
handleTupleResult(
|
|
11877
|
+
handleTupleResult(result2, payload, i);
|
|
11841
11878
|
}
|
|
11842
11879
|
}
|
|
11843
11880
|
}
|
|
@@ -11846,11 +11883,11 @@ var $ZodTuple = /* @__PURE__ */ $constructor("$ZodTuple", (inst, def) => {
|
|
|
11846
11883
|
return payload;
|
|
11847
11884
|
};
|
|
11848
11885
|
});
|
|
11849
|
-
function handleTupleResult(
|
|
11850
|
-
if (
|
|
11851
|
-
final.issues.push(...prefixIssues(index,
|
|
11886
|
+
function handleTupleResult(result2, final, index) {
|
|
11887
|
+
if (result2.issues.length) {
|
|
11888
|
+
final.issues.push(...prefixIssues(index, result2.issues));
|
|
11852
11889
|
}
|
|
11853
|
-
final.value[index] =
|
|
11890
|
+
final.value[index] = result2.value;
|
|
11854
11891
|
}
|
|
11855
11892
|
var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
11856
11893
|
$ZodType.init(inst, def);
|
|
@@ -11871,19 +11908,19 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
|
11871
11908
|
payload.value = {};
|
|
11872
11909
|
for (const key of values) {
|
|
11873
11910
|
if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
|
|
11874
|
-
const
|
|
11875
|
-
if (
|
|
11876
|
-
proms.push(
|
|
11877
|
-
if (
|
|
11878
|
-
payload.issues.push(...prefixIssues(key,
|
|
11911
|
+
const result2 = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
|
|
11912
|
+
if (result2 instanceof Promise) {
|
|
11913
|
+
proms.push(result2.then((result3) => {
|
|
11914
|
+
if (result3.issues.length) {
|
|
11915
|
+
payload.issues.push(...prefixIssues(key, result3.issues));
|
|
11879
11916
|
}
|
|
11880
|
-
payload.value[key] =
|
|
11917
|
+
payload.value[key] = result3.value;
|
|
11881
11918
|
}));
|
|
11882
11919
|
} else {
|
|
11883
|
-
if (
|
|
11884
|
-
payload.issues.push(...prefixIssues(key,
|
|
11920
|
+
if (result2.issues.length) {
|
|
11921
|
+
payload.issues.push(...prefixIssues(key, result2.issues));
|
|
11885
11922
|
}
|
|
11886
|
-
payload.value[key] =
|
|
11923
|
+
payload.value[key] = result2.value;
|
|
11887
11924
|
}
|
|
11888
11925
|
}
|
|
11889
11926
|
}
|
|
@@ -11923,19 +11960,19 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
|
11923
11960
|
payload.value[keyResult.value] = keyResult.value;
|
|
11924
11961
|
continue;
|
|
11925
11962
|
}
|
|
11926
|
-
const
|
|
11927
|
-
if (
|
|
11928
|
-
proms.push(
|
|
11929
|
-
if (
|
|
11930
|
-
payload.issues.push(...prefixIssues(key,
|
|
11963
|
+
const result2 = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
|
|
11964
|
+
if (result2 instanceof Promise) {
|
|
11965
|
+
proms.push(result2.then((result3) => {
|
|
11966
|
+
if (result3.issues.length) {
|
|
11967
|
+
payload.issues.push(...prefixIssues(key, result3.issues));
|
|
11931
11968
|
}
|
|
11932
|
-
payload.value[keyResult.value] =
|
|
11969
|
+
payload.value[keyResult.value] = result3.value;
|
|
11933
11970
|
}));
|
|
11934
11971
|
} else {
|
|
11935
|
-
if (
|
|
11936
|
-
payload.issues.push(...prefixIssues(key,
|
|
11972
|
+
if (result2.issues.length) {
|
|
11973
|
+
payload.issues.push(...prefixIssues(key, result2.issues));
|
|
11937
11974
|
}
|
|
11938
|
-
payload.value[keyResult.value] =
|
|
11975
|
+
payload.value[keyResult.value] = result2.value;
|
|
11939
11976
|
}
|
|
11940
11977
|
}
|
|
11941
11978
|
}
|
|
@@ -12022,22 +12059,22 @@ var $ZodSet = /* @__PURE__ */ $constructor("$ZodSet", (inst, def) => {
|
|
|
12022
12059
|
const proms = [];
|
|
12023
12060
|
payload.value = /* @__PURE__ */ new Set();
|
|
12024
12061
|
for (const item of input) {
|
|
12025
|
-
const
|
|
12026
|
-
if (
|
|
12027
|
-
proms.push(
|
|
12062
|
+
const result2 = def.valueType._zod.run({ value: item, issues: [] }, ctx);
|
|
12063
|
+
if (result2 instanceof Promise) {
|
|
12064
|
+
proms.push(result2.then((result3) => handleSetResult(result3, payload)));
|
|
12028
12065
|
} else
|
|
12029
|
-
handleSetResult(
|
|
12066
|
+
handleSetResult(result2, payload);
|
|
12030
12067
|
}
|
|
12031
12068
|
if (proms.length)
|
|
12032
12069
|
return Promise.all(proms).then(() => payload);
|
|
12033
12070
|
return payload;
|
|
12034
12071
|
};
|
|
12035
12072
|
});
|
|
12036
|
-
function handleSetResult(
|
|
12037
|
-
if (
|
|
12038
|
-
final.issues.push(...
|
|
12073
|
+
function handleSetResult(result2, final) {
|
|
12074
|
+
if (result2.issues.length) {
|
|
12075
|
+
final.issues.push(...result2.issues);
|
|
12039
12076
|
}
|
|
12040
|
-
final.value.add(
|
|
12077
|
+
final.value.add(result2.value);
|
|
12041
12078
|
}
|
|
12042
12079
|
var $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
|
|
12043
12080
|
$ZodType.init(inst, def);
|
|
@@ -12116,11 +12153,11 @@ var $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def) =>
|
|
|
12116
12153
|
return payload;
|
|
12117
12154
|
};
|
|
12118
12155
|
});
|
|
12119
|
-
function handleOptionalResult(
|
|
12120
|
-
if (
|
|
12156
|
+
function handleOptionalResult(result2, input) {
|
|
12157
|
+
if (result2.issues.length && input === void 0) {
|
|
12121
12158
|
return { issues: [], value: void 0 };
|
|
12122
12159
|
}
|
|
12123
|
-
return
|
|
12160
|
+
return result2;
|
|
12124
12161
|
}
|
|
12125
12162
|
var $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
|
|
12126
12163
|
$ZodType.init(inst, def);
|
|
@@ -12135,10 +12172,10 @@ var $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
|
|
|
12135
12172
|
});
|
|
12136
12173
|
inst._zod.parse = (payload, ctx) => {
|
|
12137
12174
|
if (def.innerType._zod.optin === "optional") {
|
|
12138
|
-
const
|
|
12139
|
-
if (
|
|
12140
|
-
return
|
|
12141
|
-
return handleOptionalResult(
|
|
12175
|
+
const result2 = def.innerType._zod.run(payload, ctx);
|
|
12176
|
+
if (result2 instanceof Promise)
|
|
12177
|
+
return result2.then((r) => handleOptionalResult(r, payload.value));
|
|
12178
|
+
return handleOptionalResult(result2, payload.value);
|
|
12142
12179
|
}
|
|
12143
12180
|
if (payload.value === void 0) {
|
|
12144
12181
|
return payload;
|
|
@@ -12175,11 +12212,11 @@ var $ZodDefault = /* @__PURE__ */ $constructor("$ZodDefault", (inst, def) => {
|
|
|
12175
12212
|
payload.value = def.defaultValue;
|
|
12176
12213
|
return payload;
|
|
12177
12214
|
}
|
|
12178
|
-
const
|
|
12179
|
-
if (
|
|
12180
|
-
return
|
|
12215
|
+
const result2 = def.innerType._zod.run(payload, ctx);
|
|
12216
|
+
if (result2 instanceof Promise) {
|
|
12217
|
+
return result2.then((result3) => handleDefaultResult(result3, def));
|
|
12181
12218
|
}
|
|
12182
|
-
return handleDefaultResult(
|
|
12219
|
+
return handleDefaultResult(result2, def);
|
|
12183
12220
|
};
|
|
12184
12221
|
});
|
|
12185
12222
|
function handleDefaultResult(payload, def) {
|
|
@@ -12209,11 +12246,11 @@ var $ZodNonOptional = /* @__PURE__ */ $constructor("$ZodNonOptional", (inst, def
|
|
|
12209
12246
|
return v2 ? new Set([...v2].filter((x) => x !== void 0)) : void 0;
|
|
12210
12247
|
});
|
|
12211
12248
|
inst._zod.parse = (payload, ctx) => {
|
|
12212
|
-
const
|
|
12213
|
-
if (
|
|
12214
|
-
return
|
|
12249
|
+
const result2 = def.innerType._zod.run(payload, ctx);
|
|
12250
|
+
if (result2 instanceof Promise) {
|
|
12251
|
+
return result2.then((result3) => handleNonOptionalResult(result3, inst));
|
|
12215
12252
|
}
|
|
12216
|
-
return handleNonOptionalResult(
|
|
12253
|
+
return handleNonOptionalResult(result2, inst);
|
|
12217
12254
|
};
|
|
12218
12255
|
});
|
|
12219
12256
|
function handleNonOptionalResult(payload, inst) {
|
|
@@ -12233,14 +12270,14 @@ var $ZodSuccess = /* @__PURE__ */ $constructor("$ZodSuccess", (inst, def) => {
|
|
|
12233
12270
|
if (ctx.direction === "backward") {
|
|
12234
12271
|
throw new $ZodEncodeError("ZodSuccess");
|
|
12235
12272
|
}
|
|
12236
|
-
const
|
|
12237
|
-
if (
|
|
12238
|
-
return
|
|
12239
|
-
payload.value =
|
|
12273
|
+
const result2 = def.innerType._zod.run(payload, ctx);
|
|
12274
|
+
if (result2 instanceof Promise) {
|
|
12275
|
+
return result2.then((result3) => {
|
|
12276
|
+
payload.value = result3.issues.length === 0;
|
|
12240
12277
|
return payload;
|
|
12241
12278
|
});
|
|
12242
12279
|
}
|
|
12243
|
-
payload.value =
|
|
12280
|
+
payload.value = result2.issues.length === 0;
|
|
12244
12281
|
return payload;
|
|
12245
12282
|
};
|
|
12246
12283
|
});
|
|
@@ -12253,15 +12290,15 @@ var $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
|
|
|
12253
12290
|
if (ctx.direction === "backward") {
|
|
12254
12291
|
return def.innerType._zod.run(payload, ctx);
|
|
12255
12292
|
}
|
|
12256
|
-
const
|
|
12257
|
-
if (
|
|
12258
|
-
return
|
|
12259
|
-
payload.value =
|
|
12260
|
-
if (
|
|
12293
|
+
const result2 = def.innerType._zod.run(payload, ctx);
|
|
12294
|
+
if (result2 instanceof Promise) {
|
|
12295
|
+
return result2.then((result3) => {
|
|
12296
|
+
payload.value = result3.value;
|
|
12297
|
+
if (result3.issues.length) {
|
|
12261
12298
|
payload.value = def.catchValue({
|
|
12262
12299
|
...payload,
|
|
12263
12300
|
error: {
|
|
12264
|
-
issues:
|
|
12301
|
+
issues: result3.issues.map((iss) => finalizeIssue(iss, ctx, config()))
|
|
12265
12302
|
},
|
|
12266
12303
|
input: payload.value
|
|
12267
12304
|
});
|
|
@@ -12270,12 +12307,12 @@ var $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
|
|
|
12270
12307
|
return payload;
|
|
12271
12308
|
});
|
|
12272
12309
|
}
|
|
12273
|
-
payload.value =
|
|
12274
|
-
if (
|
|
12310
|
+
payload.value = result2.value;
|
|
12311
|
+
if (result2.issues.length) {
|
|
12275
12312
|
payload.value = def.catchValue({
|
|
12276
12313
|
...payload,
|
|
12277
12314
|
error: {
|
|
12278
|
-
issues:
|
|
12315
|
+
issues: result2.issues.map((iss) => finalizeIssue(iss, ctx, config()))
|
|
12279
12316
|
},
|
|
12280
12317
|
input: payload.value
|
|
12281
12318
|
});
|
|
@@ -12350,24 +12387,24 @@ var $ZodCodec = /* @__PURE__ */ $constructor("$ZodCodec", (inst, def) => {
|
|
|
12350
12387
|
}
|
|
12351
12388
|
};
|
|
12352
12389
|
});
|
|
12353
|
-
function handleCodecAResult(
|
|
12354
|
-
if (
|
|
12355
|
-
|
|
12356
|
-
return
|
|
12390
|
+
function handleCodecAResult(result2, def, ctx) {
|
|
12391
|
+
if (result2.issues.length) {
|
|
12392
|
+
result2.aborted = true;
|
|
12393
|
+
return result2;
|
|
12357
12394
|
}
|
|
12358
12395
|
const direction = ctx.direction || "forward";
|
|
12359
12396
|
if (direction === "forward") {
|
|
12360
|
-
const transformed = def.transform(
|
|
12397
|
+
const transformed = def.transform(result2.value, result2);
|
|
12361
12398
|
if (transformed instanceof Promise) {
|
|
12362
|
-
return transformed.then((value) => handleCodecTxResult(
|
|
12399
|
+
return transformed.then((value) => handleCodecTxResult(result2, value, def.out, ctx));
|
|
12363
12400
|
}
|
|
12364
|
-
return handleCodecTxResult(
|
|
12401
|
+
return handleCodecTxResult(result2, transformed, def.out, ctx);
|
|
12365
12402
|
} else {
|
|
12366
|
-
const transformed = def.reverseTransform(
|
|
12403
|
+
const transformed = def.reverseTransform(result2.value, result2);
|
|
12367
12404
|
if (transformed instanceof Promise) {
|
|
12368
|
-
return transformed.then((value) => handleCodecTxResult(
|
|
12405
|
+
return transformed.then((value) => handleCodecTxResult(result2, value, def.in, ctx));
|
|
12369
12406
|
}
|
|
12370
|
-
return handleCodecTxResult(
|
|
12407
|
+
return handleCodecTxResult(result2, transformed, def.in, ctx);
|
|
12371
12408
|
}
|
|
12372
12409
|
}
|
|
12373
12410
|
function handleCodecTxResult(left, value, nextSchema, ctx) {
|
|
@@ -12387,11 +12424,11 @@ var $ZodReadonly = /* @__PURE__ */ $constructor("$ZodReadonly", (inst, def) => {
|
|
|
12387
12424
|
if (ctx.direction === "backward") {
|
|
12388
12425
|
return def.innerType._zod.run(payload, ctx);
|
|
12389
12426
|
}
|
|
12390
|
-
const
|
|
12391
|
-
if (
|
|
12392
|
-
return
|
|
12427
|
+
const result2 = def.innerType._zod.run(payload, ctx);
|
|
12428
|
+
if (result2 instanceof Promise) {
|
|
12429
|
+
return result2.then(handleReadonlyResult);
|
|
12393
12430
|
}
|
|
12394
|
-
return handleReadonlyResult(
|
|
12431
|
+
return handleReadonlyResult(result2);
|
|
12395
12432
|
};
|
|
12396
12433
|
});
|
|
12397
12434
|
function handleReadonlyResult(payload) {
|
|
@@ -12453,11 +12490,11 @@ var $ZodFunction = /* @__PURE__ */ $constructor("$ZodFunction", (inst, def) => {
|
|
|
12453
12490
|
}
|
|
12454
12491
|
return function(...args) {
|
|
12455
12492
|
const parsedArgs = inst._def.input ? parse(inst._def.input, args) : args;
|
|
12456
|
-
const
|
|
12493
|
+
const result2 = Reflect.apply(func, this, parsedArgs);
|
|
12457
12494
|
if (inst._def.output) {
|
|
12458
|
-
return parse(inst._def.output,
|
|
12495
|
+
return parse(inst._def.output, result2);
|
|
12459
12496
|
}
|
|
12460
|
-
return
|
|
12497
|
+
return result2;
|
|
12461
12498
|
};
|
|
12462
12499
|
};
|
|
12463
12500
|
inst.implementAsync = (func) => {
|
|
@@ -12466,11 +12503,11 @@ var $ZodFunction = /* @__PURE__ */ $constructor("$ZodFunction", (inst, def) => {
|
|
|
12466
12503
|
}
|
|
12467
12504
|
return async function(...args) {
|
|
12468
12505
|
const parsedArgs = inst._def.input ? await parseAsync(inst._def.input, args) : args;
|
|
12469
|
-
const
|
|
12506
|
+
const result2 = await Reflect.apply(func, this, parsedArgs);
|
|
12470
12507
|
if (inst._def.output) {
|
|
12471
|
-
return await parseAsync(inst._def.output,
|
|
12508
|
+
return await parseAsync(inst._def.output, result2);
|
|
12472
12509
|
}
|
|
12473
|
-
return
|
|
12510
|
+
return result2;
|
|
12474
12511
|
};
|
|
12475
12512
|
};
|
|
12476
12513
|
inst._zod.parse = (payload, _ctx) => {
|
|
@@ -12554,8 +12591,8 @@ var $ZodCustom = /* @__PURE__ */ $constructor("$ZodCustom", (inst, def) => {
|
|
|
12554
12591
|
return;
|
|
12555
12592
|
};
|
|
12556
12593
|
});
|
|
12557
|
-
function handleRefineResult(
|
|
12558
|
-
if (!
|
|
12594
|
+
function handleRefineResult(result2, payload, input, inst) {
|
|
12595
|
+
if (!result2) {
|
|
12559
12596
|
const _iss = {
|
|
12560
12597
|
code: "custom",
|
|
12561
12598
|
input,
|
|
@@ -15601,12 +15638,12 @@ var error24 = () => {
|
|
|
15601
15638
|
}
|
|
15602
15639
|
};
|
|
15603
15640
|
function getSizing(origin, unitType, inclusive, targetShouldBe) {
|
|
15604
|
-
const
|
|
15605
|
-
if (
|
|
15606
|
-
return
|
|
15641
|
+
const result2 = Sizable[origin] ?? null;
|
|
15642
|
+
if (result2 === null)
|
|
15643
|
+
return result2;
|
|
15607
15644
|
return {
|
|
15608
|
-
unit:
|
|
15609
|
-
verb:
|
|
15645
|
+
unit: result2.unit[unitType],
|
|
15646
|
+
verb: result2.verb[targetShouldBe][inclusive ? "inclusive" : "notInclusive"]
|
|
15610
15647
|
};
|
|
15611
15648
|
}
|
|
15612
15649
|
const Nouns = {
|
|
@@ -19074,11 +19111,11 @@ var JSONSchemaGenerator = class {
|
|
|
19074
19111
|
}
|
|
19075
19112
|
return seen.schema;
|
|
19076
19113
|
}
|
|
19077
|
-
const
|
|
19078
|
-
this.seen.set(schema,
|
|
19114
|
+
const result2 = { schema: {}, count: 1, cycle: void 0, path: _params.path };
|
|
19115
|
+
this.seen.set(schema, result2);
|
|
19079
19116
|
const overrideSchema = schema._zod.toJSONSchema?.();
|
|
19080
19117
|
if (overrideSchema) {
|
|
19081
|
-
|
|
19118
|
+
result2.schema = overrideSchema;
|
|
19082
19119
|
} else {
|
|
19083
19120
|
const params = {
|
|
19084
19121
|
..._params,
|
|
@@ -19087,11 +19124,11 @@ var JSONSchemaGenerator = class {
|
|
|
19087
19124
|
};
|
|
19088
19125
|
const parent = schema._zod.parent;
|
|
19089
19126
|
if (parent) {
|
|
19090
|
-
|
|
19127
|
+
result2.ref = parent;
|
|
19091
19128
|
this.process(parent, params);
|
|
19092
19129
|
this.seen.get(parent).isParent = true;
|
|
19093
19130
|
} else {
|
|
19094
|
-
const _json =
|
|
19131
|
+
const _json = result2.schema;
|
|
19095
19132
|
switch (def.type) {
|
|
19096
19133
|
case "string": {
|
|
19097
19134
|
const json2 = _json;
|
|
@@ -19113,7 +19150,7 @@ var JSONSchemaGenerator = class {
|
|
|
19113
19150
|
if (regexes.length === 1)
|
|
19114
19151
|
json2.pattern = regexes[0].source;
|
|
19115
19152
|
else if (regexes.length > 1) {
|
|
19116
|
-
|
|
19153
|
+
result2.schema.allOf = [
|
|
19117
19154
|
...regexes.map((regex) => ({
|
|
19118
19155
|
...this.target === "draft-7" || this.target === "draft-4" || this.target === "openapi-3.0" ? { type: "string" } : {},
|
|
19119
19156
|
pattern: regex.source
|
|
@@ -19452,7 +19489,7 @@ var JSONSchemaGenerator = class {
|
|
|
19452
19489
|
case "nullable": {
|
|
19453
19490
|
const inner = this.process(def.innerType, params);
|
|
19454
19491
|
if (this.target === "openapi-3.0") {
|
|
19455
|
-
|
|
19492
|
+
result2.ref = def.innerType;
|
|
19456
19493
|
_json.nullable = true;
|
|
19457
19494
|
} else {
|
|
19458
19495
|
_json.anyOf = [inner, { type: "null" }];
|
|
@@ -19461,7 +19498,7 @@ var JSONSchemaGenerator = class {
|
|
|
19461
19498
|
}
|
|
19462
19499
|
case "nonoptional": {
|
|
19463
19500
|
this.process(def.innerType, params);
|
|
19464
|
-
|
|
19501
|
+
result2.ref = def.innerType;
|
|
19465
19502
|
break;
|
|
19466
19503
|
}
|
|
19467
19504
|
case "success": {
|
|
@@ -19471,20 +19508,20 @@ var JSONSchemaGenerator = class {
|
|
|
19471
19508
|
}
|
|
19472
19509
|
case "default": {
|
|
19473
19510
|
this.process(def.innerType, params);
|
|
19474
|
-
|
|
19511
|
+
result2.ref = def.innerType;
|
|
19475
19512
|
_json.default = JSON.parse(JSON.stringify(def.defaultValue));
|
|
19476
19513
|
break;
|
|
19477
19514
|
}
|
|
19478
19515
|
case "prefault": {
|
|
19479
19516
|
this.process(def.innerType, params);
|
|
19480
|
-
|
|
19517
|
+
result2.ref = def.innerType;
|
|
19481
19518
|
if (this.io === "input")
|
|
19482
19519
|
_json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
|
|
19483
19520
|
break;
|
|
19484
19521
|
}
|
|
19485
19522
|
case "catch": {
|
|
19486
19523
|
this.process(def.innerType, params);
|
|
19487
|
-
|
|
19524
|
+
result2.ref = def.innerType;
|
|
19488
19525
|
let catchValue;
|
|
19489
19526
|
try {
|
|
19490
19527
|
catchValue = def.catchValue(void 0);
|
|
@@ -19512,30 +19549,30 @@ var JSONSchemaGenerator = class {
|
|
|
19512
19549
|
case "pipe": {
|
|
19513
19550
|
const innerType = this.io === "input" ? def.in._zod.def.type === "transform" ? def.out : def.in : def.out;
|
|
19514
19551
|
this.process(innerType, params);
|
|
19515
|
-
|
|
19552
|
+
result2.ref = innerType;
|
|
19516
19553
|
break;
|
|
19517
19554
|
}
|
|
19518
19555
|
case "readonly": {
|
|
19519
19556
|
this.process(def.innerType, params);
|
|
19520
|
-
|
|
19557
|
+
result2.ref = def.innerType;
|
|
19521
19558
|
_json.readOnly = true;
|
|
19522
19559
|
break;
|
|
19523
19560
|
}
|
|
19524
19561
|
// passthrough types
|
|
19525
19562
|
case "promise": {
|
|
19526
19563
|
this.process(def.innerType, params);
|
|
19527
|
-
|
|
19564
|
+
result2.ref = def.innerType;
|
|
19528
19565
|
break;
|
|
19529
19566
|
}
|
|
19530
19567
|
case "optional": {
|
|
19531
19568
|
this.process(def.innerType, params);
|
|
19532
|
-
|
|
19569
|
+
result2.ref = def.innerType;
|
|
19533
19570
|
break;
|
|
19534
19571
|
}
|
|
19535
19572
|
case "lazy": {
|
|
19536
19573
|
const innerType = schema._zod.innerType;
|
|
19537
19574
|
this.process(innerType, params);
|
|
19538
|
-
|
|
19575
|
+
result2.ref = innerType;
|
|
19539
19576
|
break;
|
|
19540
19577
|
}
|
|
19541
19578
|
case "custom": {
|
|
@@ -19558,14 +19595,14 @@ var JSONSchemaGenerator = class {
|
|
|
19558
19595
|
}
|
|
19559
19596
|
const meta = this.metadataRegistry.get(schema);
|
|
19560
19597
|
if (meta)
|
|
19561
|
-
Object.assign(
|
|
19598
|
+
Object.assign(result2.schema, meta);
|
|
19562
19599
|
if (this.io === "input" && isTransforming(schema)) {
|
|
19563
|
-
delete
|
|
19564
|
-
delete
|
|
19600
|
+
delete result2.schema.examples;
|
|
19601
|
+
delete result2.schema.default;
|
|
19565
19602
|
}
|
|
19566
|
-
if (this.io === "input" &&
|
|
19567
|
-
(_a =
|
|
19568
|
-
delete
|
|
19603
|
+
if (this.io === "input" && result2.schema._prefault)
|
|
19604
|
+
(_a = result2.schema).default ?? (_a.default = result2.schema._prefault);
|
|
19605
|
+
delete result2.schema._prefault;
|
|
19569
19606
|
const _result = this.seen.get(schema);
|
|
19570
19607
|
return _result.schema;
|
|
19571
19608
|
}
|
|
@@ -19684,13 +19721,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19684
19721
|
for (const entry of [...this.seen.entries()].reverse()) {
|
|
19685
19722
|
flattenRef(entry[0], { target: this.target });
|
|
19686
19723
|
}
|
|
19687
|
-
const
|
|
19724
|
+
const result2 = {};
|
|
19688
19725
|
if (this.target === "draft-2020-12") {
|
|
19689
|
-
|
|
19726
|
+
result2.$schema = "https://json-schema.org/draft/2020-12/schema";
|
|
19690
19727
|
} else if (this.target === "draft-7") {
|
|
19691
|
-
|
|
19728
|
+
result2.$schema = "http://json-schema.org/draft-07/schema#";
|
|
19692
19729
|
} else if (this.target === "draft-4") {
|
|
19693
|
-
|
|
19730
|
+
result2.$schema = "http://json-schema.org/draft-04/schema#";
|
|
19694
19731
|
} else if (this.target === "openapi-3.0") {
|
|
19695
19732
|
} else {
|
|
19696
19733
|
console.warn(`Invalid target: ${this.target}`);
|
|
@@ -19699,9 +19736,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19699
19736
|
const id = params.external.registry.get(schema)?.id;
|
|
19700
19737
|
if (!id)
|
|
19701
19738
|
throw new Error("Schema is missing an `id` property");
|
|
19702
|
-
|
|
19739
|
+
result2.$id = params.external.uri(id);
|
|
19703
19740
|
}
|
|
19704
|
-
Object.assign(
|
|
19741
|
+
Object.assign(result2, root.def);
|
|
19705
19742
|
const defs = params.external?.defs ?? {};
|
|
19706
19743
|
for (const entry of this.seen.entries()) {
|
|
19707
19744
|
const seen = entry[1];
|
|
@@ -19713,14 +19750,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19713
19750
|
} else {
|
|
19714
19751
|
if (Object.keys(defs).length > 0) {
|
|
19715
19752
|
if (this.target === "draft-2020-12") {
|
|
19716
|
-
|
|
19753
|
+
result2.$defs = defs;
|
|
19717
19754
|
} else {
|
|
19718
|
-
|
|
19755
|
+
result2.definitions = defs;
|
|
19719
19756
|
}
|
|
19720
19757
|
}
|
|
19721
19758
|
}
|
|
19722
19759
|
try {
|
|
19723
|
-
return JSON.parse(JSON.stringify(
|
|
19760
|
+
return JSON.parse(JSON.stringify(result2));
|
|
19724
19761
|
} catch (_err) {
|
|
19725
19762
|
throw new Error("Error converting schema to JSON.");
|
|
19726
19763
|
}
|
|
@@ -21034,8 +21071,8 @@ Update the arguments and call the tool again.`);
|
|
|
21034
21071
|
});
|
|
21035
21072
|
context.signal.throwIfAborted();
|
|
21036
21073
|
};
|
|
21037
|
-
const
|
|
21038
|
-
return openCode2Result(
|
|
21074
|
+
const result2 = await definition.execute(parsed.data, { directory, abort: context.signal, ask });
|
|
21075
|
+
return openCode2Result(result2);
|
|
21039
21076
|
}
|
|
21040
21077
|
};
|
|
21041
21078
|
}
|
|
@@ -21049,17 +21086,17 @@ function sessionDirectoryResolver(ctx) {
|
|
|
21049
21086
|
return ctx.location.directory;
|
|
21050
21087
|
};
|
|
21051
21088
|
}
|
|
21052
|
-
function openCode2Result(
|
|
21053
|
-
if (typeof
|
|
21054
|
-
const files = (
|
|
21089
|
+
function openCode2Result(result2) {
|
|
21090
|
+
if (typeof result2 === "string") return { content: result2 };
|
|
21091
|
+
const files = (result2.attachments ?? []).map((attachment) => ({
|
|
21055
21092
|
type: "file",
|
|
21056
21093
|
uri: attachment.url,
|
|
21057
21094
|
mime: attachment.mime,
|
|
21058
21095
|
...attachment.filename ? { name: attachment.filename } : {}
|
|
21059
21096
|
}));
|
|
21060
21097
|
return {
|
|
21061
|
-
content: files.length > 0 ? [{ type: "text", text:
|
|
21062
|
-
...
|
|
21098
|
+
content: files.length > 0 ? [{ type: "text", text: result2.output }, ...files] : result2.output,
|
|
21099
|
+
...result2.metadata ? { metadata: result2.metadata } : {}
|
|
21063
21100
|
};
|
|
21064
21101
|
}
|
|
21065
21102
|
function completedSkillCall(event) {
|
|
@@ -21101,9 +21138,9 @@ function guardEventsFor(event) {
|
|
|
21101
21138
|
function openCode2GuardClient(ctx) {
|
|
21102
21139
|
return {
|
|
21103
21140
|
session: {
|
|
21104
|
-
abort: ({ path:
|
|
21141
|
+
abort: ({ path: path18 }) => ctx.session.interrupt({ sessionID: path18.id }),
|
|
21105
21142
|
// The resume prompt runs with the session's current agent and model, so `body.agent` and `body.model` are not sent.
|
|
21106
|
-
promptAsync: ({ path:
|
|
21143
|
+
promptAsync: ({ path: path18, body }) => ctx.session.prompt({ sessionID: path18.id, text: body.parts.map((part) => part.text).join("\n\n") })
|
|
21107
21144
|
}
|
|
21108
21145
|
};
|
|
21109
21146
|
}
|
|
@@ -21154,9 +21191,9 @@ function isRecord2(value) {
|
|
|
21154
21191
|
}
|
|
21155
21192
|
|
|
21156
21193
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
21157
|
-
import { link, mkdir as mkdir8, mkdtemp as mkdtemp2, readdir as readdir8, readFile as
|
|
21158
|
-
import
|
|
21159
|
-
import
|
|
21194
|
+
import { link, mkdir as mkdir8, mkdtemp as mkdtemp2, readdir as readdir8, readFile as readFile16, realpath as realpath3, rename as rename9, rm as rm6, rmdir as rmdir2, stat as stat4, unlink as unlink2, writeFile as writeFile9 } from "node:fs/promises";
|
|
21195
|
+
import os6 from "node:os";
|
|
21196
|
+
import path17 from "node:path";
|
|
21160
21197
|
|
|
21161
21198
|
// packages/cli/src/credentials.ts
|
|
21162
21199
|
import { chmod as chmod2, mkdir as mkdir2, readFile as readFile3, rename as rename3, rm as rm2, writeFile as writeFile3 } from "node:fs/promises";
|
|
@@ -21296,7 +21333,7 @@ async function adoptWorkPackInstalledState(input) {
|
|
|
21296
21333
|
const state = await readInstalledState(input.expectedPackDir);
|
|
21297
21334
|
if (!state || !await matchesInstalledState(input, state)) return false;
|
|
21298
21335
|
await writeJsonAtomic(path5.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
|
|
21299
|
-
return checkWorkPackInstalledState(input).then((
|
|
21336
|
+
return checkWorkPackInstalledState(input).then((result2) => result2 === "match");
|
|
21300
21337
|
}
|
|
21301
21338
|
async function readInstalledState(packDir) {
|
|
21302
21339
|
const info = await lstat2(path5.join(packDir, WORK_PACK_LOCAL_STATE_FILENAME)).catch(() => void 0);
|
|
@@ -21408,23 +21445,23 @@ function emptySummary() {
|
|
|
21408
21445
|
async function inspectWorkPackIntegrity(input) {
|
|
21409
21446
|
assertSlug(input.slug);
|
|
21410
21447
|
const packDir = path6.join(input.paths.skillsDir, input.slug);
|
|
21411
|
-
const
|
|
21448
|
+
const result2 = { slug: input.slug, summary: emptySummary(), differences: [], differencesTruncated: false };
|
|
21412
21449
|
const add = (kind, area, name) => {
|
|
21413
|
-
if (
|
|
21414
|
-
|
|
21415
|
-
if (
|
|
21416
|
-
else
|
|
21450
|
+
if (result2.summary[kind] === MAX_ENTRIES) result2.summary.truncated = true;
|
|
21451
|
+
result2.summary[kind] = Math.min(MAX_ENTRIES, result2.summary[kind] + 1);
|
|
21452
|
+
if (result2.differences.length < MAX_DIFFERENCES) result2.differences.push({ kind, area, path: name });
|
|
21453
|
+
else result2.differencesTruncated = true;
|
|
21417
21454
|
};
|
|
21418
21455
|
const root = await lstat3(packDir).catch(() => void 0);
|
|
21419
21456
|
if (!root?.isDirectory() || root.isSymbolicLink()) {
|
|
21420
21457
|
add(root ? "unsafe" : "unreadable", "pack", ".");
|
|
21421
|
-
|
|
21422
|
-
return
|
|
21458
|
+
result2.summary.kind = "unsafe-or-unreadable";
|
|
21459
|
+
return result2;
|
|
21423
21460
|
}
|
|
21424
21461
|
const expected = input.expected ? parseWorkPackFileManifest(input.expected) : await readInstalledState(packDir);
|
|
21425
|
-
if (!expected) return
|
|
21426
|
-
|
|
21427
|
-
|
|
21462
|
+
if (!expected) return result2;
|
|
21463
|
+
result2.version = expected.version;
|
|
21464
|
+
result2.summary.reference = input.expected ? input.reference ?? "server" : "installation-receipt";
|
|
21428
21465
|
const readBudget = { remaining: 128 * 1024 * 1024, exceeded: false };
|
|
21429
21466
|
const original = new Map(expected.files.map((file2) => [file2.path, file2.sha256]));
|
|
21430
21467
|
const directories = new Set(expected.directories);
|
|
@@ -21432,7 +21469,7 @@ async function inspectWorkPackIntegrity(input) {
|
|
|
21432
21469
|
const extraFiles = [], extraDirectories = [], blocked = [];
|
|
21433
21470
|
let entries = 0;
|
|
21434
21471
|
const walk = async (directory, prefix) => {
|
|
21435
|
-
if (
|
|
21472
|
+
if (result2.summary.truncated) return;
|
|
21436
21473
|
let children;
|
|
21437
21474
|
try {
|
|
21438
21475
|
children = await readdir3(directory, { withFileTypes: true });
|
|
@@ -21443,7 +21480,7 @@ async function inspectWorkPackIntegrity(input) {
|
|
|
21443
21480
|
}
|
|
21444
21481
|
for (const entry of children.sort((a, b2) => a.name < b2.name ? -1 : a.name > b2.name ? 1 : 0)) {
|
|
21445
21482
|
if (++entries > MAX_ENTRIES) {
|
|
21446
|
-
|
|
21483
|
+
result2.summary.truncated = true;
|
|
21447
21484
|
return;
|
|
21448
21485
|
}
|
|
21449
21486
|
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
@@ -21488,7 +21525,7 @@ async function inspectWorkPackIntegrity(input) {
|
|
|
21488
21525
|
}
|
|
21489
21526
|
};
|
|
21490
21527
|
await walk(packDir, "");
|
|
21491
|
-
const inaccessible = (name) =>
|
|
21528
|
+
const inaccessible = (name) => result2.summary.truncated || blocked.some((parent) => !parent || name === parent || name.startsWith(`${parent}/`));
|
|
21492
21529
|
for (const name of original.keys()) if (!seenFiles.has(name) && !seenDirectories.has(name) && !inaccessible(name)) add("missing", "pack", name);
|
|
21493
21530
|
for (const name of directories) if (!seenDirectories.has(name) && !seenFiles.has(name) && !inaccessible(name)) add("missing", "pack", name);
|
|
21494
21531
|
const cacheDirectories = /* @__PURE__ */ new Set();
|
|
@@ -21525,9 +21562,9 @@ async function inspectWorkPackIntegrity(input) {
|
|
|
21525
21562
|
}
|
|
21526
21563
|
}
|
|
21527
21564
|
}
|
|
21528
|
-
|
|
21529
|
-
|
|
21530
|
-
return
|
|
21565
|
+
result2.summary.truncated ||= readBudget.exceeded;
|
|
21566
|
+
result2.summary.kind = integrityKind(result2.summary);
|
|
21567
|
+
return result2;
|
|
21531
21568
|
}
|
|
21532
21569
|
async function regularFileDigest(filePath, budget) {
|
|
21533
21570
|
try {
|
|
@@ -25274,30 +25311,30 @@ function omittedProjectionOwners(omitted, conflict) {
|
|
|
25274
25311
|
return omitted.filter((pack) => pack[field]?.includes(conflict.filename));
|
|
25275
25312
|
}
|
|
25276
25313
|
async function runOperation(operation, operate) {
|
|
25277
|
-
let
|
|
25314
|
+
let result2;
|
|
25278
25315
|
try {
|
|
25279
|
-
|
|
25316
|
+
result2 = await operate(operation);
|
|
25280
25317
|
} catch {
|
|
25281
25318
|
return uncertainOutcome(operation, "callback-threw");
|
|
25282
25319
|
}
|
|
25283
|
-
if (
|
|
25284
|
-
if (
|
|
25320
|
+
if (result2.status === "recovery-uncertain") return uncertainOutcome(operation, stableCode(result2.code));
|
|
25321
|
+
if (result2.status === "failed") {
|
|
25285
25322
|
return {
|
|
25286
25323
|
...outcomeIdentity(operation),
|
|
25287
25324
|
status: "failed",
|
|
25288
|
-
code: stableCode(
|
|
25289
|
-
...
|
|
25290
|
-
...
|
|
25291
|
-
message:
|
|
25325
|
+
code: stableCode(result2.code),
|
|
25326
|
+
...result2.integrity ? { integrity: result2.integrity } : {},
|
|
25327
|
+
...result2.projectionConflict ? { projectionConflict: result2.projectionConflict } : {},
|
|
25328
|
+
message: result2.message ?? `O pacote "${operation.pack.slug}" falhou, mas o estado anterior foi restaurado exatamente. Corrija a causa indicada e volte a sincronizar.`
|
|
25292
25329
|
};
|
|
25293
25330
|
}
|
|
25294
|
-
if (!validSuccessFor(operation.action,
|
|
25331
|
+
if (!validSuccessFor(operation.action, result2.status)) return uncertainOutcome(operation, "invalid-callback-result");
|
|
25295
25332
|
return {
|
|
25296
25333
|
...outcomeIdentity(operation),
|
|
25297
|
-
status:
|
|
25298
|
-
...
|
|
25299
|
-
...
|
|
25300
|
-
...
|
|
25334
|
+
status: result2.status,
|
|
25335
|
+
...result2.warningCode ? { warningCode: stableCode(result2.warningCode) } : {},
|
|
25336
|
+
...result2.message ? { message: result2.message } : {},
|
|
25337
|
+
...result2.removedManagedPaths ? { removedManagedPaths: [...new Set(result2.removedManagedPaths)].sort() } : {}
|
|
25301
25338
|
};
|
|
25302
25339
|
}
|
|
25303
25340
|
function uncertainOutcome(operation, code) {
|
|
@@ -25563,15 +25600,15 @@ async function collectWorkPackObservations(paths, reconciliation) {
|
|
|
25563
25600
|
}
|
|
25564
25601
|
return [...observations.values()].sort((a, b2) => a.slug.localeCompare(b2.slug));
|
|
25565
25602
|
}
|
|
25566
|
-
async function enrichIntegrityFailure(paths, operation,
|
|
25567
|
-
if (
|
|
25603
|
+
async function enrichIntegrityFailure(paths, operation, result2) {
|
|
25604
|
+
if (result2.status !== "failed" || result2.integrity || !["local-edits-preserved", "local-baseline-missing"].includes(result2.code)) return result2;
|
|
25568
25605
|
try {
|
|
25569
25606
|
const { summary } = await inspectWorkPackIntegrity({ paths, slug: operation.pack.slug });
|
|
25570
|
-
if (summary.kind === "match") return
|
|
25571
|
-
const code = summary.kind === "runtime-artifacts" ? "local-runtime-artifacts" : summary.kind === "unknown-additions" ? "local-additions-preserved" : summary.kind === "unsafe-or-unreadable" ? "local-state-unreadable" :
|
|
25572
|
-
return { ...
|
|
25607
|
+
if (summary.kind === "match") return result2;
|
|
25608
|
+
const code = summary.kind === "runtime-artifacts" ? "local-runtime-artifacts" : summary.kind === "unknown-additions" ? "local-additions-preserved" : summary.kind === "unsafe-or-unreadable" ? "local-state-unreadable" : result2.code;
|
|
25609
|
+
return { ...result2, code, integrity: summary };
|
|
25573
25610
|
} catch {
|
|
25574
|
-
return
|
|
25611
|
+
return result2;
|
|
25575
25612
|
}
|
|
25576
25613
|
}
|
|
25577
25614
|
async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds, cleanupPendingSlugs, recoveryFailures, operation, authoritative, options) {
|
|
@@ -26753,6 +26790,7 @@ async function readJsoncObject(filePath) {
|
|
|
26753
26790
|
// packages/cli/src/workerPrompt.ts
|
|
26754
26791
|
import { createHash as createHash5 } from "node:crypto";
|
|
26755
26792
|
var STOCK_OPENWORK_PROMPT_SHA256 = "b84527bf738ab37c726ccd43c3161df30fbddd5384aadbe7abf3cfeb3fced497";
|
|
26793
|
+
var FORGE_COMPUTER_USE_INSTRUCTION = `Para criar, ler ou editar documentos Word (.docx), folhas de c\xE1lculo Excel (.xlsx) e apresenta\xE7\xF5es PowerPoint (.pptx), usa sempre c\xF3digo ou scripts sobre os ficheiros (por exemplo Python com as bibliotecas preparadas pelo Forge), nunca controlo de ecr\xE3 ou rato (computer_* / computer-use_*). Usa controlo de computador apenas como \xFAltimo recurso quando n\xE3o existir alternativa por ficheiro ou c\xF3digo, avisando primeiro a pessoa de que vais mexer no ecr\xE3 ou no rato e aguardando aprova\xE7\xE3o expl\xEDcita.`;
|
|
26756
26794
|
var FORGE_WORKER_PROMPT = `\xC9s o assistente de trabalho do Forge no OpenWork. Ajudas a pessoa a concluir
|
|
26757
26795
|
tarefas com os ficheiros, fontes e ferramentas a que tem acesso. N\xE3o pressuponhas
|
|
26758
26796
|
conhecimentos t\xE9cnicos nem inventes capacidades ou acessos.
|
|
@@ -26825,6 +26863,8 @@ e conven\xE7\xF5es pedidos. Verifica c\xE1lculos, completude, abertura dos fiche
|
|
|
26825
26863
|
e resultado das altera\xE7\xF5es. Usa as ferramentas de documentos, folhas de
|
|
26826
26864
|
c\xE1lculo e apresenta\xE7\xF5es dispon\xEDveis quando forem adequadas \xE0 entrega.
|
|
26827
26865
|
|
|
26866
|
+
${FORGE_COMPUTER_USE_INSTRUCTION}
|
|
26867
|
+
|
|
26828
26868
|
Comunica por defeito em portugu\xEAs europeu (PT-PT), de forma natural e concisa;
|
|
26829
26869
|
adapta a l\xEDngua ao pedido ou destinat\xE1rio. Preserva nomes de ferramentas,
|
|
26830
26870
|
identificadores e c\xF3digo. Come\xE7a pelo resultado ou decis\xE3o, d\xE1 atualiza\xE7\xF5es
|
|
@@ -26941,12 +26981,12 @@ function sha2562(value) {
|
|
|
26941
26981
|
|
|
26942
26982
|
// packages/cli/src/localWorkerSync.ts
|
|
26943
26983
|
async function syncLocalWorker(paths, credentials, manifest) {
|
|
26944
|
-
const
|
|
26984
|
+
const result2 = await applyManifest(paths, credentials, manifest, {
|
|
26945
26985
|
beforeCore: () => prepareLocalStartup(paths, credentials),
|
|
26946
26986
|
afterCore: () => removeWellKnownAuth(paths, credentials)
|
|
26947
26987
|
});
|
|
26948
26988
|
await recordRollbackEvidencePlugin(paths, renderEvidencePlugin());
|
|
26949
|
-
return
|
|
26989
|
+
return result2;
|
|
26950
26990
|
}
|
|
26951
26991
|
async function prepareLocalStartup(paths, credentials) {
|
|
26952
26992
|
let current;
|
|
@@ -26969,6 +27009,8 @@ async function prepareLocalStartup(paths, credentials) {
|
|
|
26969
27009
|
import { lstat as lstat6, readFile as readFile13, realpath } from "node:fs/promises";
|
|
26970
27010
|
import path13 from "node:path";
|
|
26971
27011
|
var OPENWORK_ENGINE_HEADER = "// Minimal Forge OpenWork engine configuration\n";
|
|
27012
|
+
var OPENWORK_ENGINE_INSTRUCTIONS_FILENAME = "forge-computer-use-instructions.md";
|
|
27013
|
+
var OPENWORK_ENGINE_INSTRUCTIONS_HEADER = "<!-- Minimal Forge OpenWork engine instructions -->\n";
|
|
26972
27014
|
async function inspectOpenworkEngineConfig(directory) {
|
|
26973
27015
|
if (!path13.isAbsolute(directory)) throw new Error("Indique a pasta absoluta de configura\xE7\xE3o do motor ativo.");
|
|
26974
27016
|
const root = await realpath(directory);
|
|
@@ -27014,12 +27056,38 @@ function renderOpenworkEngineConfig(manifest, credentials, paths, directory, exi
|
|
|
27014
27056
|
throw new Error("O servidor ainda n\xE3o aprovou um plugin com suporte OpenCode 2 (m\xEDnimo 0.1.49). N\xE3o altere o motor.");
|
|
27015
27057
|
}
|
|
27016
27058
|
config2.plugin = (config2.plugin ?? []).map((entry) => Array.isArray(entry) ? [entry[0], { ...entry[1], openworkEngineConfigDir: directory }] : entry);
|
|
27017
|
-
|
|
27059
|
+
const instructionsPath = path13.join(directory, OPENWORK_ENGINE_INSTRUCTIONS_FILENAME);
|
|
27060
|
+
const rawInstructions = config2.instructions;
|
|
27061
|
+
const existingInstructions = Array.isArray(rawInstructions) ? rawInstructions.filter((item) => typeof item === "string") : [];
|
|
27062
|
+
const instructions = existingInstructions.includes(instructionsPath) ? existingInstructions : [...existingInstructions, instructionsPath];
|
|
27063
|
+
return { ...config2, instructions, skills: [paths.skillsDir] };
|
|
27064
|
+
}
|
|
27065
|
+
async function writeOpenworkEngineInstructions(directory) {
|
|
27066
|
+
const file2 = path13.join(directory, OPENWORK_ENGINE_INSTRUCTIONS_FILENAME);
|
|
27067
|
+
let existing;
|
|
27068
|
+
try {
|
|
27069
|
+
const entry = await lstat6(file2);
|
|
27070
|
+
if (!entry.isFile() || entry.isSymbolicLink()) {
|
|
27071
|
+
throw new Error("Preserve o ficheiro de instru\xE7\xF5es do motor; n\xE3o \xE9 um ficheiro regular.");
|
|
27072
|
+
}
|
|
27073
|
+
existing = await readFile13(file2, "utf8");
|
|
27074
|
+
} catch (error45) {
|
|
27075
|
+
if (error45.code !== "ENOENT") throw error45;
|
|
27076
|
+
}
|
|
27077
|
+
if (existing !== void 0 && !existing.startsWith(OPENWORK_ENGINE_INSTRUCTIONS_HEADER)) {
|
|
27078
|
+
throw new Error("J\xE1 existe um ficheiro de instru\xE7\xF5es alheio ao Forge. Preserve-o e pe\xE7a revis\xE3o acompanhada.");
|
|
27079
|
+
}
|
|
27080
|
+
const content = `${OPENWORK_ENGINE_INSTRUCTIONS_HEADER}${FORGE_COMPUTER_USE_INSTRUCTION}
|
|
27081
|
+
`;
|
|
27082
|
+
if (existing === content) return false;
|
|
27083
|
+
await writeOwnerOnlyTextAtomic(file2, content);
|
|
27084
|
+
return true;
|
|
27018
27085
|
}
|
|
27019
27086
|
async function writeOpenworkEngineConfig(directory, config2) {
|
|
27020
27087
|
const state = await inspectOpenworkEngineConfig(directory);
|
|
27088
|
+
const instructionsChanged = await writeOpenworkEngineInstructions(state.directory);
|
|
27021
27089
|
const content = OPENWORK_ENGINE_HEADER + JSON.stringify(config2, null, 2) + "\n";
|
|
27022
|
-
if (state.content === content) return { changed:
|
|
27090
|
+
if (state.content === content) return { changed: instructionsChanged };
|
|
27023
27091
|
await writeOwnerOnlyTextAtomic(state.file, content);
|
|
27024
27092
|
return { changed: true };
|
|
27025
27093
|
}
|
|
@@ -27143,10 +27211,366 @@ async function resolveWritePath(file2) {
|
|
|
27143
27211
|
}
|
|
27144
27212
|
}
|
|
27145
27213
|
|
|
27214
|
+
// packages/cli/src/workPackPythonStartup.ts
|
|
27215
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
27216
|
+
import { lstat as lstat8 } from "node:fs/promises";
|
|
27217
|
+
import path16 from "node:path";
|
|
27218
|
+
|
|
27219
|
+
// packages/cli/src/pythonReadiness.ts
|
|
27220
|
+
import { execFile } from "node:child_process";
|
|
27221
|
+
import { createHash as createHash8, randomUUID as randomUUID5 } from "node:crypto";
|
|
27222
|
+
import { readFile as readFile15, stat as stat3 } from "node:fs/promises";
|
|
27223
|
+
import os5 from "node:os";
|
|
27224
|
+
import path15 from "node:path";
|
|
27225
|
+
import { promisify } from "node:util";
|
|
27226
|
+
var runPython = promisify(execFile);
|
|
27227
|
+
var CACHE_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
|
|
27228
|
+
var PROBE_MARKER = "FORGE_PYTHON_READINESS=";
|
|
27229
|
+
var PROBE = String.raw`
|
|
27230
|
+
import sys
|
|
27231
|
+
|
|
27232
|
+
# The check runs against the interpreter's installed packages without importing
|
|
27233
|
+
# scripts from the directory in which OpenWork or the CLI was opened.
|
|
27234
|
+
if sys.path and sys.path[0] == "":
|
|
27235
|
+
sys.path.pop(0)
|
|
27236
|
+
|
|
27237
|
+
import json
|
|
27238
|
+
import os
|
|
27239
|
+
import platform
|
|
27240
|
+
|
|
27241
|
+
identity = {
|
|
27242
|
+
"interpreter": os.path.abspath(sys.executable) if sys.executable else "",
|
|
27243
|
+
"pythonVersion": platform.python_version(),
|
|
27244
|
+
"supported": sys.version_info >= (3, 10),
|
|
27245
|
+
}
|
|
27246
|
+
if not identity["supported"]:
|
|
27247
|
+
print("${PROBE_MARKER}" + json.dumps(identity))
|
|
27248
|
+
sys.exit(0)
|
|
27249
|
+
|
|
27250
|
+
import importlib
|
|
27251
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
27252
|
+
from io import BytesIO
|
|
27253
|
+
import re
|
|
27254
|
+
import site
|
|
27255
|
+
|
|
27256
|
+
def release(value):
|
|
27257
|
+
# The approved ranges are inclusive/exclusive numeric releases. Accept
|
|
27258
|
+
# post and local builds, and leave prereleases outside the baseline.
|
|
27259
|
+
match = re.fullmatch(r"(?:0!)?(\d+(?:\.\d+)*)(?:(?:[._-]?(?:post|rev|r)[._-]?\d+)|-\d+)?(?:\+[a-z0-9._-]+)?", value.lower())
|
|
27260
|
+
if not match:
|
|
27261
|
+
return None
|
|
27262
|
+
parts = [int(part) for part in match[1].split(".")]
|
|
27263
|
+
while len(parts) > 1 and parts[-1] == 0:
|
|
27264
|
+
parts.pop()
|
|
27265
|
+
return tuple(parts)
|
|
27266
|
+
|
|
27267
|
+
def compatible(installed, requirement):
|
|
27268
|
+
minimum, before = requirement.split(">=", 1)[1].split(",<", 1)
|
|
27269
|
+
installed = release(installed)
|
|
27270
|
+
return installed is not None and release(minimum) <= installed < release(before)
|
|
27271
|
+
|
|
27272
|
+
def check_package(package):
|
|
27273
|
+
try:
|
|
27274
|
+
installed = version(package["name"])
|
|
27275
|
+
except PackageNotFoundError:
|
|
27276
|
+
return {**package, "status": "missing"}
|
|
27277
|
+
try:
|
|
27278
|
+
module = importlib.import_module(package["importName"])
|
|
27279
|
+
except Exception:
|
|
27280
|
+
status = "import-failed" if compatible(installed, package["requirement"]) else "incompatible"
|
|
27281
|
+
return {**package, "version": installed, "status": status}
|
|
27282
|
+
imported = getattr(module, "__version__", installed)
|
|
27283
|
+
if not isinstance(imported, str):
|
|
27284
|
+
imported = installed
|
|
27285
|
+
status = "ready" if compatible(imported, package["requirement"]) and compatible(installed, package["requirement"]) else "incompatible"
|
|
27286
|
+
return {**package, "version": imported, "status": status}
|
|
27287
|
+
|
|
27288
|
+
def example_image():
|
|
27289
|
+
from PIL import Image
|
|
27290
|
+
|
|
27291
|
+
contents = BytesIO()
|
|
27292
|
+
Image.new("RGB", (12, 12), "blue").save(contents, format="PNG")
|
|
27293
|
+
contents.seek(0)
|
|
27294
|
+
return contents
|
|
27295
|
+
|
|
27296
|
+
def check_word():
|
|
27297
|
+
from docx import Document
|
|
27298
|
+
|
|
27299
|
+
document = Document()
|
|
27300
|
+
document.add_paragraph("Forge")
|
|
27301
|
+
document.add_picture(example_image())
|
|
27302
|
+
contents = BytesIO()
|
|
27303
|
+
document.save(contents)
|
|
27304
|
+
contents.seek(0)
|
|
27305
|
+
reopened = Document(contents)
|
|
27306
|
+
return reopened.paragraphs[0].text == "Forge" and len(reopened.inline_shapes) == 1
|
|
27307
|
+
|
|
27308
|
+
def check_excel():
|
|
27309
|
+
from openpyxl import Workbook, load_workbook
|
|
27310
|
+
from openpyxl.drawing.image import Image
|
|
27311
|
+
|
|
27312
|
+
workbook = Workbook()
|
|
27313
|
+
workbook.active["A1"] = "Forge"
|
|
27314
|
+
workbook.active.add_image(Image(example_image()), "B2")
|
|
27315
|
+
contents = BytesIO()
|
|
27316
|
+
workbook.save(contents)
|
|
27317
|
+
contents.seek(0)
|
|
27318
|
+
reopened = load_workbook(contents)
|
|
27319
|
+
try:
|
|
27320
|
+
return reopened.active["A1"].value == "Forge" and len(reopened.active._images) == 1
|
|
27321
|
+
finally:
|
|
27322
|
+
reopened.close()
|
|
27323
|
+
|
|
27324
|
+
def check_powerpoint():
|
|
27325
|
+
from pptx import Presentation
|
|
27326
|
+
from pptx.enum.shapes import MSO_SHAPE_TYPE
|
|
27327
|
+
from pptx.util import Inches
|
|
27328
|
+
|
|
27329
|
+
presentation = Presentation()
|
|
27330
|
+
slide = presentation.slides.add_slide(presentation.slide_layouts[6])
|
|
27331
|
+
slide.shapes.add_textbox(Inches(1), Inches(1), Inches(4), Inches(1)).text_frame.text = "Forge"
|
|
27332
|
+
slide.shapes.add_picture(example_image(), Inches(1), Inches(2))
|
|
27333
|
+
contents = BytesIO()
|
|
27334
|
+
presentation.save(contents)
|
|
27335
|
+
contents.seek(0)
|
|
27336
|
+
reopened = Presentation(contents)
|
|
27337
|
+
texts = [shape.text for shape in reopened.slides[0].shapes if shape.has_text_frame]
|
|
27338
|
+
pictures = [shape for shape in reopened.slides[0].shapes if shape.shape_type == MSO_SHAPE_TYPE.PICTURE]
|
|
27339
|
+
return "Forge" in texts and len(pictures) == 1
|
|
27340
|
+
|
|
27341
|
+
def check_document(check):
|
|
27342
|
+
try:
|
|
27343
|
+
return check()
|
|
27344
|
+
except Exception:
|
|
27345
|
+
return False
|
|
27346
|
+
|
|
27347
|
+
packages = [check_package(package) for package in json.loads(sys.argv[1])]
|
|
27348
|
+
ready = {package["name"] for package in packages if package["status"] == "ready"}
|
|
27349
|
+
result = {
|
|
27350
|
+
**identity,
|
|
27351
|
+
"virtualEnvironment": sys.prefix != sys.base_prefix,
|
|
27352
|
+
"userSiteEnabled": site.ENABLE_USER_SITE is True,
|
|
27353
|
+
"packages": packages,
|
|
27354
|
+
"documents": {
|
|
27355
|
+
"word": {"python-docx", "Pillow"} <= ready and check_document(check_word),
|
|
27356
|
+
"excel": {"openpyxl", "Pillow"} <= ready and check_document(check_excel),
|
|
27357
|
+
"powerpoint": {"python-pptx", "Pillow"} <= ready and check_document(check_powerpoint),
|
|
27358
|
+
},
|
|
27359
|
+
}
|
|
27360
|
+
print("${PROBE_MARKER}" + json.dumps(result))
|
|
27361
|
+
`;
|
|
27362
|
+
var BASELINE_KEY = createHash8("sha256").update(PROBE).update(JSON.stringify(PYTHON_REQUIREMENTS)).digest("hex");
|
|
27363
|
+
function needsInstall(entry) {
|
|
27364
|
+
return entry.status === "missing" || entry.status === "incompatible";
|
|
27365
|
+
}
|
|
27366
|
+
var startupChecks = /* @__PURE__ */ new Map();
|
|
27367
|
+
var selectionUnreadable = "N\xE3o foi poss\xEDvel ler a sele\xE7\xE3o Python do Forge. Selecione novamente o Python com --python.";
|
|
27368
|
+
function selectionPath(paths) {
|
|
27369
|
+
return path15.join(paths.forgeDir, "python-readiness.json");
|
|
27370
|
+
}
|
|
27371
|
+
function cachePath(paths) {
|
|
27372
|
+
return path15.join(paths.forgeDir, "python-readiness-cache.json");
|
|
27373
|
+
}
|
|
27374
|
+
function result(fields) {
|
|
27375
|
+
return { ...fields, checkedAt: (/* @__PURE__ */ new Date()).toISOString(), cached: false };
|
|
27376
|
+
}
|
|
27377
|
+
function unverified(reason, interpreter) {
|
|
27378
|
+
return result({ status: "unverified", interpreter, reason });
|
|
27379
|
+
}
|
|
27380
|
+
function selectPython(reason, interpreter) {
|
|
27381
|
+
return { ...unverified(reason, interpreter), requiresPythonSelection: true };
|
|
27382
|
+
}
|
|
27383
|
+
async function readSelection(paths) {
|
|
27384
|
+
let contents;
|
|
27385
|
+
try {
|
|
27386
|
+
contents = await readFile15(selectionPath(paths), "utf8");
|
|
27387
|
+
} catch (error45) {
|
|
27388
|
+
if (error45.code === "ENOENT") return void 0;
|
|
27389
|
+
throw error45;
|
|
27390
|
+
}
|
|
27391
|
+
const selected = JSON.parse(contents);
|
|
27392
|
+
if (typeof selected?.interpreter !== "string" || !path15.isAbsolute(selected.interpreter) || typeof selected.revision !== "string") {
|
|
27393
|
+
throw new Error("Invalid Python selection");
|
|
27394
|
+
}
|
|
27395
|
+
return selected;
|
|
27396
|
+
}
|
|
27397
|
+
async function readSelectedPython(paths) {
|
|
27398
|
+
return (await readSelection(paths).catch(() => void 0))?.interpreter;
|
|
27399
|
+
}
|
|
27400
|
+
async function readCache(paths) {
|
|
27401
|
+
try {
|
|
27402
|
+
const cache = JSON.parse(await readFile15(cachePath(paths), "utf8"));
|
|
27403
|
+
if (typeof cache.key === "string" && typeof cache.result?.checkedAt === "string" && ["ready", "not-ready", "unverified"].includes(cache.result.status)) return cache;
|
|
27404
|
+
} catch {
|
|
27405
|
+
}
|
|
27406
|
+
return void 0;
|
|
27407
|
+
}
|
|
27408
|
+
async function cacheKey(selection) {
|
|
27409
|
+
try {
|
|
27410
|
+
const executable = await stat3(selection.interpreter);
|
|
27411
|
+
if (!executable.isFile()) return void 0;
|
|
27412
|
+
const venvConfig = await stat3(path15.resolve(path15.dirname(selection.interpreter), "..", "pyvenv.cfg")).catch(() => void 0);
|
|
27413
|
+
return JSON.stringify([BASELINE_KEY, selection, executable.ino, executable.size, executable.mtimeMs, executable.ctimeMs, venvConfig?.mtimeMs]);
|
|
27414
|
+
} catch {
|
|
27415
|
+
return void 0;
|
|
27416
|
+
}
|
|
27417
|
+
}
|
|
27418
|
+
async function saveCache(paths, key, checked) {
|
|
27419
|
+
if (!key) return;
|
|
27420
|
+
const cache = { key, result: checked };
|
|
27421
|
+
await writeOwnerOnlyTextAtomic(cachePath(paths), `${JSON.stringify(cache)}
|
|
27422
|
+
`).catch(() => void 0);
|
|
27423
|
+
}
|
|
27424
|
+
async function probePython(interpreter) {
|
|
27425
|
+
if (!interpreter || !path15.isAbsolute(interpreter)) {
|
|
27426
|
+
return { checked: selectPython("Selecione um execut\xE1vel Python 3 atrav\xE9s de --python com o caminho absoluto.") };
|
|
27427
|
+
}
|
|
27428
|
+
try {
|
|
27429
|
+
const { stdout } = await runPython(interpreter, ["-B", "-c", PROBE, JSON.stringify(PYTHON_REQUIREMENTS)], {
|
|
27430
|
+
cwd: os5.homedir(),
|
|
27431
|
+
encoding: "utf8",
|
|
27432
|
+
timeout: 6e4,
|
|
27433
|
+
windowsHide: true
|
|
27434
|
+
});
|
|
27435
|
+
const record2 = stdout.split(/\r?\n/).reverse().find((line) => line.startsWith(PROBE_MARKER));
|
|
27436
|
+
const probe = JSON.parse(record2?.slice(PROBE_MARKER.length) ?? "null");
|
|
27437
|
+
if (!probe || typeof probe.interpreter !== "string" || !path15.isAbsolute(probe.interpreter) || typeof probe.pythonVersion !== "string") {
|
|
27438
|
+
return { checked: selectPython("O execut\xE1vel selecionado n\xE3o devolveu um diagn\xF3stico Python v\xE1lido.", interpreter) };
|
|
27439
|
+
}
|
|
27440
|
+
if (probe.supported === false) {
|
|
27441
|
+
return { checked: result({ interpreter: probe.interpreter, pythonVersion: probe.pythonVersion, status: "not-ready", reason: "Selecione Python 3.10 ou posterior.", requiresPythonSelection: true }) };
|
|
27442
|
+
}
|
|
27443
|
+
if (probe.supported !== true || !probe.documents || probe.packages?.length !== PYTHON_REQUIREMENTS.length) {
|
|
27444
|
+
return { checked: selectPython("O execut\xE1vel selecionado n\xE3o devolveu um diagn\xF3stico Python v\xE1lido.", interpreter) };
|
|
27445
|
+
}
|
|
27446
|
+
const details = { interpreter: probe.interpreter, pythonVersion: probe.pythonVersion, packages: probe.packages, documents: probe.documents };
|
|
27447
|
+
if (probe.packages.some(needsInstall)) {
|
|
27448
|
+
return { probe, checked: result({ ...details, status: "not-ready", reason: "O Python selecionado tem bibliotecas em falta ou incompat\xEDveis. Execute prepare para instalar as bibliotecas indicadas." }) };
|
|
27449
|
+
}
|
|
27450
|
+
if (probe.packages.some((entry) => entry.status === "import-failed")) {
|
|
27451
|
+
return { probe, checked: result({ ...details, status: "not-ready", reason: "Uma biblioteca instalada falhou ao importar. Envie o diagn\xF3stico ao suporte para reparar o ambiente ou selecionar outro Python." }) };
|
|
27452
|
+
}
|
|
27453
|
+
if (!probe.documents.word || !probe.documents.excel || !probe.documents.powerpoint) {
|
|
27454
|
+
return { probe, checked: result({ ...details, status: "not-ready", reason: "O Python selecionado n\xE3o concluiu o ensaio de Word, Excel ou PowerPoint com imagens. Envie o diagn\xF3stico ao suporte para verificar esse ambiente." }) };
|
|
27455
|
+
}
|
|
27456
|
+
return { probe, checked: result({ ...details, status: "ready" }) };
|
|
27457
|
+
} catch (error45) {
|
|
27458
|
+
const failure = error45;
|
|
27459
|
+
if (failure.code === "ENOENT") {
|
|
27460
|
+
return { checked: selectPython("O execut\xE1vel Python selecionado j\xE1 n\xE3o est\xE1 dispon\xEDvel. Selecione novamente o Python com --python.", interpreter) };
|
|
27461
|
+
}
|
|
27462
|
+
if (failure.code === "EACCES" || failure.code === "EPERM") {
|
|
27463
|
+
return { checked: selectPython("O utilizador atual n\xE3o tem permiss\xE3o para executar o Python selecionado.", interpreter) };
|
|
27464
|
+
}
|
|
27465
|
+
return { checked: unverified(failure.killed ? "O Python selecionado n\xE3o concluiu a verifica\xE7\xE3o no tempo dispon\xEDvel." : "N\xE3o foi poss\xEDvel verificar o Python selecionado.", interpreter) };
|
|
27466
|
+
}
|
|
27467
|
+
}
|
|
27468
|
+
async function probeSavedPython(interpreter) {
|
|
27469
|
+
const outcome = await probePython(interpreter);
|
|
27470
|
+
if (outcome.checked.interpreter && outcome.checked.interpreter !== interpreter) {
|
|
27471
|
+
return { checked: selectPython("O caminho guardado aponta agora para outro Python. Selecione novamente o Python com --python.", interpreter) };
|
|
27472
|
+
}
|
|
27473
|
+
return outcome;
|
|
27474
|
+
}
|
|
27475
|
+
async function checkStartupPythonReadiness(paths) {
|
|
27476
|
+
let selection;
|
|
27477
|
+
try {
|
|
27478
|
+
selection = await readSelection(paths);
|
|
27479
|
+
} catch {
|
|
27480
|
+
return selectPython(selectionUnreadable);
|
|
27481
|
+
}
|
|
27482
|
+
if (!selection) return (await probePython(void 0)).checked;
|
|
27483
|
+
if (selection.preparing) {
|
|
27484
|
+
return unverified("A prepara\xE7\xE3o do Python ainda n\xE3o foi conclu\xEDda. Consulte o resultado da prepara\xE7\xE3o ou retome o comando prepare.", selection.interpreter);
|
|
27485
|
+
}
|
|
27486
|
+
const [key, cache] = await Promise.all([cacheKey(selection), readCache(paths)]);
|
|
27487
|
+
const age = cache ? Date.now() - Date.parse(cache.result.checkedAt) : Number.NaN;
|
|
27488
|
+
if (cache && key && cache.key === key && age >= 0 && age < CACHE_MAX_AGE_MS) {
|
|
27489
|
+
return { ...cache.result, cached: true };
|
|
27490
|
+
}
|
|
27491
|
+
const inFlightKey = JSON.stringify([paths.forgeDir, selection.revision, key]);
|
|
27492
|
+
const ongoing = startupChecks.get(inFlightKey);
|
|
27493
|
+
if (ongoing) return ongoing;
|
|
27494
|
+
const checking = (async () => {
|
|
27495
|
+
const { checked } = await probeSavedPython(selection.interpreter);
|
|
27496
|
+
const current = await readSelection(paths).catch(() => void 0);
|
|
27497
|
+
if (current?.revision !== selection.revision || current.preparing) {
|
|
27498
|
+
return unverified("A sele\xE7\xE3o do Python mudou durante a verifica\xE7\xE3o. Volte a verificar o Python.");
|
|
27499
|
+
}
|
|
27500
|
+
await saveCache(paths, key, checked);
|
|
27501
|
+
return checked;
|
|
27502
|
+
})();
|
|
27503
|
+
startupChecks.set(inFlightKey, checking);
|
|
27504
|
+
try {
|
|
27505
|
+
return await checking;
|
|
27506
|
+
} finally {
|
|
27507
|
+
startupChecks.delete(inFlightKey);
|
|
27508
|
+
}
|
|
27509
|
+
}
|
|
27510
|
+
|
|
27511
|
+
// packages/cli/src/workPackPythonStartup.ts
|
|
27512
|
+
var PREPARE_COMMAND = `npm exec --yes --package=minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION} -- forge-python prepare`;
|
|
27513
|
+
function startWorkPackPythonCheck(paths, report) {
|
|
27514
|
+
let latestCheck = 0;
|
|
27515
|
+
async function check2() {
|
|
27516
|
+
const checkId = ++latestCheck;
|
|
27517
|
+
const readiness = await checkStartupPythonReadiness(paths).catch(async () => ({
|
|
27518
|
+
status: "unverified",
|
|
27519
|
+
interpreter: await readSelectedPython(paths),
|
|
27520
|
+
reason: "N\xE3o foi poss\xEDvel concluir a verifica\xE7\xE3o de Python.",
|
|
27521
|
+
checkedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
27522
|
+
cached: false
|
|
27523
|
+
}));
|
|
27524
|
+
if (checkId === latestCheck) report(readiness);
|
|
27525
|
+
return readiness;
|
|
27526
|
+
}
|
|
27527
|
+
void readSelectedPython(paths).then((interpreter) => interpreter ? check2() : void 0);
|
|
27528
|
+
return {
|
|
27529
|
+
async skillInstruction(slug) {
|
|
27530
|
+
const requirements = await lstat8(path16.join(paths.skillsDir, slug, "requirements.txt")).catch(() => void 0);
|
|
27531
|
+
if (!requirements?.isFile()) return void 0;
|
|
27532
|
+
const readiness = await check2();
|
|
27533
|
+
const interpreter = readiness.interpreter ? interpreterInstruction(readiness.interpreter) : "Usa somente o Python escolhido na prepara\xE7\xE3o Forge.";
|
|
27534
|
+
if (readiness.status === "ready") return interpreter;
|
|
27535
|
+
if (canAutoRepairPython(readiness)) {
|
|
27536
|
+
return `${interpreter}
|
|
27537
|
+
${pythonIssueMessage(readiness)} Resolve isto automaticamente antes de executar os scripts Python desta skill: avisa a pessoa numa frase simples, sem termos t\xE9cnicos (n\xE3o fales em bibliotecas nem pacotes), que est\xE1s a atualizar rapidamente as ferramentas necess\xE1rias, executa ${PREPARE_COMMAND} e, se devolver status "ready", continua logo a tarefa usando o Python registado. S\xF3 pares e pe\xE7as ajuda ao suporte se a repara\xE7\xE3o falhar.`;
|
|
27538
|
+
}
|
|
27539
|
+
return `${interpreter}
|
|
27540
|
+
${pythonIssueMessage(readiness)} Informa a pessoa em linguagem simples, sem termos t\xE9cnicos, e aguarda que a prepara\xE7\xE3o seja conclu\xEDda antes de executar os scripts Python desta skill. Podes continuar as partes da tarefa que n\xE3o dependem de Python.`;
|
|
27541
|
+
}
|
|
27542
|
+
};
|
|
27543
|
+
}
|
|
27544
|
+
function canAutoRepairPython(readiness) {
|
|
27545
|
+
if (readiness.status !== "not-ready" || !readiness.interpreter || readiness.requiresPythonSelection) return false;
|
|
27546
|
+
return Boolean(readiness.packages?.some(({ status }) => status === "missing" || status === "incompatible"));
|
|
27547
|
+
}
|
|
27548
|
+
function pythonIssueKey(readiness) {
|
|
27549
|
+
if (readiness.status === "ready") return void 0;
|
|
27550
|
+
const failures = readiness.packages?.filter((item) => item.status !== "ready").map(({ name, status }) => [name, status]).sort();
|
|
27551
|
+
return createHash9("sha256").update(JSON.stringify([readiness.status, readiness.reason, failures ?? [], readiness.documents])).digest("hex");
|
|
27552
|
+
}
|
|
27553
|
+
function pythonIssueMessage(readiness) {
|
|
27554
|
+
const reason = readiness.reason ?? "A prepara\xE7\xE3o de Python est\xE1 por verificar neste computador.";
|
|
27555
|
+
const failedPackages = readiness.packages?.filter((item) => item.status !== "ready").map((item) => item.name) ?? [];
|
|
27556
|
+
const details = failedPackages.length ? ` Pacotes a verificar: ${failedPackages.join(", ")}.` : "";
|
|
27557
|
+
let action = `Para reparar automaticamente o ambiente registado, executa ${PREPARE_COMMAND}.`;
|
|
27558
|
+
if (!readiness.interpreter || readiness.requiresPythonSelection) {
|
|
27559
|
+
action = `Segue as instru\xE7\xF5es Forge para escolher um Python suportado e usa ${PREPARE_COMMAND} --python <caminho absoluto>.`;
|
|
27560
|
+
} else if (!canAutoRepairPython(readiness)) {
|
|
27561
|
+
action = "Consulta o resultado da verifica\xE7\xE3o e pede ajuda \xE0 equipa de suporte se necess\xE1rio.";
|
|
27562
|
+
}
|
|
27563
|
+
return `${reason}${details} ${action}`;
|
|
27564
|
+
}
|
|
27565
|
+
function interpreterInstruction(interpreter) {
|
|
27566
|
+
return `Para executar scripts Python desta skill, usa o caminho absoluto registado nesta m\xE1quina (string JSON): ${JSON.stringify(interpreter)}. Usa esse caminho com as aspas adequadas \xE0 shell em cada chamada e mant\xE9m o mesmo Python ao seguir os exemplos da skill que indiquem python, python3 ou py.`;
|
|
27567
|
+
}
|
|
27568
|
+
|
|
27146
27569
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
27147
|
-
var PLUGIN_VERSION = "0.1.
|
|
27570
|
+
var PLUGIN_VERSION = "0.1.58";
|
|
27148
27571
|
var FORGE_DECISION_TIMEOUT_MS = 11e4;
|
|
27149
27572
|
var STATUS_FILENAME = "work-pack-startup-status.json";
|
|
27573
|
+
var PYTHON_STATUS_FILENAME = "python-startup-status.json";
|
|
27150
27574
|
var activeSync = /* @__PURE__ */ new Map();
|
|
27151
27575
|
function isLocalConfig(options) {
|
|
27152
27576
|
return Boolean(options && typeof options === "object" && "localConfig" in options && options.localConfig === true);
|
|
@@ -27172,7 +27596,7 @@ function createForgeTools(forgeBaseUrl, state) {
|
|
|
27172
27596
|
function createEvidenceReporters(forgeBaseUrl, state) {
|
|
27173
27597
|
const reportEvidence = async (sessionID, callID, slug, kind) => {
|
|
27174
27598
|
const { forgeApiKey } = await readForgeCredentials(state.paths, forgeBaseUrl);
|
|
27175
|
-
const credentialId =
|
|
27599
|
+
const credentialId = createHash10("sha256").update(forgeApiKey).digest("hex");
|
|
27176
27600
|
const report = skillUsageReporter(forgeBaseUrl, credentialId, (events) => fetch(`${forgeBaseUrl}/sync/evidence`, {
|
|
27177
27601
|
method: "POST",
|
|
27178
27602
|
redirect: "error",
|
|
@@ -27183,7 +27607,7 @@ function createEvidenceReporters(forgeBaseUrl, state) {
|
|
|
27183
27607
|
report(sessionID, callID, slug, kind);
|
|
27184
27608
|
};
|
|
27185
27609
|
const reportReasoningLoop = (sessionID, outcome) => {
|
|
27186
|
-
reportEvidence(sessionID, `reasoning-loop:${
|
|
27610
|
+
reportEvidence(sessionID, `reasoning-loop:${randomUUID6()}`, outcome, "reasoning_loop").catch(() => {
|
|
27187
27611
|
console.error("[Forge evidence] Reasoning guard identity unavailable; event not queued");
|
|
27188
27612
|
});
|
|
27189
27613
|
};
|
|
@@ -27191,7 +27615,7 @@ function createEvidenceReporters(forgeBaseUrl, state) {
|
|
|
27191
27615
|
const slug = typeof name === "string" ? name.trim().toLowerCase() : "";
|
|
27192
27616
|
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug)) return;
|
|
27193
27617
|
try {
|
|
27194
|
-
await
|
|
27618
|
+
await readFile16(path17.join(state.paths.skillsDir, slug, ".forge-version"), "utf8");
|
|
27195
27619
|
} catch {
|
|
27196
27620
|
return;
|
|
27197
27621
|
}
|
|
@@ -27206,7 +27630,7 @@ function createEvidenceReporters(forgeBaseUrl, state) {
|
|
|
27206
27630
|
var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
27207
27631
|
const forgeBaseUrl = parseForgeBaseUrl(options);
|
|
27208
27632
|
const state = await startupSync(forgeBaseUrl, isLocalConfig(options), () => observeRuntime(_input), _input);
|
|
27209
|
-
const legacyPath =
|
|
27633
|
+
const legacyPath = path17.join(state.paths.pluginDir, FORGE_EVIDENCE_PLUGIN_FILENAME);
|
|
27210
27634
|
const ownershipSymbol = /* @__PURE__ */ Symbol.for("minimal-forge.legacy-evidence-owners.v1");
|
|
27211
27635
|
const shared = globalThis;
|
|
27212
27636
|
const legacyOwners = shared[ownershipSymbol] ??= /* @__PURE__ */ new Set();
|
|
@@ -27218,6 +27642,7 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
|
27218
27642
|
return {
|
|
27219
27643
|
...client ? { event: createReasoningLoopGuard(client, console.error, reportReasoningLoop) } : {},
|
|
27220
27644
|
"experimental.chat.system.transform": async (_input2, output) => {
|
|
27645
|
+
output.system.push(FORGE_COMPUTER_USE_INSTRUCTION);
|
|
27221
27646
|
if (skills.active) output.system.push(MANAGED_SKILL_INSTRUCTION);
|
|
27222
27647
|
},
|
|
27223
27648
|
"tool.execute.before": async (input, output) => skills.assertWritable(input.tool, output.args, directory),
|
|
@@ -27226,7 +27651,7 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
|
27226
27651
|
const official = await skills.load(input.args?.name);
|
|
27227
27652
|
if (official) {
|
|
27228
27653
|
output.title = official.title;
|
|
27229
|
-
output.output = official.
|
|
27654
|
+
output.output = await skillOutput(official, state.python);
|
|
27230
27655
|
output.metadata = official.metadata;
|
|
27231
27656
|
}
|
|
27232
27657
|
if (official?.loaded === false || legacyOwners.has(legacyOwnerKey)) return;
|
|
@@ -27238,7 +27663,7 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
|
27238
27663
|
const name = Array.isArray(entry) ? entry[0] : entry;
|
|
27239
27664
|
return name === legacyPath || name === pathToFileURL(legacyPath).href;
|
|
27240
27665
|
});
|
|
27241
|
-
const legacy = registered ? await
|
|
27666
|
+
const legacy = registered ? await readFile16(legacyPath, "utf8").catch(() => "") : "";
|
|
27242
27667
|
const oldLegacyRegistered = registered && legacy.startsWith(FORGE_PLUGIN_HEADER) && legacy.includes("work_pack_invocation") && !legacy.includes("minimal-forge.skill-usage.v1");
|
|
27243
27668
|
if (oldLegacyRegistered) legacyOwners.add(legacyOwnerKey);
|
|
27244
27669
|
if (oldLegacyRegistered) await writeFile9(legacyPath, renderEvidencePlugin()).catch(() => {
|
|
@@ -27263,7 +27688,7 @@ async function ForgeWorkPackSyncSetup(ctx) {
|
|
|
27263
27688
|
throw new Error("A pasta do motor ativo mudou. Confirme a liga\xE7\xE3o Forge neste perfil do OpenWork.");
|
|
27264
27689
|
}
|
|
27265
27690
|
const credentials = await readForgeCredentials(state.paths, forgeBaseUrl);
|
|
27266
|
-
const canonical = objectRecord2(parseJsonc(await
|
|
27691
|
+
const canonical = objectRecord2(parseJsonc(await readFile16(state.paths.opencodeConfigPath, "utf8")));
|
|
27267
27692
|
const config2 = renderOpenworkEngineConfig(state.manifest, credentials, state.paths, directory, canonical);
|
|
27268
27693
|
if (state.partialWorkPackSync) {
|
|
27269
27694
|
const companion = await inspectOpenworkEngineConfig(directory);
|
|
@@ -27280,8 +27705,8 @@ async function ForgeWorkPackSyncSetup(ctx) {
|
|
|
27280
27705
|
syncedTools.catch(() => void 0);
|
|
27281
27706
|
const { reportReasoningLoop, reportSkillInvocation } = createEvidenceReporters(forgeBaseUrl, { paths });
|
|
27282
27707
|
const managedSkills = sync.then(
|
|
27283
|
-
(state) => managedSkillSession(paths, state.manifest ?? state.failedManifest),
|
|
27284
|
-
() => managedSkillSession(paths)
|
|
27708
|
+
async (state) => ({ skills: await managedSkillSession(paths, state.manifest ?? state.failedManifest), python: state.python }),
|
|
27709
|
+
async () => ({ skills: await managedSkillSession(paths), python: void 0 })
|
|
27285
27710
|
);
|
|
27286
27711
|
const directoryOf = sessionDirectoryResolver(ctx);
|
|
27287
27712
|
const registrations = Object.entries(createForgeTools(forgeBaseUrl, { paths, decisionBaseUrl: forgeBaseUrl })).filter(([name]) => name !== "forge_feedback" || typeof ctx.permission?.assert === "function").map(([name, shape]) => openCode2Tool(name, {
|
|
@@ -27297,14 +27722,20 @@ async function ForgeWorkPackSyncSetup(ctx) {
|
|
|
27297
27722
|
for (const registration of registrations) editor.add(registration);
|
|
27298
27723
|
});
|
|
27299
27724
|
await ctx.tool.hook("execute.before", async (event) => {
|
|
27725
|
+
if (isComputerUseTool(event.tool)) {
|
|
27726
|
+
await assertComputerUsePermission(ctx, event);
|
|
27727
|
+
return;
|
|
27728
|
+
}
|
|
27300
27729
|
if (!["edit", "write", "patch", "apply_patch"].includes(event.tool)) return;
|
|
27301
|
-
|
|
27730
|
+
const { skills } = await managedSkills;
|
|
27731
|
+
await skills.assertWritable(event.tool, event.input, ctx.location.directory);
|
|
27302
27732
|
});
|
|
27303
27733
|
await ctx.tool.hook("execute.after", async (event) => {
|
|
27304
27734
|
const call = completedSkillCall(event);
|
|
27305
27735
|
if (!call || event.status !== "completed") return;
|
|
27306
|
-
const
|
|
27307
|
-
|
|
27736
|
+
const { skills, python } = await managedSkills;
|
|
27737
|
+
const official = await skills.load(call.name);
|
|
27738
|
+
if (official) event.result = { content: await skillOutput(official, python), metadata: official.metadata };
|
|
27308
27739
|
if (official?.loaded === false) return;
|
|
27309
27740
|
try {
|
|
27310
27741
|
await reportSkillInvocation(call.sessionID, call.callID, call.name);
|
|
@@ -27314,6 +27745,68 @@ async function ForgeWorkPackSyncSetup(ctx) {
|
|
|
27314
27745
|
});
|
|
27315
27746
|
return startReasoningLoopGuard(ctx, reportReasoningLoop);
|
|
27316
27747
|
}
|
|
27748
|
+
function isComputerUseTool(name) {
|
|
27749
|
+
return name.startsWith("computer_") || name.startsWith("computer-use_");
|
|
27750
|
+
}
|
|
27751
|
+
function describeComputerUseResource(toolName, input) {
|
|
27752
|
+
if (input && typeof input === "object" && !Array.isArray(input)) {
|
|
27753
|
+
const record2 = input;
|
|
27754
|
+
for (const key of ["app_id", "app", "application", "target", "window", "url", "action", "command"]) {
|
|
27755
|
+
const value = record2[key];
|
|
27756
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
27757
|
+
return `${toolName}: ${value.trim().slice(0, 120)}`;
|
|
27758
|
+
}
|
|
27759
|
+
}
|
|
27760
|
+
}
|
|
27761
|
+
return toolName;
|
|
27762
|
+
}
|
|
27763
|
+
var SENSITIVE_KEY_PATTERN = /(password|passphrase|secret|token|api[_-]?key)/i;
|
|
27764
|
+
var SECRET_VALUE_KEYS = /* @__PURE__ */ new Set(["text", "value", "input", "keys", "content"]);
|
|
27765
|
+
function sanitizeComputerUseValue(value, insideSecret = false) {
|
|
27766
|
+
if (Array.isArray(value)) {
|
|
27767
|
+
return value.map((item) => sanitizeComputerUseValue(item, insideSecret));
|
|
27768
|
+
}
|
|
27769
|
+
if (!value || typeof value !== "object") return value;
|
|
27770
|
+
const record2 = value;
|
|
27771
|
+
const isSecretRecord = insideSecret || record2.secret === true;
|
|
27772
|
+
const sanitized = {};
|
|
27773
|
+
for (const [key, entry] of Object.entries(record2)) {
|
|
27774
|
+
if (key === "secret" && typeof entry === "boolean") {
|
|
27775
|
+
sanitized[key] = entry;
|
|
27776
|
+
} else if (SENSITIVE_KEY_PATTERN.test(key) || isSecretRecord && SECRET_VALUE_KEYS.has(key)) {
|
|
27777
|
+
sanitized[key] = "[redacted]";
|
|
27778
|
+
} else {
|
|
27779
|
+
sanitized[key] = sanitizeComputerUseValue(entry, isSecretRecord);
|
|
27780
|
+
}
|
|
27781
|
+
}
|
|
27782
|
+
return sanitized;
|
|
27783
|
+
}
|
|
27784
|
+
async function assertComputerUsePermission(ctx, event) {
|
|
27785
|
+
event.signal?.throwIfAborted();
|
|
27786
|
+
if (typeof ctx.permission?.assert !== "function" || !event.sessionID) {
|
|
27787
|
+
throw new Error("O controlo do computador requer aprova\xE7\xE3o expl\xEDcita, mas este motor n\xE3o exp\xF4s o pedido de permiss\xE3o. Atualize o OpenWork.");
|
|
27788
|
+
}
|
|
27789
|
+
const inputRecord = event.input && typeof event.input === "object" && !Array.isArray(event.input) ? sanitizeComputerUseValue(event.input) : void 0;
|
|
27790
|
+
await ctx.permission.assert({
|
|
27791
|
+
sessionID: event.sessionID,
|
|
27792
|
+
...event.agent ? { agent: event.agent } : {},
|
|
27793
|
+
action: event.tool,
|
|
27794
|
+
resources: [describeComputerUseResource(event.tool, event.input)],
|
|
27795
|
+
save: [],
|
|
27796
|
+
metadata: {
|
|
27797
|
+
tool: event.tool,
|
|
27798
|
+
...inputRecord ? { input: inputRecord } : {}
|
|
27799
|
+
},
|
|
27800
|
+
...event.messageID && event.id ? { source: { type: "tool", messageID: event.messageID, id: event.id } } : {}
|
|
27801
|
+
});
|
|
27802
|
+
event.signal?.throwIfAborted();
|
|
27803
|
+
}
|
|
27804
|
+
async function skillOutput(official, python) {
|
|
27805
|
+
const instruction = official.loaded ? await python?.skillInstruction(official.metadata.name) : void 0;
|
|
27806
|
+
return instruction ? `${instruction}
|
|
27807
|
+
|
|
27808
|
+
${official.output}` : official.output;
|
|
27809
|
+
}
|
|
27317
27810
|
function reasoningLoopGuardClient(input) {
|
|
27318
27811
|
if (!input || typeof input !== "object" || !("client" in input)) return void 0;
|
|
27319
27812
|
const client = input.client;
|
|
@@ -27330,10 +27823,10 @@ function createForgeImageTool(forgeBaseUrl, gatewayBaseUrl, paths) {
|
|
|
27330
27823
|
referencePath: tool.schema.string().optional().describe("Caminho absoluto de uma imagem PNG, JPEG ou WebP a editar, at\xE9 2,5 MB")
|
|
27331
27824
|
},
|
|
27332
27825
|
async execute(args, context) {
|
|
27333
|
-
const requestId =
|
|
27826
|
+
const requestId = randomUUID6();
|
|
27334
27827
|
let referenceDataUrl;
|
|
27335
27828
|
if (args.referencePath) {
|
|
27336
|
-
const bytes = await
|
|
27829
|
+
const bytes = await readFile16(args.referencePath);
|
|
27337
27830
|
if (bytes.byteLength > 25e5) throw new Error("A imagem de refer\xEAncia \xE9 demasiado grande. Reduza-a antes de tentar novamente.");
|
|
27338
27831
|
const mime = bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])) ? "image/png" : bytes.subarray(0, 3).equals(Buffer.from([255, 216, 255])) ? "image/jpeg" : bytes.subarray(0, 4).toString() === "RIFF" && bytes.subarray(8, 12).toString() === "WEBP" ? "image/webp" : void 0;
|
|
27339
27832
|
if (!mime) throw new Error("A refer\xEAncia tem de ser PNG, JPEG ou WebP.");
|
|
@@ -27359,14 +27852,14 @@ function createForgeImageTool(forgeBaseUrl, gatewayBaseUrl, paths) {
|
|
|
27359
27852
|
if (image.byteLength > 8 * 1024 * 1024 || !image.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) {
|
|
27360
27853
|
throw new Error(`O PNG recebido \xE9 inv\xE1lido. Refer\xEAncia: ${requestId}`);
|
|
27361
27854
|
}
|
|
27362
|
-
const destination =
|
|
27855
|
+
const destination = path17.join(context.directory, `forge-image-${requestId}.png`);
|
|
27363
27856
|
await writeFile9(destination, image, { flag: "wx" });
|
|
27364
27857
|
const reset = body.quota && new Intl.DateTimeFormat("pt-PT", { dateStyle: "long", timeZone: "Europe/Lisbon" }).format(new Date(body.quota.resetsAt));
|
|
27365
27858
|
const remaining = body.quota ? ` Restam ${body.quota.remaining} imagens at\xE9 ${reset}.` : "";
|
|
27366
27859
|
return {
|
|
27367
27860
|
title: "Imagem criada",
|
|
27368
27861
|
output: `Imagem guardada em ${destination}.${remaining} A pessoa j\xE1 v\xEA a imagem na conversa. Se n\xE3o a conseguires ver, isso n\xE3o \xE9 um erro: n\xE3o o reportes.`,
|
|
27369
|
-
attachments: [{ type: "file", mime: "image/png", url: `data:image/png;base64,${body.b64_json}`, filename:
|
|
27862
|
+
attachments: [{ type: "file", mime: "image/png", url: `data:image/png;base64,${body.b64_json}`, filename: path17.basename(destination) }]
|
|
27370
27863
|
};
|
|
27371
27864
|
}
|
|
27372
27865
|
});
|
|
@@ -27408,9 +27901,9 @@ function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths, responseD
|
|
|
27408
27901
|
let requestBody;
|
|
27409
27902
|
if (fromFile) {
|
|
27410
27903
|
const file2 = await fileInsideWorkspace(context.directory, args.request_file);
|
|
27411
|
-
const planFile =
|
|
27412
|
-
if (!responseDirectory &&
|
|
27413
|
-
const plan = JSON.parse(await
|
|
27904
|
+
const planFile = path17.join(path17.dirname(path17.dirname(file2)), "plan.json");
|
|
27905
|
+
if (!responseDirectory && path17.basename(path17.dirname(file2)) === "requests" && await fileExists(planFile)) {
|
|
27906
|
+
const plan = JSON.parse(await readFile16(planFile, "utf8"));
|
|
27414
27907
|
if (plan?.engine === "jev-batch" && plan.model === "typesafe/jev-1.13" && Array.isArray(plan.batches)) {
|
|
27415
27908
|
let batch;
|
|
27416
27909
|
for (const candidate of plan.batches) {
|
|
@@ -27423,7 +27916,7 @@ function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths, responseD
|
|
|
27423
27916
|
return createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths).execute({ plan_file: planFile, batch_id: batch.batch_id }, context);
|
|
27424
27917
|
}
|
|
27425
27918
|
}
|
|
27426
|
-
const raw = await
|
|
27919
|
+
const raw = await readFile16(file2, "utf8");
|
|
27427
27920
|
if (Buffer.byteLength(raw) > 512 * 1024) throw new Error("O ficheiro de pedido excede 512 KiB.");
|
|
27428
27921
|
let parsed;
|
|
27429
27922
|
try {
|
|
@@ -27442,11 +27935,11 @@ function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths, responseD
|
|
|
27442
27935
|
if (args.state === void 0 || !args.questions || Object.keys(args.questions).length === 0) throw new Error("Indica state e questions.");
|
|
27443
27936
|
requestBody = { state: args.state, questions: args.questions };
|
|
27444
27937
|
}
|
|
27445
|
-
const responseDir = await mkdtemp2(
|
|
27446
|
-
const responseFile =
|
|
27938
|
+
const responseDir = await mkdtemp2(path17.join(responseDirectory ?? context.directory, ".forge-decision-"));
|
|
27939
|
+
const responseFile = path17.join(responseDir, "response.json");
|
|
27447
27940
|
try {
|
|
27448
27941
|
const credentials = await readForgeCredentials(paths, forgeBaseUrl);
|
|
27449
|
-
const probeFile =
|
|
27942
|
+
const probeFile = path17.join(responseDir, ".write-test");
|
|
27450
27943
|
await writeFile9(probeFile, "", { flag: "wx", mode: 384 });
|
|
27451
27944
|
await unlink2(probeFile);
|
|
27452
27945
|
context.abort.throwIfAborted();
|
|
@@ -27496,24 +27989,24 @@ function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths, responseD
|
|
|
27496
27989
|
}
|
|
27497
27990
|
async function fileInsideWorkspace(directory, candidate) {
|
|
27498
27991
|
const workspace = await realpath3(directory);
|
|
27499
|
-
const file2 = await realpath3(
|
|
27500
|
-
const relative =
|
|
27501
|
-
if (!relative || (relative === ".." || relative.startsWith(`..${
|
|
27992
|
+
const file2 = await realpath3(path17.resolve(workspace, candidate));
|
|
27993
|
+
const relative = path17.relative(workspace, file2);
|
|
27994
|
+
if (!relative || (relative === ".." || relative.startsWith(`..${path17.sep}`)) || path17.isAbsolute(relative)) throw new Error("O ficheiro tem de estar dentro do workspace.");
|
|
27502
27995
|
return file2;
|
|
27503
27996
|
}
|
|
27504
27997
|
async function fileExists(candidate) {
|
|
27505
27998
|
try {
|
|
27506
|
-
await
|
|
27999
|
+
await stat4(candidate);
|
|
27507
28000
|
return true;
|
|
27508
28001
|
} catch (error45) {
|
|
27509
28002
|
if (error45.code === "ENOENT") return false;
|
|
27510
28003
|
throw error45;
|
|
27511
28004
|
}
|
|
27512
28005
|
}
|
|
27513
|
-
async function ensureJevDirectory(directory, filesystem = { stat:
|
|
28006
|
+
async function ensureJevDirectory(directory, filesystem = { stat: stat4, mkdir: mkdir8 }) {
|
|
27514
28007
|
try {
|
|
27515
28008
|
if ((await filesystem.stat(directory)).isDirectory()) return;
|
|
27516
|
-
throw new Error(`O destino ${
|
|
28009
|
+
throw new Error(`O destino ${path17.basename(directory)} existe, mas n\xE3o \xE9 uma pasta. Preservar o conte\xFAdo e verificar o caminho.`);
|
|
27517
28010
|
} catch (error45) {
|
|
27518
28011
|
if (error45.code !== "ENOENT") throw error45;
|
|
27519
28012
|
}
|
|
@@ -27545,7 +28038,7 @@ function validSmallDecision(answer, question) {
|
|
|
27545
28038
|
return Object.keys(criteria).length === Object.keys(probabilities).length && Object.keys(criteria).every((key) => decisionProbability(probabilities[key]));
|
|
27546
28039
|
}
|
|
27547
28040
|
async function validateSavedDecision(file2, request, smallPlan) {
|
|
27548
|
-
const body = JSON.parse(await
|
|
28041
|
+
const body = JSON.parse(await readFile16(file2, "utf8"));
|
|
27549
28042
|
const answers = body.answers;
|
|
27550
28043
|
const questions = request.questions;
|
|
27551
28044
|
const usage = body.usage;
|
|
@@ -27569,19 +28062,19 @@ async function acquireJevRunLock(lockDir) {
|
|
|
27569
28062
|
let owner;
|
|
27570
28063
|
let ownerRaw;
|
|
27571
28064
|
try {
|
|
27572
|
-
ownerRaw = await
|
|
28065
|
+
ownerRaw = await readFile16(path17.join(lockDir, "owner.json"), "utf8");
|
|
27573
28066
|
owner = JSON.parse(ownerRaw);
|
|
27574
28067
|
} catch {
|
|
27575
28068
|
throw new Error("Chamada interrompida com lock sem identifica\xE7\xE3o; n\xE3o \xE9 poss\xEDvel confirmar que terminou. Preservar o lock e verificar a execu\xE7\xE3o.");
|
|
27576
28069
|
}
|
|
27577
|
-
if (!Number.isInteger(owner.pid) || owner.pid <= 0 || owner.hostname && owner.hostname !==
|
|
28070
|
+
if (!Number.isInteger(owner.pid) || owner.pid <= 0 || owner.hostname && owner.hostname !== os6.hostname()) {
|
|
27578
28071
|
throw new Error("N\xE3o \xE9 poss\xEDvel confirmar que a execu\xE7\xE3o do lock terminou nesta m\xE1quina. Preservar o lock.");
|
|
27579
28072
|
}
|
|
27580
28073
|
try {
|
|
27581
28074
|
process.kill(owner.pid, 0);
|
|
27582
28075
|
} catch (error45) {
|
|
27583
28076
|
if (error45.code === "ESRCH") {
|
|
27584
|
-
const archived = `${lockDir}.interrupted-${
|
|
28077
|
+
const archived = `${lockDir}.interrupted-${createHash10("sha256").update(ownerRaw).digest("hex")}`;
|
|
27585
28078
|
await rename9(lockDir, archived);
|
|
27586
28079
|
try {
|
|
27587
28080
|
await mkdir8(lockDir);
|
|
@@ -27603,38 +28096,38 @@ function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
27603
28096
|
},
|
|
27604
28097
|
async execute(args, context) {
|
|
27605
28098
|
const planFile = await fileInsideWorkspace(context.directory, args.plan_file);
|
|
27606
|
-
if (
|
|
27607
|
-
const runDir =
|
|
27608
|
-
const plan = objectRecord2(JSON.parse(await
|
|
28099
|
+
if (path17.basename(planFile) !== "plan.json" || path17.basename(path17.dirname(planFile)) !== "jev") throw new Error("Indica o ficheiro jev/plan.json.");
|
|
28100
|
+
const runDir = path17.dirname(path17.dirname(planFile));
|
|
28101
|
+
const plan = objectRecord2(JSON.parse(await readFile16(planFile, "utf8")));
|
|
27609
28102
|
const smallPlan = plan.schema_version === 2 && Array.isArray(plan.requests) && plan.batches === void 0;
|
|
27610
28103
|
if (plan.engine !== "jev-batch" || plan.model !== "typesafe/jev-1.13" || !smallPlan && (!Array.isArray(plan.batches) || plan.requests !== void 0)) throw new Error("O plano Jev \xE9 inv\xE1lido.");
|
|
27611
28104
|
const allBatches = smallPlan ? plan.requests.map((request, index) => {
|
|
27612
28105
|
const id = String(index).padStart(4, "0");
|
|
27613
28106
|
return {
|
|
27614
28107
|
batch_id: id,
|
|
27615
|
-
request_file:
|
|
27616
|
-
request_fingerprint:
|
|
28108
|
+
request_file: path17.join(runDir, "jev", "requests", `${id}.json`),
|
|
28109
|
+
request_fingerprint: createHash10("sha256").update(canonicalJson(request)).digest("hex")
|
|
27617
28110
|
};
|
|
27618
28111
|
}) : plan.batches.map(objectRecord2);
|
|
27619
28112
|
const batches = args.batch_id ? allBatches.filter((batch) => batch.batch_id === args.batch_id) : allBatches;
|
|
27620
28113
|
if (args.batch_id && batches.length !== 1) throw new Error("O lote indicado n\xE3o pertence ao plano Jev.");
|
|
27621
|
-
const responsePath =
|
|
28114
|
+
const responsePath = path17.join(runDir, "jev", "responses");
|
|
27622
28115
|
await ensureJevDirectory(responsePath);
|
|
27623
28116
|
const responseDir = await fileInsideWorkspace(context.directory, responsePath);
|
|
27624
|
-
if (
|
|
27625
|
-
const lockDir =
|
|
28117
|
+
if (path17.dirname(responseDir) !== path17.join(runDir, "jev")) throw new Error("A pasta de respostas tem de pertencer ao run Jev.");
|
|
28118
|
+
const lockDir = path17.join(runDir, "jev", ".decide-run.lock");
|
|
27626
28119
|
const interrupted = await acquireJevRunLock(lockDir);
|
|
27627
28120
|
let saved = 0;
|
|
27628
28121
|
let skipped = 0;
|
|
27629
28122
|
let recovered = 0;
|
|
27630
28123
|
const repeated = [];
|
|
27631
28124
|
try {
|
|
27632
|
-
const ownerFile =
|
|
27633
|
-
await writeOwnerOnlyTextAtomic(ownerFile, JSON.stringify({ ...interrupted, pid: process.pid, hostname:
|
|
27634
|
-
const attemptsPath =
|
|
28125
|
+
const ownerFile = path17.join(lockDir, "owner.json");
|
|
28126
|
+
await writeOwnerOnlyTextAtomic(ownerFile, JSON.stringify({ ...interrupted, pid: process.pid, hostname: os6.hostname(), started_at: (/* @__PURE__ */ new Date()).toISOString() }));
|
|
28127
|
+
const attemptsPath = path17.join(runDir, "jev", "attempts");
|
|
27635
28128
|
await ensureJevDirectory(attemptsPath);
|
|
27636
28129
|
const attemptsDir = await fileInsideWorkspace(context.directory, attemptsPath);
|
|
27637
|
-
if (
|
|
28130
|
+
if (path17.dirname(attemptsDir) !== path17.join(runDir, "jev")) throw new Error("A pasta de tentativas tem de pertencer ao run Jev.");
|
|
27638
28131
|
for (const batch of batches) {
|
|
27639
28132
|
context.abort.throwIfAborted();
|
|
27640
28133
|
const batchId = batch.batch_id;
|
|
@@ -27642,17 +28135,17 @@ function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
27642
28135
|
if (typeof batchId !== "string" || !validBatchId.test(batchId) || typeof batch.request_file !== "string" || typeof batch.request_fingerprint !== "string") {
|
|
27643
28136
|
throw new Error("O plano Jev cont\xE9m um lote inv\xE1lido.");
|
|
27644
28137
|
}
|
|
27645
|
-
const acceptedFile =
|
|
27646
|
-
const responseFile =
|
|
28138
|
+
const acceptedFile = path17.join(runDir, "jev", "accepted", `${batchId}.json`);
|
|
28139
|
+
const responseFile = path17.join(responseDir, smallPlan ? `${batchId}.json` : `${batchId}.response.json`);
|
|
27647
28140
|
const requestFile = await fileInsideWorkspace(context.directory, batch.request_file);
|
|
27648
|
-
if (
|
|
27649
|
-
const rawRequest = await
|
|
28141
|
+
if (path17.dirname(requestFile) !== path17.join(runDir, "jev", "requests")) throw new Error(`${batchId}: pedido fora do run.`);
|
|
28142
|
+
const rawRequest = await readFile16(requestFile, "utf8");
|
|
27650
28143
|
if (Buffer.byteLength(rawRequest) > 512 * 1024) throw new Error("O ficheiro de pedido excede 512 KiB.");
|
|
27651
28144
|
const request = objectRecord2(JSON.parse(rawRequest));
|
|
27652
28145
|
const questions = objectRecord2(request.questions);
|
|
27653
28146
|
if (request.state === void 0 || !Object.keys(questions).length) throw new Error("O pedido deve conter state e questions.");
|
|
27654
28147
|
if (request.model !== void 0 && request.model !== plan.model) throw new Error("O modelo do pedido n\xE3o corresponde ao Jev configurado.");
|
|
27655
|
-
const fingerprint =
|
|
28148
|
+
const fingerprint = createHash10("sha256").update(canonicalJson(request)).digest("hex");
|
|
27656
28149
|
if (fingerprint !== batch.request_fingerprint) throw new Error(`${batchId}: fingerprint do pedido n\xE3o corresponde ao plano.`);
|
|
27657
28150
|
if (await fileExists(acceptedFile)) {
|
|
27658
28151
|
if (smallPlan) {
|
|
@@ -27673,9 +28166,9 @@ function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
27673
28166
|
skipped++;
|
|
27674
28167
|
continue;
|
|
27675
28168
|
}
|
|
27676
|
-
const attemptsFile =
|
|
28169
|
+
const attemptsFile = path17.join(attemptsDir, `${batchId}.json`);
|
|
27677
28170
|
let attempts = { request_fingerprint: fingerprint, attempts: 0, response_files: [] };
|
|
27678
|
-
if (await fileExists(attemptsFile)) attempts = JSON.parse(await
|
|
28171
|
+
if (await fileExists(attemptsFile)) attempts = JSON.parse(await readFile16(attemptsFile, "utf8"));
|
|
27679
28172
|
else if (interrupted.batch_id === batchId) {
|
|
27680
28173
|
if (interrupted.request_fingerprint !== fingerprint) throw new Error(`${batchId}: fingerprint da chamada interrompida n\xE3o corresponde ao plano.`);
|
|
27681
28174
|
attempts.attempts = 1;
|
|
@@ -27688,13 +28181,13 @@ function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
27688
28181
|
if (!await fileExists(attemptsFile) && attempts.attempts > 0) await persistAttempts();
|
|
27689
28182
|
const stop = (error45, detail = {}) => JSON.stringify({ verified: false, saved, skipped, recovered, repeated, stopped_at: batchId, ...detail, error: error45 });
|
|
27690
28183
|
const recoverResponse = async () => {
|
|
27691
|
-
const legacyAllocations = interrupted.batch_id === batchId && interrupted.request_fingerprint === fingerprint ? (await readdir8(responseDir)).filter((name) => name.startsWith(".forge-decision-")).map((name) =>
|
|
28184
|
+
const legacyAllocations = interrupted.batch_id === batchId && interrupted.request_fingerprint === fingerprint ? (await readdir8(responseDir)).filter((name) => name.startsWith(".forge-decision-")).map((name) => path17.join(responseDir, name, "response.json")) : [];
|
|
27692
28185
|
const candidates = [...attempts.response_files, ...legacyAllocations];
|
|
27693
28186
|
for (const candidate of new Set(candidates)) {
|
|
27694
28187
|
if (typeof candidate !== "string") throw new Error("Registo de recupera\xE7\xE3o inv\xE1lido.");
|
|
27695
28188
|
if (!await fileExists(candidate)) continue;
|
|
27696
28189
|
const file2 = await fileInsideWorkspace(context.directory, candidate);
|
|
27697
|
-
if (
|
|
28190
|
+
if (path17.dirname(path17.dirname(file2)) !== responseDir) throw new Error("Resposta recuper\xE1vel fora da pasta do lote.");
|
|
27698
28191
|
try {
|
|
27699
28192
|
await validateSavedDecision(file2, request, smallPlan);
|
|
27700
28193
|
} catch {
|
|
@@ -27715,15 +28208,15 @@ function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
27715
28208
|
if (attempts.attempts >= 2) return stop("A \xFAnica repeti\xE7\xE3o deste lote j\xE1 foi usada. Preservar o progresso e recuperar a resposta do hist\xF3rico acess\xEDvel.");
|
|
27716
28209
|
const previousAttempts = attempts.attempts;
|
|
27717
28210
|
const decide = createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths, responseDir, async (allocated) => {
|
|
27718
|
-
await writeOwnerOnlyTextAtomic(ownerFile, JSON.stringify({ pid: process.pid, hostname:
|
|
28211
|
+
await writeOwnerOnlyTextAtomic(ownerFile, JSON.stringify({ pid: process.pid, hostname: os6.hostname(), batch_id: batchId, request_fingerprint: fingerprint, started_at: (/* @__PURE__ */ new Date()).toISOString() }));
|
|
27719
28212
|
const next = { ...attempts, attempts: attempts.attempts + 1, response_files: [...attempts.response_files, allocated] };
|
|
27720
28213
|
if (next.attempts === 2) next.repeated_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
27721
28214
|
await writeOwnerOnlyTextAtomic(attemptsFile, JSON.stringify(next));
|
|
27722
28215
|
attempts = next;
|
|
27723
28216
|
});
|
|
27724
|
-
let
|
|
28217
|
+
let result2;
|
|
27725
28218
|
try {
|
|
27726
|
-
|
|
28219
|
+
result2 = JSON.parse(await decide.execute({ state: request.state, questions }, context));
|
|
27727
28220
|
} catch (error45) {
|
|
27728
28221
|
if (error45 instanceof ForgeDecisionRejectedError) {
|
|
27729
28222
|
attempts.attempts = previousAttempts;
|
|
@@ -27739,8 +28232,8 @@ function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
27739
28232
|
continue;
|
|
27740
28233
|
}
|
|
27741
28234
|
if (attempts.attempts === 2 && !repeated.includes(batchId)) repeated.push(batchId);
|
|
27742
|
-
if (typeof
|
|
27743
|
-
source =
|
|
28235
|
+
if (typeof result2.response_file !== "string") return stop(String(result2.persistence_error), { recovery_response: result2, persistence_code: result2.persistence_code });
|
|
28236
|
+
source = result2.response_file;
|
|
27744
28237
|
try {
|
|
27745
28238
|
await validateSavedDecision(source, request, smallPlan);
|
|
27746
28239
|
} catch (error45) {
|
|
@@ -27753,7 +28246,7 @@ function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
27753
28246
|
let identical = false;
|
|
27754
28247
|
if (error45.code === "EEXIST") {
|
|
27755
28248
|
try {
|
|
27756
|
-
identical = await
|
|
28249
|
+
identical = await readFile16(source, "utf8") === await readFile16(responseFile, "utf8");
|
|
27757
28250
|
} catch {
|
|
27758
28251
|
}
|
|
27759
28252
|
}
|
|
@@ -27761,7 +28254,7 @@ function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
27761
28254
|
return stop("Resposta conclu\xEDda mas n\xE3o guardada no destino do lote; resolver a grava\xE7\xE3o e retomar sem nova chamada.", { recovery_file: source, persistence_code: error45.code });
|
|
27762
28255
|
}
|
|
27763
28256
|
}
|
|
27764
|
-
await unlink2(source).then(() => rmdir2(
|
|
28257
|
+
await unlink2(source).then(() => rmdir2(path17.dirname(source))).catch(() => void 0);
|
|
27765
28258
|
saved++;
|
|
27766
28259
|
if (args.batch_id) return JSON.stringify({ ...await validateSavedDecision(responseFile, request, smallPlan), response_file: responseFile, repeated });
|
|
27767
28260
|
}
|
|
@@ -27857,26 +28350,21 @@ async function synchronizeAtStartup(forgeBaseUrl, observe, localConfig, input) {
|
|
|
27857
28350
|
manifest = await fetchManifest(credentials, PLUGIN_VERSION);
|
|
27858
28351
|
decisionBaseUrl = resolveDecisionBaseUrl(manifest.gatewayBaseUrl, forgeBaseUrl);
|
|
27859
28352
|
forgeConfigVerified = true;
|
|
27860
|
-
const
|
|
28353
|
+
const result2 = localConfig ? await syncLocalWorker(paths, credentials, manifest) : await applyWorkPackManifest(paths, credentials, manifest, {});
|
|
27861
28354
|
if (localConfig) {
|
|
27862
|
-
appliedLocalSync = { manifest, partialWorkPackSync:
|
|
27863
|
-
const config2 = objectRecord2(parseJsonc(await
|
|
28355
|
+
appliedLocalSync = { manifest, partialWorkPackSync: result2 };
|
|
28356
|
+
const config2 = objectRecord2(parseJsonc(await readFile16(paths.opencodeConfigPath, "utf8")));
|
|
27864
28357
|
const targetVersion = configuredWorkPackSyncPluginVersion(config2);
|
|
27865
28358
|
if (targetVersion) pluginUpdate = { targetVersion, restartRequired: targetVersion !== PLUGIN_VERSION };
|
|
27866
28359
|
if (pluginUpdate?.restartRequired) {
|
|
27867
|
-
|
|
27868
|
-
console.info(`[Forge] ${message}`);
|
|
27869
|
-
const client = input && typeof input === "object" ? input.client : void 0;
|
|
27870
|
-
if (client?.tui?.showToast) {
|
|
27871
|
-
void Promise.resolve().then(() => client.tui.showToast({ body: { title: "Forge", message, variant: "info", duration: 1e4 } })).catch(() => void 0);
|
|
27872
|
-
}
|
|
28360
|
+
startupNotice(input, "Atualiza\xE7\xE3o preparada. Quando terminar o trabalho, feche e volte a abrir o OpenWork para a aplicar.", "info");
|
|
27873
28361
|
}
|
|
27874
28362
|
}
|
|
27875
|
-
await reportWorkPackObservations(credentials, "sync",
|
|
27876
|
-
const failures =
|
|
28363
|
+
await reportWorkPackObservations(credentials, "sync", result2.workPackObservations, runtime, PLUGIN_VERSION);
|
|
28364
|
+
const failures = result2.workPacks.outcomes.filter(
|
|
27877
28365
|
(outcome) => outcome.status === "failed" || outcome.status === "recovery-uncertain"
|
|
27878
28366
|
);
|
|
27879
|
-
if (failures.length > 0 ||
|
|
28367
|
+
if (failures.length > 0 || result2.workPacks.receipt.status === "failed") {
|
|
27880
28368
|
const summary = failures.map((outcome) => `${outcome.slug}:${outcome.code ?? outcome.status}`).join(", ");
|
|
27881
28369
|
throw new Error(`Sincroniza\xE7\xE3o autom\xE1tica de Work Packs falhou${summary ? ` (${summary})` : ""}`);
|
|
27882
28370
|
}
|
|
@@ -27885,12 +28373,13 @@ async function synchronizeAtStartup(forgeBaseUrl, observe, localConfig, input) {
|
|
|
27885
28373
|
version: 1,
|
|
27886
28374
|
pluginVersion: PLUGIN_VERSION,
|
|
27887
28375
|
...pluginUpdate ? { pluginUpdate } : {},
|
|
27888
|
-
status:
|
|
28376
|
+
status: result2.workPacks.receipt.status,
|
|
27889
28377
|
syncedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
27890
|
-
installed:
|
|
27891
|
-
removed:
|
|
28378
|
+
installed: result2.installed,
|
|
28379
|
+
removed: result2.removed
|
|
27892
28380
|
});
|
|
27893
|
-
|
|
28381
|
+
const python = watchStartupPython(paths, input);
|
|
28382
|
+
return { paths, before, after, forgeConfigVerified, decisionBaseUrl, manifest, python };
|
|
27894
28383
|
} catch (error45) {
|
|
27895
28384
|
const message = safeErrorMessage(error45);
|
|
27896
28385
|
console.error("[Forge work-pack sync] Startup sync failed:", message);
|
|
@@ -27902,17 +28391,44 @@ async function synchronizeAtStartup(forgeBaseUrl, observe, localConfig, input) {
|
|
|
27902
28391
|
attemptedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
27903
28392
|
message
|
|
27904
28393
|
}).catch(() => void 0);
|
|
28394
|
+
const python = watchStartupPython(paths, input);
|
|
27905
28395
|
if (credentials) await reportFailure(credentials, "sync", new Error(message), runtime, PLUGIN_VERSION);
|
|
27906
28396
|
if (localConfig && !forgeConfigVerified && credentials) {
|
|
27907
28397
|
decisionBaseUrl = await savedGatewayBaseUrl(paths, credentials, forgeBaseUrl) ?? decisionBaseUrl;
|
|
27908
28398
|
}
|
|
27909
28399
|
const after = await managedProjectionNames(paths).catch(() => before);
|
|
27910
|
-
return { paths, before, after, forgeConfigVerified, decisionBaseUrl, failedManifest: manifest, ...appliedLocalSync };
|
|
28400
|
+
return { paths, before, after, forgeConfigVerified, decisionBaseUrl, python, failedManifest: manifest, ...appliedLocalSync };
|
|
27911
28401
|
}
|
|
27912
28402
|
}
|
|
28403
|
+
function startupNotice(input, message, variant) {
|
|
28404
|
+
console.info(`[Forge] ${message}`);
|
|
28405
|
+
const client = input && typeof input === "object" ? input.client : void 0;
|
|
28406
|
+
if (client?.tui?.showToast) {
|
|
28407
|
+
void Promise.resolve().then(() => client.tui.showToast({ body: { title: "Forge", message, variant, duration: 1e4 } })).catch(() => void 0);
|
|
28408
|
+
}
|
|
28409
|
+
}
|
|
28410
|
+
function watchStartupPython(paths, input) {
|
|
28411
|
+
const file2 = path17.join(paths.forgeDir, PYTHON_STATUS_FILENAME);
|
|
28412
|
+
let writing = Promise.resolve();
|
|
28413
|
+
return startWorkPackPythonCheck(paths, (readiness) => {
|
|
28414
|
+
writing = writing.then(async () => {
|
|
28415
|
+
const issue2 = pythonIssueKey(readiness);
|
|
28416
|
+
if (!issue2) {
|
|
28417
|
+
await rm6(file2, { force: true });
|
|
28418
|
+
return;
|
|
28419
|
+
}
|
|
28420
|
+
const current = await readFile16(file2, "utf8").then((raw) => objectRecord2(JSON.parse(raw))).catch(() => ({}));
|
|
28421
|
+
if (current.issue !== issue2 || Object.keys(current).length !== 1) {
|
|
28422
|
+
await writeOwnerOnlyTextAtomic(file2, `${JSON.stringify({ issue: issue2 })}
|
|
28423
|
+
`);
|
|
28424
|
+
}
|
|
28425
|
+
if (current.issue !== issue2) startupNotice(input, pythonIssueMessage(readiness), "warning");
|
|
28426
|
+
}).catch(() => void 0);
|
|
28427
|
+
});
|
|
28428
|
+
}
|
|
27913
28429
|
async function savedGatewayBaseUrl(paths, credentials, forgeBaseUrl) {
|
|
27914
28430
|
try {
|
|
27915
|
-
const config2 = objectRecord2(parseJsonc(await
|
|
28431
|
+
const config2 = objectRecord2(parseJsonc(await readFile16(paths.opencodeConfigPath, "utf8")));
|
|
27916
28432
|
const options = objectRecord2(objectRecord2(objectRecord2(config2.provider).forge).options);
|
|
27917
28433
|
if (options.apiKey !== credentials.forgeApiKey || typeof options.baseURL !== "string" || !options.baseURL.endsWith("/v1")) return void 0;
|
|
27918
28434
|
const origin = options.baseURL.slice(0, -"/v1".length);
|
|
@@ -27937,7 +28453,7 @@ function resolveStartupPaths() {
|
|
|
27937
28453
|
return resolvePaths(void 0, void 0, env);
|
|
27938
28454
|
}
|
|
27939
28455
|
async function readForgeCredentials(paths, forgeBaseUrl) {
|
|
27940
|
-
const raw = await
|
|
28456
|
+
const raw = await readFile16(paths.opencodeAuthPath, "utf8").catch((error45) => {
|
|
27941
28457
|
if (error45.code === "ENOENT") return void 0;
|
|
27942
28458
|
throw error45;
|
|
27943
28459
|
});
|
|
@@ -27982,8 +28498,8 @@ function objectRecord2(value) {
|
|
|
27982
28498
|
}
|
|
27983
28499
|
async function writeStatus(paths, value) {
|
|
27984
28500
|
await mkdir8(paths.forgeDir, { recursive: true });
|
|
27985
|
-
const target =
|
|
27986
|
-
const temporary =
|
|
28501
|
+
const target = path17.join(paths.forgeDir, STATUS_FILENAME);
|
|
28502
|
+
const temporary = path17.join(paths.forgeDir, `.${STATUS_FILENAME}.${process.pid}.tmp`);
|
|
27987
28503
|
await writeFile9(temporary, `${JSON.stringify(value, null, 2)}
|
|
27988
28504
|
`, { mode: 384 });
|
|
27989
28505
|
await rename9(temporary, target);
|