minimal-forge-work-pack-sync 0.1.30 → 0.1.31
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 +128 -7
- 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.31";
|
|
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 { mkdir as mkdir3, mkdtemp as mkdtemp2, readdir as readdir4, readFile as readFile4, rename as rename4, 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, stat, 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.31";
|
|
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();
|
|
@@ -25226,6 +25226,7 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
|
25226
25226
|
if (state.forgeConfigVerified) applySharedWorkerPrompt(config2);
|
|
25227
25227
|
},
|
|
25228
25228
|
tool: {
|
|
25229
|
+
forge_decide_run: createForgeDecisionRunTool(forgeBaseUrl, state.decisionBaseUrl, state.paths),
|
|
25229
25230
|
forge_decide: createForgeDecisionTool(forgeBaseUrl, state.decisionBaseUrl, state.paths),
|
|
25230
25231
|
forge_generate_codebook: createForgeCodebookTool(forgeBaseUrl, state.decisionBaseUrl, state.paths),
|
|
25231
25232
|
forge_feedback: createForgeFeedbackTool(forgeBaseUrl, state.paths)
|
|
@@ -25251,16 +25252,43 @@ function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
25251
25252
|
})
|
|
25252
25253
|
]);
|
|
25253
25254
|
return tool({
|
|
25254
|
-
description: "Pede ao Jev
|
|
25255
|
+
description: "Pede ao Jev decis\xF5es estruturadas. Para um pedido preparado, passa request_file; a resposta crua fica guardada em response_file.",
|
|
25255
25256
|
args: {
|
|
25257
|
+
request_file: tool.schema.string().optional().describe("Ficheiro JSON de pedido dentro do workspace"),
|
|
25256
25258
|
state: tool.schema.union([
|
|
25257
25259
|
tool.schema.string(),
|
|
25258
25260
|
tool.schema.record(tool.schema.string(), tool.schema.any()),
|
|
25259
25261
|
tool.schema.array(tool.schema.any())
|
|
25260
|
-
]).describe("
|
|
25261
|
-
questions: tool.schema.record(tool.schema.string(), question).describe("
|
|
25262
|
+
]).optional().describe("Para chamadas diretas: evid\xEAncia necess\xE1ria para decidir"),
|
|
25263
|
+
questions: tool.schema.record(tool.schema.string(), question).optional().describe("Para chamadas diretas: perguntas identificadas por uma chave est\xE1vel")
|
|
25262
25264
|
},
|
|
25263
25265
|
async execute(args, context) {
|
|
25266
|
+
const fromFile = typeof args.request_file === "string" && args.request_file.trim().length > 0;
|
|
25267
|
+
if (fromFile === (args.state !== void 0 || args.questions !== void 0)) {
|
|
25268
|
+
throw new Error("Indica request_file ou state e questions, mas n\xE3o ambos.");
|
|
25269
|
+
}
|
|
25270
|
+
let requestBody;
|
|
25271
|
+
if (fromFile) {
|
|
25272
|
+
const file2 = await fileInsideWorkspace(context.directory, args.request_file);
|
|
25273
|
+
const raw2 = await readFile4(file2, "utf8");
|
|
25274
|
+
if (Buffer.byteLength(raw2) > 512 * 1024) throw new Error("O ficheiro de pedido excede 512 KiB.");
|
|
25275
|
+
let parsed;
|
|
25276
|
+
try {
|
|
25277
|
+
parsed = JSON.parse(raw2);
|
|
25278
|
+
} catch {
|
|
25279
|
+
throw new Error("O ficheiro de pedido n\xE3o cont\xE9m JSON v\xE1lido.");
|
|
25280
|
+
}
|
|
25281
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("O pedido n\xE3o \xE9 um objeto JSON.");
|
|
25282
|
+
const record2 = parsed;
|
|
25283
|
+
if (record2.model !== void 0 && record2.model !== "typesafe/jev-1.13") throw new Error("O modelo do pedido n\xE3o corresponde ao Jev configurado.");
|
|
25284
|
+
if (record2.state === void 0 || !record2.questions || typeof record2.questions !== "object" || Array.isArray(record2.questions) || Object.keys(record2.questions).length === 0) {
|
|
25285
|
+
throw new Error("O pedido deve conter state e questions.");
|
|
25286
|
+
}
|
|
25287
|
+
requestBody = { state: record2.state, questions: record2.questions };
|
|
25288
|
+
} else {
|
|
25289
|
+
if (args.state === void 0 || !args.questions || Object.keys(args.questions).length === 0) throw new Error("Indica state e questions.");
|
|
25290
|
+
requestBody = { state: args.state, questions: args.questions };
|
|
25291
|
+
}
|
|
25264
25292
|
const responseDir = await mkdtemp2(path6.join(context.directory, ".forge-decision-"));
|
|
25265
25293
|
const responseFile = path6.join(responseDir, "response.json");
|
|
25266
25294
|
const credentials = await readWellKnownForgeCredentials(paths.opencodeAuthPath, forgeBaseUrl);
|
|
@@ -25271,7 +25299,7 @@ function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
25271
25299
|
authorization: `Bearer ${credentials.forgeApiKey}`,
|
|
25272
25300
|
"content-type": "application/json"
|
|
25273
25301
|
},
|
|
25274
|
-
body: JSON.stringify(
|
|
25302
|
+
body: JSON.stringify(requestBody),
|
|
25275
25303
|
signal: AbortSignal.any([context.abort, AbortSignal.timeout(FORGE_DECISION_TIMEOUT_MS)])
|
|
25276
25304
|
});
|
|
25277
25305
|
const raw = await response.text();
|
|
@@ -25298,6 +25326,99 @@ function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
|
25298
25326
|
}
|
|
25299
25327
|
});
|
|
25300
25328
|
}
|
|
25329
|
+
async function fileInsideWorkspace(directory, candidate) {
|
|
25330
|
+
const workspace = await realpath(directory);
|
|
25331
|
+
const file2 = await realpath(path6.resolve(workspace, candidate));
|
|
25332
|
+
const relative = path6.relative(workspace, file2);
|
|
25333
|
+
if (!relative || (relative === ".." || relative.startsWith(`..${path6.sep}`)) || path6.isAbsolute(relative)) throw new Error("O ficheiro tem de estar dentro do workspace.");
|
|
25334
|
+
return file2;
|
|
25335
|
+
}
|
|
25336
|
+
async function fileExists(candidate) {
|
|
25337
|
+
try {
|
|
25338
|
+
await stat(candidate);
|
|
25339
|
+
return true;
|
|
25340
|
+
} catch (error45) {
|
|
25341
|
+
if (error45.code === "ENOENT") return false;
|
|
25342
|
+
throw error45;
|
|
25343
|
+
}
|
|
25344
|
+
}
|
|
25345
|
+
function canonicalJson(value) {
|
|
25346
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
25347
|
+
if (value && typeof value === "object") {
|
|
25348
|
+
const record2 = value;
|
|
25349
|
+
return `{${Object.keys(record2).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(record2[key])}`).join(",")}}`;
|
|
25350
|
+
}
|
|
25351
|
+
return JSON.stringify(value);
|
|
25352
|
+
}
|
|
25353
|
+
function createForgeDecisionRunTool(forgeBaseUrl, decisionBaseUrl, paths) {
|
|
25354
|
+
const decide = createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths);
|
|
25355
|
+
return tool({
|
|
25356
|
+
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.",
|
|
25357
|
+
args: { plan_file: tool.schema.string().describe("Caminho de jev/plan.json dentro do workspace") },
|
|
25358
|
+
async execute(args, context) {
|
|
25359
|
+
const planFile = await fileInsideWorkspace(context.directory, args.plan_file);
|
|
25360
|
+
if (path6.basename(planFile) !== "plan.json" || path6.basename(path6.dirname(planFile)) !== "jev") throw new Error("Indica o ficheiro jev/plan.json.");
|
|
25361
|
+
const runDir = path6.dirname(path6.dirname(planFile));
|
|
25362
|
+
const plan = JSON.parse(await readFile4(planFile, "utf8"));
|
|
25363
|
+
if (plan.engine !== "jev-batch" || plan.model !== "typesafe/jev-1.13" || !Array.isArray(plan.batches)) throw new Error("O plano Jev \xE9 inv\xE1lido.");
|
|
25364
|
+
const batches = plan.batches;
|
|
25365
|
+
const responsePath = path6.join(runDir, "jev", "responses");
|
|
25366
|
+
await mkdir3(responsePath, { recursive: true });
|
|
25367
|
+
const responseDir = await fileInsideWorkspace(context.directory, responsePath);
|
|
25368
|
+
if (path6.dirname(responseDir) !== path6.join(runDir, "jev")) throw new Error("A pasta de respostas tem de pertencer ao run Jev.");
|
|
25369
|
+
let saved = 0;
|
|
25370
|
+
let skipped = 0;
|
|
25371
|
+
for (const batch of batches) {
|
|
25372
|
+
const batchId = batch.batch_id;
|
|
25373
|
+
if (typeof batchId !== "string" || !/^batch-[0-9]{4}-[A-Za-z0-9._-]+$/.test(batchId) || typeof batch.request_file !== "string" || typeof batch.request_fingerprint !== "string") {
|
|
25374
|
+
throw new Error("O plano Jev cont\xE9m um lote inv\xE1lido.");
|
|
25375
|
+
}
|
|
25376
|
+
const acceptedFile = path6.join(runDir, "jev", "accepted", `${batchId}.json`);
|
|
25377
|
+
const responseFile = path6.join(responseDir, `${batchId}.response.json`);
|
|
25378
|
+
if (await fileExists(acceptedFile) || await fileExists(responseFile)) {
|
|
25379
|
+
skipped++;
|
|
25380
|
+
continue;
|
|
25381
|
+
}
|
|
25382
|
+
const requestFile = await fileInsideWorkspace(context.directory, batch.request_file);
|
|
25383
|
+
if (path6.dirname(requestFile) !== path6.join(runDir, "jev", "requests")) throw new Error(`${batchId}: pedido fora do run.`);
|
|
25384
|
+
const request = JSON.parse(await readFile4(requestFile, "utf8"));
|
|
25385
|
+
const fingerprint = createHash5("sha256").update(canonicalJson(request)).digest("hex");
|
|
25386
|
+
if (fingerprint !== batch.request_fingerprint) throw new Error(`${batchId}: fingerprint do pedido n\xE3o corresponde ao plano.`);
|
|
25387
|
+
let result;
|
|
25388
|
+
try {
|
|
25389
|
+
const output = await decide.execute({ request_file: requestFile }, context);
|
|
25390
|
+
result = JSON.parse(typeof output === "string" ? output : output.output);
|
|
25391
|
+
} catch (error45) {
|
|
25392
|
+
return JSON.stringify({ verified: false, saved, skipped, stopped_at: batchId, error: error45 instanceof Error ? error45.message : "Falha na chamada Jev." });
|
|
25393
|
+
}
|
|
25394
|
+
if (typeof result.response_file !== "string") {
|
|
25395
|
+
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." });
|
|
25396
|
+
}
|
|
25397
|
+
try {
|
|
25398
|
+
await link(result.response_file, responseFile);
|
|
25399
|
+
} catch {
|
|
25400
|
+
return JSON.stringify({
|
|
25401
|
+
verified: false,
|
|
25402
|
+
saved,
|
|
25403
|
+
skipped,
|
|
25404
|
+
stopped_at: batchId,
|
|
25405
|
+
recovery_file: result.response_file,
|
|
25406
|
+
error: "Resposta conclu\xEDda mas n\xE3o copiada para o run; recuperar o ficheiro indicado, sem repetir a chamada."
|
|
25407
|
+
});
|
|
25408
|
+
}
|
|
25409
|
+
saved++;
|
|
25410
|
+
}
|
|
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
|
+
}
|
|
25420
|
+
});
|
|
25421
|
+
}
|
|
25301
25422
|
function createForgeCodebookTool(forgeBaseUrl, gatewayBaseUrl, paths) {
|
|
25302
25423
|
return tool({
|
|
25303
25424
|
description: "Gera um rascunho de codebook em portugu\xEAs europeu a partir de uma pergunta e das respostas. Apresentar para aprova\xE7\xE3o humana antes de codificar; n\xE3o aplica c\xF3digos nem altera ficheiros.",
|