mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 20:45:33 -08:00
v3-orchestrator
This commit is contained in:
1 parent
7a4b7c6db8
commit
681c4a4b85
27 files changed
+1138
-36
No files matched your search
+144
-8
@@ -22,8 +22,12 @@
|
||||
* `--pick-folder` (passed by the desktop shortcut, never forwarded to the CLI) asks for the
|
||||
* project folder with a native folder picker first, starting on the folder picked last time.
|
||||
*
|
||||
* When the desktop app is installed (~/.plan2code/app/) and a display exists, `plan2code` opens
|
||||
* the app on the chosen folder, agent and model instead of running the agent in this terminal.
|
||||
* `--classic` (never forwarded to the CLI), no app, and no display on Linux keep the flow above.
|
||||
*
|
||||
* `plan2code update` starts no agent: it re-runs the npx install with `--update`, which
|
||||
* reinstalls whatever ~/.plan2code/install.json lists. Before an agent starts, one line says
|
||||
* reinstalls whatever ~/.plan2code/install.json lists (the desktop app included). Before an agent starts, one line says
|
||||
* when a newer release is out (releaseNotice), read from the web console's cached release check
|
||||
* and never waiting on the network.
|
||||
*
|
||||
@@ -42,6 +46,13 @@ const IS_WINDOWS = process.platform === 'win32';
|
||||
const IS_MAC = process.platform === 'darwin';
|
||||
const PICK_FOLDER_FLAG = '--pick-folder';
|
||||
const CLI_FLAG = '--cli';
|
||||
const CLASSIC_FLAG = '--classic';
|
||||
// Where install.js puts the desktop app, and the one file in it the launcher starts.
|
||||
// PLAN2CODE_APP names a different executable (the tests start a stand-in this way).
|
||||
const APP_DIR = path.join(os.homedir(), '.plan2code', 'app');
|
||||
const APP_FILE = IS_WINDOWS ? 'plan2code-app.exe' : 'plan2code-app';
|
||||
// How long a freshly started app may take to fall over before the launcher calls it started.
|
||||
const APP_START_GRACE_MS = 1200;
|
||||
const STATE_FILE = path.join(os.homedir(), '.plan2code', 'launcher.json');
|
||||
// Menus longer than this print compactly (id-only, two columns).
|
||||
const MODELS_MENU_COMPACT_AT = 30;
|
||||
@@ -541,6 +552,74 @@ async function chooseModel(cli, extraArgs) {
|
||||
}
|
||||
}
|
||||
|
||||
/** A window can open: assumed on Windows and macOS, and on Linux only with an X11 or Wayland display. */
|
||||
function hasDisplay() {
|
||||
// sshd sets one of these for an SSH login on both platforms, and there is no window to open
|
||||
// there. A plain background/service context (no SSH, no desktop) cannot be told apart from an
|
||||
// ordinary desktop login on Windows or macOS without a new dependency, so SSH is as far as this goes.
|
||||
if ((IS_WINDOWS || IS_MAC) && (process.env.SSH_CONNECTION || process.env.SSH_TTY)) return false;
|
||||
return IS_WINDOWS || IS_MAC || Boolean(process.env.DISPLAY || process.env.WAYLAND_DISPLAY);
|
||||
}
|
||||
|
||||
/** The installed desktop app's executable, or null when it is not installed. */
|
||||
function findApp() {
|
||||
const file = process.env.PLAN2CODE_APP || path.join(APP_DIR, APP_FILE);
|
||||
try {
|
||||
return fs.statSync(file).isFile() ? file : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** The model the forwarded arguments pick (`--model x`, `--model=x`, Codex's `-m x`), or null. */
|
||||
function modelFrom(args, cliId) {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i];
|
||||
if (arg === '--model' || (cliId === 'codex' && arg === '-m')) return args[i + 1] || null;
|
||||
if (arg.startsWith('--model=')) return arg.slice('--model='.length) || null;
|
||||
if (cliId === 'codex' && arg.startsWith('-m=')) return arg.slice(3) || null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the desktop app on the folder, agent and model and let it run on its own. Resolves true
|
||||
* once it has started, false (after one line saying why) when it could not, so the caller can
|
||||
* carry on with today's terminal flow.
|
||||
*/
|
||||
function startApp(app, { cwd, cliId, model }) {
|
||||
const args = ['--project', cwd, '--agent', cliId, ...(model ? ['--model', model] : [])];
|
||||
return new Promise((resolve) => {
|
||||
let child;
|
||||
try {
|
||||
child = spawnCommand(app, args, { cwd, detached: true, stdio: 'ignore' });
|
||||
} catch (error) {
|
||||
console.error(`${ce.yellow('plan2code:')} could not start the app (${error.message}); opening in this terminal instead.`);
|
||||
return resolve(false);
|
||||
}
|
||||
child.once('error', (error) => {
|
||||
console.error(`${ce.yellow('plan2code:')} could not start the app (${error.message}); opening in this terminal instead.`);
|
||||
resolve(false);
|
||||
});
|
||||
child.once('spawn', () => {
|
||||
// A program that starts and then dies (a missing system library is reported after the
|
||||
// exec, not as a spawn error) must not strand the person with a closed terminal: an exit
|
||||
// with a failure inside the grace period falls back to the terminal flow.
|
||||
const timer = setTimeout(() => {
|
||||
child.removeAllListeners('exit');
|
||||
child.unref();
|
||||
resolve(true);
|
||||
}, APP_START_GRACE_MS);
|
||||
child.once('exit', (code, signal) => {
|
||||
clearTimeout(timer);
|
||||
if (code === 0) return resolve(true);
|
||||
console.error(`${ce.yellow('plan2code:')} the app exited at once (${signal ? `signal ${signal}` : `code ${code}`}); opening in this terminal instead.`);
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The native folder picker for this OS, as a command to run: it prints the chosen folder, or
|
||||
* nothing when the person cancels. Null when this OS has no picker we can drive.
|
||||
@@ -588,7 +667,7 @@ function getPickerCommand(start) {
|
||||
};
|
||||
}
|
||||
|
||||
if (!process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) return null;
|
||||
if (!hasDisplay()) return null;
|
||||
if (findOnPath('zenity')) {
|
||||
return { command: 'zenity', args: ['--file-selection', '--directory', `--title=${PICKER_PROMPT}`, `--filename=${start}${path.sep}`] };
|
||||
}
|
||||
@@ -598,6 +677,39 @@ function getPickerCommand(start) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A git repo (a `.git` entry, file or directory since worktrees use a file), or has `AGENTS.md`
|
||||
* or a `specs/` folder: enough to call `dir` a project without asking first.
|
||||
*/
|
||||
function looksLikeProject(dir) {
|
||||
return (
|
||||
fs.existsSync(path.join(dir, '.git')) ||
|
||||
fs.existsSync(path.join(dir, 'AGENTS.md')) ||
|
||||
isDirectory(path.join(dir, 'specs'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* True to proceed with `cwd`: it already looks like a project, or the person confirmed it when
|
||||
* asked. Without a terminal to ask there is nobody to confirm, so it refuses rather than risk
|
||||
* opening the app (or the terminal flow) on the wrong folder.
|
||||
*/
|
||||
async function confirmProject(cwd) {
|
||||
if (looksLikeProject(cwd)) return true;
|
||||
if (!process.stdin.isTTY) {
|
||||
console.error(
|
||||
`${ce.yellow('plan2code:')} ${cwd} doesn't look like a project (no git repo, AGENTS.md or specs folder); run \`plan2code\` there from a terminal to confirm, or cd into a project first.`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
const answer = (
|
||||
await ask(`${c.yellow(cwd)} doesn't look like a project (no git repo, AGENTS.md or specs folder). Open Plan2Code there anyway? [y/N]: `)
|
||||
)
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
return answer === 'y' || answer === 'yes';
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask for the project folder: the native picker when there is one, a typed path otherwise.
|
||||
* Returns the folder, or null when the person cancelled.
|
||||
@@ -660,15 +772,24 @@ function spawnCommand(file, args, options) {
|
||||
: spawn(file, args, options);
|
||||
}
|
||||
|
||||
/** `plan2code update`: the npx install with --update, passing npx's exit code through. No agent starts. */
|
||||
function runUpdate() {
|
||||
/**
|
||||
* `plan2code update`: the npx install with --update, passing npx's exit code through. No agent
|
||||
* starts. That one install updates the skills, this launcher and the desktop app (when it is
|
||||
* installed) together, so the three never drift apart.
|
||||
*/
|
||||
/** `tag` pins the install to that release (the desktop app's own Update skills button, so it
|
||||
* never pulls in work a published release does not have yet); omitted, `plan2code update` keeps
|
||||
* pulling the latest off `main` as it always has. */
|
||||
function runUpdate(tag) {
|
||||
console.log('Updating Plan2Code...');
|
||||
console.log(c.dim('One update covers the skills, the plan2code command and the desktop app (when installed).'));
|
||||
const npx = findOnPath('npx');
|
||||
if (!npx) {
|
||||
console.error(`${ce.red('plan2code:')} npx was not found on your PATH. It comes with Node.js 18+ (https://nodejs.org).`);
|
||||
return process.exit(127);
|
||||
}
|
||||
const child = spawnCommand(npx, ['--yes', '--allow-git=all', `git+${REPO_URL}`, '--update'], { stdio: 'inherit' });
|
||||
const spec = tag ? `git+${REPO_URL}#${tag}` : `git+${REPO_URL}`;
|
||||
const child = spawnCommand(npx, ['--yes', '--allow-git=all', spec, '--update'], { stdio: 'inherit' });
|
||||
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
||||
process.on(signal, () => {});
|
||||
}
|
||||
@@ -723,9 +844,15 @@ async function releaseNotice() {
|
||||
|
||||
async function launch() {
|
||||
const argv = process.argv.slice(2);
|
||||
if (argv[0] === UPDATE_COMMAND) return runUpdate();
|
||||
if (argv[0] === UPDATE_COMMAND) {
|
||||
const tagAt = argv.indexOf('--tag');
|
||||
return runUpdate(tagAt >= 0 ? argv[tagAt + 1] : undefined);
|
||||
}
|
||||
const fromShortcut = argv.includes(PICK_FOLDER_FLAG);
|
||||
const { cli: requestedCli, rest: extraArgs } = takeCliFlag(argv.filter((arg) => arg !== PICK_FOLDER_FLAG));
|
||||
const classic = argv.includes(CLASSIC_FLAG);
|
||||
const { cli: requestedCli, rest: extraArgs } = takeCliFlag(
|
||||
argv.filter((arg) => arg !== PICK_FOLDER_FLAG && arg !== CLASSIC_FLAG)
|
||||
);
|
||||
|
||||
printIntro();
|
||||
await releaseNotice();
|
||||
@@ -746,8 +873,17 @@ async function launch() {
|
||||
console.log(`Opening Plan2Code in ${c.cyan(folder)}`);
|
||||
}
|
||||
|
||||
if (!(await confirmProject(cwd))) return process.exit(0);
|
||||
|
||||
if (!hasModelFlag(extraArgs, cli.id)) await chooseModel(cli, extraArgs);
|
||||
|
||||
// The app takes over from here when it is installed, a window can open and --classic is absent.
|
||||
const app = !classic && hasDisplay() ? findApp() : null;
|
||||
if (app && (await startApp(app, { cwd, cliId: cli.id, model: modelFrom(extraArgs, cli.id) }))) {
|
||||
console.log(`Opened the Plan2Code app in ${c.cyan(cwd)} ${c.dim('(run `plan2code --classic` to stay in this terminal)')}`);
|
||||
return process.exit(0);
|
||||
}
|
||||
|
||||
const args = cli.args(extraArgs);
|
||||
const options = { cwd, stdio: 'inherit' };
|
||||
|
||||
@@ -777,4 +913,4 @@ async function launch() {
|
||||
// Run only when invoked directly; requiring the file (the tests do) is load-only.
|
||||
if (require.main === module) launch();
|
||||
|
||||
module.exports = { mergeModels, modelEntries, renderBanner, paint, hasModelFlag, compareVersions };
|
||||
module.exports = { mergeModels, modelEntries, renderBanner, paint, hasModelFlag, compareVersions, modelFrom, hasDisplay, looksLikeProject };
|
||||
+1
-1
@@ -39,7 +39,7 @@ The page draws the cards itself — you never send the list. It also knows the r
|
||||
- `documented` ("Ready to build"): Implement is next.
|
||||
- `building` ("Building"): Implement is next.
|
||||
- `built` ("Ready to finalize"): Finalize is next.
|
||||
- A `documented` or `building` spec whose `[/]` phase file holds a waiting `**Plan change:**` line in its Notes (Implement paused for a revision; `(applied <date>):` or `(dropped <date>):` means done): recommend Revise the plan instead, `details` "Plan change waiting from Phase N". On a `built` spec the Revise card is greyed, so name the waiting brief in `note`.
|
||||
- A `documented` or `building` spec whose `[/]` phase file holds a waiting `**Plan change:**` line in its Notes (Implement paused for a revision; `(applied <date>):` or `(dropped <date>):` means done): recommend Revise the plan instead, `details` "Plan change waiting from Phase N". The Revise card is lit on a `built` spec too (a change found in the last manual checks): recommend it there only for a waiting brief, and say so in `note`; otherwise Finalize stays the next step.
|
||||
- A spec that scans `unrecognized` ("files on disk") is input, not progress: its folder rides along on a Pathfinder or Plan launch as reference, and those are the only pipeline cards it lights. Read the files and recommend the fit — a settled design doc the person wrote is Plan's brief, loose notes are Pathfinder's. No skill generates such a doc; see the table below for what each one does write. Never flag Document or anything downstream of it for such a spec.
|
||||
- A `diagnosed` spec ("Bug diagnosed") is a bug Diagnose wrote up: recommend Quick Task, or Plan when its `DIAGNOSIS-<date>.md` sizes the fix as big; its folder rides along on either launch.
|
||||
- A `fixed` spec ("Bug fixed") is a diagnosed bug Quick Task fixed but did not archive: finished, so never recommend for it or name it in the note; the picker never pre-selects one and hides it while unavailable workflows are hidden. The person archives it (Quick Task offers that once the bug is fixed) or deletes it with the picker's ✕.
|
||||
|
||||
@@ -51,6 +51,7 @@ import { readPrHosts, resetSubagentCursor } from "./settings.mjs";
|
||||
import { WORKFLOWS, isWorkflow } from "./public/skills.js";
|
||||
import { startsClean } from "./public/hops.js";
|
||||
import { snapshot } from "./git-repo.mjs";
|
||||
import { announcePage, currentSession, inAppSignal } from "./in-app.mjs";
|
||||
import { handoffsDir, listHandoffs, removeHandoffs, staleHandoffs } from "./handoffs.mjs";
|
||||
import {
|
||||
readPatch,
|
||||
@@ -95,6 +96,10 @@ function leavePointer() {
|
||||
}
|
||||
}
|
||||
|
||||
// Printed on every `open`: this console can be framed by the desktop app (the
|
||||
// embed mode, and the in-app signal). The app refuses a console without it.
|
||||
const EMBED_API = 1;
|
||||
|
||||
export async function cmdOpen() {
|
||||
trace("open: start");
|
||||
// A workflow the console does not know is refused first, before the pointer,
|
||||
@@ -105,6 +110,20 @@ export async function cmdOpen() {
|
||||
die(`unknown workflow "${args.workflow}"; one of: ${WORKFLOWS.join(", ")}`, 2);
|
||||
}
|
||||
leavePointer();
|
||||
// Under the desktop app the page belongs in the app's window: never the
|
||||
// browser, and (unless a session was named) the app's own session, so one
|
||||
// console serves the whole window. A session that is gone is simply not
|
||||
// reused: the open below makes a new one and announces its address.
|
||||
const inApp = inAppSignal();
|
||||
if (inApp) {
|
||||
args["no-open"] = true;
|
||||
const named = args.resume || args.session;
|
||||
if (!named) {
|
||||
// The window knows its current session; the environment's is only a fallback.
|
||||
const sid = path.basename((await currentSession(inApp)) || inApp.sid || "");
|
||||
if (sid && fs.existsSync(sessionDir(sid))) args.resume = sid;
|
||||
}
|
||||
}
|
||||
const { project, worktree, branch } = repoRoots();
|
||||
reapHandles(project);
|
||||
trace("open: project found");
|
||||
@@ -369,13 +388,16 @@ export async function cmdOpen() {
|
||||
// Reuse a live server if one is already serving this session.
|
||||
if (existing && (await reusable)) {
|
||||
if (!args["no-open"]) openBrowser(existing.url);
|
||||
const inAppReport = await tellApp(inApp, { url: existing.url, sid, workflow: state.workflow });
|
||||
const [owed, subCursor] = subagentsOwed();
|
||||
print({
|
||||
ok: true,
|
||||
sid,
|
||||
session: dir,
|
||||
url: existing.url,
|
||||
embed: EMBED_API,
|
||||
reused: true,
|
||||
...inAppReport,
|
||||
pendingResult: carried,
|
||||
terminalLine: terminalLine(existing.url),
|
||||
workspace,
|
||||
@@ -416,12 +438,18 @@ export async function cmdOpen() {
|
||||
const notes = [];
|
||||
if (remote.note) notes.push(remote.note);
|
||||
if (carried) notes.push("Answers are already waiting. Run `wait` to collect them.");
|
||||
const inAppReport = await tellApp(inApp, { url: handle.url, sid, workflow: state.workflow });
|
||||
if (inAppReport.inApp && !inAppReport.announced) {
|
||||
notes.push(`The app did not take the page. Open ${handle.url} in a browser, or press Reload in the app.`);
|
||||
}
|
||||
const [owed, subCursor] = subagentsOwed();
|
||||
print({
|
||||
ok: true,
|
||||
sid,
|
||||
session: dir,
|
||||
url: handle.url,
|
||||
embed: EMBED_API,
|
||||
...inAppReport,
|
||||
port: handle.port,
|
||||
pid: handle.pid,
|
||||
pendingResult: carried,
|
||||
@@ -437,6 +465,16 @@ export async function cmdOpen() {
|
||||
sweep();
|
||||
}
|
||||
|
||||
/**
|
||||
* Under the app, say which page to show; outside it, nothing and no keys.
|
||||
* The report rides on `open`'s output so the agent can tell what happened.
|
||||
*/
|
||||
async function tellApp(signal, page) {
|
||||
if (!signal) return {};
|
||||
const announced = signal.announce ? await announcePage(signal, page) : false;
|
||||
return { inApp: true, announced };
|
||||
}
|
||||
|
||||
/**
|
||||
* The workspace as `open` hands it to the agent, and the cursor seeded to
|
||||
* match: the agent now has the whole list, so no change up to here is owed.
|
||||
|
||||
@@ -382,6 +382,10 @@ A patch that breaks one is refused, exit `3`, with the reason:
|
||||
7. **`run`, `folderIssue` and `helpers` are well formed** (their topic files).
|
||||
8. **A doc's `version` never goes back.**
|
||||
9. **A finish `command` has no placeholders** (`<` or `>`).
|
||||
10. **Every note gets a reply.** A card whose thread ends with the person's own
|
||||
words stays that way until a patch adds an agent reply to it; settling or
|
||||
reopening it does not count. Exempt once the item is deleted, or the whole
|
||||
session is ending.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -665,6 +665,21 @@ export function validate(state) {
|
||||
if (recs.length > 1) problems.push(`item "${item.id}" marks ${recs.length} options recommended; at most one`);
|
||||
}
|
||||
|
||||
// A note on a card is unanswered the moment no agent words follow it in its
|
||||
// thread. Once that is true, no patch may move past it except one that
|
||||
// finally replies: deleting the item drops it from state.items before this
|
||||
// check ever sees it, and the session's own ending is exempt because
|
||||
// nothing further is coming to answer into.
|
||||
if (state.finish == null) {
|
||||
for (const item of state.items) {
|
||||
const thread = Array.isArray(item.thread) ? item.thread : [];
|
||||
const last = thread[thread.length - 1];
|
||||
if (isPlainObject(last) && last.who === "user") {
|
||||
problems.push(`item "${item.id}" has an unanswered note from the person; reply in its thread before this patch`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The dashboard's page is the menu: a card posted there is drawn nowhere,
|
||||
// yet counts as open (and keeps Stop live for a question nobody can see).
|
||||
if (state.workflow === "dashboard" && state.items.some((i) => isOpen(i))) {
|
||||
|
||||
@@ -66,3 +66,14 @@ connect();
|
||||
setTimeout(() => {
|
||||
if (!wakeHoldsChime) sound("sessionStart");
|
||||
}, 0);
|
||||
|
||||
// Inside the desktop app's frame, tell the app this page drew. A frame the
|
||||
// browser refused (or a server that died) never sends it, which is how the app
|
||||
// tells a blocked page from a slow one. The message carries no data.
|
||||
if (window.parent && window.parent !== window) {
|
||||
try {
|
||||
window.parent.postMessage({ plan2code: "console-ready" }, "*");
|
||||
} catch {
|
||||
/* no parent to tell */
|
||||
}
|
||||
}
|
||||
@@ -2610,7 +2610,7 @@
|
||||
the editor on open. -->
|
||||
<dialog class="modal notepad" id="notepad-modal" aria-labelledby="notepad-title">
|
||||
<h2 id="notepad-title">Notebook</h2>
|
||||
<p class="modal-blurb">A private space to keep track of notes, uploaded images related to your in-progress work on this project. Saved on this machine and <strong class="private-note">never shared to the AI Agent</strong>.</p>
|
||||
<p class="modal-blurb">A private space to keep track of notes and uploaded images related to your in-progress work on this project. Saved on this machine and <strong class="private-note">never shared to the AI Agent</strong>.</p>
|
||||
<div class="notepad-tabbar">
|
||||
<div class="notepad-tabs" id="notepad-tabs" role="tablist" aria-label="Notebook tabs"></div>
|
||||
<button type="button" class="btn small ghost notepad-tab-new" id="notepad-tab-new">+ New tab</button>
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
finish,
|
||||
} from "../selectors.js";
|
||||
import { hooks, page, redraw, saveNow } from "../state.js";
|
||||
import { el, approvalTip, mdInto, releasesLink, copyButton } from "../render.js";
|
||||
import { el, approvalTip, mdInto, releasesLink, copyButton, lightDismiss } from "../render.js";
|
||||
import { needsRoleNudge, ROLE_NOT_SET } from "../starters.js";
|
||||
import { looks, renderSwatches, saveLooks } from "../looks.js";
|
||||
import { RED_BANNER } from "../meter.js";
|
||||
@@ -990,6 +990,7 @@ export function wireDashboard() {
|
||||
$("update-done").addEventListener("click", () => $("update-modal").close());
|
||||
$("delete-cancel").addEventListener("click", () => $("delete-modal").close());
|
||||
$("handoff-close").addEventListener("click", () => $("handoff-modal").close());
|
||||
lightDismiss($("handoff-modal"));
|
||||
$("delete-go").addEventListener("click", deleteStep);
|
||||
$("delete-name").addEventListener("input", () => {
|
||||
$("delete-go").disabled = !deleteTarget || $("delete-name").value.trim() !== deleteTarget.name;
|
||||
|
||||
@@ -161,8 +161,8 @@ export const SKILLS = Object.freeze([
|
||||
builds: false, phased: false, metered: true, templates: false,
|
||||
weight: 1, started: "Revise plan started", ran: "Plan revised", resume: "overview",
|
||||
subagents: null,
|
||||
states: ["documented", "building"],
|
||||
greyed: { default: "Needs a spec that is already written up", built: "The spec is fully built" },
|
||||
states: ["documented", "building", "built"],
|
||||
greyed: { default: "Needs a spec that is already written up" },
|
||||
card: {
|
||||
group: "pipeline",
|
||||
chip: "Step 1b",
|
||||
|
||||
@@ -303,9 +303,10 @@
|
||||
.handoff-preview-next { margin: 0 0 16px; font-size: 14px; color: var(--ink); }
|
||||
.handoff-preview-actions { display: flex; flex-wrap: wrap; gap: 10px; }
|
||||
.handoff-preview-actions .btn.danger { margin-left: auto; }
|
||||
.modal.handoff-read { max-width: 720px; }
|
||||
.modal.handoff-read { width: min(960px, calc(100vw - 32px)); max-width: none; }
|
||||
.modal.handoff-read[open] { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
|
||||
.handoff-body { flex: 1; min-height: 0; overflow-y: auto; margin-top: 8px; }
|
||||
.handoff-body.md { max-width: none; }
|
||||
.modal.handoff-read .modal-actions { flex: none; }
|
||||
|
||||
/* A spec's Delete button sits beside its chip, not inside it: a button cannot
|
||||
|
||||
@@ -151,11 +151,14 @@ function signIn(req, res, ctx, url) {
|
||||
const given = url.pathname.slice(3).replace(/\/$/, "");
|
||||
if (!ctx.token || !timingSafeEq(given, ctx.token)) return send(res, 403, "Not found", "text/plain");
|
||||
ctx.touch();
|
||||
// Inside the app's frame the page is cross-site, and SameSite=Strict would
|
||||
// never be sent back, so embed mode loosens the cookie to None; Secure, which
|
||||
// loopback counts as a trustworthy origin for. Anywhere else it stays Strict.
|
||||
res.writeHead(
|
||||
302,
|
||||
baseHeaders({
|
||||
location: "/",
|
||||
"set-cookie": `${cookieName(ctx)}=${ctx.token}; HttpOnly; SameSite=Strict; Path=/`,
|
||||
"set-cookie": `${cookieName(ctx)}=${ctx.token}; HttpOnly; ${embedAncestor() === "'none'" ? "SameSite=Strict" : "SameSite=None; Secure"}; Path=/`,
|
||||
})
|
||||
);
|
||||
return res.end();
|
||||
@@ -163,6 +166,22 @@ function signIn(req, res, ctx, url) {
|
||||
|
||||
/* -------------------------------------------------------- the page itself */
|
||||
|
||||
// PLAN2CODE_EMBED_ORIGIN is an opt-in widening of frame-ancestors for a shell
|
||||
// that embeds the page. The whole value must be exactly one allowed origin:
|
||||
// a loopback http origin with a real port, or one of the three tauri origins,
|
||||
// which name the embedding app page itself (that page is not on 127.0.0.1).
|
||||
// Anything else (a list, a wildcard, a bare host, another scheme) is ignored
|
||||
// and the directive keeps 'none'.
|
||||
function embedAncestor() {
|
||||
const value = process.env.PLAN2CODE_EMBED_ORIGIN;
|
||||
if (!value) return "'none'";
|
||||
if (value === "http://tauri.localhost" || value === "https://tauri.localhost" || value === "tauri://localhost") return value;
|
||||
const m = /^http:\/\/(127\.0\.0\.1|localhost):(\d{1,5})$/.exec(value);
|
||||
if (!m) return "'none'";
|
||||
const port = Number(m[2]);
|
||||
return port >= 1 && port <= 65535 ? value : "'none'";
|
||||
}
|
||||
|
||||
function page(req, res, ctx) {
|
||||
let html;
|
||||
try {
|
||||
@@ -176,7 +195,7 @@ function page(req, res, ctx) {
|
||||
const csp =
|
||||
"default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' data:; " +
|
||||
"font-src 'self'; connect-src 'self'; media-src 'self'; " +
|
||||
"base-uri 'none'; form-action 'none'; frame-ancestors 'none'";
|
||||
"base-uri 'none'; form-action 'none'; frame-ancestors " + embedAncestor();
|
||||
return send(res, 200, html, TYPES[".html"], { "content-security-policy": csp });
|
||||
}
|
||||
|
||||
|
||||
@@ -344,9 +344,10 @@ export async function removeScratch(consoleDir, names) {
|
||||
// console, the launcher (bin/, launcher.json), the install record that
|
||||
// `plan2code update` reads (install.json), the models the person added and
|
||||
// the handoffs (old ones go one by one, by age, on open: handoffs.mjs) and
|
||||
// the notepads, removed only one at a time through Cleanup (notepads.mjs).
|
||||
// the notepads, removed only one at a time through Cleanup (notepads.mjs), and
|
||||
// the desktop app (app/, which install.js fills, and app.json, its settings).
|
||||
const KEPT_CONSOLE_ENTRIES = new Set([...PROTECTED_CONSOLE_FILES, "sessions", "runtime"]);
|
||||
export const KEPT_PLAN2CODE_ENTRIES = new Set(["console", "bin", "launcher.json", "install.json", "models.json", "handoffs", "notepads"]);
|
||||
export const KEPT_PLAN2CODE_ENTRIES = new Set(["console", "bin", "launcher.json", "install.json", "models.json", "handoffs", "notepads", "app", "app.json"]);
|
||||
// A stray must sit untouched this long before Cleanup lists it. The same
|
||||
// folders hold files that live for milliseconds -- a held
|
||||
// `workspaces.json.lock`, a `<file>.<pid>.tmp` between its write and its
|
||||
|
||||
Reference in new issue
Block a user