Skip to content

Commit 59cc707

Browse files
refactor(core): use standard PlanErrorMessages constant for path access errors
Addresses review feedback by restoring the idiomatic PlanErrorMessages.PATH_ACCESS_DENIED constant inside resolveAndValidatePlanPath instead of a raw 'Security violation' string. This allowed for removing redundant catch-and-translate logic in exit-plan-mode.ts.
1 parent d3f624b commit 59cc707

3 files changed

Lines changed: 2 additions & 8 deletions

File tree

packages/core/src/tools/exit-plan-mode.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ Ask the user for specific feedback on how to improve the plan.`,
504504
});
505505

506506
expect(result).toBe(
507-
`Access denied: plan path (${path.join(mockPlansDir, 'malicious.md')}) must be within the designated plans directory (${mockPlansDir}).`,
507+
`Access denied: plan path (malicious.md) must be within the designated plans directory (${mockPlansDir}).`,
508508
);
509509
});
510510

packages/core/src/tools/exit-plan-mode.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ export class ExitPlanModeTool extends BaseDeclarativeTool<
6969
this.config.getProjectRoot(),
7070
);
7171
} catch (e) {
72-
if (e instanceof Error && e.message.startsWith('Security violation')) {
73-
return `Access denied: plan path (${path.join(
74-
this.config.storage.getPlansDir(),
75-
params.plan_filename,
76-
)}) must be within the designated plans directory (${this.config.storage.getPlansDir()}).`;
77-
}
7872
return e instanceof Error ? e.message : String(e);
7973
}
8074

packages/core/src/utils/planUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function resolveAndValidatePlanPath(
6767

6868
if (!isSubpath(realPlansDir, realPath)) {
6969
throw new Error(
70-
`Security violation: plan path (${trimmedPath}) must be within the designated plans directory (${plansDir}).`,
70+
PlanErrorMessages.PATH_ACCESS_DENIED(trimmedPath, plansDir),
7171
);
7272
}
7373

0 commit comments

Comments
 (0)