@dreki-gg/pi-plan-mode 0.26.0 → 0.26.1
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/CHANGELOG.md +12 -0
- package/extensions/plan-mode/__tests__/initiative-status.test.ts +5 -5
- package/extensions/plan-mode/__tests__/plan-references-context.test.ts +4 -4
- package/extensions/plan-mode/__tests__/reconcile-plans.test.ts +3 -3
- package/extensions/plan-mode/__tests__/resolve-plan.test.ts +4 -4
- package/extensions/plan-mode/__tests__/revise-plan.test.ts +4 -4
- package/extensions/plan-mode/__tests__/submit-initiative.test.ts +2 -2
- package/extensions/plan-mode/__tests__/submit-plan.test.ts +3 -3
- package/extensions/plan-mode/__tests__/update-initiative.test.ts +2 -2
- package/extensions/plan-mode/__tests__/update-plan.test.ts +2 -2
- package/extensions/plan-mode/__tests__/utils.test.ts +2 -1
- package/extensions/plan-mode/commands/list-initiatives.ts +19 -109
- package/extensions/plan-mode/commands/list-plans.ts +21 -168
- package/extensions/plan-mode/exec-pending.ts +59 -0
- package/extensions/plan-mode/index.ts +8 -7
- package/extensions/plan-mode/references/context.ts +5 -5
- package/extensions/plan-mode/references/plan-index.ts +1 -1
- package/extensions/plan-mode/resolve-plan.ts +4 -4
- package/extensions/plan-mode/resume.ts +6 -5
- package/extensions/plan-mode/tools/add-task.ts +1 -1
- package/extensions/plan-mode/tools/initiative-status.ts +6 -6
- package/extensions/plan-mode/tools/preview-prototype.ts +3 -3
- package/extensions/plan-mode/tools/reconcile-plans.ts +2 -2
- package/extensions/plan-mode/tools/revise-plan.ts +7 -7
- package/extensions/plan-mode/tools/submit-initiative.ts +4 -4
- package/extensions/plan-mode/tools/submit-plan.ts +7 -7
- package/extensions/plan-mode/tools/update-initiative.ts +2 -2
- package/extensions/plan-mode/tools/update-plan.ts +3 -3
- package/extensions/plan-mode/types.ts +17 -59
- package/extensions/plan-mode/utils.ts +2 -29
- package/package.json +2 -1
- package/extensions/plan-mode/__tests__/atomic-write.test.ts +0 -45
- package/extensions/plan-mode/__tests__/concurrent-writes.test.ts +0 -85
- package/extensions/plan-mode/__tests__/initiative-readiness.test.ts +0 -159
- package/extensions/plan-mode/__tests__/initiatives-manifest.test.ts +0 -89
- package/extensions/plan-mode/__tests__/list-initiatives.test.ts +0 -59
- package/extensions/plan-mode/__tests__/list-plans.test.ts +0 -253
- package/extensions/plan-mode/__tests__/plan-storage.test.ts +0 -57
- package/extensions/plan-mode/__tests__/plans-manifest.test.ts +0 -120
- package/extensions/plan-mode/__tests__/reconcile.test.ts +0 -188
- package/extensions/plan-mode/__tests__/schema.test.ts +0 -334
- package/extensions/plan-mode/__tests__/task-status.test.ts +0 -74
- package/extensions/plan-mode/__tests__/task-storage.test.ts +0 -101
- package/extensions/plan-mode/effects/filesystem.ts +0 -65
- package/extensions/plan-mode/effects/runtime.ts +0 -24
- package/extensions/plan-mode/errors.ts +0 -105
- package/extensions/plan-mode/initiative.ts +0 -172
- package/extensions/plan-mode/plan-storage.ts +0 -6
- package/extensions/plan-mode/reconcile.ts +0 -235
- package/extensions/plan-mode/schema.ts +0 -99
- package/extensions/plan-mode/storage/atomic-write.ts +0 -75
- package/extensions/plan-mode/storage/file-lock.ts +0 -49
- package/extensions/plan-mode/storage/initiatives-manifest.ts +0 -154
- package/extensions/plan-mode/storage/plan-storage.ts +0 -88
- package/extensions/plan-mode/storage/plans-manifest.ts +0 -174
- package/extensions/plan-mode/storage/task-storage.ts +0 -111
- package/extensions/plan-mode/task-status.ts +0 -46
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
2
|
-
import { Effect } from 'effect';
|
|
3
|
-
import { chdir } from 'node:process';
|
|
4
|
-
import { mkdtemp, rm } from 'node:fs/promises';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
import { tmpdir } from 'node:os';
|
|
7
|
-
import { FileSystem, nodeFileSystemService } from '../effects/filesystem.js';
|
|
8
|
-
import {
|
|
9
|
-
readInitiativesManifest,
|
|
10
|
-
upsertInitiativeEntry,
|
|
11
|
-
writeInitiativesManifest,
|
|
12
|
-
} from '../storage/initiatives-manifest.js';
|
|
13
|
-
|
|
14
|
-
const run = <A, E>(program: Effect.Effect<A, E, FileSystem>): Promise<A> =>
|
|
15
|
-
Effect.runPromise(program.pipe(Effect.provideService(FileSystem, nodeFileSystemService)));
|
|
16
|
-
|
|
17
|
-
const originalCwd = process.cwd();
|
|
18
|
-
let dir: string;
|
|
19
|
-
|
|
20
|
-
beforeEach(async () => {
|
|
21
|
-
dir = await mkdtemp(join(tmpdir(), 'plan-mode-initiatives-'));
|
|
22
|
-
chdir(dir);
|
|
23
|
-
});
|
|
24
|
-
afterEach(async () => {
|
|
25
|
-
chdir(originalCwd);
|
|
26
|
-
await rm(dir, { recursive: true, force: true });
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('initiatives.jsonl manifest', () => {
|
|
30
|
-
test('round trips entries', async () => {
|
|
31
|
-
const entry = {
|
|
32
|
-
_type: 'initiative' as const,
|
|
33
|
-
name: 'auth-overhaul',
|
|
34
|
-
status: 'in-progress' as const,
|
|
35
|
-
title: 'Auth Overhaul',
|
|
36
|
-
created_at: 'now',
|
|
37
|
-
completed_at: null,
|
|
38
|
-
};
|
|
39
|
-
await run(writeInitiativesManifest([entry]));
|
|
40
|
-
await expect(run(readInitiativesManifest())).resolves.toEqual([entry]);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('missing manifest returns an empty list', async () => {
|
|
44
|
-
await expect(run(readInitiativesManifest())).resolves.toEqual([]);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('upserts new entries', async () => {
|
|
48
|
-
await run(upsertInitiativeEntry('big-thing', { status: 'in-progress', title: 'Big Thing' }));
|
|
49
|
-
const entries = await run(readInitiativesManifest());
|
|
50
|
-
expect(entries).toHaveLength(1);
|
|
51
|
-
expect(entries[0]?.name).toBe('big-thing');
|
|
52
|
-
expect(entries[0]?.title).toBe('Big Thing');
|
|
53
|
-
expect(entries[0]?.completed_at).toBeNull();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('upserts existing entries without changing created_at', async () => {
|
|
57
|
-
await run(
|
|
58
|
-
writeInitiativesManifest([
|
|
59
|
-
{
|
|
60
|
-
_type: 'initiative',
|
|
61
|
-
name: 'i',
|
|
62
|
-
status: 'in-progress',
|
|
63
|
-
title: 'Old',
|
|
64
|
-
created_at: 'created',
|
|
65
|
-
completed_at: null,
|
|
66
|
-
},
|
|
67
|
-
]),
|
|
68
|
-
);
|
|
69
|
-
await run(upsertInitiativeEntry('i', { status: 'done', title: 'New' }));
|
|
70
|
-
const [entry] = await run(readInitiativesManifest());
|
|
71
|
-
expect(entry.created_at).toBe('created');
|
|
72
|
-
expect(entry.status).toBe('done');
|
|
73
|
-
expect(entry.completed_at).toBeString();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test('records a reason for terminal statuses and clears completed_at on reopen', async () => {
|
|
77
|
-
await run(upsertInitiativeEntry('i', { status: 'in-progress', title: 'I' }));
|
|
78
|
-
await run(upsertInitiativeEntry('i', { status: 'superseded', reason: 'merged into j' }));
|
|
79
|
-
let [entry] = await run(readInitiativesManifest());
|
|
80
|
-
expect(entry.status).toBe('superseded');
|
|
81
|
-
expect(entry.reason).toBe('merged into j');
|
|
82
|
-
expect(entry.completed_at).toBeString();
|
|
83
|
-
|
|
84
|
-
await run(upsertInitiativeEntry('i', { status: 'in-progress' }));
|
|
85
|
-
[entry] = await run(readInitiativesManifest());
|
|
86
|
-
expect(entry.status).toBe('in-progress');
|
|
87
|
-
expect(entry.completed_at).toBeNull();
|
|
88
|
-
});
|
|
89
|
-
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
2
|
-
import { chdir } from 'node:process';
|
|
3
|
-
import { mkdtemp, rm } from 'node:fs/promises';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { tmpdir } from 'node:os';
|
|
6
|
-
import { makePlanRuntime } from '../effects/runtime.js';
|
|
7
|
-
import { upsertPlanEntry } from '../storage/plans-manifest.js';
|
|
8
|
-
import { upsertInitiativeEntry } from '../storage/initiatives-manifest.js';
|
|
9
|
-
import {
|
|
10
|
-
filterInitiatives,
|
|
11
|
-
formatInitiativeList,
|
|
12
|
-
loadInitiativeListItems,
|
|
13
|
-
parseFilter,
|
|
14
|
-
} from '../commands/list-initiatives.js';
|
|
15
|
-
|
|
16
|
-
const runPlanIO = makePlanRuntime();
|
|
17
|
-
|
|
18
|
-
const originalCwd = process.cwd();
|
|
19
|
-
let dir: string;
|
|
20
|
-
beforeEach(async () => {
|
|
21
|
-
dir = await mkdtemp(join(tmpdir(), 'plan-mode-list-init-'));
|
|
22
|
-
chdir(dir);
|
|
23
|
-
});
|
|
24
|
-
afterEach(async () => {
|
|
25
|
-
chdir(originalCwd);
|
|
26
|
-
await rm(dir, { recursive: true, force: true });
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('list-initiatives', () => {
|
|
30
|
-
test('parseFilter maps aliases', () => {
|
|
31
|
-
expect(parseFilter('done')).toBe('done');
|
|
32
|
-
expect(parseFilter('active')).toBe('in-progress');
|
|
33
|
-
expect(parseFilter('whatever')).toBe('all');
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('rolls up member-plan progress and readiness', async () => {
|
|
37
|
-
await runPlanIO(upsertInitiativeEntry('big', { status: 'in-progress', title: 'Big' }));
|
|
38
|
-
await runPlanIO(upsertPlanEntry('a', { status: 'done', title: 'A', initiative: 'big' }));
|
|
39
|
-
await runPlanIO(
|
|
40
|
-
upsertPlanEntry('b', { status: 'in-progress', title: 'B', initiative: 'big', depends_on: ['a'] }),
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const items = await runPlanIO(loadInitiativeListItems());
|
|
44
|
-
expect(items).toHaveLength(1);
|
|
45
|
-
expect(items[0]?.totalPlans).toBe(2);
|
|
46
|
-
expect(items[0]?.donePlans).toBe(1);
|
|
47
|
-
expect(items[0]?.ready).toBe(1); // b unblocked (a done)
|
|
48
|
-
|
|
49
|
-
const text = formatInitiativeList(items, 'all');
|
|
50
|
-
expect(text).toMatch(/big — Big \[1\/2 plans, ready 1, blocked 0\]/);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('filterInitiatives narrows by status', async () => {
|
|
54
|
-
await runPlanIO(upsertInitiativeEntry('x', { status: 'in-progress', title: 'X' }));
|
|
55
|
-
await runPlanIO(upsertInitiativeEntry('y', { status: 'done', title: 'Y' }));
|
|
56
|
-
const items = await runPlanIO(loadInitiativeListItems());
|
|
57
|
-
expect(filterInitiatives(items, 'done').map((i) => i.name)).toEqual(['y']);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
2
|
-
import { chdir } from 'node:process';
|
|
3
|
-
import { mkdtemp, rm } from 'node:fs/promises';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { tmpdir } from 'node:os';
|
|
6
|
-
import { makePlanRuntime } from '../effects/runtime.js';
|
|
7
|
-
import { upsertPlanEntry } from '../storage/plans-manifest.js';
|
|
8
|
-
import { writeTasksJsonl } from '../storage/task-storage.js';
|
|
9
|
-
import type { TaskMeta, TaskRecord, PlanStatus } from '../types.js';
|
|
10
|
-
import {
|
|
11
|
-
filterPlans,
|
|
12
|
-
sortPlans,
|
|
13
|
-
formatPlanList,
|
|
14
|
-
parseArgs,
|
|
15
|
-
loadPlanListItems,
|
|
16
|
-
type PlanListItem,
|
|
17
|
-
type SortField,
|
|
18
|
-
type StatusFilter,
|
|
19
|
-
} from '../commands/list-plans.js';
|
|
20
|
-
|
|
21
|
-
const runPlanIO = makePlanRuntime();
|
|
22
|
-
const originalCwd = process.cwd();
|
|
23
|
-
let dir: string;
|
|
24
|
-
|
|
25
|
-
beforeEach(async () => {
|
|
26
|
-
dir = await mkdtemp(join(tmpdir(), 'plan-mode-list-'));
|
|
27
|
-
chdir(dir);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
afterEach(async () => {
|
|
31
|
-
chdir(originalCwd);
|
|
32
|
-
await rm(dir, { recursive: true, force: true });
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
36
|
-
|
|
37
|
-
const meta = (name: string): TaskMeta => ({
|
|
38
|
-
_type: 'meta',
|
|
39
|
-
title: `Title ${name}`,
|
|
40
|
-
plan_name: name,
|
|
41
|
-
created_at: '2026-01-01T00:00:00.000Z',
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const task = (id: string, status: 'done' | 'pending' = 'done'): TaskRecord => ({
|
|
45
|
-
_type: 'task',
|
|
46
|
-
id,
|
|
47
|
-
description: `task ${id}`,
|
|
48
|
-
status,
|
|
49
|
-
origin: 'plan',
|
|
50
|
-
created_at: '2026-01-01T00:00:00.000Z',
|
|
51
|
-
updated_at: '2026-01-01T00:00:00.000Z',
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
function makePlanItem(overrides: Partial<PlanListItem> & { name: string }): PlanListItem {
|
|
55
|
-
return {
|
|
56
|
-
title: `Title ${overrides.name}`,
|
|
57
|
-
status: 'in-progress',
|
|
58
|
-
created_at: '2026-01-01T00:00:00.000Z',
|
|
59
|
-
completed_at: null,
|
|
60
|
-
totalTasks: 3,
|
|
61
|
-
doneTasks: 1,
|
|
62
|
-
pendingTasks: 2,
|
|
63
|
-
...overrides,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// ── filterPlans ──────────────────────────────────────────────────────────────
|
|
68
|
-
|
|
69
|
-
describe('filterPlans', () => {
|
|
70
|
-
const plans: PlanListItem[] = [
|
|
71
|
-
makePlanItem({ name: 'alpha', status: 'in-progress' }),
|
|
72
|
-
makePlanItem({ name: 'beta', status: 'done' }),
|
|
73
|
-
makePlanItem({ name: 'gamma', status: 'abandoned' }),
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
test('returns all when filter is "all"', () => {
|
|
77
|
-
expect(filterPlans(plans, 'all')).toHaveLength(3);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('filters by in-progress', () => {
|
|
81
|
-
const result = filterPlans(plans, 'in-progress');
|
|
82
|
-
expect(result).toHaveLength(1);
|
|
83
|
-
expect(result[0].name).toBe('alpha');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('filters by done', () => {
|
|
87
|
-
const result = filterPlans(plans, 'done');
|
|
88
|
-
expect(result).toHaveLength(1);
|
|
89
|
-
expect(result[0].name).toBe('beta');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('filters by abandoned', () => {
|
|
93
|
-
const result = filterPlans(plans, 'abandoned');
|
|
94
|
-
expect(result).toHaveLength(1);
|
|
95
|
-
expect(result[0].name).toBe('gamma');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test('returns empty when no match', () => {
|
|
99
|
-
expect(filterPlans(plans, 'superseded')).toHaveLength(0);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// ── sortPlans ────────────────────────────────────────────────────────────────
|
|
104
|
-
|
|
105
|
-
describe('sortPlans', () => {
|
|
106
|
-
const plans: PlanListItem[] = [
|
|
107
|
-
makePlanItem({ name: 'charlie', created_at: '2026-03-01T00:00:00.000Z', totalTasks: 2 }),
|
|
108
|
-
makePlanItem({ name: 'alpha', created_at: '2026-01-01T00:00:00.000Z', totalTasks: 5 }),
|
|
109
|
-
makePlanItem({ name: 'bravo', created_at: '2026-02-01T00:00:00.000Z', totalTasks: 1 }),
|
|
110
|
-
];
|
|
111
|
-
|
|
112
|
-
test('sorts by name', () => {
|
|
113
|
-
const result = sortPlans(plans, 'name');
|
|
114
|
-
expect(result.map((p) => p.name)).toEqual(['alpha', 'bravo', 'charlie']);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test('sorts by date ascending (oldest first)', () => {
|
|
118
|
-
const result = sortPlans(plans, 'date-asc');
|
|
119
|
-
expect(result.map((p) => p.name)).toEqual(['alpha', 'bravo', 'charlie']);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test('sorts by date descending (newest first)', () => {
|
|
123
|
-
const result = sortPlans(plans, 'date-desc');
|
|
124
|
-
expect(result.map((p) => p.name)).toEqual(['charlie', 'bravo', 'alpha']);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test('sorts by task count (most tasks first)', () => {
|
|
128
|
-
const result = sortPlans(plans, 'tasks');
|
|
129
|
-
expect(result.map((p) => p.name)).toEqual(['alpha', 'charlie', 'bravo']);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test('does not mutate the original array', () => {
|
|
133
|
-
const original = [...plans];
|
|
134
|
-
sortPlans(plans, 'name');
|
|
135
|
-
expect(plans.map((p) => p.name)).toEqual(original.map((p) => p.name));
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// ── formatPlanList ───────────────────────────────────────────────────────────
|
|
140
|
-
|
|
141
|
-
describe('formatPlanList', () => {
|
|
142
|
-
test('shows message when empty and filter is all', () => {
|
|
143
|
-
expect(formatPlanList([], 'all', 'date-desc')).toContain('No plans found');
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test('shows filter-specific message when empty', () => {
|
|
147
|
-
expect(formatPlanList([], 'done', 'date-desc')).toContain('No plans with status "done"');
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
test('includes plan details in output', () => {
|
|
151
|
-
const plans = [makePlanItem({ name: 'alpha', title: 'Alpha Plan', totalTasks: 5, doneTasks: 3 })];
|
|
152
|
-
const output = formatPlanList(plans, 'all', 'date-desc');
|
|
153
|
-
expect(output).toContain('alpha');
|
|
154
|
-
expect(output).toContain('Alpha Plan');
|
|
155
|
-
expect(output).toContain('3/5 tasks');
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
test('shows header with count and sort', () => {
|
|
159
|
-
const plans = [makePlanItem({ name: 'a' }), makePlanItem({ name: 'b' })];
|
|
160
|
-
const output = formatPlanList(plans, 'all', 'tasks');
|
|
161
|
-
expect(output).toContain('All plans (2)');
|
|
162
|
-
expect(output).toContain('most tasks first');
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
// ── parseArgs ────────────────────────────────────────────────────────────────
|
|
167
|
-
|
|
168
|
-
describe('parseArgs', () => {
|
|
169
|
-
test('parses filter only', () => {
|
|
170
|
-
expect(parseArgs('done')).toEqual({ filter: 'done', sort: 'date-desc' });
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
test('parses sort only', () => {
|
|
174
|
-
expect(parseArgs('oldest')).toEqual({ filter: 'all', sort: 'date-asc' });
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
test('parses filter and sort together', () => {
|
|
178
|
-
expect(parseArgs('in-progress tasks')).toEqual({ filter: 'in-progress', sort: 'tasks' });
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
test('accepts aliases', () => {
|
|
182
|
-
expect(parseArgs('pending newest')).toEqual({ filter: 'in-progress', sort: 'date-desc' });
|
|
183
|
-
expect(parseArgs('active oldest')).toEqual({ filter: 'in-progress', sort: 'date-asc' });
|
|
184
|
-
expect(parseArgs('completed name')).toEqual({ filter: 'done', sort: 'name' });
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
test('defaults to all + date-desc for unknown tokens', () => {
|
|
188
|
-
expect(parseArgs('unknown gibberish')).toEqual({ filter: 'all', sort: 'date-desc' });
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
test('is case-insensitive', () => {
|
|
192
|
-
expect(parseArgs('DONE TASKS')).toEqual({ filter: 'done', sort: 'tasks' });
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
// ── loadPlanListItems (integration) ──────────────────────────────────────────
|
|
197
|
-
|
|
198
|
-
describe('loadPlanListItems', () => {
|
|
199
|
-
test('returns empty for no plans', async () => {
|
|
200
|
-
const items = await runPlanIO(loadPlanListItems());
|
|
201
|
-
expect(items).toEqual([]);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
test('loads plans with task counts', async () => {
|
|
205
|
-
await runPlanIO(upsertPlanEntry('alpha', { status: 'in-progress', title: 'Alpha' }));
|
|
206
|
-
await runPlanIO(
|
|
207
|
-
writeTasksJsonl('.plans/alpha', meta('alpha'), [
|
|
208
|
-
task('t-001', 'done'),
|
|
209
|
-
task('t-002', 'pending'),
|
|
210
|
-
task('t-003', 'pending'),
|
|
211
|
-
]),
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
const items = await runPlanIO(loadPlanListItems());
|
|
215
|
-
expect(items).toHaveLength(1);
|
|
216
|
-
expect(items[0].name).toBe('alpha');
|
|
217
|
-
expect(items[0].totalTasks).toBe(3);
|
|
218
|
-
expect(items[0].doneTasks).toBe(1);
|
|
219
|
-
expect(items[0].pendingTasks).toBe(2);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
test('handles plans without task files', async () => {
|
|
223
|
-
await runPlanIO(upsertPlanEntry('orphan', { status: 'in-progress', title: 'Orphan' }));
|
|
224
|
-
|
|
225
|
-
const items = await runPlanIO(loadPlanListItems());
|
|
226
|
-
expect(items).toHaveLength(1);
|
|
227
|
-
expect(items[0].totalTasks).toBe(0);
|
|
228
|
-
expect(items[0].doneTasks).toBe(0);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
test('loads multiple plans', async () => {
|
|
232
|
-
await runPlanIO(upsertPlanEntry('alpha', { status: 'in-progress', title: 'Alpha' }));
|
|
233
|
-
await runPlanIO(upsertPlanEntry('beta', { status: 'done', title: 'Beta' }));
|
|
234
|
-
await runPlanIO(
|
|
235
|
-
writeTasksJsonl('.plans/alpha', meta('alpha'), [task('t-001', 'pending')]),
|
|
236
|
-
);
|
|
237
|
-
await runPlanIO(
|
|
238
|
-
writeTasksJsonl('.plans/beta', meta('beta'), [task('t-001', 'done'), task('t-002', 'done')]),
|
|
239
|
-
);
|
|
240
|
-
|
|
241
|
-
const items = await runPlanIO(loadPlanListItems());
|
|
242
|
-
expect(items).toHaveLength(2);
|
|
243
|
-
|
|
244
|
-
const alpha = items.find((i) => i.name === 'alpha')!;
|
|
245
|
-
expect(alpha.status).toBe('in-progress');
|
|
246
|
-
expect(alpha.totalTasks).toBe(1);
|
|
247
|
-
|
|
248
|
-
const beta = items.find((i) => i.name === 'beta')!;
|
|
249
|
-
expect(beta.status).toBe('done');
|
|
250
|
-
expect(beta.totalTasks).toBe(2);
|
|
251
|
-
expect(beta.doneTasks).toBe(2);
|
|
252
|
-
});
|
|
253
|
-
});
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
2
|
-
import { Effect } from 'effect';
|
|
3
|
-
import { chdir } from 'node:process';
|
|
4
|
-
import { mkdtemp, rm } from 'node:fs/promises';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
import { tmpdir } from 'node:os';
|
|
7
|
-
import { FileSystem, nodeFileSystemService } from '../effects/filesystem.js';
|
|
8
|
-
import {
|
|
9
|
-
loadHandoff,
|
|
10
|
-
readAndClearExecPending,
|
|
11
|
-
saveHandoff,
|
|
12
|
-
writeExecPending,
|
|
13
|
-
} from '../storage/plan-storage.js';
|
|
14
|
-
import type { ExecPendingConfig } from '../types.js';
|
|
15
|
-
|
|
16
|
-
const run = <A, E>(program: Effect.Effect<A, E, FileSystem>): Promise<A> =>
|
|
17
|
-
Effect.runPromise(program.pipe(Effect.provideService(FileSystem, nodeFileSystemService)));
|
|
18
|
-
|
|
19
|
-
const originalCwd = process.cwd();
|
|
20
|
-
let dir: string;
|
|
21
|
-
const config: ExecPendingConfig = { model: { provider: 'anthropic', id: 'opus' }, thinking: 'low' };
|
|
22
|
-
|
|
23
|
-
beforeEach(async () => {
|
|
24
|
-
dir = await mkdtemp(join(tmpdir(), 'plan-mode-plan-'));
|
|
25
|
-
chdir(dir);
|
|
26
|
-
});
|
|
27
|
-
afterEach(async () => {
|
|
28
|
-
chdir(originalCwd);
|
|
29
|
-
await rm(dir, { recursive: true, force: true });
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('handoff documents', () => {
|
|
33
|
-
test('round trips handoff content', async () => {
|
|
34
|
-
await run(saveHandoff('.plans/p', '# Handoff'));
|
|
35
|
-
await expect(run(loadHandoff('.plans/p'))).resolves.toBe('# Handoff');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('missing handoff returns undefined', async () => {
|
|
39
|
-
await expect(run(loadHandoff('.plans/missing'))).resolves.toBeUndefined();
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe('exec-pending markers', () => {
|
|
44
|
-
test('writes, reads, and clears a marker', async () => {
|
|
45
|
-
await run(writeExecPending('.plans/p', config));
|
|
46
|
-
const first = await run(readAndClearExecPending());
|
|
47
|
-
expect(first?.planDir).toBe('.plans/p');
|
|
48
|
-
expect(first?.config).toEqual(config);
|
|
49
|
-
|
|
50
|
-
// Marker is cleared after reading.
|
|
51
|
-
await expect(run(readAndClearExecPending())).resolves.toBeUndefined();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('returns undefined when .plans does not exist', async () => {
|
|
55
|
-
await expect(run(readAndClearExecPending())).resolves.toBeUndefined();
|
|
56
|
-
});
|
|
57
|
-
});
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
2
|
-
import { Effect } from 'effect';
|
|
3
|
-
import { chdir } from 'node:process';
|
|
4
|
-
import { mkdtemp, rm } from 'node:fs/promises';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
import { tmpdir } from 'node:os';
|
|
7
|
-
import { FileSystem, nodeFileSystemService } from '../effects/filesystem.js';
|
|
8
|
-
import {
|
|
9
|
-
readPlansManifest,
|
|
10
|
-
reconcilePlanStatus,
|
|
11
|
-
upsertPlanEntry,
|
|
12
|
-
writePlansManifest,
|
|
13
|
-
} from '../storage/plans-manifest.js';
|
|
14
|
-
|
|
15
|
-
const run = <A, E>(program: Effect.Effect<A, E, FileSystem>): Promise<A> =>
|
|
16
|
-
Effect.runPromise(program.pipe(Effect.provideService(FileSystem, nodeFileSystemService)));
|
|
17
|
-
|
|
18
|
-
const originalCwd = process.cwd();
|
|
19
|
-
let dir: string;
|
|
20
|
-
|
|
21
|
-
beforeEach(async () => {
|
|
22
|
-
dir = await mkdtemp(join(tmpdir(), 'plan-mode-manifest-'));
|
|
23
|
-
chdir(dir);
|
|
24
|
-
});
|
|
25
|
-
afterEach(async () => {
|
|
26
|
-
chdir(originalCwd);
|
|
27
|
-
await rm(dir, { recursive: true, force: true });
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('plans.jsonl manifest', () => {
|
|
31
|
-
test('round trips entries', async () => {
|
|
32
|
-
const entry = {
|
|
33
|
-
_type: 'plan' as const,
|
|
34
|
-
name: 'refactor',
|
|
35
|
-
status: 'in-progress' as const,
|
|
36
|
-
title: 'Refactor',
|
|
37
|
-
created_at: 'now',
|
|
38
|
-
completed_at: null,
|
|
39
|
-
};
|
|
40
|
-
await run(writePlansManifest([entry]));
|
|
41
|
-
await expect(run(readPlansManifest())).resolves.toEqual([entry]);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('missing manifest returns an empty list', async () => {
|
|
45
|
-
await expect(run(readPlansManifest())).resolves.toEqual([]);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('upserts new entries', async () => {
|
|
49
|
-
await run(upsertPlanEntry('new-plan', { status: 'in-progress', title: 'New Plan' }));
|
|
50
|
-
const entries = await run(readPlansManifest());
|
|
51
|
-
expect(entries).toHaveLength(1);
|
|
52
|
-
expect(entries[0]?.name).toBe('new-plan');
|
|
53
|
-
expect(entries[0]?.title).toBe('New Plan');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('upserts existing entries without changing created_at', async () => {
|
|
57
|
-
await run(
|
|
58
|
-
writePlansManifest([
|
|
59
|
-
{
|
|
60
|
-
_type: 'plan',
|
|
61
|
-
name: 'p',
|
|
62
|
-
status: 'in-progress',
|
|
63
|
-
title: 'Old',
|
|
64
|
-
created_at: 'created',
|
|
65
|
-
completed_at: null,
|
|
66
|
-
},
|
|
67
|
-
]),
|
|
68
|
-
);
|
|
69
|
-
await run(upsertPlanEntry('p', { status: 'done', title: 'New' }));
|
|
70
|
-
const [entry] = await run(readPlansManifest());
|
|
71
|
-
expect(entry.created_at).toBe('created');
|
|
72
|
-
expect(entry.status).toBe('done');
|
|
73
|
-
expect(entry.completed_at).toBeString();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test('records a reason for terminal statuses and clears completed_at on reopen', async () => {
|
|
77
|
-
await run(upsertPlanEntry('p', { status: 'in-progress', title: 'P' }));
|
|
78
|
-
await run(upsertPlanEntry('p', { status: 'superseded', reason: 'absorbed by q' }));
|
|
79
|
-
let [entry] = await run(readPlansManifest());
|
|
80
|
-
expect(entry.status).toBe('superseded');
|
|
81
|
-
expect(entry.reason).toBe('absorbed by q');
|
|
82
|
-
expect(entry.completed_at).toBeString();
|
|
83
|
-
|
|
84
|
-
// Reopening clears completed_at.
|
|
85
|
-
await run(upsertPlanEntry('p', { status: 'in-progress' }));
|
|
86
|
-
[entry] = await run(readPlansManifest());
|
|
87
|
-
expect(entry.status).toBe('in-progress');
|
|
88
|
-
expect(entry.completed_at).toBeNull();
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe('reconcilePlanStatus (registry as a projection of task state)', () => {
|
|
93
|
-
test('flips in-progress → done when finalizable', async () => {
|
|
94
|
-
await run(upsertPlanEntry('p', { status: 'in-progress', title: 'P' }));
|
|
95
|
-
await run(reconcilePlanStatus('p', true, 'P'));
|
|
96
|
-
const [entry] = await run(readPlansManifest());
|
|
97
|
-
expect(entry.status).toBe('done');
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('reopens done → in-progress when no longer finalizable', async () => {
|
|
101
|
-
await run(upsertPlanEntry('p', { status: 'done', title: 'P' }));
|
|
102
|
-
await run(reconcilePlanStatus('p', false, 'P'));
|
|
103
|
-
const [entry] = await run(readPlansManifest());
|
|
104
|
-
expect(entry.status).toBe('in-progress');
|
|
105
|
-
expect(entry.completed_at).toBeNull();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test('never overrides a manually-closed terminal status', async () => {
|
|
109
|
-
await run(upsertPlanEntry('p', { status: 'abandoned', title: 'P', reason: 'rejected' }));
|
|
110
|
-
await run(reconcilePlanStatus('p', true, 'P'));
|
|
111
|
-
const [entry] = await run(readPlansManifest());
|
|
112
|
-
expect(entry.status).toBe('abandoned');
|
|
113
|
-
expect(entry.reason).toBe('rejected');
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test('is a no-op for an unknown plan (nothing created)', async () => {
|
|
117
|
-
await run(reconcilePlanStatus('ghost', true));
|
|
118
|
-
await expect(run(readPlansManifest())).resolves.toEqual([]);
|
|
119
|
-
});
|
|
120
|
-
});
|