Add Ask for suggestions chip, thread tag, stale-pick pruning and agent line
AI Assisted
No files matched your search
|
Before Width: | Height: | Size: 110 KiB After Width: | Height: | Size: 119 KiB |
|
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 122 KiB |
|
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 95 KiB |
|
Before Width: | Height: | Size: 109 KiB After Width: | Height: | Size: 113 KiB |
|
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 123 KiB |
|
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 117 KiB |
|
Before Width: | Height: | Size: 122 KiB After Width: | Height: | Size: 122 KiB |
|
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 109 KiB |
|
Before Width: | Height: | Size: 117 KiB After Width: | Height: | Size: 119 KiB |
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 105 KiB |
@@ -1,6 +1,6 @@
|
||||
// Page tests for the Ask tab: a Quick question and the agent's reply, the
|
||||
// starters, a retry after a failed send, a new conversation, a picture attached
|
||||
// to a note, and the Subagents tab. Run with:
|
||||
// to a note, the Subagents tab, and the Ask for suggestions chip. Run with:
|
||||
// node --test scripts/test-web-console-page-ask.mjs
|
||||
//
|
||||
// Each test drives the real console in a real Chrome or Edge through
|
||||
@@ -323,3 +323,167 @@ test("the Subagents tab shows a reported helper's strength line and none for a h
|
||||
assert.equal(await badges.first().locator(".sa-bars i.on").count(), 2);
|
||||
assert.equal(await rows.filter({ hasText: "Check the tests" }).locator(".sa-strength").count(), 0);
|
||||
});
|
||||
|
||||
// Ask for suggestions: the chip in the Notes on this panel.
|
||||
|
||||
const opt = (k, text) => ({ k, text, detail: `The ${text.toLowerCase()} option.` });
|
||||
|
||||
// The page's own staged answers, from the module app.js loaded.
|
||||
const stagedOn = (s) =>
|
||||
s.page.evaluate(async () => {
|
||||
const { page } = await import("/state.js");
|
||||
return page.local.staged;
|
||||
});
|
||||
|
||||
// Opens a question from the sidebar and waits for its card.
|
||||
async function goTo(s, id, title) {
|
||||
await s.page.locator("#sidebar").getByRole("button", { name: new RegExp(title) }).click();
|
||||
await itemCard(s.page, id).waitFor();
|
||||
await s.page.waitForFunction((want) => document.getElementById("aside").dataset.item === want, id);
|
||||
}
|
||||
|
||||
const chipOf = (s) => s.page.locator("#aside").getByRole("button", { name: "Ask Plan2Code for suggestions on this question" });
|
||||
|
||||
// What a person sees break: the chip on a card where there is nothing to pick,
|
||||
// on a settled record, or missing where they are unsure what to pick.
|
||||
test("the Ask for suggestions chip shows on open choice, multi and confirm cards only", async (t) => {
|
||||
const s = await openSession(await suite.browser(), {
|
||||
t,
|
||||
workflow: "plan",
|
||||
payload: {
|
||||
items: [
|
||||
{ id: "c1", kind: "choice", title: "Export format", body: "Which format?", options: [opt("A", "CSV"), opt("B", "JSON")] },
|
||||
{ id: "m1", kind: "multi", title: "Columns", body: "Which?", options: [opt("1", "Date"), opt("2", "User")] },
|
||||
{ id: "y1", kind: "confirm", title: "Keep going", body: "Carry on?" },
|
||||
{ id: "t1", kind: "text", title: "What to call it", body: "A name.", required: false },
|
||||
{ id: "d1", kind: "choice", title: "Old pick", body: "Which?", options: [opt("A", "CSV"), opt("B", "JSON")], status: "answered", answer: { k: "B" } },
|
||||
],
|
||||
agent: { status: "waiting" },
|
||||
},
|
||||
});
|
||||
for (const [id, title, shown] of [["c1", "Export format", 1], ["m1", "Columns", 1], ["y1", "Keep going", 1], ["t1", "What to call it", 0], ["d1", "Old pick", 0]]) {
|
||||
await goTo(s, id, title);
|
||||
assert.equal(await chipOf(s).count(), shown, `chip on ${id}`);
|
||||
if (shown) assert.equal(await textOf(chipOf(s)), "Ask for suggestions");
|
||||
}
|
||||
});
|
||||
|
||||
// What a person sees break: asking for suggestions sends or clears picks they
|
||||
// staged, locks the card, or keeps the note they typed in the box.
|
||||
test("Ask for suggestions sends one flagged note and leaves every staged pick staged", async (t) => {
|
||||
const s = await openSession(await suite.browser(), {
|
||||
t,
|
||||
workflow: "plan",
|
||||
payload: {
|
||||
items: [
|
||||
{ id: "c1", kind: "choice", title: "Export format", body: "Which format?", options: [opt("A", "CSV"), opt("B", "JSON")] },
|
||||
{ id: "c2", kind: "choice", title: "Where it goes", body: "Where?", options: [opt("A", "Email"), opt("B", "Slack")] },
|
||||
],
|
||||
agent: { status: "waiting" },
|
||||
},
|
||||
});
|
||||
await goTo(s, "c2", "Where it goes");
|
||||
await itemCard(s.page, "c2").getByLabel("Slack").check();
|
||||
await goTo(s, "c1", "Export format");
|
||||
await itemCard(s.page, "c1").getByLabel("JSON").check();
|
||||
await s.page.waitForFunction(async () => {
|
||||
const { page } = await import("/state.js");
|
||||
return page.local.staged.c1 && page.local.staged.c2;
|
||||
});
|
||||
await fillBox(s.page.locator("#thread-c1"), "I lean B");
|
||||
await chipOf(s).click();
|
||||
|
||||
const got = collect(s);
|
||||
assert.equal(got.actions.length, 1, `one action: ${JSON.stringify(got.actions)}`);
|
||||
const [action] = got.actions;
|
||||
assert.equal(action.i, "c1");
|
||||
assert.equal(action.type, "comment");
|
||||
assert.equal(action.suggest, true);
|
||||
assert.equal(action.text, "I lean B");
|
||||
assert.ok(got.reply.startsWith("Suggestions wanted on Export format: I lean B"), got.reply);
|
||||
|
||||
await s.page.waitForFunction(() => document.getElementById("suggest-c1")?.disabled);
|
||||
const staged = await stagedOn(s);
|
||||
assert.equal(staged.c1 && staged.c1.k, "B", "the pick on this card is still staged");
|
||||
assert.equal(staged.c2 && staged.c2.k, "B", "the pick on the other card is still staged");
|
||||
const card = itemCard(s.page, "c1");
|
||||
assert.match(await textOf(card), /Ready to send/i);
|
||||
assert.equal(await card.getByLabel("CSV").isEnabled(), true, "the card is still a live form");
|
||||
assert.equal(await boxValue(s.page.locator("#thread-c1")), "");
|
||||
await goTo(s, "c2", "Where it goes");
|
||||
assert.match(await textOf(itemCard(s.page, "c2")), /Ready to send/i);
|
||||
});
|
||||
|
||||
// What a person sees break: a request for suggestions that vanishes with no
|
||||
// sign it went, or a chip that never comes back once the agent has answered.
|
||||
test("a request for suggestions shows tagged and waiting, and the chip comes back once the agent replies", async (t) => {
|
||||
const s = await openSession(await suite.browser(), {
|
||||
t,
|
||||
workflow: "plan",
|
||||
payload: {
|
||||
items: [{ id: "c1", kind: "choice", title: "Export format", body: "Which format?", options: [opt("A", "CSV"), opt("B", "JSON")] }],
|
||||
agent: { status: "waiting" },
|
||||
},
|
||||
});
|
||||
await itemCard(s.page, "c1").waitFor();
|
||||
await chipOf(s).click();
|
||||
const got = collect(s);
|
||||
assert.ok(got.reply.startsWith("Suggestions wanted on Export format: (no note)"), got.reply);
|
||||
|
||||
const mine = s.page.locator("#aside .msg.you.pending");
|
||||
await mine.locator(".suggest-tag", { hasText: "Asked for suggestions" }).waitFor();
|
||||
assert.match(await textOf(mine), /Sent, waiting for Plan2Code/i);
|
||||
await s.page.waitForFunction(() => document.getElementById("suggest-c1")?.disabled);
|
||||
|
||||
s.post({ items: [{ id: "c1", thread: [{ who: "agent", text: "I would pick JSON: your scripts read it directly." }] }], agent: { status: "waiting" } });
|
||||
await s.page.locator("#aside .msg", { hasText: "I would pick JSON" }).waitFor();
|
||||
await s.page.waitForFunction(() => document.getElementById("suggest-c1") && !document.getElementById("suggest-c1").disabled);
|
||||
assert.equal(await s.page.locator("#aside .msg.you .suggest-tag").count(), 1, "the request keeps its tag once answered");
|
||||
});
|
||||
|
||||
// What a person sees break: a pick on an option the agent took away still
|
||||
// staged and sent, or the other picks on the card cleared with it.
|
||||
test("a re-post that removes a staged multi option clears only that pick and says so", async (t) => {
|
||||
const s = await openSession(await suite.browser(), {
|
||||
t,
|
||||
workflow: "plan",
|
||||
payload: {
|
||||
items: [{ id: "m1", kind: "multi", title: "Columns", body: "Which?", options: [opt("1", "Date"), opt("2", "User"), opt("3", "Action")] }],
|
||||
agent: { status: "waiting" },
|
||||
},
|
||||
});
|
||||
const card = itemCard(s.page, "m1");
|
||||
await card.getByLabel("Date").check();
|
||||
await card.getByLabel("Action").check();
|
||||
await s.page.waitForFunction(async () => {
|
||||
const { page } = await import("/state.js");
|
||||
return (page.local.staged.m1?.ks || []).length === 2;
|
||||
});
|
||||
|
||||
s.post({ items: [{ id: "m1", body: "Which, now that Action is gone?", options: [opt("1", "Date"), opt("2", "User")] }] });
|
||||
await s.page.locator("#banner", { hasText: "no longer matches the reworded question" }).waitFor();
|
||||
assert.match(await textOf(s.page.locator("#banner")), /A pick on Columns no longer matches/);
|
||||
assert.deepEqual((await stagedOn(s)).m1.ks, ["1"]);
|
||||
await itemCard(s.page, "m1").getByText("Which, now that Action is gone?").waitFor();
|
||||
assert.equal(await itemCard(s.page, "m1").getByLabel("Date").isChecked(), true);
|
||||
// A notice, not a fault: it clears by itself.
|
||||
await s.page.locator("#banner").waitFor({ state: "hidden", timeout: 20000 });
|
||||
});
|
||||
|
||||
// What a person sees break: a chip that sends past the Implementation Loop,
|
||||
// which answers for the agent while it drives.
|
||||
test("the Ask for suggestions chip stays away while the loop drives, even on a card waiting for the person", async (t) => {
|
||||
const s = await openSession(await suite.browser(), {
|
||||
t,
|
||||
workflow: "implement",
|
||||
open: ["--loop"],
|
||||
env: { PLAN2CODE_IN_APP: "1" },
|
||||
payload: {
|
||||
items: [{ id: "c1", kind: "choice", title: "Export format", body: "Which format?", options: [opt("A", "CSV"), opt("B", "JSON")] }],
|
||||
agent: { status: "waiting" },
|
||||
},
|
||||
});
|
||||
await itemCard(s.page, "c1").getByLabel("JSON").waitFor();
|
||||
await s.page.locator("#thread-c1").waitFor();
|
||||
assert.equal(await chipOf(s).count(), 0, "no chip while the loop drives");
|
||||
});
|
||||
@@ -39,6 +39,8 @@ With nothing to post, `node "<CONSOLE>" wait --session <sid> --seconds 240` wait
|
||||
|
||||
`reply` is what they would have typed: one line per question, parts joined with `; `. Act on it as their typed answer, in that turn, with no summary back. Open every `Image:` and `File:` path in it with your file-read tool before you answer.
|
||||
|
||||
A `Suggestions wanted on <title>:` line asks your recommendation for that item: reply in its `thread`, list each suggestion and why, and re-post the item (reworded, `recommended`) only when that helps.
|
||||
|
||||
Other fields, when present: `session` (actions about the session, dispatch on `i`: `__launch` and `__pickup` run `resume`, then read `skillFile` and follow it in this conversation; `__stop`, `__dashboard`, `__commit`, `__changelog`, `__delete`, `__brief`, `__review`, `__done`, `__git` are covered by the topic file `read` names, or by your notes), `chat` (the seq numbers of Quick questions that need a reply), `read` (open each path now, before acting), `resume`, `skillFile`, `handoffFile`, `fallback` (hop fields: run `resume` as given).
|
||||
|
||||
## A patch
|
||||
|
||||
@@ -1819,6 +1819,13 @@
|
||||
answer and a note together. Plan2Code's replies appear in the same
|
||||
panel.
|
||||
</p>
|
||||
<p>
|
||||
On a question with options to pick, <strong>Ask for suggestions</strong>
|
||||
asks Plan2Code what it would pick and why, on its own: anything you
|
||||
already ticked stays as it is, and anything typed in the note box goes
|
||||
along with it. The answer appears in the same panel, and sometimes the
|
||||
question comes back reworded.
|
||||
</p>
|
||||
<h4>Attaching a file</h4>
|
||||
<p>Three ways, whichever is handiest:</p>
|
||||
<ul>
|
||||
|
||||
@@ -11,6 +11,7 @@ import { attachMentions } from "../mention-box.js";
|
||||
import { makeMdField } from "../md-field.js";
|
||||
import { pickerAccept, attachmentKind, noteAwaiting, threadWho, threadText } from "../answers.js";
|
||||
import { postJson } from "../net.js";
|
||||
import { suggestState } from "../send-state.js";
|
||||
import { CHECKIN_LINE, helperRows, showSwitch, switchLabel, defaultInstruction, PATHFINDER_RESEARCH_LINE, STRENGTHS, DEFAULT_STRENGTH, STRENGTH_HELP } from "../subagents.js";
|
||||
|
||||
const $ = (id) => document.getElementById(id);
|
||||
@@ -665,6 +666,7 @@ export function renderAside() {
|
||||
if (pending) who.appendChild(el("span", null, "Sent, waiting for Plan2Code"));
|
||||
else if (m.at) who.appendChild(el("span", null, shortTime(m.at)));
|
||||
box.appendChild(who);
|
||||
if (m.suggest === true) box.appendChild(suggestTag());
|
||||
const text = threadText(m);
|
||||
if (text) box.appendChild(md(text, "md"));
|
||||
const tray = mine ? sentAttachments(m) : null;
|
||||
@@ -678,6 +680,7 @@ export function renderAside() {
|
||||
who.appendChild(el("span", null, "You"));
|
||||
who.appendChild(el("span", null, "Sent, waiting for Plan2Code"));
|
||||
box.appendChild(who);
|
||||
if (waiting.suggest === true) box.appendChild(suggestTag());
|
||||
if (waiting.text) box.appendChild(md(waiting.text, "md"));
|
||||
const tray = sentAttachments(waiting);
|
||||
if (tray) box.appendChild(tray);
|
||||
@@ -698,7 +701,9 @@ export function renderAside() {
|
||||
wrap.appendChild(label);
|
||||
|
||||
const attached = noteImages(item.id);
|
||||
wrap.appendChild(attachRow(item.id, "Add files to this note"));
|
||||
const row = attachRow(item.id, "Add files to this note");
|
||||
if (!loopDriving() && !isDashboard() && SUGGEST_KINDS.includes(item.kind)) row.appendChild(suggestChip(item));
|
||||
wrap.appendChild(row);
|
||||
|
||||
if (attached.length) wrap.appendChild(attachTray(item.id, attached));
|
||||
|
||||
@@ -727,6 +732,33 @@ export function renderAside() {
|
||||
aside.scrollTop = place;
|
||||
}
|
||||
|
||||
// The cards with options to pick from, where asking what Plan2Code would pick
|
||||
// makes sense.
|
||||
const SUGGEST_KINDS = ["choice", "multi", "confirm"];
|
||||
|
||||
// Ask for suggestions: its own send, beside the main one (core.js). Focus
|
||||
// stays in the panel: on the chip when it is live again, else the note box.
|
||||
function suggestChip(item) {
|
||||
const st = suggestState(item);
|
||||
const chip = el("button", "btn tiny suggest-chip", "Ask for suggestions");
|
||||
chip.type = "button";
|
||||
chip.id = "suggest-" + item.id;
|
||||
chip.setAttribute("aria-label", "Ask Plan2Code for suggestions on this question");
|
||||
chip.title = st.why;
|
||||
chip.disabled = st.disabled;
|
||||
chip.addEventListener("click", async () => {
|
||||
await hooks.askSuggestions(item.id);
|
||||
const again = $("suggest-" + item.id);
|
||||
if (again && !again.disabled) again.focus();
|
||||
else $("thread-" + item.id)?.field?.focus();
|
||||
});
|
||||
return chip;
|
||||
}
|
||||
|
||||
function suggestTag() {
|
||||
return el("span", "pill suggest-tag", "Asked for suggestions");
|
||||
}
|
||||
|
||||
// The helpers the agent reported, as it last posted them. Everything here is
|
||||
// the agent's text, so it goes in as text, never as markup.
|
||||
export function renderSubagents(main) {
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
noteAction,
|
||||
noteReplyLines,
|
||||
progressTotal,
|
||||
pruneStaged,
|
||||
recordedAnswer,
|
||||
sentAnswer,
|
||||
staleLaunchFeedback,
|
||||
@@ -464,6 +465,18 @@ export function adopt(body) {
|
||||
delete page.local.sent[id];
|
||||
}
|
||||
}
|
||||
// A re-posted card can drop or rekey an option a pick was staged on: that
|
||||
// pick goes, and the person is told which question lost it.
|
||||
const pruned = pruneStaged(page.S.items || [], page.local.staged);
|
||||
if (pruned.dropped.length) {
|
||||
page.local.staged = pruned.staged;
|
||||
save();
|
||||
const titles = pruned.dropped.map((id) => (byId(id) && byId(id).title) || id).join(", ");
|
||||
const line = `A pick on ${titles} no longer matches the reworded question, so it was cleared.`;
|
||||
banner(line, "info");
|
||||
clearTimeout(arrivalBannerTimer);
|
||||
arrivalBannerTimer = setTimeout(() => !page.gone && $("banner").textContent === line && banner(null), 8000);
|
||||
}
|
||||
// A retracted send suppresses exactly that send. Once the item moves --
|
||||
// settled, sent again (a new `at`), or answered by an agent reply -- the
|
||||
// mark is stale and keeping it would hide a send that is not that one.
|
||||
|
||||
@@ -417,6 +417,11 @@ h1 {
|
||||
|
||||
.attach-row { display: flex; align-items: center; margin: -4px 0 6px -13px; }
|
||||
.attach-row.is-under { margin: 6px 0 4px -13px; }
|
||||
.attach-row .suggest-chip { margin: 0 0 0 auto; }
|
||||
.msg .suggest-tag {
|
||||
display: inline-block; margin-bottom: 4px;
|
||||
background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line);
|
||||
}
|
||||
.attach-tray { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
|
||||
.attach-thumb {
|
||||
position: relative;
|
||||
|
||||
@@ -1369,10 +1369,11 @@ function submit(req, res, ctx) {
|
||||
}
|
||||
// Name the items that went. A page with OTHER answers staged should drop
|
||||
// only what was sent, and a brief request is a submit carrying no answers
|
||||
// at all, so a blanket "everything is gone" is wrong for both.
|
||||
// at all, so a blanket "everything is gone" is wrong for both. A request
|
||||
// for suggestions sends no answer, so the pick staged on its card stays.
|
||||
ctx.broadcast("submitted", {
|
||||
rev: ctx.rev,
|
||||
ids: body.actions.map((a) => a && a.i).filter(Boolean),
|
||||
ids: body.actions.filter((a) => a && !(a.type === "comment" && a.suggest === true)).map((a) => a.i).filter(Boolean),
|
||||
});
|
||||
ctx.pushState();
|
||||
return json(res, 200, { ok: true });
|
||||
|
||||