samagotchi 0.166.0 → 0.167.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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +63 -1
  3. data/docs/architecture.md +1 -0
  4. data/docs/cli.md +10 -5
  5. data/docs/configuration.md +1 -0
  6. data/docs/guardrails.md +6 -5
  7. data/docs/hooks.md +4 -6
  8. data/docs/internals/bundles.md +2 -4
  9. data/docs/internals/engine.md +4 -5
  10. data/docs/internals/objectives.md +141 -9
  11. data/docs/internals/remote-sessions.md +5 -6
  12. data/docs/internals/web-frontend.md +30 -25
  13. data/docs/memory.md +1 -2
  14. data/docs/sessions.md +20 -2
  15. data/docs/testing.md +4 -3
  16. data/lib/samagotchi/bridge.rb +1 -1
  17. data/lib/samagotchi/bundle_command/installed_check.rb +2 -14
  18. data/lib/samagotchi/bundle_command.rb +19 -11
  19. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  20. data/lib/samagotchi/cli/command.rb +10 -0
  21. data/lib/samagotchi/compat.rb +3 -11
  22. data/lib/samagotchi/config.rb +3 -0
  23. data/lib/samagotchi/context_command.rb +2 -1
  24. data/lib/samagotchi/engine/objectives.rb +20 -1
  25. data/lib/samagotchi/engine/side_requests.rb +3 -2
  26. data/lib/samagotchi/engine/turn_end.rb +4 -1
  27. data/lib/samagotchi/engine.rb +3 -0
  28. data/lib/samagotchi/extension_load.rb +2 -26
  29. data/lib/samagotchi/guardrails/approvals.rb +36 -13
  30. data/lib/samagotchi/jsonl_store.rb +61 -0
  31. data/lib/samagotchi/memory_bundle/status.rb +3 -15
  32. data/lib/samagotchi/memory_bundle/system_bundle.rb +16 -10
  33. data/lib/samagotchi/memory_command.rb +4 -2
  34. data/lib/samagotchi/objectives.rb +43 -14
  35. data/lib/samagotchi/objectives_backing.rb +124 -0
  36. data/lib/samagotchi/objectives_check.rb +19 -126
  37. data/lib/samagotchi/objectives_command.rb +14 -7
  38. data/lib/samagotchi/objectives_record.rb +104 -0
  39. data/lib/samagotchi/objectives_track.rb +353 -0
  40. data/lib/samagotchi/push_command.rb +2 -1
  41. data/lib/samagotchi/remote_command.rb +2 -1
  42. data/lib/samagotchi/reply_wait/poll.rb +6 -6
  43. data/lib/samagotchi/reply_wait.rb +4 -24
  44. data/lib/samagotchi/schedule_command.rb +6 -0
  45. data/lib/samagotchi/schedules.rb +1 -1
  46. data/lib/samagotchi/session_access/remote.rb +3 -5
  47. data/lib/samagotchi/session_commands.rb +1 -1
  48. data/lib/samagotchi/sessions_command.rb +12 -6
  49. data/lib/samagotchi/share_command.rb +2 -1
  50. data/lib/samagotchi/tool_activity.rb +11 -1
  51. data/lib/samagotchi/tool_declarations.rb +5 -1
  52. data/lib/samagotchi/tools/objectives_tool.rb +19 -2
  53. data/lib/samagotchi/turn_stages/objectives.rb +46 -3
  54. data/lib/samagotchi/version.rb +1 -1
  55. data/lib/samagotchi/web/participant_access.rb +1 -1
  56. data/lib/samagotchi/web/public/app.js +52 -424
  57. data/lib/samagotchi/web/public/copy.js +2 -1
  58. data/lib/samagotchi/web/public/index.html +35 -9
  59. data/lib/samagotchi/web/public/info_bar_model.js +3 -1
  60. data/lib/samagotchi/web/public/no_contact_fill.js +29 -0
  61. data/lib/samagotchi/web/public/objectives.css +14 -0
  62. data/lib/samagotchi/web/public/objectives_moves.js +82 -9
  63. data/lib/samagotchi/web/public/objectives_state.js +42 -0
  64. data/lib/samagotchi/web/public/objectives_strip.js +33 -9
  65. data/lib/samagotchi/web/public/objectives_track.js +52 -0
  66. data/lib/samagotchi/web/public/objectives_wiring.js +16 -1
  67. data/lib/samagotchi/web/public/participant.html +1 -1
  68. data/lib/samagotchi/web/public/participants_panel.js +14 -7
  69. data/lib/samagotchi/web/public/question_cards.js +7 -12
  70. data/lib/samagotchi/web/public/resync_reach.js +10 -6
  71. data/lib/samagotchi/web/public/scope.js +3 -3
  72. data/lib/samagotchi/web/public/session_rename.js +6 -2
  73. data/lib/samagotchi/web/public/session_state.js +1 -1
  74. data/lib/samagotchi/web/public/session_sync.js +249 -0
  75. data/lib/samagotchi/web/public/session_view.js +279 -0
  76. data/lib/samagotchi/web/public/stream_handlers.js +1 -1
  77. data/lib/samagotchi/web/public/tokens.css +2 -2
  78. data/lib/samagotchi/web/public/turn_block.js +8 -0
  79. data/lib/samagotchi/web/public/turn_html.js +1 -1
  80. data/lib/samagotchi/web/public/widget_picks.js +3 -0
  81. data/lib/samagotchi/web/public/working_set_view.js +1 -1
  82. data/lib/samagotchi/web/session_access_routes.rb +4 -15
  83. metadata +10 -1
@@ -10,7 +10,11 @@
10
10
  <meta name="apple-mobile-web-app-title" content="Chi">
11
11
  <!-- viewport-fit=cover: the page runs under the notch and the home indicator; what must stay clear of them pads by --safe-* (below). -->
12
12
  <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
13
- <!-- The phone's status bar and Safari's toolbar take the page's own background (tokens.css --bg), per theme. -->
13
+ <!-- The phone's status bar and Safari's toolbar take the page's own background, per theme: on a phone (600px and less) the
14
+ colour its top edge starts with (tokens.css --bg-top, the top bar's tint), so the status bar and the bar under it are one
15
+ surface; elsewhere --bg. The first meta that matches wins. -->
16
+ <meta name="theme-color" content="#131d29" media="(prefers-color-scheme: dark) and (max-width: 600px)">
17
+ <meta name="theme-color" content="#dde8f4" media="(prefers-color-scheme: light) and (max-width: 600px)">
14
18
  <meta name="theme-color" content="#0b0d11" media="(prefers-color-scheme: dark)">
15
19
  <meta name="theme-color" content="#f5f6f8" media="(prefers-color-scheme: light)">
16
20
  <link rel="stylesheet" href="/assets/tokens.css">
@@ -30,6 +34,12 @@
30
34
  /* No iOS text autosizing: it grows text in a box sized for the text as written (it clipped the session cards). */
31
35
  html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
32
36
  body{font-family: ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;background:radial-gradient(1100px 700px at 8% 0%,color-mix(in srgb,var(--accent) 13%,transparent),transparent 70%),var(--bg);background-attachment:fixed;color:var(--text);height:100vh;height:100dvh;display:flex;flex-direction:column}
37
+ /* A phone: the accent's tint runs down from the top edge, flat across it (--bg-top, the status bar's theme-color above),
38
+ not from the top-left corner: the status bar, which iOS paints in theme-color (the Home Screen app) or over the page's
39
+ top (a Safari tab), meets the top bar with no seam. The colour layer under the gradient is never seen in the page
40
+ (the gradient covers the body): it is the body's background-color, which is what iOS 26's Home Screen app paints
41
+ the status bar strip in (not theme-color, not html's background; with no colour the strip is black). */
42
+ @media(max-width:600px){body{background:linear-gradient(var(--bg-top),var(--bg) 420px),var(--bg-top)}}
33
43
  /* Glass: the composer card, the strip cards, the all-sessions cards and the question cards (by selector, so app.js is untouched). */
34
44
  .turn-stage,#topStrip .card,#allList .card,.bubble.question,.bubble.plugin-card{background:var(--glass-bg);-webkit-backdrop-filter:blur(18px) saturate(1.35);backdrop-filter:blur(18px) saturate(1.35);border:1px solid var(--glass-border);box-shadow:inset 0 1px 0 var(--glass-highlight),var(--glass-shadow)}
35
45
  @media(hover:hover){#topStrip .card:hover,#allList .card:hover{background:color-mix(in srgb,var(--bg-hover) 75%,transparent);border-color:var(--card-hover-border)}}
@@ -1310,9 +1320,9 @@ body.has-session.composer-folded #infoBar{border-top-color:transparent}
1310
1320
  .pp-invite-row{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
1311
1321
  .pp-invite-row label{display:inline-flex;align-items:center;gap:4px;font-size:12px;color:var(--text-3)}
1312
1322
  .participants-popover input,.participants-popover select{font:inherit;font-size:12.5px;color:var(--text);background:var(--bg-inset);border:1px solid var(--border-strong);border-radius:6px;padding:3px 7px}
1313
- .pp-invite input[name=name]{flex:1;min-width:120px}
1323
+ .pp-invite input[name=chi-invitee]{flex:1;min-width:120px}
1314
1324
  .pp-invite input[name=cap]{width:52px}
1315
- .pp-invite input[name=identity]{flex:1;min-width:160px}
1325
+ .pp-invite input[name=chi-invitee-account]{flex:1;min-width:160px}
1316
1326
  .pp-bound{color:var(--text-2)}
1317
1327
  .pp-invite .pp-invite-btn{margin-left:auto;background:var(--primary);border-color:var(--primary);color:var(--on-solid);font-weight:600}
1318
1328
  .pp-invite-done{display:flex;flex-direction:column;gap:6px;padding-top:6px;border-top:1px solid var(--border)}
@@ -1543,6 +1553,8 @@ body.has-session #newBtn .brand-new{display:inline}
1543
1553
  #scope{display:inline-flex;align-items:center;gap:8px;min-width:0;font-size:12px;color:var(--text-muted)}
1544
1554
  #scope[hidden]{display:none}
1545
1555
  #scope .scope-name{display:inline-flex;align-items:center;flex-shrink:0;min-height:28px;padding:0 9px;border:1px solid var(--border-strong);border-radius:999px;background:transparent;color:var(--text-2);font:inherit;line-height:inherit;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:40vw;cursor:pointer;transition:none}
1556
+ /* The chip's words in a span of their own: a flex container's bare text gets no ellipsis, a flex item's does. */
1557
+ #scope .scope-label{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1546
1558
  #scope .scope-name:hover:not(:disabled){filter:none}
1547
1559
  #scope .scope-name.error{color:var(--warn-text);border-color:var(--warn-border)}
1548
1560
  #scope .scope-all{color:var(--text-muted);text-decoration:none}
@@ -1633,9 +1645,11 @@ body.all-view #scope .scope-where{display:none}
1633
1645
  /* clip, not hidden: the ellipsis as before, and the touch tap box (its ::after) reaches out above and below. */
1634
1646
  #stripStatus{flex-grow:1000;overflow-x:clip;overflow-y:visible;text-overflow:ellipsis}
1635
1647
  /* A session page: the chip gives way to the pill. The start page has the "new session in …" path beside the chip:
1636
- there the chip keeps its words and the path is what cuts. */
1637
- body.has-session #scope .scope-name{flex-shrink:1;min-width:0}
1638
- body:not(.has-session) #scope .scope-name,body:not(.has-session) #scope .scope-back{flex-shrink:0}
1648
+ there the chip keeps its words and the path is what cuts. Where the path is hidden (the strip hidden, the all view)
1649
+ the chip cuts with an ellipsis as on a session page, or "all" would run under the pill (320px). */
1650
+ #scope .scope-name{flex-shrink:1;min-width:0}
1651
+ body:not(.has-session):not(.strip-hidden):not(.all-view) #scope .scope-name,
1652
+ body:not(.has-session):not(.strip-hidden):not(.all-view) #scope .scope-back{flex-shrink:0}
1639
1653
  body:not(.has-session) #scope .scope-where{flex:1 1 auto;min-width:0}
1640
1654
  #stripStatus:has(.live,.waiting) .pill-count{display:none}
1641
1655
  }
@@ -1777,6 +1791,18 @@ body.all-view #allHead{display:flex}
1777
1791
  @media(min-width:601px){body.all-view #notifyBtn{margin-left:0}}
1778
1792
  /* Nor does the header squeeze the scope chip there: its "all" segment would run under the sessions pill (800px). */
1779
1793
  @media(min-width:601px){body.all-view #scope{flex-shrink:0}}
1794
+ /* Where the header doesn't fit beside the chips at its smallest (the search at its min-width), it and the bell after it
1795
+ wrap to a line of their own, right-aligned, rather than run over the sessions pill (~601-760px). The header's basis is
1796
+ that smallest width; it grows into the free space, so where it fits the line looks as before. With the bell shown, the
1797
+ header's box also holds the bell's place (40px: its 28px and the 12px gap) as padding, and the bell's negative margin
1798
+ pulls it into that padding (taking no room of its own): a line breaks before the header and the bell together,
1799
+ never between them. */
1800
+ @media(min-width:601px){
1801
+ body.all-view #topBar{flex-wrap:wrap;row-gap:8px}
1802
+ body.all-view #allHead{flex:1 1 260px}
1803
+ body.all-view:has(#notifyBtn:not([hidden])) #allHead{flex-basis:300px;padding-right:40px}
1804
+ body.all-view #notifyBtn{margin-left:-40px}
1805
+ }
1780
1806
  /* The search field is glass too (no shadow: it is a field, not a card); the focus ring below replaces the highlight. */
1781
1807
  #allHead input{flex:0 1 240px;width:240px;min-width:90px;box-sizing:border-box;height:24px;background:var(--glass-bg);-webkit-backdrop-filter:blur(18px) saturate(1.35);backdrop-filter:blur(18px) saturate(1.35);border:1px solid var(--glass-border);box-shadow:inset 0 1px 0 var(--glass-highlight);color:var(--text);padding:2px 11px;border-radius:999px;font-size:12px}
1782
1808
  #allHead input::placeholder{color:var(--text-faint)}
@@ -1948,7 +1974,7 @@ a{color:var(--accent)}
1948
1974
  <button type="button" class="strip-toggle" id="stripStatus" title="All sessions, with search"><span class="pill-count">sessions</span></button>
1949
1975
  <span id="sessionTitleRow" hidden><span id="sessionTitle"></span><button type="button" id="titleRenameBtn" class="title-rename" title="Rename this session" aria-label="Rename this session" hidden>✎</button></span>
1950
1976
  <div id="allHead">
1951
- <input id="filter" type="search" placeholder="Search preview, id or status" aria-label="Search sessions" autocomplete="off">
1977
+ <input id="filter" name="chi-filter" type="search" placeholder="Search preview, id or status" aria-label="Search sessions" autocomplete="off">
1952
1978
  <span class="count" id="count"></span>
1953
1979
  <button type="button" class="strip-toggle" id="includeArchived" aria-pressed="false" title="Show archived sessions too">archived</button>
1954
1980
  <button class="ghost" id="selectBtn" title="Pick sessions to archive several at once">Select</button>
@@ -1980,14 +2006,14 @@ a{color:var(--accent)}
1980
2006
  <div id="composer" style="position:relative">
1981
2007
  <div id="commandList" role="listbox" aria-label="Commands" hidden></div>
1982
2008
  <div id="modelPanel" hidden>
1983
- <label class="model-search"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><circle cx="7" cy="7" r="4.5"/><path d="M10.5 10.5 14 14" stroke-linecap="round"/></svg><input id="modelSearch" type="text" placeholder="Search models" autocomplete="off" spellcheck="false" role="combobox" aria-label="Search models" aria-autocomplete="list" aria-controls="modelList" aria-expanded="false"></label>
2009
+ <label class="model-search"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><circle cx="7" cy="7" r="4.5"/><path d="M10.5 10.5 14 14" stroke-linecap="round"/></svg><input id="modelSearch" name="chi-model-search" type="text" placeholder="Search models" autocomplete="off" spellcheck="false" role="combobox" aria-label="Search models" aria-autocomplete="list" aria-controls="modelList" aria-expanded="false"></label>
1984
2010
  <div id="modelList" role="listbox" aria-label="Models"></div>
1985
2011
  </div>
1986
2012
  <div id="deliveryLine" class="composer-line" aria-live="off" hidden></div>
1987
2013
  <div class="compose-col">
1988
2014
  <div id="reviseChip" hidden></div>
1989
2015
  <div id="chips" hidden></div>
1990
- <textarea id="prompt" placeholder="Ask chi anything…" aria-controls="commandList" aria-autocomplete="list" aria-expanded="false"></textarea>
2016
+ <textarea id="prompt" name="chi-composer" autocomplete="off" placeholder="Ask chi anything…" aria-controls="commandList" aria-autocomplete="list" aria-expanded="false"></textarea>
1991
2017
  <div id="composeHint">Enter to start · Shift+Enter for a newline</div>
1992
2018
  </div>
1993
2019
  <div class="actions-col">
@@ -152,7 +152,9 @@ export function infoBarModel({ id, state, sessions, chain, cardTitle, badge, res
152
152
  // link may not be listed yet: then neither, and its links show dates).
153
153
  const selfIso = state.createdAt || sessions.find((x) => x.id === id)?.created_at || null;
154
154
  const parentChip = delegatedBy(state.parentId, sessions.find((x) => x.id === state.parentId) || null);
155
- const reach = REACH[state.reach] || null;
155
+ // Not while its turn runs: the stage says "reconnecting…" then (on a
156
+ // phone too, where the bar can hide its status), and the chip keeps it.
157
+ const reach = running ? null : REACH[state.reach] || null;
156
158
  return {
157
159
  id,
158
160
  // Its turn runs but a card blocks it: the word `chi sessions list` has for it.
@@ -0,0 +1,29 @@
1
+ // A text field that isn't a contact form. iOS Safari offers its "AutoFill
2
+ // Contact" bar above the keyboard on a field that looks like one (no
3
+ // autocomplete, a name or label with a contact word in it: name, email,
4
+ // title, phone…), and once it has seen one it offers it on the page's later
5
+ // text fields too, the composer among them. What it respects against that:
6
+ // autocomplete="off" and a name with no contact word in it.
7
+ //
8
+ // Fields drawn by a lit-html template can't call this: they carry the same
9
+ // two attributes in the template (autocomplete="off", a chi-… name), and
10
+ // spec/web/public/no_contact_fill.test.js checks the templates for them; it
11
+ // also checks each field made with createElement (or an el/node helper)
12
+ // goes through this.
13
+ //
14
+ // A module of its own: static JS is cached at unversioned URLs.
15
+
16
+ // The words iOS reads as a contact field, in a name, a placeholder or a
17
+ // label. A field's name never has one; its wording avoids them.
18
+ export const CONTACT_WORDS = /\b(name|e-?mail|title|phone|tel|address|street|city|zip|postal|country|company|organi[sz]ation|first|last|given|family|nickname)\b/i;
19
+
20
+ // +input+ an input or textarea; +name+ its form name (no contact word in
21
+ // it: a chi-… name). +prose+: the reader writes prose here, so autocorrect
22
+ // stays on (autocomplete="off" turns it off in some browsers).
23
+ export function noContactFill(input, name, { prose = false } = {}) {
24
+ if (CONTACT_WORDS.test(name)) throw new Error(`noContactFill: "${name}" reads as a contact field`);
25
+ input.setAttribute("autocomplete", "off");
26
+ if (prose) input.setAttribute("autocorrect", "on");
27
+ input.name = name;
28
+ return input;
29
+ }
@@ -39,6 +39,11 @@ button.obj-chip{cursor:pointer;font:inherit;font-size:13px;line-height:1.4;text-
39
39
  .obj-row-acts{flex:none;display:flex;gap:4px}
40
40
  .obj-check.refuted{color:var(--warn-text)}
41
41
  .obj-check.confirmed{color:var(--text-2)}
42
+ /* The tracker's reading (objectives_track.js): words first; one that differs from the agent's last move gets weight, never colour alone; a stale one fades. */
43
+ .obj-track.differs{color:var(--warn-text);font-weight:600}
44
+ .obj-track.stale{opacity:.7}
45
+ .obj-track-at{font-weight:400;color:var(--text-muted)}
46
+ .obj-track-row{display:flex;justify-content:flex-end}
42
47
  .obj-act{padding:3px 10px;font-size:12px;border-radius:6px}
43
48
  .obj-act.ghost{background:var(--bg-raised);color:var(--text-2)}
44
49
  form.obj-row{align-items:center}
@@ -73,6 +78,15 @@ form.obj-row{align-items:center}
73
78
  .obj-moves{display:flex;flex-direction:column;gap:2px;margin-bottom:-4px;font-size:13px}
74
79
  .obj-move-line{display:flex;align-items:baseline;gap:8px;color:var(--text-2);flex-wrap:wrap}
75
80
  .obj-move-note{min-width:0;flex:1 1 200px;overflow-wrap:anywhere}
81
+ /* A move's state beside its id: words, never colour alone (objectives_state.js). */
82
+ .obj-state{font-size:12px;color:var(--text-2);white-space:nowrap}
83
+ .obj-state.done{font-weight:600}
84
+ /* A done move its turn's runs don't back (Objectives::Backing): muted words. */
85
+ .obj-unbacked{font-size:12px;color:var(--text-muted);font-style:italic}
86
+ /* The newest turn did work and recorded no move (objectives_moves.js), muted where a moves line goes. */
87
+ .obj-nomove{display:flex;align-items:center;gap:8px;flex-wrap:wrap;font-size:12px;color:var(--text-muted);margin-bottom:-4px}
88
+ @media (pointer:coarse){.obj-track-ask{min-height:36px}}
89
+ .obj-panel.sheet .obj-track-row .obj-act{min-width:0;padding:0 12px}
76
90
  .obj-concerns .obj-pill{margin-right:4px}
77
91
  .obj-notyet{flex:none}
78
92
  .obj-moves:not(.newest) .obj-notyet{display:none}
@@ -9,6 +9,8 @@
9
9
  // short version where the bundle's /short is there (decision-card): the card
10
10
  // lands under it, so the button sits there too. A module of its own: static JS is cached at unversioned URLs.
11
11
  import { foldable } from "./answer_fold.js";
12
+ import { TURN_PROMPT } from "./bubbles.js";
13
+ import { backingText, stateOfParams, stateWord, WORK_ROWS } from "./objectives_state.js";
12
14
  import { keepFollowing } from "./scroll.js";
13
15
  import { html, nothing, render } from "./vendor/lit-html.js";
14
16
 
@@ -16,12 +18,15 @@ const ROW_TITLE = /^(O\d+)\s+([^]*)$/;
16
18
  const RECORDED = /Recorded a move on /;
17
19
  const CONCERNS = /^Concerns (O\d+)\b/;
18
20
 
19
- // A row's move: {id, note}, null for any other row, and for a call that recorded
20
- // nothing (no list, a refusal: Tools::ObjectivesTool).
21
+ // A row's move: {id, note, state?} (state only for blocked or done, from the
22
+ // params line), null for any other row, and for a call that recorded nothing (no
23
+ // list, a refusal: Tools::ObjectivesTool).
21
24
  export function moveOfRow(row) {
22
25
  if (row?.tool !== "objectives" || !RECORDED.test(String(row.output || ""))) return null;
23
26
  const found = ROW_TITLE.exec(String(row.title || row.params || ""));
24
- return found ? { id: found[1], note: found[2] } : null;
27
+ if (!found) return null;
28
+ const state = stateOfParams(row.params);
29
+ return state ? { id: found[1], note: found[2], state } : { id: found[1], note: found[2] };
25
30
  }
26
31
 
27
32
  // The row's title, its objective a chip, marked for the line above an answer
@@ -31,12 +36,23 @@ export function moveRowText(row, shown) {
31
36
  const found = ROW_TITLE.exec(String(shown ?? ""));
32
37
  if (!found) return shown;
33
38
  const move = moveOfRow(row);
34
- return html`<span class="obj-pill obj-mark" data-move-id=${move ? move.id : nothing} data-move-note=${move ? move.note : nothing}>${found[1]}</span> ${found[2]}`;
39
+ return html`<span class="obj-pill obj-mark" data-move-id=${move ? move.id : nothing} data-move-note=${move ? move.note : nothing} data-move-state=${move?.state || nothing}>${found[1]}</span>${stateTemplate(move?.state)} ${found[2]}`;
40
+ }
41
+
42
+ // A move's state as words beside its id, by text and a class (never colour
43
+ // alone); nothing for progress.
44
+ function stateTemplate(state) {
45
+ const word = stateWord(state);
46
+ return word ? html` <span class=${`obj-state ${state}`}>${word}</span>` : nothing;
35
47
  }
36
48
 
37
49
  // A finished turn block's moves, in order.
38
50
  export function movesInBlock(block) {
39
- return [...block.querySelectorAll("[data-move-id]")].map((el) => ({ id: el.dataset.moveId, note: el.dataset.moveNote || "" }));
51
+ return [...block.querySelectorAll("[data-move-id]")].map((el) => {
52
+ const move = { id: el.dataset.moveId, note: el.dataset.moveNote || "" };
53
+ if (el.dataset.moveState) move.state = el.dataset.moveState;
54
+ return move;
55
+ });
40
56
  }
41
57
 
42
58
  // A card body's "Concerns O2 …" paragraph: the id a chip. Idempotent.
@@ -64,7 +80,12 @@ function lineFor(block) {
64
80
  // @param notYet (id) the tap on a move's Not yet (the newest turn's only: CSS)
65
81
  // @param canShorten () whether the newest long answer offers its short version
66
82
  // @param shorten () the tap on it
67
- export function createObjectivesMoves({ historyEl, notYet = () => {}, canShorten = () => false, shorten = () => {} }) {
83
+ // @param latestMove (id) the view's last move of an objective (its backing), null while it can't be placed
84
+ // @param canMarkNoMove () whether the newest finished block may say it recorded no move (an active objective, no turn running or held)
85
+ // @param canTrack () whether that line offers Where are we? (the worker has the tracker)
86
+ // @param track () the tap on it: a promise, false for a failure (already told)
87
+ export function createObjectivesMoves({ historyEl, notYet = () => {}, canShorten = () => false, shorten = () => {}, latestMove = () => null,
88
+ canMarkNoMove = () => false, canTrack = () => false, track = () => {} }) {
68
89
  // Off once tapped; back when +ask+ answers false (a failure, already told).
69
90
  const once = (e, ask) => {
70
91
  const button = e.currentTarget;
@@ -74,7 +95,7 @@ export function createObjectivesMoves({ historyEl, notYet = () => {}, canShorten
74
95
  });
75
96
  };
76
97
  const drawLine = (line, moves) => render(html`${moves.map((m) => html`<div class="obj-move-line">
77
- <span class="obj-pill obj-mark">${m.id}</span><span class="obj-move-note">${m.note}</span>
98
+ <span class="obj-pill obj-mark">${m.id}</span>${stateTemplate(m.state)}<span class="obj-move-note">${m.note}</span>${m.flag ? html`<span class="obj-unbacked">${m.flag}</span>` : nothing}
78
99
  <button type="button" class="obj-act ghost obj-notyet" title=${`Tell the agent: not yet on ${m.id}`} @click=${(e) => once(e, () => notYet(m.id))}>Not yet</button>
79
100
  </div>`)}`, line);
80
101
 
@@ -113,9 +134,60 @@ export function createObjectivesMoves({ historyEl, notYet = () => {}, canShorten
113
134
  }
114
135
  }
115
136
 
137
+ // The view's backing is its latest move's: drawn on that objective's last
138
+ // move in the history only (a block may hold two moves on it).
139
+ function flagged(blocks) {
140
+ const newest = new Map();
141
+ blocks.forEach((block, b) => movesInBlock(block).forEach((m, i) => newest.set(m.id, `${b}:${i}`)));
142
+ return (b, moves) => moves.map((m, i) => {
143
+ const flag = newest.get(m.id) === `${b}:${i}` ? backingText(latestMove(m.id)) : null;
144
+ return flag ? { ...m, flag } : m;
145
+ });
146
+ }
147
+
148
+ // The newest finished turn of the owner's that did work (an edit, write or
149
+ // execute row) and recorded no move says so where its moves line would be.
150
+ // Only the newest: the list of an older turn's time isn't known. Not for a
151
+ // canceled or failed turn, nor a participant's (turn_block.js stamps them),
152
+ // nor one that ran before the list's first note (the model had none to move
153
+ // on), nor once a newer turn's prompt follows it (a plain turn has no block).
154
+ const after = (a, b) => !!(a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING);
155
+ function newerTurn(block) {
156
+ for (let el = block.nextElementSibling; el; el = el.nextElementSibling) if (el.matches(TURN_PROMPT)) return true;
157
+ return false;
158
+ }
159
+
160
+ function placeNoMove(blocks) {
161
+ const newest = blocks[blocks.length - 1];
162
+ const list = historyEl.querySelector(".objectives-entry");
163
+ const wanted = newest && canMarkNoMove() && newest.dataset.end === "completed" && !newest.dataset.participant
164
+ && !newest.querySelector("[data-move-id]") && newest.querySelector(WORK_ROWS)
165
+ && list && after(list, newest) && !newerTurn(newest);
166
+ for (const el of historyEl.querySelectorAll(":scope > .obj-nomove")) {
167
+ if (!wanted || el.previousElementSibling !== newest) el.remove();
168
+ }
169
+ if (!wanted) return;
170
+ const offer = canTrack() ? "track" : "";
171
+ const shown = newest.nextElementSibling?.classList.contains("obj-nomove") ? newest.nextElementSibling : null;
172
+ if (shown?.dataset.offer === offer) return;
173
+ keepFollowing(historyEl, () => {
174
+ const el = shown || historyEl.ownerDocument.createElement("div");
175
+ el.className = "obj-nomove";
176
+ el.dataset.offer = offer;
177
+ el.title = "This turn did work and recorded no move on the objectives. Information only.";
178
+ // The tracker on demand, where the worker has it (feature_gates.js).
179
+ render(html`<span>no move recorded</span>${offer ? html` <button type="button" class="obj-act ghost obj-track-ask"
180
+ title="One side request reads the session's record for every active objective. Information only, nothing enters the conversation"
181
+ @click=${(e) => once(e, track)}>Where are we?</button>` : nothing}`, el);
182
+ if (!shown) newest.after(el);
183
+ });
184
+ }
185
+
116
186
  function decorate() {
117
- for (const block of historyEl.querySelectorAll(":scope > .turn-work")) {
118
- const moves = movesInBlock(block);
187
+ const blocks = [...historyEl.querySelectorAll(":scope > .turn-work")];
188
+ const withFlags = flagged(blocks);
189
+ for (const [b, block] of blocks.entries()) {
190
+ const moves = withFlags(b, movesInBlock(block));
119
191
  const line = lineFor(block);
120
192
  if (!moves.length) {
121
193
  line?.remove();
@@ -132,6 +204,7 @@ export function createObjectivesMoves({ historyEl, notYet = () => {}, canShorten
132
204
  });
133
205
  }
134
206
  markNewest();
207
+ placeNoMove(blocks);
135
208
  placeShort();
136
209
  for (const card of historyEl.querySelectorAll(".plugin-card .card-body")) {
137
210
  if (card.closest(".plugin-card").querySelector(".card-source")?.textContent === "decision-card") chipConcerns(card);
@@ -0,0 +1,42 @@
1
+ // Where a move says its objective stands (pure, no DOM): a move's state
2
+ // (Tools::ObjectivesTool: progress, blocked or done; done is the agent's claim,
3
+ // never the item's status) and its words, and its backing's flag. A module of its own, not new exports of
4
+ // objectives_model.js: static JS is cached at unversioned URLs, and an existing
5
+ // module importing a new export of another existing one blanks a page with a
6
+ // mixed cache. See docs/internals/objectives.md.
7
+
8
+ const WORDS = { blocked: "blocked", done: "claims done" };
9
+
10
+ // A tool row's params line carries a blocked or done state before its note
11
+ // (ToolActivity#objectives_state_param); the title doesn't (an older page reads it).
12
+ const PARAMS_STATE = /^id="(?:[^"\\]|\\.)*" state="(blocked|done)" note=/;
13
+
14
+ // The words a state adds: null for progress, none or one this page doesn't know.
15
+ export function stateWord(state) {
16
+ return Object.hasOwn(WORDS, state) ? WORDS[state] : null;
17
+ }
18
+
19
+ // The state a row's params line names: "blocked", "done" or null.
20
+ export function stateOfParams(params) {
21
+ return PARAMS_STATE.exec(String(params ?? ""))?.[1] ?? null;
22
+ }
23
+
24
+ // A move's backing (Objectives::Backing, derived from its turn's runs) as the
25
+ // muted mark's words, only when it is flagged: a done move whose turn's last
26
+ // command failed, or that edited after it. null otherwise.
27
+ export function backingText(move) {
28
+ const backing = move?.backing;
29
+ if (!backing?.unbacked) return null;
30
+ return backing.command === "failed" ? "not backed: the last command failed" : "not backed: edited after the last command ran";
31
+ }
32
+
33
+ // Whether the list has an objective still active: the no-move mark asks for one.
34
+ export function hasActive(list) {
35
+ return Array.isArray(list?.items) && list.items.some((i) => i?.status === "active");
36
+ }
37
+
38
+ // The rows that make a turn "did work" for the no-move mark: an edit, write or
39
+ // execute that went through (its status mark ok: not failed, denied or
40
+ // stopped). turn_block.js stamps data-tool. An objectives call, a proposal
41
+ // too, is no work.
42
+ export const WORK_ROWS = ["edit", "write", "execute"].map((t) => `.activity-row[data-tool="${t}"] > .activity-status.ok`).join(", ");
@@ -9,6 +9,9 @@
9
9
  // static JS is cached at unversioned URLs.
10
10
  import { createChipPopover, SHEET_TALL } from "./chip_popover.js";
11
11
  import { addLine, checkText, DONE, DROPPED, editableText, expireChecks, headline, markLine, nextExpiry, notYetText, pendingText, progress, rewordLine, stripItems } from "./objectives_model.js";
12
+ import { backingText, hasActive, stateWord } from "./objectives_state.js";
13
+ import { expireTracking, TRACK_LINE, trackDiffers, tracking, trackingUntil, trackText } from "./objectives_track.js";
14
+ import { wallClock } from "./format.js";
12
15
  import { html, nothing, render } from "./vendor/lit-html.js";
13
16
 
14
17
  const EXPIRY_SLACK_MS = 50;
@@ -21,8 +24,10 @@ const EXPIRY_MAX_MS = 140_000;
21
24
  // @param sendMessage (text) sends it as the user's message: a promise (Not yet)
22
25
  // @param failed (error) a refused post, to tell the user
23
26
  // @param onChange () the list came or went
27
+ // @param canTrack () the worker has the tracker (its Bridge feature): Where are we? shows only then
24
28
  export function createObjectivesStrip({ el, session = () => null, running = () => false, sendLine = async () => {},
25
- sendMessage = async () => {}, failed = () => {}, onChange = () => {}, doc = document, win = window }) {
29
+ sendMessage = async () => {}, failed = () => {}, onChange = () => {}, canTrack = () => false,
30
+ doc = document, win = window }) {
26
31
  let list = null;
27
32
  // The item whose text is being edited; while a post is out.
28
33
  let editing = null;
@@ -65,9 +70,20 @@ export function createObjectivesStrip({ el, session = () => null, running = () =
65
70
  function subline(item) {
66
71
  const parts = [];
67
72
  if (item.done_when) parts.push(html`<span>done when: ${item.done_when}</span>`);
68
- if (item.move) parts.push(html`<span>last move: ${item.move.note}${item.move.evidence ? ` (${item.move.evidence})` : ""}</span>`);
73
+ if (item.move) {
74
+ const word = stateWord(item.move.state);
75
+ parts.push(html`<span>last move: ${word ? html`<span class=${`obj-state ${item.move.state}`}>${word}</span> ` : nothing}${item.move.note}${item.move.evidence ? ` (${item.move.evidence})` : ""}</span>`);
76
+ const flag = backingText(item.move);
77
+ if (flag) parts.push(html`<span class="obj-unbacked" title="From the runs of its turn before the move. Information only.">${flag}</span>`);
78
+ }
69
79
  const check = checkText(item.check);
70
80
  if (check) parts.push(html`<span class=${`obj-check ${item.check.verdict || "running"}`} title=${item.check.model ? `Read by ${item.check.model}. Information only.` : "Information only."}>${check}</span>`);
81
+ const track = trackText(item.track);
82
+ if (track) {
83
+ const klass = `obj-track${trackDiffers(item) ? " differs" : ""}${item.track.stale ? " stale" : ""}`;
84
+ const title = `${item.track.model ? `Read by ${item.track.model}. ` : ""}${item.track.stale ? "Read before the latest change. " : ""}${trackDiffers(item) ? "Differs from the agent's last move. " : ""}Information only.`;
85
+ parts.push(html`<span class=${klass} title=${title}>${track}<span class="obj-track-at"> · ${wallClock(item.track.at, Date.now())}</span></span>`);
86
+ }
71
87
  return parts.length ? html`<div class="obj-row-sub">${parts}</div>` : nothing;
72
88
  }
73
89
 
@@ -112,7 +128,10 @@ export function createObjectivesStrip({ el, session = () => null, running = () =
112
128
  <input class="obj-input" name="text" placeholder="Add an objective" aria-label="Add an objective" autocomplete="off">
113
129
  <button type="submit" class="obj-act" ?disabled=${busy}>Add</button>
114
130
  </form>
115
- <div class="obj-note" role="status">${waiting || "No message, no turn: the agent reads the change before its next turn."}</div>`;
131
+ <div class="obj-note" role="status">${waiting || "No message, no turn: the agent reads the change before its next turn."}</div>
132
+ ${canTrack() && hasActive(list) ? html`<div class="obj-track-row">
133
+ <button type="button" class="obj-act ghost" data-obj-act="track" title="One side request reads the session's record for every active objective. Information only, nothing enters the conversation" ?disabled=${busy || tracking(list)}>${tracking(list) ? "Reading where they stand…" : "Where are we?"}</button>
134
+ </div>` : nothing}`;
116
135
  };
117
136
 
118
137
  const shell = createChipPopover({
@@ -162,6 +181,8 @@ export function createObjectivesStrip({ el, session = () => null, running = () =
162
181
  drawPanel();
163
182
  } else if (act === "notyet") {
164
183
  notYet(id);
184
+ } else if (act === "track") {
185
+ post(TRACK_LINE);
165
186
  } else {
166
187
  post(markLine(act, id));
167
188
  }
@@ -198,21 +219,21 @@ export function createObjectivesStrip({ el, session = () => null, running = () =
198
219
  // cap keeps a page whose clock is off from holding it for long.
199
220
  function armExpiry() {
200
221
  win.clearTimeout(expiry);
201
- const at = nextExpiry(list);
202
- if (at === null) return;
222
+ const at = [nextExpiry(list), trackingUntil(list)].filter((t) => t !== null).reduce((a, b) => Math.min(a, b), Infinity);
223
+ if (at === Infinity) return;
203
224
  expiry = win.setTimeout(() => {
204
- list = expireChecks(list, Math.max(Date.now(), at));
225
+ list = expireTracking(expireChecks(list, Math.max(Date.now(), at)), Math.max(Date.now(), at));
205
226
  draw();
206
227
  drawPanel();
207
228
  armExpiry();
208
229
  }, Math.min(Math.max(at - Date.now(), 0) + EXPIRY_SLACK_MS, EXPIRY_MAX_MS));
209
230
  }
210
231
 
211
- // The list without what a check adds: its start and end aren't a change to it.
212
- const listSig = (view) => JSON.stringify(view?.items?.map(({ check: _check, ...item }) => item) ?? null);
232
+ // The list without what a check or a track adds: their start and end aren't a change to it.
233
+ const listSig = (view) => JSON.stringify(view?.items?.map(({ check: _check, track: _track, ...item }) => item) ?? null);
213
234
 
214
235
  const take = (view) => {
215
- const next = view && Array.isArray(view.items) ? expireChecks(view, Date.now()) : null;
236
+ const next = view && Array.isArray(view.items) ? expireTracking(expireChecks(view, Date.now()), Date.now()) : null;
216
237
  if (listSig(next) !== listSig(list)) told.clear();
217
238
  list = next;
218
239
  armExpiry();
@@ -233,6 +254,9 @@ export function createObjectivesStrip({ el, session = () => null, running = () =
233
254
  },
234
255
  notYet,
235
256
  hasList: () => !!list,
257
+ hasActive: () => hasActive(list),
258
+ // An objective's last move as the view has it (its state, its backing), null with none.
259
+ moveOf: (id) => list?.items?.find((i) => i.id === id)?.move ?? null,
236
260
  // A turn started or ended: the waiting line's words.
237
261
  redraw: () => {
238
262
  draw();
@@ -0,0 +1,52 @@
1
+ // The tracker on the page (pure, no DOM): ObjectivesTrack's reading of each
2
+ // objective (the view's item.track: {reading, reason, at, model, stale?}) and
3
+ // the view's tracking: {until} while one runs. Information only. A module of
4
+ // its own, not new exports of objectives_model.js or objectives_state.js:
5
+ // static JS is cached at unversioned URLs, and an existing module importing a
6
+ // new export of another existing one blanks a page with a mixed cache. See
7
+ // docs/internals/objectives.md, The tracker.
8
+ import { workerPredates } from "./worker_features.js";
9
+
10
+ // The one line both of its buttons post (ObjectivesCommand).
11
+ export const TRACK_LINE = "/objectives track";
12
+
13
+ // The worker's Bridge feature (ObjectivesTrack::FEATURE): an older worker hides Where are we?.
14
+ export const TRACK_FEATURE = "objectives_track";
15
+
16
+ // The page's objectivesTrack gate (feature_gates.js): a live worker that predates the tracker.
17
+ export function trackWorkerUnavailable(workerFeatures, bridgeUp) {
18
+ return workerPredates(workerFeatures, bridgeUp, TRACK_FEATURE);
19
+ }
20
+
21
+ const word = (reading) => (reading === "no_answer" ? "no answer" : String(reading ?? ""));
22
+
23
+ // The list's row: "tracker: no sign — nothing ran for it". null with no reading.
24
+ export function trackText(track) {
25
+ if (!track?.reading) return null;
26
+ return `tracker: ${word(track.reading)}${track.reason ? ` — ${track.reason}` : ""}`;
27
+ }
28
+
29
+ // Whether the reading disagrees with the agent's last move on it (claims done vs no
30
+ // sign): the signal to look at. Not for an objective with no move, nor no answer.
31
+ export function trackDiffers(item) {
32
+ const reading = item?.track?.reading;
33
+ const state = item?.move?.state || "progress";
34
+ return !!(item?.move && reading && reading !== "no_answer" && reading !== state);
35
+ }
36
+
37
+ // When the running read runs out, in ms; null with none. No event says so when its worker dies.
38
+ export function trackingUntil(list) {
39
+ const at = Date.parse(list?.tracking?.until);
40
+ return Number.isFinite(at) ? at : null;
41
+ }
42
+
43
+ // +list+ without a running read past its time.
44
+ export function expireTracking(list, now) {
45
+ const at = trackingUntil(list);
46
+ if (at === null || at > now) return list;
47
+ const { tracking: _gone, ...rest } = list;
48
+ return rest;
49
+ }
50
+
51
+ // Whether a read runs now.
52
+ export const tracking = (list) => trackingUntil(list) !== null;
@@ -6,6 +6,7 @@ import { stillOn } from "./latest.js";
6
6
  import { cantText } from "./format.js";
7
7
  import { createObjectivesMoves } from "./objectives_moves.js";
8
8
  import { createObjectivesStrip } from "./objectives_strip.js";
9
+ import { TRACK_LINE } from "./objectives_track.js";
9
10
 
10
11
  // @param el the strip's element
11
12
  // @param historyEl the history
@@ -17,8 +18,10 @@ import { createObjectivesStrip } from "./objectives_strip.js";
17
18
  // @param sendCommand, sendTurn data.js's
18
19
  // @param follow () follows a worker a post woke
19
20
  // @param toast (text, action, options)
21
+ // @param canTrack () the open session's worker has the tracker (feature_gates.js's objectivesTrack gate)
20
22
  // @return {seed, update, reset, redraw, notYet}
21
- export function createObjectives({ el, historyEl, session, running, holding = () => false, commands, clientId, sendCommand, sendTurn, follow, toast }) {
23
+ export function createObjectives({ el, historyEl, session, running, holding = () => false, commands, clientId, sendCommand, sendTurn, follow, toast,
24
+ canTrack = () => false }) {
22
25
  const posted = async (request) => {
23
26
  const still = stillOn(session);
24
27
  await request(session());
@@ -34,13 +37,25 @@ export function createObjectives({ el, historyEl, session, running, holding = ()
34
37
  sendMessage: (text) => posted((id) => sendTurn(id, text, { clientId: `${clientId}:objectives`, history: false })),
35
38
  failed: told("edit the objectives"),
36
39
  onChange: () => moves.decorate(),
40
+ canTrack,
37
41
  });
38
42
  const moves = createObjectivesMoves({
39
43
  historyEl, notYet: (id) => strip.notYet(id),
44
+ // The view's move is the newest: not while a turn runs or one is held in the
45
+ // stage, whose move the history doesn't have yet. ?.: a cached older strip.
46
+ latestMove: (id) => (running() || holding() ? null : strip.moveOf?.(id) ?? null),
47
+ // The history's newest block is the newest turn's only then (canShorten's rule).
48
+ canMarkNoMove: () => !running() && !holding() && !!strip.hasActive?.(),
40
49
  // Not during a turn: its answer isn't there yet, and /short refuses it. Nor
41
50
  // with a turn still in the stage: the history's last answer isn't the newest,
42
51
  // which is what /short reads. The hand-off fills the history, which redraws this.
43
52
  canShorten: () => strip.hasList() && !running() && !holding() && (commands() || []).some((c) => c?.name === "/short"),
53
+ canTrack,
54
+ // As a strip tap: no echo; the card is the answer. false: a failure, already told.
55
+ track: () => posted((id) => sendCommand(id, TRACK_LINE, { clientId, card: true })).then(() => true, (e) => {
56
+ told("ask where the objectives stand")(e);
57
+ return false;
58
+ }),
44
59
  // false: a failure, already told: the button comes back.
45
60
  shorten: () => posted((id) => sendCommand(id, "/short", { clientId, card: true })).then(() => true, (e) => {
46
61
  told("ask for it")(e);
@@ -193,7 +193,7 @@ button.small{font-size:12px;padding:2px 8px}
193
193
  <div class="p-hint composer-line" id="hint">⏎ sends, ⇧⏎ a new line, ↑ an earlier comment. The model answers in a read-only turn; the owner sees everything.</div>
194
194
  <div class="compose-col">
195
195
  <div id="chips" hidden></div>
196
- <textarea id="comment" rows="1" placeholder="Comment or ask" aria-label="Comment or ask"></textarea>
196
+ <textarea id="comment" name="chi-comment" autocomplete="off" rows="1" placeholder="Comment or ask" aria-label="Comment or ask"></textarea>
197
197
  </div>
198
198
  <div class="actions-col">
199
199
  <button type="button" id="attachBtn" class="attach-btn" title="Add images" aria-label="Add images" hidden></button>