pi-openai-toolkit 0.14.13 → 0.15.1
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/README.md +250 -241
- package/README.zh.md +250 -241
- package/config.schema.json +352 -0
- package/docs/configuration.md +176 -0
- package/docs/internals.md +139 -128
- package/package.json +135 -127
- package/src/auto-mode/extension.ts +35 -13
- package/src/config/legacy.ts +717 -0
- package/src/config/migration.ts +100 -0
- package/src/config/notifications.ts +28 -0
- package/src/config/policy.ts +122 -0
- package/src/config/v2.ts +1347 -0
- package/src/config-command.ts +73 -0
- package/src/config.ts +318 -739
- package/src/context-management/tools.ts +353 -347
- package/src/context-management/window-manager.ts +696 -693
- package/src/debug.ts +5 -5
- package/src/deferred-tool-carryover.ts +3 -1
- package/src/extension-runtime.ts +1375 -1329
- package/src/image-generation/extension.ts +14 -18
- package/src/image-generation/protocol.ts +10 -4
- package/src/image-generation/service.ts +9 -3
- package/src/request-context-cache.ts +2 -1
- package/src/types.ts +641 -628
- package/src/web-search/alpha-client.ts +876 -875
- package/src/web-search/extension.ts +529 -523
- package/src/web-search/payload.ts +299 -295
- package/src/web-search/prompt.ts +60 -59
- package/src/web-search/types.ts +144 -144
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { CONFIG_PATH, loadToolkitConfig, resolveToolkitConfig, type ResolvedToolkitConfig } from "./config";
|
|
3
|
+
import { previewToolkitMigration } from "./config/migration";
|
|
4
|
+
import { formatConfigIssues } from "./config/notifications";
|
|
5
|
+
import { redactValue } from "./debug";
|
|
6
|
+
|
|
7
|
+
const registered = new WeakSet<object>();
|
|
8
|
+
const MAX_REPORT_CHARS = 24_000;
|
|
9
|
+
|
|
10
|
+
function boundedReport(text: string): string {
|
|
11
|
+
// Even known string fields may accidentally contain credentials. Never show them unredacted.
|
|
12
|
+
const redacted = redactValue(text);
|
|
13
|
+
const safe = typeof redacted === "string" ? redacted : "Configuration report unavailable.";
|
|
14
|
+
return safe.length <= MAX_REPORT_CHARS ? safe : `${safe.slice(0, MAX_REPORT_CHARS)}\n[Report truncated; do not use truncated JSON as a configuration file.]`;
|
|
15
|
+
}
|
|
16
|
+
function readLeaf(value: unknown, fieldPath: string): unknown {
|
|
17
|
+
for (const key of fieldPath.split(".")) {
|
|
18
|
+
if (!value || typeof value !== "object" || !Object.prototype.hasOwnProperty.call(value, key)) return undefined;
|
|
19
|
+
value = Reflect.get(value, key);
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function describeToolkitConfig(resolved: ResolvedToolkitConfig): string {
|
|
25
|
+
const lines = [
|
|
26
|
+
`Toolkit configuration: ${resolved.source ?? CONFIG_PATH}`,
|
|
27
|
+
`Format: ${resolved.format}; model: ${resolved.modelKey ?? "not selected"}`,
|
|
28
|
+
`Invalid selected features: ${resolved.invalidFeatures.join(", ") || "none"}`,
|
|
29
|
+
"Configuration intent only. Tool registration and backend capability are not verified.",
|
|
30
|
+
];
|
|
31
|
+
for (const [field, origin] of Object.entries(resolved.origins)) {
|
|
32
|
+
const value = JSON.stringify(readLeaf(resolved.policy, field));
|
|
33
|
+
lines.push(`${field} = ${value} [${origin.kind}${origin.path ? `: ${origin.path}` : ""}]`);
|
|
34
|
+
}
|
|
35
|
+
if (resolved.issues.length) lines.push("", formatConfigIssues(resolved.issues, 30));
|
|
36
|
+
return boundedReport(lines.join("\n"));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Human-only local inspection. Registration does not load config or call action APIs. */
|
|
40
|
+
export function registerToolkitConfigCommand(pi: ExtensionAPI, loadConfig: typeof loadToolkitConfig = loadToolkitConfig): void {
|
|
41
|
+
if (registered.has(pi) || typeof pi.registerCommand !== "function") return;
|
|
42
|
+
registered.add(pi);
|
|
43
|
+
pi.registerCommand("toolkit-config", {
|
|
44
|
+
description: "Read-only global configuration: /toolkit-config [show|validate|migration-preview]",
|
|
45
|
+
handler: async (args, ctx) => {
|
|
46
|
+
if (!ctx.hasUI) throw new Error("/toolkit-config requires an interactive or RPC UI; it does not write reports to stdout.");
|
|
47
|
+
const action = args.trim() || "show";
|
|
48
|
+
if (!["show", "validate", "migration-preview"].includes(action)) {
|
|
49
|
+
ctx.ui.notify("Usage: /toolkit-config [show|validate|migration-preview]", "warning");
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const loaded = loadConfig();
|
|
53
|
+
const resolved = resolveToolkitConfig(loaded, ctx.model);
|
|
54
|
+
if (action === "show") {
|
|
55
|
+
ctx.ui.notify(describeToolkitConfig(resolved), resolved.invalidFeatures.length ? "warning" : "info");
|
|
56
|
+
} else if (action === "validate") {
|
|
57
|
+
ctx.ui.notify(boundedReport(resolved.issues.length
|
|
58
|
+
? `Toolkit configuration: ${loaded.document?.configPath ?? loaded.source ?? CONFIG_PATH}\n${formatConfigIssues(resolved.issues, 80)}`
|
|
59
|
+
: "Toolkit configuration is valid. Backend support has not been tested."),
|
|
60
|
+
resolved.issues.length ? "warning" : "info");
|
|
61
|
+
} else {
|
|
62
|
+
const preview = previewToolkitMigration(loaded);
|
|
63
|
+
ctx.ui.notify(boundedReport([
|
|
64
|
+
`Migration preview: ${preview.status}. No file was changed.`,
|
|
65
|
+
...preview.reasons,
|
|
66
|
+
...(preview.unmappedPaths.length ? [`Unmapped/dormant paths (unknown names masked): ${preview.unmappedPaths.join(", ")}`] : []),
|
|
67
|
+
"Before any future manual apply, back up the original bytes and verify all installed Toolkit copies support v2.",
|
|
68
|
+
...(preview.candidate ? ["Candidate (review required):", JSON.stringify(preview.candidate, null, 2)] : []),
|
|
69
|
+
].join("\n")), preview.status === "needs-review" ? "warning" : "info");
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|