mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 04:45:33 -08:00
Carry the spec into the app's New Session and name it beside the meter
AI Assisted
This commit is contained in:
1 parent
7856618a4c
commit
7891c06642
14 files changed
+320
-6
No files matched your search
@@ -17,6 +17,7 @@ Optional local browser UI shipped with **every** skill. Source lives in `src/web
|
||||
| `in-app.mjs` | the desktop app's signal to `open`: `inAppSignal()` reads `PLAN2CODE_IN_APP`, `PLAN2CODE_CONSOLE_SID`, `PLAN2CODE_APP_ANNOUNCE` and `PLAN2CODE_APP_TOKEN`; `announcePage()` POSTs the page to that window's loopback endpoint. Under the app `open` never starts a browser, resumes the app's session and announces the page; with the variables unset nothing here runs. Imported by `cmd-open.mjs` |
|
||||
| `open-link.mjs` | the desktop app's webview opens no new windows, so the page there sends links off the console (`linkLeavesPage()` in `public/app-bridge.js`: http or https on another origin, caught in `wireChrome()`) to `POST /open-link`. `linkToOpen()` takes http and https only (400 otherwise); `openLink()` starts the default browser with the link as one argument, never through a shell (`rundll32 url.dll,FileProtocolHandler` on Windows, `open` on macOS, `$BROWSER` or `xdg-open` elsewhere) and skips it under `PLAN2CODE_NO_BROWSER`. When that fails the page shows the link with a Copy button to paste into a browser |
|
||||
| `loop-setup.mjs` | the Implementation Loop's setup, remembered per project in `~/.plan2code/console/loop-setup.json` (one entry per folded project folder, schema 1): defaults, validation and the read and write the `/loop-setup` route uses. The app reads the same file itself for the quick check, so the page never carries that command |
|
||||
| `spec-carry.mjs` | the spec a desktop app's New Session carries to the fresh dashboard: one short-lived `~/.plan2code/console/spec-carry.json` (`{project, spec, at}`), written by `restart_brief::leave_spec` in the app from the old session's `specDir` (or, from a dashboard, its picker's `specSel` in the draft), taken once by `POST /spec-carry` (`takeSpecCarry`: same folded project, under ten minutes old, one folder under `specs/`) and used by `loadSpecCarry()` in `selectors.js` only when the new picker lists that spec |
|
||||
| `cmd-post-wait.mjs` | `post` and `wait`: publish a patch, then collect what the person sent |
|
||||
| `cmd-small.mjs` | the small commands: keep, forget, delete-spec, handoff, delete-handoff, status and stop; `handoff new` refuses an unknown `--workflow` the same way `open` does |
|
||||
| `files.mjs` | where the console's files live, how they are written safely, and the argument parser both command lines share |
|
||||
@@ -43,5 +44,5 @@ Optional local browser UI shipped with **every** skill. Source lives in `src/web
|
||||
| `update-check.mjs` | the dashboard's release check, server-only (never in `SERVABLE`): `compareVersions()` (numeric X.Y.Z, `null` otherwise), `latestTag()` (the highest `refs/tags/vX.Y.Z`, peeled `^{}` and pre-release tags skipped), `checkForUpdate({ installed, cacheFile, now, run })` (never throws) and `runLsRemote()` (`git ls-remote --tags` on the repo: no shell, `GIT_TERMINAL_PROMPT=0`, `GCM_INTERACTIVE=never`, SSH `BatchMode` when `GIT_SSH_COMMAND` is unset, `windowsHide`, killed at 10 s; git authenticates itself, the console never touches a credential). The answer, failures included, is cached for an hour in `~/.plan2code/console/update-check.json` (`UPDATE_CHECK_FILE`, in `PROTECTED_CONSOLE_FILES` so no sweep removes it). `server.mjs` starts it after the ready line and never awaits it; `stateFrame()` carries `update: { installed, latest }` only when a newer release exists (its `latest` is part of `haveKey()`, so a page that connected first still gets it), and `GET /version` returns `{ version, latest }`. Tests seed a fresh cached failure in every console home, so no test server reaches the network. The `plan2code` launcher reads the same cache for its terminal release notice (a copy of this module sits in `~/.plan2code/bin/`) |
|
||||
| `console.md` | the core of the agent-facing contract, read once per conversation (every skill ships the same copy, so a dashboard hop never re-reads it): starting, the turn (`post --wait`, the exit codes, handling a send, `settle`), posting, the payload and its kinds, documents (including `file` blocks), the house rules, and an index of the topic files below with the moment each is read. A test caps it at 24,000 characters |
|
||||
| `console-finish.md` · `console-stop.md` · `console-chat.md` · `console-workspace.md` · `console-subagents.md` · `console-launches.md` · `console-meter.md` · `console-attachments.md` · `console-trouble.md` | topic files, each read only when its moment first comes: finishing (the finish and its buttons), stop requests (the way home mid-workflow, `stopWarning`, resuming a pause), Quick questions, the Workspace, standing instructions and helper reports, dashboard launches and the menu payload, the session meter's `run` events (read only when a `run` is refused: the notes inline every `run`), keeping a cited note attachment, and recovery |
|
||||
| `notes/<workflow>.md` | per-workflow notes (`init` for both inits, `pathfinder` with Briefs, `plan`, `revise-plan`, `document`, `implement` for both builds, `loop` for a build the desktop app's Implementation Loop runs with `--loop` (where it reports a `loopOutcome` instead of asking for sign-off), `quick-task`, `review`, `finalize`, `handoff`, `changelog`, `git`, `xray`, `diagnose`, `pr-prep`, `test`). Each skill's Interface line reads `<D>/console.md` and its own notes file right after `open`; a test checks every skill names one that exists |
|
||||
| `notes/<workflow>.md` | per-workflow notes (`init` for both inits, `pathfinder` with Briefs, `plan`, `revise-plan`, `document`, `implement` for both builds, `loop` for a build the desktop app's Implementation Loop runs with `--loop` (where it reports a `loopOutcome` instead of asking for sign-off), `quick-task`, `review`, `finalize`, `handoff`, `changelog`, `git`, `xray`, `diagnose`, `pr-prep`, `test`, `dead-code`). Each skill's Interface line reads `<D>/console.md` and its own notes file right after `open`; a test checks every skill names one that exists |
|
||||
| `building.md` · `building-review.md` | the build half of the contract, for `implement`, `implement-review` and `quick-task`: progress posts (`agent.activity`, `agent.quietMinutes`, `file` blocks re-read with `refresh`), the chat check between tasks, questions mid-build and stop requests; `building-review.md` is the review run on the page (the sign-off's `review` verdict, **Review it now**, Implement + Review's Stage 2, Finalize's Step 2.5), read only when asked for |
|
||||
@@ -265,6 +265,9 @@ fn before_fresh_hook(state: &AppState) -> BeforeFresh {
|
||||
.lock()
|
||||
.ok()
|
||||
.and_then(|guard| guard.as_ref().map(|sup| sup.session().sid.clone()));
|
||||
if let (Some(sid), Some(home)) = (sid.as_deref(), session_reader::console_home()) {
|
||||
restart_brief::leave_spec(&home, sid, chrono::Utc::now().timestamp_millis());
|
||||
}
|
||||
let note = sid.and_then(|sid| restart_brief::note_for_restart(&sid));
|
||||
if let Ok(guard) = announce.lock() {
|
||||
if let Some(server) = guard.as_ref() {
|
||||
|
||||
@@ -65,6 +65,39 @@ pub fn leave_brief(
|
||||
handoff::write(handoffs, when, &record, &body).map(Some)
|
||||
}
|
||||
|
||||
/// The spec session `sid` was on, if the fresh dashboard's picker can offer
|
||||
/// it: a skill's `specDir`, or, from the dashboard itself, the spec its picker
|
||||
/// had selected (the page's draft keeps it as `specSel`).
|
||||
pub fn spec_in(console_home: &Path, sid: &str) -> Option<String> {
|
||||
let session = session_reader::load(console_home, sid).ok()?;
|
||||
let spec = if text(&session.state, "workflow") == Some("dashboard") {
|
||||
let draft = std::fs::read_to_string(session.dir.join("draft.json")).ok()?;
|
||||
let draft: Value = serde_json::from_str(&draft).ok()?;
|
||||
text(&draft, "specSel")?.to_string()
|
||||
} else {
|
||||
text(&session.state, "specDir")?.to_string()
|
||||
};
|
||||
valid_spec(&spec).then_some(spec)
|
||||
}
|
||||
|
||||
/// Leave the spec session `sid` was on for the next dashboard in the same
|
||||
/// folder (the web console's `spec-carry.mjs` reads and removes it). A hint
|
||||
/// only: nothing here fails a Restart, a failed write loses the preselection.
|
||||
pub fn leave_spec(console_home: &Path, sid: &str, now_ms: i64) {
|
||||
let Some(spec) = spec_in(console_home, sid) else {
|
||||
return;
|
||||
};
|
||||
let Ok(session) = session_reader::load(console_home, sid) else {
|
||||
return;
|
||||
};
|
||||
let Some(worktree) = text(&session.state, "worktree") else {
|
||||
return;
|
||||
};
|
||||
let entry = serde_json::json!({ "project": worktree, "spec": spec, "at": now_ms });
|
||||
let _ = std::fs::create_dir_all(console_home);
|
||||
let _ = std::fs::write(console_home.join("spec-carry.json"), entry.to_string());
|
||||
}
|
||||
|
||||
/// The bar's line for a Restart on session `sid`, written to the real console
|
||||
/// and handoff folders. `None` when there was nothing to leave.
|
||||
pub fn note_for_restart(sid: &str) -> Option<String> {
|
||||
@@ -199,6 +232,44 @@ mod tests {
|
||||
assert!(doc.contains("Phase 5: Restart brief: 4 of 11 done."));
|
||||
}
|
||||
|
||||
fn carried(home: &Path) -> Option<Value> {
|
||||
let text = fs::read_to_string(home.join("spec-carry.json")).ok()?;
|
||||
serde_json::from_str(&text).ok()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_skill_session_carries_its_spec_to_the_next_dashboard() {
|
||||
let (home, project, _) = session("carry-skill", "implement", Some("specs/feature"));
|
||||
leave_spec(&home, "s1", 1234);
|
||||
let entry = carried(&home).expect("a carry file");
|
||||
assert_eq!(entry["spec"], "specs/feature");
|
||||
assert_eq!(entry["project"], project.to_string_lossy().as_ref());
|
||||
assert_eq!(entry["at"], 1234);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_dashboard_session_carries_the_spec_its_picker_had() {
|
||||
let (home, _, _) = session("carry-dash", "dashboard", None);
|
||||
let draft = home.join("sessions").join("s1").join("draft.json");
|
||||
fs::write(&draft, r#"{"specSel":"specs/other"}"#).unwrap();
|
||||
leave_spec(&home, "s1", 1);
|
||||
assert_eq!(carried(&home).unwrap()["spec"], "specs/other");
|
||||
// Start from scratch, a handoff pick and an untouched picker carry nothing.
|
||||
for body in [r#"{"specSel":null}"#, r#"{"specSel":"handoff:x"}"#, "{}"] {
|
||||
let _ = fs::remove_file(home.join("spec-carry.json"));
|
||||
fs::write(&draft, body).unwrap();
|
||||
leave_spec(&home, "s1", 1);
|
||||
assert!(carried(&home).is_none(), "{body}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_session_with_no_spec_carries_nothing() {
|
||||
let (home, _, _) = session("carry-none", "quick-task", None);
|
||||
leave_spec(&home, "s1", 1);
|
||||
assert!(carried(&home).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_dashboard_session_leaves_nothing() {
|
||||
let (home, _, handoffs) = session("dashboard", "dashboard", None);
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// The page side of the spec an app's New Session carries: loadSpecCarry() in selectors.js.
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { page } from "../src/web-console/public/state.js";
|
||||
import { loadSpecCarry } from "../src/web-console/public/selectors.js";
|
||||
|
||||
const specs = [
|
||||
{ dir: "specs/a", name: "a", state: "building" },
|
||||
{ dir: "specs/b", name: "b", state: "planned" },
|
||||
];
|
||||
|
||||
// loadSpecCarry asks once per page, so each case is a fresh module copy.
|
||||
async function fresh() {
|
||||
return (await import(`../src/web-console/public/selectors.js?${Math.random()}`)).loadSpecCarry;
|
||||
}
|
||||
|
||||
function setup({ spec, sel } = {}) {
|
||||
page.S = { workflow: "dashboard", scan: { specs } };
|
||||
page.local = sel === undefined ? {} : { specSel: sel };
|
||||
globalThis.localStorage = { setItem() {}, getItem: () => null, removeItem() {} };
|
||||
const calls = [];
|
||||
globalThis.fetch = async (url, init) => {
|
||||
calls.push([url, init && init.method]);
|
||||
return { status: 200, json: async () => ({ spec }) };
|
||||
};
|
||||
return calls;
|
||||
}
|
||||
|
||||
test("a carried spec the picker lists becomes the pick", async () => {
|
||||
setup({ spec: "specs/b" });
|
||||
await (await fresh())();
|
||||
assert.equal(page.local.specSel, "specs/b");
|
||||
});
|
||||
|
||||
test("a carried spec the picker does not list leaves the default", async () => {
|
||||
setup({ spec: "specs/gone" });
|
||||
await (await fresh())();
|
||||
assert.equal("specSel" in page.local, false);
|
||||
});
|
||||
|
||||
test("a pick the person already made is never replaced, or even asked about", async () => {
|
||||
const calls = setup({ spec: "specs/b", sel: null });
|
||||
await (await fresh())();
|
||||
assert.equal(page.local.specSel, null);
|
||||
assert.equal(calls.length, 0);
|
||||
});
|
||||
|
||||
test("it asks once per page", async () => {
|
||||
const calls = setup({ spec: undefined });
|
||||
const load = await fresh();
|
||||
await load();
|
||||
await load();
|
||||
assert.equal(calls.length, 1);
|
||||
assert.deepEqual(calls[0], ["/spec-carry", "POST"]);
|
||||
assert.equal(typeof loadSpecCarry, "function");
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
// The spec an app's New Session carries to the fresh dashboard (spec-carry.mjs).
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
import { takeSpecCarry, SPEC_CARRY_MAX_AGE_MS } from "../src/web-console/spec-carry.mjs";
|
||||
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "spec-carry-"));
|
||||
const file = path.join(dir, "spec-carry.json");
|
||||
const put = (entry) => fs.writeFileSync(file, JSON.stringify(entry));
|
||||
const NOW = 1_000_000_000;
|
||||
|
||||
test("a fresh hint for this folder is taken once", () => {
|
||||
put({ project: dir, spec: "specs/feature", at: NOW });
|
||||
assert.equal(takeSpecCarry(dir, NOW + 1000, file), "specs/feature");
|
||||
assert.equal(fs.existsSync(file), false);
|
||||
assert.equal(takeSpecCarry(dir, NOW + 1000, file), null);
|
||||
});
|
||||
|
||||
test("a stale hint is dropped, not used", () => {
|
||||
put({ project: dir, spec: "specs/feature", at: NOW });
|
||||
assert.equal(takeSpecCarry(dir, NOW + SPEC_CARRY_MAX_AGE_MS + 1, file), null);
|
||||
assert.equal(fs.existsSync(file), false);
|
||||
});
|
||||
|
||||
test("another folder's fresh hint stays for its own dashboard", () => {
|
||||
put({ project: path.join(dir, "elsewhere"), spec: "specs/feature", at: NOW });
|
||||
assert.equal(takeSpecCarry(dir, NOW, file), null);
|
||||
assert.equal(fs.existsSync(file), true);
|
||||
});
|
||||
|
||||
test("a spec that is not directly under specs/ is refused", () => {
|
||||
for (const spec of ["../x", "specs/a/b", "specs/.hidden", "other", 5]) {
|
||||
put({ project: dir, spec, at: NOW });
|
||||
assert.equal(takeSpecCarry(dir, NOW, file), null, String(spec));
|
||||
}
|
||||
});
|
||||
|
||||
test("no file, or a broken one, is no hint", () => {
|
||||
fs.rmSync(file, { force: true });
|
||||
assert.equal(takeSpecCarry(dir, NOW, file), null);
|
||||
fs.writeFileSync(file, "{nope");
|
||||
assert.equal(takeSpecCarry(dir, NOW, file), null);
|
||||
});
|
||||
@@ -365,6 +365,7 @@ test("the scratch sweep removes old patches and helpers, never looks, the pointe
|
||||
file("looks.json"),
|
||||
file("workspaces.json"),
|
||||
file("loop-setup.json"),
|
||||
file("spec-carry.json"),
|
||||
file("loop-reports.json"),
|
||||
file("subagents.json"),
|
||||
file("pr-hosts.json"),
|
||||
@@ -381,7 +382,7 @@ test("the scratch sweep removes old patches and helpers, never looks, the pointe
|
||||
const stale = staleScratch(dir, Date.now(), SESSION_MAX_AGE_MS).sort();
|
||||
assert.deepEqual(stale, ["helper.mjs", "p2.json"]);
|
||||
assert.deepEqual(
|
||||
(await removeScratch(dir, [...stale, "looks.json", "workspaces.json", "loop-setup.json", "loop-reports.json", "subagents.json", "pr-hosts.json", "../p.json", "console-dir", "update-check.json"])).sort(),
|
||||
(await removeScratch(dir, [...stale, "looks.json", "workspaces.json", "loop-setup.json", "loop-reports.json", "subagents.json", "spec-carry.json", "pr-hosts.json", "../p.json", "console-dir", "update-check.json"])).sort(),
|
||||
["helper.mjs", "p2.json"]
|
||||
);
|
||||
for (const p of removable) assert.equal(fs.existsSync(p), false, p);
|
||||
@@ -392,6 +393,7 @@ test("the scratch sweep removes old patches and helpers, never looks, the pointe
|
||||
"loop-reports.json",
|
||||
"loop-setup.json",
|
||||
"pr-hosts.json",
|
||||
"spec-carry.json",
|
||||
"subagents.json",
|
||||
"update-check.json",
|
||||
"workspaces.json",
|
||||
|
||||
@@ -193,7 +193,7 @@ const ROUTE_ORDER = [
|
||||
"/notepad", "/notepad/text", "/notepad/image", "/notepad/thumb", "/notepad/image/delete", "/notepad/tab",
|
||||
"/notepad/tab/rename", "/notepad/tab/delete", "/notepad/tab/order", "/notepad/tab/last", "/notepad/tab/sent", "/notepad/images/",
|
||||
"/attachments/", "/shots/", "/uploads/", "/submit", "/open-link", "/chat", "/chat/decision", "/workspace",
|
||||
"WORKSPACE_EDITS", "/workspace/scope", "/workspace/browse", "/loop-setup", "/loop-setup", "/cancel", "/ping", "/bye",
|
||||
"WORKSPACE_EDITS", "/workspace/scope", "/workspace/browse", "/loop-setup", "/loop-setup", "/spec-carry", "/cancel", "/ping", "/bye",
|
||||
];
|
||||
|
||||
test("shape: routes.mjs lists every URL the server answers, in order", () => {
|
||||
|
||||
@@ -145,6 +145,9 @@
|
||||
<button type="button" class="linky" id="meter-help">What is this?</button>
|
||||
</div>
|
||||
</span>
|
||||
<!-- The spec this session works on (the dashboard picker's pick on the
|
||||
dashboard), quiet beside the meter. Hidden when there is none. -->
|
||||
<span class="spec-tag" id="spec-tag" hidden></span>
|
||||
</div>
|
||||
<div class="progress-block">
|
||||
<div class="progress-label">
|
||||
@@ -436,6 +439,13 @@
|
||||
<path d="M10 3v14.5a2 2 0 0 0 4 0V3" />
|
||||
<path d="M10 12h4" />
|
||||
</symbol>
|
||||
<!-- Clear out dead code: a skull. -->
|
||||
<symbol id="ci-dead-code" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M12 3a7 7 0 0 0-7 7c0 2.4 1.2 4.1 3 5.2V18a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1v-2.8c1.8-1.1 3-2.8 3-5.2a7 7 0 0 0-7-7z" />
|
||||
<circle cx="9.5" cy="11" r="1.5" />
|
||||
<circle cx="14.5" cy="11" r="1.5" />
|
||||
<path d="M10 19v2M12 19v2M14 19v2" />
|
||||
</symbol>
|
||||
<!-- Changelog: a version tag. -->
|
||||
<symbol id="ci-changelog" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M3 4a1 1 0 0 1 1-1h7.6a2 2 0 0 1 1.4.6l7.4 7.4a2 2 0 0 1 0 2.8l-5.6 5.6a2 2 0 0 1-2.8 0L4.6 12a2 2 0 0 1-.6-1.4z" />
|
||||
@@ -901,6 +911,35 @@
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
<!-- Dead code: clearing out code nothing uses. He holds up a small
|
||||
skull whose jaw chatters, his star glancing over at it, before it
|
||||
settles and the chatter starts again. -->
|
||||
<svg class="pose pose-dead-code" data-pose="dead-code" viewBox="0 4 240 216" aria-hidden="true" focusable="false">
|
||||
<ellipse class="shadow" cx="126" cy="198" rx="44" ry="5" />
|
||||
<g class="bob">
|
||||
<g class="dd-skull">
|
||||
<g class="dd-jaw">
|
||||
<rect class="dd-bone" x="176" y="112" width="22" height="16" rx="5" />
|
||||
<line class="lt" x1="183" y1="120" x2="183" y2="127" />
|
||||
<line class="lt" x1="191" y1="120" x2="191" y2="127" />
|
||||
</g>
|
||||
<path class="dd-bone" d="M187 88 A17 17 0 0 0 170 105 C170 112 173 116 178 119 L196 119 C201 116 204 112 204 105 A17 17 0 0 0 187 88 Z" />
|
||||
<circle class="fl" cx="180" cy="105" r="4.5" />
|
||||
<circle class="fl" cx="194" cy="105" r="4.5" />
|
||||
<path class="fl" d="M187 110 L184.5 115 L189.5 115 Z" />
|
||||
</g>
|
||||
<g transform="translate(-14 0)">
|
||||
<rect class="fl foot f1" x="94" y="179" width="20" height="10" rx="5" />
|
||||
<rect class="fl foot f2" x="126" y="179" width="20" height="10" rx="5" />
|
||||
<rect class="sh" x="80" y="72" width="80" height="108" rx="16" />
|
||||
<path class="ln" d="M80 126 L66 150" /><circle class="fl" cx="66" cy="150" r="5.5" />
|
||||
<g class="dd-look"><path class="ey blink" d="M126 86 L129.64 94.98 L139.31 95.67 L131.9 101.92 L134.23 111.33 L126 106.2 L117.77 111.33 L120.1 101.92 L112.69 95.67 L122.36 94.98 Z" /></g>
|
||||
<path class="es" d="M110 120 Q122 129 134 120" />
|
||||
<line class="ln" x1="160" y1="126" x2="196" y2="136" />
|
||||
<circle class="fl" cx="200" cy="136" r="5.5" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
<!-- Agent setup: waving hello at a terminal window, its prompt waiting
|
||||
for the command line that brings an agent. -->
|
||||
<svg class="pose pose-setup" data-pose="setup" viewBox="0 4 240 216" aria-hidden="true" focusable="false">
|
||||
|
||||
@@ -54,8 +54,8 @@ import { helperRows, showTab } from "../subagents.js";
|
||||
import { FOOTER_TIERS, footerLabel } from "../workspace.js";
|
||||
import {
|
||||
activity, agentAdrift, agentWorking, askBusy, loopDriving, loopWaiting, loopWaitingKey, asked, awaitingReply, byId, dashboardLive, docs, doingNow,
|
||||
AGENTS_VIEW, agentsTabShown, finish, gitAwaiting, isDashboard, isGitBoard, isOpen, isSpecFileView, items, loadAgentsDoc, loadOverview, myTurn, openItems,
|
||||
finishKey, patience, pressStranded, reviewPending, scan, selSpec, sendCollected, specFileTabs, stagedCount, stranded,
|
||||
AGENTS_VIEW, agentsTabShown, finish, gitAwaiting, isDashboard, isGitBoard, isOpen, isSpecFileView, items, loadAgentsDoc, loadOverview, loadSpecCarry, myTurn, openItems,
|
||||
finishKey, overviewSpec, patience, pressStranded, reviewPending, scan, selSpec, sendCollected, specFileTabs, stagedCount, stranded,
|
||||
topics, workingMs, WORKING_GRACE_MS,
|
||||
workspaceFolders,
|
||||
} from "../selectors.js";
|
||||
@@ -550,6 +550,8 @@ export function adopt(body) {
|
||||
// A spec file tab's file changes under a build, so a tab you are watching
|
||||
// refetches on every new frame too, not only on the click that opened it.
|
||||
if (firstLoad || page.S.specDir !== prevSpecDir || page.S.workflow !== prevWorkflow || isSpecFileView(page.view)) loadOverview();
|
||||
// A New Session in the app leaves the spec it was in; the fresh dashboard picks it up once its scan is here.
|
||||
loadSpecCarry();
|
||||
// The Dashboard's AGENTS.md tab: found on arrival, re-read while it is open.
|
||||
if (firstLoad || page.S.workflow !== prevWorkflow || page.view === AGENTS_VIEW) loadAgentsDoc();
|
||||
if (announce) showArrival(announce);
|
||||
@@ -1131,8 +1133,20 @@ function renderMeter() {
|
||||
);
|
||||
}
|
||||
|
||||
// The spec in hand, quiet beside the meter: the picker's pick on the
|
||||
// dashboard, the session's own spec everywhere else (overviewSpec()).
|
||||
function renderSpecTag() {
|
||||
const tag = $("spec-tag");
|
||||
const dir = isAgentless(page.S.workflow) ? "" : overviewSpec();
|
||||
const name = dir ? (isDashboard() && selSpec()?.name) || dir.replace(/^specs\//, "") : "";
|
||||
tag.hidden = !name;
|
||||
tag.textContent = name;
|
||||
tag.title = name ? "Spec: " + dir : "";
|
||||
}
|
||||
|
||||
function renderChrome() {
|
||||
renderMeter();
|
||||
renderSpecTag();
|
||||
$("title").textContent = page.S.title || "Session";
|
||||
$("badge").textContent = workflowLabel(page.S.workflow);
|
||||
renderTabTitle();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Plain functions over `page` (state.js) that more than one screen asks the
|
||||
// same question of, kept here so no screen has to import another to ask it.
|
||||
|
||||
import { page, redraw } from "./state.js";
|
||||
import { page, redraw, saveNow } from "./state.js";
|
||||
import { boardAwaiting } from "./git-board.js";
|
||||
import { defaultSpec, reviewOffer, dashboardOffer, submittedAwaiting, quietLimitMs } from "./answers.js";
|
||||
import { isAgentless } from "./skills.js";
|
||||
@@ -338,6 +338,26 @@ export async function loadOverview() {
|
||||
if (changed) redraw();
|
||||
}
|
||||
|
||||
// A New Session in the desktop app leaves the spec it was in for the fresh
|
||||
// dashboard (spec-carry.mjs). Asked once per page, before the picker is
|
||||
// touched; used only if the picker lists that spec, else the default stands.
|
||||
let specCarryAsked = false;
|
||||
export async function loadSpecCarry() {
|
||||
if (specCarryAsked || !isDashboard() || !scan() || page.local.specSel !== undefined) return;
|
||||
specCarryAsked = true;
|
||||
try {
|
||||
const res = await fetch("/spec-carry", { method: "POST", cache: "no-store" });
|
||||
const { spec } = res.status === 200 ? await res.json() : {};
|
||||
if (!spec || page.local.specSel !== undefined || !specList().some((s) => s.dir === spec)) return;
|
||||
page.local.specSel = spec;
|
||||
saveNow();
|
||||
redraw();
|
||||
loadOverview();
|
||||
} catch {
|
||||
/* no hint: the picker keeps its default */
|
||||
}
|
||||
}
|
||||
|
||||
// The Dashboard's AGENTS.md tab: its view id, and whether it is on now (the
|
||||
// dashboard, with an AGENTS.md the last read found).
|
||||
export const AGENTS_VIEW = "agents-md";
|
||||
|
||||
@@ -151,6 +151,14 @@
|
||||
.meter-fresh-row .handoff-code { flex-basis: 180px; font-size: 12px; padding: 6px 10px; }
|
||||
.meter-item-points { flex: none; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
|
||||
|
||||
/* The spec in hand: small and muted so it never competes with the title. */
|
||||
.spec-tag {
|
||||
flex: 0 1 auto; min-width: 0; max-width: 220px; align-self: center;
|
||||
font-size: 11.5px; color: var(--ink-3);
|
||||
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||
}
|
||||
.spec-tag[hidden] { display: none; }
|
||||
|
||||
.badge {
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
|
||||
@@ -35,6 +35,7 @@ import { SHOTS_DIR_NAME, SHOT_NAME, shotType, isOpen } from "./patches.mjs";
|
||||
import { appendChat, currentConversation, pendingChatCount, typedCount } from "./inbox.mjs";
|
||||
import { specKey } from "./workspace.mjs";
|
||||
import { readLoopSetup, saveLoopSetup } from "./loop-setup.mjs";
|
||||
import { takeSpecCarry } from "./spec-carry.mjs";
|
||||
import { resolveStrengths } from "./strengths.mjs";
|
||||
import { MARKERS, phaseChecklist } from "./spec-files.mjs";
|
||||
import {
|
||||
@@ -128,6 +129,7 @@ const ROUTES = [
|
||||
{ path: "/workspace/browse", method: "POST", origin: true, run: workspaceBrowse },
|
||||
{ path: "/loop-setup", method: "GET", run: loopSetupGet },
|
||||
{ path: "/loop-setup", method: "POST", origin: true, run: loopSetupPost },
|
||||
{ path: "/spec-carry", method: "POST", origin: true, run: specCarry },
|
||||
{ path: "/cancel", method: "POST", origin: true, run: cancel },
|
||||
{ path: "/ping", method: "POST", run: ping },
|
||||
{ path: "/bye", origin: true, run: bye },
|
||||
@@ -1723,6 +1725,12 @@ function loopSetupPost(req, res, ctx) {
|
||||
});
|
||||
}
|
||||
|
||||
// The spec the app's New Session carried over (spec-carry.mjs), taken once by
|
||||
// the fresh dashboard's page, which keeps it only if its picker lists that spec.
|
||||
function specCarry(req, res, ctx) {
|
||||
return json(res, 200, { spec: takeSpecCarry(loopProject(ctx)) });
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------- the workspace */
|
||||
|
||||
// The Workspace: the original folder plus any the person adds as context.
|
||||
|
||||
@@ -306,6 +306,7 @@ export const PROTECTED_CONSOLE_FILES = new Set([
|
||||
"workspaces.json",
|
||||
"loop-setup.json",
|
||||
"loop-reports.json",
|
||||
"spec-carry.json",
|
||||
"subagents.json",
|
||||
"pr-hosts.json",
|
||||
"console-dir",
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// Plan2Code Web Console - the spec a desktop app's New Session carries over to its fresh dashboard.
|
||||
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
import { HOME_DIR } from "./files.mjs";
|
||||
import { foldKey } from "./workspace.mjs";
|
||||
|
||||
// One short-lived file, written by the app just before the fresh agent starts
|
||||
// and read once by the new dashboard's page:
|
||||
//
|
||||
// { "project": "<worktree>", "spec": "specs/<name>", "at": <epoch ms> }
|
||||
//
|
||||
// Beside looks.json, never under specs/. It is only a hint: the page uses it
|
||||
// when that spec is on the new dashboard's picker, and ignores it otherwise.
|
||||
export const SPEC_CARRY_FILE = path.join(HOME_DIR, "spec-carry.json");
|
||||
|
||||
// An old hint must not preselect a spec in a session the person opens much later.
|
||||
export const SPEC_CARRY_MAX_AGE_MS = 10 * 60 * 1000;
|
||||
|
||||
const SPEC_KEY = /^specs\/[^/\\.][^/\\]*$/;
|
||||
|
||||
/**
|
||||
* The spec dir the app left for `project`, or null. The file is removed on any
|
||||
* read that finds it, so one New Session hints one dashboard: a stale or
|
||||
* other-folder hint is dropped too, never kept for a later session.
|
||||
*/
|
||||
export function takeSpecCarry(project, now = Date.now(), file = SPEC_CARRY_FILE) {
|
||||
let entry;
|
||||
try {
|
||||
entry = JSON.parse(fs.readFileSync(file, "utf8"));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
if (!entry || typeof entry !== "object") return null;
|
||||
const mine = typeof entry.project === "string" && project && foldKey(entry.project) === foldKey(project);
|
||||
// Another window's hint stays for that window's dashboard.
|
||||
if (!mine) {
|
||||
return Number.isFinite(entry.at) && now - entry.at <= SPEC_CARRY_MAX_AGE_MS ? null : (fs.rmSync(file, { force: true }), null);
|
||||
}
|
||||
fs.rmSync(file, { force: true });
|
||||
const fresh = Number.isFinite(entry.at) && now - entry.at <= SPEC_CARRY_MAX_AGE_MS;
|
||||
return fresh && typeof entry.spec === "string" && SPEC_KEY.test(entry.spec) ? entry.spec : null;
|
||||
}
|
||||
Reference in new issue
Block a user