feat: smart subtree-aware reinit and validate --fix

- project_map_reinit now regenerates only the target subtree + ancestors
  by default, falling back to full reinit when subtree file count exceeds
  reinitFullThresholdPercent (default 10%).
- Add reinitFullThresholdPercent config option.
- Expose fix=true on project_map_validate Pi tool for localized repair.
- Update docs and runtime guidance to prefer patch / validate --fix
  before full reinit.
- Add integration tests for smart reinit and update typebox mock.
This commit is contained in:
Developer
2026-06-16 11:46:48 +00:00
parent 5f1c107667
commit cb581f44b9
11 changed files with 384 additions and 54 deletions
+20 -7
View File
@@ -209,11 +209,12 @@ export default function (pi: ExtensionAPI) {
name: "project_map_validate",
label: "Project Map Validate",
description:
"Check all .pi-map.md / .pi-map.index.md files for staleness and discrepancies",
"Check all .pi-map.md / .pi-map.index.md files for staleness and discrepancies. Optionally repair them.",
promptSnippet: "Validate paired project map/index artifacts for accuracy",
promptGuidelines: [
"Use project_map_validate before making architectural decisions if you suspect stale data",
"Use project_map_validate to detect files that were deleted or added outside the agent",
"Set fix=true to repair localized discrepancies without running a full project_map_reinit",
],
parameters: Type.Object({
path: Type.Optional(
@@ -221,13 +222,23 @@ export default function (pi: ExtensionAPI) {
description: "Project root path (default: current directory)",
}),
),
fix: Type.Optional(
Type.Boolean({
description:
"Repair discrepancies automatically (default: false). Requires an LLM client.",
default: false,
}),
),
}),
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
try {
const targetPath = params.path || ctx.cwd;
const client = params.fix ? getPiLLMClient(ctx) : undefined;
const result = await validateMaps(targetPath, {
fix: false,
fix: params.fix ?? false,
verbose: false,
llmClient: client,
cacheDir: ctx.cwd,
});
const text = result.clean
? "All .pi-map.md files are clean."
@@ -253,12 +264,14 @@ export default function (pi: ExtensionAPI) {
name: "project_map_reinit",
label: "Project Map Reinit",
description:
"Force full regeneration of all .pi-map.md / .pi-map.index.md artifacts",
"Regenerate .pi-map.md / .pi-map.index.md artifacts for a subtree plus its ancestors, falling back to full regeneration only when the subtree covers more than the configured percentage of project files (default: 10%)",
promptSnippet:
"Force full regeneration of paired project map/index artifacts",
"Regenerate paired project map/index artifacts for a subtree or the whole project",
promptGuidelines: [
"Use project_map_reinit when validation shows widespread staleness",
"Use project_map_reinit after pulling major changes from version control",
"Use project_map_reinit only after project_map_patch and project_map_validate --fix cannot resolve the staleness",
"For localized changes, prefer project_map_patch <changed-file> or project_map_validate with fix=true",
"Use project_map_reinit for widespread structural damage (e.g. broken links across many directories) or after large merges",
"When reinit falls back to full regeneration, it is because the target subtree covers more than the configured reinitFullThresholdPercent of project files",
],
parameters: Type.Object({
path: Type.Optional(
@@ -364,7 +377,7 @@ export default function (pi: ExtensionAPI) {
if (dirtyFiles.length > 0) {
ctx.ui.notify(
`pi-project-map: ${dirtyFiles.length} dirty packages detected. Run project_map_validate or project_map_reinit.`,
`pi-project-map: ${dirtyFiles.length} dirty package(s) detected. Run project_map_validate first; use project_map_reinit only if staleness is widespread.`,
"warning",
);
}