minimal-forge-work-pack-sync 0.1.31 → 0.1.32
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 +75 -50
- 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.32";
|
|
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";
|
|
@@ -7925,7 +7925,7 @@ async function replaceFile(filename, contents) {
|
|
|
7925
7925
|
|
|
7926
7926
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
7927
7927
|
var import_yaml = __toESM(require_dist(), 1);
|
|
7928
|
-
import { link, mkdir as mkdir3, mkdtemp as mkdtemp2, readdir as readdir4, readFile as readFile4, realpath, rename as rename4, stat, writeFile as writeFile4 } from "node:fs/promises";
|
|
7928
|
+
import { link, mkdir as mkdir3, mkdtemp as mkdtemp2, readdir as readdir4, readFile as readFile4, realpath, rename as rename4, rm as rm2, rmdir, stat, unlink, writeFile as writeFile4 } from "node:fs/promises";
|
|
7929
7929
|
import path6 from "node:path";
|
|
7930
7930
|
|
|
7931
7931
|
// node_modules/@opencode-ai/plugin/node_modules/zod/v4/classic/external.js
|
|
@@ -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.32";
|
|
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();
|
|
@@ -25233,6 +25233,8 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
|
25233
25233
|
}
|
|
25234
25234
|
};
|
|
25235
25235
|
};
|
|
25236
|
+
var ForgeDecisionRejectedError = class extends Error {
|
|
25237
|
+
};
|
|
25236
25238
|
function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
25237
25239
|
const question = tool.schema.discriminatedUnion("type", [
|
|
25238
25240
|
tool.schema.object({
|
|
@@ -25322,6 +25324,10 @@ function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
25322
25324
|
}
|
|
25323
25325
|
const nested = body?.error && typeof body.error === "object" && !Array.isArray(body.error) ? body.error.message : void 0;
|
|
25324
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
|
+
}
|
|
25325
25331
|
throw new Error(safeError);
|
|
25326
25332
|
}
|
|
25327
25333
|
});
|
|
@@ -25366,56 +25372,75 @@ function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
25366
25372
|
await mkdir3(responsePath, { recursive: true });
|
|
25367
25373
|
const responseDir = await fileInsideWorkspace(context.directory, responsePath);
|
|
25368
25374
|
if (path6.dirname(responseDir) !== path6.join(runDir, "jev")) throw new Error("A pasta de respostas tem de pertencer ao run Jev.");
|
|
25375
|
+
const lockDir = path6.join(runDir, "jev", ".decide-run.lock");
|
|
25376
|
+
try {
|
|
25377
|
+
await mkdir3(lockDir);
|
|
25378
|
+
} catch (error45) {
|
|
25379
|
+
if (error45.code !== "EEXIST") throw error45;
|
|
25380
|
+
throw new Error("Este plano j\xE1 est\xE1 em execu\xE7\xE3o ou tem uma chamada interrompida. Verificar as respostas e recuperar o lote antes de remover jev/.decide-run.lock; n\xE3o repetir chamadas incertas.");
|
|
25381
|
+
}
|
|
25382
|
+
let releaseLock = true;
|
|
25369
25383
|
let saved = 0;
|
|
25370
25384
|
let skipped = 0;
|
|
25371
|
-
|
|
25372
|
-
|
|
25373
|
-
|
|
25374
|
-
|
|
25375
|
-
|
|
25376
|
-
|
|
25377
|
-
|
|
25378
|
-
|
|
25379
|
-
|
|
25380
|
-
|
|
25381
|
-
|
|
25382
|
-
|
|
25383
|
-
|
|
25384
|
-
|
|
25385
|
-
|
|
25386
|
-
|
|
25387
|
-
|
|
25388
|
-
|
|
25389
|
-
|
|
25390
|
-
result
|
|
25391
|
-
|
|
25392
|
-
|
|
25393
|
-
|
|
25394
|
-
|
|
25395
|
-
|
|
25396
|
-
|
|
25397
|
-
|
|
25398
|
-
|
|
25399
|
-
|
|
25400
|
-
|
|
25401
|
-
verified: false,
|
|
25402
|
-
|
|
25403
|
-
|
|
25404
|
-
|
|
25405
|
-
|
|
25406
|
-
|
|
25407
|
-
|
|
25408
|
-
|
|
25409
|
-
|
|
25385
|
+
try {
|
|
25386
|
+
await writeFile4(path6.join(lockDir, "owner.json"), JSON.stringify({ pid: process.pid, started_at: (/* @__PURE__ */ new Date()).toISOString() }), { mode: 384 });
|
|
25387
|
+
for (const batch of batches) {
|
|
25388
|
+
context.abort.throwIfAborted();
|
|
25389
|
+
const batchId = batch.batch_id;
|
|
25390
|
+
if (typeof batchId !== "string" || !/^batch-[0-9]{4}-[A-Za-z0-9._-]+$/.test(batchId) || typeof batch.request_file !== "string" || typeof batch.request_fingerprint !== "string") {
|
|
25391
|
+
throw new Error("O plano Jev cont\xE9m um lote inv\xE1lido.");
|
|
25392
|
+
}
|
|
25393
|
+
const acceptedFile = path6.join(runDir, "jev", "accepted", `${batchId}.json`);
|
|
25394
|
+
const responseFile = path6.join(responseDir, `${batchId}.response.json`);
|
|
25395
|
+
if (await fileExists(acceptedFile) || await fileExists(responseFile)) {
|
|
25396
|
+
skipped++;
|
|
25397
|
+
continue;
|
|
25398
|
+
}
|
|
25399
|
+
const requestFile = await fileInsideWorkspace(context.directory, batch.request_file);
|
|
25400
|
+
if (path6.dirname(requestFile) !== path6.join(runDir, "jev", "requests")) throw new Error(`${batchId}: pedido fora do run.`);
|
|
25401
|
+
const request = JSON.parse(await readFile4(requestFile, "utf8"));
|
|
25402
|
+
const fingerprint = createHash5("sha256").update(canonicalJson(request)).digest("hex");
|
|
25403
|
+
if (fingerprint !== batch.request_fingerprint) throw new Error(`${batchId}: fingerprint do pedido n\xE3o corresponde ao plano.`);
|
|
25404
|
+
let result;
|
|
25405
|
+
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
|
+
try {
|
|
25407
|
+
const output = await decide.execute({ request_file: requestFile }, context);
|
|
25408
|
+
result = JSON.parse(typeof output === "string" ? output : output.output);
|
|
25409
|
+
} catch (error45) {
|
|
25410
|
+
releaseLock = error45 instanceof ForgeDecisionRejectedError;
|
|
25411
|
+
return JSON.stringify({ verified: false, saved, skipped, stopped_at: batchId, recovery_lock: releaseLock ? void 0 : lockDir, error: error45 instanceof Error ? error45.message : "Falha na chamada Jev." });
|
|
25412
|
+
}
|
|
25413
|
+
if (typeof result.response_file !== "string") {
|
|
25414
|
+
releaseLock = false;
|
|
25415
|
+
return JSON.stringify({ verified: false, saved, skipped, stopped_at: batchId, recovery_response: result, error: result.persistence_error ?? "Resposta Jev sem ficheiro guardado; recuperar do hist\xF3rico, sem repetir." });
|
|
25416
|
+
}
|
|
25417
|
+
try {
|
|
25418
|
+
await link(result.response_file, responseFile);
|
|
25419
|
+
} catch {
|
|
25420
|
+
releaseLock = false;
|
|
25421
|
+
return JSON.stringify({
|
|
25422
|
+
verified: false,
|
|
25423
|
+
saved,
|
|
25424
|
+
skipped,
|
|
25425
|
+
stopped_at: batchId,
|
|
25426
|
+
recovery_file: result.response_file,
|
|
25427
|
+
error: "Resposta conclu\xEDda mas n\xE3o copiada para o run; recuperar o ficheiro indicado, sem repetir a chamada."
|
|
25428
|
+
});
|
|
25429
|
+
}
|
|
25430
|
+
await unlink(result.response_file).then(() => rmdir(path6.dirname(result.response_file))).catch(() => void 0);
|
|
25431
|
+
saved++;
|
|
25432
|
+
}
|
|
25433
|
+
return JSON.stringify({
|
|
25434
|
+
verified: true,
|
|
25435
|
+
batch_count: batches.length,
|
|
25436
|
+
saved,
|
|
25437
|
+
skipped,
|
|
25438
|
+
response_dir: responseDir,
|
|
25439
|
+
next_step: "Executar jev-accept sobre as respostas guardadas ainda n\xE3o aceites; depois jev-validate e jev-merge."
|
|
25440
|
+
});
|
|
25441
|
+
} finally {
|
|
25442
|
+
if (releaseLock) await rm2(lockDir, { recursive: true });
|
|
25410
25443
|
}
|
|
25411
|
-
return JSON.stringify({
|
|
25412
|
-
verified: true,
|
|
25413
|
-
batch_count: batches.length,
|
|
25414
|
-
saved,
|
|
25415
|
-
skipped,
|
|
25416
|
-
response_dir: responseDir,
|
|
25417
|
-
next_step: "Executar jev-accept sobre as respostas guardadas ainda n\xE3o aceites; depois jev-validate e jev-merge."
|
|
25418
|
-
});
|
|
25419
25444
|
}
|
|
25420
25445
|
});
|
|
25421
25446
|
}
|