minimal-forge-work-pack-sync 0.1.32 → 0.1.33
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 +47 -43
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7551,7 +7551,7 @@ var DEFAULT_DEBUG_TRACE_LIMITS = {
|
|
|
7551
7551
|
};
|
|
7552
7552
|
|
|
7553
7553
|
// packages/shared/src/contracts/settings.ts
|
|
7554
|
-
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.
|
|
7554
|
+
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.33";
|
|
7555
7555
|
var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
|
|
7556
7556
|
var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
|
|
7557
7557
|
var FIRECRAWL_KEYLESS_MCP_NAME = "firecrawl";
|
|
@@ -25168,7 +25168,7 @@ function isRecord(value) {
|
|
|
25168
25168
|
}
|
|
25169
25169
|
|
|
25170
25170
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
25171
|
-
var PLUGIN_VERSION = "0.1.
|
|
25171
|
+
var PLUGIN_VERSION = "0.1.33";
|
|
25172
25172
|
var FORGE_DECISION_TIMEOUT_MS = 11e4;
|
|
25173
25173
|
var STATUS_FILENAME = "work-pack-startup-status.json";
|
|
25174
25174
|
var activeSync = /* @__PURE__ */ new Map();
|
|
@@ -25235,7 +25235,7 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
|
25235
25235
|
};
|
|
25236
25236
|
var ForgeDecisionRejectedError = class extends Error {
|
|
25237
25237
|
};
|
|
25238
|
-
function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
25238
|
+
function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths, responseDirectory) {
|
|
25239
25239
|
const question = tool.schema.discriminatedUnion("type", [
|
|
25240
25240
|
tool.schema.object({
|
|
25241
25241
|
type: tool.schema.literal("noul"),
|
|
@@ -25272,11 +25272,11 @@ function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
25272
25272
|
let requestBody;
|
|
25273
25273
|
if (fromFile) {
|
|
25274
25274
|
const file2 = await fileInsideWorkspace(context.directory, args.request_file);
|
|
25275
|
-
const
|
|
25276
|
-
if (Buffer.byteLength(
|
|
25275
|
+
const raw = await readFile4(file2, "utf8");
|
|
25276
|
+
if (Buffer.byteLength(raw) > 512 * 1024) throw new Error("O ficheiro de pedido excede 512 KiB.");
|
|
25277
25277
|
let parsed;
|
|
25278
25278
|
try {
|
|
25279
|
-
parsed = JSON.parse(
|
|
25279
|
+
parsed = JSON.parse(raw);
|
|
25280
25280
|
} catch {
|
|
25281
25281
|
throw new Error("O ficheiro de pedido n\xE3o cont\xE9m JSON v\xE1lido.");
|
|
25282
25282
|
}
|
|
@@ -25291,44 +25291,48 @@ function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
25291
25291
|
if (args.state === void 0 || !args.questions || Object.keys(args.questions).length === 0) throw new Error("Indica state e questions.");
|
|
25292
25292
|
requestBody = { state: args.state, questions: args.questions };
|
|
25293
25293
|
}
|
|
25294
|
-
const responseDir = await mkdtemp2(path6.join(context.directory, ".forge-decision-"));
|
|
25294
|
+
const responseDir = await mkdtemp2(path6.join(responseDirectory ?? context.directory, ".forge-decision-"));
|
|
25295
25295
|
const responseFile = path6.join(responseDir, "response.json");
|
|
25296
|
-
const credentials = await readWellKnownForgeCredentials(paths.opencodeAuthPath, forgeBaseUrl);
|
|
25297
|
-
const response = await fetch(`${decisionBaseUrl}/v1/decisions`, {
|
|
25298
|
-
method: "POST",
|
|
25299
|
-
redirect: "error",
|
|
25300
|
-
headers: {
|
|
25301
|
-
authorization: `Bearer ${credentials.forgeApiKey}`,
|
|
25302
|
-
"content-type": "application/json"
|
|
25303
|
-
},
|
|
25304
|
-
body: JSON.stringify(requestBody),
|
|
25305
|
-
signal: AbortSignal.any([context.abort, AbortSignal.timeout(FORGE_DECISION_TIMEOUT_MS)])
|
|
25306
|
-
});
|
|
25307
|
-
const raw = await response.text();
|
|
25308
|
-
let body;
|
|
25309
25296
|
try {
|
|
25310
|
-
|
|
25311
|
-
|
|
25312
|
-
|
|
25313
|
-
|
|
25297
|
+
const credentials = await readWellKnownForgeCredentials(paths.opencodeAuthPath, forgeBaseUrl);
|
|
25298
|
+
const response = await fetch(`${decisionBaseUrl}/v1/decisions`, {
|
|
25299
|
+
method: "POST",
|
|
25300
|
+
redirect: "error",
|
|
25301
|
+
headers: {
|
|
25302
|
+
authorization: `Bearer ${credentials.forgeApiKey}`,
|
|
25303
|
+
"content-type": "application/json"
|
|
25304
|
+
},
|
|
25305
|
+
body: JSON.stringify(requestBody),
|
|
25306
|
+
signal: AbortSignal.any([context.abort, AbortSignal.timeout(FORGE_DECISION_TIMEOUT_MS)])
|
|
25307
|
+
});
|
|
25308
|
+
const raw = await response.text();
|
|
25309
|
+
let body;
|
|
25314
25310
|
try {
|
|
25315
|
-
|
|
25316
|
-
return JSON.stringify({ ...body, response_file: responseFile }, null, 2);
|
|
25311
|
+
body = JSON.parse(raw);
|
|
25317
25312
|
} catch {
|
|
25318
|
-
return JSON.stringify({
|
|
25319
|
-
...body,
|
|
25320
|
-
response_file: null,
|
|
25321
|
-
persistence_error: "A decis\xE3o foi conclu\xEDda, mas n\xE3o foi poss\xEDvel guardar o ficheiro. Recuperar esta resposta do hist\xF3rico da ferramenta; n\xE3o repetir a chamada ao Jev."
|
|
25322
|
-
}, null, 2);
|
|
25323
25313
|
}
|
|
25314
|
+
if (response.ok && body && typeof body === "object" && body.answers && typeof body.answers === "object") {
|
|
25315
|
+
try {
|
|
25316
|
+
await writeFile4(responseFile, raw, { flag: "wx", mode: 384 });
|
|
25317
|
+
return JSON.stringify({ ...body, response_file: responseFile }, null, 2);
|
|
25318
|
+
} catch {
|
|
25319
|
+
return JSON.stringify({
|
|
25320
|
+
...body,
|
|
25321
|
+
response_file: null,
|
|
25322
|
+
persistence_error: "A decis\xE3o foi conclu\xEDda, mas n\xE3o foi poss\xEDvel guardar o ficheiro. Recuperar esta resposta do hist\xF3rico da ferramenta; n\xE3o repetir a chamada ao Jev."
|
|
25323
|
+
}, null, 2);
|
|
25324
|
+
}
|
|
25325
|
+
}
|
|
25326
|
+
const nested = body?.error && typeof body.error === "object" && !Array.isArray(body.error) ? body.error.message : void 0;
|
|
25327
|
+
const safeError = typeof nested === "string" && nested.length <= 300 ? nested.replace(/forge_[A-Za-z0-9_-]+/g, "<credencial oculta>") : `O Forge n\xE3o concluiu a decis\xE3o (HTTP ${response.status})`;
|
|
25328
|
+
const code = body?.error && typeof body.error === "object" ? body.error.code : void 0;
|
|
25329
|
+
if (response.status === 401 || response.status === 403 || ["rate_limit_exceeded", "payload_too_large", "invalid_content_type", "invalid_json", "invalid_decision_request", "openrouter_key_missing"].includes(String(code))) {
|
|
25330
|
+
throw new ForgeDecisionRejectedError(safeError);
|
|
25331
|
+
}
|
|
25332
|
+
throw new Error(safeError);
|
|
25333
|
+
} finally {
|
|
25334
|
+
await rmdir(responseDir).catch(() => void 0);
|
|
25324
25335
|
}
|
|
25325
|
-
const nested = body?.error && typeof body.error === "object" && !Array.isArray(body.error) ? body.error.message : void 0;
|
|
25326
|
-
const safeError = typeof nested === "string" && nested.length <= 300 ? nested.replace(/forge_[A-Za-z0-9_-]+/g, "<credencial oculta>") : `O Forge n\xE3o concluiu a decis\xE3o (HTTP ${response.status})`;
|
|
25327
|
-
const code = body?.error && typeof body.error === "object" ? body.error.code : void 0;
|
|
25328
|
-
if (response.status === 401 || response.status === 403 || ["rate_limit_exceeded", "payload_too_large", "invalid_content_type", "invalid_json", "invalid_decision_request", "openrouter_key_missing"].includes(String(code))) {
|
|
25329
|
-
throw new ForgeDecisionRejectedError(safeError);
|
|
25330
|
-
}
|
|
25331
|
-
throw new Error(safeError);
|
|
25332
25336
|
}
|
|
25333
25337
|
});
|
|
25334
25338
|
}
|
|
@@ -25357,7 +25361,6 @@ function canonicalJson(value) {
|
|
|
25357
25361
|
return JSON.stringify(value);
|
|
25358
25362
|
}
|
|
25359
25363
|
function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
25360
|
-
const decide = createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths);
|
|
25361
25364
|
return tool({
|
|
25362
25365
|
description: "Executa em c\xF3digo os lotes Jev pendentes de um plano preparado. Guarda cada resposta crua e nunca repete lotes com resposta ou aceita\xE7\xE3o j\xE1 guardada. Requer a aprova\xE7\xE3o habitual para as chamadas pagas antes de usar.",
|
|
25363
25366
|
args: { plan_file: tool.schema.string().describe("Caminho de jev/plan.json dentro do workspace") },
|
|
@@ -25372,6 +25375,7 @@ function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
25372
25375
|
await mkdir3(responsePath, { recursive: true });
|
|
25373
25376
|
const responseDir = await fileInsideWorkspace(context.directory, responsePath);
|
|
25374
25377
|
if (path6.dirname(responseDir) !== path6.join(runDir, "jev")) throw new Error("A pasta de respostas tem de pertencer ao run Jev.");
|
|
25378
|
+
const decide = createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths, responseDir);
|
|
25375
25379
|
const lockDir = path6.join(runDir, "jev", ".decide-run.lock");
|
|
25376
25380
|
try {
|
|
25377
25381
|
await mkdir3(lockDir);
|
|
@@ -25392,15 +25396,15 @@ function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
25392
25396
|
}
|
|
25393
25397
|
const acceptedFile = path6.join(runDir, "jev", "accepted", `${batchId}.json`);
|
|
25394
25398
|
const responseFile = path6.join(responseDir, `${batchId}.response.json`);
|
|
25395
|
-
if (await fileExists(acceptedFile) || await fileExists(responseFile)) {
|
|
25396
|
-
skipped++;
|
|
25397
|
-
continue;
|
|
25398
|
-
}
|
|
25399
25399
|
const requestFile = await fileInsideWorkspace(context.directory, batch.request_file);
|
|
25400
25400
|
if (path6.dirname(requestFile) !== path6.join(runDir, "jev", "requests")) throw new Error(`${batchId}: pedido fora do run.`);
|
|
25401
25401
|
const request = JSON.parse(await readFile4(requestFile, "utf8"));
|
|
25402
25402
|
const fingerprint = createHash5("sha256").update(canonicalJson(request)).digest("hex");
|
|
25403
25403
|
if (fingerprint !== batch.request_fingerprint) throw new Error(`${batchId}: fingerprint do pedido n\xE3o corresponde ao plano.`);
|
|
25404
|
+
if (await fileExists(acceptedFile) || await fileExists(responseFile)) {
|
|
25405
|
+
skipped++;
|
|
25406
|
+
continue;
|
|
25407
|
+
}
|
|
25404
25408
|
let result;
|
|
25405
25409
|
await writeFile4(path6.join(lockDir, "owner.json"), JSON.stringify({ pid: process.pid, batch_id: batchId, request_fingerprint: fingerprint, started_at: (/* @__PURE__ */ new Date()).toISOString() }), { mode: 384 });
|
|
25406
25410
|
try {
|