mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 10:45:22 +00:00
feat: 组合包配置集中到 my-pi/ 目录并改为整体重建
- 组合包拥有、可随时重建的配置、日志与缓存统一放在 <agentDir>/my-pi/:permission-system/(policy.jsonc、hard-guards.jsonc、 logs/)、rtk-optimizer/config.json、tool-search/(config.json、 catalog-v1.json)与 system-prompt-cover.md。hashline.json、lsp.json 由外部扩展读取固定路径,是唯一例外。 - 新增 config/bundle-manifest.json 与 scripts/rebuild-bundle-config.mjs: 先校验全部来源与目标,在临时目录构建完整树,再整体删除旧 my-pi/ (符号链接只删链接)并原子替换,不备份。install.sh / update.sh 每次 运行都调用它;扩展自身不再播种或迁移配置。 - update.sh 删除 pi update 失败后的 git clean 恢复逻辑:Pi 1.3.0 会在 下一次 pi update 时依据中断标记自行恢复。同时删除 Tool Search settings.json 快照迁移与封面部署脚本。 - Tool Search 改为读取 my-pi/tool-search/config.json(源为 config/tool-search.json,须与 BUNDLE_TOOL_SEARCH_DEFAULTS 一致), 不再读写 settings.json 的 toolSearch 段,移除 bundleDefaultsVersion。 - 默认权限策略开启 debugLog。 - 旧位置的残留文件不迁移、不清理;AGENTS.md / README 同步新约束。 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent
7e6a8faae1
commit
2682bd7fa7
@@ -18,6 +18,10 @@
|
||||
- Added the authoritative `user-interaction` group for the maintained `ask_user_question` TUI tool.
|
||||
- Added authoritative `chrome-navigation`, `chrome-interaction`, and `chrome-debugging` groups for all 21 tools registered by the pinned `pi-chrome` bridge after explicit session authorization.
|
||||
- Raised the bundle defaults to five active groups and 28 dynamic tools, and pinned the high-frequency Context Mode execution trio alongside CodeGraph exploration and LSP diagnostics.
|
||||
- Moved user configuration from the `settings.json` `toolSearch` section to the bundle-owned `<agent-dir>/my-pi/tool-search/config.json`, deployed by the bundle's rebuild script; a missing or invalid file falls back to `BUNDLE_TOOL_SEARCH_DEFAULTS`. Moved the model-enriched catalog cache to `<agent-dir>/my-pi/tool-search/catalog-v1.json`.
|
||||
|
||||
### Removed
|
||||
- Removed `ensureToolSearchDefaults`, `BUNDLE_TOOL_SEARCH_DEFAULTS_VERSION`, `bundleDefaultsVersion` handling, and all `settings.json` reads/writes; the bundle deploys config via `scripts/rebuild-bundle-config.mjs` instead of extension-side seeding or snapshot migration.
|
||||
- Pinned all six Hermes memory tools in the bundle defaults and raised `bundleDefaultsVersion` to 3. The injected memory policy expects these schemas every turn, and pinning also keeps the request prefix cache-stable instead of paying a `tool_search` round trip plus a cache invalidation. `scripts/migrate-tool-search-settings.mjs` migrates the complete version-2 snapshot with an owner-only backup, atomic replacement, and fail-safe preservation of custom or invalid settings.
|
||||
- Pinned `context_tree_query` alongside the memory tools and raised `bundleDefaultsVersion` to 4. Recovering pruned tool evidence must not depend on a `tool_search` activation, and the added name keeps the request prefix stable. The migration helper now accepts the complete version-3 snapshot in addition to version 2.
|
||||
- Added atomic multi-group activation through `tool_search.groups`, bounded to five exact group ids and rejected without state changes when the complete workflow cannot fit.
|
||||
|
||||
+26
-33
@@ -14,7 +14,7 @@ Generated metadata never replaces executable schemas. Exact names, parameter typ
|
||||
2. Hidden tool definitions are hashed with the grouping constraints.
|
||||
3. Every tool exposed by the standard `my-pi` bundle is matched against the checked-in catalog in `extensions/bundle-groups.ts`. If all tools are recognized, no model call and no user cache are needed.
|
||||
4. User `groupOverrides` take priority over checked-in assignments. Optional or unavailable bundle tools are simply filtered out of their predefined groups.
|
||||
5. Additional user or third-party tools receive deterministic prefix/source groups immediately. A matching private model-enriched cache at `<agent-dir>/tool-search/catalog-v1.json` is reused when present.
|
||||
5. Additional user or third-party tools receive deterministic prefix/source groups immediately. A matching private model-enriched cache at `<agent-dir>/my-pi/tool-search/catalog-v1.json` is reused when present.
|
||||
6. Only when unrecognized tools exist and the call does not name an exact existing group may `tool_search` ask the current authenticated model to enrich the complete catalog. Exact group activation always uses the current deterministic catalog immediately. Validation requires all checked-in bundle tools to remain in their predefined groups before a `0600` cache is accepted.
|
||||
7. Missing authentication, invalid JSON, timeout, cancellation, changed bundle assignments, or cache errors leave the checked-in plus deterministic hybrid catalog usable.
|
||||
|
||||
@@ -74,33 +74,29 @@ The first loads are purely additive and retain Pi's native deferred-loading prop
|
||||
|
||||
## Configuration
|
||||
|
||||
Pi reads this configuration from `<agent-dir>/settings.json` (normally `~/.pi/agent/settings.json`). The bundle adds fields only when missing and never replaces explicit user choices:
|
||||
Pi reads this configuration from `<agent-dir>/my-pi/tool-search/config.json` (normally `~/.pi/agent/my-pi/tool-search/config.json`), deployed by the bundle's `install.sh` / `update.sh` from `config/tool-search.json`. A missing, unreadable, or invalid file falls back to the built-in `BUNDLE_TOOL_SEARCH_DEFAULTS`; the extension never writes the file:
|
||||
|
||||
```json
|
||||
{
|
||||
"toolSearch": {
|
||||
"alwaysEnabled": [
|
||||
"codegraph_explore",
|
||||
"lsp_diagnostics",
|
||||
"ctx_execute",
|
||||
"ctx_execute_file",
|
||||
"ctx_batch_execute",
|
||||
"memory_search",
|
||||
"session_search",
|
||||
"memory_add",
|
||||
"memory_replace",
|
||||
"memory_remove",
|
||||
"skill_manage",
|
||||
"context_tree_query"
|
||||
],
|
||||
],
|
||||
"showToolSearchFooterStatus": false,
|
||||
"maxActiveGroups": 5,
|
||||
"maxToolsPerGroup": 8,
|
||||
"maxDynamicTools": 28,
|
||||
"groupOverrides": {},
|
||||
"bundleDefaultsVersion": 4
|
||||
}
|
||||
"alwaysEnabled": [
|
||||
"codegraph_explore",
|
||||
"lsp_diagnostics",
|
||||
"ctx_execute",
|
||||
"ctx_execute_file",
|
||||
"ctx_batch_execute",
|
||||
"memory_search",
|
||||
"session_search",
|
||||
"memory_add",
|
||||
"memory_replace",
|
||||
"memory_remove",
|
||||
"skill_manage",
|
||||
"context_tree_query"
|
||||
],
|
||||
"showToolSearchFooterStatus": false,
|
||||
"maxActiveGroups": 5,
|
||||
"maxToolsPerGroup": 8,
|
||||
"maxDynamicTools": 28,
|
||||
"groupOverrides": {}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -112,22 +108,19 @@ Pi reads this configuration from `<agent-dir>/settings.json` (normally `~/.pi/ag
|
||||
| `maxToolsPerGroup` | `8` | Maximum size accepted from model-generated groups |
|
||||
| `maxDynamicTools` | `28` | Hard cap across active dynamic group tools |
|
||||
| `groupOverrides` | `{}` | Exact tool lists that override checked-in, generated, or fallback assignments |
|
||||
| `bundleDefaultsVersion` | `4` on a newly created default section | Bundle provenance for controlled default migrations; ignored by runtime routing |
|
||||
|
||||
Example override:
|
||||
|
||||
```json
|
||||
{
|
||||
"toolSearch": {
|
||||
"groupOverrides": {
|
||||
"web-tavily": ["tavily_web_search", "tavily_web_fetch"],
|
||||
"lsp": ["lsp_definition", "lsp_references", "lsp_hover", "lsp_symbols", "lsp_diagnostics"]
|
||||
}
|
||||
"groupOverrides": {
|
||||
"web-tavily": ["tavily_web_search", "tavily_web_fetch"],
|
||||
"lsp": ["lsp_definition", "lsp_references", "lsp_hover", "lsp_symbols", "lsp_diagnostics"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
An explicit override larger than `maxDynamicTools` remains visible but cannot be activated until the limit or override is corrected. Normal extension loading preserves existing values and writes owner-only settings through a unique same-directory temporary file. When the user explicitly runs the bundle's updated `update.sh`, its post-update migration helper changes only the complete former `3`/`20` default snapshot: it creates an owner-only timestamped backup, atomically writes the current defaults, and records `bundleDefaultsVersion: 2`. Customized or invalid settings are preserved, and a content change detected immediately before commit aborts the migration.
|
||||
An explicit override larger than `maxDynamicTools` remains visible but cannot be activated until the limit or override is corrected. Every `install.sh` / `update.sh` run rebuilds the file together with the rest of the `my-pi/` tree, so hand edits are overwritten — change `config/tool-search.json` in the bundle repository for durable customization.
|
||||
|
||||
## Current host integration
|
||||
|
||||
@@ -138,7 +131,7 @@ This version directly targets `@earendil-works/pi-coding-agent`, current `typebo
|
||||
- `extensions/index.ts` — Pi lifecycle, model call, activation, and group LRU
|
||||
- `extensions/catalog.ts` — hashing, strict catalog validation, fallback grouping, cache, and ranking
|
||||
- `extensions/bundle-groups.ts` — checked-in authoritative groups for tools exposed by `my-pi`
|
||||
- `extensions/config.ts` — safe bundle-default deployment and config parsing
|
||||
- `extensions/config.ts` — bundle-deployed config path and config parsing
|
||||
- `test/` — catalog, config, model-generation, and active-set tests
|
||||
- `docs/dynamic-tool-loading.md` — current Pi propagation and replacement behavior
|
||||
- `UPSTREAM.md` — imported snapshot and local divergence
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
import {
|
||||
chmodSync,
|
||||
closeSync,
|
||||
fsyncSync,
|
||||
mkdirSync,
|
||||
openSync,
|
||||
readFileSync,
|
||||
renameSync,
|
||||
rmSync,
|
||||
writeFileSync,
|
||||
} from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
export type ToolSearchDefaultResult = "updated" | "unchanged" | "skipped-invalid";
|
||||
const TOOL_SEARCH_DIR = join("my-pi", "tool-search");
|
||||
|
||||
/**
|
||||
* Path of the bundle-managed Tool Search config inside the agent directory.
|
||||
* `scripts/rebuild-bundle-config.mjs` deploys `config/tool-search.json` here;
|
||||
* this extension never writes or migrates it.
|
||||
*/
|
||||
export function getToolSearchConfigPath(agentDir: string): string {
|
||||
return join(agentDir, TOOL_SEARCH_DIR, "config.json");
|
||||
}
|
||||
|
||||
/** Catalog cache path under the same bundle-owned `my-pi/tool-search/` tree. */
|
||||
export function getToolSearchCatalogPath(agentDir: string): string {
|
||||
return join(agentDir, TOOL_SEARCH_DIR, "catalog-v1.json");
|
||||
}
|
||||
|
||||
export const BUNDLE_TOOL_SEARCH_DEFAULTS = {
|
||||
alwaysEnabled: [
|
||||
@@ -35,8 +39,6 @@ export const BUNDLE_TOOL_SEARCH_DEFAULTS = {
|
||||
groupOverrides: {},
|
||||
} as const;
|
||||
|
||||
export const BUNDLE_TOOL_SEARCH_DEFAULTS_VERSION = 4;
|
||||
|
||||
export interface ToolSearchConfig {
|
||||
alwaysEnabled: string[];
|
||||
showToolSearchFooterStatus: boolean;
|
||||
@@ -80,12 +82,16 @@ export function bundleFallbackConfig(): ToolSearchConfig {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the Tool Search config from `<agentDir>/my-pi/tool-search/config.json`.
|
||||
* A missing, unreadable, or non-object file falls back to the bundle defaults.
|
||||
*/
|
||||
export function readToolSearchConfig(agentDir: string): ToolSearchConfig {
|
||||
const fallback = bundleFallbackConfig();
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(readFileSync(join(agentDir, "settings.json"), "utf8"));
|
||||
if (!isObject(parsed) || !isObject(parsed.toolSearch)) return fallback;
|
||||
const config = parsed.toolSearch;
|
||||
const parsed: unknown = JSON.parse(readFileSync(getToolSearchConfigPath(agentDir), "utf8"));
|
||||
if (!isObject(parsed)) return fallback;
|
||||
const config = parsed;
|
||||
return {
|
||||
alwaysEnabled: Array.isArray(config.alwaysEnabled) ? stringList(config.alwaysEnabled) : fallback.alwaysEnabled,
|
||||
showToolSearchFooterStatus:
|
||||
@@ -101,52 +107,3 @@ export function readToolSearchConfig(agentDir: string): ToolSearchConfig {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
/** Add bundle defaults without replacing explicit user choices. */
|
||||
export function ensureToolSearchDefaults(agentDir: string): ToolSearchDefaultResult {
|
||||
const targetPath = join(agentDir, "settings.json");
|
||||
let settings: Record<string, unknown> = {};
|
||||
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(readFileSync(targetPath, "utf8"));
|
||||
if (!isObject(parsed)) return "skipped-invalid";
|
||||
settings = parsed;
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code !== "ENOENT") return "skipped-invalid";
|
||||
}
|
||||
|
||||
const existing = settings.toolSearch;
|
||||
if (existing !== undefined && !isObject(existing)) return "skipped-invalid";
|
||||
|
||||
const toolSearch = { ...(existing ?? {}) };
|
||||
let changed = false;
|
||||
for (const [key, value] of Object.entries(BUNDLE_TOOL_SEARCH_DEFAULTS)) {
|
||||
if (Object.hasOwn(toolSearch, key)) continue;
|
||||
toolSearch[key] = Array.isArray(value) ? [...value] : isObject(value) ? { ...value } : value;
|
||||
changed = true;
|
||||
}
|
||||
if (existing === undefined) {
|
||||
toolSearch.bundleDefaultsVersion = BUNDLE_TOOL_SEARCH_DEFAULTS_VERSION;
|
||||
changed = true;
|
||||
}
|
||||
if (!changed) return "unchanged";
|
||||
|
||||
settings.toolSearch = toolSearch;
|
||||
mkdirSync(dirname(targetPath), { recursive: true });
|
||||
const temporaryPath = `${targetPath}.my-pi-${process.pid}-${Math.random().toString(16).slice(2)}.tmp`;
|
||||
let descriptor: number | undefined;
|
||||
try {
|
||||
descriptor = openSync(temporaryPath, "wx", 0o600);
|
||||
writeFileSync(descriptor, `${JSON.stringify(settings, null, 2)}\n`, "utf8");
|
||||
fsyncSync(descriptor);
|
||||
closeSync(descriptor);
|
||||
descriptor = undefined;
|
||||
renameSync(temporaryPath, targetPath);
|
||||
chmodSync(targetPath, 0o600);
|
||||
} catch (error) {
|
||||
if (descriptor !== undefined) closeSync(descriptor);
|
||||
rmSync(temporaryPath, { force: true });
|
||||
throw error;
|
||||
}
|
||||
return "updated";
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { unlinkSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { getAgentDir, type ExtensionAPI, type ExtensionContext, type ToolInfo } from "@earendil-works/pi-coding-agent";
|
||||
import { Type } from "typebox";
|
||||
@@ -29,7 +28,7 @@ import {
|
||||
createBundleCatalog,
|
||||
type BundleCatalogResult,
|
||||
} from "./bundle-groups.ts";
|
||||
import { ensureToolSearchDefaults, readToolSearchConfig } from "./config.ts";
|
||||
import { getToolSearchCatalogPath, readToolSearchConfig } from "./config.ts";
|
||||
|
||||
const TOOL_SEARCH_NAME = "tool_search";
|
||||
const POWERSHELL_TOOL_NAME = "powershell";
|
||||
@@ -113,11 +112,7 @@ function groupDescription(catalog: ToolCatalog, source: CatalogSource): string {
|
||||
|
||||
export default function toolSearchExtension(pi: ExtensionAPI): void {
|
||||
const agentDir = getAgentDir();
|
||||
const cachePath = join(agentDir, "tool-search", "catalog-v1.json");
|
||||
const defaultResult = ensureToolSearchDefaults(agentDir);
|
||||
if (defaultResult === "skipped-invalid") {
|
||||
console.warn("my-pi: skipped pi-tool-search defaults because settings.json or toolSearch is invalid");
|
||||
}
|
||||
const cachePath = getToolSearchCatalogPath(agentDir);
|
||||
|
||||
let config = readToolSearchConfig(agentDir);
|
||||
let tools: ToolInfo[] = [];
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
|
||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { dirname, join } from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
import { BUNDLE_TOOL_SEARCH_DEFAULTS, ensureToolSearchDefaults, readToolSearchConfig } from "../extensions/config.ts";
|
||||
import {
|
||||
BUNDLE_TOOL_SEARCH_DEFAULTS,
|
||||
bundleFallbackConfig,
|
||||
getToolSearchCatalogPath,
|
||||
getToolSearchConfigPath,
|
||||
readToolSearchConfig,
|
||||
} from "../extensions/config.ts";
|
||||
|
||||
async function withAgentDir(run: (agentDir: string) => Promise<void>): Promise<void> {
|
||||
const agentDir = await mkdtemp(join(tmpdir(), "my-pi-tool-search-"));
|
||||
@@ -15,71 +21,73 @@ async function withAgentDir(run: (agentDir: string) => Promise<void>): Promise<v
|
||||
}
|
||||
}
|
||||
|
||||
test("writes bundle defaults when toolSearch is absent", async () => {
|
||||
await withAgentDir(async (agentDir) => {
|
||||
assert.equal(ensureToolSearchDefaults(agentDir), "updated");
|
||||
assert.deepEqual(BUNDLE_TOOL_SEARCH_DEFAULTS.alwaysEnabled, [
|
||||
"codegraph_explore",
|
||||
"lsp_diagnostics",
|
||||
"ctx_execute",
|
||||
"ctx_execute_file",
|
||||
"ctx_batch_execute",
|
||||
"memory_search",
|
||||
"session_search",
|
||||
"memory_add",
|
||||
"memory_replace",
|
||||
"memory_remove",
|
||||
"skill_manage",
|
||||
"context_tree_query",
|
||||
]);
|
||||
assert.deepEqual(JSON.parse(await readFile(join(agentDir, "settings.json"), "utf8")), {
|
||||
toolSearch: {
|
||||
alwaysEnabled: [...BUNDLE_TOOL_SEARCH_DEFAULTS.alwaysEnabled],
|
||||
showToolSearchFooterStatus: false,
|
||||
maxActiveGroups: 5,
|
||||
maxToolsPerGroup: 8,
|
||||
maxDynamicTools: 28,
|
||||
groupOverrides: {},
|
||||
bundleDefaultsVersion: 4,
|
||||
},
|
||||
});
|
||||
assert.equal((await stat(join(agentDir, "settings.json"))).mode & 0o777, 0o600);
|
||||
async function writeConfig(agentDir: string, content: string): Promise<void> {
|
||||
const path = getToolSearchConfigPath(agentDir);
|
||||
await mkdir(dirname(path), { recursive: true });
|
||||
await writeFile(path, content, "utf8");
|
||||
}
|
||||
|
||||
test("bundle defaults keep the committed tool list", () => {
|
||||
assert.deepEqual(BUNDLE_TOOL_SEARCH_DEFAULTS.alwaysEnabled, [
|
||||
"codegraph_explore",
|
||||
"lsp_diagnostics",
|
||||
"ctx_execute",
|
||||
"ctx_execute_file",
|
||||
"ctx_batch_execute",
|
||||
"memory_search",
|
||||
"session_search",
|
||||
"memory_add",
|
||||
"memory_replace",
|
||||
"memory_remove",
|
||||
"skill_manage",
|
||||
"context_tree_query",
|
||||
]);
|
||||
assert.deepEqual(bundleFallbackConfig(), {
|
||||
alwaysEnabled: [...BUNDLE_TOOL_SEARCH_DEFAULTS.alwaysEnabled],
|
||||
showToolSearchFooterStatus: false,
|
||||
maxActiveGroups: 5,
|
||||
maxToolsPerGroup: 8,
|
||||
maxDynamicTools: 28,
|
||||
groupOverrides: {},
|
||||
});
|
||||
});
|
||||
|
||||
test("fills missing defaults and preserves explicit settings", async () => {
|
||||
test("config and catalog live under the bundle-owned my-pi tree", async () => {
|
||||
await withAgentDir(async (agentDir) => {
|
||||
const path = join(agentDir, "settings.json");
|
||||
await writeFile(path, JSON.stringify({ theme: "dark", toolSearch: { alwaysEnabled: ["multi_grep"], maxActiveGroups: 2 } }), "utf8");
|
||||
assert.equal(ensureToolSearchDefaults(agentDir), "updated");
|
||||
assert.deepEqual(JSON.parse(await readFile(path, "utf8")), {
|
||||
theme: "dark",
|
||||
toolSearch: {
|
||||
alwaysEnabled: ["multi_grep"],
|
||||
maxActiveGroups: 2,
|
||||
showToolSearchFooterStatus: false,
|
||||
maxToolsPerGroup: 8,
|
||||
maxDynamicTools: 28,
|
||||
groupOverrides: {},
|
||||
},
|
||||
});
|
||||
assert.equal(
|
||||
getToolSearchConfigPath(agentDir),
|
||||
join(agentDir, "my-pi", "tool-search", "config.json"),
|
||||
);
|
||||
assert.equal(
|
||||
getToolSearchCatalogPath(agentDir),
|
||||
join(agentDir, "my-pi", "tool-search", "catalog-v1.json"),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("falls back to bundle defaults when the config file is absent or invalid", async () => {
|
||||
await withAgentDir(async (agentDir) => {
|
||||
assert.deepEqual(readToolSearchConfig(agentDir), bundleFallbackConfig());
|
||||
|
||||
await writeConfig(agentDir, "{not-json");
|
||||
assert.deepEqual(readToolSearchConfig(agentDir), bundleFallbackConfig());
|
||||
|
||||
await writeConfig(agentDir, '"a string, not an object"');
|
||||
assert.deepEqual(readToolSearchConfig(agentDir), bundleFallbackConfig());
|
||||
});
|
||||
});
|
||||
|
||||
test("normalizes invalid runtime values without overwriting the file", async () => {
|
||||
await withAgentDir(async (agentDir) => {
|
||||
const path = join(agentDir, "settings.json");
|
||||
const original = JSON.stringify({
|
||||
toolSearch: {
|
||||
alwaysEnabled: ["one", "one", 3],
|
||||
showToolSearchFooterStatus: "no",
|
||||
maxActiveGroups: 0,
|
||||
maxToolsPerGroup: 4,
|
||||
maxDynamicTools: -1,
|
||||
groupOverrides: { web: ["search", 2], empty: [] },
|
||||
},
|
||||
alwaysEnabled: ["one", "one", 3],
|
||||
showToolSearchFooterStatus: "no",
|
||||
maxActiveGroups: 0,
|
||||
maxToolsPerGroup: 4,
|
||||
maxDynamicTools: -1,
|
||||
groupOverrides: { web: ["search", 2], empty: [] },
|
||||
});
|
||||
await writeFile(path, original, "utf8");
|
||||
await writeConfig(agentDir, original);
|
||||
assert.deepEqual(readToolSearchConfig(agentDir), {
|
||||
alwaysEnabled: ["one"],
|
||||
showToolSearchFooterStatus: false,
|
||||
@@ -88,34 +96,29 @@ test("normalizes invalid runtime values without overwriting the file", async ()
|
||||
maxDynamicTools: 28,
|
||||
groupOverrides: { web: ["search"] },
|
||||
});
|
||||
assert.equal(await readFile(path, "utf8"), original);
|
||||
assert.equal(await readFile(getToolSearchConfigPath(agentDir), "utf8"), original);
|
||||
});
|
||||
});
|
||||
|
||||
test("preserves a complete explicit configuration including former defaults", async () => {
|
||||
test("reads an explicit configuration verbatim", async () => {
|
||||
await withAgentDir(async (agentDir) => {
|
||||
const path = join(agentDir, "settings.json");
|
||||
const original = `${JSON.stringify({
|
||||
toolSearch: {
|
||||
alwaysEnabled: ["codegraph_explore", "lsp_diagnostics"],
|
||||
showToolSearchFooterStatus: false,
|
||||
maxActiveGroups: 3,
|
||||
maxToolsPerGroup: 8,
|
||||
maxDynamicTools: 20,
|
||||
groupOverrides: {},
|
||||
},
|
||||
alwaysEnabled: ["codegraph_explore", "lsp_diagnostics"],
|
||||
showToolSearchFooterStatus: true,
|
||||
maxActiveGroups: 3,
|
||||
maxToolsPerGroup: 8,
|
||||
maxDynamicTools: 20,
|
||||
groupOverrides: { custom: ["some_tool"] },
|
||||
}, null, 2)}\n`;
|
||||
await writeFile(path, original, "utf8");
|
||||
assert.equal(ensureToolSearchDefaults(agentDir), "unchanged");
|
||||
assert.equal(await readFile(path, "utf8"), original);
|
||||
});
|
||||
});
|
||||
|
||||
test("does not overwrite malformed settings", async () => {
|
||||
await withAgentDir(async (agentDir) => {
|
||||
const path = join(agentDir, "settings.json");
|
||||
await writeFile(path, "{not-json", "utf8");
|
||||
assert.equal(ensureToolSearchDefaults(agentDir), "skipped-invalid");
|
||||
assert.equal(await readFile(path, "utf8"), "{not-json");
|
||||
await writeConfig(agentDir, original);
|
||||
assert.deepEqual(readToolSearchConfig(agentDir), {
|
||||
alwaysEnabled: ["codegraph_explore", "lsp_diagnostics"],
|
||||
showToolSearchFooterStatus: true,
|
||||
maxActiveGroups: 3,
|
||||
maxToolsPerGroup: 8,
|
||||
maxDynamicTools: 20,
|
||||
groupOverrides: { custom: ["some_tool"] },
|
||||
});
|
||||
assert.equal(await readFile(getToolSearchConfigPath(agentDir), "utf8"), original);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import test from "node:test";
|
||||
@@ -52,17 +52,17 @@ test("loads whole groups and evicts the least-recently-used group", async () =>
|
||||
process.env.PI_CODING_AGENT_DIR = agentDir;
|
||||
|
||||
try {
|
||||
const configDir = join(agentDir, "my-pi", "tool-search");
|
||||
await mkdir(configDir, { recursive: true });
|
||||
await writeFile(
|
||||
join(agentDir, "settings.json"),
|
||||
join(configDir, "config.json"),
|
||||
JSON.stringify({
|
||||
toolSearch: {
|
||||
alwaysEnabled: ["codegraph_explore", "lsp_diagnostics"],
|
||||
showToolSearchFooterStatus: false,
|
||||
maxActiveGroups: 2,
|
||||
maxToolsPerGroup: 4,
|
||||
maxDynamicTools: 8,
|
||||
groupOverrides: {},
|
||||
},
|
||||
alwaysEnabled: ["codegraph_explore", "lsp_diagnostics"],
|
||||
showToolSearchFooterStatus: false,
|
||||
maxActiveGroups: 2,
|
||||
maxToolsPerGroup: 4,
|
||||
maxDynamicTools: 8,
|
||||
groupOverrides: {},
|
||||
}),
|
||||
);
|
||||
const handlers = new Map<string, (...args: any[]) => unknown>();
|
||||
@@ -229,7 +229,7 @@ test("builds and caches a validated catalog with the current model on first sear
|
||||
assert.equal(result?.details.catalogSource, "model");
|
||||
assert.deepEqual(result?.usage, usage);
|
||||
assert.match(prompts[0] ?? "", /Search the public web with filters and return sources/);
|
||||
const cache = JSON.parse(await readFile(join(agentDir, "tool-search", "catalog-v1.json"), "utf8"));
|
||||
const cache = JSON.parse(await readFile(join(agentDir, "my-pi", "tool-search", "catalog-v1.json"), "utf8"));
|
||||
assert.equal(cache.catalog.groups[0].id, "web-research");
|
||||
} finally {
|
||||
if (previousAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
||||
@@ -300,7 +300,7 @@ test("uses the precomputed bundle groups without calling a model", async () => {
|
||||
assert.equal(result?.details.loadedGroup, "web-tavily");
|
||||
assert.equal(result?.details.catalogSource, "bundle");
|
||||
assert.equal(modelCalls, 0);
|
||||
await assert.rejects(readFile(join(agentDir, "tool-search", "catalog-v1.json"), "utf8"), /ENOENT/);
|
||||
await assert.rejects(readFile(join(agentDir, "my-pi", "tool-search", "catalog-v1.json"), "utf8"), /ENOENT/);
|
||||
} finally {
|
||||
if (previousAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
||||
else process.env.PI_CODING_AGENT_DIR = previousAgentDir;
|
||||
|
||||
Reference in New Issue
Block a user