mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 04:45:33 -08:00
Add a per-phase webhook message and more detail to loop notifications
AI Assisted
This commit is contained in:
1 parent
e5155778bf
commit
5136269ca7
7 files changed
+632
-79
No files matched your search
+1
-1
@@ -168,7 +168,7 @@ and Resume asks again if either one changed.
|
||||
**The notification.** The loop says a question is waiting, that it is complete, or why it stopped, and,
|
||||
when you turn on **Also tell me when each phase is complete**, that a phase passed. Nothing is sent when you
|
||||
stopped it yourself, and with **Take the agent's best guess** no question ever waits on you. Every message
|
||||
names the project and spec and the phase as `Phase 2 of 4 (name)`, and ends with the time the phase and the
|
||||
names the project and spec and the phase as `Phase 2 of 4 (name)`, and, except the finish message (run time only), ends with the time the phase and the
|
||||
whole run have taken. A phase message also says how many tasks are done, the commit's subject and short id,
|
||||
and what comes next, for example: `Plan2Code loop on plan2code / lunch-vote: Phase 2 of 4 (Votes) is complete.
|
||||
Done: 5 tasks, committed "Add votes" (abc1234). Next: Phase 3, Results. Elapsed: phase 6m, run 14m.` What the app sends depends on the **Send to** choice:
|
||||
|
||||
@@ -150,6 +150,9 @@ pub struct LoopSetup {
|
||||
/// The query parameter or JSON field that carries the message, for the
|
||||
/// kinds that let the person name it.
|
||||
pub notify_param: String,
|
||||
/// Whether a phase that passes is told to the address too (the question,
|
||||
/// stop and finish messages are always sent).
|
||||
pub notify_phases: bool,
|
||||
/// Whether each phase runs on its own strength (off: every phase runs as today).
|
||||
pub phase_strength: bool,
|
||||
/// The picks per spec folder (`specs/<name>`), only for phases not yet done.
|
||||
@@ -171,6 +174,7 @@ impl Default for LoopSetup {
|
||||
notify_kind: NotifyKind::Query,
|
||||
notify_url: String::new(),
|
||||
notify_param: loop_notify::DEFAULT_PARAM.to_string(),
|
||||
notify_phases: false,
|
||||
phase_strength: false,
|
||||
strengths: BTreeMap::new(),
|
||||
}
|
||||
@@ -242,6 +246,12 @@ pub struct TestsPart {
|
||||
pub ran: bool,
|
||||
pub passed: bool,
|
||||
pub summary: String,
|
||||
/// Names of the tests that failed, when `passed` is false.
|
||||
pub failing: Vec<String>,
|
||||
/// Names of the failing tests the phase file's Notes say are expected to
|
||||
/// fail until a later phase (`expectedFailures` on the wire).
|
||||
#[serde(rename = "expectedFailures")]
|
||||
pub expected_failures: Vec<String>,
|
||||
}
|
||||
|
||||
/// What a phase's skill reported (`loopOutcome`, overview API).
|
||||
@@ -754,6 +764,15 @@ fn expect_patch(setup: &LoopSetup) -> Value {
|
||||
/// Whether to take the skill's report at its word, cross-checked against the
|
||||
/// spec's own marks (`phase_status` is the phase's entry from `specs.mjs
|
||||
/// status`). The quick check runs after an Approve, not here.
|
||||
/// Whether every failing test the report names is also listed as expected.
|
||||
fn excused_failures(tests: &TestsPart) -> bool {
|
||||
!tests.failing.is_empty()
|
||||
&& tests
|
||||
.failing
|
||||
.iter()
|
||||
.all(|name| tests.expected_failures.contains(name))
|
||||
}
|
||||
|
||||
pub fn judge_outcome(outcome: &Outcome, phase_status: &Value, setup: &LoopSetup) -> Verdict {
|
||||
let refuse = |why: String| Verdict::Refuse(why);
|
||||
if outcome.result == "failed" {
|
||||
@@ -782,14 +801,26 @@ pub fn judge_outcome(outcome: &Outcome, phase_status: &Value, setup: &LoopSetup)
|
||||
// tasks and listed conflicts are not: the checks below cover blocked tasks
|
||||
// through the spec's own marks, and a conflict the agent worked around is
|
||||
// reported to the person, not refused (FR-7).
|
||||
// A failure is excused only when every failing test is named and also
|
||||
// listed as expected: a bare "expected" never passes, so a real failure
|
||||
// cannot be waved through.
|
||||
let mut warnings = Vec::new();
|
||||
if let Some(tests) = &outcome.tests {
|
||||
if tests.ran && !tests.passed {
|
||||
let summary = one_line(&tests.summary);
|
||||
return refuse(if summary.is_empty() {
|
||||
"its tests ran and failed".to_string()
|
||||
if excused_failures(tests) {
|
||||
warnings.push(format!(
|
||||
"{} test(s) failed as the phase's Notes expect: {}",
|
||||
tests.failing.len(),
|
||||
tests.failing.join(", ")
|
||||
));
|
||||
} else {
|
||||
format!("its tests ran and failed: {summary}")
|
||||
});
|
||||
let summary = one_line(&tests.summary);
|
||||
return refuse(if summary.is_empty() {
|
||||
"its tests ran and failed".to_string()
|
||||
} else {
|
||||
format!("its tests ran and failed: {summary}")
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
let blocked = count(tasks, "blocked");
|
||||
@@ -808,7 +839,6 @@ pub fn judge_outcome(outcome: &Outcome, phase_status: &Value, setup: &LoopSetup)
|
||||
if done != total {
|
||||
return refuse(format!("the spec shows {done} of {total} tasks done"));
|
||||
}
|
||||
let mut warnings = Vec::new();
|
||||
if setup.review {
|
||||
let review = outcome.review.clone().unwrap_or_default();
|
||||
if !review.ran {
|
||||
@@ -1313,8 +1343,14 @@ pub fn confirm_text(rec: &RunningRecord) -> String {
|
||||
));
|
||||
}
|
||||
if !rec.setup.notify_url.is_empty() {
|
||||
let when = if rec.setup.notify_phases {
|
||||
"after each phase, when the loop needs you, or when it ends"
|
||||
} else {
|
||||
"When the loop needs you or ends"
|
||||
};
|
||||
text.push_str(&format!(
|
||||
" When the loop needs you or ends, {}.",
|
||||
" {}, {}.",
|
||||
capitalized(when),
|
||||
loop_notify::describe(
|
||||
rec.setup.notify_kind,
|
||||
&rec.setup.notify_url,
|
||||
@@ -1325,6 +1361,14 @@ pub fn confirm_text(rec: &RunningRecord) -> String {
|
||||
text
|
||||
}
|
||||
|
||||
fn capitalized(text: &str) -> String {
|
||||
let mut chars = text.chars();
|
||||
chars
|
||||
.next()
|
||||
.map(|c| c.to_uppercase().collect::<String>() + chars.as_str())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// What the Start confirm promised about the notification, to tell a change on
|
||||
/// Resume; empty when no address is set.
|
||||
pub fn confirmed_notify(setup: &LoopSetup) -> String {
|
||||
@@ -1332,8 +1376,8 @@ pub fn confirmed_notify(setup: &LoopSetup) -> String {
|
||||
String::new()
|
||||
} else {
|
||||
format!(
|
||||
"{:?} {} {}",
|
||||
setup.notify_kind, setup.notify_url, setup.notify_param
|
||||
"{:?} {} {} {}",
|
||||
setup.notify_kind, setup.notify_url, setup.notify_param, setup.notify_phases
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1364,39 +1408,167 @@ pub fn send_notify_test(setup: &LoopSetup) -> Result<(), String> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The message for a question holding the loop, or ending it (On question: Stop).
|
||||
pub fn question_message(spec: &str, phase: u32, ended: bool) -> String {
|
||||
let name = spec.strip_prefix("specs/").unwrap_or(spec);
|
||||
if ended {
|
||||
format!("Plan2Code loop stopped on {name}: Phase {phase} has a question for you to answer.")
|
||||
} else {
|
||||
/// Where the loop is, copied out of the record so a message can be written, and
|
||||
/// sent, with no lock held.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Where {
|
||||
pub project: String,
|
||||
pub spec: String,
|
||||
pub n: u32,
|
||||
/// The spec's last phase number (phases already done are not in the record).
|
||||
pub of: usize,
|
||||
pub name: String,
|
||||
pub phase_time: Duration,
|
||||
pub run_time: Duration,
|
||||
}
|
||||
|
||||
impl Where {
|
||||
pub fn of(rec: &RunningRecord, index: usize) -> Where {
|
||||
let phase = &rec.phases[index];
|
||||
Where {
|
||||
project: rec
|
||||
.project
|
||||
.file_name()
|
||||
.map(|n| n.to_string_lossy().into_owned())
|
||||
.unwrap_or_default(),
|
||||
spec: rec
|
||||
.spec
|
||||
.strip_prefix("specs/")
|
||||
.unwrap_or(&rec.spec)
|
||||
.to_string(),
|
||||
n: phase.n,
|
||||
of: rec.phases.last().map_or(0, |p| p.n as usize),
|
||||
name: phase.name.clone(),
|
||||
phase_time: rec.phase_started_at.elapsed(),
|
||||
run_time: rec.started_at.elapsed(),
|
||||
}
|
||||
}
|
||||
|
||||
/// "plan2code / lunch", or just the spec when the folder has no name.
|
||||
fn label(&self) -> String {
|
||||
if self.project.is_empty() {
|
||||
self.spec.clone()
|
||||
} else {
|
||||
format!("{} / {}", self.project, self.spec)
|
||||
}
|
||||
}
|
||||
|
||||
/// "Phase 2 of 4 (Setup screen)".
|
||||
fn phase_text(&self) -> String {
|
||||
let mut text = format!("Phase {} of {}", self.n, self.of);
|
||||
if !self.name.is_empty() {
|
||||
text.push_str(&format!(" ({})", self.name));
|
||||
}
|
||||
text
|
||||
}
|
||||
|
||||
/// "Elapsed: phase 6m, run 14m."
|
||||
fn elapsed(&self) -> String {
|
||||
format!(
|
||||
"Plan2Code loop is waiting on {name}: Phase {phase} has a question for you to answer."
|
||||
"Elapsed: phase {}, run {}.",
|
||||
minutes(self.phase_time),
|
||||
minutes(self.run_time)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// "under 1m", "6m", "1h 5m".
|
||||
fn minutes(time: Duration) -> String {
|
||||
let total = time.as_secs() / 60;
|
||||
match total {
|
||||
0 => "under 1m".to_string(),
|
||||
1..=59 => format!("{total}m"),
|
||||
_ => format!("{}h {}m", total / 60, total % 60),
|
||||
}
|
||||
}
|
||||
|
||||
/// The message for a question holding the loop, or ending it (On question: Stop).
|
||||
pub fn question_message(at: &Where, ended: bool) -> String {
|
||||
let (verb, tail) = if ended {
|
||||
("stopped on", "has a question for you to answer")
|
||||
} else {
|
||||
("is waiting on", "has a question for you to answer")
|
||||
};
|
||||
format!(
|
||||
"Plan2Code loop {verb} {}: {} {tail}. {}",
|
||||
at.label(),
|
||||
at.phase_text(),
|
||||
at.elapsed()
|
||||
)
|
||||
}
|
||||
|
||||
/// The message for a loop that built everything.
|
||||
pub fn finished_message(spec: &str, phases: usize) -> String {
|
||||
let name = spec.strip_prefix("specs/").unwrap_or(spec);
|
||||
pub fn finished_message(at: &Where, phases: usize) -> String {
|
||||
let built = if phases == 1 {
|
||||
"1 phase".to_string()
|
||||
} else {
|
||||
format!("all {phases} phases")
|
||||
};
|
||||
format!("Plan2Code loop complete on {name}: {built} built.")
|
||||
format!(
|
||||
"Plan2Code loop complete on {}: {built} built. Elapsed: {}.",
|
||||
at.label(),
|
||||
minutes(at.run_time)
|
||||
)
|
||||
}
|
||||
|
||||
/// The message for a stop, or none when the person stopped it themselves.
|
||||
pub fn stop_message(cause: &StopCause, spec: &str, phase: u32, line: &str) -> Option<String> {
|
||||
let name = spec.strip_prefix("specs/").unwrap_or(spec);
|
||||
pub fn stop_message(cause: &StopCause, at: &Where, line: &str) -> Option<String> {
|
||||
match cause {
|
||||
StopCause::StoppedByPerson => None,
|
||||
StopCause::Question => Some(question_message(spec, phase, true)),
|
||||
_ => Some(format!("Plan2Code loop stopped on {name}: {line}")),
|
||||
StopCause::Question => Some(question_message(at, true)),
|
||||
_ => Some(format!(
|
||||
"Plan2Code loop stopped on {} at {}: {line} {}",
|
||||
at.label(),
|
||||
at.phase_text(),
|
||||
at.elapsed()
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// What a phase that passed did, for its message.
|
||||
pub struct PhaseDone {
|
||||
/// How many tasks the phase had, all of them done (the approval checked).
|
||||
pub tasks: Option<u64>,
|
||||
pub subject: String,
|
||||
/// The commit's short id, when one was made.
|
||||
pub commit: Option<String>,
|
||||
/// The next phase's number and name, or none after the last.
|
||||
pub next: Option<(u32, String)>,
|
||||
}
|
||||
|
||||
/// The message for a phase that passed (Also tell me when each phase is complete).
|
||||
pub fn phase_message(at: &Where, done: &PhaseDone) -> String {
|
||||
let mut text = format!(
|
||||
"Plan2Code loop on {}: {} is complete.",
|
||||
at.label(),
|
||||
at.phase_text()
|
||||
);
|
||||
let mut did = Vec::new();
|
||||
if let Some(tasks) = done.tasks {
|
||||
did.push(format!(
|
||||
"{tasks} {}",
|
||||
if tasks == 1 { "task" } else { "tasks" }
|
||||
));
|
||||
}
|
||||
match (done.subject.trim(), done.commit.as_deref()) {
|
||||
("", Some(commit)) => did.push(format!("committed {commit}")),
|
||||
("", None) => {}
|
||||
(subject, Some(commit)) => did.push(format!("committed \"{subject}\" ({commit})")),
|
||||
(subject, None) => did.push(format!("\"{subject}\", not committed")),
|
||||
}
|
||||
if !did.is_empty() {
|
||||
text.push_str(&format!(" Done: {}.", did.join(", ")));
|
||||
}
|
||||
match &done.next {
|
||||
Some((n, name)) if name.is_empty() => text.push_str(&format!(" Next: Phase {n}.")),
|
||||
Some((n, name)) => text.push_str(&format!(" Next: Phase {n}, {name}.")),
|
||||
None => text.push_str(" That was the last phase."),
|
||||
}
|
||||
text.push(' ');
|
||||
text.push_str(&at.elapsed());
|
||||
text
|
||||
}
|
||||
|
||||
/// Send the setup's notification, when it has one; the reason it failed, if it did.
|
||||
fn notify(setup: &LoopSetup, message: &str) -> Option<String> {
|
||||
if setup.notify_url.is_empty() {
|
||||
@@ -1643,8 +1815,9 @@ pub fn ask_prompt(spec: &str) -> String {
|
||||
format!(
|
||||
"The Implementation Loop for {spec} stopped. Change nothing: do not start the loop, \
|
||||
do not edit files and do not run git. Read {spec}/overview.md and the report so far, \
|
||||
then open the web console with --web (it joins the session already on screen) and \
|
||||
answer the person's questions through its Ask tab until they press a button on the \
|
||||
then open the web console with --web (it joins the session already on screen). Pass \
|
||||
neither --workflow nor --spec to that open: any workflow name makes it a hop to \
|
||||
another skill, which wipes the stopped screen. Answer the person's questions through its Ask tab until they press a button on the \
|
||||
stopped screen."
|
||||
)
|
||||
}
|
||||
@@ -1989,21 +2162,15 @@ fn observe(ctx: &Ctx, stage: Option<&str>, asked: bool) {
|
||||
} else if rec.step == Step::WaitingOnYou {
|
||||
rec.step = Step::Build;
|
||||
}
|
||||
let hold = newly_waiting.then(|| {
|
||||
(
|
||||
rec.setup.clone(),
|
||||
rec.spec.clone(),
|
||||
rec.phases[rec.current].n,
|
||||
)
|
||||
});
|
||||
let hold = newly_waiting.then(|| (rec.setup.clone(), Where::of(rec, rec.current)));
|
||||
((rec.step, rec.waiting) != before, hold)
|
||||
};
|
||||
if let Some((setup, spec, phase)) = hold {
|
||||
if let Some((setup, at)) = hold {
|
||||
(ctx.hooks.attention)();
|
||||
// On its own thread: a slow address must not delay the watch.
|
||||
let (slot, run_id) = (Arc::clone(&ctx.slot), ctx.run_id);
|
||||
thread::spawn(move || {
|
||||
if let Some(reason) = notify(&setup, &question_message(&spec, phase, false)) {
|
||||
if let Some(reason) = notify(&setup, &question_message(&at, false)) {
|
||||
if let Some(rec) = lock(&slot).as_mut().filter(|r| r.run_id == run_id) {
|
||||
rec.notify_failure = Some(reason);
|
||||
}
|
||||
@@ -2328,7 +2495,7 @@ fn handle_outcome(ctx: &Ctx, snap: &Snapshot, raw: &Value) -> bool {
|
||||
}
|
||||
.with_outcome(&outcome);
|
||||
add_entry(ctx, passed);
|
||||
let (next, stop_after, stop_now) = {
|
||||
let (next, stop_after, stop_now, told) = {
|
||||
let mut guard = lock(&ctx.slot);
|
||||
let Some(rec) = guard.as_mut().filter(|r| r.run_id == ctx.run_id) else {
|
||||
return false;
|
||||
@@ -2337,12 +2504,40 @@ fn handle_outcome(ctx: &Ctx, snap: &Snapshot, raw: &Value) -> bool {
|
||||
phase.status = PhaseStatus::Done;
|
||||
phase.commit = commit;
|
||||
phase.subject = Some(outcome.subject.clone());
|
||||
let told = (rec.setup.notify_phases && !rec.setup.notify_url.is_empty()).then(|| {
|
||||
let tasks = &entry["tasks"];
|
||||
let done = PhaseDone {
|
||||
tasks: counted(tasks, "total"),
|
||||
subject: outcome.subject.clone(),
|
||||
commit: rec.phases[snap.current].commit.clone(),
|
||||
next: rec
|
||||
.phases
|
||||
.get(snap.current + 1)
|
||||
.map(|p| (p.n, p.name.clone())),
|
||||
};
|
||||
(
|
||||
rec.setup.clone(),
|
||||
phase_message(&Where::of(rec, snap.current), &done),
|
||||
)
|
||||
});
|
||||
(
|
||||
(snap.current + 1 < rec.phases.len()).then_some(snap.current + 1),
|
||||
rec.stop_after_phase,
|
||||
rec.stop_now,
|
||||
told,
|
||||
)
|
||||
};
|
||||
if let Some((setup, message)) = told {
|
||||
// On its own thread: a slow address must not delay the next phase.
|
||||
let (slot, run_id) = (Arc::clone(&ctx.slot), ctx.run_id);
|
||||
thread::spawn(move || {
|
||||
if let Some(reason) = notify(&setup, &message) {
|
||||
if let Some(rec) = lock(&slot).as_mut().filter(|r| r.run_id == run_id) {
|
||||
rec.notify_failure = Some(reason);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// Stop now, even on the last phase: the phase is recorded as it stands,
|
||||
// and no next phase or Finalize follows.
|
||||
if stop_now {
|
||||
@@ -2993,7 +3188,7 @@ fn stop_loop(ctx: &Ctx, cause: StopCause, line: String, can: &[&str]) {
|
||||
rec.report.entries.push(entry);
|
||||
rec.report_failure = loop_report::save(&ctx.home, &rec.project, &rec.report).err();
|
||||
let mut evidence = evidence_with_report(&evidence_markdown(&cause, &line, &rec), &rec);
|
||||
let sent = stop_message(&cause, &rec.spec, rec.phases[at].n, &line)
|
||||
let sent = stop_message(&cause, &Where::of(&rec, at), &line)
|
||||
.and_then(|message| notify(&rec.setup, &message));
|
||||
if let Some(reason) = sent.or_else(|| rec.notify_failure.clone()) {
|
||||
let said = notify_failed(&reason);
|
||||
@@ -3084,7 +3279,7 @@ fn finish(ctx: &Ctx) {
|
||||
if skip_finalize && rec.setup.after_last == AfterLast::RunFinalize {
|
||||
said = format!("{said}; Finalize was not started, as you asked to stop");
|
||||
}
|
||||
let message = finished_message(&rec.spec, built);
|
||||
let message = finished_message(&Where::of(&rec, rec.current), built);
|
||||
if let Some(reason) = notify(&rec.setup, &message).or_else(|| rec.notify_failure.clone()) {
|
||||
said = format!("{said}; {}", notify_failed(&reason));
|
||||
}
|
||||
@@ -3304,41 +3499,114 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// Where a message is written from, without a record behind it.
|
||||
fn at_phase(spec: &str, n: u32, of: usize) -> Where {
|
||||
Where {
|
||||
project: "plan2code".into(),
|
||||
spec: spec.strip_prefix("specs/").unwrap_or(spec).into(),
|
||||
n,
|
||||
of,
|
||||
name: format!("P{n}"),
|
||||
phase_time: Duration::from_secs(6 * 60 + 20),
|
||||
run_time: Duration::from_secs(74 * 60),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_messages_say_what_the_person_needs_to_know() {
|
||||
let at = at_phase("specs/lunch", 2, 4);
|
||||
assert_eq!(
|
||||
question_message("specs/lunch", 2, false),
|
||||
"Plan2Code loop is waiting on lunch: Phase 2 has a question for you to answer."
|
||||
question_message(&at, false),
|
||||
"Plan2Code loop is waiting on plan2code / lunch: Phase 2 of 4 (P2) has a question for you to answer. Elapsed: phase 6m, run 1h 14m."
|
||||
);
|
||||
assert_eq!(
|
||||
stop_message(&StopCause::Question, "specs/lunch", 2, "ignored").unwrap(),
|
||||
"Plan2Code loop stopped on lunch: Phase 2 has a question for you to answer."
|
||||
stop_message(&StopCause::Question, &at, "ignored").unwrap(),
|
||||
"Plan2Code loop stopped on plan2code / lunch: Phase 2 of 4 (P2) has a question for you to answer. Elapsed: phase 6m, run 1h 14m."
|
||||
);
|
||||
assert_eq!(
|
||||
finished_message("specs/lunch", 3),
|
||||
"Plan2Code loop complete on lunch: all 3 phases built."
|
||||
finished_message(&at, 3),
|
||||
"Plan2Code loop complete on plan2code / lunch: all 3 phases built. Elapsed: 1h 14m."
|
||||
);
|
||||
assert_eq!(
|
||||
finished_message("specs/lunch", 1),
|
||||
"Plan2Code loop complete on lunch: 1 phase built."
|
||||
finished_message(&at, 1),
|
||||
"Plan2Code loop complete on plan2code / lunch: 1 phase built. Elapsed: 1h 14m."
|
||||
);
|
||||
assert_eq!(
|
||||
stop_message(
|
||||
&StopCause::QuickCheck,
|
||||
"specs/lunch",
|
||||
2,
|
||||
"Phase 2 stopped: tests"
|
||||
)
|
||||
.unwrap(),
|
||||
"Plan2Code loop stopped on lunch: Phase 2 stopped: tests"
|
||||
stop_message(&StopCause::QuickCheck, &at, "Phase 2 stopped: tests").unwrap(),
|
||||
"Plan2Code loop stopped on plan2code / lunch at Phase 2 of 4 (P2): Phase 2 stopped: tests Elapsed: phase 6m, run 1h 14m."
|
||||
);
|
||||
assert_eq!(
|
||||
stop_message(&StopCause::StoppedByPerson, "specs/lunch", 2, "x"),
|
||||
stop_message(&StopCause::StoppedByPerson, &at, "x"),
|
||||
None,
|
||||
"the person is already there"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_total_is_the_specs_last_phase_not_the_phases_left() {
|
||||
let rec = record("specs/x", vec![phase(4), phase(5)]);
|
||||
assert_eq!(Where::of(&rec, 0).phase_text(), "Phase 4 of 5 (P4)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_phase_message_says_what_was_done_and_what_is_next() {
|
||||
let at = at_phase("specs/lunch", 2, 4);
|
||||
let done = PhaseDone {
|
||||
tasks: Some(5),
|
||||
subject: "Add votes".into(),
|
||||
commit: Some("abc1234".into()),
|
||||
next: Some((3, "Results".into())),
|
||||
};
|
||||
assert_eq!(
|
||||
phase_message(&at, &done),
|
||||
"Plan2Code loop on plan2code / lunch: Phase 2 of 4 (P2) is complete. Done: 5 tasks, committed \"Add votes\" (abc1234). Next: Phase 3, Results. Elapsed: phase 6m, run 1h 14m."
|
||||
);
|
||||
// Commit off, the last phase, one task: nothing invented.
|
||||
let last = PhaseDone {
|
||||
tasks: Some(1),
|
||||
subject: "Add votes".into(),
|
||||
commit: None,
|
||||
next: None,
|
||||
};
|
||||
let text = phase_message(&at_phase("specs/lunch", 4, 4), &last);
|
||||
assert!(
|
||||
text.contains("Done: 1 task, \"Add votes\", not committed."),
|
||||
"{text}"
|
||||
);
|
||||
assert!(text.contains("That was the last phase."), "{text}");
|
||||
assert!(!text.contains("Next:"), "{text}");
|
||||
let bare = PhaseDone {
|
||||
tasks: None,
|
||||
subject: String::new(),
|
||||
commit: None,
|
||||
next: Some((3, String::new())),
|
||||
};
|
||||
let text = phase_message(&at, &bare);
|
||||
assert!(!text.contains("Done:"), "{text}");
|
||||
assert!(text.contains("Next: Phase 3."), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_phase_message_is_opt_in_and_changes_what_the_confirm_promises() {
|
||||
let mut s = setup();
|
||||
assert!(!s.notify_phases, "off by default");
|
||||
let older: LoopSetup = serde_json::from_value(json!({ "review": true })).unwrap();
|
||||
assert!(!older.notify_phases, "an older entry sends none");
|
||||
s.notify_url = "https://e.com/hook".into();
|
||||
let off = confirmed_notify(&s);
|
||||
let rec = RunningRecord::new("p".into(), "specs/x".into(), s.clone(), vec![phase(1)]);
|
||||
assert!(confirm_text(&rec).contains("When the loop needs you or ends"));
|
||||
s.notify_phases = true;
|
||||
assert_ne!(
|
||||
off,
|
||||
confirmed_notify(&s),
|
||||
"Resume asks again when the box changes"
|
||||
);
|
||||
let rec = RunningRecord::new("p".into(), "specs/x".into(), s, vec![phase(1)]);
|
||||
assert!(confirm_text(&rec)
|
||||
.contains("After each phase, when the loop needs you, or when it ends"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_web_address_means_no_call_and_an_older_entry_reads_with_none() {
|
||||
assert_eq!(notify(&setup(), "x"), None);
|
||||
@@ -3782,6 +4050,7 @@ mod tests {
|
||||
summary: "3 failed
|
||||
second line"
|
||||
.into(),
|
||||
..Default::default()
|
||||
});
|
||||
assert_eq!(
|
||||
refused(judge_outcome(&o, &st, &setup())),
|
||||
@@ -3796,12 +4065,45 @@ second line"
|
||||
ran: false,
|
||||
passed: false,
|
||||
summary: String::new(),
|
||||
..Default::default()
|
||||
});
|
||||
assert_eq!(judge_outcome(&o, &st, &setup()), approved());
|
||||
o.tests = None;
|
||||
assert_eq!(judge_outcome(&o, &st, &setup()), approved());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failing_tests_the_notes_expect_pass_with_a_warning_and_others_are_refused() {
|
||||
let st = status(14, 0, 0, 0);
|
||||
let mut o = passed();
|
||||
o.tests = Some(TestsPart {
|
||||
ran: true,
|
||||
passed: false,
|
||||
summary: "3 failed".into(),
|
||||
failing: vec!["a".into(), "b".into()],
|
||||
expected_failures: vec!["a".into(), "b".into()],
|
||||
});
|
||||
match judge_outcome(&o, &st, &setup()) {
|
||||
Verdict::Approve { warnings } => assert!(warnings
|
||||
.iter()
|
||||
.any(|w| w.contains("2 test(s) failed as the phase's Notes expect: a, b"))),
|
||||
other => panic!("expected approval, got {other:?}"),
|
||||
}
|
||||
o.tests.as_mut().unwrap().expected_failures = vec!["a".into()];
|
||||
assert_eq!(
|
||||
refused(judge_outcome(&o, &st, &setup())),
|
||||
"its tests ran and failed: 3 failed"
|
||||
);
|
||||
let t = o.tests.as_mut().unwrap();
|
||||
t.failing.clear();
|
||||
t.expected_failures = vec!["a".into()];
|
||||
assert_eq!(
|
||||
refused(judge_outcome(&o, &st, &setup())),
|
||||
"its tests ran and failed: 3 failed",
|
||||
"a bare expectation with no named failure never passes"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn blocked_tasks_and_conflicts_in_the_report_alone_do_not_refuse() {
|
||||
let mut o = passed();
|
||||
@@ -4364,6 +4666,7 @@ second line"
|
||||
ran: true,
|
||||
passed: false,
|
||||
summary: "2 failed".into(),
|
||||
..Default::default()
|
||||
});
|
||||
let review = outcome.review.as_mut().unwrap();
|
||||
review.left = Left {
|
||||
@@ -4899,6 +5202,38 @@ second line"
|
||||
end_the_test(&ctx);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_passing_phase_calls_the_web_address_only_when_the_box_is_on() {
|
||||
if !harness_ready("phase message") {
|
||||
return;
|
||||
}
|
||||
for (on, name) in [(true, "phase-message-on"), (false, "phase-message-off")] {
|
||||
let repo = throwaway_repo(name);
|
||||
let (ctx, home) = running_loop(&repo, Limits::default());
|
||||
let (url, calls) = listening_address();
|
||||
{
|
||||
let mut guard = lock(&ctx.slot);
|
||||
let setup = &mut guard.as_mut().unwrap().setup;
|
||||
setup.notify_url = url;
|
||||
setup.notify_param = "msg".into();
|
||||
setup.notify_phases = on;
|
||||
}
|
||||
finish_phase_tasks(&repo, 2);
|
||||
write_session(&home, json!({ "loopOutcome": good_report(2) }));
|
||||
assert!(tick(&ctx), "the loop goes on to Phase 3");
|
||||
if on {
|
||||
let call = calls.recv_timeout(CALL_WAIT).unwrap();
|
||||
assert!(call.contains("is%20complete."), "{call}");
|
||||
assert!(call.contains("Phase%202%20of%203%20"), "{call}");
|
||||
assert!(call.contains("Add%20the%20driver"), "{call}");
|
||||
assert!(call.contains("Next%3A%20Phase%203"), "{call}");
|
||||
} else {
|
||||
assert!(calls.recv_timeout(QUIET).is_err(), "the box is off");
|
||||
}
|
||||
end_the_test(&ctx);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn under_best_guess_a_question_stops_the_phase_at_once_naming_it() {
|
||||
if !git_ready("guess question") {
|
||||
@@ -5594,7 +5929,7 @@ second line"
|
||||
let big = evidence_markdown(&StopCause::UnsafeFiles(vec!["dump.bin".into()]), "l", &rec);
|
||||
assert!(big.contains("`dump.bin` (over 5 MB"), "{big}");
|
||||
// The line is never sent as a notification for a stop by the person.
|
||||
assert!(stop_message(&cause, "specs/lunch", 4, "x").is_some());
|
||||
assert!(stop_message(&cause, &at_phase("specs/lunch", 4, 5), "x").is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -6547,7 +6882,7 @@ second line"
|
||||
);
|
||||
assert!(!should_retry(&cause, &setup(), 0));
|
||||
let line = stop_line(&cause, 3, "", false);
|
||||
assert!(stop_message(&cause, "specs/lunch", 3, &line)
|
||||
assert!(stop_message(&cause, &at_phase("specs/lunch", 3, 3), &line)
|
||||
.unwrap()
|
||||
.contains("watcher failed"));
|
||||
let rec = record("specs/x", vec![phase(3)]);
|
||||
@@ -6724,9 +7059,17 @@ second line"
|
||||
fn a_finished_loop_calls_the_web_address_with_the_message() {
|
||||
let (ctx, calls) = notifying_loop("finish");
|
||||
finish(&ctx);
|
||||
assert_eq!(
|
||||
calls.recv_timeout(CALL_WAIT).unwrap(),
|
||||
"GET /hook?msg=Plan2Code%20loop%20complete%20on%20lunch%3A%20all%202%20phases%20built. HTTP/1.1"
|
||||
let call = calls.recv_timeout(CALL_WAIT).unwrap();
|
||||
assert!(
|
||||
call.starts_with("GET /hook?msg=Plan2Code%20loop%20complete%20on%20"),
|
||||
"{call}"
|
||||
);
|
||||
// The project's folder comes first, then the spec, then the time taken.
|
||||
assert!(
|
||||
call.ends_with(
|
||||
"%20%2F%20lunch%3A%20all%202%20phases%20built.%20Elapsed%3A%20under%201m. HTTP/1.1"
|
||||
),
|
||||
"{call}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6740,7 +7083,11 @@ second line"
|
||||
&["resume"],
|
||||
);
|
||||
let call = calls.recv_timeout(CALL_WAIT).unwrap();
|
||||
assert!(call.contains("loop%20stopped%20on%20lunch"), "{call}");
|
||||
assert!(call.contains("loop%20stopped%20on%20"), "{call}");
|
||||
assert!(
|
||||
call.contains("%20%2F%20lunch%20at%20Phase%202%20of%203"),
|
||||
"{call}"
|
||||
);
|
||||
assert!(call.contains("the%20quick%20check%20failed"), "{call}");
|
||||
|
||||
let (ctx, calls) = notifying_loop("question");
|
||||
@@ -6758,8 +7105,11 @@ second line"
|
||||
let (ctx, calls) = notifying_loop("hold");
|
||||
observe(&ctx, None, true);
|
||||
let call = calls.recv_timeout(CALL_WAIT).unwrap();
|
||||
assert!(call.contains("is%20waiting%20on%20lunch"), "{call}");
|
||||
assert!(call.contains("Phase%202"), "{call}");
|
||||
assert!(call.contains("is%20waiting%20on%20"), "{call}");
|
||||
assert!(
|
||||
call.contains("%20%2F%20lunch%3A%20Phase%202%20of%203"),
|
||||
"{call}"
|
||||
);
|
||||
// Still the same question: no second call. Answered, then a new one: another.
|
||||
observe(&ctx, None, true);
|
||||
assert!(calls.recv_timeout(QUIET).is_err());
|
||||
@@ -6846,6 +7196,9 @@ second line"
|
||||
assert!(!prompt.contains("--phase"), "{prompt}");
|
||||
assert!(prompt.to_lowercase().contains("change nothing"), "{prompt}");
|
||||
assert!(!prompt.contains('\u{2014}'), "{prompt}");
|
||||
// The open must not name a workflow or a spec: a hop wipes the stopped screen.
|
||||
assert!(prompt.contains("neither --workflow nor --spec"), "{prompt}");
|
||||
assert!(!prompt.contains("--workflow implement"), "{prompt}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -557,6 +557,7 @@ test("loop-setup: a new project reads as the defaults with remembered false, and
|
||||
assert.equal(got.setup.notifyUrl, "", "no web address is called by default");
|
||||
assert.equal(got.setup.notifyKind, "query");
|
||||
assert.equal(got.setup.notifyParam, "message");
|
||||
assert.equal(got.setup.notifyPhases, false, "a phase-complete message is opt-in");
|
||||
assert.equal(fs.existsSync(LOOP_SETUP_PATH), false, "reading never creates the file");
|
||||
});
|
||||
|
||||
@@ -626,6 +627,31 @@ test("loop-setup: an entry saved before fixMode existed reads as levels", () =>
|
||||
assert.deepEqual(got.read.fix, ["warning"], "the saved fields are kept");
|
||||
});
|
||||
|
||||
test("loop-setup: the phase-complete message saves as a yes or no, and an older entry reads as no", () => {
|
||||
fs.rmSync(LOOP_SETUP_PATH, { force: true });
|
||||
const got = inStore(
|
||||
async (m, { project, workspace }) => {
|
||||
const fs = await import("node:fs");
|
||||
const { foldKey } = await import(workspace);
|
||||
const base = { ...m.LOOP_DEFAULTS, fix: [...m.LOOP_DEFAULTS.fix], notifyUrl: "https://example.com/hook" };
|
||||
const on = m.saveLoopSetup(project, { ...base, notifyPhases: true }).notifyPhases;
|
||||
let refused = "";
|
||||
try {
|
||||
m.saveLoopSetup(project, { ...base, notifyPhases: "yes" });
|
||||
} catch (e) {
|
||||
refused = e.message;
|
||||
}
|
||||
const { notifyPhases, ...older } = { ...base, saved: "2026-01-01T00:00:00.000Z" };
|
||||
fs.writeFileSync(m.LOOP_SETUP_FILE, JSON.stringify({ schema: 1, projects: { [foldKey(project)]: older } }));
|
||||
return { on, refused, older: m.readLoopSetup(project).notifyPhases };
|
||||
},
|
||||
{ project: projectA, workspace: WORKSPACE_URL }
|
||||
);
|
||||
assert.equal(got.on, true);
|
||||
assert.match(got.refused, /"notifyPhases" must be true or false/);
|
||||
assert.equal(got.older, false, "an entry saved before the box existed sends no phase messages");
|
||||
});
|
||||
|
||||
test("loop-setup: good web addresses save, with a bad name allowed only while no address is set", () => {
|
||||
fs.rmSync(LOOP_SETUP_PATH, { force: true });
|
||||
const got = inStore(
|
||||
@@ -778,7 +804,7 @@ test("loop-setup: GET /loop-setup lists the phases left for a spec and refuses a
|
||||
}
|
||||
|
||||
// Saving through the route, then reading it back in a new request.
|
||||
const save = await send({ review: true, fixMode: "smart", fix: ["critical"], commit: true, onQuestion: "stop", afterLast: "offer-finalize", quickCheck: "", notifyKind: "query", notifyUrl: "https://example.com/hook", notifyParam: "msg", retryOnce: true, silenceMinutes: 30, phaseStrength: false, strengths: {} });
|
||||
const save = await send({ review: true, fixMode: "smart", fix: ["critical"], commit: true, onQuestion: "stop", afterLast: "offer-finalize", quickCheck: "", notifyKind: "query", notifyUrl: "https://example.com/hook", notifyParam: "msg", notifyPhases: true, retryOnce: true, silenceMinutes: 30, phaseStrength: false, strengths: {} });
|
||||
assert.equal(save.status, 200, await save.clone().text());
|
||||
const after = await get("?spec=specs/demo");
|
||||
assert.equal(after.body.remembered, true);
|
||||
@@ -948,7 +974,7 @@ test("GET /loop-setup?agent= answers the loop agent's resolved strengths and thi
|
||||
// A save with picks reads back for its own spec; a pick for a phase that is not there is pruned.
|
||||
const entry = {
|
||||
review: true, fixMode: "smart", fix: ["critical"], commit: true, onQuestion: "guess", afterLast: "offer-finalize", quickCheck: "",
|
||||
notifyKind: "query", notifyUrl: "", notifyParam: "message", retryOnce: true, silenceMinutes: 20, phaseStrength: true,
|
||||
notifyKind: "query", notifyUrl: "", notifyParam: "message", notifyPhases: false, retryOnce: true, silenceMinutes: 20, phaseStrength: true,
|
||||
strengths: { "specs/demo": [{ n: 2, name: "Two", strength: "best" }, { n: 9, name: "Gone", strength: "best" }] },
|
||||
};
|
||||
const save = await fetch(`${base}/loop-setup`, { method: "POST", headers: { "content-type": "application/json", cookie, origin: base, connection: "close" }, body: JSON.stringify(entry) });
|
||||
|
||||
@@ -73,6 +73,8 @@ test("the web address field shows the name only beside an address, warns while t
|
||||
|
||||
assert.equal(await url.inputValue(), "");
|
||||
assert.equal(await param.isVisible(), false, "no address, no name to set");
|
||||
const phases = s.page.locator("#loop-notify-phases");
|
||||
assert.equal(await phases.isVisible(), false, "no address, no phase messages to choose");
|
||||
assert.equal(await warn.isVisible(), false);
|
||||
|
||||
await url.fill("example.com");
|
||||
@@ -83,6 +85,9 @@ test("the web address field shows the name only beside an address, warns while t
|
||||
assert.equal(await warn.isVisible(), false);
|
||||
assert.equal(await param.isVisible(), true);
|
||||
assert.equal(await param.inputValue(), "message", "the default name");
|
||||
assert.equal(await phases.isVisible(), true);
|
||||
assert.equal(await phases.isChecked(), false, "a message per phase is opt-in");
|
||||
await phases.check();
|
||||
|
||||
await param.fill("a b");
|
||||
assert.match(await textOf(warn), /letters, digits/);
|
||||
@@ -103,6 +108,7 @@ test("the web address field shows the name only beside an address, warns while t
|
||||
const reread = await s.page.evaluate(async () => (await fetch("/loop-setup")).json());
|
||||
assert.equal(reread.notifyUrl, "https://example.com/hook?team=a");
|
||||
assert.equal(reread.notifyParam, "msg");
|
||||
assert.equal(reread.notifyPhases, true, "the box is saved with the setup");
|
||||
assert.equal(reread.remembered, true);
|
||||
});
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ export const LOOP_DEFAULTS = Object.freeze({
|
||||
notifyKind: "query",
|
||||
notifyUrl: "",
|
||||
notifyParam: "message",
|
||||
notifyPhases: false,
|
||||
phaseStrength: false,
|
||||
strengths: Object.freeze({}),
|
||||
});
|
||||
@@ -61,7 +62,7 @@ export function loopSetupProblems(entry) {
|
||||
for (const key of Object.keys(entry)) {
|
||||
if (!Object.hasOwn(LOOP_DEFAULTS, key)) problems.push(`"${key}" is not a setup field`);
|
||||
}
|
||||
for (const key of ["review", "commit", "retryOnce"]) {
|
||||
for (const key of ["review", "commit", "retryOnce", "notifyPhases"]) {
|
||||
if (typeof entry[key] !== "boolean") problems.push(`"${key}" must be true or false`);
|
||||
}
|
||||
if (!Array.isArray(entry.fix) || !entry.fix.every((l) => LEVELS.includes(l)) || new Set(entry.fix).size !== entry.fix.length) {
|
||||
|
||||
@@ -101,6 +101,7 @@ export async function openLoopSetup(spec) {
|
||||
notifyKind: NOTIFY_KINDS.some((k) => k.id === setup.notifyKind) ? setup.notifyKind : "query",
|
||||
notifyUrl: typeof setup.notifyUrl === "string" ? setup.notifyUrl : "",
|
||||
notifyParam: setup.notifyParam || DEFAULT_NOTIFY_PARAM,
|
||||
notifyPhases: setup.notifyPhases === true,
|
||||
phaseStrength: setup.phaseStrength === true,
|
||||
// Every spec's picks, as saved; only this spec's key is changed here.
|
||||
strengths: setup.strengths && typeof setup.strengths === "object" && !Array.isArray(setup.strengths) ? structuredClone(setup.strengths) : {},
|
||||
@@ -182,6 +183,7 @@ export function pickModelText(resolved, word, appFacts) {
|
||||
}
|
||||
|
||||
function close() {
|
||||
stopWatchingLine();
|
||||
page.loopSetup = null;
|
||||
page.loopStart = null;
|
||||
redraw();
|
||||
@@ -354,8 +356,97 @@ function select(id, label, options, value, onChange) {
|
||||
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
|
||||
* three flat bars with the middle one lighter. `text` adds the name after the bars.
|
||||
*/
|
||||
export function strengthBadge(level, text) {
|
||||
const chip = el("span", `sa-badge lvl-${level}`);
|
||||
chip.appendChild(strengthBars(level));
|
||||
if (text) chip.appendChild(document.createTextNode(text));
|
||||
return chip;
|
||||
}
|
||||
|
||||
function strengthBars(level) {
|
||||
const bars = el("span", level ? "sa-bars" : "sa-bars is-flat");
|
||||
bars.setAttribute("aria-hidden", "true");
|
||||
for (let i = 1; i <= 3; i++) bars.appendChild(el("i", level && i <= level ? "on" : null));
|
||||
return bars;
|
||||
}
|
||||
|
||||
const SVG_NS = "http://www.w3.org/2000/svg";
|
||||
let lineGrid = null;
|
||||
let lineWatching = false;
|
||||
|
||||
function svgPart(name, attrs) {
|
||||
const part = document.createElementNS(SVG_NS, name);
|
||||
for (const [k, v] of Object.entries(attrs)) part.setAttribute(k, String(v));
|
||||
return part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the strength line into the grid's SVG from where the checked nodes sit:
|
||||
* a dashed column line per strength, then a square-step path from each row's
|
||||
* picked node to the next. Derived from the DOM on every call, so it cannot
|
||||
* disagree with the radios.
|
||||
*/
|
||||
export function drawStrengthLine(grid) {
|
||||
const svg = grid && grid.querySelector(".loop-strength-line");
|
||||
if (!svg) return;
|
||||
svg.replaceChildren();
|
||||
const gr = grid.getBoundingClientRect();
|
||||
const nodes = [...grid.querySelectorAll(".loop-strength-row input:checked + .loop-strength-node")];
|
||||
if (nodes.length < 2 || !gr.width) return;
|
||||
svg.setAttribute("viewBox", `0 0 ${gr.width} ${gr.height}`);
|
||||
const pts = nodes.map((n) => {
|
||||
const b = n.getBoundingClientRect();
|
||||
return { x: b.left - gr.left + b.width / 2, y: b.top - gr.top + b.height / 2 };
|
||||
});
|
||||
const top = grid.querySelector(".loop-strength-row").getBoundingClientRect().top - gr.top;
|
||||
grid.querySelectorAll(".loop-strength-head .loop-strength-chip").forEach((chip, k) => {
|
||||
const b = chip.getBoundingClientRect();
|
||||
const x = b.left - gr.left + b.width / 2;
|
||||
svg.appendChild(svgPart("line", { class: `col lvl-${k}`, x1: x, x2: x, y1: top, y2: gr.height }));
|
||||
});
|
||||
for (let i = 1; i < pts.length; i++) {
|
||||
const a = pts[i - 1];
|
||||
const p = pts[i];
|
||||
// The run across sits at the top of the next node's cell, so it stays clear of a phase name above the cells.
|
||||
const m = nodes[i].parentElement.getBoundingClientRect().top - gr.top;
|
||||
let d = `M${a.x} ${a.y}V${p.y}`;
|
||||
if (a.x !== p.x) {
|
||||
const r = Math.min(8, Math.abs(p.x - a.x) / 2);
|
||||
const dir = p.x > a.x ? 1 : -1;
|
||||
d = `M${a.x} ${a.y}V${m - r}Q${a.x} ${m} ${a.x + dir * r} ${m}H${p.x - dir * r}Q${p.x} ${m} ${p.x} ${m + r}V${p.y}`;
|
||||
}
|
||||
svg.appendChild(svgPart("path", { class: "step", d }));
|
||||
}
|
||||
}
|
||||
|
||||
function redrawLine() {
|
||||
if (lineGrid && lineGrid.isConnected) drawStrengthLine(lineGrid);
|
||||
else stopWatchingLine();
|
||||
}
|
||||
|
||||
function stopWatchingLine() {
|
||||
lineGrid = null;
|
||||
if (lineWatching) window.removeEventListener("resize", redrawLine);
|
||||
lineWatching = false;
|
||||
}
|
||||
|
||||
/** Draw once layout exists, and again on resize and when fonts load; stop once the grid is gone. */
|
||||
function watchStrengthLine(grid) {
|
||||
lineGrid = grid;
|
||||
if (!lineWatching) window.addEventListener("resize", redrawLine);
|
||||
lineWatching = true;
|
||||
requestAnimationFrame(redrawLine);
|
||||
if (document.fonts && document.fonts.ready) document.fonts.ready.then(redrawLine);
|
||||
}
|
||||
|
||||
/** The "Strength per phase" field: the toggle, Set all to, and one row per phase left. */
|
||||
function strengthField(s, redo) {
|
||||
stopWatchingLine();
|
||||
const f = s.form;
|
||||
const resolved = s.facts.resolved;
|
||||
const box = field("Strength per phase");
|
||||
@@ -400,23 +491,59 @@ function strengthField(s, redo) {
|
||||
all.appendChild(everyone);
|
||||
box.appendChild(all);
|
||||
|
||||
// One column per option, in rank order: level 0 is Match my session.
|
||||
const columns = [["", MATCH_SESSION], ...STRENGTH_WORDS].map(([value, label], level) => ({ value, label, level, mapped: value === "" || Boolean(resolved[value]) }));
|
||||
const grid = el("div", "loop-strength-grid");
|
||||
const line = svgPart("svg", { class: "loop-strength-line", "aria-hidden": "true", focusable: "false" });
|
||||
const head = el("div", "loop-strength-head");
|
||||
head.appendChild(el("span", "loop-strength-spacer"));
|
||||
for (const c of columns) {
|
||||
const chip = strengthBadge(c.level, c.mapped ? c.label : `${c.label} (not mapped)`);
|
||||
chip.classList.add("loop-strength-chip");
|
||||
if (!c.mapped) chip.classList.add("is-unmapped");
|
||||
head.appendChild(chip);
|
||||
}
|
||||
head.appendChild(el("span", "loop-strength-spacer"));
|
||||
grid.appendChild(head);
|
||||
|
||||
const rows = el("div", "loop-strength-rows");
|
||||
for (const p of s.facts.phasesLeft) {
|
||||
const word = pickOf(f, s.spec, p);
|
||||
const row = el("div", "loop-strength-row");
|
||||
row.dataset.phase = String(p.n);
|
||||
row.setAttribute("role", "radiogroup");
|
||||
row.setAttribute("aria-label", `Phase ${p.n} strength`);
|
||||
row.appendChild(el("span", "loop-strength-phase", `Phase ${p.n}: ${p.name}`));
|
||||
row.appendChild(
|
||||
select(`loop-strength-${p.n}`, `Phase ${p.n} strength`, options, word, (v) => {
|
||||
setPick(f, s.spec, p, v);
|
||||
for (const c of columns) {
|
||||
const cell = el("label", `loop-strength-cell lvl-${c.level}${c.mapped ? "" : " is-unmapped"}`);
|
||||
const input = el("input");
|
||||
input.type = "radio";
|
||||
input.name = `loop-strength-${p.n}`;
|
||||
input.id = `loop-strength-${p.n}-${c.value || "match"}`;
|
||||
input.value = c.value;
|
||||
input.checked = word === c.value;
|
||||
input.disabled = !c.mapped;
|
||||
input.setAttribute("aria-label", `Phase ${p.n} ${c.label}`);
|
||||
input.addEventListener("change", () => {
|
||||
if (!input.checked) return;
|
||||
setPick(f, s.spec, p, c.value);
|
||||
s.problems = [];
|
||||
redraw();
|
||||
})
|
||||
);
|
||||
});
|
||||
const node = el("span", "loop-strength-node");
|
||||
node.appendChild(strengthBars(c.level));
|
||||
cell.append(input, node);
|
||||
row.appendChild(cell);
|
||||
}
|
||||
row.appendChild(el("span", "loop-strength-model", pickModelText(resolved, word, page.loopFacts)));
|
||||
rows.appendChild(row);
|
||||
}
|
||||
box.appendChild(rows);
|
||||
grid.appendChild(rows);
|
||||
if (s.facts.phasesLeft.length >= 2) {
|
||||
grid.prepend(line);
|
||||
watchStrengthLine(grid);
|
||||
}
|
||||
box.appendChild(grid);
|
||||
return box;
|
||||
}
|
||||
|
||||
@@ -496,7 +623,7 @@ function drawBody(pane, s) {
|
||||
|
||||
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. Leave the address empty to send nothing."
|
||||
"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"));
|
||||
@@ -529,6 +656,9 @@ function drawBody(pane, s) {
|
||||
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");
|
||||
@@ -545,6 +675,7 @@ function drawBody(pane, s) {
|
||||
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;
|
||||
@@ -577,7 +708,7 @@ function drawBody(pane, s) {
|
||||
showNotify();
|
||||
});
|
||||
showNotify();
|
||||
notify.append(kindLabel, notifyInput, kindHint, paramRow, notifyWarn, testRow);
|
||||
notify.append(kindLabel, notifyInput, kindHint, paramRow, phasesRow, notifyWarn, testRow);
|
||||
form.appendChild(notify);
|
||||
|
||||
const check = field("Quick check", "A command the app runs after each phase, such as npm run build. The page never runs it.");
|
||||
|
||||
@@ -633,14 +633,50 @@
|
||||
.loop-radio-body { display: grid; gap: 1px; }
|
||||
.loop-radio-detail { font-size: 12.5px; color: var(--ink-3); }
|
||||
.loop-switch.is-gray { opacity: 0.55; cursor: default; }
|
||||
.loop-switch[hidden] { display: none; }
|
||||
.loop-strength-none .linky { font-size: inherit; }
|
||||
.loop-strength-all { display: flex; align-items: center; gap: 10px; margin-top: 4px; font-size: 13px; color: var(--ink-2); }
|
||||
.loop-strength-rows { display: grid; gap: 6px; }
|
||||
.loop-strength-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(150px, 190px) minmax(70px, 120px); align-items: center; gap: 10px; font-size: 13.5px; }
|
||||
.loop-strength-phase { overflow-wrap: anywhere; color: var(--ink); }
|
||||
.loop-strength-model { font-size: 12.5px; color: var(--ink-3); overflow-wrap: anywhere; }
|
||||
.loop-strength-grid { position: relative; display: grid; gap: 6px; margin-top: 6px; }
|
||||
.loop-strength-line { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 0; }
|
||||
.loop-strength-line .step { fill: none; stroke: var(--ink-3); stroke-width: 3px; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.loop-strength-line .col { stroke-width: 2px; stroke-dasharray: 2 5; stroke-linecap: round; stroke-opacity: 0.18; }
|
||||
.loop-strength-line .col.lvl-0 { stroke: var(--lvl-0); }
|
||||
.loop-strength-line .col.lvl-1 { stroke: var(--lvl-1); }
|
||||
.loop-strength-line .col.lvl-2 { stroke: var(--lvl-2); }
|
||||
.loop-strength-line .col.lvl-3 { stroke: var(--lvl-3); }
|
||||
.loop-strength-rows { display: grid; gap: 0; }
|
||||
.loop-strength-head, .loop-strength-row { position: relative; z-index: 1; display: grid; grid-template-columns: minmax(130px, 1.5fr) repeat(4, minmax(0, 1fr)) 64px; align-items: center; column-gap: 4px; font-size: 13.5px; }
|
||||
.loop-strength-row { min-height: 34px; }
|
||||
.loop-strength-chip { justify-self: center; font-size: 12px; padding: 5px 9px; white-space: normal; text-align: center; line-height: 1.15; max-width: 100%; border-radius: 16px; }
|
||||
.loop-strength-chip.is-unmapped { opacity: 0.5; }
|
||||
.loop-strength-phase { overflow-wrap: anywhere; color: var(--ink); padding-right: 8px; }
|
||||
.loop-strength-model { font-size: 12.5px; color: var(--ink-3); overflow-wrap: anywhere; text-align: right; }
|
||||
.loop-strength-cell { --b: var(--lvl-0); position: relative; display: flex; align-items: center; justify-content: center; height: 34px; cursor: pointer; }
|
||||
.loop-strength-cell.lvl-1 { --b: var(--lvl-1); }
|
||||
.loop-strength-cell.lvl-2 { --b: var(--lvl-2); }
|
||||
.loop-strength-cell.lvl-3 { --b: var(--lvl-3); }
|
||||
.loop-strength-cell input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: inherit; }
|
||||
.loop-strength-node { box-sizing: border-box; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--ink-3); background: var(--bg); display: grid; place-items: center; color: var(--bg); transition: all 0.12s; position: relative; z-index: 2; }
|
||||
.loop-strength-cell:hover .loop-strength-node { border-color: var(--b); transform: scale(1.25); }
|
||||
.loop-strength-cell input:focus-visible + .loop-strength-node { outline: 2px solid var(--focus); outline-offset: 3px; }
|
||||
.loop-strength-cell input:checked + .loop-strength-node { width: 30px; height: 30px; background: var(--b); border-color: var(--b); box-shadow: 0 0 0 4px var(--bg); }
|
||||
.loop-strength-node .sa-bars { display: none; }
|
||||
.loop-strength-cell input:checked + .loop-strength-node .sa-bars { display: inline-flex; }
|
||||
.loop-strength-cell.is-unmapped { cursor: default; }
|
||||
.loop-strength-cell.is-unmapped .loop-strength-node { opacity: 0.35; }
|
||||
.loop-strength-cell.is-unmapped input:checked + .loop-strength-node { opacity: 0.7; }
|
||||
.loop-strength-cell.is-unmapped:hover .loop-strength-node { transform: none; border-color: var(--ink-3); }
|
||||
.loop-strength-cell.is-unmapped input:checked + .loop-strength-node:hover { border-color: var(--b); }
|
||||
/* Match my session has no rank: three flat bars, the middle one lighter. */
|
||||
.sa-bars.is-flat i:nth-child(n) { height: 7px; opacity: 1; }
|
||||
.sa-bars.is-flat i:nth-child(2) { opacity: 0.55; }
|
||||
.loop-select { font: inherit; font-size: 13.5px; padding: 5px 8px; color: var(--ink); background: var(--panel-2); border: 1px solid var(--rule); border-radius: 6px; max-width: 100%; }
|
||||
@media (max-width: 560px) { .loop-strength-row { grid-template-columns: 1fr 1fr; } .loop-strength-phase { grid-column: 1 / -1; } }
|
||||
@media (max-width: 620px) {
|
||||
.loop-strength-head, .loop-strength-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
||||
.loop-strength-spacer, .loop-strength-model { display: none; }
|
||||
.loop-strength-phase { grid-column: 1 / -1; padding-top: 8px; }
|
||||
.loop-strength-chip { font-size: 10.5px; padding: 4px 6px; gap: 4px; flex-wrap: wrap; justify-content: center; }
|
||||
}
|
||||
.loop-ticks { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-left: 4px; }
|
||||
.loop-text { font: inherit; font-size: 14px; padding: 6px 10px; color: var(--ink); background: var(--panel-2); border: 1px solid var(--rule); border-radius: 6px; max-width: 520px; width: 100%; }
|
||||
.loop-text.loop-narrow { width: 90px; }
|
||||
|
||||
Reference in new issue
Block a user