mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-29 05:11:19 -08:00
Add the Review Loop: unattended review-and-fix rounds in the desktop app and in loop phases
AI Assisted
This commit is contained in:
1 parent
d6a28b5dc8
commit
57567d7a0b
71 files changed
+11331
-443
No files matched your search
@@ -6,6 +6,7 @@
|
||||
"name": "Claude Code",
|
||||
"kind": "builtin",
|
||||
"command": "claude",
|
||||
"helpers": true,
|
||||
"prompt": "/plan2code",
|
||||
"args": ["{prompt}", "{bypass}", "{model}"],
|
||||
"bypassArgs": ["--permission-mode", "bypassPermissions"],
|
||||
@@ -37,6 +38,7 @@
|
||||
"name": "Devin",
|
||||
"kind": "builtin",
|
||||
"command": "devin",
|
||||
"helpers": false,
|
||||
"prompt": "/plan2code",
|
||||
"args": ["{bypass}", "{model}", "--", "{prompt}"],
|
||||
"bypassArgs": ["--permission-mode", "bypass"],
|
||||
@@ -64,6 +66,7 @@
|
||||
"name": "Codex",
|
||||
"kind": "builtin",
|
||||
"command": "codex",
|
||||
"helpers": false,
|
||||
"prompt": "$plan2code",
|
||||
"args": ["{bypass}", "{model}", "{prompt}"],
|
||||
"bypassArgs": ["--dangerously-bypass-approvals-and-sandbox"],
|
||||
@@ -94,6 +97,7 @@
|
||||
"name": "GitHub Copilot CLI",
|
||||
"kind": "template",
|
||||
"command": "copilot",
|
||||
"helpers": false,
|
||||
"prompt": "Use the /plan2code skill",
|
||||
"args": ["-i", "{prompt}"],
|
||||
"bypassArgs": ["--allow-all-tools"],
|
||||
@@ -104,6 +108,7 @@
|
||||
"name": "OpenCode",
|
||||
"kind": "template",
|
||||
"command": "opencode",
|
||||
"helpers": false,
|
||||
"prompt": "@plan2code",
|
||||
"args": ["{model}", "--prompt", "{prompt}"],
|
||||
"bypassArgs": ["--auto"],
|
||||
@@ -114,6 +119,7 @@
|
||||
"name": "Gemini CLI",
|
||||
"kind": "template",
|
||||
"command": "gemini",
|
||||
"helpers": false,
|
||||
"prompt": "Use the plan2code skill",
|
||||
"args": ["{model}", "{prompt}"],
|
||||
"bypassArgs": ["--approval-mode=yolo"],
|
||||
@@ -125,6 +131,7 @@
|
||||
"name": "Pi",
|
||||
"kind": "template",
|
||||
"command": "pi",
|
||||
"helpers": false,
|
||||
"prompt": "/skill:plan2code",
|
||||
"args": ["{model}", "{prompt}"],
|
||||
"modelArgs": ["--model", "{model}"]
|
||||
@@ -134,6 +141,7 @@
|
||||
"name": "Cursor CLI",
|
||||
"kind": "template",
|
||||
"command": "agent",
|
||||
"helpers": false,
|
||||
"prompt": "/plan2code",
|
||||
"args": ["{model}", "{prompt}"],
|
||||
"bypassArgs": ["--force"],
|
||||
|
||||
@@ -8,7 +8,7 @@ Critical review specialist -- experienced senior engineer providing independent
|
||||
|
||||
## Interface
|
||||
|
||||
The FIRST thing you do, before anything else in this file — before the scope detection: ask **web console** (browser page, suggested) or **terminal**? Console → run `node "<D>/console.mjs" open --workflow review` before reading (<D>: references/web-console/ beside this SKILL.md — ~/.agents/skills/plan2code-review/references/web-console/ globally — or the dir in ~/.plan2code/console/console-dir), then read <D>/console.md and <D>/notes/review.md. Scope questions, the findings report and the pick-what-gets-fixed menu all go through it; the report lands on the page as a doc. Switchable anytime. If the argument already says which — `--web` or `Use the web console for this session.` — take it and do not ask; drop the flag. Launched by the dashboard? Its session is already open — resume it (console-launches.md), then Process. Read inside a build session for its review button? Skip this section — building-review.md's overrides govern, the session is already running.
|
||||
The FIRST thing you do, before anything else in this file — before the scope detection: ask **web console** (browser page, suggested) or **terminal**? Console → run `node "<D>/console.mjs" open --workflow review` before reading (<D>: references/web-console/ beside this SKILL.md — ~/.agents/skills/plan2code-review/references/web-console/ globally — or the dir in ~/.plan2code/console/console-dir), then read <D>/console.md and <D>/notes/review.md. Scope questions, the findings report and the pick-what-gets-fixed menu all go through it; the report lands on the page as a doc. Switchable anytime. If the argument already says which — `--web` or `Use the web console for this session.` — take it and do not ask; drop the flag. `--loop` (only inside the desktop app, a Review Loop round): open with `open --loop --workflow review --round <n> --role <role> --scope-file <path>` from the arguments, read `<D>/notes/review-loop.md` after `console.md`, and follow it; it replaces the scope question, the fix menu, the sign-off, Lessons End and every git step below. Launched by the dashboard? Its session is already open — resume it (console-launches.md), then Process. Read inside a build session for its review button? Skip this section — building-review.md's overrides govern, the session is already running.
|
||||
|
||||
## Scripts
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ The seven noting skills (and any skill sent here by Start's Review now) run it b
|
||||
|
||||
**The check** (before step 1, unless the state is `not-set-up`). Skip it when `references/lesson-check.md` is not beside this file (a read-only skill sent here by Review now ships no checker brief): run plain `list`, and the rows show Not checked yet. Otherwise run `node "<S>/lessons.mjs" check-input`. `lessons` empty: skip the check and run step 1 as written. Otherwise:
|
||||
|
||||
- **Start the checker** with `references/lesson-check.md` and the JSON. With helpers on and available, it is a fresh helper given reading tools only, never relying on a permission mode (Claude Code: a custom helper already installed whose tool list holds only reading tools, such as `tools: Read, Grep, Glob`, never the built-in `Explore` or a general-purpose one, since both keep the shell; Devin: `run_subagent` with the read-only explore profile; Codex: a fresh helper told it may only read), `how: "helper"`, at `helper-strength.md`'s lesson check row (standard strength, medium effort). With Subagents off for the skill, no helper support, or (Claude Code) no reading-only helper installed, you grade in a separate step after re-reading the brief, `how: "same-agent"`; the card says so.
|
||||
- **Start the checker** with `references/lesson-check.md` and the JSON. With helpers on and available, it is a fresh helper given reading tools only, never relying on a permission mode (Claude Code: a custom helper already installed whose tool list holds only reading tools, such as one whose `tools:` line lists only the read, search and list-files tools, never the built-in `Explore` or a general-purpose one, since both keep the shell; Devin: `run_subagent` with the read-only explore profile; Codex: a fresh helper told it may only read), `how: "helper"`, at `helper-strength.md`'s lesson check row (standard strength, medium effort). With Subagents off for the skill, no helper support, or (Claude Code) no reading-only helper installed, you grade in a separate step after re-reading the brief, `how: "same-agent"`; the card says so.
|
||||
- Write its reply to a file in the console session folder, or the OS temp folder in a terminal, never in the project. Run `check-record --file <path>`. Exit 4: give the checker its `problems` once and record again; still failing, step 1 runs `list --check-failed "<one line>"` and every lesson still shows.
|
||||
- Step 1 then runs `list --check <checkId>`. On the web console, post an `activity` line while it runs ("Checking 4 lessons").
|
||||
|
||||
|
||||
@@ -58,8 +58,11 @@ export function loadAgentList({ dir = MODULE_DIR, optional = false } = {}) {
|
||||
warnings.push(`agents[${index}] skipped: not an object`);
|
||||
return;
|
||||
}
|
||||
if (entry.kind === "builtin") builtins.push(entry);
|
||||
else if (entry.kind === "template") templates.push(entry);
|
||||
// helpers: the agent can start a subagent from inside a session; a missing
|
||||
// key reads false.
|
||||
const carried = { ...entry, helpers: entry.helpers === true };
|
||||
if (entry.kind === "builtin") builtins.push(carried);
|
||||
else if (entry.kind === "template") templates.push(carried);
|
||||
else warnings.push(`agents[${index}] skipped: unknown kind ${JSON.stringify(entry.kind)}`);
|
||||
});
|
||||
return { builtins, templates, warnings };
|
||||
|
||||
@@ -42,6 +42,7 @@ import {
|
||||
resolveDocFiles,
|
||||
resolveDocImages,
|
||||
validate,
|
||||
ROUND_ROLES,
|
||||
} from "./patches.mjs";
|
||||
import {
|
||||
initialWorkspace,
|
||||
@@ -111,14 +112,40 @@ function leavePointer() {
|
||||
const EMBED_API = 1;
|
||||
|
||||
// The only workflows a loop drives (open --loop).
|
||||
const LOOP_WORKFLOWS = ["implement", "implement-review"];
|
||||
const LOOP_WORKFLOWS = ["implement", "implement-review", "review"];
|
||||
|
||||
// What the loop locks a session with: `driving`, and, when the app started this
|
||||
// phase on a strength, its word (PLAN2CODE_LOOP_STRENGTH), which the server's
|
||||
// Subagents sync reads so the phase's helpers follow it.
|
||||
function loopLock() {
|
||||
function loopLock(round) {
|
||||
const strength = process.env.PLAN2CODE_LOOP_STRENGTH;
|
||||
return STRENGTH_ORDER.includes(strength) ? { driving: true, strength } : { driving: true };
|
||||
const lock = STRENGTH_ORDER.includes(strength) ? { driving: true, strength } : { driving: true };
|
||||
return round ? { ...lock, ...round } : lock;
|
||||
}
|
||||
|
||||
// A Review Loop round (open --loop --workflow review) carries its round, role
|
||||
// and scope file; every other open refuses them. Returns the stamp, or null.
|
||||
function roundFlags(loopMode) {
|
||||
const given = ["round", "role", "scope-file"].filter((f) => args[f] !== undefined);
|
||||
const isRound = loopMode && args.workflow === "review";
|
||||
if (!isRound) {
|
||||
if (given.length) die(`--${given[0]} goes only with --loop --workflow review`, 2);
|
||||
return null;
|
||||
}
|
||||
const n = Number(args.round);
|
||||
if (args.round === undefined || args.round === true || !Number.isInteger(n) || n < 1 || !/^\d+$/.test(String(args.round))) {
|
||||
die("--round must be a positive integer for a Review Loop round", 2);
|
||||
}
|
||||
if (typeof args.role !== "string" || !ROUND_ROLES.includes(args.role)) {
|
||||
die(`--role must be one of ${ROUND_ROLES.join(", ")} for a Review Loop round`, 2);
|
||||
}
|
||||
const scopeFile = args["scope-file"];
|
||||
let isFile = false;
|
||||
try {
|
||||
isFile = typeof scopeFile === "string" && scopeFile !== "" && fs.statSync(scopeFile).isFile();
|
||||
} catch {}
|
||||
if (!isFile) die("--scope-file must name an existing file for a Review Loop round", 2);
|
||||
return { round: n, role: args.role, scopeFile: path.resolve(scopeFile) };
|
||||
}
|
||||
|
||||
export async function cmdOpen() {
|
||||
@@ -140,6 +167,7 @@ export async function cmdOpen() {
|
||||
die(`--loop goes only with --workflow ${LOOP_WORKFLOWS.join(" or --workflow ")}`, 2);
|
||||
}
|
||||
}
|
||||
const round = roundFlags(loopMode);
|
||||
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
|
||||
@@ -252,9 +280,10 @@ export async function cmdOpen() {
|
||||
} else if (switching) {
|
||||
s.workflow = args.workflow;
|
||||
// An inline switch (into Review) is not a loop phase.
|
||||
if (!LOOP_WORKFLOWS.includes(args.workflow)) {
|
||||
if (!LOOP_WORKFLOWS.includes(args.workflow) || args.workflow === "review") {
|
||||
delete s.loopOutcome;
|
||||
delete s.loopEnd;
|
||||
delete s.roundOutcome;
|
||||
}
|
||||
}
|
||||
if (args.title) s.title = args.title;
|
||||
@@ -270,9 +299,17 @@ export async function cmdOpen() {
|
||||
// without it (Fix together with an agent, from a stop screen) is an ordinary,
|
||||
// unlocked session. `loopExpect` goes with the lock: the app restamps it
|
||||
// on its next look, so a stale setup never judges a new run.
|
||||
if (loopMode) s.loop = loopLock();
|
||||
else {
|
||||
if (loopMode) {
|
||||
// A different round or role never inherits the last one's report: its
|
||||
// outcome and its `report` doc go, so the report proof is that run's own.
|
||||
if (round && (s.loop?.round !== round.round || s.loop?.role !== round.role)) {
|
||||
delete s.roundOutcome;
|
||||
s.docs = (s.docs || []).filter((d) => d && d.id !== "report");
|
||||
}
|
||||
s.loop = loopLock(round);
|
||||
} else {
|
||||
delete s.loop;
|
||||
delete s.roundOutcome;
|
||||
delete s.loopExpect;
|
||||
// The loop's cards mean nothing without it, and validate() refuses
|
||||
// handledBy outside a loop session, which would wedge every post.
|
||||
@@ -302,7 +339,7 @@ export async function cmdOpen() {
|
||||
// Only a freshly opened dashboard plays Planny's wake-up.
|
||||
if (args.workflow === "dashboard") state.wake = true;
|
||||
// Locked from the first frame, before the state is first written.
|
||||
if (loopMode) state.loop = loopLock();
|
||||
if (loopMode) state.loop = loopLock(round);
|
||||
// The setup session's hand-over data (forCli + the token /handover
|
||||
// checks), created with the state so the first write already has it.
|
||||
if (args.workflow === "setup") {
|
||||
@@ -583,6 +620,9 @@ export async function cmdOpen() {
|
||||
...owed,
|
||||
...(remote.remote ? { remote: remote.remote } : {}),
|
||||
...(notes.length ? { note: notes.join(" ") } : {}),
|
||||
// A Review Loop round reads its own notes once, the way a phase agent is
|
||||
// pointed at notes/loop.md by its skill: the console names the file.
|
||||
...(round ? { read: [path.join(HERE, "notes", "review-loop.md")] } : {}),
|
||||
});
|
||||
advanceSubagents(dir, subCursor);
|
||||
// After the print, never before it: the page and the link wait for nothing.
|
||||
|
||||
@@ -115,7 +115,7 @@ if (!cmd || !Object.hasOwn(COMMANDS, cmd)) {
|
||||
// A flag given with no value parses as `true`, and a boolean handed on as a
|
||||
// path or a name crashes somewhere deep (path.basename(true) throws). Every
|
||||
// flag that takes a value is checked once, here, and refused as bad usage.
|
||||
const VALUE_FLAGS = ["session", "sid", "resume", "file", "spec", "title", "workflow", "skill", "handoff", "upload", "name", "from", "seconds", "limit", "idle-ms", "for-cli"];
|
||||
const VALUE_FLAGS = ["session", "sid", "resume", "file", "spec", "title", "workflow", "skill", "handoff", "upload", "name", "from", "seconds", "limit", "idle-ms", "for-cli", "round", "role", "scope-file"];
|
||||
for (const flag of VALUE_FLAGS) {
|
||||
if (flag in args && typeof args[flag] !== "string") die(`--${flag} needs a value`, 2);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ const SPEC_KEY = /^specs\/[^/\\.][^/\\]*$/;
|
||||
|
||||
export const LOOP_DEFAULTS = Object.freeze({
|
||||
review: true,
|
||||
reviewRounds: 2,
|
||||
fixMode: "smart",
|
||||
fix: Object.freeze([...LEVELS]),
|
||||
commit: true,
|
||||
@@ -68,6 +69,9 @@ export function loopSetupProblems(entry) {
|
||||
if (!Array.isArray(entry.fix) || !entry.fix.every((l) => LEVELS.includes(l)) || new Set(entry.fix).size !== entry.fix.length) {
|
||||
problems.push(`"fix" must list distinct levels from ${LEVELS.join(", ")}`);
|
||||
}
|
||||
if (!Number.isInteger(entry.reviewRounds) || entry.reviewRounds < 0 || entry.reviewRounds > 6) {
|
||||
problems.push('"reviewRounds" must be a whole number from 0 to 6');
|
||||
}
|
||||
if (!FIX_MODES.includes(entry.fixMode)) problems.push(`"fixMode" must be one of ${FIX_MODES.join(", ")}`);
|
||||
if (!ON_QUESTION.includes(entry.onQuestion)) problems.push(`"onQuestion" must be one of ${ON_QUESTION.join(", ")}`);
|
||||
if (!AFTER_LAST.includes(entry.afterLast)) problems.push(`"afterLast" must be one of ${AFTER_LAST.join(", ")}`);
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
# Review Loop Round
|
||||
|
||||
Read after `console.md`. Run by the desktop app's Review Loop (`--loop` on `review`), part of the `console.md` contract. This note replaces the scope card, the fix menu, the sign-off, Lessons End and every git step.
|
||||
|
||||
## Who you are
|
||||
|
||||
One round of a Review Loop. The app started you with `--round <n>`, `--role <role>` and `--scope-file <path>`, and opened the session with `open --loop --workflow review --round <n> --role <role> --scope-file <path>`: run that open again if the server went away, with the same flags. Nobody is watching. Never run git in any form, never ask the person, never commit. A real question is a stop: report `failed`, reason `other`.
|
||||
|
||||
## Scope
|
||||
|
||||
Read the scope file first. For round 1 it names the scope the person picked. For a later round it is the previous round's diff. Review nothing outside it. A file the scope names but that is gone is a finding only if the change deleted it.
|
||||
|
||||
## Role both
|
||||
|
||||
1. Start one fresh read-only reviewer subagent with `reviewer-brief.md` filled in for the scope, whatever the Subagents switch says. It never sees this conversation.
|
||||
2. Verify every finding it returns (`verification-protocol.md`), and drop what does not hold.
|
||||
3. Post the verified findings as one doc with id `report`, grouped Critical, Warning, Suggestion.
|
||||
4. Fix Critical and Warning only. List Suggestions without fixing them.
|
||||
5. Run the targeted tests for the files you changed (`references/test-runs.md`), never the full suite. Changed nothing? Run the targeted tests for the files in scope: a passed round never sends `ran:false`.
|
||||
|
||||
## Role reviewer
|
||||
|
||||
Do the review only: steps 1 to 3 of Role both. Change no file. Post the `report` doc and report; leave `tests` out, and send `fixed` as an empty list.
|
||||
|
||||
## Role fixer
|
||||
|
||||
The scope file names the reviewer's report by file path. Read it, fix Critical and Warning, run the targeted tests for what you changed, and start no new review. Leave `report` out. Still send `review`: its counts and lists come from the reviewer's report, with `fixed` and `unfixed` showing what this round fixed and left.
|
||||
|
||||
## Reporting
|
||||
|
||||
Post in this order, each as its own patch with no `--wait`:
|
||||
|
||||
1. The `report` doc (roles both and reviewer), before the outcome.
|
||||
2. One top-level `roundOutcome`:
|
||||
|
||||
```json
|
||||
{ "roundOutcome": {
|
||||
"round": 2, "role": "both", "result": "passed", "reason": null,
|
||||
"summary": "Fixed 1 warning; 1 suggestion left",
|
||||
"report": "report",
|
||||
"review": { "critical": 0, "warning": 1, "suggestion": 1,
|
||||
"fixed": [ { "title": "Close the file handle", "file": "src/z.js", "line": 12 } ],
|
||||
"unfixed": [],
|
||||
"suggestions": [ { "title": "Name the timer", "file": "src/x.js" } ] },
|
||||
"tests": { "ran": true, "passed": true, "summary": "14 pass" },
|
||||
"subject": "Close the file handle in z.js" } }
|
||||
```
|
||||
|
||||
3. `{"agent":{"status":"waiting"}}`, then keep waiting in bounded `wait` slices until the app ends the session. Never end the turn on text.
|
||||
|
||||
Every field is required except `report` for a fixer and `tests` for a reviewer. `round` and `role` must equal the flags. `critical`, `warning` and `suggestion` count what the review found before fixing; `fixed` and `unfixed` list the Critical and Warning findings by that outcome (at most 50 each, `file` relative to the project). `result` is `passed` when the round ran its steps and its tests; `failed` carries one reason: `tests`, `findings`, `blocked`, `conflict` or `other`. `summary` is one line under 200 characters, `subject` one line under 100.
|
||||
|
||||
## Refusals
|
||||
|
||||
An exit 3 on `roundOutcome` names the field: fix it and post again inside the same round. A `loopOutcome` is refused here: a round reports `roundOutcome` only.
|
||||
@@ -9,3 +9,5 @@ Closing gate: `review` "Check the fixes", `"doc":"report"`, `"nothingYet":false`
|
||||
Lessons first: with lessons to offer (`references/lessons.md`, End), post its `card` as one `lessons` item with `--wait` before the finish.
|
||||
|
||||
Completion finish: `command` is the suggested commit when fixes landed (AGENTS.md format, `"where":"When you are happy with it, commit it from your terminal:"`, `"commit":true`), else none; `"dashboard":true`. A stop's `command` is the bare `/plan2code-review`, no dashboard.
|
||||
|
||||
Under `--loop` (a Review Loop round, desktop app only): read `notes/review-loop.md` after `console.md`; it replaces the scope card, the fix menu and the sign-off.
|
||||
+163
-5
@@ -598,7 +598,7 @@ export function applyPatch(state, patch) {
|
||||
if (v === null) {
|
||||
// The loop's report fields are set, never deleted: a null here would
|
||||
// strip the app's criteria or an already-posted report.
|
||||
if (["loopExpect", "loopOutcome", "loopEnd"].includes(k)) throw new Error(rule("", k, "cannot be deleted by a patch"));
|
||||
if (["loopExpect", "loopOutcome", "loopEnd", "roundOutcome"].includes(k)) throw new Error(rule("", k, "cannot be deleted by a patch"));
|
||||
delete next[k];
|
||||
continue;
|
||||
}
|
||||
@@ -664,9 +664,19 @@ export function applyPatch(state, patch) {
|
||||
next.chat = chat;
|
||||
break;
|
||||
}
|
||||
case "roundOutcome":
|
||||
// A Review Loop round's one report. validate() checks its shape and
|
||||
// the report doc; here only who may send it, and how often.
|
||||
if (state.loop?.driving !== true || !state.loop.round) {
|
||||
throw new Error(rule("", "roundOutcome", "is only accepted in a Review Loop round session"));
|
||||
}
|
||||
if (state.roundOutcome !== undefined) throw new Error(rule("", "roundOutcome", "was already posted for this session"));
|
||||
next.roundOutcome = v;
|
||||
break;
|
||||
case "loopOutcome":
|
||||
// The skill's one report of a phase built under the loop. The shape is
|
||||
// checked by validate(); here only who may send it, and how often.
|
||||
if (state.loop?.round) throw new Error(rule("", "loopOutcome", "is not accepted in a round session: a round reports roundOutcome, not loopOutcome"));
|
||||
if (!state.loop?.driving) {
|
||||
throw new Error(rule("", "loopOutcome", "is only accepted in a loop session; a resume without --loop unlocked it, so run open --resume <sid> --workflow <yours> --loop, then post this again"));
|
||||
}
|
||||
@@ -1248,6 +1258,7 @@ export function validate(state) {
|
||||
if (state.loopExpect !== undefined) problems.push(...loopExpectProblems(state.loopExpect));
|
||||
if (state.loopOutcome !== undefined) problems.push(...loopOutcomeProblems(state.loopOutcome, state.loopExpect));
|
||||
if (state.loopEnd !== undefined) problems.push(...loopEndProblems(state.loopEnd, state));
|
||||
if (state.roundOutcome !== undefined) problems.push(...roundOutcomeProblems(state.roundOutcome, state));
|
||||
// The dashboard agent's answer to Suggest for me on the loop setup screen.
|
||||
if (state.loopSuggest !== undefined) problems.push(...loopSuggestProblems(state.loopSuggest));
|
||||
|
||||
@@ -1489,6 +1500,7 @@ export function isOpen(item) {
|
||||
/* ------------------------------------------------------ the loop's reports */
|
||||
|
||||
const LOOP_LEVELS = ["critical", "warning", "suggestion"];
|
||||
export const ROUND_ROLES = ["both", "reviewer", "fixer"];
|
||||
const LOOP_REASONS = ["tests", "findings", "blocked", "conflict", "other"];
|
||||
const LOOP_CAN = ["resume", "ask", "fix", "finalize", "dashboard"];
|
||||
const TASK_ID = /^\d+\.\d+$/;
|
||||
@@ -1707,9 +1719,153 @@ export function loopSuggestProblems(v) {
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Problems with a `roundOutcome` (what a Review Loop round reports), as
|
||||
* sentences naming the field; an empty array when it is good. Rules are the
|
||||
* overview's Data Model. `state` is the merged session, which holds the
|
||||
* round's stamp and the report doc the outcome names.
|
||||
*/
|
||||
export function roundOutcomeProblems(o, state) {
|
||||
const p = [];
|
||||
const bad = (field, rule) => p.push(`roundOutcome.${field} ${rule}`);
|
||||
if (!isPlainObject(o)) return ["roundOutcome must be an object"];
|
||||
const prose = (field, s) => {
|
||||
if (typeof s === "string") p.push(...proseProblems(s, `roundOutcome.${field}`));
|
||||
};
|
||||
const stamp = state?.loop || {};
|
||||
if (!isPosInt(o.round)) bad("round", "must be a positive integer");
|
||||
else if (o.round !== stamp.round) bad("round", `must be ${stamp.round}, this session's round`);
|
||||
if (!ROUND_ROLES.includes(o.role)) bad("role", `must be one of ${ROUND_ROLES.join(", ")}`);
|
||||
else if (o.role !== stamp.role) bad("role", `must be "${stamp.role}", this session's role`);
|
||||
const role = ROUND_ROLES.includes(o.role) ? o.role : stamp.role;
|
||||
if (o.result !== "passed" && o.result !== "failed") bad("result", 'must be "passed" or "failed"');
|
||||
if (o.result === "passed") {
|
||||
if (o.reason !== null) bad("reason", "must be null when the round passed");
|
||||
} else if (o.result === "failed" && !LOOP_REASONS.includes(o.reason)) {
|
||||
bad("reason", `must be one of ${LOOP_REASONS.join(", ")} when the round failed`);
|
||||
}
|
||||
if (!oneLine(o.summary, 200)) bad("summary", "must be one line of 1 to 200 characters");
|
||||
else prose("summary", o.summary);
|
||||
if (!oneLine(o.subject, 100)) bad("subject", "must be one line of 1 to 100 characters");
|
||||
else prose("subject", o.subject);
|
||||
|
||||
if (role === "both" || role === "reviewer") {
|
||||
// A report is a doc the agent already posted: docs carry no kind field,
|
||||
// so the outcome names the doc by its id.
|
||||
if (typeof o.report !== "string" || !(state?.docs || []).some((d) => d && d.id === o.report)) {
|
||||
bad("report", "must name a report doc already posted in this session");
|
||||
}
|
||||
} else if (o.report !== undefined && typeof o.report !== "string") bad("report", "must be a doc id when present");
|
||||
|
||||
if (!isPlainObject(o.review)) bad("review", "must be an object { critical, warning, suggestion, fixed, unfixed, suggestions }");
|
||||
else {
|
||||
const r = o.review;
|
||||
for (const level of LOOP_LEVELS) if (!isNonNegInt(r[level])) bad(`review.${level}`, "must be a non-negative integer");
|
||||
for (const list of ["fixed", "unfixed", "suggestions"]) {
|
||||
if (!Array.isArray(r[list])) bad(`review.${list}`, "must be an array");
|
||||
else if (r[list].length > 50) bad(`review.${list}`, "has at most 50 entries");
|
||||
else {
|
||||
r[list].forEach((f, i) => {
|
||||
const at = `review.${list}[${i}]`;
|
||||
if (!isPlainObject(f)) return bad(at, "must be an object { title, file, line? }");
|
||||
if (!oneLine(f.title, 200)) bad(`${at}.title`, "must be one line of 1 to 200 characters");
|
||||
else prose(`${at}.title`, f.title);
|
||||
if (!relativePath(f.file)) bad(`${at}.file`, "must be a relative path inside the project");
|
||||
if (f.line !== undefined && !isPosInt(f.line)) bad(`${at}.line`, "must be a positive integer when present");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (role === "both" || role === "fixer") {
|
||||
if (!isPlainObject(o.tests)) bad("tests", "must be an object { ran, passed, summary }");
|
||||
else {
|
||||
if (typeof o.tests.ran !== "boolean") bad("tests.ran", "must be true or false");
|
||||
if (typeof o.tests.passed !== "boolean") bad("tests.passed", "must be true or false");
|
||||
if (typeof o.tests.summary !== "string" || /[\r\n]/.test(o.tests.summary)) bad("tests.summary", "must be a one-line string");
|
||||
else prose("tests.summary", o.tests.summary);
|
||||
}
|
||||
} else if (o.tests !== undefined && !isPlainObject(o.tests)) bad("tests", "must be an object when present");
|
||||
return p;
|
||||
}
|
||||
|
||||
const REVIEW_END_REASONS = ["clean", "cap", "person", "failed"];
|
||||
|
||||
/**
|
||||
* The Review Loop's `loopEnd` (`kind: "review"`): why the run ended, the report
|
||||
* doc, what Continue and the partial diff offer, the Suggestions pick, and
|
||||
* after sign-off (`signedOff`) the note on what it did. `report` and
|
||||
* `partial.diff` name docs on the page, as `evidence` does for the other kinds.
|
||||
*/
|
||||
function reviewLoopEndProblems(e, state) {
|
||||
const p = [];
|
||||
const bad = (field, rule) => p.push(`loopEnd.${field} ${rule}`);
|
||||
const prose = (field, s) => {
|
||||
if (typeof s === "string") p.push(...proseProblems(s, `loopEnd.${field}`));
|
||||
};
|
||||
const onPage = (id) => typeof id === "string" && (state?.docs || []).some((d) => d && d.id === id);
|
||||
if (!oneLine(e.line, 200)) bad("line", "must be one line of 1 to 200 characters");
|
||||
else prose("line", e.line);
|
||||
if (!REVIEW_END_REASONS.includes(e.reason)) bad("reason", `must be one of ${REVIEW_END_REASONS.join(", ")}`);
|
||||
if (!onPage(e.report)) bad("report", "must be the id of a doc on the page");
|
||||
if (typeof e.canContinue !== "boolean") bad("canContinue", "must be true or false");
|
||||
if (typeof e.canSquash !== "boolean") bad("canSquash", "must be true or false");
|
||||
if (e.signedOff !== undefined && typeof e.signedOff !== "boolean") bad("signedOff", "must be true or false when present");
|
||||
if (e.note !== undefined) {
|
||||
if (!oneLine(e.note, 200)) bad("note", "must be one line of 1 to 200 characters");
|
||||
else prose("note", e.note);
|
||||
}
|
||||
if (!Array.isArray(e.can) || !e.can.every((c) => LOOP_CAN.includes(c))) {
|
||||
bad("can", `must be an array with entries from ${LOOP_CAN.join(", ")}`);
|
||||
}
|
||||
if (e.partial !== undefined) {
|
||||
if (!isPlainObject(e.partial)) bad("partial", "must be an object { files, added, removed, diff }");
|
||||
else {
|
||||
for (const k of ["files", "added", "removed"]) if (!isNonNegInt(e.partial[k])) bad(`partial.${k}`, "must be a non-negative integer");
|
||||
if (!onPage(e.partial.diff)) bad("partial.diff", "must be the id of a doc on the page");
|
||||
}
|
||||
}
|
||||
if (e.suggestions !== undefined) {
|
||||
if (!Array.isArray(e.suggestions)) bad("suggestions", "must be an array");
|
||||
else if (e.suggestions.length > 50) bad("suggestions", "has at most 50 entries");
|
||||
else {
|
||||
const seen = new Set();
|
||||
e.suggestions.forEach((s, i) => {
|
||||
const at = `suggestions[${i}]`;
|
||||
if (!isPlainObject(s)) return bad(at, "must be an object { id, title, file, line? }");
|
||||
if (typeof s.id !== "string" || !/^s[0-9]{1,3}$/.test(s.id)) bad(`${at}.id`, "must look like s1");
|
||||
else if (seen.has(s.id)) bad(`${at}.id`, "must be unique");
|
||||
else seen.add(s.id);
|
||||
if (!oneLine(s.title, 200)) bad(`${at}.title`, "must be one line of 1 to 200 characters");
|
||||
else prose(`${at}.title`, s.title);
|
||||
if (s.file !== "" && !relativePath(s.file)) bad(`${at}.file`, "must be a relative path inside the project or empty");
|
||||
else prose(`${at}.file`, s.file);
|
||||
if (s.line !== undefined && !isPosInt(s.line)) bad(`${at}.line`, "must be a positive integer when present");
|
||||
});
|
||||
}
|
||||
}
|
||||
if (e.open !== undefined) {
|
||||
if (!Array.isArray(e.open)) bad("open", "must be an array");
|
||||
else if (e.open.length > 50) bad("open", "has at most 50 entries");
|
||||
else {
|
||||
e.open.forEach((f, i) => {
|
||||
const at = `open[${i}]`;
|
||||
if (!isPlainObject(f)) return bad(at, "must be an object { title, file, line? }");
|
||||
if (f.level !== undefined && f.level !== "critical" && f.level !== "warning") bad(`${at}.level`, 'must be "critical" or "warning" when present');
|
||||
if (!oneLine(f.title, 200)) bad(`${at}.title`, "must be one line of 1 to 200 characters");
|
||||
else prose(`${at}.title`, f.title);
|
||||
if (!relativePath(f.file)) bad(`${at}.file`, "must be a relative path inside the project");
|
||||
if (f.line !== undefined && !isPosInt(f.line)) bad(`${at}.line`, "must be a positive integer when present");
|
||||
});
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Problems with a `loopEnd` (the app's word on how the loop ended), given the
|
||||
* merged state so `evidence` can be checked against the docs on the page.
|
||||
* merged state so `evidence` (or, for a Review Loop's `kind: "review"`, `report`
|
||||
* and `partial.diff`) can be checked against the docs on the page.
|
||||
*/
|
||||
export function loopEndProblems(e, state) {
|
||||
const p = [];
|
||||
@@ -1718,7 +1874,8 @@ export function loopEndProblems(e, state) {
|
||||
const prose = (field, s) => {
|
||||
if (typeof s === "string") p.push(...proseProblems(s, `loopEnd.${field}`));
|
||||
};
|
||||
if (e.kind !== "stopped" && e.kind !== "finished") bad("kind", 'must be "stopped" or "finished"');
|
||||
if (e.kind === "review") return reviewLoopEndProblems(e, state);
|
||||
if (e.kind !== "stopped" && e.kind !== "finished") bad("kind", 'must be "stopped" or "finished" (or "review" for a Review Loop)');
|
||||
if (!oneLine(e.line, 200)) bad("line", "must be one line of 1 to 200 characters");
|
||||
else prose("line", e.line);
|
||||
if (e.evidence !== undefined) {
|
||||
@@ -1772,7 +1929,8 @@ export function loopEndProblems(e, state) {
|
||||
// Loop mode adds four optional keys that a blank state does not hold (absent,
|
||||
// not null): `loop: { driving: true, strength? }` (set by `open --loop`), `loopExpect`
|
||||
// (the app's judging criteria), `loopOutcome` (the skill's report) and
|
||||
// `loopEnd` (the app's ending).
|
||||
// `loopEnd` (the app's ending). A Review Loop round adds `roundOutcome` and
|
||||
// stamps `loop: { driving, round, role, scopeFile }`.
|
||||
export function blankState({ sid, workflow, title, project, specDir }) {
|
||||
return {
|
||||
schema: SCHEMA,
|
||||
@@ -1809,7 +1967,7 @@ export function switchWorkflow(state, { workflow, title, specDir }) {
|
||||
// A blank state holds no `loop`, `loopExpect`, `loopOutcome` or `loopEnd`,
|
||||
// so a hop never carries them over; `open --loop` stamps `loop` again after
|
||||
// the switch, and the app restamps `loopExpect` on its next look.
|
||||
for (const key of ["loop", "loopExpect", "loopOutcome", "loopEnd"]) delete next[key];
|
||||
for (const key of ["loop", "loopExpect", "loopOutcome", "loopEnd", "roundOutcome"]) delete next[key];
|
||||
if (state.chat) next.chat = state.chat;
|
||||
return next;
|
||||
}
|
||||
@@ -733,6 +733,13 @@ const LOOP_SKILL = SKILLS.find((s) => s.appOnly && s.card);
|
||||
export const LOOP_ENTRY = LOOP_SKILL
|
||||
? { skill: LOOP_SKILL.skill, command: "Desktop app only", workflow: null, appOnly: true, ...LOOP_SKILL.card }
|
||||
: null;
|
||||
// The Review Loop's card, the second app-only entry: same shape, own setup screen.
|
||||
const REVIEW_LOOP_SKILL = SKILLS.find((s) => s.appOnly && s.card && s !== LOOP_SKILL);
|
||||
export const REVIEW_LOOP_ENTRY = REVIEW_LOOP_SKILL
|
||||
? { skill: REVIEW_LOOP_SKILL.skill, command: "Desktop app only", workflow: null, appOnly: true, ...REVIEW_LOOP_SKILL.card }
|
||||
: null;
|
||||
// Every app-only card, in the order the dashboard draws them.
|
||||
export const APP_ONLY_ENTRIES = Object.freeze([LOOP_ENTRY, REVIEW_LOOP_ENTRY].filter(Boolean));
|
||||
export const OUTSIDE_APP_LINE = "Runs only in the Plan2Code desktop app.";
|
||||
|
||||
// A workflow by the name its dashboard card gives it ("Implement"), for the
|
||||
@@ -851,7 +858,7 @@ export function cardAvailability(entry, scan, sel, lookup = stateFor) {
|
||||
const hasAgents = Boolean(scan && scan.hasAgents);
|
||||
const state = sel && sel.state && sel.state !== "unrecognized" ? sel.state : null;
|
||||
const next = sel ? Boolean(state) && NEXT_FOR_STATE[state] === entry.skill : entry.skill === "plan2code-0-pathfinder";
|
||||
const rule = skillByName(entry.skill) || (entry.appOnly ? LOOP_SKILL : null);
|
||||
const rule = skillByName(entry.skill) || (entry.appOnly ? SKILLS.find((s) => s.appOnly && s.skill === entry.skill) || LOOP_SKILL : null);
|
||||
if (!rule || !rule.states) return ON;
|
||||
|
||||
// The three cards whose rules read the scan rather than the spec.
|
||||
|
||||
@@ -40,7 +40,8 @@ export function onAppMessage(kind, handler) {
|
||||
/**
|
||||
* Hear the app's answers to the Implementation Loop's named requests:
|
||||
* `loop-facts` (what agent a loop would use), `loop-start-result`,
|
||||
* `loop-notify-test-result` and the three stop-screen results. `store` is the page object and `redraw` its
|
||||
* `loop-notify-test-result` and the three stop-screen results, then the Review Loop's
|
||||
* `review-loop-facts` and `review-loop-start-result`. `store` is the page object and `redraw` its
|
||||
* render; they are handed in so this file keeps importing nothing.
|
||||
*/
|
||||
export function wireLoopMessages(store, redraw) {
|
||||
@@ -59,6 +60,31 @@ export function wireLoopMessages(store, redraw) {
|
||||
store.loopStart = { ok: data.ok === true, error: data.ok === true ? null : String(data.error || "The app did not start the loop.") };
|
||||
redraw();
|
||||
});
|
||||
// The Review Loop's own answers: its facts, and the result of its Start.
|
||||
onAppMessage("review-loop-facts", (data) => {
|
||||
store.reviewFacts = data.facts && typeof data.facts === "object" ? data.facts : null;
|
||||
redraw();
|
||||
});
|
||||
onAppMessage("review-loop-start-result", (data) => {
|
||||
// Cancel in the app's confirm: nothing started, so the setup is as it was.
|
||||
if (data.ok === true && data.started === false) {
|
||||
store.reviewStart = null;
|
||||
if (store.reviewLoopSetup) store.reviewLoopSetup.starting = false;
|
||||
redraw();
|
||||
return;
|
||||
}
|
||||
store.reviewStart = { ok: data.ok === true, error: data.ok === true ? null : String(data.error || "The app did not start the Review Loop.") };
|
||||
if (!store.reviewStart.ok && store.reviewLoopSetup) store.reviewLoopSetup.starting = false;
|
||||
redraw();
|
||||
});
|
||||
// The end screen's presses (Continue, Keep or Discard, Sign off, the finished
|
||||
// screen's next step): the answer clears the pressed state and keeps any error.
|
||||
for (const kind of ["review-loop-continue-result", "review-loop-partial-result", "review-loop-sign-off-result", "review-loop-next-result"]) {
|
||||
onAppMessage(kind, (data) => {
|
||||
store.reviewAction = { kind, ok: data.ok === true, error: data.ok === true ? null : String(data.error || "The app could not do that.") };
|
||||
redraw();
|
||||
});
|
||||
}
|
||||
onAppMessage("loop-notify-test-result", (data) => {
|
||||
store.loopNotifyTest = { waiting: false, ok: data.ok === true, sent: data.sent === true, error: data.ok === true ? null : String(data.error || "The app could not send the test.") };
|
||||
redraw();
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
adopt, askSuggestions, banner, clearBanner, connect, fillSky, fitGrowBox, loadState, markSent, maybeWelcome, render, renderFooter,
|
||||
renderSidebar, renderWhere, save, startClock, startLooks, stagedPayload, syncWorkspaceScope,
|
||||
wakeHoldsChime, wireAsk, wireCards, wireChrome, wireCleanup, wireDashboard, wireDocs, wireEnding,
|
||||
wireActivities, wireLoopSetup, wireHelp, launchSkill, sendLearning, beginLearningSave, renderLearningRow, learningBlocked, openHelpOn, openLoopSetup, wireLooks, wireNotepad, wirePrefs, wireWorkspace,
|
||||
wireActivities, wireLoopSetup, wireHelp, launchSkill, sendLearning, beginLearningSave, renderLearningRow, learningBlocked, openHelpOn, openLoopSetup, openReviewLoopSetup, wireLooks, wireNotepad, wirePrefs, wireWorkspace,
|
||||
openPrefs, markSaved, confirmUnsaved, loadAgentsView, wireAgentsView, hasUnsaved, unsavedName, saveOpen, discardOpen, focusOpen,
|
||||
renderCard, send, refreshLessonsSend,
|
||||
} from "./screens/core.js";
|
||||
@@ -37,7 +37,7 @@ import { sound } from "./sound.js";
|
||||
// and the few calls a screen makes into another are handed to state.js first.
|
||||
onSave(save);
|
||||
useHooks({
|
||||
launchSkill, sendLearning, beginLearningSave, renderLearningRow, learningBlocked, openHelpOn, openLoopSetup, askSuggestions, banner, clearBanner, fitGrowBox, markSent, maybeWelcome, renderFooter, renderSidebar, renderWhere, stagedPayload, syncWorkspaceScope,
|
||||
launchSkill, sendLearning, beginLearningSave, renderLearningRow, learningBlocked, openHelpOn, openLoopSetup, openReviewLoopSetup, askSuggestions, banner, clearBanner, fitGrowBox, markSent, maybeWelcome, renderFooter, renderSidebar, renderWhere, stagedPayload, syncWorkspaceScope,
|
||||
openPrefs, markSaved, confirmUnsaved, loadAgentsView, wireAgentsView, hasUnsaved, unsavedName, saveOpen, discardOpen, focusOpen,
|
||||
renderCard, send, refreshLessonsSend,
|
||||
});
|
||||
|
||||
@@ -2511,6 +2511,9 @@
|
||||
that skips what is not worth fixing and records each skip, or
|
||||
<strong>by level</strong> (Critical, Warning, Suggestion).
|
||||
</li>
|
||||
<li>
|
||||
<strong>Review rounds per phase</strong> (default 2): when a phase's own review leaves Critical or Warning, fresh reviewers run up to this many more rounds before the phase is committed.
|
||||
</li>
|
||||
<li>
|
||||
It uses the launch agent and model the app is running, and it needs
|
||||
<strong>permission checks off</strong>: with them on, an agent would
|
||||
|
||||
@@ -0,0 +1,262 @@
|
||||
// Plan2Code Web Console - the parts both loop setup screens draw, so neither screen imports the other; defines only.
|
||||
//
|
||||
// The Implementation Loop's screen (screens/loop-setup.js) and the Review Loop's
|
||||
// (screens/review-loop-setup.js) share these: the field builders, the strength
|
||||
// words, the notification fields with their checks, and the silence input. The
|
||||
// page's shape test keeps a screen from importing another screen, so what two
|
||||
// screens use lives here, beside state.js.
|
||||
|
||||
import { el } from "./render.js";
|
||||
import { page } from "./state.js";
|
||||
|
||||
export const STRENGTH_WORDS = [
|
||||
["thrifty", "Thrifty"],
|
||||
["balanced", "Balanced"],
|
||||
["best", "Best"],
|
||||
];
|
||||
export const MATCH_SESSION = "Match my session";
|
||||
|
||||
export const DEFAULT_NOTIFY_PARAM = "message";
|
||||
// What the setup can send a notification to. `name` is the label for the field
|
||||
// the person names, on the kinds that have one.
|
||||
export const NOTIFY_KINDS = [
|
||||
{ id: "query", label: "A web address, with the message in its query string", placeholder: "https://example.com/hook", hint: "The app calls this address with a GET.", name: "Query string name for the message" },
|
||||
{ id: "discord", label: "Discord webhook", placeholder: "https://discord.com/api/webhooks/...", hint: "In Discord: Edit Channel, Integrations, Webhooks, then Copy Webhook URL." },
|
||||
{ id: "slack", label: "Slack webhook", placeholder: "https://hooks.slack.com/services/...", hint: "An Incoming Webhook URL from your Slack app's settings." },
|
||||
{ id: "teams", label: "Microsoft Teams webhook", placeholder: "https://...", hint: 'In Teams: Workflows, the template "Post to a channel when a webhook request is received", then copy its URL.' },
|
||||
{ id: "google-chat", label: "Google Chat webhook", placeholder: "https://chat.googleapis.com/v1/spaces/...", hint: "In the space: Apps & integrations, Webhooks, then copy the URL." },
|
||||
{ id: "json", label: "A web address, with the message in a JSON body", placeholder: "https://example.com/hook", hint: "The app sends a POST with a JSON object holding the message, for any other service.", name: "JSON field name for the message" },
|
||||
];
|
||||
|
||||
export const hasMapping = (resolved) => Boolean(resolved) && Object.keys(resolved).length > 0;
|
||||
|
||||
/**
|
||||
* What is wrong with the web address fields as typed, or "". The server checks
|
||||
* again on save; this is the line that shows while typing.
|
||||
*/
|
||||
export function notifyProblem(url, param, kind = "query") {
|
||||
const address = url.trim();
|
||||
if (!address) return "";
|
||||
if (!/^https?:\/\//i.test(address)) return "The web address must start with http:// or https://.";
|
||||
let good = /^https?:\/\/[^/?#@]+([/?#][!-~]*)?$/i.test(address) && !/[^!-~]/.test(address);
|
||||
if (good) {
|
||||
try {
|
||||
good = Boolean(new URL(address).hostname);
|
||||
} catch {
|
||||
good = false;
|
||||
}
|
||||
}
|
||||
if (!good) return "That is not a web address the app can call. Leave out any user name or password, and percent-encode spaces and accents.";
|
||||
const named = NOTIFY_KINDS.some((k) => k.id === kind && k.name);
|
||||
if (named && !/^[A-Za-z0-9._~-]{1,64}$/.test(param.trim() || DEFAULT_NOTIFY_PARAM)) return "The name can only use letters, digits, and - _ . ~";
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* The chat service a pasted address belongs to, or "". A webhook needs a POST:
|
||||
* a GET to a Discord webhook answers 200 and posts nothing, so staying on the
|
||||
* query string kind would look like it worked.
|
||||
*/
|
||||
export function kindForUrl(url) {
|
||||
let parsed;
|
||||
try {
|
||||
parsed = new URL(url.trim());
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
const host = parsed.hostname.toLowerCase();
|
||||
const under = (domain) => host === domain || host.endsWith(`.${domain}`);
|
||||
if ((under("discord.com") || under("discordapp.com")) && parsed.pathname.startsWith("/api/webhooks/")) return "discord";
|
||||
if (host === "hooks.slack.com") return "slack";
|
||||
if (host === "chat.googleapis.com") return "google-chat";
|
||||
if (under("logic.azure.com") || under("powerplatform.com") || under("powerautomate.com")) return "teams";
|
||||
return "";
|
||||
}
|
||||
|
||||
export function field(label, hint) {
|
||||
const box = el("div", "loop-field");
|
||||
box.appendChild(el("p", "loop-label", label));
|
||||
if (hint) box.appendChild(el("p", "loop-hint", hint));
|
||||
return box;
|
||||
}
|
||||
|
||||
export function toggle(id, text, checked, onChange) {
|
||||
const label = el("label", "loop-switch");
|
||||
const input = el("input");
|
||||
input.type = "checkbox";
|
||||
input.id = id;
|
||||
input.checked = checked;
|
||||
input.addEventListener("change", () => onChange(input.checked));
|
||||
label.append(input, el("span", null, text));
|
||||
return label;
|
||||
}
|
||||
|
||||
export function radios(name, options, current, onChange) {
|
||||
const group = el("div", "loop-radios");
|
||||
group.setAttribute("role", "radiogroup");
|
||||
for (const [value, text, detail] of options) {
|
||||
const label = el("label", "loop-radio");
|
||||
const input = el("input");
|
||||
input.type = "radio";
|
||||
input.name = name;
|
||||
input.id = `loop-${name}-${value}`;
|
||||
input.checked = current === value;
|
||||
input.addEventListener("change", () => input.checked && onChange(value));
|
||||
const body = el("span", "loop-radio-body");
|
||||
body.appendChild(el("span", "loop-radio-text", text));
|
||||
if (detail) body.appendChild(el("span", "loop-radio-detail", detail));
|
||||
label.append(input, body);
|
||||
group.appendChild(label);
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
/** A plain select: [value, text, disabled?] options, the chosen value, a change handler. */
|
||||
export function select(id, label, options, value, onChange) {
|
||||
const box = el("select", "loop-select");
|
||||
box.id = id;
|
||||
box.setAttribute("aria-label", label);
|
||||
for (const [v, text, disabled] of options) {
|
||||
const o = el("option", null, text);
|
||||
o.value = v;
|
||||
o.disabled = Boolean(disabled);
|
||||
box.appendChild(o);
|
||||
}
|
||||
box.value = value;
|
||||
box.addEventListener("change", () => onChange(box.value));
|
||||
return box;
|
||||
}
|
||||
|
||||
/** The "stuck after this many minutes" number input, bound to `f.silenceMinutes`. */
|
||||
export function silenceField(f, text = "Count the agent as stuck after this many minutes with no activity") {
|
||||
const silence = el("label", "loop-number");
|
||||
silence.appendChild(el("span", null, text));
|
||||
const silenceInput = el("input", "is-compact loop-text loop-narrow");
|
||||
silenceInput.type = "number";
|
||||
silenceInput.id = "loop-silence";
|
||||
silenceInput.min = "1";
|
||||
silenceInput.max = "60";
|
||||
silenceInput.step = "1";
|
||||
silenceInput.value = String(f.silenceMinutes);
|
||||
silenceInput.addEventListener("input", () => {
|
||||
f.silenceMinutes = Number(silenceInput.value);
|
||||
});
|
||||
silence.appendChild(silenceInput);
|
||||
return silence;
|
||||
}
|
||||
|
||||
/**
|
||||
* The "Send a notification" field: kind, address, the name for the message, the
|
||||
* per-step toggle and Send a test. `s` is the screen's state (`starting`,
|
||||
* `notifyKindChosen`), `f` its form (`notifyKind`, `notifyUrl`, `notifyParam`,
|
||||
* and the toggle's key). `o` says what the toggle is called and keys on, and what
|
||||
* Send a test does (`onTest`, required); the Implementation Loop's screen takes the
|
||||
* other defaults.
|
||||
*/
|
||||
export function notifyFields(s, f, options = {}) {
|
||||
const o = {
|
||||
intro:
|
||||
"When the loop waits on your answer or ends, except when you stop it yourself, the app sends a short message saying which, with the project, the phase, what it built and how long it took. Leave the address empty to send nothing.",
|
||||
phasesId: "loop-notify-phases",
|
||||
phasesKey: "notifyPhases",
|
||||
phasesText: "Also tell me when each phase is complete",
|
||||
...options,
|
||||
};
|
||||
const notify = field("Send a notification", o.intro);
|
||||
const kindLabel = el("label", "loop-number");
|
||||
kindLabel.appendChild(el("span", null, "Send to"));
|
||||
const kindSelect = el("select", "is-compact loop-text");
|
||||
kindSelect.id = "loop-notify-kind";
|
||||
for (const kind of NOTIFY_KINDS) {
|
||||
const option = el("option", null, kind.label);
|
||||
option.value = kind.id;
|
||||
kindSelect.appendChild(option);
|
||||
}
|
||||
kindSelect.value = f.notifyKind;
|
||||
kindLabel.appendChild(kindSelect);
|
||||
const kindHint = el("p", "loop-hint");
|
||||
const notifyInput = el("input", "is-compact loop-text");
|
||||
notifyInput.type = "text";
|
||||
notifyInput.inputMode = "url";
|
||||
notifyInput.id = "loop-notify-url";
|
||||
notifyInput.value = f.notifyUrl;
|
||||
notifyInput.maxLength = 2000;
|
||||
notifyInput.setAttribute("aria-label", "Web address to call");
|
||||
const paramRow = el("div");
|
||||
const paramLabel = el("label", "loop-number");
|
||||
const paramText = el("span");
|
||||
paramLabel.appendChild(paramText);
|
||||
const paramInput = el("input", "is-compact loop-text loop-param");
|
||||
paramInput.type = "text";
|
||||
paramInput.id = "loop-notify-param";
|
||||
paramInput.value = f.notifyParam;
|
||||
paramInput.placeholder = DEFAULT_NOTIFY_PARAM;
|
||||
paramInput.maxLength = 64;
|
||||
paramLabel.appendChild(paramInput);
|
||||
paramRow.appendChild(paramLabel);
|
||||
const phasesRow = toggle(o.phasesId, o.phasesText, f[o.phasesKey], (v) => {
|
||||
f[o.phasesKey] = v;
|
||||
});
|
||||
const notifyWarn = el("p", "loop-warn");
|
||||
const testRow = el("div", "loop-test");
|
||||
const testButton = el("button", "btn", "Send a test");
|
||||
testButton.type = "button";
|
||||
testButton.id = "loop-notify-test";
|
||||
testButton.addEventListener("click", () => o.onTest());
|
||||
testRow.appendChild(testButton);
|
||||
const testLine = notifyTestLine();
|
||||
if (testLine) testRow.appendChild(testLine);
|
||||
const showNotify = () => {
|
||||
const kind = NOTIFY_KINDS.find((k) => k.id === f.notifyKind);
|
||||
kindSelect.value = kind.id;
|
||||
kindHint.textContent = kind.hint;
|
||||
notifyInput.placeholder = kind.placeholder;
|
||||
paramText.textContent = kind.name || "";
|
||||
paramRow.hidden = !kind.name || f.notifyUrl.trim() === "";
|
||||
phasesRow.hidden = f.notifyUrl.trim() === "";
|
||||
const problem = notifyProblem(f.notifyUrl, f.notifyParam, kind.id);
|
||||
notifyWarn.textContent = problem;
|
||||
notifyWarn.hidden = !problem;
|
||||
testButton.disabled = Boolean(problem) || f.notifyUrl.trim() === "" || Boolean(page.loopNotifyTest && page.loopNotifyTest.waiting) || s.starting;
|
||||
};
|
||||
// What a test said was about the address as it was.
|
||||
const forgetTest = () => {
|
||||
if (page.loopNotifyTest && !page.loopNotifyTest.waiting) {
|
||||
page.loopNotifyTest = null;
|
||||
testRow.querySelector("p")?.remove();
|
||||
}
|
||||
};
|
||||
notifyInput.addEventListener("input", () => {
|
||||
f.notifyUrl = notifyInput.value;
|
||||
forgetTest();
|
||||
// A pasted webhook picks its own kind, unless the person chose one here.
|
||||
const service = kindForUrl(f.notifyUrl);
|
||||
if (service && f.notifyKind === "query" && !s.notifyKindChosen) f.notifyKind = service;
|
||||
showNotify();
|
||||
});
|
||||
kindSelect.addEventListener("change", () => {
|
||||
f.notifyKind = kindSelect.value;
|
||||
forgetTest();
|
||||
s.notifyKindChosen = true;
|
||||
showNotify();
|
||||
});
|
||||
paramInput.addEventListener("input", () => {
|
||||
f.notifyParam = paramInput.value;
|
||||
forgetTest();
|
||||
showNotify();
|
||||
});
|
||||
showNotify();
|
||||
notify.append(kindLabel, notifyInput, kindHint, paramRow, phasesRow, notifyWarn, testRow);
|
||||
return notify;
|
||||
}
|
||||
|
||||
/** The line beside Send a test, or null with nothing to say. */
|
||||
export function notifyTestLine() {
|
||||
const test = page.loopNotifyTest;
|
||||
if (!test) return null;
|
||||
if (test.waiting) return el("p", "loop-why", "Waiting for the app's confirm...");
|
||||
if (!test.ok) return el("p", "loop-error", test.error);
|
||||
if (test.sent) return el("p", "loop-why", "Sent, and the address answered OK. Check that the message arrived.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
// Plan2Code Web Console - how a Review Loop run ends: the stop screens, the sign-off and the finished screen; defines only.
|
||||
|
||||
import { el } from "./render.js";
|
||||
import { field, toggle } from "./loop-parts.js";
|
||||
import { blockBody } from "./doc-files.js";
|
||||
import { docs } from "./selectors.js";
|
||||
import { tellApp } from "./app-bridge.js";
|
||||
import { page, redraw } from "./state.js";
|
||||
|
||||
// The app's `loopEnd` with `kind: "review"` (patches.mjs reviewLoopEndProblems):
|
||||
// reason why it ended: clean, cap, person or failed
|
||||
// report a doc on the page holding the Markdown report
|
||||
// partial after Stop now: the partial diff doc and its stats, until Keep or Discard
|
||||
// suggestions, canSquash, canContinue, open, signedOff, note
|
||||
// Before sign-off the card offers Continue (when allowed), the Suggestions pick,
|
||||
// the squash switch and Sign off; after it, the finished screen's three ways on.
|
||||
|
||||
const HEADINGS = {
|
||||
clean: "Clean",
|
||||
cap: "Stopped at the round cap",
|
||||
person: "Stopped by you",
|
||||
failed: "Failed",
|
||||
};
|
||||
|
||||
// What the card remembers across redraws, keyed by the ending it belongs to:
|
||||
// the ticked Suggestions, the squash switch, and which press is waiting on the app.
|
||||
let ticks = { key: null, picks: new Set(), squash: false };
|
||||
let pressed = { key: null, what: "" };
|
||||
let lastKey = null;
|
||||
|
||||
// The ending a press belongs to. Keep or Discard reposts the same ending without
|
||||
// its partial changes, so a press waiting on the app ends with that change.
|
||||
function endKey(end) {
|
||||
return `review|${end.line}|${end.reason}|${end.signedOff ? "signed" : "open"}|${end.partial ? "partial" : "whole"}`;
|
||||
}
|
||||
|
||||
// The ending the ticks and the squash switch belong to: the same through Keep
|
||||
// or Discard, so what the person ticked is not cleared by settling the partial changes.
|
||||
function tickKey(end) {
|
||||
return `review|${end.line}|${end.reason}|${end.signedOff ? "signed" : "open"}`;
|
||||
}
|
||||
|
||||
function button(label, id, cls, disabled, onClick) {
|
||||
const b = el("button", "btn" + (cls ? " " + cls : ""), label);
|
||||
b.type = "button";
|
||||
b.id = id;
|
||||
b.disabled = disabled;
|
||||
b.addEventListener("click", onClick);
|
||||
return b;
|
||||
}
|
||||
|
||||
function stats(partial) {
|
||||
const row = el("p", "diff-totals review-end-stats");
|
||||
row.appendChild(el("span", null, `${partial.files} ${partial.files === 1 ? "file" : "files"} changed, `));
|
||||
row.appendChild(el("span", "diff-plus", `+${partial.added}`));
|
||||
row.appendChild(document.createTextNode(" "));
|
||||
row.appendChild(el("span", "diff-minus", `-${partial.removed}`));
|
||||
return row;
|
||||
}
|
||||
|
||||
function where(item) {
|
||||
if (!item.file) return "";
|
||||
return item.line ? `${item.file}:${item.line}` : item.file;
|
||||
}
|
||||
|
||||
/** How a Review Loop run ended, drawn from the app's `loopEnd`. */
|
||||
export function renderReviewLoopEnd(end) {
|
||||
const key = endKey(end);
|
||||
if (lastKey !== key) {
|
||||
lastKey = key;
|
||||
page.reviewAction = null;
|
||||
}
|
||||
const ticked = tickKey(end);
|
||||
if (ticks.key !== ticked) ticks = { key: ticked, picks: new Set(), squash: false };
|
||||
const failed =
|
||||
page.reviewAction && !page.reviewAction.ok ? page.reviewAction.error : page.loopAction && !page.loopAction.ok ? page.loopAction.error : "";
|
||||
const busy = pressed.key === key && !failed;
|
||||
const press = (what, kind, extra) => {
|
||||
if (page.gone || busy) return;
|
||||
pressed = { key, what };
|
||||
page.reviewAction = null;
|
||||
page.loopAction = null;
|
||||
tellApp(kind, extra);
|
||||
redraw();
|
||||
};
|
||||
|
||||
const card = el("article", "card handoff loop-end review-end");
|
||||
card.appendChild(el("p", "card-kicker", end.signedOff ? "Review Loop finished" : "Review Loop ended"));
|
||||
const heading = end.signedOff ? "Signed off" : HEADINGS[end.reason] || end.line;
|
||||
card.appendChild(el("h2", "loop-end-heading review-end-heading", heading));
|
||||
if (end.line) card.appendChild(el("p", "loop-line review-end-line", end.line));
|
||||
if (end.note) card.appendChild(el("p", "callout is-info review-end-note", end.note));
|
||||
|
||||
const report = docs().find((d) => d.id === end.report);
|
||||
if (report) {
|
||||
const read = el("button", "btn sm review-end-report", "Read the full report");
|
||||
read.type = "button";
|
||||
read.addEventListener("click", () => {
|
||||
page.view = "doc:" + report.id;
|
||||
redraw();
|
||||
});
|
||||
card.appendChild(read);
|
||||
}
|
||||
|
||||
if (end.signedOff) {
|
||||
drawFinished(card, end, busy, press);
|
||||
} else {
|
||||
drawStop(card, end, busy, press);
|
||||
}
|
||||
if (failed) card.appendChild(el("p", "loop-error review-end-error", failed));
|
||||
return card;
|
||||
}
|
||||
|
||||
function drawPartial(card, end, busy, press) {
|
||||
const partial = end.partial;
|
||||
const box = el("section", "review-end-partial");
|
||||
box.appendChild(el("h3", null, "What Stop now left"));
|
||||
box.appendChild(stats(partial));
|
||||
const doc = docs().find((d) => d.id === partial.diff);
|
||||
const block = doc && (doc.blocks || []).find((b) => typeof b.diff === "string" || typeof b.text === "string");
|
||||
if (block) {
|
||||
const view = el("div", "review-end-diff");
|
||||
view.appendChild(blockBody(block, doc));
|
||||
box.appendChild(view);
|
||||
}
|
||||
box.appendChild(el("p", "loop-end-hint", "Keep leaves these changes in your files. Discard takes them out and cannot be undone."));
|
||||
const row = el("div", "btn-row");
|
||||
row.appendChild(button("Keep these changes", "review-end-keep", "primary", busy, () => press("keep", "review-loop-partial", { keep: true })));
|
||||
row.appendChild(button("Discard them", "review-end-discard", "", busy, () => press("discard", "review-loop-partial", { keep: false })));
|
||||
box.appendChild(row);
|
||||
card.appendChild(box);
|
||||
}
|
||||
|
||||
function drawStop(card, end, busy, press) {
|
||||
if (end.partial) drawPartial(card, end, busy, press);
|
||||
// While the partial work is undecided the app refuses Continue, so it is not offered.
|
||||
if (end.canContinue && !end.partial) {
|
||||
const choice = el("div", "loop-end-choice");
|
||||
const label = end.reason === "cap" ? "Run one more round" : "Continue";
|
||||
choice.appendChild(button(label, "review-end-continue", "", busy, () => press("continue", "review-loop-continue")));
|
||||
choice.appendChild(el("p", "loop-end-hint", "Pick the review up again with the same setup."));
|
||||
card.appendChild(choice);
|
||||
}
|
||||
|
||||
const suggestions = Array.isArray(end.suggestions) ? end.suggestions : [];
|
||||
if (suggestions.length) {
|
||||
const pick = field("Suggestions", "Nothing is ticked. Ticked ones are applied in one last pass, with their own check and commit.");
|
||||
pick.classList.add("review-end-suggestions");
|
||||
for (const s of suggestions) {
|
||||
const label = toggle(`review-end-pick-${s.id}`, "", ticks.picks.has(s.id), (on) => {
|
||||
if (on) ticks.picks.add(s.id);
|
||||
else ticks.picks.delete(s.id);
|
||||
});
|
||||
label.classList.add("review-end-pick");
|
||||
const text = label.querySelector("span");
|
||||
text.appendChild(el("strong", null, s.title));
|
||||
const at = where(s);
|
||||
if (at) text.appendChild(el("code", "review-end-where", at));
|
||||
pick.appendChild(label);
|
||||
}
|
||||
card.appendChild(pick);
|
||||
}
|
||||
if (end.canSquash) {
|
||||
const sq = field("Commits");
|
||||
sq.appendChild(toggle("review-end-squash", "Squash the round commits into one", ticks.squash, (on) => (ticks.squash = on)));
|
||||
card.appendChild(sq);
|
||||
}
|
||||
const row = el("div", "btn-row");
|
||||
row.appendChild(
|
||||
button("Sign off", "review-end-signoff", "primary", busy || Boolean(end.partial), () => press("sign-off", "review-loop-sign-off", { picks: [...ticks.picks], squash: ticks.squash }))
|
||||
);
|
||||
card.appendChild(row);
|
||||
card.appendChild(
|
||||
el("p", "loop-end-hint", end.partial ? "Keep or discard the partial changes first, then sign off." : "Sign off finishes the run, with or without picks.")
|
||||
);
|
||||
}
|
||||
|
||||
function drawFinished(card, end, busy, press) {
|
||||
const actions = el("div", "loop-end-actions review-end-next");
|
||||
const add = (label, id, hint, primary, onClick) => {
|
||||
const choice = el("div", "loop-end-choice" + (primary ? " is-recommended" : ""));
|
||||
choice.appendChild(button(label, id, primary ? "primary" : "", busy, onClick));
|
||||
choice.appendChild(el("p", "loop-end-hint", hint));
|
||||
actions.appendChild(choice);
|
||||
};
|
||||
add("PR Prep", "review-end-pr-prep", "Get the branch ready for a pull request.", true, () => press("pr-prep", "review-loop-next", { next: "pr-prep" }));
|
||||
if (Array.isArray(end.open) && end.open.length) {
|
||||
add("Fix what's left by hand", "review-end-quick-task", "Start a Quick task with the Critical and Warning findings still open.", false, () =>
|
||||
press("quick-task", "review-loop-next", { next: "quick-task" })
|
||||
);
|
||||
}
|
||||
add("Back to the dashboard", "review-end-dashboard", "Leave this screen and pick another skill. Your work stays as it is.", false, () => press("dashboard", "loop-dashboard"));
|
||||
card.appendChild(actions);
|
||||
}
|
||||
|
||||
/** The end card is no longer drawn (Continue started another round): a press and
|
||||
* the ending it belonged to are over, so the next ending starts with live buttons. */
|
||||
export function forgetReviewEnd() {
|
||||
pressed = { key: null, what: "" };
|
||||
lastKey = null;
|
||||
}
|
||||
@@ -68,6 +68,7 @@ import {
|
||||
import { sound } from "../sound.js";
|
||||
import { renderConfirm, renderDashboard } from "./dashboard.js";
|
||||
import { renderLoopSetup } from "./loop-setup.js";
|
||||
import { renderReviewLoopSetup } from "./review-loop-setup.js";
|
||||
import { renderLaunching, renderWaiting } from "./starting.js";
|
||||
import { attachFiles, findSetAside, heldNotes, noteImages, pendingNotes, purgeImages } from "../uploads.js";
|
||||
import { closeMentions } from "../mention-box.js";
|
||||
@@ -82,6 +83,7 @@ import { framed, linkLeavesPage, onAppMessage, shortcutIdFor, startNewSession, t
|
||||
import { openPrefs as openPrefsDialog } from "./prefs-dialog.js";
|
||||
import { continueButton } from "../continue-button.js";
|
||||
import { askOfflineFlipped, askState, declineOpen, renderAside, renderAsk, renderSubagents, renderSubagentsButton } from "./ask.js";
|
||||
import { forgetReviewEnd } from "../review-loop-end.js";
|
||||
import { renderHandoff, renderLoopEnd, renderHomeButton, renderStopButton, renderStopControls, renderStopping, renderFooterDashboard, stopInProgress, stopWarning } from "./ending.js";
|
||||
import { renderNotepadButton } from "./notepad.js";
|
||||
import { renderActivities } from "./activities.js";
|
||||
@@ -107,6 +109,7 @@ export { wireEnding } from "./ending.js";
|
||||
export { wireNotepad } from "./notepad.js";
|
||||
export { wireActivities } from "./activities.js";
|
||||
export { openLoopSetup, wireLoopSetup } from "./loop-setup.js";
|
||||
export { openReviewLoopSetup } from "./review-loop-setup.js";
|
||||
|
||||
const $ = (id) => document.getElementById(id);
|
||||
|
||||
@@ -450,6 +453,7 @@ export function adopt(body) {
|
||||
if (!isDashboard() || finish()) {
|
||||
page.dashPick = null;
|
||||
page.loopSetup = null;
|
||||
page.reviewLoopSetup = null;
|
||||
}
|
||||
// A launch (or an ending) mid wake-up: cut it short rather than play on
|
||||
// over a page that is no longer the menu.
|
||||
@@ -1419,6 +1423,9 @@ export function renderStatus() {
|
||||
// still has presses on offer the move is theirs; with none, it is done.
|
||||
if (page.S.loopEnd) {
|
||||
const end = page.S.loopEnd;
|
||||
if (end.kind === "review") {
|
||||
return end.signedOff ? say("point", "Signed off. Pick what happens next.") : say("point", "The Review Loop ended. Sign off when you are ready.");
|
||||
}
|
||||
const moves = Array.isArray(end.can) ? end.can.length : 0;
|
||||
if (!moves) return say("done", "The loop is done.");
|
||||
return say(
|
||||
@@ -1805,6 +1812,7 @@ function paintMain(main) {
|
||||
if (isDashboard() && !finish()) {
|
||||
if (page.local.launching) renderLaunching(main);
|
||||
else if (page.loopSetup) renderLoopSetup(main);
|
||||
else if (page.reviewLoopSetup) renderReviewLoopSetup(main);
|
||||
else if (page.dashPick) {
|
||||
// A spec-switch under an open confirm can gray the pick out. Rather
|
||||
// than offer START on a card that cannot launch, drop back to the
|
||||
@@ -1816,7 +1824,7 @@ function paintMain(main) {
|
||||
}
|
||||
} else renderDashboard(main);
|
||||
// Review from the Learning banner: the lessons card, over the menu.
|
||||
renderLessonsDialog(!page.local.launching && !page.loopSetup && !page.dashPick);
|
||||
renderLessonsDialog(!page.local.launching && !page.loopSetup && !page.reviewLoopSetup && !page.dashPick);
|
||||
return;
|
||||
}
|
||||
renderLessonsDialog(false);
|
||||
@@ -1849,6 +1857,7 @@ function paintMain(main) {
|
||||
|
||||
// How the Implementation Loop ended, from the app's `loopEnd`: its own
|
||||
// screen, ahead of any card the last phase left behind.
|
||||
if (!page.S.loopEnd) forgetReviewEnd();
|
||||
if (page.S.loopEnd && !finish()) {
|
||||
const card = renderLoopEnd(page.S.loopEnd);
|
||||
card.classList.add("is-primary");
|
||||
@@ -2601,9 +2610,10 @@ export function wireChrome() {
|
||||
// Escape is the confirm pane's Back — but not while a dialog has it. Native
|
||||
// dialogs close themselves on the same key; backing out of the pick at the
|
||||
// same time would be two undos for one press.
|
||||
if (e.key === "Escape" && (page.dashPick || page.loopSetup) && isDashboard() && !finish() && !document.querySelector("dialog[open]")) {
|
||||
if (e.key === "Escape" && (page.dashPick || page.loopSetup || page.reviewLoopSetup) && isDashboard() && !finish() && !document.querySelector("dialog[open]")) {
|
||||
page.dashPick = null;
|
||||
page.loopSetup = null;
|
||||
page.reviewLoopSetup = null;
|
||||
redraw();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
SKILL_CATALOG,
|
||||
catalogEntry,
|
||||
LOOP_ENTRY,
|
||||
APP_ONLY_ENTRIES,
|
||||
OUTSIDE_APP_LINE,
|
||||
launchVariant,
|
||||
SPEC_STATE_LABELS,
|
||||
@@ -296,16 +297,17 @@ export function renderDashboard(main) {
|
||||
let shown = 0;
|
||||
for (const g of CATALOG_GROUPS) {
|
||||
const entries = SKILL_CATALOG.filter((e) => e.group === g.id && (!hide || available(e)));
|
||||
// The desktop app's Implementation Loop card closes its group. Outside the
|
||||
// app it is always drawn, grayed, so the feature can be found.
|
||||
const loopCard = LOOP_ENTRY && LOOP_ENTRY.group === g.id && (!page.inApp || !hide || available(LOOP_ENTRY));
|
||||
if (!entries.length && !loopCard) continue;
|
||||
shown += entries.length + (loopCard ? 1 : 0);
|
||||
// The desktop app's Implementation Loop and Review Loop cards close their
|
||||
// group. Outside the app they are always drawn, grayed, so the features can
|
||||
// be found.
|
||||
const loopCards = APP_ONLY_ENTRIES.filter((e) => e.group === g.id && (!page.inApp || !hide || available(e)));
|
||||
if (!entries.length && !loopCards.length) continue;
|
||||
shown += entries.length + loopCards.length;
|
||||
const section = el("section", "dash-group");
|
||||
section.appendChild(el("h3", "dash-group-title", g.title));
|
||||
const grid = el("div", "dash-grid");
|
||||
for (const e of entries) grid.appendChild(dashCard(e, menu));
|
||||
if (loopCard) grid.appendChild(dashCard(LOOP_ENTRY, menu));
|
||||
for (const e of loopCards) grid.appendChild(dashCard(e, menu));
|
||||
section.appendChild(grid);
|
||||
wrap.appendChild(section);
|
||||
}
|
||||
@@ -752,6 +754,8 @@ async function readHandoff(h) {
|
||||
}
|
||||
}
|
||||
|
||||
const REVIEW_LOOP_SKILL = "plan2code-review-loop";
|
||||
|
||||
function dashCard(entry, menu) {
|
||||
const presentation = entry.appOnly ? loopPresentation(entry, menu) : cardPresentation(entry, scan(), selSpec(), menu);
|
||||
// The agent's `recommend` and detail describe the initially selected spec.
|
||||
@@ -784,6 +788,8 @@ function dashCard(entry, menu) {
|
||||
title.appendChild(document.createTextNode(entry.title));
|
||||
b.appendChild(title);
|
||||
b.appendChild(el("span", "dash-card-blurb", entry.blurb));
|
||||
// A line only the desktop app shows (the Review card's pointer to the Review Loop).
|
||||
if (entry.appNote && page.inApp) b.appendChild(el("span", "dash-card-detail", entry.appNote));
|
||||
if (presentation.detail) b.appendChild(el("span", "dash-card-detail", presentation.detail));
|
||||
if (!presentation.on && presentation.reason) b.appendChild(el("span", "dash-card-off", presentation.reason));
|
||||
|
||||
@@ -793,8 +799,8 @@ function dashCard(entry, menu) {
|
||||
b.appendChild(foot);
|
||||
|
||||
b.addEventListener("click", () => {
|
||||
// The loop card opens its own setup screen instead of a confirm pane.
|
||||
if (entry.appOnly) return hooks.openLoopSetup(selSpec());
|
||||
// A loop card opens its own setup screen instead of a confirm pane.
|
||||
if (entry.appOnly) return entry.skill === REVIEW_LOOP_SKILL ? hooks.openReviewLoopSetup(selSpec()) : hooks.openLoopSetup(selSpec());
|
||||
page.dashPick = entry;
|
||||
redraw();
|
||||
});
|
||||
@@ -803,7 +809,7 @@ function dashCard(entry, menu) {
|
||||
if (entry.appOnly) {
|
||||
const wrap = el("div", "dash-card-wrap");
|
||||
wrap.appendChild(b);
|
||||
wrap.appendChild(loopHelpLink());
|
||||
wrap.appendChild(loopHelpLink(entry));
|
||||
return wrap;
|
||||
}
|
||||
return b;
|
||||
@@ -814,13 +820,17 @@ function dashCard(entry, menu) {
|
||||
// pre-selected: a person opts into running unattended.
|
||||
function loopPresentation(entry, menu) {
|
||||
if (!page.inApp) return { on: false, reason: OUTSIDE_APP_LINE, recommended: false, detail: "" };
|
||||
if (entry.skill === REVIEW_LOOP_SKILL && loopDriving()) {
|
||||
return { on: false, reason: "A loop is running. Stop it from the banner at the top of the window first.", recommended: false, detail: "" };
|
||||
}
|
||||
return { ...cardPresentation(entry, scan(), selSpec(), menu), recommended: false };
|
||||
}
|
||||
|
||||
// "How the loop works" under the card: a real button styled as a link, a
|
||||
// sibling of the card button inside its wrapper.
|
||||
function loopHelpLink() {
|
||||
const a = el("button", "dash-card-link", "How the loop works");
|
||||
function loopHelpLink(entry) {
|
||||
const review = entry && entry.skill === REVIEW_LOOP_SKILL;
|
||||
const a = el("button", "dash-card-link", review ? "How the Review Loop works" : "How the loop works");
|
||||
a.type = "button";
|
||||
a.addEventListener("click", () => hooks.openHelpOn("loop"));
|
||||
return a;
|
||||
|
||||
@@ -55,6 +55,7 @@ const LOOP_LOCK_TITLE = "The loop is building. Stop it from the banner at the to
|
||||
import { docSavedNote, downloadDoc } from "../doc-files.js";
|
||||
import { startNewSession, tellApp } from "../app-bridge.js";
|
||||
import { pendingNotes } from "../uploads.js";
|
||||
import { renderReviewLoopEnd } from "../review-loop-end.js";
|
||||
|
||||
// The end of the session, and the only screen in this page whose job is to
|
||||
// send someone somewhere else.
|
||||
@@ -239,6 +240,7 @@ function loopEndKey(end) {
|
||||
* its agent made; the report behind the button holds them all).
|
||||
*/
|
||||
export function renderLoopEnd(end) {
|
||||
if (end.kind === "review") return renderReviewLoopEnd(end);
|
||||
const card = el("article", "card handoff loop-end");
|
||||
const finished = end.kind === "finished";
|
||||
card.appendChild(el("p", "card-kicker", finished ? "Loop finished" : "Loop stopped"));
|
||||
|
||||
@@ -272,6 +272,8 @@ function buildHelp() {
|
||||
}
|
||||
li.appendChild(strong);
|
||||
li.appendChild(document.createTextNode(" " + (e.help || e.blurb)));
|
||||
// The app-only pointer (Review's line about the Review Loop), shown in the app.
|
||||
if (e.appNote && page.inApp) li.appendChild(el("span", "help-app-note", " " + e.appNote));
|
||||
list.appendChild(li);
|
||||
}
|
||||
cards.append(head, list);
|
||||
|
||||
@@ -11,6 +11,7 @@ import { hooks, page, redraw, saveNow } from "../state.js";
|
||||
import { SKILL_CATALOG } from "../answers.js";
|
||||
import { postJson } from "../net.js";
|
||||
import { tellApp, wireLoopMessages } from "../app-bridge.js";
|
||||
import { DEFAULT_NOTIFY_PARAM, MATCH_SESSION, NOTIFY_KINDS, STRENGTH_WORDS, field, hasMapping, notifyFields, notifyProblem, radios, select, silenceField, toggle } from "../loop-parts.js";
|
||||
|
||||
let justPicked = ""; // the strength node picked a moment ago, which alone plays its grow
|
||||
// Suggest for me was pressed and has just come back (answer, time-out or failed
|
||||
@@ -34,26 +35,9 @@ const AFTER_LAST = [
|
||||
["run-finalize", "Run Finalize automatically", "Finalize starts by itself once every phase is built."],
|
||||
];
|
||||
|
||||
const STRENGTH_WORDS = [
|
||||
["thrifty", "Thrifty"],
|
||||
["balanced", "Balanced"],
|
||||
["best", "Best"],
|
||||
];
|
||||
const MATCH_SESSION = "Match my session";
|
||||
// How long Suggest for me waits on the dashboard agent before it gives the field back.
|
||||
export const SUGGEST_WAIT_MS = 120000;
|
||||
|
||||
const DEFAULT_NOTIFY_PARAM = "message";
|
||||
// What the setup can send a notification to. `name` is the label for the field
|
||||
// the person names, on the kinds that have one.
|
||||
const NOTIFY_KINDS = [
|
||||
{ id: "query", label: "A web address, with the message in its query string", placeholder: "https://example.com/hook", hint: "The app calls this address with a GET.", name: "Query string name for the message" },
|
||||
{ id: "discord", label: "Discord webhook", placeholder: "https://discord.com/api/webhooks/...", hint: "In Discord: Edit Channel, Integrations, Webhooks, then Copy Webhook URL." },
|
||||
{ id: "slack", label: "Slack webhook", placeholder: "https://hooks.slack.com/services/...", hint: "An Incoming Webhook URL from your Slack app's settings." },
|
||||
{ id: "teams", label: "Microsoft Teams webhook", placeholder: "https://...", hint: 'In Teams: Workflows, the template "Post to a channel when a webhook request is received", then copy its URL.' },
|
||||
{ id: "google-chat", label: "Google Chat webhook", placeholder: "https://chat.googleapis.com/v1/spaces/...", hint: "In the space: Apps & integrations, Webhooks, then copy the URL." },
|
||||
{ id: "json", label: "A web address, with the message in a JSON body", placeholder: "https://example.com/hook", hint: "The app sends a POST with a JSON object holding the message, for any other service.", name: "JSON field name for the message" },
|
||||
];
|
||||
const SMART_DETAIL = "A fresh agent reads the review's findings and fixes the ones worth fixing. A skipped Critical stops the phase.";
|
||||
|
||||
/** Called by the page's start-up: hear the app's answers to the loop's requests. */
|
||||
@@ -97,6 +81,7 @@ export async function openLoopSetup(spec) {
|
||||
const { phasesLeft, branch, pending, suggestedQuickCheck, remembered, saved, picks, resolved, ...setup } = answer;
|
||||
mine.form = {
|
||||
review: setup.review !== false,
|
||||
reviewRounds: Number.isInteger(setup.reviewRounds) && setup.reviewRounds >= 0 && setup.reviewRounds <= 6 ? setup.reviewRounds : 2,
|
||||
fixMode: setup.fixMode === "levels" ? "levels" : "smart",
|
||||
fix: Array.isArray(setup.fix) ? [...setup.fix] : LEVELS.map(([k]) => k),
|
||||
commit: setup.commit !== false,
|
||||
@@ -154,8 +139,6 @@ function ensureResolved(s) {
|
||||
});
|
||||
}
|
||||
|
||||
const hasMapping = (resolved) => Boolean(resolved) && Object.keys(resolved).length > 0;
|
||||
|
||||
/** This spec's saved word for a phase, or "" for Match my session. */
|
||||
function pickOf(form, spec, phase) {
|
||||
const list = form.strengths && form.strengths[spec];
|
||||
@@ -220,87 +203,6 @@ export function startBlock(form, facts, appFacts) {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* What is wrong with the web address fields as typed, or "". The server checks
|
||||
* again on save; this is the line that shows while typing.
|
||||
*/
|
||||
export function notifyProblem(url, param, kind = "query") {
|
||||
const address = url.trim();
|
||||
if (!address) return "";
|
||||
if (!/^https?:\/\//i.test(address)) return "The web address must start with http:// or https://.";
|
||||
let good = /^https?:\/\/[^/?#@]+([/?#][!-~]*)?$/i.test(address) && !/[^!-~]/.test(address);
|
||||
if (good) {
|
||||
try {
|
||||
good = Boolean(new URL(address).hostname);
|
||||
} catch {
|
||||
good = false;
|
||||
}
|
||||
}
|
||||
if (!good) return "That is not a web address the app can call. Leave out any user name or password, and percent-encode spaces and accents.";
|
||||
const named = NOTIFY_KINDS.some((k) => k.id === kind && k.name);
|
||||
if (named && !/^[A-Za-z0-9._~-]{1,64}$/.test(param.trim() || DEFAULT_NOTIFY_PARAM)) return "The name can only use letters, digits, and - _ . ~";
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* The chat service a pasted address belongs to, or "". A webhook needs a POST:
|
||||
* a GET to a Discord webhook answers 200 and posts nothing, so staying on the
|
||||
* query string kind would look like it worked.
|
||||
*/
|
||||
export function kindForUrl(url) {
|
||||
let parsed;
|
||||
try {
|
||||
parsed = new URL(url.trim());
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
const host = parsed.hostname.toLowerCase();
|
||||
const under = (domain) => host === domain || host.endsWith(`.${domain}`);
|
||||
if ((under("discord.com") || under("discordapp.com")) && parsed.pathname.startsWith("/api/webhooks/")) return "discord";
|
||||
if (host === "hooks.slack.com") return "slack";
|
||||
if (host === "chat.googleapis.com") return "google-chat";
|
||||
if (under("logic.azure.com") || under("powerplatform.com") || under("powerautomate.com")) return "teams";
|
||||
return "";
|
||||
}
|
||||
|
||||
function field(label, hint) {
|
||||
const box = el("div", "loop-field");
|
||||
box.appendChild(el("p", "loop-label", label));
|
||||
if (hint) box.appendChild(el("p", "loop-hint", hint));
|
||||
return box;
|
||||
}
|
||||
|
||||
function toggle(id, text, checked, onChange) {
|
||||
const label = el("label", "loop-switch");
|
||||
const input = el("input");
|
||||
input.type = "checkbox";
|
||||
input.id = id;
|
||||
input.checked = checked;
|
||||
input.addEventListener("change", () => onChange(input.checked));
|
||||
label.append(input, el("span", null, text));
|
||||
return label;
|
||||
}
|
||||
|
||||
function radios(name, options, current, onChange) {
|
||||
const group = el("div", "loop-radios");
|
||||
group.setAttribute("role", "radiogroup");
|
||||
for (const [value, text, detail] of options) {
|
||||
const label = el("label", "loop-radio");
|
||||
const input = el("input");
|
||||
input.type = "radio";
|
||||
input.name = name;
|
||||
input.id = `loop-${name}-${value}`;
|
||||
input.checked = current === value;
|
||||
input.addEventListener("change", () => input.checked && onChange(value));
|
||||
const body = el("span", "loop-radio-body");
|
||||
body.appendChild(el("span", "loop-radio-text", text));
|
||||
if (detail) body.appendChild(el("span", "loop-radio-detail", detail));
|
||||
label.append(input, body);
|
||||
group.appendChild(label);
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
function factRow(list, label, value) {
|
||||
const row = el("div", "loop-fact");
|
||||
row.appendChild(el("dt", null, label));
|
||||
@@ -348,22 +250,6 @@ export function renderLoopSetup(main) {
|
||||
main.appendChild(pane);
|
||||
}
|
||||
|
||||
/** A plain select: [value, text, disabled?] options, the chosen value, a change handler. */
|
||||
function select(id, label, options, value, onChange) {
|
||||
const box = el("select", "loop-select");
|
||||
box.id = id;
|
||||
box.setAttribute("aria-label", label);
|
||||
for (const [v, text, disabled] of options) {
|
||||
const o = el("option", null, text);
|
||||
o.value = v;
|
||||
o.disabled = Boolean(disabled);
|
||||
box.appendChild(o);
|
||||
}
|
||||
box.value = value;
|
||||
box.addEventListener("change", () => onChange(box.value));
|
||||
return box;
|
||||
}
|
||||
|
||||
/**
|
||||
* The rising-bar badge of the Subagents tab for a strength level: bars up to
|
||||
* `level` (1 to 3) are on. Level 0 (Match my session) has no rank, so it draws
|
||||
@@ -521,7 +407,7 @@ function applySuggestion(s, answer, resolved) {
|
||||
}
|
||||
|
||||
/** The "Strength per phase" field: the toggle, Set all to, and one row per phase left. */
|
||||
function strengthField(s, redo) {
|
||||
export function strengthField(s, redo) {
|
||||
stopWatchingLine();
|
||||
const f = s.form;
|
||||
const resolved = s.facts.resolved;
|
||||
@@ -697,6 +583,7 @@ function drawBody(pane, s) {
|
||||
|
||||
const review = field("Review");
|
||||
review.appendChild(toggle("loop-review", "Review each phase with a fresh agent before it counts", f.review, (v) => ((f.review = v), redo())));
|
||||
review.appendChild(roundsField(f));
|
||||
form.appendChild(review);
|
||||
|
||||
if (f.review) {
|
||||
@@ -735,95 +622,7 @@ function drawBody(pane, s) {
|
||||
after.appendChild(radios("afterlast", AFTER_LAST, f.afterLast, (v) => ((f.afterLast = v), redo())));
|
||||
form.appendChild(after);
|
||||
|
||||
const notify = field(
|
||||
"Send a notification",
|
||||
"When the loop waits on your answer or ends, except when you stop it yourself, the app sends a short message saying which, with the project, the phase, what it built and how long it took. Leave the address empty to send nothing."
|
||||
);
|
||||
const kindLabel = el("label", "loop-number");
|
||||
kindLabel.appendChild(el("span", null, "Send to"));
|
||||
const kindSelect = el("select", "is-compact loop-text");
|
||||
kindSelect.id = "loop-notify-kind";
|
||||
for (const kind of NOTIFY_KINDS) {
|
||||
const option = el("option", null, kind.label);
|
||||
option.value = kind.id;
|
||||
kindSelect.appendChild(option);
|
||||
}
|
||||
kindSelect.value = f.notifyKind;
|
||||
kindLabel.appendChild(kindSelect);
|
||||
const kindHint = el("p", "loop-hint");
|
||||
const notifyInput = el("input", "is-compact loop-text");
|
||||
notifyInput.type = "text";
|
||||
notifyInput.inputMode = "url";
|
||||
notifyInput.id = "loop-notify-url";
|
||||
notifyInput.value = f.notifyUrl;
|
||||
notifyInput.maxLength = 2000;
|
||||
notifyInput.setAttribute("aria-label", "Web address to call");
|
||||
const paramRow = el("div");
|
||||
const paramLabel = el("label", "loop-number");
|
||||
const paramText = el("span");
|
||||
paramLabel.appendChild(paramText);
|
||||
const paramInput = el("input", "is-compact loop-text loop-param");
|
||||
paramInput.type = "text";
|
||||
paramInput.id = "loop-notify-param";
|
||||
paramInput.value = f.notifyParam;
|
||||
paramInput.placeholder = DEFAULT_NOTIFY_PARAM;
|
||||
paramInput.maxLength = 64;
|
||||
paramLabel.appendChild(paramInput);
|
||||
paramRow.appendChild(paramLabel);
|
||||
const phasesRow = toggle("loop-notify-phases", "Also tell me when each phase is complete", f.notifyPhases, (v) => {
|
||||
f.notifyPhases = v;
|
||||
});
|
||||
const notifyWarn = el("p", "loop-warn");
|
||||
const testRow = el("div", "loop-test");
|
||||
const testButton = el("button", "btn", "Send a test");
|
||||
testButton.type = "button";
|
||||
testButton.id = "loop-notify-test";
|
||||
testButton.addEventListener("click", () => sendTest(s));
|
||||
testRow.appendChild(testButton);
|
||||
const testLine = notifyTestLine();
|
||||
if (testLine) testRow.appendChild(testLine);
|
||||
const showNotify = () => {
|
||||
const kind = NOTIFY_KINDS.find((k) => k.id === f.notifyKind);
|
||||
kindSelect.value = kind.id;
|
||||
kindHint.textContent = kind.hint;
|
||||
notifyInput.placeholder = kind.placeholder;
|
||||
paramText.textContent = kind.name || "";
|
||||
paramRow.hidden = !kind.name || f.notifyUrl.trim() === "";
|
||||
phasesRow.hidden = f.notifyUrl.trim() === "";
|
||||
const problem = notifyProblem(f.notifyUrl, f.notifyParam, kind.id);
|
||||
notifyWarn.textContent = problem;
|
||||
notifyWarn.hidden = !problem;
|
||||
testButton.disabled = Boolean(problem) || f.notifyUrl.trim() === "" || Boolean(page.loopNotifyTest && page.loopNotifyTest.waiting) || s.starting;
|
||||
};
|
||||
// What a test said was about the address as it was.
|
||||
const forgetTest = () => {
|
||||
if (page.loopNotifyTest && !page.loopNotifyTest.waiting) {
|
||||
page.loopNotifyTest = null;
|
||||
testRow.querySelector("p")?.remove();
|
||||
}
|
||||
};
|
||||
notifyInput.addEventListener("input", () => {
|
||||
f.notifyUrl = notifyInput.value;
|
||||
forgetTest();
|
||||
// A pasted webhook picks its own kind, unless the person chose one here.
|
||||
const service = kindForUrl(f.notifyUrl);
|
||||
if (service && f.notifyKind === "query" && !s.notifyKindChosen) f.notifyKind = service;
|
||||
showNotify();
|
||||
});
|
||||
kindSelect.addEventListener("change", () => {
|
||||
f.notifyKind = kindSelect.value;
|
||||
forgetTest();
|
||||
s.notifyKindChosen = true;
|
||||
showNotify();
|
||||
});
|
||||
paramInput.addEventListener("input", () => {
|
||||
f.notifyParam = paramInput.value;
|
||||
forgetTest();
|
||||
showNotify();
|
||||
});
|
||||
showNotify();
|
||||
notify.append(kindLabel, notifyInput, kindHint, paramRow, phasesRow, notifyWarn, testRow);
|
||||
form.appendChild(notify);
|
||||
form.appendChild(notifyFields(s, f, { onTest: () => sendTest(s) }));
|
||||
|
||||
const check = field("Quick check", "A command the app runs after each phase, such as npm run build. The page never runs it.");
|
||||
const checkInput = el("input", "is-compact loop-text");
|
||||
@@ -844,20 +643,7 @@ function drawBody(pane, s) {
|
||||
|
||||
const retry = field("If a phase crashes or goes quiet");
|
||||
retry.appendChild(toggle("loop-retry", "Retry it once", f.retryOnce, (v) => ((f.retryOnce = v), redo())));
|
||||
const silence = el("label", "loop-number");
|
||||
silence.appendChild(el("span", null, "Count the agent as stuck after this many minutes with no activity"));
|
||||
const silenceInput = el("input", "is-compact loop-text loop-narrow");
|
||||
silenceInput.type = "number";
|
||||
silenceInput.id = "loop-silence";
|
||||
silenceInput.min = "1";
|
||||
silenceInput.max = "60";
|
||||
silenceInput.step = "1";
|
||||
silenceInput.value = String(f.silenceMinutes);
|
||||
silenceInput.addEventListener("input", () => {
|
||||
f.silenceMinutes = Number(silenceInput.value);
|
||||
});
|
||||
silence.appendChild(silenceInput);
|
||||
retry.appendChild(silence);
|
||||
retry.appendChild(silenceField(f));
|
||||
retry.appendChild(el("p", "loop-hint", "No activity means no file changes, in the project or the agent's session, so allow for your slowest build or test run. Waiting on your answer does not count."));
|
||||
form.appendChild(retry);
|
||||
|
||||
@@ -895,16 +681,6 @@ function drawBody(pane, s) {
|
||||
pane.appendChild(foot);
|
||||
}
|
||||
|
||||
/** The line beside Send a test, or null with nothing to say. */
|
||||
function notifyTestLine() {
|
||||
const test = page.loopNotifyTest;
|
||||
if (!test) return null;
|
||||
if (test.waiting) return el("p", "loop-why", "Waiting for the app's confirm...");
|
||||
if (!test.ok) return el("p", "loop-error", test.error);
|
||||
if (test.sent) return el("p", "loop-why", "Sent, and the address answered OK. Check that the message arrived.");
|
||||
return null;
|
||||
}
|
||||
|
||||
function gitButton() {
|
||||
const b = el("button", "btn", "Open the Git board");
|
||||
b.type = "button";
|
||||
@@ -915,6 +691,30 @@ function gitButton() {
|
||||
return b;
|
||||
}
|
||||
|
||||
/** "Review rounds per phase": fresh reviewer rounds after a phase's own review, off with Review. */
|
||||
function roundsField(f) {
|
||||
const box = el("label", "loop-number");
|
||||
box.appendChild(el("span", null, "Review rounds per phase"));
|
||||
const input = el("input", "is-compact loop-text loop-narrow");
|
||||
input.type = "number";
|
||||
input.id = "loop-review-rounds";
|
||||
input.min = "0";
|
||||
input.max = "6";
|
||||
input.step = "1";
|
||||
input.value = String(f.reviewRounds);
|
||||
input.disabled = !f.review;
|
||||
input.addEventListener("input", () => {
|
||||
f.reviewRounds = Number(input.value);
|
||||
});
|
||||
box.appendChild(input);
|
||||
const wrap = el("div", null);
|
||||
wrap.appendChild(box);
|
||||
wrap.appendChild(
|
||||
el("p", "loop-hint", f.review ? "When a phase's own review leaves a Critical or a Warning, fresh reviewers run up to this many more rounds before the phase is committed. 0 turns them off." : "Applies only with Review on")
|
||||
);
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/** The form as the console saves it (exported for the page tests). */
|
||||
export function setupBody(f, s) {
|
||||
const body = { ...f, quickCheck: f.quickCheck.trim(), notifyUrl: f.notifyUrl.trim(), notifyParam: f.notifyParam.trim() || DEFAULT_NOTIFY_PARAM };
|
||||
|
||||
@@ -0,0 +1,433 @@
|
||||
// Plan2Code Web Console - the Review Loop's setup screen, drawn by the page from the console's saved setup and the app's facts; defines only.
|
||||
//
|
||||
// The dashboard's Review Loop card opens this in place of the cards. Nothing
|
||||
// here runs an agent: Start saves the picks through POST /review-loop-setup,
|
||||
// then sends them to the desktop app (`review-loop-start { setup }`), which
|
||||
// confirms in its own window. Its field builders come from ../loop-parts.js, shared with
|
||||
// the Implementation Loop's screen. The notification address belongs to the
|
||||
// Implementation Loop's setup: this screen shows it and, when changed, saves it
|
||||
// there (POST /loop-setup), because the app reads it from that file alone.
|
||||
|
||||
import { el } from "../render.js";
|
||||
import { hooks, page, redraw } from "../state.js";
|
||||
import { specList } from "../selectors.js";
|
||||
import { postJson } from "../net.js";
|
||||
import { tellApp } from "../app-bridge.js";
|
||||
import { MATCH_SESSION, STRENGTH_WORDS, field, hasMapping, notifyFields, notifyProblem, radios, select, silenceField, toggle } from "../loop-parts.js";
|
||||
|
||||
const SCOPES = [
|
||||
["branch", "Branch against main, with uncommitted changes", "Everything this branch changed since it left main, plus what is not committed yet."],
|
||||
["uncommitted", "Uncommitted changes only", "Only what is changed in your working tree right now."],
|
||||
["spec", "A spec's work", "The files the chosen spec's phases built."],
|
||||
];
|
||||
|
||||
export const HANDS_OFF_LINE = "Please do not edit this project's files while rounds run: anything changed goes into the round.";
|
||||
export const REVIEWER_NOTE = "Each round's reviewer runs fresh, whatever the Subagents switch says; the switch still governs other helpers.";
|
||||
export const COMMIT_FIRST_LINE = "Commit my current changes first as Work before Review Loop";
|
||||
const CAP_HINT = "Rounds stop sooner on a clean one. You can always add a round later, one at a time, up to 6 in all.";
|
||||
|
||||
/**
|
||||
* Open the screen for `spec` (the picker's selected spec object, or null). The
|
||||
* saved setup and the read-only facts come from the console; the agent and its
|
||||
* helpers come from the app. A spec pre-fills the picker and the spec scope.
|
||||
*/
|
||||
export async function openReviewLoopSetup(spec) {
|
||||
if (page.gone || page.pendingResult || page.local.launching) return;
|
||||
const dir = spec && spec.dir ? spec.dir : "";
|
||||
page.reviewStart = null;
|
||||
page.loopNotifyTest = null;
|
||||
page.reviewLoopSetup = { spec: dir, loaded: false, failed: false, form: null, facts: null, problems: [], starting: false, resolvedFor: undefined, notifyKindChosen: false };
|
||||
tellApp("review-loop-facts");
|
||||
redraw();
|
||||
const mine = page.reviewLoopSetup;
|
||||
let res;
|
||||
try {
|
||||
res = await fetch("/review-loop-setup?facts=1" + (dir ? "&spec=" + encodeURIComponent(dir) : ""), { cache: "no-store" });
|
||||
} catch {
|
||||
res = null;
|
||||
}
|
||||
if (page.reviewLoopSetup !== mine) return;
|
||||
const answer = res && res.ok ? await res.json().catch(() => null) : null;
|
||||
if (page.reviewLoopSetup !== mine) return;
|
||||
if (!answer) {
|
||||
mine.failed = true;
|
||||
redraw();
|
||||
return;
|
||||
}
|
||||
const facts = page.reviewFacts;
|
||||
mine.form = {
|
||||
scope: ["branch", "uncommitted", "spec"].includes(answer.scope) ? answer.scope : "branch",
|
||||
spec: typeof answer.spec === "string" ? answer.spec : "",
|
||||
cap: Number.isInteger(answer.cap) ? answer.cap : 3,
|
||||
commit: answer.commit !== false,
|
||||
agreeCommit: false,
|
||||
suggestions: answer.suggestions === true,
|
||||
strength: typeof answer.strength === "string" ? answer.strength : "",
|
||||
silenceMinutes: Number.isInteger(answer.silenceMinutes) ? answer.silenceMinutes : 20,
|
||||
notifyRounds: answer.notifyRounds === true,
|
||||
notifyKind: (facts && facts.notifyKind) || "query",
|
||||
notifyUrl: (facts && facts.notifyUrl) || "",
|
||||
notifyParam: (facts && facts.notifyParam) || "message",
|
||||
};
|
||||
// The picker's spec lives in the form; the saved one only matters on the spec scope.
|
||||
if (dir) mine.form.spec = dir;
|
||||
mine.facts = { branch: typeof answer.branch === "string" ? answer.branch : "", pending: Number.isInteger(answer.pending) ? answer.pending : null, resolved: undefined };
|
||||
mine.loaded = true;
|
||||
redraw();
|
||||
}
|
||||
|
||||
const reviewAgent = () => (page.reviewFacts && typeof page.reviewFacts.agent === "string" ? page.reviewFacts.agent : "");
|
||||
|
||||
/** The facts' notify values arrive with the app's answer, which can follow the setup: take them while the fields are still as saved. */
|
||||
function adoptNotify(s) {
|
||||
const facts = page.reviewFacts;
|
||||
if (!facts || s.notifyAdopted || !s.form) return;
|
||||
s.notifyAdopted = true;
|
||||
if (!s.form.notifyUrl) s.form.notifyUrl = facts.notifyUrl || "";
|
||||
s.form.notifyKind = facts.notifyKind || s.form.notifyKind;
|
||||
s.form.notifyParam = facts.notifyParam || s.form.notifyParam;
|
||||
}
|
||||
|
||||
/** Read the agent's strengths once the app has said which agent it is (the two answers come in either order). */
|
||||
function ensureResolved(s) {
|
||||
if (!page.reviewFacts || s.resolvedFor === reviewAgent()) return;
|
||||
const agent = reviewAgent();
|
||||
s.resolvedFor = agent;
|
||||
if (!agent) {
|
||||
s.facts.resolved = null;
|
||||
return;
|
||||
}
|
||||
fetch("/review-loop-setup?agent=" + encodeURIComponent(agent), { cache: "no-store" })
|
||||
.then((res) => (res.ok ? res.json() : null))
|
||||
.catch(() => null)
|
||||
.then((answer) => {
|
||||
if (page.reviewLoopSetup !== s || s.resolvedFor !== agent) return;
|
||||
s.facts.resolved = answer && answer.resolved && typeof answer.resolved === "object" ? answer.resolved : null;
|
||||
redraw();
|
||||
});
|
||||
}
|
||||
|
||||
function close() {
|
||||
page.reviewLoopSetup = null;
|
||||
page.reviewStart = null;
|
||||
redraw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Why Start is grayed, or "" when it can go, in the spec's order. Exported for
|
||||
* the page's unit tests.
|
||||
*/
|
||||
export function reviewStartBlock(form, facts, appFacts) {
|
||||
if (!form || !facts) return "Loading the setup...";
|
||||
if (!appFacts) return "Asking the app...";
|
||||
if (appFacts.running) return "A loop is already running in this window. Stop it from the banner first.";
|
||||
if (appFacts.promptSupport === false) return "This agent cannot be started with a first prompt.";
|
||||
if (form.scope === "spec" && !form.spec) return "Pick the spec whose work to review.";
|
||||
if (form.commit && facts.pending !== null && facts.pending > 0 && !form.agreeCommit) {
|
||||
return `${facts.pending} uncommitted ${facts.pending === 1 ? "change needs" : "changes need"} your say-so: tick the box to commit ${facts.pending === 1 ? "it" : "them"} first, or turn commits off.`;
|
||||
}
|
||||
const problem = notifyProblem(form.notifyUrl, form.notifyParam, form.notifyKind);
|
||||
if (problem) return problem;
|
||||
return "";
|
||||
}
|
||||
|
||||
/** The form as the console saves it (exported for the page tests). */
|
||||
export function reviewSetupBody(f) {
|
||||
return {
|
||||
scope: f.scope,
|
||||
spec: f.scope === "spec" ? f.spec : "",
|
||||
cap: f.cap,
|
||||
commit: f.commit,
|
||||
suggestions: f.suggestions,
|
||||
strength: f.strength,
|
||||
silenceMinutes: f.silenceMinutes,
|
||||
notifyRounds: f.notifyRounds,
|
||||
};
|
||||
}
|
||||
|
||||
/** What the app is sent: the saved picks and whether the person agreed to the pre-run commit. */
|
||||
export function reviewStartMessage(f, facts) {
|
||||
const dirty = facts && facts.pending !== null && facts.pending > 0;
|
||||
return { ...reviewSetupBody(f), preRunCommitAgreed: Boolean(f.commit && dirty && f.agreeCommit) };
|
||||
}
|
||||
|
||||
function factRow(list, label, value) {
|
||||
const row = el("div", "loop-fact");
|
||||
row.appendChild(el("dt", null, label));
|
||||
row.appendChild(el("dd", null, value));
|
||||
list.appendChild(row);
|
||||
}
|
||||
|
||||
function agentLine(facts) {
|
||||
if (!facts) return "Asking the app...";
|
||||
if (!facts.agent) return "No agent is chosen yet";
|
||||
const label = facts.agentLabel || facts.agent;
|
||||
return facts.helpers ? `${label} (starts its own helpers: one session per round)` : `${label} (no helpers: a reviewer session, then a fixer session, each round)`;
|
||||
}
|
||||
|
||||
export function renderReviewLoopSetup(main) {
|
||||
const s = page.reviewLoopSetup;
|
||||
const pane = el("div", "dash-confirm loop-setup review-loop-setup");
|
||||
pane.appendChild(el("p", "card-kicker", "Step 3 · Review Loop"));
|
||||
pane.appendChild(el("h2", "dash-title", "Set up the Review Loop"));
|
||||
|
||||
if (s.failed) {
|
||||
pane.appendChild(el("p", "loop-error", "The setup could not be read. Go back and try again."));
|
||||
} else if (!s.loaded) {
|
||||
const wait = el("p", "dash-working");
|
||||
wait.append(el("span", "spinner tiny"), el("span", null, "Loading the setup..."));
|
||||
pane.appendChild(wait);
|
||||
} else {
|
||||
drawBody(pane, s);
|
||||
}
|
||||
|
||||
const actions = el("div", "confirm-actions");
|
||||
const back = el("button", "btn ghost", "Back");
|
||||
back.type = "button";
|
||||
back.addEventListener("click", close);
|
||||
actions.appendChild(back);
|
||||
const help = el("button", "linky loop-help", "How the loop works");
|
||||
help.type = "button";
|
||||
help.addEventListener("click", () => hooks.openHelpOn("loop"));
|
||||
actions.appendChild(help);
|
||||
pane.appendChild(actions);
|
||||
main.appendChild(pane);
|
||||
}
|
||||
|
||||
/** One strength for every round: Match my session, or a mapped word. Grayed when this agent maps none. */
|
||||
function strengthPick(s) {
|
||||
const f = s.form;
|
||||
const resolved = s.facts.resolved;
|
||||
const appFacts = page.reviewFacts;
|
||||
const box = field("Strength");
|
||||
const loading = !appFacts || resolved === undefined;
|
||||
const none = !loading && (appFacts.strengthsMapped === false || !hasMapping(resolved));
|
||||
if (none) {
|
||||
const gray = el("p", "loop-hint loop-strength-none");
|
||||
gray.append("This agent has no strengths mapped yet. ");
|
||||
const link = el("button", "linky", "Map them in Agents & models");
|
||||
link.type = "button";
|
||||
link.addEventListener("click", () => hooks.openPrefs("agents"));
|
||||
gray.appendChild(link);
|
||||
box.appendChild(gray);
|
||||
return box;
|
||||
}
|
||||
if (loading) {
|
||||
box.appendChild(el("p", "loop-hint", "Asking the app which agent this loop uses..."));
|
||||
return box;
|
||||
}
|
||||
const options = [["", MATCH_SESSION], ...STRENGTH_WORDS.map(([word, label]) => [word, resolved[word] ? label : label + " (not mapped)", !resolved[word]])];
|
||||
if (f.strength && !resolved[f.strength]) f.strength = "";
|
||||
box.appendChild(
|
||||
select("review-loop-strength", "Strength for every round", options, f.strength, (v) => {
|
||||
f.strength = v;
|
||||
s.problems = [];
|
||||
redraw();
|
||||
})
|
||||
);
|
||||
const row = f.strength ? resolved[f.strength] : null;
|
||||
box.appendChild(el("p", "loop-hint", row ? [row.model, row.effort].filter(Boolean).join(", ") : "Rounds use the model and effort this window started with."));
|
||||
return box;
|
||||
}
|
||||
|
||||
function specPicker(s) {
|
||||
const f = s.form;
|
||||
const specs = specList();
|
||||
const wrap = el("div", "loop-spec-pick");
|
||||
const options = [["", "Choose a spec..."]];
|
||||
for (const sp of specs) options.push([sp.dir, sp.dir]);
|
||||
// A spec the list does not hold (one picked on the dashboard that has since moved) stays visible.
|
||||
if (f.spec && !specs.some((sp) => sp.dir === f.spec)) options.push([f.spec, f.spec]);
|
||||
wrap.appendChild(
|
||||
select("review-loop-spec", "Spec to review", options, f.spec, (v) => {
|
||||
f.spec = v;
|
||||
s.problems = [];
|
||||
redraw();
|
||||
})
|
||||
);
|
||||
return wrap;
|
||||
}
|
||||
|
||||
function drawBody(pane, s) {
|
||||
const f = s.form;
|
||||
adoptNotify(s);
|
||||
ensureResolved(s);
|
||||
const appFacts = page.reviewFacts;
|
||||
const redo = () => {
|
||||
s.problems = [];
|
||||
redraw();
|
||||
};
|
||||
|
||||
const lines = el("div", "loop-lines");
|
||||
for (const text of [
|
||||
"The app reviews your change in rounds, each in a fresh agent session. Round 1 looks at everything in scope; each later round looks only at what the round before it changed.",
|
||||
"It stops on a clean round, at the round cap, or when you press a stop button on the banner at the top of the window. It never pushes.",
|
||||
]) {
|
||||
lines.appendChild(el("p", "loop-line", text));
|
||||
}
|
||||
lines.appendChild(el("p", "loop-line loop-hands-off", HANDS_OFF_LINE));
|
||||
pane.appendChild(lines);
|
||||
|
||||
const facts = el("dl", "loop-facts");
|
||||
factRow(facts, "Agent", agentLine(appFacts));
|
||||
factRow(facts, "Branch", s.facts.branch || "unknown");
|
||||
factRow(facts, "Uncommitted changes", s.facts.pending === null ? "unknown" : String(s.facts.pending));
|
||||
pane.appendChild(facts);
|
||||
|
||||
const form = el("div", "loop-form");
|
||||
|
||||
const scope = field("What to review");
|
||||
scope.appendChild(radios("reviewscope", SCOPES, f.scope, (v) => ((f.scope = v), redo())));
|
||||
if (f.scope === "spec") scope.appendChild(specPicker(s));
|
||||
form.appendChild(scope);
|
||||
|
||||
const cap = field("Round cap", CAP_HINT);
|
||||
const capLabel = el("label", "loop-number");
|
||||
capLabel.appendChild(el("span", null, "Stop after this many rounds (1 to 6)"));
|
||||
const capInput = el("input", "is-compact loop-text loop-narrow");
|
||||
capInput.type = "number";
|
||||
capInput.id = "review-loop-cap";
|
||||
capInput.min = "1";
|
||||
capInput.max = "6";
|
||||
capInput.step = "1";
|
||||
capInput.value = String(f.cap);
|
||||
capInput.addEventListener("input", () => {
|
||||
f.cap = Number(capInput.value);
|
||||
});
|
||||
capLabel.appendChild(capInput);
|
||||
cap.appendChild(capLabel);
|
||||
form.appendChild(cap);
|
||||
|
||||
const commit = field("Commit");
|
||||
commit.appendChild(toggle("review-loop-commit", "Commit each round to the current branch", f.commit, (v) => ((f.commit = v), redo())));
|
||||
if (f.commit && s.facts.pending !== null && s.facts.pending > 0) {
|
||||
commit.appendChild(toggle("review-loop-agree", COMMIT_FIRST_LINE, f.agreeCommit, (v) => ((f.agreeCommit = v), redo())));
|
||||
}
|
||||
form.appendChild(commit);
|
||||
|
||||
const sugg = field("Suggestions");
|
||||
sugg.appendChild(toggle("review-loop-suggestions", "Apply Suggestions on their own", f.suggestions, (v) => ((f.suggestions = v), redo())));
|
||||
sugg.appendChild(el("p", "loop-hint", "Off: Suggestions are listed in the report for you to pick. On: they are applied in one last pass."));
|
||||
form.appendChild(sugg);
|
||||
|
||||
form.appendChild(strengthPick(s));
|
||||
|
||||
const reviewer = field("Reviewers");
|
||||
reviewer.appendChild(el("p", "loop-hint loop-reviewer-note", REVIEWER_NOTE));
|
||||
form.appendChild(reviewer);
|
||||
|
||||
const retry = field("If a round goes quiet");
|
||||
retry.appendChild(silenceField(f, "Count the agent as stuck after this many minutes with no activity"));
|
||||
retry.appendChild(el("p", "loop-hint", "No activity means no file changes, in the project or the agent's session, so allow for your slowest test run. A stuck round is retried once."));
|
||||
form.appendChild(retry);
|
||||
|
||||
form.appendChild(
|
||||
notifyFields(s, f, {
|
||||
intro: "When the Review Loop needs you or ends, except when you stop it yourself, the app sends a short message naming the round. The address is the Implementation Loop's: changing it here changes it there. Leave it empty to send nothing.",
|
||||
phasesId: "review-loop-notify-rounds",
|
||||
phasesKey: "notifyRounds",
|
||||
phasesText: "Also tell me when each round finishes",
|
||||
onTest: () => sendTest(s),
|
||||
})
|
||||
);
|
||||
pane.appendChild(form);
|
||||
|
||||
const block = reviewStartBlock(f, s.facts, appFacts);
|
||||
const gated = Boolean(block);
|
||||
const foot = el("div", "loop-start");
|
||||
if (gated) {
|
||||
const why = el("p", "loop-why", block);
|
||||
why.setAttribute("role", "status");
|
||||
foot.appendChild(why);
|
||||
}
|
||||
if (s.problems.length) {
|
||||
const bad = el("ul", "loop-problems");
|
||||
for (const p of s.problems) bad.appendChild(el("li", null, p));
|
||||
foot.appendChild(bad);
|
||||
}
|
||||
const waiting = s.starting && !page.reviewStart;
|
||||
if (waiting) foot.appendChild(el("p", "loop-why", "Waiting for the app's confirm..."));
|
||||
if (page.reviewStart && !page.reviewStart.ok) foot.appendChild(el("p", "loop-error", page.reviewStart.error));
|
||||
if (page.reviewStart && page.reviewStart.ok) foot.appendChild(el("p", "loop-why", "The Review Loop is starting..."));
|
||||
const start = el("button", "btn primary", "Start the Review Loop");
|
||||
start.type = "button";
|
||||
start.id = "review-loop-start";
|
||||
start.disabled = gated || waiting || page.gone || page.pendingResult || Boolean(page.reviewStart && page.reviewStart.ok);
|
||||
start.addEventListener("click", () => startReviewLoop(s));
|
||||
foot.appendChild(start);
|
||||
pane.appendChild(foot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the notification fields into the Implementation Loop's setup, the only
|
||||
* place the app reads them from. A project with no loop setup yet gets the
|
||||
* loop's defaults beside the new address. Resolves to a problem line or "".
|
||||
*/
|
||||
async function saveNotify(s) {
|
||||
const f = s.form;
|
||||
const facts = page.reviewFacts || {};
|
||||
const url = f.notifyUrl.trim();
|
||||
const param = f.notifyParam.trim() || "message";
|
||||
if (url === (facts.notifyUrl || "") && f.notifyKind === (facts.notifyKind || "query") && param === (facts.notifyParam || "message")) return "";
|
||||
let current = null;
|
||||
try {
|
||||
const res = await fetch("/loop-setup", { cache: "no-store" });
|
||||
current = res.ok ? await res.json() : null;
|
||||
} catch {
|
||||
current = null;
|
||||
}
|
||||
if (!current) return "The notification address could not be saved. Try again.";
|
||||
// The loop's own screen drops these two before it saves; the store rejects them as unknown fields.
|
||||
const { remembered, saved, ...entry } = current;
|
||||
const { status, body } = await postJson("/loop-setup", { ...entry, notifyKind: f.notifyKind, notifyUrl: url, notifyParam: param });
|
||||
if (status !== 200 || !body || body.ok !== true) {
|
||||
return Array.isArray(body && body.problems) && body.problems.length ? body.problems.join(" ") : "The notification address could not be saved. Try again.";
|
||||
}
|
||||
// What the app now reads, so a second Start does not save it again.
|
||||
if (page.reviewFacts) page.reviewFacts = { ...page.reviewFacts, notifyKind: f.notifyKind, notifyUrl: url, notifyParam: param };
|
||||
return "";
|
||||
}
|
||||
|
||||
async function sendTest(s) {
|
||||
const f = s.form;
|
||||
if (!f.notifyUrl.trim() || notifyProblem(f.notifyUrl, f.notifyParam, f.notifyKind) || (page.loopNotifyTest && page.loopNotifyTest.waiting)) return;
|
||||
s.problems = [];
|
||||
page.loopNotifyTest = { waiting: true };
|
||||
redraw();
|
||||
const problem = await saveNotify(s);
|
||||
if (page.reviewLoopSetup !== s) return;
|
||||
if (problem) {
|
||||
page.loopNotifyTest = null;
|
||||
s.problems = [problem];
|
||||
redraw();
|
||||
return;
|
||||
}
|
||||
tellApp("loop-notify-test");
|
||||
}
|
||||
|
||||
async function startReviewLoop(s) {
|
||||
const f = s.form;
|
||||
if (reviewStartBlock(f, s.facts, page.reviewFacts) || (s.starting && !page.reviewStart)) return;
|
||||
s.problems = [];
|
||||
page.reviewStart = null;
|
||||
s.starting = true;
|
||||
redraw();
|
||||
const problem = await saveNotify(s);
|
||||
if (page.reviewLoopSetup !== s) return;
|
||||
if (problem) {
|
||||
s.starting = false;
|
||||
s.problems = [problem];
|
||||
redraw();
|
||||
return;
|
||||
}
|
||||
const { status, body } = await postJson("/review-loop-setup", reviewSetupBody(f));
|
||||
if (page.reviewLoopSetup !== s) return;
|
||||
if (status !== 200 || !body || body.ok !== true) {
|
||||
s.starting = false;
|
||||
s.problems = Array.isArray(body && body.problems) && body.problems.length ? body.problems : ["The setup could not be saved. Try again."];
|
||||
redraw();
|
||||
return;
|
||||
}
|
||||
tellApp("review-loop-start", { setup: reviewStartMessage(f, s.facts) });
|
||||
redraw();
|
||||
}
|
||||
@@ -42,10 +42,10 @@
|
||||
// card the dashboard card (group, chip, title, blurb, about, and
|
||||
// `spec: true` when it takes the picked spec), or null; an
|
||||
// optional `help` is Help's line for the card when it differs
|
||||
// from `blurb`, and `icon` names the `ci-*` symbol in
|
||||
// from `blurb`, `appNote` is a line only the desktop app shows (card and Help), and `icon` names the `ci-*` symbol in
|
||||
// index.html's card-icons sheet drawn before the title
|
||||
// appOnly the entry is a card the desktop app alone offers (the
|
||||
// Implementation Loop): no workflow, no installed skill, and no
|
||||
// Implementation Loop and the Review Loop): no workflow, no installed skill, and no
|
||||
// list derived from the workflows (WORKFLOWS, the meter, the
|
||||
// resume command, Help's card list) holds it. `skill` is an id
|
||||
// only; `workflow` is null. Use FLOW_SKILLS for those lists.
|
||||
@@ -283,6 +283,32 @@ export const SKILLS = Object.freeze([
|
||||
"Builds every remaining phase of the spec without you at the keyboard. Each phase gets a fresh agent that builds it and reviews it. The app checks the result against the spec, runs your quick check, commits, and moves on. It stops at the first phase that goes wrong and tells you why. Desktop app only.",
|
||||
},
|
||||
}),
|
||||
// The desktop app's Review Loop, a second app-only card beside the
|
||||
// Implementation Loop: it runs review and fix rounds over a finished change,
|
||||
// each round checked by a fresh reviewer. Any project state lights it; the
|
||||
// setup screen picks the scope.
|
||||
skill({
|
||||
skill: "plan2code-review-loop",
|
||||
workflow: null,
|
||||
appOnly: true,
|
||||
label: "Review Loop",
|
||||
name: "Review Loop",
|
||||
pose: null,
|
||||
builds: false, phased: false, metered: false, templates: false,
|
||||
weight: null, started: null, ran: null, resume: null,
|
||||
subagents: null,
|
||||
states: "any",
|
||||
greyed: null,
|
||||
card: {
|
||||
group: "pipeline",
|
||||
chip: "Step 3",
|
||||
title: "Review Loop",
|
||||
icon: "loop",
|
||||
blurb: "Review and fix in rounds on its own, each round checked by a fresh reviewer.",
|
||||
about:
|
||||
"Reviews a finished change and fixes what it finds, round after round, without you at the keyboard. The first round reviews everything in scope; each later round reviews only what the last round changed, with a reviewer that never saw the fix being written. It stops on a clean round, at the round cap, or when you say so, then hands back one report and the usual sign-off. Desktop app only.",
|
||||
},
|
||||
}),
|
||||
skill({
|
||||
skill: "plan2code-4-finalize",
|
||||
workflow: "finalize",
|
||||
@@ -343,6 +369,7 @@ export const SKILLS = Object.freeze([
|
||||
title: "Review",
|
||||
icon: "review",
|
||||
blurb: "A second opinion on the changes. Problems ranked, and you pick what gets fixed.",
|
||||
appNote: "In the app, the Review Loop runs review and fix rounds on its own.",
|
||||
about:
|
||||
"A fresh-eyes pass over what changed: bugs, gaps, and the things the builder was too close to see. Problems come back ranked with a suggestion each, you pick which ones get fixed, and it fixes them.",
|
||||
},
|
||||
|
||||
@@ -130,6 +130,14 @@ export const page = {
|
||||
// The setup screen the dashboard's Implementation Loop card opened, or null
|
||||
// (screens/loop-setup.js owns the shape).
|
||||
loopSetup: null,
|
||||
// The Review Loop's setup screen (screens/review-loop-setup.js owns the shape), what
|
||||
// the app answered to `review-loop-facts`, and `{ ok, error }` once it answered a
|
||||
// `review-loop-start`.
|
||||
reviewLoopSetup: null,
|
||||
reviewFacts: null,
|
||||
reviewStart: null,
|
||||
// `{ kind, ok, error }` once the app answered a press on the Review Loop's end screen.
|
||||
reviewAction: null,
|
||||
loopFacts: null,
|
||||
loopStart: null,
|
||||
loopNotifyTest: null,
|
||||
|
||||
@@ -666,4 +666,13 @@
|
||||
.loop-end-details { display: grid; gap: 10px; }
|
||||
.loop-end-details > summary { cursor: pointer; font-size: var(--fs-md); color: var(--ink-2); }
|
||||
.loop-end-details[open] > summary { margin-bottom: 8px; }
|
||||
/* The Review Loop's end: the partial diff, the Suggestions pick and the finished screen. */
|
||||
.review-end-partial { display: grid; gap: 10px; }
|
||||
.review-end-partial h3 { margin: 0; }
|
||||
.review-end-stats { margin: 0; }
|
||||
.review-end-diff { max-height: 420px; overflow: auto; border: 1px solid var(--rule); border-radius: 8px; }
|
||||
.review-end-suggestions { display: grid; gap: 6px; }
|
||||
.review-end-pick span { display: grid; gap: 2px; }
|
||||
.review-end-where { font-family: var(--mono); font-size: var(--fs-xs); color: var(--ink-2); overflow-wrap: anywhere; }
|
||||
.review-end-note { margin: 0; }
|
||||
.confirm-note > .confirm-note-retry { justify-self: start; }
|
||||
@@ -0,0 +1,96 @@
|
||||
// Plan2Code Web Console - the Review Loop's setup, remembered per project.
|
||||
|
||||
import path from "node:path";
|
||||
|
||||
import { ensureDir, HOME_DIR, readJson, withStateLock, writeJsonAtomic } from "./files.mjs";
|
||||
import { foldKey } from "./workspace.mjs";
|
||||
|
||||
// One file for the person, beside loop-setup.json, keyed by the folder a
|
||||
// session runs in (FR-29: its own entry per project):
|
||||
//
|
||||
// { "schema": 1, "projects": { "<folded worktree>": { ...setup, "saved": "<iso>" } } }
|
||||
//
|
||||
// Never under specs/: the server never writes into a project. The notify
|
||||
// address and kind are not kept here: the Review Loop reads them from the
|
||||
// Implementation Loop's setup (FR-26).
|
||||
export const REVIEW_LOOP_SETUP_FILE = path.join(HOME_DIR, "review-loop-setup.json");
|
||||
export const REVIEW_LOOP_SETUP_LOCK = "review-loop-setup.json.lock";
|
||||
|
||||
const SCOPES = ["branch", "uncommitted", "spec"];
|
||||
const STRENGTH_WORDS = ["", "thrifty", "balanced", "best"];
|
||||
// A spec folder directly under specs/, no leading dot (the route's own rule).
|
||||
const SPEC_KEY = /^specs\/[^/\\.][^/\\]*$/;
|
||||
|
||||
export const REVIEW_LOOP_DEFAULTS = Object.freeze({
|
||||
scope: "branch",
|
||||
spec: "",
|
||||
cap: 3,
|
||||
commit: true,
|
||||
suggestions: false,
|
||||
strength: "",
|
||||
silenceMinutes: 20,
|
||||
notifyRounds: false,
|
||||
});
|
||||
|
||||
/** Problems with a setup entry, as sentences naming the field; empty when it is good. */
|
||||
export function reviewLoopSetupProblems(entry) {
|
||||
if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return ["the setup must be an object"];
|
||||
const problems = [];
|
||||
for (const key of Object.keys(entry)) {
|
||||
if (!Object.hasOwn(REVIEW_LOOP_DEFAULTS, key)) problems.push(`"${key}" is not a setup field`);
|
||||
}
|
||||
if (!SCOPES.includes(entry.scope)) problems.push(`"scope" must be one of ${SCOPES.join(", ")}`);
|
||||
if (typeof entry.spec !== "string" || (entry.spec !== "" && !SPEC_KEY.test(entry.spec))) {
|
||||
problems.push('"spec" must be empty or a folder directly under specs/');
|
||||
}
|
||||
if (!Number.isInteger(entry.cap) || entry.cap < 1 || entry.cap > 6) problems.push('"cap" must be a whole number from 1 to 6');
|
||||
for (const key of ["commit", "suggestions", "notifyRounds"]) {
|
||||
if (typeof entry[key] !== "boolean") problems.push(`"${key}" must be true or false`);
|
||||
}
|
||||
if (!STRENGTH_WORDS.includes(entry.strength)) problems.push('"strength" must be empty, thrifty, balanced or best');
|
||||
if (!Number.isInteger(entry.silenceMinutes) || entry.silenceMinutes < 1 || entry.silenceMinutes > 60) {
|
||||
problems.push('"silenceMinutes" must be a whole number from 1 to 60');
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
function readStore() {
|
||||
const saved = readJson(REVIEW_LOOP_SETUP_FILE, null);
|
||||
const ok = saved && saved.schema === 1 && saved.projects && typeof saved.projects === "object" && !Array.isArray(saved.projects);
|
||||
return ok ? saved : { schema: 1, projects: {} };
|
||||
}
|
||||
|
||||
/**
|
||||
* The setup for this project: the saved entry over the defaults, or the
|
||||
* defaults alone. `remembered` says which, so the screen can tell a first
|
||||
* visit from a returning one. A missing, unreadable or foreign-schema file
|
||||
* reads as empty.
|
||||
*/
|
||||
export function readReviewLoopSetup(project) {
|
||||
const saved = readStore().projects[foldKey(project)];
|
||||
if (saved && typeof saved === "object") return { ...REVIEW_LOOP_DEFAULTS, ...saved, remembered: true };
|
||||
return { ...REVIEW_LOOP_DEFAULTS, remembered: false };
|
||||
}
|
||||
|
||||
/** Validate and save this project's setup; throws an Error listing the problems. */
|
||||
export function saveReviewLoopSetup(project, entry) {
|
||||
const problems = reviewLoopSetupProblems(entry);
|
||||
if (problems.length) {
|
||||
const err = new Error(`the review loop setup is not valid: ${problems.join("; ")}`);
|
||||
err.problems = problems;
|
||||
throw err;
|
||||
}
|
||||
ensureDir(path.dirname(REVIEW_LOOP_SETUP_FILE));
|
||||
return withStateLock(
|
||||
path.dirname(REVIEW_LOOP_SETUP_FILE),
|
||||
() => {
|
||||
const store = readStore();
|
||||
// Only the known fields are kept, in the defaults' order.
|
||||
const known = Object.fromEntries(Object.keys(REVIEW_LOOP_DEFAULTS).map((key) => [key, entry[key]]));
|
||||
store.projects[foldKey(project)] = { ...known, saved: new Date().toISOString() };
|
||||
writeJsonAtomic(REVIEW_LOOP_SETUP_FILE, { schema: 1, projects: store.projects });
|
||||
return readReviewLoopSetup(project);
|
||||
},
|
||||
REVIEW_LOOP_SETUP_LOCK,
|
||||
);
|
||||
}
|
||||
@@ -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 { readReviewLoopSetup, saveReviewLoopSetup } from "./review-loop-setup.mjs";
|
||||
import { takeSpecCarry } from "./spec-carry.mjs";
|
||||
import { resolveStrengths } from "./strengths.mjs";
|
||||
import { MARKERS, phaseChecklist } from "./spec-files.mjs";
|
||||
@@ -136,6 +137,8 @@ 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: "/review-loop-setup", method: "GET", run: reviewLoopSetupGet },
|
||||
{ path: "/review-loop-setup", method: "POST", origin: true, run: reviewLoopSetupPost },
|
||||
{ path: "/spec-carry", method: "POST", origin: true, run: specCarry },
|
||||
{ path: "/cancel", method: "POST", origin: true, run: cancel },
|
||||
{ path: "/ping", method: "POST", run: ping },
|
||||
@@ -1878,6 +1881,41 @@ function loopSetupPost(req, res, ctx) {
|
||||
});
|
||||
}
|
||||
|
||||
// The Review Loop's setup for this project (review-loop-setup.mjs). `?spec=`
|
||||
// puts the spec and the spec scope into the answer without saving anything.
|
||||
// `?facts=1` adds the read-only facts the screen shows (the branch and the count
|
||||
// of uncommitted files, as the loop's setup reads them); `?agent=<id>` adds that
|
||||
// agent's resolved strengths. Neither is saved.
|
||||
function reviewLoopSetupGet(req, res, ctx, url) {
|
||||
let answer = readReviewLoopSetup(loopProject(ctx));
|
||||
const spec = url && url.searchParams.get("spec");
|
||||
if (spec !== null && spec !== undefined) {
|
||||
if (!/^specs\/[^/\\]+$/.test(spec) || /^specs\/\./.test(spec)) return json(res, 400, { error: "spec must be a folder directly under specs/" });
|
||||
answer = { ...answer, spec, scope: "spec" };
|
||||
}
|
||||
if (url && url.searchParams.get("facts") === "1") {
|
||||
const state = ctx.readState() || {};
|
||||
const pending = state.scan && Number.isInteger(state.scan.pending) ? state.scan.pending : null;
|
||||
answer = { ...answer, branch: state.branch || "", pending };
|
||||
}
|
||||
const agent = url && url.searchParams.get("agent");
|
||||
if (agent) answer = { ...answer, resolved: resolvedStrengthsFor(agent) };
|
||||
return json(res, 200, answer);
|
||||
}
|
||||
|
||||
function reviewLoopSetupPost(req, res, ctx) {
|
||||
return readBody(req, res, (err, body) => {
|
||||
if (err && err.tooBig) return json(res, 413, { error: "too large" });
|
||||
if (err || !body || typeof body !== "object" || Array.isArray(body)) return json(res, 400, { ok: false, problems: ["the setup must be a JSON object"] });
|
||||
try {
|
||||
return json(res, 200, { ok: true, setup: saveReviewLoopSetup(loopProject(ctx), body) });
|
||||
} catch (e) {
|
||||
if (Array.isArray(e.problems)) return json(res, 400, { ok: false, problems: e.problems });
|
||||
return json(res, 500, { error: String(e.message) });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
||||
@@ -306,6 +306,7 @@ export const PROTECTED_CONSOLE_FILES = new Set([
|
||||
"workspaces.json",
|
||||
"loop-setup.json",
|
||||
"loop-reports.json",
|
||||
"review-loop-setup.json",
|
||||
"spec-carry.json",
|
||||
"subagents.json",
|
||||
"pr-hosts.json",
|
||||
|
||||
@@ -36,6 +36,8 @@ export const SERVABLE = new Set([
|
||||
"uploads.js",
|
||||
"sound.js",
|
||||
"looks.js",
|
||||
"loop-parts.js",
|
||||
"review-loop-end.js",
|
||||
"selectors.js",
|
||||
"strengths.js",
|
||||
"app.css",
|
||||
@@ -84,6 +86,7 @@ export const SERVABLE = new Set([
|
||||
"screens/core.js",
|
||||
"screens/ending.js",
|
||||
"screens/loop-setup.js",
|
||||
"screens/review-loop-setup.js",
|
||||
"screens/docs.js",
|
||||
"screens/cards.js",
|
||||
"screens/starting.js",
|
||||
|
||||
Reference in new issue
Block a user