pi-jev-guard 0.1.3 → 0.1.5
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/extensions/index.ts +43 -15
- package/package.json +1 -1
- package/src/commands.ts +11 -1
package/extensions/index.ts
CHANGED
|
@@ -307,35 +307,63 @@ export default function (pi: ExtensionAPI) {
|
|
|
307
307
|
getLastGate: () => lastGate,
|
|
308
308
|
});
|
|
309
309
|
|
|
310
|
-
// Seed
|
|
311
|
-
//
|
|
312
|
-
//
|
|
313
|
-
//
|
|
314
|
-
|
|
315
|
-
|
|
310
|
+
// Seed all'avvio: pi ripristina il modello di sessione PRIMA di
|
|
311
|
+
// session_start, quindi un twin persistito non esisterebbe ancora e
|
|
312
|
+
// cadrebbe su "Could not restore model ...__jev". Pre-registriamo un
|
|
313
|
+
// overlay statico dai provider builtin quando la config persiste
|
|
314
|
+
// automatic (o JEV_AUTO_UPSTREAM è impostato); session_start lo
|
|
315
|
+
// sostituisce col clone live dal registry.
|
|
316
|
+
const bootAuto = process.env.JEV_AUTO_UPSTREAM?.trim();
|
|
317
|
+
const autoOff = bootAuto === "0" || bootAuto?.toLowerCase() === "off";
|
|
318
|
+
let seedTarget: { provider: string; model: string } | undefined;
|
|
319
|
+
if (bootAuto && !autoOff) {
|
|
320
|
+
const parsed = parseUpstreamRef([bootAuto]);
|
|
321
|
+
if (!("error" in parsed)) seedTarget = parsed;
|
|
322
|
+
} else if (!bootAuto && config.mode === "automatic") {
|
|
323
|
+
seedTarget = {
|
|
324
|
+
provider: config.automatic.upstreamProvider,
|
|
325
|
+
model: config.automatic.upstreamModel,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
if (seedTarget) {
|
|
316
329
|
try {
|
|
317
330
|
// providers/all è mappato dagli alias di pi; il subpath del singolo
|
|
318
331
|
// provider non lo è e fallirebbe a load (solo installazioni npm).
|
|
319
|
-
const base = builtinProviders().find((p) => p.id ===
|
|
320
|
-
if (!base) throw new Error(
|
|
332
|
+
const base = builtinProviders().find((p) => p.id === seedTarget?.provider);
|
|
333
|
+
if (!base) throw new Error(`provider ${seedTarget.provider} not in builtins`);
|
|
334
|
+
// Il catalogo builtin può non avere il modello salvato (es. versioni
|
|
335
|
+
// più vecchie senza deepseek-flash): uniamo la definizione statica.
|
|
336
|
+
const extra =
|
|
337
|
+
seedTarget.provider === "deepseek" && seedTarget.model === "deepseek-flash"
|
|
338
|
+
? [STATIC_DEEPSEEK_FLASH]
|
|
339
|
+
: [];
|
|
321
340
|
const seedUpstream: Provider = {
|
|
322
341
|
...base,
|
|
323
|
-
getModels: () =>
|
|
342
|
+
getModels: () => {
|
|
343
|
+
const models = base.getModels();
|
|
344
|
+
const missing = extra.filter(
|
|
345
|
+
(m) => !models.some((existing) => existing.id === m.id),
|
|
346
|
+
);
|
|
347
|
+
return [...models, ...missing];
|
|
348
|
+
},
|
|
324
349
|
};
|
|
350
|
+
const hasModel = seedUpstream
|
|
351
|
+
.getModels()
|
|
352
|
+
.some((m) => m.id === seedTarget?.model);
|
|
353
|
+
if (!hasModel) throw new Error(`model ${seedTarget.model} not in builtins`);
|
|
325
354
|
const overlay = buildOverlaidProvider({
|
|
326
355
|
upstream: seedUpstream,
|
|
327
|
-
twinModelIds: [
|
|
356
|
+
twinModelIds: [seedTarget.model],
|
|
328
357
|
getConfig,
|
|
329
358
|
getReview: getGateReview,
|
|
330
359
|
onVerdict: recordGateVerdict,
|
|
331
360
|
});
|
|
332
361
|
pi.registerProvider(overlay);
|
|
333
|
-
upstreamRefs.set(
|
|
334
|
-
overlaidProviderId =
|
|
335
|
-
twinTarget = { provider:
|
|
362
|
+
upstreamRefs.set(seedTarget.provider, seedUpstream);
|
|
363
|
+
overlaidProviderId = seedTarget.provider;
|
|
364
|
+
twinTarget = { provider: seedTarget.provider, model: seedTarget.model };
|
|
336
365
|
} catch {
|
|
337
|
-
|
|
338
|
-
twinTarget = undefined;
|
|
366
|
+
// Nessun seed: il twin arriverà da session_start se possibile.
|
|
339
367
|
}
|
|
340
368
|
}
|
|
341
369
|
|
package/package.json
CHANGED
package/src/commands.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFileSync, existsSync, statSync, realpathSync, writeFileSync, mkdirSync, chmodSync } from "node:fs";
|
|
2
2
|
import { resolve, dirname } from "node:path";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
3
4
|
import type { ExtensionAPI, ModelRegistry } from "@earendil-works/pi-coding-agent";
|
|
4
5
|
import type { JevConfig } from "./config.ts";
|
|
5
6
|
import { defaultConfigPath, expandHome, parseUpstreamRef, resolveBackend, saveConfig } from "./config.ts";
|
|
@@ -345,9 +346,18 @@ export function registerJevCommand(pi: ExtensionAPI, deps: JevCommandDeps) {
|
|
|
345
346
|
|
|
346
347
|
if (sub === "save-key") {
|
|
347
348
|
const cfg = deps.config();
|
|
348
|
-
|
|
349
|
+
let target = cfg.jev.apiKeyFile?.trim()
|
|
349
350
|
? expandHome(cfg.jev.apiKeyFile.trim())
|
|
350
351
|
: resolve(dirname(defaultConfigPath()), "jev-api-key.txt");
|
|
352
|
+
// Mai chiavi in tmp: dir effimera (pulizia automatica = chiave persa).
|
|
353
|
+
// Può capitare con config stantie caricate in memoria prima di un fix.
|
|
354
|
+
if (target === tmpdir() || target.startsWith(tmpdir() + "/")) {
|
|
355
|
+
ctx.ui.notify(
|
|
356
|
+
`Jev: percorso chiave sotto tmp ignorato (${target}); uso quello canonico.`,
|
|
357
|
+
"warning",
|
|
358
|
+
);
|
|
359
|
+
target = resolve(dirname(defaultConfigPath()), "jev-api-key.txt");
|
|
360
|
+
}
|
|
351
361
|
let key: string | undefined;
|
|
352
362
|
try {
|
|
353
363
|
key = await ctx.ui.input(
|