pi-distill 1.7.2 → 1.8.0
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/package.json +9 -9
- package/src/index.ts +22 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-distill",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Pi tool-output distillation with file-first configuration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.ts",
|
|
@@ -56,18 +56,18 @@
|
|
|
56
56
|
"coding-agent"
|
|
57
57
|
],
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@earendil-works/pi-ai": ">=0.80.0
|
|
60
|
-
"@earendil-works/pi-coding-agent": ">=0.80.0
|
|
61
|
-
"@earendil-works/pi-tui": ">=0.80.0
|
|
59
|
+
"@earendil-works/pi-ai": ">=0.80.0",
|
|
60
|
+
"@earendil-works/pi-coding-agent": ">=0.80.0",
|
|
61
|
+
"@earendil-works/pi-tui": ">=0.80.0"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"pi-extensions-i18n": "^0.
|
|
65
|
-
"pi-extensions-tool-display": "^1.
|
|
64
|
+
"pi-extensions-i18n": "^0.5.0",
|
|
65
|
+
"pi-extensions-tool-display": "^1.2.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@earendil-works/pi-ai": "0.
|
|
69
|
-
"@earendil-works/pi-coding-agent": "0.
|
|
70
|
-
"@earendil-works/pi-tui": "0.
|
|
68
|
+
"@earendil-works/pi-ai": "0.85.1",
|
|
69
|
+
"@earendil-works/pi-coding-agent": "0.85.1",
|
|
70
|
+
"@earendil-works/pi-tui": "0.85.1",
|
|
71
71
|
"@types/node": "24.12.4",
|
|
72
72
|
"tsx": "4.23.1",
|
|
73
73
|
"typescript": "5.9.3"
|
package/src/index.ts
CHANGED
|
@@ -43,7 +43,7 @@ import { getTextContent, hasNonTextContent, limitReturnedToolResult } from "./ou
|
|
|
43
43
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
44
44
|
import { tmpdir } from "node:os";
|
|
45
45
|
import { dirname, join } from "node:path";
|
|
46
|
-
import { createTranslator, loadCatalog } from "pi-extensions-i18n";
|
|
46
|
+
import { createTranslator, loadCatalog, notifyWithSource, type NoticeColor, type NoticeSource } from "pi-extensions-i18n";
|
|
47
47
|
import {
|
|
48
48
|
buildSummaryPrompt,
|
|
49
49
|
buildSummarySystemPrompt,
|
|
@@ -110,6 +110,13 @@ type ToolResultEventPatch = {
|
|
|
110
110
|
export const OUTPUT_REQUEST_DESCRIPTION = i18n.t("outputRequestDescription");
|
|
111
111
|
const OUTPUT_REQUEST_SYSTEM_GUIDELINE = i18n.t("outputRequestSystemGuideline");
|
|
112
112
|
|
|
113
|
+
/** 本扩展的提示标签;短且唯一,便于在会话里定位来源。 */
|
|
114
|
+
const NOTICE_TAG = "distill";
|
|
115
|
+
/** 提示标签颜色;与其它扩展错开,避免看起来像同一条消息。 */
|
|
116
|
+
const NOTICE_COLOR: NoticeColor = "muted";
|
|
117
|
+
/** 本扩展的提示来源。 */
|
|
118
|
+
const NOTICE_SOURCE: NoticeSource = { tag: NOTICE_TAG, color: NOTICE_COLOR };
|
|
119
|
+
|
|
113
120
|
type SummaryDecisionMode = "RAW" | "SUMMARY";
|
|
114
121
|
type SummaryReasonCode =
|
|
115
122
|
| "VERBATIM_REQUEST"
|
|
@@ -921,12 +928,12 @@ async function summarizeOutputWithRetries(
|
|
|
921
928
|
}
|
|
922
929
|
if (timedOut) timeoutRetries += 1;
|
|
923
930
|
else errorRetries += 1;
|
|
924
|
-
context.ctx
|
|
931
|
+
notifyWithSource({ ctx: context.ctx, source: NOTICE_SOURCE, level: "warning", message: i18n.t("retryingSummary", {
|
|
925
932
|
kind: i18n.t(timedOut ? "retryKindTimeout" : "retryKindError"),
|
|
926
933
|
retry: retriesUsed + 1,
|
|
927
934
|
limit: retryLimit,
|
|
928
935
|
error: error instanceof Error ? error.message : String(error),
|
|
929
|
-
})
|
|
936
|
+
}) });
|
|
930
937
|
} finally {
|
|
931
938
|
clearTimeout(timeout);
|
|
932
939
|
context.signal?.removeEventListener("abort", abortFromParent);
|
|
@@ -955,9 +962,9 @@ export async function processToolResult(
|
|
|
955
962
|
const maxReturnedChars = config?.maxOutputChars ?? 10_000;
|
|
956
963
|
const finish = (candidate: ToolResult) => limitReturnedToolResult(candidate, maxReturnedChars);
|
|
957
964
|
if (loaded.warnings.length > 0) {
|
|
958
|
-
context.ctx
|
|
965
|
+
notifyWithSource({ ctx: context.ctx, source: NOTICE_SOURCE, level: "warning", message: i18n.t("configWarnings", {
|
|
959
966
|
warnings: loaded.warnings.join(" "),
|
|
960
|
-
})
|
|
967
|
+
}) });
|
|
961
968
|
}
|
|
962
969
|
|
|
963
970
|
if (config && loaded.enabled && !isDistillToolEnabled(config, context.toolName)) return result;
|
|
@@ -1325,7 +1332,7 @@ async function editDistillNumber(
|
|
|
1325
1332
|
const value = await ctx.ui.input(title, String(current));
|
|
1326
1333
|
if (value === undefined) return undefined;
|
|
1327
1334
|
if (!/^\d+$/.test(value.trim()) || Number(value) <= 0) {
|
|
1328
|
-
ctx
|
|
1335
|
+
notifyWithSource({ ctx, source: NOTICE_SOURCE, level: "error", message: i18n.t("positiveInteger") });
|
|
1329
1336
|
return undefined;
|
|
1330
1337
|
}
|
|
1331
1338
|
return Number(value);
|
|
@@ -1341,7 +1348,7 @@ async function editDistillNonNegativeInteger(
|
|
|
1341
1348
|
const normalized = value.trim();
|
|
1342
1349
|
const parsed = Number(normalized);
|
|
1343
1350
|
if (!/^\d+$/.test(normalized) || !Number.isSafeInteger(parsed)) {
|
|
1344
|
-
ctx
|
|
1351
|
+
notifyWithSource({ ctx, source: NOTICE_SOURCE, level: "error", message: i18n.t("nonNegativeInteger") });
|
|
1345
1352
|
return undefined;
|
|
1346
1353
|
}
|
|
1347
1354
|
return parsed;
|
|
@@ -1358,7 +1365,7 @@ async function editDistillModel(
|
|
|
1358
1365
|
if (value === undefined) return undefined;
|
|
1359
1366
|
const normalized = value.trim();
|
|
1360
1367
|
if (normalized && !/^[^/\s]+\/[^/\s]+$/.test(normalized)) {
|
|
1361
|
-
ctx
|
|
1368
|
+
notifyWithSource({ ctx, source: NOTICE_SOURCE, level: "error", message: i18n.t("modelInvalid") });
|
|
1362
1369
|
return undefined;
|
|
1363
1370
|
}
|
|
1364
1371
|
return normalized;
|
|
@@ -1374,7 +1381,7 @@ async function saveDistillConfigFile(
|
|
|
1374
1381
|
await writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
1375
1382
|
const saved = loadDistillConfig();
|
|
1376
1383
|
if (saved.warnings.length > 0) {
|
|
1377
|
-
ctx
|
|
1384
|
+
notifyWithSource({ ctx, source: NOTICE_SOURCE, level: "warning", message: i18n.t("savedWarnings", { warnings: saved.warnings.join(" ") }) });
|
|
1378
1385
|
}
|
|
1379
1386
|
onSaved?.();
|
|
1380
1387
|
}
|
|
@@ -1396,7 +1403,7 @@ async function runDistillToolConfigUi(
|
|
|
1396
1403
|
): Promise<void> {
|
|
1397
1404
|
const toolNames = getConfigurableToolNames(pi);
|
|
1398
1405
|
if (toolNames.length === 0) {
|
|
1399
|
-
ctx
|
|
1406
|
+
notifyWithSource({ ctx, source: NOTICE_SOURCE, level: "warning", message: i18n.t("noConfigurableTools") });
|
|
1400
1407
|
return;
|
|
1401
1408
|
}
|
|
1402
1409
|
|
|
@@ -1423,7 +1430,7 @@ async function runDistillConfigUi(
|
|
|
1423
1430
|
): Promise<void> {
|
|
1424
1431
|
const loaded = loadDistillConfig();
|
|
1425
1432
|
if (loaded.warnings.length > 0) {
|
|
1426
|
-
ctx
|
|
1433
|
+
notifyWithSource({ ctx, source: NOTICE_SOURCE, level: "warning", message: i18n.t("configWarnings", { warnings: loaded.warnings.join(" ") }) });
|
|
1427
1434
|
}
|
|
1428
1435
|
const config = getDistillUiConfig();
|
|
1429
1436
|
|
|
@@ -1532,7 +1539,7 @@ function registerDistillConfigCommand(
|
|
|
1532
1539
|
description: i18n.t("commandDescription"),
|
|
1533
1540
|
handler: async (_args: string, ctx: ExtensionCommandContext) => {
|
|
1534
1541
|
if (!ctx.hasUI) {
|
|
1535
|
-
ctx
|
|
1542
|
+
notifyWithSource({ ctx, source: NOTICE_SOURCE, level: "warning", message: i18n.t("interactiveOnly") });
|
|
1536
1543
|
return;
|
|
1537
1544
|
}
|
|
1538
1545
|
await runDistillConfigUi(ctx, pi, getDistillConfigPath(), () => onSaved(ctx));
|
|
@@ -1551,10 +1558,10 @@ function registerDistillStatsCommand(
|
|
|
1551
1558
|
description: i18n.t("statsCommandDescription"),
|
|
1552
1559
|
handler: async (_args: string, ctx: ExtensionCommandContext) => {
|
|
1553
1560
|
if (!ctx.hasUI) {
|
|
1554
|
-
ctx
|
|
1561
|
+
notifyWithSource({ ctx, source: NOTICE_SOURCE, level: "warning", message: i18n.t("interactiveOnly") });
|
|
1555
1562
|
return;
|
|
1556
1563
|
}
|
|
1557
|
-
ctx
|
|
1564
|
+
notifyWithSource({ ctx, source: NOTICE_SOURCE, level: "info", message: formatDistillSessionStats(getStats()) });
|
|
1558
1565
|
},
|
|
1559
1566
|
});
|
|
1560
1567
|
}
|
|
@@ -1570,7 +1577,7 @@ export default function piDistillExtension(pi: ExtensionAPI) {
|
|
|
1570
1577
|
const reportWarning = (message: string) => {
|
|
1571
1578
|
if (reportedWarnings.has(message)) return;
|
|
1572
1579
|
reportedWarnings.add(message);
|
|
1573
|
-
ctx
|
|
1580
|
+
notifyWithSource({ ctx, source: NOTICE_SOURCE, level: "warning", message });
|
|
1574
1581
|
};
|
|
1575
1582
|
try {
|
|
1576
1583
|
extendDistillToolParameters(pi, loadDistillConfig(), reportWarning);
|