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.
- package/README.md +4 -0
- package/dist/cli.js +68 -25
- package/dist/client/.vite/manifest.json +1 -1
- package/dist/client/assets/selector-C2KL2wxg.js +1 -0
- package/dist/commentOrder.d.ts +19 -0
- package/dist/commentOrder.js +26 -0
- package/dist/mcp/endpoint.d.ts +20 -0
- package/dist/mcp/endpoint.js +61 -0
- package/dist/mcp/oauthServer.d.ts +33 -0
- package/dist/mcp/oauthServer.js +403 -0
- package/dist/mcp/oauthStore.d.ts +42 -0
- package/dist/mcp/oauthStore.js +138 -0
- package/dist/mcp/planTools.d.ts +27 -0
- package/dist/mcp/planTools.js +230 -0
- package/dist/planCheck.d.ts +22 -0
- package/dist/planCheck.js +30 -0
- package/dist/planHost.d.ts +2 -0
- package/dist/planHost.js +4 -0
- package/dist/planSession.d.ts +8 -0
- package/dist/planSession.js +27 -0
- package/dist/registryService.d.ts +2 -0
- package/dist/registryService.js +57 -1
- package/dist/shellCache.d.ts +2 -2
- package/dist/shellCache.js +2 -2
- package/dist/shellWorker.js +2 -2
- package/docs/changelogs/changelog-2026-11-20.md +23 -0
- package/docs/changelogs/changelog-2026-12-02.md +22 -0
- package/package.json +5 -2
- package/skills/live-plan/SKILL.md +16 -1
- package/dist/client/assets/selector-tlBGWtQl.js +0 -1
package/README.md
CHANGED
|
@@ -209,6 +209,8 @@ live-plan theme set --accent #0369a1 --url <printed-plan-url>
|
|
|
209
209
|
- `POST /api/agent-events/ack` — `{ "ids": ["evt_..."] }` sets `delivered_at`. The CLI calls this after it prints.
|
|
210
210
|
- `POST /api/comments` — comment on one plan part. `live-plan addressing` (`POST /api/comments/:id/addressing`) marks it reviewing. `live-plan reply` (`POST /api/comments/:id/reply`) appends the reply text. `live-plan address` (`POST /api/comments/:id/address`) marks it answered with outcome `implemented` (default), `errored`, or `issues`.
|
|
211
211
|
- `POST /api/mode` — set the session to `watch`, `comment`, or `review`. The open tab follows.
|
|
212
|
+
- `POST /mcp` — the MCP server (protocol 2026-07-28 and the 2025 revisions). Takes an OAuth bearer token; a request without one gets 401 pointing to `/.well-known/oauth-protected-resource/mcp`
|
|
213
|
+
- `/.well-known/oauth-authorization-server`, `POST /oauth/register`, `GET`/`POST /oauth/authorize`, `POST /oauth/token`, `POST /oauth/revoke` — the OAuth 2.1 server agents sign in with. Allow is accepted only from a browser on this machine
|
|
212
214
|
- `GET /api/processes` — plans hosted by the service (directory, git status, site URL). `status` is `ok`, `offline`, or `disabled`
|
|
213
215
|
- `GET /dashboard` — registry page for running and executed plans: day, week, and month summaries, plus a table (status, completion, folder, files modified, start time, duration)
|
|
214
216
|
- `GET /api/dashboard?period=day|week|month` — the same summary and rows as JSON. `live-plan tui` reads this route.
|
|
@@ -227,6 +229,8 @@ live-plan serve path/to/work.plan.md
|
|
|
227
229
|
live-plan events --url <printed-plan-url>
|
|
228
230
|
```
|
|
229
231
|
|
|
232
|
+
Agents that speak MCP can use the plan service as an MCP server instead. `live-plan mcp` prints its URL (`http://127.0.0.1:9477/mcp`) and how to add it. It has six tools, `check_plan`, `serve_plan`, `wait_for_events`, `set_mode`, `reply_to_comment`, and `close_plan`, and signs an agent in with OAuth: the first connection opens a consent page in the browser. See [ADR 0043](docs/architecture/decisions/0043-mcp-server.md).
|
|
233
|
+
|
|
230
234
|
- Guideline: [`docs/agent-guidelines.md`](docs/agent-guidelines.md)
|
|
231
235
|
- Skill: from this repo, `npm run skills:install` copies [`skills/live-plan/`](skills/live-plan/SKILL.md) and the other project skills into `~/.agents/skills`. Run it again to refresh those copies. [`skills/live-plan/SKILL.md`](skills/live-plan/SKILL.md)
|
|
232
236
|
- Primitive schemas: [`skills/live-plan/primitives.md`](skills/live-plan/primitives.md)
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
|
-
import {
|
|
3
|
+
import { checkPlanFile } from './planCheck';
|
|
4
4
|
import { writeSync } from 'node:fs';
|
|
5
5
|
import { access, readFile, writeFile, mkdir } from 'node:fs/promises';
|
|
6
6
|
import { dirname, resolve } from 'node:path';
|
|
@@ -16,7 +16,6 @@ import { startLivingPlanServer } from './server';
|
|
|
16
16
|
import { applyExecutionChange } from './execution';
|
|
17
17
|
import { cwdThemeConfigPath, globalThemeConfigPath } from './configHome';
|
|
18
18
|
import { configPathBesidePlan, DEFAULT_ACCENT, loadThemeConfig, normalizeAccent, saveThemeConfig, themePayload, } from './theme';
|
|
19
|
-
import { planToExpectedGraph, workflowRequirementError } from './workflow';
|
|
20
19
|
import { closeHostedPlan, defaultRegistryHome, ensureRegistry, listProcesses, localServiceUrl, readPackageVersion, readRegistryLock, registerHostedPlan, registryBindUrl, registryHealthy, reviveRegistry, rewriteToBindUrl, } from './registryClient';
|
|
21
20
|
import { isPidAlive } from './pid';
|
|
22
21
|
import { DEFAULT_REGISTRY_HOST, DEFAULT_REGISTRY_PORT } from './registryConstants';
|
|
@@ -60,6 +59,7 @@ Usage (a plan command takes the plan file, or --url <plan-url>):
|
|
|
60
59
|
live-plan tui [--period day|week|month] [--registry-port N] [--registry-host HOST]
|
|
61
60
|
live-plan registry [--port N] [--host HOST]
|
|
62
61
|
live-plan lan on|off|status
|
|
62
|
+
live-plan mcp [--json] | mcp revoke [client-id]
|
|
63
63
|
live-plan account login --url https://host [--headless | --token <token>]
|
|
64
64
|
live-plan skills list|install [--harness <id>]... [--all] [--json]
|
|
65
65
|
live-plan desktop state|configure --json '{...}'|install-cli
|
|
@@ -100,6 +100,7 @@ Other commands:
|
|
|
100
100
|
tui The registry in the terminal: running plans, and the day, week, and month dashboard. Starts the plan service when it is not already running. Quitting leaves that service up. Active plans are listed first. Click a control, or use Tab, arrows, p, d, and the number keys.
|
|
101
101
|
registry Run the plan service in the foreground. serve and review start it on their own.
|
|
102
102
|
lan Publish this machine's plan service on the local network. Off until \`lan on\`.
|
|
103
|
+
mcp Print the MCP server URL on this machine's service, how to add it to an agent, and the agents signed in to it. Starts the service when it is not running. An agent signs in with OAuth the first time: a consent page opens in the browser. \`mcp revoke\` signs every agent out, or one with its client id.
|
|
103
104
|
skills Copy the live-plan skill into agent harnesses: claude-code, codex, cursor, gemini, opencode, agents. \`skills install\` with no --harness uses every harness found on this machine. \`skills list\` shows where it is installed.
|
|
104
105
|
desktop What the desktop app's setup screen runs. \`state\` prints its config as one JSON line. \`configure --json\` changes it: mode (local or cloud), cloudUrl, colorMode, accent, diffsTheme. \`install-cli\` puts live-plan on the PATH from the app.
|
|
105
106
|
|
|
@@ -494,29 +495,9 @@ async function changeExecution(url, action, patch) {
|
|
|
494
495
|
return putExecution(url, applyExecutionChange(current, action, patch));
|
|
495
496
|
}
|
|
496
497
|
async function cmdCheck(file) {
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
const workflowError = workflowRequirementError(plan) ?? (await planNotReadyReason(source));
|
|
501
|
-
const workflow = workflowError ? undefined : planToExpectedGraph(plan);
|
|
502
|
-
console.log(JSON.stringify({
|
|
503
|
-
title: plan.title,
|
|
504
|
-
summary: plan.summary,
|
|
505
|
-
agent: plan.agent,
|
|
506
|
-
blocks: plan.blocks.map((block) => block.type),
|
|
507
|
-
interactionIds: plan.interactionIds,
|
|
508
|
-
workflow: workflow
|
|
509
|
-
? {
|
|
510
|
-
title: workflow.title,
|
|
511
|
-
nodes: workflow.nodes.map((node) => ({
|
|
512
|
-
id: node.id,
|
|
513
|
-
planRef: node.planRef,
|
|
514
|
-
status: node.status,
|
|
515
|
-
})),
|
|
516
|
-
}
|
|
517
|
-
: null,
|
|
518
|
-
...(workflowError ? { error: workflowError } : {}),
|
|
519
|
-
}, null, 2));
|
|
498
|
+
const checked = await checkPlanFile(file);
|
|
499
|
+
console.log(JSON.stringify(checked, null, 2));
|
|
500
|
+
const workflowError = checked.error;
|
|
520
501
|
if (workflowError) {
|
|
521
502
|
await recordLog({
|
|
522
503
|
level: 'error',
|
|
@@ -1272,6 +1253,65 @@ async function cmdExecution(args) {
|
|
|
1272
1253
|
console.error('Usage: live-plan execution <start|push|stop> --url <server-url>');
|
|
1273
1254
|
return 1;
|
|
1274
1255
|
}
|
|
1256
|
+
/** `live-plan mcp`: the MCP endpoint on this machine's service, and the agents allowed to use it. */
|
|
1257
|
+
async function cmdMcp(args) {
|
|
1258
|
+
const action = args[0] && !args[0].startsWith('--') ? args[0] : undefined;
|
|
1259
|
+
if (action !== undefined && action !== 'revoke') {
|
|
1260
|
+
console.error('Usage: live-plan mcp [--json] | live-plan mcp revoke [client-id]');
|
|
1261
|
+
return 1;
|
|
1262
|
+
}
|
|
1263
|
+
const registry = await openRegistry(args);
|
|
1264
|
+
if (!registry) {
|
|
1265
|
+
console.error('The MCP server runs on the plan service, and the service could not start.');
|
|
1266
|
+
return 1;
|
|
1267
|
+
}
|
|
1268
|
+
const origin = registryBindUrl(registry);
|
|
1269
|
+
const headers = { authorization: `Bearer ${registry.token}` };
|
|
1270
|
+
if (action === 'revoke') {
|
|
1271
|
+
const clientId = args[1] && !args[1].startsWith('--') ? args[1] : undefined;
|
|
1272
|
+
const target = clientId ? `${origin}/api/mcp/agents/${encodeURIComponent(clientId)}` : `${origin}/api/mcp/agents`;
|
|
1273
|
+
const response = await fetch(target, { method: 'DELETE', headers });
|
|
1274
|
+
if (!response.ok) {
|
|
1275
|
+
console.error(clientId ? `No agent with the client id ${clientId}.` : await response.text());
|
|
1276
|
+
return 1;
|
|
1277
|
+
}
|
|
1278
|
+
const { revoked } = (await response.json());
|
|
1279
|
+
console.log(clientId ? `Signed out ${clientId}.` : `Signed out ${revoked} agent${revoked === 1 ? '' : 's'}.`);
|
|
1280
|
+
return 0;
|
|
1281
|
+
}
|
|
1282
|
+
const response = await fetch(`${origin}/api/mcp/agents`, { headers });
|
|
1283
|
+
if (!response.ok) {
|
|
1284
|
+
console.error(`The service did not list MCP agents (${response.status}). Restart it with a newer live-plan.`);
|
|
1285
|
+
return 1;
|
|
1286
|
+
}
|
|
1287
|
+
const listed = (await response.json());
|
|
1288
|
+
const url = `${origin}/mcp`;
|
|
1289
|
+
if (hasFlag(args, '--json')) {
|
|
1290
|
+
printJsonLine({ url, agents: listed.agents });
|
|
1291
|
+
return 0;
|
|
1292
|
+
}
|
|
1293
|
+
console.log(`Living Plan MCP server: ${url}`);
|
|
1294
|
+
console.log('');
|
|
1295
|
+
console.log('Add it to an agent as a streamable HTTP server. Claude Code:');
|
|
1296
|
+
console.log(` claude mcp add --transport http living-plan ${url}`);
|
|
1297
|
+
console.log('Other agents take the same URL in their MCP config:');
|
|
1298
|
+
console.log(` { "mcpServers": { "living-plan": { "url": "${url}" } } }`);
|
|
1299
|
+
console.log('The first time, the agent opens a Living Plan page in your browser. Choose Allow there.');
|
|
1300
|
+
console.log('');
|
|
1301
|
+
if (listed.agents.length === 0) {
|
|
1302
|
+
console.log('No agent is signed in yet.');
|
|
1303
|
+
}
|
|
1304
|
+
else {
|
|
1305
|
+
console.log('Signed in:');
|
|
1306
|
+
for (const agent of listed.agents) {
|
|
1307
|
+
const when = agent.lastIssuedAt ? new Date(agent.lastIssuedAt).toLocaleString() : 'unknown';
|
|
1308
|
+
console.log(` ${agent.clientName} ${agent.clientId} last token ${when}`);
|
|
1309
|
+
}
|
|
1310
|
+
console.log('live-plan mcp revoke signs every agent out. Pass a client id to sign out one.');
|
|
1311
|
+
}
|
|
1312
|
+
console.log('The service has to be running. Any live-plan command or the desktop app starts it.');
|
|
1313
|
+
return 0;
|
|
1314
|
+
}
|
|
1275
1315
|
async function cmdProcesses() {
|
|
1276
1316
|
const home = defaultRegistryHome();
|
|
1277
1317
|
const lock = await readRegistryLock(home);
|
|
@@ -1581,6 +1621,9 @@ async function main() {
|
|
|
1581
1621
|
if (command === 'registry') {
|
|
1582
1622
|
return cmdRegistry(args.slice(1));
|
|
1583
1623
|
}
|
|
1624
|
+
if (command === 'mcp') {
|
|
1625
|
+
return cmdMcp(args.slice(1));
|
|
1626
|
+
}
|
|
1584
1627
|
if (command === 'lan') {
|
|
1585
1628
|
const { lanOff, lanOn, lanStatus } = await import('./lanCommand');
|
|
1586
1629
|
const action = args[1];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{n as t,t as n}from"./jsx-runtime-DKj5X9O4.js";import{n as r}from"./queryClient-Bs5tSUJh.js";import"./mountChrome-BVWpsDCy.js";import{t as i}from"./client-BsE_buVT.js";import{g as a}from"./offlineSync-Cv3FVIlJ.js";import{a as o,r as s}from"./engine-DUyaiAMV.js";import{n as c}from"./planEvents-cuzv9ELr.js";import{t as l}from"./arrow-up-CEVVOXD5.js";import{t as u}from"./button-DJWAGApe.js";import{n as d,t as f}from"./circle-x-BLGxA3gi.js";import{t as p}from"./triangle-alert-C9Sgr3jF.js";import{a as m,i as h,n as g,r as _,t as v}from"./Popover-DbE4vUPG.js";var y=e(t(),1),b=i();function x(e){return typeof e.createdAt==`number`&&Number.isFinite(e.createdAt)?e.createdAt:0}function S(e){return[...e].sort((e,t)=>x(e)-x(t))}function ee(e){return S(e).reverse()}function C(e,t,n){let r=new Set(n),i=e.findIndex(e=>r.has(e.id)),a=i===-1?0:i;return[...e.slice(0,a),t,...e.slice(a)]}function te(e){return e.kind===`message`||e.partId===`review:message`?`minibar`:`component`}function w(e,t){let n=new Set((e.find(e=>e.id===t.id)?.replies??[]).flatMap(e=>e.id?[e.id]:[]));return(t.replies??[]).flatMap(e=>e.id&&!n.has(e.id)?[e.id]:[])}function ne(e,t){let n=w(e,t);return n.length===0?null:{replyIds:n,surface:te(t)}}var T=e(n(),1);function E({label:e=`Addressing`}){return(0,T.jsx)(`span`,{className:`plan-comment-progress`,role:`img`,"aria-label":e,title:e,children:(0,T.jsxs)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,"aria-hidden":`true`,children:[(0,T.jsx)(`circle`,{cx:`8`,cy:`8`,r:`5.5`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,opacity:`0.35`}),(0,T.jsx)(`path`,{d:`M8 2.5a5.5 5.5 0 0 1 5.5 5.5`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`})]})})}function D({reply:e,onSettled:t}){let n=e.fresh===!0;return(0,y.useEffect)(()=>{n&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches&&t?.(e.id)},[n,t,e.id]),(0,T.jsx)(`p`,{className:n?`plan-comment-reply reply-applied`:`plan-comment-reply`,"data-reply-id":e.id,onAnimationEnd:n=>{n.target===n.currentTarget&&n.animationName===`reply-applied`&&t?.(e.id)},children:e.text})}function O({align:e=`start`,variant:t=`muted`,children:n,className:r}){let i=[`plan-bubble`,`is-${t}`,e===`end`?`is-end`:`is-start`,r].filter(Boolean).join(` `);return(0,T.jsx)(`div`,{className:i,"data-align":e,"data-variant":t,children:n})}function k({children:e,className:t}){return(0,T.jsx)(`div`,{className:t?`plan-bubble-content ${t}`:`plan-bubble-content`,children:e})}function A({className:e,...t}){return(0,T.jsx)(`kbd`,{"data-slot":`kbd`,className:e?`plan-kbd ${e}`:`plan-kbd`,...t})}function j({className:e,...t}){return(0,T.jsx)(`kbd`,{"data-slot":`kbd-group`,className:e?`plan-kbd-group ${e}`:`plan-kbd-group`,...t})}function re(){return typeof navigator<`u`&&/Mac|iPhone|iPad|iPod/.test(navigator.platform)}function M(){return(0,T.jsxs)(j,{"aria-hidden":`true`,children:[(0,T.jsx)(A,{children:re()?`⌘`:`Ctrl`}),(0,T.jsx)(A,{children:`Enter`})]})}function N(e){return e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&!e.repeat}function P({align:e=`start`,children:t,className:n}){let r=[`plan-message`,e===`end`?`is-end`:`is-start`,n].filter(Boolean).join(` `);return(0,T.jsx)(`div`,{className:r,"data-align":e,children:t})}function F({children:e,className:t}){return(0,T.jsx)(`div`,{className:t?`plan-message-content ${t}`:`plan-message-content`,children:e})}function I({children:e,className:t}){return(0,T.jsx)(`div`,{className:t?`plan-message-footer ${t}`:`plan-message-footer`,children:e})}function L({status:e}){return e===`working`?(0,T.jsxs)(`span`,{className:`plan-agent-status is-working`,children:[(0,T.jsx)(E,{label:`Working`}),`Working`]}):e===`implemented`?(0,T.jsxs)(`span`,{className:`plan-agent-status is-implemented`,children:[(0,T.jsx)(d,{"aria-hidden":`true`,size:16}),`Implemented`]}):e===`errored`?(0,T.jsxs)(`span`,{className:`plan-agent-status is-errored`,children:[(0,T.jsx)(f,{"aria-hidden":`true`,size:16}),`Errored`]}):e===`issues`?(0,T.jsxs)(`span`,{className:`plan-agent-status is-issues`,children:[(0,T.jsx)(p,{"aria-hidden":`true`,size:16}),`Had issues`]}):(0,T.jsx)(`span`,{className:`plan-agent-status is-pending`,children:`Pending`})}function R(e){return e instanceof Element&&!!e.closest(`.plan-agent-toggle, .plan-agent-panel`)}function ie({messages:e,sending:t,attentionKey:n,onSend:r,onReplySettled:i}){let[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(``),h=(0,y.useRef)(null),g=a||s||d;(0,y.useEffect)(()=>{n&&f(!0)},[n]),(0,y.useEffect)(()=>{let e=h.current;if(!e)return;let t=()=>c(!0),n=t=>{let n=t.relatedTarget;n instanceof Node&&e.contains(n)||c(!1)};return e.addEventListener(`focusin`,t),e.addEventListener(`focusout`,n),()=>{e.removeEventListener(`focusin`,t),e.removeEventListener(`focusout`,n)}},[]),(0,y.useEffect)(()=>{if(!g)return;let e=e=>{let t=h.current;!t||e.target instanceof Node&&t.contains(e.target)||(f(!1),o(!1),c(!1),document.activeElement instanceof HTMLElement&&t.contains(document.activeElement)&&document.activeElement.blur())};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[g]);function _(e){R(e.target)&&o(!0)}function v(e){R(e.relatedTarget)||(o(!1),h.current?.contains(document.activeElement)&&c(!0))}function b(e){(e.pointerType===`touch`||e.pointerType===`pen`||window.matchMedia(`(hover: none), (pointer: coarse)`).matches)&&f(!0)}let x=e.some(e=>e.status===`working`),S=x?`Messages in progress`:g?`Hide messages sent to the agent`:`Show messages sent to the agent`;async function ee(e){e.preventDefault();let n=p.trim();n&&!t&&(await r(n),m(``))}function C(e){N(e)&&(e.preventDefault(),!(t||e.currentTarget.value.trim().length===0)&&e.currentTarget.form?.requestSubmit())}return(0,T.jsx)(`div`,{ref:h,className:`plan-agent-dock`,children:(0,T.jsxs)(`div`,{className:g?`plan-agent-tray is-open`:`plan-agent-tray`,onMouseOver:_,onMouseOut:v,children:[(0,T.jsxs)(`div`,{className:`plan-agent-panel`,role:`region`,"aria-label":`Messages sent to the agent`,"aria-hidden":!g||void 0,children:[(0,T.jsxs)(`header`,{className:`plan-agent-chat-header`,children:[(0,T.jsx)(`p`,{className:`plan-agent-chat-title`,children:`Messages`}),(0,T.jsx)(`p`,{className:`plan-agent-chat-subtitle`,children:`Ask the agent to change the plan.`})]}),(0,T.jsx)(`div`,{className:`plan-agent-messages`,children:e.length>0?(0,T.jsx)(`div`,{className:`plan-agent-chat`,children:e.map(e=>(0,T.jsxs)(`div`,{className:`plan-agent-turn`,children:[(0,T.jsx)(P,{align:`end`,children:(0,T.jsxs)(F,{children:[(0,T.jsx)(O,{variant:`muted`,align:`end`,children:(0,T.jsx)(k,{children:e.text})}),(0,T.jsx)(I,{children:(0,T.jsx)(L,{status:e.status})})]})}),(e.replies??[]).map(e=>(0,T.jsx)(P,{align:`start`,children:(0,T.jsx)(F,{children:(0,T.jsx)(O,{variant:`ghost`,align:`start`,children:(0,T.jsx)(k,{children:(0,T.jsx)(D,{reply:e,onSettled:i})})})})},e.id))]},e.id))}):(0,T.jsx)(`p`,{className:`plan-agent-empty`,children:`No messages yet`})}),(0,T.jsxs)(`form`,{className:`plan-agent-composer`,onSubmit:e=>void ee(e),children:[(0,T.jsx)(`textarea`,{className:`plan-agent-composer-input`,rows:2,value:p,placeholder:`Add a message`,"aria-label":`Add a message`,"aria-keyshortcuts":`Control+Enter Meta+Enter`,onChange:e=>m(e.target.value),onKeyDown:C}),(0,T.jsxs)(`div`,{className:`plan-agent-composer-bar`,children:[(0,T.jsx)(M,{}),(0,T.jsx)(`button`,{type:`submit`,className:`plan-agent-send`,"aria-label":t?`Sending`:`Send`,disabled:t||p.trim().length===0,children:(0,T.jsx)(l,{size:16,"aria-hidden":`true`})})]})]})]}),(0,T.jsx)(u,{type:`button`,className:x?`plan-agent-toggle is-working`:`plan-agent-toggle`,"aria-expanded":g,"aria-label":S,onPointerDown:b,children:x?(0,T.jsx)(E,{label:`Working`}):`Messages${e.length>0?` ${e.length}`:``}`})]})})}function ae({onApprove:e}){return(0,T.jsx)(u,{type:`button`,className:`plan-approve-button`,"data-plan-grab-ignore":``,onClick:e,children:`Approve`})}function oe({comment:e,onAddress:t}){return e.addressedAt?(0,T.jsx)(`span`,{className:`plan-comment-status is-addressed`,children:`Addressed`}):e.addressingAt?(0,T.jsxs)(`span`,{className:`plan-comment-status is-addressing`,children:[(0,T.jsx)(E,{}),`Addressing`]}):(0,T.jsxs)(`span`,{className:`plan-comment-status is-pending`,children:[`Pending`,(0,T.jsx)(`button`,{type:`button`,className:`plan-comment-address`,onClick:t,children:`Mark addressed`})]})}function se({open:e,anchor:t,title:n,excerpt:r,comments:i,sending:a,error:o,freshReplyIds:s,onOpenChange:c,onSend:l,onAddress:d,onReplySettled:f}){let[p,b]=(0,y.useState)(``);async function x(e){e.preventDefault();let t=p.trim();if(t&&!a)try{await l(t),b(``)}catch{}}function S(e){N(e)&&(e.preventDefault(),!(a||e.currentTarget.value.trim().length===0)&&e.currentTarget.form?.requestSubmit())}return(0,T.jsx)(v,{open:e,onOpenChange:c,modal:!1,children:(0,T.jsxs)(g,{className:`plan-comment-popover`,anchor:t,side:`right`,align:`start`,sideOffset:10,collisionPadding:{top:12,right:12,bottom:88,left:12},collisionAvoidance:{side:`shift`,align:`shift`,fallbackAxisSide:`none`},finalFocus:!1,children:[(0,T.jsxs)(h,{children:[(0,T.jsx)(m,{title:n,children:n}),r?(0,T.jsx)(_,{children:r}):null]}),i.length>0?(0,T.jsx)(`div`,{className:`plan-comment-chat`,children:i.map(e=>(0,T.jsxs)(`div`,{className:`plan-comment-turn`,children:[(0,T.jsx)(P,{align:`end`,children:(0,T.jsxs)(F,{children:[(0,T.jsx)(O,{variant:`muted`,align:`end`,children:(0,T.jsx)(k,{children:e.text})}),(0,T.jsx)(I,{children:(0,T.jsx)(oe,{comment:e,onAddress:()=>d(e.id)})})]})}),(e.replies??[]).map(e=>(0,T.jsx)(P,{align:`start`,children:(0,T.jsx)(F,{children:(0,T.jsx)(O,{variant:`ghost`,align:`start`,children:(0,T.jsx)(k,{children:(0,T.jsx)(D,{reply:{id:e.id,text:e.text,fresh:s?.has(e.id)},onSettled:f})})})})},e.id))]},e.id))}):null,(0,T.jsxs)(`form`,{className:`plan-comment-form`,onSubmit:e=>void x(e),children:[(0,T.jsx)(`textarea`,{className:`plan-comment-input`,value:p,rows:3,placeholder:`Message for the agent`,"aria-label":`Message for the agent`,"aria-keyshortcuts":`Control+Enter Meta+Enter`,onChange:e=>b(e.target.value),onKeyDown:S}),o?(0,T.jsx)(`p`,{className:`plan-comment-error`,children:o}):null,(0,T.jsxs)(`div`,{className:`plan-comment-actions`,children:[(0,T.jsx)(M,{}),(0,T.jsx)(u,{type:`submit`,variant:`primary`,disabled:a||p.trim().length===0,children:a?`Sending`:`Send`})]})]})]})})}function ce({enabled:e,onToggle:t}){return(0,T.jsxs)(u,{type:`button`,className:`plan-grab-toggle`,"data-plan-grab-ignore":``,"aria-pressed":e,"aria-label":e?`Turn comments off`:`Turn comments on`,onClick:t,children:[`Comment`,(0,T.jsx)(A,{"aria-hidden":`true`,children:`C`})]})}var z=250,B=200,V=`var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1))`,le=`var(--ease-in-out, cubic-bezier(0.77, 0, 0.175, 1))`,H=`opacity ${B}ms ${V}`,U=`transform ${z}ms ${le}`;function W(e,t){return{partId:e,left:t.left,top:t.top,width:Math.max(t.width,8),height:Math.max(t.height,8)}}function G(e,t){let n=Math.max(t.width,1),r=Math.max(t.height,1);return`translate(${e.left-t.left}px, ${e.top-t.top}px) scale(${e.width/n}, ${e.height/r})`}function ue(e,t){return Math.abs(e.left-t.left)<.5&&Math.abs(e.top-t.top)<.5&&Math.abs(e.width-t.width)<.5&&Math.abs(e.height-t.height)<.5}function de({partId:e,rect:t,label:n,enterFrom:r,visible:i,onExited:a}){let o=(0,y.useRef)(null),s=(0,y.useRef)(null),c=(0,y.useRef)(0),l=(0,y.useRef)(a);return l.current=a,(0,y.useLayoutEffect)(()=>{let n=o.current;if(!n)return;let i=W(e,t),a=s.current;if(a&&a.partId===i.partId&&ue(a,i))return;let l=a===null,u=a!==null&&a.partId!==i.partId,d=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,f=performance.now()<c.current;if(n.style.left=`${i.left}px`,n.style.top=`${i.top}px`,n.style.width=`${i.width}px`,n.style.height=`${i.height}px`,l&&r&&!d){let e={partId:i.partId,left:r.x-7,top:r.y-7,width:14,height:14};n.style.transition=`none`,n.style.transform=G(e,i),n.getBoundingClientRect(),n.style.transition=U,n.style.transform=`translate(0px, 0px) scale(1, 1)`,c.current=performance.now()+z}else u&&a&&!d?(n.style.transition=`none`,n.style.transform=G(a,i),n.getBoundingClientRect(),n.style.transition=U,n.style.transform=`translate(0px, 0px) scale(1, 1)`,c.current=performance.now()+z):f||(n.style.transition=`none`,n.style.transform=`none`);s.current=i},[e,t,r]),(0,y.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;if(i){e.style.opacity=`1`;return}if(t){e.style.opacity=`0`,l.current();return}let n=e.style.transition;e.style.transition=!n||n===`none`?H:n.includes(`opacity`)?n:`${n}, ${H}`,e.style.opacity=`0`;let r=t=>{t.propertyName===`opacity`&&e.style.opacity===`0`&&l.current()};return e.addEventListener(`transitionend`,r),()=>e.removeEventListener(`transitionend`,r)},[i]),(0,T.jsx)(`div`,{ref:o,"data-plan-grab-ignore":``,className:`plan-grab-overlay`,children:(0,T.jsx)(`span`,{className:`plan-grab-label`,children:n})})}function K(e){return(e instanceof HTMLElement||e instanceof SVGElement)&&!!e.dataset.planPart}function q(e){let t=e.getRootNode();return t instanceof ShadowRoot?t.host:null}function fe(e){let t=e.getRootNode();if(!(t instanceof ShadowRoot))return null;let n=e.closest(`[data-line-index]`);if(!n)return null;let r=t.host.closest(`[data-plan-part]`),i=r?.dataset.planPart;if(!r||!i)return null;let a=Number(n.getAttribute(`data-line-index`));if(!Number.isInteger(a))return null;let o=Number(r.dataset.start||`1`),s=a+(o>=1?o:1);return n.dataset.planPart=`${i}/line:${s}`,n.dataset.planKind=`line`,n}function pe(e){let t=e;for(;t;){if(K(t))return t;t=t.parentElement?t.parentElement:q(t)}return null}var me=`button, input, textarea, select, label`;function he(e){let t=e.closest(me);return t!=null&&!K(t)}function ge(e){if(!e||e.closest(`[data-plan-grab-ignore]`)||he(e))return null;let t=fe(e);if(t)return t;let n=pe(e);return!n||n.closest(`[data-plan-grab-ignore]`)?null:n}var _e=new Set([`A`,`ABBR`,`B`,`CODE`,`EM`,`I`,`KBD`,`MARK`,`S`,`SMALL`,`SPAN`,`STRONG`,`SUB`,`SUP`,`U`]);function ve(e){let t=[],n=e=>{if(e.nodeType===Node.TEXT_NODE){t.push(e.textContent??``);return}if(!(e instanceof Element))return;let r=!_e.has(e.tagName);r&&t.push(` `);for(let t of e.childNodes)n(t);r&&t.push(` `)};for(let t of e.childNodes)n(t);return t.join(``).replace(/\s+/g,` `).trim()}function J(e){let t=ve(e).slice(0,180);return{partId:e.dataset.planPart??``,kind:e.dataset.planKind??`part`,excerpt:t,element:e}}function ye(e){let t=e.parentElement??q(e);return t?pe(t):null}function be(e){let t=e.querySelector(`[data-plan-part]`);return t&&K(t)?t:null}function xe(e){let[t]=e.split(`/`);if(t&&!t.startsWith(`markdown:`))return t.slice(t.indexOf(`:`)+1)||void 0}function Se(e){let t=Y(e);if(!t)return;let n=t.closest(`.block`),r=n instanceof HTMLElement?n:t instanceof HTMLElement?t:null;r&&(document.body.classList.add(`plan-live`),r.classList.remove(`change-applied`),r.offsetWidth,r.classList.add(`change-applied`))}function Y(e){let t=document.querySelector(`[data-plan-part="${CSS.escape(e)}"]`);if(t&&K(t))return t;let n=/^(.*)\/line:(\d+)$/.exec(e);if(!n)return null;let r=n[1]??``,i=Number(n[2]),a=document.querySelector(`[data-plan-part="${CSS.escape(r)}"]`);if(!a)return null;let o=Number(a.dataset.start||`1`),s=i-(o>=1?o:1),c=[];a.shadowRoot&&c.push(a.shadowRoot);for(let e of a.querySelectorAll(`*`))e.shadowRoot&&c.push(e.shadowRoot);for(let t of c){let n=t.querySelector(`[data-line-index="${s}"]`);if(n)return n.dataset.planPart=e,n.dataset.planKind=`line`,n}return null}function Ce(e,t){let n=e.replaceAll(`-`,` `);return t?`${n} · ${t.length>42?`${t.slice(0,42)}…`:t}`:n}function we({count:e,busy:t=!1,style:n,onClick:r}){let i=t?e===1?`1 comment being addressed`:`${e} comments being addressed`:e===1?`1 unaddressed comment`:`${e} unaddressed comments`;return(0,T.jsx)(`button`,{type:`button`,className:`plan-grab-mark`,"data-plan-grab-ignore":``,style:n,"aria-label":i,title:i,onClick:e=>{e.preventDefault(),e.stopPropagation(),r()},children:t?(0,T.jsx)(E,{label:i}):(0,T.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`10`,height:`10`,"aria-hidden":`true`,children:(0,T.jsx)(`path`,{d:`M2.5 3.5h11v7.2H8.4L5.2 13.5v-2.8H2.5v-7.2z`,fill:`currentColor`})})})}function X(e){return`${window.__LIVE_PLAN_BASE__??``}${e}`}function Te(){let e=document.body.dataset.planMode;return e===`comment`||e===`review`||e===`watch`?e:`watch`}function Ee(){let e=document.getElementById(`living-plan-review`);if(!e?.textContent)return null;try{let t=JSON.parse(e.textContent);return t?.decision===`iterate`?{note:t.note,ids:(t.comments??[]).flatMap(e=>e.id?[e.id]:[])}:null}catch{return null}}function De(){let e=document.getElementById(`living-plan-comments`);if(!e?.textContent)return[];try{let t=JSON.parse(e.textContent);return Array.isArray(t)?t:[]}catch{return[]}}function Oe(e){try{let t=JSON.parse(e);if(typeof t?.error==`string`)return t.error}catch{}return e.trim()}function ke(e,t){return Math.abs(e.top-t.top)<.5&&Math.abs(e.left-t.left)<.5&&Math.abs(e.width-t.width)<.5&&Math.abs(e.height-t.height)<.5}function Ae(e){let t=document.querySelector(`[data-tab-panel="plan"]`);if(!(t instanceof HTMLElement)||t.hidden)return!1;if(t.contains(e)||e.closest(`.mermaid-diagram`))return!0;let n=e.getRootNode();return n instanceof ShadowRoot&&t.contains(n.host)}function je(e){return e.outcome===`implemented`||e.outcome===`errored`||e.outcome===`issues`?e.outcome:e.addressedAt?`implemented`:e.addressingAt?`working`:`pending`}function Z(e,t){let n=e.findIndex(e=>e.id===t.id);if(n===-1){let n=t.id.startsWith(`pending:`),r=e=>e.partId===t.partId&&e.text===t.text;if(n){let n=e.filter(e=>e.id.startsWith(`pending:`)&&r(e)).length;return e.filter(e=>!e.id.startsWith(`pending:`)&&r(e)).length>n?e:[...e,t]}let i=e.findIndex(e=>e.id.startsWith(`pending:`)&&r(e));if(i===-1)return[...e,t];let a=e.slice();return a[i]=t,a}let r=e.slice();return r[n]=t,r}function Me(e,t,n){let r=ee(e).map(e=>({id:e.id,text:e.text,status:je(e),replies:(e.replies??[]).map(e=>({id:e.id,text:e.text,fresh:n.has(e.id)}))})),i=t?.note?.trim();return!t||!i?r:C(r,{id:`review-note`,text:i,status:`pending`},t.ids)}function Ne(){let[e,t]=(0,y.useState)(Te),[n,i]=(0,y.useState)(()=>Te()!==`watch`),l=(0,y.useRef)(e);l.current=e;let u=e===`review`?n:e!==`watch`;(0,y.useEffect)(()=>(document.documentElement.dataset.comments=u?`on`:`off`,()=>{delete document.documentElement.dataset.comments}),[u]);let[d,f]=(0,y.useState)(()=>S(De())),p=(0,y.useRef)(d),[m,h]=(0,y.useState)(()=>new Set),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(!1),[x,C]=(0,y.useState)(null),[w,E]=(0,y.useState)(null),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(null),[j,re]=(0,y.useState)(null),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(Ee),I=(0,y.useRef)(!1),L=(0,y.useRef)(!1),R=(0,y.useRef)(!1),[oe,z]=(0,y.useState)([]),[B,V]=(0,y.useState)(!1),[le,H]=(0,y.useState)(``),U=(0,y.useRef)(x),W=(0,y.useRef)(w);U.current=x,W.current=w;let G=(0,y.useMemo)(()=>d.filter(e=>e.addressedAt==null),[d]),ue=(0,y.useMemo)(()=>w?ee(d.filter(e=>e.partId===w.partId)):[],[d,w]);(0,y.useEffect)(()=>{let e=e=>{let t=e.detail?.root;if(C(null),!(t instanceof Element)){E(null),O(!1);return}let n=W.current?.partId,r=t.getAttribute(`data-plan-part`);n!=null&&(n===r||r!=null&&n.startsWith(r+`/`)||t.querySelector(`[data-plan-part="${CSS.escape(n)}"]`)!=null)&&(E(null),O(!1))};return window.addEventListener(`living-plan-document`,e),()=>window.removeEventListener(`living-plan-document`,e)},[]);function K(e){(e===`watch`||e===`comment`||e===`review`)&&e!==l.current&&(l.current=e,t(e),i(e!==`watch`))}(0,y.useEffect)(()=>{let e=e=>K(e.detail?.mode);window.addEventListener(`living-plan-mode`,e);let t=e=>{try{let t=JSON.parse(e.data);return t&&typeof t==`object`?t:null}catch{return null}},n=c(`mode`,e=>K(t(e)?.mode)),r=c(`hello`,e=>K(t(e)?.mode)),i=c(`review`,e=>{let n=t(e)?.decision;(n===`approve`||n===`deny`)&&K(`watch`)});return()=>{window.removeEventListener(`living-plan-mode`,e),n(),r(),i()}},[]);function q(e){let t=S(e(p.current));p.current=t,f(t)}function fe(e){h(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})}function pe(e,t){let n=ne(e,t);if(!n)return;h(e=>{let t=new Set(e);for(let e of n.replyIds)t.add(e);return t});let r=n.replyIds[n.replyIds.length-1]??null;if(n.surface===`minibar`){_(r);return}Se(t.partId);let i=Y(t.partId);if(!i)return;let a=J(i);E(a),C(a),A(a.element.getBoundingClientRect()),H(``),b(!0),O(!0)}(0,y.useEffect)(()=>(document.body.classList.toggle(`plan-grab-armed`,u),!u&&!v&&(C(null),O(!1),E(null)),()=>document.body.classList.remove(`plan-grab-armed`)),[u,v]);async function me(){if(!R.current){R.current=!0;try{let e=await r(`review`,X(`/api/review`),{decision:`approve`});if(!e.ok&&!e.queued){let t=Oe(e.text),n=t?`Could not approve: ${t}`:`Could not approve`;H(n),window.showPlanToast?.(n,`error`);return}K(`watch`)}finally{R.current=!1}}}async function he(e){V(!0),H(``);try{let t=await r(`comment`,X(`/api/comments`),{partId:`review:message`,kind:`message`,text:e});if(!t.ok&&!t.queued)throw Error(t.text||`Could not send the message`);let n=t.body;n?.comment&&q(e=>Z(e,n.comment))}catch(e){throw H(e instanceof Error?e.message:`Could not send the message`),e}finally{V(!1)}}async function _e(){if(e===`review`){i(e=>!e);return}let n=e===`watch`?`comment`:`watch`,a=await r(`mode`,X(`/api/mode`),{mode:n});!a.ok&&!a.queued?H(a.text||`Could not change mode`):(t(n),i(n!==`watch`))}(0,y.useEffect)(()=>c(`comment`,e=>{try{let t=JSON.parse(e.data);if(!t?.id||!t.partId)return;let n=p.current;q(e=>Z(e,t)),pe(n,t)}catch{}}),[]),(0,y.useEffect)(()=>{if(!u)return;let e=e=>{if(e.button!==0)return;let t=e.target;if(!(t instanceof Element)||t.closest(`[data-plan-grab-ignore]`)||!Ae(t))return;let n=ge(t);if(!n)return;e.preventDefault(),e.stopPropagation();let r=J(n);E(r),C(r),A(r.element.getBoundingClientRect()),H(``),O(!0)};return document.addEventListener(`click`,e,!0),()=>document.removeEventListener(`click`,e,!0)},[u]),(0,y.useEffect)(()=>{if(!u||D)return;let e=e=>{let t=document.elementFromPoint(e.clientX,e.clientY);if(!(t instanceof Element)||!Ae(t)){C(null);return}let n=ge(t),r=U.current?.element;if(!n){C(null);return}if(n===r)return;r||re({x:e.clientX,y:e.clientY});let i=J(n);C(i),A(i.element.getBoundingClientRect())};return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)},[u,D]),(0,y.useEffect)(()=>{if(!u||D)return;let e=e=>{if(e.key!==`ArrowUp`&&e.key!==`ArrowDown`)return;let t=e.target;if(t instanceof HTMLElement&&(t.closest(`input, textarea, select`)||t.isContentEditable))return;let n=U.current?.element;if(!n)return;let r=e.key===`ArrowUp`?ye(n):be(n);if(!r)return;e.preventDefault();let i=J(r);C(i),A(i.element.getBoundingClientRect())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[u,D]),(0,y.useEffect)(()=>{let e=e=>{if(e.key!==`c`&&e.key!==`C`||e.metaKey||e.ctrlKey||e.altKey||e.repeat)return;let t=e.target;t instanceof HTMLElement&&(t.closest(`input, textarea, select`)||t.isContentEditable)||(e.preventDefault(),_e())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[e,n]),(0,y.useEffect)(()=>{let e=e=>{let t=e.detail;t?.decision===`iterate`&&F({note:t.note,ids:(t.comments??[]).flatMap(e=>e.id?[e.id]:[])})};return window.addEventListener(`living-plan-review`,e),()=>window.removeEventListener(`living-plan-review`,e)},[]),(0,y.useEffect)(()=>{if(!P||L.current)return;let e=d.find(e=>P.ids.includes(e.id)&&e.addressingAt&&e.addressedAt==null);if(!e)return;let t=Y(e.partId);if(!t)return;L.current=!0;let n=J(t);E(n),C(n),A(t.getBoundingClientRect()),O(!0)},[P,d]),(0,y.useEffect)(()=>{if(!(u||G.length>0||D)){A(null),z([]);return}let e=0,t=()=>{let n=(D?W.current:U.current)?.element;if(n?.isConnected){let e=n.getBoundingClientRect();A(t=>t&&ke(t,e)?t:e)}else A(null);let r=new Map;for(let e of G){let t=r.get(e.partId)??{count:0,busy:!1};r.set(e.partId,{count:t.count+1,busy:t.busy||e.addressingAt!=null})}let i=[];for(let[e,t]of r){let n=Y(e);if(!n?.isConnected||n.closest(`[hidden]`))continue;let r=n.getBoundingClientRect();r.width<2&&r.height<2||i.push({partId:e,count:t.count,busy:t.busy,top:r.top-8,left:r.right-8})}z(e=>e.length===i.length&&e.every((e,t)=>e.partId===i[t]?.partId&&e.count===i[t]?.count&&e.busy===i[t]?.busy&&Math.abs(e.top-(i[t]?.top??0))<.5&&Math.abs(e.left-(i[t]?.left??0))<.5)?e:i),e=requestAnimationFrame(t)};return e=requestAnimationFrame(t),()=>cancelAnimationFrame(e)},[u,D,G]);function ve(e){let t=Y(e);if(!t)return;let n=J(t);E(n),A(n.element.getBoundingClientRect()),H(``),O(!0)}async function je(e){if(w){V(!0),H(``);try{let t=await r(`comment`,X(`/api/comments`),{partId:w.partId,kind:w.kind,blockId:xe(w.partId),excerpt:w.excerpt,text:e});if(!t.ok&&!t.queued)throw Error(t.text||`Could not send the comment`);let n=t.body;n?.comment&&q(e=>Z(e,n.comment))}catch(e){throw H(e instanceof Error?e.message:`Could not send the comment`),e}finally{V(!1)}}}async function Ne(e){let t=await r(`address`,X(`/api/comments/${encodeURIComponent(e)}/address`),{});if(!t.ok&&!t.queued)return;let n=t.body;n?.comment&&q(e=>Z(e,n.comment))}(0,y.useEffect)(()=>{let e=s(),n=()=>{};return o().then(r=>{if(!r?.available)return;let o=()=>{if(!r.hydrated)return;let n=r.plan(e.id),o=n?.mode;!navigator.onLine&&(o===`watch`||o===`comment`||o===`review`)&&o!==l.current&&(t(o),i(o!==`watch`));let s=r.comments(e.id);if(s.length===0&&!n)return;let c=new Set(a(s.filter(e=>e.pending),s.filter(e=>!e.pending))),u=s.filter(e=>!e.pending||c.has(e));q(()=>u.map(e=>e.comment))};o(),n=r.subscribe(o)}),()=>n()},[]);let Q=D?w:x,Pe=w?.excerpt.trim()||(w?w.kind.replaceAll(`-`,` `):`Comment`),Fe=!!(Q&&k);I.current=Fe;let $=Q&&k?{partId:Q.partId,rect:k,label:Ce(Q.kind,Q.excerpt),enterFrom:j}:M;return(0,y.useEffect)(()=>{Q&&k&&N({partId:Q.partId,rect:k,label:Ce(Q.kind,Q.excerpt),enterFrom:j})},[Q,k,j]),(0,T.jsxs)(T.Fragment,{children:[$?(0,T.jsx)(de,{partId:$.partId,rect:$.rect,label:$.label,enterFrom:$.enterFrom,visible:Fe,onExited:()=>{I.current||N(null)}}):null,oe.map(e=>(0,T.jsx)(we,{count:e.count,busy:e.busy,style:{top:e.top,left:e.left},onClick:()=>ve(e.partId)},e.partId)),(0,T.jsx)(se,{open:D,anchor:w?.element??null,title:Pe,excerpt:``,comments:ue,sending:B,error:le,freshReplyIds:m,onOpenChange:e=>{O(e),e||(E(null),b(!1))},onSend:je,onAddress:e=>void Ne(e),onReplySettled:fe}),(0,T.jsxs)(`div`,{className:`plan-corner-actions`,children:[(0,T.jsx)(ce,{enabled:u,onToggle:()=>void _e()}),e===`review`&&!P?(0,T.jsx)(ae,{onApprove:()=>void me()}):null]}),e===`review`||d.some(e=>te(e)===`minibar`)?(0,T.jsx)(ie,{sending:B,attentionKey:g,onSend:he,onReplySettled:fe,messages:Me(d,P,m)}):null]})}if(typeof document<`u`){let e=document.createElement(`div`);e.id=`plan-selector-root`,document.body.append(e),(0,b.createRoot)(e).render((0,T.jsx)(Ne,{}))}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comments oldest first, by the time they were submitted: the order the host stores them in. The
|
|
3
|
+
* device copy keeps rows by their random id, so the page cannot trust the order a source hands it.
|
|
4
|
+
* Comments with the same time keep the order they came in.
|
|
5
|
+
*/
|
|
6
|
+
export declare function inSubmissionOrder<T extends {
|
|
7
|
+
createdAt?: unknown;
|
|
8
|
+
}>(comments: readonly T[]): T[];
|
|
9
|
+
/** Comments newest first: the order the comment popover and the messages tray show them in. */
|
|
10
|
+
export declare function newestFirst<T extends {
|
|
11
|
+
createdAt?: unknown;
|
|
12
|
+
}>(comments: readonly T[]): T[];
|
|
13
|
+
/**
|
|
14
|
+
* A review note placed among messages listed newest first. The note was sent with the review, after
|
|
15
|
+
* the comments it carried, so it goes above the newest of them that is listed, or on top when none is.
|
|
16
|
+
*/
|
|
17
|
+
export declare function withReviewNote<T extends {
|
|
18
|
+
id: string;
|
|
19
|
+
}>(messages: readonly T[], note: T, carried: readonly string[]): T[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** When a comment was submitted. A comment without a time counts as the oldest. */
|
|
2
|
+
function submittedAt(comment) {
|
|
3
|
+
return typeof comment.createdAt === 'number' && Number.isFinite(comment.createdAt) ? comment.createdAt : 0;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Comments oldest first, by the time they were submitted: the order the host stores them in. The
|
|
7
|
+
* device copy keeps rows by their random id, so the page cannot trust the order a source hands it.
|
|
8
|
+
* Comments with the same time keep the order they came in.
|
|
9
|
+
*/
|
|
10
|
+
export function inSubmissionOrder(comments) {
|
|
11
|
+
return [...comments].sort((left, right) => submittedAt(left) - submittedAt(right));
|
|
12
|
+
}
|
|
13
|
+
/** Comments newest first: the order the comment popover and the messages tray show them in. */
|
|
14
|
+
export function newestFirst(comments) {
|
|
15
|
+
return inSubmissionOrder(comments).reverse();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A review note placed among messages listed newest first. The note was sent with the review, after
|
|
19
|
+
* the comments it carried, so it goes above the newest of them that is listed, or on top when none is.
|
|
20
|
+
*/
|
|
21
|
+
export function withReviewNote(messages, note, carried) {
|
|
22
|
+
const ids = new Set(carried);
|
|
23
|
+
const found = messages.findIndex((message) => ids.has(message.id));
|
|
24
|
+
const at = found === -1 ? 0 : found;
|
|
25
|
+
return [...messages.slice(0, at), note, ...messages.slice(at)];
|
|
26
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PlanHost } from '../planHost';
|
|
2
|
+
import { type OAuthStore } from './oauthStore';
|
|
3
|
+
export type McpEndpoint = {
|
|
4
|
+
/** Answer `/mcp`, the OAuth routes, and their discovery documents. Undefined for any other path. */
|
|
5
|
+
handle(request: Request, peer: string): Promise<Response | undefined>;
|
|
6
|
+
store: OAuthStore;
|
|
7
|
+
close(): Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The MCP server on the plan service: `/mcp` speaks MCP 2026-07-28 and the 2025 revisions, and takes
|
|
11
|
+
* only a bearer token from the built-in OAuth server. Tokens live in `mcp-oauth.sqlite` beside the
|
|
12
|
+
* registry, so a service restart keeps every agent signed in.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createMcpEndpoint(options: {
|
|
15
|
+
home: string;
|
|
16
|
+
planHost: PlanHost;
|
|
17
|
+
planUrl: (id: string) => string;
|
|
18
|
+
openPage: (url: string) => Promise<void>;
|
|
19
|
+
version: string;
|
|
20
|
+
}): McpEndpoint;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { bearerAuthChallengeResponse, createMcpHandler, OAuthError, OAuthErrorCode, verifyBearerToken, } from '@modelcontextprotocol/server';
|
|
2
|
+
import { recordLog } from '../serviceLog';
|
|
3
|
+
import { createOAuthServer, MCP_PATH } from './oauthServer';
|
|
4
|
+
import { MCP_SCOPE, oauthDatabasePath, openOAuthStore } from './oauthStore';
|
|
5
|
+
import { createPlanToolServer } from './planTools';
|
|
6
|
+
/**
|
|
7
|
+
* The MCP server on the plan service: `/mcp` speaks MCP 2026-07-28 and the 2025 revisions, and takes
|
|
8
|
+
* only a bearer token from the built-in OAuth server. Tokens live in `mcp-oauth.sqlite` beside the
|
|
9
|
+
* registry, so a service restart keeps every agent signed in.
|
|
10
|
+
*/
|
|
11
|
+
export function createMcpEndpoint(options) {
|
|
12
|
+
const store = openOAuthStore(oauthDatabasePath(options.home));
|
|
13
|
+
const oauth = createOAuthServer(store);
|
|
14
|
+
const verifier = {
|
|
15
|
+
async verifyAccessToken(token) {
|
|
16
|
+
const grant = store.verifyAccessToken(token);
|
|
17
|
+
if (!grant)
|
|
18
|
+
throw new OAuthError(OAuthErrorCode.InvalidToken, 'The token is not valid or has expired');
|
|
19
|
+
return { token, clientId: grant.clientId, scopes: [MCP_SCOPE], expiresAt: Math.floor(grant.expiresAt / 1000) };
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
const handler = createMcpHandler(() => createPlanToolServer({
|
|
23
|
+
planHost: options.planHost,
|
|
24
|
+
planUrl: options.planUrl,
|
|
25
|
+
openPage: options.openPage,
|
|
26
|
+
version: options.version,
|
|
27
|
+
}), {
|
|
28
|
+
// Always stream, so a long wait_for_events carries keep-alive frames instead of an idle socket.
|
|
29
|
+
responseMode: 'sse',
|
|
30
|
+
onerror: (error) => {
|
|
31
|
+
void recordLog({ level: 'warn', message: `MCP: ${error.message}`, source: 'server', echo: false }).catch(() => undefined);
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
async handle(request, peer) {
|
|
36
|
+
const answered = await oauth.handle(request, peer);
|
|
37
|
+
if (answered)
|
|
38
|
+
return answered;
|
|
39
|
+
if (new URL(request.url).pathname !== MCP_PATH)
|
|
40
|
+
return undefined;
|
|
41
|
+
const resourceMetadataUrl = oauth.resourceMetadataUrl(request);
|
|
42
|
+
let authInfo;
|
|
43
|
+
try {
|
|
44
|
+
authInfo = await verifyBearerToken(request.headers.get('authorization'), {
|
|
45
|
+
verifier,
|
|
46
|
+
requiredScopes: [MCP_SCOPE],
|
|
47
|
+
resourceMetadataUrl,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
return bearerAuthChallengeResponse(error, { requiredScopes: [MCP_SCOPE], resourceMetadataUrl });
|
|
52
|
+
}
|
|
53
|
+
return handler.fetch(request, { authInfo });
|
|
54
|
+
},
|
|
55
|
+
store,
|
|
56
|
+
async close() {
|
|
57
|
+
await handler.close();
|
|
58
|
+
store.close();
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type OAuthStore } from './oauthStore';
|
|
2
|
+
/** Where the MCP endpoint lives on the plan service. */
|
|
3
|
+
export declare const MCP_PATH = "/mcp";
|
|
4
|
+
export declare const PROTECTED_RESOURCE_PATH = "/.well-known/oauth-protected-resource";
|
|
5
|
+
export declare const AUTHORIZATION_SERVER_PATH = "/.well-known/oauth-authorization-server";
|
|
6
|
+
export declare const AUTHORIZE_PATH = "/oauth/authorize";
|
|
7
|
+
export declare const TOKEN_PATH = "/oauth/token";
|
|
8
|
+
export declare const REGISTER_PATH = "/oauth/register";
|
|
9
|
+
export declare const REVOKE_PATH = "/oauth/revoke";
|
|
10
|
+
export type OAuthServer = {
|
|
11
|
+
/** Answer an OAuth or discovery request. Undefined when the path is not one of them. */
|
|
12
|
+
handle(request: Request, peer: string): Promise<Response | undefined>;
|
|
13
|
+
/** The resource metadata URL a 401 from the MCP endpoint points to. */
|
|
14
|
+
resourceMetadataUrl(request: Request): string;
|
|
15
|
+
};
|
|
16
|
+
export declare function originOf(request: Request): string;
|
|
17
|
+
/**
|
|
18
|
+
* A redirect URI an agent may register: https anywhere, http only back to this computer, or an app's
|
|
19
|
+
* own scheme (RFC 8252). Never a fragment, and never a scheme a browser runs as code.
|
|
20
|
+
*/
|
|
21
|
+
export declare function allowedRedirectUri(value: unknown): value is string;
|
|
22
|
+
/** Exact match, except a loopback http redirect may use any port (RFC 8252 section 7.3). */
|
|
23
|
+
export declare function redirectMatches(registered: string, presented: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The OAuth 2.1 authorization server for the MCP endpoint, built into the plan service.
|
|
26
|
+
*
|
|
27
|
+
* Agents register themselves (RFC 7591), send the person to the consent page, and trade the code for
|
|
28
|
+
* tokens with PKCE. Only a browser on this computer can allow access, so a page reached over the LAN
|
|
29
|
+
* or through `--host` cannot grant it.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createOAuthServer(store: OAuthStore, options?: {
|
|
32
|
+
now?: () => number;
|
|
33
|
+
}): OAuthServer;
|