Show the project's AGENTS.md on a dashboard tab with in-place links

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-06 13:42:38 -08:00
1 parent d84d6a4690
commit 20a349a3f8
12 files changed
+272 -11

No files matched your search

+15 -4
View File
@@ -54,7 +54,7 @@ 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,
finish, gitAwaiting, isDashboard, isGitBoard, isOpen, isSpecFileView, items, loadOverview, myTurn, openItems,
AGENTS_VIEW, agentsTabShown, finish, gitAwaiting, isDashboard, isGitBoard, isOpen, isSpecFileView, items, loadAgentsDoc, loadOverview, myTurn, openItems,
patience, pressStranded, reviewPending, scan, selSpec, sendCollected, specFileTabs, stagedCount, stranded,
topics, workingMs, WORKING_GRACE_MS,
workspaceFolders,
@@ -67,7 +67,7 @@ import { attachFiles, heldNotes, noteImages, pendingNotes, removeImage } from ".
import { closeMentions } from "../mention-box.js";
import { buildPager, fitGrowBox, markFor, markMore, renderCard, renderEndItem, renderNotice } from "./cards.js";
import { sendState, suggestState } from "../send-state.js";
import { renderBriefButton, renderDoc, renderOverview } from "./docs.js";
import { renderAgentsDoc, renderBriefButton, renderDoc, renderOverview } from "./docs.js";
import { board, renderGitBoard, resetBoard } from "./git-host.js";
import { renderWorkspace, tellFolderIssues } from "./workspace.js";
import { openHelpOn } from "./help-dialog.js";
@@ -535,6 +535,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();
// 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);
// New entries land at the bottom of the rail. Gliding down to them beats
// leaving the list parked where it was while it grew underneath.
@@ -991,7 +993,7 @@ function withFocus(fn) {
// (the dashboard menu, the end page).
function currentScroller() {
if (!drawnView) return null;
if (drawnView.startsWith("doc:") || isSpecFileView(drawnView)) return $("main");
if (drawnView.startsWith("doc:") || isSpecFileView(drawnView) || drawnView === AGENTS_VIEW) return $("main");
if (drawnView === "questions") return $("main").querySelector(":scope > .card.question");
if (drawnView === "ask") return $("main").querySelector(".ask-list");
return null;
@@ -1430,6 +1432,10 @@ function renderViews() {
const fileTabs = specFileTabs();
for (const f of fileTabs) tabs.push({ id: f.id, label: f.label, count: 0 });
if (isSpecFileView(page.view) && !fileTabs.some((f) => f.id === page.view)) page.view = "questions";
// Right after Dashboard: the project's AGENTS.md, present while the file is.
// Like a spec file tab, it sends the person home if the file goes away.
if (agentsTabShown()) tabs.splice(1, 0, { id: AGENTS_VIEW, label: "AGENTS.md", count: 0 });
else if (page.view === AGENTS_VIEW) page.view = "questions";
for (const d of docs()) tabs.push({ id: "doc:" + d.id, label: d.title || "Document", count: 0 });
// The helpers the agent reported, from the first one on; cleared by a
// dashboard hop, which sends the person home like the Overview tab does.
@@ -1482,6 +1488,10 @@ function renderViews() {
// changed on disk since.
render();
if (isSpecFileView(t.id)) loadOverview();
if (t.id === AGENTS_VIEW) {
page.agentsDoc.open = "AGENTS.md";
loadAgentsDoc();
}
});
nav.appendChild(b);
}
@@ -1616,7 +1626,7 @@ function renderMain() {
}
function paintMain(main) {
main.classList.toggle("is-doc", page.view.startsWith("doc:") || isSpecFileView(page.view));
main.classList.toggle("is-doc", page.view.startsWith("doc:") || isSpecFileView(page.view) || page.view === AGENTS_VIEW);
main.classList.toggle("is-ask", page.view === "ask");
// An agent-less session has no questions, docs or board to draw: its whole
@@ -1625,6 +1635,7 @@ function paintMain(main) {
if (page.view.startsWith("doc:")) return renderDoc(main, page.view.slice(4));
if (isSpecFileView(page.view)) return renderOverview(main, page.view);
if (page.view === AGENTS_VIEW) return renderAgentsDoc(main);
if (page.view === "ask") return renderAsk(main);
if (page.view === "subagents") return renderSubagents(main);
+59 -1
View File
@@ -1,6 +1,6 @@
// Plan2Code Web Console - documents: tabs, blocks, print and download, and the brief button; defines only.
import { docs, agentWorking, workingMs, patience, WORKING_GRACE_MS, finish, SPEC_FILES } from "../selectors.js";
import { docs, agentWorking, workingMs, patience, WORKING_GRACE_MS, finish, SPEC_FILES, loadAgentsDoc } from "../selectors.js";
import { el, md } from "../render.js";
import { downloadDocHtml, docSavedNote, downloadDoc, blockBody } from "../doc-files.js";
import { hooks, page, redraw } from "../state.js";
@@ -239,6 +239,64 @@ export function renderOverview(main, kind = "overview") {
main.appendChild(box);
}
// The files the AGENTS.md tab may show: the same two shapes the server serves.
const AGENTS_FILE = /^(?:AGENTS\.md|\.agents-docs\/[A-Za-z0-9._-]+\.md)$/;
// A link in an agent-guide file, resolved against the file it sits in: the
// guide's own name when it points at another agent-guide file, else null (an
// outside link keeps the usual rules).
export function agentsLinkTarget(from, href) {
if (!href || /^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith("#") || href.startsWith("/")) return null;
try {
const u = new URL(href, "http://guide.invalid/" + from);
const rel = decodeURIComponent(u.pathname.slice(1));
return AGENTS_FILE.test(rel) ? rel : null;
} catch {
return null;
}
}
// The Dashboard's AGENTS.md tab: the project's agent guide, read-only, straight
// from disk. A link to another guide file (.agents-docs/...) opens in place,
// with a way back to AGENTS.md.
export function renderAgentsDoc(main) {
const { open, texts } = page.agentsDoc;
const head = el("div", "doc-head");
head.appendChild(el("h2", null, open === "AGENTS.md" ? "AGENTS.md" : open));
const tools = el("div", "doc-tools");
if (open !== "AGENTS.md") {
const guide = el("button", "btn small", "Back to AGENTS.md");
guide.type = "button";
guide.addEventListener("click", () => {
page.agentsDoc.open = "AGENTS.md";
redraw();
main.scrollTop = 0;
});
tools.appendChild(guide);
}
tools.appendChild(backButton());
tools.appendChild(printButton());
head.appendChild(tools);
main.appendChild(head);
main.appendChild(el("p", "help", open + " · read-only, straight from disk"));
const box = el("div", "block settled");
box.appendChild(
md(texts[open] || "", "md", {
link: (href) => {
const rel = agentsLinkTarget(open, href);
if (!rel) return null;
return () => {
page.agentsDoc.open = rel;
redraw();
main.scrollTop = 0;
loadAgentsDoc();
};
},
})
);
main.appendChild(box);
}
// The brief dialog's buttons, wired once at start-up.
export function wireDocs() {
$("btn-brief").addEventListener("click", openBrief);