@howaboua/opencode-roadmap-plugin 0.1.5 → 0.1.7

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/README.md CHANGED
@@ -1,29 +1,100 @@
1
- # @howaboua/opencode-roadmap-plugin
1
+ # Opencode Roadmap Plugin
2
2
 
3
- Strategic roadmap planning and multi-agent coordination for OpenCode.
3
+ Persistent project roadmaps for OpenCode. Coordinates work across sessions and parallel Task tool subagents.
4
+
5
+ ## Why Use This?
6
+
7
+ OpenCode's built-in todo is session-scoped—it disappears when you restart. Task tool subagents are stateless—they can't see each other's work.
8
+
9
+ This plugin solves both:
10
+
11
+ - **Persists to disk** — survives restarts, available across sessions
12
+ - **Shared context** — subagents read the same roadmap to understand the bigger picture
13
+ - **Concurrent awareness** — agents see what's `in_progress` and avoid conflicts
14
+
15
+ ![opencode-roadmap](https://github.com/user-attachments/assets/e2479a72-ec65-457f-9503-bf2d01580c70)
4
16
 
5
17
  ## Installation
6
18
 
7
- Add to your repository `opencode.json` or user-level `~/.config/opencode/opencode.json`:
19
+ Add to your `opencode.json`:
8
20
 
9
21
  ```json
10
22
  {
11
- "plugin": ["@howaboua/opencode-roadmap-plugin"]
23
+ "plugin": ["@howaboua/opencode-roadmap-plugin@latest"]
12
24
  }
13
25
  ```
14
26
 
15
- ## How It Works
27
+ OpenCode installs it automatically on next launch.
28
+
29
+ ## Tools
30
+
31
+ ### `createroadmap`
32
+
33
+ Create or extend a project roadmap.
34
+
35
+ ```
36
+ "Create a roadmap for building user auth with login, signup, and password reset"
37
+ ```
38
+
39
+ - Features group related work (`"1"`, `"2"`, `"3"`)
40
+ - Actions are concrete tasks (`"1.01"`, `"1.02"`) within features
41
+ - New actions always start as `pending`
42
+ - Append-only: existing IDs never change
43
+
44
+ ### `readroadmap`
45
+
46
+ View current state and progress.
47
+
48
+ ```
49
+ "Show me the roadmap"
50
+ "What's the status of feature 2?"
51
+ ```
52
+
53
+ Before delegating work to Task tool subagents, instruct them to read the roadmap first so they understand their assigned action within the broader plan.
16
54
 
17
- - `createroadmap`: create or append features/actions while keeping IDs immutable.
18
- - `updateroadmap`: advance action status forward only (`pending` → `in_progress` → `completed`), optional description update.
19
- - `readroadmap`: summarize roadmap, optionally filtered by feature/action.
20
- - Storage: JSON on disk with auto-archive when all actions complete.
21
- - Validation: Zod schemas enforce shape; errors surface readable templates.
55
+ ### `updateroadmap`
22
56
 
23
- ## Development
57
+ Change action status or description.
24
58
 
25
- ```bash
26
- npm run build # Emit dist/ (ESM + d.ts)
27
59
  ```
60
+ "Mark action 1.01 as in_progress"
61
+ "Action 2.03 is completed"
62
+ ```
63
+
64
+ **Statuses:** `pending` → `in_progress` → `completed` | `cancelled`
65
+
66
+ Transitions are flexible—you can revert if plans change. Only `cancelled` is terminal.
67
+
68
+ Auto-archives the roadmap when all actions reach `completed`.
69
+
70
+ ## Coordinating Parallel Work
71
+
72
+ When multiple subagents work simultaneously:
73
+
74
+ 1. Each reads the roadmap to see what's `in_progress`
75
+ 2. Agents stay focused on their assigned action only
76
+ 3. They avoid modifying files that belong to another `in_progress` action
77
+ 4. Errors outside their scope get noted, not fixed
78
+
79
+ This prevents conflicts when subagents run in parallel.
80
+
81
+ ## Workflow Example
82
+
83
+ ```
84
+ You: "Plan out building a REST API with auth, users, and posts endpoints"
85
+
86
+ AI: Creates roadmap with 3 features, ~12 actions
87
+
88
+ You: "Implement feature 1"
89
+
90
+ AI: Reads roadmap → sees Feature 1 has 4 actions → uses todowrite for immediate steps → delegates to subagents → each subagent reads roadmap first → updates status when done
91
+ ```
92
+
93
+ ## Storage
94
+
95
+ - **Active:** `roadmap.json` in project root
96
+ - **Archived:** `roadmap.archive.<timestamp>.json` when complete
97
+
98
+ ## License
28
99
 
29
- See `AGENTS.md` for coding standards.
100
+ MIT
@@ -1,20 +1,24 @@
1
- Initialize or append to project roadmap. Supports adding new features and actions.
1
+ Establish a durable project roadmap saved to disk. Provides shared context across sessions and Task tool subagents.
2
2
 
3
- Constraints:
4
- 1. Descriptions: MUST be detailed, clear, and actionable (unlike the minimal example below).
5
- 2. Append-only: New IDs must follow sequence (Feature 1->2, Action 1.01->1.02).
6
- 3. ID Format: Feature "1", Action "1.01".
7
- 4. Validation: Action prefix MUST match Feature (Action "1.01" belongs to Feature "1").
8
- 5. Status: Must be "pending".
3
+ Use when:
4
+ - User says "roadmap", "plan the project", "phases", or "milestones"
5
+ - Work will be delegated to Task tool subagents that need shared context
6
+ - Deliverables group naturally into distinct features
7
+
8
+ When launching Task tool subagents, instruct them to call readroadmap first to understand their work within the broader plan.
9
+
10
+ Structure: Features contain Actions. IDs are immutable once created.
11
+
12
+ Format:
13
+ - Feature: number "1", "2", title, description
14
+ - Action: number "1.01", "1.02" (prefix matches parent feature), description, status "pending"
9
15
 
10
16
  Example:
11
17
  {
12
- "features": [
13
- {
14
- "number": "1", "title": "Auth", "description": "User authentication system setup",
15
- "actions": [
16
- { "number": "1.01", "description": "Initialize PostgreSQL database schema with users table and indexes", "status": "pending" }
17
- ]
18
- }
19
- ]
20
- }
18
+ "features": [{
19
+ "number": "1", "title": "Auth", "description": "User authentication system",
20
+ "actions": [
21
+ { "number": "1.01", "description": "Design JWT token flow and refresh strategy", "status": "pending" }
22
+ ]
23
+ }]
24
+ }
@@ -1,7 +1,13 @@
1
+ /**
2
+ * Loads tool description text files from the descriptions directory.
3
+ * ESM-compatible using import.meta.url for path resolution.
4
+ */
1
5
  import { promises as fs } from "fs";
2
- import { join } from "path";
6
+ import { dirname, join } from "path";
7
+ import { fileURLToPath } from "url";
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
3
10
  export async function loadDescription(filename) {
4
- // Assets are colocated with the compiled loader (copied into dist/src/descriptions).
5
11
  const filePath = join(__dirname, filename);
6
12
  try {
7
13
  return await fs.readFile(filePath, "utf-8");
@@ -1,2 +1,19 @@
1
- Retrieve current roadmap state, progress, and details.
2
- Filter: Provide 'featureNumber' or 'actionNumber' for specific details, or omit to read entire roadmap.
1
+ Load the persisted roadmap from disk to understand project state.
2
+
3
+ When to use:
4
+ 1. Before starting a major feature - read roadmap first, then plan immediate steps with todowrite
5
+ 2. When launching Task tool subagents - instruct them to call readroadmap to understand their assigned work
6
+ 3. To check overall progress across features
7
+
8
+ Concurrent work awareness:
9
+ - Actions marked "in_progress" may have another agent actively working on them
10
+ - Stay focused on YOUR assigned action only - do not fix unrelated codebase errors
11
+ - Avoid modifying files that belong to another in_progress action
12
+ - If you encounter errors in code outside your scope, note them but do not fix
13
+
14
+ Returns: feature list, action statuses, completion percentages.
15
+
16
+ Filter options:
17
+ - featureNumber: show one feature and its actions
18
+ - actionNumber: show one action's details
19
+ - (omit both): full roadmap overview
@@ -1,8 +1,10 @@
1
- Update action status or description.
1
+ Advance action state within the persisted roadmap.
2
2
 
3
- Constraints:
4
- 1. Forward-only status: pending in_progress completed.
5
- 2. Immutable IDs: Cannot change action numbers or move actions.
6
- 3. Side Effect: Automatically archives roadmap file when ALL actions are completed.
3
+ Statuses: pending, in_progress, completed, cancelled
4
+ Transitions: Flexible (can revert if needed), except cancelled is terminal.
7
5
 
8
- Input: actionNumber (required), status (optional), description (optional).
6
+ Update after completing work on an action. When delegating to Task tool subagents, instruct them to call updateroadmap when they finish their assigned action.
7
+
8
+ Archives roadmap automatically when all actions reach completed.
9
+
10
+ Input: actionNumber (required), status (optional), description (optional).
@@ -1,5 +1,12 @@
1
+ /**
2
+ * Loads error message templates from the errors directory.
3
+ * Supports template variable substitution for dynamic error messages.
4
+ */
1
5
  import { promises as fs } from "fs";
2
- import { join } from "path";
6
+ import { dirname, join } from "path";
7
+ import { fileURLToPath } from "url";
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
3
10
  const ERROR_CACHE = {};
4
11
  export async function loadErrorTemplate(filename) {
5
12
  if (ERROR_CACHE[filename])
@@ -1,10 +1,21 @@
1
1
  import type { Roadmap, RoadmapStorage, ValidationError } from "./types.js";
2
+ type UpdateResult<T> = {
3
+ roadmap: Roadmap;
4
+ buildResult: (archiveName: string | null) => T;
5
+ archive?: boolean;
6
+ };
2
7
  export declare class FileStorage implements RoadmapStorage {
3
8
  private readonly directory;
4
9
  constructor(directory: string);
5
10
  exists(): Promise<boolean>;
6
11
  read(): Promise<Roadmap | null>;
12
+ private readFromDisk;
13
+ private acquireLock;
14
+ private fsyncDir;
15
+ private writeAtomic;
16
+ private archiveUnlocked;
7
17
  write(roadmap: Roadmap): Promise<void>;
18
+ update<T>(fn: (current: Roadmap | null) => Promise<UpdateResult<T>> | UpdateResult<T>): Promise<T>;
8
19
  archive(): Promise<string>;
9
20
  }
10
21
  export declare class RoadmapValidator {
@@ -23,3 +34,4 @@ export declare class RoadmapValidator {
23
34
  static validateDescription(description: string, fieldType: "feature" | "action"): ValidationError | null;
24
35
  static validateStatusProgression(currentStatus: string, newStatus: string): ValidationError | null;
25
36
  }
37
+ export {};
@@ -1,7 +1,16 @@
1
+ /**
2
+ * File-based storage for roadmap data with atomic writes and validation.
3
+ * Handles concurrent access via file locking and provides safe read/write operations.
4
+ */
1
5
  import { promises as fs } from "fs";
2
6
  import { join } from "path";
7
+ import { z } from "zod";
3
8
  import { Roadmap as RoadmapSchema } from "./types.js";
4
9
  const ROADMAP_FILE = "roadmap.json";
10
+ const LOCK_FILE = `${ROADMAP_FILE}.lock`;
11
+ const LOCK_TIMEOUT_MS = 5000;
12
+ const LOCK_RETRY_MS = 50;
13
+ const LOCK_STALE_MS = 30000;
5
14
  export class FileStorage {
6
15
  directory;
7
16
  constructor(directory) {
@@ -17,6 +26,9 @@ export class FileStorage {
17
26
  }
18
27
  }
19
28
  async read() {
29
+ return this.readFromDisk();
30
+ }
31
+ async readFromDisk() {
20
32
  try {
21
33
  const filePath = join(this.directory, ROADMAP_FILE);
22
34
  const data = await fs.readFile(filePath, "utf-8");
@@ -31,6 +43,10 @@ export class FileStorage {
31
43
  if (error instanceof SyntaxError) {
32
44
  throw new Error("Roadmap file contains invalid JSON. File may be corrupted.");
33
45
  }
46
+ if (error instanceof z.ZodError) {
47
+ const issues = error.errors.map((e) => `${e.path.join(".")}: ${e.message}`).join(", ");
48
+ throw new Error(`Roadmap file has invalid structure: ${issues}`);
49
+ }
34
50
  if (error instanceof Error && error.message.includes("ENOENT")) {
35
51
  return null;
36
52
  }
@@ -40,35 +56,108 @@ export class FileStorage {
40
56
  throw new Error("Unknown error while reading roadmap");
41
57
  }
42
58
  }
43
- async write(roadmap) {
44
- const filePath = join(this.directory, ROADMAP_FILE);
45
- const tempPath = join(this.directory, `${ROADMAP_FILE}.tmp.${Date.now()}`);
46
- try {
47
- const data = JSON.stringify(roadmap, null, 2);
48
- await fs.writeFile(tempPath, data, "utf-8");
49
- await fs.rename(tempPath, filePath);
50
- }
51
- catch (error) {
59
+ async acquireLock() {
60
+ const lockPath = join(this.directory, LOCK_FILE);
61
+ const start = Date.now();
62
+ while (Date.now() - start < LOCK_TIMEOUT_MS) {
52
63
  try {
53
- await fs.unlink(tempPath);
64
+ await fs.writeFile(lockPath, String(process.pid), { flag: "wx" });
65
+ return async () => {
66
+ await fs.unlink(lockPath).catch(() => { });
67
+ };
54
68
  }
55
69
  catch {
56
- // Ignore cleanup errors
70
+ const isStale = await fs
71
+ .stat(lockPath)
72
+ .then((stat) => Date.now() - stat.mtimeMs > LOCK_STALE_MS)
73
+ .catch(() => false);
74
+ if (isStale) {
75
+ await fs.unlink(lockPath).catch(() => { });
76
+ continue;
77
+ }
78
+ await new Promise((resolve) => setTimeout(resolve, LOCK_RETRY_MS));
57
79
  }
80
+ }
81
+ throw new Error("Could not acquire lock on roadmap file. Another operation may be in progress.");
82
+ }
83
+ async fsyncDir() {
84
+ const handle = await fs.open(this.directory, "r");
85
+ try {
86
+ await handle.sync();
87
+ }
88
+ finally {
89
+ await handle.close().catch(() => { });
90
+ }
91
+ }
92
+ async writeAtomic(filePath, data) {
93
+ const randomSuffix = Math.random().toString(36).slice(2, 8);
94
+ const tempPath = join(this.directory, `${ROADMAP_FILE}.tmp.${Date.now()}.${randomSuffix}`);
95
+ const handle = await fs.open(tempPath, "w");
96
+ try {
97
+ await handle.writeFile(data, "utf-8");
98
+ await handle.sync();
99
+ await handle.close();
100
+ await fs.rename(tempPath, filePath);
101
+ await this.fsyncDir();
102
+ }
103
+ catch (error) {
104
+ await handle.close().catch(() => { });
105
+ await fs.unlink(tempPath).catch(() => { });
58
106
  if (error instanceof Error) {
59
107
  throw error;
60
108
  }
61
109
  throw new Error("Unknown error while writing roadmap");
62
110
  }
63
111
  }
64
- async archive() {
112
+ async archiveUnlocked() {
65
113
  const filePath = join(this.directory, ROADMAP_FILE);
66
114
  const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
67
115
  const archiveFilename = `roadmap.archive.${timestamp}.json`;
68
116
  const archivePath = join(this.directory, archiveFilename);
69
117
  await fs.rename(filePath, archivePath);
118
+ await this.fsyncDir();
70
119
  return archiveFilename;
71
120
  }
121
+ async write(roadmap) {
122
+ await fs.mkdir(this.directory, { recursive: true }).catch(() => { });
123
+ const unlock = await this.acquireLock();
124
+ try {
125
+ const data = JSON.stringify(roadmap, null, 2);
126
+ const filePath = join(this.directory, ROADMAP_FILE);
127
+ await this.writeAtomic(filePath, data);
128
+ }
129
+ finally {
130
+ await unlock();
131
+ }
132
+ }
133
+ async update(fn) {
134
+ await fs.mkdir(this.directory, { recursive: true }).catch(() => { });
135
+ const unlock = await this.acquireLock();
136
+ try {
137
+ const current = await this.readFromDisk();
138
+ const outcome = await fn(current);
139
+ const data = JSON.stringify(outcome.roadmap, null, 2);
140
+ const filePath = join(this.directory, ROADMAP_FILE);
141
+ await this.writeAtomic(filePath, data);
142
+ const archiveName = outcome.archive ? await this.archiveUnlocked() : null;
143
+ return outcome.buildResult(archiveName);
144
+ }
145
+ finally {
146
+ await unlock();
147
+ }
148
+ }
149
+ async archive() {
150
+ if (!(await this.exists())) {
151
+ throw new Error("Cannot archive: roadmap file does not exist");
152
+ }
153
+ const unlock = await this.acquireLock();
154
+ try {
155
+ return await this.archiveUnlocked();
156
+ }
157
+ finally {
158
+ await unlock();
159
+ }
160
+ }
72
161
  }
73
162
  export class RoadmapValidator {
74
163
  static validateFeatureNumber(number) {
@@ -112,7 +201,7 @@ export class RoadmapValidator {
112
201
  }
113
202
  // Check action-feature mismatch
114
203
  if (featureNumber) {
115
- const actionFeaturePrefix = action.number.split('.')[0];
204
+ const actionFeaturePrefix = action.number.split(".")[0];
116
205
  if (actionFeaturePrefix !== featureNumber) {
117
206
  errors.push({
118
207
  code: "ACTION_FEATURE_MISMATCH",
@@ -192,16 +281,18 @@ export class RoadmapValidator {
192
281
  return null;
193
282
  }
194
283
  static validateStatusProgression(currentStatus, newStatus) {
195
- const statusFlow = {
196
- pending: ["in_progress", "completed"],
197
- in_progress: ["completed"],
198
- completed: [],
199
- };
200
- const allowedTransitions = statusFlow[currentStatus] || [];
201
- if (!allowedTransitions.includes(newStatus)) {
284
+ const validStatuses = ["pending", "in_progress", "completed", "cancelled"];
285
+ if (!validStatuses.includes(newStatus)) {
286
+ return {
287
+ code: "INVALID_STATUS",
288
+ message: `Invalid status "${newStatus}". Valid: ${validStatuses.join(", ")}`,
289
+ };
290
+ }
291
+ // Allow any transition except from cancelled (terminal state for abandoned work)
292
+ if (currentStatus === "cancelled") {
202
293
  return {
203
294
  code: "INVALID_STATUS_TRANSITION",
204
- message: `Invalid transition from "${currentStatus}" to "${newStatus}". Allowed: ${allowedTransitions.length > 0 ? allowedTransitions.join(", ") : "None (terminal state)"}`,
295
+ message: "Cannot change status of cancelled action. Create a new action instead.",
205
296
  };
206
297
  }
207
298
  return null;
@@ -1,2 +1,6 @@
1
+ /**
2
+ * Tool for creating and appending to project roadmaps.
3
+ * Supports merge logic for adding new features/actions to existing roadmaps.
4
+ */
1
5
  import { type ToolDefinition } from "@opencode-ai/plugin";
2
6
  export declare function createCreateRoadmapTool(directory: string): Promise<ToolDefinition>;