fix(core): resolve nested plan directory duplication and relative path policies (#25138)

This commit is contained in:
Mahima Shanware
2026-04-21 14:20:57 -04:00
committed by GitHub
parent c260550146
commit a4e98c0a4c
17 changed files with 283 additions and 76 deletions
@@ -7,6 +7,7 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { PromptProvider } from './promptProvider.js';
import type { Config } from '../config/config.js';
import { makeRelative } from '../utils/paths.js';
import {
getAllGeminiMdFilenames,
DEFAULT_CONTEXT_FILENAME,
@@ -58,6 +59,7 @@ describe('PromptProvider', () => {
).getToolRegistry?.() as unknown as ToolRegistry;
},
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
getProjectRoot: vi.fn().mockReturnValue('/tmp/project-temp'),
topicState: new TopicState(),
getEnableShellOutputEfficiency: vi.fn().mockReturnValue(true),
getSandboxEnabled: vi.fn().mockReturnValue(false),
@@ -236,7 +238,14 @@ describe('PromptProvider', () => {
expect(prompt).toContain(
'`write_file` and `replace` may ONLY be used to write .md plan files',
);
expect(prompt).toContain('/tmp/project-temp/plans/');
const expectedRelativePath = makeRelative(
mockConfig.storage.getPlansDir(),
mockConfig.getProjectRoot(),
).replaceAll('\\', '/');
expect(prompt).toContain(
`write .md plan files to \`${expectedRelativePath}/\``,
);
});
});
+14 -3
View File
@@ -8,7 +8,7 @@ import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import type { HierarchicalMemory } from '../config/memory.js';
import { GEMINI_DIR } from '../utils/paths.js';
import { GEMINI_DIR, makeRelative } from '../utils/paths.js';
import { ApprovalMode } from '../policy/types.js';
import * as snippets from './snippets.js';
import * as legacySnippets from './snippets.legacy.js';
@@ -199,8 +199,19 @@ export class PromptProvider {
() => ({
interactive: interactiveMode,
planModeToolsList,
plansDir: context.config.storage.getPlansDir(),
approvedPlanPath: context.config.getApprovedPlanPath(),
plansDir: makeRelative(
context.config.storage.getPlansDir(),
context.config.getProjectRoot(),
).replaceAll('\\', '/'),
approvedPlanPath: (() => {
const approvedPath = context.config.getApprovedPlanPath();
return approvedPath
? makeRelative(
approvedPath,
context.config.getProjectRoot(),
).replaceAll('\\', '/')
: undefined;
})(),
}),
isPlanMode,
),