minimal-forge-work-pack-sync 0.1.32 → 0.1.34
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 +97 -45
- 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.34";
|
|
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";
|
|
@@ -7688,7 +7688,7 @@ async function probeHealth(url2, route, headers, healthyField, source) {
|
|
|
7688
7688
|
}
|
|
7689
7689
|
|
|
7690
7690
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
7691
|
-
import { createHash as createHash5 } from "node:crypto";
|
|
7691
|
+
import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
|
|
7692
7692
|
import { pathToFileURL } from "node:url";
|
|
7693
7693
|
|
|
7694
7694
|
// packages/cli/src/skillUsageReporter.ts
|
|
@@ -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.34";
|
|
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();
|
|
@@ -25229,13 +25229,61 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
|
25229
25229
|
forge_decide_run: createForgeDecisionRunTool(forgeBaseUrl, state.decisionBaseUrl, state.paths),
|
|
25230
25230
|
forge_decide: createForgeDecisionTool(forgeBaseUrl, state.decisionBaseUrl, state.paths),
|
|
25231
25231
|
forge_generate_codebook: createForgeCodebookTool(forgeBaseUrl, state.decisionBaseUrl, state.paths),
|
|
25232
|
-
forge_feedback: createForgeFeedbackTool(forgeBaseUrl, state.paths)
|
|
25232
|
+
forge_feedback: createForgeFeedbackTool(forgeBaseUrl, state.paths),
|
|
25233
|
+
forge_image: createForgeImageTool(forgeBaseUrl, state.decisionBaseUrl, state.paths)
|
|
25233
25234
|
}
|
|
25234
25235
|
};
|
|
25235
25236
|
};
|
|
25236
25237
|
var ForgeDecisionRejectedError = class extends Error {
|
|
25237
25238
|
};
|
|
25238
|
-
function
|
|
25239
|
+
function createForgeImageTool(forgeBaseUrl, gatewayBaseUrl, paths) {
|
|
25240
|
+
return tool({
|
|
25241
|
+
description: "Cria ou edita uma imagem a pedido da pessoa. Usa uma \xFAnica chamada por imagem; cada revis\xE3o consome outra das 30 imagens mensais. Guarda o PNG na pasta de trabalho e devolve o caminho para visualiza\xE7\xE3o. N\xE3o fa\xE7as revis\xF5es autom\xE1ticas.",
|
|
25242
|
+
args: {
|
|
25243
|
+
prompt: tool.schema.string().min(1).max(8e3).describe("Descri\xE7\xE3o da imagem ou altera\xE7\xE3o pedida"),
|
|
25244
|
+
referencePath: tool.schema.string().optional().describe("Caminho expl\xEDcito de uma imagem PNG, JPEG ou WebP a editar")
|
|
25245
|
+
},
|
|
25246
|
+
async execute(args, context) {
|
|
25247
|
+
const requestId = randomUUID2();
|
|
25248
|
+
let referenceDataUrl;
|
|
25249
|
+
if (args.referencePath) {
|
|
25250
|
+
const bytes = await readFile4(args.referencePath);
|
|
25251
|
+
if (bytes.byteLength > 25e5) throw new Error("A imagem de refer\xEAncia \xE9 demasiado grande. Reduza-a antes de tentar novamente.");
|
|
25252
|
+
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;
|
|
25253
|
+
if (!mime) throw new Error("A refer\xEAncia tem de ser PNG, JPEG ou WebP.");
|
|
25254
|
+
referenceDataUrl = `data:${mime};base64,${bytes.toString("base64")}`;
|
|
25255
|
+
}
|
|
25256
|
+
const credentials = await readWellKnownForgeCredentials(paths.opencodeAuthPath, forgeBaseUrl);
|
|
25257
|
+
let response;
|
|
25258
|
+
try {
|
|
25259
|
+
response = await fetch(`${gatewayBaseUrl}/v1/images`, {
|
|
25260
|
+
method: "POST",
|
|
25261
|
+
redirect: "error",
|
|
25262
|
+
headers: { authorization: `Bearer ${credentials.forgeApiKey}`, "content-type": "application/json" },
|
|
25263
|
+
body: JSON.stringify({ requestId, prompt: args.prompt, referenceDataUrl }),
|
|
25264
|
+
signal: AbortSignal.any([context.abort, AbortSignal.timeout(15e4)])
|
|
25265
|
+
});
|
|
25266
|
+
} catch {
|
|
25267
|
+
throw new Error(`O resultado da imagem \xE9 incerto. N\xE3o repita automaticamente. Refer\xEAncia: ${requestId}`);
|
|
25268
|
+
}
|
|
25269
|
+
const body = await response.json();
|
|
25270
|
+
if (!response.ok) throw new Error(`${body.error?.message ?? "A gera\xE7\xE3o falhou"} Refer\xEAncia: ${requestId}`);
|
|
25271
|
+
if (body.media_type !== "image/png" || !body.b64_json) throw new Error(`O resultado da imagem \xE9 incerto. Refer\xEAncia: ${requestId}`);
|
|
25272
|
+
const image = Buffer.from(body.b64_json, "base64");
|
|
25273
|
+
if (image.byteLength > 8 * 1024 * 1024 || !image.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) {
|
|
25274
|
+
throw new Error(`O PNG recebido \xE9 inv\xE1lido. Refer\xEAncia: ${requestId}`);
|
|
25275
|
+
}
|
|
25276
|
+
const destination = path6.join(context.directory, `forge-image-${requestId}.png`);
|
|
25277
|
+
await writeFile4(destination, image, { flag: "wx" });
|
|
25278
|
+
const reset = body.quota && new Intl.DateTimeFormat("pt-PT", { dateStyle: "long", timeZone: "Europe/Lisbon" }).format(new Date(body.quota.resetsAt));
|
|
25279
|
+
const remaining = body.quota ? ` Restam ${body.quota.remaining} imagens at\xE9 ${reset}.` : "";
|
|
25280
|
+
return `Imagem guardada em ${destination}.${remaining}
|
|
25281
|
+
|
|
25282
|
+
`;
|
|
25283
|
+
}
|
|
25284
|
+
});
|
|
25285
|
+
}
|
|
25286
|
+
function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths, responseDirectory) {
|
|
25239
25287
|
const question = tool.schema.discriminatedUnion("type", [
|
|
25240
25288
|
tool.schema.object({
|
|
25241
25289
|
type: tool.schema.literal("noul"),
|
|
@@ -25272,11 +25320,11 @@ function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
25272
25320
|
let requestBody;
|
|
25273
25321
|
if (fromFile) {
|
|
25274
25322
|
const file2 = await fileInsideWorkspace(context.directory, args.request_file);
|
|
25275
|
-
const
|
|
25276
|
-
if (Buffer.byteLength(
|
|
25323
|
+
const raw = await readFile4(file2, "utf8");
|
|
25324
|
+
if (Buffer.byteLength(raw) > 512 * 1024) throw new Error("O ficheiro de pedido excede 512 KiB.");
|
|
25277
25325
|
let parsed;
|
|
25278
25326
|
try {
|
|
25279
|
-
parsed = JSON.parse(
|
|
25327
|
+
parsed = JSON.parse(raw);
|
|
25280
25328
|
} catch {
|
|
25281
25329
|
throw new Error("O ficheiro de pedido n\xE3o cont\xE9m JSON v\xE1lido.");
|
|
25282
25330
|
}
|
|
@@ -25291,44 +25339,48 @@ function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
25291
25339
|
if (args.state === void 0 || !args.questions || Object.keys(args.questions).length === 0) throw new Error("Indica state e questions.");
|
|
25292
25340
|
requestBody = { state: args.state, questions: args.questions };
|
|
25293
25341
|
}
|
|
25294
|
-
const responseDir = await mkdtemp2(path6.join(context.directory, ".forge-decision-"));
|
|
25342
|
+
const responseDir = await mkdtemp2(path6.join(responseDirectory ?? context.directory, ".forge-decision-"));
|
|
25295
25343
|
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
25344
|
try {
|
|
25310
|
-
|
|
25311
|
-
|
|
25312
|
-
|
|
25313
|
-
|
|
25345
|
+
const credentials = await readWellKnownForgeCredentials(paths.opencodeAuthPath, forgeBaseUrl);
|
|
25346
|
+
const response = await fetch(`${decisionBaseUrl}/v1/decisions`, {
|
|
25347
|
+
method: "POST",
|
|
25348
|
+
redirect: "error",
|
|
25349
|
+
headers: {
|
|
25350
|
+
authorization: `Bearer ${credentials.forgeApiKey}`,
|
|
25351
|
+
"content-type": "application/json"
|
|
25352
|
+
},
|
|
25353
|
+
body: JSON.stringify(requestBody),
|
|
25354
|
+
signal: AbortSignal.any([context.abort, AbortSignal.timeout(FORGE_DECISION_TIMEOUT_MS)])
|
|
25355
|
+
});
|
|
25356
|
+
const raw = await response.text();
|
|
25357
|
+
let body;
|
|
25314
25358
|
try {
|
|
25315
|
-
|
|
25316
|
-
return JSON.stringify({ ...body, response_file: responseFile }, null, 2);
|
|
25359
|
+
body = JSON.parse(raw);
|
|
25317
25360
|
} 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
25361
|
}
|
|
25362
|
+
if (response.ok && body && typeof body === "object" && body.answers && typeof body.answers === "object") {
|
|
25363
|
+
try {
|
|
25364
|
+
await writeFile4(responseFile, raw, { flag: "wx", mode: 384 });
|
|
25365
|
+
return JSON.stringify({ ...body, response_file: responseFile }, null, 2);
|
|
25366
|
+
} catch {
|
|
25367
|
+
return JSON.stringify({
|
|
25368
|
+
...body,
|
|
25369
|
+
response_file: null,
|
|
25370
|
+
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."
|
|
25371
|
+
}, null, 2);
|
|
25372
|
+
}
|
|
25373
|
+
}
|
|
25374
|
+
const nested = body?.error && typeof body.error === "object" && !Array.isArray(body.error) ? body.error.message : void 0;
|
|
25375
|
+
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})`;
|
|
25376
|
+
const code = body?.error && typeof body.error === "object" ? body.error.code : void 0;
|
|
25377
|
+
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))) {
|
|
25378
|
+
throw new ForgeDecisionRejectedError(safeError);
|
|
25379
|
+
}
|
|
25380
|
+
throw new Error(safeError);
|
|
25381
|
+
} finally {
|
|
25382
|
+
await rmdir(responseDir).catch(() => void 0);
|
|
25324
25383
|
}
|
|
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
25384
|
}
|
|
25333
25385
|
});
|
|
25334
25386
|
}
|
|
@@ -25357,7 +25409,6 @@ function canonicalJson(value) {
|
|
|
25357
25409
|
return JSON.stringify(value);
|
|
25358
25410
|
}
|
|
25359
25411
|
function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
25360
|
-
const decide = createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths);
|
|
25361
25412
|
return tool({
|
|
25362
25413
|
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
25414
|
args: { plan_file: tool.schema.string().describe("Caminho de jev/plan.json dentro do workspace") },
|
|
@@ -25372,6 +25423,7 @@ function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
25372
25423
|
await mkdir3(responsePath, { recursive: true });
|
|
25373
25424
|
const responseDir = await fileInsideWorkspace(context.directory, responsePath);
|
|
25374
25425
|
if (path6.dirname(responseDir) !== path6.join(runDir, "jev")) throw new Error("A pasta de respostas tem de pertencer ao run Jev.");
|
|
25426
|
+
const decide = createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths, responseDir);
|
|
25375
25427
|
const lockDir = path6.join(runDir, "jev", ".decide-run.lock");
|
|
25376
25428
|
try {
|
|
25377
25429
|
await mkdir3(lockDir);
|
|
@@ -25392,15 +25444,15 @@ function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
25392
25444
|
}
|
|
25393
25445
|
const acceptedFile = path6.join(runDir, "jev", "accepted", `${batchId}.json`);
|
|
25394
25446
|
const responseFile = path6.join(responseDir, `${batchId}.response.json`);
|
|
25395
|
-
if (await fileExists(acceptedFile) || await fileExists(responseFile)) {
|
|
25396
|
-
skipped++;
|
|
25397
|
-
continue;
|
|
25398
|
-
}
|
|
25399
25447
|
const requestFile = await fileInsideWorkspace(context.directory, batch.request_file);
|
|
25400
25448
|
if (path6.dirname(requestFile) !== path6.join(runDir, "jev", "requests")) throw new Error(`${batchId}: pedido fora do run.`);
|
|
25401
25449
|
const request = JSON.parse(await readFile4(requestFile, "utf8"));
|
|
25402
25450
|
const fingerprint = createHash5("sha256").update(canonicalJson(request)).digest("hex");
|
|
25403
25451
|
if (fingerprint !== batch.request_fingerprint) throw new Error(`${batchId}: fingerprint do pedido n\xE3o corresponde ao plano.`);
|
|
25452
|
+
if (await fileExists(acceptedFile) || await fileExists(responseFile)) {
|
|
25453
|
+
skipped++;
|
|
25454
|
+
continue;
|
|
25455
|
+
}
|
|
25404
25456
|
let result;
|
|
25405
25457
|
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
25458
|
try {
|