@lysyi3m/sidecar 1.8.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -84,8 +84,15 @@ export function applyItemEvent(items, e, askOf) {
84
84
  item.status = decisionState(e) === "planned" ? "planned" : "addressed";
85
85
  }
86
86
  }
87
- /** An item's status under a review budget: a decision past the budget is left for the user. */
88
- export const itemStatus = (item, budget) => item.status === "addressed" && item.reviewTurns >= budget ? "exhausted" : item.status;
87
+ /**
88
+ * An item's status under a review budget. A point awaiting review or reopened once its reviews are
89
+ * spent is left for the user: no further review can settle it.
90
+ */
91
+ export const itemStatus = (item, budget) => (item.status === "addressed" || item.status === "reopened") && item.reviewTurns >= budget
92
+ ? "exhausted"
93
+ : item.status;
94
+ /** Whether a point's reviews are spent: a decision on it now is never reviewed. */
95
+ export const reviewsSpent = (item, budget) => item.reviewTurns >= budget;
89
96
  /** Items whose latest decision awaits the navigator's review, oldest decision first. */
90
97
  export function awaitingReview(items, budget) {
91
98
  return [...items.values()]
@@ -179,9 +179,11 @@ export function sideList(cases, activeCase, collapsed = DEFAULT_COLLAPSED) {
179
179
  </a>`
180
180
  : html `<a class="side-case" href="/cases/${c.case_id}"${current(c)}>
181
181
  <div class="side-title">${c.title || c.case_id}</div>
182
- <div class="side-meta"><span>${ago(c.updated)}</span>${
183
- // The section heading already says active or closed; only a state worth noticing gets a tag.
184
- c.in_flight ? html `<span class="side-tag is-accent">asking</span>` : ""}</div>
182
+ <div class="side-meta"><span>${ago(c.updated)}</span></div>${
183
+ // A running turn shows as motion, not words: a line sweeps under the entry.
184
+ c.in_flight
185
+ ? html `<span class="side-live" role="img" aria-label="navigator answering"></span>`
186
+ : ""}
185
187
  </a>`;
186
188
  const section = (name, label, members) => {
187
189
  if (!members.length)
@@ -197,8 +199,8 @@ export function sideList(cases, activeCase, collapsed = DEFAULT_COLLAPSED) {
197
199
  }
198
200
  /* ---------------------------------------------------------------- index */
199
201
  /** The index's state filters, by the case state each shows, with the label the sidebar uses. */
200
- const FILTERS = ["open", "closed"];
201
- const FILTER_LABELS = { open: "active", closed: "closed" };
202
+ const FILTERS = ["all", "open", "closed"];
203
+ const FILTER_LABELS = { all: "all", open: "active", closed: "closed" };
202
204
  export function indexPage(cases, query, chrome = { collapsed: false }) {
203
205
  const filter = FILTERS.find((f) => f === query.state) ?? "open";
204
206
  const content = html `<div class="toolbar">
@@ -263,25 +265,51 @@ function caseHead(model) {
263
265
  const { state, status, items, caseId } = model;
264
266
  const { opened } = state;
265
267
  const views = [...items.values()];
266
- const flagCount = views.filter((v) => v.item.kind === "flag").length;
267
- const unsettledCount = views.filter((v) => v.status !== "confirmed").length;
268
- const held = views.filter((v) => v.status === "held").length;
269
- // Amber asks for action while the case is in progress; a closed case keeps its counts, plain.
270
- const alert = status === "closed" ? "stat" : "stat is-alert";
271
268
  const opinions = [...state.asks.values()].filter((a) => a.terminal?.kind === "opinion").length;
269
+ const flags = views.filter((v) => v.item.kind === "flag").length;
270
+ const unsettled = views.filter((v) => v.status !== "confirmed").length;
271
+ // Points the agents could not settle between them: the user decides each one.
272
+ const standing = views
273
+ .filter((v) => v.status === "held" || v.status === "exhausted")
274
+ .sort((a, b) => a.item.raisedN - b.item.raisedN)
275
+ .map((v) => v.item.ref);
276
+ const standingRow = standing.length > 0
277
+ ? html `<div class="standing"><span class="label">${standing.length} ${standing.length > 1 ? "standing disagreements" : "standing disagreement"}</span>${standing.map((ref) => refFor(ref, model))}</div>`
278
+ : "";
272
279
  const fact = (name, value) => html `<div class="fact"><dt class="label">${name}</dt><dd>${value}</dd></div>`;
273
280
  return html `<header class="case-head" id="case-head">
274
281
  <h1 class="title">${opened.title}</h1>
275
282
  <div class="case-meta">${stateChip(status)}<div class="case-path case-where mono"><span>${caseId}</span><span>·</span>${pathLine(opened.workspace)}</div></div>
276
- <dl class="facts">${[
283
+ <dl class="facts${state.inFlight ? " is-live" : ""}">${[
277
284
  fact("Driver", driverLine(opened.driver, state.driverModel, state.driverEffort)),
278
285
  fact("Navigator", agentLine(opened.navigator, opened.model, opened.effort)),
279
286
  fact("Opened", html `<span class="mono">${time(opened.ts, "zoned")}</span>`),
280
287
  fact("Last activity", ago(model.events.at(-1)?.ts)),
281
- ]}</dl>
282
- <div class="stats"><span class="stat"><b>${state.asks.size}</b>asks</span><span class="stat"><b>${opinions}</b>opinions</span><span class="stat"><b>${flagCount}</b>raised flags</span>${unsettledCount > 0 ? html `<span class="${alert}"><b>${unsettledCount}</b>unsettled</span>` : ""}${held > 0 ? html `<span class="${alert}"><b>${held}</b>standing disagreement${held > 1 ? "s" : ""}</span>` : ""}${state.inFlight ? html `<span class="stat"><b>1</b>ask in flight</span>` : ""}</div>
288
+ ]}</dl>${
289
+ // A running turn sweeps along the facts' top rule (app.css); a screen reader hears it instead.
290
+ state.inFlight ? html `<span class="sr-only">Navigator answering</span>` : ""}
291
+ ${shows([
292
+ ["ask", "Asks", state.asks.size],
293
+ ["opinion", "Opinions", opinions],
294
+ ["flag", "Flags", flags],
295
+ // Red, open or closed case alike: the case is not in order until every point is settled.
296
+ ["unsettled", "Unsettled", unsettled],
297
+ ])}
298
+ ${standingRow}
283
299
  </header>`;
284
300
  }
301
+ /**
302
+ * The timeline's filters, with the count each shows, styled as the index's state filters. A filter
303
+ * with nothing to show is left out, and with nothing to filter, so is the control. The page
304
+ * (static/app.js) keeps which one is pressed; the server renders "all", as a page just loaded is.
305
+ */
306
+ function shows(filters) {
307
+ const present = filters.filter(([, , n]) => n > 0);
308
+ if (present.length === 0)
309
+ return "";
310
+ const button = (tag, label) => html `<button type="button" class="label${tag === "unsettled" ? " is-unsettled" : ""}" data-show="${tag}" aria-pressed="${String(tag === "all")}">${label}</button>`;
311
+ return html `<div class="segmented shows" role="group" aria-label="Show in the timeline">${button("all", "All")}${present.map(([tag, label, n]) => button(tag, `${label} ${n}`))}</div>`;
312
+ }
285
313
  function brief(model) {
286
314
  const e = model.state.brief;
287
315
  if (!e)
@@ -341,7 +369,7 @@ function itemState(id, model) {
341
369
  : ""}`;
342
370
  }
343
371
  function entry(e, opts, body) {
344
- return html `<article class="entry${opts.service ? " service" : ""}${opts.notable ? " notable" : ""}" id="${opts.id}">
372
+ return html `<article class="entry${opts.service ? " service" : ""}${opts.notable ? " notable" : ""}" id="${opts.id}"${opts.tags?.length ? html ` data-tags="${opts.tags.join(" ")}"` : ""}>
345
373
  <div class="entry-time mono">${time(e.ts, "clock")}</div>
346
374
  <div class="entry-rail"><span class="marker ${opts.marker}"></span></div>
347
375
  <div class="entry-body">${body}</div>
@@ -374,7 +402,7 @@ function askEntry(e, model) {
374
402
  else {
375
403
  foot = html `<div class="card-foot">${ask?.attempts.length ? "the navigator is working…" : "queued"}</div>`;
376
404
  }
377
- return entry(e, { id: `ask-${String(e.askId)}`, marker: "driver" }, html `<div class="card">
405
+ return entry(e, { id: `ask-${String(e.askId)}`, marker: "driver", tags: ["ask"] }, html `<div class="card">
378
406
  ${cardHead("Driver", model.state.opened.driver, e.review ? "Review request" : "Ask", [html `<span class="mono">${e.askId}</span>`])}
379
407
  <div class="card-text">${e.review
380
408
  ? html `The navigator reviews the decisions awaiting it${targets.length ? html `: ${targets.map((t, i) => html `${i ? ", " : ""}${refFor(t.ref, model)}`)}` : ""}.`
@@ -385,14 +413,21 @@ ${foot}
385
413
  function opinionEntry(e, model) {
386
414
  const askId = String(e.askId);
387
415
  const isReview = model.state.asks.get(askId)?.event.review === true;
388
- const flags = flagsOf(e).map((flag) => html `<div class="flag" id="flag-${flag.id}"><span class="flag-id">${flag.id}</span><div class="flag-text">${prose(flag.body)}</div><div class="flag-status">${severityChip(flag.severity)}${itemState(flag.id, model)}</div></div>`);
416
+ const settled = (id) => model.items.get(id)?.status === "confirmed";
417
+ const points = [...flagsOf(e).map((f) => f.id), ...(model.items.has(askId) ? [askId] : [])];
418
+ const tags = [
419
+ "opinion",
420
+ ...(flagsOf(e).length ? ["flag"] : []),
421
+ ...(points.some((id) => !settled(id)) ? ["unsettled"] : []),
422
+ ];
423
+ const flags = flagsOf(e).map((flag) => html `<div class="flag" id="flag-${flag.id}"${settled(flag.id) ? raw(" data-settled") : ""}><span class="flag-id">${flag.id}</span><div class="flag-text">${prose(flag.body)}</div><div class="flag-status">${severityChip(flag.severity)}${itemState(flag.id, model)}</div></div>`);
389
424
  const limits = Array.isArray(e.limits) ? e.limits : [];
390
425
  const reviews = reviewsOf(e).map((r) => {
391
426
  // A review of a decision since replaced is history: it says nothing about the point now.
392
427
  const applied = model.items.get(r.ref)?.item.reviews.find((h) => h.opinionN === e.n)?.applied ?? false;
393
428
  return html `<div class="flag"><span class="flag-id">${refFor(r.ref, model)}</span><div class="flag-text">${prose(r.body)}</div><div class="flag-status"><span class="chip ${!applied ? "is-quiet" : r.status === "confirmed" ? "is-ok" : "is-alert"}">${r.status}</span>${applied ? "" : html `<span class="dim">of an earlier decision</span>`}</div></div>`;
394
429
  });
395
- return entry(e, { id: `ask-${askId}-opinion`, marker: "navigator" }, html `<div class="card navigator">
430
+ return entry(e, { id: `ask-${askId}-opinion`, marker: "navigator", tags }, html `<div class="card navigator">
396
431
  ${cardHead("Navigator", model.state.opened.navigator, isReview ? "Review" : "Opinion", [html `<span>re</span>`, ref(`#ask-${askId}`, e.askId)])}
397
432
  <div class="verdict"><span class="chip ${VERDICT_CLASS[String(e.verdict)] ?? ""}">${e.verdict}</span>${e.severity !== undefined ? severityChip(e.severity) : ""}${model.items.has(askId) ? itemState(askId, model) : ""}</div>
398
433
  <div class="card-text">${prose(e.body)}</div>
@@ -18,6 +18,7 @@
18
18
  --accent-weak: light-dark(#e8eefc, #16203a);
19
19
  --alert: light-dark(#9a3412, #e0a165);
20
20
  --alert-weak: light-dark(#fdf3ec, #221a12);
21
+ --danger: light-dark(#b42318, #f08a80);
21
22
  --ok: light-dark(#2f6b3f, #8cc79c);
22
23
  --ok-weak: light-dark(#eef6f0, #121c16);
23
24
 
@@ -188,6 +189,7 @@ button {
188
189
  }
189
190
 
190
191
  .side-case {
192
+ position: relative;
191
193
  display: block;
192
194
  padding: 8px 16px 8px 14px;
193
195
  border-left: 2px solid transparent;
@@ -249,8 +251,8 @@ tbody tr:hover .case-title {
249
251
  .page {
250
252
  --page-gap: 22px;
251
253
  --page-end: 96px;
252
- --entry-end: 16px;
253
- --service-end: 10px;
254
+ --entry-end: 6px;
255
+ --service-end: 6px;
254
256
  max-width: 1080px;
255
257
  margin: 0 auto;
256
258
  padding: 26px 32px var(--page-end);
@@ -282,6 +284,18 @@ tbody tr:hover .case-title {
282
284
  }
283
285
  }
284
286
 
287
+ /*
288
+ * A case page stacks its header, brief and timeline 12px apart, as the header stacks its rows; the
289
+ * top bar keeps the page's usual distance above them.
290
+ */
291
+ .page:has(> .case-head) {
292
+ --page-gap: 12px;
293
+
294
+ & > .topbar {
295
+ margin-bottom: 10px;
296
+ }
297
+ }
298
+
285
299
  .topbar {
286
300
  display: flex;
287
301
  align-items: center;
@@ -412,10 +426,6 @@ h1.title {
412
426
  letter-spacing: 0.06em;
413
427
  text-transform: uppercase;
414
428
  color: var(--ink-2);
415
-
416
- &.is-accent {
417
- color: var(--accent);
418
- }
419
429
  }
420
430
 
421
431
  /* ---------------------------------------------------------------- toolbar */
@@ -614,6 +624,7 @@ tbody td:first-child {
614
624
 
615
625
  /* Why the case page stopped updating: its log could not be read. */
616
626
  .message.problem {
627
+ margin: 0;
617
628
  padding: 10px 14px;
618
629
  border: 1px solid var(--alert);
619
630
  border-radius: 10px;
@@ -627,7 +638,7 @@ tbody td:first-child {
627
638
  .case-head {
628
639
  display: flex;
629
640
  flex-direction: column;
630
- gap: 14px;
641
+ gap: 12px;
631
642
  }
632
643
 
633
644
  /* An agent's mark sits on the text baseline and takes the surrounding ink: its file is a mask over
@@ -671,9 +682,11 @@ tbody td:first-child {
671
682
  }
672
683
 
673
684
  .facts {
685
+ position: relative;
674
686
  display: grid;
675
687
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
676
688
  gap: 12px 26px;
689
+ margin: 0;
677
690
  padding: 14px 0;
678
691
  border-top: 1px solid var(--line);
679
692
  border-bottom: 1px solid var(--line);
@@ -694,40 +707,138 @@ tbody td:first-child {
694
707
  }
695
708
  }
696
709
 
697
- .stats {
710
+ /* The timeline's filters, each with its count: a segmented control, as the index's. "Unsettled" is
711
+ red while it shows. */
712
+ .shows {
713
+ align-self: flex-start;
714
+ max-width: 100%;
715
+
716
+ & .is-unsettled {
717
+ &,
718
+ &:not([aria-pressed="true"]):hover {
719
+ color: var(--danger);
720
+ }
721
+
722
+ &[aria-pressed="true"] {
723
+ color: var(--bg);
724
+ background: var(--danger);
725
+ }
726
+ }
727
+ }
728
+
729
+ /* Too wide for a phone in one row: the segments wrap, each row filled, ruled like a grid. The
730
+ negative margins tuck each segment's outer rules under the control's own border. */
731
+ @media (max-width: 760px) {
732
+ .shows {
733
+ flex-wrap: wrap;
734
+
735
+ & button {
736
+ flex: 1 0 auto;
737
+ margin: 0 -1px -1px 0;
738
+ border-bottom: 1px solid var(--line);
739
+ }
740
+ }
741
+ }
742
+
743
+ .timeline[data-show="ask"] > .entry:not([data-tags~="ask"]),
744
+ .timeline[data-show="opinion"] > .entry:not([data-tags~="opinion"]),
745
+ .timeline[data-show="flag"] > .entry:not([data-tags~="flag"]),
746
+ .timeline[data-show="unsettled"] > .entry:not([data-tags~="unsettled"]) {
747
+ display: none;
748
+ }
749
+
750
+ /* Under "unsettled", a card keeps its settled flags for context, faded. */
751
+ .timeline[data-show="unsettled"] .flag[data-settled] {
752
+ opacity: 0.45;
753
+ }
754
+
755
+ /* The points left for the user, each a link to where it is shown. */
756
+ .standing {
698
757
  display: flex;
699
758
  flex-wrap: wrap;
700
- gap: 8px;
759
+ align-items: baseline;
760
+ gap: 4px 10px;
761
+ padding: 8px 12px;
762
+ border-left: 2px solid var(--danger);
763
+ border-radius: 0 7px 7px 0;
764
+ background: color-mix(in srgb, var(--danger) 8%, var(--bg));
765
+ font-size: 12.5px;
766
+
767
+ & .label {
768
+ color: var(--danger);
769
+ }
770
+
771
+ & .ref {
772
+ font-size: 12px;
773
+ color: var(--danger);
774
+ border-bottom-color: currentColor;
775
+ }
701
776
  }
702
777
 
703
- .stat {
704
- display: inline-flex;
705
- align-items: baseline;
706
- gap: 6px;
707
- padding: 5px 10px;
708
- border: 1px solid var(--line);
709
- border-radius: 7px;
710
- font-size: 11.5px;
711
- color: var(--ink-2);
778
+ /*
779
+ * A running turn: a highlight sweeps along a rule, the facts' top one on the case page and a line
780
+ * under the entry in the sidebar. Motion, not words, so nothing reflows when a turn starts or ends.
781
+ */
782
+ @keyframes live-sweep {
783
+ from {
784
+ background-position: -30% 0;
785
+ }
712
786
 
713
- & b {
714
- font-family: var(--font-mono);
715
- font-size: 13px;
716
- font-weight: 600;
717
- color: var(--ink);
787
+ to {
788
+ background-position: 130% 0;
718
789
  }
790
+ }
719
791
 
720
- &.is-alert {
721
- border-color: var(--alert);
722
- background: var(--alert-weak);
723
- color: var(--alert);
792
+ .facts.is-live::before,
793
+ .side-live {
794
+ content: "";
795
+ position: absolute;
796
+ height: 2px;
797
+ border-radius: 2px;
798
+ background: linear-gradient(90deg, transparent, var(--accent), transparent) no-repeat;
799
+ background-size: 25% 100%;
800
+ animation: live-sweep 1.6s ease-in-out infinite;
801
+ }
724
802
 
725
- & b {
726
- color: var(--alert);
727
- }
803
+ .facts.is-live::before {
804
+ left: 0;
805
+ right: 0;
806
+ top: -1px;
807
+ }
808
+
809
+ .side-live {
810
+ left: 14px;
811
+ right: 16px;
812
+ bottom: 3px;
813
+ }
814
+
815
+ @media (prefers-reduced-motion: reduce) {
816
+ .facts.is-live::before,
817
+ .side-live {
818
+ animation: none;
819
+ background-position: 50% 0;
820
+ }
821
+ }
822
+
823
+ /* Forced colors drop background images: the rule shows whole, in the system's highlight colour. */
824
+ @media (forced-colors: active) {
825
+ .facts.is-live::before,
826
+ .side-live {
827
+ animation: none;
828
+ background: Highlight;
728
829
  }
729
830
  }
730
831
 
832
+ /* Text for screen readers only, where the page shows the same thing without words. */
833
+ .sr-only {
834
+ position: absolute;
835
+ width: 1px;
836
+ height: 1px;
837
+ overflow: hidden;
838
+ clip-path: inset(50%);
839
+ white-space: nowrap;
840
+ }
841
+
731
842
  /* ---------------------------------------------------------------- brief */
732
843
 
733
844
  .brief {
@@ -769,9 +880,15 @@ tbody td:first-child {
769
880
  * reads top-down in one column — no left/right chat split — and says who posted it in its
770
881
  * header: the role, the agent, the kind.
771
882
  */
883
+ /*
884
+ * Every entry pads 6px above and below its content, so any two entries stand 12px apart, card or
885
+ * service line. The timeline takes back the first entry's top padding, so it starts 12px under the
886
+ * brief, as the brief starts under the header.
887
+ */
772
888
  .timeline {
773
889
  display: flex;
774
890
  flex-direction: column;
891
+ margin-top: -6px;
775
892
  }
776
893
 
777
894
  .entry {
@@ -1061,29 +1178,26 @@ tbody td:first-child {
1061
1178
 
1062
1179
  /* ---------------------------------------------------------------- service events */
1063
1180
 
1064
- /*
1065
- * Bookkeeping, not conversation: one quiet line on the rail. A card entry ends with 16px; a
1066
- * service line ends with 10px and starts flush, so the space above and below it matches.
1067
- */
1181
+ /* Bookkeeping, not conversation: one quiet line on the rail, padded as a card is. */
1068
1182
  .entry.service .entry-time {
1069
- padding-top: 1px;
1183
+ padding-top: 7px;
1070
1184
  }
1071
1185
 
1072
1186
  .entry.service .entry-body {
1073
- padding: 0 0 var(--service-end);
1187
+ padding: 6px 0 var(--service-end);
1074
1188
  }
1075
1189
 
1076
1190
  .entry.service .marker {
1077
- top: 5px;
1191
+ top: 11px;
1078
1192
  }
1079
1193
 
1080
1194
  /* The rail starts and ends at the marker's centre. */
1081
1195
  .entry.service:first-child .entry-rail::before {
1082
- top: 9px;
1196
+ top: 15px;
1083
1197
  }
1084
1198
 
1085
1199
  .entry.service:last-child .entry-rail::before {
1086
- bottom: calc(100% - 9px);
1200
+ bottom: calc(100% - 15px);
1087
1201
  }
1088
1202
 
1089
1203
  /* Always one line: a detail too long for it ends in an ellipsis, and the line's title holds it all. */
@@ -1145,10 +1259,11 @@ tbody td:first-child {
1145
1259
  grid-row: 1 / span 2;
1146
1260
  }
1147
1261
 
1262
+ /* The time row leads the entry: it takes the 6px a card's top would, so entries stay 12px apart. */
1148
1263
  .entry-time {
1149
1264
  grid-column: 2;
1150
1265
  grid-row: 1;
1151
- padding-top: 8px;
1266
+ padding-top: 6px;
1152
1267
  text-align: left;
1153
1268
  line-height: 1.4;
1154
1269
  }
@@ -1160,11 +1275,11 @@ tbody td:first-child {
1160
1275
  }
1161
1276
 
1162
1277
  .marker {
1163
- top: 10px;
1278
+ top: 8px;
1164
1279
  }
1165
1280
 
1166
1281
  .entry:first-child .entry-rail::before {
1167
- top: 12px;
1282
+ top: 10px;
1168
1283
  }
1169
1284
 
1170
1285
  /* A service line keeps its time on the same line, ahead of the text. */
@@ -36,14 +36,83 @@ function times() {
36
36
  /* ---------------------------------------------------------------- live case */
37
37
 
38
38
  const timeline = document.getElementById("timeline");
39
+
40
+ /**
41
+ * The timeline filter the page shows. CSS hides the entries whose data-tags lack it, so streamed
42
+ * entries follow it too. A filter whose button is gone, such as "unsettled" once every point is
43
+ * settled, falls back to all.
44
+ */
45
+ let shown = "all";
46
+ function show(tag) {
47
+ const buttons = [...document.querySelectorAll("button[data-show]")];
48
+ shown = buttons.some((b) => b.dataset.show === tag) ? tag : "all";
49
+ for (const b of buttons) b.setAttribute("aria-pressed", String(b.dataset.show === shown));
50
+ if (shown === "all") delete timeline.dataset.show;
51
+ else timeline.dataset.show = shown;
52
+ }
53
+
54
+ /**
55
+ * Clears the URL's anchor, and with it the highlight of the entry it names: a filter change leaves
56
+ * that entry behind. replaceState alone keeps :target, so an empty fragment clears it first; it
57
+ * would scroll to the top, so the scroll position is put back.
58
+ */
59
+ function dropAnchor() {
60
+ if (!location.hash) return;
61
+ const y = scrollY;
62
+ location.replace("#");
63
+ scrollTo(scrollX, y);
64
+ history.replaceState(null, "", location.pathname + location.search);
65
+ }
66
+
67
+ /** The element a fragment names: its id as written, else percent-decoded, as the browser looks it up. */
68
+ function anchored(hash) {
69
+ const id = hash.slice(1);
70
+ if (!id) return null;
71
+ try {
72
+ return document.getElementById(id) ?? document.getElementById(decodeURIComponent(id));
73
+ } catch {
74
+ return null;
75
+ }
76
+ }
77
+
78
+ const hidden = (element) => element.getClientRects().length === 0;
79
+
80
+ /** Shows everything when the filter hides `target`; reports whether it did. */
81
+ function reveal(target) {
82
+ if (shown === "all" || !target || !hidden(target)) return false;
83
+ show("all");
84
+ return true;
85
+ }
86
+
39
87
  if (timeline) {
88
+ document.addEventListener("click", (event) => {
89
+ const button = event.target.closest("button[data-show]");
90
+ if (button) {
91
+ show(button.dataset.show);
92
+ dropAnchor();
93
+ }
94
+ // Before the browser follows the link, so it can scroll to the target.
95
+ const link = event.target.closest('a[href^="#"]');
96
+ if (link) reveal(anchored(link.hash));
97
+ });
98
+ // Back and Forward reach an anchor without a click: the browser found the target hidden, so the
99
+ // page scrolls to it once it shows.
100
+ addEventListener("hashchange", () => {
101
+ const target = anchored(location.hash);
102
+ if (reveal(target)) target.scrollIntoView();
103
+ });
104
+
40
105
  /** Near the bottom: the reader is following the case, not reading back. */
41
106
  const following = () => innerHeight + scrollY >= document.documentElement.scrollHeight - 160;
42
107
  const stream = new EventSource(timeline.dataset.stream);
43
108
  stream.addEventListener("patch", ({ data }) => {
44
109
  const follow = following();
45
110
  apply(data, timeline);
46
- if (follow) timeline.lastElementChild?.scrollIntoView({ behavior: "smooth", block: "end" });
111
+ // A patch may replace the header, and its filters with it.
112
+ show(shown);
113
+ // The last entry the filter shows, not the last one streamed.
114
+ const last = [...timeline.children].findLast((entry) => !hidden(entry));
115
+ if (follow) last?.scrollIntoView({ behavior: "smooth", block: "end" });
47
116
  });
48
117
  // While the case's log cannot be read, the page does not update: it says why. Empty data clears it.
49
118
  const problem = document.querySelector("[data-problem]");
@@ -124,6 +193,10 @@ async function exportCase(caseId) {
124
193
  node.removeAttribute("data-stream");
125
194
  node.removeAttribute("data-refresh");
126
195
  }
196
+ // The file has no script to filter with: it keeps every entry, and its filters only count.
197
+ page.querySelector("#timeline")?.removeAttribute("data-show");
198
+ for (const b of page.querySelectorAll("button[data-show]"))
199
+ b.setAttribute("aria-pressed", String(b.dataset.show === "all"));
127
200
  for (const time of page.querySelectorAll("time[datetime]")) {
128
201
  time.textContent = utc(time.dateTime, time.dataset.format);
129
202
  time.removeAttribute("title");
@@ -274,20 +347,19 @@ let filter = document.querySelector("[data-cases]")?.dataset.filterState ?? "ope
274
347
  function filterCases() {
275
348
  if (!search) return;
276
349
  const rows = [...document.querySelectorAll("#case-rows tr")];
277
- const inState = rows.filter((r) => r.dataset.state === filter);
350
+ const inFilter = (row, name) => name === "all" || row.dataset.state === name;
351
+ const inState = rows.filter((r) => inFilter(r, filter));
278
352
  const needle = search.value.trim().toLowerCase();
279
353
  let shown = 0;
280
354
  for (const row of rows) {
281
- row.hidden = !(row.dataset.state === filter && row.dataset.haystack.includes(needle));
355
+ row.hidden = !(inFilter(row, filter) && row.dataset.haystack.includes(needle));
282
356
  if (!row.hidden) shown++;
283
357
  }
284
358
  document.querySelector("[data-cases]").dataset.filterState = filter;
285
359
  for (const button of document.querySelectorAll("[data-filter]")) {
286
360
  const name = button.dataset.filter;
287
361
  button.setAttribute("aria-pressed", String(name === filter));
288
- button.querySelector("[data-count]").textContent = rows.filter(
289
- (r) => r.dataset.state === name,
290
- ).length;
362
+ button.querySelector("[data-count]").textContent = rows.filter((r) => inFilter(r, name)).length;
291
363
  }
292
364
  document.querySelector("[data-result-count]").textContent = `${shown} / ${inState.length}`;
293
365
  const message = document.querySelector("[data-message]");
@@ -5,7 +5,7 @@ import { adapters, findAdapter, getNavigator, preferredNavigator, selectableNavi
5
5
  import { loadConfig } from "../config.js";
6
6
  import { processAlive, startTime } from "../lib/proc.js";
7
7
  import { SIDECAR_VERSION } from "../lib/version.js";
8
- import { awaitingReview, flagsOf, itemStatus, reviewsOf, reviewTargetsOf, unsettled, } from "../cases/items.js";
8
+ import { awaitingReview, flagsOf, itemStatus, reviewsOf, reviewsSpent, reviewTargetsOf, unsettled, } from "../cases/items.js";
9
9
  import { caseStatus, fold } from "../cases/state.js";
10
10
  import { Store } from "../cases/store.js";
11
11
  import { cancelTurn, dispatchAsk, reconcile, waitForOutcome, } from "../turns/dispatch.js";
@@ -301,13 +301,13 @@ export class SidecarServer {
301
301
  return;
302
302
  const reviewBudget = this.#reviewBudget();
303
303
  if (awaitingReview(s.items, reviewBudget).length === 0)
304
- throw new NothingToReview(this.#unsettled(s, reviewBudget));
304
+ throw new NothingToReview(this.#unsettled(s, reviewBudget), reviewBudget);
305
305
  });
306
306
  return { caseId, dispatched };
307
307
  }
308
308
  catch (err) {
309
309
  if (err instanceof NothingToReview)
310
- return { caseId, nothing: nothingToReview(err.unsettled) };
310
+ return { caseId, nothing: nothingToReview(err.unsettled, err.budget) };
311
311
  throw err;
312
312
  }
313
313
  });
@@ -354,9 +354,10 @@ export class SidecarServer {
354
354
  if (result.status === "failed" &&
355
355
  foundNothingToReview(e) &&
356
356
  state.asks.get(String(e.askId))?.event.review) {
357
+ const budget = this.#reviewBudget();
357
358
  return {
358
359
  case_id: caseId,
359
- ...nothingToReview(this.#unsettled(state)),
360
+ ...nothingToReview(this.#unsettled(state, budget), budget),
360
361
  ask_id: String(e.askId),
361
362
  };
362
363
  }
@@ -415,21 +416,19 @@ export class SidecarServer {
415
416
  const reviewBudget = this.#reviewBudget();
416
417
  const n = Array.isArray(input.ref) ? recorded.map((r) => r.n) : recorded[0].n;
417
418
  const many = (list, one, more) => (list.length > 1 ? more : one);
418
- if (input.state === "planned" && points.length > 0) {
419
- const planned = points.map((i) => i.ref);
420
- return {
421
- n,
422
- next: `${planned.join(", ")} ${many(planned, "is", "are")} planned: the navigator does not review ${many(planned, "it", "them")} until you record a ready decision on ${many(planned, "it", "them")}.`,
423
- };
419
+ const spent = points.filter((i) => reviewsSpent(i, reviewBudget)).map((i) => i.ref);
420
+ const next = [];
421
+ if (input.state === "planned") {
422
+ const planned = points.filter((i) => !reviewsSpent(i, reviewBudget)).map((i) => i.ref);
423
+ if (planned.length > 0)
424
+ next.push(`${planned.join(", ")} ${many(planned, "is", "are")} planned: the navigator does not review ${many(planned, "it", "them")} until you record a ready decision on ${many(planned, "it", "them")}.`);
425
+ if (spent.length > 0)
426
+ next.push(`${spent.join(", ")} ${many(spent, "has", "have")} used ${many(spent, "its", "their")} ${reviewCount(reviewBudget)}; the navigator will not review ${many(spent, "it", "them")} again. Once the change exists, tell the user ${many(spent, "it is", "they are")} left for them.`);
424
427
  }
425
- const spent = points.filter((i) => i.reviewTurns >= reviewBudget).map((i) => i.ref);
426
- if (spent.length > 0) {
427
- return {
428
- n,
429
- next: `${spent.join(", ")} ${many(spent, "has", "have")} used ${many(spent, "its", "their")} ${reviewBudget} reviews; the navigator will not review this decision. Tell the user ${many(spent, "it is", "they are")} left for them.`,
430
- };
428
+ else if (spent.length > 0) {
429
+ next.push(`${spent.join(", ")} ${many(spent, "has", "have")} used ${many(spent, "its", "their")} ${reviewCount(reviewBudget)}; the navigator will not review this decision. Tell the user ${many(spent, "it is", "they are")} left for them.`);
431
430
  }
432
- return { n };
431
+ return next.length > 0 ? { n, next: next.join(" ") } : { n };
433
432
  });
434
433
  }
435
434
  async read(input) {
@@ -722,32 +721,40 @@ function renderOpinion(e, state, budget) {
722
721
  for (const r of reviews.filter((r) => current(r) && r.status === "held")) {
723
722
  next.push(`Tell the user now: the navigator holds its point on ${r.ref} against your decision; its reason is in reviews. The user may decide.`);
724
723
  }
725
- for (const r of reviews.filter((r) => current(r) && r.status === "reopened")) {
726
- next.push(`The navigator reopened ${r.ref}; what is missing is in reviews. Record a new decision with ref=${r.ref}, or leave it for the user.`);
727
- }
728
- // A newer decision may have been recorded during the turn: say what each point awaits now.
724
+ // A reopened point with its reviews spent cannot be settled by another decision: it escalates.
729
725
  const now = (ref) => {
730
726
  const item = state.items.get(ref);
731
727
  return item ? itemStatus(item, budget) : undefined;
732
728
  };
729
+ for (const r of reviews.filter((r) => current(r) && r.status === "reopened")) {
730
+ next.push(now(r.ref) === "exhausted"
731
+ ? `The navigator reopened ${r.ref}, and it has used its ${reviewCount(budget)}: it is left for the user. Tell the user now, with both positions; do not decide it again.`
732
+ : `The navigator reopened ${r.ref}; what is missing is in reviews. Record a new decision with ref=${r.ref}, or leave it for the user.`);
733
+ }
734
+ // A newer decision may have been recorded during the turn: say what each point awaits now.
733
735
  const stale = reviews.filter((r) => !current(r)).map((r) => r.ref);
734
736
  if (stale.length > 0) {
735
- next.push(`The navigator reviewed an earlier decision on ${stale.join(", ")}, not your newer one; ${awaits(stale, now)}`);
737
+ next.push(`The navigator reviewed an earlier decision on ${stale.join(", ")}, not your newer one; ${awaits(stale, state, budget)}`);
736
738
  }
737
739
  const omitted = targets.map((t) => t.ref).filter((ref) => !reviews.some((r) => r.ref === ref));
738
740
  if (omitted.length > 0)
739
- next.push(`The navigator did not review ${omitted.join(", ")}; ${awaits(omitted, now)}`);
741
+ next.push(`The navigator did not review ${omitted.join(", ")}; ${awaits(omitted, state, budget)}`);
740
742
  // Without a decision that refs its id, an item stays open: on the dashboard and in a re-brief seed.
741
- if (!isReview) {
742
- const point = state.items.has(askId) ? [askId] : [];
743
- const refs = [...point, ...flagIds];
744
- next.push(refs.length > 0
745
- ? `Record a decision on each point with sidecar_record kind=decision (${refs.join(", ")}); one decision may name several refs when it settles them the same way. The navigator reviews each point.`
746
- : `Record your decision on the opinion with sidecar_record kind=decision ref=${askId}.`);
747
- }
748
- else if (flagIds.length > 0) {
749
- next.push(`Record a decision on each new point with sidecar_record kind=decision (${flagIds.join(", ")}).`);
750
- }
743
+ // A replayed result reads the current state: a point decided since needs no new decision, and one
744
+ // left for the user must not get one.
745
+ const raised = [...(!isReview && state.items.has(askId) ? [askId] : []), ...flagIds];
746
+ const toDecide = raised.filter((ref) => now(ref) === "open");
747
+ const left = raised.filter((ref) => now(ref) === "exhausted");
748
+ if (!isReview && raised.length === 0) {
749
+ next.push(`Record your decision on the opinion with sidecar_record kind=decision ref=${askId}.`);
750
+ }
751
+ else if (toDecide.length > 0) {
752
+ next.push(isReview
753
+ ? `Record a decision on each new point with sidecar_record kind=decision (${toDecide.join(", ")}).`
754
+ : `Record a decision on each point with sidecar_record kind=decision (${toDecide.join(", ")}); one decision may name several refs when it settles them the same way. The navigator reviews each point.`);
755
+ }
756
+ if (left.length > 0)
757
+ next.push(awaits(left, state, budget));
751
758
  const waiting = awaitingReview(state.items, budget).map((i) => i.ref);
752
759
  if (waiting.length > 0) {
753
760
  next.push(`Awaiting the navigator's review: ${waiting.join(", ")}. They ride along with your next ask, or call sidecar_review before sidecar_close.`);
@@ -764,37 +771,65 @@ function renderOpinion(e, state, budget) {
764
771
  next: next.join(" "),
765
772
  };
766
773
  }
774
+ const reviewCount = (budget) => `${budget} ${budget === 1 ? "review" : "reviews"}`;
767
775
  /** Where each point stands now, for a review that did not settle it. */
768
- function awaits(refs, now) {
776
+ function awaits(refs, state, budget) {
769
777
  return (refs
770
778
  .map((ref) => {
771
- const status = now(ref);
779
+ const item = state.items.get(ref);
780
+ const status = item ? itemStatus(item, budget) : undefined;
781
+ if (status === "exhausted")
782
+ return `${ref} has used its ${reviewCount(budget)} and is left for the user: tell the user now`;
772
783
  if (status === "addressed")
773
784
  return `${ref} still awaits review`;
774
785
  if (status === "planned")
775
- return `${ref} is planned: it is not reviewed until you record a ready decision on it`;
786
+ return reviewsSpent(item, budget)
787
+ ? `${ref} is planned and has used its ${reviewCount(budget)}: once the change exists, it is left for the user`
788
+ : `${ref} is planned: it is not reviewed until you record a ready decision on it`;
776
789
  return `${ref} is ${status ?? "unknown"}`;
777
790
  })
778
791
  .join("; ") + ".");
779
792
  }
780
- /** A review with nothing to do. Planned points are why, when there are some: the driver may not know. */
781
- function nothingToReview(left) {
782
- const planned = left.filter((i) => i.status === "planned").map((i) => i.ref);
793
+ /**
794
+ * A review with nothing to do, and why, when the driver may not know: points left for the user,
795
+ * which no review settles, and planned points, which wait for a ready decision.
796
+ */
797
+ function nothingToReview(left, budget) {
798
+ const exhausted = left.filter((i) => i.status === "exhausted").map((i) => i.ref);
799
+ const planned = left.filter((i) => i.status === "planned");
800
+ const reviewable = planned.filter((i) => i.reviews_used < budget).map((i) => i.ref);
801
+ const spent = planned.filter((i) => i.reviews_used >= budget).map((i) => i.ref);
802
+ const are = (refs) => (refs.length > 1 ? "are" : "is");
803
+ const next = [
804
+ ...(exhausted.length > 0
805
+ ? [
806
+ `${exhausted.join(", ")} ${are(exhausted)} left for the user: no review can settle ${exhausted.length > 1 ? "them" : "it"}. Tell the user now.`,
807
+ ]
808
+ : []),
809
+ ...(reviewable.length > 0
810
+ ? [
811
+ `${reviewable.join(", ")} ${are(reviewable)} planned: record a ready decision once the change exists, then review.`,
812
+ ]
813
+ : []),
814
+ ...(spent.length > 0
815
+ ? [
816
+ `${spent.join(", ")} ${are(spent)} planned with ${spent.length > 1 ? "their" : "its"} ${reviewCount(budget)} used: once the change exists, ${spent.length > 1 ? "they are" : "it is"} left for the user.`,
817
+ ]
818
+ : []),
819
+ ];
783
820
  return {
784
821
  status: "nothing-to-review",
785
822
  unsettled: left,
786
- ...(planned.length > 0
787
- ? {
788
- next: `${planned.join(", ")} ${planned.length > 1 ? "are" : "is"} planned: record a ready decision once the change exists, then review.`,
789
- }
790
- : {}),
823
+ ...(next.length > 0 ? { next: next.join(" ") } : {}),
791
824
  };
792
825
  }
793
826
  /** Thrown inside the dispatch transaction when a review turn would have nothing to review. */
794
827
  class NothingToReview extends Error {
795
828
  unsettled;
796
- constructor(unsettled) {
829
+ budget;
830
+ constructor(unsettled, budget) {
797
831
  super("nothing awaits review");
798
832
  this.unsettled = unsettled;
833
+ this.budget = budget;
799
834
  }
800
835
  }
@@ -22,14 +22,15 @@ When to use it
22
22
  The loop
23
23
  1. sidecar_open with a brief that stands alone. Share the dashboard link with the user once.
24
24
  2. sidecar_ask one question at a time. Do not act on it until the outcome arrives.
25
- 3. Decide every point the result's next names, with sidecar_record kind=decision: what you accept, reject or defer, and why. Never drop a point silently. Before you accept a point that matters, read the cited lines yourself.
26
- 4. The navigator reviews your decisions with your next ask, or with sidecar_review when no ask is coming. A point is settled only when the navigator confirms your decision. On reopened, decide again or leave the point for the user.
25
+ 3. Decide every point the result's next asks you to decide, with sidecar_record kind=decision: what you accept, reject or defer, and why. Never drop a point silently. Before you accept a point that matters, read the cited lines yourself.
26
+ 4. The navigator reviews your decisions with your next ask, or with sidecar_review when no ask is coming. A point is settled only when the navigator confirms your decision. On reopened, decide again or leave the point for the user. Each point gets a limited number of reviews; a point that used them unsettled is left for the user: do not decide it again.
27
27
  5. Close the case with sidecar_close when the work is done; before that, call sidecar_review if decisions still await the navigator. When the same work continues later, a review round on the same PR included, sidecar_attach the case again, closed or not; a new problem gets a new case.
28
28
 
29
29
  Tell the user
30
30
  - On failed: "navigator unavailable: <outcome>, proceeding". Then continue without the opinion, and record your own conclusion as a note with ref=<ask id>.
31
31
  - On held: the navigator stands by a point you rejected. Tell the user at once, with both positions, so they can intervene; do not argue it further.
32
- - The points left for the user, the confirmed deferrals (they stay listed, not settled), and the points sidecar_close lists as unsettled.
32
+ - On a point left for the user: you and the navigator did not settle it within its reviews. Tell the user at once, with both positions, as for held.
33
+ - The confirmed deferrals (they stay listed, not settled), and the points sidecar_close lists as unsettled.
33
34
  - In your report, where the navigator disagreed with you and what you did about it. Report the case state accurately, for example "design agreed; implementation pending": do not say the navigator agrees while its points are open, planned or reopened.`;
34
35
  const text = z.string().trim().min(1, "must be a non-empty string");
35
36
  const upTo = (max) => text.max(max, `must be at most ${max} characters`);
@@ -1,5 +1,5 @@
1
1
  import { DEFAULTS } from "../config.js";
2
- import { decisionState, unsettled } from "../cases/items.js";
2
+ import { decisionState, itemStatus, unsettled } from "../cases/items.js";
3
3
  const ROLE = `You are the navigator in a sidecar case. The driver, another coding agent, works on a task in this workspace and asks you for an independent opinion, one question at a time. You are read-only: you read and search; you never change anything.
4
4
 
5
5
  How to work
@@ -50,7 +50,7 @@ export function buildPrompt(state, ask, opts) {
50
50
  const review = opts.review ?? [];
51
51
  // A decision under review is shown with its item, not a second time among the updates.
52
52
  const shown = new Set(review.map((i) => i.decision.n));
53
- const { head, tail, parts } = layout(state, ask, opts.fresh, opts.rebrief ?? false, review, shown, opts.git);
53
+ const { head, tail, parts } = layout(state, ask, opts.fresh, opts.rebrief ?? false, review, shown, opts.git, opts.reviewBudget ?? DEFAULTS.reviewBudget);
54
54
  const size = fixedSize(head, tail, parts);
55
55
  if (size > bound)
56
56
  return { ok: false, size, bound };
@@ -83,10 +83,11 @@ export function buildPrompt(state, ask, opts) {
83
83
  * re-brief, the larger of the two prompts, so the targets claimed for the turn fit either.
84
84
  */
85
85
  export function reviewRoom(state, ask, bound, git) {
86
- const { head, tail, parts } = layout(state, ask, true, true, [], new Set(), git);
86
+ // The budget only labels entries, which the fixed size does not count.
87
+ const { head, tail, parts } = layout(state, ask, true, true, [], new Set(), git, DEFAULTS.reviewBudget);
87
88
  return bound - fixedSize(head, tail, parts) - "\n\n".length;
88
89
  }
89
- function layout(state, ask, fresh, rebrief, review, shown, git) {
90
+ function layout(state, ask, fresh, rebrief, review, shown, git, budget) {
90
91
  // A resumed session raised every point after its start itself; a fresh one holds none.
91
92
  const reviewSection = renderReview(review, fresh ? undefined : (i) => i.raisedN > state.sessionStart);
92
93
  const tail = [
@@ -147,7 +148,7 @@ function layout(state, ask, fresh, rebrief, review, shown, git) {
147
148
  {
148
149
  title: "Your points not yet settled",
149
150
  entries: pending.map((i) => ({
150
- text: `- [${i.ref}] ${[i.status, i.severity].filter((v) => v !== undefined).join(", ")}: ${capped(i.point)}`,
151
+ text: `- [${i.ref}] ${[pendingStatus(i, budget), i.severity].filter((v) => v !== undefined).join(", ")}: ${capped(i.point)}`,
151
152
  n: i.raisedN,
152
153
  seeded: [i.raisedN],
153
154
  })),
@@ -157,6 +158,11 @@ function layout(state, ask, fresh, rebrief, review, shown, git) {
157
158
  ]),
158
159
  };
159
160
  }
161
+ /** A point the review budget left for the user says so: no review of it is coming. */
162
+ const pendingStatus = (item, budget) => {
163
+ const status = itemStatus(item, budget);
164
+ return status === "exhausted" ? "left for the user" : status;
165
+ };
160
166
  const nonEmpty = (parts) => parts.filter((p) => p.entries.length > 0);
161
167
  /**
162
168
  * The case's workspace is the navigator's working directory, but a navigator does not assume it,
@@ -212,6 +212,7 @@ async function fresh(isRebrief) {
212
212
  bound: config.seedBound,
213
213
  review,
214
214
  git,
215
+ reviewBudget: config.reviewBudget,
215
216
  });
216
217
  if (!prompt.ok)
217
218
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lysyi3m/sidecar",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "description": "Lets one coding agent consult another mid-task: a driver asks, a read-only navigator answers",
5
5
  "license": "MIT",
6
6
  "repository": {