@zeliper/zscode-mcp-server 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/state/manager.d.ts +73 -1
- package/dist/state/manager.d.ts.map +1 -1
- package/dist/state/manager.js +266 -0
- package/dist/state/manager.js.map +1 -1
- package/dist/state/schema.d.ts +9 -9
- package/dist/state/schema.d.ts.map +1 -1
- package/dist/state/schema.js +1 -0
- package/dist/state/schema.js.map +1 -1
- package/dist/tools/context.d.ts.map +1 -1
- package/dist/tools/context.js +74 -7
- package/dist/tools/context.js.map +1 -1
- package/dist/tools/memory.d.ts.map +1 -1
- package/dist/tools/memory.js +13 -42
- package/dist/tools/memory.js.map +1 -1
- package/dist/tools/modify.d.ts.map +1 -1
- package/dist/tools/modify.js +91 -28
- package/dist/tools/modify.js.map +1 -1
- package/dist/tools/plan.d.ts.map +1 -1
- package/dist/tools/plan.js +142 -7
- package/dist/tools/plan.js.map +1 -1
- package/dist/tools/staging.d.ts.map +1 -1
- package/dist/tools/staging.js +239 -16
- package/dist/tools/staging.js.map +1 -1
- package/dist/tools/status.js +33 -4
- package/dist/tools/status.js.map +1 -1
- package/dist/utils/format.d.ts +16 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +42 -3
- package/dist/utils/format.js.map +1 -1
- package/package.json +1 -1
package/dist/state/manager.d.ts
CHANGED
|
@@ -1,15 +1,38 @@
|
|
|
1
1
|
import { type State, type Plan, type Staging, type Task, type Project, type Decision, type Memory, type TaskStatus, type PlanStatus, type HistoryEntryType, type TaskOutput, type IdGenerator, type MemoryEventType, type RelatedStagingArtifacts, type CrossReferencedTaskOutput, type ModelType, type SessionBudget } from "./types.js";
|
|
2
2
|
declare const idGenerator: IdGenerator;
|
|
3
|
+
interface PlanStatusCache {
|
|
4
|
+
totalTasks: number;
|
|
5
|
+
completedTasks: number;
|
|
6
|
+
stagingCount: number;
|
|
7
|
+
completedStagingCount: number;
|
|
8
|
+
}
|
|
3
9
|
export declare class StateManager {
|
|
4
10
|
private static instance;
|
|
5
11
|
private state;
|
|
6
12
|
private projectRoot;
|
|
7
13
|
private stateFilePath;
|
|
14
|
+
private _dirty;
|
|
15
|
+
private _saveTimer;
|
|
16
|
+
private _saveDebounceMs;
|
|
17
|
+
private _planStatusCache;
|
|
18
|
+
private _statusCacheValid;
|
|
8
19
|
private constructor();
|
|
9
20
|
static initialize(projectRoot: string): Promise<StateManager>;
|
|
10
21
|
static getInstance(): StateManager;
|
|
11
22
|
private load;
|
|
12
23
|
private save;
|
|
24
|
+
/**
|
|
25
|
+
* Schedule a debounced save operation
|
|
26
|
+
*/
|
|
27
|
+
private scheduleSave;
|
|
28
|
+
/**
|
|
29
|
+
* Immediately flush pending save to disk
|
|
30
|
+
*/
|
|
31
|
+
flushSave(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Invalidate cache for a specific plan (also invalidates global status cache)
|
|
34
|
+
*/
|
|
35
|
+
private invalidatePlanCache;
|
|
13
36
|
private ensureInitialized;
|
|
14
37
|
private requirePlan;
|
|
15
38
|
private requireStaging;
|
|
@@ -25,6 +48,12 @@ export declare class StateManager {
|
|
|
25
48
|
getTasksByStaging(stagingId: string): Task[];
|
|
26
49
|
getStagingByOrder(planId: string, order: number): Staging | undefined;
|
|
27
50
|
initializeProject(name: string, description?: string, goals?: string[], constraints?: string[]): Promise<Project>;
|
|
51
|
+
updateProject(updates: {
|
|
52
|
+
name?: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
goals?: string[];
|
|
55
|
+
constraints?: string[];
|
|
56
|
+
}): Promise<Project>;
|
|
28
57
|
createPlan(title: string, description: string | undefined, stagingConfigs: Array<{
|
|
29
58
|
name: string;
|
|
30
59
|
description?: string;
|
|
@@ -44,7 +73,34 @@ export declare class StateManager {
|
|
|
44
73
|
updatePlanStatus(planId: string, status: PlanStatus): Promise<void>;
|
|
45
74
|
startStaging(planId: string, stagingId: string): Promise<Staging>;
|
|
46
75
|
completeStaging(stagingId: string): Promise<void>;
|
|
47
|
-
updateTaskStatus(taskId: string, status: TaskStatus, notes?: string): Promise<
|
|
76
|
+
updateTaskStatus(taskId: string, status: TaskStatus, notes?: string): Promise<{
|
|
77
|
+
stagingCompleted?: boolean;
|
|
78
|
+
completedStagingId?: string;
|
|
79
|
+
nextStaging?: Staging | null;
|
|
80
|
+
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Batch update multiple tasks' status at once.
|
|
83
|
+
* This is more efficient than calling updateTaskStatus multiple times
|
|
84
|
+
* and ensures atomic updates for parallel staging execution.
|
|
85
|
+
*/
|
|
86
|
+
updateTasksStatus(updates: Array<{
|
|
87
|
+
taskId: string;
|
|
88
|
+
status: TaskStatus;
|
|
89
|
+
notes?: string;
|
|
90
|
+
}>): Promise<{
|
|
91
|
+
results: Array<{
|
|
92
|
+
taskId: string;
|
|
93
|
+
taskTitle: string;
|
|
94
|
+
previousStatus: TaskStatus;
|
|
95
|
+
newStatus: TaskStatus;
|
|
96
|
+
success: boolean;
|
|
97
|
+
error?: string;
|
|
98
|
+
}>;
|
|
99
|
+
stagingCompleted?: boolean;
|
|
100
|
+
completedStagingId?: string;
|
|
101
|
+
nextStaging?: Staging | null;
|
|
102
|
+
planCompleted?: boolean;
|
|
103
|
+
}>;
|
|
48
104
|
saveTaskOutput(taskId: string, output: TaskOutput): Promise<void>;
|
|
49
105
|
getExecutableTasks(stagingId: string): Task[];
|
|
50
106
|
archivePlan(planId: string, reason?: string): Promise<string>;
|
|
@@ -151,6 +207,22 @@ export declare class StateManager {
|
|
|
151
207
|
}): Promise<Task>;
|
|
152
208
|
getProjectRoot(): string;
|
|
153
209
|
isInitialized(): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Get cached plan status or compute if not cached
|
|
212
|
+
*/
|
|
213
|
+
getCachedPlanStatus(planId: string): PlanStatusCache | null;
|
|
214
|
+
/**
|
|
215
|
+
* Check if status cache is valid
|
|
216
|
+
*/
|
|
217
|
+
isStatusCacheValid(): boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Mark status cache as valid (after full rebuild)
|
|
220
|
+
*/
|
|
221
|
+
markStatusCacheValid(): void;
|
|
222
|
+
/**
|
|
223
|
+
* Clear all caches
|
|
224
|
+
*/
|
|
225
|
+
clearAllCaches(): void;
|
|
154
226
|
}
|
|
155
227
|
export { idGenerator };
|
|
156
228
|
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/state/manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,KAAK,EACV,KAAK,IAAI,EACT,KAAK,OAAO,EACZ,KAAK,IAAI,EACT,KAAK,OAAO,EAEZ,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,yBAAyB,EAC9B,KAAK,SAAS,EACd,KAAK,aAAa,EACnB,MAAM,YAAY,CAAC;AA0CpB,QAAA,MAAM,WAAW,EAAE,WAOlB,CAAC;AAGF,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA6B;IACpD,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,aAAa,CAAS;
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/state/manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,KAAK,EACV,KAAK,IAAI,EACT,KAAK,OAAO,EACZ,KAAK,IAAI,EACT,KAAK,OAAO,EAEZ,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,eA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AAE,OAAO,EAAE;QAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;QACrC,cAAc,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;QAC3C,KAAK,CAAC,EAAE,SAAS,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;KACvB,GAAG,OAAO,CAAC,IAAI,CAAC;IAqDjB,cAAc,IAAI,MAAM;IAIxB,aAAa,IAAI,OAAO;IAKxB;;OAEG;IACH,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI;IAqC3D;;OAEG;IACH,kBAAkB,IAAI,OAAO;IAI7B;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAI5B;;OAEG;IACH,cAAc,IAAI,IAAI;CAIvB;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
package/dist/state/manager.js
CHANGED
|
@@ -31,6 +31,13 @@ export class StateManager {
|
|
|
31
31
|
state = null;
|
|
32
32
|
projectRoot;
|
|
33
33
|
stateFilePath;
|
|
34
|
+
// Optimization: Dirty flag for debounced saving
|
|
35
|
+
_dirty = false;
|
|
36
|
+
_saveTimer = null;
|
|
37
|
+
_saveDebounceMs = 100;
|
|
38
|
+
// Optimization: Plan status cache
|
|
39
|
+
_planStatusCache = new Map();
|
|
40
|
+
_statusCacheValid = false;
|
|
34
41
|
constructor(projectRoot) {
|
|
35
42
|
this.projectRoot = normalizePath(projectRoot);
|
|
36
43
|
this.stateFilePath = normalizePath(join(projectRoot, ".claude", "state.json"));
|
|
@@ -70,9 +77,43 @@ export class StateManager {
|
|
|
70
77
|
if (!this.state) {
|
|
71
78
|
throw new Error("No state to save");
|
|
72
79
|
}
|
|
80
|
+
// Mark dirty and schedule debounced save
|
|
81
|
+
this._dirty = true;
|
|
82
|
+
this.scheduleSave();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Schedule a debounced save operation
|
|
86
|
+
*/
|
|
87
|
+
scheduleSave() {
|
|
88
|
+
if (this._saveTimer) {
|
|
89
|
+
return; // Already scheduled
|
|
90
|
+
}
|
|
91
|
+
this._saveTimer = setTimeout(async () => {
|
|
92
|
+
await this.flushSave();
|
|
93
|
+
}, this._saveDebounceMs);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Immediately flush pending save to disk
|
|
97
|
+
*/
|
|
98
|
+
async flushSave() {
|
|
99
|
+
if (this._saveTimer) {
|
|
100
|
+
clearTimeout(this._saveTimer);
|
|
101
|
+
this._saveTimer = null;
|
|
102
|
+
}
|
|
103
|
+
if (!this._dirty || !this.state) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this._dirty = false;
|
|
73
107
|
// Use atomic write to prevent data corruption
|
|
74
108
|
await atomicWriteFile(this.stateFilePath, JSON.stringify(this.state, null, 2));
|
|
75
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Invalidate cache for a specific plan (also invalidates global status cache)
|
|
112
|
+
*/
|
|
113
|
+
invalidatePlanCache(planId) {
|
|
114
|
+
this._planStatusCache.delete(planId);
|
|
115
|
+
this._statusCacheValid = false;
|
|
116
|
+
}
|
|
76
117
|
// ============ Validation Helpers ============
|
|
77
118
|
ensureInitialized() {
|
|
78
119
|
if (!this.state) {
|
|
@@ -182,6 +223,26 @@ export class StateManager {
|
|
|
182
223
|
await this.save();
|
|
183
224
|
return project;
|
|
184
225
|
}
|
|
226
|
+
async updateProject(updates) {
|
|
227
|
+
const state = this.ensureInitialized();
|
|
228
|
+
const now = new Date().toISOString();
|
|
229
|
+
if (updates.name !== undefined) {
|
|
230
|
+
state.project.name = updates.name;
|
|
231
|
+
}
|
|
232
|
+
if (updates.description !== undefined) {
|
|
233
|
+
state.project.description = updates.description;
|
|
234
|
+
}
|
|
235
|
+
if (updates.goals !== undefined) {
|
|
236
|
+
state.project.goals = updates.goals;
|
|
237
|
+
}
|
|
238
|
+
if (updates.constraints !== undefined) {
|
|
239
|
+
state.project.constraints = updates.constraints;
|
|
240
|
+
}
|
|
241
|
+
state.project.updatedAt = now;
|
|
242
|
+
await this.addHistory("project_updated", { updates: Object.keys(updates) });
|
|
243
|
+
await this.save();
|
|
244
|
+
return state.project;
|
|
245
|
+
}
|
|
185
246
|
// ============ Plan Operations ============
|
|
186
247
|
async createPlan(title, description, stagingConfigs) {
|
|
187
248
|
const state = this.ensureInitialized();
|
|
@@ -317,6 +378,8 @@ export class StateManager {
|
|
|
317
378
|
const now = new Date().toISOString();
|
|
318
379
|
staging.status = "completed";
|
|
319
380
|
staging.completedAt = now;
|
|
381
|
+
// Invalidate cache for this plan
|
|
382
|
+
this.invalidatePlanCache(staging.planId);
|
|
320
383
|
const plan = this.getPlan(staging.planId);
|
|
321
384
|
if (plan) {
|
|
322
385
|
plan.updatedAt = now;
|
|
@@ -346,9 +409,12 @@ export class StateManager {
|
|
|
346
409
|
const now = new Date().toISOString();
|
|
347
410
|
task.status = status;
|
|
348
411
|
task.updatedAt = now;
|
|
412
|
+
// Invalidate cache for this plan
|
|
413
|
+
this.invalidatePlanCache(task.planId);
|
|
349
414
|
if (notes) {
|
|
350
415
|
task.notes = notes;
|
|
351
416
|
}
|
|
417
|
+
let result = {};
|
|
352
418
|
if (status === "in_progress") {
|
|
353
419
|
task.startedAt = now;
|
|
354
420
|
await this.addHistory("task_started", { taskId, taskTitle: task.title });
|
|
@@ -365,6 +431,14 @@ export class StateManager {
|
|
|
365
431
|
});
|
|
366
432
|
if (allTasksDone) {
|
|
367
433
|
await this.completeStaging(staging.id);
|
|
434
|
+
result.stagingCompleted = true;
|
|
435
|
+
result.completedStagingId = staging.id;
|
|
436
|
+
// Find next staging
|
|
437
|
+
const allStagings = this.getStagingsByPlan(staging.planId);
|
|
438
|
+
const currentIndex = allStagings.findIndex(s => s.id === staging.id);
|
|
439
|
+
result.nextStaging = currentIndex >= 0 && currentIndex < allStagings.length - 1
|
|
440
|
+
? allStagings[currentIndex + 1]
|
|
441
|
+
: null;
|
|
368
442
|
}
|
|
369
443
|
}
|
|
370
444
|
}
|
|
@@ -372,6 +446,124 @@ export class StateManager {
|
|
|
372
446
|
await this.addHistory("task_blocked", { taskId, taskTitle: task.title, notes });
|
|
373
447
|
}
|
|
374
448
|
await this.save();
|
|
449
|
+
return result;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Batch update multiple tasks' status at once.
|
|
453
|
+
* This is more efficient than calling updateTaskStatus multiple times
|
|
454
|
+
* and ensures atomic updates for parallel staging execution.
|
|
455
|
+
*/
|
|
456
|
+
async updateTasksStatus(updates) {
|
|
457
|
+
const now = new Date().toISOString();
|
|
458
|
+
const results = [];
|
|
459
|
+
const affectedPlanIds = new Set();
|
|
460
|
+
const affectedStagingIds = new Set();
|
|
461
|
+
// Process all updates first (validation and state change)
|
|
462
|
+
for (const update of updates) {
|
|
463
|
+
const task = this.getTask(update.taskId);
|
|
464
|
+
if (!task) {
|
|
465
|
+
results.push({
|
|
466
|
+
taskId: update.taskId,
|
|
467
|
+
taskTitle: "unknown",
|
|
468
|
+
previousStatus: "pending",
|
|
469
|
+
newStatus: update.status,
|
|
470
|
+
success: false,
|
|
471
|
+
error: `Task not found: ${update.taskId}`,
|
|
472
|
+
});
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
const previousStatus = task.status;
|
|
476
|
+
// Validate state transition
|
|
477
|
+
const allowedTransitions = VALID_TASK_TRANSITIONS[task.status];
|
|
478
|
+
if (!allowedTransitions.includes(update.status)) {
|
|
479
|
+
results.push({
|
|
480
|
+
taskId: update.taskId,
|
|
481
|
+
taskTitle: task.title,
|
|
482
|
+
previousStatus,
|
|
483
|
+
newStatus: update.status,
|
|
484
|
+
success: false,
|
|
485
|
+
error: `Invalid transition: ${task.status} -> ${update.status}`,
|
|
486
|
+
});
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
// Apply the update
|
|
490
|
+
task.status = update.status;
|
|
491
|
+
task.updatedAt = now;
|
|
492
|
+
if (update.notes) {
|
|
493
|
+
task.notes = update.notes;
|
|
494
|
+
}
|
|
495
|
+
affectedPlanIds.add(task.planId);
|
|
496
|
+
affectedStagingIds.add(task.stagingId);
|
|
497
|
+
if (update.status === "in_progress") {
|
|
498
|
+
task.startedAt = now;
|
|
499
|
+
}
|
|
500
|
+
else if (update.status === "done") {
|
|
501
|
+
task.completedAt = now;
|
|
502
|
+
}
|
|
503
|
+
results.push({
|
|
504
|
+
taskId: update.taskId,
|
|
505
|
+
taskTitle: task.title,
|
|
506
|
+
previousStatus,
|
|
507
|
+
newStatus: update.status,
|
|
508
|
+
success: true,
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
// Invalidate cache for affected plans
|
|
512
|
+
for (const planId of affectedPlanIds) {
|
|
513
|
+
this.invalidatePlanCache(planId);
|
|
514
|
+
}
|
|
515
|
+
// Add history entries for successful updates
|
|
516
|
+
for (const result of results) {
|
|
517
|
+
if (result.success) {
|
|
518
|
+
if (result.newStatus === "in_progress") {
|
|
519
|
+
await this.addHistory("task_started", { taskId: result.taskId, taskTitle: result.taskTitle });
|
|
520
|
+
}
|
|
521
|
+
else if (result.newStatus === "done") {
|
|
522
|
+
await this.addHistory("task_completed", { taskId: result.taskId, taskTitle: result.taskTitle });
|
|
523
|
+
}
|
|
524
|
+
else if (result.newStatus === "blocked") {
|
|
525
|
+
const update = updates.find(u => u.taskId === result.taskId);
|
|
526
|
+
await this.addHistory("task_blocked", { taskId: result.taskId, taskTitle: result.taskTitle, notes: update?.notes });
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
// Check for staging completion
|
|
531
|
+
let stagingCompleted = false;
|
|
532
|
+
let completedStagingId;
|
|
533
|
+
let nextStaging = null;
|
|
534
|
+
let planCompleted = false;
|
|
535
|
+
for (const stagingId of affectedStagingIds) {
|
|
536
|
+
const staging = this.getStaging(stagingId);
|
|
537
|
+
if (staging && staging.status === "in_progress") {
|
|
538
|
+
const allTasksDone = staging.tasks.every(id => {
|
|
539
|
+
const t = this.getTask(id);
|
|
540
|
+
return t?.status === "done";
|
|
541
|
+
});
|
|
542
|
+
if (allTasksDone) {
|
|
543
|
+
await this.completeStaging(staging.id);
|
|
544
|
+
stagingCompleted = true;
|
|
545
|
+
completedStagingId = staging.id;
|
|
546
|
+
// Find next staging
|
|
547
|
+
const allStagings = this.getStagingsByPlan(staging.planId);
|
|
548
|
+
const currentIndex = allStagings.findIndex(s => s.id === staging.id);
|
|
549
|
+
if (currentIndex >= 0 && currentIndex < allStagings.length - 1) {
|
|
550
|
+
nextStaging = allStagings[currentIndex + 1];
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
planCompleted = true;
|
|
554
|
+
}
|
|
555
|
+
break; // Only report first staging completion
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
await this.save();
|
|
560
|
+
return {
|
|
561
|
+
results,
|
|
562
|
+
stagingCompleted: stagingCompleted ? true : undefined,
|
|
563
|
+
completedStagingId,
|
|
564
|
+
nextStaging,
|
|
565
|
+
planCompleted: planCompleted ? true : undefined,
|
|
566
|
+
};
|
|
375
567
|
}
|
|
376
568
|
async saveTaskOutput(taskId, output) {
|
|
377
569
|
// Validate taskId to prevent path traversal
|
|
@@ -497,6 +689,8 @@ export class StateManager {
|
|
|
497
689
|
if (plan.status === "archived" || plan.status === "cancelled") {
|
|
498
690
|
throw new PlanInvalidStateError(planId, plan.status, ["draft", "active", "completed"]);
|
|
499
691
|
}
|
|
692
|
+
// Invalidate cache for this plan
|
|
693
|
+
this.invalidatePlanCache(planId);
|
|
500
694
|
const now = new Date().toISOString();
|
|
501
695
|
let affectedStagings = 0;
|
|
502
696
|
let affectedTasks = 0;
|
|
@@ -771,6 +965,15 @@ export class StateManager {
|
|
|
771
965
|
lines.push(`\n## Constraints`);
|
|
772
966
|
project.constraints.forEach(c => lines.push(`- ${c}`));
|
|
773
967
|
}
|
|
968
|
+
// Features (MCP Tools) - Always include
|
|
969
|
+
lines.push(`\n## Features`);
|
|
970
|
+
lines.push(`- **Plan Management**: create_plan, update_plan, sync_plan, zscode:cancel, zscode:archive, zscode:unarchive`);
|
|
971
|
+
lines.push(`- **Staging Management**: zscode:start, add_staging, update_staging, remove_staging, complete_staging`);
|
|
972
|
+
lines.push(`- **Task Management**: add_task, update_task, update_task_details, remove_task, save_task_output, get_staging_artifacts`);
|
|
973
|
+
lines.push(`- **Memory System**: add_memory, list_memories, update_memory, remove_memory, get_memories_for_context, list_categories`);
|
|
974
|
+
lines.push(`- **Context & Status**: get_full_context, zscode:status, init_project, update_project, add_decision`);
|
|
975
|
+
lines.push(`- **Summary**: generate_summary, get_project_summary, delete_project_summary`);
|
|
976
|
+
lines.push(`- **File Operations**: zscode:read, zscode:write`);
|
|
774
977
|
// Current status
|
|
775
978
|
lines.push(`\n## Status`);
|
|
776
979
|
lines.push(`- Active Plans: ${activePlans.length}`);
|
|
@@ -932,6 +1135,8 @@ export class StateManager {
|
|
|
932
1135
|
// Insert into plan's staging list
|
|
933
1136
|
plan.stagings.splice(insertAt, 0, stagingId);
|
|
934
1137
|
plan.updatedAt = now;
|
|
1138
|
+
// Invalidate cache for this plan
|
|
1139
|
+
this.invalidatePlanCache(planId);
|
|
935
1140
|
await this.addHistory("staging_added", { planId, stagingId, name: config.name });
|
|
936
1141
|
await this.save();
|
|
937
1142
|
return staging;
|
|
@@ -942,6 +1147,8 @@ export class StateManager {
|
|
|
942
1147
|
if (staging.status === "in_progress") {
|
|
943
1148
|
throw new StagingInvalidStateError(stagingId, staging.status, ["pending", "completed", "cancelled"]);
|
|
944
1149
|
}
|
|
1150
|
+
// Invalidate cache for this plan
|
|
1151
|
+
this.invalidatePlanCache(staging.planId);
|
|
945
1152
|
const plan = this.requirePlan(staging.planId);
|
|
946
1153
|
// Remove all tasks in this staging
|
|
947
1154
|
for (const taskId of staging.tasks) {
|
|
@@ -1022,6 +1229,8 @@ export class StateManager {
|
|
|
1022
1229
|
};
|
|
1023
1230
|
state.tasks[taskId] = task;
|
|
1024
1231
|
staging.tasks.push(taskId);
|
|
1232
|
+
// Invalidate cache for this plan
|
|
1233
|
+
this.invalidatePlanCache(staging.planId);
|
|
1025
1234
|
await this.addHistory("task_added", { stagingId, taskId, title: config.title });
|
|
1026
1235
|
await this.save();
|
|
1027
1236
|
return task;
|
|
@@ -1032,6 +1241,8 @@ export class StateManager {
|
|
|
1032
1241
|
if (task.status === "in_progress") {
|
|
1033
1242
|
throw new TaskInvalidStateError(taskId, task.status, ["pending", "done", "blocked", "cancelled"]);
|
|
1034
1243
|
}
|
|
1244
|
+
// Invalidate cache for this plan
|
|
1245
|
+
this.invalidatePlanCache(task.planId);
|
|
1035
1246
|
const staging = this.requireStaging(task.stagingId);
|
|
1036
1247
|
// Remove task from staging
|
|
1037
1248
|
staging.tasks = staging.tasks.filter(id => id !== taskId);
|
|
@@ -1101,6 +1312,61 @@ export class StateManager {
|
|
|
1101
1312
|
isInitialized() {
|
|
1102
1313
|
return this.state !== null;
|
|
1103
1314
|
}
|
|
1315
|
+
// ============ Cached Status Methods ============
|
|
1316
|
+
/**
|
|
1317
|
+
* Get cached plan status or compute if not cached
|
|
1318
|
+
*/
|
|
1319
|
+
getCachedPlanStatus(planId) {
|
|
1320
|
+
if (!this.state)
|
|
1321
|
+
return null;
|
|
1322
|
+
// Return cached if valid
|
|
1323
|
+
if (this._planStatusCache.has(planId)) {
|
|
1324
|
+
return this._planStatusCache.get(planId);
|
|
1325
|
+
}
|
|
1326
|
+
// Compute and cache
|
|
1327
|
+
const plan = this.getPlan(planId);
|
|
1328
|
+
if (!plan)
|
|
1329
|
+
return null;
|
|
1330
|
+
const stagings = this.getStagingsByPlan(planId);
|
|
1331
|
+
let totalTasks = 0;
|
|
1332
|
+
let completedTasks = 0;
|
|
1333
|
+
let completedStagingCount = 0;
|
|
1334
|
+
for (const staging of stagings) {
|
|
1335
|
+
if (staging.status === "completed") {
|
|
1336
|
+
completedStagingCount++;
|
|
1337
|
+
}
|
|
1338
|
+
const tasks = this.getTasksByStaging(staging.id);
|
|
1339
|
+
totalTasks += tasks.length;
|
|
1340
|
+
completedTasks += tasks.filter(t => t.status === "done").length;
|
|
1341
|
+
}
|
|
1342
|
+
const cache = {
|
|
1343
|
+
totalTasks,
|
|
1344
|
+
completedTasks,
|
|
1345
|
+
stagingCount: stagings.length,
|
|
1346
|
+
completedStagingCount,
|
|
1347
|
+
};
|
|
1348
|
+
this._planStatusCache.set(planId, cache);
|
|
1349
|
+
return cache;
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Check if status cache is valid
|
|
1353
|
+
*/
|
|
1354
|
+
isStatusCacheValid() {
|
|
1355
|
+
return this._statusCacheValid;
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Mark status cache as valid (after full rebuild)
|
|
1359
|
+
*/
|
|
1360
|
+
markStatusCacheValid() {
|
|
1361
|
+
this._statusCacheValid = true;
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* Clear all caches
|
|
1365
|
+
*/
|
|
1366
|
+
clearAllCaches() {
|
|
1367
|
+
this._planStatusCache.clear();
|
|
1368
|
+
this._statusCacheValid = false;
|
|
1369
|
+
}
|
|
1104
1370
|
}
|
|
1105
1371
|
export { idGenerator };
|
|
1106
1372
|
//# sourceMappingURL=manager.js.map
|