pi-byterover 0.2.2 → 0.2.3
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.d.ts +1 -1
- package/dist/index.js +101 -66
- package/dist/tools.d.ts +1 -1
- package/package.json +14 -13
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { accessSync, constants, existsSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { delimiter, dirname, isAbsolute, join } from "node:path";
|
|
3
3
|
import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
|
-
//#region node_modules/.pnpm/@byterover+brv-bridge@1.
|
|
5
|
+
//#region node_modules/.pnpm/@byterover+brv-bridge@1.2.0/node_modules/@byterover/brv-bridge/dist/process.js
|
|
6
6
|
function resolveWin32Command(name) {
|
|
7
7
|
if (process.platform !== "win32") return {
|
|
8
8
|
command: name,
|
|
@@ -172,7 +172,7 @@ async function brvSearch(params) {
|
|
|
172
172
|
return parseLastJsonLine(stdout);
|
|
173
173
|
}
|
|
174
174
|
//#endregion
|
|
175
|
-
//#region node_modules/.pnpm/@byterover+brv-bridge@1.
|
|
175
|
+
//#region node_modules/.pnpm/@byterover+brv-bridge@1.2.0/node_modules/@byterover/brv-bridge/dist/bridge.js
|
|
176
176
|
const noopLogger = {
|
|
177
177
|
debug: () => {},
|
|
178
178
|
info: () => {},
|
|
@@ -235,7 +235,12 @@ var BrvBridge = class {
|
|
|
235
235
|
query,
|
|
236
236
|
signal: options?.signal
|
|
237
237
|
});
|
|
238
|
-
|
|
238
|
+
const recall = { content: (result.data?.result ?? result.data?.content ?? "").trim() };
|
|
239
|
+
if (result.data?.matchedDocs !== void 0) recall.matchedDocs = result.data.matchedDocs;
|
|
240
|
+
if (result.data?.tier !== void 0) recall.tier = result.data.tier;
|
|
241
|
+
if (result.data?.durationMs !== void 0) recall.durationMs = result.data.durationMs;
|
|
242
|
+
if (result.data?.topScore !== void 0) recall.topScore = result.data.topScore;
|
|
243
|
+
return recall;
|
|
239
244
|
} catch (err) {
|
|
240
245
|
const msg = String(err);
|
|
241
246
|
if (msg.includes("aborted")) this.logger.warn("recall aborted");
|
|
@@ -320,7 +325,7 @@ var BrvBridge = class {
|
|
|
320
325
|
}
|
|
321
326
|
};
|
|
322
327
|
//#endregion
|
|
323
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
328
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.js
|
|
324
329
|
var _a$1;
|
|
325
330
|
function $constructor(name, initializer, params) {
|
|
326
331
|
function init(inst, def) {
|
|
@@ -379,7 +384,7 @@ function config(newConfig) {
|
|
|
379
384
|
return globalConfig;
|
|
380
385
|
}
|
|
381
386
|
//#endregion
|
|
382
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
387
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/util.js
|
|
383
388
|
function getEnumValues(entries) {
|
|
384
389
|
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
|
|
385
390
|
return Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
|
|
@@ -691,7 +696,7 @@ function issue(...args) {
|
|
|
691
696
|
return { ...iss };
|
|
692
697
|
}
|
|
693
698
|
//#endregion
|
|
694
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
699
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/errors.js
|
|
695
700
|
const initializer$1 = (inst, def) => {
|
|
696
701
|
inst.name = "$ZodError";
|
|
697
702
|
Object.defineProperty(inst, "_zod", {
|
|
@@ -751,7 +756,7 @@ function formatError(error, mapper = (issue) => issue.message) {
|
|
|
751
756
|
return fieldErrors;
|
|
752
757
|
}
|
|
753
758
|
//#endregion
|
|
754
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
759
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/parse.js
|
|
755
760
|
const _parse = (_Err) => (schema, value, _ctx, _params) => {
|
|
756
761
|
const ctx = _ctx ? {
|
|
757
762
|
..._ctx,
|
|
@@ -865,7 +870,7 @@ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
|
865
870
|
return _safeParseAsync(_Err)(schema, value, _ctx);
|
|
866
871
|
};
|
|
867
872
|
//#endregion
|
|
868
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
873
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/regexes.js
|
|
869
874
|
/**
|
|
870
875
|
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
871
876
|
* (timestamps embedded in the id). Use {@link cuid2} instead.
|
|
@@ -929,7 +934,7 @@ const boolean$1 = /^(?:true|false)$/i;
|
|
|
929
934
|
const lowercase = /^[^A-Z]*$/;
|
|
930
935
|
const uppercase = /^[^a-z]*$/;
|
|
931
936
|
//#endregion
|
|
932
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
937
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/checks.js
|
|
933
938
|
const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
|
|
934
939
|
var _a;
|
|
935
940
|
inst._zod ?? (inst._zod = {});
|
|
@@ -1287,7 +1292,7 @@ const $ZodCheckOverwrite = /* @__PURE__ */ $constructor("$ZodCheckOverwrite", (i
|
|
|
1287
1292
|
};
|
|
1288
1293
|
});
|
|
1289
1294
|
//#endregion
|
|
1290
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
1295
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/doc.js
|
|
1291
1296
|
var Doc = class {
|
|
1292
1297
|
constructor(args = []) {
|
|
1293
1298
|
this.content = [];
|
|
@@ -1318,14 +1323,14 @@ var Doc = class {
|
|
|
1318
1323
|
}
|
|
1319
1324
|
};
|
|
1320
1325
|
//#endregion
|
|
1321
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
1326
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/versions.js
|
|
1322
1327
|
const version = {
|
|
1323
1328
|
major: 4,
|
|
1324
1329
|
minor: 4,
|
|
1325
|
-
patch:
|
|
1330
|
+
patch: 3
|
|
1326
1331
|
};
|
|
1327
1332
|
//#endregion
|
|
1328
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
1333
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/schemas.js
|
|
1329
1334
|
const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
1330
1335
|
var _a;
|
|
1331
1336
|
inst ?? (inst = {});
|
|
@@ -2201,20 +2206,23 @@ const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
|
|
|
2201
2206
|
});
|
|
2202
2207
|
const $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def) => {
|
|
2203
2208
|
$ZodType.init(inst, def);
|
|
2209
|
+
inst._zod.optin = "optional";
|
|
2204
2210
|
inst._zod.parse = (payload, ctx) => {
|
|
2205
2211
|
if (ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
|
|
2206
2212
|
const _out = def.transform(payload.value, payload);
|
|
2207
2213
|
if (ctx.async) return (_out instanceof Promise ? _out : Promise.resolve(_out)).then((output) => {
|
|
2208
2214
|
payload.value = output;
|
|
2215
|
+
payload.fallback = true;
|
|
2209
2216
|
return payload;
|
|
2210
2217
|
});
|
|
2211
2218
|
if (_out instanceof Promise) throw new $ZodAsyncError();
|
|
2212
2219
|
payload.value = _out;
|
|
2220
|
+
payload.fallback = true;
|
|
2213
2221
|
return payload;
|
|
2214
2222
|
};
|
|
2215
2223
|
});
|
|
2216
2224
|
function handleOptionalResult(result, input) {
|
|
2217
|
-
if (result.issues.length
|
|
2225
|
+
if (input === void 0 && (result.issues.length || result.fallback)) return {
|
|
2218
2226
|
issues: [],
|
|
2219
2227
|
value: void 0
|
|
2220
2228
|
};
|
|
@@ -2233,9 +2241,10 @@ const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) =>
|
|
|
2233
2241
|
});
|
|
2234
2242
|
inst._zod.parse = (payload, ctx) => {
|
|
2235
2243
|
if (def.innerType._zod.optin === "optional") {
|
|
2244
|
+
const input = payload.value;
|
|
2236
2245
|
const result = def.innerType._zod.run(payload, ctx);
|
|
2237
|
-
if (result instanceof Promise) return result.then((r) => handleOptionalResult(r,
|
|
2238
|
-
return handleOptionalResult(result,
|
|
2246
|
+
if (result instanceof Promise) return result.then((r) => handleOptionalResult(r, input));
|
|
2247
|
+
return handleOptionalResult(result, input);
|
|
2239
2248
|
}
|
|
2240
2249
|
if (payload.value === void 0) return payload;
|
|
2241
2250
|
return def.innerType._zod.run(payload, ctx);
|
|
@@ -2320,7 +2329,7 @@ function handleNonOptionalResult(payload, inst) {
|
|
|
2320
2329
|
}
|
|
2321
2330
|
const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
|
|
2322
2331
|
$ZodType.init(inst, def);
|
|
2323
|
-
|
|
2332
|
+
inst._zod.optin = "optional";
|
|
2324
2333
|
defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
2325
2334
|
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
2326
2335
|
inst._zod.parse = (payload, ctx) => {
|
|
@@ -2335,6 +2344,7 @@ const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
|
|
|
2335
2344
|
input: payload.value
|
|
2336
2345
|
});
|
|
2337
2346
|
payload.issues = [];
|
|
2347
|
+
payload.fallback = true;
|
|
2338
2348
|
}
|
|
2339
2349
|
return payload;
|
|
2340
2350
|
});
|
|
@@ -2346,6 +2356,7 @@ const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
|
|
|
2346
2356
|
input: payload.value
|
|
2347
2357
|
});
|
|
2348
2358
|
payload.issues = [];
|
|
2359
|
+
payload.fallback = true;
|
|
2349
2360
|
}
|
|
2350
2361
|
return payload;
|
|
2351
2362
|
};
|
|
@@ -2374,7 +2385,8 @@ function handlePipeResult(left, next, ctx) {
|
|
|
2374
2385
|
}
|
|
2375
2386
|
return next._zod.run({
|
|
2376
2387
|
value: left.value,
|
|
2377
|
-
issues: left.issues
|
|
2388
|
+
issues: left.issues,
|
|
2389
|
+
fallback: left.fallback
|
|
2378
2390
|
}, ctx);
|
|
2379
2391
|
}
|
|
2380
2392
|
const $ZodReadonly = /* @__PURE__ */ $constructor("$ZodReadonly", (inst, def) => {
|
|
@@ -2421,7 +2433,7 @@ function handleRefineResult(result, payload, input, inst) {
|
|
|
2421
2433
|
}
|
|
2422
2434
|
}
|
|
2423
2435
|
//#endregion
|
|
2424
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
2436
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/registries.js
|
|
2425
2437
|
var _a;
|
|
2426
2438
|
var $ZodRegistry = class {
|
|
2427
2439
|
constructor() {
|
|
@@ -2468,7 +2480,7 @@ function registry() {
|
|
|
2468
2480
|
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
2469
2481
|
const globalRegistry = globalThis.__zod_globalRegistry;
|
|
2470
2482
|
//#endregion
|
|
2471
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
2483
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/api.js
|
|
2472
2484
|
/* @__NO_SIDE_EFFECTS__ */
|
|
2473
2485
|
function _string(Class, params) {
|
|
2474
2486
|
return new Class({
|
|
@@ -2973,7 +2985,7 @@ function _check(fn, params) {
|
|
|
2973
2985
|
return ch;
|
|
2974
2986
|
}
|
|
2975
2987
|
//#endregion
|
|
2976
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
2988
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/to-json-schema.js
|
|
2977
2989
|
function initializeContext(params) {
|
|
2978
2990
|
let target = params?.target ?? "draft-2020-12";
|
|
2979
2991
|
if (target === "draft-4") target = "draft-04";
|
|
@@ -3221,7 +3233,10 @@ function isTransforming(_schema, _ctx) {
|
|
|
3221
3233
|
if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault") return isTransforming(def.innerType, ctx);
|
|
3222
3234
|
if (def.type === "intersection") return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
|
|
3223
3235
|
if (def.type === "record" || def.type === "map") return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
|
3224
|
-
if (def.type === "pipe")
|
|
3236
|
+
if (def.type === "pipe") {
|
|
3237
|
+
if (_schema._zod.traits.has("$ZodCodec")) return true;
|
|
3238
|
+
return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
|
|
3239
|
+
}
|
|
3225
3240
|
if (def.type === "object") {
|
|
3226
3241
|
for (const key in def.shape) if (isTransforming(def.shape[key], ctx)) return true;
|
|
3227
3242
|
return false;
|
|
@@ -3263,7 +3278,7 @@ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params)
|
|
|
3263
3278
|
return finalize(ctx, schema);
|
|
3264
3279
|
};
|
|
3265
3280
|
//#endregion
|
|
3266
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
3281
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/json-schema-processors.js
|
|
3267
3282
|
const formatMap = {
|
|
3268
3283
|
guid: "uuid",
|
|
3269
3284
|
url: "uri",
|
|
@@ -3318,7 +3333,6 @@ const booleanProcessor = (_schema, _ctx, json, _params) => {
|
|
|
3318
3333
|
const neverProcessor = (_schema, _ctx, json, _params) => {
|
|
3319
3334
|
json.not = {};
|
|
3320
3335
|
};
|
|
3321
|
-
const unknownProcessor = (_schema, _ctx, _json, _params) => {};
|
|
3322
3336
|
const enumProcessor = (schema, _ctx, json, _params) => {
|
|
3323
3337
|
const def = schema._zod.def;
|
|
3324
3338
|
const values = getEnumValues(def.entries);
|
|
@@ -3452,7 +3466,8 @@ const catchProcessor = (schema, ctx, json, params) => {
|
|
|
3452
3466
|
};
|
|
3453
3467
|
const pipeProcessor = (schema, ctx, _json, params) => {
|
|
3454
3468
|
const def = schema._zod.def;
|
|
3455
|
-
const
|
|
3469
|
+
const inIsTransform = def.in._zod.traits.has("$ZodTransform");
|
|
3470
|
+
const innerType = ctx.io === "input" ? inIsTransform ? def.out : def.in : def.out;
|
|
3456
3471
|
process$1(innerType, ctx, params);
|
|
3457
3472
|
const seen = ctx.seen.get(schema);
|
|
3458
3473
|
seen.ref = innerType;
|
|
@@ -3471,7 +3486,7 @@ const optionalProcessor = (schema, ctx, _json, params) => {
|
|
|
3471
3486
|
seen.ref = def.innerType;
|
|
3472
3487
|
};
|
|
3473
3488
|
//#endregion
|
|
3474
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
3489
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/iso.js
|
|
3475
3490
|
const ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def) => {
|
|
3476
3491
|
$ZodISODateTime.init(inst, def);
|
|
3477
3492
|
ZodStringFormat.init(inst, def);
|
|
@@ -3501,7 +3516,7 @@ function duration(params) {
|
|
|
3501
3516
|
return /* @__PURE__ */ _isoDuration(ZodISODuration, params);
|
|
3502
3517
|
}
|
|
3503
3518
|
//#endregion
|
|
3504
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
3519
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/errors.js
|
|
3505
3520
|
const initializer = (inst, issues) => {
|
|
3506
3521
|
$ZodError.init(inst, issues);
|
|
3507
3522
|
inst.name = "ZodError";
|
|
@@ -3523,7 +3538,7 @@ const initializer = (inst, issues) => {
|
|
|
3523
3538
|
};
|
|
3524
3539
|
const ZodRealError = /* @__PURE__ */ $constructor("ZodError", initializer, { Parent: Error });
|
|
3525
3540
|
//#endregion
|
|
3526
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
3541
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/parse.js
|
|
3527
3542
|
const parse = /* @__PURE__ */ _parse(ZodRealError);
|
|
3528
3543
|
const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
3529
3544
|
const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
@@ -3537,7 +3552,7 @@ const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
|
|
|
3537
3552
|
const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
|
|
3538
3553
|
const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
|
|
3539
3554
|
//#endregion
|
|
3540
|
-
//#region node_modules/.pnpm/zod@4.4.
|
|
3555
|
+
//#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/schemas.js
|
|
3541
3556
|
const _installedGroups = /* @__PURE__ */ new WeakMap();
|
|
3542
3557
|
function _installLazyMethods(inst, group, methods) {
|
|
3543
3558
|
const proto = Object.getPrototypeOf(inst);
|
|
@@ -3954,7 +3969,7 @@ function boolean(params) {
|
|
|
3954
3969
|
const ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
|
|
3955
3970
|
$ZodUnknown.init(inst, def);
|
|
3956
3971
|
ZodType.init(inst, def);
|
|
3957
|
-
inst._zod.processJSONSchema = (ctx, json, params) =>
|
|
3972
|
+
inst._zod.processJSONSchema = (ctx, json, params) => void 0;
|
|
3958
3973
|
});
|
|
3959
3974
|
function unknown() {
|
|
3960
3975
|
return /* @__PURE__ */ _unknown(ZodUnknown);
|
|
@@ -4146,9 +4161,11 @@ const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) =>
|
|
|
4146
4161
|
const output = def.transform(payload.value, payload);
|
|
4147
4162
|
if (output instanceof Promise) return output.then((output) => {
|
|
4148
4163
|
payload.value = output;
|
|
4164
|
+
payload.fallback = true;
|
|
4149
4165
|
return payload;
|
|
4150
4166
|
});
|
|
4151
4167
|
payload.value = output;
|
|
4168
|
+
payload.fallback = true;
|
|
4152
4169
|
return payload;
|
|
4153
4170
|
};
|
|
4154
4171
|
});
|
|
@@ -4442,6 +4459,7 @@ const ensureBrvGitignore = async (cwd) => {
|
|
|
4442
4459
|
//#endregion
|
|
4443
4460
|
//#region src/lru-cache.ts
|
|
4444
4461
|
var LruCache = class {
|
|
4462
|
+
maxSize;
|
|
4445
4463
|
#entries = /* @__PURE__ */ new Map();
|
|
4446
4464
|
constructor(maxSize) {
|
|
4447
4465
|
this.maxSize = maxSize;
|
|
@@ -4758,9 +4776,6 @@ function Integer(options) {
|
|
|
4758
4776
|
return Create({ "~kind": "Integer" }, { type: "integer" }, options);
|
|
4759
4777
|
}
|
|
4760
4778
|
//#endregion
|
|
4761
|
-
//#region node_modules/.pnpm/typebox@1.1.36/node_modules/typebox/build/type/types/number.mjs
|
|
4762
|
-
const NumberPattern = "-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?";
|
|
4763
|
-
//#endregion
|
|
4764
4779
|
//#region node_modules/.pnpm/typebox@1.1.36/node_modules/typebox/build/type/types/string.mjs
|
|
4765
4780
|
/** Creates a String type. */
|
|
4766
4781
|
function String$1(options) {
|
|
@@ -4769,7 +4784,6 @@ function String$1(options) {
|
|
|
4769
4784
|
//#endregion
|
|
4770
4785
|
//#region node_modules/.pnpm/typebox@1.1.36/node_modules/typebox/build/type/types/record.mjs
|
|
4771
4786
|
const IntegerKey = `^${IntegerPattern}$`;
|
|
4772
|
-
`${NumberPattern}`;
|
|
4773
4787
|
//#endregion
|
|
4774
4788
|
//#region node_modules/.pnpm/typebox@1.1.36/node_modules/typebox/build/type/script/token/internal/char.mjs
|
|
4775
4789
|
function Range(start, end) {
|
|
@@ -4969,8 +4983,10 @@ function byterover(pi) {
|
|
|
4969
4983
|
if (eventHandlersRegistered) return;
|
|
4970
4984
|
eventHandlersRegistered = true;
|
|
4971
4985
|
pi.on("before_agent_start", async (event, ctx) => beforeAgentStart(event, ctx));
|
|
4986
|
+
pi.on("context", async (event, ctx) => injectRecallContext(event, ctx));
|
|
4972
4987
|
pi.on("agent_end", async (_event, ctx) => {
|
|
4973
|
-
|
|
4988
|
+
runtime?.pendingRecalls.delete(sessionKey(ctx));
|
|
4989
|
+
curateTurn(ctx);
|
|
4974
4990
|
});
|
|
4975
4991
|
pi.on("session_before_compact", async (_event, ctx) => {
|
|
4976
4992
|
await curateTurn(ctx);
|
|
@@ -4978,10 +4994,10 @@ function byterover(pi) {
|
|
|
4978
4994
|
};
|
|
4979
4995
|
const createBridgeFactory = (config, defaultCwd) => {
|
|
4980
4996
|
const brvLogger = {
|
|
4981
|
-
debug: (message) =>
|
|
4982
|
-
info: (message) =>
|
|
4983
|
-
warn: (message) =>
|
|
4984
|
-
error: (message) =>
|
|
4997
|
+
debug: (message) => void 0,
|
|
4998
|
+
info: (message) => void 0,
|
|
4999
|
+
warn: (message) => void 0,
|
|
5000
|
+
error: (message) => void 0
|
|
4985
5001
|
};
|
|
4986
5002
|
return (override) => new BrvBridge({
|
|
4987
5003
|
brvPath: config.brvPath,
|
|
@@ -4995,27 +5011,47 @@ function byterover(pi) {
|
|
|
4995
5011
|
const beforeAgentStart = async (event, ctx) => {
|
|
4996
5012
|
const state = runtime;
|
|
4997
5013
|
if (state === void 0) return { systemPrompt: event.systemPrompt };
|
|
4998
|
-
const { bridge, config } = state;
|
|
5014
|
+
const { bridge, config, pendingRecalls } = state;
|
|
4999
5015
|
let systemPrompt = event.systemPrompt;
|
|
5000
5016
|
if (config.manualTools) systemPrompt = appendSystemPromptBlock(systemPrompt, buildManualToolGuidance(config));
|
|
5001
5017
|
if (!config.autoRecall) return { systemPrompt };
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
logBrv("warn", "ByteRover bridge not ready, skipping recall");
|
|
5005
|
-
return { systemPrompt };
|
|
5006
|
-
}
|
|
5007
|
-
const formattedMessages = formatMessages(selectMessagesForRecall(messagesWithCurrentPrompt(extractPiSessionMessages(ctx.sessionManager.getBranch()), event.prompt), config));
|
|
5018
|
+
const messagesForRecall = selectMessagesForRecall(messagesWithCurrentPrompt(extractPiSessionMessages(ctx.sessionManager.getBranch()), event.prompt), config);
|
|
5019
|
+
const formattedMessages = formatMessages(messagesForRecall);
|
|
5008
5020
|
if (!formattedMessages) return { systemPrompt };
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5021
|
+
const query = `${config.recallPrompt.trim()}\n\nRecent conversation:\n\n---\n${formattedMessages}`;
|
|
5022
|
+
pendingRecalls.set(sessionKey(ctx), {
|
|
5023
|
+
key: turnKey(messagesForRecall),
|
|
5024
|
+
promise: (async () => {
|
|
5025
|
+
try {
|
|
5026
|
+
if (!await bridge.ready()) {
|
|
5027
|
+
notifyBrv(ctx, "warning", "ByteRover bridge not ready, skipping recall", config);
|
|
5028
|
+
return;
|
|
5029
|
+
}
|
|
5030
|
+
return stripEchoedRecallQuery((await bridge.recall(query, { cwd: ctx.cwd })).content, query) || void 0;
|
|
5031
|
+
} catch (error) {
|
|
5032
|
+
notifyBrv(ctx, "error", "Failed to recall context from ByteRover", config);
|
|
5033
|
+
`${errorMessage(error)}`;
|
|
5034
|
+
return;
|
|
5035
|
+
}
|
|
5036
|
+
})()
|
|
5037
|
+
});
|
|
5038
|
+
return { systemPrompt };
|
|
5039
|
+
};
|
|
5040
|
+
const injectRecallContext = async (event, ctx) => {
|
|
5041
|
+
const state = runtime;
|
|
5042
|
+
if (state === void 0) return {};
|
|
5043
|
+
const pendingRecall = state.pendingRecalls.get(sessionKey(ctx));
|
|
5044
|
+
if (pendingRecall === void 0) return {};
|
|
5045
|
+
const content = await pendingRecall.promise;
|
|
5046
|
+
if (!content) return {};
|
|
5047
|
+
return { messages: [...event.messages, {
|
|
5048
|
+
role: "user",
|
|
5049
|
+
content: [{
|
|
5050
|
+
type: "text",
|
|
5051
|
+
text: `<${state.config.contextTagName}>\n${content}\n</${state.config.contextTagName}>`
|
|
5052
|
+
}],
|
|
5053
|
+
timestamp: Date.now()
|
|
5054
|
+
}] };
|
|
5019
5055
|
};
|
|
5020
5056
|
const curateTurn = async (ctx) => {
|
|
5021
5057
|
const state = runtime;
|
|
@@ -5027,13 +5063,11 @@ function byterover(pi) {
|
|
|
5027
5063
|
const key = turnKey(messagesInTurn);
|
|
5028
5064
|
const dedupeKey = sessionKey(ctx);
|
|
5029
5065
|
if (curatedTurns.get(dedupeKey) === key) {
|
|
5030
|
-
|
|
5066
|
+
`${dedupeKey}`;
|
|
5031
5067
|
return;
|
|
5032
5068
|
}
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
logBrv("debug", `Skipping in-flight ByteRover curation for ${dedupeKey}`);
|
|
5036
|
-
await inFlightCuration.promise;
|
|
5069
|
+
if (inFlightCurations.get(dedupeKey)?.key === key) {
|
|
5070
|
+
`${dedupeKey}`;
|
|
5037
5071
|
return;
|
|
5038
5072
|
}
|
|
5039
5073
|
const formattedMessages = formatMessages(messagesInTurn);
|
|
@@ -5043,14 +5077,14 @@ function byterover(pi) {
|
|
|
5043
5077
|
const result = await bridge.persist(`${config.persistPrompt.trim()}\n\nConversation:\n\n---\n${formattedMessages}`, { cwd: ctx.cwd });
|
|
5044
5078
|
if (result.status === "error") {
|
|
5045
5079
|
notifyBrv(ctx, "error", "Failed to curate conversation turn with ByteRover", config);
|
|
5046
|
-
|
|
5080
|
+
`${result.message}`;
|
|
5047
5081
|
return;
|
|
5048
5082
|
}
|
|
5049
5083
|
const currentInFlightCuration = inFlightCurations.get(dedupeKey);
|
|
5050
5084
|
if (currentInFlightCuration?.key === key && currentInFlightCuration.promise === promise) curatedTurns.set(dedupeKey, key);
|
|
5051
5085
|
} catch (error) {
|
|
5052
5086
|
notifyBrv(ctx, "error", "Failed to curate conversation turn with ByteRover", config);
|
|
5053
|
-
|
|
5087
|
+
`${errorMessage(error)}`;
|
|
5054
5088
|
}
|
|
5055
5089
|
};
|
|
5056
5090
|
const promise = persistCuration();
|
|
@@ -5069,7 +5103,7 @@ function byterover(pi) {
|
|
|
5069
5103
|
if (!configResult.success) {
|
|
5070
5104
|
runtime = void 0;
|
|
5071
5105
|
notifyBrv(ctx, "error", "Invalid ByteRover configuration");
|
|
5072
|
-
|
|
5106
|
+
configResult.error.message;
|
|
5073
5107
|
return;
|
|
5074
5108
|
}
|
|
5075
5109
|
const { config } = configResult;
|
|
@@ -5081,7 +5115,7 @@ function byterover(pi) {
|
|
|
5081
5115
|
await ensureBrvGitignore(ctx.cwd);
|
|
5082
5116
|
} catch (error) {
|
|
5083
5117
|
notifyBrv(ctx, "warning", "Failed to initialize ByteRover storage, some features may not work", config);
|
|
5084
|
-
|
|
5118
|
+
`${errorMessage(error)}`;
|
|
5085
5119
|
}
|
|
5086
5120
|
const createBridge = createBridgeFactory(config, ctx.cwd);
|
|
5087
5121
|
const bridge = createBridge();
|
|
@@ -5089,7 +5123,8 @@ function byterover(pi) {
|
|
|
5089
5123
|
config,
|
|
5090
5124
|
bridge,
|
|
5091
5125
|
curatedTurns: new LruCache(500),
|
|
5092
|
-
inFlightCurations: /* @__PURE__ */ new Map()
|
|
5126
|
+
inFlightCurations: /* @__PURE__ */ new Map(),
|
|
5127
|
+
pendingRecalls: /* @__PURE__ */ new Map()
|
|
5093
5128
|
};
|
|
5094
5129
|
if (config.manualTools) registerManualTools({
|
|
5095
5130
|
pi,
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BrvBridge, SearchResultItem } from "@byterover/brv-bridge";
|
|
2
|
-
import type { ExtensionAPI } from "@
|
|
2
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import type { ConfigSchema } from "./config.js";
|
|
4
4
|
type Config = ReturnType<typeof ConfigSchema.parse>;
|
|
5
5
|
type BridgeOverride = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-byterover",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Pi ByteRover extension",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"byterover",
|
|
@@ -37,23 +37,24 @@
|
|
|
37
37
|
"provenance": true
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@byterover/brv-bridge": "^1.
|
|
41
|
-
"zod": "^4.3
|
|
40
|
+
"@byterover/brv-bridge": "^1.2.0",
|
|
41
|
+
"zod": "^4.4.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@changesets/changelog-github": "^0.
|
|
44
|
+
"@changesets/changelog-github": "^0.7.0",
|
|
45
45
|
"@changesets/cli": "^2.31.0",
|
|
46
|
-
"@types/node": "^25.
|
|
46
|
+
"@types/node": "^25.9.1",
|
|
47
|
+
"@typescript/native-preview": "7.0.0-dev.20260519.1",
|
|
47
48
|
"husky": "^9.1.7",
|
|
48
|
-
"oxfmt": "^0.
|
|
49
|
-
"oxlint": "^1.
|
|
50
|
-
"rolldown": "1.0.
|
|
49
|
+
"oxfmt": "^0.51.0",
|
|
50
|
+
"oxlint": "^1.66.0",
|
|
51
|
+
"rolldown": "1.0.2",
|
|
51
52
|
"typescript": "^6.0.3",
|
|
52
|
-
"vitest": "^4.1.
|
|
53
|
+
"vitest": "^4.1.7"
|
|
53
54
|
},
|
|
54
55
|
"peerDependencies": {
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
56
|
+
"@earendil-works/pi-ai": "*",
|
|
57
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
57
58
|
"typebox": "*"
|
|
58
59
|
},
|
|
59
60
|
"pi": {
|
|
@@ -64,7 +65,7 @@
|
|
|
64
65
|
"scripts": {
|
|
65
66
|
"build": "pnpm run clean && pnpm run build:js && pnpm run build:types",
|
|
66
67
|
"build:js": "rolldown -c",
|
|
67
|
-
"build:types": "
|
|
68
|
+
"build:types": "tsgo --project tsconfig.build.json --emitDeclarationOnly",
|
|
68
69
|
"build:watch": "rolldown -c -w",
|
|
69
70
|
"clean": "rm -rf dist",
|
|
70
71
|
"changeset": "changeset",
|
|
@@ -74,7 +75,7 @@
|
|
|
74
75
|
"lint:fix": "oxlint --fix",
|
|
75
76
|
"release": "pnpm run build && changeset publish",
|
|
76
77
|
"test": "vitest run",
|
|
77
|
-
"typecheck": "
|
|
78
|
+
"typecheck": "tsgo --noEmit",
|
|
78
79
|
"version-packages": "changeset version"
|
|
79
80
|
}
|
|
80
81
|
}
|