@diegopetrucci/pi-librarian 0.1.8 → 0.1.10
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/.pi-fleet-tested-version +1 -1
- package/README.md +1 -1
- package/index.ts +54 -9
- package/package.json +5 -1
package/.pi-fleet-tested-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.80.6
|
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ Then reload pi:
|
|
|
39
39
|
- Uses `gh` for GitHub search/API access
|
|
40
40
|
- Uses cached local checkouts only when enabled
|
|
41
41
|
- Toggle cache behavior for future calls with `/librarian-cache on | off | toggle | status`
|
|
42
|
-
- Configure internal subagent defaults with `/librarian-config status | model <provider/model|auto> | thinking <off|minimal|low|medium|high|xhigh|auto> | clear [all|model|thinking]`
|
|
42
|
+
- Configure internal subagent defaults with `/librarian-config status | model <provider/model|auto> | thinking <off|minimal|low|medium|high|xhigh|max|auto> | clear [all|model|thinking]`
|
|
43
43
|
- Cached repos are removed lazily after 7 days without use
|
|
44
44
|
|
|
45
45
|
## Commands
|
package/index.ts
CHANGED
|
@@ -30,11 +30,25 @@ const CACHE_CONFIG_FILE = "librarian.json";
|
|
|
30
30
|
type LibrarianStatus = "running" | "done" | "error" | "aborted";
|
|
31
31
|
|
|
32
32
|
type CacheMode = "disabled" | "enabled";
|
|
33
|
-
type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
33
|
+
type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
34
|
+
type ThinkingLevelMap = Partial<Record<ThinkingLevel, unknown | null>>;
|
|
35
|
+
type PiModel = {
|
|
36
|
+
provider: string;
|
|
37
|
+
id: string;
|
|
38
|
+
reasoning?: boolean;
|
|
39
|
+
thinkingLevelMap?: ThinkingLevelMap;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type CreateAgentSessionOptions = NonNullable<Parameters<typeof createAgentSession>[0]>;
|
|
43
|
+
|
|
44
|
+
function getModelRuntimeOption(ctx: { modelRegistry?: unknown }): Pick<CreateAgentSessionOptions, "modelRuntime"> {
|
|
45
|
+
const modelRuntime = (ctx.modelRegistry as { runtime?: CreateAgentSessionOptions["modelRuntime"] } | undefined)?.runtime;
|
|
46
|
+
return modelRuntime ? { modelRuntime } : {};
|
|
47
|
+
}
|
|
34
48
|
|
|
35
49
|
const DEFAULT_CACHE_MODE: CacheMode = "disabled";
|
|
36
50
|
const DEFAULT_THINKING_LEVEL: ThinkingLevel = "low";
|
|
37
|
-
const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh"] as const;
|
|
51
|
+
const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"] as const;
|
|
38
52
|
|
|
39
53
|
const PREFERRED_FAST_MODEL_PATTERNS = [
|
|
40
54
|
/\bgpt[-_. ]?5\.5(?:[-_. ].*)?\b(?:mini|nano|fast|lite)\b/,
|
|
@@ -316,6 +330,29 @@ function parseThinkingLevel(value: unknown): ThinkingLevel | undefined {
|
|
|
316
330
|
return (THINKING_LEVELS as readonly string[]).includes(normalized) ? (normalized as ThinkingLevel) : undefined;
|
|
317
331
|
}
|
|
318
332
|
|
|
333
|
+
function isThinkingLevelSupported(model: PiModel, level: ThinkingLevel): boolean {
|
|
334
|
+
if (!model.reasoning) return level === "off";
|
|
335
|
+
const map = model.thinkingLevelMap;
|
|
336
|
+
if (level === "xhigh" || level === "max") {
|
|
337
|
+
return !!map && Object.prototype.hasOwnProperty.call(map, level) && map[level] != null;
|
|
338
|
+
}
|
|
339
|
+
return map?.[level] !== null;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function resolveThinkingLevel(model: PiModel, requested: ThinkingLevel): ThinkingLevel {
|
|
343
|
+
if (isThinkingLevelSupported(model, requested)) return requested;
|
|
344
|
+
const requestedIndex = THINKING_LEVELS.indexOf(requested);
|
|
345
|
+
for (let index = requestedIndex + 1; index < THINKING_LEVELS.length; index += 1) {
|
|
346
|
+
const level = THINKING_LEVELS[index];
|
|
347
|
+
if (isThinkingLevelSupported(model, level)) return level;
|
|
348
|
+
}
|
|
349
|
+
for (let index = requestedIndex - 1; index >= 0; index -= 1) {
|
|
350
|
+
const level = THINKING_LEVELS[index];
|
|
351
|
+
if (isThinkingLevelSupported(model, level)) return level;
|
|
352
|
+
}
|
|
353
|
+
return "off";
|
|
354
|
+
}
|
|
355
|
+
|
|
319
356
|
function normalizeModelPreference(value: unknown): string | undefined {
|
|
320
357
|
if (typeof value !== "string") return undefined;
|
|
321
358
|
const trimmed = value.trim();
|
|
@@ -327,7 +364,7 @@ function normalizeModelPreference(value: unknown): string | undefined {
|
|
|
327
364
|
function parseModelPreference(value: unknown): { model?: string; thinkingLevel?: ThinkingLevel } {
|
|
328
365
|
const model = normalizeModelPreference(value);
|
|
329
366
|
if (!model) return {};
|
|
330
|
-
const match = model.match(/^(.*):(off|minimal|low|medium|high|xhigh)$/i);
|
|
367
|
+
const match = model.match(/^(.*):(off|minimal|low|medium|high|xhigh|max)$/i);
|
|
331
368
|
if (!match?.[1]) return { model };
|
|
332
369
|
const baseModel = match[1].trim();
|
|
333
370
|
if (!baseModel || baseModel.toLowerCase() === "auto" || baseModel.toLowerCase() === "current") {
|
|
@@ -529,7 +566,7 @@ async function buildLibrarianCandidates(
|
|
|
529
566
|
modelRef: modelRef(configuredMatched),
|
|
530
567
|
provider: configuredMatched.provider,
|
|
531
568
|
modelId: configuredMatched.id,
|
|
532
|
-
thinkingLevel,
|
|
569
|
+
thinkingLevel: resolveThinkingLevel(configuredMatched, thinkingLevel),
|
|
533
570
|
autoSelected: false,
|
|
534
571
|
selectionReason: "Using the configured librarian model.",
|
|
535
572
|
});
|
|
@@ -552,7 +589,7 @@ async function buildLibrarianCandidates(
|
|
|
552
589
|
modelRef: modelRef(model),
|
|
553
590
|
provider: model.provider,
|
|
554
591
|
modelId: model.id,
|
|
555
|
-
thinkingLevel,
|
|
592
|
+
thinkingLevel: resolveThinkingLevel(model, thinkingLevel),
|
|
556
593
|
autoSelected: true,
|
|
557
594
|
selectionReason: index === 0 ? topReason : `Auto-selected ${modelRef(model)} as a lower-ranked fallback.`,
|
|
558
595
|
});
|
|
@@ -564,7 +601,7 @@ async function buildLibrarianCandidates(
|
|
|
564
601
|
modelRef: modelRef(ctx.model),
|
|
565
602
|
provider: ctx.model.provider,
|
|
566
603
|
modelId: ctx.model.id,
|
|
567
|
-
thinkingLevel,
|
|
604
|
+
thinkingLevel: resolveThinkingLevel(ctx.model, thinkingLevel),
|
|
568
605
|
autoSelected: true,
|
|
569
606
|
selectionReason: `Used the current session model ${modelRef(ctx.model)} as a final fallback.`,
|
|
570
607
|
});
|
|
@@ -777,6 +814,14 @@ function isAbortLikeError(error: unknown): boolean {
|
|
|
777
814
|
return /aborted|cancelled|canceled/i.test(message);
|
|
778
815
|
}
|
|
779
816
|
|
|
817
|
+
export const __test__ = {
|
|
818
|
+
buildLibrarianCandidates,
|
|
819
|
+
findAvailableModel,
|
|
820
|
+
isModelAvailabilityError,
|
|
821
|
+
parseModelPreference,
|
|
822
|
+
resolveThinkingLevel,
|
|
823
|
+
};
|
|
824
|
+
|
|
780
825
|
export default function librarianExtension(pi: ExtensionAPI) {
|
|
781
826
|
let cachePreference: CacheMode = DEFAULT_CACHE_MODE;
|
|
782
827
|
let modelPreference: string | undefined;
|
|
@@ -890,7 +935,7 @@ export default function librarianExtension(pi: ExtensionAPI) {
|
|
|
890
935
|
return;
|
|
891
936
|
}
|
|
892
937
|
|
|
893
|
-
notifyCommand(ctx, "Usage: /librarian-config status | model <provider/model|auto> | thinking <off|minimal|low|medium|high|xhigh|auto> | clear [all|model|thinking]", "warning");
|
|
938
|
+
notifyCommand(ctx, "Usage: /librarian-config status | model <provider/model|auto> | thinking <off|minimal|low|medium|high|xhigh|max|auto> | clear [all|model|thinking]", "warning");
|
|
894
939
|
},
|
|
895
940
|
});
|
|
896
941
|
|
|
@@ -1107,11 +1152,11 @@ export default function librarianExtension(pi: ExtensionAPI) {
|
|
|
1107
1152
|
|
|
1108
1153
|
const created = await createAgentSession({
|
|
1109
1154
|
cwd: workspace,
|
|
1110
|
-
|
|
1155
|
+
...getModelRuntimeOption(ctx),
|
|
1111
1156
|
resourceLoader,
|
|
1112
1157
|
sessionManager: SessionManager.inMemory(workspace),
|
|
1113
1158
|
model: candidate.model,
|
|
1114
|
-
thinkingLevel,
|
|
1159
|
+
thinkingLevel: candidate.details.thinkingLevel,
|
|
1115
1160
|
tools: ["read", "bash"],
|
|
1116
1161
|
});
|
|
1117
1162
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diegopetrucci/pi-librarian",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "A pi GitHub research scout with a toggleable local repo checkout cache under the user's OS cache directory.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -33,5 +33,9 @@
|
|
|
33
33
|
"@earendil-works/pi-coding-agent": "*",
|
|
34
34
|
"@earendil-works/pi-tui": "*",
|
|
35
35
|
"typebox": "*"
|
|
36
|
+
},
|
|
37
|
+
"type": "module",
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=22.19.0"
|
|
36
40
|
}
|
|
37
41
|
}
|