visual-living-plan 2.32.1 → 2.33.0

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.
@@ -0,0 +1,230 @@
1
+ import { dirname, isAbsolute, resolve } from 'node:path';
2
+ import { McpServer } from '@modelcontextprotocol/server';
3
+ import { z } from 'zod';
4
+ import { HttpError } from '../http';
5
+ import { checkPlanFile } from '../planCheck';
6
+ /** How long `wait_for_events` waits by default, and at most. */
7
+ export const DEFAULT_WAIT_SECONDS = 300;
8
+ export const MAX_WAIT_SECONDS = 3600;
9
+ /** After the first submission, wait this long for others sent with it, so one call returns the batch. */
10
+ const BATCH_SETTLE_MS = 200;
11
+ const PROGRESS_EVERY_MS = 15_000;
12
+ export const SERVER_INSTRUCTIONS = `Living Plan shows a plan file you write as a page a person reads and answers.
13
+
14
+ 1. Write the plan as a .plan.md file (the live-plan skill has the format) and call check_plan.
15
+ 2. Call serve_plan. The page opens for the person.
16
+ 3. Call wait_for_events, again and again. Each call returns what the person submitted: answers (interaction), comments (comment), and verdicts (review). An empty list means nothing came in yet; call it again.
17
+ 4. Answer each comment with reply_to_comment. Edit the plan file to show progress; the page updates by itself.
18
+ 5. Call set_mode with review when you need the person to approve, deny, or ask for another iteration.
19
+ 6. Call close_plan when the work is done.
20
+
21
+ Every tool takes the plan file's absolute path.`;
22
+ const planPath = z.string().describe('Absolute path of the .plan.md file');
23
+ function text(value, isError = false) {
24
+ return {
25
+ content: [{ type: 'text', text: typeof value === 'string' ? value : JSON.stringify(value, null, 2) }],
26
+ ...(isError ? { isError: true } : {}),
27
+ };
28
+ }
29
+ function failure(error) {
30
+ if (error instanceof HttpError)
31
+ return text(error.message, true);
32
+ if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
33
+ return text('No file at that path.', true);
34
+ }
35
+ return text(error instanceof Error ? error.message : String(error), true);
36
+ }
37
+ /** Run a tool body and turn a thrown error into a tool error the agent can read. */
38
+ async function attempt(run) {
39
+ try {
40
+ return await run();
41
+ }
42
+ catch (error) {
43
+ return failure(error);
44
+ }
45
+ }
46
+ function planFile(plan) {
47
+ if (!isAbsolute(plan))
48
+ throw new HttpError(400, 'Pass the plan file as an absolute path.');
49
+ if (!plan.endsWith('.md'))
50
+ throw new HttpError(400, 'A plan file ends in .md.');
51
+ return resolve(plan);
52
+ }
53
+ function openSession(planHost, plan) {
54
+ const session = planHost.sessionForPath(planFile(plan));
55
+ if (!session)
56
+ throw new HttpError(404, 'This plan is not open. Call serve_plan first.');
57
+ return session;
58
+ }
59
+ /** The submission as the CLI prints it: event, id, seq, and data. */
60
+ function shown(event) {
61
+ return { event: event.event, id: event.id, seq: event.seq, data: event.data };
62
+ }
63
+ /**
64
+ * Wait until the person submits something, the timeout passes, or the call is cancelled. While it
65
+ * waits, the page shows an agent connected. Submissions that reach a call still open are marked
66
+ * delivered; a cancelled call leaves them queued for the next one.
67
+ */
68
+ export async function waitForSubmissions(session, timeoutMs, signal, onTick) {
69
+ const listening = new AbortController();
70
+ const started = Date.now();
71
+ const received = new Map();
72
+ let closed = false;
73
+ let timer;
74
+ let tick;
75
+ try {
76
+ await new Promise((finish) => {
77
+ const settle = () => {
78
+ if (timer)
79
+ clearTimeout(timer);
80
+ timer = setTimeout(finish, BATCH_SETTLE_MS);
81
+ };
82
+ const take = (event) => {
83
+ if (event.deliveredAt != null || received.has(event.id))
84
+ return;
85
+ received.set(event.id, event);
86
+ settle();
87
+ };
88
+ signal.addEventListener('abort', () => finish(), { once: true });
89
+ const pending = session.listenAgent({
90
+ onNotice: take,
91
+ onClose: () => {
92
+ closed = true;
93
+ finish();
94
+ },
95
+ }, listening.signal);
96
+ for (const event of pending)
97
+ take(event);
98
+ if (received.size === 0)
99
+ timer = setTimeout(finish, timeoutMs);
100
+ if (onTick)
101
+ tick = setInterval(() => onTick(Date.now() - started), PROGRESS_EVERY_MS);
102
+ if (signal.aborted)
103
+ finish();
104
+ });
105
+ }
106
+ finally {
107
+ if (timer)
108
+ clearTimeout(timer);
109
+ if (tick)
110
+ clearInterval(tick);
111
+ listening.abort();
112
+ }
113
+ const events = [...received.values()].sort((left, right) => left.seq - right.seq);
114
+ if (events.length > 0 && !signal.aborted && !closed)
115
+ session.acknowledgeEvents({ ids: events.map((event) => event.id) });
116
+ return { events: signal.aborted ? [] : events, closed };
117
+ }
118
+ /** One MCP server instance with the six plan tools. The handler builds one per request. */
119
+ export function createPlanToolServer(options) {
120
+ const { planHost } = options;
121
+ const server = new McpServer({ name: 'living-plan', title: 'Living Plan', version: options.version }, { instructions: SERVER_INSTRUCTIONS });
122
+ server.registerTool('check_plan', {
123
+ title: 'Check a plan file',
124
+ description: 'Validate a .plan.md file before serving it. Returns its title, form ids, and workflow, or the error to fix.',
125
+ inputSchema: z.object({ plan: planPath }),
126
+ annotations: { readOnlyHint: true, openWorldHint: false },
127
+ }, ({ plan }) => attempt(async () => {
128
+ const checked = await checkPlanFile(planFile(plan));
129
+ return text(checked, Boolean(checked.error));
130
+ }));
131
+ server.registerTool('serve_plan', {
132
+ title: 'Show a plan',
133
+ description: 'Open the plan as a page for the person and return its URL. Serving an open plan again keeps its answers and comments.',
134
+ inputSchema: z.object({ plan: planPath }),
135
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
136
+ }, ({ plan }) => attempt(async () => {
137
+ const path = planFile(plan);
138
+ const checked = await checkPlanFile(path);
139
+ const hosted = await planHost.register({ planPath: path, mode: 'watch', cwd: dirname(path) });
140
+ await options.openPage(hosted.url).catch(() => undefined);
141
+ // The page shows a plan that does not compile as an error. The agent hears it here too.
142
+ return text({
143
+ id: hosted.id,
144
+ url: hosted.url,
145
+ mode: hosted.mode,
146
+ plan: hosted.planPath,
147
+ ...(checked.error ? { error: checked.error } : {}),
148
+ });
149
+ }));
150
+ server.registerTool('wait_for_events', {
151
+ title: 'Wait for the person',
152
+ description: 'Wait for what the person submits on the plan page: answers (interaction), comments (comment), and verdicts (review). ' +
153
+ 'Returns as soon as something arrives, or an empty list after timeout_seconds. Call it again to keep listening.',
154
+ inputSchema: z.object({
155
+ plan: planPath,
156
+ timeout_seconds: z
157
+ .number()
158
+ .int()
159
+ .min(1)
160
+ .max(MAX_WAIT_SECONDS)
161
+ .optional()
162
+ .describe(`Seconds to wait before returning an empty list. Default ${DEFAULT_WAIT_SECONDS}.`),
163
+ }),
164
+ annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false },
165
+ }, ({ plan, timeout_seconds }, ctx) => attempt(async () => {
166
+ const session = openSession(planHost, plan);
167
+ const progressToken = ctx.mcpReq._meta?.progressToken;
168
+ const onTick = progressToken === undefined
169
+ ? undefined
170
+ : (elapsedMs) => void ctx.mcpReq
171
+ .notify({
172
+ method: 'notifications/progress',
173
+ params: { progressToken, progress: Math.round(elapsedMs / 1000), message: 'Waiting for the person' },
174
+ })
175
+ .catch(() => undefined);
176
+ const timeoutMs = (timeout_seconds ?? DEFAULT_WAIT_SECONDS) * 1000;
177
+ const { events, closed } = await waitForSubmissions(session, timeoutMs, ctx.mcpReq.signal, onTick);
178
+ if (closed)
179
+ return text('The plan was closed while waiting.', true);
180
+ return text({ events: events.map(shown), mode: session.mode, timedOut: events.length === 0 });
181
+ }));
182
+ server.registerTool('set_mode', {
183
+ title: 'Set the page mode',
184
+ description: 'watch shows status, comment invites comments, review asks for a verdict (approve, deny, or iterate). The verdict arrives through wait_for_events.',
185
+ inputSchema: z.object({
186
+ plan: planPath,
187
+ mode: z.enum(['watch', 'comment', 'review']),
188
+ iteration: z.number().int().min(1).optional().describe('Review round number, when starting a new round'),
189
+ }),
190
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
191
+ }, ({ plan, mode, iteration }) => attempt(() => {
192
+ const session = openSession(planHost, plan);
193
+ return text(session.updateMode(iteration === undefined ? { mode } : { mode, iteration }));
194
+ }));
195
+ server.registerTool('reply_to_comment', {
196
+ title: 'Reply to a comment',
197
+ description: 'Reply to a comment from wait_for_events and mark it answered. Set keep_open to reply without closing it.',
198
+ inputSchema: z.object({
199
+ plan: planPath,
200
+ comment_id: z.string().min(1).describe('The id in the comment event data'),
201
+ text: z.string().min(1).max(4000),
202
+ outcome: z
203
+ .enum(['implemented', 'errored', 'issues'])
204
+ .optional()
205
+ .describe('How it ended. Default implemented. Not used with keep_open.'),
206
+ keep_open: z.boolean().optional(),
207
+ }),
208
+ annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false },
209
+ }, ({ plan, comment_id, text: reply, outcome, keep_open }) => attempt(() => {
210
+ if (keep_open && outcome)
211
+ return text('outcome closes the comment. Leave it out with keep_open.', true);
212
+ const session = openSession(planHost, plan);
213
+ session.replyToComment(comment_id, { text: reply });
214
+ if (keep_open)
215
+ return text({ ok: true, commentId: comment_id, open: true });
216
+ session.addressComment(comment_id, outcome ? { outcome } : {});
217
+ return text({ ok: true, commentId: comment_id, outcome: outcome ?? 'implemented' });
218
+ }));
219
+ server.registerTool('close_plan', {
220
+ title: 'Close a plan',
221
+ description: 'Close the plan page when the work is done. The plan file stays; the run moves to the dashboard history.',
222
+ inputSchema: z.object({ plan: planPath }),
223
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
224
+ }, ({ plan }) => attempt(async () => {
225
+ const session = openSession(planHost, plan);
226
+ await planHost.closePlan(session.id);
227
+ return text({ ok: true, closed: options.planUrl(session.id) });
228
+ }));
229
+ return server;
230
+ }
@@ -0,0 +1,22 @@
1
+ export type PlanCheck = {
2
+ title: string;
3
+ summary?: string;
4
+ agent?: string;
5
+ blocks: string[];
6
+ interactionIds: string[];
7
+ workflow: {
8
+ title?: string;
9
+ nodes: Array<{
10
+ id: string;
11
+ planRef?: string;
12
+ status?: string;
13
+ }>;
14
+ } | null;
15
+ error?: string;
16
+ };
17
+ /**
18
+ * What `live-plan check` prints and the MCP `check_plan` tool returns. `error` is set when the plan
19
+ * has no workflow or would not compile as MDX, the same check the watchers run before a change
20
+ * reaches the page.
21
+ */
22
+ export declare function checkPlanFile(file: string): Promise<PlanCheck>;
@@ -0,0 +1,30 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
+ import { parsePlan } from './parse';
4
+ import { planNotReadyReason } from './planReady';
5
+ import { planToExpectedGraph, workflowRequirementError } from './workflow';
6
+ /**
7
+ * What `live-plan check` prints and the MCP `check_plan` tool returns. `error` is set when the plan
8
+ * has no workflow or would not compile as MDX, the same check the watchers run before a change
9
+ * reaches the page.
10
+ */
11
+ export async function checkPlanFile(file) {
12
+ const source = await readFile(resolve(file), 'utf8');
13
+ const plan = parsePlan(source, file);
14
+ const workflowError = workflowRequirementError(plan) ?? (await planNotReadyReason(source));
15
+ const workflow = workflowError ? undefined : planToExpectedGraph(plan);
16
+ return {
17
+ title: plan.title,
18
+ summary: plan.summary,
19
+ agent: plan.agent,
20
+ blocks: plan.blocks.map((block) => block.type),
21
+ interactionIds: plan.interactionIds,
22
+ workflow: workflow
23
+ ? {
24
+ title: workflow.title,
25
+ nodes: workflow.nodes.map((node) => ({ id: node.id, planRef: node.planRef, status: node.status })),
26
+ }
27
+ : null,
28
+ ...(workflowError ? { error: workflowError } : {}),
29
+ };
30
+ }
@@ -20,6 +20,8 @@ export type PlanHost = {
20
20
  listRecords(): ProcessRecord[];
21
21
  dashboardRecords(): PlanRecord[];
22
22
  getSession(id: string): PlanSession | undefined;
23
+ /** The open session for a plan file, by its absolute path. */
24
+ sessionForPath(planPath: string): PlanSession | undefined;
23
25
  authorize(request: Request, session: PlanSession): boolean;
24
26
  close(): Promise<void>;
25
27
  };
package/dist/planHost.js CHANGED
@@ -272,6 +272,10 @@ export async function createPlanHost(options) {
272
272
  getSession(id) {
273
273
  return sessions.get(id);
274
274
  },
275
+ sessionForPath(planPath) {
276
+ const wanted = resolve(planPath);
277
+ return [...sessions.values()].find((session) => session.planPath === wanted);
278
+ },
275
279
  authorize,
276
280
  async close() {
277
281
  if (closed)
@@ -87,6 +87,14 @@ export type PlanSession = {
87
87
  stopExecution: (body?: unknown) => unknown;
88
88
  browserEvents: (request: Request) => Response;
89
89
  agentEvents: (request: Request) => Response;
90
+ /**
91
+ * An agent listening inside the service (the MCP `wait_for_events` tool). It counts as an open agent
92
+ * stream until `signal` aborts. Returns the submissions still pending; later ones go to `onNotice`.
93
+ */
94
+ listenAgent: (handlers: {
95
+ onNotice: (event: PlanSubmissionEvent) => void;
96
+ onClose: () => void;
97
+ }, signal: AbortSignal) => PlanSubmissionEvent[];
90
98
  submitInteraction: (interactionId: string, body: unknown, request?: Request) => unknown;
91
99
  submitComment: (body: unknown, request?: Request) => unknown;
92
100
  addressComment: (commentId: string, body?: unknown, request?: Request) => unknown;
@@ -788,6 +788,32 @@ export async function openPlanSession(options) {
788
788
  pending: pendingEvents(),
789
789
  }, request.signal, { keepAliveMs: AGENT_KEEPALIVE_MS, onMembership: agentsChanged });
790
790
  }
791
+ function listenAgent(handlers, signal) {
792
+ touch();
793
+ if (signal.aborted)
794
+ return pendingEvents();
795
+ const leave = () => {
796
+ if (!agentClients.delete(client))
797
+ return;
798
+ agentsChanged();
799
+ touch();
800
+ persist();
801
+ };
802
+ const client = {
803
+ write(event, data) {
804
+ if (event === 'notice' && data && typeof data === 'object')
805
+ handlers.onNotice({ ...data });
806
+ },
807
+ close() {
808
+ leave();
809
+ handlers.onClose();
810
+ },
811
+ };
812
+ agentClients.add(client);
813
+ agentsChanged();
814
+ signal.addEventListener('abort', leave, { once: true });
815
+ return pendingEvents();
816
+ }
791
817
  function currentAgentPresence() {
792
818
  return agentPresence(agentClients.size, agentSeenAt);
793
819
  }
@@ -1103,6 +1129,7 @@ export async function openPlanSession(options) {
1103
1129
  stopExecution,
1104
1130
  browserEvents,
1105
1131
  agentEvents,
1132
+ listenAgent,
1106
1133
  submitInteraction,
1107
1134
  submitComment,
1108
1135
  addressComment,
@@ -18,4 +18,6 @@ export declare function startRegistryServer(options: {
18
18
  resolvePeer?: (request: Request) => string | null;
19
19
  /** Skip mDNS. Tests set this so a LAN-enabled home does not open UDP 5353. */
20
20
  advertise?: boolean;
21
+ /** Test seam. Production opens a plan the MCP `serve_plan` tool serves, the first time only, as `serve` does. */
22
+ openPage?: (url: string) => Promise<void>;
21
23
  }): Promise<RegistryServer>;
@@ -10,6 +10,9 @@ import { bindElysia } from './httpServer';
10
10
  import { archivePlanFile, archivedPlanPath, isPathInside } from './planArchive';
11
11
  import { createPlanHost } from './planHost';
12
12
  import { registerPlanRoutes } from './planRoutes';
13
+ import { createMcpEndpoint } from './mcp/endpoint';
14
+ import { choosePlanOpen, rememberPageOpened } from './openedPages';
15
+ import { openUrl } from './openUrl';
13
16
  import { guardRequest } from './requestGuard';
14
17
  import { readClientAsset } from './planSession';
15
18
  import { authorizeLan, cookieValue, currentPeer, grantLanEntry, LAN_COOKIE } from './lanAccess';
@@ -190,6 +193,22 @@ export async function startRegistryServer(options) {
190
193
  getOrigin: () => originBox.current,
191
194
  onFinish: remember,
192
195
  });
196
+ const mcp = createMcpEndpoint({
197
+ home: options.home,
198
+ planHost,
199
+ planUrl: (id) => `${originBox.current.replace(/\/$/, '')}/plans/${id}/`,
200
+ openPage: options.openPage ?? ((url) => openPageOnce(url, options.home)),
201
+ version: options.version ?? '0.0.0',
202
+ });
203
+ const peerOf = (request) => (options.resolvePeer ? (options.resolvePeer(request) ?? '') : currentPeer());
204
+ // The MCP and OAuth handlers read the body themselves.
205
+ const mcpRoute = async ({ request, set }) => {
206
+ const response = await mcp.handle(request, peerOf(request));
207
+ if (response)
208
+ return response;
209
+ set.status = 404;
210
+ return { error: 'Not found' };
211
+ };
193
212
  function dashboardPlans(window) {
194
213
  // Plans deleted from the dashboard keep their rows. They are only left out here.
195
214
  const deleted = store.deletedPlanIds();
@@ -200,7 +219,7 @@ export async function startRegistryServer(options) {
200
219
  .onBeforeHandle(({ request, set }) => {
201
220
  set.headers['cache-control'] = 'no-store';
202
221
  const url = new URL(request.url);
203
- const peer = options.resolvePeer ? (options.resolvePeer(request) ?? '') : currentPeer();
222
+ const peer = peerOf(request);
204
223
  const guard = guardRequest({
205
224
  method: request.method,
206
225
  host: request.headers.get('host'),
@@ -242,6 +261,33 @@ export async function startRegistryServer(options) {
242
261
  set.status = 500;
243
262
  recordUnexpectedError(error, request);
244
263
  return { error: error instanceof Error ? error.message : 'Unknown error' };
264
+ })
265
+ .all('/mcp', mcpRoute, { parse: 'none' })
266
+ .all('/oauth/*', mcpRoute, { parse: 'none' })
267
+ .all('/.well-known/*', mcpRoute, { parse: 'none' })
268
+ .get('/api/mcp/agents', ({ request, set }) => {
269
+ if (!authorized(request, token)) {
270
+ set.status = 401;
271
+ return { error: 'Unauthorized' };
272
+ }
273
+ return { url: `${originBox.current.replace(/\/$/, '')}/mcp`, agents: mcp.store.listGrants() };
274
+ })
275
+ .delete('/api/mcp/agents', ({ request, set }) => {
276
+ if (!authorized(request, token)) {
277
+ set.status = 401;
278
+ return { error: 'Unauthorized' };
279
+ }
280
+ return { ok: true, revoked: mcp.store.revoke() };
281
+ })
282
+ .delete('/api/mcp/agents/:clientId', ({ request, params, set }) => {
283
+ if (!authorized(request, token)) {
284
+ set.status = 401;
285
+ return { error: 'Unauthorized' };
286
+ }
287
+ const revoked = mcp.store.revoke(String(params.clientId ?? ''));
288
+ if (!revoked)
289
+ set.status = 404;
290
+ return revoked ? { ok: true, revoked } : { error: 'No agent with that id' };
245
291
  })
246
292
  .get('/dashboard', () => html(dashboardPage))
247
293
  .get('/api/dashboard', ({ request, set }) => {
@@ -502,6 +548,7 @@ export async function startRegistryServer(options) {
502
548
  bound = bindElysia(app, host, options.port ?? 0);
503
549
  }
504
550
  catch (error) {
551
+ await mcp.close();
505
552
  await planHost.close();
506
553
  store.close();
507
554
  throw error;
@@ -554,9 +601,18 @@ export async function startRegistryServer(options) {
554
601
  if (lock?.pid === process.pid) {
555
602
  await rm(registryLockPath(options.home), { force: true });
556
603
  }
604
+ await mcp.close();
557
605
  await planHost.close();
558
606
  store.close();
559
607
  await bound.stop();
560
608
  },
561
609
  };
562
610
  }
611
+ /** Open a plan page the MCP `serve_plan` tool served, once per machine, as `serve` does. */
612
+ async function openPageOnce(url, home) {
613
+ const choice = await choosePlanOpen(url, { noOpen: false, forceOpen: false }, home).catch(() => 'open');
614
+ if (choice === 'skip')
615
+ return;
616
+ await openUrl(url);
617
+ await rememberPageOpened(url, home).catch(() => undefined);
618
+ }
@@ -17,8 +17,8 @@
17
17
  */
18
18
  export declare const SHELL_CACHE_PREFIX = "visual-living-plan-shell-";
19
19
  /** Keep both equal to package.json `version`. test/shellCache.test.ts checks them. */
20
- export declare const SHELL_CACHE_VERSION = "2.32.1";
21
- export declare const SHELL_CACHE_NAME = "visual-living-plan-shell-2.32.1";
20
+ export declare const SHELL_CACHE_VERSION = "2.33.0";
21
+ export declare const SHELL_CACHE_NAME = "visual-living-plan-shell-2.33.0";
22
22
  /** One document cache per device. The worker cannot see which account is signed in. */
23
23
  export declare const DOCUMENT_CACHE_MARKER = "device";
24
24
  export declare const PRECACHE_BATCH = 16;
@@ -17,8 +17,8 @@
17
17
  */
18
18
  export const SHELL_CACHE_PREFIX = 'visual-living-plan-shell-';
19
19
  /** Keep both equal to package.json `version`. test/shellCache.test.ts checks them. */
20
- export const SHELL_CACHE_VERSION = '2.32.1';
21
- export const SHELL_CACHE_NAME = 'visual-living-plan-shell-2.32.1';
20
+ export const SHELL_CACHE_VERSION = '2.33.0';
21
+ export const SHELL_CACHE_NAME = 'visual-living-plan-shell-2.33.0';
22
22
  /** One document cache per device. The worker cannot see which account is signed in. */
23
23
  export const DOCUMENT_CACHE_MARKER = 'device';
24
24
  export const PRECACHE_BATCH = 16;
@@ -2,8 +2,8 @@
2
2
 
3
3
  // src/shellCache.ts
4
4
  var SHELL_CACHE_PREFIX = "visual-living-plan-shell-";
5
- var SHELL_CACHE_VERSION = "2.32.1";
6
- var SHELL_CACHE_NAME = "visual-living-plan-shell-2.32.1";
5
+ var SHELL_CACHE_VERSION = "2.33.0";
6
+ var SHELL_CACHE_NAME = "visual-living-plan-shell-2.33.0";
7
7
  var DOCUMENT_CACHE_MARKER = "device";
8
8
  var PRECACHE_BATCH = 16;
9
9
  var ASSET_EXTENSION = /\.(?:js|mjs|css|png|jpe?g|gif|webp|avif|svg|ico|woff2?|ttf|otf|wasm)$/i;
@@ -0,0 +1,23 @@
1
+ # Changelog — 2026-11-20
2
+
3
+ ## 2.32.2
4
+
5
+ **PR:** [#205](https://github.com/marco-calderon/visual-living-plan/pull/205)
6
+
7
+ **Bump:** patch
8
+
9
+ ### Summary
10
+
11
+ The comment popover and the Messages tray list messages newest first, by the time they were sent. Before, they could come up shuffled after the page loaded.
12
+
13
+ ### Bugs fixed
14
+
15
+ - Comments in the comment popover and messages in the Messages tray could show in a shuffled order. The page's device copy keeps comments by their random id, and the page used that order. Both now show the newest message on top. An agent reply stays under the message it answers.
16
+
17
+ ### Improvements
18
+
19
+ - In the Messages tray, the note sent with an *Iterate* review sits above the newest comment it was sent with, instead of always on top.
20
+
21
+ ### Notes
22
+
23
+ `SHELL_CACHE_VERSION` moves to 2.32.2. No registry restart needed.
@@ -0,0 +1,22 @@
1
+ # Changelog — 2026-12-02
2
+
3
+ ## 2.33.0
4
+
5
+ **PR:** [#206](https://github.com/marco-calderon/visual-living-plan/pull/206)
6
+
7
+ **Bump:** minor
8
+
9
+ ### Summary
10
+
11
+ The plan service on this machine is now also an MCP server. An agent that speaks MCP drives a plan with six tool calls instead of shell commands, and signs in with OAuth the first time: a Living Plan page opens in the browser and you choose Allow.
12
+
13
+ ### New features
14
+
15
+ - MCP server at `http://127.0.0.1:9477/mcp`, for MCP 2026-07-28 clients and the 2025 revisions. Six tools match the six commands: `check_plan`, `serve_plan`, `wait_for_events`, `set_mode`, `reply_to_comment`, and `close_plan`. Each takes the plan file's path and at most a few other arguments.
16
+ - `wait_for_events` waits in one call until the person answers, comments, or gives a verdict, for up to 5 minutes by default. There is no background listener to start again. While it waits, the page shows the agent connected.
17
+ - OAuth sign-in for the MCP server: the agent registers itself, a consent page asks you to Allow or Deny, and the agent keeps a token it renews by itself for 30 days. Only a browser on this computer can allow an agent.
18
+ - `live-plan mcp` prints the MCP server URL, the line to add it to Claude Code, and the agents signed in. `live-plan mcp revoke` signs every agent out, or one by its client id.
19
+
20
+ ### Notes
21
+
22
+ The CLI is unchanged and still drives hosted (`--cloud`) plans; the MCP server covers plans on this machine's service. The service has to be running before an agent connects. Any `live-plan` command or the desktop app starts it. Signed-in agents are kept in `~/.config/living-plan/mcp-oauth.sqlite` and survive a restart. `SHELL_CACHE_VERSION` moves to 2.33.0. The service restarts by itself on the version change, as on every release.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "visual-living-plan",
3
- "version": "2.32.1",
3
+ "version": "2.33.0",
4
4
  "description": "Agent-authored living plans with human interaction, live updates, and a swappable execution canvas",
5
5
  "type": "module",
6
6
  "packageManager": "bun@1.4.4",
@@ -60,6 +60,7 @@
60
60
  "dependencies": {
61
61
  "@base-ui/react": "^1.9.0",
62
62
  "@journeyapps/wa-sqlite": "^1.7.2",
63
+ "@modelcontextprotocol/server": "2.4.0",
63
64
  "@semos-labs/glyph": "^0.2.10",
64
65
  "@tanstack/browser-db-sqlite-persistence": "^1.0.0-rc.1.1",
65
66
  "@tanstack/db": "^1.0.0-rc.1.1",
@@ -78,7 +79,8 @@
78
79
  "react": "^19.3.0",
79
80
  "winston": "^3.19.0",
80
81
  "winston-daily-rotate-file": "^5.0.0",
81
- "yaml": "^2.8.1"
82
+ "yaml": "^2.8.1",
83
+ "zod": "^4.2.0"
82
84
  },
83
85
  "devDependencies": {
84
86
  "@cloudflare/vite-plugin": "^1.26.0",
@@ -89,6 +91,7 @@
89
91
  "@lexical/selection": "0.48.0",
90
92
  "@mdx-js/mdx": "^3.1.1",
91
93
  "@mdxeditor/editor": "^4.5.0",
94
+ "@modelcontextprotocol/client": "2.4.0",
92
95
  "@panzoom/panzoom": "^4.6.2",
93
96
  "@pierre/diffs": "^1.6.4",
94
97
  "@pierre/highlights": "^0.4.0",
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: live-plan
3
3
  description: >-
4
- Drive a living visual plan with the live-plan CLI so a human can watch phase
4
+ Drive a living visual plan with the live-plan CLI (or its MCP tools) so a human can watch phase
5
5
  status and answer choices, forms, questions, and approval gates in a browser.
6
6
  Use when work has multiple steps, needs a human decision before continuing,
7
7
  needs Approve/Deny/Iterate on a plan, should show highlighted source or a
@@ -33,6 +33,21 @@ Do not call this repo's `npm run` scripts from a consuming project. Those are fo
33
33
 
34
34
  Six commands drive a plan: `check`, `serve`, `events`, `mode`, `reply`, and `close`. Each one names the plan by its file path, for example `events path/to/work.plan.md`. `serve` registers the plan, prints its URL, and returns. Pass `--cloud` to host it on the signed-in cloud service (preferred, see Host). `events` is the one listener: it prints what the person did on the page, and every verdict, answer, and comment arrives there. `mode` switches the page between watch, comment, and review. `reply` answers a comment. After an approval the run follows the plan file, so `execution` is optional. Every waiting command reconnects by itself when the connection drops or the service restarts (see Connection drops). `review`, `watch`, `wait`, `addressing`, and `address` still work as shortcuts.
35
35
 
36
+ ### MCP tools instead of commands
37
+
38
+ When your tools include `serve_plan` and `wait_for_events` (the Living Plan MCP server), use them for a local plan instead of the commands. They take the plan file's absolute path and follow the same Loop:
39
+
40
+ | MCP tool | CLI command | Arguments besides `plan` |
41
+ |---|---|---|
42
+ | `check_plan` | `check` | none |
43
+ | `serve_plan` | `serve` | none |
44
+ | `wait_for_events` | `events` | `timeout_seconds` (default 300, at most 3600) |
45
+ | `set_mode` | `mode` | `mode`, `iteration` |
46
+ | `reply_to_comment` | `reply` | `comment_id`, `text`, `outcome`, `keep_open` |
47
+ | `close_plan` | `close` | none |
48
+
49
+ Call `wait_for_events` again each time it returns. It returns as soon as the person submits something, or `{"events": []}` after `timeout_seconds`; an empty list means nothing arrived yet. Each event has the same `event`, `id`, `seq`, and `data` as an `events` line. Use the commands for `--cloud`, `execution`, and `search`. To set up the server, see `live-plan mcp`: it prints the URL to add to the agent, and the first connection asks the person to choose Allow in the browser.
50
+
36
51
  ## Host
37
52
 
38
53
  Prefer the cloud host. Use the local session when the user asks for it, has no network, or does not want an account.