samagotchi 0.165.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 (100) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +99 -1
  3. data/docs/architecture.md +1 -0
  4. data/docs/cli.md +16 -7
  5. data/docs/configuration.md +4 -1
  6. data/docs/guardrails.md +8 -3
  7. data/docs/hooks.md +4 -6
  8. data/docs/internals/bridge.md +6 -0
  9. data/docs/internals/bundles.md +2 -4
  10. data/docs/internals/engine.md +4 -5
  11. data/docs/internals/objectives.md +141 -9
  12. data/docs/internals/remote-sessions.md +6 -7
  13. data/docs/internals/web-frontend.md +62 -24
  14. data/docs/memory.md +1 -2
  15. data/docs/releasing.md +12 -3
  16. data/docs/sessions.md +24 -6
  17. data/docs/testing.md +14 -4
  18. data/lib/samagotchi/bridge.rb +1 -1
  19. data/lib/samagotchi/bundle_command/installed_check.rb +2 -14
  20. data/lib/samagotchi/bundle_command.rb +19 -11
  21. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  22. data/lib/samagotchi/cli/command.rb +10 -0
  23. data/lib/samagotchi/compat.rb +4 -14
  24. data/lib/samagotchi/config.rb +3 -0
  25. data/lib/samagotchi/context_command.rb +2 -1
  26. data/lib/samagotchi/engine/objectives.rb +20 -1
  27. data/lib/samagotchi/engine/side_requests.rb +3 -2
  28. data/lib/samagotchi/engine/turn_end.rb +4 -1
  29. data/lib/samagotchi/engine.rb +3 -0
  30. data/lib/samagotchi/extension_load.rb +2 -26
  31. data/lib/samagotchi/guardrails/approvals.rb +59 -9
  32. data/lib/samagotchi/jsonl_store.rb +61 -0
  33. data/lib/samagotchi/memory_bundle/status.rb +3 -15
  34. data/lib/samagotchi/memory_bundle/system_bundle.rb +16 -10
  35. data/lib/samagotchi/memory_command.rb +4 -2
  36. data/lib/samagotchi/objectives.rb +43 -14
  37. data/lib/samagotchi/objectives_backing.rb +124 -0
  38. data/lib/samagotchi/objectives_check.rb +19 -126
  39. data/lib/samagotchi/objectives_command.rb +14 -7
  40. data/lib/samagotchi/objectives_record.rb +104 -0
  41. data/lib/samagotchi/objectives_track.rb +353 -0
  42. data/lib/samagotchi/plugin/sessions.rb +4 -1
  43. data/lib/samagotchi/push_command.rb +2 -1
  44. data/lib/samagotchi/remote_command.rb +2 -1
  45. data/lib/samagotchi/reply_wait/poll.rb +10 -21
  46. data/lib/samagotchi/reply_wait.rb +4 -47
  47. data/lib/samagotchi/run_options.rb +1 -1
  48. data/lib/samagotchi/schedule_command.rb +6 -0
  49. data/lib/samagotchi/schedules.rb +1 -1
  50. data/lib/samagotchi/session_access/remote.rb +7 -24
  51. data/lib/samagotchi/session_commands.rb +1 -1
  52. data/lib/samagotchi/session_inbox.rb +1 -1
  53. data/lib/samagotchi/sessions_command.rb +12 -6
  54. data/lib/samagotchi/share_command.rb +2 -1
  55. data/lib/samagotchi/tool_activity.rb +11 -1
  56. data/lib/samagotchi/tool_declarations.rb +5 -1
  57. data/lib/samagotchi/tools/delegate.rb +2 -4
  58. data/lib/samagotchi/tools/objectives_tool.rb +19 -2
  59. data/lib/samagotchi/turn_stages/objectives.rb +46 -3
  60. data/lib/samagotchi/version.rb +1 -1
  61. data/lib/samagotchi/web/participant_access.rb +1 -1
  62. data/lib/samagotchi/web/public/app.js +55 -420
  63. data/lib/samagotchi/web/public/auth_lost.js +3 -1
  64. data/lib/samagotchi/web/public/bar_fold.js +1 -1
  65. data/lib/samagotchi/web/public/chip_popover.js +5 -1
  66. data/lib/samagotchi/web/public/copy.js +2 -1
  67. data/lib/samagotchi/web/public/delivery_line.js +19 -4
  68. data/lib/samagotchi/web/public/index.html +156 -49
  69. data/lib/samagotchi/web/public/info_bar.js +1 -1
  70. data/lib/samagotchi/web/public/info_bar_model.js +8 -1
  71. data/lib/samagotchi/web/public/live_timing.js +3 -0
  72. data/lib/samagotchi/web/public/no_contact_fill.js +29 -0
  73. data/lib/samagotchi/web/public/objectives.css +14 -0
  74. data/lib/samagotchi/web/public/objectives_moves.js +82 -9
  75. data/lib/samagotchi/web/public/objectives_state.js +42 -0
  76. data/lib/samagotchi/web/public/objectives_strip.js +33 -9
  77. data/lib/samagotchi/web/public/objectives_track.js +52 -0
  78. data/lib/samagotchi/web/public/objectives_wiring.js +16 -1
  79. data/lib/samagotchi/web/public/participant.html +1 -1
  80. data/lib/samagotchi/web/public/participants_panel.js +14 -7
  81. data/lib/samagotchi/web/public/question_cards.js +7 -12
  82. data/lib/samagotchi/web/public/resync_reach.js +63 -0
  83. data/lib/samagotchi/web/public/scope.js +3 -3
  84. data/lib/samagotchi/web/public/session_fields.js +1 -0
  85. data/lib/samagotchi/web/public/session_rename.js +6 -2
  86. data/lib/samagotchi/web/public/session_state.js +6 -1
  87. data/lib/samagotchi/web/public/session_sync.js +249 -0
  88. data/lib/samagotchi/web/public/session_view.js +279 -0
  89. data/lib/samagotchi/web/public/stage_frame.js +4 -2
  90. data/lib/samagotchi/web/public/stage_stall.js +134 -0
  91. data/lib/samagotchi/web/public/stage_view.js +75 -6
  92. data/lib/samagotchi/web/public/stream_handlers.js +1 -1
  93. data/lib/samagotchi/web/public/tokens.css +2 -2
  94. data/lib/samagotchi/web/public/turn_block.js +8 -0
  95. data/lib/samagotchi/web/public/turn_html.js +1 -1
  96. data/lib/samagotchi/web/public/widget_picks.js +3 -0
  97. data/lib/samagotchi/web/public/working_set_view.js +1 -1
  98. data/lib/samagotchi/web/session_access_routes.rb +4 -15
  99. data/lib/samagotchi/web/token.rb +2 -2
  100. metadata +12 -1
@@ -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>
@@ -169,6 +169,12 @@ function rowTemplate(row, { capFor }) {
169
169
  row.expires ? html` · ${row.expires}` : nothing}${row.identity ? html` · <span class="pp-bound">bound to ${row.identity}</span>` : nothing}</div>${actions}</li>`;
170
170
  }
171
171
 
172
+ // The Invite form's fields by what inviteBody takes. The text fields' names
173
+ // have no contact word in them (no_contact_fill.js): iOS Safari's AutoFill
174
+ // Contact bar, offered on a "name" or an email field, then stays on the
175
+ // page's later fields, the composer's too.
176
+ export const INVITE_FIELDS = { name: "chi-invitee", kind: "kind", days: "days", cap: "cap", identity: "chi-invitee-account" };
177
+
172
178
  function inviteTemplate(invite, { canShare }) {
173
179
  if (!invite) return nothing;
174
180
  return html`<div class="pp-invite-done">
@@ -195,7 +201,7 @@ export const EMPTY_PAIR = "Nobody yet. Invite a person (or an agent) to work wit
195
201
  // turns act; otherwise (a review session, an older worker) that they read.
196
202
  // +identityHeader+: the header chi web's auth proxy names the signed-in
197
203
  // user in (the list's identity_header), null without one: then the Invite
198
- // has no email field (a bound link could never open).
204
+ // has no account field (a bound link could never open).
199
205
  export function panelTemplate(grants, { now, sessionId, invite = null, error = null, capFor = null, canShare = false,
200
206
  busy = false, working = null, reviewing = false, identityHeader = null,
201
207
  pair = false } = {}) {
@@ -212,11 +218,12 @@ export function panelTemplate(grants, { now, sessionId, invite = null, error = n
212
218
  ${working && !invite ? html`<div class="pp-warning pp-working" role="note">${working}<button type="button"
213
219
  data-act="start-review" ?disabled=${reviewing}>${reviewing ? "Starting…" : "Start a review of it"}</button></div>` : nothing}
214
220
  ${invite ? inviteTemplate(invite, { canShare }) : html`<form class="pp-invite">
215
- <div class="pp-invite-row"><input name="name" type="text" placeholder="Name (Alex)" autocomplete="off" aria-label="Their name" maxlength="64"
221
+ <div class="pp-invite-row"><input name="chi-invitee" type="text" placeholder="Who (Alex)" autocomplete="off" aria-label="Who the link is for" maxlength="64"
216
222
  ><span class="select-wrap"><select name="kind" aria-label="A person or an agent"><option value="human">person</option><option value="agent">agent</option></select></span></div>
217
- ${identityHeader ? html`<div class="pp-invite-row"><input name="identity" type="email" placeholder="Their email (alex@example.com)"
218
- autocomplete="off" aria-label="Their email: the link opens only for that account"></div>
219
- <div class="ctx-pop-meta pp-bind-note">With their email the link opens only for them, signed in through the proxy.
223
+ ${identityHeader ? html`<div class="pp-invite-row"><input name="chi-invitee-account" type="text" inputmode="email"
224
+ placeholder="Their account (alex@example.com)" autocomplete="off" autocapitalize="off" spellcheck="false"
225
+ aria-label="Their sign-in account: the link opens only for it"></div>
226
+ <div class="ctx-pop-meta pp-bind-note">Bound to their account, the link opens only for them, signed in through the proxy.
220
227
  Without one, anyone the proxy lets in who gets the link can open it.</div>` : nothing}
221
228
  <div class="pp-invite-row"><label>Expires <span class="select-wrap"><select name="days">${EXPIRY_DAYS.map((d) => html`<option value=${d}
222
229
  ?selected=${d === DEFAULT_EXPIRY_DAYS}>${d === 1 ? "1 day" : `${d} days`}</option>`)}</select></span></label
@@ -246,7 +253,7 @@ export function createParticipantsControl({ el, session, api, onChange = () => {
246
253
  // "review", the server's ReviewStart.share_terms), never guessed from the warning.
247
254
  let inviteMode = null;
248
255
  // The header chi web's proxy names the user in (GET …/participants), null
249
- // without one: the Invite's email field.
256
+ // without one: the Invite's account field.
250
257
  let identityHeader = null;
251
258
  // Where a participant's link opens, no token (GET …/participants
252
259
  // link_base): a claim link's base (claimTarget).
@@ -326,7 +333,7 @@ export function createParticipantsControl({ el, session, api, onChange = () => {
326
333
  }
327
334
 
328
335
  async function submitInvite(form) {
329
- const values = Object.fromEntries(["name", "kind", "days", "cap", "identity"].map((k) => [k, form.elements[k]?.value]));
336
+ const values = Object.fromEntries(Object.entries(INVITE_FIELDS).map(([k, field]) => [k, form.elements[field]?.value]));
330
337
  const { body, error: problem } = inviteBody(values);
331
338
  if (problem) {
332
339
  error = problem;
@@ -23,6 +23,10 @@ import { sessionHash } from "./route.js";
23
23
  import { clientLabel, isOwn } from "./turn_events.js";
24
24
  import { continueLine } from "./commands.js";
25
25
  import { plainText } from "./plain_line.js";
26
+ import { noContactFill } from "./no_contact_fill.js";
27
+
28
+ // A card's text fields' name: not a contact field (no_contact_fill.js).
29
+ const CARD_NOTE = "chi-card-note";
26
30
 
27
31
  // @param sessionId () => the open session's id (answers go there)
28
32
  // @param clientId this tab's id in the session's events
@@ -175,7 +179,7 @@ export function createQuestionCards({
175
179
  if (pq.allow_freeform) {
176
180
  freeformInput = doc.createElement("input");
177
181
  freeformInput.type = "text";
178
- noContactFill(freeformInput);
182
+ noContactFill(freeformInput, CARD_NOTE, { prose: true });
179
183
  freeformInput.className = "question-freeform";
180
184
  freeformInput.placeholder = approval ? "Reason for the model (with Deny, or alone to deny)…" : "Other…";
181
185
  card.appendChild(freeformInput);
@@ -255,15 +259,6 @@ export function createQuestionCards({
255
259
  focusWhenIdle(card, pq.id, { staged });
256
260
  }
257
261
 
258
- // A card's text field isn't a contact form: what iOS Safari respects
259
- // against its "AutoFill Contact" bar (no autocomplete, a name with no
260
- // contact word in it). Autocorrect stays: the reader writes prose here.
261
- function noContactFill(input) {
262
- input.setAttribute("autocomplete", "off");
263
- input.setAttribute("autocorrect", "on");
264
- input.name = "chi-card-note";
265
- }
266
-
267
262
  function isPlainEnter(e) {
268
263
  return e.key === "Enter" && !e.isComposing && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey;
269
264
  }
@@ -294,7 +289,7 @@ export function createQuestionCards({
294
289
  function renderStepLimitActions(card, pq, options) {
295
290
  const reason = doc.createElement("input");
296
291
  reason.type = "text";
297
- noContactFill(reason);
292
+ noContactFill(reason, CARD_NOTE, { prose: true });
298
293
  reason.className = "question-freeform continue-reason";
299
294
  reason.placeholder = CONTINUE_REASON_PLACEHOLDER;
300
295
  const err = doc.createElement("div");
@@ -635,7 +630,7 @@ export function createQuestionCards({
635
630
  no.addEventListener("click", () => answer(continueLine("no")));
636
631
  const reason = doc.createElement("input");
637
632
  reason.type = "text";
638
- noContactFill(reason);
633
+ noContactFill(reason, CARD_NOTE, { prose: true });
639
634
  reason.className = "continue-reason";
640
635
  reason.placeholder = "Why not? (the model reads it)";
641
636
  const noBecause = doc.createElement("button");
@@ -0,0 +1,63 @@
1
+ // A re-read of the open session (session_sync.js resync) that could not reach chi web:
2
+ // the one rule for what the page does then. The history already drawn for
3
+ // this session stays as it is (the conversation is still right, only newer
4
+ // events are missing) and the info bar's status chip says the page is
5
+ // retrying, then, once the retries ran out, that it is offline (the full
6
+ // words in its tooltip); while a turn runs the stage's own line says
7
+ // "reconnecting…" instead (stage_stall.js) and the chip keeps the turn's word;
8
+ // the next re-read that succeeds clears it (the hub's next event re-reads a
9
+ // session left in that state: needsReread). Only a first load (select()'s
10
+ // "Loading…", nothing of the session drawn yet) shows the error in the
11
+ // history, as there is nothing to keep.
12
+ // Its own module: new exports go in new modules (web-frontend.md).
13
+
14
+ // The status chip's word (its class), text and tooltip per state. The texts
15
+ // fit the room the chip keeps for its widest word (running, stopped), so the
16
+ // bar doesn't move while one shows.
17
+ export const REACH = Object.freeze({
18
+ reconnecting: Object.freeze({
19
+ status: "reconnecting", text: "retrying",
20
+ tip: "Reconnecting: can't reach chi web, trying again. The conversation shown is as it was; newer events show once it's back.",
21
+ }),
22
+ offline: Object.freeze({
23
+ status: "offline", text: "offline",
24
+ tip: "Can't reach chi web. The conversation shown is as it was; the page reads it again once chi web is back.",
25
+ }),
26
+ });
27
+
28
+ // What a failed re-read does. +drawn+: the history shows this session's
29
+ // conversation; +retrying+: another try is scheduled.
30
+ // @return {{hint: boolean, reach: "reconnecting"|"offline"|null}}
31
+ // hint: replace the history with the error; reach: the store's field.
32
+ export function readFailed({ drawn, retrying }) {
33
+ if (!drawn) return { hint: true, reach: null };
34
+ return { hint: false, reach: retrying ? "reconnecting" : "offline" };
35
+ }
36
+
37
+ // The page side. +store+: the session store (its current.reach); +historyEl+,
38
+ // +errorHint+(message): the node a first load's failure shows.
39
+ export function createResyncReach({ store, historyEl, errorHint }) {
40
+ // The session whose conversation the history shows (null: a "Loading…"
41
+ // or error hint, the start page).
42
+ let drawnId = null;
43
+ return {
44
+ // select() put its "Loading…" hint in.
45
+ loading() {
46
+ drawnId = null;
47
+ },
48
+ // A re-read of +id+ drew it: the indicator goes.
49
+ drawn(id) {
50
+ drawnId = id;
51
+ if (store.current.reach) store.update({ current: { reach: null } });
52
+ },
53
+ // A re-read of +id+ (the open session) failed with +message+.
54
+ failed(id, message, { retrying }) {
55
+ const { hint, reach } = readFailed({ drawn: drawnId === id, retrying });
56
+ if (hint) historyEl.replaceChildren(errorHint(message));
57
+ if (reach !== store.current.reach) store.update({ current: { reach } });
58
+ },
59
+ // The session still shows a failed re-read: any sign of chi web (a hub
60
+ // event) is worth a re-read, not only a worker's bridge_up.
61
+ needsReread: () => !!store.current.reach,
62
+ };
63
+ }
@@ -50,13 +50,13 @@ export function scopeTemplate(scope, { error = null, where = () => ({ hash: "" }
50
50
  const at = where();
51
51
  const allHref = () => allScopeHref(where().hash, scope.dir);
52
52
  const all = html`<a class="scope-all" href=${allScopeHref(at.hash, scope.dir)} title=${"Sessions of every project"} @click=${(e) => { e.currentTarget.href = allHref(); }}>all</a>`;
53
- if (error) return html`<button id="scopePick" class="scope-name error" type="button" aria-haspopup="dialog" aria-expanded="false" title=${error}>folder not found</button>${all}`;
54
- if (scope.projectName) return html`<button id="scopePick" class="scope-name" type="button" aria-haspopup="dialog" aria-expanded="false" title=${`Sessions of ${scope.projectDir}`}>${scope.projectName}</button>${all}`;
53
+ if (error) return html`<button id="scopePick" class="scope-name error" type="button" aria-haspopup="dialog" aria-expanded="false" title=${error}><span class="scope-label">folder not found</span></button>${all}`;
54
+ if (scope.projectName) return html`<button id="scopePick" class="scope-name" type="button" aria-haspopup="dialog" aria-expanded="false" title=${`Sessions of ${scope.projectDir}`}><span class="scope-label">${scope.projectName}</span></button>${all}`;
55
55
  const dir = scope.dir || scope.serverDir;
56
56
  const backHref = () => projectScopeHref(scope.backDir, where().hash);
57
57
  const back = scope.backName
58
58
  ? html`<a class="scope-all scope-back" href=${projectScopeHref(scope.backDir, at.hash)} title=${`Sessions of ${scope.backName} only`} @click=${(e) => { e.currentTarget.href = backHref(); }}>← ${scope.backName}</a>`
59
59
  : nothing;
60
60
  const newSession = dir ? html`<span class="scope-where" title=${`New sessions start in ${dir}`}>new session in<span class="path"><bdi>${dir}</bdi></span></span>` : nothing;
61
- return html`<button id="scopePick" class="scope-name" type="button" aria-haspopup="dialog" aria-expanded="false" title="Sessions of every project">all projects</button>${back}${newSession}`;
61
+ return html`<button id="scopePick" class="scope-name" type="button" aria-haspopup="dialog" aria-expanded="false" title="Sessions of every project"><span class="scope-label">all projects</span></button>${back}${newSession}`;
62
62
  }
@@ -110,6 +110,7 @@ export const FIELDS = {
110
110
  turnStarted: { redraws: ["composer", "infoBar"], writers: "setTurnRunning" },
111
111
  streamSeq: { redraws: [], writers: "resync" },
112
112
  streamFromGuess: { redraws: [], writers: "followWokenWorker, startStream, the stream's takeGuess" },
113
+ reach: { redraws: ["infoBar"], writers: "resync (resync_reach.js)" },
113
114
  };
114
115
 
115
116
  // The fields a hub card brings for the open session (followSelectedSession):
@@ -12,6 +12,7 @@
12
12
  // strip draws every card from new nodes on each session event, so an input
13
13
  // inside a card would be thrown away mid-typing.
14
14
  import { normalize } from "./format.js";
15
+ import { noContactFill } from "./no_contact_fill.js";
15
16
 
16
17
  // As long as a title may be (TitleCommand::LIMIT).
17
18
  const TITLE_CHARS = 80;
@@ -114,9 +115,12 @@ export function createRename({ doc = document, anchor, session, titleOf, shownTi
114
115
  const el = doc.createElement("input");
115
116
  el.type = "text";
116
117
  el.className = "rename-input";
118
+ // Not a contact field (no_contact_fill.js): no contact word in its
119
+ // name or its wording, so "label", never "title".
120
+ noContactFill(el, "chi-session-label");
117
121
  el.maxLength = TITLE_CHARS;
118
- el.placeholder = normalize(shownTitle(id)) || "Session title";
119
- el.setAttribute("aria-label", "Session title (Enter saves, empty clears, Esc cancels)");
122
+ el.placeholder = normalize(shownTitle(id)) || "Session label";
123
+ el.setAttribute("aria-label", "Session label (Enter saves, empty clears, Esc cancels)");
120
124
  el.value = titleOf(id) || "";
121
125
  el.dataset.before = el.value;
122
126
  el.addEventListener("keydown", (e) => {