@@ -9,7 +9,6 @@ interface PlanWatcher {
99 pollTimer : ReturnType < typeof setInterval > | null ;
1010 plansDirs : string [ ] ;
1111 watchedDirs : Set < string > ;
12- knownFiles : Set < string > ;
1312}
1413
1514const watchers = new Map < string , PlanWatcher > ( ) ;
@@ -20,25 +19,6 @@ const PLAN_DIRS = ['.claude/plans', 'docs/plans'];
2019/** How often to check for newly created plan directories (ms). */
2120const DIR_POLL_INTERVAL = 3_000 ;
2221
23- /** Snapshot existing `.md` filenames across the given directories. */
24- export function snapshotExistingFiles ( dirs : string [ ] ) : Set < string > {
25- const known = new Set < string > ( ) ;
26- for ( const dir of dirs ) {
27- let entries : fs . Dirent [ ] ;
28- try {
29- entries = fs . readdirSync ( dir , { withFileTypes : true } ) ;
30- } catch {
31- continue ;
32- }
33- for ( const e of entries ) {
34- if ( e . isFile ( ) && e . name . endsWith ( '.md' ) ) {
35- known . add ( e . name ) ;
36- }
37- }
38- }
39- return known ;
40- }
41-
4222/**
4323 * Reads and merges `.claude/settings.local.json` in the worktree to set
4424 * `plansDirectory: "./.claude/plans"`. Creates the plans dir if needed.
@@ -71,20 +51,15 @@ export function ensurePlansDirectory(worktreePath: string): void {
7151}
7252
7353/** Reads the newest `.md` file by mtime from a single plans directory. */
74- function readNewestPlan (
75- plansDir : string ,
76- knownFiles ?: Set < string > ,
77- ) : { content : string ; fileName : string ; mtime : number } | null {
54+ function readNewestPlan ( plansDir : string ) : { content : string ; fileName : string ; mtime : number } | null {
7855 let entries : fs . Dirent [ ] ;
7956 try {
8057 entries = fs . readdirSync ( plansDir , { withFileTypes : true } ) ;
8158 } catch {
8259 return null ;
8360 }
8461
85- const mdFiles = entries . filter (
86- ( e ) => e . isFile ( ) && e . name . endsWith ( '.md' ) && ( ! knownFiles || ! knownFiles . has ( e . name ) ) ,
87- ) ;
62+ const mdFiles = entries . filter ( ( e ) => e . isFile ( ) && e . name . endsWith ( '.md' ) ) ;
8863 if ( mdFiles . length === 0 ) return null ;
8964
9065 let newest : { name : string ; mtime : number } | null = null ;
@@ -111,13 +86,10 @@ function readNewestPlan(
11186}
11287
11388/** Reads the newest plan across multiple directories. */
114- export function readNewestPlanFromDirs (
115- plansDirs : string [ ] ,
116- knownFiles ?: Set < string > ,
117- ) : { content : string ; fileName : string } | null {
89+ function readNewestPlanFromDirs ( plansDirs : string [ ] ) : { content : string ; fileName : string } | null {
11890 let best : { content : string ; fileName : string ; mtime : number } | null = null ;
11991 for ( const dir of plansDirs ) {
120- const result = readNewestPlan ( dir , knownFiles ) ;
92+ const result = readNewestPlan ( dir ) ;
12193 if ( result && ( ! best || result . mtime > best . mtime ) ) {
12294 best = result ;
12395 }
@@ -126,9 +98,9 @@ export function readNewestPlanFromDirs(
12698}
12799
128100/** Sends plan content for a task to the renderer. */
129- function sendPlanContent ( win : BrowserWindow , taskId : string , plansDirs : string [ ] , knownFiles : Set < string > ) : void {
101+ function sendPlanContent ( win : BrowserWindow , taskId : string , plansDirs : string [ ] ) : void {
130102 if ( win . isDestroyed ( ) ) return ;
131- const result = readNewestPlanFromDirs ( plansDirs , knownFiles ) ;
103+ const result = readNewestPlanFromDirs ( plansDirs ) ;
132104 if ( result ) {
133105 win . webContents . send ( IPC . PlanContent , {
134106 taskId,
@@ -170,10 +142,6 @@ function startDirPolling(taskId: string, entry: PlanWatcher, onChange: () => voi
170142 for ( const dir of current . plansDirs ) {
171143 if ( current . watchedDirs . has ( dir ) ) continue ;
172144 if ( ! fs . existsSync ( dir ) ) continue ;
173- // Snapshot existing files before watching so they are ignored
174- for ( const name of snapshotExistingFiles ( [ dir ] ) ) {
175- current . knownFiles . add ( name ) ;
176- }
177145 const watcher = watchDir ( dir , onChange ) ;
178146 if ( watcher ) {
179147 current . fsWatchers . push ( watcher ) ;
@@ -206,15 +174,14 @@ export function startPlanWatcher(win: BrowserWindow, taskId: string, worktreePat
206174 const claudePlansDir = path . join ( worktreePath , '.claude' , 'plans' ) ;
207175 fs . mkdirSync ( claudePlansDir , { recursive : true } ) ;
208176
209- const knownFiles = snapshotExistingFiles ( plansDirs ) ;
177+ sendPlanContent ( win , taskId , plansDirs ) ;
210178
211179 const entry : PlanWatcher = {
212180 fsWatchers : [ ] ,
213181 timeout : null ,
214182 pollTimer : null ,
215183 plansDirs,
216184 watchedDirs : new Set ( ) ,
217- knownFiles,
218185 } ;
219186
220187 const onChange = ( ) => {
@@ -223,7 +190,7 @@ export function startPlanWatcher(win: BrowserWindow, taskId: string, worktreePat
223190 if ( current . timeout ) clearTimeout ( current . timeout ) ;
224191 current . timeout = setTimeout ( ( ) => {
225192 current . timeout = null ;
226- sendPlanContent ( win , taskId , current . plansDirs , current . knownFiles ) ;
193+ sendPlanContent ( win , taskId , current . plansDirs ) ;
227194 } , 200 ) ;
228195 } ;
229196
0 commit comments