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
@@ -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