minimal-forge-work-pack-sync 0.1.38 → 0.1.40
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 +186 -9
- package/dist/repair.js +2 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7607,7 +7607,7 @@ var DEFAULT_DEBUG_TRACE_LIMITS = {
|
|
|
7607
7607
|
// packages/shared/src/contracts/settings.ts
|
|
7608
7608
|
var DOCUMENT_READER_AGENT = "document-reader";
|
|
7609
7609
|
var OPENROUTER_ALIAS_PROVIDER_NAME = "OpenRouter (via Forge)";
|
|
7610
|
-
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.
|
|
7610
|
+
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.40";
|
|
7611
7611
|
var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
|
|
7612
7612
|
var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
|
|
7613
7613
|
var FIRECRAWL_KEYLESS_MCP_NAME = "firecrawl";
|
|
@@ -7696,6 +7696,7 @@ function managedPermission(value) {
|
|
|
7696
7696
|
forge_decide: "allow",
|
|
7697
7697
|
forge_decide_run: "allow",
|
|
7698
7698
|
forge_generate_codebook: "allow",
|
|
7699
|
+
forge_image: "allow",
|
|
7699
7700
|
forge_feedback: "deny"
|
|
7700
7701
|
};
|
|
7701
7702
|
}
|
|
@@ -8169,6 +8170,172 @@ async function replaceFile(filename, contents) {
|
|
|
8169
8170
|
await rename(temporary, filename);
|
|
8170
8171
|
}
|
|
8171
8172
|
|
|
8173
|
+
// packages/cli/src/reasoningLoopGuard.ts
|
|
8174
|
+
var LINE_MIN_CHARS = 2;
|
|
8175
|
+
var LINE_KEY_MAX_CHARS = 400;
|
|
8176
|
+
var CYCLE_CHECK_STRIDE = 32;
|
|
8177
|
+
var MAX_CYCLE_PERIOD = 512;
|
|
8178
|
+
var MIN_CYCLE_SPAN = 512;
|
|
8179
|
+
var CYCLE_TAIL_CHARS = 4 * MAX_CYCLE_PERIOD;
|
|
8180
|
+
var MIN_REPEATED_LINE_CHARS = 2048;
|
|
8181
|
+
var MIN_REPEATED_LINE_COVERAGE = 0.6;
|
|
8182
|
+
var MIN_REPEATED_LINE_CONCENTRATION = 4;
|
|
8183
|
+
var MAX_DISTINCT_LINES = 5e3;
|
|
8184
|
+
var REASONING_LOOP_RESUME_TEXT = "[Forge] A gera\xE7\xE3o anterior foi interrompida porque o racioc\xEDnio estava a repetir-se sem avan\xE7ar. N\xE3o repitas o racioc\xEDnio anterior. Continua a tarefa a partir do ponto em que est\xE1: executa a pr\xF3xima a\xE7\xE3o ou d\xE1 a resposta final.";
|
|
8185
|
+
function trailingCycle(text, maxPeriod, minSpan) {
|
|
8186
|
+
for (let period = 1; period <= maxPeriod; period++) {
|
|
8187
|
+
if (text.length < period * 2) break;
|
|
8188
|
+
const need = Math.max(minSpan, 2 * period) - period;
|
|
8189
|
+
const limit = Math.min(text.length - period, need);
|
|
8190
|
+
let matched = 0;
|
|
8191
|
+
while (matched < limit && text[text.length - period - 1 - matched] === text[text.length - 1 - matched]) matched++;
|
|
8192
|
+
if (matched >= need && new Set(text.slice(text.length - period)).size >= 2) return matched + period;
|
|
8193
|
+
}
|
|
8194
|
+
return 0;
|
|
8195
|
+
}
|
|
8196
|
+
var ReasoningLoopDetector = class {
|
|
8197
|
+
tail = "";
|
|
8198
|
+
sinceCycleCheck = 0;
|
|
8199
|
+
partial = "";
|
|
8200
|
+
lines = /* @__PURE__ */ new Map();
|
|
8201
|
+
totalLineChars = 0;
|
|
8202
|
+
repeatedLineChars = 0;
|
|
8203
|
+
lineInstances = 0;
|
|
8204
|
+
rule;
|
|
8205
|
+
get tripped() {
|
|
8206
|
+
return this.rule;
|
|
8207
|
+
}
|
|
8208
|
+
push(text) {
|
|
8209
|
+
if (this.rule || !text) return this.rule;
|
|
8210
|
+
if (this.pushLines(text)) return this.rule = "reasoning-lines";
|
|
8211
|
+
this.tail = (this.tail + text).slice(-CYCLE_TAIL_CHARS);
|
|
8212
|
+
this.sinceCycleCheck += text.length;
|
|
8213
|
+
if (this.sinceCycleCheck < CYCLE_CHECK_STRIDE) return void 0;
|
|
8214
|
+
this.sinceCycleCheck = 0;
|
|
8215
|
+
if (trailingCycle(this.tail, MAX_CYCLE_PERIOD, MIN_CYCLE_SPAN) > 0) return this.rule = "reasoning-cycle";
|
|
8216
|
+
return void 0;
|
|
8217
|
+
}
|
|
8218
|
+
pushLines(text) {
|
|
8219
|
+
this.partial += text;
|
|
8220
|
+
let index;
|
|
8221
|
+
while ((index = this.partial.indexOf("\n")) >= 0) {
|
|
8222
|
+
this.addLine(this.partial.slice(0, index).trim());
|
|
8223
|
+
this.partial = this.partial.slice(index + 1);
|
|
8224
|
+
}
|
|
8225
|
+
if (this.partial.length > LINE_KEY_MAX_CHARS) this.partial = this.partial.slice(-LINE_KEY_MAX_CHARS);
|
|
8226
|
+
if (this.repeatedLineChars < MIN_REPEATED_LINE_CHARS || this.totalLineChars === 0) return false;
|
|
8227
|
+
if (this.repeatedLineChars / this.totalLineChars < MIN_REPEATED_LINE_COVERAGE) return false;
|
|
8228
|
+
return this.lineInstances / this.lines.size >= MIN_REPEATED_LINE_CONCENTRATION;
|
|
8229
|
+
}
|
|
8230
|
+
addLine(line) {
|
|
8231
|
+
if (line.length < LINE_MIN_CHARS) return;
|
|
8232
|
+
const key = line.slice(0, LINE_KEY_MAX_CHARS);
|
|
8233
|
+
const previous = this.lines.get(key) ?? 0;
|
|
8234
|
+
if (previous === 0 && this.lines.size >= MAX_DISTINCT_LINES) return;
|
|
8235
|
+
this.lines.set(key, previous + 1);
|
|
8236
|
+
this.totalLineChars += key.length;
|
|
8237
|
+
this.lineInstances += 1;
|
|
8238
|
+
if (previous === 1) this.repeatedLineChars += key.length * 2;
|
|
8239
|
+
else if (previous > 1) this.repeatedLineChars += key.length;
|
|
8240
|
+
}
|
|
8241
|
+
};
|
|
8242
|
+
var MAX_AUTOMATIC_RESUMES = 1;
|
|
8243
|
+
function createReasoningLoopGuard(client, log = console.error) {
|
|
8244
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
8245
|
+
const session = (id) => {
|
|
8246
|
+
let state = sessions.get(id);
|
|
8247
|
+
if (!state) sessions.set(id, state = { parts: /* @__PURE__ */ new Map(), closedParts: /* @__PURE__ */ new Set(), interruptions: 0, interrupted: false, resumePending: false });
|
|
8248
|
+
return state;
|
|
8249
|
+
};
|
|
8250
|
+
const closeParts = (state) => {
|
|
8251
|
+
for (const partID of state.parts.keys()) state.closedParts.add(partID);
|
|
8252
|
+
state.parts.clear();
|
|
8253
|
+
};
|
|
8254
|
+
async function interrupt(sessionID, state, rule) {
|
|
8255
|
+
closeParts(state);
|
|
8256
|
+
state.interrupted = true;
|
|
8257
|
+
state.interruptions += 1;
|
|
8258
|
+
state.resumePending = state.interruptions <= MAX_AUTOMATIC_RESUMES;
|
|
8259
|
+
log(`[Forge reasoning guard] Repetitive reasoning interrupted (${rule}, interruption ${state.interruptions})`);
|
|
8260
|
+
try {
|
|
8261
|
+
await client.session.abort({ path: { id: sessionID } });
|
|
8262
|
+
} catch (error45) {
|
|
8263
|
+
state.resumePending = false;
|
|
8264
|
+
log(`[Forge reasoning guard] Abort failed: ${error45 instanceof Error ? error45.message : String(error45)}`);
|
|
8265
|
+
}
|
|
8266
|
+
}
|
|
8267
|
+
async function resume(sessionID, state) {
|
|
8268
|
+
state.resumePending = false;
|
|
8269
|
+
try {
|
|
8270
|
+
await client.session.promptAsync({
|
|
8271
|
+
path: { id: sessionID },
|
|
8272
|
+
body: {
|
|
8273
|
+
...state.agent ? { agent: state.agent } : {},
|
|
8274
|
+
...state.model ? { model: state.model } : {},
|
|
8275
|
+
parts: [{ type: "text", text: REASONING_LOOP_RESUME_TEXT }]
|
|
8276
|
+
}
|
|
8277
|
+
});
|
|
8278
|
+
} catch (error45) {
|
|
8279
|
+
log(`[Forge reasoning guard] Resume failed: ${error45 instanceof Error ? error45.message : String(error45)}`);
|
|
8280
|
+
}
|
|
8281
|
+
}
|
|
8282
|
+
async function reasoningText(sessionID, partID, text, absolute) {
|
|
8283
|
+
const state = session(sessionID);
|
|
8284
|
+
if (state.interrupted || state.closedParts.has(partID)) return;
|
|
8285
|
+
let part = state.parts.get(partID);
|
|
8286
|
+
if (!part) state.parts.set(partID, part = { detector: new ReasoningLoopDetector(), seen: 0 });
|
|
8287
|
+
const fresh = absolute ? text.slice(part.seen) : text;
|
|
8288
|
+
part.seen = absolute ? Math.max(part.seen, text.length) : part.seen + text.length;
|
|
8289
|
+
if (!fresh || part.detector.tripped) return;
|
|
8290
|
+
const rule = part.detector.push(fresh);
|
|
8291
|
+
if (rule) await interrupt(sessionID, state, rule);
|
|
8292
|
+
}
|
|
8293
|
+
return async ({ event }) => {
|
|
8294
|
+
try {
|
|
8295
|
+
const properties = event?.properties ?? {};
|
|
8296
|
+
if (event?.type === "message.part.updated") {
|
|
8297
|
+
const part = properties.part;
|
|
8298
|
+
if (part?.type !== "reasoning" || typeof part.id !== "string" || typeof part.sessionID !== "string") return;
|
|
8299
|
+
if (typeof part.text === "string") await reasoningText(part.sessionID, part.id, part.text, true);
|
|
8300
|
+
return;
|
|
8301
|
+
}
|
|
8302
|
+
if (event?.type === "message.part.delta") {
|
|
8303
|
+
const { sessionID, partID, field, delta } = properties;
|
|
8304
|
+
if (field !== "text" || typeof sessionID !== "string" || typeof partID !== "string" || typeof delta !== "string") return;
|
|
8305
|
+
if (!sessions.get(sessionID)?.parts.has(partID)) return;
|
|
8306
|
+
await reasoningText(sessionID, partID, delta, false);
|
|
8307
|
+
return;
|
|
8308
|
+
}
|
|
8309
|
+
if (event?.type === "message.updated") {
|
|
8310
|
+
const info = properties.info;
|
|
8311
|
+
if (info?.role !== "user" || typeof info.sessionID !== "string") return;
|
|
8312
|
+
const state = session(info.sessionID);
|
|
8313
|
+
if (typeof info.agent === "string") state.agent = info.agent;
|
|
8314
|
+
if (typeof info.model?.providerID === "string" && typeof info.model.modelID === "string") {
|
|
8315
|
+
state.model = { providerID: info.model.providerID, modelID: info.model.modelID };
|
|
8316
|
+
}
|
|
8317
|
+
return;
|
|
8318
|
+
}
|
|
8319
|
+
if (event?.type === "session.idle") {
|
|
8320
|
+
const sessionID = properties.sessionID;
|
|
8321
|
+
if (typeof sessionID !== "string") return;
|
|
8322
|
+
const state = sessions.get(sessionID);
|
|
8323
|
+
if (!state) return;
|
|
8324
|
+
closeParts(state);
|
|
8325
|
+
state.interrupted = false;
|
|
8326
|
+
if (state.resumePending) await resume(sessionID, state);
|
|
8327
|
+
return;
|
|
8328
|
+
}
|
|
8329
|
+
if (event?.type === "session.deleted") {
|
|
8330
|
+
const info = properties.info;
|
|
8331
|
+
if (typeof info?.id === "string") sessions.delete(info.id);
|
|
8332
|
+
}
|
|
8333
|
+
} catch (error45) {
|
|
8334
|
+
log(`[Forge reasoning guard] Event handling failed: ${error45 instanceof Error ? error45.message : String(error45)}`);
|
|
8335
|
+
}
|
|
8336
|
+
};
|
|
8337
|
+
}
|
|
8338
|
+
|
|
8172
8339
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
8173
8340
|
var import_yaml = __toESM(require_dist(), 1);
|
|
8174
8341
|
import { link, mkdir as mkdir7, mkdtemp as mkdtemp2, readdir as readdir5, readFile as readFile11, realpath, rename as rename8, rm as rm6, rmdir, stat as stat3, unlink, writeFile as writeFile8 } from "node:fs/promises";
|
|
@@ -26244,7 +26411,7 @@ async function syncLocalWorker(paths, credentials, manifest) {
|
|
|
26244
26411
|
}
|
|
26245
26412
|
|
|
26246
26413
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
26247
|
-
var PLUGIN_VERSION = "0.1.
|
|
26414
|
+
var PLUGIN_VERSION = "0.1.40";
|
|
26248
26415
|
var FORGE_DECISION_TIMEOUT_MS = 11e4;
|
|
26249
26416
|
var STATUS_FILENAME = "work-pack-startup-status.json";
|
|
26250
26417
|
var activeSync = /* @__PURE__ */ new Map();
|
|
@@ -26263,7 +26430,9 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
|
26263
26430
|
const shared = globalThis;
|
|
26264
26431
|
const legacyOwners = shared[ownershipSymbol] ??= /* @__PURE__ */ new Set();
|
|
26265
26432
|
const legacyOwnerKey = JSON.stringify([forgeBaseUrl, legacyPath]);
|
|
26433
|
+
const client = reasoningLoopGuardClient(_input);
|
|
26266
26434
|
return {
|
|
26435
|
+
...client ? { event: createReasoningLoopGuard(client) } : {},
|
|
26267
26436
|
"tool.execute.after": async (input) => {
|
|
26268
26437
|
if (input.tool !== "skill" || legacyOwners.has(legacyOwnerKey)) return;
|
|
26269
26438
|
const slug = typeof input.args?.name === "string" ? input.args.name.trim().toLowerCase() : "";
|
|
@@ -26312,14 +26481,20 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
|
|
|
26312
26481
|
}
|
|
26313
26482
|
};
|
|
26314
26483
|
};
|
|
26484
|
+
function reasoningLoopGuardClient(input) {
|
|
26485
|
+
if (!input || typeof input !== "object" || !("client" in input)) return void 0;
|
|
26486
|
+
const client = input.client;
|
|
26487
|
+
if (typeof client?.session?.abort !== "function" || typeof client.session.promptAsync !== "function") return void 0;
|
|
26488
|
+
return client;
|
|
26489
|
+
}
|
|
26315
26490
|
var ForgeDecisionRejectedError = class extends Error {
|
|
26316
26491
|
};
|
|
26317
26492
|
function createForgeImageTool(forgeBaseUrl, gatewayBaseUrl, paths) {
|
|
26318
26493
|
return tool({
|
|
26319
|
-
description: "Cria ou edita uma imagem
|
|
26494
|
+
description: "Cria ou edita uma imagem quadrada (PNG, formato 1:1) quando a pessoa pede uma imagem, ilustra\xE7\xE3o, \xEDcone ou altera\xE7\xE3o a uma fotografia. Se pedir outro formato, explica que s\xF3 existe o quadrado antes de gerar. Escreve em prompt uma descri\xE7\xE3o completa: assunto, estilo, composi\xE7\xE3o, cores e o texto exato que deva aparecer, entre aspas. Para editar uma imagem existente, indica-a em referencePath e descreve apenas a altera\xE7\xE3o. Cada chamada consome uma das 30 imagens mensais da pessoa: faz uma chamada por pedido, n\xE3o cries varia\xE7\xF5es ou revis\xF5es por iniciativa pr\xF3pria e n\xE3o repitas depois de um erro. Mostra a imagem \xE0 pessoa na conversa e guarda o PNG na pasta de trabalho.",
|
|
26320
26495
|
args: {
|
|
26321
|
-
prompt: tool.schema.string().min(1).max(8e3).describe("Descri\xE7\xE3o da imagem ou altera\xE7\xE3o
|
|
26322
|
-
referencePath: tool.schema.string().optional().describe("Caminho
|
|
26496
|
+
prompt: tool.schema.string().min(1).max(8e3).describe("Descri\xE7\xE3o completa da imagem, ou s\xF3 da altera\xE7\xE3o quando h\xE1 refer\xEAncia"),
|
|
26497
|
+
referencePath: tool.schema.string().optional().describe("Caminho absoluto de uma imagem PNG, JPEG ou WebP a editar, at\xE9 2,5 MB")
|
|
26323
26498
|
},
|
|
26324
26499
|
async execute(args, context) {
|
|
26325
26500
|
const requestId = randomUUID4();
|
|
@@ -26355,9 +26530,11 @@ function createForgeImageTool(forgeBaseUrl, gatewayBaseUrl, paths) {
|
|
|
26355
26530
|
await writeFile8(destination, image, { flag: "wx" });
|
|
26356
26531
|
const reset = body.quota && new Intl.DateTimeFormat("pt-PT", { dateStyle: "long", timeZone: "Europe/Lisbon" }).format(new Date(body.quota.resetsAt));
|
|
26357
26532
|
const remaining = body.quota ? ` Restam ${body.quota.remaining} imagens at\xE9 ${reset}.` : "";
|
|
26358
|
-
return
|
|
26359
|
-
|
|
26360
|
-
|
|
26533
|
+
return {
|
|
26534
|
+
title: "Imagem criada",
|
|
26535
|
+
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.`,
|
|
26536
|
+
attachments: [{ type: "file", mime: "image/png", url: `data:image/png;base64,${body.b64_json}`, filename: path12.basename(destination) }]
|
|
26537
|
+
};
|
|
26361
26538
|
}
|
|
26362
26539
|
});
|
|
26363
26540
|
}
|
|
@@ -26584,7 +26761,7 @@ function createForgeCodebookTool(forgeBaseUrl, gatewayBaseUrl, paths) {
|
|
|
26584
26761
|
code: tool.schema.number().int().nonnegative(),
|
|
26585
26762
|
label: tool.schema.string().min(1).max(120),
|
|
26586
26763
|
description: tool.schema.string().max(1e3).nullable().optional()
|
|
26587
|
-
})).min(1).max(
|
|
26764
|
+
})).min(1).max(20).optional().describe("Grelha completa a enriquecer, incluindo 98/99 se existirem; omitir para gerar de raiz"),
|
|
26588
26765
|
context: tool.schema.string().max(1e4).optional().describe("Contexto conhecido, regras do estudo e exemplos humanos explicitamente aprovados; n\xE3o apresentar c\xF3digos anteriores de IA como verdade")
|
|
26589
26766
|
},
|
|
26590
26767
|
async execute(args, context) {
|
package/dist/repair.js
CHANGED
|
@@ -401,7 +401,7 @@ var DEVICE_ENROLLMENT_PROTOCOL_VERSION = 1;
|
|
|
401
401
|
// packages/shared/src/contracts/settings.ts
|
|
402
402
|
var DOCUMENT_READER_AGENT = "document-reader";
|
|
403
403
|
var OPENROUTER_ALIAS_PROVIDER_NAME = "OpenRouter (via Forge)";
|
|
404
|
-
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.
|
|
404
|
+
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.40";
|
|
405
405
|
var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
|
|
406
406
|
var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
|
|
407
407
|
var FIRECRAWL_KEYLESS_MCP_NAME = "firecrawl";
|
|
@@ -490,6 +490,7 @@ function managedPermission(value) {
|
|
|
490
490
|
forge_decide: "allow",
|
|
491
491
|
forge_decide_run: "allow",
|
|
492
492
|
forge_generate_codebook: "allow",
|
|
493
|
+
forge_image: "allow",
|
|
493
494
|
forge_feedback: "deny"
|
|
494
495
|
};
|
|
495
496
|
}
|