fix(tracker): lazily initialize tracker directory

This commit is contained in:
Anjali Sridhar
2026-02-22 11:14:04 -08:00
parent eb33db5b40
commit daf9da26c8
3 changed files with 9 additions and 13 deletions
@@ -26,13 +26,6 @@ describe('TrackerService', () => {
await fs.rm(testTrackerDir, { recursive: true, force: true });
});
it('should initialize the tracker directory', async () => {
await service.ensureInitialized();
const tasksDir = testTrackerDir;
const stats = await fs.stat(tasksDir);
expect(stats.isDirectory()).toBe(true);
});
it('should create a task with a generated 6-char hex ID', async () => {
const taskData: Omit<TrackerTask, 'id'> = {
title: 'Test Task',
+9 -5
View File
@@ -12,15 +12,18 @@ import { TrackerTaskSchema, type TrackerTask } from './trackerTypes.js';
export class TrackerService {
private readonly tasksDir: string;
private initialized = false;
constructor(readonly trackerDir: string) {
console.log('trackerDir', trackerDir);
this.tasksDir = trackerDir;
}
/**
* Initializes the tracker storage if it doesn't exist.
*/
async ensureInitialized(): Promise<void> {
await fs.mkdir(this.tasksDir, { recursive: true });
private async ensureInitialized(): Promise<void> {
if (!this.initialized) {
await fs.mkdir(this.tasksDir, { recursive: true });
this.initialized = true;
}
}
/**
@@ -49,6 +52,7 @@ export class TrackerService {
* Reads a task by ID.
*/
async getTask(id: string): Promise<TrackerTask | null> {
await this.ensureInitialized();
const taskPath = path.join(this.tasksDir, `${id}.json`);
try {
const content = await fs.readFile(taskPath, 'utf8');
-1
View File
@@ -67,7 +67,6 @@ class TrackerInitInvocation extends BaseTrackerInvocation<
}
override async execute(_signal: AbortSignal): Promise<ToolResult> {
await this.service.ensureInitialized();
return {
llmContent: `Task tracker initialized successfully. Storage is ready at ${this.service.trackerDir}`,
returnDisplay: 'Tracker initialized.',